本文整理汇总了PHP中Nette\Utils\Finder::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::find方法的具体用法?PHP Finder::find怎么用?PHP Finder::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Finder
的用法示例。
在下文中一共展示了Finder::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateTree
/**
* 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: 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);
}
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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);
}
}
}
示例6: clean
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: loadFromDirectory
/**
* {@inheritdoc}
*/
private function loadFromDirectory($path)
{
$files = [];
foreach (Finder::find(['*.neon', '*.yaml', '*.yml'])->from($path) as $file) {
$files[] = $file;
}
return $this->load($files);
}
示例8: loadConfigFiles
/**
* @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: getModifyTime
/**
* @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: cleanSessions
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: clearTemp
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);
}
示例12: purgeDir
/**
* @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: purgeDir
/**
* @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: run
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]));
}
示例15: actionClean
/**
* 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);
}