/** * __construct * @param string $configJson * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ public function __construct($configJson = '') { if ($configJson == '') { $msg = 'O arquivo de configuração no formato JSON deve ser passado para a classe.'; throw new Exception\InvalidArgumentException($msg); } if (is_file($configJson)) { $configJson = Files\FilesFolders::readFile($configJson); } //carrega os dados de configuração $this->aConfig = (array) json_decode($configJson); $this->aDocFormat = (array) $this->aConfig['aDocFormat']; $this->aProxyConf = (array) $this->aConfig['aProxyConf']; $this->aMailConf = (array) $this->aConfig['aMailConf']; //seta o timezone DateTime::tzdBR($this->aConfig['siglaUF']); //carrega os certificados $this->oCertificate = new Pkcs12($this->aConfig['pathCertsFiles'], $this->aConfig['cnpj']); if ($this->oCertificate->priKey == '') { //tentar carregar novo certificado $this->atualizaCertificado($this->aConfig['pathCertsFiles'] . $this->aConfig['certPfxName'], $this->aConfig['certPassword']); if ($this->oCertificate->expireTimestamp == 0) { $msg = 'Não existe certificado válido disponível. Atualize o Certificado.'; throw new Exception\RuntimeException($msg); } } $this->setAmbiente($this->aConfig['tpAmb']); $this->certExpireTimestamp = $this->oCertificate->expireTimestamp; $this->zLoadSoapClass(); //verifica se a contingência está ativada $pathContingencia = NFEPHP_ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $this->aConfig['cnpj'] . '_contingencia.json'; if (is_file($pathContingencia)) { $contJson = Files\FilesFolders::readFile($pathContingencia); if (!empty($contJson)) { $aCont = (array) json_decode($contJson); $this->motivoContingencia = $aCont['motivo']; $this->tsContingencia = $aCont['ts']; $this->enableSVCAN = $aCont['SVCAN']; $this->enableSVCRS = $aCont['SVCRS']; } } }
/** * @dataProvider siglasNaoExistentes */ public function testTZDSiglaNaoExistente($uf) { $this->assertEmpty(DateTime::tzdBR($uf)); }
/** * __construct * * @param string $configJson * @param bool $ignore default false usado para testes apenas * @throws InvalidArgumentException * @throws RuntimeException */ public function __construct($configJson = '', $ignore = false) { if ($configJson == '') { $msg = 'O arquivo de configuração no formato JSON deve ser passado para a classe.'; throw new InvalidArgumentException($msg); } if (is_file($configJson)) { $configJson = Files\FilesFolders::readFile($configJson); } //carrega os dados de configuração $this->aConfig = (array) json_decode($configJson, true); $this->aProxyConf = (array) $this->aConfig['aProxyConf']; $this->verAplic = $this->aConfig['verAplic']; //seta o timezone DateTime::tzdBR($this->aConfig['siglaUF']); //carrega os certificados $this->oCertificate = new Pkcs12($this->aConfig['pathCertsFiles'], $this->aConfig['cnpj'], '', '', '', $ignore); $timestampnow = gmmktime(0, 0, 0, date("m"), date("d"), date("Y")); if ($this->oCertificate->expireTimestamp == 0 || $this->oCertificate->expireTimestamp < $timestampnow) { //tentar carregar novo certificado $this->atualizaCertificado($this->aConfig['pathCertsFiles'] . $this->aConfig['certPfxName'], $this->aConfig['certPassword']); if ($this->oCertificate->expireTimestamp == 0 || $this->oCertificate->expireTimestamp < $timestampnow) { $msg = 'Não existe certificado válido disponível. Atualize o Certificado.'; throw new RuntimeException($msg); } } $this->setAmbiente($this->aConfig['tpAmb']); $this->certExpireTimestamp = $this->oCertificate->expireTimestamp; $this->certExpireDate = date('d/m/Y', $this->certExpireTimestamp); $this->loadSoapClass(); }
public function testConvertTimestampToSefazTime() { DateTime::tzdBR('CE'); $seft = DateTime::convertTimestampToSefazTime($this->tstp); $this->assertEquals($seft, $this->sefTime); }