lithium\console\command\Test::_path()
Validates and gets a fully-namespaced class path from an absolute or relative physical path to a directory or file. The final class path may be partial in that in doesn't contain the class name.
This method can be thought of the reverse of Libraries::path()
.
lithium/tests/cases/core/LibrariesTest.php -> lithium\tests\cases\core\LibrariesTest
lithium/tests/cases/core -> lithium\tests\cases\core
lithium/core/Libraries.php -> lithium\core\Libraries
lithium/core/ -> lithium\core
lithium/core -> lithium\core
Parameters
-
string
$path
The directory of or file path to one or more classes.
Returns
stringReturns a fully-namespaced class path, or false
, if an error occurs.
Source
protected function _path($path) {
$path = rtrim(str_replace('\\', '/', $path), '/');
if (!$path) {
$this->error('Please provide a path to tests.');
return false;
}
if ($path[0] === '/') {
$library = $this->_library($path);
}
if ($path[0] !== '/') {
$libraries = array_reduce(Libraries::get(), function($v, $w) {
$v[] = basename($w['path']);
return $v;
});
$library = $this->_library($this->request->env('working') . '/' . $path);
$parts = explode('/', str_replace("../", "", $path));
$plugin = array_shift($parts);
if ($plugin === 'libraries') {
$plugin = array_shift($parts);
}
if (in_array($plugin, $libraries)) {
$library = $plugin;
$path = join('/', $parts);
}
}
if (empty($library)) {
$this->error("No library found in path `{$path}`.");
return false;
}
if (!$config = Libraries::get($library)) {
$this->error("Library `{$library}` does not exist.");
return false;
}
$path = str_replace($config['path'], null, $path);
$realpath = $config['path'] . '/' . $path;
if (!realpath($realpath)) {
$this->error("Path `{$realpath}` not found.");
return false;
}
$class = str_replace(".php", "", str_replace('/', '\\', ltrim($path, '/')));
return $config['prefix'] . $class;
}