1: <?php
2: 3: 4: 5:
6: class Horde_Core_Controller_RequestMapper
7: {
8: 9: 10:
11: protected $_mapper;
12:
13: public function __construct(Horde_Routes_Mapper $mapper)
14: {
15: $this->_mapper = $mapper;
16: }
17:
18: public function getRequestConfiguration(Horde_Injector $injector)
19: {
20: $request = $injector->getInstance('Horde_Controller_Request');
21: $registry = $injector->getInstance('Horde_Registry');
22: $settingsFinder = $injector->getInstance('Horde_Core_Controller_SettingsFinder');
23:
24: $config = $injector->createInstance('Horde_Core_Controller_RequestConfiguration');
25:
26: $uri = substr($request->getPath(), strlen($registry->get('webroot', 'horde')));
27: $uri = trim($uri, '/');
28: if (strpos($uri, '/') === false) {
29: $app = $uri;
30: } else {
31: list($app,) = explode('/', $uri, 2);
32: }
33: $config->setApplication($app);
34:
35:
36: $fileroot = $registry->get('fileroot', $app);
37: $routeFile = $fileroot . '/config/routes.php';
38: if (!file_exists($routeFile)) {
39: $config->setControllerName('Horde_Core_Controller_NotFound');
40: return $config;
41: }
42:
43:
44: $registry->pushApp($app);
45:
46:
47:
48: $this->_mapper->prefix = $registry->get('webroot', $app);
49:
50:
51: $this->_mapper->directory = $registry->get('fileroot', $app) . '/app/controllers';
52:
53:
54: $mapper = $this->_mapper;
55: include $routeFile;
56: if (file_exists($fileroot . '/config/routes.local.php')) {
57: include $fileroot . '/config/routes.local.php';
58: }
59:
60:
61:
62: $match = $this->_mapper->match($request->getPath());
63:
64: if (isset($match['controller'])) {
65: $config->setControllerName(ucfirst($app) . '_' . ucfirst($match['controller']) . '_Controller');
66: $config->setSettingsExporterName($settingsFinder->getSettingsExporterName($config->getControllerName()));
67: } else {
68: $config->setControllerName('Horde_Core_Controller_NotFound');
69: }
70:
71: return $config;
72: }
73: }
74: