1 | <?php declare(strict_types=1); |
||
2 | |||
3 | use Doctrine\ORM\EntityManagerInterface; |
||
4 | use Doctrine\ORM\Tools\Console\ConsoleRunner; |
||
5 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\CreateConstraintCommand; |
||
6 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateEmbeddableFromArchetypeCommand; |
||
7 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateEntityCommand; |
||
8 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateFieldCommand; |
||
9 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateRelationsCommand; |
||
10 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\OverrideCreateCommand; |
||
11 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\OverridesUpdateCommand; |
||
12 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\RemoveUnusedRelationsCommand; |
||
13 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetEmbeddableCommand; |
||
14 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetFieldCommand; |
||
15 | use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetRelationCommand; |
||
16 | use EdmondsCommerce\DoctrineStaticMeta\Container; |
||
17 | use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
||
18 | use EdmondsCommerce\DoctrineStaticMeta\Exception\ErrorException; |
||
0 ignored issues
–
show
|
|||
19 | use EdmondsCommerce\DoctrineStaticMeta\Schema\Schema; |
||
20 | use EdmondsCommerce\DoctrineStaticMeta\SimpleEnv; |
||
21 | |||
22 | require __DIR__ . '/vendor/autoload.php'; |
||
23 | |||
24 | set_error_handler( |
||
25 | function ($severity, $message, $file, $line) { |
||
26 | if (!(error_reporting() & $severity)) { |
||
27 | // This error code is not included in error_reporting |
||
28 | return; |
||
29 | } |
||
30 | throw new ErrorException($message, 0, $severity, $file, $line); |
||
31 | } |
||
32 | ); |
||
33 | |||
34 | try { |
||
35 | |||
36 | SimpleEnv::setEnv(__DIR__ . '/.env'); |
||
37 | $container = new Container(); |
||
38 | $container->buildSymfonyContainer($_SERVER); |
||
39 | |||
40 | $schemaBuilder = $container->get(Schema::class); |
||
41 | $schemaBuilder->validate()->update(); |
||
42 | |||
43 | // This adds the DSM commands into the standard doctrine bin |
||
44 | $commands = [ |
||
45 | $container->get(GenerateRelationsCommand::class), |
||
46 | $container->get(GenerateEntityCommand::class), |
||
47 | $container->get(SetRelationCommand::class), |
||
48 | $container->get(GenerateFieldCommand::class), |
||
49 | $container->get(SetFieldCommand::class), |
||
50 | $container->get(SetEmbeddableCommand::class), |
||
51 | $container->get(GenerateEmbeddableFromArchetypeCommand::class), |
||
52 | $container->get(RemoveUnusedRelationsCommand::class), |
||
53 | $container->get(OverrideCreateCommand::class), |
||
54 | $container->get(OverridesUpdateCommand::class), |
||
55 | $container->get(CreateConstraintCommand::class), |
||
56 | ]; |
||
57 | |||
58 | $entityManager = $container->get(EntityManagerInterface::class); |
||
59 | } catch (DoctrineStaticMetaException | ErrorException $e) { |
||
60 | throw new DoctrineStaticMetaException('Exception setting up Doctrine CLI: ' . $e->getMessage(), $e->getCode(), $e); |
||
61 | } |
||
62 | |||
63 | return ConsoleRunner::createHelperSet($entityManager); |
||
64 | |||
65 |
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: