Skip to content

Commit

Permalink
bin/shpala rewriten
Browse files Browse the repository at this point in the history
  • Loading branch information
127 committed Dec 19, 2019
1 parent 917dfa1 commit 47a05c2
Show file tree
Hide file tree
Showing 20 changed files with 1,203 additions and 1,196 deletions.
7 changes: 7 additions & 0 deletions bin/shpala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ $db = new Database(false, false);
$db->set_connect($cnf->config['database']);
$connect = $db->get_connect();
$dbname = $cnf->config['database']['database'];

//Minimal setup to use BaseRecord
BaseRecord::$_db_di = $connect;
if(isset($cnf->config['database']['tables_prefix'])) {
BaseRecord::$_prefix_di = $cnf->config['database']['tables_prefix'];
}

require_once $task;
exit(0);
?>
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$GLOBALS['APP_DIR'] = realpath(__DIR__);

if($GLOBALS['APP_ENV'] != 'production'){
$_sig = '/\.(?:png|jpg|jpeg|gif|css|html|htm|ico|js|webmanifest|txt)$/';
$_sig = '/\.(?:png|jpg|jpeg|gif|css|html|htm|ico|js|webmanifest|txt|json)$/';
if(php_sapi_name() == 'cli-server' && preg_match($_sig, $_SERVER['REQUEST_URI'])) {
return false;
}
Expand Down
60 changes: 30 additions & 30 deletions lib/shpala/base_cache.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?php
abstract class BaseCache {
protected static $adapters = null;
private static $_defaults = [
'adapter'=>'files',
'options'=>[
'live'=>3600,
'path'=>'/tmp/cache/'
]
];
private static $_convention = 'Storage';
public static function factory($config=null){
static::$_defaults['options']['path'] = $GLOBALS['APP_DIR'].static::$_defaults['options']['path'];
$options = static::$_defaults['options'];
$adapter_name = static::$_defaults['adapter'];
if(is_string($config)) {
$adapter_name = $config;
}
if(is_array($config)){
$adapter_name = isset($config['adapter']) ? $config['adapter'] : $adapter_name;
$options = isset($config['options']) ? array_merge($options, $config['options']) : $options;
}
if ($adapter_name=='') {
die('Missing adapter');
}
if (static::$adapters === null) {
$_n = static::$_convention.ucfirst($adapter_name);
static::$adapters = new $_n($options);
}
return static::$adapters;
}
protected static $adapters = null;
private static $_defaults = [
'adapter'=>'files',
'options'=>[
'live'=>3600,
'path'=>'/tmp/cache/'
]
];
private static $_convention = 'Storage';
public static function factory($config=null){
static::$_defaults['options']['path'] = $GLOBALS['APP_DIR'].static::$_defaults['options']['path'];
$options = static::$_defaults['options'];
$adapter_name = static::$_defaults['adapter'];
if(is_string($config)) {
$adapter_name = $config;
}
if(is_array($config)){
$adapter_name = isset($config['adapter']) ? $config['adapter'] : $adapter_name;
$options = isset($config['options']) ? array_merge($options, $config['options']) : $options;
}
if ($adapter_name=='') {
die('Missing adapter');
}
if (static::$adapters === null) {
$_n = static::$_convention.ucfirst($adapter_name);
static::$adapters = new $_n($options);
}
return static::$adapters;
}
}

?>
98 changes: 49 additions & 49 deletions lib/shpala/base_controller.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
<?php
class BaseController {
public $db;
public $view;
public $params;
public $resource;
public $i18n;
private $_render_layout = true;
private $_render_action = true;
public function __construct(Resource &$resource) {
$this->resource = $resource;
public $db;
public $view;
public $params;
public $resource;
public $i18n;
private $_render_layout = true;
private $_render_action = true;
public function __construct(Resource &$resource) {
$this->resource = $resource;

//aliases
$this->db = $resource->connect;
$this->params = $resource->router->params;
$this->view = $resource->view;
if($resource->i18n){
$this->i18n = $resource->i18n->strings;
}
if($resource->helpers){
$this->helpers = $resource->helpers;
}
//aliases
$this->db = $resource->connect;
$this->params = $resource->router->params;
$this->view = $resource->view;
if($resource->i18n){
$this->i18n = $resource->i18n->strings;
}
if($resource->helpers){
$this->helpers = $resource->helpers;
}

$this->call_init();
return $this;
}

protected function call_init(){
if(method_exists($this, 'init')){
$this->init();
}
$this->call_init();
return $this;
}

protected function call_init(){
if(method_exists($this, 'init')){
$this->init();
}

protected function set_db(&$db){
$this->db = $db;
}

public function set_render_layout($flag=true){
$this->_render_layout = $flag;
}

public function get_render_layout(){
return $this->_render_layout;
}

public function set_render_action($flag=true){
$this->_render_action = $flag;
}

public function get_render_action(){
return $this->_render_action;
}
}

protected function set_db(&$db){
$this->db = $db;
}

public function set_render_layout($flag=true){
$this->_render_layout = $flag;
}

public function get_render_layout(){
return $this->_render_layout;
}

public function set_render_action($flag=true){
$this->_render_action = $flag;
}

public function get_render_action(){
return $this->_render_action;
}
}
?>
4 changes: 1 addition & 3 deletions lib/shpala/base_helpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<?php
class BaseHelpers {

}
class BaseHelpers {}
?>
23 changes: 12 additions & 11 deletions lib/shpala/base_job.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
class BaseJob {
public static $_db_di=null;
protected $_db;

public function __construct() {
if(self::$_db_di!=null)
$this->_db = self::$_db_di;
if(method_exists($this, 'init')){
$this->init();
}
return $this;
}
public static $_db_di=null;
protected $_db;

public function __construct() {
if(self::$_db_di!=null){
$this->_db = self::$_db_di;
}
if(method_exists($this, 'init')){
$this->init();
}
return $this;
}
}

?>
Loading

0 comments on commit 47a05c2

Please sign in to comment.