Exemplo 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();
 }
 /**
  * {@inheritdoc}
  */
 public function get($type)
 {
     if (!$this->decoratedRegistry->has($type)) {
         return $this->defaultResolver;
     }
     return $this->decoratedRegistry->get($type);
 }
 /**
  * {@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);
 }
 /**
  * @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);
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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);
 }
 /**
  * {@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());
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
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());
 }
Exemplo n.º 11
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']);
 }
Exemplo n.º 12
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;
 }
 /**
  * {@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(','));
     }
 }
Exemplo n.º 14
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());
 }
Exemplo n.º 15
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);
 }
Exemplo n.º 16
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());
 }
Exemplo n.º 17
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);
 }
 /**
  * @param FormInterface $form
  * @param string $calculatorName
  * @param array $data
  */
 protected function addConfigurationFields(FormInterface $form, $calculatorName, array $data = [])
 {
     /** @var CalculatorInterface $calculator */
     $calculator = $this->calculatorRegistry->get($calculatorName);
     $calculatorTypeName = sprintf('sylius_shipping_calculator_%s', $calculator->getType());
     if (!$this->formRegistry->hasType($calculatorTypeName)) {
         return;
     }
     $configurationField = $this->factory->createNamed('configuration', $calculatorTypeName, $data, ['auto_initialize' => false]);
     $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);
 }
 /**
  * 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);
 }
 /**
  * @param FormInterface $form
  * @param string        $feeCalculatorType
  * @param array         $data
  */
 private function addConfigurationFields(FormInterface $form, $feeCalculatorType, $data = array())
 {
     $feeCalculator = $this->feeCalculatorRegistry->get($feeCalculatorType);
     $formType = sprintf('sylius_fee_calculator_%s', $feeCalculator->getType());
     try {
         $configurationField = $this->factory->createNamed('feeCalculatorConfiguration', $formType, $data, array('auto_initialize' => false));
     } catch (\InvalidArgumentException $exception) {
         return;
     }
     $form->add($configurationField);
 }
 /**
  * Add configuration fields to the form.
  *
  * @param FormInterface $form
  * @param string        $rendererType
  * @param array         $data
  */
 public function addConfigurationFields(FormInterface $form, $rendererType, array $data = [])
 {
     /** @var RendererInterface $renderer */
     $renderer = $this->rendererRegistry->get($rendererType);
     $formType = $renderer->getType();
     try {
         $configurationField = $this->factory->createNamed('rendererConfiguration', $formType, $data, ['auto_initialize' => false]);
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $form->add($configurationField);
 }
 /**
  * {@inheritdoc}
  */
 public function isEligible(ShippingSubjectInterface $subject, ShippingMethodInterface $method)
 {
     if (!$this->isCategoryEligible($subject, $method)) {
         return false;
     }
     foreach ($method->getRules() as $rule) {
         $checker = $this->registry->get($rule->getType());
         if (!$checker->isEligible($subject, $rule->getConfiguration())) {
             return false;
         }
     }
     return true;
 }
 function it_does_not_check_more_rules_if_one_has_returned_false(RuleCheckerInterface $cartQuantityRuleChecker, RuleCheckerInterface $itemTotalRuleChecker, RuleInterface $cartQuantityRule, RuleInterface $itemTotalRule, PromotionInterface $promotion, PromotionSubjectInterface $subject, ServiceRegistryInterface $rulesRegistry)
 {
     $promotion->hasRules()->willReturn(true);
     $promotion->getRules()->willReturn([$cartQuantityRule, $itemTotalRule]);
     $cartQuantityRule->getType()->willReturn(RuleInterface::TYPE_CART_QUANTITY);
     $cartQuantityRule->getConfiguration()->willReturn([]);
     $itemTotalRule->getType()->willReturn(RuleInterface::TYPE_ITEM_TOTAL);
     $itemTotalRule->getConfiguration()->willReturn([]);
     $rulesRegistry->get(RuleInterface::TYPE_CART_QUANTITY)->willReturn($cartQuantityRuleChecker);
     $rulesRegistry->get(RuleInterface::TYPE_ITEM_TOTAL)->willReturn($itemTotalRuleChecker);
     $cartQuantityRuleChecker->isEligible($subject, [])->willReturn(false);
     $itemTotalRuleChecker->isEligible($subject, [])->shouldNotBeCalled();
     $this->isEligible($subject, $promotion)->shouldReturn(false);
 }
 function it_does_not_check_more_rules_if_one_has_returned_false(ServiceRegistryInterface $rulesRegistry, RuleCheckerInterface $firstRuleChecker, RuleCheckerInterface $secondRuleChecker, RuleInterface $firstRule, RuleInterface $secondRule, PromotionInterface $promotion, PromotionSubjectInterface $subject)
 {
     $promotion->hasRules()->willReturn(true);
     $promotion->getRules()->willReturn([$firstRule, $secondRule]);
     $firstRule->getType()->willReturn('first_rule');
     $firstRule->getConfiguration()->willReturn([]);
     $secondRule->getType()->willReturn('second_rule');
     $secondRule->getConfiguration()->willReturn([]);
     $rulesRegistry->get('first_rule')->willReturn($firstRuleChecker);
     $rulesRegistry->get('second_rule')->willReturn($secondRuleChecker);
     $firstRuleChecker->isEligible($subject, [])->willReturn(false);
     $secondRuleChecker->isEligible($subject, [])->shouldNotBeCalled();
     $this->isEligible($subject, $promotion)->shouldReturn(false);
 }
Exemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function apply(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters)
 {
     if (!$parameters->has('criteria')) {
         return;
     }
     $criteria = $parameters->get('criteria');
     foreach ($criteria as $name => $data) {
         if (!$grid->hasFilter($name)) {
             continue;
         }
         $filter = $grid->getFilter($name);
         $this->filtersRegistry->get($filter->getType())->apply($dataSource, $name, $data, $filter->getOptions());
     }
 }
Exemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $paymentCosts = array();
     $payment = $view->parent->vars['value']->getPayments()->last();
     foreach ($view->vars['choices'] as $choiceView) {
         $method = $choiceView->data;
         if (!$method instanceof PaymentMethodInterface) {
             throw new UnexpectedTypeException($method, 'Sylius\\Component\\Payment\\Model\\PaymentMethodInterface');
         }
         $feeCalculator = $this->feeCalculatorRegistry->get($method->getFeeCalculator());
         $payment->setMethod($method);
         $paymentCosts[$choiceView->value] = $feeCalculator->calculate($payment, $method->getFeeCalculatorConfiguration());
     }
     $view->vars['paymentCosts'] = $paymentCosts;
 }
Exemplo n.º 28
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>');
 }
Exemplo n.º 29
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);
 }
Exemplo n.º 30
0
 function it_uses_a_correct_driver_to_get_the_data_for_a_grid(ServiceRegistryInterface $driversRegistry, DriverInterface $driver, Grid $grid, Parameters $parameters)
 {
     $grid->getDriver()->willReturn('doctrine/orm');
     $grid->getDriverConfiguration()->willReturn(['resource' => 'sylius.tax_category']);
     $driversRegistry->has('doctrine/orm')->willReturn(true);
     $driversRegistry->get('doctrine/orm')->willReturn($driver);
     $driver->getDataSource(['resource' => 'sylius.tax_category'], $parameters)->willReturn(['foo', 'bar']);
     $this->getDataSource($grid, $parameters)->shouldReturn(['foo', 'bar']);
 }