class Serial
{
private $prefixo = "";
public $letras = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
public $numeros = array(0,1,2,3,4,5,6,7,8,9);
/*
* Método construtor
* Cria um prefixo para cada objeto criado
*/
public function __construct() {
$max = count($this->letras)-1;
for($a=0;$a<5;$a++) {
$this->prefixo .= $this->letras[rand(0, $max)];
}
return $this;
}
/*
* Método get
* Gera um serial de 15 digitos toda vez que o método for chamado
*/
public function get() {
$serial = '';
$max = count($this->numeros)-1;
for($b=0;$b<15;$b++){
$serial .= (!($b % 5) && $b ? '-' : ''). $this->numeros[rand(0, $max)];
}
returnecho $this->prefixo."-".$serial;$serial."\n";
return $this;
}
}
require_once('serial.class.php');
$serial_A = new Serial;Serial();
echo $serial_A->get() . "\n";
echo $serial_A->get() . "\n";
echo $serial_A->get()
. "\n\n";
$serial_B = new Serial;
echo $serial_B ->get() . "\n";
echo $serial_B->get()->get()
. "\n\n";
$serial_C = new Serial;
echo $serial_C ->get()->get()->get()
. "\n";
echo $serial_C ->get()->get()->get()
. "\n";
echo $serial_C ->get()->get()->get()
. "\n";
echo $serial_C ->get() . "\n\n";->get()->get();
Exemplo de saída
MPRDM-68308-47678-09412
MPRDM-34567-47698-43685
MPRDM-79111-86573-68267
MPRDM-78570-58526-57259
MPRDM-89941-85110-50824
MPRDM-41477-69233-60018
MPRDM-76481-63231-98672
MPRDM-14028-03542-56162
MPRDM-41338-20932-00450
MPRDM-72468-49538-39004
MPRDM-82852-74510-92625
MPRDM-34866-98635-93850
MPRDM-42227-33041-72832
MPRDM-15014-94731-68651
MPRDM-12007-58515-50146
MPRDM-27148-78106-34490
MPRDM-99967-35102-51586
MPRDM-47226-20839-60614