Fixes + code style fixes
This commit is contained in:
parent
9d3104fcac
commit
e9b5de8ea9
|
@ -8,7 +8,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '../bootstrap.php');
|
||||
require_once(dirname(__DIR__) . '/bootstrap.php');
|
||||
|
||||
$writeServers = $config->get('b8.database.servers.write');
|
||||
|
||||
|
|
10
bin/console
10
bin/console
|
@ -8,13 +8,8 @@
|
|||
* @link http://www.phptesting.org/
|
||||
*/
|
||||
|
||||
define('PHPCI_IS_CONSOLE', true);
|
||||
|
||||
require_once(dirname(__DIR__) . '/bootstrap.php');
|
||||
|
||||
use PHPCI\Command\RunCommand;
|
||||
use PHPCI\Command\RebuildCommand;
|
||||
use PHPCI\Command\GenerateCommand;
|
||||
use PHPCI\Command\UpdateCommand;
|
||||
use PHPCI\Command\InstallCommand;
|
||||
use PHPCI\Command\DaemonCommand;
|
||||
|
@ -27,13 +22,16 @@ use PHPCI\Service\BuildService;
|
|||
use Symfony\Component\Console\Application;
|
||||
use b8\Store\Factory;
|
||||
|
||||
define('PHPCI_IS_CONSOLE', true);
|
||||
|
||||
require_once(dirname(__DIR__) . '/bootstrap.php');
|
||||
|
||||
$application = new Application();
|
||||
|
||||
$application->add(new RunCommand($loggerConfig->getFor('RunCommand')));
|
||||
$application->add(new RebuildCommand($loggerConfig->getFor('RunCommand')));
|
||||
$application->add(new InstallCommand);
|
||||
$application->add(new UpdateCommand($loggerConfig->getFor('UpdateCommand')));
|
||||
$application->add(new GenerateCommand);
|
||||
$application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand')));
|
||||
$application->add(new PollCommand($loggerConfig->getFor('PollCommand')));
|
||||
$application->add(new CreateAdminCommand(Factory::getStore('User')));
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
* @link http://www.phptesting.org/
|
||||
*/
|
||||
|
||||
use PHPCI\Command\DaemoniseCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
define('PHPCI_IS_CONSOLE', true);
|
||||
|
||||
require_once(dirname(__DIR__) . '/bootstrap.php');
|
||||
|
||||
use PHPCI\Command\DaemoniseCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
$application = new Application();
|
||||
$application->add(new DaemoniseCommand($loggerConfig->getFor('DaemoniseCommand')));
|
||||
$application->run();
|
||||
|
|
|
@ -7,73 +7,67 @@
|
|||
* @link http://www.phptesting.org/
|
||||
*/
|
||||
|
||||
// Let PHP take a guess as to the default timezone, if the user hasn't set one:
|
||||
use PHPCI\Logging\LoggerConfig;
|
||||
|
||||
$timezone = ini_get('date.timezone');
|
||||
if (empty($timezone)) {
|
||||
date_default_timezone_set('UTC');
|
||||
if (!defined('ROOT_DIR')) {
|
||||
define('ROOT_DIR', __DIR__ . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
$configFile = dirname(__FILE__) . '/app/config.yml';
|
||||
$configEnv = getenv('phpci_config_file');
|
||||
$usingCustomConfigFile = false;
|
||||
|
||||
if (!empty($configEnv) && file_exists($configEnv)) {
|
||||
$configFile = $configEnv;
|
||||
$usingCustomConfigFile = true;
|
||||
if (!defined('PHPCI_DIR')) {
|
||||
define('PHPCI_DIR', ROOT_DIR . 'src' . DIRECTORY_SEPARATOR . 'PHPCI' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
// If we don't have a config file at all, fail at this point and tell the user to install:
|
||||
if (!file_exists($configFile) && (!defined('PHPCI_IS_CONSOLE') || !PHPCI_IS_CONSOLE)) {
|
||||
$message = 'PHPCI has not yet been installed - Please use the command "./console phpci:install" ';
|
||||
$message .= '(or "php ./console phpci:install" for Windows) to install it.';
|
||||
|
||||
die($message);
|
||||
if (!defined('PHPCI_PUBLIC_DIR')) {
|
||||
define('PHPCI_PUBLIC_DIR', ROOT_DIR . 'public' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
// If composer has not been run, fail at this point and tell the user to install:
|
||||
if (!file_exists(dirname(__FILE__) . '/vendor/autoload.php') && defined('PHPCI_IS_CONSOLE') && PHPCI_IS_CONSOLE) {
|
||||
$message = 'Please install PHPCI with "composer install" (or "php composer.phar install"';
|
||||
$message .= ' for Windows) before using console';
|
||||
|
||||
file_put_contents('php://stderr', $message);
|
||||
exit(1);
|
||||
if (!defined('PHPCI_APP_DIR')) {
|
||||
define('PHPCI_APP_DIR', ROOT_DIR . 'app' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
// Load Composer autoloader:
|
||||
require_once(dirname(__FILE__) . '/vendor/autoload.php');
|
||||
if (!defined('PHPCI_BIN_DIR')) {
|
||||
define('PHPCI_BIN_DIR', ROOT_DIR . 'bin' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
if (!defined('PHPCI_RUNTIME_DIR')) {
|
||||
define('PHPCI_RUNTIME_DIR', ROOT_DIR . 'runtime' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
if (!defined('PHPCI_BUILDS_DIR')) {
|
||||
define('PHPCI_BUILDS_DIR', ROOT_DIR . 'runtime' . DIRECTORY_SEPARATOR . 'builds' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
if (!defined('IS_WIN')) {
|
||||
define('IS_WIN', ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false));
|
||||
}
|
||||
|
||||
require_once(ROOT_DIR . 'vendor/autoload.php');
|
||||
|
||||
\PHPCI\ErrorHandler::register();
|
||||
|
||||
if (defined('PHPCI_IS_CONSOLE') && PHPCI_IS_CONSOLE) {
|
||||
$loggerConfig = LoggerConfig::newFromFile(__DIR__ . "/app/loggerconfig.php");
|
||||
$loggerConfig = LoggerConfig::newFromFile(PHPCI_APP_DIR . "loggerconfig.php");
|
||||
}
|
||||
|
||||
// Load configuration if present:
|
||||
$conf = [];
|
||||
$conf['b8']['app']['namespace'] = 'PHPCI';
|
||||
$conf['b8']['app']['default_controller'] = 'Home';
|
||||
$conf['b8']['view']['path'] = dirname(__FILE__) . '/src/PHPCI/View/';
|
||||
$conf['using_custom_file'] = $usingCustomConfigFile;
|
||||
$conf['b8']['view']['path'] = PHPCI_DIR . 'View' . DIRECTORY_SEPARATOR;
|
||||
|
||||
$config = new b8\Config($conf);
|
||||
|
||||
$configFile = PHPCI_APP_DIR . 'config.yml';
|
||||
if (file_exists($configFile)) {
|
||||
$config->loadYaml($configFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow to modify PHPCI configuration without modify versioned code.
|
||||
* Daemons should be killed to apply changes in the file.
|
||||
*
|
||||
* @ticket 781
|
||||
*/
|
||||
$localVarsFile = dirname(__FILE__) . '/local_vars.php';
|
||||
if (is_readable($localVarsFile)) {
|
||||
require_once $localVarsFile;
|
||||
if (!defined('PHPCI_URL') && !empty($config)) {
|
||||
define('PHPCI_URL', $config->get('phpci.url', '') . '/');
|
||||
}
|
||||
|
||||
require_once(dirname(__FILE__) . '/vars.php');
|
||||
if (!defined('PHPCI_IS_CONSOLE')) {
|
||||
define('PHPCI_IS_CONSOLE', false);
|
||||
}
|
||||
|
||||
\PHPCI\Helper\Lang::init($config);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace b8;
|
||||
|
||||
use b8\Config;
|
||||
use b8\Exception\HttpException\NotFoundException;
|
||||
use b8\Http;
|
||||
use b8\View;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace b8;
|
|||
use Symfony\Component\Yaml\Parser as YamlParser;
|
||||
|
||||
if (!defined('B8_PATH')) {
|
||||
define('B8_PATH', dirname(__FILE__) . '/');
|
||||
define('B8_PATH', __DIR__ . '/');
|
||||
}
|
||||
|
||||
class Config
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Database;
|
||||
use b8\Database,
|
||||
b8\Database\Map,
|
||||
b8\View\Template;
|
||||
|
||||
class CodeGenerator
|
||||
{
|
||||
protected $_db = null;
|
||||
protected $_map = null;
|
||||
protected $_tables = null;
|
||||
protected $_ns = null;
|
||||
protected $_path = null;
|
||||
|
||||
/**
|
||||
* @param Database $db
|
||||
* @param array $namespaces
|
||||
* @param string $path
|
||||
* @param bool $includeCountQueries
|
||||
*/
|
||||
public function __construct(Database $db, array $namespaces, $path, $includeCountQueries = true)
|
||||
{
|
||||
$this->_db = $db;
|
||||
$this->_ns = $namespaces;
|
||||
$this->_path = $path;
|
||||
$this->_map = new Map($this->_db);
|
||||
$this->_tables = $this->_map->generate();
|
||||
$this->_counts = $includeCountQueries;
|
||||
}
|
||||
|
||||
protected function getNamespace($modelName)
|
||||
{
|
||||
return array_key_exists($modelName, $this->_ns) ? $this->_ns[$modelName] : $this->_ns['default'];
|
||||
}
|
||||
|
||||
public function getPath($namespace)
|
||||
{
|
||||
return array_key_exists($namespace, $this->_path) ? $this->_path[$namespace] : $this->_path['default'];
|
||||
}
|
||||
|
||||
public function generateModels()
|
||||
{
|
||||
print PHP_EOL . 'GENERATING MODELS' . PHP_EOL . PHP_EOL;
|
||||
|
||||
foreach($this->_tables as $tableName => $table)
|
||||
{
|
||||
$namespace = $this->getNamespace($table['php_name']);
|
||||
$modelPath = $this->getPath($namespace) . str_replace('\\', '/', $namespace) . '/Model/';
|
||||
$basePath = $modelPath . 'Base/';
|
||||
$modelFile = $modelPath . $table['php_name'] . '.php';
|
||||
$baseFile = $basePath . $table['php_name'] . 'Base.php';
|
||||
|
||||
if (!is_dir($basePath)) {
|
||||
@mkdir($basePath, 0777, true);
|
||||
}
|
||||
|
||||
$model = $this->_processTemplate($tableName, $table, 'ModelTemplate');
|
||||
$base = $this->_processTemplate($tableName, $table, 'BaseModelTemplate');
|
||||
|
||||
print '-- ' . $table['php_name'] . PHP_EOL;
|
||||
|
||||
if(!is_file($modelFile))
|
||||
{
|
||||
print '-- -- Writing new Model' . PHP_EOL;
|
||||
file_put_contents($modelFile, $model);
|
||||
}
|
||||
|
||||
print '-- -- Writing base Model' . PHP_EOL;
|
||||
file_put_contents($baseFile, $base);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateStores()
|
||||
{
|
||||
print PHP_EOL . 'GENERATING STORES' . PHP_EOL . PHP_EOL;
|
||||
|
||||
foreach($this->_tables as $tableName => $table)
|
||||
{
|
||||
$namespace = $this->getNamespace($table['php_name']);
|
||||
$storePath = $this->getPath($namespace) . str_replace('\\', '/', $namespace) . '/Store/';
|
||||
$basePath = $storePath . 'Base/';
|
||||
$storeFile = $storePath . $table['php_name'] . 'Store.php';
|
||||
$baseFile = $basePath . $table['php_name'] . 'StoreBase.php';
|
||||
|
||||
if (!is_dir($basePath)) {
|
||||
@mkdir($basePath, 0777, true);
|
||||
}
|
||||
|
||||
$model = $this->_processTemplate($tableName, $table, 'StoreTemplate');
|
||||
$base = $this->_processTemplate($tableName, $table, 'BaseStoreTemplate');
|
||||
|
||||
print '-- ' . $table['php_name'] . PHP_EOL;
|
||||
|
||||
if(!is_file($storeFile))
|
||||
{
|
||||
print '-- -- Writing new Store' . PHP_EOL;
|
||||
file_put_contents($storeFile, $model);
|
||||
}
|
||||
|
||||
print '-- -- Writing base Store' . PHP_EOL;
|
||||
file_put_contents($baseFile, $base);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateControllers()
|
||||
{
|
||||
print PHP_EOL . 'GENERATING CONTROLLERS' . PHP_EOL . PHP_EOL;
|
||||
|
||||
@mkdir($this->_path . 'Controller/Base/', 0777, true);
|
||||
|
||||
foreach($this->_tables as $tableName => $table)
|
||||
{
|
||||
$namespace = $this->getNamespace($table['php_name']);
|
||||
$controllerPath = $this->getPath($namespace) . str_replace('\\', '/', $namespace) . '/Controller/';
|
||||
$basePath = $controllerPath . 'Base/';
|
||||
$controllerFile = $controllerPath . $table['php_name'] . 'Controller.php';
|
||||
$baseFile = $basePath . $table['php_name'] . 'ControllerBase.php';
|
||||
|
||||
if (!is_dir($basePath)) {
|
||||
@mkdir($basePath, 0777, true);
|
||||
}
|
||||
|
||||
$model = $this->_processTemplate($tableName, $table, 'ControllerTemplate');
|
||||
$base = $this->_processTemplate($tableName, $table, 'BaseControllerTemplate');
|
||||
|
||||
print '-- ' . $table['php_name'] . PHP_EOL;
|
||||
|
||||
if(!is_file($controllerFile))
|
||||
{
|
||||
print '-- -- Writing new Controller' . PHP_EOL;
|
||||
file_put_contents($controllerFile, $model);
|
||||
}
|
||||
|
||||
print '-- -- Writing base Controller' . PHP_EOL;
|
||||
file_put_contents($baseFile, $base);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _processTemplate($tableName, $table, $template)
|
||||
{
|
||||
$tpl = Template::createFromFile($template, B8_PATH . 'Database/CodeGenerator/');
|
||||
$tpl->appNamespace = $this->getNamespace($table['php_name']);
|
||||
$tpl->name = $tableName;
|
||||
$tpl->table = $table;
|
||||
$tpl->counts = $this->_counts;
|
||||
$tpl->addFunction('get_namespace', function($args, $view) {
|
||||
return $this->getNamespace($view->getVariable($args['model']));
|
||||
});
|
||||
|
||||
return $tpl->render();
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* {@table.php_name} base controller for table: {@name}
|
||||
*/
|
||||
|
||||
namespace {@appNamespace}\Controller\Base;
|
||||
|
||||
use b8\Controller\RestController;
|
||||
|
||||
/**
|
||||
* {@table.php_name} base Controller
|
||||
* @see {@appNamespace}\Controller\{@table.php_name}
|
||||
* @uses {@appNamespace}\Store\{@table.php_name}Store
|
||||
* @uses {@appNamespace}\Model\{@table.php_name}
|
||||
*/
|
||||
class {@table.php_name}ControllerBase extends RestController
|
||||
{
|
||||
protected $_modelName = '{@table.php_name}';
|
||||
protected $_resourceName = '{@table.php_name.toLowerCase}s';
|
||||
protected $_modelClass = '\{@appNamespace}\Model\{@table.php_name}';
|
||||
}
|
|
@ -1,268 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* {@table.php_name} base model for table: {@name}
|
||||
*/
|
||||
|
||||
namespace {@appNamespace}\Model\Base;
|
||||
|
||||
use {@appNamespace}\Model;
|
||||
use b8\Store\Factory;
|
||||
|
||||
/**
|
||||
* {@table.php_name} Base Model
|
||||
*/
|
||||
class {@table.php_name}Base extends Model
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $sleepable = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tableName = '{@name}';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $modelName = '{@table.php_name}';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array(
|
||||
{loop table.columns}
|
||||
'{@item.name}' => null,
|
||||
{/loop}
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $getters = array(
|
||||
// Direct property getters:
|
||||
{loop table.columns}
|
||||
'{@item.name}' => 'get{@item.php_name}',
|
||||
{/loop}
|
||||
|
||||
// Foreign key getters:
|
||||
{loop table.relationships.toOne}
|
||||
'{@item.php_name}' => 'get{@item.php_name}',
|
||||
{/loop}
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $setters = array(
|
||||
// Direct property setters:
|
||||
{loop table.columns}
|
||||
'{@item.name}' => 'set{@item.php_name}',
|
||||
{/loop}
|
||||
|
||||
// Foreign key setters:
|
||||
{loop table.relationships.toOne}
|
||||
'{@item.php_name}' => 'set{@item.php_name}',
|
||||
{/loop}
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
{loop table.columns}
|
||||
'{@item.name}' => array(
|
||||
'type' => '{@item.type}',
|
||||
{if item.length}
|
||||
'length' => {@item.length},
|
||||
{/if}
|
||||
{if item.null}
|
||||
'nullable' => true,
|
||||
{/if}
|
||||
{if item.is_primary_key}
|
||||
'primary_key' => true,
|
||||
{/if}
|
||||
{if item.auto}
|
||||
'auto_increment' => true,
|
||||
{/if}
|
||||
{if item.default_is_null}
|
||||
'default' => null,
|
||||
{/if}
|
||||
{ifnot item.default_is_null}
|
||||
{if item.default}
|
||||
'default' => {if item.default.isNumeric}{@item.default}{/if}{ifnot item.default.isNumeric}'{@item.default}'{/ifnot},
|
||||
{/if}
|
||||
{/ifnot}
|
||||
),
|
||||
{/loop}
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $indexes = array(
|
||||
{loop table.indexes}
|
||||
'{@item.name}' => array({if item.unique}'unique' => true, {/if}'columns' => '{@item.columns}'),
|
||||
{/loop}
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $foreignKeys = array(
|
||||
{loop table.relationships.toOne}
|
||||
'{@item.fk_name}' => array(
|
||||
'local_col' => '{@item.from_col}',
|
||||
'update' => '{@item.fk_update}',
|
||||
'delete' => '{@item.fk_delete}',
|
||||
'table' => '{@item.table}',
|
||||
'col' => '{@item.col}'
|
||||
),
|
||||
{/loop}
|
||||
);
|
||||
|
||||
{loop table.columns}
|
||||
/**
|
||||
* Get the value of {@item.php_name} / {@item.name}.
|
||||
*
|
||||
{if item.validate_int}
|
||||
* @return int
|
||||
{/if}{if item.validate_string}
|
||||
* @return string
|
||||
{/if}{if item.validate_float}
|
||||
* @return float
|
||||
{/if}{if item.validate_date}
|
||||
* @return \DateTime
|
||||
{/if}
|
||||
*/
|
||||
public function get{@item.php_name}()
|
||||
{
|
||||
$rtn = $this->data['{@item.name}'];
|
||||
|
||||
{if item.validate_date}
|
||||
if (!empty($rtn)) {
|
||||
$rtn = new \DateTime($rtn);
|
||||
}
|
||||
|
||||
{/if}
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
{/loop}
|
||||
{loop table.columns}
|
||||
/**
|
||||
* Set the value of {@item.php_name} / {@item.name}.
|
||||
*
|
||||
{if item.validate_null}
|
||||
* Must not be null.
|
||||
{/if}{if item.validate_int}
|
||||
* @param $value int
|
||||
{/if}{if item.validate_string}
|
||||
* @param $value string
|
||||
{/if}{if item.validate_float}
|
||||
* @param $value float
|
||||
{/if}{if item.validate_date}
|
||||
* @param $value \DateTime
|
||||
{/if}
|
||||
*/
|
||||
public function set{@item.php_name}($value)
|
||||
{
|
||||
{if item.validate_null}
|
||||
$this->_validateNotNull('{@item.php_name}', $value);
|
||||
{/if}
|
||||
{if item.validate_int}
|
||||
$this->_validateInt('{@item.php_name}', $value);
|
||||
{/if}
|
||||
{if item.validate_string}
|
||||
$this->_validateString('{@item.php_name}', $value);
|
||||
{/if}
|
||||
{if item.validate_float}
|
||||
$this->_validateFloat('{@item.php_name}', $value);
|
||||
{/if}
|
||||
{if item.validate_date}
|
||||
$this->_validateDate('{@item.php_name}', $value);
|
||||
{/if}
|
||||
|
||||
if ($this->data['{@item.name}'] === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['{@item.name}'] = $value;
|
||||
|
||||
$this->_setModified('{@item.name}');
|
||||
}
|
||||
|
||||
{/loop}{loop table.relationships.toOne}
|
||||
/**
|
||||
* Get the {@item.table_php_name} model for this {@parent.table.php_name} by {@item.col_php}.
|
||||
*
|
||||
* @uses \{@parent.appNamespace}\Store\{@item.table_php_name}Store::getBy{@item.col_php}()
|
||||
* @uses \{@parent.appNamespace}\Model\{@item.table_php_name}
|
||||
* @return \{@parent.appNamespace}\Model\{@item.table_php_name}
|
||||
*/
|
||||
public function get{@item.php_name}()
|
||||
{
|
||||
$key = $this->get{@item.from_col_php}();
|
||||
|
||||
if (empty($key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheKey = 'Cache.{@item.table_php_name}.' . $key;
|
||||
$rtn = $this->cache->get($cacheKey, null);
|
||||
|
||||
if (empty($rtn)) {
|
||||
$rtn = Factory::getStore('{@item.table_php_name}', '{get_namespace model: item.table_php_name}')->getBy{@item.col_php}($key);
|
||||
$this->cache->set($cacheKey, $rtn);
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set {@item.php_name} - Accepts an ID, an array representing a {@item.table_php_name} or a {@item.table_php_name} model.
|
||||
*
|
||||
* @param $value mixed
|
||||
*/
|
||||
public function set{@item.php_name}($value)
|
||||
{
|
||||
// Is this an instance of {@item.table_php_name}?
|
||||
if ($value instanceof \{@parent.appNamespace}\Model\{@item.table_php_name}) {
|
||||
return $this->set{@item.php_name}Object($value);
|
||||
}
|
||||
|
||||
// Is this an array representing a {@item.table_php_name} item?
|
||||
if (is_array($value) && !empty($value['{@item.col}'])) {
|
||||
return $this->set{@item.from_col_php}($value['{@item.col}']);
|
||||
}
|
||||
|
||||
// Is this a scalar value representing the ID of this foreign key?
|
||||
return $this->set{@item.from_col_php}($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set {@item.php_name} - Accepts a {@item.table_php_name} model.
|
||||
*
|
||||
* @param $value \{@parent.appNamespace}\Model\{@item.table_php_name}
|
||||
*/
|
||||
public function set{@item.php_name}Object(\{@parent.appNamespace}\Model\{@item.table_php_name} $value)
|
||||
{
|
||||
return $this->set{@item.from_col_php}($value->get{@item.col_php}());
|
||||
}
|
||||
|
||||
{/loop}{loop table.relationships.toMany}
|
||||
/**
|
||||
* Get {@item.table_php} models by {@item.from_col_php} for this {@parent.table.php_name}.
|
||||
*
|
||||
* @uses \{@parent.appNamespace}\Store\{@item.table_php}Store::getBy{@item.from_col_php}()
|
||||
* @uses \{@parent.appNamespace}\Model\{@item.table_php}
|
||||
* @return \{@parent.appNamespace}\Model\{@item.table_php}[]
|
||||
*/
|
||||
public function get{@item.php_name}()
|
||||
{
|
||||
return Factory::getStore('{@item.table_php}', '{get_namespace model: item.table_php_name}')->getBy{@item.from_col_php}($this->get{@item.col_php}());
|
||||
}
|
||||
|
||||
{/loop}}
|
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* {@table.php_name} base store for table: {@name}
|
||||
*/
|
||||
|
||||
namespace {@appNamespace}\Store\Base;
|
||||
|
||||
use b8\Database;
|
||||
use b8\Exception\HttpException;
|
||||
use {@appNamespace}\Store;
|
||||
use {@appNamespace}\Model\{@table.php_name};
|
||||
|
||||
/**
|
||||
* {@table.php_name} Base Store
|
||||
*/
|
||||
class {@table.php_name}StoreBase extends Store
|
||||
{
|
||||
protected $tableName = '{@name}';
|
||||
protected $modelName = '\{@appNamespace}\Model\{@table.php_name}';
|
||||
{if table.primary_key}
|
||||
protected $primaryKey = '{@table.primary_key.column}';
|
||||
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
{
|
||||
return $this->getBy{@table.primary_key.php_name}($value, $useConnection);
|
||||
}
|
||||
{/if}
|
||||
{ifnot table.primary_key}
|
||||
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
{
|
||||
throw new \Exception('getByPrimaryKey is not implemented for this store, as the table has no primary key.');
|
||||
}
|
||||
{/ifnot}
|
||||
{loop table.columns}
|
||||
{if item.unique_indexed}
|
||||
|
||||
public function getBy{@item.php_name}($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `{@parent.name}` WHERE `{@item.name}` = :{@item.name} LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':{@item.name}', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new {@parent.table.php_name}($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
{/if}
|
||||
{if item.many_indexed}
|
||||
|
||||
public function getBy{@item.php_name}($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
{if counts}
|
||||
$query = 'SELECT COUNT(*) AS cnt FROM `{@parent.name}` WHERE `{@item.name}` = :{@item.name}';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':{@item.name}', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$count = (int)$res['cnt'];
|
||||
} else {
|
||||
$count = 0;
|
||||
}
|
||||
{/if}
|
||||
|
||||
$query = 'SELECT * FROM `{@parent.name}` WHERE `{@item.name}` = :{@item.name} LIMIT :limit';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':{@item.name}', $value);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new {@parent.table.php_name}($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
{ifnot counts}$count = count($rtn);{/ifnot}
|
||||
|
||||
return array('items' => $rtn, 'count' => $count);
|
||||
} else {
|
||||
return array('items' => array(), 'count' => 0);
|
||||
}
|
||||
}
|
||||
{/if}
|
||||
{/loop}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* {@table.php_name} controller for table: {@name}
|
||||
*/
|
||||
|
||||
namespace {@appNamespace}\Controller;
|
||||
|
||||
use {@appNamespace}\Controller\Base\{@table.php_name}ControllerBase;
|
||||
|
||||
/**
|
||||
* {@table.php_name} Controller
|
||||
* @uses {@appNamespace}\Controller\Base\{@table.php_name}Base
|
||||
* @uses {@appNamespace}\Store\{@table.php_name}Store
|
||||
* @uses {@appNamespace}\Model\{@table.php_name}
|
||||
*/
|
||||
class {@table.php_name}Controller extends {@table.php_name}ControllerBase
|
||||
{
|
||||
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* {@table.php_name} model for table: {@name}
|
||||
*/
|
||||
|
||||
namespace {@appNamespace}\Model;
|
||||
|
||||
use {@appNamespace}\Model\Base\{@table.php_name}Base;
|
||||
|
||||
/**
|
||||
* {@table.php_name} Model
|
||||
* @uses {@appNamespace}\Model\Base\{@table.php_name}Base
|
||||
*/
|
||||
class {@table.php_name} extends {@table.php_name}Base
|
||||
{
|
||||
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* {@table.php_name} store for table: {@name}
|
||||
*/
|
||||
|
||||
namespace {@appNamespace}\Store;
|
||||
|
||||
use {@appNamespace}\Store\Base\{@table.php_name}StoreBase;
|
||||
|
||||
/**
|
||||
* {@table.php_name} Store
|
||||
* @uses {@appNamespace}\Store\Base\{@table.php_name}StoreBase
|
||||
*/
|
||||
class {@table.php_name}Store extends {@table.php_name}StoreBase
|
||||
{
|
||||
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
|
||||
}
|
|
@ -4,21 +4,21 @@ namespace b8\Exception;
|
|||
|
||||
class HttpException extends \Exception
|
||||
{
|
||||
protected $errorCode = 500;
|
||||
protected $statusMessage = 'Internal Server Error';
|
||||
protected $errorCode = 500;
|
||||
protected $statusMessage = 'Internal Server Error';
|
||||
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
public function getStatusMessage()
|
||||
{
|
||||
return $this->statusMessage;
|
||||
}
|
||||
public function getStatusMessage()
|
||||
{
|
||||
return $this->statusMessage;
|
||||
}
|
||||
|
||||
public function getHttpHeader()
|
||||
{
|
||||
return 'HTTP/1.1 ' . $this->errorCode . ' ' . $this->statusMessage;
|
||||
}
|
||||
}
|
||||
public function getHttpHeader()
|
||||
{
|
||||
return 'HTTP/1.1 ' . $this->errorCode . ' ' . $this->statusMessage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Exception\HttpException;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
|
||||
class BadRequestException extends HttpException
|
||||
{
|
||||
protected $errorCode = 400;
|
||||
protected $statusMessage = 'Bad Request';
|
||||
}
|
||||
protected $errorCode = 400;
|
||||
protected $statusMessage = 'Bad Request';
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Exception\HttpException;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
|
||||
class ForbiddenException extends HttpException
|
||||
{
|
||||
protected $errorCode = 403;
|
||||
protected $statusMessage = 'Forbidden';
|
||||
}
|
||||
protected $errorCode = 403;
|
||||
protected $statusMessage = 'Forbidden';
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Exception\HttpException;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
|
||||
class NotAuthorizedException extends HttpException
|
||||
{
|
||||
protected $errorCode = 401;
|
||||
protected $statusMessage = 'Not Authorized';
|
||||
}
|
||||
protected $errorCode = 401;
|
||||
protected $statusMessage = 'Not Authorized';
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Exception\HttpException;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
|
||||
class NotFoundException extends HttpException
|
||||
{
|
||||
protected $errorCode = 404;
|
||||
protected $statusMessage = 'Not Found';
|
||||
}
|
||||
protected $errorCode = 404;
|
||||
protected $statusMessage = 'Not Found';
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Exception\HttpException;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
|
||||
class ServerErrorException extends HttpException
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Exception\HttpException;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
|
||||
class ValidationException extends HttpException
|
||||
{
|
||||
protected $errorCode = 400;
|
||||
protected $statusMessage = 'Bad Request';
|
||||
}
|
||||
protected $errorCode = 400;
|
||||
protected $statusMessage = 'Bad Request';
|
||||
}
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace b8;
|
||||
use b8\Form\FieldSet,
|
||||
b8\View;
|
||||
|
||||
use b8\Form\FieldSet, b8\View;
|
||||
|
||||
class Form extends FieldSet
|
||||
{
|
||||
protected $_action = '';
|
||||
protected $_method = 'POST';
|
||||
protected $_action = '';
|
||||
protected $_method = 'POST';
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
return $this->_action;
|
||||
}
|
||||
public function getAction()
|
||||
{
|
||||
return $this->_action;
|
||||
}
|
||||
|
||||
public function setAction($action)
|
||||
{
|
||||
$this->_action = $action;
|
||||
}
|
||||
public function setAction($action)
|
||||
{
|
||||
$this->_action = $action;
|
||||
}
|
||||
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->_method;
|
||||
}
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->_method;
|
||||
}
|
||||
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->_method = $method;
|
||||
}
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->_method = $method;
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
$view->action = $this->getAction();
|
||||
$view->method = $this->getMethod();
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
$view->action = $this->getAction();
|
||||
$view->method = $this->getMethod();
|
||||
|
||||
parent::_onPreRender($view);
|
||||
}
|
||||
parent::_onPreRender($view);
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,4 +4,4 @@ namespace b8\Form;
|
|||
|
||||
class ControlGroup extends FieldSet
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,112 +7,107 @@ use b8\Config;
|
|||
|
||||
abstract class Element
|
||||
{
|
||||
protected $_name;
|
||||
protected $_id;
|
||||
protected $_label;
|
||||
protected $_css;
|
||||
protected $_ccss;
|
||||
protected $_parent;
|
||||
protected $_name;
|
||||
protected $_id;
|
||||
protected $_label;
|
||||
protected $_css;
|
||||
protected $_ccss;
|
||||
protected $_parent;
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
if(!is_null($name))
|
||||
{
|
||||
$this->setName($name);
|
||||
}
|
||||
}
|
||||
public function __construct($name = null)
|
||||
{
|
||||
if (!is_null($name)) {
|
||||
$this->setName($name);
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = strtolower(preg_replace('/([^a-zA-Z0-9_\-])/', '', $name));
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = strtolower(preg_replace('/([^a-zA-Z0-9_\-])/', '', $name));
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return !$this->_id ? 'element-'.$this->_name : $this->_id;
|
||||
}
|
||||
public function getId()
|
||||
{
|
||||
return !$this->_id ? 'element-' . $this->_name : $this->_id;
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->_id = $id;
|
||||
public function setId($id)
|
||||
{
|
||||
$this->_id = $id;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->_label;
|
||||
}
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->_label;
|
||||
}
|
||||
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->_label = $label;
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->_label = $label;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function getClass()
|
||||
{
|
||||
return $this->_css;
|
||||
}
|
||||
public function getClass()
|
||||
{
|
||||
return $this->_css;
|
||||
}
|
||||
|
||||
public function setClass($class)
|
||||
{
|
||||
$this->_css = $class;
|
||||
public function setClass($class)
|
||||
{
|
||||
$this->_css = $class;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function getContainerClass()
|
||||
{
|
||||
return $this->_ccss;
|
||||
}
|
||||
public function getContainerClass()
|
||||
{
|
||||
return $this->_ccss;
|
||||
}
|
||||
|
||||
public function setContainerClass($class)
|
||||
{
|
||||
$this->_ccss = $class;
|
||||
public function setContainerClass($class)
|
||||
{
|
||||
$this->_ccss = $class;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function setParent(Element $parent)
|
||||
{
|
||||
$this->_parent = $parent;
|
||||
public function setParent(Element $parent)
|
||||
{
|
||||
$this->_parent = $parent;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
$viewPath = Config::getInstance()->get('b8.view.path');
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
$viewPath = Config::getInstance()->get('b8.view.path');
|
||||
|
||||
if(is_null($viewFile))
|
||||
{
|
||||
$class = explode('\\', get_called_class());
|
||||
$viewFile = end($class);
|
||||
}
|
||||
if (is_null($viewFile)) {
|
||||
$class = explode('\\', get_called_class());
|
||||
$viewFile = end($class);
|
||||
}
|
||||
|
||||
if(file_exists($viewPath . 'Form/' . $viewFile . '.phtml'))
|
||||
{
|
||||
$view = new View('Form/' . $viewFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
$view = new View($viewFile, B8_PATH . 'Form/View/');
|
||||
}
|
||||
if (file_exists($viewPath . 'Form/' . $viewFile . '.phtml')) {
|
||||
$view = new View('Form/' . $viewFile);
|
||||
} else {
|
||||
$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->css = $this->getClass();
|
||||
$view->ccss = $this->getContainerClass();
|
||||
$view->parent = $this->_parent;
|
||||
|
||||
$this->_onPreRender($view);
|
||||
$this->_onPreRender($view);
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
abstract protected function _onPreRender(View &$view);
|
||||
}
|
||||
abstract protected function _onPreRender(View &$view);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\Form\Input,
|
||||
b8\View;
|
||||
|
||||
use b8\Form\Input, b8\View;
|
||||
|
||||
class Button extends Input
|
||||
{
|
||||
public function validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'button';
|
||||
}
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'button';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,48 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\View,
|
||||
b8\Form\Input;
|
||||
|
||||
use b8\View, b8\Form\Input;
|
||||
|
||||
class Checkbox extends Input
|
||||
{
|
||||
protected $_checked;
|
||||
protected $_checkedValue;
|
||||
protected $_checked;
|
||||
protected $_checkedValue;
|
||||
|
||||
public function getCheckedValue()
|
||||
{
|
||||
return $this->_checkedValue;
|
||||
}
|
||||
public function getCheckedValue()
|
||||
{
|
||||
return $this->_checkedValue;
|
||||
}
|
||||
|
||||
public function setCheckedValue($value)
|
||||
{
|
||||
$this->_checkedValue = $value;
|
||||
}
|
||||
public function setCheckedValue($value)
|
||||
{
|
||||
$this->_checkedValue = $value;
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
if(is_bool($value) && $value == true)
|
||||
{
|
||||
$this->_value = $this->getCheckedValue();
|
||||
$this->_checked = true;
|
||||
return;
|
||||
}
|
||||
public function setValue($value)
|
||||
{
|
||||
if (is_bool($value) && $value == true) {
|
||||
$this->_value = $this->getCheckedValue();
|
||||
$this->_checked = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if($value == $this->getCheckedValue())
|
||||
{
|
||||
$this->_value = $this->getCheckedValue();
|
||||
$this->_checked = true;
|
||||
return;
|
||||
}
|
||||
if ($value == $this->getCheckedValue()) {
|
||||
$this->_value = $this->getCheckedValue();
|
||||
$this->_checked = true;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_value = $value;
|
||||
$this->_checked = false;
|
||||
}
|
||||
$this->_value = $value;
|
||||
$this->_checked = false;
|
||||
}
|
||||
|
||||
public function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->checkedValue = $this->getCheckedValue();
|
||||
$view->checked = $this->_checked;
|
||||
}
|
||||
}
|
||||
public function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->checkedValue = $this->getCheckedValue();
|
||||
$view->checked = $this->_checked;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\Form\FieldSet;
|
||||
|
||||
class CheckboxGroup extends FieldSet
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\Form\Element\Hidden,
|
||||
b8\View;
|
||||
|
||||
use b8\View;
|
||||
|
||||
class Csrf extends Hidden
|
||||
{
|
||||
protected $_rows = 4;
|
||||
protected $_rows = 4;
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if($this->_value != $_COOKIE[$this->getName()])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function validate()
|
||||
{
|
||||
if ($this->_value != $_COOKIE[$this->getName()]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$csrf = md5(microtime(true));
|
||||
$view->csrf = $csrf;
|
||||
setcookie($this->getName(), $csrf);
|
||||
}
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$csrf = md5(microtime(true));
|
||||
$view->csrf = $csrf;
|
||||
setcookie($this->getName(), $csrf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
|
||||
class Email extends Text
|
||||
{
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'email';
|
||||
}
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'email';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\Form\Input,
|
||||
b8\View;
|
||||
|
||||
use b8\Form\Input, b8\View;
|
||||
|
||||
class Hidden extends Input
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\Form\Element\Text,
|
||||
b8\View;
|
||||
|
||||
use b8\View;
|
||||
|
||||
class Password extends Text
|
||||
{
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'password';
|
||||
}
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'password';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\Form\Element\Select;
|
||||
|
||||
class Radio extends Select
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\Form\Element\Button,
|
||||
b8\View;
|
||||
|
||||
use b8\View;
|
||||
|
||||
class Submit extends Button
|
||||
{
|
||||
protected $_value = 'Submit';
|
||||
protected $_value = 'Submit';
|
||||
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Button'));
|
||||
}
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Button'));
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'submit';
|
||||
}
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'submit';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\Form\Input,
|
||||
b8\View;
|
||||
|
||||
use b8\Form\Input, b8\View;
|
||||
|
||||
class Text extends Input
|
||||
{
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'text';
|
||||
}
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'text';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
use b8\Form\Element\Text,
|
||||
b8\View;
|
||||
|
||||
use b8\View;
|
||||
|
||||
class TextArea extends Text
|
||||
{
|
||||
protected $_rows = 4;
|
||||
protected $_rows = 4;
|
||||
|
||||
public function getRows()
|
||||
{
|
||||
return $this->_rows;
|
||||
}
|
||||
public function getRows()
|
||||
{
|
||||
return $this->_rows;
|
||||
}
|
||||
|
||||
public function setRows($rows)
|
||||
{
|
||||
$this->_rows = $rows;
|
||||
}
|
||||
public function setRows($rows)
|
||||
{
|
||||
$this->_rows = $rows;
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->rows = $this->getRows();
|
||||
}
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->rows = $this->getRows();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
|
||||
class Url extends Text
|
||||
{
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
public function render($viewFile = null)
|
||||
{
|
||||
return parent::render(($viewFile ? $viewFile : 'Text'));
|
||||
}
|
||||
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'url';
|
||||
}
|
||||
}
|
||||
protected function _onPreRender(View &$view)
|
||||
{
|
||||
parent::_onPreRender($view);
|
||||
$view->type = 'url';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,4 +89,4 @@ class FieldSet extends Element
|
|||
{
|
||||
return $this->_children[$fieldName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
namespace b8\Form;
|
||||
|
||||
use b8\Form\Element,
|
||||
b8\View;
|
||||
use b8\Form\Element, b8\View;
|
||||
|
||||
class Input extends Element
|
||||
{
|
||||
|
@ -115,4 +114,4 @@ class Input extends Element
|
|||
$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 <?php print $css; ?>" type="<?php print $type; ?>" value="<?php print $value; ?>">
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
<?php if(!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
|
||||
<div class="control-group <?php print $ccss ?> <?php print (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>
|
||||
<?php if(isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if(!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
|
||||
<div class="control-group <?php print $ccss ?> <?php print (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>
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!($parent instanceof \b8\Form\Element\CheckboxGroup)): ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<div class="control-group <?php print $css; ?>">
|
||||
<?php if($label): ?>
|
||||
<label class="control-label"><?php print $label; ?></label>
|
||||
<?php endif; ?>
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label"><?php print $label; ?></label>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="controls">
|
||||
<?php foreach($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<div class="control-group <?php print $css; ?>">
|
||||
|
||||
<?php foreach($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?php print $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="<?php print $id; ?>" name="<?php print $name; ?>" value="<?php print $csrf; ?>">
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<fieldset class="row <?php print $css; ?>">
|
||||
<?php if($label): ?>
|
||||
<legend><?php print $label; ?></legend>
|
||||
<?php endif; ?>
|
||||
<?php if ($label): ?>
|
||||
<legend><?php print $label; ?></legend>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<form id="<?php print $id; ?>" class="<?php print $css; ?>" action="<?php print $action; ?>" method="<?php print $method; ?>">
|
||||
<?php foreach($children as $field): ?>
|
||||
<?php print $field; ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</form>
|
||||
<?php foreach ($children as $field): ?>
|
||||
<?php print $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="<?php print $id; ?>" name="<?php print $name; ?>" value="<?php print $value; ?>">
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
<div id="<?php print $id; ?>" class="control-group <?php print $ccss; ?>">
|
||||
<?php if($label): ?>
|
||||
<label class="control-label"><?php print $label; ?></label>
|
||||
<?php endif; ?>
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label"><?php print $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>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<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>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if(isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
<div class="control-group <?php print $ccss; ?>">
|
||||
<?php if($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $label; ?></label>
|
||||
<?php endif; ?>
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $label; ?></label>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="controls">
|
||||
<select id="<?php print $id; ?>" class="<?php print $css; ?>" name="<?php print $name; ?>">
|
||||
<?php foreach($options as $val => $lbl): ?>
|
||||
<option value="<?php print $val; ?>" <?php print ($value == $val) ? ' selected="selected"' : ''; ?>><?php print $lbl; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="controls">
|
||||
<select id="<?php print $id; ?>" class="<?php print $css; ?>" name="<?php print $name; ?>">
|
||||
<?php foreach ($options as $val => $lbl): ?>
|
||||
<option
|
||||
value="<?php print $val; ?>" <?php print ($value == $val) ? ' selected="selected"' : ''; ?>><?php print $lbl; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<?php if(isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
<div class="control-group <?php print $ccss; ?> <?php print (isset($error) ? 'error' : ''); ?>">
|
||||
<?php if($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $label; ?></label>
|
||||
<?php endif; ?>
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $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' : '' ?>>
|
||||
<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' : '' ?>>
|
||||
|
||||
<?php if(isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<div class="control-group <?php print $ccss; ?> <?php print (isset($error) ? 'error' : ''); ?>">
|
||||
<?php if($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $label; ?></label>
|
||||
<?php endif; ?>
|
||||
<?php if ($label): ?>
|
||||
<label class="control-label" for="<?php print $id ?>"><?php print $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>
|
||||
|
||||
<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>
|
||||
|
||||
<?php if(isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (isset($error)): ?>
|
||||
<span class="help-block"><?php print $error; ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -21,7 +21,7 @@ class Request
|
|||
{
|
||||
$this->parseInput();
|
||||
|
||||
$this->data['path'] = $this->getRequestPath();
|
||||
$this->data['path'] = $this->getRequestPath();
|
||||
$this->data['parts'] = array_values(array_filter(explode('/', $this->data['path'])));
|
||||
}
|
||||
|
||||
|
|
|
@ -27,4 +27,4 @@ class JsonResponse extends Response
|
|||
|
||||
return json_encode(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,22 +6,22 @@ use b8\Http\Response;
|
|||
|
||||
class RedirectResponse extends Response
|
||||
{
|
||||
public function __construct(Response $createFrom = null)
|
||||
{
|
||||
parent::__construct($createFrom);
|
||||
public function __construct(Response $createFrom = null)
|
||||
{
|
||||
parent::__construct($createFrom);
|
||||
|
||||
$this->setContent(null);
|
||||
$this->setResponseCode(302);
|
||||
}
|
||||
$this->setContent(null);
|
||||
$this->setResponseCode(302);
|
||||
}
|
||||
|
||||
public function hasLayout()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function hasLayout()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function flush()
|
||||
{
|
||||
parent::flush();
|
||||
die;
|
||||
}
|
||||
}
|
||||
public function flush()
|
||||
{
|
||||
parent::flush();
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,16 @@ namespace b8\Http;
|
|||
|
||||
use b8\Application;
|
||||
use b8\Config;
|
||||
use b8\Http\Request;
|
||||
|
||||
class Router
|
||||
{
|
||||
/**
|
||||
* @var \b8\Http\Request;
|
||||
* @var Request;
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @var \b8\Http\Config;
|
||||
* @var Config;
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
|
@ -126,4 +125,4 @@ class Router
|
|||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,4 +164,4 @@ class HttpClient
|
|||
|
||||
return $rtn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ class Image
|
|||
public static $cachePath = '/tmp/';
|
||||
public static $sourcePath = './';
|
||||
|
||||
|
||||
/**
|
||||
* @var \Imagick
|
||||
*/
|
||||
|
@ -146,4 +145,4 @@ class Image
|
|||
|
||||
return $rtn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,9 +118,6 @@ class Model
|
|||
$this->modified[$column] = $column;
|
||||
}
|
||||
|
||||
//----------------
|
||||
// Validation
|
||||
//----------------
|
||||
protected function _validateString($name, $value)
|
||||
{
|
||||
if (!is_string($value) && !is_null($value)) {
|
||||
|
|
|
@ -313,4 +313,4 @@ abstract class Store
|
|||
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,21 @@ namespace b8\Type;
|
|||
|
||||
interface Cache
|
||||
{
|
||||
public function get($key, $default = null);
|
||||
public function set($key, $value = null, $ttl = 0);
|
||||
public function delete($key);
|
||||
public function contains($key);
|
||||
public function isEnabled();
|
||||
public function get($key, $default = null);
|
||||
|
||||
public function __get($key);
|
||||
public function __set($key, $value = null);
|
||||
public function __unset($key);
|
||||
public function __isset($key);
|
||||
}
|
||||
public function set($key, $value = null, $ttl = 0);
|
||||
|
||||
public function delete($key);
|
||||
|
||||
public function contains($key);
|
||||
|
||||
public function isEnabled();
|
||||
|
||||
public function __get($key);
|
||||
|
||||
public function __set($key, $value = null);
|
||||
|
||||
public function __unset($key);
|
||||
|
||||
public function __isset($key);
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@ namespace b8\Type;
|
|||
|
||||
interface RestUser
|
||||
{
|
||||
public function checkPermission($permission, $resource);
|
||||
}
|
||||
public function checkPermission($permission, $resource);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ namespace b8\View\Helper;
|
|||
|
||||
class Format
|
||||
{
|
||||
public function Currency($number, $symbol = true)
|
||||
{
|
||||
return ($symbol ? '£' : '') . number_format($number, 2, '.', ',');
|
||||
}
|
||||
}
|
||||
public function Currency($number, $symbol = true)
|
||||
{
|
||||
return ($symbol ? '£' : '') . number_format($number, 2, '.', ',');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use b8\View;
|
|||
class Template extends View
|
||||
{
|
||||
public static $templateFunctions = [];
|
||||
protected static $extension = 'html';
|
||||
protected static $extension = 'html';
|
||||
|
||||
public function __construct($viewCode)
|
||||
{
|
||||
|
@ -267,9 +267,9 @@ class Template extends View
|
|||
$rtn = '';
|
||||
foreach ($working as $key => $val) {
|
||||
// Make sure we support nesting loops:
|
||||
$keyWas = isset($this->key) ? $this->key : null;
|
||||
$valWas = isset($this->value) ? $this->value : null;
|
||||
$itemWas = isset($this->item) ? $this->item : null;
|
||||
$keyWas = isset($this->key) ? $this->key : null;
|
||||
$valWas = isset($this->value) ? $this->value : null;
|
||||
$itemWas = isset($this->item) ? $this->item : null;
|
||||
|
||||
// Set up the necessary variables within the stack:
|
||||
$this->parent = $this;
|
||||
|
@ -537,4 +537,4 @@ class Template extends View
|
|||
|
||||
return $this->{$helper}()->{$function}();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace b8\View;
|
||||
|
||||
use b8\View\Template;
|
||||
|
||||
class UserView extends Template
|
||||
{
|
||||
public function __construct($string)
|
||||
|
@ -11,4 +9,4 @@ class UserView extends Template
|
|||
trigger_error('Use of UserView is now deprecated. Please use Template instead.', E_USER_NOTICE);
|
||||
parent::__construct($string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class Application extends b8\Application
|
|||
} else {
|
||||
$_SESSION['phpci_login_redirect'] = substr($request->getPath(), 1);
|
||||
$response = new RedirectResponse($response);
|
||||
$response->setHeader('Location', PHPCI_URL.'session/login');
|
||||
$response->setHeader('Location', PHPCI_URL . 'session/login');
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -110,7 +110,7 @@ class Builder implements LoggerAwareInterface
|
|||
$this->buildLogger = new BuildLogger($logger, $build);
|
||||
|
||||
$pluginFactory = $this->buildPluginFactory($build);
|
||||
$pluginFactory->addConfigFromFile(PHPCI_DIR . "/app/pluginconfig.php");
|
||||
$pluginFactory->addConfigFromFile(PHPCI_APP_DIR . "pluginconfig.php");
|
||||
$this->pluginExecutor = new Plugin\Util\Executor($pluginFactory, $this->buildLogger);
|
||||
|
||||
$executorClass = 'PHPCI\Helper\UnixCommandExecutor';
|
||||
|
@ -120,7 +120,7 @@ class Builder implements LoggerAwareInterface
|
|||
|
||||
$this->commandExecutor = new $executorClass(
|
||||
$this->buildLogger,
|
||||
PHPCI_DIR,
|
||||
ROOT_DIR,
|
||||
$this->quiet,
|
||||
$this->verbose
|
||||
);
|
||||
|
|
|
@ -62,19 +62,19 @@ class DaemonCommand extends Command
|
|||
->setDescription('Initiates the daemon to run commands.')
|
||||
->addArgument(
|
||||
'state', InputArgument::REQUIRED, 'start|stop|status'
|
||||
)
|
||||
->addOption(
|
||||
'pid-file', 'p', InputOption::VALUE_REQUIRED,
|
||||
)->addOption(
|
||||
'pid-file',
|
||||
'p',
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Path of the PID file',
|
||||
implode(DIRECTORY_SEPARATOR,
|
||||
[PHPCI_DIR, 'daemon', 'daemon.pid'])
|
||||
)
|
||||
->addOption(
|
||||
'log-file', 'l', InputOption::VALUE_REQUIRED,
|
||||
(ROOT_DIR . 'runtime' . DIRECTORY_SEPARATOR . 'daemon' . DIRECTORY_SEPARATOR . 'daemon.pid')
|
||||
)->addOption(
|
||||
'log-file',
|
||||
'l',
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Path of the log file',
|
||||
implode(DIRECTORY_SEPARATOR,
|
||||
[PHPCI_DIR, 'daemon', 'daemon.log'])
|
||||
);
|
||||
(ROOT_DIR . 'runtime' . DIRECTORY_SEPARATOR . 'daemon' . DIRECTORY_SEPARATOR . 'daemon.log')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,8 +113,8 @@ class DaemonCommand extends Command
|
|||
|
||||
$this->logger->info("Trying to start the daemon");
|
||||
|
||||
$cmd = "nohup %s/daemonise phpci:daemonise > %s 2>&1 &";
|
||||
$command = sprintf($cmd, PHPCI_DIR, $this->logFilePath);
|
||||
$cmd = "nohup %sdaemonise phpci:daemonise > %s 2>&1 &";
|
||||
$command = sprintf($cmd, PHPCI_BIN_DIR, $this->logFilePath);
|
||||
$output = $exitCode = null;
|
||||
exec($command, $output, $exitCode);
|
||||
|
||||
|
|
|
@ -65,14 +65,14 @@ class DaemoniseCommand extends Command
|
|||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$cmd = "echo %s > '%s/daemon/daemon.pid'";
|
||||
$command = sprintf($cmd, getmypid(), PHPCI_DIR);
|
||||
$cmd = "echo %s > '%sdaemon/daemon.pid'";
|
||||
$command = sprintf($cmd, getmypid(), PHPCI_RUNTIME_DIR);
|
||||
exec($command);
|
||||
|
||||
$this->output = $output;
|
||||
$this->run = true;
|
||||
$this->sleep = 0;
|
||||
$runner = new RunCommand($this->logger);
|
||||
$this->run = true;
|
||||
$this->sleep = 0;
|
||||
$runner = new RunCommand($this->logger);
|
||||
$runner->setMaxBuilds(1);
|
||||
$runner->setDaemon(true);
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use b8\Database;
|
||||
use b8\Database\CodeGenerator;
|
||||
|
||||
/**
|
||||
* Generate console command - Reads the database and generates models and stores.
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Console
|
||||
*/
|
||||
class GenerateCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('phpci:generate')
|
||||
->setDescription('Generate models and stores from the database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Model and Store classes by reading database meta data.
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$gen = new CodeGenerator(
|
||||
Database::getConnection(),
|
||||
['default' => 'PHPCI'],
|
||||
['default' => PHPCI_DIR],
|
||||
false
|
||||
);
|
||||
|
||||
$gen->generateModels();
|
||||
$gen->generateStores();
|
||||
}
|
||||
}
|
|
@ -35,8 +35,8 @@ class InstallCommand extends Command
|
|||
|
||||
protected function configure()
|
||||
{
|
||||
$defaultPath = PHPCI_DIR . 'PHPCI/config.yml';
|
||||
|
||||
$defaultPath = PHPCI_APP_DIR . 'config.yml';
|
||||
|
||||
$this
|
||||
->setName('phpci:install')
|
||||
->addOption('url', null, InputOption::VALUE_OPTIONAL, Lang::get('installation_url'))
|
||||
|
@ -363,8 +363,8 @@ class InstallCommand extends Command
|
|||
{
|
||||
$output->write(Lang::get('setting_up_db'));
|
||||
|
||||
$phinxBinary = escapeshellarg(PHPCI_DIR . 'vendor/bin/phinx');
|
||||
$phinxScript = escapeshellarg(PHPCI_DIR . 'app/phinx.php');
|
||||
$phinxBinary = escapeshellarg(ROOT_DIR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'phinx');
|
||||
$phinxScript = escapeshellarg(PHPCI_APP_DIR . 'phinx.php');
|
||||
shell_exec($phinxBinary . ' migrate -c ' . $phinxScript);
|
||||
|
||||
$output->writeln('<info>'.Lang::get('ok').'</info>');
|
||||
|
|
|
@ -51,7 +51,7 @@ class PollCommand extends Command
|
|||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$parser = new Parser();
|
||||
$yaml = file_get_contents(APPLICATION_PATH . 'PHPCI/config.yml');
|
||||
$yaml = file_get_contents(PHPCI_APP_DIR . 'config.yml');
|
||||
$this->settings = $parser->parse($yaml);
|
||||
|
||||
$token = $this->settings['phpci']['github']['token'];
|
||||
|
|
|
@ -53,7 +53,7 @@ class UpdateCommand extends Command
|
|||
|
||||
$output->write(Lang::get('updating_phpci'));
|
||||
|
||||
shell_exec(PHPCI_DIR . 'vendor/bin/phinx migrate -c "' . PHPCI_DIR . 'app/phinx.php"');
|
||||
shell_exec(ROOT_DIR . 'vendor/bin/phinx migrate -c "' . PHPCI_APP_DIR . 'phinx.php"');
|
||||
|
||||
$output->writeln('<info>'.Lang::get('ok').'</info>');
|
||||
}
|
||||
|
|
|
@ -107,9 +107,9 @@ class BuildController extends \PHPCI\Controller
|
|||
*/
|
||||
protected function getUiPlugins()
|
||||
{
|
||||
$rtn = [];
|
||||
$path = APPLICATION_PATH . 'public/assets/js/build-plugins/';
|
||||
$dir = opendir($path);
|
||||
$rtn = [];
|
||||
$path = PHPCI_PUBLIC_DIR . 'assets' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'build-plugins' . DIRECTORY_SEPARATOR;
|
||||
$dir = opendir($path);
|
||||
|
||||
while ($item = readdir($dir)) {
|
||||
if (substr($item, 0, 1) == '.' || substr($item, -3) != '.js') {
|
||||
|
|
|
@ -35,11 +35,9 @@ class PluginController extends \PHPCI\Controller
|
|||
$this->view->installedPackages = $json['require'];
|
||||
|
||||
$pluginInfo = new PluginInformationCollection();
|
||||
$pluginInfo->add(FilesPluginInformation::newFromDir(
|
||||
PHPCI_DIR . "PHPCI/Plugin/"
|
||||
));
|
||||
$pluginInfo->add(FilesPluginInformation::newFromDir(PHPCI_DIR . "Plugin" . DIRECTORY_SEPARATOR));
|
||||
$pluginInfo->add(ComposerPluginInformation::buildFromYaml(
|
||||
PHPCI_DIR . "vendor/composer/installed.json"
|
||||
ROOT_DIR . "vendor" . DIRECTORY_SEPARATOR . "composer" . DIRECTORY_SEPARATOR . "installed.json"
|
||||
));
|
||||
|
||||
$this->view->plugins = $pluginInfo->getInstalledPlugins();
|
||||
|
@ -55,7 +53,7 @@ class PluginController extends \PHPCI\Controller
|
|||
*/
|
||||
protected function getComposerJson()
|
||||
{
|
||||
$json = file_get_contents(APPLICATION_PATH . 'composer.json');
|
||||
$json = file_get_contents(ROOT_DIR . 'composer.json');
|
||||
return json_decode($json, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class SettingsController extends Controller
|
|||
parent::init();
|
||||
|
||||
$parser = new Parser();
|
||||
$yaml = file_get_contents(PHPCI_CONFIG_FILE);
|
||||
$yaml = file_get_contents(PHPCI_APP_DIR . 'config.yml');
|
||||
$this->settings = $parser->parse($yaml);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class SettingsController extends Controller
|
|||
$authSettings = $this->settings['phpci']['authentication_settings'];
|
||||
}
|
||||
|
||||
$this->view->configFile = PHPCI_CONFIG_FILE;
|
||||
$this->view->configFile = PHPCI_APP_DIR . 'config.yml';
|
||||
$this->view->basicSettings = $this->getBasicForm($basicSettings);
|
||||
$this->view->buildSettings = $this->getBuildForm($buildSettings);
|
||||
$this->view->github = $this->getGithubForm();
|
||||
|
@ -242,7 +242,7 @@ class SettingsController extends Controller
|
|||
{
|
||||
$dumper = new Dumper();
|
||||
$yaml = $dumper->dump($this->settings, 4);
|
||||
file_put_contents(PHPCI_CONFIG_FILE, $yaml);
|
||||
file_put_contents(PHPCI_APP_DIR . 'config.yml', $yaml);
|
||||
|
||||
if (error_get_last()) {
|
||||
$error_get_last = error_get_last();
|
||||
|
@ -387,7 +387,7 @@ class SettingsController extends Controller
|
|||
*/
|
||||
protected function canWriteConfig()
|
||||
{
|
||||
return is_writeable(PHPCI_CONFIG_FILE);
|
||||
return is_writeable(PHPCI_APP_DIR . 'config.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,11 +59,11 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
|||
*/
|
||||
public function __construct(BuildLogger $logger, $rootDir, &$quiet = false, &$verbose = false)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->quiet = $quiet;
|
||||
$this->logger = $logger;
|
||||
$this->quiet = $quiet;
|
||||
$this->verbose = $verbose;
|
||||
$this->lastOutput = [];
|
||||
$this->rootDir = rtrim($rootDir, '/\\') . DIRECTORY_SEPARATOR;
|
||||
$this->rootDir = $rootDir;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,9 +158,9 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
|||
foreach ($binary as $bin) {
|
||||
$this->logger->log(Lang::get('looking_for_binary', $bin), LogLevel::DEBUG);
|
||||
|
||||
if (is_dir($composerBin) && is_file($composerBin.'/'.$bin)) {
|
||||
if (is_dir($composerBin) && is_file($composerBin . DIRECTORY_SEPARATOR . $bin)) {
|
||||
$this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
|
||||
return $composerBin . '/' . $bin;
|
||||
return $composerBin . DIRECTORY_SEPARATOR . $bin;
|
||||
}
|
||||
|
||||
if (is_file($this->rootDir . $bin)) {
|
||||
|
@ -168,9 +168,9 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
|||
return $this->rootDir . $bin;
|
||||
}
|
||||
|
||||
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
|
||||
if (is_file($this->rootDir . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin)) {
|
||||
$this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG);
|
||||
return $this->rootDir . 'vendor/bin/' . $bin;
|
||||
return $this->rootDir . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin;
|
||||
}
|
||||
|
||||
$findCmdResult = $this->findGlobalBinary($bin);
|
||||
|
@ -202,14 +202,14 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
|||
public function getComposerBinDir($path)
|
||||
{
|
||||
if (is_dir($path)) {
|
||||
$composer = $path.'/composer.json';
|
||||
$composer = $path . DIRECTORY_SEPARATOR . 'composer.json';
|
||||
if (is_file($composer)) {
|
||||
$json = json_decode(file_get_contents($composer));
|
||||
|
||||
if (isset($json->config->{"bin-dir"})) {
|
||||
return $path.'/'.$json->config->{"bin-dir"};
|
||||
} elseif (is_dir($path . '/vendor/bin')) {
|
||||
return $path . '/vendor/bin';
|
||||
return $path . DIRECTORY_SEPARATOR . $json->config->{"bin-dir"};
|
||||
} elseif (is_dir($path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin')) {
|
||||
return $path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,6 @@
|
|||
|
||||
namespace PHPCI\Helper;
|
||||
|
||||
use b8\Cache;
|
||||
use b8\Config;
|
||||
use b8\HttpClient;
|
||||
|
||||
/**
|
||||
* Provides some basic diff processing functionality.
|
||||
* @package PHPCI\Helper
|
||||
|
|
|
@ -103,11 +103,9 @@ class Lang
|
|||
public static function getLanguageOptions()
|
||||
{
|
||||
$languages = [];
|
||||
|
||||
foreach (self::$languages as $language) {
|
||||
$strings = [];
|
||||
require(PHPCI_DIR . 'src/PHPCI/Languages/lang.' . $language . '.php');
|
||||
$languages[$language] = $strings['language_name'];
|
||||
$strings = include_once(PHPCI_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.' . $language . '.php');
|
||||
$languages[$language] = !empty($strings['language_name']) ? $strings['language_name'] : $language;
|
||||
}
|
||||
|
||||
return $languages;
|
||||
|
@ -172,16 +170,14 @@ class Lang
|
|||
*/
|
||||
protected static function loadLanguage($language = null)
|
||||
{
|
||||
$language = $language
|
||||
? $language
|
||||
: self::$language;
|
||||
$langFile = PHPCI_DIR . 'src/PHPCI/Languages/lang.' . $language . '.php';
|
||||
$language = $language ? $language : self::$language;
|
||||
$langFile = PHPCI_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.' . $language . '.php';
|
||||
|
||||
if (!file_exists($langFile)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
require($langFile);
|
||||
$strings = include_once($langFile);
|
||||
|
||||
if (is_null($strings) || !is_array($strings) || !count($strings)) {
|
||||
return null;
|
||||
|
@ -196,7 +192,7 @@ class Lang
|
|||
protected static function loadAvailableLanguages()
|
||||
{
|
||||
$matches = [];
|
||||
foreach (glob(PHPCI_DIR . 'src/PHPCI/Languages/lang.*.php') as $file) {
|
||||
foreach (glob(PHPCI_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.*.php') as $file) {
|
||||
if (preg_match('/lang\.([a-z]{2}\-?[a-z]*)\.php/', $file, $matches)) {
|
||||
self::$languages[] = $matches[1];
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Dansk',
|
||||
'language' => 'Sprog',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Deutsch',
|
||||
'language' => 'Sprache',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Ελληνικά',
|
||||
'language' => 'Γλώσσα',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings =[
|
||||
return [
|
||||
'language_name' => 'English',
|
||||
'language' => 'Language',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Español',
|
||||
'language' => 'Lenguaje',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Français',
|
||||
'language' => 'Langue',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Italiano',
|
||||
'language' => 'Lingua',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Nederlands',
|
||||
'language' => 'Taal',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Polski',
|
||||
'language' => 'Język',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Pусский',
|
||||
'language' => 'язык',
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
$strings = [
|
||||
return [
|
||||
'language_name' => 'Українська',
|
||||
'language' => 'Мова',
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class Build extends BuildBase
|
|||
*/
|
||||
protected function getZeroConfigPlugins(Builder $builder)
|
||||
{
|
||||
$pluginDir = PHPCI_DIR . 'PHPCI/Plugin/';
|
||||
$pluginDir = PHPCI_DIR . 'Plugin' . DIRECTORY_SEPARATOR;
|
||||
$dir = new \DirectoryIterator($pluginDir);
|
||||
|
||||
$config = [
|
||||
|
@ -257,8 +257,8 @@ class Build extends BuildBase
|
|||
}
|
||||
|
||||
if (empty($this->currentBuildPath)) {
|
||||
$buildDirectory = $this->getId() . '_' . substr(md5(microtime(true)), 0, 5);
|
||||
$this->currentBuildPath = PHPCI_BUILD_ROOT_DIR . $buildDirectory . DIRECTORY_SEPARATOR;
|
||||
$buildDirectory = $this->getId() . '_' . substr(md5(microtime(true)), 0, 5);
|
||||
$this->currentBuildPath = PHPCI_BUILDS_DIR . $buildDirectory . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
return $this->currentBuildPath;
|
||||
|
|
|
@ -202,10 +202,10 @@ class PhpTalLint implements PHPCI\Plugin
|
|||
|
||||
list($suffixes, $tales) = $this->getFlags();
|
||||
|
||||
$lint = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
|
||||
$lint = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
|
||||
$lint .= 'vendor' . DIRECTORY_SEPARATOR . 'phptal' . DIRECTORY_SEPARATOR . 'phptal' . DIRECTORY_SEPARATOR;
|
||||
$lint .= 'tools' . DIRECTORY_SEPARATOR . 'phptal_lint.php';
|
||||
$cmd = '/usr/bin/env php ' . $lint . ' %s %s "%s"';
|
||||
$cmd = '/usr/bin/env php ' . $lint . ' %s %s "%s"';
|
||||
|
||||
$this->phpci->executeCommand($cmd, $suffixes, $tales, $this->phpci->buildPath . $path);
|
||||
|
||||
|
|
|
@ -79,10 +79,6 @@ class Shell implements \PHPCI\Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
if (!defined('ENABLE_SHELL_PLUGIN') || !ENABLE_SHELL_PLUGIN) {
|
||||
throw new \Exception(Lang::get('shell_not_enabled'));
|
||||
}
|
||||
|
||||
$success = true;
|
||||
|
||||
foreach ($this->commands as $command) {
|
||||
|
|
|
@ -313,7 +313,7 @@
|
|||
<script src="<?php print PHPCI_URL; ?>assets/plugins/chartjs/Chart.min.js" type="text/javascript"></script>
|
||||
<script src="<?php print PHPCI_URL; ?>assets/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
|
||||
<script src="<?php print PHPCI_URL; ?>assets/plugins/datepicker/bootstrap-datepicker.js" type="text/javascript"></script>
|
||||
<?php if (file_exists(PHPCI_DIR . 'assets/plugins/datepicker/locales/bootstrap-datepicker.' . Lang::getLanguage() . '.js')) :?>
|
||||
<?php if (file_exists(PHPCI_PUBLIC_DIR . 'assets/plugins/datepicker/locales/bootstrap-datepicker.' . Lang::getLanguage() . '.js')) :?>
|
||||
<script src="<?php print PHPCI_URL; ?>assets/plugins/datepicker/locales/bootstrap-datepicker.<?php print Lang::getLanguage(); ?>.js" type="text/javascript"></script>
|
||||
<?php endif; ?>
|
||||
<script src="<?php print PHPCI_URL; ?>assets/js/AdminLTE/app.min.js" type="text/javascript"></script>
|
||||
|
|
|
@ -1,573 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\b8;
|
||||
|
||||
use b8\Database\Generator,
|
||||
b8\Database\CodeGenerator,
|
||||
b8\Database,
|
||||
b8\Config;
|
||||
|
||||
class CodeGenerationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $_db;
|
||||
protected static $_base;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
Database::setDetails('b8_test_' . getenv('PHPCI_BUILD'), 'b8_test', 'b8_test');
|
||||
Database::setWriteServers(['localhost']);
|
||||
Database::setReadServers(['localhost']);
|
||||
|
||||
$config = new Config();
|
||||
Config::getInstance()->set('b8.app.namespace', 'Generation');
|
||||
|
||||
self::$_db = Database::getConnection('write');
|
||||
|
||||
self::$_db->query('DROP TABLE IF EXISTS tres');
|
||||
self::$_db->query('DROP TABLE IF EXISTS dos');
|
||||
self::$_db->query('DROP TABLE IF EXISTS uno');
|
||||
|
||||
self::$_base = dirname(__FILE__) . '/data/generation/';
|
||||
$gen = new Generator(self::$_db, 'Test', self::$_base . 'models/');
|
||||
$gen->generate();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$_db->query('DROP TABLE IF EXISTS tres');
|
||||
self::$_db->query('DROP TABLE IF EXISTS dos');
|
||||
self::$_db->query('DROP TABLE IF EXISTS uno');
|
||||
|
||||
unlink(self::$_base . 'Generation/Model/Base/UnoBase.php');
|
||||
unlink(self::$_base . 'Generation/Model/Base/DosBase.php');
|
||||
unlink(self::$_base . 'Generation/Model/Base/TresBase.php');
|
||||
unlink(self::$_base . 'Generation/Store/Base/UnoStoreBase.php');
|
||||
unlink(self::$_base . 'Generation/Store/Base/DosStoreBase.php');
|
||||
unlink(self::$_base . 'Generation/Store/Base/TresStoreBase.php');
|
||||
unlink(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php');
|
||||
unlink(self::$_base . 'Generation/Controller/Base/DosControllerBase.php');
|
||||
unlink(self::$_base . 'Generation/Controller/Base/TresControllerBase.php');
|
||||
unlink(self::$_base . 'Generation/Model/Uno.php');
|
||||
unlink(self::$_base . 'Generation/Model/Dos.php');
|
||||
unlink(self::$_base . 'Generation/Model/Tres.php');
|
||||
unlink(self::$_base . 'Generation/Store/UnoStore.php');
|
||||
unlink(self::$_base . 'Generation/Store/DosStore.php');
|
||||
unlink(self::$_base . 'Generation/Store/TresStore.php');
|
||||
unlink(self::$_base . 'Generation/Controller/UnoController.php');
|
||||
unlink(self::$_base . 'Generation/Controller/DosController.php');
|
||||
unlink(self::$_base . 'Generation/Controller/TresController.php');
|
||||
}
|
||||
|
||||
public function testGenerate()
|
||||
{
|
||||
error_reporting(E_ALL);
|
||||
$codeGenerator = new CodeGenerator(self::$_db, 'Generation', self::$_base . 'Generation/');
|
||||
$codeGenerator->generateModels();
|
||||
$codeGenerator->generateStores();
|
||||
$codeGenerator->generateControllers();
|
||||
|
||||
$this->assertFileExists(self::$_base . 'Generation/Model/Base/UnoBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Model/Base/DosBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Model/Base/TresBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Store/Base/UnoStoreBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Store/Base/DosStoreBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Store/Base/TresStoreBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Controller/Base/DosControllerBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Controller/Base/TresControllerBase.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Model/Uno.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Model/Dos.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Model/Tres.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Store/UnoStore.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Store/DosStore.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Store/TresStore.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Controller/UnoController.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Controller/DosController.php');
|
||||
$this->assertFileExists(self::$_base . 'Generation/Controller/TresController.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGenerate
|
||||
*/
|
||||
public function testGeneratedModels()
|
||||
{
|
||||
if (!defined('APPLICATION_PATH')) {
|
||||
define('APPLICATION_PATH', self::$_base);
|
||||
}
|
||||
|
||||
require_once(self::$_base . 'Generation/Model/Base/UnoBase.php');
|
||||
require_once(self::$_base . 'Generation/Model/Base/DosBase.php');
|
||||
require_once(self::$_base . 'Generation/Model/Base/TresBase.php');
|
||||
require_once(self::$_base . 'Generation/Model/Uno.php');
|
||||
require_once(self::$_base . 'Generation/Model/Dos.php');
|
||||
require_once(self::$_base . 'Generation/Model/Tres.php');
|
||||
require_once(self::$_base . 'ArrayPropertyModel.php');
|
||||
|
||||
$uno = new Generation\Model\Uno();
|
||||
$dos = new Generation\Model\Dos();
|
||||
$tres = new Generation\Model\Tres();
|
||||
|
||||
$this->assertTrue($uno instanceof b8\Model);
|
||||
$this->assertTrue($dos instanceof b8\Model);
|
||||
$this->assertTrue($tres instanceof b8\Model);
|
||||
|
||||
$this->assertTrue($uno instanceof Generation\Model\Base\UnoBase);
|
||||
$this->assertTrue($dos instanceof Generation\Model\Base\DosBase);
|
||||
$this->assertTrue($tres instanceof Generation\Model\Base\TresBase);
|
||||
|
||||
$this->assertTrue($uno->getTableName() == 'uno');
|
||||
$this->assertTrue($dos->getTableName() == 'dos');
|
||||
$this->assertTrue($tres->getTableName() == 'tres');
|
||||
|
||||
$uno->setId(1);
|
||||
$uno->setFieldDatetime(new DateTime());
|
||||
$this->assertTrue($uno->getFieldDatetime() instanceof DateTime);
|
||||
|
||||
$unoArray = $uno->toArray();
|
||||
$this->assertArrayHasKey('field_varchar', $unoArray);
|
||||
$this->assertTrue($unoArray['field_datetime'] instanceof DateTime);
|
||||
|
||||
Generation\Model\Uno::$sleepable = ['id', 'field_varchar'];
|
||||
$unoArray = $uno->toArray();
|
||||
$this->assertArrayHasKey('field_varchar', $unoArray);
|
||||
$this->assertFalse(array_key_exists('field_datetime', $unoArray));
|
||||
|
||||
$tres->setField($uno);
|
||||
$this->assertTrue($tres->getFieldInt() == 1);
|
||||
|
||||
$this->assertTrue(in_array('id', $uno->getModified()));
|
||||
$this->assertTrue(is_array($uno->getDataArray()));
|
||||
|
||||
$uno->setValues(['field_int' => 100, 'field_bob' => 100]);
|
||||
$this->assertFalse(in_array('field_bob', $uno->getModified()));
|
||||
$this->assertTrue($uno->getFieldInt() === 100);
|
||||
|
||||
$uno->setFieldInt(true);
|
||||
$this->assertTrue($uno->getFieldInt() === 1);
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->setFieldInt('invalid');
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
$uno->setFieldInt('500');
|
||||
$this->assertTrue($uno->getFieldInt() === 500);
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->setFieldFloat('invalid');
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
$uno->setFieldFloat('4.12');
|
||||
$this->assertTrue($uno->getFieldFloat() === 4.12);
|
||||
|
||||
|
||||
$uno->setFieldDatetime('2014-01-01');
|
||||
$this->assertTrue($uno->getFieldDatetime() instanceof DateTime);
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->setFieldDatetime(2012);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->setFieldInt(null);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->setValues(['field_int' => 'null']);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
$uno->setValues(['field_int' => 'true']);
|
||||
$this->assertTrue($uno->getFieldInt() === 1);
|
||||
|
||||
$uno->setValues(['field_int' => 'false']);
|
||||
$this->assertTrue($uno->getFieldInt() === 0);
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->setFieldVarchar(false);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->setFieldVarchar('Hi');
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertFalse($caught);
|
||||
|
||||
// Test toArray() with an array property:
|
||||
$aModel = new Generation\ArrayPropertyModel();
|
||||
$array = $aModel->toArray();
|
||||
|
||||
$this->assertArrayHasKey('array_property', $array);
|
||||
$this->assertTrue(is_array($array['array_property']));
|
||||
$this->assertTrue(is_array($array['array_property']['three']));
|
||||
$this->assertTrue($array['array_property']['one'] == 'two');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGeneratedModels
|
||||
*/
|
||||
public function testGeneratedStores()
|
||||
{
|
||||
require_once(self::$_base . 'Generation/Store/Base/UnoStoreBase.php');
|
||||
require_once(self::$_base . 'Generation/Store/Base/DosStoreBase.php');
|
||||
require_once(self::$_base . 'Generation/Store/Base/TresStoreBase.php');
|
||||
require_once(self::$_base . 'Generation/Store/UnoStore.php');
|
||||
require_once(self::$_base . 'Generation/Store/DosStore.php');
|
||||
require_once(self::$_base . 'Generation/Store/TresStore.php');
|
||||
|
||||
$uno = new Generation\Store\UnoStore();
|
||||
$dos = new Generation\Store\DosStore();
|
||||
$tres = new Generation\Store\TresStore();
|
||||
|
||||
$this->assertTrue($uno instanceof b8\Store);
|
||||
$this->assertTrue($dos instanceof b8\Store);
|
||||
$this->assertTrue($tres instanceof b8\Store);
|
||||
|
||||
$this->assertTrue($uno instanceof Generation\Store\Base\UnoStoreBase);
|
||||
$this->assertTrue($dos instanceof Generation\Store\Base\DosStoreBase);
|
||||
$this->assertTrue($tres instanceof Generation\Store\Base\TresStoreBase);
|
||||
|
||||
$tresModel = new Generation\Model\Tres();
|
||||
$tresModel->setFieldVarchar('Hi');
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$tres->save($tresModel);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->save($tresModel);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
|
||||
$unoModel = new Generation\Model\Uno();
|
||||
$unoModel->setFieldVarchar('Hi');
|
||||
|
||||
$unoModel = $uno->save($unoModel);
|
||||
$id = $unoModel->getId();
|
||||
$this->assertTrue(!empty($id));
|
||||
$this->assertTrue($unoModel->getFieldVarchar() == 'Hi');
|
||||
|
||||
$unoModel->setFieldVarchar('Ha');
|
||||
$unoModel = $uno->save($unoModel);
|
||||
$this->assertTrue($id == $unoModel->getId());
|
||||
$this->assertTrue($unoModel->getFieldVarchar() == 'Ha');
|
||||
|
||||
$unoModel = $uno->save($unoModel);
|
||||
$this->assertTrue($id == $unoModel->getId());
|
||||
$this->assertTrue($unoModel->getFieldVarchar() == 'Ha');
|
||||
|
||||
$unoModel2 = $uno->getByPrimaryKey($id);
|
||||
$this->assertTrue($unoModel2->getId() == $unoModel->getId());
|
||||
|
||||
$res = $uno->getWhere(['field_varchar' => 'Ha']);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => ['operator' => 'between', 'value' => [0, 100]]]);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => ['operator' => 'IN', 'value' => [1, 2, 3, 4]]]);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => ['operator' => '!=', 'value' => ['null', 100]]]);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => ['operator' => '==', 'value' => ['null']]]);
|
||||
$this->assertTrue($res['count'] == 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => ['operator' => '==', 'value' => 'null']]);
|
||||
$this->assertTrue($res['count'] == 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => ['operator' => '!=', 'value' => 'null']]);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['field_varchar' => ['operator' => 'like', 'value' => 'Ha']]);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['field_varchar' => ['operator' => '!=', 'value' => 'Hi']]);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['field_varchar' => ['Ha', 'Hi']]);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => 1], 1, 0, ['dos' => ['alias' => 'd', 'on' => 'd.id = uno.id']], ['id' => 'ASC']);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => 1], 1, 0, ['dos' => ['alias' => 'd', 'on' => 'd.id = uno.id']], 'rand');
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => 1], 1, 10);
|
||||
$this->assertTrue(count($res['items']) == 0 && $res['count'] == 1);
|
||||
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->getWhere(['invalid_column' => 1]);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
$res = $uno->getWhere(['id' => 1], 1, 0, [], 'rand', ['LEFT JOIN dos d ON d.id = uno.id']);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
|
||||
$res = $uno->getWhere(['id' => 1], 1, 0, [], 'rand', [], 'field_varchar');
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere([], 1, 0, [], 'rand', [], null, [['type' => 'AND', 'query' => 'id = 1', 'params' => []]]);
|
||||
$this->assertTrue($res['count'] != 0);
|
||||
|
||||
$res = $uno->getWhere(['id' => 2], 1, 0, [], 'rand', [], null,
|
||||
[['type' => 'AND', 'query' => 'id = ?', 'params' => ['id']]]);
|
||||
$this->assertTrue($res['count'] == 0);
|
||||
|
||||
$caught = false;
|
||||
|
||||
try {
|
||||
$uno->getWhere(['' => 1]);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
// ----
|
||||
// Tests for Model::toArray() with relationships:
|
||||
// ----
|
||||
$tresModel->setField($unoModel);
|
||||
$array = $tresModel->toArray();
|
||||
|
||||
$this->assertTrue(array_key_exists('Field', $array));
|
||||
$this->assertTrue(array_key_exists('id', $array['Field']));
|
||||
$this->assertTrue($array['Field']['id'] == $unoModel->getId());
|
||||
|
||||
// ----
|
||||
// Tests for Store::delete()
|
||||
// ----
|
||||
|
||||
$caught = false;
|
||||
try {
|
||||
$tres->delete($tresModel);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
$caught = false;
|
||||
try {
|
||||
$uno->delete($tresModel);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
|
||||
$this->assertTrue($uno->delete($unoModel));
|
||||
$this->assertTrue(is_null($uno->getByPrimaryKey(1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGeneratedStores
|
||||
*/
|
||||
public function testGeneratedControllers()
|
||||
{
|
||||
require_once(self::$_base . 'Generation/Controller/Base/UnoControllerBase.php');
|
||||
require_once(self::$_base . 'Generation/Controller/Base/DosControllerBase.php');
|
||||
require_once(self::$_base . 'Generation/Controller/Base/TresControllerBase.php');
|
||||
require_once(self::$_base . 'Generation/Controller/UnoController.php');
|
||||
require_once(self::$_base . 'Generation/Controller/DosController.php');
|
||||
require_once(self::$_base . 'Generation/Controller/TresController.php');
|
||||
require_once(self::$_base . 'TestUser.php');
|
||||
|
||||
$uno = new Generation\Controller\UnoController();
|
||||
$dos = new Generation\Controller\DosController();
|
||||
$tres = new Generation\Controller\TresController();
|
||||
|
||||
$uno->init();
|
||||
$dos->init();
|
||||
$tres->init();
|
||||
|
||||
$this->assertTrue($uno instanceof b8\Controller);
|
||||
$this->assertTrue($dos instanceof b8\Controller);
|
||||
$this->assertTrue($tres instanceof b8\Controller);
|
||||
|
||||
$this->assertTrue($uno instanceof Generation\Controller\Base\UnoControllerBase);
|
||||
$this->assertTrue($dos instanceof Generation\Controller\Base\DosControllerBase);
|
||||
$this->assertTrue($tres instanceof Generation\Controller\Base\TresControllerBase);
|
||||
|
||||
$config = new Config();
|
||||
Config::getInstance()->set('hello', 'world');
|
||||
|
||||
$this->assertTrue($uno->getParam('hello', 'dave') == 'world');
|
||||
|
||||
$uno->setParam('hello', 'dave');
|
||||
$this->assertTrue($uno->getParam('hello', 'world') == 'dave');
|
||||
$this->assertTrue(array_key_exists('hello', $uno->getParams()));
|
||||
|
||||
$uno->unsetParam('hello');
|
||||
$this->assertFalse(array_key_exists('hello', $uno->getParams()));
|
||||
|
||||
$testUser = new \TestUser();
|
||||
$uno->setActiveUser($testUser);
|
||||
$dos->setActiveUser($uno->getActiveUser());
|
||||
$tres->setActiveUser($uno->getActiveUser());
|
||||
|
||||
$unoModel = new Generation\Model\Uno();
|
||||
$unoStore = \b8\Store\Factory::getStore('Uno');
|
||||
$unoModel->setFieldVarchar('Hi');
|
||||
|
||||
$unoStore->save($unoModel);
|
||||
$list = $uno->index();
|
||||
|
||||
$this->assertTrue(is_array($list));
|
||||
$this->assertTrue(is_array($list['items']));
|
||||
$this->assertTrue(count($list['items']) > 0);
|
||||
|
||||
$caught = false;
|
||||
try {
|
||||
$dos->index();
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
|
||||
$first = array_shift($list['items']);
|
||||
|
||||
$uno1 = $uno->get($first['id']);
|
||||
$this->assertTrue(is_array($uno1));
|
||||
$this->assertTrue(isset($uno1['uno']));
|
||||
$this->assertTrue($uno1['uno']['id'] == $first['id']);
|
||||
|
||||
$caught = false;
|
||||
try {
|
||||
$dos->get(1);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
|
||||
$uno->setParam('field_varchar', 'Un');
|
||||
$uno1 = $uno->put($first['id']);
|
||||
$this->assertTrue($uno1['uno']['id'] == $first['id']);
|
||||
|
||||
$caught = false;
|
||||
try {
|
||||
$dos->put(1);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
$this->assertTrue(is_null($uno->put(10000)));
|
||||
|
||||
|
||||
$uno->setParam('field_text', 'Hello');
|
||||
$res = $uno->post();
|
||||
$this->assertTrue($res['uno']['field_varchar'] == 'Un');
|
||||
$this->assertTrue(!empty($res['uno']['id']));
|
||||
|
||||
$caught = false;
|
||||
try {
|
||||
$dos->post();
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
$del = $uno->delete($res['uno']['id']);
|
||||
$this->assertTrue($del['deleted']);
|
||||
|
||||
$del = $uno->delete($res['uno']['id']);
|
||||
$this->assertFalse($del['deleted']);
|
||||
|
||||
$del = $tres->delete(100);
|
||||
$this->assertFalse($del['deleted']);
|
||||
|
||||
$caught = false;
|
||||
try {
|
||||
$dos->delete(1000);
|
||||
} catch (Exception $ex) {
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($caught);
|
||||
|
||||
//----
|
||||
// Tests for _parseWhere()
|
||||
//----
|
||||
$uno->setParam('where', ['id' => [1000]]);
|
||||
$uno->setParam('neq', 'id');
|
||||
$list = $uno->index();
|
||||
|
||||
$this->assertTrue(is_array($list));
|
||||
$this->assertTrue(count($list['items']) != 0);
|
||||
|
||||
$uno->setParam('where', ['id' => 1000]);
|
||||
$uno->setParam('fuzzy', 'id');
|
||||
$list = $uno->index();
|
||||
|
||||
$this->assertTrue(is_array($list));
|
||||
$this->assertTrue(count($list['items']) == 0);
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ class DatabaseGenerationTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCreateDatabase()
|
||||
{
|
||||
$gen = new Generator($this->_db, 'Test', dirname(__FILE__) . '/data/generation/models/');
|
||||
$gen = new Generator($this->_db, 'Test', __DIR__ . '/data/generation/models/');
|
||||
$gen->generate();
|
||||
|
||||
$map = new Map($this->_db);
|
||||
|
@ -49,10 +49,10 @@ class DatabaseGenerationTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testUpdateDatabase()
|
||||
{
|
||||
$gen = new Generator($this->_db, 'Test', dirname(__FILE__) . '/data/generation/models/');
|
||||
$gen = new Generator($this->_db, 'Test', __DIR__ . '/data/generation/models/');
|
||||
$gen->generate();
|
||||
|
||||
$gen = new Generator($this->_db, 'Update', dirname(__FILE__) . '/data/generation/update_models/');
|
||||
$gen = new Generator($this->_db, 'Update', __DIR__ . '/data/generation/update_models/');
|
||||
$gen->generate();
|
||||
|
||||
$map = new Map($this->_db);
|
||||
|
|
|
@ -16,7 +16,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($f->getMethod() == 'POST');
|
||||
|
||||
$config = new Config();
|
||||
Config::getInstance()->set('ViewPath', dirname(__FILE__) . '/data/view/');
|
||||
Config::getInstance()->set('ViewPath', __DIR__ . '/data/view/');
|
||||
|
||||
$this->assertTrue($f->render('form') == '/POST');
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ class ViewTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function testSimpleView()
|
||||
{
|
||||
$view = new View('simple', dirname(__FILE__) . '/data/view/');
|
||||
$view = new View('simple', __DIR__ . '/data/view/');
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class ViewTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testInvalidView()
|
||||
{
|
||||
new View('dogs', dirname(__FILE__) . '/data/view/');
|
||||
new View('dogs', __DIR__ . '/data/view/');
|
||||
}
|
||||
|
||||
public function testViewVars()
|
||||
{
|
||||
$view = new View('vars', dirname(__FILE__) . '/data/view/');
|
||||
$view = new View('vars', __DIR__ . '/data/view/');
|
||||
$view->who = 'World';
|
||||
|
||||
$this->assertTrue(isset($view->who));
|
||||
|
@ -32,7 +32,7 @@ class ViewTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testFormatViewHelper()
|
||||
{
|
||||
$view = new View('format', dirname(__FILE__) . '/data/view/');
|
||||
$view = new View('format', __DIR__ . '/data/view/');
|
||||
$view->number = 1000000.25;
|
||||
$view->symbol = true;
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Generation;
|
||||
use Generation\Model\Uno;
|
||||
|
||||
class ArrayPropertyModel extends Uno
|
||||
{
|
||||
public function __construct($initialData = [])
|
||||
{
|
||||
$this->_getters['array_property'] = 'getArrayProperty';
|
||||
self::$sleepable[] = 'array_property';
|
||||
}
|
||||
|
||||
public function getArrayProperty()
|
||||
{
|
||||
return ['one' => 'two', 'three' => ['four' => 'five']];
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once(B8_PATH . 'Type/RestUser.php');
|
||||
|
||||
use b8\Type\RestUser;
|
||||
|
||||
class TestUser implements RestUser
|
||||
{
|
||||
public function checkPermission($permission, $resource)
|
||||
{
|
||||
return $resource == 'unos' || $resource == 'tress' ? true : false;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Model\Base;
|
||||
|
||||
use b8\Model;
|
||||
|
||||
class BadModel extends Model
|
||||
{
|
||||
protected $_tableName = 'bad_table';
|
||||
|
||||
public $columns = [
|
||||
'id' => ['type' => 'catfish'],
|
||||
];
|
||||
|
||||
public $indexes = [];
|
||||
public $foreignKeys = [];
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Model\Base;
|
||||
|
||||
use b8\Model;
|
||||
|
||||
class Dos extends Model
|
||||
{
|
||||
protected $_tableName = 'dos';
|
||||
|
||||
public $columns = [
|
||||
'id' => ['type' => 'int', 'primary_key' => true, 'auto_increment' => false],
|
||||
'field_varchar' => ['type' => 'varchar', 'length' => '250', 'default' => 'Hello World'],
|
||||
'field_datetime' => ['type' => 'datetime'],
|
||||
'field_int' => ['type' => 'int'],
|
||||
];
|
||||
|
||||
public $indexes = [
|
||||
'PRIMARY' => ['unique' => true, 'columns' => 'id'],
|
||||
'idx_test_1' => ['unique' => true, 'columns' => 'field_int'],
|
||||
'idx_test_2' => ['columns' => 'field_datetime'],
|
||||
];
|
||||
public $foreignKeys = [];
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue