Skip to content

Commit

Permalink
fixed code as url_generator is now always available
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 29, 2015
1 parent 2179d54 commit 53f39cf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions doc/services.rst
Expand Up @@ -245,15 +245,15 @@ Core parameters

Defaults to 80.

This parameter can be used by the ``UrlGeneratorProvider``.
This parameter can be used when generating URLs.

* **request.https_port** (optional): Allows you to override the default port
for HTTPS URLs. If the current request is HTTPS, it will always use the
current port.

Defaults to 443.

This parameter can be used by the ``UrlGeneratorProvider``.
This parameter can be used when generating URLs.

* **debug** (optional): Returns whether or not the application is running in
debug mode.
Expand Down
8 changes: 4 additions & 4 deletions doc/usage.rst
Expand Up @@ -389,9 +389,9 @@ have the value ``index``.
Named Routes
~~~~~~~~~~~~

Some providers (such as ``UrlGeneratorProvider``) can make use of named routes.
By default Silex will generate an internal route name for you but you can give
an explicit route name by calling ``bind``::
Some providers can make use of named routes. By default Silex will generate an
internal route name for you but you can give an explicit route name by calling
``bind``::

$app->get('/', function () {
// ...
Expand Down Expand Up @@ -625,7 +625,7 @@ round-trip to the browser (as for a redirect), use an internal sub-request::

.. tip::

If you are using ``UrlGeneratorProvider``, you can also generate the URI::
You can also generate the URI via the built-in URL generator::

$request = Request::create($app['url_generator']->generate('hello'), 'GET');

Expand Down
2 changes: 1 addition & 1 deletion src/Silex/Provider/SecurityServiceProvider.php
Expand Up @@ -335,7 +335,7 @@ public function register(Container $app)
};

$app['security.http_utils'] = function ($app) {
return new HttpUtils(isset($app['url_generator']) ? $app['url_generator'] : null, $app['request_matcher']);
return new HttpUtils($app['url_generator'], $app['request_matcher']);
};

$app['security.last_error'] = $app->protect(function (Request $request) {
Expand Down
5 changes: 1 addition & 4 deletions src/Silex/Provider/TwigServiceProvider.php
Expand Up @@ -67,10 +67,7 @@ public function register(Container $app)

if (class_exists('Symfony\Bridge\Twig\Extension\RoutingExtension')) {
$twig->addExtension(new HttpFoundationExtension($app['request_stack']));

if (isset($app['url_generator'])) {
$twig->addExtension(new RoutingExtension($app['url_generator']));
}
$twig->addExtension(new RoutingExtension($app['url_generator']));

if (isset($app['translator'])) {
$twig->addExtension(new TranslationExtension($app['translator']));
Expand Down
8 changes: 4 additions & 4 deletions tests/Silex/Tests/Application/UrlGeneratorTraitTest.php
Expand Up @@ -21,16 +21,16 @@ class UrlGeneratorTraitTest extends \PHPUnit_Framework_TestCase
public function testUrl()
{
$app = new UrlGeneratorApplication();
$app['url_generator'] = $translator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->disableOriginalConstructor()->getMock();
$translator->expects($this->once())->method('generate')->with('foo', array(), true);
$app['url_generator'] = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->disableOriginalConstructor()->getMock();
$app['url_generator']->expects($this->once())->method('generate')->with('foo', array(), true);
$app->url('foo');
}

public function testPath()
{
$app = new UrlGeneratorApplication();
$app['url_generator'] = $translator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->disableOriginalConstructor()->getMock();
$translator->expects($this->once())->method('generate')->with('foo', array(), false);
$app['url_generator'] = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->disableOriginalConstructor()->getMock();
$app['url_generator']->expects($this->once())->method('generate')->with('foo', array(), false);
$app->path('foo');
}
}

0 comments on commit 53f39cf

Please sign in to comment.