Sokil\Mongo\Structure::getObject PHP Метод

getObject() публичный Метод

Get structure object from a document's value
public getObject ( string $selector, string | callable $className = '\Sokil\Mongo\Structure' ) : object
$selector string
$className string | callable string class name or closure, which accept data and return string class name
Результат object representation of document with class, passed as argument
    public function getObject($selector, $className = '\\Sokil\\Mongo\\Structure')
    {
        $data = $this->get($selector);
        if (!$data) {
            return null;
        }
        // get class name from callable
        if (is_callable($className)) {
            $className = $className($data);
        }
        // prepare structure
        $structure = new $className();
        if (!$structure instanceof Structure) {
            throw new Exception('Wrong structure class specified');
        }
        return $structure->merge($data);
    }