[BUGFIX] Use proper path to install cli binary
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Composer / CliEntryPoint.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Composer;
4
5 /*
6 * This file is part of the TYPO3 project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Composer\Script\Event;
19 use Composer\Util\Filesystem as FilesystemUtility;
20 use Symfony\Component\Filesystem\Filesystem;
21 use TYPO3\CMS\Composer\Plugin\Config;
22 use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;
23
24 class CliEntryPoint implements InstallerScript
25 {
26 /**
27 * Absolute path to entry script source
28 *
29 * @var string
30 */
31 private $source;
32
33 /**
34 * The target file relative to the web directory
35 *
36 * @var string
37 */
38 private $target;
39
40 public function __construct(string $source, string $target)
41 {
42 $this->source = $source;
43 $this->target = $target;
44 }
45
46 public function run(Event $event): bool
47 {
48 $composer = $event->getComposer();
49 $filesystemUtility = new FilesystemUtility();
50 $filesystem = new Filesystem();
51 $pluginConfig = Config::load($composer);
52
53 $entryPointContent = file_get_contents($this->source);
54 $targetFile = $pluginConfig->get('root-dir') . '/' . $this->target;
55 $autoloadFile = $composer->getConfig()->get('vendor-dir') . '/autoload.php';
56
57 $entryPointContent = preg_replace(
58 '/__DIR__ . \'[^\']*\'/',
59 $filesystemUtility->findShortestPathCode($targetFile, $autoloadFile),
60 $entryPointContent
61 );
62
63 $filesystemUtility->ensureDirectoryExists(dirname($targetFile));
64 $filesystem->dumpFile($targetFile, $entryPointContent);
65 $filesystem->chmod($targetFile, 0755);
66
67 return $filesystem->exists($targetFile);
68 }
69 }