Skip to content

Instantly share code, notes, and snippets.

@miszmaniac
Created May 13, 2013 05:46
Show Gist options
  • Save miszmaniac/5566377 to your computer and use it in GitHub Desktop.
Save miszmaniac/5566377 to your computer and use it in GitHub Desktop.
Próbka - jak można użyć Traitów w widokach.
<?
trait FormElements {
protected function getLabel($text, $for) {
return "<label for='$for'>$text</label>";
}
protected function getTextInput($name) {
return "<input type='text' name='$name'/>";
}
}
trait FormDecorator {
use FormElements;
protected function getLabeledInput($name) {
$asciiName = iconv('utf-8', 'ascii//translit//ignore', $name);
$label = $this->getLabel($name, $asciiName);
$input = $this->getTextInput($asciiName);
return "<dt>$label</dt><dd>$input</dd>";
}
protected function decorateForm($form) {
return "<dl>$form</dl>";
}
}
class HtmlForm {
use FormDecorator;
public function createLoginForm() {
$form = $this->getLabeledInput('user') . $this->getLabeledInput('email'). $this->getLabeledInput('password');
return $this->decorateForm($form);
}
}
$form = new HtmlForm();
echo $form->createLoginForm();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment