From e59e4a397fa54c47c1735f3fbb94cc19ec80768e Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 5 Dec 2017 20:57:53 +0700 Subject: [PATCH 1/5] Code style fixes. --- src/B8Framework/Config.php | 1 - src/B8Framework/Http/Router.php | 3 +- src/B8Framework/View/Template.php | 29 ++++++++++++------- src/PHPCensor/Command/CreateAdminCommand.php | 6 ++-- src/PHPCensor/Command/CreateBuildCommand.php | 6 ++-- src/PHPCensor/Command/InstallCommand.php | 27 +++++++++-------- src/PHPCensor/Command/RunCommand.php | 10 ++++--- .../Command/ScheduleBuildCommand.php | 6 ++-- src/PHPCensor/Command/WorkerCommand.php | 6 ++-- src/PHPCensor/Store/BuildStore.php | 8 +++-- 10 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/B8Framework/Config.php b/src/B8Framework/Config.php index 977abb0a..60ec8225 100644 --- a/src/B8Framework/Config.php +++ b/src/B8Framework/Config.php @@ -188,7 +188,6 @@ class Config } elseif (is_array($source[$target_key]) && is_array($target_value)) { // Both are arrays, deep merge them self::deepMerge($source[$target_key], $target_value); - } elseif (is_array($source[$target_key])) { // Source is the array, push target value $source[$target_key][] = $target_value; diff --git a/src/B8Framework/Http/Router.php b/src/B8Framework/Http/Router.php index aa651c55..d0653241 100644 --- a/src/B8Framework/Http/Router.php +++ b/src/B8Framework/Http/Router.php @@ -2,7 +2,8 @@ namespace b8\Http; -use b8\Application, b8\Config; +use b8\Application; +use b8\Config; class Router { diff --git a/src/B8Framework/View/Template.php b/src/B8Framework/View/Template.php index d58957cc..9735b928 100644 --- a/src/B8Framework/View/Template.php +++ b/src/B8Framework/View/Template.php @@ -7,6 +7,7 @@ use b8\View; class Template extends View { public static $templateFunctions = []; + protected static $extension = 'html'; public function __construct($viewCode) @@ -222,10 +223,19 @@ class Template extends View { $matches = []; - if (preg_match('/([a-zA-Z0-9_\-\(\):\s.\"]+)\s+?([\!\=\<\>]+)?\s+?([a-zA-Z0-9\(\)_\-:\s.\"]+)?/', $condition, - $matches)) { - $left = is_numeric($matches[1]) ? intval($matches[1]) : $this->processVariableName($matches[1]); - $right = is_numeric($matches[3]) ? intval($matches[3]) : $this->processVariableName($matches[3]); + if (preg_match( + '/([a-zA-Z0-9_\-\(\):\s.\"]+)\s+?([\!\=\<\>]+)?\s+?([a-zA-Z0-9\(\)_\-:\s.\"]+)?/', + $condition, + $matches + )) { + $left = is_numeric($matches[1]) + ? intval($matches[1]) + : $this->processVariableName($matches[1]); + + $right = is_numeric($matches[3]) + ? intval($matches[3]) + : $this->processVariableName($matches[3]); + $operator = $matches[2]; switch ($operator) { @@ -374,7 +384,6 @@ class Template extends View { // Case one - Test for function calls: if (substr($varName, 0, 1) == '(' && substr($varName, -1) == ')') { - $functionCall = substr($varName, 1, -1); $parts = explode(' ', $functionCall, 2); $functionName = $parts[0]; @@ -469,7 +478,8 @@ class Template extends View { if (array_key_exists($function, self::$templateFunctions)) { $handler = self::$templateFunctions[$function]; - $args = $this->processFunctionArguments($args); + $args = $this->processFunctionArguments($args); + return $handler($args, $this); } @@ -478,15 +488,13 @@ class Template extends View protected function processFunctionArguments($args) { - $rtn = []; - + $rtn = []; $args = explode(';', $args); foreach ($args as $arg) { $arg = explode(':', $arg); if (count($arg) == 2) { - $key = trim($arg[0]); $val = trim($arg[1]); @@ -516,7 +524,6 @@ class Template extends View } foreach ($args['variables'] as $variable) { - $variable = explode('=>', $variable); $variable = array_map('trim', $variable); @@ -533,7 +540,7 @@ class Template extends View protected function callHelperFunction($args) { - $helper = $args['helper']; + $helper = $args['helper']; $function = $args['method']; return $this->{$helper}()->{$function}(); diff --git a/src/PHPCensor/Command/CreateAdminCommand.php b/src/PHPCensor/Command/CreateAdminCommand.php index c723459f..113974bf 100644 --- a/src/PHPCensor/Command/CreateAdminCommand.php +++ b/src/PHPCensor/Command/CreateAdminCommand.php @@ -13,7 +13,7 @@ use Symfony\Component\Console\Question\Question; /** * Create admin command - creates an admin user - * + * * @author Wogan May (@woganmay) */ class CreateAdminCommand extends Command @@ -38,9 +38,9 @@ class CreateAdminCommand extends Command $this ->setName('php-censor:create-admin') - ->addOption('admin-name', null, InputOption::VALUE_OPTIONAL, 'Admin name') + ->addOption('admin-name', null, InputOption::VALUE_OPTIONAL, 'Admin name') ->addOption('admin-password', null, InputOption::VALUE_OPTIONAL, 'Admin password') - ->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email') + ->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email') ->setDescription('Create an admin user'); } diff --git a/src/PHPCensor/Command/CreateBuildCommand.php b/src/PHPCensor/Command/CreateBuildCommand.php index 28b97592..237d85b3 100644 --- a/src/PHPCensor/Command/CreateBuildCommand.php +++ b/src/PHPCensor/Command/CreateBuildCommand.php @@ -47,12 +47,14 @@ class CreateBuildCommand extends Command { $this ->setName('php-censor:create-build') - ->setDescription('Create a build for a project') + ->addArgument('projectId', InputArgument::REQUIRED, 'A project ID') ->addOption('commit', null, InputOption::VALUE_OPTIONAL, 'Commit ID to build') ->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'Branch to build') ->addOption('email', null, InputOption::VALUE_OPTIONAL, 'Committer email') - ->addOption('message', null, InputOption::VALUE_OPTIONAL, 'Commit message'); + ->addOption('message', null, InputOption::VALUE_OPTIONAL, 'Commit message') + + ->setDescription('Create a build for a project'); } /** diff --git a/src/PHPCensor/Command/InstallCommand.php b/src/PHPCensor/Command/InstallCommand.php index 10e30307..1f3b86e5 100644 --- a/src/PHPCensor/Command/InstallCommand.php +++ b/src/PHPCensor/Command/InstallCommand.php @@ -37,19 +37,19 @@ class InstallCommand extends Command $this ->setName('php-censor:install') - ->addOption('url', null, InputOption::VALUE_OPTIONAL, 'PHP Censor installation URL') - ->addOption('db-type', null, InputOption::VALUE_OPTIONAL, 'Database type') - ->addOption('db-host', null, InputOption::VALUE_OPTIONAL, 'Database host') - ->addOption('db-port', null, InputOption::VALUE_OPTIONAL, 'Database port') - ->addOption('db-name', null, InputOption::VALUE_OPTIONAL, 'Database name') - ->addOption('db-user', null, InputOption::VALUE_OPTIONAL, 'Database user') - ->addOption('db-password', null, InputOption::VALUE_OPTIONAL, 'Database password') - ->addOption('admin-name', null, InputOption::VALUE_OPTIONAL, 'Admin name') - ->addOption('admin-password', null, InputOption::VALUE_OPTIONAL, 'Admin password') - ->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email') - ->addOption('queue-use', null, InputOption::VALUE_OPTIONAL, 'Don\'t ask for queue details', true) - ->addOption('queue-host', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue server hostname') - ->addOption('queue-name', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue name') + ->addOption('url', null, InputOption::VALUE_OPTIONAL, 'PHP Censor installation URL') + ->addOption('db-type', null, InputOption::VALUE_OPTIONAL, 'Database type') + ->addOption('db-host', null, InputOption::VALUE_OPTIONAL, 'Database host') + ->addOption('db-port', null, InputOption::VALUE_OPTIONAL, 'Database port') + ->addOption('db-name', null, InputOption::VALUE_OPTIONAL, 'Database name') + ->addOption('db-user', null, InputOption::VALUE_OPTIONAL, 'Database user') + ->addOption('db-password', null, InputOption::VALUE_OPTIONAL, 'Database password') + ->addOption('admin-name', null, InputOption::VALUE_OPTIONAL, 'Admin name') + ->addOption('admin-password', null, InputOption::VALUE_OPTIONAL, 'Admin password') + ->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email') + ->addOption('queue-use', null, InputOption::VALUE_OPTIONAL, 'Don\'t ask for queue details', true) + ->addOption('queue-host', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue server hostname') + ->addOption('queue-name', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue name') ->addOption('config-from-file', null, InputOption::VALUE_OPTIONAL, 'Take config from file and ignore options', false) ->setDescription('Install PHP Censor'); @@ -467,7 +467,6 @@ class InstallCommand extends Command unset($pdo); return true; - } catch (Exception $ex) { $output->writeln('PHP Censor could not connect to database with the details provided. Please try again.'); $output->writeln('' . $ex->getMessage() . ''); diff --git a/src/PHPCensor/Command/RunCommand.php b/src/PHPCensor/Command/RunCommand.php index 2ff7f563..71b32e2d 100644 --- a/src/PHPCensor/Command/RunCommand.php +++ b/src/PHPCensor/Command/RunCommand.php @@ -18,7 +18,7 @@ use PHPCensor\Model\Build; /** * Run console command - Runs any pending builds. - * + * * @author Dan Cryer */ class RunCommand extends Command @@ -52,8 +52,10 @@ class RunCommand extends Command { $this ->setName('php-censor:run-builds') - ->setDescription('Run all pending PHP Censor builds') - ->addOption('debug', null, null, 'Run PHP Censor in debug mode'); + + ->addOption('debug', null, null, 'Run PHP Censor in debug mode') + + ->setDescription('Run all pending PHP Censor builds'); } /** @@ -81,7 +83,7 @@ class RunCommand extends Command $this->logger->pushProcessor(new LoggedBuildContextTidier()); $this->logger->addInfo('Finding builds to process'); - + /** @var BuildStore $buildStore */ $buildStore = Factory::getStore('Build'); $result = $buildStore->getByStatus(Build::STATUS_PENDING, $this->maxBuilds); diff --git a/src/PHPCensor/Command/ScheduleBuildCommand.php b/src/PHPCensor/Command/ScheduleBuildCommand.php index 57c02f9f..1c8b574a 100644 --- a/src/PHPCensor/Command/ScheduleBuildCommand.php +++ b/src/PHPCensor/Command/ScheduleBuildCommand.php @@ -55,8 +55,10 @@ class ScheduleBuildCommand extends Command { $this ->setName('php-censor:schedule-build') - ->setDescription('Schedules a build for active projects which have not been ran by X days') - ->addArgument('days', InputArgument::REQUIRED, 'Since specified days'); + + ->addArgument('days', InputArgument::REQUIRED, 'Since specified days') + + ->setDescription('Schedules a build for active projects which have not been ran by X days'); } /** diff --git a/src/PHPCensor/Command/WorkerCommand.php b/src/PHPCensor/Command/WorkerCommand.php index 3004c51b..644e9394 100644 --- a/src/PHPCensor/Command/WorkerCommand.php +++ b/src/PHPCensor/Command/WorkerCommand.php @@ -41,8 +41,10 @@ class WorkerCommand extends Command { $this ->setName('php-censor:worker') - ->setDescription('Runs the PHP Censor build worker.') - ->addOption('debug', null, null, 'Run PHP Censor in Debug Mode'); + + ->addOption('debug', null, null, 'Run PHP Censor in Debug Mode') + + ->setDescription('Runs the PHP Censor build worker.'); } protected function execute(InputInterface $input, OutputInterface $output) diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 868249e6..be3ad4e8 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -274,8 +274,8 @@ class BuildStore extends Store $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $projects = []; - $latest = []; - foreach($res as $item) { + $latest = []; + foreach ($res as $item) { $project_id = $item['project_id']; $environment = $item['environment']; if (empty($projects[$project_id])) { @@ -312,11 +312,13 @@ class BuildStore extends Store $projects[$project_id][$environment]['failed'] = $build; } } - foreach($projects as $idx => $project) { + + foreach ($projects as $idx => $project) { $projects[$idx] = array_filter($project, function($val) { return ($val['latest'][0]->getStatus() != Build::STATUS_SUCCESS); }); } + $projects = array_filter($projects); return ['projects' => $projects, 'latest' => $latest]; From dd1d7e2be3db75e7e09b1e5ecfb8e5e2dc3feff1 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 18 Jan 2018 21:51:33 +0700 Subject: [PATCH 2/5] Fixed var names for framework. --- src/B8Framework/Application.php | 23 ++++-- src/B8Framework/Config.php | 5 +- src/B8Framework/Database.php | 3 +- src/B8Framework/Form.php | 12 +-- src/B8Framework/Form/Element.php | 54 +++++++------ src/B8Framework/Form/Element/Checkbox.php | 22 +++--- src/B8Framework/Form/Element/Csrf.php | 4 +- src/B8Framework/Form/Element/Select.php | 6 +- src/B8Framework/Form/Element/Submit.php | 2 +- src/B8Framework/Form/Element/TextArea.php | 6 +- src/B8Framework/Form/FieldSet.php | 16 ++-- src/B8Framework/Form/Input.php | 12 +-- src/B8Framework/Form/View/Button.phtml | 2 +- src/B8Framework/Form/View/Checkbox.phtml | 4 +- src/B8Framework/Form/View/CheckboxGroup.phtml | 2 +- src/B8Framework/Form/View/ControlGroup.phtml | 2 +- src/B8Framework/Form/View/FieldSet.phtml | 2 +- src/B8Framework/Form/View/Form.phtml | 2 +- src/B8Framework/Form/View/Radio.phtml | 4 +- src/B8Framework/Form/View/Select.phtml | 4 +- src/B8Framework/Form/View/Text.phtml | 4 +- src/B8Framework/Form/View/TextArea.phtml | 4 +- src/B8Framework/Model.php | 79 +++++++++++++++++++ src/B8Framework/View.php | 18 ++--- src/B8Framework/View/Template.php | 2 +- 25 files changed, 196 insertions(+), 98 deletions(-) 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 @@ -
+
-