PHP code example of mlebkowski / silex-private-scope

1. Go to this page and download the library: Download mlebkowski/silex-private-scope 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/ */

    

mlebkowski / silex-private-scope example snippets


$app = new Nassau\Silex\ScopedApplication([
    'version' => 1.0,
]);

$app['private-service'] = function () { };
$app['version']; // 1.0; services are registered as public if passed to constructor

$app['private-service']; // throws \Nassau\Silex\PrivateScopeViolationException

$app = new Nassau\Silex\ScopedApplication;
$app['public-service'] = $app->publish(function (Silex\Application $app) { 
    return $app['private-service'];
});
$app['private-service'] = function () { return "private" }

$app['public-service']; // "private";