Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to add low level commands for extensions #136

Merged
merged 2 commits into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
language: php

branches:
only:
- master
- 1.1.x
- develop

php:
- 5.5
- 5.6
Expand Down
2 changes: 1 addition & 1 deletion Classes/Command/BackendCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Helhum\Typo3Console\Mvc\Controller\CommandController;

/**
* Class SchedulerCommandController
* Class BackendCommandController
*/
class BackendCommandController extends CommandController
{
Expand Down
2 changes: 2 additions & 0 deletions Classes/Core/ConsoleBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Helhum\Typo3Console\Core\Booting\Sequence;
use Helhum\Typo3Console\Error\ExceptionHandler;
use Helhum\Typo3Console\Mvc\Cli\CommandManager;
use Helhum\Typo3Console\Mvc\Cli\RequestHandler;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility;
Expand Down Expand Up @@ -94,6 +95,7 @@ public function run($classLoader = null)

$this->initializeCommandManager();
$this->initializePackageManagement();
$this->registerRequestHandler(new RequestHandler($this));

$requestHandler = $this->resolveCliRequestHandler();
$requestHandler->handleRequest();
Expand Down
48 changes: 48 additions & 0 deletions Classes/Mvc/Cli/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

use Helhum\Typo3Console\Core\ConsoleBootstrap;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Package\PackageInterface;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;

Expand Down Expand Up @@ -105,13 +107,59 @@ public function handleRequest()
*/
protected function boot($commandIdentifier)
{
$this->registerCommands();
$sequence = $this->bootstrap->buildBootingSequenceForCommand($commandIdentifier);
$sequence->invoke($this->bootstrap);

$this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
$this->dispatcher = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Dispatcher::class);
}

protected function registerCommands()
{
/** @var PackageManager $packageManager */
$packageManager = $this->bootstrap->getEarlyInstance(PackageManager::class);
foreach ($packageManager->getActivePackages() as $package) {
$possibleCommandsFileName = $package->getPackagePath() . '/Configuration/Console/Commands.php';
if (!file_exists($possibleCommandsFileName)) {
continue;
}
$commandConfiguration = require $possibleCommandsFileName;
$this->ensureValidCommandsConfiguration($commandConfiguration, $package);
foreach ($commandConfiguration['controllers'] as $controller) {
$this->bootstrap->getCommandManager()->registerCommandController($controller);
}
foreach ($commandConfiguration['runLevels'] as $commandIdentifier => $runLevel) {
$this->bootstrap->setRunLevelForCommand($commandIdentifier, $runLevel);
}
foreach ($commandConfiguration['bootingSteps'] as $commandIdentifier => $bootingSteps) {
foreach ((array)$bootingSteps as $bootingStep) {
$this->bootstrap->addBootingStepForCommand($commandIdentifier, $bootingStep);
}
}
}
}

/**
* @param mixed $commandConfiguration
* @param PackageInterface $package
*/
protected function ensureValidCommandsConfiguration($commandConfiguration, PackageInterface $package)
{
if (
!is_array($commandConfiguration)
|| count($commandConfiguration) !== 3
|| !isset($commandConfiguration['controllers'])
|| !is_array($commandConfiguration['controllers'])
|| !isset($commandConfiguration['runLevels'])
|| !is_array($commandConfiguration['runLevels'])
|| !isset($commandConfiguration['bootingSteps'])
|| !is_array($commandConfiguration['bootingSteps'])
) {
throw new \RuntimeException($package->getPackageKey() . ' defines invalid commands in Configuration/Console/Commands.php', 1461186959);
}
}

protected function shutdown()
{
$this->bootstrap->shutdown();
Expand Down
87 changes: 0 additions & 87 deletions Classes/Package.php

This file was deleted.

15 changes: 0 additions & 15 deletions Classes/Package/UncachedPackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function init(Bootstrap $bootstrap)
$this->loadPackageStates();
$this->initializePackageObjects();
$this->initializeCompatibilityLoadedExtArray();

$this->getPackage('typo3_console')->bootPackage($bootstrap);
}

protected function loadPackageStates()
Expand All @@ -51,19 +49,6 @@ protected function loadPackageStates()
} else {
$this->registerPackagesFromConfiguration($this->packageStatesConfiguration['packages']);
}

if ($this->consolePackageBootRequired($this->getPackage('typo3_console'))) {
$this->packages['typo3_console'] = new \Helhum\Typo3Console\Package($this, 'typo3_console', $this->getPackage('typo3_console')->getPackagePath());
}
}

/**
* @param PackageInterface $consolePackage
* @return bool
*/
protected function consolePackageBootRequired($consolePackage)
{
return !$consolePackage instanceof \Helhum\Typo3Console\Package;
}

/**
Expand Down
28 changes: 28 additions & 0 deletions Configuration/Console/Commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
return array(
'controllers' => array(
\Helhum\Typo3Console\Command\CacheCommandController::class,
\Helhum\Typo3Console\Command\BackendCommandController::class,
\Helhum\Typo3Console\Command\SchedulerCommandController::class,
\Helhum\Typo3Console\Command\CleanupCommandController::class,
\Helhum\Typo3Console\Command\DocumentationCommandController::class,
\Helhum\Typo3Console\Command\InstallCommandController::class,
\Helhum\Typo3Console\Command\DatabaseCommandController::class,
\Helhum\Typo3Console\Command\ConfigurationCommandController::class,
\Helhum\Typo3Console\Command\FrontendCommandController::class,
),
'runLevels' => array(
'typo3_console:install:databasedata' => \Helhum\Typo3Console\Core\Booting\RunLevel::LEVEL_MINIMAL ,
'typo3_console:install:defaultconfiguration' => \Helhum\Typo3Console\Core\Booting\RunLevel::LEVEL_MINIMAL ,
'typo3_console:install:*' => \Helhum\Typo3Console\Core\Booting\RunLevel::LEVEL_COMPILE ,
'typo3_console:cache:flush' => \Helhum\Typo3Console\Core\Booting\RunLevel::LEVEL_COMPILE ,
),
'bootingSteps' => array(
'typo3_console:install:databasedata' => array(
'helhum.typo3console:database',
'helhum.typo3console:enablecorecaches'
),
'typo3_console:install:defaultconfiguration' => array('helhum.typo3console:database'),
'typo3_console:cache:flush' => array('helhum.typo3console:database'),
)
);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": ".Build/Web",
"Package": {
"partOfMinimalUsableSystem": true
"protected": true
}
}
}
Expand Down