{"id":20235352,"url":"https://github.com/phphleb/draft","last_synced_at":"2025-05-07T10:32:48.819Z","repository":{"id":57040467,"uuid":"419450430","full_name":"phphleb/draft","owner":"phphleb","description":"Draft Instances - DI (Dependency injection) implementation","archived":true,"fork":false,"pushed_at":"2022-12-28T14:46:56.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T08:34:44.517Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phphleb.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-20T18:42:30.000Z","updated_at":"2024-02-03T11:50:29.000Z","dependencies_parsed_at":"2023-01-31T06:45:55.650Z","dependency_job_id":null,"html_url":"https://github.com/phphleb/draft","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphleb%2Fdraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphleb%2Fdraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphleb%2Fdraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphleb%2Fdraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phphleb","download_url":"https://codeload.github.com/phphleb/draft/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252859898,"owners_count":21815425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T08:16:02.678Z","updated_at":"2025-05-07T10:32:48.516Z","avatar_url":"https://github.com/phphleb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Draft Instances\n\n### Class generator using templates (\"drafts\")\n\nThis way is different from the traditional **DI (Dependency injection)**,\nsince it does not injects dependencies programmatically at runtime, but in advance,\nby generating and changing classes according to settings. The created classes exist as files;\ntheir correctness can be checked, dependencies are \"visible\" for IDE, so as testing is possible.\n\n[Link to instructions](https://phphleb.ru/ru/v1/di/) (RU)\n\nDraft Instances is an experimental technique, as well as some others in [HLEB](https://github.com/phphleb/hleb) framework encompassing this library.\n*Unsuitable for using recklessly.* If desired, the library may be connected separately (generation is implemented in **GeneratingTask** class).\n\n#### Installation\n```bash\n$ composer require phphleb/draft\n```\n#### Deployment\n```bash\n$ php console phphleb/draft --add\n```\n#### Generation\nGenerating classes and updating the autoloader. Every time when the settings or template classes are changed, this command is to be started.\n```bash\n$ php console drafts/generating-task --update-all\n$ composer dump-autoload\n```\n\nThe 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.\n\nUsing settings from one template (\"draft\"), you can create a lot of similar classes for different tasks. Each\n\"draft\" is arbitrary in content, the principle of substituting settings into it is simple, and it is specified as follows.\n\n`1` Array with settings:\n```php\nreturn [\n'AClass' =\u003e [\n        'TestDraftClass' =\u003e [\n            'ActionName' =\u003e 'new \\DateTime',\n            'Value' =\u003e '\\'now\\'',\n            'ReturnType' =\u003e '\\DateTimeInterface',\n            'Description' =\u003e 'Demo A class'\n        ]\n    ],\n'BClass' =\u003e [\n        'TestDraftClass' =\u003e [\n            'ActionName' =\u003e 'implode',\n            'Value' =\u003e '[100,500]',\n            'ReturnType' =\u003e 'string',\n            'Description' =\u003e 'Demo B class'\n        ]\n    ],\n];\n```\n`2` Schematic template class **TestDraftClass.php** (default setting values for substitution are neutral-random to support syntax highlighting in IDE)\n```php\n\u003c?php\n/* *//**\u003c-@Description*/\nclass TestDraftClass/**\u003c-@ClassName*/\n{\n  private const VALUE = null/**\u003c-@Value*/;\n  public function get(): void/**\u003c-@ReturnType*/\n  {\n     return /**\u003c-@ActionName*/(self::VALUE);\n  }\n}\n````\n`3` After starting the generation, two working classes are obtained:\n\n```php\n\u003c?php\n/* Demo A class */\nclass AClass\n{\n  private const VALUE = 'now';\n  public function get(): \\DateTimeInterface\n  {\n     return new \\DateTime(self::VALUE);\n  }\n}\n````\n```php\n\u003c?php\n/* Demo B class */\nclass BClass\n{\n  private const VALUE = [100,500];\n  public function get(): string\n  {\n     return implode(self::VALUE);\n  }\n}\n````\n\nThe substitution was performed according to markers ```/**\u003c-@```...```*/```, then the value on the left to the marker, before the gap char, was taken, and all this was substituted with the suitable value from the class configuration.\nOnly this rule is to be taken into account, on creating your own classes-\"drafts\" and their settings.\n\nBy default, some examples illustrating generation capabilities were created in this library (**services.php** file and **DraftInstances** folder with \"drafts\").\n\n#### Switch to testing\nAllows you to reassign classes from another folder (with stubs) for the entire project.\n```bash\n$ php console drafts/generating-task --update-all /app/Optional/tests/services.php\n$ composer dump-autoload\n```\nAfter that, you can run tests.\n\nAttention! Only for the development server. Then you need to switch back to default.\n\n#### Updating the library\n\n```bash\n$ composer update phphleb/draft\n$ php console phphleb/draft --add\n$ php console drafts/generating-task --update-all\n$ composer dump-autoload\n```\n\n-----------------------------------\n\n\n[![License: MIT](https://img.shields.io/badge/License-MIT%20(Free)-brightgreen.svg)](https://github.com/phphleb/draft/blob/main/LICENSE) ![PHP](https://img.shields.io/badge/PHP-^7.3.0-blue) ![PHP](https://img.shields.io/badge/PHP-8-blue) ![PHP](https://img.shields.io/badge/HLEB-\u003e=1.5.72-brightgreen)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphphleb%2Fdraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphphleb%2Fdraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphphleb%2Fdraft/lists"}