Skip to content

Commit

Permalink
Merge branch '3.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed Jul 29, 2023
2 parents eef34ab + 55722a5 commit a161e29
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/Combine/JavascriptMinify.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class JavascriptMinify
*/
public function minify($css)
{
return JSMin::minify($contents);
return JSMin::minify($css);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Database/Factories/HasFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public static function factory($count = null, $state = [])
*/
protected static function factoryForModel(string $modelName)
{
$factory = str_replace('Models\\', 'Factories\\', $modelName) . 'Factory';
if (strpos($modelName, 'App\\') === 0) {
$factory = str_replace('Models\\', 'Database\\Factories\\', $modelName) . 'Factory';
}
else {
$factory = str_replace('Models\\', 'Updates\\Factories\\', $modelName) . 'Factory';
}

return $factory::new();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Relations/AttachMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getSimpleValue()

if ($files) {
$value = [];
foreach ($value as $file) {
foreach ($files as $file) {
$value[] = $file->getPath();
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Database/Relations/DefinedConstraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ trait DefinedConstraints
*/
public function addDefinedConstraints(): void
{
$args = $this->parent->getRelationDefinition($this->relationName);
if (static::$constraints) {
$args = $this->parent->getRelationDefinition($this->relationName);

$this->addDefinedConstraintsToRelation($this, $args);
$this->addDefinedConstraintsToRelation($this, $args);

$this->addDefinedConstraintsToQuery($this, $args);
$this->addDefinedConstraintsToQuery($this, $args);
}
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Database/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public function __construct(Builder $query, Model $farParent, Model $parent, $fi
*/
public function addDefinedConstraints()
{
$args = $this->farParent->getRelationDefinition($this->relationName);
if (static::$constraints) {
$args = $this->farParent->getRelationDefinition($this->relationName);

$this->addDefinedConstraintsToRelation($this, $args);
$this->addDefinedConstraintsToRelation($this, $args);

$this->addDefinedConstraintsToQuery($this, $args);
$this->addDefinedConstraintsToQuery($this, $args);
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Foundation/Console/ProjectSetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function requestServerData(string $uri, array $postData = [])
*/
protected function createServerUrl($uri)
{
$gateway = env('APP_UPDATE_GATEWAY', Config::get('system.update_gateway', 'https://gateway.octobercms.com/api'));
$gateway = Config::get('system.update_gateway', 'https://gateway.octobercms.com/api');
if (substr($gateway, -1) != '/') {
$gateway .= '/';
}
Expand Down Expand Up @@ -189,7 +189,7 @@ protected function makeHttpRequest($url, $postData)
*/
protected function getComposerUrl(bool $withProtocol = true): string
{
$gateway = env('APP_COMPOSER_GATEWAY', Config::get('system.composer_gateway', 'gateway.octobercms.com'));
$gateway = Config::get('system.composer_gateway', 'gateway.octobercms.com');

return $withProtocol ? 'https://'.$gateway : $gateway;
}
Expand All @@ -214,7 +214,7 @@ protected function injectJsonToFile(string $filename, array $jsonArr, bool $merg
}

/**
* mergeRecursive substitues the native PHP array_merge_recursive to be
* mergeRecursive substitutes the native PHP array_merge_recursive to be
* more config friendly. Scalar values are replaced instead of being
* merged in to their own new array.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Parse/Syntax/FieldParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class FieldParser
{
/**
* @var string Template contents
* @var string template contents
*/
protected $template = '';

Expand Down Expand Up @@ -199,10 +199,10 @@ protected function processRepeaterTags($template)

$field['fields'] = $innerFields;
$tags[$name] = [
'tags' => $innerTags,
'tags' => $innerTags,
'template' => $outerTemplate,
'open' => $openTag,
'close' => $closeTag
'open' => $openTag,
'close' => $closeTag
];

// Remove the inner content of the repeater
Expand Down Expand Up @@ -322,7 +322,7 @@ protected function processParams($value, $tagName)
}

/**
* Converts parameter string to an array.
* processParamsRegex converts parameter string to an array.
*
* In: name="test" comment="This is a test"
* Out: ['name' => 'test', 'comment' => 'This is a test']
Expand Down
32 changes: 20 additions & 12 deletions src/Parse/Syntax/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class Parser
const CHAR_OPEN = '{';
const CHAR_CLOSE = '}';

/**
* @var string template to parse
*/
protected $template;

/**
* @var \October\Rain\Parse\Syntax\FieldParser Field parser instance.
*/
Expand All @@ -30,12 +35,11 @@ class Parser
protected $varPrefix = '';

/**
* Constructor.
* Available options:
* - varPrefix: Prefix to add to every top level parameter.
* - tagPrefix: Prefix to add to all tags, in addition to tags without a prefix.
* __construct parser, with available options:
* - varPrefix: Prefix to add to every top level parameter.
* - tagPrefix: Prefix to add to all tags, in addition to tags without a prefix.
* @param string $template
* @param array $options
* @param string $template Template to parse.
*/
public function __construct($template = null, $options = [])
{
Expand Down Expand Up @@ -105,8 +109,8 @@ public function toTwig()
}

/**
* Returns the template with fields replaced with the simple
* templating engine used by the TextParser class.
* toView returns the template with fields replaced with the simple
* template engine used by the TextParser class.
* @return string
*/
public function toView()
Expand All @@ -115,7 +119,7 @@ public function toView()
}

/**
* Parses the template to a specific view engine (Twig, Simple)
* toViewEngine parses the template to a specific view engine (Twig, Simple)
* @param string $engine
* @return string
*/
Expand All @@ -134,6 +138,9 @@ protected function toViewEngine($engine)
return $template;
}

/**
* processRepeatingTag
*/
protected function processRepeatingTag($engine, $template, $field, $tagDetails)
{
$prefixField = $this->varPrefix.$field;
Expand Down Expand Up @@ -172,6 +179,9 @@ protected function processRepeatingTag($engine, $template, $field, $tagDetails)
return $template;
}

/**
* processTag
*/
protected function processTag($engine, $template, $field, $tagString)
{
$prefixField = $this->varPrefix.$field;
Expand All @@ -182,7 +192,7 @@ protected function processTag($engine, $template, $field, $tagString)
}

/**
* Processes a field type and converts it to the Twig engine.
* evalTwigViewField processes a field type and converts it to the Twig engine.
* @param string $field
* @param array $params
* @param string $prefix
Expand All @@ -194,9 +204,7 @@ protected function evalTwigViewField($field, $params, $prefix = null)
return '';
}

/*
* Used by Twig for loop
*/
// Used by Twig for loop
if ($prefix) {
$field = $prefix.'.'.$field;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Resize/Resizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public static function open($file): Resizer
*/
protected function retainImageTransparency($img)
{
if (!$img) {
return;
}

if ($this->mime === 'image/gif') {
$alphaColor = ['red' => 0, 'green' => 0, 'blue' => 0];
$alphaIndex = imagecolortransparent($img);
Expand Down
22 changes: 20 additions & 2 deletions src/Scaffold/Console/CreateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CreateFactory extends GeneratorCommandBase
*/
protected $signature = 'create:factory
{namespace : App or Plugin Namespace. <info>(eg: Acme.Blog)</info>}
{name : The name of the job class to generate. <info>(eg: PostFactory)</info>}
{name : The name of the factory class to generate. <info>(eg: PostFactory)</info>}
{--o|overwrite : Overwrite existing files with generated ones}';

/**
Expand All @@ -25,12 +25,30 @@ class CreateFactory extends GeneratorCommandBase
*/
protected $typeLabel = 'Factory';

/**
* handle executes the console command
*/
public function handle()
{
if (!ends_with($this->argument('name'), 'Factory')) {
$this->components->error('Factory classes names must end in "Factory"');
return;
}

parent::handle();
}

/**
* makeStubs makes all stubs
*/
public function makeStubs()
{
$this->makeStub('factory/factory.stub', 'factories/{{studly_name}}.php');
if ($this->isAppNamespace()) {
$this->makeStub('factory/factory_app.stub', 'database/factories/{{studly_name}}.php');
}
else {
$this->makeStub('factory/factory.stub', 'updates/factories/{{studly_name}}.php');
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffold/Console/factory/factory.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace {{namespace_php}}\Factories;
<?php namespace {{namespace_php}}\Updates\Factories;

use October\Rain\Database\Factories\Factory;

Expand Down
20 changes: 20 additions & 0 deletions src/Scaffold/Console/factory/factory_app.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php namespace {{namespace_php}}\Database\Factories;

use October\Rain\Database\Factories\Factory;

/**
* {{studly_name}}
*/
class {{studly_name}} extends Factory
{
/**
* definition for the default state.
* @return array<string, mixed>
*/
public function definition()
{
return [
//
];
}
}
24 changes: 17 additions & 7 deletions src/Validation/Concerns/FormatsMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use Illuminate\Support\Str;

/**
* FormatsMessages is a modifier to the base trait
* FormatsMessages is a modifier to the base trait, it implements
* some extended technology to allow rule objects to specify methods
* message() and replace() for custom messaging.
*
* @see \Illuminate\Validation\Concerns\FormatsMessages
*/
Expand All @@ -17,6 +19,10 @@ trait FormatsMessages
*/
protected function getMessage($attribute, $rule)
{
$attributeWithPlaceholders = $attribute;

$attribute = $this->replacePlaceholderInString($attribute);

$inlineMessage = $this->getInlineMessage($attribute, $rule);

// First we will retrieve the custom message for the validation rule if one
Expand All @@ -28,8 +34,12 @@ protected function getMessage($attribute, $rule)

$lowerRule = Str::snake($rule);

$customKey = "validation.custom.{$attribute}.{$lowerRule}";

$customMessage = $this->getCustomMessageFromTranslator(
$customKey = "validation.custom.{$attribute}.{$lowerRule}"
in_array($rule, $this->sizeRules)
? [$customKey.".{$this->getAttributeType($attribute)}", $customKey]
: $customKey
);

// First we check for a custom defined validation message for the attribute
Expand All @@ -39,8 +49,7 @@ protected function getMessage($attribute, $rule)
return $customMessage;
}

// Apply fallback message from extension class, if one exists.
// This is custom logic from the parent class.
// Modification: Apply fallback message from extension class, if one exists.
if ($this->hasExtensionMethod($lowerRule, 'message')) {
return $this->callExtensionMethod($lowerRule, 'message');
}
Expand All @@ -49,7 +58,7 @@ protected function getMessage($attribute, $rule)
// specific error message for the type of attribute being validated such
// as a number, file or string which all have different message types.
if (in_array($rule, $this->sizeRules)) {
return $this->getSizeMessage($attribute, $rule);
return $this->getSizeMessage($attributeWithPlaceholders, $rule);
}

// Finally, if no developer specified messages have been set, and no other
Expand Down Expand Up @@ -85,6 +94,8 @@ public function makeReplacements($message, $attribute, $rule, $parameters)
$lowerRule = Str::snake($rule);

$message = $this->replaceInputPlaceholder($message, $attribute);
$message = $this->replaceIndexPlaceholder($message, $attribute);
$message = $this->replacePositionPlaceholder($message, $attribute);

if (isset($this->replacers[$lowerRule])) {
return $this->callReplacer($message, $attribute, $lowerRule, $parameters, $this);
Expand All @@ -93,8 +104,7 @@ public function makeReplacements($message, $attribute, $rule, $parameters)
return $this->$replacer($message, $attribute, $rule, $parameters);
}

// Apply fallback replacer from extension class, if one exists.
// This is custom logic from the parent class.
// Modification: Apply fallback replacer from extension class, if one exists.
if ($this->hasExtensionMethod($lowerRule, 'replace')) {
return $this->callExtensionMethod($lowerRule, 'replace', [$message, $attribute, $lowerRule, $parameters]);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use October\Rain\Exception\ValidationException;

/**
* Validator is a modifier to the base class
* Validator is a modifier to the base class, it extends validation rules
* with extra methods for specifying messages and replacements inside the
* class definition.
*/
class Validator extends ValidatorBase
{
Expand Down

0 comments on commit a161e29

Please sign in to comment.