-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from HerveEmagma/master
Fix custom routing
- Loading branch information
Showing
3 changed files
with
128 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Bolt\Extension\Bolt\Sitemap\Controller; | ||
|
||
use Silex\Application; | ||
use Silex\ControllerCollection; | ||
use Silex\ControllerProviderInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* The controller for Sitemap routes. | ||
* | ||
*/ | ||
|
||
class Sitemap implements ControllerProviderInterface | ||
{ | ||
/** @var Application */ | ||
protected $app; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function connect(Application $app) | ||
{ | ||
$this->app = $app; | ||
|
||
/** @var ControllerCollection $ctr */ | ||
$ctr = $app['controllers_factory']; | ||
|
||
// This matches both GET requests. | ||
$ctr->match('sitemap', [$this, 'sitemap']) | ||
->method('GET'); | ||
|
||
$ctr->match('sitemap.xml', [$this, 'sitemapXml']) | ||
->method('GET'); | ||
|
||
return $ctr; | ||
} | ||
|
||
/** | ||
* @param Application $app | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function sitemap(Application $app, Request $request) | ||
{ | ||
$config = $app['sitemap.config']; | ||
|
||
$body = $app["twig"]->render($config['template'], ['entries' => $app['sitemap.links']]); | ||
|
||
return new Response($body, Response::HTTP_OK); | ||
} | ||
|
||
/** | ||
* @param Application $app | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function sitemapXml(Application $app, Request $request) | ||
{ | ||
$config = $app['sitemap.config']; | ||
|
||
$body = $app["twig"]->render($config['xml_template'], ['entries' => $app['sitemap.links']]); | ||
|
||
$response = new Response($body, Response::HTTP_OK); | ||
$response->headers->set('Content-Type', 'application/xml; charset=utf-8'); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters