Author: Christer Edvartsen (cogo@starzinger.net)
Inheritance: implements Imbo\Model\ModelInterface
Exemplo n.º 1
0
 /**
  * Get an access control rule specified by ID
  *
  * @param EventInterface $event The current event
  */
 public function getRule(EventInterface $event)
 {
     $acl = $event->getAccessControl();
     $request = $event->getRequest();
     $publicKey = $request->getRoute()->get('publickey');
     $accessRuleId = $request->getRoute()->get('accessRuleId');
     $keyExists = $acl->publicKeyExists($publicKey);
     if (!$keyExists) {
         throw new RuntimeException('Public key not found', 404);
     }
     $accessRule = $acl->getAccessRule($publicKey, $accessRuleId);
     if (!$accessRule) {
         throw new RuntimeException('Access rule not found', 404);
     }
     $model = new AccessRuleModel();
     $model->setId($accessRule['id'])->setUsers($accessRule['users']);
     if (isset($accessRule['group'])) {
         $model->setGroup($accessRule['group']);
     }
     if (isset($accessRule['resources'])) {
         $model->setResources($accessRule['resources']);
     }
     $event->getResponse()->setModel($model);
 }
Exemplo n.º 2
0
 /**
  * @covers Imbo\Model\AccessRule::getData
  */
 public function testGetData()
 {
     $this->model->setId(1)->setGroup('name')->setResources(['r1', 'r2'])->setUsers(['u1', 'u2']);
     $this->assertSame(['id' => 1, 'group' => 'name', 'resources' => ['r1', 'r2'], 'users' => ['u1', 'u2']], $this->model->getData());
 }
Exemplo n.º 3
0
Arquivo: XML.php Projeto: imbo/imbo
    /**
     * {@inheritdoc}
     */
    public function formatAccessRule(Model\AccessRule $model)
    {
        $rule = $this->formatAccessRuleArray(['id' => $model->getId(), 'users' => $model->getUsers(), 'group' => $model->getGroup(), 'resources' => $model->getResources()]);
        return <<<RULE
<?xml version="1.0" encoding="UTF-8"?>
<imbo>
  {$rule}
</imbo>
RULE;
    }
Exemplo n.º 4
0
Arquivo: JSON.php Projeto: imbo/imbo
 /**
  * {@inheritdoc}
  */
 public function formatAccessRule(Model\AccessRule $model)
 {
     $data = ['id' => $model->getId(), 'users' => $model->getUsers()];
     if ($group = $model->getGroup()) {
         $data['group'] = $group;
     }
     if ($resources = $model->getResources()) {
         $data['resources'] = $resources;
     }
     return $this->encode($data);
 }