This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Add helper trait to provide type-hinting for zend-view #102
Merged
weierophinney
merged 12 commits into
zendframework:develop
from
thexpand:view-helper-trait
Nov 18, 2019
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1f1021b
Add helper trait to provide type-hinting for zend-view
thexpand 101aeee
Add ending doc block annotation for ignoring coding standards
thexpand 7f3a1fc
Add doc block with copyright and license information
thexpand e74a547
Change comment in doc-block's description to properly address Zend Fr…
thexpand 9c9c8f7
Add data types for all @method parameters in the helper trait
thexpand 013008b
Add a more descriptive title of the helper trait
thexpand f9b5d9c
Replace the year range with the current year in the copyright doc-block
thexpand f312207
Add documentation for HelperTrait for IDE auto-completion
thexpand ad3a270
Merge remote-tracking branch 'origin/view-helper-trait' into view-hel…
thexpand 3e04da1
Fix wrong type-hint
thexpand 7949014
Move the docs section for IDE auto-completion inside a block quote an…
thexpand fa2136b
Fix wrong namespace in docs for HelperTrait and re-align code example
thexpand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,29 @@ displaying translated content. | |
See the [zend-view helpers documentation](http://framework.zend.com/manual/current/en/modules/zend.view.helpers.html#zend-view-helpers) | ||
for more information. | ||
|
||
## IDE auto-completion in templates | ||
|
||
The `Zend\I18n\View\Helper\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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This headline gets the level of 4. |
||
|
||
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\I18n\View\Helper\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. | ||
|
||
## CurrencyFormat Helper | ||
|
||
The `CurrencyFormat` view helper can be used to simplify rendering of localized | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* @see https://github.com/zendframework/zend-i18n for the canonical source repository | ||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license https://github.com/zendframework/zend-i18n/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
thexpand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
namespace Zend\I18n\View; | ||
|
||
use IntlDateFormatter; | ||
|
||
// @codingStandardsIgnoreStart | ||
thexpand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Helper trait for auto-completion of code in modern IDEs. | ||
* | ||
* The trait provides convenience methods for view helpers, | ||
* defined by the zend-i18n 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-i18n component. However, multiple helper traits from different | ||
* Zend Framework components can be chained afterwards. | ||
* | ||
* @example @var \Zend\View\Renderer\PhpRenderer|\Zend\I18n\View\HelperTrait $this | ||
* | ||
* @method string currencyFormat(float $number, string|null $currencyCode = null, bool|null $showDecimals = null, string|null $locale = null, string|null $pattern = null) | ||
* @method string dateFormat(\DateTime|int|array $date, int $dateType = IntlDateFormatter::NONE, int $timeType = IntlDateFormatter::NONE, string|null $locale = null, string|null $pattern = null) | ||
* @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) | ||
* @method string plural(array|string $strings, int $number) | ||
* @method string translate(string $message, string|null $textDomain = null, string|null $locale = null) | ||
* @method string translatePlural(string $singular, string $plural, int $number, string|null $textDomain = null, string|null $locale = null) | ||
*/ | ||
trait HelperTrait | ||
{ | ||
} | ||
// @codingStandardsIgnoreEnd |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we should set the entire section as a blockquote.
The headline is then marked up with
###
.