当前位置: 首页>>代码示例>>PHP>>正文


PHP FileHelper::findFiles方法代码示例

本文整理汇总了PHP中yii\helpers\FileHelper::findFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHelper::findFiles方法的具体用法?PHP FileHelper::findFiles怎么用?PHP FileHelper::findFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\FileHelper的用法示例。


在下文中一共展示了FileHelper::findFiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionGenerate

 /**
  * Сгенерировать карту классов для автоподгрузки.
  */
 public function actionGenerate()
 {
     $root = '@app';
     $root = Yii::getAlias($root);
     $root = FileHelper::normalizePath($root);
     $mapFile = '@app/config/classes.php';
     $mapFile = Yii::getAlias($mapFile);
     $options = ['filter' => function ($path) {
         if (is_file($path)) {
             $file = basename($path);
             if ($file[0] < 'A' || $file[0] > 'Z') {
                 return false;
             }
         }
         return;
     }, 'only' => ['*.php'], 'except' => ['/views/', '/vendor/', '/config/', '/tests/']];
     $files = FileHelper::findFiles($root, $options);
     $map = [];
     foreach ($files as $file) {
         if (strpos($file, $root) !== 0) {
             throw new \Exception("Something wrong: {$file}\n");
         }
         $path = str_replace('\\', '/', substr($file, strlen($root)));
         $map['app' . substr(str_replace('/', '\\', $path), 0, -4)] = $file;
     }
     $this->generateMapFile($mapFile, $map);
 }
开发者ID:herroffizier,项目名称:yii2-app,代码行数:30,代码来源:ClassmapController.php

示例2: init

 public function init()
 {
     $this->css[] = \Yii::$app->settings->get($this->settingsKey, self::SETTINGS_SECTION) . '-' . self::MAIN_LESS_FILE;
     parent::init();
     if (!$this->sourcePath) {
         // TODO: this is workaround for empty source path when using bundled assets
         return;
     } else {
         $sourcePath = \Yii::getAlias($this->sourcePath);
         @mkdir($sourcePath);
         $models = Less::find()->all();
         $hash = sha1(Json::encode($models));
         if ($hash !== \Yii::$app->cache->get(self::CACHE_ID)) {
             $lessFiles = FileHelper::findFiles($sourcePath, ['only' => ['*.less']]);
             foreach ($lessFiles as $file) {
                 unlink($file);
             }
             foreach ($models as $model) {
                 file_put_contents("{$sourcePath}/{$model->key}.less", $model->value);
             }
             $dependency = new FileDependency();
             $dependency->fileName = __FILE__;
             \Yii::$app->cache->set(self::CACHE_ID, $hash, 0, $dependency);
             @touch($sourcePath);
         }
     }
 }
开发者ID:dmstr,项目名称:yii2-prototype-module,代码行数:27,代码来源:DbAsset.php

示例3: bootstrap

 public function bootstrap($app)
 {
     $configs = $app->cache->get(self::CACHE_CONFIG_ID);
     if ($configs === false) {
         $configs = [];
         foreach ($this->getPaths() as $alias) {
             $path = Yii::getAlias($alias);
             $files = FileHelper::findFiles($path, ['only' => ['*/' . self::DEFINITION_FILE]]);
             foreach ($files as $file) {
                 try {
                     $config = (require $file);
                     $config['basePath'] = dirname($file);
                     $configs[] = $config;
                 } catch (Exception $e) {
                     Yii::trace("Failed loading module config.php file: {$e->getMessage()}", __METHOD__);
                 }
             }
             usort($configs, function ($configA, $configB) {
                 if (isset($configA['weight'], $configB['weight'])) {
                     return (int) $configA['weight'] > (int) $configB['weight'];
                 }
                 return 0;
             });
         }
         if (!YII_DEBUG && !empty($configs)) {
             $app->cache->set(self::CACHE_CONFIG_ID, $configs);
         }
     }
     $app->get('moduleManager')->registerModules($configs);
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:30,代码来源:ModuleManager.php

示例4: itemList

 public function itemList($options = [])
 {
     $session = Yii::$app->session;
     $moduleId = Yii::$app->controller->module->id;
     if (isset($options['sub-directory'])) {
         $session->set($moduleId, ['path' => '/' . ltrim($options['sub-directory'], '/')]);
     }
     //$session->remove($moduleId);
     $dir = $this->routes->uploadDir . $session->get($moduleId)['path'];
     if (is_dir($dir)) {
         //echo $dir;
         $files = \yii\helpers\FileHelper::findFiles($dir, ['recursive' => false]);
         $files_r = [];
         if (!isset($options['show-directory']) || intval($options['show-directory']) === 1) {
             foreach (glob($dir . '/*', GLOB_ONLYDIR) as $filename) {
                 $files_r[] = $filename;
             }
         }
         foreach ($files as $value) {
             $files_r[] = str_replace('\\', '/', $value);
         }
     } else {
         $message = 'Path ' . $session->get($moduleId)['path'] . ' not found!.';
         $session->remove($moduleId);
         throw new \yii\web\HttpException(500, $message);
     }
     return $files_r;
 }
开发者ID:miragesoft,项目名称:yii2-basicfilemanager,代码行数:28,代码来源:FileModel.php

示例5: actionIndex

 public function actionIndex()
 {
     $th = \Yii::$app->thumbnail;
     $rollMenu = (new RollMenu())->items;
     // here comes gallery processing
     $galleryGroup = \Yii::$app->request->get('group', 'all');
     $files = [];
     foreach (glob('img/gallery/*', GLOB_ONLYDIR) as $file) {
         $galleryGroups[] = basename($file);
     }
     if (in_array($galleryGroup, $galleryGroups)) {
         $files = FileHelper::findFiles("img/gallery/{$galleryGroup}");
     } else {
         if ($galleryGroup == 'latest') {
             $files = FileHelper::findFiles("img/gallery");
             $files = array_map("filemtime", $files);
             arsort($files);
         } else {
             $files = FileHelper::findFiles("img/gallery");
         }
     }
     $galleryGroups = array_merge($galleryGroups, ['all', 'latest']);
     $galleryItems = [];
     foreach ($files as $f) {
         $galleryItems[] = ['url' => $f, 'src' => $th->thumbnailFileUrl($f, 200, 200, $th->inset), 'options' => array('title' => \Yii::t('app/images', FilenameHelper::FilenameToTitle($f)))];
     }
     $galleryWidget = ['menu' => $galleryGroups, 'items' => $galleryItems];
     $latestNews = null;
     if (\Yii::$app->request->isAjax) {
         return $this->renderPartial('/templates/image-gallery', ['galleryWidget' => $galleryWidget]);
     }
     return $this->render('index', ['rollMenu' => $rollMenu, 'latestNews' => $latestNews, 'galleryWidget' => $galleryWidget]);
 }
开发者ID:secondsano,项目名称:unico-yii,代码行数:33,代码来源:SiteController.php

示例6: repairTable

 public static function repairTable($pathDb, $pathDbBak, $mode = 0660, $excludeTables = [])
 {
     $files = FileHelper::findFiles($pathDb, ['only' => ['*.ibd']]);
     $tables = self::getTableNames($files);
     $tables = self::filterTables($tables, $excludeTables);
     \Yii::$app->db->createCommand('set foreign_key_checks=0;')->query();
     self::msg('%b[info]%n Total tables: ' . ($totalTables = count($tables)));
     $i = 0;
     foreach ($tables as $table => $tableFile) {
         self::msg('%b' . ++$i . '[' . $totalTables . '] %y' . strtoupper($table) . '%n');
         try {
             \Yii::$app->db->createCommand('ALTER TABLE ' . $table . ' DISCARD TABLESPACE;')->query();
             self::msg("\tdiscard tablespace");
             $tablePathBak = $pathDbBak . '/' . $table . '.ibd';
             copy($tablePathBak, $tableFile);
             self::msg("\tcopy IBD file");
             chmod($tableFile, $mode);
             self::msg("\tchmod = " . base_convert($mode, 10, 8));
             \Yii::$app->db->createCommand('ALTER TABLE ' . $table . ' IMPORT TABLESPACE;')->query();
             self::msg("\timport tablespace");
             $tableInDb = \Yii::$app->db->createCommand('SHOW CREATE TABLE ' . $table . ';')->queryScalar();
             self::msg("\ttest: " . ($tableInDb === $table ? '%GSUCCESS' : '%RFAIL') . '%n');
         } catch (Exception $e) {
             throw $e;
         }
     }
     \Yii::$app->db->createCommand('set foreign_key_checks=1;')->query();
     self::msg('%b[info]%n Complete!');
 }
开发者ID:efureev,项目名称:yii2-recover-innodb-table,代码行数:29,代码来源:DbUtils.php

示例7: actionExtractModule

 /**
  * Extracts messages for a given module from source code.
  * 
  * @param string $moduleId
  */
 public function actionExtractModule($moduleId)
 {
     $module = Yii::$app->moduleManager->getModule($moduleId);
     $configFile = Yii::getAlias('@humhub/config/i18n.php');
     $config = array_merge(['translator' => 'Yii::t', 'overwrite' => false, 'removeUnused' => false, 'sort' => true, 'format' => 'php', 'ignoreCategories' => []], require $configFile);
     $config['sourcePath'] = $module->getBasePath();
     if (!is_dir($config['sourcePath'] . '/messages')) {
         @mkdir($config['sourcePath'] . '/messages');
     }
     $files = FileHelper::findFiles(realpath($config['sourcePath']), $config);
     $messages = [];
     foreach ($files as $file) {
         $messages = array_merge_recursive($messages, $this->extractMessages($file, $config['translator'], $config['ignoreCategories']));
     }
     // Remove unrelated translation categories
     foreach ($messages as $category => $msgs) {
         $categoryModule = $this->getModuleByCategory($category);
         if ($categoryModule == null || $categoryModule->id != $module->id) {
             unset($messages[$category]);
         }
     }
     foreach ($config['languages'] as $language) {
         $dir = $config['sourcePath'] . DIRECTORY_SEPARATOR . 'messages' . DIRECTORY_SEPARATOR . $language;
         if (!is_dir($dir)) {
             @mkdir($dir);
         }
         $this->saveMessagesToPHP($messages, $dir, $config['overwrite'], $config['removeUnused'], $config['sort'], false);
     }
 }
开发者ID:freddykr,项目名称:humhub,代码行数:34,代码来源:MessageController.php

示例8: actionImport

 /**
  * @param string $sourcePath
  * @throws Exception
  */
 public function actionImport($sourcePath = null)
 {
     if (!$sourcePath) {
         $sourcePath = $this->prompt('Enter a source path');
     }
     $sourcePath = realpath(Yii::getAlias($sourcePath));
     if (!is_dir($sourcePath)) {
         throw new Exception('The source path ' . $sourcePath . ' is not a valid directory.');
     }
     $translationsFiles = FileHelper::findFiles($sourcePath, ['only' => ['*.php']]);
     foreach ($translationsFiles as $translationsFile) {
         $relativePath = trim(str_replace([$sourcePath, '.php'], '', $translationsFile), '/,\\');
         $relativePath = FileHelper::normalizePath($relativePath, '/');
         $relativePath = explode('/', $relativePath, 2);
         if (count($relativePath) > 1) {
             $language = $this->prompt('Enter language.', ['default' => $relativePath[0]]);
             $category = $this->prompt('Enter category.', ['default' => $relativePath[1]]);
             $translations = (require_once $translationsFile);
             if (is_array($translations)) {
                 foreach ($translations as $sourceMessage => $translation) {
                     if (!empty($translation)) {
                         $sourceMessage = $this->getSourceMessage($category, $sourceMessage);
                         $this->setTranslation($sourceMessage, $language, $translation);
                     }
                 }
             }
         }
     }
     echo PHP_EOL . 'Done.' . PHP_EOL;
 }
开发者ID:wancer,项目名称:yii2-i18n-module,代码行数:34,代码来源:I18nController.php

示例9: run

 /**
  * @inheritdoc
  */
 public function run()
 {
     $models = StorageItem::find()->all();
     $results = [];
     if (Yii::$app->controller->module->webAccessUrl === false) {
         foreach ($models as $model) {
             $filePath = Yii::$app->controller->module->getFilePath($model->file_path);
             $url = Url::to(['view', 'id' => $model->id]);
             $fileName = pathinfo($filePath, PATHINFO_FILENAME);
             $results[] = $this->createEntry($filePath, $url, $fileName);
         }
     } else {
         $onlyExtensions = array_map(function ($ext) {
             return '*.' . $ext;
         }, Yii::$app->controller->module->imageAllowedExtensions);
         $filesPath = FileHelper::findFiles(Yii::$app->controller->module->getStorageDir(), ['recursive' => true, 'only' => $onlyExtensions]);
         if (is_array($filesPath) && count($filesPath)) {
             foreach ($filesPath as $filePath) {
                 $url = Yii::$app->controller->module->getUrl(pathinfo($filePath, PATHINFO_BASENAME));
                 $fileName = pathinfo($filePath, PATHINFO_FILENAME);
                 $results[] = $this->createEntry($filePath, $url, $fileName);
             }
         }
     }
     return $results;
 }
开发者ID:insma,项目名称:yii2-file-storage,代码行数:29,代码来源:ImageManagerJsonAction.php

示例10: init

 /**
  * Gets data from cache or database
  * Truncates tables
  * @return \self
  * @throws \yii\db\Exception
  */
 public static function init()
 {
     if ($data = \Yii::$app->cache->get(static::$cacheKey)) {
         //return static::$data = unserialize($data);
     }
     $dir = \Yii::getAlias(static::$fixturePath);
     MigrationHelper::unsetForeignKeyCheck();
     $files = FileHelper::findFiles($dir, ['only' => ['*.php']]);
     asort($files);
     foreach ($files as $file) {
         $table = preg_replace('/\\d+\\_(.*)/', '$1', basename($file, '.php'));
         \Yii::$app->db->createCommand()->truncateTable($table)->execute();
         if (!($data = (require $file))) {
             continue;
         }
         $modelClass = @$data['modelClass'];
         unset($data['modelClass']);
         foreach ($data as $key => $values) {
             \Yii::$app->db->createCommand()->insert($table, $values)->execute();
             if ($modelClass) {
                 /** @var \yii\db\ActiveRecord $model */
                 $model = new $modelClass($values);
                 static::$data[$table][$key] = $model->hasAttribute('id') ? $model::find()->orderBy(['id' => SORT_DESC])->one() : new $model();
             } else {
                 static::$data[$table][$key] = $values;
             }
         }
     }
     static::update();
     MigrationHelper::setForeignKeyCheck();
     return new static();
 }
开发者ID:bariew,项目名称:yii2-tools,代码行数:38,代码来源:FixtureManager.php

示例11: delete

 /**
  * @param string $name
  * @return boolean
  */
 public function delete($name = '')
 {
     foreach (FileHelper::findFiles($this->getFileName($name)) as $file) {
         unlink($file);
     }
     return rmdir($this->getFileName($name));
 }
开发者ID:sam002,项目名称:yii2-acme,代码行数:11,代码来源:CertificateStorageFile.php

示例12: toJson

 /**
  * @return string
  */
 public function toJson()
 {
     $toJson = [];
     foreach (FileHelper::findFiles($this->getPath(), ['only' => ['*.jpg', '*.jpe', '*.jpeg', '*.png', '*.gif', '*.bmp']]) as $this->_file) {
         $toJson = ArrayHelper::merge($toJson, [['thumb' => $this->getUrl(), 'image' => $this->getUrl()]]);
     }
     return Json::encode($toJson);
 }
开发者ID:apurey,项目名称:cmf,代码行数:11,代码来源:ImageListModel.php

示例13: toJson

 /**
  * @return string
  */
 public function toJson()
 {
     $toJson = [];
     foreach (FileHelper::findFiles($this->getPath()) as $this->_file) {
         $toJson = ArrayHelper::merge($toJson, [['title' => $this->normalizeFilename(), 'name' => FileHelper::getMimeType($this->_file), 'link' => $this->getUrl(), 'size' => $this->getSize()]]);
     }
     return Json::encode($toJson);
 }
开发者ID:apurey,项目名称:cmf,代码行数:11,代码来源:FileListModel.php

示例14: getControllers

 /**
  * @param Module $module
  *
  * @return array
  */
 public function getControllers($module)
 {
     $files = FileHelper::findFiles($module->controllerPath, ['only' => ['*Controller.php']]);
     return ArrayHelper::getColumn($files, function ($file) use($module) {
         $class = pathinfo($file, PATHINFO_FILENAME);
         $route = Inflector::camel2id($class = substr($class, 0, strlen($class) - strlen('Controller')));
         return new ControllerModel(['route' => $module->uniqueId . '/' . $route, 'label' => Inflector::camel2words($class)]);
     });
 }
开发者ID:voodoo-mobile,项目名称:yii2-api,代码行数:14,代码来源:Harvester.php

示例15: findFiles

 /**
  * @inheritdoc
  */
 protected function findFiles($path, $except = [])
 {
     if (empty($except)) {
         $except = ['README.md'];
     }
     $path = FileHelper::normalizePath($path);
     $options = ['only' => ['*.md'], 'except' => $except];
     return FileHelper::findFiles($path, $options);
 }
开发者ID:dawei101,项目名称:plants,代码行数:12,代码来源:GuideController.php


注:本文中的yii\helpers\FileHelper::findFiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。