Skip to content

Commit

Permalink
DoctrineHelper::createAnnotationMetadataConfiguration not resolving v…
Browse files Browse the repository at this point in the history
…endor folder correctly (#126)

* DoctrineHelper::createAnnotationMetadataConfiguration not resolving vendor from auditor-bundle

* phpstan

Co-authored-by: a.dmitryuk <[email protected]>
Co-authored-by: Damien Harper <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2022
1 parent 2861bd3 commit 85f9ffd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Provider/Doctrine/Persistence/Helper/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DH\Auditor\Provider\Doctrine\Persistence\Helper;

use Composer\Autoload\ClassLoader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Result;
Expand All @@ -18,6 +19,7 @@
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\Setup;
use InvalidArgumentException;
use ReflectionClass;

/**
* @see \DH\Auditor\Tests\Provider\Doctrine\Persistence\Helper\DoctrineHelperTest
Expand Down Expand Up @@ -145,7 +147,7 @@ public static function createAttributeMetadataConfiguration(array $paths, bool $
public static function createAnnotationMetadataConfiguration(array $paths, bool $isDevMode = false): Configuration
{
if (class_exists(ORMSetup::class)) {
require_once __DIR__.'/../../../../../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
require_once self::getVendorDir().'/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';

return ORMSetup::createAnnotationMetadataConfiguration($paths, $isDevMode);
}
Expand All @@ -157,4 +159,13 @@ public static function getEntityManagerFromOnFlushEventArgs(OnFlushEventArgs $ar
{
return method_exists($args, 'getObjectManager') ? $args->getObjectManager() : $args->getEntityManager();
}

public static function getVendorDir(): string
{
$reflection = new ReflectionClass(ClassLoader::class);
$filename = $reflection->getFileName();
\assert(\is_string($filename));

return \dirname($filename, 2);
}
}

0 comments on commit 85f9ffd

Please sign in to comment.