From 2e420522ece22942a9b3b6ee413ca0e1dfa76148 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 13:22:24 -0800 Subject: Preliminary work to cut over to Kohana 2.4 - Kohana::log() -> Kohana_Log::add() - Kohana::config_XXX -> Kohana_Config::instance()->XXX - Implement View::set_global in MY_View - Updated Cache_Database_Driver to latest APIs - ORM::$loaded -> ORM::loaded() - Updated item::viewable() to use K2.4 parenthesization --- modules/gallery/libraries/MY_View.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'modules/gallery/libraries/MY_View.php') diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index eb55aca6..0311f2dd 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -18,6 +18,31 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class View extends View_Core { + static $global_data; + + /** + * Reimplement Kohana 2.3's View::set_global() functionality. + */ + public function set_global($key, $value) { + View::$global_data->$key = $value; + $this->$key = $value; + } + + public function __isset($key) { + if (isset(View::$global_data->$key)) { + return true; + } + return parent::__isset($key); + } + + public function &__get($key) { + Kohana_Log::add("error",print_r("__get($key)",1)); + if (isset(View::$global_data->$key)) { + return View::$global_data->$key; + } + return parent::__get($key); + } + /** * Override View_Core::__construct so that we can set the csrf value into all views. * @@ -38,7 +63,7 @@ class View extends View_Core { try { return parent::render($print, $renderer); } catch (Exception $e) { - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); return ""; } } -- cgit v1.2.3 From daedadda751a188c20f032b09c1ca32e39279360 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 14:27:06 -0800 Subject: Switch from stdClass to arrays for global data. --- modules/gallery/libraries/MY_View.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'modules/gallery/libraries/MY_View.php') diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index 0311f2dd..d1ec6684 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -18,27 +18,26 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class View extends View_Core { - static $global_data; + static $global_data = array(); /** * Reimplement Kohana 2.3's View::set_global() functionality. */ public function set_global($key, $value) { - View::$global_data->$key = $value; + View::$global_data[$key] = $value; $this->$key = $value; } public function __isset($key) { - if (isset(View::$global_data->$key)) { + if (array_key_exists($key, View::$global_data)) { return true; } return parent::__isset($key); } public function &__get($key) { - Kohana_Log::add("error",print_r("__get($key)",1)); - if (isset(View::$global_data->$key)) { - return View::$global_data->$key; + if (array_key_exists($key, View::$global_data)) { + return View::$global_data[$key]; } return parent::__get($key); } -- cgit v1.2.3 From 7eacc465d53d08ced85114b0a4ddc26b3fed848e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 14:50:29 -0800 Subject: Fix set_global() to be more elegant and preserve local trumping --- modules/gallery/libraries/MY_View.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'modules/gallery/libraries/MY_View.php') diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index d1ec6684..45aae188 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -25,21 +25,6 @@ class View extends View_Core { */ public function set_global($key, $value) { View::$global_data[$key] = $value; - $this->$key = $value; - } - - public function __isset($key) { - if (array_key_exists($key, View::$global_data)) { - return true; - } - return parent::__isset($key); - } - - public function &__get($key) { - if (array_key_exists($key, View::$global_data)) { - return View::$global_data[$key]; - } - return parent::__get($key); } /** @@ -58,9 +43,10 @@ class View extends View_Core { * * @see View_Core::render */ - public function render($print=false, $renderer=false) { + public function render($print=false, $renderer=false, $modifier=false) { try { - return parent::render($print, $renderer); + $this->kohana_local_data = array_merge(View::$global_data, $this->kohana_local_data); + return parent::render($print, $renderer, $modifier); } catch (Exception $e) { Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); return ""; -- cgit v1.2.3 From ccb0ea3d30a114c069240453d7d85f18328db6e5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 19:24:50 -0800 Subject: Make globals work if you access the the variables directly with $v->foo instead of doing it in a rendered template. --- modules/gallery/libraries/MY_View.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'modules/gallery/libraries/MY_View.php') diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index 45aae188..cec59ec1 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -27,6 +27,26 @@ class View extends View_Core { View::$global_data[$key] = $value; } + public function is_set($key) { + return parent::is_set($key) ? true : array_key_exists($key, View::$global_data); + } + + /** + * Completely replace View_Core::__get() so that local data trumps global data, trumps members. + * This simulates the Kohana 2.3 behavior. + */ + public function &__get($key) { + if (isset($this->kohana_local_data[$key])) { + return $this->kohana_local_data[$key]; + } else if (isset(View::$global_data[$key])) { + return View::$global_data[$key]; + } else if (isset($this->$key)) { + return $this->$key; + } else { + throw new Kohana_Exception('Undefined view variable: :var', array(':var' => $key)); + } + } + /** * Override View_Core::__construct so that we can set the csrf value into all views. * -- cgit v1.2.3