[Solar-svn] Revision 2927

pmjones at solarphp.com pmjones at solarphp.com
Fri Nov 9 10:28:47 CST 2007


Solar binary
------------

* [CHG] Now tells you when it's not using a config file at all.

* [CHG] Now determines the top-level vendor class from the CLI invocation name.  This lets you symlink to the same solar binary under different names, and that name determines which Vendor_Cli stack it will use.




Modified: trunk/bin/solar
===================================================================
--- trunk/bin/solar	2007-11-09 16:25:44 UTC (rev 2926)
+++ trunk/bin/solar	2007-11-09 16:28:47 UTC (rev 2927)
@@ -69,20 +69,46 @@
     exit(-1);
 }
 
-$config = realpath($config);
-echo "Using config file '$config'.\n";
+// was there a config file at all?
+if ($config) {
+    $config = realpath($config);
+    echo "Using config file '$config'.\n";
+} else {
+    echo "Not using a config file.\n";
+}
 
 /**
+ * Find the "vendor" (top-level class name)
+ */
+
+// the command used to invoke this script
+// e.g., '/usr/local/bin/foo'
+$cmd = $_SERVER['argv'][0];
+
+// 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.
+// 'foo' => 'Foo'
+// 'foo-bar' => 'FooBar'
+// 'foo_bar' => 'FooBar'
+$vendor = str_replace(array('-', '_'), ' ', $vendor);
+$vendor = ucwords($vendor);
+$vendor = str_replace(' ', '', $vendor);
+
+/**
  * Main
  */
 
 // Start Solar with the requested config file (if any)
 Solar::start($config);
 
-// create a console controller
+// create a console controller using the Vendor_Cli classes
 $console = Solar::factory('Solar_Controller_Console', array(
-    'classes' => 'Solar_Cli',
-    'default' => 'base',
+    'classes' => "{$vendor}_Cli",
+    'default' => "base",
 ));
 
 // execute the requested command




More information about the Solar-svn mailing list