Doctrine\Common\Persistence\AbstractManagerRegistry::getManagerForClass PHP Method

getManagerForClass() public method

public getManagerForClass ( $class )
    public function getManagerForClass($class)
    {
        // Check for namespace alias
        if (strpos($class, ':') !== false) {
            list($namespaceAlias, $simpleClassName) = explode(':', $class, 2);
            $class = $this->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
        }
        $proxyClass = new \ReflectionClass($class);
        if ($proxyClass->implementsInterface($this->proxyInterfaceName)) {
            if (!($parentClass = $proxyClass->getParentClass())) {
                return null;
            }
            $class = $parentClass->getName();
        }
        foreach ($this->managers as $id) {
            $manager = $this->getService($id);
            if (!$manager->getMetadataFactory()->isTransient($class)) {
                return $manager;
            }
        }
    }

Usage Example

 /**
  * Persist block
  *
  * This block defines if entity must be persisted using desired
  * manager.
  *
  * This manager is defined as default in bundle parameters, but can
  * be overwritten in each annotation
  *
  * Same logic in perisist option. This variable is defined in bundle
  * parameters and can be overwritten there. Can also be defined in
  * every single annotation
  *
  * @param AnnotationEntity $annotation Annotation
  * @param Object           $entity     Entity
  *
  * @return EntityAnnotationResolver self Object
  */
 protected function resolvePersist(AnnotationEntity $annotation, $entity)
 {
     /**
      * Persist block
      *
      * This block defines if entity must be persisted using desired
      * manager.
      *
      * Given the entity we can find which manager manages it
      *
      * Same logic in perisist option. This variable is defined in bundle
      * parameters and can be overwritten there. Can also be defined in
      * every single annotation
      */
     /**
      * Get the persist variable. If not defined, is set as defined in
      * parameters
      */
     $persist = !is_null($annotation->getPersist()) ? $annotation->getPersist() : $this->defaultPersist;
     if ($persist) {
         /**
          * Loading locally desired Doctrine manager
          */
         $this->doctrine->getManagerForClass(get_class($entity))->persist($entity);
     }
     return $this;
 }
All Usage Examples Of Doctrine\Common\Persistence\AbstractManagerRegistry::getManagerForClass