vstelmakh / url-highlight-symfony-bundle
Symfony bundle for url highlight library
Package info
github.com/vstelmakh/url-highlight-symfony-bundle
Type:symfony-bundle
pkg:composer/vstelmakh/url-highlight-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
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Warning
This package is no longer maintained and only supports URL Highlight v3. Use URL Highlight directly and follow its documentation.
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.yamlconfig
# 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.