@@ -237,7 +237,6 @@ discard block |
||
| 237 | 237 | /** |
| 238 | 238 | * Add default models to the form. |
| 239 | 239 | * |
| 240 | - * @param mixed $model |
|
| 241 | 240 | * @return void |
| 242 | 241 | */ |
| 243 | 242 | public function defaults() |
@@ -457,7 +456,7 @@ discard block |
||
| 457 | 456 | * Check if a type exists. |
| 458 | 457 | * |
| 459 | 458 | * @param string $type |
| 460 | - * @return string |
|
| 459 | + * @return boolean |
|
| 461 | 460 | */ |
| 462 | 461 | public function typeExists($type) |
| 463 | 462 | { |
@@ -1072,7 +1071,7 @@ discard block |
||
| 1072 | 1071 | * |
| 1073 | 1072 | * @param string $method |
| 1074 | 1073 | * @param array $parameters |
| 1075 | - * @return mixed |
|
| 1074 | + * @return Fields\Field|null |
|
| 1076 | 1075 | */ |
| 1077 | 1076 | public function __call($method, $parameters) |
| 1078 | 1077 | { |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | public function completed($name = null) |
| 359 | 359 | { |
| 360 | - if($this->submitted($name) && $this->valid()) { |
|
| 360 | + if ($this->submitted($name) && $this->valid()) { |
|
| 361 | 361 | $this->broadcast('completed'); |
| 362 | 362 | return true; |
| 363 | 363 | } |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | $errors = []; |
| 498 | 498 | |
| 499 | 499 | foreach ($this->fields as $field) { |
| 500 | - foreach($field->errors() as $error) { |
|
| 500 | + foreach ($field->errors() as $error) { |
|
| 501 | 501 | $errors[] = $error; |
| 502 | 502 | } |
| 503 | 503 | } |
@@ -619,8 +619,8 @@ discard block |
||
| 619 | 619 | { |
| 620 | 620 | $config = $this->templateConfig($template); |
| 621 | 621 | |
| 622 | - if ( isset($config['plugins']) && is_array($config['plugins'])) { |
|
| 623 | - foreach($config['plugins'] as $plugin) { |
|
| 622 | + if (isset($config['plugins']) && is_array($config['plugins'])) { |
|
| 623 | + foreach ($config['plugins'] as $plugin) { |
|
| 624 | 624 | $this->addPlugin($plugin); |
| 625 | 625 | } |
| 626 | 626 | } |
@@ -636,8 +636,8 @@ discard block |
||
| 636 | 636 | { |
| 637 | 637 | $config = $this->templateConfig($template); |
| 638 | 638 | |
| 639 | - if ( isset($config['plugins']) && is_array($config['plugins'])) { |
|
| 640 | - foreach($config['plugins'] as $plugin) { |
|
| 639 | + if (isset($config['plugins']) && is_array($config['plugins'])) { |
|
| 640 | + foreach ($config['plugins'] as $plugin) { |
|
| 641 | 641 | $this->removePlugin($plugin); |
| 642 | 642 | } |
| 643 | 643 | } |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | foreach ($field->errors() as $error => $parameters) { |
| 675 | 675 | |
| 676 | 676 | if ($error == 'userDefined') { |
| 677 | - foreach($parameters as $message) { |
|
| 677 | + foreach ($parameters as $message) { |
|
| 678 | 678 | $properties['errors'][] = ['error' => $message]; |
| 679 | 679 | } |
| 680 | 680 | } else { |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | |
| 684 | 684 | $message = $this->translate($error, $field); |
| 685 | 685 | |
| 686 | - foreach($parameters as $key => $value) { |
|
| 686 | + foreach ($parameters as $key => $value) { |
|
| 687 | 687 | if (is_object($value) && method_exists($value, '__toString')) $value = (string) $value; |
| 688 | 688 | if (is_array($value)) $value = implode(', ', $value); |
| 689 | 689 | $message = str_replace('['.$key.']', $value, $message); |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | */ |
| 931 | 931 | private function broadcast($event, $params = []) |
| 932 | 932 | { |
| 933 | - foreach($this->plugins as $plugin) { |
|
| 933 | + foreach ($this->plugins as $plugin) { |
|
| 934 | 934 | $plugin->event($this, $event, $params); |
| 935 | 935 | } |
| 936 | 936 | } |
@@ -1078,7 +1078,7 @@ discard block |
||
| 1078 | 1078 | { |
| 1079 | 1079 | if ( ! method_exists($this, $method)) |
| 1080 | 1080 | { |
| 1081 | - if ( $this->typeExists($method)) { |
|
| 1081 | + if ($this->typeExists($method)) { |
|
| 1082 | 1082 | return $this->addField($method, array_shift($parameters)); |
| 1083 | 1083 | } |
| 1084 | 1084 | } |
@@ -259,7 +259,9 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public function fields($names = null) |
| 261 | 261 | { |
| 262 | - if (is_null($names)) return $this->fields; |
|
| 262 | + if (is_null($names)) { |
|
| 263 | + return $this->fields; |
|
| 264 | + } |
|
| 263 | 265 | |
| 264 | 266 | return array_filter($this->fields, function($field) use ($names) { |
| 265 | 267 | return array_key_exists($field->name, $names); |
@@ -442,7 +444,9 @@ discard block |
||
| 442 | 444 | */ |
| 443 | 445 | public function addNamespaceForClass($class) |
| 444 | 446 | { |
| 445 | - if (is_object($class)) $class = get_class($class); |
|
| 447 | + if (is_object($class)) { |
|
| 448 | + $class = get_class($class); |
|
| 449 | + } |
|
| 446 | 450 | |
| 447 | 451 | $reflector = new \ReflectionClass($class); |
| 448 | 452 | |
@@ -477,7 +481,9 @@ discard block |
||
| 477 | 481 | $class = '\\Fields\\'.ucwords($class).'\\'.ucwords($class); |
| 478 | 482 | |
| 479 | 483 | foreach ($this->namespaces as $namespace) { |
| 480 | - if (class_exists($namespace.$class)) return $namespace.$class; |
|
| 484 | + if (class_exists($namespace.$class)) { |
|
| 485 | + return $namespace.$class; |
|
| 486 | + } |
|
| 481 | 487 | } |
| 482 | 488 | } |
| 483 | 489 | |
@@ -490,9 +496,13 @@ discard block |
||
| 490 | 496 | */ |
| 491 | 497 | public function errors($name = null) |
| 492 | 498 | { |
| 493 | - if ($this->submitted()) $this->validate(); |
|
| 499 | + if ($this->submitted()) { |
|
| 500 | + $this->validate(); |
|
| 501 | + } |
|
| 494 | 502 | |
| 495 | - if ( ! is_null($name)) $this->field($name)->errors(); |
|
| 503 | + if ( ! is_null($name)) { |
|
| 504 | + $this->field($name)->errors(); |
|
| 505 | + } |
|
| 496 | 506 | |
| 497 | 507 | $errors = []; |
| 498 | 508 | |
@@ -684,8 +694,12 @@ discard block |
||
| 684 | 694 | $message = $this->translate($error, $field); |
| 685 | 695 | |
| 686 | 696 | foreach($parameters as $key => $value) { |
| 687 | - if (is_object($value) && method_exists($value, '__toString')) $value = (string) $value; |
|
| 688 | - if (is_array($value)) $value = implode(', ', $value); |
|
| 697 | + if (is_object($value) && method_exists($value, '__toString')) { |
|
| 698 | + $value = (string) $value; |
|
| 699 | + } |
|
| 700 | + if (is_array($value)) { |
|
| 701 | + $value = implode(', ', $value); |
|
| 702 | + } |
|
| 689 | 703 | $message = str_replace('['.$key.']', $value, $message); |
| 690 | 704 | } |
| 691 | 705 | $properties['errors'][] = ['error' => $message]; |
@@ -705,7 +719,9 @@ discard block |
||
| 705 | 719 | */ |
| 706 | 720 | public function renderField($field, $properties = null) |
| 707 | 721 | { |
| 708 | - if (is_null($properties)) $properties = $this->fieldProperties($field); |
|
| 722 | + if (is_null($properties)) { |
|
| 723 | + $properties = $this->fieldProperties($field); |
|
| 724 | + } |
|
| 709 | 725 | |
| 710 | 726 | return $this->renderTemplate($field->type, $properties, $field); |
| 711 | 727 | } |
@@ -719,7 +735,9 @@ discard block |
||
| 719 | 735 | */ |
| 720 | 736 | public function renderFieldErrors($field, $properties = null) |
| 721 | 737 | { |
| 722 | - if (is_null($properties)) $properties = $this->fieldProperties($field); |
|
| 738 | + if (is_null($properties)) { |
|
| 739 | + $properties = $this->fieldProperties($field); |
|
| 740 | + } |
|
| 723 | 741 | |
| 724 | 742 | return $this->renderTemplate('errors', $properties, $field); |
| 725 | 743 | } |
@@ -736,9 +754,13 @@ discard block |
||
| 736 | 754 | |
| 737 | 755 | $this->setValues(); |
| 738 | 756 | |
| 739 | - if ($this->submitted()) $this->validate(); |
|
| 757 | + if ($this->submitted()) { |
|
| 758 | + $this->validate(); |
|
| 759 | + } |
|
| 740 | 760 | |
| 741 | - if ( ! is_null($template)) $this->setTemplate($template); |
|
| 761 | + if ( ! is_null($template)) { |
|
| 762 | + $this->setTemplate($template); |
|
| 763 | + } |
|
| 742 | 764 | |
| 743 | 765 | $properties = []; |
| 744 | 766 | $properties['id'] = $this->id; |
@@ -992,7 +1014,9 @@ discard block |
||
| 992 | 1014 | */ |
| 993 | 1015 | public function pathForClass($class) |
| 994 | 1016 | { |
| 995 | - if (is_object($class)) $class = get_class($class); |
|
| 1017 | + if (is_object($class)) { |
|
| 1018 | + $class = get_class($class); |
|
| 1019 | + } |
|
| 996 | 1020 | |
| 997 | 1021 | $reflector = new \ReflectionClass($class); |
| 998 | 1022 | $path = dirname($reflector->getFileName()); |
@@ -35,6 +35,7 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * Get autoload path. |
| 37 | 37 | * |
| 38 | + * @param string $append |
|
| 38 | 39 | * @return string |
| 39 | 40 | */ |
| 40 | 41 | public function path($append = null) |
@@ -46,7 +47,7 @@ discard block |
||
| 46 | 47 | /** |
| 47 | 48 | * Get paths to templates. |
| 48 | 49 | * |
| 49 | - * @return string |
|
| 50 | + * @return string[] |
|
| 50 | 51 | */ |
| 51 | 52 | public function templatePaths() |
| 52 | 53 | { |
@@ -9,52 +9,52 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | * @var string |
| 11 | 11 | */ |
| 12 | - protected $path; |
|
| 12 | + protected $path; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 14 | + /** |
|
| 15 | 15 | * Create a new plugin instance. |
| 16 | 16 | * |
| 17 | 17 | * @return void |
| 18 | 18 | */ |
| 19 | - public function __construct() |
|
| 20 | - { |
|
| 21 | - $this->setPath(); |
|
| 22 | - } |
|
| 19 | + public function __construct() |
|
| 20 | + { |
|
| 21 | + $this->setPath(); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | + /** |
|
| 25 | 25 | * Set the plugin autoload path. |
| 26 | 26 | * |
| 27 | 27 | * @return void |
| 28 | 28 | */ |
| 29 | - public function setPath() |
|
| 30 | - { |
|
| 31 | - $reflector = new \ReflectionClass($this); |
|
| 32 | - $this->path = dirname($reflector->getFileName());; |
|
| 33 | - } |
|
| 29 | + public function setPath() |
|
| 30 | + { |
|
| 31 | + $reflector = new \ReflectionClass($this); |
|
| 32 | + $this->path = dirname($reflector->getFileName());; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | + /** |
|
| 36 | 36 | * Get autoload path. |
| 37 | 37 | * |
| 38 | 38 | * @return string |
| 39 | 39 | */ |
| 40 | - public function path($append = null) |
|
| 41 | - { |
|
| 42 | - return is_null($append) ? $this->path |
|
| 43 | - : $this->path.'/'.ltrim(rtrim($append, '/'), '/').'/'; |
|
| 44 | - } |
|
| 40 | + public function path($append = null) |
|
| 41 | + { |
|
| 42 | + return is_null($append) ? $this->path |
|
| 43 | + : $this->path.'/'.ltrim(rtrim($append, '/'), '/').'/'; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | + /** |
|
| 47 | 47 | * Get paths to templates. |
| 48 | 48 | * |
| 49 | 49 | * @return string |
| 50 | 50 | */ |
| 51 | - public function templatePaths() |
|
| 52 | - { |
|
| 53 | - $path = $this->path('templates'); |
|
| 54 | - return [$path]; |
|
| 55 | - } |
|
| 51 | + public function templatePaths() |
|
| 52 | + { |
|
| 53 | + $path = $this->path('templates'); |
|
| 54 | + return [$path]; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | + /** |
|
| 58 | 58 | * Trigger an event callback. |
| 59 | 59 | * - onLoad |
| 60 | 60 | * - onDefine |
@@ -66,19 +66,19 @@ discard block |
||
| 66 | 66 | * - onValid |
| 67 | 67 | * - onInvalid |
| 68 | 68 | * |
| 69 | - * @param \Helmut\Forms\Form $form |
|
| 70 | - * @param string $name |
|
| 71 | - * @param array $params |
|
| 69 | + * @param \Helmut\Forms\Form $form |
|
| 70 | + * @param string $name |
|
| 71 | + * @param array $params |
|
| 72 | 72 | * @return mixed |
| 73 | 73 | */ |
| 74 | - public function event($form, $name, $params = []) |
|
| 75 | - { |
|
| 76 | - $name = $form->validator()->studly($name); |
|
| 74 | + public function event($form, $name, $params = []) |
|
| 75 | + { |
|
| 76 | + $name = $form->validator()->studly($name); |
|
| 77 | 77 | |
| 78 | - if (method_exists($this, 'on'.$name)) { |
|
| 79 | - return call_user_func_array(array($this, 'on'.$name), [$form, $params]); |
|
| 80 | - } |
|
| 78 | + if (method_exists($this, 'on'.$name)) { |
|
| 79 | + return call_user_func_array(array($this, 'on'.$name), [$form, $params]); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | public function setPath() |
| 30 | 30 | { |
| 31 | 31 | $reflector = new \ReflectionClass($this); |
| 32 | - $this->path = dirname($reflector->getFileName());; |
|
| 32 | + $this->path = dirname($reflector->getFileName()); ; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | /** |
| 71 | 71 | * Create a template cache key. |
| 72 | 72 | * |
| 73 | - * @param string $name |
|
| 74 | 73 | * @param array $paths |
| 74 | + * @param string $template |
|
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | 77 | public function key($template, $paths) |
@@ -100,7 +100,6 @@ discard block |
||
| 100 | 100 | /** |
| 101 | 101 | * Check if a template exists. |
| 102 | 102 | * |
| 103 | - * @param string $key |
|
| 104 | 103 | * @param string $template |
| 105 | 104 | * @param array $paths |
| 106 | 105 | * @return boolean |
@@ -4,141 +4,141 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Renderer { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * Array of engine definitions using |
|
| 9 | - * file extension as key. |
|
| 10 | - * |
|
| 11 | - * @var array |
|
| 12 | - */ |
|
| 13 | - protected $engines = [ |
|
| 14 | - '.mustache.php' => 'Helmut\Forms\Engines\Mustache', |
|
| 15 | - '.twig.php' => 'Helmut\Forms\Engines\Twig', |
|
| 16 | - '.blade.php' => 'Helmut\Forms\Engines\Blade', |
|
| 17 | - ]; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Cache of running engines. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $running = []; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Cache of template files. |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $templates = []; |
|
| 32 | - |
|
| 33 | - /** |
|
| 7 | + /** |
|
| 8 | + * Array of engine definitions using |
|
| 9 | + * file extension as key. |
|
| 10 | + * |
|
| 11 | + * @var array |
|
| 12 | + */ |
|
| 13 | + protected $engines = [ |
|
| 14 | + '.mustache.php' => 'Helmut\Forms\Engines\Mustache', |
|
| 15 | + '.twig.php' => 'Helmut\Forms\Engines\Twig', |
|
| 16 | + '.blade.php' => 'Helmut\Forms\Engines\Blade', |
|
| 17 | + ]; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Cache of running engines. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $running = []; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Cache of template files. |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $templates = []; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | 34 | * Add a new engine implementation. |
| 35 | 35 | * |
| 36 | - * @param string $extension |
|
| 37 | - * @param string $class |
|
| 36 | + * @param string $extension |
|
| 37 | + * @param string $class |
|
| 38 | 38 | * @return void |
| 39 | 39 | */ |
| 40 | - public function addEngine($extension, $class) |
|
| 41 | - { |
|
| 42 | - array_unshift($this->engines, [$extension => $class]); |
|
| 43 | - } |
|
| 40 | + public function addEngine($extension, $class) |
|
| 41 | + { |
|
| 42 | + array_unshift($this->engines, [$extension => $class]); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | + /** |
|
| 46 | 46 | * Get an engine implementation. |
| 47 | 47 | * |
| 48 | - * @param string $key |
|
| 48 | + * @param string $key |
|
| 49 | 49 | * @return \Helmut\Forms\Engine |
| 50 | 50 | */ |
| 51 | - public function start($key) |
|
| 52 | - { |
|
| 53 | - if ( ! isset($this->running[$key])) { |
|
| 54 | - $this->running[$key] = new $this->engines[$key]; |
|
| 55 | - } |
|
| 51 | + public function start($key) |
|
| 52 | + { |
|
| 53 | + if ( ! isset($this->running[$key])) { |
|
| 54 | + $this->running[$key] = new $this->engines[$key]; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return $this->running[$key]; |
|
| 58 | - } |
|
| 57 | + return $this->running[$key]; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | + /** |
|
| 61 | 61 | * Get engine file extensions. |
| 62 | 62 | * |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function extensions() |
|
| 66 | - { |
|
| 67 | - return array_keys($this->engines); |
|
| 68 | - } |
|
| 65 | + public function extensions() |
|
| 66 | + { |
|
| 67 | + return array_keys($this->engines); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 70 | + /** |
|
| 71 | 71 | * Create a template cache key. |
| 72 | 72 | * |
| 73 | - * @param string $name |
|
| 74 | - * @param array $paths |
|
| 73 | + * @param string $name |
|
| 74 | + * @param array $paths |
|
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public function key($template, $paths) |
|
| 78 | - { |
|
| 79 | - return $template.'-'.md5(serialize($paths)); |
|
| 80 | - } |
|
| 77 | + public function key($template, $paths) |
|
| 78 | + { |
|
| 79 | + return $template.'-'.md5(serialize($paths)); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 82 | + /** |
|
| 83 | 83 | * Render a template. |
| 84 | 84 | * |
| 85 | - * @param string $template |
|
| 86 | - * @param array $properties |
|
| 87 | - * @param array $paths |
|
| 85 | + * @param string $template |
|
| 86 | + * @param array $properties |
|
| 87 | + * @param array $paths |
|
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | - public function render($template, $properties, $paths) |
|
| 91 | - { |
|
| 92 | - if ($this->has($template, $paths)) { |
|
| 90 | + public function render($template, $properties, $paths) |
|
| 91 | + { |
|
| 92 | + if ($this->has($template, $paths)) { |
|
| 93 | 93 | |
| 94 | - $template = $this->findTemplate($template, $paths); |
|
| 94 | + $template = $this->findTemplate($template, $paths); |
|
| 95 | 95 | |
| 96 | - return $this->start($template['engine'])->render($template['path'], $properties); |
|
| 97 | - } |
|
| 98 | - } |
|
| 96 | + return $this->start($template['engine'])->render($template['path'], $properties); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 100 | + /** |
|
| 101 | 101 | * Check if a template exists. |
| 102 | 102 | * |
| 103 | - * @param string $key |
|
| 104 | - * @param string $template |
|
| 105 | - * @param array $paths |
|
| 103 | + * @param string $key |
|
| 104 | + * @param string $template |
|
| 105 | + * @param array $paths |
|
| 106 | 106 | * @return boolean |
| 107 | 107 | */ |
| 108 | - public function has($template, $paths) |
|
| 109 | - { |
|
| 110 | - return ! is_null($this->findTemplate($template, $paths)); |
|
| 111 | - } |
|
| 108 | + public function has($template, $paths) |
|
| 109 | + { |
|
| 110 | + return ! is_null($this->findTemplate($template, $paths)); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 113 | + /** |
|
| 114 | 114 | * Find template file with engine. |
| 115 | 115 | * |
| 116 | - * @param string $template |
|
| 117 | - * @param array $paths |
|
| 116 | + * @param string $template |
|
| 117 | + * @param array $paths |
|
| 118 | 118 | * @return void |
| 119 | 119 | */ |
| 120 | - public function findTemplate($template, $paths) |
|
| 121 | - { |
|
| 122 | - $key = $this->key($template, $paths); |
|
| 123 | - |
|
| 124 | - if ( ! isset($this->templates[$key])) { |
|
| 125 | - |
|
| 126 | - $this->templates[$key] = null; |
|
| 127 | - |
|
| 128 | - $extensions = $this->extensions(); |
|
| 129 | - foreach ($paths as $path) { |
|
| 130 | - foreach ($extensions as $extension) { |
|
| 131 | - if (file_exists($path.$template.$extension)) { |
|
| 132 | - return $this->templates[$key] = [ |
|
| 133 | - 'engine' => $extension, |
|
| 134 | - 'path' => $path.$template.$extension, |
|
| 135 | - ]; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $this->templates[$key]; |
|
| 142 | - } |
|
| 120 | + public function findTemplate($template, $paths) |
|
| 121 | + { |
|
| 122 | + $key = $this->key($template, $paths); |
|
| 123 | + |
|
| 124 | + if ( ! isset($this->templates[$key])) { |
|
| 125 | + |
|
| 126 | + $this->templates[$key] = null; |
|
| 127 | + |
|
| 128 | + $extensions = $this->extensions(); |
|
| 129 | + foreach ($paths as $path) { |
|
| 130 | + foreach ($extensions as $extension) { |
|
| 131 | + if (file_exists($path.$template.$extension)) { |
|
| 132 | + return $this->templates[$key] = [ |
|
| 133 | + 'engine' => $extension, |
|
| 134 | + 'path' => $path.$template.$extension, |
|
| 135 | + ]; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $this->templates[$key]; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | } |
@@ -1,9 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'required' => 'Este campo es obligatorio.', |
|
| 5 | - 'validate' => 'El campo [field] es inválido.', |
|
| 6 | - 'validate_required' => 'El campo [field] es obligatorio.', |
|
| 4 | + 'required' => 'Este campo es obligatorio.', |
|
| 5 | + 'validate' => 'El campo [field] es inválido.', |
|
| 6 | + 'validate_required' => 'El campo [field] es obligatorio.', |
|
| 7 | 7 | 'validate_alpha' => 'El campo [field] solo debe contener letras.', |
| 8 | 8 | 'validate_alpha_dash' => 'El campo [field] solo debe contener letras, números y guiones.', |
| 9 | 9 | 'validate_alpha_num' => 'El campo [field] solo debe contener letras y números.', |
@@ -1,9 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'required' => 'This field is required.', |
|
| 5 | - 'validate' => 'The [field] field is invalid.', |
|
| 6 | - 'validate_required' => 'The [field] field is required.', |
|
| 4 | + 'required' => 'This field is required.', |
|
| 5 | + 'validate' => 'The [field] field is invalid.', |
|
| 6 | + 'validate_required' => 'The [field] field is required.', |
|
| 7 | 7 | 'validate_alpha' => 'The [field] may only contain letters.', |
| 8 | 8 | 'validate_alpha_dash' => 'The [field] may only contain letters, numbers, and dashes.', |
| 9 | 9 | 'validate_alpha_num' => 'The [field] may only contain letters and numbers.', |
@@ -471,7 +471,7 @@ |
||
| 471 | 471 | |
| 472 | 472 | // Work out the argument names of the requested method |
| 473 | 473 | $method = new \ReflectionMethod($this, $name); |
| 474 | - foreach($method->getParameters() as $arg) { |
|
| 474 | + foreach ($method->getParameters() as $arg) { |
|
| 475 | 475 | $args[] = $arg->getName(); |
| 476 | 476 | } |
| 477 | 477 | |
@@ -347,7 +347,9 @@ discard block |
||
| 347 | 347 | return false; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - if (isset($this->errors[$method])) unset($this->errors[$method]); |
|
| 350 | + if (isset($this->errors[$method])) { |
|
| 351 | + unset($this->errors[$method]); |
|
| 352 | + } |
|
| 351 | 353 | |
| 352 | 354 | return true; |
| 353 | 355 | } |
@@ -389,7 +391,9 @@ discard block |
||
| 389 | 391 | */ |
| 390 | 392 | public function error($message) |
| 391 | 393 | { |
| 392 | - if ( ! isset($this->errors['userDefined'])) $this->errors['userDefined'] = []; |
|
| 394 | + if ( ! isset($this->errors['userDefined'])) { |
|
| 395 | + $this->errors['userDefined'] = []; |
|
| 396 | + } |
|
| 393 | 397 | |
| 394 | 398 | $this->errors['userDefined'][] = $message; |
| 395 | 399 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Memory extends Plugin { |
| 8 | 8 | |
| 9 | - // Protects input from accidental loss |
|
| 9 | + // Protects input from accidental loss |
|
| 10 | 10 | // by saving as you type. WIP |
| 11 | 11 | |
| 12 | 12 | } |
| 13 | 13 | \ No newline at end of file |
@@ -6,40 +6,40 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Feedback extends Plugin { |
| 8 | 8 | |
| 9 | - public function onLoad($form) |
|
| 10 | - { |
|
| 11 | - $form->addButton('feedback_trigger_'.$form->id); |
|
| 12 | - } |
|
| 9 | + public function onLoad($form) |
|
| 10 | + { |
|
| 11 | + $form->addButton('feedback_trigger_'.$form->id); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function onSubmitted($form) |
|
| 15 | - { |
|
| 16 | - $request = $form->getRequest(); |
|
| 14 | + public function onSubmitted($form) |
|
| 15 | + { |
|
| 16 | + $request = $form->getRequest(); |
|
| 17 | 17 | |
| 18 | - if ($request->get('feedback_trigger_'.$form->id)) { |
|
| 18 | + if ($request->get('feedback_trigger_'.$form->id)) { |
|
| 19 | 19 | |
| 20 | - $field = $form->field($request->get('name')); |
|
| 20 | + $field = $form->field($request->get('name')); |
|
| 21 | 21 | |
| 22 | - if ( ! is_null($field)) { |
|
| 22 | + if ( ! is_null($field)) { |
|
| 23 | 23 | |
| 24 | - $field->setFromRequest($request); |
|
| 25 | - $field->runValidations(); |
|
| 24 | + $field->setFromRequest($request); |
|
| 25 | + $field->runValidations(); |
|
| 26 | 26 | |
| 27 | - $response = [ |
|
| 28 | - 'id' => $field->id, |
|
| 29 | - 'valid' => $field->valid(), |
|
| 30 | - 'error_id' => 'feedback_errors_'.$field->id, |
|
| 31 | - 'error' => '', |
|
| 32 | - ]; |
|
| 27 | + $response = [ |
|
| 28 | + 'id' => $field->id, |
|
| 29 | + 'valid' => $field->valid(), |
|
| 30 | + 'error_id' => 'feedback_errors_'.$field->id, |
|
| 31 | + 'error' => '', |
|
| 32 | + ]; |
|
| 33 | 33 | |
| 34 | - if ( ! $field->valid()) { |
|
| 35 | - $response['error'] = $form->renderFieldErrors($field); |
|
| 36 | - } |
|
| 34 | + if ( ! $field->valid()) { |
|
| 35 | + $response['error'] = $form->renderFieldErrors($field); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - header('Content-Type: application/json'); |
|
| 39 | - echo json_encode($response); |
|
| 40 | - exit(); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 38 | + header('Content-Type: application/json'); |
|
| 39 | + echo json_encode($response); |
|
| 40 | + exit(); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | } |
| 46 | 46 | \ No newline at end of file |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'plugins' => [ |
|
| 5 | - 'feedback', |
|
| 6 | - ], |
|
| 4 | + 'plugins' => [ |
|
| 5 | + 'feedback', |
|
| 6 | + ], |
|
| 7 | 7 | ]; |
| 8 | 8 | \ No newline at end of file |