PHP code example of impulsephp / core

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

    

impulsephp / core example snippets




return [
    'template_engine' => null,
    'template_path' => 'views',
    'providers' => [],
    'middlewares' => [],
    'locale' => 'fr',
    'supported' => ['fr', 'en'],
    'cache' => [
        'enabled' => true,
        'ttl' => 600,
    ],
    'devtools' => false,
];

use Impulse\Core\App;


namespace App\Page;

use App\Layout\DefaultLayout;
use Impulse\Core\Attributes\PageProperty;
use Impulse\Core\Component\AbstractPage;

#[PageProperty(
    route: '/',
    name: 'home',
    title: 'Accueil',
    layout: DefaultLayout::class
)]
final class HomePage extends AbstractPage
{
    public function template(): string
    {
        return <<<HTML
            <h1>Accueil</h1>
        HTML;
    }
}

namespace App\Component;

use Impulse\Core\Attributes\Action;
use Impulse\Core\Component\AbstractComponent;

final class CounterComponent extends AbstractComponent
{
    public function setup(): void
    {
        $this->state('count', 0);
    }

    #[Action]
    public function increment(): void
    {
        $this->count++;
    }

    public function template(): string
    {
        return <<<HTML
            <button>{$this->count}</button>
        HTML;
    }
}

use Impulse\Core\Http\Response;

return Response::redirect('/login');

return Response::redirectToPage('login');

return Response::redirectToPage('login')
    ->withFlash('registered', '1');

$registered = $request->getFlash('registered');

return [
    'env' => 'dev',
    'devtools' => [
        'enabled' => true,
        'address' => 'tcp://127.0.0.1:9567',
    ],
    'providers' => [
        Impulse\Core\Provider\DevToolsProvider::class,
    ],
];