|
|
|
@ -11,14 +11,14 @@ use RecursiveIteratorIterator;
|
|
|
|
|
use Seld\PharUtils\Timestamps;
|
|
|
|
|
|
|
|
|
|
class PharArchive {
|
|
|
|
|
|
|
|
|
|
private const FILENAME = 'spip_loader.phar';
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
private string $sourceDirectory,
|
|
|
|
|
private string $buildDirectory,
|
|
|
|
|
private string $filename = self::FILENAME
|
|
|
|
|
) {}
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPhpFiles(): Iterator {
|
|
|
|
|
$iterator = new RecursiveDirectoryIterator(
|
|
|
|
@ -26,7 +26,7 @@ class PharArchive {
|
|
|
|
|
RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS
|
|
|
|
|
);
|
|
|
|
|
$iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
|
|
|
|
|
$iterator = new CallbackFilterIterator($iterator, function($file) {
|
|
|
|
|
$iterator = new CallbackFilterIterator($iterator, function ($file) {
|
|
|
|
|
/** @var \SplFileInfo $file */
|
|
|
|
|
if (!$file->isFile()) {
|
|
|
|
|
return false;
|
|
|
|
@ -82,37 +82,36 @@ class PharArchive {
|
|
|
|
|
rename($this->buildDirectory . '/' . self::FILENAME, $this->buildDirectory . '/' . $filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes whitespace from a PHP source string while preserving line numbers.
|
|
|
|
|
*
|
|
|
|
|
* @param string $source A PHP string
|
|
|
|
|
* @return string The PHP string with the whitespace removed
|
|
|
|
|
*/
|
|
|
|
|
private function stripWhitespace(string $source): string
|
|
|
|
|
{
|
|
|
|
|
if (!function_exists('token_get_all')) {
|
|
|
|
|
return $source;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Removes whitespace from a PHP source string while preserving line numbers.
|
|
|
|
|
*
|
|
|
|
|
* @param string $source A PHP string
|
|
|
|
|
* @return string The PHP string with the whitespace removed
|
|
|
|
|
*/
|
|
|
|
|
private function stripWhitespace(string $source): string {
|
|
|
|
|
if (!function_exists('token_get_all')) {
|
|
|
|
|
return $source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
foreach (token_get_all($source) as $token) {
|
|
|
|
|
if (is_string($token)) {
|
|
|
|
|
$output .= $token;
|
|
|
|
|
} elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
|
|
|
|
|
$output .= str_repeat("\n", substr_count($token[1], "\n"));
|
|
|
|
|
} elseif (T_WHITESPACE === $token[0]) {
|
|
|
|
|
// reduce wide spaces
|
|
|
|
|
$whitespace = Preg::replace('{[ \t]+}', ' ', $token[1]);
|
|
|
|
|
// normalize newlines to \n
|
|
|
|
|
$whitespace = Preg::replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
|
|
|
|
|
// trim leading spaces
|
|
|
|
|
$whitespace = Preg::replace('{\n +}', "\n", $whitespace);
|
|
|
|
|
$output .= $whitespace;
|
|
|
|
|
} else {
|
|
|
|
|
$output .= $token[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$output = '';
|
|
|
|
|
foreach (token_get_all($source) as $token) {
|
|
|
|
|
if (is_string($token)) {
|
|
|
|
|
$output .= $token;
|
|
|
|
|
} elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
|
|
|
|
|
$output .= str_repeat("\n", substr_count($token[1], "\n"));
|
|
|
|
|
} elseif (T_WHITESPACE === $token[0]) {
|
|
|
|
|
// reduce wide spaces
|
|
|
|
|
$whitespace = Preg::replace('{[ \t]+}', ' ', $token[1]);
|
|
|
|
|
// normalize newlines to \n
|
|
|
|
|
$whitespace = Preg::replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
|
|
|
|
|
// trim leading spaces
|
|
|
|
|
$whitespace = Preg::replace('{\n +}', "\n", $whitespace);
|
|
|
|
|
$output .= $whitespace;
|
|
|
|
|
} else {
|
|
|
|
|
$output .= $token[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|