Completed
Push — 3.x ( db377c...cd74a2 )
by Andrey F.
12:41
created

CoreController::dashboardAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 35 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

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