Skip to content

Commit

Permalink
[phalcon#13060] - Correction to the method calls/parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Jan 27, 2019
1 parent e426f0b commit 795d59e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 107 deletions.
3 changes: 1 addition & 2 deletions phalcon/html/helper/abstracthelper.zep
Expand Up @@ -12,14 +12,13 @@ namespace Phalcon\Html\Helper;

use Phalcon\Html\Exception;
use Phalcon\EscaperInterface;
use Phalcon\Service\ServiceInterface;

/**
* Phalcon\Html\Helper\AbstractHelper
*
* Abstract class for all html helpers
*/
abstract class AbstractHelper implements ServiceInterface
abstract class AbstractHelper
{
/**
* @var <EscaperInterface>
Expand Down
37 changes: 8 additions & 29 deletions phalcon/html/helper/anchor.zep
Expand Up @@ -24,41 +24,20 @@ class Anchor extends AbstractHelper
* @var string text The text for the anchor
* @var array attributes Any additional attributes
*/
public function __invoke()
public function __invoke(string! href, string! text, array attributes = []) -> string
{
var arguments, attributes, escapedText, href, overrides, text;
var escapedText, overrides;

let arguments = func_get_args();
let overrides = ["href" : href];

/**
* Check parameters passed
* Avoid duplicate "href" and ignore it if it is passed in the attributes
*/
if (count(arguments) >= 2 &&
typeof arguments[0] === "string" &&
typeof arguments[1] === "string") {
unset(attributes["href"]);

let overrides = this->orderAttributes(overrides, attributes),
escapedText = this->escaper->escapeHtml(text);

if (true === isset(arguments[2]) && typeof arguments[2] === "array") {
let attributes = arguments[2];
} else {
let attributes = [];
}

let href = arguments[0],
overrides = ["href" : href],
text = arguments[1];

/**
* Avoid duplicate "href" and ignore it if it is passed in the attributes
*/
unset(attributes["href"]);

let overrides = this->orderAttributes(overrides, attributes),
escapedText = this->escaper->escapeHtml(text);

return "<a " . rtrim(this->renderAttributes(overrides)) . ">" . escapedText . "</a>";
} else {
throw new \InvalidArgumentException("Incorrect passed arguments");
}
return "<a " . rtrim(this->renderAttributes(overrides)) . ">" . escapedText . "</a>";
}
}
22 changes: 2 additions & 20 deletions phalcon/html/helper/button.zep
Expand Up @@ -23,26 +23,8 @@ class Button extends AbstractHelper
* @var string text The text for the anchor
* @var array attributes Any additional attributes
*/
public function __invoke()
public function __invoke(string! text, array attributes = []) -> string
{
var arguments, attributes, text;

let arguments = func_get_args();

/**
* Check parameters passed
*/
if (count(arguments) >= 1 && typeof arguments[0] === "string") {
if (true === isset(arguments[1]) && typeof arguments[1] === "array") {
let attributes = arguments[1];
} else {
let attributes = [];
}
let text = arguments[0];

return this->renderElement("button", text, attributes);
} else {
throw new \InvalidArgumentException("Incorrect passed arguments");
}
return this->renderElement("button", text, attributes);
}
}
26 changes: 2 additions & 24 deletions phalcon/html/helper/element.zep
Expand Up @@ -24,30 +24,8 @@ class Element extends AbstractHelper
* @var string text The text for the anchor
* @var array attributes Any additional attributes
*/
public function __invoke()
public function __invoke(string! tag, string! text, array attributes = []) -> string
{
var arguments, attributes, tag, text;

let arguments = func_get_args();

/**
* Check parameters passed
*/
if (count(arguments) >= 2 &&
typeof arguments[0] === "string" &&
typeof arguments[1] === "string") {

if (true === isset(arguments[2]) && typeof arguments[2] === "array") {
let attributes = arguments[2];
} else {
let attributes = [];
}
let tag = arguments[0],
text = arguments[1];

return this->renderElement(tag, text, attributes);
} else {
throw new \InvalidArgumentException("Incorrect passed arguments");
}
return this->renderElement(tag, text, attributes);
}
}
14 changes: 3 additions & 11 deletions phalcon/html/helper/form.zep
Expand Up @@ -22,23 +22,15 @@ class Form extends AbstractHelper
/**
* @var array attributes Any additional attributes
*/
public function __invoke()
public function __invoke(array attributes = []) -> string
{
var arguments, attributes, overrides;
var overrides;

let arguments = func_get_args(),
overrides = [
let overrides = [
"method" : "post",
"enctype" : "multipart/form-data"
];

if (1 === count(arguments) && typeof arguments[0] === "array") {
let attributes = arguments[0];
} else {
let attributes = [];
}


let overrides = this->orderAttributes(overrides, attributes);

return "<form " . rtrim(this->renderAttributes(overrides)) . ">";
Expand Down
2 changes: 1 addition & 1 deletion phalcon/html/helper/formclose.zep
Expand Up @@ -22,7 +22,7 @@ class FormClose extends AbstractHelper
/**
* @var array attributes Any additional attributes
*/
public function __invoke()
public function __invoke() -> string
{
return "</form>";
}
Expand Down
22 changes: 2 additions & 20 deletions phalcon/html/helper/textarea.zep
Expand Up @@ -23,26 +23,8 @@ class TextArea extends AbstractHelper
* @var string text The text for the anchor
* @var array attributes Any additional attributes
*/
public function __invoke()
public function __invoke(string! text, array attributes = []) -> string
{
var arguments, attributes, text;

let arguments = func_get_args();

/**
* Check parameters passed
*/
if (count(arguments) >= 1 && typeof arguments[0] === "string") {
if (true === isset(arguments[1]) && typeof arguments[1] === "array") {
let attributes = arguments[1];
} else {
let attributes = [];
}
let text = arguments[0];

return this->renderElement("textarea", text, attributes);
} else {
throw new \InvalidArgumentException("Incorrect passed arguments");
}
return this->renderElement("textarea", text, attributes);
}
}

0 comments on commit 795d59e

Please sign in to comment.