|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright 2011 Johannes M. Schmitt <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace JMS\TwigJsBundle\Controller; |
|
20
|
|
|
|
|
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
25
|
|
|
use TwigJs\CompileRequest; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Demo Compilation Controller. |
|
29
|
|
|
* |
|
30
|
|
|
* The preferred way of integrating twig.js is by using Assetic with the |
|
31
|
|
|
* "twig_js" filter. However, if you need to customize your integration, |
|
32
|
|
|
* this controller gives you a good starting point. |
|
33
|
|
|
* |
|
34
|
|
|
* It is not recommended to use this in production as the passed template |
|
35
|
|
|
* name is not validated, and thus, any templates could be rendered. |
|
36
|
|
|
* |
|
37
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
|
38
|
|
|
*/ |
|
39
|
|
|
class DemoCompilationController implements ContainerAwareInterface |
|
40
|
|
|
{ |
|
41
|
|
|
use ContainerAwareTrait; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param Request $request |
|
45
|
|
|
* @return Response |
|
46
|
|
|
* @throws \Exception |
|
47
|
|
|
*/ |
|
48
|
|
|
public function compileAction(Request $request) |
|
49
|
|
|
{ |
|
50
|
|
|
$compileRequest = new CompileRequest($request->query->get('name'), null); |
|
51
|
|
|
|
|
52
|
|
|
return new Response( |
|
53
|
|
|
$this->container->get('twig_js.compile_request_handler') |
|
54
|
|
|
->process($compileRequest), |
|
55
|
|
|
200, |
|
56
|
|
|
array('Content-Type' => 'application/javascript') |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|