Subversion Repositories PHPX

Compare Revisions

Last modification

Regard whitespace Rev 49 → Rev 50

/trunk/Db/Table.php
7,6 → 7,7
* Generic database table model class
*
* @author Thomas Lahn
* @property Database $database
* @property-read int $lastInsertId
* ID of the last inserted row, or the last value from
a sequence object, depending on the underlying driver.
20,7 → 21,7
/**
* Database of the table
* @var Database
* @var Database|string
*/
protected $_database;
45,12 → 46,16
* Name of the primary key column
* @throws InvalidArgumentException
*/
public function __construct(Database $database = null, $name = '', $id = '')
public function __construct($database = null, $name = '', $id = '')
{
if ($database === null)
{
/* Call getter to convert to Database if possible */
if ($this->database === null)
{
$this->_database = Application::getInstance()->getDefaultDatabase();
}
}
else
{
$this->_database = $database;
61,9 → 66,11
$this->_name = $name;
}
if (!$this->_name)
if (!\is_string($this->_name))
{
throw new InvalidArgumentException('a table name is required');
throw new \InvalidArgumentException(
'Expected string for table name, saw '
. \get_class($this->_name) || \gettype($this->_name));
}
 
if ($id !== '')
78,10 → 85,41
*/
public function getDatabase()
{
if (\is_string($this->_database))
{
/* Call setter to convert to Database */
$this->database = $this->_database;
}
 
return $this->_database;
}
/**
* @param Database|string $value
* @throws InvalidArgumentException
*/
public function setDatabase ($value)
{
if ($value instanceof Database)
{
$this->_database = $value;
}
else if ($value !== null)
{
$database = new $value();
if (!($database instanceof Database))
{
throw new \InvalidArgumentException(
'Expected Database instance or string for class name, saw '
. (\get_class($value) || \gettype($value))
);
}
 
$this->_database = $database;
}
}
 
/**
* Initiates a transaction
*
* @return bool
187,11 → 225,11
*/
public function delete($id, array $condition = null)
{
if (!is_null($id))
if ($id !== null)
{
$condition = array($this->_id => $id);
}
else if (is_null($condition))
else if ($condition === null)
{
throw new InvalidArgumentException(
'$id and $condition cannot both be null');