xref: /dokuwiki/inc/Feed/FeedParserFile.php (revision db9267247e06d4aae1a33463c71b2c22d7f7a2a7)
1*db926724SAndreas Gohr<?php
2*db926724SAndreas Gohr
3*db926724SAndreas Gohrnamespace dokuwiki\Feed;
4*db926724SAndreas Gohr
5*db926724SAndreas Gohruse dokuwiki\HTTP\DokuHTTPClient;
6*db926724SAndreas Gohruse SimplePie\File;
7*db926724SAndreas Gohruse SimplePie\SimplePie;
8*db926724SAndreas Gohr
9*db926724SAndreas Gohr/**
10*db926724SAndreas Gohr * Fetch an URL using our own HTTPClient
11*db926724SAndreas Gohr *
12*db926724SAndreas Gohr * Replaces SimplePie's own class
13*db926724SAndreas Gohr */
14*db926724SAndreas Gohrclass FeedParserFile extends File
15*db926724SAndreas Gohr{
16*db926724SAndreas Gohr    protected $http;
17*db926724SAndreas Gohr    /** @noinspection PhpMissingParentConstructorInspection */
18*db926724SAndreas Gohr
19*db926724SAndreas Gohr    /**
20*db926724SAndreas Gohr     * Inititializes the HTTPClient
21*db926724SAndreas Gohr     *
22*db926724SAndreas Gohr     * We ignore all given parameters - they are set in DokuHTTPClient
23*db926724SAndreas Gohr     *
24*db926724SAndreas Gohr     * @inheritdoc
25*db926724SAndreas Gohr     */
26*db926724SAndreas Gohr    public function __construct(
27*db926724SAndreas Gohr        $url
28*db926724SAndreas Gohr    ) {
29*db926724SAndreas Gohr        $this->http = new DokuHTTPClient();
30*db926724SAndreas Gohr        $this->success = $this->http->sendRequest($url);
31*db926724SAndreas Gohr
32*db926724SAndreas Gohr        $this->headers = $this->http->resp_headers;
33*db926724SAndreas Gohr        $this->body = $this->http->resp_body;
34*db926724SAndreas Gohr        $this->error = $this->http->error;
35*db926724SAndreas Gohr
36*db926724SAndreas Gohr        $this->method = SimplePie::FILE_SOURCE_REMOTE | SimplePie::FILE_SOURCE_FSOCKOPEN;
37*db926724SAndreas Gohr
38*db926724SAndreas Gohr        return $this->success;
39*db926724SAndreas Gohr    }
40*db926724SAndreas Gohr
41*db926724SAndreas Gohr    /** @inheritdoc */
42*db926724SAndreas Gohr    public function headers()
43*db926724SAndreas Gohr    {
44*db926724SAndreas Gohr        return $this->headers;
45*db926724SAndreas Gohr    }
46*db926724SAndreas Gohr
47*db926724SAndreas Gohr    /** @inheritdoc */
48*db926724SAndreas Gohr    public function body()
49*db926724SAndreas Gohr    {
50*db926724SAndreas Gohr        return $this->body;
51*db926724SAndreas Gohr    }
52*db926724SAndreas Gohr
53*db926724SAndreas Gohr    /** @inheritdoc */
54*db926724SAndreas Gohr    public function close()
55*db926724SAndreas Gohr    {
56*db926724SAndreas Gohr        return true;
57*db926724SAndreas Gohr    }
58*db926724SAndreas Gohr}
59