/**
  * {@inheritdoc}
  *
  * Expected input format :
  * {
  *     'attribute': 'maximum_print_size',
  *     'code': '210_x_1219_mm',
  *     'sort_order': 2,
  *     'labels': {
  *         'de_DE': '210 x 1219 mm',
  *         'en_US': '210 x 1219 mm',
  *         'fr_FR': '210 x 1219 mm'
  *     }
  * }
  *
  * @throws BusinessValidationException
  */
 public function update($attributeOption, array $data, array $options = [])
 {
     if (!$attributeOption instanceof AttributeOptionInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\AttributeOptionInterface", "%s" provided.', ClassUtils::getClass($attributeOption)));
     }
     // TODO: ugly fix to workaround issue with "attribute.group.code: This value should not be blank."
     // in case of existing option, attribute is a proxy, attribute group too, the validated group code is null
     $attributeOption->getAttribute() !== null ? $attributeOption->getAttribute()->getGroup()->getCode() : null;
     $isNew = $attributeOption->getId() === null;
     $readOnlyFields = ['attribute', 'code'];
     $updateViolations = new ConstraintViolationList();
     foreach ($data as $field => $data) {
         $isReadOnlyField = in_array($field, $readOnlyFields);
         if ($isNew || !$isReadOnlyField) {
             try {
                 $this->setData($attributeOption, $field, $data);
             } catch (\InvalidArgumentException $e) {
                 $setViolation = new ConstraintViolation($e->getMessage(), $e->getMessage(), [], $attributeOption, null, null);
                 $updateViolations->add($setViolation);
             }
         }
     }
     $validatorViolations = $this->validator->validate($attributeOption);
     $updateViolations->addAll($validatorViolations);
     if ($updateViolations->count() > 0) {
         throw new BusinessValidationException($updateViolations);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  *
  * Expected input format :
  * {
  *     'attribute': 'maximum_print_size',
  *     'code': '210_x_1219_mm',
  *     'sort_order': 2,
  *     'labels': {
  *         'de_DE': '210 x 1219 mm',
  *         'en_US': '210 x 1219 mm',
  *         'fr_FR': '210 x 1219 mm'
  *     }
  * }
  */
 public function update($attributeOption, array $data, array $options = [])
 {
     if (!$attributeOption instanceof AttributeOptionInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Component\\Catalog\\Model\\AttributeOptionInterface", "%s" provided.', ClassUtils::getClass($attributeOption)));
     }
     $isNew = $attributeOption->getId() === null;
     $readOnlyFields = ['attribute', 'code'];
     foreach ($data as $field => $data) {
         $isReadOnlyField = in_array($field, $readOnlyFields);
         if ($isNew || !$isReadOnlyField) {
             $this->setData($attributeOption, $field, $data);
         }
     }
     return $this;
 }
 /**
  * @param object $entity
  *
  * @return array
  */
 private function getIdentifierValues($entity)
 {
     try {
         return $this->modelManager->getIdentifierValues($entity);
     } catch (\Exception $e) {
         throw new \InvalidArgumentException(sprintf('Unable to retrieve the identifier values for entity %s', ClassUtils::getClass($entity)), 0, $e);
     }
 }
 /**
  * Export
  *
  * @param mixed $var
  * @param int $maxDepth
  * @return mixed
  */
 public static function export($var, $maxDepth)
 {
     $return = null;
     $isObj = is_object($var);
     if ($isObj && in_array('Doctrine\\Common\\Collections\\Collection', class_implements($var))) {
         $var = $var->toArray();
     }
     if ($maxDepth) {
         if (is_array($var)) {
             $return = array();
             foreach ($var as $k => $v) {
                 $return[$k] = self::export($v, $maxDepth - 1);
             }
         } else {
             if ($isObj) {
                 $return = new \stdclass();
                 if ($var instanceof \DateTime) {
                     $return->__CLASS__ = "DateTime";
                     $return->date = $var->format('c');
                     $return->timezone = $var->getTimeZone()->getName();
                 } else {
                     $reflClass = ClassUtils::newReflectionObject($var);
                     $return->__CLASS__ = ClassUtils::getClass($var);
                     if ($var instanceof \Doctrine\Common\Persistence\Proxy) {
                         $return->__IS_PROXY__ = true;
                         $return->__PROXY_INITIALIZED__ = $var->__isInitialized();
                     }
                     foreach ($reflClass->getProperties() as $reflProperty) {
                         $name = $reflProperty->getName();
                         $reflProperty->setAccessible(true);
                         $return->{$name} = self::export($reflProperty->getValue($var), $maxDepth - 1);
                     }
                 }
             } else {
                 $return = $var;
             }
         }
     } else {
         $return = is_object($var) ? get_class($var) : (is_array($var) ? 'Array(' . count($var) . ')' : $var);
     }
     return $return;
 }