]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
remove locator
authorAndrey Kutejko <andy128k@gmail.com>
Fri, 26 Jul 2013 15:16:52 +0000 (18:16 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Fri, 26 Jul 2013 15:16:52 +0000 (18:16 +0300)
14 files changed:
ipf/orm/access.php
ipf/orm/collection.php
ipf/orm/configurable.php
ipf/orm/hydrator.php
ipf/orm/hydrator/abstract.php
ipf/orm/hydrator/recorddriver.php
ipf/orm/locator.php [deleted file]
ipf/orm/locator/injectable.php [deleted file]
ipf/orm/manager.php
ipf/orm/null.php
ipf/orm/record.php
ipf/orm/record/iterator.php
ipf/orm/table.php
ipf/orm/validator.php

index 39ae5740f880b92b8dab50d6ad8ddd8c4c3f9779..d0a87d2fe26c716fd007b476acd7ffb1cbb2dd02 100644 (file)
@@ -1,6 +1,6 @@
 <?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)
     {
@@ -79,4 +79,4 @@ abstract class IPF_ORM_Access extends IPF_ORM_Locator_Injectable implements Arra
     {
         throw new IPF_ORM_Exception('Add is not supported for ' . get_class($this));
     }
-}
\ No newline at end of file
+}
index 2e89bf1eb0102780920b57b7166750e32f2f94b3..4ac8e3e969a6bc77fa6104b5c38b500e059112a6 100644 (file)
@@ -9,7 +9,6 @@ class IPF_ORM_Collection extends IPF_ORM_Access implements Countable, IteratorAg
     protected $referenceField;
     protected $relation;
     protected $keyColumn;
-    protected static $null;
 
     public function __construct($table, $keyColumn = null)
     {
@@ -32,11 +31,6 @@ class IPF_ORM_Collection extends IPF_ORM_Access implements Countable, IteratorAg
         }
     }
 
-    public static function initNullObject(IPF_ORM_Null $null)
-    {
-        self::$null = $null;
-    }
-
     public function getTable()
     {
         return $this->_table;
index 887b2b82c1131c7c3fe8238a1ef7b3e6c317432f..b629ec0fc168a51e160d07e3869cdefe631a23bc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-abstract class IPF_ORM_Configurable extends IPF_ORM_Locator_Injectable
+abstract class IPF_ORM_Configurable
 {
     protected $attributes = array();
     protected $parent;
index 70a17ce95e57d471725a669d757c10a27826ccad..a4bb6bf4c5adcf682ab95eeb1330f1187031285d 100644 (file)
@@ -183,7 +183,7 @@ class IPF_ORM_Hydrator extends IPF_ORM_Hydrator_Abstract
 
     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;
         }
index 47d71aabda9cef7abdc0cd0b8ada6968fbbbf7ae..497d2ca56c8dac590297c14a1d1bfd4f0f525f0e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-abstract class IPF_ORM_Hydrator_Abstract extends IPF_ORM_Locator_Injectable
+abstract class IPF_ORM_Hydrator_Abstract
 {
     protected $_queryComponents = array();
 
@@ -29,4 +29,4 @@ abstract class IPF_ORM_Hydrator_Abstract extends IPF_ORM_Locator_Injectable
     }
 
     abstract public function hydrateResultSet($stmt, $tableAliases);
-}
\ No newline at end of file
+}
index c020cd992f07b9a3d66ce2e746222cd7a7b84d8d..c415723e4656bedffa37c3e0645e781cf05b9499 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-class IPF_ORM_Hydrator_RecordDriver extends IPF_ORM_Locator_Injectable
+class IPF_ORM_Hydrator_RecordDriver
 {
     protected $_collections = array();
     protected $_tables = array();
@@ -38,9 +38,9 @@ class IPF_ORM_Hydrator_RecordDriver extends IPF_ORM_Locator_Injectable
         $this->_collections[] = $coll;
     }
     
-    public function getNullPointer() 
+    public function getNullPointer()
     {
-        return self::$_null;
+        return IPF_ORM_Null::getInstance();
     }
     
     public function getElement(array $data, $component)
diff --git a/ipf/orm/locator.php b/ipf/orm/locator.php
deleted file mode 100644 (file)
index aaf4998..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-<?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);
-    }
-}
diff --git a/ipf/orm/locator/injectable.php b/ipf/orm/locator/injectable.php
deleted file mode 100644 (file)
index 69460d9..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?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
index ddeaaf79b15e78cace860a8732a829d10bdfa251..74d68fe3cb0cc2644cf1e59824b4b0f0c8e04ef4 100644 (file)
@@ -11,8 +11,6 @@ class IPF_ORM_Manager extends IPF_ORM_Configurable implements Countable, Iterato
 
     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",
index 20e813d66ea4091026dc2127cf45e9d8ddcdddde..6347618b62602afa7fe2f8fa6ab407e0f91f01bb 100644 (file)
@@ -1,13 +1,36 @@
 <?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
+}
+
index e618d8bdb62cf3cd98546f4035cb1f8a6fef156a..57b9f279e21886064fe115bf55275a8da5be2935 100644 (file)
@@ -165,7 +165,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
                 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;
@@ -182,9 +182,9 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
             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]);
         }
@@ -210,7 +210,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
                     $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];
                     }
                 }
@@ -219,7 +219,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
                 $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];
@@ -248,7 +248,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
         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)) {
@@ -424,7 +424,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
         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;
         }
 
@@ -444,14 +444,13 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
 
     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];
@@ -503,7 +502,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
 
             if ($this->_isValueModified($type, $old, $value)) {
                 if ($value === null) {
-                    $value = self::$_null;
+                    $value = IPF_ORM_Null::getInstance();
                 }
 
                 $this->_data[$fieldName] = $value;
@@ -546,7 +545,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
         $rel = $this->_table->getRelation($name);
 
         if ($value === null) {
-            $value = self::$_null;
+            $value = IPF_ORM_Null::getInstance();
         }
 
         // one-to-many or one-to-one relation
@@ -561,7 +560,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
                     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());
@@ -605,9 +604,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
         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;
@@ -620,7 +617,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
         } 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());
@@ -695,7 +692,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
         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;
             }
@@ -766,7 +763,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
         $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;
             }
 
@@ -780,7 +777,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
 
         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);
                 }
             }
@@ -911,7 +908,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
         $modified = array();
 
         foreach ($data as $key => $val) {
-            if ( ! ($val instanceof IPF_ORM_Null)) {
+            if (!IPF_ORM_Null::isNull($val)) {
                 $ret->_modified[] = $key;
             }
         }
@@ -1185,7 +1182,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
 
             if ($deep) {
                 foreach ($this->_references as $name => $reference) {
-                    if ( ! ($reference instanceof IPF_ORM_Null)) {
+                    if (!IPF_ORM_Null::isNull($reference)) {
                         $reference->free($deep);
                     }
                 }
index c070cfb7df2e2661a485968c8a465150af3b2390..505a9906a6c2a95d6cf643b2785674dafc868dad 100644 (file)
@@ -3,26 +3,22 @@
 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
+}
+
index 9ea227d98eefc2d24c4d732a32ff6c744bc5ebaa..325c90d48f5917cc176d6900a4e9201345cd4d25 100644 (file)
@@ -844,7 +844,7 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable
 
     public function enumValue($fieldName, $index)
     {
-        if ($index instanceof IPF_ORM_Null) {
+        if (IPF_ORM_Null::isNull($index)) {
             return $index;
         }
 
@@ -942,8 +942,8 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable
 
     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 {
index 497678e674b6138483bc890f211a787dae8400c8..526471e354d41cdab4c2629d7ead67facd94e757 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-class IPF_ORM_Validator extends IPF_ORM_Locator_Injectable
+class IPF_ORM_Validator
 {
     private static $validators = array();
     public static function getValidator($name)
@@ -33,7 +33,7 @@ class IPF_ORM_Validator extends IPF_ORM_Locator_Injectable
 
     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();