Skip to content

Commit

Permalink
allow to use dot notation on individual group members
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Mar 21, 2024
1 parent bf300a6 commit 420dfed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions DotAccess.php
Expand Up @@ -20,6 +20,8 @@ class DotAccess
*/
public static function get($array, $key, $default = null)
{
$key = trim($key, '.');

if (!static::accessible($array)) {
return $default;
}
Expand Down
10 changes: 9 additions & 1 deletion action.php
Expand Up @@ -29,10 +29,18 @@ public function getUser()
$result = json_decode($raw, true);
if (!$result) throw new OAuthException('Failed to parse data from userurl');

$grpdots = sexplode('[]', $this->getConf('json-grps'), 2);
$user = DotAccess::get($result, $this->getConf('json-user'), '');
$name = DotAccess::get($result, $this->getConf('json-name'), '');
$mail = DotAccess::get($result, $this->getConf('json-mail'), '');
$grps = DotAccess::get($result, $this->getConf('json-grps'), []);
$grps = DotAccess::get($result, $grpdots[0], []);

// use dot notation on each group
if(is_array($grps) && $grpdots[1]) {
$grps = array_map(function($grp) use ($grpdots) {
return DotAccess::get($grp, $grpdots[1], '');
}, $grps);
}

// type fixes
if (is_array($user)) $user = array_shift($user);
Expand Down

0 comments on commit 420dfed

Please sign in to comment.