Create a tag for relation window toggler with directive crudLoader based on a ngrest model class.

@param string $ngrestModelClass
@return string The generated tag or null if permission does not exists
507303
public function createCrudLoaderTag($ngrestModelClass, $ngRestModelSelectMode = null, array $options = [])
    {
        $menu = Yii::$app->adminmenu->getApiDetail($ngrestModelClass::ngRestApiEndpoint(), Yii::$app->request->get('pool'));
        
        if ($menu) {
            if ($ngRestModelSelectMode) {
                $options['model-setter'] = $ngRestModelSelectMode;
                $options['model-selection'] = 1;
            } else {
                $options['model-selection'] = 0;
            }
            
            return $this->createTag('crud-loader', null, array_merge(['api' => $menu['route'], 'alias' => $menu['alias']], $options));
        }
        
        return null;
    }
159415
public function setModelClass($model_class): Repository
	{
		if ( !is_subclass_of($model_class, Model::class)) {
			throw new InvalidArgumentException('Specified model class must be an instance of ' . Model::class);
		}

		$this->model_class = $model_class;

		/** @var \Illuminate\Database\Eloquent\Model|\Fuzz\MagicBox\Contracts\MagicBoxResource $instance */
		$instance = new $model_class;

		// @todo use set methods
		$this->setFillable($instance->getRepositoryFillable());
		$this->setIncludable($instance->getRepositoryIncludable());
		$this->setFilterable($instance->getRepositoryFilterable());

		$this->key_name = $instance->getKeyName();

		return $this;
	}
414402
private function getBlockRendererForClass($blockClass)
    {
        if (!isset($this->renderers[$blockClass])) {
            return null;
        }

        return $this->renderers[$blockClass];
    }
420939
public function generateApiContent($fileNamespace, $className, $modelClass)
    {
        $alias = Inflector::humanize(Inflector::camel2words($className));
        return $this->view->render('@admin/commands/views/crud/create_api.php', [
            'namespace' => $fileNamespace,
            'className' => $className,
            'modelClass' =>  $modelClass,
            'luyaVersion' => $this->getGeneratorText('crud/create'),
            'alias' => $alias,
        ]);
    }
38228
public function getBindingModel($bindingModel) {
        $this->_normalizeModel($bindingModel);
        $bindingModel = new $bindingModel();

        $referenceMap = $bindingModel->getReferenceMapNormalized();
        foreach ($referenceMap as $rule => $reference) {
            // Check here wether we need to internationalize the refTableClass
            $refModel = new $reference['refTableClass'];
            if ($refModel->getObserver('Translatable')) {
                try {
                    $refModel = $this->getModel($reference['refTableClass']);
                } catch (Garp_I18n_ModelFactory_Exception_ModelAlreadyLocalized $e) {
                    continue;
                }
            }
            $refTableClass = get_class($refModel);
            $bindingModel->addReference(
                $rule,
                $reference['columns'],
                $refTableClass,
                $reference['refColumns']
            );
        }
        return $bindingModel;
    }
1030776
protected function getRelationNameFromJoinParams(AbstractNode $joinNode, ReflectionClass $reflectionNodeClass): ?string
    {
        //todo: refactoring
        $relationArgument = $joinNode->getFirstChildOfType('Arguments');
        $stringRelationArgument = $relationArgument->getFirstChildOfType('Literal');

        if ($stringRelationArgument !== null) {
            $relationArgumentName = trim($stringRelationArgument->getName(), '\'');

            if (!ctype_alpha($relationArgumentName)) {
                return null;
            }

            return $relationArgumentName;
        }

        $constRelationArgument = $relationArgument->getFirstChildOfType('ConstantPostfix');

        if ($constRelationArgument !== null) {
            return $reflectionNodeClass->getConstant($constRelationArgument->getName());
        }

        return null;
    }
1191757
protected Tag getControllerTag(Class<? extends Controller> controllerClass) {
        if (controllerClass.isAnnotationPresent(ApiOperations.class)) {
            ApiOperations annotation = controllerClass.getAnnotation(ApiOperations.class);
            io.swagger.models.Tag tag = new io.swagger.models.Tag();
            tag.setName(Optional.fromNullable(Strings.emptyToNull(annotation.tag())).or(controllerClass.getSimpleName()));
            tag.setDescription(translate(annotation.descriptionKey(), annotation.description()));

            if (!Strings.isNullOrEmpty(annotation.externalDocs())) {
                ExternalDocs docs = new ExternalDocs();
                docs.setUrl(annotation.externalDocs());
                tag.setExternalDocs(docs);
            }

            if (!Strings.isNullOrEmpty(tag.getDescription())) {
                return tag;
            }
        }
        return null;
    }
1139874
protected function buildUrl(AbstractModel $subject, AbstractModel $parent = null, $appendUrl = null, $docType = null)
    {
        if (is_null($docType)) {
            $docType = substr($this->mapper->getContentType(), strpos($this->mapper->getContentType(), '/') + 1);
        }

        $url = $this->baseUri;
        if (!is_null($parent) && intval($parent->getId()) > 0) {
            $url .= '/' . $this->mapTypeName($parent) . '/' . $parent->getId();
        }
        $url .= '/' . $this->mapTypeName($subject);
        if (intval($subject->getId()) > 0) {
            $url .= '/' . $subject->getId();
        }
        if (!is_null($appendUrl)) {
            $url .= $appendUrl;
        }
        return $url . '.' . $docType;
    }
21282
protected function makeModelDisplayValueFromModelClass($modelClass)
    {
        $stripPrefix = config('cms-models.collector.models-namespace');

        if ($stripPrefix && starts_with($modelClass, $stripPrefix)) {
            $modelClass = trim(substr($modelClass, 0, strlen($stripPrefix)), '\\');
        }

        return ucfirst(str_replace('\\', ' ', $modelClass));
    }
421900
private function loadController($class)
    {
        $controller = new $class($this->currentControllerAliasConfig);
        if (!is_a($controller, '\\mpf\\web\\Controller')) {
            $this->critical('Controller `' . $class . '` must extend \\mpf\\web\\Controller!', array(
                'requestedController' => $this->request()->getController(),
                'requestedModule' => $this->request()->getModule()
            ));
            return null;
        }
        return $controller;
    }
1262601
public function getModel()
    {
        if ($this->_model === null) {
            $this->_model = Yii::createObject($this->modelClass);

            if (!$this->_model instanceof NgRestModelInterface) {
                throw new InvalidConfigException("The modelClass '$this->modelClass' must be an instance of NgRestModelInterface.");
            }
        }
    
        return $this->_model;
    }
697379
public function create()
  {
    $class = ClassGen::classGen(
      $this->entityName . 'Controller',
      $this->namespace,
      ['Phrest\API\Controllers\RESTController'],
      'RESTController'
    );

    foreach ($this->entityDefinition->requests as $requestMethod => $actions)
    {
      foreach ($actions as $actionName => $action)
      {
        if (empty($action))
        {
          continue;
        }

        $getParams = $this->generateGetParamsFromUrl($action->url);
        $postParams = $this->generatePostParams($action);

        $docblock = $this->createDocblockForMethod(
          $requestMethod,
          $action,
          $getParams,
          $postParams
        );

        $method = ClassGen::method($actionName, $getParams, 'public');
        $method->setDocBlock($docblock);

        $body = $this->createBodyForMethod($action);
        $method->setBody($body);

        $class->addMethodFromGenerator($method);
      }
    }

    foreach ($this->uses as $use)
    {
      $class->addUse($use);
    }

    return $class;
  }
477506
protected function getQueryBuilderForModelClass($modelClass)
    {
        if ( ! is_a($modelClass, Model::class, true)) {
            throw new UnexpectedValueException("{$modelClass} is not an Eloquent model.");
        }

        // If the targeted model is a CMS model, we can default back to its reference data
        // if not specifics are given, otherwise, a custom fallback reference must be used.
        if ($info = $this->getCmsModelInformation($modelClass)) {

            // Get model records, filtered as necessary
            $repository = $this->getModelRepositoryForInformation($info);

            /** @var Model[] $models */
            return $repository->query();
        }

        // The model is not part of the CMS
        return $this->getQueryBuilderForNonCmsModelClass($modelClass);
    }
312107
public function findFileForClass(\ReflectionClass $class, $extension)
    {
        /** @var ResourceBinding $binding */
        foreach ($this->discovery->findBindings('jms/serializer-metadata') as $binding) {
            $prefix = $binding->getParameterValue('namespace-prefix');
            if ($binding->getParameterValue('extension') !== $extension
                || ('' !== $prefix && 0 !== strpos($class->getNamespaceName(), $prefix))
            ) {
                continue;
            }

            $len = 0;
            if ('' !== $prefix) {
                $len = strlen($prefix) + 1;
            }

            $basePath = Glob::getBasePath($binding->getQuery());
            $path = $basePath . '/' . str_replace('\\', '.', substr($class->name, $len)) . '.' . $extension;
            if (($key = array_search($path, $binding->getResources()->getPaths(), true)) !== false) {
                return $binding->getResources()->get($key)->getFilesystemPath();
            }
        }

        return null;
    }
447826
public function getDocBlockTag() {
    $doc_comment = $this->getFunction()->getDocComment();
    return $doc_comment ? $doc_comment->getParameter($this->name->getText()) : NULL;
  }
27749
public function getNgRestConfig()
    {
        if ($this->_config == null) {
            $config = new Config();
            
            // Generate config builder object
            $configBuilder = new ConfigBuilder(static::class);
            $this->ngRestConfig($configBuilder);
            $config->setConfig($configBuilder->getConfig());
            foreach ($this->i18n as $fieldName) {
                $config->appendFieldOption($fieldName, 'i18n', true);
            }

            // copy model data into config
            $config->setApiEndpoint(static::ngRestApiEndpoint());
            $config->setPrimaryKey($this->getNgRestPrimaryKey());
            $config->setFilters($this->ngRestFilters());
            $config->setDefaultOrder($this->ngRestListOrder());
            $config->setAttributeGroups($this->ngRestAttributeGroups());
            $config->setGroupByField($this->ngRestGroupByField());
            $config->setGroupByExpanded($this->ngRestGroupByExpanded());
            $config->setTableName($this->tableName());
            $config->setAttributeLabels($this->attributeLabels());
            $config->setActiveButtons($this->ngRestActiveButtons());
            
            // ensure relations are made not on composite table.
            if ($this->ngRestRelations() && count($this->getNgRestPrimaryKey()) > 1) {
                throw new InvalidConfigException("You can not use the ngRestRelations() on composite key model.");
            }
            
            // generate relations
            foreach ($this->generateNgRestRelations() as $relation) {
                $config->setRelation($relation);
            }

            $config->onFinish();
            $this->_config = $config;
        }

        return $this->_config;
    }
688798
protected function getModelClassForResource($resourceClass)
    {
        if (false === array_key_exists($resourceClass, $this->getModelClasses())) {
            throw new \InvalidArgumentException(sprintf('"%s" class not supported', $resourceClass));
        }

        return $this->getModelClasses()[$resourceClass];
    }