2017-03-23 10:55:09 +01:00
|
|
|
<?php
|
2017-04-25 12:58:19 +02:00
|
|
|
namespace Typo3Update;
|
2017-03-23 10:55:09 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use PHP_CodeSniffer as PhpCs;
|
2017-04-25 12:58:19 +02:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2017-03-23 10:55:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper to retrieve options from PhpCs with defaults.
|
|
|
|
*/
|
2017-04-06 08:56:46 +02:00
|
|
|
class Options
|
2017-03-23 10:55:09 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns the configured vendor, e.g. to generate new namespaces.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-04-06 08:56:46 +02:00
|
|
|
public static function getVendor()
|
2017-03-23 10:55:09 +01:00
|
|
|
{
|
2017-04-06 08:56:46 +02:00
|
|
|
$vendor = static::getOptionWithDefault(
|
2017-04-06 08:26:13 +02:00
|
|
|
'vendor',
|
|
|
|
'YourCompany'
|
|
|
|
);
|
|
|
|
|
2017-03-23 10:55:09 +01:00
|
|
|
return trim($vendor, '\\/');
|
|
|
|
}
|
2017-03-23 13:34:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the configured file path containing the mappings for classes, interfaced and traits.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-04-06 08:56:46 +02:00
|
|
|
public static function getMappingFile()
|
2017-03-23 13:34:12 +01:00
|
|
|
{
|
2017-04-06 08:56:46 +02:00
|
|
|
return (string) static::getOptionWithDefault(
|
2017-04-06 08:26:13 +02:00
|
|
|
'mappingFile',
|
2017-04-25 12:58:19 +02:00
|
|
|
__DIR__ . '/../../../LegacyClassnames.php'
|
2017-04-06 08:26:13 +02:00
|
|
|
);
|
2017-03-23 13:34:12 +01:00
|
|
|
}
|
2017-03-28 12:52:14 +02:00
|
|
|
|
|
|
|
/**
|
2017-03-30 11:08:42 +02:00
|
|
|
* Returns an array of absolute file names containing removed function configurations.
|
2017-03-28 12:52:14 +02:00
|
|
|
*
|
2017-04-06 08:56:46 +02:00
|
|
|
* @return array<string>
|
2017-03-28 12:52:14 +02:00
|
|
|
*/
|
2017-04-06 08:56:46 +02:00
|
|
|
public static function getRemovedFunctionConfigFiles()
|
2017-03-28 12:52:14 +02:00
|
|
|
{
|
2017-04-06 08:56:46 +02:00
|
|
|
return static::getOptionFileNames(
|
2017-04-06 08:26:13 +02:00
|
|
|
'removedFunctionConfigFiles',
|
2017-04-25 12:58:19 +02:00
|
|
|
__DIR__ . '/Configuration/Removed/Functions/*.yaml'
|
2017-04-06 08:26:13 +02:00
|
|
|
);
|
2017-03-28 12:52:14 +02:00
|
|
|
}
|
2017-03-30 13:13:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of absolute file names containing removed constant configurations.
|
|
|
|
*
|
2017-04-06 08:56:46 +02:00
|
|
|
* @return array<string>
|
2017-03-30 13:13:19 +02:00
|
|
|
*/
|
2017-04-06 08:56:46 +02:00
|
|
|
public static function getRemovedConstantConfigFiles()
|
2017-03-30 13:13:19 +02:00
|
|
|
{
|
2017-04-06 08:56:46 +02:00
|
|
|
return static::getOptionFileNames(
|
2017-04-06 08:26:13 +02:00
|
|
|
'removedConstantConfigFiles',
|
2017-04-25 12:58:19 +02:00
|
|
|
__DIR__ . '/Configuration/Removed/Constants/*.yaml'
|
2017-04-06 08:26:13 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-13 13:40:04 +02:00
|
|
|
/**
|
2017-04-13 15:27:25 +02:00
|
|
|
* Returns an array of absolute file names containing removed typoscript.
|
2017-04-13 13:40:04 +02:00
|
|
|
*
|
|
|
|
* @return array<string>
|
|
|
|
*/
|
2017-04-13 15:27:25 +02:00
|
|
|
public static function getRemovedTypoScriptConfigFiles()
|
2017-04-13 13:40:04 +02:00
|
|
|
{
|
|
|
|
return static::getOptionFileNames(
|
2017-04-13 15:27:25 +02:00
|
|
|
'removedTypoScript',
|
2017-04-25 15:50:04 +02:00
|
|
|
__DIR__ . '/Configuration/Removed/TypoScript/*.yaml'
|
2017-04-13 13:40:04 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-25 09:22:50 +02:00
|
|
|
/**
|
|
|
|
* Returns an array of absolute file names containing removed class configurations.
|
|
|
|
*
|
|
|
|
* @return array<string>
|
|
|
|
*/
|
|
|
|
public static function getRemovedClassConfigFiles()
|
|
|
|
{
|
|
|
|
return static::getOptionFileNames(
|
|
|
|
'removedClassConfigFiles',
|
2017-04-27 14:05:05 +02:00
|
|
|
__DIR__ . '/Configuration/Removed/Classes/*.yaml'
|
2017-04-25 09:22:50 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-06 08:26:13 +02:00
|
|
|
/**
|
|
|
|
* Get the option by optionName, if not defined, use default.
|
|
|
|
*
|
|
|
|
* @param string $optionName
|
|
|
|
* @param mixed $default
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2017-04-06 08:56:46 +02:00
|
|
|
private static function getOptionWithDefault($optionName, $default)
|
2017-04-06 08:26:13 +02:00
|
|
|
{
|
|
|
|
$option = PhpCs::getConfigData($optionName);
|
|
|
|
if (!$option) {
|
|
|
|
$option = $default;
|
2017-03-30 13:13:19 +02:00
|
|
|
}
|
|
|
|
|
2017-04-06 08:26:13 +02:00
|
|
|
return $option;
|
|
|
|
}
|
|
|
|
|
2017-04-25 16:35:54 +02:00
|
|
|
/**
|
|
|
|
* Get the configured features.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-04-25 12:58:19 +02:00
|
|
|
public static function getFeaturesConfiguration()
|
|
|
|
{
|
|
|
|
$option = [];
|
|
|
|
$fileNames = static::getOptionFileNames(
|
|
|
|
'features',
|
|
|
|
__DIR__ . '/Configuration/Features/*.yaml'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($fileNames as $file) {
|
2017-04-27 11:48:59 +02:00
|
|
|
$content = Yaml::parse(file_get_contents((string) $file));
|
|
|
|
if ($content === null) {
|
|
|
|
$content = [];
|
|
|
|
}
|
|
|
|
$option = array_merge($option, $content);
|
2017-04-25 12:58:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $option;
|
|
|
|
}
|
|
|
|
|
2017-04-06 08:26:13 +02:00
|
|
|
/**
|
|
|
|
* Get file names defined by option using optionName, if not defined, use default.
|
|
|
|
*
|
2017-04-06 08:56:46 +02:00
|
|
|
* TODO: Multiple files allowed, using glob ...
|
|
|
|
* to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ...
|
|
|
|
*
|
2017-04-06 08:26:13 +02:00
|
|
|
* @param string $optionName
|
|
|
|
* @param mixed $default
|
|
|
|
*
|
2017-04-06 08:56:46 +02:00
|
|
|
* @return array<string>
|
2017-04-06 08:26:13 +02:00
|
|
|
*/
|
2017-04-06 08:56:46 +02:00
|
|
|
protected static function getOptionFileNames($optionName, $default)
|
2017-04-06 08:26:13 +02:00
|
|
|
{
|
2017-04-06 08:56:46 +02:00
|
|
|
$files = static::getOptionWithDefault($optionName, $default);
|
|
|
|
$fileNames = [];
|
2017-04-06 08:26:13 +02:00
|
|
|
|
|
|
|
foreach ((new \GlobIterator($files)) as $file) {
|
2017-04-06 08:56:46 +02:00
|
|
|
$fileNames[] = (string) $file;
|
2017-03-30 13:13:19 +02:00
|
|
|
}
|
2017-04-06 08:56:46 +02:00
|
|
|
|
|
|
|
return $fileNames;
|
2017-03-30 13:13:19 +02:00
|
|
|
}
|
2017-03-23 10:55:09 +01:00
|
|
|
}
|