Completed
Branch BUG-10626-dst-unit-test (cc62a6)
by
unknown
37:15 queued 23:58
created
core/services/commands/CompositeCommandHandler.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 namespace EventEspresso\core\services\commands;
4 4
 
5
-if (! defined('EVENT_ESPRESSO_VERSION')) {
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6 6
     exit('No direct script access allowed');
7 7
 }
8 8
 
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace EventEspresso\core\services\commands;
4 4
 
5 5
 if (! defined('EVENT_ESPRESSO_VERSION')) {
6
-    exit('No direct script access allowed');
6
+	exit('No direct script access allowed');
7 7
 }
8 8
 
9 9
 
@@ -21,59 +21,59 @@  discard block
 block discarded – undo
21 21
 abstract class CompositeCommandHandler extends CommandHandler
22 22
 {
23 23
 
24
-    /**
25
-     * @type CommandBusInterface $command_bus
26
-     */
27
-    private $command_bus;
24
+	/**
25
+	 * @type CommandBusInterface $command_bus
26
+	 */
27
+	private $command_bus;
28 28
 
29
-    /**
30
-     * @type CommandFactoryInterface $command_factory
31
-     */
32
-    private $command_factory;
29
+	/**
30
+	 * @type CommandFactoryInterface $command_factory
31
+	 */
32
+	private $command_factory;
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * CompositeCommandHandler constructor.
38
-     *
39
-     * @param CommandBusInterface     $command_bus
40
-     * @param CommandFactoryInterface $command_factory
41
-     */
42
-    public function __construct(CommandBusInterface $command_bus, CommandFactoryInterface $command_factory)
43
-    {
44
-        $this->command_bus = $command_bus;
45
-        $this->command_factory = $command_factory;
46
-    }
36
+	/**
37
+	 * CompositeCommandHandler constructor.
38
+	 *
39
+	 * @param CommandBusInterface     $command_bus
40
+	 * @param CommandFactoryInterface $command_factory
41
+	 */
42
+	public function __construct(CommandBusInterface $command_bus, CommandFactoryInterface $command_factory)
43
+	{
44
+		$this->command_bus = $command_bus;
45
+		$this->command_factory = $command_factory;
46
+	}
47 47
 
48 48
 
49 49
 
50
-    /**
51
-     * @param CommandBusInterface $command_bus
52
-     */
53
-    public function setCommandBus(CommandBusInterface $command_bus)
54
-    {
55
-        $this->command_bus = $command_bus;
56
-    }
50
+	/**
51
+	 * @param CommandBusInterface $command_bus
52
+	 */
53
+	public function setCommandBus(CommandBusInterface $command_bus)
54
+	{
55
+		$this->command_bus = $command_bus;
56
+	}
57 57
 
58 58
 
59 59
 
60
-    /**
61
-     * @return CommandBusInterface
62
-     */
63
-    public function commandBus()
64
-    {
65
-        return $this->command_bus;
66
-    }
60
+	/**
61
+	 * @return CommandBusInterface
62
+	 */
63
+	public function commandBus()
64
+	{
65
+		return $this->command_bus;
66
+	}
67 67
 
68 68
 
69 69
 
70
-    /**
71
-     * @return CommandFactoryInterface
72
-     */
73
-    public function commandFactory()
74
-    {
75
-        return $this->command_factory;
76
-    }
70
+	/**
71
+	 * @return CommandFactoryInterface
72
+	 */
73
+	public function commandFactory()
74
+	{
75
+		return $this->command_factory;
76
+	}
77 77
 
78 78
 
79 79
 
Please login to merge, or discard this patch.
core/domain/services/capabilities/CapabilitiesCheckerInterface.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -20,26 +20,26 @@
 block discarded – undo
20 20
 interface CapabilitiesCheckerInterface
21 21
 {
22 22
 
23
-    /**
24
-     * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO.
25
-     * If any of the individual capability checks fails, then the command will NOT be executed.
26
-     *
27
-     * @param CapCheckInterface|CapCheckInterface[] $cap_check
28
-     * @return bool
29
-     * @throws InvalidClassException
30
-     * @throws InsufficientPermissionsException
31
-     */
32
-    public function processCapCheck($cap_check);
33
-
34
-
35
-
36
-    /**
37
-     * @param string $capability - the capability to be checked, like: 'ee_edit_registrations'
38
-     * @param string $context    - what the user is attempting to do, like: 'Edit Registration'
39
-     * @param int    $ID         - (optional) ID for item where current_user_can is being called from
40
-     * @return bool
41
-     * @throws InsufficientPermissionsException
42
-     * @throws InvalidClassException
43
-     */
44
-    public function process($capability, $context, $ID = 0);
23
+	/**
24
+	 * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO.
25
+	 * If any of the individual capability checks fails, then the command will NOT be executed.
26
+	 *
27
+	 * @param CapCheckInterface|CapCheckInterface[] $cap_check
28
+	 * @return bool
29
+	 * @throws InvalidClassException
30
+	 * @throws InsufficientPermissionsException
31
+	 */
32
+	public function processCapCheck($cap_check);
33
+
34
+
35
+
36
+	/**
37
+	 * @param string $capability - the capability to be checked, like: 'ee_edit_registrations'
38
+	 * @param string $context    - what the user is attempting to do, like: 'Edit Registration'
39
+	 * @param int    $ID         - (optional) ID for item where current_user_can is being called from
40
+	 * @return bool
41
+	 * @throws InsufficientPermissionsException
42
+	 * @throws InvalidClassException
43
+	 */
44
+	public function process($capability, $context, $ID = 0);
45 45
 }
Please login to merge, or discard this patch.
core/domain/services/capabilities/CapabilitiesChecker.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\exceptions\InvalidDataTypeException;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -24,92 +24,92 @@  discard block
 block discarded – undo
24 24
 class CapabilitiesChecker implements CapabilitiesCheckerInterface
25 25
 {
26 26
 
27
-    /**
28
-     * @type EE_Capabilities $capabilities
29
-     */
30
-    private $capabilities;
31
-
32
-
33
-
34
-    /**
35
-     * CapabilitiesChecker constructor
36
-     *
37
-     * @param EE_Capabilities $capabilities
38
-     */
39
-    public function __construct(EE_Capabilities $capabilities)
40
-    {
41
-        $this->capabilities = $capabilities;
42
-    }
43
-
44
-
45
-
46
-    /**
47
-     * @return EE_Capabilities
48
-     */
49
-    protected function capabilities()
50
-    {
51
-        return $this->capabilities;
52
-    }
53
-
54
-
55
-
56
-    /**
57
-     * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO.
58
-     * If any of the individual capability checks fails, then the command will NOT be executed.
59
-     *
60
-     * @param CapCheckInterface|CapCheckInterface[] $cap_check
61
-     * @return bool
62
-     * @throws InvalidClassException
63
-     * @throws InsufficientPermissionsException
64
-     */
65
-    public function processCapCheck($cap_check)
66
-    {
67
-        if (is_array($cap_check)) {
68
-            foreach ($cap_check as $check) {
69
-                $this->processCapCheck($check);
70
-            }
71
-            return true;
72
-        }
73
-        // at this point, $cap_check should be an individual instance of CapCheck
74
-        if (! $cap_check instanceof CapCheckInterface) {
75
-            throw new InvalidClassException(
76
-                '\EventEspresso\core\domain\services\capabilities\CapCheckInterface'
77
-            );
78
-        }
79
-        // sometimes cap checks are conditional, and no capabilities are required
80
-        if ($cap_check instanceof PublicCapabilities) {
81
-            return true;
82
-        }
83
-        $capabilities = (array)$cap_check->capability();
84
-        foreach ($capabilities as $capability) {
85
-            if (
86
-            ! $this->capabilities()->current_user_can(
87
-                $capability,
88
-                $cap_check->context(),
89
-                $cap_check->ID()
90
-            )
91
-            ) {
92
-                throw new InsufficientPermissionsException($cap_check->context());
93
-            }
94
-        }
95
-        return true;
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * @param string $capability - the capability to be checked, like: 'ee_edit_registrations'
102
-     * @param string $context    - what the user is attempting to do, like: 'Edit Registration'
103
-     * @param int    $ID         - (optional) ID for item where current_user_can is being called from
104
-     * @return bool
105
-     * @throws InvalidDataTypeException
106
-     * @throws InsufficientPermissionsException
107
-     * @throws InvalidClassException
108
-     */
109
-    public function process($capability, $context, $ID = 0)
110
-    {
111
-        return $this->processCapCheck(new CapCheck($capability, $context, $ID));
112
-    }
27
+	/**
28
+	 * @type EE_Capabilities $capabilities
29
+	 */
30
+	private $capabilities;
31
+
32
+
33
+
34
+	/**
35
+	 * CapabilitiesChecker constructor
36
+	 *
37
+	 * @param EE_Capabilities $capabilities
38
+	 */
39
+	public function __construct(EE_Capabilities $capabilities)
40
+	{
41
+		$this->capabilities = $capabilities;
42
+	}
43
+
44
+
45
+
46
+	/**
47
+	 * @return EE_Capabilities
48
+	 */
49
+	protected function capabilities()
50
+	{
51
+		return $this->capabilities;
52
+	}
53
+
54
+
55
+
56
+	/**
57
+	 * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO.
58
+	 * If any of the individual capability checks fails, then the command will NOT be executed.
59
+	 *
60
+	 * @param CapCheckInterface|CapCheckInterface[] $cap_check
61
+	 * @return bool
62
+	 * @throws InvalidClassException
63
+	 * @throws InsufficientPermissionsException
64
+	 */
65
+	public function processCapCheck($cap_check)
66
+	{
67
+		if (is_array($cap_check)) {
68
+			foreach ($cap_check as $check) {
69
+				$this->processCapCheck($check);
70
+			}
71
+			return true;
72
+		}
73
+		// at this point, $cap_check should be an individual instance of CapCheck
74
+		if (! $cap_check instanceof CapCheckInterface) {
75
+			throw new InvalidClassException(
76
+				'\EventEspresso\core\domain\services\capabilities\CapCheckInterface'
77
+			);
78
+		}
79
+		// sometimes cap checks are conditional, and no capabilities are required
80
+		if ($cap_check instanceof PublicCapabilities) {
81
+			return true;
82
+		}
83
+		$capabilities = (array)$cap_check->capability();
84
+		foreach ($capabilities as $capability) {
85
+			if (
86
+			! $this->capabilities()->current_user_can(
87
+				$capability,
88
+				$cap_check->context(),
89
+				$cap_check->ID()
90
+			)
91
+			) {
92
+				throw new InsufficientPermissionsException($cap_check->context());
93
+			}
94
+		}
95
+		return true;
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * @param string $capability - the capability to be checked, like: 'ee_edit_registrations'
102
+	 * @param string $context    - what the user is attempting to do, like: 'Edit Registration'
103
+	 * @param int    $ID         - (optional) ID for item where current_user_can is being called from
104
+	 * @return bool
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InsufficientPermissionsException
107
+	 * @throws InvalidClassException
108
+	 */
109
+	public function process($capability, $context, $ID = 0)
110
+	{
111
+		return $this->processCapCheck(new CapCheck($capability, $context, $ID));
112
+	}
113 113
 
114 114
 
115 115
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\exceptions\InvalidClassException;
8 8
 use EventEspresso\core\exceptions\InvalidDataTypeException;
9 9
 
10
-if (! defined('EVENT_ESPRESSO_VERSION')) {
10
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11 11
     exit('No direct script access allowed');
12 12
 }
13 13
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             return true;
72 72
         }
73 73
         // at this point, $cap_check should be an individual instance of CapCheck
74
-        if (! $cap_check instanceof CapCheckInterface) {
74
+        if ( ! $cap_check instanceof CapCheckInterface) {
75 75
             throw new InvalidClassException(
76 76
                 '\EventEspresso\core\domain\services\capabilities\CapCheckInterface'
77 77
             );
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         if ($cap_check instanceof PublicCapabilities) {
81 81
             return true;
82 82
         }
83
-        $capabilities = (array)$cap_check->capability();
83
+        $capabilities = (array) $cap_check->capability();
84 84
         foreach ($capabilities as $capability) {
85 85
             if (
86 86
             ! $this->capabilities()->current_user_can(
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function __construct()
58 58
     {
59
-        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
59
+        espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php');
60 60
     }
61 61
 
62 62
 
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
         $this->_load_class_tools();
112 112
         // load interfaces
113 113
         espresso_load_required('EEI_Payment_Method_Interfaces',
114
-            EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
114
+            EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php');
115 115
         // deprecated functions
116
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
116
+        espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php');
117 117
         // WP cron jobs
118 118
         $this->registry->load_core('Cron_Tasks');
119 119
         $this->registry->load_core('EE_Request_Handler');
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public function dependency_map()
151 151
     {
152
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
152
+        if ( ! $this->dependency_map instanceof EE_Dependency_Map) {
153 153
             throw new EE_Error(
154 154
                 sprintf(
155 155
                     __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function registry()
170 170
     {
171
-        if (! $this->registry instanceof EE_Registry) {
171
+        if ( ! $this->registry instanceof EE_Registry) {
172 172
             throw new EE_Error(
173 173
                 sprintf(
174 174
                     __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
@@ -186,14 +186,14 @@  discard block
 block discarded – undo
186 186
      */
187 187
     private function _load_dependency_map()
188 188
     {
189
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
189
+        if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) {
190 190
             EE_Error::add_error(
191 191
                 __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
192 192
                 __FILE__, __FUNCTION__, __LINE__
193 193
             );
194 194
             wp_die(EE_Error::get_notices());
195 195
         }
196
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
196
+        require_once(EE_CORE.'EE_Dependency_Map.core.php');
197 197
         return EE_Dependency_Map::instance($this->request, $this->response);
198 198
     }
199 199
 
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
      */
205 205
     private function _load_registry()
206 206
     {
207
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
207
+        if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) {
208 208
             EE_Error::add_error(
209 209
                 __('The EE_Registry core class could not be loaded.', 'event_espresso'),
210 210
                 __FILE__, __FUNCTION__, __LINE__
211 211
             );
212 212
             wp_die(EE_Error::get_notices());
213 213
         }
214
-        require_once(EE_CORE . 'EE_Registry.core.php');
214
+        require_once(EE_CORE.'EE_Registry.core.php');
215 215
         return EE_Registry::instance($this->dependency_map);
216 216
     }
217 217
 
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
      */
223 223
     private function _load_class_tools()
224 224
     {
225
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
225
+        if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) {
226 226
             EE_Error::add_error(
227 227
                 __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
228 228
                 __FILE__, __FUNCTION__, __LINE__
229 229
             );
230 230
         }
231
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
231
+        require_once(EE_HELPERS.'EEH_Class_Tools.helper.php');
232 232
     }
233 233
 
234 234
 
Please login to merge, or discard this patch.
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -24,228 +24,228 @@  discard block
 block discarded – undo
24 24
 class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App
25 25
 {
26 26
 
27
-    /**
28
-     * @type LoaderInterface $loader
29
-     */
30
-    protected $loader;
31
-
32
-    /**
33
-     * @var EE_Request $request
34
-     */
35
-    protected $request;
36
-
37
-    /**
38
-     * @var EE_Response $response
39
-     */
40
-    protected $response;
41
-
42
-    /**
43
-     * @var EE_Dependency_Map $dependency_map
44
-     */
45
-    protected $dependency_map;
46
-
47
-    /**
48
-     * @var EE_Registry $registry
49
-     */
50
-    protected $registry;
51
-
52
-
53
-
54
-    /**
55
-     * EE_Load_Espresso_Core constructor
56
-     */
57
-    public function __construct()
58
-    {
59
-        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * handle
66
-     * sets hooks for running rest of system
67
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
68
-     * starting EE Addons from any other point may lead to problems
69
-     *
70
-     * @param EE_Request  $request
71
-     * @param EE_Response $response
72
-     * @return EE_Response
73
-     * @throws EE_Error
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidInterfaceException
76
-     * @throws InvalidArgumentException
77
-     */
78
-    public function handle_request(EE_Request $request, EE_Response $response)
79
-    {
80
-        $this->request = $request;
81
-        $this->response = $response;
82
-        // info about how to load classes required by other classes
83
-        $this->dependency_map = $this->_load_dependency_map();
84
-        // central repository for classes
85
-        $this->registry = $this->_load_registry();
86
-        // PSR4 Autoloaders
87
-        $this->registry->load_core('EE_Psr4AutoloaderInit');
88
-        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
89
-        $this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader');
90
-        $this->dependency_map->setLoader($this->loader);
91
-        // build DI container
92
-        $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
93
-        $OpenCoffeeShop->addRecipes();
94
-        // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
95
-        // create and cache the CommandBus, and also add middleware
96
-        $this->registry->create(
97
-            'CommandBusInterface',
98
-            array(
99
-                null,
100
-                apply_filters(
101
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
102
-                    array(
103
-                        $this->registry->create('CapChecker'),
104
-                        $this->registry->create('AddActionHook'),
105
-                    )
106
-                ),
107
-            ),
108
-            true
109
-        );
110
-        // workarounds for PHP < 5.3
111
-        $this->_load_class_tools();
112
-        // load interfaces
113
-        espresso_load_required('EEI_Payment_Method_Interfaces',
114
-            EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
115
-        // deprecated functions
116
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
117
-        // WP cron jobs
118
-        $this->registry->load_core('Cron_Tasks');
119
-        $this->registry->load_core('EE_Request_Handler');
120
-        $this->registry->load_core('EE_System');
121
-        return $this->response;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @return EE_Request
128
-     */
129
-    public function request()
130
-    {
131
-        return $this->request;
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     * @return EE_Response
138
-     */
139
-    public function response()
140
-    {
141
-        return $this->response;
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * @return EE_Dependency_Map
148
-     * @throws EE_Error
149
-     */
150
-    public function dependency_map()
151
-    {
152
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
153
-            throw new EE_Error(
154
-                sprintf(
155
-                    __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
156
-                    print_r($this->dependency_map, true)
157
-                )
158
-            );
159
-        }
160
-        return $this->dependency_map;
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * @return EE_Registry
167
-     * @throws EE_Error
168
-     */
169
-    public function registry()
170
-    {
171
-        if (! $this->registry instanceof EE_Registry) {
172
-            throw new EE_Error(
173
-                sprintf(
174
-                    __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
175
-                    print_r($this->registry, true)
176
-                )
177
-            );
178
-        }
179
-        return $this->registry;
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * @return EE_Dependency_Map
186
-     */
187
-    private function _load_dependency_map()
188
-    {
189
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
190
-            EE_Error::add_error(
191
-                __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
192
-                __FILE__, __FUNCTION__, __LINE__
193
-            );
194
-            wp_die(EE_Error::get_notices());
195
-        }
196
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
197
-        return EE_Dependency_Map::instance($this->request, $this->response);
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * @return EE_Registry
204
-     */
205
-    private function _load_registry()
206
-    {
207
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
208
-            EE_Error::add_error(
209
-                __('The EE_Registry core class could not be loaded.', 'event_espresso'),
210
-                __FILE__, __FUNCTION__, __LINE__
211
-            );
212
-            wp_die(EE_Error::get_notices());
213
-        }
214
-        require_once(EE_CORE . 'EE_Registry.core.php');
215
-        return EE_Registry::instance($this->dependency_map);
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * @return void
222
-     */
223
-    private function _load_class_tools()
224
-    {
225
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
226
-            EE_Error::add_error(
227
-                __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
228
-                __FILE__, __FUNCTION__, __LINE__
229
-            );
230
-        }
231
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * called after the request stack has been fully processed
238
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
239
-     *
240
-     * @param EE_Request  $request
241
-     * @param EE_Response $response
242
-     */
243
-    public function handle_response(EE_Request $request, EE_Response $response)
244
-    {
245
-        if ($response->plugin_deactivated()) {
246
-            espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
247
-        }
248
-    }
27
+	/**
28
+	 * @type LoaderInterface $loader
29
+	 */
30
+	protected $loader;
31
+
32
+	/**
33
+	 * @var EE_Request $request
34
+	 */
35
+	protected $request;
36
+
37
+	/**
38
+	 * @var EE_Response $response
39
+	 */
40
+	protected $response;
41
+
42
+	/**
43
+	 * @var EE_Dependency_Map $dependency_map
44
+	 */
45
+	protected $dependency_map;
46
+
47
+	/**
48
+	 * @var EE_Registry $registry
49
+	 */
50
+	protected $registry;
51
+
52
+
53
+
54
+	/**
55
+	 * EE_Load_Espresso_Core constructor
56
+	 */
57
+	public function __construct()
58
+	{
59
+		espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * handle
66
+	 * sets hooks for running rest of system
67
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
68
+	 * starting EE Addons from any other point may lead to problems
69
+	 *
70
+	 * @param EE_Request  $request
71
+	 * @param EE_Response $response
72
+	 * @return EE_Response
73
+	 * @throws EE_Error
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidInterfaceException
76
+	 * @throws InvalidArgumentException
77
+	 */
78
+	public function handle_request(EE_Request $request, EE_Response $response)
79
+	{
80
+		$this->request = $request;
81
+		$this->response = $response;
82
+		// info about how to load classes required by other classes
83
+		$this->dependency_map = $this->_load_dependency_map();
84
+		// central repository for classes
85
+		$this->registry = $this->_load_registry();
86
+		// PSR4 Autoloaders
87
+		$this->registry->load_core('EE_Psr4AutoloaderInit');
88
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
89
+		$this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader');
90
+		$this->dependency_map->setLoader($this->loader);
91
+		// build DI container
92
+		$OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
93
+		$OpenCoffeeShop->addRecipes();
94
+		// $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
95
+		// create and cache the CommandBus, and also add middleware
96
+		$this->registry->create(
97
+			'CommandBusInterface',
98
+			array(
99
+				null,
100
+				apply_filters(
101
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
102
+					array(
103
+						$this->registry->create('CapChecker'),
104
+						$this->registry->create('AddActionHook'),
105
+					)
106
+				),
107
+			),
108
+			true
109
+		);
110
+		// workarounds for PHP < 5.3
111
+		$this->_load_class_tools();
112
+		// load interfaces
113
+		espresso_load_required('EEI_Payment_Method_Interfaces',
114
+			EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
115
+		// deprecated functions
116
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
117
+		// WP cron jobs
118
+		$this->registry->load_core('Cron_Tasks');
119
+		$this->registry->load_core('EE_Request_Handler');
120
+		$this->registry->load_core('EE_System');
121
+		return $this->response;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @return EE_Request
128
+	 */
129
+	public function request()
130
+	{
131
+		return $this->request;
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 * @return EE_Response
138
+	 */
139
+	public function response()
140
+	{
141
+		return $this->response;
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * @return EE_Dependency_Map
148
+	 * @throws EE_Error
149
+	 */
150
+	public function dependency_map()
151
+	{
152
+		if (! $this->dependency_map instanceof EE_Dependency_Map) {
153
+			throw new EE_Error(
154
+				sprintf(
155
+					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
156
+					print_r($this->dependency_map, true)
157
+				)
158
+			);
159
+		}
160
+		return $this->dependency_map;
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * @return EE_Registry
167
+	 * @throws EE_Error
168
+	 */
169
+	public function registry()
170
+	{
171
+		if (! $this->registry instanceof EE_Registry) {
172
+			throw new EE_Error(
173
+				sprintf(
174
+					__('Invalid EE_Registry: "%1$s"', 'event_espresso'),
175
+					print_r($this->registry, true)
176
+				)
177
+			);
178
+		}
179
+		return $this->registry;
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * @return EE_Dependency_Map
186
+	 */
187
+	private function _load_dependency_map()
188
+	{
189
+		if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
190
+			EE_Error::add_error(
191
+				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
192
+				__FILE__, __FUNCTION__, __LINE__
193
+			);
194
+			wp_die(EE_Error::get_notices());
195
+		}
196
+		require_once(EE_CORE . 'EE_Dependency_Map.core.php');
197
+		return EE_Dependency_Map::instance($this->request, $this->response);
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * @return EE_Registry
204
+	 */
205
+	private function _load_registry()
206
+	{
207
+		if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
208
+			EE_Error::add_error(
209
+				__('The EE_Registry core class could not be loaded.', 'event_espresso'),
210
+				__FILE__, __FUNCTION__, __LINE__
211
+			);
212
+			wp_die(EE_Error::get_notices());
213
+		}
214
+		require_once(EE_CORE . 'EE_Registry.core.php');
215
+		return EE_Registry::instance($this->dependency_map);
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * @return void
222
+	 */
223
+	private function _load_class_tools()
224
+	{
225
+		if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
226
+			EE_Error::add_error(
227
+				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
228
+				__FILE__, __FUNCTION__, __LINE__
229
+			);
230
+		}
231
+		require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * called after the request stack has been fully processed
238
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
239
+	 *
240
+	 * @param EE_Request  $request
241
+	 * @param EE_Response $response
242
+	 */
243
+	public function handle_response(EE_Request $request, EE_Response $response)
244
+	{
245
+		if ($response->plugin_deactivated()) {
246
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
247
+		}
248
+	}
249 249
 
250 250
 
251 251
 
Please login to merge, or discard this patch.
core/services/commands/CommandBus.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\commands\middleware\CommandBusMiddlewareInterface;
7 7
 use EventEspresso\core\services\commands\middleware\InvalidCommandBusMiddlewareException;
8 8
 
9
-if (! defined('EVENT_ESPRESSO_VERSION')) {
9
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10 10
     exit('No direct script access allowed');
11 11
 }
12 12
 
@@ -88,24 +88,24 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public function execute($command)
90 90
     {
91
-        if (! $command instanceof CommandInterface) {
92
-            throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface');
91
+        if ( ! $command instanceof CommandInterface) {
92
+            throw new InvalidDataTypeException(__METHOD__.'( $command )', $command, 'CommandInterface');
93 93
         }
94 94
         // we're going to add the Command Handler as a callable
95 95
         // that will get run at the end of our middleware stack
96 96
         // can't pass $this to a Closure, so use a named variable
97 97
         $command_bus = $this;
98
-        $middleware = function ($command) use ($command_bus) {
98
+        $middleware = function($command) use ($command_bus) {
99 99
             return $command_bus->getCommandHandlerManager()
100 100
                 ->getCommandHandler($command, $command_bus)
101 101
                 ->handle($command);
102 102
         };
103 103
         // now build the rest of the middleware stack
104 104
         while ($command_bus_middleware = array_pop($this->command_bus_middleware)) {
105
-            if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) {
105
+            if ( ! $command_bus_middleware instanceof CommandBusMiddlewareInterface) {
106 106
                 throw new InvalidCommandBusMiddlewareException($command_bus_middleware);
107 107
             }
108
-            $middleware = function ($command) use ($command_bus_middleware, $middleware) {
108
+            $middleware = function($command) use ($command_bus_middleware, $middleware) {
109 109
                 return $command_bus_middleware->handle($command, $middleware);
110 110
             };
111 111
         }
Please login to merge, or discard this patch.
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\services\commands\middleware\InvalidCommandBusMiddlewareException;
8 8
 
9 9
 if (! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 
@@ -40,78 +40,78 @@  discard block
 block discarded – undo
40 40
 class CommandBus implements CommandBusInterface
41 41
 {
42 42
 
43
-    /**
44
-     * @type CommandHandlerManagerInterface $command_handler_manager
45
-     */
46
-    private $command_handler_manager;
47
-
48
-    /**
49
-     * @type CommandBusMiddlewareInterface[] $command_bus_middleware
50
-     */
51
-    private $command_bus_middleware;
52
-
53
-
54
-
55
-    /**
56
-     * CommandBus constructor
57
-     *
58
-     * @param CommandHandlerManagerInterface  $command_handler_manager
59
-     * @param CommandBusMiddlewareInterface[] $command_bus_middleware
60
-     */
61
-    public function __construct(
62
-        CommandHandlerManagerInterface $command_handler_manager,
63
-        array $command_bus_middleware = array()
64
-    ) {
65
-        $this->command_handler_manager = $command_handler_manager;
66
-        $this->command_bus_middleware = is_array($command_bus_middleware)
67
-            ? $command_bus_middleware
68
-            : array($command_bus_middleware);
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * @return CommandHandlerManagerInterface
75
-     */
76
-    public function getCommandHandlerManager()
77
-    {
78
-        return $this->command_handler_manager;
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     * @param CommandInterface $command
85
-     * @return mixed
86
-     * @throws InvalidDataTypeException
87
-     * @throws InvalidCommandBusMiddlewareException
88
-     */
89
-    public function execute($command)
90
-    {
91
-        if (! $command instanceof CommandInterface) {
92
-            throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface');
93
-        }
94
-        // we're going to add the Command Handler as a callable
95
-        // that will get run at the end of our middleware stack
96
-        // can't pass $this to a Closure, so use a named variable
97
-        $command_bus = $this;
98
-        $middleware = function ($command) use ($command_bus) {
99
-            return $command_bus->getCommandHandlerManager()
100
-                ->getCommandHandler($command, $command_bus)
101
-                ->handle($command);
102
-        };
103
-        // now build the rest of the middleware stack
104
-        while ($command_bus_middleware = array_pop($this->command_bus_middleware)) {
105
-            if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) {
106
-                throw new InvalidCommandBusMiddlewareException($command_bus_middleware);
107
-            }
108
-            $middleware = function ($command) use ($command_bus_middleware, $middleware) {
109
-                return $command_bus_middleware->handle($command, $middleware);
110
-            };
111
-        }
112
-        // and finally, pass the command into the stack and return the results
113
-        return $middleware($command);
114
-    }
43
+	/**
44
+	 * @type CommandHandlerManagerInterface $command_handler_manager
45
+	 */
46
+	private $command_handler_manager;
47
+
48
+	/**
49
+	 * @type CommandBusMiddlewareInterface[] $command_bus_middleware
50
+	 */
51
+	private $command_bus_middleware;
52
+
53
+
54
+
55
+	/**
56
+	 * CommandBus constructor
57
+	 *
58
+	 * @param CommandHandlerManagerInterface  $command_handler_manager
59
+	 * @param CommandBusMiddlewareInterface[] $command_bus_middleware
60
+	 */
61
+	public function __construct(
62
+		CommandHandlerManagerInterface $command_handler_manager,
63
+		array $command_bus_middleware = array()
64
+	) {
65
+		$this->command_handler_manager = $command_handler_manager;
66
+		$this->command_bus_middleware = is_array($command_bus_middleware)
67
+			? $command_bus_middleware
68
+			: array($command_bus_middleware);
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * @return CommandHandlerManagerInterface
75
+	 */
76
+	public function getCommandHandlerManager()
77
+	{
78
+		return $this->command_handler_manager;
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 * @param CommandInterface $command
85
+	 * @return mixed
86
+	 * @throws InvalidDataTypeException
87
+	 * @throws InvalidCommandBusMiddlewareException
88
+	 */
89
+	public function execute($command)
90
+	{
91
+		if (! $command instanceof CommandInterface) {
92
+			throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface');
93
+		}
94
+		// we're going to add the Command Handler as a callable
95
+		// that will get run at the end of our middleware stack
96
+		// can't pass $this to a Closure, so use a named variable
97
+		$command_bus = $this;
98
+		$middleware = function ($command) use ($command_bus) {
99
+			return $command_bus->getCommandHandlerManager()
100
+				->getCommandHandler($command, $command_bus)
101
+				->handle($command);
102
+		};
103
+		// now build the rest of the middleware stack
104
+		while ($command_bus_middleware = array_pop($this->command_bus_middleware)) {
105
+			if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) {
106
+				throw new InvalidCommandBusMiddlewareException($command_bus_middleware);
107
+			}
108
+			$middleware = function ($command) use ($command_bus_middleware, $middleware) {
109
+				return $command_bus_middleware->handle($command, $middleware);
110
+			};
111
+		}
112
+		// and finally, pass the command into the stack and return the results
113
+		return $middleware($command);
114
+	}
115 115
 
116 116
 
117 117
 }
Please login to merge, or discard this patch.
core/services/commands/CommandFactory.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,40 +24,40 @@
 block discarded – undo
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     * @var LoaderInterface $loader
29
-     */
30
-    private $loader;
31
-
32
-
33
-
34
-    /**
35
-     * CommandFactory constructor
36
-     *
37
-     * @param LoaderInterface $loader
38
-     * @throws InvalidDataTypeException
39
-     * @throws InvalidInterfaceException
40
-     * @throws InvalidArgumentException
41
-     */
42
-    public function __construct(LoaderInterface $loader = null)
43
-    {
44
-       $this->loader = $loader;
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * @param string $command_fqcn
51
-     * @param array  $arguments
52
-     * @return mixed
53
-     * @throws InvalidArgumentException
54
-     * @throws InvalidDataTypeException
55
-     * @throws InvalidInterfaceException
56
-     */
57
-    public function getNew($command_fqcn, $arguments = array())
58
-    {
59
-        return $this->loader->getNew($command_fqcn, $arguments);
60
-    }
27
+	/**
28
+	 * @var LoaderInterface $loader
29
+	 */
30
+	private $loader;
31
+
32
+
33
+
34
+	/**
35
+	 * CommandFactory constructor
36
+	 *
37
+	 * @param LoaderInterface $loader
38
+	 * @throws InvalidDataTypeException
39
+	 * @throws InvalidInterfaceException
40
+	 * @throws InvalidArgumentException
41
+	 */
42
+	public function __construct(LoaderInterface $loader = null)
43
+	{
44
+	   $this->loader = $loader;
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * @param string $command_fqcn
51
+	 * @param array  $arguments
52
+	 * @return mixed
53
+	 * @throws InvalidArgumentException
54
+	 * @throws InvalidDataTypeException
55
+	 * @throws InvalidInterfaceException
56
+	 */
57
+	public function getNew($command_fqcn, $arguments = array())
58
+	{
59
+		return $this->loader->getNew($command_fqcn, $arguments);
60
+	}
61 61
 
62 62
 
63 63
 
Please login to merge, or discard this patch.
core/services/commands/CommandFactoryInterface.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@
 block discarded – undo
13 13
 interface CommandFactoryInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @param string $command_fqcn
18
-     * @param array  $arguments
19
-     * @return mixed
20
-     * @throws InvalidArgumentException
21
-     * @throws InvalidDataTypeException
22
-     * @throws InvalidInterfaceException
23
-     */
24
-    public function getNew($command_fqcn, $arguments = array());
16
+	/**
17
+	 * @param string $command_fqcn
18
+	 * @param array  $arguments
19
+	 * @return mixed
20
+	 * @throws InvalidArgumentException
21
+	 * @throws InvalidDataTypeException
22
+	 * @throws InvalidInterfaceException
23
+	 */
24
+	public function getNew($command_fqcn, $arguments = array());
25 25
 
26 26
 }
27 27
 // End of file CommandFactoryInterface.php
Please login to merge, or discard this patch.
core/services/commands/CommandHandlerManager.php 2 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\loaders\LoaderInterface;
7 7
 
8 8
 if (! defined('EVENT_ESPRESSO_VERSION')) {
9
-    exit('No direct script access allowed');
9
+	exit('No direct script access allowed');
10 10
 }
11 11
 
12 12
 
@@ -24,109 +24,109 @@  discard block
 block discarded – undo
24 24
 class CommandHandlerManager implements CommandHandlerManagerInterface
25 25
 {
26 26
 
27
-    /**
28
-     * @var CommandHandlerInterface[] $command_handlers
29
-     */
30
-    protected $command_handlers;
31
-
32
-    /**
33
-     * @type LoaderInterface $loader
34
-     */
35
-    private $loader;
36
-
37
-
38
-
39
-    /**
40
-     * CommandHandlerManager constructor
41
-     *
42
-     * @param LoaderInterface $loader
43
-     */
44
-    public function __construct(LoaderInterface $loader)
45
-    {
46
-        $this->loader = $loader;
47
-    }
48
-
49
-
50
-
51
-    /**
52
-     * By default, Commands and CommandHandlers would normally
53
-     * reside in the same folder under the same namespace,
54
-     * and the names of the two classes would only differ in that
55
-     * one ends in "Command" and the other ends in "CommandHandler".
56
-     * However, if you wanted to utilize a CommandHandler from somewhere else,
57
-     * then this method allows you to add that CommandHandler and specify the FQCN
58
-     * (Fully Qualified ClassName) for the Command class that it should be used for.
59
-     * For example:
60
-     *      by default the "Vendor\some\namespace\DoSomethingCommand"
61
-     *      would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler"
62
-     *      but if you wanted to instead process that commend using:
63
-     *      "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler"
64
-     *      then the following code:
65
-     *      $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' );
66
-     *      $CommandHandlerManager->addCommandHandler(
67
-     *          new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(),
68
-     *          'Vendor\some\namespace\DoSomethingCommand'
69
-     *      );
70
-     *      would result in the alternate CommandHandler being used to process that Command
71
-     *
72
-     * @param CommandHandlerInterface $command_handler
73
-     * @param string                  $fqcn_for_command Fully Qualified ClassName for Command
74
-     * @return void
75
-     * @throws InvalidCommandHandlerException
76
-     */
77
-    public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '')
78
-    {
79
-        $command = ! empty($fqcn_for_command)
80
-            ? $fqcn_for_command
81
-            : str_replace('CommandHandler', 'Command', get_class($command_handler));
82
-        if (empty($command)) {
83
-            throw new InvalidCommandHandlerException($command);
84
-        }
85
-        $this->command_handlers[$command] = $command_handler;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * @param CommandInterface $command
92
-     * @param CommandBusInterface       $command_bus
93
-     * @return mixed
94
-     * @throws DomainException
95
-     * @throws CommandHandlerNotFoundException
96
-     */
97
-    public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null)
98
-    {
99
-        $command_name = get_class($command);
100
-        $command_handler = apply_filters(
101
-            'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler',
102
-            str_replace('Command', 'CommandHandler', $command_name),
103
-            $command
104
-        );
105
-        $handler = null;
106
-        // has a command handler already been set for this class ?
107
-        // if not, can we find one via the FQCN ?
108
-        if (isset($this->command_handlers[$command_name])) {
109
-            $handler = $this->command_handlers[$command_name];
110
-        } else if (class_exists($command_handler)) {
111
-            $handler = $this->loader->getShared($command_handler);
112
-        }
113
-        // if Handler requires an instance of the CommandBus, but that has not yet been set
114
-        if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) {
115
-            if (! $command_bus instanceof CommandBusInterface) {
116
-                throw new DomainException(
117
-                    esc_html__(
118
-                        'CompositeCommandHandler classes require an instance of the CommandBus.',
119
-                        'event_espresso'
120
-                    )
121
-                );
122
-            }
123
-            $handler->setCommandBus($command_bus);
124
-        }
125
-        if ($handler instanceof CommandHandlerInterface) {
126
-            return $handler;
127
-        }
128
-        throw new CommandHandlerNotFoundException($command_handler);
129
-    }
27
+	/**
28
+	 * @var CommandHandlerInterface[] $command_handlers
29
+	 */
30
+	protected $command_handlers;
31
+
32
+	/**
33
+	 * @type LoaderInterface $loader
34
+	 */
35
+	private $loader;
36
+
37
+
38
+
39
+	/**
40
+	 * CommandHandlerManager constructor
41
+	 *
42
+	 * @param LoaderInterface $loader
43
+	 */
44
+	public function __construct(LoaderInterface $loader)
45
+	{
46
+		$this->loader = $loader;
47
+	}
48
+
49
+
50
+
51
+	/**
52
+	 * By default, Commands and CommandHandlers would normally
53
+	 * reside in the same folder under the same namespace,
54
+	 * and the names of the two classes would only differ in that
55
+	 * one ends in "Command" and the other ends in "CommandHandler".
56
+	 * However, if you wanted to utilize a CommandHandler from somewhere else,
57
+	 * then this method allows you to add that CommandHandler and specify the FQCN
58
+	 * (Fully Qualified ClassName) for the Command class that it should be used for.
59
+	 * For example:
60
+	 *      by default the "Vendor\some\namespace\DoSomethingCommand"
61
+	 *      would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler"
62
+	 *      but if you wanted to instead process that commend using:
63
+	 *      "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler"
64
+	 *      then the following code:
65
+	 *      $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' );
66
+	 *      $CommandHandlerManager->addCommandHandler(
67
+	 *          new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(),
68
+	 *          'Vendor\some\namespace\DoSomethingCommand'
69
+	 *      );
70
+	 *      would result in the alternate CommandHandler being used to process that Command
71
+	 *
72
+	 * @param CommandHandlerInterface $command_handler
73
+	 * @param string                  $fqcn_for_command Fully Qualified ClassName for Command
74
+	 * @return void
75
+	 * @throws InvalidCommandHandlerException
76
+	 */
77
+	public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '')
78
+	{
79
+		$command = ! empty($fqcn_for_command)
80
+			? $fqcn_for_command
81
+			: str_replace('CommandHandler', 'Command', get_class($command_handler));
82
+		if (empty($command)) {
83
+			throw new InvalidCommandHandlerException($command);
84
+		}
85
+		$this->command_handlers[$command] = $command_handler;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * @param CommandInterface $command
92
+	 * @param CommandBusInterface       $command_bus
93
+	 * @return mixed
94
+	 * @throws DomainException
95
+	 * @throws CommandHandlerNotFoundException
96
+	 */
97
+	public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null)
98
+	{
99
+		$command_name = get_class($command);
100
+		$command_handler = apply_filters(
101
+			'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler',
102
+			str_replace('Command', 'CommandHandler', $command_name),
103
+			$command
104
+		);
105
+		$handler = null;
106
+		// has a command handler already been set for this class ?
107
+		// if not, can we find one via the FQCN ?
108
+		if (isset($this->command_handlers[$command_name])) {
109
+			$handler = $this->command_handlers[$command_name];
110
+		} else if (class_exists($command_handler)) {
111
+			$handler = $this->loader->getShared($command_handler);
112
+		}
113
+		// if Handler requires an instance of the CommandBus, but that has not yet been set
114
+		if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) {
115
+			if (! $command_bus instanceof CommandBusInterface) {
116
+				throw new DomainException(
117
+					esc_html__(
118
+						'CompositeCommandHandler classes require an instance of the CommandBus.',
119
+						'event_espresso'
120
+					)
121
+				);
122
+			}
123
+			$handler->setCommandBus($command_bus);
124
+		}
125
+		if ($handler instanceof CommandHandlerInterface) {
126
+			return $handler;
127
+		}
128
+		throw new CommandHandlerNotFoundException($command_handler);
129
+	}
130 130
 
131 131
 
132 132
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use DomainException;
6 6
 use EventEspresso\core\services\loaders\LoaderInterface;
7 7
 
8
-if (! defined('EVENT_ESPRESSO_VERSION')) {
8
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
9 9
     exit('No direct script access allowed');
10 10
 }
11 11
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         }
113 113
         // if Handler requires an instance of the CommandBus, but that has not yet been set
114 114
         if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) {
115
-            if (! $command_bus instanceof CommandBusInterface) {
115
+            if ( ! $command_bus instanceof CommandBusInterface) {
116 116
                 throw new DomainException(
117 117
                     esc_html__(
118 118
                         'CompositeCommandHandler classes require an instance of the CommandBus.',
Please login to merge, or discard this patch.
core/services/loaders/Loader.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -24,140 +24,140 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * @var LoaderDecoratorInterface $new_loader
29
-     */
30
-    private $new_loader;
31
-
32
-
33
-    /**
34
-     * @var LoaderDecoratorInterface $shared_loader
35
-     */
36
-    private $shared_loader;
37
-
38
-
39
-
40
-    /**
41
-     * Loader constructor.
42
-     *
43
-     * @param LoaderDecoratorInterface|null $new_loader
44
-     * @param LoaderDecoratorInterface|null $shared_loader
45
-     * @throws InvalidInterfaceException
46
-     * @throws InvalidArgumentException
47
-     * @throws InvalidDataTypeException
48
-     */
49
-    public function __construct(LoaderDecoratorInterface $new_loader = null, LoaderDecoratorInterface $shared_loader = null)
50
-    {
51
-        $this->new_loader = $this->setupNewLoader($new_loader);
52
-        $this->shared_loader = $this->setupSharedLoader($shared_loader);
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * @param LoaderDecoratorInterface|null $new_loader
59
-     * @return CoreLoader|LoaderDecoratorInterface
60
-     * @throws InvalidArgumentException
61
-     */
62
-    private function setupNewLoader(LoaderDecoratorInterface $new_loader = null)
63
-    {
64
-        // if not already generated, create a standard loader
65
-        if (! $new_loader instanceof LoaderDecoratorInterface) {
66
-            $new_loader = new CoreLoader(EE_Registry::instance());
67
-        }
68
-        return $new_loader;
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * @param LoaderDecoratorInterface|null $shared_loader
75
-     * @return CoreLoader|LoaderDecoratorInterface
76
-     * @throws InvalidDataTypeException
77
-     * @throws InvalidInterfaceException
78
-     * @throws InvalidArgumentException
79
-     */
80
-    private function setupSharedLoader(LoaderDecoratorInterface $shared_loader = null)
81
-    {
82
-        // if not already generated, create a caching loader
83
-        if (! $shared_loader instanceof LoaderDecoratorInterface) {
84
-            $shared_loader = new CachingLoader(
85
-                new CoreLoader(EE_Registry::instance()),
86
-                new LooseCollection('')
87
-            );
88
-        }
89
-        return $shared_loader;
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * @return LoaderDecoratorInterface
96
-     */
97
-    public function getNewLoader()
98
-    {
99
-        return $this->new_loader;
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * @return LoaderDecoratorInterface
106
-     */
107
-    public function getSharedLoader()
108
-    {
109
-        return $this->shared_loader;
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * @param string $fqcn
116
-     * @param array  $arguments
117
-     * @param bool   $shared
118
-     * @return mixed
119
-     */
120
-    public function load($fqcn, $arguments = array(), $shared = true)
121
-    {
122
-        return $shared
123
-            ? $this->getSharedLoader()->load($fqcn, $arguments)
124
-            : $this->getNewLoader()->load($fqcn, $arguments);
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     * @param string $fqcn
131
-     * @param array  $arguments
132
-     * @return mixed
133
-     */
134
-    public function getNew($fqcn, $arguments = array())
135
-    {
136
-        return $this->getNewLoader()->load($fqcn, $arguments);
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     * @param string $fqcn
143
-     * @param array  $arguments
144
-     * @return mixed
145
-     */
146
-    public function getShared($fqcn, $arguments = array())
147
-    {
148
-        return $this->getSharedLoader()->load($fqcn, $arguments);
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * calls reset() on loaders if that method exists
155
-     */
156
-    public function reset()
157
-    {
158
-        $this->new_loader->reset();
159
-        $this->shared_loader->reset();
160
-    }
27
+	/**
28
+	 * @var LoaderDecoratorInterface $new_loader
29
+	 */
30
+	private $new_loader;
31
+
32
+
33
+	/**
34
+	 * @var LoaderDecoratorInterface $shared_loader
35
+	 */
36
+	private $shared_loader;
37
+
38
+
39
+
40
+	/**
41
+	 * Loader constructor.
42
+	 *
43
+	 * @param LoaderDecoratorInterface|null $new_loader
44
+	 * @param LoaderDecoratorInterface|null $shared_loader
45
+	 * @throws InvalidInterfaceException
46
+	 * @throws InvalidArgumentException
47
+	 * @throws InvalidDataTypeException
48
+	 */
49
+	public function __construct(LoaderDecoratorInterface $new_loader = null, LoaderDecoratorInterface $shared_loader = null)
50
+	{
51
+		$this->new_loader = $this->setupNewLoader($new_loader);
52
+		$this->shared_loader = $this->setupSharedLoader($shared_loader);
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * @param LoaderDecoratorInterface|null $new_loader
59
+	 * @return CoreLoader|LoaderDecoratorInterface
60
+	 * @throws InvalidArgumentException
61
+	 */
62
+	private function setupNewLoader(LoaderDecoratorInterface $new_loader = null)
63
+	{
64
+		// if not already generated, create a standard loader
65
+		if (! $new_loader instanceof LoaderDecoratorInterface) {
66
+			$new_loader = new CoreLoader(EE_Registry::instance());
67
+		}
68
+		return $new_loader;
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * @param LoaderDecoratorInterface|null $shared_loader
75
+	 * @return CoreLoader|LoaderDecoratorInterface
76
+	 * @throws InvalidDataTypeException
77
+	 * @throws InvalidInterfaceException
78
+	 * @throws InvalidArgumentException
79
+	 */
80
+	private function setupSharedLoader(LoaderDecoratorInterface $shared_loader = null)
81
+	{
82
+		// if not already generated, create a caching loader
83
+		if (! $shared_loader instanceof LoaderDecoratorInterface) {
84
+			$shared_loader = new CachingLoader(
85
+				new CoreLoader(EE_Registry::instance()),
86
+				new LooseCollection('')
87
+			);
88
+		}
89
+		return $shared_loader;
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * @return LoaderDecoratorInterface
96
+	 */
97
+	public function getNewLoader()
98
+	{
99
+		return $this->new_loader;
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * @return LoaderDecoratorInterface
106
+	 */
107
+	public function getSharedLoader()
108
+	{
109
+		return $this->shared_loader;
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * @param string $fqcn
116
+	 * @param array  $arguments
117
+	 * @param bool   $shared
118
+	 * @return mixed
119
+	 */
120
+	public function load($fqcn, $arguments = array(), $shared = true)
121
+	{
122
+		return $shared
123
+			? $this->getSharedLoader()->load($fqcn, $arguments)
124
+			: $this->getNewLoader()->load($fqcn, $arguments);
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 * @param string $fqcn
131
+	 * @param array  $arguments
132
+	 * @return mixed
133
+	 */
134
+	public function getNew($fqcn, $arguments = array())
135
+	{
136
+		return $this->getNewLoader()->load($fqcn, $arguments);
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 * @param string $fqcn
143
+	 * @param array  $arguments
144
+	 * @return mixed
145
+	 */
146
+	public function getShared($fqcn, $arguments = array())
147
+	{
148
+		return $this->getSharedLoader()->load($fqcn, $arguments);
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * calls reset() on loaders if that method exists
155
+	 */
156
+	public function reset()
157
+	{
158
+		$this->new_loader->reset();
159
+		$this->shared_loader->reset();
160
+	}
161 161
 
162 162
 }
163 163
 // End of file Loader.php
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     private function setupNewLoader(LoaderDecoratorInterface $new_loader = null)
63 63
     {
64 64
         // if not already generated, create a standard loader
65
-        if (! $new_loader instanceof LoaderDecoratorInterface) {
65
+        if ( ! $new_loader instanceof LoaderDecoratorInterface) {
66 66
             $new_loader = new CoreLoader(EE_Registry::instance());
67 67
         }
68 68
         return $new_loader;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     private function setupSharedLoader(LoaderDecoratorInterface $shared_loader = null)
81 81
     {
82 82
         // if not already generated, create a caching loader
83
-        if (! $shared_loader instanceof LoaderDecoratorInterface) {
83
+        if ( ! $shared_loader instanceof LoaderDecoratorInterface) {
84 84
             $shared_loader = new CachingLoader(
85 85
                 new CoreLoader(EE_Registry::instance()),
86 86
                 new LooseCollection('')
Please login to merge, or discard this patch.