Generate the php file code

@see \Cathedral\Builder\BuilderAbstract::setupFile()
10898
protected function setupFile() {
		$this->_file->setNamespace($this->getNames()->namespace_entity);
	
		$this->_file->setUse('Zend\Db\RowGateway\RowGatewayInterface');
		$this->_file->setUse("{$this->getNames()->namespace_model}\\{$this->getNames()->modelName}");
	}
1201750
public function main()
    {
        $this->loadDependencies();

        if (!isset($this->file) && count($this->filesets) == 0) {
            throw new BuildException('Missing either a nested fileset or attribute "file" set');
        }

        if (count($this->formatters) == 0) {
            // turn legacy format attribute into formatter
            $fmt = new PHPCPDFormatterElement($this);
            $fmt->setType($this->format);
            $fmt->setUseFile(false);

            $this->formatters[] = $fmt;
        }

        $this->validateFormatters();

        $filesToParse = [];

        if ($this->file instanceof PhingFile) {
            $filesToParse[] = $this->file->getPath();
        } else {
            // append any files in filesets
            foreach ($this->filesets as $fs) {
                $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();

                foreach ($files as $filename) {
                    $f = new PhingFile($fs->getDir($this->project), $filename);
                    $filesToParse[] = $f->getAbsolutePath();
                }
            }
        }

        $this->log('Processing files...');

        if ($this->oldVersion) {
            $detectorClass = 'PHPCPD_Detector';
            $strategyClass = 'PHPCPD_Detector_Strategy_Default';
        } else {
            $detectorClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Detector';
            $strategyClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Strategy\\DefaultStrategy';
        }

        $detector = new $detectorClass(new $strategyClass());
        $clones = $detector->copyPasteDetection(
            $filesToParse,
            $this->minLines,
            $this->minTokens,
            $this->fuzzy
        );

        $this->log('Finished copy/paste detection');

        foreach ($this->formatters as $fe) {
            $formatter = $fe->getFormatter();
            $formatter->processClones(
                $clones,
                $this->project,
                $fe->getUseFile(),
                $fe->getOutfile()
            );
        }
    }
938045
public function setUploadedFile($uploadedFile)
	{
		$this->clear();

		if ($uploadedFile == LARACLIP_NULL) {
			return;
		}

		$this->uploadedFile = $this->IOWrapper->make($uploadedFile);
		$this->instanceWrite('file_name', $this->uploadedFile->getFilename());
		$this->instanceWrite('file_size', $this->uploadedFile->getSize());
		$this->instanceWrite('content_type', $this->uploadedFile->getMimeType());
		$this->instanceWrite('updated_at', date('Y-m-d H:i:s'));
		$this->queueAllForWrite();
	}
1069416
private function generateCacheFile()
    {
        $previousErrorSetting = libxml_use_internal_errors(true);
        libxml_clear_errors();
        if (@$this->domDocument->schemaValidate($this->xmlSchemaFile)) {
            $this->domDocument->preserveWhiteSpace = false;
            // Reload the XML to strip whitespace from XIncluded XML.
            $this->domDocument->loadXML($this->domDocument->saveXML());

            $xslDocument = new DOMDocument('1.0', 'UTF-8');
            $xslDocument->load(__DIR__.'/Resources/xsl/flexmodel-cache.xsl');

            $processor = new XSLTProcessor();
            $processor->setParameter('', 'checksum', md5($this->domDocument->saveXML()));
            $processor->importStyleSheet($xslDocument);
            $processor->registerPHPFunctions();

            $configuration = $processor->transformToXML($this->domDocument);
            file_put_contents($this->getCacheFile(), $configuration);

            $this->loadConfiguration(false);
        } else {
            $errors = libxml_get_errors();
            foreach ($errors as $error) {
                trigger_error(sprintf('Line %s: %s in "%s"', $error->line, trim($error->message), $error->file), E_USER_WARNING);
            }
            libxml_clear_errors();
        }
        libxml_use_internal_errors($previousErrorSetting);
    }
94249
private function generateConsts()
    {
        $result = '<?php' . PHP_EOL;
        foreach($this->ref->getConstants() as $name => $value)
        {
            $value = var_export($value, true);
            $result .= <<<CODE
define('{$name}', {$value});

CODE;
        }
        file_put_contents($this->savePath . '/consts.php', $result);
    }
834220
protected function generateFileHeader()
    {
        $shipping_file = $this->shipping_file;
        $assignment = $shipping_file->assignment;
        $assignor_person = $assignment->assignor->person;
        $bank = $assignment->bank;

        $format = '%03.3s%04.4s%01.1s%-9.9s%01.1s%014.14s%020.20s%05.5s%-1.1s'
            . '%012.12s%-1.1s%-1.1s%-30.30s%-30.30s%-10.10s%01.1s%08.8s%06.6s'
            . '%06.6s%03.3s%05.5s%-20.20s%-20.20s%-29.29s';

        $data = [
            $bank->code,
            '0',
            '0',
            '',
            $assignor_person->getDocumentType(),
            $assignor_person->document,
            $assignment->covenant,
            '0', // $assignment->agency,
            '',
            '0', // $assignment->account,
            '',
            '',
            Utils::cleanSpaces($assignor_person->name),
            $bank->name,
            '',
            '1',
            static::date('dmY', $shipping_file->stamp),
            static::date('His', $shipping_file->stamp),
            $shipping_file->counter,
            static::VERSION_FILE_LAYOUT,
            '0',
            '',
            $shipping_file->notes,
            '',
        ];

        return vsprintf($format, static::normalize($data));
    }
336875
function setupFileElement( editor, fileInput, filebrowser ) {
		var params = filebrowser.params || {};
		params.CKEditor = editor.name;
		params.CKEditorFuncNum = editor._.filebrowserFn;
		if ( !params.langCode )
			params.langCode = editor.langCode;

		fileInput.action = addQueryString( filebrowser.url, params );
		fileInput.filebrowser = filebrowser;
	}
278863
public function buildFileContainerTemplate() {
		$tr = Html::el("tr");
		
		$preview = Html::el("td")->addAttributes([
			"style" => "width: 15%"
		]);
		$preview->addHtml($this->elements["imagePreview"]->setAttribute("width", "100%"));
		$preview->addHtml($this->elements["filePreview"]);
		$tr->addHtml($preview);
		
		$name = Html::el("td");
		$name->addHtml($this->elements["filename"]);
		$tr->addHtml($name);
		
		$progress = Html::el("td");
		$progress->addHtml($this->elements["fileProgress"])->addAttributes([
			"style" => "width: 20%"
		]);
		$tr->addHtml($progress);
		
		$delete = Html::el("td")->addAttributes([
			"style" => "width: 50px; text-align: center",
		]);
		$delete->addHtml($this->elements["delete"]);
		$tr->addHtml($delete);
		
		return $tr;
	}
1120027
private void setupFile() {
        if (!new File(directory).exists() && !new File(directory).mkdirs()) {
            try {
                throw new IOException("Unable to create output directory");
            } catch (IOException e) {
                log.info(e);
            }
        }
        if (!file.exists()) {
            try {
                if (!file.createNewFile()) {
                    throw new IOException("Unable to create output file");
                }
            } catch (IOException e) {
                log.error(e);
            }
        }
    }
66587
public function install()
    {
        $definition = $this->file->read();
        $excluded   = $definition['archive']['exclude'] ?? [];

        $excluded = array_map(
            function (string $exclude): string {
                return substr($exclude, 0, 1) !== '/'
                    ? '/' . $exclude
                    : $exclude;
            },
            $excluded
        );

        $files = array_merge(
            $this->defaults,
            array_map(
                function (FileMappingInterface $mapping): string {
                    return '/' . $mapping->getRelativeDestination();
                },
                iterator_to_array(
                    $this->resolver->resolve()
                )
            )
        );

        foreach ($files as $file) {
            if (!in_array($file, $excluded)
                && file_exists($this->destination . $file)
            ) {
                $excluded[] = $file;
                $this->io->write(
                    sprintf(
                        '<info>Added:</info> %s to archive exclude in composer.json',
                        $file
                    )
                );
            }
        }

        $definition['archive']['exclude'] = $excluded;
        $this->file->write($definition);
    }
520844
protected final function BuiltInTemplateFile()
    {
        $class = new \ReflectionClass($this);
        $classFile = Str::Replace('\\', '/', $class->getFileName());
        $templatePath = Str::Replace('/Modules/', '/Templates/', $classFile);
        return Path::AddExtension($templatePath, 'phtml', true);
    }
1202975
public function setup_file_system() {
        global $CFG;
        if ($this->filesystem === null) {
            require_once($CFG->libdir . '/filestorage/file_system.php');
            if (!empty($CFG->alternative_file_system_class)) {
                $class = $CFG->alternative_file_system_class;
            } else {
                // The default file_system is the filedir.
                require_once($CFG->libdir . '/filestorage/file_system_filedir.php');
                $class = file_system_filedir::class;
            }
            $this->filesystem = new $class();
        }

        return $this->filesystem;
    }
372118
public static function init($configFile = null)
    {
        if (!version_compare(PHP_VERSION, '5.6.0', '>=')) {
            Daemon::log('PHP >= 5.6.0 required.');
            return;
        }

        //run without composer
        if (!function_exists('setTimeout')) {
            require 'PHPDaemon/Utils/func.php';
        }

        Daemon::initSettings();
        FileSystem::init();
        Daemon::$runName = basename($_SERVER['argv'][0]);

        $error = false;
        $argv = $_SERVER['argv'];
        $runmode = isset($argv[1]) ? str_replace('-', '', $argv[1]) : '';
        $args = Bootstrap::getArgs($argv);

        if (!isset(self::$params[$runmode]) && !in_array($runmode, self::$commands)) {
            if ('' !== $runmode) {
                echo('Unrecognized command: ' . $runmode . "\n");
            }

            self::printUsage();
            exit;
        } elseif ('help' === $runmode) {
            self::printHelp();
            exit;
        }

        $n = null;
        if ('log' === $runmode) {
            if (isset($args['n'])) {
                $n = $args['n'];
                unset($args['n']);
            } else {
                $n = 20;
            }
        }

        if (isset($configFile)) {
            Daemon::$config->configfile->setHumanValue($configFile);
        }
        if (isset($args['configfile'])) {
            Daemon::$config->configfile->setHumanValue($args['configfile']);
        }

        if (!Daemon::$config->loadCmdLineArgs($args)) {
            $error = true;
        }

        if (!Daemon::loadConfig(Daemon::$config->configfile->value)) {
            $error = true;
        }

        if ('log' === $runmode) {
            passthru('tail -n ' . $n . ' -f ' . escapeshellarg(Daemon::$config->logstorage->value));
            exit;
        }

        if (extension_loaded('apc') && ini_get('apc.enabled')) {
            Daemon::log('Detected pecl-apc extension enabled. Usage of bytecode caching (APC/eAccelerator/xcache/...)  makes no sense at all in case of using phpDaemon \'cause phpDaemon includes files just in time itself.');
        }

        if (isset(Daemon::$config->locale->value) && Daemon::$config->locale->value !== '') {
            setlocale(LC_ALL, array_map('trim', explode(',', Daemon::$config->locale->value)));
        }

        if (Daemon::$config->autoreimport->value && !is_callable('runkit_import')) {
            Daemon::log('[WARN] runkit extension not found. You should install it or disable --auto-reimport. Non-critical error.');
        }

        if (!is_callable('posix_kill')) {
            Daemon::log('[EMERG] Posix not found. You should compile PHP without \'--disable-posix\'.');
            $error = true;
        }

        if (!is_callable('pcntl_signal')) {
            Daemon::log('[EMERG] PCNTL not found. You should compile PHP with \'--enable-pcntl\'.');
            $error = true;
        }

        if (extension_loaded('libevent')) {
            Daemon::log('[EMERG] libevent extension found. You have to remove libevent.so extension.');
            $error = true;
        }

        $eventVer = '1.6.1';
        $eventVerType = 'stable';
        if (!Daemon::loadModuleIfAbsent('event', $eventVer . '-' . $eventVerType)) {
            Daemon::log('[EMERG] event extension >= ' . $eventVer . ' not found (or OUTDATED). You have to install it. `pecl install http://pecl.php.net/get/event`');
            $error = true;
        }

        if (!is_callable('socket_create')) {
            Daemon::log('[EMERG] Sockets extension not found. You should compile PHP with \'--enable-sockets\'.');
            $error = true;
        }

        if (!is_callable('shmop_open')) {
            Daemon::log('[EMERG] Shmop extension not found. You should compile PHP with \'--enable-shmop\'.');
            $error = true;
        }

        if (!isset(Daemon::$config->user)) {
            Daemon::log('[EMERG] You must set \'user\' parameter.');
            $error = true;
        }

        if (!isset(Daemon::$config->path)) {
            Daemon::log('[EMERG] You must set \'path\' parameter (path to your application resolver).');
            $error = true;
        }

        if (!file_exists(Daemon::$config->pidfile->value)) {
            if (!touch(Daemon::$config->pidfile->value)) {
                Daemon::log('[EMERG] Couldn\'t create pid-file \'' . Daemon::$config->pidfile->value . '\'.');
                $error = true;
            }

            Bootstrap::$pid = 0;
        } elseif (!is_file(Daemon::$config->pidfile->value)) {
            Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be a regular file.');
            Bootstrap::$pid = false;
            $error = true;
        } elseif (!is_writable(Daemon::$config->pidfile->value)) {
            Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be writable.');
            $error = true;
        } elseif (!is_readable(Daemon::$config->pidfile->value)) {
            Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be readable.');
            Bootstrap::$pid = false;
            $error = true;
        } else {
            Bootstrap::$pid = (int)file_get_contents(Daemon::$config->pidfile->value);
        }

        if (Daemon::$config->chroot->value !== '/') {
            if (posix_getuid() != 0) {
                Daemon::log('You must have the root privileges to change root.');
                $error = true;
            }
        }

        $pathList = preg_split('~\s*;\s*~', Daemon::$config->path->value);
        $found = false;
        foreach ($pathList as $path) {
            if (@is_file($path)) {
                Daemon::$appResolverPath = $path;
                $found = true;
                break;
            }
        }
        if (!$found) {
            Daemon::log('Your application resolver \'' . Daemon::$config->path->value . '\' is not available (config directive \'path\').');
            $error = true;
        }

        Daemon::$appResolver = require Daemon::$appResolverPath;

        if (isset(Daemon::$config->group->value) && is_callable('posix_getgid')) {
            if (($sg = posix_getgrnam(Daemon::$config->group->value)) === false) {
                Daemon::log('Unexisting group \'' . Daemon::$config->group->value . '\'. You have to replace config-variable \'group\' with existing group-name.');
                $error = true;
            } elseif (($sg['gid'] != posix_getgid()) && (posix_getuid() != 0)) {
                Daemon::log('You must have the root privileges to change group.');
                $error = true;
            }
        }

        if (isset(Daemon::$config->user->value) && is_callable('posix_getuid')) {
            if (($su = posix_getpwnam(Daemon::$config->user->value)) === false) {
                Daemon::log('Unexisting user \'' . Daemon::$config->user->value . '\', user not found. You have to replace config-variable \'user\' with existing username.');
                $error = true;
            } elseif (($su['uid'] != posix_getuid()) && (posix_getuid() != 0)) {
                Daemon::log('You must have the root privileges to change user.');
                $error = true;
            }
        }

        if (isset(Daemon::$config->minspareworkers->value)
            && Daemon::$config->minspareworkers->value > 0
            && isset(Daemon::$config->maxspareworkers->value)
            && Daemon::$config->maxspareworkers->value > 0
        ) {
            if (Daemon::$config->minspareworkers->value > Daemon::$config->maxspareworkers->value) {
                Daemon::log('\'minspareworkers\' cannot be greater than \'maxspareworkers\'.');
                $error = true;
            }
        }

        if (isset(Daemon::$config->addincludepath->value)) {
            ini_set(
                'include_path',
                ini_get('include_path') . ':' . implode(':', Daemon::$config->addincludepath->value)
            );
        }

        if (isset(Daemon::$config->minworkers->value) && isset(Daemon::$config->maxworkers->value)) {
            if (Daemon::$config->minworkers->value > Daemon::$config->maxworkers->value) {
                Daemon::$config->minworkers->value = Daemon::$config->maxworkers->value;
            }
        }

        if ($runmode === 'start') {
            if ($error === false) {
                Bootstrap::start();
            } else {
                exit(6);
            }
        } elseif ($runmode === 'runworker') {
            if ($error === false) {
                Bootstrap::runworker();
            } else {
                exit(6);
            }
        } elseif ($runmode === 'status' || $runmode === 'fullstatus') {
            $status = Bootstrap::$pid && Thread\Generic::ifExistsByPid(Bootstrap::$pid);
            echo '[STATUS] phpDaemon ' . Daemon::$version . ' is ' . ($status ? 'running' : 'NOT running') . ' (' . Daemon::$config->pidfile->value . ").\n";

            if ($status && ($runmode === 'fullstatus')) {
                echo 'Uptime: ' . DateTime::diffAsText(filemtime(Daemon::$config->pidfile->value), time()) . "\n";

                Daemon::$shm_wstate = new ShmEntity(Daemon::$config->pidfile->value, Daemon::SHM_WSTATE_SIZE, 'wstate');

                $stat = Daemon::getStateOfWorkers();

                echo "State of workers:\n";
                echo "\tTotal: " . $stat['alive'] . "\n";
                echo "\tIdle: " . $stat['idle'] . "\n";
                echo "\tBusy: " . $stat['busy'] . "\n";
                echo "\tShutdown: " . $stat['shutdown'] . "\n";
                echo "\tPre-init: " . $stat['preinit'] . "\n";
                echo "\tInit: " . $stat['init'] . "\n";
            }

            echo "\n";
        } elseif ($runmode === 'update') {
            if ((!Bootstrap::$pid) || (!posix_kill(Bootstrap::$pid, SIGHUP))) {
                echo '[UPDATE] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
            }
        } elseif ($runmode === 'reopenlog') {
            if ((!Bootstrap::$pid) || (!posix_kill(Bootstrap::$pid, SIGUSR1))) {
                echo '[REOPEN-LOG] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
            }
        } elseif ($runmode === 'reload') {
            if ((!Bootstrap::$pid) || (!posix_kill(Bootstrap::$pid, SIGUSR2))) {
                echo '[RELOAD] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
            }
        } elseif ($runmode === 'restart') {
            if ($error === false) {
                Bootstrap::stop(2);
                Bootstrap::start();
            }
        } elseif ($runmode === 'hardrestart') {
            Bootstrap::stop(3);
            Bootstrap::start();
        } elseif ($runmode === 'ipcpath') {
            $i = Daemon::$appResolver->getInstanceByAppName('\PHPDaemon\IPCManager\IPCManager');
            echo $i->getSocketUrl() . PHP_EOL;
        } elseif ($runmode === 'configtest') {
            $term = new Terminal;
            $term->enableColor();

            echo "\n";

            $rows = [];

            $rows[] = [
                'parameter' => 'PARAMETER',
                'value' => 'VALUE',
                '_color' => '37',
                '_bold' => true,
            ];

            foreach (Daemon::$config as $name => $entry) {
                if (!$entry instanceof Generic) {
                    continue;
                }

                $row = [
                    'parameter' => $name,
                    'value' => var_export($entry->humanValue, true),
                ];

                if ($entry->defaultValue != $entry->humanValue) {
                    $row['value'] .= ' (' . var_export($entry->defaultValue, true) . ')';
                }

                $rows[] = $row;
            }

            $term->drawtable($rows);

            echo "\n";
        } elseif ($runmode === 'stop') {
            Bootstrap::stop();
        } elseif ($runmode === 'gracefulstop') {
            Bootstrap::stop(4);
        } elseif ($runmode === 'hardstop') {
            echo '[HARDSTOP] Sending SIGINT to ' . Bootstrap::$pid . '... ';

            $ok = Bootstrap::$pid && posix_kill(Bootstrap::$pid, SIGINT);

            echo $ok ? 'OK.' : 'ERROR. It seems that phpDaemon is not running.';

            if ($ok) {
                $i = 0;

                while ($r = Thread\Generic::ifExistsByPid(Bootstrap::$pid)) {
                    usleep(500000);

                    if ($i === 9) {
                        echo "\nphpDaemon master-process hasn't finished. Sending SIGKILL... ";
                        posix_kill(Bootstrap::$pid, SIGKILL);
                        sleep(0.2);
                        if (!Thread\Generic::ifExistsByPid(Bootstrap::$pid)) {
                            echo " Oh, his blood is on my hands :'(";
                        } else {
                            echo "ERROR: Process alive. Permissions?";
                        }

                        break;
                    }

                    ++$i;
                }
            }

            echo "\n";
        }
    }
1351261
public function addFile($file) {
        $baseName = basename($file, '.php');

        $components = explode('.', $baseName);
        $language = $components[1];

        $data = require($file);

        $this->add($data, $language);
    }
191562
private function setup()
    {
        self::$version = '3.1.7';
        self::$src = dirname(__FILE__);
        self::$dir = dirname(dirname(__FILE__));
        self::$url = $this->getCuztomUrl(self::$src);

        // Do
        do_action('cuztom_setup');
    }
1339528
public function TemplateFile()
    {
        if (!$this->AllowCustomTemplates() ||
                !$this->content || !$this->content->GetTemplate())
        {
            return $this->BuiltInTemplateFile();
        }
        $file = Path::Combine(PathUtil::ModuleCustomTemplatesFolder($this), $this->content->GetTemplate());
        return Path::AddExtension($file, 'phtml');
    }
948905
public function generateFile()
    {
        parent::generateFile();

        if (count($this->uses) > 0) {
            sort($this->uses);
            $uses = '';
            foreach ($this->uses as $use) {
                $uses .= 'use ' . $use . ';' . $this->getNewlineCharacter();
            }
            $this->file_content = str_replace('{{ uses }}', $uses, $this->file_content);
        } else {
            $this->file_content = str_replace('{{ uses }}', '', $this->file_content);
        }
        $this->file_content = str_replace('{{ className }}', $this->class_name, $this->file_content);

        return $this->file_content;
    }