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\GenerateEmbeddableFromArchetypeCommand; |
||
6 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateEntityCommand; |
||
7 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateFieldCommand; |
||
8 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateRelationsCommand; |
||
9 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\RemoveUnusedRelationsCommand; |
||
10 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetEmbeddableCommand; |
||
11 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetFieldCommand; |
||
12 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetRelationCommand; |
||
13 | use EdmondsCommerce\DoctrineStaticMeta\Container; |
||
14 | use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
||
15 | use EdmondsCommerce\DoctrineStaticMeta\Exception\ErrorException; |
||
0 ignored issues
–
show
|
|||
16 | use EdmondsCommerce\DoctrineStaticMeta\Schema\Schema; |
||
17 | use EdmondsCommerce\DoctrineStaticMeta\SimpleEnv; |
||
18 | |||
19 | require __DIR__.'/vendor/autoload.php'; |
||
20 | |||
21 | set_error_handler( |
||
22 | function ($severity, $message, $file, $line) { |
||
23 | if (!(error_reporting() & $severity)) { |
||
24 | // This error code is not included in error_reporting |
||
25 | return; |
||
26 | } |
||
27 | throw new ErrorException($message, 0, $severity, $file, $line); |
||
28 | } |
||
29 | ); |
||
30 | |||
31 | try { |
||
32 | |||
33 | SimpleEnv::setEnv(__DIR__.'/.env'); |
||
34 | $container = new Container(); |
||
35 | $container->buildSymfonyContainer($_SERVER); |
||
36 | |||
37 | $schemaBuilder = $container->get(Schema::class); |
||
38 | $schemaBuilder->validate()->update(); |
||
39 | |||
40 | // This adds the DSM commands into the standard doctrine bin |
||
41 | $commands = [ |
||
42 | $container->get(GenerateRelationsCommand::class), |
||
43 | $container->get(GenerateEntityCommand::class), |
||
44 | $container->get(SetRelationCommand::class), |
||
45 | $container->get(GenerateFieldCommand::class), |
||
46 | $container->get(SetFieldCommand::class), |
||
47 | $container->get(SetEmbeddableCommand::class), |
||
48 | $container->get(GenerateEmbeddableFromArchetypeCommand::class), |
||
49 | $container->get(RemoveUnusedRelationsCommand::class), |
||
50 | ]; |
||
51 | |||
52 | $entityManager = $container->get(EntityManager::class); |
||
53 | } catch (DoctrineStaticMetaException | ErrorException $e) { |
||
54 | throw new DoctrineStaticMetaException('Exception setting up Doctrine CLI: '.$e->getMessage(), $e->getCode(), $e); |
||
55 | } |
||
56 | |||
57 | return ConsoleRunner::createHelperSet($entityManager); |
||
58 | |||
59 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are 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.php
However, as
OtherDir/Foo.php
does 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: