RedBeanPHP\Repository::convertToBeans PHP Method

convertToBeans() public method

New in 4.3.2: meta mask. The meta mask is a special mask to send data from raw result rows to the meta store of the bean. This is useful for bundling additional information with custom queries. Values of every column whos name starts with $mask will be transferred to the meta section of the bean under key 'data.bundle'.
public convertToBeans ( string $type, array $rows, string $mask = NULL ) : array
$type string type of beans you would like to have
$rows array rows from the database result
$mask string meta mask to apply (optional)
return array
    public function convertToBeans($type, $rows, $mask = NULL)
    {
        $masklen = 0;
        if ($mask !== NULL) {
            $masklen = mb_strlen($mask);
        }
        $collection = array();
        $this->stash[$this->nesting] = array();
        foreach ($rows as $row) {
            $meta = array();
            if (!is_null($mask)) {
                foreach ($row as $key => $value) {
                    if (strpos($key, $mask) === 0) {
                        unset($row[$key]);
                        $meta[$key] = $value;
                    }
                }
            }
            $id = $row['id'];
            $this->stash[$this->nesting][$id] = $row;
            $collection[$id] = $this->load($type, $id);
            if ($mask !== NULL) {
                $collection[$id]->setMeta('data.bundle', $meta);
            }
        }
        $this->stash[$this->nesting] = NULL;
        return $collection;
    }

Usage Example

示例#1
0
 /**
  * Returns the next bean in the collection.
  * If called the first time, this will return the first bean in the collection.
  * If there are no more beans left in the collection, this method
  * will return NULL.
  *
  * @return OODBBean|NULL
  */
 public function next()
 {
     $row = $this->cursor->getNextItem();
     if ($row) {
         $beans = $this->repository->convertToBeans($this->type, array($row));
         $bean = array_shift($beans);
         return $bean;
     }
     return NULL;
 }
All Usage Examples Of RedBeanPHP\Repository::convertToBeans