| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Integrations collection | |
| 3 | + * Integrations: Integrations collection class | |
| 4 | 4 | * |
| 5 | - * @package Parsely\Integrations | |
| 5 | + * @package Parsely | |
| 6 | 6 | * @since 2.6.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | declare(strict_types=1); |
| @@ -9,47 +9,69 @@ | ||
| 9 | 9 | declare(strict_types=1); |
| 10 | 10 | |
| 11 | 11 | namespace Parsely\Integrations; |
| 12 | 12 | |
| 13 | +use Parsely\Parsely; | |
| 14 | + | |
| 13 | 15 | /** |
| 14 | 16 | * Integrations are registered to this collection. |
| 15 | 17 | * |
| 16 | - * The `integrate()` method is called on each registered integration, on the init hook. | |
| 18 | + * The `integrate()` method is called on each registered integration, on the | |
| 19 | + * init hook. | |
| 17 | 20 | * |
| 18 | 21 | * @since 2.6.0 |
| 19 | 22 | */ |
| 20 | 23 | class Integrations { |
| 21 | 24 | /** |
| 25 | + * Instance of Parsely class. | |
| 26 | + * | |
| 27 | + * @var Parsely | |
| 28 | + */ | |
| 29 | + private $parsely; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Constructor. | |
| 33 | + * | |
| 34 | + * @param Parsely $parsely Instance of Parsely class. | |
| 35 | + */ | |
| 36 | + public function __construct( Parsely $parsely ) { | |
| 37 | + $this->parsely = $parsely; | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 22 | 41 | * Collection of registered integrations. |
| 23 | 42 | * |
| 24 | - * @var array | |
| 43 | + * @var array<Integrations> | |
| 25 | 44 | */ |
| 26 | 45 | private $integrations = array(); |
| 27 | 46 | |
| 28 | 47 | /** |
| 29 | - * Register an integration. | |
| 48 | + * Registers an integration. | |
| 30 | 49 | * |
| 31 | 50 | * @since 2.6.0 |
| 32 | 51 | * |
| 33 | - * @param string $key A unique identifier for the integration. | |
| 34 | - * @param string|object $class_or_object Fully-qualified class name, or an instantiated object. | |
| 35 | - * If a class name is passed, it will be instantiated. | |
| 36 | - * @return void | |
| 52 | + * @param string $key A unique identifier for the integration. | |
| 53 | + * @param class-string|Integrations $class_or_object Fully-qualified class name, or an instantiated object. | |
| 54 | + * If a class name is passed, it will be instantiated. | |
| 37 | 55 | */ |
| 38 | 56 | public function register( string $key, $class_or_object ): void { |
| 39 | 57 | // If a Foo::class or other fully qualified class name is passed, instantiate it. |
| 40 | 58 | if ( ! is_object( $class_or_object ) ) { |
| 41 | - $class_or_object = new $class_or_object(); | |
| 59 | + /** | |
| 60 | + * Variable. | |
| 61 | + * | |
| 62 | + * @var Integrations | |
| 63 | + */ | |
| 64 | + $class_or_object = new $class_or_object( $this->parsely ); | |
| 42 | 65 | } |
| 43 | 66 | $this->integrations[ $key ] = $class_or_object; |
| 44 | 67 | } |
| 45 | 68 | |
| 46 | 69 | /** |
| 47 | - * Integrate each integration by calling the method that does the add_action() and add_filter() calls. | |
| 70 | + * Integrates each integration by calling the method that does the | |
| 71 | + * add_action() and add_filter() calls. | |
| 48 | 72 | * |
| 49 | 73 | * @since 2.6.0 |
| 50 | - * | |
| 51 | - * @return void | |
| 52 | 74 | */ |
| 53 | 75 | public function integrate(): void { |
| 54 | 76 | foreach ( $this->integrations as $integration ) { |
| 55 | 77 | $integration->integrate(); |