1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the feed-io package. |
4
|
|
|
* |
5
|
|
|
* (c) Alexandre Debril <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace FeedIo\Command; |
12
|
|
|
|
13
|
|
|
use FeedIo\Factory; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
class ReadCommand extends Command |
21
|
|
|
{ |
22
|
|
|
protected function configure() |
23
|
|
|
{ |
24
|
|
|
$this->setName('read') |
25
|
|
|
->setDescription('reads a feed') |
26
|
|
|
->addArgument( |
27
|
|
|
'url', |
28
|
|
|
InputArgument::REQUIRED, |
29
|
|
|
'Please provide the feed\' URL' |
30
|
|
|
) |
31
|
|
|
->addOption('count', 'c', InputOption::VALUE_OPTIONAL) |
32
|
|
|
; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
36
|
|
|
{ |
37
|
|
|
$url = $input->getArgument('url'); |
38
|
|
|
$feedIo = Factory::create()->getFeedIo(); |
39
|
|
|
|
40
|
|
|
$feed = $feedIo->read($url)->getFeed(); |
41
|
|
|
$output->writeln("<info>{$feed->getTitle()}</info>"); |
42
|
|
|
|
43
|
|
|
$limit = null; |
44
|
|
|
if ( $input->hasOption('count') ) { |
45
|
|
|
$limit = intval($input->getOption('count')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
foreach( $feed as $i => $item ) { |
49
|
|
|
$output->writeln("<info>{$item->getLastModified()->format(\DateTime::ATOM)} : {$item->getTitle()}</info>"); |
50
|
|
|
$output->writeln("{$item->getDescription()}"); |
51
|
|
|
|
52
|
|
|
if ( ! is_null($limit) && $limit === $i+1 ) |
53
|
|
|
break; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |