1. Go to this page and download the library: Download ween/conveyor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ween / conveyor example snippets
use Conveyor\Route;
Route::get('/', function() {
return 'GET request';
});
Route::post('/', function() {
return 'POST request';
});
Route::any('/', function() {
return 'both GET and POST request';
});
Route::get('/', 'DemoControllers@method');
// Will dispatch routes, run the middlewares and finally call the matched method
Route::dispatch();
// Capture the matched array, which
Route::get('/a/(:all)b/ab', function() {
return 'I can receive all request uri like /a/abcb/ab, /a/123b/ab, /a/b/c/db/ab';
});
Route::get('/a/(:any)b/ab', function() {
return 'I can receive all request uri like /a/ab/ab, /a/4b/ab, /a/a4b/ab';
});
Route::get('/a/(:num)b/ab', function() {
return 'I can receive all request uri like /a/0123456789b/ab';
});
/**
* $params recognize three keywords now:
* $params['prefix'] set a prefix uri for current group;
* $params['namespace'] set the namespace for current group, so that class can be autoloaded with PSR-4;
* $params['middleware'] set some registered middlewares before call final function.
*/
Route::group(array $params, closure $callback);
Route::group(['prefix' => '/user', 'namespace' => 'App\\Controller\\'], function() {
Route::group(['prefix' => '/sub1', 'namespace' => 'Bpp\\Controller\\', 'middleware' => 'foo, bar'], function() {
Route::get('/', function() {
return 'I can receive uri like /user/sub1';
});
// Request /user/sub1/abc will load class DemoController in namespace Bpp\\Controller\\
// Middleware will not work because no registered middleware exist.
Route::get('/abc', 'DemoController@method');
});
Route::group(['prefix' => '/sub2'], function() {
Route::get('/', function() {
return 'I can receive uri like /user/sub2/';
});
Route::get('/a(:all)', function() {
return 'I can receive all request uri start with /user/sub2/a';
});
});
});
use Conveyor\Route;
Route::register([
'namespace' => 'App\\Controllers\\',
'alias' => [
'home' => \App\Middlewares\HomeMiddleware::class,
]
]);
// some routes...
Route::get('abc', 'HomeController@demo')->middleware('home');
namespace App\Middlewares;
class HomeMiddleware
{
public function handle()
{
// $result = 'result of your milldeware validation';
if ($result) {
// if validate success, just return true
return true;
} else {
// if failed ,please give a response array
// [some fields...]
return ['result' => 'error', 'msg' => 'error message'];
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.