Ejemplo n.º 1
0
 /**
  * Rebuild a barely new group to a readable array.
  *
  * @param \Docoflow\Entity\Step &$steps
  *
  * @return \Docoflow\Entity\Group
  */
 public function rebuild(Step &$steps)
 {
     $groups = new static();
     foreach ($this as $group) {
         $group = fluent($group);
         if (!($groupId = $group->{'$id'})) {
             throw new Exception("Group doesn't have an id.");
         }
         if (!($assignedStep = $group->{'$step'})) {
             throw new Exception("Group doesn't have any assigned step id.");
         }
         if ($steps->has($assignedStep)) {
             if ($steps->get($assignedStep)->groups->has($groupId)) {
                 throw new Exception("Group id [{$groupId}] has been assigned before and it can't be overriden.");
             }
             $group->verificator = new Verificator();
             $groups->offsetSet($groupId, $group);
             $steps->pushGroup($groupId, $group);
             $steps->get($assignedStep)->groups->offsetSet($groupId, $group);
         } else {
             throw new Exception("Assigned step [{$assignedStep}] doesn't exist.");
         }
     }
     return $groups;
 }
Ejemplo n.º 2
0
 /**
  * Extracts a slice of $length elements starting at position $offset from the Collection.
  *
  * If $length is null it returns all elements from $offset to the end of the Collection.
  * Keys have to be preserved by this method. Calling this method will only return the
  * selected slice and NOT change the elements contained in the collection slice is called on.
  *
  * @param int $offset The offset to start from.
  * @param int|null $length The maximum number of elements to return, or null for no limit.
  *
  * @return HierarchyCollection
  */
 public function slice($offset, $length = null)
 {
     $i = 0;
     $collection = new static();
     do {
         $collection->offsetSet($offset, $this->offsetGet($offset));
         $i++;
         if ($length !== null && $i >= $length) {
             break;
         }
     } while ($offset = $this->_elements->next($offset));
     return $collection;
 }
Ejemplo n.º 3
0
 /**
  * @see Modelable::from_array() */
 public static function from_array(array $data) : ModelableAPI
 {
     $model = new static();
     foreach ($array as $prop => $value) {
         $model->offsetSet($prop, $value);
     }
     return $model;
 }