Download the PHP package ali-translator/url-template without Composer
On this page you can find all versions of the php package ali-translator/url-template. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ali-translator/url-template
More information about ali-translator/url-template
Files in ali-translator/url-template
Package url-template
Short Description Helping on work with template url, example: "{country}.example.com/{language}/{city}"
License MIT
Homepage https://sli.su/
Informations about the package url-template
Url Template
Helping on work with url by their "base" template.
For example, base structure of you project url was "gb.example.com/en/london/".
In this example you template url has next parameters: "country","language" and "city".
Lets create for this example temple: "{country}.example.com/{language}/{city}"
Installation
Code examle:
Warning: be careful with some free regular expressions, as for language '[a-z]{2}', will be better '(en|de|ua)'
Optionality default values
You may set optionality default value of parameter. For this you must set callable argument for default value.
You optionality parameter must be depending only from required argument.
Example of use:
Parameter decorators
Sometimes you need some decoration for you parameters in url.
For example, if you want next path template to be "/{country}-{language}/", and you decide to hide default language.
In this case, without decorators, you get the following compiled url :"/country-/"
Excessive character "-" looks bad.
You can use Decorators to solve this problem.
Decorator - class which implement "ParameterDecoratorInterface".
Example of use:
For correct decorator works - use array on requirements, with available values, not regular expression.
Validate ParsedTemplate object
Additional features
- also you may use templates, where in one "url namespace" placed few parameters, as host "{country}-{language}-{currency}.test.com" and path "/{country}-{language}/"
- If you need only compile "host url" or "path url"
- If you need skip from url only some of default parameters - you may set array with parameters name for parameter
$hideDefaultParametersFromUrl
ofUrlTemplateConfig
class -
If you have an optional parameter that depends on another parameter, and this another parameter was in another part of the url(for example the optional parameter is in the "path url part", and it depends on the parameter in the "host url part"), then there can be a problem when you need to process relative url, without the host.
To be able to leave this possibility, you need to pass a value to the function of determining the optional parameter: - For creating new
UrlTemplateConfig
by existed:
Tests
In packet exist docker-compose file, with environment for testing.