Skip to content

Commit

Permalink
#24 if no id exists an uuid4 string is now usedf
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasFranek committed Jul 5, 2018
1 parent d00b1d6 commit b409cef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"symfony/yaml": "^2.8",
"symfony/console": "^2.8",
"symfony/filesystem": "^2.8",
"memio/memio": "^2.0"

"memio/memio": "^2.0",
"ramsey/uuid": "^3.7"
},
"suggest": {
"ext-memcached": "Required for caching"
Expand Down
14 changes: 8 additions & 6 deletions src/Models/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Webuntis\Serializer\Serializer;
use Webuntis\Types\StringType;
use Webuntis\Types\TypeHandler;
use Ramsey\Uuid\Uuid;

/**
* Abstract Class Model
Expand All @@ -33,7 +34,7 @@
*/
abstract class AbstractModel implements ModelInterface {
/**
* @var int
* @var string|int
*/
private $id;

Expand All @@ -54,19 +55,19 @@ public function __construct(?array $data = []) {

/**
* returns the id
* @return int
* @return string|int
*/
public function getId() : int
public function getId()
{
return $this->id;
}

/**
* set the id
* @param int $id
* @param int|string $id
* @return AbstractModel $this
*/
public function setId(int $id) : self
public function setId($id) : self
{
$this->id = $id;

Expand All @@ -91,7 +92,8 @@ protected function parse(array $data) : void
if(isset($data['id'])) {
$this->setId($data['id']);
}else {
$this->setId(rand(0, getrandmax()));
$uuid = Uuid::uuid4();
$this->setId($uuid->toString());
}
$fields = YAMLConfiguration::getFields(get_class($this));
$typeHandler = new TypeHandler();
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Interfaces/ModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
*/
interface ModelInterface {
/**
* @return int
* @return int|string
*/
public function getId() : int;
public function getId();

/**
* @param int $id
* @param int|string $id
* @return AbstractModel
*/
public function setId(int $id) : AbstractModel;
public function setId($id) : AbstractModel;

/**
* @param string $format
Expand Down

0 comments on commit b409cef

Please sign in to comment.