本文整理汇总了PHP中Pagekit\Application::finder方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::finder方法的具体用法?PHP Application::finder怎么用?PHP Application::finder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagekit\Application
的用法示例。
在下文中一共展示了Application::finder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
/**
* @Request({"path"})
*/
public function indexAction($path)
{
if (!($dir = $this->getPath())) {
return $this->error(__('Invalid path.'));
}
if (!is_dir($dir) || '-' === ($mode = $this->getMode($dir))) {
throw new ForbiddenException(__('Permission denied.'));
}
$data = array_fill_keys(['items'], []);
$data['mode'] = $mode;
$finder = App::finder();
$finder->sort(function ($a, $b) {
return $b->getRealpath() > $a->getRealpath() ? -1 : 1;
});
foreach ($finder->depth(0)->in($dir) as $file) {
if ('-' === ($mode = $this->getMode($file->getPathname()))) {
continue;
}
$info = ['name' => $file->getFilename(), 'mime' => 'application/' . ($file->isDir() ? 'folder' : 'file'), 'path' => $this->normalizePath($path . '/' . $file->getFilename()), 'url' => ltrim(App::url()->getStatic($file->getPathname(), [], 'base'), '/'), 'writable' => $mode == 'w'];
if (!$file->isDir()) {
$info = array_merge($info, ['size' => $this->formatFileSize($file->getSize()), 'lastmodified' => date(\DateTime::ISO8601, $file->getMTime())]);
}
$data['items'][] = $info;
}
return $data;
}
示例2: getDirectories
/**
* Gets a list of files and directories and their writable status.
*
* @return string[]
*/
protected function getDirectories()
{
// -TODO-
$directories = [App::get('path.storage'), App::get('path.temp'), App::get('config.file')];
$result = [];
foreach ($directories as $directory) {
$result[$this->getRelativePath($directory)] = is_writable($directory);
if (is_dir($directory)) {
foreach (App::finder()->in($directory)->directories()->depth(0) as $dir) {
$result[$this->getRelativePath($dir->getPathname())] = is_writable($dir->getPathname());
}
}
}
return $result;
}
示例3: doClearCache
/**
* TODO: clear opcache
*/
public function doClearCache(array $options = [])
{
// clear cache
if (empty($options) || @$options['cache']) {
App::cache()->flushAll();
foreach (glob(App::get('path.cache') . '/*.cache') as $file) {
@unlink($file);
}
}
// clear temp folder
if (@$options['temp']) {
foreach (App::finder()->in(App::get('path.temp'))->depth(0)->ignoreDotFiles(true) as $file) {
App::file()->delete($file->getPathname());
}
}
}