示例#1
0
 public function getName()
 {
     if (empty($this->name)) {
         $r = new \ReflectionClass($this);
         $classname = $r->getShortName();
         $this->name = Strings::toLowerCamel(preg_replace('#Type$#', '', $classname));
     }
     return $this->name;
 }
示例#2
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;
 }
示例#3
0
 protected static function validateForeachable($param)
 {
     if (!is_array($param) && !$param instanceof \Traversable) {
         throw new ForeachableException(Strings::getClassOrType($param));
     }
 }
示例#4
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;
         }
     }
 }
示例#5
0
 /**
  * Soft deletes a record (implementing IsSoftDeletable)
  * @param $list
  * @return array ID list of actual soft deleted records
  * @author Yohann Marillet
  */
 public function softDelete($list)
 {
     if (!is_array($list) && !$list instanceof \Traversable) {
         $list = [$list];
     }
     $className = $this->getClassName();
     $idName = $this->getClassMetadata()->getIdentifier();
     //does not work for compound PKs
     $idName = reset($idName);
     $getter = Strings::toGetter($idName);
     $notDeleted = [];
     $resolveAlreadyDeleted = false;
     if (reset($list) instanceof $className) {
         $entities = $list;
     } else {
         $entities = $this->findByIdentifiersArray($list);
         $resolveAlreadyDeleted = true;
     }
     $return = [];
     foreach ($entities as $entity) {
         $id = $entity->{$getter}();
         if ($resolveAlreadyDeleted) {
             $notDeleted[] = $id;
         }
         /** @var IsSoftDeletable $entity */
         if ($entity->isSoftDeletable()) {
             $return[] = $id;
             $entity->setIsDeleted(true);
             $this->getEntityManager()->persist($entity);
         }
     }
     if (!empty($return)) {
         $this->getEntityManager()->flush();
     }
     if ($resolveAlreadyDeleted) {
         $diff = array_diff($list, $notDeleted);
         $return = $return + $diff;
     }
     return $return;
 }