Complex classes like OrmExtension often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use OrmExtension, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class OrmExtension extends Nette\DI\CompilerExtension |
||
| 30 | { |
||
| 31 | |||
| 32 | const ANNOTATION_DRIVER = 'annotations'; |
||
| 33 | const PHP_NAMESPACE = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\\\\]*'; |
||
| 34 | const TAG_CONNECTION = 'doctrine.connection'; |
||
| 35 | const TAG_ENTITY_MANAGER = 'doctrine.entityManager'; |
||
| 36 | const TAG_BIND_TO_MANAGER = 'doctrine.bindToManager'; |
||
| 37 | const TAG_REPOSITORY_ENTITY = 'doctrine.repositoryEntity'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | public $managerDefaults = [ |
||
| 43 | 'metadataCache' => 'default', |
||
| 44 | 'queryCache' => 'default', |
||
| 45 | 'resultCache' => 'default', |
||
| 46 | 'hydrationCache' => 'default', |
||
| 47 | 'secondLevelCache' => [ |
||
| 48 | 'enabled' => FALSE, |
||
| 49 | 'factoryClass' => 'Doctrine\ORM\Cache\DefaultCacheFactory', |
||
| 50 | 'driver' => 'default', |
||
| 51 | 'regions' => [ |
||
| 52 | 'defaultLifetime' => 3600, |
||
| 53 | 'defaultLockLifetime' => 60, |
||
| 54 | ], |
||
| 55 | 'fileLockRegionDirectory' => '%tempDir%/cache/Doctrine.Cache.Locks', // todo fix |
||
| 56 | 'logging' => '%debugMode%', |
||
| 57 | ], |
||
| 58 | 'classMetadataFactory' => 'Kdyby\Doctrine\Mapping\ClassMetadataFactory', |
||
| 59 | 'defaultRepositoryClassName' => 'Kdyby\Doctrine\EntityRepository', |
||
| 60 | 'repositoryFactoryClassName' => 'Kdyby\Doctrine\RepositoryFactory', |
||
| 61 | 'queryBuilderClassName' => 'Kdyby\Doctrine\QueryBuilder', |
||
| 62 | 'autoGenerateProxyClasses' => '%debugMode%', |
||
| 63 | 'namingStrategy' => 'Doctrine\ORM\Mapping\UnderscoreNamingStrategy', |
||
| 64 | 'quoteStrategy' => 'Doctrine\ORM\Mapping\DefaultQuoteStrategy', |
||
| 65 | 'entityListenerResolver' => 'Kdyby\Doctrine\Mapping\EntityListenerResolver', |
||
| 66 | 'proxyDir' => '%tempDir%/proxies', |
||
| 67 | 'proxyNamespace' => 'Kdyby\GeneratedProxy', |
||
| 68 | 'dql' => ['string' => [], 'numeric' => [], 'datetime' => [], 'hints' => []], |
||
| 69 | 'hydrators' => [], |
||
| 70 | 'metadata' => [], |
||
| 71 | 'filters' => [], |
||
| 72 | 'namespaceAlias' => [], |
||
| 73 | 'targetEntityMappings' => [], |
||
| 74 | ]; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var array |
||
| 78 | */ |
||
| 79 | public $connectionDefaults = [ |
||
| 80 | 'dbname' => NULL, |
||
| 81 | 'host' => '127.0.0.1', |
||
| 82 | 'port' => NULL, |
||
| 83 | 'user' => NULL, |
||
| 84 | 'password' => NULL, |
||
| 85 | 'charset' => 'UTF8', |
||
| 86 | 'driver' => 'pdo_mysql', |
||
| 87 | 'driverClass' => NULL, |
||
| 88 | 'options' => NULL, |
||
| 89 | 'path' => NULL, |
||
| 90 | 'memory' => NULL, |
||
| 91 | 'unix_socket' => NULL, |
||
| 92 | 'logging' => '%debugMode%', |
||
| 93 | 'platformService' => NULL, |
||
| 94 | 'defaultTableOptions' => [], |
||
| 95 | 'resultCache' => 'default', |
||
| 96 | 'types' => [], |
||
| 97 | 'schemaFilter' => NULL, |
||
| 98 | ]; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var array |
||
| 102 | */ |
||
| 103 | public $metadataDriverClasses = [ |
||
| 104 | self::ANNOTATION_DRIVER => 'Kdyby\Doctrine\Mapping\AnnotationDriver', |
||
| 105 | 'static' => 'Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver', |
||
| 106 | 'yml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver', |
||
| 107 | 'yaml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver', |
||
| 108 | 'xml' => 'Doctrine\ORM\Mapping\Driver\XmlDriver', |
||
| 109 | 'db' => 'Doctrine\ORM\Mapping\Driver\DatabaseDriver', |
||
| 110 | ]; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @var array |
||
| 114 | */ |
||
| 115 | private $proxyAutoloaders = []; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var array |
||
| 119 | */ |
||
| 120 | private $targetEntityMappings = []; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var array |
||
| 124 | */ |
||
| 125 | private $configuredManagers = []; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var array |
||
| 129 | */ |
||
| 130 | private $managerConfigs = []; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var array |
||
| 134 | */ |
||
| 135 | private $configuredConnections = []; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var array |
||
| 139 | */ |
||
| 140 | private $postCompileRepositoriesQueue = []; |
||
| 141 | |||
| 142 | |||
| 143 | |||
| 144 | public function loadConfiguration() |
||
| 145 | { |
||
| 146 | $this->proxyAutoloaders = |
||
| 147 | $this->targetEntityMappings = |
||
| 148 | $this->configuredConnections = |
||
| 149 | $this->managerConfigs = |
||
| 150 | $this->configuredManagers = |
||
| 151 | $this->postCompileRepositoriesQueue = []; |
||
| 152 | |||
| 153 | $extensions = array_filter($this->compiler->getExtensions(), function ($item) { |
||
| 154 | return $item instanceof Kdyby\Annotations\DI\AnnotationsExtension; |
||
| 155 | }); |
||
| 156 | if (empty($extensions)) { |
||
| 157 | throw new Nette\Utils\AssertionException('You should register \'Kdyby\Annotations\DI\AnnotationsExtension\' before \'' . get_class($this) . '\'.', E_USER_NOTICE); |
||
| 158 | } |
||
| 159 | |||
| 160 | $builder = $this->getContainerBuilder(); |
||
| 161 | $config = $this->getConfig(); |
||
| 162 | |||
| 163 | $builder->parameters[$this->prefix('debug')] = !empty($config['debug']); |
||
| 164 | if (isset($config['dbname']) || isset($config['driver']) || isset($config['connection'])) { |
||
| 165 | $config = ['default' => $config]; |
||
| 166 | $defaults = ['debug' => $builder->parameters['debugMode']]; |
||
| 167 | |||
| 168 | } else { |
||
| 169 | $defaults = array_intersect_key($config, $this->managerDefaults) |
||
| 170 | + array_intersect_key($config, $this->connectionDefaults) |
||
| 171 | + ['debug' => $builder->parameters['debugMode']]; |
||
| 172 | |||
| 173 | $config = array_diff_key($config, $defaults); |
||
| 174 | } |
||
| 175 | |||
| 176 | if (empty($config)) { |
||
| 177 | throw new Kdyby\Doctrine\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file."); |
||
| 178 | } |
||
| 179 | |||
| 180 | foreach ($config as $name => $emConfig) { |
||
| 181 | if (!is_array($emConfig) || (empty($emConfig['dbname']) && empty($emConfig['driver']))) { |
||
| 182 | throw new Kdyby\Doctrine\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file."); |
||
| 183 | } |
||
| 184 | |||
| 185 | $emConfig = Nette\DI\Config\Helpers::merge($emConfig, $defaults); |
||
| 186 | $this->processEntityManager($name, $emConfig); |
||
|
|
|||
| 187 | } |
||
| 188 | |||
| 189 | if ($this->targetEntityMappings) { |
||
| 190 | if (count($this->compiler->getExtensions('Kdyby\Events\DI\EventsExtension')) === 0) { |
||
| 191 | throw new Nette\Utils\AssertionException('The option \'targetEntityMappings\' required \'Kdyby\Events\DI\EventsExtension\'.', E_USER_NOTICE); |
||
| 192 | } |
||
| 193 | |||
| 194 | $listener = $builder->addDefinition($this->prefix('resolveTargetEntityListener')) |
||
| 195 | ->setClass('Kdyby\Doctrine\Tools\ResolveTargetEntityListener') |
||
| 196 | ->addTag(Kdyby\Events\DI\EventsExtension::SUBSCRIBER_TAG) |
||
| 197 | ->setInject(FALSE); |
||
| 198 | |||
| 199 | foreach ($this->targetEntityMappings as $originalEntity => $mapping) { |
||
| 200 | $listener->addSetup('addResolveTargetEntity', [$originalEntity, $mapping['targetEntity'], $mapping]); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | $this->loadConsole(); |
||
| 205 | |||
| 206 | $builder->addDefinition($this->prefix('registry')) |
||
| 207 | ->setClass('Kdyby\Doctrine\Registry', [ |
||
| 208 | $this->configuredConnections, |
||
| 209 | $this->configuredManagers, |
||
| 210 | $builder->parameters[$this->name]['dbal']['defaultConnection'], |
||
| 211 | $builder->parameters[$this->name]['orm']['defaultEntityManager'], |
||
| 212 | ]); |
||
| 213 | } |
||
| 214 | |||
| 215 | |||
| 216 | |||
| 217 | protected function loadConsole() |
||
| 218 | { |
||
| 219 | $builder = $this->getContainerBuilder(); |
||
| 220 | |||
| 221 | foreach ($this->loadFromFile(__DIR__ . '/console.neon') as $i => $command) { |
||
| 222 | $cli = $builder->addDefinition($this->prefix('cli.' . $i)) |
||
| 223 | ->addTag(Kdyby\Console\DI\ConsoleExtension::COMMAND_TAG) |
||
| 224 | ->setInject(FALSE); // lazy injects |
||
| 225 | |||
| 226 | if (is_string($command)) { |
||
| 227 | $cli->setClass($command); |
||
| 228 | |||
| 229 | } else { |
||
| 230 | throw new Kdyby\Doctrine\NotSupportedException; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | |||
| 236 | |||
| 237 | protected function processEntityManager($name, array $defaults) |
||
| 238 | { |
||
| 239 | $builder = $this->getContainerBuilder(); |
||
| 240 | $config = $this->resolveConfig($defaults, $this->managerDefaults, $this->connectionDefaults); |
||
| 241 | |||
| 242 | if ($isDefault = !isset($builder->parameters[$this->name]['orm']['defaultEntityManager'])) { |
||
| 243 | $builder->parameters[$this->name]['orm']['defaultEntityManager'] = $name; |
||
| 244 | } |
||
| 245 | |||
| 246 | $metadataDriver = $builder->addDefinition($this->prefix($name . '.metadataDriver')) |
||
| 247 | ->setClass('Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain') |
||
| 248 | ->setAutowired(FALSE) |
||
| 249 | ->setInject(FALSE); |
||
| 250 | /** @var Nette\DI\ServiceDefinition $metadataDriver */ |
||
| 251 | |||
| 252 | Validators::assertField($config, 'metadata', 'array'); |
||
| 253 | Validators::assertField($config, 'targetEntityMappings', 'array'); |
||
| 254 | $config['targetEntityMappings'] = $this->normalizeTargetEntityMappings($config['targetEntityMappings']); |
||
| 255 | foreach ($this->compiler->getExtensions() as $extension) { |
||
| 256 | if ($extension instanceof IEntityProvider) { |
||
| 257 | $metadata = $extension->getEntityMappings(); |
||
| 258 | Validators::assert($metadata, 'array'); |
||
| 259 | $config['metadata'] = array_merge($config['metadata'], $metadata); |
||
| 260 | } |
||
| 261 | |||
| 262 | if ($extension instanceof ITargetEntityProvider) { |
||
| 263 | $targetEntities = $extension->getTargetEntityMappings(); |
||
| 264 | Validators::assert($targetEntities, 'array'); |
||
| 265 | $config['targetEntityMappings'] = Nette\Utils\Arrays::mergeTree($config['targetEntityMappings'], $this->normalizeTargetEntityMappings($targetEntities)); |
||
| 266 | } |
||
| 267 | |||
| 268 | if ($extension instanceof IDatabaseTypeProvider) { |
||
| 269 | $providedTypes = $extension->getDatabaseTypes(); |
||
| 270 | Validators::assert($providedTypes, 'array'); |
||
| 271 | |||
| 272 | if (!isset($defaults['types'])) { |
||
| 273 | $defaults['types'] = []; |
||
| 274 | } |
||
| 275 | |||
| 276 | $defaults['types'] = array_merge($defaults['types'], $providedTypes); |
||
| 277 | } |
||
| 278 | } |
||
| 279 | |||
| 280 | foreach (self::natSortKeys($config['metadata']) as $namespace => $driver) { |
||
| 281 | $this->processMetadataDriver($metadataDriver, $namespace, $driver, $name); |
||
| 282 | } |
||
| 283 | |||
| 284 | $this->processMetadataDriver($metadataDriver, 'Kdyby\\Doctrine', __DIR__ . '/../Entities', $name); |
||
| 285 | |||
| 286 | if (empty($config['metadata'])) { |
||
| 287 | $metadataDriver->addSetup('setDefaultDriver', [ |
||
| 288 | new Statement($this->metadataDriverClasses[self::ANNOTATION_DRIVER], [ |
||
| 289 | [$builder->expand('%appDir%')], |
||
| 290 | 2 => $this->prefix('@cache.' . $name . '.metadata') |
||
| 291 | ]) |
||
| 292 | ]); |
||
| 293 | } |
||
| 294 | |||
| 295 | if ($config['repositoryFactoryClassName'] === 'default') { |
||
| 296 | $config['repositoryFactoryClassName'] = 'Doctrine\ORM\Repository\DefaultRepositoryFactory'; |
||
| 297 | } |
||
| 298 | $builder->addDefinition($this->prefix($name . '.repositoryFactory')) |
||
| 299 | ->setClass($config['repositoryFactoryClassName']) |
||
| 300 | ->setAutowired(FALSE); |
||
| 301 | |||
| 302 | Validators::assertField($config, 'namespaceAlias', 'array'); |
||
| 303 | Validators::assertField($config, 'hydrators', 'array'); |
||
| 304 | Validators::assertField($config, 'dql', 'array'); |
||
| 305 | Validators::assertField($config['dql'], 'string', 'array'); |
||
| 306 | Validators::assertField($config['dql'], 'numeric', 'array'); |
||
| 307 | Validators::assertField($config['dql'], 'datetime', 'array'); |
||
| 308 | Validators::assertField($config['dql'], 'hints', 'array'); |
||
| 309 | |||
| 310 | $autoGenerateProxyClasses = is_bool($config['autoGenerateProxyClasses']) |
||
| 311 | ? ($config['autoGenerateProxyClasses'] ? AbstractProxyFactory::AUTOGENERATE_ALWAYS : AbstractProxyFactory::AUTOGENERATE_NEVER) |
||
| 312 | : $config['autoGenerateProxyClasses']; |
||
| 313 | |||
| 314 | $configuration = $builder->addDefinition($this->prefix($name . '.ormConfiguration')) |
||
| 315 | ->setClass('Kdyby\Doctrine\Configuration') |
||
| 316 | ->addSetup('setMetadataCacheImpl', [$this->processCache($config['metadataCache'], $name . '.metadata')]) |
||
| 317 | ->addSetup('setQueryCacheImpl', [$this->processCache($config['queryCache'], $name . '.query')]) |
||
| 318 | ->addSetup('setResultCacheImpl', [$this->processCache($config['resultCache'], $name . '.ormResult')]) |
||
| 319 | ->addSetup('setHydrationCacheImpl', [$this->processCache($config['hydrationCache'], $name . '.hydration')]) |
||
| 320 | ->addSetup('setMetadataDriverImpl', [$this->prefix('@' . $name . '.metadataDriver')]) |
||
| 321 | ->addSetup('setClassMetadataFactoryName', [$config['classMetadataFactory']]) |
||
| 322 | ->addSetup('setDefaultRepositoryClassName', [$config['defaultRepositoryClassName']]) |
||
| 323 | ->addSetup('setQueryBuilderClassName', [$config['queryBuilderClassName']]) |
||
| 324 | ->addSetup('setRepositoryFactory', [$this->prefix('@' . $name . '.repositoryFactory')]) |
||
| 325 | ->addSetup('setProxyDir', [$config['proxyDir']]) |
||
| 326 | ->addSetup('setProxyNamespace', [$config['proxyNamespace']]) |
||
| 327 | ->addSetup('setAutoGenerateProxyClasses', [$autoGenerateProxyClasses]) |
||
| 328 | ->addSetup('setEntityNamespaces', [$config['namespaceAlias']]) |
||
| 329 | ->addSetup('setCustomHydrationModes', [$config['hydrators']]) |
||
| 330 | ->addSetup('setCustomStringFunctions', [$config['dql']['string']]) |
||
| 331 | ->addSetup('setCustomNumericFunctions', [$config['dql']['numeric']]) |
||
| 332 | ->addSetup('setCustomDatetimeFunctions', [$config['dql']['datetime']]) |
||
| 333 | ->addSetup('setDefaultQueryHints', [$config['dql']['hints']]) |
||
| 334 | ->addSetup('setNamingStrategy', CacheHelpers::filterArgs($config['namingStrategy'])) |
||
| 335 | ->addSetup('setQuoteStrategy', CacheHelpers::filterArgs($config['quoteStrategy'])) |
||
| 336 | ->addSetup('setEntityListenerResolver', CacheHelpers::filterArgs($config['entityListenerResolver'])) |
||
| 337 | ->setAutowired(FALSE) |
||
| 338 | ->setInject(FALSE); |
||
| 339 | /** @var Nette\DI\ServiceDefinition $configuration */ |
||
| 340 | |||
| 341 | $this->proxyAutoloaders[$config['proxyNamespace']] = $config['proxyDir']; |
||
| 342 | |||
| 343 | $this->processSecondLevelCache($name, $config['secondLevelCache'], $isDefault); |
||
| 344 | |||
| 345 | Validators::assertField($config, 'filters', 'array'); |
||
| 346 | foreach ($config['filters'] as $filterName => $filterClass) { |
||
| 347 | $configuration->addSetup('addFilter', [$filterName, $filterClass]); |
||
| 348 | } |
||
| 349 | |||
| 350 | if ($config['targetEntityMappings']) { |
||
| 351 | $configuration->addSetup('setTargetEntityMap', [array_map(function ($mapping) { |
||
| 352 | return $mapping['targetEntity']; |
||
| 353 | }, $config['targetEntityMappings'])]); |
||
| 354 | $this->targetEntityMappings = Nette\Utils\Arrays::mergeTree($this->targetEntityMappings, $config['targetEntityMappings']); |
||
| 355 | } |
||
| 356 | |||
| 357 | $entityManagerArguments = [ |
||
| 358 | $connectionService = $this->processConnection($name, $defaults, $isDefault), |
||
| 359 | $this->prefix('@' . $name . '.ormConfiguration'), |
||
| 360 | ]; |
||
| 361 | |||
| 362 | if (class_exists('Kdyby\Events\NamespacedEventManager')) { |
||
| 363 | $builder->addDefinition($this->prefix($name . '.evm')) |
||
| 364 | ->setClass('Kdyby\Events\NamespacedEventManager', [Kdyby\Doctrine\Events::NS . '::']) |
||
| 365 | ->addSetup('$dispatchGlobalEvents', [TRUE]) // for BC |
||
| 366 | ->setAutowired(FALSE); |
||
| 367 | |||
| 368 | $entityManagerArguments[] = $this->prefix('@' . $name . '.evm'); |
||
| 369 | } |
||
| 370 | |||
| 371 | // entity manager |
||
| 372 | $entityManager = $builder->addDefinition($managerServiceId = $this->prefix($name . '.entityManager')) |
||
| 373 | ->setClass('Kdyby\Doctrine\EntityManager') |
||
| 374 | ->setFactory('Kdyby\Doctrine\EntityManager::create', $entityManagerArguments) |
||
| 375 | ->addTag(self::TAG_ENTITY_MANAGER) |
||
| 376 | ->addTag('kdyby.doctrine.entityManager') |
||
| 377 | ->setAutowired($isDefault) |
||
| 378 | ->setInject(FALSE); |
||
| 379 | |||
| 380 | if ($this->isTracyPresent()) { |
||
| 381 | $entityManager->addSetup('?->bindEntityManager(?)', [$this->prefix('@' . $name . '.diagnosticsPanel'), '@self']); |
||
| 382 | } |
||
| 383 | |||
| 384 | $builder->addDefinition($this->prefix('repositoryFactory.' . $name . '.defaultRepositoryFactory')) |
||
| 385 | ->setClass($config['defaultRepositoryClassName']) |
||
| 386 | ->setImplement('Kdyby\Doctrine\DI\IRepositoryFactory') |
||
| 387 | ->setArguments([new Code\PhpLiteral('$entityManager'), new Code\PhpLiteral('$classMetadata')]) |
||
| 388 | ->setParameters(['Doctrine\ORM\EntityManagerInterface entityManager', 'Doctrine\ORM\Mapping\ClassMetadata classMetadata']) |
||
| 389 | ->setAutowired(FALSE); |
||
| 390 | |||
| 391 | $builder->addDefinition($this->prefix($name . '.schemaValidator')) |
||
| 392 | ->setClass('Doctrine\ORM\Tools\SchemaValidator', ['@' . $managerServiceId]) |
||
| 393 | ->setAutowired($isDefault); |
||
| 394 | |||
| 395 | $builder->addDefinition($this->prefix($name . '.schemaTool')) |
||
| 396 | ->setClass('Doctrine\ORM\Tools\SchemaTool', ['@' . $managerServiceId]) |
||
| 397 | ->setAutowired($isDefault); |
||
| 398 | |||
| 399 | $cacheCleaner = $builder->addDefinition($this->prefix($name . '.cacheCleaner')) |
||
| 400 | ->setClass('Kdyby\Doctrine\Tools\CacheCleaner', ['@' . $managerServiceId]) |
||
| 401 | ->setAutowired($isDefault); |
||
| 402 | |||
| 403 | $builder->addDefinition($this->prefix($name . '.schemaManager')) |
||
| 404 | ->setClass('Doctrine\DBAL\Schema\AbstractSchemaManager') |
||
| 405 | ->setFactory('@Kdyby\Doctrine\Connection::getSchemaManager') |
||
| 406 | ->setAutowired($isDefault); |
||
| 407 | |||
| 408 | foreach ($this->compiler->getExtensions('Kdyby\Annotations\DI\AnnotationsExtension') as $extension) { |
||
| 409 | /** @var Kdyby\Annotations\DI\AnnotationsExtension $extension */ |
||
| 410 | $cacheCleaner->addSetup('addCacheStorage', [$extension->prefix('@cache.annotations')]); |
||
| 411 | } |
||
| 412 | |||
| 413 | if ($isDefault) { |
||
| 414 | $builder->addDefinition($this->prefix('helper.entityManager')) |
||
| 415 | ->setClass('Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper', ['@' . $managerServiceId]) |
||
| 416 | ->addTag(Kdyby\Console\DI\ConsoleExtension::HELPER_TAG, 'em'); |
||
| 417 | |||
| 418 | $builder->addDefinition($this->prefix('helper.connection')) |
||
| 419 | ->setClass('Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper', [$connectionService]) |
||
| 420 | ->addTag(Kdyby\Console\DI\ConsoleExtension::HELPER_TAG, 'db'); |
||
| 421 | |||
| 422 | $builder->addAlias($this->prefix('schemaValidator'), $this->prefix($name . '.schemaValidator')); |
||
| 423 | $builder->addAlias($this->prefix('schemaTool'), $this->prefix($name . '.schemaTool')); |
||
| 424 | $builder->addAlias($this->prefix('cacheCleaner'), $this->prefix($name . '.cacheCleaner')); |
||
| 425 | $builder->addAlias($this->prefix('schemaManager'), $this->prefix($name . '.schemaManager')); |
||
| 426 | } |
||
| 427 | |||
| 428 | $this->configuredManagers[$name] = $managerServiceId; |
||
| 429 | $this->managerConfigs[$name] = $config; |
||
| 430 | } |
||
| 431 | |||
| 432 | |||
| 433 | |||
| 434 | protected function processSecondLevelCache($name, array $config, $isDefault) |
||
| 485 | |||
| 486 | |||
| 487 | |||
| 488 | protected function processConnection($name, array $defaults, $isDefault = FALSE) |
||
| 567 | |||
| 568 | |||
| 569 | |||
| 570 | /** |
||
| 571 | * @param \Nette\DI\ServiceDefinition $metadataDriver |
||
| 572 | * @param string $namespace |
||
| 573 | * @param string|object $driver |
||
| 574 | * @param string $prefix |
||
| 575 | * @throws \Nette\Utils\AssertionException |
||
| 576 | * @return string |
||
| 577 | */ |
||
| 578 | protected function processMetadataDriver(Nette\DI\ServiceDefinition $metadataDriver, $namespace, $driver, $prefix) |
||
| 631 | |||
| 632 | |||
| 633 | |||
| 634 | /** |
||
| 635 | * @param string|\stdClass $cache |
||
| 636 | * @param string $suffix |
||
| 637 | * @return string |
||
| 638 | */ |
||
| 639 | protected function processCache($cache, $suffix) |
||
| 643 | |||
| 644 | |||
| 645 | |||
| 646 | public function beforeCompile() |
||
| 727 | |||
| 728 | |||
| 729 | |||
| 730 | /** |
||
| 731 | * @param Nette\DI\ServiceDefinition $def |
||
| 732 | * @return string[] |
||
| 733 | */ |
||
| 734 | protected function getServiceBoundManagers(Nette\DI\ServiceDefinition $def) |
||
| 741 | |||
| 742 | |||
| 743 | |||
| 744 | public function afterCompile(Code\ClassType $class) |
||
| 761 | |||
| 762 | |||
| 763 | |||
| 764 | protected function processRepositoryFactoryEntities(Code\ClassType $class) |
||
| 802 | |||
| 803 | |||
| 804 | |||
| 805 | /** |
||
| 806 | * @param Code\ClassType $class |
||
| 807 | * @return Nette\DI\Container |
||
| 808 | */ |
||
| 809 | private static function evalAndInstantiateContainer(Code\ClassType $class) |
||
| 821 | |||
| 822 | |||
| 823 | |||
| 824 | /** |
||
| 825 | * @param $provided |
||
| 826 | * @param $defaults |
||
| 827 | * @param $diff |
||
| 828 | * @return array |
||
| 829 | */ |
||
| 830 | private function resolveConfig(array $provided, array $defaults, array $diff = []) |
||
| 837 | |||
| 838 | |||
| 839 | /** |
||
| 840 | * @param array $targetEntityMappings |
||
| 841 | * @return array |
||
| 842 | */ |
||
| 843 | private function normalizeTargetEntityMappings(array $targetEntityMappings) |
||
| 864 | |||
| 865 | |||
| 866 | |||
| 867 | /** |
||
| 868 | * @return bool |
||
| 869 | */ |
||
| 870 | private function isTracyPresent() |
||
| 874 | |||
| 875 | |||
| 876 | |||
| 877 | private function addCollapsePathsToTracy(Method $init) |
||
| 888 | |||
| 889 | |||
| 890 | |||
| 891 | /** |
||
| 892 | * @param \Nette\Configurator $configurator |
||
| 893 | */ |
||
| 894 | public static function register(Nette\Configurator $configurator) |
||
| 900 | |||
| 901 | |||
| 902 | |||
| 903 | /** |
||
| 904 | * @param array $array |
||
| 905 | */ |
||
| 906 | private static function natSortKeys(array &$array) |
||
| 914 | |||
| 915 | } |
||
| 916 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.