Mongolid\Util\ObjectIdUtils::isObjectId PHP Method

isObjectId() public static method

Checks if the given value can be a valid ObjectId.
public static isObjectId ( mixed $value ) : boolean
$value mixed String to be evaluated if it can be used as a valid ObjectID.
return boolean True if is valid.
    public static function isObjectId($value)
    {
        if (is_object($value) && method_exists($value, '__toString')) {
            $value = (string) $value;
        }
        if (is_string($value) && strlen($value) == 24 && ctype_xdigit($value)) {
            return true;
        }
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * Filters any field in the $fields that has it's value specified as a
  * 'objectId'. It will wraps the $value, if any, into a ObjectID object.
  *
  * @param mixed $value Value that may be converted to ObjectID.
  *
  * @return ObjectID|mixed
  */
 public function objectId($value = null)
 {
     if ($value === null) {
         return new ObjectID();
     }
     if (is_string($value) && ObjectIdUtils::isObjectId($value)) {
         $value = new ObjectID($value);
     }
     return $value;
 }
All Usage Examples Of Mongolid\Util\ObjectIdUtils::isObjectId
ObjectIdUtils