@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function registerMessage(string $domain, string $string, bool $resolveDomain = true): void |
| 63 | 63 | { |
| 64 | - if ($resolveDomain) { |
|
| 64 | + if ($resolveDomain){ |
|
| 65 | 65 | $domain = $this->config->resolveDomain($domain); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function indexClasses(ClassesInterface $locator): void |
| 84 | 84 | { |
| 85 | - foreach ($locator->getClasses(TranslatorTrait::class) as $class) { |
|
| 85 | + foreach ($locator->getClasses(TranslatorTrait::class) as $class){ |
|
| 86 | 86 | $strings = $this->fetchMessages($class, true); |
| 87 | - foreach ($strings as $string) { |
|
| 87 | + foreach ($strings as $string){ |
|
| 88 | 88 | $this->registerMessage($class->getName(), $string); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | private function registerInvocations(array $invocations): void |
| 120 | 120 | { |
| 121 | - foreach ($invocations as $invocation) { |
|
| 122 | - if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) { |
|
| 121 | + foreach ($invocations as $invocation){ |
|
| 122 | + if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING){ |
|
| 123 | 123 | //We can only index invocations with constant string arguments |
| 124 | 124 | continue; |
| 125 | 125 | } |
@@ -142,20 +142,20 @@ discard block |
||
| 142 | 142 | { |
| 143 | 143 | $target = $reflection->getDefaultProperties() + $reflection->getConstants(); |
| 144 | 144 | |
| 145 | - foreach ($reflection->getProperties() as $property) { |
|
| 146 | - if (is_string($property->getDocComment()) && strpos($property->getDocComment(), '@do-not-index')) { |
|
| 145 | + foreach ($reflection->getProperties() as $property){ |
|
| 146 | + if (is_string($property->getDocComment()) && strpos($property->getDocComment(), '@do-not-index')){ |
|
| 147 | 147 | unset($target[$property->getName()]); |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $strings = []; |
| 152 | 152 | array_walk_recursive($target, function ($value) use (&$strings): void { |
| 153 | - if (is_string($value) && Translator::isMessage($value)) { |
|
| 153 | + if (is_string($value) && Translator::isMessage($value)){ |
|
| 154 | 154 | $strings[] = $this->prepareMessage($value); |
| 155 | 155 | } |
| 156 | 156 | }); |
| 157 | 157 | |
| 158 | - if ($inherit && $reflection->getParentClass()) { |
|
| 158 | + if ($inherit && $reflection->getParentClass()){ |
|
| 159 | 159 | //Joining strings data with parent class values (inheritance ON) - resolved into same |
| 160 | 160 | //domain on export |
| 161 | 161 | $strings = array_merge( |
@@ -178,27 +178,27 @@ discard block |
||
| 178 | 178 | //Translation using default bundle |
| 179 | 179 | $domain = $this->config->getDefaultDomain(); |
| 180 | 180 | |
| 181 | - if ($invocation->getName() === 'say') { |
|
| 181 | + if ($invocation->getName() === 'say'){ |
|
| 182 | 182 | //Let's try to confirm domain |
| 183 | 183 | $domain = $this->config->resolveDomain($invocation->getClass()); |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | //`l` and `p`, `say` functions |
| 187 | 187 | $argument = null; |
| 188 | - switch (strtolower($invocation->getName())) { |
|
| 188 | + switch (strtolower($invocation->getName())){ |
|
| 189 | 189 | case 'say': |
| 190 | 190 | case 'l': |
| 191 | - if ($invocation->countArguments() >= 3) { |
|
| 191 | + if ($invocation->countArguments() >= 3){ |
|
| 192 | 192 | $argument = $invocation->getArgument(2); |
| 193 | 193 | } |
| 194 | 194 | break; |
| 195 | 195 | case 'p': |
| 196 | - if ($invocation->countArguments() >= 4) { |
|
| 196 | + if ($invocation->countArguments() >= 4){ |
|
| 197 | 197 | $argument = $invocation->getArgument(3); |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) { |
|
| 201 | + if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING){ |
|
| 202 | 202 | //Domain specified in arguments |
| 203 | 203 | $domain = $this->config->resolveDomain($argument->stringValue()); |
| 204 | 204 | } |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | private function prepareMessage(string $string): string |
| 216 | 216 | { |
| 217 | - if (Translator::isMessage($string)) { |
|
| 217 | + if (Translator::isMessage($string)){ |
|
| 218 | 218 | $string = substr($string, 2, -2); |
| 219 | 219 | } |
| 220 | 220 | |
@@ -61,7 +61,8 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function registerMessage(string $domain, string $string, bool $resolveDomain = true): void |
| 63 | 63 | { |
| 64 | - if ($resolveDomain) { |
|
| 64 | + if ($resolveDomain) |
|
| 65 | + { |
|
| 65 | 66 | $domain = $this->config->resolveDomain($domain); |
| 66 | 67 | } |
| 67 | 68 | |
@@ -82,9 +83,11 @@ discard block |
||
| 82 | 83 | */ |
| 83 | 84 | public function indexClasses(ClassesInterface $locator): void |
| 84 | 85 | { |
| 85 | - foreach ($locator->getClasses(TranslatorTrait::class) as $class) { |
|
| 86 | + foreach ($locator->getClasses(TranslatorTrait::class) as $class) |
|
| 87 | + { |
|
| 86 | 88 | $strings = $this->fetchMessages($class, true); |
| 87 | - foreach ($strings as $string) { |
|
| 89 | + foreach ($strings as $string) |
|
| 90 | + { |
|
| 88 | 91 | $this->registerMessage($class->getName(), $string); |
| 89 | 92 | } |
| 90 | 93 | } |
@@ -118,8 +121,10 @@ discard block |
||
| 118 | 121 | */ |
| 119 | 122 | private function registerInvocations(array $invocations): void |
| 120 | 123 | { |
| 121 | - foreach ($invocations as $invocation) { |
|
| 122 | - if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) { |
|
| 124 | + foreach ($invocations as $invocation) |
|
| 125 | + { |
|
| 126 | + if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) |
|
| 127 | + { |
|
| 123 | 128 | //We can only index invocations with constant string arguments |
| 124 | 129 | continue; |
| 125 | 130 | } |
@@ -142,20 +147,24 @@ discard block |
||
| 142 | 147 | { |
| 143 | 148 | $target = $reflection->getDefaultProperties() + $reflection->getConstants(); |
| 144 | 149 | |
| 145 | - foreach ($reflection->getProperties() as $property) { |
|
| 146 | - if (is_string($property->getDocComment()) && strpos($property->getDocComment(), '@do-not-index')) { |
|
| 150 | + foreach ($reflection->getProperties() as $property) |
|
| 151 | + { |
|
| 152 | + if (is_string($property->getDocComment()) && strpos($property->getDocComment(), '@do-not-index')) |
|
| 153 | + { |
|
| 147 | 154 | unset($target[$property->getName()]); |
| 148 | 155 | } |
| 149 | 156 | } |
| 150 | 157 | |
| 151 | 158 | $strings = []; |
| 152 | 159 | array_walk_recursive($target, function ($value) use (&$strings): void { |
| 153 | - if (is_string($value) && Translator::isMessage($value)) { |
|
| 160 | + if (is_string($value) && Translator::isMessage($value)) |
|
| 161 | + { |
|
| 154 | 162 | $strings[] = $this->prepareMessage($value); |
| 155 | 163 | } |
| 156 | 164 | }); |
| 157 | 165 | |
| 158 | - if ($inherit && $reflection->getParentClass()) { |
|
| 166 | + if ($inherit && $reflection->getParentClass()) |
|
| 167 | + { |
|
| 159 | 168 | //Joining strings data with parent class values (inheritance ON) - resolved into same |
| 160 | 169 | //domain on export |
| 161 | 170 | $strings = array_merge( |
@@ -178,27 +187,32 @@ discard block |
||
| 178 | 187 | //Translation using default bundle |
| 179 | 188 | $domain = $this->config->getDefaultDomain(); |
| 180 | 189 | |
| 181 | - if ($invocation->getName() === 'say') { |
|
| 190 | + if ($invocation->getName() === 'say') |
|
| 191 | + { |
|
| 182 | 192 | //Let's try to confirm domain |
| 183 | 193 | $domain = $this->config->resolveDomain($invocation->getClass()); |
| 184 | 194 | } |
| 185 | 195 | |
| 186 | 196 | //`l` and `p`, `say` functions |
| 187 | 197 | $argument = null; |
| 188 | - switch (strtolower($invocation->getName())) { |
|
| 198 | + switch (strtolower($invocation->getName())) |
|
| 199 | + { |
|
| 189 | 200 | case 'say': |
| 190 | 201 | case 'l': |
| 191 | - if ($invocation->countArguments() >= 3) { |
|
| 202 | + if ($invocation->countArguments() >= 3) |
|
| 203 | + { |
|
| 192 | 204 | $argument = $invocation->getArgument(2); |
| 193 | 205 | } |
| 194 | 206 | break; |
| 195 | 207 | case 'p': |
| 196 | - if ($invocation->countArguments() >= 4) { |
|
| 208 | + if ($invocation->countArguments() >= 4) |
|
| 209 | + { |
|
| 197 | 210 | $argument = $invocation->getArgument(3); |
| 198 | 211 | } |
| 199 | 212 | } |
| 200 | 213 | |
| 201 | - if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) { |
|
| 214 | + if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) |
|
| 215 | + { |
|
| 202 | 216 | //Domain specified in arguments |
| 203 | 217 | $domain = $this->config->resolveDomain($argument->stringValue()); |
| 204 | 218 | } |
@@ -214,7 +228,8 @@ discard block |
||
| 214 | 228 | */ |
| 215 | 229 | private function prepareMessage(string $string): string |
| 216 | 230 | { |
| 217 | - if (Translator::isMessage($string)) { |
|
| 231 | + if (Translator::isMessage($string)) |
|
| 232 | + { |
|
| 218 | 233 | $string = substr($string, 2, -2); |
| 219 | 234 | } |
| 220 | 235 | |
@@ -77,7 +77,7 @@ |
||
| 77 | 77 | $container = new Container(); |
| 78 | 78 | $container->bind(TranslatorConfig::class, new TranslatorConfig([ |
| 79 | 79 | 'locale' => 'en', |
| 80 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 80 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 81 | 81 | 'loaders' => [ |
| 82 | 82 | 'php' => PhpFileLoader::class, |
| 83 | 83 | 'po' => PoFileLoader::class, |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | |
| 45 | 45 | $this->container->bind(TranslatorConfig::class, new TranslatorConfig([ |
| 46 | 46 | 'locale' => 'en', |
| 47 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 47 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 48 | 48 | 'loaders' => [ |
| 49 | 49 | 'php' => PhpFileLoader::class, |
| 50 | 50 | 'po' => PoFileLoader::class, |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | public function testHasLocale(): void |
| 26 | 26 | { |
| 27 | 27 | $loader = new CatalogueLoader(new TranslatorConfig([ |
| 28 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 28 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 29 | 29 | ])); |
| 30 | 30 | |
| 31 | 31 | $this->assertTrue($loader->hasLocale('ru')); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public function testGetLocales(): void |
| 36 | 36 | { |
| 37 | 37 | $loader = new CatalogueLoader(new TranslatorConfig([ |
| 38 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 38 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 39 | 39 | ])); |
| 40 | 40 | |
| 41 | 41 | $compared = $loader->getLocales(); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | public function testLoadCatalogue(): void |
| 50 | 50 | { |
| 51 | 51 | $loader = new CatalogueLoader(new TranslatorConfig([ |
| 52 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 52 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 53 | 53 | 'loaders' => [ |
| 54 | 54 | 'php' => PhpFileLoader::class, |
| 55 | 55 | 'po' => PoFileLoader::class, |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | public function testLoadCatalogueNoLoader(): void |
| 90 | 90 | { |
| 91 | 91 | $loader = new CatalogueLoader(new TranslatorConfig([ |
| 92 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 92 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 93 | 93 | 'loaders' => [ |
| 94 | 94 | 'php' => PhpFileLoader::class, |
| 95 | 95 | ], |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $cache->shouldReceive('setLocales')->andReturn(null); |
| 32 | 32 | |
| 33 | 33 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
| 34 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 34 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 35 | 35 | 'loaders' => [ |
| 36 | 36 | 'php' => PhpFileLoader::class, |
| 37 | 37 | 'po' => PoFileLoader::class, |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $cache->shouldNotReceive('setLocales')->andReturn(null); |
| 50 | 50 | |
| 51 | 51 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
| 52 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 52 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 53 | 53 | 'loaders' => [ |
| 54 | 54 | 'php' => PhpFileLoader::class, |
| 55 | 55 | 'po' => PoFileLoader::class, |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $cache->shouldReceive('getLocales')->andReturn(['en', 'ru']); |
| 67 | 67 | |
| 68 | 68 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
| 69 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 69 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 70 | 70 | 'loaders' => [ |
| 71 | 71 | 'php' => PhpFileLoader::class, |
| 72 | 72 | 'po' => PoFileLoader::class, |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | ]); |
| 130 | 130 | |
| 131 | 131 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
| 132 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
| 132 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
| 133 | 133 | 'loaders' => [ |
| 134 | 134 | 'php' => PhpFileLoader::class, |
| 135 | 135 | 'po' => PoFileLoader::class, |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function getMessage(string $field, $value): string |
| 75 | 75 | { |
| 76 | - if (!empty($this->message)) { |
|
| 76 | + if (!empty($this->message)){ |
|
| 77 | 77 | return Translator::interpolate( |
| 78 | 78 | $this->message, |
| 79 | 79 | array_merge([$value, $field], $this->args) |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $name = $this->check; |
| 84 | - if (is_array($name) && isset($name[0], $name[1])) { |
|
| 84 | + if (is_array($name) && isset($name[0], $name[1])){ |
|
| 85 | 85 | $name = sprintf( |
| 86 | 86 | '%s::%s', |
| 87 | 87 | is_object($name[0]) ? get_class($name[0]) : $name, |
| 88 | 88 | $name[1] |
| 89 | 89 | ); |
| 90 | - } elseif (!is_string($name)) { |
|
| 90 | + } elseif (!is_string($name)){ |
|
| 91 | 91 | $name = '~user-defined~'; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -73,7 +73,8 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function getMessage(string $field, $value): string |
| 75 | 75 | { |
| 76 | - if (!empty($this->message)) { |
|
| 76 | + if (!empty($this->message)) |
|
| 77 | + { |
|
| 77 | 78 | return Translator::interpolate( |
| 78 | 79 | $this->message, |
| 79 | 80 | array_merge([$value, $field], $this->args) |
@@ -81,13 +82,16 @@ discard block |
||
| 81 | 82 | } |
| 82 | 83 | |
| 83 | 84 | $name = $this->check; |
| 84 | - if (is_array($name) && isset($name[0], $name[1])) { |
|
| 85 | + if (is_array($name) && isset($name[0], $name[1])) |
|
| 86 | + { |
|
| 85 | 87 | $name = sprintf( |
| 86 | 88 | '%s::%s', |
| 87 | 89 | is_object($name[0]) ? get_class($name[0]) : $name, |
| 88 | 90 | $name[1] |
| 89 | 91 | ); |
| 90 | - } elseif (!is_string($name)) { |
|
| 92 | + } |
|
| 93 | + elseif (!is_string($name)) |
|
| 94 | + { |
|
| 91 | 95 | $name = '~user-defined~'; |
| 92 | 96 | } |
| 93 | 97 | |
@@ -40,11 +40,11 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | public function getConditions(): \Generator |
| 42 | 42 | { |
| 43 | - if (empty($this->conditions)) { |
|
| 43 | + if (empty($this->conditions)){ |
|
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - foreach ($this->conditions as $condition) { |
|
| 47 | + foreach ($this->conditions as $condition){ |
|
| 48 | 48 | yield $condition->withOptions($this->conditions->offsetGet($condition)); |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -40,11 +40,13 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | public function getConditions(): \Generator |
| 42 | 42 | { |
| 43 | - if (empty($this->conditions)) { |
|
| 43 | + if (empty($this->conditions)) |
|
| 44 | + { |
|
| 44 | 45 | return; |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | - foreach ($this->conditions as $condition) { |
|
| 48 | + foreach ($this->conditions as $condition) |
|
| 49 | + { |
|
| 48 | 50 | yield $condition->withOptions($this->conditions->offsetGet($condition)); |
| 49 | 51 | } |
| 50 | 52 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | ValidatorConfig $config, |
| 42 | 42 | ParserInterface $parser = null, |
| 43 | 43 | FactoryInterface $factory = null |
| 44 | - ) { |
|
| 44 | + ){ |
|
| 45 | 45 | $this->config = $config; |
| 46 | 46 | $this->parser = $parser ?? new RuleParser(); |
| 47 | 47 | $this->factory = $factory ?? new Container(); |
@@ -78,14 +78,14 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function getRules($rules): \Generator |
| 80 | 80 | { |
| 81 | - foreach ($this->parser->split($rules) as $id => $rule) { |
|
| 82 | - if (empty($id) || $rule instanceof \Closure) { |
|
| 81 | + foreach ($this->parser->split($rules) as $id => $rule){ |
|
| 82 | + if (empty($id) || $rule instanceof \Closure){ |
|
| 83 | 83 | yield new CallableRule($rule); |
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // fetch from cache |
| 88 | - if (isset($this->rules[$id])) { |
|
| 88 | + if (isset($this->rules[$id])){ |
|
| 89 | 89 | yield $this->rules[$id]; |
| 90 | 90 | continue; |
| 91 | 91 | } |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | $args = $this->parser->parseArgs($rule); |
| 127 | 127 | $message = $this->parser->parseMessage($rule); |
| 128 | 128 | |
| 129 | - if (!is_array($check)) { |
|
| 129 | + if (!is_array($check)){ |
|
| 130 | 130 | return new CallableRule($check, $args, $message); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if (is_string($check[0]) && $this->config->hasChecker($check[0])) { |
|
| 133 | + if (is_string($check[0]) && $this->config->hasChecker($check[0])){ |
|
| 134 | 134 | $check[0] = $this->config->getChecker($check[0])->resolve($this->factory); |
| 135 | 135 | |
| 136 | 136 | return new CheckerRule($check[0], $check[1], $args, $message); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if (!is_object($check[0])) { |
|
| 139 | + if (!is_object($check[0])){ |
|
| 140 | 140 | $check[0] = (new Autowire($check[0]))->resolve($this->factory); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -151,17 +151,17 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | protected function makeConditions(array $conditions): ?\SplObjectStorage |
| 153 | 153 | { |
| 154 | - if (empty($conditions)) { |
|
| 154 | + if (empty($conditions)){ |
|
| 155 | 155 | return null; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | $storage = new \SplObjectStorage(); |
| 159 | - foreach ($conditions as $condition => $options) { |
|
| 159 | + foreach ($conditions as $condition => $options){ |
|
| 160 | 160 | $condition = $this->config->resolveAlias($condition); |
| 161 | 161 | |
| 162 | - if ($this->config->hasCondition($condition)) { |
|
| 162 | + if ($this->config->hasCondition($condition)){ |
|
| 163 | 163 | $autowire = $this->config->getCondition($condition); |
| 164 | - } else { |
|
| 164 | + }else{ |
|
| 165 | 165 | $autowire = new Autowire($condition); |
| 166 | 166 | } |
| 167 | 167 | |
@@ -78,14 +78,17 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function getRules($rules): \Generator |
| 80 | 80 | { |
| 81 | - foreach ($this->parser->split($rules) as $id => $rule) { |
|
| 82 | - if (empty($id) || $rule instanceof \Closure) { |
|
| 81 | + foreach ($this->parser->split($rules) as $id => $rule) |
|
| 82 | + { |
|
| 83 | + if (empty($id) || $rule instanceof \Closure) |
|
| 84 | + { |
|
| 83 | 85 | yield new CallableRule($rule); |
| 84 | 86 | continue; |
| 85 | 87 | } |
| 86 | 88 | |
| 87 | 89 | // fetch from cache |
| 88 | - if (isset($this->rules[$id])) { |
|
| 90 | + if (isset($this->rules[$id])) |
|
| 91 | + { |
|
| 89 | 92 | yield $this->rules[$id]; |
| 90 | 93 | continue; |
| 91 | 94 | } |
@@ -126,17 +129,20 @@ discard block |
||
| 126 | 129 | $args = $this->parser->parseArgs($rule); |
| 127 | 130 | $message = $this->parser->parseMessage($rule); |
| 128 | 131 | |
| 129 | - if (!is_array($check)) { |
|
| 132 | + if (!is_array($check)) |
|
| 133 | + { |
|
| 130 | 134 | return new CallableRule($check, $args, $message); |
| 131 | 135 | } |
| 132 | 136 | |
| 133 | - if (is_string($check[0]) && $this->config->hasChecker($check[0])) { |
|
| 137 | + if (is_string($check[0]) && $this->config->hasChecker($check[0])) |
|
| 138 | + { |
|
| 134 | 139 | $check[0] = $this->config->getChecker($check[0])->resolve($this->factory); |
| 135 | 140 | |
| 136 | 141 | return new CheckerRule($check[0], $check[1], $args, $message); |
| 137 | 142 | } |
| 138 | 143 | |
| 139 | - if (!is_object($check[0])) { |
|
| 144 | + if (!is_object($check[0])) |
|
| 145 | + { |
|
| 140 | 146 | $check[0] = (new Autowire($check[0]))->resolve($this->factory); |
| 141 | 147 | } |
| 142 | 148 | |
@@ -151,17 +157,22 @@ discard block |
||
| 151 | 157 | */ |
| 152 | 158 | protected function makeConditions(array $conditions): ?\SplObjectStorage |
| 153 | 159 | { |
| 154 | - if (empty($conditions)) { |
|
| 160 | + if (empty($conditions)) |
|
| 161 | + { |
|
| 155 | 162 | return null; |
| 156 | 163 | } |
| 157 | 164 | |
| 158 | 165 | $storage = new \SplObjectStorage(); |
| 159 | - foreach ($conditions as $condition => $options) { |
|
| 166 | + foreach ($conditions as $condition => $options) |
|
| 167 | + { |
|
| 160 | 168 | $condition = $this->config->resolveAlias($condition); |
| 161 | 169 | |
| 162 | - if ($this->config->hasCondition($condition)) { |
|
| 170 | + if ($this->config->hasCondition($condition)) |
|
| 171 | + { |
|
| 163 | 172 | $autowire = $this->config->getCondition($condition); |
| 164 | - } else { |
|
| 173 | + } |
|
| 174 | + else |
|
| 175 | + { |
|
| 165 | 176 | $autowire = new Autowire($condition); |
| 166 | 177 | } |
| 167 | 178 | |
@@ -69,11 +69,11 @@ |
||
| 69 | 69 | */ |
| 70 | 70 | public function datetime($value): bool |
| 71 | 71 | { |
| 72 | - if (!is_scalar($value)) { |
|
| 72 | + if (!is_scalar($value)){ |
|
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if (is_numeric($value)) { |
|
| 76 | + if (is_numeric($value)){ |
|
| 77 | 77 | return true; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -69,11 +69,13 @@ |
||
| 69 | 69 | */ |
| 70 | 70 | public function datetime($value): bool |
| 71 | 71 | { |
| 72 | - if (!is_scalar($value)) { |
|
| 72 | + if (!is_scalar($value)) |
|
| 73 | + { |
|
| 73 | 74 | return false; |
| 74 | 75 | } |
| 75 | 76 | |
| 76 | - if (is_numeric($value)) { |
|
| 77 | + if (is_numeric($value)) |
|
| 78 | + { |
|
| 77 | 79 | return true; |
| 78 | 80 | } |
| 79 | 81 | |