Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/rdohms/DMS-Filter

Library that offers Input Filtering based on Annotations for use with Objects. Check out 2.dev for 2.0 pre-release.
https://github.com/rdohms/DMS-Filter

annotations filtering hacktoberfest security

Last synced: about 1 month ago
JSON representation

Library that offers Input Filtering based on Annotations for use with Objects. Check out 2.dev for 2.0 pre-release.

Lists

README

        

# DMS Filter Component

This library provides a service that can be used to filter object values based on annotations

[![Latest Stable Version](https://poser.pugx.org/dms/dms-filter/v/stable.png)](https://packagist.org/packages/dms/dms-filter) [![Total Downloads](https://poser.pugx.org/dms/dms-filter/downloads.png)](https://packagist.org/packages/dms/dms-filter) [![Latest Unstable Version](https://poser.pugx.org/dms/dms-filter/v/unstable.png)](https://packagist.org/packages/dms/dms-filter) [![License](https://poser.pugx.org/dms/dms-filter/license.png)](https://packagist.org/packages/dms/dms-filter) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/bb7f41c3-ee7c-4473-8fbf-806453a9e899/mini.png)](https://insight.sensiolabs.com/projects/bb7f41c3-ee7c-4473-8fbf-806453a9e899) [![Build Status](https://travis-ci.org/rdohms/dms-filter.png?branch=master)](https://travis-ci.org/rdohms/dms-filter)![Unit Tests](https://github.com/rdohms/dms-filter/workflows/Unit%20Tests/badge.svg)

## Install

Use composer to add DMS\Filter to your app

`composer require dms/dms-filter`

## Usage

### Annotation way

Your Entity:

```php

```

Filtering:

```php
setEnableParsePhpImports(true);

//Load AnnotationLoader
$loader = new Mapping\Loader\AnnotationLoader($reader);
$this->loader = $loader;

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

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

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

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

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

Full example: https://gist.github.com/1098352

### Attribute way

Your Entity:

```php

```

Filtering:
```php
loader = $loader;

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

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

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

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

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

## Dependencies

This package relies on these external libraries:

* Doctrine Annotations

## Contributing

Feel free to send pull requests, just follow these guides:

* Fork
* Code
* Test
* Just create FilterTestCase and run `phpunit`
* Submit PR

## Credits

This library is inspired by the Symfony 2 Validator component and is meant to work alongside it.

Symfony 2 Validator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator