PHP code example of donchev / framework

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

    

donchev / framework example snippets


return static function (RouteCollector $router) {
    $router->get('/', [HomeController::class, 'index']);
    $router->post('/submit', [ContactController::class, 'submit']);
    $router->get('/blog/{slug}', [BlogController::class, 'show']);
};

class HomeController extends AbstractController
{
    public function index(): void
    {
        $this->renderTemplate('home/index.html.twig', [
            'title' => 'Welcome!'
        ]);
    }
}

use Nette\Mail\Message;

$message = new Message();
$message->setFrom('[email protected]')
        ->addTo('[email protected]')
        ->setSubject('Hello')
        ->setBody('This is a test email.');

$mailer = $container->get(Mailer::class);
$mailer->send($message);

/** @var MeekroDB $db */
$db = $container->get(MeekroDB::class);

$users = $db->query("SELECT * FROM users WHERE active = %i", 1);

use Symfony\Contracts\Cache\CacheInterface;

$cache = $container->get(CacheInterface::class);

$data = $cache->get('some_key', function () {
    return 'cached value';
});

$flash = new FlashService();
$flash->add('success', 'Saved successfully!');

class RequestLoggerMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // logging logic...
        return $handler->handle($request);
    }
}

$validator = new DataValidator();

$data = [
    'name' => 'John Doe',
    'age' => 32
];

$rules = [
    'name' => 'string',
    'age' => 'min:30'
];

$result = $validator->validate($data, $rules);

// Output:
[
  'age' => [
    '"age" must have at least 30 characters'
  ]
]


class AuthController
{
    public function login(Post $post, DataValidator $validator, FlashService $flashService): void
    {
        $data = [
            'email' => $post->get('email'),
            'password' => $post->get('password'),
        ];

        $rules = [
            'email' => '

$sanitizer = new DataSanitizer();

$data = ['asd123', '1.5ds'];
$sanitized = $sanitizer->sanitize($data, 'float');

// Output: [123.0, 1.5]

class HelloCommand extends Command
{
    protected string $signature = 'hello';
    protected string $description = 'Says hello';

    public function handle(): void
    {
        $this->info('Hello from the Tiny Framework!');
    }
}
bash
php bin/console hello