‪TYPO3CMS  10.4
CliEntryPoint.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS 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 
19 
20 use Composer\Script\Event;
21 use Composer\Util\Filesystem as FilesystemUtility;
22 use Symfony\Component\Filesystem\Filesystem;
23 use TYPO3\CMS\Composer\Plugin\Config;
24 use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;
25 
26 class ‪CliEntryPoint implements InstallerScript
27 {
33  private ‪$source;
34 
40  private ‪$target;
41 
42  public function ‪__construct(string ‪$source, string ‪$target)
43  {
44  $this->source = ‪$source;
45  $this->target = ‪$target;
46  }
47 
48  public function ‪run(Event $event): bool
49  {
50  $composer = $event->getComposer();
51  $filesystemUtility = new FilesystemUtility();
52  $filesystem = new Filesystem();
53  $pluginConfig = Config::load($composer);
54 
55  $entryPointContent = file_get_contents($this->source);
56  if ($entryPointContent === false) {
57  return false;
58  }
59  $targetFile = $pluginConfig->get('root-dir') . '/' . ‪$this->target;
60  $autoloadFile = $composer->getConfig()->get('vendor-dir') . '/autoload.php';
61 
62  $entryPointContent = preg_replace(
63  '/__DIR__ . \'[^\']*\'/',
64  $filesystemUtility->findShortestPathCode($targetFile, $autoloadFile),
65  $entryPointContent
66  );
67 
68  $filesystemUtility->ensureDirectoryExists(dirname($targetFile));
69  $filesystem->dumpFile($targetFile, $entryPointContent);
70  $filesystem->chmod($targetFile, 0755);
71 
72  return $filesystem->exists($targetFile);
73  }
74 }
‪TYPO3\CMS\Core\Composer\CliEntryPoint\$target
‪string $target
Definition: CliEntryPoint.php:38
‪TYPO3\CMS\Core\Composer\CliEntryPoint\$source
‪string $source
Definition: CliEntryPoint.php:32
‪TYPO3\CMS\Core\Composer\CliEntryPoint\run
‪run(Event $event)
Definition: CliEntryPoint.php:46
‪TYPO3\CMS\Core\Composer\CliEntryPoint\__construct
‪__construct(string $source, string $target)
Definition: CliEntryPoint.php:40
‪TYPO3\CMS\Core\Composer\CliEntryPoint
Definition: CliEntryPoint.php:27
‪TYPO3\CMS\Core\Composer
Definition: CliEntryPoint.php:18