/** * Start redirecting PHP errors * @param int $level PHP Error level to catch (Default = E_ALL & ~E_DEPRECATED) */ static function Start($level = null) { if ($level == null) { if (defined("E_DEPRECATED")) { $level = E_ALL & ~E_DEPRECATED; } else { // php 5.2 and earlier don't support E_DEPRECATED $level = E_ALL; self::$IGNORE_DEPRECATED = true; } } set_error_handler(array("ExceptionThrower", "HandleError"), $level); }
/** * Commence la redirection des erreurs * @param int $level PHP niveau d'Erreur à attraper (Default = E_ALL & ~E_DEPRECATED) */ static function Start($level = null) { if ($level == null) { if (defined("E_DEPRECATED")) { $level = E_ALL & ~E_DEPRECATED; } else { // php 5.2 et les versions antérieur ne support pas E_DEPRECATED $level = E_ALL; self::$IGNORE_DEPRECATED = true; } } //Modification du handler // il appelera la class lorqu'il attrapera une erreur set_error_handler(array("ExceptionThrower", "HandleError"), $level); }
/** * @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; }
/** * 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; }
/** * 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; }
/** * 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; }
public function eat() { ExceptionThrower::throwWithMessage('Rotten banana'); }
<?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;
print htmlentities($e['sqltext']); printf("\n%" . ($e['offset'] + 1) . "s", "^"); print "\n</pre>\n"; } else { $results = array(); $numrows = oci_fetch_all($res, $results, null, null, OCI_FETCHSTATEMENT_BY_ROW); if ($numrows == 0) { echo "Tickets Not available!!"; } else { oci_execute($res); usleep(100); print "<TABLE border \"1\">"; $first = 0; while ($row = @oci_fetch_assoc($res)) { if (!$first) { $first = 1; print "<TR><TH>"; print implode("</TH><TH>", array_keys($row)); print "</TH></TR>\n"; } print "<TR><TD>"; print @implode("</TD><TD>", array_values($row)); print "</TD></TR>\n"; } print "</TABLE>"; } } include 'footer.php'; oci_close($conn); ExceptionThrower::Stop();
/** * Fired by the PHP error handler function. Calling this function will * always throw an exception unless error_reporting == 0. If the * PHP command is called with @ preceeding it, then it will be ignored * here as well. * * @deprecated use ExceptionThrower::HandleError instead * @param string $code * @param string $string * @param string $file * @param string $line * @param string $context */ static function HandleException($code, $string, $file, $line, $context) { ExceptionThrower::HandleError($code, $string, $file, $line, $context); }
/** * Kein Unterschied bei speziellen Exceptions. * * @expectedException \InvalidArgumentException */ public function testUsingPhpException() { $class = new ExceptionThrower(); $class->usingPhpException(-5); }