forked from Symfomany/poo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.php
executable file
·262 lines (192 loc) · 5.4 KB
/
app.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
require_once __DIR__.'/vendor/autoload.php';
//Use Symfony2 Component
use Command\GreatCommand;
use Symfony\Component\Console\Application;
/**
* Another Component
*/
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
/**
* Debug
*/
//use debug SYmfony 2
use Symfony\Component\Debug\Debug;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
// Use Finder Symfony 2
use Symfony\Component\Finder\Finder;
/**
* Session
*/
use Symfony\Component\HttpFoundation\Session\Session;
/**
* YAML
*/
use Symfony\Component\Yaml\Parser;
/**
* Processing
*/
use Symfony\Component\Process\Process;
/**
* Injection des dépendances
*/
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Config Component
*/
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/**
* Use log for tracing app
*/
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
/**
* Use StopWatch SYmfony2
*/
use Symfony\Component\Stopwatch\Stopwatch;
/**
* Using CSS Selector
*/
use Symfony\Component\CssSelector\CssSelector;
/**
* Using DOMCrawler
*/
use Symfony\Component\DomCrawler\Crawler;
// Initialize Debugging by SYmfony 2...
Debug::enable();
ErrorHandler::register();
ExceptionHandler::register();
$stopwatch = new Stopwatch();
$stopwatch->start('go');
/**
* Using Session
*/
$session = new Session();
$session->start();
// set and get session attributes
$nb = (int)$session->get('nb');
$nb = $nb + 1;
$session->set('nb', $nb);
$nbnew = $session->get('nb');
var_dump($nbnew);
/**
* Use Log
*/
// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('logs/dev.log', Logger::WARNING));
// add records to the log
$log->addWarning('Coucou');
$log->addError('3WA Powaaa!!!');
/**
* Injecting classes
*/
$container = new ContainerBuilder();
$container
//add User Object
->register('user', "App\User")
->addArgument('Julien')
->addArgument('Boyer');
$container
//add Administrateur Object
->register('administrateur', "App\Administrateur")
->addArgument('Djamchid')
->addArgument('Dallili')
->addArgument('Maison 3WA')
->addArgument('Directeur et Entrepreneur')
->addArgument('http://www.google.fr')
->addArgument(4);
/**
* Using YAML File to load services
*/
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config/'));
$loader->load('services.yml');
$objectuser = $container->get('user');
$objectadmin = $container->get('administrateur');
$objectelodie = $container->get('user.elodie');
var_dump($objectuser);
var_dump($objectadmin);
var_dump($objectelodie);
/**
* Find img
*/
$finder = new Finder();
$finder->files()->in('./img/');
echo "<ul>";
foreach ($finder as $file) {
// Print the absolute path
echo "<li>".$file->getRealpath() . " => " . $file->getRelativePathname()."</li>";
}
echo "</ul>";
/**
* Sub Process
*/
$process = new Process('ls -al');
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
var_dump($process->getOutput());
$process = new Process('cd img && ls -al');
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
var_dump($process->getOutput());
/**
* Parse in YAML
*/
$yaml = new Parser();
$configuration = $yaml->parse(file_get_contents('config/app.yml'));
var_dump($configuration);
/**
* Print HTML DOM
*/
echo "<h3> li numéro 2 dans les images du Finder img/ </h3>";
//descendant-or-self::*/*[name() = 'ul' and (position() = 1)]
$xpathelement = CssSelector::toXPath('ul > li:nth-child(1)');
print $xpathelement;
// example 1: for everything with an id
//$elements = $xpath->query("//*[@id]");
$url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"];
$url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
$url .= $_SERVER["REQUEST_URI"];
$crawler = new Crawler($url);
$crawler = $crawler->filterXPath($xpathelement);
foreach ($crawler as $domElement) {
var_dump($domElement->nodeName);
}
$event = $stopwatch->stop('go');
echo "<h3>Metrix de l'applicaton</h3>";
echo "<code'>";
echo "<p>Category: ".$event->getCategory()." </p>"; // Returns the category the event was started in
echo "<p>Origin: ".$event->getOrigin()."ms. </p>"; // Returns the event start time in milliseconds
echo "<p>Debut: ".$event->getStartTime()."ms. </p>"; // Returns the start time of the very first period
echo "<p>Fin: ".$event->getEndTime()."ms. </p>"; // Returns the end time of the very last period
echo "<p>Duration: ".$event->getDuration()."ms. </p>"; // Returns the event duration, including all periods
echo "<p>Memoire: ".$event->getMemory()."Mb. </p>"; // Returns the max memory usage of all periods
echo "</code>";
/**
* Using Filesystem
*/
/*
$fs = new Filesystem();
try {
$fs->mkdir('images/produits/'.mt_rand());
} catch (IOExceptionInterface $e) {
echo "An error occurred while creating your directory at ".$e->getPath();
}
// set modification time to the current timestamp
$fs->touch('message.txt');
*/
/**
* Console Component Symfony 2
*/
$application = new Application();
$application->add(new GreatCommand());
$application->run();