00001 <?php
00044 require_once 'Object/Freezer/HashGenerator.php';
00045 require_once 'Object/Freezer/Util.php';
00046
00058 class Object_Freezer_HashGenerator_NonRecursiveSHA1 implements Object_Freezer_HashGenerator
00059 {
00063 protected $idGenerator;
00064
00070 public function __construct(Object_Freezer_IdGenerator $idGenerator)
00071 {
00072 $this->idGenerator = $idGenerator;
00073 }
00074
00084 public function getHash($object)
00085 {
00086
00087 if (!is_object($object)) {
00088 throw Object_Freezer_Util::getInvalidArgumentException(1, 'object');
00089 }
00090
00091 $attributes = Object_Freezer_Util::readAttributes($object);
00092 ksort($attributes);
00093
00094 if (isset($attributes['__php_object_freezer_hash'])) {
00095 unset($attributes['__php_object_freezer_hash']);
00096 }
00097
00098 foreach ($attributes as $key => $value) {
00099 if (is_array($value)) {
00100 $attributes[$key] = '<array>';
00101 }
00102
00103 else if (is_object($value)) {
00104 if (!isset($value->__php_object_freezer_uuid)) {
00105 $value->__php_object_freezer_uuid = $this->idGenerator->getId();
00106 }
00107
00108 $attributes[$key] = $value->__php_object_freezer_uuid;
00109 }
00110
00111 else if (is_resource($value)) {
00112 $attributes[$key] = NULL;
00113 }
00114 }
00115
00116 return sha1(get_class($object) . join(':', $attributes));
00117 }
00118 }