cxCepTransformer.php
895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Cacic\CommonBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
/**
*
* Trata o CEP: Remove ou adiciona a máscara (xxxxx-xxx)
* @author CreatiX
*
*/
class cxCepTransformer implements DataTransformerInterface
{
public function __construct(){}
/**
* Adiciona o hífen ao CEP (Adiciona a marcação da máscara)
*
* @param string $cep
* @return string
*/
public function transform( $cep )
{
if ( $cep !== null )
return substr( $cep, 0, 5 ) .'-'. substr( $cep, 5 );
else return '';
}
/**
* Remove o hífen do CEP (Remove a marcação da máscara)
*
* @param string $cep
* @return string
*/
public function reverseTransform( $cep )
{
if ( $cep !== null )
return str_replace( '-', '', $cep );
else return '';
}
}