-
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 2.13.x: Update wrong deprecation message in class loader Un-deprecate proxy logic Fix proxies with return types in magic methods
- Loading branch information
Showing
19 changed files
with
475 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
* @author Roman Borschel <[email protected]> | ||
* @since 2.0 | ||
* | ||
* @deprecated The ClassLoader is deprecated and will be removed in version 3.0 of doctrine/common. | ||
* @deprecated The ClassLoader is deprecated and will be removed in version 4.0 of doctrine/common. | ||
*/ | ||
class ClassLoader | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ | |
* Abstract factory for proxy objects. | ||
* | ||
* @author Benjamin Eberlei <[email protected]> | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
abstract class AbstractProxyFactory | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ | |
* @author Benjamin Eberlei <[email protected]> | ||
* | ||
* @internal | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
class Autoloader | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ | |
* @link www.doctrine-project.org | ||
* @since 2.4 | ||
* @author Marco Pivetta <[email protected]> | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
class InvalidArgumentException extends BaseInvalidArgumentException implements ProxyException | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ | |
* | ||
* @link www.doctrine-project.org | ||
* @author Fredrik Wendel <[email protected]> | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
class OutOfBoundsException extends BaseOutOfBoundsException implements ProxyException | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ | |
* @link www.doctrine-project.org | ||
* @since 2.4 | ||
* @author Marco Pivetta <[email protected]> | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
interface ProxyException | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ | |
* @link www.doctrine-project.org | ||
* @since 2.4 | ||
* @author Marco Pivetta <[email protected]> | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
class UnexpectedValueException extends BaseUnexpectedValueException implements ProxyException | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ | |
* @author Roman Borschel <[email protected]> | ||
* @author Marco Pivetta <[email protected]> | ||
* @since 2.4 | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
interface Proxy extends BaseProxy | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
* Definition structure how to create a proxy. | ||
* | ||
* @author Benjamin Eberlei <[email protected]> | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
class ProxyDefinition | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?php | ||
namespace Doctrine\Common\Proxy; | ||
|
||
use Doctrine\Persistence\Mapping\ClassMetadata; | ||
use Doctrine\Common\Proxy\Exception\InvalidArgumentException; | ||
use Doctrine\Common\Proxy\Exception\UnexpectedValueException; | ||
use Doctrine\Common\Util\ClassUtils; | ||
use Doctrine\Persistence\Mapping\ClassMetadata; | ||
use function array_map; | ||
use function method_exists; | ||
|
||
|
@@ -14,8 +14,6 @@ | |
* | ||
* @author Marco Pivetta <[email protected]> | ||
* @since 2.4 | ||
* | ||
* @deprecated The Doctrine\Common\Proxy component is deprecated, please use ocramius/proxy-manager instead. | ||
*/ | ||
class ProxyGenerator | ||
{ | ||
|
@@ -433,14 +431,24 @@ private function generateMagicGet(ClassMetadata $class) | |
$hasParentGet = false; | ||
$returnReference = ''; | ||
$inheritDoc = ''; | ||
$name = '$name'; | ||
$parametersString = '$name'; | ||
$returnTypeHint = null; | ||
|
||
if ($reflectionClass->hasMethod('__get')) { | ||
$hasParentGet = true; | ||
$inheritDoc = '{@inheritDoc}'; | ||
$hasParentGet = true; | ||
$inheritDoc = '{@inheritDoc}'; | ||
$methodReflection = $reflectionClass->getMethod('__get'); | ||
|
||
if ($reflectionClass->getMethod('__get')->returnsReference()) { | ||
if ($methodReflection->returnsReference()) { | ||
$returnReference = '& '; | ||
} | ||
|
||
$methodParameters = $methodReflection->getParameters(); | ||
$name = '$' . $methodParameters[0]->getName(); | ||
|
||
$parametersString = $this->buildParametersString($methodReflection->getParameters()); | ||
$returnTypeHint = $this->getMethodReturnType($methodReflection); | ||
} | ||
|
||
if (empty($lazyPublicProperties) && ! $hasParentGet) { | ||
|
@@ -450,42 +458,63 @@ private function generateMagicGet(ClassMetadata $class) | |
$magicGet = <<<EOT | ||
/** | ||
* $inheritDoc | ||
* @param string \$name | ||
* @param string $name | ||
*/ | ||
public function {$returnReference}__get(\$name) | ||
public function {$returnReference}__get($parametersString)$returnTypeHint | ||
{ | ||
EOT; | ||
|
||
if ( ! empty($lazyPublicProperties)) { | ||
$magicGet .= sprintf(<<<'EOT' | ||
if (\array_key_exists(%s, self::$lazyPropertiesNames)) { | ||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', [%s]); | ||
EOT | ||
, $name, $name); | ||
|
||
if ($returnTypeHint === ': void') { | ||
$magicGet .= "\n return;"; | ||
} else { | ||
$magicGet .= "\n return \$this->$name;"; | ||
} | ||
|
||
$magicGet .= <<<'EOT' | ||
if (\array_key_exists($name, self::$lazyPropertiesNames)) { | ||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', [$name]); | ||
return $this->$name; | ||
} | ||
|
||
|
||
EOT; | ||
} | ||
|
||
if ($hasParentGet) { | ||
$magicGet .= <<<'EOT' | ||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', [$name]); | ||
return parent::__get($name); | ||
|
||
EOT; | ||
$magicGet .= sprintf(<<<'EOT' | ||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', [%s]); | ||
EOT | ||
, $name); | ||
|
||
if ($returnTypeHint === ': void') { | ||
$magicGet .= sprintf(<<<'EOT' | ||
parent::__get(%s); | ||
return; | ||
EOT | ||
, $name); | ||
} else { | ||
$magicGet .= sprintf(<<<'EOT' | ||
return parent::__get(%s); | ||
EOT | ||
, $name); | ||
} | ||
} else { | ||
$magicGet .= <<<'EOT' | ||
trigger_error(sprintf('Undefined property: %s::$%s', __CLASS__, $name), E_USER_NOTICE); | ||
$magicGet .= sprintf(<<<EOT | ||
trigger_error(sprintf('Undefined property: %%s::$%%s', __CLASS__, %s), E_USER_NOTICE); | ||
EOT; | ||
EOT | ||
, $name); | ||
} | ||
|
||
$magicGet .= " }"; | ||
|
||
return $magicGet; | ||
return $magicGet . "\n }"; | ||
} | ||
|
||
/** | ||
|
@@ -499,22 +528,31 @@ private function generateMagicSet(ClassMetadata $class) | |
{ | ||
$lazyPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class); | ||
$hasParentSet = $class->getReflectionClass()->hasMethod('__set'); | ||
$parametersString = '$name, $value'; | ||
$returnTypeHint = null; | ||
|
||
if ($hasParentSet) { | ||
$methodReflection = $class->getReflectionClass()->getMethod('__set'); | ||
$parametersString = $this->buildParametersString($methodReflection->getParameters()); | ||
$returnTypeHint = $this->getMethodReturnType($methodReflection); | ||
} | ||
|
||
if (empty($lazyPublicProperties) && ! $hasParentSet) { | ||
return ''; | ||
} | ||
|
||
$inheritDoc = $hasParentSet ? '{@inheritDoc}' : ''; | ||
$magicSet = <<<EOT | ||
$magicSet = sprintf(<<<'EOT' | ||
/** | ||
* $inheritDoc | ||
* @param string \$name | ||
* @param mixed \$value | ||
* %s | ||
* @param string $name | ||
* @param mixed $value | ||
*/ | ||
public function __set(\$name, \$value) | ||
public function __set(%s)%s | ||
{ | ||
|
||
EOT; | ||
EOT | ||
, $inheritDoc, $parametersString, $returnTypeHint); | ||
|
||
if ( ! empty($lazyPublicProperties)) { | ||
$magicSet .= <<<'EOT' | ||
|
@@ -540,9 +578,7 @@ public function __set(\$name, \$value) | |
$magicSet .= " \$this->\$name = \$value;"; | ||
} | ||
|
||
$magicSet .= "\n }"; | ||
|
||
return $magicSet; | ||
return $magicSet . "\n }"; | ||
} | ||
|
||
/** | ||
|
@@ -556,6 +592,14 @@ private function generateMagicIsset(ClassMetadata $class) | |
{ | ||
$lazyPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class); | ||
$hasParentIsset = $class->getReflectionClass()->hasMethod('__isset'); | ||
$parametersString = '$name'; | ||
$returnTypeHint = null; | ||
|
||
if ($hasParentIsset) { | ||
$methodReflection = $class->getReflectionClass()->getMethod('__isset'); | ||
$parametersString = $this->buildParametersString($methodReflection->getParameters()); | ||
$returnTypeHint = $this->getMethodReturnType($methodReflection); | ||
} | ||
|
||
if (empty($lazyPublicProperties) && ! $hasParentIsset) { | ||
return ''; | ||
|
@@ -568,7 +612,7 @@ private function generateMagicIsset(ClassMetadata $class) | |
* @param string \$name | ||
* @return boolean | ||
*/ | ||
public function __isset(\$name) | ||
public function __isset($parametersString)$returnTypeHint | ||
{ | ||
EOT; | ||
|
@@ -590,7 +634,6 @@ public function __isset(\$name) | |
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', [$name]); | ||
return parent::__isset($name); | ||
|
||
EOT; | ||
} else { | ||
$magicIsset .= " return false;"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ | |
* | ||
* @author Benjamin Eberlei <[email protected]> | ||
* @author Johannes Schmitt <[email protected]> | ||
* | ||
* @deprecated The ClassUtils class is deprecated. | ||
*/ | ||
class ClassUtils | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/Doctrine/Tests/Common/Proxy/MagicGetClassWithScalarType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Proxy; | ||
|
||
/** | ||
* Test asset class | ||
* @author Jan Barasek <[email protected]> | ||
*/ | ||
class MagicGetClassWithScalarType | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $id = 'id'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $publicField = 'publicField'; | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return string | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function __get(string $name): string | ||
{ | ||
if ($name === 'test') { | ||
return 'test'; | ||
} | ||
|
||
if ($name === 'publicField' || $name === 'id') { | ||
throw new \BadMethodCallException('Should never be called for "publicField" or "id"'); | ||
} | ||
|
||
return 'not defined'; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Doctrine/Tests/Common/Proxy/MagicGetClassWithScalarTypeAndRenamedParameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Proxy; | ||
|
||
/** | ||
* Test asset class | ||
* @author Jan Barasek <[email protected]> | ||
*/ | ||
class MagicGetClassWithScalarTypeAndRenamedParameter | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $id = 'id'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $publicField = 'publicField'; | ||
|
||
/** | ||
* @param string $n | ||
* | ||
* @return string | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function __get(string $n): string | ||
{ | ||
if ($n === 'test') { | ||
return 'test'; | ||
} | ||
|
||
if ($n === 'publicField' || $n === 'id') { | ||
throw new \BadMethodCallException('Should never be called for "publicField" or "id"'); | ||
} | ||
|
||
return 'not defined'; | ||
} | ||
} |
Oops, something went wrong.