/** * Get the resources associated with a specific group * * @param EventInterface $event The current event */ public function getGroup(EventInterface $event) { $route = $event->getRequest()->getRoute(); $groupName = $route->get('group'); $adapter = $event->getAccessControl(); if (!$adapter->groupExists($groupName)) { throw new ResourceException('Resource group not found', 404); } $resources = $adapter->getGroup($groupName); $model = new GroupModel(); $model->setName($groupName); $model->setResources($resources); $response = $event->getResponse(); $response->setModel($model); }
/** * {@inheritdoc} */ public function formatGroup(Model\Group $model) { $entries = ''; foreach ($model->getResources() as $resource) { $entries .= '<resource>' . $this->formatValue($resource) . '</resource>'; } return <<<GROUP <?xml version="1.0" encoding="UTF-8"?> <imbo> <name>{$model->getName()}</name> <resources>{$entries}</resources> </imbo> GROUP; }
/** * @covers Imbo\Model\Group::getData */ public function testGetData() { $this->model->setName('name')->setResources(['image.get', 'image.head']); $this->assertSame(['name' => 'name', 'resources' => ['image.get', 'image.head']], $this->model->getData()); }
/** * {@inheritdoc} */ public function formatGroup(Model\Group $model) { return $this->encode(['name' => $model->getName(), 'resources' => $model->getResources()]); }