/** * Event constructor. Get an UUID for the event. * * @since 0.1.0 * @return void */ public function __construct() { $this->uuid = Uuid::getUuid(); $now = new \DateTime('now'); $now->setTimezone(new \DateTimeZone('UTC')); $timestamp = $now->format('Y-m-d H:i:s'); $this->timestamp = $timestamp; }
function testItUnpacksUuidsFromBinaryForm() { $uuid = Uuid::getUuid(); $packed = Uuid::pack($uuid); $unpacked = Uuid::unpack($packed); $this->assertRegExp('%^[0-9A-Za-z-]+$%', $unpacked); $this->assertEquals($unpacked, $uuid); }
/** * Logs with an arbitrary level. * * @since 0.1.0 * * @param mixed $level * @param string $message * @param array $context * @param \Wplog\Events\Event The event being logged. * * @return Boolean */ public function log($level, $message, array $context = array(), Event $event = null) : bool { $message = $this->parseContext($message, $context); $inserted = $this->wpdb->insert($this->wpdb->prefix . 'wplog', ['uuid' => Uuid::pack($event->getUuid()), 'timestamp' => $event->getTimestamp(), 'severity' => $level, 'event_type' => $event->getType(), 'body' => $message, 'user_id' => $event->getUserId()], ['%s', '%s', '%s', '%s', '%s', '%d']); return $inserted === 1; }