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])) {
$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");
}
if (substr($this->file[0], 142, 1) != '2') {
throw new \Exception(sprintf("Arquivo de retorno inválido"));
}
$r = new \ReflectionClass('\\Eduardokum\\LaravelBoleto\\Contracts\\Cnab\\Cnab');
$constantNames = $r->getConstants();
$bancosDisponiveis = [];
foreach ($constantNames as $constantName => $codigoBanco) {
if (preg_match('/^COD_BANCO.*/', $constantName)) {
$bancosDisponiveis[] = $codigoBanco;
}
}
if (!in_array(substr($this->file[0], 0, 3), $bancosDisponiveis)) {
throw new \Exception(sprintf("Banco: %s, inválido", substr($this->file[0], 76, 3)));
}
$this->header = new Header();
$this->headerLote = new HeaderLote();
$this->trailerLote = new TrailerLote();
$this->trailerArquivo = new TrailerArquivo();
}