Ejemplo n.º 1
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/triangle.php";
$app = new Silex\Application();
$app->get("/", function () {
    return "\n        <!DOCTYPE html>\n        <html>\n        <head>\n        <title>Triangle Land</title>\n        </head>\n        <body>\n          <div class='container'>\n            <h1>Enter the dimensions of your triangle:</h1>\n              <form action='/view_triangle'>\n              <div class='form-group'>\n              <label for='side1'>Side 1</label>\n              <input id='side1' name='side1' class='form-control' type='number'>\n              </div>\n              <div class='form-group'>\n                  <label for='side2'>Side 2</label>\n                  <input id='side2' name='side2' class='form-control' type='number'>\n              </div>\n              <div class='form-group'>\n                  <label for='side3'>Side 3</label>\n                  <input id='side3' name='side3' class='form-control' type='number'>\n              </div>\n\n              <button type='submit' class='btn-success'>Check it</button>\n\n            </form>\n          </div>\n        </body>\n        </html>\n        ";
});
$app->get("/view_triangle", function () {
    $my_triangle = new Triangle($_GET['side1'], $_GET['side2'], $_GET['side3']);
    if ($my_triangle->isEquilateral()) {
        return "<h1>Congrats! That shit is equilateral! ;)</h1>";
    } else {
        return "<h1>That shit is whack :(</h1>";
    }
});
return $app;
Ejemplo n.º 2
0
?>

<!DOCTYPE html>
<html>
<head>
    <title>Triangle</title>
</head>
  <body>
      <h1>What kind of triangle is it?</h1>
      <?php 
$get_side1 = $_GET["length1"];
$get_side2 = $_GET["length2"];
$get_side3 = $_GET["length3"];
$new_triangle = new Triangle($_GET["length1"], $_GET["length2"], $_GET["length3"]);
$is_triangle = $new_triangle->isTriangle();
$get_equilateral = $new_triangle->isEquilateral();
$get_scalene = $new_triangle->isScalene();
$get_isosceles = $new_triangle->isIsosceles();
if ($is_triangle) {
    if ($get_equilateral) {
        echo "<p>Your triangle is equilateral!</p>";
    } elseif ($get_scalene) {
        echo "<p>Your triangle is scalene!</p>";
    } else {
        echo "<p>Your triangle is isosceles!</p>";
    }
} else {
    echo "<p>This is not a triangle! Try again!</p>";
}
?>
  </body>