Skip to content

Commit

Permalink
support PSR-7
Browse files Browse the repository at this point in the history
  • Loading branch information
xujiajun committed Jul 12, 2017
1 parent cdf8ff4 commit 4006a3e
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 8 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"pda/pheanstalk": "^3.1",
"symfony/polyfill-iconv": "^1.2",
"filp/whoops": "^2.1",
"psr/container": "~1.0"
"psr/container": "~1.0",
"symfony/psr-http-message-bridge": "^1.0",
"zendframework/zend-diactoros": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "5.5.*"
Expand Down
164 changes: 163 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/Framework/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use TastPHP\Framework\Cache\RedisServiceProvider;
use TastPHP\Framework\Config\Config;
use TastPHP\Framework\Config\ConfigServiceProvider;
use TastPHP\Framework\Container\PimpleContainerProvider;
use TastPHP\Framework\CsrfToken\CsrfTokenServiceProvider;
use TastPHP\Framework\Doctrine\DoctrineServiceProvider;
use TastPHP\Framework\EventDispatcher\EventDispatcher;
Expand Down Expand Up @@ -83,7 +84,8 @@ class Kernel extends Container
'SwiftMailer' => SwiftMailerServiceProvider::class,
'Queue' => QueueServiceProvider::class,
'Router' => RouterServiceProvider::class,
'ExceptionHandler' => ExceptionHandlerServiceProvider::class
'ExceptionHandler' => ExceptionHandlerServiceProvider::class,
'Container' => PimpleContainerProvider::class
];

use KernelListeners;
Expand Down
19 changes: 15 additions & 4 deletions src/Framework/Router/RouterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@

namespace TastPHP\Framework\Router;

use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use TastPHP\Framework\Service\ServiceProvider;
use TastPHP\Framework\Router\TastRouter;
use TastPHP\Framework\Router\RouterService;
use Symfony\Component\HttpFoundation\Request;
use TastPHP\Framework\Event\AppEvent;

class RouterServiceProvider extends ServiceProvider
{
public function register()
{
{
$request = Request::createFromGlobals();
$this->app['Request'] = $request;
$this->app->singleton('eventDispatcher')->dispatch(AppEvent::REQUEST, new \TastPHP\Framework\Event\HttpEvent($request));

$psrRequest = $request;

if (!$this->app->runningInConsole()) {
$psr7Factory = new DiactorosFactory();
$psrRequest = $psr7Factory->createRequest($request);

$httpFoundationFactory = new HttpFoundationFactory();
$psrRequest = $httpFoundationFactory->createRequest($psrRequest);
}

$this->app->singleton('eventDispatcher')->dispatch(AppEvent::REQUEST, new \TastPHP\Framework\Event\HttpEvent($psrRequest));

$router = new TastRouter();
$router->register($this->app);
Expand Down
4 changes: 3 additions & 1 deletion src/Framework/Service/ServiceMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public static function __callStatic($method, $parameters)
$map = static::getMap();
$object = \Kernel::getInstance()->singleton($map);

if (!is_object($object)) throw new \RuntimeException($map.' can not be loaded , check your service provider config!');
if (!is_object($object)) {
throw new \RuntimeException($map . ' can not be loaded , check your service provider config!');
}

return call_user_func_array([$object, $method], $parameters);
}
Expand Down

0 comments on commit 4006a3e

Please sign in to comment.