PHP code example of lukasz93p / doctrine-domain-id-types
1. Go to this page and download the library: Download lukasz93p/doctrine-domain-id-types library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lukasz93p / doctrine-domain-id-types example snippets
namespace Lukasz93P\DoctrineDomainIdTypes\domainId;
interface AggregateId
{
/**
* @return AggregateId
*/
public static function generate();
/**
* @param string $string
* @return AggregateId
*/
public static function fromString(string $string);
public function toString(): string;
public function equals(AggregateId $otherAggregateId): bool;
}
namespace App\domain\id;
use Lukasz93P\DoctrineDomainIdTypes\domainId\AggregateId;
interface ProductId extends AggregateId
{
// some additional method specific for ProductId if needed
}
namespace App\infrastructure\persistence\testPackage\id;
use App\domain\id\ProductId;
use Lukasz93P\DoctrineDomainIdTypes\domainId\BaseAggregateId;
class ProductDoctrineId extends BaseAggregateId implements ProductId
{
// BaseAggregateId class provides implementation for all
// methods declared in Lukasz93P\DoctrineDomainIdTypes\domainId\AggregateId
// ! IMPORTANT ! do not create constructor for this class because constructor
// of base class Lukasz93P\DoctrineDomainIdTypes\domainId\BaseAggregateId is private final
}
namespace App\infrastructure\persistence\product\id;
use Lukasz93P\DoctrineDomainIdTypes\doctrineId\AggregateIdDoctrineFieldType;
class ProductDoctrineIdType extends AggregateIdDoctrineFieldType
{
// implement abstract method which should return class name
// of Your's id interface implementation
protected function mappedAggregateIdImplementationClassName(): string
{
return ProductDoctrineId::class;
}
// implement abstract method which return name of custom Doctrine field
public function getName()
{
return 'product_id';
}
}