Write the routes file
@return boolean
337283
protected function writeFile()
    {
        //  Routes are writable, apparently, give it a bash
        $sData = '<?php' . "\n\n";
        $sData .= '/**' . "\n";
        $sData .= ' * THIS FILE IS CREATED/MODIFIED AUTOMATICALLY' . "\n";
        $sData .= ' * ===========================================' . "\n";
        $sData .= ' *' . "\n";
        $sData .= ' * Any changes you make in this file will be overwritten the' . "\n";
        $sData .= ' * next time the app routes are generated.' . "\n";
        $sData .= ' *' . "\n";
        $sData .= ' * See Nails docs for instructions on how to utilise the' . "\n";
        $sData .= ' * routes_app.php file' . "\n";
        $sData .= ' *' . "\n";
        $sData .= ' **/' . "\n\n";

        // --------------------------------------------------------------------------

        foreach ($this->aRoutes as $sKey => $sValue) {
            if (preg_match('#^//.*$#', $sKey)) {
                //  This is a comment
                $sData .= $sKey . "\n";
            } else {
                //  This is a route
                $sData .= '$route[\'' . $sKey . '\']=\'' . $sValue . '\';' . "\n";
            }
        }

        $oDate = Factory::factory('DateTime');
        $sData .= "\n" . '//LAST GENERATED: ' . $oDate->format('Y-m-d H:i:s');
        $sData .= "\n";

        // --------------------------------------------------------------------------

        $fHandle = @fopen(static::ROUTES_DIR . static::ROUTES_FILE, 'w');

        if (!$fHandle) {
            $this->setError('Unable to open routes file for writing.');
            return false;
        }

        if (!fwrite($fHandle, $sData)) {
            fclose($fHandle);
            $this->setError('Unable to write data to routes file.');
            return false;
        }

        fclose($fHandle);
        return true;
    }
661021
public function write()
    {
        $filename = $this->isFileWritable() ? $this->filename : $this->getCacheFilename();

        return file_put_contents($filename, $this->render());
    }
1320516
protected function _writeFiles()
    {
        $overwriteAll = false;
        if (!empty($this->params['overwrite'])) {
            $overwriteAll = true;
        }
        foreach ($this->_storage as $domain => $sentences) {
            $output = $this->_writeHeader();
            foreach ($sentences as $sentence => $header) {
                $output .= $header . $sentence;
            }

            // Remove vendor prefix if present.
            $slashPosition = strpos($domain, '/');
            if ($slashPosition !== false) {
                $domain = substr($domain, $slashPosition + 1);
            }

            $filename = str_replace('/', '_', $domain) . '.pot';
            $File = new File($this->_output . $filename);
            $response = '';
            while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
                $this->out();
                $response = $this->in(
                    sprintf('Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename),
                    ['y', 'n', 'a'],
                    'y'
                );
                if (strtoupper($response) === 'N') {
                    $response = '';
                    while (!$response) {
                        $response = $this->in('What would you like to name this file?', null, 'new_' . $filename);
                        $File = new File($this->_output . $response);
                        $filename = $response;
                    }
                } elseif (strtoupper($response) === 'A') {
                    $overwriteAll = true;
                }
            }
            $File->write($output);
            $File->close();
        }
    }
1300899
private function writeMarkdown($parsedRoutes)
    {
        $outputPath = config('apidoc.output');
        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
        $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md';
        $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md';

        $infoText = view('apidoc::partials.info')
            ->with('outputPath', ltrim($outputPath, 'public/'))
            ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection());

        $settings = ['languages' => config('apidoc.example_languages')];
        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) use ($settings) {
            return $routeGroup->map(function ($route) use ($settings) {
                if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) {
                    $route['headers']['Content-Type'] = 'application/json';
                }
                $route['output'] = (string) view('apidoc::partials.route')
                    ->with('route', $route)
                    ->with('settings', $settings)
                    ->render();

                return $route;
            });
        });

        $frontmatter = view('apidoc::partials.frontmatter')
            ->with('settings', $settings);
        /*
         * In case the target file already exists, we should check if the documentation was modified
         * and skip the modified parts of the routes.
         */
        if (file_exists($targetFile) && file_exists($compareFile)) {
            $generatedDocumentation = file_get_contents($targetFile);
            $compareDocumentation = file_get_contents($compareFile);

            if (preg_match('/---(.*)---\\s<!-- START_INFO -->/is', $generatedDocumentation, $generatedFrontmatter)) {
                $frontmatter = trim($generatedFrontmatter[1], "\n");
            }

            $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
                return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) {
                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) {
                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
                        if ($routeDocumentationChanged === false || $this->option('force')) {
                            if ($routeDocumentationChanged) {
                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
                            }
                        } else {
                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
                            $route['modified_output'] = $existingRouteDoc[0];
                        }
                    }

                    return $route;
                });
            });
        }

        $prependFileContents = file_exists($prependFile)
            ? file_get_contents($prependFile)."\n" : '';
        $appendFileContents = file_exists($appendFile)
            ? "\n".file_get_contents($appendFile) : '';

        $documentarian = new Documentarian();

        $markdown = view('apidoc::documentarian')
            ->with('writeCompareFile', false)
            ->with('frontmatter', $frontmatter)
            ->with('infoText', $infoText)
            ->with('prependMd', $prependFileContents)
            ->with('appendMd', $appendFileContents)
            ->with('outputPath', config('apidoc.output'))
            ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection())
            ->with('parsedRoutes', $parsedRouteOutput);

        if (! is_dir($outputPath)) {
            $documentarian->create($outputPath);
        }

        // Write output file
        file_put_contents($targetFile, $markdown);

        // Write comparable markdown file
        $compareMarkdown = view('apidoc::documentarian')
            ->with('writeCompareFile', true)
            ->with('frontmatter', $frontmatter)
            ->with('infoText', $infoText)
            ->with('prependMd', $prependFileContents)
            ->with('appendMd', $appendFileContents)
            ->with('outputPath', config('apidoc.output'))
            ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection())
            ->with('parsedRoutes', $parsedRouteOutput);

        file_put_contents($compareFile, $compareMarkdown);

        $this->info('Wrote index.md to: '.$outputPath);

        $this->info('Generating API HTML code');

        $documentarian->generate($outputPath);

        $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');

        if ($this->shouldGeneratePostmanCollection()) {
            $this->info('Generating Postman collection');

            file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
        }

        if ($logo = config('apidoc.logo')) {
            copy(
                $logo,
                $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png'
            );
        }
    }
1158258
public function write()
    {
        $data = array();
        $dumper = new ArrayDumper();

        foreach ($this->getCanonicalPackages() as $package) {
            $data[] = $dumper->dump($package);
        }

        $this->file->write($data);
    }
1205841
public function filesToOverwrite()
    {
        $files = new Filesystem;
        $stubs = array_map(function (SplFileInfo $file) {
            return $file->getRelativePathname();
        }, $files->allFiles("{$this->sageRoot}/resources/assets"));
        return array_intersect($stubs, $this->getFileList());
    }
921032
public function write()
    {
        $lines = array();

        foreach ($this->data as $fetch) {
            $data = array($fetch['url'], $fetch['length'], $fetch['filename']);
            array_push($lines, join(' ', $data) . "\n");
        }

        if (count($lines) == 0) {
            if (file_exists($this->fileName)) {
                unlink($this->fileName);
            }
        } else {
            writeFileText($this->fileName, $this->fileEncoding, join('', $lines));
        }
    }
595643
public function cache()
    {
        foreach($this->getRoutes() as $key => $r) {
            if (!is_string($r['callback'])) {
                throw new Exception(sprintf('Routes cannot contain a Closure/Function callback while caching.'));
            }
        }

        $cacheContent = '<?php return '.var_export($this->getRoutes(), true).';' . PHP_EOL;
        if (false === file_put_contents($this->cacheFile, $cacheContent)) {
            throw new Exception(sprintf('Routes cache file could not be written.'));
        }

        return true;
    }
593961
private function write()
    {
        $project = $this->getProject();

        if (!touch($this->file->getPath())) {
            throw new BuildException("Unable to write to " . $this->file->getPath() . ".");
        }

        $this->log("Writing to " . $this->file->__toString(), Project::MSG_INFO);

        if (is_array($this->checksum)) {
            $this->log("Using " . implode(', ', $this->checksum) . " for checksuming.", Project::MSG_INFO);
        }

        foreach ($this->filesets as $fs) {
            $dir = $fs->getDir($this->project)->getPath();

            $ds = $fs->getDirectoryScanner($project);
            $fromDir = $fs->getDir($project);
            $srcFiles = $ds->getIncludedFiles();
            $srcDirs = $ds->getIncludedDirectories();

            foreach ($ds->getIncludedFiles() as $file_path) {
                $line = $file_path;
                if ($this->checksum) {
                    foreach ($this->checksum as $algo) {
                        if (!$hash = $this->hashFile($dir . '/' . $file_path, $algo)) {
                            throw new BuildException("Hashing $dir/$file_path with $algo failed!");
                        }

                        $line .= "\t" . $hash;
                    }
                }
                $line .= "\n";
                $manifest[] = $line;
                $this->log("Adding file " . $file_path, Project::MSG_VERBOSE);
                $this->meta['totalFileCount']++;
                $this->meta['totalFileSize'] += filesize($dir . '/' . $file_path);
            }
        }

        file_put_contents($this->file, $manifest);

        $this->log(
            "Done. Total files: " . $this->meta['totalFileCount'] . ". Total file size: " . $this->meta['totalFileSize'] . " bytes.",
            Project::MSG_INFO
        );
    }
538343
public function write()
    {
        
        $buffer = '';
        $file = $this->getTranslationFile();
        
        // Add PO Headers.
        $buffer .= 'msgid ""' . "\n";
        $buffer .= 'msgstr ""' . "\n";
        
        // If the TranslationFile is a specific POFile instance, we add PO Headers
        // to the output.
        if (get_class($this->getTranslationFile()) == 'tao_helpers_translation_POFile') {
        	foreach ($file->getHeaders() as $name => $value) {
        		$buffer .= '"' . $name . ': ' . $value . '\n"' . "\n";
        	}
        }
        
        // Write all Translation Units.
        $buffer .= "\n";
		foreach($this->getTranslationFile()->getTranslationUnits() as $tu) {
            
			$c = tao_helpers_translation_POUtils::sanitize($tu->getContext(), true);
			$s = tao_helpers_translation_POUtils::sanitize($tu->getSource(), true);
			$t = tao_helpers_translation_POUtils::sanitize($tu->getTarget(), true);
            $a = tao_helpers_translation_POUtils::serializeAnnotations($tu->getAnnotations());

            if (!empty($a)){
                $buffer .= "${a}\n";
            }

            if ($c) {
                $buffer .= "msgctxt \"{$c}\"\n";
            }

			$buffer .= "msgid \"{$s}\"\n";
			$buffer .= "msgstr \"{$t}\"\n";
			$buffer .= "\n";
		}
		
		return file_put_contents($this->getFilePath(), $buffer);
        
    }
279381
private function rewriteRoutes()
    {
        $iExitCode = $this->callCommand('routes:rewrite', [], false, true);
        if ($iExitCode == static::EXIT_CODE_SUCCESS) {

            $this->oOutput->writeln('<info>done!</info>');
            return true;

        } else {

            $this->abort(
                self::EXIT_CODE_FAILURE,
                [
                    'The Routes Rewriting tool encountered issues and aborted the process.',
                    'You should run it manually and investigate any issues.',
                    'The exit code was ' . $iExitCode,
                ]
            );

            return false;
        }
    }
946822
public function updateRoutesFile($name)
    {
        $name = strtolower(Pluralizer::plural($name));

        $routesPath = app_path() . '/routes.php';
        $routesContent = $this->file->get($routesPath);

        $resourceRoute = "Route::resource('" . $name . "', '" . ucwords($name) . "Controller');";

        if ( ! strpos($routesContent, $resourceRoute))
        {
            return $this->file->append($routesPath, "\n\n".$resourceRoute);
        }

        return false;
    }
129006
public function writeManifest() {
        $written = false;
        if (!empty ($this->vehicles)) {
            if (!empty($this->attributes['setup-options']) && is_array($this->attributes['setup-options'])) {
                $cacheManager = $this->xpdo->getCacheManager();
                $cacheManager->copyFile($this->attributes['setup-options']['source'],$this->path . $this->signature . '/setup-options.php');

                $this->attributes['setup-options'] = $this->signature . '/setup-options.php';
            }
            $manifest = array(
                xPDOTransport::MANIFEST_VERSION => $this->manifestVersion,
                xPDOTransport::MANIFEST_ATTRIBUTES => $this->attributes,
                xPDOTransport::MANIFEST_VEHICLES => $this->vehicles
            );
            $content = var_export($manifest, true);
            $cacheManager = $this->xpdo->getCacheManager();
            if ($content && $cacheManager) {
                $fileName = $this->path . $this->signature . '/manifest.php';
                $content = "<?php return {$content};";
                if (!($written = $cacheManager->writeFile($fileName, $content))) {
                    $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error writing manifest to ' . $fileName);
                }
            }
        }
        return $written;
    }
763594
protected function rewrite() {
		$routes=array();
		$aliases=&$this->f3->ref('ALIASES');
		$redirects=array();
		foreach($this->f3->get('ROUTES') as $old=>$data) {
			$route=current(current($data));//let's pick up any route just to get the URL name
			$name=@$route[3];//PHP 5.3 compatibility
			$new=$old;
			if (!($name && in_array($name,$this->global_aliases)
				|| isset($this->global_regex) && preg_match($this->global_regex,$old))) {
				if (isset($this->rules[$this->current][$name])) {
					$new=$this->rules[$this->current][$name];
					if ($new===FALSE) {
						if (isset($aliases[$name]))
							unset($aliases[$name]);
						continue;
					}
				}
				$new=rtrim('/'.$this->current.($new),'/');
				if ($this->migrate && $this->auto) {
					$redir=$old;
					if (isset($this->rules[$this->primary][$name]))
						$redir=$this->rules[$this->primary][$name];
					if ($redir!==FALSE)
						$redirects[$old]=rtrim('/'.$this->primary.($redir),'/');
				}
			}
			if (isset($routes[$new]) && $this->strict)
				user_error(sprintf(self::E_Duplicate,$new),E_USER_ERROR);
			$routes[$new]=$data;
			if (isset($aliases[$name]))
				$aliases[$name]=$new;
		}
		$this->f3->set('ROUTES',$routes);
		foreach($redirects as $old=>$new)
			$this->f3->route('GET '.$old,function($f3)use($new){$f3->reroute($new,TRUE);});
	}
438190
private function generateResourceRoutes()
    {
        $this->comment("Resources routes...");
        if (!$this->checkWilling('resource')) {
            return $this->line("\tskip");
        }

        $variables = [
            'STARTER' => $this->starter,
        ];
        $routesPath = $this->getDestinationPath('resource.routes');
        $routesContent = Utils::renderTemplate(
            config('zgldh-scaffold.templates.resource.routes', 'zgldh.scaffold::raw.resources.assets.routes'),
            $variables);
        Utils::writeFile($routesPath, $routesContent);

        $routeLine = "require('{$this->moduleDirectoryName}/{$this->starter->getModuleName()}/resources/assets/routes.js').default";
        Utils::addToVueRoute($routeLine);
    }
575863
public static function save()
	{
		self::lock();
		if ( is_null( self::$authFileP ) ) throw new Exception( 'No lock has been requested' );

		$file = '<?php if (realpath(__FILE__)===realpath($_SERVER["SCRIPT_FILENAME"])) {header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");die();}?>' . "\n";
		$file.= json_encode( self::$auth );

		self::write( $file );

		return true;
	}
929665
public function generateRoutes()
    {
        if (!$content = $this->getRoutesContent()) {
            return '';
        }

        if (version_compare(app()->version(), '5.3.0', '<')) {
            $path = app_path('Http/routes/'.implode('/', $this->sectionSegments).'.php');
        } else {
            $path = base_path('routes/web/'.implode('/', $this->sectionSegments).'.php');
        }

        if (is_file($path)) {
            return '';
        }

        $this->createMissingDirs($path);

        return file_put_contents($path, $content) !== false ? $path : '';
    }