src/DB/PDO/Table.php
protected function getFieldsFromResult( $result, $fields = array(), $strict = TRUE ){
		if( is_string( $fields ) )
			$fields	= strlen( trim( $fields ) ) ? array( trim( $fields ) ) : array();
		if( !is_array( $fields ) )
			throw new \InvalidArgumentException( 'Fields must be of array or string' );
		if( !$result ){
			if( $strict )
				throw new \Exception( 'Result is empty' );
			if( count( $fields ) === 1 )
				return NULL;
			return array();
		}
		if( !count( $fields ) )
			return $result;
		foreach( $fields as $field )
			if( !in_array( $field, $this->columns ) )
				throw new \InvalidArgumentException( 'Field "'.$field.'" is not an existing column' );

		if( count( $fields ) === 1 ){
			switch( $this->fetchMode ){
				case \PDO::FETCH_CLASS:
				case \PDO::FETCH_OBJ:
					if( !isset( $result->$field ) )
						throw new \DomainException( 'Field "'.$field.'" is not an column of result set' );
					return $result->$field;
				default:
					if( !isset( $result[$field] ) )
						throw new \DomainException( 'Field "'.$field.'" is not an column of result set' );
					return $result[$field];
			}
		}
		switch( $this->fetchMode ){
			case \PDO::FETCH_CLASS:
			case \PDO::FETCH_OBJ:
				$map	= (object) array();
				foreach( $fields as $field ){
					if( !isset( $result->$field ) )
						throw new \DomainException( 'Field "'.$field.'" is not an column of result set' );
					$map->$field	= $result->$field;
				}
				return $map;
			default:
				$list	= array();
				foreach( $fields as $field ){
					if( !isset( $result[$field] ) )
						throw new \DomainException( 'Field "'.$field.'" is not an column of result set' );
					$list[$field]	= $result[$field];
				}
				return $list;
		}
	}
protected function getFieldsFromResult( $result, $fields = array(), $strict = TRUE ){
		if( is_string( $fields ) )
			$fields	= strlen( trim( $fields ) ) ? array( trim( $fields ) ) : array();
		if( !is_array( $fields ) )
			throw new \InvalidArgumentException( 'Fields must be of array or string' );
		if( !$result ){
			if( $strict )
				throw new \Exception( 'Result is empty' );
			if( count( $fields ) === 1 )
				return NULL;
			return array();
		}
		if( !count( $fields ) )
			return $result;
		foreach( $fields as $field )
			if( !in_array( $field, $this->columns ) )
				throw new \InvalidArgumentException( 'Field "'.$field.'" is not an existing column' );

		if( count( $fields ) === 1 ){
			switch( $this->fetchMode ){
				case \PDO::FETCH_CLASS:
				case \PDO::FETCH_OBJ:
					if( !isset( $result->$field ) )
						throw new \DomainException( 'Field "'.$field.'" is not an column of result set' );
					return $result->$field;
				default:
					if( !isset( $result[$field] ) )
						throw new \DomainException( 'Field "'.$field.'" is not an column of result set' );
					return $result[$field];
			}
		}
		switch( $this->fetchMode ){
			case \PDO::FETCH_CLASS:
			case \PDO::FETCH_OBJ:
				$map	= (object) array();
				foreach( $fields as $field ){
					if( !isset( $result->$field ) )
						throw new \DomainException( 'Field "'.$field.'" is not an column of result set' );
					$map->$field	= $result->$field;
				}
				return $map;
			default:
				$list	= array();
				foreach( $fields as $field ){
					if( !isset( $result[$field] ) )
						throw new \DomainException( 'Field "'.$field.'" is not an column of result set' );
					$list[$field]	= $result[$field];
				}
				return $list;
		}
	}
protected function getFieldsFromResult ( $ result , $ fields = array ( ) , $ strict = TRUE ) { if ( is_string ( $ fields ) ) $ fields = strlen ( trim ( $ fields ) ) ? array ( trim ( $ fields ) ) : array ( ) ; if ( ! is_array ( $ fields ) ) throw new \ InvalidArgumentException ( 'Fields must be of array or string' ) ; if ( ! $ result ) { if ( $ strict ) throw new \ Exception ( 'Result is empty' ) ; if ( count ( $ fields ) === 1 ) return NULL ; return array ( ) ; } if ( ! count ( $ fields ) ) return $ result ; foreach ( $ fields as $ field ) if ( ! in_array ( $ field , $ this -> columns ) ) throw new \ InvalidArgumentException ( 'Field "' . $ field . '" is not an existing column' ) ; if ( count ( $ fields ) === 1 ) { switch ( $ this -> fetchMode ) { case \ PDO :: FETCH_CLASS : case \ PDO :: FETCH_OBJ : if ( ! isset ( $ result -> $ field ) ) throw new \ DomainException ( 'Field "' . $ field . '" is not an column of result set' ) ; return $ result -> $ field ; default : if ( ! isset ( $ result [ $ field ] ) ) throw new \ DomainException ( 'Field "' . $ field . '" is not an column of result set' ) ; return $ result [ $ field ] ; } } switch ( $ this -> fetchMode ) { case \ PDO :: FETCH_CLASS : case \ PDO :: FETCH_OBJ : $ map = ( object ) array ( ) ; foreach ( $ fields as $ field ) { if ( ! isset ( $ result -> $ field ) ) throw new \ DomainException ( 'Field "' . $ field . '" is not an column of result set' ) ; $ map -> $ field = $ result -> $ field ; } return $ map ; default : $ list = array ( ) ; foreach ( $ fields as $ field ) { if ( ! isset ( $ result [ $ field ] ) ) throw new \ DomainException ( 'Field "' . $ field . '" is not an column of result set' ) ; $ list [ $ field ] = $ result [ $ field ] ; } return $ list ; } }
Returns any fields or one field from a query result.
@access		protected
@param		mixed			$result			Query result as array or object
@param		array|string	$fields			List of fields or one field
@param		boolean			$strict			Flag: throw exception if result is empty
@return		string|array|object			Structure depending on result and field list length
@throws		InvalidArgumentException			If given fields list is neither a list nor a string
Returns any fields or one field from a query result .