PHP code example of retailcrm / url-validator

1. Go to this page and download the library: Download retailcrm/url-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

retailcrm / url-validator example snippets






namespace App\Dto;

use Symfony\Component\Validator\Constraints as Assert;
use RetailCrm\Validator\CrmUrl;

class Connection
{
    /**
     * @var string
     * 
     * @Assert\NotBlank()
     * @Assert\Url()
     * @CrmUrl()
     */
    public $apiUrl;
}



namespace App;

use Symfony\Component\Validator\Constraints as Assert;
use RetailCrm\Validator\CrmUrl;

class Connection
{
    /**
     * @var string
     *
     * @Assert\NotBlank()
     * @Assert\Url()
     * @CrmUrl()
     */
    public $apiUrl;

    public function __construct(string $apiUrl)
    {
        $this->apiUrl = $apiUrl;
    }
}

namespace App;

// We assume that `app.php` is stored within a directory that is being autoloaded by Composer.
notationMapping(true)
    ->addDefaultDoctrineAnnotationReader()
    ->getValidator();
$violations = $validator->validate(new Connection('https://test.retailcrm.pro'));

if (0 !== count($violations)) {
    foreach ($violations as $violation) {
        echo $violation->getMessage();
    }
}