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
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"description": "Integrates Twig with Nice PHP framework",
"license": "MIT",
"require": {
"php": ">=5.4.0",
"nice/templating": "1.0.x-dev",
"twig/twig": "~1.15",
"symfony/config": "~2.3",
"symfony/dependency-injection": "~2.3"
"php": ">=8.1.0",
"nice/templating": "dev-php-and-symfony-update",
"twig/twig": "~2.13",
"symfony/config": "~6.3",
"symfony/dependency-injection": "~6.3"
},
"require-dev": {
"phpunit/phpunit": "~3.7",
"symfony/http-kernel": "~2.3",
"nice/framework": "1.0.x-dev"
"phpunit/phpunit": "~10.3",
"symfony/http-kernel": "~6.3",
"nice/framework": "dev-php-and-symfony-update"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/TwigConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class TwigConfiguration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('twig');
$treeBuilder = new TreeBuilder('twig');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
3 changes: 2 additions & 1 deletion src/Extension/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function load(array $config, ContainerBuilder $container)
->addArgument(array('%twig.template_dir%'));

$container->register('twig', 'Twig_Environment')
->addArgument(new Reference('twig.loader'));
->addArgument(new Reference('twig.loader'))
->setPublic(true);

$container->register('templating.engine.twig', 'Nice\Templating\TwigEngine')
->addArgument(new Reference('twig'))
Expand Down
3 changes: 2 additions & 1 deletion src/Twig/AssetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Nice\Twig;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Twig\TwigFunction;

class AssetExtension extends \Twig_Extension
{
Expand All @@ -36,7 +37,7 @@ public function __construct(ContainerInterface $container)
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl'))
new TwigFunction('asset', array($this, 'getAssetUrl'))
);
}

Expand Down
21 changes: 9 additions & 12 deletions src/Twig/RouterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Twig\TwigFunction;

class RouterExtension extends \Twig_Extension
{
Expand Down Expand Up @@ -62,13 +63,13 @@ public function getGlobals()
public function getFunctions()
{
return array(
'current_controller' => new \Twig_Function_Method($this, 'getController'),
'current_action' => new \Twig_Function_Method($this, 'getAction'),
'current_route' => new \Twig_Function_Method($this, 'getRoute'),
'is_current_controller' => new \Twig_Function_Method($this, 'isCurrentController'),
'is_current_route' => new \Twig_Function_Method($this, 'isCurrentRoute'),
'path' => new \Twig_Function_Method($this, 'generatePath'),
'url' => new \Twig_Function_Method($this, 'generateUrl')
new TwigFunction('current_controller', [$this, 'getController']),
new TwigFunction('current_action', [$this, 'getAction']),
new TwigFunction('current_route', [$this, 'getRoute']),
new TwigFunction('is_current_controller', [$this, 'isCurrentController']),
new TwigFunction('is_current_route', [$this, 'isCurrentRoute']),
new TwigFunction('path', [$this, 'generatePath']),
new TwigFunction('url', [$this, 'generateUrl'])
);
}

Expand Down Expand Up @@ -173,11 +174,7 @@ public function generateUrl($name, array $parameters = array())
protected function getCurrentRequest()
{
if (!$this->request) {
if ($this->container->isScopeActive('request')) {
$this->request = $this->container->get('request');
} else {
throw new \RuntimeException('Unable to get "request" service');
}
$this->request = $this->container->get('request');
}

return $this->request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
namespace Nice\Tests\Extension;

use Nice\DependencyInjection\Compiler\RegisterTwigExtensionsPass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class RegisterTwigExtensionsPassTest extends \PHPUnit_Framework_TestCase
class RegisterTwigExtensionsPassTest extends TestCase
{
/**
* Test the RegisterTwigExtensionsPass
Expand Down Expand Up @@ -43,7 +44,11 @@ public function testProcess()
*/
public function testSilentFailWhenTwigServiceDoesntExist()
{
$container = new ContainerBuilder();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
->onlyMethods(['getDefinition'])
->getMock();

$container->expects($this->never())->method('getDefinition')->with(['twig']);

$container->register('fake.extension', 'FakeExtension')
->addTag('twig.extension');
Expand Down
3 changes: 2 additions & 1 deletion tests/Extension/TwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
namespace Nice\Tests\Extension;

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

class TwigExtensionTest extends \PHPUnit_Framework_TestCase
class TwigExtensionTest extends TestCase
{
/**
* Test the TwigExtension
Expand Down
3 changes: 2 additions & 1 deletion tests/Twig/AssetExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
namespace Nice\Tests\Twig;

use Nice\Twig\AssetExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;

class AssetExtensionTest extends \PHPUnit_Framework_TestCase
class AssetExtensionTest extends TestCase
{
/**
* Test a simple example
Expand Down
18 changes: 2 additions & 16 deletions tests/Twig/RouterExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
namespace Nice\Tests\Twig;

use Nice\Twig\RouterExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\HttpFoundation\Request;

class RouterExtensionTest extends \PHPUnit_Framework_TestCase
class RouterExtensionTest extends TestCase
{
/**
* Tests getCurrentController
Expand Down Expand Up @@ -138,19 +139,6 @@ public function testBasicMethods()
$this->assertEquals('router', $extension->getName());
}

/**
* Tests that an exception is thrown when the request service is unavailable
*/
public function testCannotGetRequest()
{
$container = new Container();
$extension = new RouterExtension($container);

$this->setExpectedException('RuntimeException', 'Unable to get "request" service');

$extension->getController();
}

/**
* @param string $uri The URI to give to the request
*
Expand All @@ -164,8 +152,6 @@ public function getExtension($uri = '/', $controller = 'HomeController::indexAct
$container = $container ?: new Container();
$container->set('request', $request);
$container->set('app', new \stdClass());
$container->addScope(new Scope('request'));
$container->enterScope('request');

return new RouterExtension($container);
}
Expand Down