Generates the log initialization
for a Laravel GAE app.

@param string $startDir the Laravel 'app/start' directory path.
768005
protected function generateLogInit($startDir)
    {
        $startTemplatesPath = __DIR__.'/templates/start';

        $startFiles = [
            'local.php',
            'production.php'
        ];

        foreach ($startFiles as $filename)
        {
            $srcPath = "{$startTemplatesPath}/{$filename}";
            $destPath = "{$startDir}/{$filename}";

            if (file_exists($destPath))
            {
                $overwrite = $this->myCommand->confirm(
                    "Overwrite the existing {$destPath} file?", false
                );

                if ( ! $overwrite)
                {
                    continue;
                }

                $this->createBackupFile($destPath);
            }

            copy($srcPath, $destPath);
        }

        $this->myCommand->info('Generated the log initialization files.');
    }
1315590
public function start()
    {
        $finder  = new Finder;
        $appPath = realpath(getenv('APPPATH'));
        $appDir  = basename($appPath);
        $found   = [];

        $finder->ignoreUnreadableDirs()->files()->name('*.php')->in($appPath);

        $this->writeln([sprintf('In: ./%s/',$appDir), str_repeat('-', 60)]);

        foreach ($finder as $file)
        {
            $_file = new \SplFileObject($file->getRealPath());

            foreach ($_file as $k => $line) {
                $exp = preg_match('/TODO|FIXME/', $line);

                if ($exp > 0) {
                    $line = str_replace(['//','#','TODO:','FIXME:'], ['','','[TODO]','[FIXME]'], trim($line));
                    $found[$file->getRelativePath().'/'. basename($file)][] = "[{$k}]{$line}";
                }
            }
        }
        
        if (empty($found))
        {
            $this->text('There are not notes marked.');
            $this->newLine();
        }
        else
        {
            foreach ($found as $file => $lines)
            {
                $this->text(sprintf('./%s/%s:', $appDir, $file));
                $this->newLine();
                $this->listing($lines);
            }
        }
    }
1289177
private List<Resource<?>> allDirectoriesOnPath(Resource<?> startingDir)
   {
      List<Resource<?>> result = new ArrayList<>();

      while (startingDir != null)
      {
         result.add(startingDir);
         startingDir = startingDir.getParent();
      }

      return result;
   }
1003330
public static function iterateDir( $startPath )
    {
        foreach( new \DirectoryIterator( $startPath ) as $objItem ) {
            if( $objItem->isLink( ) ) {
                Self::$arrSymlinks[] = $objItem->getPath( ) . '/' . $objItem->getFilename( );
                continue;
            }
            if($objItem->isDir( ) ) {
                if( !$objItem->isDot( ) ) Self::iterateDir( $objItem->getPathname(), $arrResult );
                continue;
            }
            if( $objItem->isLink() ) Self::$arrSymlinks[] = $objItem->getPath( ) . '/' . $objItem->getFilename( );
        }
        return;
    }
568064
public function show($start)
    {
        if (!$start) {
            if (!empty(config('app.project'))) {
                $this->line(config('app.project'));
            }
            if (!empty(config('app.owner'))) {
                $this->line('by '.config('app.owner'));
            }
            $this->line('');
            $this->line('***********');
            $this->line('Based on : ');
        } else {
            $this->line('');
        }

        $version = Application::getVersion()->console();
        $this->question('Vinala ', true);
        $this->line("Framework v$version");
        $this->line('-------');
        $this->line(Application::getVersion()->kernel());
        $this->line('-------');
        $this->write('created by Youssef Had (');
        $this->question('youssefhad2@gmail.com - www.facebook.com/yussef.had', true);
        $this->line(')');
        $this->write('Website ');
        $this->question('www.github.com/vinala/vinala');
        $this->line('');
    }
908547
protected function initDefaultFiles()
    {
        $logDir = $this->getParam(DirectoryKeys::VAR_LOG) . DIRECTORY_SEPARATOR;
        $this->setParam(FileKeys::APPSERVER_ERRORS_LOG, ParamNode::TYPE_STRING, $logDir . 'appserver-errors.log');
        $this->setParam(FileKeys::APPSERVER_ACCESS_LOG, ParamNode::TYPE_STRING, $logDir . 'appserver-access.log');
    }
624392
public function warmUp($cacheDir)
    {
        $dir = $cacheDir.'/victoire/Entity';
        $file = $dir.'/EntityProxy.php';

        if (!file_exists($dir)) {
            if (false === @mkdir($dir, 0777, true)) {
                throw new \RuntimeException(sprintf('Could not create directory "%s".', $dir));
            }
        }

        $generator = new EntityProxyGenerator($this->businessEntityHelper, $this->fileLocator);
        $cacheContent = $generator->generate();

        $this->writeCacheFile($file, $cacheContent);
        if (!class_exists('Victoire\\Bundle\\CoreBundle\\Entity\\EntityProxy')) {
            include_once $file;
        }
    }
410471
private function recursiveScan($startFolder) {
		if (is_file($startFolder)) {
			$this->files[] = $startFolder;
			return;
		}
		$contents = scandir($startFolder);
		foreach ($contents as $content) {
			if (strpos($content, '.') === 0) {
				continue;
			}

			$path = $startFolder.DIRECTORY_SEPARATOR.$content;
			if (is_dir($path)) {
				$this->recursiveScan($path);
			} else {
				$fileExtension = pathinfo($content, PATHINFO_EXTENSION);
				if (strlen($fileExtension) == 0 || !in_array($fileExtension, $this->getFileExtensions())) {
					continue;
				}
				$this->files[] = $path;
			}
		}
	}
63934
public function warmUp($cacheDir): void
    {
        if ($this->configLoader instanceof WarmableInterface) {
            $this->configLoader->warmUp($cacheDir);
        }
    }
1323994
public function run()
    {
        $homedir = $this->parameter->getOption('homedir');
        $homedir = ltrim($homedir, DS);

        $homedir_actual = $this->path->getDir($homedir);

        $this->output->writeln([
            "Parable initialization script",
            "-----------------------------------",
            "This script will initialize Parable's structure.",
            "",
            "The full 'home directory' will be '<green>{$homedir_actual}</green>',",
            "but you can use the --homedir option to change this.",
            "",
            "Example: <yellow>parable init-structure --homedir=http_docs</yellow>",
            "",
            "<red>WARNING</red>",
            "This will overwrite existing files without notice!",
        ]);

        if (file_exists($this->path->getDir('app')) && file_exists($this->path->getDir('public'))) {
            $this->output->writeBlock('Note: It looks like you already have a structure initialized!', 'info');
        } else {
            $this->output->newline();
        }

        for (;;) {
            $this->output->write('Do you want to continue? [y/N] ');
            if ($this->input->getYesNo(false)) {
                break;
            } else {
                $this->output->writeln(['', '<red>You chose not to continue.</red>', '']);
                return $this;
            }
        }

        $this->output->newline();
        $this->output->write('Creating folder structure: ');

        $dirs = [
            'app',
            'app/Command',
            'app/Config',
            'app/Controller',
            'app/Init',
            'app/Model',
            'app/Routing',
            'app/View',
            'app/View/Home',
            $homedir,
        ];

        foreach ($dirs as $dir) {
            if (!file_exists($this->path->getDir($dir))) {
                mkdir($this->path->getDir($dir));
            }
            $this->output->write('.');
        }

        $this->output->writeln(" <green>OK</green>");

        $this->output->write('Copying files: ');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/.htaccess"),
            $this->path->getDir(".htaccess")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/dynamicReturnTypeMeta.json"),
            $this->path->getDir("dynamicReturnTypeMeta.json")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/public/index.php_struct"),
            $this->path->getDir("{$homedir}/index.php")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/public/.htaccess"),
            $this->path->getDir("{$homedir}/.htaccess")
        );
        $this->output->write('.');

        // And we continue copying files
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/Command/HelloWorld.php_struct"),
            $this->path->getDir("app/Command/HelloWorld.php")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/Config/App.php_struct"),
            $this->path->getDir("app/Config/App.php")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/Config/Custom.php_struct"),
            $this->path->getDir("app/Config/Custom.php")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/Controller/Home.php_struct"),
            $this->path->getDir("app/Controller/Home.php")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/Init/Example.php_struct"),
            $this->path->getDir("app/Init/Example.php")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/Model/User.php_struct"),
            $this->path->getDir("app/Model/User.php")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/Routing/App.php_struct"),
            $this->path->getDir("app/Routing/App.php")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/View/Home/index.phtml_struct"),
            $this->path->getDir("app/View/Home/index.phtml")
        );
        $this->output->write('.');
        copy(
            $this->path->getDir("{$this->vendor_path}/structure/app/View/Home/test.phtml_struct"),
            $this->path->getDir("app/View/Home/test.phtml")
        );
        $this->output->write('.');

        // If the homedir isn't 'public', change the values in Config\App.php and .htaccess.
        if ($homedir !== 'public') {
            $config = file_get_contents($this->path->getDir('app/Config/App.php'));
            $config = str_replace('"homedir" => "public"', '"homedir" => "' . $homedir . '"', $config);
            file_put_contents($this->path->getDir('app/Config/App.php'), $config);
            $this->output->write('.');

            $htaccess = file_get_contents($this->path->getDir('.htaccess'));
            $htaccess = str_replace("public/$1", "{$homedir}/$1", $htaccess);
            file_put_contents($this->path->getDir('.htaccess'), $htaccess);
        }
        $this->output->write('.');

        $this->output->writeln(' <green>OK</green>');

        $this->output->writeln(['', '<green>Completed!</green>', '']);
        return $this;
    }
163317
public function start($args)
    {
        parent::start($args);
        if (!$this->_header) {
            return;
        }
        $this->write($this->kahlan() . "\n\n");
        $this->write($this->kahlanBaseline() . "\n\n", 'dark-grey');
        $this->write("src directory  : ", 'blue');
        $this->write(join(', ', array_map('realpath', $this->_srcDir)) . "\n");
        $this->write("spec directory : ", 'blue');
        $this->write(join(', ', array_map('realpath', $this->_specDir)) . "\n");
    }
1118016
public static function db_init($dir)
    {
        $db = self::db();

        $file = $dir . '/' . $db->db_provider . '.initial.sql';
        if (!file_exists($file)) {
            rcube::raise_error("DDL file $file not found", false, true);
        }

        echo "Creating database schema... ";

        if ($sql = file_get_contents($file)) {
            if (!$db->exec_script($sql)) {
                $error = $db->is_error();
            }
        }
        else {
            $error = "Unable to read file $file or it is empty";
        }

        if ($error) {
            echo "[FAILED]\n";
            rcube::raise_error($error, false, true);
        }
        else {
            echo "[OK]\n";
        }
    }
698080
public function getLogsTriggeredBy($startMessage)
    {
        $query = $this->connection->createQueryBuilder();

        $query->select('*')->from(Tables::PROCESS_LOG)
            ->where('start_message = :start_message')
            ->orderBy('started_at', 'DESC')
            ->setParameter('start_message', $startMessage);

        return $query->execute()->fetchAll();
    }
1072749
public function actionStart()
    {
        if ($this->clearLogs) {
            if (file_exists(static::$logFile)) {
                unlink(static::$logFile);
            }
            if (file_exists(static::$errorLogFile)) {
                unlink(static::$errorLogFile);
            }
        }

        $message = 'Starting Yii 2 Daemon ' . $this->version . '... ';

        if ($this->_getPid() === false) {
            $this->_getWorkers();
            if (!static::$_workersData) {
                $message .= 'No tasks found. Stopping!';
                echo $message . PHP_EOL;
                $this->_log($message);
                return static::EXIT_CODE_ERROR;
            }
            if ($this->_meetRequerements) {
                pcntl_signal(SIGTERM, ['inpassor\daemon\Controller', 'signalHandler']);
                pcntl_signal(SIGINT, ['inpassor\daemon\Controller', 'signalHandler']);
                pcntl_signal(SIGCHLD, ['inpassor\daemon\Controller', 'signalHandler']);
            }
        } else {
            $message .= 'Service is already running!';
            echo $message . PHP_EOL;
            $this->_log($message);
            return static::EXIT_CODE_NORMAL;
        }

        $this->_pid = $this->_meetRequerements ? pcntl_fork() : 0;
        if ($this->_pid == -1) {
            $message .= 'Could not start service!';
            echo $message . PHP_EOL;
            $this->_log($message);
            return static::EXIT_CODE_ERROR;
        } elseif ($this->_pid) {
            file_put_contents($this->_pidFile, $this->_pid);
            return static::EXIT_CODE_NORMAL;
        }
        if ($this->_meetRequerements) {
            posix_setsid();
        }

        $message .= 'OK.';
        echo $message . PHP_EOL;
        $this->_log($message);

        if ($this->_meetRequerements) {
            declare(ticks=1);
        };

        $previousSec = null;

        while (!static::$_stop) {
            $currentSec = date('s');
            $tickPlus = $currentSec === $previousSec ? 0 : 1;
            if ($tickPlus) {
                foreach (static::$_workersData as $workerUid => $workerData) {
                    if ($workerData['tick'] >= $workerData['delay']) {
                        static::$_workersData[$workerUid]['tick'] = 0;
                        $pid = 0;
                        if ($this->_meetRequerements) {
                            if (!isset(static::$workersPids[$workerUid])) {
                                static::$workersPids[$workerUid] = [];
                            }
                            $pid = (count(static::$workersPids[$workerUid]) < $workerData['maxProcesses']) ? pcntl_fork() : -2;
                        }
                        if ($pid == -1) {
                            $this->_log('Could not launch worker "' . $workerUid . '"');
                        } elseif ($pid == -2) {
                            $this->_log('Max processes exceed for launch worker "' . $workerUid . '"');
                        } elseif ($pid) {
                            static::$workersPids[$workerUid][] = $pid;
                        } else {

                            $config = ArrayHelper::merge(static::$_workersConfig[$workerUid] ?? [], [
                                'uid' => $workerUid
                            ]);

                            /** @var \inpassor\daemon\Worker $worker */
                            $worker = \Yii::createObject($config);
                            $worker->run();

                            if ($this->_meetRequerements) {
                                return static::EXIT_CODE_NORMAL;
                            }
                        }
                    }
                    static::$_workersData[$workerUid]['tick'] += $tickPlus;
                }
            }
            usleep(500000);
            $previousSec = $currentSec;
        }
        return static::EXIT_CODE_NORMAL;
    }
340722
public static function _init()
	{
		// load the file config
		\Config::load('file', true);

		// make sure the log directories exist
		try
		{
			// determine the name and location of the logfile
			$path     = \Config::get('log_path', APPPATH.'logs'.DS);
			$filename = \Config::get('log_file', null);

			if(empty($filename))
			{
				$rootpath = $path.date('Y').DS;
				$filepath = $path.date('Y/m').DS;
				$filename = $filepath.date('d').'.php';
			}
			else
			{
				$rootpath = $path;
				$filepath = $path;
				$filename = $path.$filename;
			}

			// get the required folder permissions
			$permission = \Config::get('file.chmod.folders', 0777);

			if ( ! is_dir($rootpath))
			{
				mkdir($rootpath, 0777, true);
				chmod($rootpath, $permission);
			}
			if ( ! is_dir($filepath))
			{
				mkdir($filepath, 0777, true);
				chmod($filepath, $permission);
			}

			$handle = fopen($filename, 'a');
		}
		catch (\Exception $e)
		{
			\Config::set('log_threshold', \Fuel::L_NONE);
			throw new \FuelException('Unable to create or write to the log file. Please check the permissions on '.\Config::get('log_path').'. ('.$e->getMessage().')');
		}

		if ( ! filesize($filename))
		{
			fwrite($handle, "<?php defined('COREPATH') or exit('No direct script access allowed'); ?>".PHP_EOL.PHP_EOL);
			chmod($filename, \Config::get('file.chmod.files', 0666));
		}
		fclose($handle);

		// create the monolog instance
		static::$monolog = new \Monolog\Logger('fuelphp');

		// create the streamhandler, and activate the handler
		$stream = new \Monolog\Handler\StreamHandler($filename, \Monolog\Logger::DEBUG);
		$formatter = new \Monolog\Formatter\LineFormatter("%level_name% - %datetime% --> %message%".PHP_EOL, "Y-m-d H:i:s");
		$stream->setFormatter($formatter);
		static::$monolog->pushHandler($stream);
	}
140464
public function warmUp($cacheDir)
    {

        $fs = new FileSystem();
        $fs->dumpFile($this->cacheDir . '/swagger/swagger.json', $this->swaggerBuilder->buildSwagger());
    }
1055524
public function start() {
		$project = $this->Project();
		$log = $this->log();

		$args = array(
			'projectName' => $project->Name,
			'logfile' => $this->logfile(),
			'env' => $project->getProcessEnv()
		);

		if(!$this->DeployerID) {
			$this->DeployerID = Member::currentUserID();
		}

		if($this->DeployerID) {
			$deployer = $this->Deployer();
			$message = sprintf(
				'Update repository job for %s initiated by %s (%s)',
				$project->Name,
				$deployer->getName(),
				$deployer->Email
			);
			$log->write($message);
		}

		$token = Resque::enqueue('git', 'FetchJob', $args, true);
		$this->ResqueToken = $token;
		$this->write();

		$message = sprintf('Fetch queued as job %s', $token);
		$log->write($message);
	}