-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- rename into IO/Reader - add loadXML()
- Loading branch information
Showing
4 changed files
with
107 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the xmltv-library package. | ||
* | ||
* (c) 2019 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Library\XMLTV\IO; | ||
|
||
use DOMDocument; | ||
use Exception; | ||
use GuzzleHttp\Client; | ||
use Psr\Log\LoggerInterface; | ||
use WBW\Library\XMLTV\Model\Tv; | ||
use WBW\Library\XMLTV\Parser\Parser; | ||
use WBW\Library\XMLTV\Parser\ParserHelper; | ||
|
||
/** | ||
* Reader. | ||
* | ||
* @author webeweb <https://github.com/webeweb/> | ||
* @package WBW\Library\XMLTV\IO | ||
*/ | ||
class Reader { | ||
|
||
/** | ||
* Load an XML file. | ||
* | ||
* @param string $url The URL. | ||
* @param string $filename The filename The filename. | ||
* @param LoggerInterface|null $logger The logger. | ||
* @return Tv Returns the TV. | ||
* @throws Exception Throws an exception if an error occurs. | ||
*/ | ||
public static function loadXML($url, $filename, LoggerInterface $logger = null) { | ||
|
||
$stream = fopen($filename, "w"); | ||
|
||
$client = new Client([ | ||
"headers" => [ | ||
"Accept" => "text/xml", | ||
"User-Agent" => "webeweb/xmltv-library", | ||
], | ||
"save_to" => $stream, | ||
"synchronous" => true, | ||
]); | ||
|
||
$client->request("GET", $url); | ||
|
||
return static::readXML($filename, $logger); | ||
} | ||
|
||
/** | ||
* Read an XML file. | ||
* | ||
* @param string $filename The filename. | ||
* @param LoggerInterface $logger The logger. | ||
* @return Tv Returns the TV. | ||
*/ | ||
public static function readXML($filename, LoggerInterface $logger = null) { | ||
|
||
$document = new DOMDocument(); | ||
$document->load($filename); | ||
|
||
ParserHelper::setLogger($logger); | ||
|
||
return Parser::parseTv($document->documentElement); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters