Returns an array of objects of class $class from
the rows of a PDOStatement(query result)

@param PDOStatement $result
@param string $class_name name of class to create
@return static[]
767632
static function fromResult(PDOStatement $result, $class_name = null, $use_pool = null) {
		if (null === $class_name) {
			$class_name = get_called_class();
		}
		if (null === $use_pool) {
			$use_pool = static::$_poolEnabled;
		}

		$objects = array();
		if (is_array($class_name)) {
			$class_names = $class_name;
			unset($class_name);
			while ($values = $result->fetch(PDO::FETCH_NUM)) {
				unset($main_object);
				$startcol = 0;
				foreach ($class_names as $key => $class_name) {
					$object = new $class_name;
					if (!$object->fromNumericResultArray($values, $startcol)) {
						continue;
					}

					if (
						$use_pool
						&& ($pk = $object->getPrimaryKey())
						&& ($pool_object = $object->retrieveFromPool($object->{'get' . $pk}()))
					) {
						$object = $pool_object;
					}

					if ($use_pool) {
						$object->insertIntoPool($object);
					}

					if (!isset($main_object)) {
						$main_object = $objects[] = $object;
					} else {
						if (method_exists($main_object, 'set' . $class_name)) {
							$main_object->{'set' . $class_name}($object);
						} else {
							$main_object->{$class_name} = $object;
						}
					}
				}
			}
		} else {
			// PDO::FETCH_PROPS_LATE is required to call the ctor after hydrating the fields
			$flags = PDO::FETCH_CLASS;
			if (defined('PDO::FETCH_PROPS_LATE')) {
				$flags |= PDO::FETCH_PROPS_LATE;
			}
			$result->setFetchMode($flags, $class_name);
			while (false !== ($object = $result->fetch())) {
				if (
					$use_pool
					&& (!empty($pk) || ($pk = $object->getPrimaryKey()))
					&& ($pool_object = $object->retrieveFromPool($object->{'get' . $pk}()))
				) {
					$object = $pool_object;
				} else {
					$object->castInts();
					$object->setNew(false);
				}

				$objects[] = $object;

				if ($use_pool) {
					$object->insertIntoPool($object);
				}
			}
		}
		return $objects;
	}
881676
public function fetchAssocList(\PDOStatement $res, $assign_by = null)
    {
        $result = array();
        try {
            while ($row = $res->fetch(\PDO::FETCH_ASSOC)) {
                if (!empty($assign_by) && !is_array($assign_by)) {
                    $result[$row[$assign_by]] = (array)$row;
                } elseif (!empty($assign_by) && is_array($assign_by)) {
                    $key = array();
                    foreach ($assign_by as $key_w) {
                        if (isset($row[$key_w])) {
                            $key[] = $row[$key_w];
                        }
                    }

                    if (empty($key)) {
                        $result[] = (object)$row;
                    } else {
                        // removes the first '- '
                        $key          = implode('-', $key);
                        $result[$key] = (object)$row;
                    }
                } else {
                    $result[] = (array)$row;
                }
            }
        } catch (DatabaseException $e) {
            throw $e;
        }

        return $result;
    }
1162385
public function toRecords(string $recordClass): array
    {
        $array = [];
        foreach ($this->rows as $row) {
            /**
             * @var $row Row
             */
            $record = Record::instanceRecord($recordClass, $row->toArray());
            $record->setLoaded();
            $array[] = $record;
        }
        return $array;
    }
597379
public function fetchAllObj(string $class = null): array
    {
        if ($class == null && $this->modelClass !== null) {
            return parent::fetchAllObj($this->modelClass);
        } else {
            return parent::fetchAllObj($class);
        }
    }
1324858
protected function getResults(\stdClass $response, $type) : array
    {
        $result = [];
        if (!empty($this->auth['apiRequest'][$type])) {
            $result = UserFunction::build(
                $this->auth['apiRequest'][$type],
                [
                    'response' => \Keboola\Utils\objectToArray($response),
                    'attr' => $this->configAttributes
                ]
            );
            // for backward compatibility, check the values if they are a valid path within the response
            foreach ($result as $key => $value) {
                try {
                    $result[$key] = \Keboola\Utils\getDataFromPath($value, $response, '.', false);
                } catch (NoDataFoundException $e) {
                    // silently ignore invalid paths as they are probably values already processed by functions
                }
            }
        }
        return $result;
    }
315867
public function getActiveRecordObjects($class, $orderBy=NULL, $descOrder=FALSE) {

		if (!class_exists($class) or !is_subclass_of($class, 'Pair\ActiveRecord')) {
			return array();
		}
		
		// sets pagination count
		$this->db->setQuery('SELECT COUNT(*) FROM `' . $class::TABLE_NAME . '`');
		$this->pagination->count = $this->db->loadCount();
	
		$orderDir = $descOrder ? 'DESC' : 'ASC';
		
		$query =
			'SELECT *' .
			' FROM `' . $class::TABLE_NAME . '`' .
			($orderBy ? ' ORDER BY `' . $orderBy . '` ' . $orderDir : NULL) .
			' LIMIT ' . $this->pagination->start . ', ' . $this->pagination->limit;
	
		$this->db->setQuery($query);
		$list = $this->db->loadObjectList();
	
		$objects = array();
	
		foreach ($list as $item) {
			$objects[] = new $class($item);
		}

		return $objects;
	
	}
548407
public function getJavaClass(string $class_name): Interfaces\JavaClass
    {
        try {
            $class = $this->pjbProxyClient->getJavaClass($class_name);
        } catch (Pjb62BrokenConnectionException | Exception\InvalidUsageException $e) {
            PjbProxyClient::unregisterInstance();
            throw new BrokenConnectionException($e->getMessage(), $e->getCode(), $e);
        }

        return $class;
    }
122687
private function loadResults($my_std_class)
    {
        if(property_exists($my_std_class->table,'row'))
        {
            foreach ($my_std_class->table->row as $row)
            {
                $this->result->push($this->convertToStdClass($row));
            }
        }

    }
1180235
static function deserialize($class_name, $assoc_s)
    {
        $pairs = Auth_OpenID_KVForm::toArray($assoc_s, $strict = true);
        $keys = array();
        $values = array();
        foreach ($pairs as $key => $value) {
            if (is_array($value)) {
                list($key, $value) = $value;
            }
            $keys[] = $key;
            $values[] = $value;
        }

        $class_vars = get_class_vars($class_name);
        $class_assoc_keys = $class_vars['assoc_keys'];

        sort($keys);
        sort($class_assoc_keys);

        if ($keys != $class_assoc_keys) {
            trigger_error('Unexpected key values: ' . var_export($keys, true),
                          E_USER_WARNING);
            return null;
        }

        $version = $pairs['version'];
        $handle = $pairs['handle'];
        $secret = $pairs['secret'];
        $issued = $pairs['issued'];
        $lifetime = $pairs['lifetime'];
        $assoc_type = $pairs['assoc_type'];

        if ($version != '2') {
            trigger_error('Unknown version: ' . $version, E_USER_WARNING);
            return null;
        }

        $issued = intval($issued);
        $lifetime = intval($lifetime);
        $secret = base64_decode($secret);

        return new $class_name(
            $handle, $secret, $issued, $lifetime, $assoc_type);
    }
1137489
public function queryObjArray($query, $className, $options = array(), $classConstructorArguments = NULL)
    {
        if (!class_exists($className)) {
            $this->_error(FQDBException::CLASS_NOT_EXIST, FQDBException::FQDB_CODE);
        }

        return $this->queryArray($query, $options,
            function(\PDOStatement $statement) use ($className, $classConstructorArguments) {
                return $statement->fetchAll(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE,
                    $className, $classConstructorArguments);
            }
        );
    }
172060
public function makeArrayFromParameters($class_method, $parameterValues)
	{
	    if (empty($class_method))
	        return array();
	    
	    // Get the class name and the method name
	    list($className, $methodName) = explode('::', $class_method);
	    if (empty($className) || empty($methodName))
	        return array();
	    
	    /**
	     * Build an array from the parameters
	     * Parameters' name will become keys
	     * Values will be parameters' values or default values
	     */ 
	    $parametersArray = array();
	    try 
	    {
	        // Gets the data of class/method from Reflection object
    	    $reflectionMethod = new \ReflectionMethod($className, $methodName);
    	    $parameters = $reflectionMethod->getParameters();
    	    
    	    // Loop on parameters
    	    foreach ($parameters as $keyParameter => $parameter)
    	    {
    	        // Check if we have a value given
    	        if (!empty($parameterValues[$keyParameter]))
    	            $parametersArray[$parameter->getName()] = $parameterValues[$keyParameter];
    	            else
    	                // No value given, check if parameter has an optional value
    	                if ($parameter->isOptional())
    	                    $parametersArray[$parameter->getName()] = $parameter->getDefaultValue();
    	                    else
    	                        // Else
    	                        $parametersArray[$parameter->getName()] = null;
    	    }
	    }
	    catch (\Exception $e)
	    {
	        // Class or method were not found
	        return array();
	    }
	    
	    return $parametersArray;
	}
1091463
public function parse(RefClass $class)
    {
        $result = [];

        $annotations = $this->parseComment($class->docComment);
        foreach ($annotations as $annotation) {
            $annotation->originClass = $class->name;
            $result[]                = $annotation;
        }

        foreach ($class->constants as $constant) {
            foreach ($this->parseComment($constant->docComment) as $annotation) {
                $annotation->originClass    = $class->name;
                $annotation->originConstant = $constant->name;
                $result[]                   = $annotation;
            }
        }

        foreach ($class->properties as $property) {
            foreach ($this->parseComment($property->docComment) as $annotation) {
                $annotation->originClass    = $class->name;
                $annotation->originProperty = $property->name;
                $result[]                   = $annotation;
            }
        }

        foreach ($class->methods as $method) {
            foreach ($this->parseComment($method->docComment) as $annotation) {
                $annotation->originClass  = $class->name;
                $annotation->originMethod = $method->name;
                $result[]                 = $annotation;
            }
        }

        return $result;
    }
644658
private function _define_column_types(\PDOStatement $result)
    {
        $columns = array();
        $intTypes = array('int', 'integer', 'long', 'tiny', 'smallint', 'int4');

        try {
            for ($i = 0; $i < $result->columnCount(); ++$i) {
                $meta = $result->getColumnMeta($i);
                if ($meta && $meta['name'] != '[]') {
                    $metaType = strtolower($meta['native_type']);
                    $pdoType = $meta['pdo_type'];
                    if (in_array($pdoType, array(\PDO::PARAM_STR, \PDO::PARAM_LOB))) {
                        $metaType = 'string';
                    } elseif (in_array($metaType, $intTypes)) {
                        $metaType = 'integer';
                    } elseif ($pdoType === \PDO::PARAM_NULL) {
                        $metaType = 'null';
                    }
                    $columns[$meta['name']] = $metaType;
                }
            }
        } catch (\PDOException $e) {
        }

        return $columns;
    }
645337
private function createGetIteratorCallable(stdClass $result, Server $server)
    {
        // Inline results can be wrapped with an ArrayIterator
        if (isset($result->results) && is_array($result->results)) {
            $results = $result->results;

            return function() use ($results) {
                if (isset($this->options['typeMap'])) {
                    return new TypeMapArrayIterator($results, $this->options['typeMap']);
                }

                return new ArrayIterator($results);
            };
        }

        if (isset($result->result) && (is_string($result->result) || is_object($result->result))) {
            $options = isset($this->options['typeMap']) ? ['typeMap' => $this->options['typeMap']] : [];

            $find = is_string($result->result)
                ? new Find($this->databaseName, $result->result, [], $options)
                : new Find($result->result->db, $result->result->collection, [], $options);

            return function() use ($find, $server) {
                return $find->execute($server);
            };
        }

        throw new UnexpectedValueException('mapReduce command did not return inline results or an output collection');
    }
1180480
public function getFieldsByClass($className)
    {
        $result = [];

        foreach ($this->fields as $field) {
            if ($field instanceof $className ||
                get_class($field) == $className ||
                (new \ReflectionClass($field))->getShortName() == $className
            ) {
                $result[] = $field;
            }
        }

        return $result;
    }
204708
protected function collectionFromResult($result)
    {
        // If we have one result which is not an assoc array, make it the first element of an array for the
        // collectionFromResult function so we always return a collection from filter
        if ((bool) count(array_filter(array_keys($result), 'is_string'))) {
            $result = [$result];
        }

        $class = $this->class;
        $collection = [];

        foreach ($result as $r) {
            $collection[] = new $class($this->connection, $r);
        }

        return $collection;
    }
696664
public function getAnnotationsFromPropertyOrClass($annotation_class)
	{
		$annotations = $this->getAnnotations($annotation_class);

		if ( !$annotations ) {
			$annotations = $this->annotationManager->getClassAnnotations($this->getDataType(), $annotation_class);
		}

		return $annotations;
	}