Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Entity\{Fields,Features}\ to Model\ #301

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/ddd/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ are provided in the form of PHP [traits].

Use entity fields to provide _read operations_ for common entity fields. Built-in fields are:

- `Msgphp\Domain\Entity\Fields\CreatedAtField`
- `Msgphp\Domain\Entity\Fields\LastUpdatedAtField`
- `Msgphp\Domain\Model\CreatedAtField`
- `Msgphp\Domain\Model\LastUpdatedAtField`

## Entity Features

Use entity features to provide _write operations_ for common entity fields. Built-in features are:

- `MsgPhp\Domain\Entity\Features\CanBeConfirmed`
- `MsgPhp\Domain\Entity\Features\CanBeEnabled`
- `MsgPhp\Domain\Model\CanBeConfirmed`
- `MsgPhp\Domain\Model\CanBeEnabled`

## Basic Example

```php
<?php

use MsgPhp\Domain\Entity\Fields\CreatedAtField;
use MsgPhp\Domain\Entity\Features\CanBeEnabled;
use MsgPhp\Domain\Model\CreatedAtField;
use MsgPhp\Domain\Model\CanBeEnabled;

// --- SETUP ---

Expand Down
2 changes: 1 addition & 1 deletion docs/event-sourcing/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A domain event is bound to `MsgPhp\Domain\Event\DomainEventInterface`. Its purpo
```php
<?php

use MsgPhp\Domain\Entity\Features\CanBeEnabled;
use MsgPhp\Domain\Model\CanBeEnabled;
use MsgPhp\Domain\Event\DomainEventHandlerInterface;
use MsgPhp\Domain\Event\DomainEventHandlerTrait;
use MsgPhp\Domain\Event\EnableEvent;
Expand Down
5 changes: 1 addition & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ parameters:
- '#Static property MsgPhp\\.+\\Tests\\.+Test::\$bus \(Symfony\\Component\\Messenger\\MessageBusInterface\) does not accept null\.#'
-
message: '#Call to an undefined method object::.+\(\)\.#'
path: *src/*/Tests/Entity/Fields/*Test.php
-
message: '#Call to an undefined method object::.+\(\)\.#'
path: *src/*/Tests/Entity/Features/*Test.php
path: *src/*/Tests/Model/*Test.php
-
message: '#Call to an undefined method object::dispatch\(\)\.#'
path: src/Domain/Tests/Message/MessageDispatchingTraitTest.php
Expand Down
11 changes: 5 additions & 6 deletions src/Domain/Infra/Doctrine/ObjectMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace MsgPhp\Domain\Infra\Doctrine;

use MsgPhp\Domain\Entity\Features;
use MsgPhp\Domain\Entity\Fields;
use MsgPhp\Domain\Model;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand All @@ -16,7 +15,7 @@ final class ObjectMappings implements ObjectMappingProviderInterface
{
public static function provideObjectMappings(MappingConfig $config): iterable
{
yield Features\CanBeConfirmed::class => [
yield Model\CanBeConfirmed::class => [
'confirmationToken' => [
'type' => 'string',
'unique' => true,
Expand All @@ -28,17 +27,17 @@ public static function provideObjectMappings(MappingConfig $config): iterable
'nullable' => true,
],
];
yield Features\CanBeEnabled::class => [
yield Model\CanBeEnabled::class => [
'enabled' => [
'type' => 'boolean',
],
];
yield Fields\CreatedAtField::class => [
yield Model\CreatedAtField::class => [
'createdAt' => [
'type' => 'datetime',
],
];
yield Fields\LastUpdatedAtField::class => [
yield Model\LastUpdatedAtField::class => [
'lastUpdatedAt' => [
'type' => 'datetime',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MsgPhp\Domain\Entity\Features;
namespace MsgPhp\Domain\Model;

use MsgPhp\Domain\Event\ConfirmEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MsgPhp\Domain\Entity\Features;
namespace MsgPhp\Domain\Model;

use MsgPhp\Domain\Event\DisableEvent;
use MsgPhp\Domain\Event\EnableEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MsgPhp\Domain\Entity\Fields;
namespace MsgPhp\Domain\Model;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MsgPhp\Domain\Entity\Fields;
namespace MsgPhp\Domain\Model;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Tests/Infra/Doctrine/ObjectMappingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ final class ObjectMappingsTest extends TestCase
public function testMapping(): void
{
$available = array_flip(array_map(function (string $file): string {
return 'MsgPhp\\Domain\\Entity\\'.basename(\dirname($file)).'\\'.basename($file, '.php');
}, array_merge(glob(\dirname(__DIR__, 3).'/Entity/Features/*.php'), glob(\dirname(__DIR__, 3).'/Entity/Fields/*.php'))));
return 'MsgPhp\\Domain\\Model\\'.basename($file, '.php');
}, glob(\dirname(__DIR__, 3).'/Model/*.php')));
$mappings = ObjectMappings::provideObjectMappings(new MappingConfig([]));
$mappings = array_keys($mappings instanceof \Traversable ? iterator_to_array($mappings) : $mappings);
sort($mappings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace MsgPhp\Domain\Tests\Entity\Features;
namespace MsgPhp\Domain\Tests\Model;

use MsgPhp\Domain\Entity\Features\CanBeConfirmed;
use MsgPhp\Domain\Event\ConfirmEvent;
use MsgPhp\Domain\Model\CanBeConfirmed;
use PHPUnit\Framework\TestCase;

final class CanBeConfirmedTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace MsgPhp\Domain\Tests\Entity\Features;
namespace MsgPhp\Domain\Tests\Model;

use MsgPhp\Domain\Entity\Features\CanBeEnabled;
use MsgPhp\Domain\Event\DisableEvent;
use MsgPhp\Domain\Event\EnableEvent;
use MsgPhp\Domain\Model\CanBeEnabled;
use PHPUnit\Framework\TestCase;

final class CanBeEnabledTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace MsgPhp\Domain\Tests\Entity\Fields;
namespace MsgPhp\Domain\Tests\Model;

use MsgPhp\Domain\Entity\Fields\CreatedAtField;
use MsgPhp\Domain\Model\CreatedAtField;
use PHPUnit\Framework\TestCase;

final class CreatedAtFieldTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace MsgPhp\Domain\Tests\Entity\Fields;
namespace MsgPhp\Domain\Tests\Model;

use MsgPhp\Domain\Entity\Fields\LastUpdatedAtField;
use MsgPhp\Domain\Model\LastUpdatedAtField;
use PHPUnit\Framework\TestCase;

final class LastUpdatedAtFieldTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion src/Eav/Entity/AttributeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace MsgPhp\Eav\Entity;

use MsgPhp\Eav\AttributeValueIdInterface;
use MsgPhp\Eav\Entity\Fields\AttributeField;
use MsgPhp\Eav\Model\AttributeField;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand Down
7 changes: 3 additions & 4 deletions src/Eav/Infra/Doctrine/ObjectMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use MsgPhp\Domain\Infra\Doctrine\ObjectMappingProviderInterface;
use MsgPhp\Eav\Entity\Attribute;
use MsgPhp\Eav\Entity\AttributeValue;
use MsgPhp\Eav\Entity\Features;
use MsgPhp\Eav\Entity\Fields;
use MsgPhp\Eav\Model;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand All @@ -20,7 +19,7 @@ final class ObjectMappings implements ObjectMappingProviderInterface
{
public static function provideObjectMappings(MappingConfig $config): iterable
{
yield Features\EntityAttributeValue::class => [
yield Model\EntityAttributeValue::class => [
'attributeValue' => [
'type' => self::TYPE_ONE_TO_ONE,
'targetEntity' => AttributeValue::class,
Expand All @@ -30,7 +29,7 @@ public static function provideObjectMappings(MappingConfig $config): iterable
],
],
];
yield Fields\AttributeField::class => [
yield Model\AttributeField::class => [
'attribute' => [
'type' => self::TYPE_MANY_TO_ONE,
'targetEntity' => Attribute::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MsgPhp\Eav\Entity\Fields;
namespace MsgPhp\Eav\Model;

use MsgPhp\Eav\AttributeIdInterface;
use MsgPhp\Eav\Entity\Attribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MsgPhp\Eav\Entity\Features;
namespace MsgPhp\Eav\Model;

use MsgPhp\Eav\AttributeIdInterface;
use MsgPhp\Eav\AttributeValueIdInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/Eav/Tests/Infra/Doctrine/ObjectMappingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ final class ObjectMappingsTest extends TestCase
public function testMapping(): void
{
$available = array_flip(array_map(function (string $file): string {
return 'MsgPhp\\Eav\\Entity\\'.basename(\dirname($file)).'\\'.basename($file, '.php');
}, array_merge(glob(\dirname(__DIR__, 3).'/Entity/Features/*.php'), glob(\dirname(__DIR__, 3).'/Entity/Fields/*.php'))));
return 'MsgPhp\\Eav\\Model\\'.basename($file, '.php');
}, glob(\dirname(__DIR__, 3).'/Model/*.php')));
$mappings = ObjectMappings::provideObjectMappings(new MappingConfig([]));
$mappings = array_keys($mappings instanceof \Traversable ? iterator_to_array($mappings) : $mappings);
sort($mappings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace MsgPhp\Eav\Tests\Entity\Fields;
namespace MsgPhp\Eav\Tests\Model;

use MsgPhp\Eav\AttributeIdInterface;
use MsgPhp\Eav\Entity\Attribute;
use MsgPhp\Eav\Entity\Fields\AttributeField;
use MsgPhp\Eav\Model\AttributeField;
use PHPUnit\Framework\TestCase;

final class AttributeFieldTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace MsgPhp\Eav\Tests\Entity\Features;
namespace MsgPhp\Eav\Tests\Model;

use MsgPhp\Eav\AttributeIdInterface;
use MsgPhp\Eav\AttributeValueIdInterface;
use MsgPhp\Eav\Entity\Attribute;
use MsgPhp\Eav\Entity\AttributeValue;
use MsgPhp\Eav\Entity\Features\EntityAttributeValue;
use MsgPhp\Eav\Model\EntityAttributeValue;
use PHPUnit\Framework\TestCase;

final class EntityAttributeValueTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion src/User/Entity/UserEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MsgPhp\User\Entity;

use MsgPhp\User\Entity\Fields\UserField;
use MsgPhp\User\Model\UserField;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand Down
4 changes: 2 additions & 2 deletions src/User/Entity/UserRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace MsgPhp\User\Entity;

use MsgPhp\User\Entity\Fields\RoleField;
use MsgPhp\User\Entity\Fields\UserField;
use MsgPhp\User\Model\RoleField;
use MsgPhp\User\Model\UserField;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion src/User/Entity/Username.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MsgPhp\User\Entity;

use MsgPhp\User\Entity\Fields\UserField;
use MsgPhp\User\Model\UserField;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand Down
23 changes: 11 additions & 12 deletions src/User/Infra/Doctrine/ObjectMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
use MsgPhp\Domain\Infra\Doctrine\MappingConfig;
use MsgPhp\Domain\Infra\Doctrine\ObjectMappingProviderInterface;
use MsgPhp\User\Entity\Credential;
use MsgPhp\User\Entity\Features;
use MsgPhp\User\Entity\Fields;
use MsgPhp\User\Entity\Role;
use MsgPhp\User\Entity\User;
use MsgPhp\User\Entity\UserEmail;
use MsgPhp\User\Entity\UserRole;
use MsgPhp\User\Model;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
Expand All @@ -22,11 +21,11 @@
final class ObjectMappings implements ObjectMappingProviderInterface
{
private const CREDENTIALS = [
Features\EmailCredential::class => Credential\Email::class,
Features\EmailPasswordCredential::class => Credential\EmailPassword::class,
Features\NicknameCredential::class => Credential\Nickname::class,
Features\NicknamePasswordCredential::class => Credential\NicknamePassword::class,
Features\TokenCredential::class => Credential\Token::class,
Model\EmailCredential::class => Credential\Email::class,
Model\EmailPasswordCredential::class => Credential\EmailPassword::class,
Model\NicknameCredential::class => Credential\Nickname::class,
Model\NicknamePasswordCredential::class => Credential\NicknamePassword::class,
Model\TokenCredential::class => Credential\Token::class,
];

public static function provideObjectMappings(MappingConfig $config): iterable
Expand All @@ -41,7 +40,7 @@ public static function provideObjectMappings(MappingConfig $config): iterable
];
}

yield Features\ResettablePassword::class => [
yield Model\ResettablePassword::class => [
'passwordResetToken' => [
'type' => 'string',
'unique' => true,
Expand All @@ -53,15 +52,15 @@ public static function provideObjectMappings(MappingConfig $config): iterable
'nullable' => true,
],
];
yield Fields\EmailsField::class => [
yield Model\EmailsField::class => [
'emails' => [
'type' => self::TYPE_ONE_TO_MANY,
'targetEntity' => UserEmail::class,
'mappedBy' => 'user',
'indexBy' => 'email',
],
];
yield Fields\RoleField::class => [
yield Model\RoleField::class => [
'role' => [
'type' => self::TYPE_MANY_TO_ONE,
'targetEntity' => Role::class,
Expand All @@ -70,14 +69,14 @@ public static function provideObjectMappings(MappingConfig $config): iterable
],
],
];
yield Fields\RolesField::class => [
yield Model\RolesField::class => [
'roles' => [
'type' => self::TYPE_ONE_TO_MANY,
'targetEntity' => UserRole::class,
'mappedBy' => 'user',
],
];
yield Fields\UserField::class => [
yield Model\UserField::class => [
'user' => [
'type' => self::TYPE_MANY_TO_ONE,
'targetEntity' => User::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace MsgPhp\User\Entity\Features;
namespace MsgPhp\User\Model;

use MsgPhp\User\CredentialInterface;
use MsgPhp\User\Event\Domain\ChangeCredentialEvent;
Expand Down
Loading