Skip to content

Commit

Permalink
Value Object example added [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Nov 27, 2018
1 parent 96ecf78 commit 98394d5
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,53 @@ $entity->validatePartially(partiallyValidateFields);

### Example of intended usage

#### Value Object Example

```php
<?php
declare(strict_types=1);

namespace MyLibrary\ValueObject;

use Selami\Entity\Interfaces\ValueObjectInterface;
use stdClass;
use Selami\Entity\Model;
use Selami\Entity\ValueObjectTrait;

final ProfileValueObject implements ValueObjectInterface
{
private static schemaFile = 'models/profile';

use ValueObject;

public static function create(stdClass $data) : ValueObjectInterface
{
$model = Model::createFromJsonFile(self::$schemaFile);
return static($model, $data)
}
}


#### Entity Example

```php
<?php
declare(strict_types=1);

namespace MyLibrary\Entity;

use JsonSerializable;
use Selami\Entity\Interfaces\EntityInterface;
use stdClass;
use Selami\Entity\Model;
use Selami\Entity\EntityTrait;

final ProfileEntity implements JsonSerializable
final ProfileEntity implements EntityInterface
{
private static schemaFile = 'models/profile';

use EntityTrait;

public static function create(string $id, ?stdClass $data=null)
public static function create(string $id, ?stdClass $data=null) : EntityInterface
{
$model = Model::createFromJsonFile(self::$schemaFile);
return static($model, $id, $data)
Expand Down

0 comments on commit 98394d5

Please sign in to comment.