-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from skroczek/dependencies-update
Dependencies update
- Loading branch information
Showing
6 changed files
with
194 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2016 Sebastian Kroczek <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace JMS\ObjectRouting\Symfony; | ||
|
||
use JMS\ObjectRouting\RouterInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
/** | ||
* Class Symfony22Adapter | ||
* @package JMS\ObjectRouting\Symfony | ||
* @author Sebastian Kroczek <[email protected]> | ||
*/ | ||
class Symfony22Adapter implements RouterInterface | ||
{ | ||
private $delegate; | ||
|
||
public function __construct(\Symfony\Component\Routing\RouterInterface $router) | ||
{ | ||
$this->delegate = $router; | ||
} | ||
|
||
public function generate($name, array $params, $absolute = false) | ||
{ | ||
return $this->delegate->generate($name, $params, $absolute ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2016 Sebastian Kroczek <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace JMS\ObjectRouting\Twig; | ||
|
||
use JMS\ObjectRouting\ObjectRouter; | ||
|
||
/** | ||
* Class Routing20Extension | ||
* @package JMS\ObjectRouting\Twig | ||
* @author Sebastian Kroczek <[email protected]> | ||
*/ | ||
class Routing20Extension extends \Twig_Extension | ||
{ | ||
private $router; | ||
|
||
public function __construct(ObjectRouter $router) | ||
{ | ||
$this->router = $router; | ||
} | ||
|
||
public function getFunctions() | ||
{ | ||
return array( | ||
new \Twig_SimpleFunction('object_path', array($this, 'path')), | ||
new \Twig_SimpleFunction('object_url', array($this, 'url')), | ||
); | ||
} | ||
|
||
public function url($type, $object, array $extraParams = array()) | ||
{ | ||
return $this->router->generate($type, $object, true, $extraParams); | ||
} | ||
|
||
public function path($type, $object, array $extraParams = array()) | ||
{ | ||
return $this->router->generate($type, $object, false, $extraParams); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'jms.object_routing'; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace JMS\Tests\ObjectRouting\Symfony; | ||
|
||
use JMS\ObjectRouting\Symfony\Symfony22Adapter; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
class Symfony22AdapterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var Symfony22Adapter */ | ||
private $adapter; | ||
private $router; | ||
|
||
public function testGenerate() | ||
{ | ||
$this->router->expects($this->once()) | ||
->method('generate') | ||
->with('foo', array('bar' => 'baz'), UrlGeneratorInterface::ABSOLUTE_URL) | ||
->will($this->returnValue('/foo-bar-baz')); | ||
|
||
$this->assertEquals('/foo-bar-baz', $this->adapter->generate('foo', array('bar' => 'baz'), true)); | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
$this->adapter = new Symfony22Adapter( | ||
$this->router = $this->getMock('Symfony\Component\Routing\RouterInterface') | ||
); | ||
} | ||
} |