PHP code example of earc / data-primary-key-generator

1. Go to this page and download the library: Download earc/data-primary-key-generator 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/ */

    

earc / data-primary-key-generator example snippets


use eArc\Data\Initializer;

Initializer::init();

use eArc\Data\ParameterInterface;
use eArc\DataPrimaryKeyGenerator\PrimaryKeyGenerator;

di_tag(ParameterInterface::TAG_ON_AUTO_PRIMARY_KEY, PrimaryKeyGenerator::class);

use eArc\DataPrimaryKeyGenerator\ParameterInterface;
use eArc\DataPrimaryKeyGenerator\PrimaryKeyGenerator;

di_set_param(ParameterInterface::INFRASTRUCTURE, PrimaryKeyGenerator::USE_REDIS);

use eArc\DataPrimaryKeyGenerator\ParameterInterface;

di_set_param(ParameterInterface::REDIS_CONNECTION, ['127.0.0.1', 6379]);

use eArc\DataPrimaryKeyGenerator\ParameterInterface;
use eArc\DataPrimaryKeyGenerator\PrimaryKeyGenerator;

di_set_param(ParameterInterface::INFRASTRUCTURE, PrimaryKeyGenerator::USE_FILESYSTEM);

use eArc\DataFilesystem\ParameterInterface;

di_set_param(ParameterInterface::DATA_PATH, '/path/to/save/the/entity/data');

use eArc\Data\Entity\AbstractEntity;
use eArc\DataPrimaryKeyGenerator\AutoincrementPrimaryKeyInterface;
use eArc\DataPrimaryKeyGenerator\AutoUUIDPrimaryKeyInterface;

class MyEntityUUID extends AbstractEntity implements AutoUUIDPrimaryKeyInterface
{
    public function setPrimaryKey(?string $primaryKey): void
    {
        $this->primaryKey = $primaryKey;
    }
}

class MyEntityAutoincrementPK extends AbstractEntity implements AutoincrementPrimaryKeyInterface
{
    public function setPrimaryKey(?string $primaryKey): void
    {
        $this->primaryKey = $primaryKey;
    }
}

use eArc\DataPrimaryKeyGenerator\AutoincrementPrimaryKeyInterface;
use eArc\DataPrimaryKeyGenerator\ParameterInterface;

di_set_param(ParameterInterface::DEFAULT_INTERFACE, AutoincrementPrimaryKeyInterface::class);

use eArc\Data\Entity\AbstractEntity;
use eArc\Data\Entity\Interfaces\PrimaryKey\AutoPrimaryKeyInterface;

class MyEntityAutoincrementPK extends AbstractEntity implements AutoPrimaryKeyInterface
{
    public function setPrimaryKey(?string $primaryKey): void
    {
        $this->primaryKey = $primaryKey;
    }
}

use eArc\DataPrimaryKeyGenerator\ParameterInterface;

di_set_param(ParameterInterface::HASH_KEY_NAME, 'my-hash-key-name');

use eArc\DataPrimaryKeyGenerator\ParameterInterface;

di_set_param(ParameterInterface::DIR_NAME_POSTFIX, '@my-dir-name-postfix');