Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Product Factory
<?php
class ProductFactory
{
public static function build($product_type, $sku, $name)
{
$product = "Product_" . ucwords($product_type);
if(class_exists($product))
{
return new $product($sku, $name);
}
else {
throw new Exception("Invalid product type given.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.