mirror of
https://github.com/dg/dibi.git
synced 2025-08-15 10:34:06 +02:00
improved reflection skills
This commit is contained in:
@@ -65,7 +65,7 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
* @param array columns
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator($offset = NULL, $limit = NULL, $cols = NULL)
|
||||
public function getIterator($offset = NULL, $limit = NULL)
|
||||
{
|
||||
return $this->connection->query('
|
||||
SELECT *
|
||||
|
@@ -111,16 +111,6 @@ class DibiDatabaseInfo extends DibiObject
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSequences()
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -289,7 +279,7 @@ class DibiTableInfo extends DibiObject
|
||||
{
|
||||
if ($this->columns === NULL) {
|
||||
$this->columns = array();
|
||||
foreach ($this->driver->getColumns($this->name) as $info) {
|
||||
foreach ($this->driver->getColumns($this->info['name']) as $info) {
|
||||
$this->columns[strtolower($info['name'])] = new DibiColumnInfo($this->driver, $info);
|
||||
}
|
||||
}
|
||||
@@ -305,15 +295,13 @@ class DibiTableInfo extends DibiObject
|
||||
if ($this->indexes === NULL) {
|
||||
$this->initColumns();
|
||||
$this->indexes = array();
|
||||
foreach ($this->driver->getIndexes($this->name) as $info) {
|
||||
$cols = array();
|
||||
foreach ($info['columns'] as $name) {
|
||||
$cols[] = $this->columns[strtolower($name)];
|
||||
foreach ($this->driver->getIndexes($this->info['name']) as $info) {
|
||||
foreach ($info['columns'] as $key => $name) {
|
||||
$info['columns'][$key] = $this->columns[strtolower($name)];
|
||||
}
|
||||
$name = $info['name'];
|
||||
$this->indexes[strtolower($name)] = new DibiIndexInfo($this, $name, $cols, $info['unique']);
|
||||
$this->indexes[strtolower($info['name'])] = new DibiIndexInfo($info);
|
||||
if (!empty($info['primary'])) {
|
||||
$this->primaryKey = $this->indexes[strtolower($name)];
|
||||
$this->primaryKey = $this->indexes[strtolower($info['name'])];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -343,7 +331,7 @@ class DibiColumnInfo extends DibiObject
|
||||
/** @var IDibiDriver */
|
||||
private $driver;
|
||||
|
||||
/** @var array (name, table, type, nativetype, size, precision, scale, nullable, default, autoincrement) */
|
||||
/** @var array (name, table, fullname, type, nativetype, size, nullable, default, autoincrement) */
|
||||
private $info;
|
||||
|
||||
|
||||
@@ -366,6 +354,16 @@ class DibiColumnInfo extends DibiObject
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTable()
|
||||
{
|
||||
return !empty($this->info['table']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return DibiTableInfo
|
||||
*/
|
||||
@@ -409,26 +407,6 @@ class DibiColumnInfo extends DibiObject
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPrecision()
|
||||
{
|
||||
return isset($this->info['precision']) ? (int) $this->info['precision'] : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getScale()
|
||||
{
|
||||
return isset($this->info['scale']) ? (int) $this->info['scale'] : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -452,11 +430,22 @@ class DibiColumnInfo extends DibiObject
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefaultValue()
|
||||
public function getDefault()
|
||||
{
|
||||
return isset($this->info['default']) ? $this->info['default'] : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return mixed
|
||||
*/
|
||||
public function getInfo($key)
|
||||
{
|
||||
return isset($this->info[$key]) ? $this->info[$key] : NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -513,22 +502,13 @@ class DibiForeignKeyInfo extends DibiObject
|
||||
*/
|
||||
class DibiIndexInfo extends DibiObject
|
||||
{
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var array of DibiColumnInfo */
|
||||
private $columns;
|
||||
|
||||
/** @var bool */
|
||||
private $unique;
|
||||
/** @var array (name, columns, unique, primary) */
|
||||
private $info;
|
||||
|
||||
|
||||
|
||||
public function __construct($name, array $columns, $unique)
|
||||
public function __construct(array $info)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->columns = $columns;
|
||||
$this->unique = (bool) $unique;
|
||||
$this->info = $info;
|
||||
}
|
||||
|
||||
|
||||
@@ -538,7 +518,7 @@ class DibiIndexInfo extends DibiObject
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
return $this->info['name'];
|
||||
}
|
||||
|
||||
|
||||
@@ -548,7 +528,7 @@ class DibiIndexInfo extends DibiObject
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->columns;
|
||||
return $this->info['columns'];
|
||||
}
|
||||
|
||||
|
||||
@@ -558,7 +538,18 @@ class DibiIndexInfo extends DibiObject
|
||||
*/
|
||||
public function isUnique()
|
||||
{
|
||||
return $this->unique;
|
||||
return !empty($this->info['unique']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPrimary()
|
||||
{
|
||||
return !empty($this->info['primary']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -216,7 +216,7 @@ class DibiFluent extends DibiObject
|
||||
* @param string flag name
|
||||
* @return bool
|
||||
*/
|
||||
final public function getFlag($flag, $value = TRUE)
|
||||
final public function getFlag($flag)
|
||||
{
|
||||
return isset($this->flags[strtoupper($flag)]);
|
||||
}
|
||||
|
@@ -124,7 +124,7 @@ abstract class DibiObject
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ abstract class DibiObject
|
||||
self::$extMethods[$pair[1]][''] = NULL;
|
||||
}
|
||||
}
|
||||
if ($name === NULL) return;
|
||||
if ($name === NULL) return NULL;
|
||||
}
|
||||
|
||||
$name = strtolower($name);
|
||||
@@ -189,7 +189,7 @@ abstract class DibiObject
|
||||
if ($callback !== NULL) { // works as setter
|
||||
$l[$class] = $callback;
|
||||
$l[''] = NULL;
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// works as getter
|
||||
|
@@ -169,9 +169,8 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
$cols = array();
|
||||
foreach ($this->metaCache as $col) {
|
||||
// intentional ==
|
||||
$name = $col['table'] == '' ? $col['name'] : ($col['table'] . '.' . $col['name']);
|
||||
foreach ($this->metaCache as $info) {
|
||||
$name = $info['fullname'];
|
||||
if (isset($cols[$name])) {
|
||||
$fix = 1;
|
||||
while (isset($cols[$name . '#' . $fix])) $fix++;
|
||||
@@ -539,7 +538,7 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
$cols = array();
|
||||
foreach ($this->metaCache as $info) {
|
||||
$cols[] = (!$withTables || $info['table'] === NULL) ? $info['name'] : ($info['table'] . '.' . $info['name']);
|
||||
$cols[] = $info[$withTables ? 'fullname' : 'name'];
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
@@ -147,9 +147,7 @@ abstract class DibiTable extends DibiObject
|
||||
'INSERT INTO %n', $this->name, '%v', $this->prepare($data)
|
||||
);
|
||||
|
||||
if ($this->primaryAutoIncrement) {
|
||||
return $this->connection->insertId();
|
||||
}
|
||||
return $this->primaryAutoIncrement ? $this->connection->insertId() : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -250,7 +250,7 @@ final class DibiTranslator extends DibiObject
|
||||
case 'by': // key ASC, key DESC
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$v = (is_string($v) && strcasecmp($v, 'desc')) || $v > 0 ? 'ASC' : 'DESC';
|
||||
$v = (is_string($v) && strncasecmp($v, 'd', 1)) || $v > 0 ? 'ASC' : 'DESC';
|
||||
$vx[] = $this->delimite($k) . ' ' . $v;
|
||||
} else {
|
||||
$vx[] = $this->delimite($v);
|
||||
|
Reference in New Issue
Block a user