find() 공개 정적인 메소드

Begins search for files matching mask and all directories.
public static find ( $masks ) : self
리턴 self
예제 #1
0
파일: PathSelect.php 프로젝트: ixtrum/forms
 /**
  * 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;
 }
예제 #2
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);
     }
 }
예제 #3
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);
 }
예제 #4
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);
     }
 }
예제 #5
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);
         }
     }
 }
예제 #6
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);
         }
     }
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 private function loadFromDirectory($path)
 {
     $files = [];
     foreach (Finder::find(['*.neon', '*.yaml', '*.yml'])->from($path) as $file) {
         $files[] = $file;
     }
     return $this->load($files);
 }
예제 #8
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;
 }
예제 #9
0
 /**
  * @param array $sourceFiles
  * @return int
  */
 protected function getModifyTime($sourceFiles)
 {
     $time = 0;
     foreach ($sourceFiles as $sourceFile) {
         /** @var \SplFileInfo $file */
         foreach (Finder::find("*.scss")->from(dirname($sourceFile)) as $file) {
             $time = max($time, $file->getMTime());
         }
     }
     return $time;
 }
예제 #10
0
 public function cleanSessions()
 {
     foreach (Finder::find('*')->in($this->sessionsDir) as $file) {
         $path = $file->getPathname();
         if (is_dir($path)) {
             File::rmdir($path, TRUE);
         } else {
             unlink($path);
         }
     }
 }
예제 #11
0
function clearTemp($directory = TEMP_DIR)
{
    $files = \Nette\Utils\Finder::find('*')->exclude('.*')->in($directory);
    foreach ($files as $path => $file) {
        if ($file->isDir()) {
            clearTemp($path);
            @rmdir($path);
        } else {
            @unlink($path);
        }
    }
    @rmdir($directory);
}
 /**
  * @param string $path
  */
 public static function purgeDir($path)
 {
     if (!is_dir($path)) {
         mkdir($path, 0755, TRUE);
     }
     foreach (Nette\Utils\Finder::find('*')->from($path)->childFirst() as $item) {
         /** @var \SplFileInfo $item */
         if ($item->isDir()) {
             rmdir($item);
         } elseif ($item->isFile()) {
             unlink($item);
         }
     }
 }
예제 #13
0
 /**
  * @param string $path
  */
 public function purgeDir($path)
 {
     if (!is_dir($path)) {
         mkdir($path, 0755, true);
     }
     foreach (Finder::find('*')->from($path)->childFirst() as $item) {
         /** @var \SplFileInfo $item */
         if ($item->isDir()) {
             rmdir($item);
         } else {
             unlink($item);
         }
     }
 }
예제 #14
0
 public function run(InputInterface $input, OutputInterface $output)
 {
     $latte = $this->getHelper('container')->getByType(ITemplateFactory::class)->createTemplate()->getLatte();
     $counter = [0, 0];
     foreach (Finder::find('*.latte')->from($this->source) as $name => $file) {
         try {
             $latte->warmupCache($name);
             $counter[0]++;
         } catch (\Exception $e) {
             $counter[1]++;
         }
     }
     $output->writeln(sprintf('%s templates successfully compiled, %s failed.', $counter[0], $counter[1]));
 }
 /**
  * Akce pro smazání obsahu adresáře, do kterého se ukládá aplikační cache
  * @throws \Nette\Application\AbortException
  */
 public function actionClean()
 {
     $deletedArr = [];
     $errorArr = [];
     foreach (Finder::find('*')->in(CACHE_DIRECTORY) as $file => $info) {
         try {
             FileSystem::delete($file);
             $deletedArr[] = $file;
         } catch (\Exception $e) {
             $errorArr[] = $file;
         }
     }
     $response = ['state' => empty($errorArr) ? 'OK' : 'error', 'deleted' => $deletedArr, 'errors' => $errorArr];
     $this->sendJson($response);
 }
예제 #16
0
파일: FileTools.php 프로젝트: h4kuna/static
 /**
  * Delete all files in directory
  *
  * @deprecated
  * @param $path directory to clean
  * @param $recursive delete files in subdirs
  * @param $delDirs delete subdirs
  * @param $delRoot delete root directory
  * @return bool
  */
 public static function cleanDirRecursive($path, $delRoot = TRUE)
 {
     foreach (Finder::find('*')->in($path) as $item) {
         $p = $item->getPathname();
         if ($item->isDir()) {
             self::cleanDirRecursive($p);
         } else {
             \unlink($p);
         }
     }
     if ($delRoot) {
         \rmdir($path);
     }
     return TRUE;
 }
예제 #17
0
파일: File.php 프로젝트: svobodni/web
 /**
  * Removes directory.
  *
  * @static
  * @param string $dirname
  * @param bool $recursive
  * @return bool
  */
 public static function rmdir($dirname, $recursive = FALSE)
 {
     if (!$recursive) {
         return rmdir($dirname);
     }
     $dirContent = Finder::find('*')->from($dirname)->childFirst();
     foreach ($dirContent as $file) {
         if ($file->isDir()) {
             @rmdir($file->getPathname());
         } else {
             @unlink($file->getPathname());
         }
     }
     @rmdir($dirname);
     return TRUE;
 }
예제 #18
0
 public function build()
 {
     $hash = md5(serialize($this->dirs)) . md5(serialize($this->files));
     if ($this->cache->load('hash') !== $hash) {
         $files = [];
         $css = [];
         $js = [];
         // Find files in dirs
         foreach ($this->dirs as $dir) {
             $dir = $this->fixPath($dir);
             if (in_array($dir, $this->ignored)) {
                 continue;
             }
             $tmp = [];
             foreach (Finder::find($this->supported)->from($dir) as $file) {
                 if ($file->isDir()) {
                     continue;
                 }
                 $tmp[$file->getRealPath()] = $file->getRealPath();
             }
             sort($tmp);
             $files = array_merge($files, $tmp);
         }
         // Merge custom added files and found files
         $files = array_merge($files, $this->files);
         foreach ($files as $file) {
             $file = $this->fixPath($file);
             if (in_array($file, $this->ignored)) {
                 continue;
             }
             $file = new \SplFileInfo($file);
             $path = Strings::substring($file->getRealPath(), strlen($this->resourcesDir));
             $path = Strings::replace($path, '#\\\\#', '/');
             switch ($file->getExtension()) {
                 case 'css':
                     $css[] = $path;
                     break;
                 case 'js':
                     $js[] = $path;
                     break;
             }
         }
         $this->cache->save('hash', $hash);
         $this->cache->save('files', [$css, $js]);
     }
     list($this->css, $this->js) = $this->cache->load('files');
 }
예제 #19
0
 /**
  * @param $module
  * @param null $layout
  * @param null $subdir
  * @return array
  */
 public function getTemplatesByModule($module, $layout = NULL, $subdir = NULL)
 {
     $data = array();
     $prefix = $layout ? "/{$layout}" : '';
     $suffix = $subdir ? "/{$subdir}" : '';
     $path = $this->modules[$module]['path'] . "/Resources/layouts{$prefix}{$suffix}";
     if (file_exists($path)) {
         foreach (Finder::find("*")->in($path) as $file) {
             if ($file->getBasename() === '@layout.latte' || !is_file($file->getPathname())) {
                 continue;
             }
             $p = str_replace('/', '.', $subdir);
             $data[($p ? $p . '.' : '') . substr($file->getBasename(), 0, -6)] = "@{$module}Module{$prefix}{$suffix}/{$file->getBasename()}";
         }
     }
     return $data;
 }
예제 #20
0
 public function afterCompile(ClassType $class)
 {
     /**
      * old template must regenerate
      * if you use translate macro {_''} and after start this extension, you will see only exception
      * Nette\MemberAccessException
      * Call to undefined method Nette\Templating\FileTemplate::translate()
      * let's clear temp directory
      * _Nette.FileTemplate
      */
     $temp = $this->containerBuilder->parameters['tempDir'] . '/cache/latte';
     if (file_exists($temp) && $this->containerBuilder->parameters['debugMode']) {
         foreach (Finder::find('*')->in($temp) as $file) {
             /* @var $file \SplFileInfo */
             @unlink($file->getPathname());
         }
     }
 }
예제 #21
0
 /**
  * Removes items from the cache by conditions & garbage collector.
  *
  * @param  array  conditions
  *
  * @return void
  */
 public function clean(array $conds)
 {
     $all = !empty($conds[Cache::ALL]);
     $collector = empty($conds);
     // cleaning using file iterator
     if ($all || $collector) {
         $now = time();
         foreach (Nette\Utils\Finder::find('_*')->from($this->dir)->childFirst() as $entry) {
             $path = (string) $entry;
             if ($entry->isDir()) {
                 // collector: remove empty dirs
                 @rmdir($path);
                 // @ - removing dirs is not necessary
                 continue;
             }
             if ($all) {
                 $this->delete($path);
             } else {
                 // collector
                 $meta = $this->readMetaAndLock($path, LOCK_SH);
                 if (!$meta) {
                     continue;
                 }
                 if (!empty($meta[self::META_DELTA]) && filemtime($meta[self::FILE]) + $meta[self::META_DELTA] < $now || !empty($meta[self::META_EXPIRE]) && $meta[self::META_EXPIRE] < $now) {
                     $this->delete($path, $meta[self::HANDLE]);
                     continue;
                 }
                 flock($meta[self::HANDLE], LOCK_UN);
                 fclose($meta[self::HANDLE]);
             }
         }
         if ($this->journal) {
             $this->journal->clean($conds);
         }
         return;
     }
     // cleaning using journal
     if ($this->journal) {
         foreach ($this->journal->clean($conds) as $file) {
             $this->delete($file);
         }
     }
 }
예제 #22
0
 /**
  * @param Nette\Application\UI\Form $form
  * @param                           $values
  */
 public function deleteFormSubmitted(Nette\Application\UI\Form $form, $values)
 {
     $goToDir = $this->getDirectory();
     $name = $this->getAbsoluteDirectory();
     if ($this->fileManager->isFeatureEnabled('deleteDir') && !$this->fileManager->isRootSelected() && $form->submitted === $form['delete']) {
         Nette\Utils\FileSystem::delete($this->getAbsoluteDirectory());
         $goToDir = Zax\Utils\PathHelpers::getParentDir($this->getDirectory());
         $this->onDirDelete($name);
         $this->flashMessage('fileManager.alert.dirDeleted', 'success');
     } else {
         if ($this->fileManager->isFeatureEnabled('truncateDir') && $form->submitted === $form['truncate']) {
             foreach (Nette\Utils\Finder::find('*')->in($this->getAbsoluteDirectory()) as $k => $file) {
                 Nette\Utils\FileSystem::delete($k);
             }
             $this->onDirTruncate($name);
             $this->flashMessage('fileManager.alert.dirTruncated', 'success');
         }
     }
     $this->fileManager->setDirectory($goToDir);
     $this->fileManager->go('this', ['dir' => $goToDir, 'view' => 'Default', 'directoryList-view' => 'Default']);
 }
예제 #23
0
 /**
  * @param array $params
  * @return IResponse
  */
 public function execute(array $params = [])
 {
     $vars = $this->parameters['vars'];
     $theme = $this->parameters['theme'];
     $output = $this->parameters['output'];
     // Force create folder
     Helpers::purge($output);
     // Create Latte
     $template = $this->templateFactory->createTemplate();
     // Convert all latte files to static html files
     foreach (Finder::find('*.latte')->in(implode(', ', (array) $theme['pages'])) as $file => $splfile) {
         /** @var \SplFileInfo $splfile */
         $template->setFile($splfile->getRealPath());
         $template->setParameters($params);
         $template->setParameters($vars);
         file_put_contents($output . DS . $splfile->getBasename('.latte') . '.html', $template->__toString());
     }
     // Move all files/folders to output
     foreach ($theme['copy'] as $copy) {
         FileSystem::copy($copy, $output . DS . str_replace($theme['pages'], NULL, $copy), TRUE);
     }
     return new TextResponse("Generate: done");
 }
예제 #24
0
remove($key){unset($this->locks[$key]);$this->delete($this->getCacheFile($key));}function
clean(array$conds){$all=!empty($conds[Cache::ALL]);$collector=empty($conds);if($all||$collector){$now=time();foreach(Nette\Utils\Finder::find('_*')->from($this->dir)->childFirst()as$entry){$path=(string)$entry;if($entry->isDir()){@rmdir($path);continue;}if($all){$this->delete($path);}else{$meta=$this->readMetaAndLock($path,LOCK_SH);if(!$meta){continue;}if((!empty($meta[self::META_DELTA])&&filemtime($meta[self::FILE])+$meta[self::META_DELTA]<$now)||(!empty($meta[self::META_EXPIRE])&&$meta[self::META_EXPIRE]<$now)){$this->delete($path,$meta[self::HANDLE]);continue;}flock($meta[self::HANDLE],LOCK_UN);fclose($meta[self::HANDLE]);}}if($this->journal){$this->journal->clean($conds);}return;}if($this->journal){foreach($this->journal->clean($conds)as$file){$this->delete($file);}}}protected
예제 #25
0
파일: Generator.php 프로젝트: sirone/apigen
 /**
  * Deletes a directory.
  *
  * @param string $path Directory path
  * @return boolean
  */
 private function deleteDir($path)
 {
     if (!is_dir($path)) {
         return true;
     }
     foreach (Nette\Utils\Finder::find('*')->from($path)->childFirst() as $item) {
         if ($item->isDir()) {
             if (!@rmdir($item)) {
                 return false;
             }
         } elseif ($item->isFile()) {
             if (!@unlink($item)) {
                 return false;
             }
         }
     }
     if (!@rmdir($path)) {
         return false;
     }
     return true;
 }
 public function deleteDir($directory)
 {
     $dirContent = Nette\Utils\Finder::find('*')->from($directory)->childFirst();
     foreach ($dirContent as $file) {
         if ($file->isDir()) {
             @rmdir($file->getPathname());
         } else {
             @unlink($file->getPathname());
         }
     }
     @unlink($directory);
 }
 /**
  * Funkce pro provedení závěrečných operací
  */
 public function finallyOperations()
 {
     #region chmod
     if (!empty($this->config['finally']['chmod'])) {
         $chmodOperations = $this->config['finally']['chmod'];
         foreach ($chmodOperations as $userRights => $filesArr) {
             if (!empty($filesArr)) {
                 foreach ($filesArr as $file) {
                     try {
                         $filePath = self::getRootDirectory() . $file;
                         @chmod($filePath, '0' . $userRights);
                     } catch (\Exception $e) {
                         /*chmod chybu ignorujeme...*/
                     }
                 }
             }
         }
     }
     #endregion chmod
     #region delete
     if (!empty($this->config['finally']['delete'])) {
         foreach ($this->config['finally']['delete'] as $file) {
             try {
                 FileSystem::delete(self::getRootDirectory() . $file);
             } catch (\Exception $e) {
                 /*ignore error*/
             }
         }
     }
     #endregion delete
     #region clear directories
     if (!empty($this->config['finally']['clearDirectories'])) {
         foreach ($this->config['finally']['clearDirectories'] as $directory) {
             try {
                 $finderItems = Finder::find('*')->from(self::getRootDirectory() . $directory);
                 if ($finderItems->count() > 0) {
                     foreach ($finderItems as $item) {
                         try {
                             /** @noinspection PhpUndefinedMethodInspection */
                             FileSystem::delete($item->getPathName());
                         } catch (\Exception $e) {
                             /*ignorujeme chybu*/
                         }
                     }
                 }
             } catch (\Exception $e) {
                 /*ignore error*/
             }
         }
     }
     #endregion clear directories
 }
예제 #28
0
파일: Dir.php 프로젝트: kdyby/filesystem
 /**
  * @param string $mask
  * @param bool $recursive
  * @return \Nette\Utils\Finder|\SplFileInfo[]
  */
 public function find($mask, $recursive = FALSE)
 {
     $masks = is_array($mask) ? $mask : func_get_args();
     if (is_bool(end($masks))) {
         $recursive = array_pop($masks);
     }
     return Nette\Utils\Finder::find($masks)->{$recursive ? 'from' : 'in'}($this->dir);
 }
예제 #29
0
$directions = ['nahoru' => true, 'dolù' => false, 'doleva' => true, 'doprava' => false];
//true øíká, zda je cílová buòka sudá
/** @var \SplFileInfo $colorDirectory */
foreach (Finder::findDirectories('*')->from(__DIR__ . '/imagesOld') as $colorDirectory) {
    \Nette\Utils\FileSystem::createDir(__DIR__ . '/imagesNew/' . $colorDirectory->getBasename());
    $directionImages = [];
    $directionImages['startCell'] = [];
    $startCellImages = [];
    $directionImages['targetCell'] = [];
    $targetCellImages = [];
    foreach (array_keys($directions) as $direction) {
        $directionImages['startCell'][$direction] = [];
        $directionImages['targetCell'][$direction] = [];
    }
    /** @var \SplFileInfo $image */
    foreach (Finder::find('*')->from($colorDirectory->getPathname()) as $image) {
        //		echo $image->getPathname() . PHP_EOL;
        foreach ($directions as $direction => $isTargetEven) {
            //rozlišení smìru
            if (Strings::contains($image->getBasename(), $direction)) {
                //				echo $direction . PHP_EOL;
                $matched = Strings::match($image->getBasename(), "~{$direction}-(\\d+)~");
                $number = $matched[1];
                //				echo $matched[0] . PHP_EOL;
                //				echo implode(', ', $matched) . PHP_EOL;
                $isEven = $number % 2 == 0;
                if ($isEven == $isTargetEven) {
                    //sudé èíslo, cílová buòka
                    $directionImages['targetCell'][$direction][] = $image->getPathname();
                } else {
                    //liché èíslo, poèáteèní buòka
예제 #30
0
 /**
  * Remove file or directory.
  *
  * @param string $filename
  * @param bool $onlyEmptyDir
  */
 public static function remove($filename, $onlyEmptyDir = false)
 {
     self::checkFilename($filename);
     $filename = self::normalizePath($filename);
     if (is_dir($filename)) {
         $files = Finder::find('*')->in($filename);
         foreach ($files as $file => $fileInfo) {
             self::remove($file);
         }
     }
     if (is_dir($filename) && !$onlyEmptyDir) {
         rmdir($filename);
     } elseif (!is_dir($filename)) {
         unlink($filename);
     }
 }