public function register(Application $app) { $app["services.article"] = $app->share(function ($app) { return new services\Article($app["factories.article"], $app["services.guzzle.client"], $app["services.logger"]); }); $app["services.reference"] = $app->share(function ($app) { return new services\Reference($app["factories.reference"], $app["services.guzzle.client"], $app["services.logger"]); }); $app["services.comment"] = $app->share(function ($app) { return new services\Comment($app["factories.comment"], $app["services.guzzle.client"], $app["services.logger"]); }); $app["services.logger"] = function () { return new services\Logger(); }; $app["services.guzzle.client"] = $app->share(function () { return new Client(); }); }
public function register(Application $app) { $app["factories.article"] = $app->protect(function ($id, $date, $title, $body) { return new beans\Article($id, $date, $title, $body); }); $app["factories.reference"] = $app->protect(function ($id, $articleId, $title, $link) { return new beans\Reference($id, $articleId, $title, $link); }); $app["factories.comment"] = $app->protect(function ($id, $articleId, $date, $author, $body) { return new beans\Comment($id, $articleId, $date, $author, $body); }); $app["services.guzzle.client"] = $app->share(function () { return new Client(); }); }
<?php require_once 'vendor/autoload.php'; use Silex\Provider\TwigServiceProvider; use Silex\Provider\TranslationServiceProvider; use Silex\Provider\FormServiceProvider; use Silex\Provider\ValidatorServiceProvider; use Silex\Provider\UrlGeneratorServiceProvider; use Silex\Provider\HttpCacheServiceProvider; use Blongden\Guestbook; class Application extends Silex\Application { use Silex\Application\TwigTrait; use Silex\Application\UrlGeneratorTrait; } $app = new Application(); $app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/views']); $app->register(new TranslationServiceProvider(), ['locale_fallback' => 'en']); $app->register(new FormServiceProvider()); $app->register(new ValidatorServiceProvider()); $app->register(new UrlGeneratorServiceProvider()); $app->register(new HttpCacheServiceProvider(), ['http_cache.cache_dir' => __DIR__ . '/cache', 'http_cache.options' => ['debug' => true]]); $app['guestbook'] = $app->share(function () { return new Guestbook('guestbook.json'); }); $app['request_time'] = $_SERVER['REQUEST_TIME']; return $app;