@@ -15,8 +15,8 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface Swift_Events_CommandListener extends Swift_Events_EventListener |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Invoked immediately following a command being sent. |
|
| 20 | - */ |
|
| 21 | - public function commandSent(Swift_Events_CommandEvent $evt); |
|
| 18 | + /** |
|
| 19 | + * Invoked immediately following a command being sent. |
|
| 20 | + */ |
|
| 21 | + public function commandSent(Swift_Events_CommandEvent $evt); |
|
| 22 | 22 | } |
@@ -15,50 +15,50 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Events_ResponseEvent extends Swift_Events_EventObject |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * The overall result. |
|
| 20 | - * |
|
| 21 | - * @var bool |
|
| 22 | - */ |
|
| 23 | - private $valid; |
|
| 18 | + /** |
|
| 19 | + * The overall result. |
|
| 20 | + * |
|
| 21 | + * @var bool |
|
| 22 | + */ |
|
| 23 | + private $valid; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * The response received from the server. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - private $response; |
|
| 25 | + /** |
|
| 26 | + * The response received from the server. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + private $response; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Create a new ResponseEvent for $source and $response. |
|
| 34 | - * |
|
| 35 | - * @param string $response |
|
| 36 | - * @param bool $valid |
|
| 37 | - */ |
|
| 38 | - public function __construct(Swift_Transport $source, $response, $valid = false) |
|
| 39 | - { |
|
| 40 | - parent::__construct($source); |
|
| 41 | - $this->response = $response; |
|
| 42 | - $this->valid = $valid; |
|
| 43 | - } |
|
| 32 | + /** |
|
| 33 | + * Create a new ResponseEvent for $source and $response. |
|
| 34 | + * |
|
| 35 | + * @param string $response |
|
| 36 | + * @param bool $valid |
|
| 37 | + */ |
|
| 38 | + public function __construct(Swift_Transport $source, $response, $valid = false) |
|
| 39 | + { |
|
| 40 | + parent::__construct($source); |
|
| 41 | + $this->response = $response; |
|
| 42 | + $this->valid = $valid; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Get the response which was received from the server. |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function getResponse() |
|
| 51 | - { |
|
| 52 | - return $this->response; |
|
| 53 | - } |
|
| 45 | + /** |
|
| 46 | + * Get the response which was received from the server. |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function getResponse() |
|
| 51 | + { |
|
| 52 | + return $this->response; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Get the success status of this Event. |
|
| 57 | - * |
|
| 58 | - * @return bool |
|
| 59 | - */ |
|
| 60 | - public function isValid() |
|
| 61 | - { |
|
| 62 | - return $this->valid; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Get the success status of this Event. |
|
| 57 | + * |
|
| 58 | + * @return bool |
|
| 59 | + */ |
|
| 60 | + public function isValid() |
|
| 61 | + { |
|
| 62 | + return $this->valid; |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -15,56 +15,56 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface Swift_Events_EventDispatcher |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Create a new SendEvent for $source and $message. |
|
| 20 | - * |
|
| 21 | - * @return Swift_Events_SendEvent |
|
| 22 | - */ |
|
| 23 | - public function createSendEvent(Swift_Transport $source, Swift_Mime_SimpleMessage $message); |
|
| 18 | + /** |
|
| 19 | + * Create a new SendEvent for $source and $message. |
|
| 20 | + * |
|
| 21 | + * @return Swift_Events_SendEvent |
|
| 22 | + */ |
|
| 23 | + public function createSendEvent(Swift_Transport $source, Swift_Mime_SimpleMessage $message); |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Create a new CommandEvent for $source and $command. |
|
| 27 | - * |
|
| 28 | - * @param string $command That will be executed |
|
| 29 | - * @param array $successCodes That are needed |
|
| 30 | - * |
|
| 31 | - * @return Swift_Events_CommandEvent |
|
| 32 | - */ |
|
| 33 | - public function createCommandEvent(Swift_Transport $source, $command, $successCodes = []); |
|
| 25 | + /** |
|
| 26 | + * Create a new CommandEvent for $source and $command. |
|
| 27 | + * |
|
| 28 | + * @param string $command That will be executed |
|
| 29 | + * @param array $successCodes That are needed |
|
| 30 | + * |
|
| 31 | + * @return Swift_Events_CommandEvent |
|
| 32 | + */ |
|
| 33 | + public function createCommandEvent(Swift_Transport $source, $command, $successCodes = []); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Create a new ResponseEvent for $source and $response. |
|
| 37 | - * |
|
| 38 | - * @param string $response |
|
| 39 | - * @param bool $valid If the response is valid |
|
| 40 | - * |
|
| 41 | - * @return Swift_Events_ResponseEvent |
|
| 42 | - */ |
|
| 43 | - public function createResponseEvent(Swift_Transport $source, $response, $valid); |
|
| 35 | + /** |
|
| 36 | + * Create a new ResponseEvent for $source and $response. |
|
| 37 | + * |
|
| 38 | + * @param string $response |
|
| 39 | + * @param bool $valid If the response is valid |
|
| 40 | + * |
|
| 41 | + * @return Swift_Events_ResponseEvent |
|
| 42 | + */ |
|
| 43 | + public function createResponseEvent(Swift_Transport $source, $response, $valid); |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Create a new TransportChangeEvent for $source. |
|
| 47 | - * |
|
| 48 | - * @return Swift_Events_TransportChangeEvent |
|
| 49 | - */ |
|
| 50 | - public function createTransportChangeEvent(Swift_Transport $source); |
|
| 45 | + /** |
|
| 46 | + * Create a new TransportChangeEvent for $source. |
|
| 47 | + * |
|
| 48 | + * @return Swift_Events_TransportChangeEvent |
|
| 49 | + */ |
|
| 50 | + public function createTransportChangeEvent(Swift_Transport $source); |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Create a new TransportExceptionEvent for $source. |
|
| 54 | - * |
|
| 55 | - * @return Swift_Events_TransportExceptionEvent |
|
| 56 | - */ |
|
| 57 | - public function createTransportExceptionEvent(Swift_Transport $source, Swift_TransportException $ex); |
|
| 52 | + /** |
|
| 53 | + * Create a new TransportExceptionEvent for $source. |
|
| 54 | + * |
|
| 55 | + * @return Swift_Events_TransportExceptionEvent |
|
| 56 | + */ |
|
| 57 | + public function createTransportExceptionEvent(Swift_Transport $source, Swift_TransportException $ex); |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Bind an event listener to this dispatcher. |
|
| 61 | - */ |
|
| 62 | - public function bindEventListener(Swift_Events_EventListener $listener); |
|
| 59 | + /** |
|
| 60 | + * Bind an event listener to this dispatcher. |
|
| 61 | + */ |
|
| 62 | + public function bindEventListener(Swift_Events_EventListener $listener); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Dispatch the given Event to all suitable listeners. |
|
| 66 | - * |
|
| 67 | - * @param string $target method |
|
| 68 | - */ |
|
| 69 | - public function dispatchEvent(Swift_Events_EventObject $evt, $target); |
|
| 64 | + /** |
|
| 65 | + * Dispatch the given Event to all suitable listeners. |
|
| 66 | + * |
|
| 67 | + * @param string $target method |
|
| 68 | + */ |
|
| 69 | + public function dispatchEvent(Swift_Events_EventObject $evt, $target); |
|
| 70 | 70 | } |
@@ -15,29 +15,29 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Events_TransportExceptionEvent extends Swift_Events_EventObject |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * The Exception thrown. |
|
| 20 | - * |
|
| 21 | - * @var Swift_TransportException |
|
| 22 | - */ |
|
| 23 | - private $exception; |
|
| 18 | + /** |
|
| 19 | + * The Exception thrown. |
|
| 20 | + * |
|
| 21 | + * @var Swift_TransportException |
|
| 22 | + */ |
|
| 23 | + private $exception; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Create a new TransportExceptionEvent for $transport. |
|
| 27 | - */ |
|
| 28 | - public function __construct(Swift_Transport $transport, Swift_TransportException $ex) |
|
| 29 | - { |
|
| 30 | - parent::__construct($transport); |
|
| 31 | - $this->exception = $ex; |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * Create a new TransportExceptionEvent for $transport. |
|
| 27 | + */ |
|
| 28 | + public function __construct(Swift_Transport $transport, Swift_TransportException $ex) |
|
| 29 | + { |
|
| 30 | + parent::__construct($transport); |
|
| 31 | + $this->exception = $ex; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get the TransportException thrown. |
|
| 36 | - * |
|
| 37 | - * @return Swift_TransportException |
|
| 38 | - */ |
|
| 39 | - public function getException() |
|
| 40 | - { |
|
| 41 | - return $this->exception; |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * Get the TransportException thrown. |
|
| 36 | + * |
|
| 37 | + * @return Swift_TransportException |
|
| 38 | + */ |
|
| 39 | + public function getException() |
|
| 40 | + { |
|
| 41 | + return $this->exception; |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -15,112 +15,112 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Events_SendEvent extends Swift_Events_EventObject |
| 17 | 17 | { |
| 18 | - /** Sending has yet to occur */ |
|
| 19 | - const RESULT_PENDING = 0x0001; |
|
| 20 | - |
|
| 21 | - /** Email is spooled, ready to be sent */ |
|
| 22 | - const RESULT_SPOOLED = 0x0011; |
|
| 23 | - |
|
| 24 | - /** Sending was successful */ |
|
| 25 | - const RESULT_SUCCESS = 0x0010; |
|
| 26 | - |
|
| 27 | - /** Sending worked, but there were some failures */ |
|
| 28 | - const RESULT_TENTATIVE = 0x0100; |
|
| 29 | - |
|
| 30 | - /** Sending failed */ |
|
| 31 | - const RESULT_FAILED = 0x1000; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * The Message being sent. |
|
| 35 | - * |
|
| 36 | - * @var Swift_Mime_SimpleMessage |
|
| 37 | - */ |
|
| 38 | - private $message; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Any recipients which failed after sending. |
|
| 42 | - * |
|
| 43 | - * @var string[] |
|
| 44 | - */ |
|
| 45 | - private $failedRecipients = []; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * The overall result as a bitmask from the class constants. |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - private $result; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Create a new SendEvent for $source and $message. |
|
| 56 | - */ |
|
| 57 | - public function __construct(Swift_Transport $source, Swift_Mime_SimpleMessage $message) |
|
| 58 | - { |
|
| 59 | - parent::__construct($source); |
|
| 60 | - $this->message = $message; |
|
| 61 | - $this->result = self::RESULT_PENDING; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the Transport used to send the Message. |
|
| 66 | - * |
|
| 67 | - * @return Swift_Transport |
|
| 68 | - */ |
|
| 69 | - public function getTransport() |
|
| 70 | - { |
|
| 71 | - return $this->getSource(); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Get the Message being sent. |
|
| 76 | - * |
|
| 77 | - * @return Swift_Mime_SimpleMessage |
|
| 78 | - */ |
|
| 79 | - public function getMessage() |
|
| 80 | - { |
|
| 81 | - return $this->message; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Set the array of addresses that failed in sending. |
|
| 86 | - * |
|
| 87 | - * @param array $recipients |
|
| 88 | - */ |
|
| 89 | - public function setFailedRecipients($recipients) |
|
| 90 | - { |
|
| 91 | - $this->failedRecipients = $recipients; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Get an recipient addresses which were not accepted for delivery. |
|
| 96 | - * |
|
| 97 | - * @return string[] |
|
| 98 | - */ |
|
| 99 | - public function getFailedRecipients() |
|
| 100 | - { |
|
| 101 | - return $this->failedRecipients; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Set the result of sending. |
|
| 106 | - * |
|
| 107 | - * @param int $result |
|
| 108 | - */ |
|
| 109 | - public function setResult($result) |
|
| 110 | - { |
|
| 111 | - $this->result = $result; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Get the result of this Event. |
|
| 116 | - * |
|
| 117 | - * The return value is a bitmask from |
|
| 118 | - * {@see RESULT_PENDING, RESULT_SUCCESS, RESULT_TENTATIVE, RESULT_FAILED} |
|
| 119 | - * |
|
| 120 | - * @return int |
|
| 121 | - */ |
|
| 122 | - public function getResult() |
|
| 123 | - { |
|
| 124 | - return $this->result; |
|
| 125 | - } |
|
| 18 | + /** Sending has yet to occur */ |
|
| 19 | + const RESULT_PENDING = 0x0001; |
|
| 20 | + |
|
| 21 | + /** Email is spooled, ready to be sent */ |
|
| 22 | + const RESULT_SPOOLED = 0x0011; |
|
| 23 | + |
|
| 24 | + /** Sending was successful */ |
|
| 25 | + const RESULT_SUCCESS = 0x0010; |
|
| 26 | + |
|
| 27 | + /** Sending worked, but there were some failures */ |
|
| 28 | + const RESULT_TENTATIVE = 0x0100; |
|
| 29 | + |
|
| 30 | + /** Sending failed */ |
|
| 31 | + const RESULT_FAILED = 0x1000; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * The Message being sent. |
|
| 35 | + * |
|
| 36 | + * @var Swift_Mime_SimpleMessage |
|
| 37 | + */ |
|
| 38 | + private $message; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Any recipients which failed after sending. |
|
| 42 | + * |
|
| 43 | + * @var string[] |
|
| 44 | + */ |
|
| 45 | + private $failedRecipients = []; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * The overall result as a bitmask from the class constants. |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + private $result; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Create a new SendEvent for $source and $message. |
|
| 56 | + */ |
|
| 57 | + public function __construct(Swift_Transport $source, Swift_Mime_SimpleMessage $message) |
|
| 58 | + { |
|
| 59 | + parent::__construct($source); |
|
| 60 | + $this->message = $message; |
|
| 61 | + $this->result = self::RESULT_PENDING; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the Transport used to send the Message. |
|
| 66 | + * |
|
| 67 | + * @return Swift_Transport |
|
| 68 | + */ |
|
| 69 | + public function getTransport() |
|
| 70 | + { |
|
| 71 | + return $this->getSource(); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Get the Message being sent. |
|
| 76 | + * |
|
| 77 | + * @return Swift_Mime_SimpleMessage |
|
| 78 | + */ |
|
| 79 | + public function getMessage() |
|
| 80 | + { |
|
| 81 | + return $this->message; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Set the array of addresses that failed in sending. |
|
| 86 | + * |
|
| 87 | + * @param array $recipients |
|
| 88 | + */ |
|
| 89 | + public function setFailedRecipients($recipients) |
|
| 90 | + { |
|
| 91 | + $this->failedRecipients = $recipients; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Get an recipient addresses which were not accepted for delivery. |
|
| 96 | + * |
|
| 97 | + * @return string[] |
|
| 98 | + */ |
|
| 99 | + public function getFailedRecipients() |
|
| 100 | + { |
|
| 101 | + return $this->failedRecipients; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Set the result of sending. |
|
| 106 | + * |
|
| 107 | + * @param int $result |
|
| 108 | + */ |
|
| 109 | + public function setResult($result) |
|
| 110 | + { |
|
| 111 | + $this->result = $result; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Get the result of this Event. |
|
| 116 | + * |
|
| 117 | + * The return value is a bitmask from |
|
| 118 | + * {@see RESULT_PENDING, RESULT_SUCCESS, RESULT_TENTATIVE, RESULT_FAILED} |
|
| 119 | + * |
|
| 120 | + * @return int |
|
| 121 | + */ |
|
| 122 | + public function getResult() |
|
| 123 | + { |
|
| 124 | + return $this->result; |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -15,19 +15,19 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_FailoverTransport extends Swift_Transport_FailoverTransport |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Creates a new FailoverTransport with $transports. |
|
| 20 | - * |
|
| 21 | - * @param Swift_Transport[] $transports |
|
| 22 | - */ |
|
| 23 | - public function __construct($transports = []) |
|
| 24 | - { |
|
| 25 | - \call_user_func_array( |
|
| 26 | - [$this, 'Swift_Transport_FailoverTransport::__construct'], |
|
| 27 | - Swift_DependencyContainer::getInstance() |
|
| 28 | - ->createDependenciesFor('transport.failover') |
|
| 29 | - ); |
|
| 18 | + /** |
|
| 19 | + * Creates a new FailoverTransport with $transports. |
|
| 20 | + * |
|
| 21 | + * @param Swift_Transport[] $transports |
|
| 22 | + */ |
|
| 23 | + public function __construct($transports = []) |
|
| 24 | + { |
|
| 25 | + \call_user_func_array( |
|
| 26 | + [$this, 'Swift_Transport_FailoverTransport::__construct'], |
|
| 27 | + Swift_DependencyContainer::getInstance() |
|
| 28 | + ->createDependenciesFor('transport.failover') |
|
| 29 | + ); |
|
| 30 | 30 | |
| 31 | - $this->setTransports($transports); |
|
| 32 | - } |
|
| 31 | + $this->setTransports($transports); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -15,373 +15,373 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_DependencyContainer |
| 17 | 17 | { |
| 18 | - /** Constant for literal value types */ |
|
| 19 | - const TYPE_VALUE = 0x00001; |
|
| 20 | - |
|
| 21 | - /** Constant for new instance types */ |
|
| 22 | - const TYPE_INSTANCE = 0x00010; |
|
| 23 | - |
|
| 24 | - /** Constant for shared instance types */ |
|
| 25 | - const TYPE_SHARED = 0x00100; |
|
| 26 | - |
|
| 27 | - /** Constant for aliases */ |
|
| 28 | - const TYPE_ALIAS = 0x01000; |
|
| 29 | - |
|
| 30 | - /** Constant for arrays */ |
|
| 31 | - const TYPE_ARRAY = 0x10000; |
|
| 32 | - |
|
| 33 | - /** Singleton instance */ |
|
| 34 | - private static $instance = null; |
|
| 35 | - |
|
| 36 | - /** The data container */ |
|
| 37 | - private $store = []; |
|
| 38 | - |
|
| 39 | - /** The current endpoint in the data container */ |
|
| 40 | - private $endPoint; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Constructor should not be used. |
|
| 44 | - * |
|
| 45 | - * Use {@link getInstance()} instead. |
|
| 46 | - */ |
|
| 47 | - public function __construct() |
|
| 48 | - { |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Returns a singleton of the DependencyContainer. |
|
| 53 | - * |
|
| 54 | - * @return self |
|
| 55 | - */ |
|
| 56 | - public static function getInstance() |
|
| 57 | - { |
|
| 58 | - if (!isset(self::$instance)) { |
|
| 59 | - self::$instance = new self(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return self::$instance; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * List the names of all items stored in the Container. |
|
| 67 | - * |
|
| 68 | - * @return array |
|
| 69 | - */ |
|
| 70 | - public function listItems() |
|
| 71 | - { |
|
| 72 | - return array_keys($this->store); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Test if an item is registered in this container with the given name. |
|
| 77 | - * |
|
| 78 | - * @see register() |
|
| 79 | - * |
|
| 80 | - * @param string $itemName |
|
| 81 | - * |
|
| 82 | - * @return bool |
|
| 83 | - */ |
|
| 84 | - public function has($itemName) |
|
| 85 | - { |
|
| 86 | - return \array_key_exists($itemName, $this->store) |
|
| 87 | - && isset($this->store[$itemName]['lookupType']); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Lookup the item with the given $itemName. |
|
| 92 | - * |
|
| 93 | - * @see register() |
|
| 94 | - * |
|
| 95 | - * @param string $itemName |
|
| 96 | - * |
|
| 97 | - * @return mixed |
|
| 98 | - * |
|
| 99 | - * @throws Swift_DependencyException If the dependency is not found |
|
| 100 | - */ |
|
| 101 | - public function lookup($itemName) |
|
| 102 | - { |
|
| 103 | - if (!$this->has($itemName)) { |
|
| 104 | - throw new Swift_DependencyException('Cannot lookup dependency "'.$itemName.'" since it is not registered.'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - switch ($this->store[$itemName]['lookupType']) { |
|
| 108 | - case self::TYPE_ALIAS: |
|
| 109 | - return $this->createAlias($itemName); |
|
| 110 | - case self::TYPE_VALUE: |
|
| 111 | - return $this->getValue($itemName); |
|
| 112 | - case self::TYPE_INSTANCE: |
|
| 113 | - return $this->createNewInstance($itemName); |
|
| 114 | - case self::TYPE_SHARED: |
|
| 115 | - return $this->createSharedInstance($itemName); |
|
| 116 | - case self::TYPE_ARRAY: |
|
| 117 | - return $this->createDependenciesFor($itemName); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Create an array of arguments passed to the constructor of $itemName. |
|
| 123 | - * |
|
| 124 | - * @param string $itemName |
|
| 125 | - * |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - public function createDependenciesFor($itemName) |
|
| 129 | - { |
|
| 130 | - $args = []; |
|
| 131 | - if (isset($this->store[$itemName]['args'])) { |
|
| 132 | - $args = $this->resolveArgs($this->store[$itemName]['args']); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $args; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Register a new dependency with $itemName. |
|
| 140 | - * |
|
| 141 | - * This method returns the current DependencyContainer instance because it |
|
| 142 | - * requires the use of the fluid interface to set the specific details for the |
|
| 143 | - * dependency. |
|
| 144 | - * |
|
| 145 | - * @see asNewInstanceOf(), asSharedInstanceOf(), asValue() |
|
| 146 | - * |
|
| 147 | - * @param string $itemName |
|
| 148 | - * |
|
| 149 | - * @return $this |
|
| 150 | - */ |
|
| 151 | - public function register($itemName) |
|
| 152 | - { |
|
| 153 | - $this->store[$itemName] = []; |
|
| 154 | - $this->endPoint = &$this->store[$itemName]; |
|
| 155 | - |
|
| 156 | - return $this; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Specify the previously registered item as a literal value. |
|
| 161 | - * |
|
| 162 | - * {@link register()} must be called before this will work. |
|
| 163 | - * |
|
| 164 | - * @param mixed $value |
|
| 165 | - * |
|
| 166 | - * @return $this |
|
| 167 | - */ |
|
| 168 | - public function asValue($value) |
|
| 169 | - { |
|
| 170 | - $endPoint = &$this->getEndPoint(); |
|
| 171 | - $endPoint['lookupType'] = self::TYPE_VALUE; |
|
| 172 | - $endPoint['value'] = $value; |
|
| 173 | - |
|
| 174 | - return $this; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Specify the previously registered item as an alias of another item. |
|
| 179 | - * |
|
| 180 | - * @param string $lookup |
|
| 181 | - * |
|
| 182 | - * @return $this |
|
| 183 | - */ |
|
| 184 | - public function asAliasOf($lookup) |
|
| 185 | - { |
|
| 186 | - $endPoint = &$this->getEndPoint(); |
|
| 187 | - $endPoint['lookupType'] = self::TYPE_ALIAS; |
|
| 188 | - $endPoint['ref'] = $lookup; |
|
| 189 | - |
|
| 190 | - return $this; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Specify the previously registered item as a new instance of $className. |
|
| 195 | - * |
|
| 196 | - * {@link register()} must be called before this will work. |
|
| 197 | - * Any arguments can be set with {@link withDependencies()}, |
|
| 198 | - * {@link addConstructorValue()} or {@link addConstructorLookup()}. |
|
| 199 | - * |
|
| 200 | - * @see withDependencies(), addConstructorValue(), addConstructorLookup() |
|
| 201 | - * |
|
| 202 | - * @param string $className |
|
| 203 | - * |
|
| 204 | - * @return $this |
|
| 205 | - */ |
|
| 206 | - public function asNewInstanceOf($className) |
|
| 207 | - { |
|
| 208 | - $endPoint = &$this->getEndPoint(); |
|
| 209 | - $endPoint['lookupType'] = self::TYPE_INSTANCE; |
|
| 210 | - $endPoint['className'] = $className; |
|
| 211 | - |
|
| 212 | - return $this; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Specify the previously registered item as a shared instance of $className. |
|
| 217 | - * |
|
| 218 | - * {@link register()} must be called before this will work. |
|
| 219 | - * |
|
| 220 | - * @param string $className |
|
| 221 | - * |
|
| 222 | - * @return $this |
|
| 223 | - */ |
|
| 224 | - public function asSharedInstanceOf($className) |
|
| 225 | - { |
|
| 226 | - $endPoint = &$this->getEndPoint(); |
|
| 227 | - $endPoint['lookupType'] = self::TYPE_SHARED; |
|
| 228 | - $endPoint['className'] = $className; |
|
| 229 | - |
|
| 230 | - return $this; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Specify the previously registered item as array of dependencies. |
|
| 235 | - * |
|
| 236 | - * {@link register()} must be called before this will work. |
|
| 237 | - * |
|
| 238 | - * @return $this |
|
| 239 | - */ |
|
| 240 | - public function asArray() |
|
| 241 | - { |
|
| 242 | - $endPoint = &$this->getEndPoint(); |
|
| 243 | - $endPoint['lookupType'] = self::TYPE_ARRAY; |
|
| 244 | - |
|
| 245 | - return $this; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Specify a list of injected dependencies for the previously registered item. |
|
| 250 | - * |
|
| 251 | - * This method takes an array of lookup names. |
|
| 252 | - * |
|
| 253 | - * @see addConstructorValue(), addConstructorLookup() |
|
| 254 | - * |
|
| 255 | - * @return $this |
|
| 256 | - */ |
|
| 257 | - public function withDependencies(array $lookups) |
|
| 258 | - { |
|
| 259 | - $endPoint = &$this->getEndPoint(); |
|
| 260 | - $endPoint['args'] = []; |
|
| 261 | - foreach ($lookups as $lookup) { |
|
| 262 | - $this->addConstructorLookup($lookup); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - return $this; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Specify a literal (non looked up) value for the constructor of the |
|
| 270 | - * previously registered item. |
|
| 271 | - * |
|
| 272 | - * @see withDependencies(), addConstructorLookup() |
|
| 273 | - * |
|
| 274 | - * @param mixed $value |
|
| 275 | - * |
|
| 276 | - * @return $this |
|
| 277 | - */ |
|
| 278 | - public function addConstructorValue($value) |
|
| 279 | - { |
|
| 280 | - $endPoint = &$this->getEndPoint(); |
|
| 281 | - if (!isset($endPoint['args'])) { |
|
| 282 | - $endPoint['args'] = []; |
|
| 283 | - } |
|
| 284 | - $endPoint['args'][] = ['type' => 'value', 'item' => $value]; |
|
| 285 | - |
|
| 286 | - return $this; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Specify a dependency lookup for the constructor of the previously |
|
| 291 | - * registered item. |
|
| 292 | - * |
|
| 293 | - * @see withDependencies(), addConstructorValue() |
|
| 294 | - * |
|
| 295 | - * @param string $lookup |
|
| 296 | - * |
|
| 297 | - * @return $this |
|
| 298 | - */ |
|
| 299 | - public function addConstructorLookup($lookup) |
|
| 300 | - { |
|
| 301 | - $endPoint = &$this->getEndPoint(); |
|
| 302 | - if (!isset($this->endPoint['args'])) { |
|
| 303 | - $endPoint['args'] = []; |
|
| 304 | - } |
|
| 305 | - $endPoint['args'][] = ['type' => 'lookup', 'item' => $lookup]; |
|
| 306 | - |
|
| 307 | - return $this; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** Get the literal value with $itemName */ |
|
| 311 | - private function getValue($itemName) |
|
| 312 | - { |
|
| 313 | - return $this->store[$itemName]['value']; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** Resolve an alias to another item */ |
|
| 317 | - private function createAlias($itemName) |
|
| 318 | - { |
|
| 319 | - return $this->lookup($this->store[$itemName]['ref']); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** Create a fresh instance of $itemName */ |
|
| 323 | - private function createNewInstance($itemName) |
|
| 324 | - { |
|
| 325 | - $reflector = new ReflectionClass($this->store[$itemName]['className']); |
|
| 326 | - if ($reflector->getConstructor()) { |
|
| 327 | - return $reflector->newInstanceArgs( |
|
| 328 | - $this->createDependenciesFor($itemName) |
|
| 329 | - ); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - return $reflector->newInstance(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** Create and register a shared instance of $itemName */ |
|
| 336 | - private function createSharedInstance($itemName) |
|
| 337 | - { |
|
| 338 | - if (!isset($this->store[$itemName]['instance'])) { |
|
| 339 | - $this->store[$itemName]['instance'] = $this->createNewInstance($itemName); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - return $this->store[$itemName]['instance']; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** Get the current endpoint in the store */ |
|
| 346 | - private function &getEndPoint() |
|
| 347 | - { |
|
| 348 | - if (!isset($this->endPoint)) { |
|
| 349 | - throw new BadMethodCallException('Component must first be registered by calling register()'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - return $this->endPoint; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** Get an argument list with dependencies resolved */ |
|
| 356 | - private function resolveArgs(array $args) |
|
| 357 | - { |
|
| 358 | - $resolved = []; |
|
| 359 | - foreach ($args as $argDefinition) { |
|
| 360 | - switch ($argDefinition['type']) { |
|
| 361 | - case 'lookup': |
|
| 362 | - $resolved[] = $this->lookupRecursive($argDefinition['item']); |
|
| 363 | - break; |
|
| 364 | - case 'value': |
|
| 365 | - $resolved[] = $argDefinition['item']; |
|
| 366 | - break; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - return $resolved; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** Resolve a single dependency with an collections */ |
|
| 374 | - private function lookupRecursive($item) |
|
| 375 | - { |
|
| 376 | - if (\is_array($item)) { |
|
| 377 | - $collection = []; |
|
| 378 | - foreach ($item as $k => $v) { |
|
| 379 | - $collection[$k] = $this->lookupRecursive($v); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - return $collection; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - return $this->lookup($item); |
|
| 386 | - } |
|
| 18 | + /** Constant for literal value types */ |
|
| 19 | + const TYPE_VALUE = 0x00001; |
|
| 20 | + |
|
| 21 | + /** Constant for new instance types */ |
|
| 22 | + const TYPE_INSTANCE = 0x00010; |
|
| 23 | + |
|
| 24 | + /** Constant for shared instance types */ |
|
| 25 | + const TYPE_SHARED = 0x00100; |
|
| 26 | + |
|
| 27 | + /** Constant for aliases */ |
|
| 28 | + const TYPE_ALIAS = 0x01000; |
|
| 29 | + |
|
| 30 | + /** Constant for arrays */ |
|
| 31 | + const TYPE_ARRAY = 0x10000; |
|
| 32 | + |
|
| 33 | + /** Singleton instance */ |
|
| 34 | + private static $instance = null; |
|
| 35 | + |
|
| 36 | + /** The data container */ |
|
| 37 | + private $store = []; |
|
| 38 | + |
|
| 39 | + /** The current endpoint in the data container */ |
|
| 40 | + private $endPoint; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Constructor should not be used. |
|
| 44 | + * |
|
| 45 | + * Use {@link getInstance()} instead. |
|
| 46 | + */ |
|
| 47 | + public function __construct() |
|
| 48 | + { |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Returns a singleton of the DependencyContainer. |
|
| 53 | + * |
|
| 54 | + * @return self |
|
| 55 | + */ |
|
| 56 | + public static function getInstance() |
|
| 57 | + { |
|
| 58 | + if (!isset(self::$instance)) { |
|
| 59 | + self::$instance = new self(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return self::$instance; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * List the names of all items stored in the Container. |
|
| 67 | + * |
|
| 68 | + * @return array |
|
| 69 | + */ |
|
| 70 | + public function listItems() |
|
| 71 | + { |
|
| 72 | + return array_keys($this->store); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Test if an item is registered in this container with the given name. |
|
| 77 | + * |
|
| 78 | + * @see register() |
|
| 79 | + * |
|
| 80 | + * @param string $itemName |
|
| 81 | + * |
|
| 82 | + * @return bool |
|
| 83 | + */ |
|
| 84 | + public function has($itemName) |
|
| 85 | + { |
|
| 86 | + return \array_key_exists($itemName, $this->store) |
|
| 87 | + && isset($this->store[$itemName]['lookupType']); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Lookup the item with the given $itemName. |
|
| 92 | + * |
|
| 93 | + * @see register() |
|
| 94 | + * |
|
| 95 | + * @param string $itemName |
|
| 96 | + * |
|
| 97 | + * @return mixed |
|
| 98 | + * |
|
| 99 | + * @throws Swift_DependencyException If the dependency is not found |
|
| 100 | + */ |
|
| 101 | + public function lookup($itemName) |
|
| 102 | + { |
|
| 103 | + if (!$this->has($itemName)) { |
|
| 104 | + throw new Swift_DependencyException('Cannot lookup dependency "'.$itemName.'" since it is not registered.'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + switch ($this->store[$itemName]['lookupType']) { |
|
| 108 | + case self::TYPE_ALIAS: |
|
| 109 | + return $this->createAlias($itemName); |
|
| 110 | + case self::TYPE_VALUE: |
|
| 111 | + return $this->getValue($itemName); |
|
| 112 | + case self::TYPE_INSTANCE: |
|
| 113 | + return $this->createNewInstance($itemName); |
|
| 114 | + case self::TYPE_SHARED: |
|
| 115 | + return $this->createSharedInstance($itemName); |
|
| 116 | + case self::TYPE_ARRAY: |
|
| 117 | + return $this->createDependenciesFor($itemName); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Create an array of arguments passed to the constructor of $itemName. |
|
| 123 | + * |
|
| 124 | + * @param string $itemName |
|
| 125 | + * |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + public function createDependenciesFor($itemName) |
|
| 129 | + { |
|
| 130 | + $args = []; |
|
| 131 | + if (isset($this->store[$itemName]['args'])) { |
|
| 132 | + $args = $this->resolveArgs($this->store[$itemName]['args']); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $args; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Register a new dependency with $itemName. |
|
| 140 | + * |
|
| 141 | + * This method returns the current DependencyContainer instance because it |
|
| 142 | + * requires the use of the fluid interface to set the specific details for the |
|
| 143 | + * dependency. |
|
| 144 | + * |
|
| 145 | + * @see asNewInstanceOf(), asSharedInstanceOf(), asValue() |
|
| 146 | + * |
|
| 147 | + * @param string $itemName |
|
| 148 | + * |
|
| 149 | + * @return $this |
|
| 150 | + */ |
|
| 151 | + public function register($itemName) |
|
| 152 | + { |
|
| 153 | + $this->store[$itemName] = []; |
|
| 154 | + $this->endPoint = &$this->store[$itemName]; |
|
| 155 | + |
|
| 156 | + return $this; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Specify the previously registered item as a literal value. |
|
| 161 | + * |
|
| 162 | + * {@link register()} must be called before this will work. |
|
| 163 | + * |
|
| 164 | + * @param mixed $value |
|
| 165 | + * |
|
| 166 | + * @return $this |
|
| 167 | + */ |
|
| 168 | + public function asValue($value) |
|
| 169 | + { |
|
| 170 | + $endPoint = &$this->getEndPoint(); |
|
| 171 | + $endPoint['lookupType'] = self::TYPE_VALUE; |
|
| 172 | + $endPoint['value'] = $value; |
|
| 173 | + |
|
| 174 | + return $this; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Specify the previously registered item as an alias of another item. |
|
| 179 | + * |
|
| 180 | + * @param string $lookup |
|
| 181 | + * |
|
| 182 | + * @return $this |
|
| 183 | + */ |
|
| 184 | + public function asAliasOf($lookup) |
|
| 185 | + { |
|
| 186 | + $endPoint = &$this->getEndPoint(); |
|
| 187 | + $endPoint['lookupType'] = self::TYPE_ALIAS; |
|
| 188 | + $endPoint['ref'] = $lookup; |
|
| 189 | + |
|
| 190 | + return $this; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Specify the previously registered item as a new instance of $className. |
|
| 195 | + * |
|
| 196 | + * {@link register()} must be called before this will work. |
|
| 197 | + * Any arguments can be set with {@link withDependencies()}, |
|
| 198 | + * {@link addConstructorValue()} or {@link addConstructorLookup()}. |
|
| 199 | + * |
|
| 200 | + * @see withDependencies(), addConstructorValue(), addConstructorLookup() |
|
| 201 | + * |
|
| 202 | + * @param string $className |
|
| 203 | + * |
|
| 204 | + * @return $this |
|
| 205 | + */ |
|
| 206 | + public function asNewInstanceOf($className) |
|
| 207 | + { |
|
| 208 | + $endPoint = &$this->getEndPoint(); |
|
| 209 | + $endPoint['lookupType'] = self::TYPE_INSTANCE; |
|
| 210 | + $endPoint['className'] = $className; |
|
| 211 | + |
|
| 212 | + return $this; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Specify the previously registered item as a shared instance of $className. |
|
| 217 | + * |
|
| 218 | + * {@link register()} must be called before this will work. |
|
| 219 | + * |
|
| 220 | + * @param string $className |
|
| 221 | + * |
|
| 222 | + * @return $this |
|
| 223 | + */ |
|
| 224 | + public function asSharedInstanceOf($className) |
|
| 225 | + { |
|
| 226 | + $endPoint = &$this->getEndPoint(); |
|
| 227 | + $endPoint['lookupType'] = self::TYPE_SHARED; |
|
| 228 | + $endPoint['className'] = $className; |
|
| 229 | + |
|
| 230 | + return $this; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Specify the previously registered item as array of dependencies. |
|
| 235 | + * |
|
| 236 | + * {@link register()} must be called before this will work. |
|
| 237 | + * |
|
| 238 | + * @return $this |
|
| 239 | + */ |
|
| 240 | + public function asArray() |
|
| 241 | + { |
|
| 242 | + $endPoint = &$this->getEndPoint(); |
|
| 243 | + $endPoint['lookupType'] = self::TYPE_ARRAY; |
|
| 244 | + |
|
| 245 | + return $this; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Specify a list of injected dependencies for the previously registered item. |
|
| 250 | + * |
|
| 251 | + * This method takes an array of lookup names. |
|
| 252 | + * |
|
| 253 | + * @see addConstructorValue(), addConstructorLookup() |
|
| 254 | + * |
|
| 255 | + * @return $this |
|
| 256 | + */ |
|
| 257 | + public function withDependencies(array $lookups) |
|
| 258 | + { |
|
| 259 | + $endPoint = &$this->getEndPoint(); |
|
| 260 | + $endPoint['args'] = []; |
|
| 261 | + foreach ($lookups as $lookup) { |
|
| 262 | + $this->addConstructorLookup($lookup); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + return $this; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Specify a literal (non looked up) value for the constructor of the |
|
| 270 | + * previously registered item. |
|
| 271 | + * |
|
| 272 | + * @see withDependencies(), addConstructorLookup() |
|
| 273 | + * |
|
| 274 | + * @param mixed $value |
|
| 275 | + * |
|
| 276 | + * @return $this |
|
| 277 | + */ |
|
| 278 | + public function addConstructorValue($value) |
|
| 279 | + { |
|
| 280 | + $endPoint = &$this->getEndPoint(); |
|
| 281 | + if (!isset($endPoint['args'])) { |
|
| 282 | + $endPoint['args'] = []; |
|
| 283 | + } |
|
| 284 | + $endPoint['args'][] = ['type' => 'value', 'item' => $value]; |
|
| 285 | + |
|
| 286 | + return $this; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Specify a dependency lookup for the constructor of the previously |
|
| 291 | + * registered item. |
|
| 292 | + * |
|
| 293 | + * @see withDependencies(), addConstructorValue() |
|
| 294 | + * |
|
| 295 | + * @param string $lookup |
|
| 296 | + * |
|
| 297 | + * @return $this |
|
| 298 | + */ |
|
| 299 | + public function addConstructorLookup($lookup) |
|
| 300 | + { |
|
| 301 | + $endPoint = &$this->getEndPoint(); |
|
| 302 | + if (!isset($this->endPoint['args'])) { |
|
| 303 | + $endPoint['args'] = []; |
|
| 304 | + } |
|
| 305 | + $endPoint['args'][] = ['type' => 'lookup', 'item' => $lookup]; |
|
| 306 | + |
|
| 307 | + return $this; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** Get the literal value with $itemName */ |
|
| 311 | + private function getValue($itemName) |
|
| 312 | + { |
|
| 313 | + return $this->store[$itemName]['value']; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** Resolve an alias to another item */ |
|
| 317 | + private function createAlias($itemName) |
|
| 318 | + { |
|
| 319 | + return $this->lookup($this->store[$itemName]['ref']); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** Create a fresh instance of $itemName */ |
|
| 323 | + private function createNewInstance($itemName) |
|
| 324 | + { |
|
| 325 | + $reflector = new ReflectionClass($this->store[$itemName]['className']); |
|
| 326 | + if ($reflector->getConstructor()) { |
|
| 327 | + return $reflector->newInstanceArgs( |
|
| 328 | + $this->createDependenciesFor($itemName) |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + return $reflector->newInstance(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** Create and register a shared instance of $itemName */ |
|
| 336 | + private function createSharedInstance($itemName) |
|
| 337 | + { |
|
| 338 | + if (!isset($this->store[$itemName]['instance'])) { |
|
| 339 | + $this->store[$itemName]['instance'] = $this->createNewInstance($itemName); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + return $this->store[$itemName]['instance']; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** Get the current endpoint in the store */ |
|
| 346 | + private function &getEndPoint() |
|
| 347 | + { |
|
| 348 | + if (!isset($this->endPoint)) { |
|
| 349 | + throw new BadMethodCallException('Component must first be registered by calling register()'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + return $this->endPoint; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** Get an argument list with dependencies resolved */ |
|
| 356 | + private function resolveArgs(array $args) |
|
| 357 | + { |
|
| 358 | + $resolved = []; |
|
| 359 | + foreach ($args as $argDefinition) { |
|
| 360 | + switch ($argDefinition['type']) { |
|
| 361 | + case 'lookup': |
|
| 362 | + $resolved[] = $this->lookupRecursive($argDefinition['item']); |
|
| 363 | + break; |
|
| 364 | + case 'value': |
|
| 365 | + $resolved[] = $argDefinition['item']; |
|
| 366 | + break; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + return $resolved; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** Resolve a single dependency with an collections */ |
|
| 374 | + private function lookupRecursive($item) |
|
| 375 | + { |
|
| 376 | + if (\is_array($item)) { |
|
| 377 | + $collection = []; |
|
| 378 | + foreach ($item as $k => $v) { |
|
| 379 | + $collection[$k] = $this->lookupRecursive($v); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + return $collection; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + return $this->lookup($item); |
|
| 386 | + } |
|
| 387 | 387 | } |
@@ -15,12 +15,12 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_NullTransport extends Swift_Transport_NullTransport |
| 17 | 17 | { |
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 20 | - \call_user_func_array( |
|
| 21 | - [$this, 'Swift_Transport_NullTransport::__construct'], |
|
| 22 | - Swift_DependencyContainer::getInstance() |
|
| 23 | - ->createDependenciesFor('transport.null') |
|
| 24 | - ); |
|
| 25 | - } |
|
| 18 | + public function __construct() |
|
| 19 | + { |
|
| 20 | + \call_user_func_array( |
|
| 21 | + [$this, 'Swift_Transport_NullTransport::__construct'], |
|
| 22 | + Swift_DependencyContainer::getInstance() |
|
| 23 | + ->createDependenciesFor('transport.null') |
|
| 24 | + ); |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -15,10 +15,10 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface Swift_FileStream extends Swift_OutputByteStream |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Get the complete path to the file. |
|
| 20 | - * |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function getPath(); |
|
| 18 | + /** |
|
| 19 | + * Get the complete path to the file. |
|
| 20 | + * |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function getPath(); |
|
| 24 | 24 | } |