samuelgfeller/slim-api-starter
Composer 安装命令:
composer create-project samuelgfeller/slim-api-starter
包简介
API starter template using Slim micro-framework
README 文档
README
Slim
starter
Slim 4 API starter template with a few examples and some essential features to help you build a secure and scalable API following current best practices and SOLID principles.
An extensive documentation explains the architecture, components, design choices (i.e. SRP) and features.
Features
- Dependency Injection - PHP-DI
- Database migrations - Phinx
- Validation - cakephp/validation
- Logging - Monolog
- Query Builder - cakephp/database
- Integration testing - PHPUnit
- Error handling
- GitHub Actions - Scrutinizer
- Coding standards fixer - PHP CS Fixer
- Static code analysis - PHPStan
Requirements
- PHP 8.2+
- Composer
- MariaDB or MySQL database
Installation
1. Create project
Navigate to the directory you want to create the project in and run the following command, replacing project-name with the desired name for your project.
composer create-project samuelgfeller/slim-api-starter project-name
This will create a new directory with the specified name and install all necessary dependencies.
2. Set up the database
Open the project and rename the file config/env/env.example.php to config/env/env.php
and add the local database credentials.
Then, create the database for the project and update the config/env/env.dev.php
file with the name of the database, like this:
$settings['db']['database'] = 'my_dev_database_name';
After that, create a separate database for testing and update the config/env/env.test.php
file with its name. The name must contain the word "test". There is a safety measure to
prevent accidentally truncating the development database while testing:
$settings['db']['database'] = 'my_dev_database_name_test';
3. Run migrations
Open the terminal in the project's root directory and run the following command to create the
demo table user:
composer migrate
4. Insert demo data
Four demo users can be inserted into the database to test the API response by running the following command:
composer seed
5. Update GitHub workflows
To run the project's tests automatically when pushing, update the
.github/workflows/build.yml file.
Replace the matrix value "test-database" with the name of
your test database as specified in config/env/env.test.php.
If you don't plan on using Scrutinizer, remove the .scrutinizer file at the root of the project,
otherwise you can follow this
guide
on how to set it up.
Done!
That's it! Your project should now be fully set up and ready to use.
If you are using XAMPP and installed the project in the htdocs folder, you can access it
in the browser at http://localhost/project-name.
Or you can serve it locally by running php -S localhost:8080 -t public/ in the project's root
directory.
Support
If you value this project and want to support it, star it on GitHub or visit the Support❤️ page. (thank you!)
License
This project is licensed under the MIT License — see the LICENSE file for details.
samuelgfeller/slim-api-starter 适用场景与选型建议
samuelgfeller/slim-api-starter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 samuelgfeller/slim-api-starter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 samuelgfeller/slim-api-starter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-30