public function testOnce() { $id = uniqid("", true); $count = 0; Event::once($id, function () use(&$count) { $count += 1; }); Event::emit($id); Event::emit($id); Event::emit($id); Event::emit($id); $this->assertSame(1, $count); }
/** 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; }