diff --git a/src/B8Framework/Application.php b/src/B8Framework/Application.php index 774a46e4..d90e8def 100644 --- a/src/B8Framework/Application.php +++ b/src/B8Framework/Application.php @@ -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'; } diff --git a/src/B8Framework/Config.php b/src/B8Framework/Config.php index 60ec8225..fa3d6c1b 100644 --- a/src/B8Framework/Config.php +++ b/src/B8Framework/Config.php @@ -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)) { diff --git a/src/B8Framework/Database.php b/src/B8Framework/Database.php index 9cddd471..15cda019 100644 --- a/src/B8Framework/Database.php +++ b/src/B8Framework/Database.php @@ -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); diff --git a/src/B8Framework/Form.php b/src/B8Framework/Form.php index 664f8583..39f59568 100644 --- a/src/B8Framework/Form.php +++ b/src/B8Framework/Form.php @@ -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; } /** diff --git a/src/B8Framework/Form/Element.php b/src/B8Framework/Form/Element.php index cea9ff39..e485b9a3 100644 --- a/src/B8Framework/Form/Element.php +++ b/src/B8Framework/Form/Element.php @@ -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); diff --git a/src/B8Framework/Form/Element/Checkbox.php b/src/B8Framework/Form/Element/Checkbox.php index 482b7b7a..e69349f7 100644 --- a/src/B8Framework/Form/Element/Checkbox.php +++ b/src/B8Framework/Form/Element/Checkbox.php @@ -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; } } diff --git a/src/B8Framework/Form/Element/Csrf.php b/src/B8Framework/Form/Element/Csrf.php index caeb18dd..89b1e924 100644 --- a/src/B8Framework/Form/Element/Csrf.php +++ b/src/B8Framework/Form/Element/Csrf.php @@ -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; } diff --git a/src/B8Framework/Form/Element/Select.php b/src/B8Framework/Form/Element/Select.php index d48060b9..900ed742 100644 --- a/src/B8Framework/Form/Element/Select.php +++ b/src/B8Framework/Form/Element/Select.php @@ -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; } } diff --git a/src/B8Framework/Form/Element/Submit.php b/src/B8Framework/Form/Element/Submit.php index 7493531a..a95bff0f 100644 --- a/src/B8Framework/Form/Element/Submit.php +++ b/src/B8Framework/Form/Element/Submit.php @@ -9,7 +9,7 @@ class Submit extends Button /** * @var string */ - protected $_value = 'Submit'; + protected $value = 'Submit'; /** * @param string $viewFile diff --git a/src/B8Framework/Form/Element/TextArea.php b/src/B8Framework/Form/Element/TextArea.php index 5744b653..6ec8b85a 100644 --- a/src/B8Framework/Form/Element/TextArea.php +++ b/src/B8Framework/Form/Element/TextArea.php @@ -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; } /** diff --git a/src/B8Framework/Form/FieldSet.php b/src/B8Framework/Form/FieldSet.php index 94b63f5e..49f485a3 100644 --- a/src/B8Framework/Form/FieldSet.php +++ b/src/B8Framework/Form/FieldSet.php @@ -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]; } } diff --git a/src/B8Framework/Form/Input.php b/src/B8Framework/Form/Input.php index 5b0bafad..90e62645 100644 --- a/src/B8Framework/Form/Input.php +++ b/src/B8Framework/Form/Input.php @@ -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(); diff --git a/src/B8Framework/Form/View/Button.phtml b/src/B8Framework/Form/View/Button.phtml index 60a3a613..6ca3a6d0 100644 --- a/src/B8Framework/Form/View/Button.phtml +++ b/src/B8Framework/Form/View/Button.phtml @@ -1 +1 @@ - + diff --git a/src/B8Framework/Form/View/Checkbox.phtml b/src/B8Framework/Form/View/Checkbox.phtml index c4a0858a..184efd77 100644 --- a/src/B8Framework/Form/View/Checkbox.phtml +++ b/src/B8Framework/Form/View/Checkbox.phtml @@ -1,9 +1,9 @@ -