| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Created by PhpStorm. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * User: Administrador | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Date: 20/07/2017 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Time: 04:06 PM. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Greenter\Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Greenter\Builder\BuilderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Greenter\Model\DocumentInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Greenter\Model\Response\BaseResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Greenter\Services\SenderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Greenter\XMLSecLibs\Sunat\SignedXml; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * Class FeFactory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | class FeFactory implements FactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @var SignedXml | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private $signer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * Sender service. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @var SenderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     private $sender; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * Ultimo xml generado. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     private $lastXml; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * Xml Builder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @var BuilderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     private $builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * Get document builder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @return BuilderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |     public function getBuilder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 2 |  |         return $this->builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * Get sender service. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @return SenderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 2 |  |     public function getSender() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 2 |  |         return $this->sender; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * Set sender service. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @param SenderInterface $sender | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @return FeFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 54 |  |     public function setSender($sender) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 54 |  |         $this->sender = $sender; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 54 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * Set document builder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param BuilderInterface $builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @return FeFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 68 |  |     public function setBuilder($builder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 68 |  |         $this->builder = $builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 68 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @return SignedXml | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 2 |  |     public function getSigner() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 2 |  |         return $this->signer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @param SignedXml $signer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @return FeFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 78 |  |     public function setSigner($signer) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 78 |  |         $this->signer = $signer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 78 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * Build and send document. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * @param DocumentInterface $document | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * @return BaseResult | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 54 |  |     public function send(DocumentInterface $document) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 54 |  |         $this->lastXml = $this->getXmlSigned($document); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 54 |  |         return $this->sender->send($document->getName(), $this->lastXml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     // by thefantas | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     public function sendForce(DocumentInterface $document, $dir_xml) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return $this->sender->send($document->getName(), $dir_xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 136 |  |  |     // by thefantas | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |     public function genXML(DocumentInterface $document) | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |         $this->lastXml = $this->getXmmlSigned($document); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      * Get Last XML Signed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 12 |  |     public function getLastXml() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 12 |  |         return $this->lastXml; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @param DocumentInterface $document | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 68 |  |     public function getXmlSigned(DocumentInterface $document) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 68 |  |         $xml = $this->builder->build($document); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 | 68 |  |         return $this->signer->signXml($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 163 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 164 |  |  |  | 
            
                        
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.