@@ -16,27 +16,27 @@ |
||
| 16 | 16 | class InvalidAliasException extends DomainException |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * InvalidClassException constructor. |
|
| 21 | - * |
|
| 22 | - * @param string $fqcn |
|
| 23 | - * @param string $alias |
|
| 24 | - * @param string $message |
|
| 25 | - * @param int $code |
|
| 26 | - * @param Exception $previous |
|
| 27 | - */ |
|
| 28 | - public function __construct($fqcn, $alias, $message = '', $code = 0, Exception $previous = null) |
|
| 29 | - { |
|
| 30 | - if (empty($message)) { |
|
| 31 | - $message = sprintf( |
|
| 32 | - __( |
|
| 33 | - '"%1$s" can not be used as an alias because the "%2$s" class does not extend or implement it.', |
|
| 34 | - 'event_espresso' |
|
| 35 | - ), |
|
| 36 | - $alias, |
|
| 37 | - $fqcn |
|
| 38 | - ); |
|
| 39 | - } |
|
| 40 | - parent::__construct($message, $code, $previous); |
|
| 41 | - } |
|
| 19 | + /** |
|
| 20 | + * InvalidClassException constructor. |
|
| 21 | + * |
|
| 22 | + * @param string $fqcn |
|
| 23 | + * @param string $alias |
|
| 24 | + * @param string $message |
|
| 25 | + * @param int $code |
|
| 26 | + * @param Exception $previous |
|
| 27 | + */ |
|
| 28 | + public function __construct($fqcn, $alias, $message = '', $code = 0, Exception $previous = null) |
|
| 29 | + { |
|
| 30 | + if (empty($message)) { |
|
| 31 | + $message = sprintf( |
|
| 32 | + __( |
|
| 33 | + '"%1$s" can not be used as an alias because the "%2$s" class does not extend or implement it.', |
|
| 34 | + 'event_espresso' |
|
| 35 | + ), |
|
| 36 | + $alias, |
|
| 37 | + $fqcn |
|
| 38 | + ); |
|
| 39 | + } |
|
| 40 | + parent::__construct($message, $code, $previous); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | public function __construct($alias, $fqcn) |
| 36 | 36 | { |
| 37 | - if (! is_subclass_of($fqcn, $alias)) { |
|
| 37 | + if ( ! is_subclass_of($fqcn, $alias)) { |
|
| 38 | 38 | throw new InvalidAliasException($fqcn, $alias); |
| 39 | 39 | } |
| 40 | 40 | $this->alias = $alias; |
@@ -17,46 +17,46 @@ |
||
| 17 | 17 | class ClassAlias |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string $alias an interface or base class representing what object |
|
| 22 | - * can be utilized by another object and/or function |
|
| 23 | - */ |
|
| 24 | - private $alias; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string $fqcn the actual class that should be substituted for the alias above |
|
| 28 | - */ |
|
| 29 | - private $fqcn; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * ClassAlias constructor. |
|
| 33 | - * |
|
| 34 | - * @param string $alias Interface specified by implementing class |
|
| 35 | - * @param string $fqcn Concrete class that satisfies interface |
|
| 36 | - * @throws InvalidAliasException |
|
| 37 | - */ |
|
| 38 | - public function __construct($alias, $fqcn) |
|
| 39 | - { |
|
| 40 | - if (! is_subclass_of($fqcn, $alias)) { |
|
| 41 | - throw new InvalidAliasException($fqcn, $alias); |
|
| 42 | - } |
|
| 43 | - $this->alias = $alias; |
|
| 44 | - $this->fqcn = $fqcn; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function alias() |
|
| 51 | - { |
|
| 52 | - return $this->alias; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public function fqcn() |
|
| 59 | - { |
|
| 60 | - return $this->fqcn; |
|
| 61 | - } |
|
| 20 | + /** |
|
| 21 | + * @var string $alias an interface or base class representing what object |
|
| 22 | + * can be utilized by another object and/or function |
|
| 23 | + */ |
|
| 24 | + private $alias; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string $fqcn the actual class that should be substituted for the alias above |
|
| 28 | + */ |
|
| 29 | + private $fqcn; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * ClassAlias constructor. |
|
| 33 | + * |
|
| 34 | + * @param string $alias Interface specified by implementing class |
|
| 35 | + * @param string $fqcn Concrete class that satisfies interface |
|
| 36 | + * @throws InvalidAliasException |
|
| 37 | + */ |
|
| 38 | + public function __construct($alias, $fqcn) |
|
| 39 | + { |
|
| 40 | + if (! is_subclass_of($fqcn, $alias)) { |
|
| 41 | + throw new InvalidAliasException($fqcn, $alias); |
|
| 42 | + } |
|
| 43 | + $this->alias = $alias; |
|
| 44 | + $this->fqcn = $fqcn; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function alias() |
|
| 51 | + { |
|
| 52 | + return $this->alias; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public function fqcn() |
|
| 59 | + { |
|
| 60 | + return $this->fqcn; |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -18,41 +18,41 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class FactoryWithDependencyResolver implements FactoryInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var DependencyResolverInterface $dependency_resolver |
|
| 23 | - */ |
|
| 24 | - private $dependency_resolver; |
|
| 21 | + /** |
|
| 22 | + * @var DependencyResolverInterface $dependency_resolver |
|
| 23 | + */ |
|
| 24 | + private $dependency_resolver; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var LoaderInterface $loader |
|
| 28 | - */ |
|
| 29 | - private $loader; |
|
| 26 | + /** |
|
| 27 | + * @var LoaderInterface $loader |
|
| 28 | + */ |
|
| 29 | + private $loader; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * FactoryWithDependencyResolver constructor. |
|
| 33 | - * |
|
| 34 | - * @param DependencyResolverInterface $dependency_resolver |
|
| 35 | - * @param LoaderInterface $loader |
|
| 36 | - */ |
|
| 37 | - public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader) |
|
| 38 | - { |
|
| 39 | - $this->dependency_resolver = $dependency_resolver; |
|
| 40 | - $this->loader = $loader; |
|
| 41 | - } |
|
| 31 | + /** |
|
| 32 | + * FactoryWithDependencyResolver constructor. |
|
| 33 | + * |
|
| 34 | + * @param DependencyResolverInterface $dependency_resolver |
|
| 35 | + * @param LoaderInterface $loader |
|
| 36 | + */ |
|
| 37 | + public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader) |
|
| 38 | + { |
|
| 39 | + $this->dependency_resolver = $dependency_resolver; |
|
| 40 | + $this->loader = $loader; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return DependencyResolverInterface |
|
| 45 | - */ |
|
| 46 | - public function dependencyResolver() |
|
| 47 | - { |
|
| 48 | - return $this->dependency_resolver; |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * @return DependencyResolverInterface |
|
| 45 | + */ |
|
| 46 | + public function dependencyResolver() |
|
| 47 | + { |
|
| 48 | + return $this->dependency_resolver; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return LoaderInterface |
|
| 53 | - */ |
|
| 54 | - public function loader() |
|
| 55 | - { |
|
| 56 | - return $this->loader; |
|
| 57 | - } |
|
| 51 | + /** |
|
| 52 | + * @return LoaderInterface |
|
| 53 | + */ |
|
| 54 | + public function loader() |
|
| 55 | + { |
|
| 56 | + return $this->loader; |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -11,10 +11,10 @@ |
||
| 11 | 11 | interface FactoryInterface |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param mixed $arguments Either a Fully Qualified Class Name |
|
| 16 | - * or array of data required for construction |
|
| 17 | - * @return mixed |
|
| 18 | - */ |
|
| 19 | - public static function create($arguments); |
|
| 14 | + /** |
|
| 15 | + * @param mixed $arguments Either a Fully Qualified Class Name |
|
| 16 | + * or array of data required for construction |
|
| 17 | + * @return mixed |
|
| 18 | + */ |
|
| 19 | + public static function create($arguments); |
|
| 20 | 20 | } |
@@ -16,131 +16,131 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Config |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var EE_Network_Config |
|
| 21 | - */ |
|
| 22 | - private $network_config; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var EE_Config |
|
| 27 | - */ |
|
| 28 | - private $ee_config; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - public function __construct(EE_Network_Config $network_config, EE_Config $ee_config) |
|
| 32 | - { |
|
| 33 | - $this->network_config = $network_config; |
|
| 34 | - $this->ee_config = $ee_config; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Get the site license key for the site. |
|
| 40 | - */ |
|
| 41 | - public function siteLicenseKey() |
|
| 42 | - { |
|
| 43 | - return $this->network_config->core->site_license_key; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - public function i18nDomain() |
|
| 48 | - { |
|
| 49 | - return 'event_espresso'; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - public function checkPeriod() |
|
| 54 | - { |
|
| 55 | - return 24; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - public function optionKey() |
|
| 60 | - { |
|
| 61 | - return 'ee_site_license_key'; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - public function optionsPageSlug() |
|
| 66 | - { |
|
| 67 | - return 'espresso_general_settings'; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - public function hostServerUrl() |
|
| 72 | - { |
|
| 73 | - return defined('PUE_UPDATES_ENDPOINT') |
|
| 74 | - ? PUE_UPDATES_ENDPOINT |
|
| 75 | - : 'https://eventespresso.com'; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - public function pluginSlug() |
|
| 80 | - { |
|
| 81 | - // Note: PUE uses a simple preg_match to determine what type is currently installed based on version number. |
|
| 82 | - // So it's important that you use a key for the version type that is unique and not found in another key. |
|
| 83 | - // For example: |
|
| 84 | - // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
| 85 | - // $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug'; |
|
| 86 | - // The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr ) |
|
| 87 | - // so doing something like: |
|
| 88 | - // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
| 89 | - // $plugin_slug['prerelease']['b'] = 'some-pre-release-slug'; |
|
| 90 | - // ..WOULD work! |
|
| 91 | - return array( |
|
| 92 | - 'free' => array('decaf' => 'event-espresso-core-decaf'), |
|
| 93 | - 'premium' => array('p' => 'event-espresso-core-reg'), |
|
| 94 | - 'prerelease' => array('beta' => 'event-espresso-core-pr'), |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Return whether the site is opted in for UXIP or not. |
|
| 101 | - * |
|
| 102 | - * @return bool |
|
| 103 | - */ |
|
| 104 | - public function isOptedInForUxip() |
|
| 105 | - { |
|
| 106 | - return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Return whether the site has been notified about UXIP or not. |
|
| 112 | - * |
|
| 113 | - * @return bool |
|
| 114 | - */ |
|
| 115 | - public function hasNotifiedForUxip() |
|
| 116 | - { |
|
| 117 | - return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Set the site opted in for UXIP. |
|
| 123 | - */ |
|
| 124 | - public function setHasOptedInForUxip() |
|
| 125 | - { |
|
| 126 | - $this->ee_config->core->ee_ueip_optin = true; |
|
| 127 | - $this->ee_config->update_espresso_config(false, false); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Set the site opted out for UXIP |
|
| 133 | - */ |
|
| 134 | - public function setHasOptedOutForUxip() |
|
| 135 | - { |
|
| 136 | - $this->ee_config->core->ee_ueip_optin = false; |
|
| 137 | - $this->ee_config->update_espresso_config(false, false); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - public function setHasNotifiedAboutUxip() |
|
| 142 | - { |
|
| 143 | - $this->ee_config->core->ee_ueip_has_notified = true; |
|
| 144 | - $this->ee_config->update_espresso_config(false, false); |
|
| 145 | - } |
|
| 19 | + /** |
|
| 20 | + * @var EE_Network_Config |
|
| 21 | + */ |
|
| 22 | + private $network_config; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var EE_Config |
|
| 27 | + */ |
|
| 28 | + private $ee_config; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + public function __construct(EE_Network_Config $network_config, EE_Config $ee_config) |
|
| 32 | + { |
|
| 33 | + $this->network_config = $network_config; |
|
| 34 | + $this->ee_config = $ee_config; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Get the site license key for the site. |
|
| 40 | + */ |
|
| 41 | + public function siteLicenseKey() |
|
| 42 | + { |
|
| 43 | + return $this->network_config->core->site_license_key; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + public function i18nDomain() |
|
| 48 | + { |
|
| 49 | + return 'event_espresso'; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + public function checkPeriod() |
|
| 54 | + { |
|
| 55 | + return 24; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + public function optionKey() |
|
| 60 | + { |
|
| 61 | + return 'ee_site_license_key'; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + public function optionsPageSlug() |
|
| 66 | + { |
|
| 67 | + return 'espresso_general_settings'; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + public function hostServerUrl() |
|
| 72 | + { |
|
| 73 | + return defined('PUE_UPDATES_ENDPOINT') |
|
| 74 | + ? PUE_UPDATES_ENDPOINT |
|
| 75 | + : 'https://eventespresso.com'; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + public function pluginSlug() |
|
| 80 | + { |
|
| 81 | + // Note: PUE uses a simple preg_match to determine what type is currently installed based on version number. |
|
| 82 | + // So it's important that you use a key for the version type that is unique and not found in another key. |
|
| 83 | + // For example: |
|
| 84 | + // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
| 85 | + // $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug'; |
|
| 86 | + // The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr ) |
|
| 87 | + // so doing something like: |
|
| 88 | + // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
| 89 | + // $plugin_slug['prerelease']['b'] = 'some-pre-release-slug'; |
|
| 90 | + // ..WOULD work! |
|
| 91 | + return array( |
|
| 92 | + 'free' => array('decaf' => 'event-espresso-core-decaf'), |
|
| 93 | + 'premium' => array('p' => 'event-espresso-core-reg'), |
|
| 94 | + 'prerelease' => array('beta' => 'event-espresso-core-pr'), |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Return whether the site is opted in for UXIP or not. |
|
| 101 | + * |
|
| 102 | + * @return bool |
|
| 103 | + */ |
|
| 104 | + public function isOptedInForUxip() |
|
| 105 | + { |
|
| 106 | + return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Return whether the site has been notified about UXIP or not. |
|
| 112 | + * |
|
| 113 | + * @return bool |
|
| 114 | + */ |
|
| 115 | + public function hasNotifiedForUxip() |
|
| 116 | + { |
|
| 117 | + return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Set the site opted in for UXIP. |
|
| 123 | + */ |
|
| 124 | + public function setHasOptedInForUxip() |
|
| 125 | + { |
|
| 126 | + $this->ee_config->core->ee_ueip_optin = true; |
|
| 127 | + $this->ee_config->update_espresso_config(false, false); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Set the site opted out for UXIP |
|
| 133 | + */ |
|
| 134 | + public function setHasOptedOutForUxip() |
|
| 135 | + { |
|
| 136 | + $this->ee_config->core->ee_ueip_optin = false; |
|
| 137 | + $this->ee_config->update_espresso_config(false, false); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + public function setHasNotifiedAboutUxip() |
|
| 142 | + { |
|
| 143 | + $this->ee_config->core->ee_ueip_has_notified = true; |
|
| 144 | + $this->ee_config->update_espresso_config(false, false); |
|
| 145 | + } |
|
| 146 | 146 | } |
@@ -15,145 +15,145 @@ |
||
| 15 | 15 | class CustomTaxonomyDefinitions |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var array $taxonomies |
|
| 20 | - */ |
|
| 21 | - private $taxonomies; |
|
| 18 | + /** |
|
| 19 | + * @var array $taxonomies |
|
| 20 | + */ |
|
| 21 | + private $taxonomies; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * EspressoCustomPostTypeDefinitions constructor. |
|
| 26 | - */ |
|
| 27 | - public function __construct() |
|
| 28 | - { |
|
| 29 | - $this->setTaxonomies(); |
|
| 30 | - add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2); |
|
| 31 | - } |
|
| 24 | + /** |
|
| 25 | + * EspressoCustomPostTypeDefinitions constructor. |
|
| 26 | + */ |
|
| 27 | + public function __construct() |
|
| 28 | + { |
|
| 29 | + $this->setTaxonomies(); |
|
| 30 | + add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - private function setTaxonomies() |
|
| 35 | - { |
|
| 36 | - $this->taxonomies = array( |
|
| 37 | - 'espresso_event_categories' => array( |
|
| 38 | - 'singular_name' => esc_html__('Event Category', 'event_espresso'), |
|
| 39 | - 'plural_name' => esc_html__('Event Categories', 'event_espresso'), |
|
| 40 | - 'args' => array( |
|
| 41 | - 'public' => true, |
|
| 42 | - 'show_in_nav_menus' => true, |
|
| 43 | - 'show_in_rest' => true, |
|
| 44 | - 'capabilities' => array( |
|
| 45 | - 'manage_terms' => 'ee_manage_event_categories', |
|
| 46 | - 'edit_terms' => 'ee_edit_event_category', |
|
| 47 | - 'delete_terms' => 'ee_delete_event_category', |
|
| 48 | - 'assign_terms' => 'ee_assign_event_category', |
|
| 49 | - ), |
|
| 50 | - 'rewrite' => array( |
|
| 51 | - 'slug' => EEH_URL::slugify( |
|
| 52 | - __('event-category', 'event_espresso'), |
|
| 53 | - 'event-category' |
|
| 54 | - ) |
|
| 55 | - ), |
|
| 56 | - ), |
|
| 57 | - ), |
|
| 58 | - 'espresso_venue_categories' => array( |
|
| 59 | - 'singular_name' => esc_html__('Venue Category', 'event_espresso'), |
|
| 60 | - 'plural_name' => esc_html__('Venue Categories', 'event_espresso'), |
|
| 61 | - 'args' => array( |
|
| 62 | - 'public' => true, |
|
| 63 | - 'show_in_nav_menus' => false, // by default this doesn't show for decaf |
|
| 64 | - 'show_in_rest' => true, |
|
| 65 | - 'capabilities' => array( |
|
| 66 | - 'manage_terms' => 'ee_manage_venue_categories', |
|
| 67 | - 'edit_terms' => 'ee_edit_venue_category', |
|
| 68 | - 'delete_terms' => 'ee_delete_venue_category', |
|
| 69 | - 'assign_terms' => 'ee_assign_venue_category', |
|
| 70 | - ), |
|
| 71 | - 'rewrite' => array( |
|
| 72 | - 'slug' => EEH_URL::slugify( |
|
| 73 | - __('venue-category', 'event_espresso'), |
|
| 74 | - 'venue-category' |
|
| 75 | - ) |
|
| 76 | - ), |
|
| 77 | - ), |
|
| 78 | - ), |
|
| 79 | - 'espresso_event_type' => array( |
|
| 80 | - 'singular_name' => esc_html__('Event Type', 'event_espresso'), |
|
| 81 | - 'plural_name' => esc_html__('Event Types', 'event_espresso'), |
|
| 82 | - 'args' => array( |
|
| 83 | - 'public' => true, |
|
| 84 | - 'show_ui' => false, |
|
| 85 | - 'show_in_rest' => true, |
|
| 86 | - 'capabilities' => array( |
|
| 87 | - 'manage_terms' => 'ee_read_event_type', |
|
| 88 | - 'edit_terms' => 'ee_edit_event_type', |
|
| 89 | - 'delete_terms' => 'ee_delete_event_type', |
|
| 90 | - 'assign_terms' => 'ee_assign_event_type', |
|
| 91 | - ), |
|
| 92 | - 'rewrite' => array( |
|
| 93 | - 'slug' => EEH_URL::slugify( |
|
| 94 | - __('event-type', 'event_espresso'), |
|
| 95 | - 'event-type' |
|
| 96 | - ) |
|
| 97 | - ), |
|
| 98 | - 'hierarchical' => true, |
|
| 99 | - ), |
|
| 100 | - ), |
|
| 101 | - ); |
|
| 102 | - } |
|
| 34 | + private function setTaxonomies() |
|
| 35 | + { |
|
| 36 | + $this->taxonomies = array( |
|
| 37 | + 'espresso_event_categories' => array( |
|
| 38 | + 'singular_name' => esc_html__('Event Category', 'event_espresso'), |
|
| 39 | + 'plural_name' => esc_html__('Event Categories', 'event_espresso'), |
|
| 40 | + 'args' => array( |
|
| 41 | + 'public' => true, |
|
| 42 | + 'show_in_nav_menus' => true, |
|
| 43 | + 'show_in_rest' => true, |
|
| 44 | + 'capabilities' => array( |
|
| 45 | + 'manage_terms' => 'ee_manage_event_categories', |
|
| 46 | + 'edit_terms' => 'ee_edit_event_category', |
|
| 47 | + 'delete_terms' => 'ee_delete_event_category', |
|
| 48 | + 'assign_terms' => 'ee_assign_event_category', |
|
| 49 | + ), |
|
| 50 | + 'rewrite' => array( |
|
| 51 | + 'slug' => EEH_URL::slugify( |
|
| 52 | + __('event-category', 'event_espresso'), |
|
| 53 | + 'event-category' |
|
| 54 | + ) |
|
| 55 | + ), |
|
| 56 | + ), |
|
| 57 | + ), |
|
| 58 | + 'espresso_venue_categories' => array( |
|
| 59 | + 'singular_name' => esc_html__('Venue Category', 'event_espresso'), |
|
| 60 | + 'plural_name' => esc_html__('Venue Categories', 'event_espresso'), |
|
| 61 | + 'args' => array( |
|
| 62 | + 'public' => true, |
|
| 63 | + 'show_in_nav_menus' => false, // by default this doesn't show for decaf |
|
| 64 | + 'show_in_rest' => true, |
|
| 65 | + 'capabilities' => array( |
|
| 66 | + 'manage_terms' => 'ee_manage_venue_categories', |
|
| 67 | + 'edit_terms' => 'ee_edit_venue_category', |
|
| 68 | + 'delete_terms' => 'ee_delete_venue_category', |
|
| 69 | + 'assign_terms' => 'ee_assign_venue_category', |
|
| 70 | + ), |
|
| 71 | + 'rewrite' => array( |
|
| 72 | + 'slug' => EEH_URL::slugify( |
|
| 73 | + __('venue-category', 'event_espresso'), |
|
| 74 | + 'venue-category' |
|
| 75 | + ) |
|
| 76 | + ), |
|
| 77 | + ), |
|
| 78 | + ), |
|
| 79 | + 'espresso_event_type' => array( |
|
| 80 | + 'singular_name' => esc_html__('Event Type', 'event_espresso'), |
|
| 81 | + 'plural_name' => esc_html__('Event Types', 'event_espresso'), |
|
| 82 | + 'args' => array( |
|
| 83 | + 'public' => true, |
|
| 84 | + 'show_ui' => false, |
|
| 85 | + 'show_in_rest' => true, |
|
| 86 | + 'capabilities' => array( |
|
| 87 | + 'manage_terms' => 'ee_read_event_type', |
|
| 88 | + 'edit_terms' => 'ee_edit_event_type', |
|
| 89 | + 'delete_terms' => 'ee_delete_event_type', |
|
| 90 | + 'assign_terms' => 'ee_assign_event_type', |
|
| 91 | + ), |
|
| 92 | + 'rewrite' => array( |
|
| 93 | + 'slug' => EEH_URL::slugify( |
|
| 94 | + __('event-type', 'event_espresso'), |
|
| 95 | + 'event-type' |
|
| 96 | + ) |
|
| 97 | + ), |
|
| 98 | + 'hierarchical' => true, |
|
| 99 | + ), |
|
| 100 | + ), |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @return array |
|
| 107 | - */ |
|
| 108 | - public function getCustomTaxonomyDefinitions() |
|
| 109 | - { |
|
| 110 | - return (array) apply_filters( |
|
| 111 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
| 112 | - // legacy filter applied for now, |
|
| 113 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
| 114 | - apply_filters( |
|
| 115 | - 'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', |
|
| 116 | - $this->taxonomies |
|
| 117 | - ) |
|
| 118 | - ); |
|
| 119 | - } |
|
| 105 | + /** |
|
| 106 | + * @return array |
|
| 107 | + */ |
|
| 108 | + public function getCustomTaxonomyDefinitions() |
|
| 109 | + { |
|
| 110 | + return (array) apply_filters( |
|
| 111 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
| 112 | + // legacy filter applied for now, |
|
| 113 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
| 114 | + apply_filters( |
|
| 115 | + 'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', |
|
| 116 | + $this->taxonomies |
|
| 117 | + ) |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function getCustomTaxonomySlugs() |
|
| 126 | - { |
|
| 127 | - return array_keys($this->getCustomTaxonomyDefinitions()); |
|
| 128 | - } |
|
| 122 | + /** |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function getCustomTaxonomySlugs() |
|
| 126 | + { |
|
| 127 | + return array_keys($this->getCustomTaxonomyDefinitions()); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * By default, WordPress strips all html from term taxonomy description content. |
|
| 133 | - * The purpose of this method is to remove that restriction |
|
| 134 | - * and ensure that we still run ee term taxonomy descriptions |
|
| 135 | - * through some full html sanitization equivalent to the post content field. |
|
| 136 | - * So first we remove default filter for term description |
|
| 137 | - * but we have to do this earlier before wp sets their own filter |
|
| 138 | - * because they just set a global filter on all term descriptions |
|
| 139 | - * before the custom term description filter. |
|
| 140 | - * Really sux. |
|
| 141 | - * |
|
| 142 | - * @param string $description The description content. |
|
| 143 | - * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function filterCustomTermDescription($description, $taxonomy) |
|
| 147 | - { |
|
| 148 | - // get a list of EE taxonomies |
|
| 149 | - $custom_taxonomies = $this->getCustomTaxonomySlugs(); |
|
| 150 | - // only do our own thing if the taxonomy listed is an ee taxonomy. |
|
| 151 | - if (in_array($taxonomy, $custom_taxonomies, true)) { |
|
| 152 | - // remove default wp filter |
|
| 153 | - remove_filter('pre_term_description', 'wp_filter_kses'); |
|
| 154 | - // sanitize THIS content. |
|
| 155 | - $description = wp_kses($description, wp_kses_allowed_html('post')); |
|
| 156 | - } |
|
| 157 | - return $description; |
|
| 158 | - } |
|
| 131 | + /** |
|
| 132 | + * By default, WordPress strips all html from term taxonomy description content. |
|
| 133 | + * The purpose of this method is to remove that restriction |
|
| 134 | + * and ensure that we still run ee term taxonomy descriptions |
|
| 135 | + * through some full html sanitization equivalent to the post content field. |
|
| 136 | + * So first we remove default filter for term description |
|
| 137 | + * but we have to do this earlier before wp sets their own filter |
|
| 138 | + * because they just set a global filter on all term descriptions |
|
| 139 | + * before the custom term description filter. |
|
| 140 | + * Really sux. |
|
| 141 | + * |
|
| 142 | + * @param string $description The description content. |
|
| 143 | + * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function filterCustomTermDescription($description, $taxonomy) |
|
| 147 | + { |
|
| 148 | + // get a list of EE taxonomies |
|
| 149 | + $custom_taxonomies = $this->getCustomTaxonomySlugs(); |
|
| 150 | + // only do our own thing if the taxonomy listed is an ee taxonomy. |
|
| 151 | + if (in_array($taxonomy, $custom_taxonomies, true)) { |
|
| 152 | + // remove default wp filter |
|
| 153 | + remove_filter('pre_term_description', 'wp_filter_kses'); |
|
| 154 | + // sanitize THIS content. |
|
| 155 | + $description = wp_kses($description, wp_kses_allowed_html('post')); |
|
| 156 | + } |
|
| 157 | + return $description; |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -17,23 +17,23 @@ |
||
| 17 | 17 | class DetectFileEditorRequest extends Middleware |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * converts a Request to a Response |
|
| 22 | - * |
|
| 23 | - * @param RequestInterface $request |
|
| 24 | - * @param ResponseInterface $response |
|
| 25 | - * @return ResponseInterface |
|
| 26 | - */ |
|
| 27 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 28 | - { |
|
| 29 | - $this->request = $request; |
|
| 30 | - $this->response = $response; |
|
| 31 | - // can't store user data during WP error scrapes if no user exists |
|
| 32 | - // so don't load the session since it's not going to work anyways |
|
| 33 | - if ($this->request->isWordPressScrape()) { |
|
| 34 | - add_filter('FHEE_load_EE_Session', '__return_false', 999); |
|
| 35 | - } |
|
| 36 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 37 | - return $this->response; |
|
| 38 | - } |
|
| 20 | + /** |
|
| 21 | + * converts a Request to a Response |
|
| 22 | + * |
|
| 23 | + * @param RequestInterface $request |
|
| 24 | + * @param ResponseInterface $response |
|
| 25 | + * @return ResponseInterface |
|
| 26 | + */ |
|
| 27 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 28 | + { |
|
| 29 | + $this->request = $request; |
|
| 30 | + $this->response = $response; |
|
| 31 | + // can't store user data during WP error scrapes if no user exists |
|
| 32 | + // so don't load the session since it's not going to work anyways |
|
| 33 | + if ($this->request->isWordPressScrape()) { |
|
| 34 | + add_filter('FHEE_load_EE_Session', '__return_false', 999); |
|
| 35 | + } |
|
| 36 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 37 | + return $this->response; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -76,22 +76,22 @@ discard block |
||
| 76 | 76 | public function getModelSchemaForFields(array $model_fields, array $schema) |
| 77 | 77 | { |
| 78 | 78 | foreach ($model_fields as $field => $model_field) { |
| 79 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
| 79 | + if ( ! $model_field instanceof EE_Model_Field_Base) { |
|
| 80 | 80 | continue; |
| 81 | 81 | } |
| 82 | - $schema['properties'][ $field ] = $model_field->getSchema(); |
|
| 82 | + $schema['properties'][$field] = $model_field->getSchema(); |
|
| 83 | 83 | |
| 84 | 84 | // if this is a primary key field add the primary key item |
| 85 | 85 | if ($model_field instanceof EE_Primary_Key_Field_Base) { |
| 86 | - $schema['properties'][ $field ]['primary_key'] = true; |
|
| 86 | + $schema['properties'][$field]['primary_key'] = true; |
|
| 87 | 87 | if ($model_field instanceof EE_Primary_Key_Int_Field) { |
| 88 | - $schema['properties'][ $field ]['readonly'] = true; |
|
| 88 | + $schema['properties'][$field]['readonly'] = true; |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // if this is a foreign key field add the foreign key item |
| 93 | 93 | if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
| 94 | - $schema['properties'][ $field ]['foreign_key'] = array( |
|
| 94 | + $schema['properties'][$field]['foreign_key'] = array( |
|
| 95 | 95 | 'description' => esc_html__( |
| 96 | 96 | 'This is a foreign key the points to the given models.', |
| 97 | 97 | 'event_espresso' |
@@ -115,18 +115,18 @@ discard block |
||
| 115 | 115 | public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
| 116 | 116 | { |
| 117 | 117 | foreach ($relations_on_model as $model_name => $relation) { |
| 118 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
| 118 | + if ( ! $relation instanceof EE_Model_Relation_Base) { |
|
| 119 | 119 | continue; |
| 120 | 120 | } |
| 121 | 121 | $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
| 122 | 122 | ? strtolower($model_name) |
| 123 | 123 | : EEH_Inflector::pluralize_and_lower($model_name); |
| 124 | - $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
| 125 | - $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
| 124 | + $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
| 125 | + $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
| 126 | 126 | |
| 127 | 127 | // links schema |
| 128 | - $links_key = 'https://api.eventespresso.com/' . strtolower($model_name); |
|
| 129 | - $schema['properties']['_links']['properties'][ $links_key ] = array( |
|
| 128 | + $links_key = 'https://api.eventespresso.com/'.strtolower($model_name); |
|
| 129 | + $schema['properties']['_links']['properties'][$links_key] = array( |
|
| 130 | 130 | 'description' => esc_html__( |
| 131 | 131 | 'Array of objects describing the link(s) for this relation resource.', |
| 132 | 132 | 'event_espresso' |
@@ -25,256 +25,256 @@ |
||
| 25 | 25 | class JsonModelSchema |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var EEM_Base |
|
| 30 | - */ |
|
| 31 | - protected $model; |
|
| 28 | + /** |
|
| 29 | + * @var EEM_Base |
|
| 30 | + */ |
|
| 31 | + protected $model; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var CalculatedModelFields |
|
| 35 | - */ |
|
| 36 | - protected $fields_calculator; |
|
| 33 | + /** |
|
| 34 | + * @var CalculatedModelFields |
|
| 35 | + */ |
|
| 36 | + protected $fields_calculator; |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * JsonModelSchema constructor. |
|
| 41 | - * |
|
| 42 | - * @param EEM_Base $model |
|
| 43 | - * @param CalculatedModelFields $fields_calculator |
|
| 44 | - */ |
|
| 45 | - public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator) |
|
| 46 | - { |
|
| 47 | - $this->model = $model; |
|
| 48 | - $this->fields_calculator = $fields_calculator; |
|
| 49 | - } |
|
| 39 | + /** |
|
| 40 | + * JsonModelSchema constructor. |
|
| 41 | + * |
|
| 42 | + * @param EEM_Base $model |
|
| 43 | + * @param CalculatedModelFields $fields_calculator |
|
| 44 | + */ |
|
| 45 | + public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator) |
|
| 46 | + { |
|
| 47 | + $this->model = $model; |
|
| 48 | + $this->fields_calculator = $fields_calculator; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Return the schema for a given model from a given model. |
|
| 54 | - * |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function getModelSchema() |
|
| 58 | - { |
|
| 59 | - return $this->getModelSchemaForRelations( |
|
| 60 | - $this->model->relation_settings(), |
|
| 61 | - $this->getModelSchemaForFields( |
|
| 62 | - $this->model->field_settings(), |
|
| 63 | - $this->getInitialSchemaStructure() |
|
| 64 | - ) |
|
| 65 | - ); |
|
| 66 | - } |
|
| 52 | + /** |
|
| 53 | + * Return the schema for a given model from a given model. |
|
| 54 | + * |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function getModelSchema() |
|
| 58 | + { |
|
| 59 | + return $this->getModelSchemaForRelations( |
|
| 60 | + $this->model->relation_settings(), |
|
| 61 | + $this->getModelSchemaForFields( |
|
| 62 | + $this->model->field_settings(), |
|
| 63 | + $this->getInitialSchemaStructure() |
|
| 64 | + ) |
|
| 65 | + ); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Get the schema for a given set of model fields. |
|
| 71 | - * |
|
| 72 | - * @param EE_Model_Field_Base[] $model_fields |
|
| 73 | - * @param array $schema |
|
| 74 | - * @return array |
|
| 75 | - */ |
|
| 76 | - public function getModelSchemaForFields(array $model_fields, array $schema) |
|
| 77 | - { |
|
| 78 | - foreach ($model_fields as $field => $model_field) { |
|
| 79 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
| 80 | - continue; |
|
| 81 | - } |
|
| 82 | - $schema['properties'][ $field ] = $model_field->getSchema(); |
|
| 69 | + /** |
|
| 70 | + * Get the schema for a given set of model fields. |
|
| 71 | + * |
|
| 72 | + * @param EE_Model_Field_Base[] $model_fields |
|
| 73 | + * @param array $schema |
|
| 74 | + * @return array |
|
| 75 | + */ |
|
| 76 | + public function getModelSchemaForFields(array $model_fields, array $schema) |
|
| 77 | + { |
|
| 78 | + foreach ($model_fields as $field => $model_field) { |
|
| 79 | + if (! $model_field instanceof EE_Model_Field_Base) { |
|
| 80 | + continue; |
|
| 81 | + } |
|
| 82 | + $schema['properties'][ $field ] = $model_field->getSchema(); |
|
| 83 | 83 | |
| 84 | - // if this is a primary key field add the primary key item |
|
| 85 | - if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
| 86 | - $schema['properties'][ $field ]['primary_key'] = true; |
|
| 87 | - if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
| 88 | - $schema['properties'][ $field ]['readonly'] = true; |
|
| 89 | - } |
|
| 90 | - } |
|
| 84 | + // if this is a primary key field add the primary key item |
|
| 85 | + if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
| 86 | + $schema['properties'][ $field ]['primary_key'] = true; |
|
| 87 | + if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
| 88 | + $schema['properties'][ $field ]['readonly'] = true; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - // if this is a foreign key field add the foreign key item |
|
| 93 | - if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
| 94 | - $schema['properties'][ $field ]['foreign_key'] = array( |
|
| 95 | - 'description' => esc_html__( |
|
| 96 | - 'This is a foreign key the points to the given models.', |
|
| 97 | - 'event_espresso' |
|
| 98 | - ), |
|
| 99 | - 'type' => 'array', |
|
| 100 | - 'enum' => $model_field->get_model_class_names_pointed_to(), |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - return $schema; |
|
| 105 | - } |
|
| 92 | + // if this is a foreign key field add the foreign key item |
|
| 93 | + if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
| 94 | + $schema['properties'][ $field ]['foreign_key'] = array( |
|
| 95 | + 'description' => esc_html__( |
|
| 96 | + 'This is a foreign key the points to the given models.', |
|
| 97 | + 'event_espresso' |
|
| 98 | + ), |
|
| 99 | + 'type' => 'array', |
|
| 100 | + 'enum' => $model_field->get_model_class_names_pointed_to(), |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + return $schema; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Get the schema for a given set of model relations |
|
| 110 | - * |
|
| 111 | - * @param EE_Model_Relation_Base[] $relations_on_model |
|
| 112 | - * @param array $schema |
|
| 113 | - * @return array |
|
| 114 | - */ |
|
| 115 | - public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
| 116 | - { |
|
| 117 | - foreach ($relations_on_model as $model_name => $relation) { |
|
| 118 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
| 119 | - continue; |
|
| 120 | - } |
|
| 121 | - $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
| 122 | - ? strtolower($model_name) |
|
| 123 | - : EEH_Inflector::pluralize_and_lower($model_name); |
|
| 124 | - $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
| 125 | - $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
| 108 | + /** |
|
| 109 | + * Get the schema for a given set of model relations |
|
| 110 | + * |
|
| 111 | + * @param EE_Model_Relation_Base[] $relations_on_model |
|
| 112 | + * @param array $schema |
|
| 113 | + * @return array |
|
| 114 | + */ |
|
| 115 | + public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
| 116 | + { |
|
| 117 | + foreach ($relations_on_model as $model_name => $relation) { |
|
| 118 | + if (! $relation instanceof EE_Model_Relation_Base) { |
|
| 119 | + continue; |
|
| 120 | + } |
|
| 121 | + $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
| 122 | + ? strtolower($model_name) |
|
| 123 | + : EEH_Inflector::pluralize_and_lower($model_name); |
|
| 124 | + $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
| 125 | + $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
| 126 | 126 | |
| 127 | - // links schema |
|
| 128 | - $links_key = 'https://api.eventespresso.com/' . strtolower($model_name); |
|
| 129 | - $schema['properties']['_links']['properties'][ $links_key ] = array( |
|
| 130 | - 'description' => esc_html__( |
|
| 131 | - 'Array of objects describing the link(s) for this relation resource.', |
|
| 132 | - 'event_espresso' |
|
| 133 | - ), |
|
| 134 | - 'type' => 'array', |
|
| 135 | - 'readonly' => true, |
|
| 136 | - 'items' => array( |
|
| 137 | - 'type' => 'object', |
|
| 138 | - 'properties' => array( |
|
| 139 | - 'href' => array( |
|
| 140 | - 'type' => 'string', |
|
| 141 | - 'description' => sprintf( |
|
| 142 | - // translators: placeholder is the model name for the relation. |
|
| 143 | - esc_html__( |
|
| 144 | - 'The link to the resource for the %s relation(s) to this entity', |
|
| 145 | - 'event_espresso' |
|
| 146 | - ), |
|
| 147 | - $model_name |
|
| 148 | - ), |
|
| 149 | - ), |
|
| 150 | - 'single' => array( |
|
| 151 | - 'type' => 'boolean', |
|
| 152 | - 'description' => sprintf( |
|
| 153 | - // translators: placeholder is the model name for the relation. |
|
| 154 | - esc_html__( |
|
| 155 | - 'Whether or not there is only a single %s relation to this entity', |
|
| 156 | - 'event_espresso' |
|
| 157 | - ), |
|
| 158 | - $model_name |
|
| 159 | - ), |
|
| 160 | - ), |
|
| 161 | - ), |
|
| 162 | - 'additionalProperties' => false |
|
| 163 | - ), |
|
| 164 | - ); |
|
| 165 | - } |
|
| 166 | - return $schema; |
|
| 167 | - } |
|
| 127 | + // links schema |
|
| 128 | + $links_key = 'https://api.eventespresso.com/' . strtolower($model_name); |
|
| 129 | + $schema['properties']['_links']['properties'][ $links_key ] = array( |
|
| 130 | + 'description' => esc_html__( |
|
| 131 | + 'Array of objects describing the link(s) for this relation resource.', |
|
| 132 | + 'event_espresso' |
|
| 133 | + ), |
|
| 134 | + 'type' => 'array', |
|
| 135 | + 'readonly' => true, |
|
| 136 | + 'items' => array( |
|
| 137 | + 'type' => 'object', |
|
| 138 | + 'properties' => array( |
|
| 139 | + 'href' => array( |
|
| 140 | + 'type' => 'string', |
|
| 141 | + 'description' => sprintf( |
|
| 142 | + // translators: placeholder is the model name for the relation. |
|
| 143 | + esc_html__( |
|
| 144 | + 'The link to the resource for the %s relation(s) to this entity', |
|
| 145 | + 'event_espresso' |
|
| 146 | + ), |
|
| 147 | + $model_name |
|
| 148 | + ), |
|
| 149 | + ), |
|
| 150 | + 'single' => array( |
|
| 151 | + 'type' => 'boolean', |
|
| 152 | + 'description' => sprintf( |
|
| 153 | + // translators: placeholder is the model name for the relation. |
|
| 154 | + esc_html__( |
|
| 155 | + 'Whether or not there is only a single %s relation to this entity', |
|
| 156 | + 'event_espresso' |
|
| 157 | + ), |
|
| 158 | + $model_name |
|
| 159 | + ), |
|
| 160 | + ), |
|
| 161 | + ), |
|
| 162 | + 'additionalProperties' => false |
|
| 163 | + ), |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | + return $schema; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Outputs the schema header for a model. |
|
| 172 | - * |
|
| 173 | - * @return array |
|
| 174 | - */ |
|
| 175 | - public function getInitialSchemaStructure() |
|
| 176 | - { |
|
| 177 | - return array( |
|
| 178 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 179 | - 'title' => $this->model->get_this_model_name(), |
|
| 180 | - 'type' => 'object', |
|
| 181 | - 'properties' => array( |
|
| 182 | - 'link' => array( |
|
| 183 | - 'description' => esc_html__( |
|
| 184 | - 'Link to event on WordPress site hosting events.', |
|
| 185 | - 'event_espresso' |
|
| 186 | - ), |
|
| 187 | - 'type' => 'string', |
|
| 188 | - 'readonly' => true, |
|
| 189 | - ), |
|
| 190 | - '_links' => array( |
|
| 191 | - 'description' => esc_html__( |
|
| 192 | - 'Various links for resources related to the entity.', |
|
| 193 | - 'event_espresso' |
|
| 194 | - ), |
|
| 195 | - 'type' => 'object', |
|
| 196 | - 'readonly' => true, |
|
| 197 | - 'properties' => array( |
|
| 198 | - 'self' => array( |
|
| 199 | - 'description' => esc_html__( |
|
| 200 | - 'Link to this entities resource.', |
|
| 201 | - 'event_espresso' |
|
| 202 | - ), |
|
| 203 | - 'type' => 'array', |
|
| 204 | - 'items' => array( |
|
| 205 | - 'type' => 'object', |
|
| 206 | - 'properties' => array( |
|
| 207 | - 'href' => array( |
|
| 208 | - 'type' => 'string', |
|
| 209 | - ), |
|
| 210 | - ), |
|
| 211 | - 'additionalProperties' => false |
|
| 212 | - ), |
|
| 213 | - 'readonly' => true |
|
| 214 | - ), |
|
| 215 | - 'collection' => array( |
|
| 216 | - 'description' => esc_html__( |
|
| 217 | - 'Link to this entities collection resource.', |
|
| 218 | - 'event_espresso' |
|
| 219 | - ), |
|
| 220 | - 'type' => 'array', |
|
| 221 | - 'items' => array( |
|
| 222 | - 'type' => 'object', |
|
| 223 | - 'properties' => array( |
|
| 224 | - 'href' => array( |
|
| 225 | - 'type' => 'string' |
|
| 226 | - ), |
|
| 227 | - ), |
|
| 228 | - 'additionalProperties' => false |
|
| 229 | - ), |
|
| 230 | - 'readonly' => true |
|
| 231 | - ), |
|
| 232 | - ), |
|
| 233 | - 'additionalProperties' => false, |
|
| 234 | - ), |
|
| 235 | - '_calculated_fields' => array_merge( |
|
| 236 | - $this->fields_calculator->getJsonSchemaForModel($this->model), |
|
| 237 | - array( |
|
| 238 | - '_protected' => $this->getProtectedFieldsSchema() |
|
| 239 | - ) |
|
| 240 | - ), |
|
| 241 | - '_protected' => $this->getProtectedFieldsSchema() |
|
| 242 | - ), |
|
| 243 | - 'additionalProperties' => false, |
|
| 244 | - ); |
|
| 245 | - } |
|
| 170 | + /** |
|
| 171 | + * Outputs the schema header for a model. |
|
| 172 | + * |
|
| 173 | + * @return array |
|
| 174 | + */ |
|
| 175 | + public function getInitialSchemaStructure() |
|
| 176 | + { |
|
| 177 | + return array( |
|
| 178 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 179 | + 'title' => $this->model->get_this_model_name(), |
|
| 180 | + 'type' => 'object', |
|
| 181 | + 'properties' => array( |
|
| 182 | + 'link' => array( |
|
| 183 | + 'description' => esc_html__( |
|
| 184 | + 'Link to event on WordPress site hosting events.', |
|
| 185 | + 'event_espresso' |
|
| 186 | + ), |
|
| 187 | + 'type' => 'string', |
|
| 188 | + 'readonly' => true, |
|
| 189 | + ), |
|
| 190 | + '_links' => array( |
|
| 191 | + 'description' => esc_html__( |
|
| 192 | + 'Various links for resources related to the entity.', |
|
| 193 | + 'event_espresso' |
|
| 194 | + ), |
|
| 195 | + 'type' => 'object', |
|
| 196 | + 'readonly' => true, |
|
| 197 | + 'properties' => array( |
|
| 198 | + 'self' => array( |
|
| 199 | + 'description' => esc_html__( |
|
| 200 | + 'Link to this entities resource.', |
|
| 201 | + 'event_espresso' |
|
| 202 | + ), |
|
| 203 | + 'type' => 'array', |
|
| 204 | + 'items' => array( |
|
| 205 | + 'type' => 'object', |
|
| 206 | + 'properties' => array( |
|
| 207 | + 'href' => array( |
|
| 208 | + 'type' => 'string', |
|
| 209 | + ), |
|
| 210 | + ), |
|
| 211 | + 'additionalProperties' => false |
|
| 212 | + ), |
|
| 213 | + 'readonly' => true |
|
| 214 | + ), |
|
| 215 | + 'collection' => array( |
|
| 216 | + 'description' => esc_html__( |
|
| 217 | + 'Link to this entities collection resource.', |
|
| 218 | + 'event_espresso' |
|
| 219 | + ), |
|
| 220 | + 'type' => 'array', |
|
| 221 | + 'items' => array( |
|
| 222 | + 'type' => 'object', |
|
| 223 | + 'properties' => array( |
|
| 224 | + 'href' => array( |
|
| 225 | + 'type' => 'string' |
|
| 226 | + ), |
|
| 227 | + ), |
|
| 228 | + 'additionalProperties' => false |
|
| 229 | + ), |
|
| 230 | + 'readonly' => true |
|
| 231 | + ), |
|
| 232 | + ), |
|
| 233 | + 'additionalProperties' => false, |
|
| 234 | + ), |
|
| 235 | + '_calculated_fields' => array_merge( |
|
| 236 | + $this->fields_calculator->getJsonSchemaForModel($this->model), |
|
| 237 | + array( |
|
| 238 | + '_protected' => $this->getProtectedFieldsSchema() |
|
| 239 | + ) |
|
| 240 | + ), |
|
| 241 | + '_protected' => $this->getProtectedFieldsSchema() |
|
| 242 | + ), |
|
| 243 | + 'additionalProperties' => false, |
|
| 244 | + ); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * Returns an array of JSON schema to describe the _protected property on responses |
|
| 249 | - * @since 4.9.74.p |
|
| 250 | - * @return array |
|
| 251 | - */ |
|
| 252 | - protected function getProtectedFieldsSchema() |
|
| 253 | - { |
|
| 254 | - return array( |
|
| 255 | - 'description' => esc_html__('Array of property names whose values were replaced with their default (because they are related to a password-protected entity.)', 'event_espresso'), |
|
| 256 | - 'type' => 'array', |
|
| 257 | - 'items' => array( |
|
| 258 | - 'description' => esc_html__('Each name corresponds to a property that is protected by password for this entity and has its default value returned in the response.', 'event_espresso'), |
|
| 259 | - 'type' => 'string', |
|
| 260 | - 'readonly' => true, |
|
| 261 | - ), |
|
| 262 | - 'readonly' => true |
|
| 263 | - ); |
|
| 264 | - } |
|
| 247 | + /** |
|
| 248 | + * Returns an array of JSON schema to describe the _protected property on responses |
|
| 249 | + * @since 4.9.74.p |
|
| 250 | + * @return array |
|
| 251 | + */ |
|
| 252 | + protected function getProtectedFieldsSchema() |
|
| 253 | + { |
|
| 254 | + return array( |
|
| 255 | + 'description' => esc_html__('Array of property names whose values were replaced with their default (because they are related to a password-protected entity.)', 'event_espresso'), |
|
| 256 | + 'type' => 'array', |
|
| 257 | + 'items' => array( |
|
| 258 | + 'description' => esc_html__('Each name corresponds to a property that is protected by password for this entity and has its default value returned in the response.', 'event_espresso'), |
|
| 259 | + 'type' => 'string', |
|
| 260 | + 'readonly' => true, |
|
| 261 | + ), |
|
| 262 | + 'readonly' => true |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Allows one to just use the object as a string to get the json. |
|
| 269 | - * eg. |
|
| 270 | - * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields); |
|
| 271 | - * echo $json_schema; //outputs the schema as a json formatted string. |
|
| 272 | - * |
|
| 273 | - * @return string |
|
| 274 | - */ |
|
| 275 | - public function __toString() |
|
| 276 | - { |
|
| 277 | - $schema = wp_json_encode($this->getModelSchema()); |
|
| 278 | - return is_string($schema) ? $schema : ''; |
|
| 279 | - } |
|
| 267 | + /** |
|
| 268 | + * Allows one to just use the object as a string to get the json. |
|
| 269 | + * eg. |
|
| 270 | + * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields); |
|
| 271 | + * echo $json_schema; //outputs the schema as a json formatted string. |
|
| 272 | + * |
|
| 273 | + * @return string |
|
| 274 | + */ |
|
| 275 | + public function __toString() |
|
| 276 | + { |
|
| 277 | + $schema = wp_json_encode($this->getModelSchema()); |
|
| 278 | + return is_string($schema) ? $schema : ''; |
|
| 279 | + } |
|
| 280 | 280 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function createFromModel($model_name) |
| 42 | 42 | { |
| 43 | - return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name); |
|
| 43 | + return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\'.$model_name); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | public function createFromClassname($calculator_classname) |
| 52 | 52 | { |
| 53 | 53 | $calculator = $this->loader->getShared($calculator_classname); |
| 54 | - if (!$calculator instanceof Base) { |
|
| 54 | + if ( ! $calculator instanceof Base) { |
|
| 55 | 55 | throw new UnexpectedEntityException( |
| 56 | 56 | $calculator_classname, |
| 57 | 57 | 'EventEspresso\core\libraries\rest_api\calculations\Base' |
@@ -18,46 +18,46 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class CalculatedModelFieldsFactory |
| 20 | 20 | { |
| 21 | - private $loader; |
|
| 21 | + private $loader; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * CalculatedModelFieldsFactory constructor. |
|
| 25 | - * @param LoaderInterface $loader |
|
| 26 | - */ |
|
| 27 | - public function __construct(LoaderInterface $loader) |
|
| 28 | - { |
|
| 29 | - $this->loader = $loader; |
|
| 30 | - } |
|
| 23 | + /** |
|
| 24 | + * CalculatedModelFieldsFactory constructor. |
|
| 25 | + * @param LoaderInterface $loader |
|
| 26 | + */ |
|
| 27 | + public function __construct(LoaderInterface $loader) |
|
| 28 | + { |
|
| 29 | + $this->loader = $loader; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Creates the calculator class that corresponds to that particular model |
|
| 34 | - * @since 4.9.68.p |
|
| 35 | - * @param string $model_name |
|
| 36 | - * @return Base |
|
| 37 | - * @throws UnexpectedEntityException |
|
| 38 | - */ |
|
| 39 | - public function createFromModel($model_name) |
|
| 40 | - { |
|
| 41 | - return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name); |
|
| 42 | - } |
|
| 32 | + /** |
|
| 33 | + * Creates the calculator class that corresponds to that particular model |
|
| 34 | + * @since 4.9.68.p |
|
| 35 | + * @param string $model_name |
|
| 36 | + * @return Base |
|
| 37 | + * @throws UnexpectedEntityException |
|
| 38 | + */ |
|
| 39 | + public function createFromModel($model_name) |
|
| 40 | + { |
|
| 41 | + return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Creates the calculator class that corresponds to that classname and verifies it's of the correct type |
|
| 46 | - * @param string $calculator_classname |
|
| 47 | - * @return Base |
|
| 48 | - * @throws UnexpectedEntityException |
|
| 49 | - */ |
|
| 50 | - public function createFromClassname($calculator_classname) |
|
| 51 | - { |
|
| 52 | - $calculator = $this->loader->getShared($calculator_classname); |
|
| 53 | - if (!$calculator instanceof Base) { |
|
| 54 | - throw new UnexpectedEntityException( |
|
| 55 | - $calculator_classname, |
|
| 56 | - 'EventEspresso\core\libraries\rest_api\calculations\Base' |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - return $calculator; |
|
| 60 | - } |
|
| 44 | + /** |
|
| 45 | + * Creates the calculator class that corresponds to that classname and verifies it's of the correct type |
|
| 46 | + * @param string $calculator_classname |
|
| 47 | + * @return Base |
|
| 48 | + * @throws UnexpectedEntityException |
|
| 49 | + */ |
|
| 50 | + public function createFromClassname($calculator_classname) |
|
| 51 | + { |
|
| 52 | + $calculator = $this->loader->getShared($calculator_classname); |
|
| 53 | + if (!$calculator instanceof Base) { |
|
| 54 | + throw new UnexpectedEntityException( |
|
| 55 | + $calculator_classname, |
|
| 56 | + 'EventEspresso\core\libraries\rest_api\calculations\Base' |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + return $calculator; |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | // End of file CalculationsFactory.php |
| 63 | 63 | // Location: EventEspresso\core\libraries\rest_api\calculations/CalculationsFactory.php |