コード例 #1
0
ファイル: ConnectionTest.php プロジェクト: Macavity/phormium
 public function setUp()
 {
     $this->connection = DB::getConnection('testdb');
     $this->driver = $this->connection->getDriver();
     // Clean up events before every test
     $this->triggeredEvents = array();
     $this->triggeredArguments = array();
     $that = $this;
     foreach ($this->queryEvents as $event) {
         Event::removeListeners($event);
         Event::on($event, function () use($event, $that) {
             $that->triggeredEvents[] = $event;
             $that->triggeredArguments[] = func_get_args();
         });
     }
 }
コード例 #2
0
ファイル: Connection.php プロジェクト: Macavity/phormium
 /** Fetches all resulting records from a PDO statement. */
 private function pdoFetch($query, $arguments, PDOStatement $stmt, $fetchStyle, $class)
 {
     Event::emit(Event::QUERY_FETCHING, array($query, $arguments, $this));
     $fetchIntoClass = $fetchStyle === PDO::FETCH_CLASS && isset($class);
     try {
         // For Informix use fetch() in a loop instead of fetchAll(), because
         // the latter method has problems with pdo_informix. If a record is
         // locked, fetchAll() will only return records upto the locked
         // record, without raising an error. Fetch, on the other hand will
         // produce an error.
         if ($this->getDriver() == 'informix') {
             $data = array();
             if ($fetchIntoClass) {
                 $stmt->setFetchMode(PDO::FETCH_CLASS, $class);
             }
             while ($row = $stmt->fetch($fetchStyle)) {
                 $data[] = $row;
             }
         } else {
             if ($fetchIntoClass) {
                 $data = $stmt->fetchAll($fetchStyle, $class);
             } else {
                 $data = $stmt->fetchAll($fetchStyle);
             }
         }
     } catch (\Exception $ex) {
         Event::emit(Event::QUERY_ERROR, array($query, $arguments, $this, $ex));
         throw $ex;
     }
     Event::emit(Event::QUERY_FETCHED, array($query, $arguments, $this));
     return $data;
 }
コード例 #3
0
ファイル: events.php プロジェクト: Macavity/phormium
 /** Hooks onto relevant events. */
 public function register()
 {
     Event::on('query.started', array($this, 'started'));
     Event::on('query.completed', array($this, 'completed'));
 }
コード例 #4
0
ファイル: EventTest.php プロジェクト: Macavity/phormium
 public function testAddRemove()
 {
     Event::removeListeners();
     $id1 = uniqid("", true);
     $id2 = uniqid("", true);
     $listener = function () {
     };
     Event::on($id1, $listener);
     Event::on($id2, $listener);
     $listeners1 = Event::listeners($id1);
     $listeners2 = Event::listeners($id2);
     $this->assertEquals($listeners1, $listeners2);
     $this->assertCount(1, $listeners1);
     $this->assertCount(1, $listeners2);
     Event::removeListener($id1, $listener);
     $listeners1 = Event::listeners($id1);
     $listeners2 = Event::listeners($id2);
     $this->assertCount(0, $listeners1);
     $this->assertCount(1, $listeners2);
     Event::removeListener($id2, $listener);
     $listeners1 = Event::listeners($id1);
     $listeners2 = Event::listeners($id2);
     $this->assertCount(0, $listeners1);
     $this->assertCount(0, $listeners2);
     Event::on($id1, $listener);
     Event::on($id2, $listener);
     $listeners1 = Event::listeners($id1);
     $listeners2 = Event::listeners($id2);
     $this->assertEquals($listeners1, $listeners2);
     $this->assertCount(1, $listeners1);
     $this->assertCount(1, $listeners2);
     Event::removeListeners();
     $listeners1 = Event::listeners($id1);
     $listeners2 = Event::listeners($id2);
     $this->assertCount(0, $listeners1);
     $this->assertCount(0, $listeners2);
 }