Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Twig 3.8 #1588

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sweetrdf/easyrdf": "1.7.*",
"symfony/polyfill-php80": "1.*",
"symfony/polyfill-php81": "1.*",
"twig/twig": "^2.15.3",
"twig/twig": "3.8.*",
"willdurand/negotiation": "3.1.*",
"punic/punic": "3.5.1",
"ml/json-ld": "1.*",
Expand Down
26 changes: 13 additions & 13 deletions src/controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
}

// specify where to look for templates and cache
$loader = new Twig_Loader_Filesystem(__DIR__ . '/../view');
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../view');
// initialize Twig environment
$this->twig = new Twig_Environment($loader, array('cache' => $tmpDir,'auto_reload' => true));
$this->twig = new \Twig\Environment($loader, array('cache' => $tmpDir,'auto_reload' => true));
// used for setting the base href for the relative urls
$this->twig->addGlobal("BaseHref", $this->getBaseHref());
// setting the service name string from the config.ttl
Expand All @@ -58,10 +58,10 @@
$this->twig->addGlobal("PreferredProperties", array('skos:prefLabel', 'skos:narrower', 'skos:broader', 'skosmos:memberOf', 'skos:altLabel', 'skos:related'));

// register a Twig filter for generating URLs for vocabulary resources (concepts and groups)
$this->twig->addFilter(new Twig_SimpleFilter('link_url', array($this, 'linkUrlFilter')));
$this->twig->addFilter(new \Twig\TwigFilter('link_url', array($this, 'linkUrlFilter')));

// register a Twig filter for generating strings from language codes with CLDR
$langFilter = new Twig_SimpleFilter('lang_name', function ($langcode, $lang) {
$langFilter = new \Twig\TwigFilter('lang_name', function ($langcode, $lang) {
return Language::getName($langcode, $lang);
});
$this->twig->addFilter($langFilter);
Expand Down Expand Up @@ -144,7 +144,7 @@
{
$this->model->setLocale($request->getLang());
// load template
$template = $this->twig->loadTemplate('landing.twig');
$template = $this->twig->load('landing.twig');

Check warning on line 147 in src/controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

src/controller/WebController.php#L147

Added line #L147 was not covered by tests
// set template variables
$categoryLabel = $this->model->getClassificationLabel($request->getLang());
$sortedVocabs = $this->model->getVocabularyList(false, true);
Expand Down Expand Up @@ -189,7 +189,7 @@
$customLabels = $vocab->getConfig()->getPropertyLabelOverrides();

$pluginParameters = json_encode($vocab->getConfig()->getPluginParameters());
$template = $this->twig->loadTemplate('concept.twig');
$template = $this->twig->load('concept.twig');

$crumbs = $vocab->getBreadCrumbs($request->getContentLang(), $uri);
echo $template->render(
Expand All @@ -212,7 +212,7 @@
*/
public function invokeFeedbackForm($request)
{
$template = $this->twig->loadTemplate('feedback.twig');
$template = $this->twig->load('feedback.twig');

Check warning on line 215 in src/controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

src/controller/WebController.php#L215

Added line #L215 was not covered by tests
$this->model->setLocale($request->getLang());
$vocabList = $this->model->getVocabularyList(false);
$vocab = $request->getVocab();
Expand Down Expand Up @@ -300,7 +300,7 @@
mail($toAddress, $messageSubject, $message, $headers, $params);
} catch (Exception $e) {
header("HTTP/1.0 404 Not Found");
$template = $this->twig->loadTemplate('error.twig');
$template = $this->twig->load('error.twig');

Check warning on line 303 in src/controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

src/controller/WebController.php#L303

Added line #L303 was not covered by tests
if ($this->model->getConfig()->getLogCaughtExceptions()) {
error_log('Caught exception: ' . $e->getMessage());
}
Expand All @@ -320,7 +320,7 @@
*/
public function invokeAboutPage($request)
{
$template = $this->twig->loadTemplate('about.twig');
$template = $this->twig->load('about.twig');

Check warning on line 323 in src/controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

src/controller/WebController.php#L323

Added line #L323 was not covered by tests
$this->model->setLocale($request->getLang());
$url = $request->getServerConstant('HTTP_HOST');

Expand All @@ -339,7 +339,7 @@
public function invokeGlobalSearch($request)
{
$lang = $request->getLang();
$template = $this->twig->loadTemplate('global-search.twig');
$template = $this->twig->load('global-search.twig');

Check warning on line 342 in src/controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

src/controller/WebController.php#L342

Added line #L342 was not covered by tests
$this->model->setLocale($request->getLang());

$parameters = new ConceptSearchParameters($request, $this->model->getConfig());
Expand Down Expand Up @@ -408,7 +408,7 @@
*/
public function invokeVocabularySearch($request)
{
$template = $this->twig->loadTemplate('vocab-search.twig');
$template = $this->twig->load('vocab-search.twig');

Check warning on line 411 in src/controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

src/controller/WebController.php#L411

Added line #L411 was not covered by tests
$this->model->setLocale($request->getLang());
$vocab = $request->getVocab();
$searchResults = null;
Expand Down Expand Up @@ -495,7 +495,7 @@
}
$pluginParameters = json_encode($vocab->getConfig()->getPluginParameters());

$template = $this->twig->loadTemplate('vocab-home.twig');
$template = $this->twig->load('vocab-home.twig');

Check warning on line 498 in src/controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

src/controller/WebController.php#L498

Added line #L498 was not covered by tests

echo $template->render(
array(
Expand All @@ -516,7 +516,7 @@
{
$this->model->setLocale($request->getLang());
header("HTTP/1.0 404 Not Found");
$template = $this->twig->loadTemplate('error.twig');
$template = $this->twig->load('error.twig');

Check warning on line 519 in src/controller/WebController.php

View check run for this annotation

Codecov / codecov/patch

src/controller/WebController.php#L519

Added line #L519 was not covered by tests
echo $template->render(
array(
'languages' => $this->languages,
Expand Down
2 changes: 1 addition & 1 deletion tests/Http304Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function initObjects(string $vocabularyName)
$mockedTemplate = Mockery::mock();
$mockedTemplate->shouldReceive("render")->andReturn("rendered");
$this->twig->allows([
"loadTemplate" => $mockedTemplate
"load" => $mockedTemplate
]);
$this->controller->twig = $this->twig;
}
Expand Down
Loading