Dockerized Pure PHP Composer based MVC Framework
This project tries to cover some PHP features in a simple MVC structure with minimum installed composer packages. Then developers can use packages for specific requirements. Please add your ideas in Discussions, ask features or report bugs in issues.
Features:
List of features related with structure
- public Contains the index.php file, to start application and configures auto-loading. Different server configurations added into this directory too. Finally, you can find the Sitemap generator that runs after creation or updating a post.
- public/assets Assets can contain your media files like images, audios & videos.
- public/css & public/js
Contains the styles & scripts (After changes on these files, you can use minifier script to update minified versions, just run
docker-compose exec php-mvc-app php minifier.php
) - public/feed There is a RSS generator in here and runs after creation or updating a post.
- grpc
A simple router for distribute the requests to different services. It is not working yet and I created an issue for it
⚠ and if you have an idea or a solution, only by PHP for both server and client sides, please add your solution in there. - websocket A WebSocket sample. You can open /websocket route in 2 tabs and test the websocket connection.
- src Contains migrations for a DB and routes.
- src/App Contains all classes that used in codes like PDO, Middleware, Router & ...
- src/Console Contains all scripts to run multiple times via Cron Jobs (Scripts should be registered in /commands.php with custom timing, they will run by independent service in docker-compose)
- src/Controllers
Controllers related with your routes separated for web and API. API folder includes both RESTful API and gRPC API. If you want use gRPC (gRPC client & server are not completed, and I ignored them for now. So be careful about the bugs in gRPC
⚠ and if you have an idea or a solution, only by PHP, please make a new discussion/issue/PR), you can find .proto file in API folder. Updating it will need to generate PHP codes again by
docker-compose exec php-mvc-app protoc -I=src/Controllers/API \
src/Controllers/API/blog.proto \
--php_out=src/Controllers/API/gRPC \
--grpc_out=src/Controllers/API/gRPC \
--plugin=protoc-gen-grpc=/usr/bin/grpc_php_plugin
- src/Models Models related with controllers' DB queries & requirements.
- src/Views Simple PHP files to show data on Frontend with reusable include files.
- / You can update env variables and composer.json to add custom packages.
Useful Functions:
- XmlGenerator::feed() Generate sitemap.xml & rss.xml via a script file
- HandleForm::upload(...) Upload file, resize image & add watermark
- HandleForm::validate(...) Validation rules
- HandleFile::write(...) & HandleFile::read(...) Write into and read from file
- Helper::mailto(...) Send HTML Email
- Helper::dd(...) Dumps a given variable along with some additional data
- Helper::log(...) Logging custom data into file
- Helper::csrf(...) Check Cross-site request forgery token
- Helper::slug(...) Slugify string to make user-friendly URL
- Cache::checkCache(...), Cache::cache(...) & Cache::clearCache(...) Check existing cache, cache data and clear cache, by Memcached
- UserInfo::current() Return current user information
- UserInfo::info(...) Return selected user information
- Event::listen(...) & Event::trigger(...) Register an event listener and trigger it when needed
Run Web App:
- Install docker and docker-compose if needed
- Uncomment
// createTables();
insrc/routes
- Run
docker-compose up --build -d
- Open your browser and open web app in
localhost:8080
(It will create tables related with migrations.php and then will commentcreateTables();
automatically.) - You can run
docker-compose down
to stop and remove containers - Next time you can use
docker-compose up -d
Use Ajax to send forms' data:
Consider a route for your form like /blog/create
; now use blog-create
as an ID for form, and blog-create-submit
for submit button ID. All form's buttons need to have constant form-button
class.
RESTful API samples
Ready to use PostMan collection for RESTful API side:
Let me know about collaborating: [email protected]