-
Notifications
You must be signed in to change notification settings - Fork 0
/
netbrothers-feed.php
58 lines (49 loc) · 1.61 KB
/
netbrothers-feed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* NbFeed
*
* @author Stefan Wessel, NetBrothers GmbH
* @date 23.06.23
*/
use NetBrothers\NbFeed\Service\ConfigService;
use NetBrothers\NbFeed\Service\FeedService;
/**
* To use this example, call `composer install --no-dev` after the checkout.
* The script tries to load the `autoload.php` automatically. If this does not
* work, set the path manually.
*/
$libModeAutoload = __DIR__ . '/../../../autoload.php';
if (file_exists($libModeAutoload)) {
// when used as a vendor package
require $libModeAutoload;
} else {
// when used entirely standalone (e.g. git clone)
require __DIR__ . '/../vendor/autoload.php';
}
/**
* How you set the configuration might depend on the PHP and/or DI framework you
* are using. For demonstration purposes, the configuration is set manually in
* this example.
*/
// URL RSS-Feed (required)
$feedUrl = 'https://www.heise.de/security/rss/alert-news.rdf';
// Initialize `ConfigService`
$configService = new ConfigService();
// $configService->setMaxEntriesToSave(1);
$configService->setStoragePath(__DIR__ . '/../tmp');
$configService->setFeedFileName('heise-security');
$configService->setCacheMaxAge(300);
// Instantiating the `FeedService`
$feedService = new FeedService($configService);
/**
* Retrieve the feed:
* - As we have never loaded anything before, the feed is now being pulled,
* transformed and saved to disk.
* - If there is a file on the hard disk that is **not** older than allowed, the
* results are pulled from the cache.
*/
$feedArray = $feedService->getFeed($feedUrl, true);
print PHP_EOL;
var_dump($feedArray);
print PHP_EOL;
unset($feedArray);