Skip to content

Commit

Permalink
Merge pull request #127 from ck99/#126_remove_unused_priority_handling
Browse files Browse the repository at this point in the history
#126 remove unused priority handling from cache control subscriber
  • Loading branch information
ddeboer committed Aug 4, 2014
2 parents db41aa3 + e645ea1 commit 1144c3f
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions EventListener/AbstractRuleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ class AbstractRuleSubscriber
*
* @param RuleMatcherInterface $ruleMatcher The headers apply to responses matched by this matcher.
* @param array $settings An array of header configuration.
* @param int $priority Optional priority of this matcher. Higher priority is applied first.
*/
public function addRule(
RuleMatcherInterface $ruleMatcher,
array $settings = array(),
$priority = 0
array $settings = array()
) {
if (!isset($this->rulesMap[$priority])) {
$this->rulesMap[$priority] = array();
}
$this->rulesMap[$priority][] = array($ruleMatcher, $settings);
$this->rulesMap[] = array($ruleMatcher, $settings);
}

/**
Expand All @@ -51,28 +46,12 @@ public function addRule(
*/
protected function matchRule(Request $request, Response $response)
{
foreach ($this->getRules() as $elements) {
foreach ($this->rulesMap as $elements) {
if ($elements[0]->matches($request, $response)) {
return $elements[1];
}
}

return false;
}

/**
* Get the rules ordered by priority.
*
* @return RuleMatcherInterface[] of array with rule matcher, settings
*/
private function getRules()
{
$sortedRules = array();
krsort($this->rulesMap);
foreach ($this->rulesMap as $rules) {
$sortedRules = array_merge($sortedRules, $rules);
}

return $sortedRules;
}
}

0 comments on commit 1144c3f

Please sign in to comment.