34 private $_strVal = null;
36 private static $_dummyIdPattern =
'wcmf[A-Za-z0-9]{32}';
37 private static $_idPattern = null;
38 private static $_delimiterPattern = null;
39 private static $_numPkKeys = array();
41 private static $_nullOID = null;
55 $this->_prefix = $prefix;
57 $this->_fqType = $type !=
'NULL' ? $persistenceFacade->getFullyQualifiedType($type) :
'NULL';
62 $this->_id = array($id);
73 $numPKs = self::getNumberOfPKs($type);
74 while (
sizeof($this->_id) < $numPKs) {
75 $this->_id[] = self::getDummyId();
88 if (self::$_nullOID == null) {
89 self::$_nullOID =
new ObjectId(
'NULL');
91 return self::$_nullOID;
99 return $this->_prefix;
107 return $this->_fqType;
123 return $this->_id[0];
133 if (self::parse($oid) == null) {
144 public static function parse($oid) {
150 if (strlen($oid) == 0) {
154 if (self::$_delimiterPattern == null) {
155 self::$_delimiterPattern =
'/'.self::DELIMITER.
'/';
158 $oidParts = preg_split(self::$_delimiterPattern, $oid);
159 if (
sizeof($oidParts) < 2) {
163 if (self::$_idPattern == null) {
164 self::$_idPattern =
'/^[0-9]*$|^'.self::$_dummyIdPattern.
'$/';
169 $nextPart = array_pop($oidParts);
170 while($nextPart !== null && preg_match(self::$_idPattern, $nextPart) == 1) {
171 $intNextPart = (int)$nextPart;
172 if ($nextPart == (
string)$intNextPart) {
173 $ids[] = $intNextPart;
178 $nextPart = array_pop($oidParts);
180 $ids = array_reverse($ids);
189 $numPks = self::getNumberOfPKs($type);
190 if ($numPks == null || $numPks !=
sizeof($ids)) {
195 $prefix = join(self::DELIMITER, $oidParts);
197 return new ObjectID($type, $ids, $prefix);
205 if ($this->_strVal == null) {
206 $oidStr = $this->_fqType.self::DELIMITER.join(self::DELIMITER, $this->_id);
207 if (strlen(trim($this->_prefix)) > 0) {
208 $oidStr = $this->_prefix.self::DELIMITER.$oidStr;
210 $this->_strVal = $oidStr;
212 return $this->_strVal;
220 return 'wcmf'.md5(uniqid(ip2long(@$_SERVER[
'REMOTE_ADDR']) ^ (
int)@$_SERVER[
'REMOTE_PORT'] ^ @getmypid() ^ @disk_free_space(sys_get_temp_dir()), 1));
229 return (strlen($id) == 36 && strpos($id,
'wcmf') === 0);
237 foreach ($this->
getId() as $id) {
238 if (self::isDummyId($id)) {
250 private static function getNumberOfPKs($type) {
251 if (!isset(self::$_numPkKeys[$type])) {
254 if ($persistenceFacade->isKnownType($type)) {
255 $mapper = $persistenceFacade->getMapper($type);
256 $numPKs =
sizeof($mapper->getPKNames());
258 self::$_numPkKeys[$type] = $numPKs;
260 return self::$_numPkKeys[$type];
static getDummyId()
Get a dummy id ("wcmf" + unique 32 character string).
static NULL_OID()
Get the NULL instance.
getPrefix()
Get the prefix.
Persistence layer related interfaces and classes.
ObjectId is the unique identifier of an object.
static getInstance($name, $dynamicConfiguration=array())
static isDummyId($id)
Check if a given id is a dummy id.
containsDummyIds()
Check if this object id contains a dummy id.
static parse($oid)
Parse a serialized object id string into an ObjectId instance.
__toString()
Get a string representation of the object id.
static isValid($oid)
Check if a serialized ObjectId has a valid syntax, the type is known and if the number of primary key...
getFirstId()
Get the first id.
__construct($type, $id=null, $prefix=null)
Constructor.
getType()
Get the type (including namespace)