Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Documented the new relativeProtocol option of Url constraint#9278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
javiereguiluz wants to merge3 commits intosymfony:masterfromjaviereguiluz:fix_9266
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletionsreference/constraints/Url.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@ Validates that a value is a valid URL string.
| | - `payload`_ |
| | - `checkDNS`_ |
| | - `dnsMessage`_ |
| | - `relativeProtocol`_ |
+----------------+---------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` |
+----------------+---------------------------------------------------------------------+
Expand DownExpand Up@@ -382,3 +383,77 @@ DNS check failed.
)));
}
}

relativeProtocol
~~~~~~~~~~~~~~~~

**type**: ``boolean`` **default**: ``false``

.. versionadded:: 4.1
The ``relativeProtocol`` option was introduced in Symfony 4.1.

If ``true``, the protocol is considered optional when validating the syntax of
the given URL. This means that both ``http://`` and ``https://`` are valid but
also relative URLs that contain no protocol (e.g. ``//example.com``).

.. configuration-block::

.. code-block:: php-annotations

// src/Entity/Author.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Author
{
/**
* @Assert\Url(
* relativeProtocol = true
* )
*/
protected $bioUrl;
}

.. code-block:: yaml

# config/validator/validation.yaml
App\Entity\Author:
properties:
bioUrl:
- Url: { relativeProtocol: true }

.. code-block:: xml

<!-- config/validator/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

<class name="App\Entity\Author">
<property name="bioUrl">
<constraint name="Url">
<option name="relativeProtocol">true</option>
</constraint>
</property>
</class>
</constraint-mapping>

.. code-block:: php

// src/Entity/Author.php
namespace App\Entity;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;

class Author
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
'relativeProtocol' => true,
)));
}
}

[8]ページ先頭

©2009-2025 Movatter.jp