subscribe

Introduction to using SabreAMF with Flex

Wil wrote a pretty good introduction to using SabreAMF with flex. He's making use of the Zend autoloader to load the classes. If you're new to SabreAMF, this might be a good starting point.

He also mentions its best to set display_errors to 0, to suppress PHP errors. I personally prefer re-throw all PHP errors as exceptions using the following class:

<?php

    /**
     * This is a default exception wrapper for PHP errors.
     * This allows you to deal with PHP errors as exceptions (using try..catch blocks etc..)
     *
     * @uses Exception
     * @package Sabre
     * @subpackage PHP
     * @version $Id: Exception.php 733 2007-05-15 22:04:52Z evert $
     * @copyright Copyright (C) 2007 Rooftop Solutions. All rights reserved.
     * @author Evert Pot (http://www.rooftopsolutions.nl)
     */
    class Sabre_PHP_Exception extends Exception {

        /**
         * __construct
         *
         * @param string $message
         * @param string $code
         * @param string $file
         * @param int $line
         * @return void
         */
        function __construct($message,$code=false,$file=false,$line=false) {

            parent::__construct($message,$code);
            $this->file = $file;
            $this->line = $line;

        }

        /**
         * Register this class as an error handler
         *
         * @return void
         */
        static function register() {

            set_error_handler(array('Sabre_PHP_Exception','handleError'));

        }

        static function unregister() {

            restore_error_handler();

        }

        /**
         * handleError
         *
         * @param string $code
         * @param string $message
         * @param string $file
         * @param int $line
         * @return void
         */
        static function handleError($code,$message,$file,$line) {

            if (!$code) return;
            throw new self($message,$code,$file,$line);

        }

    }

?>

Simply call Sabre_PHP_Exception::register();, and you're off..

Web mentions

Comments

  • blaz

    Hi,

    first great job for Sabre

    then I woold like to know if we can catch php Exception in the FaultResult handler on flex?

    thanks
  • blaz

    hum.. i receive the Exception on the e.fault.message
  • Evert

    Evert

    So you fixed it?

  • blaz

    yes thanks,

    The probleme was coming from my code because i catch Exception somewhere and i return the exceptions :S

    I have seen this part of code in CallbackServer.php that help me :

    $response = new SabreAMF_AMF3_ErrorMessage($request['data']);
    $response->faultString = $e->getMessage();
    $response->faultCode = $e->getCode();
    $response->faultDetail = $detail;

    thanks
  • Evert

    Evert

    Cool! Glad it works..