示例#1
0
 public function testGetEntriesAddEntry()
 {
     $lb = new LogBuffer();
     $this->assertTrue(is_array($lb->getEntries()));
     $this->assertSame(0, count($lb->getEntries()));
     $lb->addEntry(new LogEntry('test'));
     $this->assertSame(1, count($lb->getEntries()));
     $this->assertInstanceOf('Webiny\\AnalyticsDb\\LogEntry', $lb->getEntries()[0]);
 }
示例#2
0
 /**
  * Add a log to the buffer.
  * Note: the data is not saved until you call the save method.
  *
  * @param string $entity Entity name.
  * @param int    $ref
  * @param int    $increment
  *
  * @return LogEntry
  * @throws AnalyticsDbException
  */
 public function log($entity, $ref = 0, $increment = 1)
 {
     if (!preg_match('/^([A-z0-9\\/\\-\\_]+)$/', $entity)) {
         throw new AnalyticsDbException('Entity name can only contain ([A-z0-9\\/\\-]).');
     }
     if (!preg_match('/^([A-z0-9\\/\\-\\_]+)$/', $ref)) {
         throw new AnalyticsDbException('Entity referrer can only contain ([A-z0-9\\/\\-]).');
     }
     $entry = new LogEntry($entity);
     $entry->setRef($ref);
     $entry->setIncrement($increment);
     $this->logBuffer->addEntry($entry);
     return $entry;
 }