@@ -7,84 +7,84 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Customization |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @return array |
|
| 12 | - */ |
|
| 13 | - public function filterEditorSettings(array $settings) |
|
| 14 | - { |
|
| 15 | - if ($this->isReviewEditable()) { |
|
| 16 | - $settings = [ |
|
| 17 | - 'media_buttons' => false, |
|
| 18 | - 'quicktags' => false, |
|
| 19 | - 'textarea_rows' => 12, |
|
| 20 | - 'tinymce' => false, |
|
| 21 | - ]; |
|
| 22 | - } |
|
| 23 | - return $settings; |
|
| 24 | - } |
|
| 10 | + /** |
|
| 11 | + * @return array |
|
| 12 | + */ |
|
| 13 | + public function filterEditorSettings(array $settings) |
|
| 14 | + { |
|
| 15 | + if ($this->isReviewEditable()) { |
|
| 16 | + $settings = [ |
|
| 17 | + 'media_buttons' => false, |
|
| 18 | + 'quicktags' => false, |
|
| 19 | + 'textarea_rows' => 12, |
|
| 20 | + 'tinymce' => false, |
|
| 21 | + ]; |
|
| 22 | + } |
|
| 23 | + return $settings; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @param string $html |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function filterEditorTextarea($html) |
|
| 31 | - { |
|
| 32 | - if ($this->isReviewEditable()) { |
|
| 33 | - $html = str_replace('<textarea', '<div id="ed_toolbar"></div><textarea', $html); |
|
| 34 | - } |
|
| 35 | - return $html; |
|
| 36 | - } |
|
| 26 | + /** |
|
| 27 | + * @param string $html |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function filterEditorTextarea($html) |
|
| 31 | + { |
|
| 32 | + if ($this->isReviewEditable()) { |
|
| 33 | + $html = str_replace('<textarea', '<div id="ed_toolbar"></div><textarea', $html); |
|
| 34 | + } |
|
| 35 | + return $html; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - public function removeAutosave() |
|
| 42 | - { |
|
| 43 | - if (!$this->isReviewEditor() || $this->isReviewEditable()) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - wp_deregister_script('autosave'); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + public function removeAutosave() |
|
| 42 | + { |
|
| 43 | + if (!$this->isReviewEditor() || $this->isReviewEditable()) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + wp_deregister_script('autosave'); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - public function removeMetaBoxes() |
|
| 53 | - { |
|
| 54 | - remove_meta_box('slugdiv', Application::POST_TYPE, 'advanced'); |
|
| 55 | - } |
|
| 49 | + /** |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + public function removeMetaBoxes() |
|
| 53 | + { |
|
| 54 | + remove_meta_box('slugdiv', Application::POST_TYPE, 'advanced'); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return void |
|
| 59 | - */ |
|
| 60 | - public function removePostTypeSupport() |
|
| 61 | - { |
|
| 62 | - if (!$this->isReviewEditor() || $this->isReviewEditable()) { |
|
| 63 | - return; |
|
| 64 | - } |
|
| 65 | - remove_post_type_support(Application::POST_TYPE, 'title'); |
|
| 66 | - remove_post_type_support(Application::POST_TYPE, 'editor'); |
|
| 67 | - } |
|
| 57 | + /** |
|
| 58 | + * @return void |
|
| 59 | + */ |
|
| 60 | + public function removePostTypeSupport() |
|
| 61 | + { |
|
| 62 | + if (!$this->isReviewEditor() || $this->isReviewEditable()) { |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | + remove_post_type_support(Application::POST_TYPE, 'title'); |
|
| 66 | + remove_post_type_support(Application::POST_TYPE, 'editor'); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @return bool |
|
| 71 | - */ |
|
| 72 | - protected function isReviewEditable() |
|
| 73 | - { |
|
| 74 | - $postId = intval(filter_input(INPUT_GET, 'post')); |
|
| 75 | - return $postId > 0 |
|
| 76 | - && 'local' == glsr(Database::class)->get($postId, 'review_type') |
|
| 77 | - && $this->isReviewEditor(); |
|
| 78 | - } |
|
| 69 | + /** |
|
| 70 | + * @return bool |
|
| 71 | + */ |
|
| 72 | + protected function isReviewEditable() |
|
| 73 | + { |
|
| 74 | + $postId = intval(filter_input(INPUT_GET, 'post')); |
|
| 75 | + return $postId > 0 |
|
| 76 | + && 'local' == glsr(Database::class)->get($postId, 'review_type') |
|
| 77 | + && $this->isReviewEditor(); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return bool |
|
| 82 | - */ |
|
| 83 | - protected function isReviewEditor() |
|
| 84 | - { |
|
| 85 | - $screen = glsr_current_screen(); |
|
| 86 | - return 'post' == $screen->base |
|
| 87 | - && Application::POST_TYPE == $screen->id |
|
| 88 | - && Application::POST_TYPE == $screen->post_type; |
|
| 89 | - } |
|
| 80 | + /** |
|
| 81 | + * @return bool |
|
| 82 | + */ |
|
| 83 | + protected function isReviewEditor() |
|
| 84 | + { |
|
| 85 | + $screen = glsr_current_screen(); |
|
| 86 | + return 'post' == $screen->base |
|
| 87 | + && Application::POST_TYPE == $screen->id |
|
| 88 | + && Application::POST_TYPE == $screen->post_type; |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | |
| 8 | 8 | class EmailDefaults extends Defaults |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @return array |
|
| 12 | - */ |
|
| 13 | - protected function defaults() |
|
| 14 | - { |
|
| 15 | - return [ |
|
| 16 | - 'after' => '', |
|
| 17 | - 'attachments' => [], |
|
| 18 | - 'bcc' => '', |
|
| 19 | - 'before' => '', |
|
| 20 | - 'cc' => '', |
|
| 21 | - 'from' => $this->getFromName().' <'.$this->getFromEmail().'>', |
|
| 22 | - 'message' => '', |
|
| 23 | - 'reply-to' => '', |
|
| 24 | - 'subject' => '', |
|
| 25 | - 'template' => '', |
|
| 26 | - 'template-tags' => [], |
|
| 27 | - 'to' => '', |
|
| 28 | - ]; |
|
| 29 | - } |
|
| 10 | + /** |
|
| 11 | + * @return array |
|
| 12 | + */ |
|
| 13 | + protected function defaults() |
|
| 14 | + { |
|
| 15 | + return [ |
|
| 16 | + 'after' => '', |
|
| 17 | + 'attachments' => [], |
|
| 18 | + 'bcc' => '', |
|
| 19 | + 'before' => '', |
|
| 20 | + 'cc' => '', |
|
| 21 | + 'from' => $this->getFromName().' <'.$this->getFromEmail().'>', |
|
| 22 | + 'message' => '', |
|
| 23 | + 'reply-to' => '', |
|
| 24 | + 'subject' => '', |
|
| 25 | + 'template' => '', |
|
| 26 | + 'template-tags' => [], |
|
| 27 | + 'to' => '', |
|
| 28 | + ]; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - protected function getFromEmail() |
|
| 35 | - { |
|
| 36 | - return glsr(OptionManager::class)->getWP('admin_email'); |
|
| 37 | - } |
|
| 31 | + /** |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + protected function getFromEmail() |
|
| 35 | + { |
|
| 36 | + return glsr(OptionManager::class)->getWP('admin_email'); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - protected function getFromName() |
|
| 43 | - { |
|
| 44 | - return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + protected function getFromName() |
|
| 43 | + { |
|
| 44 | + return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -7,33 +7,33 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Metaboxes |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @param int $postId |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function saveAssignedToMetabox($postId) |
|
| 15 | - { |
|
| 16 | - if (!wp_verify_nonce(Helper::filterInput('_nonce-assigned-to'), 'assigned_to')) { |
|
| 17 | - return; |
|
| 18 | - } |
|
| 19 | - $assignedTo = strval(Helper::filterInput('assigned_to')); |
|
| 20 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
| 21 | - } |
|
| 10 | + /** |
|
| 11 | + * @param int $postId |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function saveAssignedToMetabox($postId) |
|
| 15 | + { |
|
| 16 | + if (!wp_verify_nonce(Helper::filterInput('_nonce-assigned-to'), 'assigned_to')) { |
|
| 17 | + return; |
|
| 18 | + } |
|
| 19 | + $assignedTo = strval(Helper::filterInput('assigned_to')); |
|
| 20 | + glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param int $postId |
|
| 25 | - * @return mixed |
|
| 26 | - */ |
|
| 27 | - public function saveResponseMetabox($postId) |
|
| 28 | - { |
|
| 29 | - if (!wp_verify_nonce(Helper::filterInput('_nonce-response'), 'response')) { |
|
| 30 | - return; |
|
| 31 | - } |
|
| 32 | - $response = strval(Helper::filterInput('response')); |
|
| 33 | - glsr(Database::class)->update($postId, 'response', trim(wp_kses($response, [ |
|
| 34 | - 'a' => ['href' => [], 'title' => []], |
|
| 35 | - 'em' => [], |
|
| 36 | - 'strong' => [], |
|
| 37 | - ]))); |
|
| 38 | - } |
|
| 23 | + /** |
|
| 24 | + * @param int $postId |
|
| 25 | + * @return mixed |
|
| 26 | + */ |
|
| 27 | + public function saveResponseMetabox($postId) |
|
| 28 | + { |
|
| 29 | + if (!wp_verify_nonce(Helper::filterInput('_nonce-response'), 'response')) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | + $response = strval(Helper::filterInput('response')); |
|
| 33 | + glsr(Database::class)->update($postId, 'response', trim(wp_kses($response, [ |
|
| 34 | + 'a' => ['href' => [], 'title' => []], |
|
| 35 | + 'em' => [], |
|
| 36 | + 'strong' => [], |
|
| 37 | + ]))); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -13,248 +13,248 @@ |
||
| 13 | 13 | |
| 14 | 14 | abstract class BaseType implements ArrayAccess, JsonSerializable, Type |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $allowed = []; |
|
| 16 | + /** |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $allowed = []; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - public $parents = []; |
|
| 21 | + /** |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + public $parents = []; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $properties = []; |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $properties = []; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $type; |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $type; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param string $method |
|
| 38 | - * @return static |
|
| 39 | - */ |
|
| 40 | - public function __call($method, array $arguments) |
|
| 41 | - { |
|
| 42 | - return $this->setProperty($method, Arr::get($arguments, 0)); |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * @param string $method |
|
| 38 | + * @return static |
|
| 39 | + */ |
|
| 40 | + public function __call($method, array $arguments) |
|
| 41 | + { |
|
| 42 | + return $this->setProperty($method, Arr::get($arguments, 0)); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $type |
|
| 47 | - */ |
|
| 48 | - public function __construct($type = null) |
|
| 49 | - { |
|
| 50 | - $this->type = !is_string($type) |
|
| 51 | - ? (new ReflectionClass($this))->getShortName() |
|
| 52 | - : $type; |
|
| 53 | - $this->setAllowedProperties(); |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * @param string $type |
|
| 47 | + */ |
|
| 48 | + public function __construct($type = null) |
|
| 49 | + { |
|
| 50 | + $this->type = !is_string($type) |
|
| 51 | + ? (new ReflectionClass($this))->getShortName() |
|
| 52 | + : $type; |
|
| 53 | + $this->setAllowedProperties(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function __toString() |
|
| 60 | - { |
|
| 61 | - return $this->toScript(); |
|
| 62 | - } |
|
| 56 | + /** |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function __toString() |
|
| 60 | + { |
|
| 61 | + return $this->toScript(); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return static |
|
| 66 | - */ |
|
| 67 | - public function addProperties(array $properties) |
|
| 68 | - { |
|
| 69 | - foreach ($properties as $property => $value) { |
|
| 70 | - $this->setProperty($property, $value); |
|
| 71 | - } |
|
| 72 | - return $this; |
|
| 73 | - } |
|
| 64 | + /** |
|
| 65 | + * @return static |
|
| 66 | + */ |
|
| 67 | + public function addProperties(array $properties) |
|
| 68 | + { |
|
| 69 | + foreach ($properties as $property => $value) { |
|
| 70 | + $this->setProperty($property, $value); |
|
| 71 | + } |
|
| 72 | + return $this; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function getContext() |
|
| 79 | - { |
|
| 80 | - return 'https://schema.org'; |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function getContext() |
|
| 79 | + { |
|
| 80 | + return 'https://schema.org'; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @return array |
|
| 85 | - */ |
|
| 86 | - public function getProperties() |
|
| 87 | - { |
|
| 88 | - return $this->properties; |
|
| 89 | - } |
|
| 83 | + /** |
|
| 84 | + * @return array |
|
| 85 | + */ |
|
| 86 | + public function getProperties() |
|
| 87 | + { |
|
| 88 | + return $this->properties; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @param string $property |
|
| 93 | - * @param mixed $default |
|
| 94 | - * @return mixed |
|
| 95 | - */ |
|
| 96 | - public function getProperty($property, $default = null) |
|
| 97 | - { |
|
| 98 | - return Arr::get($this->properties, $property, $default); |
|
| 99 | - } |
|
| 91 | + /** |
|
| 92 | + * @param string $property |
|
| 93 | + * @param mixed $default |
|
| 94 | + * @return mixed |
|
| 95 | + */ |
|
| 96 | + public function getProperty($property, $default = null) |
|
| 97 | + { |
|
| 98 | + return Arr::get($this->properties, $property, $default); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - public function getType() |
|
| 105 | - { |
|
| 106 | - return $this->type; |
|
| 107 | - } |
|
| 101 | + /** |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + public function getType() |
|
| 105 | + { |
|
| 106 | + return $this->type; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @param bool $condition |
|
| 111 | - * @param mixed $callback |
|
| 112 | - * @return static |
|
| 113 | - */ |
|
| 114 | - public function doIf($condition, $callback) |
|
| 115 | - { |
|
| 116 | - if ($condition) { |
|
| 117 | - $callback($this); |
|
| 118 | - } |
|
| 119 | - return $this; |
|
| 120 | - } |
|
| 109 | + /** |
|
| 110 | + * @param bool $condition |
|
| 111 | + * @param mixed $callback |
|
| 112 | + * @return static |
|
| 113 | + */ |
|
| 114 | + public function doIf($condition, $callback) |
|
| 115 | + { |
|
| 116 | + if ($condition) { |
|
| 117 | + $callback($this); |
|
| 118 | + } |
|
| 119 | + return $this; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function jsonSerialize() |
|
| 126 | - { |
|
| 127 | - return $this->toArray(); |
|
| 128 | - } |
|
| 122 | + /** |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function jsonSerialize() |
|
| 126 | + { |
|
| 127 | + return $this->toArray(); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @param mixed $offset |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function offsetExists($offset) |
|
| 135 | - { |
|
| 136 | - return array_key_exists($offset, $this->properties); |
|
| 137 | - } |
|
| 130 | + /** |
|
| 131 | + * @param mixed $offset |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function offsetExists($offset) |
|
| 135 | + { |
|
| 136 | + return array_key_exists($offset, $this->properties); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * @param string $offset |
|
| 141 | - * @return mixed |
|
| 142 | - */ |
|
| 143 | - public function offsetGet($offset) |
|
| 144 | - { |
|
| 145 | - return $this->getProperty($offset); |
|
| 146 | - } |
|
| 139 | + /** |
|
| 140 | + * @param string $offset |
|
| 141 | + * @return mixed |
|
| 142 | + */ |
|
| 143 | + public function offsetGet($offset) |
|
| 144 | + { |
|
| 145 | + return $this->getProperty($offset); |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * @param string $offset |
|
| 150 | - * @param mixed $value |
|
| 151 | - * @return void |
|
| 152 | - */ |
|
| 153 | - public function offsetSet($offset, $value) |
|
| 154 | - { |
|
| 155 | - $this->setProperty($offset, $value); |
|
| 156 | - } |
|
| 148 | + /** |
|
| 149 | + * @param string $offset |
|
| 150 | + * @param mixed $value |
|
| 151 | + * @return void |
|
| 152 | + */ |
|
| 153 | + public function offsetSet($offset, $value) |
|
| 154 | + { |
|
| 155 | + $this->setProperty($offset, $value); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * @param string $offset |
|
| 160 | - * @return void |
|
| 161 | - */ |
|
| 162 | - public function offsetUnset($offset) |
|
| 163 | - { |
|
| 164 | - unset($this->properties[$offset]); |
|
| 165 | - } |
|
| 158 | + /** |
|
| 159 | + * @param string $offset |
|
| 160 | + * @return void |
|
| 161 | + */ |
|
| 162 | + public function offsetUnset($offset) |
|
| 163 | + { |
|
| 164 | + unset($this->properties[$offset]); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @param string $property |
|
| 169 | - * @param mixed $value |
|
| 170 | - * @return static |
|
| 171 | - */ |
|
| 172 | - public function setProperty($property, $value) |
|
| 173 | - { |
|
| 174 | - if (!in_array($property, $this->allowed) |
|
| 175 | - && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
| 176 | - glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
| 177 | - return $this; |
|
| 178 | - } |
|
| 179 | - $this->properties[$property] = $value; |
|
| 180 | - return $this; |
|
| 181 | - } |
|
| 167 | + /** |
|
| 168 | + * @param string $property |
|
| 169 | + * @param mixed $value |
|
| 170 | + * @return static |
|
| 171 | + */ |
|
| 172 | + public function setProperty($property, $value) |
|
| 173 | + { |
|
| 174 | + if (!in_array($property, $this->allowed) |
|
| 175 | + && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
| 176 | + glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
| 177 | + return $this; |
|
| 178 | + } |
|
| 179 | + $this->properties[$property] = $value; |
|
| 180 | + return $this; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * @return array |
|
| 185 | - */ |
|
| 186 | - public function toArray() |
|
| 187 | - { |
|
| 188 | - return [ |
|
| 189 | - '@context' => $this->getContext(), |
|
| 190 | - '@type' => $this->getType(), |
|
| 191 | - ] + $this->serializeProperty($this->getProperties()); |
|
| 192 | - } |
|
| 183 | + /** |
|
| 184 | + * @return array |
|
| 185 | + */ |
|
| 186 | + public function toArray() |
|
| 187 | + { |
|
| 188 | + return [ |
|
| 189 | + '@context' => $this->getContext(), |
|
| 190 | + '@type' => $this->getType(), |
|
| 191 | + ] + $this->serializeProperty($this->getProperties()); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * @return string |
|
| 196 | - */ |
|
| 197 | - public function toScript() |
|
| 198 | - { |
|
| 199 | - return sprintf('<script type="application/ld+json">%s</script>', |
|
| 200 | - json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
| 201 | - ); |
|
| 202 | - } |
|
| 194 | + /** |
|
| 195 | + * @return string |
|
| 196 | + */ |
|
| 197 | + public function toScript() |
|
| 198 | + { |
|
| 199 | + return sprintf('<script type="application/ld+json">%s</script>', |
|
| 200 | + json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * @param array|null $parents |
|
| 206 | - * @return array |
|
| 207 | - */ |
|
| 208 | - protected function getParents($parents = null) |
|
| 209 | - { |
|
| 210 | - if (!isset($parents)) { |
|
| 211 | - $parents = $this->parents; |
|
| 212 | - } |
|
| 213 | - $newParents = $parents; |
|
| 214 | - foreach ($parents as $parent) { |
|
| 215 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
| 216 | - if (!class_exists($parentClass)) { |
|
| 217 | - continue; |
|
| 218 | - } |
|
| 219 | - $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
| 220 | - } |
|
| 221 | - return array_values(array_unique($newParents)); |
|
| 222 | - } |
|
| 204 | + /** |
|
| 205 | + * @param array|null $parents |
|
| 206 | + * @return array |
|
| 207 | + */ |
|
| 208 | + protected function getParents($parents = null) |
|
| 209 | + { |
|
| 210 | + if (!isset($parents)) { |
|
| 211 | + $parents = $this->parents; |
|
| 212 | + } |
|
| 213 | + $newParents = $parents; |
|
| 214 | + foreach ($parents as $parent) { |
|
| 215 | + $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
| 216 | + if (!class_exists($parentClass)) { |
|
| 217 | + continue; |
|
| 218 | + } |
|
| 219 | + $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
| 220 | + } |
|
| 221 | + return array_values(array_unique($newParents)); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * @return void |
|
| 226 | - */ |
|
| 227 | - protected function setAllowedProperties() |
|
| 228 | - { |
|
| 229 | - $parents = $this->getParents(); |
|
| 230 | - foreach ($parents as $parent) { |
|
| 231 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
| 232 | - if (!class_exists($parentClass)) { |
|
| 233 | - continue; |
|
| 234 | - } |
|
| 235 | - $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
| 236 | - } |
|
| 237 | - } |
|
| 224 | + /** |
|
| 225 | + * @return void |
|
| 226 | + */ |
|
| 227 | + protected function setAllowedProperties() |
|
| 228 | + { |
|
| 229 | + $parents = $this->getParents(); |
|
| 230 | + foreach ($parents as $parent) { |
|
| 231 | + $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
| 232 | + if (!class_exists($parentClass)) { |
|
| 233 | + continue; |
|
| 234 | + } |
|
| 235 | + $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * @param mixed $property |
|
| 241 | - * @return array|string |
|
| 242 | - */ |
|
| 243 | - protected function serializeProperty($property) |
|
| 244 | - { |
|
| 245 | - if (is_array($property)) { |
|
| 246 | - return array_map([$this, 'serializeProperty'], $property); |
|
| 247 | - } |
|
| 248 | - if ($property instanceof Type) { |
|
| 249 | - $property = $property->toArray(); |
|
| 250 | - unset($property['@context']); |
|
| 251 | - } |
|
| 252 | - if ($property instanceof DateTimeInterface) { |
|
| 253 | - $property = $property->format(DateTime::ATOM); |
|
| 254 | - } |
|
| 255 | - if (is_object($property)) { |
|
| 256 | - throw new InvalidProperty(); |
|
| 257 | - } |
|
| 258 | - return $property; |
|
| 259 | - } |
|
| 239 | + /** |
|
| 240 | + * @param mixed $property |
|
| 241 | + * @return array|string |
|
| 242 | + */ |
|
| 243 | + protected function serializeProperty($property) |
|
| 244 | + { |
|
| 245 | + if (is_array($property)) { |
|
| 246 | + return array_map([$this, 'serializeProperty'], $property); |
|
| 247 | + } |
|
| 248 | + if ($property instanceof Type) { |
|
| 249 | + $property = $property->toArray(); |
|
| 250 | + unset($property['@context']); |
|
| 251 | + } |
|
| 252 | + if ($property instanceof DateTimeInterface) { |
|
| 253 | + $property = $property->format(DateTime::ATOM); |
|
| 254 | + } |
|
| 255 | + if (is_object($property)) { |
|
| 256 | + throw new InvalidProperty(); |
|
| 257 | + } |
|
| 258 | + return $property; |
|
| 259 | + } |
|
| 260 | 260 | } |
@@ -12,302 +12,302 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Validator |
| 14 | 14 | { |
| 15 | - use ValidationRules; |
|
| 15 | + use ValidationRules; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - public $errors = []; |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + public $errors = []; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The data under validation. |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - protected $data = []; |
|
| 22 | + /** |
|
| 23 | + * The data under validation. |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + protected $data = []; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The failed validation rules. |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $failedRules = []; |
|
| 28 | + /** |
|
| 29 | + * The failed validation rules. |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $failedRules = []; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The rules to be applied to the data. |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $rules = []; |
|
| 34 | + /** |
|
| 35 | + * The rules to be applied to the data. |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $rules = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The size related validation rules. |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - protected $sizeRules = [ |
|
| 45 | - 'Between', 'Max', 'Min', |
|
| 46 | - ]; |
|
| 40 | + /** |
|
| 41 | + * The size related validation rules. |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + protected $sizeRules = [ |
|
| 45 | + 'Between', 'Max', 'Min', |
|
| 46 | + ]; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * The validation rules that imply the field is required. |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - protected $implicitRules = [ |
|
| 53 | - 'Required', |
|
| 54 | - ]; |
|
| 48 | + /** |
|
| 49 | + * The validation rules that imply the field is required. |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + protected $implicitRules = [ |
|
| 53 | + 'Required', |
|
| 54 | + ]; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * The numeric related validation rules. |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - protected $numericRules = [ |
|
| 61 | - 'Number', |
|
| 62 | - ]; |
|
| 56 | + /** |
|
| 57 | + * The numeric related validation rules. |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + protected $numericRules = [ |
|
| 61 | + 'Number', |
|
| 62 | + ]; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Run the validator's rules against its data. |
|
| 66 | - * @param mixed $data |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function validate($data, array $rules = []) |
|
| 70 | - { |
|
| 71 | - $this->normalizeData($data); |
|
| 72 | - $this->setRules($rules); |
|
| 73 | - foreach ($this->rules as $attribute => $rules) { |
|
| 74 | - foreach ($rules as $rule) { |
|
| 75 | - $this->validateAttribute($attribute, $rule); |
|
| 76 | - if ($this->shouldStopValidating($attribute)) { |
|
| 77 | - break; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - return $this->errors; |
|
| 82 | - } |
|
| 64 | + /** |
|
| 65 | + * Run the validator's rules against its data. |
|
| 66 | + * @param mixed $data |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function validate($data, array $rules = []) |
|
| 70 | + { |
|
| 71 | + $this->normalizeData($data); |
|
| 72 | + $this->setRules($rules); |
|
| 73 | + foreach ($this->rules as $attribute => $rules) { |
|
| 74 | + foreach ($rules as $rule) { |
|
| 75 | + $this->validateAttribute($attribute, $rule); |
|
| 76 | + if ($this->shouldStopValidating($attribute)) { |
|
| 77 | + break; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + return $this->errors; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Validate a given attribute against a rule. |
|
| 86 | - * @param string $attribute |
|
| 87 | - * @param string $rule |
|
| 88 | - * @return void |
|
| 89 | - * @throws BadMethodCallException |
|
| 90 | - */ |
|
| 91 | - public function validateAttribute($attribute, $rule) |
|
| 92 | - { |
|
| 93 | - list($rule, $parameters) = $this->parseRule($rule); |
|
| 94 | - if ('' == $rule) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - $value = $this->getValue($attribute); |
|
| 98 | - if (!method_exists($this, $method = 'validate'.$rule)) { |
|
| 99 | - throw new BadMethodCallException("Method [$method] does not exist."); |
|
| 100 | - } |
|
| 101 | - if (!$this->$method($value, $attribute, $parameters)) { |
|
| 102 | - $this->addFailure($attribute, $rule, $parameters); |
|
| 103 | - } |
|
| 104 | - } |
|
| 84 | + /** |
|
| 85 | + * Validate a given attribute against a rule. |
|
| 86 | + * @param string $attribute |
|
| 87 | + * @param string $rule |
|
| 88 | + * @return void |
|
| 89 | + * @throws BadMethodCallException |
|
| 90 | + */ |
|
| 91 | + public function validateAttribute($attribute, $rule) |
|
| 92 | + { |
|
| 93 | + list($rule, $parameters) = $this->parseRule($rule); |
|
| 94 | + if ('' == $rule) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + $value = $this->getValue($attribute); |
|
| 98 | + if (!method_exists($this, $method = 'validate'.$rule)) { |
|
| 99 | + throw new BadMethodCallException("Method [$method] does not exist."); |
|
| 100 | + } |
|
| 101 | + if (!$this->$method($value, $attribute, $parameters)) { |
|
| 102 | + $this->addFailure($attribute, $rule, $parameters); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Add an error message to the validator's collection of errors. |
|
| 108 | - * @param string $attribute |
|
| 109 | - * @param string $rule |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - protected function addError($attribute, $rule, array $parameters) |
|
| 113 | - { |
|
| 114 | - $message = $this->getMessage($attribute, $rule, $parameters); |
|
| 115 | - $this->errors[$attribute][] = $message; |
|
| 116 | - } |
|
| 106 | + /** |
|
| 107 | + * Add an error message to the validator's collection of errors. |
|
| 108 | + * @param string $attribute |
|
| 109 | + * @param string $rule |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + protected function addError($attribute, $rule, array $parameters) |
|
| 113 | + { |
|
| 114 | + $message = $this->getMessage($attribute, $rule, $parameters); |
|
| 115 | + $this->errors[$attribute][] = $message; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Add a failed rule and error message to the collection. |
|
| 120 | - * @param string $attribute |
|
| 121 | - * @param string $rule |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - protected function addFailure($attribute, $rule, array $parameters) |
|
| 125 | - { |
|
| 126 | - $this->addError($attribute, $rule, $parameters); |
|
| 127 | - $this->failedRules[$attribute][$rule] = $parameters; |
|
| 128 | - } |
|
| 118 | + /** |
|
| 119 | + * Add a failed rule and error message to the collection. |
|
| 120 | + * @param string $attribute |
|
| 121 | + * @param string $rule |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + protected function addFailure($attribute, $rule, array $parameters) |
|
| 125 | + { |
|
| 126 | + $this->addError($attribute, $rule, $parameters); |
|
| 127 | + $this->failedRules[$attribute][$rule] = $parameters; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Get the data type of the given attribute. |
|
| 132 | - * @param string $attribute |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - protected function getAttributeType($attribute) |
|
| 136 | - { |
|
| 137 | - return !$this->hasRule($attribute, $this->numericRules) |
|
| 138 | - ? 'length' |
|
| 139 | - : ''; |
|
| 140 | - } |
|
| 130 | + /** |
|
| 131 | + * Get the data type of the given attribute. |
|
| 132 | + * @param string $attribute |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + protected function getAttributeType($attribute) |
|
| 136 | + { |
|
| 137 | + return !$this->hasRule($attribute, $this->numericRules) |
|
| 138 | + ? 'length' |
|
| 139 | + : ''; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Get the validation message for an attribute and rule. |
|
| 144 | - * @param string $attribute |
|
| 145 | - * @param string $rule |
|
| 146 | - * @return string|null |
|
| 147 | - */ |
|
| 148 | - protected function getMessage($attribute, $rule, array $parameters) |
|
| 149 | - { |
|
| 150 | - if (in_array($rule, $this->sizeRules)) { |
|
| 151 | - return $this->getSizeMessage($attribute, $rule, $parameters); |
|
| 152 | - } |
|
| 153 | - $lowerRule = Str::snakeCase($rule); |
|
| 154 | - return $this->translator($lowerRule, $parameters); |
|
| 155 | - } |
|
| 142 | + /** |
|
| 143 | + * Get the validation message for an attribute and rule. |
|
| 144 | + * @param string $attribute |
|
| 145 | + * @param string $rule |
|
| 146 | + * @return string|null |
|
| 147 | + */ |
|
| 148 | + protected function getMessage($attribute, $rule, array $parameters) |
|
| 149 | + { |
|
| 150 | + if (in_array($rule, $this->sizeRules)) { |
|
| 151 | + return $this->getSizeMessage($attribute, $rule, $parameters); |
|
| 152 | + } |
|
| 153 | + $lowerRule = Str::snakeCase($rule); |
|
| 154 | + return $this->translator($lowerRule, $parameters); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Get a rule and its parameters for a given attribute. |
|
| 159 | - * @param string $attribute |
|
| 160 | - * @param string|array $rules |
|
| 161 | - * @return array|null |
|
| 162 | - */ |
|
| 163 | - protected function getRule($attribute, $rules) |
|
| 164 | - { |
|
| 165 | - if (!array_key_exists($attribute, $this->rules)) { |
|
| 166 | - return; |
|
| 167 | - } |
|
| 168 | - $rules = (array) $rules; |
|
| 169 | - foreach ($this->rules[$attribute] as $rule) { |
|
| 170 | - list($rule, $parameters) = $this->parseRule($rule); |
|
| 171 | - if (in_array($rule, $rules)) { |
|
| 172 | - return [$rule, $parameters]; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 157 | + /** |
|
| 158 | + * Get a rule and its parameters for a given attribute. |
|
| 159 | + * @param string $attribute |
|
| 160 | + * @param string|array $rules |
|
| 161 | + * @return array|null |
|
| 162 | + */ |
|
| 163 | + protected function getRule($attribute, $rules) |
|
| 164 | + { |
|
| 165 | + if (!array_key_exists($attribute, $this->rules)) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 168 | + $rules = (array) $rules; |
|
| 169 | + foreach ($this->rules[$attribute] as $rule) { |
|
| 170 | + list($rule, $parameters) = $this->parseRule($rule); |
|
| 171 | + if (in_array($rule, $rules)) { |
|
| 172 | + return [$rule, $parameters]; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Get the size of an attribute. |
|
| 179 | - * @param string $attribute |
|
| 180 | - * @param mixed $value |
|
| 181 | - * @return mixed |
|
| 182 | - */ |
|
| 183 | - protected function getSize($attribute, $value) |
|
| 184 | - { |
|
| 185 | - $hasNumeric = $this->hasRule($attribute, $this->numericRules); |
|
| 186 | - if (is_numeric($value) && $hasNumeric) { |
|
| 187 | - return $value; |
|
| 188 | - } elseif (is_array($value)) { |
|
| 189 | - return count($value); |
|
| 190 | - } |
|
| 191 | - return function_exists('mb_strlen') |
|
| 192 | - ? mb_strlen($value) |
|
| 193 | - : strlen($value); |
|
| 194 | - } |
|
| 177 | + /** |
|
| 178 | + * Get the size of an attribute. |
|
| 179 | + * @param string $attribute |
|
| 180 | + * @param mixed $value |
|
| 181 | + * @return mixed |
|
| 182 | + */ |
|
| 183 | + protected function getSize($attribute, $value) |
|
| 184 | + { |
|
| 185 | + $hasNumeric = $this->hasRule($attribute, $this->numericRules); |
|
| 186 | + if (is_numeric($value) && $hasNumeric) { |
|
| 187 | + return $value; |
|
| 188 | + } elseif (is_array($value)) { |
|
| 189 | + return count($value); |
|
| 190 | + } |
|
| 191 | + return function_exists('mb_strlen') |
|
| 192 | + ? mb_strlen($value) |
|
| 193 | + : strlen($value); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Get the proper error message for an attribute and size rule. |
|
| 198 | - * @param string $attribute |
|
| 199 | - * @param string $rule |
|
| 200 | - * @return string|null |
|
| 201 | - */ |
|
| 202 | - protected function getSizeMessage($attribute, $rule, array $parameters) |
|
| 203 | - { |
|
| 204 | - $type = $this->getAttributeType($attribute); |
|
| 205 | - $lowerRule = Str::snakeCase($rule.$type); |
|
| 206 | - return $this->translator($lowerRule, $parameters); |
|
| 207 | - } |
|
| 196 | + /** |
|
| 197 | + * Get the proper error message for an attribute and size rule. |
|
| 198 | + * @param string $attribute |
|
| 199 | + * @param string $rule |
|
| 200 | + * @return string|null |
|
| 201 | + */ |
|
| 202 | + protected function getSizeMessage($attribute, $rule, array $parameters) |
|
| 203 | + { |
|
| 204 | + $type = $this->getAttributeType($attribute); |
|
| 205 | + $lowerRule = Str::snakeCase($rule.$type); |
|
| 206 | + return $this->translator($lowerRule, $parameters); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Get the value of a given attribute. |
|
| 211 | - * @param string $attribute |
|
| 212 | - * @return mixed |
|
| 213 | - */ |
|
| 214 | - protected function getValue($attribute) |
|
| 215 | - { |
|
| 216 | - if (isset($this->data[$attribute])) { |
|
| 217 | - return $this->data[$attribute]; |
|
| 218 | - } |
|
| 219 | - } |
|
| 209 | + /** |
|
| 210 | + * Get the value of a given attribute. |
|
| 211 | + * @param string $attribute |
|
| 212 | + * @return mixed |
|
| 213 | + */ |
|
| 214 | + protected function getValue($attribute) |
|
| 215 | + { |
|
| 216 | + if (isset($this->data[$attribute])) { |
|
| 217 | + return $this->data[$attribute]; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Determine if the given attribute has a rule in the given set. |
|
| 223 | - * @param string $attribute |
|
| 224 | - * @param string|array $rules |
|
| 225 | - * @return bool |
|
| 226 | - */ |
|
| 227 | - protected function hasRule($attribute, $rules) |
|
| 228 | - { |
|
| 229 | - return !is_null($this->getRule($attribute, $rules)); |
|
| 230 | - } |
|
| 221 | + /** |
|
| 222 | + * Determine if the given attribute has a rule in the given set. |
|
| 223 | + * @param string $attribute |
|
| 224 | + * @param string|array $rules |
|
| 225 | + * @return bool |
|
| 226 | + */ |
|
| 227 | + protected function hasRule($attribute, $rules) |
|
| 228 | + { |
|
| 229 | + return !is_null($this->getRule($attribute, $rules)); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Normalize the provided data to an array. |
|
| 234 | - * @param mixed $data |
|
| 235 | - * @return void |
|
| 236 | - */ |
|
| 237 | - protected function normalizeData($data) |
|
| 238 | - { |
|
| 239 | - $this->data = is_object($data) |
|
| 240 | - ? get_object_vars($data) |
|
| 241 | - : $data; |
|
| 242 | - } |
|
| 232 | + /** |
|
| 233 | + * Normalize the provided data to an array. |
|
| 234 | + * @param mixed $data |
|
| 235 | + * @return void |
|
| 236 | + */ |
|
| 237 | + protected function normalizeData($data) |
|
| 238 | + { |
|
| 239 | + $this->data = is_object($data) |
|
| 240 | + ? get_object_vars($data) |
|
| 241 | + : $data; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * Parse a parameter list. |
|
| 246 | - * @param string $rule |
|
| 247 | - * @param string $parameter |
|
| 248 | - * @return array |
|
| 249 | - */ |
|
| 250 | - protected function parseParameters($rule, $parameter) |
|
| 251 | - { |
|
| 252 | - return 'regex' == strtolower($rule) |
|
| 253 | - ? [$parameter] |
|
| 254 | - : str_getcsv($parameter); |
|
| 255 | - } |
|
| 244 | + /** |
|
| 245 | + * Parse a parameter list. |
|
| 246 | + * @param string $rule |
|
| 247 | + * @param string $parameter |
|
| 248 | + * @return array |
|
| 249 | + */ |
|
| 250 | + protected function parseParameters($rule, $parameter) |
|
| 251 | + { |
|
| 252 | + return 'regex' == strtolower($rule) |
|
| 253 | + ? [$parameter] |
|
| 254 | + : str_getcsv($parameter); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - /** |
|
| 258 | - * Extract the rule name and parameters from a rule. |
|
| 259 | - * @param string $rule |
|
| 260 | - * @return array |
|
| 261 | - */ |
|
| 262 | - protected function parseRule($rule) |
|
| 263 | - { |
|
| 264 | - $parameters = []; |
|
| 265 | - if (Str::contains($rule, ':')) { |
|
| 266 | - list($rule, $parameter) = explode(':', $rule, 2); |
|
| 267 | - $parameters = $this->parseParameters($rule, $parameter); |
|
| 268 | - } |
|
| 269 | - $rule = Str::camelCase($rule); |
|
| 270 | - return [$rule, $parameters]; |
|
| 271 | - } |
|
| 257 | + /** |
|
| 258 | + * Extract the rule name and parameters from a rule. |
|
| 259 | + * @param string $rule |
|
| 260 | + * @return array |
|
| 261 | + */ |
|
| 262 | + protected function parseRule($rule) |
|
| 263 | + { |
|
| 264 | + $parameters = []; |
|
| 265 | + if (Str::contains($rule, ':')) { |
|
| 266 | + list($rule, $parameter) = explode(':', $rule, 2); |
|
| 267 | + $parameters = $this->parseParameters($rule, $parameter); |
|
| 268 | + } |
|
| 269 | + $rule = Str::camelCase($rule); |
|
| 270 | + return [$rule, $parameters]; |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * Set the validation rules. |
|
| 275 | - * @return void |
|
| 276 | - */ |
|
| 277 | - protected function setRules(array $rules) |
|
| 278 | - { |
|
| 279 | - foreach ($rules as $key => $rule) { |
|
| 280 | - $rules[$key] = is_string($rule) |
|
| 281 | - ? explode('|', $rule) |
|
| 282 | - : $rule; |
|
| 283 | - } |
|
| 284 | - $this->rules = $rules; |
|
| 285 | - } |
|
| 273 | + /** |
|
| 274 | + * Set the validation rules. |
|
| 275 | + * @return void |
|
| 276 | + */ |
|
| 277 | + protected function setRules(array $rules) |
|
| 278 | + { |
|
| 279 | + foreach ($rules as $key => $rule) { |
|
| 280 | + $rules[$key] = is_string($rule) |
|
| 281 | + ? explode('|', $rule) |
|
| 282 | + : $rule; |
|
| 283 | + } |
|
| 284 | + $this->rules = $rules; |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * Check if we should stop further validations on a given attribute. |
|
| 289 | - * @param string $attribute |
|
| 290 | - * @return bool |
|
| 291 | - */ |
|
| 292 | - protected function shouldStopValidating($attribute) |
|
| 293 | - { |
|
| 294 | - return $this->hasRule($attribute, $this->implicitRules) |
|
| 295 | - && isset($this->failedRules[$attribute]) |
|
| 296 | - && array_intersect(array_keys($this->failedRules[$attribute]), $this->implicitRules); |
|
| 297 | - } |
|
| 287 | + /** |
|
| 288 | + * Check if we should stop further validations on a given attribute. |
|
| 289 | + * @param string $attribute |
|
| 290 | + * @return bool |
|
| 291 | + */ |
|
| 292 | + protected function shouldStopValidating($attribute) |
|
| 293 | + { |
|
| 294 | + return $this->hasRule($attribute, $this->implicitRules) |
|
| 295 | + && isset($this->failedRules[$attribute]) |
|
| 296 | + && array_intersect(array_keys($this->failedRules[$attribute]), $this->implicitRules); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Returns a translated message for the attribute. |
|
| 301 | - * @param string $key |
|
| 302 | - * @param string $attribute |
|
| 303 | - * @return void|string |
|
| 304 | - */ |
|
| 305 | - protected function translator($key, array $parameters) |
|
| 306 | - { |
|
| 307 | - $strings = glsr(ValidationStringsDefaults::class)->defaults(); |
|
| 308 | - if (isset($strings[$key])) { |
|
| 309 | - return $this->replace($strings[$key], $parameters); |
|
| 310 | - } |
|
| 311 | - return 'error'; |
|
| 312 | - } |
|
| 299 | + /** |
|
| 300 | + * Returns a translated message for the attribute. |
|
| 301 | + * @param string $key |
|
| 302 | + * @param string $attribute |
|
| 303 | + * @return void|string |
|
| 304 | + */ |
|
| 305 | + protected function translator($key, array $parameters) |
|
| 306 | + { |
|
| 307 | + $strings = glsr(ValidationStringsDefaults::class)->defaults(); |
|
| 308 | + if (isset($strings[$key])) { |
|
| 309 | + return $this->replace($strings[$key], $parameters); |
|
| 310 | + } |
|
| 311 | + return 'error'; |
|
| 312 | + } |
|
| 313 | 313 | } |
@@ -6,22 +6,22 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ValidateReviewDefaults extends Defaults |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return array |
|
| 11 | - */ |
|
| 12 | - protected function defaults() |
|
| 13 | - { |
|
| 14 | - return [ |
|
| 15 | - 'assign_to' => '', |
|
| 16 | - 'category' => '', |
|
| 17 | - 'content' => '', |
|
| 18 | - 'email' => '', |
|
| 19 | - 'form_id' => '', |
|
| 20 | - 'ip_address' => '', |
|
| 21 | - 'name' => '', |
|
| 22 | - 'rating' => '0', |
|
| 23 | - 'terms' => '', |
|
| 24 | - 'title' => '', |
|
| 25 | - ]; |
|
| 26 | - } |
|
| 9 | + /** |
|
| 10 | + * @return array |
|
| 11 | + */ |
|
| 12 | + protected function defaults() |
|
| 13 | + { |
|
| 14 | + return [ |
|
| 15 | + 'assign_to' => '', |
|
| 16 | + 'category' => '', |
|
| 17 | + 'content' => '', |
|
| 18 | + 'email' => '', |
|
| 19 | + 'form_id' => '', |
|
| 20 | + 'ip_address' => '', |
|
| 21 | + 'name' => '', |
|
| 22 | + 'rating' => '0', |
|
| 23 | + 'terms' => '', |
|
| 24 | + 'title' => '', |
|
| 25 | + ]; |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -6,23 +6,23 @@ |
||
| 6 | 6 | |
| 7 | 7 | class StyleValidationDefaults extends Defaults |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return array |
|
| 11 | - */ |
|
| 12 | - protected function defaults() |
|
| 13 | - { |
|
| 14 | - return [ |
|
| 15 | - 'error_tag' => 'div', |
|
| 16 | - 'error_tag_class' => 'glsr-field-error', |
|
| 17 | - 'field_class' => 'glsr-field', |
|
| 18 | - 'field_error_class' => 'glsr-has-error', |
|
| 19 | - 'input_error_class' => 'glsr-is-invalid', |
|
| 20 | - 'input_valid_class' => 'glsr-is-valid', |
|
| 21 | - 'message_error_class' => 'glsr-has-errors', |
|
| 22 | - 'message_initial_class' => 'glsr-is-visible', |
|
| 23 | - 'message_success_class' => 'glsr-has-success', |
|
| 24 | - 'message_tag' => 'div', |
|
| 25 | - 'message_tag_class' => 'glsr-form-message', |
|
| 26 | - ]; |
|
| 27 | - } |
|
| 9 | + /** |
|
| 10 | + * @return array |
|
| 11 | + */ |
|
| 12 | + protected function defaults() |
|
| 13 | + { |
|
| 14 | + return [ |
|
| 15 | + 'error_tag' => 'div', |
|
| 16 | + 'error_tag_class' => 'glsr-field-error', |
|
| 17 | + 'field_class' => 'glsr-field', |
|
| 18 | + 'field_error_class' => 'glsr-has-error', |
|
| 19 | + 'input_error_class' => 'glsr-is-invalid', |
|
| 20 | + 'input_valid_class' => 'glsr-is-valid', |
|
| 21 | + 'message_error_class' => 'glsr-has-errors', |
|
| 22 | + 'message_initial_class' => 'glsr-is-visible', |
|
| 23 | + 'message_success_class' => 'glsr-has-success', |
|
| 24 | + 'message_tag' => 'div', |
|
| 25 | + 'message_tag_class' => 'glsr-form-message', |
|
| 26 | + ]; |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -14,52 +14,52 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Multilingual |
| 16 | 16 | { |
| 17 | - protected $integration; |
|
| 17 | + protected $integration; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param string $method |
|
| 21 | - * @param array $args |
|
| 22 | - * @return |
|
| 23 | - */ |
|
| 24 | - public function __call($method, $args = []) |
|
| 25 | - { |
|
| 26 | - if ($this->isIntegrated() && method_exists($this->integration, $method)) { |
|
| 27 | - return call_user_func_array([$this->integration, $method], $args); |
|
| 28 | - } |
|
| 29 | - return Arr::get($args, 0, false); |
|
| 30 | - } |
|
| 19 | + /** |
|
| 20 | + * @param string $method |
|
| 21 | + * @param array $args |
|
| 22 | + * @return |
|
| 23 | + */ |
|
| 24 | + public function __call($method, $args = []) |
|
| 25 | + { |
|
| 26 | + if ($this->isIntegrated() && method_exists($this->integration, $method)) { |
|
| 27 | + return call_user_func_array([$this->integration, $method], $args); |
|
| 28 | + } |
|
| 29 | + return Arr::get($args, 0, false); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param string $integration |
|
| 34 | - * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
|
| 35 | - */ |
|
| 36 | - public function getIntegration($integration = '') |
|
| 37 | - { |
|
| 38 | - if (empty($integration)) { |
|
| 39 | - $integration = glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
| 40 | - } |
|
| 41 | - if (!empty($integration)) { |
|
| 42 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.ucfirst($integration); |
|
| 43 | - if (class_exists($integrationClass)) { |
|
| 44 | - return glsr($integrationClass); |
|
| 45 | - } |
|
| 46 | - glsr_log()->error($integrationClass.' does not exist'); |
|
| 47 | - } |
|
| 48 | - return false; |
|
| 49 | - } |
|
| 32 | + /** |
|
| 33 | + * @param string $integration |
|
| 34 | + * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
|
| 35 | + */ |
|
| 36 | + public function getIntegration($integration = '') |
|
| 37 | + { |
|
| 38 | + if (empty($integration)) { |
|
| 39 | + $integration = glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
| 40 | + } |
|
| 41 | + if (!empty($integration)) { |
|
| 42 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.ucfirst($integration); |
|
| 43 | + if (class_exists($integrationClass)) { |
|
| 44 | + return glsr($integrationClass); |
|
| 45 | + } |
|
| 46 | + glsr_log()->error($integrationClass.' does not exist'); |
|
| 47 | + } |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * return bool |
|
| 53 | - */ |
|
| 54 | - public function isIntegrated() |
|
| 55 | - { |
|
| 56 | - if (!empty($this->integration)) { |
|
| 57 | - return true; |
|
| 58 | - } |
|
| 59 | - if ($integration = $this->getIntegration()) { |
|
| 60 | - $this->integration = $integration; |
|
| 61 | - return true; |
|
| 62 | - } |
|
| 63 | - return false; |
|
| 64 | - } |
|
| 51 | + /** |
|
| 52 | + * return bool |
|
| 53 | + */ |
|
| 54 | + public function isIntegrated() |
|
| 55 | + { |
|
| 56 | + if (!empty($this->integration)) { |
|
| 57 | + return true; |
|
| 58 | + } |
|
| 59 | + if ($integration = $this->getIntegration()) { |
|
| 60 | + $this->integration = $integration; |
|
| 61 | + return true; |
|
| 62 | + } |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -10,126 +10,126 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | trait ValidationRules |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Get the size of an attribute. |
|
| 15 | - * @param string $attribute |
|
| 16 | - * @param mixed $value |
|
| 17 | - * @return mixed |
|
| 18 | - */ |
|
| 19 | - abstract protected function getSize($attribute, $value); |
|
| 13 | + /** |
|
| 14 | + * Get the size of an attribute. |
|
| 15 | + * @param string $attribute |
|
| 16 | + * @param mixed $value |
|
| 17 | + * @return mixed |
|
| 18 | + */ |
|
| 19 | + abstract protected function getSize($attribute, $value); |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Replace all placeholders. |
|
| 23 | - * @param string $message |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - protected function replace($message, array $parameters) |
|
| 27 | - { |
|
| 28 | - if (!Str::contains($message, '%s')) { |
|
| 29 | - return $message; |
|
| 30 | - } |
|
| 31 | - return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
| 32 | - foreach ($parameters as $key => $value) { |
|
| 33 | - return array_shift($parameters); |
|
| 34 | - } |
|
| 35 | - }, $message); |
|
| 36 | - } |
|
| 21 | + /** |
|
| 22 | + * Replace all placeholders. |
|
| 23 | + * @param string $message |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + protected function replace($message, array $parameters) |
|
| 27 | + { |
|
| 28 | + if (!Str::contains($message, '%s')) { |
|
| 29 | + return $message; |
|
| 30 | + } |
|
| 31 | + return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
| 32 | + foreach ($parameters as $key => $value) { |
|
| 33 | + return array_shift($parameters); |
|
| 34 | + } |
|
| 35 | + }, $message); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Validate that an attribute was "accepted". |
|
| 40 | - * This validation rule implies the attribute is "required". |
|
| 41 | - * @param string $attribute |
|
| 42 | - * @param mixed $value |
|
| 43 | - * @return bool |
|
| 44 | - */ |
|
| 45 | - public function validateAccepted($value) |
|
| 46 | - { |
|
| 47 | - $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
|
| 48 | - return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
| 49 | - } |
|
| 38 | + /** |
|
| 39 | + * Validate that an attribute was "accepted". |
|
| 40 | + * This validation rule implies the attribute is "required". |
|
| 41 | + * @param string $attribute |
|
| 42 | + * @param mixed $value |
|
| 43 | + * @return bool |
|
| 44 | + */ |
|
| 45 | + public function validateAccepted($value) |
|
| 46 | + { |
|
| 47 | + $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
|
| 48 | + return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Validate the size of an attribute is between a set of values. |
|
| 53 | - * @param string $attribute |
|
| 54 | - * @param mixed $value |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public function validateBetween($value, $attribute, array $parameters) |
|
| 58 | - { |
|
| 59 | - $this->requireParameterCount(2, $parameters, 'between'); |
|
| 60 | - $size = $this->getSize($attribute, $value); |
|
| 61 | - return $size >= $parameters[0] && $size <= $parameters[1]; |
|
| 62 | - } |
|
| 51 | + /** |
|
| 52 | + * Validate the size of an attribute is between a set of values. |
|
| 53 | + * @param string $attribute |
|
| 54 | + * @param mixed $value |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public function validateBetween($value, $attribute, array $parameters) |
|
| 58 | + { |
|
| 59 | + $this->requireParameterCount(2, $parameters, 'between'); |
|
| 60 | + $size = $this->getSize($attribute, $value); |
|
| 61 | + return $size >= $parameters[0] && $size <= $parameters[1]; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Validate that an attribute is a valid e-mail address. |
|
| 66 | - * @param mixed $value |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function validateEmail($value) |
|
| 70 | - { |
|
| 71 | - return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * Validate that an attribute is a valid e-mail address. |
|
| 66 | + * @param mixed $value |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function validateEmail($value) |
|
| 70 | + { |
|
| 71 | + return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Validate the size of an attribute is less than a maximum value. |
|
| 76 | - * @param string $attribute |
|
| 77 | - * @param mixed $value |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public function validateMax($value, $attribute, array $parameters) |
|
| 81 | - { |
|
| 82 | - $this->requireParameterCount(1, $parameters, 'max'); |
|
| 83 | - return $this->getSize($attribute, $value) <= $parameters[0]; |
|
| 84 | - } |
|
| 74 | + /** |
|
| 75 | + * Validate the size of an attribute is less than a maximum value. |
|
| 76 | + * @param string $attribute |
|
| 77 | + * @param mixed $value |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public function validateMax($value, $attribute, array $parameters) |
|
| 81 | + { |
|
| 82 | + $this->requireParameterCount(1, $parameters, 'max'); |
|
| 83 | + return $this->getSize($attribute, $value) <= $parameters[0]; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Validate the size of an attribute is greater than a minimum value. |
|
| 88 | - * @param string $attribute |
|
| 89 | - * @param mixed $value |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function validateMin($value, $attribute, array $parameters) |
|
| 93 | - { |
|
| 94 | - $this->requireParameterCount(1, $parameters, 'min'); |
|
| 95 | - return $this->getSize($attribute, $value) >= $parameters[0]; |
|
| 96 | - } |
|
| 86 | + /** |
|
| 87 | + * Validate the size of an attribute is greater than a minimum value. |
|
| 88 | + * @param string $attribute |
|
| 89 | + * @param mixed $value |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function validateMin($value, $attribute, array $parameters) |
|
| 93 | + { |
|
| 94 | + $this->requireParameterCount(1, $parameters, 'min'); |
|
| 95 | + return $this->getSize($attribute, $value) >= $parameters[0]; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Validate that an attribute is numeric. |
|
| 100 | - * @param mixed $value |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 103 | - public function validateNumber($value) |
|
| 104 | - { |
|
| 105 | - return is_numeric($value); |
|
| 106 | - } |
|
| 98 | + /** |
|
| 99 | + * Validate that an attribute is numeric. |
|
| 100 | + * @param mixed $value |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | + public function validateNumber($value) |
|
| 104 | + { |
|
| 105 | + return is_numeric($value); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Validate that a required attribute exists. |
|
| 110 | - * @param mixed $value |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function validateRequired($value) |
|
| 114 | - { |
|
| 115 | - return is_null($value) |
|
| 116 | - || (is_string($value) && in_array(trim($value), ['', '[]'])) |
|
| 117 | - || (is_array($value) && empty($value)) |
|
| 118 | - ? false |
|
| 119 | - : true; |
|
| 120 | - } |
|
| 108 | + /** |
|
| 109 | + * Validate that a required attribute exists. |
|
| 110 | + * @param mixed $value |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function validateRequired($value) |
|
| 114 | + { |
|
| 115 | + return is_null($value) |
|
| 116 | + || (is_string($value) && in_array(trim($value), ['', '[]'])) |
|
| 117 | + || (is_array($value) && empty($value)) |
|
| 118 | + ? false |
|
| 119 | + : true; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Require a certain number of parameters to be present. |
|
| 124 | - * @param int $count |
|
| 125 | - * @param string $rule |
|
| 126 | - * @return void |
|
| 127 | - * @throws InvalidArgumentException |
|
| 128 | - */ |
|
| 129 | - protected function requireParameterCount($count, array $parameters, $rule) |
|
| 130 | - { |
|
| 131 | - if (count($parameters) < $count) { |
|
| 132 | - throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
| 133 | - } |
|
| 134 | - } |
|
| 122 | + /** |
|
| 123 | + * Require a certain number of parameters to be present. |
|
| 124 | + * @param int $count |
|
| 125 | + * @param string $rule |
|
| 126 | + * @return void |
|
| 127 | + * @throws InvalidArgumentException |
|
| 128 | + */ |
|
| 129 | + protected function requireParameterCount($count, array $parameters, $rule) |
|
| 130 | + { |
|
| 131 | + if (count($parameters) < $count) { |
|
| 132 | + throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | } |