Exemple #1
0
// et ei ole tühjad
// clean input
// salvestate
if (isset($_POST["create"])) {
    if (empty($_POST["auto"])) {
        $autonr_error = "See väli on kohustuslik";
    } else {
        $autonr = cleanInput($_POST["auto"]);
    }
    if (empty($_POST["sisenemismass"])) {
        $sisenemismass_error = "See väli on kohustuslik";
    } else {
        $sisenemismass = cleanInput($_POST["sisenemismass"]);
    }
    if ($autonr_error == "" && $sisenemismass_error == "") {
        $message = createCar($autonr, $sisenemismass);
        header("Location: data2.php");
        if ($message != "") {
            //salvestamine õnnestus
            // teen tühjaks input value'd
            $autonr = "";
            $sisenemismass = "";
            echo $message;
        }
    }
}
// create if end
function cleanInput($data)
{
    $data = trim($data);
    $data = stripslashes($data);
 * and then outputs current state of tank for each car
 *
 * @param \AbstractFactory\AbstractCar[] $cars
 */
function runCars($cars)
{
    // make cars go
    foreach ($cars as $car) {
        echo $car->go() . PHP_EOL;
    }
    echo '-------------------' . PHP_EOL;
    foreach ($cars as $car) {
        echo $car->getName() . ' currently has ' . $car->getCurrentTankVolume() . ' l in tank' . PHP_EOL;
    }
}
// create two different cars
$chevroletCar = createCar(new ChevroletFactory());
$nissanCar = createCar(new NissanFactory());
// output basic data for each car
echo $chevroletCar;
echo $nissanCar;
// now output some data
echo 'Chevrolet mileage: ' . $chevroletCar->getMileage() . PHP_EOL;
echo 'Nissan mileage: ' . $nissanCar->getMileage() . PHP_EOL;
// refule cars
$chevroletCar->refuelTank(50);
$nissanCar->refuelTank(50);
runCars([$chevroletCar, $nissanCar]);
runCars([$chevroletCar, $nissanCar]);
runCars([$chevroletCar, $nissanCar]);
runCars([$chevroletCar, $nissanCar]);