namespace hoplite\http;
+require_once HOPLITE_ROOT . '/base/functions.php';
+
/*!
A UrlMap will translate a raw HTTP request into a http\Request object. It does
so by matching the incoming URL to a pattern. For information on the format of
@return Action|NULL The loaded action, or NULL on error.
*/
public function LookupAction($map_value)
- {}
+ {
+ // If the first character is uppercase or a namespaced class, simply return
+ // the value.
+ $first_char = $map_value[0];
+ if ($first_char == '\\' || ctype_upper($first_char))
+ return $map_value;
+
+ // Otherwise this is a path. Check if an extension is present, and if not,
+ // add one.
+ $pathinfo = pathinfo($map_value);
+ if (!isset($pathinfo['extension'])) {
+ $map_value .= '.php';
+ $pathinfo['extension'] = 'php';
+ }
+
+ return $this->_ClassNameFromFileName($pathinfo);
+ }
/*!
Takes a file name and returns the name of an Action class. This uses an
This can be overridden to provide a custom transformation.
+ @param array Result of a pathinfo() call
+
@return string Action class name.
*/
- protected function _ClassNameFromFileName($file_name)
- {}
+ protected function _ClassNameFromFileName($pathinfo)
+ {
+ $filename = $pathinfo['filename'];
+ return \hoplite\base\UnderscoreToCamelCase($filename);
+ }
}
$request = new http\Request('user/TEST');
$this->assertEquals('Third', $this->fixture->Evaluate($request));
}
+
+ public function testLookupActionClass()
+ {
+ $test_class = '\hoplite\test\TestAction';
+ $this->assertEquals($test_class, $this->fixture->LookupAction($test_class));
+
+ $test_class = 'TestAction';
+ $this->assertEquals($test_class, $this->fixture->LookupAction($test_class));
+ }
+
+ public function testLookupActionFile()
+ {
+ $this->assertEquals('TestAction', $this->fixture->LookupAction('actions/test_action'));
+ $this->assertEquals('TestAction', $this->fixture->LookupAction('actions/test_action.php'));
+ }
}