getClassName() public method

Returns the class name of the object managed by the repository.
public getClassName ( ) : string
return string
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (!$value) {
         return null;
     }
     if (null === ($entity = $this->repository->findOneBy(array($this->identifier => $value)))) {
         throw new TransformationFailedException(sprintf('Object "%s" with identifier "%s"="%s" does not exist.', $this->repository->getClassName(), $this->identifier, $value));
     }
     return $entity;
 }
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (null === $value) {
         return '';
     }
     $class = $this->repository->getClassName();
     if (!$value instanceof $class) {
         throw new UnexpectedTypeException($value, $class);
     }
     $accessor = PropertyAccess::createPropertyAccessor();
     return $accessor->getValue($value, $this->identifier);
 }
 public function createUserIdentity($user)
 {
     list($className, $identifier) = $this->extractUserIdentityFields($user);
     if (isset($this->userCache[$className][$identifier])) {
         return $this->userCache[$className][$identifier];
     }
     if (null !== ($this->userCache[$className][$identifier] = $this->userRepository->findOneBy(array('class' => $className, 'identifier' => $identifier)))) {
         return $this->userCache[$className][$identifier];
     }
     $userClass = $this->userRepository->getClassName();
     return $this->userCache[$className][$identifier] = new $userClass($className, $identifier);
 }
 /**
  * Inserts a new ACE
  *
  * This method is idempotent.
  */
 public function createAce($grantee, $target, $permission, $flush = true)
 {
     $grantee = $this->extractSecurityIdentity($grantee);
     $target = $this->extractTargetIdentity($target);
     if (!isset($this->writeCache[$grantee])) {
         $this->writeCache[$grantee] = new \SplObjectStorage();
     }
     if (!isset($this->writeCache[$grantee][$target])) {
         // Permissions are strings, no need for an SplObjectStorage.
         $this->writeCache[$grantee][$target] = array();
     }
     $ace = null;
     if (isset($this->writeCache[$grantee][$target][$permission])) {
         $ace = $this->writeCache[$grantee][$target][$permission];
     } else {
         if (null !== $target->getId() && (null !== $grantee->getId() || SecurityIdentity::KIND_ANONYMOUS === $grantee->getKind())) {
             // Both the target is persisted and the grantee is either
             // persisted or anonymous. Let's see what the database has to
             // say regarding this ACE.
             $ace = $this->repository->findOneBy(array('grantee' => $this->generateCriteriaValue($grantee->getId()), 'target' => $this->generateCriteriaValue($target->getId()), 'permission' => $this->generateCriteriaValue($permission)));
         }
         if (null === $ace) {
             $aceClass = $this->repository->getClassName();
             $ace = $this->writeCache[$grantee][$target][$permission] = new $class($grantee, $target, $permission);
             $this->om->persist($ace);
         }
     }
     if ($flush) {
         $this->om->flush();
     }
     return $ace;
 }
 /**
  * Get reflection of entity class
  * 
  * @return \ReflectionClass
  */
 protected function getClassReflection()
 {
     if ($this->reflection === null) {
         $class = $this->repository->getClassName();
         $this->reflection = new \ReflectionClass($class);
     }
     return $this->reflection;
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function create(Utils\ArrayHash $values, Entities\IEntity $entity = NULL)
 {
     if (!$entity instanceof Entities\IEntity) {
         $entityName = $this->entityRepository->getClassName();
         $entity = $this->managerRegistry->getManagerForClass($entityName)->getClassMetadata($entityName)->newInstance();
     }
     if (!$entity || !$entity instanceof Entities\IEntity) {
         throw new Exceptions\InvalidArgumentException('Entity could not be created.');
     }
     $this->processHooks($this->beforeCreate, [$entity, $values]);
     $this->entityMapper->fillEntity($values, $entity, TRUE);
     $entityManager = $this->managerRegistry->getManagerForClass(get_class($entity));
     $entityManager->persist($entity);
     $this->processHooks($this->afterCreate, [$entity, $values]);
     if ($this->getFlush() === TRUE) {
         $entityManager->flush();
     }
     return $entity;
 }
 public function createObjectFieldIdentity($object, $fieldName)
 {
     list($className, $identifier) = $this->extractObjectIdentityFields($object);
     if (isset($this->objectFieldCache[$className][$identifier][$fieldName])) {
         return $this->objectFieldCache[$className][$identifier][$fieldName];
     }
     if (null !== $object->getId() && null !== ($this->objectFieldCache[$className][$identifier][$fieldName] = $this->objectFieldRepository->findOneBy(array('object' => $object->getId(), 'fieldName' => $fieldName)))) {
         return $this->objectFieldCache[$className][$identifier][$fieldName];
     }
     $objectFieldClass = $this->objectFieldRepository->getClassName();
     return $this->objectFieldCache[$className][$identifier][$fieldName] = new $objectFieldClass($object, $fieldName, $this->createClassFieldIdentity($object->getClassName(), $field));
 }
 function it_should_create_entity(ManagerRegistry $registry, EntityManager $em, ClassFactory $factory, ObjectRepository $repository, ClassMetadataInfo $class)
 {
     $entity = (object) ['foo' => null, 'bar' => null];
     $class->getFieldNames()->willReturn(['id', 'foo', 'bar']);
     $class->setFieldValue($entity, 'id', null)->shouldBeCalled();
     $class->setFieldValue($entity, 'foo', 1)->shouldBeCalled();
     $class->setFieldValue($entity, 'bar', 2)->shouldBeCalled();
     $class->getAssociationNames()->willReturn([]);
     $repository->getClassName()->willReturn('foo');
     $factory->create('foo')->willReturn($entity);
     $em->getRepository('foo')->willReturn($repository);
     $em->getClassMetadata('foo')->willReturn($class);
     $em->persist($entity)->shouldBeCalled();
     $em->flush()->shouldBeCalled();
     $registry->getManager(null)->willReturn($em);
     $this->setRegistry($registry);
     $this->setClassFactory($factory);
     $entity->foo = 1;
     $entity->bar = 2;
     $this->create(['foo' => 1, 'bar' => 2])->shouldBe($entity);
 }
 function let(ObjectRepository $repository)
 {
     $repository->getClassName()->willReturn('spec\\Sylius\\Bundle\\ResourceBundle\\Form\\DataTransformer\\FakeEntity');
     $this->beConstructedWith($repository, 'id');
 }
 public function __construct(ObjectRepository $repository)
 {
     $this->repository = $repository;
     $this->class = $repository->getClassName();
 }
示例#11
0
 /**
  * @param OptionsResolver $resolver
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     // We do not check if method exists because you may want to call a magic method
     $methodName = $this->methodName;
     $resolver->setDefaults(['choices' => call_user_func([$this->repository, $methodName]), 'class' => $this->repository->getClassName()]);
 }
 /**
  * @param string $class
  *
  * @return bool
  */
 public function supportsClass($class)
 {
     return $this->userRepository->getClassName() === $class || is_subclass_of($class, $this->userRepository->getClassName());
 }
 public function __construct(ObjectRepository $repository)
 {
     $this->repository = $repository;
     parent::__construct($repository->getClassName());
 }
 public function __construct(ObjectManager $em, ObjectRepository $repository)
 {
     $this->em = $em;
     $this->repository = $repository;
     $this->reflClass = new \ReflectionClass($repository->getClassName());
 }