Update the inventory project to validate all information as it is entered into an HTML form (via HTML and JavaScript as shown in Chapter 4) in the interface tier. After the information is validated it is passed to the business rules tier. The business rules tier will validate the information received and filter out any harmful information. Once the information is accepted (and stored in the properties) the application will display all fields of the product stored in the warehouse of the ABC Computer Parts Company. The interface tier and the business rules tier must be separated using dependency injection (via an XML file), as shown.

inventory.php

class Product {
// —————————————– Properties —————————————–
private $product_name = “no name”;
private $product_code = 0;
private $product_price = 0;
private $product_quantity = 90;
private $product_needs = “no needs”;
private $error_message = “??”;

// ———————————- Set Methods ———————————————-
function set_product_name($value) {
$error_message = TRUE;
(ctype_alpha($value) && strlen($value) <= 20) ? $this - > product_name = $value: $this – > error_message = FALSE;
return $this – > error_message;
}

function set_product_code($value) {
$error_message = TRUE;
(is_numeric($value) && ($value > 0 && $value <= 999999)) ? $this - > product_code = $value: $this – > error_message = FALSE;
return $this – > error_message;
}

function set_product_price($value) {
$error_message = TRUE;
(is_numeric($value) && ($value > 0 && $value <= 999999)) ? $this - > product_price = $value: $this – > error_message = FALSE;
return $this – > error_message;
}

function set_product_quantity($value) {
$error_message = TRUE;
(is_numeric($value) && ($value > 0 && $value <= 999999)) ? $this - > product_quantity = $value: $this – > error_message = FALSE;
return $this – > error_message;
}

function set_product_needs($value) {
$error_message = TRUE;
(preg_match(&#39;/[^a-z_-0-9]/i&#39;, $value) && strlen($value) <= 40) ? $this - > product_needs = $value: $this – > error_message = FALSE;
return $this – > error_message;
}
// —————————————– Get Methods ————————————————————
function get_product_name() {
return $this – > product_name;
}

function get_product_code() {
return $this – > product_code;
}

function get_product_price() {
return $this – > product_price;
}

function get_product_quantity() {
return $this – > product_quantity;
}

function get_product_needs() {
return $this – > product_needs;
}

function get_properties() {
return “$this->product_name,$this->product_code,$this->product_price,$this->product_quantity,$this->product_needs.”;
}
}

lab.php

Require_once(“inventory.php”);
$lab = new Product;
// ——————————Set Properties————————–
$product_error_message = $lab – > set_product_name(&#39;Hinge&#39;);
print $product_error_message == TRUE ? &#39;Name update successful
&#39; : &#39;Name update not successful
&#39;;

$product_error_message = $lab – > set_product_code(45435);
print $product_error_message == TRUE ? &#39;Code update successful
&#39; : &#39;Code update not successful
&#39;;

$product_error_message = $lab – > set_product_price(7.50);
print $product_error_message == TRUE ? &#39;Price update successful
&#39; : &#39;Product update not successful
&#39;;

$product_error_message = $lab – > set_product_quantity(75);
print $product_error_message == TRUE ? &#39;Quantity update successful
&#39; : &#39;Quantity update not successful
&#39;;

$product_error_message = $lab – > set_product_needs(&#39;Wrap in plastic&#39;);
print $product_error_message == TRUE ? &#39;Needs update successful
&#39; : &#39;Needs update not successful
&#39;;
// ——————————Get Properties————————–
print $lab – > get_product_name().

“;
print $lab – > get_product_code().

“;
print $lab – > get_product_price().

“;
print $lab – > get_product_quantity().

“;
print $lab – > get_product_needs().

“;
$product_properties = $lab – > get_properties();
list($product_name, $product_code, $product_price, $product_quantity, $product_needs) = explode(&#39;,&#39;, $product_properties);
print “Name: $product_name. Code: $product_code. Price: $product_price. Quantity: $product_quantity. Needs: $product_needs”;
?>

"Get 15% discount on your first 3 orders with us"
Use the following coupon
"FIRST15"

Order Now