예제 #1
0
/**
 * Bootstrap
 *
 * Example function for initializing a system.
 *
 * @param bool   Whether this is a development server.
 * @param string The filename of the log file to use.
 * @return HTTP\Response
 */
function bootstrap($isDevelopmentServer, $logFile)
{
    try {
        /************/
        /* Autoload */
        /************/
        $component = 'Autoload';
        $evokeDir = __DIR__ . '/src/';
        $autoloadDir = $evokeDir . 'Evoke/Service/Autoload/';
        require $autoloadDir . 'AutoloadIface.php';
        require $autoloadDir . 'PSR0Namespace.php';
        $autoloader = new Service\Autoload\PSR0Namespace($evokeDir, 'Evoke\\');
        spl_autoload_register([$autoloader, 'load']);
        /***********/
        /* Logging */
        /***********/
        $component = 'Logging';
        $logging = new Service\Log\Logging(new DateTime());
        $logging->attach(new Service\Log\File($logFile));
        /************/
        /* Response */
        /************/
        $component = 'Response';
        $response = new HTTP\Response();
        /********************/
        /* Shutdown Handler */
        /********************/
        $component = 'Shutdown Handler';
        $viewShutdownMessageBox = new View\HTML5\MessageBox(['class' => 'Message_Box Shutdown']);
        $viewError = new View\HTML5\Error();
        $xhtmlWriter = new Writer\XML(new XMLWriter());
        $shutdownHandler = new Service\ShutdownHandler('*****@*****.**', $response, $isDevelopmentServer, $viewShutdownMessageBox, $xhtmlWriter, $viewError);
        register_shutdown_function([$shutdownHandler, 'handler']);
        /*********************/
        /* Exception Handler */
        /*********************/
        $component = 'Exception Handler';
        $viewExceptionMessageBox = new View\HTML5\MessageBox(['class' => 'Message_Box Exception']);
        $viewException = new View\HTML5\Exception();
        $exceptionHandler = new Service\ExceptionHandler($response, $isDevelopmentServer, $viewExceptionMessageBox, $xhtmlWriter, $viewException);
        set_exception_handler([$exceptionHandler, 'handler']);
        /*****************/
        /* Error Handler */
        /*****************/
        $component = 'Error Handler';
        $errorHandler = new Service\ErrorHandler($logging);
        set_error_handler([$errorHandler, 'handler']);
        return $response;
    } catch (\Exception $e) {
        header('HTTP/1.1 500 Internal Server Error');
        die('System failure due to: ' . $component . '.' . $isDevelopmentServer ? ' Exception: ' . $e->getMessage() : '');
    }
}
예제 #2
0
 /**
  * We don't log to detached observers.
  */
 public function testDontLogToDetached()
 {
     $dateTime = new \DateTime();
     $expectedMessage = 'This is the message.';
     $expectedLevel = 'User Notice';
     $detached = 3;
     $object = new Logging($dateTime);
     $observers = [];
     for ($i = 0; $i < 4; $i++) {
         $observers[$i] = $this->createMock('Evoke\\Service\\Log\\LoggerIface');
         if ($i === $detached) {
             $observers[$i]->expects($this->never())->method('log');
         } else {
             $observers[$i]->expects($this->once())->method('log')->with($dateTime, $expectedMessage, $expectedLevel);
         }
         $object->attach($observers[$i]);
     }
     $object->detach($observers[$detached]);
     $object->log('This is the message.', E_USER_NOTICE);
 }