Overview

Namespaces

  • GAubry
    • ErrorHandler
    • Helpers
    • Logger
    • Shell
  • Himedia
    • Padocc
      • DB
      • Minifier
      • Numbering
      • Properties
      • Task
        • Base
        • Extended
  • None
  • Psr
    • Log

Classes

  • AttributeProperties
  • Deployment
  • DeploymentStatus
  • DIContainer
  • Padocc
  • Task

Interfaces

  • DIContainerInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  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:  * Deployment
 10:  *
 11:  * @author Geoffroy AUBRY <gaubry@hi-media.com>
 12:  */
 13: final class Deployment
 14: {
 15:     /**
 16:      * @var DIContainerInterface
 17:      */
 18:     private $oDIContainer;
 19: 
 20:     /**
 21:      * @var array
 22:      */
 23:     private $aConfig;
 24: 
 25:     /**
 26:      * Constructor.
 27:      *
 28:      * @param DIContainerInterface $oDIContainer Service container
 29:      */
 30:     public function __construct(DIContainerInterface $oDIContainer)
 31:     {
 32:         $this->aConfig      = $oDIContainer->getConfig();
 33:         $this->oDIContainer = $oDIContainer;
 34:     }
 35: 
 36:     /**
 37:      * Gets the service container.
 38:      *
 39:      * @return DIContainerInterface
 40:      */
 41:     public function getContainer()
 42:     {
 43:         return $this->oDIContainer;
 44:     }
 45: 
 46:     /**
 47:      * Exécute le déploiement.
 48:      *
 49:      * @param string $xmlPathOrString     Path to the project XML configuration file or XML file content.
 50:      * @param string $sEnvironment        Name of the environment where to deploy.
 51:      * @param string $sExecutionID        au format YYYYMMDDHHMMSS_xxxxx, où x est un nombre aléatoire
 52:      * @param array  $aExternalProperties tableau associatif nom/valeur des propriétés externes.
 53:      * @param string $sRollbackID         identifiant de déploiement sur lequel effectuer un rollback
 54:      */
 55:     public function run($xmlPathOrString, $sEnvironment, $sExecutionID, array $aExternalProperties, $sRollbackID)
 56:     {
 57:         $oLogger = $this->getContainer()->getLogger();
 58: 
 59:         // Interprets the project XML configuration into a SimpleXML object
 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:      * Registers external properties.
 89:      *
 90:      * @param array  $aProperties
 91:      * @param bool   $bEscape
 92:      * @param string $sPrefix
 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('&#0160;', ' ', $sValue) : $sValue;
 99:             $this->getContainer()->getPropertiesAdapter()->setProperty($sQualifiedName, $sFilteredValue);
100:         }
101:     }
102: }
103: 
Platform for Automatized Deployments with pOwerful Concise Configuration API documentation generated by ApiGen 2.8.0