예제 #1
0
파일: tools.php 프로젝트: evilgeny/bob
/**
 *	Returns first element of Iterator or default value if Iterator is empty.
 *	Parameter $factory allows to apply factory to returned element.
 *
 *	@param		iterator	Traversable			Iterator
 *	@param		factory		RM_Store_iFactory	Optional factory (performance hack)
 *	@param		default		mixed				Value to return if iterator is empty (default is RM_Base_NullObject)
 *	@return		mixed
 */
function iterFirst($iterator, RM_Store_iFactory $factory = NULL, $default = NULL)
{
    foreach ($iterator as $data) {
        return $factory ? $factory->create($data) : $data;
    }
    return $default === NULL ? M('Base')->null() : $default;
}
예제 #2
0
 public function createByProps($data = NULL)
 {
     $object = $this->_factory->createByProps($data);
     if (!$object->{$this->_guidProp}) {
         $object->{$this->_guidProp} = M('Guid')->get($this->_guidType);
     }
     return $object;
 }
예제 #3
0
 public function createByProps($data = NULL)
 {
     return new RM_TextFilter_ObjectDecorator($this->_factory->createByProps($data), $this->_config, $this->_default);
 }
예제 #4
0
 public function current()
 {
     return $this->_factory->create($this->_iter->current());
 }