2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-02-17 13:55:05 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerAware;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
2010-02-17 13:55:05 +00:00
|
|
|
/**
|
2010-04-07 02:07:59 +01:00
|
|
|
* TemplateController.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:55:05 +00:00
|
|
|
*/
|
2010-08-30 06:26:19 +01:00
|
|
|
class TemplateController extends ContainerAware
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-08-14 21:03:02 +01:00
|
|
|
/**
|
|
|
|
* Renders a template.
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param string $template The template name
|
|
|
|
* @param int|null $maxAge Max age for client caching
|
|
|
|
* @param int|null $sharedAge Max age for shared (proxy) caching
|
|
|
|
* @param bool|null $private Whether or not caching should apply for client caches only
|
2010-08-14 21:03:02 +01:00
|
|
|
*
|
|
|
|
* @return Response A Response instance
|
|
|
|
*/
|
2012-11-21 20:00:39 +00:00
|
|
|
public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2012-11-21 20:00:39 +00:00
|
|
|
/** @var $response \Symfony\Component\HttpFoundation\Response */
|
|
|
|
$response = $this->container->get('templating')->renderResponse($template);
|
2012-12-06 08:58:41 +00:00
|
|
|
|
2012-11-21 20:00:39 +00:00
|
|
|
if ($maxAge) {
|
|
|
|
$response->setMaxAge($maxAge);
|
|
|
|
}
|
2012-12-06 08:58:41 +00:00
|
|
|
|
2012-11-21 20:00:39 +00:00
|
|
|
if ($sharedAge) {
|
|
|
|
$response->setSharedMaxAge($sharedAge);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($private) {
|
|
|
|
$response->setPrivate();
|
2012-12-06 08:58:41 +00:00
|
|
|
} elseif ($private === false || (null === $private && ($maxAge || $sharedAge))) {
|
2012-11-21 20:00:39 +00:00
|
|
|
$response->setPublic($private);
|
|
|
|
}
|
2012-12-06 08:58:41 +00:00
|
|
|
|
2012-11-21 20:00:39 +00:00
|
|
|
return $response;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|