<?php
class Zoo {
protected $pool = [];
public function __construct($temp, $legs, $animal)
{
// Külön vannak
// Test: pool feltöltése példához
$this->pool[] = new AnimalFactory(['magyar', 'szavak'], [4, 3], 'Dog');
$this->pool[] = new AnimalFactory(['magyar', 'szavak'], 2, 'Dog');
$this->pool[] = new AnimalFactory(['english', 'words'], $legs, $animal);
}
public function start() {
foreach($this->pool as $animalPool)
{
$tmp = $animalPool->start();
$this->kiir($tmp);
}
}
public function kiir($value) {
var_dump($value);
}
}
class AnimalFactory {
private $wordList;
private $legs;
private $animal;
private $obj;
// Wordlist és lábak száma
public function __construct($wordList, $legs, $animal) {
$this->legs = $legs;
$this->animal = $animal;
$className = $animal;
$this->obj = new $className($wordList, $legs);
}
public function start(){
$value = $this->obj->test();
return [
'legs' => $this->legs,
'value' => $value
];
}
}
class Animal {
protected $wordList;
public function __construct($wordList) {
$this->wordList = $wordList;
}
}
class Dog extends Animal implements AnimalInterface {
public function test() {
return $this->wordList[0] . ' Dog-';
}
}
class Lion extends Animal implements AnimalInterface {
public function test() {
return $this->wordList[0] . ' Lion-';
}
}
// Csak egy interface
interface AnimalInterface {
public function test();
}
// Teszteljük le
$baba = new Zoo('asd', 3, 'Lion');
$baba->start();