@@ -19,78 +19,78 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | interface AssetManagerInterface |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @since $VID:$ |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function assetNamespace(); |
|
| 22 | + /** |
|
| 23 | + * @since $VID:$ |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function assetNamespace(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @since 4.9.62.p |
|
| 30 | - */ |
|
| 31 | - public function addAssets(); |
|
| 28 | + /** |
|
| 29 | + * @since 4.9.62.p |
|
| 30 | + */ |
|
| 31 | + public function addAssets(); |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return ManifestFile |
|
| 36 | - * @throws DuplicateCollectionIdentifierException |
|
| 37 | - * @throws InvalidDataTypeException |
|
| 38 | - * @throws InvalidEntityException |
|
| 39 | - * @since 4.9.62.p |
|
| 40 | - */ |
|
| 41 | - public function addManifestFile(); |
|
| 34 | + /** |
|
| 35 | + * @return ManifestFile |
|
| 36 | + * @throws DuplicateCollectionIdentifierException |
|
| 37 | + * @throws InvalidDataTypeException |
|
| 38 | + * @throws InvalidEntityException |
|
| 39 | + * @since 4.9.62.p |
|
| 40 | + */ |
|
| 41 | + public function addManifestFile(); |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return ManifestFile[] |
|
| 46 | - * @since 4.9.62.p |
|
| 47 | - */ |
|
| 48 | - public function getManifestFile(); |
|
| 44 | + /** |
|
| 45 | + * @return ManifestFile[] |
|
| 46 | + * @since 4.9.62.p |
|
| 47 | + */ |
|
| 48 | + public function getManifestFile(); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param string $handle |
|
| 53 | - * @param string $source |
|
| 54 | - * @param array $dependencies |
|
| 55 | - * @param bool $load_in_footer |
|
| 56 | - * @return JavascriptAsset |
|
| 57 | - * @throws DuplicateCollectionIdentifierException |
|
| 58 | - * @throws InvalidDataTypeException |
|
| 59 | - * @throws InvalidEntityException |
|
| 60 | - * @since 4.9.62.p |
|
| 61 | - */ |
|
| 62 | - public function addJavascript( |
|
| 63 | - $handle, |
|
| 64 | - $source, |
|
| 65 | - array $dependencies = array(), |
|
| 66 | - $load_in_footer = true |
|
| 67 | - ); |
|
| 51 | + /** |
|
| 52 | + * @param string $handle |
|
| 53 | + * @param string $source |
|
| 54 | + * @param array $dependencies |
|
| 55 | + * @param bool $load_in_footer |
|
| 56 | + * @return JavascriptAsset |
|
| 57 | + * @throws DuplicateCollectionIdentifierException |
|
| 58 | + * @throws InvalidDataTypeException |
|
| 59 | + * @throws InvalidEntityException |
|
| 60 | + * @since 4.9.62.p |
|
| 61 | + */ |
|
| 62 | + public function addJavascript( |
|
| 63 | + $handle, |
|
| 64 | + $source, |
|
| 65 | + array $dependencies = array(), |
|
| 66 | + $load_in_footer = true |
|
| 67 | + ); |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $handle |
|
| 73 | - * @param string $source |
|
| 74 | - * @param array $dependencies |
|
| 75 | - * @param string $media |
|
| 76 | - * @return StylesheetAsset |
|
| 77 | - * @throws DuplicateCollectionIdentifierException |
|
| 78 | - * @throws InvalidDataTypeException |
|
| 79 | - * @throws InvalidEntityException |
|
| 80 | - * @since 4.9.62.p |
|
| 81 | - */ |
|
| 82 | - public function addStylesheet( |
|
| 83 | - $handle, |
|
| 84 | - $source, |
|
| 85 | - array $dependencies = array(), |
|
| 86 | - $media = 'all' |
|
| 87 | - ); |
|
| 71 | + /** |
|
| 72 | + * @param string $handle |
|
| 73 | + * @param string $source |
|
| 74 | + * @param array $dependencies |
|
| 75 | + * @param string $media |
|
| 76 | + * @return StylesheetAsset |
|
| 77 | + * @throws DuplicateCollectionIdentifierException |
|
| 78 | + * @throws InvalidDataTypeException |
|
| 79 | + * @throws InvalidEntityException |
|
| 80 | + * @since 4.9.62.p |
|
| 81 | + */ |
|
| 82 | + public function addStylesheet( |
|
| 83 | + $handle, |
|
| 84 | + $source, |
|
| 85 | + array $dependencies = array(), |
|
| 86 | + $media = 'all' |
|
| 87 | + ); |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @param string $handle |
|
| 92 | - * @return bool |
|
| 93 | - * @since 4.9.62.p |
|
| 94 | - */ |
|
| 95 | - public function enqueueAsset($handle); |
|
| 90 | + /** |
|
| 91 | + * @param string $handle |
|
| 92 | + * @return bool |
|
| 93 | + * @since 4.9.62.p |
|
| 94 | + */ |
|
| 95 | + public function enqueueAsset($handle); |
|
| 96 | 96 | } |
@@ -12,42 +12,42 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | interface BlockAssetManagerInterface |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @since $VID:$ |
|
| 17 | - * @return string |
|
| 18 | - */ |
|
| 19 | - public function assetNamespace(); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @since $VID:$ |
|
| 23 | - * @return void |
|
| 24 | - */ |
|
| 25 | - public function setAssetHandles(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @since $VID:$ |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function getEditorScriptHandle(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @since $VID:$ |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function getEditorStyleHandle(); |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @since $VID:$ |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public function getScriptHandle(); |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @since $VID:$ |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public function getStyleHandle(); |
|
| 15 | + /** |
|
| 16 | + * @since $VID:$ |
|
| 17 | + * @return string |
|
| 18 | + */ |
|
| 19 | + public function assetNamespace(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @since $VID:$ |
|
| 23 | + * @return void |
|
| 24 | + */ |
|
| 25 | + public function setAssetHandles(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @since $VID:$ |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function getEditorScriptHandle(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @since $VID:$ |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function getEditorStyleHandle(); |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @since $VID:$ |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public function getScriptHandle(); |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @since $VID:$ |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public function getStyleHandle(); |
|
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -43,351 +43,351 @@ |
||
| 43 | 43 | class CollectionDetails implements CollectionDetailsInterface |
| 44 | 44 | { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * if $identifier_type is set to this, |
|
| 48 | - * then the collection will use each object's spl_object_hash() as it's identifier |
|
| 49 | - */ |
|
| 50 | - const ID_OBJECT_HASH = 'identifier-uses-spl-object-hash'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * if $identifier_type is set to this, |
|
| 54 | - * then the collection will use each object's class name as it's identifier |
|
| 55 | - */ |
|
| 56 | - const ID_CLASS_NAME = 'identifier-uses-object-class-name'; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * if $identifier_type is set to this, |
|
| 60 | - * then the collection will use the return value from a specified callback method on each object |
|
| 61 | - */ |
|
| 62 | - const ID_CALLBACK_METHOD = 'identifier-uses-callback-method'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * The interface used for controlling what gets added to the collection |
|
| 66 | - * |
|
| 67 | - * @var string $collection_interface |
|
| 68 | - */ |
|
| 69 | - protected $collection_interface = ''; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * a unique name used to identify the collection in filter names |
|
| 73 | - * supplied value is run through sanitize_title_with_dashes(), |
|
| 74 | - * but then also converts dashes to underscores |
|
| 75 | - * |
|
| 76 | - * @var string $collection_name |
|
| 77 | - */ |
|
| 78 | - protected $collection_name = ''; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * what the collection uses for the object identifier. |
|
| 82 | - * corresponds to one of the class constants above. |
|
| 83 | - * CollectionDetails::ID_OBJECT_HASH will use spl_object_hash( object ) for the identifier |
|
| 84 | - * CollectionDetails::ID_CLASS_NAME will use get_class( object ) for the identifier |
|
| 85 | - * CollectionDetails::ID_CALLBACK_METHOD will use a callback for the identifier |
|
| 86 | - * defaults to using spl_object_hash() so that multiple objects of the same class can be added |
|
| 87 | - * |
|
| 88 | - * @var string $identifier_type |
|
| 89 | - */ |
|
| 90 | - protected $identifier_type = CollectionDetails::ID_OBJECT_HASH; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * the pattern applied to paths when searching for class files to add to the collection |
|
| 94 | - * ie: "My_Awesome_*.class.php" |
|
| 95 | - * defaults to "*.php" |
|
| 96 | - * |
|
| 97 | - * @var string $file_mask |
|
| 98 | - */ |
|
| 99 | - protected $file_mask = ''; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * if the $identifier_type above is set to CollectionDetails::ID_CALLBACK_METHOD, |
|
| 103 | - * then this specifies the method to use on each entity. |
|
| 104 | - * If the callback method does not exist, then an exception will be thrown |
|
| 105 | - * |
|
| 106 | - * @var string $identifier_callback |
|
| 107 | - */ |
|
| 108 | - protected $identifier_callback = ''; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * an array of Fully Qualified Class Names |
|
| 112 | - * for example: |
|
| 113 | - * $FQCNs = array( |
|
| 114 | - * '/Fully/Qualified/ClassNameA' |
|
| 115 | - * '/Fully/Qualified/Other/ClassNameB' |
|
| 116 | - * ); |
|
| 117 | - * |
|
| 118 | - * @var array $collection_FQCNs |
|
| 119 | - */ |
|
| 120 | - protected $collection_FQCNs = array(); |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * an array of full server paths to folders containing files to be loaded into collection |
|
| 124 | - * for example: |
|
| 125 | - * $paths = array( |
|
| 126 | - * '/full/server/path/to/ClassNameA.ext.php' // for class ClassNameA |
|
| 127 | - * '/full/server/path/to/other/ClassNameB.php' // for class ClassNameB |
|
| 128 | - * ); |
|
| 129 | - * |
|
| 130 | - * @var array $collection_paths |
|
| 131 | - */ |
|
| 132 | - protected $collection_paths = array(); |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @var LocatorInterface $file_locator |
|
| 136 | - */ |
|
| 137 | - protected $file_locator; |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * CollectionDetails constructor. |
|
| 142 | - * |
|
| 143 | - * @access public |
|
| 144 | - * @param string $collection_name |
|
| 145 | - * @param string $collection_interface |
|
| 146 | - * @param array $collection_FQCNs |
|
| 147 | - * @param array $collection_paths |
|
| 148 | - * @param string $file_mask |
|
| 149 | - * @param string $identifier_type |
|
| 150 | - * @param string $identifier_callback |
|
| 151 | - * @param LocatorInterface $file_locator |
|
| 152 | - * @throws CollectionDetailsException |
|
| 153 | - */ |
|
| 154 | - public function __construct( |
|
| 155 | - $collection_name, |
|
| 156 | - $collection_interface, |
|
| 157 | - array $collection_FQCNs = array(), |
|
| 158 | - array $collection_paths = array(), |
|
| 159 | - $file_mask = '', |
|
| 160 | - $identifier_type = CollectionDetails::ID_OBJECT_HASH, |
|
| 161 | - $identifier_callback = '', |
|
| 162 | - LocatorInterface $file_locator = null |
|
| 163 | - ) { |
|
| 164 | - try { |
|
| 165 | - $this->setCollectionName($collection_name); |
|
| 166 | - $this->setCollectionInterface($collection_interface); |
|
| 167 | - $this->setCollectionFQCNs($collection_FQCNs); |
|
| 168 | - $this->setCollectionPaths($collection_paths); |
|
| 169 | - $this->setFileMasks($file_mask); |
|
| 170 | - $this->setIdentifierType($identifier_type); |
|
| 171 | - $this->setIdentifierCallback($identifier_callback); |
|
| 172 | - $this->file_locator = $file_locator; |
|
| 173 | - } catch (Exception $exception) { |
|
| 174 | - throw new CollectionDetailsException($exception); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @access public |
|
| 181 | - * @return mixed |
|
| 182 | - */ |
|
| 183 | - public function getCollectionInterface() |
|
| 184 | - { |
|
| 185 | - return $this->collection_interface; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @access protected |
|
| 191 | - * @param string $collection_interface |
|
| 192 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 193 | - */ |
|
| 194 | - protected function setCollectionInterface($collection_interface) |
|
| 195 | - { |
|
| 196 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
| 197 | - throw new InvalidInterfaceException($collection_interface); |
|
| 198 | - } |
|
| 199 | - $this->collection_interface = $collection_interface; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * the collection name will be used for creating dynamic filters |
|
| 205 | - * |
|
| 206 | - * @access public |
|
| 207 | - * @return string |
|
| 208 | - */ |
|
| 209 | - public function collectionName() |
|
| 210 | - { |
|
| 211 | - return $this->collection_name; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * sanitizes collection name and converts spaces and dashes to underscores |
|
| 217 | - * |
|
| 218 | - * @access protected |
|
| 219 | - * @param string $collection_name |
|
| 220 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 221 | - */ |
|
| 222 | - protected function setCollectionName($collection_name) |
|
| 223 | - { |
|
| 224 | - if (! is_string($collection_name)) { |
|
| 225 | - throw new InvalidDataTypeException('$collection_name', $collection_name, 'string'); |
|
| 226 | - } |
|
| 227 | - $this->collection_name = str_replace( |
|
| 228 | - '-', |
|
| 229 | - '_', |
|
| 230 | - sanitize_title_with_dashes($collection_name, '', 'save') |
|
| 231 | - ); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @access public |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - public function identifierType() |
|
| 240 | - { |
|
| 241 | - return $this->identifier_type; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @access protected |
|
| 247 | - * @param string $identifier_type |
|
| 248 | - * @throws InvalidIdentifierException |
|
| 249 | - */ |
|
| 250 | - protected function setIdentifierType($identifier_type) |
|
| 251 | - { |
|
| 252 | - if (! ($identifier_type === CollectionDetails::ID_CLASS_NAME |
|
| 253 | - || $identifier_type === CollectionDetails::ID_OBJECT_HASH |
|
| 254 | - || $identifier_type === CollectionDetails::ID_CALLBACK_METHOD |
|
| 255 | - )) { |
|
| 256 | - throw new InvalidIdentifierException( |
|
| 257 | - $identifier_type, |
|
| 258 | - 'CollectionDetails::ID_CLASS_NAME or CollectionDetails::ID_OBJECT_HASH or CollectionDetails::ID_CALLBACK_METHOD' |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - $this->identifier_type = $identifier_type; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @access public |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - public function identifierCallback() |
|
| 270 | - { |
|
| 271 | - return $this->identifier_callback; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @access protected |
|
| 277 | - * @param string $identifier_callback |
|
| 278 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 279 | - */ |
|
| 280 | - protected function setIdentifierCallback($identifier_callback = 'identifier') |
|
| 281 | - { |
|
| 282 | - if (! is_string($identifier_callback)) { |
|
| 283 | - throw new InvalidDataTypeException('$identifier_callback', $identifier_callback, 'string'); |
|
| 284 | - } |
|
| 285 | - $this->identifier_callback = $identifier_callback; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @access public |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function getFileMask() |
|
| 294 | - { |
|
| 295 | - return $this->file_mask; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * sets the file mask which is then used to filter what files get loaded |
|
| 301 | - * when searching for classes to add to the collection. Defaults to '*.php' |
|
| 302 | - * |
|
| 303 | - * @access protected |
|
| 304 | - * @param string $file_mask |
|
| 305 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 306 | - */ |
|
| 307 | - protected function setFileMasks($file_mask) |
|
| 308 | - { |
|
| 309 | - $this->file_mask = ! empty($file_mask) ? $file_mask : '*.php'; |
|
| 310 | - // we know our default is a string, so if it's not a string now, |
|
| 311 | - // then that means the incoming parameter was something else |
|
| 312 | - if (! is_string($this->file_mask)) { |
|
| 313 | - throw new InvalidDataTypeException('$file_mask', $this->file_mask, 'string'); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @access public |
|
| 320 | - * @return array |
|
| 321 | - */ |
|
| 322 | - public function getCollectionFQCNs() |
|
| 323 | - { |
|
| 324 | - return $this->collection_FQCNs; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @access public |
|
| 330 | - * @param string|array $collection_FQCNs |
|
| 331 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 332 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 333 | - */ |
|
| 334 | - public function setCollectionFQCNs($collection_FQCNs) |
|
| 335 | - { |
|
| 336 | - foreach ((array) $collection_FQCNs as $collection_FQCN) { |
|
| 337 | - if (! empty($collection_FQCN)) { |
|
| 338 | - if (class_exists($collection_FQCN)) { |
|
| 339 | - $this->collection_FQCNs[] = $collection_FQCN; |
|
| 340 | - } else { |
|
| 341 | - foreach ($this->getFQCNsFromPartialNamespace($collection_FQCN) as $FQCN) { |
|
| 342 | - $this->collection_FQCNs[] = $FQCN; |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @access protected |
|
| 352 | - * @param string $partial_FQCN |
|
| 353 | - * @return array |
|
| 354 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 355 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 356 | - */ |
|
| 357 | - protected function getFQCNsFromPartialNamespace($partial_FQCN) |
|
| 358 | - { |
|
| 359 | - if (! $this->file_locator instanceof FqcnLocator) { |
|
| 360 | - $this->file_locator = new FqcnLocator(); |
|
| 361 | - } |
|
| 362 | - $this->file_locator->locate($partial_FQCN); |
|
| 363 | - return $this->file_locator->getFQCNs(); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @access public |
|
| 369 | - * @return array |
|
| 370 | - */ |
|
| 371 | - public function getCollectionPaths() |
|
| 372 | - { |
|
| 373 | - return $this->collection_paths; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @access public |
|
| 379 | - * @param string|array $collection_paths |
|
| 380 | - * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
| 381 | - */ |
|
| 382 | - public function setCollectionPaths($collection_paths) |
|
| 383 | - { |
|
| 384 | - foreach ((array) $collection_paths as $collection_path) { |
|
| 385 | - if (! empty($collection_path)) { |
|
| 386 | - if (! is_readable($collection_path)) { |
|
| 387 | - throw new InvalidFilePathException($collection_path); |
|
| 388 | - } |
|
| 389 | - $this->collection_paths[] = $collection_path; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 46 | + /** |
|
| 47 | + * if $identifier_type is set to this, |
|
| 48 | + * then the collection will use each object's spl_object_hash() as it's identifier |
|
| 49 | + */ |
|
| 50 | + const ID_OBJECT_HASH = 'identifier-uses-spl-object-hash'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * if $identifier_type is set to this, |
|
| 54 | + * then the collection will use each object's class name as it's identifier |
|
| 55 | + */ |
|
| 56 | + const ID_CLASS_NAME = 'identifier-uses-object-class-name'; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * if $identifier_type is set to this, |
|
| 60 | + * then the collection will use the return value from a specified callback method on each object |
|
| 61 | + */ |
|
| 62 | + const ID_CALLBACK_METHOD = 'identifier-uses-callback-method'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * The interface used for controlling what gets added to the collection |
|
| 66 | + * |
|
| 67 | + * @var string $collection_interface |
|
| 68 | + */ |
|
| 69 | + protected $collection_interface = ''; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * a unique name used to identify the collection in filter names |
|
| 73 | + * supplied value is run through sanitize_title_with_dashes(), |
|
| 74 | + * but then also converts dashes to underscores |
|
| 75 | + * |
|
| 76 | + * @var string $collection_name |
|
| 77 | + */ |
|
| 78 | + protected $collection_name = ''; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * what the collection uses for the object identifier. |
|
| 82 | + * corresponds to one of the class constants above. |
|
| 83 | + * CollectionDetails::ID_OBJECT_HASH will use spl_object_hash( object ) for the identifier |
|
| 84 | + * CollectionDetails::ID_CLASS_NAME will use get_class( object ) for the identifier |
|
| 85 | + * CollectionDetails::ID_CALLBACK_METHOD will use a callback for the identifier |
|
| 86 | + * defaults to using spl_object_hash() so that multiple objects of the same class can be added |
|
| 87 | + * |
|
| 88 | + * @var string $identifier_type |
|
| 89 | + */ |
|
| 90 | + protected $identifier_type = CollectionDetails::ID_OBJECT_HASH; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * the pattern applied to paths when searching for class files to add to the collection |
|
| 94 | + * ie: "My_Awesome_*.class.php" |
|
| 95 | + * defaults to "*.php" |
|
| 96 | + * |
|
| 97 | + * @var string $file_mask |
|
| 98 | + */ |
|
| 99 | + protected $file_mask = ''; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * if the $identifier_type above is set to CollectionDetails::ID_CALLBACK_METHOD, |
|
| 103 | + * then this specifies the method to use on each entity. |
|
| 104 | + * If the callback method does not exist, then an exception will be thrown |
|
| 105 | + * |
|
| 106 | + * @var string $identifier_callback |
|
| 107 | + */ |
|
| 108 | + protected $identifier_callback = ''; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * an array of Fully Qualified Class Names |
|
| 112 | + * for example: |
|
| 113 | + * $FQCNs = array( |
|
| 114 | + * '/Fully/Qualified/ClassNameA' |
|
| 115 | + * '/Fully/Qualified/Other/ClassNameB' |
|
| 116 | + * ); |
|
| 117 | + * |
|
| 118 | + * @var array $collection_FQCNs |
|
| 119 | + */ |
|
| 120 | + protected $collection_FQCNs = array(); |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * an array of full server paths to folders containing files to be loaded into collection |
|
| 124 | + * for example: |
|
| 125 | + * $paths = array( |
|
| 126 | + * '/full/server/path/to/ClassNameA.ext.php' // for class ClassNameA |
|
| 127 | + * '/full/server/path/to/other/ClassNameB.php' // for class ClassNameB |
|
| 128 | + * ); |
|
| 129 | + * |
|
| 130 | + * @var array $collection_paths |
|
| 131 | + */ |
|
| 132 | + protected $collection_paths = array(); |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @var LocatorInterface $file_locator |
|
| 136 | + */ |
|
| 137 | + protected $file_locator; |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * CollectionDetails constructor. |
|
| 142 | + * |
|
| 143 | + * @access public |
|
| 144 | + * @param string $collection_name |
|
| 145 | + * @param string $collection_interface |
|
| 146 | + * @param array $collection_FQCNs |
|
| 147 | + * @param array $collection_paths |
|
| 148 | + * @param string $file_mask |
|
| 149 | + * @param string $identifier_type |
|
| 150 | + * @param string $identifier_callback |
|
| 151 | + * @param LocatorInterface $file_locator |
|
| 152 | + * @throws CollectionDetailsException |
|
| 153 | + */ |
|
| 154 | + public function __construct( |
|
| 155 | + $collection_name, |
|
| 156 | + $collection_interface, |
|
| 157 | + array $collection_FQCNs = array(), |
|
| 158 | + array $collection_paths = array(), |
|
| 159 | + $file_mask = '', |
|
| 160 | + $identifier_type = CollectionDetails::ID_OBJECT_HASH, |
|
| 161 | + $identifier_callback = '', |
|
| 162 | + LocatorInterface $file_locator = null |
|
| 163 | + ) { |
|
| 164 | + try { |
|
| 165 | + $this->setCollectionName($collection_name); |
|
| 166 | + $this->setCollectionInterface($collection_interface); |
|
| 167 | + $this->setCollectionFQCNs($collection_FQCNs); |
|
| 168 | + $this->setCollectionPaths($collection_paths); |
|
| 169 | + $this->setFileMasks($file_mask); |
|
| 170 | + $this->setIdentifierType($identifier_type); |
|
| 171 | + $this->setIdentifierCallback($identifier_callback); |
|
| 172 | + $this->file_locator = $file_locator; |
|
| 173 | + } catch (Exception $exception) { |
|
| 174 | + throw new CollectionDetailsException($exception); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @access public |
|
| 181 | + * @return mixed |
|
| 182 | + */ |
|
| 183 | + public function getCollectionInterface() |
|
| 184 | + { |
|
| 185 | + return $this->collection_interface; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @access protected |
|
| 191 | + * @param string $collection_interface |
|
| 192 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 193 | + */ |
|
| 194 | + protected function setCollectionInterface($collection_interface) |
|
| 195 | + { |
|
| 196 | + if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
| 197 | + throw new InvalidInterfaceException($collection_interface); |
|
| 198 | + } |
|
| 199 | + $this->collection_interface = $collection_interface; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * the collection name will be used for creating dynamic filters |
|
| 205 | + * |
|
| 206 | + * @access public |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 209 | + public function collectionName() |
|
| 210 | + { |
|
| 211 | + return $this->collection_name; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * sanitizes collection name and converts spaces and dashes to underscores |
|
| 217 | + * |
|
| 218 | + * @access protected |
|
| 219 | + * @param string $collection_name |
|
| 220 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 221 | + */ |
|
| 222 | + protected function setCollectionName($collection_name) |
|
| 223 | + { |
|
| 224 | + if (! is_string($collection_name)) { |
|
| 225 | + throw new InvalidDataTypeException('$collection_name', $collection_name, 'string'); |
|
| 226 | + } |
|
| 227 | + $this->collection_name = str_replace( |
|
| 228 | + '-', |
|
| 229 | + '_', |
|
| 230 | + sanitize_title_with_dashes($collection_name, '', 'save') |
|
| 231 | + ); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @access public |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + public function identifierType() |
|
| 240 | + { |
|
| 241 | + return $this->identifier_type; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @access protected |
|
| 247 | + * @param string $identifier_type |
|
| 248 | + * @throws InvalidIdentifierException |
|
| 249 | + */ |
|
| 250 | + protected function setIdentifierType($identifier_type) |
|
| 251 | + { |
|
| 252 | + if (! ($identifier_type === CollectionDetails::ID_CLASS_NAME |
|
| 253 | + || $identifier_type === CollectionDetails::ID_OBJECT_HASH |
|
| 254 | + || $identifier_type === CollectionDetails::ID_CALLBACK_METHOD |
|
| 255 | + )) { |
|
| 256 | + throw new InvalidIdentifierException( |
|
| 257 | + $identifier_type, |
|
| 258 | + 'CollectionDetails::ID_CLASS_NAME or CollectionDetails::ID_OBJECT_HASH or CollectionDetails::ID_CALLBACK_METHOD' |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + $this->identifier_type = $identifier_type; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @access public |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + public function identifierCallback() |
|
| 270 | + { |
|
| 271 | + return $this->identifier_callback; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @access protected |
|
| 277 | + * @param string $identifier_callback |
|
| 278 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 279 | + */ |
|
| 280 | + protected function setIdentifierCallback($identifier_callback = 'identifier') |
|
| 281 | + { |
|
| 282 | + if (! is_string($identifier_callback)) { |
|
| 283 | + throw new InvalidDataTypeException('$identifier_callback', $identifier_callback, 'string'); |
|
| 284 | + } |
|
| 285 | + $this->identifier_callback = $identifier_callback; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @access public |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function getFileMask() |
|
| 294 | + { |
|
| 295 | + return $this->file_mask; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * sets the file mask which is then used to filter what files get loaded |
|
| 301 | + * when searching for classes to add to the collection. Defaults to '*.php' |
|
| 302 | + * |
|
| 303 | + * @access protected |
|
| 304 | + * @param string $file_mask |
|
| 305 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 306 | + */ |
|
| 307 | + protected function setFileMasks($file_mask) |
|
| 308 | + { |
|
| 309 | + $this->file_mask = ! empty($file_mask) ? $file_mask : '*.php'; |
|
| 310 | + // we know our default is a string, so if it's not a string now, |
|
| 311 | + // then that means the incoming parameter was something else |
|
| 312 | + if (! is_string($this->file_mask)) { |
|
| 313 | + throw new InvalidDataTypeException('$file_mask', $this->file_mask, 'string'); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @access public |
|
| 320 | + * @return array |
|
| 321 | + */ |
|
| 322 | + public function getCollectionFQCNs() |
|
| 323 | + { |
|
| 324 | + return $this->collection_FQCNs; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @access public |
|
| 330 | + * @param string|array $collection_FQCNs |
|
| 331 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 332 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 333 | + */ |
|
| 334 | + public function setCollectionFQCNs($collection_FQCNs) |
|
| 335 | + { |
|
| 336 | + foreach ((array) $collection_FQCNs as $collection_FQCN) { |
|
| 337 | + if (! empty($collection_FQCN)) { |
|
| 338 | + if (class_exists($collection_FQCN)) { |
|
| 339 | + $this->collection_FQCNs[] = $collection_FQCN; |
|
| 340 | + } else { |
|
| 341 | + foreach ($this->getFQCNsFromPartialNamespace($collection_FQCN) as $FQCN) { |
|
| 342 | + $this->collection_FQCNs[] = $FQCN; |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @access protected |
|
| 352 | + * @param string $partial_FQCN |
|
| 353 | + * @return array |
|
| 354 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 355 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 356 | + */ |
|
| 357 | + protected function getFQCNsFromPartialNamespace($partial_FQCN) |
|
| 358 | + { |
|
| 359 | + if (! $this->file_locator instanceof FqcnLocator) { |
|
| 360 | + $this->file_locator = new FqcnLocator(); |
|
| 361 | + } |
|
| 362 | + $this->file_locator->locate($partial_FQCN); |
|
| 363 | + return $this->file_locator->getFQCNs(); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @access public |
|
| 369 | + * @return array |
|
| 370 | + */ |
|
| 371 | + public function getCollectionPaths() |
|
| 372 | + { |
|
| 373 | + return $this->collection_paths; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @access public |
|
| 379 | + * @param string|array $collection_paths |
|
| 380 | + * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
| 381 | + */ |
|
| 382 | + public function setCollectionPaths($collection_paths) |
|
| 383 | + { |
|
| 384 | + foreach ((array) $collection_paths as $collection_path) { |
|
| 385 | + if (! empty($collection_path)) { |
|
| 386 | + if (! is_readable($collection_path)) { |
|
| 387 | + throw new InvalidFilePathException($collection_path); |
|
| 388 | + } |
|
| 389 | + $this->collection_paths[] = $collection_path; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | 393 | } |
@@ -16,25 +16,25 @@ |
||
| 16 | 16 | class CollectionLoaderException extends RuntimeException |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * DuplicateCollectionIdentifierException constructor. |
|
| 21 | - * |
|
| 22 | - * @param Exception $previous |
|
| 23 | - * @param string $message |
|
| 24 | - * @param int $code |
|
| 25 | - */ |
|
| 26 | - public function __construct(Exception $previous, $message = '', $code = 0) |
|
| 27 | - { |
|
| 28 | - if (empty($message)) { |
|
| 29 | - $message = sprintf( |
|
| 30 | - __( |
|
| 31 | - 'The following error occurred during the creation and/or loading of this collection: %1$s %2$s', |
|
| 32 | - 'event_espresso' |
|
| 33 | - ), |
|
| 34 | - '<br />', |
|
| 35 | - $previous->getMessage() |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - parent::__construct($message, $code, $previous); |
|
| 39 | - } |
|
| 19 | + /** |
|
| 20 | + * DuplicateCollectionIdentifierException constructor. |
|
| 21 | + * |
|
| 22 | + * @param Exception $previous |
|
| 23 | + * @param string $message |
|
| 24 | + * @param int $code |
|
| 25 | + */ |
|
| 26 | + public function __construct(Exception $previous, $message = '', $code = 0) |
|
| 27 | + { |
|
| 28 | + if (empty($message)) { |
|
| 29 | + $message = sprintf( |
|
| 30 | + __( |
|
| 31 | + 'The following error occurred during the creation and/or loading of this collection: %1$s %2$s', |
|
| 32 | + 'event_espresso' |
|
| 33 | + ), |
|
| 34 | + '<br />', |
|
| 35 | + $previous->getMessage() |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + parent::__construct($message, $code, $previous); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -16,25 +16,25 @@ |
||
| 16 | 16 | class CollectionDetailsException extends RuntimeException |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * DuplicateCollectionIdentifierException constructor. |
|
| 21 | - * |
|
| 22 | - * @param Exception $previous |
|
| 23 | - * @param string $message |
|
| 24 | - * @param int $code |
|
| 25 | - */ |
|
| 26 | - public function __construct(Exception $previous, $message = '', $code = 0) |
|
| 27 | - { |
|
| 28 | - if (empty($message)) { |
|
| 29 | - $message = sprintf( |
|
| 30 | - __( |
|
| 31 | - 'The following error occurred during the collection details generation: %1$s %2$s', |
|
| 32 | - 'event_espresso' |
|
| 33 | - ), |
|
| 34 | - '<br />', |
|
| 35 | - $previous->getMessage() |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - parent::__construct($message, $code, $previous); |
|
| 39 | - } |
|
| 19 | + /** |
|
| 20 | + * DuplicateCollectionIdentifierException constructor. |
|
| 21 | + * |
|
| 22 | + * @param Exception $previous |
|
| 23 | + * @param string $message |
|
| 24 | + * @param int $code |
|
| 25 | + */ |
|
| 26 | + public function __construct(Exception $previous, $message = '', $code = 0) |
|
| 27 | + { |
|
| 28 | + if (empty($message)) { |
|
| 29 | + $message = sprintf( |
|
| 30 | + __( |
|
| 31 | + 'The following error occurred during the collection details generation: %1$s %2$s', |
|
| 32 | + 'event_espresso' |
|
| 33 | + ), |
|
| 34 | + '<br />', |
|
| 35 | + $previous->getMessage() |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + parent::__construct($message, $code, $previous); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -20,216 +20,216 @@ |
||
| 20 | 20 | abstract class Block implements BlockInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * BlockAssetManager that this editor block uses for asset registration |
|
| 25 | - * |
|
| 26 | - * @var BlockAssetManagerInterface $block_asset_manager |
|
| 27 | - */ |
|
| 28 | - protected $block_asset_manager; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array $attributes |
|
| 32 | - */ |
|
| 33 | - private $attributes; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * If set to true, then the block will render its content client side |
|
| 37 | - * If false, then the block will render its content server side using the renderBlock() method |
|
| 38 | - * |
|
| 39 | - * @var bool $dynamic |
|
| 40 | - */ |
|
| 41 | - private $dynamic = false; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var string $block_type |
|
| 45 | - */ |
|
| 46 | - private $block_type; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var array $supported_routes |
|
| 50 | - */ |
|
| 51 | - private $supported_routes; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var WP_Block_Type $wp_block_type |
|
| 55 | - */ |
|
| 56 | - private $wp_block_type; |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * BlockLoader constructor. |
|
| 61 | - * |
|
| 62 | - * @param BlockAssetManagerInterface $block_asset_manager |
|
| 63 | - */ |
|
| 64 | - public function __construct(BlockAssetManagerInterface $block_asset_manager) |
|
| 65 | - { |
|
| 66 | - $this->block_asset_manager = $block_asset_manager; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function blockType() |
|
| 74 | - { |
|
| 75 | - return $this->block_type; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function namespacedBlockType() |
|
| 83 | - { |
|
| 84 | - return self::NAME_SPACE . '/' . $this->block_type; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param string $block_type |
|
| 90 | - */ |
|
| 91 | - protected function setBlockType($block_type) |
|
| 92 | - { |
|
| 93 | - $this->block_type = $block_type; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * BlockAssetManager that this editor block uses for asset registration |
|
| 99 | - * |
|
| 100 | - * @return BlockAssetManagerInterface |
|
| 101 | - */ |
|
| 102 | - public function assetManager() |
|
| 103 | - { |
|
| 104 | - return $this->block_asset_manager; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param WP_Block_Type $wp_block_type |
|
| 110 | - */ |
|
| 111 | - protected function setWpBlockType($wp_block_type) |
|
| 112 | - { |
|
| 113 | - $this->wp_block_type = $wp_block_type; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * returns an array of fully qualified class names |
|
| 118 | - * for RouteMatchSpecificationInterface objects |
|
| 119 | - * that specify routes that the block should be loaded for. |
|
| 120 | - * |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - public function supportedRoutes() |
|
| 124 | - { |
|
| 125 | - return $this->supported_routes; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param array $supported_routes |
|
| 131 | - */ |
|
| 132 | - protected function setSupportedRoutes(array $supported_routes) |
|
| 133 | - { |
|
| 134 | - $this->supported_routes = $supported_routes; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return array |
|
| 140 | - */ |
|
| 141 | - public function attributes() |
|
| 142 | - { |
|
| 143 | - return $this->attributes; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param array $attributes |
|
| 149 | - */ |
|
| 150 | - public function setAttributes(array $attributes) |
|
| 151 | - { |
|
| 152 | - $this->attributes = $attributes; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @return bool |
|
| 158 | - */ |
|
| 159 | - public function isDynamic() |
|
| 160 | - { |
|
| 161 | - return $this->dynamic; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param bool $dynamic |
|
| 167 | - */ |
|
| 168 | - public function setDynamic($dynamic = true) |
|
| 169 | - { |
|
| 170 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Registers the Editor Block with WP core; |
|
| 176 | - * Returns the registered block type on success, or false on failure. |
|
| 177 | - * |
|
| 178 | - * @return WP_Block_Type|false |
|
| 179 | - */ |
|
| 180 | - public function registerBlock() |
|
| 181 | - { |
|
| 182 | - $args = array( |
|
| 183 | - 'attributes' => $this->attributes(), |
|
| 184 | - 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
| 185 | - 'editor_style' => $this->block_asset_manager->getEditorStyleHandle(), |
|
| 186 | - 'script' => $this->block_asset_manager->getScriptHandle(), |
|
| 187 | - 'style' => $this->block_asset_manager->getStyleHandle(), |
|
| 188 | - ); |
|
| 189 | - if ($this->isDynamic()) { |
|
| 190 | - $args['render_callback'] = array($this, 'renderBlock'); |
|
| 191 | - } |
|
| 192 | - $wp_block_type = register_block_type( |
|
| 193 | - new WP_Block_Type( |
|
| 194 | - $this->namespacedBlockType(), |
|
| 195 | - $args |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - $this->setWpBlockType($wp_block_type); |
|
| 199 | - return $wp_block_type; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
| 205 | - */ |
|
| 206 | - public function unRegisterBlock() |
|
| 207 | - { |
|
| 208 | - return unregister_block_type($this->namespacedBlockType()); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @return array |
|
| 215 | - */ |
|
| 216 | - public function getEditorContainer() |
|
| 217 | - { |
|
| 218 | - return array( |
|
| 219 | - $this->namespacedBlockType(), |
|
| 220 | - array(), |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * returns the rendered HTML for the block |
|
| 227 | - * |
|
| 228 | - * @param array $attributes |
|
| 229 | - * @return string |
|
| 230 | - */ |
|
| 231 | - public function renderBlock(array $attributes = array()) |
|
| 232 | - { |
|
| 233 | - return ''; |
|
| 234 | - } |
|
| 23 | + /** |
|
| 24 | + * BlockAssetManager that this editor block uses for asset registration |
|
| 25 | + * |
|
| 26 | + * @var BlockAssetManagerInterface $block_asset_manager |
|
| 27 | + */ |
|
| 28 | + protected $block_asset_manager; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array $attributes |
|
| 32 | + */ |
|
| 33 | + private $attributes; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * If set to true, then the block will render its content client side |
|
| 37 | + * If false, then the block will render its content server side using the renderBlock() method |
|
| 38 | + * |
|
| 39 | + * @var bool $dynamic |
|
| 40 | + */ |
|
| 41 | + private $dynamic = false; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var string $block_type |
|
| 45 | + */ |
|
| 46 | + private $block_type; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var array $supported_routes |
|
| 50 | + */ |
|
| 51 | + private $supported_routes; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var WP_Block_Type $wp_block_type |
|
| 55 | + */ |
|
| 56 | + private $wp_block_type; |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * BlockLoader constructor. |
|
| 61 | + * |
|
| 62 | + * @param BlockAssetManagerInterface $block_asset_manager |
|
| 63 | + */ |
|
| 64 | + public function __construct(BlockAssetManagerInterface $block_asset_manager) |
|
| 65 | + { |
|
| 66 | + $this->block_asset_manager = $block_asset_manager; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function blockType() |
|
| 74 | + { |
|
| 75 | + return $this->block_type; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function namespacedBlockType() |
|
| 83 | + { |
|
| 84 | + return self::NAME_SPACE . '/' . $this->block_type; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param string $block_type |
|
| 90 | + */ |
|
| 91 | + protected function setBlockType($block_type) |
|
| 92 | + { |
|
| 93 | + $this->block_type = $block_type; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * BlockAssetManager that this editor block uses for asset registration |
|
| 99 | + * |
|
| 100 | + * @return BlockAssetManagerInterface |
|
| 101 | + */ |
|
| 102 | + public function assetManager() |
|
| 103 | + { |
|
| 104 | + return $this->block_asset_manager; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param WP_Block_Type $wp_block_type |
|
| 110 | + */ |
|
| 111 | + protected function setWpBlockType($wp_block_type) |
|
| 112 | + { |
|
| 113 | + $this->wp_block_type = $wp_block_type; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * returns an array of fully qualified class names |
|
| 118 | + * for RouteMatchSpecificationInterface objects |
|
| 119 | + * that specify routes that the block should be loaded for. |
|
| 120 | + * |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + public function supportedRoutes() |
|
| 124 | + { |
|
| 125 | + return $this->supported_routes; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param array $supported_routes |
|
| 131 | + */ |
|
| 132 | + protected function setSupportedRoutes(array $supported_routes) |
|
| 133 | + { |
|
| 134 | + $this->supported_routes = $supported_routes; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return array |
|
| 140 | + */ |
|
| 141 | + public function attributes() |
|
| 142 | + { |
|
| 143 | + return $this->attributes; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param array $attributes |
|
| 149 | + */ |
|
| 150 | + public function setAttributes(array $attributes) |
|
| 151 | + { |
|
| 152 | + $this->attributes = $attributes; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @return bool |
|
| 158 | + */ |
|
| 159 | + public function isDynamic() |
|
| 160 | + { |
|
| 161 | + return $this->dynamic; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param bool $dynamic |
|
| 167 | + */ |
|
| 168 | + public function setDynamic($dynamic = true) |
|
| 169 | + { |
|
| 170 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Registers the Editor Block with WP core; |
|
| 176 | + * Returns the registered block type on success, or false on failure. |
|
| 177 | + * |
|
| 178 | + * @return WP_Block_Type|false |
|
| 179 | + */ |
|
| 180 | + public function registerBlock() |
|
| 181 | + { |
|
| 182 | + $args = array( |
|
| 183 | + 'attributes' => $this->attributes(), |
|
| 184 | + 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
| 185 | + 'editor_style' => $this->block_asset_manager->getEditorStyleHandle(), |
|
| 186 | + 'script' => $this->block_asset_manager->getScriptHandle(), |
|
| 187 | + 'style' => $this->block_asset_manager->getStyleHandle(), |
|
| 188 | + ); |
|
| 189 | + if ($this->isDynamic()) { |
|
| 190 | + $args['render_callback'] = array($this, 'renderBlock'); |
|
| 191 | + } |
|
| 192 | + $wp_block_type = register_block_type( |
|
| 193 | + new WP_Block_Type( |
|
| 194 | + $this->namespacedBlockType(), |
|
| 195 | + $args |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + $this->setWpBlockType($wp_block_type); |
|
| 199 | + return $wp_block_type; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
| 205 | + */ |
|
| 206 | + public function unRegisterBlock() |
|
| 207 | + { |
|
| 208 | + return unregister_block_type($this->namespacedBlockType()); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @return array |
|
| 215 | + */ |
|
| 216 | + public function getEditorContainer() |
|
| 217 | + { |
|
| 218 | + return array( |
|
| 219 | + $this->namespacedBlockType(), |
|
| 220 | + array(), |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * returns the rendered HTML for the block |
|
| 227 | + * |
|
| 228 | + * @param array $attributes |
|
| 229 | + * @return string |
|
| 230 | + */ |
|
| 231 | + public function renderBlock(array $attributes = array()) |
|
| 232 | + { |
|
| 233 | + return ''; |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -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 | } |
@@ -23,20 +23,20 @@ |
||
| 23 | 23 | class RouteMatchSpecificationDependencyResolver extends DependencyResolver |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Used to configure and/or setup any aliases or recursions required by the DependencyResolver |
|
| 28 | - * |
|
| 29 | - * @since $VID:$ |
|
| 30 | - * @throws InvalidAliasException |
|
| 31 | - */ |
|
| 32 | - public function initialize() |
|
| 33 | - { |
|
| 34 | - $this->addAlias( |
|
| 35 | - new ClassAlias( |
|
| 36 | - 'EventEspresso\core\services\request\RequestInterface', |
|
| 37 | - 'EventEspresso\core\services\request\Request' |
|
| 38 | - ) |
|
| 39 | - ); |
|
| 40 | - $this->addRecursion('EventEspresso\core\domain\entities\route_match\specifications'); |
|
| 41 | - } |
|
| 26 | + /** |
|
| 27 | + * Used to configure and/or setup any aliases or recursions required by the DependencyResolver |
|
| 28 | + * |
|
| 29 | + * @since $VID:$ |
|
| 30 | + * @throws InvalidAliasException |
|
| 31 | + */ |
|
| 32 | + public function initialize() |
|
| 33 | + { |
|
| 34 | + $this->addAlias( |
|
| 35 | + new ClassAlias( |
|
| 36 | + 'EventEspresso\core\services\request\RequestInterface', |
|
| 37 | + 'EventEspresso\core\services\request\Request' |
|
| 38 | + ) |
|
| 39 | + ); |
|
| 40 | + $this->addRecursion('EventEspresso\core\domain\entities\route_match\specifications'); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -24,46 +24,46 @@ |
||
| 24 | 24 | class RouteMatchSpecificationFactory extends FactoryWithDependencyResolver |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * RouteMatchSpecificationFactory constructor |
|
| 29 | - * |
|
| 30 | - * @param RouteMatchSpecificationDependencyResolver $dependency_resolver |
|
| 31 | - * @param LoaderInterface $loader |
|
| 32 | - */ |
|
| 33 | - public function __construct(RouteMatchSpecificationDependencyResolver $dependency_resolver, LoaderInterface $loader) |
|
| 34 | - { |
|
| 35 | - parent::__construct($dependency_resolver, $loader); |
|
| 36 | - } |
|
| 27 | + /** |
|
| 28 | + * RouteMatchSpecificationFactory constructor |
|
| 29 | + * |
|
| 30 | + * @param RouteMatchSpecificationDependencyResolver $dependency_resolver |
|
| 31 | + * @param LoaderInterface $loader |
|
| 32 | + */ |
|
| 33 | + public function __construct(RouteMatchSpecificationDependencyResolver $dependency_resolver, LoaderInterface $loader) |
|
| 34 | + { |
|
| 35 | + parent::__construct($dependency_resolver, $loader); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param $fqcn |
|
| 40 | - * @return RouteMatchSpecification |
|
| 41 | - * @throws InvalidDataTypeException |
|
| 42 | - * @throws ReflectionException |
|
| 43 | - * @since $VID:$ |
|
| 44 | - */ |
|
| 45 | - public function createNewRouteMatchSpecification($fqcn) |
|
| 46 | - { |
|
| 47 | - $this->dependencyResolver()->resolveDependenciesForClass($fqcn); |
|
| 48 | - return $this->loader()->getShared($fqcn); |
|
| 49 | - } |
|
| 38 | + /** |
|
| 39 | + * @param $fqcn |
|
| 40 | + * @return RouteMatchSpecification |
|
| 41 | + * @throws InvalidDataTypeException |
|
| 42 | + * @throws ReflectionException |
|
| 43 | + * @since $VID:$ |
|
| 44 | + */ |
|
| 45 | + public function createNewRouteMatchSpecification($fqcn) |
|
| 46 | + { |
|
| 47 | + $this->dependencyResolver()->resolveDependenciesForClass($fqcn); |
|
| 48 | + return $this->loader()->getShared($fqcn); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param $fqcn |
|
| 54 | - * @return RouteMatchSpecification |
|
| 55 | - * @throws InvalidArgumentException |
|
| 56 | - * @throws InvalidDataTypeException |
|
| 57 | - * @throws InvalidInterfaceException |
|
| 58 | - * @throws ReflectionException |
|
| 59 | - * @since $VID:$ |
|
| 60 | - */ |
|
| 61 | - public static function create($fqcn) |
|
| 62 | - { |
|
| 63 | - /** @var RouteMatchSpecificationFactory $specification_factory */ |
|
| 64 | - $specification_factory = LoaderFactory::getLoader()->getShared( |
|
| 65 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' |
|
| 66 | - ); |
|
| 67 | - return $specification_factory->createNewRouteMatchSpecification($fqcn); |
|
| 68 | - } |
|
| 52 | + /** |
|
| 53 | + * @param $fqcn |
|
| 54 | + * @return RouteMatchSpecification |
|
| 55 | + * @throws InvalidArgumentException |
|
| 56 | + * @throws InvalidDataTypeException |
|
| 57 | + * @throws InvalidInterfaceException |
|
| 58 | + * @throws ReflectionException |
|
| 59 | + * @since $VID:$ |
|
| 60 | + */ |
|
| 61 | + public static function create($fqcn) |
|
| 62 | + { |
|
| 63 | + /** @var RouteMatchSpecificationFactory $specification_factory */ |
|
| 64 | + $specification_factory = LoaderFactory::getLoader()->getShared( |
|
| 65 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' |
|
| 66 | + ); |
|
| 67 | + return $specification_factory->createNewRouteMatchSpecification($fqcn); |
|
| 68 | + } |
|
| 69 | 69 | } |