Completed
Branch FET-10416-autoload-b4-bootstra... (42a01c)
by
unknown
13:17
created
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/services/commands/CommandBus.php 2 patches
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
-        $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
+		$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.
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.
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.
core/services/loaders/LoaderDecoratorInterface.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
 interface LoaderDecoratorInterface
10 10
 {
11 11
 
12
-    /**
13
-     * @param string $fqcn
14
-     * @param array  $arguments
15
-     * @return mixed
16
-     */
17
-    public function load($fqcn, $arguments = array());
12
+	/**
13
+	 * @param string $fqcn
14
+	 * @param array  $arguments
15
+	 * @return mixed
16
+	 */
17
+	public function load($fqcn, $arguments = array());
18 18
 
19 19
 
20 20
 
21
-    /**
22
-     * calls reset() on loader if method exists
23
-     */
24
-    public function reset();
21
+	/**
22
+	 * calls reset() on loader if method exists
23
+	 */
24
+	public function reset();
25 25
 
26 26
 }
27 27
 // End of file LoaderInterface.php
Please login to merge, or discard this patch.
core/services/loaders/LoaderInterface.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -9,39 +9,39 @@
 block discarded – undo
9 9
 interface LoaderInterface
10 10
 {
11 11
 
12
-    /**
13
-     * Can be for instantiating a new instance of a class,
14
-     * or for getting a shared instance of a class (default)
15
-     *
16
-     * @param string $fqcn
17
-     * @param array  $arguments
18
-     * @param bool   $shared
19
-     * @return mixed
20
-     */
21
-    public function load($fqcn, $arguments = array(), $shared = true);
22
-
23
-    /**
24
-     * Used for instantiating a new instance of a class
25
-     *
26
-     * @param string $fqcn
27
-     * @param array  $arguments
28
-     * @return mixed
29
-     */
30
-    public function getNew($fqcn, $arguments = array());
31
-
32
-    /**
33
-     * Used for getting a shared instance of a class
34
-     *
35
-     * @param string $fqcn
36
-     * @param array  $arguments
37
-     * @return mixed
38
-     */
39
-    public function getShared($fqcn, $arguments = array());
40
-
41
-    /**
42
-     * calls reset() on loader if method exists
43
-     */
44
-    public function reset();
12
+	/**
13
+	 * Can be for instantiating a new instance of a class,
14
+	 * or for getting a shared instance of a class (default)
15
+	 *
16
+	 * @param string $fqcn
17
+	 * @param array  $arguments
18
+	 * @param bool   $shared
19
+	 * @return mixed
20
+	 */
21
+	public function load($fqcn, $arguments = array(), $shared = true);
22
+
23
+	/**
24
+	 * Used for instantiating a new instance of a class
25
+	 *
26
+	 * @param string $fqcn
27
+	 * @param array  $arguments
28
+	 * @return mixed
29
+	 */
30
+	public function getNew($fqcn, $arguments = array());
31
+
32
+	/**
33
+	 * Used for getting a shared instance of a class
34
+	 *
35
+	 * @param string $fqcn
36
+	 * @param array  $arguments
37
+	 * @return mixed
38
+	 */
39
+	public function getShared($fqcn, $arguments = array());
40
+
41
+	/**
42
+	 * calls reset() on loader if method exists
43
+	 */
44
+	public function reset();
45 45
 
46 46
 }
47 47
 // End of file LoaderInterface.php
Please login to merge, or discard this patch.