<?php
namespace Main\InterfaceStuff;

require_once 'Object.php';
require_once 'IPhrases.php';

use \Main\Object;	// Import class from Main namespace

// Just added these to demonstrate instanceof.
require_once 'FrenchPhrases.php';
use \Main\InterfaceStuff;

// NOTE FOR Software Engineers
// PHP doesn't really support polymorphism because it's a loosely typed language
// so we don't need to store objects as their parent class, just restrict ourselves
// to using parent class methods. Likewise, we can't cast back to a child class
// because we don't need to, just return the object and use the child methods.
class Translator extends Object
{
	// Attributes
	private $_languages;
	
	// Constructor
	
	// Methods for properties
	// Getters and Setters
	// NONE
	
	// Methods
	
	public function AddLanguage(IPhrases $language)	// Note this type hint doesn't perform a conversion, just a check
	{
		$this->_languages[] = $language;
	}
	
	public function SayHelloToEverybody()
	{
		foreach($this->_languages as $language)
		{
			// Polymorphism -- we don't know the language
			// that $language contains
			$language->Hello();
		}
	}
	
	// Return the french phrases object
	public function FindFrenchPhrases()
	{
		foreach($this->_languages as $language)
		{
			// Here we have to check if the object
			// is a FrenchPhrases object
			if($language instanceof FrenchPhrases)
			{
				return $language;	// No conversion to child class reqd, PHP is loosely typed
			}
		}
		//return false;	// Not supported, return boolean false
		return;      // Not supported, just don't return object i.e. undefined
	}
} 
?>
