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


PHP FileHelper::filterPath方法代码示例

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


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

示例1: run

 /**
  * @inheritdoc
  */
 public function run(&$cmdParams, &$params)
 {
     // TODO: add log info
     $res = true;
     $taskRunner = $this->taskRunner;
     $toBeParsed = [];
     $fileList = !empty($cmdParams[0]) ? $cmdParams[0] : [];
     $this->_replaceList = !empty($cmdParams[1]) ? $cmdParams[1] : $this->_replaceList;
     $baseDir = !empty($cmdParams[2]) ? $taskRunner->parsePath($cmdParams[2]) : '';
     $options = !empty($cmdParams[3]) ? $cmdParams[3] : [];
     if (!empty($baseDir) && (!empty($baseDir) && !is_dir($baseDir))) {
         Log::throwException('replaceInFiles: baseDir has to be a directory');
     }
     // if $fileList is specified but it is a string, we convert it to an array
     if (!empty($fileList) && is_string($fileList)) {
         $fileList = explode(',', $fileList);
     }
     foreach ($fileList as $srcPath) {
         $parsedPath = $taskRunner->parseStringAliases(trim($srcPath));
         if (!empty($baseDir)) {
             $toBeParsed[$parsedPath] = $baseDir . DIRECTORY_SEPARATOR . $parsedPath;
         } else {
             $toBeParsed[] = $parsedPath;
         }
     }
     $this->controller->stdout("Replacing in files: ");
     foreach ($toBeParsed as $srcRelPath => $srcFullPath) {
         if (file_exists($srcFullPath)) {
             if (is_dir($srcFullPath)) {
                 $files = FileHelper::findFiles($srcFullPath, $options);
                 foreach ($files as $foundPath) {
                     $this->_replace($foundPath);
                 }
             } elseif (FileHelper::filterPath($srcFullPath, $options)) {
                 $this->_replace($srcFullPath);
             }
         } else {
             $this->controller->stderr("\n{$srcFullPath} does not exists!\n", Console::FG_RED);
         }
     }
     $this->controller->stdout("\n");
     return $res;
 }
开发者ID:giovdk21,项目名称:deployii,代码行数:46,代码来源:ReplaceInFilesCommand.php

示例2: saeCopyDirectory

 public static function saeCopyDirectory($src, $dst, $options = [])
 {
     $handle = opendir($src);
     if ($handle === false) {
         throw new InvalidParamException('Unable to open directory: ' . $src);
     }
     if (!isset($options['basePath'])) {
         // this should be done only once
         $options['basePath'] = realpath($src);
     }
     while (($file = readdir($handle)) !== false) {
         if ($file === '.' || $file === '..') {
             continue;
         }
         $from = $src . DIRECTORY_SEPARATOR . $file;
         $to = $dst . '/' . $file;
         if (FileHelper::filterPath($from, $options)) {
             if (isset($options['beforeCopy']) && !call_user_func($options['beforeCopy'], $from, $to)) {
                 continue;
             }
             if (is_file($from)) {
                 copy($from, $to);
             } else {
                 static::saeCopyDirectory($from, $to, $options);
             }
             if (isset($options['afterCopy'])) {
                 call_user_func($options['afterCopy'], $from, $to);
             }
         }
     }
     closedir($handle);
 }
开发者ID:weiforrest,项目名称:Yii2-StorageManage,代码行数:32,代码来源:SaeAssetManager.php

示例3: run

 /**
  * @inheritdoc
  */
 public function run(&$cmdParams, &$params)
 {
     $res = true;
     $taskRunner = $this->taskRunner;
     $toBeAdded = [];
     $srcList = !empty($cmdParams[0]) ? $cmdParams[0] : [];
     $destFile = !empty($cmdParams[1]) ? $taskRunner->parsePath($cmdParams[1]) : '';
     $srcBaseDir = !empty($cmdParams[2]) ? $taskRunner->parsePath($cmdParams[2]) : '';
     $format = !empty($cmdParams[3]) ? strtolower($cmdParams[3]) : self::CMP_GZ;
     $options = !empty($cmdParams[4]) ? $cmdParams[4] : [];
     if (!empty($srcBaseDir) && !is_dir($srcBaseDir)) {
         Log::throwException('compress: srcBaseDir has to be a directory');
     }
     if (empty($destFile) || file_exists($destFile) && is_dir($destFile)) {
         Log::throwException('compress: Destination has to be a file');
     }
     switch ($format) {
         case self::CMP_NONE:
             $extension = '.tar';
             $compression = \Phar::NONE;
             $doCompress = false;
             break;
         case self::CMP_GZ:
             $extension = '.tar.gz';
             $compression = \Phar::GZ;
             $doCompress = true;
             break;
         case self::CMP_BZ2:
             $extension = '.tar.bz2';
             $compression = \Phar::BZ2;
             $doCompress = true;
             break;
         default:
             $extension = '';
             $compression = false;
             $doCompress = false;
             Log::throwException('compress: Invalid format specified: ' . $format);
             break;
     }
     // if $srcList is specified but it is a string, we convert it to an array
     if (!empty($srcList) && is_string($srcList)) {
         $srcList = explode(',', $srcList);
     }
     foreach ($srcList as $srcPath) {
         $parsedPath = $taskRunner->parseStringAliases(trim($srcPath));
         if (!empty($srcBaseDir)) {
             $toBeAdded[$parsedPath] = $srcBaseDir . DIRECTORY_SEPARATOR . $parsedPath;
         } else {
             $toBeAdded[] = $parsedPath;
         }
     }
     $this->controller->stdout("Creating archive: ");
     $this->controller->stdout($destFile, Console::FG_BLUE);
     $archive = null;
     $destDir = dirname($destFile);
     $destBaseFile = $destDir . DIRECTORY_SEPARATOR . basename($destFile, '.tar');
     if (!$this->controller->dryRun) {
         if (!is_dir($destDir)) {
             FileHelper::createDirectory($destDir);
         }
         @unlink($destFile);
         @unlink($destBaseFile);
         try {
             $archive = new \PharData($destFile);
         } catch (\Exception $e) {
             Log::throwException($e->getMessage());
         }
     } else {
         $this->controller->stdout(' [dry run]', Console::FG_YELLOW);
     }
     $this->controller->stdout("\n");
     $this->controller->stdout("Adding to archive: ");
     foreach ($toBeAdded as $srcRelPath => $srcFullPath) {
         if (file_exists($srcFullPath)) {
             $this->controller->stdout("\n - " . $srcFullPath);
             if (!$this->controller->dryRun) {
                 if (is_dir($srcFullPath)) {
                     $files = FileHelper::findFiles($srcFullPath, $options);
                     $archive->buildFromIterator(new ArrayIterator($files), !empty($srcBaseDir) ? $srcBaseDir : $srcFullPath);
                 } elseif (FileHelper::filterPath($srcFullPath, $options)) {
                     $archive->addFile($srcFullPath, !empty($srcBaseDir) ? $srcRelPath : basename($srcFullPath));
                 }
             } else {
                 $this->controller->stdout(' [dry run]', Console::FG_YELLOW);
             }
         } else {
             $this->controller->stderr("\n{$srcFullPath} does not exists!\n", Console::FG_RED);
         }
     }
     $this->controller->stdout("\n");
     if ($doCompress) {
         $this->controller->stdout("Compressing archive: ");
         $this->controller->stdout($destBaseFile . $extension, Console::FG_CYAN);
         if (!$this->controller->dryRun) {
             @unlink($destBaseFile . $extension);
             try {
                 $archive->compress($compression, $extension);
//.........这里部分代码省略.........
开发者ID:giovdk21,项目名称:deployii,代码行数:101,代码来源:CompressCommand.php

示例4: _put

 private function _put($srcFullPath, $srcRelPath)
 {
     $destRelPath = $this->_destDir . '/' . $srcRelPath;
     $this->controller->stdout("\n - " . $srcRelPath . "\t => " . $destRelPath);
     if (!$this->controller->dryRun) {
         if (is_dir($srcFullPath)) {
             $files = FileHelper::findFiles($srcFullPath, $this->_options);
             foreach ($files as $foundPath) {
                 $relativePath = substr($foundPath, strlen($this->_srcBaseDir) + 1);
                 $this->_sftpHelper->mkdir($destRelPath);
                 $this->_put($foundPath, $relativePath, $this->_srcBaseDir, $this->_destDir, $this->_options);
             }
         } elseif (FileHelper::filterPath($srcFullPath, $this->_options)) {
             $this->_sftpHelper->mkdir(dirname($destRelPath), -1, true);
             if ($this->_overwrite || !$this->_sftpHelper->fileExists($destRelPath)) {
                 $res = $this->_sftpHelper->put($destRelPath, $srcFullPath);
                 if (!$res) {
                     Log::logger()->addError('sftpPut: error uploading file {from} to {to}', ['from' => $srcFullPath, 'to' => $destRelPath]);
                 }
             } else {
                 $this->controller->stdout(' [skipped]', Console::FG_PURPLE);
             }
         }
     } else {
         $this->controller->stdout(' [dry run]', Console::FG_YELLOW);
     }
 }
开发者ID:giovdk21,项目名称:deployii,代码行数:27,代码来源:SftpPutCommand.php


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