@@ -7,18 +7,18 @@ |
||
7 | 7 | |
8 | 8 | class RegisterShortcodes |
9 | 9 | { |
10 | - /** |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function handle(Command $command) |
|
14 | - { |
|
15 | - foreach ($command->shortcodes as $shortcode) { |
|
16 | - $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
17 | - if (!class_exists($shortcodeClass)) { |
|
18 | - glsr_log()->error(sprintf('Class missing (%s)', $shortcodeClass)); |
|
19 | - continue; |
|
20 | - } |
|
21 | - add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
22 | - } |
|
23 | - } |
|
10 | + /** |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function handle(Command $command) |
|
14 | + { |
|
15 | + foreach ($command->shortcodes as $shortcode) { |
|
16 | + $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
17 | + if (!class_exists($shortcodeClass)) { |
|
18 | + glsr_log()->error(sprintf('Class missing (%s)', $shortcodeClass)); |
|
19 | + continue; |
|
20 | + } |
|
21 | + add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
22 | + } |
|
23 | + } |
|
24 | 24 | } |
@@ -7,22 +7,22 @@ |
||
7 | 7 | |
8 | 8 | class RegisterTinymcePopups |
9 | 9 | { |
10 | - /** |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function handle(Command $command) |
|
14 | - { |
|
15 | - foreach ($command->popups as $slug => $label) { |
|
16 | - $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
17 | - if (!class_exists($buttonClass)) { |
|
18 | - glsr_log()->error(sprintf('Class missing (%s)', $buttonClass)); |
|
19 | - continue; |
|
20 | - } |
|
21 | - $shortcode = glsr($buttonClass)->register($slug, [ |
|
22 | - 'label' => $label, |
|
23 | - 'title' => $label, |
|
24 | - ]); |
|
25 | - glsr()->mceShortcodes[$slug] = $shortcode->properties; |
|
26 | - } |
|
27 | - } |
|
10 | + /** |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function handle(Command $command) |
|
14 | + { |
|
15 | + foreach ($command->popups as $slug => $label) { |
|
16 | + $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
17 | + if (!class_exists($buttonClass)) { |
|
18 | + glsr_log()->error(sprintf('Class missing (%s)', $buttonClass)); |
|
19 | + continue; |
|
20 | + } |
|
21 | + $shortcode = glsr($buttonClass)->register($slug, [ |
|
22 | + 'label' => $label, |
|
23 | + 'title' => $label, |
|
24 | + ]); |
|
25 | + glsr()->mceShortcodes[$slug] = $shortcode->properties; |
|
26 | + } |
|
27 | + } |
|
28 | 28 | } |
@@ -6,60 +6,60 @@ |
||
6 | 6 | |
7 | 7 | class DefaultsManager |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function defaults() |
|
13 | - { |
|
14 | - $settings = $this->settings(); |
|
15 | - $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
16 | - return wp_parse_args($defaults, [ |
|
17 | - 'version' => '', |
|
18 | - 'version_upgraded_from' => '', |
|
19 | - ]); |
|
20 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function defaults() |
|
13 | + { |
|
14 | + $settings = $this->settings(); |
|
15 | + $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
16 | + return wp_parse_args($defaults, [ |
|
17 | + 'version' => '', |
|
18 | + 'version_upgraded_from' => '', |
|
19 | + ]); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return array |
|
24 | - */ |
|
25 | - public function get() |
|
26 | - { |
|
27 | - return Arr::convertDotNotationArray($this->defaults()); |
|
28 | - } |
|
22 | + /** |
|
23 | + * @return array |
|
24 | + */ |
|
25 | + public function get() |
|
26 | + { |
|
27 | + return Arr::convertDotNotationArray($this->defaults()); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function set() |
|
34 | - { |
|
35 | - $settings = glsr(OptionManager::class)->all(); |
|
36 | - $currentSettings = Arr::removeEmptyArrayValues($settings); |
|
37 | - $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
38 | - $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
39 | - update_option(OptionManager::databaseKey(), $updatedSettings); |
|
40 | - return $defaultSettings; |
|
41 | - } |
|
30 | + /** |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function set() |
|
34 | + { |
|
35 | + $settings = glsr(OptionManager::class)->all(); |
|
36 | + $currentSettings = Arr::removeEmptyArrayValues($settings); |
|
37 | + $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
38 | + $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
39 | + update_option(OptionManager::databaseKey(), $updatedSettings); |
|
40 | + return $defaultSettings; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function settings() |
|
47 | - { |
|
48 | - $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
49 | - return $this->normalize($settings); |
|
50 | - } |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function settings() |
|
47 | + { |
|
48 | + $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
49 | + return $this->normalize($settings); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - protected function normalize(array $settings) |
|
56 | - { |
|
57 | - array_walk($settings, function (&$setting) { |
|
58 | - if (isset($setting['default'])) { |
|
59 | - return; |
|
60 | - } |
|
61 | - $setting['default'] = ''; |
|
62 | - }); |
|
63 | - return $settings; |
|
64 | - } |
|
52 | + /** |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + protected function normalize(array $settings) |
|
56 | + { |
|
57 | + array_walk($settings, function (&$setting) { |
|
58 | + if (isset($setting['default'])) { |
|
59 | + return; |
|
60 | + } |
|
61 | + $setting['default'] = ''; |
|
62 | + }); |
|
63 | + return $settings; |
|
64 | + } |
|
65 | 65 | } |
@@ -9,77 +9,77 @@ |
||
9 | 9 | |
10 | 10 | class RegisterPostType |
11 | 11 | { |
12 | - public $args; |
|
13 | - public $columns; |
|
14 | - public $plural; |
|
15 | - public $postType; |
|
16 | - public $single; |
|
12 | + public $args; |
|
13 | + public $columns; |
|
14 | + public $plural; |
|
15 | + public $postType; |
|
16 | + public $single; |
|
17 | 17 | |
18 | - public function __construct($input) |
|
19 | - { |
|
20 | - $args = glsr(PostTypeDefaults::class)->merge($input); |
|
21 | - $this->normalize($args); |
|
22 | - $this->normalizeColumns(); |
|
23 | - $this->normalizeLabels(); |
|
24 | - } |
|
18 | + public function __construct($input) |
|
19 | + { |
|
20 | + $args = glsr(PostTypeDefaults::class)->merge($input); |
|
21 | + $this->normalize($args); |
|
22 | + $this->normalizeColumns(); |
|
23 | + $this->normalizeLabels(); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - protected function normalize(array $args) |
|
30 | - { |
|
31 | - foreach ($args as $key => $value) { |
|
32 | - $property = Helper::buildPropertyName($key); |
|
33 | - if (!property_exists($this, $property)) { |
|
34 | - continue; |
|
35 | - } |
|
36 | - $this->$property = $value; |
|
37 | - unset($args[$key]); |
|
38 | - } |
|
39 | - $this->args = wp_parse_args($args, [ |
|
40 | - 'menu_name' => $this->plural, |
|
41 | - ]); |
|
42 | - } |
|
26 | + /** |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + protected function normalize(array $args) |
|
30 | + { |
|
31 | + foreach ($args as $key => $value) { |
|
32 | + $property = Helper::buildPropertyName($key); |
|
33 | + if (!property_exists($this, $property)) { |
|
34 | + continue; |
|
35 | + } |
|
36 | + $this->$property = $value; |
|
37 | + unset($args[$key]); |
|
38 | + } |
|
39 | + $this->args = wp_parse_args($args, [ |
|
40 | + 'menu_name' => $this->plural, |
|
41 | + ]); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - protected function normalizeLabels() |
|
48 | - { |
|
49 | - $this->args['labels'] = wp_parse_args($this->args['labels'], [ |
|
50 | - 'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural), |
|
51 | - 'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural), |
|
52 | - 'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single), |
|
53 | - 'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single), |
|
54 | - 'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single), |
|
55 | - 'menu_name' => $this->args['menu_name'], |
|
56 | - 'name' => $this->plural, |
|
57 | - 'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single), |
|
58 | - 'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural), |
|
59 | - 'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural), |
|
60 | - 'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural), |
|
61 | - 'singular_name' => $this->single, |
|
62 | - 'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single), |
|
63 | - 'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single), |
|
64 | - ]); |
|
65 | - unset($this->args['menu_name']); |
|
66 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + protected function normalizeLabels() |
|
48 | + { |
|
49 | + $this->args['labels'] = wp_parse_args($this->args['labels'], [ |
|
50 | + 'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural), |
|
51 | + 'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural), |
|
52 | + 'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single), |
|
53 | + 'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single), |
|
54 | + 'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single), |
|
55 | + 'menu_name' => $this->args['menu_name'], |
|
56 | + 'name' => $this->plural, |
|
57 | + 'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single), |
|
58 | + 'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural), |
|
59 | + 'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural), |
|
60 | + 'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural), |
|
61 | + 'singular_name' => $this->single, |
|
62 | + 'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single), |
|
63 | + 'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single), |
|
64 | + ]); |
|
65 | + unset($this->args['menu_name']); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - protected function normalizeColumns() |
|
72 | - { |
|
73 | - $this->columns = ['cb' => ''] + $this->columns; |
|
74 | - if (array_key_exists('category', $this->columns)) { |
|
75 | - $keys = array_keys($this->columns); |
|
76 | - $keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY; |
|
77 | - $this->columns = array_combine($keys, $this->columns); |
|
78 | - } |
|
79 | - if (array_key_exists('pinned', $this->columns)) { |
|
80 | - $this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>', |
|
81 | - ['class' => 'pinned-icon'] |
|
82 | - ); |
|
83 | - } |
|
84 | - } |
|
68 | + /** |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + protected function normalizeColumns() |
|
72 | + { |
|
73 | + $this->columns = ['cb' => ''] + $this->columns; |
|
74 | + if (array_key_exists('category', $this->columns)) { |
|
75 | + $keys = array_keys($this->columns); |
|
76 | + $keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY; |
|
77 | + $this->columns = array_combine($keys, $this->columns); |
|
78 | + } |
|
79 | + if (array_key_exists('pinned', $this->columns)) { |
|
80 | + $this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>', |
|
81 | + ['class' => 'pinned-icon'] |
|
82 | + ); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |
@@ -7,162 +7,162 @@ |
||
7 | 7 | |
8 | 8 | class Router |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - protected $unguardedActions = []; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + protected $unguardedActions = []; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [ |
|
18 | - 'dismiss-notice', |
|
19 | - 'fetch-paged-reviews', |
|
20 | - ]); |
|
21 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [ |
|
18 | + 'dismiss-notice', |
|
19 | + 'fetch-paged-reviews', |
|
20 | + ]); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function routeAdminPostRequest() |
|
27 | - { |
|
28 | - $request = $this->getRequest(); |
|
29 | - if (!$this->isValidPostRequest($request)) { |
|
30 | - return; |
|
31 | - } |
|
32 | - check_admin_referer($request['_action']); |
|
33 | - $this->routeRequest('admin', $request['_action'], $request); |
|
34 | - } |
|
23 | + /** |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function routeAdminPostRequest() |
|
27 | + { |
|
28 | + $request = $this->getRequest(); |
|
29 | + if (!$this->isValidPostRequest($request)) { |
|
30 | + return; |
|
31 | + } |
|
32 | + check_admin_referer($request['_action']); |
|
33 | + $this->routeRequest('admin', $request['_action'], $request); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function routeAjaxRequest() |
|
40 | - { |
|
41 | - $request = $this->getRequest(); |
|
42 | - $this->checkAjaxRequest($request); |
|
43 | - $this->checkAjaxNonce($request); |
|
44 | - $this->routeRequest('ajax', $request['_action'], $request); |
|
45 | - wp_die(); |
|
46 | - } |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function routeAjaxRequest() |
|
40 | + { |
|
41 | + $request = $this->getRequest(); |
|
42 | + $this->checkAjaxRequest($request); |
|
43 | + $this->checkAjaxNonce($request); |
|
44 | + $this->routeRequest('ajax', $request['_action'], $request); |
|
45 | + wp_die(); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function routePublicPostRequest() |
|
52 | - { |
|
53 | - if (is_admin()) { |
|
54 | - return; |
|
55 | - } |
|
56 | - $request = $this->getRequest(); |
|
57 | - if (!$this->isValidPostRequest($request)) { |
|
58 | - return; |
|
59 | - } |
|
60 | - if (!$this->isValidPublicNonce($request)) { |
|
61 | - return; |
|
62 | - } |
|
63 | - $this->routeRequest('public', $request['_action'], $request); |
|
64 | - } |
|
48 | + /** |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function routePublicPostRequest() |
|
52 | + { |
|
53 | + if (is_admin()) { |
|
54 | + return; |
|
55 | + } |
|
56 | + $request = $this->getRequest(); |
|
57 | + if (!$this->isValidPostRequest($request)) { |
|
58 | + return; |
|
59 | + } |
|
60 | + if (!$this->isValidPublicNonce($request)) { |
|
61 | + return; |
|
62 | + } |
|
63 | + $this->routeRequest('public', $request['_action'], $request); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function checkAjaxNonce(array $request) |
|
70 | - { |
|
71 | - if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) { |
|
72 | - return; |
|
73 | - } |
|
74 | - if (!isset($request['_nonce'])) { |
|
75 | - $this->sendAjaxError('request is missing a nonce', $request); |
|
76 | - } |
|
77 | - if (!wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
78 | - $this->sendAjaxError('request failed the nonce check', $request, 403); |
|
79 | - } |
|
80 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function checkAjaxNonce(array $request) |
|
70 | + { |
|
71 | + if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) { |
|
72 | + return; |
|
73 | + } |
|
74 | + if (!isset($request['_nonce'])) { |
|
75 | + $this->sendAjaxError('request is missing a nonce', $request); |
|
76 | + } |
|
77 | + if (!wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
78 | + $this->sendAjaxError('request failed the nonce check', $request, 403); |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return void |
|
84 | - */ |
|
85 | - protected function checkAjaxRequest(array $request) |
|
86 | - { |
|
87 | - if (!isset($request['_action'])) { |
|
88 | - $this->sendAjaxError('request must include an action', $request); |
|
89 | - } |
|
90 | - if (empty($request['_ajax_request'])) { |
|
91 | - $this->sendAjaxError('request is invalid', $request); |
|
92 | - } |
|
93 | - } |
|
82 | + /** |
|
83 | + * @return void |
|
84 | + */ |
|
85 | + protected function checkAjaxRequest(array $request) |
|
86 | + { |
|
87 | + if (!isset($request['_action'])) { |
|
88 | + $this->sendAjaxError('request must include an action', $request); |
|
89 | + } |
|
90 | + if (empty($request['_ajax_request'])) { |
|
91 | + $this->sendAjaxError('request is invalid', $request); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * All ajax requests in the plugin are triggered by a single action hook: glsr_action, |
|
97 | - * while each ajax route is determined by $_POST[request][_action]. |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - protected function getRequest() |
|
101 | - { |
|
102 | - $request = Helper::filterInputArray(Application::ID); |
|
103 | - if (Helper::filterInput('action') == Application::PREFIX.'action') { |
|
104 | - $request['_ajax_request'] = true; |
|
105 | - } |
|
106 | - if ('submit-review' == Helper::filterInput('_action', $request)) { |
|
107 | - $request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response'); |
|
108 | - } |
|
109 | - return $request; |
|
110 | - } |
|
95 | + /** |
|
96 | + * All ajax requests in the plugin are triggered by a single action hook: glsr_action, |
|
97 | + * while each ajax route is determined by $_POST[request][_action]. |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + protected function getRequest() |
|
101 | + { |
|
102 | + $request = Helper::filterInputArray(Application::ID); |
|
103 | + if (Helper::filterInput('action') == Application::PREFIX.'action') { |
|
104 | + $request['_ajax_request'] = true; |
|
105 | + } |
|
106 | + if ('submit-review' == Helper::filterInput('_action', $request)) { |
|
107 | + $request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response'); |
|
108 | + } |
|
109 | + return $request; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - protected function isValidPostRequest(array $request = []) |
|
116 | - { |
|
117 | - return !empty($request['_action']) && empty($request['_ajax_request']); |
|
118 | - } |
|
112 | + /** |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + protected function isValidPostRequest(array $request = []) |
|
116 | + { |
|
117 | + return !empty($request['_action']) && empty($request['_ajax_request']); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - protected function isValidPublicNonce(array $request) |
|
124 | - { |
|
125 | - if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
126 | - glsr_log()->error('nonce check failed for public request')->debug($request); |
|
127 | - return false; |
|
128 | - } |
|
129 | - return true; |
|
130 | - } |
|
120 | + /** |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + protected function isValidPublicNonce(array $request) |
|
124 | + { |
|
125 | + if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
126 | + glsr_log()->error('nonce check failed for public request')->debug($request); |
|
127 | + return false; |
|
128 | + } |
|
129 | + return true; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @param string $type |
|
134 | - * @param string $action |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - protected function routeRequest($type, $action, array $request = []) |
|
138 | - { |
|
139 | - $actionHook = 'site-reviews/route/'.$type.'/request'; |
|
140 | - $controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers')); |
|
141 | - $method = Helper::buildMethodName($action, 'router'); |
|
142 | - $request = apply_filters('site-reviews/route/request', $request, $action, $type); |
|
143 | - do_action($actionHook, $action, $request); |
|
144 | - if (is_callable([$controller, $method])) { |
|
145 | - call_user_func([$controller, $method], $request); |
|
146 | - return; |
|
147 | - } |
|
148 | - if (0 === did_action($actionHook)) { |
|
149 | - glsr_log('Unknown '.$type.' router request: '.$action); |
|
150 | - } |
|
151 | - } |
|
132 | + /** |
|
133 | + * @param string $type |
|
134 | + * @param string $action |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + protected function routeRequest($type, $action, array $request = []) |
|
138 | + { |
|
139 | + $actionHook = 'site-reviews/route/'.$type.'/request'; |
|
140 | + $controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers')); |
|
141 | + $method = Helper::buildMethodName($action, 'router'); |
|
142 | + $request = apply_filters('site-reviews/route/request', $request, $action, $type); |
|
143 | + do_action($actionHook, $action, $request); |
|
144 | + if (is_callable([$controller, $method])) { |
|
145 | + call_user_func([$controller, $method], $request); |
|
146 | + return; |
|
147 | + } |
|
148 | + if (0 === did_action($actionHook)) { |
|
149 | + glsr_log('Unknown '.$type.' router request: '.$action); |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param string $error |
|
155 | - * @param int $statusCode |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - protected function sendAjaxError($error, array $request, $statusCode = 400) |
|
159 | - { |
|
160 | - glsr_log()->error($error)->debug($request); |
|
161 | - glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>'); |
|
162 | - wp_send_json_error([ |
|
163 | - 'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'), |
|
164 | - 'notices' => glsr(Notice::class)->get(), |
|
165 | - 'error' => $error, |
|
166 | - ]); |
|
167 | - } |
|
153 | + /** |
|
154 | + * @param string $error |
|
155 | + * @param int $statusCode |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + protected function sendAjaxError($error, array $request, $statusCode = 400) |
|
159 | + { |
|
160 | + glsr_log()->error($error)->debug($request); |
|
161 | + glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>'); |
|
162 | + wp_send_json_error([ |
|
163 | + 'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'), |
|
164 | + 'notices' => glsr(Notice::class)->get(), |
|
165 | + 'error' => $error, |
|
166 | + ]); |
|
167 | + } |
|
168 | 168 | } |
@@ -8,97 +8,97 @@ |
||
8 | 8 | |
9 | 9 | class TaxonomyController |
10 | 10 | { |
11 | - /** |
|
12 | - * @return void |
|
13 | - * @action Application::TAXONOMY._add_form_fields |
|
14 | - * @action Application::TAXONOMY._edit_form |
|
15 | - */ |
|
16 | - public function disableParents() |
|
17 | - { |
|
18 | - global $wp_taxonomies; |
|
19 | - $wp_taxonomies[Application::TAXONOMY]->hierarchical = false; |
|
20 | - } |
|
11 | + /** |
|
12 | + * @return void |
|
13 | + * @action Application::TAXONOMY._add_form_fields |
|
14 | + * @action Application::TAXONOMY._edit_form |
|
15 | + */ |
|
16 | + public function disableParents() |
|
17 | + { |
|
18 | + global $wp_taxonomies; |
|
19 | + $wp_taxonomies[Application::TAXONOMY]->hierarchical = false; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return void |
|
24 | - * @action Application::TAXONOMY._term_edit_form_top |
|
25 | - * @action Application::TAXONOMY._term_new_form_tag |
|
26 | - */ |
|
27 | - public function enableParents() |
|
28 | - { |
|
29 | - global $wp_taxonomies; |
|
30 | - $wp_taxonomies[Application::TAXONOMY]->hierarchical = true; |
|
31 | - } |
|
22 | + /** |
|
23 | + * @return void |
|
24 | + * @action Application::TAXONOMY._term_edit_form_top |
|
25 | + * @action Application::TAXONOMY._term_new_form_tag |
|
26 | + */ |
|
27 | + public function enableParents() |
|
28 | + { |
|
29 | + global $wp_taxonomies; |
|
30 | + $wp_taxonomies[Application::TAXONOMY]->hierarchical = true; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return void |
|
35 | - * @action restrict_manage_posts |
|
36 | - */ |
|
37 | - public function renderTaxonomyFilter() |
|
38 | - { |
|
39 | - if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) { |
|
40 | - return; |
|
41 | - } |
|
42 | - echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [ |
|
43 | - 'class' => 'screen-reader-text', |
|
44 | - 'for' => Application::TAXONOMY, |
|
45 | - ]); |
|
46 | - wp_dropdown_categories([ |
|
47 | - 'depth' => 3, |
|
48 | - 'hide_empty' => true, |
|
49 | - 'hide_if_empty' => true, |
|
50 | - 'hierarchical' => true, |
|
51 | - 'name' => Application::TAXONOMY, |
|
52 | - 'orderby' => 'name', |
|
53 | - 'selected' => $this->getSelected(), |
|
54 | - 'show_count' => false, |
|
55 | - 'show_option_all' => $this->getShowOptionAll(), |
|
56 | - 'taxonomy' => Application::TAXONOMY, |
|
57 | - 'value_field' => 'slug', |
|
58 | - ]); |
|
59 | - } |
|
33 | + /** |
|
34 | + * @return void |
|
35 | + * @action restrict_manage_posts |
|
36 | + */ |
|
37 | + public function renderTaxonomyFilter() |
|
38 | + { |
|
39 | + if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) { |
|
40 | + return; |
|
41 | + } |
|
42 | + echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [ |
|
43 | + 'class' => 'screen-reader-text', |
|
44 | + 'for' => Application::TAXONOMY, |
|
45 | + ]); |
|
46 | + wp_dropdown_categories([ |
|
47 | + 'depth' => 3, |
|
48 | + 'hide_empty' => true, |
|
49 | + 'hide_if_empty' => true, |
|
50 | + 'hierarchical' => true, |
|
51 | + 'name' => Application::TAXONOMY, |
|
52 | + 'orderby' => 'name', |
|
53 | + 'selected' => $this->getSelected(), |
|
54 | + 'show_count' => false, |
|
55 | + 'show_option_all' => $this->getShowOptionAll(), |
|
56 | + 'taxonomy' => Application::TAXONOMY, |
|
57 | + 'value_field' => 'slug', |
|
58 | + ]); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param int $postId |
|
63 | - * @param array $terms |
|
64 | - * @param array $newTTIds |
|
65 | - * @param string $taxonomy |
|
66 | - * @param bool $append |
|
67 | - * @param array $oldTTIds |
|
68 | - * @return void |
|
69 | - * @action set_object_terms |
|
70 | - */ |
|
71 | - public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
72 | - { |
|
73 | - if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) { |
|
74 | - return; |
|
75 | - } |
|
76 | - $diff = array_diff($newTTIds, $oldTTIds); |
|
77 | - if (empty($newTerm = array_shift($diff))) { |
|
78 | - $newTerm = array_shift($newTTIds); |
|
79 | - } |
|
80 | - if ($newTerm) { |
|
81 | - wp_set_object_terms($postId, intval($newTerm), $taxonomy); |
|
82 | - } |
|
83 | - } |
|
61 | + /** |
|
62 | + * @param int $postId |
|
63 | + * @param array $terms |
|
64 | + * @param array $newTTIds |
|
65 | + * @param string $taxonomy |
|
66 | + * @param bool $append |
|
67 | + * @param array $oldTTIds |
|
68 | + * @return void |
|
69 | + * @action set_object_terms |
|
70 | + */ |
|
71 | + public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
72 | + { |
|
73 | + if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) { |
|
74 | + return; |
|
75 | + } |
|
76 | + $diff = array_diff($newTTIds, $oldTTIds); |
|
77 | + if (empty($newTerm = array_shift($diff))) { |
|
78 | + $newTerm = array_shift($newTTIds); |
|
79 | + } |
|
80 | + if ($newTerm) { |
|
81 | + wp_set_object_terms($postId, intval($newTerm), $taxonomy); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - protected function getSelected() |
|
89 | - { |
|
90 | - global $wp_query; |
|
91 | - return Arr::get($wp_query->query, Application::TAXONOMY); |
|
92 | - } |
|
85 | + /** |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + protected function getSelected() |
|
89 | + { |
|
90 | + global $wp_query; |
|
91 | + return Arr::get($wp_query->query, Application::TAXONOMY); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - protected function getShowOptionAll() |
|
98 | - { |
|
99 | - $taxonomy = get_taxonomy(Application::TAXONOMY); |
|
100 | - return $taxonomy |
|
101 | - ? ucfirst(strtolower($taxonomy->labels->all_items)) |
|
102 | - : ''; |
|
103 | - } |
|
94 | + /** |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + protected function getShowOptionAll() |
|
98 | + { |
|
99 | + $taxonomy = get_taxonomy(Application::TAXONOMY); |
|
100 | + return $taxonomy |
|
101 | + ? ucfirst(strtolower($taxonomy->labels->all_items)) |
|
102 | + : ''; |
|
103 | + } |
|
104 | 104 | } |
@@ -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 | } |
@@ -11,239 +11,239 @@ |
||
11 | 11 | |
12 | 12 | class Settings |
13 | 13 | { |
14 | - /** |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - public $settings; |
|
18 | - |
|
19 | - /** |
|
20 | - * @param string $id |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public function buildFields($id) |
|
24 | - { |
|
25 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
26 | - $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
27 | - $data = !method_exists($this, $method) |
|
28 | - ? $this->getTemplateData($id) |
|
29 | - : $this->$method($id); |
|
30 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - protected function getFieldDefault(array $field) |
|
37 | - { |
|
38 | - return Arr::get($field, 'default'); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - protected function getFieldNameForDependsOn($path) |
|
45 | - { |
|
46 | - $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
47 | - return $this->isMultiDependency($path) |
|
48 | - ? $fieldName.'[]' |
|
49 | - : $fieldName; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - protected function getSettingFields($path) |
|
56 | - { |
|
57 | - return array_filter($this->settings, function ($key) use ($path) { |
|
58 | - return Str::startsWith($path, $key); |
|
59 | - }, ARRAY_FILTER_USE_KEY); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - protected function getSettingRows(array $fields) |
|
66 | - { |
|
67 | - $rows = ''; |
|
68 | - foreach ($fields as $name => $field) { |
|
69 | - $field = wp_parse_args($field, [ |
|
70 | - 'is_setting' => true, |
|
71 | - 'name' => $name, |
|
72 | - ]); |
|
73 | - $rows.= new Field($this->normalize($field)); |
|
74 | - } |
|
75 | - return $rows; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $id |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - protected function getTemplateData($id) |
|
83 | - { |
|
84 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
85 | - return [ |
|
86 | - 'context' => [ |
|
87 | - 'rows' => $this->getSettingRows($fields), |
|
88 | - ], |
|
89 | - ]; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param string $id |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - protected function getTemplateDataForAddons($id) |
|
97 | - { |
|
98 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
99 | - $settings = Arr::convertDotNotationArray($fields); |
|
100 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
101 | - $results = []; |
|
102 | - foreach ($settingKeys as $key) { |
|
103 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
104 | - return Str::startsWith('settings.addons.'.$key, $path); |
|
105 | - }, ARRAY_FILTER_USE_KEY); |
|
106 | - $results[$key] = $this->getSettingRows($addonFields); |
|
107 | - } |
|
108 | - ksort($results); |
|
109 | - return [ |
|
110 | - 'settings' => $results, |
|
111 | - ]; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param string $id |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - protected function getTemplateDataForLicenses($id) |
|
119 | - { |
|
120 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
121 | - ksort($fields); |
|
122 | - return [ |
|
123 | - 'context' => [ |
|
124 | - 'rows' => $this->getSettingRows($fields), |
|
125 | - ], |
|
126 | - ]; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - protected function getTemplateDataForTranslations() |
|
133 | - { |
|
134 | - $translations = glsr(Translation::class)->renderAll(); |
|
135 | - $class = empty($translations) |
|
136 | - ? 'glsr-hidden' |
|
137 | - : ''; |
|
138 | - return [ |
|
139 | - 'context' => [ |
|
140 | - 'class' => $class, |
|
141 | - 'database_key' => OptionManager::databaseKey(), |
|
142 | - 'translations' => $translations, |
|
143 | - ], |
|
144 | - ]; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param string $path |
|
149 | - * @param string|array $expectedValue |
|
150 | - * @return bool |
|
151 | - */ |
|
152 | - protected function isFieldHidden($path, $expectedValue) |
|
153 | - { |
|
154 | - $optionValue = glsr(OptionManager::class)->get( |
|
155 | - $path, |
|
156 | - Arr::get(glsr()->defaults, $path) |
|
157 | - ); |
|
158 | - if (is_array($expectedValue)) { |
|
159 | - return is_array($optionValue) |
|
160 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
161 | - : !in_array($optionValue, $expectedValue); |
|
162 | - } |
|
163 | - return $optionValue != $expectedValue; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - protected function isMultiDependency($path) |
|
170 | - { |
|
171 | - if (isset($this->settings[$path])) { |
|
172 | - $field = $this->settings[$path]; |
|
173 | - return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
174 | - || !empty($field['multiple']); |
|
175 | - } |
|
176 | - return false; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function normalize(array $field) |
|
183 | - { |
|
184 | - $field = $this->normalizeDependsOn($field); |
|
185 | - $field = $this->normalizeLabelAndLegend($field); |
|
186 | - $field = $this->normalizeValue($field); |
|
187 | - return $field; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - protected function normalizeDependsOn(array $field) |
|
194 | - { |
|
195 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
196 | - $isFieldHidden = false; |
|
197 | - $conditions = []; |
|
198 | - foreach ($field['depends_on'] as $path => $value) { |
|
199 | - $conditions[] = [ |
|
200 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
201 | - 'value' => $value, |
|
202 | - ]; |
|
203 | - if ($this->isFieldHidden($path, $value)) { |
|
204 | - $isFieldHidden = true; |
|
205 | - } |
|
206 | - } |
|
207 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
208 | - $field['is_hidden'] = $isFieldHidden; |
|
209 | - } |
|
210 | - return $field; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @return array |
|
215 | - */ |
|
216 | - protected function normalizeLabelAndLegend(array $field) |
|
217 | - { |
|
218 | - if (!empty($field['label'])) { |
|
219 | - $field['legend'] = $field['label']; |
|
220 | - unset($field['label']); |
|
221 | - } else { |
|
222 | - $field['is_valid'] = false; |
|
223 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
224 | - } |
|
225 | - return $field; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - protected function normalizeValue(array $field) |
|
232 | - { |
|
233 | - if (!isset($field['value'])) { |
|
234 | - $field['value'] = glsr(OptionManager::class)->get( |
|
235 | - $field['name'], |
|
236 | - $this->getFieldDefault($field) |
|
237 | - ); |
|
238 | - } |
|
239 | - return $field; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - protected function normalizeSettingPath($path) |
|
246 | - { |
|
247 | - return Str::prefix('settings.', rtrim($path, '.')); |
|
248 | - } |
|
14 | + /** |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + public $settings; |
|
18 | + |
|
19 | + /** |
|
20 | + * @param string $id |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public function buildFields($id) |
|
24 | + { |
|
25 | + $this->settings = glsr(DefaultsManager::class)->settings(); |
|
26 | + $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
27 | + $data = !method_exists($this, $method) |
|
28 | + ? $this->getTemplateData($id) |
|
29 | + : $this->$method($id); |
|
30 | + return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + protected function getFieldDefault(array $field) |
|
37 | + { |
|
38 | + return Arr::get($field, 'default'); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + protected function getFieldNameForDependsOn($path) |
|
45 | + { |
|
46 | + $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
47 | + return $this->isMultiDependency($path) |
|
48 | + ? $fieldName.'[]' |
|
49 | + : $fieldName; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + protected function getSettingFields($path) |
|
56 | + { |
|
57 | + return array_filter($this->settings, function ($key) use ($path) { |
|
58 | + return Str::startsWith($path, $key); |
|
59 | + }, ARRAY_FILTER_USE_KEY); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + protected function getSettingRows(array $fields) |
|
66 | + { |
|
67 | + $rows = ''; |
|
68 | + foreach ($fields as $name => $field) { |
|
69 | + $field = wp_parse_args($field, [ |
|
70 | + 'is_setting' => true, |
|
71 | + 'name' => $name, |
|
72 | + ]); |
|
73 | + $rows.= new Field($this->normalize($field)); |
|
74 | + } |
|
75 | + return $rows; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $id |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + protected function getTemplateData($id) |
|
83 | + { |
|
84 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
85 | + return [ |
|
86 | + 'context' => [ |
|
87 | + 'rows' => $this->getSettingRows($fields), |
|
88 | + ], |
|
89 | + ]; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param string $id |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + protected function getTemplateDataForAddons($id) |
|
97 | + { |
|
98 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
99 | + $settings = Arr::convertDotNotationArray($fields); |
|
100 | + $settingKeys = array_keys($settings['settings']['addons']); |
|
101 | + $results = []; |
|
102 | + foreach ($settingKeys as $key) { |
|
103 | + $addonFields = array_filter($fields, function ($path) use ($key) { |
|
104 | + return Str::startsWith('settings.addons.'.$key, $path); |
|
105 | + }, ARRAY_FILTER_USE_KEY); |
|
106 | + $results[$key] = $this->getSettingRows($addonFields); |
|
107 | + } |
|
108 | + ksort($results); |
|
109 | + return [ |
|
110 | + 'settings' => $results, |
|
111 | + ]; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param string $id |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + protected function getTemplateDataForLicenses($id) |
|
119 | + { |
|
120 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
121 | + ksort($fields); |
|
122 | + return [ |
|
123 | + 'context' => [ |
|
124 | + 'rows' => $this->getSettingRows($fields), |
|
125 | + ], |
|
126 | + ]; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + protected function getTemplateDataForTranslations() |
|
133 | + { |
|
134 | + $translations = glsr(Translation::class)->renderAll(); |
|
135 | + $class = empty($translations) |
|
136 | + ? 'glsr-hidden' |
|
137 | + : ''; |
|
138 | + return [ |
|
139 | + 'context' => [ |
|
140 | + 'class' => $class, |
|
141 | + 'database_key' => OptionManager::databaseKey(), |
|
142 | + 'translations' => $translations, |
|
143 | + ], |
|
144 | + ]; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param string $path |
|
149 | + * @param string|array $expectedValue |
|
150 | + * @return bool |
|
151 | + */ |
|
152 | + protected function isFieldHidden($path, $expectedValue) |
|
153 | + { |
|
154 | + $optionValue = glsr(OptionManager::class)->get( |
|
155 | + $path, |
|
156 | + Arr::get(glsr()->defaults, $path) |
|
157 | + ); |
|
158 | + if (is_array($expectedValue)) { |
|
159 | + return is_array($optionValue) |
|
160 | + ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
161 | + : !in_array($optionValue, $expectedValue); |
|
162 | + } |
|
163 | + return $optionValue != $expectedValue; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + protected function isMultiDependency($path) |
|
170 | + { |
|
171 | + if (isset($this->settings[$path])) { |
|
172 | + $field = $this->settings[$path]; |
|
173 | + return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
174 | + || !empty($field['multiple']); |
|
175 | + } |
|
176 | + return false; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function normalize(array $field) |
|
183 | + { |
|
184 | + $field = $this->normalizeDependsOn($field); |
|
185 | + $field = $this->normalizeLabelAndLegend($field); |
|
186 | + $field = $this->normalizeValue($field); |
|
187 | + return $field; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + protected function normalizeDependsOn(array $field) |
|
194 | + { |
|
195 | + if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
196 | + $isFieldHidden = false; |
|
197 | + $conditions = []; |
|
198 | + foreach ($field['depends_on'] as $path => $value) { |
|
199 | + $conditions[] = [ |
|
200 | + 'name' => $this->getFieldNameForDependsOn($path), |
|
201 | + 'value' => $value, |
|
202 | + ]; |
|
203 | + if ($this->isFieldHidden($path, $value)) { |
|
204 | + $isFieldHidden = true; |
|
205 | + } |
|
206 | + } |
|
207 | + $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
208 | + $field['is_hidden'] = $isFieldHidden; |
|
209 | + } |
|
210 | + return $field; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @return array |
|
215 | + */ |
|
216 | + protected function normalizeLabelAndLegend(array $field) |
|
217 | + { |
|
218 | + if (!empty($field['label'])) { |
|
219 | + $field['legend'] = $field['label']; |
|
220 | + unset($field['label']); |
|
221 | + } else { |
|
222 | + $field['is_valid'] = false; |
|
223 | + glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
224 | + } |
|
225 | + return $field; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + protected function normalizeValue(array $field) |
|
232 | + { |
|
233 | + if (!isset($field['value'])) { |
|
234 | + $field['value'] = glsr(OptionManager::class)->get( |
|
235 | + $field['name'], |
|
236 | + $this->getFieldDefault($field) |
|
237 | + ); |
|
238 | + } |
|
239 | + return $field; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + protected function normalizeSettingPath($path) |
|
246 | + { |
|
247 | + return Str::prefix('settings.', rtrim($path, '.')); |
|
248 | + } |
|
249 | 249 | } |
@@ -7,73 +7,73 @@ |
||
7 | 7 | |
8 | 8 | abstract class Field |
9 | 9 | { |
10 | - /** |
|
11 | - * @var Builder |
|
12 | - */ |
|
13 | - protected $builder; |
|
10 | + /** |
|
11 | + * @var Builder |
|
12 | + */ |
|
13 | + protected $builder; |
|
14 | 14 | |
15 | - public function __construct(Builder $builder) |
|
16 | - { |
|
17 | - $this->builder = $builder; |
|
18 | - } |
|
15 | + public function __construct(Builder $builder) |
|
16 | + { |
|
17 | + $this->builder = $builder; |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return string|void |
|
22 | - */ |
|
23 | - public function build() |
|
24 | - { |
|
25 | - glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @return string|void |
|
22 | + */ |
|
23 | + public function build() |
|
24 | + { |
|
25 | + glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public static function defaults() |
|
32 | - { |
|
33 | - return []; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public static function defaults() |
|
32 | + { |
|
33 | + return []; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public static function merge(array $args) |
|
40 | - { |
|
41 | - $merged = array_merge( |
|
42 | - wp_parse_args($args, static::defaults()), |
|
43 | - static::required() |
|
44 | - ); |
|
45 | - $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
46 | - $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
47 | - return $merged; |
|
48 | - } |
|
36 | + /** |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public static function merge(array $args) |
|
40 | + { |
|
41 | + $merged = array_merge( |
|
42 | + wp_parse_args($args, static::defaults()), |
|
43 | + static::required() |
|
44 | + ); |
|
45 | + $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
46 | + $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
47 | + return $merged; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $delimiter |
|
52 | - * @param string $key |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public static function mergedAttribute($key, $delimiter, array $args) |
|
56 | - { |
|
57 | - return array_filter(array_merge( |
|
58 | - explode($delimiter, Arr::get($args, $key)), |
|
59 | - explode($delimiter, Arr::get(static::defaults(), $key)), |
|
60 | - explode($delimiter, Arr::get(static::required(), $key)) |
|
61 | - )); |
|
62 | - } |
|
50 | + /** |
|
51 | + * @param string $delimiter |
|
52 | + * @param string $key |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public static function mergedAttribute($key, $delimiter, array $args) |
|
56 | + { |
|
57 | + return array_filter(array_merge( |
|
58 | + explode($delimiter, Arr::get($args, $key)), |
|
59 | + explode($delimiter, Arr::get(static::defaults(), $key)), |
|
60 | + explode($delimiter, Arr::get(static::required(), $key)) |
|
61 | + )); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public static function required() |
|
68 | - { |
|
69 | - return []; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public static function required() |
|
68 | + { |
|
69 | + return []; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - protected function mergeFieldArgs() |
|
76 | - { |
|
77 | - $this->builder->args = static::merge($this->builder->args); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + protected function mergeFieldArgs() |
|
76 | + { |
|
77 | + $this->builder->args = static::merge($this->builder->args); |
|
78 | + } |
|
79 | 79 | } |