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 | // echo "\n\nException setting up Doctrine CLI: ".$e->getMessage()."\n\n"; |
||
50 | // echo $e->getTraceAsStringRelativePath(); |
||
51 | // echo "\n\n"; |
||
52 | // exit(1); |
||
53 | } |
||
54 | |||
55 | return ConsoleRunner::createHelperSet($entityManager); |
||
56 | |||
57 |
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: