{"id":21194451,"url":"https://github.com/cspray/annotated-console","last_synced_at":"2025-03-14T21:28:16.888Z","repository":{"id":56870472,"uuid":"526770807","full_name":"cspray/annotated-console","owner":"cspray","description":"A small library for creating Symfony Console apps using Annotated Container!","archived":false,"fork":false,"pushed_at":"2022-09-08T10:17:11.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-14T20:57:51.466Z","etag":null,"topics":["annotated-container","symfony-console"],"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/cspray.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":"2022-08-19T22:48:04.000Z","updated_at":"2022-08-25T11:09:22.000Z","dependencies_parsed_at":"2022-08-20T11:21:09.286Z","dependency_job_id":null,"html_url":"https://github.com/cspray/annotated-console","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cspray%2Fannotated-console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cspray%2Fannotated-console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cspray%2Fannotated-console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cspray%2Fannotated-console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cspray","download_url":"https://codeload.github.com/cspray/annotated-console/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243648321,"owners_count":20324855,"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":["annotated-container","symfony-console"],"created_at":"2024-11-20T19:22:15.556Z","updated_at":"2025-03-14T21:28:16.868Z","avatar_url":"https://github.com/cspray.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Annotated Console\n\nAnnotated Console is a way to autowire and configure [symfony/console](https://github.com/symfony/console) applications using [Annotated Container](https://github.com/cspray/annotated-container). Out of the box, Annotated Console is intended to provide the following features:\n\n- Automatically add Command instances to a Symfony Application.\n- Allow configuring a Command using PHP 8 Attributes.\n- Depend on services in Command constructors and take advantage of other functionality provided by [Annotated Container](https://github.com/cspray/annotated-container).\n\n## Installation\n\nI recommend installing Annotated Console using [Composer](https://getcomposer.org).\n\n```shell\ncomposer require cspray/annotated-console:dev-main cspray/annotated-container:v2.x-dev\n```\n\n\u003e Annotated Console currently requires Annotated Container v2.x-dev. When Annotated Container releases 2.0 this library \n\u003e will release a 1.0 package.\n\n## Quick Start\n\nAnnotated Console is designed to get going in a few straightforward steps.\n\n## Step 1 - Initiate your Container\n\nThe functionality for this library is primarily provided by [Annotated Container](https://github.com/cspray/annotated-container). Which means you need to make sure that your configuration is setup to boostrap your app. As long as you have a PSR-4 or PSR-0 autoload configuration setup in your `composer.json` you can run the following command from the root of your project:\n\n```shell\n./vendor/bin/annotated-container init\n```\n\nBy default, the init command will create a directory to cache your Container so static analysis doesn't have to run on every Command. Early in development it is advised to disable the cache by removing the `\u003ccacheDir\u003e` element from the configuration file. It is important that if new Services or Commands are added the Container cache is busted appropriately.\n\n## Step 2 - Create your App's Binary\n\nNext, you'll need to create the file that you'll use to run your app. You can name and store this file anywhere you'd like, but we'll put our example in `./bin/acme`.\n\n```php\n#!/usr/bin/env php\n\u003c?php declare(strict_types=1);\n\nuse Cspray\\AnnotatedConsole\\AnnotatedConsole;\nuse Symfony\\Component\\Console\\Input\\ArgvInput;\n\nrequire_once dirname(__DIR__) . '/vendor/autoload.php';\n\n// Customize this as appropriate for your installation. Please check out Annotated Container docs for more information\n// If your list of profiles only ever includes 'default' you can skip over providing $profiles completely\n$profiles = ['default'];\n$exitCode = (new AnnotatedConsole(profiles: $profiles))-\u003erun(new ArgvInput());\nexit($exitCode);\n```\n\nAfter you've added this script ensure you run `chmod +x ./bin/acme` so that you can execute it!\n\n## Step 3 - Add your Commands\n\nAt this point you're ready to start adding Commands! Anywhere in a directory scanned by Annotated Container, this will be defined in the `annotated-container.xml` file created in Step 1, implement an object that extends Command and is controlled by the Container.\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace Acme\\Demo;\n\nuse Symfony\\Component\\Console\\Command\\Command;\nuse Cspray\\AnnotatedConsole\\Attribute\\ConsoleCommand;\nuse Symfony\\Component\\Console\\Input\\InputInterface;\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\n\n#[ConsoleCommand('hello-world')]\nclass HelloWorld extends Command {\n\n    protected function execute(InputInterface $input, OutputInterface $output) {\n        $output-\u003ewriteln('Hello, world!');\n    }\n\n}\n```\n\nNow, if you run `./bin/acme hello-world` your Command will be executed!\n\nYou can configure the bulk of your Command through the ConsoleCommand Attribute. Check out the `demo` directory for \nmore examples, including configuring arguments and options.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcspray%2Fannotated-console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcspray%2Fannotated-console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcspray%2Fannotated-console/lists"}