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

Commit

Permalink
Merge pull request #22 from thexpand/view-helper-trait
Browse files Browse the repository at this point in the history
Add helper trait to provide type-hinting for zend-view
  • Loading branch information
michalbundyra committed Oct 19, 2019
2 parents 0d65e19 + a60436e commit 3108c26
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/book/flash-messenger-view-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,27 @@ data-dismiss="alert" aria-hidden="true">&times;</button><ul><li>',
],
],
```

## IDE auto-completion in templates

The `Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait` trait can be used to
provide auto-completion for modern IDEs. It defines the aliases of the view
helpers in a DocBlock as `@method` tags.

### Usage

In order to allow auto-completion in templates, `$this` variable should be
type-hinted via a DocBlock at the top of your template. It is recommended that
you always add the `Zend\View\Renderer\PhpRenderer` as the first type, so that
the IDE can auto-suggest the default view helpers from `zend-view`. Next, chain
the `HelperTrait` from `zend-i18n` with a pipe symbol (a.k.a. vertical bar) `|`:

```php
/**
* @var Zend\View\Renderer\PhpRenderer|Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait $this
*/
```

You may chain as many `HelperTrait` traits as you like, depending on view
helpers from which Zend Framework component you are using and would like to
provide auto-completion for.
31 changes: 31 additions & 0 deletions src/View/HelperTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @see https://github.com/zendframework/zend-mvc-plugin-flashmessenger for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-mvc-plugin-flashmessenger/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Mvc\Plugin\FlashMessenger\View;

use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger as PluginFlashMessenger;
use Zend\Mvc\Plugin\FlashMessenger\View\Helper\FlashMessenger;

/**
* Helper trait for auto-completion of code in modern IDEs.
*
* The trait provides convenience methods for view helpers,
* defined by the zend-mvc-plugin-flashmessenger component.
* It is designed to be used for type-hinting $this variable
* inside zend-view templates via doc blocks.
*
* The base class is PhpRenderer, followed by the helper trait from
* the zend-mvc-plugin-flashmessenger component. However, multiple helper traits
* from different Zend Framework components can be chained afterwards.
*
* @example @var \Zend\View\Renderer\PhpRenderer|\Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait $this
*
* @method FlashMessenger|PluginFlashMessenger flashMessenger(string|null $namespace = null)
*/
trait HelperTrait
{
}

0 comments on commit 3108c26

Please sign in to comment.