本文整理汇总了PHP中Twig_Loader_Filesystem类的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Loader_Filesystem类的具体用法?PHP Twig_Loader_Filesystem怎么用?PHP Twig_Loader_Filesystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Twig_Loader_Filesystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetNamespaces
public function testGetNamespaces()
{
$loader = new Twig_Loader_Filesystem(sys_get_temp_dir());
$this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE), $loader->getNamespaces());
$loader->addPath(sys_get_temp_dir(), 'named');
$this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE, 'named'), $loader->getNamespaces());
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('<comment>Iniciando busca de templates</comment>');
/**
* @var $app \app\AppInit
*/
$app = $this->getHelper('init')->getInit();
$cache = $app->getCache();
$src = $app->getBaseDir() . "/src";
$loader = new \Twig_Loader_Filesystem($src);
$twig = new \Twig_Environment($loader, array('cache' => $cache['twig'], 'auto_reload' => true));
$config = $app->config();
$container = $app->container();
foreach ($config['modules'] as $ap) {
if (file_exists($container['Modules'] . $ap . '/Views')) {
$loader->addPath($container['Modules'] . $ap . '/Views', $ap);
}
if (file_exists($container['Modules'] . $ap . '/Templates')) {
$loader->addPath($container['Modules'] . $ap . '/Templates', $ap);
}
}
$twig->addExtension(new \Twig_Extensions_Extension_I18n());
$d = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($src), \RecursiveIteratorIterator::LEAVES_ONLY);
$Regex2 = new \RegexIterator($d, '/\\.html.twig$/i');
foreach ($Regex2 as $file) {
if ($file->isFile()) {
$twig->loadTemplate(str_replace($src . '/', '', $file));
}
}
#$output->writeln("<comment>Finalizando</comment>");
}
示例3: initExtension
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;
}
示例4: render
public function render($echo = false)
{
// Load template directories.
$loader = new \Twig_Loader_Filesystem();
$loader->addPath('templates');
// Set up Twig.
$twig = new \Twig_Environment($loader, array('debug' => true, 'strct_variables' => true));
$twig->addExtension(new \Twig_Extension_Debug());
// Mardown support.
$twig->addFilter(new \Twig_SimpleFilter('markdown', function ($text) {
$parsedown = new \Parsedown();
return $parsedown->text($text);
}));
// DB queries.
$twig->addFunction(new \Twig_SimpleFunction('db_queries', function () {
return Db::getQueries();
}));
// Render.
$string = $twig->render($this->template, $this->data);
if ($echo) {
echo $string;
} else {
return $string;
}
}
示例5: __construct
function __construct()
{
// This is how to call the template engine:
// do_action('wunderground_render_template', $file_name, $data_array );
add_action('wunderground_render_template', array(&$this, 'render'), 10, 2);
// Set up Twig
Twig_Autoloader::register();
// This path should always be the last
$base_path = trailingslashit(plugin_dir_path(Wunderground_Plugin::$file)) . 'templates';
$this->loader = new Twig_Loader_Filesystem($base_path);
// Tap in here to add additional template paths
$additional_paths = apply_filters('wunderground_template_paths', array(trailingslashit(get_stylesheet_directory()) . 'wunderground'));
foreach ($additional_paths as $path) {
// If the directory exists
if (is_dir($path)) {
// Tell Twig to use it first
$this->loader->prependPath($path);
}
}
// You can force debug mode by adding `add_filter( 'wunderground_twig_debug' '__return_true' );`
$debug = apply_filters('wunderground_twig_debug', current_user_can('manage_options') && isset($_GET['debug']));
$this->twig = new Twig_Environment($this->loader, array('debug' => !empty($debug), 'auto_reload' => true));
if (!empty($debug)) {
$this->twig->addExtension(new Twig_Extension_Debug());
}
}
示例6: register
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['twig.path'] = array($app['app.templates.path']);
$app['twig.templates'] = array();
$app['twig.loader'] = function () use($app) {
$loaders = [];
$twigLoaderFs = new \Twig_Loader_Filesystem($app['twig.path']);
foreach ($app['extensions'] as $info) {
if (!is_dir($templateViewDirectory = $info['pathName'] . '/' . self::EXTENSION_TEMPLATE_PATH)) {
throw new InvalidTemplateDirectoryException(sprintf('"%s" is not a directory', $templateViewDirectory));
}
$currentController = $app['request']->get('_controller');
if (strstr($currentController, '\\', true) === $info['name']) {
$twigLoaderFs->addPath($templateViewDirectory);
break;
}
}
$loaders[] = $twigLoaderFs;
$loaders[] = new \Twig_Loader_Array($app['twig.templates']);
return new \Twig_Loader_Chain($loaders);
};
$app['twig.environment'] = function () use($app) {
$isTemplateMustBeCached = $app['twig.cache_templates'];
$templateCacheDirectory = $app['twig.cache.directory'];
$options = [];
if ($isTemplateMustBeCached && $this->isTemplateCacheDirectoryValid($templateCacheDirectory)) {
$options = ['cache' => $templateCacheDirectory];
}
return new \Twig_Environment($app['twig.loader'], $options);
};
$app['twig'] = function () use($app) {
return $app['twig.environment'];
};
}
示例7: setUp
/**
* @throws \Twig_Error_Loader
*/
protected function setUp()
{
// Setup factory for tabs
$this->tabFactory = Forms::createFormFactory();
parent::setUp();
$rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig', 'fields.html.twig'));
if (interface_exists('Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface')) {
$csrfProviderInterface = 'Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface';
} else {
$csrfProviderInterface = 'Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface';
}
$renderer = new TwigRenderer($rendererEngine, $this->getMock($csrfProviderInterface));
$this->extension = new FormExtension($renderer);
$reflection = new \ReflectionClass($renderer);
$bridgeDirectory = dirname($reflection->getFileName()) . '/../Resources/views/Form';
$loader = new \Twig_Loader_Filesystem(array($bridgeDirectory, __DIR__ . '/../../Resources/views/Form'));
$loader->addPath(__DIR__ . '/../../Resources/views', 'MopaBootstrap');
$environment = new Twig_Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension(new IconExtension('fontawesome'));
$environment->addExtension(new FormExtension2());
$environment->addGlobal('global', '');
$environment->addExtension($this->extension);
$this->extension->initRuntime($environment);
}
示例8: createConfig
/**
* {@inheritDoc}
*/
public function createConfig(array $config = array())
{
$config = ArrayObject::ensureArrayObject($config);
$config->defaults($this->defaultConfig);
$config->defaults(array('payum.template.layout' => '@PayumCore/layout.html.twig', 'payum.http_client' => HttpClientFactory::create(), 'guzzle.client' => HttpClientFactory::createGuzzle(), 'twig.env' => function (ArrayObject $config) {
$loader = new \Twig_Loader_Filesystem();
foreach ($config['payum.paths'] as $namespace => $path) {
$loader->addPath($path, $namespace);
}
return new \Twig_Environment($loader);
}, 'payum.action.get_http_request' => new GetHttpRequestAction(), 'payum.action.capture_payment' => new CapturePaymentAction(), 'payum.action.execute_same_request_with_model_details' => new ExecuteSameRequestWithModelDetailsAction(), 'payum.action.render_template' => function (ArrayObject $config) {
return new RenderTemplateAction($config['twig.env'], $config['payum.template.layout']);
}, 'payum.extension.endless_cycle_detector' => new EndlessCycleDetectorExtension(), 'payum.action.get_currency' => function (ArrayObject $config) {
return new GetCurrencyAction($config['payum.iso4217']);
}, 'payum.prepend_actions' => array(), 'payum.prepend_extensions' => array(), 'payum.prepend_apis' => array(), 'payum.default_options' => array(), 'payum.required_options' => array(), 'payum.api.http_client' => function (ArrayObject $config) {
return $config['payum.http_client'];
}, 'payum.security.token_storage' => null));
if ($config['payum.security.token_storage']) {
$config['payum.action.get_token'] = function (ArrayObject $config) {
return new GetTokenAction($config['payum.security.token_storage']);
};
}
$config['payum.paths'] = array_replace(['PayumCore' => __DIR__ . '/Resources/views'], $config['payum.paths'] ?: []);
return (array) $config;
}
示例9: getTwig
protected function getTwig()
{
$options = ['cache' => false, 'strict_variables' => true];
$loader = new \Twig_Loader_Filesystem();
$loader->addPath($this->skeletonDirs);
return new \Twig_Environment($loader, $options);
}
示例10: testGetNamespaces
public function testGetNamespaces()
{
$loader = new Twig_Loader_Filesystem(sys_get_temp_dir());
$this->assertEquals(array('__main__'), $loader->getNamespaces());
$loader->addPath(sys_get_temp_dir(), 'named');
$this->assertEquals(array('__main__', 'named'), $loader->getNamespaces());
}
示例11: initRuntime
public function initRuntime(\Twig_Environment $environment)
{
$this->twigEnvironment = $environment;
$loader = new \Twig_Loader_Filesystem();
$loader->addPath(__DIR__ . '/../Resorces/views', 'np_navigation');
$environment->getLoader()->addLoader($loader);
}
示例12: getInstance
public static function getInstance()
{
if (self::$instance !== null) {
return self::$instance;
}
$loader = new \Twig_Loader_Filesystem();
$translator = Translator::getInstance();
$modules = \SimpleSAML_Module::getModules();
foreach ($modules as $module) {
if (\SimpleSAML_Module::isModuleEnabled($module)) {
$path = \SimpleSAML_Module::getModuleDir($module);
$templatePath = self::resourceExists('templates', $path);
if (false !== $templatePath) {
$loader->addPath($templatePath, $module);
}
$translationPath = self::resourceExists('translations', $path);
if (false !== $translationPath) {
$translations = new Finder();
$translations->files()->in($translationPath)->name('/\\.[a-zA-Z_]+\\.yml$/');
/** @var SplFileInfo $translation */
foreach ($translations as $translation) {
$name = $translation->getBasename('.yml');
$locale = substr($name, strrpos($name, '.') + 1);
$translator->addResource('yaml', $translation->getPathname(), $locale, $module);
}
}
}
}
self::$instance = new \Twig_Environment($loader);
self::$instance->addExtension(new TranslationExtension($translator));
return self::$instance;
}
示例13: __construct
/**
* Response constructor.
* @param $view
* @param array $param
*/
public function __construct($view, $param = [])
{
$loader = new \Twig_Loader_Filesystem(SRC_ROUTE . "/Views");
$loader->addPath(SRC_ROUTE . "/", "");
$this->_twig = new \Twig_Environment($loader, ["charset" => "utf-8", "debug" => true]);
echo $this->_twig->render($view, $param);
}
示例14: init
public function init()
{
$view_dir = [__DIR__ . '/../Views', __DIR__ . '/../Templates'];
$twigConfig = [];
if ($this->config['twig']['cache']) {
$twigConfig["cache"] = $this->app['cache']['twig'];
}
$twigConfig["debug"] = $this->config['twig']['debug'];
$loader = new \Twig_Loader_Filesystem($view_dir);
foreach ($view_dir as $d) {
$loader->addPath($d, 'Meister');
}
foreach ($this->config['modules'] as $app) {
if (file_exists($this->app['Modules'] . $app . '/Views')) {
$loader->addPath($this->app['Modules'] . $app . '/Views', $app);
}
if (file_exists($this->app['Modules'] . $app . '/Templates')) {
$loader->addPath($this->app['Modules'] . $app . '/Templates', $app);
}
}
$this->twig = new \Twig_Environment($loader, $twigConfig);
$this->twig->addExtension(new \Twig_Extensions_Extension_I18n());
/**
* Verifica permissões para exibir determinada coisa
*/
$function = new \Twig_SimpleFunction('permission', function ($rule) {
return $this->app['auth']->checkRules($rule);
});
$this->twig->addFunction($function);
}
示例15: __construct
/**
* TwigFilesystemProvider constructor.
* @param \Twig_Loader_Filesystem $loader
* @param string $root_path
* @param string $namespace
*/
public function __construct(\Twig_Loader_Filesystem $loader, $root_path, $namespace)
{
$this->loader = $loader;
$this->namespace = $namespace;
if (!in_array($namespace, $loader->getNamespaces())) {
$loader->addPath($root_path, $namespace);
}
}