Code style fixes.
This commit is contained in:
parent
fa569f3e22
commit
4e68eb7180
89 changed files with 942 additions and 251 deletions
|
|
@ -20,20 +20,25 @@ class Application
|
|||
protected $controller;
|
||||
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @var Response
|
||||
*/
|
||||
* @var Response
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
*
|
||||
* @param Request|null $request
|
||||
*/
|
||||
public function __construct(Config $config, Http\Request $request = null)
|
||||
{
|
||||
$this->config = $config;
|
||||
|
|
@ -52,6 +57,11 @@ class Application
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function handleRequest()
|
||||
{
|
||||
$this->route = $this->router->dispatch();
|
||||
|
|
@ -90,7 +100,7 @@ class Application
|
|||
|
||||
/**
|
||||
* @param string $class
|
||||
*
|
||||
*
|
||||
* @return Controller
|
||||
*/
|
||||
protected function loadController($class)
|
||||
|
|
@ -102,7 +112,7 @@ class Application
|
|||
|
||||
/**
|
||||
* @param array $route
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function controllerExists($route)
|
||||
|
|
@ -112,7 +122,7 @@ class Application
|
|||
|
||||
/**
|
||||
* @param array $route
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getControllerClass($route)
|
||||
|
|
@ -122,7 +132,12 @@ class Application
|
|||
return $this->config->get('b8.app.namespace') . '\\' . $namespace . '\\' . $controller . 'Controller';
|
||||
}
|
||||
|
||||
public function isValidRoute($route)
|
||||
/**
|
||||
* @param array $route
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValidRoute(array $route)
|
||||
{
|
||||
if ($this->controllerExists($route)) {
|
||||
return true;
|
||||
|
|
@ -131,6 +146,11 @@ class Application
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function toPhpName($string)
|
||||
{
|
||||
$string = str_replace('-', ' ', $string);
|
||||
|
|
|
|||
|
|
@ -2,16 +2,14 @@
|
|||
|
||||
namespace b8;
|
||||
|
||||
/**
|
||||
* @package b8
|
||||
* @subpackage Cache
|
||||
*/
|
||||
|
||||
class Cache
|
||||
{
|
||||
const TYPE_APC = 'ApcCache';
|
||||
const TYPE_REQUEST = 'RequestCache';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $instance = [];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -10,8 +10,14 @@ if (!defined('B8_PATH')) {
|
|||
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
return self::$instance;
|
||||
|
|
@ -22,6 +28,9 @@ class Config
|
|||
*/
|
||||
protected $config = [];
|
||||
|
||||
/**
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct($settings = null)
|
||||
{
|
||||
self::$instance = $this;
|
||||
|
|
@ -36,6 +45,9 @@ class Config
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $yamlFile
|
||||
*/
|
||||
public function loadYaml($yamlFile)
|
||||
{
|
||||
// Path to a YAML file.
|
||||
|
|
@ -52,8 +64,10 @@ class Config
|
|||
|
||||
/**
|
||||
* Get a configuration value by key, returning a default value if not set.
|
||||
* @param $key string
|
||||
* @param $default mixed
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
|
|
@ -82,9 +96,10 @@ class Config
|
|||
|
||||
/**
|
||||
* Set a value by key.
|
||||
* @param $key string
|
||||
* @param $value mixed
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function set($key, $value = null)
|
||||
|
|
@ -96,6 +111,8 @@ class Config
|
|||
|
||||
/**
|
||||
* Set an array of values.
|
||||
*
|
||||
* @param $array
|
||||
*/
|
||||
public function setArray($array)
|
||||
{
|
||||
|
|
@ -105,6 +122,10 @@ class Config
|
|||
/**
|
||||
* Short-hand syntax for get()
|
||||
* @see Config::get()
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
|
|
@ -114,6 +135,11 @@ class Config
|
|||
/**
|
||||
* Short-hand syntax for set()
|
||||
* @see Config::set()
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __set($key, $value = null)
|
||||
{
|
||||
|
|
@ -122,6 +148,10 @@ class Config
|
|||
|
||||
/**
|
||||
* Is set
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function __isset($key)
|
||||
{
|
||||
|
|
@ -130,6 +160,8 @@ class Config
|
|||
|
||||
/**
|
||||
* Unset
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function __unset($key)
|
||||
{
|
||||
|
|
@ -137,8 +169,8 @@ class Config
|
|||
}
|
||||
|
||||
/**
|
||||
* Deeply merge the $target array onto the $source array.
|
||||
* The $source array will be modified!
|
||||
* Deeply merge the $target array onto the $source array. The $source array will be modified!
|
||||
*
|
||||
* @param array $source
|
||||
* @param array $target
|
||||
*/
|
||||
|
|
@ -153,7 +185,6 @@ class Config
|
|||
if (!is_array($source[$target_key]) && !is_array($target_value)) {
|
||||
// Neither value is an array, overwrite
|
||||
$source[$target_key] = $target_value;
|
||||
|
||||
} elseif (is_array($source[$target_key]) && is_array($target_value)) {
|
||||
// Both are arrays, deep merge them
|
||||
self::deepMerge($source[$target_key], $target_value);
|
||||
|
|
@ -173,6 +204,9 @@ class Config
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getArray()
|
||||
{
|
||||
return $this->config;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,7 @@ namespace b8;
|
|||
|
||||
use b8\Http\Request;
|
||||
use b8\Http\Response;
|
||||
use b8\View;
|
||||
|
||||
/**
|
||||
* b8 Abstract Controller class
|
||||
* @package b8
|
||||
*/
|
||||
abstract class Controller
|
||||
{
|
||||
/**
|
||||
|
|
@ -37,6 +32,11 @@ abstract class Controller
|
|||
*/
|
||||
protected $view;
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
*/
|
||||
public function __construct(Config $config, Request $request, Response $response)
|
||||
{
|
||||
$this->config = $config;
|
||||
|
|
@ -44,6 +44,11 @@ abstract class Controller
|
|||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasAction($name)
|
||||
{
|
||||
if (method_exists($this, $name)) {
|
||||
|
|
@ -59,6 +64,10 @@ abstract class Controller
|
|||
|
||||
/**
|
||||
* Handles an action on this controller and returns a Response object.
|
||||
*
|
||||
* @param string $action
|
||||
* @param array $actionParams
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handleAction($action, $actionParams)
|
||||
|
|
@ -84,8 +93,8 @@ abstract class Controller
|
|||
/**
|
||||
* Get a specific incoming request parameter.
|
||||
*
|
||||
* @param $key
|
||||
* @param mixed $default Default return value (if key does not exist)
|
||||
* @param string $key
|
||||
* @param mixed $default Default return value (if key does not exist)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
|
@ -96,20 +105,22 @@ abstract class Controller
|
|||
|
||||
/**
|
||||
* Change the value of an incoming request parameter.
|
||||
* @param $key
|
||||
* @param $value
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setParam($key, $value)
|
||||
{
|
||||
return $this->request->setParam($key, $value);
|
||||
$this->request->setParam($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an incoming request parameter.
|
||||
* @param $key
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function unsetParam($key)
|
||||
{
|
||||
return $this->request->unsetParam($key);
|
||||
$this->request->unsetParam($key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class Database extends \PDO
|
|||
* @param string $type
|
||||
*
|
||||
* @return \b8\Database
|
||||
*
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getConnection($type = 'read')
|
||||
|
|
|
|||
|
|
@ -4,19 +4,35 @@ namespace b8\Exception;
|
|||
|
||||
class HttpException extends \Exception
|
||||
{
|
||||
protected $errorCode = 500;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $errorCode = 500;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $statusMessage = 'Internal Server Error';
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatusMessage()
|
||||
{
|
||||
return $this->statusMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHttpHeader()
|
||||
{
|
||||
return 'HTTP/1.1 ' . $this->errorCode . ' ' . $this->statusMessage;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,13 @@ use b8\Exception\HttpException;
|
|||
|
||||
class BadRequestException extends HttpException
|
||||
{
|
||||
protected $errorCode = 400;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $errorCode = 400;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $statusMessage = 'Bad Request';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,13 @@ use b8\Exception\HttpException;
|
|||
|
||||
class ForbiddenException extends HttpException
|
||||
{
|
||||
protected $errorCode = 403;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $errorCode = 403;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $statusMessage = 'Forbidden';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,13 @@ use b8\Exception\HttpException;
|
|||
|
||||
class NotAuthorizedException extends HttpException
|
||||
{
|
||||
protected $errorCode = 401;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $errorCode = 401;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $statusMessage = 'Not Authorized';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,13 @@ use b8\Exception\HttpException;
|
|||
|
||||
class NotFoundException extends HttpException
|
||||
{
|
||||
protected $errorCode = 404;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $errorCode = 404;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $statusMessage = 'Not Found';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,13 @@ use b8\Exception\HttpException;
|
|||
|
||||
class ValidationException extends HttpException
|
||||
{
|
||||
protected $errorCode = 400;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $errorCode = 400;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $statusMessage = 'Bad Request';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,33 +2,55 @@
|
|||
|
||||
namespace b8;
|
||||
|
||||
use b8\Form\FieldSet, b8\View;
|
||||
use b8\Form\FieldSet;
|
||||
|
||||
class Form extends FieldSet
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_action = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_method = 'POST';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAction()
|
||||
{
|
||||
return $this->_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
*/
|
||||
public function setAction($action)
|
||||
{
|
||||
$this->_action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->_method = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
$view->action = $this->getAction();
|
||||
|
|
@ -37,6 +59,9 @@ class Form extends FieldSet
|
|||
parent::onPreRender($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render();
|
||||
|
|
|
|||
|
|
@ -7,13 +7,39 @@ use b8\Config;
|
|||
|
||||
abstract class Element
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_label;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_css;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_ccss;
|
||||
|
||||
/**
|
||||
* @var Element
|
||||
*/
|
||||
protected $_parent;
|
||||
|
||||
/**
|
||||
* @param string|null $name
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
if (!is_null($name)) {
|
||||
|
|
@ -21,73 +47,123 @@ abstract class Element
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = strtolower(preg_replace('/([^a-zA-Z0-9_\-%])/', '', $name));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return !$this->_id ? 'element-' . $this->_name : $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->_id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->_label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->_label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getClass()
|
||||
{
|
||||
return $this->_css;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setClass($class)
|
||||
{
|
||||
$this->_css = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContainerClass()
|
||||
{
|
||||
return $this->_ccss;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainerClass($class)
|
||||
{
|
||||
$this->_ccss = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Element $parent
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParent(Element $parent)
|
||||
{
|
||||
$this->_parent = $parent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewFile
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
$viewPath = Config::getInstance()->get('b8.view.path');
|
||||
|
||||
if (is_null($viewFile)) {
|
||||
$class = explode('\\', get_called_class());
|
||||
$class = explode('\\', get_called_class());
|
||||
$viewFile = end($class);
|
||||
}
|
||||
|
||||
|
|
@ -109,5 +185,8 @@ abstract class Element
|
|||
return $view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
abstract protected function onPreRender(View &$view);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,26 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\Form\Input, b8\View;
|
||||
use b8\Form\Input;
|
||||
use b8\View;
|
||||
|
||||
class Button extends Input
|
||||
{
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->type = 'button';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,23 +2,40 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View, b8\Form\Input;
|
||||
use b8\View;
|
||||
use b8\Form\Input;
|
||||
|
||||
class Checkbox extends Input
|
||||
{
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_checked;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_checkedValue;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCheckedValue()
|
||||
{
|
||||
return $this->_checkedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setCheckedValue($value)
|
||||
{
|
||||
$this->_checkedValue = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
if (is_bool($value) && $value === true) {
|
||||
|
|
@ -33,13 +50,17 @@ class Checkbox extends Input
|
|||
return;
|
||||
}
|
||||
|
||||
$this->_value = $value;
|
||||
$this->_value = $value;
|
||||
$this->_checked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
public function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->checkedValue = $this->getCheckedValue();
|
||||
$view->checked = $this->_checked;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,14 @@ use b8\View;
|
|||
|
||||
class Csrf extends Hidden
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $_rows = 4;
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if ($this->_value != $_COOKIE[$this->getName()]) {
|
||||
|
|
@ -17,11 +23,16 @@ class Csrf extends Hidden
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
$csrf = md5(microtime(true));
|
||||
|
||||
$csrf = md5(microtime(true));
|
||||
$view->csrf = $csrf;
|
||||
|
||||
setcookie($this->getName(), $csrf);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,23 @@ use b8\View;
|
|||
|
||||
class Email extends Text
|
||||
{
|
||||
/**
|
||||
* @param string $viewFile
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->type = 'email';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,23 @@ use b8\View;
|
|||
|
||||
class Password extends Text
|
||||
{
|
||||
/**
|
||||
* @param string $viewFile
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->type = 'password';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,20 +2,31 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View, b8\Form\Input;
|
||||
use b8\View;
|
||||
use b8\Form\Input;
|
||||
|
||||
class Select extends Input
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = [];
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->options = $this->_options;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,16 +6,28 @@ use b8\View;
|
|||
|
||||
class Submit extends Button
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_value = 'Submit';
|
||||
|
||||
/**
|
||||
* @param string $viewFile
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Button'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->type = 'submit';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,18 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\Form\Input, b8\View;
|
||||
use b8\Form\Input;
|
||||
use b8\View;
|
||||
|
||||
class Text extends Input
|
||||
{
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->type = 'text';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,21 +6,34 @@ use b8\View;
|
|||
|
||||
class TextArea extends Text
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $_rows = 4;
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getRows()
|
||||
{
|
||||
return $this->_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $rows
|
||||
*/
|
||||
public function setRows($rows)
|
||||
{
|
||||
$this->_rows = $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->rows = $this->getRows();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,23 @@ use b8\View;
|
|||
|
||||
class Url extends Text
|
||||
{
|
||||
/**
|
||||
* @param string $viewFile
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
parent::onPreRender($view);
|
||||
|
||||
$view->type = 'url';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
namespace b8\Form;
|
||||
|
||||
use b8\Form\Element, b8\View;
|
||||
use b8\View;
|
||||
|
||||
class FieldSet extends Element
|
||||
{
|
||||
/**
|
||||
* @var Element[]
|
||||
*/
|
||||
protected $_children = [];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
$rtn = [];
|
||||
|
|
@ -30,6 +36,9 @@ class FieldSet extends Element
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $values
|
||||
*/
|
||||
public function setValues(array $values)
|
||||
{
|
||||
foreach ($this->_children as $field) {
|
||||
|
|
@ -51,12 +60,18 @@ class FieldSet extends Element
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Element $field
|
||||
*/
|
||||
public function addField(Element $field)
|
||||
{
|
||||
$this->_children[$field->getName()] = $field;
|
||||
$field->setParent($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$rtn = true;
|
||||
|
|
@ -70,6 +85,9 @@ class FieldSet extends Element
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
$rendered = [];
|
||||
|
|
@ -80,11 +98,19 @@ class FieldSet extends Element
|
|||
$view->children = $rendered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Element[]
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return $this->_children;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fieldName
|
||||
*
|
||||
* @return Element
|
||||
*/
|
||||
public function getChild($fieldName)
|
||||
{
|
||||
return $this->_children[$fieldName];
|
||||
|
|
|
|||
|
|
@ -2,17 +2,47 @@
|
|||
|
||||
namespace b8\Form;
|
||||
|
||||
use b8\Form\Element, b8\View;
|
||||
use b8\View;
|
||||
|
||||
class Input extends Element
|
||||
{
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_required = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_pattern;
|
||||
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
protected $_validator;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_value;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_error;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_customError = false;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $label
|
||||
* @param boolean $required
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function create($name, $label, $required = false)
|
||||
{
|
||||
$el = new static();
|
||||
|
|
@ -23,33 +53,59 @@ class Input extends Element
|
|||
return $el;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getRequired()
|
||||
{
|
||||
return $this->_required;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $required
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRequired($required)
|
||||
{
|
||||
$this->_required = (bool)$required;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return callable
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return $this->_validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $validator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValidator($validator)
|
||||
{
|
||||
if (is_callable($validator) || $validator instanceof \Closure) {
|
||||
|
|
@ -59,17 +115,29 @@ class Input extends Element
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->_pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pattern
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
$this->_pattern = $pattern;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if ($this->getRequired() && empty($this->_value)) {
|
||||
|
|
@ -79,6 +147,7 @@ class Input extends Element
|
|||
|
||||
if ($this->getPattern() && !preg_match('/' . $this->getPattern() . '/', $this->_value)) {
|
||||
$this->_error = 'Invalid value entered.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -89,6 +158,7 @@ class Input extends Element
|
|||
call_user_func_array($validator, [$this->_value]);
|
||||
} catch (\Exception $ex) {
|
||||
$this->_error = $ex->getMessage();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -100,18 +170,27 @@ class Input extends Element
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setError($message)
|
||||
{
|
||||
$this->_customError = true;
|
||||
$this->_error = $message;
|
||||
$this->_error = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param View $view
|
||||
*/
|
||||
protected function onPreRender(View &$view)
|
||||
{
|
||||
$view->value = $this->getValue();
|
||||
$view->error = $this->_error;
|
||||
$view->pattern = $this->_pattern;
|
||||
$view->value = $this->getValue();
|
||||
$view->error = $this->_error;
|
||||
$view->pattern = $this->_pattern;
|
||||
$view->required = $this->_required;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<input class="btn <?php print $css; ?>" type="<?php print $type; ?>" value="<?php print $value; ?>">
|
||||
<input class="btn <?= $css; ?>" type="<?= $type; ?>" value="<?= $value; ?>">
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
<?php if (!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
|
||||
<div class="control-group <?php print $ccss ?> <?php print (isset($error) ? 'error' : ''); ?>">
|
||||
<div class="control-group <?= $ccss ?> <?= (isset($error) ? 'error' : ''); ?>">
|
||||
<div class="controls">
|
||||
<div class="checkbox">
|
||||
<?php endif; ?>
|
||||
<label class="checkbox <?php print $css; ?>" for="<?php print $id ?>">
|
||||
<input type="checkbox" id="<?php print $id; ?>" name="<?php print $name; ?>"
|
||||
value="<?php print $checkedValue; ?>" <?php print ($checked ? 'checked' : ''); ?> <?php print $required ? 'required' : '' ?>>
|
||||
<?php print $label; ?>
|
||||
<label class="checkbox <?= $css; ?>" for="<?= $id ?>">
|
||||
<input type="checkbox" id="<?= $id; ?>" name="<?= $name; ?>"
|
||||
value="<?= $checkedValue; ?>"
|
||||
<?= ($checked ? 'checked' : ''); ?> <?= $required ? 'required' : '' ?>
|
||||
>
|
||||
<?= $label; ?>
|
||||
</label>
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<span class="help-block"><?= $error; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
<div class="control-group <?php print $css; ?>">
|
||||
<div class="control-group <?= $css; ?>">
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label"><?php print $label; ?></label>
|
||||
<label class="control-label"><?= $label; ?></label>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="controls">
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?= $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="control-group <?php print $css; ?>">
|
||||
<div class="control-group <?= $css; ?>">
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?= $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<input type="hidden" id="<?php print $id; ?>" name="<?php print $name; ?>" value="<?php print $csrf; ?>">
|
||||
<input type="hidden" id="<?= $id; ?>" name="<?= $name; ?>" value="<?= $csrf; ?>">
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<fieldset class="row <?php print $css; ?>">
|
||||
<fieldset class="row <?= $css; ?>">
|
||||
<?php if ($label): ?>
|
||||
<legend><?php print $label; ?></legend>
|
||||
<legend><?= $label; ?></legend>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?= $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<form id="<?php print $id; ?>" class="<?php print $css; ?>" action="<?php print $action; ?>" method="<?php print $method; ?>">
|
||||
<form id="<?= $id; ?>" class="<?= $css; ?>" action="<?= $action; ?>" method="<?= $method; ?>">
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?= $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<input type="hidden" id="<?php print $id; ?>" name="<?php print $name; ?>" value="<?php print $value; ?>">
|
||||
<input type="hidden" id="<?= $id; ?>" name="<?= $name; ?>" value="<?= $value; ?>">
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
<div id="<?php print $id; ?>" class="control-group <?php print $ccss; ?>">
|
||||
<div id="<?= $id; ?>" class="control-group <?= $ccss; ?>">
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label"><?php print $label; ?></label>
|
||||
<label class="control-label"><?= $label; ?></label>
|
||||
<?php endif; ?>
|
||||
<div class="controls">
|
||||
<?php foreach ($options as $val => $lbl): ?>
|
||||
<label class="radio" for="radio-<?php print $id; ?>-<?php print $val; ?>">
|
||||
<input type="radio" id="radio-<?php print $id; ?>-<?php print $val; ?>" class="<?php print $css; ?>"
|
||||
name="<?php print $name; ?>"
|
||||
value="<?php print $val; ?>" <?php print ($value == $val) ? ' checked="checked"' : ''; ?> <?php print $required ? 'required' : '' ?>>
|
||||
<?php print $lbl; ?>
|
||||
<label class="radio" for="radio-<?= $id; ?>-<?= $val; ?>">
|
||||
<input type="radio" id="radio-<?= $id; ?>-<?= $val; ?>" class="<?= $css; ?>"
|
||||
name="<?= $name; ?>"
|
||||
value="<?= $val; ?>"
|
||||
<?= ($value == $val) ? ' checked="checked"' : ''; ?> <?= $required ? 'required' : '' ?>
|
||||
>
|
||||
<?= $lbl; ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<span class="help-block"><?= $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
<div class="control-group <?php print $ccss; ?>">
|
||||
<div class="control-group <?= $ccss; ?>">
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $label; ?></label>
|
||||
<label class="control-label" for="<?= $id ?>"><?= $label; ?></label>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="controls">
|
||||
<select id="<?php print $id; ?>" class="<?php print $css; ?>" name="<?php print $name; ?>">
|
||||
<select id="<?= $id; ?>" class="<?= $css; ?>" name="<?= $name; ?>">
|
||||
<?php foreach ($options as $val => $lbl): ?>
|
||||
<option
|
||||
value="<?php print $val; ?>" <?php print ($value == $val) ? ' selected="selected"' : ''; ?>><?php print $lbl; ?></option>
|
||||
value="<?= $val; ?>" <?= ($value == $val) ? ' selected="selected"' : ''; ?>
|
||||
><?= $lbl; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<span class="help-block"><?= $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
<div class="control-group <?php print $ccss; ?> <?php print (isset($error) ? 'error' : ''); ?>">
|
||||
<div class="control-group <?= $ccss; ?> <?= (isset($error) ? 'error' : ''); ?>">
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $label; ?></label>
|
||||
<label class="control-label" for="<?= $id ?>"><?= $label; ?></label>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="controls">
|
||||
<input id="<?php print $id; ?>" type="<?php print $type; ?>" class="<?php print $css; ?>"
|
||||
name="<?php print $name; ?>" <?php print isset($value) ? ' value="' . $value . '"' : '' ?> <?php print isset($pattern) ? ' pattern="' . $pattern . '"' : '' ?> <?php print $required ? ' required' : '' ?>>
|
||||
|
||||
<input id="<?= $id; ?>" type="<?= $type; ?>" class="<?= $css; ?>"
|
||||
name="<?= $name; ?>"
|
||||
<?= isset($value) ? ' value="' . $value . '"' : '' ?>
|
||||
<?= isset($pattern) ? ' pattern="' . $pattern . '"' : '' ?>
|
||||
<?= $required ? ' required' : '' ?>
|
||||
>
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<span class="help-block"><?= $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
<div class="control-group <?php print $ccss; ?> <?php print (isset($error) ? 'error' : ''); ?>">
|
||||
<div class="control-group <?= $ccss; ?> <?= (isset($error) ? 'error' : ''); ?>">
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $label; ?></label>
|
||||
<label class="control-label" for="<?= $id ?>"><?= $label; ?></label>
|
||||
<?php endif; ?>
|
||||
<div class="controls">
|
||||
<textarea rows="<?php print $rows; ?>" id="<?php print $id; ?>" class="<?php print $css; ?>"
|
||||
name="<?php print $name; ?>" <?php print $required ? ' required' : '' ?>><?php print isset($value) ? $value : '' ?></textarea>
|
||||
<textarea rows="<?= $rows; ?>" id="<?= $id; ?>" class="<?= $css; ?>"
|
||||
name="<?= $name; ?>" <?= $required ? ' required' : '' ?>><?= isset($value) ? $value : '' ?></textarea>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<span class="help-block"><?= $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace b8;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
use b8\Cache;
|
||||
|
||||
class Model
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,19 +3,45 @@
|
|||
namespace b8;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
use b8\Database;
|
||||
|
||||
abstract class Store
|
||||
{
|
||||
protected $modelName = null;
|
||||
protected $tableName = null;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $modelName = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tableName = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = null;
|
||||
|
||||
/**
|
||||
* @return \b8\Model
|
||||
* @param string $key
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return Model
|
||||
*/
|
||||
abstract public function getByPrimaryKey($key, $useConnection = 'read');
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param integer $limit
|
||||
* @param integer $offset
|
||||
* @param array $joins
|
||||
* @param array $order
|
||||
* @param array $manualJoins
|
||||
* @param string $group
|
||||
* @param array $manualWheres
|
||||
* @param string $whereType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWhere(
|
||||
$where = [],
|
||||
$limit = 25,
|
||||
|
|
@ -196,6 +222,14 @@ abstract class Store
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $obj
|
||||
* @param boolean $saveAllColumns
|
||||
*
|
||||
* @throws HttpException\BadRequestException
|
||||
*
|
||||
* @return Model|null
|
||||
*/
|
||||
public function save(Model $obj, $saveAllColumns = false)
|
||||
{
|
||||
if (!isset($this->primaryKey)) {
|
||||
|
|
@ -217,6 +251,12 @@ abstract class Store
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $obj
|
||||
* @param bool $saveAllColumns
|
||||
*
|
||||
* @return Model|null
|
||||
*/
|
||||
public function saveByUpdate(Model $obj, $saveAllColumns = false)
|
||||
{
|
||||
$rtn = null;
|
||||
|
|
@ -249,6 +289,12 @@ abstract class Store
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $obj
|
||||
* @param bool $saveAllColumns
|
||||
*
|
||||
* @return Model|null
|
||||
*/
|
||||
public function saveByInsert(Model $obj, $saveAllColumns = false)
|
||||
{
|
||||
$rtn = null;
|
||||
|
|
@ -280,6 +326,13 @@ abstract class Store
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $obj
|
||||
*
|
||||
* @throws HttpException\BadRequestException
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(Model $obj)
|
||||
{
|
||||
if (!isset($this->primaryKey)) {
|
||||
|
|
@ -299,6 +352,13 @@ abstract class Store
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @throws HttpException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function fieldCheck($field)
|
||||
{
|
||||
if (empty($field)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue