/**
  * @param QueryBuilder $queryBuilder
  * @param                     $event
  * @return mixed
  */
 public function fireEvents($queryBuilder, $event)
 {
     $statements = $queryBuilder->getStatements();
     $tables = isset($statements['tables']) ? $statements['tables'] : array();
     // Events added with :any will be fired in case of any table,
     // we are adding :any as a fake table at the beginning.
     array_unshift($tables, ':any');
     // Fire all events
     foreach ($tables as $table) {
         // Fire before events for :any table
         if ($action = $this->getEvent($event, $table)) {
             // Make an event id, with event type and table
             $eventId = $event . $table;
             // Fire event
             $handlerParams = func_get_args();
             unset($handlerParams[1]);
             // we do not need $event
             // Add to fired list
             $this->firedEvents[] = $eventId;
             switch (count($handlerParams)) {
                 case 0:
                     $action();
                     break;
                 case 1:
                     $action($handlerParams[0]);
                     break;
                 case 2:
                     $action($handlerParams[0], $handlerParams[1]);
                     break;
                 case 3:
                     $action($handlerParams[0], $handlerParams[1], $handlerParams[2]);
                     break;
                 case 4:
                     $action($handlerParams[0], $handlerParams[1], $handlerParams[2]);
                     break;
                 case 5:
                     $action($handlerParams[0], $handlerParams[1], $handlerParams[2]);
                     break;
             }
             $result = call_user_func_array($action, $handlerParams);
             if (!is_null($result)) {
                 return $result;
             }
         }
     }
 }
 /**
  * @expectedException \Fairy\Exception
  * @expectedExceptionCode 3
  */
 public function testTableNotSpecifiedException()
 {
     $this->builder->where('a', 'b')->get();
 }
示例#3
0
 /**
  * @param QueryBuilder $queryBuilder
  * @param null $alias
  *
  * @return Raw
  */
 public function subQuery(QueryBuilder $queryBuilder, $alias = null)
 {
     $sql = '(' . $queryBuilder->getQuery()->getRawSql() . ')';
     if ($alias) {
         $sql = $sql . ' as ' . $alias;
     }
     return $queryBuilder->raw($sql);
 }