Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Filter] Added new Filters: Int, Float and Boolean

  • Loading branch information...
commit fcffe487ecf6bbc8bbb4a81439ecb6ddc5aa0075 1 parent 1892ca3
@rdohms authored
Showing with 76 additions and 1 deletion.
  1. +1 −1  README.md
  2. +23 −0 Rules/Boolean.php
  3. +28 −0 Rules/Float.php
  4. +24 −0 Rules/Int.php
View
2  README.md
@@ -18,7 +18,7 @@ This library provides a service that can be used to filter object values based o
$metadataFactory = new Mapping\ClassMetadataFactory($loader);
//Get a Filter
- $filter = new Filter($metadataFactory);
+ $filter = new DMS\Filter\Filter($metadataFactory);
//Filter object
$filter->filter($object);
View
23 Rules/Boolean.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace DMS\Filter\Rules;
+
+/**
+ * Boolean Rule
+ *
+ * @package DMS
+ * @subpackage Filter
+ *
+ * @Annotation
+ */
+class Boolean extends Rule
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function applyFilter($value)
+ {
+ return (boolean) $value;
+ }
+
+}
View
28 Rules/Float.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace DMS\Filter\Rules;
+
+/**
+ * Float Rule
+ * Converts content into a Float
+ *
+ * @package DMS
+ * @subpackage Filter
+ *
+ * @Annotation
+ */
+class Float extends Rule
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function applyFilter($value)
+ {
+ if (is_array($value) || is_object($value)) {
+ return null;
+ }
+
+ return floatval($value);
+ }
+
+}
View
24 Rules/Int.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace DMS\Filter\Rules;
+
+/**
+ * Int Rule
+ * Converts content into an Int
+ *
+ * @package DMS
+ * @subpackage Filter
+ *
+ * @Annotation
+ */
+class Int extends Rule
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function applyFilter($value)
+ {
+ return (int) ((string) $value);
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.