PHPackages                             retailcrm/url-validator - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. retailcrm/url-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

retailcrm/url-validator
=======================

URL validator for RetailCRM

v1.1.0(2y ago)25.0k5MITPHPPHP &gt;=7.3

Since Aug 16Pushed 2y ago5 watchersCompare

[ Source](https://github.com/retailcrm/url-validator)[ Packagist](https://packagist.org/packages/retailcrm/url-validator)[ Docs](https://www.retailcrm.ru/)[ RSS](/packages/retailcrm-url-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

[![Build Status](https://github.com/retailcrm/url-validator/workflows/CI/badge.svg)](https://github.com/retailcrm/url-validator/actions)[![Coverage](https://camo.githubusercontent.com/3b3f4aab7500e310d41450a070f8af10a3805d631329c92502604639b1dc5d46/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f72657461696c63726d2f75726c2d76616c696461746f722f6d61737465722e7376673f6c6f676f3d636f6465636f76266c6f676f436f6c6f723d7768697465)](https://codecov.io/gh/retailcrm/url-validator)[![Latest stable](https://camo.githubusercontent.com/eb4e528dc6db6380538ff08e24c34f866eee4c895d82f2bf78691a01d3c595d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72657461696c63726d2f75726c2d76616c696461746f722e737667)](https://packagist.org/packages/retailcrm/url-validator)[![PHP from Packagist](https://camo.githubusercontent.com/b8339c26c3afd3ab06d691a4561e961120646c4b8f962724e8c0402d9f5fb774/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72657461696c63726d2f75726c2d76616c696461746f722e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/retailcrm/url-validator)

RetailCRM URL Validator
=======================

[](#retailcrm-url-validator)

This validator will help you validate system URLs in your project using [`symfony/validator`](https://packagist.org/packages/symfony/validator).

Table of contents
=================

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

Requirements
------------

[](#requirements)

- PHP 7.3 and above
- PHP's JSON support
- `symfony/validator`

Installation
------------

[](#installation)

Follow those steps to install the library:

1. Download and install [Composer](https://getcomposer.org/download/) package manager.
2. Install the library from the Packagist by executing this command:

```
composer require retailcrm/url-validator:"^1"
```

3. Include the autoloader if it's not included, or you didn't use Composer before.

```
require 'path/to/vendor/autoload.php';
```

Replace `path/to/vendor/autoload.php` with the correct path to Composer's `autoload.php`.

Usage
-----

[](#usage)

You have to use Symfony Validator to work with this library. Please refer to the [official documentation for the `symfony/validator`](https://symfony.com/doc/current/components/validator.html) to learn how to use it. If you want to use `symfony/validator` with Symfony framework - you should use [this documentation](https://symfony.com/doc/current/validation.html).

After ensuring that you're using `symfony/validator` you can just append the `@CrmUrl()` annotation to the DTO entity field that contains system URL.

After that validator's `validate` call on this DTO will generate the proper violation messages for incorrect URLs.

Here's an example of the DTO (*note:* `@Assert\Url()` is optional):

```
