1. Go to this page and download the library: Download nicolachoquet06250/php-lib 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/ */
nicolachoquet06250 / php-lib example snippets
namespace appExample\controllers_directory;
use PhpLib\decorators\Route as RouteAttribute;
use PhpLib\routing\Route;
use PhpLib\injection\Injector;
use PhpLib\interfaces\routing\Router;
#[RouteAttribute('/')]
class ClassController {
use Injector;
public function __construct(
private ?Router $router
) {}
public function get() {
// code of GET http method
}
public function post(int $id) {
// code of POST http method
}
public function put(int $id) {
// code of PUT http method
}
public function delete(int $id) {
// code of DELETE http method
}
#[RouteAttribute(
uri: '/test/toto/{slot}',
httpMethod: Route::GET,
params: [ 'slot' => Route::SLOT ]
)]
public function customGetRoute(string $slot) {
// code of custom GET method
}
#[RouteAttribute(
uri: '/test/toto/{slot}',
httpMethod: Route::POST,
params: [ 'slot' => Route::SLOT ]
)]
public function customPostRoute(string $slot) {
// code of custom GET method
}
}
namespace appExample\error_controllers_directory;
use PhpLib\decorators\ErrorRoute;
use PhpLib\routing\Router;
#[ErrorRoute(Router::NOT_FOUND)]
class NotFound {
public function __construct(
protected string $message,
private int $code,
protected array $stackTrace
) {
http_response_code($this->code);
}
public function get() {
// code of "404 not found" error
}
}
use PhpLib\routing\Router;
use appExample\controllers_directory\ClassController;
use appExample\error_controllers_directory\{ NotFound, BadRequest, InternalError };
use PhpLib\injection\InjectionContainer;
use PhpLib\interfaces\routing\{
Router as RouterInterface,
Context as ContextInterface
};
use PhpLib\routing\{ Context, Router };
s);
// ... rest of code
use PhpLib\injection\Injector;
use PhpLib\interfaces\routing\{
Router as RouterInterface,
Context as ContextInterface
};
class MyClass {
// indispensable for injection in construct
use Injector;
public function __construct(
private ?RouterInterface $router,
private ?ContextInterface $context
) {
// code of construct
}
}
shell
cd [project]
mkdir [error_controllers_directory]
cd [error_controllers_directory]
touch [HttpErrorClass].php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.