[Solar-svn] Revision 2902
pmjones at solarphp.com
pmjones at solarphp.com
Sat Oct 20 14:00:49 CDT 2007
Standards: 2 breaks related to Locale and Request objects
* [BRK] Removed Solar::$locale property; instead, Solar::start() calls Solar_Registry::set('locale', 'Solar_Locale) to create a locale object in the registry. Access that object instead of Solar::$locale, using Solar_Registry::get('locale').
* [CHG] Solar::start() now lazy-loads a Solar_Request object into the registry under 'request'.
Modified: trunk/Solar/App/Hello.php
===================================================================
--- trunk/Solar/App/Hello.php 2007-10-20 18:18:25 UTC (rev 2901)
+++ trunk/Solar/App/Hello.php 2007-10-20 19:00:49 UTC (rev 2902)
@@ -106,7 +106,7 @@
$this->code = $code;
// reset the locale strings to the new code
- Solar::$locale->setCode($this->code);
+ Solar_Registry::get('locale')->setCode($this->code);
// set the translated text
$this->text = $this->locale('TEXT_HELLO_WORLD');
@@ -131,7 +131,7 @@
$this->code = $code;
// reset the locale strings to the new code
- Solar::$locale->setCode($this->code);
+ Solar_Registry::get('locale')->setCode($this->code);
// set the translated text
$this->text = $this->locale('TEXT_HELLO_WORLD');
Modified: trunk/Solar/Base.php
===================================================================
--- trunk/Solar/Base.php 2007-10-20 18:18:25 UTC (rev 2901)
+++ trunk/Solar/Base.php 2007-10-20 19:00:49 UTC (rev 2902)
@@ -199,9 +199,10 @@
/**
*
- * Looks up locale strings based on a key.
+ * Looks up class-specific locale strings based on a key.
*
- * This is a convenient shortcut for calling [[Solar::$locale]]->fetch()
+ * This is a convenient shortcut for calling
+ * [[Solar_Registry]]::get('locale')->fetch()
* that automatically uses the current class name.
*
* You can also pass an array of replacement values. If the `$replace`
@@ -240,8 +241,6 @@
*
* @see Manual::Solar/Using_locales
*
- * @see Solar::$locale
- *
* @see Class::Solar_Locale
*
*/
@@ -252,7 +251,12 @@
$class = get_class($this);
}
- return Solar::$locale->fetch($class, $key, $num, $replace);
+ static $locale;
+ if (! $locale) {
+ $locale = Solar_Registry::get('locale');
+ }
+
+ return $locale->fetch($class, $key, $num, $replace);
}
/**
@@ -269,15 +273,10 @@
*/
protected function _exception($code, $info = array())
{
- static $class;
- if (! $class) {
- $class = get_class($this);
- }
-
return Solar::exception(
$class,
$code,
- Solar::$locale->fetch($class, $code, 1, $info),
+ $this->locale($code, 1, $info),
(array) $info
);
}
Modified: trunk/Solar/View/Helper/GetTextRaw.php
===================================================================
--- trunk/Solar/View/Helper/GetTextRaw.php 2007-10-20 18:18:25 UTC (rev 2901)
+++ trunk/Solar/View/Helper/GetTextRaw.php 2007-10-20 19:00:49 UTC (rev 2902)
@@ -81,7 +81,11 @@
*/
public function getTextRaw($key, $num = 1, $replace = null)
{
- return Solar::$locale->fetch($this->_class, $key, $num, $replace);
+ static $locale;
+ if (! $locale) {
+ $locale = Solar_Registry::get('locale');
+ }
+ return $locale->fetch($this->_class, $key, $num, $replace);
}
/**
Modified: trunk/Solar.php
===================================================================
--- trunk/Solar.php 2007-10-20 18:18:25 UTC (rev 2901)
+++ trunk/Solar.php 2007-10-20 19:00:49 UTC (rev 2902)
@@ -95,8 +95,13 @@
* [[php::ini_set | ]] key, and the value is the value for that setting.
*
* `locale_class`
- * : (string) Use this class for Solar::$locale.
+ * : (string) Use this class for the registered 'locale' object. Default
+ * 'Solar_Locale'.
*
+ * `request_class`
+ * : (string) Use this class for the registered 'request' object. Default
+ * 'Solar_Request'.
+ *
* `start`
* : (array) Run these scripts at the end of Solar::start().
*
@@ -107,10 +112,11 @@
*
*/
protected static $_Solar = array(
- 'ini_set' => array(),
- 'locale_class' => 'Solar_Locale',
- 'start' => array(),
- 'stop' => array(),
+ 'ini_set' => array(),
+ 'locale_class' => 'Solar_Locale',
+ 'request_class' => 'Solar_Request',
+ 'start' => array(),
+ 'stop' => array(),
);
/**
@@ -124,28 +130,6 @@
/**
*
- * Where this class (the Solar arch-class) is in the filesystem.
- *
- * @var string
- *
- */
- public static $dir = null;
-
- /**
- *
- * Locale class for managing translations.
- *
- * In general, you should never need to address this directly; instead,
- * use [[Solar_Base::locale() | $this->locale()]] in classes extended
- * from [[Class::Solar_Base]].
- *
- * @var Solar_Locale
- *
- */
- public static $locale;
-
- /**
- *
* Parent hierarchy for all classes.
*
* We keep track of this so configs, locale strings, etc. can be
@@ -242,9 +226,6 @@
return;
}
- // where is Solar in the filesystem?
- Solar::$dir = dirname(__FILE__);
-
// clear out registered globals
if (ini_get('register_globals')) {
Solar::cleanGlobals();
@@ -269,10 +250,18 @@
ini_set($key, $val);
}
- // load the locale class
- $class = Solar::config('Solar', 'locale_class', 'Solar_Locale');
- Solar::$locale = Solar::factory($class);
+ // register the locale class (lazy-load)
+ Solar_Registry::set(
+ 'locale',
+ Solar::config('Solar', 'locale_class', 'Solar_Locale')
+ );
+ // register the request-envivronment class (lazy-load)
+ Solar_Registry::set(
+ 'request',
+ Solar::config('Solar', 'request_class', 'Solar_Request')
+ );
+
// run any 'start' hook scripts
foreach ((array) Solar::config('Solar', 'start') as $file) {
Solar_File::load($file);
@@ -299,7 +288,6 @@
// clean up
Solar::$config = array();
Solar::$parents = array();
- Solar::$locale = null;
// reset the status flag, and we're done.
Solar::$_status = false;
More information about the Solar-svn
mailing list