-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac5c214
commit 6ab7994
Showing
10 changed files
with
214 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title> | ||
{% block title %} | ||
Welcome! | ||
{% endblock %} | ||
</title> | ||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>"> | ||
</head> | ||
<body> | ||
{% block content %} | ||
<h1>{{ title }}</h1> | ||
{% endblock %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor/ | ||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Schranz\Templating\Integration\Spiral\Twig\Bootloader; | ||
|
||
use Schranz\Templating\Adapter\Twig\TwigRenderer; | ||
use Schranz\Templating\TemplateRenderer\TemplateRendererInterface; | ||
use Spiral\Core\Container; | ||
use Spiral\Boot\Bootloader\Bootloader; | ||
use Spiral\Twig\TwigEngine; | ||
use Spiral\Views\ViewContext; | ||
use Spiral\Views\ViewManager; | ||
use Twig\Environment; | ||
|
||
class TwigBootloader extends Bootloader | ||
{ | ||
public function boot(Container $container): void | ||
{ | ||
$container->bindSingleton('twig', function (Container $container) { | ||
// Use a hack to get Twig from the ViewManager as it is not available as an service yet | ||
$viewManager = $container->get(ViewManager::class); | ||
|
||
$engines = $viewManager->getEngines(); | ||
|
||
$twigEngine = null; | ||
foreach ($engines as $engine) { | ||
if ($engine instanceof TwigEngine) { | ||
$twigEngine = $engine; | ||
break; | ||
} | ||
} | ||
|
||
if (null === $twigEngine) { | ||
throw new \LogicException( | ||
\sprintf('Expected "%s" to be registered in the view manager.', TwigEngine::class) | ||
); | ||
} | ||
|
||
return $twigEngine->getEnvironment(new ViewContext()); | ||
}); | ||
|
||
$container->bind(Environment::class, 'twig'); | ||
|
||
$container->bindSingleton('schranz_templating.renderer.twig', function (Container $container) { | ||
return new TwigRenderer($container->get('twig')); | ||
}); | ||
|
||
$container->bind(TemplateRendererInterface::class, 'schranz_templating.renderer.twig'); | ||
$container->bind(TwigRenderer::class, 'schranz_templating.renderer.twig'); | ||
|
||
$container->bindSingleton('schranz_templating.renderer.twig', function (Container $container) { | ||
return new TwigRenderer($container->get('twig')); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Alexander Schranz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Schranz Template Renderer Integration for Twig | ||
|
||
Integrate the templating [Twig Adapter](https://github.com/schranz-templating/twig-adapter) | ||
into the Spiral Framework. | ||
|
||
Part of the [Schranz Templating Project](https://github.com/schranz-templating/templating). | ||
|
||
## Installation | ||
|
||
Install this package via Composer: | ||
|
||
```bash | ||
composer require schranz-templating/spiral-twig-integration | ||
``` | ||
|
||
Register the Bootloader class in your `app/src/Application/Kernel.php` if not already automatically | ||
added by the framework: | ||
|
||
```php | ||
class Kernel extends \Spiral\Framework\Kernel | ||
{ | ||
protected const LOAD = [ | ||
// ... | ||
\Spiral\Twig\Bootloader\TwigBootloader::class, | ||
\Schranz\Templating\Integration\Spiral\Twig\Bootloader\TwigBootloader::class, | ||
]; | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
The Twig Integration has currently no configuration as Twig | ||
is supported out of the box by Spiral and can be configured | ||
via the [Spiral Twig Views](https://spiral.dev/docs/views-twig). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "schranz-templating/spiral-twig-integration", | ||
"description": "A integration of template renderer into spiral via twig template engine.", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Schranz\\Templating\\Integration\\Spiral\\Twig\\": "" | ||
} | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "path", | ||
"url": "./../../../TemplateRenderer", | ||
"options": { | ||
"symlink": true | ||
} | ||
}, | ||
{ | ||
"type": "path", | ||
"url": "./../../../Adapter/Twig", | ||
"options": { | ||
"symlink": true | ||
} | ||
} | ||
], | ||
"require": { | ||
"php": "^7.2 || ^8.0", | ||
"schranz-templating/twig-adapter": "^0.1", | ||
"spiral/twig-bridge": "^1.0 || ^2.0", | ||
"psr/container": "^1.0 || ^2.0" | ||
}, | ||
"minimum-stability": "dev", | ||
"config": { | ||
"allow-plugins": { | ||
"spiral/composer-publish-plugin": true | ||
} | ||
} | ||
} |