title: How to access slim4's routeParser with the PHP-DI setup demonstrated in Slim-Skeleton?
body: <p>I've set up a new app based on the SlimPHP team's <a href="https://github.com/slimphp/Slim-Skeleton" rel="nofollow noreferrer">Slim Skeleton</a> application. Inside of my route definitions, I want to be able to access the route parser as <a href="http://www.slimframework.com/docs/v4/objects/routing.html#route-names" rel="nofollow noreferrer">described in the Slim4 documentation</a>. So, for example, I'd like to be able to edit the skeleton's <a href="https://github.com/slimphp/Slim-Skeleton/blob/master/app/routes.php" rel="nofollow noreferrer">app/routes.php</a> file something like this:</p>
  
  <pre><code>    $app-&gt;get('/', function (Request $request, Response $response) {
          $routeParser = $app-&gt;getRouteCollector()-&gt;getRouteParser();  // this doesn't work
          $response-&gt;getBody()-&gt;write('Hello world! ' . $routeParser-&gt;urlFor('something'));
          return $response;
      });
  </code></pre>
  
  <p>It makes sense that <code>$app-&gt;getRouteCollector()-&gt;getRouteParser()</code> doesn't work, because <code>$app</code> isn't defined here. But I would think that we'd instead call <code>$this-&gt;getRouteCollector()-&gt;getRouteParser();</code>, but that gives the error: <code>"Call to undefined method DI\\Container::getRouteCollector()"</code>. </p>
  
  <p>It definitely seems that my confusion is about Dependency Injection, which is new for me and not coming naturally to me. I'd honestly love to define the $routeParser variable somewhere else (inside index.php?) so that I could access it in any route definition without having to call $app->getRouteCollector()->getRouteParser() every time. But at the moment I'd settle for anything that worked. </p>