https://github.com/phphleb/draft
Draft Instances - DI (Dependency injection) implementation
https://github.com/phphleb/draft
Last synced: about 1 year ago
JSON representation
Draft Instances - DI (Dependency injection) implementation
- Host: GitHub
- URL: https://github.com/phphleb/draft
- Owner: phphleb
- License: mit
- Archived: true
- Created: 2021-10-20T18:42:30.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-28T14:46:56.000Z (over 3 years ago)
- Last Synced: 2025-03-18T08:34:44.517Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Draft Instances
### 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
```bash
$ composer require phphleb/draft
```
#### Deployment
```bash
$ php console phphleb/draft --add
```
#### Generation
Generating classes and updating the autoloader. Every time when the settings or template classes are changed, this command is to be started.
```bash
$ 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:
```php
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)
```php
=1.5.72-brightgreen)