php yii-helpers-FileHelper类(方法)实例源码

下面列出了php yii-helpers-FileHelper 类(方法)源码代码实例,从而了解它的用法。

作者:herroffizie    项目:yii2-ap   
/**
  * Сгенерировать карту классов для автоподгрузки.
  */
 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);
 }

作者:how    项目:yii   
protected function tearDown()
 {
     if (is_dir($this->tmpPath)) {
         FileHelper::removeDirectory($this->tmpPath);
     }
     parent::tearDown();
 }

作者:albertborso    项目:yii   
public function tearDown()
 {
     FileHelper::removeDirectory($this->sourcePath);
     if (file_exists($this->configFileName)) {
         unlink($this->configFileName);
     }
 }

作者:mbrowniebyte    项目:yii2-clean-asset   
public function cleanAssetDir()
 {
     $now = time();
     $asset_temp_dirs = glob($this->asset_dir . '/*', GLOB_ONLYDIR);
     // check if less than want to keep
     if (count($asset_temp_dirs) <= $this->keep) {
         return 0;
     }
     // get all dirs and sort by modified
     $modified = [];
     foreach ($asset_temp_dirs as $asset_temp_dir) {
         $modified[$asset_temp_dir] = filemtime($asset_temp_dir);
     }
     asort($modified);
     $nbr_dirs = count($modified);
     // keep last dirs
     for ($i = min($nbr_dirs, $this->keep); $i > 0; $i--) {
         array_pop($modified);
     }
     if ($this->dry_run) {
         $msg_try = 'would have ';
     } else {
         $msg_try = '';
     }
     // remove dirs
     foreach ($modified as $dir => $mod) {
         $this->echo_msg($msg_try . 'removed ' . $dir . ', last modified ' . Yii::$app->formatter->asDatetime($mod));
         if (!$this->dry_run) {
             FileHelper::removeDirectory($dir);
         }
     }
     return $this->dry_run ? 0 : $nbr_dirs;
 }

作者:rajanishtime    项目:basicyi   
public function tearDown()
 {
     $filePath = $this->getTestFilePath();
     if (file_exists($filePath)) {
         FileHelper::removeDirectory($filePath);
     }
 }

作者:deesof    项目:yii2-consol   
/**
  * @return array all directories
  */
 protected function getDirectories()
 {
     if ($this->_paths === null) {
         $paths = ArrayHelper::getValue(Yii::$app->params, $this->paramVar, []);
         $paths = array_merge($paths, $this->migrationLookup);
         $extra = !empty($this->extraFile) && is_file($this->extraFile = Yii::getAlias($this->extraFile)) ? require $this->extraFile : [];
         $paths = array_merge($extra, $paths);
         $p = [];
         foreach ($paths as $path) {
             $p[Yii::getAlias($path, false)] = true;
         }
         unset($p[false]);
         $currentPath = Yii::getAlias($this->migrationPath);
         if (!isset($p[$currentPath])) {
             $p[$currentPath] = true;
             if (!empty($this->extraFile)) {
                 $extra[] = $this->migrationPath;
                 FileHelper::createDirectory(dirname($this->extraFile));
                 file_put_contents($this->extraFile, "<?php\nreturn " . VarDumper::export($extra) . ";\n", LOCK_EX);
             }
         }
         $this->_paths = array_keys($p);
         foreach ($this->migrationNamespaces as $namespace) {
             $path = str_replace('/', DIRECTORY_SEPARATOR, Yii::getAlias('@' . str_replace('\\', '/', $namespace)));
             $this->_paths[$namespace] = $path;
         }
     }
     return $this->_paths;
 }

作者:jiangrongyon    项目:docge   
public function actionIndex()
 {
     $src = DOCGEN_PATH . '/swagger-ui/';
     $dst = Yii::getAlias('@app') . '/web/apidoc/';
     FileHelper::copyDirectory($src, $dst);
     return Controller::EXIT_CODE_NORMAL;
 }

作者:sheillendr    项目:yii2-them   
/**
  * @inheritdoc
  */
 public function applyTo($path)
 {
     $pathMap = $this->pathMap;
     if (empty($pathMap)) {
         if (($basePath = $this->getBasePath()) === null) {
             throw new InvalidConfigException('The "basePath" property must be set.');
         }
         $pathMap = [Yii::$app->getBasePath() => [$basePath]];
     }
     $module = Yii::$app->controller->module;
     if (!$module instanceof \yii\web\Application) {
         $pathMap['@app/modules/' . $module->id . '/views'] = [$pathMap['@app/views'][0] . '/' . $module->id];
     }
     #debug
     //        echo '<pre>';
     //        print_r(Yii::$app->controller->module);
     //        echo '</pre>';
     #end debug
     #debug
     echo '<pre>';
     print_r($pathMap);
     echo '</pre>';
     #end debug
     $path = FileHelper::normalizePath($path);
     #debug
     echo 'path: ', $path, '<br/>';
     #end debug
     foreach ($pathMap as $from => $tos) {
         $from = FileHelper::normalizePath(Yii::getAlias($from)) . DIRECTORY_SEPARATOR;
         #debug
         echo 'from: ', $from, '<br/>';
         #end debug
         if (strpos($path, $from) === 0) {
             $n = strlen($from);
             foreach ((array) $tos as $to) {
                 $to = FileHelper::normalizePath(Yii::getAlias($to)) . DIRECTORY_SEPARATOR;
                 #debug
                 echo 'to: ', $to, '<br/>';
                 #end debug
                 $file = $to . substr($path, $n);
                 if (is_file($file)) {
                     #debug
                     echo 'return file: ', $file, '<br/>';
                     if (strpos($path, 'layouts')) {
                         exit;
                     }
                     #end debug
                     return $file;
                 }
             }
         }
     }
     #debug
     echo 'return path: ', $path, '<br/>';
     if (strpos($path, 'layouts')) {
         exit;
     }
     #end debug
     return $path;
 }

作者:rmrevi    项目:yii2-fil   
protected function tearDown()
 {
     parent::tearDown();
     FileHelper::removeDirectory(\Yii::$app->getModule('file')->upload_path);
     FileHelper::removeDirectory(\Yii::$app->getModule('file')->storage_path);
     $this->destroyApplication();
 }

作者:phpson    项目:yii2-extjs-rba   
public function init()
 {
     parent::init();
     $extJsSrcDir = Yii::getAlias($this->extJsDir);
     $extJsSrcExtendDir = Yii::getAlias($this->extJsExtendDir);
     $dstDir = Yii::getAlias($this->dstPath);
     $extJsDstDir = $dstDir . DIRECTORY_SEPARATOR . 'extjs';
     $extJsExtendDstDir = $dstDir . DIRECTORY_SEPARATOR . 'extjs-extend';
     if (!is_dir($dstDir)) {
         if (!is_dir($dstDir)) {
             FileHelper::createDirectory($dstDir);
         }
     }
     if (!is_dir($extJsDstDir)) {
         symlink($extJsSrcDir, $extJsDstDir);
     }
     if (!is_dir($extJsExtendDstDir)) {
         symlink($extJsSrcExtendDir, $extJsExtendDstDir);
     }
     $data = DpConfig::find()->all();
     $config = [];
     foreach ($data as $item) {
         $config[$item['name']] = $item['value'];
     }
     $this->config = $config;
     $this->identity = Yii::$app->user->identity;
 }

作者:huasxi    项目:lulucms   
public function loadActiveModules($isAdmin)
 {
     $moduleManager = LuLu::getService('modularityService');
     
     $this->activeModules = $moduleManager->getActiveModules($isAdmin);
     
     $module = $isAdmin ? 'AdminModule' : 'HomeModule';
     foreach ($this->activeModules as $m)
     {
         $moduleId = $m['id'];
         $moduleDir = $m['dir'];
         $ModuleClassName = $m['dir_class'];
         
         $this->setModule($moduleId, [
             'class' => 'source\modules\\' . $moduleDir . '\\' . $module
         ]);
         
         
         $serviceFile= LuLu::getAlias('@source').'\modules\\' .$moduleDir.'\\'.$ModuleClassName.'Service.php';
         
         if(FileHelper::exist($serviceFile))
         {
             $serviceClass = 'source\modules\\' .$moduleDir.'\\'.$ModuleClassName.'Service.php';
             $serviceInstance = new $serviceClass();
             $this->set($serviceInstance->getServiceId(), $serviceInstance);
         }
     }
 }

作者:hassiumsof    项目:hasscms-package   
/**
  * @hass-todo 没有添加事务
  * @return string
  */
 public function actionIndex()
 {
     $model = new MigrationUtility();
     $upStr = new OutputString();
     $downStr = new OutputString();
     if ($model->load(\Yii::$app->getRequest()->post())) {
         if (!empty($model->tableSchemas)) {
             list($up, $down) = $this->generalTableSchemas($model->tableSchemas, $model->tableOption, $model->foreignKeyOnUpdate, $model->foreignKeyOnDelete);
             $upStr->outputStringArray = array_merge($upStr->outputStringArray, $up->outputStringArray);
             $downStr->outputStringArray = array_merge($downStr->outputStringArray, $down->outputStringArray);
         }
         if (!empty($model->tableDatas)) {
             list($up, $down) = $this->generalTableDatas($model->tableDatas);
             $upStr->outputStringArray = array_merge($upStr->outputStringArray, $up->outputStringArray);
             $downStr->outputStringArray = array_merge($downStr->outputStringArray, $down->outputStringArray);
         }
         $path = Yii::getAlias($model->migrationPath);
         if (!is_dir($path)) {
             FileHelper::createDirectory($path);
         }
         $name = 'm' . gmdate('ymd_His') . '_' . $model->migrationName;
         $file = $path . DIRECTORY_SEPARATOR . $name . '.php';
         $content = $this->renderFile(Yii::getAlias("@hass/migration/views/migration.php"), ['className' => $name, 'up' => $upStr->output(), 'down' => $downStr->output()]);
         file_put_contents($file, $content);
         $this->flash("success", "迁移成功,保存在" . $file);
     }
     if ($model->migrationPath == null) {
         $model->migrationPath = $this->module->migrationPath;
     }
     return $this->render('index', ['model' => $model]);
 }

作者:jasli    项目:yii2-kindedito   
public function actionIndex()
 {
     $file = UploadedFile::getInstanceByName('imgFile');
     $basePath = dirname(\Yii::getAlias('@common'));
     $date = date("Y{$this->separator}m", time());
     $uploadPath = "../uploads/Attachment/{$date}";
     if (!is_dir($basePath . "/" . $uploadPath)) {
         FileHelper::createDirectory($basePath . "/" . $uploadPath);
     }
     if (preg_match('/(\\.[\\S\\s]+)$/', $file->name, $match)) {
         $filename = md5(uniqid(rand())) . $match[1];
     } else {
         $filename = $file->name;
     }
     $uploadData = ['type' => $file->type, 'name' => $filename, 'size' => $file->size, 'path' => "/" . $uploadPath, 'module' => null, 'controller' => null, 'action' => null, 'user_id' => \Yii::$app->user->isGuest ? 0 : \Yii::$app->user->identity->id];
     $module = \Yii::$app->controller->module;
     Upload::$db = $module->db;
     $model = new Upload();
     $model->setAttributes($uploadData);
     $model->validate();
     if ($model->save() && $file->saveAs($basePath . '/' . $uploadPath . '/' . $filename)) {
         return Json::encode(array('error' => 0, 'url' => "/" . $uploadPath . '/' . $filename, 'id' => $model->id, 'name' => $file->name));
     } else {
         return Json::encode(array('error' => 1, 'msg' => Json::encode($model->getErrors())));
     }
 }

作者:chabberwoc    项目:halo-de   
public function init()
 {
     if (!isset($this->runtimePath)) {
         $this->runtimePath = Yii::$app->runtimePath;
     }
     $this->configFile = $this->runtimePath . '/halo/active-plugins.php';
     if (!is_dir(dirname($this->configFile))) {
         FileHelper::createDirectory(dirname($this->configFile));
     }
     if (file_exists($this->configFile)) {
         $this->_activePlugins = (require $this->configFile);
     } else {
         $this->_activePlugins = [];
     }
     foreach (glob($this->pluginPath . '/*', GLOB_ONLYDIR) as $vendorPath) {
         foreach (glob($vendorPath . '/*', GLOB_ONLYDIR) as $pluginPath) {
             $pluginInfoFile = $pluginPath . '/plugin.json';
             if (!is_file($pluginInfoFile)) {
                 // not plugin
                 continue;
             }
             $pluginId = basename($vendorPath) . '.' . basename($pluginPath);
             $pluginInfo = json_decode(file_get_contents($pluginInfoFile), true);
             if ($pluginInfo === null) {
                 // something wrong, can not read plugin.json
                 continue;
             }
             $this->_availablePlugins[$pluginId] = $pluginInfo;
         }
     }
 }

作者:heartshar    项目:dotplant   
/**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->uploadDir = !empty(\Yii::$app->getModule('core')->fileUploadPath) ? \Yii::$app->getModule('core')->fileUploadPath : $this->uploadDir;
     $this->uploadDir = FileHelper::normalizePath(\Yii::getAlias($this->uploadDir));
     $this->additionalRenderData['uploadDir'] = $this->uploadDir;
 }

作者:yurii-githu    项目:yii2-myli   
/**
  * (non-PHPdoc)
  * EXTRA: 
  * @see \yii\web\AssetManager::publishDirectory()
  * 
  *  [const-dir] contain directory name or empty if copy current asset directly to base assets' dir 
  */
 public function publishDirectory($src, $options)
 {
     throw new \yii\base\Exception('works but block support until it will be required. skip testing purpose');
     // default behavior with hashed dir
     if (!isset($options['const-dir'])) {
         return parent::publishDirectory($src, $options);
     }
     //
     // my custom : don't generate random dir, instead, use custom if set
     //
     $dstDir = $this->basePath . (!empty($options['const-dir']) ? '/' . $options['const-dir'] : '');
     //dont copy if already was copied
     // TODO: add datetime checks
     if (file_exists($dstDir)) {
         return [$dstDir, $this->baseUrl];
     }
     // A. copy only subdirs if set
     if (!empty($options['sub-dirs']) && is_array($options['sub-dirs'])) {
         foreach ($options['sub-dirs'] as $subdir) {
             if (is_dir($src . '/' . $subdir)) {
                 FileHelper::copyDirectory($src . '/' . $subdir, $dstDir . '/' . $subdir, ['dirMode' => $this->dirMode, 'fileMode' => $this->fileMode, 'beforeCopy' => @$options['beforeCopy'], 'afterCopy' => @$options['afterCopy'], 'forceCopy' => @$options['forceCopy']]);
             }
             //TODO: else write error log
         }
     } else {
         //copy whole dir
         FileHelper::copyDirectory($src, $dstDir, ['dirMode' => $this->dirMode, 'fileMode' => $this->fileMode, 'beforeCopy' => @$options['beforeCopy'], 'afterCopy' => @$options['afterCopy'], 'forceCopy' => @$options['forceCopy']]);
     }
     return [$dstDir, $this->baseUrl];
 }

作者:kd-brine    项目:k   
public function getText()
 {
     $file = FileHelper::localize($this->textFile);
     //        FileHelper::getMimeType()
     $f = file('uploads/' . $file->name);
     return $f;
 }

作者:gromve    项目:yii2-platform-basi   
public function up()
 {
     // Creates folders for media manager
     $webroot = Yii::getAlias('@app/web');
     foreach (['upload', 'files'] as $folder) {
         $path = $webroot . '/' . $folder;
         if (!file_exists($path)) {
             echo "mkdir('{$path}', 0777)...";
             if (mkdir($path, 0777, true)) {
                 echo "done.\n";
             } else {
                 echo "failed.\n";
             }
         }
     }
     // Creates the default platform config
     /** @var \gromver\platform\basic\console\modules\main\Module $main */
     $cmf = Yii::$app->grom;
     $paramsPath = Yii::getAlias($cmf->paramsPath);
     $paramsFile = $paramsPath . DIRECTORY_SEPARATOR . 'params.php';
     $params = $cmf->params;
     $model = new \gromver\models\ObjectModel(\gromver\platform\basic\modules\main\models\PlatformParams::className());
     $model->setAttributes($params);
     echo 'Setup application config: ' . PHP_EOL;
     $this->readStdinUser('Site Name (My Site)', $model, 'siteName', 'My Site');
     $this->readStdinUser('Admin Email (admin@email.com)', $model, 'adminEmail', 'admin@email.com');
     $this->readStdinUser('Support Email (support@email.com)', $model, 'supportEmail', 'support@email.com');
     if ($model->validate()) {
         \yii\helpers\FileHelper::createDirectory($paramsPath);
         file_put_contents($paramsFile, '<?php return ' . var_export($model->toArray(), true) . ';');
         @chmod($paramsFile, 0777);
     }
     echo 'Setup complete.' . PHP_EOL;
 }

作者:freddyk    项目:humhu   
/**
  * @inheritdoc
  */
 protected function saveMessagesToPHP($messages, $dirName, $overwrite, $removeUnused, $sort, $markUnused)
 {
     $dirNameBase = $dirName;
     foreach ($messages as $category => $msgs) {
         /**
          * Fix Directory
          */
         $module = $this->getModuleByCategory($category);
         if ($module !== null) {
             // Use Module Directory
             $dirName = str_replace(Yii::getAlias("@humhub/messages"), $module->getBasePath() . '/messages', $dirNameBase);
             preg_match('/.*?Module\\.(.*)/', $category, $result);
             $category = $result[1];
         } else {
             // Use Standard HumHub Directory
             $dirName = $dirNameBase;
         }
         $file = str_replace("\\", '/', "{$dirName}/{$category}.php");
         $path = dirname($file);
         FileHelper::createDirectory($path);
         $msgs = array_values(array_unique($msgs));
         $coloredFileName = Console::ansiFormat($file, [Console::FG_CYAN]);
         $this->stdout("Saving messages to {$coloredFileName}...\n");
         $this->saveMessagesCategoryToPHP($msgs, $file, $overwrite, $removeUnused, $sort, $category, $markUnused);
     }
 }

作者:pavlinte    项目:yii2-adm-pages   
/**
  * @param integer $id
  * @return mixed
  */
 public function actionFiles($id, $id_parent = null)
 {
     $model = $this->findModel($id);
     $files = Module::getInst()->files;
     $startPath = '';
     if (!isset($files[$model->type])) {
         throw new InvalidConfigException('The "files" property for type(' . $model->type . ') must be set.');
     }
     if (isset($files[$model->type]['startPath'])) {
         $startPath = strtr($files[$model->type]['startPath'], ['{id}' => $model->id]);
     }
     foreach ($files[$model->type]['dirs'] as $path) {
         $dir = Yii::getAlias(strtr($path, ['{id}' => $model->id]));
         \yii\helpers\FileHelper::createDirectory($dir);
     }
     if (!$id_parent) {
         $id_parent = 0;
     }
     $elfinderData = [];
     //for https://github.com/pavlinter/yii2-adm-app
     $elfinderData['w'] = isset($files[$model->type]['maxWidth']) ? $files[$model->type]['maxWidth'] : 0;
     $elfinderData['h'] = isset($files[$model->type]['maxHeight']) ? $files[$model->type]['maxWidth'] : 0;
     $elfinderData['watermark'] = isset($files[$model->type]['watermark']) && $files[$model->type]['watermark'] ? 1 : 0;
     return $this->render('files', ['model' => $model, 'startPath' => $startPath, 'id_parent' => $id_parent, 'elfinderData' => $elfinderData]);
 }


问题


面经


文章

微信
公众号

扫码关注公众号