PHP code example of hostnet / accessor-generator-plugin-lib
1. Go to this page and download the library: Download hostnet/accessor-generator-plugin-lib 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/ */
hostnet / accessor-generator-plugin-lib example snippets
namespace Hostnet\Product\Entity;
use Doctrine\ORM\Mapping as ORM;
use Hostnet\Component\AccessorGenerator\Attribute as AG;
#[ORM\Entity]
#[ORM\Table(name: 'periode')]
class Period
{
/** This is the file that is generated with the accessor methods inside. */
use Generated\PeriodMethodsTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(name: 'id', type: 'integer')]
#[AG\Generate]
private int $id;
// ...
}
use Doctrine\ORM\Mapping as ORM;
use Hostnet\Component\AccessorGenerator\Annotation as AG;
/**
* @ORM\Entity
* @ORM\Table(name="periode")
*/
class Period
{
use Generated\PeriodMethodsTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer")
* @AG\Generate
*/
private int $id;
}
#[AG\Generate(add: 'none', set: 'none', remove: 'none', get: 'none', is: 'none')]
class MyEntity
{
#[AG\Generate(encryption_alias: '<encryption_alias>')]
private $my_value;
public function __construct(string $my_value)
{
$this->my_value = $my_value; // No encryption is taking place.
$this->setMyValue($my_value); // The value is now encrypted in the field.
}
}
$task = new Task();
$task->setParam(MyParamEnum::I_CLIENT_ID, 123456);
echo $task->getParam(MyParamEnum);
// 12345
use Hostnet\Component\AccessorGenerator\Enum\EnumeratorCompatibleEntityInterface;
class Parameter implements EnumeratorCompatibleEntityInterface
{
#[ORM\ManyToOne(targetEntity: Task::class)]
private $owner;
#[ORM\Column(type: 'string')]
private $name;
#[ORM\Column(type: 'string')]
#[AG\Generate]
private $value;
// This signature is a
class MyTaskParamNames
{
/**
* Represents the client if the task is currently runnnig for.
*/
public const I_CLIENT_ID = 'CLIENT_ID';
/**
* An awesome URL.
*/
public const S_AWESOME_URL = 'https://www.hostnet.nl/';
}
$task = new Task();
// hasClientId() will check if a parameter with the name I_CLIENT_ID exists in the collection of parameters belonging to
// this Task instance.
if (! $task->getMyParams()->hasClientId()) {
// Create the I_CLIENT_ID parameter with a value of 1234.
$task->getMyParams()->setClientId(1234);
}
// Update the value of the existng parameter.
$task->getMyParams()->setClientId(999);
// Retrieve the value
$client_id = $task->getMyParams()->getClientId();
// Clear the value (keeps the element in the collection, but nullifies the value).
// hasClientId() will now return FALSE as if the parameter doesn't exist.
$task->getMyParams()->clearClientId();
// Remove the element entirely, effectively dropping the record from the database.
$task->getMyParams()->removeClientId();
$task->getMyParams()->hasClientId(); // From MyTaskParamNames
$task->getBetterParams()->setFoobar(1234); // From BetterParamNames
use Hostnet\Component\AccessorGenerator\Attribute as AG;
trait TaskTrait
{
use Generated\TaskTraitMethodsTrait;
#[AG\Enumerator('\My\Namespace\MyExtraParamName', name: 'parameters')]
/** @var \My\Namespace\Generated\MyExtraParamNameEnum */
private $some_extra_params;
}
$task = new Task();
$task->getSomeExtraParams()->...
// Whilst still having access to the already existing enumerators that we defined before.
$task->getMyParams();
$task->getBetterParams();
class Task
{
use Generated\TaskMethodsTrait;
}
class Task
{
use Generated\TaskTrait;
use Generated\TaskMethodsTrait;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.