Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function create($schemaAlias, $data = null, array $options = [])
 {
     $schema = $this->schemaRegistry->get($schemaAlias);
     $builder = $this->formFactory->createBuilder('form', $data, array_merge_recursive(['data_class' => null], $options));
     $schema->buildForm($builder);
     return $builder->getForm();
 }
Ejemplo n.º 2
0
 /**
  * @param FormInterface $form
  * @param string        $ruleType
  * @param array         $data
  */
 protected function addConfigurationFields(FormInterface $form, $ruleType, array $data = [])
 {
     /** @var RuleCheckerInterface $checker */
     $checker = $this->checkerRegistry->get($ruleType);
     $configurationField = $this->factory->createNamed('configuration', $checker->getConfigurationFormType(), $data, ['auto_initialize' => false]);
     $form->add($configurationField);
 }
 /**
  * {@inheritdoc}
  */
 public function get($type)
 {
     if (!$this->decoratedRegistry->has($type)) {
         return $this->defaultResolver;
     }
     return $this->decoratedRegistry->get($type);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new AddCodeFormSubscriber())->addEventSubscriber(new BuildReportDataFetcherFormSubscriber($this->dataFetcherRegistry, $builder->getFormFactory()))->addEventSubscriber(new BuildReportRendererFormSubscriber($this->rendererRegistry, $builder->getFormFactory()))->add('name', 'text', ['label' => 'sylius.form.report.name', 'required' => true])->add('description', 'textarea', ['label' => 'sylius.form.report.description', 'required' => false])->add('dataFetcher', 'sylius_data_fetcher_choice', ['label' => 'sylius.form.report.data_fetcher'])->add('renderer', 'sylius_renderer_choice', ['label' => 'sylius.form.report.renderer.label']);
     $prototypes = ['renderers' => [], 'dataFetchers' => []];
     foreach ($this->rendererRegistry->all() as $type => $renderer) {
         $formType = sprintf('sylius_renderer_%s', $renderer->getType());
         if (!$formType) {
             continue;
         }
         try {
             $prototypes['renderers'][$type] = $builder->create('rendererConfiguration', $formType)->getForm();
         } catch (\InvalidArgumentException $e) {
             continue;
         }
     }
     foreach ($this->dataFetcherRegistry->all() as $type => $dataFetcher) {
         $formType = sprintf('sylius_data_fetcher_%s', $dataFetcher->getType());
         if (!$formType) {
             continue;
         }
         try {
             $prototypes['dataFetchers'][$type] = $builder->create('dataFetcherConfiguration', $formType)->getForm();
         } catch (\InvalidArgumentException $e) {
             continue;
         }
     }
     $builder->setAttribute('prototypes', $prototypes);
 }
 /**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters)
 {
     if ($parameters->has(ResourceOwnerFilter::TYPE)) {
         $this->filtersRegistry->get(ResourceOwnerFilter::TYPE)->apply($dataSource, ResourceOwnerFilter::FIELD, $parameters->get(ResourceOwnerFilter::TYPE), []);
     }
     return $this->filtersApplicator->apply($dataSource, $grid, $parameters);
 }
Ejemplo n.º 6
0
 function it_throws_an_exception_if_driver_is_not_supported(Grid $grid, ServiceRegistryInterface $driversRegistry)
 {
     $parameters = new Parameters();
     $grid->getDriver()->willReturn('doctrine/banana');
     $driversRegistry->has('doctrine/banana')->willReturn(false);
     $this->shouldThrow(new UnsupportedDriverException('doctrine/banana'))->during('getDataSource', [$grid, $parameters]);
 }
Ejemplo n.º 7
0
 function it_renders_field_with_data_via_appriopriate_field_type(GridView $gridView, Field $field, ServiceRegistryInterface $fieldsRegistry, FieldTypeInterface $fieldType)
 {
     $field->getType()->willReturn('string');
     $fieldsRegistry->get('string')->willReturn($fieldType);
     $fieldType->render($field, 'Value')->willReturn('<strong>Value</strong>');
     $this->renderField($gridView, $field, 'Value')->shouldReturn('<strong>Value</strong>');
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function getDataSource(Grid $grid, Parameters $parameters)
 {
     $driver = $grid->getDriver();
     if (!$this->driversRegistry->has($driver)) {
         throw new UnsupportedDriverException($driver);
     }
     return $this->driversRegistry->get($driver)->getDataSource($grid->getDriverConfiguration(), $parameters);
 }
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof AttributeValueInterface) {
         throw new UnexpectedTypeException(get_class($value), AttributeValueInterface::class);
     }
     $attributeType = $this->attributeTypeRegistry->get($value->getType());
     $attributeType->validate($value, $this->context, $value->getAttribute()->getConfiguration());
 }
Ejemplo n.º 10
0
 /**
  * @param Field $field
  * @param $data
  */
 public function renderField(GridView $gridView, Field $field, $data)
 {
     $fieldType = $this->fieldsRegistry->get($field->getType());
     $resolver = new OptionsResolver();
     $fieldType->configureOptions($resolver);
     $options = $resolver->resolve($field->getOptions());
     return $fieldType->render($field, $data, $options);
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PriceableInterface $subject, array $context = array())
 {
     if (null === ($type = $subject->getPricingCalculator())) {
         throw new \InvalidArgumentException('Cannot calculate the price for PriceableInterface instance without calculator defined.');
     }
     $calculator = $this->registry->get($type);
     return $calculator->calculate($subject, $subject->getPricingConfiguration(), $context);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException If the report subject does not have a renderer.
  */
 public function render(ReportInterface $subject, Data $data)
 {
     if (null === ($type = $subject->getRenderer())) {
         throw new \InvalidArgumentException('Cannot render data for ReportInterface instance without renderer defined.');
     }
     $renderer = $this->registry->get($type);
     return $renderer->render($subject, $data);
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject)
 {
     if (null === ($method = $subject->getMethod())) {
         throw new UndefinedShippingMethodException('Cannot calculate charge for shipping subject without defined shipping method.');
     }
     $calculator = $this->registry->get($method->getCalculator());
     return $calculator->calculate($subject, $method->getConfiguration());
 }
Ejemplo n.º 14
0
 function it_should_create_a_form_for_given_schema_namespace(FormInterface $form, FormBuilder $formBuilder, FormFactoryInterface $formFactory, SchemaInterface $schema, ServiceRegistryInterface $schemaRegistry)
 {
     $schemaRegistry->get('sylius_general')->willReturn($schema);
     $formFactory->createBuilder('form', null, ['data_class' => null])->willReturn($formBuilder);
     $schema->buildForm($formBuilder)->shouldBeCalled()->willReturn($formBuilder);
     $formBuilder->getForm()->willReturn($form);
     $this->create('sylius_general')->shouldReturn($form);
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['resource' => null, 'choices' => function (Options $options) {
         return $options['function']($this->resourceRepositoryRegistry->get($options['resource']), $options);
     }, 'function' => function (RepositoryInterface $repository, Options $options) {
         return $repository->findAll();
     }])->setRequired(['resource']);
 }
 function it_builds_prototypes(FormBuilderInterface $builder, FormBuilderInterface $prototype, FormInterface $form, ServiceRegistryInterface $registry)
 {
     $registry->all()->willReturn(['configuration_kind' => '']);
     $builder->create('name', 'sylius_promotion_action', ['configuration_type' => 'configuration_kind'])->willReturn($prototype);
     $prototype->getForm()->willReturn($form);
     $builder->setAttribute('prototypes', ['configuration_kind' => $form])->shouldBeCalled();
     $this->buildForm($builder, ['registry' => $registry, 'prototype_name' => 'name', 'type' => 'sylius_promotion_action', 'options' => []]);
 }
Ejemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PaymentSubjectInterface $payment)
 {
     if (null === $payment->getMethod()) {
         throw new \InvalidArgumentException("Cannot calculate fee for payment without payment method configured.");
     }
     /** @var FeeCalculatorInterface $feeCalculator */
     $feeCalculator = $this->serviceRegistry->get($payment->getMethod()->getFeeCalculator());
     return $feeCalculator->calculate($payment, $payment->getMethod()->getFeeCalculatorConfiguration());
 }
Ejemplo n.º 18
0
 function it_should_delegate_calculation_to_a_calculator_defined_on_shipping_method(ServiceRegistryInterface $registry, ShipmentInterface $shipment, ShippingMethodInterface $method, CalculatorInterface $calculator)
 {
     $shipment->getMethod()->willReturn($method);
     $method->getCalculator()->willReturn('default');
     $method->getConfiguration()->willReturn([]);
     $registry->get('default')->willReturn($calculator);
     $calculator->calculate($shipment, [])->shouldBeCalled()->willReturn(1000);
     $this->calculate($shipment, [])->shouldReturn(1000);
 }
 function it_registers_theme_schema_alias_if_not_exists_during_loading_settings(SettingsManagerInterface $decoratedSettingsManager, ServiceRegistryInterface $schemaRegistry, ThemeSettingsSchemaProviderInterface $themeSettingsSchemaProvider, ThemeInterface $theme, SettingsInterface $settings, SchemaInterface $schema)
 {
     $theme->getName()->willReturn('theme/name');
     $schemaRegistry->has('theme_theme/name')->willReturn(false);
     $themeSettingsSchemaProvider->getSchema($theme)->willReturn($schema);
     $schemaRegistry->register('theme_theme/name', $schema)->shouldBeCalled();
     $decoratedSettingsManager->load('theme_theme/name', null)->willReturn($settings);
     $this->load($theme)->shouldReturn($settings);
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function load(ThemeInterface $theme, $namespace = null)
 {
     $schemaAlias = sprintf('theme_%s', $theme->getName());
     if (!$this->schemaRegistry->has($schemaAlias)) {
         $schema = $this->themeSettingsSchemaProvider->getSchema($theme);
         $this->schemaRegistry->register($schemaAlias, $schema);
     }
     return $this->decoratedSettingsManager->load($schemaAlias, $namespace);
 }
Ejemplo n.º 21
0
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException If the report does not have a data fetcher.
  */
 public function fetch(ReportInterface $report, array $configuration = [])
 {
     if (null === ($type = $report->getDataFetcher())) {
         throw new \InvalidArgumentException('Cannot fetch data for ReportInterface instance without DataFetcher defined.');
     }
     $dataFetcher = $this->registry->get($type);
     $configuration = empty($configuration) ? $report->getDataFetcherConfiguration() : $configuration;
     return $dataFetcher->fetch($configuration);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (!$options['multiple']) {
         $builder->addModelTransformer(new ResourceToIdentifierTransformer($this->resourceRepositoryRegistry->get($options['resource']), $options['choice_value']));
     }
     if ($options['multiple']) {
         $builder->addModelTransformer(new RecursiveTransformer(new ResourceToIdentifierTransformer($this->resourceRepositoryRegistry->get($options['resource']), $options['choice_value'])))->addViewTransformer(new CollectionToStringTransformer(','));
     }
 }
 function it_validates_attribute_value_based_on_their_type(AttributeInterface $attribute, AttributeTypeInterface $attributeType, AttributeValueInterface $attributeValue, ServiceRegistryInterface $attributeTypesRegistry, ValidAttributeValue $attributeValueConstraint)
 {
     $attributeValue->getType()->willReturn(TextAttributeType::TYPE);
     $attributeTypesRegistry->get('text')->willReturn($attributeType);
     $attributeValue->getAttribute()->willReturn($attribute);
     $attribute->getConfiguration()->willReturn(['min' => 2, 'max' => 255]);
     $attributeType->validate($attributeValue, Argument::any(ExecutionContextInterface::class), ['min' => 2, 'max' => 255])->shouldBeCalled();
     $this->validate($attributeValue, $attributeValueConstraint);
 }
Ejemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public function createTyped($type)
 {
     /** @var AttributeTypeInterface $attributeType */
     $attributeType = $this->attributeTypesRegistry->get($type);
     $attribute = $this->factory->createNew();
     $attribute->setType($type);
     $attribute->setStorageType($attributeType->getStorageType());
     return $attribute;
 }
Ejemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function getDataSource(Grid $grid, Parameters $parameters)
 {
     $driverName = $grid->getDriver();
     if (!$this->driversRegistry->has($driverName)) {
         throw new UnsupportedDriverException($driverName);
     }
     /** @var DriverInterface $driver */
     $driver = $this->driversRegistry->get($driverName);
     return $driver->getDataSource($grid->getDriverConfiguration(), $parameters);
 }
Ejemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject)
 {
     // FIXME: ShippingSubjectInterface does not have any of called methods!
     if (null === ($method = $subject->getMethod())) {
         throw new UndefinedShippingMethodException('Cannot calculate charge for shipping subject without defined shipping method.');
     }
     /** @var CalculatorInterface $calculator */
     $calculator = $this->registry->get($method->getCalculator());
     return $calculator->calculate($subject, $method->getConfiguration());
 }
Ejemplo n.º 27
0
 function it_creates_typed_attribute(Attribute $typedAttribute, AttributeTypeInterface $attributeType, FactoryInterface $factory, ServiceRegistryInterface $attributeTypesRegistry)
 {
     $factory->createNew()->willReturn($typedAttribute);
     $attributeType->getStorageType()->willReturn('datetime');
     $attributeTypesRegistry->get('datetime')->willReturn($attributeType);
     $typedAttribute->setType('datetime')->shouldBeCalled();
     $typedAttribute->getType()->willReturn('datetime');
     $typedAttribute->setStorageType('datetime')->shouldBeCalled();
     $this->createTyped('datetime')->shouldReturn($typedAttribute);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $prototypes = [];
     foreach (array_keys($this->registry->all()) as $type) {
         $prototypeOptions = array_replace(['configuration_type' => $type], $options['options']);
         $form = $builder->create($options['prototype_name'], $options['type'], $prototypeOptions);
         $prototypes[$type] = $form->getForm();
     }
     $builder->setAttribute('prototypes', $prototypes);
 }
 /**
  * Add configuration fields to the form
  *
  * @param FormInterface $form
  * @param string        $rendererType
  * @param array         $data
  */
 public function addConfigurationFields(FormInterface $form, $rendererType, array $data = array())
 {
     $renderer = $this->rendererRegistry->get($rendererType);
     $formType = sprintf('sylius_renderer_%s', $renderer->getType());
     try {
         $configurationField = $this->factory->createNamed('rendererConfiguration', $formType, $data, array('auto_initialize' => false));
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $form->add($configurationField);
 }
 /**
  * Add configuration fields to the form.
  *
  * @param FormInterface $form
  * @param string        $dataFetcherType
  * @param array         $config
  */
 protected function addConfigurationFields(FormInterface $form, $dataFetcherType, array $config = [])
 {
     $dataFetcher = $this->dataFecherRegistry->get($dataFetcherType);
     $formType = $dataFetcher->getType();
     try {
         $configurationField = $this->factory->createNamed('dataFetcherConfiguration', $formType, $config, ['auto_initialize' => false]);
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $form->add($configurationField);
 }