{"id":17492137,"url":"https://github.com/jupitern/slim3-skeleton","last_synced_at":"2025-04-16T05:57:47.299Z","repository":{"id":48502409,"uuid":"69554373","full_name":"jupitern/slim3-skeleton","owner":"jupitern","description":"Slim3 skeleton (http + cli) with some add-ons out of the box","archived":false,"fork":false,"pushed_at":"2021-06-11T10:13:42.000Z","size":669,"stargazers_count":44,"open_issues_count":4,"forks_count":12,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-19T11:17:06.515Z","etag":null,"topics":["php-framework","skeleton-application","slim","slim-cli","slim-framework","slim3","slim3-skeleton"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jupitern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-29T09:50:12.000Z","updated_at":"2024-08-20T11:13:30.000Z","dependencies_parsed_at":"2022-09-19T06:41:33.792Z","dependency_job_id":null,"html_url":"https://github.com/jupitern/slim3-skeleton","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupitern%2Fslim3-skeleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupitern%2Fslim3-skeleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupitern%2Fslim3-skeleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupitern%2Fslim3-skeleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jupitern","download_url":"https://codeload.github.com/jupitern/slim3-skeleton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249205819,"owners_count":21229999,"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":["php-framework","skeleton-application","slim","slim-cli","slim-framework","slim3","slim3-skeleton"],"created_at":"2024-10-19T08:08:05.609Z","updated_at":"2025-04-16T05:57:47.277Z","avatar_url":"https://github.com/jupitern.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slim Framework 3 Skeleton Application (http + cli)\n\nUse this skeleton application to quickly setup and start working on a new Slim Framework 3 application (Tested with slim 3.12).\nThis application handles http and command line requests.\nThis application ships with a few service providers and a session middleware out of the box.\nSupport for container resolution and auto-wiring.\n\nTo remove a service provider comment it on config/app.php file and remove it from composer.json, update composer.\n\nAvailable service providers:\n\n* [SlashTrace](https://github.com/slashtrace/slashtrace)\n* [Monolog](https://github.com/Seldaek/monolog)\n* [Eloquent](https://github.com/illuminate/database)\n* [Plates](https://github.com/thephpleague/plates)\n* [Twig](https://github.com/twigphp/Twig)\n* [Flysystem](https://github.com/thephpleague/flysystem)\n* [PHPMailer](https://github.com/PHPMailer/PHPMailer)\n* [Redis](https://github.com/predis/predis)\n\nAvailable middleware:\n\n* Session\n\n### Install the Application\n\nRun this command from the directory in which you want to install your new Slim Framework application.\n\n    php composer.phar create-project jupitern/slim3-skeleton [my-app-name]\n\nReplace `[my-app-name]` with the desired directory name for your new application. You'll want to:\n\n* Point your virtual host document root to your new application's `public/` directory.\n* Ensure `storage/` is web writable.\n* make the necessary changes in config file config/app.php\n\n### Run it:\n\n1. `$ cd [my-app-name]\\public`\n2. `$ php -S localhost:8080` OR `$ composer serve`\n3. Browse to http://localhost:8080\n\n\n### Key directories\n\n* `app`:        Application code (models, controllers, cli commands, handlers, middleware, service providers and others)\n* `config`:     Configuration files like db, mail, routes...\n* `lib`:        Other project classes like utils, business logic and framework extensions\n* `storage`:    Log files, cache files and your raw, un-compiled assets such as LESS, SASS, or JavaScript.\n* `public`:     The public directory contains `index.php` file, assets such as images, JavaScript, and CSS\n* `views`:      Views template files.\n* `vendor`:     Composer dependencies\n\n### Routing and dependency injection\n\nThe app class has a route resolver method that:\n* matches and injects params into the controller action passed as uri arguments\n* looks up and injects dependencies from the container by matching controller constructor / method argument class names\n* automatic Resolution using controller constructor / method argument types\n* accepts string or Response object as controller action response\n\nExample defining two routes for a website and backend folders:\n\n```php\n\nuse \\Psr\\Http\\Message\\ServerRequestInterface as Request;\nuse \\Psr\\Http\\Message\\ResponseInterface as Response;\n\n// simple route example\n$app-\u003eget('/welcome/{name}', function (Request $request, Response $response, $args) {\n\t$name = $request-\u003egetAttribute('name');\n\t$response-\u003egetBody()-\u003ewrite(\"Hello, $name\");\n\n\treturn $response;\n});\n\n\n// example route to resolve request to uri '/' to \\App\\Http\\Site\\Welcome::index\n$app-\u003eany('/', function ($request, $response, $args) use($app) {\n\treturn $app-\u003eresolveRoute([\\App\\Http\\Welcome::class, \"index\"], $args);\n});\n\n\n// example calling http://localhost:8080/index.php/test/nuno with the route bellow\n// injects the :name param value into the method $name parameter\n// Other parameters in the method will be searched in the container by classname or automatically resolved\n// in this example the resolveRoute method will create a user instance and inject it in the controller method\n$app-\u003eany('/test[/{name}]', function ($request, $response, $args) use($app) {\n\treturn $app-\u003eresolveRoute([\\App\\Http\\Welcome::class, \"method\"], $args);\n});\n\nnamespace App\\Http;\nuse Jupitern\\Slim3\\App\\Http\\Controller;\n\nclass Welcome extends Controller\n{\n\tpublic function method($name, \\App\\Model\\User $user)\n\t{\n\t    return get_class($user).\"\u003cbr/\u003ename = {$name}\";\n\t}\n}\n\n```\n\n### Console usage\n\n* Usage: php cli.php [command-name] [method-name] [parameters...]\n* Help: php cli.php help\n\nHow to create a new command:\n 1. Create a class under directory app\\Console in namespace App\\Console\n 2. Your class should extend \\App\\Console\\Command\n 3. create a public method with some params.\n 4. DONE!\n\nExample:\n\nCommand class:\n```php\nnamespace App\\Console;\n\nclass Test extends Command\n{\n\n\tpublic function method($a, $b='foobar')\n\t{\n\t\treturn\n\t\t\t\"\\nEntered console command with params: \\n\".\n\t\t\t\"a= {$a}\\n\".\n\t\t\t\"b= {$b}\\n\";\n\t}\n}\n```\n\nExecute the class:method from command line:\n\n```php\n// since param \"b\" is optional you can use one of the following commands\n\n\u003e php cli.php Test method a=foo b=bar\n\n\u003e php cli.php Test method a=foo\n```\n\n### Code examples\n\nGet application instance\n```php\n$app = \\Lib\\Framework\\App::instance();\n// or simpler using a helper function\n$app = app();\n```\n\nDebug a variable, array or object using the debug helper function\n```php\ndebug(['a', 'b', 'c']);\n// or debug and exit passing true as second param\ndebug(['a', 'b', 'c'], true);\n```\n\n\nRead a user from db using Laravel Eloquent service provider\n```php\n$user = \\App\\Model\\User::find(1);\necho $user-\u003eName;\n```\n\nSend a email using PHPMailer service provider service named 'mail' on config file\n```php\n/* @var $mail \\PHPMailer\\PHPMailer\\PHPMailer */\n$mail = app()-\u003eresolve('mail');\n$mail-\u003eaddAddress('john.doe@domain.com');\n$mail-\u003eSubject = \"test\";\n$mail-\u003eBody    = \"\u003cb\u003etest body\u003c/b\u003e\";\n$mail-\u003eAltBody = \"alt body\";\n$mail-\u003esend();\n```\n\nList a directory content with Flysystem service provider named 'fs_local' on config file\n```php\n$filesystem = app()-\u003eresolve('fs_local');\n$contents = $filesystem-\u003elistContents(STORAGE_PATH, true);\nvar_dump($contents);\n```\n\nWrite and read from session using Session Helper class\n```php\n// save user info in session\n\\Jupitern\\Slim3\\Utils\\Session::set('user', ['id' =\u003e '1']);\n// get user info from session\n$uservar = \\Jupitern\\Slim3\\Utils\\Session::get('user');\nvar_dump($uservar);\n```\n\nWrite and read from cache with Redis service provider named 'redis' on config file\n```php\n/** @var \\Jupitern\\Slim3\\Utils\\Redis $cache */\n$cache = app()-\u003eresolve('redis');\n$cache-\u003eset(\"cacheKey\", \"some test value\");\necho $cache-\u003eget(\"cacheKey\");\n```\n\n## Changelog\n\nv3.0\n - moved core code to another package.\n - route resolution using reflection can now be switched off for performance.\n - config file services changed structure.\n - register services in container using a string instead of classnames.\n - code refactor and improvements.\n\nv2.6\n - Replaced Whoops and Collision packages by slashtrace that provides http and cli debug\n\nV2.5\n - Allow for providers and middleware to be registered only for a given scope (dependent on app name)\n - general code improvements and error handling when developing rest api\n\n\n## Roadmap\n\n - [ ] more service providers / separate service providers in packages\n - [ ] more code examples\n\n## Contributing\n\n - welcome to discuss a bugs, features and ideas.\n\n## License\n\njupitern/slim3-skeleton is release under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupitern%2Fslim3-skeleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjupitern%2Fslim3-skeleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupitern%2Fslim3-skeleton/lists"}