/** * Flush caches according to the previously registered node changes. * * @return void */ public function commit() { foreach ($this->tagsToFlush as $tag) { $this->routeCachingService->flushCachesByTag($tag); } $this->tagsToFlush = array(); }
/** * @test */ public function storeResolvedUriPathConvertsObjectsImplementingCacheAwareInterfaceToCacheEntryIdentifier() { $mockObject = $this->getMock(\TYPO3\Flow\Cache\CacheAwareInterface::class); $mockObject->expects($this->atLeastOnce())->method('getCacheEntryIdentifier')->will($this->returnValue('objectIdentifier')); $routeValues = array('b' => 'route values', 'someObject' => $mockObject); $cacheIdentifier = '264b593d59582adea4ccc52b33cc093f'; $matchingUriPath = 'uncached/matching/uri'; $this->mockResolveCache->expects($this->once())->method('set')->with($cacheIdentifier, $matchingUriPath); $this->routerCachingService->storeResolvedUriPath($matchingUriPath, $routeValues); }
/** * @test */ public function routeStoresMatchResultsInCacheIfNotFoundInCache() { $router = $this->getAccessibleRouterMock(['createRoutesFromConfiguration']); $matchResults = ['some' => 'match results']; $mockHttpRequest = $this->getMockBuilder(\TYPO3\Flow\Http\Request::class)->disableOriginalConstructor()->getMock(); $mockRoute1 = $this->getMockBuilder(\TYPO3\Flow\Mvc\Routing\Route::class)->getMock(); $mockRoute1->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(false)); $mockRoute2 = $this->getMockBuilder(\TYPO3\Flow\Mvc\Routing\Route::class)->getMock(); $mockRoute2->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(true)); $mockRoute2->expects($this->once())->method('getMatchResults')->will($this->returnValue($matchResults)); $router->_set('routes', [$mockRoute1, $mockRoute2]); $this->mockRouterCachingService->expects($this->once())->method('storeMatchResults')->with($mockHttpRequest, $matchResults); $this->assertSame($matchResults, $router->route($mockHttpRequest)); }
/** * @test */ public function routeStoresMatchResultsInCacheIfNotFoundInCache() { $router = $this->getAccessibleMock('TYPO3\\Flow\\Mvc\\Routing\\Router', array('createRoutesFromConfiguration')); $this->inject($router, 'routerCachingService', $this->mockRouterCachingService); $this->inject($router, 'systemLogger', $this->mockSystemLogger); $matchResults = array('some' => 'match results'); $mockHttpRequest = $this->getMockBuilder('TYPO3\\Flow\\Http\\Request')->disableOriginalConstructor()->getMock(); $mockRoute1 = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Routing\\Route')->getMock(); $mockRoute1->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(FALSE)); $mockRoute2 = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Routing\\Route')->getMock(); $mockRoute2->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(TRUE)); $mockRoute2->expects($this->once())->method('getMatchResults')->will($this->returnValue($matchResults)); $router->_set('routes', array($mockRoute1, $mockRoute2)); $this->mockRouterCachingService->expects($this->once())->method('storeMatchResults')->with($mockHttpRequest, $matchResults); $this->assertSame($matchResults, $router->route($mockHttpRequest)); }
/** * @test */ public function routeStoresMatchResultsInCacheIfNotFoundInCache() { $matchResults = array('some' => 'match results'); $mockActionRequest = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\ActionRequest')->disableOriginalConstructor()->getMock(); $mockActionRequest->expects($this->once())->method('getArguments')->will($this->returnValue(array())); $mockHttpRequest = $this->getMockBuilder('TYPO3\\Flow\\Http\\Request')->disableOriginalConstructor()->getMock(); $mockHttpRequest->expects($this->once())->method('createActionRequest')->will($this->returnValue($mockActionRequest)); $mockRoute1 = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Routing\\Route')->getMock(); $mockRoute1->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(FALSE)); $mockRoute2 = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Routing\\Route')->getMock(); $mockRoute2->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(TRUE)); $mockRoute2->expects($this->once())->method('getMatchResults')->will($this->returnValue($matchResults)); $this->router->_set('routes', array($mockRoute1, $mockRoute2)); $this->mockRouterCachingService->expects($this->once())->method('storeMatchResults')->with($mockHttpRequest, $matchResults); $this->assertSame($mockActionRequest, $this->router->route($mockHttpRequest)); }
/** * Builds the corresponding uri (excluding protocol and host) by iterating * through all configured routes and calling their respective resolves() * method. If no matching route is found, an empty string is returned. * Note: calls of this message are cached by RouterCachingAspect * * @param array $routeValues Key/value pairs to be resolved. E.g. array('@package' => 'MyPackage', '@controller' => 'MyController'); * @return string * @throws NoMatchingRouteException */ public function resolve(array $routeValues) { $cachedResolvedUriPath = $this->routerCachingService->getCachedResolvedUriPath($routeValues); if ($cachedResolvedUriPath !== FALSE) { return $cachedResolvedUriPath; } $this->lastResolvedRoute = NULL; $this->createRoutesFromConfiguration(); /** @var $route Route */ foreach ($this->routes as $route) { if ($route->resolves($routeValues)) { $this->lastResolvedRoute = $route; $resolvedUriPath = $route->getResolvedUriPath(); if ($resolvedUriPath !== NULL) { $this->routerCachingService->storeResolvedUriPath($resolvedUriPath, $routeValues); } return $resolvedUriPath; } } $this->systemLogger->log('Router resolve(): Could not resolve a route for building an URI for the given route values.', LOG_WARNING, $routeValues); throw new NoMatchingRouteException('Could not resolve a route and its corresponding URI for the given parameters. This may be due to referring to a not existing package / controller / action while building a link or URI. Refer to log and check the backtrace for more details.', 1301610453); }