Exemplo n.º 1
0
        $name = $this->getName();
        return "<label for=\"{$name}\">{$this->label}</label>\n" . $this->element->__toString();
    }
}
class ErrorDecorator extends HtmlDecorator
{
    protected $error;
    public function setError($message)
    {
        $this->error = $message;
    }
    public function __toString()
    {
        return $this->element->__toString() . "<span>{$this->error}</span>\n";
    }
}
$input = new InputText('nickname');
$labelled = new LabelDecorator($input);
$labelled->setLabel('Nickname:');
printf("%s\n", $labelled);
$input = new InputText('nickname');
$error = new ErrorDecorator($input);
$error->setError('You must enter a unique nickname');
printf("%s\n", $error);
// Label + Error
$input = new InputText('nickname');
$labelled = new LabelDecorator($input);
$labelled->setLabel('Nickname:');
$error = new ErrorDecorator($labelled);
$error->setError('You must enter a unique nickname');
printf("%s\n", $error);
    }
    public function __toString()
    {
        $name = $this->getName();
        return "<label for=\"{$name}\">{$this->label}</label>\n" . $this->element->__toString();
    }
}
class ErrorDecorator extends HtmlDecorator
{
    protected $error;
    public function setError($message)
    {
        $this->error = $message;
    }
    public function __toString()
    {
        return $this->element->__toString() . "<span>{$this->error}</span>\n";
    }
}
$input = new InputText('nickname');
printf("InputText without decorator:<br>%s<br>", $input);
$labelled = new LabelDecorator($input);
$labelled->setLabel('Nickname:');
printf("InputText with LabelDecorator:<br>%s<br>", $labelled);
$error = new ErrorDecorator($input);
$error->setError('You must enter a unique nickname');
printf("InputText with ErrorDecorator:<br>%s<br>\n", $error);
// Label + Error
$error = new ErrorDecorator($labelled);
$error->setError('You must enter a unique nickname');
printf("InputText with LabelDecorator and ErrorDecorator:<br>%s<br>", $error);
Exemplo n.º 3
0
    {
        $name = $this->getName();
        return "<label for\"{$name}\">{$this->label}</label>\n" . $this->element->__toString();
    }
}
class ErrorDecorator extends HtmlDecorator
{
    protected $error;
    public function setError($message)
    {
        $this->error = $message;
    }
    public function __toString()
    {
        return $this->element->__toString() . "<span>{$this->error}</span>\n";
    }
}
$input = new InputText('nickname');
$labelled = new LabelDecorator($input);
$labelled->setLabel('Nick');
echo $labelled . PHP_EOL;
$input = new InputText('nickname');
$error = new ErrorDecorator($input);
$error->setError('You must enter a nickname');
echo $error . PHP_EOL;
$input = new InputText('nickname');
$labelled = new LabelDecorator($input);
$labelled->setLabel('Nick:');
$error = new ErrorDecorator($labelled);
$error->setError('You must enter a nickname');
echo $error;
Exemplo n.º 4
0
 public function getSchema()
 {
     $list = parent::getSchema();
     return array_merge($list, ['refusalReason' => 'string', 'errorCode' => 'string', 'errorType' => 'string', 'message' => 'string']);
 }