Builds an object from the provided data.

@param array|object $document the attributes that will be used to compose the entity
@param Schema       $schema   schema that will be used to map each field

@return mixed
768526
public function assemble($document, Schema $schema)
    {
        $entityClass = $schema->entityClass;
        $model = Ioc::make($entityClass);

        foreach ($document as $field => $value) {
            $fieldType = $schema->fields[$field] ?? null;

            if ($fieldType && 'schema.' == substr($fieldType, 0, 7)) {
                $value = $this->assembleDocumentsRecursively($value, substr($fieldType, 7));
            }

            $model->$field = $value;
        }

        $entity = $this->morphingTime($model);

        return $this->prepareOriginalAttributes($entity);
    }
99846
public function addSchema(SchemaInterface $schema): SchemaBuilder
    {
        $this->schemas[$schema->getClass()] = $schema;

        return $this;
    }
784359
protected function add_additional_fields_schema( $schema ) {
		if ( empty( $schema['title'] ) ) {
			return $schema;
		}

		/**
		 * Can't use $this->get_object_type otherwise we cause an inf loop.
		 */
		$object_type = $schema['title'];

		$additional_fields = $this->get_additional_fields( $object_type );

		foreach ( $additional_fields as $field_name => $field_options ) {
			if ( ! $field_options['schema'] ) {
				continue;
			}

			$schema['properties'][ $field_name ] = $field_options['schema'];
		}

		return $schema;
	}
472406
public function schema($schema = null) {
        if (!func_num_args()) {
            return $this->_schema;
        }
        $this->_schema = $schema;
        return $this;
    }
452522
public function visitSchema(Schema $schema)
    {
        return new Schema(
            $this->transformConstraintArray($schema->constraints()),
            $schema->defaultValue(),
            $schema->title(),
            $schema->description()
        );
    }
803946
public static function execute(Schema $schema, $root, Document $ast, $operation = NULL, array $args = NULL)
    {
        if (!self::$UNDEFINED) {
            self::$UNDEFINED = new \stdClass();
        }

        try {
            $errors = new \ArrayObject();
            $context = self::buildExecutionContext($schema, $root, $ast, $operation, $args, $errors);
            $data = self::executeOperation($context, $root, $context->operation);
        } catch (\Exception $e) {
            $errors[] = $e;
        }

        $result = ['data' => isset($data) ? $data : NULL];
        if (count($errors) > 0) {
            $result['errors'] = $errors->getArrayCopy();
        }

        return $result;
    }
434041
public function generate($document, ClassMetadata $class, DocumentManagerInterface $dm, $parent = null)
    {
        if (null === $parent) {
            $parent = $class->parentMapping ? $class->getFieldValue($document, $class->parentMapping) : null;
        }

        $name = $class->nodename ? $class->getFieldValue($document, $class->nodename) : null;
        $id = $class->getFieldValue($document, $class->identifier);

        if (empty($id)) {
            if (empty($name) && empty($parent)) {
                throw IdException::noIdentificationParameters($document, $class->parentMapping, $class->nodename);
            }

            if (empty($parent)) {
                throw IdException::noIdNoParent($document, $class->parentMapping);
            }

            if (empty($name)) {
                throw IdException::noIdNoName($document, $class->nodename);
            }
        }

        // use assigned ID by default
        if (empty($parent) || empty($name)) {
            return $id;
        }

        if ($exception = $class->isValidNodename($name)) {
            throw IdException::illegalName($document, $class->nodename, $name);
        }

        // determine ID based on the path and the node name
        return $this->buildName($document, $class, $dm, $parent, $name);
    }
646484
public function addObject($object, Document $doc = null)
    {
        if (!isset($this->_serializer)) {
            throw new RuntimeException('No serializer defined');
        }

        $data = \call_user_func($this->_serializer, $object);
        if (!$doc) {
            $doc = new Document();
        }
        $doc->setData($data);

        return $this->addDocument($doc);
    }
972653
public function setSchema($schema)
    {
        $schema = func_get_args();
        
        $schema = "'".implode("','", $schema)."'";
        
        $query = $this->getUtilityQuery()->setSchema($schema);
        $this->query($query);
        
        return $this;
    }
1357637
private static function cast(array $cfg, $schema=null){
    if ( \is_null($schema) && \is_object(static::$schema) ){
      $schema = static::$schema;
    }
    if ( \is_object($schema) && \is_array($cfg) && isset($schema->properties) ){
      foreach ( $schema->properties as $k => $p ){
        if ( empty($cfg[$k]) ){
          unset($cfg[$k]);
        }
        else if ( \is_object($p) ){
          if ( \is_string($cfg[$k]) && $p->type === 'integer' ){
            $cfg[$k] = (int)$cfg[$k];
          }
          else if ( \is_int($cfg[$k]) && $p->type === 'boolean' ){
            $cfg[$k] = (bool)$cfg[$k];
          }
          else if ( \is_array($cfg[$k]) ){
            $cfg[$k] = self::cast($cfg[$k], $p);
          }
        }
      }
    }
    return $cfg;
  }
1344175
public function generate($schema, $className, Context $context)
    {
        $files   = [];
        $classes = [];

        foreach ($schema->getClasses() as $class) {
            $methods   = [];
            $modelFqdn = $schema->getNamespace()."\\Model\\".$class->getName();
            $methods[] = $this->createSupportsDenormalizationMethod($modelFqdn);
            $methods[] = $this->createSupportsNormalizationMethod($modelFqdn);
            $methods[] = $this->createDenormalizeMethod($modelFqdn, $context, $class->getProperties());
            $methods[] = $this->createNormalizeMethod($modelFqdn, $context, $class->getProperties());

            $normalizerClass = $this->createNormalizerClass(
                $class->getName().'Normalizer',
                $methods
            );
            $classes[] = $normalizerClass->name;

            $namespace = new Stmt\Namespace_(new Name($schema->getNamespace()."\\Normalizer"), [
                new Stmt\Use_([new Stmt\UseUse(new Name('Joli\Jane\Runtime\Reference'))]),
                new Stmt\Use_([new Stmt\UseUse(new Name('Symfony\Component\Serializer\Exception\InvalidArgumentException'))]),
                new Stmt\Use_([new Stmt\UseUse(new Name('Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface'))]),
                new Stmt\Use_([new Stmt\UseUse(new Name('Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait'))]),
                new Stmt\Use_([new Stmt\UseUse(new Name('Symfony\Component\Serializer\Normalizer\DenormalizerInterface'))]),
                new Stmt\Use_([new Stmt\UseUse(new Name('Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface'))]),
                new Stmt\Use_([new Stmt\UseUse(new Name('Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait'))]),
                new Stmt\Use_([new Stmt\UseUse(new Name('Symfony\Component\Serializer\Normalizer\NormalizerInterface'))]),
                $normalizerClass
            ]);
            $files[]   = new File($schema->getDirectory().'/Normalizer/'.$class->getName().'Normalizer.php', $namespace, self::FILE_TYPE_NORMALIZER);
        }

        $files[] = new File(
            $schema->getDirectory().'/Normalizer/NormalizerFactory.php',
            new Stmt\Namespace_(new Name($schema->getNamespace()."\\Normalizer"), [
                $this->createNormalizerFactoryClass($classes)
            ]),
            self::FILE_TYPE_NORMALIZER
        );

        return $files;
    }
826414
public function convert(DOMDocument $document)
    {
        $xpath = new DOMXPath($document);
        $xpath->registerNamespace('docbook', 'http://docbook.org/ns/docbook');
        $xpathExpression = '//docbook:eztemplate | //docbook:eztemplateinline';

        $templates = $xpath->query($xpathExpression);
        /** @var \DOMElement[] $templatesSorted */
        $templatesSorted = array();
        $maxDepth = 0;

        foreach ($templates as $template) {
            $depth = $this->getNodeDepth($template);
            if ($depth > $maxDepth) {
                $maxDepth = $depth;
            }
            $templatesSorted[$depth][] = $template;
        }

        ksort($templatesSorted, SORT_NUMERIC);

        foreach ($templatesSorted as $templates) {
            foreach ($templates as $template) {
                $this->processTemplate($document, $template);
            }
        }

        return $document;
    }
440396
public function create($schema)
    {
        $types = array_map(function ($column) {
            return $column['name'] . ':' . $column['type'];
        }, $schema);

        return implode(', ', $types);
    }
277500
public function setSchema($schema)
    {
        $this->schema = $schema;
        $sessionVars  = [
            'CURRENT_SCHEMA' => $schema,
        ];

        return $this->setSessionVars($sessionVars);
    }
33761
public function generate($schema, $className, Context $context)
    {
        $files = [];

        foreach ($schema->getClasses() as $class) {
            $properties = [];
            $methods    = [];

            foreach ($class->getProperties() as $property) {
                $properties[] = $this->createProperty($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
                $methods[]    = $this->createGetter($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
                $methods[]    = $this->createSetter($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
            }

            $model = $this->createModel(
                $class->getName(),
                $properties,
                $methods
            );

            $namespace = new Stmt\Namespace_(new Name($schema->getNamespace()."\\Model"), [$model]);

            $files[] = new File($schema->getDirectory().'/Model/'.$class->getName().'.php', $namespace, self::FILE_TYPE_MODEL);
        }

        return $files;
    }
1222802
private function getQueryForDocument(object $document) : array
    {
        $id = $this->uow->getDocumentIdentifier($document);
        $id = $this->class->getDatabaseIdentifierValue($id);

        $shardKeyQueryPart = $this->getShardKeyQuery($document);
        return array_merge(['_id' => $id], $shardKeyQueryPart);
    }
986805
public function convert(DOMDocument $document)
    {
        foreach ($this->converters as $converter) {
            $converter->convert($document);
        }

        return $document;
    }