error() public static method

Report error log
public static error ( string $text )
$text string
 /**
  * Get weather string from weather data
  *
  * @param array $data
  *
  * @return string
  */
 private function getWeatherString(array $data)
 {
     try {
         if (!(isset($data['cod']) && $data['cod'] === 200)) {
             return '';
         }
         //http://openweathermap.org/weather-conditions
         $conditions = ['clear' => ' ☀️', 'clouds' => ' ☁️', 'rain' => ' ☔', 'drizzle' => ' ☔', 'thunderstorm' => ' ⚡️', 'snow' => ' ❄️'];
         $conditions_now = strtolower($data['weather'][0]['main']);
         return sprintf('The temperature in %s (%s) is %s°C' . "\n" . 'Current conditions are: %s%s', $data['name'], $data['sys']['country'], $data['main']['temp'], $data['weather'][0]['description'], isset($conditions[$conditions_now]) ? $conditions[$conditions_now] : '');
     } catch (Exception $e) {
         TelegramLog::error($e->getMessage());
         return '';
     }
 }
Esempio n. 2
0
 /**
  * Add a single custom commands path
  *
  * @param string $path   Custom commands path to add
  * @param bool   $before If the path should be prepended or appended to the list
  *
  * @return Telegram
  */
 public function addCommandsPath($path, $before = true)
 {
     if (!is_dir($path)) {
         TelegramLog::error('Commands path "' . $path . '" does not exist.');
     } elseif (!in_array($path, $this->commands_paths)) {
         if ($before) {
             array_unshift($this->commands_paths, $path);
         } else {
             array_push($this->commands_paths, $path);
         }
     }
     return $this;
 }
 public function testExternalStream()
 {
     $file = $this->logfiles['external'];
     $this->assertFileNotExists($file);
     $external_monolog = new Logger('bot_update_log');
     $external_monolog->pushHandler(new StreamHandler($file, Logger::ERROR));
     $external_monolog->pushHandler(new StreamHandler($file, Logger::DEBUG));
     TelegramLog::initialize($external_monolog);
     TelegramLog::error('my error');
     TelegramLog::debug('my debug');
     $this->assertFileExists($file);
     $file_contents = file_get_contents($file);
     $this->assertContains('bot_update_log.ERROR: my error', $file_contents);
     $this->assertContains('bot_update_log.DEBUG: my debug', $file_contents);
 }
 /**
  * Get date
  *
  * @param string $lat
  * @param string $lng
  *
  * @return array
  */
 private function getDate($lat, $lng)
 {
     $path = 'timezone/json';
     $date_utc = new \DateTime(null, new \DateTimeZone('UTC'));
     $timestamp = $date_utc->format('U');
     $query = ['location' => urlencode($lat) . ',' . urlencode($lng), 'timestamp' => urlencode($timestamp)];
     if ($this->google_api_key !== null) {
         $query['key'] = $this->google_api_key;
     }
     try {
         $response = $this->client->get($path, ['query' => $query]);
     } catch (RequestException $e) {
         TelegramLog::error($e->getMessage());
         return [];
     }
     if (!($data = $this->validateResponseData($response->getBody()))) {
         return [];
     }
     $local_time = $timestamp + $data['rawOffset'] + $data['dstOffset'];
     return [$local_time, $data['timeZoneId']];
 }