From e730ff56b59b20e3cad02ad7beb6d4ca55b726f6 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 10 Sep 2013 11:37:06 -0400 Subject: [PATCH] Allow override of present working directory. --- .../Mvc/Router/ConsoleRouter.php | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/module/VuFindConsole/src/VuFindConsole/Mvc/Router/ConsoleRouter.php b/module/VuFindConsole/src/VuFindConsole/Mvc/Router/ConsoleRouter.php index a45764bd1e4..fbd12ee35e0 100644 --- a/module/VuFindConsole/src/VuFindConsole/Mvc/Router/ConsoleRouter.php +++ b/module/VuFindConsole/src/VuFindConsole/Mvc/Router/ConsoleRouter.php @@ -40,6 +40,27 @@ use Zend\Mvc\Router\Http\RouteMatch, Zend\Mvc\Router\RouteStackInterface, */ class ConsoleRouter implements RouteStackInterface { + /** + * Present working directory + * + * @var string + */ + protected $pwd = ''; + + /** + * Constructor + * + * @param string $pwd Present working directory + */ + public function __construct($pwd = null) + { + if (null !== $pwd) { + $this->pwd = $pwd; + } else if (defined('CLI_DIR')) { + $this->pwd = CLI_DIR; + } + } + /** * Create a new route with given options. * @@ -49,7 +70,7 @@ class ConsoleRouter implements RouteStackInterface */ public static function factory($options = array()) { - return new ConsoleRouter(); + return new ConsoleRouter(isset($options['pwd']) ? $options['pwd'] : null); } /** @@ -64,13 +85,12 @@ class ConsoleRouter implements RouteStackInterface // Get command line arguments and present working directory from // server superglobal: $filename = $request->getScriptName(); - $pwd = CLI_DIR; // Convert base filename (minus .php extension and underscores) and // containing directory name into action and controller, respectively: $baseFilename = str_replace('_', '', basename($filename)); $baseFilename = substr($baseFilename, 0, strlen($baseFilename) - 4); - $baseDirname = basename(dirname(realpath($pwd . '/' . $filename))); + $baseDirname = basename(dirname(realpath($this->pwd . '/' . $filename))); $routeMatch = new RouteMatch( array('controller' => $baseDirname, 'action' => $baseFilename), 1 ); -- GitLab