public function test_log_creates_a_log_model()
 {
     LoggerService::log(Log::TYPE_WARNING, 'this is a message', 'users', 1000, 9999);
     $log = Log::find()->order_by('id desc');
     $this->assertEquals(Log::TYPE_WARNING, $log->type);
     $this->assertEquals('this is a message', $log->message);
     $this->assertEquals('users', $log->table_name);
     $this->assertEquals(1000, $log->item_id);
     $this->assertEquals(9999, $log->user_id);
 }
Example #2
0
 public function validate($instance)
 {
     foreach ($this->options as $key => $value) {
         $method_name = "validate_{$key}";
         $error = $this->{$method_name}($instance, $value);
         if (!is_null($error)) {
             if (empty($error)) {
                 $error = tr("%1 is not valid!", $this->readable_attribute());
             }
             LoggerService::error($error);
             return false;
         }
     }
     return true;
 }
Example #3
0
    }
}
class FlashLogger
{
    public function error($message)
    {
        $this->flash('error', $message);
    }
    public function information($message)
    {
        $this->flash('message', $message);
    }
    public function success($message)
    {
        $this->flash('success', $message);
    }
    public function dump()
    {
    }
    private function flash($id, $message)
    {
        if (flash_empty($id)) {
            flash($id, $message);
        } else {
            $current_flash = get_flash($id);
            flash($id, $current_flash . '<br>' . $message);
        }
    }
}
LoggerService::$logger = new FlashLogger();
Example #4
0
class SilentLogger
{
    public $errors = [];
    public $informations = [];
    public $successes = [];
    public function error($message)
    {
        $this->errors[] = $message;
    }
    public function information($message)
    {
        $this->informations[] = $message;
    }
    public function success($message)
    {
        $this->successes[] = $message;
    }
    public function dump()
    {
        foreach (['errors' => $this->errors, 'information' => $this->informations, 'successes' => $this->successes] as $type => $logs) {
            if (count($logs)) {
                echo $type . ':';
                echo "\n";
                echo implode("\n", $logs);
            }
        }
    }
}
LoggerService::$logger = new SilentLogger();