vstelmakh / url-highlight-symfony-bundle
Symfony bundle for url highlight library
Installs: 3 170
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1 || ^8
- symfony/config: >=2.7 <6
- symfony/dependency-injection: >=2.7 <6
- symfony/http-kernel: >=2.7 <6
- symfony/yaml: >=2.7 <6
- vstelmakh/url-highlight: ^3
- vstelmakh/url-highlight-twig-extension: ^3
Requires (Dev)
- phpstan/phpstan: ^0.12.3
- phpunit/phpunit: >=7.5.3 <10
- squizlabs/php_codesniffer: ^3.5
- vstelmakh/covelyzer: ^0.1.0
README
Symfony bundle for Url highlight library.
Supported Symfony versions: ^2.7
, ^3
, ^4
, ^5
.
Installation
Install the latest version with:
$ composer require vstelmakh/url-highlight-symfony-bundle
Setup
If your application is using Symfony Flex - you are ready to go, skip next steps.
Enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php return [ // ... VStelmakh\UrlHighlightSymfonyBundle\UrlHighlightBundle::class => ['all' => true], ];
Usage
Bundle provide url highlight service which available via autowire or directly from container:
<?php use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use VStelmakh\UrlHighlight\UrlHighlight; class ExampleController extends AbstractController { public function autowire(UrlHighlight $urlHighlight) { // do your stuff } public function fromContainer() { /** @var UrlHighlight $urlHighlight */ $urlHighlight = $this->container->get('vstelmakh.url_highlight'); } }
Additionally urls_to_html
filter available in templates:
{{ 'Basic example http://example.com'|urls_to_html }} {# output: Basic example <a href="http://example.com">http://example.com</a> #}
More details see usage in Twig url highlight repository.
Configuration
Works out of the box with default configuration:
url_highlight: validator: ~ highlighter: ~ encoder: ~
If you need to change configuration add desired options to your parameters.yaml
or create separate config: config/packages/url_highlight.yaml
.
More information about configuration options could be found in Url highlight library.
Example to define validator to not match urls without scheme
- Define validator service. Use bundled with Url highlight library or create your own implementation
of
VStelmakh\UrlHighlight\Validator\ValidatorInterface
:
# config/services.yaml services: ... VStelmakh\UrlHighlight\Validator\Validator: arguments: [false]
- Provide service id in
url_highlight.yaml
config
# config/packages/url_highlight.yaml url_highlight: validator: VStelmakh\UrlHighlight\Validator\Validator
Credits
Volodymyr Stelmakh
Licensed under the MIT License. See LICENSE for more information.