Skip to content

Commit 67706c5

Browse files
authored
PHP 8-only Support, New Features (v4) (spatie#153)
* add 'content-type' config option to allow customization of the content-type for the feed response * add jsonfeed.org support * add test for jsonfeed.org support, update test snapshots * sync config/misc files with spatie/package-skeleton-laravel where possible * drop php 7 support; add support for parallel testing; bump phpunit version to 9.5 * update php-cs-fixer config * update readme * escape quotes for content/summary fields * add support for feed images * add configuration option for specifying the feed type (atom, rss. or json) * add owner feed object prop, timestamp() method for generating correct timestamps based on the feed format * ensure that generated rss, atom and json feeds can pass w3c validation * add helper class for determining content types for feeds; use helper class to determine response content type * add `image` attribute to FeedItem (json feeds only); remove `Feed::author` attribute and add `Feed::authorName` and `Feed::authorEmail` attributes; add test for response content type; update tests/snapshots * update readme, wip * use hasViewComposer() instead of separate methods for registering the view composer; code cleanup * remove unused import * add configuration file validation * wip * add config validator tests; update test snapshots * support tuple syntax for items configuration key * wip * update readme, description of items key in config * make config validation and tests more robust * wip * rename `jsonfeed` view to `json` * use PHP 8 syntax where possible * remove feed::feed view * default to feed::atom view instead of feed::feed * add support for caching feed items * rename kebab-case config keys to camelCase * wip * use php 8 syntax, code cleanup * add version upgrade guide * validate cacheTtl config option * revert item cache commits * fix feed item resolver and tests * update docs on how to correctly pass arguments to the `items` method * use PHPUnit 9.5.4; bump laravel-package-tools version to v1.9 * update changelog * remove parallel testing, use PHPUnit 9.4 to avoid issues with v9.5
1 parent f0d15c8 commit 67706c5

Some content is hidden

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

49 files changed

+1081
-365
lines changed

.editorconfig

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
; This file is for unifying the coding style for different editors and IDEs.
2-
; More information at http://editorconfig.org
3-
41
root = true
52

63
[*]
@@ -13,3 +10,6 @@ trim_trailing_whitespace = true
1310

1411
[*.md]
1512
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitattributes

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
33

44
# Ignore all test and documentation with "export-ignore".
5+
/.github export-ignore
56
/.gitattributes export-ignore
67
/.gitignore export-ignore
7-
/.travis.yml export-ignore
88
/phpunit.xml.dist export-ignore
9-
/.scrutinizer.yml export-ignore
109
/tests export-ignore
10+
/.editorconfig export-ignore
11+
/.php_cs.dist export-ignore
12+
/psalm.xml export-ignore
13+
/psalm.xml.dist export-ignore
14+
/testbench.yaml export-ignore

.github/CONTRIBUTING.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54+
55+
**Happy coding**!

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
github: spatie
2+
custom: https://spatie.be/open-source/support-us

.github/ISSUE_TEMPLATE/config.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Ask a question
4+
url: https://github.com/spatie/laravel-feed/discussions/new?category=q-a
5+
about: Ask the community for help
6+
- name: Request a feature
7+
url: https://github.com/spatie/laravel-feed/discussions/new?category=ideas
8+
about: Share ideas for new features
9+
- name: Report a bug
10+
url: https://github.com/spatie/laravel-feed/issues/new
11+
about: Report a reproducable bug

.github/SECURITY.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Security Policy
2+
3+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.

.github/workflows/php-cs-fixer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Fix style
1414
uses: docker://oskarstark/php-cs-fixer-ga
1515
with:
16-
args: --config=.php_cs --allow-risky=yes
16+
args: --config=.php_cs.dist --allow-risky=yes
1717

1818
- name: Extract branch name
1919
shell: bash

.github/workflows/run-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
os: [ubuntu-latest]
12-
php: [7.4, 8.0]
12+
php: [8.0]
1313
laravel: [7.*, 8.*]
1414
dependency-version: [prefer-lowest, prefer-stable]
1515
include:

.gitignore

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
.idea
2+
.php_cs
3+
.php_cs.cache
4+
.phpunit.result.cache
15
build
26
composer.lock
7+
coverage
38
docs
9+
phpunit.xml
10+
psalm.xml
11+
testbench.yaml
412
vendor
5-
.php_cs.cache

.php_cs renamed to .php_cs.dist

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
$finder = Symfony\Component\Finder\Finder::create()
44
->notPath('bootstrap/*')
55
->notPath('storage/*')
6-
->notPath('storage/*')
76
->notPath('resources/view/mail/*')
87
->in([
98
__DIR__ . '/src',
@@ -30,9 +29,15 @@ return PhpCsFixer\Config::create()
3029
],
3130
'phpdoc_single_line_var_spacing' => true,
3231
'phpdoc_var_without_name' => true,
32+
'class_attributes_separation' => [
33+
'elements' => [
34+
'method',
35+
],
36+
],
3337
'method_argument_space' => [
3438
'on_multiline' => 'ensure_fully_multiline',
3539
'keep_multiple_spaces_after_comma' => true,
36-
]
40+
],
41+
'single_trait_insert_per_statement' => true,
3742
])
3843
->setFinder($finder);

CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
All notable changes to `laravel-feed` will be documented in this file
44

5+
## 4.0.0 - unreleased
6+
7+
- adds support for PHP 8 only.
8+
- drops PHP 7 support.
9+
- uses PHP 8 syntax where possible.
10+
- bumps `PHPUnit` to v9.5.
11+
- adds support for running tests in parallel.
12+
- updates the readme to include the new API & configuration settings.
13+
- adds an `UPGRADING.md` guide to help users manually upgrade package versions.
14+
- adds support for json feeds _(`jsonfeed.org` support)_.
15+
- removes `FeedItem::author`. _Use `FeedItem::authorName` and `FeedItem::authorEmail` instead._
16+
- removes the `feed::feed` view. _Use `feed::atom`, `feed::json`, `feed:rss` or a custom view instead._
17+
- adds support for `FeedItem::image` _(json feeds only)_.
18+
- adds validation of the configuration file.
19+
- adds support for tuple notation in the `items` configuration key.
20+
- adds feed config option `format` to specify the type of feed that is generated _(`rss`, `atom`, or `json`)_.
21+
- adds feed config option `contentType` to force the content type of the feed response.
22+
- adds feed config option `image` which associates an image with the overall feed.
23+
- changes feed config option `type` default value to an empty string _(value is now auto detected by default)_.
24+
- changes feed config option `view` so that it is now required to be an existing view.
25+
- config option `view` no longer defaults to `feed::feed` when it contains an empty value _(now defaults to `feed::atom`)._
26+
- generated rss and atom feeds now pass w3c validation (#152).
27+
28+
This release contains Breaking Changes:
29+
- `FeedItem::author` has been replaced with `authorName` and `authorEmail` _(optional)_.
30+
- Several new configuration options are required (see above).
31+
- The value of the configuration option `view` must be an existing view _(empty values/non-existent views now throw an Exception)_.
32+
533
## 3.2.1 - 2021-05-27
634

735
- fix breaking change introduced in 3.1.4

CONTRIBUTING.md

-32
This file was deleted.

README.md

+62-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/spatie/laravel-feed/run-tests?label=tests)
66
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-feed.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-feed)
77

8-
This package provides an easy way to generate [RSS feeds](http://www.whatisrss.com/). There's almost no coding required on your part. Just follow the installation instructions update your config file and you're good to go.
8+
This package provides an easy way to generate a feed for your Laravel application. Supported formats are [RSS](http://www.whatisrss.com/), [Atom](https://en.wikipedia.org/wiki/Atom_(standard)), and [JSON](https://jsonfeed.org). There's almost no coding required on your part. Just follow the installation instructions, update your config file, and you're good to go.
99

1010
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).
1111

@@ -50,9 +50,13 @@ return [
5050
* Here you can specify which class and method will return
5151
* the items that should appear in the feed. For example:
5252
* 'App\Model@getAllFeedItems'
53+
* or
54+
* ['App\Model', 'getAllFeedItems']
5355
*
54-
* You can also pass an argument to that method:
55-
* ['App\Model@getAllFeedItems', 'argument']
56+
* You can also pass an argument to that method. Note that their key must be the name of the parameter: *
57+
* ['App\Model@getAllFeedItems', 'parameterName' => 'argument']
58+
* or
59+
* ['App\Model', 'getAllFeedItems', 'parameterName' => 'argument']
5660
*/
5761
'items' => '',
5862

@@ -65,10 +69,34 @@ return [
6569
'description' => 'The description of the feed.',
6670
'language' => 'en-US',
6771

72+
/*
73+
* The image to display for the feed. For Atom feeds, this is displayed as
74+
* a banner/logo; for RSS and JSON feeds, it's displayed as an icon.
75+
* An empty value omits the image attribute from the feed.
76+
*/
77+
'image' => '',
78+
79+
/*
80+
* The format of the feed. Acceptable values are 'rss', 'atom', or 'json'.
81+
*/
82+
'format' => 'atom',
83+
6884
/*
6985
* The view that will render the feed.
7086
*/
71-
'view' => 'feed::feed',
87+
'view' => 'feed::atom',
88+
89+
/*
90+
* The type to be used in the <link> tag. Set to an empty string to automatically
91+
* determine the correct value.
92+
*/
93+
'type' => '',
94+
95+
/*
96+
* The content type for the feed response. Set to an empty string to automatically
97+
* determine the correct value.
98+
*/
99+
'contentType' => '',
72100
],
73101
],
74102
];
@@ -103,7 +131,8 @@ class NewsItem extends Model implements Feedable
103131
->summary($this->summary)
104132
->updated($this->updated_at)
105133
->link($this->link)
106-
->author($this->author);
134+
->authorName($this->author)
135+
->authorEmail($this->authorEmail);
107136
}
108137
}
109138
```
@@ -127,7 +156,7 @@ class NewsItem extends Model implements Feedable
127156
'summary' => $this->summary,
128157
'updated' => $this->updated_at,
129158
'link' => $this->link,
130-
'author' => $this->author,
159+
'authorName' => $this->authorName,
131160
]);
132161
}
133162
}
@@ -158,7 +187,14 @@ return [
158187
/*
159188
* Here you can specify which class and method will return
160189
* the items that should appear in the feed. For example:
161-
* '\App\Model@getAllFeedItems'
190+
* 'App\Model@getAllFeedItems'
191+
* or
192+
* ['App\Model', 'getAllFeedItems']
193+
*
194+
* You can also pass an argument to that method. Note that their key must be the name of the parameter: *
195+
* ['App\Model@getAllFeedItems', 'parameterName' => 'argument']
196+
* or
197+
* ['App\Model', 'getAllFeedItems', 'parameterName' => 'argument']
162198
*/
163199
'items' => 'App\NewsItem@getFeedItems',
164200

@@ -169,6 +205,11 @@ return [
169205

170206
'title' => 'All newsitems on mysite.com',
171207

208+
/*
209+
* The format of the feed. Acceptable values are 'rss', 'atom', or 'json'.
210+
*/
211+
'format' => 'atom',
212+
172213
/*
173214
* Custom view for the items.
174215
*
@@ -202,12 +243,17 @@ return [
202243

203244
'feeds' => [
204245
'news' => [
205-
'items' => 'App\NewsItem@getFeedItems',
246+
'items' => ['App\NewsItem', 'getFeedItems'],
206247

207248
'url' => '/feed',
208249

209250
'title' => 'All newsitems on mysite.com',
210251

252+
/*
253+
* The format of the feed. Acceptable values are 'rss', 'atom', or 'json'.
254+
*/
255+
'format' => 'atom',
256+
211257
/*
212258
* Custom view for the items.
213259
*
@@ -240,23 +286,23 @@ As an alternative you can use this blade component:
240286
<x-feed-links />
241287
```
242288

243-
## Changelog
244-
245-
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
246-
247289
## Testing
248290

249-
``` bash
291+
```bash
250292
composer test
251293
```
252294

295+
## Changelog
296+
297+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
298+
253299
## Contributing
254300

255-
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
301+
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
256302

257-
## Security
303+
## Security Vulnerabilities
258304

259-
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
305+
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
260306

261307
## Credits
262308

0 commit comments

Comments
 (0)