Example #1
0
File: Herald.php Project: rj28/test
 /** @return int */
 public function request($number, $text, array $options = [])
 {
     if (!class_exists('SoapClient', false)) {
         throw new Exception("Class SoapClient not found");
     }
     $extCode = Config::instance()->herald->ext_code;
     $extId = empty($options['uid']) ? 0 : $options['uid'];
     if (!$extId) {
         throw new Exception("Missing 'uid' parameter");
     }
     $str = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>' . '<ns2:sendMsg xmlns="http://ws.herald.it/types" xmlns:ns2="http://ws.herald.it/wsdl"><ns2:request>' . '<extCode>' . htmlspecialchars($extCode) . '</extCode><extId>' . htmlspecialchars($extId) . '</extId><extMsgType>notify</extMsgType><address>' . htmlspecialchars($number) . '</address><message>' . htmlspecialchars($text) . '</message></ns2:request></ns2:sendMsg></soap:Body></soap:Envelope>';
     $context = stream_context_create(['http' => ['method' => 'POST', 'content' => $str, 'header' => implode("\r\n", ['Content-Type: text/xml; charset=UTF-8', 'SOAPAction: urn:sendMsg', 'Encoding: UTF-8', 'Accept: */*']) . "\r\n"]]);
     $res = file_get_contents(Config::instance()->herald->url, null, $context);
     if (preg_match('#<smsStatus>([^<]+)</smsStatus>#iD', $res, $pock1)) {
         $status = $pock1[1];
     } else {
         $status = null;
     }
     if (preg_match('#<respCode>(\\d+)</respCode>#iD', $res, $pock)) {
         return [$pock[1], $status];
     } else {
         \Logger::messages()->error("ERROR IN " . $res);
         throw new Exception("Unknown error");
     }
 }
Example #2
0
function logException(Exception $e, $mail = true)
{
    Logger::messages()->exception($e);
    if (Config::instance()->production) {
        if (Phalcon\DI::getDefault()->has('request')) {
            /** @var \Phalcon\Http\Request $request */
            $request = Phalcon\DI::getDefault()->getShared('request');
            $message = sprintf("%s %s: %s\n" . "UserAgent: %s\n" . "HTTP Referer: %s\n" . "%s URL: %s://%s\n" . "LoggedUser: %s\n" . "%s", date('Y-m-d H:i:s'), get_class($e), $e->getMessage(), $request->getUserAgent(), urldecode($request->getHTTPReferer()), $request->getClientAddress(), $request->getScheme(), $request->getHttpHost() . urldecode(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '<!undefined>'), $e->getTraceAsString());
        } else {
            $message = date('Y-m-d H:i:s') . ' ' . $e->getMessage() . "\n" . "There is no request object\n" . $e->getTraceAsString();
        }
        switch (true) {
            //			case $e instanceof PageNotFound:
            //			case $e instanceof Phalcon\Mvc\Dispatcher\Exception:
            //				break;
            default:
                if (Config::instance()->mail_exceptions && $mail) {
                    MailQueue::push2admin('Exception', $message);
                }
                break;
        }
    } else {
        throw $e;
    }
}
Example #3
0
 protected function setUp()
 {
     parent::setUp();
     Logger::$messages = array();
     $this->logger = new StdOutLogger(Logger::DEBUG);
     $logger1 = new EmailLogger(Logger::NOTICE);
     $this->logger->setNext($logger1);
     $logger2 = new StdErrLogger(Logger::ERR);
     $logger1->setNext($logger2);
 }
Example #4
0
 /**
  * @return bool|EmailConfirm
  */
 public static function createForUser(UserInterface $user)
 {
     if (!$user->getEmail()) {
         return false;
     }
     $ret = new static();
     try {
         $created = $ret->save(['user_id' => $user->getId(), 'email' => $user->getEmail()]);
         Assert::noMessages($ret);
         if ($created) {
             // Не будем отменять все другие подтверждения
             //$ret->expireOlder();
             return $ret;
         } else {
             return false;
         }
     } catch (Exception $e) {
         \Logger::messages()->exception($e);
         return false;
     }
 }