Skip to content

Commit

Permalink
Merge pull request #379 from eliashaeussler/task/valinor-xml
Browse files Browse the repository at this point in the history
[TASK] Use eliashaeussler/valinor-xml to map XML sitemaps
  • Loading branch information
eliashaeussler authored Jun 14, 2024
2 parents f37c5a1 + 8e53d16 commit 85a1ceb
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 317 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"ext-zlib": "*",
"composer-runtime-api": "^2.1",
"cuyz/valinor": "^1.3",
"eliashaeussler/valinor-xml": "^1.0",
"guzzlehttp/guzzle": "^7.0",
"guzzlehttp/promises": "^1.0 || ^2.0",
"guzzlehttp/psr7": "^2.0",
"mtownsend/xml-to-array": "^2.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/log": "^2.0 || ^3.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
Expand Down
57 changes: 56 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/CacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace EliasHaeussler\CacheWarmup;

use EliasHaeussler\ValinorXml;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
Expand Down Expand Up @@ -99,10 +100,12 @@ public function run(): Result\CacheWarmupResult
* @throws Exception\FileIsMissing
* @throws Exception\SitemapIsInvalid
* @throws Exception\UrlIsEmpty
* @throws Exception\XmlIsMalformed
* @throws Exception\SitemapCannotBeParsed
* @throws Exception\UrlIsInvalid
* @throws GuzzleException
* @throws ValinorXml\Exception\ArrayPathHasUnexpectedType
* @throws ValinorXml\Exception\ArrayPathIsInvalid
* @throws ValinorXml\Exception\XmlIsMalformed
*/
public function addSitemaps(array|string|Sitemap\Sitemap $sitemaps): self
{
Expand Down Expand Up @@ -138,7 +141,7 @@ public function addSitemaps(array|string|Sitemap\Sitemap $sitemaps): self
// Parse sitemap object
try {
$result = $this->parser->parse($sitemap);
} catch (GuzzleException|Exception\FileIsMissing|Exception\SitemapCannotBeParsed|Exception\XmlIsMalformed $exception) {
} catch (GuzzleException|Exception\FileIsMissing|Exception\SitemapCannotBeParsed|ValinorXml\Exception\Exception $exception) {
// Exit early if running in strict mode
if ($this->strict) {
throw $exception;
Expand Down
48 changes: 0 additions & 48 deletions src/Exception/XmlIsMalformed.php

This file was deleted.

95 changes: 0 additions & 95 deletions src/Mapper/Source/XmlSource.php

This file was deleted.

8 changes: 5 additions & 3 deletions src/Xml/XmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
use CuyZ\Valinor;
use DateTimeInterface;
use EliasHaeussler\CacheWarmup\Exception;
use EliasHaeussler\CacheWarmup\Mapper;
use EliasHaeussler\CacheWarmup\Result;
use EliasHaeussler\CacheWarmup\Sitemap;
use EliasHaeussler\ValinorXml;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
Expand Down Expand Up @@ -60,9 +60,11 @@ public function __construct(

/**
* @throws Exception\FileIsMissing
* @throws Exception\XmlIsMalformed
* @throws Exception\SitemapCannotBeParsed
* @throws GuzzleException
* @throws ValinorXml\Exception\ArrayPathHasUnexpectedType
* @throws ValinorXml\Exception\ArrayPathIsInvalid
* @throws ValinorXml\Exception\XmlIsMalformed
*/
public function parse(Sitemap\Sitemap $sitemap): Result\ParserResult
{
Expand All @@ -81,7 +83,7 @@ public function parse(Sitemap\Sitemap $sitemap): Result\ParserResult
}

// Initialize XML source
$xml = Mapper\Source\XmlSource::fromXml($contents)
$xml = ValinorXml\Mapper\Source\XmlSource::fromXmlString($contents)
->asCollection('sitemap')
->asCollection('url');
$source = Valinor\Mapper\Source\Source::iterable($xml)->map([
Expand Down
46 changes: 0 additions & 46 deletions tests/unit/Exception/XmlIsMalformedTest.php

This file was deleted.

Loading

0 comments on commit 85a1ceb

Please sign in to comment.