<?php
-abstract class IPF_ORM_Access extends IPF_ORM_Locator_Injectable implements ArrayAccess
+abstract class IPF_ORM_Access implements ArrayAccess
{
public function setArray(array $array)
{
{
throw new IPF_ORM_Exception('Add is not supported for ' . get_class($this));
}
-}
\ No newline at end of file
+}
protected $referenceField;
protected $relation;
protected $keyColumn;
- protected static $null;
public function __construct($table, $keyColumn = null)
{
}
}
- public static function initNullObject(IPF_ORM_Null $null)
- {
- self::$null = $null;
- }
-
public function getTable()
{
return $this->_table;
<?php
-abstract class IPF_ORM_Configurable extends IPF_ORM_Locator_Injectable
+abstract class IPF_ORM_Configurable
{
protected $attributes = array();
protected $parent;
protected function _setLastElement(&$prev, &$coll, $index, $dqlAlias, $oneToOne)
{
- if ($coll === self::$_null || $coll === null) {
+ if (IPF_ORM_Null::isNull($coll) || $coll === null) {
unset($prev[$dqlAlias]); // Ticket #1228
return;
}
<?php
-abstract class IPF_ORM_Hydrator_Abstract extends IPF_ORM_Locator_Injectable
+abstract class IPF_ORM_Hydrator_Abstract
{
protected $_queryComponents = array();
}
abstract public function hydrateResultSet($stmt, $tableAliases);
-}
\ No newline at end of file
+}
<?php
-class IPF_ORM_Hydrator_RecordDriver extends IPF_ORM_Locator_Injectable
+class IPF_ORM_Hydrator_RecordDriver
{
protected $_collections = array();
protected $_tables = array();
$this->_collections[] = $coll;
}
- public function getNullPointer()
+ public function getNullPointer()
{
- return self::$_null;
+ return IPF_ORM_Null::getInstance();
}
public function getElement(array $data, $component)
+++ /dev/null
-<?php
-
-class IPF_ORM_Locator implements Countable, IteratorAggregate
-{
- protected $_resources = array();
- protected $_classPrefix = 'IPF_ORM_';
- protected static $_instances = array();
- public function __construct(array $defaults = null)
- {
- if (null !== $defaults) {
- foreach ($defaults as $name => $resource) {
- if ($resource instanceof IPF_ORM_Locator_Injectable) {
- $resource->setLocator($this);
- }
- $this->_resources[$name] = $resource;
- }
- }
- self::$_instances[] = $this;
- }
-
- public static function instance()
- {
- if (empty(self::$_instances)) {
- $obj = new IPF_ORM_Locator();
- }
- return current(self::$_instances);
- }
-
- public function setClassPrefix($prefix)
- {
- $this->_classPrefix = $prefix;
- }
-
- public function getClassPrefix()
- {
- return $this->_classPrefix;
- }
-
- public function contains($name)
- {
- return isset($this->_resources[$name]);
- }
-
- public function bind($name, $value)
- {
- $this->_resources[$name] = $value;
-
- return $this;
- }
-
- public function locate($name)
- {
- if (isset($this->_resources[$name])) {
- return $this->_resources[$name];
- } else {
- $className = $name;
-
- if ( ! class_exists($className)) {
-
- $name = explode('.', $name);
- $name = array_map('strtolower', $name);
- $name = array_map('ucfirst', $name);
- $name = implode('_', $name);
-
- $className = $this->_classPrefix . $name;
-
- if ( ! class_exists($className)) {
- throw new IPF_ORM_Exception_Locator("Couldn't locate resource " . $className);
- }
- }
-
- $this->_resources[$name] = new $className();
-
- if ($this->_resources[$name] instanceof IPF_ORM_Locator_Injectable) {
- $this->_resources[$name]->setLocator($this);
- }
-
- return $this->_resources[$name];
- }
-
- throw new IPF_ORM_Exception_Locator("Couldn't locate resource " . $name);
- }
-
- public function count()
- {
- return count($this->_resources);
- }
-
- public function getIterator()
- {
- return new ArrayIterator($this->_resources);
- }
-}
+++ /dev/null
-<?php
-
-class IPF_ORM_Locator_Injectable
-{
- protected $_locator;
- protected $_resources = array();
-
- protected static $_null;
-
- public function setLocator(IPF_ORM_Locator $locator)
- {
- $this->_locator = $locator;
- return $this;
- }
-
- public function getLocator()
- {
- if ( ! isset($this->_locator)) {
- $this->_locator = IPF_ORM_Locator::instance();
-
- }
- return $this->_locator;
- }
-
- public function locate($name)
- {
- if (isset($this->_resources[$name])) {
- if (is_object($this->_resources[$name])) {
- return $this->_resources[$name];
- } else {
- // get the name of the concrete implementation
- $concreteImpl = $this->_resources[$name];
-
- return $this->getLocator()->locate($concreteImpl);
- }
- } else {
- return $this->getLocator()->locate($name);
- }
- }
-
- public function bind($name, $resource)
- {
- $this->_resources[$name] = $resource;
-
- return $this;
- }
-
- public static function initNullObject(IPF_ORM_Null $null)
- {
- self::$_null = $null;
- }
-
- public static function getNullObject()
- {
- return self::$_null;
- }
-}
\ No newline at end of file
private function __construct()
{
- IPF_ORM_Locator_Injectable::initNullObject(new IPF_ORM_Null);
-
$this->attributes = array(
IPF_ORM::ATTR_LOAD_REFERENCES => true,
IPF_ORM::ATTR_IDXNAME_FORMAT => "%s_idx",
<?php
final class IPF_ORM_Null
-{
+{
+ private static $instance = null;
+ public static function getInstance()
+ {
+ if (!self::$instance)
+ self::$instance = new IPF_ORM_Null;
+ return self::$instance;
+ }
+
+ private function __construct()
+ {
+ }
+
+ private function __clone()
+ {
+ }
+
+ public static function isNull($obj)
+ {
+ return $obj === self::$instance;
+ }
+
public function exists()
{
- return false;
+ return false;
}
+
public function __toString()
{
return '';
}
-}
\ No newline at end of file
+}
+
continue;
}
- if ($value === self::$_null || $overwrite) {
+ if (IPF_ORM_Null::isNull($value) || $overwrite) {
$this->_data[$column] = $default;
$this->_modified[] = $column;
$this->_state = IPF_ORM_Record::STATE_TDIRTY;
if (isset($tmp[$fieldName])) {
$data[$fieldName] = $tmp[$fieldName];
} else if (array_key_exists($fieldName, $tmp)) {
- $data[$fieldName] = self::$_null;
+ $data[$fieldName] = IPF_ORM_Null::getInstance();
} else if (!isset($this->_data[$fieldName])) {
- $data[$fieldName] = self::$_null;
+ $data[$fieldName] = IPF_ORM_Null::getInstance();
}
unset($tmp[$fieldName]);
}
$name = $name[0];
}
if ($exists) {
- if (isset($this->_data[$name]) && $this->_data[$name] !== self::$_null) {
+ if (isset($this->_data[$name]) && !IPF_ORM_Null::isNull($this->_data[$name])) {
$this->_id[$name] = $this->_data[$name];
}
}
$names = $this->_table->getIdentifier();
foreach ($names as $name) {
- if ($this->_data[$name] === self::$_null) {
+ if (IPF_ORM_Null::isNull($this->_data[$name])) {
$this->_id[$name] = null;
} else {
$this->_id[$name] = $this->_data[$name];
foreach ($this->_data as $k => $v) {
if ($v instanceof IPF_ORM_Record && $this->_table->getTypeOf($k) != 'object') {
unset($vars['_data'][$k]);
- } elseif ($v === self::$_null) {
+ } elseif (IPF_ORM_Null::isNull($v)) {
unset($vars['_data'][$k]);
} else {
switch ($this->_table->getTypeOf($k)) {
if ( ! isset($this->_data[$fieldName])) {
throw new IPF_ORM_Exception('Unknown property '. $fieldName);
}
- if ($this->_data[$fieldName] === self::$_null) {
+ if (IPF_ORM_Null::isNull($this->_data[$fieldName])) {
return null;
}
public function get($fieldName, $load = true)
{
- $value = self::$_null;
+ $value = IPF_ORM_Null::getInstance();
if (isset($this->_data[$fieldName])) {
- // check if the value is the IPF_ORM_Null object located in self::$_null)
- if ($this->_data[$fieldName] === self::$_null && $load) {
+ if (IPF_ORM_Null::isNull($this->_data[$fieldName]) && $load) {
$this->load();
}
- if ($this->_data[$fieldName] === self::$_null) {
+ if (IPF_ORM_Null::isNull($this->_data[$fieldName])) {
$value = null;
} else {
$value = $this->_data[$fieldName];
if ($this->_isValueModified($type, $old, $value)) {
if ($value === null) {
- $value = self::$_null;
+ $value = IPF_ORM_Null::getInstance();
}
$this->_data[$fieldName] = $value;
$rel = $this->_table->getRelation($name);
if ($value === null) {
- $value = self::$_null;
+ $value = IPF_ORM_Null::getInstance();
}
// one-to-many or one-to-one relation
return $this;
}
} else {
- if ($value !== self::$_null) {
+ if (!IPF_ORM_Null::isNull($value)) {
$relatedTable = $value->getTable();
$foreignFieldName = $relatedTable->getFieldName($rel->getForeign());
$localFieldName = $this->_table->getFieldName($rel->getLocal());
if (isset($this->_values[$fieldName])) {
return true;
}
- if (isset($this->_references[$fieldName]) &&
- $this->_references[$fieldName] !== self::$_null) {
-
+ if (isset($this->_references[$fieldName]) && !IPF_ORM_Null::isNull($this->_references[$fieldName])) {
return true;
}
return false;
} else if (isset($this->_references[$name])) {
if ($this->_references[$name] instanceof IPF_ORM_Record) {
$this->_pendingDeletes[] = $this->$name;
- $this->_references[$name] = self::$_null;
+ $this->_references[$name] = IPF_ORM_Null::getInstance();
} elseif ($this->_references[$name] instanceof IPF_ORM_Collection) {
$this->_pendingDeletes[] = $this->$name;
$this->_references[$name]->setData(array());
foreach ($modifiedFields as $field) {
$type = $this->_table->getTypeOf($field);
- if ($this->_data[$field] === self::$_null) {
+ if (IPF_ORM_Null::isNull($this->_data[$field])) {
$a[$field] = null;
continue;
}
$a = array();
foreach ($this as $column => $value) {
- if ($value === self::$_null || is_object($value)) {
+ if (IPF_ORM_Null::isNull($value) || is_object($value)) {
$value = null;
}
if ($deep) {
foreach ($this->_references as $key => $relation) {
- if (! $relation instanceof IPF_ORM_Null) {
+ if (!IPF_ORM_Null::isNull($relation)) {
$a[$key] = $relation->toArray($deep, $prefixKey);
}
}
$modified = array();
foreach ($data as $key => $val) {
- if ( ! ($val instanceof IPF_ORM_Null)) {
+ if (!IPF_ORM_Null::isNull($val)) {
$ret->_modified[] = $key;
}
}
if ($deep) {
foreach ($this->_references as $name => $reference) {
- if ( ! ($reference instanceof IPF_ORM_Null)) {
+ if (!IPF_ORM_Null::isNull($reference)) {
$reference->free($deep);
}
}
class IPF_ORM_Record_Iterator extends ArrayIterator
{
private $record;
- private static $null;
+
public function __construct(IPF_ORM_Record $record)
{
$this->record = $record;
parent::__construct($record->getData());
}
- public static function initNullObject(IPF_ORM_Null $null)
- {
- self::$null = $null;
- }
-
public function current()
{
$value = parent::current();
- if ($value === self::$null) {
+ if (IPF_ORM_Null::isNull($value)) {
return null;
} else {
return $value;
}
}
-}
\ No newline at end of file
+}
+
public function enumValue($fieldName, $index)
{
- if ($index instanceof IPF_ORM_Null) {
+ if (IPF_ORM_Null::isNull($index)) {
return $index;
}
public function prepareValue($fieldName, $value, $typeHint = null)
{
- if ($value === self::$_null) {
- return self::$_null;
+ if (IPF_ORM_Null::isNull($value)) {
+ return $value;
} else if ($value === null) {
return null;
} else {
<?php
-class IPF_ORM_Validator extends IPF_ORM_Locator_Injectable
+class IPF_ORM_Validator
{
private static $validators = array();
public static function getValidator($name)
private function validateField(IPF_ORM_Table $table, $fieldName, $value, IPF_ORM_Record $record)
{
- if ($value === self::$_null) {
+ if (IPF_ORM_Null::isNull($value)) {
$value = null;
} else if ($value instanceof IPF_ORM_Record) {
$value = $value->getIncremented();