Completed
Pull Request — Gutenberg/master (#614)
by
unknown
14:10
created
core/services/route_match/RouteMatchSpecificationFactory.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -24,46 +24,46 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/services/dependencies/DependencyResolverInterface.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,16 +15,16 @@
 block discarded – undo
15 15
  */
16 16
 interface DependencyResolverInterface
17 17
 {
18
-    /**
19
-     * Used to configure and/or setup any aliases or recursions required by the DependencyResolver
20
-     *
21
-     * @since $VID:$
22
-     */
23
-    public function initialize();
18
+	/**
19
+	 * Used to configure and/or setup any aliases or recursions required by the DependencyResolver
20
+	 *
21
+	 * @since $VID:$
22
+	 */
23
+	public function initialize();
24 24
 
25
-    /**
26
-     * @param string $fqcn Fully Qualified Class Name
27
-     * @since $VID:$
28
-     */
29
-    public function resolveDependenciesForClass($fqcn);
25
+	/**
26
+	 * @param string $fqcn Fully Qualified Class Name
27
+	 * @since $VID:$
28
+	 */
29
+	public function resolveDependenciesForClass($fqcn);
30 30
 }
Please login to merge, or discard this patch.
core/services/dependencies/ClassAlias.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -15,45 +15,45 @@
 block discarded – undo
15 15
 class ClassAlias
16 16
 {
17 17
 
18
-    /**
19
-     * @var string $alias
20
-     */
21
-    private $alias;
22
-
23
-    /**
24
-     * @var string $fqcn
25
-     */
26
-    private $fqcn;
27
-
28
-    /**
29
-     * DependencyAlias constructor.
30
-     *
31
-     * @param string $alias Interface specified by implementing class
32
-     * @param string $fqcn  Concrete class that satisfies interface
33
-     * @throws InvalidAliasException
34
-     */
35
-    public function __construct($alias, $fqcn)
36
-    {
37
-        if (! is_subclass_of($fqcn, $alias)) {
38
-            throw new InvalidAliasException($fqcn, $alias);
39
-        }
40
-        $this->alias = $alias;
41
-        $this->fqcn = $fqcn;
42
-    }
43
-
44
-    /**
45
-     * @return string
46
-     */
47
-    public function alias()
48
-    {
49
-        return $this->alias;
50
-    }
51
-
52
-    /**
53
-     * @return string
54
-     */
55
-    public function fqcn()
56
-    {
57
-        return $this->fqcn;
58
-    }
18
+	/**
19
+	 * @var string $alias
20
+	 */
21
+	private $alias;
22
+
23
+	/**
24
+	 * @var string $fqcn
25
+	 */
26
+	private $fqcn;
27
+
28
+	/**
29
+	 * DependencyAlias constructor.
30
+	 *
31
+	 * @param string $alias Interface specified by implementing class
32
+	 * @param string $fqcn  Concrete class that satisfies interface
33
+	 * @throws InvalidAliasException
34
+	 */
35
+	public function __construct($alias, $fqcn)
36
+	{
37
+		if (! is_subclass_of($fqcn, $alias)) {
38
+			throw new InvalidAliasException($fqcn, $alias);
39
+		}
40
+		$this->alias = $alias;
41
+		$this->fqcn = $fqcn;
42
+	}
43
+
44
+	/**
45
+	 * @return string
46
+	 */
47
+	public function alias()
48
+	{
49
+		return $this->alias;
50
+	}
51
+
52
+	/**
53
+	 * @return string
54
+	 */
55
+	public function fqcn()
56
+	{
57
+		return $this->fqcn;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
      */
35 35
     public function __construct($alias, $fqcn)
36 36
     {
37
-        if (! is_subclass_of($fqcn, $alias)) {
37
+        if ( ! is_subclass_of($fqcn, $alias)) {
38 38
             throw new InvalidAliasException($fqcn, $alias);
39 39
         }
40 40
         $this->alias = $alias;
Please login to merge, or discard this patch.
core/services/dependencies/DependencyResolver.php 2 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -23,156 +23,156 @@
 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
-    {
65
-        $this->mirror = $mirror;
66
-        $this->class_cache = $class_cache;
67
-        $this->dependency_map = $dependency_map;
68
-        $this->initialize();
69
-    }
70
-
71
-    /**
72
-     * @return Mirror
73
-     */
74
-    public function mirror()
75
-    {
76
-        return $this->mirror;
77
-    }
78
-
79
-    /**
80
-     * @return ClassInterfaceCache
81
-     */
82
-    public function classCache()
83
-    {
84
-        return $this->class_cache;
85
-    }
86
-
87
-    /**
88
-     * @return EE_Dependency_Map
89
-     */
90
-    public function dependencyMap()
91
-    {
92
-        return $this->dependency_map;
93
-    }
94
-
95
-    /**
96
-     * @param ClassAlias $alias
97
-     * @throws InvalidAliasException
98
-     */
99
-    public function addAlias(ClassAlias $alias)
100
-    {
101
-        $this->aliases[ $alias->fqcn() ] = $alias;
102
-    }
103
-
104
-    /**
105
-     * @param string $param_fqcn Fully Qualified Class Name for dependency parameter
106
-     * @return string
107
-     */
108
-    public function resolveAlias($param_fqcn)
109
-    {
110
-        return isset($this->aliases[ $param_fqcn ])
111
-            ? $this->aliases[ $param_fqcn ]->alias()
112
-            : $this->classCache()->getFqnForAlias($param_fqcn);
113
-    }
114
-
115
-    /**
116
-     * Primarily used to indicate the base namespace for composite objects
117
-     * so that dependencies requiring the same DependencyResolver can be acquired
118
-     * for example:
119
-     * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C
120
-     * may all implement Vendor\path\to\Interface,
121
-     * but Vendor\path\to\class\C could be a composite object
122
-     * that requires Vendor\path\to\class\A and Vendor\path\to\class\B,
123
-     * and needs both of those dependencies resolved, which would therefore require
124
-     * the use of the same DependencyResolver.
125
-     *
126
-     * By specifying a base namespace  of "Vendor\path\to\",
127
-     * then all classes that are descendants of that namespace
128
-     * will use DependencyResolver to acquire the classes they need
129
-     *
130
-     * @param string $base_namespace Partial namespace used for detecting other classes
131
-     *                               that should employ this same DependencyResolver
132
-     */
133
-    public function addRecursion($base_namespace)
134
-    {
135
-        $this->recursions[] = $base_namespace;
136
-    }
137
-
138
-    /**
139
-     * Returns true if the parameter FQCN belongs to one of
140
-     * the namespaces that utilizes this DependencyResolver
141
-     *
142
-     * @param string $param_fqcn Fully Qualified Class Name for dependency parameter
143
-     * @return boolean
144
-     * @since $VID:$
145
-     */
146
-    public function dependencyRecursionExists($param_fqcn)
147
-    {
148
-        foreach ($this->recursions as $recursion) {
149
-            if (strpos($param_fqcn, $recursion) !== false) {
150
-                return true;
151
-            }
152
-        }
153
-        return false;
154
-    }
155
-
156
-
157
-    /**
158
-     * @param string $fqcn Fully Qualified Class Name
159
-     * @throws InvalidDataTypeException
160
-     * @throws ReflectionException
161
-     * @since $VID:$
162
-     */
163
-    public function resolveDependenciesForClass($fqcn)
164
-    {
165
-        $dependencies = array();
166
-        $params = $this->mirror()->getParameters($fqcn);
167
-        foreach ($params as $index => $param) {
168
-            // is this a dependency for a specific class ?
169
-            $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index);
170
-            if ($this->dependencyRecursionExists($param_class)) {
171
-                $this->resolveDependenciesForClass($param_class);
172
-            }
173
-            $param_class = $this->resolveAlias($param_class);
174
-            $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache;
175
-        }
176
-        $this->dependencyMap()->registerDependencies($fqcn, $dependencies);
177
-    }
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
+	{
65
+		$this->mirror = $mirror;
66
+		$this->class_cache = $class_cache;
67
+		$this->dependency_map = $dependency_map;
68
+		$this->initialize();
69
+	}
70
+
71
+	/**
72
+	 * @return Mirror
73
+	 */
74
+	public function mirror()
75
+	{
76
+		return $this->mirror;
77
+	}
78
+
79
+	/**
80
+	 * @return ClassInterfaceCache
81
+	 */
82
+	public function classCache()
83
+	{
84
+		return $this->class_cache;
85
+	}
86
+
87
+	/**
88
+	 * @return EE_Dependency_Map
89
+	 */
90
+	public function dependencyMap()
91
+	{
92
+		return $this->dependency_map;
93
+	}
94
+
95
+	/**
96
+	 * @param ClassAlias $alias
97
+	 * @throws InvalidAliasException
98
+	 */
99
+	public function addAlias(ClassAlias $alias)
100
+	{
101
+		$this->aliases[ $alias->fqcn() ] = $alias;
102
+	}
103
+
104
+	/**
105
+	 * @param string $param_fqcn Fully Qualified Class Name for dependency parameter
106
+	 * @return string
107
+	 */
108
+	public function resolveAlias($param_fqcn)
109
+	{
110
+		return isset($this->aliases[ $param_fqcn ])
111
+			? $this->aliases[ $param_fqcn ]->alias()
112
+			: $this->classCache()->getFqnForAlias($param_fqcn);
113
+	}
114
+
115
+	/**
116
+	 * Primarily used to indicate the base namespace for composite objects
117
+	 * so that dependencies requiring the same DependencyResolver can be acquired
118
+	 * for example:
119
+	 * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C
120
+	 * may all implement Vendor\path\to\Interface,
121
+	 * but Vendor\path\to\class\C could be a composite object
122
+	 * that requires Vendor\path\to\class\A and Vendor\path\to\class\B,
123
+	 * and needs both of those dependencies resolved, which would therefore require
124
+	 * the use of the same DependencyResolver.
125
+	 *
126
+	 * By specifying a base namespace  of "Vendor\path\to\",
127
+	 * then all classes that are descendants of that namespace
128
+	 * will use DependencyResolver to acquire the classes they need
129
+	 *
130
+	 * @param string $base_namespace Partial namespace used for detecting other classes
131
+	 *                               that should employ this same DependencyResolver
132
+	 */
133
+	public function addRecursion($base_namespace)
134
+	{
135
+		$this->recursions[] = $base_namespace;
136
+	}
137
+
138
+	/**
139
+	 * Returns true if the parameter FQCN belongs to one of
140
+	 * the namespaces that utilizes this DependencyResolver
141
+	 *
142
+	 * @param string $param_fqcn Fully Qualified Class Name for dependency parameter
143
+	 * @return boolean
144
+	 * @since $VID:$
145
+	 */
146
+	public function dependencyRecursionExists($param_fqcn)
147
+	{
148
+		foreach ($this->recursions as $recursion) {
149
+			if (strpos($param_fqcn, $recursion) !== false) {
150
+				return true;
151
+			}
152
+		}
153
+		return false;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param string $fqcn Fully Qualified Class Name
159
+	 * @throws InvalidDataTypeException
160
+	 * @throws ReflectionException
161
+	 * @since $VID:$
162
+	 */
163
+	public function resolveDependenciesForClass($fqcn)
164
+	{
165
+		$dependencies = array();
166
+		$params = $this->mirror()->getParameters($fqcn);
167
+		foreach ($params as $index => $param) {
168
+			// is this a dependency for a specific class ?
169
+			$param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index);
170
+			if ($this->dependencyRecursionExists($param_class)) {
171
+				$this->resolveDependenciesForClass($param_class);
172
+			}
173
+			$param_class = $this->resolveAlias($param_class);
174
+			$dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache;
175
+		}
176
+		$this->dependencyMap()->registerDependencies($fqcn, $dependencies);
177
+	}
178 178
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function addAlias(ClassAlias $alias)
100 100
     {
101
-        $this->aliases[ $alias->fqcn() ] = $alias;
101
+        $this->aliases[$alias->fqcn()] = $alias;
102 102
     }
103 103
 
104 104
     /**
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public function resolveAlias($param_fqcn)
109 109
     {
110
-        return isset($this->aliases[ $param_fqcn ])
111
-            ? $this->aliases[ $param_fqcn ]->alias()
110
+        return isset($this->aliases[$param_fqcn])
111
+            ? $this->aliases[$param_fqcn]->alias()
112 112
             : $this->classCache()->getFqnForAlias($param_fqcn);
113 113
     }
114 114
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
                 $this->resolveDependenciesForClass($param_class);
172 172
             }
173 173
             $param_class = $this->resolveAlias($param_class);
174
-            $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache;
174
+            $dependencies[$param_class] = EE_Dependency_Map::load_from_cache;
175 175
         }
176 176
         $this->dependencyMap()->registerDependencies($fqcn, $dependencies);
177 177
     }
Please login to merge, or discard this patch.
core/services/editor/BlockRegistrationManager.php 2 patches
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -32,210 +32,210 @@
 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
-        }
238
-
239
-    }
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
+
239
+	}
240 240
 }
241 241
 
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/factory/FactoryWithDependencyResolver.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,41 +18,41 @@
 block discarded – undo
18 18
  */
19 19
 abstract class FactoryWithDependencyResolver implements FactoryInterface
20 20
 {
21
-    /**
22
-     * @var DependencyResolverInterface $dependency_resolver
23
-     */
24
-    private $dependency_resolver;
21
+	/**
22
+	 * @var DependencyResolverInterface $dependency_resolver
23
+	 */
24
+	private $dependency_resolver;
25 25
 
26
-    /**
27
-     * @var LoaderInterface $loader
28
-     */
29
-    private $loader;
26
+	/**
27
+	 * @var LoaderInterface $loader
28
+	 */
29
+	private $loader;
30 30
 
31
-    /**
32
-     * FactoryWithDependencyResolver constructor.
33
-     *
34
-     * @param DependencyResolverInterface $dependency_resolver
35
-     * @param LoaderInterface             $loader
36
-     */
37
-    public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader)
38
-    {
39
-        $this->dependency_resolver = $dependency_resolver;
40
-        $this->loader = $loader;
41
-    }
31
+	/**
32
+	 * FactoryWithDependencyResolver constructor.
33
+	 *
34
+	 * @param DependencyResolverInterface $dependency_resolver
35
+	 * @param LoaderInterface             $loader
36
+	 */
37
+	public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader)
38
+	{
39
+		$this->dependency_resolver = $dependency_resolver;
40
+		$this->loader = $loader;
41
+	}
42 42
 
43
-    /**
44
-     * @return DependencyResolverInterface
45
-     */
46
-    public function dependencyResolver()
47
-    {
48
-        return $this->dependency_resolver;
49
-    }
43
+	/**
44
+	 * @return DependencyResolverInterface
45
+	 */
46
+	public function dependencyResolver()
47
+	{
48
+		return $this->dependency_resolver;
49
+	}
50 50
 
51
-    /**
52
-     * @return LoaderInterface
53
-     */
54
-    public function loader()
55
-    {
56
-        return $this->loader;
57
-    }
51
+	/**
52
+	 * @return LoaderInterface
53
+	 */
54
+	public function loader()
55
+	{
56
+		return $this->loader;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
core/services/loaders/ClassInterfaceCache.php 2 patches
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.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
     {
50 50
         $fqn = $this->getFqn($fqn);
51 51
         // have we already seen this FQCN ?
52
-        if (! array_key_exists($fqn, $this->interfaces)) {
53
-            $this->interfaces[ $fqn ] = array();
52
+        if ( ! array_key_exists($fqn, $this->interfaces)) {
53
+            $this->interfaces[$fqn] = array();
54 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 ]
55
+                $this->interfaces[$fqn] = class_implements($fqn, false);
56
+                $this->interfaces[$fqn] = $this->interfaces[$fqn] !== false
57
+                    ? $this->interfaces[$fqn]
58 58
                     : array();
59 59
             }
60 60
         }
61
-        return $this->interfaces[ $fqn ];
61
+        return $this->interfaces[$fqn];
62 62
     }
63 63
 
64 64
 
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
     {
88 88
         $fqn   = $this->getFqn($fqn);
89 89
         $alias = $this->getFqn($alias);
90
-        if(strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) {
90
+        if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) {
91 91
             throw new InvalidAliasException($fqn, $alias);
92 92
         }
93 93
         // are we adding an alias for a specific class?
94 94
         if ($for_class !== '') {
95 95
             // make sure it's set up as an array
96
-            if (! isset($this->aliases[ $for_class ])) {
97
-                $this->aliases[ $for_class ] = array();
96
+            if ( ! isset($this->aliases[$for_class])) {
97
+                $this->aliases[$for_class] = array();
98 98
             }
99
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
99
+            $this->aliases[$for_class][$alias] = $fqn;
100 100
             return;
101 101
         }
102
-        $this->aliases[ $alias ] = $fqn;
102
+        $this->aliases[$alias] = $fqn;
103 103
     }
104 104
 
105 105
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     protected function isDirectAlias($fqn = '')
133 133
     {
134
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
134
+        return isset($this->aliases[(string) $fqn]) && ! is_array($this->aliases[(string) $fqn]);
135 135
     }
136 136
 
137 137
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     {
147 147
         return (
148 148
             $for_class !== ''
149
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
149
+            && isset($this->aliases[(string) $for_class][(string) $fqn])
150 150
         );
151 151
     }
152 152
 
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
     {
172 172
         $alias = $this->getFqn($alias);
173 173
         if ($this->isAliasForClass($alias, $for_class)) {
174
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
174
+            return $this->getFqnForAlias($this->aliases[(string) $for_class][(string) $alias], $for_class);
175 175
         }
176 176
         if ($this->isDirectAlias($alias)) {
177
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
177
+            return $this->getFqnForAlias($this->aliases[(string) $alias], '');
178 178
         }
179 179
         return $alias;
180 180
     }
Please login to merge, or discard this patch.
core/domain/services/factories/FactoryInterface.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@
 block discarded – undo
11 11
 interface FactoryInterface
12 12
 {
13 13
 
14
-    /**
15
-     * @param mixed $arguments Either a Fully Qualified Class Name
16
-     *                         or array of data required for construction
17
-     * @return mixed
18
-     */
19
-    public static function create($arguments);
14
+	/**
15
+	 * @param mixed $arguments Either a Fully Qualified Class Name
16
+	 *                         or array of data required for construction
17
+	 * @return mixed
18
+	 */
19
+	public static function create($arguments);
20 20
 }
Please login to merge, or discard this patch.
core/domain/entities/route_match/MatchAnyRouteSpecification.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 class MatchAnyRouteSpecification extends MultiRouteSpecification
15 15
 {
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
-        foreach ($this->specifications as $specification) {
26
-            if ($specification->isMatchingRoute()) {
27
-                return true;
28
-            }
29
-        }
30
-        return false;
31
-    }
17
+	/**
18
+	 * returns true if current request matches specification
19
+	 *
20
+	 * @since $VID:$
21
+	 * @return boolean
22
+	 */
23
+	public function isMatchingRoute()
24
+	{
25
+		foreach ($this->specifications as $specification) {
26
+			if ($specification->isMatchingRoute()) {
27
+				return true;
28
+			}
29
+		}
30
+		return false;
31
+	}
32 32
 }
Please login to merge, or discard this patch.