-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
290 additions
and
44 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
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,40 @@ | ||
<?php | ||
|
||
namespace CfdiUtils\Cleaner\BeforeLoad; | ||
|
||
class BeforeLoadCleaner implements BeforeLoadCleanerInterface | ||
{ | ||
/** @var BeforeLoadCleanerInterface[] */ | ||
private $cleaners; | ||
|
||
public function __construct(BeforeLoadCleanerInterface ...$cleaners) | ||
{ | ||
if ([] === $cleaners) { | ||
$cleaners = $this->defaultCleaners(); | ||
} | ||
$this->cleaners = $cleaners; | ||
} | ||
|
||
/** @return BeforeLoadCleanerInterface[] */ | ||
public static function defaultCleaners(): array | ||
{ | ||
return [ | ||
new ChangeXmlnsSchemaLocation(), | ||
new RemoveDuplicatedCfdi3Namespace(), | ||
]; | ||
} | ||
|
||
/** @return BeforeLoadCleanerInterface[] */ | ||
public function members(): array | ||
{ | ||
return $this->cleaners; | ||
} | ||
|
||
public function clean(string $content): string | ||
{ | ||
foreach ($this->cleaners as $cleaner) { | ||
$content = $cleaner->clean($content); | ||
} | ||
return $content; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/CfdiUtils/Cleaner/BeforeLoad/BeforeLoadCleanerInterface.php
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,8 @@ | ||
<?php | ||
|
||
namespace CfdiUtils\Cleaner\BeforeLoad; | ||
|
||
interface BeforeLoadCleanerInterface | ||
{ | ||
public function clean(string $content): string; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/CfdiUtils/Cleaner/BeforeLoad/ChangeXmlnsSchemaLocation.php
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,11 @@ | ||
<?php | ||
|
||
namespace CfdiUtils\Cleaner\BeforeLoad; | ||
|
||
class ChangeXmlnsSchemaLocation implements BeforeLoadCleanerInterface | ||
{ | ||
public function clean(string $content): string | ||
{ | ||
return str_replace(' xmlns:schemaLocation="', ' xsi:schemaLocation="', $content); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/CfdiUtils/Cleaner/BeforeLoad/RemoveDuplicatedCfdi3Namespace.php
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,15 @@ | ||
<?php | ||
|
||
namespace CfdiUtils\Cleaner\BeforeLoad; | ||
|
||
class RemoveDuplicatedCfdi3Namespace implements BeforeLoadCleanerInterface | ||
{ | ||
public function clean(string $content): string | ||
{ | ||
if (false !== strpos($content, ' xmlns="http://www.sat.gob.mx/cfd/3"') | ||
&& false !== strpos($content, ' xmlns:cfdi="http://www.sat.gob.mx/cfd/3"')) { | ||
$content = str_replace(' xmlns="http://www.sat.gob.mx/cfd/3"', '', $content); | ||
} | ||
return $content; | ||
} | ||
} |
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.