/** * Initializer * * @param array $setting Configure array * * @return bool Return true when initialized, false when fail. * Remember re-init cause fail too */ public static function init(array $setting = array()) { if (!static::$inited) { static::$cores = Framework::getAllCores(); static::$defaults = array('Setting' => array('CookieKey' => isset($setting['CookieKey']) ? $setting['CookieKey'] : '!', 'Expire' => isset($setting['Expire']) ? (int) $setting['Expire'] : 3600, 'Salt' => isset($setting['Salt']) ? $setting['Salt'] : '', 'RandomKeyLen' => isset($setting['RandomKeyLen']) ? (int) $setting['RandomKeyLen'] : 16)); static::$inited = true; register_shutdown_function(function () { return static::update(); }); return true; } return false; }
public static function Init() { if (!static::$inited) { //вместо ворнингов в лог мускул будет кидать эксепшены mysqli_report(MYSQLI_REPORT_STRICT); try { static::$connect = new mysqli(static::$settings['host'], static::$settings['login'], static::$settings['password'], static::$settings['dbname'], static::$settings['port'], static::$settings['socket']); static::$connect->query("SET NAMES '" . (static::$settings['codepage'] ? static::$settings['codepage'] : 'utf8') . "'"); static::$inited = TRUE; } catch (Exception $e) { echo "\nТехническое сообщение:\n Ошибка №" . $e->getCode() . ". " . $e->getMessage(); //1045 - не вошел в бд. exit; } } return true; }
/** * Preparing the class * * @return bool Return true when success, false on fail (For exp when class already inited) */ private static function selfInit() { if (static::$inited) { return true; } else { static::$inited = true; } static::newTag('%', function ($value, $selected, $param, $pool) { $poolRef = null; $result = $value; if (is_null($value)) { $locator = explode('.', trim($selected), 2); if (isset($pool['%'][$locator[0]])) { if (!isset($locator[1])) { $result = $pool['%'][$locator[0]]; } elseif (isset($pool['%'][$locator[0]]['.' . $locator[1]])) { $result = $pool['%'][$locator[0]]['.' . $locator[1]]; } } } if (is_string($result) || is_numeric($result)) { foreach (explode(' ', $param) as $currentParam) { switch (trim($currentParam)) { case 'Lower': $result = strtolower($result); break; case 'Upper': $result = strtoupper($result); break; case 'Uppercase': $result = ucfirst($result); break; case 'Lowercase': $result = lcfirst($result); break; case 'Number': $result = number_format((int) $result, 2, '.', ','); break; case 'Html': $result = htmlspecialchars($result); break; case 'URL': $result = urlencode($result); break; case 'Slashes': $result = addslashes($result); break; case 'Br': $result = nl2br($result); break; default: if (isset($pool['!'][$param])) { $result = sprintf($pool['!'][$param], $result); } break; } } return $result; } return false; }, function ($value) { $flated = array(); $lastKey = ''; if (is_array($value)) { $recursive_array = function ($array, $tag) use(&$recursive_array, &$flated) { foreach ($array as $key => $val) { $key = '.' . $key; if (is_array($val)) { $recursive_array($val, $key); } else { $flated[$tag . $key] = $val; } } }; $recursive_array($value, ''); return $flated; } else { return $value; } return false; }); static::newTag('!', function ($value, $selected, $param) { if ($value) { return $value; } return $param; }, function ($value) { return $value; }); static::newTag('T', function ($value, $selected, $param, $pool) { $result = ''; $time = 0; if (isset($pool['T'][$selected])) { $time = intval($pool['T'][$selected]); } else { $locator = explode('.', trim($selected), 2); if (isset($pool['%'][$locator[0]])) { if (!isset($locator[1])) { $time = intval($pool['%'][$locator[0]]); } elseif (isset($pool['%'][$locator[0]]['.' . $locator[1]])) { $time = intval($pool['%'][$locator[0]]['.' . $locator[1]]); } } } switch (trim($param)) { case 'RFC2822': return date(DATE_RFC2822, $time); break; case 'ATOM': return date(DATE_ATOM, $time); break; default: return date('F j, Y, g:i a T', $time); break; } }, function ($value) { return $value; }); return true; }
/** * Constructor of Auther * * @param Socket $socket Socket object * @param array $auths Auth data */ public function __construct(Socket $socket, array &$auths) { if (!static::$inited) { static::init(); static::$inited = true; } $this->socket = $socket; $this->auths = $auths; }
/** * reset * * @param bool $all * * @return void */ public static function reset($all = false) { $class = get_called_class(); if ($all || $class == __CLASS__) { static::$inited = array(); } else { static::$inited[$class] = array(); } }