https://github.com/jk-oster/simple-php-mvc
A simple custom mvc framework for PHP
https://github.com/jk-oster/simple-php-mvc
Last synced: 6 months ago
JSON representation
A simple custom mvc framework for PHP
- Host: GitHub
- URL: https://github.com/jk-oster/simple-php-mvc
- Owner: jk-oster
- License: mit
- Created: 2022-06-23T12:46:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-22T11:19:51.000Z (over 2 years ago)
- Last Synced: 2025-02-16T05:28:36.298Z (10 months ago)
- Language: PHP
- Homepage:
- Size: 222 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://justforfunnoreally.dev)
# A simple mvc framework
@author Jakob Osterberger
I coded this little framework to get familiar with the MVC pattern and how it is used in PHP applications.
The framework includes a:
### Database class to ease DB access, provides methods to:
- establish and manage multiple DataBase connections
### QueryBuilder class to ease DB access, provides methods to:
- build SQL queries (select, where, insert, update, delete, join, limit, count, orderBy)
- execute SQL queries
- fetch results
- fetch single result queries
### Model - a simple DataClass which provides:
- magic GETTER
- magic SETTER
- static method to map an array to Domain Object
- array access to Domain Object
- serializing to JSON
### BaseRepository
Takes care of CRUD operations and ORM for Domain Objects.
Automatically retrieves all fields & keys of domain in database by naming convention of extended Model
(e.q. 'UserRepository' -> DomainModelName = 'User', DataBaseTableName = 'user'). Provides methods to:
- CREATE new rows in DataBase Table
- RETRIEVE rows from DataBase Table
- UPDATE rows of DataBase Table
- DELETE rows from DataBase Table
### BaseController
- provides a basic implementation of a controller
### Router
- provides methods to register routes
- provides methods to dispatch routes
- provides methods to redirect to routes
- provides methods to register middlewares
### Route
- provides methods to register middlewares
- provides methods to register callbacks (controller methods)
### Request
- Wrapper for PHP's $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION, $_ENV, $_REQUEST, php://input
### Response
Wrapper for PHP's header() and setcookie() functions
- provides methods to set HTTP status code
- provides methods to set HTTP headers
- provides methods to set HTTP cookies
- provides methods to set HTTP body
### Collection
Provides methods to work with collections and arrays in a functional way (inspired by Laravel's Collection class)
### View
- provides methods to render views
- provides methods to render partials
- provides methods to render layouts
## Development with [REPL](https://github.com/ramsey/composer-repl-lib)
Run the PHP REPL with the following command:
```shell
./vendor/bin/repl
```
## Run Tests
```shell
./vendor/bin/phpstan analyse src SimpleMvc
./vendor/bin/phpunit tests
```