{"id":16423584,"url":"https://github.com/rougin/blueprint","last_synced_at":"2025-10-03T23:25:16.541Z","repository":{"id":36133651,"uuid":"40437186","full_name":"rougin/blueprint","owner":"rougin","description":"A bootstrap for PHP console projects.","archived":false,"fork":false,"pushed_at":"2024-10-20T16:33:45.000Z","size":122,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T18:47:07.841Z","etag":null,"topics":["blueprint","file-generator","generator","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"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/rougin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-09T13:27:31.000Z","updated_at":"2024-10-20T16:32:42.000Z","dependencies_parsed_at":"2024-09-15T14:09:19.986Z","dependency_job_id":"eda70000-41db-44e1-9153-ed4b0496edd5","html_url":"https://github.com/rougin/blueprint","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fblueprint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fblueprint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fblueprint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fblueprint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rougin","download_url":"https://codeload.github.com/rougin/blueprint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245072236,"owners_count":20556352,"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":["blueprint","file-generator","generator","php-library"],"created_at":"2024-10-11T07:40:21.344Z","updated_at":"2025-10-03T23:25:11.502Z","avatar_url":"https://github.com/rougin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blueprint\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]][link-license]\n[![Build Status][ico-build]][link-build]\n[![Coverage Status][ico-coverage]][link-coverage]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nBlueprint is a PHP package for bootstrapping console applications.\n\n## Installation\n\nInstall `Blueprint` via [Composer](https://getcomposer.org/):\n\n``` bash\n$ composer require rougin/blueprint\n```\n\n## Basic Usage\n\n### Creating a new `blueprint.yml`\n\nCreate a `blueprint.yml` file by running the `initialize` command:\n\n``` bash\n$ vendor/bin/blueprint initialize\n```\n\n``` yml\n# blueprint.yml\n\nname: Blueprint\nversion: 0.7.0\n\npaths:\n  templates: %%CURRENT_DIRECTORY%%/src/Templates\n  commands: %%CURRENT_DIRECTORY%%/src/Commands\n\nnamespaces:\n  commands: Rougin\\Blueprint\\Commands\n```\n\n\u003e [!NOTE]\n\u003e * Replace the values specified in the `blueprint.yml` file.\n\u003e * Add commands and templates (if applicable) to their respective directories.\n\n### Creating a command\n\nPrior to creating a command, the `commands` property in `blueprint.yml` must be updated:\n\n``` yml\n# blueprint.yml\n\n# ...\n\nnamespaces:\n  commands: Acme\\Commands\n```\n\nThen create the command (e.g., `TestCommand`) to the specified directory:\n\n``` php\n// src/Commands/TestCommand.php\n\nnamespace Acme\\Commands;\n\nuse Symfony\\Component\\Console\\Command\\Command;\nuse Symfony\\Component\\Console\\Input\\InputInterface;\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\n\nclass TestCommand extends Command\n{\n    protected function configure()\n    {\n        $this-\u003esetName('test')-\u003esetDescription('Returns a \"Test\" string');\n    }\n\n    protected function execute(InputInterface $input, OutputInterface $output)\n    {\n        $output-\u003ewriteln('\u003cinfo\u003eTest\u003c/info\u003e');\n    }\n}\n```\n\n### Updating the `composer.json`\n\nAfter creating the command (e.g., `TestCommand`), kindly check if its namespace is defined in `Composer`:\n\n``` json\n// composer.json\n\n// ...\n\n\"autoload\":\n{\n  \"psr-4\":\n  {\n    \"Acme\\\\\": \"src\"\n  }\n}\n\n// ...\n```\n\n``` bash\n$ composer dump-autoload\n```\n\n### Running the command\n\nThe created commands will be recognized automatically by Blueprint. With this, it could be executed in the same `blueprint` command:\n\n``` bash\n$ vendor/bin/blueprint test\n\nTest\n```\n\n## Extending Blueprint\n\nThe `v0.7.0` version introduces a way to extend the `Blueprint` package to use it as the console application for specified projects.\n\n### Initializing the instance\n\nTo initialize a console application, the `Blueprint` class must be created first:\n\n``` php\n// bin/app.php\n\nuse Rougin\\Blueprint\\Blueprint;\n\n// Return the root directory of the project ----------\n$root = (string) __DIR__ . '/../../../../';\n\n$exists = file_exists($root . '/vendor/autoload.php');\n\n$root = $exists ? $root : __DIR__ . '/../';\n// ---------------------------------------------------\n\nrequire $root . '/vendor/autoload.php';\n\n$app = new Blueprint;\n```\n\nAfter creating the `Blueprint` class, the following details can now be updated:\n\n``` php\n// bin/app.php\n\n// ...\n\n// Set the name of the console application. ----\n$app-\u003esetName('Acme');\n// ---------------------------------------------\n\n// Set the version of the console application. ----\n$app-\u003esetVersion('0.1.0');\n// ------------------------------------------------\n\n// Set the directory for the defined commands. ----\n$app-\u003esetCommandPath(__DIR__ . '/../src/Commands');\n// ------------------------------------------------\n\n// Set the directory for the templates. Might be useful ------\n// if creating commands with template engines (e.g., Twig) ---\n$app-\u003esetTemplatePath(__DIR__ . '/../src/Templates');\n// -----------------------------------------------------------\n\n// Set the namespace for the \"commands\" path. ----\n$namespace = 'Acme\\Simplest\\Commands';\n$app-\u003esetCommandNamespace($namespace);\n// -----------------------------------------------\n\n// Run the console application ---\n$app-\u003erun();\n// -------------------------------\n```\n\n\u003e [!NOTE]\n\u003e Using this approach means the `blueprint.yml` can now be omitted. This approach is also applicable to create customized console applications without the `Blueprint` branding.\n\nThen run the console application in the terminal:\n\n``` bash\n$ php bin\\app.php\n\nAcme 0.1.0\n\nUsage:\n  command [options] [arguments]\n\nOptions:\n  -h, --help            Display help for the given command. When no command is given display help for the list command\n  -q, --quiet           Do not output any message\n  -V, --version         Display this application version\n      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output\n  -n, --no-interaction  Do not ask any interactive question\n  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n\nAvailable commands:\n  completion  Dump the shell completion script\n  help        Display help for a command\n  list        List commands\n```\n\n### Customized `Command` class\n\n`Blueprint` also provides an alternative `Command` class for creating commands with descriptive methods and less code:\n\n``` php\n// src/Commands/TestCommand.php\n\nnamespace Acme\\Commands;\n\nuse Rougin\\Blueprint\\Command;\n\nclass TestCommand extends Command\n{\n    protected $name = 'test';\n\n    protected $description = 'Returns a \"Test\" string';\n\n    public function execute()\n    {\n        $this-\u003eshowPass('Test');\n    }\n}\n```\n\n\u003e [!NOTE]\n\u003e All of the functionalities for the `Command` class is derived from the [`Symfony's Console` component](https://symfony.com/doc/current/console.html#creating-a-command).\n\n### Injecting dependencies\n\nTo perform [automagic resolutions](https://github.com/rougin/slytherin/wiki/Container) in each defined commands, the `addPackage` can be used with the additional functionality from the `Container` class from [`Slytherin`](https://roug.in/slytherin/):\n\n``` php\n// src/Sample.php\n\nnamespace Acme;\n\nclass Sample\n{\n    protected $name;\n\n    public function __construct($name)\n    {\n        $this-\u003ename = $name;\n    }\n\n    public function getName()\n    {\n        return $this-\u003ename;\n    }\n}\n```\n\n``` php\n// src/Packages/SamplePackage.php\n\nnamespace Acme\\Packages;\n\nuse Acme\\Sample;\nuse Rougin\\Slytherin\\Container\\ContainerInterface;\nuse Rougin\\Slytherin\\Integration\\Configuration;\nuse Rougin\\Slytherin\\Integration\\IntegrationInterface;\n\nclass SamplePackage implements IntegrationInterface\n{\n    public function define(ContainerInterface $container, Configuration $config)\n    {\n        return $container-\u003eset(Sample::class, new Sample('Blueprint'));\n    }\n}\n```\n\n``` php\n// bin/app.php\n\nuse Acme\\Packages\\SamplePackage;\nuse Rougin\\Slytherin\\Container\\Container;\n\n// ...\n\n// Add the specified integration (or package) to the container ---\n$container = new Container;\n\n$container-\u003eaddPackage(new SamplePackage);\n// ---------------------------------------------------------------\n\n// Set the container to the console application ---\n$app-\u003esetContainer($container);\n// ------------------------------------------------\n\n```\n\nWith the above-mentioned integration, for any command that uses the `Sample` class will get the `text` value as the `$name` property:\n\n``` php\nnamespace Acme\\Commands;\n\nuse Acme\\Sample;\nuse Rougin\\Blueprint\\Command;\n\nclass TextCommand extends Command\n{\n    protected $name = 'text';\n\n    protected $description = 'Shows a sample text';\n\n    protected $sample;\n\n    public function __construct(Sample $sample)\n    {\n        $this-\u003esample = $sample;\n    }\n\n    public function run()\n    {\n        $this-\u003eshowText('Hello, ' . $this-\u003esample-\u003egetName() . '!');\n\n        return self::RETURN_SUCCESS;\n    }\n}\n```\n\n``` bash\n$ php bin/app.php text\n\nHello, Blueprint!\n```\n\n## Changelog\n\nPlease see [CHANGELOG][link-changelog] for more information what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Credits\n\n- [All contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE][link-license] for more information.\n\n[ico-build]: https://img.shields.io/github/actions/workflow/status/rougin/blueprint/build.yml?style=flat-square\n[ico-coverage]: https://img.shields.io/codecov/c/github/rougin/blueprint?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/rougin/blueprint.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-version]: https://img.shields.io/packagist/v/rougin/blueprint.svg?style=flat-square\n\n[link-build]: https://github.com/rougin/blueprint/actions\n[link-changelog]: https://github.com/rougin/blueprint/blob/master/CHANGELOG.md\n[link-contributors]: https://github.com/rougin/blueprint/contributors\n[link-coverage]: https://app.codecov.io/gh/rougin/blueprint\n[link-downloads]: https://packagist.org/packages/rougin/blueprint\n[link-license]: https://github.com/rougin/blueprint/blob/master/LICENSE.md\n[link-packagist]: https://packagist.org/packages/rougin/blueprint\n[link-upgrading]: https://github.com/rougin/blueprint/blob/master/UPGRADING.md","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frougin%2Fblueprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frougin%2Fblueprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frougin%2Fblueprint/lists"}