/** * {@inheritdoc} */ public function getCallerPermissions(Caller $caller) { $cacheId = sprintf('callers/%s/%s', $caller->getCallerType(), $caller->getCallerId()); $permissions = $this->cache->fetch($cacheId); if (!$this->cache->contains($cacheId)) { $permissions = $this->driver->getCallerPermissions($caller); $this->cache->save($cacheId, $permissions); } return $permissions; }
/** * {@inheritdoc} */ public function getCallerPermissions(Caller $caller) { $cacheId = sprintf('callers/%s/%s', $caller->getCallerType(), $caller->getCallerId()); $item = $this->pool->getItem($cacheId); $permissions = $item->get(); if ($item->isMiss()) { $item->lock(); $permissions = $this->driver->getCallerPermissions($caller); $item->set($permissions); } return $permissions; }
/** @test */ final function the_caller_can_call_the_caller_trait_methods() { $this->caller->allow('create'); $this->assertTrue($this->caller->can('create')); $this->caller->deny('create'); $this->assertFalse($this->caller->can('create')); $this->caller->toggle('update'); $this->assertTrue($this->caller->can('update')); }
/** * Creates a key to store the caller's permissions * * @param \BeatSwitch\Lock\Callers\Caller $caller * @return string */ private function getCallerKey(Caller $caller) { return 'caller_' . $caller->getCallerType() . '_' . $caller->getCallerId(); }
/** * Get all the lock instances for all the roles of the current caller * * @return \BeatSwitch\Lock\Roles\RoleLock[] */ protected function getLockInstancesForCallerRoles() { return array_map(function ($role) { return $this->manager->role($role); }, $this->caller->getCallerRoles()); }