Ejemplo n.º 1
0
 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct(array $userSettings = array())
 {
     // Setup IoC container
     $this->container = new \Slim\Helper\Set();
     $this->container['settings'] = array_merge(static::getDefaultSettings(), $userSettings);
     // Default environment
     $this->container->singleton('environment', function ($c) {
         return \Slim\Environment::getInstance();
     });
     // Default request
     $this->container->singleton('request', function ($c) {
         return new \Slim\Http\Request($c['environment']);
     });
     // Default response
     $this->container->singleton('response', function ($c) {
         return new \Slim\Http\Response();
     });
     // Default router
     $this->container->singleton('router', function ($c) {
         return new \Slim\Router();
     });
     // Default view
     $this->container->singleton('view', function ($c) {
         $viewClass = $c['settings']['view'];
         return $viewClass instanceof \Slim\View ? $viewClass : new $viewClass();
     });
     // Default log writer
     $this->container->singleton('logWriter', function ($c) {
         $logWriter = $c['settings']['log.writer'];
         return is_object($logWriter) ? $logWriter : new \Slim\LogWriter($c['environment']['slim.errors']);
     });
     // Default log
     $this->container->singleton('log', function ($c) {
         $log = new \Slim\Log($c['logWriter']);
         $log->setEnabled($c['settings']['log.enabled']);
         $log->setLevel($c['settings']['log.level']);
         $env = $c['environment'];
         $env['slim.log'] = $log;
         return $log;
     });
     // Default mode
     $this->container['mode'] = function ($c) {
         $mode = $c['settings']['mode'];
         if (isset($_ENV['SLIM_MODE'])) {
             $mode = $_ENV['SLIM_MODE'];
         } else {
             $envMode = getenv('SLIM_MODE');
             if ($envMode !== false) {
                 $mode = $envMode;
             }
         }
         return $mode;
     };
     // Define default middleware stack
     $this->middleware = array($this);
     $this->add(new \Slim\Middleware\Flash());
     $this->add(new \Slim\Middleware\MethodOverride());
     // Make default if first instance
     if (is_null(static::getInstance())) {
         $this->setName('default');
     }
 }
Ejemplo n.º 2
0
 public function testGetAndSetWriter()
 {
     $writer1 = new MyWriter();
     $writer2 = new MyWriter();
     $log = new \Slim\Log($writer1);
     $this->assertSame($writer1, $log->getWriter());
     $log->setWriter($writer2);
     $this->assertSame($writer2, $log->getWriter());
 }
Ejemplo n.º 3
0
 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct($userSettings = array())
 {
     // Setup Slim application
     $this->settings = array_merge(self::getDefaultSettings(), $userSettings);
     $this->environment = \Slim\Environment::getInstance();
     $this->request = new \Slim\Http\Request($this->environment);
     $this->response = new \Slim\Http\Response();
     $this->router = new \Slim\Router($this->request->getResourceUri());
     $this->middleware = array($this);
     $this->add(new \Slim\Middleware\Flash());
     $this->add(new \Slim\Middleware\MethodOverride());
     // Determine application mode
     $this->getMode();
     // Setup view
     $this->view($this->config('view'));
     // Make default if first instance
     if (is_null(self::getInstance())) {
         $this->setName('default');
     }
     // Set default logger that writes to stderr (may be overridden with middleware)
     $logWriter = $this->config('log.writer');
     if (!$logWriter) {
         $logWriter = new \Slim\LogWriter($this->environment['slim.errors']);
     }
     $log = new \Slim\Log($logWriter);
     $log->setEnabled($this->config('log.enabled'));
     $log->setLevel($this->config('log.level'));
     $this->environment['slim.log'] = $log;
 }
Ejemplo n.º 4
0
 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct(array $userSettings = array())
 {
     // Setup IoC container
     $this->container = new \Slim\Helper\Set();
     $this->container['settings'] = array_merge(static::getDefaultSettings(), $userSettings);
     // Default environment
     $this->container->singleton('environment', function ($c) {
         return \Slim\Environment::getInstance();
     });
     // Default request
     $this->container->singleton('request', function ($c) {
         return new \Slim\Http\Request($c['environment']);
     });
     // Default response
     $this->container->singleton('response', function ($c) {
         return new \Slim\Http\Response();
     });
     // Default router
     $this->container->singleton('router', function ($c) {
         return new \Slim\Router();
     });
     // Default view
     $this->container->singleton('view', function ($c) {
         $viewClass = $c['settings']['view'];
         $templatesPath = $c['settings']['templates.path'];
         $view = $viewClass instanceof \Slim\View ? $viewClass : new $viewClass();
         $view->setTemplatesDirectory($templatesPath);
         return $view;
     });
     // Default log writer
     $this->container->singleton('logWriter', function ($c) {
         $logWriter = $c['settings']['log.writer'];
         return is_object($logWriter) ? $logWriter : new \Slim\LogWriter($c['environment']['slim.errors']);
     });
     // Default log
     $this->container->singleton('log', function ($c) {
         $log = new \Slim\Log($c['logWriter']);
         $log->setEnabled($c['settings']['log.enabled']);
         /**
          * set exception and message queue cnofiguration to logger 
          * @author Mustafa Zeynel Dağlı
          */
         $log->setExceptionsQueue($c['settings']['exceptions.rabbitMQ']);
         /**
          * set message queue logging format on message receiver
          * @author Mustafa Zeynel Dağlı
          */
         $log->setExceptionsQueueLogging($c['settings']['exceptions.rabbitMQ.logging']);
         /**
          * set exception queue name
          * @author Mustafa Zeynel Dağlı
          */
         $log->setExceptionsQueueName($c['settings']['exceptions.rabbitMQ.queue.name']);
         /**
          * set serial for message queue in log class
          * @author Mustafa Zeynel Dağlı
          */
         $log->setSerial($c['settings']['request.serial']);
         //print_r('slim construct log level-->'.$c['settings']['log.level']);
         $log->setLevel($c['settings']['log.level']);
         $env = $c['environment'];
         $env['slim.log'] = $log;
         return $log;
     });
     // Default mode
     $this->container['mode'] = function ($c) {
         $mode = $c['settings']['mode'];
         if (isset($_ENV['SLIM_MODE'])) {
             $mode = $_ENV['SLIM_MODE'];
         } else {
             $envMode = getenv('SLIM_MODE');
             if ($envMode !== false) {
                 $mode = $envMode;
             }
         }
         return $mode;
     };
     // Define default middleware stack
     $this->middleware = array($this);
     //$this->add(new \Slim\Middleware\Flash());
     $this->add(new \Slim\Middleware\MethodOverride());
     //$this->add(new \Slim\Middleware\MiddlewareTest());
     $this->add(new \Slim\Middleware\Flash());
     //$this->add(new \Slim\Middleware\MethodOverride());
     // Make default if first instance
     if (is_null(static::getInstance())) {
         $this->setName('default');
     }
 }