Skip to content

Commit

Permalink
Merge pull request #995 from doctrine/3.4.x-merge-up-into-3.5.x_WbajvUjT
Browse files Browse the repository at this point in the history
Merge release 3.4.3 into 3.5.x
  • Loading branch information
malarzm authored Oct 9, 2022
2 parents a0587f6 + 8b5e565 commit bd3bdee
Show file tree
Hide file tree
Showing 17 changed files with 599 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"name": "3.4",
"branchName": "3.4.x",
"slug": "3.4",
"current": true
"current": true,
"aliases": [
"current",
"stable"
]
},
{
"name": "3.3",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
name: "PHPUnit"
uses: "doctrine/.github/.github/workflows/[email protected]"
with:
php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0", "8.1"]'
php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]'
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
phpVersion: 80100
phpVersion: 80200
level: 3
paths:
- src
Expand Down
11 changes: 11 additions & 0 deletions src/Proxy/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public static function classMustNotBeFinal($className)
return new self(sprintf('Unable to create a proxy for a final class "%s".', $className));
}

/**
* @param string $className
* @psalm-param class-string $className
*
* @return self
*/
public static function classMustNotBeReadOnly($className)
{
return new self(sprintf('Unable to create a proxy for a readonly class "%s".', $className));
}

/** @param mixed $value */
public static function invalidAutoGenerateMode($value): self
{
Expand Down
16 changes: 15 additions & 1 deletion src/Proxy/ProxyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ class ProxyGenerator
* Used to match very simple id methods that don't need
* to be decorated since the identifier is known.
*/
public 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';
public const PATTERN_MATCH_ID_METHOD = <<<'EOT'
((?(DEFINE)
(?<type>\\?[a-z_\x7f-\xff][\w\x7f-\xff]*(?:\\[a-z_\x7f-\xff][\w\x7f-\xff]*)*)
(?<intersection_type>(?&type)\s*&\s*(?&type))
(?<union_type>(?:(?:\(\s*(?&intersection_type)\s*\))|(?&type))(?:\s*\|\s*(?:(?:\(\s*(?&intersection_type)\s*\))|(?&type)))+)
)(?:public\s+)?(?:function\s+%s\s*\(\)\s*)\s*(?::\s*(?:(?&union_type)|(?&intersection_type)|(?:\??(?&type)))\s*)?{\s*return\s*\$this->%s;\s*})i
EOT;

/**
* The namespace that contains all proxy classes.
Expand Down Expand Up @@ -361,6 +367,10 @@ private function verifyClassCanBeProxied(ClassMetadata $class)
if ($class->getReflectionClass()->isAbstract()) {
throw InvalidArgumentException::classMustNotBeAbstract($class->getName());
}

if (PHP_VERSION_ID >= 80200 && $class->getReflectionClass()->isReadOnly()) {
throw InvalidArgumentException::classMustNotBeReadOnly($class->getName());
}
}

/**
Expand Down Expand Up @@ -1214,6 +1224,10 @@ private function formatType(
if ($type instanceof ReflectionUnionType) {
return implode('|', array_map(
function (ReflectionType $unionedType) use ($method, $parameter) {
if ($unionedType instanceof ReflectionIntersectionType) {
return '(' . $this->formatType($unionedType, $method, $parameter) . ')';
}

return $this->formatType($unionedType, $method, $parameter);
},
$type->getTypes()
Expand Down
13 changes: 13 additions & 0 deletions tests/Common/Proxy/LazyLoadableObjectWithPHP81IntersectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Doctrine\Tests\Common\Proxy;

class LazyLoadableObjectWithPHP81IntersectionType
{
private \stdClass&\Stringable $identifierFieldIntersectionType;

public function getIdentifierFieldIntersectionType(): \stdClass&\Stringable
{
return $this->identifierFieldIntersectionType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

namespace Doctrine\Tests\Common\Proxy;

use BadMethodCallException;
use Doctrine\Persistence\Mapping\ClassMetadata;
use ReflectionClass;
use function array_keys;

class LazyLoadableObjectWithPHP81IntersectionTypeClassMetadata implements ClassMetadata
{
/** @var ReflectionClass */
protected $reflectionClass;

/** @var array<string,bool> */
protected $identifier = [
'identifierFieldIntersectionType' => true,
];

/** @var array<string,bool> */
protected $fields = [
'identifierFieldIntersectionType' => true,
];

/**
* {@inheritDoc}
*/
public function getName()
{
return $this->getReflectionClass()->getName();
}

/**
* {@inheritDoc}
*/
public function getIdentifier()
{
return array_keys($this->identifier);
}

/**
* {@inheritDoc}
*/
public function getReflectionClass()
{
if ($this->reflectionClass === null) {
$this->reflectionClass = new ReflectionClass(__NAMESPACE__ . '\LazyLoadableObjectWithPHP81IntersectionType');
}

return $this->reflectionClass;
}

/**
* {@inheritDoc}
*/
public function isIdentifier($fieldName)
{
return isset($this->identifier[$fieldName]);
}

/**
* {@inheritDoc}
*/
public function hasField($fieldName)
{
return isset($this->fields[$fieldName]);
}

/**
* {@inheritDoc}
*/
public function hasAssociation($fieldName)
{
return false;
}

/**
* {@inheritDoc}
*/
public function isSingleValuedAssociation($fieldName)
{
throw new BadMethodCallException('not implemented');
}

/**
* {@inheritDoc}
*/
public function isCollectionValuedAssociation($fieldName)
{
throw new BadMethodCallException('not implemented');
}

/**
* {@inheritDoc}
*/
public function getFieldNames()
{
return array_keys($this->fields);
}

/**
* {@inheritDoc}
*/
public function getIdentifierFieldNames()
{
return $this->getIdentifier();
}

/**
* {@inheritDoc}
*/
public function getAssociationNames()
{
return [];
}

/**
* {@inheritDoc}
*/
public function getTypeOfField($fieldName)
{
return 'string';
}

/**
* {@inheritDoc}
*/
public function getAssociationTargetClass($assocName)
{
throw new BadMethodCallException('not implemented');
}

/**
* {@inheritDoc}
*/
public function isAssociationInverseSide($assocName)
{
throw new BadMethodCallException('not implemented');
}

/**
* {@inheritDoc}
*/
public function getAssociationMappedByTargetField($assocName)
{
throw new BadMethodCallException('not implemented');
}

/**
* {@inheritDoc}
*/
public function getIdentifierValues($object)
{
throw new BadMethodCallException('not implemented');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Doctrine\Tests\Common\Proxy;

class LazyLoadableObjectWithPHP82UnionAndIntersectionType
{
private (\stdClass&\Stringable)|null $identifierFieldUnionAndIntersectionType = null;

public function getIdentifierFieldUnionAndIntersectionType(): (\stdClass&\Stringable)|null
{
return $this->identifierFieldUnionAndIntersectionType;
}
}
Loading

0 comments on commit bd3bdee

Please sign in to comment.