Skip to content

Commit

Permalink
Only add the YamlDriver to the chain when symfony/yaml is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Jun 28, 2023
1 parent ee9acb1 commit d0faf99
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Builder/DefaultDriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Metadata\Driver\DriverChain;
use Metadata\Driver\DriverInterface;
use Metadata\Driver\FileLocator;
use Symfony\Component\Yaml\Yaml;

final class DefaultDriverFactory implements DriverFactoryInterface
{
Expand Down Expand Up @@ -62,11 +63,15 @@ public function createDriver(array $metadataDirs, Reader $annotationReader): Dri

if (!empty($metadataDirs)) {
$fileLocator = new FileLocator($metadataDirs);
$driver = new DriverChain([
new YamlDriver($fileLocator, $this->propertyNamingStrategy, $this->typeParser, $this->expressionEvaluator),
new XmlDriver($fileLocator, $this->propertyNamingStrategy, $this->typeParser, $this->expressionEvaluator),
$driver,
]);
$innerDriver = $driver;
$driver = new DriverChain();

if (class_exists(Yaml::class)) {
$driver->addDriver(new YamlDriver($fileLocator, $this->propertyNamingStrategy, $this->typeParser, $this->expressionEvaluator));
}

$driver->addDriver(new XmlDriver($fileLocator, $this->propertyNamingStrategy, $this->typeParser, $this->expressionEvaluator));
$driver->addDriver($innerDriver);
}

$driver->addDriver(new NullDriver($this->propertyNamingStrategy));
Expand Down

0 comments on commit d0faf99

Please sign in to comment.