/** * initialisation and auto configuration */ public static function _init() { $crypter = new Crypt_AES(); $hasher = new Crypt_Hash('sha256'); // load the config \Config::load('crypt', true); static::$defaults = \Config::get('crypt', array()); // generate random crypto keys if we don't have them or they are incorrect length $update = false; foreach (array('crypto_key', 'crypto_iv', 'crypto_hmac') as $key) { if (empty(static::$defaults[$key]) or strlen(static::$defaults[$key]) % 4 != 0) { $crypto = ''; for ($i = 0; $i < 8; $i++) { $crypto .= static::safe_b64encode(pack('n', mt_rand(0, 0xffff))); } static::$defaults[$key] = $crypto; $update = true; } } // update the config if needed if ($update === true) { try { \Config::save('crypt', static::$defaults); } catch (\FileAccessException $e) { // failed to write the config file, inform the user echo \View::forge('errors/crypt_keys', array('keys' => static::$defaults)); die; } } }
/** * @param \Tacone\Bees\Field\Field $object * @param $storage * @param string $path * * @return static */ public static function make($object, &$storage, $path, $default = null) { $instance = new static($object, $storage, $path); if (func_num_args() > 3) { $instance->defaults($default); } return $instance; }
/** * 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; }
/** * Returns the default encoding flags * @return int */ public static function defaults() { if (static::$defaults === null) { $defaults = 0; if (defined('JSON_UNESCAPED_SLASHES')) { $defaults |= constant('JSON_UNESCAPED_SLASHES'); } if (defined('JSON_UNESCAPED_UNICODE')) { $defaults |= constant('JSON_UNESCAPED_UNICODE'); } static::$defaults = $defaults; } return static::$defaults; }
protected static function setRoute($route) { $destination = explode('::', $route->destination); $info = ['controller' => $destination[0], 'method' => $destination[1], 'params' => $route->params, 'defaults' => $route->defaults, 'extension' => isset($route->params['extension']) ? $route->params['extension'] : 'html']; // Remove the first dot from the extension if ($info['extension'][0] == '.') { $info['extension'] = substr($info['extension'], 1); } // Allow static use current route info. static::$controller = $info['controller']; static::$method = $info['method']; static::$params = $info['params']; static::$defaults = $info['defaults']; static::$extension = $info['extension']; return static::$currentRoute = $info; }