Skip to content

Commit

Permalink
Deprecate the Silex 1 integration from the library
Browse files Browse the repository at this point in the history
The Silex integration is now available in a separate package, which will
allow to have a separate versioning of the integration. This will simplify
the migration to Silex 2 (this can be a version 2 of the package, with an
updated dependency).
  • Loading branch information
stof committed Aug 22, 2017
1 parent f49faca commit 64c2a4c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ matrix:
dist: precise

before_install:
# Test the legacy Silex integration on the PHP 5.5 job. It is not tested on all jobs as it prevents testing with Symfony 3
- if [ "$TRAVIS_PHP_VERSION" = "5.5" ]; then composer require --no-update --dev silex/silex "^1.0"; fi;
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
# force the PHPUnit version for PHP 7.2, until https://github.com/symfony/symfony/issues/23943 is resolved
- if [ "$TRAVIS_PHP_VERSION" = "nightly" ]; then export SYMFONY_PHPUNIT_VERSION="6.3"; fi;
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3 (unreleased)

* Deprecated the Silex 1 KnpMenuServiceProvider. Use the `knplabs/knp-menu-silex` package instead.

## 2.2 (2016-09-22)

* Added a new function to twig: `knp_menu_get_current_item`
Expand Down
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@
"php": ">=5.3.0"
},
"require-dev": {
"pimple/pimple": "~1.0",
"symfony/http-foundation": "~2.4|~3.0",
"symfony/http-kernel": "~2.4|~3.0",
"symfony/phpunit-bridge": "~3.3",
"symfony/routing": "~2.3|~3.0",
"silex/silex": "~1.0",
"twig/twig": "~1.16|~2.0"
},
"suggest": {
"pimple/pimple": "for the built-in implementations of the menu provider and renderer provider",
"silex/silex": "for the integration with your silex application",
"twig/twig": "for the TwigRenderer and the integration with your templates"
},
"autoload": {
Expand All @@ -46,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
"dev-master": "2.3-dev"
}
}
}
78 changes: 2 additions & 76 deletions doc/03-Silex-Integration.markdown
Original file line number Diff line number Diff line change
@@ -1,79 +1,5 @@
Silex 1 Integration
===================

KnpMenu provides an extension for the [Silex](http://silex-project.org/)
microframework version 1. **This extension is not compatible with Silex 2.**
If you use Silex version 2, please do a pull request to provide the necessary
integration.

RouterAwareFactory
------------------

The `Knp\Menu\Silex\RouterAwareFactory` extends the default factory to add
the support of the url generator of the Symfony2 Routing component. You can
then pass 3 new options to the factory:

* `route`: The route name (the generator will be used if the name is not `null`)
* `routeParameters`: The parameters to generate the url (if omitted, an empty array is used)
* `routeAbsolute`: Whether the generated url should be absolute (default `false`)

>**NOTE**
>When you give both a route and an uri to the factory, the route will be used.
Using the KnpMenuExtension
--------------------------

### Registering the extension

```php
<?php

// registering the autoloader for the library.
$app['autoloader']->registerNamespace('Knp\Menu', __DIR__.'/vendor/KnpMenu/src');

// registering the extension
$app->register(new \Knp\Menu\Integration\Silex\KnpMenuServiceProvider());
```

>**WARNING**
>The Twig integration is available only when the KnpMenuServiceProvider is registered
>**after** the TwigServiceProvider in your application.
#### Parameters

* **knp_menu.menus** (optional): an array of ``alias => id`` pair for the
[menu provider](02-Twig-Integration.markdown#menu-provider).
* **knp_menu.renderers** (optional): an array of ``alias => id`` pair for
the [renderer provider](02-Twig-Integration.markdown#renderer-provider).
* **knp_menu.default_renderer** (optional): the alias of the default renderer (default to `'list'`)
* **knp_menu.template** (optional): The template used by default by the TwigRenderer.

#### Services

* **knp_menu.factory**: The menu factory (it is a router-aware one if the
UrlGeneratorExtension is registered)
* **knp_menu.renderer.list**: The ListRenderer
* **knp_menu.renderer.twig**: The TwigRenderer (only when the Twig integration is available)

### Adding your menu to the menu provider

Making your menu available through the menu provider is really easy. Simply
create the menu as a service in the application and register it in the parameter:

```php
<?php

$app['my_main_menu'] = function($app) {
$menu = $app['knp_menu.factory']->createItem('root');

$menu->addChild('Home', array('route' => 'homepage'));
// ... add more children

return $menu;
};

$app['knp_menu.menus'] = array('main' => 'my_main_menu');
```

Your menu is now available in the [menu provider](02-Twig-Integration.markdown#menu-provider)
with the name `main`.
The Silex service provider provided in KnpMenu itself is deprecated as of KnpMenu 2.3.
Use [`knplabs/knp-menu-silex`](https://packagist.org/packages/knplabs/knp-menu-silex) instead.
2 changes: 2 additions & 0 deletions src/Knp/Menu/Integration/Silex/KnpMenuServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Knp\Menu\Integration\Silex;

@trigger_error('The '.__NAMESPACE__.'\KnpMenuServiceProvider class is deprecated since version 2.3 and will be removed in 3.0. Use the provider available in the "knplabs/knp-menu-silex" package instead.', E_USER_DEPRECATED);

use Knp\Menu\Integration\Symfony\RoutingExtension;
use Silex\Application;
use Silex\ServiceProviderInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Silex\Provider\UrlGeneratorServiceProvider;
use Symfony\Component\HttpFoundation\Request;

/**
* @group legacy
*/
class KnpMenuServiceProviderTest extends TestCase
{
protected function setUp()
Expand Down

0 comments on commit 64c2a4c

Please sign in to comment.