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