Fixed var names for framework.

This commit is contained in:
Dmitry Khomutov 2018-01-18 21:51:33 +07:00
commit dd1d7e2be3
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
25 changed files with 196 additions and 98 deletions

View file

@ -10,32 +10,32 @@ abstract class Element
/**
* @var string
*/
protected $_name;
protected $name;
/**
* @var string
*/
protected $_id;
protected $id;
/**
* @var string
*/
protected $_label;
protected $label;
/**
* @var string
*/
protected $_css;
protected $class;
/**
* @var string
*/
protected $_ccss;
protected $containerClass;
/**
* @var Element
*/
protected $_parent;
protected $parent;
/**
* @param string|null $name
@ -52,7 +52,7 @@ abstract class Element
*/
public function getName()
{
return $this->_name;
return $this->name;
}
/**
@ -62,7 +62,8 @@ abstract class Element
*/
public function setName($name)
{
$this->_name = strtolower(preg_replace('/([^a-zA-Z0-9_\-%])/', '', $name));
$this->name = strtolower(preg_replace('/([^a-zA-Z0-9_\-%])/', '', $name));
return $this;
}
@ -71,7 +72,9 @@ abstract class Element
*/
public function getId()
{
return !$this->_id ? 'element-' . $this->_name : $this->_id;
return !$this->id
? ('element-' . $this->name)
: $this->id;
}
/**
@ -81,7 +84,8 @@ abstract class Element
*/
public function setId($id)
{
$this->_id = $id;
$this->id = $id;
return $this;
}
@ -90,7 +94,7 @@ abstract class Element
*/
public function getLabel()
{
return $this->_label;
return $this->label;
}
/**
@ -100,7 +104,8 @@ abstract class Element
*/
public function setLabel($label)
{
$this->_label = $label;
$this->label = $label;
return $this;
}
@ -109,7 +114,7 @@ abstract class Element
*/
public function getClass()
{
return $this->_css;
return $this->class;
}
/**
@ -119,7 +124,8 @@ abstract class Element
*/
public function setClass($class)
{
$this->_css = $class;
$this->class = $class;
return $this;
}
@ -128,7 +134,7 @@ abstract class Element
*/
public function getContainerClass()
{
return $this->_ccss;
return $this->containerClass;
}
/**
@ -138,7 +144,8 @@ abstract class Element
*/
public function setContainerClass($class)
{
$this->_ccss = $class;
$this->containerClass = $class;
return $this;
}
@ -149,7 +156,8 @@ abstract class Element
*/
public function setParent(Element $parent)
{
$this->_parent = $parent;
$this->parent = $parent;
return $this;
}
@ -173,12 +181,12 @@ abstract class Element
$view = new View($viewFile, B8_PATH . 'Form/View/');
}
$view->name = $this->getName();
$view->id = $this->getId();
$view->label = $this->getLabel();
$view->css = $this->getClass();
$view->ccss = $this->getContainerClass();
$view->parent = $this->_parent;
$view->name = $this->getName();
$view->id = $this->getId();
$view->label = $this->getLabel();
$view->class = $this->getClass();
$view->containerClass = $this->getContainerClass();
$view->parent = $this->parent;
$this->onPreRender($view);

View file

@ -10,19 +10,19 @@ class Checkbox extends Input
/**
* @var boolean
*/
protected $_checked;
protected $checked;
/**
* @var mixed
*/
protected $_checkedValue;
protected $checkedValue;
/**
* @return mixed
*/
public function getCheckedValue()
{
return $this->_checkedValue;
return $this->checkedValue;
}
/**
@ -30,7 +30,7 @@ class Checkbox extends Input
*/
public function setCheckedValue($value)
{
$this->_checkedValue = $value;
$this->checkedValue = $value;
}
/**
@ -39,19 +39,19 @@ class Checkbox extends Input
public function setValue($value)
{
if (is_bool($value) && $value === true) {
$this->_value = $this->getCheckedValue();
$this->_checked = true;
$this->value = $this->getCheckedValue();
$this->checked = true;
return;
}
if ($value == $this->getCheckedValue()) {
$this->_value = $this->getCheckedValue();
$this->_checked = true;
$this->value = $this->getCheckedValue();
$this->checked = true;
return;
}
$this->_value = $value;
$this->_checked = false;
$this->value = $value;
$this->checked = false;
}
/**
@ -62,6 +62,6 @@ class Checkbox extends Input
parent::onPreRender($view);
$view->checkedValue = $this->getCheckedValue();
$view->checked = $this->_checked;
$view->checked = $this->checked;
}
}

View file

@ -9,14 +9,14 @@ class Csrf extends Hidden
/**
* @var integer
*/
protected $_rows = 4;
protected $rows = 4;
/**
* @return boolean
*/
public function validate()
{
if ($this->_value != $_COOKIE[$this->getName()]) {
if ($this->value != $_COOKIE[$this->getName()]) {
return false;
}

View file

@ -10,14 +10,14 @@ class Select extends Input
/**
* @var array
*/
protected $_options = [];
protected $options = [];
/**
* @param array $options
*/
public function setOptions(array $options)
{
$this->_options = $options;
$this->options = $options;
}
/**
@ -27,6 +27,6 @@ class Select extends Input
{
parent::onPreRender($view);
$view->options = $this->_options;
$view->options = $this->options;
}
}

View file

@ -9,7 +9,7 @@ class Submit extends Button
/**
* @var string
*/
protected $_value = 'Submit';
protected $value = 'Submit';
/**
* @param string $viewFile

View file

@ -9,14 +9,14 @@ class TextArea extends Text
/**
* @var integer
*/
protected $_rows = 4;
protected $rows = 4;
/**
* @return integer
*/
public function getRows()
{
return $this->_rows;
return $this->rows;
}
/**
@ -24,7 +24,7 @@ class TextArea extends Text
*/
public function setRows($rows)
{
$this->_rows = $rows;
$this->rows = $rows;
}
/**

View file

@ -9,7 +9,7 @@ class FieldSet extends Element
/**
* @var Element[]
*/
protected $_children = [];
protected $children = [];
/**
* @return array
@ -17,7 +17,7 @@ class FieldSet extends Element
public function getValues()
{
$rtn = [];
foreach ($this->_children as $field) {
foreach ($this->children as $field) {
if ($field instanceof FieldSet) {
$fieldName = $field->getName();
@ -41,7 +41,7 @@ class FieldSet extends Element
*/
public function setValues(array $values)
{
foreach ($this->_children as $field) {
foreach ($this->children as $field) {
if ($field instanceof FieldSet) {
$fieldName = $field->getName();
@ -65,7 +65,7 @@ class FieldSet extends Element
*/
public function addField(Element $field)
{
$this->_children[$field->getName()] = $field;
$this->children[$field->getName()] = $field;
$field->setParent($this);
}
@ -76,7 +76,7 @@ class FieldSet extends Element
{
$rtn = true;
foreach ($this->_children as $child) {
foreach ($this->children as $child) {
if (!$child->validate()) {
$rtn = false;
}
@ -91,7 +91,7 @@ class FieldSet extends Element
protected function onPreRender(View &$view)
{
$rendered = [];
foreach ($this->_children as $child) {
foreach ($this->children as $child) {
$rendered[] = $child->render();
}
@ -103,7 +103,7 @@ class FieldSet extends Element
*/
public function getChildren()
{
return $this->_children;
return $this->children;
}
/**
@ -113,6 +113,6 @@ class FieldSet extends Element
*/
public function getChild($fieldName)
{
return $this->_children[$fieldName];
return $this->children[$fieldName];
}
}

View file

@ -24,7 +24,7 @@ class Input extends Element
/**
* @var mixed
*/
protected $_value;
protected $value;
/**
* @var string
@ -58,7 +58,7 @@ class Input extends Element
*/
public function getValue()
{
return $this->_value;
return $this->value;
}
/**
@ -68,7 +68,7 @@ class Input extends Element
*/
public function setValue($value)
{
$this->_value = $value;
$this->value = $value;
return $this;
}
@ -140,12 +140,12 @@ class Input extends Element
*/
public function validate()
{
if ($this->getRequired() && empty($this->_value)) {
if ($this->getRequired() && empty($this->value)) {
$this->_error = $this->getLabel() . ' is required.';
return false;
}
if ($this->getPattern() && !preg_match('/' . $this->getPattern() . '/', $this->_value)) {
if ($this->getPattern() && !preg_match('/' . $this->getPattern() . '/', $this->value)) {
$this->_error = 'Invalid value entered.';
return false;
@ -155,7 +155,7 @@ class Input extends Element
if (is_callable($validator)) {
try {
call_user_func_array($validator, [$this->_value]);
call_user_func_array($validator, [$this->value]);
} catch (\Exception $ex) {
$this->_error = $ex->getMessage();

View file

@ -1 +1 @@
<input class="btn <?= $css; ?>" type="<?= $type; ?>" value="<?= $value; ?>">
<input class="btn <?= $class; ?>" type="<?= $type; ?>" value="<?= $value; ?>">

View file

@ -1,9 +1,9 @@
<?php if (!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
<div class="control-group <?= $ccss ?> <?= (isset($error) ? 'error' : ''); ?>">
<div class="control-group <?= $containerClass ?> <?= (isset($error) ? 'error' : ''); ?>">
<div class="controls">
<div class="checkbox">
<?php endif; ?>
<label class="checkbox <?= $css; ?>" for="<?= $id ?>">
<label class="checkbox <?= $class; ?>" for="<?= $id ?>">
<input type="checkbox" id="<?= $id; ?>" name="<?= $name; ?>"
value="<?= $checkedValue; ?>"
<?= ($checked ? 'checked' : ''); ?> <?= $required ? 'required' : '' ?>

View file

@ -1,4 +1,4 @@
<div class="control-group <?= $css; ?>">
<div class="control-group <?= $class; ?>">
<?php if ($label): ?>
<label class="control-label"><?= $label; ?></label>
<?php endif; ?>

View file

@ -1,4 +1,4 @@
<div class="control-group <?= $css; ?>">
<div class="control-group <?= $class; ?>">
<?php foreach ($children as $field): ?>
<?= $field; ?>
<?php endforeach; ?>

View file

@ -1,4 +1,4 @@
<fieldset class="row <?= $css; ?>">
<fieldset class="row <?= $class; ?>">
<?php if ($label): ?>
<legend><?= $label; ?></legend>
<?php endif; ?>

View file

@ -1,4 +1,4 @@
<form id="<?= $id; ?>" class="<?= $css; ?>" action="<?= $action; ?>" method="<?= $method; ?>">
<form id="<?= $id; ?>" class="<?= $class; ?>" action="<?= $action; ?>" method="<?= $method; ?>">
<?php foreach ($children as $field): ?>
<?= $field; ?>
<?php endforeach; ?>

View file

@ -1,11 +1,11 @@
<div id="<?= $id; ?>" class="control-group <?= $ccss; ?>">
<div id="<?= $id; ?>" class="control-group <?= $containerClass; ?>">
<?php if ($label): ?>
<label class="control-label"><?= $label; ?></label>
<?php endif; ?>
<div class="controls">
<?php foreach ($options as $val => $lbl): ?>
<label class="radio" for="radio-<?= $id; ?>-<?= $val; ?>">
<input type="radio" id="radio-<?= $id; ?>-<?= $val; ?>" class="<?= $css; ?>"
<input type="radio" id="radio-<?= $id; ?>-<?= $val; ?>" class="<?= $class; ?>"
name="<?= $name; ?>"
value="<?= $val; ?>"
<?= ($value == $val) ? ' checked="checked"' : ''; ?> <?= $required ? 'required' : '' ?>

View file

@ -1,10 +1,10 @@
<div class="control-group <?= $ccss; ?>">
<div class="control-group <?= $containerClass; ?>">
<?php if ($label): ?>
<label class="control-label" for="<?= $id ?>"><?= $label; ?></label>
<?php endif; ?>
<div class="controls">
<select id="<?= $id; ?>" class="<?= $css; ?>" name="<?= $name; ?>">
<select id="<?= $id; ?>" class="<?= $class; ?>" name="<?= $name; ?>">
<?php foreach ($options as $val => $lbl): ?>
<option
value="<?= $val; ?>" <?= ($value == $val) ? ' selected="selected"' : ''; ?>

View file

@ -1,10 +1,10 @@
<div class="control-group <?= $ccss; ?> <?= (isset($error) ? 'error' : ''); ?>">
<div class="control-group <?= $containerClass; ?> <?= (isset($error) ? 'error' : ''); ?>">
<?php if ($label): ?>
<label class="control-label" for="<?= $id ?>"><?= $label; ?></label>
<?php endif; ?>
<div class="controls">
<input id="<?= $id; ?>" type="<?= $type; ?>" class="<?= $css; ?>"
<input id="<?= $id; ?>" type="<?= $type; ?>" class="<?= $class; ?>"
name="<?= $name; ?>"
<?= isset($value) ? ' value="' . $value . '"' : '' ?>
<?= isset($pattern) ? ' pattern="' . $pattern . '"' : '' ?>

View file

@ -1,9 +1,9 @@
<div class="control-group <?= $ccss; ?> <?= (isset($error) ? 'error' : ''); ?>">
<div class="control-group <?= $containerClass; ?> <?= (isset($error) ? 'error' : ''); ?>">
<?php if ($label): ?>
<label class="control-label" for="<?= $id ?>"><?= $label; ?></label>
<?php endif; ?>
<div class="controls">
<textarea rows="<?= $rows; ?>" id="<?= $id; ?>" class="<?= $css; ?>"
<textarea rows="<?= $rows; ?>" id="<?= $id; ?>" class="<?= $class; ?>"
name="<?= $name; ?>" <?= $required ? ' required' : '' ?>><?= isset($value) ? $value : '' ?></textarea>
<?php if (isset($error)): ?>