Fixed var names for framework.
This commit is contained in:
parent
e59e4a397f
commit
dd1d7e2be3
25 changed files with 196 additions and 98 deletions
|
|
@ -3,9 +3,9 @@
|
|||
namespace b8;
|
||||
|
||||
use b8\Exception\HttpException\NotFoundException;
|
||||
use b8\Http;
|
||||
use b8\Http\Response;
|
||||
use b8\Http\Request;
|
||||
use b8\Http\Router;
|
||||
|
||||
class Application
|
||||
{
|
||||
|
|
@ -34,23 +34,28 @@ class Application
|
|||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var Router
|
||||
*/
|
||||
protected $router;
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
*
|
||||
* @param Request|null $request
|
||||
*/
|
||||
public function __construct(Config $config, Http\Request $request = null)
|
||||
public function __construct(Config $config, Request $request = null)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->response = new Http\Response();
|
||||
$this->response = new Response();
|
||||
|
||||
if (!is_null($request)) {
|
||||
$this->request = $request;
|
||||
} else {
|
||||
$this->request = new Http\Request();
|
||||
$this->request = new Request();
|
||||
}
|
||||
|
||||
$this->router = new Http\Router($this, $this->request, $this->config);
|
||||
$this->router = new Router($this, $this->request, $this->config);
|
||||
|
||||
if (method_exists($this, 'init')) {
|
||||
$this->init();
|
||||
|
|
@ -92,9 +97,10 @@ class Application
|
|||
public function getController()
|
||||
{
|
||||
if (empty($this->controller)) {
|
||||
$controllerClass = $this->getControllerClass($this->route);
|
||||
$controllerClass = $this->getControllerClass($this->route);
|
||||
$this->controller = $this->loadController($controllerClass);
|
||||
}
|
||||
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
|
|
@ -105,8 +111,10 @@ class Application
|
|||
*/
|
||||
protected function loadController($class)
|
||||
{
|
||||
/** @var Controller $controller */
|
||||
$controller = new $class($this->config, $this->request, $this->response);
|
||||
$controller->init();
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
|
|
@ -127,8 +135,9 @@ class Application
|
|||
*/
|
||||
protected function getControllerClass($route)
|
||||
{
|
||||
$namespace = $this->toPhpName($route['namespace']);
|
||||
$namespace = $this->toPhpName($route['namespace']);
|
||||
$controller = $this->toPhpName($route['controller']);
|
||||
|
||||
return $this->config->get('b8.app.namespace') . '\\' . $namespace . '\\' . $controller . 'Controller';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class Config
|
|||
{
|
||||
// Path to a YAML file.
|
||||
$parser = new YamlParser();
|
||||
$yaml = file_get_contents($yamlFile);
|
||||
$yaml = file_get_contents($yamlFile);
|
||||
$config = (array)$parser->parse($yaml);
|
||||
|
||||
if (empty($config)) {
|
||||
|
|
@ -75,7 +75,7 @@ class Config
|
|||
$keyParts = explode('.', $key);
|
||||
$selected = $this->config;
|
||||
|
||||
$i = -1;
|
||||
$i = -1;
|
||||
$last_part = count($keyParts) - 1;
|
||||
while ($part = array_shift($keyParts)) {
|
||||
$i++;
|
||||
|
|
@ -180,6 +180,7 @@ class Config
|
|||
$source = $target;
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($target as $target_key => $target_value) {
|
||||
if (isset($source[$target_key])) {
|
||||
if (!is_array($source[$target_key]) && !is_array($target_value)) {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ class Database extends \PDO
|
|||
}
|
||||
|
||||
self::$lastUsed[$type] = time();
|
||||
|
||||
return self::$connections[$type];
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +135,7 @@ class Database extends \PDO
|
|||
} elseif ('pgsql' === self::$details['type']) {
|
||||
$quote = '"';
|
||||
}
|
||||
|
||||
|
||||
$statement = preg_replace('/{{(.*?)}}/', ($quote . '\1' . $quote), $statement);
|
||||
|
||||
return parent::prepare($statement, $driver_options);
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@ class Form extends FieldSet
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_action = '';
|
||||
protected $action = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_method = 'POST';
|
||||
protected $method = 'POST';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAction()
|
||||
{
|
||||
return $this->_action;
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -29,7 +29,7 @@ class Form extends FieldSet
|
|||
*/
|
||||
public function setAction($action)
|
||||
{
|
||||
$this->_action = $action;
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,7 +37,7 @@ class Form extends FieldSet
|
|||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->_method;
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -45,7 +45,7 @@ class Form extends FieldSet
|
|||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->_method = $method;
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class Submit extends Button
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_value = 'Submit';
|
||||
protected $value = 'Submit';
|
||||
|
||||
/**
|
||||
* @param string $viewFile
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<input class="btn <?= $css; ?>" type="<?= $type; ?>" value="<?= $value; ?>">
|
||||
<input class="btn <?= $class; ?>" type="<?= $type; ?>" value="<?= $value; ?>">
|
||||
|
|
|
|||
|
|
@ -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' : '' ?>
|
||||
|
|
|
|||
|
|
@ -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; ?>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<div class="control-group <?= $css; ?>">
|
||||
<div class="control-group <?= $class; ?>">
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?= $field; ?>
|
||||
<?php endforeach; ?>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<fieldset class="row <?= $css; ?>">
|
||||
<fieldset class="row <?= $class; ?>">
|
||||
<?php if ($label): ?>
|
||||
<legend><?= $label; ?></legend>
|
||||
<?php endif; ?>
|
||||
|
|
|
|||
|
|
@ -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; ?>
|
||||
|
|
|
|||
|
|
@ -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' : '' ?>
|
||||
|
|
|
|||
|
|
@ -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"' : ''; ?>
|
||||
|
|
|
|||
|
|
@ -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 . '"' : '' ?>
|
||||
|
|
|
|||
|
|
@ -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)): ?>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ class Model
|
|||
protected $tableName;
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @param array $initialData
|
||||
*/
|
||||
public function __construct($initialData = [])
|
||||
{
|
||||
if (is_array($initialData)) {
|
||||
|
|
@ -23,11 +26,20 @@ class Model
|
|||
$this->cache = Cache::getCache(Cache::TYPE_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $depth
|
||||
* @param integer $currentDepth
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($depth = 2, $currentDepth = 0)
|
||||
{
|
||||
if (isset(static::$sleepable) && is_array(static::$sleepable) && count(static::$sleepable)) {
|
||||
|
|
@ -44,6 +56,13 @@ class Model
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $property
|
||||
* @param integer $currentDepth
|
||||
* @param integer $depth
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function propertyToArray($property, $currentDepth, $depth)
|
||||
{
|
||||
$rtn = null;
|
||||
|
|
@ -60,6 +79,13 @@ class Model
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param integer $currentDepth
|
||||
* @param integer $depth
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function valueToArray($value, $currentDepth, $depth)
|
||||
{
|
||||
$rtn = null;
|
||||
|
|
@ -84,16 +110,25 @@ class Model
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDataArray()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getModified()
|
||||
{
|
||||
return $this->modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $values
|
||||
*/
|
||||
public function setValues(array $values)
|
||||
{
|
||||
foreach ($values as $key => $value) {
|
||||
|
|
@ -113,11 +148,20 @@ class Model
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
*/
|
||||
protected function setModified($column)
|
||||
{
|
||||
$this->modified[$column] = $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws HttpException\ValidationException
|
||||
*/
|
||||
protected function validateString($name, $value)
|
||||
{
|
||||
if (!is_string($value) && !is_null($value)) {
|
||||
|
|
@ -125,6 +169,12 @@ class Model
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws HttpException\ValidationException
|
||||
*/
|
||||
protected function validateInt($name, &$value)
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
|
|
@ -140,6 +190,12 @@ class Model
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws HttpException\ValidationException
|
||||
*/
|
||||
protected function validateFloat($name, &$value)
|
||||
{
|
||||
if (!is_numeric($value) && !is_null($value)) {
|
||||
|
|
@ -151,6 +207,12 @@ class Model
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws HttpException\ValidationException
|
||||
*/
|
||||
protected function validateDate($name, &$value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
|
|
@ -164,6 +226,12 @@ class Model
|
|||
$value = empty($value) ? null : $value->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws HttpException\ValidationException
|
||||
*/
|
||||
protected function validateNotNull($name, $value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
|
|
@ -171,6 +239,11 @@ class Model
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
if (array_key_exists($key, $this->getters)) {
|
||||
|
|
@ -181,6 +254,12 @@ class Model
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
if (array_key_exists($key, $this->setters)) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ namespace b8;
|
|||
|
||||
class View
|
||||
{
|
||||
protected $_vars = [];
|
||||
protected static $_helpers = [];
|
||||
protected $vars = [];
|
||||
protected static $helpers = [];
|
||||
protected static $extension = 'phtml';
|
||||
|
||||
public function __construct($file, $path = null)
|
||||
|
|
@ -36,22 +36,22 @@ class View
|
|||
|
||||
public function __isset($var)
|
||||
{
|
||||
return isset($this->_vars[$var]);
|
||||
return isset($this->vars[$var]);
|
||||
}
|
||||
|
||||
public function __get($var)
|
||||
{
|
||||
return $this->_vars[$var];
|
||||
return $this->vars[$var];
|
||||
}
|
||||
|
||||
public function __set($var, $val)
|
||||
{
|
||||
$this->_vars[$var] = $val;
|
||||
$this->vars[$var] = $val;
|
||||
}
|
||||
|
||||
public function __call($method, $params = [])
|
||||
{
|
||||
if (!isset(self::$_helpers[$method])) {
|
||||
if (!isset(self::$helpers[$method])) {
|
||||
$class = '\\' . Config::getInstance()->get('b8.app.namespace') . '\\Helper\\' . $method;
|
||||
|
||||
if (!class_exists($class)) {
|
||||
|
|
@ -62,15 +62,15 @@ class View
|
|||
throw new \Exception('Helper class does not exist: ' . $class);
|
||||
}
|
||||
|
||||
self::$_helpers[$method] = new $class();
|
||||
self::$helpers[$method] = new $class();
|
||||
}
|
||||
|
||||
return self::$_helpers[$method];
|
||||
return self::$helpers[$method];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
extract($this->_vars);
|
||||
extract($this->vars);
|
||||
|
||||
ob_start();
|
||||
require($this->viewFile);
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ class Template extends View
|
|||
$thisPart = array_shift($varPart);
|
||||
|
||||
|
||||
if (!array_key_exists($thisPart, $this->_vars)) {
|
||||
if (!array_key_exists($thisPart, $this->vars)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue