From 5e97fa864a671dd97e60ed258258e1b1d854504d Mon Sep 17 00:00:00 2001 From: Gregory Henry Date: Mon, 9 Mar 2015 15:23:05 -0700 Subject: [PATCH 1/3] Created class factory in Model class for subclassing Table. --- lib/Model.php | 8 ++++++++ lib/Table.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Model.php b/lib/Model.php index 36e0a4918..e036bbda3 100644 --- a/lib/Model.php +++ b/lib/Model.php @@ -279,6 +279,14 @@ public function __construct(array $attributes=array(), $guard_attributes=true, $ $this->invoke_callback('after_construct',false); } + + /** + * Factory method to facilitate subclassing of Table if desired. + */ + public static function get_table($model_class_name) + { + return new Table($model_class_name); + } /** * Magic method which delegates to read_attribute(). This handles firing off getter methods, diff --git a/lib/Table.php b/lib/Table.php index 5f08e1895..f4167b7c1 100644 --- a/lib/Table.php +++ b/lib/Table.php @@ -68,7 +68,7 @@ public static function load($model_class_name) { /* do not place set_assoc in constructor..it will lead to infinite loop due to relationships requesting the model's table, but the cache hasn't been set yet */ - self::$cache[$model_class_name] = new Table($model_class_name); + self::$cache[$model_class_name] = Model::get_table($model_class_name); self::$cache[$model_class_name]->set_associations(); } From 92bf645d4583b475316d4722c9b15f4f9de26964 Mon Sep 17 00:00:00 2001 From: Gregory Henry Date: Mon, 9 Mar 2015 15:44:30 -0700 Subject: [PATCH 2/3] Changed method name. --- lib/Model.php | 2 +- lib/Table.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Model.php b/lib/Model.php index e036bbda3..502590a3e 100644 --- a/lib/Model.php +++ b/lib/Model.php @@ -283,7 +283,7 @@ public function __construct(array $attributes=array(), $guard_attributes=true, $ /** * Factory method to facilitate subclassing of Table if desired. */ - public static function get_table($model_class_name) + public static function make_table($model_class_name) { return new Table($model_class_name); } diff --git a/lib/Table.php b/lib/Table.php index f4167b7c1..ca25c127e 100644 --- a/lib/Table.php +++ b/lib/Table.php @@ -68,7 +68,7 @@ public static function load($model_class_name) { /* do not place set_assoc in constructor..it will lead to infinite loop due to relationships requesting the model's table, but the cache hasn't been set yet */ - self::$cache[$model_class_name] = Model::get_table($model_class_name); + self::$cache[$model_class_name] = Model::make_table($model_class_name); self::$cache[$model_class_name]->set_associations(); } From afa0659c6bfbf8626b739087ac1ec4c0f38067da Mon Sep 17 00:00:00 2001 From: Gregory Henry Date: Tue, 10 Mar 2015 13:13:54 -0700 Subject: [PATCH 3/3] Changed method access level for subclassing. --- lib/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Table.php b/lib/Table.php index ca25c127e..e28585549 100644 --- a/lib/Table.php +++ b/lib/Table.php @@ -391,7 +391,7 @@ private function add_relationship($relationship) $this->relationships[$relationship->attribute_name] = $relationship; } - private function get_meta_data() + protected function get_meta_data() { // as more adapters are added probably want to do this a better way // than using instanceof but gud enuff for now