Skip to content

Commit

Permalink
Use SchemaValidationHelper to accomplish all validation for an extension
Browse files Browse the repository at this point in the history
  • Loading branch information
craigh committed Jul 14, 2017
1 parent 76bacf9 commit 0c1baf3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 29 deletions.
28 changes: 1 addition & 27 deletions src/lib/Zikula/Bundle/CoreBundle/Bundle/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function decode($file)
$base = substr($base, strlen($zkRoot) + 1);

$json = json_decode($this->getFileContents($file), true);
if (\JSON_ERROR_NONE === json_last_error() && true === $this->validateBasic($json)) {
if (\JSON_ERROR_NONE === json_last_error()) {
// add base-path for future use
$json['extra']['zikula']['base-path'] = $base;

Expand Down Expand Up @@ -102,32 +102,6 @@ public function getThemesMetaData($indexByShortName = false)
return $this->getMetaData('zikula-theme', $indexByShortName);
}

// @todo this can probably be removed in favour of ComposerValidationHelper
private function validateBasic($json)
{
if (!isset($json['type'])) {
return false;
}

switch ($json['type']) {
case 'zikula-module':
case 'zikula-theme':
break;
default:
return false;
}

if (!isset($json['autoload']['psr-4'])) {
return false;
}

if (!isset($json['extra']['zikula']['class'])) {
return false;
}

return true;
}

private function getMetaData($type, $indexByShortName)
{
$array = [];
Expand Down
5 changes: 3 additions & 2 deletions src/system/ExtensionsModule/Schema/schema.composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"type": "object",
"additionalProperties": true
}
}
},
"required": ["psr-4"]
},
"require": {
"type": "object",
Expand Down Expand Up @@ -90,5 +91,5 @@
"additionalProperties": true
}
},
"required": ["name", "description", "type", "license", "authors", "require", "extra"]
"required": ["name", "description", "type", "license", "authors", "require", "extra", "autoload"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"name": "Zikula Team"
}
],
"autoload": {
"psr-4": { "Zikula\\FooModule\\": "" }
},
"require": {
"php": ">=5.5.9"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"name": "Zikula Team"
}
],
"autoload": {
"psr-4": { "Zikula\\FooModule\\": "" }
},
"require": {
"php": ">=5.5.9"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "zikula/foo-module",
"description": "A foo module.",
"type": "zikula-module",
"license": "MIT",
"authors": [
{
"name": "Zikula Team"
}
],
"autoload": {
"psr-0": { "Zikula\\Module\\FooModule\\": "" }
},
"require": {
"php": ">=5.5.9"
},
"extra": {
"zikula": {
"class": "Zikula\\SpecModule\\ZikulaFooModule",
"core-compatibility": ">=1.4.2"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"name": "Zikula Team"
}
],
"autoload": {
"psr-4": { "Zikula\\FooModule\\": "" }
},
"require": {
"php": ">=5.5.9"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function getFileNamesProvider()
['minimum_composer.json', true, []],
['maximum_composer.json', true, []],
['minimum_error1_composer.json', false, ["Error found in composer file of Fixtures (/../Fixtures) in property \"description\": The property description is required."]],
['minimum_error2_composer.json', false, ["Error found in composer file of Fixtures (/../Fixtures) in property \"autoload.psr-4\": The property psr-4 is required."]],
['minimum_syntax_error_composer.json', false, ["Unable to decode composer file of Fixtures (/../Fixtures): Syntax error. Ensure the composer.json file has a valid syntax."]],
['empty_composer.json', false, [
"Error found in composer file of Fixtures (/../Fixtures) in property \"name\": The property name is required.",
Expand All @@ -70,6 +71,7 @@ public function getFileNamesProvider()
"Error found in composer file of Fixtures (/../Fixtures) in property \"authors\": The property authors is required.",
"Error found in composer file of Fixtures (/../Fixtures) in property \"require\": The property require is required.",
"Error found in composer file of Fixtures (/../Fixtures) in property \"extra\": The property extra is required.",
"Error found in composer file of Fixtures (/../Fixtures) in property \"autoload\": The property autoload is required.",
]],
];
}
Expand Down

0 comments on commit 0c1baf3

Please sign in to comment.