Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
16 changes: 7 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
"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",
"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 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,13 @@ 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');

$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
9 changes: 4 additions & 5 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 @@ -70,9 +69,9 @@ public function load(array $config, ContainerBuilder $container)
false
)));

$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);
}
}
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
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,9 +9,10 @@

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

namespace Nice\Tests\DependencyInjection\ContainerInitializer;

use PHPUnit\Framework\TestCase;
use Nice\Application;
use Nice\DependencyInjection\ContainerInitializer\CachedInitializer;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class CachedInitializerTest extends \PHPUnit_Framework_TestCase
class CachedInitializerTest extends TestCase
{
/**
* Test container initialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Nice\Tests\DependencyInjection\ContainerInitializer;

use PHPUnit\Framework\TestCase;
use Nice\Application;
use Nice\DependencyInjection\CompilerAwareExtensionInterface;
use Nice\DependencyInjection\ConfigurationProvider\NullConfigurationProvider;
Expand All @@ -18,7 +19,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;

class DefaultInitializerTest extends \PHPUnit_Framework_TestCase
class DefaultInitializerTest extends TestCase
{
/**
* Test container initialization
Expand Down
3 changes: 2 additions & 1 deletion tests/Extension/LogConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

namespace Nice\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Nice\Extension\LogConfiguration;
use Symfony\Component\Config\Definition\Processor;

class LogConfigurationTest extends \PHPUnit_Framework_TestCase
class LogConfigurationTest extends TestCase
{
public function testDefaultConfig()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Extension/LogExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

namespace Nice\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Nice\Extension\LogExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class LogExtensionTest extends \PHPUnit_Framework_TestCase
class LogExtensionTest extends TestCase
{
/**
* Test the LogExtension
Expand Down
3 changes: 2 additions & 1 deletion tests/Extension/RouterExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

namespace Nice\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Nice\Extension\RouterExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class RouterExtensionTest extends \PHPUnit_Framework_TestCase
class RouterExtensionTest extends TestCase
{
/**
* Test the RouterExtension
Expand Down
3 changes: 2 additions & 1 deletion tests/Extension/SessionExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

namespace Nice\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Nice\Extension\SessionExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class SessionExtensionTest extends \PHPUnit_Framework_TestCase
class SessionExtensionTest extends TestCase
{
/**
* Test the RouterExtension
Expand Down
3 changes: 2 additions & 1 deletion tests/Router/ContainerAwareControllerResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

namespace Nice\Tests\Router;

use PHPUnit\Framework\TestCase;
use Nice\Router\ContainerAwareControllerResolver;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;

class ContainerAwareControllerResolverTest extends \PHPUnit_Framework_TestCase
class ContainerAwareControllerResolverTest extends TestCase
{
/**
* Test that the ContainerAwareControllerResolver properly injects the container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

namespace Nice\Tests\Router\DispatcherFactory;

use PHPUnit\Framework\TestCase;
use Nice\Router\DispatcherFactory\GroupCountBasedFactory;

class GroupCountBasedFactoryTest extends \PHPUnit_Framework_TestCase
class GroupCountBasedFactoryTest extends TestCase
{
/**
* Test Dispatcher creation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
namespace Nice\Tests\Router\NamedDataGenerator;

use FastRoute\DataGenerator;
use PHPUnit\Framework\TestCase;
use Nice\Router\NamedDataGenerator\HandlerWrapperGenerator;

class HandlerWrapperGeneratorTest extends \PHPUnit_Framework_TestCase
class HandlerWrapperGeneratorTest extends TestCase
{
/**
* Tests addRoute functionality
Expand Down
3 changes: 2 additions & 1 deletion tests/Router/RouteCollector/CachedCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

namespace Nice\Tests\Router\RouteCollector;

use PHPUnit\Framework\TestCase;
use Nice\Router\RouteCollector\CachedCollector;

class CachedCollectorTest extends \PHPUnit_Framework_TestCase
class CachedCollectorTest extends TestCase
{
/**
* Test basic caching
Expand Down
3 changes: 2 additions & 1 deletion tests/Router/RouteCollector/SimpleCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

namespace Nice\Tests\Router\RouteCollector;

use PHPUnit\Framework\TestCase;
use Nice\Router\RouteCollector\SimpleCollector;

class SimpleCollectorTest extends \PHPUnit_Framework_TestCase
class SimpleCollectorTest extends TestCase
{
/**
* Test basic functionality
Expand Down
3 changes: 2 additions & 1 deletion tests/Router/RouteCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

namespace Nice\Tests\Router\RouteCollector;

use PHPUnit\Framework\TestCase;
use Nice\Router\RouteCollector;

class RouteCollectorTest extends \PHPUnit_Framework_TestCase
class RouteCollectorTest extends TestCase
{
/**
* Test basic functionality
Expand Down
Loading