Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -33,7 +33,6 @@ class FactoryClass
$this->methods = array();
foreach ($this->getPublicStaticMethods() as $method) {
if ($method->isFactory()) {
// echo $this->getName() . '::' . $method->getName() . ' : ' . count($method->getCalls()) . PHP_EOL;
$this->methods[] = $method;
}
}

View File

@@ -53,9 +53,8 @@ abstract class FactoryFile
public function generateFactoryCall(FactoryCall $call)
{
$method = $call->getMethod();
$code = $method->getComment($this->indent) . PHP_EOL;
$code = $method->getComment($this->indent) . "\n";
$code .= $this->generateDeclaration($call->getName(), $method);
// $code .= $this->generateImport($method);
$code .= $this->generateCall($method);
$code .= $this->generateClosing();
return $code;
@@ -66,7 +65,7 @@ abstract class FactoryFile
$code = $this->indent . $this->getDeclarationModifiers()
. 'function ' . $name . '('
. $this->generateDeclarationArguments($method)
. ')' . PHP_EOL . $this->indent . '{' . PHP_EOL;
. ')' . "\n" . $this->indent . '{' . "\n";
return $code;
}
@@ -86,25 +85,25 @@ abstract class FactoryFile
public function generateImport(FactoryMethod $method)
{
return $this->indent . self::INDENT . "require_once '" . $method->getClass()->getFile() . "';" . PHP_EOL;
return $this->indent . self::INDENT . "require_once '" . $method->getClass()->getFile() . "';" . "\n";
}
public function generateCall(FactoryMethod $method)
{
$code = '';
if ($method->acceptsVariableArguments()) {
$code .= $this->indent . self::INDENT . '$args = func_get_args();' . PHP_EOL;
$code .= $this->indent . self::INDENT . '$args = func_get_args();' . "\n";
}
$code .= $this->indent . self::INDENT . 'return ';
if ($method->acceptsVariableArguments()) {
$code .= 'call_user_func_array(array(\''
. '\\' . $method->getClassName() . '\', \''
. $method->getName() . '\'), $args);' . PHP_EOL;
. $method->getName() . '\'), $args);' . "\n";
} else {
$code .= '\\' . $method->getClassName() . '::'
. $method->getName() . '('
. $method->getParameterInvocations() . ');' . PHP_EOL;
. $method->getParameterInvocations() . ');' . "\n";
}
return $code;
@@ -112,7 +111,7 @@ abstract class FactoryFile
public function generateClosing()
{
return $this->indent . '}' . PHP_EOL;
return $this->indent . '}' . "\n";
}
public function write()

View File

@@ -73,7 +73,7 @@ class FactoryGenerator
public function getSortedFiles()
{
$iter = \File_Iterator_Factory::getFileIterator($this->path, '.php');
$iter = $this->getFileIterator();
$files = array();
foreach ($iter as $file) {
$files[] = $file;
@@ -83,6 +83,15 @@ class FactoryGenerator
return $files;
}
private function getFileIterator()
{
$factoryClass = class_exists('File_Iterator_Factory') ? 'File_Iterator_Factory' : 'SebastianBergmann\FileIterator\Factory';
$factory = new $factoryClass();
return $factory->getFileIterator($this->path, '.php');
}
public function getFactoryClass($file)
{
$name = $this->getFactoryClassName($file);

View File

@@ -216,16 +216,16 @@ class FactoryMethod
public function getCommentText()
{
return implode(PHP_EOL, $this->comment);
return implode("\n", $this->comment);
}
public function getComment($indent = '')
{
$comment = $indent . '/**';
foreach ($this->comment as $line) {
$comment .= PHP_EOL . rtrim($indent . ' * ' . $line);
$comment .= "\n" . rtrim($indent . ' * ' . $line);
}
$comment .= PHP_EOL . $indent . ' */';
$comment .= "\n" . $indent . ' */';
return $comment;
}
}

View File

@@ -22,19 +22,15 @@ class FactoryParameter
$this->reflector = $reflector;
}
/**
* Compute the declaration code.
*
* @return string
*/
public function getDeclaration()
{
if ($this->reflector->isArray()) {
$code = 'array ';
} else {
$class = $this->reflector->getClass();
if ($class !== null) {
$code = '\\' . $class->name . ' ';
} else {
$code = '';
}
}
$code .= '$' . $this->reflector->name;
$code = $this->getTypeCode() . $this->getInvocation();
if ($this->reflector->isOptional()) {
$default = $this->reflector->getDefaultValue();
if (is_null($default)) {
@@ -48,7 +44,7 @@ class FactoryParameter
} elseif (is_array($default)) {
$default = 'array()';
} else {
echo 'Warning: unknown default type for ' . $this->getMethod()->getFullName() . PHP_EOL;
echo 'Warning: unknown default type for ' . $this->getMethod()->getFullName() . "\n";
var_dump($default);
$default = 'null';
}
@@ -57,11 +53,77 @@ class FactoryParameter
return $code;
}
public function getInvocation()
/**
* Compute the type code for the paramater.
*
* @return string
*/
private function getTypeCode()
{
return '$' . $this->reflector->name;
// Handle PHP 5 separately
if (PHP_VERSION_ID < 70000) {
if ($this->reflector->isArray()) {
return 'array';
}
$class = $this->reflector->getClass();
return $class ? sprintf('\\%s ', $class->getName()) : '';
}
if (!$this->reflector->hasType()) {
return '';
}
$type = $this->reflector->getType();
$name = self::getQualifiedName($type);
// PHP 7.1+ supports nullable types via a leading question mark
return (PHP_VERSION_ID >= 70100 && $type->allowsNull()) ? sprintf('?%s ', $name) : sprintf('%s ', $name);
}
/**
* Compute qualified name for the given type.
*
* This function knows how to prefix class names with a leading slash and
* also how to handle PHP 8's union types.
*
* @param ReflectionType $type
*
* @return string
*/
private static function getQualifiedName(ReflectionType $type)
{
// PHP 8 union types can be recursively processed
if ($type instanceof ReflectionUnionType) {
return implode('|', array_map(function (ReflectionType $type) {
// The "self::" call within a Closure is fine here because this
// code will only ever be executed on PHP 7.0+
return self::getQualifiedName($type);
}, $type->getTypes()));
}
// PHP 7.0 doesn't have named types, but 7.1+ does
$name = $type instanceof ReflectionNamedType ? $type->getName() : (string) $type;
return $type->isBuiltin() ? $name : sprintf('\\%s', $name);
}
/**
* Compute the invocation code.
*
* @return string
*/
public function getInvocation()
{
return sprintf('$%s', $this->reflector->getName());
}
/**
* Compute the method name.
*
* @return string
*/
public function getMethod()
{
return $this->method;

View File

@@ -19,7 +19,7 @@ class GlobalFunctionFile extends FactoryFile
public function addCall(FactoryCall $call)
{
$this->functions .= PHP_EOL . $this->generateFactoryCall($call);
$this->functions .= "\n" . $this->generateFactoryCall($call);
}
public function build()
@@ -33,7 +33,7 @@ class GlobalFunctionFile extends FactoryFile
public function generateFactoryCall(FactoryCall $call)
{
$code = "if (!function_exists('{$call->getName()}')) {";
$code = "if (!function_exists('{$call->getName()}')) {\n";
$code.= parent::generateFactoryCall($call);
$code.= "}\n";