<?php
 
/**
 * Class representing restaurant
 */
class Restaurant {
 
    private $url;
    private $name;
    private $xpaths = array();
 
    public function getName() {
        return $this->name;
    }
 
    public function getUrl() {
        return $this->url;
    }
 
    public function getXpaths() {
        return $this->xpaths;
    }
 
    /**
     * @param $name
     * @param $url
     * @param $xpaths
     */
    function __construct($name, $url, $xpaths) {
 
        if (empty($url) || empty($xpaths)) {
            throw new InvalidArgumentException("All argument are required");
        }
 
        $this->name = $name;
        $this->url = $url;
 
        if (is_string($xpaths)) {
            $this->xpaths[] = $xpaths;
        } else if (is_array($xpaths)) {
            $this->xpaths = $xpaths;
        } else {
            throw new InvalidArgumentException("Xpaths must be string or array");
        }
    }
 
}
 
interface iOutput {
    public function log($message);
    public function display();
}
 
class Output implements iOutput {
    protected $output = "";
 
    public function log($message) {
        $this->output .= $message;
    }
 
    public function display(){}
}
 
class HtmlOutput extends Output  {
 
    public function display(){
        echo $this->output;
    }
}
 
class EmailOutput {
 
    public function display(){
        // Send mail
    }
}
 
 
class Parser {
 
    private $restaurants = array();
    private $logger;
 
    function __construct($logger, $restaurants) {
 
        // Check if logger implements iOutput interface
        if (  !in_array("iOutput", class_implements($logger)) ) {
            throw new InvalidArgumentException("Logger class must implement interface iOutput");
        }
 
        $this->logger = $logger;
 
        if (empty($restaurants) || !is_array($restaurants)) {
            throw new InvalidArgumentException("Array argument required");
        }
 
        $this->restaurants = $restaurants;
    }
 
    public function parse() {
        foreach ($this->restaurants as $restaurant) {
 
            $source = file_get_contents($restaurant->getUrl());