title: Slim 3 get current route in middleware
body: <p>I want to get the name of the current I route in a middleware class. Previously (in Slim 2.*) you could fetch the current route like so:</p>
  
  <p><code>
  $route = $this-&gt;app-&gt;router-&gt;getCurrentRoute();
  </code></p>
  
  <p>But this function has been removed in the 3.0 version of Slim. I've found the following code in the <code>__invoke</code> method of <code>Slim\App</code>:</p>
  
  <pre><code>    // Get the route info
      $routeInfo = $request-&gt;getAttribute('routeInfo');
  
      /** @var \Slim\Interfaces\RouterInterface $router */
      $router = $this-&gt;container-&gt;get('router');
  
      // If router hasn't been dispatched or the URI changed then dispatch
      if (null === $routeInfo || ($routeInfo['request'] !== [$request-&gt;getMethod(), (string) $request-&gt;getUri()])) {
          $request = $this-&gt;dispatchRouterAndPrepareRoute($request, $router);
          $routeInfo = $request-&gt;getAttribute('routeInfo');
      }
  </code></pre>
  
  <p>This indicates that the current route is stored as the attribute <code>routeInfo</code> in the <code>Request</code>. But it seems that my custom middleware class is called before the attribute is set (by the <code>$this-&gt;dispatchRouterAndPrepareRoute($request, $router);</code> method). Because calling <code>$request-&gt;getAttribute('routeInfo')</code> resolves to <code>NULL</code>.</p>
  
  <p>So my question is; how can I get the current route (or the name of the route) from a middleware function/class?</p>
  
  <p>Or should I just copy the piece of code above from <code>Slim\App</code>?</p>