{"id":25963585,"url":"https://github.com/drewm/slim-commander","last_synced_at":"2025-03-04T20:47:17.308Z","repository":{"id":56972152,"uuid":"122182330","full_name":"drewm/slim-commander","owner":"drewm","description":"A very simple structure for running CLI commands as part of your Slim Framework application.","archived":false,"fork":false,"pushed_at":"2018-02-20T13:38:47.000Z","size":7,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-08T22:17:45.394Z","etag":null,"topics":["cli","slimphp"],"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/drewm.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":"2018-02-20T10:12:17.000Z","updated_at":"2022-04-11T10:19:16.000Z","dependencies_parsed_at":"2022-08-21T10:20:13.984Z","dependency_job_id":null,"html_url":"https://github.com/drewm/slim-commander","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewm%2Fslim-commander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewm%2Fslim-commander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewm%2Fslim-commander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewm%2Fslim-commander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drewm","download_url":"https://codeload.github.com/drewm/slim-commander/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241921824,"owners_count":20042764,"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":["cli","slimphp"],"created_at":"2025-03-04T20:47:16.658Z","updated_at":"2025-03-04T20:47:17.298Z","avatar_url":"https://github.com/drewm.png","language":"PHP","readme":"# SlimCommander\n\nA very simple structure for running CLI commands as part of your Slim Framework application.\n\nThis is not a console tool. It's just a parallel to the HTTP entry point into your application, \nenabling you to do things like create create scripts to be run as cronjobs or set up basic queue listeners.\n\n## Usage \n\nTaking the structure of Slim-Skeleton as an example, your `public/index.php` does this:\n\n```php\nrequire __DIR__ . '/../vendor/autoload.php';\n\nsession_start();\n\n// Instantiate the app\n$settings = require __DIR__ . '/../src/settings.php';\n$app = new \\Slim\\App($settings);\n\n// Set up dependencies\nrequire __DIR__ . '/../src/dependencies.php';\n\n// Register middleware\nrequire __DIR__ . '/../src/middleware.php';\n\n// Register routes\nrequire __DIR__ . '/../src/routes.php';\n\n// Run app\n$app-\u003erun();\n```\n\nYou need to create a new PHP script, similar to this, to serve as the entry point for your commands. \nIt should be outside the `public` folder. Perhaps `src/cli.php`.\n\n```php\nrequire __DIR__ . '/../vendor/autoload.php';\n\n// Instantiate the app\n$settings = require __DIR__ . '/settings.php';\n$app = new \\DrewM\\SlimCommander\\App($settings);\n\n// Set up dependencies\nrequire __DIR__ . '/dependencies.php';\n\n// Register commands instead of routes\nrequire __DIR__ . '/commands.php';\n\n// Run app\n$app-\u003erun($argv);\n```\n\nInstead of routes, you define commands in e.g. `src/commands.php`.\n\n```php\n$app-\u003ecommand('HelloWorld', 'HelloWorld:greet', [\n    'name',\n]);\n```\n\nArguments are:\n\n1. Name of the command\n2. The callback, defined in the same way as a regular Slim route callback\n3. An array of expected argument names\n\nIn the above example, the first argument will be passed to the callback as `name`\n\nYour callback gets the container passed to its constructor:\n\n```php\nclass HelloWorld\n{\n    private $container;\n\n    public function __construct($container)\n    {\n        $this-\u003econtainer = $container;\n    }\n\n    public function greet($args)\n    {\n        echo \"Hello \" . $args['name'];\n    }\n}\n```\n\nAdd it to your container, just as you would normally:\n\n```php\n$container['HelloWorld'] = function ($container) {\n    return new \\App\\Commands\\HelloWorld($container);\n};\n```\n\nAnd then you'd execute it with `php src/cli.php HelloWorld Fred`","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrewm%2Fslim-commander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrewm%2Fslim-commander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrewm%2Fslim-commander/lists"}