コード例 #1
0
ファイル: TwigView.php プロジェクト: deltaphp/deltacore
 public function initExtension($extension, \Twig_Environment $render, \Twig_Loader_Filesystem $fileSystemLoader)
 {
     if (false === strpos($extension, "\\")) {
         $extension = "\\" . $extension;
     }
     $config = $this->getConfig();
     switch ($extension) {
         case "\\TranslationExtension":
             $config = isset($config["translationExtension"]) ? $config["translationExtension"] : [];
             $lang = isset($config["lang"]) ? $config["lang"] : "ru";
             $locale = isset($config["locale"]) ? $config["locale"] : "ru_RU";
             $translator = new \Symfony\Component\Translation\Translator($locale);
             $translator->addLoader('xlf', new \Symfony\Component\Translation\Loader\XliffFileLoader());
             $vendorFormDir = VENDOR_DIR . '/symfony/form/Symfony/Component/Form';
             $vendorValidatorDir = VENDOR_DIR . '/symfony/validator/Symfony/Component/Validator';
             $translator->addResource('xlf', $vendorFormDir . "/Resources/translations/validators.{$lang}.xlf", $locale, 'validators');
             $translator->addResource('xlf', $vendorValidatorDir . "/Resources/translations/validators.{$lang}.xlf", $locale, 'validators');
             $extension = new \Symfony\Bridge\Twig\Extension\TranslationExtension($translator);
             break;
         case "\\FormExtension":
             $config = isset($config["formExtension"]) ? $config["formExtension"] : [];
             $templates = $config["templates"] ?: "/vendor/symfony/twig-bridge/Resources/views/Form";
             $templates = $this->getRootDir() . "/" . $templates;
             $fileSystemLoader->addPath($templates);
             $formTemplate = $config["formTheme"] ?: "form_div_layout.html.twig";
             $formTemplate = (array) $formTemplate;
             $formEngine = new \Symfony\Bridge\Twig\Form\TwigRendererEngine($formTemplate);
             $formEngine->setEnvironment($render);
             $extension = new \Symfony\Bridge\Twig\Extension\FormExtension(new \Symfony\Bridge\Twig\Form\TwigRenderer($formEngine, $this->getFormCsrfProvider()));
             break;
         default:
             $extension = new $extension();
     }
     return $extension;
 }
コード例 #2
0
ファイル: di.php プロジェクト: nitheeshp/bookshelf
    $session = new \Symfony\Component\HttpFoundation\Session\Session();
    $session->start();
    return $session;
}), 'translator' => \DI\factory(function () {
    $translator = new \Symfony\Component\Translation\Translator('en_US', new \Symfony\Component\Translation\MessageSelector());
    $translator->addLoader('php', new \Symfony\Component\Translation\Loader\PhpFileLoader());
    $translator->addResource('php', './app/Resources/translator/en_US.php', 'en_US');
    $translator->addResource('php', './app/Resources/translator/it_IT.php', 'it_IT');
    return $translator;
}), 'template' => \DI\factory(function (\DI\Container $c) {
    $twigBridgeViews = __DIR__ . '/../vendor/symfony/twig-bridge/Resources/views/Form';
    $loader = new Twig_Loader_Filesystem([$twigBridgeViews, './app/Resources/view']);
    $twig = new Twig_Environment($loader, $c->get('parameters')['twig']['loader_options']);
    $twig->addGlobal('show_exception_backtrace', $c->get('parameters')['twig']['show_exception_backtrace']);
    $twig->addGlobal('session', $c->get('session'));
    $formEngine = new \Symfony\Bridge\Twig\Form\TwigRendererEngine(['bootstrap_3_layout.html.twig']);
    $formEngine->setEnvironment($twig);
    $formExt = new \Symfony\Bridge\Twig\Extension\FormExtension(new \Symfony\Bridge\Twig\Form\TwigRenderer($formEngine));
    $twig->addExtension($formExt);
    $transExt = new \Symfony\Bridge\Twig\Extension\TranslationExtension($c->get('translator'));
    $twig->addExtension($transExt);
    return $twig;
}), 'router' => function () {
    return \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) {
        $r->addRoute('GET', '/', ['ClassicApp\\Controller\\IndexController', 'index']);
        $r->addRoute('GET', '/book', ['ClassicApp\\Controller\\BookController', 'index']);
        $r->addRoute('GET', '/book/new', ['ClassicApp\\Controller\\BookController', 'create']);
        $r->addRoute('POST', '/book/new', ['ClassicApp\\Controller\\BookController', 'create']);
    });
}, 'redis' => \DI\factory(function (\DI\Container $c) {
    $redis = new Redis();