[FEATURE] Add code to generate entry scripts on composer run 02/53602/7
authorHelmut Hummel <typo3@helhum.io>
Tue, 25 Jul 2017 14:28:13 +0000 (16:28 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 31 Jul 2017 05:10:14 +0000 (07:10 +0200)
With the new composer installers versions,
the core package itself (in fact any composer package)
can add scripts to be run on composer build time.

Use this API to add scripts to TYPO3,
that will create the entry scripts for frontend,
backend and install tool

We do this in a way, that also works if these system extensions
are installed individually.

This also has the benefit, that we can adapt the core
with doing more things during composer build time
(e.g. maybe publishing assets) in the future,
or change the entry scripts to different locations,
without touching the plugin any more.

Resolves: #81981
Releases: master
Change-Id: I3982bd5e73a14cdd54e83d0a7b3a1c93f2191efd
Reviewed-on: https://review.typo3.org/53602
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
13 files changed:
.gitignore
Build/.php_cs
Build/Scripts/cglFixMyCommit.sh
composer.json
composer.lock
index.php [deleted file]
typo3/index.php [deleted file]
typo3/install.php [deleted file]
typo3/sysext/backend/Classes/Composer/InstallerScripts.php [new file with mode: 0644]
typo3/sysext/core/Classes/Composer/InstallerScripts.php [new file with mode: 0644]
typo3/sysext/core/Classes/Composer/InstallerScripts/WebDirectory.php [new file with mode: 0644]
typo3/sysext/frontend/Classes/Composer/InstallerScripts.php [new file with mode: 0644]
typo3/sysext/install/Classes/Composer/InstallerScripts.php [new file with mode: 0644]

index bfe065c..7c2db8a 100644 (file)
@@ -39,8 +39,11 @@ typo3/sysext/*/Resources/Public/JavaScript/*.js.map
 phantomjsdriver.log
 #
 # Ignore composer stuff
-bin/*
-vendor/*
+/bin/*
+/vendor/*
+/index.php
+/typo3/index.php
+/typo3/install.php
 #
 # Ignore common TYPO3 CMS files/directories
 typo3temp/*
index 7259893..dc5933d 100644 (file)
@@ -37,6 +37,8 @@ $finder = PhpCsFixer\Finder::create()
     ->exclude('vendor')
     ->exclude('typo3conf')
     ->exclude('typo3temp')
+    ->notName('install.php')
+    ->notName('index.php')
     ->in(__DIR__ . '/../');
 // Return a Code Sniffing configuration using
 // all sniffers needed for PSR-2
@@ -76,7 +78,6 @@ return PhpCsFixer\Config::create()
         'no_short_bool_cast' => true,
         'no_unneeded_control_parentheses' => true,
         'phpdoc_no_empty_return' => true,
-        'no_blank_lines_after_phpdoc' => true,
         'phpdoc_trim' => true
     ])
     ->setFinder($finder);
index 0fe7d2f..9f35316 100755 (executable)
@@ -36,6 +36,7 @@ fi
 
 php_no_xdebug ./bin/php-cs-fixer fix \
     -v ${DRYRUN} \
+    --path-mode intersection \
     --config=Build/.php_cs \
     `echo ${DETECTED_FILES} | xargs ls -d 2>/dev/null`
 
index 50e44b2..2897106 100644 (file)
@@ -43,7 +43,7 @@
                "symfony/polyfill-mbstring": "^1.2",
                "doctrine/instantiator": "~1.0.4",
                "typo3/class-alias-loader": "^1.0",
-               "typo3/cms-composer-installers": "^1.2.8",
+               "typo3/cms-composer-installers": "^1.4.0@rc",
                "psr/http-message": "~1.0",
                "cogpowered/finediff": "~0.3.1",
                "mso/idna-convert": "^1.1.0",
index b70b946..c24d42c 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "c18ec8225643a1e9e1aae0108629cd38",
+    "content-hash": "cb6c37b20dd41e36057e0b54cbb338cb",
     "packages": [
         {
             "name": "cogpowered/finediff",
         },
         {
             "name": "typo3/cms-composer-installers",
-            "version": "1.3.1",
+            "version": "1.4.0-rc1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/TYPO3/CmsComposerInstallers.git",
-                "reference": "cb25a053cdba0fcc43a9f56f5e086f77eed6b916"
+                "reference": "07c6fe266b829ada1ea11a84926142fbb37b4069"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/TYPO3/CmsComposerInstallers/zipball/cb25a053cdba0fcc43a9f56f5e086f77eed6b916",
-                "reference": "cb25a053cdba0fcc43a9f56f5e086f77eed6b916",
+                "url": "https://api.github.com/repos/TYPO3/CmsComposerInstallers/zipball/07c6fe266b829ada1ea11a84926142fbb37b4069",
+                "reference": "07c6fe266b829ada1ea11a84926142fbb37b4069",
                 "shasum": ""
             },
             "require": {
-                "composer-plugin-api": "^1.0.0"
+                "composer-plugin-api": "^1.0.0",
+                "php": ">=7.0.0 <7.2"
             },
             "conflict": {
                 "composer/installers": "<1.0.24 || >1.0.24"
                 "netresearch/composer-installers": "*"
             },
             "require-dev": {
-                "composer/composer": "1.*"
+                "composer/composer": "^1.2"
             },
             "type": "composer-plugin",
             "extra": {
                 "class": "TYPO3\\CMS\\Composer\\Installer\\Plugin",
                 "branch-alias": {
-                    "dev-master": "1.3.x-dev"
+                    "dev-master": "1.4.x-dev"
                 }
             },
             "autoload": {
                 "installer",
                 "typo3"
             ],
-            "time": "2016-07-05T09:38:42+00:00"
+            "time": "2017-07-26T14:34:07+00:00"
         },
         {
             "name": "typo3fluid/fluid",
     ],
     "aliases": [],
     "minimum-stability": "stable",
-    "stability-flags": [],
+    "stability-flags": {
+        "typo3/cms-composer-installers": 5
+    },
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": {
diff --git a/index.php b/index.php
deleted file mode 100644 (file)
index ee91334..0000000
--- a/index.php
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-require __DIR__ . '/typo3/sysext/frontend/Resources/Private/Php/frontend.php';
diff --git a/typo3/index.php b/typo3/index.php
deleted file mode 100644 (file)
index 4b06de8..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-require __DIR__ . '/sysext/backend/Resources/Private/Php/backend.php';
diff --git a/typo3/install.php b/typo3/install.php
deleted file mode 100644 (file)
index 07c456f..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-require __DIR__ . '/sysext/install/Resources/Private/Php/install.php';
diff --git a/typo3/sysext/backend/Classes/Composer/InstallerScripts.php b/typo3/sysext/backend/Classes/Composer/InstallerScripts.php
new file mode 100644 (file)
index 0000000..c9ea46a
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+declare(strict_types=1);
+namespace TYPO3\CMS\Backend\Composer;
+
+/*
+ * This file is part of the TYPO3 project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Composer\Script\Event;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\EntryPoint;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration;
+use TYPO3\CMS\Composer\Plugin\Core\ScriptDispatcher;
+
+/**
+ * Hook into Composer build to generate TYPO3 backend entry script
+ */
+class InstallerScripts implements InstallerScriptsRegistration
+{
+    /**
+     * @param Event $event
+     * @param ScriptDispatcher $scriptDispatcher
+     */
+    public static function register(Event $event, ScriptDispatcher $scriptDispatcher)
+    {
+        $scriptDispatcher->addInstallerScript(
+            new EntryPoint(
+                dirname(dirname(__DIR__)) . '/Resources/Private/Php/backend.php',
+                'typo3/index.php'
+            )
+        );
+    }
+}
diff --git a/typo3/sysext/core/Classes/Composer/InstallerScripts.php b/typo3/sysext/core/Classes/Composer/InstallerScripts.php
new file mode 100644 (file)
index 0000000..df5d396
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+declare(strict_types=1);
+namespace TYPO3\CMS\Core\Composer;
+
+/*
+ * This file is part of the TYPO3 project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Composer\Script\Event;
+use Composer\Semver\Constraint\EmptyConstraint;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration;
+use TYPO3\CMS\Composer\Plugin\Core\ScriptDispatcher;
+use TYPO3\CMS\Core\Composer\InstallerScripts\WebDirectory;
+
+/**
+ * Hook into Composer build to set up TYPO3 web directory if necessary
+ */
+class InstallerScripts implements InstallerScriptsRegistration
+{
+    /**
+     * @param Event $event
+     * @param ScriptDispatcher $scriptDispatcher
+     */
+    public static function register(Event $event, ScriptDispatcher $scriptDispatcher)
+    {
+        if (null !== $event->getComposer()->getRepositoryManager()->getLocalRepository()->findPackage('typo3/cms', new EmptyConstraint())) {
+            $scriptDispatcher->addInstallerScript(
+                new WebDirectory(),
+                60
+            );
+        }
+    }
+}
diff --git a/typo3/sysext/core/Classes/Composer/InstallerScripts/WebDirectory.php b/typo3/sysext/core/Classes/Composer/InstallerScripts/WebDirectory.php
new file mode 100644 (file)
index 0000000..8bfc990
--- /dev/null
@@ -0,0 +1,99 @@
+<?php
+declare(strict_types=1);
+namespace TYPO3\CMS\Core\Composer\InstallerScripts;
+
+/*
+ * This file is part of the TYPO3 project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Composer\Composer;
+use Composer\IO\IOInterface;
+use Composer\Script\Event;
+use Composer\Semver\Constraint\EmptyConstraint;
+use TYPO3\CMS\Composer\Plugin\Config;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;
+use TYPO3\CMS\Composer\Plugin\Util\Filesystem;
+
+/**
+ * Setting up TYPO3 web directory
+ */
+class WebDirectory implements InstallerScript
+{
+    /**
+     * @var string
+     */
+    private static $typo3Dir = '/typo3';
+
+    /**
+     * @var string
+     */
+    private static $systemExtensionsDir = '/sysext';
+
+    /**
+     * @var IOInterface
+     */
+    private $io;
+
+    /**
+     * @var Composer
+     */
+    private $composer;
+
+    /**
+     * @var Filesystem
+     */
+    private $filesystem;
+
+    /**
+     * @var Config
+     */
+    private $pluginConfig;
+
+    /**
+     * Prepare the web directory with symlinks
+     *
+     * @param Event $event
+     * @return bool
+     */
+    public function run(Event $event): bool
+    {
+        $this->io = $event->getIO();
+        $this->composer = $event->getComposer();
+        $this->filesystem = new Filesystem();
+        $this->pluginConfig = Config::load($this->composer);
+
+        $symlinks = $this->initializeSymlinks();
+        if ($this->filesystem->someFilesExist($symlinks)) {
+            $this->filesystem->removeSymlinks($symlinks);
+        }
+        $this->filesystem->establishSymlinks($symlinks);
+
+        return true;
+    }
+
+    /**
+     * Initialize symlinks from configuration
+     * @return array
+     */
+    private function initializeSymlinks(): array
+    {
+        $webDir = $this->filesystem->normalizePath($this->pluginConfig->get('web-dir'));
+        $backendDir = $webDir . self::$typo3Dir;
+        $this->filesystem->ensureDirectoryExists($backendDir);
+        $localRepository = $this->composer->getRepositoryManager()->getLocalRepository();
+        $package = $localRepository->findPackage('typo3/cms', new EmptyConstraint());
+        $sourcesDir = $this->composer->getInstallationManager()->getInstallPath($package);
+        return [
+            $sourcesDir . self::$typo3Dir . self::$systemExtensionsDir => $backendDir . self::$systemExtensionsDir,
+        ];
+    }
+}
diff --git a/typo3/sysext/frontend/Classes/Composer/InstallerScripts.php b/typo3/sysext/frontend/Classes/Composer/InstallerScripts.php
new file mode 100644 (file)
index 0000000..d20d6c7
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+declare(strict_types=1);
+namespace TYPO3\CMS\Frontend\Composer;
+
+/*
+ * This file is part of the TYPO3 project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Composer\Script\Event;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\EntryPoint;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration;
+use TYPO3\CMS\Composer\Plugin\Core\ScriptDispatcher;
+
+/**
+ * Hook into Composer build to generate TYPO3 frontend entry script
+ */
+class InstallerScripts implements InstallerScriptsRegistration
+{
+    /**
+     * @param Event $event
+     * @param ScriptDispatcher $scriptDispatcher
+     */
+    public static function register(Event $event, ScriptDispatcher $scriptDispatcher)
+    {
+        $scriptDispatcher->addInstallerScript(
+            new EntryPoint(
+                dirname(dirname(__DIR__)) . '/Resources/Private/Php/frontend.php',
+                'index.php'
+            )
+        );
+    }
+}
diff --git a/typo3/sysext/install/Classes/Composer/InstallerScripts.php b/typo3/sysext/install/Classes/Composer/InstallerScripts.php
new file mode 100644 (file)
index 0000000..85c3894
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+declare(strict_types=1);
+namespace TYPO3\CMS\Install\Composer;
+
+/*
+ * This file is part of the TYPO3 project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Composer\Script\Event;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\EntryPoint;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration;
+use TYPO3\CMS\Composer\Plugin\Core\ScriptDispatcher;
+
+/**
+ * Hook into Composer build to generate TYPO3 install tool entry script
+ */
+class InstallerScripts implements InstallerScriptsRegistration
+{
+    /**
+     * @param Event $event
+     * @param ScriptDispatcher $scriptDispatcher
+     */
+    public static function register(Event $event, ScriptDispatcher $scriptDispatcher)
+    {
+        $scriptDispatcher->addInstallerScript(
+            new EntryPoint(
+                dirname(dirname(__DIR__)) . '/Resources/Private/Php/install.php',
+                'typo3/install.php'
+            )
+        );
+    }
+}