Автор: Christer Edvartsen (cogo@starzinger.net)
Наследование: implements Imbo\Model\ModelInterface
Пример #1
0
 /**
  * Handle DELETE requests
  *
  * @param EventInterface
  */
 public function deleteImage(EventInterface $event)
 {
     $event->getManager()->trigger('db.image.delete');
     $event->getManager()->trigger('storage.image.delete');
     $model = new Model\ArrayModel();
     $model->setData(['imageIdentifier' => $event->getRequest()->getImageIdentifier()]);
     $event->getResponse()->setModel($model);
 }
Пример #2
0
 /**
  * Handle POST requests
  *
  * @param EventInterface
  */
 public function addImage(EventInterface $event)
 {
     $event->getManager()->trigger('db.image.insert');
     $event->getManager()->trigger('storage.image.insert');
     $request = $event->getRequest();
     $response = $event->getResponse();
     $image = $request->getImage();
     $model = new Model\ArrayModel();
     $model->setData(['imageIdentifier' => $image->getImageIdentifier(), 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'extension' => $image->getExtension()]);
     $response->setModel($model);
 }
Пример #3
0
 /**
  * Handle GET requests
  *
  * @param EventInterface $event The current event
  */
 public function get(EventInterface $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $response->setStatusCode(200, 'Hell Yeah');
     $baseUrl = $request->getSchemeAndHttpHost() . $request->getBaseUrl();
     $model = new Model\ArrayModel();
     $model->setData(array('version' => Version::VERSION, 'urls' => array('site' => 'http://www.imbo-project.org', 'source' => 'https://github.com/imbo/imbo', 'issues' => 'https://github.com/imbo/imbo/issues', 'docs' => 'http://docs.imbo-project.org'), 'endpoints' => array('status' => $baseUrl . '/status', 'stats' => $baseUrl . '/stats', 'user' => $baseUrl . '/users/{publicKey}', 'images' => $baseUrl . '/users/{publicKey}/images', 'image' => $baseUrl . '/users/{publicKey}/images/{imageIdentifier}', 'globalShortImageUrl' => $baseUrl . '/s/{id}', 'metadata' => $baseUrl . '/users/{publicKey}/images/{imageIdentifier}/metadata', 'shortImageUrls' => $baseUrl . '/users/{publicKey}/images/{imageIdentifier}/shorturls', 'shortImageUrl' => $baseUrl . '/users/{publicKey}/images/{imageIdentifier}/shorturls/{id}')));
     $response->setModel($model);
     // Prevent caching
     $response->setMaxAge(0)->setPrivate();
     $response->headers->addCacheControlDirective('no-store');
 }
Пример #4
0
 /**
  * Delete a single short URL
  *
  * @param EventInterface $event
  */
 public function deleteShortUrl(EventInterface $event)
 {
     $database = $event->getDatabase();
     $request = $event->getRequest();
     $publicKey = $request->getPublicKey();
     $imageIdentifier = $request->getImageIdentifier();
     $shortUrlId = $request->getRoute()->get('shortUrlId');
     if (!($params = $database->getShortUrlParams($shortUrlId))) {
         throw new ResourceException('ShortURL not found', 404);
     }
     if ($params['publicKey'] !== $publicKey || $params['imageIdentifier'] !== $imageIdentifier) {
         throw new ResourceException('ShortURL not found', 404);
     }
     $database->deleteShortUrls($publicKey, $imageIdentifier, $shortUrlId);
     $model = new ArrayModel();
     $model->setData(array('id' => $shortUrlId));
     $event->getResponse()->setModel($model);
 }
Пример #5
0
 /**
  * @covers Imbo\Model\ArrayModel::setTitle
  * @covers Imbo\Model\ArrayModel::getTitle
  */
 public function testCanSetAndGetTitle()
 {
     $this->assertNull($this->model->getTitle());
     $this->assertSame($this->model, $this->model->setTitle('title'));
     $this->assertSame('title', $this->model->getTitle());
 }
Пример #6
0
Файл: XML.php Проект: ASP96/imbo
    /**
     * {@inheritdoc}
     */
    public function formatArrayModel(Model\ArrayModel $model)
    {
        $data = $this->formatArray($model->getData());
        return <<<DATA
<?xml version="1.0" encoding="UTF-8"?>
<imbo>{$data}</imbo>
DATA;
    }
Пример #7
0
 /**
  * Delete all short URLs for a given image
  *
  * @param EventInterface $event
  */
 public function deleteImageShortUrls(EventInterface $event)
 {
     $request = $event->getRequest();
     $publicKey = $request->getPublicKey();
     $imageIdentifier = $request->getImageIdentifier();
     $event->getDatabase()->deleteShortUrls($publicKey, $imageIdentifier);
     if ($event->getName() === 'shorturls.delete') {
         // If the request is against the shorturls resource directly we need to supply a
         // response model. If this method is triggered because of an image has been deleted
         // the image resource will supply the response model
         $model = new ArrayModel();
         $model->setData(array('imageIdentifier' => $imageIdentifier));
         $event->getResponse()->setModel($model);
     }
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function formatArrayModel(Model\ArrayModel $model)
 {
     return $this->encode($model->getData() ?: new stdClass());
 }