Final Class Yiisoft\YiiDevTool\App\Command\Git\PullCommand
| Inheritance | Yiisoft\YiiDevTool\App\Command\Git\PullCommand » Yiisoft\YiiDevTool\App\Component\Console\PackageCommand » Symfony\Component\Console\Command\Command |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| getApplication() | Yiisoft\YiiDevTool\App\Component\Console\PackageCommand |
Protected Methods
Method Details
Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::afterProcessingPackages()
Override this method in a subclass if you want to do something after processing the packages.
For example, link the packages with each other.
| protected void afterProcessingPackages ( \Symfony\Component\Console\Input\InputInterface $input ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
protected function afterProcessingPackages(InputInterface $input): void
{
}
Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::areTargetPackagesSpecifiedExplicitly()
| protected boolean areTargetPackagesSpecifiedExplicitly ( ) |
protected function areTargetPackagesSpecifiedExplicitly(): bool
{
if ($this->targetPackagesSpecifiedExplicitly === null) {
throw new RuntimeException('Target packages are not initialized.');
}
return $this->targetPackagesSpecifiedExplicitly;
}
Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::beforeProcessingPackages()
Override this method in a subclass if you want to do something before processing the packages.
For example, check the input arguments.
| protected void beforeProcessingPackages ( \Symfony\Component\Console\Input\InputInterface $input ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
protected function beforeProcessingPackages(InputInterface $input): void
{
}
| protected boolean checkSSHConnection ( ) |
protected function checkSSHConnection(): bool
{
$process = new Process(['ssh', '-T', 'git@github.com']);
$process
->setTimeout(null)
->run();
if ($process->getExitCode() !== 1) {
$this
->getIO()
->error([
'Checking access to github.com ... DENIED',
'Error: ' . $process->getErrorOutput(),
'Seems like you have not installed SSH key to you Github account.',
'Key is required to work with repository via SSH.',
'See here for instructions: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account',
]);
return false;
}
return true;
}
| protected void configure ( ) |
protected function configure(): void
{
$this->setAliases(['pull']);
parent::configure();
}
| protected boolean doesPackageContainErrors ( Yiisoft\YiiDevTool\App\Component\Package\Package $package ) | ||
| $package | Yiisoft\YiiDevTool\App\Component\Package\Package | |
protected function doesPackageContainErrors(Package $package): bool
{
return $this->errorList->has($package);
}
| protected integer execute ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
| $output | \Symfony\Component\Console\Output\OutputInterface | |
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->initPackageList();
$this->initTargetPackages($input);
$io = $this->getIO();
$this->beforeProcessingPackages($input);
$packages = $this->getTargetPackages();
sort($packages);
foreach ($packages as $package) {
if ($this->isCurrentInstallationValid($package)) {
$this->processPackage($package);
}
}
$io->clearPreparedPackageHeader();
$this->afterProcessingPackages($input);
$this->showPackageErrors();
if ($io->nothingHasBeenOutput()) {
$message = $this->getMessageWhenNothingHasBeenOutput();
if ($message !== null) {
$io
->important()
->info($message);
}
}
return Command::SUCCESS;
}
Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::getAppRootDir()
Use this method to get a root directory of the tool.
Commands and components can be moved as a result of refactoring, so you should not rely on their location in the file system.
| protected string getAppRootDir ( ) | ||
| return | string |
Path to the root directory of the tool WITH a TRAILING SLASH. |
|---|---|---|
protected function getAppRootDir(): string
{
return rtrim($this
->getApplication()
->getRootDir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
| public Yiisoft\YiiDevTool\App\YiiDevToolApplication getApplication ( ) | ||
| return | Yiisoft\YiiDevTool\App\YiiDevToolApplication | |
|---|---|---|
| protected Yiisoft\YiiDevTool\App\Component\Package\PackageErrorList getErrorsList ( ) |
protected function getErrorsList(): PackageErrorList
{
return $this->errorList;
}
| protected string getExampleCommandPrefix ( ) | ||
| return | string |
Console command prefix that works in current environment. |
|---|---|---|
protected function getExampleCommandPrefix(): string
{
$shell = getenv('SHELL');
$isBash = ($shell && stripos($shell, 'bash')) !== false;
return $isBash ? './' : '';
}
| protected Yiisoft\YiiDevTool\App\Component\Console\OutputManager getIO ( ) |
protected function getIO(): OutputManager
{
if ($this->io === null) {
throw new RuntimeException('IO is not initialized.');
}
return $this->io;
}
| protected string|null getMessageWhenNothingHasBeenOutput ( ) |
protected function getMessageWhenNothingHasBeenOutput(): ?string
{
return '<em>Nothing to pull</em>';
}
| protected Yiisoft\YiiDevTool\App\Component\Package\PackageList getPackageList ( ) |
protected function getPackageList(): PackageList
{
return $this->packageList;
}
| protected Yiisoft\YiiDevTool\App\Component\Package\Package[] getTargetPackages ( ) |
protected function getTargetPackages(): array
{
if ($this->targetPackages === null) {
throw new RuntimeException('Target packages are not initialized.');
}
return $this->targetPackages;
}
| protected void initPackageList ( ) |
protected function initPackageList(): void
{
$io = $this->getIO();
try {
$ownerPackages = require $this->getAppRootDir() . 'owner-packages.php';
if (!preg_match('/^[a-z0-9][a-z0-9-]*[a-z0-9]$/i', $ownerPackages)) {
$io->error([
'The packages owner can only contain the characters [a-z0-9-], and the character \'-\' cannot appear at the beginning or at the end.',
'See <file>owner-packages.php</file> to set the packages owner.',
]);
exit(1);
}
$packagesRootDir = $this->getApplication()->getConfig('packagesRootDir') ?? $this->getAppRootDir() . 'dev';
$this->packageList = new PackageList(
$ownerPackages,
$this->getAppRootDir() . 'packages.php',
packagesRootDir: $packagesRootDir,
);
$this->errorList = new PackageErrorList();
} catch (InvalidArgumentException $e) {
$io->error([
'Invalid local package configuration <file>packages.local.php</file>',
$e->getMessage(),
'See <file>packages.local.php.example</file> for configuration examples.',
]);
exit(1);
}
}
| protected void initTargetPackages ( \Symfony\Component\Console\Input\InputInterface $input ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
protected function initTargetPackages(InputInterface $input): void
{
if ($this->packageList === null) {
throw new RuntimeException('Package list is not initialized.');
}
$io = $this->getIO();
$commaSeparatedPackageIds = $input->getArgument('packages');
if ($commaSeparatedPackageIds === null) {
$this->targetPackagesSpecifiedExplicitly = false;
$this->targetPackages = $this->packageList->getEnabledPackages();
return;
}
$targetPackageIds = array_unique(explode(',', $commaSeparatedPackageIds));
$problemsFound = false;
$targetPackages = [];
foreach ($targetPackageIds as $targetPackageId) {
$package = $this->packageList->getPackage($targetPackageId);
if ($package === null) {
$io->error("Package <package>$targetPackageId</package> not found in <file>packages.php</file>");
$problemsFound = true;
continue;
}
if ($package->disabled()) {
$io->error("Package <package>$targetPackageId</package> disabled in <file>packages.local.php</file>");
$problemsFound = true;
continue;
}
$targetPackages[] = $package;
}
if ($problemsFound) {
exit(1);
}
$this->targetPackagesSpecifiedExplicitly = true;
$this->targetPackages = $targetPackages;
}
| protected mixed initialize ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
| $output | \Symfony\Component\Console\Output\OutputInterface | |
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->io = new OutputManager(new YiiDevToolStyle($input, $output));
}
| protected void processPackage ( Yiisoft\YiiDevTool\App\Component\Package\Package $package ) | ||
| $package | Yiisoft\YiiDevTool\App\Component\Package\Package | |
protected function processPackage(Package $package): void
{
$io = $this->getIO();
$io->preparePackageHeader($package, 'Pulling package {package}');
$process = new Process(['git', 'pull'], $package->getPath());
$process
->setTimeout(null)
->run();
if ($process->isSuccessful()) {
$output = $process->getOutput() . $process->getErrorOutput();
$io
->important(trim($output) !== 'Already up to date.')
->info($output);
$io->done();
} else {
$output = $process->getErrorOutput();
$io
->important()
->info($output);
$io->error([
"An error occurred during pulling package <package>{$package->getId()}</package> repository.",
'Package pull aborted.',
]);
$this->registerPackageError($package, $output, 'pulling package repository');
}
}
| protected void registerPackageError ( Yiisoft\YiiDevTool\App\Component\Package\Package $package, string $message, string $during ) | ||
| $package | Yiisoft\YiiDevTool\App\Component\Package\Package | |
| $message | string | |
| $during | string | |
protected function registerPackageError(Package $package, string $message, string $during): void
{
$this->errorList->set($package, $message, $during);
}
Signup or Login in order to comment.