Skip to content

Instantly share code, notes, and snippets.

@antonkril
Last active May 2, 2016 08:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save antonkril/9b7616c67b874738fca9897ca16c4fc9 to your computer and use it in GitHub Desktop.
Save antonkril/9b7616c67b874738fca9897ca16c4fc9 to your computer and use it in GitHub Desktop.
Hackathon Extension Point for Setup App
<type name="wrapperList">
<arguments>
<argument name="wrappers" xsi:type="array">
<item xsi:type="string">UpgradeCommand</item>
<item xsi:type="array">
<item xsi:type="array">
<item xsi:type="object">Wrapper</item>
</item>
</item>
</argument>
</arguments>
</type>
<?php
namespace Magento\Framework\Console;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Application as SymfonyApplication;
use Magento\Framework\App\Bootstrap;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Shell\ComplexParameter;
use Magento\Setup\Console\CompilerPreparation;
/**
* Magento 2 CLI Application. This is the hood for all command line tools supported by Magento
*
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Cli extends SymfonyApplication
{
/**
* Gets application commands
*
* @return array
*/
protected function getApplicationCommands()
{
$commands = [];
try {
$bootstrapParam = new ComplexParameter(self::INPUT_KEY_BOOTSTRAP);
$params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER);
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
/** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
$omProvider = $this->serviceManager->get('Magento\Setup\Model\ObjectManagerProvider');
$omProvider->setObjectManager($objectManager);
if (class_exists('Magento\Setup\Console\CommandList')) {
$setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager);
$commands = array_merge($commands, $setupCommandList->getCommands());
}
if ($objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) {
/** @var \Magento\Framework\Console\CommandList $commandList */
$commandList = $objectManager->create('Magento\Framework\Console\CommandList');
$commands = array_merge($commands, $commandList->getCommands());
}
$commands = array_merge($commands, $this->getVendorCommands($objectManager));
$commands = $objectManager->create('wrapperList')->decorate($commands);
} catch (\Exception $e) {
$this->initException = $e;
}
return $commands;
}
}
<?php
class WrapperList
{
public function decorate($commands)
{
foreach($commands as $key => $command) {
$class = get_class($command);
if (isset($this->decorators[$class])) {
foreach ($this->decorators[$class] as $decorator) {
$commands[$key] = $this->decoratorFactory->care($decorator, ['subject' => $commands[$key]]);
}
}
}
return $commands;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment