-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
211 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Pantheon\D9ify\Site\Sources; | ||
|
||
use Pantheon\D9ify\Site\InfoInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Interface SiteSourceInterface | ||
* | ||
* @package D9ify\Site\Sources | ||
*/ | ||
interface SiteSourceInterface | ||
{ | ||
|
||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function valid(): bool; | ||
|
||
/** | ||
* @param \D9ify\Site\Sources\OutputInterface $output | ||
* | ||
* @return bool | ||
*/ | ||
public function cloneFiles(OutputInterface $output): bool; | ||
|
||
/** | ||
* @return \D9ify\Site\InfoInterface | ||
*/ | ||
public function getSiteInfo(): InfoInterface; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getConnectionInfo(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Pantheon\D9ify\Site\Sources; | ||
|
||
use CzProject\GitPhp\GitRepository; | ||
use Pantheon\D9ify\Traits\CommandExecutorTrait; | ||
use Pantheon\D9ify\Traits\DefaultClonePathTrait; | ||
use Pantheon\D9ify\Traits\SiteInfoTrait; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class Terminus | ||
* @package D9ify\Site\Sources | ||
*/ | ||
class Terminus implements SiteSourceInterface | ||
{ | ||
|
||
use CommandExecutorTrait; | ||
use SiteInfoTrait; | ||
use DefaultClonePathTrait; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected string $siteID; | ||
/** | ||
* @var string|mixed | ||
*/ | ||
protected string $referenceEnvironment; | ||
|
||
/** | ||
* Terminus constructor. | ||
* @param $siteID | ||
* @param string $referenceEnvironment | ||
*/ | ||
public function __construct($siteID, $referenceEnvironment = "live") | ||
{ | ||
$this->setSiteInfoFromSiteId($siteID); | ||
$this->referenceEnvironment = $referenceEnvironment; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function valid(): bool | ||
{ | ||
return $this->getSiteInfo()->valid(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getConnectionInfo(): array | ||
{ | ||
return $this->execute("terminus connection:info %s.dev --format=json", [ | ||
$this->getSiteInfo()->getName() | ||
]); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getClonePath():string | ||
{ | ||
return $this->getDefaultClonePathBase() . DIRECTORY_SEPARATOR . $this->getSiteInfo()->getName(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getGitCommand():string | ||
{ | ||
return str_replace( | ||
$this->getSiteInfo()->getName(), | ||
$this->getClonePath(), | ||
$this->getConnectionInfo()['git_command'] | ||
); | ||
} | ||
|
||
/** | ||
* @return bool | ||
* @throws \Exception | ||
*/ | ||
public function cloneFiles(OutputInterface $output): bool | ||
{ | ||
|
||
$this->execute($this->getGitCommand()); | ||
if ($this->getLastStatus() !== 0) { | ||
throw new \Exception("Cannot clone site with terminus command." . | ||
join(PHP_EOL, $this->execResult)); | ||
} | ||
$output->writeln( | ||
sprintf( | ||
"Site Code Folder: %s", | ||
$this->clonePath->getRealPath() | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters