1. Go to this page and download the library: Download aliengen/pachyderm 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/ */
aliengen / pachyderm example snippets
use Pachyderm\Dispatcher;
use Pachyderm\Exchange\Response;
$dispatcher = new Dispatcher();
// Declare a new GET endpoint
$dispatcher->get('/my_endpoint', function() {
return Response::success(['success' => true]);
});
// Dispatch the request
$dispatcher->dispatch();
use Pachyderm\Dispatcher;
use Pachyderm\Middleware\MiddlewareManager;
use Pachyderm\Middleware\PreflightRequestMiddleware;
use Pachyderm\Middleware\TimerMiddleware;
use Pachyderm\Middleware\DbSessionMiddleware;
use Pachyderm\Middleware\SessionMiddleware;
use Pachyderm\Middleware\SessionAuthMiddleware;
use Pachyderm\Middleware\JSONEncoderMiddleware;
use Pachyderm\Exchange\Response;
/*
* Instantiate the dispatcher with a base URL and middleware manager.
*/
$dispatcher = new Dispatcher('/api', new MiddlewareManager());
/* Declaration of the middleware. */
$dispatcher->registerMiddlewares([
JSONEncoderMiddleware::class,
PreflightRequestMiddleware::class,
SessionMiddleware::class,
SessionAuthMiddleware::class,
TimerMiddleware::class,
DbSessionMiddleware::class
]);
/**
* Declaration of the routes.
*/
$dispatcher->get('/my_endpoint', function() {
return Response::success(['success' => true]);
});
$dispatcher->post('/my_post_endpoint', function($data) {
return Response::success(['success' => true]);
});
/**
* Dispatch the request.
*/
$dispatcher->dispatch();
$dispatcher->registerMiddlewares([
JSONEncoderMiddleware::class,
PreflightRequestMiddleware::class,
// Add more middleware as needed
]);
$dispatcher->get('/my_endpoint', function() {
return Response::success(['success' => true]);
},
[
// Local middleware to be applied only to this route
CustomMiddleware::class
],
[
// Global middleware to be excluded from this route
JSONEncoderMiddleware::class
]);
use Pachyderm\Db;
// Define your database configuration parameters
$parameters = [
'host' => 'your_db_host',
'username' => 'your_db_username',
'password' => 'your_db_password',
'database' => 'your_db_name'
];
// Create a new instance of the Db class
$db = new Db($parameters);
// Use the $db instance to perform database operations
$results = $db->findAll('users');
use Pachyderm\Dispatcher;
use Pachyderm\Middleware\MiddlewareManager;
use Pachyderm\Middleware\ExceptionHandlerMiddleware;
$dispatcher = new Dispatcher('/api', new MiddlewareManager());
// Register the ExceptionHandlerMiddleware
$dispatcher->registerMiddlewares([
ExceptionHandlerMiddleware::class,
// Other middlewares...
]);
// Define a route that throws a BadRequestException
$dispatcher->get('/example', function() {
// Simulate a condition that causes a bad request
$condition = false;
if (!$condition) {
throw new BadRequestException('Invalid request parameters.');
}
return Response::success(['success' => true]);
});
// Dispatch the request
$dispatcher->dispatch();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.