Finder::findFiles('*.php') ->size('> 10kB') ->from('.') ->exclude('temp');
Author: David Grudl
Inheritance: extends Nette\Object, implements IteratorAggregate
示例#1
1
 public function beforeRender()
 {
     $dir = $this->getAbsoluteDirectory();
     $this->template->rootDir = $this->getRoot();
     $this->template->rootDirProvider = $this->rootDir;
     $this->template->fileSystemCurrent = Nette\Utils\Finder::findFiles('*')->in($dir);
 }
示例#2
0
 private function copy($dir, $targetDir)
 {
     $files = [];
     /** @var $file \SplFileInfo */
     foreach (Finder::find('*')->from($dir) as $file) {
         if ($file->isFile()) {
             $filename = $this->getRelativePath($file->getPathname(), $dir);
             $files[$filename] = $file;
         }
     }
     foreach ($files as $filename => $file) {
         $target = $targetDir . '/' . $filename;
         $dir = (new \SplFileInfo($target))->getPath();
         if (!file_exists($dir)) {
             umask(00);
             mkdir($dir, 0777, true);
         }
         if (Strings::lower($file->getExtension()) == 'zip' && extension_loaded('zlib')) {
             $archive = new \ZipArchive();
             $res = $archive->open($file->getRealPath());
             if ($res === true) {
                 $archive->extractTo($targetDir);
                 $archive->close();
             }
             continue;
         }
         @copy($file->getPathname(), $target);
     }
 }
示例#3
0
 public function run()
 {
     if (!$this->srcPath) {
         throw new \UnexpectedValueException("Please specify srcPath first.");
     }
     if (!$this->targetPath) {
         throw new \UnexpectedValueException("Please specify targetPath first.");
     }
     if (!is_dir($this->targetPath)) {
         mkdir($this->targetPath, 0777);
     }
     $lastLessEditTime = 0;
     foreach (\Nette\Utils\Finder::find("*.less")->from($this->getSrcPath()) as $file) {
         $lastLessEditTime = max($lastLessEditTime, $file->getMTime());
     }
     $lastCompileTime = 0;
     foreach (\Nette\Utils\Finder::find("*.css")->from($this->getTargetPath()) as $file) {
         $lastCompileTime = max($lastCompileTime, $file->getMTime());
     }
     $compiler = new \lessc();
     foreach ($this->getfilesMapping() as $src => $target) {
         if (!is_file($this->targetPath . "/" . $target) || $lastLessEditTime > $lastCompileTime) {
             $compiler->compileFile($this->srcPath . "/" . $src, $this->targetPath . "/" . $target);
         }
     }
 }
示例#4
0
 public function wipeCache()
 {
     $paths = [realpath($this->tempDir . '/cache'), realpath($this->tempDir . '/proxy')];
     foreach (Nette\Utils\Finder::find('*')->in($paths) as $k => $file) {
         Nette\Utils\FileSystem::delete($k);
     }
 }
 public function render()
 {
     $editor = new OpenInEditor();
     $structure = (object) array('structure' => array());
     $isAll = true;
     foreach (Finder::findFiles('*Test.php')->from($this->dir) as $file) {
         $relative = substr($file, strlen($this->dir) + 1);
         $cursor =& $structure;
         foreach (explode(DIRECTORY_SEPARATOR, $relative) as $d) {
             $r = isset($cursor->relative) ? $cursor->relative . DIRECTORY_SEPARATOR : NULL;
             $cursor =& $cursor->structure[$d];
             $path = $this->dir . DIRECTORY_SEPARATOR . $r . $d;
             $open = $path === $this->open;
             if ($open) {
                 $isAll = false;
             }
             $cursor = (object) array('relative' => $r . $d, 'name' => $d, 'open' => $open, 'structure' => isset($cursor->structure) ? $cursor->structure : array(), 'editor' => $editor->link($path, 1), 'mode' => is_file($path) ? 'file' : 'folder');
             if (!$cursor->structure and $cursor->mode === 'file') {
                 foreach ($this->loadMethod($path) as $l => $m) {
                     $cursor->structure[$m] = (object) array('relative' => $cursor->relative . '::' . $m, 'name' => $m, 'open' => $cursor->open and $this->method === $m, 'structure' => array(), 'editor' => $editor->link($path, $l), 'mode' => 'method');
                 }
             }
         }
         $cursor->name = $file->getBasename();
     }
     $this->template->isAll = ($isAll and $this->open !== false);
     $this->template->basePath = TemplateFactory::getBasePath();
     $this->template->structure = $structure->structure;
     $this->template->setFile(__DIR__ . '/StructureRenderer.latte');
     $this->template->render();
 }
 /**
  * Parse all the exception files found in /log/*.html
  * Checks if they are in log_error table, if not it includes them there
  */
 public function parseFiles()
 {
     foreach (Nette\Utils\Finder::findFiles('*.html')->in($this->logDir) as $file) {
         $lstErrorTp = $this->lstErrorTp->getByName("exception");
         $filePath = $this->getExceptionFilePath($file->getFilename());
         if (is_file($filePath)) {
             $parse = file_get_contents($filePath, false, null, -1, 600);
             $titleStart = strpos($parse, "<title>");
             $titleLineEnds = strpos($parse, "-->", $titleStart);
             $message = str_replace(array("<title>", "</title><!-- "), array("", ": "), substr($parse, $titleStart, $titleLineEnds - $titleStart));
             if (empty($message) || strlen($message) < 3) {
                 $message = "Unparsable name!";
             }
             $row = $this->logError->getTable()->where(array("log_error.del_flag" => 0, "message" => $message, "error_tp.name" => "exception", "url" => $file->getFilename(), "log_error.ins_dt" => date('Y-m-d H:i:s', $file->getMTime())))->fetch();
             if (!$row) {
                 $inserted = $this->logError->getTable()->insert(array("message" => $message, "file_content" => file_get_contents($filePath), "url" => $file->getFilename(), "ins_dt" => date('Y-m-d H:i:s', $file->getMTime()), "error_tp_id" => $lstErrorTp->id, "del_flag" => 0, "ins_process_id" => "HQ\\ExceptionService::parseFiles()"));
                 if ($inserted) {
                     unlink($filePath);
                 }
             }
         } else {
             $this->logger->logError("404", "Could not reach exception file to parse: " . $file->getFileName());
         }
     }
 }
示例#7
0
 /**
  * Search configuration files.
  * @param mixed
  * @param mixed
  */
 public function addFindConfig($dirs, $exclude = NULL)
 {
     $cache = new Caching\Cache(new Caching\Storages\FileStorage($this->getCacheDirectory()), self::Caching);
     // Search will be started only when the cache does not exist.
     if (!$cache->load(self::Caching)) {
         // Search configuration files.
         foreach (Utils\Finder::findFiles('*.neon')->from($dirs)->exclude($exclude) as $row) {
             $data[] = $row->getPathname();
         }
         foreach ($data as $row) {
             $name[] = basename($row);
         }
         // Sort found files by number and put into the cache.
         array_multisort($name, SORT_NUMERIC, $data);
         if (isset($data)) {
             $cache->save(self::Caching, $data);
         }
     }
     // Loads the data from the cache.
     if ($cache->load(self::Caching)) {
         foreach ($cache->load(self::Caching) as $files) {
             $this->addConfig($files);
         }
     }
 }
示例#8
0
 private function clearTemp()
 {
     /* @var $file SplFileInfo  */
     foreach (Finder::findFiles('*')->from($this->temp) as $file) {
         @unlink($file->getPathname());
     }
 }
示例#9
0
 public function beforeRender()
 {
     $dir = $this->getAbsoluteDirectory();
     if ($this->usageInfo) {
         $rootSize = 0;
         $rootCountFiles = 0;
         foreach (Nette\Utils\Finder::findFiles('*')->from($this->getRoot()) as $file) {
             $rootSize += $file->getSize();
             $rootCountFiles++;
         }
         $subSizes = [];
         $subCountFiles = [];
         foreach ($this->getSubdirectories() as $path => $subdir) {
             $subSizes[$path] = 0;
             $subCountFiles[$path] = 0;
             foreach (Nette\Utils\Finder::findFiles('*')->from($subdir) as $file) {
                 $subSizes[$path] += $file->getSize();
                 $subCountFiles[$path]++;
             }
         }
         $this->template->subSizes = $subSizes;
         $this->template->rootSize = $rootSize;
         $this->template->rootCountFiles = $rootCountFiles;
         $this->template->subCountFiles = $subCountFiles;
     }
     $this->template->rootDir = $this->getRoot();
     $this->template->currentDir = $dir;
     $this->template->fileSystemDirs = $this->getSubdirectories();
     $this->template->usageInfo = $this->usageInfo;
 }
 /**
  * @return array
  */
 private function getPresenters()
 {
     @SafeStream::register();
     //intentionally @ (prevents multiple registration warning)
     $tree = array();
     foreach (Finder::findFiles('*Presenter.php')->from(APP_DIR) as $path => $file) {
         $data = $this->processPresenter($file);
         if ($data === FALSE) {
             continue;
         }
         list($module, $presenter, $actions) = $data;
         $tree[$module][$presenter] = $actions;
     }
     foreach (Finder::findFiles('*.latte', '*.phtml')->from(APP_DIR) as $path => $file) {
         $data = $this->processTemplate($file);
         if ($data === FALSE) {
             continue;
         }
         list($module, $presenter, $action) = $data;
         if (!isset($tree[$module][$presenter])) {
             $tree[$module][$presenter] = array();
         }
         if (array_search($action, $tree[$module][$presenter]) === FALSE) {
             $tree[$module][$presenter][] = $action;
         }
     }
     $tree = $this->removeSystemPresenters($tree);
     return $tree;
 }
示例#11
0
 public function flush()
 {
     /** @var $file \SplFileInfo */
     foreach (Finder::findFiles('*')->in($this->getAbsolutePath()) as $file) {
         @unlink($file->getRealPath());
     }
 }
示例#12
0
 private function addWebLoader(\Nette\DI\ContainerBuilder $builder, $name, $config)
 {
     $filesServiceName = $this->prefix($name . 'Files');
     $files = $builder->addDefinition($filesServiceName)->setClass('WebLoader\\FileCollection')->setArguments(array($config['sourceDir']));
     foreach ($config['files'] as $file) {
         // finder support
         if (is_array($file) && isset($file['files']) && (isset($file['in']) || isset($file['from']))) {
             $finder = \Nette\Utils\Finder::findFiles($file['files']);
             unset($file['files']);
             foreach ($file as $method => $params) {
                 call_user_func_array(array($finder, $method), array($params));
             }
             foreach ($finder as $foundFile) {
                 $files->addSetup('addFile', array((string) $foundFile));
             }
         } else {
             $files->addSetup('addFile', array($file));
         }
     }
     $files->addSetup('addRemoteFiles', array($config['remoteFiles']));
     $compiler = $builder->addDefinition($this->prefix($name . 'Compiler'))->setClass('WebLoader\\Compiler')->setArguments(array('@' . $filesServiceName, $config['namingConvention'], $config['tempDir']));
     $compiler->addSetup('setJoinFiles', array($config['joinFiles']));
     foreach ($config['filters'] as $filter) {
         $compiler->addSetup('addFilter', array($filter));
     }
     foreach ($config['fileFilters'] as $filter) {
         $compiler->addSetup('addFileFilter', array($filter));
     }
     // todo css media
 }
示例#13
0
 public function build()
 {
     foreach (\Nette\Utils\Finder::findFiles('*.latte')->from($this->settings->template) as $template) {
         $destination = $this->settings->netteRoot . str_replace($this->settings->template, '', mb_substr($template, 0, -6));
         if (mb_strpos($destination, '\\Module') !== FALSE) {
             $destination = str_replace('\\Module', $this->settings->module ? '\\' . $this->settings->module . 'Module' : '\\', $destination);
         }
         if (mb_strpos($destination, '\\NDBT') !== FALSE && $this->settings->target !== \Utils\Constants::TARGET_NETTE_DATABASE || mb_strpos($destination, '\\D2') !== FALSE && $this->settings->target !== \Utils\Constants::TARGET_DOCTRINE2) {
             continue;
         } else {
             $destination = str_replace(['\\NDBT', '\\D2'], '\\', $destination);
         }
         if (mb_strpos($destination, '\\Table') !== FALSE) {
             foreach ($this->settings->tables as $table) {
                 $this->parameters['table'] = $table;
                 $newDestination = str_replace('\\Table', "\\{$table->sanitizedName}", $destination);
                 if (mb_strpos(basename($destination), '.') !== FALSE) {
                     $this->saveTemplate($newDestination, $this->processTemplate($template, $this->parameters));
                 } else {
                     $this->processTemplate($newDestination, $this->parameters);
                 }
             }
         } else {
             if (mb_strpos(basename($destination), '.') !== FALSE) {
                 $this->saveTemplate($destination, $this->processTemplate($template, $this->parameters));
             } else {
                 $this->processTemplate($template, $this->parameters);
             }
         }
     }
     foreach (\Nette\Utils\Finder::findFiles('*.*')->exclude('*.latte')->from($this->settings->template) as $template) {
         $destination = $this->settings->netteRoot . str_replace($this->settings->template, '', $template);
         \Nette\Utils\FileSystem::copy($template, $destination);
     }
 }
示例#14
0
 public function run()
 {
     foreach (Finder::findFiles('*Test.php')->from(__DIR__) as $fileInfo) {
         /** @var \SplFileInfo $fileInfo*/
         $baseName = $fileInfo->getBasename('.php');
         if ($baseName === 'PhpRQTest') {
             continue;
         }
         $className = 'PhpRQ\\' . $baseName;
         $reflection = new \ReflectionClass($className);
         if (!$reflection->isInstantiable()) {
             continue;
         }
         foreach ($reflection->getMethods() as $method) {
             if (!$method->isPublic() || strpos($methodName = $method->getName(), 'test') === false) {
                 continue;
             }
             $phpdoc = $method->getDocComment();
             if ($phpdoc !== false && ($providerPos = strpos($phpdoc, '@dataProvider')) !== false) {
                 $providerMethodPos = $providerPos + 14;
                 $providerMethodLen = strpos($phpdoc, "\n", $providerMethodPos) - $providerMethodPos;
                 $providerMethod = substr($phpdoc, $providerMethodPos, $providerMethodLen);
                 $testCase = new $className($this->provider->getRedisClient());
                 foreach ($testCase->{$providerMethod}() as $args) {
                     $testCase = new $className($this->provider->getRedisClient());
                     call_user_func_array([$testCase, $methodName], (array) $args);
                 }
             } else {
                 $testCase = new $className($this->provider->getRedisClient());
                 $testCase->{$methodName}();
             }
         }
     }
 }
示例#15
0
 /**
  * @param string $path
  * @param string $find
  * @param int $depth
  */
 public function addAutoloadConfig($path, $find = 'config.neon', $depth = -1)
 {
     // Development
     if (!$this->cacheConfig && $this->isDevelopment()) {
         foreach (Finder::find($find)->from($path)->limitDepth($depth) as $file) {
             $this->addConfig((string) $file);
         }
         return;
     }
     // Production
     $directory = $this->parameters['tempDir'] . '/cache/configs';
     $cachePath = $directory . '/' . Strings::webalize(str_replace(dirname($this->parameters['appDir']), '', $path)) . '.neon';
     if (file_exists($cachePath)) {
         $this->addConfig($cachePath);
         return;
     }
     $encoder = new Encoder();
     $decoder = new Decoder();
     @mkdir($directory);
     $content = [];
     foreach (Finder::find($find)->from($path)->limitDepth($depth) as $file) {
         $content = Helpers::merge($content, $decoder->decode(file_get_contents($file)));
     }
     file_put_contents($cachePath, $encoder->encode($content));
     $this->addConfig($cachePath);
 }
示例#16
0
 /**
  * Generate dir structure tree
  *
  * @param string  $dir       Path to root dir
  * @param boolean $showFiles Show files
  *
  * @return \Nette\Utils\Html
  */
 private function generateTree($dir, $showFiles = true)
 {
     if (!is_dir($dir)) {
         throw new \Exception("Directory '{$dir}' does not exist!");
     }
     if ($showFiles) {
         $files = Finder::find("*")->in($dir);
     } else {
         $files = Finder::findDirectories("*")->in($dir);
     }
     $list = Html::el("ul");
     foreach ($files as $file) {
         // Create file link
         $link = Html::el("a")->href($file->getRealPath())->title($file->getRealPath());
         if ($file->isDir()) {
             $link[0] = Html::el("i")->class("icon-folder-open");
         } else {
             $link[0] = Html::el("i")->class("icon-file");
         }
         $link[1] = Html::el("span", Strings::truncate($file->getFileName(), 30));
         // Create item in list
         $item = Html::el("li");
         $item[0] = $link;
         if ($file->isDir()) {
             $item[1] = $this->generateTree($file->getPathName(), $showFiles);
         }
         $list->add($item);
     }
     return $list;
 }
示例#17
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     Debugger::timer();
     $output->writeln('Running tests...');
     $runner = new Runner();
     $path = realpath($input->getArgument('path'));
     if ($path) {
         if (is_dir($path)) {
             $runner->setTestsRoot($path . '/');
             foreach (Finder::findFiles('*.php')->exclude('tester.php')->from($path) as $path => $fileInfo) {
                 $basePath = Helpers::stripExtension($path);
                 $runner->addTest($basePath);
             }
         } else {
             $basePath = Helpers::stripExtension($path);
             $runner->addTest($basePath);
         }
     } else {
         if ($path = realpath($input->getArgument('path') . '.php')) {
             $basePath = Helpers::stripExtension($path);
             $runner->addTest($basePath);
         } else {
             $output->writeln("<error>The given path isn't valid</error>");
             return 1;
         }
     }
     $runner->setOutput($output);
     $runner->runTests();
     $output->writeln('Completed in ' . round(Debugger::timer(), 2) . ' seconds');
     if ($runner->failed()) {
         return 1;
     } else {
         return 0;
     }
 }
示例#18
0
 /**
  * @param array $resources
  * @param bool $minify
  * @param string $baseDir
  * @throws AssetsException
  * @return array
  */
 public function getAssets(array $resources, $minify, $baseDir)
 {
     $config = [];
     $return = [];
     foreach ($resources as $resource) {
         $contents = file_get_contents($resource);
         $decompiled = Strings::endsWith($resource, '.json') ? json_decode($contents, TRUE) : Neon::decode($contents);
         $config = \Nette\DI\Config\Helpers::merge($config, $decompiled);
     }
     foreach ($config as $moduleArray) {
         foreach ($moduleArray as $type => $typeArray) {
             if (!isset(self::$supportTypes[$type])) {
                 throw new AssetsException("Found section '{$type}', but expected one of " . implode(', ', array_keys(self::$supportTypes)));
             }
             foreach ($typeArray as $minified => $assets) {
                 if ($minify) {
                     $return[$type][$minified] = TRUE;
                     continue;
                 }
                 foreach ((array) $assets as $row) {
                     if (strpos($row, '*') !== FALSE) {
                         /** @var \SplFileInfo $file */
                         foreach (Finder::findFiles(basename($row))->in($baseDir . '/' . dirname($row)) as $file) {
                             $return[$type][$minified][] = dirname($row) . '/' . $file->getBasename();
                         }
                     } else {
                         $return[$type][$minified][] = $row;
                     }
                 }
             }
         }
     }
     return $return;
 }
示例#19
0
 /**
  * @param Configurator $configurator
  */
 protected function loadConfigFiles(Configurator $configurator)
 {
     if ($this->autoloadConfig === TRUE || is_array($this->autoloadConfig)) {
         $scanDirs = $this->autoloadConfig === TRUE ? [$this->appDir] : $this->autoloadConfig;
         $cache = $this->createCache();
         $files = $cache->load(self::CACHE_NAMESPACE);
         if ($files === NULL) {
             $files = [0 => []];
             foreach (Finder::findFiles('*.neon')->from($scanDirs) as $path => $file) {
                 $content = Neon::decode(file_get_contents($path));
                 if (!is_array($content) || !array_key_exists('autoload', $content)) {
                     continue;
                 }
                 $autoload = Arrays::get($content, ['autoload', 0], FALSE);
                 if ($autoload === FALSE) {
                     continue;
                 }
                 $autoload = is_int($autoload) ? $autoload : 0;
                 if (!isset($files[$autoload])) {
                     $files[$autoload] = [];
                 }
                 $files[$autoload][] = $path;
             }
             $cache->save(self::CACHE_NAMESPACE, $files);
         }
         foreach ($files as $priorityFiles) {
             foreach ($priorityFiles as $config) {
                 $configurator->addConfig($config);
             }
         }
     }
     foreach ($this->configs as $config) {
         $configurator->addConfig($config);
     }
 }
示例#20
0
 /**
  * {@inheritdoc}
  */
 private function loadFromDirectory($path)
 {
     $files = [];
     foreach (Finder::find(['*.neon', '*.yaml', '*.yml'])->from($path) as $file) {
         $files[] = $file;
     }
     return $this->load($files);
 }
示例#21
0
 /**
  * @param $param
  * @throws FileNotFoundException
  * @return string
  */
 public function find($param)
 {
     foreach (Finder::findFiles($param)->from($this->assetsDir) as $file) {
         /** @var \SplFileInfo $file */
         return $file->getPathname();
     }
     throw new FileNotFoundException("File {$param} not found.");
 }
示例#22
0
 /**
  * Find CSS files.
  * @param  mixed
  * @return array
  */
 private function findCssFiles($path)
 {
     $data = [];
     foreach (Finder::findFiles('*.css')->from($path) as $row) {
         $data[] = $row->getPathname();
     }
     return $data;
 }
 public function getAvailableThemes()
 {
     $directories = array_keys(iterator_to_array(Finder::findDirectories('*')->in($this->getThemesDir())));
     array_walk($directories, function (&$item) {
         $item = basename($item);
     });
     return $directories;
 }
示例#24
0
 public function clean($time)
 {
     foreach (\Nette\Utils\Finder::find('*')->exclude('.*')->from($this->dir)->childFirst() as $file) {
         if ($file->isFile() && $file->getATime() < $time) {
             unlink((string) $file);
         }
     }
 }
 private function getUnimportedTasks($folder)
 {
     $importedExperiments = \Nette\Utils\Finder::findDirectories('*')->in($folder)->imported(TRUE)->toArray();
     if (count($importedExperiments) == 0) {
         return array();
     }
     return \Nette\Utils\Finder::findDirectories('*')->in($importedExperiments)->imported(FALSE)->aborted(FALSE);
 }
示例#26
0
 protected function _after()
 {
     foreach (\Nette\Utils\Finder::findFiles('*')->from(__DIR__ . '/../_data/tmp') as $file) {
         @unlink((string) $file);
     }
     @copy(__DIR__ . '/../_data/image.gif', __DIR__ . '/../_data/assets/original/image.gif');
     // move in FileUpload
 }
示例#27
0
 /**
  * Load filters
  * @return array
  */
 public function loadFilters()
 {
     $filters = array();
     foreach (Finder::findFiles('*.php')->in($this->filterDir) as $file) {
         require_once $file->getRealPath();
     }
     return $filters;
 }
示例#28
0
 /**
  * @param array of extensionName
  * @return array path => Migration\File
  */
 public function find(array $extensions)
 {
     $this->extensionPaterns = array_combine($extensions, array_map(function ($name) {
         return '#' . preg_quote('.' . $name, '#') . '$#si';
     }, $extensions));
     $files = iterator_to_array(Finder::findFiles(NULL)->in($this->directory));
     ksort($files);
     return array_filter(array_map(array($this, 'createMigrationFile'), $files));
 }
示例#29
0
 /**
  * @param string $path
  *
  * @return array
  */
 private function loadConfigFiles($path)
 {
     $files = [];
     /** @var \SplFileInfo $file */
     foreach (Nette\Utils\Finder::find('config/hotplug.neon')->from($path) as $file) {
         $files[] = $file->getPathname();
     }
     return $files;
 }
示例#30
0
 public function preRemove(File $fileEntity, LifecycleEventArgs $args)
 {
     $dir = $this->publicDir . '/_cache';
     if (is_dir($dir)) {
         foreach (Finder::findFiles('*/*/*/' . $fileEntity->getName())->from($dir) as $file) {
             unlink($file->getPathname());
         }
     }
 }