28 class ObjectId implements \Serializable, \JsonSerializable {
35 private $strVal =
null;
37 private static $dummyIdPattern =
'wcmf[A-Za-z0-9]{32}';
38 private static $idPattern =
null;
39 private static $delimiterPattern =
null;
40 private static $numPkKeys = [];
42 private static $nullOID =
null;
56 $this->prefix = $prefix;
58 $this->fqType = $type !=
'NULL' ? $persistenceFacade->getFullyQualifiedType($type) :
'NULL';
61 $this->
id = !is_array($id) ? [$id] : $id;
64 $numPKs = self::getNumberOfPKs($type);
65 while (
sizeof($this->
id) < $numPKs) {
79 if (self::$nullOID ==
null) {
80 self::$nullOID =
new ObjectId(
'NULL');
82 return self::$nullOID;
124 if (self::parse($oid) ==
null) {
135 public static function parse($oid) {
141 $oidParts = self::parseOidString($oid);
146 $type = $oidParts[
'type'];
147 $ids = $oidParts[
'id'];
148 $prefix = $oidParts[
'prefix'];
156 $numPks = self::getNumberOfPKs($type);
157 if ($numPks ==
null || $numPks !=
sizeof($ids)) {
161 return new ObjectID($type, $ids, $prefix);
169 private static function parseOidString($oid) {
170 if (strlen($oid) == 0) {
174 $oidParts = preg_split(self::getDelimiterPattern(), $oid);
175 if (
sizeof($oidParts) < 2) {
179 if (self::$idPattern ==
null) {
180 self::$idPattern =
'/^[0-9]*$|^'.self::$dummyIdPattern.
'$/';
185 $nextPart = array_pop($oidParts);
186 while($nextPart !==
null && preg_match(self::$idPattern, $nextPart) == 1) {
187 $intNextPart = (int)$nextPart;
188 if ($nextPart == (
string)$intNextPart) {
189 $ids[] = $intNextPart;
194 $nextPart = array_pop($oidParts);
196 $ids = array_reverse($ids);
202 $prefix = join(self::DELIMITER, $oidParts);
216 if ($this->strVal ==
null) {
217 $oidStr = $this->fqType.self::DELIMITER.join(self::DELIMITER, $this->
id);
218 if (strlen(trim($this->prefix)) > 0) {
219 $oidStr = $this->prefix.self::DELIMITER.$oidStr;
221 $this->strVal = $oidStr;
223 return $this->strVal;
240 return (strlen($id) == 36 && strpos($id,
'wcmf') === 0);
248 foreach ($this->
getId() as $id) {
249 if (self::isDummyId($id)) {
261 private static function getNumberOfPKs($type) {
262 if (!isset(self::$numPkKeys[$type])) {
265 if ($persistenceFacade->isKnownType($type)) {
266 $mapper = $persistenceFacade->getMapper($type);
267 $numPKs =
sizeof($mapper->getPKNames());
269 self::$numPkKeys[$type] = $numPKs;
271 return self::$numPkKeys[$type];
274 private static function getDelimiterPattern() {
275 if (self::$delimiterPattern ==
null) {
276 self::$delimiterPattern =
'/'.self::DELIMITER.
'/';
278 return self::$delimiterPattern;
286 $oidParts = self::parseOidString($data);
287 $this->prefix = $oidParts[
'prefix'];
288 $this->fqType = $oidParts[
'type'];
289 $this->
id = $oidParts[
'id'];
static NULL_OID()
Get the NULL instance.
containsDummyIds()
Check if this object id contains a dummy id.
static getDummyId()
Get a dummy id ("wcmf" + unique 32 character string).
static isDummyId($id)
Check if a given id is a dummy id.
Persistence layer related interfaces and classes.
__toString()
Get a string representation of the object id.
StringUtil provides support for string manipulation.
ObjectId is the unique identifier of an object.
getPrefix()
Get the prefix.
getFirstId()
Get the first id.
static parse($oid)
Parse a serialized object id string into an ObjectId instance.
getType()
Get the type (including namespace)
static getInstance($name, $dynamicConfiguration=[])
static guidv4()
Generate a v4 UUID Code from https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-...
static isValid($oid)
Check if a serialized ObjectId has a valid syntax, the type is known and if the number of primary key...
__construct($type, $id=[], $prefix=null)
Constructor.
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...