final protected function _attachDefaultEvents()
    {
        if ($this->_isEventAttached)
            return;

        // Attach Default Listener:

        # Throw Exception if exception not handle on Error Event
        $this->event()->on(EventHeapOfSapi::EVENT_APP_ERROR
            /**
             * @param \Exception $exception pass as argument when app_error happen
             * @param bool $exceptionShouldThrow
             */
            , function(\Exception $exception = null, $sapi = null, $exceptionShouldThrow = true)
            {
                // TODO Response Aware Exception; map exception code to response code aware and more; include headers
                $exception_code = $exception->getCode();

                /** @var iHttpResponse $response */
                $response = $sapi->services()->get('/httpResponse');
                if (Status::_($response)->isSuccess()) {
                    if (! (is_numeric($exception_code)
                        && $exception_code > 100
                        && $exception_code <= 600
                    ))
                        $exception_code = 500;

                    $response->setStatusCode(($exception_code) ? $exception_code : 500);
                }


                /** @var $e EventError */
                if ($exceptionShouldThrow && $exception instanceof \Exception)
                    throw $exception;
            }
            , self::LISTENER_THROW_EXCEPTION_PRIORITY
        );

        $this->doAttachDefaultEvents();
        $this->_isEventAttached = true;
    }
final protected function _attachDefaultEvents()
    {
        if ($this->_isEventAttached)
            return;

        // Attach Default Listener:

        # Throw Exception if exception not handle on Error Event
        $this->event()->on(EventHeapOfSapi::EVENT_APP_ERROR
            /**
             * @param \Exception $exception pass as argument when app_error happen
             * @param bool $exceptionShouldThrow
             */
            , function(\Exception $exception = null, $sapi = null, $exceptionShouldThrow = true)
            {
                // TODO Response Aware Exception; map exception code to response code aware and more; include headers
                $exception_code = $exception->getCode();

                /** @var iHttpResponse $response */
                $response = $sapi->services()->get('/httpResponse');
                if (Status::_($response)->isSuccess()) {
                    if (! (is_numeric($exception_code)
                        && $exception_code > 100
                        && $exception_code <= 600
                    ))
                        $exception_code = 500;

                    $response->setStatusCode(($exception_code) ? $exception_code : 500);
                }


                /** @var $e EventError */
                if ($exceptionShouldThrow && $exception instanceof \Exception)
                    throw $exception;
            }
            , self::LISTENER_THROW_EXCEPTION_PRIORITY
        );

        $this->doAttachDefaultEvents();
        $this->_isEventAttached = true;
    }
final protected function _attachDefaultEvents ( ) { if ( $ this -> _isEventAttached ) return ; // Attach Default Listener: # Throw Exception if exception not handle on Error Event $ this -> event ( ) -> on ( EventHeapOfSapi :: EVENT_APP_ERROR /**
             * @param \Exception $exception pass as argument when app_error happen
             * @param bool $exceptionShouldThrow
             */ , function ( \ Exception $ exception = null , $ sapi = null , $ exceptionShouldThrow = true ) { // TODO Response Aware Exception; map exception code to response code aware and more; include headers $ exception_code = $ exception -> getCode ( ) ; /** @var iHttpResponse $response */ $ response = $ sapi -> services ( ) -> get ( '/httpResponse' ) ; if ( Status :: _ ( $ response ) -> isSuccess ( ) ) { if ( ! ( is_numeric ( $ exception_code ) && $ exception_code > 100 && $ exception_code <= 600 ) ) $ exception_code = 500 ; $ response -> setStatusCode ( ( $ exception_code ) ? $ exception_code : 500 ) ; } /** @var $e EventError */ if ( $ exceptionShouldThrow && $ exception instanceof \ Exception ) throw $ exception ; } , self :: LISTENER_THROW_EXCEPTION_PRIORITY ) ; $ this -> doAttachDefaultEvents ( ) ; $ this -> _isEventAttached = true ; }
Initialize To Events

- usually bind listener(s) to events

@return void
Initialize To Events