Skip to content

Commit 430fb82

Browse files
committed
Add suport for symfony/property-info 7.3@beta
1 parent 321cc75 commit 430fb82

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- [GH#274](https://github.com/jolicode/automapper/pull/274) Fix support for Symfony 7.3
12+
1013
### Added
1114
- [GH#246](https://github.com/jolicode/automapper/pull/246) Add support for PHP 8.4
1215
- [GH#246](https://github.com/jolicode/automapper/pull/246) Add support for API Platform 4

src/Extractor/GetTypeTrait.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
use PHPStan\PhpDocParser\Parser\TokenIterator;
1414
use PHPStan\PhpDocParser\Parser\TypeParser;
1515
use PHPStan\PhpDocParser\ParserConfig;
16+
use Symfony\Component\PropertyInfo\PhpStan\NameScope;
1617
use Symfony\Component\PropertyInfo\PhpStan\NameScopeFactory;
1718
use Symfony\Component\PropertyInfo\Type;
1819
use Symfony\Component\PropertyInfo\Util\PhpStanTypeHelper;
20+
use Symfony\Component\TypeInfo\TypeContext\TypeContext;
21+
use Symfony\Component\TypeInfo\TypeContext\TypeContextFactory;
1922

2023
/**
2124
* Add helper functions to extract types from a property.
@@ -58,13 +61,12 @@ private function extractFromDocBlock(string|false|null $rawDocNode, string $clas
5861
}
5962
}
6063

61-
static $nameScopeFactory = new NameScopeFactory();
6264
static $phpStanTypeHelper = new PhpStanTypeHelper();
6365

6466
$tokens = new TokenIterator($lexer->tokenize($rawDocNode));
6567
$docNode = $phpDocParser->parse($tokens);
6668
$tokens->consumeTokenType(Lexer::TOKEN_END);
67-
$nameScope = $nameScopeFactory->create($class, $declaringClass);
69+
$nameScope = $this->createNameScope($class, $declaringClass);
6870

6971
$types = [];
7072

@@ -159,4 +161,18 @@ private function resolveTypeName(string $name, \ReflectionClass $declaringClass)
159161

160162
return $name;
161163
}
164+
165+
private function createNameScope(string $class, string $declaringClass): NameScope|TypeContext
166+
{
167+
// For Symfony <=7.2. To remove when we drop support for Symfony <= 7.2
168+
if (class_exists(NameScopeFactory::class)) {
169+
static $nameScopeFactory = new NameScopeFactory();
170+
171+
return $nameScopeFactory->create($class, $declaringClass);
172+
}
173+
174+
static $typeContextFactory = new TypeContextFactory();
175+
176+
return $typeContextFactory->createFromClassName($class, $declaringClass);
177+
}
162178
}

0 commit comments

Comments
 (0)