Download the PHP package mimmi20/mezzio-navigation-laminasviewrenderer without Composer

On this page you can find all versions of the php package mimmi20/mezzio-navigation-laminasviewrenderer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mezzio-navigation-laminasviewrenderer

Mezzio Navigation ViewHelper

Latest Stable Version Latest Unstable Version License

Code Status

codecov Test Coverage Average time to resolve an issue Percentage of issues still open Mutation testing badge Maintainability

Installation

Run

Render the navigation

Calling the view helper for menus in your layout script:

Using multiple navigations

Once the mezzio-navigation module is registered, you can create as many navigation definitions as you wish, and the underlying factories will create navigation containers automatically.

Add the container definitions to your configuration file, e.g. config/autoload/global.php:

Container names have a prefix

There is one important point to know when using mezzio-navigation as a module: The name of the container in your view script must be prefixed with Mezzio\Navigation\, followed by the name of the configuration key. This helps ensure that no naming collisions occur with other services.

The following example demonstrates rendering the navigation menus for the named default, special, and sitemap containers.

View Helpers

The navigation helpers are used for rendering navigational elements from Mimmi20\Mezzio\Navigation\Navigation instances.

There are 5 built-in helpers:

All built-in helpers implements the interface Mezzio\Navigation\LaminasView\View\Helper\Navigation\ViewHelperInterface, which adds integration with laminas-acl or laminas-rbac and laminas-i18n. This interface Mimmi20\Mezzio\Navigation\Helper\Navigation\HelperInterface, which defines the following methods:

Method signature Description
getContainer() : null\|ContainerInterface Retrieve the current navigation container, if any.
hasContainer() : bool Is any navigation container currently registered?
setContainer(ContainerInterface $container) : self Set a navigation container.
getTranslator() : null\|Laminas\I18n\Translator\TranslatorInterface Retrieve the current translator instance, if any.
setTranslator(Laminas\I18n\Translator\TranslatorInterface) : self` Set a translator instance to use with labels.
hasTranslator() : bool Is a translator instance present?
isTranslatorEnabled() : bool Should translation occur? To be true, both the flag enabling translation must be set, and a translator instance present.
setTranslatorEnabled(bool $flag) : self Set the flag indicating whether or not translation should occur.
getAcl() : null\|Laminas\Permissions\Acl\AclInterface Retrieve the current ACL instance, if any.
setAcl(Laminas\Permissions\Acl\AclInterface $acl) : self Set an ACL instance.
hasAcl() : bool Whether or not an ACL instance is present.
getRole() : null\|string\|\Laminas\Permissions\Acl\Role\RoleInterface Retrieve the current ACL role instance, if any.
setRole(string\|Laminas\Permissions\Acl\Role\RoleInterface $acl) : self Set an ACL role instance.
hasRole() : bool Whether or not an ACL role instance is present.
getUseAcl() : bool Whether or not to use ACLs; both the flag must be enabled and an ACL instance present.
setUseAcl(bool $flag) : self Set the flag indicating whether or not to use ACLs.
__toString() Cast the helper to a string value; relies on render().
render() Render the helper to a string.

In addition to the method stubs from the interface, the abstract class also implements the following methods:

Method signature Description
getIndent() : string Retrieve the indentation string to use; default is 4 spaces.
setIndent(string\|int $indent) : self Set the indentation to use. In the case of an integer, this indicates the number of spaces. Indentation can be specified for all but the Sitemap helper.
getMinDepth() : int Retrieve the minimum depth a page must have to be included in output
setMinDepth(null\|int $depth) : self Set the minimum depth a page must have to be included in output; null means no minimum.
getMaxDepth() : int Retrieve the maximum depth a page must have to be included in output
setMaxDepth(null\|int $depth) : self Set the maximum depth a page must have to be included in output; null means no maximum.
getRenderInvisible() : bool Retrieve the flag indicating whether or not to render items marked as invisible; defaults to false.
setRenderInvisible(bool $flag) : self Set the flag indicating whether or not to render items marked as invisible.
__call() : mixed Proxy method calls to the registered container; this allows you to use the helper as if it were a navigation container. See the example below.
findActive(/* ... */) : array Find the deepest active page in the container, using the arguments ContainerInterface $container, int $minDepth = null, int $maxDepth = -1). If depths are not given, the method will use the values retrieved from getMinDepth() and getMaxDepth(). The deepest active page must be between $minDepth and $maxDepth inclusively. Returns an array containing the found page instance (key page) and the depth (key depth) at which the page was found.
htmlify(PageInterface $page) : string Renders an HTML a element based on the give page.
accept(PageInterface $page, bool $recursive = true) : bool Determine if a page should be accepted when iterating containers. This method checks for page visibility and verifies that the helper's role is allowed access to the page's resource and privilege.

If a container is not explicitly set, the helper will create an empty Mimmi20\Mezzio\Navigation\Navigation container when calling $helper->getContainer().

Proxying calls to the navigation container

Navigation view helpers use the magic method __call() to proxy method calls to the navigation container that is registered in the view helper.

The call above will add a page to the container in the Navigation helper.

Translation of labels and titles

The navigation helpers support translation of page labels and titles. You can set a translator of type Laminas\I18n\Translator\TranslatorInterface in the helper using $helper->setTranslator($translator).

If you want to disable translation, use $helper->setTranslatorEnabled(false).

The proxy helper will inject its own translator to the helper it proxies to if the proxied helper doesn't already have a translator.

Sitemaps do not use translation

There is no translation in the sitemap helper, since there are no page labels or titles involved in an XML sitemap.

Integration with ACL

All navigational view helpers support ACLs. An object implementing Laminas\Permissions\Acl\AclInterface can be assigned to a helper instance with $helper->setAcl($acl), and role with $helper->setRole('member') or $helper->setRole(new Laminas\Permissions\Acl\Role\GenericRole('member')). If an ACL is used in the helper, the role in the helper must be allowed by the ACL to access a page's resource and/or have the page's privilege for the page to be included when rendering.

If a page is not accepted by ACL, any descendant page will also be excluded from rendering.

The proxy helper will inject its own ACL and role to the helper it proxies to if the proxied helper doesn't already have any.

The examples below all show how ACL affects rendering.

Navigation setup used in examples

This example shows the setup of a navigation container for a fictional software company.

Notes on the setup:

In addition to the container above, the following router setup is added to the configuration file of the module, e.g. module/MyModule/config/module.config.php

The setup of ACL can be done in a module class, e.g. module/MyModule/Module.php:

Navigation Proxy

The navigation() helper is a proxy helper that relays calls to other navigational helpers. It can be considered an entry point to all navigation-related view tasks.

The Navigation helper finds other helpers that implement Mezzio\Navigation\Helper\Navigation\HelperInterface, which means custom view helpers can also be proxied. This would, however, require that the custom helper path is added to the view.

When proxying to other helpers, the Navigation helper can inject its container, ACL and optionally role, and a translator. This means that you won't have to explicitly set all three in all navigational helpers, nor resort to injecting by means of static methods.

Methods

Method signature Description
findHelper(string $helper, bool $strict = true) : Navigation\HelperInterface Finds the given helper, verifies that it is a navigational helper, and injects the current container, ACL and role instances, and translator, if present. If $strict is true, the method will raise an exception when unable to find a valid helper.
getInjectContainer() : bool Retrieve the flag indicating whether or not to inject the current container into proxied helpers; default is true.
setInjectContainer(bool $flag) : self Set the flag indicating whether or not to inject the current container into proxied helpers.
getInjectAcl() : bool Retrieve the flag indicating whether or not to inject ACL and role instances into proxied helpers; default is true.
setInjectAcl(bool $flag) : self Set the flag indicating whether or not to inject ACL and role instances into proxied helpers.
getInjectTranslator() : bool Retrieve the flag indicating whether or not to inject the current translator instance into proxied helpers; default is true.
setInjectTranslator(bool $flag) : self Set the flag indicating whether or not to inject the current translator instance into proxied helpers.
getDefaultProxy() : string Retrieve the default proxy helper to delegate to when rendering; defaults to menu.
setDefaultProxy(string $helper) : self Set the default proxy helper to delegate to when rendering.
render(ContainerInterface = null) Proxies to the render method of the default proxy.

Breadcrumbs

Breadcrumbs are used for indicating where in a sitemap a user is currently browsing, and are typically rendered like the following:

The breadcrumbs() helper follows the Breadcrumbs Pattern as outlined in the Yahoo! Design Pattern Library, and allows simple customization (minimum/maximum depth, indentation, separator, and whether the last element should be linked), or rendering using a partial view script.

The Breadcrumbs helper finds the deepest active page in a navigation container, and renders an upwards path to the root. For pages, the "activeness" of a page is determined by inspecting the request object, as stated in the section on pages.

The helper sets the minDepth property to 1 by default, meaning breadcrumbs will not be rendered if the deepest active page is a root page. If maxDepth is specified, the helper will stop rendering when at the specified depth (e.g. stop at level 2 even if the deepest active page is on level 3).

Methods in the breadcrumbs helper:

Method signature Description
getSeparator() : string Retrieves the separator string to use between breadcrumbs; default is >.
setSeparator(string $separator) : self Set the separator string to use between breadcrumbs.
getLinkLast() : bool Retrieve the flag indicating whether the last breadcrumb should be rendered as an anchor; defaults to false.
setLinkLast(bool $flag) : self Set the flag indicating whether the last breadcrumb should be rendered as an anchor.
getPartial() : string\|array Retrieve a partial view script that should be used for rendering breadcrumbs. If a partial view script is set, the helper's render() method will use the renderPartial() method. The helper expects the partial to be a string or an array with two elements. If the partial is a string, it denotes the name of the partial script to use. If it is an array, the first element will be used as the name of the partial view script, and the second element is the module where the script is found.
setPartial(string\|array $partial) : self Set the partial view script to use when rendering breadcrumbs; see getPartial() for acceptable values.
renderStraight() The default render method used when no partial view script is present.
renderPartial() Used for rendering using a partial view script.

Basic usage

This example shows how to render breadcrumbs with default settings.

In a view script or layout:

The call above takes advantage of the magic __toString() method, and is equivalent to:

Output:

Specifying indentation

This example shows how to render breadcrumbs with initial indentation.

Rendering with 8 spaces indentation:

Output:

Customize output

This example shows how to customize breadcrumbs output by specifying multiple options.

In a view script or layout:

Output:

Setting minimum depth required to render breadcrumbs:

Output: Nothing, because the deepest active page is not at level 10 or deeper.

Rendering using a partial view script

This example shows how to render customized breadcrumbs using a partial vew script. By calling setPartial(), you can specify a partial view script that will be used when calling render(). When a partial is specified, the renderPartial() method will be called when emitting the breadcrumbs. This method will find the deepest active page and pass an array of pages that leads to the active page to the partial view script.

In a layout:

Contents of module/MyModule/view/my-module/partials/breadcrumbs.phtml:

Output:

Links

The links() helper is used for rendering HTML LINK elements. Links are used for describing document relationships of the currently active page. Read more about links and link types at:

There are two types of relations; forward and reverse, indicated by the kewyords rel and rev. Most methods in the helper will take a $rel param, which must be either rel or rev. Most methods also take a $type param, which is used for specifying the link type (e.g. alternate, start, next, prev, chapter, etc).

Relationships can be added to page objects manually, or found by traversing the container registered in the helper. The method findRelation($page, $rel, $type) will first try to find the given $rel of $type from the $page by calling $page>findRel($type) or $page>findRel($type). If the $page has a relation that can be converted to a page instance, that relation will be used. If the $page instance doesn't have the specified $type, the helper will look for a method in the helper named search$rel$type (e.g. searchRelNext() or searchRevAlternate()). If such a method exists, it will be used for determining the $page's relation by traversing the container.

Not all relations can be determined by traversing the container. These are the relations that will be found by searching:

Allowed relation types

When looking for relations in the page instance ($page->getRel($type) or $page->getRev($type)), the helper accepts the values of type string, array, Traversable, or Mezzio\Navigation\Page\PageInterface:

  • PageInterface instances are used directly.
  • If a string is found, it will be converted to a Mezzio\Navigation\Page\Uri.
  • If an array or Traversable is found, it will be converted to one or several page instances. If the first key is numeric, it will be considered to contain several pages, and each element will be passed to the page factory. If the first key is not numeric, the value will be passed to the page factory directly, and a single page will be returned.

The helper also supports magic methods for finding relations. E.g. to find forward alternate relations, call $helper->findRelAlternate($page), and to find reverse section relations, call $helper->findRevSection($page). Those calls correspond to $helper->findRelation($page, 'rel', 'alternate') and $helper->findRelation($page, 'rev', 'section'), respectively.

To customize which relations should be rendered, the helper uses a render flag. The render flag is an integer value, and will be used in a bitwise and (&) operation against the helper's render constants to determine if the relation that belongs to the render constant should be rendered.

See the example below for more information.

The LinksInterface helper defines the following constants:

The constants from RENDER_ALTERNATE to RENDER_BOOKMARK denote standard HTML link types. RENDER_CUSTOM denotes non-standard relations specified in pages. RENDER_ALL denotes standard and non-standard relations.

Methods in the links helper:

Method signature Description
getRenderFlag() : int Retrieves the render flag; default is RENDER_ALL.
setRenderFlag(int $flag) : self Set the render flag; see examples below.
findAllRelations(PageInterface $page, int $flag = null) : array Finds all relations of all types for a given page.
findRelation(PageInterface $page, string $rel, string $type) : PageInterface\|array\|null Finds all relations of a given type from a given page.
searchRel*(PageInterface $page) : PageInterface\|null Traverses a container to find forward relations to the Start page, the Next page, the Previous page, Chapters, Sections, and Subsections.
searchRev*(PageInterface $page) : PageInterface\|null Traverses a container to find reverse relations to Sections or Subsections.
renderLink(PageInterface $page, string $attrib, string $relation) : string Renders a single link element.

Basic usage

Specify relations in pages

This example shows how to specify relations in pages.

Default rendering of links

This example shows how to render a menu from a container registered in the view helper.

In a view script or layout:

Output:

Specify which relations to render

This example shows how to specify which relations to find and render.

Render only start, next, and prev:

Output:

Render only native link types:

Output:

Render all but chapters:

Output:

Menu

The menu() helper is used for rendering menus from navigation containers. By default, the menu will be rendered using HTML UL and LI tags, but the helper also allows using a partial view script.

Methods in the Menu helper:

Method signature Description
getUlClass() : string Retrieve the CSS class used when rendering ul elements in renderMenu().
setUlClass(string $class) : self Set the CSS class to use when rendering ul elements in renderMenu().
getOnlyActiveBranch() : bool Retrieve the flag specifying whether or not to render only the active branch of a container.
setOnlyActiveBranch(bool $flag) : self Set the flag specifying whether or not to render only the active branch of a container.
getRenderParents() : bool Retrieve the flag specifying whether or not to render parent pages when rendering the active branch of a container.
setRenderParents(bool $flag) : self Set the flag specifying whether or not to render parent pages when rendering the active branch of a container. When set to false, only the deepest active menu will be rendered.
getPartial() : string\|array Retrieve a partial view script that should be used for rendering breadcrumbs. If a partial view script is set, the helper's render() method will use the renderPartial() method. The helper expects the partial to be a string or an array with two elements. If the partial is a string, it denotes the name of the partial script to use. If it is an array, the first element will be used as the name of the partial view script, and the second element is the module where the script is found.
setPartial(string\|array $partial) : self Set the partial view script to use when rendering breadcrumbs; see getPartial() for acceptable values.
htmlify(/* ... */) : string Overrides the method from the abstract class, with the argument list PageInterface $page, bool $escapeLabel = true, bool $addClassToListItem = false. Returns span elements if the page has no href.
renderMenu(ContainerInterface $container = null, $options = []) : string Default rendering method; renders a container as an HTML UL list. If $container is not given, the container registered in the helper will be rendered. $options is used for overriding options specified temporarily without resetting the values in the helper instance; if none are set, those already provided to the helper will be used. Options are an associative array where each key corresponds to an option in the helper. See the table below for recognized options.
renderPartial(ContainerInterface $container = null, string\|array $partial = null) : string Used for rendering the menu using a partial view script.
renderSubMenu(/* ... */) : string Renders the deepest menu level of a container's active branch. Accepts the arguments ContainerInterface $container, string $ulClass = null, string\|int $indent = null (an integer value indicates number of spaces to use), string $liActiveClass = null.

The following are options recognized by the renderMenu() method:

Option name Description
indent Indentation. Expects a string or an int value.
minDepth Minimum depth. Expects an int or null (no minimum depth).
maxDepth Maximum depth. Expects an int or null (no maximum depth).
ulClass CSS class for ul element. Expects a string.
onlyActiveBranch Whether only active branch should be rendered. Expects a boolean value.
renderParents Whether parents should be rendered if only rendering active branch. Expects a boolean value.

Basic usage

This example shows how to render a menu from a container registered/found in the view helper. Notice how pages are filtered out based on visibility and ACL.

In a view script or layout:

Or:

Output:

Calling renderMenu() directly

This example shows how to render a menu that is not registered in the view helper by calling renderMenu() directly and specifying options.

Output:

Rendering the deepest active menu

This example shows how renderSubMenu() will render the deepest sub menu of the active branch.

Calling renderSubMenu($container, $ulClass, $indent) is equivalent to calling renderMenu($container, $options) with the following options:

Usage of renderSubMenu method:

The output will be the same if 'FAQ' or 'Foo Server' is active:

Rendering with maximum depth

Output:

Rendering with minimum depth

Output:

Rendering only the active branch

Output:

Rendering only the active branch with minimum depth

Output:

Rendering only the active branch with maximum depth

Output:

Rendering only the active branch with maximum depth and no parents

Output:

Rendering a custom menu using a partial view script

This example shows how to render a custom menu using a partial view script. By calling setPartial(), you can specify a partial view script that will be used when calling render(); when a partial is specified, that method will proxy to the renderPartial() method.

The renderPartial() method will assign the container to the view with the key container.

In a layout:

In module/MyModule/view/my-module/partials/menu.phtml:

Output:

Using additional parameters in partial view scripts

Starting with version 2.6.0, you can assign custom variables to a partial script.

In a layout:

In module/MyModule/view/my-module/partials/menu.phtml:

Output:

Using menu options in partial view scripts

In a layout:

In module/MyModule/view/my-module/partials/menu.phtml:

Output:

Using ACLs with partial view scripts

If you want to use an ACL within your partial view script, then you will have to check the access to a page manually.

In module/MyModule/view/my-module/partials/menu.phtml:

View Helper - Sitemap

The sitemap() helper is used for generating XML sitemaps, as defined by the Sitemaps XML format. Read more about Sitemaps on Wikipedia.

By default, the sitemap helper uses sitemap validators to validate each element that is rendered. This can be disabled by calling $helper->setUseSitemapValidators(false).

Sitemap XML elements

Element Type Description
loc string Absolute URL to page. An absolute URL will be generated by the helper.
lastmod string The date of last modification of the file, in W3C Datetime format. This time portion can be omitted if desired, and only use YYYY-MM-DD. The helper will try to retrieve the lastmod value from the page's custom property lastmod if it is set in the page. If the value is not a valid date, it is ignored.
changefreq string How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page. Valid values are: "always", "hourly", "daily", "weekly", "monthly", "yearly", and "never". The helper will try to retrieve the changefreq value from the page's custom property changefreq if it is set in the page. If the value is not valid, it is ignored.
priority float The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. The helper will try to retrieve the priority value from the page's custom property priority if it is set in the page. If the value is not valid, it is ignored.

Validation only when enabled

If you disable sitemap validators, the custom properties (see table) are not validated at all.

The sitemap helper also supports Sitemap XSD Schema validation of the generated sitemap. This is disabled by default, since it will require a request to the schema file. It can be enabled with $helper->setUseSchemaValidation(true).

Methods in the sitemap helper:

Method signature Description
getFormatOutput() : bool Retrieve the flag indicating whether or not generated XML should be formatted. Default is false.
setFormatOutput(bool $flag) : self Set the flag indicating whether or not generated XML should be formatted. The flag corresponds to the the formatOutput property of the native DOMDocument class. Read more in the DOMDocument documentation.
getUseXmlDeclaration() : bool Retrieve the flag indicating whether or not to emit the XML declaration when rendering; defaults to true.
setUseXmlDeclaration(bool $flag) : self Set the flag indicating whether or not to emit the XML declaration when rendering.
getUseSitemapValidators() : bool Retrieve the flag indicating whether or not sitemap validators should be used when generating the DOM; default is true.
setUseSitemapValidators(bool $flag) : self Set the flag indicating whether or not sitemap validators should be used when generating the DOM.
getUseSchemaValidation() : bool Retrieve the flag indicating whether or not the helper should use XML schema validation when generating the DOM; default is false.
setUseSchemaValidation(bool $flag) : self Set the flag indicating whether or not the helper should use XML schema validation when generating the DOM.
getServerUrl() : string Retrieve the server URL to prepend to non-absolute URIs via the url() method; if none is present, it will be determined by the helper.
setServerUrl(string $url) : self Set the base server URL to prepend to non-absolute URIs.
url(PageInterface $page) : string Generate an absolute URL for the provided page.
getDomSitemap(ContainerInterface = null) : DOMDocument Generates a DOMDocument sitemap representation from the given container.

Basic usage

This example shows how to render an XML sitemap based on the setup we did further up.

Notice how pages that are invisible or pages with ACL roles incompatible with the view helper are filtered out:

Rendering using no ACL role

Render the sitemap using no ACL role (should filter out /community/account):

Output:

Rendering using a maximum depth

Render the sitemap using a maximum depth of 1.

Output:

UTF-8 encoding used by default

By default, laminas-view uses UTF-8 as its default encoding. If you want to use another encoding with Sitemap, you will have do three things:

  1. Create a custom renderer and implement a getEncoding() method.
  2. Create a custom rendering strategy that will return an instance of your custom renderer.
  3. Attach the custom strategy in the ViewEvent.

See the example from the HeadStyle documentation to see how you can achieve this.

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.


All versions of mezzio-navigation-laminasviewrenderer with dependencies

PHP Build Version
Package Version
Requires php Version ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
ext-mbstring Version *
laminas/laminas-stdlib Version ^3.19.0
laminas/laminas-view Version ^2.35.0
mezzio/mezzio-helpers Version ^5.16.0
mezzio/mezzio-laminasviewrenderer Version ^2.15.1
mimmi20/laminasviewrenderer-helper-partialrenderer Version ^2.0.3
mimmi20/mezzio-navigation Version ^3.0.7
mimmi20/navigation-helper-acceptpage Version ^2.1.4
mimmi20/navigation-helper-containerparser Version ^4.0.4
mimmi20/navigation-helper-findactive Version ^2.1.4
mimmi20/navigation-helper-findfromproperty Version ^2.1.5
mimmi20/navigation-helper-findroot Version ^2.1.4
mimmi20/navigation-helper-htmlify Version ^4.0.4
psr/container Version ^1.1.2 || ^2.0.2
psr/log Version ^3.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mimmi20/mezzio-navigation-laminasviewrenderer contains the following files

Loading the files please wait ....