Автор: Fabien Potencier (fabien@symfony.com)
Наследование: implements Symfony\Component\Templating\EngineInterface, implements ArrayAccess
Пример #1
0
 private function generate_content()
 {
     $this->page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
     if (!$this->page) {
         $this->page = filter_input(INPUT_POST, 'page', FILTER_SANITIZE_STRING);
     }
     if (empty($this->page)) {
         $keys = array_keys($this->defaultpage);
         $this->page = $keys[0];
     }
     if (!$this->page_exists()) {
         $this->send_file_not_found_header();
         $loader = new FilesystemLoader(VIEW_PATH . 'navbars/%name%');
         $templating = new PhpEngine(new TemplateNameParser(), $loader);
         $this->topnav = $templating->render('topnav.php', array('foo' => 'bar'));
         $loader2 = new FilesystemLoader(VIEW_PATH . 'system/%name%');
         $templating2 = new PhpEngine(new TemplateNameParser(), $loader2);
         $this->content = $templating2->render('404.php', array('topnav' => $this->topnav));
         $loader3 = new FilesystemLoader(VIEW_PATH . '%name%');
         $templating3 = new PhpEngine(new TemplateNameParser(), $loader3);
         echo $templating3->render('main.php', array('content' => $this->content, 'theme' => 'sparkle2015'));
         return false;
     }
     new $this->controller();
     return true;
 }
Пример #2
0
 /**
  * Render template
  *
  * @param string $migrationName Migration name.
  *
  * @return string Rendered tempalte.
  */
 public function render($migrationName)
 {
     $loader = new FilesystemLoader(__DIR__ . '/views/%name%');
     $view = new PhpEngine(new TemplateNameParser(), $loader);
     $this->templateInitialization->setMigrationName($migrationName);
     return $view->render($this->getTemplatePath(), array('migrationName' => $migrationName, 'initUp' => $this->templateInitialization->getInitUp(), 'initDown' => $this->templateInitialization->getInitDown()));
 }
 public function register(Application $app)
 {
     $app['tmpl'] = function () {
         return new DelegatingEngine();
     };
     $app['tmpl.parser'] = function ($app) {
         $parser = new TemplateNameParser($app['events']);
         $parser->addEngine('php', '.php');
         return $parser;
     };
     $app['tmpl.php'] = function ($app) {
         $helpers = [new SlotsHelper(), new GravatarHelper()];
         if (isset($app['view.styles'])) {
             $helpers[] = new StyleHelper($app['view.styles']);
         }
         if (isset($app['view.scripts'])) {
             $helpers[] = new ScriptHelper($app['view.scripts']);
         }
         if (isset($app['view.sections'])) {
             $helpers[] = new SectionHelper($app['view.sections']);
         }
         if (isset($app['csrf'])) {
             $helpers[] = new TokenHelper($app['csrf']);
         }
         if (isset($app['markdown'])) {
             $helpers[] = new MarkdownHelper($app['markdown']);
         }
         $engine = new PhpEngine($app['tmpl.parser'], new FilesystemLoader([]));
         $engine->addHelpers($helpers);
         return $engine;
     };
 }
Пример #4
0
 protected function render($name, array $args = array(), $status = '200')
 {
     $loader = new FilesystemLoader(__DIR__ . '/../../../../src/Resources/views/%name%');
     $templating = new PhpEngine(new TemplateNameParser(), $loader);
     $templating->set(new SlotsHelper());
     return new Response($templating->render($name, $args), $status);
 }
Пример #5
0
 public static function make($name, array $data = array(), $engine = self::ENGINE_AUTO)
 {
     is_null(self::$TWIG_OPTION_DEBUG) && (self::$TWIG_OPTION_DEBUG = env("TWIG_OPTION_DEBUG", 0));
     is_null(self::$TWIG_OPTION_AUTO_RELOAD) && (self::$TWIG_OPTION_AUTO_RELOAD = env("TWIG_OPTION_AUTO_RELOAD", 1));
     is_null(self::$TWIG_OPTION_CHARSET) && (self::$TWIG_OPTION_CHARSET = env("TWIG_OPTION_CHARSET", "UTF-8"));
     if ($engine == self::ENGINE_AUTO) {
         $name_ext = substr($name, strrpos($name, '.'));
         switch ($name_ext) {
             case ".php":
                 $engine = self::ENGINE_SYMFONY;
                 break;
             case ".twig":
             default:
                 $engine = self::ENGINE_TWIG;
                 break;
         }
     }
     $content = "";
     is_null(self::$VIEWS_DIR) && (self::$VIEWS_DIR = resources_path("views"));
     switch ($engine) {
         case self::ENGINE_SYMFONY:
             $loader = new FilesystemLoader(self::$VIEWS_DIR . DIRECTORY_SEPARATOR . "%name%");
             $templating = new PhpEngine(new TemplateNameParser(), $loader);
             $content = $templating->render($name, $data);
             break;
         case self::ENGINE_TWIG:
             $loader = new \Twig_Loader_Filesystem(self::$VIEWS_DIR);
             $twig = new \Twig_Environment($loader, array('cache' => self::$CACHE_VIEWS_DIR ?: storage_path("cache" . DIRECTORY_SEPARATOR . "views"), 'auto_reload' => self::$TWIG_OPTION_AUTO_RELOAD, 'debug' => self::$TWIG_OPTION_DEBUG, 'charset' => self::$TWIG_OPTION_CHARSET));
             $content = $twig->render($name, $data);
             break;
     }
     return $content;
 }
 public function __construct(PhpEngine $engine, $csrfTokenManager = null, array $defaultThemes = array())
 {
     if ($csrfTokenManager instanceof CsrfProviderInterface) {
         $csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
     } elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
         throw new UnexpectedTypeException($csrfTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
     }
     $engine->addHelpers(array(new FormHelper(new FormRenderer(new FormRendererEngine($engine, $defaultThemes), $csrfTokenManager))));
 }
 public function send($email, $patchFiles)
 {
     $message = \Swift_Message::newInstance();
     $message->setSubject('Some code you are watching has been edited');
     $message->setFrom($this->from);
     $message->setTo($email);
     $message->setBody($this->view->render('htmlEmail', ['patchFiles' => $patchFiles]), 'text/html');
     //$message->addPart($body, 'text/plain');
     return $this->mailer->send($message);
 }
Пример #8
0
 protected function setUp()
 {
     parent::setUp();
     $root = realpath(__DIR__ . '/../../../Resources/views');
     $rootTheme = realpath(__DIR__ . '/Resources');
     $templateNameParser = new StubTemplateNameParser($root, $rootTheme);
     $loader = new FilesystemLoader(array());
     $engine = new PhpEngine($templateNameParser, $loader);
     $this->helper = new FormHelper($engine, $this->getMock('Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface'), array('FrameworkBundle:Form', 'FrameworkBundle:FormTable'));
     $engine->setHelpers(array($this->helper, new TranslatorHelper(new StubTranslator())));
 }
 protected function setUp()
 {
     parent::setUp();
     $root = realpath(__DIR__ . '/../../../Resources/views');
     $rootTheme = realpath(__DIR__ . '/Resources');
     $templateNameParser = new StubTemplateNameParser($root, $rootTheme);
     $loader = new FilesystemLoader(array());
     $engine = new PhpEngine($templateNameParser, $loader);
     $this->helper = new FormHelper($engine, array('FrameworkBundle:Form', 'FrameworkBundle:FormTable'));
     $engine->setHelpers(array($this->helper, new TranslatorHelper(new StubTranslator())));
 }
Пример #10
0
 protected function setUp()
 {
     parent::setUp();
     $root = realpath(__DIR__ . '/../../../Resources/views/Form');
     $rootCustom = realpath(__DIR__ . '/Resources');
     $templateNameParser = new StubTemplateNameParser($root, $rootCustom);
     $loader = new FilesystemLoader(array());
     $engine = new PhpEngine($templateNameParser, $loader);
     $this->helper = new FormHelper($engine);
     $engine->setHelpers(array($this->helper, new TranslatorHelper(new StubTranslator())));
 }
Пример #11
0
 /**
  * Wrapping the original form factory method
  * Get the form helper
  * @author Martin Schindler
  * @return FormHelper
  */
 private function getFormHelper()
 {
     if (!$this->formHelper) {
         $phpEngine = new PhpEngine(new TemplateNameParser(realpath(self::VIEW_PATH)), new FilesystemLoader(array()));
         $formHelper = new FormHelper(new FormRenderer(new TemplatingRendererEngine($phpEngine, $this->getFormThemePaths()), null));
         $translator = new Translator($this->defaultLocale);
         $translator->addLoader('xlf', new XliffFileLoader());
         $phpEngine->addHelpers(array($formHelper, new TranslatorHelper($translator)));
         $this->formHelper = $formHelper;
     }
     return $this->formHelper;
 }
 public function initPlugin()
 {
     $this->app[$this->getPluginName()] = function ($app) {
         $paths = $app->config('templating.paths') ?: [$app['dir.root'] . '/module/' . $app['app.module'] . '/template/%name%'];
         $basePath = $app->config('templating.basePath') ?: $app->request()->getBasePath() . '/assets';
         $loader = new FilesystemLoader($paths);
         $engine = new PhpEngine(new TemplateNameParser(), $loader);
         $engine->addGlobal('app', $app);
         $engine->set(new SlotsHelper());
         $engine->set(new AssetsHelper($basePath));
         $app->event()->emit('plugin.templating.after', [$app, $engine]);
         return $engine;
     };
 }
Пример #13
0
 public function demoAction(Request $request, $template, $slug)
 {
     $criteria = new Criteria();
     $criteria->setSlug($slug);
     $repository = $this->getServices()->get('scribble.repository');
     $scribble = $repository->getOne($criteria);
     if (!$scribble) {
         throw new NotFoundHttpException();
     }
     $loader = new FilesystemLoader(array($this->getServices()->get('theme')->getTemplateDir() . '/%name%', $scribble->getDir() . '/%name%'));
     $view = new PhpEngine(new TemplateNameParser(), $loader);
     $vars = array('request' => $request, 'services' => $this->getServices(), 'scribble' => $scribble);
     return new Response($view->render($template, $vars));
 }
Пример #14
0
    /**
     * Constructor.
     *
     * @param TemplateNameParserInterface $parser    A TemplateNameParserInterface instance
     * @param ContainerInterface          $container The DI container
     * @param LoaderInterface             $loader    A loader instance
     * @param GlobalVariables             $globals   A GlobalVariables instance
     */
    public function __construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader, GlobalVariables $globals)
    {
        $this->container = $container;

        parent::__construct($parser, $loader);
        $this->addGlobal('app', $globals);
    }
 public function getFormHelper()
 {
     if (!$this->form_helper) {
         // Set up requirements - hopefully we can facilitate this more in 2.2
         $engine = new PhpEngine(new SimpleTemplateNameParser(realpath(__DIR__ . '/../views/Form')), new FilesystemLoader(array()));
         //set helpers
         $vendorDir = $this->symfonyVendorDir;
         $defaultThemes = $this->getFormThemePaths();
         $form_helper = new FormHelper(new FormRenderer(new TemplatingRendererEngine($engine, $defaultThemes), null));
         $translator = new Translator('en');
         $translator->addLoader('xlf', new XliffFileLoader());
         $translator->addResource('xlf', realpath($vendorDir . '/form/Resources/translations/validators.en.xlf'), 'en', 'validators');
         $translator->addResource('xlf', realpath($vendorDir . '/validator/Resources/translations/validators.en.xlf'), 'en', 'validators');
         $engine->addHelpers(array($form_helper, new TranslatorHelper($translator)));
         $this->form_helper = $form_helper;
     }
     return $this->form_helper;
 }
Пример #16
0
 public function __construct(Application $app, TemplateNameParserInterface $templateNameParser, LoaderInterface $loader, EscaperInterface $escaper)
 {
     $this->app = $app;
     parent::__construct($templateNameParser, $loader);
     $this->setEscaper('html', [$escaper, 'html']);
     $this->setEscaper('html_attr', [$escaper, 'htmlAttr']);
     $this->setEscaper('js', [$escaper, 'js']);
     $this->setEscaper('url', [$escaper, 'url']);
     $this->setEscaper('css', [$escaper, 'css']);
 }
Пример #17
0
 /**
  * @param type $template Le template à afficher
  * @param array Les options à transmettre à la vue pour les utiliser
  * @return Response
  */
 protected function render($template, array $options = array())
 {
     $loader = new FilesystemLoader(__DIR__ . '/../view/%name%');
     $templating = new PhpEngine(new TemplateNameParser(), $loader);
     $templating->set(new SlotsHelper());
     $templating->set(new AssetsHelper('/'));
     $templating->set(new RouterHelper(new UrlGenerator($this->routes, $this->requestContext)));
     $templating->addGlobal('request', $this->request);
     //Marche bien
     $templating->addGlobal('session', $this->request->getSession());
     $templating->addGlobal('user', $this->request->getSession() ? $this->request->getSession()->get('user') : null);
     $response = Response::create($templating->render($template, $options));
     return $response;
 }
Пример #18
0
 /**
  * @param $mailer \PHPMailer
  * @param $to string
  * @param $subject string
  * @param $body string
  */
 private function sendMail($mailer, $to, $subject, $body)
 {
     $addresses = $this->parseEmails($to);
     if (is_array($addresses)) {
         foreach ($addresses as $address) {
             $mailer->addAddress($address);
         }
     } else {
         $mailer->addAddress($to);
     }
     $mailer->Subject = $subject;
     $loader = new FilesystemLoader(ROOT . '/src/Flock/Templates/%name%');
     $templating = new PhpEngine(new TemplateNameParser(), $loader);
     $mailer->msgHTML($templating->render('message.php', array('custom' => $body)));
     if ($mailer->send()) {
         echo "Message sent!";
     } else {
         echo "The message could not be delivered.";
         echo "Mailer error: " . $mailer->ErrorInfo;
     }
 }
Пример #19
0
 /**
  * Templating engines currently supported:
  * - PHP
  * - Twig
  * - Smarty
  * - Mustache.
  *
  * @param ServiceManager $serviceManager
  *
  * @throws \RuntimeException
  */
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     $config = $serviceManager->get('Config');
     $appRootDir = $config['parameters']['app.root_dir'];
     $appCacheDir = $config['parameters']['app.cache_dir'];
     $appCharset = $config['parameters']['app.charset'];
     // The "framework.templating" option is deprecated. Please replace it with "framework.view"
     $config = $this->processConfiguration($config);
     // these are the templating engines currently supported
     // @todo - this needs to come from the app config.
     $knownEngineIds = array('php', 'smarty', 'twig', 'mustache', 'plates', 'latte');
     // these are the engines selected by the user
     $engineIds = isset($config['engines']) ? $config['engines'] : array('php');
     // filter templating engines
     $engineIds = array_intersect($engineIds, $knownEngineIds);
     if (empty($engineIds)) {
         throw new \RuntimeException(sprintf('At least one templating engine should be defined in your app config (in $config[\'view.engines\']). These are the available ones: "%s". Example: "$config[\'templating.engines\'] = array(\'%s\');"', implode('", ', $knownEngineIds), implode("', ", $knownEngineIds)));
     }
     /*
      * Templating Locator.
      */
     $serviceManager->setFactory('templating.locator', function ($serviceManager) use($appCacheDir) {
         return new TemplateLocator($serviceManager->get('file_locator'), $appCacheDir);
     });
     /*
      * Templating Name Parser.
      */
     $serviceManager->setFactory('templating.name_parser', function ($serviceManager) {
         return new TemplateNameParser($serviceManager->get('modulemanager'));
     });
     /*
      * Filesystem Loader.
      */
     $serviceManager->setFactory('templating.loader.filesystem', function ($serviceManager) {
         return new FileSystemLoader($serviceManager->get('templating.locator'));
     });
     /*
      * Templating assets helper.
      */
     $serviceManager->setFactory('templating.helper.assets', function ($serviceManager) {
         return new AssetsHelper($serviceManager->get('request')->getBasePath());
     });
     /*
      * Templating globals.
      */
     $serviceManager->setFactory('templating.globals', function ($serviceManager) {
         return new GlobalVariables($serviceManager->get('servicemanager'));
     });
     /*
      * PHP Engine.
      *
      * TODO: Migrate to Symfony\Bundle\FrameworkBundle\Templating\PhpEngine
      */
     $serviceManager->setFactory('templating.engine.php', function ($serviceManager) use($appCharset) {
         $engine = new PhpEngine($serviceManager->get('templating.name_parser'), $serviceManager->get('templating.loader'), array(new SlotsHelper(), $serviceManager->get('templating.helper.assets'), new RouterHelper($serviceManager->get('router')), new SessionHelper($serviceManager->get('session'))));
         $engine->addGlobal('app', $serviceManager->get('templating.globals'));
         $engine->setCharset($appCharset);
         return $engine;
     });
     /*
      * Twig Engine
      */
     $serviceManager->setFactory('templating.engine.twig', function ($serviceManager) {
         if (!class_exists('Twig_Environment')) {
             throw new \Exception('PPI\\Framework\\TwigModule not found. Composer require: ppi/twig-module');
         }
         $twigEnvironment = new \Twig_Environment(new \PPI\Framework\View\Twig\Loader\FileSystemLoader($serviceManager->get('templating.locator'), $serviceManager->get('templating.name_parser')));
         // Add some twig extension
         $twigEnvironment->addExtension(new \PPI\Framework\View\Twig\Extension\AssetsExtension($serviceManager->get('templating.helper.assets')));
         $twigEnvironment->addExtension(new \PPI\Framework\View\Twig\Extension\RouterExtension($serviceManager->get('router')));
         return new \PPI\Framework\View\Twig\TwigEngine($twigEnvironment, $serviceManager->get('templating.name_parser'), $serviceManager->get('templating.locator'), $serviceManager->get('templating.globals'));
     });
     /*
      * Smarty Engine.
      */
     $serviceManager->setFactory('templating.engine.smarty', function ($serviceManager) use($appCacheDir) {
         if (!class_exists('NoiseLabs\\Bundle\\SmartyBundle\\SmartyEngine')) {
             throw new \Exception('PPI\\Framework\\SmartyModule not found. Composer require: ppi/smarty-module');
         }
         $cacheDir = $appCacheDir . DIRECTORY_SEPARATOR . 'smarty';
         $smartyEngine = new \PPI\Framework\View\Smarty\SmartyEngine(new \Smarty(), $serviceManager->get('templating.locator'), $serviceManager->get('templating.name_parser'), $serviceManager->get('templating.loader'), array('cache_dir' => $cacheDir . DIRECTORY_SEPARATOR . 'cache', 'compile_dir' => $cacheDir . DIRECTORY_SEPARATOR . 'templates_c'), $serviceManager->get('templating.globals'), $serviceManager->get('logger'));
         // Add some SmartyBundle extensions
         $smartyEngine->addExtension(new SmartyAssetsExtension($serviceManager->get('templating.helper.assets')));
         $smartyEngine->addExtension(new SmartyRouterExtension($serviceManager->get('router')));
         return $smartyEngine;
     });
     // Mustache Engine
     $serviceManager->setFactory('templating.engine.mustache', function ($serviceManager, $appCacheDir) {
         if (!class_exists('Mustache_Engine')) {
             throw new \Exception('PPI\\Framework\\MustacheModule not found. Composer require: ppi/mustache-module');
         }
         $rawMustacheEngine = new \Mustache_Engine(array('loader' => new MustacheFileSystemLoader($serviceManager->get('templating.locator'), $serviceManager->get('templating.name_parser')), 'cache' => $appCacheDir . DIRECTORY_SEPARATOR . 'mustache'));
         return new MustacheEngine($rawMustacheEngine, $serviceManager->get('templating.name_parser'));
     });
     /*
      * Delegating Engine.
      */
     $serviceManager->setFactory('templating.engine.delegating', function ($serviceManager) use($engineIds) {
         $delegatingEngine = new DelegatingEngine();
         // @todo - lazy load this
         foreach ($engineIds as $id) {
             $delegatingEngine->addEngine($serviceManager->get('templating.engine.' . $id));
         }
         return $delegatingEngine;
     });
     $serviceManager->setAlias('templating', 'templating.engine.delegating');
 }
Пример #20
0
 /**
  * {@inheritdoc}
  */
 public function __construct(TemplateNameParserInterface $parser = null, LoaderInterface $loader = null, array $helpers = [])
 {
     $parser = $parser ?: new TemplateNameParser();
     $loader = $loader ?: new FilesystemLoader([]);
     parent::__construct($parser, $loader, $helpers);
 }
 static function setup($app)
 {
     // Set debug setting
     $app['debug'] = $app['config']['debug'];
     // Setup logging
     $app->register(new \Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => $app['root_path'] . '/app/logs/AppName.log', 'monolog.level' => $app['debug'] ? \Monolog\Logger::DEBUG : \Monolog\Logger::NOTICE, 'monolog.name' => 'AppName'));
     // Setup sessions
     $app->register(new SessionServiceProvider());
     // Setup PHP Activerecord DB connection
     if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
         // Windows
         // I couldn't get an absolute path to work on windows. Using relative.
         $path = 'sqlite://windows(../app/db/db.sqlite)';
     } else {
         // Unix-like
         $path = 'sqlite://unix(' . $app['root_path'] . '/app/db/db.sqlite)';
     }
     $app['activerecord.cfg'] = \ActiveRecord\Config::instance();
     $app['activerecord.cfg']->set_connections(array('prod' => $path));
     \ActiveRecord\Config::initialize(function ($cfg) {
         $cfg->set_default_connection('prod');
     });
     // Setup symfony php template views
     $app['view'] = $app->share(function ($app) {
         $loader = new FilesystemLoader($app['root_path'] . '/app/template/%name%');
         $templating = new PhpEngine(new TemplateNameParser(), $loader);
         // Initialise the slots helper
         $templating->set(new SlotsHelper());
         return $templating;
     });
     // Setup basic app authentication
     $app->register(new \Silex\Provider\SecurityServiceProvider());
     $app->register(new \Silex\Provider\RememberMeServiceProvider());
     $app['security.firewalls'] = array('login' => array('pattern' => '^/login$', 'anonymous' => true), 'create_password' => array('pattern' => '^/create_password', 'users' => $app->share(function () use($app) {
         return new \AppName\Security\UserProvider();
     }), 'anonymous' => true), 'main' => array('form' => array('login_path' => '/login', 'check_path' => '/login_check'), 'logout' => array('logout_path' => '/logout'), 'pattern' => '^/', 'users' => $app->share(function () use($app) {
         return new \AppName\Security\UserProvider();
     }), 'remember_me' => array('key' => 'j34krjh23lk4jh23lktc3ktjh', 'name' => 'AppName', 'always_remember_me' => true)));
     // Conveinience function to get username
     $app['current_username'] = $app->share(function ($app) {
         $token = $app['security']->getToken();
         // Return username, if available
         if (null !== $token) {
             $user = $token->getUser();
             return $user->getUsername();
         } else {
             return 'anon';
         }
     });
     // Need to boot app here due to security bundle needing to be initialized before being used.
     //		$app->boot();
     // Setup custom logging processor. Sets username and IP for every log message
     //		$app['monolog']->pushProcessor(array(new \AppName\Monolog\LogProcessor($app['security']), 'logProcessor'));
     /**
      * Accept JSON Requests
      */
     $app->before(function (Request $request) {
         if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
             $data = json_decode($request->getContent(), true);
             $request->request->replace(is_array($data) ? $data : array());
         }
     });
     /**
      * Error handler. Return a JSON object with error info
      */
     // $app->error(function(\Exception $e) use ($app){
     // 	// Let this type of exception pass through, it will prompt for authentication.
     // 	if($e instanceof \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException)
     // 		return;
     // 	// Let 404 errors go through
     // 	if($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
     // 		return;
     // 	$return = array('message' => $e->getMessage());
     // 	$return['class'] = get_class($e);
     // 	if($app['debug']){
     // 		$return['trace'] = $e->getTrace();
     // 		$return['file'] = $e->getFile();
     // 		$return['line'] = $e->getLine();
     // 		$return['code'] = $e->getCode();
     // 	}
     // 	return $app->json($return, 500);
     // }, 0);
     // Debug controllers
     if ($app['debug']) {
         $app->get('/make_error/', function (Request $request) use($app) {
             throw new Exception('Test exception');
             return '';
         });
     }
     return $app;
 }
Пример #22
0
 /**
  * Constructor.
  *
  * @param ContainerInterface $container The DI container
  * @param LoaderInterface    $loader    A loader instance
  */
 public function __construct(ContainerInterface $container, LoaderInterface $loader)
 {
     $this->container = $container;
     parent::__construct($loader);
 }
Пример #23
0
 public function __construct(PhpEngine $engine, CsrfTokenManagerInterface $csrfTokenManager = null, array $defaultThemes = array())
 {
     $engine->addHelpers(array(new FormHelper(new FormRenderer(new TemplatingRendererEngine($engine, $defaultThemes), $csrfTokenManager))));
 }
Пример #24
0
$log->pushHandler(new StreamHandler('logs/dev.log'));
// add records to the log
$log->addWarning('Coucou');
$log->addError('3WA Powaaa!!!');
/**
 * Injection des dépendances
 */
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
$container->register('user', "Application\\Utility\\User")->addArgument('Julien')->addArgument('Boyer');
$objectuser = $container->get('user');
$objectuser2 = $container->get('user');
$objectuser3 = $container->get('user');
dump($objectuser);
dump($objectuser2);
dump($objectuser3);
/**
 * Templating
 */
use Symfony\Component\Templating\PhpEngine;
use Symfony\Component\Templating\TemplateNameParser;
use Symfony\Component\Templating\Loader\FilesystemLoader;
$loader = new FilesystemLoader(__DIR__ . '/views/%name%');
$templating = new PhpEngine(new TemplateNameParser(), $loader);
echo $templating->render('hello.php', array('firstname' => 'Ludo'));
/**
 * Twig
 */
$loader = new Twig_Loader_Filesystem(__DIR__ . '/views/');
$twig = new Twig_Environment($loader, array('cache' => __DIR__ . 'caches/', 'debug' => true));
echo $twig->render('index.html.twig', array('firstname' => 'Julien'));
 /**
  * Create a filter url for the field named $title
  * and identified by $key which consists of
  * alias and field. $options holds all link
  * parameters like "alt, class" and so on.
  *
  * $key example: "article.title"
  *
  * @param string $title
  * @param string $key
  * @param array $options
  * @param array $params
  * @param string $template
  * @return string
  */
 public function filter($pagination, array $fields, $options = array(), $params = array(), $template = null)
 {
     return $this->templating->render($template ?: $pagination->getFiltrationTemplate(), $this->processor->filter($pagination, $fields, $options, $params));
 }
Пример #26
0
 public function getIndex(HttpFoundation\Request $request)
 {
     return $this->view->render('mainPage', ['githubClientId' => $this->githubClientId]);
 }
Пример #27
0
$app->register(new LocaleServiceProvider());
$app->register(new FormServiceProvider());
$app->register(new CsrfServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new TwigServiceProvider(), array('twig.path' => __DIR__ . '/../web/templates', 'twig.class.path' => __DIR__ . '/../vendor/twig/lib'));
$app['templating.engines'] = function () {
    return array('twig', 'php');
};
$app['templating.loader'] = function () {
    return new FilesystemLoader(__DIR__ . '/../web/templates/%name%');
};
$app['templating.template_name_parser'] = function () {
    return new TemplateNameParser();
};
$app['templating.engine.php'] = function () use($app) {
    $engine = new PhpEngine($app['templating.template_name_parser'], $app['templating.loader']);
    $engine->set(new SlotsHelper());
    return $engine;
};
$app['templating.engine.twig'] = function () use($app) {
    return new TwigEngine($app['twig'], $app['templating.template_name_parser']);
};
$app['templating'] = function () use($app) {
    $engines = array();
    foreach ($app['templating.engines'] as $i => $engine) {
        if (is_string($engine)) {
            $engines[$i] = $app[sprintf('templating.engine.%s', $engine)];
        }
    }
    return new DelegatingEngine($engines);
};
Пример #28
0
 /**
  * {@inheritdoc}
  */
 protected function renderTemplate(array $context = array())
 {
     return $this->phpEngine->render('ckeditor_widget.html.php', $context);
 }
 protected function setTheme(FormView $view, array $themes)
 {
     $this->engine->get('form')->setTheme($view, $themes);
 }
Пример #30
0
 /**
  * Constructor.
  *
  * @param TemplateNameParserInterface $parser    A TemplateNameParserInterface instance
  * @param ContainerInterface          $container The DI container
  * @param LoaderInterface             $loader    A loader instance
  */
 public function __construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader)
 {
     $this->container = $container;
     parent::__construct($parser, $loader);
 }