Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

API CHANGE: Allow <classname>::get(), eg, Member::get()->byID(5)

  • Loading branch information...
commit 8e48e6e23185d5eefca342978fcb2c00dbf9fca4 1 parent 33ae836
Sam Minnée sminnee authored
Showing with 34 additions and 1 deletion.
  1. +16 −1 model/DataObject.php
  2. +18 −0 tests/model/DataObjectTest.php
17 model/DataObject.php
View
@@ -2488,7 +2488,22 @@ public function extendedSQL($filter = "", $sort = "", $limit = "", $join = ""){
*
* @return mixed The objects matching the filter, in the class specified by $containerClass
*/
- public static function get($callerClass, $filter = "", $sort = "", $join = "", $limit = null, $containerClass = "DataList") {
+ public static function get($callerClass = null, $filter = "", $sort = "", $join = "", $limit = null, $containerClass = "DataList") {
+ if($callerClass == null) {
+ $callerClass = get_called_class();
+ if($callerClass == 'DataObject') {
+ throw new \InvalidArgumentException("Call <classname>::get() instead of DataObject::get()");
+ }
+
+ if($filter || $sort || $join || $limit || ($containerClass != "DataList")) {
+ throw new \InvalidArgumentException("If calling <classname>::get() then you shouldn't pass any other arguments");
+ }
+
+ $result = DataList::create(get_called_class());
+ $result->setModel(DataModel::inst());
+ return $result;
+ }
+
// Todo: Determine if we can deprecate for 3.0.0 and use DI or something instead
// Todo: Make the $containerClass method redundant
if($containerClass != "DataList") user_error("The DataObject::get() \$containerClass argument has been deprecated", E_USER_NOTICE);
18 tests/model/DataObjectTest.php
View
@@ -1036,6 +1036,24 @@ function testRelObject() {
$this->assertEquals("Team 1", $player->relObject('Teams.First.Title')->getValue());
}
+ function testLateStaticBindingStyle() {
+ // Confirm that DataObjectTest_Player::get() operates as excepted
+ $this->assertEquals(4, DataObjectTest_Player::get()->Count());
+ $this->assertInstanceOf('DataObjectTest_Player', DataObjectTest_Player::get()->First());
+
+ // You can't pass arguments to LSB syntax - use the DataList methods instead.
+ $this->setExpectedException('InvalidArgumentException');
+ DataObjectTest_Player::get(null, "\"ID\" = 1");
+
+ }
+
+ function testBrokenLateStaticBindingStyle() {
+ // If you call DataObject::get() you have to pass a first argument
+ $this->setExpectedException('InvalidArgumentException');
+ DataObject::get();
+
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.