Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
"description": "A nice PHP microframework",
"license": "MIT",
"require": {
"php": ">=5.4.0",
"symfony/config": "~2.3",
"symfony/http-kernel": "~2.3",
"symfony/dependency-injection": "~2.3",
"nikic/fast-route": ">=0.6"
"php": ">=8.1",
"symfony/config": "~6.3",
"symfony/http-kernel": "~6.3",
"symfony/dependency-injection": "~6.3",
"symfony/yaml": "~6.3",
"nikic/fast-route": ">=1.3"
},
"require-dev": {
"symfony/debug": "~2.3",
"symfony/expression-language": "~2.4",
"phpunit/phpunit": "~3.7",
"codeclimate/php-test-reporter": "dev-master"
"symfony/expression-language": "~6.3",
"phpunit/phpunit": "~10.3"
},
"suggest": {
"stack/builder": "Stack HttpKernel middlewares - http://stackphp.com",
Expand Down
8 changes: 4 additions & 4 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ public function run(Request $request = null)
*
* @param Request $request A Request instance
* @param int $type The type of the request
* (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
* (one of HttpKernelInterface::MAIN_REQUEST or HttpKernelInterface::SUB_REQUEST)
* @param bool $catch Whether to catch exceptions or not
*
* @return Response A Response instance
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response
{
if (!$this->booted) {
$this->boot();
Expand Down Expand Up @@ -361,13 +361,13 @@ public function getContainer()
* @param object|callable $service The service instance
* @param string $scope The scope of the service
*/
public function set($id, $service, $scope = ContainerInterface::SCOPE_CONTAINER)
public function set(string $id, ?object $service)
{
if (!$this->booted) {
$this->boot();
}

$this->container->set($id, $service, $scope);
$this->container->set($id, $service);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function initializeContainer(Application $application, array $extensions
$this->dumpContainer($cache, $container, $class, 'Container');
}

require_once $cache;
require_once $cache->getPath();

return new $class();
}
Expand All @@ -97,6 +97,11 @@ protected function getContainerClass(Application $application)
*/
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
{
if (!$container->isCompiled()) {
// The container must be compiled before it can be dumped.
$container->compile();
}

$dumper = new PhpDumper($container);
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass;

/**
* Creates and initializes a Service Container, ready for use by the Application
Expand Down Expand Up @@ -62,18 +62,14 @@ public function initializeContainer(Application $application, array $extensions
$container->setParameter('app.cache_dir', $application->getCacheDir());
$container->setParameter('app.log_dir', $application->getLogDir());

$container->register('event_dispatcher', 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher')
->setArguments(array(new Reference('service_container')));
$container->register('event_dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher')
->setPublic(true);

$container->register('app', 'Symfony\Component\HttpKernel\HttpKernelInterface')
->setSynthetic(true);

$container->register('request', 'Symfony\Componenet\HttpKernel\Request')
->setSynthetic(true)
->setSynchronized(true)
->setScope('request');

$container->addScope(new Scope('request'));
->setSynthetic(true);

$extensionAliases = array();
foreach ($extensions as $extension) {
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/LogConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class LogConfiguration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('logging');
$treeBuilder = new TreeBuilder('logging');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
3 changes: 2 additions & 1 deletion src/Extension/LogExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ private function configureStreamChannel(array $channelConfig, ContainerBuilder $
$container->register($loggerService)
->setClass('Monolog\Logger')
->addArgument($name)
->addMethodCall('pushHandler', array(new Reference($handlerService)));
->addMethodCall('pushHandler', array(new Reference($handlerService)))
->setPublic(true);
}

private function configureErrorLogChannel(array $channelConfig, ContainerBuilder $container)
Expand Down
12 changes: 6 additions & 6 deletions src/Extension/RouterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public function load(array $config, ContainerBuilder $container)
->addArgument(new Reference('router.collector'));

$container->register('router.dispatcher', 'FastRoute\Dispatcher')
->setFactoryService('router.dispatcher_factory')
->setFactoryMethod('create');
->setFactory(array(new Reference('router.dispatcher_factory'), 'create'));

$container->register('router.dispatcher_subscriber', 'Nice\Router\RouterSubscriber')
->addArgument(new Reference('router.dispatcher'))
Expand All @@ -68,11 +67,12 @@ public function load(array $config, ContainerBuilder $container)
'request',
ContainerInterface::NULL_ON_INVALID_REFERENCE,
false
)));
)))
->setPublic(true);

$container->register('http_kernel', 'Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel')
$container->register('http_kernel', 'Symfony\Component\HttpKernel\HttpKernel')
->addArgument(new Reference('event_dispatcher'))
->addArgument(new Reference('service_container'))
->addArgument(new Reference('router.controller_resolver'));
->addArgument(new Reference('router.controller_resolver'))
->setPublic(true);
}
}
3 changes: 2 additions & 1 deletion src/Extension/SessionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class SessionExtension extends Extension
*/
public function load(array $config, ContainerBuilder $container)
{
$container->register('session', 'Symfony\Component\HttpFoundation\Session\Session');
$container->register('session', 'Symfony\Component\HttpFoundation\Session\Session')
->setPublic(true);

$container->register('session.session_subscriber', 'Nice\Session\SessionSubscriber')
->addArgument(new Reference('service_container'))
Expand Down
2 changes: 1 addition & 1 deletion src/Router/ContainerAwareControllerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setContainer(ContainerInterface $container = null)
*
* @return callable
*/
protected function createController($controller)
protected function createController(string $controller): callable
{
$parts = explode(':', $controller);
if (count($parts) === 2) {
Expand Down
2 changes: 1 addition & 1 deletion src/Router/RouteCollector/CachedCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getData()
$cache->write('<?php return '.var_export($routes, true).';');
}

return require $cache;
return require $cache->getPath();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Router/RouterSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use FastRoute\Dispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(Dispatcher $dispatcher)
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
if ($request->get('_controller')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Router/UrlGenerator/CachedDataGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public function getData()
$cache->write('<?php return '.var_export($routes, true).';');
}

return require $cache;
return require $cache->getPath();
}
}
6 changes: 3 additions & 3 deletions src/Router/WrappedHandlerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Nice\Router;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand All @@ -19,9 +19,9 @@
class WrappedHandlerSubscriber implements EventSubscriberInterface
{
/**
* @param GetResponseEvent $event
* @param RequestEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
$handler = $request->get('_controller');
Expand Down
6 changes: 3 additions & 3 deletions src/Session/SessionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand All @@ -36,9 +36,9 @@ public function __construct(ContainerInterface $container)
}

/**
* @param GetResponseEvent $event
* @param RequestEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(RequestEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
Expand Down
17 changes: 9 additions & 8 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

namespace Nice\Tests;

use PHPUnit\Framework\TestCase;
use Nice\Application;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface;

class ApplicationTest extends \PHPUnit_Framework_TestCase
class ApplicationTest extends TestCase
{
/**
* Test the instantiation
Expand Down Expand Up @@ -190,7 +191,7 @@ public function testDefaultExtensions()
{
/** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */
$app = $this->getMockBuilder('Nice\Application')
->setMethods(array('getRootDir'))
->onlyMethods(array('getRootDir'))
->setConstructorArgs(array('init', true))
->getMock();
$app->expects($this->any())
Expand All @@ -211,7 +212,7 @@ public function testInitializeContainer()
{
/** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */
$app = $this->getMockBuilder('Nice\Application')
->setMethods(array('getRootDir'))
->onlyMethods(array('getRootDir'))
->setConstructorArgs(array('init', true))
->getMock();
$app->expects($this->any())
Expand All @@ -234,14 +235,14 @@ public function testFailureToCreateCacheDir()
{
/** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */
$app = $this->getMockBuilder('Nice\Application')
->setMethods(array('getRootDir', 'getCacheDir'))
->onlyMethods(array('getRootDir', 'getCacheDir'))
->setConstructorArgs(array('create', true))
->getMock();
$app->expects($this->any())
->method('getCacheDir')
->will($this->returnValue('/someunwriteable/path'));

$this->setExpectedException('RuntimeException', 'Unable to create the cache directory');
$this->expectException('RuntimeException', 'Unable to create the cache directory');

$app->boot();
}
Expand All @@ -257,14 +258,14 @@ public function testFailureToWriteCacheDir()

/** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */
$app = $this->getMockBuilder('Nice\Application')
->setMethods(array('getRootDir', 'getCacheDir'))
->onlyMethods(array('getRootDir', 'getCacheDir'))
->setConstructorArgs(array('write', true))
->getMock();
$app->expects($this->any())
->method('getCacheDir')
->will($this->returnValue($tmpdir));

$this->setExpectedException('RuntimeException', 'Unable to write in the cache directory');
$this->expectException('RuntimeException', 'Unable to write in the cache directory');

$app->boot();
}
Expand All @@ -280,7 +281,7 @@ protected function getMockApplication(HttpKernelInterface $kernel = null, $cache

/** @var \Nice\Application|\PHPUnit_Framework_MockObject_MockObject $app */
$app = $this->getMockBuilder('Nice\Application')
->setMethods(array('getRootDir', 'registerDefaultExtensions', 'initializeContainer'))
->onlyMethods(array('getRootDir', 'registerDefaultExtensions', 'initializeContainer'))
->setConstructorArgs(array('test', true, $cache))
->getMock();
$app->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

namespace Nice\Tests\DependencyInjection\ConfigurationProvider;

use PHPUnit\Framework\TestCase;
use Nice\DependencyInjection\ConfigurationProvider\FileConfigurationProvider;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class FileConfigurationProviderTest extends \PHPUnit_Framework_TestCase
class FileConfigurationProviderTest extends TestCase
{
/**
* Test no-operation functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@

namespace Nice\Tests\DependencyInjection\ConfigurationProvider;

use PHPUnit\Framework\TestCase;
use Nice\DependencyInjection\ConfigurationProvider\NullConfigurationProvider;

class NullConfigurationProviderTest extends \PHPUnit_Framework_TestCase
class NullConfigurationProviderTest extends TestCase
{
/**
* Test no-operation functionality
*/
public function testNoOp()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$container = $this->getMockForAbstractClass('Symfony\Component\DependencyInjection\ContainerBuilder');
$container->expects($this->never())
->method($this->anything());

Expand Down
Loading