From b19316554447b5b54723e5ae58a6d141378f4b1d Mon Sep 17 00:00:00 2001 From: Alex Debril Date: Thu, 27 Jul 2017 17:08:26 +0200 Subject: [PATCH] Installation instructions for sf 3.3 --- Controller/StreamController.php | 9 +++++---- README.md | 22 ++++++++++++++++------ Resources/config/routing.yml | 2 +- Tests/Controller/StreamControllerTest.php | 4 ++++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Controller/StreamController.php b/Controller/StreamController.php index 47d1e23..0fd1e41 100644 --- a/Controller/StreamController.php +++ b/Controller/StreamController.php @@ -93,8 +93,7 @@ protected function createStreamResponse(array $options, $format, $source = self: if ($this->mustForceRefresh() || $content->getLastModified() > $this->getModifiedSince()) { $response = new Response($this->getFeedIo()->format($content, $format)); - $response->headers->set('Content-Type', 'application/xhtml+xml'); - $this->setFeedHeaders($response, $content); + $this->setFeedHeaders($response, $content, $format); } else { $response = new Response(); @@ -107,11 +106,13 @@ protected function createStreamResponse(array $options, $format, $source = self: /** * @param Response $response * @param FeedInterface $feed + * @param string $format * @return $this */ - protected function setFeedHeaders(Response $response, FeedInterface $feed) + protected function setFeedHeaders(Response $response, FeedInterface $feed, $format) { - $response->headers->set('Content-Type', 'application/xhtml+xml'); + $contentType = 'json' == $format ? 'application/json':'application/xhtml+xml'; + $response->headers->set('Content-Type', $contentType); if (! $this->isPrivate() ) { $response->setPublic(); } diff --git a/README.md b/README.md index bc94d6c..dead6bb 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,24 @@ You can try rss-atom-bundle through its [Demo](https://rss-atom-demo.herokuapp.c As a Symfony Bundle, RssAtomBundle must be installed using Composer. If you do not know Composer, please refer to its website: http://getcomposer.org/ -### Installation in a Symfony project +### Your application uses Symfony 3.3 or later -This is the most common way if you want to add RssAtomBundle into an existing project. +Activate Symfony's [contrib recipes](https://github.com/symfony/recipes-contrib) and use Composer to require the bundle : - composer require debril/rss-atom-bundle +```shell +composer config extra.symfony.allow-contrib true +composer require debril/rss-atom-bundle +``` + +That's it. To check the installation, you can start your application and hit http://localhost:8000/rss in your browser. You should see a mock RSS stream. + +### If your application uses Symfony < 3.3 + +Install the bundle using Composer : + +```shell +composer require debril/rss-atom-bundle +``` Add the bundle's routing configuration in app/config/routing.yml : @@ -43,7 +56,6 @@ rssatom: resource: "@DebrilRssAtomBundle/Resources/config/routing.yml" ``` -#### If your application uses Symfony < 3.3 Edit your app/AppKernel.php to register the bundle in the registerBundles() method as above: @@ -61,8 +73,6 @@ class AppKernel extends Kernel new Debril\RssAtomBundle\DebrilRssAtomBundle(), ``` -This step will not be necessary anymore starting from Symfony 3.3. - ## Usage rss-atom-bundle is designed to read feeds across the internet and to publish your own using [feed-io](https://github.com/alexdebril/feed-io) diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 42338b6..e1f3357 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -12,7 +12,7 @@ feed_atom: defaults: { _controller: DebrilRssAtomBundle:Stream:index, "format": 'atom', "id": null } feed_json: - path: /atom/{id} + path: /json/{id} defaults: { _controller: DebrilRssAtomBundle:Stream:index, "format": 'json', "id": null } feed_mock: diff --git a/Tests/Controller/StreamControllerTest.php b/Tests/Controller/StreamControllerTest.php index fb022bb..8b4986f 100644 --- a/Tests/Controller/StreamControllerTest.php +++ b/Tests/Controller/StreamControllerTest.php @@ -50,6 +50,7 @@ public function testGetAtom() $response = $client->getResponse(); $this->assertEquals('200', $response->getStatusCode()); + $this->assertEquals('application/xhtml+xml', $response->headers->get('content-type')); $atom = new Document($response->getContent()); @@ -65,6 +66,7 @@ public function testGetRss() $response = $client->getResponse(); $this->assertEquals('200', $response->getStatusCode()); + $this->assertEquals('application/xhtml+xml', $response->headers->get('content-type')); $rss = new Document($response->getContent()); @@ -79,7 +81,9 @@ public function testGetJson() $client->request('GET', '/json/1'); $response = $client->getResponse(); + $this->assertEquals('200', $response->getStatusCode()); + $this->assertEquals('application/json', $response->headers->get('content-type')); $json = new Document($response->getContent());