phdomiciano/phcodemvc
Composer 安装命令:
composer create-project phdomiciano/phcodemvc
包简介
This is a simple CRUD of courses list with MVC but without Frameworks.
README 文档
README
This is a simple CRUD of courses list with MVC but without Frameworks. The challenge is not to use external frameworks but to develop an entire MVC structure following good practices and concepts.
Requirements
- PHP ^8.1
- Composer
This code uses
- PSR-4: Autoloading (Composer)
- DOCTRINE/ORM
- SQLITE
Installation
Install the package through Composer.
Run the Composer require command from the Terminal:
composer create-project phdomiciano/phcodemvc
If necessary update your requiries, run on Terminal:
composer update
composer dump-autoload
Create the sqlite database and all tables required, run on terminal:
php db.php migrate
Run on Terminal your php server and access the url from project in a web browser.
php -S localhost:8080
Applied solutions
- Requests Forms Validation
- Dependency Injection
- Polymorphism
- Anonymous classes
Developed solutions
Migration
To be used in a development environment, a script was created that can be executed by Terminal, for small instructions to the database, such as creating the database, executing migrations, consulting records and tables, among others. For try and more information, run on Terminal:
php db.php help
For new migrations, a structure similar to other Frameworks was created, just create a new file in the "database/migrate" folder
Index
The index.php file is the application's Core, responsible for filtering, forwarding the routes and executing the first validations.
Routes
To create a new route, simply add it to the "config/routes.php" file. Intuitively, following in a simplified way the pattern of the main existing Frameworks.
The Route class, located in the "src/infra" folder, is responsible for identifying and filtering the route information, according to the "routes.php" list.
Request
The parent Request class, located in "src/requests", manages http requests, facilitates data handling and sanitizes all input data automatically regardless of the submitted method. This class can be used for manual or automatic validation of form data through the "validate()" method.
The "validate()" method can receive an array of filters manually or capture the validation rules automatically from the child classes of Request.
The custom Request class can be configured in the "routes.php" file. If no custom Request is provided for the route, the system automatically loads the parent class, allowing manual validations.
Controller
The Controller parent class already has an entityManager and an object of the Request class.
Auth
The Auth class, located in the "src/infra" folder, can be used anywhere on the system. It handles and stores user authentication information, record ownership validation, and CSRF token management.
View
The View class, located in the "src/infra" folder, must be used in controllers to display views. This class is responsible for finding view files, managing alerts and errors with automatic capture. Alerts and errors are treated like flash messages, being automatically deleted after the first read.
CSRF protection
This code is concerned with CSRF (Cross-site request forgery). The Auth class manages random tokens that change with each submit and all forms must contain a hidden one with this token, which is automatically compared by the Request class every time some data is requested. Form submits don't work if the form doesn't have this hidden with valid token. Hidden can be easily created in any view, as the View class loads an Auth object with a method that generates a hidden. Just print this inside each form:
<?=$auth->token();?>
ORM by Attributes
Doctrine was used as ORM, configured with mapping by Attributes instead of Annotations, in a more visual way and without having to use comments as code.
PSRs and best practices
This code meets PSRs, following some of the established standards like PSR-4, PSR-1 and PSR-12. Code identification, clean code, code structure, typing variables and function parameters, as well as defining return types.
phdomiciano/phcodemvc 适用场景与选型建议
phdomiciano/phcodemvc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「mvc」 「crud」 「courses」 「courseslist」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phdomiciano/phcodemvc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phdomiciano/phcodemvc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phdomiciano/phcodemvc 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Kinikit - PHP Application development framework MVC component
Gii Generator for double model generation
A PSR-7 compatible library for making CRUD API endpoints
Admin panel generator for Laravel 8 and based on Vuetify Admin, a separate SPA admin framework running on top of REST APIs.
Collection of tools to use the full power of the Enyalius framework
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-23