first commit
This commit is contained in:
101
bundles/KupShop/ContentBundle/View/Error404View.php
Normal file
101
bundles/KupShop/ContentBundle/View/Error404View.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ondra
|
||||
* Date: 11.10.17
|
||||
* Time: 8:00.
|
||||
*/
|
||||
|
||||
namespace KupShop\ContentBundle\View;
|
||||
|
||||
use KupShop\ComponentsBundle\View\ComponentsViewInterface;
|
||||
use KupShop\ComponentsBundle\View\ComponentsViewTrait;
|
||||
use KupShop\KupShopBundle\Context\CacheContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\KupShopBundle\Util\Contexts;
|
||||
use KupShop\KupShopBundle\Views\Traits\RequestTrait;
|
||||
use KupShop\KupShopBundle\Views\View;
|
||||
use KupShop\ResponseCacheBundle\Util\Cache\ResponseCache;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class Error404View extends View implements ComponentsViewInterface
|
||||
{
|
||||
use RequestTrait;
|
||||
use ComponentsViewTrait;
|
||||
|
||||
protected $template = 'error404.tpl';
|
||||
|
||||
private $search;
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return translate('title', 'error404');
|
||||
}
|
||||
|
||||
public function getBodyVariables()
|
||||
{
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
|
||||
$vars = parent::getBodyVariables();
|
||||
|
||||
$vars['search'] = $this->getSearchString();
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
public function getSearchString()
|
||||
{
|
||||
// Když cachujeme, nemůže být nic nastavený v searchi
|
||||
if (findModule(\Modules::RESPONSE_CACHE)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$search = strtr($this->search, ['/' => ' ', '-' => ' ']);
|
||||
$search = preg_replace('/((_k|_z)\d+)/', '', $search);
|
||||
|
||||
return urlencode(trim($search));
|
||||
}
|
||||
|
||||
public function setUrl($search)
|
||||
{
|
||||
$this->search = $search;
|
||||
}
|
||||
|
||||
public function getResponse(?Request $request = null)
|
||||
{
|
||||
if (findModule(\Modules::RESPONSE_CACHE)) {
|
||||
$responseCache = ServiceContainer::getService(ResponseCache::class);
|
||||
|
||||
$cacheEnabled = !getAdminUser();
|
||||
$isHit = false;
|
||||
|
||||
$cacheContext = Contexts::get(CacheContext::class);
|
||||
$cacheKeyContext = $cacheContext->getKey([CacheContext::TYPE_FULL_PAGE, CacheContext::TYPE_PRICE, CacheContext::TYPE_TEXT]);
|
||||
|
||||
if (is_null($cacheKeyContext)) {
|
||||
$cacheEnabled = false;
|
||||
}
|
||||
|
||||
if ($cacheEnabled) {
|
||||
$this->responseCacheEnabled = true;
|
||||
|
||||
$cacheKey = [
|
||||
'404',
|
||||
$cacheKeyContext,
|
||||
];
|
||||
$cacheKey = join('-', $cacheKey);
|
||||
|
||||
$response = $responseCache->wrap(function () use ($request) {
|
||||
return parent::getResponse($request);
|
||||
}, $cacheKey, 15 * 60, null, $isHit);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($response)) {
|
||||
$response = parent::getResponse($request);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user