Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions classes/ComponentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Winter\Storm\Support\Traits\Singleton;
use ApplicationException;
use Lang;

/**
* Provides helper methods for Builder CMS components.
Expand Down Expand Up @@ -64,7 +65,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)) {
Expand All @@ -73,7 +74,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;
Expand Down
5 changes: 3 additions & 2 deletions classes/IndexOperationsBehaviorBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Backend\Classes\ControllerBehavior;
use Backend\Behaviors\FormController;
use ApplicationException;
use Lang;

/**
* Base class for index operation behaviors
Expand All @@ -17,7 +18,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);
Expand All @@ -36,7 +37,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;
Expand Down
3 changes: 2 additions & 1 deletion classes/LanguageMixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Yaml;
use Symfony\Component\Yaml\Dumper as YamlDumper;
use ApplicationException;
use Lang;

class LanguageMixer
{
Expand All @@ -28,7 +29,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) {
Expand Down
8 changes: 4 additions & 4 deletions classes/LocalizationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -333,7 +333,7 @@ protected function getFilePath($language = null)
}

if (!$this->validateLanguage($language)) {
throw new SystemException('Invalid language file name: '.$language);
throw new SystemException('Invalid language file name: ' . $language);
}

$path = $this->getPluginCodeObj()->toPluginDirectoryPath().'/lang/'.$language.'/lang.php';
Expand Down Expand Up @@ -364,7 +364,7 @@ protected function modelToLanguageFile()
return "<?php return ".$phpData.";";
}
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()]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions classes/MenusModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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'];
Expand Down
8 changes: 4 additions & 4 deletions classes/MigrationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion classes/ModelFormModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use SystemException;
use ValidationException;
use Lang;

/**
* Represents and manages model forms.
Expand Down Expand Up @@ -131,7 +132,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')]);
}
}

Expand Down
6 changes: 3 additions & 3 deletions classes/ModelListModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('Cannot decode columns JSON string.'));
}
}

Expand Down Expand Up @@ -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')]);
}
}

Expand Down Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion classes/ModelModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,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();
Expand Down
2 changes: 1 addition & 1 deletion classes/PermissionsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
7 changes: 4 additions & 3 deletions classes/PluginCode.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Winter\Builder\Classes;

use ApplicationException;
use Lang;

/**
* Represents a plugin code and provides basic code operations.
Expand All @@ -18,13 +19,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);
Expand All @@ -35,7 +36,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];
Expand Down
8 changes: 4 additions & 4 deletions classes/YamlModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
32 changes: 29 additions & 3 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
'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.',
],
'author_name' => [
'title' => 'Author name',
Expand Down Expand Up @@ -110,6 +112,7 @@
'error_deleted_at_column_must_exist' => 'The database table must have deleted_at column.',
'add_form' => 'Add form',
'add_list' => 'Add list',
'error_db_table_not_found' => 'Database table not found: :table',
'delete_model' => 'Delete model :model',
'delete_model_confirm' => 'Are you sure you wish to delete the ":model" model? This will also remove any forms and lists connected to the model.',
'deleted' => 'Model ":model" successfully deleted.',
Expand Down Expand Up @@ -399,6 +402,7 @@
'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.',
'validation_create_at_least_one_field' => 'Please create at least one field.',
],
'list' => [
'tab_new_list' => 'New list',
Expand Down Expand Up @@ -437,7 +441,9 @@
'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',
'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',
Expand Down Expand Up @@ -611,6 +617,8 @@
'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.',
],
'localization' => [
'menu_label' => 'Localization',
Expand Down Expand Up @@ -639,6 +647,9 @@
'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_cannot_parse_yaml' => 'Cannot parse the YAML content: :message',
],
'permission' => [
'menu_label' => 'Permissions',
Expand All @@ -654,9 +665,14 @@
'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.',
],
'yaml' => [
'save_error' => "Error saving file ':name'. Please check write permissions.",
'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'.",
Expand Down Expand Up @@ -687,6 +703,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_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_version_file_is_not_found' => 'Version file :path is not found',
],
'components' => [
'list_title' => 'Record list',
Expand Down Expand Up @@ -738,12 +758,18 @@
'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.',
],
'settings' => [
'menu_desc' => 'Set your author name and namespace for plugin creation.'
'menu_desc' => 'Set your author name and namespace for plugin creation.',
],
'welcome' => [
'heading' => 'Welcome to the Builder.',
Expand Down