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 Product { | |
private $stockItem; | |
private $sku; | |
public function __construct($sku, $stockQuantity, $stockStatus){ | |
$this->stockItem = new StockItem($stockQuantity, $stockStatus); | |
$this->sku = $sku; | |
} |
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 StockItem { | |
private $quantity; | |
private $status; | |
public function __construct($quantity, $status){ | |
$this->quantity = $quantity; | |
$this->status = $status; |
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 Product { | |
private $stockItem; | |
private $sku; | |
public function __construct($sku, StockItem $stockItem){ | |
$this->stockItem = $stockItem; | |
$this->sku = $sku; | |
} |
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 Product { | |
private $stockItem; | |
private $sku; | |
public function __construct($sku){ | |
$this->sku = $sku; | |
} | |
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 | |
abstract class Product | |
{ | |
private $sku; | |
private $name; | |
protected $type = null; | |
public function __construct($sku, $name) | |
{ |
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 | |
$product = new Product_Chair('0001','INGOLF Chair'); | |
... | |
$product = new Product_Table('0002','STOCKHOLN Table'); | |
... |
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 ProductController { | |
public function create($product_type) | |
{ | |
// Some post data validation logic here | |
// Now we need to instantiate our product | |
$product = ProductFactory::build($product_type, $post['sku'], $post['name']) |
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); |
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 | |
/** Example taken from http://www.webgeekly.com/tutorials/php/how-to-create-a-singleton-class-in-php/ **/ | |
class User | |
{ | |
// Hold an instance of the class | |
private static $instance; | |
// The singleton method |
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
mkdir dev | |
cd dev | |
export CMAKE_PREFIX_PATH=`pwd` | |
git clone git://github.com/facebook/hhvm.git | |
cd hhvm | |
git submodule init | |
cd ../ | |
## Required for builtin web-server support |