# Integrate both juliangut/slim-routing and php-di/slim-bridge

**URL:** <https://discourse.slimframework.com/t/integrate-both-juliangut-slim-routing-and-php-di-slim-bridge/6049>\
**Category:** Questions\
**Created:** [February 16, 2025, 2:20pm UTC](https://discourse.slimframework.com/t/integrate-both-juliangut-slim-routing-and-php-di-slim-bridge/6049 "2025-02-16T14:20:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![azurams](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/azurams/32/1670_2.png) [@azurams](https://discourse.slimframework.com/u/azurams)\
**Post date:** [February 16, 2025, 2:20pm UTC](https://discourse.slimframework.com/t/integrate-both-juliangut-slim-routing-and-php-di-slim-bridge/6049/1 "2025-02-16T14:20:16Z")

</div>

In my application I already use php-di/slim-bridge, where the app is created with  
`$app = \DI\Bridge\Slim\Bridge::create($container);`

I would like to use also `juliangut/slim-routing` library to have php attributes defined routes and other benefits.

However, in the `juliangut/slim-routing` usage section, I see

```auto
$configuration = new Configuration([
    'sources' => ['/path/to/routing/files'],
]);
AppFactory::setRouteCollectorConfiguration($configuration);

// Instantiate the app
$app = AppFactory::create();

```

I don’t get how I can get the two libraries work together if $app is created in different ways.  
Is there any way of achieving the integration of both libraries ?

---

<div class="post-metadata">

**Author:** ![tj\_gumis](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@tj\_gumis](https://discourse.slimframework.com/u/tj_gumis)\
**Post date:** [February 17, 2025, 12:33pm UTC](https://discourse.slimframework.com/t/integrate-both-juliangut-slim-routing-and-php-di-slim-bridge/6049/2 "2025-02-17T12:33:01Z")

</div>

Imagine your container definition:

_definitions.php_

```php
return [
    Configuration::class => static function (ContainerInterface $container) {
        return new Configuration([
            'sources' => ['/path/to/routing/files'],
        ]);
    },
    App::class => static function (ContainerInterface $container) {
        AppFactory::setRouteCollectorConfiguration(
            $container->get(Configuration::class)
        );
        return AppFactory::createFromContainer($container);
    },
];

```

and `$app` instantiation:

_bootstrap.php_

```php
use DI\ContainerBuilder;
use Slim\App;

$builder = new ContainerBuilder();
$builder->useAutowiring(true);
$definitions = require_once 'definitions.php';
$builder->addDefinitions($definitions);
$container = $builder->build();

$app = $container->get(App::class);

```

---

<div class="post-metadata">

**Author:** ![azurams](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/azurams/32/1670_2.png) [@azurams](https://discourse.slimframework.com/u/azurams)\
**Post date:** [February 17, 2025, 3:45pm UTC](https://discourse.slimframework.com/t/integrate-both-juliangut-slim-routing-and-php-di-slim-bridge/6049/3 "2025-02-17T15:45:40Z")

</div>

thank you for opening my mind.  
I achieved to set up what I wanted within the container.

---

<div class="post-metadata">

**Author:** ![LLEGAZ](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llegaz/32/1665_2.png) [@LLEGAZ](https://discourse.slimframework.com/u/LLEGAZ)\
**Post date:** [February 23, 2025, 6:48am UTC](https://discourse.slimframework.com/t/integrate-both-juliangut-slim-routing-and-php-di-slim-bridge/6049/4 "2025-02-23T06:48:24Z")

</div>

Won’t it work just inserting the `RouteCollectorConfiguration` ?

```php
$container = $containerBuilder->build();
$configuration = new Configuration([
    'sources' => ['/path/to/routing/files'],
]);
AppFactory::setRouteCollectorConfiguration($configuration);
AppFactory::setContainer($container);

// Instantiate the app
$app = AppFactory::create();

```

just wondering

---

<div class="post-metadata">

**Author:** ![tj\_gumis](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@tj\_gumis](https://discourse.slimframework.com/u/tj_gumis)\
**Post date:** [February 25, 2025, 7:36pm UTC](https://discourse.slimframework.com/t/integrate-both-juliangut-slim-routing-and-php-di-slim-bridge/6049/5 "2025-02-25T19:36:31Z")

</div>

Sure, but there is something called `separation of concern`. The way you wonder to apply, put together both application bootstrapping and injection definitions at the same code scope.

Look, this is certainly injection definition:

```php
$configuration = new Configuration([
    'sources' => ['/path/to/routing/files'],
]);

```

you will have lots of such definitions to prepare, and I assume you will do it more or less like in my `definitions.php` file example.  
Now you have to answer yourself a question, why `Configuration` object is so special that you decide to instantiate it within `bootstraping` scope and other in `definitions` scope?  
I say there is nothing special in `Configuration object`, and you have to be consistent in your code.

BTW, you can do it optionally this way:

```php
return [
    App::class => static function (ContainerInterface $container) {
        AppFactory::setRouteCollectorConfiguration(
            new Configuration([
                'sources' => ['/path/to/routing/files'],
            ])
        );
        return AppFactory::createFromContainer($container);
    },
];

```

and this is certainly justified and correct in case if `Configuration` object is used exclusively as a parameter of `AppFactory::setRouteCollectorConfiguration` method, meaning no other object will use it. In many cases it is not, that is why my example, for a presentation purpose is more general.

---

<div class="post-metadata">

**Author:** ![LLEGAZ](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llegaz/32/1665_2.png) [@LLEGAZ](https://discourse.slimframework.com/u/LLEGAZ)\
**Post date:** [February 26, 2025, 10:29am UTC](https://discourse.slimframework.com/t/integrate-both-juliangut-slim-routing-and-php-di-slim-bridge/6049/6 "2025-02-26T10:29:25Z")

</div>

Your first example was great. Thank you for your detailed reply.

I was just wondering of a simpler approach maybe because I’m an ol’ man already, and thus adhering fully to the KISS principle.

As you put it in your reply I (personally) won’t take offense of a `Configuration` object whatsoever in a app’s bootstrapping script, especially in term of concerns… but you are right start clean to enable a harmonious evolving is really important for long run and/or big project.
