PHP code example of phpdevcommunity / michel-core

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

    

phpdevcommunity / michel-core example snippets


define('MICHEL_COMPOSER_AUTOLOAD_FILE', dirname(__DIR__) .'/vendor/autoload.php');

final class Kernel extends BaseKernel
{
    public function getCacheDir(): string
    {
        return $this->getProjectDir() . '/var/cache';
    }

    public function getProjectDir(): string
    {
        return dirname(__DIR__);
    }

    public function getLogDir(): string
    {
        return $this->getProjectDir() . '/var/log';
    }

    public function getConfigDir(): string
    {
        return $this->getProjectDir() . '/config';
    }

    public function getPublicDir(): string
    {
        return $this->getProjectDir() . '/public';
    }

    protected function afterBoot(): void
    {
        // You can perform additional setup or actions here after the framework has booted.
    }
}


return [

    // Framework Settings

    'server_request' => static function (): ServerRequestInterface {
        return ServerRequestFactory::fromGlobals();
    },

    'response_factory' => static function (): ResponseFactoryInterface {
        return new ResponseFactory();
    },

    'container' => static function (array $definitions, array $options): ContainerInterface {

        // Customize the container configuration here
        
        return new Container(
            $definitions,
            new ReflectionResolver()
        );
    },

    'custom_environments' => [],

];

$kernel = new Kernel();
if (php_sapi_name() !== 'cli') {
    $response = $kernel->handle(App::createServerRequest());
    \send_http_response($response);
}

'server_request' => static function (): ServerRequestInterface {
    // Instantiate a ServerRequest using Laminas Diactoros or your preferred PSR-7 library.
    return \Laminas\Diactoros\ServerRequestFactory::fromGlobals();
},

'response_factory' => static function (): ResponseFactoryInterface {
    // Instantiate a ResponseFactory using Laminas Diactoros or your preferred PSR-17 library.
    return new \Laminas\Diactoros\ResponseFactory();
},

'container' => static function (array $definitions, array $options): ContainerInterface {
    // Instantiate a PSR-11 compatible container using \PhpDevCommunity\DependencyInjection\Container or your preferred library.
    return new \PhpDevCommunity\DependencyInjection\Container($definitions, new \PhpDevCommunity\DependencyInjection\ReflectionResolver());
},

'custom_environments' => [],