PHP code example of dms / dms-filter

1. Go to this page and download the library: Download dms/dms-filter 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/ */

    

dms / dms-filter example snippets




namespace App\Entity;

//Import Attributes
use DMS\Filter\Rules as Filter;

class User
{
    #[Filter\StripTags]
    #[Filter\Trim]
    #[Filter\StripNewlines]
    public string $name;

    #[Filter\StripTags]
    #[Filter\Trim]
    #[Filter\StripNewlines]
    public string $email;
}


    //Load AttributeLoader
    $loader = new Mapping\Loader\AttributeLoader();

    //Get a MetadataFactory
    $metadataFactory = new Mapping\ClassMetadataFactory($loader);

    //Get a FilterLoader
    $filterLoader = new \DMS\Filter\Filters\Loader\FilterLoader();

    //Get a Filter
    $filter = new DMS\Filter\Filter($metadataFactory, $filterLoader);


    //Get your Entity
    $user = new App\Entity\User();
    $user->name = "My <b>name</b>";
    $user->email = " [email protected]";

    //Filter you entity
    $filter->filterEntity($user);

    echo $user->name; //"My name"
    echo $user->email; //"[email protected]"