Example #1
0
/**
 * Concrete Abstraction Class
 */
class ExtendedListing extends Listing
{
    function __construct($data_source)
    {
        parent::__construct($data_source);
    }
    function readWithEncode()
    {
        return htmlspecialchars($this->read(), ENT_QUOTES, mb_internal_encoding());
    }
}
/**
 * Client
 */
$list1 = new Listing(new FileDataSource('data.txt'));
$list2 = new ExtendedListing(new FileDataSource('data.txt'));
try {
    $list1->open();
    $list2->open();
} catch (Exception $e) {
    die($e->getMessage());
}
$data = $list1->read();
echo $data;
$data = $list2->readWithEncode();
echo $data;
$list1->close();
$list2->close();