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

Commit 70ed80f

Browse files
committed
Merge pull request #102 from thexpand/view-helper-trait
Add helper trait to provide type-hinting for zend-view
2 parents b5713bc + fa2136b commit 70ed80f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

docs/book/view-helpers.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ displaying translated content.
77
See the [zend-view helpers documentation](https://docs.zendframework.com/zend-view/helpers/intro/)
88
for more information.
99

10+
> ### IDE auto-completion in templates
11+
>
12+
> The `Zend\I18n\View\HelperTrait` trait can be used to provide auto-completion
13+
> for modern IDEs. It defines the aliases of the view helpers in a DocBlock as
14+
> `@method` tags.
15+
>
16+
> #### Usage
17+
>
18+
> In order to allow auto-completion in templates, `$this` variable should be
19+
> type-hinted via a DocBlock at the top of your template. It is recommended that
20+
> you always add the `Zend\View\Renderer\PhpRenderer` as the first type, so that
21+
> the IDE can auto-suggest the default view helpers from `zend-view`. Next,
22+
> chain the `HelperTrait` from `zend-i18n` with a pipe symbol (a.k.a. vertical
23+
> bar) `|`:
24+
> ```php
25+
> /**
26+
> * @var Zend\View\Renderer\PhpRenderer|Zend\I18n\View\HelperTrait $this
27+
> */
28+
> ```
29+
>
30+
> You may chain as many `HelperTrait` traits as you like, depending on view
31+
> helpers from which Zend Framework component you are using and would like to
32+
> provide auto-completion for.
33+
1034
## CurrencyFormat Helper
1135
1236
The `CurrencyFormat` view helper can be used to simplify rendering of localized

src/View/HelperTrait.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-i18n 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-i18n/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace Zend\I18n\View;
9+
10+
use IntlDateFormatter;
11+
12+
// @codingStandardsIgnoreStart
13+
14+
/**
15+
* Helper trait for auto-completion of code in modern IDEs.
16+
*
17+
* The trait provides convenience methods for view helpers,
18+
* defined by the zend-i18n component. It is designed to be used
19+
* for type-hinting $this variable inside zend-view templates via doc blocks.
20+
*
21+
* The base class is PhpRenderer, followed by the helper trait from
22+
* the zend-i18n component. However, multiple helper traits from different
23+
* Zend Framework components can be chained afterwards.
24+
*
25+
* @example @var \Zend\View\Renderer\PhpRenderer|\Zend\I18n\View\HelperTrait $this
26+
*
27+
* @method string currencyFormat(float $number, string|null $currencyCode = null, bool|null $showDecimals = null, string|null $locale = null, string|null $pattern = null)
28+
* @method string dateFormat(\DateTime|int|array $date, int $dateType = IntlDateFormatter::NONE, int $timeType = IntlDateFormatter::NONE, string|null $locale = null, string|null $pattern = null)
29+
* @method string numberFormat(int|float $number, int|null $formatStyle = null, int|null $formatType = null, string|null $locale = null, int|null $decimals = null, array|null $textAttributes = null)
30+
* @method string plural(array|string $strings, int $number)
31+
* @method string translate(string $message, string|null $textDomain = null, string|null $locale = null)
32+
* @method string translatePlural(string $singular, string $plural, int $number, string|null $textDomain = null, string|null $locale = null)
33+
*/
34+
trait HelperTrait
35+
{
36+
}
37+
// @codingStandardsIgnoreEnd

0 commit comments

Comments
 (0)