1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basster\LegacyBridgeBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
7
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class LegacyScriptController |
11
|
|
|
* |
12
|
|
|
* @package Basster\LegacyBridgeBundle\Controller |
13
|
|
|
*/ |
14
|
|
|
class LegacyScriptController implements ContainerAwareInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var ContainerInterface |
18
|
|
|
*/ |
19
|
|
|
private $container; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
private $prependScript; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $appendScript; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param $requestPath |
29
|
|
|
* @param $legacyScript |
30
|
|
|
* |
31
|
|
|
* @return \Symfony\Component\HttpFoundation\StreamedResponse |
32
|
|
|
*/ |
33
|
3 |
|
public function runLegacyScript($requestPath, $legacyScript) |
34
|
|
|
{ |
35
|
3 |
|
$container = $this->container; |
36
|
3 |
|
$prepend = $this->prependScript; |
37
|
3 |
|
$append = $this->appendScript; |
38
|
|
|
|
39
|
3 |
|
$requireLegacyScript = function () use ( |
40
|
3 |
|
$requestPath, |
41
|
3 |
|
$legacyScript, |
42
|
3 |
|
$container, |
43
|
3 |
|
$prepend, |
44
|
3 |
|
$append |
45
|
|
|
) { |
46
|
3 |
|
$_SERVER['PHP_SELF'] = $requestPath; |
47
|
3 |
|
$_SERVER['SCRIPT_NAME'] = $requestPath; |
48
|
3 |
|
$_SERVER['SCRIPT_FILENAME'] = $legacyScript; |
49
|
3 |
|
$_SERVER['SYMFONY_CONTAINER'] = $container; |
50
|
3 |
|
chdir(dirname($legacyScript)); |
51
|
|
|
|
52
|
3 |
|
if ($prepend) { |
53
|
|
|
/** @noinspection PhpIncludeInspection */ |
54
|
1 |
|
require $prepend; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** @noinspection PhpIncludeInspection */ |
58
|
3 |
|
require $legacyScript; |
59
|
|
|
|
60
|
3 |
|
if ($append) { |
61
|
|
|
/** @noinspection PhpIncludeInspection */ |
62
|
1 |
|
require $append; |
63
|
|
|
} |
64
|
3 |
|
}; |
65
|
|
|
|
66
|
3 |
|
return StreamedResponse::create($requireLegacyScript); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string|null $script |
71
|
|
|
*/ |
72
|
1 |
|
public function setPrependScript($script = null) |
73
|
|
|
{ |
74
|
1 |
|
$this->prependScript = $script; |
75
|
1 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string|null $script |
79
|
|
|
*/ |
80
|
1 |
|
public function setAppendScript($script = null) |
81
|
|
|
{ |
82
|
1 |
|
$this->appendScript = $script; |
83
|
1 |
|
} |
84
|
|
|
|
85
|
|
|
/** {@inheritdoc} */ |
86
|
3 |
|
public function setContainer(ContainerInterface $container = null) |
87
|
|
|
{ |
88
|
3 |
|
$this->container = $container; |
89
|
3 |
|
} |
90
|
|
|
} |
91
|
|
|
|