Skip to content

Commit

Permalink
#25 Centralisation of profile recognition -> Using ZugferdProfileReso…
Browse files Browse the repository at this point in the history
…lver in ZugferdDocumentPdfMerger and ZugferdDocumentReader
  • Loading branch information
HorstOeko committed Oct 12, 2023
1 parent 7af4d01 commit e3c1953
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
20 changes: 2 additions & 18 deletions src/ZugferdDocumentPdfMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
namespace horstoeko\zugferd;

use Exception;
use SimpleXMLElement;
use horstoeko\zugferd\ZugferdProfiles;
use horstoeko\zugferd\ZugferdDocumentPdfBuilderAbstract;
use horstoeko\zugferd\ZugferdProfileResolver;

/**
* Class representing the facillity adding existing XML data (file or data-string)
Expand Down Expand Up @@ -121,21 +120,6 @@ private function xmlDataIsFile(): bool
*/
private function getProfileDefinition(): array
{
$xmlContent = $this->getXmlContent();

$xmldocument = new SimpleXMLElement($xmlContent);
$typeelement = $xmldocument->xpath('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:GuidelineSpecifiedDocumentContextParameter/ram:ID');

if (!is_array($typeelement) || !isset($typeelement[0])) {
throw new Exception('Coult not determaine the profile...');
}

foreach (ZugferdProfiles::PROFILEDEF as $profile => $profiledef) {
if ($typeelement[0] == $profiledef["contextparameter"]) {
return $profiledef;
}
}

throw new Exception('Could not determine the profile...');
return ZugferdProfileResolver::resolveProfileDef($this->getXmlContent());
}
}
19 changes: 4 additions & 15 deletions src/ZugferdDocumentReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use \Closure;
use \DateTime;
use \Exception;
use \SimpleXMLElement;
use \horstoeko\stringmanagement\FileUtils;
use \horstoeko\stringmanagement\StringUtils;
use \horstoeko\stringmanagement\PathUtils;
use \horstoeko\stringmanagement\StringUtils;
use \horstoeko\zugferd\ZugferdProfileResolver;

/**
* Class representing the document reader for incoming XML-Documents with
Expand Down Expand Up @@ -242,20 +242,9 @@ public static function readAndGuessFromFile(string $xmlfilename): ZugferdDocumen
*/
public static function readAndGuessFromContent(string $xmlcontent): ZugferdDocumentReader
{
$xmldocument = new SimpleXMLElement($xmlcontent);
$typeelement = $xmldocument->xpath('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:GuidelineSpecifiedDocumentContextParameter/ram:ID');

if (!is_array($typeelement) || !isset($typeelement[0])) {
throw new Exception('Coult not determaine the profile...');
}

foreach (ZugferdProfiles::PROFILEDEF as $profile => $profiledef) {
if ($typeelement[0] == $profiledef["contextparameter"]) {
return (new self($profile))->readContent($xmlcontent);
}
}
$profileId = ZugferdProfileResolver::resolveProfileId($xmlcontent);

throw new Exception('Could not determine the profile...');
return (new self($profileId))->readContent($xmlcontent);
}

/**
Expand Down

0 comments on commit e3c1953

Please sign in to comment.