public function getObjectList($selector, $className = '\Sokil\Mongo\Structure')
    {
        $data = $this->get($selector);
        if (!$data || !is_array($data)) {
            return array();
        }

        // class name is string
        if (is_string($className)) {
            $list = array_map(
                function ($dataItem) use ($className) {
                    $listItemStructure = new $className();
                    if (!($listItemStructure instanceof Structure)) {
                        throw new Exception('Wrong structure class specified');
                    }
                    $listItemStructure->mergeUnmodified($dataItem);
                    return $listItemStructure;
                },
                $data
            );

            return $list;
        }

        // class name id callable
        if (is_callable($className)) {
            return array_map(function ($dataItem) use ($className) {
                $classNameString = $className($dataItem);
                $listItemStructure = new $classNameString;
                if (!($listItemStructure instanceof Structure)) {
                    throw new Exception('Wrong structure class specified');
                }

                return $listItemStructure->merge($dataItem);
            }, $data);
        }

        throw new Exception('Wrong class name specified. Use string or closure');
    }
public function getObjectList($selector, $className = '\Sokil\Mongo\Structure')
    {
        $data = $this->get($selector);
        if (!$data || !is_array($data)) {
            return array();
        }

        // class name is string
        if (is_string($className)) {
            $list = array_map(
                function ($dataItem) use ($className) {
                    $listItemStructure = new $className();
                    if (!($listItemStructure instanceof Structure)) {
                        throw new Exception('Wrong structure class specified');
                    }
                    $listItemStructure->mergeUnmodified($dataItem);
                    return $listItemStructure;
                },
                $data
            );

            return $list;
        }

        // class name id callable
        if (is_callable($className)) {
            return array_map(function ($dataItem) use ($className) {
                $classNameString = $className($dataItem);
                $listItemStructure = new $classNameString;
                if (!($listItemStructure instanceof Structure)) {
                    throw new Exception('Wrong structure class specified');
                }

                return $listItemStructure->merge($dataItem);
            }, $data);
        }

        throw new Exception('Wrong class name specified. Use string or closure');
    }
public function getObjectList ( $ selector , $ className = '\Sokil\Mongo\Structure' ) { $ data = $ this -> get ( $ selector ) ; if ( ! $ data || ! is_array ( $ data ) ) { return array ( ) ; } // class name is string if ( is_string ( $ className ) ) { $ list = array_map ( function ( $ dataItem ) use ( $ className ) { $ listItemStructure = new $ className ( ) ; if ( ! ( $ listItemStructure instanceof Structure ) ) { throw new Exception ( 'Wrong structure class specified' ) ; } $ listItemStructure -> mergeUnmodified ( $ dataItem ) ; return $ listItemStructure ; } , $ data ) ; return $ list ; } // class name id callable if ( is_callable ( $ className ) ) { return array_map ( function ( $ dataItem ) use ( $ className ) { $ classNameString = $ className ( $ dataItem ) ; $ listItemStructure = new $ classNameString ; if ( ! ( $ listItemStructure instanceof Structure ) ) { throw new Exception ( 'Wrong structure class specified' ) ; } return $ listItemStructure -> merge ( $ dataItem ) ; } , $ data ) ; } throw new Exception ( 'Wrong class name specified. Use string or closure' ) ; }
Get list of structure objects from list of values in mongo document

@param string $selector
@param string|callable $className Structure class name or closure, which accept data and return string class name of Structure

@return object|array representation of document with class, passed as argument

@throws \Sokil\Mongo\Exception
Get list of structure objects from list of values in mongo document