[Solar-svn] Revision 3216

pmjones at solarphp.com pmjones at solarphp.com
Thu Jun 12 09:41:02 CDT 2008


solar "binary"

* [BRK] Per mailing list discussion, assume that the binary is part of a Solar
  "system" and as such can look for certain directories (source, scripts, and
  include).  Remove checks for $_SERVER['PHP_PEAR_INSTALL_DIR'] etc.

* [CHG] More-robust checks for binary location in relation to vendor name
  (i.e., in source and scripts, under the name "solar" and the vendor name,
  to allow for symlinks and copies).

* [CHG] When looking for config file, check for both Vendor.config.php and
  Solar.config.php by default.

* [FIX] When creating the console controller, use the config values if they
  exist.  If not, use Vendor_Cli as the main class and Solar_Cli as the 
  fallback (instead of always using Solar_Cli no matter what).


Modified: trunk/bin/solar
===================================================================
--- trunk/bin/solar	2008-06-11 13:40:36 UTC (rev 3215)
+++ trunk/bin/solar	2008-06-12 14:41:01 UTC (rev 3216)
@@ -6,22 +6,36 @@
 error_reporting(E_ALL | E_STRICT);
 ini_set('display_errors', true);
 ini_set('html_errors', false);
+$argv = empty($_SERVER['argv']) ? array(0 => '') : $_SERVER['argv'];
 
+// get the last part of the command used to invoke this script and use as the
+// vendor name.  e.g., './scripts/solar' => 'solar'
+$path = explode(DIRECTORY_SEPARATOR, $argv[0]);
+$vendor = end($path);
 
-/**
- * Find the "vendor" (top-level class name)
- */
+// what is the solar system root, if anywhere?
+$dirs = array(
+    // symlink solar
+    "/source/solar/bin/solar",
+    // symlink vendor
+    "/source/$vendor/bin/$vendor",
+    // copy solar
+    "/scripts/solar",
+    // copy vendor
+    "/scripts/$vendor",
+);
 
-// the command used to invoke this script
-// e.g., '/usr/local/bin/foo'
-$cmd = $_SERVER['argv'][0];
+$root = false;
+$file = __FILE__;
+foreach ($dirs as $dir) {
+    $len = -1 * strlen($dir);
+    if (substr($file, $len) == $dir) {
+        $root = substr($file, 0, $len);
+        break;
+    }
+}
 
-// get the last part of the command.
-// e.g., '/usr/local/bin/foo' => 'foo'
-$path = explode(DIRECTORY_SEPARATOR, $cmd);
-$vendor = end($path);
-
-// change to a class name prefix set.
+// change vendor name to a class name prefix:
 // 'foo' => 'Foo'
 // 'foo-bar' => 'FooBar'
 // 'foo_bar' => 'FooBar'
@@ -29,45 +43,22 @@
 $vendor = ucwords($vendor);
 $vendor = str_replace(' ', '', $vendor);
 
-
 /**
- * Discover and set the include-path
+ * 
+ * Discover and set the include-path.
+ * 
+ * Use the solar system root include path, fall back to the default path.
+ * 
+ * Override with the value of --include-path, if any.
+ * 
  */
-
-$vendor_key = 'PHP_' . strtoupper($vendor) . '_INCLUDE_PATH';
-switch (true) {
-
-// are we in a "solar system" installation? recognize this from the standard
-// directory structure and the physical file location within it.
-case (substr(__FILE__, -23) == '/source/solar/bin/solar'):
-    $include = '.' . PATH_SEPARATOR
-             . '..' . PATH_SEPARATOR
-             . substr(__FILE__, 0, -23) . '/include';
-    break;
-    
-// use a vendor-specific include path?
-case (! empty($_SERVER[$vendor_key])):
-    $include = $_SERVER[$vendor_key];
-    break;
-    
-// fall back to the solar include path
-case (! empty($_SERVER['PHP_SOLAR_INCLUDE_PATH'])):
-    $include = $_SERVER['PHP_SOLAR_INCLUDE_PATH'];
-    break;
-    
-// fall back to the pear dir
-case (! empty($_SERVER['PHP_PEAR_INSTALL_DIR'])):
-    $include = $_SERVER['PHP_PEAR_INSTALL_DIR'];
-    break;
-
-// stick with the php.ini include path
-default:
+if ($root) {
+    $include = '.' . PATH_SEPARATOR . '..' . PATH_SEPARATOR . "$root/include";
+} else {
     $include = get_include_path();
-    break;
 }
 
 // manually look for a --include-path argument that overrides the default
-$argv = empty($_SERVER['argv']) ? array() : $_SERVER['argv'];
 $found = false;
 foreach ($argv as $val) {
     if ($val == '--include-path') {
@@ -90,7 +81,7 @@
     }
 }
 
-// if there was a --include-path but no param, that's a failure
+// if there was an --include-path but no param, that's a failure
 if ($found && ! $include) {
     echo "Please specify an include-path after the --include-path option." . PHP_EOL;
     exit(-1);
@@ -101,35 +92,24 @@
 
 
 /**
- * Discover the config file
+ * 
+ * Discover the config file.
+ * 
+ * Look first for Vendor.config.php, fall back to Solar.config.php.
+ * 
+ * Override with the value of --config, if any.
+ * 
  */
-
-$vendor_key = 'PHP_' . strtoupper($vendor) . '_CONFIG_FILE';
-switch (true) {
-
-// are we in a "solar system" installation? recognize this from the standard
-// directory structure and the physical file location within it.
-case (substr(__FILE__, -23) == '/source/solar/bin/solar'):
-    $config = substr(__FILE__, 0, -23) . "/config/$vendor.config.php";
-    break;
-    
-// the vendor-specific default config
-case (! empty($_SERVER[$vendor_key])):
-    $config = $_SERVER[$vendor_key];
-    break;
-    
-// fall back to the solar default config
-case (! empty($_SERVER['PHP_SOLAR_CONFIG_FILE'])):
-    $config = $_SERVER['PHP_SOLAR_CONFIG_FILE'];
-    break;
-
-// no default config
-default:
+if ($root) {
+    $config = "$root/config/$vendor.config.php";
+    if (! file_exists($config) || ! is_readable($config)) {
+        $config = "$root/config/Solar.config.php";
+    }
+} else {
     $config = false;
 }
 
 // manually look for a --config argument that overrides the default
-$argv = empty($_SERVER['argv']) ? array() : $_SERVER['argv'];
 $found = false;
 foreach ($argv as $val) {
     if ($val == '--config') {
@@ -175,11 +155,29 @@
 require 'Solar.php';
 Solar::start($config);
 
-// create a console controller using the Vendor_Cli classes
-$console = Solar::factory('Solar_Controller_Console', array(
-    'classes' => "{$vendor}_Cli",
-    'default' => "base",
-));
+// is there a config for the console?
+if (Solar::config('Solar_Controller_Console')) {
+    
+    // use the config as-is and create the console
+    $console = Solar::factory('Solar_Controller_Console');
+    
+} else {
+    
+    // create a config for the console
+    $config = array();
+    
+    // use Vendor_Cli, then Solar_Cli as the fallback
+    $config['classes'][] = "{$vendor}_Cli";
+    if ($vendor != 'Solar') {
+        $config['classes'][] = "Solar_Cli";
+    }
+    
+    // default command is "base"
+    $config['default'] = 'base';
+    
+    // create the console
+    $console = Solar::factory('Solar_Controller_Console', $config);
+}
 
 // execute the requested command
 try {




More information about the Solar-svn mailing list