[Solar-svn] Revision 2880
pmjones at solarphp.com
pmjones at solarphp.com
Wed Oct 17 08:03:13 CDT 2007
Moving many Solar::* methods to their own classes, changes to output control
in Solar_Controller_Command, and fix for Solar_Auth_Adapter_Sql.
New Classes
-----------
* [NEW] Solar_Dir contains Solar arch-class directory methods.
* [NEW] Solar_File contains Solar arch-class file methods.
* [NEW] Solar_Registry contains Solar arch-class registry methods.
* [BRK] Removed deprecated Solar::loadClass() and loadInterface() in favor of
new autoload() method.
Search-and-replace these method names; method signatures are unchanged.
Solar::loadClass() Solar::autoload()
Solar::loadInterface() Solar::autoload()
Solar::fileExists() Solar_File::exists()
Solar::run() Solar_File::load()
Solar::dirname() Solar_Dir::name()
Solar::fixdir() Solar_Dir::fix()
Solar::isDir() Solar_Dir::exists()
Solar::temp() Solar_Dir::tmp()
Solar::isRegistered() Solar_Registry::exists()
Solar::register() Solar_Registry::set()
Solar::registry() Solar_Registry::get()
Solar_Controller_Command
------------------------
* [CHG] Instead of echo, we now use fwrite() with php://stdout
* [BRK] Renamed methods _print() and _println() to _out() and _outln()
* [ADD] New methods _err() and _errln() write to php://stderr
Solar_Auth_Adapter_Sql
----------------------
* [FIX] Uses fetchAll() vice select('rowset'); thanks, Jeff Surgeson and
Rodrigo Moraes.
Modified: trunk/Solar/Access/Adapter/File.php
===================================================================
--- trunk/Solar/Access/Adapter/File.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Access/Adapter/File.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -65,7 +65,7 @@
$file = realpath($this->_config['file']);
// does the file exist?
- if (! Solar::fileExists($file)) {
+ if (! Solar_File::exists($file)) {
throw $this->_exception(
'ERR_FILE_NOT_READABLE',
array('file' => $file)
Modified: trunk/Solar/App/Base/Layout/_auth.php
===================================================================
--- trunk/Solar/App/Base/Layout/_auth.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/Base/Layout/_auth.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -15,13 +15,13 @@
*
*/
?>
-<?php if (Solar::isRegistered('user')): ?>
+<?php if (Solar_Registry::exists('user')): ?>
<div id="auth">
- <?php if (Solar::registry('user')->auth->isValid()): ?>
+ <?php if (Solar_Registry::get('user')->auth->isValid()): ?>
<p>
<?php echo $this->getText('TEXT_AUTH_USERNAME'); ?><br />
<strong><?php
- echo $this->escape(Solar::registry('user')->auth->handle);
+ echo $this->escape(Solar_Registry::get('user')->auth->handle);
?></strong>
</p>
<?php
@@ -57,7 +57,7 @@
?>
<?php endif; ?>
<p><?php
- $status = Solar::registry('user')->auth->getFlash('status_text');
+ $status = Solar_Registry::get('user')->auth->getFlash('status_text');
echo nl2br(wordwrap($this->escape($status), 20));
?></p>
</div>
Modified: trunk/Solar/App/Base.php
===================================================================
--- trunk/Solar/App/Base.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/Base.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -172,14 +172,14 @@
protected function _setup()
{
// register a Solar_Sql object if not already
- if (! Solar::isRegistered('sql')) {
- Solar::register('sql', Solar::factory('Solar_Sql'));
+ if (! Solar_Registry::exists('sql')) {
+ Solar_Registry::set('sql', Solar::factory('Solar_Sql'));
}
// register a Solar_User object if not already.
// this will trigger the authentication process.
- if (! Solar::isRegistered('user')) {
- Solar::register('user', Solar::factory('Solar_User'));
+ if (! Solar_Registry::exists('user')) {
+ Solar_Registry::set('user', Solar::factory('Solar_User'));
}
// set the layout title
@@ -199,7 +199,7 @@
*/
protected function _preAction()
{
- $allow = Solar::registry('user')->access->isAllowed(
+ $allow = Solar_Registry::get('user')->access->isAllowed(
get_class($this),
$this->_action
);
Modified: trunk/Solar/App/Bookmarks/Layout/_local.php
===================================================================
--- trunk/Solar/App/Bookmarks/Layout/_local.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/Bookmarks/Layout/_local.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -27,7 +27,7 @@
<div id="bookmarks-local">
- <?php if (Solar::registry('user')->auth->isValid()): ?>
+ <?php if (Solar_Registry::get('user')->auth->isValid()): ?>
<!-- Add a new bookmark -->
<p><?php
Modified: trunk/Solar/App/Bookmarks/View/_item.php
===================================================================
--- trunk/Solar/App/Bookmarks/View/_item.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/Bookmarks/View/_item.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -66,7 +66,7 @@
</li>
- <?php if (Solar::registry('user')->auth->handle == $item->owner_handle): ?>
+ <?php if (Solar_Registry::get('user')->auth->handle == $item->owner_handle): ?>
<li class="edit">
<?php echo $this->action("bookmarks/edit/{$item->id}", 'PROCESS_EDIT'); ?>
</li>
Modified: trunk/Solar/App/Bookmarks.php
===================================================================
--- trunk/Solar/App/Bookmarks.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/Bookmarks.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -180,7 +180,7 @@
/**
*
- * Local reference to the 'user' object in [[Solar::registry()]].
+ * Local reference to the 'user' object in [[Solar_Registry::get()]].
*
* @var Solar_User
*
@@ -235,7 +235,7 @@
}
// get a user object for privileges
- $this->user = Solar::registry('user');
+ $this->user = Solar_Registry::get('user');
// keep a bookmarks model
$this->_bookmarks = Solar::factory('Solar_Model_Nodes_Bookmarks');
Modified: trunk/Solar/App/Hello/View/rss.php
===================================================================
--- trunk/Solar/App/Hello/View/rss.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/Hello/View/rss.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -18,7 +18,7 @@
*/
header('Content-Type: text/xml; charset=iso-8859-1');
echo '<?xml version="1.0" encoding="iso-8859-1" ?>' . "\n";
-$request = Solar::registry('request');
+$request = Solar_Registry::get('request');
$server = $request->server();
?>
<rss version="2.0">
Modified: trunk/Solar/App/Hello.php
===================================================================
--- trunk/Solar/App/Hello.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/Hello.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -82,8 +82,8 @@
{
// register a Solar_User object if not already.
// this will trigger the authentication process.
- if (! Solar::isRegistered('user')) {
- Solar::register('user', Solar::factory('Solar_User'));
+ if (! Solar_Registry::exists('user')) {
+ Solar_Registry::set('user', Solar::factory('Solar_User'));
}
// set the layout title
Modified: trunk/Solar/App/HelloAjax/View/rss.php
===================================================================
--- trunk/Solar/App/HelloAjax/View/rss.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/HelloAjax/View/rss.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -18,7 +18,7 @@
*/
header('Content-Type: text/xml; charset=iso-8859-1');
echo '<?xml version="1.0" encoding="iso-8859-1" ?>' . "\n";
-$request = Solar::registry('request');
+$request = Solar_Registry::get('request');
$server = $request->server();
?>
<rss version="2.0">
Modified: trunk/Solar/App/HelloAjax.php
===================================================================
--- trunk/Solar/App/HelloAjax.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/App/HelloAjax.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -83,8 +83,8 @@
{
// register a Solar_User object if not already.
// this will trigger the authentication process.
- if (! Solar::isRegistered('user')) {
- Solar::register('user', Solar::factory('Solar_User'));
+ if (! Solar_Registry::exists('user')) {
+ Solar_Registry::set('user', Solar::factory('Solar_User'));
}
// set the layout title
Modified: trunk/Solar/Auth/Adapter/Sql.php
===================================================================
--- trunk/Solar/Auth/Adapter/Sql.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Auth/Adapter/Sql.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -129,7 +129,7 @@
->multiWhere($this->_config['where']);
// get the results
- $rows = $select->fetch('rowset');
+ $rows = $select->fetchAll();
// if we get back exactly 1 row, the user is authenticated;
// otherwise, it's more or less than exactly 1 row.
@@ -139,7 +139,7 @@
$info = array('handle' => $this->_handle);
// set optional info from optional cols
- $row = $rows->current();
+ $row = current($rows);
foreach ($optional as $key => $val) {
if ($this->_config[$val]) {
$info[$key] = $row[$this->_config[$val]];
Modified: trunk/Solar/Base.php
===================================================================
--- trunk/Solar/Base.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Base.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -129,7 +129,7 @@
// is construct-time config a file name?
if (is_string($config)) {
- $config = Solar::run($config);
+ $config = Solar_File::load($config);
}
// final override with construct-time config
Modified: trunk/Solar/Cache/Adapter/File.php
===================================================================
--- trunk/Solar/Cache/Adapter/File.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Cache/Adapter/File.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -109,13 +109,13 @@
public function __construct($config = null)
{
// set the default cache directory location
- $this->_Solar_Cache_Adapter_File['path'] = Solar::temp('/Solar_Cache_File/');
+ $this->_Solar_Cache_Adapter_File['path'] = Solar_Dir::tmp('/Solar_Cache_File/');
// basic construction
parent::__construct($config);
// keep local values so they can't be changed
- $this->_path = Solar::fixdir($this->_config['path']);
+ $this->_path = Solar_Dir::fix($this->_config['path']);
// build the context property
if (is_resource($this->_config['context'])) {
Modified: trunk/Solar/Class/Map.php
===================================================================
--- trunk/Solar/Class/Map.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Class/Map.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -92,7 +92,7 @@
*/
public function setBase($base)
{
- $this->_base = Solar::fixdir($base);
+ $this->_base = Solar_Dir::fix($base);
}
/**
@@ -170,7 +170,7 @@
protected function _findBaseByClass($class)
{
$file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
- $base = Solar::fileExists($file);
+ $base = Solar_File::exists($file);
if ($base) {
$neglen = -1 * strlen($file);
$base = substr($base, 0, $neglen);
@@ -179,7 +179,7 @@
// no base yet, look for a dir (drop the .php, add a separator)
$dir = substr($file, 0, -4);
- $base = Solar::isDir($dir);
+ $base = Solar_Dir::exists($dir);
if ($base) {
$neglen = -1 * strlen($dir);
$base = substr($base, 0, $neglen);
Modified: trunk/Solar/Class/Stack.php
===================================================================
--- trunk/Solar/Class/Stack.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Class/Stack.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -191,11 +191,11 @@
$file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
// does the file exist?
- if (! Solar::fileExists($file)) {
+ if (! Solar_File::exists($file)) {
continue;
}
- // include it in a limited scope. we don't use Solar::run()
+ // include it in a limited scope. we don't use Solar_File::load()
// because we want to avoid exceptions.
$this->_run($file);
Modified: trunk/Solar/Cli/Base.php
===================================================================
--- trunk/Solar/Cli/Base.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Cli/Base.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -43,10 +43,10 @@
// we use 'null' command because we could have gotten here from
// using an option or something else first, and a recognized
// command later on. showing that command here would be confusing.
- $this->_println('ERR_UNKNOWN_COMMAND', 1, array('cmd' => null));
- $this->_println('HELP_TRY_SOLAR_HELP');
+ $this->_outln('ERR_UNKNOWN_COMMAND', 1, array('cmd' => null));
+ $this->_outln('HELP_TRY_SOLAR_HELP');
} else {
- $this->_println($this->getInfoHelp());
+ $this->_outln($this->getInfoHelp());
}
}
@@ -66,8 +66,8 @@
switch (true) {
case $this->_options['version']:
- $this->_print("Solar command-line tool, version ");
- $this->_println($this->apiVersion() . '.');
+ $this->_out("Solar command-line tool, version ");
+ $this->_outln($this->apiVersion() . '.');
$skip_exec = true;
break;
@@ -88,7 +88,7 @@
parent::_postExec();
// return terminal to normal colors
- $this->_print("%n");
+ $this->_out("%n");
}
}
Modified: trunk/Solar/Cli/Help.php
===================================================================
--- trunk/Solar/Cli/Help.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Cli/Help.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -57,14 +57,14 @@
*/
protected function _displayCommandHelp($cmd = null)
{
- $this->_println();
+ $this->_outln();
// the list of known command-to-class mappings
$list = $this->_console->getCommandList();
// is this a known command?
if (empty($list[$cmd])) {
- $this->_println('ERR_UNKNOWN_COMMAND', 1, array('cmd' => $cmd));
+ $this->_outln('ERR_UNKNOWN_COMMAND', 1, array('cmd' => $cmd));
return;
}
@@ -72,24 +72,24 @@
$obj = Solar::factory($class);
$help = $obj->getInfoHelp();
if ($help) {
- $this->_println($help);
+ $this->_outln($help);
} else {
- $this->_println('ERR_NO_HELP');
+ $this->_outln('ERR_NO_HELP');
}
- $this->_println();
+ $this->_outln();
$opts = $obj->getInfoOptions();
if ($opts) {
- $this->_println('HELP_VALID_OPTIONS');
- $this->_println();
+ $this->_outln('HELP_VALID_OPTIONS');
+ $this->_outln();
foreach ($opts as $key => $val) {
- $this->_println($key);
+ $this->_outln($key);
$val = str_replace("\n", "\n ", wordwrap(": $val"));
- $this->_println($val);
- $this->_println();
+ $this->_outln($val);
+ $this->_outln();
}
}
}
@@ -105,13 +105,13 @@
*/
protected function _displayCommandList()
{
- $this->_println($this->getInfoHelp());
- $this->_println('HELP_AVAILABLE_COMMANDS');
+ $this->_outln($this->getInfoHelp());
+ $this->_outln('HELP_AVAILABLE_COMMANDS');
// now get the list of available commands
$list = $this->_console->getCommandList();
foreach ($list as $key => $val) {
- $this->_println(" $key");
+ $this->_outln(" $key");
}
}
}
\ No newline at end of file
Modified: trunk/Solar/Cli/MakeModel/Data/model.php
===================================================================
--- trunk/Solar/Cli/MakeModel/Data/model.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Cli/MakeModel/Data/model.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -8,7 +8,7 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
}
}
\ No newline at end of file
Modified: trunk/Solar/Cli/MakeModel.php
===================================================================
--- trunk/Solar/Cli/MakeModel.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Cli/MakeModel.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -65,7 +65,7 @@
*/
protected function _exec($class = null)
{
- $this->_println('Making model.');
+ $this->_outln('Making model.');
// we need a class name, at least
if (! $class) {
@@ -79,8 +79,8 @@
$this->_setTarget();
// emit feedback
- $this->_println("Using table '{$this->_table}'.");
- $this->_println("Writing '$class' to '{$this->_target}'.");
+ $this->_outln("Using table '{$this->_table}'.");
+ $this->_outln("Writing '$class' to '{$this->_target}'.");
// load the templates
$this->_loadTemplates();
@@ -110,26 +110,26 @@
. '.php';
if (file_exists($target)) {
- $this->_println('Model class exists.');
+ $this->_outln('Model class exists.');
} else {
- $this->_println('Writing model class.');
+ $this->_outln('Writing model class.');
file_put_contents($target, $text);
}
// get the setup dir
- $dir = Solar::fixdir(
+ $dir = Solar_Dir::fix(
$this->_target . str_replace('_', '/', $class) . '/Setup'
);
@mkdir($dir, 0777, true);
// write the cols file
- $this->_println('Updating table cols.');
+ $this->_outln('Updating table cols.');
$text = var_export($table_cols, true);
file_put_contents($dir . 'table_cols.php', "<?php\nreturn $text;");
// write the name file
- $this->_println('Updating table name.');
+ $this->_outln('Updating table name.');
file_put_contents($dir . 'table_name.php', "<?php\nreturn '{$this->_table}';");
// write the record template
@@ -141,9 +141,9 @@
);
if (file_exists($record_target)) {
- $this->_println('Record class exists.');
+ $this->_outln('Record class exists.');
} else {
- $this->_println('Writing record class.');
+ $this->_outln('Writing record class.');
file_put_contents($record_target, $text);
}
@@ -156,14 +156,14 @@
);
if (file_exists($collection_target)) {
- $this->_println('Collection class exists.');
+ $this->_outln('Collection class exists.');
} else {
- $this->_println('Writing collection class.');
+ $this->_outln('Writing collection class.');
file_put_contents($collection_target, $text);
}
// done!
- $this->_println("Done.");
+ $this->_outln("Done.");
}
/**
@@ -176,7 +176,7 @@
protected function _loadTemplates()
{
$this->_tpl = array();
- $dir = Solar::fixdir(dirname(__FILE__) . '/MakeModel/Data');
+ $dir = Solar_Dir::fix(dirname(__FILE__) . '/MakeModel/Data');
$list = glob($dir . '*.php');
foreach ($list as $file) {
$key = substr(basename($file), 0, -4);
@@ -197,10 +197,10 @@
if (! $target) {
// use the same target as 2 levels up from this class,
// should be the PEAR dir (or main Solar dir)
- $target = Solar::dirname(__FILE__, 2);
+ $target = Solar_Dir::name(__FILE__, 2);
}
- $this->_target = Solar::fixdir($target);
+ $this->_target = Solar_Dir::fix($target);
}
/**
Modified: trunk/Solar/Cli/MakeTests.php
===================================================================
--- trunk/Solar/Cli/MakeTests.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Cli/MakeTests.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -119,7 +119,7 @@
*/
protected function _exec($class = null)
{
- $this->_println("Making tests.");
+ $this->_outln("Making tests.");
// make sure we have a class to work with
if (! $class) {
@@ -136,24 +136,24 @@
$map = Solar::factory('Solar_Class_Map');
// tell the user where the source and targets are
- $this->_println("Source: " . $map->getBase());
- $this->_println("Target: $this->_target");
+ $this->_outln("Source: " . $map->getBase());
+ $this->_outln("Target: $this->_target");
// get the class and file locations
$class_file = $map->fetch($class);
foreach ($class_file as $class => $file) {
// tell the user what class we're on
- $this->_print("$class: ");
+ $this->_out("$class: ");
// if this is an exception class, skip it
if (strpos($class, '_Exception')) {
- $this->_println("skip (exception class)");
+ $this->_outln("skip (exception class)");
continue;
}
// load the class and get its API reference
- Solar::loadClass($class);
+ Solar::autoload($class);
$apiref = Solar::factory('Solar_Docs_Apiref');
$apiref->addClass($class);
$api = $apiref->api[$class];
@@ -171,11 +171,11 @@
file_put_contents($this->_file, $this->_code);
// done with this class
- $this->_println(' ;');
+ $this->_outln(' ;');
}
// done with all classes.
- $this->_println('Done.');
+ $this->_outln('Done.');
}
/**
@@ -188,7 +188,7 @@
protected function _loadTemplates()
{
$this->_tpl = array();
- $dir = Solar::fixdir(dirname(__FILE__) . '/MakeTests/Data');
+ $dir = Solar_Dir::fix(dirname(__FILE__) . '/MakeTests/Data');
$list = glob($dir . '*.php');
foreach ($list as $file) {
$key = substr(basename($file), 0, -4);
@@ -213,7 +213,7 @@
}
// make sure it matches the OS.
- $this->_target = Solar::fixdir($this->_target);
+ $this->_target = Solar_Dir::fix($this->_target);
// make sure it exists
if (! is_dir($this->_target)) {
@@ -322,13 +322,13 @@
// is this an ignored method?
if (in_array($name, $ignore)) {
- $this->_print('.');
+ $this->_out('.');
continue;
}
// is this a public method?
if ($info['access'] != 'public') {
- $this->_print('.');
+ $this->_out('.');
continue;
};
@@ -339,7 +339,7 @@
$def = "public function {$test_name}()";
$pos = strpos($this->_code, $def);
if ($pos) {
- $this->_print('.');
+ $this->_out('.');
continue;
}
@@ -359,7 +359,7 @@
// append to the test code
$this->_code .= $test_code;
- $this->_print('+');
+ $this->_out('+');
}
// append the last brace
Modified: trunk/Solar/Cli/RunTests.php
===================================================================
--- trunk/Solar/Cli/RunTests.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Cli/RunTests.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -94,10 +94,10 @@
}
// make sure it matches the OS
- $dir = Solar::fixdir($dir);
+ $dir = Solar_Dir::fix($dir);
// feedback
- $this->_println("Run tests from '$dir'.");
+ $this->_outln("Run tests from '$dir'.");
// make sure it ends in "/Test/".
$end = DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR;
Modified: trunk/Solar/Controller/Command.php
===================================================================
--- trunk/Solar/Controller/Command.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Controller/Command.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -112,6 +112,10 @@
*/
protected $_console;
+ protected $_stdout;
+
+ protected $_stderr;
+
/**
*
* Constructor.
@@ -123,6 +127,10 @@
{
parent::__construct($config);
+ // stdout and stderr
+ $this->_stdout = fopen('php://stdout', 'w');
+ $this->_stderr = fopen('php://stderr', 'w');
+
// set the recognized options
$options = $this->_getOptionSettings();
$this->_getopt = Solar::factory('Solar_Getopt');
@@ -132,6 +140,12 @@
$this->_setup();
}
+ public function __destruct()
+ {
+ fclose($this->_stdout);
+ fclose($this->_stderr);
+ }
+
/**
*
* Injects the console-controller object (if any) that invoked this command.
@@ -262,7 +276,7 @@
. DIRECTORY_SEPARATOR . 'help.txt';
// does that file exist?
- $file = Solar::fileExists($file);
+ $file = Solar_File::exists($file);
if ($file) {
return file_get_contents($file);
}
@@ -292,7 +306,7 @@
. DIRECTORY_SEPARATOR . 'Info'
. DIRECTORY_SEPARATOR . 'options.php';
- $file = Solar::fileExists($file);
+ $file = Solar_File::exists($file);
if ($file) {
$options = array_merge(
@@ -311,7 +325,7 @@
*
* If the text is a locale key, that text will be used instead.
*
- * Automatically replaces style-format codes for shell output.
+ * Automatically replaces style-format codes for VT100 shell output.
*
* @param string $text The text to print to STDOUT, usually a translation
* key.
@@ -324,22 +338,11 @@
* @return void
*
*/
- protected function _print($text = null, $num = 1, $replace = null)
+ protected function _out($text = null, $num = 1, $replace = null)
{
- static $vt100_keys;
- if (! $vt100_keys) {
- $vt100_keys = array_keys($this->_vt100);
- }
-
- static $vt100_vals;
- if (! $vt100_vals) {
- $vt100_vals = array_values($this->_vt100);
- }
-
- echo str_replace(
- $vt100_keys,
- $vt100_vals,
- $this->locale($text, $num, $replace)
+ fwrite(
+ $this->_stdout,
+ $this->_vt100($text, $num, $replace)
);
}
@@ -349,7 +352,7 @@
*
* If the text is a locale key, that text will be used instead.
*
- * Automatically replaces style-format codes for shell output.
+ * Automatically replaces style-format codes for VT100 shell output.
*
* @param string $text The text to print to STDOUT, usually a translation
* key.
@@ -362,13 +365,105 @@
* @return void
*
*/
- protected function _println($text = null, $num = 1, $replace = null)
+ protected function _outln($text = null, $num = 1, $replace = null)
{
- echo $this->_print($text, $num, $replace) . "\n";
+ fwrite(
+ $this->_stdout,
+ $this->_vt100($text, $num, $replace) . "\n"
+ );
}
/**
*
+ * Prints text to STDERR **without** a trailing newline.
+ *
+ * If the text is a locale key, that text will be used instead.
+ *
+ * Automatically replaces style-format codes for VT100 shell output.
+ *
+ * @param string $text The text to print to STDERR, usually a translation
+ * key.
+ *
+ * @param mixed $num Helps determine whether to get a singular
+ * or plural translation.
+ *
+ * @param array $replace An array of replacement values for the string.
+ *
+ * @return void
+ *
+ */
+ protected function _err($text = null, $num = 1, $replace = null)
+ {
+ fwrite(
+ $this->_stderr,
+ $this->_vt100($text, $num, $replace)
+ );
+ }
+
+ /**
+ *
+ * Prints text to STDERR and appends a newline.
+ *
+ * If the text is a locale key, that text will be used instead.
+ *
+ * Automatically replaces style-format codes for VT100 shell output.
+ *
+ * @param string $text The text to print to STDERR, usually a translation
+ * key.
+ *
+ * @param mixed $num Helps determine whether to get a singular
+ * or plural translation.
+ *
+ * @param array $replace An array of replacement values for the string.
+ *
+ * @return void
+ *
+ */
+ protected function _errln($text = null, $num = 1, $replace = null)
+ {
+ fwrite(
+ $this->_stderr,
+ $this->_vt100($text, $num, $replace) . "\n"
+ );
+ }
+
+ /**
+ *
+ * Frontend to locale() that replaces style-format codes for VT100 shell
+ * output.
+ *
+ * @param string $text The text to print to STDERR, usually a translation
+ * key.
+ *
+ * @param mixed $num Helps determine whether to get a singular
+ * or plural translation.
+ *
+ * @param array $replace An array of replacement values for the string.
+ *
+ * @return string The localized string with VT100 shell codes.
+ *
+ */
+ protected function _vt100($text, $num, $replace)
+ {
+ static $vt100_keys;
+ if (! $vt100_keys) {
+ $vt100_keys = array_keys($this->_vt100);
+ }
+
+ static $vt100_vals;
+ if (! $vt100_vals) {
+ $vt100_vals = array_values($this->_vt100);
+ }
+
+ return str_replace(
+ $vt100_keys,
+ $vt100_vals,
+ $this->locale($text, $num, $replace)
+ );
+ }
+
+ /**
+ *
* Post-construction setup logic.
*
* @return void
Modified: trunk/Solar/Controller/Console.php
===================================================================
--- trunk/Solar/Controller/Console.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Controller/Console.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -188,7 +188,7 @@
$stack = $this->_stack->get();
foreach ($stack as $class) {
- $dir = Solar::isDir(str_replace('_', DIRECTORY_SEPARATOR, $class));
+ $dir = Solar_Dir::exists(str_replace('_', DIRECTORY_SEPARATOR, $class));
if (! $dir) {
continue;
}
Modified: trunk/Solar/Controller/Front.php
===================================================================
--- trunk/Solar/Controller/Front.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Controller/Front.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -129,8 +129,8 @@
*/
protected function _setup()
{
- if (! Solar::isRegistered('request')) {
- Solar::register('request', 'Solar_Request');
+ if (! Solar_Registry::exists('request')) {
+ Solar_Registry::set('request', 'Solar_Request');
}
}
Modified: trunk/Solar/Example/Model/Areas.php
===================================================================
--- trunk/Solar/Example/Model/Areas.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/Areas.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,8 +40,8 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
$this->_hasMany('nodes', array(
'foreign_class' => 'nodes',
Modified: trunk/Solar/Example/Model/Metas.php
===================================================================
--- trunk/Solar/Example/Model/Metas.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/Metas.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,8 +40,8 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
$this->_belongsTo('node', array(
'foreign_class' => 'nodes',
Modified: trunk/Solar/Example/Model/Nodes.php
===================================================================
--- trunk/Solar/Example/Model/Nodes.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/Nodes.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,8 +40,8 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
$this->_belongsTo('area', array(
'foreign_class' => 'areas',
Modified: trunk/Solar/Example/Model/Taggings.php
===================================================================
--- trunk/Solar/Example/Model/Taggings.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/Taggings.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,8 +40,8 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
$this->_belongsTo('node', array(
'foreign_class' => 'nodes',
Modified: trunk/Solar/Example/Model/Tags.php
===================================================================
--- trunk/Solar/Example/Model/Tags.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/Tags.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,8 +40,8 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
$this->_hasMany('taggings');
$this->_hasMany('nodes', array(
Modified: trunk/Solar/Example/Model/TestSolarDib.php
===================================================================
--- trunk/Solar/Example/Model/TestSolarDib.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/TestSolarDib.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,7 +40,7 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
}
}
\ No newline at end of file
Modified: trunk/Solar/Example/Model/TestSolarFoo.php
===================================================================
--- trunk/Solar/Example/Model/TestSolarFoo.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/TestSolarFoo.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,8 +40,8 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
$this->_addFilter('email', 'validateEmail');
$this->_addFilter('uri', 'validateUri');
Modified: trunk/Solar/Example/Model/TestSolarSpecialCols.php
===================================================================
--- trunk/Solar/Example/Model/TestSolarSpecialCols.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/TestSolarSpecialCols.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,8 +40,8 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
// recognize sequence columns
$this->_sequence_cols = array(
Modified: trunk/Solar/Example/Model/TestSolarSqlDescribe.php
===================================================================
--- trunk/Solar/Example/Model/TestSolarSqlDescribe.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/TestSolarSqlDescribe.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,7 +40,7 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
}
}
\ No newline at end of file
Modified: trunk/Solar/Example/Model/Users.php
===================================================================
--- trunk/Solar/Example/Model/Users.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Example/Model/Users.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -40,8 +40,8 @@
. 'Setup'
. DIRECTORY_SEPARATOR;
- $this->_table_name = Solar::run($dir . 'table_name.php');
- $this->_table_cols = Solar::run($dir . 'table_cols.php');
+ $this->_table_name = Solar_File::load($dir . 'table_name.php');
+ $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
$this->_index = array(
'created',
Modified: trunk/Solar/Locale.php
===================================================================
--- trunk/Solar/Locale.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Locale.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -283,14 +283,14 @@
// method, which automatically replaces '/' with the
// correct directory separator.
$base = str_replace('_', '/', $class);
- $file = Solar::fixdir($base . '/Locale/')
+ $file = Solar_Dir::fix($base . '/Locale/')
. $this->_code . '.php';
// can we find the file?
- $target = Solar::fileExists($file);
+ $target = Solar_File::exists($file);
if ($target) {
// put the locale values into the shared locale array
- $this->trans[$class] = (array) Solar::run($target);
+ $this->trans[$class] = (array) Solar_File::load($target);
} else {
// could not find file.
// fail silently, as it's often the case that the
Modified: trunk/Solar/Path/Stack.php
===================================================================
--- trunk/Solar/Path/Stack.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Path/Stack.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -171,7 +171,7 @@
{
foreach ($this->_stack as $dir) {
$spec = $dir . $file;
- if (Solar::fileExists($spec)) {
+ if (Solar_File::exists($spec)) {
return $spec;
}
}
Modified: trunk/Solar/Role/Adapter/File.php
===================================================================
--- trunk/Solar/Role/Adapter/File.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Role/Adapter/File.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -65,7 +65,7 @@
$file = realpath($this->_config['file']);
// does the file exist?
- if (! Solar::fileExists($file)) {
+ if (! Solar_File::exists($file)) {
throw $this->_exception(
'ERR_FILE_NOT_READABLE',
array('file' => $file)
Modified: trunk/Solar/Sql/Model/Related.php
===================================================================
--- trunk/Solar/Sql/Model/Related.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Sql/Model/Related.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -530,7 +530,7 @@
$pos += 6; // "Model_"
$tmp = substr($this->native_class, 0, $pos) . ucfirst($this->foreign_class);
try {
- Solar::loadClass($tmp);
+ Solar::autoload($tmp);
// if no exception, $class gets set
$class = $tmp;
} catch (Exception $e) {
@@ -545,7 +545,7 @@
// model class literally. this will throw an exception if the
// class cannot be found anywhere.
try {
- Solar::loadClass($this->foreign_class);
+ Solar::autoload($this->foreign_class);
// if no exception, $class gets set
$class = $this->foreign_class;
} catch (Solar_Exception $e) {
Modified: trunk/Solar/Test/Suite.php
===================================================================
--- trunk/Solar/Test/Suite.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar/Test/Suite.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -126,7 +126,7 @@
parent::__construct($config);
// where are the tests located?
- $this->_dir = Solar::fixdir($this->_config['dir']);
+ $this->_dir = Solar_Dir::fix($this->_config['dir']);
// keep a Solar_Debug_Var object around for later
$this->_var = Solar::factory('Solar_Debug_Var');
@@ -412,7 +412,7 @@
// running tests for one class series?
if ($class) {
$sub = str_replace('_', DIRECTORY_SEPARATOR, $class);
- $dir = $this->_dir . Solar::fixdir($sub);
+ $dir = $this->_dir . Solar_Dir::fix($sub);
$file = rtrim($dir, DIRECTORY_SEPARATOR) . '.php';
if (is_readable($file)) {
require_once $file;
Modified: trunk/Solar.php
===================================================================
--- trunk/Solar.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/Solar.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -55,11 +55,6 @@
}
/**
- * Register Solar::loadClass() and Solar::loadInterface() for autoload.
- */
-spl_autoload_register(array('Solar', 'autoload'));
-
-/**
* Make sure Solar_Base is loaded even before Solar::start() is called.
* DO NOT use spl_autoload() in this case, it causes segfaults from recursion
* in some environments.
@@ -70,6 +65,21 @@
}
/**
+ * Make sure Solar_File is loaded even before Solar::start() is called.
+ * DO NOT use spl_autoload() in this case, it causes segfaults from recursion
+ * in some environments.
+ */
+if (! class_exists('Solar_File', false)) {
+ require dirname(__FILE__) . DIRECTORY_SEPARATOR
+ . 'Solar' . DIRECTORY_SEPARATOR . 'File.php';
+}
+
+/**
+ * Register Solar::autoload() with SPL.
+ */
+spl_autoload_register(array('Solar', 'autoload'));
+
+/**
*
* The Solar arch-class provides static methods needed throughout the Solar environment.
*
@@ -131,42 +141,6 @@
/**
*
- * Object registry.
- *
- * Objects are registered using [[Solar::register()]]; the registry
- * array is keyed on the name of the registered object.
- *
- * Although this property is public, you generally shouldn't need
- * to manipulate it in any way.
- *
- * @var array
- *
- */
- public static $registry = array();
-
- /**
- *
- * Status flag (whether Solar has started or not).
- *
- * @var bool
- *
- */
- protected static $_status = false;
-
- /**
- *
- * A filename to include; used by [[Solar::run()]] to keep the filename
- * out of the execution scope.
- *
- * @var string
- *
- * @see Solar::run()
- *
- */
- protected static $_file = null;
-
- /**
- *
* Locale class for managing translations.
*
* In general, you should never need to address this directly; instead,
@@ -195,6 +169,15 @@
/**
*
+ * Status flag (whether Solar has started or not).
+ *
+ * @var bool
+ *
+ */
+ protected static $_status = false;
+
+ /**
+ *
* Constructor is disabled to enforce a singleton pattern.
*
*/
@@ -300,7 +283,7 @@
// run any 'start' hook scripts
foreach ((array) Solar::config('Solar', 'start') as $file) {
- Solar::run($file);
+ Solar_File::load($file);
}
// and we're done!
@@ -318,11 +301,10 @@
{
// run the user-defined stop scripts.
foreach ((array) Solar::config('Solar', 'stop') as $file) {
- Solar::run($file);
+ Solar_File::load($file);
}
// clean up
- Solar::$registry = array();
Solar::$config = array();
Solar::$parents = array();
Solar::$locale = null;
@@ -378,9 +360,9 @@
// convert the class name to a file path.
$file = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
- // include the file and check for failure. we use run() here
+ // include the file and check for failure. we use Solar_File::load()
// instead of require() so we can see the exception backtrace.
- $result = Solar::run($file);
+ Solar_File::load($file);
// if the class or interface was not in the file, we have a problem.
// do not use autoload, because this method is registered with
@@ -397,167 +379,6 @@
/**
*
- * Loads a class file from the include_path.
- *
- * @param string $class A Solar (or other) class name.
- *
- * @return void
- *
- * @todo Add localization for errors
- *
- */
- public static function loadClass($class)
- {
- return Solar::autoload($class);
- }
-
- /**
- *
- * Loads an interface file from the include_path.
- *
- * @param string $interface A Solar (or other) interface class name.
- *
- * @return void
- *
- * @todo Add localization for errors
- *
- */
- public static function loadInterface($interface)
- {
- return Solar::autoload($interface);
- }
-
- /**
- *
- * Uses [[php::include() | ]] to run a script in a limited scope.
- *
- * @param string $file The file to include.
- *
- * @return mixed The return value of the included file.
- *
- */
- public static function run($file)
- {
- Solar::$_file = Solar::fileExists($file);
- if (! Solar::$_file) {
- // could not open the file for reading
- throw Solar::exception(
- 'Solar',
- 'ERR_FILE_NOT_READABLE',
- 'File does not exist or is not readable',
- array('file' => $file)
- );
- }
-
- // clean up the local scope, then include the file and
- // return its results. keeps the include() outside of an if()
- // statement, which makes it possible to opcode-cache.
- unset($file);
- return include Solar::$_file;
- }
-
- /**
- *
- * Hack for [[php::file_exists() | ]] that checks the include_path.
- *
- * Use this to see if a file exists anywhere in the include_path.
- *
- * {{code: php
- * $file = 'path/to/file.php';
- * if (Solar::fileExists('path/to/file.php')) {
- * include $file;
- * }
- * }}
- *
- * @param string $file Check for this file in the include_path.
- *
- * @return mixed If the file exists and is readble in the include_path,
- * returns the path and filename; if not, returns boolean false.
- *
- */
- public static function fileExists($file)
- {
- // no file requested?
- $file = trim($file);
- if (! $file) {
- return false;
- }
-
- // using an absolute path for the file?
- // dual check for Unix '/' and Windows '\',
- // or Windows drive letter and a ':'.
- $abs = ($file[0] == '/' || $file[0] == '\\' || $file[1] == ':');
- if ($abs && file_exists($file)) {
- return $file;
- }
-
- // using a relative path on the file
- $path = explode(PATH_SEPARATOR, ini_get('include_path'));
- foreach ($path as $base) {
- // strip Unix '/' and Windows '\'
- $target = rtrim($base, '\\/') . DIRECTORY_SEPARATOR . $file;
- if (file_exists($target)) {
- return $target;
- }
- }
-
- // never found it
- return false;
- }
-
- /**
- *
- * Hack for [[php::is_dir() | ]] that checks the include_path.
- *
- * Use this to see if a directory exists anywhere in the include_path.
- *
- * {{code: php
- * $dir = Solar::isDir('path/to/dir')
- * if ($dir) {
- * $files = scandir($dir);
- * } else {
- * echo "Not found in the include-path.";
- * }
- * }}
- *
- * @param string $dir Check for this directory in the include_path.
- *
- * @return mixed If the directory exists in the include_path, returns the
- * absolute path; if not, returns boolean false.
- *
- */
- public static function isDir($dir)
- {
- // no file requested?
- $dir = trim($dir);
- if (! $dir) {
- return false;
- }
-
- // using an absolute path for the file?
- // dual check for Unix '/' and Windows '\',
- // or Windows drive letter and a ':'.
- $abs = ($dir[0] == '/' || $dir[0] == '\\' || $dir[1] == ':');
- if ($abs && is_dir($dir)) {
- return $dir;
- }
-
- // using a relative path on the file
- $path = explode(PATH_SEPARATOR, ini_get('include_path'));
- foreach ($path as $base) {
- // strip Unix '/' and Windows '\'
- $target = rtrim($base, '\\/') . DIRECTORY_SEPARATOR . $dir;
- if (is_dir($target)) {
- return $target;
- }
- }
-
- // never found it
- return false;
- }
-
- /**
- *
* Convenience method to instantiate and configure an object.
*
* @param string $class The class name.
@@ -569,7 +390,7 @@
*/
public static function factory($class, $config = null)
{
- Solar::loadClass($class);
+ Solar::autoload($class);
$obj = new $class($config);
// is it an object factory?
@@ -584,109 +405,20 @@
/**
*
- * Accesses an object in the registry.
+ * Combination dependency-injection and service-locator method; returns
+ * a dependency object as passed, or an object from the registry, or a
+ * new factory instance.
*
- * @param string $key The registered name.
+ * @param string $class The dependency object should be an instance of
+ * this class. Technically, this is more a hint than a requirement,
+ * although it will be used as the class name if [[Solar::factory()]]
+ * gets called.
*
- * @return object The object registered under $key.
+ * @param mixed $spec If an object, check to make sure it's an instance
+ * of $class. If a string, treat as a [[Solar_Registry::get()]] key.
+ * Otherwise, use this as a config param to [[Solar::factory()]] to
+ * create a $class object.
*
- * @todo Localize these errors.
- *
- */
- public static function registry($key)
- {
- // has the shared object already been loaded?
- if (! Solar::isRegistered($key)) {
- throw Solar::exception(
- 'Solar',
- 'ERR_NOT_IN_REGISTRY',
- "Object with name '$key' not in registry.",
- array('name' => $key)
- );
- }
-
- // was the registration for a lazy-load?
- if (is_array(Solar::$registry[$key])) {
- $val = Solar::$registry[$key];
- $obj = Solar::factory($val[0], $val[1]);
- Solar::$registry[$key] = $obj;
- }
-
- // done
- return Solar::$registry[$key];
- }
-
- /**
- *
- * Registers an object under a unique name.
- *
- * @param string $key The name under which to register the object.
- *
- * @param object|string $spec The registry specification.
- *
- * @param mixed $config If lazy-loading, use this as the config.
- *
- * @return void
- *
- * @todo Localize these errors.
- *
- */
- public static function register($key, $spec, $config = null)
- {
- if (Solar::isRegistered($key)) {
- // name already exists in registry
- $class = get_class(Solar::$registry[$key]);
- throw Solar::exception(
- 'Solar',
- 'ERR_REGISTRY_NAME_EXISTS',
- "Object with '$key' of class '$class' already in registry",
- array('name' => $key, 'class' => $class)
- );
- }
-
- // register as an object, or as a class and config?
- if (is_object($spec)) {
- // directly register the object
- Solar::$registry[$key] = $spec;
- } elseif (is_string($spec)) {
- // register a class and config for lazy loading
- Solar::$registry[$key] = array($spec, $config);
- } else {
- throw Solar::exception(
- 'Solar',
- 'ERR_REGISTRY_FAILURE',
- 'Please pass an object, or a class name and a config array',
- array()
- );
- }
- }
-
- /**
- *
- * Check to see if an object name already exists in the registry.
- *
- * @param string $key The name to check.
- *
- * @return bool
- *
- */
- public static function isRegistered($key)
- {
- return ! empty(Solar::$registry[$key]);
- }
-
- /**
- *
- * Returns a dependency object.
- *
- * @param string $class The dependency object should be an instance of this class.
- * Technically, this is more a hint than a requirement, although it will be used
- * as the class name if [[Solar::factory()]] gets called.
- *
- * @param mixed $spec If an object, check to make sure it's an instance of $class.
- * If a string, treat as a [[Solar::registry()]] key. Otherwise, use this as a config
- * param to [[Solar::factory()]] to create a $class object.
- *
* @return object The dependency object.
*
*/
@@ -699,7 +431,7 @@
// check for registry objects
if (is_string($spec)) {
- return Solar::registry($spec);
+ return Solar_Registry::get($spec);
}
// not an object, not in registry.
@@ -906,48 +638,6 @@
/**
*
- * "Fixes" a directory string for the operating system.
- *
- * Use slashes anywhere you need a directory separator. Then run the
- * string through fixdir() and the slashes will be converted to the
- * proper separator (for example '\' on Windows).
- *
- * Always adds a final trailing separator.
- *
- * @param string $dir The directory string to 'fix'.
- *
- * @return string The "fixed" directory string.
- *
- */
- public static function fixdir($dir)
- {
- $dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
- return rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
- }
-
- /**
- *
- * Convenience method for dirname() and higher-level directories.
- *
- * @param string $file Get the dirname() of this file.
- *
- * @param int $up Move up in the directory structure this many
- * times, default 0.
- *
- * @return string The dirname() of the file.
- *
- */
- public static function dirname($file, $up = 0)
- {
- $dir = dirname($file);
- while ($up --) {
- $dir = dirname($dir);
- }
- return $dir;
- }
-
- /**
- *
* Returns an array of the parent classes for a given class.
*
* Parents in "reverse" order ... element 0 is the immediate parent,
@@ -1024,7 +714,7 @@
array_keys($_COOKIE),
array_keys($_SERVER),
array_keys($_FILES),
- // $_SESSION = null if you have not started the session yet.
+ // $_SESSION is null if you have not started the session yet.
// This insures that a check is performed regardless.
isset($_SESSION) && is_array($_SESSION) ? array_keys($_SESSION) : array()
);
@@ -1069,7 +759,7 @@
$config = (array) $spec;
} elseif (is_string($spec)) {
// merge from array file return
- $config = (array) Solar::run($spec);
+ $config = (array) Solar_File::load($spec);
} else {
// no added config
$config = array();
@@ -1077,78 +767,4 @@
return $config;
}
-
- /**
- *
- * Returns the OS-specific directory for temporary files, optionally with
- * a path added to it.
- *
- * @param string $add Add this to the end of the temporary directory
- * path.
- *
- * @return string The temp directory path, with optional suffix added.
- *
- */
- public static function temp($add = '')
- {
- if (function_exists('sys_get_temp_dir')) {
- $tmp = sys_get_temp_dir();
- } else {
- $tmp = Solar::_getTempDir();
- }
-
- if ($add) {
- // convert slashes to os-specific separators,
- // and remove leading separators
- $add = str_replace('/', DIRECTORY_SEPARATOR, $add);
- $add = ltrim($add, DIRECTORY_SEPARATOR);
-
- // remove trailing separators, and append $add.
- $tmp = rtrim($tmp, DIRECTORY_SEPARATOR);
- $tmp .= DIRECTORY_SEPARATOR . $add;
- }
-
- return $tmp;
- }
-
- /**
- *
- * Returns the OS-specific temporary directory location.
- *
- * @return string The temp directory path.
- *
- */
- protected static function _getTempDir()
- {
- // non-Windows system?
- if (strtolower(substr(PHP_OS, 0, 3)) != 'win') {
- $tmp = empty($_ENV['TMPDIR']) ? getenv('TMPDIR') : $_ENV['TMPDIR'];
- if ($tmp) {
- return $tmp;
- } else {
- return '/tmp';
- }
- }
-
- // Windows 'TEMP'
- $tmp = empty($_ENV['TEMP']) ? getenv('TEMP') : $_ENV['TEMP'];
- if ($tmp) {
- return $tmp;
- }
-
- // Windows 'TMP'
- $tmp = empty($_ENV['TMP']) ? getenv('TMP') : $_ENV['TMP'];
- if ($tmp) {
- return $tmp;
- }
-
- // Windows 'windir'
- $tmp = empty($_ENV['windir']) ? getenv('windir') : $_ENV['windir'];
- if ($tmp) {
- return $tmp;
- }
-
- // final fallback for Windows
- return getenv('SystemRoot') . '\\temp';
- }
}
Modified: trunk/bin/solar
===================================================================
--- trunk/bin/solar 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/bin/solar 2007-10-17 13:03:13 UTC (rev 2880)
@@ -80,7 +80,7 @@
Solar::start($config);
// register a request environment object for the controllers
-Solar::register('request', 'Solar_Request');
+Solar_Registry::set('request', 'Solar_Request');
// create a console controller
$console = Solar::factory('Solar_Controller_Console', array(
Modified: trunk/tests/Solar/Auth/AdapterTestCase.php
===================================================================
--- trunk/tests/Solar/Auth/AdapterTestCase.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/Solar/Auth/AdapterTestCase.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -35,12 +35,12 @@
public function setup()
{
// register the request environment
- if (! Solar::isRegistered('request')) {
- Solar::register('request', 'Solar_Request');
+ if (! Solar_Registry::exists('request')) {
+ Solar_Registry::set('request', 'Solar_Request');
}
// keep the request environment
- $this->_request = Solar::registry('request');
+ $this->_request = Solar_Registry::get('request');
$this->_request->reset();
// get a new adapter
Modified: trunk/tests/Solar/Cache/Adapter/FileTest.php
===================================================================
--- trunk/tests/Solar/Cache/Adapter/FileTest.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/Solar/Cache/Adapter/FileTest.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -17,7 +17,7 @@
public function setup()
{
if (is_null($this->_config['config']['path'])) {
- $this->_config['config']['path'] = Solar::temp('/Solar_Cache_Testing/');
+ $this->_config['config']['path'] = Solar_Dir::tmp('/Solar_Cache_Testing/');
}
parent::setup();
Modified: trunk/tests/Solar/Class/MapTest.php
===================================================================
--- trunk/tests/Solar/Class/MapTest.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/Solar/Class/MapTest.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -13,16 +13,16 @@
// and that's a bit much to keep up with.
public function testFetch_limited()
{
- $dir = Solar::fixdir(dirname(__FILE__) . '/../../support/');
+ $dir = Solar_Dir::fix(dirname(__FILE__) . '/../../support/');
$base = realpath($dir);
$map = Solar::factory('Solar_Class_Map');
$map->setBase($base);
$actual = $map->fetch('Solar_Class_Map');
$expect = array (
- "Solar_Class_Map_DirOne_TestOne" => Solar::fixdir("$base/Solar/Class/Map/DirOne/") . "TestOne.php",
- "Solar_Class_Map_DirOne_TestTwo" => Solar::fixdir("$base/Solar/Class/Map/DirOne/") . "TestTwo.php",
- "Solar_Class_Map_TestOne" => Solar::fixdir("$base/Solar/Class/Map/") . "TestOne.php",
- "Solar_Class_Map_TestTwo" => Solar::fixdir("$base/Solar/Class/Map/") . "TestTwo.php",
+ "Solar_Class_Map_DirOne_TestOne" => Solar_Dir::fix("$base/Solar/Class/Map/DirOne/") . "TestOne.php",
+ "Solar_Class_Map_DirOne_TestTwo" => Solar_Dir::fix("$base/Solar/Class/Map/DirOne/") . "TestTwo.php",
+ "Solar_Class_Map_TestOne" => Solar_Dir::fix("$base/Solar/Class/Map/") . "TestOne.php",
+ "Solar_Class_Map_TestTwo" => Solar_Dir::fix("$base/Solar/Class/Map/") . "TestTwo.php",
);
$this->assertSame($actual, $expect);
Modified: trunk/tests/Solar/Form/Load/TableTest.php
===================================================================
--- trunk/tests/Solar/Form/Load/TableTest.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/Solar/Form/Load/TableTest.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -2,9 +2,9 @@
require_once dirname(__FILE__) . '/../../../SolarUnitTest.config.php';
-Solar::loadClass('Solar_Sql');
+Solar::autoload('Solar_Sql');
-Solar::loadClass('Solar_Sql_Table');
+Solar::autoload('Solar_Sql_Table');
/**
* @todo This test is way too dependant on location and uses real classes where
Modified: trunk/tests/Solar/Log/Adapter/FileTest.php
===================================================================
--- trunk/tests/Solar/Log/Adapter/FileTest.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/Solar/Log/Adapter/FileTest.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -13,7 +13,7 @@
public function setup()
{
- $this->_config['file'] = Solar::temp('test_solar_log_adapter_file.log');
+ $this->_config['file'] = Solar_File::tmp('test_solar_log_adapter_file.log');
parent::setup();
@unlink($this->_config['file']);
}
Modified: trunk/tests/Solar/Log/Adapter/MultiTest.php
===================================================================
--- trunk/tests/Solar/Log/Adapter/MultiTest.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/Solar/Log/Adapter/MultiTest.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -16,7 +16,7 @@
'adapter' => 'Solar_Log_Adapter_File',
'config' => array(
'events' => 'debug',
- 'file' => Solar::temp('test_solar_log_adapter_multi.debug.log'),
+ 'file' => Solar_File::tmp('test_solar_log_adapter_multi.debug.log'),
'format' => '%e %m',
),
),
@@ -24,7 +24,7 @@
'adapter' => 'Solar_Log_Adapter_File',
'config' => array(
'events' => 'info, notice',
- 'file' => Solar::temp('test_solar_log_adapter_multi.other.log'),
+ 'file' => Solar_File::tmp('test_solar_log_adapter_multi.other.log'),
'format' => '%e %m',
),
),
Modified: trunk/tests/Solar/Path/StackTest.php
===================================================================
--- trunk/tests/Solar/Path/StackTest.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/Solar/Path/StackTest.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -19,9 +19,9 @@
public function testGet()
{
$expect = array(
- Solar::fixdir('/path/foo/'),
- Solar::fixdir('/path/bar/'),
- Solar::fixdir('/path/baz/'),
+ Solar_Dir::fix('/path/foo/'),
+ Solar_Dir::fix('/path/bar/'),
+ Solar_Dir::fix('/path/baz/'),
);
$stack = Solar::factory('Solar_Path_Stack');
@@ -35,9 +35,9 @@
$stack->add(array('/path/foo', '/path/bar', '/path/baz'));
$expect = array(
- Solar::fixdir('/path/foo/'),
- Solar::fixdir('/path/bar/'),
- Solar::fixdir('/path/baz/'),
+ Solar_Dir::fix('/path/foo/'),
+ Solar_Dir::fix('/path/bar/'),
+ Solar_Dir::fix('/path/baz/'),
);
$this->assertSame($stack->get(), $expect);
@@ -50,9 +50,9 @@
$stack->add('/path/foo:/path/bar:/path/baz');
$expect = array(
- Solar::fixdir('/path/foo/'),
- Solar::fixdir('/path/bar/'),
- Solar::fixdir('/path/baz/'),
+ Solar_Dir::fix('/path/foo/'),
+ Solar_Dir::fix('/path/bar/'),
+ Solar_Dir::fix('/path/baz/'),
);
$this->assertSame($stack->get(), $expect);
@@ -66,9 +66,9 @@
$stack->add('/path/baz');
$expect = array(
- Solar::fixdir('/path/baz/'),
- Solar::fixdir('/path/bar/'),
- Solar::fixdir('/path/foo/'),
+ Solar_Dir::fix('/path/baz/'),
+ Solar_Dir::fix('/path/bar/'),
+ Solar_Dir::fix('/path/foo/'),
);
$this->assertSame($stack->get(), $expect);
@@ -77,9 +77,9 @@
public function testSet_byString()
{
$expect = array(
- Solar::fixdir('/path/foo/'),
- Solar::fixdir('/path/bar/'),
- Solar::fixdir('/path/baz/'),
+ Solar_Dir::fix('/path/foo/'),
+ Solar_Dir::fix('/path/bar/'),
+ Solar_Dir::fix('/path/baz/'),
);
$stack = Solar::factory('Solar_Path_Stack');
@@ -91,9 +91,9 @@
public function testSet_byArray()
{
$expect = array(
- Solar::fixdir('/path/foo/'),
- Solar::fixdir('/path/bar/'),
- Solar::fixdir('/path/baz/'),
+ Solar_Dir::fix('/path/foo/'),
+ Solar_Dir::fix('/path/bar/'),
+ Solar_Dir::fix('/path/baz/'),
);
$stack = Solar::factory('Solar_Path_Stack');
@@ -122,17 +122,17 @@
// should find it at a
$actual = $stack->find('target1');
- $expect = Solar::fixdir($path[0]) . 'target1';
+ $expect = Solar_Dir::fix($path[0]) . 'target1';
$this->assertSame($expect, $actual);
// should find it at b
$actual = $stack->find('target2');
- $expect = Solar::fixdir($path[1]) . 'target2';
+ $expect = Solar_Dir::fix($path[1]) . 'target2';
$this->assertSame($expect, $actual);
// should find it at c
$actual = $stack->find('target3');
- $expect = Solar::fixdir($path[2]) . 'target3';
+ $expect = Solar_Dir::fix($path[2]) . 'target3';
$this->assertSame($expect, $actual);
// should not find it at all
@@ -160,17 +160,17 @@
// should find it at Solar_Base
$actual = $stack->findReal('target1');
- $expect = Solar::fixdir($path[0]) . 'target1';
+ $expect = Solar_Dir::fix($path[0]) . 'target1';
$this->assertSame($expect, $actual);
// should find it at Solar_Debug_Timer
$actual = $stack->findReal('target2');
- $expect = Solar::fixdir($path[1]) . 'target2';
+ $expect = Solar_Dir::fix($path[1]) . 'target2';
$this->assertSame($expect, $actual);
// should find it at Solar_Debug_Var
$actual = $stack->findReal('target3');
- $expect = Solar::fixdir($path[2]) . 'target3';
+ $expect = Solar_Dir::fix($path[2]) . 'target3';
$this->assertSame($expect, $actual);
// should not find it at all
Modified: trunk/tests/Solar/View/HelperTestCase.php
===================================================================
--- trunk/tests/Solar/View/HelperTestCase.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/Solar/View/HelperTestCase.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -20,12 +20,12 @@
// register the request environment so all classes have access to it,
// not just the helpers.
- if (! Solar::isRegistered('request')) {
- Solar::register('request', 'Solar_Request');
+ if (! Solar_Registry::exists('request')) {
+ Solar_Registry::set('request', 'Solar_Request');
}
// retain and reset the request environment
- $this->_request = Solar::registry('request');
+ $this->_request = Solar_Registry::get('request');
$this->_request->reset();
}
Modified: trunk/tests/SolarTest.php
===================================================================
--- trunk/tests/SolarTest.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/SolarTest.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -7,7 +7,7 @@
{
public function testLoadClassThrowsExceptionOnEmptyString() {
try {
- Solar::loadClass('');
+ Solar::autoload('');
$this->fail('Should throw exception on empty string');
}
catch (Solar_Exception $e) {
@@ -22,11 +22,11 @@
'Insure class has not been loaded.'
);
- Solar::loadClass('Solar_LoadClassObject');
+ Solar::autoload('Solar_LoadClassObject');
$this->assertTrue(
class_exists('Solar_LoadClassObject', false),
- 'Insure Solar::loadClass() loaded the requested class.'
+ 'Insure Solar::autoload() loaded the requested class.'
);
} catch (Exception $e) {
echo $e;
Modified: trunk/tests/support/Solar/Controller/PageController.php
===================================================================
--- trunk/tests/support/Solar/Controller/PageController.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/support/Solar/Controller/PageController.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -16,11 +16,6 @@
*/
/**
- * Parent class.
- */
-Solar::loadClass('Solar_Controller_Page');
-
-/**
*
* Example page-controller to support unit tests.
*
Modified: trunk/tests/support/Solar/FactoryObject.php
===================================================================
--- trunk/tests/support/Solar/FactoryObject.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/support/Solar/FactoryObject.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -2,7 +2,7 @@
/**
*
- * This test exists for the purpose of testing loadClass().
+ * This test exists for the purpose of testing autoload().
*
* @see SolarTest::testFactoryLoadsAndReturnsObject()
*
Modified: trunk/tests/support/Solar/LoadClassObject.php
===================================================================
--- trunk/tests/support/Solar/LoadClassObject.php 2007-10-14 15:28:26 UTC (rev 2879)
+++ trunk/tests/support/Solar/LoadClassObject.php 2007-10-17 13:03:13 UTC (rev 2880)
@@ -2,7 +2,7 @@
/**
*
- * This test exists for the purpose of testing loadClass().
+ * This test exists for the purpose of testing autoload().
*
* @see SolarTest::testLoadClassReturnsAnObjectOnKnownClass()
*
More information about the Solar-svn
mailing list