Commit 3c9b1578 by Klimov Paul

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

parent a5e903f2
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
namespace yii\console\controllers; namespace yii\console\controllers;
use yii\console\Controller; use yii\console\Controller;
use yii\console\Exception;
use yii\helpers\FileHelper;
/** /**
* This command extracts messages to be translated from source files. * This command extracts messages to be translated from source files.
...@@ -26,6 +28,7 @@ class MessageController extends Controller ...@@ -26,6 +28,7 @@ class MessageController extends Controller
* *
* @param string $config the path of the configuration file. You can find * @param string $config the path of the configuration file. You can find
* an example in framework/messages/config.php. * 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 * 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 * returns an array of name-value pairs. Each name-value pair represents
...@@ -58,25 +61,25 @@ class MessageController extends Controller ...@@ -58,25 +61,25 @@ class MessageController extends Controller
public function actionIndex($config) public function actionIndex($config)
{ {
if (!is_file($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'; $translator = 'Yii::t';
extract($config); extract($config);
if (!isset($sourcePath, $messagePath, $languages)) { 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)) { 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)) { 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)) { if (empty($languages)) {
$this->usageError("Languages cannot be empty."); throw new Exception("Languages cannot be empty.");
} }
if (!isset($overwrite)) { if (!isset($overwrite)) {
...@@ -96,7 +99,7 @@ class MessageController extends Controller ...@@ -96,7 +99,7 @@ class MessageController extends Controller
if (isset($exclude)) { if (isset($exclude)) {
$options['exclude'] = $exclude; $options['exclude'] = $exclude;
} }
$files = CFileHelper::findFiles(realpath($sourcePath), $options); $files = FileHelper::findFiles(realpath($sourcePath), $options);
$messages = array(); $messages = array();
foreach ($files as $file) { foreach ($files as $file) {
...@@ -209,7 +212,7 @@ class MessageController extends Controller ...@@ -209,7 +212,7 @@ class MessageController extends Controller
/** /**
* Message translations. * 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. * It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages. * You may modify this file by translating the extracted messages.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment