-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from giansalex/feature/path-resolver
XSD Resolver
- Loading branch information
Showing
27 changed files
with
549 additions
and
237 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Soporte | ||
* Date: 25/10/2018 | ||
* Time: 10:39 | ||
*/ | ||
|
||
namespace Greenter\Ubl\Resolver; | ||
|
||
/** | ||
* Interface PathResolverInterface | ||
*/ | ||
interface PathResolverInterface | ||
{ | ||
/** | ||
* Get Path XSD. | ||
* | ||
* @param \DOMDocument $document | ||
* @return string|null | ||
*/ | ||
function getPath(\DOMDocument $document); | ||
} |
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,71 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Soporte | ||
* Date: 25/10/2018 | ||
* Time: 12:13 | ||
*/ | ||
|
||
namespace Greenter\Ubl\Resolver; | ||
|
||
/** | ||
* Class UblPathResolver | ||
* @package Greenter\Ubl\Resolver | ||
*/ | ||
class UblPathResolver implements PathResolverInterface | ||
{ | ||
const XSD_EXTENSION = '.xsd'; | ||
|
||
/** | ||
* UBL Version. | ||
* | ||
* @var string | ||
*/ | ||
public $version; | ||
|
||
/** | ||
* @var VersionResolverInterface | ||
*/ | ||
public $versionResolver; | ||
|
||
/** | ||
* Base XSD Directory | ||
* | ||
* @var string | ||
*/ | ||
public $baseDirectory; | ||
|
||
/** | ||
* Get Path XSD. | ||
* | ||
* @param \DOMDocument $document | ||
* @return string|null | ||
*/ | ||
function getPath(\DOMDocument $document) | ||
{ | ||
$name = $document->documentElement->localName; | ||
if (empty($this->version)) { | ||
$this->loadVersion($document); | ||
} | ||
$path = $this->getFullPath($name); | ||
|
||
return $path; | ||
} | ||
|
||
private function getFullPath($name) | ||
{ | ||
$filename = 'UBL-'.$name.'-'.$this->version.self::XSD_EXTENSION; | ||
$path = join(DIRECTORY_SEPARATOR, [$this->baseDirectory, $this->version, 'maindoc', $filename]); | ||
|
||
return $path; | ||
} | ||
|
||
private function loadVersion(\DOMDocument $document) | ||
{ | ||
if (!$this->versionResolver) { | ||
$this->versionResolver = new UblVersionResolver(); | ||
} | ||
|
||
$this->version = $this->versionResolver->getVersion($document); | ||
} | ||
} |
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
Oops, something went wrong.