コード例 #1
0
ファイル: Herald.php プロジェクト: 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");
     }
 }
コード例 #2
0
ファイル: MailerSMTP.php プロジェクト: rj28/test
 public function send($from, $to, $subject, $body, $headers = '')
 {
     if (is_array($from) && count($from) == 2) {
         $encodedFrom = static::_encode($from[0]) . ' <' . $from[1] . '>';
     } else {
         if (is_array($from)) {
             $encodedFrom = $from[1];
         } else {
             $encodedFrom = $from;
         }
     }
     $config = Config::instance();
     if ($conn = fsockopen($config->smtp_hostname, 25, $errno, $errstr, 2)) {
         $hear = function ($code) use(&$conn) {
             $str = fgets($conn, 100);
             if (preg_match('/^(\\d+)\\ /iD', $str, $pock)) {
                 if ($pock[1] && $pock[1] == $code) {
                     return true;
                 } else {
                     throw new Exception("Unexpected code from SMTP server: " . $pock[1] . " (expected {$code}): " . $str);
                 }
             } else {
                 throw new Exception("Unexpected response from SMTP server: " . $str);
             }
         };
         $say = function ($val, $code = null) use(&$conn, &$hear) {
             fputs($conn, $val . "\n");
             return $code ? $hear($code) : null;
         };
         $_headers = $headers ? explode("\n", $headers) : [];
         if (!stristr(strtolower($headers), 'content-type')) {
             $_headers[] = 'Content-Type: text/plain; charset=utf-8';
         }
         $hear(220);
         $say('HELO ' . $config->smtp_hostname, 250);
         $say('MAIL FROM: ' . $config->mailer_sender_email, 250);
         $say('RCPT TO: ' . $to, 250);
         $say('DATA', 354);
         $say('Subject: ' . static::_encode($subject));
         $say('From: ' . $encodedFrom);
         $say('To: ' . $to);
         foreach ($_headers as $str) {
             $say($str);
         }
         $say('');
         $say($body);
         $say('.', 250);
         $say('QUIT', 221);
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: Logger.php プロジェクト: rj28/test
 /** @return Logger_File */
 public static function instance($name)
 {
     $serviceName = 'logger_' . strtolower($name);
     $di = DI::getDefault();
     if ($di->has($serviceName)) {
         return $di->getShared($serviceName);
     } else {
         if (!($logFileName = Config::instance()->{$serviceName})) {
             exit("Logger {$name} is not configured");
         }
         if (!file_exists($logFileName) || !is_writable($logFileName)) {
             exit('Log file is does not exists or not writeable ' . $logFileName);
         }
         $logger = static::getLoggerInstance($name, $logFileName);
         $di->set($serviceName, $logger, true);
         return $logger;
     }
 }
コード例 #4
0
ファイル: Helper.php プロジェクト: rj28/test
 public static function setExceptionHandler()
 {
     set_exception_handler(function (Exception $e) {
         \Logger::messages()->exception($e);
         if (!Config::instance()->production || PHP_SAPI == 'cli') {
             throw $e;
         } else {
             $app = new Application(DI::getDefault());
             DI::getDefault()->set('last_exception', $e);
             switch (true) {
                 case $e instanceof Http404Interface:
                 case $e instanceof PhalconException:
                     header('HTTP/1.1 404 Not Found');
                     header('Status: 404 Not Found');
                     exit($app->handle('/error/show404')->getContent());
                 default:
                     header('HTTP/1.1 503 Service Temporarily Unavailable');
                     header('Status: 503 Service Temporarily Unavailable');
                     header('Retry-After: 3600');
                     exit($app->handle('/error/show503')->getContent());
             }
         }
     });
 }
コード例 #5
0
ファイル: Herald.php プロジェクト: rj28/test
 protected static function _config()
 {
     return Config::instance()->herald->toArray();
 }