Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ability to Disable Default Pattern Data Rules + Add Extra Pattern Data Rules #17

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 37 additions & 3 deletions src/PatternLab/PatternData.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,52 @@ public static function getRules() {

}

/**
* Load all of the rules related to Pattern Data

/**
* Load all of the rules related to Pattern Data, plus any extra add-ons
*/
public static function loadRules($options) {
// First handle default PL rules, minus any being disabled
foreach (glob(__DIR__."/PatternData/Rules/*.php") as $filename) {
$ruleName = str_replace(".php","",str_replace(__DIR__."/PatternData/Rules/","",$filename));
if ($ruleName[0] != "_") {

$disabledRules = array();
if (Config::getOption("disabledPatternRules")) {
$disabledRules = Config::getOption("disabledPatternRules");
}

// Load all rules that aren't on the disabledPatternRules list
if (($ruleName[0] != "_") && (!in_array($ruleName, $disabledRules))) {
$ruleClass = "\PatternLab\PatternData\Rules\\".$ruleName;
$rule = new $ruleClass($options);
self::setRule($ruleName, $rule);
}
}

// Then handle any extra rules to add on top of the default PL rules
$extraPatternRulesDir = Config::getOption("sourceDir") . '/_extensions/rules'; // Default extra rules location to check
if (Config::getOption("extraPatternRulesDir")) {
$extraPatternRulesDir = Config::getOption("extraPatternRulesDir");
}

if (is_dir($extraPatternRulesDir)){
foreach (glob($extraPatternRulesDir . "/*.php") as $filename) {
$ruleName = str_replace(".php","",str_replace($extraPatternRulesDir . "/","",$filename));

$extraRules = array();
if (Config::getOption("extraPatternRules")) {
$extraRules = Config::getOption("extraPatternRules");
}

// Only load extra rules that are on the extraPatternRules list
if (($ruleName[0] != "_") && (in_array($ruleName, $extraRules))) {
require_once($filename); // Pull in extra rule so we can use it
$ruleClass = "\PatternLab\PatternData\Rules\\".$ruleName;
$rule = new $ruleClass($options);
self::setRule($ruleName, $rule);
}
}
}
}

/**
Expand Down