<?php
interface InputFields {
public function show();
public function addStyle(array $styles);
}
class InputEmail implements InputFields {
private $_html = "<input type = 'email'>";
public function show() {
echo $this->_html . '<br>'. '<br>';
}
public function addStyle(array $styles) { }
}
$input = new InputEmail();
$input->addStyle ([
'width' => '300px',
'border-radius' => '5px',
'border' => '1px solid blue',
'background' => '#fcfcfc',
'padding' => '10px 20px',
]);
$input->show();
<?php
interface InputFields {
public function show();
public function addStyle(array $styles);
}
class InputEmail implements InputFields {
private $_styles = "styles=\"";
private $_start_tag = "<input type = 'email' ";
private $_end_tag = ">";
public function addStyle(array $styles) {
foreach ($styles as $style => $value){
$this->_styles .= $style . ':' . $value . ';';
}
$this->_styles .= '"';
return $this->_styles;
}
public function show() {
echo $this->_start_tag . $this->_styles . $this->_end_tag . '<br>'. '<br>';
}
}
$input = new InputEmail();
$input->addStyle ([
'width' => '300px',
'border-radius' => '5px',
'border' => '1px solid blue',
'background' => '#fcfcfc',
'padding' => '10px 20px',
]);
$input->show();
// Output: <input type = 'email' styles="width:300px;border-radius:5px;border:1px solid blue;background:#fcfcfc;padding:10px 20px;"><br><br>