Skip to content

Commit 7911aab

Browse files
committed
Added PHP_DIRECTORY rule to NewControllerDialog
1 parent 26504ab commit 7911aab

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

resources/magento2/validation.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ validator.startWithNumberOrCapitalLetter=The {0} must start from a number or a c
77
validator.onlyNumbers={0} must contain numbers only
88
validator.mustNotBeNegative={0} must not be negative
99
validator.identifier={0} must contain letters, numbers, dashes, and underscores only
10-
validator.class.isNotValid=The {0} is not valid class name
10+
validator.class.isNotValid=The {0} field does not contain a valid class name
1111
validator.class.shouldBeUnique=Duplicated class {0}
1212
validator.namespace.isNotValid=The {0} is not valid namespace name
1313
validator.directory.isNotValid={0} is not valid
14+
validator.directory.php.isNotValid=The {0} field does not contain a valid PHP directory
1415
validator.module.noSuchModule=No such module {0}
1516
validator.file.alreadyExists={0} already exists
1617
validator.file.cantBeCreated={0} can't be created

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
1515
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
1616
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpDirectoryRule;
1718
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator;
1819
import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp;
1920
import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp;
@@ -60,8 +61,8 @@ public class NewControllerDialog extends AbstractDialog {
6061

6162
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
6263
message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME})
63-
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
64-
message = {PhpClassRule.MESSAGE, CONTROLLER_NAME})
64+
@FieldValidation(rule = RuleRegistry.PHP_DIRECTORY,
65+
message = {PhpDirectoryRule.MESSAGE, CONTROLLER_NAME})
6566
private JTextField controllerName;
6667

6768
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,

src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
1515
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule;
1616
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpDirectoryRule;
1718
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpNamespaceNameRule;
1819
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.RouteIdRule;
1920
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.StartWithNumberOrCapitalLetterRule;
@@ -25,6 +26,7 @@ public enum RuleRegistry {
2526
ALPHANUMERIC(AlphanumericRule.class),
2627
ALPHANUMERIC_WITH_UNDERSCORE(AlphanumericWithUnderscoreRule.class),
2728
DIRECTORY(DirectoryRule.class),
29+
PHP_DIRECTORY(PhpDirectoryRule.class),
2830
IDENTIFIER(IdentifierRule.class),
2931
PHP_NAMESPACE_NAME(PhpNamespaceNameRule.class),
3032
START_WITH_NUMBER_OR_CAPITAL_LETTER(StartWithNumberOrCapitalLetterRule.class),
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule;
7+
8+
import com.magento.idea.magento2plugin.util.RegExUtil;
9+
10+
public class PhpDirectoryRule implements ValidationRule {
11+
public static final String MESSAGE = "validator.directory.php.isNotValid";
12+
private static final ValidationRule INSTANCE = new PhpDirectoryRule();
13+
14+
@Override
15+
public boolean check(final String value) {
16+
return value.matches(RegExUtil.Magento.PHP_CLASS);
17+
}
18+
19+
public static ValidationRule getInstance() {
20+
return INSTANCE;
21+
}
22+
}

0 commit comments

Comments
 (0)