Example #1
0
 public function register()
 {
     $this->registerSite();
     $this->registerAccessPoint();
     $this->registerEvent();
     $this->registerGuest();
     //@TODO hardcoded values
     $this->ioc->bind(Connection::class, function () {
         $connection = new Connection(['driver' => 'mongodb', 'host' => 'localhost', 'port' => 27117, 'database' => 'ace', 'username' => '', 'password' => '', 'options' => ['db' => 'admin']]);
         $connection->useDefaultQueryGrammar();
         return $connection;
     });
     $this->ioc->bind(SiteGateway::class, function () {
         return new SiteGateway($this->ioc->make(Connection::class));
     });
     $this->ioc->bind(AccessPointGateway::class, function () {
         return new AccessPointGateway($this->ioc->make(Connection::class));
     });
     $this->ioc->bind(EventGateway::class, function () {
         return new EventGateway($this->ioc->make(Connection::class));
     });
     $this->ioc->bind(GuestGateway::class, function () {
         return new GuestGateway($this->ioc->make(Connection::class));
     });
 }
 /**
  * Handle dynamic method calls.
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     $start = microtime(true);
     $result = call_user_func_array([$this->collection, $method], $parameters);
     if ($this->connection->logging()) {
         // Once we have run the query we will calculate the time that it took to run and
         // then log the query, bindings, and execution time so we will report them on
         // the event that the developer needs them. We'll log time in milliseconds.
         $time = $this->connection->getElapsedTime($start);
         $query = [];
         // Convert the query parameters to a json string.
         array_walk_recursive($parameters, function (&$item, $key) {
             if ($item instanceof ObjectID) {
                 $item = (string) $item;
             }
         });
         // Convert the query parameters to a json string.
         foreach ($parameters as $parameter) {
             try {
                 $query[] = json_encode($parameter);
             } catch (Exception $e) {
                 $query[] = '{...}';
             }
         }
         $queryString = $this->collection->getCollectionName() . '.' . $method . '(' . implode(',', $query) . ')';
         $this->connection->logQuery($queryString, [], $time);
     }
     return $result;
 }
 /**
  * Handle dynamic method calls.
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     $query = array();
     // Build the query string.
     foreach ($parameters as $parameter) {
         try {
             $query[] = json_encode($parameter);
         } catch (Exception $e) {
             $query[] = '{...}';
         }
     }
     $start = microtime(true);
     $result = call_user_func_array(array($this->collection, $method), $parameters);
     // Once we have run the query we will calculate the time that it took to run and
     // then log the query, bindings, and execution time so we will report them on
     // the event that the developer needs them. We'll log time in milliseconds.
     $time = $this->connection->getElapsedTime($start);
     // Convert the query to a readable string.
     $queryString = $this->collection->getName() . '.' . $method . '(' . join(',', $query) . ')';
     $this->connection->logQuery($queryString, array(), $time);
     return $result;
 }
Example #4
0
 /**
  * Set the table prefix and return the grammar.
  *
  * @param \Illuminate\Database\Grammar $grammar
  * @return \Illuminate\Database\Grammar 
  * @static 
  */
 public static function withTablePrefix($grammar)
 {
     //Method inherited from \Illuminate\Database\Connection
     return \Jenssegers\Mongodb\Connection::withTablePrefix($grammar);
 }
 /**
  * Get the collection.
  *
  * @return QueryBuilder
  */
 protected function getCacheCollection()
 {
     return $this->connection->collection($this->collection_name);
 }