Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

Ajout de deux classe permettant de genrer des requète REST au sein de l'application

TODO: tester et mettre en place ces requètes dans le core du MVC afin qu'elles soient utilisable simplement et de facon protégé par un fichier de config

TODO: ajouter un plug-in symfony permettant de charger un utilisateur dans les apps a partir de l'authentification multiple

TODO: lire les documentation officielles provenant des 4 plate-formes tranquillement afin de comprendre commet doit on tester ces type d'auth quitte a créé un sous domaine particulier directement hebergé sur gittea
-->Sécuriser le serveur de dev

Emmanuel ROY authored on 02/12/2019 17:33:20
Showing 1 changed files
... ...
@@ -5,22 +5,192 @@ namespace App\Controller;
5 5
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6 6
 use Symfony\Component\Routing\Annotation\Route;
7 7
 use Symfony\Component\HttpFoundation\Request;
8
+use Symfony\Component\HttpFoundation\Session\Session;
8 9
 
9 10
 class LuckyController extends AbstractController
10 11
 {
12
+
13
+    function recursiveObjectToJson($object)
14
+    {
15
+        $json = "";
16
+        var_dump($object);
17
+        echo "Iterating over: " . $object->count() . " values\n";
18
+        $iterator = $object->getIterator();
19
+        while ($iterator->valid()) {
20
+            print_r($iterator->key() . "=" . $iterator->current() . "\n");
21
+            $iterator->next();
22
+        }
23
+        print_r($iterator);
24
+        foreach ($iterator as $key => $value) {
25
+            print_r($key . $value);
26
+            if (is_object($value)) {
27
+                $json .= '{ "text" : "' . $key . ' - ' . get_class($value) . '", "children" : [';
28
+                $json .= $this->recursiveObjectToJson($value);
29
+                $json .= ']}';
30
+            } elseif (is_array($value)) {
31
+                $json .= '{ "text" : "' . $key . '", "children" : [';
32
+                $json .= $this->recursiveObjectToJson($value);
33
+                $json .= ']}';
34
+            } else {
35
+                $json .= '{ "text" : "' . $value . '" }';
36
+            }
37
+        }
38
+        return $json;
39
+    }
40
+
41
+    private function ObjectToJson($object)
42
+    {
43
+        $json = '{
44
+            "core" : {
45
+                "data" : [';
46
+        $json .= $this->recursiveObjectToJson($object);
47
+        $json .= ']}}';
48
+
49
+        return $json;
50
+    }
51
+
52
+    /*it comes from https://www.php.net/manual/en/function.var-dump.php */
53
+    public function dump_debug($input, $collapse = false)
54
+    {
55
+        $recursive = function ($data, $level = 0) use (&$recursive, $collapse) {
56
+            global $argv;
57
+
58
+            $isTerminal = isset($argv);
59
+
60
+            if (!$isTerminal && $level == 0 && !defined("DUMP_DEBUG_SCRIPT")) {
61
+                define("DUMP_DEBUG_SCRIPT", true);
62
+
63
+                echo '<script language="Javascript">function toggleDisplay(id) {';
64
+                echo 'var state = document.getElementById("container"+id).style.display;';
65
+                echo 'document.getElementById("container"+id).style.display = state == "inline" ? "none" : "inline";';
66
+                echo 'document.getElementById("plus"+id).style.display = state == "inline" ? "inline" : "none";';
67
+                echo '}</script>' . "\n";
68
+            }
69
+
70
+            $type = !is_string($data) && is_callable($data) ? "Callable" : ucfirst(gettype($data));
71
+            $type_data = null;
72
+            $type_color = null;
73
+            $type_length = null;
74
+
75
+            switch ($type) {
76
+                case "String":
77
+                    $type_color = "green";
78
+                    $type_length = strlen($data);
79
+                    $type_data = "\"" . htmlentities($data) . "\"";
80
+                    break;
81
+
82
+                case "Double":
83
+                case "Float":
84
+                    $type = "Float";
85
+                    $type_color = "#0099c5";
86
+                    $type_length = strlen($data);
87
+                    $type_data = htmlentities($data);
88
+                    break;
89
+
90
+                case "Integer":
91
+                    $type_color = "red";
92
+                    $type_length = strlen($data);
93
+                    $type_data = htmlentities($data);
94
+                    break;
95
+
96
+                case "Boolean":
97
+                    $type_color = "#92008d";
98
+                    $type_length = strlen($data);
99
+                    $type_data = $data ? "TRUE" : "FALSE";
100
+                    break;
101
+
102
+                case "NULL":
103
+                    $type_length = 0;
104
+                    break;
105
+
106
+                case "Array":
107
+                    $type_length = count($data);
108
+            }
109
+
110
+            if (in_array($type, array("Object", "Array"))) {
111
+                $notEmpty = false;
112
+
113
+                foreach ($data as $key => $value) {
114
+                    if (!$notEmpty) {
115
+                        $notEmpty = true;
116
+
117
+                        if ($isTerminal) {
118
+                            echo $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "\n";
119
+
120
+                        } else {
121
+                            $id = substr(md5(rand() . ":" . $key . ":" . $level), 0, 8);
122
+
123
+                            echo "<a href=\"javascript:toggleDisplay('" . $id . "');\" style=\"text-decoration:none\">";
124
+                            echo "<span style='color:#666666'>" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "</span>";
125
+                            echo "</a>";
126
+                            echo "<span id=\"plus" . $id . "\" style=\"display: " . ($collapse ? "inline" : "none") . ";\">&nbsp;&#10549;</span>";
127
+                            echo "<div id=\"container" . $id . "\" style=\"display: " . ($collapse ? "" : "inline") . ";\">";
128
+                            echo "<br />";
129
+                        }
130
+
131
+                        for ($i = 0; $i <= $level; $i++) {
132
+                            echo $isTerminal ? "|    " : "<span style='color:black'>|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
133
+                        }
134
+
135
+                        echo $isTerminal ? "\n" : "<br />";
136
+                    }
137
+
138
+                    for ($i = 0; $i <= $level; $i++) {
139
+                        echo $isTerminal ? "|    " : "<span style='color:black'>|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
140
+                    }
141
+
142
+                    echo $isTerminal ? "[" . $key . "] => " : "<span style='color:black'>[" . $key . "]&nbsp;=>&nbsp;</span>";
143
+
144
+                    call_user_func($recursive, $value, $level + 1);
145
+                }
146
+
147
+                if ($notEmpty) {
148
+                    for ($i = 0; $i <= $level; $i++) {
149
+                        echo $isTerminal ? "|    " : "<span style='color:black'>|</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
150
+                    }
151
+
152
+                    if (!$isTerminal) {
153
+                        echo "</div>";
154
+                    }
155
+
156
+                } else {
157
+                    echo $isTerminal ?
158
+                        $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "  " :
159
+                        "<span style='color:#666666'>" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "</span>&nbsp;&nbsp;";
160
+                }
161
+
162
+            } else {
163
+                echo $isTerminal ?
164
+                    $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "  " :
165
+                    "<span style='color:#666666'>" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "</span>&nbsp;&nbsp;";
166
+
167
+                if ($type_data != null) {
168
+                    echo $isTerminal ? $type_data : "<span style='color:" . $type_color . "'>" . $type_data . "</span>";
169
+                }
170
+            }
171
+
172
+            echo $isTerminal ? "\n" : "<br />";
173
+        };
174
+
175
+        call_user_func($recursive, $input);
176
+    }
177
+
11 178
     /**
12 179
      * @Route("/syf51", name="homepage")
13 180
      */
14 181
     public function indexAction(Request $request)
15 182
     {
16 183
         print_r("<pre>");
17
-        print_r($this->get('session'));
184
+        $session = $this->var_log($this->get('session'));
185
+        //$session = json_encode($this->get('session'));
186
+        print_r($session);
18 187
         print_r($_COOKIE);
19 188
         print_r($_SESSION);
189
+        print_r("</pre>");
20 190
         $_SESSION['test-user51'] = "user51";
21 191
         // replace this example code with whatever you need
22 192
         return $this->render('default/page.html.twig', [
23
-            'text' => 'homepage',
193
+            'text' => 'homepage', 'json' => $session
24 194
         ]);
25 195
     }
26 196
 
Browse code

Ajout d'une autre application symfony 5.0.99 afin de tester le partage de la variable $_SESSION -->OK

TODO: ajouter un plug-in symfony permettant de charger un utilisateur dans les apps a partir de l'authentification multiple

TODO: lire les documentation officielles provenant des 4 plate-formes tranquillement afin de comprendre commet doit on tester ces type d'auth quitte a créé un sous domaine particulier directement hebergé sur gittea
-->Sécuriser le serveur de dev

Emmanuel ROY authored on 23/11/2019 03:00:32
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,66 @@
1
+<?php
2
+// src/Controller/LuckyController.php
3
+namespace App\Controller;
4
+
5
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
+use Symfony\Component\Routing\Annotation\Route;
7
+use Symfony\Component\HttpFoundation\Request;
8
+
9
+class LuckyController extends AbstractController
10
+{
11
+    /**
12
+     * @Route("/syf51", name="homepage")
13
+     */
14
+    public function indexAction(Request $request)
15
+    {
16
+        print_r("<pre>");
17
+        print_r($this->get('session'));
18
+        print_r($_COOKIE);
19
+        print_r($_SESSION);
20
+        $_SESSION['test-user51'] = "user51";
21
+        // replace this example code with whatever you need
22
+        return $this->render('default/page.html.twig', [
23
+            'text' => 'homepage',
24
+        ]);
25
+    }
26
+
27
+    /**
28
+     * @Route("/syf51/page1", name="page1")
29
+     */
30
+    public function page1Action(Request $request)
31
+    {
32
+        // replace this example code with whatever you need
33
+        return $this->render('default/page.html.twig', [
34
+            'text' => 'page1',
35
+        ]);
36
+    }
37
+
38
+    /**
39
+     * @Route("/syf51/page2", name="page2")
40
+     */
41
+    public function page2Action(Request $request)
42
+    {
43
+        // replace this example code with whatever you need
44
+        return $this->render('default/page.html.twig', [
45
+            'text' => 'page2',
46
+        ]);
47
+    }
48
+
49
+    /**
50
+     * @Route("/syf51/number")
51
+     */
52
+    public function number()
53
+    {
54
+
55
+        print_r("<pre>");
56
+        print_r($this->get('session'));
57
+        print_r($_COOKIE);
58
+        print_r($_SESSION);
59
+
60
+        $number = random_int(0, 100);
61
+
62
+        return $this->render('lucky/number.html.twig', [
63
+            'number' => $number,
64
+        ]);
65
+    }
66
+}
0 67
\ No newline at end of file