-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 8c16121.
- Loading branch information
Andrea Pollastri
committed
Nov 13, 2023
1 parent
ebbed0a
commit 901c36d
Showing
27 changed files
with
95 additions
and
393 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
vendor | ||
composer.lock | ||
.phpunit.result.cache | ||
.php-cs-fixer.cache | ||
.phpunit.result.cache |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Abstracts; | ||
|
||
use Axiostudio\FatturaElettronica\Contracts\Model as ModelInterface; | ||
|
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 |
---|---|---|
@@ -1,17 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Contracts; | ||
|
||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
|
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 |
---|---|---|
@@ -1,51 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica; | ||
|
||
use Axiostudio\FatturaElettronica\Handlers\Model as ModelHandler; | ||
use Axiostudio\FatturaElettronica\Handlers\Xml as XmlHandler; | ||
use Axiostudio\FatturaElettronica\Handlers\XmlDatiBeniServizi as DatiBeniServiziHandler; | ||
use Axiostudio\FatturaElettronica\Handlers\Model as ModelHandler; | ||
use Axiostudio\FatturaElettronica\Models\FatturaElettronica as Fattura; | ||
|
||
class FatturaElettronica | ||
{ | ||
use DatiBeniServiziHandler; | ||
use ModelHandler; | ||
use XmlHandler; | ||
|
||
public function compose( | ||
array $FatturaElettronicaHeader, | ||
array $FatturaElettronicaBody, | ||
array $DettaglioLinee, | ||
array $DatiRiepilogo | ||
): array { | ||
return $this->create( | ||
$FatturaElettronicaHeader, | ||
$FatturaElettronicaBody, | ||
$DettaglioLinee, | ||
$DatiRiepilogo | ||
); | ||
} | ||
use DatiBeniServiziHandler; | ||
|
||
protected function fileName($header): string | ||
{ | ||
$idPaese = (\is_array($header[0][0]) && isset($header[0][0][1])) ? $header[0][0][1] : Settings::IdPaeseDefault(); | ||
$idCodice = (\is_array($header[0][0])) ? $header[0][0][0] : $header[0][0]; | ||
$idPaese = (is_array($header[0][0]) && isset($header[0][0][1])) ? $header[0][0][1] : Settings::IdPaeseDefault(); | ||
$idCodice = (is_array($header[0][0])) ? $header[0][0][0] : $header[0][0]; | ||
$progressivoInvio = $header[0][1]; | ||
|
||
return $idPaese.$idCodice.'_'.$progressivoInvio.'.xml'; | ||
return $idPaese . $idCodice . '_' . $progressivoInvio . '.xml'; | ||
} | ||
|
||
protected function fileContent($header, $body): string | ||
|
@@ -61,12 +35,27 @@ protected function create( | |
array $DettaglioLinee, | ||
array $DatiRiepilogo | ||
): array { | ||
|
||
$xmlContent = $this->fileContent($FatturaElettronicaHeader, $FatturaElettronicaBody); | ||
$xmlContent = $this->addDatiBeniServiziToXml($xmlContent, $DettaglioLinee, $DatiRiepilogo); | ||
|
||
return [ | ||
'fileContent' => $xmlContent, | ||
'fileName' => $this->fileName($FatturaElettronicaHeader), | ||
'fileName' => $this->fileName($FatturaElettronicaHeader) | ||
]; | ||
} | ||
|
||
public function compose( | ||
array $FatturaElettronicaHeader, | ||
array $FatturaElettronicaBody, | ||
array $DettaglioLinee, | ||
array $DatiRiepilogo | ||
): array { | ||
return $this->create( | ||
$FatturaElettronicaHeader, | ||
$FatturaElettronicaBody, | ||
$DettaglioLinee, | ||
$DatiRiepilogo | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,36 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Handlers; | ||
|
||
use Axiostudio\FatturaElettronica\Contracts\Model as ModelInterface; | ||
use Symfony\Component\Validator\Validation; | ||
use Axiostudio\FatturaElettronica\Contracts\Model as ModelInterface; | ||
|
||
trait Model | ||
{ | ||
public function createModel(ModelInterface $model, bool $toArray = false): array|ModelInterface | ||
{ | ||
$validator = Validation::createValidatorBuilder() | ||
->addMethodMapping('loadValidatorMetadata') | ||
->getValidator() | ||
; | ||
->getValidator(); | ||
|
||
$errors = $validator->validate($model); | ||
|
||
if (\count($errors) > 0) { | ||
if (count($errors) > 0) { | ||
$errorsString = (string) $errors; | ||
|
||
throw new \Exception($errorsString); | ||
} | ||
|
||
|
@@ -45,4 +31,4 @@ protected function modelToArray(ModelInterface $model): array | |
{ | ||
return json_decode(json_encode($model), true); | ||
} | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,21 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Handlers; | ||
|
||
use Axiostudio\FatturaElettronica\Settings; | ||
use Spatie\ArrayToXml\ArrayToXml; | ||
use Axiostudio\FatturaElettronica\Settings; | ||
|
||
trait Xml | ||
{ | ||
|
@@ -26,26 +14,28 @@ public function createXml(array $array): string | |
return $this->updateXml($xml); | ||
} | ||
|
||
public function createXmlBlock(array $array): string | ||
protected function updateXml(string $xml): string | ||
{ | ||
$xml = ArrayToXml::convert($array); | ||
$xml = str_replace('<?xml version="1.0"?>', Settings::XmlStart(), $xml); | ||
$xml = str_replace('<root>', '', $xml); | ||
$xml = str_replace('</root>', Settings::XmlEnd(), $xml); | ||
|
||
return $this->updateXmlBlock($xml); | ||
return $xml; | ||
} | ||
|
||
protected function updateXml(string $xml): string | ||
public function createXmlBlock(array $array): string | ||
{ | ||
$xml = str_replace('<?xml version="1.0"?>', Settings::XmlStart(), $xml); | ||
$xml = str_replace('<root>', '', $xml); | ||
$xml = ArrayToXml::convert($array); | ||
|
||
return str_replace('</root>', Settings::XmlEnd(), $xml); | ||
return $this->updateXmlBlock($xml); | ||
} | ||
|
||
protected function updateXmlBlock(string $xml): string | ||
{ | ||
$xml = str_replace('<?xml version="1.0"?>', '', $xml); | ||
$xml = str_replace('<root>', '', $xml); | ||
$xml = str_replace('</root>', '', $xml); | ||
|
||
return str_replace('</root>', '', $xml); | ||
return $xml; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,26 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Handlers; | ||
|
||
use Axiostudio\FatturaElettronica\Handlers\Xml; | ||
use Axiostudio\FatturaElettronica\Handlers\Model; | ||
use Axiostudio\FatturaElettronica\Models\DatiRiepilogo; | ||
use Axiostudio\FatturaElettronica\Models\DettaglioLinee; | ||
|
||
trait XmlDatiBeniServizi | ||
{ | ||
use Model; | ||
use Xml; | ||
use Model; | ||
|
||
public function addDatiBeniServiziToXml(string $Xml, array $DettaglioLinee = [], array $DatiRiepilogo = []): string | ||
{ | ||
|
@@ -29,16 +19,18 @@ public function addDatiBeniServiziToXml(string $Xml, array $DettaglioLinee = [], | |
foreach ($DettaglioLinee as $numero => $linea) { | ||
$data = $this->createModel(new DettaglioLinee(...$linea), true); | ||
$data['NumeroLinea'] = $numero + 1; | ||
$DettaglioLineeBlock .= '<DettaglioLinee>'.$this->createXmlBlock($data).'</DettaglioLinee>'; | ||
$DettaglioLineeBlock .= '<DettaglioLinee>' . $this->createXmlBlock($data) . '</DettaglioLinee>'; | ||
} | ||
|
||
$DatiRiepilogoBlock = ''; | ||
|
||
foreach ($DatiRiepilogo as $dato) { | ||
$data = $this->createModel(new DatiRiepilogo(...$dato), true); | ||
$DatiRiepilogoBlock .= '<DatiRiepilogo>'.$this->createXmlBlock($data).'</DatiRiepilogo>'; | ||
$DatiRiepilogoBlock .= '<DatiRiepilogo>' . $this->createXmlBlock($data) . '</DatiRiepilogo>'; | ||
} | ||
|
||
return str_replace('<XmlDatiBeniServizi></XmlDatiBeniServizi>', $DettaglioLineeBlock.$DatiRiepilogoBlock, $Xml); | ||
$xml = str_replace('<XmlDatiBeniServizi></XmlDatiBeniServizi>', $DettaglioLineeBlock . $DatiRiepilogoBlock, $Xml); | ||
|
||
return $xml; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Models; | ||
|
||
use Axiostudio\FatturaElettronica\Abstracts\Model; | ||
|
@@ -38,5 +26,8 @@ public function __construct(...$args) | |
} | ||
} | ||
|
||
public static function loadValidatorMetadata(ClassMetadata $metadata): void {} | ||
public static function loadValidatorMetadata(ClassMetadata $metadata): void | ||
{ | ||
// | ||
} | ||
} |
Oops, something went wrong.