-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralisation of profile recognition
- Loading branch information
HorstOeko
committed
Jan 7, 2024
1 parent
25c91f2
commit 23dcbda
Showing
9 changed files
with
373 additions
and
63 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
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
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
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,111 @@ | ||
<?php | ||
|
||
/** | ||
* This file is a part of horstoeko/orderx. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace horstoeko\orderx; | ||
|
||
use Exception; | ||
use horstoeko\orderx\exception\OrderCannotFindProfileString; | ||
use horstoeko\orderx\exception\OrderUnknownProfileException; | ||
use horstoeko\orderx\OrderProfiles; | ||
use SimpleXMLElement; | ||
|
||
/** | ||
* Class representing the profile resolver | ||
* | ||
* @category Order-X | ||
* @package Order-X | ||
* @author D. Erling <horstoeko@erling.com.de> | ||
* @license https://opensource.org/licenses/MIT MIT | ||
* @link https://github.com/horstoeko/orderx | ||
*/ | ||
class OrderProfileResolver | ||
{ | ||
/** | ||
* Resolve profile id and profile definition by the content of $xmlContent | ||
* | ||
* @param string $xmlContent | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public static function resolve(string $xmlContent): array | ||
{ | ||
$xmldocument = new SimpleXMLElement($xmlContent); | ||
$typeelement = $xmldocument->xpath('/rsm:SCRDMCCBDACIOMessageStructure/rsm:ExchangedDocumentContext/ram:GuidelineSpecifiedDocumentContextParameter/ram:ID'); | ||
|
||
if (!is_array($typeelement) || !isset($typeelement[0])) { | ||
throw new OrderCannotFindProfileString(); | ||
} | ||
|
||
/** | ||
* @var int $profile | ||
* @var array $profiledef | ||
*/ | ||
foreach (OrderProfiles::PROFILEDEF as $profile => $profiledef) { | ||
if ($typeelement[0] == $profiledef["contextparameter"]) { | ||
return [$profile, $profiledef]; | ||
} | ||
} | ||
|
||
throw new OrderUnknownProfileException((string)$typeelement[0]); | ||
} | ||
|
||
/** | ||
* Resolve profile id by the content of $xmlContent | ||
* | ||
* @param string $xmlContent | ||
* @return int | ||
* @throws Exception | ||
*/ | ||
public static function resolveProfileId(string $xmlContent): int | ||
{ | ||
return static::resolve($xmlContent)[0]; | ||
} | ||
|
||
/** | ||
* Resolve profile definition by the content of $xmlContent | ||
* | ||
* @param string $xmlContent | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public static function resolveProfileDef(string $xmlContent): array | ||
{ | ||
return static::resolve($xmlContent)[1]; | ||
} | ||
|
||
/** | ||
* Resolve profile id and profile definition by it's id | ||
* | ||
* @param integer $profileId | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public static function resolveById(int $profileId): array | ||
{ | ||
if (!isset(OrderProfiles::PROFILEDEF[$profileId])) { | ||
throw new Exception('Could not determine the profile...'); | ||
} | ||
|
||
return [$profileId, OrderProfiles::PROFILEDEF[$profileId]]; | ||
} | ||
|
||
/** | ||
* Resolve profile profile definition by it's id | ||
* | ||
* @param int $profileId | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public static function resolveProfileDefById(int $profileId): array | ||
{ | ||
$resolved = static::resolveById($profileId); | ||
|
||
return $resolved[1]; | ||
} | ||
} |
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
Oops, something went wrong.