get schema for an array of models

@param string        $modelName name of model
@param DocumentModel $model     model

@return Schema
178466
public function getCollectionSchema($modelName, DocumentModel $model)
    {
        $collectionSchema = new Schema;
        $collectionSchema->setTitle(sprintf('Array of %s objects', $modelName));
        $collectionSchema->setType('array');
        $collectionSchema->setItems($this->getModelSchema($modelName, $model));
        return $collectionSchema;
    }
93386
public function create(Model $model) : Model
    {
        return $model->load(['attachment', 'tags', 'taxonomies'])
            ->setAttribute('category', $model->taxonomies->map(function ($item) {
                return $item->id;
            })->toArray());
    }
262330
protected function getModelNamespace($modelName, $modelDirectory)
    {
        if (!empty($modelDirectory)) {
            $modelDirectory = str_finish($modelDirectory, '\\');
        }

        $namespace = Helpers::getAppNamespace() . ltrim(Config::getModelsPath($modelDirectory . $modelName), '\\');

        return rtrim(Helpers::convertSlashToBackslash($namespace), '\\');
    }
176384
protected function getModelPath($modelName)
    {
        $inputName = explode('/', ucfirst($modelName));
        array_pop($inputName);

        return implode('/', $inputName);
    }
905979
public function getIncludes($modelName) {
		if ($this->models->has($modelName)
				&& $this->models->get($modelName)->has('includes')) {
			return $this->models->get($modelName)->get('includes');
		}
		return new ArrayList();
	}
310953
public function findBy($modelName, $param = [])
    {
        if (!class_exists($modelName, true)) {
            return new \SplObjectStorage();
        }

        $configuration  = $this->getModelConfiguration($modelName);
        $collection     = $this->getCollectionBy($configuration);

        $resultSet  = $collection->find($param);
        $result     = new \SplObjectStorage();
        // clone is much faster than new
        if (!$this->modelPrototypeStorage[$modelName]) {
            $this->modelTemplateStorage[$modelName] = new $modelName();
        }

        foreach ($resultSet as $data) {
            $nModel = $this->fillModel(
                clone $this->modelTemplateStorage[$modelName],
                $data
            );
            $result->attach($nModel);
        }

        return $result;
    }
82048
public function makeModel($modelName = null)
  {
    $modelName = ucwords($_POST['command']);

    $this->$modelName = $modelName;

    if (file_exists("App/Models/{$this->$modelName}.php")) {
      $this->errors[] = "The model {$this->$modelName} already exists!";
    } elseif (strripos($this->$modelName, '_') == 0) {
      $this->$modelName = ucwords(str_replace('_', '', $this->$modelName));
    }

    if (!empty($this->errors)) {
      echo array_shift($this->errors);
    } else {
      $newModelTemplate = file_get_contents(__DIR__ . '/templates/makeModel.txt');
      $newModel = str_replace('ModelName', $this->$modelName, $newModelTemplate);
      file_put_contents("App/Models/{$this->$modelName}.php", $newModel);
    }

  }
884476
public function createDocumentTableFor($documentName)
    {
        $class = $this->dm->getClassMetadata($documentName);

        if ($class->isMappedSuperclass || $class->isEmbeddedDocument) {
            throw ODMException::cannotCreateMappedSuperclassTable($documentName);
        }

        $this->doCreateTable($class->getTableName(), $class->getDefinitionTable());
    }
927063
public function addConstraints($fieldName, Schema $property, DocumentModel $model)
    {
        $constraints = $model->getConstraints($fieldName);

        if (!is_array($constraints)) {
            return $property;
        }

        foreach ($constraints as $constraint) {
            $isSupported = false;
            foreach ($this->builders as $builder) {
                if ($builder->supportsConstraint($constraint->name, $constraint->options)) {
                    $property = $builder->buildConstraint($fieldName, $property, $model, $constraint->options);
                    $isSupported = true;
                }
            }

            if (!$isSupported) {
                /**
                 * unknown/not supported constraints will be added to the 'x-constraints' schema property.
                 * this allows others (possibly schema constraints) to pick it up and implement more advanced logic.
                 */
                 $property->addConstraint($constraint->name);
            }
        }

        return $property;
    }
105523
protected function getModelClass(string $argumentName = 'model'): string
    {
        $model = $this->directiveArgValue($argumentName);

        // Fallback to using information from the schema definition as the model name
        if (! $model) {
            if ($this->definitionNode instanceof FieldDefinitionNode) {
                $model = ASTHelper::getUnderlyingTypeName($this->definitionNode);
            } elseif ($this->definitionNode instanceof ObjectTypeDefinitionNode) {
                $model = $this->definitionNode->name->value;
            }
        }

        if (! $model) {
            throw new DirectiveException(
                "A `model` argument must be assigned to the '{$this->name()}'directive on '{$this->definitionNode->name->value}"
            );
        }

        return $this->namespaceModelClass($model);
    }
1364319
public function buildConstraint($fieldName, Schema $property, DocumentModel $model, array $options)
    {
        if (in_array('array', $property->getType()->getTypes())) {
            foreach ($options as $option) {
                if ($option->name == 'min') {
                    $property->setMinItems(intval($option->value));
                }
                if ($option->name == 'max') {
                    $property->setMaxItems(intval($option->value));
                }
            }
        }

        return $property;
    }
564682
protected function _getSchemaCache($modelName = null) {
		if (empty($modelName)) {
			return null;
		}

		$modelName = (string)$modelName;
		if (!isset($this->_schemaCache[$modelName])) {
			return null;
		}

		return $this->_schemaCache[$modelName];
	}
1331648
public function setModelName($modelName)
    {
        if (0 === strpos($modelName, '\\')) {
            $this->modelName = substr($modelName, 1);
        } else {
            $this->modelName = $modelName;
        }
        if ($this->modelName && !$this->modelTableMapName) {
            $this->modelTableMapName = constant($this->modelName . '::TABLE_MAP');
        }
        if (!$this->tableMap && $this->modelName) {
            $this->tableMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName())->getTableByPhpName($this->modelName);
        }

        return $this;
    }
1178796
public function setSchemaName($schemaName)
    {
        if (trim($schemaName) == '') {
            $schemaName = null;
        }
        $this->schemaName = $schemaName;

        return $this;
    }
508121
protected function prepareDocument($document, SVMModel $model)
    {
        $tokenMap = $model->getTokenMap();

        $data = array();

        if ($this->documentNormalizer) {
            $document = $this->documentNormalizer->normalize($document);
        }

        $tokens = $this->tokenizer->tokenize($document);

        if ($this->tokenNormalizer) {
            $tokens = $this->tokenNormalizer->normalize($tokens);
        }

        $tokenCounts = array_count_values($tokens);

        foreach ($tokenCounts as $token => $value) {
            if (isset($tokenMap[$token])) {
                $data[$tokenMap[$token]] = $value;
            }
        }

        ksort($data, SORT_NUMERIC);

        return $data;
    }
686105
public static function iterate(Mongo_Document $document, $name, $model = false)
  {
    if (is_bool($model)) $model = get_called_class();
    else if (is_object($model)) $model = get_class($model);

    $value = $document->get($name);
    if (!is_array($value) && !($value instanceof Iterator)) throw new MongoException();

    $result = array();
    foreach ($value as $key => $v)
    {
      $sub = new $model($document, $name . '.' . $key);
      $result[$key] = $sub;
    }
    return $result;
  }
362219
public function getModelConfiguration($objectName)
    {
        if (isset($this->configuration[$objectName])) {
            $modelConfiguration = $this->configuration[$objectName];
            $modelConfiguration['__object_name'] = $objectName;
            if (isset($modelConfiguration['fields']) === false) {
                $modelConfiguration['fields'] = array();
            }

            return $modelConfiguration;
        }
    }