From 8a996b9f94457eb517cc8ba1d308e3d38005028b Mon Sep 17 00:00:00 2001 From: Web-VPF Date: Sat, 15 Jan 2022 13:38:27 +0200 Subject: [PATCH 1/4] localization of error messages --- classes/BaseModel.php | 2 +- classes/ComponentHelper.php | 4 +- classes/ControllerModel.php | 4 +- classes/DatabaseTableModel.php | 4 +- classes/IndexOperationsBehaviorBase.php | 4 +- classes/LanguageMixer.php | 2 +- classes/LocalizationModel.php | 10 ++--- classes/MenusModel.php | 8 ++-- classes/MigrationColumnType.php | 4 +- classes/MigrationModel.php | 20 ++++----- classes/ModelFormModel.php | 4 +- classes/ModelListModel.php | 6 +-- classes/ModelModel.php | 4 +- classes/ModelYamlModel.php | 4 +- classes/PermissionsModel.php | 4 +- classes/PhpSourceStream.php | 4 +- classes/PluginCode.php | 6 +-- classes/PluginVersion.php | 2 +- classes/YamlModel.php | 8 ++-- lang/en/lang.php | 59 +++++++++++++++++++++++-- 20 files changed, 107 insertions(+), 56 deletions(-) diff --git a/classes/BaseModel.php b/classes/BaseModel.php index 138427f..7385167 100644 --- a/classes/BaseModel.php +++ b/classes/BaseModel.php @@ -123,7 +123,7 @@ public function getModelPluginName() public function getPluginCodeObj() { if (!$this->pluginCodeObj) { - throw new SystemException(sprintf('The active plugin is not set in the %s object.', get_class($this))); + throw new SystemException(Lang::get('winter.builder::lang.plugin.error_active_plugin_is_not_set', ['class'=>get_class($this)])); } return $this->pluginCodeObj; diff --git a/classes/ComponentHelper.php b/classes/ComponentHelper.php index 7582e6e..0a0fbbd 100644 --- a/classes/ComponentHelper.php +++ b/classes/ComponentHelper.php @@ -64,7 +64,7 @@ public function getModelClassDesignTime() $modelClass = trim(Input::get('modelClass')); if ($modelClass && !is_scalar($modelClass)) { - throw new ApplicationException('Model class name should be a string.'); + throw new ApplicationException(Lang::get('winter.builder::lang.components.error_model_class_name_should_be_a_string')); } if (!strlen($modelClass)) { @@ -73,7 +73,7 @@ public function getModelClassDesignTime() } if (!ModelModel::validateModelClassName($modelClass)) { - throw new ApplicationException('Invalid model class name.'); + throw new ApplicationException(Lang::get('winter.builder::lang.components.error_invalid_model_class_name')); } return $modelClass; diff --git a/classes/ControllerModel.php b/classes/ControllerModel.php index f3b6c4f..9ad2b48 100644 --- a/classes/ControllerModel.php +++ b/classes/ControllerModel.php @@ -42,7 +42,7 @@ class ControllerModel extends BaseModel public function load($controller) { if (!$this->validateFileName($controller)) { - throw new SystemException('Invalid controller file name: '.$language); + throw new SystemException(Lang::get('winter.builder::lang.controller.error_invalid_controller_file_name', ['language'=>$language])); } $this->controller = $this->trimExtension($controller); @@ -221,7 +221,7 @@ protected function saveController() } if (!is_array($this->behaviors)) { - throw new SystemException('The behaviors data should be an array.'); + throw new SystemException(Lang::get('winter.builder::lang.controller.error_behaviors_data_should_be_an_array')); } $fileContents = File::get($controllerPath); diff --git a/classes/DatabaseTableModel.php b/classes/DatabaseTableModel.php index 967df11..c7e6194 100644 --- a/classes/DatabaseTableModel.php +++ b/classes/DatabaseTableModel.php @@ -74,7 +74,7 @@ public static function tableExists($name) public function load($name) { if (!self::tableExists($name)) { - throw new SystemException(sprintf('The table with name %s doesn\'t exist', $name)); + throw new SystemException(Lang::get('winter.builder::lang.database.error_table_with_name_doesnt_exist', ['name'=>$name])); } $schema = self::getSchemaManager()->createSchema(); @@ -90,7 +90,7 @@ public function validate() $pluginDbPrefix = $this->getPluginCodeObj()->toDatabasePrefix(); if (!strlen($pluginDbPrefix)) { - throw new SystemException('Error saving the table model - the plugin database prefix is not set for the object.'); + throw new SystemException(Lang::get('winter.builder::lang.database.error_saving_table_model_plugin_database_prefix_is_not_set_for_object')); } $prefix = $pluginDbPrefix.'_'; diff --git a/classes/IndexOperationsBehaviorBase.php b/classes/IndexOperationsBehaviorBase.php index cfa0c85..dbfd571 100644 --- a/classes/IndexOperationsBehaviorBase.php +++ b/classes/IndexOperationsBehaviorBase.php @@ -17,7 +17,7 @@ abstract class IndexOperationsBehaviorBase extends ControllerBehavior protected function makeBaseFormWidget($modelCode, $options = [], $aliasSuffix = null) { if (!strlen($this->baseFormConfigFile)) { - throw new ApplicationException(sprintf('Base form configuration file is not specified for %s behavior', get_class($this))); + throw new ApplicationException(Lang::get('winter.builder::lang.behavior.error_base_form_configuration_file_is_not_specified', ['class'=>get_class($this)])); } $widgetConfig = $this->makeConfig($this->baseFormConfigFile); @@ -36,7 +36,7 @@ protected function getPluginCode() $vector = $this->controller->getBuilderActivePluginVector(); if (!$vector) { - throw new ApplicationException('Cannot determine the currently active plugin.'); + throw new ApplicationException(Lang::get('winter.builder::lang.behavior.error_cannot_determine_currently_active_plugin')); } return $vector->pluginCodeObj; diff --git a/classes/LanguageMixer.php b/classes/LanguageMixer.php index aa871c0..f7562cb 100644 --- a/classes/LanguageMixer.php +++ b/classes/LanguageMixer.php @@ -28,7 +28,7 @@ public function addStringsFromAnotherLanguage($destContents, $srcArray) $destArray = Yaml::parse($destContents); } catch (Exception $ex) { - throw new ApplicationException(sprintf('Cannot parse the YAML content: %s', $ex->getMessage())); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_parse_yaml', ['message'=>$ex->getMessage()])); } if (!$destArray) { diff --git a/classes/LocalizationModel.php b/classes/LocalizationModel.php index a0720d3..9b49ed8 100644 --- a/classes/LocalizationModel.php +++ b/classes/LocalizationModel.php @@ -118,7 +118,7 @@ public function save() public function deleteModel() { if ($this->isNewModel()) { - throw new ApplicationException('Cannot delete language file which is not saved yet.'); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_delete_lang_file_which_is_not_saved')); } $filePath = File::symbolizePath($this->getFilePath()); @@ -227,7 +227,7 @@ public static function getDefaultLanguage() $language = Config::get('app.locale'); if (!$language) { - throw new ApplicationException('The default language is not defined in the application configuration (app.locale).'); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_default_language_is_not_defined')); } return $language; @@ -329,11 +329,11 @@ protected function getFilePath($language = null) $language = trim($language); if (!strlen($language)) { - throw new SystemException('The form model language is not set.'); + throw new SystemException(Lang::get('winter.builder::lang.localization.error_form_language_is_not_set')); } if (!$this->validateLanguage($language)) { - throw new SystemException('Invalid language file name: '.$language); + throw new SystemException(Lang::get('winter.builder::lang.localization.error_invalid_language_file_name'), ['lang'=>$language]); } $path = $this->getPluginCodeObj()->toPluginDirectoryPath().'/lang/'.$language.'/lang.php'; @@ -364,7 +364,7 @@ protected function modelToLanguageFile() return "getMessage())); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_parse_yaml'), ['message'=>$ex->getMessage()]); } } diff --git a/classes/MenusModel.php b/classes/MenusModel.php index 9c5c4de..cdb17a5 100644 --- a/classes/MenusModel.php +++ b/classes/MenusModel.php @@ -35,7 +35,7 @@ protected function modelToYamlArray() $mainMenuItem = $this->trimMenuProperties($mainMenuItem); if (!isset($mainMenuItem['code'])) { - throw new ApplicationException('Cannot save menus - the main menu item code should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.menu.error_main_menu_item_code_should_not_be_empty')); } if (isset($mainMenuItem['sideMenu'])) { @@ -45,7 +45,7 @@ protected function modelToYamlArray() $sideMenuItem = $this->trimMenuProperties($sideMenuItem); if (!isset($sideMenuItem['code'])) { - throw new ApplicationException('Cannot save menus - the side menu item code should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.menu.error_side_menu_item_code_should_not_be_empty')); } $code = $sideMenuItem['code']; @@ -79,7 +79,7 @@ public function fill(array $attributes) $attributes['menus'] = json_decode($attributes['menus'], true); if ($attributes['menus'] === null) { - throw new SystemException('Cannot decode menus JSON string.'); + throw new SystemException(Lang::get('winter.builder::lang.menu.error_cannot_decode_menus_json_string')); } } @@ -141,7 +141,7 @@ protected function trimMenuProperties($menu) protected function getFilePath() { if ($this->pluginCodeObj === null) { - throw new SystemException('Error saving plugin menus model - the plugin code object is not set.'); + throw new SystemException(Lang::get('winter.builder::lang.menu.error_plugin_code_object_is_not_set')); } return $this->pluginCodeObj->toPluginFilePath(); diff --git a/classes/MigrationColumnType.php b/classes/MigrationColumnType.php index d3dc52e..fe8b3c0 100644 --- a/classes/MigrationColumnType.php +++ b/classes/MigrationColumnType.php @@ -90,7 +90,7 @@ public static function toDoctrineTypeName($type) $typeMap = self::getDoctrineTypeMap(); if (!array_key_exists($type, $typeMap)) { - throw new SystemException(sprintf('Unknown column type: %s', $type)); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_column_type', ['type'=>$type])); } return $typeMap[$type]; @@ -104,7 +104,7 @@ public static function toMigrationMethodName($type, $columnName) $typeMap = self::getDoctrineTypeMap(); if (!in_array($type, $typeMap)) { - throw new SystemException(sprintf('Unknown column type: %s', $type)); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_column_type', ['type'=>$type])); } // Some Doctrine types map to multiple migration types, for example diff --git a/classes/MigrationModel.php b/classes/MigrationModel.php index 2a87a0d..d880a70 100644 --- a/classes/MigrationModel.php +++ b/classes/MigrationModel.php @@ -100,7 +100,7 @@ public function getNextVersion() $versionNumbers = []; if (!preg_match('/^([0-9]+)\.([0-9]+)\.([0-9]+)$/', $latestVersion, $versionNumbers)) { - throw new SystemException(sprintf('Cannot parse the latest plugin version number: %s.', $latestVersion)); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_cannot_parse_latest_plugin_version', ['version'=>$latestVersion])); } return $versionNumbers[1].'.'.$versionNumbers[2].'.'.($versionNumbers[3]+1); @@ -151,12 +151,12 @@ public function load($versionNumber) $versionNumber = trim($versionNumber); if (!strlen($versionNumber)) { - throw new ApplicationException('Cannot load the the version model - the version number should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_cannot_load_version_model_should_not_be_empty')); } $pluginVersions = $this->getPluginVersionInformation(); if (!array_key_exists($versionNumber, $pluginVersions)) { - throw new ApplicationException('The requested version does not exist in the version information file.'); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_requested_version_does_not_exist')); } $this->version = $versionNumber; @@ -171,7 +171,7 @@ public function load($versionNumber) $cnt = count($versionInformation); if ($cnt > 2) { - throw new ApplicationException('The requested version cannot be edited with Builder as it refers to multiple PHP scripts.'); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_requested_version_cannot_be_edited')); } if ($cnt > 0) { @@ -192,7 +192,7 @@ public function initVersion($versionType) $versionTypes = ['migration', 'seeder', 'custom']; if (!in_array($versionType, $versionTypes)) { - throw new SystemException('Unknown version type.'); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_version_type')); } $this->version = $this->getNextVersion(); @@ -340,7 +340,7 @@ protected function saveScriptFile() $scriptFilePath = $this->getPluginUpdatesPath($this->scriptFileName.'.php'); if (!File::put($scriptFilePath, $this->code)) { - throw new SystemException(sprintf('Error saving file %s', $scriptFilePath)); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path'=>$scriptFilePath])); } @File::chmod($scriptFilePath); @@ -373,7 +373,7 @@ protected function loadScriptFile() $scriptFilePath = $this->getPluginUpdatesPath($this->scriptFileName.'.php'); if (!File::isFile($scriptFilePath)) { - throw new ApplicationException(sprintf('Version file %s is not found.', $scriptFilePath)); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_version_file_is_not_found', ['path'=>$scriptFilePath])); } return File::get($scriptFilePath); @@ -424,7 +424,7 @@ protected function insertOrUpdateVersion() $originalFileContents = File::get($versionFilePath); if (!$originalFileContents) { - throw new SystemException(sprintf('Error loading file %s', $versionFilePath)); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_loading_file', ['path'=>$scriptFilePath])); } $versionInformation[$this->version] = [ @@ -444,7 +444,7 @@ protected function insertOrUpdateVersion() $yamlData = Yaml::render($versionInformation); if (!File::put($versionFilePath, $yamlData)) { - throw new SystemException(sprintf('Error saving file %s', $versionFilePath)); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path'=>$scriptFilePath])); } @File::chmod($versionFilePath); @@ -467,7 +467,7 @@ protected function deleteVersion() $yamlData = Yaml::render($versionInformation); if (!File::put($versionFilePath, $yamlData)) { - throw new SystemException(sprintf('Error saving file %s', $versionFilePath)); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path'=>$scriptFilePath])); } @File::chmod($versionFilePath); diff --git a/classes/ModelFormModel.php b/classes/ModelFormModel.php index ef66f03..5c29682 100644 --- a/classes/ModelFormModel.php +++ b/classes/ModelFormModel.php @@ -35,7 +35,7 @@ public function fill(array $attributes) $attributes['controls'] = json_decode($attributes['controls'], true); if ($attributes['controls'] === null) { - throw new SystemException('Cannot decode controls JSON string.'); + throw new SystemException(Lang::get('winter.builder::lang.form.error_cannot_decode_controls_json_string')); } } @@ -64,7 +64,7 @@ public function validate() parent::validate(); if (!$this->controls) { - throw new ValidationException(['controls' => 'Please create at least one field.']); + throw new ValidationException(['controls' => Lang::get('winter.builder::lang.form.validation_create_at_least_one_field')]); } } diff --git a/classes/ModelListModel.php b/classes/ModelListModel.php index 035fc43..672341d 100644 --- a/classes/ModelListModel.php +++ b/classes/ModelListModel.php @@ -37,7 +37,7 @@ public function fill(array $attributes) $attributes['columns'] = json_decode($attributes['columns'], true); if ($attributes['columns'] === null) { - throw new SystemException('Cannot decode columns JSON string.'); + throw new SystemException(Lang::get('winter.builder::lang.list.error_cannot_decode_columns_json_string')); } } @@ -66,7 +66,7 @@ public function validate() $this->validateDupicateColumns(); if (!$this->columns) { - throw new ValidationException(['columns' => 'Please create at least one column.']); + throw new ValidationException(['columns' => Lang::get('winter.builder::lang.list.validation_columns_create_at_least_one_column')]); } } @@ -101,7 +101,7 @@ protected function modelToYamlArray() foreach ($this->columns as $column) { if (!isset($column['field'])) { - throw new ApplicationException('Cannot save the list - the column field name should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.list.error_name_should_not_be_empty')); } $columnName = $column['field']; diff --git a/classes/ModelModel.php b/classes/ModelModel.php index 36ba629..e2fa4ec 100644 --- a/classes/ModelModel.php +++ b/classes/ModelModel.php @@ -161,7 +161,7 @@ public function getDatabaseTableOptions() private static function getTableNameFromModelClass($pluginCodeObj, $modelClassName) { if (!self::validateModelClassName($modelClassName)) { - throw new SystemException('Invalid model class name: '.$modelClassName); + throw new SystemException(Lang::get('winter.builder::lang.model.error_invalid_model_class_name', ['class'=>$modelClassName])); } $modelsDirectoryPath = File::symbolizePath($pluginCodeObj->toPluginDirectoryPath().'/models'); @@ -198,7 +198,7 @@ public static function getModelColumnsAndTypes($pluginCodeObj, $modelClassName) $tableName = self::getTableNameFromModelClass($pluginCodeObj, $modelClassName); if (!DatabaseTableModel::tableExists($tableName)) { - throw new ApplicationException('Database table not found: '.$tableName); + throw new ApplicationException(Lang::get('winter.builder::lang.model.error_db_table_not_found', ['table'=>$tableName])); } $schema = DatabaseTableModel::getSchema(); diff --git a/classes/ModelYamlModel.php b/classes/ModelYamlModel.php index 0b85336..8efe874 100644 --- a/classes/ModelYamlModel.php +++ b/classes/ModelYamlModel.php @@ -169,7 +169,7 @@ protected static function validateModelClassName($modelClassName) protected function getModelClassName() { if ($this->modelClassName === null) { - throw new SystemException('The model class name is not set.'); + throw new SystemException(Lang::get('winter.builder::lang.yaml.error_model_class_name_is_not_set')); } return $this->modelClassName; @@ -184,7 +184,7 @@ protected function getFilePath() { $fileName = trim($this->fileName); if (!strlen($fileName)) { - throw new SystemException('The form model file name is not set.'); + throw new SystemException(Lang::get('winter.builder::lang.yaml.error_form_model_file_name_is_not_set')); } $fileName = $this->addExtension($fileName); diff --git a/classes/PermissionsModel.php b/classes/PermissionsModel.php index 90e66e2..f204e79 100644 --- a/classes/PermissionsModel.php +++ b/classes/PermissionsModel.php @@ -48,7 +48,7 @@ protected function modelToYamlArray() } if (!isset($permission['permission'])) { - throw new ApplicationException('Cannot save permissions - the permission code should not be empty.'); + throw new ApplicationException(Lang::get('winter.builder::lang.permission.error_save_permissions_code_should_not_be_empty')); } $code = $permission['permission']; @@ -188,7 +188,7 @@ protected function yamlArrayToModel($array) protected function getFilePath() { if ($this->pluginCodeObj === null) { - throw new SystemException('Error saving plugin permission model - the plugin code object is not set.'); + throw new SystemException(Lang::get('winter.builder::lang.permission.error_saving_permission_code_is_not_set')); } return $this->pluginCodeObj->toPluginFilePath(); diff --git a/classes/PhpSourceStream.php b/classes/PhpSourceStream.php index 10291c0..a858cfd 100644 --- a/classes/PhpSourceStream.php +++ b/classes/PhpSourceStream.php @@ -68,7 +68,7 @@ public function restoreBookmark() { $head = array_pop($this->headBookmarks); if ($head === null) { - throw new SystemException("Can't restore PHP token stream bookmark - the bookmark doesn't exist"); + throw new SystemException(Lang::get('winter.builder::lang.stream.error_cant_restore_token_stream_bookmark')); } return $this->setHead($head); @@ -81,7 +81,7 @@ public function discardBookmark() { $head = array_pop($this->headBookmarks); if ($head === null) { - throw new SystemException("Can't discard PHP token stream bookmark - the bookmark doesn't exist"); + throw new SystemException(Lang::get('winter.builder::lang.stream.error_cant_discard_token_stream_bookmark')); } } diff --git a/classes/PluginCode.php b/classes/PluginCode.php index 7fba203..dbbed57 100644 --- a/classes/PluginCode.php +++ b/classes/PluginCode.php @@ -18,13 +18,13 @@ public function __construct($pluginCodeStr) { $codeParts = explode('.', $pluginCodeStr); if (count($codeParts) !== 2) { - throw new ApplicationException(sprintf('Invalid plugin code: %s', $pluginCodeStr)); + throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_code', ['code'=>$pluginCodeStr])); } list($authorCode, $pluginCode) = $codeParts; if (!$this->validateCodeWord($authorCode) || !$this->validateCodeWord($pluginCode)) { - throw new ApplicationException(sprintf('Invalid plugin code: %s', $pluginCodeStr)); + throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_code', ['code'=>$pluginCodeStr])); } $this->authorCode = trim($authorCode); @@ -35,7 +35,7 @@ public static function createFromNamespace($namespace) { $namespaceParts = explode('\\', $namespace); if (count($namespaceParts) < 2) { - throw new ApplicationException('Invalid plugin namespace value.'); + throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_namespace')); } $authorCode = $namespaceParts[0]; diff --git a/classes/PluginVersion.php b/classes/PluginVersion.php index 40a011d..544be91 100644 --- a/classes/PluginVersion.php +++ b/classes/PluginVersion.php @@ -20,7 +20,7 @@ public function getPluginVersionInformation($pluginCodeObj) $filePath = $this->getPluginUpdatesPath($pluginCodeObj, 'version.yaml'); if (!File::isFile($filePath)) { - throw new SystemException('Plugin version.yaml file is not found.'); + throw new SystemException(Lang::get('winter.builder::lang.version.error_plugin_version_yaml_file_is_not_found')); } $versionInfo = Yaml::parseFile($filePath); diff --git a/classes/YamlModel.php b/classes/YamlModel.php index 79d9023..3d95cda 100644 --- a/classes/YamlModel.php +++ b/classes/YamlModel.php @@ -102,14 +102,14 @@ protected function load($filePath) $filePath = File::symbolizePath($filePath); if (!File::isFile($filePath)) { - throw new ApplicationException('Cannot load the model - the original file is not found: '.basename($filePath)); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_load_model_file_is_not_found', ['path'=>basename($filePath)])); } try { $data = Yaml::parse(File::get($filePath)); } catch (Exception $ex) { - throw new ApplicationException(sprintf('Cannot parse the YAML file %s: %s', basename($filePath), $ex->getMessage())); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_parse_yaml_file', ['path'=>basename($filePath), 'message'=>$ex->getMessage()])); } $this->originalFilePath = $filePath; @@ -134,11 +134,11 @@ protected function load($filePath) public function deleteModel() { if (!File::isFile($this->originalFilePath)) { - throw new ApplicationException('Cannot load the model - the original file is not found: '.$filePath); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_load_model_file_is_not_found', ['path'=>$filePath])); } if (strtolower(substr($this->originalFilePath, -5)) !== '.yaml') { - throw new ApplicationException('Cannot delete the model - the original file should be a YAML document'); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_delete_model_file_should_be_yaml')); } File::delete($this->originalFilePath); diff --git a/lang/en/lang.php b/lang/en/lang.php index f382037..d83a30a 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -33,6 +33,9 @@ 'replaces_prompt' => 'Add a plugin', 'replaces_plugin_code' => 'Plugin code', 'replaces_plugin_constraint' => 'Version constraint', + 'error_invalid_plugin_code' => 'Invalid plugin code: :code', + 'error_invalid_plugin_namespace' => 'Invalid plugin namespace value.', + 'error_active_plugin_is_not_set' => 'The active plugin is not set in the :class object.', ], 'author_name' => [ 'title' => 'Author name', @@ -87,7 +90,9 @@ 'error_unsigned_negative_value' => "The default value for the unsigned column ':column' can't be negative.", 'error_table_already_exists' => "The table ':name' already exists in the database.", 'error_table_name_too_long' => "The table name should not be longer than 64 characters.", - 'error_column_name_too_long' => "The column name ':column' is too long. Column names should not be longer than 64 characters." + 'error_column_name_too_long' => "The column name ':column' is too long. Column names should not be longer than 64 characters.", + 'error_table_with_name_doesnt_exist' => "The table with name :name doesn't exist", + 'error_saving_table_model_plugin_database_prefix_is_not_set_for_object' => 'Error saving the table model - the plugin database prefix is not set for the object.', ], 'model' => [ 'menu_label' => 'Models', @@ -108,6 +113,8 @@ 'error_deleted_at_column_must_exist' => 'The database table must have deleted_at column.', 'add_form' => 'Add form', 'add_list' => 'Add list', + 'error_invalid_model_class_name' => 'Invalid model class name: :class', + 'error_db_table_not_found' => 'Database table not found: :table', ], 'form' => [ 'saved' => 'Form saved', @@ -394,6 +401,8 @@ 'tab_css_class_description' => 'Assigns a CSS class to the tabs container.', 'tab_name_template' => 'Tab %s', 'tab_already_exists' => 'Tab with the specified title already exists.', + 'error_cannot_decode_controls_json_string' => 'Cannot decode controls JSON string.', + 'validation_create_at_least_one_field' => 'Please create at least one field.', ], 'list' => [ 'tab_new_list' => 'New list', @@ -432,7 +441,10 @@ 'column_label_value_from' => 'Value from', 'error_duplicate_column' => "Duplicate column field name: ':column'.", 'btn_add_database_columns' => 'Add database columns', - 'all_database_columns_exist' => 'All database columns are already defined in the list' + 'all_database_columns_exist' => 'All database columns are already defined in the list', + 'error_cannot_decode_columns_json_string' => 'Cannot decode columns JSON string.', + 'validation_columns_create_at_least_one_column' => 'Please create at least one column.', + 'error_name_should_not_be_empty' => 'Cannot save the list - the column field name should not be empty.', ], 'controller' => [ 'menu_label' => 'Controllers', @@ -555,6 +567,8 @@ 'error_behavior_requires_base_model' => 'Behavior :behavior requires a base model class to be selected.', 'error_model_doesnt_have_lists' => 'The selected model doesn\'t have any lists. Please create a list first.', 'error_model_doesnt_have_forms' => 'The selected model doesn\'t have any forms. Please create a form first.', + 'error_invalid_controller_file_name' => 'Invalid controller file name: :language', + 'error_behaviors_data_should_be_an_array' => 'The behaviors data should be an array.', ], 'version' => [ 'menu_label' => 'Versions', @@ -580,6 +594,7 @@ 'save_unapplied_version' => 'Save unapplied version', 'sort_ascending' => 'Sort ascending', 'sort_descending' => 'Sort descending', + 'error_plugin_version_yaml_file_is_not_found' => 'Plugin version.yaml file is not found.', ], 'menu' => [ 'menu_label' => 'Backend Menu', @@ -606,6 +621,10 @@ 'property_code_required' => 'Please enter the menu item code.', 'error_duplicate_main_menu_code' => "Duplicate main menu item code: ':code'.", 'error_duplicate_side_menu_code' => "Duplicate side menu item code: ':code'.", + 'error_main_menu_item_code_should_not_be_empty' => 'Cannot save menus - the main menu item code should not be empty.', + 'error_side_menu_item_code_should_not_be_empty' => 'Cannot save menus - the side menu item code should not be empty.', + 'error_cannot_decode_menus_json_string' => 'Cannot decode menus JSON string.', + 'error_plugin_code_object_is_not_set' => 'Error saving plugin menus model - the plugin code object is not set.', ], 'localization' => [ 'menu_label' => 'Localization', @@ -634,6 +653,11 @@ 'string_key_is_a_string' => ':key is a string and cannot contain other strings.', 'string_value_is_empty' => 'String value should not be empty', 'string_key_exists' => 'The string key already exists', + 'error_cannot_delete_lang_file_which_is_not_saved' => 'Cannot delete language file which is not saved yet.', + 'error_default_language_is_not_defined' => 'The default language is not defined in the application configuration (app.locale).', + 'error_form_language_is_not_set' => 'The form model language is not set.', + 'error_invalid_language_file_name' => 'Invalid language file name :lang', + 'error_cannot_parse_yaml' => 'Cannot parse the YAML content: :message', ], 'permission' => [ 'menu_label' => 'Permissions', @@ -649,9 +673,17 @@ 'column_label_required' => 'Please enter the permission label', 'saved' => 'Permissions saved', 'error_duplicate_code' => "Duplicate permission code: ':code'.", + 'error_save_permissions_code_should_not_be_empty' => 'Cannot save permissions - the permission code should not be empty.', + 'error_saving_permission_code_is_not_set' => 'Error saving plugin permission model - the plugin code object is not set.', ], 'yaml' => [ 'save_error' => "Error saving file ':name'. Please check write permissions.", + 'error_model_class_name_is_not_set' => 'The model class name is not set.', + 'error_form_model_file_name_is_not_set' => 'The form model file name is not set.', + 'error_cannot_load_model_file_is_not_found' => 'Cannot load the model - the original file is not found: :path', + 'error_cannot_parse_yaml_file' => 'Cannot parse the YAML file :path: :message', + 'error_cannot_load_model_file_is_not_found' => 'Cannot load the model - the original file is not found: :path', + 'error_cannot_delete_model_file_should_be_yaml' => 'Cannot delete the model - the original file should be a YAML document', ], 'common' => [ 'error_file_exists' => "File already exists: ':path'.", @@ -682,6 +714,15 @@ 'error_namespace_mismatch' => "The migration code should use the plugin namespace: :namespace", 'error_migration_file_exists' => "Migration file :file already exists. Please use another class name.", 'error_cant_delete_applied' => 'This version has already been applied and cannot be deleted. Please rollback the version first.', + 'error_cannot_parse_latest_plugin_version' => 'Cannot parse the latest plugin version number: :version.', + 'error_cannot_load_version_model_should_not_be_empty' => 'Cannot load the version model - the version number should not be empty.', + 'error_requested_version_does_not_exist' => 'The requested version does not exist in the version information file.', + 'error_requested_version_cannot_be_edited' => 'The requested version cannot be edited with Builder as it refers to multiple PHP scripts.', + 'error_unknown_version_type' => 'Unknown version type.', + 'error_saving_file' => 'Error saving file :path', + 'error_version_file_is_not_found' => 'Version file :path is not found', + 'error_loading_file' => 'Error loading file :path', + 'error_unknown_column_type' => 'Unknown column type :type', ], 'components' => [ 'list_title' => 'Record list', @@ -733,11 +774,21 @@ 'details_not_found_message' => 'Not found message', 'details_not_found_message_description' => 'Message to display if the record is not found. Used in the default component\'s partial.', 'details_not_found_message_default' => 'Record not found', + 'error_invalid_model_class_name' => 'Invalid model class name.', + 'error_model_class_name_should_be_a_string' => 'Model class name should be a string.', ], 'validation' => [ - 'reserved' => ':attribute cannot be a PHP reserved keyword' + 'reserved' => ':attribute cannot be a PHP reserved keyword', + ], + 'behavior' => [ + 'error_base_form_configuration_file_is_not_specified' => 'Base form configuration file is not specified for :class behavior', + 'error_cannot_determine_currently_active_plugin' => 'Cannot determine the currently active plugin.', + ], + 'stream' => [ + 'error_cant_restore_token_stream_bookmark' => "Can't restore PHP token stream bookmark - the bookmark doesn't exist", + 'error_cant_discard_token_stream_bookmark' => "Can't discard PHP token stream bookmark - the bookmark doesn't exist", ], 'settings' => [ - 'menu_desc' => 'Set your author name and namespace for plugin creation.' + 'menu_desc' => 'Set your author name and namespace for plugin creation.', ], ]; From 1a6f205e25c9ded0d2584bf3e492301ae19f3e28 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Sat, 15 Jan 2022 12:39:38 -0600 Subject: [PATCH 2/4] Apply suggestions from code review --- classes/BaseModel.php | 2 +- classes/ControllerModel.php | 2 +- classes/DatabaseTableModel.php | 2 +- classes/IndexOperationsBehaviorBase.php | 2 +- classes/LanguageMixer.php | 2 +- classes/LocalizationModel.php | 4 ++-- classes/MigrationColumnType.php | 4 ++-- classes/MigrationModel.php | 12 ++++++------ classes/ModelModel.php | 4 ++-- classes/PluginCode.php | 4 ++-- classes/YamlModel.php | 6 +++--- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/classes/BaseModel.php b/classes/BaseModel.php index 7385167..5cfbf41 100644 --- a/classes/BaseModel.php +++ b/classes/BaseModel.php @@ -123,7 +123,7 @@ public function getModelPluginName() public function getPluginCodeObj() { if (!$this->pluginCodeObj) { - throw new SystemException(Lang::get('winter.builder::lang.plugin.error_active_plugin_is_not_set', ['class'=>get_class($this)])); + throw new SystemException(Lang::get('winter.builder::lang.plugin.error_active_plugin_is_not_set', ['class' => get_class($this)])); } return $this->pluginCodeObj; diff --git a/classes/ControllerModel.php b/classes/ControllerModel.php index 9ad2b48..2837ab0 100644 --- a/classes/ControllerModel.php +++ b/classes/ControllerModel.php @@ -42,7 +42,7 @@ class ControllerModel extends BaseModel public function load($controller) { if (!$this->validateFileName($controller)) { - throw new SystemException(Lang::get('winter.builder::lang.controller.error_invalid_controller_file_name', ['language'=>$language])); + throw new SystemException(Lang::get('winter.builder::lang.controller.error_invalid_controller_file_name', ['language' => $language])); } $this->controller = $this->trimExtension($controller); diff --git a/classes/DatabaseTableModel.php b/classes/DatabaseTableModel.php index c7e6194..10b640e 100644 --- a/classes/DatabaseTableModel.php +++ b/classes/DatabaseTableModel.php @@ -74,7 +74,7 @@ public static function tableExists($name) public function load($name) { if (!self::tableExists($name)) { - throw new SystemException(Lang::get('winter.builder::lang.database.error_table_with_name_doesnt_exist', ['name'=>$name])); + throw new SystemException(Lang::get('winter.builder::lang.database.error_table_with_name_doesnt_exist', ['name' => $name])); } $schema = self::getSchemaManager()->createSchema(); diff --git a/classes/IndexOperationsBehaviorBase.php b/classes/IndexOperationsBehaviorBase.php index dbfd571..f13c469 100644 --- a/classes/IndexOperationsBehaviorBase.php +++ b/classes/IndexOperationsBehaviorBase.php @@ -17,7 +17,7 @@ abstract class IndexOperationsBehaviorBase extends ControllerBehavior protected function makeBaseFormWidget($modelCode, $options = [], $aliasSuffix = null) { if (!strlen($this->baseFormConfigFile)) { - throw new ApplicationException(Lang::get('winter.builder::lang.behavior.error_base_form_configuration_file_is_not_specified', ['class'=>get_class($this)])); + throw new ApplicationException(Lang::get('winter.builder::lang.behavior.error_base_form_configuration_file_is_not_specified', ['class' => get_class($this)])); } $widgetConfig = $this->makeConfig($this->baseFormConfigFile); diff --git a/classes/LanguageMixer.php b/classes/LanguageMixer.php index f7562cb..5427e57 100644 --- a/classes/LanguageMixer.php +++ b/classes/LanguageMixer.php @@ -28,7 +28,7 @@ public function addStringsFromAnotherLanguage($destContents, $srcArray) $destArray = Yaml::parse($destContents); } catch (Exception $ex) { - throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_parse_yaml', ['message'=>$ex->getMessage()])); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_parse_yaml', ['message' => $ex->getMessage()])); } if (!$destArray) { diff --git a/classes/LocalizationModel.php b/classes/LocalizationModel.php index 9b49ed8..f2e48a0 100644 --- a/classes/LocalizationModel.php +++ b/classes/LocalizationModel.php @@ -333,7 +333,7 @@ protected function getFilePath($language = null) } if (!$this->validateLanguage($language)) { - throw new SystemException(Lang::get('winter.builder::lang.localization.error_invalid_language_file_name'), ['lang'=>$language]); + throw new SystemException(Lang::get('winter.builder::lang.localization.error_invalid_language_file_name'), ['lang' => $language]); } $path = $this->getPluginCodeObj()->toPluginDirectoryPath().'/lang/'.$language.'/lang.php'; @@ -364,7 +364,7 @@ protected function modelToLanguageFile() return "$ex->getMessage()]); + throw new ApplicationException(Lang::get('winter.builder::lang.localization.error_cannot_parse_yaml'), ['message' => $ex->getMessage()]); } } diff --git a/classes/MigrationColumnType.php b/classes/MigrationColumnType.php index fe8b3c0..5849cda 100644 --- a/classes/MigrationColumnType.php +++ b/classes/MigrationColumnType.php @@ -90,7 +90,7 @@ public static function toDoctrineTypeName($type) $typeMap = self::getDoctrineTypeMap(); if (!array_key_exists($type, $typeMap)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_column_type', ['type'=>$type])); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_column_type', ['type' => $type])); } return $typeMap[$type]; @@ -104,7 +104,7 @@ public static function toMigrationMethodName($type, $columnName) $typeMap = self::getDoctrineTypeMap(); if (!in_array($type, $typeMap)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_column_type', ['type'=>$type])); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_column_type', ['type' => $type])); } // Some Doctrine types map to multiple migration types, for example diff --git a/classes/MigrationModel.php b/classes/MigrationModel.php index d880a70..9464a94 100644 --- a/classes/MigrationModel.php +++ b/classes/MigrationModel.php @@ -100,7 +100,7 @@ public function getNextVersion() $versionNumbers = []; if (!preg_match('/^([0-9]+)\.([0-9]+)\.([0-9]+)$/', $latestVersion, $versionNumbers)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_cannot_parse_latest_plugin_version', ['version'=>$latestVersion])); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_cannot_parse_latest_plugin_version', ['version' => $latestVersion])); } return $versionNumbers[1].'.'.$versionNumbers[2].'.'.($versionNumbers[3]+1); @@ -340,7 +340,7 @@ protected function saveScriptFile() $scriptFilePath = $this->getPluginUpdatesPath($this->scriptFileName.'.php'); if (!File::put($scriptFilePath, $this->code)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path'=>$scriptFilePath])); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path' => $scriptFilePath])); } @File::chmod($scriptFilePath); @@ -373,7 +373,7 @@ protected function loadScriptFile() $scriptFilePath = $this->getPluginUpdatesPath($this->scriptFileName.'.php'); if (!File::isFile($scriptFilePath)) { - throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_version_file_is_not_found', ['path'=>$scriptFilePath])); + throw new ApplicationException(Lang::get('winter.builder::lang.migration.error_version_file_is_not_found', ['path' => $scriptFilePath])); } return File::get($scriptFilePath); @@ -424,7 +424,7 @@ protected function insertOrUpdateVersion() $originalFileContents = File::get($versionFilePath); if (!$originalFileContents) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_loading_file', ['path'=>$scriptFilePath])); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_loading_file', ['path' => $scriptFilePath])); } $versionInformation[$this->version] = [ @@ -444,7 +444,7 @@ protected function insertOrUpdateVersion() $yamlData = Yaml::render($versionInformation); if (!File::put($versionFilePath, $yamlData)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path'=>$scriptFilePath])); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path' => $scriptFilePath])); } @File::chmod($versionFilePath); @@ -467,7 +467,7 @@ protected function deleteVersion() $yamlData = Yaml::render($versionInformation); if (!File::put($versionFilePath, $yamlData)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path'=>$scriptFilePath])); + throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path' => $scriptFilePath])); } @File::chmod($versionFilePath); diff --git a/classes/ModelModel.php b/classes/ModelModel.php index e2fa4ec..1f5b8d4 100644 --- a/classes/ModelModel.php +++ b/classes/ModelModel.php @@ -161,7 +161,7 @@ public function getDatabaseTableOptions() private static function getTableNameFromModelClass($pluginCodeObj, $modelClassName) { if (!self::validateModelClassName($modelClassName)) { - throw new SystemException(Lang::get('winter.builder::lang.model.error_invalid_model_class_name', ['class'=>$modelClassName])); + throw new SystemException(Lang::get('winter.builder::lang.model.error_invalid_model_class_name', ['class' => $modelClassName])); } $modelsDirectoryPath = File::symbolizePath($pluginCodeObj->toPluginDirectoryPath().'/models'); @@ -198,7 +198,7 @@ public static function getModelColumnsAndTypes($pluginCodeObj, $modelClassName) $tableName = self::getTableNameFromModelClass($pluginCodeObj, $modelClassName); if (!DatabaseTableModel::tableExists($tableName)) { - throw new ApplicationException(Lang::get('winter.builder::lang.model.error_db_table_not_found', ['table'=>$tableName])); + throw new ApplicationException(Lang::get('winter.builder::lang.model.error_db_table_not_found', ['table' => $tableName])); } $schema = DatabaseTableModel::getSchema(); diff --git a/classes/PluginCode.php b/classes/PluginCode.php index dbbed57..5b0892d 100644 --- a/classes/PluginCode.php +++ b/classes/PluginCode.php @@ -18,13 +18,13 @@ public function __construct($pluginCodeStr) { $codeParts = explode('.', $pluginCodeStr); if (count($codeParts) !== 2) { - throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_code', ['code'=>$pluginCodeStr])); + throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_code', ['code' => $pluginCodeStr])); } list($authorCode, $pluginCode) = $codeParts; if (!$this->validateCodeWord($authorCode) || !$this->validateCodeWord($pluginCode)) { - throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_code', ['code'=>$pluginCodeStr])); + throw new ApplicationException(Lang::get('winter.builder::lang.plugin.error_invalid_plugin_code', ['code' => $pluginCodeStr])); } $this->authorCode = trim($authorCode); diff --git a/classes/YamlModel.php b/classes/YamlModel.php index 3d95cda..d9992df 100644 --- a/classes/YamlModel.php +++ b/classes/YamlModel.php @@ -102,14 +102,14 @@ protected function load($filePath) $filePath = File::symbolizePath($filePath); if (!File::isFile($filePath)) { - throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_load_model_file_is_not_found', ['path'=>basename($filePath)])); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_load_model_file_is_not_found', ['path' => basename($filePath)])); } try { $data = Yaml::parse(File::get($filePath)); } catch (Exception $ex) { - throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_parse_yaml_file', ['path'=>basename($filePath), 'message'=>$ex->getMessage()])); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_parse_yaml_file', ['path' => basename($filePath), 'message' => $ex->getMessage()])); } $this->originalFilePath = $filePath; @@ -134,7 +134,7 @@ protected function load($filePath) public function deleteModel() { if (!File::isFile($this->originalFilePath)) { - throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_load_model_file_is_not_found', ['path'=>$filePath])); + throw new ApplicationException(Lang::get('winter.builder::lang.yaml.error_cannot_load_model_file_is_not_found', ['path' => $filePath])); } if (strtolower(substr($this->originalFilePath, -5)) !== '.yaml') { From 0f73745e9f583b4c15b0d12ad6781e1b18e30789 Mon Sep 17 00:00:00 2001 From: Web-VPF Date: Sat, 15 Jan 2022 21:30:20 +0200 Subject: [PATCH 3/4] Added - use Lang --- classes/BaseModel.php | 1 + classes/ComponentHelper.php | 1 + classes/IndexOperationsBehaviorBase.php | 1 + classes/LanguageMixer.php | 1 + classes/ModelFormModel.php | 1 + classes/PhpSourceStream.php | 1 + classes/PluginCode.php | 1 + classes/PluginVersion.php | 1 + 8 files changed, 8 insertions(+) diff --git a/classes/BaseModel.php b/classes/BaseModel.php index 5cfbf41..ce826c0 100644 --- a/classes/BaseModel.php +++ b/classes/BaseModel.php @@ -3,6 +3,7 @@ use ValidationException; use SystemException; use Validator; +use Lang; /** * Base class for Builder models. diff --git a/classes/ComponentHelper.php b/classes/ComponentHelper.php index 0a0fbbd..a59216c 100644 --- a/classes/ComponentHelper.php +++ b/classes/ComponentHelper.php @@ -5,6 +5,7 @@ use Exception; use Winter\Storm\Support\Traits\Singleton; use ApplicationException; +use Lang; /** * Provides helper methods for Builder CMS components. diff --git a/classes/IndexOperationsBehaviorBase.php b/classes/IndexOperationsBehaviorBase.php index f13c469..f395f4d 100644 --- a/classes/IndexOperationsBehaviorBase.php +++ b/classes/IndexOperationsBehaviorBase.php @@ -3,6 +3,7 @@ use Backend\Classes\ControllerBehavior; use Backend\Behaviors\FormController; use ApplicationException; +use Lang; /** * Base class for index operation behaviors diff --git a/classes/LanguageMixer.php b/classes/LanguageMixer.php index 5427e57..6abd597 100644 --- a/classes/LanguageMixer.php +++ b/classes/LanguageMixer.php @@ -3,6 +3,7 @@ use Yaml; use Symfony\Component\Yaml\Dumper as YamlDumper; use ApplicationException; +use Lang; class LanguageMixer { diff --git a/classes/ModelFormModel.php b/classes/ModelFormModel.php index 5c29682..003e301 100644 --- a/classes/ModelFormModel.php +++ b/classes/ModelFormModel.php @@ -2,6 +2,7 @@ use SystemException; use ValidationException; +use Lang; /** * Represents and manages model forms. diff --git a/classes/PhpSourceStream.php b/classes/PhpSourceStream.php index a858cfd..f7cf74e 100644 --- a/classes/PhpSourceStream.php +++ b/classes/PhpSourceStream.php @@ -1,6 +1,7 @@ Date: Wed, 30 Nov 2022 11:47:33 +0200 Subject: [PATCH 4/4] Cancel translation of system messages --- classes/BaseModel.php | 3 +-- classes/ControllerModel.php | 4 ++-- classes/DatabaseTableModel.php | 4 ++-- classes/LocalizationModel.php | 4 ++-- classes/MenusModel.php | 4 ++-- classes/MigrationColumnType.php | 4 ++-- classes/MigrationModel.php | 12 ++++++------ classes/ModelFormModel.php | 2 +- classes/ModelListModel.php | 2 +- classes/ModelModel.php | 2 +- classes/ModelYamlModel.php | 4 ++-- classes/PermissionsModel.php | 2 +- classes/PhpSourceStream.php | 5 ++--- classes/PluginVersion.php | 3 +-- lang/en/lang.php | 25 ------------------------- 15 files changed, 26 insertions(+), 54 deletions(-) diff --git a/classes/BaseModel.php b/classes/BaseModel.php index ce826c0..138427f 100644 --- a/classes/BaseModel.php +++ b/classes/BaseModel.php @@ -3,7 +3,6 @@ use ValidationException; use SystemException; use Validator; -use Lang; /** * Base class for Builder models. @@ -124,7 +123,7 @@ public function getModelPluginName() public function getPluginCodeObj() { if (!$this->pluginCodeObj) { - throw new SystemException(Lang::get('winter.builder::lang.plugin.error_active_plugin_is_not_set', ['class' => get_class($this)])); + throw new SystemException(sprintf('The active plugin is not set in the %s object.', get_class($this))); } return $this->pluginCodeObj; diff --git a/classes/ControllerModel.php b/classes/ControllerModel.php index 2837ab0..f3b6c4f 100644 --- a/classes/ControllerModel.php +++ b/classes/ControllerModel.php @@ -42,7 +42,7 @@ class ControllerModel extends BaseModel public function load($controller) { if (!$this->validateFileName($controller)) { - throw new SystemException(Lang::get('winter.builder::lang.controller.error_invalid_controller_file_name', ['language' => $language])); + throw new SystemException('Invalid controller file name: '.$language); } $this->controller = $this->trimExtension($controller); @@ -221,7 +221,7 @@ protected function saveController() } if (!is_array($this->behaviors)) { - throw new SystemException(Lang::get('winter.builder::lang.controller.error_behaviors_data_should_be_an_array')); + throw new SystemException('The behaviors data should be an array.'); } $fileContents = File::get($controllerPath); diff --git a/classes/DatabaseTableModel.php b/classes/DatabaseTableModel.php index 10b640e..967df11 100644 --- a/classes/DatabaseTableModel.php +++ b/classes/DatabaseTableModel.php @@ -74,7 +74,7 @@ public static function tableExists($name) public function load($name) { if (!self::tableExists($name)) { - throw new SystemException(Lang::get('winter.builder::lang.database.error_table_with_name_doesnt_exist', ['name' => $name])); + throw new SystemException(sprintf('The table with name %s doesn\'t exist', $name)); } $schema = self::getSchemaManager()->createSchema(); @@ -90,7 +90,7 @@ public function validate() $pluginDbPrefix = $this->getPluginCodeObj()->toDatabasePrefix(); if (!strlen($pluginDbPrefix)) { - throw new SystemException(Lang::get('winter.builder::lang.database.error_saving_table_model_plugin_database_prefix_is_not_set_for_object')); + throw new SystemException('Error saving the table model - the plugin database prefix is not set for the object.'); } $prefix = $pluginDbPrefix.'_'; diff --git a/classes/LocalizationModel.php b/classes/LocalizationModel.php index f2e48a0..042e2d4 100644 --- a/classes/LocalizationModel.php +++ b/classes/LocalizationModel.php @@ -329,11 +329,11 @@ protected function getFilePath($language = null) $language = trim($language); if (!strlen($language)) { - throw new SystemException(Lang::get('winter.builder::lang.localization.error_form_language_is_not_set')); + throw new SystemException('The form model language is not set.'); } if (!$this->validateLanguage($language)) { - throw new SystemException(Lang::get('winter.builder::lang.localization.error_invalid_language_file_name'), ['lang' => $language]); + throw new SystemException('Invalid language file name: ' . $language); } $path = $this->getPluginCodeObj()->toPluginDirectoryPath().'/lang/'.$language.'/lang.php'; diff --git a/classes/MenusModel.php b/classes/MenusModel.php index cdb17a5..042d031 100644 --- a/classes/MenusModel.php +++ b/classes/MenusModel.php @@ -79,7 +79,7 @@ public function fill(array $attributes) $attributes['menus'] = json_decode($attributes['menus'], true); if ($attributes['menus'] === null) { - throw new SystemException(Lang::get('winter.builder::lang.menu.error_cannot_decode_menus_json_string')); + throw new SystemException('Cannot decode menus JSON string.'); } } @@ -141,7 +141,7 @@ protected function trimMenuProperties($menu) protected function getFilePath() { if ($this->pluginCodeObj === null) { - throw new SystemException(Lang::get('winter.builder::lang.menu.error_plugin_code_object_is_not_set')); + throw new SystemException('Error saving plugin menus model - the plugin code object is not set.'); } return $this->pluginCodeObj->toPluginFilePath(); diff --git a/classes/MigrationColumnType.php b/classes/MigrationColumnType.php index 5849cda..d3dc52e 100644 --- a/classes/MigrationColumnType.php +++ b/classes/MigrationColumnType.php @@ -90,7 +90,7 @@ public static function toDoctrineTypeName($type) $typeMap = self::getDoctrineTypeMap(); if (!array_key_exists($type, $typeMap)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_column_type', ['type' => $type])); + throw new SystemException(sprintf('Unknown column type: %s', $type)); } return $typeMap[$type]; @@ -104,7 +104,7 @@ public static function toMigrationMethodName($type, $columnName) $typeMap = self::getDoctrineTypeMap(); if (!in_array($type, $typeMap)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_column_type', ['type' => $type])); + throw new SystemException(sprintf('Unknown column type: %s', $type)); } // Some Doctrine types map to multiple migration types, for example diff --git a/classes/MigrationModel.php b/classes/MigrationModel.php index 9464a94..4ab5d35 100644 --- a/classes/MigrationModel.php +++ b/classes/MigrationModel.php @@ -100,7 +100,7 @@ public function getNextVersion() $versionNumbers = []; if (!preg_match('/^([0-9]+)\.([0-9]+)\.([0-9]+)$/', $latestVersion, $versionNumbers)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_cannot_parse_latest_plugin_version', ['version' => $latestVersion])); + throw new SystemException(sprintf('Cannot parse the latest plugin version number: %s.', $latestVersion)); } return $versionNumbers[1].'.'.$versionNumbers[2].'.'.($versionNumbers[3]+1); @@ -192,7 +192,7 @@ public function initVersion($versionType) $versionTypes = ['migration', 'seeder', 'custom']; if (!in_array($versionType, $versionTypes)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_unknown_version_type')); + throw new SystemException('Unknown version type.'); } $this->version = $this->getNextVersion(); @@ -340,7 +340,7 @@ protected function saveScriptFile() $scriptFilePath = $this->getPluginUpdatesPath($this->scriptFileName.'.php'); if (!File::put($scriptFilePath, $this->code)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path' => $scriptFilePath])); + throw new SystemException(sprintf('Error saving file %s', $scriptFilePath)); } @File::chmod($scriptFilePath); @@ -424,7 +424,7 @@ protected function insertOrUpdateVersion() $originalFileContents = File::get($versionFilePath); if (!$originalFileContents) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_loading_file', ['path' => $scriptFilePath])); + throw new SystemException(sprintf('Error loading file %s', $versionFilePath)); } $versionInformation[$this->version] = [ @@ -444,7 +444,7 @@ protected function insertOrUpdateVersion() $yamlData = Yaml::render($versionInformation); if (!File::put($versionFilePath, $yamlData)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path' => $scriptFilePath])); + throw new SystemException(sprintf('Error saving file %s', $versionFilePath)); } @File::chmod($versionFilePath); @@ -467,7 +467,7 @@ protected function deleteVersion() $yamlData = Yaml::render($versionInformation); if (!File::put($versionFilePath, $yamlData)) { - throw new SystemException(Lang::get('winter.builder::lang.migration.error_saving_file', ['path' => $scriptFilePath])); + throw new SystemException(sprintf('Error saving file %s', $versionFilePath)); } @File::chmod($versionFilePath); diff --git a/classes/ModelFormModel.php b/classes/ModelFormModel.php index 003e301..985a018 100644 --- a/classes/ModelFormModel.php +++ b/classes/ModelFormModel.php @@ -36,7 +36,7 @@ public function fill(array $attributes) $attributes['controls'] = json_decode($attributes['controls'], true); if ($attributes['controls'] === null) { - throw new SystemException(Lang::get('winter.builder::lang.form.error_cannot_decode_controls_json_string')); + throw new SystemException('Cannot decode controls JSON string.'); } } diff --git a/classes/ModelListModel.php b/classes/ModelListModel.php index 672341d..89f86d1 100644 --- a/classes/ModelListModel.php +++ b/classes/ModelListModel.php @@ -37,7 +37,7 @@ public function fill(array $attributes) $attributes['columns'] = json_decode($attributes['columns'], true); if ($attributes['columns'] === null) { - throw new SystemException(Lang::get('winter.builder::lang.list.error_cannot_decode_columns_json_string')); + throw new SystemException('Cannot decode columns JSON string.')); } } diff --git a/classes/ModelModel.php b/classes/ModelModel.php index 1f5b8d4..9e5af77 100644 --- a/classes/ModelModel.php +++ b/classes/ModelModel.php @@ -161,7 +161,7 @@ public function getDatabaseTableOptions() private static function getTableNameFromModelClass($pluginCodeObj, $modelClassName) { if (!self::validateModelClassName($modelClassName)) { - throw new SystemException(Lang::get('winter.builder::lang.model.error_invalid_model_class_name', ['class' => $modelClassName])); + throw new SystemException('Invalid model class name: '.$modelClassName); } $modelsDirectoryPath = File::symbolizePath($pluginCodeObj->toPluginDirectoryPath().'/models'); diff --git a/classes/ModelYamlModel.php b/classes/ModelYamlModel.php index 8efe874..0b85336 100644 --- a/classes/ModelYamlModel.php +++ b/classes/ModelYamlModel.php @@ -169,7 +169,7 @@ protected static function validateModelClassName($modelClassName) protected function getModelClassName() { if ($this->modelClassName === null) { - throw new SystemException(Lang::get('winter.builder::lang.yaml.error_model_class_name_is_not_set')); + throw new SystemException('The model class name is not set.'); } return $this->modelClassName; @@ -184,7 +184,7 @@ protected function getFilePath() { $fileName = trim($this->fileName); if (!strlen($fileName)) { - throw new SystemException(Lang::get('winter.builder::lang.yaml.error_form_model_file_name_is_not_set')); + throw new SystemException('The form model file name is not set.'); } $fileName = $this->addExtension($fileName); diff --git a/classes/PermissionsModel.php b/classes/PermissionsModel.php index f204e79..0e48f94 100644 --- a/classes/PermissionsModel.php +++ b/classes/PermissionsModel.php @@ -188,7 +188,7 @@ protected function yamlArrayToModel($array) protected function getFilePath() { if ($this->pluginCodeObj === null) { - throw new SystemException(Lang::get('winter.builder::lang.permission.error_saving_permission_code_is_not_set')); + throw new SystemException('Error saving plugin permission model - the plugin code object is not set.'); } return $this->pluginCodeObj->toPluginFilePath(); diff --git a/classes/PhpSourceStream.php b/classes/PhpSourceStream.php index f7cf74e..10291c0 100644 --- a/classes/PhpSourceStream.php +++ b/classes/PhpSourceStream.php @@ -1,7 +1,6 @@ headBookmarks); if ($head === null) { - throw new SystemException(Lang::get('winter.builder::lang.stream.error_cant_restore_token_stream_bookmark')); + throw new SystemException("Can't restore PHP token stream bookmark - the bookmark doesn't exist"); } return $this->setHead($head); @@ -82,7 +81,7 @@ public function discardBookmark() { $head = array_pop($this->headBookmarks); if ($head === null) { - throw new SystemException(Lang::get('winter.builder::lang.stream.error_cant_discard_token_stream_bookmark')); + throw new SystemException("Can't discard PHP token stream bookmark - the bookmark doesn't exist"); } } diff --git a/classes/PluginVersion.php b/classes/PluginVersion.php index 97a04da..40a011d 100644 --- a/classes/PluginVersion.php +++ b/classes/PluginVersion.php @@ -3,7 +3,6 @@ use SystemException; use File; use Yaml; -use Lang; /** * Helper class for managing plugin versions @@ -21,7 +20,7 @@ public function getPluginVersionInformation($pluginCodeObj) $filePath = $this->getPluginUpdatesPath($pluginCodeObj, 'version.yaml'); if (!File::isFile($filePath)) { - throw new SystemException(Lang::get('winter.builder::lang.version.error_plugin_version_yaml_file_is_not_found')); + throw new SystemException('Plugin version.yaml file is not found.'); } $versionInfo = Yaml::parseFile($filePath); diff --git a/lang/en/lang.php b/lang/en/lang.php index d83a30a..f80143a 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -35,7 +35,6 @@ 'replaces_plugin_constraint' => 'Version constraint', 'error_invalid_plugin_code' => 'Invalid plugin code: :code', 'error_invalid_plugin_namespace' => 'Invalid plugin namespace value.', - 'error_active_plugin_is_not_set' => 'The active plugin is not set in the :class object.', ], 'author_name' => [ 'title' => 'Author name', @@ -91,8 +90,6 @@ 'error_table_already_exists' => "The table ':name' already exists in the database.", 'error_table_name_too_long' => "The table name should not be longer than 64 characters.", 'error_column_name_too_long' => "The column name ':column' is too long. Column names should not be longer than 64 characters.", - 'error_table_with_name_doesnt_exist' => "The table with name :name doesn't exist", - 'error_saving_table_model_plugin_database_prefix_is_not_set_for_object' => 'Error saving the table model - the plugin database prefix is not set for the object.', ], 'model' => [ 'menu_label' => 'Models', @@ -113,7 +110,6 @@ 'error_deleted_at_column_must_exist' => 'The database table must have deleted_at column.', 'add_form' => 'Add form', 'add_list' => 'Add list', - 'error_invalid_model_class_name' => 'Invalid model class name: :class', 'error_db_table_not_found' => 'Database table not found: :table', ], 'form' => [ @@ -401,7 +397,6 @@ 'tab_css_class_description' => 'Assigns a CSS class to the tabs container.', 'tab_name_template' => 'Tab %s', 'tab_already_exists' => 'Tab with the specified title already exists.', - 'error_cannot_decode_controls_json_string' => 'Cannot decode controls JSON string.', 'validation_create_at_least_one_field' => 'Please create at least one field.', ], 'list' => [ @@ -442,7 +437,6 @@ 'error_duplicate_column' => "Duplicate column field name: ':column'.", 'btn_add_database_columns' => 'Add database columns', 'all_database_columns_exist' => 'All database columns are already defined in the list', - 'error_cannot_decode_columns_json_string' => 'Cannot decode columns JSON string.', 'validation_columns_create_at_least_one_column' => 'Please create at least one column.', 'error_name_should_not_be_empty' => 'Cannot save the list - the column field name should not be empty.', ], @@ -567,8 +561,6 @@ 'error_behavior_requires_base_model' => 'Behavior :behavior requires a base model class to be selected.', 'error_model_doesnt_have_lists' => 'The selected model doesn\'t have any lists. Please create a list first.', 'error_model_doesnt_have_forms' => 'The selected model doesn\'t have any forms. Please create a form first.', - 'error_invalid_controller_file_name' => 'Invalid controller file name: :language', - 'error_behaviors_data_should_be_an_array' => 'The behaviors data should be an array.', ], 'version' => [ 'menu_label' => 'Versions', @@ -594,7 +586,6 @@ 'save_unapplied_version' => 'Save unapplied version', 'sort_ascending' => 'Sort ascending', 'sort_descending' => 'Sort descending', - 'error_plugin_version_yaml_file_is_not_found' => 'Plugin version.yaml file is not found.', ], 'menu' => [ 'menu_label' => 'Backend Menu', @@ -623,8 +614,6 @@ 'error_duplicate_side_menu_code' => "Duplicate side menu item code: ':code'.", 'error_main_menu_item_code_should_not_be_empty' => 'Cannot save menus - the main menu item code should not be empty.', 'error_side_menu_item_code_should_not_be_empty' => 'Cannot save menus - the side menu item code should not be empty.', - 'error_cannot_decode_menus_json_string' => 'Cannot decode menus JSON string.', - 'error_plugin_code_object_is_not_set' => 'Error saving plugin menus model - the plugin code object is not set.', ], 'localization' => [ 'menu_label' => 'Localization', @@ -655,8 +644,6 @@ 'string_key_exists' => 'The string key already exists', 'error_cannot_delete_lang_file_which_is_not_saved' => 'Cannot delete language file which is not saved yet.', 'error_default_language_is_not_defined' => 'The default language is not defined in the application configuration (app.locale).', - 'error_form_language_is_not_set' => 'The form model language is not set.', - 'error_invalid_language_file_name' => 'Invalid language file name :lang', 'error_cannot_parse_yaml' => 'Cannot parse the YAML content: :message', ], 'permission' => [ @@ -674,12 +661,9 @@ 'saved' => 'Permissions saved', 'error_duplicate_code' => "Duplicate permission code: ':code'.", 'error_save_permissions_code_should_not_be_empty' => 'Cannot save permissions - the permission code should not be empty.', - 'error_saving_permission_code_is_not_set' => 'Error saving plugin permission model - the plugin code object is not set.', ], 'yaml' => [ 'save_error' => "Error saving file ':name'. Please check write permissions.", - 'error_model_class_name_is_not_set' => 'The model class name is not set.', - 'error_form_model_file_name_is_not_set' => 'The form model file name is not set.', 'error_cannot_load_model_file_is_not_found' => 'Cannot load the model - the original file is not found: :path', 'error_cannot_parse_yaml_file' => 'Cannot parse the YAML file :path: :message', 'error_cannot_load_model_file_is_not_found' => 'Cannot load the model - the original file is not found: :path', @@ -714,15 +698,10 @@ 'error_namespace_mismatch' => "The migration code should use the plugin namespace: :namespace", 'error_migration_file_exists' => "Migration file :file already exists. Please use another class name.", 'error_cant_delete_applied' => 'This version has already been applied and cannot be deleted. Please rollback the version first.', - 'error_cannot_parse_latest_plugin_version' => 'Cannot parse the latest plugin version number: :version.', 'error_cannot_load_version_model_should_not_be_empty' => 'Cannot load the version model - the version number should not be empty.', 'error_requested_version_does_not_exist' => 'The requested version does not exist in the version information file.', 'error_requested_version_cannot_be_edited' => 'The requested version cannot be edited with Builder as it refers to multiple PHP scripts.', - 'error_unknown_version_type' => 'Unknown version type.', - 'error_saving_file' => 'Error saving file :path', 'error_version_file_is_not_found' => 'Version file :path is not found', - 'error_loading_file' => 'Error loading file :path', - 'error_unknown_column_type' => 'Unknown column type :type', ], 'components' => [ 'list_title' => 'Record list', @@ -784,10 +763,6 @@ 'error_base_form_configuration_file_is_not_specified' => 'Base form configuration file is not specified for :class behavior', 'error_cannot_determine_currently_active_plugin' => 'Cannot determine the currently active plugin.', ], - 'stream' => [ - 'error_cant_restore_token_stream_bookmark' => "Can't restore PHP token stream bookmark - the bookmark doesn't exist", - 'error_cant_discard_token_stream_bookmark' => "Can't discard PHP token stream bookmark - the bookmark doesn't exist", - ], 'settings' => [ 'menu_desc' => 'Set your author name and namespace for plugin creation.', ],