本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::isOk方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::isOk方法的具体用法?PHP Response::isOk怎么用?PHP Response::isOk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::isOk方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleResponse
/**
* Update a valid non cacheable Response with http cache headers
*
* @see http://symfony.com/fr/doc/current/book/http_cache.html
*/
public function handleResponse(Response $response)
{
// do not handle invalid response
if (!$response->isOk()) {
return $response;
}
// do not handle response with http cache headers
if ($response->isCacheable()) {
return $response;
}
// seek for optional configuration
$this->readRoutingConfiguration();
// mark the response as private
$response->setPrivate();
// set the private or shared max age
$response->setMaxAge($this->duration);
$response->setSharedMaxAge($this->duration);
// set expires
$date = new \DateTime();
$date->modify(sprintf('+%d seconds', $this->duration));
$response->setExpires($date);
// set a custom Cache-Control directive
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}
示例2: setDetails
/**
* Parses the requested route to fetch
* - the resource (databox, basket, record etc ..)
* - general action (list, add, search)
* - the action (setstatus, setname etc..)
* - the aspect (collections, related, content etc..)
*
* @param ApiLog $log
* @param Request $request
* @param Response $response
*/
private function setDetails(ApiLog $log, Request $request, Response $response)
{
$chunks = explode('/', trim($request->getPathInfo(), '/'));
if (false === $response->isOk() || sizeof($chunks) === 0) {
return;
}
switch ($chunks[0]) {
case ApiLog::DATABOXES_RESOURCE:
$this->hydrateDataboxes($log, $chunks);
break;
case ApiLog::RECORDS_RESOURCE:
$this->hydrateRecords($log, $chunks);
break;
case ApiLog::BASKETS_RESOURCE:
$this->hydrateBaskets($log, $chunks);
break;
case ApiLog::FEEDS_RESOURCE:
$this->hydrateFeeds($log, $chunks);
break;
case ApiLog::QUARANTINE_RESOURCE:
$this->hydrateQuarantine($log, $chunks);
break;
case ApiLog::STORIES_RESOURCE:
$this->hydrateStories($log, $chunks);
break;
case ApiLog::MONITOR_RESOURCE:
$this->hydrateMonitor($log, $chunks);
break;
}
}
示例3: after
public function after(Request $request, Response $response)
{
$now = new \DateTime("now");
$mapper = new CacheRecordSQLMapper($this->app["db"]);
$currentRouteName = $request->attributes->get("_route");
if ($this->isCacheCompromiser($currentRouteName)) {
/** @todo method check */
$mapper = new CacheRecordSQLMapper($this->app["db"]);
$compromisedCount = $mapper->compromiseAll();
return;
}
if ($this->isRouteCacheable($currentRouteName) && $response->isOk()) {
$cacheRecord = $mapper->findByUri($this->getCurrentUri());
if (!$cacheRecord) {
// $this->createCacheRecord();
$data = [];
$data["uri"] = $this->getCurrentUri();
$data["hash"] = md5($response->getContent());
$data["lmt"] = $now->format("Y-m-d H:i:s");
$cacheRecord = new CacheRecord($data);
$mapper->create($cacheRecord);
$response->setPublic();
$response->setDate($now);
$response->setMaxAge($this->config->getMaxAge());
$response->setSharedMaxAge($this->config->getMaxAgeShared());
$response->setLastModified($now);
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}
if ($cacheRecord->getCompromised()) {
if ($cacheRecord->getHash() === md5($response->getContent())) {
$cacheRecord->setCompromised(false);
$mapper->update($cacheRecord->getId(), $cacheRecord);
$response = $this->createResponse($cacheRecord->getLmt());
$response->setNotModified();
return $response;
} else {
$cacheRecord->setCompromised(false);
$cacheRecord->setHash(md5($response->getContent()));
$cacheRecord->setLmt(date("Y-m-d H:i:s"));
$mapper->update($cacheRecord->getId(), $cacheRecord);
return $response;
}
} else {
$now = new \DateTime("2015-12-12");
$response->setPublic();
$response->setDate($now);
$response->setMaxAge($this->config->getMaxAge());
$response->setSharedMaxAge($this->config->getMaxAgeShared() + 1);
$response->setLastModified(new \DateTime($cacheRecord->getLmt()));
return $response;
}
}
}
示例4: afterRead
public static function afterRead(Request $request, Response $response, Application $app)
{
if ($response->isOk()) {
$token = self::getCacheToken($request, $app);
if (!$app['cache']->contains($token)) {
if (self::isFileListRequest($request)) {
$minutes = $app['config']->getMinutesCachingFileListings();
} else {
$minutes = $app['config']->getMinutesCachingData();
}
$app['cache']->save($token, $response->getContent(), $minutes * 60);
}
}
}
示例5: processResponse
/**
* {@inheritdoc}
*/
public function processResponse(Request $request, Response $response)
{
if (!$response->isOk()) {
return;
}
$cacheKey = $request->attributes->get('_cacheKey');
$ttl = $request->attributes->get('_cacheTTL');
if (empty($cacheKey)) {
return;
}
$cache = $this->getCache();
$this->info(sprintf('miss: save into cache: %s', $cacheKey), ['application' => 'cache', 'type' => 'miss', 'cacheKey' => $cacheKey, 'ttl' => $ttl]);
$item = $cache->getItem($cacheKey);
$item->set($response);
$item->expiresAfter($ttl);
$cache->save($item);
$response->headers->set('X-Cache', 'miss');
$response->setMaxAge($ttl);
$response->setExpires(new DateTime(sprintf('+%d seconds', $ttl)));
}
示例6: testIsOk
public function testIsOk()
{
$response = new Response('', 200);
$this->assertTrue($response->isOk());
$response = new Response('', 404);
$this->assertFalse($response->isOk());
}
示例7: assertResponseOk
private function assertResponseOk(Response $response)
{
$this->assertTrue($response->isOk());
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
}