{"id":18029804,"url":"https://github.com/ajaxray/slim-magic","last_synced_at":"2025-04-04T21:13:48.726Z","repository":{"id":142566902,"uuid":"425840257","full_name":"ajaxray/slim-magic","owner":"ajaxray","description":"A tiny, sample blog with Slim Framework using magic Dependency Injection Container.","archived":false,"fork":false,"pushed_at":"2022-03-05T11:16:17.000Z","size":284,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T05:42:04.554Z","etag":null,"topics":["dependency-injection","dependency-manager","sample-app","slim-4","slim-framework","slim-micro-framework"],"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/ajaxray.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-08T13:04:30.000Z","updated_at":"2023-06-09T11:35:51.000Z","dependencies_parsed_at":"2023-05-05T10:31:15.235Z","dependency_job_id":null,"html_url":"https://github.com/ajaxray/slim-magic","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/ajaxray%2Fslim-magic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxray%2Fslim-magic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxray%2Fslim-magic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxray%2Fslim-magic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajaxray","download_url":"https://codeload.github.com/ajaxray/slim-magic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249549,"owners_count":20908212,"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":["dependency-injection","dependency-manager","sample-app","slim-4","slim-framework","slim-micro-framework"],"created_at":"2024-10-30T09:11:33.323Z","updated_at":"2025-04-04T21:13:48.702Z","avatar_url":"https://github.com/ajaxray.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slim-Magic Blog\n\nA very minimalistic, sample blog application [Slim Framework][SLIM].\n\nThe purpose of this application is to test if the [magic][M] Dependency Container is working with [Slim Framework][SLIM] and also to check the design decisions. \nSo, instead of completing the blog centric features, I’ve focused on demonstrating Dependency Injection Container usages and design layers.\n\n![Blog Screenshot](/resources/screenshot.jpg)\n\n## Selection of components\n- **Framework**: Used Slim Framework for a few reasons:\n    - Simplicity. For a minimalistic approach, a microframework like Slim is more suitable. \n    - Slim uses PSR-11: Container interface compatible Dependency Injection Container and allows using any third party container that implements PSR-11. \n    - Not opinioned. We can design application layers ourselves.\n- **Data Accessors**: [Doctrine DBAL][DD] - The Doctrine DataBase Abstraction Layer (DBAL) offers an object-oriented API and a lot of additional.\n- **Dependency Injection Container**: [Magic][M] The DI we are testing in this project\n- **View Rendering**: Using Twig or any other view library for this simple app seems overkill. So, I have written a simple class `App\\Service\\Template` to render plain PHP templates with placeholder variables.\n- **WYSIWYG Editor**: [SimpleMDE][MDE] - a simple, embeddable, and beautiful JS markdown editor.\n- **CSS Framework**: [Skeleton][SK] - this dead simple framework only styles a handful of standard HTML elements and includes a grid.\n\n## Design Overview\n\n### Directory Structure and Logical layers\n\nSlim does not expose any specific directory structure. So it’s easy to organize the files that represent the system's logical layers.\n\n| Directory      | Purpose                                                                                                                                                |\n|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|\n| public         | Contains the FrontController (inde.php) and static assets                                                                                              |\n| config         | All kind of configurations - from Service definitions to Routs                                                                                         |\n| src/Action     | The Controller classes that handle and respond to http Requests. They use task performers under src/Domain. Do not use the Data Access layer directly. |\n| src/Exception  | Purpose specific custom Exception classes.                                                                                                             |\n| src/Repository | The Data Access Layer - interacts with data sources.                                                                                                   |\n| src/Domain     | The Domain Logic remains here. Uses Data Access Layer when required.                                                                                   |\n| src/Services   | Arbitrary functionalities and Utility classes. Can be used across the layers. (e,g, from Actions, Domain etc.)                                         |\n| src/Traits     | Common functionalities that can be used by selective Actions.                                                                                          |\n| templates      | Plain php template/view files. The templates are Rendered using App\\Service\\Template Service.                                                          |\n| vendor         | Contains dependencies. Auto generated by composer.                                                                                                     |\n\n### The Request Lifecycle\n\n1. All HTTP Requests are received by `public/index.php`. It loads the bootstrapped application from config/bootstrap.php and runs the application.\n2. The `config/bootstrap.php` loads and prepares the application. Primarily it performs -\n   - Create and configure the Dependency Container using `config/container.php`\n   - Loads the defined routes from `config/routes.php`\n   - Registers required middlewares using `config/middleware.php`\n3. Slim matches the appropriate route based on URL and invokes configured Action.\n4. The required Services and domain classes are injected to Action class via constructor with proper type hinting and naming.\n5. The DC instantiates the Action class by supplying asked dependencies. Then calls the  `__invoke()` method.\n6. The  `__invoke()` method handles the Request and prepares the Response by rendering view file(s). It used the injected Services where needed.\n7. The request may be passed through middlewares before and after generating the Response. Middlewares may add/modify the request outcome. For example - generating and validating CSRF protection data.\n\n## How to test\n\n### Testing with Docker\n\n#### 1. Prerequisites\n- You should have `composer` installed. [Download composer](https://getcomposer.org/download/) if required.\n- You should have `docker` and `docker-compose` installed. [Check instructions](https://docs.docker.com/compose/install/) otherwise. \n\n#### 2. Run the application\nExecute the following 3 commands from project root directory sequentially:\n```shell\ngit clone https://github.com/ajaxray/slim-magic.git blog\ncd blog\ncp .env.dist .env\n# Set DB connection options in the .env file at this point\ndocker-compose up --build -d\ndocker-compose exec app composer install --prefer-dist --no-interaction\n```\n\n#### 3. Prepare Database\nGo to \u003chttp://localhost:8081\u003e, Adminer (a tiny alternative to phpMyAdmin) should be running here.  \nLogin with host: db and user-password  mentioned in `.env` file.\nThen select the database “blog”. Import (at left-top corner of page) the database dump `resources/db_dump.sql` file. \nIt should create the posts table with sample posts.\n\n#### 4. Go live!\nGo to \u003chttp://localhost:8080\u003e, You should see the blog home page with a list of recent posts.  \nLogin (user: admin, password: 123123) to add new posts and edit posts.\n\n#### 5. Exit plan\nRun this command to stop docker containers\n```shell\ndocker-compose down\n```\n\n### Notes:\n\n1. If you are testing manually,\n    - Use the sql dump at `resources/db_dump.sql` to create the posts table.\n    - Set database connection by updating “dsn” in `config/container.php`. \n    - Install dependencies with composer\n    ```shell\n    composer install --prefer-dist\n    ```\n2. The default user-pass for logging in is admin/123123. You can change it in “auth” values in `config/container.php`.\n\n## Compromises considering “minimalistic”\n- Not implemented User management. A fixed login credential (in config/settings.php) is being used for login instead.\n- Not implemented commenting, Category and Tagging features.\n\n\n\n\n[M]: https://github.com/ajaxray/magic\n[DD]: https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/index.html\n[SK]: http://getskeleton.com\n[MDE]: https://simplemde.com\n[SLIM]: https://www.slimframework.com\n[PSR11]: http://www.php-fig.org/psr/psr-11/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajaxray%2Fslim-magic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajaxray%2Fslim-magic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajaxray%2Fslim-magic/lists"}