edmondscommerce /
doctrine-static-meta
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | use Doctrine\ORM\EntityManager; |
||
| 4 | use Doctrine\ORM\Tools\Console\ConsoleRunner; |
||
| 5 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateEntityCommand; |
||
| 6 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateFieldCommand; |
||
| 7 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateRelationsCommand; |
||
| 8 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetFieldCommand; |
||
| 9 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetRelationCommand; |
||
| 10 | use EdmondsCommerce\DoctrineStaticMeta\Container; |
||
| 11 | use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
||
| 12 | use EdmondsCommerce\DoctrineStaticMeta\Exception\ErrorException; |
||
|
0 ignored issues
–
show
|
|||
| 13 | use EdmondsCommerce\DoctrineStaticMeta\Schema\Schema; |
||
| 14 | use EdmondsCommerce\DoctrineStaticMeta\SimpleEnv; |
||
| 15 | |||
| 16 | require __DIR__.'/vendor/autoload.php'; |
||
| 17 | |||
| 18 | set_error_handler( |
||
| 19 | function ($severity, $message, $file, $line) { |
||
| 20 | if (!(error_reporting() & $severity)) { |
||
| 21 | // This error code is not included in error_reporting |
||
| 22 | return; |
||
| 23 | } |
||
| 24 | throw new ErrorException($message, 0, $severity, $file, $line); |
||
| 25 | } |
||
| 26 | ); |
||
| 27 | |||
| 28 | try { |
||
| 29 | |||
| 30 | SimpleEnv::setEnv(__DIR__.'/.env'); |
||
| 31 | $container = new Container(); |
||
| 32 | $container->buildSymfonyContainer($_SERVER); |
||
| 33 | |||
| 34 | $schemaBuilder = $container->get(Schema::class); |
||
| 35 | $schemaBuilder->validate()->update(); |
||
| 36 | |||
| 37 | // This adds the DSM commands into the standard doctrine bin |
||
| 38 | $commands = [ |
||
| 39 | $container->get(GenerateRelationsCommand::class), |
||
| 40 | $container->get(GenerateEntityCommand::class), |
||
| 41 | $container->get(SetRelationCommand::class), |
||
| 42 | $container->get(GenerateFieldCommand::class), |
||
| 43 | $container->get(SetFieldCommand::class) |
||
| 44 | ]; |
||
| 45 | |||
| 46 | $entityManager = $container->get(EntityManager::class); |
||
| 47 | } catch (DoctrineStaticMetaException | ErrorException $e) { |
||
| 48 | throw new DoctrineStaticMetaException('Exception setting up Doctrine CLI: '.$e->getMessage(), $e->getCode(), $e); |
||
| 49 | } |
||
| 50 | |||
| 51 | return ConsoleRunner::createHelperSet($entityManager); |
||
| 52 | |||
| 53 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: