Create a Swagger model definition

@param array $model
@param string location where parameters will be found in request or response

@return Parameter model resolved against service description but not added

@throws \Exception
962833
private function createModel(array $model, $location)
    {
        $name = null;
        if (isset($model['id']) === true) {
            // if model id is set, us it as a name
            $name = trim($model['id']);
        } elseif (isset($model['nickname'], $this->responseClasses[$model['nickname']])) {
            // if custom response class is defined with model nickname, use nickname
            $name = $model['nickname'];
        } elseif (isset($model['type']) === true && $model['type'] === 'array') {
            // if model is of array type
            if (isset($model['items']['$ref']) === true) {
                // E. g. if it's an array of 'Tag' models, call this model 'TagList'.
                $name = $model['items']['$ref'].'List';
            } elseif (isset($model['nickname']) === true) {
                // Fallback generate name from operation nickname (e.g. getTags -> TagList)
                $found = preg_match('/[A-Z]/', $model['nickname'], $matches, PREG_OFFSET_CAPTURE);
                if ($found === 1) {
                    $name = rtrim(substr($model['nickname'], $matches[0][1]), 's').'List';
                }
            }
        }
        // if none of above worked to create a model name, hash model array
        if ($name === null) {
            $name = $model['id'] = 'anon_'.self::hashArray($model);
        }

        // a model is basically a parameter, but has name property added
        $defaults = [
            'name' => $name,
            'type' => 'object',
        ];
        /** @noinspection AdditionOperationOnArraysInspection */
        $data = $this->transformSchema($model + $defaults);
        if ('object' === $data['type']) {
            $data['additionalProperties'] = false;
            // model must have top level properties specified as serialized response type, but no response type itself
            foreach ($data['properties'] as $key => $property) {
                $data['properties'][$key]['location'] = $location;
            }
        } elseif ('array' === $data['type']) {
            $data['location'] = $location;
        }

        // allow result class override
        if (isset($this->responseClasses[$name])) {
            $class = $this->responseClasses[$name];
            $data['class'] = $class;

            if (is_subclass_of($class, ResultInterface::class)) {
                $data['type'] = 'object';
                if (is_array($data['additionalProperties']) === false) {
                    $data['additionalProperties'] = [];
                }
                $data['additionalProperties']['location'] = $location;
            } else {
                $data['type'] = 'class';
            }
        }

        // required makes no sense at root of model
        unset($data['required']);

        return new Parameter($data, ['description' => $this->getServiceDescription()]);
    }
1117937
protected function createRepository(
        ReflectionClass $model,
        $fileName,
        $shortName,
        $namespace,
        $contractName,
        $contractNamespace,
        array $methods
    ) {
        $path = app_path($fileName);

        $stub = $this->compileStub('repository.stub', [
            'namespace'          => $namespace,
            'class'              => $shortName,
            'model.fullname'     => $model->getName(),
            'model'              => $model->getShortName(),
            'implementation'     => $this->getImplementationClass($contractName),
            'implementation.use' => $this->getImplementationUse($contractNamespace, $contractName),
        ]);

        $stub = $this->compileMethods($stub, $methods);

        $this->files->makeDirectory(dirname($path), 0755, true, true);

        $this->files->put($path, $stub);

        return $namespace . '\\' . $shortName;
    }
244141
public static function modelName($project, $location, $model)
    {
        return self::getModelNameTemplate()->render([
            'project' => $project,
            'location' => $location,
            'model' => $model,
        ]);
    }
857291
public function create(Model $model)
    {
        $metadata = $model->getMetadata();
        $insert = $this->createInsertObj($model);
        $this->getQuery()->executeInsert($metadata, $insert);
        return $model;
    }
546101
public static function create_declared_model(array $definition): \core_analytics\model {

        list($target, $indicators) = static::get_declared_target_and_indicators_instances($definition);

        if (isset($definition['timesplitting'])) {
            $timesplitting = $definition['timesplitting'];
        } else {
            $timesplitting = false;
        }

        $created = \core_analytics\model::create($target, $indicators, $timesplitting);

        if (!empty($definition['enabled'])) {
            $created->enable();
        }

        return $created;
    }
471074
public function url ($model)
        {
            $this->url = implode ('/', array_merge ($this->sefFolder, [$model]));

            return $this;
        }
1247765
public function handlePostDefault(Request $request, $model)
    {
        $values = $this->parseRequestContent($request->content, $model->getResourceType());
        $this->validateModelData($model, $values);

        $model->fill($values);

        if (!$model->save()) {
            throw new Exception(
                'An unknown error occurred',
                static::ERROR_SCOPE | static::ERROR_UNKNOWN,
                BaseResponse::HTTP_INTERNAL_SERVER_ERROR
            );
        }

        return $model;
    }
382064
private function addModelToArray($models, $model)
    {
        $apply_to_models = array();
        
        if (count($models) > 0) {
            foreach ($models as $item_json) {
                $item = json_decode($item_json);
                $object = $model->find($item->id);
                if ($object != null) {
                    for ($count = 1; $count <= $item->quantity; $count++) {
                        $apply_to_models[] = $object;
                    }
                }
            }
        }
        
        return $apply_to_models;
    }
1278204
public function getModel($model = null)
    {
        $model          = $model ?? $this->model ?? $this->serviceAlias;
        $sl             = $this->getServiceLocator();
        $modelManager   = $sl->get(ModelManager::class);
        $model          = $modelManager->get($model);

        return $model;
    }
490319
protected function createQuery($model)
    {
        $query = $model::find();
        if (empty($query->from)) {
            // required by the query authorizer behavior and when model implements ActiveSearchInterface
            $query->from = ['t' => $model->tableName()];
        }
        return $query;
    }
702775
protected function resolveQueryBuilderFromModel($model)
    {
        if ($this->isEloquentModel($model)) {
            return $model->newQuery();
        } elseif ($this->isEloquentRelationModel($model)) {
            return $model->getQuery();
        } elseif (! $this->isQueryBuilder($model)) {
            throw new InvalidArgumentException('Unable to load Query Builder from $model');
        }

        return $model;
    }
3335
private function doCommitCreate(Model $model)
    {
        $this->dispatchLifecycleEvent(Events::preCreate, $model);

        $this->getPersisterFor($model->getType())->create($model);
        $model->getState()->setNew(false);
        // Should the model always reload? Or should the commit be assumed correct and just clear the new/dirty state?
        $model->reload();

        $this->dispatchLifecycleEvent(Events::postCreate, $model);
        return $model;
    }
1336291
public function add($model)
    {
        if (is_array($model)) {
            $this->collection[] = new MarketModel($model);
        } elseif ($model instanceof MarketModel) {
            $this->collection[] = $model;
        }

        return $this;
    }
792012
public function getIdentifierMade($model)
    {
        if (!is_object($model)) {
            throw new \InvalidArgumentException(sprintf('You must give a object, "%s" given.', gettype($model)));
        }

        $methodMadeBy = 'get' . ucfirst($this->definition->getMadeBy());
        if (!method_exists($model, $methodMadeBy)) {
            throw new \RuntimeException(sprintf('Model "%s" must have method "%s".', get_class($model), $methodMadeBy));
        }

        $modelMade = $model->$methodMadeBy();
        if (!is_object($modelMade)) {
            throw new \RuntimeException(sprintf('Model "%s::%s()" must already return object, "%s" given.', get_class($model), $methodMadeBy, gettype($modelMade)));
        }

        $methodMadeField = 'get' . ucfirst($this->definition->getMadeField());
        if (!method_exists($model->{'get'.$this->definition->getMadeBy()}(), $modelMade)) {
            throw new \RuntimeException(sprintf('Model "%s" must have method "%s".', get_class($modelMade), $methodMadeField));
        }

        return $model->{'get'.ucfirst($this->definition->getMadeBy())}()->{'get'.ucfirst($this->definition->getMadeField())}();
    }
530244
public function getModel($model) {
        $this->_normalizeModel($model);
        $langSuffix = ucfirst(strtolower($this->_language));
        // Sanity check: is the model already localized?
        if ($this->_modelIsLocalized($model)) {
            throw new Garp_I18n_ModelFactory_Exception_ModelAlreadyLocalized(
                "Looks like model $model is already internationalized."
            );
        }
        $modelName = $model.$langSuffix;
        $model = new $modelName();
        return $model;
    }
1193436
public function creating(Model $model)
    {
        // we only create this once
        if (Schema::hasColumn($model->getTable(), 'hashslug') && is_null($model->hashslug)) {
            $timestamp       = time() + $model->count() + 1;
            $str_slug_fqcn   = str_slug_fqcn($model);
            $model->hashslug = hashids($str_slug_fqcn)->encode($timestamp);
        }
    }
1086565
public function setModel($model)
    {
        // in case of Agile Data model - don't add it to object.
        // Agile Data Model owner is Agile Data Persistance and so be it.
        if ($model instanceof \atk4\data\Model) {
            return $this->model = $model;
        }

        $model = $this->app->normalizeClassName($model, 'Model');
        $this->model = $this->add($model);

        return $this->model;
    }