‪TYPO3CMS  9.5
CliEntryPoint.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
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 {
31  private ‪$source;
32 
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 }
‪TYPO3\CMS\Core\Composer\CliEntryPoint\$target
‪string $target
Definition: CliEntryPoint.php:36
‪TYPO3\CMS\Core\Composer\CliEntryPoint\$source
‪string $source
Definition: CliEntryPoint.php:30
‪TYPO3\CMS\Core\Composer\CliEntryPoint\run
‪run(Event $event)
Definition: CliEntryPoint.php:44
‪TYPO3\CMS\Core\Composer\CliEntryPoint\__construct
‪__construct(string $source, string $target)
Definition: CliEntryPoint.php:38
‪TYPO3\CMS\Core\Composer\CliEntryPoint
Definition: CliEntryPoint.php:25
‪TYPO3\CMS\Core\Composer
Definition: CliEntryPoint.php:3