1<?php 2namespace TYPO3\CMS\Composer\Plugin\Core\IncludeFile; 3 4/* 5 * This file was taken from the typo3 console plugin package. 6 * (c) Helmut Hummel <info@helhum.io> 7 * 8 * This file is part of the TYPO3 project. 9 * 10 * It is free software; you can redistribute it and/or modify it under 11 * the terms of the GNU General Public License, either version 2 12 * of the License, or any later version. 13 * 14 * For the full copyright and license information, please read the 15 * LICENSE.txt file that was distributed with this source code. 16 * 17 * The TYPO3 project - inspiring people to share! 18 */ 19 20use Composer\IO\IOInterface; 21use Composer\Util\Filesystem; 22use TYPO3\CMS\Composer\Plugin\Config as Typo3PluginConfig; 23 24class BaseDirToken implements TokenInterface 25{ 26 /** 27 * @var string 28 */ 29 private $name = 'base-dir'; 30 31 /** 32 * @var Typo3PluginConfig 33 */ 34 private $typo3PluginConfig; 35 36 /** 37 * @var Filesystem 38 */ 39 private $filesystem; 40 41 /** 42 * @var IOInterface 43 */ 44 private $io; 45 46 /** 47 * BaseDirToken constructor. 48 * 49 * @param IOInterface $io 50 * @param Typo3PluginConfig $typo3PluginConfig 51 * @param Filesystem $filesystem 52 */ 53 public function __construct(IOInterface $io, Typo3PluginConfig $typo3PluginConfig, Filesystem $filesystem = null) 54 { 55 $this->io = $io; 56 $this->typo3PluginConfig = $typo3PluginConfig; 57 $this->filesystem = $filesystem ?: new Filesystem(); 58 } 59 60 /** 61 * @return string 62 */ 63 public function getName() 64 { 65 return $this->name; 66 } 67 68 /** 69 * @param string $includeFilePath 70 * @throws \InvalidArgumentException 71 * @return string 72 */ 73 public function getContent(string $includeFilePath) 74 { 75 return $this->filesystem->findShortestPathCode( 76 $includeFilePath, 77 $this->typo3PluginConfig->getBaseDir(), 78 true 79 ); 80 } 81} 82