Complex classes like EntityManager 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 EntityManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 62 | /* final */class EntityManager implements EntityManagerInterface |
||
| 63 | { |
||
| 64 | /** |
||
| 65 | * The used Configuration. |
||
| 66 | * |
||
| 67 | * @var \Doctrine\ORM\Configuration |
||
| 68 | */ |
||
| 69 | private $config; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The database connection used by the EntityManager. |
||
| 73 | * |
||
| 74 | * @var \Doctrine\DBAL\Connection |
||
| 75 | */ |
||
| 76 | private $conn; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The metadata factory, used to retrieve the ORM metadata of entity classes. |
||
| 80 | * |
||
| 81 | * @var \Doctrine\ORM\Mapping\ClassMetadataFactory |
||
| 82 | */ |
||
| 83 | private $metadataFactory; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The UnitOfWork used to coordinate object-level transactions. |
||
| 87 | * |
||
| 88 | * @var \Doctrine\ORM\UnitOfWork |
||
| 89 | */ |
||
| 90 | private $unitOfWork; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * The event manager that is the central point of the event system. |
||
| 94 | * |
||
| 95 | * @var \Doctrine\Common\EventManager |
||
| 96 | */ |
||
| 97 | private $eventManager; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The proxy factory used to create dynamic proxies. |
||
| 101 | * |
||
| 102 | * @var \Doctrine\ORM\Proxy\ProxyFactory |
||
| 103 | */ |
||
| 104 | private $proxyFactory; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * The repository factory used to create dynamic repositories. |
||
| 108 | * |
||
| 109 | * @var \Doctrine\ORM\Repository\RepositoryFactory |
||
| 110 | */ |
||
| 111 | private $repositoryFactory; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The expression builder instance used to generate query expressions. |
||
| 115 | * |
||
| 116 | * @var \Doctrine\ORM\Query\Expr |
||
| 117 | */ |
||
| 118 | private $expressionBuilder; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Whether the EntityManager is closed or not. |
||
| 122 | * |
||
| 123 | * @var bool |
||
| 124 | */ |
||
| 125 | private $closed = false; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Collection of query filters. |
||
| 129 | * |
||
| 130 | * @var \Doctrine\ORM\Query\FilterCollection |
||
| 131 | */ |
||
| 132 | private $filterCollection; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @var \Doctrine\ORM\Cache The second level cache regions API. |
||
| 136 | */ |
||
| 137 | private $cache; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Creates a new EntityManager that operates on the given database connection |
||
| 141 | * and uses the given Configuration and EventManager implementations. |
||
| 142 | * |
||
| 143 | * @param \Doctrine\DBAL\Connection $conn |
||
| 144 | * @param \Doctrine\ORM\Configuration $config |
||
| 145 | * @param \Doctrine\Common\EventManager $eventManager |
||
| 146 | */ |
||
| 147 | 2323 | protected function __construct(Connection $conn, Configuration $config, EventManager $eventManager) |
|
| 148 | { |
||
| 149 | 2323 | $this->conn = $conn; |
|
| 150 | 2323 | $this->config = $config; |
|
| 151 | 2323 | $this->eventManager = $eventManager; |
|
| 152 | |||
| 153 | 2323 | $metadataFactoryClassName = $config->getClassMetadataFactoryName(); |
|
| 154 | |||
| 155 | 2323 | $this->metadataFactory = new $metadataFactoryClassName; |
|
| 156 | 2323 | $this->metadataFactory->setEntityManager($this); |
|
| 157 | 2323 | $this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl()); |
|
| 158 | |||
| 159 | 2323 | $this->repositoryFactory = $config->getRepositoryFactory(); |
|
| 160 | 2323 | $this->unitOfWork = new UnitOfWork($this); |
|
| 161 | 2323 | $this->proxyFactory = new ProxyFactory( |
|
| 162 | $this, |
||
| 163 | 2323 | $config->getProxyDir(), |
|
| 164 | 2323 | $config->getProxyNamespace(), |
|
| 165 | 2323 | $config->getAutoGenerateProxyClasses() |
|
| 166 | ); |
||
| 167 | |||
| 168 | 2323 | if ($config->isSecondLevelCacheEnabled()) { |
|
| 169 | 275 | $cacheConfig = $config->getSecondLevelCacheConfiguration(); |
|
| 170 | 275 | $cacheFactory = $cacheConfig->getCacheFactory(); |
|
| 171 | 275 | $this->cache = $cacheFactory->createCache($this); |
|
| 172 | } |
||
| 173 | 2323 | } |
|
| 174 | |||
| 175 | /** |
||
| 176 | * {@inheritDoc} |
||
| 177 | */ |
||
| 178 | 1827 | public function getConnection() |
|
| 182 | |||
| 183 | /** |
||
| 184 | * Gets the metadata factory used to gather the metadata of classes. |
||
| 185 | * |
||
| 186 | * @return \Doctrine\ORM\Mapping\ClassMetadataFactory |
||
| 187 | */ |
||
| 188 | 2323 | public function getMetadataFactory() |
|
| 192 | |||
| 193 | /** |
||
| 194 | * {@inheritDoc} |
||
| 195 | */ |
||
| 196 | 17 | public function getExpressionBuilder() |
|
| 197 | { |
||
| 198 | 17 | if ($this->expressionBuilder === null) { |
|
| 199 | 17 | $this->expressionBuilder = new Query\Expr; |
|
| 200 | } |
||
| 201 | |||
| 202 | 17 | return $this->expressionBuilder; |
|
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * {@inheritDoc} |
||
| 207 | */ |
||
| 208 | 2 | public function beginTransaction() |
|
| 212 | |||
| 213 | /** |
||
| 214 | * {@inheritDoc} |
||
| 215 | */ |
||
| 216 | 210 | public function getCache() |
|
| 220 | |||
| 221 | /** |
||
| 222 | * {@inheritDoc} |
||
| 223 | */ |
||
| 224 | 4 | public function transactional($func) |
|
| 225 | { |
||
| 226 | 4 | if (!is_callable($func)) { |
|
| 227 | 1 | throw new \InvalidArgumentException('Expected argument of type "callable", got "' . gettype($func) . '"'); |
|
| 228 | } |
||
| 229 | |||
| 230 | 3 | $this->conn->beginTransaction(); |
|
| 231 | |||
| 232 | try { |
||
| 233 | 3 | $return = call_user_func($func, $this); |
|
| 234 | |||
| 235 | 3 | $this->flush(); |
|
| 236 | 3 | $this->conn->commit(); |
|
| 237 | |||
| 238 | 3 | return $return ?: true; |
|
| 239 | } catch (Exception $e) { |
||
| 240 | $this->close(); |
||
| 241 | $this->conn->rollBack(); |
||
| 242 | |||
| 243 | throw $e; |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * {@inheritDoc} |
||
| 249 | */ |
||
| 250 | 1 | public function commit() |
|
| 254 | |||
| 255 | /** |
||
| 256 | * {@inheritDoc} |
||
| 257 | */ |
||
| 258 | 1 | public function rollback() |
|
| 262 | |||
| 263 | /** |
||
| 264 | * Returns the ORM metadata descriptor for a class. |
||
| 265 | * |
||
| 266 | * The class name must be the fully-qualified class name without a leading backslash |
||
| 267 | * (as it is returned by get_class($obj)) or an aliased class name. |
||
| 268 | * |
||
| 269 | * Examples: |
||
| 270 | * MyProject\Domain\User |
||
| 271 | * sales:PriceRequest |
||
| 272 | * |
||
| 273 | * Internal note: Performance-sensitive method. |
||
| 274 | * |
||
| 275 | * @param string $className |
||
| 276 | * |
||
| 277 | * @return \Doctrine\ORM\Mapping\ClassMetadata |
||
| 278 | */ |
||
| 279 | 1880 | public function getClassMetadata($className) |
|
| 283 | |||
| 284 | /** |
||
| 285 | * {@inheritDoc} |
||
| 286 | */ |
||
| 287 | 922 | public function createQuery($dql = '') |
|
| 288 | { |
||
| 289 | 922 | $query = new Query($this); |
|
| 290 | |||
| 291 | 922 | if ( ! empty($dql)) { |
|
| 292 | 917 | $query->setDql($dql); |
|
| 293 | } |
||
| 294 | |||
| 295 | 922 | return $query; |
|
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * {@inheritDoc} |
||
| 300 | */ |
||
| 301 | 1 | public function createNamedQuery($name) |
|
| 305 | |||
| 306 | /** |
||
| 307 | * {@inheritDoc} |
||
| 308 | */ |
||
| 309 | 21 | public function createNativeQuery($sql, ResultSetMapping $rsm) |
|
| 310 | { |
||
| 311 | 21 | $query = new NativeQuery($this); |
|
| 312 | |||
| 313 | 21 | $query->setSql($sql); |
|
| 314 | 21 | $query->setResultSetMapping($rsm); |
|
| 315 | |||
| 316 | 21 | return $query; |
|
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * {@inheritDoc} |
||
| 321 | */ |
||
| 322 | 1 | public function createNamedNativeQuery($name) |
|
| 323 | { |
||
| 324 | 1 | list($sql, $rsm) = $this->config->getNamedNativeQuery($name); |
|
| 325 | |||
| 326 | 1 | return $this->createNativeQuery($sql, $rsm); |
|
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * {@inheritDoc} |
||
| 331 | */ |
||
| 332 | 112 | public function createQueryBuilder() |
|
| 336 | |||
| 337 | /** |
||
| 338 | * Flushes all changes to objects that have been queued up to now to the database. |
||
| 339 | * This effectively synchronizes the in-memory state of managed objects with the |
||
| 340 | * database. |
||
| 341 | * |
||
| 342 | * If an entity is explicitly passed to this method only this entity and |
||
| 343 | * the cascade-persist semantics + scheduled inserts/removals are synchronized. |
||
| 344 | * |
||
| 345 | * @param null|object|array $entity |
||
| 346 | * |
||
| 347 | * @return void |
||
| 348 | * |
||
| 349 | * @throws \Doctrine\ORM\OptimisticLockException If a version check on an entity that |
||
| 350 | * makes use of optimistic locking fails. |
||
| 351 | * @throws ORMException |
||
| 352 | */ |
||
| 353 | 1009 | public function flush($entity = null) |
|
| 354 | { |
||
| 355 | 1009 | $this->errorIfClosed(); |
|
| 356 | |||
| 357 | 1008 | $this->unitOfWork->commit($entity); |
|
| 358 | 999 | } |
|
| 359 | |||
| 360 | /** |
||
| 361 | * Finds an Entity by its identifier. |
||
| 362 | * |
||
| 363 | * @param string $entityName The class name of the entity to find. |
||
| 364 | * @param mixed $id The identity of the entity to find. |
||
| 365 | * @param integer|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants |
||
| 366 | * or NULL if no specific lock mode should be used |
||
| 367 | * during the search. |
||
| 368 | * @param integer|null $lockVersion The version of the entity to find when using |
||
| 369 | * optimistic locking. |
||
| 370 | * |
||
| 371 | * @return object|null The entity instance or NULL if the entity can not be found. |
||
| 372 | * |
||
| 373 | * @throws OptimisticLockException |
||
| 374 | * @throws ORMInvalidArgumentException |
||
| 375 | * @throws TransactionRequiredException |
||
| 376 | * @throws ORMException |
||
| 377 | */ |
||
| 378 | 409 | public function find($entityName, $id, $lockMode = null, $lockVersion = null) |
|
| 379 | { |
||
| 380 | 409 | $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\')); |
|
| 381 | |||
| 382 | 409 | if ( ! is_array($id)) { |
|
| 383 | 365 | if ($class->isIdentifierComposite) { |
|
|
|
|||
| 384 | throw ORMInvalidArgumentException::invalidCompositeIdentifier(); |
||
| 385 | } |
||
| 386 | |||
| 387 | 365 | $id = array($class->identifier[0] => $id); |
|
| 388 | } |
||
| 389 | |||
| 390 | 409 | foreach ($id as $i => $value) { |
|
| 391 | 409 | if (is_object($value) && $this->metadataFactory->hasMetadataFor(ClassUtils::getClass($value))) { |
|
| 392 | 6 | $id[$i] = $this->unitOfWork->getSingleIdentifierValue($value); |
|
| 393 | |||
| 394 | 6 | if ($id[$i] === null) { |
|
| 395 | 409 | throw ORMInvalidArgumentException::invalidIdentifierBindingEntity(); |
|
| 396 | } |
||
| 397 | } |
||
| 398 | } |
||
| 399 | |||
| 400 | 408 | $sortedId = array(); |
|
| 401 | |||
| 402 | 408 | foreach ($class->identifier as $identifier) { |
|
| 403 | 408 | if ( ! isset($id[$identifier])) { |
|
| 404 | 1 | throw ORMException::missingIdentifierField($class->name, $identifier); |
|
| 405 | } |
||
| 406 | |||
| 407 | 407 | $sortedId[$identifier] = $id[$identifier]; |
|
| 408 | 407 | unset($id[$identifier]); |
|
| 409 | } |
||
| 410 | |||
| 411 | 407 | if ($id) { |
|
| 412 | 1 | throw ORMException::unrecognizedIdentifierFields($class->name, array_keys($id)); |
|
| 413 | } |
||
| 414 | |||
| 415 | 406 | $unitOfWork = $this->getUnitOfWork(); |
|
| 416 | |||
| 417 | // Check identity map first |
||
| 418 | 406 | if (($entity = $unitOfWork->tryGetById($sortedId, $class->rootEntityName)) !== false) { |
|
| 419 | 41 | if ( ! ($entity instanceof $class->name)) { |
|
| 420 | 1 | return null; |
|
| 421 | } |
||
| 422 | |||
| 423 | switch (true) { |
||
| 424 | 40 | case LockMode::OPTIMISTIC === $lockMode: |
|
| 425 | 1 | $this->lock($entity, $lockMode, $lockVersion); |
|
| 426 | break; |
||
| 427 | |||
| 428 | 40 | case LockMode::NONE === $lockMode: |
|
| 429 | 40 | case LockMode::PESSIMISTIC_READ === $lockMode: |
|
| 430 | 40 | case LockMode::PESSIMISTIC_WRITE === $lockMode: |
|
| 431 | $persister = $unitOfWork->getEntityPersister($class->name); |
||
| 432 | $persister->refresh($sortedId, $entity, $lockMode); |
||
| 433 | break; |
||
| 434 | } |
||
| 435 | |||
| 436 | 40 | return $entity; // Hit! |
|
| 437 | } |
||
| 438 | |||
| 439 | 391 | $persister = $unitOfWork->getEntityPersister($class->name); |
|
| 440 | |||
| 441 | switch (true) { |
||
| 442 | 391 | case LockMode::OPTIMISTIC === $lockMode: |
|
| 443 | 1 | if ( ! $class->isVersioned) { |
|
| 444 | 1 | throw OptimisticLockException::notVersioned($class->name); |
|
| 445 | } |
||
| 446 | |||
| 447 | $entity = $persister->load($sortedId); |
||
| 448 | |||
| 449 | $unitOfWork->lock($entity, $lockMode, $lockVersion); |
||
| 450 | |||
| 451 | return $entity; |
||
| 452 | |||
| 453 | 390 | case LockMode::PESSIMISTIC_READ === $lockMode: |
|
| 454 | 389 | case LockMode::PESSIMISTIC_WRITE === $lockMode: |
|
| 455 | 2 | if ( ! $this->getConnection()->isTransactionActive()) { |
|
| 456 | 2 | throw TransactionRequiredException::transactionRequired(); |
|
| 457 | } |
||
| 458 | return $persister->load($sortedId, null, null, array(), $lockMode); |
||
| 459 | |||
| 460 | 388 | case LockMode::NONE === $lockMode: |
|
| 461 | return $persister->load($sortedId, null, null, array(), $lockMode); |
||
| 462 | |||
| 463 | default: |
||
| 464 | 388 | return $persister->loadById($sortedId); |
|
| 465 | } |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * {@inheritDoc} |
||
| 470 | */ |
||
| 471 | 90 | public function getReference($entityName, $id) |
|
| 472 | { |
||
| 473 | 90 | $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\')); |
|
| 474 | |||
| 475 | 90 | if ( ! is_array($id)) { |
|
| 476 | 49 | $id = array($class->identifier[0] => $id); |
|
| 477 | } |
||
| 478 | |||
| 479 | 90 | $sortedId = array(); |
|
| 480 | |||
| 481 | 90 | foreach ($class->identifier as $identifier) { |
|
| 482 | 90 | if ( ! isset($id[$identifier])) { |
|
| 483 | throw ORMException::missingIdentifierField($class->name, $identifier); |
||
| 484 | } |
||
| 485 | |||
| 486 | 90 | $sortedId[$identifier] = $id[$identifier]; |
|
| 487 | 90 | unset($id[$identifier]); |
|
| 488 | } |
||
| 489 | |||
| 490 | 90 | if ($id) { |
|
| 491 | 1 | throw ORMException::unrecognizedIdentifierFields($class->name, array_keys($id)); |
|
| 492 | } |
||
| 493 | |||
| 494 | // Check identity map first, if its already in there just return it. |
||
| 495 | 89 | if (($entity = $this->unitOfWork->tryGetById($sortedId, $class->rootEntityName)) !== false) { |
|
| 496 | 26 | return ($entity instanceof $class->name) ? $entity : null; |
|
| 497 | } |
||
| 498 | |||
| 499 | 85 | if ($class->subClasses) { |
|
| 500 | 2 | return $this->find($entityName, $sortedId); |
|
| 501 | } |
||
| 502 | |||
| 503 | 85 | $entity = $this->proxyFactory->getProxy($class->name, $sortedId); |
|
| 504 | |||
| 505 | 85 | $this->unitOfWork->registerManaged($entity, $sortedId, array()); |
|
| 506 | |||
| 507 | 85 | return $entity; |
|
| 508 | } |
||
| 509 | |||
| 510 | /** |
||
| 511 | * {@inheritDoc} |
||
| 512 | */ |
||
| 513 | 4 | public function getPartialReference($entityName, $identifier) |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Clears the EntityManager. All entities that are currently managed |
||
| 538 | * by this EntityManager become detached. |
||
| 539 | * |
||
| 540 | * @param string|null $entityName if given, only entities of this type will get detached |
||
| 541 | * |
||
| 542 | * @return void |
||
| 543 | */ |
||
| 544 | 1215 | public function clear($entityName = null) |
|
| 548 | |||
| 549 | /** |
||
| 550 | * {@inheritDoc} |
||
| 551 | */ |
||
| 552 | 19 | public function close() |
|
| 558 | |||
| 559 | /** |
||
| 560 | * Tells the EntityManager to make an instance managed and persistent. |
||
| 561 | * |
||
| 562 | * The entity will be entered into the database at or before transaction |
||
| 563 | * commit or as a result of the flush operation. |
||
| 564 | * |
||
| 565 | * NOTE: The persist operation always considers entities that are not yet known to |
||
| 566 | * this EntityManager as NEW. Do not pass detached entities to the persist operation. |
||
| 567 | * |
||
| 568 | * @param object $entity The instance to make managed and persistent. |
||
| 569 | * |
||
| 570 | * @return void |
||
| 571 | * |
||
| 572 | * @throws ORMInvalidArgumentException |
||
| 573 | * @throws ORMException |
||
| 574 | */ |
||
| 575 | 1003 | public function persist($entity) |
|
| 585 | |||
| 586 | /** |
||
| 587 | * Removes an entity instance. |
||
| 588 | * |
||
| 589 | * A removed entity will be removed from the database at or before transaction commit |
||
| 590 | * or as a result of the flush operation. |
||
| 591 | * |
||
| 592 | * @param object $entity The entity instance to remove. |
||
| 593 | * |
||
| 594 | * @return void |
||
| 595 | * |
||
| 596 | * @throws ORMInvalidArgumentException |
||
| 597 | * @throws ORMException |
||
| 598 | */ |
||
| 599 | 51 | public function remove($entity) |
|
| 609 | |||
| 610 | /** |
||
| 611 | * Refreshes the persistent state of an entity from the database, |
||
| 612 | * overriding any local changes that have not yet been persisted. |
||
| 613 | * |
||
| 614 | * @param object $entity The entity to refresh. |
||
| 615 | * |
||
| 616 | * @return void |
||
| 617 | * |
||
| 618 | * @throws ORMInvalidArgumentException |
||
| 619 | * @throws ORMException |
||
| 620 | */ |
||
| 621 | 19 | public function refresh($entity) |
|
| 631 | |||
| 632 | /** |
||
| 633 | * Detaches an entity from the EntityManager, causing a managed entity to |
||
| 634 | * become detached. Unflushed changes made to the entity if any |
||
| 635 | * (including removal of the entity), will not be synchronized to the database. |
||
| 636 | * Entities which previously referenced the detached entity will continue to |
||
| 637 | * reference it. |
||
| 638 | * |
||
| 639 | * @param object $entity The entity to detach. |
||
| 640 | * |
||
| 641 | * @return void |
||
| 642 | * |
||
| 643 | * @throws ORMInvalidArgumentException |
||
| 644 | */ |
||
| 645 | 13 | public function detach($entity) |
|
| 653 | |||
| 654 | /** |
||
| 655 | * Merges the state of a detached entity into the persistence context |
||
| 656 | * of this EntityManager and returns the managed copy of the entity. |
||
| 657 | * The entity passed to merge will not become associated/managed with this EntityManager. |
||
| 658 | * |
||
| 659 | * @param object $entity The detached entity to merge into the persistence context. |
||
| 660 | * |
||
| 661 | * @return object The managed copy of the entity. |
||
| 662 | * |
||
| 663 | * @throws ORMInvalidArgumentException |
||
| 664 | * @throws ORMException |
||
| 665 | */ |
||
| 666 | 42 | public function merge($entity) |
|
| 676 | |||
| 677 | /** |
||
| 678 | * {@inheritDoc} |
||
| 679 | * |
||
| 680 | * @todo Implementation need. This is necessary since $e2 = clone $e1; throws an E_FATAL when access anything on $e: |
||
| 681 | * Fatal error: Maximum function nesting level of '100' reached, aborting! |
||
| 682 | */ |
||
| 683 | public function copy($entity, $deep = false) |
||
| 687 | |||
| 688 | /** |
||
| 689 | * {@inheritDoc} |
||
| 690 | */ |
||
| 691 | 10 | public function lock($entity, $lockMode, $lockVersion = null) |
|
| 695 | |||
| 696 | /** |
||
| 697 | * Gets the repository for an entity class. |
||
| 698 | * |
||
| 699 | * @param string $entityName The name of the entity. |
||
| 700 | * |
||
| 701 | * @return \Doctrine\ORM\EntityRepository The repository class. |
||
| 702 | */ |
||
| 703 | 144 | public function getRepository($entityName) |
|
| 707 | |||
| 708 | /** |
||
| 709 | * Determines whether an entity instance is managed in this EntityManager. |
||
| 710 | * |
||
| 711 | * @param object $entity |
||
| 712 | * |
||
| 713 | * @return boolean TRUE if this EntityManager currently manages the given entity, FALSE otherwise. |
||
| 714 | */ |
||
| 715 | 22 | public function contains($entity) |
|
| 721 | |||
| 722 | /** |
||
| 723 | * {@inheritDoc} |
||
| 724 | */ |
||
| 725 | 2323 | public function getEventManager() |
|
| 729 | |||
| 730 | /** |
||
| 731 | * {@inheritDoc} |
||
| 732 | */ |
||
| 733 | 2323 | public function getConfiguration() |
|
| 737 | |||
| 738 | /** |
||
| 739 | * Throws an exception if the EntityManager is closed or currently not active. |
||
| 740 | * |
||
| 741 | * @return void |
||
| 742 | * |
||
| 743 | * @throws ORMException If the EntityManager is closed. |
||
| 744 | */ |
||
| 745 | 1022 | private function errorIfClosed() |
|
| 751 | |||
| 752 | /** |
||
| 753 | * {@inheritDoc} |
||
| 754 | */ |
||
| 755 | 1 | public function isOpen() |
|
| 759 | |||
| 760 | /** |
||
| 761 | * {@inheritDoc} |
||
| 762 | */ |
||
| 763 | 2323 | public function getUnitOfWork() |
|
| 767 | |||
| 768 | /** |
||
| 769 | * {@inheritDoc} |
||
| 770 | */ |
||
| 771 | public function getHydrator($hydrationMode) |
||
| 775 | |||
| 776 | /** |
||
| 777 | * {@inheritDoc} |
||
| 778 | */ |
||
| 779 | 881 | public function newHydrator($hydrationMode) |
|
| 805 | |||
| 806 | /** |
||
| 807 | * {@inheritDoc} |
||
| 808 | */ |
||
| 809 | 165 | public function getProxyFactory() |
|
| 813 | |||
| 814 | /** |
||
| 815 | * {@inheritDoc} |
||
| 816 | */ |
||
| 817 | public function initializeObject($obj) |
||
| 821 | |||
| 822 | /** |
||
| 823 | * Factory method to create EntityManager instances. |
||
| 824 | * |
||
| 825 | * @param mixed $conn An array with the connection parameters or an existing Connection instance. |
||
| 826 | * @param Configuration $config The Configuration instance to use. |
||
| 827 | * @param EventManager $eventManager The EventManager instance to use. |
||
| 828 | * |
||
| 829 | * @return EntityManager The created EntityManager. |
||
| 830 | * |
||
| 831 | * @throws \InvalidArgumentException |
||
| 832 | * @throws ORMException |
||
| 833 | */ |
||
| 834 | 1227 | public static function create($conn, Configuration $config, EventManager $eventManager = null) |
|
| 859 | |||
| 860 | /** |
||
| 861 | * {@inheritDoc} |
||
| 862 | */ |
||
| 863 | 604 | public function getFilters() |
|
| 871 | |||
| 872 | /** |
||
| 873 | * {@inheritDoc} |
||
| 874 | */ |
||
| 875 | 35 | public function isFiltersStateClean() |
|
| 879 | |||
| 880 | /** |
||
| 881 | * {@inheritDoc} |
||
| 882 | */ |
||
| 883 | 733 | public function hasFilters() |
|
| 887 | } |
||
| 888 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: