This repository was archived by the owner on Jun 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
72 lines (47 loc) · 1.53 KB
/
index.php
File metadata and controls
72 lines (47 loc) · 1.53 KB
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
<?php
require_once __DIR__.'/silex.phar';
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$app->register(new Silex\Extension\TwigExtension(), array(
'twig.path' => __DIR__.'/views',
'twig.class_path' => __DIR__.'/vendor/twig/lib',
));
$app->get('/', function () use ($app) {
return $app['twig']->render('home.twig', array(
'title' => 'Generador aleatorio',
));
});
$app->get('/random', function () use ($app) {
$request = $app['request'];
$from = $request->get('Desde');
$to = $request->get('Hasta');
$howmany = $request->get('Cuantos');
if ((( $to-$from) < ($howmany - 1 )))
{
return $app['twig']->render('error.twig', array(
'title' => 'Error - Mal - Wrong!',
'error' =>'Con estos parámetros, no se puede ejecutar la tarea, alma de Dios. '
));
}
$results = array();
$got =0;
while ($got < $howmany)
{
$num = mt_rand($from,$to);
if ( !in_array($num, $results) )
{
array_push($results,$num);
$got++;
}
}
return $app['twig']->render('random.twig', array(
'title' => 'Resultado',
'results' => $results,
'from' => $from,
'to' => $to,
'howmany' => $howmany
));
});
$app->run();
?>