summaryrefslogtreecommitdiffstats
path: root/vendor/fguillot/picofeed/example.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/fguillot/picofeed/example.php')
-rw-r--r--vendor/fguillot/picofeed/example.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/fguillot/picofeed/example.php b/vendor/fguillot/picofeed/example.php
new file mode 100644
index 000000000..6bf9b6e20
--- /dev/null
+++ b/vendor/fguillot/picofeed/example.php
@@ -0,0 +1,45 @@
+<?php
+
+require 'vendor/autoload.php';
+
+use PicoFeed\Reader\Reader;
+use PicoFeed\PicoFeedException;
+
+try {
+
+ // Fetch from your database the previous values of the Etag and LastModified headers
+ $etag = '...';
+ $last_modified = '...';
+
+ $reader = new Reader;
+
+ // Provide those values to the download method
+ $resource = $reader->download('http://linuxfr.org/news.atom', $last_modified, $etag);
+
+ if ($resource->isModified()) {
+
+ $parser = $reader->getParser(
+ $resource->getUrl(),
+ $resource->getContent(),
+ $resource->getEncoding()
+ );
+
+ $feed = $parser->execute();
+
+ // Save your feed in your database
+ // ...
+
+ // Store the Etag and the LastModified headers in your database
+ $etag = $resource->getEtag();
+ $last_modified = $resource->getLastModified();
+
+ // ...
+ }
+ else {
+
+ echo 'Not modified, nothing to do!';
+ }
+}
+catch (PicoFeedException $e) {
+ // Do something...
+}