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\CliConfigCommandFactory; |
||
6 | use EdmondsCommerce\DoctrineStaticMeta\Container; |
||
7 | use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
||
8 | use EdmondsCommerce\DoctrineStaticMeta\Exception\ErrorException; |
||
0 ignored issues
–
show
|
|||
9 | use EdmondsCommerce\DoctrineStaticMeta\Schema\Schema; |
||
10 | use EdmondsCommerce\DoctrineStaticMeta\SimpleEnv; |
||
11 | |||
12 | require __DIR__ . '/vendor/autoload.php'; |
||
13 | |||
14 | set_error_handler( |
||
15 | function ($severity, $message, $file, $line) { |
||
16 | if (!(error_reporting() & $severity)) { |
||
17 | // This error code is not included in error_reporting |
||
18 | return; |
||
19 | } |
||
20 | throw new ErrorException($message, 0, $severity, $file, $line); |
||
21 | } |
||
22 | ); |
||
23 | |||
24 | try { |
||
25 | |||
26 | SimpleEnv::setEnv(__DIR__ . '/.env'); |
||
27 | $container = new Container(); |
||
28 | $container->buildSymfonyContainer($_SERVER); |
||
29 | |||
30 | $schemaBuilder = $container->get(Schema::class); |
||
31 | $schemaBuilder->validate()->update(); |
||
32 | |||
33 | // This adds the DSM commands into the standard doctrine bin |
||
34 | $commands = $container->get(CliConfigCommandFactory::class)->getCommands(); |
||
35 | |||
36 | $entityManager = $container->get(EntityManagerInterface::class); |
||
37 | } catch (DoctrineStaticMetaException | ErrorException $e) { |
||
38 | throw new DoctrineStaticMetaException('Exception setting up Doctrine CLI: ' . $e->getMessage(), $e->getCode(), $e); |
||
39 | } |
||
40 | |||
41 | return ConsoleRunner::createHelperSet($entityManager); |
||
42 | |||
43 |
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: