|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MewesK\TwigExcelBundle\Tests\Fixtures\TestBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
7
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class DefaultController |
|
11
|
|
|
* |
|
12
|
|
|
* @package MewesK\TwigExcelBundle\Tests\Fixtures\TestBundle\Controller |
|
13
|
|
|
*/ |
|
14
|
|
|
class DefaultController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @param $templateName |
|
18
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
19
|
|
|
* |
|
20
|
|
|
* @Route("/default/{templateName}.{_format}", name="test_default", defaults={"templateName" = "simple", "_format" = "xlsx"}) |
|
21
|
|
|
*/ |
|
22
|
|
|
public function defaultAction($templateName) |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->render( |
|
25
|
|
|
'@Test/Default/' . $templateName . '.twig', |
|
26
|
|
|
[ |
|
27
|
|
|
'data' => [ |
|
28
|
|
|
['name' => 'Everette Grim', 'salary' => 5458.0], |
|
29
|
|
|
['name' => 'Nam Poirrier', 'salary' => 3233.0], |
|
30
|
|
|
['name' => 'Jolynn Ell', 'salary' => 5718.0], |
|
31
|
|
|
['name' => 'Ta Burdette', 'salary' => 1255.0], |
|
32
|
|
|
['name' => 'Aida Salvas', 'salary' => 5226.0], |
|
33
|
|
|
['name' => 'Gilbert Navarrette', 'salary' => 1431.0], |
|
34
|
|
|
['name' => 'Kirk Figgins', 'salary' => 7429.0], |
|
35
|
|
|
['name' => 'Rashad Cloutier', 'salary' => 8457.0], |
|
36
|
|
|
['name' => 'Traci Schmitmeyer', 'salary' => 7521.0], |
|
37
|
|
|
['name' => 'Cecila Statham', 'salary' => 7180.0], |
|
38
|
|
|
['name' => 'Chong Robicheaux', 'salary' => 3511.0], |
|
39
|
|
|
['name' => 'Romona Stockstill', 'salary' => 2943.0], |
|
40
|
|
|
['name' => 'Roseann Sather', 'salary' => 9126.0], |
|
41
|
|
|
['name' => 'Vera Racette', 'salary' => 4566.0], |
|
42
|
|
|
['name' => 'Tennille Waltripv', 'salary' => 4485.0], |
|
43
|
|
|
['name' => 'Dot Hedgpeth', 'salary' => 7687.0], |
|
44
|
|
|
['name' => 'Thersa Havis', 'salary' => 2264.0], |
|
45
|
|
|
['name' => 'Long Kenner', 'salary' => 4051.0], |
|
46
|
|
|
['name' => 'Kena Kea', 'salary' => 4090.0], |
|
47
|
|
|
['name' => 'Evita Chittum', 'salary' => 4639.0] |
|
48
|
|
|
], |
|
49
|
|
|
'kernelPath' => $this->get('kernel')->getRootDir() |
|
50
|
|
|
] |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param $templateName |
|
56
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
57
|
|
|
* @throws \InvalidArgumentException |
|
58
|
|
|
* |
|
59
|
|
|
* @Route("/custom-response/{templateName}.{_format}", name="test_custom_response", defaults={"templateName" = "simple", "_format" = "xlsx"}) |
|
60
|
|
|
*/ |
|
61
|
|
|
public function customResponseAction($templateName) |
|
62
|
|
|
{ |
|
63
|
|
|
$response = new Response( |
|
64
|
|
|
$this->render( |
|
65
|
|
|
'@Test/Default/' . $templateName . '.twig', |
|
66
|
|
|
[ |
|
67
|
|
|
'data' => [ |
|
68
|
|
|
['name' => 'Everette Grim', 'salary' => 5458.0], |
|
69
|
|
|
['name' => 'Nam Poirrier', 'salary' => 3233.0], |
|
70
|
|
|
['name' => 'Jolynn Ell', 'salary' => 5718.0] |
|
71
|
|
|
] |
|
72
|
|
|
] |
|
73
|
|
|
), |
|
74
|
|
|
Response::HTTP_OK, |
|
75
|
|
|
[ |
|
76
|
|
|
'Content-Disposition' => 'attachment; filename="foobar.bin"' |
|
77
|
|
|
] |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
$response->setPrivate(); |
|
81
|
|
|
$response->setMaxAge(600); |
|
82
|
|
|
|
|
83
|
|
|
return $response; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|