<?php
require_once 'DataSourceInterface.php';

class 
FileDataSource implements DataSourceInterface
{
    private 
$_sourceName;
    private 
$_handler;

    public function 
__construct($sourceName)
    {
        
$this->_sourceName $sourceName;
    }

    public function 
open()
    {
        
$this->_handler fopen($this->_sourceName'r');
        if (!
$this->_handler) {
            throw new 
RuntimeException('File [' $this->_sourceName '] is not readable.');
        }
    }

    public function 
read()
    {
        
$buffer = array();
        while (!
feof($this->_handler)) {
            
$buffer[] = fgets($this->_handler);
        }
        return 
implode(''$buffer);
    }

    public function 
close()
    {
        if (!
is_null($this->_handler)) {
            
fclose($this->_handler);
        }
    }
}