55
66namespace ZendServer \DepH \Deployment ;
77
8- use Zend \EventManager \EventManagerInterface ;
8+ use Zend \EventManager \EventManager ;
99use Zend \EventManager \EventManagerAwareInterface ;
10- use ZendServer \DepH \Log \LogAwareInterface ;
10+ use Zend \EventManager \EventManagerInterface ;
11+
12+ class Deployment implements EventManagerAwareInterface
13+ {
1114
12- class Deployment implements EventManagerAwareInterface, LogAwareInterface{
1315 const PRE_STAGE = 1 ;
1416 const POST_STAGE = 2 ;
1517 const PRE_ACTIVATE = 3 ;
@@ -18,35 +20,30 @@ class Deployment implements EventManagerAwareInterface, LogAwareInterface{
1820 const POST_ROLLBACK = 6 ;
1921 const PRE_DEACTIVATE = 7 ;
2022 const POST_DEACTIVATE = 8 ;
21-
23+
2224 /**
2325 * @var EventManagerInterface
2426 */
2527 private $ events ;
26-
27- /**
28- * @var \ZendServer\DepH\Log\Log
29- */
30- private $ log ;
31-
28+
3229 /**
3330 * Filenames and corresponding keys of all valid action scripts
34- *
31+ *
3532 * @var array
3633 */
3734 private $ actionScriptNames = array (
38- self ::PRE_STAGE => 'pre_stage.php ' ,
39- self ::POST_STAGE => 'post_stage.php ' ,
40- self ::PRE_ACTIVATE => 'pre_activate.php ' ,
41- self ::POST_ACTIVATE => 'post_activate.php ' ,
42- self ::PRE_ROLLBACK => 'pre_rollback.php ' ,
43- self ::POST_ROLLBACK => 'post_rollback.php ' ,
44- self ::PRE_DEACTIVATE => 'pre_deactivate.php ' ,
45- self ::POST_DEACTIVATE => 'post_deactivate.php ' ,
35+ self ::PRE_STAGE => 'pre_stage.php ' ,
36+ self ::POST_STAGE => 'post_stage.php ' ,
37+ self ::PRE_ACTIVATE => 'pre_activate.php ' ,
38+ self ::POST_ACTIVATE => 'post_activate.php ' ,
39+ self ::PRE_ROLLBACK => 'pre_rollback.php ' ,
40+ self ::POST_ROLLBACK => 'post_rollback.php ' ,
41+ self ::PRE_DEACTIVATE => 'pre_deactivate.php ' ,
42+ self ::POST_DEACTIVATE => 'post_deactivate.php ' ,
4643 );
47-
44+
4845 /**
49- * @see \Zend\EventManager\EventManagerAwareInterface::setEventManager()
46+ * {@inheritdoc}
5047 */
5148 public function setEventManager (EventManagerInterface $ events )
5249 {
@@ -55,33 +52,31 @@ public function setEventManager(EventManagerInterface $events)
5552 get_called_class (),
5653 ));
5754 $ this ->events = $ events ;
55+
5856 return $ this ;
5957 }
60-
58+
6159 /**
62- * @see \Zend\EventManager\EventsCapableInterface::getEventManager()
60+ * {@inheritdoc}
6361 */
6462 public function getEventManager ()
6563 {
64+ if (! $ this ->events instanceof EventManagerInterface) {
65+ $ this ->setEventManager (new EventManager ());
66+ }
6667 return $ this ->events ;
6768 }
6869
69- /**
70- * @see \ZendServer\DepH\Log\LogAwareInterface::setLog()
71- */
72- public function setLog (\ZendServer \DepH \Log \Log $ log ) {
73- $ this ->log = $ log ;
74- }
75-
7670 /**
7771 * Retrieves the value of the constant of the currently used action
78- *
79- * @throws \ZendServer\DepH\File\ Exception\RuntimeException
80- * @return int
72+ *
73+ * @throws Exception\RuntimeException
74+ * @return int
8175 */
82- public function getCurrentAction () {
76+ public function getCurrentAction ()
77+ {
8378 $ stack = array_reverse (debug_backtrace (), true );
84-
79+
8580 foreach ($ stack as $ item ) {
8681 if (!isset ($ item ['file ' ])) {
8782 continue ;
@@ -91,61 +86,70 @@ public function getCurrentAction() {
9186 return $ key ;
9287 }
9388 }
94-
89+
9590 throw new Exception \RuntimeException ('Method can only be called from within a Zend Server Deployment Hook script ' );
9691 }
97-
92+
9893 /**
9994 * Retrieves the currently used action filename
100- *
101- * @return multitype: string or \Exception on failure
95+ *
96+ * @return string
10297 */
103- public function getCurrentActionScript () {
98+ public function getCurrentActionScript ()
99+ {
104100 return $ this ->actionScriptNames [$ this ->getCurrentAction ()];
105101 }
106-
102+
107103 /**
108104 * @return boolean
109105 */
110- public function isPreStageAction () {
106+ public function isPreStageAction ()
107+ {
111108 return (self ::PRE_STAGE == $ this ->getCurrentAction ());
112109 }
113110
114111 /**
115112 * @return boolean
116113 */
117- public function isPostStageAction () {
114+ public function isPostStageAction ()
115+ {
118116 return (self ::POST_STAGE == $ this ->getCurrentAction ());
119117 }
120118
121119 /**
122120 * @return boolean
123121 */
124- public function isPreActivateAction () {
122+ public function isPreActivateAction ()
123+ {
125124 return (self ::PRE_ACTIVATE == $ this ->getCurrentAction ());
126125 }
127126
128127 /**
129128 * @return boolean
130129 */
131- public function isPostActivateAction () {
130+ public function isPostActivateAction ()
131+ {
132132 return (self ::POST_ACTIVATE == $ this ->getCurrentAction ());
133133 }
134134
135135 /**
136136 * @return boolean
137137 */
138- public function isUpdate () {
139- return (bool ) getenv ('ZS_PREVIOUS_APP_VERSION ' );
138+ public function isUpdate ()
139+ {
140+ return (bool )getenv ('ZS_PREVIOUS_APP_VERSION ' );
140141 }
141142
142143 /**
143144 * Terminates the deployment process
145+ *
146+ * @param $msg
144147 */
145- public function terminate ($ msg ) {
148+ public function terminate ($ msg )
149+ {
146150 $ this ->getEventManager ()->trigger (__FUNCTION__ , $ this , array ('msg ' => $ msg ));
147-
151+
148152 exit (1 );
149153 }
150-
154+
151155}
0 commit comments