Skip to content

Commit

Permalink
2.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc-business-account committed Sep 3, 2022
1 parent 19c43a4 commit 5aeeec7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ Commonly, the log format could be of the type info or error. Flag could show a
Dual license (LGPL 3.0 and Commercial). See LICENSE file.

## Version
* 2.21.1 2022-09-03
* Fixed a problem with Flags where the Job or Parent is null.
* Interface StateSerializable arguments allows Job or null
* 2.21 2022-09-03
* Updated dependencies.
* Added type hinting/validation to most methods.
Expand Down
28 changes: 14 additions & 14 deletions lib/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class Flags implements StateSerializable
{
/** @var string It is the name (or id) of the container. */
/** @var string It is the name (or id) of the container. It is used for debug purposes. */
private $name;
/** @var array|null */
private $stack = [];
Expand All @@ -40,11 +40,11 @@ class Flags implements StateSerializable
/**
* Flags constructor.
*
* @param mixed $name Name of the container of flags
* @param string $name Name of the container of flags
* @param bool $changed true if the container has changed.
* @param StateMachineOne|null $stateMachine The state machine related with the flag.
*/
public function __construct($name = null, bool $changed = true, ?StateMachineOne $stateMachine = null)
public function __construct(string $name = '', bool $changed = true, ?StateMachineOne $stateMachine = null)
{
$this->name = $name;
$this->changed = $changed;
Expand All @@ -68,12 +68,12 @@ public static function factory(Job $job, string $string): Flags
/**
* Creates a flag from a job and a string
*
* @param Job $job
* @param Job|null $job
* @param String $string a serialized string containing the information of the flag.
*
* @return void
*/
public function fromString(Job $job, string $string): void
public function fromString(?Job $job, string $string): void
{
try {
$this->parentJob = $job;
Expand Down Expand Up @@ -110,7 +110,7 @@ public function check(): void

public function getTime($microtime = false)
{
if ($this->caller) {
if ($this->caller!==null) {
return $this->caller->getTime($microtime);
}
return $microtime ? microtime(true) : time();
Expand All @@ -136,8 +136,8 @@ public function pull(string $idUnique = '', string $msg = '', int $level = 0, in
{
if (isset($this->stack[$idUnique])) {
unset($this->stack[$idUnique], $this->stackId[$idUnique], $this->timeExpire[$idUnique]);
if ($this->parentJob) {
$this->caller->addLog($this->parentJob, $this->name, 'PULL'
if ($this->parentJob!==null && $this->caller!==null) {
$this->caller->addLog($this->parentJob, $this->name ?? '', 'PULL'
, "flag,,changed,,$idUnique,,$idRel,,$level,,$msg", $idRel);
}
}
Expand Down Expand Up @@ -224,8 +224,8 @@ public function push($idUnique = 0, string $msg = '', int $level = 0, int $timeE
}
$this->level[$idUnique] = $level;
$this->changed = true;
if ($this->parentJob && $this->caller) {
$this->caller->addLog($this->parentJob, $this->name, 'PUSH', "flag,,changed,,$idUnique,,$level,,$idRel,,$msg", $idRel);
if ($this->parentJob!==null && $this->caller!==null) {
$this->caller->addLog($this->parentJob, $this->name ?? '', 'PUSH', "flag,,changed,,$idUnique,,$level,,$idRel,,$msg", $idRel);
}
return $this;
}
Expand All @@ -242,8 +242,8 @@ public function message($msg = ''): Flags
$this->timeExpire['_msg'] = -1; // messages never expires.
$this->level['_msg'] = 0;
$this->changed = true;
if ($this->parentJob && $this->caller) {
$this->caller->addLog($this->parentJob, $this->name, 'MESSAGE', $msg, $this->stackId['_msg']);
if ($this->parentJob!==null && $this->caller!==null) {
$this->caller->addLog($this->parentJob, $this->name ?? '', 'MESSAGE', $msg, $this->stackId['_msg']);
}
return $this;
}
Expand Down Expand Up @@ -323,10 +323,10 @@ public function setParent(?Job $job): self
/**
* It sets the caller. Usually it is the state machine.
*
* @param $stateMachineOne
* @param StateMachineOne|null $stateMachineOne
* @return $this
*/
public function setCaller($stateMachineOne): self
public function setCaller(?StateMachineOne $stateMachineOne): self
{
$this->caller = $stateMachineOne;
return $this;
Expand Down
7 changes: 5 additions & 2 deletions lib/StateMachineOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@
*
* @package eftec\statemachineone
* @author Jorge Patricio Castro Castillo <jcastro arroba eftec dot cl>
* @version 2.21 2022-09-03
* @version 2.21.1 2022-09-03
* @license LGPL-3.0 (you could use in a comercial-close-source product but any change to this library must be shared)
* @link https://github.com/EFTEC/StateMachineOne
*/
class StateMachineOne
{
/** @var int NODB constants indicate that NO DB would be used */
public const NODB = 0;
/** @var int PDODB constants indicate that PdoOne database would be used */
public const PDODB = 1;
/** @var int PDODB constants indicate that DocumentStoreOne database would be used */
public const DOCDB = 2;
public $VERSION = '2.21';
public $VERSION = '2.21.1';
/**
* @var array Possible states. It must be an associative array.<br>
* <p>$statemachine->states=['State1'=>'name of the state','State2'=>'another name'];</p>
Expand Down
6 changes: 3 additions & 3 deletions lib/StateSerializable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public function toString();
/**
* It creates an object using a string.
*
* @param Job $job
* @param String $string
* @param Job|null $job
* @param String $string
*
* @return mixed
*/
public function fromString(Job $job, string $string);
public function fromString(?Job $job, string $string);

/**
* It sets the parent
Expand Down

0 comments on commit 5aeeec7

Please sign in to comment.