PHP code example of mikescott / emissary

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

    

mikescott / emissary example snippets



Slim\App;
use Slim\Container;

$config = [
    'settings' => [
        'database.fetch' => PDO::FETCH_CLASS,
        'database.default' => 'mysql',
        'database.connections' => [
            'mysql' => [
                'driver' => 'mysql',
                'host' => 'mysql',
                'port' => 3306,
                'database' => '',
                'username' => '',
                'password' => '',
                'charset' => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix' => '',
                'strict' => false,
                'engine' => null,
            ],
        ]
    ]
];

$providers = [
    'Illuminate\Database\DatabaseServiceProvider'
];

$aliases = [
    'DB' => 'Illuminate\Support\Facades\DB'
];

$app = new App(new Container($config));

$app->add(new \mikescott\Emissary\Middleware($providers, $aliases));

$app->get('/', function ($request, $response, $args) {
    # Illuminate/Database via facade
    $tables = DB::select('SHOW TABLES');
    var_dump($tables);

    # or via the container:
    $tables = $this->get('db')->select('SHOW TABLES');
    var_dump($tables);
});

$app->run();


Slim\App;
use Slim\Container;

$app = new App(new Container());

$app->add(new \mikescott\Emissary\Middleware([
    'foo\Example\ServiceProvider'
]));

$app->get('/', function ($request, $response, $args) {
    $response->write($this->get('example')->hello());
    return $response;
});

$app->run();


namespace foo\Example;

class Example {
    public function hello()
    {
        return "Hello, world!";
    }
}


namespace foo\Example;

class ServiceProvider extends \Illuminate\Support\ServiceProvider {
    public function register()
    {
        $this->app->singleton('example', function($app) {
           return new Example();
        });
    }
}