Skip to content

Commit

Permalink
[TASK] Use Environment API instead of PATH_site in core
Browse files Browse the repository at this point in the history
First batch taking care of "easy" places.

Resolves: #85283
Releases: master
Change-Id: I68fa5a0559aae6191858aba7690ba72918bdf507
Reviewed-on: https://review.typo3.org/57240
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
  • Loading branch information
lolli42 authored and janhelke committed Jun 15, 2018
1 parent f66e915 commit 311cfe2
Show file tree
Hide file tree
Showing 41 changed files with 361 additions and 296 deletions.
Expand Up @@ -37,7 +37,7 @@ class YamlFileLoader
/**
* Loads and parses a YAML file, and returns an array with the found data
*
* @param string $fileName either relative to PATH_site or prefixed with EXT:...
* @param string $fileName either relative to TYPO3's base project folder or prefixed with EXT:...
* @return array the configuration as array
* @throws \RuntimeException when the file is empty or is of invalid format
*/
Expand All @@ -61,7 +61,7 @@ public function load(string $fileName): array
/**
* Put into a separate method to ease the pains with unit tests
*
* @param string $fileName either relative to PATH_site or prefixed with EXT:...
* @param string $fileName either relative to TYPO3's base project folder or prefixed with EXT:...
*
* @return string the contents of the file
* @throws \RuntimeException when the file was not accessible
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/core/Classes/Core/Bootstrap.php
Expand Up @@ -840,7 +840,7 @@ protected static function runExtTablesPostProcessingHooks()
public static function initializeBackendRouter()
{
// See if the Routes.php from all active packages have been built together already
$cacheIdentifier = 'BackendRoutesFromPackages_' . sha1(TYPO3_version . PATH_site . 'BackendRoutesFromPackages');
$cacheIdentifier = 'BackendRoutesFromPackages_' . sha1(TYPO3_version . Environment::getProjectPath() . 'BackendRoutesFromPackages');

/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface */
$codeCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core');
Expand Down
Expand Up @@ -64,7 +64,7 @@ public function __construct(ClassLoader $classLoader, array $activeExtensionPack
* Returns class loading information for a single package
*
* @param PackageInterface $package The package to generate the class loading info for
* @param bool $useRelativePaths If set to TRUE, make the path relative to the current TYPO3 instance (PATH_site)
* @param bool $useRelativePaths If set to TRUE, make the path relative to the current TYPO3 public web path
* @return array
*/
public function buildClassLoadingInformationForPackage(PackageInterface $package, $useRelativePaths = false)
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Http/NormalizedParams.php
Expand Up @@ -288,7 +288,7 @@ class NormalizedParams
* @param ServerRequestInterface $serverRequest Used to access $_SERVER
* @param array $typo3ConfVars $GLOBALS['TYPO3_CONF_VARS']
* @param string $pathThisScript Absolute server entry script path, usually found within Environment::getCurrentScript()
* @param string $pathSite Absolute server path to document root, constant PATH_site
* @param string $pathSite Absolute server path to document root, Environment::getPublicPath()
*/
public function __construct(ServerRequestInterface $serverRequest, array $typo3ConfVars, string $pathThisScript, string $pathSite)
{
Expand All @@ -307,7 +307,7 @@ public function __construct(ServerRequestInterface $serverRequest, array $typo3C
$this->remoteAddress = self::determineRemoteAddress($serverParams, $typo3ConfVars, $isBehindReverseProxy);
$scriptFilename = $this->scriptFilename = $pathThisScript;
$this->documentRoot = self::determineDocumentRoot($scriptName, $scriptFilename);
$siteUrl = $this->siteUrl = self::determineSiteUrl($requestDir, $pathThisScript, $pathSite);
$siteUrl = $this->siteUrl = self::determineSiteUrl($requestDir, $pathThisScript, $pathSite . '/');
$this->sitePath = self::determineSitePath($requestHost, $siteUrl);
$this->siteScript = self::determineSiteScript($requestUrl, $siteUrl);

Expand Down
32 changes: 16 additions & 16 deletions typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
Expand Up @@ -2131,9 +2131,9 @@ public function imageMagickConvert($imagefile, $newExt = '', $w = '', $h = '', $
$theOutputName = $this->imageMagickConvert_forceFileNameBody;
$this->imageMagickConvert_forceFileNameBody = '';
}
// Making the temporary filename:
GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
$output = PATH_site . 'typo3temp/assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
// Making the temporary filename
GeneralUtility::mkdir_deep(Environment::getPublicPath() . '/typo3temp/assets/images/');
$output = Environment::getPublicPath() . '/typo3temp/assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
if ($this->dontCheckForExistingTempFile || !file_exists($output)) {
$this->imageMagickExec($imagefile, $output, $command, $frame);
}
Expand Down Expand Up @@ -2210,7 +2210,7 @@ public function cacheImageDimensions(array $identifyResult)
/**
* Fetches the cached image dimensions from the cache. Does not check if the image file exists.
*
* @param string $filePath Image file path, relative to PATH_site
* @param string $filePath Image file path, relative to public web path
*
* @return array|bool an array where [0]/[1] is w/h, [2] is extension and [3] is the file name,
* or FALSE for a cache miss
Expand Down Expand Up @@ -2248,7 +2248,7 @@ public function getCachedImageDimensions($filePath)
*
* This method does not check if the image file actually exists.
*
* @param string $filePath Image file path, relative to PATH_site
* @param string $filePath Image file path, relative to public web path
*
* @return string the hash key (an SHA1 hash), will not be empty
*/
Expand All @@ -2260,7 +2260,7 @@ protected function generateCacheKeyForImageFile($filePath)
/**
* Creates the status hash to check whether a file has been changed.
*
* @param string $filePath Image file path, relative to PATH_site
* @param string $filePath Image file path, relative to public web path
*
* @return string the status hash (an SHA1 hash)
*/
Expand Down Expand Up @@ -2401,7 +2401,7 @@ public function getImageScale($info, $w, $h, $options)
/**
* Call the identify command
*
* @param string $imagefile The relative (to PATH_site) image filepath
* @param string $imagefile The relative to public web path image filepath
* @return array|null Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
*/
public function imageMagickIdentify($imagefile)
Expand Down Expand Up @@ -2441,8 +2441,8 @@ public function imageMagickIdentify($imagefile)
* Executes an ImageMagick "convert" on two filenames, $input and $output using $params before them.
* Can be used for many things, mostly scaling and effects.
*
* @param string $input The relative (to PATH_site) image filepath, input file (read from)
* @param string $output The relative (to PATH_site) image filepath, output filename (written to)
* @param string $input The relative to public web path image filepath, input file (read from)
* @param string $output The relative to public web path image filepath, output filename (written to)
* @param string $params ImageMagick parameters
* @param int $frame Optional, refers to which frame-number to select in the image. '' or 0
* @return string The result of a call to PHP function "exec()
Expand All @@ -2467,10 +2467,10 @@ public function imageMagickExec($input, $output, $params, $frame = 0)
* Executes an ImageMagick "combine" (or composite in newer times) on four filenames - $input, $overlay and $mask as input files and $output as the output filename (written to)
* Can be used for many things, mostly scaling and effects.
*
* @param string $input The relative (to PATH_site) image filepath, bottom file
* @param string $overlay The relative (to PATH_site) image filepath, overlay file (top)
* @param string $mask The relative (to PATH_site) image filepath, the mask file (grayscale)
* @param string $output The relative (to PATH_site) image filepath, output filename (written to)
* @param string $input The relative to public web path image filepath, bottom file
* @param string $overlay The relative to public web path image filepath, overlay file (top)
* @param string $mask The relative to public web path image filepath, the mask file (grayscale)
* @param string $output The relative to public web path image filepath, output filename (written to)
* @return string
*/
public function combineExec($input, $overlay, $mask, $output)
Expand Down Expand Up @@ -2570,10 +2570,10 @@ public static function readPngGif($theFile, $output_png = false)
return $theFile;
}

if (!@is_dir(PATH_site . 'typo3temp/assets/images/')) {
GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
if (!@is_dir(Environment::getPublicPath() . '/typo3temp/assets/images/')) {
GeneralUtility::mkdir_deep(Environment::getPublicPath() . '/typo3temp/assets/images/');
}
$newFile = PATH_site . 'typo3temp/assets/images/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
$newFile = Environment::getPublicPath() . '/typo3temp/assets/images/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
$cmd = CommandUtility::imageMagickCommand(
'convert',
'"' . $theFile . '" "' . $newFile . '"',
Expand Down
23 changes: 12 additions & 11 deletions typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php
Expand Up @@ -14,6 +14,7 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Localization\Exception\FileNotFoundException;
use TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -105,16 +106,16 @@ protected function getLocalizedFileName($fileRef, $language, $sameLocation = fal
return GeneralUtility::getFileAbsFileName(str_replace($fileName, $language . '.' . $fileName, $fileRef));
}

// Analyse file reference:
// Is system:
if (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3 . 'sysext/')) {
$validatedPrefix = PATH_typo3 . 'sysext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3 . 'ext/')) {
// Is global:
$validatedPrefix = PATH_typo3 . 'ext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3conf . 'ext/')) {
// Is local:
$validatedPrefix = PATH_typo3conf . 'ext/';
// Analyse file reference
if (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getPublicPath() . '/typo3/sysext/')) {
// Is system
$validatedPrefix = Environment::getPublicPath() . '/typo3/sysext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getPublicPath() . '/typo3/ext/')) {
// Is global
$validatedPrefix = Environment::getPublicPath() . '/typo3/ext/';
} elseif (GeneralUtility::isFirstPartOfStr($fileRef, Environment::getPublicPath() . '/typo3conf/ext/')) {
// Is local
$validatedPrefix = Environment::getPublicPath() . '/typo3conf/ext/';
} else {
$validatedPrefix = '';
}
Expand All @@ -128,7 +129,7 @@ protected function getLocalizedFileName($fileRef, $language, $sameLocation = fal
// Add empty first-entry if not there.
list($file_extPath, $file_fileName) = $temp;
// The filename is prefixed with "[language key]." because it prevents the llxmltranslate tool from detecting it.
return PATH_site . 'typo3conf/l10n/' . $language . '/' . $extensionKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName;
return Environment::getPublicPath() . '/typo3conf/l10n/' . $language . '/' . $extensionKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName;
}
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions typo3/sysext/core/Classes/Log/Writer/FileWriter.php
Expand Up @@ -28,7 +28,7 @@
class FileWriter extends AbstractWriter
{
/**
* Log file path, relative to PATH_site
* Log file path, relative to TYPO3's base project folder
*
* @var string
*/
Expand Down Expand Up @@ -93,7 +93,7 @@ public function __destruct()
/**
* Sets the path to the log file.
*
* @param string $relativeLogFile path to the log file, relative to PATH_site
* @param string $relativeLogFile path to the log file, relative to public web dir
* @return WriterInterface
* @throws InvalidLogWriterConfigurationException
*/
Expand Down Expand Up @@ -212,7 +212,7 @@ protected function createLogFile()
if (!@is_dir($logFileDirectory)) {
GeneralUtility::mkdir_deep($logFileDirectory);
// create .htaccess file if log file is within the site path
if (PathUtility::getCommonPrefix([PATH_site, $logFileDirectory]) === PATH_site) {
if (PathUtility::getCommonPrefix([Environment::getPublicPath() . '/', $logFileDirectory]) === (Environment::getPublicPath() . '/')) {
// only create .htaccess, if we created the directory on our own
$this->createHtaccessFile($logFileDirectory . '/.htaccess');
}
Expand Down
Expand Up @@ -40,7 +40,15 @@ class NormalizedParamsAttribute implements MiddlewareInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$request = $request->withAttribute('normalizedParams', new NormalizedParams($request, $GLOBALS['TYPO3_CONF_VARS'], Environment::getCurrentScript(), PATH_site));
$request = $request->withAttribute(
'normalizedParams',
new NormalizedParams(
$request,
$GLOBALS['TYPO3_CONF_VARS'],
Environment::getCurrentScript(),
Environment::getPublicPath()
)
);

// Set $request as global variable. This is needed in a transition phase until core code has been
// refactored to have ServerRequest object available where it is needed. This global will be
Expand Down
18 changes: 10 additions & 8 deletions typo3/sysext/core/Classes/Package/PackageManager.php
Expand Up @@ -22,6 +22,7 @@
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\Service\OpcodeCacheService;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
Expand All @@ -30,7 +31,7 @@
/**
* The default TYPO3 Package Manager
*/
class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
class PackageManager implements SingletonInterface
{
/**
* @var DependencyOrderingService
Expand Down Expand Up @@ -66,7 +67,7 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
* Absolute path leading to the various package directories
* @var string
*/
protected $packagesBasePath = PATH_site;
protected $packagesBasePath;

/**
* Array of available packages, indexed by package key
Expand Down Expand Up @@ -107,7 +108,8 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
*/
public function __construct(DependencyOrderingService $dependencyOrderingService = null)
{
$this->packageStatesPathAndFilename = PATH_typo3conf . 'PackageStates.php';
$this->packagesBasePath = Environment::getPublicPath() . '/';
$this->packageStatesPathAndFilename = Environment::getPublicPath() . '/typo3conf/PackageStates.php';
if ($dependencyOrderingService === null) {
trigger_error(self::class . ' without constructor based dependency injection has been deprecated in v9.2 and will not work in TYPO3 v10.', E_USER_DEPRECATED);
$dependencyOrderingService = GeneralUtility::makeInstance(DependencyOrderingService::class);
Expand Down Expand Up @@ -1058,13 +1060,13 @@ protected function getPackageBasePaths()
{
if (count($this->packagesBasePaths) < 3) {
// Check if the directory even exists and if it is not empty
if (is_dir(PATH_typo3conf . 'ext') && $this->hasSubDirectories(PATH_typo3conf . 'ext')) {
$this->packagesBasePaths['local'] = PATH_typo3conf . 'ext/*/';
if (is_dir(Environment::getPublicPath() . '/typo3conf/ext') && $this->hasSubDirectories(Environment::getPublicPath() . '/typo3conf/ext')) {
$this->packagesBasePaths['local'] = Environment::getPublicPath() . '/typo3conf/ext/*/';
}
if (is_dir(PATH_typo3 . 'ext') && $this->hasSubDirectories(PATH_typo3 . 'ext')) {
$this->packagesBasePaths['global'] = PATH_typo3 . 'ext/*/';
if (is_dir(Environment::getPublicPath() . '/typo3/ext') && $this->hasSubDirectories(Environment::getPublicPath() . '/typo3/ext')) {
$this->packagesBasePaths['global'] = Environment::getPublicPath() . '/typo3/ext/*/';
}
$this->packagesBasePaths['system'] = PATH_typo3 . 'sysext/*/';
$this->packagesBasePaths['system'] = Environment::getPublicPath() . '/typo3/sysext/*/';
}
return $this->packagesBasePaths;
}
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Resource/Driver/DriverInterface.php
Expand Up @@ -119,7 +119,7 @@ public function getParentFolderIdentifierOfIdentifier($fileIdentifier);

/**
* Returns the public URL to a file.
* Either fully qualified URL or relative to PATH_site (rawurlencoded).
* Either fully qualified URL or relative to public web path (rawurlencoded).
*
* @param string $identifier
* @return string|null NULL if file is missing or deleted, the generated url otherwise
Expand Down Expand Up @@ -185,7 +185,7 @@ public function isFolderEmpty($folderIdentifier);
* further check is done here! After a successful the original file must
* not exist anymore.
*
* @param string $localFilePath (within PATH_site)
* @param string $localFilePath within public web path
* @param string $targetFolderIdentifier
* @param string $newFileName optional, if not given original name is used
* @param bool $removeOriginal if set the original file will be removed
Expand Down

0 comments on commit 311cfe2

Please sign in to comment.