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

Commit

Permalink
Merge branch 'feature/22' into develop
Browse files Browse the repository at this point in the history
Close #22
  • Loading branch information
michalbundyra committed Oct 19, 2019
2 parents 0d65e19 + 83b3930 commit 18ef7e3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file, in reverse

- [#24](https://github.com/zendframework/zend-mvc-plugin-flashmessenger/pull/24) adds support for PHP 7.3.

- [#22](https://github.com/zendframework/zend-mvc-plugin-flashmessenger/pull/22) adds `Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait`,
which can be used to provide IDE autocompletion for view helpers
provided by zend-mvc-plugin-flashmessenger. See
https://docs.zendframework.com/zend-mvc-plugin-flashmessenger/flash-messenger-view-helper/#ide-auto-completion-in-templates
for more information.

### Changed

- Nothing.
Expand Down
24 changes: 24 additions & 0 deletions docs/book/flash-messenger-view-helper.md
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
@@ -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 18ef7e3

Please sign in to comment.