-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Igor Kusmitsch
committed
Sep 24, 2024
1 parent
3e703a5
commit b45712c
Showing
58 changed files
with
435 additions
and
1,229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,79 +12,6 @@ Use composer to add DMS\Filter to your app | |
|
||
## Usage | ||
|
||
### Annotation way | ||
|
||
Your Entity: | ||
|
||
```php | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
//Import Annotations | ||
use DMS\Filter\Rules as Filter; | ||
|
||
class User | ||
{ | ||
|
||
/** | ||
* @Filter\StripTags() | ||
* @Filter\Trim() | ||
* @Filter\StripNewlines() | ||
* | ||
* @var string | ||
*/ | ||
public string $name; | ||
|
||
/** | ||
* @Filter\StripTags() | ||
* @Filter\Trim() | ||
* @Filter\StripNewlines() | ||
* | ||
* @var string | ||
*/ | ||
public string $email; | ||
|
||
} | ||
?> | ||
``` | ||
|
||
Filtering: | ||
|
||
```php | ||
<?php | ||
//Get Doctrine Reader | ||
$reader = new Annotations\AnnotationReader(); | ||
$reader->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 <b>name</b>"; | ||
$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 | ||
|
@@ -115,13 +42,15 @@ Filtering: | |
<?php | ||
//Load AttributeLoader | ||
$loader = new Mapping\Loader\AttributeLoader(); | ||
$this->loader = $loader; | ||
|
||
//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); | ||
$filter = new DMS\Filter\Filter($metadataFactory, $filterLoader); | ||
|
||
|
||
//Get your Entity | ||
|
@@ -130,19 +59,12 @@ Filtering: | |
$user->email = " [email protected]"; | ||
|
||
//Filter you entity | ||
$filter->filter($user); | ||
$filter->filterEntity($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: | ||
|
@@ -157,4 +79,4 @@ Feel free to send pull requests, just follow these guides: | |
|
||
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 | ||
Symfony Validator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="PHPCS Coding Standards for DMS"> | ||
|
||
<arg name="basepath" value="."/> | ||
<arg name="extensions" value="php"/> <!-- which extensions to look for --> | ||
<arg name="parallel" value="80"/> <!-- how many parallel processes to run --> | ||
<arg name="colors"/> | ||
<arg name="cache" value=".phpcs.cache"/> <!-- cache the results and don't commit them --> | ||
<arg value="nps"/> <!-- n = ignore warnings, p = show progress --> | ||
<rule ref="PSR12"/> | ||
|
||
<file>src</file> | ||
<file>tests</file> | ||
|
||
<rule ref="DMS"> | ||
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/> | ||
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/> | ||
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop"/> | ||
</rule> | ||
</ruleset> | ||
|
||
|
||
<exclude-pattern>vendor/*</exclude-pattern> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" verbose="true" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" beStrictAboutChangesToGlobalState="true"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/DMS</directory> | ||
</include> | ||
<report> | ||
<html outputDirectory="tests/_reports/coverage/" lowUpperBound="35" highLowerBound="70"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="DMS Filter Suite"> | ||
<directory>tests/DMS</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<testdoxText outputFile="tests/_reports/testdox/tests.txt"/> | ||
<testdoxHtml outputFile="tests/_reports/testdox/tests.html"/> | ||
</logging> | ||
</phpunit> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" | ||
beStrictAboutCoverageMetadata="true" | ||
beStrictAboutOutputDuringTests="true" | ||
bootstrap="vendor/autoload.php" | ||
cacheDirectory=".phpunit.cache" | ||
colors="true" | ||
displayDetailsOnPhpunitDeprecations="true" | ||
displayDetailsOnTestsThatTriggerDeprecations="true" | ||
displayDetailsOnTestsThatTriggerErrors="true" | ||
displayDetailsOnTestsThatTriggerNotices="true" | ||
displayDetailsOnTestsThatTriggerWarnings="true" | ||
executionOrder="depends,defects" | ||
failOnPhpunitDeprecation="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
requireCoverageMetadata="false" | ||
shortenArraysForExportThreshold="10"> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true"> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</source> | ||
|
||
<logging> | ||
<testdoxHtml outputFile="tests/_reports/testdox.html"/> | ||
</logging> | ||
<coverage includeUncoveredFiles="true" | ||
pathCoverage="false" | ||
ignoreDeprecatedCodeUnits="true" | ||
disableCodeCoverageIgnore="true"> | ||
<report> | ||
<html outputDirectory="tests/_reports/html-coverage" lowUpperBound="50" highLowerBound="90"/> | ||
</report> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.