File manager - Edit - /home/opticamezl/www/newok/templates/yootheme/packages/builder-source-filesystem/src/FileHelper.php
Back
<?php namespace YOOtheme\Builder\Source\Filesystem; use YOOtheme\File; use YOOtheme\Path; class FileHelper { /** * @var string[] */ protected $rootDirs; /** * @param string|string[] $rootDirs */ public function __construct($rootDirs) { $this->rootDirs = (array) $rootDirs; } /** * Query files. * * @param array $args * * @return array */ public function query(array $args = []) { $args += ['offset' => 0, 'limit' => 10, 'order' => '', 'order_direction' => 'ASC']; if (empty($args['pattern'])) { return []; } $pattern = $args['pattern']; $pattern = str_starts_with($pattern, '~') ? $pattern : Path::join('~', $pattern); $files = File::glob($pattern, GLOB_NOSORT); // filter out any dir $files = array_filter( $files, fn($file) => array_any($this->rootDirs, fn($dir) => str_starts_with($file, $dir)) && is_file($file), ); // order if ($args['order'] === 'rand') { shuffle($files); } else { if ($args['order'] === 'name') { natcasesort($files); } // direction if ($args['order_direction'] === 'DESC') { $files = array_reverse($files); } } // offset/limit if ($args['offset'] || $args['limit']) { $files = array_slice($files, (int) $args['offset'], (int) $args['limit'] ?: null); } return $files; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings