PHPackages                             phphleb/draft - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. phphleb/draft

AbandonedArchivedLibrary[Framework](/categories/framework)

phphleb/draft
=============

Generator of classes from drafts for the HLEB framework

v1.0.5(3y ago)2251MITPHPPHP &gt;=7.3.0

Since Oct 22Pushed 3y ago1 watchersCompare

[ Source](https://github.com/phphleb/draft)[ Packagist](https://packagist.org/packages/phphleb/draft)[ RSS](/packages/phphleb-draft/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

Draft Instances
===============

[](#draft-instances)

### Class generator using templates ("drafts")

[](#class-generator-using-templates-drafts)

This way is different from the traditional **DI (Dependency injection)**, since it does not injects dependencies programmatically at runtime, but in advance, by generating and changing classes according to settings. The created classes exist as files; their correctness can be checked, dependencies are "visible" for IDE, so as testing is possible.

[Link to instructions](https://phphleb.ru/ru/v1/di/) (RU)

Draft Instances is an experimental technique, as well as some others in [HLEB](https://github.com/phphleb/hleb) framework encompassing this library. *Unsuitable for using recklessly.* If desired, the library may be connected separately (generation is implemented in **GeneratingTask** class).

#### Installation

[](#installation)

```
$ composer require phphleb/draft
```

#### Deployment

[](#deployment)

```
$ php console phphleb/draft --add
```

#### Generation

[](#generation)

Generating classes and updating the autoloader. Every time when the settings or template classes are changed, this command is to be started.

```
$ php console drafts/generating-task --update-all
$ composer dump-autoload
```

The only distinction between the generated classes and the usual ones created by a developer is that the former are editable only from the "draft" or settings.

Using settings from one template ("draft"), you can create a lot of similar classes for different tasks. Each "draft" is arbitrary in content, the principle of substituting settings into it is simple, and it is specified as follows.

`1` Array with settings:

```
return [
'AClass' => [
        'TestDraftClass' => [
            'ActionName' => 'new \DateTime',
            'Value' => '\'now\'',
            'ReturnType' => '\DateTimeInterface',
            'Description' => 'Demo A class'
        ]
    ],
'BClass' => [
        'TestDraftClass' => [
            'ActionName' => 'implode',
            'Value' => '[100,500]',
            'ReturnType' => 'string',
            'Description' => 'Demo B class'
        ]
    ],
];
```

`2` Schematic template class **TestDraftClass.php** (default setting values for substitution are neutral-random to support syntax highlighting in IDE)

```
