Skip to content

Commit

Permalink
interim commit
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Dec 11, 2021
1 parent 1721ca4 commit 9992bb2
Show file tree
Hide file tree
Showing 394 changed files with 1,885 additions and 12,245 deletions.
2 changes: 1 addition & 1 deletion phalcon/Factory/AbstractFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class AbstractFactory extends AbstractConfigFactory
}

/**
* AdapterFactory constructor.
* Initialize services/add new services
*/
protected function init(array! services = []) -> void
{
Expand Down
128 changes: 85 additions & 43 deletions phalcon/Forms/Element/AbstractElement.zep
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
namespace Phalcon\Forms\Element;

use InvalidArgumentException;
use Phalcon\Filter\Validation\ValidatorInterface;
use Phalcon\Forms\Form;
use Phalcon\Forms\Exception;
use Phalcon\Html\TagFactory;
use Phalcon\Messages\MessageInterface;
use Phalcon\Messages\Messages;
use Phalcon\Tag;
use Phalcon\Filter\Validation\ValidatorInterface;

/**
* This is a base class for form elements
Expand All @@ -43,6 +43,11 @@ abstract class AbstractElement implements ElementInterface
*/
protected label = null;

/**
* @var string
*/
protected method = "inputText";

/**
* @var Messages
*/
Expand All @@ -58,6 +63,11 @@ abstract class AbstractElement implements ElementInterface
*/
protected options = [];

/**
* @var TagFactory|null
*/
protected tagFactory = null;

/**
* @var array
*/
Expand All @@ -84,9 +94,9 @@ abstract class AbstractElement implements ElementInterface
);
}

let this->name = name;
let this->attributes = attributes;
let this->messages = new Messages();
let this->name = name,
this->attributes = attributes,
this->messages = new Messages();
}

/**
Expand Down Expand Up @@ -133,18 +143,19 @@ abstract class AbstractElement implements ElementInterface
* Adds a group of validators
*
* @param \Phalcon\Filter\Validation\ValidatorInterface[] validators
* @param bool merge
* @param bool merge
*/
public function addValidators(array! validators, bool merge = true) -> <ElementInterface>
{
if merge {
let validators = array_merge(
this->validators,
validators
);
var validator;

if unlikely !merge {
let this->validators = [];
}

let this->validators = validators;
for validator in validators {
this->addValidator(validator);
}

return this;
}
Expand All @@ -165,13 +176,10 @@ abstract class AbstractElement implements ElementInterface
public function clear() -> <ElementInterface>
{
var form = this->form,
name = this->name,
value = this->value;
name = this->name;

if typeof form == "object" {
form->clear(name);
} else {
Tag::setDefault(name, value);
}

return this;
Expand Down Expand Up @@ -303,15 +311,7 @@ abstract class AbstractElement implements ElementInterface
}

/**
* Otherwise check Phalcon\Tag
*/
if Tag::hasValue(name) {
let value = Tag::getValue(name);
}

/**
* Assign the default value if there is no form available or
* Phalcon\Tag returns null
* Assign the default value if there is no form available
*/
if value === null {
let value = this->value;
Expand All @@ -333,12 +333,13 @@ abstract class AbstractElement implements ElementInterface
*/
public function label(array attributes = []) -> string
{
var internalAttributes, label, name, code;
var code, internalAttributes, labelName, name, tagFactory;

/**
* Check if there is an "id" attribute defined
*/
let internalAttributes = this->getAttributes();
let tagFactory = this->getTagFactory(),
internalAttributes = this->attributes;

if !fetch name, internalAttributes["id"] {
let name = this->name;
Expand All @@ -348,25 +349,23 @@ abstract class AbstractElement implements ElementInterface
let attributes["for"] = name;
}

let code = Tag::renderAttributes("<label", attributes);

/**
* Use the default label or leave the same name as label
*/
let label = this->label;
let labelName = this->label;

if label || is_numeric(label) {
let code .= ">" . label . "</label>";
} else {
let code .= ">" . name . "</label>";
if !(labelName || is_numeric(labelName)) {
let labelName = name;
}

let code = tagFactory->{"label"}(labelName, attributes);

return code;
}

/**
* Returns an array of prepared attributes for Phalcon\Tag helpers
* according to the element parameters
* Returns an array of prepared attributes for Phalcon\Html\TagFactory
* helpers according to the element parameters
*/
public function prepareAttributes(array attributes = [], bool useChecked = false) -> array
{
Expand All @@ -379,12 +378,8 @@ abstract class AbstractElement implements ElementInterface
/**
* Merge passed parameters with default ones
*/
let defaultAttributes = this->attributes;

let mergedAttributes = array_merge(
defaultAttributes,
attributes
);
let defaultAttributes = this->attributes,
mergedAttributes = array_merge(defaultAttributes, attributes);

/**
* Get the current element value
Expand Down Expand Up @@ -423,6 +418,29 @@ abstract class AbstractElement implements ElementInterface
return mergedAttributes;
}

/**
* Renders the element widget returning HTML
*/
public function render(array attributes = []) -> string
{
var helper, mergedAttributes, method, name, tagFactory, value;

let name = this->name,
value = null,
method = this->method,
tagFactory = this->getTagFactory(),
helper = tagFactory->newInstance(method);

if isset attributes["value"] {
let value = attributes["value"];
unset attributes["value"];
}

let mergedAttributes = array_merge(this->attributes, attributes);

return helper->__invoke(name, value, mergedAttributes);
}

/**
* Sets a default attribute for the element
*/
Expand Down Expand Up @@ -462,7 +480,7 @@ abstract class AbstractElement implements ElementInterface
public function setFilters(var filters) -> <ElementInterface>
{
if unlikely (typeof filters != "string" && typeof filters != "array") {
throw new Exception("Wrong filter type added");
throw new Exception("The filter needs to be an array or string");
}

let this->filters = filters;
Expand Down Expand Up @@ -510,6 +528,16 @@ abstract class AbstractElement implements ElementInterface
return this;
}

/**
* Sets the TagFactory
*/
public function setTagFactory(<TagFactory> tagFactory) -> <AbstractElement>
{
let this->tagFactory = tagFactory;

return this;
}

/**
* Sets an option for the element
*/
Expand All @@ -529,4 +557,18 @@ abstract class AbstractElement implements ElementInterface

return this;
}

/**
* Returns the tagFactory; throws exception if not present
*/
protected function getTagFactory() -> <TagFactory>
{
if unlikely empty this->tagFactory {
throw new Exception(
"The TagFactory must be set for this element to render"
);
}

return this->tagFactory;
}
}
22 changes: 11 additions & 11 deletions phalcon/Forms/Element/Check.zep
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@

namespace Phalcon\Forms\Element;

use Phalcon\Tag;

/**
* Phalcon\Forms\Element\Check
*
* Component INPUT[type=check] for forms
*/
class Check extends AbstractElement
{
/**
* Renders the element widget returning HTML
* @var string
*/
public function render(array attributes = []) -> string
{
return Tag::checkField(
this->prepareAttributes(attributes, true)
);
}
protected method = "inputCheckbox";
// /**
// * Renders the element widget returning HTML
// */
// public function render(array attributes = []) -> string
// {
// return Tag::checkField(
// this->prepareAttributes(attributes, true)
// );
// }
}
9 changes: 2 additions & 7 deletions phalcon/Forms/Element/Date.zep
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ use Phalcon\Tag;
class Date extends AbstractElement
{
/**
* Renders the element widget returning html
* @var string
*/
public function render(array attributes = []) -> string
{
return Tag::dateField(
this->prepareAttributes(attributes)
);
}
protected method = "inputDate";
}
9 changes: 2 additions & 7 deletions phalcon/Forms/Element/Email.zep
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ use Phalcon\Tag;
class Email extends AbstractElement
{
/**
* Renders the element widget returning HTML
* @var string
*/
public function render(array attributes = []) -> string
{
return Tag::emailField(
this->prepareAttributes(attributes)
);
}
protected method = "inputEmail";
}
9 changes: 2 additions & 7 deletions phalcon/Forms/Element/File.zep
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ use Phalcon\Tag;
class File extends AbstractElement
{
/**
* Renders the element widget returning HTML
* @var string
*/
public function render(array attributes = []) -> string
{
return Tag::fileField(
this->prepareAttributes(attributes)
);
}
protected method = "inputFile";
}
9 changes: 2 additions & 7 deletions phalcon/Forms/Element/Hidden.zep
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ use Phalcon\Tag;
class Hidden extends AbstractElement
{
/**
* Renders the element widget returning HTML
* @var string
*/
public function render(array attributes = []) -> string
{
return Tag::hiddenField(
this->prepareAttributes(attributes)
);
}
protected method = "inputHidden";
}
9 changes: 2 additions & 7 deletions phalcon/Forms/Element/Numeric.zep
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ use Phalcon\Tag;
class Numeric extends AbstractElement
{
/**
* Renders the element widget returning HTML
* @var string
*/
public function render(array attributes = []) -> string
{
return Tag::numericField(
this->prepareAttributes(attributes)
);
}
protected method = "inputNumeric";
}
9 changes: 2 additions & 7 deletions phalcon/Forms/Element/Password.zep
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ use Phalcon\Tag;
class Password extends AbstractElement
{
/**
* Renders the element widget returning HTML
* @var string
*/
public function render(array attributes = []) -> string
{
return Tag::passwordField(
this->prepareAttributes(attributes)
);
}
protected method = "inputPassword";
}
9 changes: 2 additions & 7 deletions phalcon/Forms/Element/Radio.zep
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ use Phalcon\Tag;
class Radio extends AbstractElement
{
/**
* Renders the element widget returning HTML
* @var string
*/
public function render(array attributes = []) -> string
{
return Tag::radioField(
this->prepareAttributes(attributes, true)
);
}
protected method = "inputRadio";
}
Loading

0 comments on commit 9992bb2

Please sign in to comment.