本文整理汇总了PHP中yii\helpers\BaseFileHelper::findFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseFileHelper::findFiles方法的具体用法?PHP BaseFileHelper::findFiles怎么用?PHP BaseFileHelper::findFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\BaseFileHelper
的用法示例。
在下文中一共展示了BaseFileHelper::findFiles方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllClasses
public static function getAllClasses()
{
$result = [];
foreach (self::getAllAliases() as $alias) {
$path = \Yii::getAlias($alias);
$files = is_dir($path) ? BaseFileHelper::findFiles($path) : [$path];
foreach ($files as $filePath) {
if (!preg_match('/.*\\/[A-Z]\\w+\\.php/', $filePath)) {
continue;
}
$className = str_replace([$path, '.php', '/', '@'], [$alias, '', '\\', ''], $filePath);
$result[] = $className;
}
}
return $result;
}
示例2: getImageAdvert
public static function getImageAdvert($data, $general = true, $original = false)
{
$image = [];
$base = Url::base();
if ($general) {
$image[] = $base . '/uploads/adverts/' . $data['idadvert'] . '/general/small_' . $data['general_image'];
} else {
$path = \Yii::getAlias("@frontend/web/uploads/adverts/" . $data['idadvert']);
$files = BaseFileHelper::findFiles($path);
foreach ($files as $file) {
if (strstr($file, 'small_') && !strstr($file, 'general')) {
$image[] = $base . 'uploads/adverts/' . $data['idadvert'] . '/' . basename($file);
}
}
}
return $image;
}
示例3: getAllClasses
public static function getAllClasses()
{
if (self::$_allClasses !== null) {
return self::$_allClasses;
}
$result = [];
foreach (self::getAllAliases() as $alias) {
$path = Yii::getAlias($alias);
if (!file_exists($path) || is_file($path)) {
continue;
}
$files = BaseFileHelper::findFiles($path, ['except' => ['/yii2-gii/', 'Yii.php']]);
foreach ($files as $filePath) {
if (!preg_match('/.*\\/[A-Z]\\w+\\.php/', $filePath)) {
continue;
}
$className = str_replace([$path, '.php', '/', '@'], [$alias, '', '\\', ''], $filePath);
$result[] = $className;
}
}
return self::$_allClasses = $result;
}
示例4: afterSave
/**
* После сохранения
*/
public function afterSave()
{
$this->path = null;
//Сохраняем файл
foreach ($this->fields as $field) {
$isWeb = $this->_webFile[$field];
$file = null;
if ($isWeb || ($file = UploadedFile::getInstance($this->owner, $field))) {
//Директория для сохранения
$path = $this->getPath($field);
$files = BaseFileHelper::findFiles($path);
foreach ($files as $cFile) {
@unlink($cFile);
}
$fileName = self::normalize($isWeb ? $this->_names[$field] : $file->name);
$filePath = BaseFileHelper::normalizePath($path . '/' . $fileName);
// d($filePath);
if ($this->_webFile[$field]) {
$result = @copy($this->_webFile[$field], $filePath);
if (!$result) {
$fileName = '';
}
} else {
$file->saveAs($path . '/' . $fileName);
chmod($filePath, 0666);
}
$this->owner->updateAttributes(array($field => $fileName));
}
}
$this->setAttach();
}
示例5: cleanup
/**
* Cleanup all files in the zip output path.
*/
protected function cleanup()
{
$files = BaseFileHelper::findFiles($this->getBaseTempFolderPath(), ['filter' => function ($path) {
return time() - filemtime($path) > 30 ? true : false;
}, 'recursive' => true]);
foreach ($files as $file) {
unlink($file);
}
}
示例6: findFiles
/**
* @inheritdoc
* @staticvar boolean $searchProcess variable that indicates call method is recursively called or this is the first call.
* Fixes logic of parent method. Some file systems may has file for which is_file === false and is_dir === false.
* For example: windows file system has it where file has "alien" character set.
*
* The method returns file paths which have local file system charset.
* The `$dir` param must be in local file system charset too.
*/
public static function findFiles($dir, $options = [])
{
static $searchProcess = false;
if (!$searchProcess) {
$searchProcess = true;
try {
$result = parent::findFiles($dir, $options);
} catch (\Exception $ex) {
$searchProcess = false;
throw $ex;
}
$searchProcess = false;
return $result;
}
if (!is_dir($dir)) {
return [];
}
return parent::findFiles($dir, $options);
}