/**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('mongoveldb', function () {
         return new DB();
     });
     Mongovel::setContainer($this->app);
     $this->registerEvents();
 }
Example #2
0
 public function next()
 {
     $this->cursor->next();
     if (!$this->iterated) {
         // Profile the query
         if (Mongovel::getContainer('config')->get('profiling.mongo')) {
             Mongovel::dispatcher()->fire('mongovel.query', array($this->cursor, $this->class, $this->method));
         }
         $this->iterated = true;
     }
 }
Example #3
0
 public static function setUpBeforeClass()
 {
     $container = new Container();
     $container->bind('config', function () {
         return Mockery::mock('Config', function ($mock) {
             $mock->shouldReceive('get')->andReturnUsing(function ($key) {
                 if ($key == 'database.mongodb.default') {
                     return array('host' => 'localhost', 'port' => 27017, 'database' => 'mongovel_tests');
                 }
                 if ($key == 'profiling.mongo') {
                     return false;
                 }
             });
         });
     });
     $container->singleton('mongoveldb', function () {
         return new DB();
     });
     Mongovel::setContainer($container);
     self::$db = Mongovel::getContainer()->make('mongoveldb');
 }
Example #4
0
 public function setDatabaseDSN($server = null, $database = null, $options = null)
 {
     if (!is_null($server)) {
         $dsn = $options ?: array();
         $dsn['server'] = $server;
         $dsn['database'] = $database;
     } else {
         // Fetch config data:
         $dsn = Mongovel::getContainer('config')->get('database.mongodb.' . $this->connection);
     }
     $this->dsn = $dsn;
     $this->database = array_pull($dsn, 'database');
     if (isset($dsn['username']) && isset($dsn['password'])) {
         $this->server = sprintf('mongodb://%s:%s@%s:%d/%s/', array_pull($dsn, 'username'), array_pull($dsn, 'password'), array_pull($dsn, 'host'), array_pull($dsn, 'port'), $this->database);
     } else {
         $this->server = sprintf('mongodb://%s:%d/', array_pull($dsn, 'host'), array_pull($dsn, 'port'));
     }
     $this->options = $dsn;
     if (!isset($this->options['connect'])) {
         $this->options['connect'] = true;
     }
 }
Example #5
0
 public function handle($cursor, $model, $method)
 {
     $stackSize = Mongovel::getContainer('config')->get('profiling.mongoStackSize', 3) + 12;
     $backtrace = debug_backtrace(0, $stackSize);
     $stack = array();
     $i0 = 7;
     while (isset($backtrace[$i0]['class']) && strpos($backtrace[$i0]['class'], 'Mongovel\\') === 0) {
         $i0++;
     }
     for ($i = $i0; $i < count($backtrace) && $i - $i0 < $stackSize - 12; $i++) {
         $caller = $backtrace[$i]['function'];
         if (isset($backtrace[$i]['class'])) {
             $caller = $backtrace[$i]['class'] . '::' . $caller;
         }
         $stack[] = $caller;
     }
     $explain = $cursor->explain();
     $info = $cursor->info();
     $message = sprintf('Mongo query on %13s::%-7s: %2sms (%s)', $model, $method, $explain['millis'], implode(', ', $stack));
     if (Mongovel::getContainer('config')->get('profiling.mongoLogParameters', false)) {
         $message .= ' ' . json_encode($info['query']);
     }
     Log::info($message);
 }
Example #6
0
 /**
  * Performs a Full text search on this collection, and returns a Collection of Models
  * 
  * @param  string $q       Search query
  * @param  array  $filter  Restrict the results
  * 
  * @return Collection
  */
 public static function textSearch($q, $filter = array())
 {
     $collectionName = static::getCollectionName();
     $search = Mongovel::db()->command(array('text' => $collectionName, 'search' => $q, 'filter' => $filter));
     $items = array();
     if (isset($search['results'])) {
         foreach ($search['results'] as $r) {
             $items[] = static::create($r['obj']);
         }
     }
     return new Collection($items);
 }
Example #7
0
 /**
  * Get the registered component.
  *
  * @return object
  */
 protected static function getFacadeAccessor()
 {
     return Mongovel::getContainer('mongoveldb');
 }