PHPackages                             vinogradsoft/navigator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vinogradsoft/navigator

ActiveContext

vinogradsoft/navigator
======================

URL generator

1.0.1(2y ago)393PHPPHP &gt;=8.0

Since Oct 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/vinogradsoft/navigator)[ Packagist](https://packagist.org/packages/vinogradsoft/navigator)[ RSS](/packages/vinogradsoft-navigator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

[![Navigator logo](banner.svg)](banner.svg)

**Create reusable applications.**
Open source library.

[![codecov](https://camo.githubusercontent.com/1aa80bf8eecfc5112dea47307ebc36f6d9e6bbe0c42f43d2f1c09b4320f07466/68747470733a2f2f636f6465636f762e696f2f67682f76696e6f67726164736f66742f6e6176696761746f722f67726170682f62616467652e7376673f746f6b656e3d3733504e4e46574c4731)](https://codecov.io/gh/vinogradsoft/navigator)[![](https://camo.githubusercontent.com/231e6bea9f265fd6379e656eec06716656fd3d6439631b6be4316db060d0c253/68747470733a2f2f62616467656e2e6e65742f7374617469632f6c6963656e73652f4d49542f677265656e)](https://camo.githubusercontent.com/231e6bea9f265fd6379e656eec06716656fd3d6439631b6be4316db060d0c253/68747470733a2f2f62616467656e2e6e65742f7374617469632f6c6963656e73652f4d49542f677265656e)

What is Navigator?
------------------

[](#what-is-navigator)

> 👉 Navigator is a url generator. Works with internal application navigation and is able to generate URLs to external resources. Internal navigation is based on named route definitions. Named routes allow you to conveniently create URLs without being tied to a domain or route definition.

General Information
-------------------

[](#general-information)

The library is intended for applications that use the [FastRoute](https://github.com/nikic/FastRoute#fastroute---fast-request-router-for-php) router in their code. FastRoute uses regular expression route definitions, and Navigator creates URLs that match those route definitions.

For code consistency, route definitions are assigned names.

```
   route            route
    name        determination
 /‾‾‾‾‾‾‾\      /‾‾‾‾‾‾‾‾‾‾‾\
'user/view' => '/user/{id:\d+}',

```

This allows URLs to be manipulated without making changes to existing code. For example, to create a URL for a named definition `'user' => '/user/{id:\d+}'`, you could use the following code:

```
/** relative url */
echo $urlBuilder->build('/user', ['id' => 100]); # /user/100

/** absolute url */
echo $urlBuilder->build('/user', ['id' => 100], true); # http://mydomain.ru/user/100
```

If for any reason you need to change the address from `/user/100` to `/employee/100`, you will simply need to change the route setting from `'/user/{id:\d+}'` to `'/employee/{id:\d+}'`. The code above will then create the relative URL `/employee/100` and the absolute URL `http://mydomain.ru/employee/100`.

The `Navigator\UrlBuilder` class object has two methods for generating URLs: `build` and `buildExternal`. The `build`method is used for navigation within the application, and `buildExternal` creates URLs for external resources and can only generate absolute URLs.

Install
-------

[](#install)

To install with composer:

```
php composer require vinogradsoft/navigator "^1.0"

```

Requires PHP 8.0 or newer.

🚀 Quick Start
-------------

[](#-quick-start)

```
