]> git.nbdom.net Git - nb.git/commitdiff
objects fix
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 16:02:30 +0000 (18:02 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 16:02:30 +0000 (18:02 +0200)
lib/php/db.php
lib/php/db/page.php
lib/php/out.php
lib/php/page.php

index cb2de02a5220eb113e622c5518585dd4712eafc4..c875dc23dd341d1c28ebf6d52d8a0b1a24c6b1af 100644 (file)
@@ -27,10 +27,13 @@ class Db extends nb {
   public $password = null;
 
   # Database infos
-  public $title;
+  public $id;
   public $name;
+  public $title;
   public $type;
   public $tables = [];
+  public $types = [];
+  public $conf = [];
   public $row_parse; # Function to call in rows()
 
   # Web
@@ -40,6 +43,9 @@ class Db extends nb {
   public $formats = [ 'table','div','csv','xml','json','yaml','sh' ];
   public $limits = ['10','20','50','100','500','1000'];
 
+  # Classes
+  public $out;
+
   function __construct($opt = '') {
 
     # Args defaults
@@ -65,10 +71,10 @@ class Db extends nb {
     }
 
     # Args into this
-    foreach ($opt as $k=>$v) $this->$k = $v;
-    #parent::__construct($opt);
+    #foreach ($opt as $k=>$v) $this->$k = $v;
+    parent::__construct($opt);
     #if(!is_scalar($opt['type'])) debug($opt['type']);
-    if (self::$encoding) out::$charset=self::$encoding;
+    if (empty($this->out)) $this->out = new Out(['charset'=>self::$encoding]);
 
     # id
     if (!empty($this->conf)) {
@@ -77,8 +83,7 @@ class Db extends nb {
     }
 
     # Formats
-    #$this->formats += array_keys(out::$types);
-    foreach(out::$types as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t;
+    foreach($this->out->types() as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t;
 
     # Pdo
     $this->connect_init();
@@ -416,7 +421,7 @@ class Db extends nb {
   }
 
   public function out($rows,$head=[]) {
-    out::rows($this->p('format',out::php_cli() ? 'csv' : 'table'),$rows,$head);
+    $this->out->rows($this->p('format',$this->out->php_cli() ? 'csv' : 'table'),$rows,$head);
     return true;
   }
 
@@ -590,7 +595,7 @@ class Db extends nb {
 
     # Construct assoc array
     $db = array_merge($conf[$id],array(
-      'dbs'  => array_keys($conf),
+      #'dbs'  => array_keys($conf),
       'conf' => $conf,
       'id'   => $id,
     ));
@@ -911,27 +916,26 @@ class Db extends nb {
       'o' => 'format',
     ]);
 
-  if ($action=self::p('action')) {
-    foreach ([
+    if ($action=self::p('action')) {
+      foreach ([
 
-      'ls' => 'db.ls',
-      'tables' => 'db.tables',
+        'ls' => 'db.ls',
+        'tables' => 'db.tables',
 
-      'fields' => 'table.fields',
-      'rows' => 'table.rows',
-      'insert' => 'table.insert',
-      'replace' => 'table.replace',
-      'update' => 'table.update',
-      'delete' => 'table.delete',
+        'fields' => 'table.fields',
+        'rows' => 'table.rows',
+        'insert' => 'table.insert',
+        'replace' => 'table.replace',
+        'update' => 'table.update',
+        'delete' => 'table.delete',
 
-    ] as $src => $dest) {
-      if ($action === $src) {
-        $action = $dest;
+      ] as $src => $dest) {
+        if ($action === $src) {
+          $action = $dest;
+        }
+        self::pset('action',$action);
       }
-      self::pset('action',$action);
     }
-  }
-    #if($format = out::client_type()) self::pset('format',$format);
 
     # Param - Extract dbname from table
     if (false and preg_match('/^(\w+)\.(.*?)$/',self::p('table'),$m)) {
index 5ecfa15e3c718231b91e00bb2f48c517e4717c7b..9421f5f07942f4ffbac15c4654af0d6498b2e2f6 100644 (file)
@@ -1,10 +1,9 @@
 <?php
 require_once(dirname(__FILE__).'/../config.php');
 require_once(dirname(__FILE__).'/../page.php');
-#bye(Page::p('web'));
 $Page = new Page([
   #'title' => 'Test',
-  'content_type' => (Page::php_cli() and !Page::p('web') ? 'text/plain' : 'text/html'),
+  'content_type' => ((Page::php_cli() and !Page::p('web') )? 'text/plain' : 'text/html'),
   'call' => array(
     'begin',
     ['out', "Hello World !!!\n"],
index 2c9d8fa626f33441de5696ff8181daf33fe3280d..37c63ce8a3aa0f9374ac5eadefbfa2b51c73416e 100644 (file)
@@ -122,10 +122,26 @@ Class Out extends Nb {
     self::$type = self::client_type();
   }
 
-  public function __construct($type,&$data,$head=array()) {
-    if (!empty($type) and !empty($data)) return $this->rows($type,$data,$head);
+  public function __construct($opt=[],&$data=[],$head=[]) {
+    // Statics
+    foreach ([
+      'charset',
+      'type',
+    ] as $k) {
+      if (isset($opt[$k])) self::${$k} = $opt[$k];
+      unset($opt[$k]);
+    }
+
+    if (isset($opt['type'])) self::$type = $opt['type'];
+    unset($opt['type']);
+
+    if (!empty(self::$type) and !empty($data)) return self::rows(self::$type,$data,$head);
+    return parent::__construct($opt);
   }
 
+  public static function charset($set=null) { if (!empty($set)) self::$charset = $set; return self::$charset; }
+  public static function types($set=null) { if (!empty($set)) self::$types = $set; return self::$types; }
+
   public static function scalar($v) {
     if ($v === null) return '';
     if (is_scalar($v)) return $v;
index f2038b666f2b5575c05b1a1f533177cc5f32c4a9..fe470cf4d15cb171c2335f8263b08f46f2818af6 100644 (file)
@@ -53,9 +53,19 @@ class Page extends nb {
 
     // Content-type
     if (isset($opt['content_type'])) $this->content_type($opt['content_type']);
-    elseif($this->php_cli()) $this->content_type('text/html');
+    #elseif($this->php_cli()) $this->content_type('text/html');
     unset($opt['content_type']);
 
+    // Statics
+    foreach ([
+      'charset',
+      'lang',
+      'html5',
+    ] as $k) {
+      if (isset($opt[$k])) self::${$k} = $opt[$k];
+      unset($opt[$k]);
+    }
+
     // Opt
     parent::__construct($opt);