1 | <?php |
||
15 | class LegacyController extends AbstractActionController |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * |
||
20 | * @var LegacyControllerOptions |
||
21 | */ |
||
22 | private $options; |
||
23 | |||
24 | /** |
||
25 | * |
||
26 | * @var MaglLegacy |
||
27 | */ |
||
28 | private $legacy; |
||
29 | |||
30 | 4 | public function __construct(LegacyControllerOptions $options, MaglLegacy $legacy) |
|
35 | |||
36 | 4 | public function indexAction() |
|
37 | { |
||
38 | 4 | $docRoots = $this->options->getDocRoots(); |
|
39 | 4 | foreach($docRoots as $key => $docRoot) { |
|
|
|||
40 | 4 | $docRoots[$key] = rtrim(getcwd() . '/' . $docRoot); |
|
41 | 4 | } |
|
42 | |||
43 | 4 | $scriptName = $this->params('script'); |
|
44 | |||
45 | 4 | if (empty($scriptName)) { |
|
46 | $path = $this->params(('path')) ? $this->params('path') : ''; |
||
47 | foreach ($this->options->getIndexFiles() as $indexFile) { |
||
48 | foreach($docRoots as $docRoot) { |
||
49 | if (is_file($docRoot . '/' . $path . $indexFile)) { |
||
50 | $this->legacy->setLegacyScriptName($path . $indexFile); |
||
51 | return $this->runScript($docRoot . '/' . $path . $indexFile); |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | |||
57 | |||
58 | 4 | $scriptUri = '/' . ltrim($scriptName, '/'); // force leading '/' |
|
59 | 4 | foreach($docRoots as $docRoot) { |
|
60 | 4 | $legacyScriptFilename = $docRoot . $scriptUri; |
|
61 | 4 | if(is_file($legacyScriptFilename)) { |
|
62 | //inform the application about the used script |
||
63 | 3 | $this->legacy->setLegacyScriptName($scriptUri); |
|
64 | |||
65 | //inject get and request variables |
||
66 | 3 | $this->setGetVariables(); |
|
67 | |||
68 | 3 | return $this->runScript($legacyScriptFilename); |
|
69 | } |
||
70 | 2 | } |
|
71 | |||
72 | // if we're here, the file doesn't really exist and we do not know what to do |
||
73 | 1 | $response = $this->getResponse(); |
|
74 | |||
75 | /* @var $response Response */ //<-- this one for netbeans (WHY, NetBeans, WHY??) |
||
76 | /** @var Response $response */ // <-- this one for other IDEs and code analyzers :) |
||
77 | 1 | $response->setStatusCode(404); |
|
78 | 1 | return $response; |
|
79 | } |
||
80 | |||
81 | 3 | private function setGetVariables() |
|
118 | |||
119 | 3 | private function runScript($scriptFileName) |
|
138 | } |
||
139 |