Completed
Branch Gutenberg/route-specific-block... (601490)
by
unknown
112:41 queued 99:18
created
core/services/loaders/ClassInterfaceCache.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
     {
52 52
         $fqn = $this->getFqn($fqn);
53 53
         // have we already seen this FQCN ?
54
-        if (! array_key_exists($fqn, $this->interfaces)) {
55
-            $this->interfaces[ $fqn ] = array();
54
+        if ( ! array_key_exists($fqn, $this->interfaces)) {
55
+            $this->interfaces[$fqn] = array();
56 56
             if (class_exists($fqn)) {
57
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
58
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
59
-                    ? $this->interfaces[ $fqn ]
57
+                $this->interfaces[$fqn] = class_implements($fqn, false);
58
+                $this->interfaces[$fqn] = $this->interfaces[$fqn] !== false
59
+                    ? $this->interfaces[$fqn]
60 60
                     : array();
61 61
             }
62 62
         }
63
-        return $this->interfaces[ $fqn ];
63
+        return $this->interfaces[$fqn];
64 64
     }
65 65
 
66 66
 
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
         // are we adding an alias for a specific class?
92 92
         if ($for_class !== '') {
93 93
             // make sure it's set up as an array
94
-            if (! isset($this->aliases[ $for_class ])) {
95
-                $this->aliases[ $for_class ] = array();
94
+            if ( ! isset($this->aliases[$for_class])) {
95
+                $this->aliases[$for_class] = array();
96 96
             }
97
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
97
+            $this->aliases[$for_class][$alias] = $fqn;
98 98
             return;
99 99
         }
100
-        $this->aliases[ $alias ] = $fqn;
100
+        $this->aliases[$alias] = $fqn;
101 101
     }
102 102
 
103 103
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     protected function isDirectAlias($fqn = '')
131 131
     {
132
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
132
+        return isset($this->aliases[(string) $fqn]) && ! is_array($this->aliases[(string) $fqn]);
133 133
     }
134 134
 
135 135
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
     {
145 145
         return (
146 146
             $for_class !== ''
147
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
147
+            && isset($this->aliases[(string) $for_class][(string) $fqn])
148 148
         );
149 149
     }
150 150
 
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
     {
170 170
         $alias = $this->getFqn($alias);
171 171
         if ($this->isAliasForClass($alias, $for_class)) {
172
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
172
+            return $this->getFqnForAlias($this->aliases[(string) $for_class][(string) $alias], $for_class);
173 173
         }
174 174
         if ($this->isDirectAlias($alias)) {
175
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
175
+            return $this->getFqnForAlias($this->aliases[(string) $alias], '');
176 176
         }
177 177
         return $alias;
178 178
     }
Please login to merge, or discard this patch.
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -17,165 +17,165 @@
 block discarded – undo
17 17
 class ClassInterfaceCache
18 18
 {
19 19
 
20
-    /**
21
-     * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
22
-     *
23
-     * @var string[][] $interfaces
24
-     */
25
-    private $interfaces = array();
26
-
27
-    /**
28
-     * @type string[][] $aliases
29
-     */
30
-    protected $aliases = array();
31
-
32
-
33
-    /**
34
-     * @param string $fqn
35
-     * @return string
36
-     */
37
-    public function getFqn($fqn)
38
-    {
39
-        $fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
40
-        return ltrim($fqn, '\\');
41
-    }
42
-
43
-
44
-    /**
45
-     * @param string $fqn
46
-     * @return array
47
-     */
48
-    public function getInterfaces($fqn)
49
-    {
50
-        $fqn = $this->getFqn($fqn);
51
-        // have we already seen this FQCN ?
52
-        if (! array_key_exists($fqn, $this->interfaces)) {
53
-            $this->interfaces[ $fqn ] = array();
54
-            if (class_exists($fqn)) {
55
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
56
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
57
-                    ? $this->interfaces[ $fqn ]
58
-                    : array();
59
-            }
60
-        }
61
-        return $this->interfaces[ $fqn ];
62
-    }
63
-
64
-
65
-    /**
66
-     * @param string $fqn
67
-     * @param string $interface
68
-     * @return bool
69
-     */
70
-    public function hasInterface($fqn, $interface)
71
-    {
72
-        $fqn        = $this->getFqn($fqn);
73
-        $interfaces = $this->getInterfaces($fqn);
74
-        return in_array($interface, $interfaces, true);
75
-    }
76
-
77
-
78
-    /**
79
-     * adds an alias for a classname
80
-     *
81
-     * @param string $fqn       the class name that should be used (concrete class to replace interface)
82
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
83
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
84
-     * @throws InvalidAliasException
85
-     */
86
-    public function addAlias($fqn, $alias, $for_class = '')
87
-    {
88
-        $fqn   = $this->getFqn($fqn);
89
-        $alias = $this->getFqn($alias);
90
-        if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) {
91
-            throw new InvalidAliasException($fqn, $alias);
92
-        }
93
-        // are we adding an alias for a specific class?
94
-        if ($for_class !== '') {
95
-            // make sure it's set up as an array
96
-            if (! isset($this->aliases[ $for_class ])) {
97
-                $this->aliases[ $for_class ] = array();
98
-            }
99
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
100
-            return;
101
-        }
102
-        $this->aliases[ $alias ] = $fqn;
103
-    }
104
-
105
-
106
-    /**
107
-     * returns TRUE if the provided FQN is an alias
108
-     *
109
-     * @param string $fqn
110
-     * @param string $for_class
111
-     * @return bool
112
-     */
113
-    public function isAlias($fqn = '', $for_class = '')
114
-    {
115
-        $fqn = $this->getFqn($fqn);
116
-        if ($this->isAliasForClass($fqn, $for_class)) {
117
-            return true;
118
-        }
119
-        if ($for_class === '' && $this->isDirectAlias($fqn)) {
120
-            return true;
121
-        }
122
-        return false;
123
-    }
124
-
125
-
126
-    /**
127
-     * returns TRUE if the provided FQN is an alias
128
-     *
129
-     * @param string $fqn
130
-     * @return bool
131
-     */
132
-    protected function isDirectAlias($fqn = '')
133
-    {
134
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
135
-    }
136
-
137
-
138
-    /**
139
-     * returns TRUE if the provided FQN is an alias for the specified class
140
-     *
141
-     * @param string $fqn
142
-     * @param string $for_class
143
-     * @return bool
144
-     */
145
-    protected function isAliasForClass($fqn = '', $for_class = '')
146
-    {
147
-        return (
148
-            $for_class !== ''
149
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     * returns FQN for provided alias if one exists, otherwise returns the original FQN
156
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
157
-     *  for example:
158
-     *      if the following two entries were added to the aliases array:
159
-     *          array(
160
-     *              'interface_alias'           => 'some\namespace\interface'
161
-     *              'some\namespace\interface'  => 'some\namespace\classname'
162
-     *          )
163
-     *      then one could use Loader::getNew( 'interface_alias' )
164
-     *      to load an instance of 'some\namespace\classname'
165
-     *
166
-     * @param string $alias
167
-     * @param string $for_class
168
-     * @return string
169
-     */
170
-    public function getFqnForAlias($alias = '', $for_class = '')
171
-    {
172
-        $alias = $this->getFqn($alias);
173
-        if ($this->isAliasForClass($alias, $for_class)) {
174
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
175
-        }
176
-        if ($this->isDirectAlias($alias)) {
177
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
178
-        }
179
-        return $alias;
180
-    }
20
+	/**
21
+	 * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
22
+	 *
23
+	 * @var string[][] $interfaces
24
+	 */
25
+	private $interfaces = array();
26
+
27
+	/**
28
+	 * @type string[][] $aliases
29
+	 */
30
+	protected $aliases = array();
31
+
32
+
33
+	/**
34
+	 * @param string $fqn
35
+	 * @return string
36
+	 */
37
+	public function getFqn($fqn)
38
+	{
39
+		$fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
40
+		return ltrim($fqn, '\\');
41
+	}
42
+
43
+
44
+	/**
45
+	 * @param string $fqn
46
+	 * @return array
47
+	 */
48
+	public function getInterfaces($fqn)
49
+	{
50
+		$fqn = $this->getFqn($fqn);
51
+		// have we already seen this FQCN ?
52
+		if (! array_key_exists($fqn, $this->interfaces)) {
53
+			$this->interfaces[ $fqn ] = array();
54
+			if (class_exists($fqn)) {
55
+				$this->interfaces[ $fqn ] = class_implements($fqn, false);
56
+				$this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
57
+					? $this->interfaces[ $fqn ]
58
+					: array();
59
+			}
60
+		}
61
+		return $this->interfaces[ $fqn ];
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param string $fqn
67
+	 * @param string $interface
68
+	 * @return bool
69
+	 */
70
+	public function hasInterface($fqn, $interface)
71
+	{
72
+		$fqn        = $this->getFqn($fqn);
73
+		$interfaces = $this->getInterfaces($fqn);
74
+		return in_array($interface, $interfaces, true);
75
+	}
76
+
77
+
78
+	/**
79
+	 * adds an alias for a classname
80
+	 *
81
+	 * @param string $fqn       the class name that should be used (concrete class to replace interface)
82
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
83
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
84
+	 * @throws InvalidAliasException
85
+	 */
86
+	public function addAlias($fqn, $alias, $for_class = '')
87
+	{
88
+		$fqn   = $this->getFqn($fqn);
89
+		$alias = $this->getFqn($alias);
90
+		if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) {
91
+			throw new InvalidAliasException($fqn, $alias);
92
+		}
93
+		// are we adding an alias for a specific class?
94
+		if ($for_class !== '') {
95
+			// make sure it's set up as an array
96
+			if (! isset($this->aliases[ $for_class ])) {
97
+				$this->aliases[ $for_class ] = array();
98
+			}
99
+			$this->aliases[ $for_class ][ $alias ] = $fqn;
100
+			return;
101
+		}
102
+		$this->aliases[ $alias ] = $fqn;
103
+	}
104
+
105
+
106
+	/**
107
+	 * returns TRUE if the provided FQN is an alias
108
+	 *
109
+	 * @param string $fqn
110
+	 * @param string $for_class
111
+	 * @return bool
112
+	 */
113
+	public function isAlias($fqn = '', $for_class = '')
114
+	{
115
+		$fqn = $this->getFqn($fqn);
116
+		if ($this->isAliasForClass($fqn, $for_class)) {
117
+			return true;
118
+		}
119
+		if ($for_class === '' && $this->isDirectAlias($fqn)) {
120
+			return true;
121
+		}
122
+		return false;
123
+	}
124
+
125
+
126
+	/**
127
+	 * returns TRUE if the provided FQN is an alias
128
+	 *
129
+	 * @param string $fqn
130
+	 * @return bool
131
+	 */
132
+	protected function isDirectAlias($fqn = '')
133
+	{
134
+		return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
135
+	}
136
+
137
+
138
+	/**
139
+	 * returns TRUE if the provided FQN is an alias for the specified class
140
+	 *
141
+	 * @param string $fqn
142
+	 * @param string $for_class
143
+	 * @return bool
144
+	 */
145
+	protected function isAliasForClass($fqn = '', $for_class = '')
146
+	{
147
+		return (
148
+			$for_class !== ''
149
+			&& isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 * returns FQN for provided alias if one exists, otherwise returns the original FQN
156
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
157
+	 *  for example:
158
+	 *      if the following two entries were added to the aliases array:
159
+	 *          array(
160
+	 *              'interface_alias'           => 'some\namespace\interface'
161
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
162
+	 *          )
163
+	 *      then one could use Loader::getNew( 'interface_alias' )
164
+	 *      to load an instance of 'some\namespace\classname'
165
+	 *
166
+	 * @param string $alias
167
+	 * @param string $for_class
168
+	 * @return string
169
+	 */
170
+	public function getFqnForAlias($alias = '', $for_class = '')
171
+	{
172
+		$alias = $this->getFqn($alias);
173
+		if ($this->isAliasForClass($alias, $for_class)) {
174
+			return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
175
+		}
176
+		if ($this->isDirectAlias($alias)) {
177
+			return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
178
+		}
179
+		return $alias;
180
+	}
181 181
 }
Please login to merge, or discard this patch.
core/services/route_match/RouteMatchSpecificationManager.php 2 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -25,122 +25,122 @@
 block discarded – undo
25 25
  */
26 26
 class RouteMatchSpecificationManager
27 27
 {
28
-    /**
29
-     * @var CollectionInterface[]|RouteMatchSpecificationInterface[] $specifications
30
-     */
31
-    private $specifications;
28
+	/**
29
+	 * @var CollectionInterface[]|RouteMatchSpecificationInterface[] $specifications
30
+	 */
31
+	private $specifications;
32 32
 
33
-    /**
34
-     * @var RouteMatchSpecificationFactory $specifications_factory
35
-     */
36
-    private $specifications_factory;
33
+	/**
34
+	 * @var RouteMatchSpecificationFactory $specifications_factory
35
+	 */
36
+	private $specifications_factory;
37 37
 
38 38
 
39
-    /**
40
-     * RouteMatchSpecificationManager constructor.
41
-     *
42
-     * @param RouteMatchSpecificationCollection $specifications
43
-     * @param RouteMatchSpecificationFactory    $specifications_factory
44
-     */
45
-    public function __construct(
46
-        RouteMatchSpecificationCollection $specifications,
47
-        RouteMatchSpecificationFactory $specifications_factory
48
-    ) {
49
-        $this->specifications = $specifications;
50
-        $this->specifications_factory = $specifications_factory;
51
-        add_action('AHEE__EE_System__loadRouteMatchSpecifications', array($this, 'initialize'));
52
-    }
39
+	/**
40
+	 * RouteMatchSpecificationManager constructor.
41
+	 *
42
+	 * @param RouteMatchSpecificationCollection $specifications
43
+	 * @param RouteMatchSpecificationFactory    $specifications_factory
44
+	 */
45
+	public function __construct(
46
+		RouteMatchSpecificationCollection $specifications,
47
+		RouteMatchSpecificationFactory $specifications_factory
48
+	) {
49
+		$this->specifications = $specifications;
50
+		$this->specifications_factory = $specifications_factory;
51
+		add_action('AHEE__EE_System__loadRouteMatchSpecifications', array($this, 'initialize'));
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Perform any early setup required for block editors to functions
57
-     *
58
-     * @return void
59
-     * @throws CollectionLoaderException
60
-     * @throws CollectionDetailsException
61
-     */
62
-    public function initialize()
63
-    {
64
-        $this->populateSpecificationCollection();
65
-    }
55
+	/**
56
+	 * Perform any early setup required for block editors to functions
57
+	 *
58
+	 * @return void
59
+	 * @throws CollectionLoaderException
60
+	 * @throws CollectionDetailsException
61
+	 */
62
+	public function initialize()
63
+	{
64
+		$this->populateSpecificationCollection();
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     * @return CollectionInterface|RouteMatchSpecificationInterface[]
70
-     * @throws CollectionLoaderException
71
-     * @throws CollectionDetailsException
72
-     * @since $VID:$
73
-     */
74
-    private function populateSpecificationCollection()
75
-    {
76
-        $loader = new CollectionLoader(
77
-            new CollectionDetails(
78
-                // collection name
79
-                RouteMatchSpecificationCollection::COLLECTION_NAME,
80
-                // collection interface
81
-                'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface',
82
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
83
-                apply_filters(
84
-                    'FHEE__EventEspresso_core_services_route_match_RouteMatchSpecificationManager__populateSpecificationCollection__collection_FQCNs',
85
-                    array(
86
-                        'EventEspresso\core\domain\entities\route_match\specifications\admin',
87
-                        // 'EventEspresso\core\domain\entities\route_match\specifications\public',
88
-                    )
89
-                ),
90
-                // filepaths to classes to add
91
-                array(),
92
-                // file mask to use if parsing folder for files to add
93
-                '',
94
-                // what to use as identifier for collection entities
95
-                // using CLASS NAME prevents duplicates (works like a singleton)
96
-                CollectionDetails::ID_CLASS_NAME
97
-            ),
98
-            $this->specifications,
99
-            null,
100
-            $this->specifications_factory
101
-        );
102
-        return $loader->getCollection();
103
-    }
68
+	/**
69
+	 * @return CollectionInterface|RouteMatchSpecificationInterface[]
70
+	 * @throws CollectionLoaderException
71
+	 * @throws CollectionDetailsException
72
+	 * @since $VID:$
73
+	 */
74
+	private function populateSpecificationCollection()
75
+	{
76
+		$loader = new CollectionLoader(
77
+			new CollectionDetails(
78
+				// collection name
79
+				RouteMatchSpecificationCollection::COLLECTION_NAME,
80
+				// collection interface
81
+				'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface',
82
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
83
+				apply_filters(
84
+					'FHEE__EventEspresso_core_services_route_match_RouteMatchSpecificationManager__populateSpecificationCollection__collection_FQCNs',
85
+					array(
86
+						'EventEspresso\core\domain\entities\route_match\specifications\admin',
87
+						// 'EventEspresso\core\domain\entities\route_match\specifications\public',
88
+					)
89
+				),
90
+				// filepaths to classes to add
91
+				array(),
92
+				// file mask to use if parsing folder for files to add
93
+				'',
94
+				// what to use as identifier for collection entities
95
+				// using CLASS NAME prevents duplicates (works like a singleton)
96
+				CollectionDetails::ID_CLASS_NAME
97
+			),
98
+			$this->specifications,
99
+			null,
100
+			$this->specifications_factory
101
+		);
102
+		return $loader->getCollection();
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches
108
-     *
109
-     * @param string $routeMatchSpecificationFqcn fully qualified class name
110
-     * @return bool
111
-     * @throws InvalidClassException
112
-     * @since $VID:$
113
-     */
114
-    public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn)
115
-    {
116
-        /** @var RouteMatchSpecificationInterface $specification */
117
-        $specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
-        if (! $specification instanceof $routeMatchSpecificationFqcn) {
119
-            throw new InvalidClassException($routeMatchSpecificationFqcn);
120
-        }
121
-        return $specification->isMatchingRoute();
122
-    }
106
+	/**
107
+	 * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches
108
+	 *
109
+	 * @param string $routeMatchSpecificationFqcn fully qualified class name
110
+	 * @return bool
111
+	 * @throws InvalidClassException
112
+	 * @since $VID:$
113
+	 */
114
+	public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn)
115
+	{
116
+		/** @var RouteMatchSpecificationInterface $specification */
117
+		$specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
+		if (! $specification instanceof $routeMatchSpecificationFqcn) {
119
+			throw new InvalidClassException($routeMatchSpecificationFqcn);
120
+		}
121
+		return $specification->isMatchingRoute();
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * Handy method for development that returns
127
-     * a list of existing RouteMatchSpecification classes
128
-     * matching the current request that can be used to identify it.
129
-     * If no matches are returned (or nothing acceptable)
130
-     * then create a new one that better matches your requirements.
131
-     *
132
-     * @return array
133
-     * @since $VID:$
134
-     */
135
-    public function findRouteMatchSpecificationsMatchingCurrentRequest()
136
-    {
137
-        $matches = array();
138
-        foreach ($this->specifications as $specification) {
139
-            /** @var RouteMatchSpecificationInterface $specification */
140
-            if ($specification->isMatchingRoute()) {
141
-                $matches[] = get_class($specification);
142
-            }
143
-        }
144
-        return $matches;
145
-    }
125
+	/**
126
+	 * Handy method for development that returns
127
+	 * a list of existing RouteMatchSpecification classes
128
+	 * matching the current request that can be used to identify it.
129
+	 * If no matches are returned (or nothing acceptable)
130
+	 * then create a new one that better matches your requirements.
131
+	 *
132
+	 * @return array
133
+	 * @since $VID:$
134
+	 */
135
+	public function findRouteMatchSpecificationsMatchingCurrentRequest()
136
+	{
137
+		$matches = array();
138
+		foreach ($this->specifications as $specification) {
139
+			/** @var RouteMatchSpecificationInterface $specification */
140
+			if ($specification->isMatchingRoute()) {
141
+				$matches[] = get_class($specification);
142
+			}
143
+		}
144
+		return $matches;
145
+	}
146 146
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@
 block discarded – undo
115 115
     {
116 116
         /** @var RouteMatchSpecificationInterface $specification */
117 117
         $specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
-        if (! $specification instanceof $routeMatchSpecificationFqcn) {
118
+        if ( ! $specification instanceof $routeMatchSpecificationFqcn) {
119 119
             throw new InvalidClassException($routeMatchSpecificationFqcn);
120 120
         }
121 121
         return $specification->isMatchingRoute();
Please login to merge, or discard this patch.
core/services/editor/BlockRegistrationManager.php 2 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -32,207 +32,207 @@
 block discarded – undo
32 32
 class BlockRegistrationManager extends BlockManager
33 33
 {
34 34
 
35
-    /**
36
-     * @var BlockAssetManagerCollection $block_asset_manager_collection
37
-     */
38
-    protected $block_asset_manager_collection;
39
-
40
-    /**
41
-     * @var RouteMatchSpecificationManager $route_manager
42
-     */
43
-    protected $route_manager;
44
-
45
-    /**
46
-     * array for tracking asset managers required by blocks for the current route
47
-     *
48
-     * @var array $block_asset_managers
49
-     */
50
-    protected $block_asset_managers = array();
51
-
52
-
53
-    /**
54
-     * BlockRegistrationManager constructor.
55
-     *
56
-     * @param BlockAssetManagerCollection    $block_asset_manager_collection
57
-     * @param BlockCollection                $blocks
58
-     * @param RouteMatchSpecificationManager $route_manager
59
-     * @param RequestInterface               $request
60
-     */
61
-    public function __construct(
62
-        BlockAssetManagerCollection $block_asset_manager_collection,
63
-        BlockCollection $blocks,
64
-        RouteMatchSpecificationManager $route_manager,
65
-        RequestInterface $request
66
-    ) {
67
-        $this->block_asset_manager_collection = $block_asset_manager_collection;
68
-        $this->route_manager = $route_manager;
69
-        parent::__construct($blocks, $request);
70
-    }
71
-
72
-
73
-    /**
74
-     *  Returns the name of a hookpoint to be used to call initialize()
75
-     *
76
-     * @return string
77
-     */
78
-    public function initHook()
79
-    {
80
-        return 'AHEE__EE_System__initialize';
81
-    }
82
-
83
-
84
-    /**
85
-     * Perform any early setup required for block editors to functions
86
-     *
87
-     * @return void
88
-     * @throws Exception
89
-     */
90
-    public function initialize()
91
-    {
92
-        $this->initializeBlocks();
93
-        add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks'));
94
-        add_action('wp_loaded', array($this, 'unloadAssets'));
95
-    }
96
-
97
-
98
-    /**
99
-     * @return CollectionInterface|BlockInterface[]
100
-     * @throws CollectionLoaderException
101
-     * @throws CollectionDetailsException
102
-     */
103
-    protected function populateBlockCollection()
104
-    {
105
-        $loader = new CollectionLoader(
106
-            new CollectionDetails(
107
-                // collection name
108
-                'editor_blocks',
109
-                // collection interface
110
-                'EventEspresso\core\domain\entities\editor\BlockInterface',
111
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
112
-                apply_filters(
113
-                    'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs',
114
-                    array(
115
-                        // 'EventEspresso\core\domain\entities\editor\blocks\common',
116
-                        // 'EventEspresso\core\domain\entities\editor\blocks\editor',
117
-                        // 'EventEspresso\core\domain\entities\editor\blocks\widgets',
118
-                    )
119
-                ),
120
-                // filepaths to classes to add
121
-                array(),
122
-                // file mask to use if parsing folder for files to add
123
-                '',
124
-                // what to use as identifier for collection entities
125
-                // using CLASS NAME prevents duplicates (works like a singleton)
126
-                CollectionDetails::ID_CLASS_NAME
127
-            ),
128
-            $this->blocks
129
-        );
130
-        return $loader->getCollection();
131
-    }
132
-
133
-
134
-    /**
135
-     * populates the BlockCollection and calls initialize() on all installed blocks
136
-     *
137
-     * @return void
138
-     * @throws Exception
139
-     */
140
-    public function initializeBlocks()
141
-    {
142
-        try {
143
-            $this->populateBlockCollection();
144
-            // cycle thru block loaders and initialize each loader
145
-            foreach ($this->blocks as $block) {
146
-                $block->initialize();
147
-                $this->trackAssetManagersForBlocks($block);
148
-                if (! $this->block_asset_manager_collection->has($block->assetManager())) {
149
-                    $this->block_asset_manager_collection->add($block->assetManager());
150
-                    $block->assetManager()->setAssetHandles();
151
-                }
152
-            }
153
-        } catch (Exception $exception) {
154
-            new ExceptionStackTraceDisplay($exception);
155
-        }
156
-    }
157
-
158
-
159
-    /**
160
-     * track blocks with routes that match the current request
161
-     *
162
-     * @param BlockInterface $block
163
-     * @throws InvalidClassException
164
-     */
165
-    private function trackAssetManagersForBlocks(BlockInterface $block)
166
-    {
167
-        $supported_routes = $block->supportedRoutes();
168
-        foreach ($supported_routes as $supported_route) {
169
-            if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) {
170
-                $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace();
171
-            }
172
-        }
173
-    }
174
-
175
-
176
-    /**
177
-     * returns true if the block should be registered for the current request
178
-     * else removes block from block_routes array and returns false
179
-     *
180
-     * @param BlockInterface $block
181
-     * @return boolean
182
-     * @throws InvalidClassException
183
-     */
184
-    public function matchesRoute(BlockInterface $block)
185
-    {
186
-        if (isset($this->block_asset_managers[ $block->blockType() ])) {
187
-            return true;
188
-        }
189
-        unset($this->block_asset_managers[ $block->blockType() ]);
190
-        return false;
191
-    }
192
-
193
-
194
-    /**
195
-     * calls registerBlock() and load assets for all installed blocks
196
-     *
197
-     * @return void
198
-     * @throws Exception
199
-     */
200
-    public function registerBlocks()
201
-    {
202
-        try {
203
-            // cycle thru block loader folders
204
-            foreach ($this->blocks as $block) {
205
-                if (! $this->matchesRoute($block)) {
206
-                    continue;
207
-                }
208
-                // perform any setup required for the block
209
-                $block_type = $block->registerBlock();
210
-                if (! $block_type instanceof WP_Block_Type) {
211
-                    throw new InvalidEntityException($block_type, 'WP_Block_Type');
212
-                }
213
-                do_action(
214
-                    'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered',
215
-                    $block,
216
-                    $block_type
217
-                );
218
-            }
219
-        } catch (Exception $exception) {
220
-            new ExceptionStackTraceDisplay($exception);
221
-        }
222
-    }
223
-
224
-    public function unloadAssets()
225
-    {
226
-        $assets = array_flip($this->block_asset_managers);
227
-        foreach ($this->block_asset_manager_collection as $asset_manager) {
228
-            // if there are no longer any blocks that require these assets,
229
-            if (! isset($assets[ $asset_manager->assetNamespace() ])) {
230
-                // then unset asset enqueueing and bail
231
-                remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
232
-                remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
233
-                remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
234
-                remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
235
-            }
236
-        }
237
-    }
35
+	/**
36
+	 * @var BlockAssetManagerCollection $block_asset_manager_collection
37
+	 */
38
+	protected $block_asset_manager_collection;
39
+
40
+	/**
41
+	 * @var RouteMatchSpecificationManager $route_manager
42
+	 */
43
+	protected $route_manager;
44
+
45
+	/**
46
+	 * array for tracking asset managers required by blocks for the current route
47
+	 *
48
+	 * @var array $block_asset_managers
49
+	 */
50
+	protected $block_asset_managers = array();
51
+
52
+
53
+	/**
54
+	 * BlockRegistrationManager constructor.
55
+	 *
56
+	 * @param BlockAssetManagerCollection    $block_asset_manager_collection
57
+	 * @param BlockCollection                $blocks
58
+	 * @param RouteMatchSpecificationManager $route_manager
59
+	 * @param RequestInterface               $request
60
+	 */
61
+	public function __construct(
62
+		BlockAssetManagerCollection $block_asset_manager_collection,
63
+		BlockCollection $blocks,
64
+		RouteMatchSpecificationManager $route_manager,
65
+		RequestInterface $request
66
+	) {
67
+		$this->block_asset_manager_collection = $block_asset_manager_collection;
68
+		$this->route_manager = $route_manager;
69
+		parent::__construct($blocks, $request);
70
+	}
71
+
72
+
73
+	/**
74
+	 *  Returns the name of a hookpoint to be used to call initialize()
75
+	 *
76
+	 * @return string
77
+	 */
78
+	public function initHook()
79
+	{
80
+		return 'AHEE__EE_System__initialize';
81
+	}
82
+
83
+
84
+	/**
85
+	 * Perform any early setup required for block editors to functions
86
+	 *
87
+	 * @return void
88
+	 * @throws Exception
89
+	 */
90
+	public function initialize()
91
+	{
92
+		$this->initializeBlocks();
93
+		add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks'));
94
+		add_action('wp_loaded', array($this, 'unloadAssets'));
95
+	}
96
+
97
+
98
+	/**
99
+	 * @return CollectionInterface|BlockInterface[]
100
+	 * @throws CollectionLoaderException
101
+	 * @throws CollectionDetailsException
102
+	 */
103
+	protected function populateBlockCollection()
104
+	{
105
+		$loader = new CollectionLoader(
106
+			new CollectionDetails(
107
+				// collection name
108
+				'editor_blocks',
109
+				// collection interface
110
+				'EventEspresso\core\domain\entities\editor\BlockInterface',
111
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
112
+				apply_filters(
113
+					'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs',
114
+					array(
115
+						// 'EventEspresso\core\domain\entities\editor\blocks\common',
116
+						// 'EventEspresso\core\domain\entities\editor\blocks\editor',
117
+						// 'EventEspresso\core\domain\entities\editor\blocks\widgets',
118
+					)
119
+				),
120
+				// filepaths to classes to add
121
+				array(),
122
+				// file mask to use if parsing folder for files to add
123
+				'',
124
+				// what to use as identifier for collection entities
125
+				// using CLASS NAME prevents duplicates (works like a singleton)
126
+				CollectionDetails::ID_CLASS_NAME
127
+			),
128
+			$this->blocks
129
+		);
130
+		return $loader->getCollection();
131
+	}
132
+
133
+
134
+	/**
135
+	 * populates the BlockCollection and calls initialize() on all installed blocks
136
+	 *
137
+	 * @return void
138
+	 * @throws Exception
139
+	 */
140
+	public function initializeBlocks()
141
+	{
142
+		try {
143
+			$this->populateBlockCollection();
144
+			// cycle thru block loaders and initialize each loader
145
+			foreach ($this->blocks as $block) {
146
+				$block->initialize();
147
+				$this->trackAssetManagersForBlocks($block);
148
+				if (! $this->block_asset_manager_collection->has($block->assetManager())) {
149
+					$this->block_asset_manager_collection->add($block->assetManager());
150
+					$block->assetManager()->setAssetHandles();
151
+				}
152
+			}
153
+		} catch (Exception $exception) {
154
+			new ExceptionStackTraceDisplay($exception);
155
+		}
156
+	}
157
+
158
+
159
+	/**
160
+	 * track blocks with routes that match the current request
161
+	 *
162
+	 * @param BlockInterface $block
163
+	 * @throws InvalidClassException
164
+	 */
165
+	private function trackAssetManagersForBlocks(BlockInterface $block)
166
+	{
167
+		$supported_routes = $block->supportedRoutes();
168
+		foreach ($supported_routes as $supported_route) {
169
+			if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) {
170
+				$this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace();
171
+			}
172
+		}
173
+	}
174
+
175
+
176
+	/**
177
+	 * returns true if the block should be registered for the current request
178
+	 * else removes block from block_routes array and returns false
179
+	 *
180
+	 * @param BlockInterface $block
181
+	 * @return boolean
182
+	 * @throws InvalidClassException
183
+	 */
184
+	public function matchesRoute(BlockInterface $block)
185
+	{
186
+		if (isset($this->block_asset_managers[ $block->blockType() ])) {
187
+			return true;
188
+		}
189
+		unset($this->block_asset_managers[ $block->blockType() ]);
190
+		return false;
191
+	}
192
+
193
+
194
+	/**
195
+	 * calls registerBlock() and load assets for all installed blocks
196
+	 *
197
+	 * @return void
198
+	 * @throws Exception
199
+	 */
200
+	public function registerBlocks()
201
+	{
202
+		try {
203
+			// cycle thru block loader folders
204
+			foreach ($this->blocks as $block) {
205
+				if (! $this->matchesRoute($block)) {
206
+					continue;
207
+				}
208
+				// perform any setup required for the block
209
+				$block_type = $block->registerBlock();
210
+				if (! $block_type instanceof WP_Block_Type) {
211
+					throw new InvalidEntityException($block_type, 'WP_Block_Type');
212
+				}
213
+				do_action(
214
+					'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered',
215
+					$block,
216
+					$block_type
217
+				);
218
+			}
219
+		} catch (Exception $exception) {
220
+			new ExceptionStackTraceDisplay($exception);
221
+		}
222
+	}
223
+
224
+	public function unloadAssets()
225
+	{
226
+		$assets = array_flip($this->block_asset_managers);
227
+		foreach ($this->block_asset_manager_collection as $asset_manager) {
228
+			// if there are no longer any blocks that require these assets,
229
+			if (! isset($assets[ $asset_manager->assetNamespace() ])) {
230
+				// then unset asset enqueueing and bail
231
+				remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
232
+				remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
233
+				remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
234
+				remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
235
+			}
236
+		}
237
+	}
238 238
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
             foreach ($this->blocks as $block) {
146 146
                 $block->initialize();
147 147
                 $this->trackAssetManagersForBlocks($block);
148
-                if (! $this->block_asset_manager_collection->has($block->assetManager())) {
148
+                if ( ! $this->block_asset_manager_collection->has($block->assetManager())) {
149 149
                     $this->block_asset_manager_collection->add($block->assetManager());
150 150
                     $block->assetManager()->setAssetHandles();
151 151
                 }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
         $supported_routes = $block->supportedRoutes();
168 168
         foreach ($supported_routes as $supported_route) {
169 169
             if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) {
170
-                $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace();
170
+                $this->block_asset_managers[$block->blockType()] = $block->assetManager()->assetNamespace();
171 171
             }
172 172
         }
173 173
     }
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
      */
184 184
     public function matchesRoute(BlockInterface $block)
185 185
     {
186
-        if (isset($this->block_asset_managers[ $block->blockType() ])) {
186
+        if (isset($this->block_asset_managers[$block->blockType()])) {
187 187
             return true;
188 188
         }
189
-        unset($this->block_asset_managers[ $block->blockType() ]);
189
+        unset($this->block_asset_managers[$block->blockType()]);
190 190
         return false;
191 191
     }
192 192
 
@@ -202,12 +202,12 @@  discard block
 block discarded – undo
202 202
         try {
203 203
             // cycle thru block loader folders
204 204
             foreach ($this->blocks as $block) {
205
-                if (! $this->matchesRoute($block)) {
205
+                if ( ! $this->matchesRoute($block)) {
206 206
                     continue;
207 207
                 }
208 208
                 // perform any setup required for the block
209 209
                 $block_type = $block->registerBlock();
210
-                if (! $block_type instanceof WP_Block_Type) {
210
+                if ( ! $block_type instanceof WP_Block_Type) {
211 211
                     throw new InvalidEntityException($block_type, 'WP_Block_Type');
212 212
                 }
213 213
                 do_action(
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
         $assets = array_flip($this->block_asset_managers);
227 227
         foreach ($this->block_asset_manager_collection as $asset_manager) {
228 228
             // if there are no longer any blocks that require these assets,
229
-            if (! isset($assets[ $asset_manager->assetNamespace() ])) {
229
+            if ( ! isset($assets[$asset_manager->assetNamespace()])) {
230 230
                 // then unset asset enqueueing and bail
231 231
                 remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
232 232
                 remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
Please login to merge, or discard this patch.
core/services/dependencies/DependencyResolver.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -23,155 +23,155 @@
 block discarded – undo
23 23
 abstract class DependencyResolver implements DependencyResolverInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var Mirror $mirror
28
-     */
29
-    private $mirror;
30
-
31
-    /**
32
-     * @var ClassInterfaceCache $class_cache
33
-     */
34
-    private $class_cache;
35
-
36
-    /**
37
-     * @var EE_Dependency_Map $dependency_map
38
-     */
39
-    private $dependency_map;
40
-
41
-    /**
42
-     * @var ClassAlias[] $aliases
43
-     */
44
-    private $aliases = array();
45
-
46
-    /**
47
-     * @var array $recursions
48
-     */
49
-    private $recursions = array();
50
-
51
-
52
-    /**
53
-     * RouteMatchSpecificationDependencyResolver constructor.
54
-     *
55
-     * @param Mirror              $mirror
56
-     * @param ClassInterfaceCache $class_cache
57
-     * @param EE_Dependency_Map   $dependency_map
58
-     */
59
-    public function __construct(
60
-        Mirror $mirror,
61
-        ClassInterfaceCache $class_cache,
62
-        EE_Dependency_Map $dependency_map
63
-    ) {
64
-        $this->mirror = $mirror;
65
-        $this->class_cache = $class_cache;
66
-        $this->dependency_map = $dependency_map;
67
-        $this->initialize();
68
-    }
69
-
70
-    /**
71
-     * @return Mirror
72
-     */
73
-    public function mirror()
74
-    {
75
-        return $this->mirror;
76
-    }
77
-
78
-    /**
79
-     * @return ClassInterfaceCache
80
-     */
81
-    public function classCache()
82
-    {
83
-        return $this->class_cache;
84
-    }
85
-
86
-    /**
87
-     * @return EE_Dependency_Map
88
-     */
89
-    public function dependencyMap()
90
-    {
91
-        return $this->dependency_map;
92
-    }
93
-
94
-    /**
95
-     * @param ClassAlias $alias
96
-     * @throws InvalidAliasException
97
-     */
98
-    public function addAlias(ClassAlias $alias)
99
-    {
100
-        $this->aliases[ $alias->fqcn() ] = $alias;
101
-    }
102
-
103
-    /**
104
-     * @param string $param_fqcn Fully Qualified Class Name for dependency parameter
105
-     * @return string
106
-     */
107
-    public function resolveAlias($param_fqcn)
108
-    {
109
-        return isset($this->aliases[ $param_fqcn ])
110
-            ? $this->aliases[ $param_fqcn ]->alias()
111
-            : $this->classCache()->getFqnForAlias($param_fqcn);
112
-    }
113
-
114
-    /**
115
-     * Primarily used to indicate the base namespace for composite objects
116
-     * so that dependencies requiring the same DependencyResolver can be acquired
117
-     * for example:
118
-     * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C
119
-     * may all implement Vendor\path\to\Interface,
120
-     * but Vendor\path\to\class\C could be a composite object
121
-     * that requires Vendor\path\to\class\A and Vendor\path\to\class\B,
122
-     * and needs both of those dependencies resolved, which would therefore require
123
-     * the use of the same DependencyResolver.
124
-     *
125
-     * By specifying a base namespace  of "Vendor\path\to\",
126
-     * then all classes that are descendants of that namespace
127
-     * will use DependencyResolver to acquire the classes they need
128
-     *
129
-     * @param string $base_namespace Partial namespace used for detecting other classes
130
-     *                               that should employ this same DependencyResolver
131
-     */
132
-    public function addRecursion($base_namespace)
133
-    {
134
-        $this->recursions[] = $base_namespace;
135
-    }
136
-
137
-    /**
138
-     * Returns true if the parameter FQCN belongs to one of
139
-     * the namespaces that utilizes this DependencyResolver
140
-     *
141
-     * @param string $param_fqcn Fully Qualified Class Name for dependency parameter
142
-     * @return boolean
143
-     * @since $VID:$
144
-     */
145
-    public function dependencyRecursionExists($param_fqcn)
146
-    {
147
-        foreach ($this->recursions as $recursion) {
148
-            if (strpos($param_fqcn, $recursion) !== false) {
149
-                return true;
150
-            }
151
-        }
152
-        return false;
153
-    }
154
-
155
-
156
-    /**
157
-     * @param string $fqcn Fully Qualified Class Name
158
-     * @throws InvalidDataTypeException
159
-     * @throws ReflectionException
160
-     * @since $VID:$
161
-     */
162
-    public function resolveDependenciesForClass($fqcn)
163
-    {
164
-        $dependencies = array();
165
-        $params = $this->mirror()->getParameters($fqcn);
166
-        foreach ($params as $index => $param) {
167
-            // is this a dependency for a specific class ?
168
-            $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index);
169
-            if ($this->dependencyRecursionExists($param_class)) {
170
-                $this->resolveDependenciesForClass($param_class);
171
-            }
172
-            $param_class = $this->resolveAlias($param_class);
173
-            $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache;
174
-        }
175
-        $this->dependencyMap()->registerDependencies($fqcn, $dependencies);
176
-    }
26
+	/**
27
+	 * @var Mirror $mirror
28
+	 */
29
+	private $mirror;
30
+
31
+	/**
32
+	 * @var ClassInterfaceCache $class_cache
33
+	 */
34
+	private $class_cache;
35
+
36
+	/**
37
+	 * @var EE_Dependency_Map $dependency_map
38
+	 */
39
+	private $dependency_map;
40
+
41
+	/**
42
+	 * @var ClassAlias[] $aliases
43
+	 */
44
+	private $aliases = array();
45
+
46
+	/**
47
+	 * @var array $recursions
48
+	 */
49
+	private $recursions = array();
50
+
51
+
52
+	/**
53
+	 * RouteMatchSpecificationDependencyResolver constructor.
54
+	 *
55
+	 * @param Mirror              $mirror
56
+	 * @param ClassInterfaceCache $class_cache
57
+	 * @param EE_Dependency_Map   $dependency_map
58
+	 */
59
+	public function __construct(
60
+		Mirror $mirror,
61
+		ClassInterfaceCache $class_cache,
62
+		EE_Dependency_Map $dependency_map
63
+	) {
64
+		$this->mirror = $mirror;
65
+		$this->class_cache = $class_cache;
66
+		$this->dependency_map = $dependency_map;
67
+		$this->initialize();
68
+	}
69
+
70
+	/**
71
+	 * @return Mirror
72
+	 */
73
+	public function mirror()
74
+	{
75
+		return $this->mirror;
76
+	}
77
+
78
+	/**
79
+	 * @return ClassInterfaceCache
80
+	 */
81
+	public function classCache()
82
+	{
83
+		return $this->class_cache;
84
+	}
85
+
86
+	/**
87
+	 * @return EE_Dependency_Map
88
+	 */
89
+	public function dependencyMap()
90
+	{
91
+		return $this->dependency_map;
92
+	}
93
+
94
+	/**
95
+	 * @param ClassAlias $alias
96
+	 * @throws InvalidAliasException
97
+	 */
98
+	public function addAlias(ClassAlias $alias)
99
+	{
100
+		$this->aliases[ $alias->fqcn() ] = $alias;
101
+	}
102
+
103
+	/**
104
+	 * @param string $param_fqcn Fully Qualified Class Name for dependency parameter
105
+	 * @return string
106
+	 */
107
+	public function resolveAlias($param_fqcn)
108
+	{
109
+		return isset($this->aliases[ $param_fqcn ])
110
+			? $this->aliases[ $param_fqcn ]->alias()
111
+			: $this->classCache()->getFqnForAlias($param_fqcn);
112
+	}
113
+
114
+	/**
115
+	 * Primarily used to indicate the base namespace for composite objects
116
+	 * so that dependencies requiring the same DependencyResolver can be acquired
117
+	 * for example:
118
+	 * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C
119
+	 * may all implement Vendor\path\to\Interface,
120
+	 * but Vendor\path\to\class\C could be a composite object
121
+	 * that requires Vendor\path\to\class\A and Vendor\path\to\class\B,
122
+	 * and needs both of those dependencies resolved, which would therefore require
123
+	 * the use of the same DependencyResolver.
124
+	 *
125
+	 * By specifying a base namespace  of "Vendor\path\to\",
126
+	 * then all classes that are descendants of that namespace
127
+	 * will use DependencyResolver to acquire the classes they need
128
+	 *
129
+	 * @param string $base_namespace Partial namespace used for detecting other classes
130
+	 *                               that should employ this same DependencyResolver
131
+	 */
132
+	public function addRecursion($base_namespace)
133
+	{
134
+		$this->recursions[] = $base_namespace;
135
+	}
136
+
137
+	/**
138
+	 * Returns true if the parameter FQCN belongs to one of
139
+	 * the namespaces that utilizes this DependencyResolver
140
+	 *
141
+	 * @param string $param_fqcn Fully Qualified Class Name for dependency parameter
142
+	 * @return boolean
143
+	 * @since $VID:$
144
+	 */
145
+	public function dependencyRecursionExists($param_fqcn)
146
+	{
147
+		foreach ($this->recursions as $recursion) {
148
+			if (strpos($param_fqcn, $recursion) !== false) {
149
+				return true;
150
+			}
151
+		}
152
+		return false;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @param string $fqcn Fully Qualified Class Name
158
+	 * @throws InvalidDataTypeException
159
+	 * @throws ReflectionException
160
+	 * @since $VID:$
161
+	 */
162
+	public function resolveDependenciesForClass($fqcn)
163
+	{
164
+		$dependencies = array();
165
+		$params = $this->mirror()->getParameters($fqcn);
166
+		foreach ($params as $index => $param) {
167
+			// is this a dependency for a specific class ?
168
+			$param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index);
169
+			if ($this->dependencyRecursionExists($param_class)) {
170
+				$this->resolveDependenciesForClass($param_class);
171
+			}
172
+			$param_class = $this->resolveAlias($param_class);
173
+			$dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache;
174
+		}
175
+		$this->dependencyMap()->registerDependencies($fqcn, $dependencies);
176
+	}
177 177
 }
Please login to merge, or discard this patch.
entities/route_match/specifications/admin/WordPressPostsEditorEdit.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,16 +14,16 @@
 block discarded – undo
14 14
  */
15 15
 class WordPressPostsEditorEdit extends RouteMatchSpecification
16 16
 {
17
-    /**
18
-     * returns true if current request matches specification
19
-     *
20
-     * @since $VID:$
21
-     * @return boolean
22
-     */
23
-    public function isMatchingRoute()
24
-    {
25
-        return strpos($this->request->requestUri(), 'wp-admin/post.php') !== false
26
-            && $this->request->getRequestParam('post_type', 'post') === 'post'
27
-            && $this->request->getRequestParam('action') === 'edit';
28
-    }
17
+	/**
18
+	 * returns true if current request matches specification
19
+	 *
20
+	 * @since $VID:$
21
+	 * @return boolean
22
+	 */
23
+	public function isMatchingRoute()
24
+	{
25
+		return strpos($this->request->requestUri(), 'wp-admin/post.php') !== false
26
+			&& $this->request->getRequestParam('post_type', 'post') === 'post'
27
+			&& $this->request->getRequestParam('action') === 'edit';
28
+	}
29 29
 }
Please login to merge, or discard this patch.
entities/route_match/specifications/admin/WordPressPostsEditorAddNew.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@
 block discarded – undo
14 14
  */
15 15
 class WordPressPostsEditorAddNew extends RouteMatchSpecification
16 16
 {
17
-    /**
18
-     * returns true if current request matches specification
19
-     *
20
-     * @since $VID:$
21
-     * @return boolean
22
-     */
23
-    public function isMatchingRoute()
24
-    {
25
-        return strpos($this->request->requestUri(), 'wp-admin/post-new.php') !== false
26
-            && $this->request->getRequestParam('post_type', 'post') === 'post';
27
-    }
17
+	/**
18
+	 * returns true if current request matches specification
19
+	 *
20
+	 * @since $VID:$
21
+	 * @return boolean
22
+	 */
23
+	public function isMatchingRoute()
24
+	{
25
+		return strpos($this->request->requestUri(), 'wp-admin/post-new.php') !== false
26
+			&& $this->request->getRequestParam('post_type', 'post') === 'post';
27
+	}
28 28
 }
Please login to merge, or discard this patch.
domain/entities/route_match/specifications/admin/WordPressPostsEditor.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -18,21 +18,21 @@
 block discarded – undo
18 18
  */
19 19
 class WordPressPostsEditor extends MatchAnyRouteSpecification
20 20
 {
21
-    /**
22
-     * WordPressPostsEditor constructor.
23
-     *
24
-     * @param WordPressPostsEditorEdit   $edit_event_route_match
25
-     * @param WordPressPostsEditorAddNew $create_event_route_match
26
-     * @param RequestInterface           $request
27
-     */
28
-    public function __construct(
29
-        WordPressPostsEditorEdit $edit_event_route_match,
30
-        WordPressPostsEditorAddNew $create_event_route_match,
31
-        RequestInterface $request
32
-    ) {
33
-        parent::__construct(
34
-            array($edit_event_route_match, $create_event_route_match),
35
-            $request
36
-        );
37
-    }
21
+	/**
22
+	 * WordPressPostsEditor constructor.
23
+	 *
24
+	 * @param WordPressPostsEditorEdit   $edit_event_route_match
25
+	 * @param WordPressPostsEditorAddNew $create_event_route_match
26
+	 * @param RequestInterface           $request
27
+	 */
28
+	public function __construct(
29
+		WordPressPostsEditorEdit $edit_event_route_match,
30
+		WordPressPostsEditorAddNew $create_event_route_match,
31
+		RequestInterface $request
32
+	) {
33
+		parent::__construct(
34
+			array($edit_event_route_match, $create_event_route_match),
35
+			$request
36
+		);
37
+	}
38 38
 }
Please login to merge, or discard this patch.
entities/route_match/specifications/admin/WordPressPostsListTable.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@
 block discarded – undo
14 14
  */
15 15
 class WordPressPostsListTable extends RouteMatchSpecification
16 16
 {
17
-    /**
18
-     * returns true if current request matches specification
19
-     *
20
-     * @since $VID:$
21
-     * @return boolean
22
-     */
23
-    public function isMatchingRoute()
24
-    {
25
-        return strpos($this->request->requestUri(), 'wp-admin/edit.php') !== false
26
-            && $this->request->getRequestParam('post_type', 'post') === 'post';
27
-    }
17
+	/**
18
+	 * returns true if current request matches specification
19
+	 *
20
+	 * @since $VID:$
21
+	 * @return boolean
22
+	 */
23
+	public function isMatchingRoute()
24
+	{
25
+		return strpos($this->request->requestUri(), 'wp-admin/edit.php') !== false
26
+			&& $this->request->getRequestParam('post_type', 'post') === 'post';
27
+	}
28 28
 }
Please login to merge, or discard this patch.