From ea2399347508c36269c2691076c511ea97108da7 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 5 Aug 2019 23:33:22 +0200 Subject: [PATCH 01/39] Fixes #100 - Missing documentation for Zend\View\Helper\HtmlTag --- doc/book/helpers/html-tag.md | 98 ++++++++++++++++++++++++++++++++++++ doc/book/helpers/intro.md | 1 + mkdocs.yml | 1 + 3 files changed, 100 insertions(+) create mode 100644 doc/book/helpers/html-tag.md diff --git a/doc/book/helpers/html-tag.md b/doc/book/helpers/html-tag.md new file mode 100644 index 00000000..be9d0029 --- /dev/null +++ b/doc/book/helpers/html-tag.md @@ -0,0 +1,98 @@ +# HtmlTag + +The `HtmlTag` helper is used to **create the root of a HTML document**, the open +and close tags for the `` element. + +## Basic Usage + +```php +htmlTag(['lang' => 'en'])->openTag() ?> + +htmlTag()->closeTag() ?> +``` + +Output: + +```html + + + +``` + +## Using Attributes + +### Set a single Attribute + +```php fct_label="Invoke Usage" +$this->htmlTag(['lang' => 'en']); + +echo $this->htmlTag()->openTag(); // +``` + +```php fct_label="Setter Usage" +$this->htmlTag()->setAttribute('lang', 'en'); + +echo $this->htmlTag()->openTag(); // +``` + +### Set multiple Attributes + +```php fct_label="Invoke Usage" +$this->htmlTag(['lang' => 'en', 'id' => 'example']); + +echo $this->htmlTag()->openTag(); // +``` + +```php fct_label="Setter Usage" +$this->htmlTag()->setAttributes(['lang' => 'en', 'id' => 'example']); + +echo $this->htmlTag()->openTag(); // +``` + +### Get current Value + +To get the current value, use the `getAttributes()` method. + +```php +$this->htmlTag(['lang' => 'en', 'id' => 'example']); + +var_dump($this->htmlTag()->getAttributes()); // ['lang' => 'en', 'id' => 'example'] +``` + +### Default Value + +The default value is an empty `array` that means no attributes are set. + +## Using Namespace + +The `HtmlTag` helper can automatically add the [XHTML namespace](http://www.w3.org/1999/xhtml/) +for XHTML documents. To use this functionality, the [`Doctype` helper](doctype.md) +is used. + +The namespace is added only if the document type is set to an XHTML type and use +is enabled: + +```php +// Set doctype to XHTML +$this->doctype(Zend\View\Helper\Doctype::XHTML1_STRICT); + +// Add namespace to open tag +$this->htmlTag()->setUseNamespaces(true); + +// Output +echo $this->htmlTag()->openTag(); // +``` + +### Get current Value + +To get the current value, use the `getUseNamespaces()` method. + +```php +$this->htmlTag()->setUseNamespaces(true); + +var_dump($this->htmlTag()->getUseNamespaces()); // true +``` + +### Default Value + +The default value is `false` that means no namespace is added as attribute. diff --git a/doc/book/helpers/intro.md b/doc/book/helpers/intro.md index 8b476d6a..bfa6d8bd 100644 --- a/doc/book/helpers/intro.md +++ b/doc/book/helpers/intro.md @@ -68,6 +68,7 @@ for, and rendering, the various HTML `` tags, such as `HeadTitle`, - [HeadTitle](head-title.md) - [HtmlList](html-list.md) - [HTML Object Plugins](html-object.md) +- [HtmlTag](html-tag.md) - [Identity](identity.md) - [InlineScript](inline-script.md) - [JSON](json.md) diff --git a/mkdocs.yml b/mkdocs.yml index fd188f24..af084a3d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -22,6 +22,7 @@ pages: - HeadTitle: helpers/head-title.md - HtmlList: helpers/html-list.md - HtmlObject: helpers/html-object.md + - HtmlTag: helpers/html-tag.md - Identity: helpers/identity.md - InlineScript: helpers/inline-script.md - Json: helpers/json.md From c24364581528ed6c4b8a3d6811b31043d717f70c Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 5 Aug 2019 23:44:29 +0200 Subject: [PATCH 02/39] Fixes page names in MkDocs configuration file --- mkdocs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index fd188f24..e96d97dd 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,14 +1,14 @@ docs_dir: doc/book site_dir: doc/html pages: - - index.md + - Home: index.md - "Quick Start": quick-start.md - "Rendering Views": - "The PhpRenderer": php-renderer.md - "View Scripts": view-scripts.md - "The ViewEvent": view-event.md - Helpers: - - Intro: helpers/intro.md + - Introduction: helpers/intro.md - Asset: helpers/asset.md - BasePath: helpers/base-path.md - Cycle: helpers/cycle.md From d7c684f55317e4369b1ea00186632ece9160f7d1 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 5 Aug 2019 23:45:08 +0200 Subject: [PATCH 03/39] Removes unneeded copyright info from MkDocs configuration file --- mkdocs.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index e96d97dd..38cd386c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -33,4 +33,3 @@ pages: site_name: zend-view site_description: zend-view repo_url: 'https://github.com/zendframework/zend-view' -copyright: 'Copyright (c) 2016 Zend Technologies USA Inc.' From 9a33cd1f820e7aa16e6c084620c772719cafb43a Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 5 Aug 2019 23:45:34 +0200 Subject: [PATCH 04/39] Updates site description in MkDocs configuration --- mkdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index 38cd386c..37300f38 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -31,5 +31,5 @@ pages: - Url: helpers/url.md - "Advanced usage of helpers": helpers/advanced-usage.md site_name: zend-view -site_description: zend-view +site_description: 'Flexible view layer supporting and providing multiple view layers, helpers, and more.Flexible view layer supporting and providing multiple view layers, helpers, and more.' repo_url: 'https://github.com/zendframework/zend-view' From 15cbd520843211312b5d11f0711763eb6b6aebac Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 5 Aug 2019 23:53:57 +0200 Subject: [PATCH 05/39] Synchronize and fixes headlines in documentation --- doc/book/helpers/gravatar.md | 2 +- doc/book/helpers/html-object.md | 2 +- doc/book/helpers/intro.md | 2 +- doc/book/helpers/json.md | 2 +- doc/book/helpers/url.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/book/helpers/gravatar.md b/doc/book/helpers/gravatar.md index 45f82b33..3e775735 100644 --- a/doc/book/helpers/gravatar.md +++ b/doc/book/helpers/gravatar.md @@ -1,4 +1,4 @@ -# Gravatar Helper +# Gravatar The `Gravatar` helper is useful for rendering image HTML markup returned from the [gravatar.com](http://gravatar.com) service. diff --git a/doc/book/helpers/html-object.md b/doc/book/helpers/html-object.md index db18894c..5ed0a014 100644 --- a/doc/book/helpers/html-object.md +++ b/doc/book/helpers/html-object.md @@ -1,4 +1,4 @@ -# HTML Object +# HtmlObject The HTML `` element is used for embedding media like Flash or QuickTime in web pages. The object view helpers take care of embedding media with minimum diff --git a/doc/book/helpers/intro.md b/doc/book/helpers/intro.md index 8b476d6a..84097562 100644 --- a/doc/book/helpers/intro.md +++ b/doc/book/helpers/intro.md @@ -1,4 +1,4 @@ -# View Helpers +# Introduction In your view scripts, you'll perform certain complex functions over and over: e.g., formatting a date, generating form elements, or displaying action links. diff --git a/doc/book/helpers/json.md b/doc/book/helpers/json.md index 411585a8..622da8cc 100644 --- a/doc/book/helpers/json.md +++ b/doc/book/helpers/json.md @@ -1,4 +1,4 @@ -# JSON +# Json When creating views that return JSON, it's important to also set the appropriate response header. The JSON view helper does exactly that. In addition, by diff --git a/doc/book/helpers/url.md b/doc/book/helpers/url.md index 43ed65d4..1aba2aa0 100644 --- a/doc/book/helpers/url.md +++ b/doc/book/helpers/url.md @@ -1,4 +1,4 @@ -# URL +# Url The URL view helper is used to create a string representation of the routes that you define within your application. The syntax for the view helper is From fea1adfa09e25dcae66e9b9b5d89157ee5130653 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 5 Aug 2019 23:54:18 +0200 Subject: [PATCH 06/39] Removes unused index.html file from docs directory --- doc/book/index.html | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 doc/book/index.html diff --git a/doc/book/index.html b/doc/book/index.html deleted file mode 100644 index 27afd7fe..00000000 --- a/doc/book/index.html +++ /dev/null @@ -1,12 +0,0 @@ -
-
-

zend-view

- -

- Flexible view layer supporting and providing multiple view layers, helpers, and more. -

- -
$ composer require zendframework/zend-view
-
-
- From 8917627aee3ce6fde2c11c826d6864f5acd3415b Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 12 Aug 2019 22:18:08 +0200 Subject: [PATCH 07/39] fix: remove duplicated description --- mkdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index 37300f38..c87694fa 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -31,5 +31,5 @@ pages: - Url: helpers/url.md - "Advanced usage of helpers": helpers/advanced-usage.md site_name: zend-view -site_description: 'Flexible view layer supporting and providing multiple view layers, helpers, and more.Flexible view layer supporting and providing multiple view layers, helpers, and more.' +site_description: 'Flexible view layer supporting and providing multiple view layers, helpers, and more.' repo_url: 'https://github.com/zendframework/zend-view' From dc0efa344a81d88be04375ff54b28a89e1fb0c81 Mon Sep 17 00:00:00 2001 From: frank Date: Tue, 13 Aug 2019 21:28:20 +0200 Subject: [PATCH 08/39] Adds cookbook recipe for setting module-specific layout --- .../setting-module-specific-layout.md | 85 +++++++++++++++++++ mkdocs.yml | 2 + 2 files changed, 87 insertions(+) create mode 100644 doc/book/cookbook/setting-module-specific-layout.md diff --git a/doc/book/cookbook/setting-module-specific-layout.md b/doc/book/cookbook/setting-module-specific-layout.md new file mode 100644 index 00000000..b7086f6d --- /dev/null +++ b/doc/book/cookbook/setting-module-specific-layout.md @@ -0,0 +1,85 @@ +# Setting module-specific Layout + +The following example shows how to set a template for the layout based on a +module name in a zend-mvc based application. The example uses a listener that +listen on the +[`Zend\Mvc\MvcEvent::EVENT_RENDER` event](https://docs.zendframework.com/zend-mvc/mvc-event/#mvceventevent_render-render) +and uses the +[`Zend\Router\RouteMatch` object](https://docs.zendframework.com/zend-mvc/routing/#routing) +to get the called module from current request. + +## Create Listener + +Create a listener as separate class, e.g. +`module/Admin/src/Listener/LayoutListener.php`: + +```php +namespace Admin\Listener; + +use Zend\EventManager\AbstractListenerAggregate; +use Zend\EventManager\EventManagerInterface; +use Zend\Mvc\MvcEvent; + +class LayoutListener extends AbstractListenerAggregate +{ + public function attach(EventManagerInterface $events, $priority = 1) + { + $this->listeners[] = $events->attach( + MvcEvent::EVENT_RENDER, + [ + $this, + 'setLayout', + ] + ); + } + + public function setLayout(MvcEvent $event) : void + { + // Get route match object + $routeMatch = $event->getRouteMatch(); + + // Check route match and parameter for current module + if ($routeMatch + && $routeMatch->getParam('module') === 'Admin' + ) { + // Get root view model + $layoutViewModel = $event->getViewModel(); + + // Change template + $layoutViewModel->setTemplate('layout/backend'); + } + } +} +``` + +## Register Listener + +Extend the module class to register the listener, e.g. +`module/Admin/Module.php`: + +```php +namespace Admin; + +use Application\Listener\LayoutListener; +use Zend\EventManager\EventInterface; +use Zend\ModuleManager\Feature\BootstrapListenerInterface; + +class Module implements BootstrapListenerInterface +{ + public function onBootstrap(EventInterface $e) + { + /** @var \Zend\Mvc\MvcEvent $e */ + + $application = $e->getApplication(); + + // Create and register layout listener + $layoutAggregate = new LayoutListener(); + $layoutAggregate->attach($application->getEventManager()); + } + + // … +} +``` + +> More informations on registering module-specific listeners can be found in the +> [documentation of zend-mvc](https://docs.zendframework.com/zend-mvc/examples/#registering-module-specific-listeners). diff --git a/mkdocs.yml b/mkdocs.yml index fd188f24..ab2d0c54 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -30,6 +30,8 @@ pages: - Placeholder: helpers/placeholder.md - Url: helpers/url.md - "Advanced usage of helpers": helpers/advanced-usage.md + - Cookbook: + - "Setting module-specific Layout": cookbook\setting-module-specific-layout.md site_name: zend-view site_description: zend-view repo_url: 'https://github.com/zendframework/zend-view' From b5045b9712974592b316411ffae1a4bdc970049f Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 16:18:58 +0200 Subject: [PATCH 09/39] Simplifies the module class for better type hint --- doc/book/cookbook/setting-module-specific-layout.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/book/cookbook/setting-module-specific-layout.md b/doc/book/cookbook/setting-module-specific-layout.md index b7086f6d..8fdae1ac 100644 --- a/doc/book/cookbook/setting-module-specific-layout.md +++ b/doc/book/cookbook/setting-module-specific-layout.md @@ -61,15 +61,12 @@ Extend the module class to register the listener, e.g. namespace Admin; use Application\Listener\LayoutListener; -use Zend\EventManager\EventInterface; -use Zend\ModuleManager\Feature\BootstrapListenerInterface; +use Zend\Mvc\MvcEvent; -class Module implements BootstrapListenerInterface +class Module { - public function onBootstrap(EventInterface $e) + public function onBootstrap(MvcEvent $e) : void { - /** @var \Zend\Mvc\MvcEvent $e */ - $application = $e->getApplication(); // Create and register layout listener From f9e290c25c48af5b62c976f1fad1602e43b74154 Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 16:31:37 +0200 Subject: [PATCH 10/39] Improves spelling and adds missing articles --- doc/book/cookbook/setting-module-specific-layout.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/book/cookbook/setting-module-specific-layout.md b/doc/book/cookbook/setting-module-specific-layout.md index 8fdae1ac..7cb0b1e0 100644 --- a/doc/book/cookbook/setting-module-specific-layout.md +++ b/doc/book/cookbook/setting-module-specific-layout.md @@ -1,16 +1,16 @@ -# Setting module-specific Layout +# Setting module-specific Layouts The following example shows how to set a template for the layout based on a module name in a zend-mvc based application. The example uses a listener that -listen on the +listens on the [`Zend\Mvc\MvcEvent::EVENT_RENDER` event](https://docs.zendframework.com/zend-mvc/mvc-event/#mvceventevent_render-render) and uses the [`Zend\Router\RouteMatch` object](https://docs.zendframework.com/zend-mvc/routing/#routing) -to get the called module from current request. +to get the called module from the current request. ## Create Listener -Create a listener as separate class, e.g. +Create a listener as a separate class, e.g. `module/Admin/src/Listener/LayoutListener.php`: ```php From edbd29cb5fd48f4ce3cae60ccdeeffbaee69bea9 Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 16:32:10 +0200 Subject: [PATCH 11/39] Fixes styling in code example --- doc/book/cookbook/setting-module-specific-layout.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc/book/cookbook/setting-module-specific-layout.md b/doc/book/cookbook/setting-module-specific-layout.md index 7cb0b1e0..b0120283 100644 --- a/doc/book/cookbook/setting-module-specific-layout.md +++ b/doc/book/cookbook/setting-module-specific-layout.md @@ -26,10 +26,7 @@ class LayoutListener extends AbstractListenerAggregate { $this->listeners[] = $events->attach( MvcEvent::EVENT_RENDER, - [ - $this, - 'setLayout', - ] + [$this, 'setLayout'] ); } From de3cb37e77aa069b03d66d1373868d0552cfa47a Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 16:44:46 +0200 Subject: [PATCH 12/39] Fixes page name and filename for new cookbook recipe --- ...le-specific-layout.md => setting-module-specific-layouts.md} | 0 mkdocs.yml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename doc/book/cookbook/{setting-module-specific-layout.md => setting-module-specific-layouts.md} (100%) diff --git a/doc/book/cookbook/setting-module-specific-layout.md b/doc/book/cookbook/setting-module-specific-layouts.md similarity index 100% rename from doc/book/cookbook/setting-module-specific-layout.md rename to doc/book/cookbook/setting-module-specific-layouts.md diff --git a/mkdocs.yml b/mkdocs.yml index ab2d0c54..94186d09 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -31,7 +31,7 @@ pages: - Url: helpers/url.md - "Advanced usage of helpers": helpers/advanced-usage.md - Cookbook: - - "Setting module-specific Layout": cookbook\setting-module-specific-layout.md + - "Setting module-specific Layouts": cookbook\setting-module-specific-layouts.md site_name: zend-view site_description: zend-view repo_url: 'https://github.com/zendframework/zend-view' From 30946b5a5382019caa40e9bd2fad7326b67b93ac Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 21:39:30 +0200 Subject: [PATCH 13/39] Updates listener and modules in code examples --- .../setting-module-specific-layouts.md | 68 +++++++++++++++---- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/doc/book/cookbook/setting-module-specific-layouts.md b/doc/book/cookbook/setting-module-specific-layouts.md index b0120283..bc15efe0 100644 --- a/doc/book/cookbook/setting-module-specific-layouts.md +++ b/doc/book/cookbook/setting-module-specific-layouts.md @@ -18,10 +18,29 @@ namespace Admin\Listener; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; +use Zend\Filter\FilterChain; +use Zend\Filter\FilterInterface; +use Zend\Filter\StringToLower; +use Zend\Filter\Word\CamelCaseToDash; use Zend\Mvc\MvcEvent; +use Zend\View\Resolver\TemplateMapResolver; class LayoutListener extends AbstractListenerAggregate { + /** @var TemplateMapResolver */ + private $templateMapResolver; + + /** @var FilterInterface */ + private $filter; + + public function __construct(TemplateMapResolver $templateMapResolver) + { + $this->templateMapResolver = $templateMapResolver; + $this->filter = (new FilterChain()) + ->attach(new CamelCaseToDash()) + ->attach(new StringToLower()); + } + public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach( @@ -29,22 +48,37 @@ class LayoutListener extends AbstractListenerAggregate [$this, 'setLayout'] ); } - + public function setLayout(MvcEvent $event) : void { - // Get route match object + // Get and check the route match object $routeMatch = $event->getRouteMatch(); + if (! $routeMatch) { + return; + } - // Check route match and parameter for current module - if ($routeMatch - && $routeMatch->getParam('module') === 'Admin' - ) { - // Get root view model - $layoutViewModel = $event->getViewModel(); + // Get and check the parameter for current controller + $controller = $routeMatch->getParam('controller'); + if (! $controller) { + return; + } + + // Extract module name + $module = substr($controller, 0, strpos($controller, '\\')); + + // Convert the module name from camel case to a lower string with dashes + $name = 'layout/' . $this->filter->filter($module); - // Change template - $layoutViewModel->setTemplate('layout/backend'); + // Has the resolver an entry / layout with the given name? + if (! $this->templateMapResolver->has($name)) { + return; } + + // Get root view model + $layoutViewModel = $event->getViewModel(); + + // Change template + $layoutViewModel->setTemplate($name); } } ``` @@ -59,16 +93,22 @@ namespace Admin; use Application\Listener\LayoutListener; use Zend\Mvc\MvcEvent; +use Zend\View\Resolver\TemplateMapResolver; class Module { - public function onBootstrap(MvcEvent $e) : void + public function onBootstrap(MvcEvent $event) : void { - $application = $e->getApplication(); + $application = $event->getApplication(); + + /** @var TemplateMapResolver $templateMapResolver */ + $templateMapResolver = $application->getServiceManager()->get( + 'ViewTemplateMapResolver' + ); // Create and register layout listener - $layoutAggregate = new LayoutListener(); - $layoutAggregate->attach($application->getEventManager()); + $listener = new LayoutListener($templateMapResolver); + $listener->attach($application->getEventManager()); } // … From 316e20deb16d7d22aa8df44f40611c5da956e4c0 Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 21:41:41 +0200 Subject: [PATCH 14/39] Adds section for template script configuration --- .../setting-module-specific-layouts.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/book/cookbook/setting-module-specific-layouts.md b/doc/book/cookbook/setting-module-specific-layouts.md index bc15efe0..4f096baf 100644 --- a/doc/book/cookbook/setting-module-specific-layouts.md +++ b/doc/book/cookbook/setting-module-specific-layouts.md @@ -117,3 +117,38 @@ class Module > More informations on registering module-specific listeners can be found in the > [documentation of zend-mvc](https://docs.zendframework.com/zend-mvc/examples/#registering-module-specific-listeners). + +## Add Template Scripts to the Configuration + +Extend the configuration of a module to add the specific layout script, e.g. +`module/Admin/config/module.config.php`: + +```php +return [ + // Add the following array + 'view_manager' => [ + 'template_map' => [ + 'layout/admin' => __DIR__ . '/../view/layout/admin.phtml', + ], + ], + // … +]; +``` + +And in another module, e.g. `module/Album/config/module.config.php`: + +```php +return [ + // Add the following array + 'view_manager' => [ + 'template_map' => [ + 'layout/album' => __DIR__ . '/../view/layout/layout-of-album.phtml', + ], + ], + // … +]; +``` + +The name of the array key must follow the format `layout/{module-name}` and the +value must contain the path to the layout file. The path and the filename can be +freely chosen. From d6f73b9afa3d0957620c70a0e9c7f0412a103a99 Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 21:46:43 +0200 Subject: [PATCH 15/39] Fixes wrong description in introduction --- doc/book/cookbook/setting-module-specific-layouts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/book/cookbook/setting-module-specific-layouts.md b/doc/book/cookbook/setting-module-specific-layouts.md index 4f096baf..dde22830 100644 --- a/doc/book/cookbook/setting-module-specific-layouts.md +++ b/doc/book/cookbook/setting-module-specific-layouts.md @@ -6,7 +6,7 @@ listens on the [`Zend\Mvc\MvcEvent::EVENT_RENDER` event](https://docs.zendframework.com/zend-mvc/mvc-event/#mvceventevent_render-render) and uses the [`Zend\Router\RouteMatch` object](https://docs.zendframework.com/zend-mvc/routing/#routing) -to get the called module from the current request. +to get the called controller from the current request. ## Create Listener From 99dccab57243f1eb247fbbff1a37a66b7330d235 Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 21:50:28 +0200 Subject: [PATCH 16/39] Removes unneeded whitespace in code example --- doc/book/cookbook/setting-module-specific-layouts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/book/cookbook/setting-module-specific-layouts.md b/doc/book/cookbook/setting-module-specific-layouts.md index dde22830..b9989b14 100644 --- a/doc/book/cookbook/setting-module-specific-layouts.md +++ b/doc/book/cookbook/setting-module-specific-layouts.md @@ -48,7 +48,7 @@ class LayoutListener extends AbstractListenerAggregate [$this, 'setLayout'] ); } - + public function setLayout(MvcEvent $event) : void { // Get and check the route match object From 9f390c7f3c9d3f965fd05abd1a644b31b7a733e3 Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Aug 2019 21:56:57 +0200 Subject: [PATCH 17/39] Fixes grammar in introduction --- doc/book/helpers/html-tag.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/book/helpers/html-tag.md b/doc/book/helpers/html-tag.md index be9d0029..d7c38caf 100644 --- a/doc/book/helpers/html-tag.md +++ b/doc/book/helpers/html-tag.md @@ -1,7 +1,7 @@ # HtmlTag -The `HtmlTag` helper is used to **create the root of a HTML document**, the open -and close tags for the `` element. +The `HtmlTag` helper is used to **create the root of an HTML document**, the +open and close tags for the `` element. ## Basic Usage From e47cb5b57b80f9157a298d714000a58593fe6804 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 19 Aug 2019 21:32:36 +0200 Subject: [PATCH 18/39] Fixes #109 - HeadTitle helper documentation is too complicated --- doc/book/helpers/head-title.md | 232 ++++++++++++++++++++++++--------- 1 file changed, 170 insertions(+), 62 deletions(-) diff --git a/doc/book/helpers/head-title.md b/doc/book/helpers/head-title.md index c0fe867e..e2f9d61b 100644 --- a/doc/book/helpers/head-title.md +++ b/doc/book/helpers/head-title.md @@ -1,8 +1,8 @@ # HeadTitle -The HTML `` element is used to provide a title for an HTML document. The -`HeadTitle` helper allows you to programmatically create and store the title for -later retrieval and output. +The HTML `<title>` element is used to **provide a title for an HTML document**. +The `HeadTitle` helper allows you to programmatically create and store the title +for later retrieval and output. The `HeadTitle` helper is a concrete implementation of the [Placeholder helper](placeholder.md). It overrides the `toString()` method to enforce generating a `<title>` element, @@ -19,62 +19,15 @@ explicitly pass a different attach order as the second parameter. ## Basic Usage -You may specify a title tag at any time. A typical usage would have you setting -title segments for each level of depth in your application: site, module, -controller, action, and potentially resource. This could be achieved in the -module class. +Specify a title tag in a view script, e.g. +`module/Album/view/album/album/index.phtml`: ```php -// module/MyModule/Module.php -<?php - -namespace MyModule; - -class Module -{ - /** - * @param \Zend\Mvc\MvcEvent $e The MvcEvent instance - * @return void - */ - public function onBootstrap($e) - { - // Register a render event - $app = $e->getParam('application'); - $app->getEventManager()->attach('render', [$this, 'setLayoutTitle']); - } - - /** - * @param \Zend\Mvc\MvcEvent $e The MvcEvent instance - * @return void - */ - public function setLayoutTitle($e) - { - $matches = $e->getRouteMatch(); - $action = $matches->getParam('action'); - $controller = $matches->getParam('controller'); - $module = __NAMESPACE__; - $siteName = 'Zend Framework'; - - // Getting the view helper manager from the application service manager - $viewHelperManager = $e->getApplication()->getServiceManager()->get('ViewHelperManager'); - - // Getting the headTitle helper from the view helper manager - $headTitleHelper = $viewHelperManager->get('headTitle'); - - // Setting a separator string for segments - $headTitleHelper->setSeparator(' - '); - - // Setting the action, controller, module and site name as title segments - $headTitleHelper->append($action); - $headTitleHelper->append($controller); - $headTitleHelper->append($module); - $headTitleHelper->append($siteName); - } -} -``` - -When you're finally ready to render the title in your layout script, echo the -helper: +$this->headTitle('My albums'); +``` + +Render the title in the layout script, e.g. +`module/Application/view/layout/layout.phtml` ```php <?= $this->headTitle() ?> @@ -83,18 +36,173 @@ helper: Output: ```html -<title>action - controller - module - Zend Framework +My albums ``` -In case you want the title without the `` and `` tags you can use -the `renderTitle()` method: +### Add the Website Name + +A typical usage includes the website name in the title. Add the name and [set a +separator](#using-separator) in the layout script, e.g. +`module/Application/view/layout/layout.phtml` ```php -headTitle()->renderTitle() ?> +headTitle('Music')->setSeparator(' - ') ?> ``` Output: ```html -action - controller - module - Zend Framework +My albums - Music +``` + +## Set Content + +The normal behaviour is to append the content to the title (container). + +```php +$this->headTitle('My albums') +$this->headTitle('Music'); + +echo $this->headTitle(); // My albumsMusic +``` + +### Append Content + +To explicitly append content, the second paramater `$setType` or the concrete +method `append()` of the helper can be used: + +```php fct_label="Invoke Usage" +$this->headTitle('My albums') +$this->headTitle('Music', 'APPEND'); + +echo $this->headTitle(); // My albumsMusic +``` + +```php fct_label="Setter Usage" +$this->headTitle('My albums') +$this->headTitle()->append('Music'); + +echo $this->headTitle(); // My albumsMusic +``` + +The constant `Zend\View\Helper\Placeholder\Container\AbstractContainer::APPEND` +can also be used as value for the second parameter `$setType`. + +### Prepend Content + +To prepend content, the second paramater `$setType` or the concrete method +`prepend()` of the helper can be used: + +```php fct_label="Invoke Usage" +$this->headTitle('My albums') +$this->headTitle('Music', 'PREPEND'); + +echo $this->headTitle(); // MusicMy albums +``` + +```php fct_label="Setter Usage" +$this->headTitle('My albums') +$this->headTitle()->prepend('Music'); + +echo $this->headTitle(); // MusicMy albums +``` + +The constant `Zend\View\Helper\Placeholder\Container\AbstractContainer::PREPEND` +can also be used as value for the second parameter `$setType`. + +### Overwrite existing Content + +To overwrite the entire content of title helper, the second parameter `$setType` +or the concrete method `set()` of the helper can be used: + +```php fct_label="Invoke Usage" +$this->headTitle('My albums') +$this->headTitle('Music', 'SET'); + +echo $this->headTitle(); // Music +``` + +```php fct_label="Setter Usage" +$this->headTitle('My albums') +$this->headTitle()->set('Music'); + +echo $this->headTitle(); // Music +``` + +The constant `Zend\View\Helper\Placeholder\Container\AbstractContainer::SET` +can also be used as value for the second parameter `$setType`. + +### Set a default Order to add Content + +```php +$this->headTitle()->setDefaultAttachOrder('PREPEND'); +$this->headTitle('My albums'); +$this->headTitle('Music'); + +echo $this->headTitle(); // MusicMy albums +``` + +#### Get Current Value + +To get the current value of this option, use the `getDefaultAttachOrder()` +method. + +```php +$this->headTitle()->setDefaultAttachOrder('PREPEND'); + +echo $this->getDefaultAttachOrder(); // PREPEND +``` + +#### Default Value + +The default value is +`Zend\View\Helper\Placeholder\Container\AbstractContainer::APPEND` which +corresponds to the value `APPEND`. + +## Using Separator + +```php +$this->headTitle()->setSeparator(' | '); +$this->headTitle('My albums'); +$this->headTitle('Music'); + +echo $this->headTitle(); // My albums | Music +``` + +### Get Current Value + +To get the current value of this option, use the `getSeparator()` +method. + +```php +$this->headTitle()->setSeparator(' | '); + +echo $this->getSeparator(); // | +``` + +### Default Value + +The default value is an empty `string` that means no extra content is added +between the titles on rendering. + +## Add Prefix and Postfix + +The content of the helper can be formatted with a prefix and a postfix. + +```php +$this->headTitle('My albums')->setPrefix('Music: ')->setPostfix('𝄞'); + +echo $this->headTitle(); // Music: My albums 𝄞 +``` + +More descriptions and another example of usage can be found at the +[`Placeholder` helper](placeholder.md#aggregate-content). + +## Render without Tags + +In case the title is needed without the `` and `` tags the +`renderTitle()` method can be used. + +```php +echo $this->headTitle('My albums')->renderTitle(); // My albums ``` From 860d42ad28927c67c67207d5621f847465d2cd55 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 19 Aug 2019 21:58:48 +0200 Subject: [PATCH 19/39] Adds missing helper calls in code examples --- doc/book/helpers/head-title.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/book/helpers/head-title.md b/doc/book/helpers/head-title.md index e2f9d61b..1cb27bb3 100644 --- a/doc/book/helpers/head-title.md +++ b/doc/book/helpers/head-title.md @@ -150,7 +150,7 @@ method. ```php $this->headTitle()->setDefaultAttachOrder('PREPEND'); -echo $this->getDefaultAttachOrder(); // PREPEND +echo $this->headTitle()->getDefaultAttachOrder(); // PREPEND ``` #### Default Value @@ -177,7 +177,7 @@ method. ```php $this->headTitle()->setSeparator(' | '); -echo $this->getSeparator(); // | +echo $this->headTitle()->getSeparator(); // | ``` ### Default Value From 84152cb4213515d3abeb2716b9ffa5aed47a4fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Tue, 20 Aug 2019 09:18:46 +0200 Subject: [PATCH 20/39] Fixes namespace for listener class in code example --- doc/book/cookbook/setting-module-specific-layouts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/book/cookbook/setting-module-specific-layouts.md b/doc/book/cookbook/setting-module-specific-layouts.md index b9989b14..69d5295f 100644 --- a/doc/book/cookbook/setting-module-specific-layouts.md +++ b/doc/book/cookbook/setting-module-specific-layouts.md @@ -91,7 +91,7 @@ Extend the module class to register the listener, e.g. ```php namespace Admin; -use Application\Listener\LayoutListener; +use Admin\Listener\LayoutListener; use Zend\Mvc\MvcEvent; use Zend\View\Resolver\TemplateMapResolver; From ed1b13234f3dcd1f23c4c89f02bcb97c166fe88a Mon Sep 17 00:00:00 2001 From: frank Date: Tue, 20 Aug 2019 21:55:34 +0200 Subject: [PATCH 21/39] Fixes #99 - Missing documentation for Escape view helpers --- doc/book/helpers/escape.md | 248 +++++++++++++++++++++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 249 insertions(+) create mode 100644 doc/book/helpers/escape.md diff --git a/doc/book/helpers/escape.md b/doc/book/helpers/escape.md new file mode 100644 index 00000000..80f377c1 --- /dev/null +++ b/doc/book/helpers/escape.md @@ -0,0 +1,248 @@ +# Escape + +The following helpers can **escape output in view scripts and defend from XSS +and related vulnerabilities**. To escape different contexts of a HTML document, +zend-view provides 5 helpers: + +* [`EscapeCss`](#escapecss) +* [`EscapeHtml`](#escapehtml) +* [`EscapeHtmlAttr`](#escapehtmlattr) +* [`EscapeJs`](#escapejs) +* [`EscapeUrl`](#escapeurl) + +More informations to the operation and the background of security can be found +in the +[documentation of zend-escaper](https://docs.zendframework.com/zend-escaper/configuration/). + +> ### Installation Requirements +> +> The escape helpers depends on the zend-escaper component, so be sure to have +> it installed before getting started: +> +> ```bash +> $ composer require zendframework/zend-escaper +> ``` + +## EscapeCss + +```php +$css = <<'); +} +CSS; + +echo $this->escapeCss($css); +``` + +Output: + +```css +body\20 \7B \D \A \20 \20 \20 \20 background\2D image\3A \20 url\28 \27 http\3A \2F \2F example\2E com\2F foo\2E jpg\3F \3C \2F style\3E \3C script\3E alert\28 1\29 \3C \2F script\3E \27 \29 \3B \D \A \7D +``` + +## EscapeHtml + +```php +$html = ""; + +echo $this->escapeHtml($html); +``` + +Output: + +```html +<script>alert('zend-framework')</script> +``` + +## EscapeHtmlAttr + +```php+html + + +escapeHtmlAttr($html) ?>>click +``` + +Output: + +```html +click +``` + +## EscapeJs + +```php +$js = "window.location = 'https://framework.zend.com/?cookie=' + document.cookie"; + +echo $this->escapeJs($js); +``` + +Output: + +```js +window.location\x20\x3D\x20\x27https\x3A\x2F\x2Fframework.zend.com\x2F\x3Fcookie\x3D\x27\x20\x2B\x20document.cookie +``` + +## EscapeUrl + +```php + + +click +``` + +Output: + +```html +click +``` + +## Using Encoding + +```php +$this->escapeHtml()->setEncoding('iso-8859-15'); +``` + +All allowed encodings can be found in the +[documentation of zend-escaper](https://docs.zendframework.com/zend-escaper/configuration/). + +### Get Current Value + +To get the current value of this option, use the `getEncoding()` method. + +```php +$this->escapeHtml()->setEncoding('iso-8859-15'); + +echo $this->escapeHtml()->getEncoding(); // iso-8859-15 +``` + +### Default Value + +The default value for all escape helpers is `utf-8`. + +## Using Recursion + +All escape helpers can use recursion for the given values during the escape +operation. This allows the escaping of the datatypes `array` and `object`. + +### Escape an Array + +To escape an `array`, the second parameter `$recurse` must be use the constant +`RECURSE_ARRAY` of an escape helper: + +```php +$html = [ + 'headline' => '

Foo

', + 'content' => [ + 'paragraph' => '

Bar

', + ], +]; + +var_dump($this->escapeHtml($html, Zend\View\Helper\EscapeHtml::RECURSE_ARRAY)); +``` + +Output: + +```php +array(2) { + 'headline' => + string(24) "<h1>Foo</h1>" + 'content' => + array(1) { + 'paragraph' => + string(22) "<p>Bar</p>" + } +} +``` + +### Escape an Object + +An escape helper can use the `__toString()` method of an object. No additional +parameter is needed: + +```php +$object = new class { + public function __toString() : string + { + return '

Foo

'; + } +}; + +echo $this->escapeHtml($object); // "<h1>Foo</h1>" +``` + +An escape helper can also use the `toArray()` method of an object. The second +parameter `$recurse` must be use the constant `RECURSE_OBJECT` of an escape +helper: + +```php +$object = new class { + public function toArray() : array + { + return ['headline' => '

Foo

']; + } +}; + +var_dump($this->escapeHtml($object, Zend\View\Helper\EscapeHtml::RECURSE_OBJECT)); +``` + +Output: + +```php +array(1) { + 'headline' => + string(3) "<h1>Foo</h1>" +} +``` + +If the object does not contains the methods `__toString()` or `toArray()` then +the object is casted to an `array`: + +```php +$object = new class { + public $headline = '

Foo

'; +}; + +var_dump($this->escapeHtml($object, Zend\View\Helper\EscapeHtml::RECURSE_OBJECT)); +``` + +Output: + +```php +array(1) { + 'headline' => + string(3) "<h1>Foo</h1>" +} +``` + +## Using Custom Escaper + +Create an own instance of `Zend\Escaper\Escaper` and set to any of the escape +helpers: + +```php +$escaper = new Zend\Escaper\Escaper('utf-8'); + +$this->escapeHtml()->setEscaper($escaper); +``` + +### Get Current Value + +To get the current value, use the `getEscaper()` method. + +```php +escapeHtml()->setEscaper($escaper); + +var_dump($this->escapeHtml()->getEscaper()); // instance of Zend\Escaper\Escaper +``` + +### Default Value + +The default value is an instance of `Zend\Escaper\Escaper`, created by the +helper. diff --git a/mkdocs.yml b/mkdocs.yml index fd188f24..8e7493f3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -13,6 +13,7 @@ pages: - BasePath: helpers/base-path.md - Cycle: helpers/cycle.md - Doctype: helpers/doctype.md + - Escape: helpers/escape.md - FlashMessenger: helpers/flash-messenger.md - Gravatar: helpers/gravatar.md - HeadLink: helpers/head-link.md From 26679ddafc593e5163df30e98d3ce98b764aa13f Mon Sep 17 00:00:00 2001 From: webimpress Date: Tue, 27 Aug 2019 23:29:41 +0100 Subject: [PATCH 22/39] Fix: replace curly offset access brace with square brackets As of PHP 7.4: the array and string offset access syntax using curly braces is deprecated. --- src/Helper/Navigation/Sitemap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Helper/Navigation/Sitemap.php b/src/Helper/Navigation/Sitemap.php index 76acb227..08aa922e 100644 --- a/src/Helper/Navigation/Sitemap.php +++ b/src/Helper/Navigation/Sitemap.php @@ -267,10 +267,10 @@ public function url(AbstractPage $page) { $href = $page->getHref(); - if (! isset($href{0})) { + if (! isset($href[0])) { // no href return ''; - } elseif ($href{0} == '/') { + } elseif ($href[0] == '/') { // href is relative to root; use serverUrl helper $url = $this->getServerUrl() . $href; } elseif (preg_match('/^[a-z]+:/im', (string) $href)) { From 95b9a2879f98b46a88893d75709ba3daa9b3dae6 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 20 Sep 2019 14:55:22 +0100 Subject: [PATCH 23/39] Fixed link to md file in mkdocs.yml Use / instead of \ as directory separator --- mkdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index f5fe5a00..8f995d78 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -32,7 +32,7 @@ pages: - Url: helpers/url.md - "Advanced usage of helpers": helpers/advanced-usage.md - Cookbook: - - "Setting module-specific Layouts": cookbook\setting-module-specific-layouts.md + - "Setting module-specific Layouts": cookbook/setting-module-specific-layouts.md site_name: zend-view site_description: 'Flexible view layer supporting and providing multiple view layers, helpers, and more.' repo_url: 'https://github.com/zendframework/zend-view' From 61bc41e2f4bf91b556013bbd4f93d28533403947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Bru=CC=88ckner?= Date: Thu, 10 Oct 2019 16:12:07 +0200 Subject: [PATCH 24/39] Removes hard number of escape helpers from introduction --- doc/book/helpers/escape.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/book/helpers/escape.md b/doc/book/helpers/escape.md index 80f377c1..e38fbb60 100644 --- a/doc/book/helpers/escape.md +++ b/doc/book/helpers/escape.md @@ -2,7 +2,7 @@ The following helpers can **escape output in view scripts and defend from XSS and related vulnerabilities**. To escape different contexts of a HTML document, -zend-view provides 5 helpers: +zend-view provides the following helpers: * [`EscapeCss`](#escapecss) * [`EscapeHtml`](#escapehtml) From d3d590044948bbbee0882ca53f72a49b6808bc78 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 10 Oct 2019 22:15:35 +0100 Subject: [PATCH 25/39] Adds CHANGELOG entry for #192 --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32761795..dd9df6af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,9 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#192](https://github.com/zendframework/zend-view/pull/192) changes + curly braces in array and string offset access to square brackets + in order to prevent issues under the upcoming PHP 7.4 release. ## 2.11.2 - 2019-02-19 From cd691f9a6e3f97812c98e7385208e3dc3661bb4d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 10 Oct 2019 10:57:31 +0200 Subject: [PATCH 26/39] fix Using array_key_exists() on objects --- src/Model/ViewModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/ViewModel.php b/src/Model/ViewModel.php index 04e76498..6c330dab 100644 --- a/src/Model/ViewModel.php +++ b/src/Model/ViewModel.php @@ -239,7 +239,7 @@ public function clearOptions() public function getVariable($name, $default = null) { $name = (string) $name; - if (array_key_exists($name, $this->variables)) { + if (isset($this->variables[$name])) { return $this->variables[$name]; } From c711fbddaedc322cf5cbdfaa5f4dce8c201e35d7 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 10 Oct 2019 23:01:54 +0100 Subject: [PATCH 27/39] Fixes failing tests on PHP 7.4 From PHP 7.4 docs: Calling get_object_vars() on an ArrayObject instance will now always return the properties of the ArrayObject itself (or a subclass). Previously it returned the values of the wrapped array/object unless the STD_PROP_LIST flag was specified. Other affected operations are: * ReflectionObject::getProperties() * reset(), current(), etc. Use Iterator methods instead. * Potentially others working on object properties as a list. --- .../application/views/scripts/partialLoopChildObject.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Helper/_files/modules/application/views/scripts/partialLoopChildObject.phtml b/test/Helper/_files/modules/application/views/scripts/partialLoopChildObject.phtml index e5babd65..1463771b 100644 --- a/test/Helper/_files/modules/application/views/scripts/partialLoopChildObject.phtml +++ b/test/Helper/_files/modules/application/views/scripts/partialLoopChildObject.phtml @@ -1,12 +1,12 @@ vars(); +$vars = (array) $this->vars(); if (empty($vars)) { echo "No object model passed"; } elseif (isset($vars['message'])) { echo $vars['message']; } else { - $objKey = current($this->vars())->helper->getObjectKey(); + $objKey = current($vars)->helper->getObjectKey(); echo 'This is an iteration with objectKey: ' . $objKey; } From 81ed6ca3c83f295fabdb67f7d9e5e2c9de0a41be Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 10 Oct 2019 23:08:36 +0100 Subject: [PATCH 28/39] Correct the fix so the behaviour of the original code is not changed Added tests to verify the change. --- src/Model/ViewModel.php | 9 +++++-- test/Model/ViewModelTest.php | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Model/ViewModel.php b/src/Model/ViewModel.php index 6c330dab..5609a091 100644 --- a/src/Model/ViewModel.php +++ b/src/Model/ViewModel.php @@ -239,8 +239,13 @@ public function clearOptions() public function getVariable($name, $default = null) { $name = (string) $name; - if (isset($this->variables[$name])) { - return $this->variables[$name]; + + if (is_array($this->variables)) { + if (array_key_exists($name, $this->variables)) { + return $this->variables[$name]; + } + } elseif ($this->variables->offsetExists($name)) { + return $this->variables->offsetGet($name); } return $default; diff --git a/test/Model/ViewModelTest.php b/test/Model/ViewModelTest.php index 318825f8..e922a0e8 100644 --- a/test/Model/ViewModelTest.php +++ b/test/Model/ViewModelTest.php @@ -361,4 +361,56 @@ public function testCloneWithArray() $this->assertEquals('foo', $model1->getVariable('a')); $this->assertEquals('bar', $model2->getVariable('a')); } + + public function variableValue() + { + return [ + // variables default expected + + // if it is set always get the value + [['foo' => 'bar'], 'baz', 'bar'], + [['foo' => 'bar'], null, 'bar'], + [new ArrayObject(['foo' => 'bar']), 'baz', 'bar'], + [new ArrayObject(['foo' => 'bar']), null, 'bar'], + + // if it is null always get null value + [['foo' => null], null, null], + [['foo' => null], 'baz', null], + [new ArrayObject(['foo' => null]), null, null], + [new ArrayObject(['foo' => null]), 'baz', null], + + // when it is not set always get default value + [[], 'baz', 'baz'], + [new ArrayObject(), 'baz', 'baz'], + ]; + } + + /** + * @dataProvider variableValue + * + * @param array|ArrayObject $variables + * @param string|null $default + * @param string|null $expected + */ + public function testGetVariableSetByConstruct($variables, $default, $expected) + { + $model = new ViewModel($variables); + + self::assertSame($expected, $model->getVariable('foo', $default)); + } + + /** + * @dataProvider variableValue + * + * @param array|ArrayObject $variables + * @param string|null $default + * @param string|null $expected + */ + public function testGetVariableSetBySetter($variables, $default, $expected) + { + $model = new ViewModel(); + $model->setVariables($variables); + + self::assertSame($expected, $model->getVariable('foo', $default)); + } } From e5b3af9b62a8ee720ce485976519f3a5470bca6d Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 19:13:04 +0100 Subject: [PATCH 29/39] Adds CHANGELOG entry for #195 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd9df6af..4bdc014c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ All notable changes to this project will be documented in this file, in reverse curly braces in array and string offset access to square brackets in order to prevent issues under the upcoming PHP 7.4 release. +- [#195](https://github.com/zendframework/zend-view/pull/195) fixes PHP 7.4 compatibility. + ## 2.11.2 - 2019-02-19 ### Added From 289e53c20786ccd6d4a432b9f0a1896fbc669da5 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 19:21:18 +0100 Subject: [PATCH 30/39] Docs update - moved documentation from doc to docs directory - added PR and ISSUE github templates - updated CODE_OF_CONDUCT and CONTRIBUTING files --- CONDUCT.md => docs/CODE_OF_CONDUCT.md | 2 +- CONTRIBUTING.md => docs/CONTRIBUTING.md | 91 +++++-------------- docs/ISSUE_TEMPLATE.md | 19 ++++ docs/PULL_REQUEST_TEMPLATE.md | 25 +++++ docs/SUPPORT.md | 25 +++++ .../setting-module-specific-layouts.md | 6 +- {doc => docs}/book/helpers/advanced-usage.md | 18 ++-- {doc => docs}/book/helpers/asset.md | 0 {doc => docs}/book/helpers/base-path.md | 0 {doc => docs}/book/helpers/cycle.md | 0 {doc => docs}/book/helpers/doctype.md | 0 {doc => docs}/book/helpers/escape.md | 8 +- {doc => docs}/book/helpers/flash-messenger.md | 2 +- {doc => docs}/book/helpers/gravatar.md | 4 +- {doc => docs}/book/helpers/head-link.md | 0 {doc => docs}/book/helpers/head-meta.md | 2 +- {doc => docs}/book/helpers/head-script.md | 2 +- {doc => docs}/book/helpers/head-style.md | 32 +++---- {doc => docs}/book/helpers/head-title.md | 12 +-- {doc => docs}/book/helpers/html-list.md | 0 {doc => docs}/book/helpers/html-object.md | 0 {doc => docs}/book/helpers/html-tag.md | 0 {doc => docs}/book/helpers/identity.md | 0 {doc => docs}/book/helpers/inline-script.md | 0 {doc => docs}/book/helpers/intro.md | 0 {doc => docs}/book/helpers/json.md | 0 {doc => docs}/book/helpers/layout.md | 4 +- {doc => docs}/book/helpers/partial.md | 0 {doc => docs}/book/helpers/placeholder.md | 0 {doc => docs}/book/helpers/url.md | 0 {doc => docs}/book/index.md | 0 {doc => docs}/book/php-renderer.md | 0 {doc => docs}/book/quick-start.md | 8 +- {doc => docs}/book/view-event.md | 0 {doc => docs}/book/view-scripts.md | 0 mkdocs.yml | 6 +- 36 files changed, 145 insertions(+), 121 deletions(-) rename CONDUCT.md => docs/CODE_OF_CONDUCT.md (96%) rename CONTRIBUTING.md => docs/CONTRIBUTING.md (54%) create mode 100644 docs/ISSUE_TEMPLATE.md create mode 100644 docs/PULL_REQUEST_TEMPLATE.md create mode 100644 docs/SUPPORT.md rename {doc => docs}/book/cookbook/setting-module-specific-layouts.md (99%) rename {doc => docs}/book/helpers/advanced-usage.md (99%) rename {doc => docs}/book/helpers/asset.md (100%) rename {doc => docs}/book/helpers/base-path.md (100%) rename {doc => docs}/book/helpers/cycle.md (100%) rename {doc => docs}/book/helpers/doctype.md (100%) rename {doc => docs}/book/helpers/escape.md (98%) rename {doc => docs}/book/helpers/flash-messenger.md (98%) rename {doc => docs}/book/helpers/gravatar.md (98%) rename {doc => docs}/book/helpers/head-link.md (100%) rename {doc => docs}/book/helpers/head-meta.md (99%) rename {doc => docs}/book/helpers/head-script.md (99%) rename {doc => docs}/book/helpers/head-style.md (99%) rename {doc => docs}/book/helpers/head-title.md (95%) rename {doc => docs}/book/helpers/html-list.md (100%) rename {doc => docs}/book/helpers/html-object.md (100%) rename {doc => docs}/book/helpers/html-tag.md (100%) rename {doc => docs}/book/helpers/identity.md (100%) rename {doc => docs}/book/helpers/inline-script.md (100%) rename {doc => docs}/book/helpers/intro.md (100%) rename {doc => docs}/book/helpers/json.md (100%) rename {doc => docs}/book/helpers/layout.md (97%) rename {doc => docs}/book/helpers/partial.md (100%) rename {doc => docs}/book/helpers/placeholder.md (100%) rename {doc => docs}/book/helpers/url.md (100%) rename {doc => docs}/book/index.md (100%) rename {doc => docs}/book/php-renderer.md (100%) rename {doc => docs}/book/quick-start.md (99%) rename {doc => docs}/book/view-event.md (100%) rename {doc => docs}/book/view-scripts.md (100%) diff --git a/CONDUCT.md b/docs/CODE_OF_CONDUCT.md similarity index 96% rename from CONDUCT.md rename to docs/CODE_OF_CONDUCT.md index c663d2be..02fafcd1 100644 --- a/CONDUCT.md +++ b/docs/CODE_OF_CONDUCT.md @@ -1,6 +1,6 @@ # Contributor Code of Conduct -The Zend Framework project adheres to [The Code Manifesto](http://codemanifesto.com) +This project adheres to [The Code Manifesto](http://codemanifesto.com) as its guidelines for contributor interactions. ## The Code Manifesto diff --git a/CONTRIBUTING.md b/docs/CONTRIBUTING.md similarity index 54% rename from CONTRIBUTING.md rename to docs/CONTRIBUTING.md index 17987436..379bc2a3 100644 --- a/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -2,73 +2,43 @@ ## RESOURCES -If you wish to contribute to Zend Framework, please be sure to +If you wish to contribute to this project, please be sure to read/subscribe to the following resources: - - [Coding Standards](https://github.com/zendframework/zf2/wiki/Coding-Standards) - - [Contributor's Guide](http://framework.zend.com/participate/contributor-guide) - - ZF Contributor's mailing list: - Archives: http://zend-framework-community.634137.n4.nabble.com/ZF-Contributor-f680267.html - Subscribe: zf-contributors-subscribe@lists.zend.com - - ZF Contributor's IRC channel: - #zftalk.dev on Freenode.net + - [Coding Standards](https://github.com/zendframework/zend-coding-standard) + - [Forums](https://discourse.zendframework.com/c/contributors) + - [Chat](https://zendframework-slack.herokuapp.com) + - [Code of Conduct](CODE_OF_CONDUCT.md) -If you are working on new features or refactoring [create a proposal](https://github.com/zendframework/zend-view/issues/new). - -## Reporting Potential Security Issues - -If you have encountered a potential security vulnerability, please **DO NOT** report it on the public -issue tracker: send it to us at [zf-security@zend.com](mailto:zf-security@zend.com) instead. -We will work with you to verify the vulnerability and patch it as soon as possible. - -When reporting issues, please provide the following information: - -- Component(s) affected -- A description indicating how to reproduce the issue -- A summary of the security vulnerability and impact - -We request that you contact us via the email address above and give the project -contributors a chance to resolve the vulnerability and issue a new release prior -to any public exposure; this helps protect users and provides them with a chance -to upgrade and/or update in order to protect their applications. - -For sensitive email communications, please use [our PGP key](http://framework.zend.com/zf-security-pgp-key.asc). +If you are working on new features or refactoring +[create a proposal](https://github.com/zendframework/zend-view/issues/new). ## RUNNING TESTS -> ### Note: testing versions prior to 2.4 -> -> This component originates with Zend Framework 2. During the lifetime of ZF2, -> testing infrastructure migrated from PHPUnit 3 to PHPUnit 4. In most cases, no -> changes were necessary. However, due to the migration, tests may not run on -> versions < 2.4. As such, you may need to change the PHPUnit dependency if -> attempting a fix on such a version. - To run tests: - Clone the repository: ```console - $ git clone git@github.com:zendframework/zend-view.git - $ cd + $ git clone git://github.com/zendframework/zend-view.git + $ cd zend-view ``` - Install dependencies via composer: ```console - $ curl -sS https://getcomposer.org/installer | php -- - $ ./composer.phar install + $ composer install ``` - If you don't have `curl` installed, you can also download `composer.phar` from https://getcomposer.org/ + If you don't have `composer` installed, please download it from https://getcomposer.org/download/ -- Run the tests via `phpunit` and the provided PHPUnit config, like in this example: +- Run the tests using the "test" command shipped in the `composer.json`: ```console - $ ./vendor/bin/phpunit + $ composer test ``` -You can turn on conditional tests with the phpunit.xml file. +You can turn on conditional tests with the `phpunit.xml` file. To do so: - Copy `phpunit.xml.dist` file to `phpunit.xml` @@ -77,24 +47,22 @@ To do so: ## Running Coding Standards Checks -This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding -standards checks, and provides configuration for our selected checks. -`phpcs` is installed by default via Composer. +First, ensure you've installed dependencies via composer, per the previous +section on running tests. -To run checks only: +To run CS checks only: ```console $ composer cs-check ``` -`phpcs` also includes a tool for fixing most CS violations, `phpcbf`: - +To attempt to automatically fix common CS issues: ```console $ composer cs-fix ``` -If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure +If the above fixes any CS issues, please re-run the tests to ensure they pass, and make sure you add and commit the changes after verification. ## Recommended Workflow for Contributions @@ -103,12 +71,12 @@ Your first step is to establish a public repository from which we can pull your work into the master repository. We recommend using [GitHub](https://github.com), as that is where the component is already hosted. -1. Setup a [GitHub account](http://github.com/), if you haven't yet -2. Fork the repository (http://github.com/zendframework/zend-view) +1. Setup a [GitHub account](https://github.com/), if you haven't yet +2. Fork the repository (https://github.com/zendframework/zend-view) 3. Clone the canonical repository locally and enter it. ```console - $ git clone git@github.com:zendframework/zend-view.git + $ git clone git://github.com/zendframework/zend-view.git $ cd zend-view ``` @@ -188,15 +156,7 @@ To send a pull request, you have two options. If using GitHub, you can do the pull request from there. Navigate to your repository, select the branch you just created, and then select the "Pull Request" button in the upper right. Select the user/organization -"zendframework" as the recipient. - -If using your own repository - or even if using GitHub - you can use `git -format-patch` to create a patchset for us to apply; in fact, this is -**recommended** for security-related patches. If you use `format-patch`, please -send the patches as attachments to: - -- zf-devteam@zend.com for patches without security implications -- zf-security@zend.com for security patches +"zendframework" (or whatever the upstream organization is) as the recipient. #### What branch to issue the pull request against? @@ -227,8 +187,3 @@ repository, we suggest doing some cleanup of these branches. ```console $ git push {username} : ``` - - -## Conduct - -Please see our [CONDUCT.md](CONDUCT.md) to understand expected behavior when interacting with others in the project. diff --git a/docs/ISSUE_TEMPLATE.md b/docs/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..39159eb0 --- /dev/null +++ b/docs/ISSUE_TEMPLATE.md @@ -0,0 +1,19 @@ + - [ ] I was not able to find an [open](https://github.com/zendframework/zend-view/issues?q=is%3Aopen) or [closed](https://github.com/zendframework/zend-view/issues?q=is%3Aclosed) issue matching what I'm seeing. + - [ ] This is not a question. (Questions should be asked on [chat](https://zendframework.slack.com/) ([Signup here](https://zendframework-slack.herokuapp.com/)) or our [forums](https://discourse.zendframework.com/).) + +Provide a narrative description of what you are trying to accomplish. + +### Code to reproduce the issue + + + +```php +``` + +### Expected results + + + +### Actual results + + diff --git a/docs/PULL_REQUEST_TEMPLATE.md b/docs/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..f00d90c0 --- /dev/null +++ b/docs/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,25 @@ +Provide a narrative description of what you are trying to accomplish: + +- [ ] Are you fixing a bug? + - [ ] Detail how the bug is invoked currently. + - [ ] Detail the original, incorrect behavior. + - [ ] Detail the new, expected behavior. + - [ ] Base your feature on the `master` branch, and submit against that branch. + - [ ] Add a regression test that demonstrates the bug, and proves the fix. + - [ ] Add a `CHANGELOG.md` entry for the fix. + +- [ ] Are you creating a new feature? + - [ ] Why is the new feature needed? What purpose does it serve? + - [ ] How will users use the new feature? + - [ ] Base your feature on the `develop` branch, and submit against that branch. + - [ ] Add only one feature per pull request; split multiple features over multiple pull requests + - [ ] Add tests for the new feature. + - [ ] Add documentation for the new feature. + - [ ] Add a `CHANGELOG.md` entry for the new feature. + +- [ ] Is this related to quality assurance? + + +- [ ] Is this related to documentation? + + diff --git a/docs/SUPPORT.md b/docs/SUPPORT.md new file mode 100644 index 00000000..3df8b014 --- /dev/null +++ b/docs/SUPPORT.md @@ -0,0 +1,25 @@ +# Getting Support + +Zend Framework offers three support channels: + +- For real-time questions, use our + [chat](https://zendframework-slack.herokuapp.com) +- For detailed questions (e.g., those requiring examples) use our + [forums](https://discourse.zendframework.com/c/questions/components) +- To report issues, use this repository's + [issue tracker](https://github.com/zendframework/zend-view/issues/new) + +**DO NOT** use the issue tracker to ask questions; use chat or the forums for +that. Questions posed to the issue tracker will be closed. + +When reporting an issue, please include the following details: + +- A narrative description of what you are trying to accomplish. +- The minimum code necessary to reproduce the issue. +- The expected results of exercising that code. +- The actual results received. + +We may ask for additional details: what version of the library you are using, +and what PHP version was used to reproduce the issue. + +You may also submit a failing test case as a pull request. diff --git a/doc/book/cookbook/setting-module-specific-layouts.md b/docs/book/cookbook/setting-module-specific-layouts.md similarity index 99% rename from doc/book/cookbook/setting-module-specific-layouts.md rename to docs/book/cookbook/setting-module-specific-layouts.md index 69d5295f..47056522 100644 --- a/doc/book/cookbook/setting-module-specific-layouts.md +++ b/docs/book/cookbook/setting-module-specific-layouts.md @@ -62,7 +62,7 @@ class LayoutListener extends AbstractListenerAggregate if (! $controller) { return; } - + // Extract module name $module = substr($controller, 0, strpos($controller, '\\')); @@ -105,7 +105,7 @@ class Module $templateMapResolver = $application->getServiceManager()->get( 'ViewTemplateMapResolver' ); - + // Create and register layout listener $listener = new LayoutListener($templateMapResolver); $listener->attach($application->getEventManager()); @@ -115,7 +115,7 @@ class Module } ``` -> More informations on registering module-specific listeners can be found in the +> More informations on registering module-specific listeners can be found in the > [documentation of zend-mvc](https://docs.zendframework.com/zend-mvc/examples/#registering-module-specific-listeners). ## Add Template Scripts to the Configuration diff --git a/doc/book/helpers/advanced-usage.md b/docs/book/helpers/advanced-usage.md similarity index 99% rename from doc/book/helpers/advanced-usage.md rename to docs/book/helpers/advanced-usage.md index 642b2033..5b9f003f 100644 --- a/doc/book/helpers/advanced-usage.md +++ b/docs/book/helpers/advanced-usage.md @@ -211,20 +211,20 @@ class SpecialPurpose extends AbstractHelper > > ```php > namespace MyModule\View\Helper; -> +> > use Zend\View\Helper\EscapeHtml; -> +> > class SpecialPurpose > { > private $count = 0; -> +> > private $escaper; -> +> > public function __construct(EscapeHtml $escaper) > { > $this->escaper = $escaper; > } -> +> > public function __invoke() > { > $this->count++; @@ -234,12 +234,12 @@ class SpecialPurpose extends AbstractHelper > } > } > ``` -> +> > Then we would write a factory like the following: -> +> > ```php > use Zend\ServiceManager\AbstractPluginManager; -> +> > class SpecialPurposeFactory > { > public function __invoke($container) @@ -248,7 +248,7 @@ class SpecialPurpose extends AbstractHelper > // zend-servicemanager v3. v2 passes the helper manager directly. > $container = $container->get('ViewHelperManager'); > } -> +> > return new SpecialPurpose($container->get('escapeHtml')); > } > } diff --git a/doc/book/helpers/asset.md b/docs/book/helpers/asset.md similarity index 100% rename from doc/book/helpers/asset.md rename to docs/book/helpers/asset.md diff --git a/doc/book/helpers/base-path.md b/docs/book/helpers/base-path.md similarity index 100% rename from doc/book/helpers/base-path.md rename to docs/book/helpers/base-path.md diff --git a/doc/book/helpers/cycle.md b/docs/book/helpers/cycle.md similarity index 100% rename from doc/book/helpers/cycle.md rename to docs/book/helpers/cycle.md diff --git a/doc/book/helpers/doctype.md b/docs/book/helpers/doctype.md similarity index 100% rename from doc/book/helpers/doctype.md rename to docs/book/helpers/doctype.md diff --git a/doc/book/helpers/escape.md b/docs/book/helpers/escape.md similarity index 98% rename from doc/book/helpers/escape.md rename to docs/book/helpers/escape.md index e38fbb60..fee04f07 100644 --- a/doc/book/helpers/escape.md +++ b/docs/book/helpers/escape.md @@ -38,7 +38,7 @@ echo $this->escapeCss($css); Output: ```css -body\20 \7B \D \A \20 \20 \20 \20 background\2D image\3A \20 url\28 \27 http\3A \2F \2F example\2E com\2F foo\2E jpg\3F \3C \2F style\3E \3C script\3E alert\28 1\29 \3C \2F script\3E \27 \29 \3B \D \A \7D +body\20 \7B \D \A \20 \20 \20 \20 background\2D image\3A \20 url\28 \27 http\3A \2F \2F example\2E com\2F foo\2E jpg\3F \3C \2F style\3E \3C script\3E alert\28 1\29 \3C \2F script\3E \27 \29 \3B \D \A \7D ``` ## EscapeHtml @@ -127,12 +127,12 @@ The default value for all escape helpers is `utf-8`. ## Using Recursion All escape helpers can use recursion for the given values during the escape -operation. This allows the escaping of the datatypes `array` and `object`. +operation. This allows the escaping of the datatypes `array` and `object`. ### Escape an Array To escape an `array`, the second parameter `$recurse` must be use the constant -`RECURSE_ARRAY` of an escape helper: +`RECURSE_ARRAY` of an escape helper: ```php $html = [ @@ -177,7 +177,7 @@ echo $this->escapeHtml($object); // "<h1>Foo</h1>" An escape helper can also use the `toArray()` method of an object. The second parameter `$recurse` must be use the constant `RECURSE_OBJECT` of an escape -helper: +helper: ```php $object = new class { diff --git a/doc/book/helpers/flash-messenger.md b/docs/book/helpers/flash-messenger.md similarity index 98% rename from doc/book/helpers/flash-messenger.md rename to docs/book/helpers/flash-messenger.md index 7a2ef4cb..e574a24b 100644 --- a/doc/book/helpers/flash-messenger.md +++ b/docs/book/helpers/flash-messenger.md @@ -22,7 +22,7 @@ which translates to `default`. // Usable in any of your .phtml files echo $this->flashMessenger()->render('error'); -// Alternatively use one of the pre-defined namespaces +// Alternatively use one of the pre-defined namespaces // (aka: use Zend\Mvc\Controller\Plugin\FlashMessenger;) echo $this->flashMessenger()->render(FlashMessenger::NAMESPACE_SUCCESS); ``` diff --git a/doc/book/helpers/gravatar.md b/docs/book/helpers/gravatar.md similarity index 98% rename from doc/book/helpers/gravatar.md rename to docs/book/helpers/gravatar.md index 3e775735..3de92326 100644 --- a/doc/book/helpers/gravatar.md +++ b/docs/book/helpers/gravatar.md @@ -80,7 +80,7 @@ The Gravatar helper defines the following constants for ratings: - `RATING_R` - `RATING_X` -The helper defines the following constants for the default image: +The helper defines the following constants for the default image: - `DEFAULT_404` - `DEFAULT_MM` @@ -99,7 +99,7 @@ $gravatar = $this->gravatar('email@example.com'); $attr = [ 'class' => 'gravatarcls', ]; -echo $gravatar->setAttributes($attr)->getImgTag(); +echo $gravatar->setAttributes($attr)->getImgTag(); ``` Alternately, you can pass this array as the third argument during helper diff --git a/doc/book/helpers/head-link.md b/docs/book/helpers/head-link.md similarity index 100% rename from doc/book/helpers/head-link.md rename to docs/book/helpers/head-link.md diff --git a/doc/book/helpers/head-meta.md b/docs/book/helpers/head-meta.md similarity index 99% rename from doc/book/helpers/head-meta.md rename to docs/book/helpers/head-meta.md index dbc39380..17510869 100644 --- a/doc/book/helpers/head-meta.md +++ b/docs/book/helpers/head-meta.md @@ -154,4 +154,4 @@ echo $this->headMeta(); // output is: // // -``` +``` diff --git a/doc/book/helpers/head-script.md b/docs/book/helpers/head-script.md similarity index 99% rename from doc/book/helpers/head-script.md rename to docs/book/helpers/head-script.md index 2e615d06..1e4d78d1 100644 --- a/doc/book/helpers/head-script.md +++ b/docs/book/helpers/head-script.md @@ -43,7 +43,7 @@ to use in the element. > use the script tag in an alternative way by setting the type to something > other then `text/javascript`. To prevent such escaping, pass an `noescape` > with a value of true as part of the `$attrs` parameter in the method calls. -> +> > ```php > // jquery template > $template = '
3. Attach the custom strategy in the `ViewEvent`. > > First we have to write the custom renderer: -> +> > ```php > // module/MyModule/View/Renderer/MyRenderer.php > namespace MyModule\View\Renderer; -> +> > // Since we just want to implement the getEncoding() method, we can extend the Zend native renderer > use Zend\View\Renderer\PhpRenderer; -> +> > class MyRenderer extends PhpRenderer > { > /** > * @var string > */ > protected $encoding; -> +> > /** > * Constructor > * @@ -86,7 +86,7 @@ The `HeadStyle` helper is a concrete implementation of the > parent::__construct(); > $this->encoding = $encoding; > } -> +> > /** > * Sets the encoding > * @@ -96,7 +96,7 @@ The `HeadStyle` helper is a concrete implementation of the > { > $this->encoding = $encoding; > } -> +> > /** > * Gets the encoding > * @@ -108,23 +108,23 @@ The `HeadStyle` helper is a concrete implementation of the > } > } > ``` -> +> > Now we make some configuration in the module class: -> +> > ```php > // module/MyModule.php > namespace MyModule; -> +> > use MyModule\View\Renderer\MyRenderer; > use Zend\Mvc\MvcEvent; > use Zend\View\Strategy\PhpRendererStrategy; -> +> > class Module > { > public function getConfig(){/* ... */} -> +> > public function getAutoloaderConfig(){/* ... */} -> +> > public function getServiceConfig() > { > return [ @@ -143,27 +143,27 @@ The `HeadStyle` helper is a concrete implementation of the > ], > ]; > } -> +> > public function onBootstrap(MvcEvent $e) > { > // Register a render event > $app = $e->getParam('application'); > $app->getEventManager()->attach('render', [$this, 'registerMyStrategy'], 100); > } -> +> > public function registerMyStrategy(MvcEvent $e) > { > $app = $e->getTarget(); > $locator = $app->getServiceManager(); > $view = $locator->get('Zend\View\View'); > $myStrategy = $locator->get('MyCustomStrategy'); -> +> > // Attach strategy, which is a listener aggregate, at high priority > $view->getEventManager()->attach($myStrategy, 100); > } > } > ``` -> +> > See the quick start [Creating and Registering Alternate Rendering and Response Strategies](../quick-start.md#creating-and-registering-alternate-rendering-and-response-strategies) > chapter for more information on how to create and register custom strategies > to your view. diff --git a/doc/book/helpers/head-title.md b/docs/book/helpers/head-title.md similarity index 95% rename from doc/book/helpers/head-title.md rename to docs/book/helpers/head-title.md index 1cb27bb3..7cac9d9e 100644 --- a/doc/book/helpers/head-title.md +++ b/docs/book/helpers/head-title.md @@ -19,7 +19,7 @@ explicitly pass a different attach order as the second parameter. ## Basic Usage -Specify a title tag in a view script, e.g. +Specify a title tag in a view script, e.g. `module/Album/view/album/album/index.phtml`: ```php @@ -41,7 +41,7 @@ Output: ### Add the Website Name -A typical usage includes the website name in the title. Add the name and [set a +A typical usage includes the website name in the title. Add the name and [set a separator](#using-separator) in the layout script, e.g. `module/Application/view/layout/layout.phtml` @@ -177,7 +177,7 @@ method. ```php $this->headTitle()->setSeparator(' | '); -echo $this->headTitle()->getSeparator(); // | +echo $this->headTitle()->getSeparator(); // | ``` ### Default Value @@ -195,8 +195,8 @@ $this->headTitle('My albums')->setPrefix('Music: ')->setPostfix('𝄞'); echo $this->headTitle(); // Music: My albums 𝄞 ``` -More descriptions and another example of usage can be found at the -[`Placeholder` helper](placeholder.md#aggregate-content). +More descriptions and another example of usage can be found at the +[`Placeholder` helper](placeholder.md#aggregate-content). ## Render without Tags @@ -204,5 +204,5 @@ In case the title is needed without the `` and `` tags the `renderTitle()` method can be used. ```php -echo $this->headTitle('My albums')->renderTitle(); // My albums +echo $this->headTitle('My albums')->renderTitle(); // My albums ``` diff --git a/doc/book/helpers/html-list.md b/docs/book/helpers/html-list.md similarity index 100% rename from doc/book/helpers/html-list.md rename to docs/book/helpers/html-list.md diff --git a/doc/book/helpers/html-object.md b/docs/book/helpers/html-object.md similarity index 100% rename from doc/book/helpers/html-object.md rename to docs/book/helpers/html-object.md diff --git a/doc/book/helpers/html-tag.md b/docs/book/helpers/html-tag.md similarity index 100% rename from doc/book/helpers/html-tag.md rename to docs/book/helpers/html-tag.md diff --git a/doc/book/helpers/identity.md b/docs/book/helpers/identity.md similarity index 100% rename from doc/book/helpers/identity.md rename to docs/book/helpers/identity.md diff --git a/doc/book/helpers/inline-script.md b/docs/book/helpers/inline-script.md similarity index 100% rename from doc/book/helpers/inline-script.md rename to docs/book/helpers/inline-script.md diff --git a/doc/book/helpers/intro.md b/docs/book/helpers/intro.md similarity index 100% rename from doc/book/helpers/intro.md rename to docs/book/helpers/intro.md diff --git a/doc/book/helpers/json.md b/docs/book/helpers/json.md similarity index 100% rename from doc/book/helpers/json.md rename to docs/book/helpers/json.md diff --git a/doc/book/helpers/layout.md b/docs/book/helpers/layout.md similarity index 97% rename from doc/book/helpers/layout.md rename to docs/book/helpers/layout.md index 3283b22f..203f9451 100644 --- a/doc/book/helpers/layout.md +++ b/docs/book/helpers/layout.md @@ -1,6 +1,6 @@ # Layout -The `Layout` helper is used to get and set the template for the layout or to +The `Layout` helper is used to get and set the template for the layout or to retrieving the root view model. ## Basic Usage @@ -24,7 +24,7 @@ $this->layout()->setTemplate('layout/backend'); ### Set View Variable on Layout Model -The `Layout` helper can also retrieve the view model for the layout (root): +The `Layout` helper can also retrieve the view model for the layout (root): ```php /** @var \Zend\View\Model\ViewModel $rootViewModel */ diff --git a/doc/book/helpers/partial.md b/docs/book/helpers/partial.md similarity index 100% rename from doc/book/helpers/partial.md rename to docs/book/helpers/partial.md diff --git a/doc/book/helpers/placeholder.md b/docs/book/helpers/placeholder.md similarity index 100% rename from doc/book/helpers/placeholder.md rename to docs/book/helpers/placeholder.md diff --git a/doc/book/helpers/url.md b/docs/book/helpers/url.md similarity index 100% rename from doc/book/helpers/url.md rename to docs/book/helpers/url.md diff --git a/doc/book/index.md b/docs/book/index.md similarity index 100% rename from doc/book/index.md rename to docs/book/index.md diff --git a/doc/book/php-renderer.md b/docs/book/php-renderer.md similarity index 100% rename from doc/book/php-renderer.md rename to docs/book/php-renderer.md diff --git a/doc/book/quick-start.md b/docs/book/quick-start.md similarity index 99% rename from doc/book/quick-start.md rename to docs/book/quick-start.md index b7d99797..6f7dfb6e 100644 --- a/doc/book/quick-start.md +++ b/docs/book/quick-start.md @@ -589,7 +589,7 @@ within your application. `Zend\View\Renderer\JsonRenderer`, and populate the Response body with the JSON value returned, as well as set a `Content-Type` header with a value of `application/json`. -- `Zend\View\Strategy\FeedStrategy`. This strategy will return the +- `Zend\View\Strategy\FeedStrategy`. This strategy will return the `Zend\View\Renderer\FeedRenderer`, setting the feed type to either "rss" or "atom", based on what was matched. Its Response strategy will populate the Response body with the generated feed, as well as set a @@ -745,7 +745,7 @@ class MyController extends AbstractActionController $viewModel->setVariable('items', $items); return $viewModel; } - + /** * Lists the items as JSON */ @@ -756,7 +756,7 @@ class MyController extends AbstractActionController $viewModel->setVariable('items', $items); return $viewModel; } - + /** * Lists the items as a Feed */ @@ -770,5 +770,5 @@ class MyController extends AbstractActionController } ``` -Or you could switch the `ViewModel` dynamically based on the "Accept" HTTP Header with the +Or you could switch the `ViewModel` dynamically based on the "Accept" HTTP Header with the [Zend-Mvc-Plugin AcceptableViewModelSelector](https://docs.zendframework.com/zend-mvc/plugins/#acceptableviewmodelselector-plugin). diff --git a/doc/book/view-event.md b/docs/book/view-event.md similarity index 100% rename from doc/book/view-event.md rename to docs/book/view-event.md diff --git a/doc/book/view-scripts.md b/docs/book/view-scripts.md similarity index 100% rename from doc/book/view-scripts.md rename to docs/book/view-scripts.md diff --git a/mkdocs.yml b/mkdocs.yml index 2fda7707..906550af 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,6 +1,6 @@ -docs_dir: doc/book -site_dir: doc/html -pages: +docs_dir: docs/book +site_dir: docs/html +nav: - Home: index.md - "Quick Start": quick-start.md - "Rendering Views": From 54fa5007a55e1f3e6b73b2a37d878215337d6464 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 19:22:27 +0100 Subject: [PATCH 31/39] Update .gitattributes --- .gitattributes | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitattributes b/.gitattributes index 7325c690..e2ae92dd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,9 @@ -/test export-ignore -/vendor export-ignore -.coveralls.yml export-ignore -.gitattributes export-ignore -.gitignore export-ignore -.travis.yml export-ignore -.php_cs export-ignore -phpunit.xml.dist export-ignore +/.coveralls.yml export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/docs/ export-ignore +/mkdocs.yml export-ignore +/phpcs.xml export-ignore +/phpunit.xml.dist export-ignore +/test/ export-ignore From 52170483629b109447f18206d47e200af637004d Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 19:22:41 +0100 Subject: [PATCH 32/39] Update .gitignore - removed all OS/IDE specific files/dirs --- .gitignore | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index d41a109a..a7c6b938 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,8 @@ -.buildpath -.DS_Store -.idea -.project -.settings/ -.*.sw* -.*.un~ -nbproject -doc/html/ -tmp/ -vendor/ -zf-mkdoc-theme/ - -clover.xml -composer.lock -coveralls-upload.json -phpunit.xml +/clover.xml +/composer.lock +/coveralls-upload.json +/docs/html/ +/phpunit.xml +/vendor/ +/zf-mkdoc-theme.tgz +/zf-mkdoc-theme/ From 28bd303d5fdd76f7274a9cd10c1bb24987c20399 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 19:23:03 +0100 Subject: [PATCH 33/39] Update LICENSE.md wording and copyright year --- LICENSE.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index dbb1b49c..4bc22a4a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,16 +1,15 @@ -Copyright (c) 2005-2015, Zend Technologies USA, Inc. - +Copyright (c) 2005-2019, Zend Technologies USA, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -- Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. -- Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. - Neither the name of Zend Technologies USA, Inc. nor the names of its contributors may be used to endorse or promote products derived from this From 09e11131c5b609fc69e33a829acaa261ce4e9a23 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 19:24:37 +0100 Subject: [PATCH 34/39] Update README.md --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a5bbc8d7..aa612c6f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,26 @@ # zend-view [![Build Status](https://secure.travis-ci.org/zendframework/zend-view.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-view) -[![Coverage Status](https://coveralls.io/repos/zendframework/zend-view/badge.svg?branch=master)](https://coveralls.io/r/zendframework/zend-view?branch=master) +[![Coverage Status](https://coveralls.io/repos/github/zendframework/zend-view/badge.svg?branch=master)](https://coveralls.io/github/zendframework/zend-view?branch=master) zend-view provides the “View” layer of the Zend Framework MVC system. It is a multi-tiered system allowing a variety of mechanisms for extension, substitution, and more. -- File issues at https://github.com/zendframework/zend-view/issues -- Documentation is at https://zendframework.github.io/zend-view/ +## Installation + +Run the following to install this library: + +```bash +$ composer require zendframework/zend-view +``` + +## Documentation + +Browse the documentation online at https://docs.zendframework.com/zend-view/ + +## Support + +* [Issues](https://github.com/zendframework/zend-view/issues/) +* [Chat](https://zendframework-slack.herokuapp.com/) +* [Forum](https://discourse.zendframework.com/) From c5426f8a85b57d2ddb9fb4e53d1b4002ddfd1e34 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 19:31:21 +0100 Subject: [PATCH 35/39] Update compose.json - reordered sections to match the template - updated description and keywords - removed redundant sections --- composer.json | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index b9eaf230..58091f1a 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,19 @@ { "name": "zendframework/zend-view", - "description": "provides a system of helpers, output filters, and variable escaping", + "description": "Flexible view layer supporting and providing multiple view layers, helpers, and more", "license": "BSD-3-Clause", "keywords": [ - "zf2", + "zendframework", + "zf", "view" ], - "homepage": "https://github.com/zendframework/zend-view", - "autoload": { - "psr-4": { - "Zend\\View\\": "src/" - } + "support": { + "docs": "https://docs.zendframework.com/zend-view/", + "issues": "https://github.com/zendframework/zend-view/issues", + "source": "https://github.com/zendframework/zend-view", + "rss": "https://github.com/zendframework/zend-view/releases.atom", + "chat": "https://zendframework-slack.herokuapp.com", + "forum": "https://discourse.zendframework.com/c/questions/components" }, "require": { "php": "^5.6 || ^7.0", @@ -58,15 +61,9 @@ "zendframework/zend-servicemanager": "Zend\\ServiceManager component", "zendframework/zend-uri": "Zend\\Uri component" }, - "minimum-stability": "dev", - "prefer-stable": true, - "config": { - "sort-packages": true - }, - "extra": { - "branch-alias": { - "dev-master": "2.11.x-dev", - "dev-develop": "2.12.x-dev" + "autoload": { + "psr-4": { + "Zend\\View\\": "src/" } }, "autoload-dev": { @@ -77,6 +74,15 @@ "ZendTest\\View\\": "test/" } }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "2.11.x-dev", + "dev-develop": "2.12.x-dev" + } + }, "bin": [ "bin/templatemap_generator.php" ], From 56c610a7a3b900a549ea17779f9ec9e848fba731 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 21:57:13 +0100 Subject: [PATCH 36/39] Update Travis CI configuration - remove --prefer-stable flag - use update instead of install for latest deps - add --no-interaction flag to update latest deps - remove sude: false as no longer needed --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 25054a05..ca5cb26d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -sudo: false - language: php cache: @@ -52,8 +50,8 @@ before_install: - if [[ $DEPS == 'latest' ]]; then travis_retry composer require $COMPOSER_ARGS --no-update --dev $LATEST_DEPS_REQUIRE ; fi install: - - if [[ $DEPS == 'lowest' ]]; then travis_retry composer update $COMPOSER_ARGS --prefer-lowest --prefer-stable ; fi - - if [[ $DEPS == 'latest' ]]; then travis_retry composer install ; fi + - if [[ $DEPS == 'lowest' ]]; then travis_retry composer update $COMPOSER_ARGS --prefer-lowest ; fi + - if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi - stty cols 120 && composer show From 328a9aa7541cfb9b82d9bb7297a8716434b08f83 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 22:09:52 +0100 Subject: [PATCH 37/39] release: 2.11.3 readiness --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bdc014c..14c80253 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.11.3 - TBD +## 2.11.3 - 2019-10-11 ### Added From f2b0613313f44801d2ecc8cbe1fb940b0bd5805a Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 11 Oct 2019 22:14:07 +0100 Subject: [PATCH 38/39] Bumped to next dev version (2.11.4) --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14c80253..42570136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 2.11.4 - TBD + +### Added + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## 2.11.3 - 2019-10-11 ### Added From 025ca34a4522187fc51d61fe11a7aee11209bf2a Mon Sep 17 00:00:00 2001 From: frank Date: Tue, 20 Aug 2019 22:28:10 +0200 Subject: [PATCH 39/39] Adds application integration for stand-alone usage to the documentation Related to https://github.com/zendframework/documentation/issues/8 --- .../application-integration/stand-alone.md | 69 +++++++++++++++++++ mkdocs.yml | 2 + 2 files changed, 71 insertions(+) create mode 100644 docs/book/application-integration/stand-alone.md diff --git a/docs/book/application-integration/stand-alone.md b/docs/book/application-integration/stand-alone.md new file mode 100644 index 00000000..a5627ea3 --- /dev/null +++ b/docs/book/application-integration/stand-alone.md @@ -0,0 +1,69 @@ +# Stand-Alone + +The view and all view-helpers of zend-view can also be used stand-alone. + +## The View + +### Setup + +[Create the a renderer, set a resolver for templates](../php-renderer.md#usage) +and initialize the view, e.g. `public/index.php`: + +```php +// Create template resolver +$templateResolver = new Zend\View\Resolver\TemplatePathStack( + [ + 'script_paths' => [__DIR__ . '/../view'], + ] +); + +// Create the renderer +$phpRenderer = new Zend\View\Renderer\PhpRenderer(); +$phpRenderer->setResolver($templateResolver); + +// Initialize the view +$view = new Zend\View\View(); +$view->getEventManager()->attach( + Zend\View\ViewEvent::EVENT_RENDERER, + function () use ($phpRenderer) { + return $phpRenderer; + } +); +``` + +### Create View Script + +[Create a view script](../view-scripts.md), e.g. `view/index.phtml`: + +```php +

+``` + +### Create View Model and render Output + +Extend the script in `public/index.php`, add a view model and render the output: + +```php +// Create view model +$viewModel = new ViewModel(['headline' => 'Example']); +$viewModel->setTemplate('index.phtml'); + +// Render +echo $view->render($viewModel); //

Example

+``` + +## View Helpers + +### Setup + +Create the renderer: + +```php +$renderer = new Zend\View\Renderer\PhpRenderer(); +``` + +### Using Helper + +```php +echo $renderer->doctype(Zend\View\Helper\Doctype::HTML5); // +``` diff --git a/mkdocs.yml b/mkdocs.yml index 906550af..b8b0bf32 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -34,6 +34,8 @@ nav: - "Advanced usage of helpers": helpers/advanced-usage.md - Cookbook: - "Setting module-specific Layouts": cookbook/setting-module-specific-layouts.md + - "Application Integration": + - "Stand-Alone": application-integration/stand-alone.md site_name: zend-view site_description: 'Flexible view layer supporting and providing multiple view layers, helpers, and more.' repo_url: 'https://github.com/zendframework/zend-view'