✏️ 正在编辑: Service.php
路径:
/srv/systems_dir/yuppiecred/application/services/Remessa/Service.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Zend_Controller_Request_Abstract as Request; use Service_Exception_ActionDomainException as ActionDomainException; class Service_Remessa_Service { /** @var string */ private const ERRO = 'Ocorreu um problema inesperado na geração da remessa!', NAO_PERMITIDO = 'Acesso não permitido!', CAMPOS_INVALIDOS = 'Preencha todos os campos!' ; /** @var string */ private const ACTION = 'quitar-protocolos', CONTROLLER = 'financeiro' ; /** * @param Request $request * @return Request */ public function validarPost(Request $request): Request { if (!$request->isPost()) { throw new ActionDomainException(self::ACTION, self::CONTROLLER, self::NAO_PERMITIDO); } return $request; } /** * @param Form_Filtro_Remessa $form * @param Zend_Controller_Request_Abstract $request * @return Form_Filtro_Remessa * @throws Zend_Form_Exception */ public function validarForm(Form_Filtro_Remessa $form, Request $request) { if (!$form->isValid($request->getPost())) { throw new ActionDomainException(self::ACTION, self::CONTROLLER, self::CAMPOS_INVALIDOS); } return $form; } /** * @param int $conta * @return Zend_Db_Table_Row_Abstract */ public function validarConta(int $conta): Zend_Db_Table_Row_Abstract { $conta = (new Model_Conta())->exibir($conta); if (!$conta) { throw new ActionDomainException(self::ACTION, self::CONTROLLER, self::CAMPOS_INVALIDOS); } return $conta; } /** * @param $arquivoRemessa * @return bool */ public function isClassRemessaValida($arquivoRemessa): bool { return !empty($arquivoRemessa) && $arquivoRemessa instanceof Core_Banco_Remessa ; } /** * @param Form_Filtro_Remessa $form * @return Core_Banco_Remessa * @throws Core_Exception */ public function validarRemessa(Form_Filtro_Remessa $form): Core_Banco_Remessa { $arquivoRemessa = Core_Banco_Remessa::factory( unserialize($form->getValue("protocolos")), $this->validarConta($form->getValue('conta_id')), $form->getValue('tipo_transferencia'), $form->getValue('data_pagamento') ); if (!$this->isClassRemessaValida($arquivoRemessa)) { throw new ActionDomainException(self::ACTION, self::CONTROLLER, self::ERRO); } return $arquivoRemessa; } /** * @param Core_Banco_Remessa $arquivoRemessa * @return string * @throws Exception */ public function validarArquivo(Core_Banco_Remessa $arquivoRemessa): string { $arquivo = $arquivoRemessa->gerar(); if (empty($arquivo)) { throw new ActionDomainException(self::ACTION, self::CONTROLLER, self::ERRO); } return $arquivo; } /** * @param Core_Banco_Remessa $arquivoRemessa * @return string */ public function getRemessaFileName(Core_Banco_Remessa $arquivoRemessa): string { return $arquivoRemessa->getFileNameDownload(); } /** * @param string $arquivo * @param Core_Banco_Remessa $arquivoRemessa */ public function downloadArquivo(string $arquivo, Core_Banco_Remessa $arquivoRemessa): string { header('Content-disposition: attachment; filename=' . $this->getRemessaFileName($arquivoRemessa)); header('Content-type: text/plain'); return $arquivo; } /** * @param Zend_Controller_Request_Abstract $request * @return string * @throws Core_Exception * @throws Zend_Form_Exception */ public function arquivoRemessa(Request $request): string { $request = $this->validarPost($request); $form = $this->validarForm(new Form_Filtro_Remessa(), $request); $arquivoRemessa = $this->validarRemessa($form); $arquivo = $this->validarArquivo($arquivoRemessa); return $this->downloadArquivo($arquivo, $arquivoRemessa); } }
💾 保存文件
← 返回文件管理器