当前位置: 首页>>代码示例>>PHP>>正文


PHP EventInterface::getResponse方法代码示例

本文整理汇总了PHP中Imbo\EventManager\EventInterface::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP EventInterface::getResponse方法的具体用法?PHP EventInterface::getResponse怎么用?PHP EventInterface::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Imbo\EventManager\EventInterface的用法示例。


在下文中一共展示了EventInterface::getResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setHeaders

 /**
  * Right before the response is sent to the client, check if any HTTP cache control headers
  * have explicity been set for this response. If not, apply the configured defaults.
  *
  * @param EventInterface $event The event instance
  */
 public function setHeaders(EventInterface $event)
 {
     $method = $event->getRequest()->getMethod();
     // Obviously we shouldn't bother doing any HTTP caching logic for non-GET/HEAD requests
     if ($method !== 'GET' && $method !== 'HEAD') {
         return;
     }
     $response = $event->getResponse();
     $headers = $event->getResponse()->headers;
     // Imbo defaults to 'public' as cache-control value - if it has changed from this value,
     // assume the resource requested has explicitly defined its own caching rules and fall back
     if ($headers->get('Cache-Control') !== 'public') {
         return;
     }
     // Get configured HTTP cache defaults from configuration, then apply them
     $config = $event->getConfig()['httpCacheHeaders'];
     if (isset($config['maxAge'])) {
         $response->setMaxAge((int) $config['maxAge']);
     }
     if (isset($config['sharedMaxAge'])) {
         $response->setSharedMaxAge($config['sharedMaxAge']);
     }
     if (isset($config['public']) && $config['public']) {
         $response->setPublic();
     } else {
         if (isset($config['public'])) {
             $response->setPrivate();
         }
     }
     if (isset($config['mustRevalidate']) && $config['mustRevalidate']) {
         $headers->addCacheControlDirective('must-revalidate');
     }
 }
开发者ID:imbo,项目名称:imbo,代码行数:39,代码来源:HttpCache.php

示例2: addGroup

 /**
  * Add resources to a group
  *
  * @param EventInterface $event The current event
  */
 public function addGroup(EventInterface $event)
 {
     $accessControl = $event->getAccessControl();
     if (!$accessControl instanceof MutableAdapterInterface) {
         throw new ResourceException('Access control adapter is immutable', 405);
     }
     $request = $event->getRequest();
     $route = $request->getRoute();
     $groupName = $route->get('group');
     $group = $accessControl->getGroup($groupName);
     $groupExists = !empty($group);
     $resources = json_decode($request->getContent(), true);
     if (!is_array($resources)) {
         throw new ResourceException('Invalid data. Array of resource strings is expected', 400);
     }
     foreach ($resources as $resource) {
         if (!is_string($resource)) {
             throw new ResourceException('Invalid value in the resources array. Only strings are allowed', 400);
         }
     }
     if ($groupExists) {
         $accessControl->updateResourceGroup($groupName, $resources);
     } else {
         $accessControl->addResourceGroup($groupName, $resources);
     }
     $response = $event->getResponse();
     $response->setStatusCode($groupExists ? 200 : 201);
 }
开发者ID:imbo,项目名称:imbo,代码行数:33,代码来源:Group.php

示例3: get

 /**
  * Handle GET requests
  *
  * @param EventInterface $event The current event
  */
 public function get(EventInterface $event)
 {
     $response = $event->getResponse();
     $response->setMaxAge(0)->setPrivate();
     $response->headers->addCacheControlDirective('no-store');
     $event->getManager()->trigger('db.stats.load');
 }
开发者ID:ASP96,项目名称:imbo,代码行数:12,代码来源:Stats.php

示例4: transform

 /**
  * Transform images
  *
  * @param EventInterface $event The current event
  */
 public function transform(EventInterface $event)
 {
     $request = $event->getRequest();
     $image = $event->getResponse()->getModel();
     $eventManager = $event->getManager();
     $presets = $event->getConfig()['transformationPresets'];
     // Fetch transformations specifed in the query and transform the image
     foreach ($request->getTransformations() as $transformation) {
         if (isset($presets[$transformation['name']])) {
             // Preset
             foreach ($presets[$transformation['name']] as $name => $params) {
                 if (is_int($name)) {
                     // No hardcoded params, use the ones from the request
                     $name = $params;
                     $params = $transformation['params'];
                 } else {
                     // Some hardcoded params. Merge with the ones from the request, making the
                     // hardcoded params overwrite the ones from the request
                     $params = array_replace($transformation['params'], $params);
                 }
                 $eventManager->trigger('image.transformation.' . strtolower($name), array('image' => $image, 'params' => $params));
             }
         } else {
             // Regular transformation
             $eventManager->trigger('image.transformation.' . strtolower($transformation['name']), array('image' => $image, 'params' => $transformation['params']));
         }
     }
 }
开发者ID:sgulseth,项目名称:imbo,代码行数:33,代码来源:ImageTransformer.php

示例5: get

 /**
  * Handle GET requests
  *
  * @param EventInterface $event The current event
  */
 public function get(EventInterface $event)
 {
     $response = $event->getResponse();
     $database = $event->getDatabase();
     $storage = $event->getStorage();
     $databaseStatus = $database->getStatus();
     $storageStatus = $storage->getStatus();
     if (!$databaseStatus || !$storageStatus) {
         if (!$databaseStatus && !$storageStatus) {
             $message = 'Database and storage error';
         } else {
             if (!$storageStatus) {
                 $message = 'Storage error';
             } else {
                 $message = 'Database error';
             }
         }
         $response->setStatusCode(503, $message);
     }
     $response->setMaxAge(0)->setPrivate();
     $response->headers->addCacheControlDirective('no-store');
     $statusModel = new Model\Status();
     $statusModel->setDate(new DateTime('now', new DateTimeZone('UTC')))->setDatabaseStatus($databaseStatus)->setStorageStatus($storageStatus);
     $response->setModel($statusModel);
 }
开发者ID:ASP96,项目名称:imbo,代码行数:30,代码来源:Status.php

示例6: send

 /**
  * Send the response
  *
  * @param EventInterface $event The current event
  */
 public function send(EventInterface $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     // Vary on public key header. Public key specified in query and URL path doesn't have to be
     // taken into consideration, since they will have varying URLs
     $response->setVary('X-Imbo-PublicKey', false);
     // Optionally mark this response as not modified
     $response->isNotModified($request);
     // Inject a possible image identifier into the response headers
     $imageIdentifier = null;
     if ($image = $request->getImage()) {
         // The request has an image. This means that an image was just added.
         // Get the image identifier from the image model
         $imageIdentifier = $image->getImageIdentifier();
     } else {
         if ($identifier = $request->getImageIdentifier()) {
             // An image identifier exists in the request URI, use that
             $imageIdentifier = $identifier;
         }
     }
     if ($imageIdentifier) {
         $response->headers->set('X-Imbo-ImageIdentifier', $imageIdentifier);
     }
     $response->send();
 }
开发者ID:imbo,项目名称:imbo,代码行数:31,代码来源:ResponseSender.php

示例7: checkAccessToken

 /**
  * {@inheritdoc}
  */
 public function checkAccessToken(EventInterface $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $query = $request->query;
     $eventName = $event->getName();
     if (($eventName === 'image.get' || $eventName === 'image.head') && $this->isWhitelisted($request)) {
         // All transformations in the request are whitelisted. Skip the access token check
         return;
     }
     // If the response has a short URL header, we can skip the access token check
     if ($response->headers->has('X-Imbo-ShortUrl')) {
         return;
     }
     if (!$query->has('accessToken')) {
         throw new RuntimeException('Missing access token', 400);
     }
     $token = $query->get('accessToken');
     // First the the raw un-encoded URI, then the URI as is
     $uris = array($request->getRawUri(), $request->getUriAsIs());
     $privateKeys = $event->getUserLookup()->getPrivateKeys($request->getPublicKey()) ?: [];
     foreach ($uris as $uri) {
         // Remove the access token from the query string as it's not used to generate the HMAC
         $uri = rtrim(preg_replace('/(?<=(\\?|&))accessToken=[^&]+&?/', '', $uri), '&?');
         foreach ($privateKeys as $privateKey) {
             $correctToken = hash_hmac('sha256', $uri, $privateKey);
             if ($correctToken === $token) {
                 return;
             }
         }
     }
     throw new RuntimeException('Incorrect access token', 400);
 }
开发者ID:ASP96,项目名称:imbo,代码行数:36,代码来源:AccessToken.php

示例8: chooseVariation

 /**
  * Choose an image variation based on the transformations and the original size of the image
  *
  * @param EventInterface $event The current event
  */
 public function chooseVariation(EventInterface $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $publicKey = $request->getPublicKey();
     $imageIdentifier = $request->getImageIdentifier();
     // Fetch the original width / height of the image to use for ratio calculations
     $image = $response->getModel();
     $imageWidth = $image->getWidth();
     $imageHeight = $image->getHeight();
     // Fetch the transformations from the request and find the max width used in the set
     $transformations = $request->getTransformations();
     if (!$transformations) {
         // No transformations in the request
         return;
     }
     $maxWidth = $this->getMaxWidth($imageWidth, $imageHeight, $transformations);
     if (!$maxWidth) {
         // No need to use a variation based on the set of transformations
         return;
     }
     // Fetch the index of the transformation that decided the max width, and the width itself
     list($transformationIndex, $maxWidth) = each($maxWidth);
     if ($maxWidth >= $imageWidth) {
         // The width is the same or above the original, use the original
         return;
     }
     // WE HAVE A WINNER! Find the best variation. The width of the variation is the first
     // available one above the $maxWidth value
     $variation = $this->database->getBestMatch($publicKey, $imageIdentifier, $maxWidth);
     if (!$variation) {
         // Could not find any :(
         return;
     }
     // Now that we have a variation we can use we need to adjust some of the transformation
     // parameters.
     $event->getManager()->trigger('image.transformations.adjust', ['transformationIndex' => $transformationIndex, 'ratio' => $imageWidth / $variation['width']]);
     // Fetch the image variation blob from the storage adapter
     $imageBlob = $this->storage->getImageVariation($publicKey, $imageIdentifier, $variation['width']);
     if (!$imageBlob) {
         // The image blob does not exist in the storage, which it should. Trigger an error and
         // return
         trigger_error('Image variation storage is not in sync with the image variation database', E_USER_WARNING);
         return;
     }
     // Set some data that the storage operations listener usually sets, since that will be
     // skipped since we have an image variation
     $lastModified = $event->getStorage()->getLastModified($publicKey, $imageIdentifier);
     $response->setLastModified($lastModified);
     // Update the model
     $model = $response->getModel();
     $model->setBlob($imageBlob)->setWidth($variation['width'])->setHeight($variation['height']);
     // Set a HTTP header that informs the user agent on which image variation that was used in
     // the transformations
     $response->headers->set('X-Imbo-ImageVariation', $variation['width'] . 'x' . $variation['height']);
     // Stop the propagation of this event
     $event->stopPropagation();
     $event->getManager()->trigger('image.loaded');
 }
开发者ID:ASP96,项目名称:imbo,代码行数:64,代码来源:ImageVariations.php

示例9: post

 /**
  * Handle POST requests
  *
  * @param EventInterface $event The current event
  */
 public function post(EventInterface $event)
 {
     $request = $event->getRequest();
     $event->getManager()->trigger('db.metadata.update', ['metadata' => json_decode($request->getContent(), true)]);
     $model = new Model\Metadata();
     $model->setData($event->getDatabase()->getMetadata($request->getUser(), $request->getImageIdentifier()));
     $event->getResponse()->setModel($model);
 }
开发者ID:imbo,项目名称:imbo,代码行数:13,代码来源:Metadata.php

示例10: addHeader

 /**
  * Add the HashTwo header to the response
  *
  * @param EventInterface $event The current event
  */
 public function addHeader(EventInterface $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $user = $request->getUser();
     $imageIdentifier = $response->getModel()->getImageIdentifier();
     $response->headers->set($this->header, ['imbo;image;' . $user . ';' . $imageIdentifier, 'imbo;user;' . $user]);
 }
开发者ID:imbo,项目名称:imbo,代码行数:13,代码来源:VarnishHashTwo.php

示例11: addHeader

 /**
  * Add the HashTwo header to the response
  *
  * @param EventInterface $event The current event
  */
 public function addHeader(EventInterface $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $publicKey = $request->getPublicKey();
     $imageIdentifier = $response->getModel()->getImageIdentifier();
     $response->headers->set($this->header, array('imbo;image;' . $publicKey . ';' . $imageIdentifier, 'imbo;user;' . $publicKey));
 }
开发者ID:ASP96,项目名称:imbo,代码行数:13,代码来源:VarnishHashTwo.php

示例12: get

 public function get(EventInterface $event)
 {
     $model = new ListModel();
     $model->setContainer('foo');
     $model->setEntry('bar');
     $model->setList([1, 2, 3]);
     $event->getResponse()->setModel($model);
 }
开发者ID:imbo,项目名称:imbo,代码行数:8,代码来源:access-control.php

示例13: addImage

 /**
  * 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);
 }
开发者ID:imbo,项目名称:imbo,代码行数:16,代码来源:Images.php

示例14: get

 /**
  * 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');
 }
开发者ID:ASP96,项目名称:imbo,代码行数:18,代码来源:Index.php

示例15: checkAccessToken

 /**
  * {@inheritdoc}
  */
 public function checkAccessToken(EventInterface $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $query = $request->query;
     $eventName = $event->getName();
     $config = $event->getConfig();
     if (($eventName === 'image.get' || $eventName === 'image.head') && $this->isWhitelisted($request)) {
         // All transformations in the request are whitelisted. Skip the access token check
         return;
     }
     // If the response has a short URL header, we can skip the access token check
     if ($response->headers->has('X-Imbo-ShortUrl')) {
         return;
     }
     if (!$query->has('accessToken')) {
         throw new RuntimeException('Missing access token', 400);
     }
     $token = $query->get('accessToken');
     // First the the raw un-encoded URI, then the URI as is
     $uris = [$request->getRawUri(), $request->getUriAsIs()];
     $privateKey = $event->getAccessControl()->getPrivateKey($request->getPublicKey());
     // append uris with [] expanded or [0] reduced
     $uris[] = $this->getUnescapedAlternativeURL($request->getRawUri());
     $uris[] = $this->getEscapedAlternativeURL($request->getRawUri());
     // See if we should modify the protocol for the incoming request
     $protocol = $config['authentication']['protocol'];
     if ($protocol === 'both') {
         $uris = array_reduce($uris, function ($dest, $uri) {
             $baseUrl = preg_replace('#^https?#', '', $uri);
             $dest[] = 'http' . $baseUrl;
             $dest[] = 'https' . $baseUrl;
             return $dest;
         }, []);
     } else {
         if (in_array($protocol, ['http', 'https'])) {
             $uris = array_map(function ($uri) use($protocol) {
                 return preg_replace('#^https?#', $protocol, $uri);
             }, $uris);
         }
     }
     foreach ($uris as $uri) {
         // Remove the access token from the query string as it's not used to generate the HMAC
         $uri = rtrim(preg_replace('/(?<=(\\?|&))accessToken=[^&]+&?/', '', $uri), '&?');
         $correctToken = hash_hmac('sha256', $uri, $privateKey);
         if ($correctToken === $token) {
             return;
         }
     }
     throw new RuntimeException('Incorrect access token', 400);
 }
开发者ID:imbo,项目名称:imbo,代码行数:54,代码来源:AccessToken.php


注:本文中的Imbo\EventManager\EventInterface::getResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。