@@ -7,34 +7,34 @@ |
||
7 | 7 | |
8 | 8 | class SitePermissions extends JsonDataNode |
9 | 9 | { |
10 | - const NODE_NAME = 'sitePermissions'; |
|
10 | + const NODE_NAME = 'sitePermissions'; |
|
11 | 11 | |
12 | - /** |
|
13 | - * @param JsonDataNodeValidator $validator |
|
14 | - */ |
|
15 | - public function __construct(JsonDataNodeValidator $validator) |
|
16 | - { |
|
17 | - parent::__construct($validator); |
|
18 | - $this->setNodeName(SitePermissions::NODE_NAME); |
|
19 | - } |
|
12 | + /** |
|
13 | + * @param JsonDataNodeValidator $validator |
|
14 | + */ |
|
15 | + public function __construct(JsonDataNodeValidator $validator) |
|
16 | + { |
|
17 | + parent::__construct($validator); |
|
18 | + $this->setNodeName(SitePermissions::NODE_NAME); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @inheritDoc |
|
23 | - */ |
|
24 | - public function initialize() |
|
25 | - { |
|
26 | - $permissions = []; |
|
27 | - $site_permissions = apply_filters( |
|
28 | - 'FHEE__EventEspresso_core_domain_entities_routing_data_nodes_core_SitePermissions__initialize__site_permissions', |
|
29 | - [ |
|
30 | - 'use_bulk_edit' => true, |
|
31 | - ] |
|
32 | - ); |
|
33 | - foreach ($site_permissions as $permission => $you_can_do_it) { |
|
34 | - if ($you_can_do_it) { |
|
35 | - $permissions[] = $permission; |
|
36 | - } |
|
37 | - } |
|
38 | - $this->setDataArray($permissions); |
|
39 | - } |
|
21 | + /** |
|
22 | + * @inheritDoc |
|
23 | + */ |
|
24 | + public function initialize() |
|
25 | + { |
|
26 | + $permissions = []; |
|
27 | + $site_permissions = apply_filters( |
|
28 | + 'FHEE__EventEspresso_core_domain_entities_routing_data_nodes_core_SitePermissions__initialize__site_permissions', |
|
29 | + [ |
|
30 | + 'use_bulk_edit' => true, |
|
31 | + ] |
|
32 | + ); |
|
33 | + foreach ($site_permissions as $permission => $you_can_do_it) { |
|
34 | + if ($you_can_do_it) { |
|
35 | + $permissions[] = $permission; |
|
36 | + } |
|
37 | + } |
|
38 | + $this->setDataArray($permissions); |
|
39 | + } |
|
40 | 40 | } |
@@ -7,32 +7,32 @@ |
||
7 | 7 | |
8 | 8 | class Capabilities extends JsonDataNode |
9 | 9 | { |
10 | - const NODE_NAME = 'capabilities'; |
|
10 | + const NODE_NAME = 'capabilities'; |
|
11 | 11 | |
12 | 12 | |
13 | - /** |
|
14 | - * @param JsonDataNodeValidator $validator |
|
15 | - */ |
|
16 | - public function __construct(JsonDataNodeValidator $validator) |
|
17 | - { |
|
18 | - parent::__construct($validator); |
|
19 | - $this->setNodeName(Capabilities::NODE_NAME); |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param JsonDataNodeValidator $validator |
|
15 | + */ |
|
16 | + public function __construct(JsonDataNodeValidator $validator) |
|
17 | + { |
|
18 | + parent::__construct($validator); |
|
19 | + $this->setNodeName(Capabilities::NODE_NAME); |
|
20 | + } |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @inheritDoc |
|
25 | - */ |
|
26 | - public function initialize() |
|
27 | - { |
|
28 | - $current_user = wp_get_current_user(); |
|
29 | - $capabilities = []; |
|
30 | - $role_capabilities = $current_user->get_role_caps(); |
|
31 | - foreach ($role_capabilities as $capability => $you_can_do_it) { |
|
32 | - if ($you_can_do_it) { |
|
33 | - $capabilities[] = $capability; |
|
34 | - } |
|
35 | - } |
|
36 | - $this->setDataArray($capabilities); |
|
37 | - } |
|
23 | + /** |
|
24 | + * @inheritDoc |
|
25 | + */ |
|
26 | + public function initialize() |
|
27 | + { |
|
28 | + $current_user = wp_get_current_user(); |
|
29 | + $capabilities = []; |
|
30 | + $role_capabilities = $current_user->get_role_caps(); |
|
31 | + foreach ($role_capabilities as $capability => $you_can_do_it) { |
|
32 | + if ($you_can_do_it) { |
|
33 | + $capabilities[] = $capability; |
|
34 | + } |
|
35 | + } |
|
36 | + $this->setDataArray($capabilities); |
|
37 | + } |
|
38 | 38 | } |
@@ -17,92 +17,92 @@ |
||
17 | 17 | class Config extends JsonDataNode |
18 | 18 | { |
19 | 19 | |
20 | - const NODE_NAME = 'config'; |
|
20 | + const NODE_NAME = 'config'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var CurrentUser $current_user |
|
24 | - */ |
|
25 | - private $current_user; |
|
22 | + /** |
|
23 | + * @var CurrentUser $current_user |
|
24 | + */ |
|
25 | + private $current_user; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var EspressoCoreDomain $core_domain |
|
29 | - */ |
|
30 | - private $core_domain; |
|
27 | + /** |
|
28 | + * @var EspressoCoreDomain $core_domain |
|
29 | + */ |
|
30 | + private $core_domain; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var GeneralSettings $general_settings |
|
34 | - */ |
|
35 | - private $general_settings; |
|
32 | + /** |
|
33 | + * @var GeneralSettings $general_settings |
|
34 | + */ |
|
35 | + private $general_settings; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var Locale $locale |
|
39 | - */ |
|
40 | - private $locale; |
|
37 | + /** |
|
38 | + * @var Locale $locale |
|
39 | + */ |
|
40 | + private $locale; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var SiteCurrency $site_currency |
|
44 | - */ |
|
45 | - private $site_currency; |
|
42 | + /** |
|
43 | + * @var SiteCurrency $site_currency |
|
44 | + */ |
|
45 | + private $site_currency; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var SitePermissions $site_permissions |
|
49 | - */ |
|
50 | - private $site_permissions; |
|
47 | + /** |
|
48 | + * @var SitePermissions $site_permissions |
|
49 | + */ |
|
50 | + private $site_permissions; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var SiteUrls $site_urls |
|
54 | - */ |
|
55 | - private $site_urls; |
|
52 | + /** |
|
53 | + * @var SiteUrls $site_urls |
|
54 | + */ |
|
55 | + private $site_urls; |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * JsonDataNode constructor. |
|
60 | - * |
|
61 | - * @param CurrentUser $current_user |
|
62 | - * @param EspressoCoreDomain $core_domain |
|
63 | - * @param GeneralSettings $general_settings |
|
64 | - * @param Locale $locale |
|
65 | - * @param SiteCurrency $site_currency |
|
66 | - * @param SitePermissions $site_permissions |
|
67 | - * @param SiteUrls $site_urls |
|
68 | - * @param JsonDataNodeValidator $validator |
|
69 | - */ |
|
70 | - public function __construct( |
|
71 | - CurrentUser $current_user, |
|
72 | - EspressoCoreDomain $core_domain, |
|
73 | - GeneralSettings $general_settings, |
|
74 | - Locale $locale, |
|
75 | - SiteCurrency $site_currency, |
|
76 | - SitePermissions $site_permissions, |
|
77 | - SiteUrls $site_urls, |
|
78 | - JsonDataNodeValidator $validator |
|
79 | - ) { |
|
80 | - parent::__construct($validator); |
|
81 | - $this->current_user = $current_user; |
|
82 | - $this->core_domain = $core_domain; |
|
83 | - $this->general_settings = $general_settings; |
|
84 | - $this->locale = $locale; |
|
85 | - $this->site_currency = $site_currency; |
|
86 | - $this->site_permissions = $site_permissions; |
|
87 | - $this->site_urls = $site_urls; |
|
88 | - $this->setNodeName(Config::NODE_NAME); |
|
89 | - } |
|
58 | + /** |
|
59 | + * JsonDataNode constructor. |
|
60 | + * |
|
61 | + * @param CurrentUser $current_user |
|
62 | + * @param EspressoCoreDomain $core_domain |
|
63 | + * @param GeneralSettings $general_settings |
|
64 | + * @param Locale $locale |
|
65 | + * @param SiteCurrency $site_currency |
|
66 | + * @param SitePermissions $site_permissions |
|
67 | + * @param SiteUrls $site_urls |
|
68 | + * @param JsonDataNodeValidator $validator |
|
69 | + */ |
|
70 | + public function __construct( |
|
71 | + CurrentUser $current_user, |
|
72 | + EspressoCoreDomain $core_domain, |
|
73 | + GeneralSettings $general_settings, |
|
74 | + Locale $locale, |
|
75 | + SiteCurrency $site_currency, |
|
76 | + SitePermissions $site_permissions, |
|
77 | + SiteUrls $site_urls, |
|
78 | + JsonDataNodeValidator $validator |
|
79 | + ) { |
|
80 | + parent::__construct($validator); |
|
81 | + $this->current_user = $current_user; |
|
82 | + $this->core_domain = $core_domain; |
|
83 | + $this->general_settings = $general_settings; |
|
84 | + $this->locale = $locale; |
|
85 | + $this->site_currency = $site_currency; |
|
86 | + $this->site_permissions = $site_permissions; |
|
87 | + $this->site_urls = $site_urls; |
|
88 | + $this->setNodeName(Config::NODE_NAME); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * @throws DomainException |
|
94 | - * @since $VID:$ |
|
95 | - */ |
|
96 | - public function initialize() |
|
97 | - { |
|
98 | - $this->addDataNode($this->core_domain); |
|
99 | - $this->addDataNode($this->current_user); |
|
100 | - $this->addDataNode($this->general_settings); |
|
101 | - $this->addDataNode($this->locale); |
|
102 | - $this->addDataNode($this->site_currency); |
|
103 | - $this->addDataNode($this->site_permissions); |
|
104 | - $this->addDataNode($this->site_urls); |
|
105 | - $this->addData('wp_debug', WP_DEBUG); |
|
106 | - $this->setInitialized(true); |
|
107 | - } |
|
92 | + /** |
|
93 | + * @throws DomainException |
|
94 | + * @since $VID:$ |
|
95 | + */ |
|
96 | + public function initialize() |
|
97 | + { |
|
98 | + $this->addDataNode($this->core_domain); |
|
99 | + $this->addDataNode($this->current_user); |
|
100 | + $this->addDataNode($this->general_settings); |
|
101 | + $this->addDataNode($this->locale); |
|
102 | + $this->addDataNode($this->site_currency); |
|
103 | + $this->addDataNode($this->site_permissions); |
|
104 | + $this->addDataNode($this->site_urls); |
|
105 | + $this->addData('wp_debug', WP_DEBUG); |
|
106 | + $this->setInitialized(true); |
|
107 | + } |
|
108 | 108 | } |
@@ -16,52 +16,52 @@ |
||
16 | 16 | */ |
17 | 17 | class CurrentUser extends JsonDataNode |
18 | 18 | { |
19 | - const NODE_NAME = 'currentUser'; |
|
19 | + const NODE_NAME = 'currentUser'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var Capabilities $capabilities |
|
23 | - */ |
|
24 | - private $capabilities; |
|
21 | + /** |
|
22 | + * @var Capabilities $capabilities |
|
23 | + */ |
|
24 | + private $capabilities; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param Capabilities $capabilities |
|
28 | - * @param JsonDataNodeValidator $validator |
|
29 | - */ |
|
30 | - public function __construct(Capabilities $capabilities, JsonDataNodeValidator $validator) |
|
31 | - { |
|
32 | - if (PHP_VERSION_ID > 70000 && ! class_exists('WPGraphQL')) { |
|
33 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
34 | - } |
|
35 | - parent::__construct($validator); |
|
36 | - $this->capabilities = $capabilities; |
|
37 | - $this->setNodeName(CurrentUser::NODE_NAME); |
|
38 | - } |
|
26 | + /** |
|
27 | + * @param Capabilities $capabilities |
|
28 | + * @param JsonDataNodeValidator $validator |
|
29 | + */ |
|
30 | + public function __construct(Capabilities $capabilities, JsonDataNodeValidator $validator) |
|
31 | + { |
|
32 | + if (PHP_VERSION_ID > 70000 && ! class_exists('WPGraphQL')) { |
|
33 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
34 | + } |
|
35 | + parent::__construct($validator); |
|
36 | + $this->capabilities = $capabilities; |
|
37 | + $this->setNodeName(CurrentUser::NODE_NAME); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @inheritDoc |
|
42 | - */ |
|
43 | - public function initialize() |
|
44 | - { |
|
45 | - $current_user = wp_get_current_user(); |
|
46 | - if (! $current_user instanceof WP_User) { |
|
47 | - $current_user = new WP_User(); |
|
48 | - } |
|
40 | + /** |
|
41 | + * @inheritDoc |
|
42 | + */ |
|
43 | + public function initialize() |
|
44 | + { |
|
45 | + $current_user = wp_get_current_user(); |
|
46 | + if (! $current_user instanceof WP_User) { |
|
47 | + $current_user = new WP_User(); |
|
48 | + } |
|
49 | 49 | |
50 | - if (class_exists(Relay::class)) { |
|
51 | - $this->addData('id', Relay::toGlobalId('user', $current_user->ID)); |
|
52 | - } |
|
53 | - $this->addData('databaseId', $current_user->ID); |
|
54 | - $this->addData('description', $current_user->description); |
|
55 | - $this->addData('email', $current_user->user_email); |
|
56 | - $this->addData('firstName', $current_user->first_name); |
|
57 | - $this->addData('lastName', $current_user->last_name); |
|
58 | - $this->addData('locale', get_user_locale($current_user->ID)); |
|
59 | - $this->addData('name', $current_user->display_name); |
|
60 | - $this->addData('nicename', $current_user->user_nicename); |
|
61 | - $this->addData('nickname', $current_user->nickname); |
|
62 | - $this->addData('username', $current_user->user_login); |
|
63 | - $this->addData('__typename', 'User'); |
|
64 | - $this->addDataNode($this->capabilities); |
|
65 | - $this->setInitialized(true); |
|
66 | - } |
|
50 | + if (class_exists(Relay::class)) { |
|
51 | + $this->addData('id', Relay::toGlobalId('user', $current_user->ID)); |
|
52 | + } |
|
53 | + $this->addData('databaseId', $current_user->ID); |
|
54 | + $this->addData('description', $current_user->description); |
|
55 | + $this->addData('email', $current_user->user_email); |
|
56 | + $this->addData('firstName', $current_user->first_name); |
|
57 | + $this->addData('lastName', $current_user->last_name); |
|
58 | + $this->addData('locale', get_user_locale($current_user->ID)); |
|
59 | + $this->addData('name', $current_user->display_name); |
|
60 | + $this->addData('nicename', $current_user->user_nicename); |
|
61 | + $this->addData('nickname', $current_user->nickname); |
|
62 | + $this->addData('username', $current_user->user_login); |
|
63 | + $this->addData('__typename', 'User'); |
|
64 | + $this->addDataNode($this->capabilities); |
|
65 | + $this->setInitialized(true); |
|
66 | + } |
|
67 | 67 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | public function __construct(Capabilities $capabilities, JsonDataNodeValidator $validator) |
31 | 31 | { |
32 | 32 | if (PHP_VERSION_ID > 70000 && ! class_exists('WPGraphQL')) { |
33 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
33 | + require_once EE_THIRD_PARTY.'wp-graphql/wp-graphql.php'; |
|
34 | 34 | } |
35 | 35 | parent::__construct($validator); |
36 | 36 | $this->capabilities = $capabilities; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | public function initialize() |
44 | 44 | { |
45 | 45 | $current_user = wp_get_current_user(); |
46 | - if (! $current_user instanceof WP_User) { |
|
46 | + if ( ! $current_user instanceof WP_User) { |
|
47 | 47 | $current_user = new WP_User(); |
48 | 48 | } |
49 | 49 |
@@ -17,143 +17,143 @@ |
||
17 | 17 | class RegularRequests extends PrimaryRoute |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * called just before matchesCurrentRequest() |
|
22 | - * and allows Route to perform any setup required such as calling setSpecification() |
|
23 | - * |
|
24 | - * @since $VID:$ |
|
25 | - */ |
|
26 | - public function initialize() |
|
27 | - { |
|
28 | - $basic_nodes = [ |
|
29 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api', |
|
30 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities', |
|
31 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale', |
|
32 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions', |
|
33 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls', |
|
34 | - ]; |
|
35 | - foreach ($basic_nodes as $basic_node) { |
|
36 | - $this->dependency_map->registerDependencies( |
|
37 | - $basic_node, |
|
38 | - ['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache] |
|
39 | - ); |
|
40 | - } |
|
41 | - $this->dependency_map->registerDependencies( |
|
42 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings', |
|
43 | - [ |
|
44 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
45 | - 'EventEspresso\core\services\converters\date_time_formats\PhpToUnicode' => EE_Dependency_Map::load_from_cache, |
|
46 | - ] |
|
47 | - ); |
|
48 | - $this->dependency_map->registerDependencies( |
|
49 | - 'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData', |
|
50 | - [ |
|
51 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api' => EE_Dependency_Map::load_from_cache, |
|
52 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache, |
|
53 | - 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
54 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
55 | - ] |
|
56 | - ); |
|
57 | - $this->dependency_map->registerDependencies( |
|
58 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config', |
|
59 | - [ |
|
60 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
61 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache, |
|
62 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings' => EE_Dependency_Map::load_from_cache, |
|
63 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale' => EE_Dependency_Map::load_from_cache, |
|
64 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency' => EE_Dependency_Map::load_from_cache, |
|
65 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions' => EE_Dependency_Map::load_from_cache, |
|
66 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls' => EE_Dependency_Map::load_from_cache, |
|
67 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
68 | - ] |
|
69 | - ); |
|
70 | - $this->dependency_map->registerDependencies( |
|
71 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser', |
|
72 | - [ |
|
73 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities' => EE_Dependency_Map::load_from_cache, |
|
74 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
75 | - ] |
|
76 | - ); |
|
77 | - $this->dependency_map->registerDependencies( |
|
78 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain', |
|
79 | - [ |
|
80 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
81 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
82 | - ] |
|
83 | - ); |
|
84 | - $this->dependency_map->registerDependencies( |
|
85 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency', |
|
86 | - [ |
|
87 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
88 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
89 | - ] |
|
90 | - ); |
|
91 | - $this->setDataNode( |
|
92 | - $this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData') |
|
93 | - ); |
|
94 | - } |
|
20 | + /** |
|
21 | + * called just before matchesCurrentRequest() |
|
22 | + * and allows Route to perform any setup required such as calling setSpecification() |
|
23 | + * |
|
24 | + * @since $VID:$ |
|
25 | + */ |
|
26 | + public function initialize() |
|
27 | + { |
|
28 | + $basic_nodes = [ |
|
29 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api', |
|
30 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities', |
|
31 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale', |
|
32 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions', |
|
33 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls', |
|
34 | + ]; |
|
35 | + foreach ($basic_nodes as $basic_node) { |
|
36 | + $this->dependency_map->registerDependencies( |
|
37 | + $basic_node, |
|
38 | + ['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache] |
|
39 | + ); |
|
40 | + } |
|
41 | + $this->dependency_map->registerDependencies( |
|
42 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings', |
|
43 | + [ |
|
44 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
45 | + 'EventEspresso\core\services\converters\date_time_formats\PhpToUnicode' => EE_Dependency_Map::load_from_cache, |
|
46 | + ] |
|
47 | + ); |
|
48 | + $this->dependency_map->registerDependencies( |
|
49 | + 'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData', |
|
50 | + [ |
|
51 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api' => EE_Dependency_Map::load_from_cache, |
|
52 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache, |
|
53 | + 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
54 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
55 | + ] |
|
56 | + ); |
|
57 | + $this->dependency_map->registerDependencies( |
|
58 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config', |
|
59 | + [ |
|
60 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
61 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache, |
|
62 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings' => EE_Dependency_Map::load_from_cache, |
|
63 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale' => EE_Dependency_Map::load_from_cache, |
|
64 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency' => EE_Dependency_Map::load_from_cache, |
|
65 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions' => EE_Dependency_Map::load_from_cache, |
|
66 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls' => EE_Dependency_Map::load_from_cache, |
|
67 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
68 | + ] |
|
69 | + ); |
|
70 | + $this->dependency_map->registerDependencies( |
|
71 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser', |
|
72 | + [ |
|
73 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities' => EE_Dependency_Map::load_from_cache, |
|
74 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
75 | + ] |
|
76 | + ); |
|
77 | + $this->dependency_map->registerDependencies( |
|
78 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain', |
|
79 | + [ |
|
80 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
81 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
82 | + ] |
|
83 | + ); |
|
84 | + $this->dependency_map->registerDependencies( |
|
85 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency', |
|
86 | + [ |
|
87 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
88 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
89 | + ] |
|
90 | + ); |
|
91 | + $this->setDataNode( |
|
92 | + $this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData') |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * returns true if the current request matches this route |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - * @since $VID:$ |
|
102 | - */ |
|
103 | - public function matchesCurrentRequest() |
|
104 | - { |
|
105 | - return ! $this->request->isActivation() || $this->request->isUnitTesting(); |
|
106 | - } |
|
97 | + /** |
|
98 | + * returns true if the current request matches this route |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + * @since $VID:$ |
|
102 | + */ |
|
103 | + public function matchesCurrentRequest() |
|
104 | + { |
|
105 | + return ! $this->request->isActivation() || $this->request->isUnitTesting(); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * @since $VID:$ |
|
111 | - */ |
|
112 | - protected function registerDependencies() |
|
113 | - { |
|
114 | - $admin = ['EE_Admin_Config' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies; |
|
115 | - $public = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies; |
|
116 | - $default_with_barista = [ |
|
117 | - 'EventEspresso\core\services\assets\BaristaFactory' => EE_Dependency_Map::load_from_cache |
|
118 | - ] + Route::$default_dependencies; |
|
119 | - $default_with_manifest = [ |
|
120 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache |
|
121 | - ] + Route::$default_dependencies; |
|
122 | - $default_routes = [ |
|
123 | - // default dependencies |
|
124 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests' => Route::$default_dependencies, |
|
125 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage' => Route::$default_dependencies, |
|
126 | - 'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests' => Route::$default_dependencies, |
|
127 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests' => Route::$default_dependencies, |
|
128 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests' => Route::$default_dependencies, |
|
129 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat' => Route::$default_dependencies, |
|
130 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests' => $default_with_barista, |
|
131 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests' => $default_with_manifest, |
|
132 | - // admin dependencies |
|
133 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute' => $admin, |
|
134 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin' => $admin, |
|
135 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor' => $admin, |
|
136 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin' => $admin, |
|
137 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor' => $admin, |
|
138 | - // public dependencies |
|
139 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests' => $public, |
|
140 | - 'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests' => $public, |
|
141 | - ]; |
|
142 | - foreach ($default_routes as $route => $dependencies) { |
|
143 | - $this->dependency_map->registerDependencies($route, $dependencies); |
|
144 | - } |
|
145 | - } |
|
109 | + /** |
|
110 | + * @since $VID:$ |
|
111 | + */ |
|
112 | + protected function registerDependencies() |
|
113 | + { |
|
114 | + $admin = ['EE_Admin_Config' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies; |
|
115 | + $public = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies; |
|
116 | + $default_with_barista = [ |
|
117 | + 'EventEspresso\core\services\assets\BaristaFactory' => EE_Dependency_Map::load_from_cache |
|
118 | + ] + Route::$default_dependencies; |
|
119 | + $default_with_manifest = [ |
|
120 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache |
|
121 | + ] + Route::$default_dependencies; |
|
122 | + $default_routes = [ |
|
123 | + // default dependencies |
|
124 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests' => Route::$default_dependencies, |
|
125 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage' => Route::$default_dependencies, |
|
126 | + 'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests' => Route::$default_dependencies, |
|
127 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests' => Route::$default_dependencies, |
|
128 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests' => Route::$default_dependencies, |
|
129 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat' => Route::$default_dependencies, |
|
130 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests' => $default_with_barista, |
|
131 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests' => $default_with_manifest, |
|
132 | + // admin dependencies |
|
133 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute' => $admin, |
|
134 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin' => $admin, |
|
135 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor' => $admin, |
|
136 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin' => $admin, |
|
137 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor' => $admin, |
|
138 | + // public dependencies |
|
139 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests' => $public, |
|
140 | + 'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests' => $public, |
|
141 | + ]; |
|
142 | + foreach ($default_routes as $route => $dependencies) { |
|
143 | + $this->dependency_map->registerDependencies($route, $dependencies); |
|
144 | + } |
|
145 | + } |
|
146 | 146 | |
147 | 147 | |
148 | - /** |
|
149 | - * implements logic required to run during request |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - * @since $VID:$ |
|
153 | - */ |
|
154 | - protected function requestHandler() |
|
155 | - { |
|
156 | - $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR); |
|
157 | - return true; |
|
158 | - } |
|
148 | + /** |
|
149 | + * implements logic required to run during request |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + * @since $VID:$ |
|
153 | + */ |
|
154 | + protected function requestHandler() |
|
155 | + { |
|
156 | + $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR); |
|
157 | + return true; |
|
158 | + } |
|
159 | 159 | } |
@@ -14,91 +14,91 @@ |
||
14 | 14 | class JsonDataNodeValidator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param JsonDataNode $data_node |
|
19 | - * @return bool returns true if data array is safe to set, false if overwrite will occur |
|
20 | - * @throws DomainException throws exception if WP_DEBUG is true |
|
21 | - */ |
|
22 | - public function dataArrayEmpty(JsonDataNode $data_node) |
|
23 | - { |
|
24 | - $data = $data_node->data(); |
|
25 | - if (! empty($data)) { |
|
26 | - $this->overwriteError($data_node->nodeName(), esc_html__('data array', 'event_espresso')); |
|
27 | - return false; |
|
28 | - } |
|
29 | - return true; |
|
30 | - } |
|
17 | + /** |
|
18 | + * @param JsonDataNode $data_node |
|
19 | + * @return bool returns true if data array is safe to set, false if overwrite will occur |
|
20 | + * @throws DomainException throws exception if WP_DEBUG is true |
|
21 | + */ |
|
22 | + public function dataArrayEmpty(JsonDataNode $data_node) |
|
23 | + { |
|
24 | + $data = $data_node->data(); |
|
25 | + if (! empty($data)) { |
|
26 | + $this->overwriteError($data_node->nodeName(), esc_html__('data array', 'event_espresso')); |
|
27 | + return false; |
|
28 | + } |
|
29 | + return true; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param array $data data array to check for property key |
|
34 | - * @param string $key value for the key being checked for |
|
35 | - * @param string $type the type of key and/or the data being checked |
|
36 | - * @return bool returns true if property is safe to write, false if overwrite will occur |
|
37 | - * @throws DomainException throws exception if WP_DEBUG is true |
|
38 | - */ |
|
39 | - public function propertyNotSet(array $data, $key, $type = 'key') |
|
40 | - { |
|
41 | - if (isset($data[ $key ])) { |
|
42 | - $this->overwriteError($key, $type); |
|
43 | - return false; |
|
44 | - } |
|
45 | - return true; |
|
46 | - } |
|
32 | + /** |
|
33 | + * @param array $data data array to check for property key |
|
34 | + * @param string $key value for the key being checked for |
|
35 | + * @param string $type the type of key and/or the data being checked |
|
36 | + * @return bool returns true if property is safe to write, false if overwrite will occur |
|
37 | + * @throws DomainException throws exception if WP_DEBUG is true |
|
38 | + */ |
|
39 | + public function propertyNotSet(array $data, $key, $type = 'key') |
|
40 | + { |
|
41 | + if (isset($data[ $key ])) { |
|
42 | + $this->overwriteError($key, $type); |
|
43 | + return false; |
|
44 | + } |
|
45 | + return true; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * @param string $key value for the key being checked for |
|
51 | - * @param string $type the type of key and/or the data being checked |
|
52 | - * @throws DomainException throws exception if WP_DEBUG is true |
|
53 | - */ |
|
54 | - public function overwriteError($key, $type) |
|
55 | - { |
|
56 | - if (WP_DEBUG) { |
|
57 | - throw new DomainException( |
|
58 | - sprintf( |
|
59 | - /* |
|
49 | + /** |
|
50 | + * @param string $key value for the key being checked for |
|
51 | + * @param string $type the type of key and/or the data being checked |
|
52 | + * @throws DomainException throws exception if WP_DEBUG is true |
|
53 | + */ |
|
54 | + public function overwriteError($key, $type) |
|
55 | + { |
|
56 | + if (WP_DEBUG) { |
|
57 | + throw new DomainException( |
|
58 | + sprintf( |
|
59 | + /* |
|
60 | 60 | * translators: |
61 | 61 | * 'The "i18n" JsonDataNode key is already set and would be overwritten by the current action.' |
62 | 62 | */ |
63 | - esc_html__( |
|
64 | - 'The "%1$s" JsonDataNode %2$s is already set and would be overwritten by the current action.', |
|
65 | - 'event_espresso' |
|
66 | - ), |
|
67 | - $key, |
|
68 | - $type |
|
69 | - ) |
|
70 | - ); |
|
71 | - } |
|
72 | - } |
|
63 | + esc_html__( |
|
64 | + 'The "%1$s" JsonDataNode %2$s is already set and would be overwritten by the current action.', |
|
65 | + 'event_espresso' |
|
66 | + ), |
|
67 | + $key, |
|
68 | + $type |
|
69 | + ) |
|
70 | + ); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * @param string $property name for the key being checked for |
|
77 | - * @param string $type the type of key and/or the data being checked |
|
78 | - * @param bool $throw if true [default] and WP_DEBUG is also true, then will throw exceptions |
|
79 | - * @return bool returns true if property is set, false if property is missing |
|
80 | - * @throws DomainException throws exception if WP_DEBUG is true |
|
81 | - */ |
|
82 | - public function validateCriticalProperty($property, $type, $throw = true) |
|
83 | - { |
|
84 | - if (empty($property)) { |
|
85 | - if (WP_DEBUG && $throw) { |
|
86 | - throw new DomainException( |
|
87 | - sprintf( |
|
88 | - /* |
|
75 | + /** |
|
76 | + * @param string $property name for the key being checked for |
|
77 | + * @param string $type the type of key and/or the data being checked |
|
78 | + * @param bool $throw if true [default] and WP_DEBUG is also true, then will throw exceptions |
|
79 | + * @return bool returns true if property is set, false if property is missing |
|
80 | + * @throws DomainException throws exception if WP_DEBUG is true |
|
81 | + */ |
|
82 | + public function validateCriticalProperty($property, $type, $throw = true) |
|
83 | + { |
|
84 | + if (empty($property)) { |
|
85 | + if (WP_DEBUG && $throw) { |
|
86 | + throw new DomainException( |
|
87 | + sprintf( |
|
88 | + /* |
|
89 | 89 | * translators: |
90 | 90 | * 'The JsonDataNodeHandler domain route is a required property but has not been set.' |
91 | 91 | */ |
92 | - esc_html__( |
|
93 | - 'The JsonDataNodeHandler %1$s is a required property but has not been set.', |
|
94 | - 'event_espresso' |
|
95 | - ), |
|
96 | - $type |
|
97 | - ) |
|
98 | - ); |
|
99 | - } |
|
100 | - return false; |
|
101 | - } |
|
102 | - return true; |
|
103 | - } |
|
92 | + esc_html__( |
|
93 | + 'The JsonDataNodeHandler %1$s is a required property but has not been set.', |
|
94 | + 'event_espresso' |
|
95 | + ), |
|
96 | + $type |
|
97 | + ) |
|
98 | + ); |
|
99 | + } |
|
100 | + return false; |
|
101 | + } |
|
102 | + return true; |
|
103 | + } |
|
104 | 104 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | public function dataArrayEmpty(JsonDataNode $data_node) |
23 | 23 | { |
24 | 24 | $data = $data_node->data(); |
25 | - if (! empty($data)) { |
|
25 | + if ( ! empty($data)) { |
|
26 | 26 | $this->overwriteError($data_node->nodeName(), esc_html__('data array', 'event_espresso')); |
27 | 27 | return false; |
28 | 28 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function propertyNotSet(array $data, $key, $type = 'key') |
40 | 40 | { |
41 | - if (isset($data[ $key ])) { |
|
41 | + if (isset($data[$key])) { |
|
42 | 42 | $this->overwriteError($key, $type); |
43 | 43 | return false; |
44 | 44 | } |
@@ -18,195 +18,195 @@ |
||
18 | 18 | abstract class JsonDataNode implements JsonDataNodeInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var JsonDataNodeValidator $validator |
|
23 | - */ |
|
24 | - protected $validator; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array $data |
|
28 | - */ |
|
29 | - private $data = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string $domain |
|
33 | - */ |
|
34 | - private $domain; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var boolean $initialized |
|
38 | - */ |
|
39 | - private $initialized = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string $node_name |
|
43 | - */ |
|
44 | - private $node_name; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @param JsonDataNodeValidator $validator |
|
49 | - * @throws DomainException |
|
50 | - */ |
|
51 | - public function __construct(JsonDataNodeValidator $validator) |
|
52 | - { |
|
53 | - $this->validator = $validator; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * for adding primitive data like arrays, integers, or strings |
|
59 | - * |
|
60 | - * @param string $key |
|
61 | - * @param mixed $data |
|
62 | - * @throws DomainException |
|
63 | - */ |
|
64 | - protected function addData($key, $data) |
|
65 | - { |
|
66 | - if ($this->validator->propertyNotSet($this->data, $key)) { |
|
67 | - $this->data[ $key ] = $data; |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * for setting value of the entire data array for the node |
|
74 | - * |
|
75 | - * @param array $data |
|
76 | - * @throws DomainException |
|
77 | - */ |
|
78 | - protected function setDataArray(array $data) |
|
79 | - { |
|
80 | - if ($this->validator->dataArrayEmpty($this)) { |
|
81 | - $this->data = $data; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * for embedding other JsonDataNode objects within this one |
|
88 | - * |
|
89 | - * @param JsonDataNode $data_node |
|
90 | - * @throws DomainException |
|
91 | - */ |
|
92 | - public function addDataNode(JsonDataNode $data_node) |
|
93 | - { |
|
94 | - if ($data_node->isNotInitialized()) { |
|
95 | - // $data_node->initialize(); |
|
96 | - $key = $data_node->nodeName(); |
|
97 | - $this->addData($key, $data_node); |
|
98 | - // if the node being added specifies a domain (use case) |
|
99 | - // and this is the primary data node, then set the domain |
|
100 | - if ($this instanceof PrimaryJsonDataNode && $data_node->domain() !== null) { |
|
101 | - $this->setDomain($data_node->domain()); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * sets the domain (use case) that this data node provides data for |
|
109 | - * |
|
110 | - * @param string $domain |
|
111 | - * @throws DomainException |
|
112 | - */ |
|
113 | - protected function setDomain($domain) |
|
114 | - { |
|
115 | - if ($this->domain !== null) { |
|
116 | - $this->validator->overwriteError($domain, 'domain route'); |
|
117 | - } |
|
118 | - $this->domain = $domain; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * used to mark the data node as having been processed |
|
124 | - * |
|
125 | - * @param bool $initialized |
|
126 | - */ |
|
127 | - protected function setInitialized($initialized) |
|
128 | - { |
|
129 | - $this->initialized = filter_var($initialized, FILTER_VALIDATE_BOOLEAN); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * self explanatory (i hope) |
|
135 | - * |
|
136 | - * @param string $node_name |
|
137 | - * @throws DomainException |
|
138 | - */ |
|
139 | - protected function setNodeName($node_name) |
|
140 | - { |
|
141 | - $this->validator->validateCriticalProperty($node_name, 'node name'); |
|
142 | - $this->node_name = $node_name; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * the actual data in key value array format |
|
148 | - * |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function data() |
|
152 | - { |
|
153 | - return $this->data; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * the domain (use case) that this data node provides data for |
|
159 | - * |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function domain() |
|
163 | - { |
|
164 | - return $this->domain; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * true if the data node has been initialized, |
|
170 | - * which entails retrieving the required data and adding it to the data node data array |
|
171 | - * |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function isInitialized() |
|
175 | - { |
|
176 | - return $this->initialized; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * true if the data node has NOT been initialized |
|
182 | - * |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - public function isNotInitialized() |
|
186 | - { |
|
187 | - return ! $this->initialized; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Specify data which should be serialized to JSON |
|
193 | - * |
|
194 | - * @link https://php.net/manual/en/jsonserializable.jsonserialize.php |
|
195 | - * @return mixed data which can be serialized by json_encode |
|
196 | - */ |
|
197 | - public function jsonSerialize() |
|
198 | - { |
|
199 | - return $this->data; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * self explanatory (i hope) |
|
205 | - * |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public function nodeName() |
|
209 | - { |
|
210 | - return $this->node_name; |
|
211 | - } |
|
21 | + /** |
|
22 | + * @var JsonDataNodeValidator $validator |
|
23 | + */ |
|
24 | + protected $validator; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array $data |
|
28 | + */ |
|
29 | + private $data = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string $domain |
|
33 | + */ |
|
34 | + private $domain; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var boolean $initialized |
|
38 | + */ |
|
39 | + private $initialized = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string $node_name |
|
43 | + */ |
|
44 | + private $node_name; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @param JsonDataNodeValidator $validator |
|
49 | + * @throws DomainException |
|
50 | + */ |
|
51 | + public function __construct(JsonDataNodeValidator $validator) |
|
52 | + { |
|
53 | + $this->validator = $validator; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * for adding primitive data like arrays, integers, or strings |
|
59 | + * |
|
60 | + * @param string $key |
|
61 | + * @param mixed $data |
|
62 | + * @throws DomainException |
|
63 | + */ |
|
64 | + protected function addData($key, $data) |
|
65 | + { |
|
66 | + if ($this->validator->propertyNotSet($this->data, $key)) { |
|
67 | + $this->data[ $key ] = $data; |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * for setting value of the entire data array for the node |
|
74 | + * |
|
75 | + * @param array $data |
|
76 | + * @throws DomainException |
|
77 | + */ |
|
78 | + protected function setDataArray(array $data) |
|
79 | + { |
|
80 | + if ($this->validator->dataArrayEmpty($this)) { |
|
81 | + $this->data = $data; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * for embedding other JsonDataNode objects within this one |
|
88 | + * |
|
89 | + * @param JsonDataNode $data_node |
|
90 | + * @throws DomainException |
|
91 | + */ |
|
92 | + public function addDataNode(JsonDataNode $data_node) |
|
93 | + { |
|
94 | + if ($data_node->isNotInitialized()) { |
|
95 | + // $data_node->initialize(); |
|
96 | + $key = $data_node->nodeName(); |
|
97 | + $this->addData($key, $data_node); |
|
98 | + // if the node being added specifies a domain (use case) |
|
99 | + // and this is the primary data node, then set the domain |
|
100 | + if ($this instanceof PrimaryJsonDataNode && $data_node->domain() !== null) { |
|
101 | + $this->setDomain($data_node->domain()); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * sets the domain (use case) that this data node provides data for |
|
109 | + * |
|
110 | + * @param string $domain |
|
111 | + * @throws DomainException |
|
112 | + */ |
|
113 | + protected function setDomain($domain) |
|
114 | + { |
|
115 | + if ($this->domain !== null) { |
|
116 | + $this->validator->overwriteError($domain, 'domain route'); |
|
117 | + } |
|
118 | + $this->domain = $domain; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * used to mark the data node as having been processed |
|
124 | + * |
|
125 | + * @param bool $initialized |
|
126 | + */ |
|
127 | + protected function setInitialized($initialized) |
|
128 | + { |
|
129 | + $this->initialized = filter_var($initialized, FILTER_VALIDATE_BOOLEAN); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * self explanatory (i hope) |
|
135 | + * |
|
136 | + * @param string $node_name |
|
137 | + * @throws DomainException |
|
138 | + */ |
|
139 | + protected function setNodeName($node_name) |
|
140 | + { |
|
141 | + $this->validator->validateCriticalProperty($node_name, 'node name'); |
|
142 | + $this->node_name = $node_name; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * the actual data in key value array format |
|
148 | + * |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function data() |
|
152 | + { |
|
153 | + return $this->data; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * the domain (use case) that this data node provides data for |
|
159 | + * |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function domain() |
|
163 | + { |
|
164 | + return $this->domain; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * true if the data node has been initialized, |
|
170 | + * which entails retrieving the required data and adding it to the data node data array |
|
171 | + * |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function isInitialized() |
|
175 | + { |
|
176 | + return $this->initialized; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * true if the data node has NOT been initialized |
|
182 | + * |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + public function isNotInitialized() |
|
186 | + { |
|
187 | + return ! $this->initialized; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Specify data which should be serialized to JSON |
|
193 | + * |
|
194 | + * @link https://php.net/manual/en/jsonserializable.jsonserialize.php |
|
195 | + * @return mixed data which can be serialized by json_encode |
|
196 | + */ |
|
197 | + public function jsonSerialize() |
|
198 | + { |
|
199 | + return $this->data; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * self explanatory (i hope) |
|
205 | + * |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public function nodeName() |
|
209 | + { |
|
210 | + return $this->node_name; |
|
211 | + } |
|
212 | 212 | } |