* General - Added Base.php for general getters and setters * Application.php - Reverted bad pretty printing * database.class.php (legacy file) - Fixed Googlebot-blocking bogus constant reference * Database.php, Table.php - Support constructor parameters to override properties
/trunk/Base.php |
---|
0,0 → 1,65 |
<?php |
namespace de\pointedears; |
/** |
* Base class providing a generic getter and setter |
* |
* @author Thomas 'PointedEars' Lahn |
*/ |
abstract class Base |
{ |
/** |
* Retrieves a property value. |
* |
* @param string $name |
* Property name |
* @throws InvalidArgumentException |
* if the property does not exist or has no getter |
* @return mixed |
* Property value |
*/ |
public function __get ($name) |
{ |
$getter = 'get' . ucfirst($name); |
if (method_exists($this, $getter)) |
{ |
return $this->$getter(); |
} |
if (property_exists($this, "_$name")) |
{ |
throw new \InvalidArgumentException("Property '_$name' has no getter"); |
} |
throw new \InvalidArgumentException("No such property: '_$name'"); |
} |
/** |
* Sets a property value. |
* |
* @param string $name |
* Property name |
* @param mixed $value |
* Property value |
* @throws InvalidArgumentException |
* if the property does not exist or is read-only |
* @return mixed |
* Return value of the property-specific setter |
*/ |
public function __set ($name, $value) |
{ |
$setter = 'set' . ucfirst($name); |
if (method_exists($this, $setter)) |
{ |
return $this->$setter($value); |
} |
if (property_exists($this, "_$name")) |
{ |
throw new \InvalidArgumentException("Property '_$name' has no setter"); |
} |
throw new \InvalidArgumentException("No such property: '_$name'"); |
} |
} |
/trunk/Db/Database.php |
---|
95,8 → 95,44 |
*/ |
protected $_lastInsertId = ''; |
public function __construct() |
/** |
* Creates a new <code>Database</code> instance. |
* |
* Each of the parameters is optional and can also be given |
* by a protected property where the parameter name is preceded |
* by <code>_</code>. Parameter values overwrite the default |
* property values. It is recommended to use default property |
* values of inheriting classes except for small applications |
* and testing purposes. |
* |
* @param string $dsn |
* @param string $username |
* @param string $password |
* @param mixed $options |
*/ |
public function __construct($dsn = '', $username = null, |
$password = null, array $options = array()) |
{ |
if ($dsn !== '') |
{ |
$this->_dsn = $dsn; |
} |
if ($username !== null) |
{ |
$this->_username = $username; |
} |
if ($password !== null) |
{ |
$this->_password = $password; |
} |
if ($options) |
{ |
$this->_options = $options; |
} |
$this->_connection = |
new PDO($this->_dsn, $this->_username, $this->_password, $this->_options); |
} |
388,8 → 424,10 |
if (is_array($where) && $this->_isAssociativeArray($where)) |
{ |
/* FIXME: Export and reuse this */ |
foreach ($where as $column => $condition) |
{ |
/* TODO: Also handle function calls as keys */ |
if (is_array($condition) && $this->_isAssociativeArray($condition)) |
{ |
reset($condition); |
/trunk/Db/Table.php |
---|
1,5 → 1,6 |
<?php |
require_once __DIR__ . '/../Application.php'; |
require_once __DIR__ . '/../AbstractModel.php'; |
/** |
10,7 → 11,7 |
* ID of the last inserted row, or the last value from |
a sequence object, depending on the underlying driver. |
*/ |
abstract class Table extends AbstractModel |
class Table extends AbstractModel |
{ |
/** |
* Name of the table |
25,9 → 26,50 |
protected $_id = 'id'; |
public function __construct() |
/** |
* Creates a new <code>Table</code> instance. |
* |
* Each of the parameters is optional and can also be given |
* by a protected property where the parameter name is preceded |
* by <code>_</code>. Parameter values overwrite the default |
* property values. It is recommended to use default property |
* values of inheriting classes except for small applications |
* and testing purposes. |
* |
* @param Database $database |
* Database of the table (required in order to use a fitting |
* query language) |
* @param string $name |
* Table name |
* @param string $id |
* Name of the primary key column |
* @throws InvalidArgumentException |
*/ |
public function __construct(Database $database = null, $name = '', $id = '') |
{ |
$this->_database = Application::getInstance()->getDefaultDatabase(); |
if ($database === null) |
{ |
$this->_database = Application::getInstance()->getDefaultDatabase(); |
} |
else |
{ |
$this->_database = $database; |
} |
if ($name !== '') |
{ |
$this->_name = $name; |
} |
if (!$this->_name) |
{ |
throw new InvalidArgumentException('a table name is required'); |
} |
if ($id !== '') |
{ |
$this->_id = $id; |
} |
} |
/** |
/trunk/Db/database.class.php |
---|
1,6 → 1,6 |
<?php |
require_once __LIB__ . '/../global.inc'; |
require_once __DIR__ . '/../global.inc'; |
/* NOTE: Obsolete with autoloader */ |
//require_once 'Zend/Registry.php'; |
/trunk/Application.php |
---|
78,8 → 78,7 |
if (strpos($name, 'persistent') === 0) |
{ |
$class = get_class($this); |
return $class::${ |
$name}; |
return $class::${$name}; |
} |
$method = 'get' . ucfirst($name); |
/trunk/.settings/org.eclipse.php.core.prefs |
---|
1,5 → 1,2 |
#Tue Jun 14 23:13:36 CEST 2011 |
eclipse.preferences.version=1 |
include_path=0;/PHPX |
phpVersion=php5 |
useShortTags=false |