private final function delete($path, $ensure_existence = TRUE) { $this->ensureNotReadOnly(); // Kit::ensureType($path, [ Kit::TYPE_STRING, Kit::TYPE_LIST ]); // @CAUTION // Kit::ensureType($path, [ Kit::TYPE_STRING, Kit::TYPE_ARRAY ]); Kit::ensureString($path); // Kit::ensureDict($this->document); // @CAUTION // Kit::ensureArray($this->document); Kit::ensureBoolean($ensure_existence); // if (TRUE === Kit::isString($path)) { if (TRUE === $ensure_existence) { $this->ensureHas($path); } if (FALSE === $ensure_existence and TRUE === is_null($this->document[$path])) { return NULL; } $value = $this->document[$path]; unset($this->document[$path]); $this->notSameAsCollection(); return $value; // } else throw new UserException('Can not support list-type $path yet.', $path); }
/** * Remove documents from this collection. * @param array $criterion Associative array with fields to match. * @param boolean $multiple If set to TRUE, all documents matching $criterion will be removed. * @return array Returns an array containing the status of the removal. * @throws MongoCursorException if the "w" option is set and the write fails. * @throws MongoCursorTimeoutException if the "w" option is set to a value greater than one * and the operation takes longer than MongoCursor::$timeout * milliseconds to complete. * This does not kill the operation on the server, * it is a client-side timeout. * The operation in MongoCollection::$wtimeout * is milliseconds. */ private final function mongoRemove($criterion, $multiple = TRUE) { $this->ensureInitialized(); // Kit::ensureDict($criterion); // @CAUTION Kit::ensureArray($criterion); Kit::ensureBoolean($multiple); $options = ['w' => 1, 'justOne' => FALSE === $multiple]; $status = $this->collection->remove($criterion, $options); self::$isChanged = TRUE; return $status; }
/** * @param string $class_name * @param boolean $with_instantiate * @param array $arg_list * @return object */ private static final function createInstance($class_name, $with_instantiate, $arg_list) { Kit::ensureString($class_name); Kit::ensureBoolean($with_instantiate); Kit::ensureArray($arg_list); $reflection_class = new ReflectionClass($class_name); if (TRUE === $with_instantiate) { return $reflection_class->newInstanceArgs($arg_list); } else { return $reflection_class->newInstanceWithoutConstructor(); } }