mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 10:04:41 +00:00
(mvc) add ChangeCase to base field type, enforces case on change event
This commit is contained in:
parent
89d73c568f
commit
c3358d74f8
@ -102,6 +102,11 @@ abstract class BaseField
|
||||
*/
|
||||
protected $internalAttributes = array();
|
||||
|
||||
/**
|
||||
* @var string $internalToLower
|
||||
*/
|
||||
private $internalChangeCase = null;
|
||||
|
||||
/**
|
||||
* generate a new UUID v4 number
|
||||
* @return string uuid v4 number
|
||||
@ -274,6 +279,11 @@ abstract class BaseField
|
||||
$this->internalInitialValue = $value;
|
||||
}
|
||||
$this->internalValue = $value;
|
||||
// apply filters, may be extended later.
|
||||
$filters = array('applyFilterChangeCase');
|
||||
foreach ($filters as $filter) {
|
||||
$this->$filter();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -539,6 +549,35 @@ abstract class BaseField
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* change character case on save
|
||||
* @param string $value set case type, upper, lower, null (don't change)
|
||||
*/
|
||||
public function setChangeCase($value)
|
||||
{
|
||||
if (strtoupper(trim($value)) == 'UPPER') {
|
||||
$this->internalChangeCase = 'UPPER';
|
||||
} elseif (strtoupper(trim($value)) == 'LOWER') {
|
||||
$this->internalChangeCase = 'LOWER';
|
||||
} else {
|
||||
$this->internalChangeCase = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* apply change case to this node, called by setValue
|
||||
*/
|
||||
private function applyFilterChangeCase()
|
||||
{
|
||||
if (!empty($this->internalValue)) {
|
||||
if ($this->internalChangeCase == 'UPPER') {
|
||||
$this->internalValue = strtoupper($this->internalValue);
|
||||
} elseif ($this->internalChangeCase == 'LOWER') {
|
||||
$this->internalValue = strtolower($this->internalValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return object type as string
|
||||
* @return string
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user