Skip to content

Commit

Permalink
MINOR If $containerClass passed in to DataObject::get() isn't DataList,
Browse files Browse the repository at this point in the history
use Deprecation::notice() instead of throwing a notice
  • Loading branch information
halkyon committed May 28, 2012
1 parent ed1373d commit 862d7f2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions model/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2618,15 +2618,15 @@ 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 = null, $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()");
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");
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());
Expand All @@ -2636,15 +2636,21 @@ public static function get($callerClass = null, $filter = "", $sort = "", $join

// 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);
if($containerClass != 'DataList') {
Deprecation::notice('3.0', '$containerClass argument is deprecated.');
}

$result = DataList::create($callerClass)->where($filter)->sort($sort);

if($limit && strpos($limit, ',') !== false) {
$limitArguments = explode(',', $limit);
$result->limit($limitArguments[1],$limitArguments[0]);
} elseif($limit) {
$result->limit($limit);
}

if($join) $result = $result->join($join);

$result->setDataModel(DataModel::inst());
return $result;
}
Expand Down

0 comments on commit 862d7f2

Please sign in to comment.