Index::readObject()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Catcher\Controller;
4
5
use Drone\Mvc\AbstractionController;
6
use Drone\FileSystem\Shell;
7
8
class Index extends AbstractionController
9
{
10
    public function index()
11
    {
12
        $data = [];
13
14
        $config = include 'module/Catcher/config/user.php';
15
        $folders = $config["output"];
16
17
        $shell = new shell();
18
19
        $_folders = [];
20
21
        foreach ($folders as $folder)
22
        {
23
            $files = $shell->ls($folder);
24
25
            $_files = [];
26
27
            foreach ($files as $file)
28
            {
29
                if (!in_array($file, ['.', '..']))
30
                    $_files[] = $file;
31
            }
32
33
            $_folders[$folder] = $_files;
34
        }
35
36
        $data["folders"] = $_folders;
37
38
        return $data;
39
    }
40
41
    public function read()
42
    {
43
        $data = [];
44
45
        $file = hex2bin($_GET["file"]);
46
47
        $json_object = (file_exists($file)) ? json_decode(file_get_contents($file)) : array();
48
        $data["json"] = $this->object_to_array($json_object);
49
50
        $data["file"] = $file;
51
        $data["_file"] = $_GET["file"];
52
53
        return $data;
54
    }
55
56
    public function readObject()
57
    {
58
        $data = [];
59
60
        $file = hex2bin($_GET["file"]);
61
        $key = $_GET["key"];
62
63
        $json_object = (file_exists($file)) ? json_decode(file_get_contents($file)) : array();
64
        $array_object = $this->object_to_array($json_object);
65
66
        $unserialized = unserialize($array_object[$key]["object"]);
67
68
        $data["file"] = $file;
69
        $data["key"] = $key;
70
        $data["object"] = $unserialized;
71
72
        return $data;
73
    }
74
75
    private function object_to_array($obj)
76
    {
77
        if (is_object($obj))
78
            $obj = (array) $obj;
79
80
        if (is_array($obj))
81
        {
82
            $new = array();
83
84
            foreach($obj as $key => $val)
85
            {
86
                $new[$key] = $this->object_to_array($val);
87
            }
88
        }
89
        else
90
            $new = $obj;
91
92
        return $new;
93
    }
94
}