本文整理汇总了PHP中Nette\Utils\Finder类的典型用法代码示例。如果您正苦于以下问题:PHP Finder类的具体用法?PHP Finder怎么用?PHP Finder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Finder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeRender
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: copy
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: run
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: wipeCache
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);
}
}
示例5: render
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();
}
示例6: parseFiles
/**
* 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: addFindConfig
/**
* 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: clearTemp
private function clearTemp()
{
/* @var $file SplFileInfo */
foreach (Finder::findFiles('*')->from($this->temp) as $file) {
@unlink($file->getPathname());
}
}
示例9: beforeRender
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;
}
示例10: getPresenters
/**
* @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: flush
public function flush()
{
/** @var $file \SplFileInfo */
foreach (Finder::findFiles('*')->in($this->getAbsolutePath()) as $file) {
@unlink($file->getRealPath());
}
}
示例12: addWebLoader
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: build
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: run
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: addAutoloadConfig
/**
* @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);
}