Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -87,7 +87,7 @@ abstract class AbstractProxyFactory
|
|||
/**
|
||||
* @var \Doctrine\Common\Proxy\ProxyDefinition[]
|
||||
*/
|
||||
private $definitions = array();
|
||||
private $definitions = [];
|
||||
|
||||
/**
|
||||
* @param \Doctrine\Common\Proxy\ProxyGenerator $proxyGenerator
|
||||
|
|
|
@ -49,9 +49,13 @@ class Autoloader
|
|||
throw InvalidArgumentException::notProxyClass($className, $proxyNamespace);
|
||||
}
|
||||
|
||||
$className = str_replace('\\', '', substr($className, strlen($proxyNamespace) + 1));
|
||||
// remove proxy namespace from class name
|
||||
$classNameRelativeToProxyNamespace = substr($className, strlen($proxyNamespace));
|
||||
|
||||
return $proxyDir . DIRECTORY_SEPARATOR . $className . '.php';
|
||||
// remove namespace separators from remaining class name
|
||||
$fileName = str_replace('\\', '', $classNameRelativeToProxyNamespace);
|
||||
|
||||
return $proxyDir . DIRECTORY_SEPARATOR . $fileName . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,15 +41,19 @@ class UnexpectedValueException extends BaseUnexpectedValueException implements P
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $methodName
|
||||
* @param string $parameterName
|
||||
* @param \Exception $previous
|
||||
* @param string $className
|
||||
* @param string $methodName
|
||||
* @param string $parameterName
|
||||
* @param \Exception|null $previous
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function invalidParameterTypeHint($className, $methodName, $parameterName, \Exception $previous)
|
||||
{
|
||||
public static function invalidParameterTypeHint(
|
||||
$className,
|
||||
$methodName,
|
||||
$parameterName,
|
||||
\Exception $previous = null
|
||||
) {
|
||||
return new self(
|
||||
sprintf(
|
||||
'The type hint of parameter "%s" in method "%s" in class "%s" is invalid.',
|
||||
|
@ -61,4 +65,24 @@ class UnexpectedValueException extends BaseUnexpectedValueException implements P
|
|||
$previous
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $className
|
||||
* @param $methodName
|
||||
* @param \Exception|null $previous
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function invalidReturnTypeHint($className, $methodName, \Exception $previous = null)
|
||||
{
|
||||
return new self(
|
||||
sprintf(
|
||||
'The return type of method "%s" in class "%s" is invalid.',
|
||||
$methodName,
|
||||
$className
|
||||
),
|
||||
0,
|
||||
$previous
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class ProxyGenerator
|
|||
* Used to match very simple id methods that don't need
|
||||
* to be decorated since the identifier is known.
|
||||
*/
|
||||
const PATTERN_MATCH_ID_METHOD = '((public\s+)?(function\s+%s\s*\(\)\s*)\s*{\s*return\s*\$this->%s;\s*})i';
|
||||
const PATTERN_MATCH_ID_METHOD = '((public\s+)?(function\s+%s\s*\(\)\s*)\s*(?::\s*\??\s*\\\\?[a-z_\x7f-\xff][\w\x7f-\xff]*(?:\\\\[a-z_\x7f-\xff][\w\x7f-\xff]*)*\s*)?{\s*return\s*\$this->%s;\s*})i';
|
||||
|
||||
/**
|
||||
* The namespace that contains all proxy classes.
|
||||
|
@ -58,10 +58,10 @@ class ProxyGenerator
|
|||
*
|
||||
* @var string[]|callable[]
|
||||
*/
|
||||
protected $placeholders = array(
|
||||
'baseProxyInterface' => 'Doctrine\Common\Proxy\Proxy',
|
||||
protected $placeholders = [
|
||||
'baseProxyInterface' => Proxy::class,
|
||||
'additionalProperties' => '',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Template used as a blueprint to generate proxies.
|
||||
|
@ -106,7 +106,7 @@ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface
|
|||
*
|
||||
* @see \Doctrine\Common\Persistence\Proxy::__getLazyProperties
|
||||
*/
|
||||
public static $lazyPropertiesDefaults = array(<lazyPropertiesDefaults>);
|
||||
public static $lazyPropertiesDefaults = [<lazyPropertiesDefaults>];
|
||||
|
||||
<additionalProperties>
|
||||
|
||||
|
@ -129,7 +129,7 @@ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface
|
|||
*/
|
||||
public function __load()
|
||||
{
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, \'__load\', array());
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, \'__load\', []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,12 +263,12 @@ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface
|
|||
preg_match_all('(<([a-zA-Z]+)>)', $this->proxyClassTemplate, $placeholderMatches);
|
||||
|
||||
$placeholderMatches = array_combine($placeholderMatches[0], $placeholderMatches[1]);
|
||||
$placeholders = array();
|
||||
$placeholders = [];
|
||||
|
||||
foreach ($placeholderMatches as $placeholder => $name) {
|
||||
$placeholders[$placeholder] = isset($this->placeholders[$name])
|
||||
? $this->placeholders[$name]
|
||||
: array($this, 'generate' . $name);
|
||||
: [$this, 'generate' . $name];
|
||||
}
|
||||
|
||||
foreach ($placeholders as & $placeholder) {
|
||||
|
@ -302,7 +302,7 @@ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface
|
|||
$tmpFileName = $fileName . '.' . uniqid('', true);
|
||||
|
||||
file_put_contents($tmpFileName, $proxyCode);
|
||||
chmod($tmpFileName, 0664);
|
||||
@chmod($tmpFileName, 0664);
|
||||
rename($tmpFileName, $fileName);
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface
|
|||
private function generateLazyPropertiesDefaults(ClassMetadata $class)
|
||||
{
|
||||
$lazyPublicProperties = $this->getLazyLoadedPublicProperties($class);
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
foreach ($lazyPublicProperties as $key => $value) {
|
||||
$values[] = var_export($key, true) . ' => ' . var_export($value, true);
|
||||
|
@ -385,7 +385,7 @@ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface
|
|||
{
|
||||
|
||||
EOT;
|
||||
$toUnset = array();
|
||||
$toUnset = [];
|
||||
|
||||
foreach ($this->getLazyLoadedPublicProperties($class) as $lazyPublicProperty => $unused) {
|
||||
$toUnset[] = '$this->' . $lazyPublicProperty;
|
||||
|
@ -443,7 +443,7 @@ EOT;
|
|||
if ( ! empty($lazyPublicProperties)) {
|
||||
$magicGet .= <<<'EOT'
|
||||
if (array_key_exists($name, $this->__getLazyProperties())) {
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', array($name));
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', [$name]);
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
@ -454,7 +454,7 @@ EOT;
|
|||
|
||||
if ($hasParentGet) {
|
||||
$magicGet .= <<<'EOT'
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', array($name));
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', [$name]);
|
||||
|
||||
return parent::__get($name);
|
||||
|
||||
|
@ -502,7 +502,7 @@ EOT;
|
|||
if ( ! empty($lazyPublicProperties)) {
|
||||
$magicSet .= <<<'EOT'
|
||||
if (array_key_exists($name, $this->__getLazyProperties())) {
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', array($name, $value));
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', [$name, $value]);
|
||||
|
||||
$this->$name = $value;
|
||||
|
||||
|
@ -515,7 +515,7 @@ EOT;
|
|||
|
||||
if ($hasParentSet) {
|
||||
$magicSet .= <<<'EOT'
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', array($name, $value));
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', [$name, $value]);
|
||||
|
||||
return parent::__set($name, $value);
|
||||
EOT;
|
||||
|
@ -559,7 +559,7 @@ EOT;
|
|||
if ( ! empty($lazyPublicProperties)) {
|
||||
$magicIsset .= <<<'EOT'
|
||||
if (array_key_exists($name, $this->__getLazyProperties())) {
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', array($name));
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', [$name]);
|
||||
|
||||
return isset($this->$name);
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ EOT;
|
|||
|
||||
if ($hasParentIsset) {
|
||||
$magicIsset .= <<<'EOT'
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', array($name));
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', [$name]);
|
||||
|
||||
return parent::__isset($name);
|
||||
|
||||
|
@ -605,7 +605,7 @@ EOT;
|
|||
|
||||
if ($hasParentSleep) {
|
||||
return $sleepImpl . <<<'EOT'
|
||||
$properties = array_merge(array('__isInitialized__'), parent::__sleep());
|
||||
$properties = array_merge(['__isInitialized__'], parent::__sleep());
|
||||
|
||||
if ($this->__isInitialized__) {
|
||||
$properties = array_diff($properties, array_keys($this->__getLazyProperties()));
|
||||
|
@ -616,7 +616,7 @@ EOT;
|
|||
EOT;
|
||||
}
|
||||
|
||||
$allProperties = array('__isInitialized__');
|
||||
$allProperties = ['__isInitialized__'];
|
||||
|
||||
/* @var $prop \ReflectionProperty */
|
||||
foreach ($class->getReflectionClass()->getProperties() as $prop) {
|
||||
|
@ -645,10 +645,10 @@ EOT;
|
|||
|
||||
return $sleepImpl . <<<EOT
|
||||
if (\$this->__isInitialized__) {
|
||||
return array($allProperties);
|
||||
return [$allProperties];
|
||||
}
|
||||
|
||||
return array($protectedProperties);
|
||||
return [$protectedProperties];
|
||||
}
|
||||
EOT;
|
||||
}
|
||||
|
@ -662,7 +662,7 @@ EOT;
|
|||
*/
|
||||
private function generateWakeupImpl(ClassMetadata $class)
|
||||
{
|
||||
$unsetPublicProperties = array();
|
||||
$unsetPublicProperties = [];
|
||||
$hasWakeup = $class->getReflectionClass()->hasMethod('__wakeup');
|
||||
|
||||
foreach (array_keys($this->getLazyLoadedPublicProperties($class)) as $lazyPublicProperty) {
|
||||
|
@ -727,7 +727,7 @@ EOT;
|
|||
*/
|
||||
public function __clone()
|
||||
{
|
||||
\$this->__cloner__ && \$this->__cloner__->__invoke(\$this, '__clone', array());
|
||||
\$this->__cloner__ && \$this->__cloner__->__invoke(\$this, '__clone', []);
|
||||
$callParentClone }
|
||||
EOT;
|
||||
}
|
||||
|
@ -742,16 +742,16 @@ EOT;
|
|||
private function generateMethods(ClassMetadata $class)
|
||||
{
|
||||
$methods = '';
|
||||
$methodNames = array();
|
||||
$methodNames = [];
|
||||
$reflectionMethods = $class->getReflectionClass()->getMethods(\ReflectionMethod::IS_PUBLIC);
|
||||
$skippedMethods = array(
|
||||
$skippedMethods = [
|
||||
'__sleep' => true,
|
||||
'__clone' => true,
|
||||
'__wakeup' => true,
|
||||
'__get' => true,
|
||||
'__set' => true,
|
||||
'__isset' => true,
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($reflectionMethods as $method) {
|
||||
$name = $method->getName();
|
||||
|
@ -778,15 +778,18 @@ EOT;
|
|||
}
|
||||
|
||||
$methods .= $name . '(' . $this->buildParametersString($class, $method, $method->getParameters()) . ')';
|
||||
$methods .= $this->getMethodReturnType($method);
|
||||
$methods .= "\n" . ' {' . "\n";
|
||||
|
||||
if ($this->isShortIdentifierGetter($method, $class)) {
|
||||
$identifier = lcfirst(substr($name, 3));
|
||||
$fieldType = $class->getTypeOfField($identifier);
|
||||
$cast = in_array($fieldType, array('integer', 'smallint')) ? '(int) ' : '';
|
||||
$cast = in_array($fieldType, ['integer', 'smallint']) ? '(int) ' : '';
|
||||
|
||||
$methods .= ' if ($this->__isInitialized__ === false) {' . "\n";
|
||||
$methods .= ' return ' . $cast . ' parent::' . $method->getName() . "();\n";
|
||||
$methods .= ' ';
|
||||
$methods .= $this->shouldProxiedMethodReturn($method) ? 'return ' : '';
|
||||
$methods .= $cast . ' parent::' . $method->getName() . "();\n";
|
||||
$methods .= ' }' . "\n\n";
|
||||
}
|
||||
|
||||
|
@ -795,8 +798,10 @@ EOT;
|
|||
|
||||
$methods .= "\n \$this->__initializer__ "
|
||||
. "&& \$this->__initializer__->__invoke(\$this, " . var_export($name, true)
|
||||
. ", array(" . $invokeParamsString . "));"
|
||||
. "\n\n return parent::" . $name . '(' . $callParamsString . ');'
|
||||
. ", [" . $invokeParamsString . "]);"
|
||||
. "\n\n "
|
||||
. ($this->shouldProxiedMethodReturn($method) ? 'return ' : '')
|
||||
. "parent::" . $name . '(' . $callParamsString . ');'
|
||||
. "\n" . ' }' . "\n";
|
||||
}
|
||||
|
||||
|
@ -872,7 +877,7 @@ EOT;
|
|||
private function getLazyLoadedPublicProperties(ClassMetadata $class)
|
||||
{
|
||||
$defaultProperties = $class->getReflectionClass()->getDefaultProperties();
|
||||
$properties = array();
|
||||
$properties = [];
|
||||
|
||||
foreach ($class->getReflectionClass()->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$name = $property->getName();
|
||||
|
@ -894,7 +899,7 @@ EOT;
|
|||
*/
|
||||
private function buildParametersString(ClassMetadata $class, \ReflectionMethod $method, array $parameters)
|
||||
{
|
||||
$parameterDefinitions = array();
|
||||
$parameterDefinitions = [];
|
||||
|
||||
/* @var $param \ReflectionParameter */
|
||||
foreach ($parameters as $param) {
|
||||
|
@ -908,10 +913,8 @@ EOT;
|
|||
$parameterDefinition .= '&';
|
||||
}
|
||||
|
||||
if (method_exists($param, 'isVariadic')) {
|
||||
if ($param->isVariadic()) {
|
||||
$parameterDefinition .= '...';
|
||||
}
|
||||
if (method_exists($param, 'isVariadic') && $param->isVariadic()) {
|
||||
$parameterDefinition .= '...';
|
||||
}
|
||||
|
||||
$parameters[] = '$' . $param->getName();
|
||||
|
@ -936,13 +939,20 @@ EOT;
|
|||
*/
|
||||
private function getParameterType(ClassMetadata $class, \ReflectionMethod $method, \ReflectionParameter $parameter)
|
||||
{
|
||||
if (method_exists($parameter, 'hasType')) {
|
||||
if ( ! $parameter->hasType()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// We need to pick the type hint class too
|
||||
return $this->formatType($parameter->getType(), $parameter->getDeclaringFunction(), $parameter);
|
||||
}
|
||||
|
||||
// For PHP 5.x, we need to pick the type hint in the old way (to be removed for PHP 7.0+)
|
||||
if ($parameter->isArray()) {
|
||||
return 'array';
|
||||
}
|
||||
|
||||
if (method_exists($parameter, 'isCallable') && $parameter->isCallable()) {
|
||||
if ($parameter->isCallable()) {
|
||||
return 'callable';
|
||||
}
|
||||
|
||||
|
@ -990,10 +1000,8 @@ EOT;
|
|||
function (\ReflectionParameter $parameter) {
|
||||
$name = '';
|
||||
|
||||
if (method_exists($parameter, 'isVariadic')) {
|
||||
if ($parameter->isVariadic()) {
|
||||
$name .= '...';
|
||||
}
|
||||
if (method_exists($parameter, 'isVariadic') && $parameter->isVariadic()) {
|
||||
$name .= '...';
|
||||
}
|
||||
|
||||
$name .= '$' . $parameter->getName();
|
||||
|
@ -1003,4 +1011,83 @@ EOT;
|
|||
$parameters
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Param \ReflectionMethod $method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getMethodReturnType(\ReflectionMethod $method)
|
||||
{
|
||||
if ( ! method_exists($method, 'hasReturnType') || ! $method->hasReturnType()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return ': ' . $this->formatType($method->getReturnType(), $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ReflectionMethod $method
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldProxiedMethodReturn(\ReflectionMethod $method)
|
||||
{
|
||||
if ( ! method_exists($method, 'hasReturnType') || ! $method->hasReturnType()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return 'void' !== strtolower($this->formatType($method->getReturnType(), $method));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ReflectionType $type
|
||||
* @param \ReflectionMethod $method
|
||||
* @param \ReflectionParameter|null $parameter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function formatType(
|
||||
\ReflectionType $type,
|
||||
\ReflectionMethod $method,
|
||||
\ReflectionParameter $parameter = null
|
||||
) {
|
||||
$name = method_exists($type, 'getName') ? $type->getName() : (string) $type;
|
||||
$nameLower = strtolower($name);
|
||||
|
||||
if ('self' === $nameLower) {
|
||||
$name = $method->getDeclaringClass()->getName();
|
||||
}
|
||||
|
||||
if ('parent' === $nameLower) {
|
||||
$name = $method->getDeclaringClass()->getParentClass()->getName();
|
||||
}
|
||||
|
||||
if ( ! $type->isBuiltin() && ! class_exists($name) && ! interface_exists($name)) {
|
||||
if (null !== $parameter) {
|
||||
throw UnexpectedValueException::invalidParameterTypeHint(
|
||||
$method->getDeclaringClass()->getName(),
|
||||
$method->getName(),
|
||||
$parameter->getName()
|
||||
);
|
||||
}
|
||||
|
||||
throw UnexpectedValueException::invalidReturnTypeHint(
|
||||
$method->getDeclaringClass()->getName(),
|
||||
$method->getName()
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! $type->isBuiltin()) {
|
||||
$name = '\\' . $name;
|
||||
}
|
||||
|
||||
if ($type->allowsNull()
|
||||
&& (null === $parameter || ! $parameter->isDefaultValueAvailable() || null !== $parameter->getDefaultValue())
|
||||
) {
|
||||
$name = '?' . $name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue