Skip to content

Commit df81c38

Browse files
author
SmetDenis
committed
data filter
1 parent bceac1a commit df81c38

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
}
2626
],
2727
"require" : {
28-
"php" : ">=5.3.10"
28+
"php" : ">=5.3.10",
29+
"jbzoo/data" : "^1.0"
2930
},
3031
"require-dev" : {
3132
"jbzoo/phpunit" : "^1.5"

src/Filter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
namespace JBZoo\Utils;
1717

18+
use JBZoo\Data\Data;
19+
use JBZoo\Data\JSON;
20+
1821
/**
1922
* Class Filter
2023
* @package JBZoo\Utils
@@ -355,6 +358,19 @@ public static function esc($string)
355358
return Str::esc($string);
356359
}
357360

361+
/**
362+
* @param array $data
363+
* @return JSON
364+
*/
365+
public static function data($data)
366+
{
367+
if ($data instanceof Data) {
368+
return $data;
369+
}
370+
371+
return new JSON($data);
372+
}
373+
358374
/**
359375
* RAW placeholder
360376
*

tests/FilterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace JBZoo\PHPUnit;
1717

18+
use JBZoo\Data\JSON;
1819
use JBZoo\Utils\Filter;
1920

2021
/**
@@ -362,4 +363,17 @@ public function tstStripQuotes()
362363
isSame("'qwerty\"", Filter::stripQuotes('\'qwerty"'));
363364
isSame("\"qwerty'", Filter::stripQuotes('"qwerty\''));
364365
}
366+
367+
public function testData()
368+
{
369+
$data = array(
370+
'key' => 'value',
371+
);
372+
373+
$obj = new JSON($data);
374+
375+
isSame($obj, Filter::data($obj));
376+
isSame($data, (array)Filter::data($obj));
377+
isSame($data, (array)Filter::data($data));
378+
}
365379
}

0 commit comments

Comments
 (0)