php Sylius-Component-Registry-ServiceRegistryInterface类(方法)实例源码

下面列出了php Sylius-Component-Registry-ServiceRegistryInterface 类(方法)源码代码实例,从而了解它的用法。

作者:loic42    项目:Syliu   
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]);
 }

作者:ahmadrabi    项目:Syliu   
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>');
 }

作者:loic42    项目:Syliu   
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);
 }

作者:loic42    项目:Syliu   
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' => []]);
 }

作者:loic42    项目:Syliu   
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);
 }

作者:ReissClothin    项目:Syliu   
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);
 }

作者:TheMadelein    项目:Syliu   
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);
 }

作者:loic42    项目:Syliu   
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);
 }

作者:ahmadrabi    项目:Syliu   
/**
  * {@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();
 }

作者:TeamNovate    项目:Syliu   
/**
  * @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);
 }

作者:ReissClothin    项目:Syliu   
/**
  * {@inheritdoc}
  */
 public function get($type)
 {
     if (!$this->decoratedRegistry->has($type)) {
         return $this->defaultResolver;
     }
     return $this->decoratedRegistry->get($type);
 }

作者:vikey8    项目:Syliu   
/**
  * {@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);
 }

作者:liverboo    项目:dos-resource-bundl   
/**
  * {@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);
 }

作者:ahmadrabi    项目:Syliu   
/**
  * {@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);
 }

作者:ahmadrabi    项目:Syliu   
/**
  * {@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());
 }

作者:okwinz    项目:Syliu   
/**
  * @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);
 }

作者:alehers    项目:Syliu   
/**
  * {@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);
 }

作者:nany    项目:Syliu   
/**
  * {@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);
 }

作者:alehers    项目:Syliu   
/**
  * {@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());
 }

作者:NeverRespons    项目:Syliu   
/**
  * {@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']);
 }


问题


面经


文章

微信
公众号

扫码关注公众号