Generate the api file content based on its view file.

@param string $fileNamespace
@param string $className
@param string $modelClass
@return string
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,
        ]);
    }
823339
protected function buildClassLoader($namespace)
    {
        $template = new Template(__DIR__);
        $template->set('namespace', $namespace);
        
        $script = $template->render('templates/autoload.php');
        $file = "{$this->getBuildDirectory()}/autoload.php";
        
        $this->createFile($file, $script);
        
        return $this;
    }
456653
public function getClassContentThumbnailAction($filename)
    {
        $base_folder = $this->application->getContainer()->getParameter('classcontent_thumbnail.base_folder');
        $base_directories = array_map(function ($directory) use ($base_folder) {
            return str_replace(
                DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR,
                DIRECTORY_SEPARATOR,
                $directory.'/'.$base_folder
            );
        }, $this->application->getResourceDir());

        File::resolveFilepath($filename, null, array('include_path' => $base_directories));

        if (false === file_exists($filename)) {
            $filename = $this->getDefaultClassContentThumbnailFilepath($base_directories);
        }

        if (false === file_exists($filename) || false === is_readable($filename)) {
            $request = $this->application->getRequest();

            throw new FrontControllerException(sprintf(
                'The file `%s` can not be found (referer: %s).',
                $request->getHost().'/'.$request->getPathInfo(),
                $request->server->get('HTTP_REFERER')
            ), FrontControllerException::NOT_FOUND);
        }

        return $this->createResourceResponse($filename);
    }
1055526
public function addFooter($filename, $modelId = null)
    {   
        $tempFilename = str_replace($this->fileExtension, '', $filename);
        $this->model = $this->getModel();
        $this->modelId = $modelId;

        if ($this->batch) {
            $iteration = $this->batch->getSessionVariable('iteration');
        } else {
            $this->_session = new \Zend_Session_Namespace(__CLASS__);
            $iteration = $this->_session->iteration;
        }

        $writer = new XMLWriter();
        $writer->openURI($filename);
        $writer->setIndent(true);
        $writer->startDocument('1.0', 'UTF-8');
        //Added padding comparable to xml output;
        $writer->startElement('dta');

            $this->createHeaderFile($writer, $filename);

            $writer->startElement('data');

            for($i=0;$i<$iteration;$i++) {
                $partFilename = $tempFilename . '_' . $i . $this->fileExtension;

                $data = file_get_contents($partFilename);
                $writer->writeRaw($data);
                unlink($partFilename);
            }

            $writer->endElement();

        $writer->endElement();

        // reset rowNumber
        if ($this->batch) {
            $this->batch->setSessionVariable('rowNumber', 0);
            $this->batch->setSessionVariable('iteration', 0);
            $this->batch->setSessionVariable('stringSizes', array());
        } else {
            $this->_session->rowNumber = 0;
            $this->_session->iteration = 0;
            $this->_session->stringSizes = array();
        }
    }
1322818
public function generate(FileGenerator $file, $client): string
    {
        $class = $file->getClass() ?: new ClassGenerator();
        $class->setNamespaceName($client->getNamespace());
        $class->setName($client->getName());
        $methods = $client->getMethodMap();

        foreach ($methods->getMethods() as $method) {
            $this->ruleSet->applyRules(new ClientMethodContext($class, $method));
        }

        $file->setClass($class);

        return $file->generate();
    }
15838
protected function generateFileContent($class, $entity)
    {
        $generator  = new FileGenerator();
        $descriptor = $entity->getFileDescriptor();

        $generator->setClass($class);
        $generator->setDocblock(DocBlockGenerator::fromArray(array(
            'shortDescription' => 'Generated by Protobuf protoc plugin.',
            'longDescription'  => 'File descriptor : ' . $descriptor->getName(),
        )));

        return $generator->generate();
    }
314779
private function createModelClass($tableName, $dbId, $namespace) {
        /** @var MySQLTableSchema $tableSchema */
        $tableSchema = X::getInstance(
            MySQLTableSchema::class,
            [$tableName, X::$dbId()],
            [],
            Toolkit::randomChars(10)
        );
        $phpDoc = $this->createDocComment($tableSchema);

        $namespacePath = str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
        $modelName = Toolkit::toCamelCase($tableSchema->name, true);
        $modelFile = X_PROJECT_ROOT . "/protected/{$namespacePath}/{$modelName}.php";
        if (is_readable($modelFile)) {
            $phpCode = file_get_contents($modelFile);
            $newPhpCode = preg_replace_callback(
                '#(/\*\*[^/]*\*/)(\s+class\s+)#m',
                function ($m) use ($phpDoc) {
                    return $phpDoc . $m[2];
                },
                $phpCode
            );
        } else {
            $date = date('Y/m/d');
            $time = date('H:i:s');
            $newPhpCode = <<<PHP
<?php
/**
 * Created by x2ts model generator.
 * Date: {$date}
 * Time: {$time}
 */

namespace {$namespace};


use x2ts\db\orm\Model;

{$phpDoc}
class {$modelName} extends Model {}
PHP;
        }
        $dir = dirname($modelFile);
        if (!@mkdir($dir, 0755, true) !== false && !is_dir($dir)) {
            throw new Exception('Cannot create directory');
        }
        file_put_contents($modelFile, $newPhpCode);
    }
531787
public function getData($namespace = null)
    {
        if(!self::$pluginData) {
            // try to find the model via namespace
            if (!$namespace) {
                // if we are in a model
                if (property_exists($this, 'namespace')) {
                    self::$pluginData = $this;
                } /// When calling the method from a parent class that uses this class as a parent
                else {
                    // try to find plugin's model via reflection class
                    try{
                        $reflector = new \ReflectionClass(self::class);
                        $fn = $reflector->getFileName();
                        $explode = explode('plugins/', str_replace('\\', '/', dirname($fn)));
                        if (isset($explode[1])) {
                            $pluginNamespace = str_replace('/Controllers', '', $explode[1]);
                            self::$pluginData = Plugin::where('namespace', $pluginNamespace)->first();
                        }

                    }catch(\Exception $e){
                        return null;
                    }
                }
            }else {
                // Return a requested plugin
                self::$pluginData = $this->getByNamespace($namespace);
            }
        }

        if (!self::$pluginData) {
            return null;
        }

        return self::$pluginData;
    }
280273
protected function findUseStatementForClassName(File $phpCsFile, $className) {
		$useStatements = $this->parseUseStatements($phpCsFile);
		if (!isset($useStatements[$className])) {
			$useStatement = $this->findInSameNameSpace($phpCsFile, $className);
			if ($useStatement) {
				return $useStatement;
			}

			return null;
		}

		return $useStatements[$className];
	}
479435
public function generateViewFile($blockClassName)
    {
        sort($this->viewFileDoc);
        return $this->view->render('@cms/views/commands/block/create_block_view.php', [
            'blockClassName' => $blockClassName,
            'phpdoc' => $this->viewFileDoc,
            'luyaText' => $this->getGeneratorText('block/create'),
        ]);
    }
1206290
protected function generateCode(Module $module, $modelName, $arrayValues)
    {
        $replaces = array(
            '<namespace>'       => 'namespace ' . $module->getNamespace() . '\\Model;',
            '<modelAnnotation>' => $this->generateDocBlock($modelName),
            '<modelClassName>'  => $modelName,
            '<construct>'       => self::$constructorMethodTemplate,
            '<modelBody>'       => $this->generateBody($modelName, $arrayValues),
            '<spaces>'          => "    ",
            '<table>'           => strtolower($modelName)
        );
        $classTemplate = str_replace(array_keys($replaces), array_values($replaces), self::$classTemplate);
        return $classTemplate;
    }
56111
public static function loadCustom($classname, $namespace, $name) {

		if(false === is_string($classname)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($classname)), E_USER_ERROR);
		}

		if(false === is_string($namespace)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($namespace)), E_USER_ERROR);
		}

		if(false === is_string($name)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
		}

		static :: $custom[$name] = $namespace;

		return static :: Instance();
	}
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;
    }
1118448
private function generateClass(): ServiceDTOGenerator
    {
        $this->DTOFile = (new PhpFile())
            ->addComment('This file is auto-generated.');

        $namespace = $this->inputData['namespace'] . '\\' . $this->inputData['module'] . 'Module\\' . $this->inputData['type'];

        $this->DTOClass = $this->DTOFile
            ->addNamespace($namespace)
            ->addClass($this->inputData['class'] . $this->inputData['type'])
            ->addComment($this->inputData['class'] . ' service ' . strtolower($this->inputData['type']) . PHP_EOL)
            ->addComment('@package ' . $namespace);

        return $this;
    }
1228654
protected function getNamespace(File $phpCsFile): string
    {
        $className = $this->getClassName($phpCsFile);
        $classNameParts = explode('\\', $className);

        return $classNameParts[0];
    }
443855
protected function writeToModel($modelFile, $inPlaceholder = "    //")
    {
        $replaces = [];
        $searches = [];

        foreach ($this->getProperties() as $property => $content) {
            $replaces[] = $this->parsePropertyValue($content);
            $searches[] = '{{' . $property . '}}';
        } // foreach

        $methodContent = '';
        $newContent = str_replace(
            $searches,
            $replaces,
            file_get_contents(realpath(__DIR__ . '/stubs/model-content.stub'))
        );

        if ($keys = $this->getForeignKeys()) {
            $methodContent = implode("\n\n", $this->getMethodCallsForForeignKeys());
        } // if

        $newContent = str_replace(
            ["    // {{relations}}", '// {{traits}}'],
            [$methodContent, ($traits = $this->getTraits()) ? 'use ' . implode(', ', $traits) . ';' : ''],
            $newContent
        );

        $written = file_put_contents(
            $modelFile,
            str_replace(
                $inPlaceholder,
                $newContent,
                file_get_contents($modelFile)
            )
        );

        if ($written) {
            // Success of formatting is optional.
            if (DIRECTORY_SEPARATOR === '\\') {
                $exec = ".\\vendor\\bin\\phpcbf.bat {$modelFile} --standard=PSR2";
            } else {
                $exec = "vendor/bin/phpcbf {$modelFile} --standard=PSR2";
            }

            @exec($exec, $output, $return);
        } // if

        return $written;
    }
1336501
protected function doGenerate($className, $file)
    {
        $resourceDataForGenerator = $this->loadResourceGeneratorData($file);

        try {
            $visitors = $this->prepareVisitors($file);

            return $this->getGenerator()->generate($className, $resourceDataForGenerator, $visitors);
        } catch (SyntaxException $e) {
            $message = $e->getMessage() . "\n" . $this->dumpSource($e->getSource());
            $message .= str_repeat("\n", 2) . 'Filename: ' . $file;

            throw new \RuntimeException($message, 0, $e);
        }
    }