PluginProbe
Parse.ly / 3.20.3
Parse.ly v3.20.3
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / Integrations / class-integrations.php

class-integrations.php in Parse.ly 3.20.3, at src/Integrations/class-integrations.php

81 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Integrations: Integrations collection class
4 *
5 * @package Parsely
6 * @since 2.6.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\Integrations;
12
13 use Parsely\Parsely;
14
15 /**
16 * Integrations are registered to this collection.
17 *
18 * The `integrate()` method is called on each registered integration, on the
19 * init hook.
20 *
21 * @since 2.6.0
22 */
23 class Integrations {
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 /**
41 * Collection of registered integrations.
42 *
43 * @var array<Integrations>
44 */
45 private $integrations = array();
46
47 /**
48 * Registers an integration.
49 *
50 * @since 2.6.0
51 *
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.
55 */
56 public function register( string $key, $class_or_object ): void {
57 // If a Foo::class or other fully qualified class name is passed, instantiate it.
58 if ( ! is_object( $class_or_object ) ) {
59 /**
60 * Variable.
61 *
62 * @var Integrations
63 */
64 $class_or_object = new $class_or_object( $this->parsely );
65 }
66 $this->integrations[ $key ] = $class_or_object;
67 }
68
69 /**
70 * Integrates each integration by calling the method that does the
71 * add_action() and add_filter() calls.
72 *
73 * @since 2.6.0
74 */
75 public function integrate(): void {
76 foreach ( $this->integrations as $integration ) {
77 $integration->integrate();
78 }
79 }
80 }
81