File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 1515
1616namespace 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 *
Original file line number Diff line number Diff line change 1515
1616namespace JBZoo \PHPUnit ;
1717
18+ use JBZoo \Data \JSON ;
1819use 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}
You can’t perform that action at this time.
0 commit comments