PHP code example of hexmakina / le-marchand

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

    

hexmakina / le-marchand example snippets


$settings = [  
  'app' => [
    'name' => 'KORAL',
    'production_host' => 'engine.hexmakina.be',
    'session_start_options' => ['session_name' => 'koral-alias'],
    'time_window_start' => '-3 months',
    'time_window_stop' => '+1 month',
  ],
  'controller_namespaces' => [
    'App\\Controllers\\',
    'HexMakina\\koral\\Controllers\\',
    'HexMakina\\kadro\\Controllers\\'
  ]
];

$box = new LeMarchand($settings);

$box->has('settings'); // returns true
$box->has('settings.app.name'); // returns true
$box->get('settings.app.name'); // returns 'KORAL'

$box->register('HexMakina\Crudites\ConnectionInterface', $connection);

// Resolve a setting
$solver->probeSettings('settings.app.name'); // Returns 'KORAL'

// Resolve a class
$solver->probeClasses(App\Controllers\UserController::class);

// Resolve an interface
$solver->probeInterface(App\Contracts\LoggerInterface::class);

// Resolve dynamically using namespaces
$solver->probeCascade('Controllers\UserController');

$factory = new Factory($box);

// Retrieve a cached instance or create a new one
$instance = $factory->serve(App\Services\EmailService::class);

// Build a new instance of a class
$newInstance = $factory->build(App\Models\User::class);

// Create a singleton
$singleton = $factory->buildSingleton(new \ReflectionClass(App\Services\Singleton::class), ['getInstance', []]);

// Resolve a service with constructor dependencies
$controller = $box->get(App\Controllers\UserController::class);

$singleton = $factory->buildSingleton(
    new \ReflectionClass(App\Services\Logger::class),
    ['getInstance', []]
);