PHP code example of beauty-framework / core

1. Go to this page and download the library: Download beauty-framework/core 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/ */

    

beauty-framework / core example snippets


use Beauty\Kernel\App;

Manager::bootFrom([
    \App\Container\Base::class,
    \App\Container\DI::class,
]);

$app = new App(
    container: $container,
);

$app->handle($request);

use Beauty\Core\Router\Route;

class UserController
{
    #[Route(method: \Beauty\Http\Enums\HttpMethodsEnum::GET, path: '/users')]
    public function index(HttpRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return new JsonResponse(200, [
            'name' => $request->json('name'),
        ]);
    }
}

use Beauty\Container\ContainerManager;

$container = ContainerManager::bootFrom([
    \App\Container\Base::class,
    \App\Container\DI::class,
]);

$service = $container->get(SomeService::class);

use Beauty\Config\ConfigRepository;

$config = config('app.debug');

class UserRegisteredEvent 
{
    public function __construct(
        public string $email
    ) {}
}

class SendWelcomeEmailListener 
{
    public function handle(UserRegisteredEvent $event): void 
    {
        // Send email
    }
}

use Beauty\Http\Middleware\MiddlewareInterface;

class AuthMiddleware implements MiddlewareInterface 
{
    public function process(HttpRequest $request, RequestHandlerInterface $handler): ResponseInterface 
    {
        // Auth check
        return $handler->handle($request);
    }
}

class SomeCommand extends AbstractCommand 
{
    protected string $name = 'hello';

    public function handle(array $args): int 
    {
        $this->line('Hello, world!');
        
        return CLI::SUCCESS;
    }
}