PHP Classes

File: src/TransferGenerator/Generator/Render/Template/Template.tpl.php

Recommend this page to a friend!
  Classes of Sergii Pryz   Transfer Object   src/TransferGenerator/Generator/Render/Template/Template.tpl.php   Download  
File: src/TransferGenerator/Generator/Render/Template/Template.tpl.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Transfer Object
Generate transfer objects using property hooks
Author: By
Last change: Optimized templete render by removing propertiesCount property
Moved class name prefix to defintion module
Allowed transfer object type and collection full qualified namespace with alias for cross namespaces usage
Date: 6 days ago
Size: 1,659 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
Picamator\TransferObject\TransferGenerator\Generator\Render\Template\TemplateHelper;

$templateTransfer ??= TemplateHelper::getDefaultTemplateTransfer();
$helper = new TemplateHelper($templateTransfer);

echo <<<TEMPLATE
<?php

declare(strict_types=1);

namespace
$templateTransfer->classNamespace;

{$helper->renderKeyValue($templateTransfer->imports, 'use :value;')}

/**
 * Specification:
 * - Class is automatically generated based on a definition file.
 * - To modify it, please update corresponding definition file and run generator again.
 *
 * Note: Do not manually edit this file, as changes will be overwritten.
 */
final class
$templateTransfer->className extends AbstractTransfer
{
    use TransferTrait;

    protected const int META_DATA_SIZE =
{$templateTransfer->properties->count()};

    protected const array META_DATA = [
{$helper->renderKeyValue($templateTransfer->metaConstants, ' self:::key => self:::key_DATA_NAME,')}
    ];

TEMPLATE;

$i = 0;
foreach (
$templateTransfer->metaConstants as $constant => $property) {
    echo <<<TEMPLATE

    //
$property{$helper->getAttribute($property)}
    public const string
$constant = '$property';
    protected const string
{$constant}_DATA_NAME = '$constant';
    protected const int
{$constant}_DATA_INDEX = $i;
{$helper->getDockBlock($property)}
    public
{$helper->getNullable($property)}{$templateTransfer->properties[$property]} \$$property {
        get => \$this->get
{$helper->getRequired($property)}Data(self::{$constant}_DATA_INDEX);
        set => \$this->setData(self::
{$constant}_DATA_INDEX, \$value);
    }

TEMPLATE;
   
$i++;
}
?>
}