mlebkowski/silex-private-scope

Private scope handling for Silex container

0.1 2015-02-27 13:52 UTC

This package is auto-updated.

Last update: 2024-04-23 18:19:33 UTC


README

Create an instance of ScopedApplication to hide your services by default:

$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

Create a public service by using publish() method. Private services will be available from inside the closure:

$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";