|
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 Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Polyfills the FrameworkBundle's original ControllerTrait. |
|
23
|
|
|
* |
|
24
|
|
|
* NEXT_MAJOR: Remove this file. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Christian Kraus <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
trait PolyfillControllerTrait |
|
29
|
|
|
{ |
|
30
|
|
|
public function __call($methodName, $arguments) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->proxyToController($methodName, $arguments); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function render($view, array $parameters = [], ?Response $response = null) |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->__call('render', [$view, $parameters, $response]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @internal |
|
42
|
|
|
*/ |
|
43
|
|
|
final protected function proxyToControllerClass($methodName, $arguments) |
|
44
|
|
|
{ |
|
45
|
|
|
if (!method_exists(Controller::class, $methodName)) { |
|
46
|
|
|
throw new \LogicException(sprintf('Call to undefined method %s::%s', __CLASS__, $methodName)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$controller = new PolyfillProxyContainer($this->container); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
return $controller->proxyCall($methodName, $arguments); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
class PolyfillProxyContainer extends Controller |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
public function __construct(ContainerInterface $container) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->setContainer($container); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function proxyCall($method, $arguments) |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->{$method}(...$arguments); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if (!trait_exists(ControllerTrait::class)) { |
|
69
|
|
|
class_alias(PolyfillControllerTrait::class, ControllerTrait::class); |
|
70
|
|
|
} |
|
71
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.