1. Go to this page and download the library: Download webpagestudio/wps-micro 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/ */
webpagestudio / wps-micro example snippets
declare(strict_types=1);
use WpsMicro\Core\Env;
use WpsMicro\Core\Kernel;
$rootPath = dirname(__DIR__);
use WpsMicro\Core\Config;
use WpsMicro\Core\Container;
use WpsMicro\Core\Kernel;
use WpsMicro\Core\Router;
$container = new Container();
$container->instance(Router::class, new Router());
$kernel = new Kernel(new Config($config), $container);
use App\Controllers\ControllerProduct;
use WpsMicro\Core\Router;
return static function (Router $router): void {
$router->get('/products/{id}', [ControllerProduct::class, 'actionShow'])
->whereNumber('id')
->name('products.show');
$router->post('/cart/add', [ControllerCart::class, 'actionAdd']);
$router->delete('/cart/{id}', [ControllerCart::class, 'actionRemove']);
};
namespace App\Controllers;
use WpsMicro\Core\Controller;
use WpsMicro\Core\Response;
final class ControllerProduct extends Controller
{
public function actionShow(string $id): Response
{
return $this->render('products/show.twig', ['id' => $id]);
}
}
use WpsMicro\Core\Middleware;
use WpsMicro\Core\Request;
use WpsMicro\Core\Response;
final class AuthMiddleware implements Middleware
{
public function handle(Request $request, callable $next): Response
{
return $next($request);
}
}
use WpsMicro\Core\Migration;
return new class extends Migration {
public function up(PDO $db): void
{
$db->exec('CREATE TABLE products (id INTEGER PRIMARY KEY)');
}
public function down(PDO $db): void
{
$db->exec('DROP TABLE products');
}
};