Download the PHP package vanio/vanio-web-bundle without Composer
On this page you can find all versions of the php package vanio/vanio-web-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vanio/vanio-web-bundle
More information about vanio/vanio-web-bundle
Files in vanio/vanio-web-bundle
Package vanio-web-bundle
Short Description Symfony2 Bundle providing some additional features for website development
License MIT
Homepage https://github.com/vaniocz/vanio-web-bundle
Informations about the package vanio-web-bundle
Web Bundle
Installation
Installation can be done as usually using composer.
composer require vanio/vanio-web-bundle
Next step is to register this bundle as well as bundles it depends on inside your AppKernel
.
Features
Detecting request type
To detect whether current request is master or sub request, special request attribute _request_type
is set.
This logic happens inside Vanio\WebBundle\Request\RequestTypeListener
listener which is not registered by default.
Enable this feature by setting detect_request_type
configuration parameter to true.
Redirecting to Referer
It's quite a common task to redirect user back after certain actions.
This bundle defines a service named vanio_web.request.referer_resolver
which helps you with that.
First it tries to read from _referer
(%vanio_web.referer_parameter%
) query parameter.
When the query parameter is not present then it reads HTTP_REFERER header and tries to match the referring URL against
defined routes. In case of missing header or invalid URL (like URL pointing to a different webpage) fallback path
is used. Since this functionality is mostly used from inside controllers,
it is possible to use Vanio\WebBundle\Request\RefererHelperTrait
which defines one method - redirectToReferer(string $fallbackPath = null): RedirectResponse
.
Flash Messages
Another thing which seems too complicated to me is translating of flash messages.
It's actually very easy but you need a session and a translator.
Two dependencies just to show a translated flash message.
To simplify that there is Vanio\WebBundle\Translation\FlashMessage
value object you can use as an envelope
of the message and pass the message parameters and domain to it. This bundle also replaces translation.extractor.php
service with implementation able to extract messages from FlashMessage
constructor.
But adding a flash message is just half of the problem. You'll also need to display it somewhere in your view and actually translate it yourself.
Validation of required fields
The required
option normally affects only the HTML5 required
attribute.
This bundle allows setting of validate_required: true
to automatically add a NotBlank
constraint to the form.
The default validation message is configurable by setting required_message
.
Form state URL canonization
Due to SEO optimizations and also in situations where having full form state serialized in URL is too long and ugly it
is possible to set canonize: true
in form options. When you submit the form it is then redirected to canonical URL
where all empty form fields (even those equal to empty_data
option) are ommited.
Templating
Generating class name
Sometimes, even just generating a class name of HTML elements can be cumbersome when it depends on some conditions.
Let's use class_name(array $classes): string
Twig function.
You need to pass it an array where key is a class and value is a boolean value indicating whether this class name should
be present.
Checking whether a text is translated
To check whether text is translated you can use is_translated(string $id, string $locale = null)
Twig
function which checks translator's catalogue. The text is considered as translated when it is present in the catalogue
and the translation does not equal to false.
Determining current menu item
To determine whether a current request matches a menu item, use is_current(string $route): bool
Twig function.
The route is considered current when either _route
request attribute equals to the given route or when request
pathinfo starts with the route path and it's delimited by /
.
Testing whether a given object implements a given type
In Twig, there is no possibility how to determine whether a given object implements a given type.
So, for example, it is not possible to determine whether a flash message is just a string or an instance of the added
FlashMessage
class.
And that's why instance of(string $class)
Twig test was added. You can use it like this:
Removing values from arrays
Removing certain values from an array is possible using without(array $array, $values)
Twig filter.
Pass it either a value or an array of values to remove and it will return a new array with the given values being unset.
Removing keys from arrays
Removing certain keys from an array is possible using without(array $array, $keys)
Twig filter.
Pass it either a string or an array of keys to remove and it will return a new array with the given keys being unset.
Removing empty values from arrays
Removing empty values from an array is possible using withoutEmpty(array $array)
Twig filter.
Value is considered empty using the same implementation as empty
Twig test
(''
, false
, null
, []
, or instances of Countable
with zero length).
Replacing based on regular expressions
The builtin replace
Twig filter uses strtr
under the hood but there is no support for replacing based on regular
expressions. So we've implemented regexp_replace(string $string, $pattern, $replacement)
filter.
You can pass it either an array with keys as regular expressions and values as replacements or when the replacement
argument is provided then the pattern can be either a string or an array (keys are ignored).
Converting HTML to plaintext
Have you ever created an HTML e-mail? Providing plaintext alternative manually is tedious
so html_to_text(string $html, array $options = []): string
Twig filter is your friend in such cases.
It uses handy html2text library.
Default Configuration
All versions of vanio-web-bundle with dependencies
symfony/security-bundle Version ^3.0
symfony/translation Version ^3.0
symfony/form Version ^3.0
symfony/twig-bridge Version ^3.0
sensio/framework-extra-bundle Version ^3.0 || ^4.0 || ^5.0
twig/twig Version ^1.24.1 || ^2.0
vanio/stdlib Version ~0.1
vanio/type-parser Version ^0.1
html2text/html2text Version ^4.0.1