getByUri shorthand function for Managed_DataObject (with uri)
This commit is contained in:
parent
7978cd6d59
commit
42a62da764
@ -383,6 +383,9 @@ abstract class Managed_DataObject extends Memcached_DataObject
|
||||
|
||||
static function getByID($id)
|
||||
{
|
||||
if (!property_exists(get_called_class(), 'id')) {
|
||||
throw new ServerException('Trying to get undefined property of dataobject class.');
|
||||
}
|
||||
if (empty($id)) {
|
||||
throw new EmptyPkeyValueException(get_called_class(), 'id');
|
||||
}
|
||||
@ -391,6 +394,24 @@ abstract class Managed_DataObject extends Memcached_DataObject
|
||||
return static::getByPK(array('id' => $id));
|
||||
}
|
||||
|
||||
static function getByUri($uri)
|
||||
{
|
||||
if (!property_exists(get_called_class(), 'uri')) {
|
||||
throw new ServerException('Trying to get undefined property of dataobject class.');
|
||||
}
|
||||
if (empty($uri)) {
|
||||
throw new EmptyPkeyValueException(get_called_class(), 'uri');
|
||||
}
|
||||
|
||||
$class = get_called_class();
|
||||
$obj = new $class();
|
||||
$obj->uri = $uri;
|
||||
if (!$obj->find(true)) {
|
||||
throw new NoResultException($obj);
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ID, checked that it is set and reasonably valid
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user