PHP code example of satori / micro

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

    

satori / micro example snippets


declare(strict_types=1);

use Satori\Micro\Application;

$app = new Application();

/**
 * Declares an action that has dependencies.
 */
$app->pageIndexAction = function (Application $app) {
    return new \Page\IndexAction(
        $app->pageIndexTemplate,
        $app->pageIndexService
    );
};

/**
 * Declares a template that depends on a configuration parameter.
 */
$app->pageIndexTemplate = function (Application $app) {
    return new \Page\IndexTemplate($app['path.template']);
};

/**
 * Declares an service.
 */
$app->pageIndexService = function (Application $app) {
    return new \Page\IndexService($app['fake.data']);
};

/**
 * Configuration parameters.
 */
$app['path.root'] = __DIR__ . '/../..';
$app['path.template'] = $app['path.root'] . '/template/site';
$app['fake.data'] = ['foo' => 'Foo', 'bar' => 'Bar'];

$action = $app->pageIndexAction;

declare(strict_types=1);

use Satori\Micro\Application;
use App\Logger;

$app = new Application();

/**
 * Declares a logger.
 */
$app->logger = function (Application $app) {
    return new \App\Logger();
};

/**
 * Subscribes a listener to an event.
 *
 * @param string   $event    The unique name of the event.
 * @param string   $listener The unique name of the listener.
 * @param callable $callback The closure or invokable object.
 */
$app->subscribe(
    'system_error', // $event
    'logger',       // $listener
    function (Application $app, array $arguments = null) {
        $logger = $app->logger;
        $logger->log('error', 'System error', $arguments);
    }
);


$app->notify('system_error', ['file' => '/app/functions.php', 'line' => 20]);