These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\AdminBundle\Controller; |
||
15 | |||
16 | // NEXT_MAJOR: remove this file |
||
17 | |||
18 | @trigger_error( |
||
0 ignored issues
–
show
|
|||
19 | 'The '.__NAMESPACE__.'\CoreController class is deprecated since version 3.36 and will be removed in 4.0.' |
||
20 | .' Use '.__NAMESPACE__.'\SearchAction or '.__NAMESPACE__.'\DashboardAction instead.', |
||
21 | E_USER_DEPRECATED |
||
22 | ); |
||
23 | |||
24 | use Sonata\AdminBundle\Action\DashboardAction; |
||
25 | use Sonata\AdminBundle\Action\SearchAction; |
||
26 | use Sonata\AdminBundle\Admin\Pool; |
||
27 | use Sonata\AdminBundle\Search\SearchHandler; |
||
28 | use Sonata\AdminBundle\Templating\TemplateRegistryInterface; |
||
29 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
30 | use Symfony\Component\HttpFoundation\JsonResponse; |
||
31 | use Symfony\Component\HttpFoundation\Request; |
||
32 | use Symfony\Component\HttpFoundation\Response; |
||
33 | |||
34 | /** |
||
35 | * @author Thomas Rabaix <[email protected]> |
||
36 | */ |
||
37 | class CoreController extends Controller |
||
38 | { |
||
39 | /** |
||
40 | * @return Response |
||
41 | */ |
||
42 | public function dashboardAction() |
||
43 | { |
||
44 | $dashboardAction = $this->container->get(DashboardAction::class); |
||
45 | |||
46 | return $dashboardAction($this->getCurrentRequest()); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * The search action first render an empty page, if the query is set, then the template generates |
||
51 | * some ajax request to retrieve results for each admin. The Ajax query returns a JSON response. |
||
52 | * |
||
53 | * @throws \RuntimeException |
||
54 | * |
||
55 | * @return JsonResponse|Response |
||
56 | */ |
||
57 | public function searchAction(Request $request) |
||
58 | { |
||
59 | $searchAction = $this->container->get(SearchAction::class); |
||
60 | |||
61 | return $searchAction($request); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Get the request object from the container. |
||
66 | * |
||
67 | * This method is compatible with both Symfony 2.3 and Symfony 3 |
||
68 | * |
||
69 | * NEXT_MAJOR: remove this method. |
||
70 | * |
||
71 | * @deprecated since 3.0, to be removed in 4.0 and action methods will be adjusted. |
||
72 | * Use Symfony\Component\HttpFoundation\Request as an action argument |
||
73 | * |
||
74 | * @return Request |
||
75 | */ |
||
76 | public function getRequest() |
||
77 | { |
||
78 | @trigger_error( |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
79 | 'The '.__METHOD__.' method is deprecated since 3.0 and will be removed in 4.0.'. |
||
80 | ' Inject the Symfony\Component\HttpFoundation\Request into the actions instead.', |
||
81 | E_USER_DEPRECATED |
||
82 | ); |
||
83 | |||
84 | return $this->getCurrentRequest(); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return Pool |
||
89 | */ |
||
90 | protected function getAdminPool() |
||
91 | { |
||
92 | $pool = $this->container->get('sonata.admin.pool'); |
||
93 | \assert($pool instanceof Pool); |
||
94 | |||
95 | return $pool; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @return SearchHandler |
||
100 | */ |
||
101 | protected function getSearchHandler() |
||
102 | { |
||
103 | $searchHandler = $this->get('sonata.admin.search.handler'); |
||
104 | \assert($searchHandler instanceof SearchHandler); |
||
105 | |||
106 | return $searchHandler; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function getBaseTemplate() |
||
113 | { |
||
114 | if ($this->getCurrentRequest()->isXmlHttpRequest()) { |
||
115 | return $this->getTemplateRegistry()->getTemplate('ajax'); |
||
116 | } |
||
117 | |||
118 | return $this->getTemplateRegistry()->getTemplate('layout'); |
||
119 | } |
||
120 | |||
121 | private function getTemplateRegistry(): TemplateRegistryInterface |
||
122 | { |
||
123 | $templateRegistry = $this->container->get('sonata.admin.global_template_registry'); |
||
124 | \assert($templateRegistry instanceof TemplateRegistryInterface); |
||
125 | |||
126 | return $templateRegistry; |
||
127 | } |
||
128 | |||
129 | private function getCurrentRequest(): Request |
||
130 | { |
||
131 | return $this->container->get('request_stack')->getCurrentRequest(); |
||
132 | } |
||
133 | } |
||
134 |
If you suppress an error, we recommend checking for the error condition explicitly: