├── docs ├── requirements.txt ├── manuais │ ├── Manual Cnab 150.pdf │ └── Manual Cnab 240 bb.pdf ├── index.rst ├── events │ ├── plugins-list.rst.inc │ ├── async-plugin.rst │ ├── history-plugin.rst │ ├── mock-plugin.rst │ ├── backoff-plugin.rst │ ├── curl-auth-plugin.rst │ ├── cookie-plugin.rst │ ├── oauth-plugin.rst │ ├── md5-validator-plugin.rst │ ├── plugins-overview.rst │ ├── log-plugin.rst │ └── creating-plugins.rst ├── docs.rst ├── getting-started │ ├── installation.rst │ └── overview.rst ├── component │ ├── uri-templates.rst │ ├── http-redirects.rst │ └── response.rst ├── conf.py └── Makefile ├── src ├── Model │ ├── Cedente.php │ ├── Pessoa.php │ ├── Sacado.php │ ├── Cobranca.php │ ├── Inscricao.php │ ├── Ocorrencia.php │ ├── Endereco.php │ ├── Banco.php │ └── Empresa.php ├── Cnab │ ├── CnabDetailInterface.php │ ├── CnabTrailerInterface.php │ ├── Cnab240 │ │ ├── AbstractTrailer.php │ │ ├── AbstractCnab240.php │ │ ├── Segmento │ │ │ ├── SegmentoInterface.php │ │ │ ├── SegmentoFactory.php │ │ │ ├── SegmentoJ.php │ │ │ ├── AbstractSegmento.php │ │ │ ├── SegmentoT.php │ │ │ └── SegmentoU.php │ │ ├── AbstractHeader.php │ │ ├── Trailer.php │ │ ├── Header.php │ │ ├── TrailerLote.php │ │ ├── HeaderLote.php │ │ └── DadosTitulo.php │ ├── Cnab400 │ │ ├── AbstractCnab400.php │ │ ├── Convenio │ │ │ ├── HeaderConvenioInterface.php │ │ │ ├── HeaderConvenio.php │ │ │ ├── DetailConvenioInterface.php │ │ │ ├── Processor │ │ │ │ ├── CNAB400Conv7Processor.php │ │ │ │ └── CNAB400Conv6Processor.php │ │ │ └── DetailConvenio.php │ │ ├── Bradesco │ │ │ ├── HeaderBradesco.php │ │ │ └── DetailBradesco.php │ │ ├── HeaderInterface.php │ │ ├── TrailerInterface.php │ │ ├── Header.php │ │ ├── Trailer.php │ │ └── DetailInterface.php │ ├── CnabHeaderInterface.php │ ├── Cnab150 │ │ ├── AbstractCnab150.php │ │ ├── Trailer.php │ │ ├── Header.php │ │ └── Detail.php │ ├── ComposableInterface.php │ └── AbstractCnab.php ├── Exception │ ├── EmptyLineException.php │ ├── InvalidHeaderException.php │ ├── InvalidPositionException.php │ ├── DetailSectionNotFoundException.php │ ├── HeaderSectionNotFoundException.php │ └── ReturnFileNotSupportedException.php ├── RetornoEvents.php ├── RetornoInterface.php ├── LoteInterface.php ├── Event │ └── OnDetailRegisterEvent.php ├── ProcessHandler.php ├── Retorno.php ├── Lote.php ├── ProcessFactory.php └── AbstractProcessor.php ├── tests ├── bootstrap.php ├── SegmentosCNAB240 │ ├── SegmentoTTest.php │ ├── SegmentoUTest.php │ └── AbstractSegmentoTestCase.php ├── AbstractCnabTestCase.php ├── Resources │ └── ret │ │ ├── 150 │ │ └── RCB001455608201413819.ret │ │ ├── 240 │ │ ├── 03091405.RET │ │ ├── RETORNOCEF090814.bax │ │ ├── IEDCBR361502201214659.ret │ │ ├── retorno_cnab240.ret │ │ └── RETORNOCEF120814.ret │ │ └── 400 │ │ ├── CBR64302.RET │ │ ├── CBR64303.RET │ │ ├── retorno_cnab400conv6.ret │ │ ├── retorno.ret │ │ ├── CBR64334531308201411115.ret │ │ ├── CB120400.RET │ │ └── retorno-cb030400-bradesco.ret ├── RetornoEventDispatcherTest.php ├── RetornoCNAB150Test.php ├── RetornoCNAB240Test.php └── RetornoCNAB400Test.php ├── .gitignore ├── .travis.yml ├── phpci.yml ├── .scrutinizer.yml ├── LICENSE ├── composer.json ├── phpunit.xml.dist ├── CONTRIBUTING.md └── README.md /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | Sphinx>=1.2b1 2 | -------------------------------------------------------------------------------- /docs/manuais/Manual Cnab 150.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umbrellaTech/ya-retorno-boleto/HEAD/docs/manuais/Manual Cnab 150.pdf -------------------------------------------------------------------------------- /docs/manuais/Manual Cnab 240 bb.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umbrellaTech/ya-retorno-boleto/HEAD/docs/manuais/Manual Cnab 240 bb.pdf -------------------------------------------------------------------------------- /src/Model/Cedente.php: -------------------------------------------------------------------------------- 1 | assertEquals('T', $segmentoTDetail->getSegmento()); 14 | $this->assertTrue(is_double($segmentoTDetail->getValorTarifa())); 15 | } 16 | } -------------------------------------------------------------------------------- /tests/SegmentosCNAB240/SegmentoUTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('U', $segmentoUDetail->getSegmento()); 14 | $this->assertTrue(is_double($segmentoUDetail->getDadosTitulo()->getValorPago())); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Convenio/HeaderConvenioInterface.php: -------------------------------------------------------------------------------- 1 | nome; 18 | } 19 | 20 | public function getBanco() 21 | { 22 | return $this->banco; 23 | } 24 | 25 | /** 26 | * @param string $nome 27 | */ 28 | public function setNome($nome) 29 | { 30 | $this->nome = $nome; 31 | return $this; 32 | } 33 | 34 | public function setBanco(Banco $banco) 35 | { 36 | $this->banco = $banco; 37 | return $this; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/Segmento/SegmentoFactory.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class SegmentoFactory 11 | { 12 | /** 13 | * @param string $tipo O tipo do segmento para carregar os detalhes 14 | * @return SegmentoInterface 15 | */ 16 | public function getDetail($tipo) 17 | { 18 | $reflection = new \ReflectionClass('\Umbrella\Ya\RetornoBoleto\Cnab\Cnab240\Segmento\Segmento' . strtoupper($tipo)); 19 | return $reflection->newInstanceArgs(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Cnab/Cnab150/AbstractCnab150.php: -------------------------------------------------------------------------------- 1 | codBarras; 15 | } 16 | 17 | public function setCodBarras($codBarras) 18 | { 19 | $this->codBarras = $codBarras; 20 | return $this; 21 | } 22 | 23 | public function getFiller() 24 | { 25 | return $this->filler; 26 | } 27 | 28 | public function setFiller($filler) 29 | { 30 | $this->filler = $filler; 31 | return $this; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /docs/events/async-plugin.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Async plugin 3 | ============ 4 | 5 | The AsyncPlugin allows you to send requests that do not wait on a response. This is handled through cURL by utilizing 6 | the progress event. When a request has sent all of its data to the remote server, Guzzle adds a 1ms timeout on the 7 | request and instructs cURL to not download the body of the response. The async plugin then catches the exception and 8 | adds a mock response to the request, along with an X-Guzzle-Async header to let you know that the response was not 9 | fully downloaded. 10 | 11 | .. code-block:: php 12 | 13 | use Guzzle\Http\Client; 14 | use Guzzle\Plugin\Async\AsyncPlugin; 15 | 16 | $client = new Client('http://www.example.com'); 17 | $client->addSubscriber(new AsyncPlugin()); 18 | $response = $client->get()->send(); 19 | -------------------------------------------------------------------------------- /docs/events/history-plugin.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | History plugin 3 | ============== 4 | 5 | The history plugin tracks all of the requests and responses sent through a request or client. This plugin can be 6 | useful for crawling or unit testing. By default, the history plugin stores up to 10 requests and responses. 7 | 8 | .. code-block:: php 9 | 10 | use Guzzle\Http\Client; 11 | use Guzzle\Plugin\History\HistoryPlugin; 12 | 13 | $client = new Client('http://www.test.com/'); 14 | 15 | // Add the history plugin to the client object 16 | $history = new HistoryPlugin(); 17 | $history->setLimit(5); 18 | $client->addSubscriber($history); 19 | 20 | $client->get('http://www.yahoo.com/')->send(); 21 | 22 | echo $history->getLastRequest(); 23 | echo $history->getLastResponse(); 24 | echo count($history); 25 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Convenio/HeaderConvenio.php: -------------------------------------------------------------------------------- 1 | convenio; 15 | } 16 | 17 | public function getSequencialRet() 18 | { 19 | return $this->sequencialRet; 20 | } 21 | 22 | public function setConvenio($convenio) 23 | { 24 | $this->convenio = $convenio; 25 | return $this; 26 | } 27 | 28 | public function setSequencialRet($sequencialRet) 29 | { 30 | $this->sequencialRet = $sequencialRet; 31 | return $this; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/AbstractHeader.php: -------------------------------------------------------------------------------- 1 | convenio; 13 | } 14 | 15 | public function getVersaoLayout() 16 | { 17 | return $this->versaoLayout; 18 | } 19 | 20 | /** 21 | * @param string $convenio 22 | */ 23 | public function setConvenio($convenio) 24 | { 25 | $this->convenio = $convenio; 26 | return $this; 27 | } 28 | 29 | /** 30 | * @param string $versaoLayout 31 | */ 32 | public function setVersaoLayout($versaoLayout) 33 | { 34 | $this->versaoLayout = $versaoLayout; 35 | return $this; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Cnab/Cnab150/Trailer.php: -------------------------------------------------------------------------------- 1 | valorTotal; 15 | } 16 | 17 | public function getQuantidadeRegistros() 18 | { 19 | return $this->quantidadeRegistros; 20 | } 21 | 22 | public function setValorTotal($valorTotal) 23 | { 24 | $this->valorTotal = $valorTotal; 25 | return $this; 26 | } 27 | 28 | public function setQuantidadeRegistros($quantidadeRegistros) 29 | { 30 | $this->quantidadeRegistros = $quantidadeRegistros; 31 | return $this; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | before_commands: 2 | - "composer install --dev --prefer-source" 3 | 4 | tools: 5 | external_code_coverage: true 6 | php_code_sniffer: 7 | enabled: true 8 | config: 9 | standard: PSR2 10 | filter: 11 | paths: ["src/*"] 12 | php_cpd: 13 | enabled: true 14 | excluded_dirs: ["/tests/", "vendor"] 15 | php_cs_fixer: 16 | enabled: false 17 | config: 18 | level: all 19 | filter: 20 | paths: ["src/*", "/tests/*"] 21 | php_loc: 22 | enabled: true 23 | php_mess_detector: 24 | enabled: true 25 | filter: 26 | paths: ["/tests/*"] 27 | php_pdepend: 28 | enabled: true 29 | excluded_dirs: ["/tests/", "vendor"] 30 | php_analyzer: 31 | filter: 32 | paths: ["src/*", "/tests/*"] 33 | sensiolabs_security_checker: true 34 | -------------------------------------------------------------------------------- /docs/events/mock-plugin.rst: -------------------------------------------------------------------------------- 1 | =========== 2 | Mock plugin 3 | =========== 4 | 5 | The mock plugin is useful for testing Guzzle clients. The mock plugin allows you to queue an array of responses that 6 | will satisfy requests sent from a client by consuming the request queue in FIFO order. 7 | 8 | .. code-block:: php 9 | 10 | use Guzzle\Http\Client; 11 | use Guzzle\Plugin\Mock\MockPlugin; 12 | use Guzzle\Http\Message\Response; 13 | 14 | $client = new Client('http://www.test.com/'); 15 | 16 | $mock = new MockPlugin(); 17 | $mock->addResponse(new Response(200)) 18 | ->addResponse(new Response(404)); 19 | 20 | // Add the mock plugin to the client object 21 | $client->addSubscriber($mock); 22 | 23 | // The following request will receive a 200 response from the plugin 24 | $client->get('http://www.example.com/')->send(); 25 | 26 | // The following request will receive a 404 response from the plugin 27 | $client->get('http://www.test.com/')->send(); 28 | -------------------------------------------------------------------------------- /tests/AbstractCnabTestCase.php: -------------------------------------------------------------------------------- 1 | getRegistro() == $self::DETALHE) { 17 | printf("%08d: ", $numLn); 18 | echo get_class($self) . ": Nosso Número " . $composable->getNossoNumero() . " " . 19 | "Data " . $composable->getDataOcorrencia() . " " . 20 | "Valor " . $composable->getValor() . "
\n"; 21 | } 22 | } else { 23 | echo "Tipo da linha não identificado
\n"; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Model/Sacado.php: -------------------------------------------------------------------------------- 1 | inscricao; 23 | } 24 | 25 | /** 26 | * @param Inscricao $inscricao 27 | * @return $this 28 | */ 29 | public function setInscricao(Inscricao $inscricao) 30 | { 31 | $this->inscricao = $inscricao; 32 | return $this; 33 | } 34 | 35 | /** 36 | * @return Ocorrencia 37 | */ 38 | public function getOcorrencia() 39 | { 40 | return $this->ocorrencia; 41 | } 42 | 43 | /** 44 | * @param Ocorrencia $ocorrencia 45 | */ 46 | public function setOcorrencia($ocorrencia) 47 | { 48 | $this->ocorrencia = $ocorrencia; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/Model/Cobranca.php: -------------------------------------------------------------------------------- 1 | qtdTitulos; 14 | } 15 | 16 | public function getValorTotal() 17 | { 18 | return $this->valorTotal; 19 | } 20 | 21 | public function getNumAviso() 22 | { 23 | return $this->numAviso; 24 | } 25 | 26 | /** 27 | * @param string $qtdTitulos 28 | */ 29 | public function setQtdTitulos($qtdTitulos) 30 | { 31 | $this->qtdTitulos = $qtdTitulos; 32 | return $this; 33 | } 34 | 35 | public function setValorTotal($valorTotal) 36 | { 37 | $this->valorTotal = $valorTotal; 38 | return $this; 39 | } 40 | 41 | /** 42 | * @param string $numAviso 43 | */ 44 | public function setNumAviso($numAviso) 45 | { 46 | $this->numAviso = $numAviso; 47 | return $this; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /docs/events/backoff-plugin.rst: -------------------------------------------------------------------------------- 1 | ==================== 2 | Backoff retry plugin 3 | ==================== 4 | 5 | The ``Guzzle\Plugin\Backoff\BackoffPlugin`` automatically retries failed HTTP requests using custom backoff strategies: 6 | 7 | .. code-block:: php 8 | 9 | use Guzzle\Http\Client; 10 | use Guzzle\Plugin\Backoff\BackoffPlugin; 11 | 12 | $client = new Client('http://www.test.com/'); 13 | // Use a static factory method to get a backoff plugin using the exponential backoff strategy 14 | $backoffPlugin = BackoffPlugin::getExponentialBackoff(); 15 | 16 | // Add the backoff plugin to the client object 17 | $client->addSubscriber($backoffPlugin); 18 | 19 | The BackoffPlugin's constructor accepts a ``Guzzle\Plugin\Backoff\BackoffStrategyInterface`` object that is used to 20 | determine when a retry should be issued and how long to delay between retries. The above code example shows how to 21 | attach a BackoffPlugin to a client that is pre-configured to retry failed 500 and 503 responses using truncated 22 | exponential backoff (emulating the behavior of Guzzle 2's ExponentialBackoffPlugin). 23 | -------------------------------------------------------------------------------- /src/Model/Inscricao.php: -------------------------------------------------------------------------------- 1 | numero = $numero; 20 | $this->tipo = $tipo; 21 | } 22 | 23 | /** 24 | * @return int 25 | */ 26 | public function getNumero() 27 | { 28 | return $this->numero; 29 | } 30 | 31 | /** 32 | * @param int $numero 33 | * @return $this 34 | */ 35 | public function setNumero($numero) 36 | { 37 | $this->numero = $numero; 38 | return $this; 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getTipo() 45 | { 46 | return $this->tipo; 47 | } 48 | 49 | /** 50 | * @param string $tipo 51 | * @return $this 52 | */ 53 | public function setTipo($tipo) 54 | { 55 | $this->tipo = $tipo; 56 | return $this; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Umbrella Tech 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/RetornoInterface.php: -------------------------------------------------------------------------------- 1 | setDefaultOption('auth', array('username', 'password', 'Basic|Digest|NTLM|Any')); 13 | 14 | If your web service client requires basic authorization, then you can use the CurlAuthPlugin to easily add an 15 | Authorization header to each request sent by the client. 16 | 17 | .. code-block:: php 18 | 19 | use Guzzle\Http\Client; 20 | use Guzzle\Plugin\CurlAuth\CurlAuthPlugin; 21 | 22 | $client = new Client('http://www.test.com/'); 23 | 24 | // Add the auth plugin to the client object 25 | $authPlugin = new CurlAuthPlugin('username', 'password'); 26 | $client->addSubscriber($authPlugin); 27 | 28 | $response = $client->get('projects/1/people')->send(); 29 | $xml = new SimpleXMLElement($response->getBody(true)); 30 | foreach ($xml->person as $person) { 31 | echo $person->email . "\n"; 32 | } 33 | -------------------------------------------------------------------------------- /tests/Resources/ret/400/CBR64302.RET: -------------------------------------------------------------------------------- 1 | 02RETORNO01COBRANCA 34584003002128180515FUNDACAO DOIS DE JULHO 001BANCO DO BRASIL1904100001985 000001943800112340 000001 2 | 1000000000000000034584003002128180515 18051500017X70000005 019000000 0000000000 1705190410 18051500017X70000005000000000000000015434140780002004100000450000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000035010000000000000 0000000000000000000000000000000000000000000000000010000002 3 | 9201001 000000000000000000000000000972 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000003 4 | -------------------------------------------------------------------------------- /tests/Resources/ret/400/CBR64303.RET: -------------------------------------------------------------------------------- 1 | 02RETORNO01COBRANCA 34584003002128180515FUNDACAO DOIS DE JULHO 001BANCO DO BRASIL2004100001986 000001944800112340 000001 2 | 1000000000000000034584003002128180515 18051500018870000005 019000000 0000000000 1705200410 18051500018870000005000000000000000010023730720002204100000450000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000035010000000000000 0000000000000000000000000000000000000000000000000010000002 3 | 9201001 000000000000000000000000000973 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000003 4 | -------------------------------------------------------------------------------- /docs/events/cookie-plugin.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Cookie plugin 3 | ============= 4 | 5 | Some web services require a Cookie in order to maintain a session. The ``Guzzle\Plugin\Cookie\CookiePlugin`` will add 6 | cookies to requests and parse cookies from responses using a CookieJar object: 7 | 8 | .. code-block:: php 9 | 10 | use Guzzle\Http\Client; 11 | use Guzzle\Plugin\Cookie\CookiePlugin; 12 | use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar; 13 | 14 | $cookiePlugin = new CookiePlugin(new ArrayCookieJar()); 15 | 16 | // Add the cookie plugin to a client 17 | $client = new Client('http://www.test.com/'); 18 | $client->addSubscriber($cookiePlugin); 19 | 20 | // Send the request with no cookies and parse the returned cookies 21 | $client->get('http://www.yahoo.com/')->send(); 22 | 23 | // Send the request again, noticing that cookies are being sent 24 | $request = $client->get('http://www.yahoo.com/'); 25 | $request->send(); 26 | 27 | echo $request; 28 | 29 | You can disable cookies per-request by setting the ``cookies.disable`` value to true on a request's params object. 30 | 31 | .. code-block:: php 32 | 33 | $request->getParams()->set('cookies.disable', true); 34 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "umbrella/retorno-boleto", 3 | "description": "Biblioteca em PHP para leitura de arquivos de retorno de títulos de cobrança de bancos brasileiros.", 4 | "type": "library", 5 | "license": "MIT", 6 | "keywords": [ 7 | "framework", 8 | "vox", 9 | "ya", 10 | "boleto", 11 | "arquivo-retorno" 12 | ], 13 | "authors": [ 14 | { 15 | "name": "Ítalo Lelis de Vietro", 16 | "email": "italolelis@lellysinformatica.com" 17 | } 18 | ], 19 | "require": { 20 | "php": ">=5.3.3", 21 | "easyframework/collections": "~3.1", 22 | "symfony/event-dispatcher": "~2.5", 23 | "danielstjules/stringy": "~1.7" 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit": "~4.2" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "Umbrella\\Ya\\RetornoBoleto\\": "src/" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "Umbrella\\Tests\\Ya\\RetornoBoleto\\": "tests/" 36 | } 37 | }, 38 | "extra": { 39 | "branch-alias": { 40 | "dev-master": "1.5.x-dev" 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /docs/events/oauth-plugin.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | OAuth plugin 3 | ============ 4 | 5 | Guzzle ships with an OAuth 1.0 plugin that can sign requests using a consumer key, consumer secret, OAuth token, 6 | and OAuth secret. Here's an example showing how to send an authenticated request to the Twitter REST API: 7 | 8 | .. code-block:: php 9 | 10 | use Guzzle\Http\Client; 11 | use Guzzle\Plugin\Oauth\OauthPlugin; 12 | 13 | $client = new Client('http://api.twitter.com/1'); 14 | $oauth = new OauthPlugin(array( 15 | 'consumer_key' => 'my_key', 16 | 'consumer_secret' => 'my_secret', 17 | 'token' => 'my_token', 18 | 'token_secret' => 'my_token_secret' 19 | )); 20 | $client->addSubscriber($oauth); 21 | 22 | $response = $client->get('statuses/public_timeline.json')->send(); 23 | 24 | If you need to use a custom signing method, you can pass a ``signature_method`` configuration option in the 25 | constructor of the OAuth plugin. The ``signature_method`` option must be a callable variable that accepts a string to 26 | sign and signing key and returns a signed string. 27 | 28 | .. note:: 29 | 30 | You can omit the ``token`` and ``token_secret`` options to use two-legged OAuth. 31 | -------------------------------------------------------------------------------- /src/LoteInterface.php: -------------------------------------------------------------------------------- 1 | cnabProvider() as $fileName) { 15 | $cnab = ProcessFactory::getRetorno(current($fileName)); 16 | 17 | $processor = new ProcessHandler($cnab); 18 | $retorno = $processor->processar(); 19 | 20 | $lotes = $retorno->getLotes(); 21 | foreach ($lotes->get(0)->getDetails() as $detail) { 22 | if ($detail->getSegmento() == $segmento) { 23 | $segmentos[] = array($detail); 24 | } 25 | } 26 | } 27 | return $segmentos; 28 | } 29 | 30 | public function segmentoTProvider() 31 | { 32 | return $this->segmentoProvider('T'); 33 | } 34 | 35 | public function segmentoUProvider() 36 | { 37 | return $this->segmentoProvider('U'); 38 | } 39 | } -------------------------------------------------------------------------------- /src/Cnab/ComposableInterface.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ./tests/ 22 | 23 | 24 | 25 | 26 | 27 | ./ 28 | 29 | ./tests/ 30 | ./vendor 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/RetornoEventDispatcherTest.php: -------------------------------------------------------------------------------- 1 | getDispatcher()->addListener(RetornoEvents::ON_DETAIL_REGISTER, 32 | function(OnDetailRegisterEvent $event) use($self, &$count) { 33 | $self->assertEquals($event->getLineNumber(), $count); 34 | $count++; 35 | }); 36 | 37 | $retorno = $processor->processar(); 38 | $this->assertNotNull($retorno); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/RetornoCNAB150Test.php: -------------------------------------------------------------------------------- 1 | processar(); 30 | 31 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Retorno", $retorno); 32 | 33 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Cnab\\Cnab150\\Header", $retorno->getHeader()); 34 | 35 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Cnab\\Cnab150\\Trailer", $retorno->getTrailer()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/RetornoCNAB240Test.php: -------------------------------------------------------------------------------- 1 | processar(); 31 | 32 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Retorno", $retorno); 33 | 34 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Cnab\\Cnab240\\Header", 35 | $retorno->getHeader()); 36 | 37 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Cnab\\Cnab240\\Trailer", 38 | $retorno->getTrailer()); 39 | } 40 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/umbrellaTech/ya-retorno-boleto). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | - **Create feature branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. 23 | 24 | 25 | ## Running Tests 26 | 27 | ``` bash 28 | $ phpunit 29 | ``` 30 | 31 | 32 | **Happy coding**! 33 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Bradesco/HeaderBradesco.php: -------------------------------------------------------------------------------- 1 | densidadeGravacao; 28 | } 29 | 30 | public function getNumAvisoBancario() 31 | { 32 | return $this->numAvisoBancario; 33 | } 34 | 35 | public function getDataCredito() 36 | { 37 | return $this->dataCredito; 38 | } 39 | 40 | public function setDensidadeGravacao(DateTime $densidadeGravacao) 41 | { 42 | $this->densidadeGravacao = $densidadeGravacao; 43 | return $this; 44 | } 45 | 46 | public function setNumAvisoBancario($numAvisoBancario) 47 | { 48 | $this->numAvisoBancario = $numAvisoBancario; 49 | return $this; 50 | } 51 | 52 | public function setDataCredito(DateTime $dataCredito) 53 | { 54 | $this->dataCredito = $dataCredito; 55 | return $this; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /docs/events/md5-validator-plugin.rst: -------------------------------------------------------------------------------- 1 | ==================== 2 | MD5 validator plugin 3 | ==================== 4 | 5 | Entity bodies can sometimes be modified over the wire due to a faulty TCP transport or misbehaving proxy. If an HTTP 6 | response contains a Content-MD5 header, then a MD5 hash of the entity body of a response can be compared against the 7 | Content-MD5 header of the response to determine if the response was delivered intact. The 8 | ``Guzzle\Plugin\Md5\Md5ValidatorPlugin`` will throw an ``UnexpectedValueException`` if the calculated MD5 hash does 9 | not match the Content-MD5 header value: 10 | 11 | .. code-block:: php 12 | 13 | use Guzzle\Http\Client; 14 | use Guzzle\Plugin\Md5\Md5ValidatorPlugin; 15 | 16 | $client = new Client('http://www.test.com/'); 17 | 18 | $md5Plugin = new Md5ValidatorPlugin(); 19 | 20 | // Add the md5 plugin to the client object 21 | $client->addSubscriber($md5Plugin); 22 | 23 | $request = $client->get('http://www.yahoo.com/'); 24 | $request->send(); 25 | 26 | Calculating the MD5 hash of a large entity body or an entity body that was transferred using a Content-Encoding is an 27 | expensive operation. When working in high performance applications, you might consider skipping the MD5 hash 28 | validation for entity bodies bigger than a certain size or Content-Encoded entity bodies 29 | (see ``Guzzle\Plugin\Md5\Md5ValidatorPlugin`` for more information). 30 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/Trailer.php: -------------------------------------------------------------------------------- 1 | quantidadeLotes; 16 | } 17 | 18 | public function getQuantidadeRegistros() 19 | { 20 | return $this->quantidadeRegistros; 21 | } 22 | 23 | public function getQuantidadeContasConc() 24 | { 25 | return $this->quantidadeContasConc; 26 | } 27 | 28 | /** 29 | * @param string $quantidadeLotes 30 | */ 31 | public function setQuantidadeLotes($quantidadeLotes) 32 | { 33 | $this->quantidadeLotes = $quantidadeLotes; 34 | return $this; 35 | } 36 | 37 | /** 38 | * @param string $quantidadeRegistros 39 | */ 40 | public function setQuantidadeRegistros($quantidadeRegistros) 41 | { 42 | $this->quantidadeRegistros = $quantidadeRegistros; 43 | return $this; 44 | } 45 | 46 | /** 47 | * @param string $quantidadeContasConc 48 | */ 49 | public function setQuantidadeContasConc($quantidadeContasConc) 50 | { 51 | $this->quantidadeContasConc = $quantidadeContasConc; 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Event/OnDetailRegisterEvent.php: -------------------------------------------------------------------------------- 1 | processor = $processor; 29 | $this->lineNumber = $lineNumber; 30 | $this->composable = $composable; 31 | } 32 | 33 | /** 34 | * Retorna o processador. 35 | * @return AbstractProcessor 36 | */ 37 | public function getProcessor() 38 | { 39 | return $this->processor; 40 | } 41 | 42 | /** 43 | * Retorna a linha do arquivo que está sendo iterada. 44 | * @return int 45 | */ 46 | public function getLineNumber() 47 | { 48 | return $this->lineNumber; 49 | } 50 | 51 | /** 52 | * Retorna o elemento ComposableInterface parseado após o processamento da linha. 53 | * @return ComposableInterface 54 | */ 55 | public function getComposable() 56 | { 57 | return $this->composable; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /docs/getting-started/installation.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Instalação 3 | ============ 4 | 5 | Requisitos 6 | ------------ 7 | 8 | #. PHP 5.3.3+ compilado com a extensão cURL 9 | #. A versão atual do cURL 7.16.2+ compilado com OpenSSL e zlib 10 | 11 | Instalando YA Retorno Boleto 12 | ----------------- 13 | 14 | Composer 15 | ~~~~~~~~ 16 | 17 | A maneira recomendada de instalar YA Retorno Boleto é com o 'Composer `_. Composer é uma 18 | ferramenta de gerenciamento de dependência para PHP que lhe permite declarar as dependências que o seu projeto precisa 19 | e instala-los em seu projeto. 20 | 21 | .. code-block:: bash 22 | 23 | # Install Composer 24 | curl -sS https://getcomposer.org/installer | php 25 | 26 | # Adicionando YA Retorno Boleto como dependencia 27 | php composer.phar require umbrella/retorno-boleto:~1.2 28 | 29 | Após a instalação, é necessário carregar o autoloader do composer: 30 | 31 | .. code-block:: php 32 | 33 | require 'vendor/autoload.php'; 34 | 35 | Você pode encontrar mais informações sobre como instalar o Composer, configurar o carregamento automático, 36 | e outras boas práticas para a definição dependências em `getcomposer.org ` _. 37 | 38 | Mantendo-se atualizado 39 | ^^^^^^^^^^^^^ 40 | 41 | Durante o desenvolvimento, você pode manter-se com as últimas alterações do branch master, definindo a versão 42 | do YA Retorno Boleto para `` dev-master``. 43 | 44 | .. code-block:: js 45 | 46 | { 47 | "require": { 48 | "umbrella/retorno-boleto": "dev-master" 49 | } 50 | } -------------------------------------------------------------------------------- /tests/Resources/ret/400/retorno_cnab400conv6.ret: -------------------------------------------------------------------------------- 1 | 02RETORNO01COBRANCA 34584003002128180515FACULDADE TESTE 001BANCO DO BRASIL0809050000857 000001 2 | 1000000000000000034584003002128180515050001545105100605 18051511267970009090AI 019000000 0000000000 1709080905123456789018051511267970009090100605000000003520000116020120000000000445000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000002 3 | 1000000000000000034584003002128180515050001585105100605 18051511275X70009090AI 019000000 0000000000 1709080905123456789018051511275X70009090100605000000003333000116020120000000000445000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000003 4 | 9201001 000005750000002124451100000582 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000004 5 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/Header.php: -------------------------------------------------------------------------------- 1 | codArquivo; 23 | } 24 | 25 | public function getDensidade() 26 | { 27 | return $this->densidade; 28 | } 29 | 30 | public function getDataGeracao() 31 | { 32 | return $this->dataGeracao; 33 | } 34 | 35 | public function getSequencialRet() 36 | { 37 | return $this->sequencialRet; 38 | } 39 | 40 | /** 41 | * @param string $codArquivo 42 | */ 43 | public function setCodArquivo($codArquivo) 44 | { 45 | $this->codArquivo = $codArquivo; 46 | return $this; 47 | } 48 | 49 | public function setDensidade($densidade) 50 | { 51 | $this->densidade = $densidade; 52 | return $this; 53 | } 54 | 55 | public function setDataGeracao($dataGeracao) 56 | { 57 | $this->dataGeracao = $dataGeracao; 58 | return $this; 59 | } 60 | 61 | /** 62 | * @param string $sequencialRet 63 | */ 64 | public function setSequencialRet($sequencialRet) 65 | { 66 | $this->sequencialRet = $sequencialRet; 67 | return $this; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/HeaderInterface.php: -------------------------------------------------------------------------------- 1 | dataGeracao; 22 | } 23 | 24 | public function getSequencialRet() 25 | { 26 | return $this->sequencialRet; 27 | } 28 | 29 | public function getConvenio() 30 | { 31 | return $this->convenio; 32 | } 33 | 34 | public function getVersaoLayout() 35 | { 36 | return $this->versaoLayout; 37 | } 38 | 39 | public function getRemessa() 40 | { 41 | return $this->remessa; 42 | } 43 | 44 | public function setDataGeracao(DateTime $dataGeracao) 45 | { 46 | $this->dataGeracao = $dataGeracao; 47 | return $this; 48 | } 49 | 50 | public function setSequencialRet($sequencialRet) 51 | { 52 | $this->sequencialRet = $sequencialRet; 53 | return $this; 54 | } 55 | 56 | public function setConvenio($convenio) 57 | { 58 | $this->convenio = $convenio; 59 | return $this; 60 | } 61 | 62 | public function setVersaoLayout($versaoLayout) 63 | { 64 | $this->versaoLayout = $versaoLayout; 65 | return $this; 66 | } 67 | 68 | public function setRemessa($remessa) 69 | { 70 | $this->remessa = $remessa; 71 | return $this; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/TrailerLote.php: -------------------------------------------------------------------------------- 1 | quantidadeRegistros; 17 | } 18 | 19 | public function getValor() 20 | { 21 | return $this->valor; 22 | } 23 | 24 | public function getQuantidadeMoedas() 25 | { 26 | return $this->quantidadeMoedas; 27 | } 28 | 29 | public function getNumAvisoDepbito() 30 | { 31 | return $this->numAvisoDepbito; 32 | } 33 | 34 | /** 35 | * @param string $quantidadeRegistros 36 | */ 37 | public function setQuantidadeRegistros($quantidadeRegistros) 38 | { 39 | $this->quantidadeRegistros = $quantidadeRegistros; 40 | return $this; 41 | } 42 | 43 | /** 44 | * @param string $valor 45 | */ 46 | public function setValor($valor) 47 | { 48 | $this->valor = $valor; 49 | return $this; 50 | } 51 | 52 | /** 53 | * @param string $quantidadeMoedas 54 | */ 55 | public function setQuantidadeMoedas($quantidadeMoedas) 56 | { 57 | $this->quantidadeMoedas = $quantidadeMoedas; 58 | return $this; 59 | } 60 | 61 | /** 62 | * @param string $numAvisoDepbito 63 | */ 64 | public function setNumAvisoDepbito($numAvisoDepbito) 65 | { 66 | $this->numAvisoDepbito = $numAvisoDepbito; 67 | return $this; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/Resources/ret/240/03091405.RET: -------------------------------------------------------------------------------- 1 | 10400000 2148743970001550000000000000000000001550451268700000000JULIANO RIBEIRO DE SOUZA 00333C ECON FEDERAL 20109201402294400000904000000 RETORNO-PRODUCAO 000 2 | 10400011T0100030 20148743970001550000000000000000000001550451268700000000JULIANO RIBEIRO DE SOUZA 00333 00000009010920140000000000 00 3 | 1040001300001T 060000005126870000000 240000000000000336100000000000000030082014000000000080000001034810000000000000000 090000000000000000 000000000000295040101 4 | 1040001300002U 06000000000000000000000000000000000000000000000000000000000000000000000080000000000000010000000000000000000000000000000000010920140209201400000209201400000000000000000000000000000000000000000000000000000000000000000000 5 | 1040001300003T 060000005126870000000 240000000000000342100000000000000001092014000000000004990237008960000000000000000 090000000000000000 000000000000295040101 6 | 1040001300004U 06000000000000000000000000000000000000000000000000000000000000000000000004990000000000005000000000000000000000000000000000010920140209201400000209201400000000000000000000000000000000000000000000000000000000000000000000 7 | 10400015 00000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 8 | 10499999 000001000008 9 | -------------------------------------------------------------------------------- /tests/Resources/ret/400/retorno.ret: -------------------------------------------------------------------------------- 1 | 02RETORNO01COBRANCA 34584003002128180515FUNDACAO DOIS DE JULHO 001BANCO DO BRASIL0505100001996 000001954800112340 000001 2 | 1000000000000000034584003002128180515 18051500034X70000005 019000000 0000000000 1705050510 18051500034X70000005000000000000000250010400610000605100000450000000000000000000000000000000000000000000000000000000000000000000000000002500000000000000000000000000000000000000000000000000205020000000000000 0000000000000000000000000000000000000000000000000010000002 3 | 1000000000000000034584003002128180515 18051500037470000005 019000000 0000000000 1705050510 18051500037470000005000000000000000250035602410000605100000450000000000000000000000000000000000000000000000000000000000000000000000000002500000000000000000000000000000000000000000000000000205020000000000000 0000000000000000000000000000000000000000000000000010000003 4 | 1000000000000000034584003002128180515 18051500038270000005 019000000 0000000000 1705050510 18051500038270000005000000000000000250035616740000605100000450000000000000000000000000000000000000000000000000000000000000000000000000002500000000000000000000000000000000000000000000000000205020000000000000 0000000000000000000000000000000000000000000000000010000004 5 | 9201001 000000000000000000000000000977 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000005 6 | -------------------------------------------------------------------------------- /tests/RetornoCNAB400Test.php: -------------------------------------------------------------------------------- 1 | processar(); 35 | 36 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Retorno", $retorno); 37 | 38 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Cnab\\Cnab400\\Convenio\\HeaderConvenioInterface", 39 | $retorno->getHeader()); 40 | } 41 | 42 | /** 43 | * @dataProvider conveio7Provider 44 | */ 45 | public function testConvenio7($fileName) 46 | { 47 | $cnab400 = ProcessFactory::getRetorno($fileName); 48 | 49 | $processor = new ProcessHandler($cnab400); 50 | $retorno = $processor->processar(); 51 | 52 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Retorno", $retorno); 53 | 54 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Cnab\\Cnab400\\HeaderInterface", 55 | $retorno->getHeader()); 56 | 57 | $this->assertInstanceOf("Umbrella\\Ya\\RetornoBoleto\\Cnab\\Cnab400\\TrailerInterface", 58 | $retorno->getTrailer()); 59 | } 60 | } -------------------------------------------------------------------------------- /src/Model/Ocorrencia.php: -------------------------------------------------------------------------------- 1 | cod; 36 | } 37 | 38 | /** 39 | * @param int $cod 40 | * @return $this 41 | */ 42 | public function setCod($cod) 43 | { 44 | $this->cod = $cod; 45 | return $this; 46 | } 47 | 48 | /** 49 | * @return string 50 | */ 51 | public function getComplemento() 52 | { 53 | return $this->complemento; 54 | } 55 | 56 | /** 57 | * @param string $complemento 58 | * @return $this 59 | */ 60 | public function setComplemento($complemento) 61 | { 62 | $this->complemento = $complemento; 63 | return $this; 64 | } 65 | 66 | /** 67 | * @return \DateTime 68 | */ 69 | public function getData() 70 | { 71 | return $this->data; 72 | } 73 | 74 | /** 75 | * @param \DateTime $data 76 | * @return $this 77 | */ 78 | public function setData($data) 79 | { 80 | $this->data = $data; 81 | return $this; 82 | } 83 | 84 | /** 85 | * @return float 86 | */ 87 | public function getValor() 88 | { 89 | return $this->valor; 90 | } 91 | 92 | /** 93 | * @param float $valor 94 | * @return $this 95 | */ 96 | public function setValor($valor) 97 | { 98 | $this->valor = $valor; 99 | return $this; 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/Segmento/SegmentoJ.php: -------------------------------------------------------------------------------- 1 | setCod($linha->substr(1, 3)); 20 | 21 | $detail 22 | ->setLote($linha->substr(4, 4)) 23 | ->setRegistro($linha->substr(8, 1)) 24 | ->setNumRegistroLote($linha->substr(9, 5)) 25 | ->setSegmento($linha->substr(14, 1)) 26 | ->setTipoMovimento($linha->substr(15, 1)) 27 | ->setCodMovimento($linha->substr(16, 2)) 28 | ->setCodBarras($linha->substr(18, 44)) 29 | ->setDataVencimento($this->createDate($linha->substr(92, 8))) 30 | ->setValorTitulo($this->convertToFloat($linha->substr(100, 15))) 31 | ->setDesconto($this->convertToFloat($linha->substr(115, 15))) 32 | ->setAcrescimos($this->convertToFloat($linha->substr(130, 15))) 33 | ->setDataPagamento($this->createDate($linha->substr(145, 8))) 34 | ->setValorPagamento($this->convertToFloat($linha->substr(153, 15))) 35 | ->setQuantidadeMoeda($this->convertToFloat($linha->substr(168, 15), 5)) 36 | ->setReferenciaSacado($linha->substr(183, 20)) 37 | ->setNossoNumero($linha->substr(203, 20)) 38 | ->setCodMoeda($linha->substr(223, 2)) 39 | ->addCnab($linha->substr(225, 6)) 40 | ->addOcorrencia($linha->substr(231, 10)); 41 | 42 | 43 | $cedente 44 | ->setNome($linha->substr(62, 30)) 45 | ->setBanco($banco); 46 | 47 | $detail 48 | ->setCedente($cedente); 49 | 50 | return $detail; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/TrailerInterface.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | abstract class AbstractSegmento implements SegmentoInterface 14 | { 15 | 16 | const DECIMAL_POINTS = 2; 17 | 18 | /** 19 | * Formata uma string, contendo uma data sem o separador, no formato DDMMAA. 20 | * @param string $date String contendo a data no formato DDMMAA. 21 | * @param string $format 22 | * @return DateTime 23 | */ 24 | public function createDate($date, $format = "mdy") 25 | { 26 | if (empty($date)) { 27 | return ""; 28 | } 29 | 30 | return DateTime::createFromFormat($format, $date); 31 | } 32 | 33 | /** 34 | * Formata uma string, contendo uma data sem o separador, no formato DDMMAA HHIISS. 35 | * @param string $dateTimeString String contendo a data no formato DDMMAA. 36 | * @return DateTime 37 | */ 38 | public function createDateTime($dateTimeString, $format = "mdy His") 39 | { 40 | if (empty($dateTimeString)) { 41 | return ""; 42 | } 43 | 44 | return DateTime::createFromFormat($format, $dateTimeString); 45 | } 46 | 47 | /** 48 | * Converte uma stringy para um float, de acordo com a quantidade de casas decimais passadas 49 | * @param Stringy $string 50 | * @param int $decimalPoints 51 | * @return float 52 | */ 53 | public function convertToFloat(Stringy $string, $decimalPoints = self::DECIMAL_POINTS) 54 | { 55 | if (!is_int($decimalPoints)) { 56 | $decimalPoints = self::DECIMAL_POINTS; 57 | } 58 | return (float) preg_replace('#(\d*)(\d{' . $decimalPoints . '})$#', '$1.$2', $string->__toString()); 59 | } 60 | 61 | public function convertToInt(Stringy $string) 62 | { 63 | return (int)$string->__toString(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/HeaderLote.php: -------------------------------------------------------------------------------- 1 | mensagens = new ArrayList(); 24 | parent::__construct(); 25 | } 26 | 27 | public function getOperacao() 28 | { 29 | return $this->operacao; 30 | } 31 | 32 | public function getServico() 33 | { 34 | return $this->servico; 35 | } 36 | 37 | public function getFormaLancamento() 38 | { 39 | return $this->formaLancamento; 40 | } 41 | 42 | public function getMensagens() 43 | { 44 | return $this->mensagens; 45 | } 46 | 47 | /** 48 | * @param string $operacao 49 | */ 50 | public function setOperacao($operacao) 51 | { 52 | $this->operacao = $operacao; 53 | return $this; 54 | } 55 | 56 | /** 57 | * @param string $servico 58 | */ 59 | public function setServico($servico) 60 | { 61 | $this->servico = $servico; 62 | return $this; 63 | } 64 | 65 | /** 66 | * @param string $formaLancamento 67 | */ 68 | public function setFormaLancamento($formaLancamento) 69 | { 70 | $this->formaLancamento = $formaLancamento; 71 | return $this; 72 | } 73 | 74 | public function setMensagens(VectorInterface $mensagens) 75 | { 76 | $this->mensagens = $mensagens; 77 | return $this; 78 | } 79 | 80 | /** 81 | * @param string $mensagem 82 | */ 83 | public function addMensagem($mensagem) 84 | { 85 | $trim = trim($mensagem); 86 | if (!empty($trim)) { 87 | $this->cnabs->add($mensagem); 88 | } 89 | return $this; 90 | } 91 | 92 | public function removeMensagem($mensagem) 93 | { 94 | $this->cnabs->remove($mensagem); 95 | return $this; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /docs/getting-started/overview.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | Bem vindo ao YA Retorno Boleto 3 | ================= 4 | 5 | O que é? 6 | ~~~~~~~~~~~~~~~ 7 | 8 | Yet Another Retorno Boleto é uma biblioteca em PHP para leitura de arquivos de retorno de títulos de cobrança 9 | de bancos brasileiros. 10 | 11 | Principais funcionalidades 12 | -------------------- 13 | 14 | - Parser de arquivos de retorno da FEBRABAN em uma unica interface. 15 | - Fácil extensão para funcionar com qualquer arquivo de retorno não suportado. 16 | 17 | .. code-block:: php 18 | 19 | use Umbrella\Ya\RetornoBoleto\ProcessFactory; 20 | use Umbrella\Ya\RetornoBoleto\ProcessHandler; 21 | 22 | // Utilizamos a factory para construir o objeto correto para um determinado arquivo de retorno 23 | $cnab = ProcessFactory::getRetorno('arquivo-retorno.ret'); 24 | 25 | // Passamos o objeto contruido para o handler 26 | $processor = new ProcessHandler($cnab); 27 | 28 | // Processamos o arquivo. Isso retornará um objeto parseado com todas as propriedades do arquvio. 29 | $retorno = $processor->processar(); 30 | 31 | License 32 | ------- 33 | 34 | Licensed using the `MIT license `_. 35 | 36 | The MIT License (MIT) 37 | 38 | Copyright (c) 2014 Umbrella Tech 39 | 40 | Permission is hereby granted, free of charge, to any person obtaining a copy 41 | of this software and associated documentation files (the "Software"), to deal 42 | in the Software without restriction, including without limitation the rights 43 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | copies of the Software, and to permit persons to whom the Software is 45 | furnished to do so, subject to the following conditions: 46 | 47 | The above copyright notice and this permission notice shall be included in all 48 | copies or substantial portions of the Software. 49 | 50 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 56 | SOFTWARE. 57 | -------------------------------------------------------------------------------- /tests/Resources/ret/240/RETORNOCEF090814.bax: -------------------------------------------------------------------------------- 1 | 10400000 2083548960001190000000000000000000001101001577600000000PM DE PEDRO VELHO C ECON FEDERAL 20808201401132900121604000000 RETORNO-PRODUCAO 000 2 | 10400011T0100030 20083548960001190000000000000000000001101001577600000000PM DE PEDRO VELHO 00001216080820140000000000 00 3 | 1040001300001T 060000000157760000000 240000000000324470100000000000000008082014000000000002000001017310000000000000000 090000000000000000 000000000000270040101 4 | 1040001300002U 06000000000000000000000000000000000000000000000000000000000000000000000002000000000000002000000000000000000000000000000000080820141108201400001108201400000000000000000000000000000000000000000000000000000000000000000000 5 | 1040001300003T 060000000157760000000 240000000000324446100000000000000011082014000000000102507001037950000000000000000 090000000000000000 000000000000270040101 6 | 1040001300004U 06000000000000000000000000000000000000000000000000000000000000000000000102507000000000102507000000000000000000000000000000080820141108201400001108201400000000000000000000000000000000000000000000000000000000000000000000 7 | 1040001300005T 060000000157760000000 240000000000324462100000000000000008082014000000000000900001017310000000000000000 090000000000000000 000000000000270040101 8 | 1040001300006U 06000000000000000000000000000000000000000000000000000000000000000000000000900000000000000900000000000000000000000000000000080820141108201400001108201400000000000000000000000000000000000000000000000000000000000000000000 9 | 10400015 00000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10 | 10499999 000001000010 11 | -------------------------------------------------------------------------------- /docs/events/plugins-overview.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | Plugin system overview 3 | ====================== 4 | 5 | The workflow of sending a request and parsing a response is driven by Guzzle's event system, which is powered by the 6 | `Symfony2 Event Dispatcher component `_. 7 | 8 | Any object in Guzzle that emits events will implement the ``Guzzle\Common\HasEventDispatcher`` interface. You can add 9 | event subscribers directly to these objects using the ``addSubscriber()`` method, or you can grab the 10 | ``Symfony\Component\EventDispatcher\EventDispatcher`` object owned by the object using ``getEventDispatcher()`` and 11 | add a listener or event subscriber. 12 | 13 | Adding event subscribers to clients 14 | ----------------------------------- 15 | 16 | Any event subscriber or event listener attached to the EventDispatcher of a ``Guzzle\Http\Client`` or 17 | ``Guzzle\Service\Client`` object will automatically be attached to all request objects created by the client. This 18 | allows you to attach, for example, a HistoryPlugin to a client object, and from that point on, every request sent 19 | through that client will utilize the HistoryPlugin. 20 | 21 | .. code-block:: php 22 | 23 | use Guzzle\Plugin\History\HistoryPlugin; 24 | use Guzzle\Service\Client; 25 | 26 | $client = new Client(); 27 | 28 | // Create a history plugin and attach it to the client 29 | $history = new HistoryPlugin(); 30 | $client->addSubscriber($history); 31 | 32 | // Create and send a request. This request will also utilize the HistoryPlugin 33 | $client->get('http://httpbin.org')->send(); 34 | 35 | // Echo out the last sent request by the client 36 | echo $history->getLastRequest(); 37 | 38 | .. tip:: 39 | 40 | :doc:`Create event subscribers `, or *plugins*, to implement reusable logic that can be 41 | shared across clients. Event subscribers are also easier to test than anonymous functions. 42 | 43 | Pre-Built plugins 44 | ----------------- 45 | 46 | Guzzle provides easy to use request plugins that add behavior to requests based on signal slot event notifications 47 | powered by the Symfony2 Event Dispatcher component. 48 | 49 | * :doc:`async-plugin` 50 | * :doc:`backoff-plugin` 51 | * :doc:`cache-plugin` 52 | * :doc:`cookie-plugin` 53 | * :doc:`curl-auth-plugin` 54 | * :doc:`history-plugin` 55 | * :doc:`log-plugin` 56 | * :doc:`md5-validator-plugin` 57 | * :doc:`mock-plugin` 58 | * :doc:`oauth-plugin` 59 | 60 | -------------------------------------------------------------------------------- /docs/component/uri-templates.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | URI templates 3 | ============= 4 | 5 | The ``$uri`` passed to one of the client's request creational methods or the base URL of a client can utilize URI 6 | templates. Guzzle supports the entire `URI templates RFC `_. URI templates add a 7 | special syntax to URIs that replace template place holders with user defined variables. 8 | 9 | Every request created by a Guzzle HTTP client passes through a URI template so that URI template expressions are 10 | automatically expanded: 11 | 12 | .. code-block:: php 13 | 14 | $client = new Guzzle\Http\Client('https://example.com/', array('a' => 'hi')); 15 | $request = $client->get('/{a}'); 16 | 17 | Because of URI template expansion, the URL of the above request will become ``https://example.com/hi``. Notice that 18 | the template was expanded using configuration variables of the client. You can pass in custom URI template variables 19 | by passing the URI of your request as an array where the first index of the array is the URI template and the second 20 | index of the array are template variables that are merged into the client's configuration variables. 21 | 22 | .. code-block:: php 23 | 24 | $request = $client->get(array('/test{?a,b}', array('b' => 'there'))); 25 | 26 | The URL for this request will become ``https://test.com?a=hi&b=there``. URI templates aren't limited to just simple 27 | variable replacements; URI templates can provide an enormous amount of flexibility when creating request URIs. 28 | 29 | .. code-block:: php 30 | 31 | $request = $client->get(array('http://example.com{+path}{/segments*}{?query,data*}', array( 32 | 'path' => '/foo/bar', 33 | 'segments' => array('one', 'two'), 34 | 'query' => 'test', 35 | 'data' => array( 36 | 'more' => 'value' 37 | ) 38 | ))); 39 | 40 | The resulting URL would become ``http://example.com/foo/bar/one/two?query=test&more=value``. 41 | 42 | By default, URI template expressions are enclosed in an opening and closing brace (e.g. ``{var}``). If you are working 43 | with a web service that actually uses braces (e.g. Solr), then you can specify a custom regular expression to use to 44 | match URI template expressions. 45 | 46 | .. code-block:: php 47 | 48 | $client->getUriTemplate()->setRegex('/\<\$(.+)\>/'); 49 | $client->get('/<$a>'); 50 | 51 | You can learn about all of the different features of URI templates by reading the 52 | `URI templates RFC `_. 53 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/Segmento/SegmentoT.php: -------------------------------------------------------------------------------- 1 | setCod($linha->substr(1, 3)); 22 | 23 | $detail 24 | ->setLote($linha->substr(4, 4)) 25 | ->setRegistro($linha->substr(8, 1)) 26 | ->setNumRegistroLote($linha->substr(9, 5)) 27 | ->setSegmento($linha->substr(14, 1)) 28 | ->setTipoMovimento($linha->substr(15, 1)) 29 | ->setCodMovimento($linha->substr(16, 2)); 30 | 31 | $banco->setAgencia($linha->substr(18, 5)) 32 | ->setDvAgencia($linha->substr(23, 1)) 33 | ->setConta($linha->substr(24, 12)) 34 | ->setDvConta($linha->substr(36, 1)); 35 | 36 | $detail->setNossoNumero($linha->substr(38, 20)) 37 | ->setCarteira($linha->substr(58, 1)) 38 | ->setNumeroDocumento($linha->substr(59, 15)) 39 | ->setDataVencimento($linha->substr(74, 8)) 40 | ->setValorTitulo($this->convertToFloat($linha->substr(82, 15))); 41 | 42 | $banco->setCod($linha->substr(97, 3)) 43 | ->setAgencia($linha->substr(100, 5)) 44 | ->setDvAgencia($linha->substr(105, 1)); 45 | 46 | $empresa = new Empresa(); 47 | $empresa->addUso($linha->substr(106, 25)); 48 | 49 | $detail->setCodMoeda($linha->substr(131, 2)); 50 | 51 | $sacado = new Sacado(); 52 | $sacado->setInscricao(new Inscricao($linha->substr(134, 15), $linha->substr(133, 1))) 53 | ->setNome($linha->substr(149, 40)); 54 | 55 | $detail->setNumeroContrato($linha->substr(189, 10)) 56 | ->setValorTarifa($this->convertToFloat($linha->substr(199, 15))) 57 | ->addOcorrencia($linha->substr(214, 10)) 58 | ->addCnab($linha->substr(224, 17)); 59 | 60 | $cedente = new Cedente(); 61 | $cedente->setBanco($banco); 62 | $detail 63 | ->setCedente($cedente) 64 | ->setSacado($sacado); 65 | 66 | return $detail; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Model/Endereco.php: -------------------------------------------------------------------------------- 1 | logradourdo; 18 | } 19 | 20 | public function getNumero() 21 | { 22 | return $this->numero; 23 | } 24 | 25 | public function getComplemento() 26 | { 27 | return $this->complemento; 28 | } 29 | 30 | public function getCep() 31 | { 32 | return $this->cep; 33 | } 34 | 35 | public function getComplementoCep() 36 | { 37 | return $this->complementoCep; 38 | } 39 | 40 | public function getCidade() 41 | { 42 | return $this->cidade; 43 | } 44 | 45 | public function getEstado() 46 | { 47 | return $this->estado; 48 | } 49 | 50 | /** 51 | * @param string $logradourdo 52 | */ 53 | public function setLogradourdo($logradourdo) 54 | { 55 | $this->logradourdo = $logradourdo; 56 | return $this; 57 | } 58 | 59 | /** 60 | * @param string $numero 61 | */ 62 | public function setNumero($numero) 63 | { 64 | $this->numero = $numero; 65 | return $this; 66 | } 67 | 68 | /** 69 | * @param string $complemento 70 | */ 71 | public function setComplemento($complemento) 72 | { 73 | $this->complemento = $complemento; 74 | return $this; 75 | } 76 | 77 | /** 78 | * @param string $cep 79 | */ 80 | public function setCep($cep) 81 | { 82 | $this->cep = $cep; 83 | return $this; 84 | } 85 | 86 | /** 87 | * @param string $complementoCep 88 | */ 89 | public function setComplementoCep($complementoCep) 90 | { 91 | $this->complementoCep = $complementoCep; 92 | return $this; 93 | } 94 | 95 | /** 96 | * @param string $cidade 97 | */ 98 | public function setCidade($cidade) 99 | { 100 | $this->cidade = $cidade; 101 | return $this; 102 | } 103 | 104 | /** 105 | * @param string $estado 106 | */ 107 | public function setEstado($estado) 108 | { 109 | $this->estado = $estado; 110 | return $this; 111 | } 112 | 113 | public function getCepCompleto() 114 | { 115 | return $this->cep . $this->complementoCep; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | import sys, os 2 | from sphinx.highlighting import lexers 3 | from pygments.lexers.web import PhpLexer 4 | 5 | lexers['php'] = PhpLexer(startinline=True, linenos=1) 6 | lexers['php-annotations'] = PhpLexer(startinline=True, linenos=1) 7 | primary_domain = 'php' 8 | 9 | # -- General configuration ----------------------------------------------------- 10 | 11 | extensions = [] 12 | templates_path = ['_templates'] 13 | source_suffix = '.rst' 14 | master_doc = 'index' 15 | 16 | project = u'Ya Retorno Boleto' 17 | copyright = u'2014, Italo Lelis de Vietro' 18 | version = '1.0.0' 19 | release = '1.0.0' 20 | 21 | exclude_patterns = ['_build'] 22 | 23 | # -- Options for HTML output --------------------------------------------------- 24 | 25 | # The name for this set of Sphinx documents. If None, it defaults to 26 | # " v documentation". 27 | html_title = "Ya Retorno Boleto documentation" 28 | html_short_title = "YARetornoBoleto" 29 | 30 | # Add any paths that contain custom static files (such as style sheets) here, 31 | # relative to this directory. They are copied after the builtin static files, 32 | # so a file named "default.css" will overwrite the builtin "default.css". 33 | html_static_path = ['_static'] 34 | 35 | # Custom sidebar templates, maps document names to template names. 36 | html_sidebars = { 37 | '**': ['localtoc.html', 'leftbar.html', 'searchbox.html'] 38 | } 39 | 40 | # Output file base name for HTML help builder. 41 | htmlhelp_basename = 'RetornoBoletodoc' 42 | 43 | 44 | # -- Options for LaTeX output -------------------------------------------------- 45 | 46 | latex_elements = {} 47 | 48 | # Grouping the document tree into LaTeX files. List of tuples 49 | # (source start file, target name, title, author, documentclass [howto/manual]). 50 | latex_documents = [ 51 | ('index', 'umbrella.tex', u'Ya Retorno Boleto Documentation', 52 | u'Italo Lelis de Vietro', 'manual'), 53 | ] 54 | 55 | # -- Options for manual page output -------------------------------------------- 56 | 57 | # One entry per manual page. List of tuples 58 | # (source start file, name, description, authors, manual section). 59 | man_pages = [ 60 | ('index', 'umbrella', u'Ya Retorno Boleto Documentation', 61 | [u'Italo Lelis de Vietro'], 1) 62 | ] 63 | 64 | # If true, show URL addresses after external links. 65 | #man_show_urls = False 66 | 67 | # -- Options for Texinfo output ------------------------------------------------ 68 | 69 | # Grouping the document tree into Texinfo files. List of tuples 70 | # (source start file, target name, title, author, 71 | # dir menu entry, description, category) 72 | texinfo_documents = [ 73 | ('index', 'Umbrella', u'Ya Retorno Boleto Documentation', 74 | u'Italo Lelis de Vietro', 'Umbrella', 'One line description of project.', 75 | 'Miscellaneous'), 76 | ] 77 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/Segmento/SegmentoU.php: -------------------------------------------------------------------------------- 1 | setCod($linha->substr(1, 3)); 27 | $sacado->setBanco($bancoSacado); 28 | 29 | $detail 30 | ->setLote($linha->substr(4, 4)) 31 | ->setRegistro($linha->substr(8, 1)) 32 | ->setNumRegistroLote($linha->substr(9, 5)) 33 | ->setSegmento($linha->substr(14, 1)) 34 | ->addCnab($linha->substr(15, 1)) 35 | ->setCodMovimento($linha->substr(16, 2)); 36 | 37 | //Dados do Titulo 38 | $dadosTitulo->setAcrescimos($this->convertToFloat($linha->substr(18, 15))) 39 | ->setValorDesconto($this->convertToFloat($linha->substr(33, 15))) 40 | ->setValorAbatimento($this->convertToFloat($linha->substr(48, 15))) 41 | ->setValorIOF($this->convertToFloat($linha->substr(63, 15))) 42 | ->setValorPago($this->convertToFloat($linha->substr(78, 15))) 43 | ->setValorLiquido($this->convertToFloat($linha->substr(93, 15))); 44 | 45 | $detail->setDadosTitulo($dadosTitulo) 46 | ->setOutrasDespesas($this->convertToFloat($linha->substr(108, 15))) 47 | ->setOutrosCreditos($this->convertToFloat($linha->substr(123, 15))) 48 | ->setDataOcorrencia($this->createDate($linha->substr(138, 8), "dmY")) 49 | ->setDataCredito($this->createDate($linha->substr(146, 8), "dmY")); 50 | 51 | $ocorrencia->setCod(($this->convertToInt($linha->substr(154, 4)))) 52 | ->setData($this->createDate($linha->substr(158, 8))) 53 | ->setValor($this->convertToFloat($linha->substr(166, 15))) 54 | ->setComplemento($linha->substr(181, 30)); 55 | 56 | $banco->setCod($linha->substr(211, 3)); 57 | $cedente->setBanco($banco); 58 | 59 | $detail->setNossoNumero($linha->substr(214, 20)) 60 | ->addCnab($linha->substr(234, 7)); 61 | 62 | $detail 63 | ->setCedente($cedente) 64 | ->setSacado($sacado); 65 | 66 | return $detail; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/ProcessHandler.php: -------------------------------------------------------------------------------- 1 | 16 | * @author Ítalo Lelis de Vietro 17 | */ 18 | class ProcessHandler 19 | { 20 | /** 21 | * @property AbstractProcessor $processor 22 | * Atributo que deve ser um objeto de uma classe que estenda a classe AbstractRetorno 23 | */ 24 | protected $processor; 25 | protected $dispatcher; 26 | 27 | /** 28 | * Construtor da classe 29 | * @param AbstractProcessor $retorno Objeto de uma sub-classe de AbstractRetorno, 30 | * que implementa a leitura de arquivo de retorno para uma determinada carteira 31 | * de um banco específico. 32 | */ 33 | public function __construct(AbstractProcessor $retorno) 34 | { 35 | $this->processor = $retorno; 36 | $this->dispatcher = new EventDispatcher(); 37 | } 38 | 39 | /** 40 | * Recupera o dispatcher para o EventDispatcher. 41 | * @return EventDispatcherInterface 42 | */ 43 | public function getDispatcher() 44 | { 45 | return $this->dispatcher; 46 | } 47 | 48 | private function createLote(RetornoInterface $retorno) 49 | { 50 | $lote = new Lote(); //Lote padrão 51 | $retorno->addLote($lote); 52 | return $lote; 53 | } 54 | 55 | /** 56 | * Executa o processamento de todo o arquivo, linha a linha. 57 | * @return RetornoInterface 58 | */ 59 | public function processar() 60 | { 61 | $retorno = new Retorno(); 62 | $lote = null; 63 | 64 | $lines = file($this->processor->getNomeArquivo(), FILE_IGNORE_NEW_LINES); 65 | foreach ($lines as $lineNumber => $lineContent) { 66 | $string = new Stringy(rtrim($lineContent, "\r\n")); 67 | $composable = $this->processor->processarLinha($lineNumber, $string); 68 | 69 | if ($this->processor->needToCreateLote()) { 70 | $lote = $this->createLote($retorno); 71 | } 72 | 73 | $this->processor->processCnab($retorno, $composable, $lote); 74 | 75 | $event = new OnDetailRegisterEvent($this->processor, $lineNumber, $composable); 76 | $this->dispatcher->dispatch(RetornoEvents::ON_DETAIL_REGISTER, $event); 77 | } 78 | 79 | return $retorno; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Retorno.php: -------------------------------------------------------------------------------- 1 | lotes = new ArrayList(); 36 | } 37 | 38 | /** 39 | * Adiciona um lote. 40 | * @param LoteInterface $lote 41 | * @return Retorno 42 | */ 43 | public function addLote(LoteInterface $lote) 44 | { 45 | $this->lotes->add($lote); 46 | return $this; 47 | } 48 | 49 | /** 50 | * Remove um lote. 51 | * @param LoteInterface $lote 52 | * @return Retorno 53 | */ 54 | public function removeLote(LoteInterface $lote) 55 | { 56 | $this->lotes->remove($lote); 57 | return $this; 58 | } 59 | 60 | /** 61 | * Recupera o header do arquivo. 62 | * @return CnabHeaderInterface 63 | */ 64 | public function getHeader() 65 | { 66 | return $this->header; 67 | } 68 | 69 | /** 70 | * Recupera o trailer do arquivo. 71 | * @return CnabTrailerInterface 72 | */ 73 | public function getTrailer() 74 | { 75 | return $this->trailer; 76 | } 77 | 78 | /** 79 | * Define o header do arquivo. 80 | * @param CnabHeaderInterface $header 81 | */ 82 | public function setHeader(CnabHeaderInterface $header) 83 | { 84 | $this->header = $header; 85 | } 86 | 87 | /** 88 | * Define o trailer do arquivo. 89 | * @param CnabTrailerInterface $trailer 90 | */ 91 | public function setTrailer(CnabTrailerInterface $trailer) 92 | { 93 | $this->trailer = $trailer; 94 | } 95 | 96 | /** 97 | * Recupera todos os lotes do arquivo. 98 | * @return VectorInterface 99 | */ 100 | public function getLotes() 101 | { 102 | return $this->lotes; 103 | } 104 | 105 | /** 106 | * Define todos os lotes do arquivo. 107 | * @param VectorInterface $lotes 108 | * @return Retorno 109 | */ 110 | public function setLotes(VectorInterface $lotes) 111 | { 112 | $this->lotes = $lotes; 113 | return $this; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Convenio/DetailConvenioInterface.php: -------------------------------------------------------------------------------- 1 | details = new ArrayList(); 37 | } 38 | 39 | /** 40 | * Adiciona um detalhe ao lote. 41 | * @param CnabDetailInterface $detail 42 | * @return Lote 43 | */ 44 | public function addDetail(CnabDetailInterface $detail) 45 | { 46 | $this->details->add($detail); 47 | return $this; 48 | } 49 | 50 | /** 51 | * Remove um detalhe do lote. 52 | * @param CnabDetailInterface $detail 53 | * @return Lote 54 | */ 55 | public function removeDetail(CnabDetailInterface $detail) 56 | { 57 | $this->details->remove($detail); 58 | return $this; 59 | } 60 | 61 | /** 62 | * Recupera o header do arquivo. 63 | * @return CnabHeaderInterface 64 | */ 65 | public function getHeader() 66 | { 67 | return $this->header; 68 | } 69 | 70 | /** 71 | * Recupera os detalhes do arquivo. 72 | * @return VectorInterface 73 | */ 74 | public function getDetails() 75 | { 76 | return $this->details; 77 | } 78 | 79 | /** 80 | * Recupera o trailer do arquivo. 81 | * @return CnabTrailerInterface 82 | */ 83 | public function getTrailer() 84 | { 85 | return $this->trailer; 86 | } 87 | 88 | /** 89 | * Define o header do arquivo. 90 | * @param CnabHeaderInterface $header 91 | */ 92 | public function setHeader(CnabHeaderInterface $header) 93 | { 94 | $this->header = $header; 95 | } 96 | 97 | /** 98 | * Define os detalhes do arquivo. 99 | * @param VectorInterface $details 100 | */ 101 | public function setDetails(VectorInterface $details) 102 | { 103 | $this->details = $details; 104 | } 105 | 106 | /** 107 | * Define o trailer do arquivo. 108 | * @param CnabTrailerInterface $trailer 109 | */ 110 | public function setTrailer(CnabTrailerInterface $trailer) 111 | { 112 | $this->trailer = $trailer; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Convenio/Processor/CNAB400Conv7Processor.php: -------------------------------------------------------------------------------- 1 | 10 | * Layout Padrão CNAB/Febraban 400 posições
. 11 | * Baseado na documentação para "Layout de Arquivo Retorno para convênios na 12 | * faixa numérica entre 1.000.000 a 9.999.999 (Convênios de 7 posições). Versão Set/09" 13 | * do Banco do Brasil (arquivo Doc2628CBR643Pos7.pdf), 14 | * disponível em http://www.bb.com.br/docs/pub/emp/empl/dwn/Doc2628CBR643Pos7.pdf 15 | * @author Ítalo Lelis de Vietro 16 | */ 17 | class CNAB400Conv7Processor extends AbstractCNAB400Processor 18 | { 19 | /** 20 | * @property int DETALHE Define o valor que identifica uma coluna do tipo DETALHE 21 | */ 22 | const DETALHE = 7; 23 | 24 | public function createHeader() 25 | { 26 | return new HeaderConvenio(); 27 | } 28 | 29 | public function createDetail() 30 | { 31 | return new DetailConvenio(); 32 | } 33 | 34 | /** 35 | * Processa a linha header do arquivo 36 | * @param string $linha Linha do header de arquivo processado 37 | * @return string Retorna um vetor contendo os dados dos campos do header do arquivo. 38 | */ 39 | protected function processarHeaderArquivo($linha) 40 | { 41 | $header = parent::processarHeaderArquivo($linha); 42 | $header 43 | ->addComplemento($linha->substr(108, 42)->trim()) 44 | ->setConvenio($linha->substr(150, 7)->trim()) 45 | ->addComplemento($linha->substr(108, 42)->trim()) 46 | ; 47 | 48 | return $header; 49 | } 50 | 51 | /** 52 | * Processa uma linha detalhe do arquivo. 53 | * @param string $linha Linha detalhe do arquivo processado 54 | * @return string Retorna um vetor contendo os dados dos campos da linha detalhe. 55 | */ 56 | protected function processarDetalhe($linha) 57 | { 58 | $detail = parent::processarDetalhe($linha); 59 | $detail 60 | ->setConvenio($linha->substr(32, 7)->trim()) 61 | ->setControle($linha->substr(38, 25)->trim()) 62 | ->setNossoNumero($linha->substr(64, 17)->trim()) 63 | ->setTipoCobranca($linha->substr(81, 1)->trim()) 64 | ->setTipoCobrancaCmd72($linha->substr(82, 1)->trim()) 65 | ->setDiasCalculo($linha->substr(83, 4)->trim()) 66 | ->setNatureza($linha->substr(87, 2)->trim()) 67 | ->setPrefixoTitulo($linha->substr(89, 3)->trim()) 68 | ->setVariacaoCarteira($linha->substr(92, 3)->trim()) 69 | ->setContaCaucao($linha->substr(95, 1)->trim()) 70 | ; 71 | return $detail; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Cnab/Cnab240/DadosTitulo.php: -------------------------------------------------------------------------------- 1 | acrescimos; 43 | } 44 | 45 | /** 46 | * @param float $acrescimos 47 | * @return $this 48 | */ 49 | public function setAcrescimos($acrescimos) 50 | { 51 | $this->acrescimos = $acrescimos; 52 | return $this; 53 | } 54 | 55 | /** 56 | * @return float 57 | */ 58 | public function getValorAbatimento() 59 | { 60 | return $this->valorAbatimento; 61 | } 62 | 63 | /** 64 | * @param float $valorAbatimento 65 | * @return $this 66 | */ 67 | public function setValorAbatimento($valorAbatimento) 68 | { 69 | $this->valorAbatimento = $valorAbatimento; 70 | return $this; 71 | } 72 | 73 | /** 74 | * @return float 75 | */ 76 | public function getValorDesconto() 77 | { 78 | return $this->valorDesconto; 79 | } 80 | 81 | /** 82 | * @param float $valorDesconto 83 | * @return $this 84 | */ 85 | public function setValorDesconto($valorDesconto) 86 | { 87 | $this->valorDesconto = $valorDesconto; 88 | return $this; 89 | } 90 | 91 | /** 92 | * @return float 93 | */ 94 | public function getValorIOF() 95 | { 96 | return $this->valorIOF; 97 | } 98 | 99 | /** 100 | * @param float $valorIOF 101 | * @return $this 102 | */ 103 | public function setValorIOF($valorIOF) 104 | { 105 | $this->valorIOF = $valorIOF; 106 | return $this; 107 | } 108 | 109 | /** 110 | * @return float 111 | */ 112 | public function getValorLiquido() 113 | { 114 | return $this->valorLiquido; 115 | } 116 | 117 | /** 118 | * @param float $valorLiquido 119 | * @return $this 120 | */ 121 | public function setValorLiquido($valorLiquido) 122 | { 123 | $this->valorLiquido = $valorLiquido; 124 | return $this; 125 | } 126 | 127 | /** 128 | * @return float 129 | */ 130 | public function getValorPago() 131 | { 132 | return $this->valorPago; 133 | } 134 | 135 | /** 136 | * @param float $valorPago 137 | * @return $this 138 | */ 139 | public function setValorPago($valorPago) 140 | { 141 | $this->valorPago = $valorPago; 142 | return $this; 143 | } 144 | 145 | 146 | } 147 | -------------------------------------------------------------------------------- /tests/Resources/ret/400/CBR64334531308201411115.ret: -------------------------------------------------------------------------------- 1 | 02RETORNO01COBRANCA 41548000056278000000PREFEITURA MUNICIPAL DE GUAMAR001BANCO DO BRASIL1308140002181 000003453906071674 1111512 000001 2 | 70000000000000000415480000562781111512 1111512140100104810000001 01900000000000 1806130814 000000000000000180010448840001508140000530000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000127020000000000000 0000000000000000000000000000000000000000000000001010000002 3 | 70000000000000000415480000562781111512 1111512140100104910000001 01900000000000 1806130814 000000000000000180000141548001508140000530000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000127020000000000000 0000000000000000000000000000000000000000000000001007000003 4 | 70000000000000000415480000562781111512 1111512140100105210000001 01900000000000 1806130814 000000000000000180000141548001508140000530000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000127020000000000000 0000000000000000000000000000000000000000000000001008000004 5 | 70000000000000000415480000562781111512 1111512140100105310000001 01900000000000 1806130814 000000000000000180000141548001508140000530000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000127020000000000000 0000000000000000000000000000000000000000000000001001000005 6 | 70000000000000000415480000562781111512 1111512140100105410000001 01900000000000 1806130814 000000000000006000010448840001508140000530000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000005947020000000000000 0000000000000000000000000000000000000000000000001010000006 7 | 70000000000000000415480000562781111512 1111512140100105510000001 01900000000000 1806130814 000000000000000180010448840001508140000530000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000127020000000000000 0000000000000000000000000000000000000000000000001010000007 8 | 9201001 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000008 9 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Convenio/Processor/CNAB400Conv6Processor.php: -------------------------------------------------------------------------------- 1 | 10 | * Layout Padrão CNAB/Febraban 400 posições
. 11 | * Baseado na documentação para "Layout de Arquivo Retorno para convênios na faixa numérica entre 1.000.000 a 9.999.999 12 | * (Convênios de 7 posições). Versão Set/09" do Banco do Brasil (arquivo Doc8826BR643Pos6.pdf), 13 | * disponível em http://www.bb.com.br/docs/pub/emp/empl/dwn/Doc8826BR643Pos6.pdf 14 | * @author Ítalo Lelis de Vietro 15 | */ 16 | class CNAB400Conv6Processor extends AbstractCNAB400Processor 17 | { 18 | /** 19 | * @property int DETALHE Define o valor que identifica uma coluna do tipo DETALHE 20 | */ 21 | const DETALHE = 1; 22 | 23 | public function createHeader() 24 | { 25 | return new HeaderConvenio(); 26 | } 27 | 28 | public function createDetail() 29 | { 30 | return new DetailConvenio(); 31 | } 32 | 33 | /** 34 | * Processa a linha header do arquivo 35 | * @param string $linha Linha do header de arquivo processado 36 | * @return string Retorna um vetor contendo os dados dos campos do header do arquivo. 37 | */ 38 | protected function processarHeaderArquivo($linha) 39 | { 40 | $header = parent::processarHeaderArquivo($linha); 41 | $header->setConvenio($linha->substr(41, 6)->trim()) 42 | ->setSequencialRet($linha->substr(101, 7)->trim()) 43 | ->addComplemento($linha->substr(108, 287)->trim()); 44 | 45 | return $header; 46 | } 47 | 48 | /** 49 | * Processa uma linha detalhe do arquivo. 50 | * @param string $linha Linha detalhe do arquivo processado 51 | * @return string Retorna um vetor contendo os dados dos campos da linha detalhe. 52 | */ 53 | protected function processarDetalhe($linha) 54 | { 55 | $detail = parent::processarDetalhe($linha); 56 | $detail 57 | ->setConvenio($linha->substr(32, 6)->trim()) 58 | ->setControle($linha->substr(38, 25)->trim()) 59 | ->setNossoNumero($linha->substr(63, 11)->trim()) 60 | ->setDvNossoNumero($linha->substr(74, 1)->trim()) 61 | ->setTipoCobranca($linha->substr(75, 1)->trim()) 62 | ->setTipoCobrancaCmd72($linha->substr(76, 1)->trim()) 63 | ->setDiasCalculo($linha->substr(77, 4)->trim()) 64 | ->setNatureza($linha->substr(81, 2)->trim()) 65 | ->addUsoBanco($linha->substr(83, 3)->trim()) 66 | ->setVariacaoCarteira($linha->substr(86, 3)->trim()) 67 | ->setContaCaucao($linha->substr(89, 1)->trim()) 68 | ->addUsoBanco($linha->substr(90, 5)->trim()) 69 | ->addUsoBanco($linha->substr(95, 1)->trim()) 70 | ->setConfirmacao($linha->substr(127, 20)->trim()) 71 | ; 72 | return $detail; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/Resources/ret/240/retorno_cnab240.ret: -------------------------------------------------------------------------------- 1 | 00100000 2026599530001760032948600014 0032860000000075367 SAPATARIA E CONFECSOES JIBA BANCO DO BRASIL 22103201102475000025703000000909214318PROCESSAMEN 2 | 00100011T0100020 20026599530001760032948600014 0032860000000075367 SAPATARIA E CONFECSOES JIBA 000000002103201100000000 000000000 3 | 0010001300001T 060032860000000075367 32948600000000196 1 23032011000000000004285237009880 0900000000000000000000000000000000000000000000000000000 000000000000000000000050000 180273294860 4 | 0010001300002U 060000000000325000000000000000000000000000000000000000000000000000000000041250000000000035000000000000000000000000000000002103201123032011 000000000000000 000 5 | 0010001300003T 060032860000000075367 32948600000000236 1 25032011000000000003000033045680 0900000000000000000000000000000000000000000000000000000 000000000000000000000050000 180273294860 6 | 0010001300004U 060000000000000000000000000000000000000000000000000000000000000000000000030000000000000025000000000000000000000000000000002103201123032011 000000000000000 000 7 | 0010001300005T 060032860000000075367 32948600000000244 1 23032011000000000001500104004900 0900000000000000000000000000000000000000000000000000000 000000000000000000000050000 180273294860 8 | 0010001300006U 060000000000000000000000000000000000000000000000000000000000000000000000015000000000000010000000000000000000000000000000002103201123032011 000000000000000 000 9 | 0010001300007T 060032860000000075367 32948600000000249 1 23032011000000000001500104022660 0900000000000000000000000000000000000000000000000000000 000000000000000000000050000 180273294860 10 | 0010001300008U 060000000000000000000000000000000000000000000000000000000000000000000000015000000000000010000000000000000000000000000000002103201123032011 000000000000000 000 11 | 0010001300009T 060032860000000075367 32948600000005048 1 01042011000000000002880033002570 0900000000000000000000000000000000000000000000000000000 000000000000000000000050000 180273294860 12 | 0010001300010U 060000000000000000000000000000000000000000000000000000000000000000000000028800000000000023800000000000000000000000000000002103201123032011 000000000000000 000 13 | 00100015 000012000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 14 | 00199999 000001000014000000 00000000000000000000000000000 15 | -------------------------------------------------------------------------------- /docs/events/log-plugin.rst: -------------------------------------------------------------------------------- 1 | ========== 2 | Log plugin 3 | ========== 4 | 5 | Use the ``Guzzle\Plugin\Log\LogPlugin`` to view all data sent over the wire, including entity bodies and redirects. 6 | 7 | .. code-block:: php 8 | 9 | use Guzzle\Http\Client; 10 | use Guzzle\Log\Zf1LogAdapter; 11 | use Guzzle\Plugin\Log\LogPlugin; 12 | use Guzzle\Log\MessageFormatter; 13 | 14 | $client = new Client('http://www.test.com/'); 15 | 16 | $adapter = new Zf1LogAdapter( 17 | new \Zend_Log(new \Zend_Log_Writer_Stream('php://output')) 18 | ); 19 | $logPlugin = new LogPlugin($adapter, MessageFormatter::DEBUG_FORMAT); 20 | 21 | // Attach the plugin to the client, which will in turn be attached to all 22 | // requests generated by the client 23 | $client->addSubscriber($logPlugin); 24 | 25 | $response = $client->get('http://google.com')->send(); 26 | 27 | The code sample above wraps a ``Zend_Log`` object using a ``Guzzle\Log\Zf1LogAdapter``. After attaching the plugin to 28 | the client, all data sent over the wire will be logged to stdout. 29 | 30 | The first argument of the LogPlugin's constructor accepts a ``Guzzle\Log\LogAdapterInterface`` object. This object is 31 | an adapter that allows you to use the logging capabilities of your favorite log implementation. The second argument of 32 | the constructor accepts a ``Guzzle\Log\MessageFormatter`` or a log messaged format string. The format string uses 33 | variable substitution and allows you to define the log data that is important to your application. The different 34 | variables that can be injected are as follows: 35 | 36 | ================== ==================================================================================== 37 | Variable Substitution 38 | ================== ==================================================================================== 39 | {request} Full HTTP request message 40 | {response} Full HTTP response message 41 | {ts} Timestamp 42 | {host} Host of the request 43 | {method} Method of the request 44 | {url} URL of the request 45 | {host} Host of the request 46 | {protocol} Request protocol 47 | {version} Protocol version 48 | {resource} Resource of the request (path + query + fragment) 49 | {port} Port of the request 50 | {hostname} Hostname of the machine that sent the request 51 | {code} Status code of the response (if available) 52 | {phrase} Reason phrase of the response (if available) 53 | {curl_error} Curl error message (if available) 54 | {curl_code} Curl error code (if available) 55 | {curl_stderr} Curl standard error (if available) 56 | {connect_time} Time in seconds it took to establish the connection (if available) 57 | {total_time} Total transaction time in seconds for last transfer (if available) 58 | {req_header_*} Replace `*` with the lowercased name of a request header to add to the message 59 | {res_header_*} Replace `*` with the lowercased name of a response header to add to the message 60 | {req_body} Request body 61 | {res_body} Response body 62 | ================== ==================================================================================== 63 | 64 | The LogPlugin has a helper method that can be used when debugging that will output the full HTTP request and 65 | response of a transaction: 66 | 67 | .. code-block:: php 68 | 69 | $client->addSubscriber(LogPlugin::getDebugPlugin()); 70 | -------------------------------------------------------------------------------- /src/ProcessFactory.php: -------------------------------------------------------------------------------- 1 | 21 | */ 22 | class ProcessFactory 23 | { 24 | 25 | /** 26 | * Instancia um objeto de uma das sub-classes de AbstractRetorno, 27 | * com base no tipo do arquivo de retorno indicado por $fileName 28 | * @param string fileName Nome do arquivo de retorno a ser identificado 29 | * para poder instancia a classe específica para leitura do mesmo. 30 | * @return AbstractProcessor Retorna um objeto de uma das sub-classes de AbstractProcessor. 31 | */ 32 | public static function getRetorno($fileName) 33 | { 34 | if (!$fileName) { 35 | throw new InvalidArgumentException("Informe o nome do arquivo de retorno."); 36 | } 37 | 38 | $arq = fopen($fileName, "r"); 39 | if (!$arq) { 40 | throw new FileNotFoundException("Não foi possível abrir o arquivo \"$fileName\"."); 41 | } 42 | 43 | //Lê o header do arquivo 44 | $linha = fgets($arq, 500); 45 | if (!$linha) { 46 | fclose($arq); 47 | throw new HeaderSectionNotFoundException("Tipo de arquivo de retorno não identificado. Não foi possível ler o header do arquivo."); 48 | } 49 | 50 | $len = strlen($linha); 51 | if ($len >= 150 && $len <= 152) { 52 | return new CNAB150Processor($fileName); 53 | } elseif ($len >= 240 && $len <= 242) { 54 | return new CNAB240Processor($fileName); 55 | } elseif ($len >= 400 && $len <= 402) { 56 | if (strstr($linha, "BRADESCO")) { 57 | throw new ReturnFileNotSupportedException('Arquivo de retorno Bradesco não suportado.'); 58 | } 59 | 60 | //Lê o primeiro registro detalhe 61 | $linha = fgets($arq, 500); 62 | if (!$linha) { 63 | throw new DetailSectionNotFoundException("Tipo de arquivo de retorno não identificado. Não foi possível ler um registro detalhe."); 64 | } 65 | switch ($linha[0]) { 66 | case CNAB400Conv6Processor::DETALHE: 67 | return new CNAB400Conv6Processor($fileName); 68 | case CNAB400Conv7Processor::DETALHE: 69 | return new CNAB400Conv7Processor($fileName); 70 | default: 71 | throw new Exception("Tipo de registro detalhe desconhecido: " . $linha[0]); 72 | } 73 | } else { 74 | throw new InvalidHeaderException("Tipo de arquivo de retorno não identificado. Total de colunas do header: $len"); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Header.php: -------------------------------------------------------------------------------- 1 | complementos = new ArrayList(); 33 | parent::__construct(); 34 | } 35 | 36 | public function getTipoOperacao() 37 | { 38 | return $this->tipoOperacao; 39 | } 40 | 41 | public function getIdTipoOperacao() 42 | { 43 | return $this->idTipoOperacao; 44 | } 45 | 46 | public function getIdTipoServico() 47 | { 48 | return $this->idTipoServico; 49 | } 50 | 51 | public function getTipoServico() 52 | { 53 | return $this->tipoServico; 54 | } 55 | 56 | public function getDataGravacao() 57 | { 58 | return $this->dataGravacao; 59 | } 60 | 61 | public function getSequencialReg() 62 | { 63 | return $this->sequencialReg; 64 | } 65 | 66 | public function getCedente() 67 | { 68 | return $this->cedente; 69 | } 70 | 71 | public function setTipoOperacao($tipoOperacao) 72 | { 73 | $this->tipoOperacao = $tipoOperacao; 74 | return $this; 75 | } 76 | 77 | public function setIdTipoOperacao($idTipoOperacao) 78 | { 79 | $this->idTipoOperacao = $idTipoOperacao; 80 | return $this; 81 | } 82 | 83 | public function setIdTipoServico($idTipoServico) 84 | { 85 | $this->idTipoServico = $idTipoServico; 86 | return $this; 87 | } 88 | 89 | public function setTipoServico($tipoServico) 90 | { 91 | $this->tipoServico = $tipoServico; 92 | return $this; 93 | } 94 | 95 | public function setDataGravacao($dataGravacao) 96 | { 97 | $this->dataGravacao = $dataGravacao; 98 | return $this; 99 | } 100 | 101 | public function setSequencialReg($sequencialReg) 102 | { 103 | $this->sequencialReg = $sequencialReg; 104 | return $this; 105 | } 106 | 107 | public function setCedente(Cedente $cedente) 108 | { 109 | $this->cedente = $cedente; 110 | return $this; 111 | } 112 | 113 | public function getComplementos() 114 | { 115 | return $this->complementos; 116 | } 117 | 118 | public function setComplementos(VectorInterface $complementos) 119 | { 120 | $this->complementos = $complementos; 121 | return $this; 122 | } 123 | 124 | public function addComplemento($complemento) 125 | { 126 | $trim = trim($complemento); 127 | if (!empty($trim)) { 128 | $this->complementos->add($complemento); 129 | } 130 | return $this; 131 | } 132 | 133 | public function removeComplemento($complemento) 134 | { 135 | $this->complementos->remove($complemento); 136 | return $this; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Bradesco/DetailBradesco.php: -------------------------------------------------------------------------------- 1 | nossoNumero; 57 | } 58 | 59 | public function getIdRateioCredito() 60 | { 61 | return $this->idRateioCredito; 62 | } 63 | 64 | public function getIdOcorrencia() 65 | { 66 | return $this->idOcorrencia; 67 | } 68 | 69 | public function getNumDocumento() 70 | { 71 | return $this->numDocumento; 72 | } 73 | 74 | public function getDespCobranca() 75 | { 76 | return $this->despCobranca; 77 | } 78 | 79 | public function getJurosAtraso() 80 | { 81 | return $this->jurosAtraso; 82 | } 83 | 84 | public function getMotivoCodOcorrencia() 85 | { 86 | return $this->motivoCodOcorrencia; 87 | } 88 | 89 | public function getNumCartorio() 90 | { 91 | return $this->numCartorio; 92 | } 93 | 94 | public function getNumProtocolo() 95 | { 96 | return $this->numProtocolo; 97 | } 98 | 99 | public function setNossoNumero($nossoNumero) 100 | { 101 | $this->nossoNumero = $nossoNumero; 102 | return $this; 103 | } 104 | 105 | public function setIdRateioCredito($idRateioCredito) 106 | { 107 | $this->idRateioCredito = $idRateioCredito; 108 | return $this; 109 | } 110 | 111 | public function setIdOcorrencia($idOcorrencia) 112 | { 113 | $this->idOcorrencia = $idOcorrencia; 114 | return $this; 115 | } 116 | 117 | public function setNumDocumento($numDocumento) 118 | { 119 | $this->numDocumento = $numDocumento; 120 | return $this; 121 | } 122 | 123 | public function setDespCobranca($despCobranca) 124 | { 125 | $this->despCobranca = $despCobranca; 126 | return $this; 127 | } 128 | 129 | public function setJurosAtraso($jurosAtraso) 130 | { 131 | $this->jurosAtraso = $jurosAtraso; 132 | return $this; 133 | } 134 | 135 | public function setMotivoCodOcorrencia($motivoCodOcorrencia) 136 | { 137 | $this->motivoCodOcorrencia = $motivoCodOcorrencia; 138 | return $this; 139 | } 140 | 141 | public function setNumCartorio($numCartorio) 142 | { 143 | $this->numCartorio = $numCartorio; 144 | return $this; 145 | } 146 | 147 | public function setNumProtocolo($numProtocolo) 148 | { 149 | $this->numProtocolo = $numProtocolo; 150 | return $this; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /tests/Resources/ret/400/CB120400.RET: -------------------------------------------------------------------------------- 1 | 02RETORNO01COBRANCA 00000000000004466911COOPERATIVA DE SERVICOS TECNIC237BRADESCO 1104120160000000042 130412 000001 2 | 1020414679200016800000090142000169102 00000000000000000097000000000000000000000000090211041215 00000000000000000097120412000000000050023700523 000000000025200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000 000002 3 | 1020414679200016800000090142000169102 00000000000000000097000000000000000000000000090611041215 00000000000000000097120412000000000050023701420 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000 130412 00000000000000 000003 4 | 1020414679200016800000090142000169102 000000000000000001860000000000000000000000000917110412 00000000000000000186000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000004 5 | 1020414679200016800000090142000169102 000000000000000001940000000000000000000000000917110412 00000000000000000194000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000005 6 | 1020414679200016800000090142000169102 000000000000000002080000000000000000000000000917110412 00000000000000000208000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000006 7 | 1020414679200016800000090142000169102 000000000000000002160000000000000000000000000917110412 00000000000000000216000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000007 8 | 1020414679200016800000090142000169102 000000000000000002240000000000000000000000000917110412 00000000000000000224000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000008 9 | 9201237 000000010000000000020000000042 00001000000000500000000000500000010000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000 000009 10 | -------------------------------------------------------------------------------- /src/Model/Banco.php: -------------------------------------------------------------------------------- 1 | reservados = new ArrayList(); 32 | } 33 | 34 | public function setReservados(VectorInterface $reservados) 35 | { 36 | $this->reservados = $reservados; 37 | return $this; 38 | } 39 | 40 | public function getReservados() 41 | { 42 | return $this->reservados; 43 | } 44 | 45 | public function getCod() 46 | { 47 | return $this->cod; 48 | } 49 | 50 | public function getAgencia() 51 | { 52 | return $this->agencia; 53 | } 54 | 55 | public function getDvAgencia() 56 | { 57 | return $this->dvAgencia; 58 | } 59 | 60 | public function getConta() 61 | { 62 | return $this->conta; 63 | } 64 | 65 | public function getDvConta() 66 | { 67 | return $this->dvConta; 68 | } 69 | 70 | public function setCod($cod) 71 | { 72 | $this->cod = $cod; 73 | return $this; 74 | } 75 | 76 | /** 77 | * @param string $agencia 78 | */ 79 | public function setAgencia($agencia) 80 | { 81 | $this->agencia = $agencia; 82 | return $this; 83 | } 84 | 85 | /** 86 | * @param string $dvAgencia 87 | */ 88 | public function setDvAgencia($dvAgencia) 89 | { 90 | $this->dvAgencia = $dvAgencia; 91 | return $this; 92 | } 93 | 94 | /** 95 | * @param string $conta 96 | */ 97 | public function setConta($conta) 98 | { 99 | $this->conta = $conta; 100 | return $this; 101 | } 102 | 103 | /** 104 | * @param string $dvConta 105 | */ 106 | public function setDvConta($dvConta) 107 | { 108 | $this->dvConta = $dvConta; 109 | return $this; 110 | } 111 | 112 | public function getDvAgenciaConta() 113 | { 114 | return $this->dvAgenciaConta; 115 | } 116 | 117 | /** 118 | * @param string $dvAgenciaConta 119 | */ 120 | public function setDvAgenciaConta($dvAgenciaConta) 121 | { 122 | $this->dvAgenciaConta = $dvAgenciaConta; 123 | return $this; 124 | } 125 | 126 | public function getNome() 127 | { 128 | return $this->nome; 129 | } 130 | 131 | /** 132 | * @param string $nome 133 | */ 134 | public function setNome($nome) 135 | { 136 | $this->nome = $nome; 137 | return $this; 138 | } 139 | 140 | /** 141 | * @param string $cnab 142 | */ 143 | public function addReservado($cnab) 144 | { 145 | $trim = trim($cnab); 146 | if (!empty($trim)) { 147 | $this->reservados->add($cnab); 148 | } 149 | return $this; 150 | } 151 | 152 | public function removeReservado($cnab) 153 | { 154 | $this->reservados->remove($cnab); 155 | return $this; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /tests/Resources/ret/400/retorno-cb030400-bradesco.ret: -------------------------------------------------------------------------------- 1 | 02RETORNO01COBRANCA 00000000000004466911COOPERATIVA DE SERVICOS TECNIC237BRADESCO 1104120160000000042 130412 000001 2 | 1020414679200016800000090142000169102 00000000000000000097000000000000000000000000090211041215 00000000000000000097120412000000000050023700523 000000000025200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000 000002 3 | 1020414679200016800000090142000169102 00000000000000000097000000000000000000000000090611041215 00000000000000000097120412000000000050023701420 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000 130412 00000000000000 000003 4 | 1020414679200016800000090142000169102 000000000000000001860000000000000000000000000917110412 00000000000000000186000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000004 5 | 1020414679200016800000090142000169102 000000000000000001940000000000000000000000000917110412 00000000000000000194000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000005 6 | 1020414679200016800000090142000169102 000000000000000002080000000000000000000000000917110412 00000000000000000208000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000006 7 | 1020414679200016800000090142000169102 000000000000000002160000000000000000000000000917110412 00000000000000000216000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000007 8 | 1020414679200016800000090142000169102 000000000000000002240000000000000000000000000917110412 00000000000000000224000000000000000000200101886 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000 130412 0000000000 000008 9 | 9201237 000000010000000000020000000042 00001000000000500000000000500000010000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000 000009 10 | -------------------------------------------------------------------------------- /docs/events/creating-plugins.rst: -------------------------------------------------------------------------------- 1 | ================ 2 | Creating plugins 3 | ================ 4 | 5 | .. highlight:: php 6 | 7 | Guzzle is extremely extensible because of the behavioral modifications that can be added to requests, clients, and 8 | commands using an event system. Before and after the majority of actions are taken in the library, an event is emitted 9 | with the name of the event and context surrounding the event. Observers can subscribe to a subject and modify the 10 | subject based on the events received. Guzzle's event system utilizes the Symfony2 EventDispatcher and is the backbone 11 | of its plugin architecture. 12 | 13 | Overview 14 | -------- 15 | 16 | Plugins must implement the ``Symfony\Component\EventDispatcher\EventSubscriberInterface`` interface. The 17 | ``EventSubscriberInterface`` requires that your class implements a static method, ``getSubscribedEvents()``, that 18 | returns an associative array mapping events to methods on the object. See the 19 | `Symfony2 documentation `_ for more information. 20 | 21 | Plugins can be attached to any subject, or object in Guzzle that implements that 22 | ``Guzzle\Common\HasDispatcherInterface``. 23 | 24 | Subscribing to a subject 25 | ~~~~~~~~~~~~~~~~~~~~~~~~ 26 | 27 | You can subscribe an instantiated observer to an event by calling ``addSubscriber`` on a subject. 28 | 29 | .. code-block:: php 30 | 31 | $testPlugin = new TestPlugin(); 32 | $client->addSubscriber($testPlugin); 33 | 34 | You can also subscribe to only specific events using a closure:: 35 | 36 | $client->getEventDispatcher()->addListener('request.create', function(Event $event) { 37 | echo $event->getName(); 38 | echo $event['request']; 39 | }); 40 | 41 | ``Guzzle\Common\Event`` objects are passed to notified functions. The Event object has a ``getName()`` method which 42 | return the name of the emitted event and may contain contextual information that can be accessed like an array. 43 | 44 | Knowing what events to listen to 45 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 46 | 47 | Any class that implements the ``Guzzle\Common\HasDispatcherInterface`` must implement a static method, 48 | ``getAllEvents()``, that returns an array of the events that are emitted from the object. You can browse the source 49 | to see each event, or you can call the static method directly in your code to get a list of available events. 50 | 51 | Event hooks 52 | ----------- 53 | 54 | * :ref:`client-events` 55 | * :ref:`service-client-events` 56 | * :ref:`request-events` 57 | * ``Guzzle\Http\Curl\CurlMulti``: 58 | * :ref:`service-builder-events` 59 | 60 | Examples of the event system 61 | ---------------------------- 62 | 63 | Simple Echo plugin 64 | ~~~~~~~~~~~~~~~~~~ 65 | 66 | This simple plugin prints a string containing the request that is about to be sent by listening to the 67 | ``request.before_send`` event:: 68 | 69 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; 70 | 71 | class EchoPlugin implements EventSubscriberInterface 72 | { 73 | public static function getSubscribedEvents() 74 | { 75 | return array('request.before_send' => 'onBeforeSend'); 76 | } 77 | 78 | public function onBeforeSend(Guzzle\Common\Event $event) 79 | { 80 | echo 'About to send a request: ' . $event['request'] . "\n"; 81 | } 82 | } 83 | 84 | $client = new Guzzle\Service\Client('http://www.test.com/'); 85 | 86 | // Create the plugin and add it as an event subscriber 87 | $plugin = new EchoPlugin(); 88 | $client->addSubscriber($plugin); 89 | 90 | // Send a request and notice that the request is printed to the screen 91 | $client->get('/')->send(); 92 | 93 | Running the above code will print a string containing the HTTP request that is about to be sent. 94 | -------------------------------------------------------------------------------- /docs/component/http-redirects.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | HTTP redirects 3 | ============== 4 | 5 | By default, Guzzle will automatically follow redirects using the non-RFC compliant implementation used by most web 6 | browsers. This means that redirects for POST requests are followed by a GET request. You can force RFC compliance by 7 | enabling the strict mode on a request's parameter object: 8 | 9 | .. code-block:: php 10 | 11 | // Set per request 12 | $request = $client->post(); 13 | $request->getParams()->set('redirect.strict', true); 14 | 15 | // You can set globally on a client so all requests use strict redirects 16 | $client->getConfig()->set('request.params', array( 17 | 'redirect.strict' => true 18 | )); 19 | 20 | By default, Guzzle will redirect up to 5 times before throwing a ``Guzzle\Http\Exception\TooManyRedirectsException``. 21 | You can raise or lower this value using the ``redirect.max`` parameter of a request object: 22 | 23 | .. code-block:: php 24 | 25 | $request->getParams()->set('redirect.max', 2); 26 | 27 | Redirect history 28 | ---------------- 29 | 30 | You can get the number of redirects of a request using the resulting response object's ``getRedirectCount()`` method. 31 | Similar to cURL's ``effective_url`` property, Guzzle provides the effective URL, or the last redirect URL that returned 32 | the request, in a response's ``getEffectiveUrl()`` method. 33 | 34 | When testing or debugging, it is often useful to see a history of redirects for a particular request. This can be 35 | achieved using the HistoryPlugin. 36 | 37 | .. code-block:: php 38 | 39 | $request = $client->get('/'); 40 | $history = new Guzzle\Plugin\History\HistoryPlugin(); 41 | $request->addSubscriber($history); 42 | $response = $request->send(); 43 | 44 | // Get the last redirect URL or the URL of the request that received 45 | // this response 46 | echo $response->getEffectiveUrl(); 47 | 48 | // Get the number of redirects 49 | echo $response->getRedirectCount(); 50 | 51 | // Iterate over each sent request and response 52 | foreach ($history->getAll() as $transaction) { 53 | // Request object 54 | echo $transaction['request']->getUrl() . "\n"; 55 | // Response object 56 | echo $transaction['response']->getEffectiveUrl() . "\n"; 57 | } 58 | 59 | // Or, simply cast the HistoryPlugin to a string to view each request and response 60 | echo $history; 61 | 62 | Disabling redirects 63 | ------------------- 64 | 65 | You can disable redirects on a client by passing a configuration option in the client's constructor: 66 | 67 | .. code-block:: php 68 | 69 | $client = new Client(null, array('redirect.disable' => true)); 70 | 71 | You can also disable redirects per request: 72 | 73 | .. code-block:: php 74 | 75 | $request = $client->get($url, array(), array('allow_redirects' => false)); 76 | 77 | Redirects and non-repeatable streams 78 | ------------------------------------ 79 | 80 | If you are redirected when sending data from a non-repeatable stream and some of the data has been read off of the 81 | stream, then you will get a ``Guzzle\Http\Exception\CouldNotRewindStreamException``. You can get around this error by 82 | adding a custom rewind method to the entity body object being sent in the request. 83 | 84 | .. code-block:: php 85 | 86 | $request = $client->post( 87 | 'http://httpbin.com/redirect/2', 88 | null, 89 | fopen('http://httpbin.com/get', 'r') 90 | ); 91 | 92 | // Add a custom function that can be used to rewind the stream 93 | // (reopen in this example) 94 | $request->getBody()->setRewindFunction(function ($body) { 95 | $body->setStream(fopen('http://httpbin.com/get', 'r')); 96 | return true; 97 | ); 98 | 99 | $response = $client->send(); 100 | -------------------------------------------------------------------------------- /src/Cnab/Cnab150/Detail.php: -------------------------------------------------------------------------------- 1 | numeroSequencial; 32 | } 33 | 34 | public function setNumeroSequencial($numeroSequencial) 35 | { 36 | $this->numeroSequencial = $numeroSequencial; 37 | return $this; 38 | } 39 | 40 | public function getDataPagamento() 41 | { 42 | return $this->dataPagamento; 43 | } 44 | 45 | public function getDataCredito() 46 | { 47 | return $this->dataCredito; 48 | } 49 | 50 | public function getValorTitulo() 51 | { 52 | return $this->valorTitulo; 53 | } 54 | 55 | public function getValorPagamento() 56 | { 57 | return $this->valorPagamento; 58 | } 59 | 60 | public function getValorRecebido() 61 | { 62 | return $this->valorRecebido; 63 | } 64 | 65 | public function getValorTarifa() 66 | { 67 | return $this->valorTarifa; 68 | } 69 | 70 | public function getCodigoAgenciaArrecadadora() 71 | { 72 | return $this->codigoAgenciaArrecadadora; 73 | } 74 | 75 | public function getFormaArrecadacao() 76 | { 77 | return $this->formaArrecadacao; 78 | } 79 | 80 | public function getNumeroAutenticacao() 81 | { 82 | return $this->numeroAutenticacao; 83 | } 84 | 85 | public function getFormaPagamento() 86 | { 87 | return $this->formaPagamento; 88 | } 89 | 90 | public function setDataPagamento(DateTime $dataPagamento) 91 | { 92 | $this->dataPagamento = $dataPagamento; 93 | return $this; 94 | } 95 | 96 | public function setDataCredito(DateTime $dataCredito) 97 | { 98 | $this->dataCredito = $dataCredito; 99 | return $this; 100 | } 101 | 102 | public function setValorTitulo($valorTitulo) 103 | { 104 | $this->valorTitulo = $valorTitulo; 105 | return $this; 106 | } 107 | 108 | public function setValorPagamento($valorPagamento) 109 | { 110 | $this->valorPagamento = $valorPagamento; 111 | return $this; 112 | } 113 | 114 | public function setValorRecebido($valorRecebido) 115 | { 116 | $this->valorRecebido = $valorRecebido; 117 | return $this; 118 | } 119 | 120 | public function setValorTarifa($valorTarifa) 121 | { 122 | $this->valorTarifa = $valorTarifa; 123 | return $this; 124 | } 125 | 126 | public function setCodigoAgenciaArrecadadora($codigoAgenciaArrecadadora) 127 | { 128 | $this->codigoAgenciaArrecadadora = $codigoAgenciaArrecadadora; 129 | return $this; 130 | } 131 | 132 | public function setFormaArrecadacao($formaArrecadacao) 133 | { 134 | $this->formaArrecadacao = $formaArrecadacao; 135 | return $this; 136 | } 137 | 138 | public function setNumeroAutenticacao($numeroAutenticacao) 139 | { 140 | $this->numeroAutenticacao = $numeroAutenticacao; 141 | return $this; 142 | } 143 | 144 | public function setFormaPagamento($formaPagamento) 145 | { 146 | $this->formaPagamento = $formaPagamento; 147 | return $this; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/Model/Empresa.php: -------------------------------------------------------------------------------- 1 | reservados = new ArrayList(); 42 | $this->usos = new ArrayList(); 43 | } 44 | 45 | public function getCod() 46 | { 47 | return $this->cod; 48 | } 49 | 50 | public function setCod($cod) 51 | { 52 | $this->cod = $cod; 53 | return $this; 54 | } 55 | 56 | public function getTipoInscricao() 57 | { 58 | return $this->tipoInscricao; 59 | } 60 | 61 | public function getNumInscricao() 62 | { 63 | return $this->numInscricao; 64 | } 65 | 66 | public function getNome() 67 | { 68 | return $this->nome; 69 | } 70 | 71 | public function getEndereco() 72 | { 73 | return $this->endereco; 74 | } 75 | 76 | public function getUsos() 77 | { 78 | return $this->usos; 79 | } 80 | 81 | /** 82 | * @param string $tipoInscricao 83 | */ 84 | public function setTipoInscricao($tipoInscricao) 85 | { 86 | $this->tipoInscricao = $tipoInscricao; 87 | return $this; 88 | } 89 | 90 | /** 91 | * @param string $numInscricao 92 | */ 93 | public function setNumInscricao($numInscricao) 94 | { 95 | $this->numInscricao = $numInscricao; 96 | return $this; 97 | } 98 | 99 | /** 100 | * @param string $nome 101 | */ 102 | public function setNome($nome) 103 | { 104 | $this->nome = $nome; 105 | return $this; 106 | } 107 | 108 | public function setEndereco(Endereco $endereco) 109 | { 110 | $this->endereco = $endereco; 111 | return $this; 112 | } 113 | 114 | public function setUsos(VectorInterface $usos) 115 | { 116 | $this->usos = $usos; 117 | return $this; 118 | } 119 | 120 | /** 121 | * @param Stringy $uso 122 | * @return $this 123 | */ 124 | public function addUso(Stringy $uso) 125 | { 126 | $uso = $uso->trim(); 127 | if (!$uso->isBlank()) { 128 | $this->usos->add($uso); 129 | } 130 | return $this; 131 | } 132 | 133 | public function removeUso($uso) 134 | { 135 | $this->usos->remove($uso); 136 | return $this; 137 | } 138 | 139 | /** 140 | * @param Stringy $cnab 141 | * @return $this 142 | */ 143 | public function addReservado(Stringy $cnab) 144 | { 145 | $cnab = $cnab->trim(); 146 | if (!$cnab->isBlank()) { 147 | $this->reservados->add($cnab); 148 | } 149 | return $this; 150 | } 151 | 152 | public function removeReservado($cnab) 153 | { 154 | $this->reservados->remove($cnab); 155 | return $this; 156 | } 157 | 158 | public function getReservados() 159 | { 160 | return $this->reservados; 161 | } 162 | 163 | public function setReservados(VectorInterface $reservados) 164 | { 165 | $this->reservados = $reservados; 166 | return $this; 167 | } 168 | 169 | public function getBanco() 170 | { 171 | return $this->banco; 172 | } 173 | 174 | public function setBanco(Banco $banco) 175 | { 176 | $this->banco = $banco; 177 | return $this; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/Cnab/AbstractCnab.php: -------------------------------------------------------------------------------- 1 | cnabs = new ArrayList(); 47 | $this->ocorrencias = new ArrayList(); 48 | } 49 | 50 | /** 51 | * @return Sacado 52 | */ 53 | public function getSacado() 54 | { 55 | return $this->sacado; 56 | } 57 | 58 | /** 59 | * @param Sacado $sacado 60 | * @return $this 61 | */ 62 | public function setSacado(Sacado $sacado) 63 | { 64 | $this->sacado = $sacado; 65 | return $this; 66 | } 67 | 68 | /** 69 | * @param string $cnab 70 | * @return $this 71 | */ 72 | public function addCnab($cnab) 73 | { 74 | $trim = trim($cnab); 75 | if (!empty($trim)) { 76 | $this->cnabs->add($cnab); 77 | } 78 | return $this; 79 | } 80 | 81 | public function removeCnab($cnab) 82 | { 83 | $this->cnabs->remove($cnab); 84 | return $this; 85 | } 86 | 87 | public function getCnabs() 88 | { 89 | return $this->cnabs; 90 | } 91 | 92 | public function setCnabs(VectorInterface $cnabs) 93 | { 94 | $this->cnabs = $cnabs; 95 | return $this; 96 | } 97 | 98 | public function getRegistro() 99 | { 100 | return $this->registro; 101 | } 102 | 103 | public function getLote() 104 | { 105 | return $this->lote; 106 | } 107 | 108 | public function getCedente() 109 | { 110 | return $this->cedente; 111 | } 112 | 113 | /** 114 | * @param string $registro 115 | * @return $this 116 | */ 117 | public function setRegistro($registro) 118 | { 119 | $this->registro = $registro; 120 | return $this; 121 | } 122 | 123 | /** 124 | * @param string $lote 125 | * @return $this 126 | */ 127 | public function setLote($lote) 128 | { 129 | $this->lote = $lote; 130 | return $this; 131 | } 132 | 133 | public function setCedente(Cedente $cedente) 134 | { 135 | $this->cedente = $cedente; 136 | return $this; 137 | } 138 | 139 | public function getOcorrencias() 140 | { 141 | return $this->ocorrencias; 142 | } 143 | 144 | public function setOcorrencias(VectorInterface $ocorrencias) 145 | { 146 | $this->ocorrencias = $ocorrencias; 147 | return $this; 148 | } 149 | 150 | public function getEmpresa() 151 | { 152 | return $this->empresa; 153 | } 154 | 155 | public function setEmpresa(Empresa $empresa) 156 | { 157 | $this->empresa = $empresa; 158 | return $this; 159 | } 160 | 161 | /** 162 | * @param string $ocorrencia 163 | * @return $this 164 | */ 165 | public function addOcorrencia($ocorrencia) 166 | { 167 | $trim = trim($ocorrencia); 168 | if (!empty($trim)) { 169 | $this->ocorrencias->add($ocorrencia); 170 | } 171 | return $this; 172 | } 173 | 174 | public function removeOcorrencia($ocorrencia) 175 | { 176 | $this->ocorrencias->remove($ocorrencia); 177 | return $this; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Trailer.php: -------------------------------------------------------------------------------- 1 | brancos = new ArrayList(); 55 | parent::__construct(); 56 | } 57 | 58 | public function getRetorno() 59 | { 60 | return $this->retorno; 61 | } 62 | 63 | public function getTipoRegistro() 64 | { 65 | return $this->tipoRegistro; 66 | } 67 | 68 | public function getSequencial() 69 | { 70 | return $this->sequencial; 71 | } 72 | 73 | public function getBanco() 74 | { 75 | return $this->banco; 76 | } 77 | 78 | public function getSimples() 79 | { 80 | return $this->simples; 81 | } 82 | 83 | public function getVinculada() 84 | { 85 | return $this->vinculada; 86 | } 87 | 88 | public function getCaucionada() 89 | { 90 | return $this->caucionada; 91 | } 92 | 93 | public function getVendor() 94 | { 95 | return $this->vendor; 96 | } 97 | 98 | public function getDescontada() 99 | { 100 | return $this->descontada; 101 | } 102 | 103 | public function setRetorno($retorno) 104 | { 105 | $this->retorno = $retorno; 106 | return $this; 107 | } 108 | 109 | public function setTipoRegistro($tipoRegistro) 110 | { 111 | $this->tipoRegistro = $tipoRegistro; 112 | return $this; 113 | } 114 | 115 | public function setSequencial($sequencial) 116 | { 117 | $this->sequencial = $sequencial; 118 | return $this; 119 | } 120 | 121 | public function setBanco(Banco $banco) 122 | { 123 | $this->banco = $banco; 124 | return $this; 125 | } 126 | 127 | public function setSimples(Cobranca $simples) 128 | { 129 | $this->simples = $simples; 130 | return $this; 131 | } 132 | 133 | public function setVinculada(Cobranca $vinculada) 134 | { 135 | $this->vinculada = $vinculada; 136 | return $this; 137 | } 138 | 139 | public function setCaucionada(Cobranca $caucionada) 140 | { 141 | $this->caucionada = $caucionada; 142 | return $this; 143 | } 144 | 145 | public function setVendor(Cobranca $vendor) 146 | { 147 | $this->vendor = $vendor; 148 | return $this; 149 | } 150 | 151 | public function setDescontada(Cobranca $descontada) 152 | { 153 | $this->descontada = $descontada; 154 | return $this; 155 | } 156 | 157 | public function getBrancos() 158 | { 159 | return $this->brancos; 160 | } 161 | 162 | public function setBrancos($brancos) 163 | { 164 | $this->brancos = $brancos; 165 | return $this; 166 | } 167 | 168 | /** 169 | * @param string $zeros 170 | */ 171 | public function addBranco($zeros) 172 | { 173 | $this->brancos->add($zeros); 174 | return $this; 175 | } 176 | 177 | public function removeBranco($zeros) 178 | { 179 | $this->brancos->remove($zeros); 180 | return $this; 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /src/AbstractProcessor.php: -------------------------------------------------------------------------------- 1 | 11 | * @author Ítalo Lelis de Vietro 12 | */ 13 | abstract class AbstractProcessor 14 | { 15 | /** 16 | * @property string $nomeArquivo Nome do arquivo de texto a ser lido 17 | */ 18 | protected $nomeArquivo = ""; 19 | protected $needToCreateLote = false; 20 | 21 | /** 22 | * Construtor da classe. 23 | * @param string $nomeArquivo Nome do arquivo de retorno do banco. 24 | */ 25 | public function __construct($nomeArquivo = null) 26 | { 27 | if (isset($nomeArquivo)) { 28 | $this->setNomeArquivo($nomeArquivo); 29 | } 30 | } 31 | 32 | public function needToCreateLote() 33 | { 34 | return $this->needToCreateLote; 35 | } 36 | 37 | public function setNeedToCreateLote($needToCreateLote) 38 | { 39 | $this->needToCreateLote = $needToCreateLote; 40 | return $this; 41 | } 42 | 43 | /** 44 | * Setter para o atributo 45 | * @param string $nomeArquivo 46 | */ 47 | public function setNomeArquivo($nomeArquivo) 48 | { 49 | $this->nomeArquivo = $nomeArquivo; 50 | } 51 | 52 | /** 53 | * Getter para o atributo 54 | */ 55 | public function getNomeArquivo() 56 | { 57 | return $this->nomeArquivo; 58 | } 59 | 60 | /** 61 | * Processa uma linha do arquivo de retorno. O método é abstrato e deve ser implementado nas sub-classes. 62 | * @param int $numLn Número da linha a ser processada 63 | * @param string $linha String contendo a linha a ser processada 64 | * @return ComposableInterface Retorna um vetor associativo contendo os valores da linha processada. 65 | */ 66 | public abstract function processarLinha($numLn, Stringy $linha); 67 | 68 | public abstract function processCnab(RetornoInterface $retorno, ComposableInterface $composable, 69 | LoteInterface $lote = null); 70 | 71 | /** 72 | * Formata uma string, contendo um valor real (float) sem o separador de decimais, 73 | * para a sua correta representação real. 74 | * @param string $valor String contendo o valor na representação 75 | * usada nos arquivos de retorno do banco, sem o separador de decimais. 76 | * @param int $numCasasDecimais Total de casas decimais do número 77 | * representado em $valor. 78 | * @return float Retorna o número representado em $valor, no seu formato float, 79 | * contendo o separador de decimais. 80 | */ 81 | public function formataNumero($valor, $numCasasDecimais = 2) 82 | { 83 | if (empty($valor)) { 84 | return 0; 85 | } 86 | $casas = $numCasasDecimais; 87 | if ($casas > 0) { 88 | $valor = substr($valor, 0, strlen($valor) - $casas) . "." . substr($valor, strlen($valor) - $casas, $casas); 89 | $valor = (float)$valor; 90 | } else { 91 | $valor = (int)$valor; 92 | } 93 | 94 | return $valor; 95 | } 96 | 97 | /** 98 | * Formata uma string, contendo uma data sem o separador, no formato DDMMAA. 99 | * @param string $date String contendo a data no formato DDMMAA. 100 | * @return DateTime 101 | */ 102 | public function createDate($date, $format = "dmy") 103 | { 104 | if (empty($date)) { 105 | return ""; 106 | } 107 | 108 | return DateTime::createFromFormat($format, $date); 109 | } 110 | 111 | /** 112 | * Formata uma string, contendo uma data sem o separador, no formato DDMMAA HHIISS. 113 | * @param string $dateTimeString String contendo a data no formato DDMMAA. 114 | * @return DateTime 115 | */ 116 | public function createDateTime($dateTimeString, $format = "mdy His") 117 | { 118 | if (empty($dateTimeString)) { 119 | return ""; 120 | } 121 | 122 | return DateTime::createFromFormat($format, $dateTimeString); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /tests/Resources/ret/150/RCB001455608201413819.ret: -------------------------------------------------------------------------------- 1 | A2110288 JUCEP 001BANCO DO BRASIL S/A2014080600045404 2 | G161870003089711 2014080520140807856300000026000042220140810000000001000327200000000260000000098000000010151 299E1045DA5C46A19 1 3 | G161870003089711 2014080520140807856200000003430042220140810000000000085008610000000034300000098000000020200 47F94B4DC91568145 1 4 | G161870003089711 2014080520140807856200000009000042220140805000000001000324250000000090000000098000000030521 4F03B87B0F2170EB1 1 5 | G161870003089711 2014080520140807856000000009000042220140810000000001000327340000000090000000098000000040585 4D280BE7A44104028 1 6 | G161870003089711 2014080520140807856200000009000042220140810000000001000327330000000090000000098000000050585 43B8C733C3B029C4B 1 7 | G161870003089711 2014080520140807856200000007840042220140726000000000084991970000000078400000098000000060585 276738516279F422A 1 8 | G161870003089711 2014080520140807856500000026000042220140810000000000085008600000000260000000098000000070614 2D2C6B77D23F7B261 1 9 | G161870003089711 2014080520140807856200000001640042220140805000000000085005050000000016400000098000000080711 23D8F38FF241C39DF 1 10 | G161870003089711 2014080520140807856600000007840042220140810000000000085008710000000078400000098000000090991 325BCBF8C29C7060D 1 11 | G161870003089711 2014080520140807856200000009000042220140806000000001000325660000000090000000098000000101106 31F7ACBFF1D1E3E67 1 12 | G161870003089711 2014080520140807856400000009000042220140805000000001000324050000000090000000098000000111165 4EAD75B0DF538C99F 1 13 | G161870003089711 2014080520140807856300000006160042220140809000000000085007480000000061600000098000000121449 465E2200EA6AD3E73 1 14 | G161870003089711 2014080520140807856800000026000042220140809000000001000326150000000260000000098000000131449 437351120A6E0C247 1 15 | G161870003089711 2014080520140807856400000009000042220140810000000001000327270000000090000000098000000142418 46C0BC01E38BC2BBD 1 16 | G161870003089711 2014080520140807856900000011960042220140805000000000085004420000000119600000098000000152434 2A3C7A115BCF114F6 1 17 | G161870003089711 2014080520140807856700000011960042220140805000000000085004430000000119600000098000000162434 28ECF2EAD712FF2A9 1 18 | G161870003089711 2014080520140807856000000023760042220140805000000000085004160000000237600000098000000172434 2D4DE1264DFB8CB0A 1 19 | G161870003089711 2014080520140807856900000023760042220140805000000000085004260000000237600000098000000182434 2D1B1DE5DF98340DB 1 20 | G161870003089711 2014080520140807856500000023760042220140805000000000085004280000000237600000098000000192434 25A34F757D51D53D2 1 21 | G161870003089711 2014080520140807856100000023760042220140805000000000085004300000000237600000098000000202434 299A4A1A9D126C270 1 22 | G161870003089711 2014080520140807856900000023760042220140805000000000085004310000000237600000098000000212434 2070643CFA6BC4ECB 1 23 | G161870003089711 2014080520140807856700000023760042220140805000000000085004320000000237600000098000000222434 20577D40C505C18DA 1 24 | G161870003089711 2014080520140807856300000026000042220140805000000000085004020000000260000000098000000232811 4E1D1B807AC3B32BD 1 25 | G161870003089711 2014080520140807856100000002050042220140809000000000085008490000000020500000098000000243174 29EACDA57A1C7162B 1 26 | G161870003089711 2014080520140807856500000026000042220140809000000000085008470000000260000000098000000253174 2D3907A7FA1557AD9 1 27 | G161870003089711 2014080520140807856300000026000042220140809000000000085008480000000260000000098000000263174 2B43685D12AD9E7BA 1 28 | G161870003089711 2014080520140807856500000300840042220140806000000000085006470000003008400000098000000273344 25064D6F7071A5E42 1 29 | G161870003089711 2014080520140807856500000007840042220140809000000000085007930000000078400000098000000288353 1A2A12EDAA847DC8A 1 30 | Z00003000000000000714120 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ya Retorno Boleto 2 | 3 | [![Build Status](http://img.shields.io/travis/umbrellaTech/ya-retorno-boleto.svg?style=flat-square)](https://travis-ci.org/umbrellaTech/ya-retorno-boleto) 4 | [![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/umbrellaTech/ya-retorno-boleto.svg?style=flat-square)](https://scrutinizer-ci.com/g/umbrellaTech/ya-retorno-boleto/) 5 | [![Code Coverage](http://img.shields.io/scrutinizer/coverage/g/umbrellaTech/ya-retorno-boleto.svg?style=flat-square)](https://scrutinizer-ci.com/g/umbrellaTech/ya-retorno-boleto/) 6 | [![Latest Stable Version](http://img.shields.io/packagist/v/umbrella/retorno-boleto.svg?style=flat-square)](https://packagist.org/packages/umbrella/retorno-boleto) 7 | [![Downloads](https://img.shields.io/packagist/dt/umbrella/retorno-boleto.svg?style=flat-square)](https://packagist.org/packages/umbrella/retorno-boleto) 8 | 9 | 10 | [![SensioLabsInsight](https://insight.sensiolabs.com/projects/ef6e9331-a2ad-4a22-bc43-1dd7c28ae086/small.png)](https://insight.sensiolabs.com/projects/ef6e9331-a2ad-4a22-bc43-1dd7c28ae086) 11 | 12 | O que é? 13 | --- 14 | Biblioteca em PHP para leitura de arquivos de retorno de títulos de cobrança de bancos brasileiros. 15 | 16 | Arquivos suportados: 17 | 18 | | **Banco** | **CNAB** | **Implementado** | **Testado** | 19 | |---------------------|--------------------------|--------------------|---------------| 20 | | **Banco do Brasil** | 150, 240,400 | Sim | Sim | 21 | | **Bradesco** | 400 - personalizado | Não | Não | 22 | | **Caixa Economica** | 150, 240 | Sim | Sim | 23 | | **HSBC** | 150, 240,400 | Sim | Sim | 24 | | **Itau** | 150, 240,400 | Sim | Sim | 25 | | **Santander** | 150, 240,400 | Sim | Sim | 26 | 27 | Instalação 28 | ---------- 29 | 30 | ```bash 31 | # Install Composer 32 | curl -sS https://getcomposer.org/installer | php 33 | 34 | # Adicionando YA Retorno Boleto como dependencia 35 | php composer.phar require umbrella/retorno-boleto:~1.2 36 | ``` 37 | 38 | Após a instalação, é necessário carregar o autoloader do composer: 39 | 40 | ```php 41 | require 'vendor/autoload.php'; 42 | ``` 43 | 44 | Uso 45 | ---------- 46 | 47 | Para lermos um arquivo de retorno, utilizamos uma factory que nos dirao tipo correto do arquivo e passaremos ele para um processador que irá lhe retornar o objeto do arquivo de retorno. 48 | 49 | ```php 50 | use Umbrella\Ya\RetornoBoleto\ProcessFactory; 51 | use Umbrella\Ya\RetornoBoleto\ProcessHandler; 52 | 53 | // Utilizamos a factory para construir o objeto correto para um determinado arquivo de retorno 54 | $cnab = ProcessFactory::getRetorno('arquivo-retorno.ret'); 55 | 56 | // Passamos o objeto contruido para o handler 57 | $processor = new ProcessHandler($cnab); 58 | 59 | // Processamos o arquivo. Isso retornará um objeto parseado com todas as propriedades do arquvio. 60 | $retorno = $processor->processar(); 61 | ``` 62 | 63 | Eventos 64 | ---------- 65 | 66 | O retorno-boleto tem suporte a eventos utilizando o componente [EventDispatcher](http://symfony.com/doc/current/components/event_dispatcher/introduction.html) do symfony. 67 | 68 | ```php 69 | use Umbrella\Ya\RetornoBoleto\Event\OnDetailRegisterEvent; 70 | use Umbrella\Ya\RetornoBoleto\ProcessFactory; 71 | use Umbrella\Ya\RetornoBoleto\ProcessHandler; 72 | use Umbrella\Ya\RetornoBoleto\RetornoEvents; 73 | 74 | // Passamos o objeto contruido para o handler 75 | $processor = new ProcessHandler($cnab); 76 | 77 | $processor->getDispatcher()->addListener(RetornoEvents::ON_DETAIL_REGISTER, 78 | function(OnDetailRegisterEvent $event) use($self, &$count) { 79 | echo $event->getLineNumber() . PHP_EOL; 80 | }); 81 | 82 | ``` 83 | 84 | Atualmente temos os seguintes eventos: 85 | 86 | | **Evento** | **Event Class** | **Descrição** | 87 | |------------------------|--------------------------|------------------------------------------| 88 | | **ON_DETAIL_REGISTER** | OnDetailRegisterEvent | Lançado sempre que um registro é iterado | 89 | 90 | 91 | Demo 92 | ---------- 93 | 94 | A aplicação de demonstração está no repositório [Ya Boleto Demo](https://github.com/umbrellaTech/ya-boleto-demo) 95 | 96 | Documentação 97 | ---------- 98 | 99 | Mais informações podem ser encontradas na documentação on-line em http://ya-retorno-boleto.readthedocs.org/pt_BR/latest/. 100 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/Convenio/DetailConvenio.php: -------------------------------------------------------------------------------- 1 | usoBanco = new ArrayList(); 33 | } 34 | 35 | public function getConvenio() 36 | { 37 | return $this->convenio; 38 | } 39 | 40 | public function getControle() 41 | { 42 | return $this->controle; 43 | } 44 | 45 | public function getNossoNumero() 46 | { 47 | return $this->nossoNumero; 48 | } 49 | 50 | public function getDvNossoNumero() 51 | { 52 | return $this->dvNossoNumero; 53 | } 54 | 55 | public function getTipoCobranca() 56 | { 57 | return $this->tipoCobranca; 58 | } 59 | 60 | public function getTipoCobrancaCmd72() 61 | { 62 | return $this->tipoCobrancaCmd72; 63 | } 64 | 65 | public function getDiasCalculo() 66 | { 67 | return $this->diasCalculo; 68 | } 69 | 70 | public function getNatureza() 71 | { 72 | return $this->natureza; 73 | } 74 | 75 | public function getVariacaoCarteira() 76 | { 77 | return $this->variacaoCarteira; 78 | } 79 | 80 | public function getContaCaucao() 81 | { 82 | return $this->contaCaucao; 83 | } 84 | 85 | public function getConfirmacao() 86 | { 87 | return $this->confirmacao; 88 | } 89 | 90 | public function getUsoBanco() 91 | { 92 | return $this->usoBanco; 93 | } 94 | 95 | public function setConvenio($convenio) 96 | { 97 | $this->convenio = $convenio; 98 | return $this; 99 | } 100 | 101 | public function setControle($controle) 102 | { 103 | $this->controle = $controle; 104 | return $this; 105 | } 106 | 107 | public function setNossoNumero($nossoNumero) 108 | { 109 | $this->nossoNumero = $nossoNumero; 110 | return $this; 111 | } 112 | 113 | public function setDvNossoNumero($dvNossoNumero) 114 | { 115 | $this->dvNossoNumero = $dvNossoNumero; 116 | return $this; 117 | } 118 | 119 | public function setTipoCobranca($tipoCobranca) 120 | { 121 | $this->tipoCobranca = $tipoCobranca; 122 | return $this; 123 | } 124 | 125 | public function setTipoCobrancaCmd72($tipoCobrancaCmd72) 126 | { 127 | $this->tipoCobrancaCmd72 = $tipoCobrancaCmd72; 128 | return $this; 129 | } 130 | 131 | public function setDiasCalculo($diasCalculo) 132 | { 133 | $this->diasCalculo = $diasCalculo; 134 | return $this; 135 | } 136 | 137 | public function setNatureza($natureza) 138 | { 139 | $this->natureza = $natureza; 140 | return $this; 141 | } 142 | 143 | public function setVariacaoCarteira($variacaoCarteira) 144 | { 145 | $this->variacaoCarteira = $variacaoCarteira; 146 | return $this; 147 | } 148 | 149 | public function setContaCaucao($contaCaucao) 150 | { 151 | $this->contaCaucao = $contaCaucao; 152 | return $this; 153 | } 154 | 155 | public function setConfirmacao($confirmacao) 156 | { 157 | $this->confirmacao = $confirmacao; 158 | return $this; 159 | } 160 | 161 | public function setUsoBanco(VectorInterface $usoBanco) 162 | { 163 | $this->usoBanco = $usoBanco; 164 | return $this; 165 | } 166 | 167 | public function addUsoBanco($usoBanco) 168 | { 169 | $trim = trim($usoBanco); 170 | if (!empty($trim)) { 171 | $this->usoBanco->add($usoBanco); 172 | } 173 | 174 | return $this; 175 | } 176 | 177 | public function removeUsoBanco($usoBanco) 178 | { 179 | $this->usoBanco->remove($usoBanco); 180 | return $this; 181 | } 182 | 183 | public function getPrefixoTitulo() 184 | { 185 | return $this->prefixoTitulo; 186 | } 187 | 188 | public function setPrefixoTitulo($prefixoTitulo) 189 | { 190 | $this->prefixoTitulo = $prefixoTitulo; 191 | return $this; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /tests/Resources/ret/240/RETORNOCEF120814.ret: -------------------------------------------------------------------------------- 1 | 10400000 2080857710001300000000000000000000000560640115100000000UPANEMA PREFEITURA C ECON FEDERAL 21108201402393200015804000000 RETORNO-PRODUCAO 000 2 | 10400011T0100030 20080857710001300000000000000000000000560640115100000000UPANEMA PREFEITURA 00000158110820140000000000 00 3 | 1040001300001T 060000004011510000000 241400000010010948100000000000000011082014000000000000750000005600000000000000000 090000000000000000 000000000000155020101 4 | 1040001300002U 06000000000000000000000000000000000000000000000000000000000000000000000000750000000000000750000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 5 | 1040001300003T 060000004011510000000 241400000010010930100000000000000011082014000000000001250000005600000000000000000 090000000000000000 000000000000155020101 6 | 1040001300004U 06000000000000000000000000000000000000000000000000000000000000000000000001250000000000001250000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 7 | 1040001300005T 060000004011510000000 241400000010010905100000000000000012082014000000000004431000005600000000000000000 090000000000000000 000000000000155020101 8 | 1040001300006U 06000000000000000000000000000000000000000000000000000000000000000000000004431000000000004431000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 9 | 1040001300007T 060000004011510000000 241400000010010840100000000000000011082014000000000002000000005600000000000000000 090000000000000000 000000000000155020101 10 | 1040001300008U 06000000000000000000000000000000000000000000000000000000000000000000000002000000000000002000000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 11 | 1040001300009T 060000004011510000000 241400000010010816100000000000000011082014000000000002500000005600000000000000000 090000000000000000 000000000000155020101 12 | 1040001300010U 06000000000000000000000000000000000000000000000000000000000000000000000002500000000000002500000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 13 | 1040001300011T 060000004011510000000 241400000010010832100000000000000012082014000000000002047000005600000000000000000 090000000000000000 000000000000155020101 14 | 1040001300012U 06000000000000000000000000000000000000000000000000000000000000000000000002047000000000002047000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 15 | 1040001300013T 060000004011510000000 241400000010010123100000000000000010082014000000000001820000005600000000000000000 090000000000000000 000000000000155020101 16 | 1040001300014U 06000000000000000000000000000000000000000000000000000000000000000000000001820000000000001820000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 17 | 1040001300015T 060000004011510000000 241400000010010115100000000000000010082014000000000004500000005600000000000000000 090000000000000000 000000000000155020101 18 | 1040001300016U 06000000000000000000000000000000000000000000000000000000000000000000000004500000000000004500000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 19 | 1040001300017T 060000004011510000000 241400000010010220100000000000000030082014000000000007500000005600000000000000000 090000000000000000 000000000000155020101 20 | 1040001300018U 06000000000000000000000000000000000000000000000000000000000000000000000007500000000000007500000000000000000000000000000000110820141208201400001208201400000000000000000000000000000000000000000000000000000000000000000000 21 | 10400015 00002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 22 | 10499999 000001000022 23 | -------------------------------------------------------------------------------- /src/Cnab/Cnab400/DetailInterface.php: -------------------------------------------------------------------------------- 1 | `_ 14 | (the first line of the response HTTP message) are easily retrievable. 15 | 16 | .. code-block:: php 17 | 18 | $response = $client->get('http://www.amazon.com')->send(); 19 | 20 | echo $response->getStatusCode(); // >>> 200 21 | echo $response->getReasonPhrase(); // >>> OK 22 | echo $response->getProtocol(); // >>> HTTP 23 | echo $response->getProtocolVersion(); // >>> 1.1 24 | 25 | You can determine the type of the response using several helper methods: 26 | 27 | .. code-block:: php 28 | 29 | $response->isSuccessful(); // true 30 | $response->isInformational(); 31 | $response->isRedirect(); 32 | $response->isClientError(); 33 | $response->isServerError(); 34 | 35 | Response headers 36 | ---------------- 37 | 38 | The Response object contains helper methods for retrieving common response headers. These helper methods normalize the 39 | variations of HTTP response headers. 40 | 41 | .. code-block:: php 42 | 43 | $response->getCacheControl(); 44 | $response->getContentType(); 45 | $response->getContentLength(); 46 | $response->getContentEncoding(); 47 | $response->getContentMd5(); 48 | $response->getEtag(); 49 | // etc... There are methods for every known response header 50 | 51 | You can interact with the Response headers using the same exact methods used to interact with Request headers. See 52 | :ref:`http-message-headers` for more information. 53 | 54 | .. code-block:: php 55 | 56 | echo $response->getHeader('Content-Type'); 57 | echo $response->getHeader('Content-Length'); 58 | echo $response->getHeaders()['Content-Type']; // PHP 5.4 59 | 60 | Response body 61 | ------------- 62 | 63 | The entity body object of a response can be retrieved by calling ``$response->getBody()``. The response EntityBody can 64 | be cast to a string, or you can pass ``true`` to this method to retrieve the body as a string. 65 | 66 | .. code-block:: php 67 | 68 | $request = $client->get('http://www.amazon.com'); 69 | $response = $request->send(); 70 | echo $response->getBody(); 71 | 72 | See :doc:`/http-client/entity-bodies` for more information on entity bodies. 73 | 74 | JSON Responses 75 | ~~~~~~~~~~~~~~ 76 | 77 | You can easily parse and use a JSON response as an array using the ``json()`` method of a response. This method will 78 | always return an array if the response is valid JSON or if the response body is empty. You will get an exception if you 79 | call this method and the response is not valid JSON. 80 | 81 | .. code-block:: php 82 | 83 | $data = $response->json(); 84 | echo gettype($data); 85 | // >>> array 86 | 87 | XML Responses 88 | ~~~~~~~~~~~~~ 89 | 90 | You can easily parse and use a XML response as SimpleXMLElement object using the ``xml()`` method of a response. This 91 | method will always return a SimpleXMLElement object if the response is valid XML or if the response body is empty. You 92 | will get an exception if you call this method and the response is not valid XML. 93 | 94 | .. code-block:: php 95 | 96 | $xml = $response->xml(); 97 | echo $xml->foo; 98 | // >>> Bar! 99 | 100 | Streaming responses 101 | ------------------- 102 | 103 | Some web services provide streaming APIs that allow a client to keep a HTTP request open for an extended period of 104 | time while polling and reading. Guzzle provides a simple way to convert HTTP request messages into 105 | ``Guzzle\Stream\Stream`` objects so that you can send the initial headers of a request, read the response headers, and 106 | pull in the response body manually as needed. 107 | 108 | Here's an example using the Twitter Streaming API to track the keyword "bieber": 109 | 110 | .. code-block:: php 111 | 112 | use Guzzle\Http\Client; 113 | use Guzzle\Stream\PhpStreamRequestFactory; 114 | 115 | $client = new Client('https://stream.twitter.com/1'); 116 | 117 | $request = $client->post('statuses/filter.json', null, array( 118 | 'track' => 'bieber' 119 | )); 120 | 121 | $request->setAuth('myusername', 'mypassword'); 122 | 123 | $factory = new PhpStreamRequestFactory(); 124 | $stream = $factory->fromRequest($request); 125 | 126 | // Read until the stream is closed 127 | while (!$stream->feof()) { 128 | // Read a line from the stream 129 | $line = $stream->readLine(); 130 | // JSON decode the line of data 131 | $data = json_decode($line, true); 132 | } 133 | 134 | You can use the ``stream`` request option when using a static client to more easily create a streaming response. 135 | 136 | .. code-block:: php 137 | 138 | $stream = Guzzle::get('http://guzzlephp.org', array('stream' => true)); 139 | while (!$stream->feof()) { 140 | echo $stream->readLine(); 141 | } 142 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Guzzle.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Guzzle.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/Guzzle" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Guzzle" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | --------------------------------------------------------------------------------