Skip to content

Commit

Permalink
Improve code blocks describing proposed API changes to template resol…
Browse files Browse the repository at this point in the history
…vers

Co-authored-by: Frank Brückner <[email protected]>
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel and froschdesign authored Oct 17, 2023
1 parent 62223de commit b3bbe36
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions docs/book/v2/migration/preparing-for-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ In version 2, template resolvers, which all implement the method `ResolverInterf

Version 3 will solve these issues by guaranteeing a string return type from `ResolverInterface::resolve()` or throw a `\Laminas\View\Exception\ExceptionInterface`.

If you use template resolvers standalone, you can prepare for this change by wrapping existing code in a try/catch
#### Before

```php
// Before
Before version 3 the return type can `null`, `false` or `string`:

// Maybe null, false or string:
```php
return $this->resolver->resolve($name, $this->renderer);
```

// After
#### After

If the template resolvers is used as standalone, use a `try`-`catch` block to create a custom signal for a missing template in an application:

```
try {
return $this->resolver->resolve($name, $this->renderer);
} catch (\Laminas\View\Exception\ExceptionInterface $error) {
return null; // Or whatever else signals a missing template in your application
return null; // custom return type
}
```

Expand Down

0 comments on commit b3bbe36

Please sign in to comment.