Skip to content

Instantly share code, notes, and snippets.

@craigtaub
Last active December 29, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigtaub/7695094 to your computer and use it in GitHub Desktop.
Save craigtaub/7695094 to your computer and use it in GitHub Desktop.
Factory for categories
abstract class Channel
{
protected $_identifier;
protected $_id;
protected $_iblId;
public function getIdentifier() {
return $this->_identifier;
}
public function getId() {
return $this->_id;
}
public function getIblid() {
return $this->_iblId;
}
//Additional channel logic
}
class Channels_BbcOne extends Channel
{
//this is all the channel objects will ever have.
public function __construct(){
$this->_identifier = 'bbcone';
$this->_id = 'bbc_one';
$this->_iblId = 'bbc_one_london';
}
}
class ChannelsFactory
{
private $_channel;
public function __construct($channel) {
$this->_channel = $channel;
}
public function build() {
switch ($this->_channel) {
case 'bbcone':
return new Channels_BbcOne();
break;
case 'bbctwo':
return new Channels_BbcTwo();
break;
}
}
}
// USAGE:
$channel = 'bbcone'; //getParam or whatever
$channelFactory = new ChannelsFactory($channel);
$channelObject = $channelFactory->build();
echo $channelObject->getId();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment