/** * Applies a configuration set to a dependency injector. * * @param Injector $injector */ public function apply(Injector $injector) { // Create a new Manager instance. $manager = new Manager(new ArrayDriver()); // Managers can do everything $manager->role('manager')->allow('all'); // $manager->role('employee')->allow('guest', 'read'); $injector->share($manager); }
/** * Return the lock instance to work on. * * @return \BeatSwitch\Lock\Callers\CallerLock|\BeatSwitch\Lock\Roles\RoleLock * @throws \Exception */ protected function lock() { if ($this->subject == 'user') { return $this->manager->caller($this->user); } elseif ($this->subject == 'role') { return $this->manager->role($this->role); } else { throw new \Exception("Caller not allowed: {$this->subject}"); } }
/** * @param \BeatSwitch\Lock\Roles\Role|string $role * @return \BeatSwitch\Lock\Roles\RoleLock */ protected function getRoleLock($role) { return $this->manager->role($role); }