mongoConnection)) return 'none'; return $this->uri; } /** * Whether the database connection has been set up yet * * @return bool */ public function isSetup(): bool { return $this->setUp; } /** * Method called by \FuzeWorks\Database to setUp the database connection * * @param array $parameters * @return bool * @throws DatabaseException */ public function setUp(array $parameters): bool { // Prepare variables for connection $this->uri = isset($parameters['uri']) ? $parameters['uri'] : null; $uriOptions = isset($parameters['uriOptions']) ? $parameters['uriOptions'] : []; $driverOptions = isset($parameters['driverOptions']) ? $parameters['driverOptions'] : []; // Don't attempt and connect without a URI if (is_null($this->uri)) throw new DatabaseException("Could not setUp MongoEngine. No URI provided"); // Import username and password if (isset($parameters['username']) && isset($parameters['password'])) { $uriOptions['username'] = $parameters['username']; $uriOptions['password'] = $parameters['password']; } // And set FuzeWorks app name $uriOptions['appname'] = 'FuzeWorks'; try { $this->mongoConnection = new Client($this->uri, $uriOptions, $driverOptions); } catch (InvalidArgumentException | RuntimeException $e) { throw new DatabaseException("Could not setUp MongoEngine. MongoDB threw exception: '" . $e->getMessage() . "'"); } // Set this engine as set up $this->setUp = true; // Register subscriber $subscriber = new MongoCommandSubscriber($this); addSubscriber($subscriber); // And return true upon success return true; } public function logMongoQuery(string $queryString, int $queryData, float $queryTimings, array $errorInfo = []) { $this->logQuery($queryString, $queryData, $queryTimings, $errorInfo); } /** * Method called by \FuzeWorks\Database to tear down the database connection upon shutdown * * @return bool */ public function tearDown(): bool { // MongoDB does not require any action. Always return true return true; } /** * Call methods on the Mongo Connection * * @param $name * @param $arguments * @return mixed */ public function __call($name, $arguments) { return $this->mongoConnection->{$name}(...$arguments); } /** * Get properties from the Mongo Connection * * @param $name * @return Database */ public function __get($name): Database { return $this->mongoConnection->$name; } /** * @return bool */ public function transactionStart(): bool { // TODO: Implement transactionStart() method. } /** * @return bool */ public function transactionEnd(): bool { // TODO: Implement transactionEnd() method. } /** * @return bool */ public function transactionCommit(): bool { // TODO: Implement transactionCommit() method. } /** * @return bool */ public function transactionRollback(): bool { // TODO: Implement transactionRollback() method. } }