Skip to content

Commit

Permalink
Merge pull request #123 from alexdebril/release/3.0
Browse files Browse the repository at this point in the history
Release/3.0
  • Loading branch information
alexdebril authored Nov 18, 2016
2 parents b4e1424 + 07def16 commit f2b11cf
Show file tree
Hide file tree
Showing 59 changed files with 121 additions and 5,953 deletions.
57 changes: 19 additions & 38 deletions Controller/StreamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Debril\RssAtomBundle\Controller;

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

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

if (! $this->container->getParameter('debril_rss_atom.private_feeds')) {
$response->setPublic();
}

$response->setMaxAge(3600);
$response->setLastModified($content->getLastModified());
} else {
$response = new Response();
$response->setNotModified();
Expand All @@ -118,19 +111,21 @@ protected function createStreamResponse(array $options, $format, $source = self:
}

/**
* @param $feed
* @param $format
* @return string
* @throws \Exception
* @param Response $response
* @param FeedInterface $feed
* @return $this
*/
protected function getStringOutput($feed, $format)
protected function setFeedHeaders(Response $response, FeedInterface $feed)
{
if ( $feed instanceof Feed ) {
return $this->getFeedIo()->format($feed, $format)->saveXML();
$response->headers->set('Content-Type', 'application/xhtml+xml');
if (! $this->isPrivate() ) {
$response->setPublic();
}

$formatter = $this->getFormatter($format);
return $formatter->toString($feed);
$response->setMaxAge(3600);
$response->setLastModified($feed->getLastModified());

return $this;
}

/**
Expand All @@ -141,7 +136,7 @@ protected function getStringOutput($feed, $format)
* @param array $options
* @param string $source
*
* @return FeedOutInterface
* @return FeedInterface
*
* @throws \Exception
*/
Expand Down Expand Up @@ -175,26 +170,11 @@ protected function mustForceRefresh()
}

/**
* Get the accurate formatter.
*
* @param string $format
*
* @throws \Exception
*
* @return FeedFormatter
* @return boolean true if the feed must be private
*/
protected function getFormatter($format)
protected function isPrivate()
{
$services = array(
'rss' => 'debril.formatter.rss',
'atom' => 'debril.formatter.atom',
);

if (!array_key_exists($format, $services)) {
throw new \Exception("Unsupported format {$format}");
}

return $this->get($services[$format]);
return $this->container->getParameter('debril_rss_atom.private_feeds');
}

/**
Expand All @@ -204,4 +184,5 @@ protected function getFeedIo()
{
return $this->container->get('feedio');
}

}
7 changes: 0 additions & 7 deletions DebrilRssAtomBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

namespace Debril\RssAtomBundle;

use Debril\RssAtomBundle\DependencyInjection\CompilerPass\DriverCompilerPass;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class DebrilRssAtomBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new DriverCompilerPass());
}
}
59 changes: 0 additions & 59 deletions DependencyInjection/CompilerPass/DriverCompilerPass.php

This file was deleted.

22 changes: 0 additions & 22 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,6 @@ public function getConfigTreeBuilder()
->arrayNode('date_formats')
->prototype('scalar')->end()
->end()
->enumNode('driver')
->info('Driver to use to fetch RSS feed. Valid values are "curl" (default), "file", "guzzle", "service".')
->values(array('curl', 'file', 'guzzle', 'service'))
->defaultValue('curl')
->end()
->scalarNode('driver_service')
->info('If driver is set to "csa-guzzle" or "service", the ID of the service to use')
->end()
->arrayNode('curlopt')
->info('Parameters for curl requests')
->children()
->scalarNode('timeout')
->info('Timeout in seconds for curl requests')
->end()
->scalarNode('useragent')
->info('User agent for curl requests')
->end()
->scalarNode('maxredirs')
->info('Maximum redirects for curl requests')
->end()
->end()
->end()
->end()
;

Expand Down
73 changes: 40 additions & 33 deletions DependencyInjection/DebrilRssAtomExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
*/
class DebrilRssAtomExtension extends Extension
{

/**
* @var array
*/
protected $defaultDateFormats = [
\DateTime::RFC3339,
\DateTime::RSS,
\DateTime::W3C,
'Y-m-d\TH:i:s.uP',
'Y-m-d',
'd/m/Y',
'd M Y H:i:s P',
'D, d M Y H:i O',
'D, d M Y H:i:s O',
'D M d Y H:i:s e',
];

/**
* {@inheritDoc}
*/
Expand All @@ -25,40 +42,10 @@ public function load(array $configs, ContainerBuilder $container)

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

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');

$default = array(
\DateTime::RFC3339,
\DateTime::RSS,
\DateTime::W3C,
'Y-m-d\TH:i:s.uP',
'Y-m-d',
'd/m/Y',
'd M Y H:i:s P',
'D, d M Y H:i O',
'D, d M Y H:i:s O',
'D M d Y H:i:s e',
);

if (!isset($config['date_formats'])) {
$container->setParameter(
'debril_rss_atom.date_formats',
$default
);
} else {
$container->setParameter(
'debril_rss_atom.date_formats',
array_merge($default, $config['date_formats'])
);
}

if ( !isset($config['curlopt']) ) {
$container->setParameter('debril_rss_atom.curlopt', array());
} else {
$container->setParameter('debril_rss_atom.curlopt', $config['curlopt']);
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');

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

Expand All @@ -73,6 +60,26 @@ protected function setDefinition(ContainerBuilder $container, $serviceName, $cla
if ( ! $container->hasDefinition($serviceName) && ! $container->hasAlias($serviceName)) {
$container->setDefinition($serviceName, new Definition($className));
}

return $this;
}

/**
* @param ContainerBuilder $container
* @param array $config
* @return $this
*/
protected function setDateFormats(ContainerBuilder $container, array $config)
{
$dateFormats = isset($config['date_formats']) ?
array_merge($this->defaultDateFormats, $config['date_formats']):
$this->defaultDateFormats;

$container->setParameter(
'debril_rss_atom.date_formats',
$dateFormats
);

return $this;
}
}
43 changes: 0 additions & 43 deletions Driver/FileDriver.php

This file was deleted.

43 changes: 0 additions & 43 deletions Driver/GuzzleBridgeDriver.php

This file was deleted.

Loading

0 comments on commit f2b11cf

Please sign in to comment.