Skip to content

Commit

Permalink
PHP 7.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederico Gendorf committed Oct 28, 2021
1 parent 88cea00 commit 6170ded
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
7 changes: 4 additions & 3 deletions code/REPEmpregado.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ public function cadastraEmpregado() {
return str_replace(chr(2), '', str_replace(chr(3), '', $ret));
}

/**
/**
* Metodo que retorna os empregados cadastrados no relogio
* @return array
*/
public function listaEmpregados() {
$qnt = 0;
$listusers = array();
$regarray = false;
do {
$CMD = "00+RU+00+1]{$qnt}";
$ret = $this->queryREP($CMD);
Expand All @@ -88,7 +89,7 @@ public function listaEmpregados() {
//echo ' | ' . $chkrcv . ' - (' . substr($ret, -2, 1) . ')' . PHP_EOL;
$proc = preg_split('/]/', $ret);
$cmds = preg_split('/\+/', $proc[0]);
$proc[0] = $cmds[4];
$proc[0] = $cmds[4] ?? false;
}
if ($cmds[3] > 0) {
$listusers = array_merge($listusers, $proc);
Expand All @@ -114,7 +115,7 @@ public function listaEmpregados() {
*/
public function deleteEmpregado() {
$ret = $this->queryREP("00+EU+00+1+E[{$this->pisEmpregado}[{$this->nomeEmpregado}[{$this->biometriaEmpregado}[1[{$this->matriculaEmpregado}");
return substr($ret,2,-2);
return substr($ret, 2, -2);
}

}
28 changes: 23 additions & 5 deletions code/REPHenry.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,23 @@ public function setPort($port) {
public function connect() {
$this->socket = $this->factory->createClient("{$this->server}:{$this->port}");
}

/**
* Genarate param Length
* @param type $data
* @return string
*/
function generateParamLength($data) {
$paramLength = strlen($data);
$h1 = $paramLength % 256;
$h16 = floor($paramLength / 256);
$h1Str = chr(($h1)) . chr(($h16));
return $h1Str;
}

/**
* Checksum protocolo Henry
* @param type $data
* @return type
*/
public function checkSum($data) {
$i;
$check = 0;
Expand All @@ -53,7 +61,12 @@ public function checkSum($data) {
$h1 = $check % 16;
return chr(hexdec(substr($this->hex, $h16, 1) . substr($this->hex, $h1, 1)));
}


/**
* Formata texto para enviar para o relógio
* @param type $data
* @return type
*/
public function textFormat($data) {
$BYTE_INIT = chr(2);
$BYTE_END = chr(3);
Expand All @@ -63,10 +76,14 @@ public function textFormat($data) {
$str .= $data;
$str .= $this->checkSum($data);
$str .= $BYTE_END;

return $str;
}

/**
* String to hex do protocolo henry
* @param type $string
* @return type
*/
public function strToHex($string) {
$hex = '';
for ($i = 0; $i < strlen($string); $i++) {
Expand All @@ -83,9 +100,10 @@ public function strToHex($string) {
* @return string
*/
public function queryREP($cmd) {
$data = '';
$this->socket->write($this->textFormat($cmd));
do {
$d = $this->socket->read(128);
$d = $this->socket->read(1);
$data .= $d;
} while (substr($d,-1,1)!=chr(3));
return $data;
Expand Down
6 changes: 5 additions & 1 deletion code/REPRegistros.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ public function setIdSequencial($idSequencial) {
*/
public function coletaRegistrosPonto() {
$idinit = $this->idSequencial;
$resp = '';
do {
$ret = $this->queryREP("00+RR+00+N]10]{$idinit}");
$ret2 = substr($ret, 3,-2);
$proc = preg_split('/]/', $ret2);
$chkcalc = ord($this->checkSum(substr($ret, 3, -2)));
$chkrcv = ord(substr($ret, -2, 1));
if ($chkcalc == $chkrcv) {
if (!empty($proc[1]) && $chkcalc == $chkrcv) {
$resp .= $proc[1];
}
$idinit += 10;
Expand All @@ -47,6 +48,7 @@ public function coletaRegistrosPonto() {
*/
public function getInclusaoAlteracaoEmpresa($registros) {
$y=0;
$regarray = false;
for ($x = 0; sizeof($registros) > $x; ++$x) {
if (substr($registros[$x], 9, 1) == 2) {
$regarray[$y]["NSR"] = substr($registros[$x], 0, 9);
Expand All @@ -72,6 +74,7 @@ public function getInclusaoAlteracaoEmpresa($registros) {
*/
public function getMarcacaoPonto($registros) {
$y=0;
$regarray = false;
for ($x = 0; sizeof($registros) > $x; ++$x) {
if (substr($registros[$x], 9, 1) == 3) {
$regarray[$y]["NSR"] = substr($registros[$x], 0, 9);
Expand All @@ -93,6 +96,7 @@ public function getMarcacaoPonto($registros) {
*/
public function getMarcacaoPontoMatricula($registros) {
$y=0;
$regarray = false;
for ($x = 0; sizeof($registros) > $x; ++$x) {
if (substr($registros[$x], 9, 1) == 7) {
$regarray[$y]["NSR"] = substr($registros[$x], 0, 9);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"require": {
"php": ">=5.4.0",
"php": ">=7.4",
"clue/socket-raw": "v1.2.0"
},
"autoload": {
Expand Down

0 comments on commit 6170ded

Please sign in to comment.