Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklog committed Dec 3, 2023
1 parent d4abe09 commit 898ac91
Show file tree
Hide file tree
Showing 28 changed files with 160 additions and 5,416 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ jobs:

strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
php-versions: ['8.2', '8.3']

steps:
- uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Validate composer.json and composer.lock
run: composer validate

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.phpunit.cache/
composer.lock
composer.phar
vendor/
50 changes: 19 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,57 @@ Install instructions
--------------------------------

First you need to add `shapecode/twig-template-event-bundle` to `composer.json`:

``` json
```bash
composer require shapecode/twig-template-event-bundle
```
... or ...
```json
{
"require": {
"shapecode/twig-template-event-bundle": "~3.0"
}
}
```

Please note that `dev-master` points to the latest release. If you want to use the latest development version please use `dev-develop`. Of course you can also use an explicit version number, e.g., `1.0.*`.
If you dont use Symfony Flex you have to add `ShapecodeTwigTemplateEventBundle` to your `bundles.php`:

You have to add `ShapecodeTwigTemplateEventBundle` to your `AppKernel.php`:

``` php
```php
<?php
// app/AppKernel.php
//...
class AppKernel extends Kernel
{
//...
public function registerBundles()
{
$bundles = array(
...
new Shapecode\Bundle\TwigTemplateEventBundle\ShapecodeTwigTemplateEventBundle(),
);
//...
// config/bundles.php

return $bundles;
}
//...
}
return [
// ...
Shapecode\Bundle\TwigTemplateEventBundle\ShapecodeTwigTemplateEventBundle::class => ['all' => true],
];
```

Now you can set events in twig templates:

``` twig
```twig
{{ event('test') }}
```

And listen to them with an event listener:

```
// services.yml
```yaml
services:
# twig events
Shapecode\Bundle\TwigTemplateEventBundle\EventListener\TestTwigEventListener:
tags:
- { name: kernel.event_listener, event: shapecode.twig_template.event, method: onTemplateEvent }
Shapecode\Bundle\TwigTemplateEventBundle\EventListener\TestTwigEventListener: ~
```
``` php
```php
<?php

namespace Shapecode\Bundle\TwigTemplateEventBundle\EventListener;

use Shapecode\Bundle\TwigTemplateEventBundle\Event\Code\TwigEventString;
use Shapecode\Bundle\TwigTemplateEventBundle\Event\TwigTemplateEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener]
class TestTwigEventListener
{

public function onTemplateEvent(TwigTemplateEvent $event): void
public function __invoke(TwigTemplateEvent $event): void
{
if ($event->getEventName() == 'test') {
$event->addCode(new TwigEventString('hello {{ world }}', array(
Expand Down
Loading

0 comments on commit 898ac91

Please sign in to comment.