Code: Select all
//adapter converter class
class ISBNConverter{
public static function convertISBN( $value, $to13=TRUE, $to10=FALSE ){
//initialize
$IsbnConverter = new ISBN();
$value = preg_replace( "#[^0-9a-zA-Z]#", "", $value );
$result = NULL;
//convert to 13
if( $to13 === TRUE ){
$result = $IsbnConverter->convert( $value );
}
//convert to 10
if( $to10 === TRUE ){
$temp = substr( $value, 3, 9 );
$checksum10 = $IsbnConverter->genchksum10( $temp );
if( $checksum10 == 10 ) $checksum10 = 'X';
$result = $temp . $checksum10;
}
//return
##echo $result;
return $result;
}
}Code: Select all
<?php
class ISBN {
//...more functions
}
?>Code: Select all
<?php
//adapter for ISBN class
class ISBNConverter{
private static $IsbnConverter;
public static function getISBNInstance(){
if( get_class( ISBNConverter::$IsbnConverter ) != "ISBN" ){
ISBNConverter::$IsbnConverter = new ISBN();
}
return ISBNConverter::$IsbnConverter;
}
public static function convertISBN( $value, $to13=TRUE, $to10=FALSE ){
//initialize
$IsbnConverter = ISBNConverter::getISBNInstance();
$value = preg_replace( "#[^0-9a-zA-Z]#", "", $value );
$result = NULL;
//convert to 13
if( $to13 === TRUE ){
$result = $IsbnConverter->convert( $value );
}
//convert to 10
if( $to10 === TRUE ){
$temp = substr( $value, 3, 9 );
$checksum10 = $IsbnConverter->genchksum10( $temp );
if( $checksum10 == 10 ) $checksum10 = 'X';
$result = $temp . $checksum10;
}
//return
##echo $result;
return $result;
}
}
//main ISBN class
class ISBN {
//...many functions
}
?>i would request your opinions about this design. please let me know if you can think of other alternatives. thanks.