1: <?php
2:
3: namespace Himedia\Padocc;
4:
5: use Himedia\Padocc\Task\Base\ExternalProperty;
6: use Himedia\Padocc\Task\Base\Project;
7:
8: 9: 10: 11: 12:
13: final class Deployment
14: {
15: 16: 17:
18: private $oDIContainer;
19:
20: 21: 22:
23: private $aConfig;
24:
25: 26: 27: 28: 29:
30: public function __construct(DIContainerInterface $oDIContainer)
31: {
32: $this->aConfig = $oDIContainer->getConfig();
33: $this->oDIContainer = $oDIContainer;
34: }
35:
36: 37: 38: 39: 40:
41: public function getContainer()
42: {
43: return $this->oDIContainer;
44: }
45:
46: 47: 48: 49: 50: 51: 52: 53: 54:
55: public function run($xmlPathOrString, $sEnvironment, $sExecutionID, array $aExternalProperties, $sRollbackID)
56: {
57: $oLogger = $this->getContainer()->getLogger();
58:
59:
60: $oXmlProject = Project::getSXEProject($xmlPathOrString);
61:
62: if (file_exists($xmlPathOrString)) {
63: $oLogger->info(sprintf('Project loaded from file %s', realpath($xmlPathOrString)));
64: }
65:
66: $this->registerProperties(array(
67: 'project_name' => (string)$oXmlProject['name'],
68: 'environment_name' => $sEnvironment,
69: 'execution_id' => $sExecutionID,
70: 'tmpdir' => $this->aConfig['dir']['tmp'] . '/deploy_' . $sExecutionID,
71: 'rollback_id' => $sRollbackID
72: ));
73:
74: $this->registerProperties($aExternalProperties, true, ExternalProperty::EXTERNAL_PROPERTY_PREFIX);
75:
76: $oProject = new Project($oXmlProject, $sEnvironment, $this->getContainer());
77:
78: $oLogger->info('Check tasks:+++');
79: $oProject->setUp();
80:
81: $oLogger->info('---Execute tasks:+++');
82: $oProject->execute();
83:
84: $oLogger->info('---');
85: }
86:
87: 88: 89: 90: 91: 92: 93:
94: private function registerProperties(array $aProperties, $bEscape = false, $sPrefix = '')
95: {
96: foreach ($aProperties as $sName => $sValue) {
97: $sQualifiedName = $sPrefix . $sName;
98: $sFilteredValue = $bEscape ? str_replace(' ', ' ', $sValue) : $sValue;
99: $this->getContainer()->getPropertiesAdapter()->setProperty($sQualifiedName, $sFilteredValue);
100: }
101: }
102: }
103: