Exemple #1
0
 /**
  * Initialize the server object
  *
  * @param Container $container
  *
  * @return Server
  * @throws \ErrorException
  */
 public static function init(Container $container = null)
 {
     if (empty(self::$_instance)) {
         // 环境检测
         if (version_compare(PHP_VERSION, '5.6.0', '<')) {
             throw new \ErrorException('NONSUPPORT_PHP_VERSION');
         }
         if (is_null($container)) {
             $container = Container::instance();
         }
         self::$_instance = new Server($container->getContainer());
     }
     return self::$_instance;
 }
 /**
  * @return Session
  */
 public function getSession()
 {
     return Container::instance()->get(Session::class);
 }
 /**
  * @return Response
  */
 public function getResponse()
 {
     return Container::instance()->get(Response::class);
 }
 /**
  * @return LoggerInterface
  */
 protected function getLogger()
 {
     return Container::instance()->get(LoggerInterface::class);
 }
 /**
  * @return Request
  */
 public function getRequest()
 {
     return Container::instance()->get(Request::class);
 }
 /**
  * @return \PDO
  */
 public function getPDO()
 {
     return Container::instance()->get(\PDO::class);
 }
Exemple #7
0
<?php

/**
 * FocusPHP
 *
 * @link      http://aicode.cc/
 * @copyright 管宜尧 <*****@*****.**>
 * @license   http://www.opensource.org/licenses/mit-license.php MIT (see the
 *            LICENSE file)
 */
require __DIR__ . '/vendor/autoload.php';
define('BASE_PATH', __DIR__ . '/src');
$basicContainer = new \Focus\BasicContainer(__DIR__ . '/src/Configs/container.php');
$server = \Focus\Server::init(\Focus\Container::instance()->setContainer($basicContainer));
$server->registerExceptionHandler(function ($exception) {
    echo "<pre>";
    echo $exception;
    echo "</pre>";
});
$server->setNotFoundRouter(new \Demo\Libraries\NotFoundRouter());
// 先注册者优先
$server->registerRouter(new \Focus\MVC\Router('Demo\\Controllers', ['/^article\\/([0-9]+).html$/' => 'post/show?id=$1', '/^category\\/([0-9]+).html$/' => 'post/list?cat=$1', '/^tag\\/(.*?).html$/' => 'post/tag?tag=$1', '/^about.html$/' => 'index/about', '/^api\\/blog\\/related-(.*?).json$/' => 'api/relatedPosts?tags=$1', '/^管宜尧$/' => 'index/admin', '/^cache$/' => 'index/cache', '/^rss.xml$/' => 'rss/show']));
$server->run();
 /**
  * 获取Config实例
  *
  * @return Config
  */
 public function getConfig()
 {
     return Container::instance()->get(Config::class);
 }