芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/public_html/invoicer.pulsehost.co.uk/vendor/silber/bouncer/src/BaseClipboard.php
checkGetId($authority, $ability, $model); } /** * Check if an authority has the given roles. * * @param array|string $roles * @param string $boolean * @return bool */ public function checkRole(Model $authority, $roles, $boolean = 'or') { $count = $this->countMatchingRoles($authority, $roles); if ($boolean == 'or') { return $count > 0; } elseif ($boolean === 'not') { return $count === 0; } return $count == count((array) $roles); } /** * Count the authority's roles matching the given roles. * * @param \Illuminate\Database\Eloquent\Model $authority * @param array|string $roles * @return int */ protected function countMatchingRoles($authority, $roles) { $lookups = $this->getRolesLookup($authority); return count(array_filter($roles, function ($role) use ($lookups) { switch (true) { case is_string($role): return $lookups['names']->has($role); case is_numeric($role): return $lookups['ids']->has($role); case $role instanceof Model: return $lookups['ids']->has($role->getKey()); } throw new InvalidArgumentException('Invalid model identifier'); })); } /** * Get the given authority's roles' IDs and names. * * @return array */ public function getRolesLookup(Model $authority) { $roles = $authority->roles()->get([ 'name', Models::role()->getQualifiedKeyName(), ])->pluck('name', Models::role()->getKeyName()); return ['ids' => $roles, 'names' => $roles->flip()]; } /** * Get the given authority's roles' names. * * @return \Illuminate\Support\Collection */ public function getRoles(Model $authority) { return $this->getRolesLookup($authority)['names']->keys(); } /** * Get a list of the authority's abilities. * * @param bool $allowed * @return \Illuminate\Database\Eloquent\Collection */ public function getAbilities(Model $authority, $allowed = true) { return Abilities::forAuthority($authority, $allowed)->get(); } /** * Get a list of the authority's forbidden abilities. * * @return \Illuminate\Database\Eloquent\Collection */ public function getForbiddenAbilities(Model $authority) { return $this->getAbilities($authority, false); } /** * Determine whether the authority owns the given model. * * @return bool */ public function isOwnedBy($authority, $model) { return $model instanceof Model && Models::isOwnedBy($authority, $model); } }