1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Frameworkless\Controllers; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Response; |
6
|
|
|
use Twig_Environment; |
7
|
|
|
use Core\Models\User\UserRepository; |
8
|
|
|
use DebugBar\StandardDebugBar; |
9
|
|
|
use Frameworkless\Helpers\Debug; |
10
|
|
|
use Monolog\Logger; |
11
|
|
|
|
12
|
|
|
class IndexController |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var Twig_Environment |
17
|
|
|
*/ |
18
|
|
|
private $twig; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* |
22
|
|
|
* @var \Models\User\UserRepository $UserRepository |
23
|
|
|
*/ |
24
|
|
|
protected $UserRepository; |
25
|
|
|
|
26
|
|
|
protected $debugbar; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* IndexController, constructed by container |
30
|
|
|
* |
31
|
|
|
* @param Twig_Environment $twig |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
Twig_Environment $twig, UserRepository $UserRepository, StandardDebugBar $debugbar, Logger $logger |
35
|
|
|
) |
36
|
|
|
{ |
37
|
|
|
$this->twig = $twig; |
38
|
|
|
$this->UserRepository = $UserRepository; |
|
|
|
|
39
|
|
|
$this->debugbar = $debugbar; |
40
|
|
|
|
41
|
|
|
$logger->addDebug('start work', [1, 2, 'test']); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Return index page (/) |
46
|
|
|
* |
47
|
|
|
* @param array $args |
48
|
|
|
* @return Response |
49
|
|
|
*/ |
50
|
|
|
public function get($args) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar"); |
53
|
|
|
|
54
|
|
|
$Users = $this->UserRepository->findMany(); |
55
|
|
|
|
56
|
|
|
$table = \Donquixote\Cellbrush\Table\Table::create(); |
57
|
|
|
$table->addColNames([0, 1, 2]); |
58
|
|
|
$table->addClass('table table-striped'); |
59
|
|
|
$table->thead() |
60
|
|
|
->addRowName('head row') |
61
|
|
|
->th('head row', 0, 'Id') |
62
|
|
|
->th('head row', 1, 'Имя') |
63
|
|
|
->th('head row', 2, 'Email'); |
64
|
|
|
$i = 0; |
65
|
|
|
foreach ($Users as $User) { |
66
|
|
|
$table->addRow($i)->tdMultiple([ |
67
|
|
|
$User->getId(), |
68
|
|
|
$User->getName(), |
69
|
|
|
$User->getEmail()]); |
70
|
|
|
$i++; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return new Response($this->twig->render('pages/index.html.twig', [ |
74
|
|
|
"table" => $table->render(), |
75
|
|
|
"debugbar_Head" => $debugbarRenderer->renderHead(), |
76
|
|
|
"debugbar_Body" => $debugbarRenderer->render() |
77
|
|
|
])); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function add($args) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
try { |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
|
88
|
|
|
|
89
|
|
|
return new Response("success create!"); |
90
|
|
|
|
91
|
|
|
} catch(\Exception $ex) { |
92
|
|
|
return new Response("system error:" . $ex->getMessage()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..