├── .gitignore ├── README.md ├── routes └── users.php ├── app └── Controllers │ └── UsersController.php ├── composer.json ├── composer.lock └── public └── index.php /.gitignore: -------------------------------------------------------------------------------- 1 | ### Composer ### 2 | composer.phar 3 | /vendor/ 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jedi-php 2 | 3 | Jedi PHP Framework - *The New Hope* 4 | -------------------------------------------------------------------------------- /routes/users.php: -------------------------------------------------------------------------------- 1 | get('/', [UsersController::class, 'index']); 12 | 13 | $app->get('/:user(\d+)', [UsersController::class, 'show']); 14 | -------------------------------------------------------------------------------- /app/Controllers/UsersController.php: -------------------------------------------------------------------------------- 1 | args->user; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "devhammed/jedi-php-template", 3 | "description": "Template for Jedi PHP Framework, The New Hope!", 4 | "type": "project", 5 | "license": "MIT", 6 | "version": "0.0.3", 7 | "authors": [ 8 | { 9 | "name": "Hammed Oyedele", 10 | "email": "itz.harmid@gmail.com" 11 | } 12 | ], 13 | "autoload": { 14 | "psr-4": { 15 | "App\\": "app/" 16 | } 17 | }, 18 | "minimum-stability": "stable", 19 | "require": { 20 | "devhammed/jedi-php": "^0.0.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "941603d2e9bb8579c0fa9645dd1c45dd", 8 | "packages": [ 9 | { 10 | "name": "devhammed/jedi-php", 11 | "version": "0.0.1", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/devhammed/jedi-php.git", 15 | "reference": "47431c123a89ae7b404cb96c4c10e643d48d8a41" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/devhammed/jedi-php/zipball/47431c123a89ae7b404cb96c4c10e643d48d8a41", 20 | "reference": "47431c123a89ae7b404cb96c4c10e643d48d8a41", 21 | "shasum": "" 22 | }, 23 | "type": "library", 24 | "autoload": { 25 | "psr-4": { 26 | "Jedi\\": "src/" 27 | } 28 | }, 29 | "notification-url": "https://packagist.org/downloads/", 30 | "license": [ 31 | "MIT" 32 | ], 33 | "authors": [ 34 | { 35 | "name": "Hammed Oyedele", 36 | "email": "itz.harmid@gmail.com" 37 | } 38 | ], 39 | "description": "Jedi PHP Framework, The New Hope!", 40 | "time": "2020-11-05T11:29:43+00:00" 41 | } 42 | ], 43 | "packages-dev": [], 44 | "aliases": [], 45 | "minimum-stability": "stable", 46 | "stability-flags": [], 47 | "prefer-stable": false, 48 | "prefer-lowest": false, 49 | "platform": [], 50 | "platform-dev": [], 51 | "plugin-api-version": "1.1.0" 52 | } 53 | -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | use(function (Context $context, Closure $next) { 12 | try { 13 | return $next($context); 14 | } catch (Throwable $e) { 15 | return $context->res->send( 16 | 'Something bad just happened.', 17 | 500, 18 | ); 19 | } 20 | }); 21 | 22 | $app->get('/', function () { 23 | return '

Home Page

'; 24 | }); 25 | 26 | $app->map('ANY', '/input', function (Context $context) { 27 | return '

Input:

' . $context->req->input('h'); 28 | }); 29 | 30 | // Sample group routes 31 | $app->group('/api', function () use ($app) { 32 | // Sample middleware for groups 33 | // This also demonstrate nested error handling 😁😁😁 34 | $app->use(function (Context $context, Closure $next) { 35 | try { 36 | return $next($context); 37 | } catch (Throwable $e) { 38 | return $context->res->send( 39 | [ 40 | 'ok' => \false, 41 | 'message' => 'Something bad just happened.', 42 | ], 43 | 500, 44 | ); 45 | } 46 | }); 47 | 48 | $app->get('/', function () { 49 | return [ 50 | 'ok' => true, 51 | 'message' => 'Welcome to our API.', 52 | ]; 53 | }); 54 | 55 | $app->get('/error', function () { 56 | throw new Error('Testing error handling for API'); 57 | 58 | return 'Error'; 59 | }); 60 | 61 | $app->group('/users', function () use ($app) { 62 | include_once(__DIR__ . '/../routes/users.php'); 63 | }); 64 | }); 65 | 66 | $app->get('/contact', function () { 67 | return '

Contact Us Page

'; 68 | }); 69 | 70 | $app->get('/error', function () { 71 | throw new Error('Testing error handling for pages'); 72 | 73 | return 'Error'; 74 | }); 75 | 76 | $app->fallback(function () { 77 | return 'Get outta here!'; 78 | }); 79 | 80 | $app->run(); 81 | --------------------------------------------------------------------------------