From 8b79d08a56615c5af4ec5690371aba8d97c56f14 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 16 May 2013 13:17:53 +0300 Subject: [PATCH 1/6] Update paris.php Makes working with models more beautiful (in my opinion). :-) Examples: User::find_many(); User::where('name', 'lapayo')->find_one(); --- paris.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/paris.php b/paris.php index 66df9589..87a04b54 100644 --- a/paris.php +++ b/paris.php @@ -447,4 +447,15 @@ public function id() { public function hydrate($data) { $this->orm->hydrate($data)->force_all_dirty(); } + + /** + * Calls static methods directly on the ORMWrapper + * + */ + public static function __callStatic($method, $parameters) + { + $model = static::factory(get_called_class()); + + return call_user_func_array(array($model, $method), $parameters); + } } From a94a2ee0036531a78fc011509c17156a7daf2ae0 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 16 May 2013 14:43:39 +0300 Subject: [PATCH 2/6] Update paris.php Keep compatibility with php 5.2 --- paris.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/paris.php b/paris.php index 87a04b54..e957657c 100644 --- a/paris.php +++ b/paris.php @@ -454,8 +454,10 @@ public function hydrate($data) { */ public static function __callStatic($method, $parameters) { - $model = static::factory(get_called_class()); + if(function_exists('get_called_class')) { + $model = static::factory(get_called_class()); - return call_user_func_array(array($model, $method), $parameters); + return call_user_func_array(array($model, $method), $parameters); + } } } From 15211c466c3a1d1a5ae43b434e09b568db7904a4 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 16 May 2013 13:48:15 +0200 Subject: [PATCH 3/6] Update querying.rst --- docs/querying.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/querying.rst b/docs/querying.rst index e43a8812..62f6bdd4 100644 --- a/docs/querying.rst +++ b/docs/querying.rst @@ -27,6 +27,18 @@ record by its primary key ID: find_one($id); +If you are using PHP 5.3+ you can also do the following: + +.. code-block:: php + + where_gte('age', 20) + ->find_many(); + +This does the same as the example above but is shorter and more readable. + + The only differences between using Idiorm and using Paris for querying are as follows: @@ -150,4 +162,4 @@ be returned. // Returns array('first_name' => 'Fred', 'age' => 50) $data = $person->as_array('first_name', 'age'); -.. _Idiorm: http://github.com/j4mie/idiorm/ \ No newline at end of file +.. _Idiorm: http://github.com/j4mie/idiorm/ From af17faf42ba7ef4b3af2b94d4795d53655847137 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 16 May 2013 14:49:13 +0300 Subject: [PATCH 4/6] Update paris.php --- paris.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paris.php b/paris.php index e957657c..578a328e 100644 --- a/paris.php +++ b/paris.php @@ -455,7 +455,7 @@ public function hydrate($data) { public static function __callStatic($method, $parameters) { if(function_exists('get_called_class')) { - $model = static::factory(get_called_class()); + $model = self::factory(get_called_class()); return call_user_func_array(array($model, $method), $parameters); } From 75a7d1204acc4f566946c3a03c02e6731f056206 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 16 May 2013 14:59:08 +0300 Subject: [PATCH 5/6] Update ParisTest53.php --- test/ParisTest53.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/ParisTest53.php b/test/ParisTest53.php index 4af49933..789dc1d7 100644 --- a/test/ParisTest53.php +++ b/test/ParisTest53.php @@ -30,10 +30,16 @@ public function testModelWithCustomTable() { $expected = 'SELECT * FROM `custom_table`'; $this->assertEquals($expected, ORM::get_last_query()); } + + public function testShortcut() { + \Paris\Tests\Simple::find_many(); + $expected = 'SELECT * FROM `paris_tests_simple`'; + $this->assertEquals($expected, ORM::get_last_query()); + } } class Simple extends Model { } class ModelWithCustomTable extends Model { public static $_table = 'custom_table'; -} \ No newline at end of file +} From fc9fe66a2151747f2be213cdec83c9ac205f7320 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 16 May 2013 15:06:03 +0300 Subject: [PATCH 6/6] Update README.markdown --- README.markdown | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.markdown b/README.markdown index abdc6528..be44b92e 100644 --- a/README.markdown +++ b/README.markdown @@ -62,6 +62,18 @@ foreach ($tweets as $tweet) { } ``` +Users who have PHP 5.3+ can simply do the following: +```php +$user = User::where_equal('username', 'j4mie') + ->find_one(); +``` +instead of: +```php +$user = Model::factory('User') + ->where_equal('username', 'j4mie') + ->find_one(); +``` + Changelog ---------