Skip to content

Commit 3a7c7cf

Browse files
committed
Clean up indentation and replace to short array syntax.
Signed-off-by: Hidehito Nozawa <[email protected]>
1 parent 51840d2 commit 3a7c7cf

File tree

10 files changed

+304
-259
lines changed

10 files changed

+304
-259
lines changed

README.md

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,80 @@
11
# \Suin\RSSWriter
22

3-
`\Suin\RSSWriter` is yet another simple RSS writer library for PHP 5.3 or later. This component is Licensed under MIT license.
3+
`\Suin\RSSWriter` is yet another simple RSS writer library for PHP 5.4 or later. This component is Licensed under MIT license.
44

55
This library can also be used to publish Podcasts.
66

77
The build status of the current master branch is tracked by Travis CI: [![Build Status](https://secure.travis-ci.org/suin/php-rss-writer.png?branch=master)](http://travis-ci.org/suin/php-rss-writer)
88

99

10-
Implementation:
10+
## Quick demo
11+
1112

1213
```php
13-
<?php
1414
$feed = new Feed();
1515

1616
$channel = new Channel();
1717
$channel
18-
->title("Channel Title")
19-
->description("Channel Description")
20-
->url('http://blog.example.com')
21-
->appendTo($feed);
22-
23-
// RSS item
18+
->title('Channel Title')
19+
->description('Channel Description')
20+
->url('http://blog.example.com')
21+
->language('en-US')
22+
->copyright('Copyright 2012, Foo Bar')
23+
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
24+
->lastBuildDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
25+
->ttl(60)
26+
->appendTo($feed);
27+
28+
// Blog item
2429
$item = new Item();
2530
$item
26-
->title("Blog Entry Title")
27-
->description("<div>Blog body</div>")
28-
->url('http://blog.example.com/2012/08/21/blog-entry/')
29-
->appendTo($channel);
31+
->title('Blog Entry Title')
32+
->description('<div>Blog body</div>')
33+
->url('http://blog.example.com/2012/08/21/blog-entry/')
34+
->author('Hidehito Nozawa')
35+
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
36+
->guid('http://blog.example.com/2012/08/21/blog-entry/', true)
37+
->appendTo($channel);
3038

3139
// Podcast item
3240
$item = new Item();
3341
$item
34-
->title("Some Podcast Entry")
35-
->description("<div>Podcast body</div>")
36-
->url('http://podcast.example.com/2012/08/21/podcast-entry/')
37-
->enclosure('http://link-to-audio-file.com/2013/08/21/podcast.mp3', 4889, 'audio/mpeg')
38-
->appendTo($channel);
39-
42+
->title('Some Podcast Entry')
43+
->description('<div>Podcast body</div>')
44+
->url('http://podcast.example.com/2012/08/21/podcast-entry/')
45+
->enclosure('http://podcast.example.com/2012/08/21/podcast.mp3', 4889, 'audio/mpeg')
46+
->appendTo($channel);
4047

41-
echo $feed;
48+
echo $feed; // or echo $feed->render();
4249
```
4350

4451
Output:
4552

4653
```xml
47-
<?xml version="1.0"?>
54+
<?xml version="1.0" encoding="UTF-8"?>
4855
<rss version="2.0">
4956
<channel>
5057
<title>Channel Title</title>
5158
<link>http://blog.example.com</link>
5259
<description>Channel Description</description>
60+
<language>en-US</language>
61+
<copyright>Copyright 2012, Foo Bar</copyright>
62+
<pubDate>Tue, 21 Aug 2012 19:50:37 +0900</pubDate>
63+
<lastBuildDate>Tue, 21 Aug 2012 19:50:37 +0900</lastBuildDate>
64+
<ttl>60</ttl>
5365
<item>
5466
<title>Blog Entry Title</title>
5567
<link>http://blog.example.com/2012/08/21/blog-entry/</link>
5668
<description>&lt;div&gt;Blog body&lt;/div&gt;</description>
69+
<guid>http://blog.example.com/2012/08/21/blog-entry/</guid>
70+
<pubDate>Tue, 21 Aug 2012 19:50:37 +0900</pubDate>
71+
<author>Hidehito Nozawa</author>
72+
</item>
73+
<item>
74+
<title>Some Podcast Entry</title>
75+
<link>http://podcast.example.com/2012/08/21/podcast-entry/</link>
76+
<description>&lt;div&gt;Podcast body&lt;/div&gt;</description>
77+
<enclosure url="http://podcast.example.com/2012/08/21/podcast.mp3" type="audio/mpeg" length="4889"/>
5778
</item>
5879
</channel>
5980
</rss>
@@ -62,12 +83,15 @@ Output:
6283
## Installation
6384

6485
### Easy installation
86+
6587
You can install directly via [Composer](https://getcomposer.org/):
88+
6689
```bash
6790
$ composer require suin/php-rss-writer
6891
```
6992

7093
### Manual installation
94+
7195
Add the following code to your `composer.json` file:
7296

7397
```json
@@ -79,13 +103,14 @@ Add the following code to your `composer.json` file:
79103
```
80104

81105
...and run composer to install it:
106+
82107
```bash
83108
$ composer install
84109
```
85110

86111
Finally, include `vendor/autoload.php` in your product:
112+
87113
```php
88-
<?php
89114
require_once 'vendor/autoload.php';
90115
```
91116

@@ -97,4 +122,4 @@ If you want to know APIs, please see [`FeedInterface`](src/Suin/RSSWriter/FeedIn
97122

98123
## License
99124

100-
MIT license
125+
MIT license

composer.json

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
{
2-
"name": "suin/php-rss-writer",
3-
"type": "library",
4-
"description": "Yet another simple RSS writer library for PHP 5.3 or later.",
5-
"keywords": ["rss", "generator", "writer", "feed", "php"],
6-
"homepage": "https://github.com/suin/php-rss-writer",
7-
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Hidehito Nozawa aka Suin",
11-
"email": "[email protected]"
12-
}
13-
],
14-
"require": {
15-
"php": ">=5.3.0"
16-
},
17-
"autoload": {
18-
"psr-0": { "Suin\\RSSWriter": "src" }
19-
}
2+
"name": "suin/php-rss-writer",
3+
"type": "library",
4+
"description": "Yet another simple RSS writer library for PHP 5.4 or later.",
5+
"keywords": [
6+
"rss",
7+
"generator",
8+
"writer",
9+
"feed",
10+
"php"
11+
],
12+
"homepage": "https://github.com/suin/php-rss-writer",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Hidehito Nozawa aka Suin",
17+
"email": "[email protected]"
18+
}
19+
],
20+
"require": {
21+
"php": ">=5.4.0"
22+
},
23+
"autoload": {
24+
"psr-0": {
25+
"Suin\\RSSWriter": "src"
26+
}
27+
}
2028
}

examples/simple-feed.php

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
11
<?php
22

3+
use Suin\RSSWriter\Channel;
4+
use Suin\RSSWriter\Feed;
5+
use Suin\RSSWriter\Item;
6+
37
// Load test target classes
48
spl_autoload_register(function ($c) {
5-
@include_once strtr($c, '\\_', '//') . '.php';
9+
@include_once strtr($c, '\\_', '//') . '.php';
610
});
711
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__) . '/src');
812

9-
use Suin\RSSWriter\Channel;
10-
use Suin\RSSWriter\Feed;
11-
use Suin\RSSWriter\Item;
12-
1313
$feed = new Feed();
1414

1515
$channel = new Channel();
1616
$channel
17-
->title("Channel Title")
18-
->description("Channel Description")
19-
->url('http://blog.example.com')
20-
->language('en-US')
21-
->copyright('Copyright 2012, Foo Bar')
22-
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
23-
->lastBuildDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
24-
->ttl(60)
25-
->appendTo($feed);
17+
->title('Channel Title')
18+
->description('Channel Description')
19+
->url('http://blog.example.com')
20+
->language('en-US')
21+
->copyright('Copyright 2012, Foo Bar')
22+
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
23+
->lastBuildDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
24+
->ttl(60)
25+
->appendTo($feed);
2626

27+
// Blog item
2728
$item = new Item();
2829
$item
29-
->title("Blog Entry Title")
30-
->description("<div>Blog body</div>")
31-
->url('http://blog.example.com/2012/08/21/blog-entry/')
32-
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
33-
->guid('http://blog.example.com/2012/08/21/blog-entry/', true)
34-
->appendTo($channel);
30+
->title('Blog Entry Title')
31+
->description('<div>Blog body</div>')
32+
->url('http://blog.example.com/2012/08/21/blog-entry/')
33+
->author('Hidehito Nozawa')
34+
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
35+
->guid('http://blog.example.com/2012/08/21/blog-entry/', true)
36+
->appendTo($channel);
3537

38+
// Podcast item
39+
$item = new Item();
40+
$item
41+
->title('Some Podcast Entry')
42+
->description('<div>Podcast body</div>')
43+
->url('http://podcast.example.com/2012/08/21/podcast-entry/')
44+
->enclosure('http://podcast.example.com/2012/08/21/podcast.mp3', 4889, 'audio/mpeg')
45+
->appendTo($channel);
3646

37-
echo $feed; // or echo $feed->render();
47+
echo $feed; // or echo $feed->render();

src/Suin/RSSWriter/Channel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Channel implements ChannelInterface
3333
protected $ttl;
3434

3535
/** @var ItemInterface[] */
36-
protected $items = array();
36+
protected $items = [];
3737

3838
/**
3939
* Set channel title

src/Suin/RSSWriter/Feed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class Feed implements FeedInterface
1212
{
1313
/** @var ChannelInterface[] */
14-
protected $channels = array();
14+
protected $channels = [];
1515

1616
/**
1717
* Add channel

src/Suin/RSSWriter/Item.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Item implements ItemInterface
1818
protected $description;
1919

2020
/** @var array */
21-
protected $categories = array();
21+
protected $categories = [];
2222

2323
/** @var string */
2424
protected $guid;
@@ -55,7 +55,7 @@ public function description($description)
5555

5656
public function category($name, $domain = null)
5757
{
58-
$this->categories[] = array($name, $domain);
58+
$this->categories[] = [$name, $domain];
5959
return $this;
6060
}
6161

@@ -74,7 +74,7 @@ public function pubDate($pubDate)
7474

7575
public function enclosure($url, $length = 0, $type = 'audio/mpeg')
7676
{
77-
$this->enclosure = array('url' => $url, 'length' => $length, 'type' => $type);
77+
$this->enclosure = ['url' => $url, 'length' => $length, 'type' => $type];
7878
return $this;
7979
}
8080

0 commit comments

Comments
 (0)