Skip to content

Commit 6932abf

Browse files
ServiceManager rewrite.
moved service configuration to ConfigProvider replaced callable factories with seperated factory classes
1 parent d5c04c5 commit 6932abf

File tree

15 files changed

+654
-365
lines changed

15 files changed

+654
-365
lines changed

src/ConfigProvider.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
namespace ZendServer\DepH;
3+
4+
class ConfigProvider
5+
{
6+
7+
/**
8+
* @return array
9+
*/
10+
public function getDependencyConfig()
11+
{
12+
return array(
13+
'factories' => array(
14+
'ZendServer\DepH\Params\Params' => 'ZendServer\DepH\Params\Params\ParamsFactory',
15+
'ZendServer\DepH\Log\Log' => 'ZendServer\DepH\Log\LogFactory',
16+
'ZendServer\DepH\Path\Path' => 'ZendServer\DepH\Path\PathFactory',
17+
'ZendServer\DepH\Debugger\ZendDebugger' => 'ZendServer\DepH\Debugger\ZendDebuggerFactory',
18+
'DB' => 'ZendServer\DepH\Db\MysqliFactory',
19+
),
20+
'invokables' => array(
21+
'Zend\EventManager\EventManager',
22+
'Zend\EventManager\SharedEventManager',
23+
'ZendServer\DepH\Deployment\Deployment',
24+
'ZendServer\DepH\File\Template',
25+
'ZendServer\DepH\SystemCall\Shell',
26+
'ZendServer\DepH\Params\ZendServer',
27+
'ZendServer\DepH\Params\Custom',
28+
'ZendServer\DepH\Db\MysqliFactory',
29+
),
30+
'aliases' => array(
31+
'EventManager' => 'Zend\EventManager\EventManager',
32+
'SharedEventManager' => 'Zend\EventManager\SharedEventManager',
33+
'Deployment' => 'ZendServer\DepH\Deployment\Deployment',
34+
'Template' => 'ZendServer\DepH\File\Template',
35+
'Shell' => 'ZendServer\DepH\SystemCall\Shell',
36+
'ZSParams' => 'ZendServer\DepH\Params\ZendServer',
37+
'CustomParams' => 'ZendServer\DepH\Params\Custom',
38+
'MysqliFactory' => 'ZendServer\DepH\Db\MysqliFactory',
39+
'Params' => 'ZendServer\DepH\Params\Params',
40+
'Log' => 'ZendServer\DepH\Log\Log',
41+
'Path' => 'ZendServer\DepH\Path\Path',
42+
'ZendDebugger' => 'ZendServer\DepH\Debugger\ZendDebugger',
43+
),
44+
'initializers' => array(
45+
'ZendServer\DepH\ServiceManager\Initializer\EventManagerInitializer',
46+
),
47+
'shared' => array(
48+
'Zend\EventManager\EventManager' => false,
49+
'ZendServer\DepH\File\Template' => false,
50+
),
51+
);
52+
}
53+
54+
/**
55+
* @return array
56+
*/
57+
public function __invoke()
58+
{
59+
return array(
60+
'dependencies' => $this->getDependencyConfig(),
61+
);
62+
}
63+
64+
}

src/Debugger/ZendDebugger.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace ZendServer\DepH\Debugger;
77

8+
use ZendServer\DepH\Deployment\Deployment;
89
use ZendServer\DepH\Log\LogAwareInterface;
910

1011
class ZendDebugger implements LogAwareInterface
@@ -18,7 +19,17 @@ class ZendDebugger implements LogAwareInterface
1819
* @var \ZendServer\DepH\Log\Log
1920
*/
2021
private $log;
21-
22+
23+
/**
24+
* ZendDebugger constructor.
25+
*
26+
* @param \ZendServer\DepH\Deployment\Deployment $deployment
27+
*/
28+
public function __construct(Deployment $deployment)
29+
{
30+
$this->setDeployment($deployment);
31+
}
32+
2233
/**
2334
* Starts a Zend debug session on client with given IP.
2435
* Please note, that the original call will terminate at the end of this script,
@@ -57,7 +68,7 @@ public function start ($clientIP, $port = 10137)
5768
/**
5869
* @param \ZendServer\DepH\Deployment\Deployment $deployment
5970
*/
60-
public function setDeployment(\ZendServer\DepH\Deployment\Deployment $deployment) {
71+
public function setDeployment(Deployment $deployment) {
6172
$this->deployment = $deployment;
6273
}
6374

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace ZendServer\DepH\Debugger;
3+
4+
use Zend\ServiceManager\FactoryInterface;
5+
use Zend\ServiceManager\ServiceLocatorInterface;
6+
7+
class ZendDebuggerFactory implements FactoryInterface
8+
{
9+
10+
/**
11+
* {@inheritdoc}
12+
*
13+
* @return ZendDebugger
14+
*/
15+
public function createService(ServiceLocatorInterface $serviceLocator)
16+
{
17+
return new ZendDebugger($serviceLocator->get('Deployment'));
18+
}
19+
}

src/Deployment/Deployment.php

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
namespace ZendServer\DepH\Deployment;
77

8-
use Zend\EventManager\EventManagerInterface;
8+
use Zend\EventManager\EventManager;
99
use 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

Comments
 (0)