Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 3108c26

Browse files
committed
Merge pull request #22 from thexpand/view-helper-trait
Add helper trait to provide type-hinting for zend-view
2 parents 0d65e19 + a60436e commit 3108c26

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

docs/book/flash-messenger-view-helper.md

+24
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,27 @@ data-dismiss="alert" aria-hidden="true">&times;</button><ul><li>',
144144
],
145145
],
146146
```
147+
148+
## IDE auto-completion in templates
149+
150+
The `Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait` trait can be used to
151+
provide auto-completion for modern IDEs. It defines the aliases of the view
152+
helpers in a DocBlock as `@method` tags.
153+
154+
### Usage
155+
156+
In order to allow auto-completion in templates, `$this` variable should be
157+
type-hinted via a DocBlock at the top of your template. It is recommended that
158+
you always add the `Zend\View\Renderer\PhpRenderer` as the first type, so that
159+
the IDE can auto-suggest the default view helpers from `zend-view`. Next, chain
160+
the `HelperTrait` from `zend-i18n` with a pipe symbol (a.k.a. vertical bar) `|`:
161+
162+
```php
163+
/**
164+
* @var Zend\View\Renderer\PhpRenderer|Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait $this
165+
*/
166+
```
167+
168+
You may chain as many `HelperTrait` traits as you like, depending on view
169+
helpers from which Zend Framework component you are using and would like to
170+
provide auto-completion for.

src/View/HelperTrait.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-mvc-plugin-flashmessenger for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license https://github.com/zendframework/zend-mvc-plugin-flashmessenger/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace Zend\Mvc\Plugin\FlashMessenger\View;
9+
10+
use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger as PluginFlashMessenger;
11+
use Zend\Mvc\Plugin\FlashMessenger\View\Helper\FlashMessenger;
12+
13+
/**
14+
* Helper trait for auto-completion of code in modern IDEs.
15+
*
16+
* The trait provides convenience methods for view helpers,
17+
* defined by the zend-mvc-plugin-flashmessenger component.
18+
* It is designed to be used for type-hinting $this variable
19+
* inside zend-view templates via doc blocks.
20+
*
21+
* The base class is PhpRenderer, followed by the helper trait from
22+
* the zend-mvc-plugin-flashmessenger component. However, multiple helper traits
23+
* from different Zend Framework components can be chained afterwards.
24+
*
25+
* @example @var \Zend\View\Renderer\PhpRenderer|\Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait $this
26+
*
27+
* @method FlashMessenger|PluginFlashMessenger flashMessenger(string|null $namespace = null)
28+
*/
29+
trait HelperTrait
30+
{
31+
}

0 commit comments

Comments
 (0)