/**
  * Send a push notification
  * @param string $deviceToken the push token for the mobile device
  * @param string $message the message to display
  * @param string $alertSound the audio file to play, otherwise use the default sound
  * @param string $unlockText if the device is locked, show "Slide to XXX" where XXX is the unlockText
  * @param int $badgeCount the number that should be shown on the springboard badge
  */
 public function Send($deviceToken, $message, $alertSound = 'default', $unlockText = '', $badgeCount = 0)
 {
     $ctx = stream_context_create();
     stream_context_set_option($ctx, 'ssl', 'local_cert', $this->certFilePath);
     stream_context_set_option($ctx, 'ssl', 'passphrase', $this->certPassphrase);
     $output = new stdClass();
     $output->date = date('Y-m-d H:i:s');
     // Open a connection to the APNS server
     $fp = stream_socket_client($this->gatewayUrl, $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
     stream_set_blocking($fp, 0);
     //This allows fread() to return right away when there are no errors. But it can also miss errors during last seconds of sending, as there is a delay before error is returned. Workaround is to pause briefly AFTER sending last notification, and then do one more fread() to see if anything else is there.
     if (!$fp) {
         $output->success = false;
         $output->message = "Connection Failed: {$err} {$errstr}";
     } else {
         $apple_expiry = time() + 10 * 24 * 60 * 60;
         //Keep push alive (waiting for delivery) for 10 days
         // format the body based on whether an unlock message was specified
         $alert = $unlockText ? array('body' => $message, 'action-loc-key' => $unlockText) : $message;
         // Create the payload body
         $body['aps'] = array('alert' => $alert, 'sound' => $alertSound, 'badge' => $badgeCount);
         $apple_identifier = 1;
         // Encode the payload as JSON
         $payload = json_encode($body);
         // Build the binary notification
         ExceptionThrower::$IGNORE_DEPRECATED = true;
         ExceptionThrower::Start();
         try {
             //$msg = pack("C", 1) . pack("N", $apple_identifier) . pack("N", $apple_expiry) . pack("n", 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n", strlen($payload)) . $payload; //Enhanced Notification
             $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
             // Send it to the server
             $result = fwrite($fp, $msg, strlen($msg));
             usleep(500000);
             $apple_error_response = fread($fp, 6);
             if (!$result) {
                 $output->success = false;
                 $output->message = 'Communication Error: Unable to deliver message';
             } else {
                 $output->success = true;
                 $output->message = print_r($result, 1) . ' ::: ' . print_r($apple_error_response, 1);
             }
         } catch (Exception $ex) {
             $output->success = false;
             $output->message = $ex->getMessage();
         }
         ExceptionThrower::Stop();
     }
     // Close the connection to the server
     fclose($fp);
     return $output;
 }
示例#2
0
 /**
  * @inheritdocs
  */
 public function Delete($key)
 {
     $result = null;
     try {
         ExceptionThrower::Start();
         $result = $this->_memcache->delete($this->_prefix . $key);
         ExceptionThrower::Stop();
     } catch (Exception $ex) {
         ExceptionThrower::Stop();
         if (!$this->_suppressServerErrors) {
             throw $ex;
         }
     }
     return $result;
 }
示例#3
0
 /**
  * Envoie une requète à la base de données
  * Le code requète permet de choisir le type de résultat attendu par la requête
  *
  * 0 = Résultat attendu ramène une seul ligne
  * 1 = Résultat attendue ramène plusieurs ligne
  * 2 = Résultat attendu ramène le nombres de lignes impacté par celle-ci
  * 
  * $format est optionnel, par défaut -> PDO::FETCH_OBJ
  * Si $CodeRequete n'est pas renseigné, sa valeur est à 0 par défaut.
  * 
  * @param int $CodeRequete de 0 à 2
  * @param string $sql
  * @param array $tParam
  * @param [int $format]
  * @return un tableau en fonction du format
  * @throws MySQLException
  */
 public static function request($codeRequete = 0, $sql, $tParam = NULL, $format = PDO::FETCH_OBJ)
 {
     try {
         global $resEr;
         global $resMessage;
         //On lance la remonté d'erreur
         ExceptionThrower::Start();
         if (empty(self::$cnx)) {
             self::$cnx = Connection::getConnection();
         }
         if ($tParam == null) {
             $stm = self::$cnx->query($sql);
         } else {
             $stm = self::$cnx->prepare($sql);
             $stm->execute($tParam);
         }
         switch ($codeRequete) {
             //requête résultat simple
             case 0:
                 $result = $stm->fetch($format);
                 $stm->closeCursor();
                 if (!$result) {
                     $result = 0;
                 }
                 break;
                 //requête résultats Multiple
             //requête résultats Multiple
             case 1:
                 $result = $stm->fetchAll($format);
                 $stm->closeCursor();
                 if (!$result) {
                     $result = 0;
                 }
                 break;
                 //requête Nombre de lignes impacté
             //requête Nombre de lignes impacté
             case 2:
                 $result = $stm->rowCount();
                 $stm->closeCursor();
                 if (!$result) {
                     $result = 0;
                 }
                 break;
         }
         //Enfin on ferme la remonté d'erreur
         ExceptionThrower::Stop();
     } catch (Exception $e) {
         //Les erreurs de la base de données étant gérer avec le SQLSTATE.
         //Cela permet de récupérer le SQLSTATE quoiqu'il arrive.
         //Car selon les cas il est récupéré soit sur le statement
         //soit sur la connexion directement.
         //On le place ensuite dans $resErr qui est afiché dans le footer.
         if (isset($stm)) {
             $resEr[0] = $stm->errorCode();
         } else {
             if (is_object(self::$cnx)) {
                 $resEr[0] = self::$cnx->errorCode();
             } else {
                 echo 'code: ' . $e->getCode() . '<br>';
                 echo 'message: ' . $e->getMessage() . '<br>';
                 foreach ($e->getTrace() as $value) {
                     echo $value . '<br>';
                 }
             }
         }
         switch ($resEr[0]) {
             case 'ERR0R':
                 $resEr[1] = '<b>"' . $stm->errorInfo()[1] . '"</b> ' . $stm->errorInfo()[2];
                 break;
             case '23000':
                 $resEr[1] = '<b>"23000"</b> Elément utilisé ' . "par un autre enregistrement";
                 break;
             default:
                 $resEr[1] = "<b>\"{$resEr['0']}\"</b> Erreur inattendu!";
                 break;
         }
         $result = 0;
         throw new MySQLException("Erreur sur la requête : {$sql} || état de la requète -->" . $resEr[0], self::$cnx);
     }
     return $result;
 }
示例#4
0
 /**
  * Send a push notification directly using a socket
  * @param string $deviceToken the push token for the mobile device
  * @param string $message the message to display
  * @param string $alertSound the audio file to play, otherwise use the default sound
  * @param string $unlockText if the device is locked, show "Slide to XXX" where XXX is the unlockText
  * @param int $badgeCount the number that should be shown on the springboard badge
  */
 public function SendWithSocket($deviceToken, $message, $alertSound = 'default', $unlockText = '', $badgeCount = 0)
 {
     $gatewayUrl = $this->sandboxMode ? "ssl://gateway.sandbox.push.apple.com:2195" : "ssl://gateway.push.apple.com:2195";
     $ctx = stream_context_create();
     stream_context_set_option($ctx, 'ssl', 'local_cert', $this->certFilePath);
     stream_context_set_option($ctx, 'ssl', 'passphrase', $this->certPassphrase);
     $output = new stdClass();
     $output->date = date('Y-m-d H:i:s');
     $fh = null;
     $errorMesssage = NULL;
     try {
         // Open a connection to the APNS server
         $fh = stream_socket_client($gatewayUrl, $err, $errorMesssage, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
     } catch (Exception $ex) {
         $errorMesssage = $ex->getMessage();
     }
     if ($errorMesssage || !$fh) {
         $output->success = false;
         $output->message = "Connection Failed: {$errorMesssage}";
     } else {
         $appleExpiry = time() + 10 * 24 * 60 * 60;
         //Keep push alive (waiting for delivery) for 10 days
         // format the body based on whether an unlock message was specified
         $alert = $unlockText ? array('body' => $message, 'action-loc-key' => $unlockText) : $message;
         // Create the payload body
         $body['aps'] = array('alert' => $alert, 'sound' => $alertSound, 'badge' => (int) $badgeCount);
         // Encode the payload as JSON
         $payload = json_encode($body);
         // Build the binary notification
         ExceptionThrower::$IGNORE_DEPRECATED = true;
         ExceptionThrower::Start();
         try {
             // @see https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html
             $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
             fwrite($fh, $msg, strlen($msg));
             $response = $this->getResponse($fh);
             if (!$response) {
                 // everything is cool
                 $output->success = true;
                 $output->message = 'Message sent';
             } else {
                 $output->success = false;
                 $output->message = 'Push notification failed with response: ' . $response;
             }
         } catch (Exception $ex) {
             $output->success = false;
             $output->message = $ex->getMessage();
         }
         ExceptionThrower::Stop();
     }
     // Close the connection to the server
     if ($fh) {
         @fclose($fh);
     }
     return $output;
 }
示例#5
0
文件: router.php 项目: AlvaCorp/POS-2
<?php

use Propel\Runtime\Propel;
require '../vendor/autoload.php';
require 'classes/ExceptionThrower.php';
require 'propel-config.php';
require 'session.php';
require 'direct.php';
ExceptionThrower::Start();
$session->start();
class BogusAction
{
    public $action;
    public $method;
    public $data;
    public $tid;
}
$isForm = false;
$isUpload = false;
if (isset($HTTP_RAW_POST_DATA)) {
    header('Content-Type: text/javascript');
    $data = json_decode($HTTP_RAW_POST_DATA);
} else {
    if (isset($_POST['extAction'])) {
        // form post
        $isForm = true;
        $isUpload = $_POST['extUpload'] == 'true';
        $data = new BogusAction();
        $data->action = $_POST['extAction'];
        $data->method = $_POST['extMethod'];
        $data->tid = isset($_POST['extTID']) ? $_POST['extTID'] : null;
示例#6
0
 /**
  * Processes user input and executes the specified controller method, ensuring
  * that the controller dependencies are all injected properly
  *
  * @param Phreezer $phreezer Object persistance engine
  * @param IRenderEngine $renderEngine rendering engine
  * @param string (optional) $action the user requested action (if not provided will use router->GetRoute())
  * @param Context (optional) a context object for persisting state
  * @param IRouter (optional) router object for reading/writing URLs (if not provided, GenericRouter will be used)
  */
 static function Dispatch($phreezer, $renderEngine, $action = '', $context = null, $router = null)
 {
     if ($router == null) {
         require_once 'GenericRouter.php';
         $router = new GenericRouter();
     }
     // get the route and normalize the controller name
     list($controller_param, $method_param) = $router->GetRoute($action);
     $controller_class = $controller_param . "Controller";
     if (self::$FAST_LOOKUP) {
         if (!class_exists($controller_class)) {
             $controller_file = "Controller/{$controller_class}.php";
             include_once $controller_file;
         }
         $controller = new $controller_class($phreezer, $renderEngine, $context, $router);
         $controller->{$method_param}();
         return true;
     }
     // if the controller was in a sub-directory, get rid of the directory path
     $slashPos = strpos($controller_class, '/');
     while ($slashPos !== false) {
         $controller_class = substr($controller_class, $slashPos + 1);
         $slashPos = strpos($controller_class, '/');
     }
     if (!class_exists($controller_class)) {
         // attempt to locate the controller file
         $controller_file = "Controller/" . $controller_param . "Controller.php";
         $controller_filepath = null;
         // search for the controller file in the default locations, then the include path
         $paths = array_merge(array('./libs/', './'), explode(PATH_SEPARATOR, get_include_path()));
         $found = false;
         foreach ($paths as $path) {
             $controller_filepath = self::ControllerFileExists($path . "/" . $controller_file);
             if ($controller_filepath) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             throw new Exception("File ~/libs/" . $controller_file . " was not found in include path");
         }
         // convert any php errors into an exception
         if (self::$IGNORE_DEPRECATED) {
             ExceptionThrower::Start();
         } else {
             ExceptionThrower::Start(E_ALL);
             ExceptionThrower::$IGNORE_DEPRECATED = false;
         }
         // we should be fairly certain the file exists at this point
         include_once $controller_filepath;
         // we found the file but the expected class doesn't appear to be defined
         if (!class_exists($controller_class)) {
             throw new Exception("Controller file was found, but class '" . $controller_class . "' is not defined");
         }
     }
     // create an instance of the controller class
     $controller = new $controller_class($phreezer, $renderEngine, $context, $router);
     // we have a valid instance, just verify there is a matching method
     if (!is_callable(array($controller, $method_param))) {
         throw new Exception("'" . $controller_class . "." . $method_param . "' is not a valid action");
     }
     // do not call the requested method/route if the controller request has been cancelled
     if (!$controller->IsTerminated()) {
         // file, class and method all are ok, go ahead and call it
         call_user_func(array(&$controller, $method_param));
     }
     // reset error handling back to whatever it was
     //restore_exception_handler();
     ExceptionThrower::Stop();
     return true;
 }