/**
  * @param  Attribute            $attribute
  * @param  array                $context
  * @return array
  * @throws InvalidItemException
  */
 protected function normalizeAttribute(Attribute $attribute, array $context)
 {
     try {
         $processedItem = $this->attributeNormalizer->normalize($attribute, $context);
     } catch (NormalizeException $e) {
         throw new InvalidItemException($e->getMessage(), [$attribute]);
     }
     return $processedItem;
 }
コード例 #2
0
 /**
  * @param  object                                                $family
  * @param  null                                                  $format
  * @param  array                                                 $context
  * @return array|\Symfony\Component\Serializer\Normalizer\scalar
  * @throws Exception\NormalizeException
  */
 public function normalize($family, $format = null, array $context = [])
 {
     /**@var Family $family * */
     $normalizedFamily = ['code' => $family->getCode(), 'labels' => [], 'attribute_groups' => []];
     foreach ($family->getTranslations() as $trans) {
         $normalizedFamily['labels'][$trans->getLocale()] = $trans->getLabel();
     }
     $associations = $this->associationTypeRepository->findAll();
     $normalizedFamily['associations'] = array();
     foreach ($associations as $association) {
         $normalizedFamily['associations'][$association->getCode()] = array();
         foreach ($association->getTranslations() as $assocTrans) {
             $normalizedFamily['associations'][$association->getCode()]['labels'][$assocTrans->getLocale()] = $assocTrans->getLabel();
         }
     }
     foreach ($family->getAttributes() as $attr) {
         $normalizedFamily['attribute_groups'][$attr->getGroup()->getCode()]['code'] = $attr->getGroup()->getCode();
         foreach ($attr->getGroup()->getTranslations() as $groupTrans) {
             $normalizedFamily['attribute_groups'][$attr->getGroup()->getCode()]['labels'][$groupTrans->getLocale()] = $groupTrans->getLabel();
         }
         $normalizedFamily['attribute_groups'][$attr->getGroup()->getCode()]['attributes'][$attr->getCode()] = $this->attributeNormalizer->normalize($attr, null, $context);
     }
     return $normalizedFamily;
 }