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

Commit f13b7b3

Browse files
committed
Merge branch 'hotfix/59' into develop
Forward port #59
2 parents dc68c0f + bcec0bd commit f13b7b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3018
-2702
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
.*.sw*
77
.*.un~
88
nbproject
9+
doc/html/
910
tmp/
11+
vendor/
12+
zf-mkdoc-theme/
1013

1114
clover.xml
1215
coveralls-upload.json
1316
phpunit.xml
14-
vendor

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ branches:
1010
cache:
1111
directories:
1212
- $HOME/.composer/cache
13+
- $HOME/.local
14+
- zf-mkdoc-theme
1315

1416
env:
1517
global:
1618
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"
19+
- SITE_URL: https://zendframework.github.io/zend-view
20+
- GH_USER_NAME: "Matthew Weier O'Phinney"
21+
- GH_USER_EMAIL: [email protected]
22+
- GH_REF: github.com/zendframework/zend-view.git
23+
- secure: "kF7z5CxnrD/lsX9sP1+SYLKm1HdT/u1F0xovlyT9fDWrz+X4DBe8Oybzk6UX5HKXQvdhVTfAbHoWhFxFrkcRKrtaEOltk68bYFgnSOYhrK5EhZz6CHqN2j1MtT6FRfdlSOi6OECvCE3wd8nYHixxEviIZyB3L5+H39FOiu5Zi+eJT/myp6IuBO6lQfnSgqKdvuQXlfWSn9VGQJztX6ea2U89eM/TAVWEwbhLAJOsOejkvAy2lvYhIZpvSEkFm9jSp3/JOw8MFljG8UEDZUkpj+zba5/vqzM8thTTbybhAIBF7wNeMNrAeFBnrPz5KDPEQYYG8NG4we6F7GvbevvBz+ej5OJPXx/ulhMiEWKN1qEmQHZ3Gl0kG0O+TgXfqLErbCNn4MLP/K0Avar03m9bvXtaTA5Yqde0rIdspjwdxmKi0OI76UnGETMDyWuXbHkRfhs54sUEOBUdM3dz5lXhlSWPCTlQCgzkVqlgTL5b8b1u7YKpkwJAFSXMhhJBycFCNCfqAy10l2wjgvhXhLgPHle7sSwYR6SMVzkjj59P1UKc2yrxkwl/S7cqrbaeGSGjDv/QVMLtBL3OLqXwIaKy3POF2gQJhFXdrmGzDOADyCbEXVUYve5pQOmT1RdVHaHiT7AmZXEQibR1DW2zzU9eX94XpK9LKzlSzUOtYT8LNNA="
1724

1825
matrix:
1926
fast_finish: true
@@ -35,6 +42,8 @@ matrix:
3542
env:
3643
- EXECUTE_TEST_COVERALLS=true
3744
- DEPS=locked
45+
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
46+
- PATH="$HOME/.local/bin:$PATH"
3847
- php: 5.6
3948
env:
4049
- DEPS=lastest
@@ -78,6 +87,10 @@ script:
7887
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
7988
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
8089
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
90+
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi
91+
92+
after_success:
93+
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi
8194

8295
after_script:
8396
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ All notable changes to this project will be documented in this file, in reverse
2020

2121
- Nothing.
2222

23-
## 2.6.8 - TBD
23+
## 2.6.8 - 2016-05-12
2424

2525
### Added
2626

2727
- [#22](https://github.com/zendframework/zend-view/pull/22) adds support for the
2828
`async` attribute within the `headScript` helper.
29+
- [#59](https://github.com/zendframework/zend-view/pull/59) adds and publishes
30+
the documentation to https://zendframework.github.io/zend-view/
2931

3032
### Deprecated
3133

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
[![Build Status](https://secure.travis-ci.org/zendframework/zend-view.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-view)
44
[![Coverage Status](https://coveralls.io/repos/zendframework/zend-view/badge.svg?branch=master)](https://coveralls.io/r/zendframework/zend-view?branch=master)
55

6-
`Zend\View` provides the “View” layer of Zend Framework 2’s MVC system. It is a
6+
zend-view provides the “View” layer of the Zend Framework MVC system. It is a
77
multi-tiered system allowing a variety of mechanisms for extension,
88
substitution, and more.
99

10-
1110
- File issues at https://github.com/zendframework/zend-view/issues
12-
- Documentation is at http://framework.zend.com/manual/current/en/index.html#zend-view
11+
- Documentation is at https://zendframework.github.io/zend-view/

doc/book/helpers/advanced-usage.md

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
# Advanced usage of helpers
2+
3+
## Registering Helpers
4+
5+
`Zend\View\Renderer\PhpRenderer` composes a *plugin manager* for managing
6+
helpers, specifically an instance of `Zend\View\HelperPluginManager`, which
7+
extends `Zend\ServiceManager\AbstractPluginManager`, which is itself an
8+
extension of `Zend\ServiceManager\ServiceManager`. `HelperPluginManager` is a
9+
specialized service manager, so you can register a helper/plugin like any other
10+
service (see the [Service Manager documentation](http://zendframework.github.io/zend-servicemanager/configuring-the-service-manager/)
11+
for more information).
12+
13+
Programmatically, this is done as follows:
14+
15+
```php
16+
use MyModule\View\Helper\LowerCase;
17+
18+
// $view is an instance of PhpRenderer
19+
$pluginManager = $view->getHelperPluginManager();
20+
21+
// Register an alias:
22+
$pluginManager->setAlias('lowercase', LowerCase::class);
23+
24+
// Register a factory:
25+
$pluginManager->setFactory(LowerCase::class, function () {
26+
$lowercaseHelper = new LowerCase();
27+
28+
// ...do some configuration or dependency injection...
29+
30+
return $lowercaseHelper;
31+
});
32+
```
33+
34+
Within an MVC application, you will typically pass a map of plugins to the class
35+
via your configuration.
36+
37+
```php
38+
use MyModule\View\Helper;
39+
use Zend\ServiceManager\Factory\InvokableFactory;
40+
41+
// From within a configuration file
42+
return [
43+
'view_helpers' => [
44+
'aliases' => [
45+
'lowercase' => Helper\LowerCase::class,
46+
'uppercase' => Helper\UpperCase::class,
47+
],
48+
'factories' => [
49+
LowerCase::class => InvokableFactory::class,
50+
UpperCase::class => InvokableFactory::class,
51+
],
52+
],
53+
];
54+
```
55+
56+
If your module class implements `Zend\ModuleManager\Feature\ViewHelperProviderInterface`,
57+
or just the method `getViewHelperConfig()`, you could also do the following
58+
(it's the same as the previous example).
59+
60+
```php
61+
namespace MyModule;
62+
63+
class Module
64+
{
65+
public function getViewHelperConfig()
66+
{
67+
return [
68+
'aliases' => [
69+
'lowercase' => Helper\LowerCase::class,
70+
'uppercase' => Helper\UpperCase::class,
71+
],
72+
'factories' => [
73+
LowerCase::class => InvokableFactory::class,
74+
UpperCase::class => InvokableFactory::class,
75+
],
76+
];
77+
}
78+
}
79+
```
80+
81+
The two latter examples can be done in each module that needs to register
82+
helpers with the `PhpRenderer`; however, be aware that another module can
83+
register helpers with the same name, so order of modules can impact which helper
84+
class will actually be registered!
85+
86+
## Writing Custom Helpers
87+
88+
Writing custom helpers is easy. We recommend extending
89+
`Zend\View\Helper\AbstractHelper`, but at the minimum, you need only implement
90+
the `Zend\View\Helper\HelperInterface` interface:
91+
92+
```php
93+
namespace Zend\View\Helper;
94+
95+
use Zend\View\Renderer\RendererInterface as Renderer;
96+
97+
interface HelperInterface
98+
{
99+
/**
100+
* Set the View object
101+
*
102+
* @param Renderer $view
103+
* @return HelperInterface
104+
*/
105+
public function setView(Renderer $view);
106+
107+
/**
108+
* Get the View object
109+
*
110+
* @return Renderer
111+
*/
112+
public function getView();
113+
}
114+
```
115+
116+
If you want your helper to be capable of being invoked as if it were a method call of the
117+
`PhpRenderer`, you should also implement an `__invoke()` method within your helper.
118+
119+
As previously noted, we recommend extending `Zend\View\Helper\AbstractHelper`, as it implements the
120+
methods defined in `HelperInterface`, giving you a headstart in your development.
121+
122+
> ### Invokable helpers
123+
>
124+
> Starting with version 2.7.0, helpers no longer need to be instances of
125+
> `HelperInterface`, but can be *any* PHP callable. We recommend writing helpers
126+
> as invokable classes (classes implementing `__invoke()`.
127+
128+
Once you have defined your helper class, make sure you can autoload it, and then
129+
register it with the [plugin manager](#registering-helpers).
130+
131+
Here is an example helper, which we're titling "SpecialPurpose"
132+
133+
```php
134+
namespace MyModule\View\Helper;
135+
136+
use Zend\View\Helper\AbstractHelper;
137+
138+
class SpecialPurpose extends AbstractHelper
139+
{
140+
protected $count = 0;
141+
142+
public function __invoke()
143+
{
144+
$this->count++;
145+
$output = sprintf("I have seen 'The Jerk' %d time(s).", $this->count);
146+
return htmlspecialchars($output, ENT_QUOTES, 'UTF-8');
147+
}
148+
}
149+
```
150+
151+
Then assume that we [register it with the plugin manager](#registering-helpers)
152+
by the name "specialpurpose".
153+
154+
Within a view script, you can call the `SpecialPurpose` helper as many times as
155+
you like; it will be instantiated once, and then it persists for the life of
156+
that `PhpRenderer` instance.
157+
158+
```php
159+
// remember, in a view script, $this refers to the Zend\View\Renderer\PhpRenderer instance.
160+
echo $this->specialPurpose();
161+
echo $this->specialPurpose();
162+
echo $this->specialPurpose();
163+
```
164+
165+
The output would look something like this:
166+
167+
```php
168+
I have seen 'The Jerk' 1 time(s).
169+
I have seen 'The Jerk' 2 time(s).
170+
I have seen 'The Jerk' 3 time(s).
171+
```
172+
173+
Sometimes you will need access to the calling `PhpRenderer` object; for
174+
instance, if you need to use the registered encoding, or want to render another
175+
view script as part of your helper. This is why we define the `setView()` and
176+
`getView()` methods. As an example, we could rewrite the `SpecialPurpose` helper
177+
as follows to take advantage of the `EscapeHtml` helper:
178+
179+
```php
180+
namespace MyModule\View\Helper;
181+
182+
use Zend\View\Helper\AbstractHelper;
183+
184+
class SpecialPurpose extends AbstractHelper
185+
{
186+
protected $count = 0;
187+
188+
public function __invoke()
189+
{
190+
$this->count++;
191+
$output = sprintf("I have seen 'The Jerk' %d time(s).", $this->count);
192+
$escaper = $this->getView()->plugin('escapehtml');
193+
return $escaper($output);
194+
}
195+
}
196+
```
197+
198+
> ### Accessing the view or other helpers in callables
199+
>
200+
> As noted earlier, starting in version 2.7.0, you may use any PHP callable as a
201+
> helper. If you do, however, how can you access the renderer or other plugins?
202+
>
203+
> The answer is: dependency injection.
204+
>
205+
> If you write your helper as a class, you can accept dependencies via the
206+
> constructor or other setter methods. Create a factory that pulls those
207+
> dependencies and injects them.
208+
>
209+
> As an example, if we need the `escapeHtml()` helper, we could write our helper
210+
> as follows:
211+
>
212+
> ```php
213+
> namespace MyModule\View\Helper;
214+
>
215+
> use Zend\View\Helper\EscapeHtml;
216+
>
217+
> class SpecialPurpose
218+
> {
219+
> private $count = 0;
220+
>
221+
> private $escaper;
222+
>
223+
> public function __construct(EscapeHtml $escaper)
224+
> {
225+
> $this->escaper = $escaper;
226+
> }
227+
>
228+
> public function __invoke()
229+
> {
230+
> $this->count++;
231+
> $output = sprintf("I have seen 'The Jerk' %d time(s).", $this->count);
232+
> $escaper = $this->escaper;
233+
> return $escaper($output);
234+
> }
235+
> }
236+
> ```
237+
>
238+
> Then we would write a factory like the following:
239+
>
240+
> ```php
241+
> use Zend\ServiceManager\AbstractPluginManager;
242+
>
243+
> class SpecialPurposeFactory
244+
> {
245+
> public function __invoke($container)
246+
> {
247+
> if (! $container instanceof AbstractPluginManager) {
248+
> // zend-servicemanager v3. v2 passes the helper manager directly.
249+
> $container = $container->get('ViewHelperManager');
250+
> }
251+
>
252+
> return new SpecialPurpose($container->get('escapeHtml'));
253+
> }
254+
> }
255+
> ```
256+
>
257+
> If access to the view were required, we'd pass the `PhpRenderer` service
258+
> instead.
259+
260+
## Registering Concrete Helpers
261+
262+
Sometimes it is convenient to instantiate a view helper, and then register it
263+
with the renderer. This can be done by injecting it directly into the plugin
264+
manager.
265+
266+
```php
267+
// $view is a PhpRenderer instance
268+
269+
$helper = new MyModule\View\Helper\LowerCase;
270+
// ...do some configuration or dependency injection...
271+
272+
$view->getHelperPluginManager()->setService('lowercase', $helper);
273+
```
274+
275+
The plugin manager will validate the helper/plugin, and if the validation
276+
passes, the helper/plugin will be registered.

doc/book/helpers/base-path.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# BasePath
2+
3+
While most URLs generated by the framework have the base URL prepended
4+
automatically, developers will need to prepend the base URL to their own URLs
5+
(usually inside an `href` attribute) in order for paths to resources to be
6+
correct.
7+
8+
If you're running a zend-mvc application, `basePath()` will point to the
9+
`public` folder of the application's root.
10+
11+
## Basic Usage
12+
13+
```php
14+
/*
15+
* The following assume that the base URL of the page/application is "/mypage".
16+
*/
17+
18+
/*
19+
* Prints:
20+
* <base href="/mypage/" />
21+
*/
22+
<base href="<?= $this->basePath() ?>" />
23+
24+
/*
25+
* Prints:
26+
* <link rel="stylesheet" type="text/css" href="/mypage/css/base.css" />
27+
*/
28+
<link rel="stylesheet" type="text/css"
29+
href="<?= $this->basePath('css/base.css') ?>" />
30+
```
31+
32+
> ### index.php script
33+
>
34+
> For simplicity's sake, we strip out the entry PHP file (e.g., `index.php`)
35+
> from the base URL. However, in some situations this may cause a problem. If
36+
> one occurs, use `$this->plugin('basePath')->setBasePath()` to manually set the
37+
> base path.

0 commit comments

Comments
 (0)