PHP code example of bermudaphp / skeleton

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

    

bermudaphp / skeleton example snippets


$routes->addRoute(
    RouteRecord::get('hello.action', '/hello/{name}', static function(string $name) use ($app): ResponseInterface {
        return $app->responde(200, 'Hello, ' . $name);
    })
);

$app->pipe(MyFirstMiddleware::class);
$app->pipe(\Bermuda\Router\Middleware\MatchRouteMiddleware::class);
$app->pipe(MyThirdMiddleware::class);
$app->pipe(\Bermuda\Router\Middleware\DispatchRouteMiddleware::class);

return Config::merge(
    new Bermuda\App\ConfigProvider,
    new Bermuda\HTTP\ConfigProvider,
    new Bermuda\Detector\ConfigProvider,
    new Bermuda\PSR7ServerFactory\ConfigProvider,
    new Bermuda\Router\ConfigProvider,
    new Bermuda\Pipeline\ConfigProvider,
    new Bermuda\MiddlewareFactory\ConfigProvider,
    new Bermuda\ErrorHandler\ConfigProvider,

    new PhpFileProvider('./config/autoload/{{,*.}global,{,*.}local}.php'),
    new PhpFileProvider('./config/development.config.php'),

    // App config provider
    new class extends ConfigProvider {

        /**
         * An associative array that maps a service name to a factory class name, or any callable.
         * Factory classes must be instantiable without arguments, and callable once instantiated (i.e., implement the __invoke() method).
         * @return array
         */
        protected function getFactories(): array
        {
            return [
                BootstrapperInterface::class => static function(ContainerInterface $container): Bootstrapper {
                    return Bootstrapper::withDefaults($container)->add(new class implements BootstrapperInterface {
                        public function boot(AppInterface $app): AppInterface
                        {
                            // Бутстрап приложения выполнится после конфигурации контейнера
                            // здесь можно зарегистрировать алиасы для функций экземпляра приложения или установить новые сущности в контейнер
                            // или все, что необходимо cделать до запуска приложения, но после конфигурации контейнера
                            $app->registerCallback('myCallback', static fn() => 'callback');
                            $app->myCallback() === 'callback' // true
                            $app->set('my-second-dependency', true);
                            $app->extend(MyFirstMiddleware, static function(MyFirstMiddleware $m, AppInterface $app) {
                              return new MyFirstMiddlewareDecorator($m, $app->get('my-second-dependency'));
                            });
                            $app->get(MyFirstMiddleware::class) instanceof MyFirstMiddlewareDecorator // true
                        }
                    });
                },

                MyService::class => static fn(ContainerInterface $container) => new MyService($container->get(MyDependency::class)),
            ];
        }
    },
);

class MyCommand extends Command
{
    public function getName(): string
    {
        return 'myCommand';
    }

    public function getDescription(): string
    {
        return 'MyCommand description';
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // command logics
        return self::SUCCESS;
    }
}
$app->pipe(MyCommands::class);
bash
php bin/console myCommand