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

[FEATURE] Use new API of typo3/cms-composer-installers #531

Merged
merged 1 commit into from
Aug 14, 2017
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ script:
- typo3cms commandreference:render > /dev/null 2>&1 && test -z "$(git diff --shortstat 2> /dev/null | tail -n1)";
- >
echo "Running php lint…";
if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" ]]; then rm -rf Classes/Composer/InstallerScript; fi;
find . -name \*.php ! -path "./.Build/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;;
git checkout Classes/Composer/InstallerScript;
- >
echo "Running unit and functional tests…";
.Build/bin/phpunit;
Expand Down
17 changes: 12 additions & 5 deletions Classes/Composer/InstallerScript/CopyTypo3Directory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Composer\InstallerScript;

/*
Expand All @@ -14,17 +15,18 @@
*/

use Composer\Script\Event as ScriptEvent;
use Helhum\Typo3ConsolePlugin\InstallerScriptInterface;
use Composer\Semver\Constraint\EmptyConstraint;
use TYPO3\CMS\Composer\Plugin\Config as Typo3Config;
use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;
use TYPO3\CMS\Composer\Plugin\Util\Filesystem;

class CopyTypo3Directory implements InstallerScriptInterface
class CopyTypo3Directory implements InstallerScript
{
/**
* @param ScriptEvent $event
* @return bool
*/
public function shouldRun(ScriptEvent $event)
private function shouldRun(ScriptEvent $event): bool
{
// Only run on Windows and only when we are the root package (made for Appveyor tests)
return DIRECTORY_SEPARATOR === '\\' && (getenv('TYPO3_CONSOLE_SUB_PROCESS') || $event->getComposer()->getPackage()->getName() === 'helhum/typo3-console');
Expand All @@ -36,13 +38,18 @@ public function shouldRun(ScriptEvent $event)
* @return bool
* @internal
*/
public function run(ScriptEvent $event)
public function run(ScriptEvent $event): bool
{
if (!$this->shouldRun($event)) {
return true;
}

$io = $event->getIO();
$composer = $event->getComposer();
$typo3Config = Typo3Config::load($composer);
$webDir = $typo3Config->get('web-dir');
$typo3Dir = $typo3Config->get('cms-package-dir');
$typo3Package = $event->getComposer()->getRepositoryManager()->getLocalRepository()->findPackage('typo3/cms', new EmptyConstraint());
$typo3Dir = $event->getComposer()->getInstallationManager()->getInstallPath($typo3Package);
if (is_link("$webDir/typo3")) {
rmdir("$webDir/typo3");
$filesystem = new Filesystem();
Expand Down
21 changes: 11 additions & 10 deletions Classes/Composer/InstallerScript/GeneratePackageStates.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Composer\InstallerScript;

/*
Expand All @@ -17,20 +18,21 @@
use Composer\Util\Filesystem;
use Helhum\Typo3Console\Mvc\Cli\CommandDispatcher;
use Helhum\Typo3ConsolePlugin\Config as PluginConfig;
use Helhum\Typo3ConsolePlugin\InstallerScriptInterface;
use TYPO3\CMS\Composer\Plugin\Config as Typo3Config;
use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;

class GeneratePackageStates implements InstallerScriptInterface
class GeneratePackageStates implements InstallerScript
{
/**
* @param ScriptEvent $event
* @return bool
*/
public function shouldRun(ScriptEvent $event)
private function shouldRun(ScriptEvent $event): bool
{
if (!getenv('TYPO3_CONSOLE_FEATURE_GENERATE_PACKAGE_STATES')) {
return false;
}

$io = $event->getIO();
$composer = $event->getComposer();
$pluginConfig = PluginConfig::load($io, $composer->getConfig());
Expand All @@ -42,16 +44,12 @@ public function shouldRun(ScriptEvent $event)
return false;
}

if ($typo3PluginConfig->get('prepare-web-dir') === false) {
return false;
}

if (!getenv('TYPO3_CONSOLE_TEST_SETUP') && $composer->getPackage()->getName() === 'helhum/typo3-console') {
return false;
}

// Ensure we have at least the typo3conf folder present
(new Filesystem())->ensureDirectoryExists($typo3PluginConfig->get('web-dir') . '/typo3conf');
(new Filesystem())->ensureDirectoryExists($typo3PluginConfig->get('root-dir') . '/typo3conf');
return true;
}

Expand All @@ -61,10 +59,13 @@ public function shouldRun(ScriptEvent $event)
* @return bool
* @internal
*/
public function run(ScriptEvent $event)
public function run(ScriptEvent $event): bool
{
$io = $event->getIO();
if (!$this->shouldRun($event)) {
return true;
}

$io = $event->getIO();
$commandDispatcher = CommandDispatcher::createFromComposerRun($event);
$commandOptions = [
'frameworkExtensions' => (string)getenv('TYPO3_ACTIVE_FRAMEWORK_EXTENSIONS'),
Expand Down
13 changes: 9 additions & 4 deletions Classes/Composer/InstallerScript/InstallDummyExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Composer\InstallerScript;

/*
Expand All @@ -15,20 +16,20 @@

use Composer\Script\Event as ScriptEvent;
use Helhum\Typo3ConsolePlugin\Config as PluginConfig;
use Helhum\Typo3ConsolePlugin\InstallerScriptInterface;
use TYPO3\CMS\Composer\Plugin\Config as Typo3Config;
use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;
use TYPO3\CMS\Composer\Plugin\Util\Filesystem;

/**
* @deprecated will be removed with 5.0
*/
class InstallDummyExtension implements InstallerScriptInterface
class InstallDummyExtension implements InstallerScript
{
/**
* @param ScriptEvent $event
* @return bool
*/
public function shouldRun(ScriptEvent $event)
private function shouldRun(ScriptEvent $event): bool
{
return $event->getComposer()->getPackage()->getName() !== 'helhum/typo3-console';
}
Expand All @@ -39,8 +40,12 @@ public function shouldRun(ScriptEvent $event)
* @return bool
* @internal
*/
public function run(ScriptEvent $event)
public function run(ScriptEvent $event): bool
{
if (!$this->shouldRun($event)) {
return true;
}

$io = $event->getIO();
$composer = $event->getComposer();

Expand Down
18 changes: 4 additions & 14 deletions Classes/Composer/InstallerScript/PopulateCommandConfiguration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Composer\InstallerScript;

/*
Expand All @@ -14,25 +15,14 @@
*/

use Composer\Script\Event as ScriptEvent;
use Helhum\Typo3ConsolePlugin\InstallerScriptInterface;
use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;

/**
* Reads console command configuration files from all composer packages in the current project
* and writes a file with all command configurations accumulated
*/
class PopulateCommandConfiguration implements InstallerScriptInterface
class PopulateCommandConfiguration implements InstallerScript
{
/**
* This method is called first. setupConsole is not called if this returns false
*
* @param ScriptEvent $event
* @return bool
*/
public function shouldRun(ScriptEvent $event)
{
return true;
}

/**
* Called from Composer
*
Expand All @@ -41,7 +31,7 @@ public function shouldRun(ScriptEvent $event)
* @return bool
* @internal
*/
public function run(ScriptEvent $event)
public function run(ScriptEvent $event): bool
{
$composer = $event->getComposer();
$composerConfig = $composer->getConfig();
Expand Down
50 changes: 29 additions & 21 deletions Classes/Composer/InstallerScripts.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Composer;

/*
Expand All @@ -13,42 +14,49 @@
*
*/

use Composer\Script\Event;
use Composer\Script\Event as ScriptEvent;
use Composer\Semver\Constraint\EmptyConstraint;
use Helhum\Typo3Console\Composer\InstallerScript\CopyTypo3Directory;
use Helhum\Typo3Console\Composer\InstallerScript\GeneratePackageStates;
use Helhum\Typo3Console\Composer\InstallerScript\InstallDummyExtension;
use Helhum\Typo3Console\Composer\InstallerScript\PopulateCommandConfiguration;
use Helhum\Typo3ConsolePlugin\ScriptDispatcher;
use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\AutoloadConnector;
use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\WebDirectory;
use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration;
use TYPO3\CMS\Composer\Plugin\Core\ScriptDispatcher;

/**
* Class for Composer and Extension Manager install scripts
* Scripts executed on composer build time
*/
class InstallerScripts
class InstallerScripts implements InstallerScriptsRegistration
{
/**
* Scripts to execute when console is set up
* Allows to register one or more script objects that implement this interface
* This will be called in the Plugin right before the scripts are executed.
*
* @var array
*/
private static $scripts = [
100 => CopyTypo3Directory::class,
90 => PopulateCommandConfiguration::class,
80 => GeneratePackageStates::class,
70 => InstallDummyExtension::class,
];

/**
* Called from Composer Plugin
*
* @throws \RuntimeException
* @param Event $event
* @param ScriptDispatcher $scriptDispatcher
* @return void
* @internal
*/
public static function setupConsole()
public static function register(Event $event, ScriptDispatcher $scriptDispatcher)
{
foreach (self::$scripts as $priority => $scriptClass) {
ScriptDispatcher::addInstallerScript($scriptClass, $priority);
$scriptDispatcher->addInstallerScript(new PopulateCommandConfiguration(), 70);
if (
!(
class_exists(\TYPO3\CMS\Core\Composer\InstallerScripts::class)
|| class_exists(\Helhum\Typo3NoSymlinkInstall\Composer\InstallerScripts::class)
|| class_exists(\Helhum\Typo3SecureWeb\Composer\InstallerScripts::class)
)
&& $event->getComposer()->getRepositoryManager()->getLocalRepository()->findPackage('typo3/cms', new EmptyConstraint()) !== null
) {
// @deprecated can be removed once TYPO3 8 support is removed
$scriptDispatcher->addInstallerScript(new WebDirectory());
$scriptDispatcher->addInstallerScript(new AutoloadConnector());
$scriptDispatcher->addInstallerScript(new CopyTypo3Directory());
}
$scriptDispatcher->addInstallerScript(new GeneratePackageStates(), 40);
$scriptDispatcher->addInstallerScript(new InstallDummyExtension(), 40);
}

/**
Expand Down