You are here

class Provision_ComposerGitCreateProject in Aegir Deploy 7.3

@file The Provision_ComposerGitCreateProject class.

Hierarchy

Expanded class hierarchy of Provision_ComposerGitCreateProject

File

modules/platform_composer_git/drush/Provision/ComposerGitCreateProject.php, line 7
The Provision_ComposerGitCreateProject class.

View source
class Provision_ComposerGitCreateProject extends Provision_ShellCommand {

  // The prefix used for properties in Aegir contexts.
  protected $context_prefix = 'composer_git_';

  // List of properties to load from the Aegir context.
  protected $context_properties = [
    'path',
    'project_url',
    'version',
  ];

  // The local path in which we'll deploy the project.
  protected $path = FALSE;

  // The Composer package to use to create the project.
  protected $package = FALSE;

  // The version of the Composer package to use.
  protected $version = FALSE;
  public function validateProvisionVerify() {
    if ($this
      ->pathExists($this->path)) {
      return $this
        ->notice(dt('Composer project path already exists. Aborting.'));
    }
    else {
      return $this
        ->deployPlatform();
    }
  }
  protected function deployPlatform() {
    $this
      ->notice(dt('Deploying platform.'));
    return $this
      ->createProject();
  }
  protected function createProject() {
    $this
      ->notice(dt('Creating `:version` version of project from `:project_url` at `:path`', [
      ':version' => $this->version,
      ':project_url' => $this->project_url,
      ':path' => $this->path,
    ]));
    $commands = [
      $this
        ->buildCloneProjectCommand(),
      $this
        ->buildCheckoutVersionCommand(),
      $this
        ->buildCreateProjectCommand(),
    ];
    foreach ($commands as $command) {
      $result = $this
        ->execCommand($command);
    }
    return $result;
  }
  protected function buildCloneProjectCommand() {
    $command = 'git clone ';
    $command .= escapeshellarg(trim($this->project_url));
    $command .= ' ';
    $command .= escapeshellarg(trim($this->path));
    return $command;
  }
  protected function buildCheckoutVersionCommand() {
    $command = 'cd ';
    $command .= escapeshellarg(trim($this->path));
    $command .= ' && git checkout ';
    $command .= escapeshellarg(trim($this->version));
    return $command;
  }
  protected function buildCreateProjectCommand() {
    $command = 'cd ';
    $command .= escapeshellarg(trim($this->path));
    $command .= ' && composer create-project --no-dev --no-interaction --no-progress';
    return $command;
  }
  public function postProvisionDelete() {
    if ($this->path != d()->root) {
      $this
        ->notice(dt('Deleting Composer project path at: ') . d()->composer_git_path);
      _provision_recursive_delete($this->path);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Provision_ComposerGitCreateProject::$context_prefix protected property Overrides Provision_ShellCommand::$context_prefix
Provision_ComposerGitCreateProject::$context_properties protected property Overrides Provision_ShellCommand::$context_properties
Provision_ComposerGitCreateProject::$package protected property
Provision_ComposerGitCreateProject::$path protected property
Provision_ComposerGitCreateProject::$version protected property
Provision_ComposerGitCreateProject::buildCheckoutVersionCommand protected function
Provision_ComposerGitCreateProject::buildCloneProjectCommand protected function
Provision_ComposerGitCreateProject::buildCreateProjectCommand protected function
Provision_ComposerGitCreateProject::createProject protected function
Provision_ComposerGitCreateProject::deployPlatform protected function
Provision_ComposerGitCreateProject::postProvisionDelete public function
Provision_ComposerGitCreateProject::validateProvisionVerify public function
Provision_ShellCommand::abort protected function
Provision_ShellCommand::error protected function
Provision_ShellCommand::execCommand protected function Run a command in a subprocess, and stream the output.
Provision_ShellCommand::log protected function
Provision_ShellCommand::notice protected function
Provision_ShellCommand::pathExists protected function
Provision_ShellCommand::runCommand protected function Run a command in a subshell, and post the output once complete.
Provision_ShellCommand::setProperty protected function
Provision_ShellCommand::success protected function
Provision_ShellCommand::warning protected function
Provision_ShellCommand::__construct public function Initialize properties from the current Aegir context.