コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (null === $value) {
         return null;
     }
     $class = $this->repository->getClassName();
     Assert::isInstanceOf($value, $class);
     $accessor = PropertyAccess::createPropertyAccessor();
     return $accessor->getValue($value, $this->identifier);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (null === $value) {
         return null;
     }
     $resource = $this->repository->findOneBy([$this->identifier => $value]);
     if (null === $resource) {
         throw new TransformationFailedException(sprintf('Object "%s" with identifier "%s"="%s" does not exist.', $this->repository->getClassName(), $this->identifier, $value));
     }
     return $resource;
 }
コード例 #3
0
 function it_reverse_transform_resource_to_identifier(RepositoryInterface $repository, FakeEntity $value)
 {
     $repository->getClassName()->willReturn(FakeEntity::class);
     $value->getId()->willReturn(6);
     $this->reverseTransform($value)->shouldReturn(6);
 }
コード例 #4
0
 function it_transforms_resource_in_identifier(RepositoryInterface $repository, ResourceInterface $resource)
 {
     $repository->getClassName()->willReturn(ResourceInterface::class);
     $resource->getId()->willReturn(6);
     $this->transform($resource)->shouldReturn(6);
 }
コード例 #5
0
 function let(RepositoryInterface $repository)
 {
     $repository->getClassName()->willReturn('spec\\Sylius\\Bundle\\ResourceBundle\\Form\\DataTransformer\\FakeEntity');
     $this->beConstructedWith($repository, 'id');
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('groups', 'sylius_group_from_identifier', ['label' => 'sylius.form.action.customer_group', 'property' => 'name', 'class' => $this->groupRepository->getClassName(), 'constraints' => [new NotBlank(), new Type(['type' => 'numeric'])]]);
 }
コード例 #7
0
ファイル: CustomerGroupType.php プロジェクト: Niiko/Sylius
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('group', CustomerGroupCodeChoiceType::class, ['label' => 'sylius.form.promotion_action.customer_group', 'property' => 'name', 'class' => $this->groupRepository->getClassName(), 'constraints' => [new NotBlank(['groups' => ['sylius']]), new Type(['type' => 'numeric', 'groups' => ['sylius']])]]);
 }