1 | <?php |
||
2 | |||
3 | namespace Bone\BoneDoctrine; |
||
4 | |||
5 | use Barnacle\Container; |
||
6 | use Barnacle\Exception\NotFoundException; |
||
7 | use Barnacle\RegistrationInterface; |
||
8 | use Bone\BoneDoctrine\Command\LoadFixturesCommand; |
||
9 | use Bone\Console\CommandRegistrationInterface; |
||
10 | use Bone\Console\ConsoleApplication; |
||
11 | use Doctrine\Common\Cache\Psr6\DoctrineProvider; |
||
0 ignored issues
–
show
|
|||
12 | use Doctrine\DBAL\Connection; |
||
13 | use Doctrine\DBAL\DriverManager; |
||
14 | use Doctrine\Migrations\Configuration\Configuration; |
||
15 | use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager; |
||
16 | use Doctrine\Migrations\Configuration\Migration\ExistingConfiguration; |
||
17 | use Doctrine\Migrations\DependencyFactory; |
||
18 | use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; |
||
19 | use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; |
||
20 | use Doctrine\Migrations\Tools\Console\Command\DiffCommand; |
||
21 | use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand; |
||
22 | use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand; |
||
23 | use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; |
||
24 | use Doctrine\Migrations\Tools\Console\Command\LatestCommand; |
||
25 | use Doctrine\Migrations\Tools\Console\Command\ListCommand; |
||
26 | use Doctrine\Migrations\Tools\Console\Command\MigrateCommand; |
||
27 | use Doctrine\Migrations\Tools\Console\Command\RollupCommand; |
||
28 | use Doctrine\Migrations\Tools\Console\Command\StatusCommand; |
||
29 | use Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand; |
||
30 | use Doctrine\Migrations\Tools\Console\Command\VersionCommand; |
||
31 | use Doctrine\ORM\EntityManager; |
||
32 | use Doctrine\ORM\EntityManagerInterface; |
||
33 | use Doctrine\ORM\ORMSetup; |
||
34 | use Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand; |
||
35 | use Doctrine\ORM\Tools\Console\Command\InfoCommand; |
||
36 | use Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand; |
||
37 | use Doctrine\ORM\Tools\Console\Command\RunDqlCommand; |
||
38 | use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand; |
||
39 | use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand; |
||
40 | use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand; |
||
41 | use Doctrine\ORM\Tools\Console\ConsoleRunner; |
||
42 | use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider; |
||
43 | use Symfony\Component\Console\Helper\QuestionHelper; |
||
44 | use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
||
45 | |||
46 | class BoneDoctrinePackage implements RegistrationInterface, CommandRegistrationInterface |
||
47 | { |
||
48 | /** |
||
49 | * @param Container $c |
||
50 | * @throws \Doctrine\ORM\ORMException |
||
51 | */ |
||
52 | 5 | public function addToContainer(Container $c) |
|
53 | { |
||
54 | /** @var EntityManager $em */ |
||
55 | |||
56 | 5 | if (!$c->has('cache_dir')) { |
|
57 | 1 | throw new NotFoundException('please set cache_dir in your config'); |
|
58 | } |
||
59 | |||
60 | 4 | if (!$c->has('db')) { |
|
61 | 1 | throw new NotFoundException('please set db connection details in your config'); |
|
62 | } |
||
63 | |||
64 | 3 | if (!$c->has('entity_paths')) { |
|
65 | 1 | throw new NotFoundException('please set entity_paths in your config'); |
|
66 | } |
||
67 | |||
68 | 2 | if (!$c->has('proxy_dir')) { |
|
69 | 1 | throw new NotFoundException('please set proxy_dir in your config'); |
|
70 | } |
||
71 | |||
72 | 1 | $credentials = $c->get('db'); |
|
73 | 1 | $entityPaths = $c->get('entity_paths'); |
|
74 | 1 | $proxyDir =$c->get('proxy_dir'); |
|
75 | 1 | $cacheDir = $c->get('cache_dir'); |
|
76 | 1 | $isDevMode = $c->has('devMode') ? $c->get('devMode') : false; |
|
77 | 1 | $cachePool = new FilesystemAdapter('', 60, $cacheDir); |
|
78 | 1 | $config = ORMSetup::createAttributeMetadataConfiguration($entityPaths, $isDevMode, $proxyDir, $cachePool); |
|
79 | 1 | $config->setProxyNamespace('DoctrineProxies'); |
|
80 | 1 | $config->setQueryCache($cachePool); |
|
81 | 1 | $connection = DriverManager::getConnection($credentials, $config); |
|
82 | 1 | $entityManager = new EntityManager($connection, $config); |
|
83 | |||
84 | 1 | $c[EntityManager::class] = $entityManager; |
|
85 | 1 | $c[EntityManagerInterface::class] = $entityManager; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param Container $container |
||
90 | * @return array |
||
91 | */ |
||
92 | 1 | public function registerConsoleCommands(Container $container): array |
|
93 | { |
||
94 | /** @var EntityManager $em $em */ |
||
95 | 1 | $em = $container->get(EntityManager::class); |
|
96 | 1 | $app = $container->get(ConsoleApplication::class); |
|
0 ignored issues
–
show
|
|||
97 | 1 | $migrationsDir = 'data/migrations'; |
|
98 | 1 | $meta = new TableMetadataStorageConfiguration(); |
|
99 | 1 | $meta->setTableName('Migration'); |
|
100 | 1 | $configuration = new Configuration(); |
|
101 | 1 | $configuration->addMigrationsDirectory('Migrations', $migrationsDir); |
|
102 | 1 | $configuration->setMetadataStorageConfiguration($meta); |
|
103 | |||
104 | 1 | $configLoader = new ExistingConfiguration($configuration); |
|
105 | 1 | $emLoader = new ExistingEntityManager($em); |
|
106 | 1 | $dependencyFactory = DependencyFactory::fromEntityManager($configLoader, $emLoader); |
|
107 | 1 | $emProvider = new SingleManagerProvider($em); |
|
108 | |||
109 | 1 | $diff = new DiffCommand($dependencyFactory); |
|
110 | 1 | $dump = new DumpSchemaCommand($dependencyFactory); |
|
111 | 1 | $exec = new ExecuteCommand($dependencyFactory); |
|
112 | 1 | $gen = new GenerateCommand($dependencyFactory); |
|
113 | 1 | $latest = new LatestCommand($dependencyFactory); |
|
114 | 1 | $list = new ListCommand($dependencyFactory); |
|
115 | 1 | $migrate = new MigrateCommand($dependencyFactory); |
|
116 | 1 | $rollup = new RollupCommand($dependencyFactory); |
|
117 | 1 | $status = new StatusCommand($dependencyFactory); |
|
118 | 1 | $sync = new SyncMetadataCommand($dependencyFactory); |
|
119 | 1 | $ver = new VersionCommand($dependencyFactory); |
|
120 | 1 | $dropDb = new DropCommand($emProvider); |
|
121 | 1 | $createDb = new CreateCommand($emProvider); |
|
122 | 1 | $validate = new ValidateSchemaCommand($emProvider); |
|
123 | 1 | $proxy = new GenerateProxiesCommand($emProvider); |
|
124 | 1 | $info = new InfoCommand($emProvider); |
|
125 | 1 | $mappingDescribe = new MappingDescribeCommand($emProvider); |
|
126 | 1 | $runDql = new RunDqlCommand($emProvider); |
|
127 | 1 | $fixtures = new LoadFixturesCommand($em, $container->has('fixtures') ? $container->get('fixtures') : []); |
|
128 | |||
129 | 1 | $diff->setName('migrant:diff'); |
|
130 | 1 | $createDb->setName('migrant:create'); |
|
131 | 1 | $dropDb->setName('migrant:drop'); |
|
132 | 1 | $dump->setName('migrant:dump'); |
|
133 | 1 | $exec->setName('migrant:execute'); |
|
134 | 1 | $gen->setName('migrant:generate'); |
|
135 | 1 | $info->setName('migrant:info'); |
|
136 | 1 | $latest->setName('migrant:latest'); |
|
137 | 1 | $list->setName('migrant:list'); |
|
138 | 1 | $mappingDescribe->setName('migrant:describe'); |
|
139 | 1 | $migrate->setName('migrant:migrate'); |
|
140 | 1 | $runDql->setName('migrant:run-dql'); |
|
141 | 1 | $rollup->setName('migrant:rollup'); |
|
142 | 1 | $status->setName('migrant:status'); |
|
143 | 1 | $sync->setName('migrant:sync'); |
|
144 | 1 | $validate->setName('migrant:validate'); |
|
145 | 1 | $ver->setName('migrant:version'); |
|
146 | 1 | $proxy->setName('migrant:generate-proxies'); |
|
147 | |||
148 | |||
149 | 1 | $commands = [$createDb, $dropDb, $diff, $dump, $exec, $gen, $info, $latest, $list, $mappingDescribe, $migrate, $rollup, $runDql, $status, $sync, $validate, $ver, $proxy, $fixtures]; |
|
150 | |||
151 | /** @var DoctrineCommand $command */ |
||
152 | 1 | foreach ($commands as $command) { |
|
153 | 1 | $name = $command->getName(); |
|
154 | 1 | $name = str_replace(array('migrations:', 'orm:'), '', $name); |
|
155 | 1 | $command->setName($name); |
|
156 | } |
||
157 | |||
158 | 1 | return $commands; |
|
159 | } |
||
160 | } |
||
161 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths