Files
Phraseanet/lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php
2013-06-17 17:01:35 +02:00

51 lines
1.5 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class MustacheLoader implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->get('/', function(Application $app, Request $request) {
$template_name = $request->query->get('template');
if (!preg_match('/^[a-zA-Z0-9-_]+$/', $template_name)) {
throw new BadRequestHttpException('Wrong template name : ' . $template_name);
}
$template_path = realpath(__DIR__ . '/../../../../../templates/web/Mustache/Prod/' . $template_name . '.Mustache.html');
if (!file_exists($template_path)) {
throw new NotFoundHttpException('Template does not exists : ' . $template_path);
}
return new \Symfony\Component\HttpFoundation\Response(file_get_contents($template_path));
});
return $controllers;
}
}