/**
  * @inheritdoc
  */
 public function __construct($code, AttributeConfigurationHandler $attributeConfigurationHandler, FamilyConfigurationHandler $familyConfigurationHandler, ContextManager $contextManager, array $config)
 {
     foreach ($config['axles'] as $axle) {
         $this->axles[$axle] = $attributeConfigurationHandler->getAttribute($axle);
     }
     unset($config['axles']);
     parent::__construct($code, $attributeConfigurationHandler, $familyConfigurationHandler, $contextManager, $config);
 }
Ejemplo n.º 2
0
 /**
  * @param string                        $code
  * @param AttributeConfigurationHandler $attributeConfigurationHandler
  * @param FamilyConfigurationHandler    $familyConfigurationHandler
  * @param ContextManager                $contextManager
  * @param array                         $config
  * @throws UnexpectedValueException
  * @throws MissingFamilyException
  * @throws AccessException
  * @throws InvalidArgumentException
  * @throws UnexpectedTypeException
  */
 public function __construct($code, AttributeConfigurationHandler $attributeConfigurationHandler, FamilyConfigurationHandler $familyConfigurationHandler, ContextManager $contextManager, array $config = null)
 {
     $this->code = $code;
     $this->contextManager = $contextManager;
     if (!empty($config['parent'])) {
         $this->parent = $familyConfigurationHandler->getFamily($config['parent']);
         $this->copyFromFamily($this->parent);
     }
     unset($config['parent']);
     foreach ($config['attributes'] as $attribute) {
         $this->attributes[$attribute] = $attributeConfigurationHandler->getAttribute($attribute);
     }
     unset($config['attributes']);
     if (!empty($config['attributeAsLabel'])) {
         $labelCode = $config['attributeAsLabel'];
         if (!$this->hasAttribute($labelCode)) {
             $message = "Bad configuration for family {$code}: attribute as label '{$labelCode}'";
             $message .= " doesn't exists for this family";
             throw new UnexpectedValueException($message);
         }
         $this->attributeAsLabel = $this->getAttribute($labelCode);
     }
     unset($config['attributeAsLabel']);
     if (!empty($config['attributeAsIdentifier'])) {
         $labelCode = $config['attributeAsIdentifier'];
         $commonMessage = "Bad configuration for family {$code}: attribute as identifier '{$labelCode}'";
         if (!$this->hasAttribute($labelCode)) {
             throw new UnexpectedValueException("{$commonMessage} doesn't exists for this family");
         }
         $this->attributeAsIdentifier = $this->getAttribute($labelCode);
         if (!$this->attributeAsIdentifier->isUnique()) {
             throw new UnexpectedValueException("{$commonMessage} should be unique");
         }
         if (!$this->attributeAsIdentifier->isRequired()) {
             throw new UnexpectedValueException("{$commonMessage} should be required");
         }
         if ($this->attributeAsIdentifier->isMultiple()) {
             throw new UnexpectedValueException("{$commonMessage} should NOT be multiple");
         }
         if (0 !== count($this->attributeAsIdentifier->getContextMask())) {
             throw new UnexpectedValueException("{$commonMessage} should NOT be contextualized");
         }
     }
     unset($config['attributeAsIdentifier']);
     $accessor = PropertyAccess::createPropertyAccessor();
     foreach ($config as $key => $value) {
         $accessor->setValue($this, $key, $value);
     }
 }
 /**
  * @param OptionsResolver $resolver
  * @throws AccessException
  * @throws UndefinedOptionsException
  * @throws MissingFamilyException
  * @throws \UnexpectedValueException
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['required' => false, 'routes' => $this->routes]);
     $resolver->setRequired(['attribute']);
     $resolver->setNormalizer('attribute', function (Options $options, $value) {
         if ($value instanceof AttributeInterface) {
             return $value;
         }
         $attribute = $this->attributeConfigurationHandler->getAttribute($value);
         if (!$attribute->getType() instanceof VariantAttributeType) {
             throw new \UnexpectedValueException('Attribute option must be of type VariantAttributeType');
         }
         return $attribute;
     });
 }
 protected function convertValue($value)
 {
     return $this->attributeConfigurationHandler->getAttribute($value);
 }