Example #1
0
 public function __construct($filename)
 {
     if (!file_exists($filename)) {
         throw new \Exception("Arquivo '{$filename}' não encontrado");
     }
     $this->conteudo = file_get_contents($filename);
     $linhas = file($filename);
     $lastDetalheRO = null;
     if (ArquivoValidator::validate($filename)) {
         foreach ($linhas as $linha) {
             switch ($linha[0]) {
                 case self::TIPO_HEADER:
                     $this->header = new Header($linha);
                     break;
                 case self::TIPO_TRAILER:
                     $this->trailer = new Trailer($linha);
                     break;
                 case self::TIPO_DETALHE_RO:
                     $lastDetalheRO = new DetalheRO($linha);
                     $this->detalhesRO[] = $lastDetalheRO;
                     break;
                 case self::TIPO_DETALHE_CV:
                     $lastDetalheRO->addDetalheCV(new DetalheCV($linha));
                     break;
                 case self::TIPO_DETALHE_ANTECIPACAO:
                     $this->detalhe_antecipacao = new DetalheAntecipacao($linha);
                     break;
                 case self::TIPO_DETALHE_RO_ANTECIPADO:
                     $lastDetalheRO = new DetalheROAntecipacao($linha);
                     $this->detalhesRO[] = $lastDetalheRO;
                     break;
                 default:
                     throw new \Exception("Arquivo com tipo não conhecido: {$linha[0]}");
                     break;
             }
         }
     }
 }
 public function testArquivoValidatorValido()
 {
     $resultado = ArquivoValidator::validate('tests/fixtures/PagamentoComCV/valido.cmp');
     $this->assertEquals(true, $resultado);
 }