示例#1
0
 /**
  * Process the application given a request method and URI
  *
  * @param string $requestMethod the request method (e.g. GET, POST, etc.)
  * @param string $requestUri the request URI
  * @return \Yee\Http\Response
  */
 public function runApp($requestMethod, $requestUri)
 {
     // Create a mock environment for testing with
     $environment = \Yee\Environment::mock(['REQUEST_METHOD' => $requestMethod, 'PATH_INFO' => $requestUri, 'REQUEST_URI' => $requestUri]);
     // Instantiate the application
     $app = new \Yee\Yee(array('version' => '0.0.0', 'debug' => false, 'mode' => 'testing'));
     $app->view(new \Yee\Views\Twig());
     new \Yee\Managers\RoutingCacheManager(array('cache' => __DIR__ . '/../cache/routing', 'controller' => array(__DIR__ . '/../App/Controllers')));
     $request = $app->request();
     $response = $app->response();
     ob_start();
     $app->execute();
     ob_end_clean();
     return $response;
 }
示例#2
0
文件: Yee.php 项目: yeephp/yeephp
 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct(array $userSettings = array())
 {
     // Setup IoC container
     $this->container = new \Yee\Helper\Set();
     $this->container['settings'] = array_merge(static::getDefaultSettings(), $userSettings);
     // Default environment
     $this->container->singleton('environment', function ($c) {
         return \Yee\Environment::getInstance();
     });
     // Default request
     $this->container->singleton('request', function ($c) {
         return new \Yee\Http\Request($c['environment']);
     });
     // Default response
     $this->container->singleton('response', function ($c) {
         return new \Yee\Http\Response();
     });
     // Default router
     $this->container->singleton('router', function ($c) {
         return new \Yee\Router();
     });
     // Default view
     $this->container->singleton('view', function ($c) {
         $viewClass = $c['settings']['view'];
         $templatesPath = $c['settings']['templates.path'];
         $view = $viewClass instanceof \Yee\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 \Yee\LogWriter($c['environment']['yee.errors']);
     });
     // Default log
     $this->container->singleton('log', function ($c) {
         $log = new \Yee\Log($c['logWriter']);
         $log->setEnabled($c['settings']['log.enabled']);
         $log->setLevel($c['settings']['log.level']);
         $env = $c['environment'];
         $env['yee.log'] = $log;
         return $log;
     });
     // Default mode
     $this->container['mode'] = function ($c) {
         $mode = $c['settings']['mode'];
         if (isset($_ENV['YEE_MODE'])) {
             $mode = $_ENV['YEE_MODE'];
         } else {
             $envMode = getenv('YEE_MODE');
             if ($envMode !== false) {
                 $mode = $envMode;
             }
         }
         return $mode;
     };
     // Define default middleware stack
     $this->middleware = array($this);
     $this->add(new \Yee\Middleware\Flash());
     $this->add(new \Yee\Middleware\MethodOverride());
     // Make default if first instance
     if (is_null(static::getInstance())) {
         $this->setName('default');
     }
 }