From 53355c46c6851e517f79f631051ba47358c12795 Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Tue, 20 Oct 2020 23:56:03 +0530 Subject: [PATCH 1/6] Changed new controller dialog validator --- .../dialog/NewControllerDialog.java | 35 +++-- .../validator/NewControllerValidator.java | 143 ------------------ 2 files changed, 24 insertions(+), 154 deletions(-) delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/NewControllerValidator.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 259e413ff..52d042284 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -10,7 +10,9 @@ import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.actions.generation.NewControllerAction; import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewControllerValidator; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp; @@ -21,7 +23,6 @@ import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -40,7 +41,6 @@ "PMD.ConstructorCallsOverridableMethod" }) public class NewControllerDialog extends AbstractDialog { - private final NewControllerValidator validator; private final String moduleName; private final Project project; private JPanel contentPane; @@ -48,11 +48,28 @@ public class NewControllerDialog extends AbstractDialog { private JButton buttonCancel; private FilteredComboBox controllerAreaSelect; private FilteredComboBox httpMethodSelect; - private JTextField controllerName; private JTextField controllerParentDir; private JCheckBox inheritClass; private JPanel adminPanel; private JTextField acl; + + private static final String CONTROLLER_NAME = "controller name"; + private static final String ACTION_NAME = "action name"; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) + @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, + message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, + message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) + @FieldValidation(rule = RuleRegistry.PHP_CLASS, + message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) + private JTextField controllerName; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, ACTION_NAME}) + @FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME, + message = {NotEmptyRule.MESSAGE, ACTION_NAME}) private JTextField actionName; /** @@ -65,7 +82,6 @@ public NewControllerDialog(final Project project, final PsiDirectory directory) super(); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - this.validator = NewControllerValidator.getInstance(this); setContentPane(contentPane); setModal(true); @@ -87,11 +103,7 @@ public void windowClosing(final WindowEvent event) { // call onCancel() on ESCAPE contentPane.registerKeyboardAction( - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - onCancel(); - } - }, + (final ActionEvent event) -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); @@ -178,7 +190,7 @@ public static void open(final Project project, final PsiDirectory directory) { } private void onOK() { - if (!validator.validate()) { + if (!validateFormFields()) { return; } @@ -243,6 +255,7 @@ private Boolean getIsInheritClass() { return inheritClass.isSelected(); } + @Override protected void onCancel() { dispose(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/NewControllerValidator.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/NewControllerValidator.java deleted file mode 100644 index b34b20a8d..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/NewControllerValidator.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.validator; - -import com.jetbrains.php.refactoring.PhpNameUtil; -import com.magento.idea.magento2plugin.actions.generation.dialog.NewControllerDialog; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.util.RegExUtil; -import javax.swing.JOptionPane; - -@SuppressWarnings({ - "PMD.OnlyOneReturn", - "PMD.FieldNamingConventions", - "PMD.DataflowAnomalyAnalysis", - "PMD.NonThreadSafeSingleton", - "PMD.NPathComplexity" -}) -public class NewControllerValidator { - private static final String ACTION_NAME = "Action Name"; - private static NewControllerValidator INSTANCE; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; - private NewControllerDialog dialog; - - /** - * Get instance of a class. - * - * @param dialog New controller dialog - * - * @return NewControllerValidator - */ - public static NewControllerValidator getInstance(final NewControllerDialog dialog) { - if (null == INSTANCE) { - INSTANCE = new NewControllerValidator(); - } - - INSTANCE.dialog = dialog; - return INSTANCE; - } - - /** - * New controller validator constructor. - */ - public NewControllerValidator() { - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); - } - - /** - * Validate whenever new controller dialog data is ready for generation. - * - * @return Boolean - */ - public boolean validate() { - final String errorTitle = commonBundle.message("common.error"); - final String actionName = dialog.getActionName(); - - if (!PhpNameUtil.isValidClassName(actionName)) { - final String errorMessage = this.validatorBundle.message( - "validator.class.isNotValid", - ACTION_NAME - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return false; - } - - if (actionName.length() == 0) { - final String errorMessage = this.validatorBundle.message( - "validator.notEmpty", - ACTION_NAME - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return false; - } - - if (!actionName.matches(RegExUtil.ALPHANUMERIC)) { - final String errorMessage = this.validatorBundle.message( - "validator.alphaNumericCharacters", - ACTION_NAME - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return false; - } - - if (!Character.isUpperCase(actionName.charAt(0)) - && !Character.isDigit(actionName.charAt(0)) - ) { - final String errorMessage = this.validatorBundle.message( - "validator.startWithNumberOrCapitalLetter", - ACTION_NAME - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return false; - } - - final String controllerName = dialog.getControllerName(); - - if (!PhpNameUtil.isValidNamespaceName(controllerName)) { - final String errorMessage = this.validatorBundle.message( - "validator.namespace.isNotValid", - "Controller Name" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return false; - } - - return true; - } -} From 7ebcc23752f5f5f537b3d42dbd207d57b88efb0d Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Wed, 21 Oct 2020 01:04:49 +0530 Subject: [PATCH 2/6] Fixed static test failures --- .../actions/generation/dialog/NewControllerDialog.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 52d042284..a616876cb 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -38,7 +38,8 @@ @SuppressWarnings({ "PMD.TooManyFields", - "PMD.ConstructorCallsOverridableMethod" + "PMD.ConstructorCallsOverridableMethod", + "PMD.ExcessiveImports" }) public class NewControllerDialog extends AbstractDialog { private final String moduleName; From 87c2bccc20389092729dfba10561ba4486242f91 Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Wed, 21 Oct 2020 19:01:28 +0530 Subject: [PATCH 3/6] Fixed validator error messages --- resources/magento2/validation.properties | 8 ++++---- .../dialog/NewControllerDialog.java | 20 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/resources/magento2/validation.properties b/resources/magento2/validation.properties index 6800dd35e..6bc5701df 100644 --- a/resources/magento2/validation.properties +++ b/resources/magento2/validation.properties @@ -1,15 +1,15 @@ validator.notEmpty=The {0} field must not be empty validator.package.validPath=Please specify a valid Magento 2 installation path -validator.alphaNumericCharacters={0} must contain letters and numbers only +validator.alphaNumericCharacters=The {0} must contain letters and numbers only validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only validator.alreadyDeclared={0} is already declared in the {1} module. -validator.startWithNumberOrCapitalLetter={0} must start from a number or a capital letter +validator.startWithNumberOrCapitalLetter=The {0} must start from a number or a capital letter validator.onlyNumbers={0} must contain numbers only validator.mustNotBeNegative={0} must not be negative validator.identifier={0} must contain letters, numbers, dashes, and underscores only -validator.class.isNotValid={0} is not valid class name +validator.class.isNotValid=The {0} is not valid class name validator.class.shouldBeUnique=Duplicated class {0} -validator.namespace.isNotValid={0} is not valid namespace name +validator.namespace.isNotValid=The {0} is not valid namespace name validator.directory.isNotValid={0} is not valid validator.module.noSuchModule=No such module {0} validator.file.alreadyExists={0} already exists diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index a616876cb..23776efd7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -12,7 +12,11 @@ import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpNamespaceNameRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.StartWithNumberOrCapitalLetterRule; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp; @@ -59,18 +63,18 @@ public class NewControllerDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) - @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, - message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, - message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) - @FieldValidation(rule = RuleRegistry.PHP_CLASS, - message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) + @FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME, + message = {PhpNamespaceNameRule.MESSAGE, CONTROLLER_NAME}) private JTextField controllerName; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ACTION_NAME}) - @FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME, - message = {NotEmptyRule.MESSAGE, ACTION_NAME}) + @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, + message = {StartWithNumberOrCapitalLetterRule.MESSAGE, ACTION_NAME}) + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, + message = {AlphanumericRule.MESSAGE, ACTION_NAME}) + @FieldValidation(rule = RuleRegistry.PHP_CLASS, + message = {PhpClassRule.MESSAGE, ACTION_NAME}) private JTextField actionName; /** From 556bb9873cb2fb9797f52101e91dedf178b9d34c Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Wed, 21 Oct 2020 19:21:49 +0530 Subject: [PATCH 4/6] Renamed 'controller action' to 'action name' in new controller dialog --- resources/magento2/common.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/magento2/common.properties b/resources/magento2/common.properties index b7e0ef9a6..785b0a831 100644 --- a/resources/magento2/common.properties +++ b/resources/magento2/common.properties @@ -8,7 +8,7 @@ common.httpMethod=HTTP Method common.controller.name=Controller Name common.controller.inheritAction=Inherit Action Class common.controller.backend.acl=Admin Resource ACL -common.controller.action=Controller Action +common.controller.action=Action Name common.ok=OK common.yes=Yes common.no=No From 26504ab836393a604b025edffdc51b42178e72f7 Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Wed, 21 Oct 2020 22:20:18 +0530 Subject: [PATCH 5/6] Fixed PHP class validation rule --- .../generation/dialog/NewControllerDialog.java | 11 ++--------- .../dialog/validator/rule/PhpClassRule.java | 4 ++-- .../magento/idea/magento2plugin/util/RegExUtil.java | 3 +++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 23776efd7..99ee9d490 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -12,11 +12,8 @@ import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpNamespaceNameRule; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.StartWithNumberOrCapitalLetterRule; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp; @@ -63,16 +60,12 @@ public class NewControllerDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) - @FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME, - message = {PhpNamespaceNameRule.MESSAGE, CONTROLLER_NAME}) + @FieldValidation(rule = RuleRegistry.PHP_CLASS, + message = {PhpClassRule.MESSAGE, CONTROLLER_NAME}) private JTextField controllerName; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ACTION_NAME}) - @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, - message = {StartWithNumberOrCapitalLetterRule.MESSAGE, ACTION_NAME}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, - message = {AlphanumericRule.MESSAGE, ACTION_NAME}) @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, ACTION_NAME}) private JTextField actionName; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpClassRule.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpClassRule.java index d90f1a1a8..d128c5d95 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpClassRule.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpClassRule.java @@ -5,7 +5,7 @@ package com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule; -import com.jetbrains.php.refactoring.PhpNameUtil; +import com.magento.idea.magento2plugin.util.RegExUtil; public class PhpClassRule implements ValidationRule { public static final String MESSAGE = "validator.class.isNotValid"; @@ -13,7 +13,7 @@ public class PhpClassRule implements ValidationRule { @Override public boolean check(final String value) { - return PhpNameUtil.isValidClassName(value); + return value.matches(RegExUtil.Magento.PHP_CLASS); } public static ValidationRule getInstance() { diff --git a/src/com/magento/idea/magento2plugin/util/RegExUtil.java b/src/com/magento/idea/magento2plugin/util/RegExUtil.java index f27746f3d..66a1e7036 100644 --- a/src/com/magento/idea/magento2plugin/util/RegExUtil.java +++ b/src/com/magento/idea/magento2plugin/util/RegExUtil.java @@ -32,6 +32,9 @@ public class RegExUtil { = "(\\d+)\\.(\\d+)\\.(\\d+)[a-zA-Z0-9_\\-]*"; public static class Magento { + public static final String PHP_CLASS + = "[A-Z][a-zA-Z0-9]+"; + public static final String MODULE_NAME = "[A-Z][a-zA-Z0-9]+_[A-Z][a-zA-Z0-9]+"; From 7911aabafbedafec0dd2368706eeb47a75b2bae9 Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Thu, 22 Oct 2020 01:03:32 +0530 Subject: [PATCH 6/6] Added PHP_DIRECTORY rule to NewControllerDialog --- resources/magento2/validation.properties | 3 ++- .../dialog/NewControllerDialog.java | 5 +++-- .../validator/annotation/RuleRegistry.java | 2 ++ .../validator/rule/PhpDirectoryRule.java | 22 +++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpDirectoryRule.java diff --git a/resources/magento2/validation.properties b/resources/magento2/validation.properties index 6bc5701df..19c38158f 100644 --- a/resources/magento2/validation.properties +++ b/resources/magento2/validation.properties @@ -7,10 +7,11 @@ validator.startWithNumberOrCapitalLetter=The {0} must start from a number or a c validator.onlyNumbers={0} must contain numbers only validator.mustNotBeNegative={0} must not be negative validator.identifier={0} must contain letters, numbers, dashes, and underscores only -validator.class.isNotValid=The {0} is not valid class name +validator.class.isNotValid=The {0} field does not contain a valid class name validator.class.shouldBeUnique=Duplicated class {0} validator.namespace.isNotValid=The {0} is not valid namespace name validator.directory.isNotValid={0} is not valid +validator.directory.php.isNotValid=The {0} field does not contain a valid PHP directory validator.module.noSuchModule=No such module {0} validator.file.alreadyExists={0} already exists validator.file.cantBeCreated={0} can't be created diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 99ee9d490..4efabffc1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -14,6 +14,7 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpDirectoryRule; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp; @@ -60,8 +61,8 @@ public class NewControllerDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME}) - @FieldValidation(rule = RuleRegistry.PHP_CLASS, - message = {PhpClassRule.MESSAGE, CONTROLLER_NAME}) + @FieldValidation(rule = RuleRegistry.PHP_DIRECTORY, + message = {PhpDirectoryRule.MESSAGE, CONTROLLER_NAME}) private JTextField controllerName; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java index b3114ba40..74976369f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java @@ -14,6 +14,7 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpDirectoryRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpNamespaceNameRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.RouteIdRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.StartWithNumberOrCapitalLetterRule; @@ -25,6 +26,7 @@ public enum RuleRegistry { ALPHANUMERIC(AlphanumericRule.class), ALPHANUMERIC_WITH_UNDERSCORE(AlphanumericWithUnderscoreRule.class), DIRECTORY(DirectoryRule.class), + PHP_DIRECTORY(PhpDirectoryRule.class), IDENTIFIER(IdentifierRule.class), PHP_NAMESPACE_NAME(PhpNamespaceNameRule.class), START_WITH_NUMBER_OR_CAPITAL_LETTER(StartWithNumberOrCapitalLetterRule.class), diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpDirectoryRule.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpDirectoryRule.java new file mode 100644 index 000000000..f0f2b8b21 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpDirectoryRule.java @@ -0,0 +1,22 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule; + +import com.magento.idea.magento2plugin.util.RegExUtil; + +public class PhpDirectoryRule implements ValidationRule { + public static final String MESSAGE = "validator.directory.php.isNotValid"; + private static final ValidationRule INSTANCE = new PhpDirectoryRule(); + + @Override + public boolean check(final String value) { + return value.matches(RegExUtil.Magento.PHP_CLASS); + } + + public static ValidationRule getInstance() { + return INSTANCE; + } +}