Horde_Rdo_Mapper::map PHP Method

map() public method

Create an instance of $this->_classname from a set of data.
public map ( array $fields = [] ) : Horde_Rdo_Base
$fields array Field names/default values for the new object.
return Horde_Rdo_Base An instance of $this->_classname with $fields as initial data.
    public function map($fields = array())
    {
        // Guess a classname if one isn't explicitly set.
        if (!$this->_classname) {
            $this->_classname = $this->mapperToEntity();
            if (!$this->_classname) {
                throw new Horde_Rdo_Exception('Unable to find an entity class (extending Horde_Rdo_Base) for ' . get_class($this));
            }
        }
        $o = new $this->_classname();
        $o->setMapper($this);
        $this->mapFields($o, $fields);
        if (is_callable(array($o, 'afterMap'))) {
            $o->afterMap();
        }
        return $o;
    }

Usage Example

Example #1
0
 /**
  * Implementation of the next() method.
  *
  * @return Horde_Rdo_Base|null The next Rdo object in the set or
  * null if no more results.
  */
 public function next()
 {
     if (is_null($this->_result)) {
         $this->rewind();
     }
     if ($this->_result) {
         $row = $this->_result->fetch();
         if (!$row) {
             $this->_eof = true;
         } else {
             $this->_eof = false;
             if (is_null($this->_index)) {
                 $this->_index = 0;
             } else {
                 ++$this->_index;
             }
             $this->_current = $this->_mapper->map($row);
         }
     }
     return $this->_current;
 }