diff options
author | Yaco <franco@reevo.org> | 2021-10-19 20:24:11 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2021-10-19 20:24:11 -0300 |
commit | e3880a1c86acaa3bbd05786ad2f5c586e6511a58 (patch) | |
tree | ec77bfc5b69f259a159c95188797bd0dade92357 /www/wiki/extensions/Maps/src/DataAccess/JsonFileParser.php | |
parent | 20ca0685509f8010580d3b45036a64ab48616af1 (diff) |
updates Maps to 7.13.0
Diffstat (limited to 'www/wiki/extensions/Maps/src/DataAccess/JsonFileParser.php')
-rw-r--r-- | www/wiki/extensions/Maps/src/DataAccess/JsonFileParser.php | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/www/wiki/extensions/Maps/src/DataAccess/JsonFileParser.php b/www/wiki/extensions/Maps/src/DataAccess/JsonFileParser.php deleted file mode 100644 index 81d6cfa0..00000000 --- a/www/wiki/extensions/Maps/src/DataAccess/JsonFileParser.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -declare( strict_types = 1 ); - -namespace Maps\DataAccess; - -use FileFetcher\FileFetcher; -use FileFetcher\FileFetchingException; -use Maps\MapsFactory; -use ValueParsers\ParseException; -use ValueParsers\ValueParser; - -/** - * Returns the content of the JSON file at the specified location as array. - * Empty array is returned on failure. - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < jeroendedauw@gmail.com > - */ -class JsonFileParser implements ValueParser { - - private $fileFetcher; - private $pageContentFetcher; - private $defaultNamespace; - - public function __construct( $fileFetcher = null, PageContentFetcher $pageContentFetcher = null ) { - $this->fileFetcher = $fileFetcher instanceof FileFetcher - ? $fileFetcher : MapsFactory::newDefault()->getGeoJsonFileFetcher(); - - $this->pageContentFetcher = $pageContentFetcher instanceof PageContentFetcher - ? $pageContentFetcher : MapsFactory::newDefault()->getPageContentFetcher(); - - $this->defaultNamespace = NS_GEO_JSON; - } - - /** - * @param string $fileLocation - * - * @return array - * @throws ParseException - */ - public function parse( $fileLocation ) { - $jsonString = $this->getJsonString( $fileLocation ); - - if ( $jsonString === null ) { - return []; - } - - $json = json_decode( $jsonString, true ); - - if ( $json === null ) { - return []; - } - - return $json; - } - - private function getJsonString( string $fileLocation ): ?string { - $content = $this->pageContentFetcher->getPageContent( $fileLocation, $this->defaultNamespace ); - - if ( $content instanceof \JsonContent ) { - return $content->getNativeData(); - } - - // Prevent reading JSON files on the server - if( !filter_var( $fileLocation, FILTER_VALIDATE_URL) ) { - return null; - } - - try { - return $this->fileFetcher->fetchFile( $fileLocation ); - } - catch ( FileFetchingException $ex ) { - return null; - } - } - - -} |