Skip to content
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
1 change: 0 additions & 1 deletion box.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"directories-bin": [
"config",
"home",
"vendor/twig/twig/lib",
"vendor/twig/twig/src"
],
"files-bin": [
Expand Down
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"symfony/expression-language": "^6.1",
"symfony/finder": "^6.1",
"symfony/yaml": "^6.1",
"twig/twig": "^2.16.1",
"twig/twig": "^3.22",
"composer/semver": "^3.4"
},
"require-dev": {
Expand Down Expand Up @@ -59,9 +59,6 @@
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
},
"audit": {
"block-insecure": false
}
}
}
115 changes: 19 additions & 96 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/Twig/EnvironmentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use my127\Workspace\Path\Path;
use my127\Workspace\Twig\Loader\Filesystem;
use Twig\Environment;
use Twig\TwigFunction;

class EnvironmentBuilder
{
/** @var Path */
private $path;

/** @var \Twig_Function[] */
/** @var TwigFunction[] */
private $functions = [];

/** @var mixed[] */
Expand All @@ -23,20 +25,20 @@ public function __construct(Path $path)

public function addFunction(string $name, callable $function): void
{
$this->functions[$name] = new \Twig_Function($name, $function);
$this->functions[$name] = new TwigFunction($name, $function);
}

public function addGlobal(string $name, $value)
{
$this->globals[$name] = $value;
}

public function create(string $path): \Twig_Environment
public function create(string $path): Environment
{
$directory = $this->path->getRealPath($path);

$loader = new Filesystem([$directory], $directory);
$environment = new \Twig_Environment($loader, [
$environment = new Environment($loader, [
'autoescape' => false,
]);

Expand Down
9 changes: 6 additions & 3 deletions src/Twig/Loader/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace my127\Workspace\Twig\Loader;

class Filesystem extends \Twig_Loader_Filesystem
use Twig\Loader\FilesystemLoader;
use Twig\Source;

class Filesystem extends FilesystemLoader
{
private $path;

Expand All @@ -13,15 +16,15 @@ public function __construct($paths = [], ?string $rootPath = null)
$this->path = $rootPath;
}

public function getSourceContext($name)
public function getSourceContext($name): Source
{
$path = $this->findTemplate($name);
$content = file_get_contents($path);

$content = str_replace("@('", "attr('", $content);
$content = str_replace('@("', 'attr("', $content);

return new \Twig_Source($content, $name, $path);
return new Source($content, $name, $path);
}

public function getRootPath(): string
Expand Down
5 changes: 3 additions & 2 deletions src/Types/Confd/Confd.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use my127\Workspace\Expression\Expression;
use my127\Workspace\Path\Path;
use my127\Workspace\Twig\Loader\Filesystem;
use Twig\Environment;

class Confd
{
Expand All @@ -14,7 +15,7 @@ class Confd
private $definition;

/**
* @var \Twig_Environment
* @var Environment
*/
private $twig;

Expand All @@ -33,7 +34,7 @@ class Confd
*/
private $rootPath;

public function __construct(Path $path, Definition $definition, \Twig_Environment $twig, Expression $expression)
public function __construct(Path $path, Definition $definition, Environment $twig, Expression $expression)
{
$this->definition = $definition;
$this->twig = $twig;
Expand Down
Loading