Created
April 10, 2013 13:42
-
-
Save tobyS/5354730 to your computer and use it in GitHub Desktop.
This file contains 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 SnakStorage | |
{ | |
public function canStore( Snak $snak ) | |
{ | |
throw new \RuntimeException("Not implemented, yet."); | |
} | |
public function storeSnak( $snak, $snakRole /* ... */ ) | |
{ | |
throw new \RuntimeException("Not implemented, yet."); | |
} | |
} | |
class PropertyValueSnakStorage | |
{ | |
public function canStore( Snak $snak ) | |
{ | |
return ( $snak instanceof PropertyValueSnak ); | |
} | |
public function storeSnak( $snak, $snakRole /* ... */ ) | |
{ | |
// Perform storage | |
} | |
} | |
class Updater | |
{ | |
private $snakStorages = array(); | |
public function __construct( array $snakStorages ) | |
{ | |
// .. add snak storages | |
} | |
public function insertSnak( Snak $snak, $snakRole ) | |
{ | |
foreach ( $this->snakStorages as $snakStorage ) | |
{ | |
if ( $snakStorage->canStore( $snak ) ) | |
{ | |
return $snakStorage->storeSnak( $snak /* ... */ ); | |
} | |
} | |
throw new \RuntimeException( 'Unknown snak ...' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment