Browse Source

Exception usage has been added to "yii\console\controllers\MessageController".

tags/2.0.0-beta
Klimov Paul 12 years ago
parent
commit
3c9b157814
  1. 19
      framework/yii/console/controllers/MessageController.php

19
framework/yii/console/controllers/MessageController.php

@ -9,6 +9,8 @@
namespace yii\console\controllers;
use yii\console\Controller;
use yii\console\Exception;
use yii\helpers\FileHelper;
/**
* This command extracts messages to be translated from source files.
@ -26,6 +28,7 @@ class MessageController extends Controller
*
* @param string $config the path of the configuration file. You can find
* an example in framework/messages/config.php.
* @throws \yii\console\Exception on failure.
*
* The file can be placed anywhere and must be a valid PHP script which
* returns an array of name-value pairs. Each name-value pair represents
@ -58,25 +61,25 @@ class MessageController extends Controller
public function actionIndex($config)
{
if (!is_file($config)) {
$this->usageError("the configuration file {$config} does not exist.");
throw new Exception("the configuration file {$config} does not exist.");
}
$config = require_once($config);
$config = require($config);
$translator = 'Yii::t';
extract($config);
if (!isset($sourcePath, $messagePath, $languages)) {
$this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".');
throw new Exception('The configuration file must specify "sourcePath", "messagePath" and "languages".');
}
if (!is_dir($sourcePath)) {
$this->usageError("The source path $sourcePath is not a valid directory.");
throw new Exception("The source path {$sourcePath} is not a valid directory.");
}
if (!is_dir($messagePath)) {
$this->usageError("The message path $messagePath is not a valid directory.");
throw new Exception("The message path {$messagePath} is not a valid directory.");
}
if (empty($languages)) {
$this->usageError("Languages cannot be empty.");
throw new Exception("Languages cannot be empty.");
}
if (!isset($overwrite)) {
@ -96,7 +99,7 @@ class MessageController extends Controller
if (isset($exclude)) {
$options['exclude'] = $exclude;
}
$files = CFileHelper::findFiles(realpath($sourcePath), $options);
$files = FileHelper::findFiles(realpath($sourcePath), $options);
$messages = array();
foreach ($files as $file) {
@ -209,7 +212,7 @@ class MessageController extends Controller
/**
* Message translations.
*
* This file is automatically generated by 'yii message' command.
* This file is automatically generated by 'yii {$this->id}' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*

Loading…
Cancel
Save