Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>private function getValidations() { $validations=[]; $validator=$this-&gt;get("validator"); $metadata=$validator-&gt;getMetadataFor(new your_entity()); $constrainedProperties=$metadata-&gt;getConstrainedProperties(); foreach($constrainedProperties as $constrainedProperty) { $propertyMetadata=$metadata-&gt;getPropertyMetadata($constrainedProperty); $constraints=$propertyMetadata[0]-&gt;constraints; $outputConstraintsCollection=[]; foreach($constraints as $constraint) { $class = new \ReflectionObject($constraint); $constraintName=$class-&gt;getShortName(); $constraintParameter=null; switch ($constraintName) { case "NotBlank": $param="notBlank"; break; case "Type": $param=$constraint-&gt;type; break; case "Length": $param=$constraint-&gt;max; break; } $outputConstraintsCollection[$constraintName]=$param; } $validations[$constrainedProperty]=$outputConstraintsCollection; } return $validations; } </code></pre> <p><strong>Returns:</strong></p> <pre><code>array(13) ( [property1] =&gt; array(4) ( [NotBlank] =&gt; (string) notBlank [NotNull] =&gt; (string) notBlank [Type] =&gt; (string) string [Length] =&gt; (int) 11 ) [property2] =&gt; array(4) ( [NotBlank] =&gt; (string) notBlank [NotNull] =&gt; (string) notBlank [Type] =&gt; (string) string [Length] =&gt; (int) 40 ) .......... ) </code></pre> <p><strong>The returned array can be configured or used to define client side validation rules depending on the client-side validation library/code that you are using</strong></p> <pre><code>$validator=$this-&gt;get("validator"); $metadata=$validator-&gt;getMetadataFor(new yourentity()); </code></pre> <p>The object <code>$metadata</code> now contains all the metadata about validations that concerns your specific entity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload