Completed
Push — master ( 3fd2dd...aba624 )
by Grégoire
04:19
created

src/Controller/HelperController.php (1 issue)

Upgrade to new PHP Analysis Engine

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
use Sonata\AdminBundle\Action\AppendFormFieldElementAction;
17
use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction;
18
use Sonata\AdminBundle\Action\RetrieveAutocompleteItemsAction;
19
use Sonata\AdminBundle\Action\RetrieveFormFieldElementAction;
20
use Sonata\AdminBundle\Action\SetObjectFieldValueAction;
21
use Sonata\AdminBundle\Admin\AdminHelper;
22
use Sonata\AdminBundle\Admin\Pool;
23
use Symfony\Component\HttpFoundation\JsonResponse;
24
use Symfony\Component\HttpFoundation\Request;
25
use Symfony\Component\HttpFoundation\Response;
26
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
27
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
28
use Symfony\Component\Validator\Validator\ValidatorInterface;
29
use Twig\Environment;
30
31
@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...
32
    'The '.__NAMESPACE__.'\HelperController class is deprecated since version 3.38.0 and will be removed in 4.0.'
33
    .' Use actions inside Sonata\AdminBundle\Action instead.',
34
    E_USER_DEPRECATED
35
);
36
37
/**
38
 * NEXT_MAJOR: remove this class.
39
 *
40
 * @deprecated since version 3.38.0, to be removed in 4.0. Use actions inside Sonata\AdminBundle\Action instead.
41
 *
42
 * @author Thomas Rabaix <[email protected]>
43
 */
44
class HelperController
45
{
46
    /**
47
     * @var \Twig_Environment
48
     */
49
    protected $twig;
50
51
    /**
52
     * @var AdminHelper
53
     */
54
    protected $helper;
55
56
    /**
57
     * @var Pool
58
     */
59
    protected $pool;
60
61
    /**
62
     * @var ValidatorInterface
63
     */
64
    protected $validator;
65
66
    /**
67
     * @param ValidatorInterface $validator
68
     */
69
    public function __construct(Environment $twig, Pool $pool, AdminHelper $helper, $validator)
70
    {
71
        // NEXT_MAJOR: Move ValidatorInterface check to method signature
72
        if (!($validator instanceof ValidatorInterface)) {
73
            throw new \InvalidArgumentException(
74
                'Argument 4 is an instance of '.\get_class($validator).', expecting an instance of'
75
                .' \Symfony\Component\Validator\Validator\ValidatorInterface'
76
            );
77
        }
78
79
        $this->twig = $twig;
80
        $this->pool = $pool;
81
        $this->helper = $helper;
82
        $this->validator = $validator;
83
    }
84
85
    /**
86
     * @throws NotFoundHttpException
87
     *
88
     * @return Response
89
     */
90
    public function appendFormFieldElementAction(Request $request)
91
    {
92
        $action = new AppendFormFieldElementAction($this->twig, $this->pool, $this->helper);
93
94
        return $action($request);
95
    }
96
97
    /**
98
     * @throws NotFoundHttpException
99
     *
100
     * @return Response
101
     */
102
    public function retrieveFormFieldElementAction(Request $request)
103
    {
104
        $action = new RetrieveFormFieldElementAction($this->twig, $this->pool, $this->helper);
105
106
        return $action($request);
107
    }
108
109
    /**
110
     * @throws NotFoundHttpException|\RuntimeException
111
     *
112
     * @return Response
113
     */
114
    public function getShortObjectDescriptionAction(Request $request)
115
    {
116
        $action = new GetShortObjectDescriptionAction($this->twig, $this->pool);
117
118
        return $action($request);
119
    }
120
121
    /**
122
     * @return Response
123
     */
124
    public function setObjectFieldValueAction(Request $request)
125
    {
126
        $action = new SetObjectFieldValueAction($this->twig, $this->pool, $this->validator);
127
128
        return $action($request);
129
    }
130
131
    /**
132
     * Retrieve list of items for autocomplete form field.
133
     *
134
     * @throws \RuntimeException
135
     * @throws AccessDeniedException
136
     *
137
     * @return JsonResponse
138
     */
139
    public function retrieveAutocompleteItemsAction(Request $request)
140
    {
141
        $action = new RetrieveAutocompleteItemsAction($this->pool);
142
143
        return $action($request);
144
    }
145
}
146