/** * Sets the tag name to $this->tagName. * Additionally, sets all tag attributes which were registered in * $this->tagAttributes and additionalArguments. * * Will be invoked just before the render method. * * @return void * @api */ public function initialize() { parent::initialize(); $this->tag->reset(); $this->tag->setTagName($this->tagName); if ($this->hasArgument('additionalAttributes') && is_array($this->arguments['additionalAttributes'])) { $this->tag->addAttributes($this->arguments['additionalAttributes']); } if (isset(self::$tagAttributes[get_class($this)])) { foreach (self::$tagAttributes[get_class($this)] as $attributeName) { if ($this->hasArgument($attributeName) && $this->arguments[$attributeName] !== '') { $this->tag->addAttribute($attributeName, $this->arguments[$attributeName]); } } } }
/** * Renders the captcha image and its textfields * * @return string */ public function render() { // Render image tag $this->tag->reset(); $this->tag->setTagName("img"); $this->tag->addAttributes($this->getAttributes("image", array("src" => $this->captchaService->create($this->arguments["width"], $this->arguments["height"]), "width" => $this->arguments["width"], "height" => $this->arguments["height"], "style" => "width: " . $this->arguments["width"] . "px; height: " . $this->arguments["height"] . "px;"))); $markup = str_replace("{image}", $this->tag->render(), $this->arguments["markup"]); // Render phrase textfield $this->tag->reset(); $this->tag->setTagName("input"); $this->tag->addAttributes($this->getAttributes("phrase", array("name" => $this->arguments["name"] . "[phrase]", "type" => "text", "autocomplete" => "off"))); $markup = str_replace("{phrase}", $this->tag->render(), $markup); // Render phrase textfield $this->tag->reset(); $this->tag->setTagName("input"); $this->tag->addAttributes($this->getAttributes("hash", array("name" => $this->arguments["name"] . "[hash]", "type" => "hidden", "value" => $this->captchaService->getPhraseHash()))); return str_replace("{hash}", $this->tag->render(), $markup); }