getManagerForClass() public method

public getManagerForClass ( $class )
 /**
  * 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;
 }
 /**
  * Specific annotation evaluation.
  *
  * @param Request          $request    Request
  * @param Annotation       $annotation Annotation
  * @param ReflectionMethod $method     Method
  *
  * @return EntityAnnotationResolver self Object
  *
  * @throws EntityNotFoundException
  */
 public function evaluateAnnotation(Request $request, Annotation $annotation, ReflectionMethod $method)
 {
     /**
      * Annotation is only laoded if is typeof AnnotationEntity
      */
     if ($annotation instanceof AnnotationObjectManager) {
         /**
          * Creating new instance of desired entity
          */
         $entity = $this->entityProvider->provide($annotation->getClass());
         $objectManager = $this->doctrine->getManagerForClass(get_class($entity));
         /**
          * Get the parameter name. If not defined, is set as defined in
          * parameters
          */
         $parameterName = $annotation->getName() ?: $this->defaultName;
         $request->attributes->set($parameterName, $objectManager);
     }
     return $this;
 }
 /**
  * Generate QueryBuilder
  *
  * @param Object $entity Entity instance
  *
  * @return QueryBuilder Query builder
  */
 public function createQueryBuilder($entity)
 {
     $entityNamespace = get_class($entity);
     return $this->doctrine->getManagerForClass(get_class($entity))->createQueryBuilder()->select(array('x'))->from($entityNamespace, 'x');
 }
Beispiel #4
0
 /**
  * Given an entity namespace, return associated object Manager.
  *
  * @param string $entityNamespace Entity Namespace
  *
  * @return ObjectManager|null Object manager
  */
 public function getManagerByEntityNamespace($entityNamespace)
 {
     return $this->manager->getManagerForClass($entityNamespace);
 }