Skip to content

Commit f2b11cf

Browse files
authored
Merge pull request #123 from alexdebril/release/3.0
Release/3.0
2 parents b4e1424 + 07def16 commit f2b11cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+121
-5953
lines changed

Controller/StreamController.php

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Debril\RssAtomBundle\Controller;
44

5-
use Debril\RssAtomBundle\Protocol\FeedFormatter;
6-
use Debril\RssAtomBundle\Protocol\FeedOutInterface;
7-
use FeedIo\Feed;
5+
use FeedIo\FeedInterface;
86
use Symfony\Component\HttpFoundation\Response;
97
use Symfony\Component\HttpFoundation\Request;
108
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
@@ -100,15 +98,10 @@ protected function createStreamResponse(array $options, $format, $source = self:
10098
$content = $this->getContent($options, $source);
10199

102100
if ($this->mustForceRefresh() || $content->getLastModified() > $this->getModifiedSince()) {
103-
$response = new Response($this->getStringOutput($content, $format));
101+
$response = new Response($this->getFeedIo()->format($content, $format)->saveXML());
104102
$response->headers->set('Content-Type', 'application/xhtml+xml');
103+
$this->setFeedHeaders($response, $content);
105104

106-
if (! $this->container->getParameter('debril_rss_atom.private_feeds')) {
107-
$response->setPublic();
108-
}
109-
110-
$response->setMaxAge(3600);
111-
$response->setLastModified($content->getLastModified());
112105
} else {
113106
$response = new Response();
114107
$response->setNotModified();
@@ -118,19 +111,21 @@ protected function createStreamResponse(array $options, $format, $source = self:
118111
}
119112

120113
/**
121-
* @param $feed
122-
* @param $format
123-
* @return string
124-
* @throws \Exception
114+
* @param Response $response
115+
* @param FeedInterface $feed
116+
* @return $this
125117
*/
126-
protected function getStringOutput($feed, $format)
118+
protected function setFeedHeaders(Response $response, FeedInterface $feed)
127119
{
128-
if ( $feed instanceof Feed ) {
129-
return $this->getFeedIo()->format($feed, $format)->saveXML();
120+
$response->headers->set('Content-Type', 'application/xhtml+xml');
121+
if (! $this->isPrivate() ) {
122+
$response->setPublic();
130123
}
131124

132-
$formatter = $this->getFormatter($format);
133-
return $formatter->toString($feed);
125+
$response->setMaxAge(3600);
126+
$response->setLastModified($feed->getLastModified());
127+
128+
return $this;
134129
}
135130

136131
/**
@@ -141,7 +136,7 @@ protected function getStringOutput($feed, $format)
141136
* @param array $options
142137
* @param string $source
143138
*
144-
* @return FeedOutInterface
139+
* @return FeedInterface
145140
*
146141
* @throws \Exception
147142
*/
@@ -175,26 +170,11 @@ protected function mustForceRefresh()
175170
}
176171

177172
/**
178-
* Get the accurate formatter.
179-
*
180-
* @param string $format
181-
*
182-
* @throws \Exception
183-
*
184-
* @return FeedFormatter
173+
* @return boolean true if the feed must be private
185174
*/
186-
protected function getFormatter($format)
175+
protected function isPrivate()
187176
{
188-
$services = array(
189-
'rss' => 'debril.formatter.rss',
190-
'atom' => 'debril.formatter.atom',
191-
);
192-
193-
if (!array_key_exists($format, $services)) {
194-
throw new \Exception("Unsupported format {$format}");
195-
}
196-
197-
return $this->get($services[$format]);
177+
return $this->container->getParameter('debril_rss_atom.private_feeds');
198178
}
199179

200180
/**
@@ -204,4 +184,5 @@ protected function getFeedIo()
204184
{
205185
return $this->container->get('feedio');
206186
}
187+
207188
}

DebrilRssAtomBundle.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
namespace Debril\RssAtomBundle;
44

5-
use Debril\RssAtomBundle\DependencyInjection\CompilerPass\DriverCompilerPass;
65
use Symfony\Component\HttpKernel\Bundle\Bundle;
7-
use Symfony\Component\DependencyInjection\ContainerBuilder;
86

97
class DebrilRssAtomBundle extends Bundle
108
{
11-
public function build(ContainerBuilder $container)
12-
{
13-
parent::build($container);
149

15-
$container->addCompilerPass(new DriverCompilerPass());
16-
}
1710
}

DependencyInjection/CompilerPass/DriverCompilerPass.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

DependencyInjection/Configuration.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,6 @@ public function getConfigTreeBuilder()
2828
->arrayNode('date_formats')
2929
->prototype('scalar')->end()
3030
->end()
31-
->enumNode('driver')
32-
->info('Driver to use to fetch RSS feed. Valid values are "curl" (default), "file", "guzzle", "service".')
33-
->values(array('curl', 'file', 'guzzle', 'service'))
34-
->defaultValue('curl')
35-
->end()
36-
->scalarNode('driver_service')
37-
->info('If driver is set to "csa-guzzle" or "service", the ID of the service to use')
38-
->end()
39-
->arrayNode('curlopt')
40-
->info('Parameters for curl requests')
41-
->children()
42-
->scalarNode('timeout')
43-
->info('Timeout in seconds for curl requests')
44-
->end()
45-
->scalarNode('useragent')
46-
->info('User agent for curl requests')
47-
->end()
48-
->scalarNode('maxredirs')
49-
->info('Maximum redirects for curl requests')
50-
->end()
51-
->end()
52-
->end()
5331
->end()
5432
;
5533

DependencyInjection/DebrilRssAtomExtension.php

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@
1515
*/
1616
class DebrilRssAtomExtension extends Extension
1717
{
18+
19+
/**
20+
* @var array
21+
*/
22+
protected $defaultDateFormats = [
23+
\DateTime::RFC3339,
24+
\DateTime::RSS,
25+
\DateTime::W3C,
26+
'Y-m-d\TH:i:s.uP',
27+
'Y-m-d',
28+
'd/m/Y',
29+
'd M Y H:i:s P',
30+
'D, d M Y H:i O',
31+
'D, d M Y H:i:s O',
32+
'D M d Y H:i:s e',
33+
];
34+
1835
/**
1936
* {@inheritDoc}
2037
*/
@@ -25,40 +42,10 @@ public function load(array $configs, ContainerBuilder $container)
2542

2643
$this->setDefinition($container, 'logger', 'Psr\Log\NullLogger');
2744

28-
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
29-
$loader->load('services.xml');
30-
31-
$default = array(
32-
\DateTime::RFC3339,
33-
\DateTime::RSS,
34-
\DateTime::W3C,
35-
'Y-m-d\TH:i:s.uP',
36-
'Y-m-d',
37-
'd/m/Y',
38-
'd M Y H:i:s P',
39-
'D, d M Y H:i O',
40-
'D, d M Y H:i:s O',
41-
'D M d Y H:i:s e',
42-
);
43-
44-
if (!isset($config['date_formats'])) {
45-
$container->setParameter(
46-
'debril_rss_atom.date_formats',
47-
$default
48-
);
49-
} else {
50-
$container->setParameter(
51-
'debril_rss_atom.date_formats',
52-
array_merge($default, $config['date_formats'])
53-
);
54-
}
55-
56-
if ( !isset($config['curlopt']) ) {
57-
$container->setParameter('debril_rss_atom.curlopt', array());
58-
} else {
59-
$container->setParameter('debril_rss_atom.curlopt', $config['curlopt']);
60-
}
45+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
46+
$loader->load('services.yml');
6147

48+
$this->setDateFormats($container, $config);
6249
$container->setParameter('debril_rss_atom.private_feeds', $config['private']);
6350
}
6451

@@ -73,6 +60,26 @@ protected function setDefinition(ContainerBuilder $container, $serviceName, $cla
7360
if ( ! $container->hasDefinition($serviceName) && ! $container->hasAlias($serviceName)) {
7461
$container->setDefinition($serviceName, new Definition($className));
7562
}
63+
64+
return $this;
65+
}
66+
67+
/**
68+
* @param ContainerBuilder $container
69+
* @param array $config
70+
* @return $this
71+
*/
72+
protected function setDateFormats(ContainerBuilder $container, array $config)
73+
{
74+
$dateFormats = isset($config['date_formats']) ?
75+
array_merge($this->defaultDateFormats, $config['date_formats']):
76+
$this->defaultDateFormats;
77+
78+
$container->setParameter(
79+
'debril_rss_atom.date_formats',
80+
$dateFormats
81+
);
82+
7683
return $this;
7784
}
7885
}

Driver/FileDriver.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

Driver/GuzzleBridgeDriver.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)