예제 #1
0
 /**
  * Modify a single object in the collection
  *
  * @param TaintedInterface $object
  *
  * @throws BusinessException
  * @return $this
  */
 protected function _modify(TaintedInterface $object)
 {
     try {
         $obj = $this->offsetGet($object);
         if ($object === $obj) {
             throw new BusinessException("Logic error: the parameter must be a different object from the one used in the collection.");
         }
         foreach ($object->getTainted() as $key => $val) {
             $func = Strings::toSetter($key);
             $obj->{$func}($val);
         }
     } catch (CollectionException $e) {
         //this element is new to the collection, simply insert it into the collection (deep copy)
         $obj = Objects::deepCopy($object);
         $this->offsetSet($obj, $obj);
     }
     return $this;
 }
예제 #2
0
 /**
  * Builds the translatable properties for a defined class
  * @param $className
  *
  * @author Yohann Marillet
  */
 protected function buildTranslatableProperties($className)
 {
     if (!isset(static::$translatableProperties[$className])) {
         static::$translatableProperties[$className] = ['fields' => [], 'setLocaleMethod' => '', 'usePersonalTranslations' => false];
         $refl = new \ReflectionClass($className);
         $reader = new AnnotationReader();
         foreach ($refl->getProperties() as $prop) {
             $annotations = $reader->getPropertyAnnotations($prop);
             foreach ($annotations as $annotation) {
                 if ($annotation instanceof \Gedmo\Mapping\Annotation\Translatable) {
                     $name = $prop->getName();
                     static::$translatableProperties[$className]['fields'][$name] = '';
                     break;
                 } elseif ($annotation instanceof \Gedmo\Mapping\Annotation\Locale) {
                     $name = $prop->getName();
                     static::$translatableProperties[$className]['setLocaleMethod'] = Strings::toSetter($name);
                     break;
                 }
             }
         }
         $usePersonalTranslations = $reader->getClassAnnotation($refl, '\\Gedmo\\Mapping\\Annotation\\TranslationEntity');
         if (null != $usePersonalTranslations) {
             static::$translatableProperties[$className]['usePersonalTranslations'] = $usePersonalTranslations;
         }
     }
 }