Example #1
0
 /**
  * Wake from serialization
  *
  * @param array $array
  */
 public static function __set_state($array)
 {
     $object = new self();
     foreach ($array as $key => $value) {
         $object->offsetSet($key, $value);
     }
     return $object;
 }
Example #2
0
 /**
  *
  * Because of compatibility with php 5.2 we can't use late static bindings in the abstract class ( introduced in php 5.3 )
  *
  * So we can't use 'new static' reserved word, we have to use 'new self'
  *
  * Workaround: declare this method into an interface, don't implement it in the abstract class
  * and declare real method every time in the same manner into the children
  *
  * @param $storage
  *
  * @return mixed
  *
  * @throws LogicException/DomainException
  */
 public static function getInflate($storage)
 {
     $obj = new self();
     foreach ($storage as $key => $value) {
         $obj->offsetSet($key, $value);
     }
     return $obj;
 }
Example #3
0
 /**
  * @param string|int $page
  * @param string|int $limit
  * @return Collection
  */
 public function getAllByPages($page = 1, $limit = 20)
 {
     $result = new self();
     if (!$this->count()) {
         return $result;
     }
     $firstElement = ($page - 1) * $limit;
     $iterator = $this->getIterator();
     $iterator->seek($firstElement);
     while ($iterator->current() && $result->count() < $limit) {
         $result->offsetSet($iterator->current()->getId(), $iterator->current());
         $iterator->next();
     }
     return $result;
 }
Example #4
0
 /**
  * Фильтрация шестерёнок. Активные или неактивные, или шестерёнки ядра
  *
  * @param int $type
  * @param mixed $param Параметр только для соответствия родительского метода
  */
 public function filter($type = Gears::ENABLED, $param = NULL)
 {
     $gears = new self();
     foreach ($this as $gear => $object) {
         if ($type == Gears::ENABLED && NULL !== cogear()->config->gears->findByValue($gear)) {
             $gears->offsetSet($gear, $object);
         } else {
             if ($type == Gears::CORE && NULL !== cogear()->site->gears->findByValue($gear)) {
                 $gears->offsetSet($gear, $object);
             } else {
                 if ($type == Gears::DISABLED && NULL === cogear()->site->gears->findByValue($gear) && NULL === cogear()->config->gears->findByValue($gear)) {
                     $gears->offsetSet($gear, $object);
                 }
             }
         }
     }
     return $gears;
 }