Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Last active January 3, 2016 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amacgregor/8507938 to your computer and use it in GitHub Desktop.
Save amacgregor/8507938 to your computer and use it in GitHub Desktop.
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