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


PHP helpers\FileHelper类代码示例

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


在下文中一共展示了FileHelper类的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: tearDown

 protected function tearDown()
 {
     if (is_dir($this->tmpPath)) {
         FileHelper::removeDirectory($this->tmpPath);
     }
     parent::tearDown();
 }
开发者ID:howq,项目名称:yii2,代码行数:7,代码来源:AssetConverterTest.php

示例3: tearDown

 public function tearDown()
 {
     FileHelper::removeDirectory($this->sourcePath);
     if (file_exists($this->configFileName)) {
         unlink($this->configFileName);
     }
 }
开发者ID:albertborsos,项目名称:yii2,代码行数:7,代码来源:BaseMessageControllerTest.php

示例4: cleanAssetDir

 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;
 }
开发者ID:mbrowniebytes,项目名称:yii2-clean-assets,代码行数:33,代码来源:CleanAssetsController.php

示例5: tearDown

 public function tearDown()
 {
     $filePath = $this->getTestFilePath();
     if (file_exists($filePath)) {
         FileHelper::removeDirectory($filePath);
     }
 }
开发者ID:rajanishtimes,项目名称:basicyii,代码行数:7,代码来源:BaseMailerTest.php

示例6: getDirectories

 /**
  * @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;
 }
开发者ID:deesoft,项目名称:yii2-console,代码行数:32,代码来源:MigrateTrait.php

示例7: actionIndex

 public function actionIndex()
 {
     $src = DOCGEN_PATH . '/swagger-ui/';
     $dst = Yii::getAlias('@app') . '/web/apidoc/';
     FileHelper::copyDirectory($src, $dst);
     return Controller::EXIT_CODE_NORMAL;
 }
开发者ID:jiangrongyong,项目名称:docgen,代码行数:7,代码来源:PublishController.php

示例8: applyTo

 /**
  * @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;
 }
开发者ID:sheillendra,项目名称:yii2-theme,代码行数:63,代码来源:Theme.php

示例9: tearDown

 protected function tearDown()
 {
     parent::tearDown();
     FileHelper::removeDirectory(\Yii::$app->getModule('file')->upload_path);
     FileHelper::removeDirectory(\Yii::$app->getModule('file')->storage_path);
     $this->destroyApplication();
 }
开发者ID:rmrevin,项目名称:yii2-file,代码行数:7,代码来源:TestCase.php

示例10: init

 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;
 }
开发者ID:phpsong,项目名称:yii2-extjs-rbac,代码行数:27,代码来源:Controller.php

示例11: loadActiveModules

 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);
         }
     }
 }
开发者ID:huasxin,项目名称:lulucms2,代码行数:28,代码来源:BaseApplication.php

示例12: actionIndex

 /**
  * @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]);
 }
开发者ID:hassiumsoft,项目名称:hasscms-packages,代码行数:35,代码来源:DefaultController.php

示例13: actionIndex

 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())));
     }
 }
开发者ID:jaslin,项目名称:yii2-kindeditor,代码行数:26,代码来源:DefaultController.php

示例14: init

 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;
         }
     }
 }
开发者ID:chabberwock,项目名称:halo-dev,代码行数:31,代码来源:PluginManager.php

示例15: init

 /**
  * @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;
 }
开发者ID:heartshare,项目名称:dotplant2,代码行数:10,代码来源:FileInputProperty.php


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