@@ -33,87 +33,87 @@ |
||
33 | 33 | */ |
34 | 34 | class SocketPost implements RequestMethod |
35 | 35 | { |
36 | - /** |
|
37 | - * reCAPTCHA service host. |
|
38 | - * |
|
39 | - * @const string |
|
40 | - */ |
|
41 | - const RECAPTCHA_HOST = 'www.google.com'; |
|
42 | - |
|
43 | - /** |
|
44 | - * @const string reCAPTCHA service path |
|
45 | - */ |
|
46 | - const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
47 | - |
|
48 | - /** |
|
49 | - * @const string Bad request error |
|
50 | - */ |
|
51 | - const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
52 | - |
|
53 | - /** |
|
54 | - * @const string Bad response error |
|
55 | - */ |
|
56 | - const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
57 | - |
|
58 | - /** |
|
59 | - * Socket to the reCAPTCHA service |
|
60 | - * |
|
61 | - * @var Socket |
|
62 | - */ |
|
63 | - private $socket; |
|
64 | - |
|
65 | - /** |
|
66 | - * Constructor |
|
67 | - * |
|
68 | - * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
69 | - */ |
|
70 | - public function __construct(Socket $socket = null) |
|
71 | - { |
|
72 | - if (! is_null($socket)) { |
|
73 | - $this->socket = $socket; |
|
74 | - } else { |
|
75 | - $this->socket = new Socket(); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Submit the POST request with the specified parameters. |
|
81 | - * |
|
82 | - * @param RequestParameters $params Request parameters |
|
83 | - * @return string Body of the reCAPTCHA response |
|
84 | - */ |
|
85 | - public function submit(RequestParameters $params) |
|
86 | - { |
|
87 | - $errno = 0; |
|
88 | - $errstr = ''; |
|
89 | - |
|
90 | - if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
91 | - $content = $params->toQueryString(); |
|
92 | - |
|
93 | - $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
94 | - $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
95 | - $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
96 | - $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
97 | - $request .= "Connection: close\r\n\r\n"; |
|
98 | - $request .= $content . "\r\n\r\n"; |
|
99 | - |
|
100 | - $this->socket->fwrite($request); |
|
101 | - $response = ''; |
|
102 | - |
|
103 | - while (! $this->socket->feof()) { |
|
104 | - $response .= $this->socket->fgets(4096); |
|
105 | - } |
|
106 | - |
|
107 | - $this->socket->fclose(); |
|
108 | - |
|
109 | - if (0 === strpos($response, 'HTTP/1.1 200 OK')) { |
|
110 | - $parts = preg_split("#\n\s*\n#Uis", $response); |
|
111 | - return $parts[1]; |
|
112 | - } |
|
113 | - |
|
114 | - return self::BAD_RESPONSE; |
|
115 | - } |
|
116 | - |
|
117 | - return self::BAD_REQUEST; |
|
118 | - } |
|
36 | + /** |
|
37 | + * reCAPTCHA service host. |
|
38 | + * |
|
39 | + * @const string |
|
40 | + */ |
|
41 | + const RECAPTCHA_HOST = 'www.google.com'; |
|
42 | + |
|
43 | + /** |
|
44 | + * @const string reCAPTCHA service path |
|
45 | + */ |
|
46 | + const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
47 | + |
|
48 | + /** |
|
49 | + * @const string Bad request error |
|
50 | + */ |
|
51 | + const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
52 | + |
|
53 | + /** |
|
54 | + * @const string Bad response error |
|
55 | + */ |
|
56 | + const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
57 | + |
|
58 | + /** |
|
59 | + * Socket to the reCAPTCHA service |
|
60 | + * |
|
61 | + * @var Socket |
|
62 | + */ |
|
63 | + private $socket; |
|
64 | + |
|
65 | + /** |
|
66 | + * Constructor |
|
67 | + * |
|
68 | + * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
69 | + */ |
|
70 | + public function __construct(Socket $socket = null) |
|
71 | + { |
|
72 | + if (! is_null($socket)) { |
|
73 | + $this->socket = $socket; |
|
74 | + } else { |
|
75 | + $this->socket = new Socket(); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Submit the POST request with the specified parameters. |
|
81 | + * |
|
82 | + * @param RequestParameters $params Request parameters |
|
83 | + * @return string Body of the reCAPTCHA response |
|
84 | + */ |
|
85 | + public function submit(RequestParameters $params) |
|
86 | + { |
|
87 | + $errno = 0; |
|
88 | + $errstr = ''; |
|
89 | + |
|
90 | + if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
91 | + $content = $params->toQueryString(); |
|
92 | + |
|
93 | + $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
94 | + $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
95 | + $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
96 | + $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
97 | + $request .= "Connection: close\r\n\r\n"; |
|
98 | + $request .= $content . "\r\n\r\n"; |
|
99 | + |
|
100 | + $this->socket->fwrite($request); |
|
101 | + $response = ''; |
|
102 | + |
|
103 | + while (! $this->socket->feof()) { |
|
104 | + $response .= $this->socket->fgets(4096); |
|
105 | + } |
|
106 | + |
|
107 | + $this->socket->fclose(); |
|
108 | + |
|
109 | + if (0 === strpos($response, 'HTTP/1.1 200 OK')) { |
|
110 | + $parts = preg_split("#\n\s*\n#Uis", $response); |
|
111 | + return $parts[1]; |
|
112 | + } |
|
113 | + |
|
114 | + return self::BAD_RESPONSE; |
|
115 | + } |
|
116 | + |
|
117 | + return self::BAD_REQUEST; |
|
118 | + } |
|
119 | 119 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function __construct(Socket $socket = null) |
71 | 71 | { |
72 | - if (! is_null($socket)) { |
|
72 | + if ( ! is_null($socket)) { |
|
73 | 73 | $this->socket = $socket; |
74 | 74 | } else { |
75 | 75 | $this->socket = new Socket(); |
@@ -87,20 +87,20 @@ discard block |
||
87 | 87 | $errno = 0; |
88 | 88 | $errstr = ''; |
89 | 89 | |
90 | - if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
90 | + if ($this->socket->fsockopen('ssl://'.self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
91 | 91 | $content = $params->toQueryString(); |
92 | 92 | |
93 | - $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
94 | - $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
93 | + $request = "POST ".self::SITE_VERIFY_PATH." HTTP/1.1\r\n"; |
|
94 | + $request .= "Host: ".self::RECAPTCHA_HOST."\r\n"; |
|
95 | 95 | $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
96 | - $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
96 | + $request .= "Content-length: ".strlen($content)."\r\n"; |
|
97 | 97 | $request .= "Connection: close\r\n\r\n"; |
98 | - $request .= $content . "\r\n\r\n"; |
|
98 | + $request .= $content."\r\n\r\n"; |
|
99 | 99 | |
100 | 100 | $this->socket->fwrite($request); |
101 | 101 | $response = ''; |
102 | 102 | |
103 | - while (! $this->socket->feof()) { |
|
103 | + while ( ! $this->socket->feof()) { |
|
104 | 104 | $response .= $this->socket->fgets(4096); |
105 | 105 | } |
106 | 106 |
@@ -29,79 +29,79 @@ |
||
29 | 29 | */ |
30 | 30 | class Socket |
31 | 31 | { |
32 | - private $handle = null; |
|
32 | + private $handle = null; |
|
33 | 33 | |
34 | - /** |
|
35 | - * fsockopen |
|
36 | - * |
|
37 | - * @see http://php.net/fsockopen |
|
38 | - * @param string $hostname |
|
39 | - * @param int $port |
|
40 | - * @param int $errno |
|
41 | - * @param string $errstr |
|
42 | - * @param float $timeout |
|
43 | - * @return resource |
|
44 | - */ |
|
45 | - public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
46 | - { |
|
47 | - $this->handle = fsockopen( |
|
48 | - $hostname, |
|
49 | - $port, |
|
50 | - $errno, |
|
51 | - $errstr, |
|
52 | - (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout) |
|
53 | - ); |
|
34 | + /** |
|
35 | + * fsockopen |
|
36 | + * |
|
37 | + * @see http://php.net/fsockopen |
|
38 | + * @param string $hostname |
|
39 | + * @param int $port |
|
40 | + * @param int $errno |
|
41 | + * @param string $errstr |
|
42 | + * @param float $timeout |
|
43 | + * @return resource |
|
44 | + */ |
|
45 | + public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
46 | + { |
|
47 | + $this->handle = fsockopen( |
|
48 | + $hostname, |
|
49 | + $port, |
|
50 | + $errno, |
|
51 | + $errstr, |
|
52 | + (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout) |
|
53 | + ); |
|
54 | 54 | |
55 | - if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
56 | - return $this->handle; |
|
57 | - } else { |
|
58 | - return false; |
|
59 | - } |
|
60 | - } |
|
55 | + if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
56 | + return $this->handle; |
|
57 | + } else { |
|
58 | + return false; |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * fwrite |
|
64 | - * |
|
65 | - * @see http://php.net/fwrite |
|
66 | - * @param string $string |
|
67 | - * @param int $length |
|
68 | - * @return int | bool |
|
69 | - */ |
|
70 | - public function fwrite($string, $length = null) |
|
71 | - { |
|
72 | - return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
73 | - } |
|
62 | + /** |
|
63 | + * fwrite |
|
64 | + * |
|
65 | + * @see http://php.net/fwrite |
|
66 | + * @param string $string |
|
67 | + * @param int $length |
|
68 | + * @return int | bool |
|
69 | + */ |
|
70 | + public function fwrite($string, $length = null) |
|
71 | + { |
|
72 | + return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * fgets |
|
77 | - * |
|
78 | - * @see http://php.net/fgets |
|
79 | - * @param int $length |
|
80 | - */ |
|
81 | - public function fgets($length = null) |
|
82 | - { |
|
83 | - return fgets($this->handle, $length); |
|
84 | - } |
|
75 | + /** |
|
76 | + * fgets |
|
77 | + * |
|
78 | + * @see http://php.net/fgets |
|
79 | + * @param int $length |
|
80 | + */ |
|
81 | + public function fgets($length = null) |
|
82 | + { |
|
83 | + return fgets($this->handle, $length); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * feof |
|
88 | - * |
|
89 | - * @see http://php.net/feof |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function feof() |
|
93 | - { |
|
94 | - return feof($this->handle); |
|
95 | - } |
|
86 | + /** |
|
87 | + * feof |
|
88 | + * |
|
89 | + * @see http://php.net/feof |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function feof() |
|
93 | + { |
|
94 | + return feof($this->handle); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * fclose |
|
99 | - * |
|
100 | - * @see http://php.net/fclose |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function fclose() |
|
104 | - { |
|
105 | - return fclose($this->handle); |
|
106 | - } |
|
97 | + /** |
|
98 | + * fclose |
|
99 | + * |
|
100 | + * @see http://php.net/fclose |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function fclose() |
|
104 | + { |
|
105 | + return fclose($this->handle); |
|
106 | + } |
|
107 | 107 | } |
@@ -33,18 +33,18 @@ |
||
33 | 33 | */ |
34 | 34 | public function log(\Exception $exception, $time = 0) |
35 | 35 | { |
36 | - if (! $time) { |
|
36 | + if ( ! $time) { |
|
37 | 37 | $time = time(); |
38 | 38 | } |
39 | 39 | $exception_log = '----------------------------------------------------------------------------------------'; |
40 | 40 | $exception_log .= PHP_EOL; |
41 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
42 | - $exception_log .= 'Message: ' . $exception->getMessage() . PHP_EOL; |
|
43 | - $exception_log .= 'Code: ' . $exception->getCode() . PHP_EOL; |
|
44 | - $exception_log .= 'File: ' . $exception->getFile() . PHP_EOL; |
|
45 | - $exception_log .= 'Line No: ' . $exception->getLine() . PHP_EOL; |
|
46 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
47 | - $exception_log .= $exception->getTraceAsString() . PHP_EOL; |
|
41 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
42 | + $exception_log .= 'Message: '.$exception->getMessage().PHP_EOL; |
|
43 | + $exception_log .= 'Code: '.$exception->getCode().PHP_EOL; |
|
44 | + $exception_log .= 'File: '.$exception->getFile().PHP_EOL; |
|
45 | + $exception_log .= 'Line No: '.$exception->getLine().PHP_EOL; |
|
46 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
47 | + $exception_log .= $exception->getTraceAsString().PHP_EOL; |
|
48 | 48 | $exception_log .= '----------------------------------------------------------------------------------------'; |
49 | 49 | $exception_log .= PHP_EOL; |
50 | 50 | error_log($exception_log); |
@@ -12,39 +12,39 @@ |
||
12 | 12 | */ |
13 | 13 | class ExceptionLogger |
14 | 14 | { |
15 | - /** |
|
16 | - * ExceptionLogger constructor. |
|
17 | - * |
|
18 | - * @param \Exception $exception |
|
19 | - */ |
|
20 | - public function __construct(\Exception $exception) |
|
21 | - { |
|
22 | - $this->log($exception); |
|
23 | - } |
|
15 | + /** |
|
16 | + * ExceptionLogger constructor. |
|
17 | + * |
|
18 | + * @param \Exception $exception |
|
19 | + */ |
|
20 | + public function __construct(\Exception $exception) |
|
21 | + { |
|
22 | + $this->log($exception); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * write exception details to log file |
|
28 | - * |
|
29 | - * @param \Exception $exception |
|
30 | - * @param int $time |
|
31 | - */ |
|
32 | - public function log(\Exception $exception, $time = 0) |
|
33 | - { |
|
34 | - if (! $time) { |
|
35 | - $time = time(); |
|
36 | - } |
|
37 | - $exception_log = '----------------------------------------------------------------------------------------'; |
|
38 | - $exception_log .= PHP_EOL; |
|
39 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
40 | - $exception_log .= 'Message: ' . $exception->getMessage() . PHP_EOL; |
|
41 | - $exception_log .= 'Code: ' . $exception->getCode() . PHP_EOL; |
|
42 | - $exception_log .= 'File: ' . $exception->getFile() . PHP_EOL; |
|
43 | - $exception_log .= 'Line No: ' . $exception->getLine() . PHP_EOL; |
|
44 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
45 | - $exception_log .= $exception->getTraceAsString() . PHP_EOL; |
|
46 | - $exception_log .= '----------------------------------------------------------------------------------------'; |
|
47 | - $exception_log .= PHP_EOL; |
|
48 | - error_log($exception_log); |
|
49 | - } |
|
26 | + /** |
|
27 | + * write exception details to log file |
|
28 | + * |
|
29 | + * @param \Exception $exception |
|
30 | + * @param int $time |
|
31 | + */ |
|
32 | + public function log(\Exception $exception, $time = 0) |
|
33 | + { |
|
34 | + if (! $time) { |
|
35 | + $time = time(); |
|
36 | + } |
|
37 | + $exception_log = '----------------------------------------------------------------------------------------'; |
|
38 | + $exception_log .= PHP_EOL; |
|
39 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
40 | + $exception_log .= 'Message: ' . $exception->getMessage() . PHP_EOL; |
|
41 | + $exception_log .= 'Code: ' . $exception->getCode() . PHP_EOL; |
|
42 | + $exception_log .= 'File: ' . $exception->getFile() . PHP_EOL; |
|
43 | + $exception_log .= 'Line No: ' . $exception->getLine() . PHP_EOL; |
|
44 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
45 | + $exception_log .= $exception->getTraceAsString() . PHP_EOL; |
|
46 | + $exception_log .= '----------------------------------------------------------------------------------------'; |
|
47 | + $exception_log .= PHP_EOL; |
|
48 | + error_log($exception_log); |
|
49 | + } |
|
50 | 50 | } |
@@ -24,14 +24,14 @@ |
||
24 | 24 | */ |
25 | 25 | public function formatArray($input) |
26 | 26 | { |
27 | - if (! is_array($input)) { |
|
27 | + if ( ! is_array($input)) { |
|
28 | 28 | throw new InvalidDataTypeException('input', $input, 'array'); |
29 | 29 | } |
30 | 30 | // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
31 | 31 | $formatter = $this; |
32 | 32 | array_walk_recursive( |
33 | 33 | $input, |
34 | - function (&$value, $key) use ($formatter) { |
|
34 | + function(&$value, $key) use ($formatter) { |
|
35 | 35 | $value = $formatter->format($value); |
36 | 36 | } |
37 | 37 | ); |
@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class FormatterBase implements FormatterInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
19 | - * |
|
20 | - * @param array $input |
|
21 | - * @return array |
|
22 | - * @throws InvalidDataTypeException if $input is not an array |
|
23 | - */ |
|
24 | - public function formatArray($input) |
|
25 | - { |
|
26 | - if (! is_array($input)) { |
|
27 | - throw new InvalidDataTypeException('input', $input, 'array'); |
|
28 | - } |
|
29 | - // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
30 | - $formatter = $this; |
|
31 | - array_walk_recursive( |
|
32 | - $input, |
|
33 | - function (&$value, $key) use ($formatter) { |
|
34 | - $value = $formatter->format($value); |
|
35 | - } |
|
36 | - ); |
|
37 | - return $input; |
|
38 | - } |
|
17 | + /** |
|
18 | + * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
19 | + * |
|
20 | + * @param array $input |
|
21 | + * @return array |
|
22 | + * @throws InvalidDataTypeException if $input is not an array |
|
23 | + */ |
|
24 | + public function formatArray($input) |
|
25 | + { |
|
26 | + if (! is_array($input)) { |
|
27 | + throw new InvalidDataTypeException('input', $input, 'array'); |
|
28 | + } |
|
29 | + // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
30 | + $formatter = $this; |
|
31 | + array_walk_recursive( |
|
32 | + $input, |
|
33 | + function (&$value, $key) use ($formatter) { |
|
34 | + $value = $formatter->format($value); |
|
35 | + } |
|
36 | + ); |
|
37 | + return $input; |
|
38 | + } |
|
39 | 39 | } |
@@ -108,7 +108,7 @@ |
||
108 | 108 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
109 | 109 | } |
110 | 110 | // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
111 | - if (! class_exists($middleware_app_class)) { |
|
111 | + if ( ! class_exists($middleware_app_class)) { |
|
112 | 112 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
113 | 113 | } |
114 | 114 | return $middleware_app; |
@@ -20,95 +20,95 @@ |
||
20 | 20 | */ |
21 | 21 | class RequestStackBuilder extends SplDoublyLinkedList |
22 | 22 | { |
23 | - private LoaderInterface $loader; |
|
23 | + private LoaderInterface $loader; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * RequestStackBuilder constructor. |
|
28 | - * |
|
29 | - * @param LoaderInterface $loader |
|
30 | - */ |
|
31 | - public function __construct(LoaderInterface $loader) |
|
32 | - { |
|
33 | - $this->loader = $loader; |
|
34 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
35 | - } |
|
26 | + /** |
|
27 | + * RequestStackBuilder constructor. |
|
28 | + * |
|
29 | + * @param LoaderInterface $loader |
|
30 | + */ |
|
31 | + public function __construct(LoaderInterface $loader) |
|
32 | + { |
|
33 | + $this->loader = $loader; |
|
34 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * builds decorated middleware stack |
|
40 | - * by continuously injecting previous middleware app into the next |
|
41 | - * |
|
42 | - * @param RequestStackCoreAppInterface $application |
|
43 | - * @return RequestStack |
|
44 | - * @throws Exception |
|
45 | - * @throws Throwable |
|
46 | - */ |
|
47 | - public function resolve(RequestStackCoreAppInterface $application): RequestStack |
|
48 | - { |
|
49 | - $core_app = $application; |
|
50 | - // NOW... because the RequestStack is following the decorator pattern, |
|
51 | - // the first stack app we add will end up at the center of the stack, |
|
52 | - // and will end up being the last item to actually run, but we don't want that! |
|
53 | - // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
54 | - // BUT... we want the final stack to be in the same order as the first. |
|
55 | - // So we need to reverse the iterator mode when transferring items, |
|
56 | - // because if we don't, the second stack will end up in the incorrect order. |
|
57 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
58 | - for ($this->rewind(); $this->valid(); $this->next()) { |
|
59 | - try { |
|
60 | - $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
61 | - $middleware_app_class = array_shift($middleware_app); |
|
62 | - $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
63 | - $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
64 | - $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
65 | - } catch (InvalidRequestStackMiddlewareException $exception) { |
|
66 | - if (WP_DEBUG) { |
|
67 | - new ExceptionStackTraceDisplay($exception); |
|
68 | - continue; |
|
69 | - } |
|
70 | - error_log($exception->getMessage()); |
|
71 | - } |
|
72 | - } |
|
73 | - return new RequestStack($application, $core_app); |
|
74 | - } |
|
38 | + /** |
|
39 | + * builds decorated middleware stack |
|
40 | + * by continuously injecting previous middleware app into the next |
|
41 | + * |
|
42 | + * @param RequestStackCoreAppInterface $application |
|
43 | + * @return RequestStack |
|
44 | + * @throws Exception |
|
45 | + * @throws Throwable |
|
46 | + */ |
|
47 | + public function resolve(RequestStackCoreAppInterface $application): RequestStack |
|
48 | + { |
|
49 | + $core_app = $application; |
|
50 | + // NOW... because the RequestStack is following the decorator pattern, |
|
51 | + // the first stack app we add will end up at the center of the stack, |
|
52 | + // and will end up being the last item to actually run, but we don't want that! |
|
53 | + // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
54 | + // BUT... we want the final stack to be in the same order as the first. |
|
55 | + // So we need to reverse the iterator mode when transferring items, |
|
56 | + // because if we don't, the second stack will end up in the incorrect order. |
|
57 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
58 | + for ($this->rewind(); $this->valid(); $this->next()) { |
|
59 | + try { |
|
60 | + $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
61 | + $middleware_app_class = array_shift($middleware_app); |
|
62 | + $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
63 | + $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
64 | + $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
65 | + } catch (InvalidRequestStackMiddlewareException $exception) { |
|
66 | + if (WP_DEBUG) { |
|
67 | + new ExceptionStackTraceDisplay($exception); |
|
68 | + continue; |
|
69 | + } |
|
70 | + error_log($exception->getMessage()); |
|
71 | + } |
|
72 | + } |
|
73 | + return new RequestStack($application, $core_app); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
79 | - * are all ordered correctly so that the middleware can be properly constructed |
|
80 | - * |
|
81 | - * @param array $middleware_app |
|
82 | - * @param bool $recurse |
|
83 | - * @return array |
|
84 | - * @throws InvalidRequestStackMiddlewareException |
|
85 | - */ |
|
86 | - protected function validateMiddlewareAppDetails(array $middleware_app, bool $recurse = false): array |
|
87 | - { |
|
88 | - $middleware_app_class = reset($middleware_app); |
|
89 | - // is array empty ? |
|
90 | - if ($middleware_app_class === false) { |
|
91 | - throw new InvalidRequestStackMiddlewareException('invalid middleware'); |
|
92 | - } |
|
93 | - // are the class and arguments in the wrong order ? |
|
94 | - if (is_array($middleware_app_class)) { |
|
95 | - if ($recurse === true) { |
|
96 | - return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
97 | - } |
|
98 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
99 | - } |
|
100 | - // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
101 | - if (is_int($middleware_app_class)) { |
|
102 | - if ($recurse === true) { |
|
103 | - $middleware_app = array_reverse($middleware_app); |
|
104 | - return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
105 | - } |
|
106 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
107 | - } |
|
108 | - // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
109 | - if (! class_exists($middleware_app_class)) { |
|
110 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
111 | - } |
|
112 | - return $middleware_app; |
|
113 | - } |
|
77 | + /** |
|
78 | + * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
79 | + * are all ordered correctly so that the middleware can be properly constructed |
|
80 | + * |
|
81 | + * @param array $middleware_app |
|
82 | + * @param bool $recurse |
|
83 | + * @return array |
|
84 | + * @throws InvalidRequestStackMiddlewareException |
|
85 | + */ |
|
86 | + protected function validateMiddlewareAppDetails(array $middleware_app, bool $recurse = false): array |
|
87 | + { |
|
88 | + $middleware_app_class = reset($middleware_app); |
|
89 | + // is array empty ? |
|
90 | + if ($middleware_app_class === false) { |
|
91 | + throw new InvalidRequestStackMiddlewareException('invalid middleware'); |
|
92 | + } |
|
93 | + // are the class and arguments in the wrong order ? |
|
94 | + if (is_array($middleware_app_class)) { |
|
95 | + if ($recurse === true) { |
|
96 | + return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
97 | + } |
|
98 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
99 | + } |
|
100 | + // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
101 | + if (is_int($middleware_app_class)) { |
|
102 | + if ($recurse === true) { |
|
103 | + $middleware_app = array_reverse($middleware_app); |
|
104 | + return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
105 | + } |
|
106 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
107 | + } |
|
108 | + // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
109 | + if (! class_exists($middleware_app_class)) { |
|
110 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
111 | + } |
|
112 | + return $middleware_app; |
|
113 | + } |
|
114 | 114 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | */ |
43 | 43 | public function add($object, $identifier = null) |
44 | 44 | { |
45 | - if (! is_object($object)) { |
|
45 | + if ( ! is_object($object)) { |
|
46 | 46 | throw new InvalidEntityException($object, 'object'); |
47 | 47 | } |
48 | 48 | $this->attach($object); |
@@ -14,37 +14,37 @@ |
||
14 | 14 | */ |
15 | 15 | class LooseCollection extends Collection |
16 | 16 | { |
17 | - /** |
|
18 | - * setCollectionInterface |
|
19 | - * |
|
20 | - * @access protected |
|
21 | - * @param string $collection_interface |
|
22 | - */ |
|
23 | - protected function setCollectionInterface($collection_interface) |
|
24 | - { |
|
25 | - $this->collection_interface = ''; |
|
26 | - } |
|
17 | + /** |
|
18 | + * setCollectionInterface |
|
19 | + * |
|
20 | + * @access protected |
|
21 | + * @param string $collection_interface |
|
22 | + */ |
|
23 | + protected function setCollectionInterface($collection_interface) |
|
24 | + { |
|
25 | + $this->collection_interface = ''; |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * add |
|
31 | - * attaches an object to the Collection |
|
32 | - * and sets any supplied data associated with the current iterator entry |
|
33 | - * by calling EE_Object_Collection::set_identifier() |
|
34 | - * |
|
35 | - * @access public |
|
36 | - * @param mixed $object |
|
37 | - * @param mixed $identifier |
|
38 | - * @return bool |
|
39 | - * @throws InvalidEntityException |
|
40 | - */ |
|
41 | - public function add($object, $identifier = null) |
|
42 | - { |
|
43 | - if (! is_object($object)) { |
|
44 | - throw new InvalidEntityException($object, 'object'); |
|
45 | - } |
|
46 | - $this->attach($object); |
|
47 | - $this->setIdentifier($object, $identifier); |
|
48 | - return $this->contains($object); |
|
49 | - } |
|
29 | + /** |
|
30 | + * add |
|
31 | + * attaches an object to the Collection |
|
32 | + * and sets any supplied data associated with the current iterator entry |
|
33 | + * by calling EE_Object_Collection::set_identifier() |
|
34 | + * |
|
35 | + * @access public |
|
36 | + * @param mixed $object |
|
37 | + * @param mixed $identifier |
|
38 | + * @return bool |
|
39 | + * @throws InvalidEntityException |
|
40 | + */ |
|
41 | + public function add($object, $identifier = null) |
|
42 | + { |
|
43 | + if (! is_object($object)) { |
|
44 | + throw new InvalidEntityException($object, 'object'); |
|
45 | + } |
|
46 | + $this->attach($object); |
|
47 | + $this->setIdentifier($object, $identifier); |
|
48 | + return $this->contains($object); |
|
49 | + } |
|
50 | 50 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function __construct(NoticeInterface $notice, $display_now = true) |
41 | 41 | { |
42 | 42 | $this->notice = $notice; |
43 | - if (! did_action('admin_notices')) { |
|
43 | + if ( ! did_action('admin_notices')) { |
|
44 | 44 | add_action('admin_notices', array($this, 'displayNotice')); |
45 | 45 | } elseif ($display_now) { |
46 | 46 | $this->displayNotice(); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | { |
109 | 109 | $message = $this->notice->message(); |
110 | 110 | if (WP_DEBUG && $this->getType() === AdminNotice::ERROR) { |
111 | - $message .= '<br/><span class="tiny-text">' . $this->generateErrorCode() . '</span>'; |
|
111 | + $message .= '<br/><span class="tiny-text">'.$this->generateErrorCode().'</span>'; |
|
112 | 112 | } |
113 | 113 | return $message; |
114 | 114 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | { |
125 | 125 | $file = explode('.', basename($this->notice->file())); |
126 | 126 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
127 | - $error_code .= ! empty($error_code) ? ' - ' . $this->notice->func() : $this->notice->func(); |
|
128 | - $error_code .= ' - ' . $this->notice->line(); |
|
127 | + $error_code .= ! empty($error_code) ? ' - '.$this->notice->func() : $this->notice->func(); |
|
128 | + $error_code .= ' - '.$this->notice->line(); |
|
129 | 129 | return $error_code; |
130 | 130 | } |
131 | 131 | } |
@@ -14,115 +14,115 @@ |
||
14 | 14 | */ |
15 | 15 | class AdminNotice |
16 | 16 | { |
17 | - const ERROR = 'notice-error'; |
|
18 | - |
|
19 | - const WARNING = 'notice-warning'; |
|
20 | - |
|
21 | - const SUCCESS = 'notice-success'; |
|
22 | - |
|
23 | - const INFORMATION = 'notice-info'; |
|
24 | - |
|
25 | - const DISMISSABLE = ' is-dismissible'; |
|
26 | - |
|
27 | - /** |
|
28 | - * generic system notice to be converted into a WP admin notice |
|
29 | - * |
|
30 | - * @var NoticeInterface $notice |
|
31 | - */ |
|
32 | - private $notice; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * AdminNotice constructor. |
|
37 | - * |
|
38 | - * @param NoticeInterface $notice |
|
39 | - * @param bool $display_now |
|
40 | - */ |
|
41 | - public function __construct(NoticeInterface $notice, $display_now = true) |
|
42 | - { |
|
43 | - $this->notice = $notice; |
|
44 | - if (! did_action('admin_notices')) { |
|
45 | - add_action('admin_notices', array($this, 'displayNotice')); |
|
46 | - } elseif ($display_now) { |
|
47 | - $this->displayNotice(); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function displayNotice() |
|
56 | - { |
|
57 | - echo wp_kses($this->getNotice(), AllowedTags::getAllowedTags()); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * produces something like: |
|
63 | - * <div class="notice notice-success is-dismissible event-espresso-admin-notice"> |
|
64 | - * <p>YOU DID IT!</p> |
|
65 | - * <button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this |
|
66 | - * notice.</span></button> |
|
67 | - * </div> |
|
68 | - * |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getNotice() |
|
72 | - { |
|
73 | - return sprintf( |
|
74 | - '<div class="notice %1$s%2$s event-espresso-admin-notice"><p>%3$s</p></div>', |
|
75 | - $this->getType(), |
|
76 | - $this->notice->isDismissible() ? AdminNotice::DISMISSABLE : '', |
|
77 | - $this->getMessage() |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - private function getType() |
|
86 | - { |
|
87 | - switch ($this->notice->type()) { |
|
88 | - case Notice::ERROR: |
|
89 | - return AdminNotice::ERROR; |
|
90 | - case Notice::ATTENTION: |
|
91 | - return AdminNotice::WARNING; |
|
92 | - case Notice::SUCCESS: |
|
93 | - return AdminNotice::SUCCESS; |
|
94 | - case Notice::INFORMATION: |
|
95 | - default: |
|
96 | - return AdminNotice::INFORMATION; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - protected function getMessage() |
|
105 | - { |
|
106 | - $message = $this->notice->message(); |
|
107 | - if (WP_DEBUG && $this->getType() === AdminNotice::ERROR) { |
|
108 | - $message .= '<br/><span class="tiny-text">' . $this->generateErrorCode() . '</span>'; |
|
109 | - } |
|
110 | - return $message; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * create error code from filepath, function name, |
|
116 | - * and line number where notice was generated |
|
117 | - * |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - protected function generateErrorCode() |
|
121 | - { |
|
122 | - $file = explode('.', basename($this->notice->file())); |
|
123 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
124 | - $error_code .= ! empty($error_code) ? ' - ' . $this->notice->func() : $this->notice->func(); |
|
125 | - $error_code .= ' - ' . $this->notice->line(); |
|
126 | - return $error_code; |
|
127 | - } |
|
17 | + const ERROR = 'notice-error'; |
|
18 | + |
|
19 | + const WARNING = 'notice-warning'; |
|
20 | + |
|
21 | + const SUCCESS = 'notice-success'; |
|
22 | + |
|
23 | + const INFORMATION = 'notice-info'; |
|
24 | + |
|
25 | + const DISMISSABLE = ' is-dismissible'; |
|
26 | + |
|
27 | + /** |
|
28 | + * generic system notice to be converted into a WP admin notice |
|
29 | + * |
|
30 | + * @var NoticeInterface $notice |
|
31 | + */ |
|
32 | + private $notice; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * AdminNotice constructor. |
|
37 | + * |
|
38 | + * @param NoticeInterface $notice |
|
39 | + * @param bool $display_now |
|
40 | + */ |
|
41 | + public function __construct(NoticeInterface $notice, $display_now = true) |
|
42 | + { |
|
43 | + $this->notice = $notice; |
|
44 | + if (! did_action('admin_notices')) { |
|
45 | + add_action('admin_notices', array($this, 'displayNotice')); |
|
46 | + } elseif ($display_now) { |
|
47 | + $this->displayNotice(); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function displayNotice() |
|
56 | + { |
|
57 | + echo wp_kses($this->getNotice(), AllowedTags::getAllowedTags()); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * produces something like: |
|
63 | + * <div class="notice notice-success is-dismissible event-espresso-admin-notice"> |
|
64 | + * <p>YOU DID IT!</p> |
|
65 | + * <button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this |
|
66 | + * notice.</span></button> |
|
67 | + * </div> |
|
68 | + * |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getNotice() |
|
72 | + { |
|
73 | + return sprintf( |
|
74 | + '<div class="notice %1$s%2$s event-espresso-admin-notice"><p>%3$s</p></div>', |
|
75 | + $this->getType(), |
|
76 | + $this->notice->isDismissible() ? AdminNotice::DISMISSABLE : '', |
|
77 | + $this->getMessage() |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + private function getType() |
|
86 | + { |
|
87 | + switch ($this->notice->type()) { |
|
88 | + case Notice::ERROR: |
|
89 | + return AdminNotice::ERROR; |
|
90 | + case Notice::ATTENTION: |
|
91 | + return AdminNotice::WARNING; |
|
92 | + case Notice::SUCCESS: |
|
93 | + return AdminNotice::SUCCESS; |
|
94 | + case Notice::INFORMATION: |
|
95 | + default: |
|
96 | + return AdminNotice::INFORMATION; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + protected function getMessage() |
|
105 | + { |
|
106 | + $message = $this->notice->message(); |
|
107 | + if (WP_DEBUG && $this->getType() === AdminNotice::ERROR) { |
|
108 | + $message .= '<br/><span class="tiny-text">' . $this->generateErrorCode() . '</span>'; |
|
109 | + } |
|
110 | + return $message; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * create error code from filepath, function name, |
|
116 | + * and line number where notice was generated |
|
117 | + * |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + protected function generateErrorCode() |
|
121 | + { |
|
122 | + $file = explode('.', basename($this->notice->file())); |
|
123 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
124 | + $error_code .= ! empty($error_code) ? ' - ' . $this->notice->func() : $this->notice->func(); |
|
125 | + $error_code .= ' - ' . $this->notice->line(); |
|
126 | + return $error_code; |
|
127 | + } |
|
128 | 128 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | case 'new_instance': |
45 | 45 | case 'new_instance_from_db': |
46 | 46 | $injector = $this->injector(); |
47 | - $closure = function ($arguments) use ($recipe, $reflector, $method, $injector) { |
|
47 | + $closure = function($arguments) use ($recipe, $reflector, $method, $injector) { |
|
48 | 48 | return call_user_func_array( |
49 | 49 | array($reflector->getName(), $method), |
50 | 50 | $injector->resolveDependencies($recipe, $reflector, $arguments) |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | }; |
53 | 53 | break; |
54 | 54 | case 'newInstance': |
55 | - $closure = function () use ($reflector) { |
|
55 | + $closure = function() use ($reflector) { |
|
56 | 56 | return $reflector->newInstance(); |
57 | 57 | }; |
58 | 58 | break; |
59 | 59 | case 'newInstanceArgs': |
60 | 60 | default: |
61 | 61 | $injector = $this->injector(); |
62 | - $closure = function ($arguments) use ($recipe, $reflector, $injector) { |
|
62 | + $closure = function($arguments) use ($recipe, $reflector, $injector) { |
|
63 | 63 | return $reflector->newInstanceArgs( |
64 | 64 | $injector->resolveDependencies($recipe, $reflector, $arguments) |
65 | 65 | ); |
@@ -18,51 +18,51 @@ |
||
18 | 18 | */ |
19 | 19 | class NewCoffeeMaker extends CoffeeMaker |
20 | 20 | { |
21 | - /** |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function type() |
|
25 | - { |
|
26 | - return CoffeeMaker::BREW_NEW; |
|
27 | - } |
|
21 | + /** |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function type() |
|
25 | + { |
|
26 | + return CoffeeMaker::BREW_NEW; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @param RecipeInterface $recipe |
|
32 | - * @param array $arguments |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function brew(RecipeInterface $recipe, $arguments = array()) |
|
36 | - { |
|
37 | - $this->resolveClassAndFilepath($recipe); |
|
38 | - $reflector = $this->injector()->getReflectionClass($recipe->fqcn()); |
|
39 | - $method = $this->resolveInstantiationMethod($reflector); |
|
40 | - switch ($method) { |
|
41 | - case 'instance': |
|
42 | - case 'new_instance': |
|
43 | - case 'new_instance_from_db': |
|
44 | - $injector = $this->injector(); |
|
45 | - $closure = function ($arguments) use ($recipe, $reflector, $method, $injector) { |
|
46 | - return call_user_func_array( |
|
47 | - array($reflector->getName(), $method), |
|
48 | - $injector->resolveDependencies($recipe, $reflector, $arguments) |
|
49 | - ); |
|
50 | - }; |
|
51 | - break; |
|
52 | - case 'newInstance': |
|
53 | - $closure = function () use ($reflector) { |
|
54 | - return $reflector->newInstance(); |
|
55 | - }; |
|
56 | - break; |
|
57 | - case 'newInstanceArgs': |
|
58 | - default: |
|
59 | - $injector = $this->injector(); |
|
60 | - $closure = function ($arguments) use ($recipe, $reflector, $injector) { |
|
61 | - return $reflector->newInstanceArgs( |
|
62 | - $injector->resolveDependencies($recipe, $reflector, $arguments) |
|
63 | - ); |
|
64 | - }; |
|
65 | - } |
|
66 | - return $this->coffeePot()->addClosure($recipe->identifier(), $closure); |
|
67 | - } |
|
30 | + /** |
|
31 | + * @param RecipeInterface $recipe |
|
32 | + * @param array $arguments |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function brew(RecipeInterface $recipe, $arguments = array()) |
|
36 | + { |
|
37 | + $this->resolveClassAndFilepath($recipe); |
|
38 | + $reflector = $this->injector()->getReflectionClass($recipe->fqcn()); |
|
39 | + $method = $this->resolveInstantiationMethod($reflector); |
|
40 | + switch ($method) { |
|
41 | + case 'instance': |
|
42 | + case 'new_instance': |
|
43 | + case 'new_instance_from_db': |
|
44 | + $injector = $this->injector(); |
|
45 | + $closure = function ($arguments) use ($recipe, $reflector, $method, $injector) { |
|
46 | + return call_user_func_array( |
|
47 | + array($reflector->getName(), $method), |
|
48 | + $injector->resolveDependencies($recipe, $reflector, $arguments) |
|
49 | + ); |
|
50 | + }; |
|
51 | + break; |
|
52 | + case 'newInstance': |
|
53 | + $closure = function () use ($reflector) { |
|
54 | + return $reflector->newInstance(); |
|
55 | + }; |
|
56 | + break; |
|
57 | + case 'newInstanceArgs': |
|
58 | + default: |
|
59 | + $injector = $this->injector(); |
|
60 | + $closure = function ($arguments) use ($recipe, $reflector, $injector) { |
|
61 | + return $reflector->newInstanceArgs( |
|
62 | + $injector->resolveDependencies($recipe, $reflector, $arguments) |
|
63 | + ); |
|
64 | + }; |
|
65 | + } |
|
66 | + return $this->coffeePot()->addClosure($recipe->identifier(), $closure); |
|
67 | + } |
|
68 | 68 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ) { |
80 | 80 | // grab the related ticket object for this line_item |
81 | 81 | $this->ticket = $ticket_line_item->ticket(); |
82 | - if (! $this->ticket instanceof EE_Ticket) { |
|
82 | + if ( ! $this->ticket instanceof EE_Ticket) { |
|
83 | 83 | throw new InvalidEntityException( |
84 | 84 | is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
85 | 85 | 'EE_Ticket', |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getCapCheck() |
105 | 105 | { |
106 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
106 | + if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
107 | 107 | return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
108 | 108 | } |
109 | 109 | return $this->cap_check; |
@@ -25,151 +25,151 @@ |
||
25 | 25 | */ |
26 | 26 | class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
27 | 27 | { |
28 | - /** |
|
29 | - * @var EE_Transaction $transaction |
|
30 | - */ |
|
31 | - private $transaction; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var EE_Ticket $ticket |
|
35 | - */ |
|
36 | - private $ticket; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var EE_Line_Item $ticket_line_item |
|
40 | - */ |
|
41 | - private $ticket_line_item; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var int $reg_count |
|
45 | - */ |
|
46 | - private $reg_count; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var int $reg_group_size |
|
50 | - */ |
|
51 | - private $reg_group_size; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string $reg_status |
|
55 | - */ |
|
56 | - private $reg_status; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var EE_Registration $registration |
|
60 | - */ |
|
61 | - protected $registration; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * CreateRegistrationCommand constructor. |
|
66 | - * |
|
67 | - * @param EE_Transaction $transaction |
|
68 | - * @param EE_Line_Item $ticket_line_item |
|
69 | - * @param int $reg_count |
|
70 | - * @param int $reg_group_size |
|
71 | - * @param string $reg_status |
|
72 | - * @throws InvalidEntityException |
|
73 | - */ |
|
74 | - public function __construct( |
|
75 | - EE_Transaction $transaction, |
|
76 | - EE_Line_Item $ticket_line_item, |
|
77 | - $reg_count = 1, |
|
78 | - $reg_group_size = 0, |
|
79 | - $reg_status = RegStatus::INCOMPLETE |
|
80 | - ) { |
|
81 | - // grab the related ticket object for this line_item |
|
82 | - $this->ticket = $ticket_line_item->ticket(); |
|
83 | - if (! $this->ticket instanceof EE_Ticket) { |
|
84 | - throw new InvalidEntityException( |
|
85 | - is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
86 | - 'EE_Ticket', |
|
87 | - sprintf( |
|
88 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
89 | - $ticket_line_item->ID() |
|
90 | - ) |
|
91 | - ); |
|
92 | - } |
|
93 | - $this->transaction = $transaction; |
|
94 | - $this->ticket_line_item = $ticket_line_item; |
|
95 | - $this->reg_count = absint($reg_count); |
|
96 | - $this->reg_group_size = absint($reg_group_size); |
|
97 | - $this->reg_status = $reg_status; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return CapCheckInterface |
|
103 | - * @throws InvalidDataTypeException |
|
104 | - */ |
|
105 | - public function getCapCheck() |
|
106 | - { |
|
107 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
108 | - return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
109 | - } |
|
110 | - return $this->cap_check; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return EE_Transaction |
|
116 | - */ |
|
117 | - public function transaction() |
|
118 | - { |
|
119 | - return $this->transaction; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return EE_Ticket |
|
125 | - */ |
|
126 | - public function ticket() |
|
127 | - { |
|
128 | - return $this->ticket; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return EE_Line_Item |
|
134 | - */ |
|
135 | - public function ticketLineItem() |
|
136 | - { |
|
137 | - return $this->ticket_line_item; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @return int |
|
143 | - */ |
|
144 | - public function regCount() |
|
145 | - { |
|
146 | - return $this->reg_count; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @return int |
|
152 | - */ |
|
153 | - public function regGroupSize() |
|
154 | - { |
|
155 | - return $this->reg_group_size; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function regStatus() |
|
163 | - { |
|
164 | - return $this->reg_status; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @return EE_Registration |
|
170 | - */ |
|
171 | - public function registration() |
|
172 | - { |
|
173 | - return $this->registration; |
|
174 | - } |
|
28 | + /** |
|
29 | + * @var EE_Transaction $transaction |
|
30 | + */ |
|
31 | + private $transaction; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var EE_Ticket $ticket |
|
35 | + */ |
|
36 | + private $ticket; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var EE_Line_Item $ticket_line_item |
|
40 | + */ |
|
41 | + private $ticket_line_item; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var int $reg_count |
|
45 | + */ |
|
46 | + private $reg_count; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var int $reg_group_size |
|
50 | + */ |
|
51 | + private $reg_group_size; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string $reg_status |
|
55 | + */ |
|
56 | + private $reg_status; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var EE_Registration $registration |
|
60 | + */ |
|
61 | + protected $registration; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * CreateRegistrationCommand constructor. |
|
66 | + * |
|
67 | + * @param EE_Transaction $transaction |
|
68 | + * @param EE_Line_Item $ticket_line_item |
|
69 | + * @param int $reg_count |
|
70 | + * @param int $reg_group_size |
|
71 | + * @param string $reg_status |
|
72 | + * @throws InvalidEntityException |
|
73 | + */ |
|
74 | + public function __construct( |
|
75 | + EE_Transaction $transaction, |
|
76 | + EE_Line_Item $ticket_line_item, |
|
77 | + $reg_count = 1, |
|
78 | + $reg_group_size = 0, |
|
79 | + $reg_status = RegStatus::INCOMPLETE |
|
80 | + ) { |
|
81 | + // grab the related ticket object for this line_item |
|
82 | + $this->ticket = $ticket_line_item->ticket(); |
|
83 | + if (! $this->ticket instanceof EE_Ticket) { |
|
84 | + throw new InvalidEntityException( |
|
85 | + is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
86 | + 'EE_Ticket', |
|
87 | + sprintf( |
|
88 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
89 | + $ticket_line_item->ID() |
|
90 | + ) |
|
91 | + ); |
|
92 | + } |
|
93 | + $this->transaction = $transaction; |
|
94 | + $this->ticket_line_item = $ticket_line_item; |
|
95 | + $this->reg_count = absint($reg_count); |
|
96 | + $this->reg_group_size = absint($reg_group_size); |
|
97 | + $this->reg_status = $reg_status; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return CapCheckInterface |
|
103 | + * @throws InvalidDataTypeException |
|
104 | + */ |
|
105 | + public function getCapCheck() |
|
106 | + { |
|
107 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
108 | + return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
109 | + } |
|
110 | + return $this->cap_check; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return EE_Transaction |
|
116 | + */ |
|
117 | + public function transaction() |
|
118 | + { |
|
119 | + return $this->transaction; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return EE_Ticket |
|
125 | + */ |
|
126 | + public function ticket() |
|
127 | + { |
|
128 | + return $this->ticket; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return EE_Line_Item |
|
134 | + */ |
|
135 | + public function ticketLineItem() |
|
136 | + { |
|
137 | + return $this->ticket_line_item; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @return int |
|
143 | + */ |
|
144 | + public function regCount() |
|
145 | + { |
|
146 | + return $this->reg_count; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @return int |
|
152 | + */ |
|
153 | + public function regGroupSize() |
|
154 | + { |
|
155 | + return $this->reg_group_size; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function regStatus() |
|
163 | + { |
|
164 | + return $this->reg_status; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @return EE_Registration |
|
170 | + */ |
|
171 | + public function registration() |
|
172 | + { |
|
173 | + return $this->registration; |
|
174 | + } |
|
175 | 175 | } |