XOOPS  2.6.0
Dtype.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
12 namespace Xoops\Core\Kernel;
13 
15 
27 class Dtype
28 {
38  public static function cleanVar(XoopsObject $obj, $key, $quote = true)
39  {
40  return Dtype::loadDtype(Dtype::getDtypeName($obj, $key))->cleanVar($obj, $key, $quote);
41  }
42 
52  public static function getVar(XoopsObject $obj, $key, $format)
53  {
54  return Dtype::loadDtype(Dtype::getDtypeName($obj, $key))
55  ->getVar($obj, $key, $format);
56  }
57 
65  private static function loadDtype($name)
66  {
67  static $dtypes;
68 
69  $name = ucfirst(strtolower($name));
70  $dtype = null;
71  if (!isset($dtypes[$name])) {
72  $className = 'Xoops\Core\Kernel\Dtype\Dtype' . ucfirst($name);
73  @$dtype = new $className();
74  if (!$dtype instanceof DtypeAbstract) {
75  trigger_error("Dtype '{$name}' not found", E_USER_WARNING);
76  $name = 'other';
78  }
79  $dtype->init();
80  $dtypes[$name] = $dtype;
81  }
82 
83  return $dtypes[$name];
84  }
85 
94  private static function getDtypeName(XoopsObject $obj, $key)
95  {
96  $name = $obj->vars[$key]['data_type'];
97  $lNames = Dtype::getLegacyNames();
98  if (isset($lNames[$name])) {
99  return $lNames[$name];
100  }
101  return $name;
102  }
103 
109  private static function getLegacyNames()
110  {
111  return array(
112  1 => 'textbox', 2 => 'textarea', 3 => 'int', 4 => 'url', 5 => 'email', 6 => 'array', 7 => 'other',
113  8 => 'source', 9 => 'stime', 10 => 'mtime', 11 => 'ltime', 13 => 'float', 14 => 'decimal', 15 => 'enum'
114  );
115  }
116 }
static loadDtype($name)
Definition: Dtype.php:65
static getVar(XoopsObject $obj, $key, $format)
Definition: Dtype.php:52
static cleanVar(XoopsObject $obj, $key, $quote=true)
Definition: Dtype.php:38
static getLegacyNames()
Definition: Dtype.php:109
static getDtypeName(XoopsObject $obj, $key)
Definition: Dtype.php:94