Last active
January 3, 2016 19:19
-
-
Save amacgregor/8507938 to your computer and use it in GitHub Desktop.
Product Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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