/**
* ImportInterface
*/
interface ImportInterface
{
/**
* Get content
*
* @return string content
*/
public function getContent();
}
/**
* ImportOne
*/
class ImportOne implements ImportInterface
{
use ImportHelper;
/**
* @var string params
*/
const CONTENT_TYPE = '#1';
/**
* @return string
*/
public function getContent()
{
return $this->import(self::CONTENT_TYPE);
}
}
/**
* ImportTwo
*/
class ImportTwo implements ImportInterface
{
use ImportHelper;
/**
* @var string
*/
const CONTENT_TYPE = '#2';
/**
* @return string основной контент
*/
public function getContent()
{
return $this->import(self::CONTENT_TYPE);
}
}
/**
* ImportClient
*/
class ImportClient
{
/**
* @var ImportInterface
*/
private $importType;
/**
* @param ImportInterface $importType
*/
public function setType(ImportInterface $importType)
{
$this->importType = $importType;
}
/**
* @return string
*/
public function getContent()
{
return $this->importType->getContent();
}
}
/**
* ImportHelper
*/
trait ImportHelper
{
/**
* @param string $query
* @return string
*/
public function import($query = 'name')
{
return $query;
}
}
/**
* Use
*/
$client = new ImportClient();
foreach (['ImportOne', 'ImportTwo'] as $type) {
$client->setType(new $type());
var_dump($client->getContent());
}