Skip to content

Commit

Permalink
Work around bug in RegexIterator in certain versions of PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
josegonzalez committed May 30, 2015
1 parent 6067f53 commit 7769771
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 18 additions & 1 deletion Lib/AnnotationParserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,29 @@ public function getPrefixedAnnotations($action) {
$annotations = $this->getAnnotations($action);

if (!empty($prefix)) {
$annotations = $annotations->useNamespace($prefix);
$annotations = $this->useNamespace($annotations, $prefix);
}

return $annotations;
}

protected function useNamespace(AnnotationsBag $annotations, $prefix)
{
$data = [];
$consumer = '(' . implode('|', array_map('preg_quote', ['.'])) .')';
$namespace_pattern = '/^' . preg_quote(rtrim($prefix, '.')) . $consumer . '/';

foreach ($annotations->toArray() as $key => $value) {
$newKey = preg_replace($namespace_pattern, '', $key);
if ($newKey === null || $newKey === $key) {
continue;
}
$data[$newKey] = $value;
}

return new AnnotationsBag($data);
}

/**
* Retrieve all the roles for the controller action
*
Expand Down
6 changes: 3 additions & 3 deletions Lib/ModelParserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public function performCheck($user, $action) {
$Model = $controller->$modelName;
$record = $this->getData($Model, $methodName, $findMethod, $findOptions);
} catch (Exception $e) {
CakeLog::debug($e->getMessage());
CakeLog::debug($e->getMessage());
return false;
}

$rules = $annotations->useNamespace('conditions')->get('if');
$rules = $this->useNamespace($annotations, 'conditions')->get('if');
if (empty($rules)) {
return !empty($record);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ public function getFinder(Controller $Controller, AnnotationsBag $annotations) {
$modelName = $annotations->get('model');
$methodName = $annotations->get('method');
$findMethod = $annotations->get('find');
$findOptions = $annotations->useNamespace('options')->export();
$findOptions = $this->useNamespace($annotations, 'options')->toArray();

if (empty($modelName)) {
$modelName = $Controller->modelClass;
Expand Down

0 comments on commit 7769771

Please sign in to comment.