Esempio n. 1
0
 public function run($folder)
 {
     set_time_limit(0);
     $this->useColors = PHP_SAPI === 'cli' && (function_exists('posix_isatty') && posix_isatty(STDOUT) || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE);
     if ($this->readOnly) {
         echo "Running in read-only mode\n";
     }
     echo "Scanning folder {$this->color('white', $folder)}\n";
     $counter = 0;
     $success = TRUE;
     foreach (Nette\Utils\Finder::findFiles($this->accept)->exclude($this->ignore)->from($folder)->exclude($this->ignore) as $file) {
         echo str_pad(str_repeat('.', $counter++ % 40), 40), "\r";
         $orig = $s = file_get_contents($file);
         $this->file = ltrim(substr($file, strlen($folder)), '/\\');
         $this->error = FALSE;
         foreach ($this->tasks as $task) {
             $res = $task($this, $s);
             if ($this->error) {
                 $success = FALSE;
                 continue 2;
             } elseif (is_string($res)) {
                 $s = $res;
             }
         }
         if ($s !== $orig && !$this->readOnly) {
             file_put_contents($file, $s);
         }
     }
     echo str_pad('', 40), "\rDone.\n";
     return $success;
 }
Esempio n. 2
0
	public function __construct($path)
	{
		$cacheFile = $path . '/routes.php';
		if (is_file($cacheFile = $path . '/routes.php')) {
			$routes = require $cacheFile;
		} else {
			$routes = array();
			foreach (Nette\Utils\Finder::findFiles('*.latte')->from($path) as $file) {
				$latte = new Latte\Engine;
				$macroSet = new Latte\Macros\MacroSet($latte->parser);
				$macroSet->addMacro('url', function($node) use (&$routes, $file) {
					$routes[$node->args] = (string) $file;
				});
				$latte->__invoke(file_get_contents($file));
			}
			file_put_contents($cacheFile, '<?php return ' . var_export($routes, TRUE) . ';');
		}

		foreach ($routes as $mask => $file) {
			$this[] = new Routers\Route($mask, function($presenter) use ($file) {
				return $presenter->createTemplate(NULL, function() {
					$latte = new Nette\Latte\Engine;
					$macroSet = new Latte\Macros\MacroSet($latte->parser);
					$macroSet->addMacro('url', '');
					return $latte;
				})->setFile($file);
			});
		}
	}
 public function createComponentJs()
 {
     $files = new \WebLoader\FileCollection(WWW_DIR . '/js');
     $loadedData = iterator_to_array(Nette\Utils\Finder::findFiles('*.js')->exclude("angular*")->from(WWW_DIR . '/js'));
     ksort($loadedData);
     $files->addFiles($loadedData);
     $compiler = \WebLoader\Compiler::createJsCompiler($files, WWW_DIR . '/webtemp');
     // při development módu vypne spojování souborů
     $dev = $this->context->parameters['productionMode'];
     $compiler->setJoinFiles($dev);
     return new \WebLoader\Nette\JavaScriptLoader($compiler, $this->template->basePath . '/webtemp');
 }
Esempio n. 4
0
 public function scanRoutes($path)
 {
     $routes = [];
     $latte = new Latte\Engine();
     $macroSet = new Latte\Macros\MacroSet($latte->getCompiler());
     $macroSet->addMacro('url', function ($node) use(&$routes, &$file) {
         $routes[$node->args] = (string) $file;
     }, NULL, NULL, $macroSet::ALLOWED_IN_HEAD);
     foreach (Nette\Utils\Finder::findFiles('*.latte')->from($path) as $file) {
         $latte->compile($file);
     }
     return $routes;
 }
Esempio n. 5
0
 public function run($folder)
 {
     set_time_limit(0);
     if ($this->readOnly) {
         echo "Running in read-only mode\n";
     }
     echo "Scanning folder {$folder}\n";
     $this->replaces = array_change_key_case($this->replaces);
     $this->deprecated = array_change_key_case($this->deprecated);
     $counter = 0;
     foreach (Nette\Utils\Finder::findFiles('*.php')->from($folder)->exclude(['.*', '*.tmp', 'tmp', 'temp', 'log']) as $file) {
         echo str_pad(str_repeat('.', $counter++ % 40), 40), "\r";
         $this->fileName = ltrim(str_replace($folder, '', $file), '/\\');
         $orig = file_get_contents($file);
         $new = $this->processFile($orig);
         if ($new !== $orig) {
             $this->report($this->readOnly ? 'FOUND' : 'FIXED', implode(', ', array_keys($this->found)));
             if (!$this->readOnly) {
                 file_put_contents($file, $new);
             }
         }
     }
     echo "\nDone.";
 }
Esempio n. 6
0
<?php

if (isset($_GET['styleguide'])) {
    view('styleguide', ['components' => Nette\Utils\Finder::findFiles('*.latte')->from(THEME_VIEWS_DIR . '/components')]);
    exit;
}
// latte file has same name as this file
view(basename(__FILE__, '.php'), ['greeting' => 'Hello']);
 private function getIgnoredFiles($path)
 {
     $toIgnoreFiles = '';
     foreach (Nette\Utils\Finder::findFiles('.gitignore')->from($path) as $giFile) {
         $filePath = str_replace('.gitignore', '', $giFile);
         $contents = explode("\n", trim(file_get_contents($giFile)));
         foreach ($contents as $ignoredLine) {
             $ignoredLine = trim($ignoredLine);
             $prefix = '';
             if (mb_substr($ignoredLine, 0, 1) === '!') {
                 $prefix = '!';
                 $ignoredLine = mb_substr($ignoredLine, 1);
             }
             if ($ignoredLine === '*') {
                 $ignoredLine = mb_substr($ignoredLine, 0, -2);
             }
             $toIgnoreFiles .= $prefix . $filePath . $ignoredLine . "\n";
         }
     }
     return $toIgnoreFiles;
 }
Esempio n. 8
0
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->createRobotLoader()->addDirectory(APP_DIR)->register();
//Extras\Debug\ComponentTreePanel::register();
// Create Dependency Injection container from config.neon file
$configurator->addConfig(CONFIG_DIR . '/config.neon');
//$configurator->addConfig(CONFIG_DIR . '/config2.neon');
$loader = new Nette\Config\Loader();
$serverName = $_SERVER['SERVER_NAME'];
//dump($serverName);
//die();
$selectedModuleNs = NULL;
$selectedHost = NULL;
$selectedProjectPath = NULL;
$selectedFile = NULL;
// detect project
foreach (Nette\Utils\Finder::findDirectories('*Module')->in(APP_DIR . '/FrontModule') as $projectPath => $file) {
    // read project config
    $projectFile = $projectPath . '/config/project.neon';
    $configFile = $projectPath . '/config/config.neon';
    //dump($file->getBaseName());
    if (is_file($projectFile) && is_file($configFile)) {
        $c = $loader->load($projectFile);
        foreach ($c['modules'] as $moduleNs => $moduleData) {
            foreach ($moduleData['hosts'] as $host) {
                if (preg_match("#.*{$serverName}\\/.*#", $host)) {
                    $selectedModuleNs = $moduleNs;
                    $selectedHost = $host;
                    $selectedProjectPath = $projectPath;
                    $selectedFile = $file;
                    break;
                }