Skip to content

Commit

Permalink
prepare 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Mar 17, 2016
1 parent ec050f7 commit 0266653
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All Notable changes to `laravel-feed` will be documented in this file

- Fixed compatibility with short php tags

## 1.0.4 - 2016-03-17

- Make output more atom compliant

## 1.0.3 - 2016-03-07

- Add compatibility with short php tags
Expand Down
1 change: 1 addition & 0 deletions Exceptions/InvalidConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Feed\Exceptions;

use Exception;

class InvalidConfiguration extends Exception
{
public static function delimiterNotPresent($configValue)
Expand Down
7 changes: 7 additions & 0 deletions src/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,37 @@ class Feed
{
/** @var array */
protected $feedConfiguration;

public function __construct(array $feedConfiguration)
{
$this->feedConfiguration = $feedConfiguration;
if (!str_contains($feedConfiguration['items'], '@')) {
throw InvalidConfiguration::delimiterNotPresent($feedConfiguration['items']);
}
}

public function getFeedResponse()
{
return response($this->getFeedContent(), 200, array('Content-Type' => 'application/xml;charset=UTF-8'));
}

public function getFeedContent()
{
list($class, $method) = explode('@', $this->feedConfiguration['items']);

$items = app($class)->{$method}();

$meta = array('id' => url($this->feedConfiguration['url']), 'link' => url($this->feedConfiguration['url']), 'title' => $this->feedConfiguration['title'], 'updated' => $this->getLastUpdatedDate($items));

return view('laravel-feed::feed', compact('meta', 'items'))->render();
}

protected function getLastUpdatedDate(Collection $items)
{
if (!count($items)) {
return '';
}

$lastItem = $items->sortBy(function (FeedItem $feedItem) {
return $feedItem->getFeedItemUpdated()->format('YmdHis');
})->last();
Expand Down
5 changes: 5 additions & 0 deletions src/FeedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
interface FeedItem
{
public function getFeedItemId();

public function getFeedItemTitle();

public function getFeedItemUpdated();

public function getFeedItemSummary();

public function getFeedItemLink();

public function getFeedItemAuthor();
}
9 changes: 9 additions & 0 deletions src/FeedServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,42 @@ public function boot()
$this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-feed');
$this->bindFeedLinks();
}

public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/laravel-feed.php', 'laravel-feed');
$this->registerRouteMacro();
}

protected function registerRouteMacro()
{
$router = $this->app['router'];

$router->macro('feeds', function ($baseUrl = '') use ($router) {

foreach (config('laravel-feed.feeds') as $index => $feedConfiguration) {
$separator = starts_with($feedConfiguration['url'], DIRECTORY_SEPARATOR) ? '' : DIRECTORY_SEPARATOR;
$fullUrl = $baseUrl.$separator.$feedConfiguration['url'];
$router->get($fullUrl, array('as' => "spatieLaravelFeed{$index}", function () use ($fullUrl, $feedConfiguration) {

$feedConfiguration['url'] = $fullUrl;
$feed = new Feed($feedConfiguration);

return $feed->getFeedResponse();

}));
}
});
}

public function bindFeedLinks()
{
$feeds = array();

foreach (config('laravel-feed.feeds') as $index => $feedConfig) {
$feeds[] = array('title' => $feedConfig['title'], 'url' => $this->app['url']->route("spatieLaravelFeed{$index}"));
}

$this->app->make(Dispatcher::class)->listen('composing: laravel-feed::feed-links', function (View $view) use ($feeds) {
$view->with(compact('feeds'));
});
Expand Down

0 comments on commit 0266653

Please sign in to comment.