-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from drupalista-br/patch-1
Criado set method para $value property e criado Abstract Class
- Loading branch information
Showing
4 changed files
with
80 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Bissolli\ValidadorCpfCnpj; | ||
|
||
abstract class DocumentoAbstract | ||
{ | ||
/** | ||
* Value to be validated | ||
* | ||
* @var string | ||
*/ | ||
protected $value; | ||
|
||
/** | ||
* Create a new ValidaDocumento instance | ||
* | ||
* @param string $value | ||
*/ | ||
public function __construct($value = null) | ||
{ | ||
if ($value) $this->setValue($value); | ||
} | ||
|
||
|
||
abstract public function isValid(); | ||
abstract public function format(); | ||
|
||
/** | ||
* Get class name without namespace | ||
* | ||
* @return string | ||
*/ | ||
public function getClassName() | ||
{ | ||
return substr(strrchr(get_class($this), '\\'), 1); | ||
} | ||
|
||
/** | ||
* Get the raw value | ||
* | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* Set the clean value | ||
* | ||
* @return self | ||
*/ | ||
public function setValue($value) | ||
{ | ||
$this->value = (string) preg_replace('/[^0-9]/', '', $value); | ||
return $this; | ||
} | ||
} |