示例#1
0
 /**
  * Initializes mutex component implementation dedicated for UNIX, GNU/Linux, Mac OS X, and other UNIX-like
  * operating systems.
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (DIRECTORY_SEPARATOR === '\\') {
         throw new InvalidConfigException('FileMutex does not have MS Windows operating system support.');
     }
     $this->mutexPath = Leaps::getAlias($this->mutexPath);
     if (!is_dir($this->mutexPath)) {
         FileHelper::createDirectory($this->mutexPath, $this->dirMode, true);
     }
 }
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * It checks the existence of the [[migrationPath]].
  * @param \yii\base\Action $action the action to be executed.
  * @throws Exception if directory specified in migrationPath doesn't exist and action isn't "create".
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $path = Leaps::getAlias($this->migrationPath);
         if (!is_dir($path)) {
             if ($action->id !== 'create') {
                 throw new Exception("Migration failed. Directory specified in migrationPath doesn't exist: {$this->migrationPath}");
             }
             FileHelper::createDirectory($path);
         }
         $this->migrationPath = $path;
         $version = Leaps::getVersion();
         $this->stdout("Leaps Migration Tool (based on Leaps v{$version})\n\n");
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /**
  * 发布文件
  *
  * @param string $src the asset file to be published
  * @return array the path and the URL that the asset is published as.
  * @throws InvalidParamException if the asset to be published does not exist.
  */
 protected function publishFile($src)
 {
     $dir = $this->hash($src);
     $fileName = basename($src);
     $dstDir = $this->basePath . DIRECTORY_SEPARATOR . $dir;
     $dstFile = $dstDir . DIRECTORY_SEPARATOR . $fileName;
     if (!is_dir($dstDir)) {
         FileHelper::createDirectory($dstDir, $this->dirMode, true);
     }
     if ($this->linkAssets) {
         if (!is_file($dstFile)) {
             symlink($src, $dstFile);
         }
     } elseif (@filemtime($dstFile) < @filemtime($src)) {
         copy($src, $dstFile);
         if ($this->fileMode !== null) {
             @chmod($dstFile, $this->fileMode);
         }
     }
     return [$dstFile, $this->baseUrl . "/{$dir}/{$fileName}"];
 }
 /**
  * Writes messages into POT file
  *
  * @param array $messages
  * @param string $dirName name of the directory to write to
  * @param string $catalog message catalog
  * @since 2.0.6
  */
 protected function saveMessagesToPOT($messages, $dirName, $catalog)
 {
     $file = str_replace("\\", '/', "{$dirName}/{$catalog}.pot");
     FileHelper::createDirectory(dirname($file));
     $this->stdout("Saving messages to {$file}...\n");
     $poFile = new GettextPoFile();
     $merged = [];
     $hasSomethingToWrite = false;
     foreach ($messages as $category => $msgs) {
         $msgs = array_values(array_unique($msgs));
         sort($msgs);
         foreach ($msgs as $message) {
             $merged[$category . chr(4) . $message] = '';
         }
         ksort($merged);
         $this->stdout("Category \"{$category}\" merged.\n");
         $hasSomethingToWrite = true;
     }
     if ($hasSomethingToWrite) {
         $poFile->save($file, $merged);
         $this->stdout("Translation saved.\n", Console::FG_GREEN);
     } else {
         $this->stdout("Nothing to save.\n", Console::FG_GREEN);
     }
 }
示例#5
0
 /**
  * Stores a value identified by a key in cache.
  * This is the implementation of the method declared in the parent class.
  *
  * @param string $key the key identifying the value to be cached
  * @param string $value the value to be cached
  * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true if the value is successfully stored into cache, false otherwise
  */
 protected function setValue($key, $value, $duration)
 {
     $this->gc();
     $cacheFile = $this->getCacheFile($key);
     if ($this->directoryLevel > 0) {
         @FileHelper::createDirectory(dirname($cacheFile), $this->dirMode, true);
     }
     if (@file_put_contents($cacheFile, $value, LOCK_EX) !== false) {
         if ($this->fileMode !== null) {
             @chmod($cacheFile, $this->fileMode);
         }
         if ($duration <= 0) {
             $duration = 31536000;
             // 1 year
         }
         return @touch($cacheFile, $duration + time());
     } else {
         $error = error_get_last();
         Leaps::warning("Unable to write cache file '{$cacheFile}': {$error['message']}", __METHOD__);
         return false;
     }
 }
 /**
  * Builds output asset bundle.
  * @param \yii\web\AssetBundle $target output asset bundle
  * @param string $type either 'js' or 'css'.
  * @param \yii\web\AssetBundle[] $bundles source asset bundles.
  * @throws Exception on failure.
  */
 protected function buildTarget($target, $type, $bundles)
 {
     $inputFiles = [];
     foreach ($target->depends as $name) {
         if (isset($bundles[$name])) {
             if (!$this->isBundleExternal($bundles[$name])) {
                 foreach ($bundles[$name]->{$type} as $file) {
                     $inputFiles[] = $bundles[$name]->basePath . '/' . $file;
                 }
             }
         } else {
             throw new Exception("Unknown bundle: '{$name}'");
         }
     }
     if (empty($inputFiles)) {
         $target->{$type} = [];
     } else {
         FileHelper::createDirectory($target->basePath, $this->getAssetManager()->dirMode);
         $tempFile = $target->basePath . '/' . strtr($target->{$type}, ['{hash}' => 'temp']);
         if ($type === 'js') {
             $this->compressJsFiles($inputFiles, $tempFile);
         } else {
             $this->compressCssFiles($inputFiles, $tempFile);
         }
         $targetFile = strtr($target->{$type}, ['{hash}' => md5_file($tempFile)]);
         $outputFile = $target->basePath . '/' . $targetFile;
         rename($tempFile, $outputFile);
         $target->{$type} = [$targetFile];
     }
 }
示例#7
0
 /**
  * Initializes the route.
  * This method is invoked after the route is created by the route manager.
  */
 public function init()
 {
     parent::init();
     if ($this->logFile === null) {
         $this->logFile = Leaps::$app->getRuntimePath() . '/logs/app.log';
     } else {
         $this->logFile = Leaps::getAlias($this->logFile);
     }
     $logPath = dirname($this->logFile);
     if (!is_dir($logPath)) {
         FileHelper::createDirectory($logPath, $this->dirMode, true);
     }
     if ($this->maxLogFiles < 1) {
         $this->maxLogFiles = 1;
     }
     if ($this->maxFileSize < 1) {
         $this->maxFileSize = 1;
     }
 }