isHeaderRetorno() public static method

Valida se o header é de um arquivo retorno valido, 240 ou 400 posicoes
public static isHeaderRetorno ( $header ) : boolean
$header
return boolean
Example #1
0
 /**
  * @param $file
  *
  * @return Retorno
  * @throws \Exception
  */
 public static function make($file)
 {
     if ($file == '') {
         throw new \Exception("file url is required.");
     } elseif (file_exists($file)) {
         $file_content = file($file);
     } elseif (is_string($file)) {
         $file_content = explode(PHP_EOL, $file);
     } else {
         throw new \Exception("Arquivo: {$file}, não existe");
     }
     if (!Util::isHeaderRetorno($file_content[0])) {
         throw new \Exception("Arquivo: {$file}, não é um arquivo de retorno");
     }
     $instancia = self::getBancoClass($file_content);
     return $instancia->processar();
 }
 /**
  *
  * @param String $file
  * @throws \Exception
  */
 public function __construct($file)
 {
     $this->_position = 0;
     if (is_array($file) && is_string($file[0])) {
         $this->file = $file;
     } elseif (is_array($file) && is_array($file[0]) && count($file[0]) == 400) {
         $this->file = $file;
     } elseif (is_file($file) && file_exists($file)) {
         $this->file = file($file);
     } elseif (is_string($file)) {
         $this->file = preg_split('/\\r\\n|\\r|\\n/', $file);
         if (empty(end($this->file))) {
             array_pop($this->file);
         }
         reset($this->file);
     } else {
         throw new \Exception("Arquivo: não existe");
     }
     $r = new \ReflectionClass('\\Eduardokum\\LaravelBoleto\\Contracts\\Boleto\\Boleto');
     $constantNames = $r->getConstants();
     $bancosDisponiveis = [];
     foreach ($constantNames as $constantName => $codigoBanco) {
         if (preg_match('/^COD_BANCO.*/', $constantName)) {
             $bancosDisponiveis[] = $codigoBanco;
         }
     }
     if (!Util::isHeaderRetorno($this->file[0])) {
         throw new \Exception(sprintf("Arquivo de retorno inválido"));
     }
     $banco = Util::isCnab400($this->file[0]) ? substr($this->file[0], 76, 3) : substr($this->file[0], 0, 3);
     if (!in_array($banco, $bancosDisponiveis)) {
         throw new \Exception(sprintf("Banco: %s, inválido", $banco));
     }
 }