Skip to content

Commit 5daa0c3

Browse files
author
Ruslan Bekenev
committed
init commit
0 parents  commit 5daa0c3

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
empty readme :( I'll fix this as soon as possible

composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "krydos/json-rules-checker",
3+
"description": "A little library for checking JSON object via rules",
4+
"authors": [
5+
{"name": "Ruslan Bekenev", "email": "ruslan@bekenev.name", "homepage": "https://github.com/KryDos"},
6+
],
7+
"autoload": {
8+
"psr-0": {
9+
"JSONRulesChecker": "src"
10+
}
11+
},
12+
"require": {
13+
"php": ">=5.3.0",
14+
}
15+
}

src/JSONRulesChecker.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace JSONRulesChecker;
3+
4+
class JSONChecker {
5+
6+
public static function checkJSON($json, $rules) {
7+
$result = false;
8+
9+
/**
10+
* go through all rules
11+
*/
12+
foreach($rules as $key => $value) {
13+
14+
if(isset($json->$key)) {
15+
16+
if(gettype($value) == 'array') {
17+
return self::checkJSON($json->$key, $value);
18+
}
19+
else {
20+
$result = true;
21+
}
22+
}
23+
else {
24+
$result = false;
25+
}
26+
}
27+
28+
return $result;
29+
}
30+
}

0 commit comments

Comments
 (0)