-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
137 lines (112 loc) · 2.22 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Model\Attributes\ExampleA\CopyFile;
use Model\Attributes\ExampleB\AnotherThing;
/**
* @test
*/
function testA(): void
{
$dir = "./php/Attributes/ExampleA";
$file = "test.html";
if ( file_exists($dir . "/" . $file) )
{
shell_exec("rm $dir/$file");
}
(new Tests\ATest())->canExecuteAction(new CopyFile($file, $dir));
}
/**
* @test
*/
function testB(): void
{
(new Tests\BTest())->canDumpAttrData(new ReflectionClass(AnotherThing::class));
}
/**
* @test
*/
function canAJAX(): void
{
function getInput(): array
{
$input = file_get_contents("php://input");
$data = json_decode($input, true);
return $data;
}
$r1 = [
"status" => 200,
"message" => "Sucesso",
"data" => [
"name" => $_POST["name"],
"phone" => $_POST["phone"]
]
];
$r2 = [
'statusCode' => 200,
'result' => getInput()
];
$r3 = [
'name' => "Cassiano",
'phone' => "(51) 9 9359-6778"
];
print json_encode($r3);
}
/**
* @test
*/
function canCreatePhar(): mixed
{
$context = stream_context_create(
[
"phar" => [
[ "compress" => Phar::GZ ],
[ "metadata" => ["user" => "cellog"] ]
]
]
);
file_put_contents("phar://./test.txt", "This is a test", 0, $context);
}
/**
* @test
*/
function canReadFile(): void
{
function getLines($file): Generator
{
$stream = fopen($file, "r");
try
{
while ( $line = fgets($stream) )
{
yield $line;
}
}
finally
{
fclose($stream);
}
}
$lines = "";
foreach ( getLines("index.php") as $n => $line )
{
if ( $n == 1 )
{
var_dump($n, $line);
}
$lines .= $line;
}
print $lines;
}
/**
*
*/
function index(): void
{
ini_set("display_errors", true);
ini_set("display_startup_errors", true);
error_reporting(E_ALL);
setlocale(LC_ALL, "");
print PHP_SAPI;
phpinfo();
}
echo (new Tests\TwigTest())->__toString();