Skip to content

Commit

Permalink
Use array key as alias for Authorize and Authenticate providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Walther Lalk committed Sep 1, 2014
1 parent c2452a7 commit a250027
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -492,20 +492,20 @@ public function constructAuthorize() {
$global = $authorize[AuthComponent::ALL];
unset($authorize[AuthComponent::ALL]);
}
foreach ($authorize as $class => $config) {
foreach ($authorize as $alias => $config) {
if (!empty($config['className'])) {
$class = $config['className'];
unset($config['className']);
} else {
$class = $alias;
}
$className = App::className($class, 'Auth', 'Authorize');
if (!class_exists($className)) {
throw new Exception(sprintf('Authorization adapter "%s" was not found.', $class));
}
if (!method_exists($className, 'authorize')) {
throw new Exception('Authorization objects must implement an authorize() method.');
}
if (!empty($config['alias'])) {
$alias = $config['alias'];
unset($config['alias']);
} else {
$alias = $className;
}
$config = (array)$config + $global;
$this->_authorizeObjects[$alias] = new $className($this->_registry, $config);
}
Expand Down Expand Up @@ -749,10 +749,12 @@ public function constructAuthenticate() {
$global = $authenticate[AuthComponent::ALL];
unset($authenticate[AuthComponent::ALL]);
}
foreach ($authenticate as $class => $config) {
foreach ($authenticate as $alias => $config) {
if (!empty($config['className'])) {
$class = $config['className'];
unset($config['className']);
} else {
$class = $alias;
}
$className = App::className($class, 'Auth', 'Authenticate');
if (!class_exists($className)) {
Expand All @@ -761,12 +763,6 @@ public function constructAuthenticate() {
if (!method_exists($className, 'authenticate')) {
throw new Exception('Authentication objects must implement an authenticate() method.');
}
if (!empty($config['alias'])) {
$alias = $config['alias'];
unset($config['alias']);
} else {
$alias = $className;
}
$config = array_merge($global, (array)$config);
$this->_authenticateObjects[$alias] = new $className($this->_registry, $config);
}
Expand Down

0 comments on commit a250027

Please sign in to comment.