/** * validate * * Run validation process * * @return null */ public function validate() { parent::validate(); // compare protection code if (property_exists($this->_data, 'protection_code')) { $protectionCode = \Storage::read('protection-code-register'); \Storage::remove('protection-code-register'); if ($this->_data->protection_code !== $protectionCode) { $this->addMessage('protection_code', \View::$language->register_form_protection_code_invalid); } } // compare password confirmation if (property_exists($this->_data, 'password') && property_exists($this->_data, 'confirm_password') && $this->_data->password !== $this->_data->confirm_password) { $this->addMessage('confirm_password', \View::$language->register_form_password_confirm_mismatch); } // check for existence if ($this->isValid()) { $checkedFields = array('email', 'login'); $UserModel = \App::getInstance('common\\UserModel'); foreach ($checkedFields as $fName) { if ($UserModel->isExists($fName, $this->_data->{$fName})) { $mKey = 'register_form_' . $fName . '_is_exists'; $this->addMessage($fName, \View::$language->{$mKey}); } } } }
public function testWhatYouWriteIsReadBack() { $data = array('this' => 'is', 'a' => 'sample'); Storage::write($data); $read = Storage::read(); $this->assertEquals($read, $data); // Actual, Expected <-- alphabetic order }
/** * load gitlab user data from file. * * @return type user list(json encoding) */ public function loadGitLabUser() { if (\Storage::has($this->userList)) { $users = \Storage::read($this->userList); return json_decode($users, true); } // if file not exist, create empty list. return []; }
/** *html静态文件缓存 * @access protected * @param string $filename 生成的静态文件名称 * @param string $filepath 生成的静态文件路径 * @param string $expire 静态文件缓存时间 * @return void */ protected function html_before($filename = '',$filepath = '',$expire = 15){ $suffix = C('HTML_FILE_SUFFIX')?C('HTML_FILE_SUFFIX'):'shtml'; if($filename === '' && $filepath === ''){ $filename = APP_PATH.'/static/'.__ACTION__.'.'.$suffix; }else{ $filename = $filename?$filename.'.'.$suffix:md5(__ACTION__).'.'.$suffix; $filepath = $filepath?APP_PATH.'/'.$filepath:APP_PATH.'/static'; $filename = $filepath.'/'.$filename; } if(Storage::has($filename)){ if(time() - Storage::get($filename,'mtime') < $expire){ exit(Storage::read($filename)); } } $this->filename = $filename; }
/** * validate * * Run validation process * * @return null */ public function validate() { parent::validate(); // compare protection code if (property_exists($this->_data, 'protection_code')) { $protectionCode = \Storage::read('protection-code-sign-in'); \Storage::remove('protection-code-sign-in'); if ($this->_data->protection_code !== $protectionCode) { $this->addMessage('protection_code', \View::$language->sign_in_form_protection_code_invalid); } } // remove sign in counter data if ($this->isValid()) { \Storage::remove('sign-in-tries'); } }
public function read() { //cached file exists? $cache = $this->options['cacheDir'] . md5($this->options['cacheId']); if (!file_exists($cache)) { return null; } $now = time(); $timeout = $this->options['timeout']; //read timestamp $data = json_decode(Storage::read($cache), true); $timestamp = $data['timestamp']; if ($now - $timestamp <= $timeout) { return $data['data']; } else { //cache expired Storage::delete($cache); return null; } }
<?php require_once CONFIG::get('ABSPATH') . '/src/models/person.php'; require_once CONFIG::get('ABSPATH') . '/src/models/storage.php'; $display['page_title'] = 'People'; list($display['page_error'], $errors) = post_errors(); if ($display['page_error']) { d_($display['page_error']); } if ($errors) { d_($errors); } $stored_people = Storage::read() ?? []; if (count($stored_people)) { $display['stored_people'] = array_map(function ($item) { return htmlspecialchars("{$item}"); }, $stored_people); $display['people'] = array_map(function ($item) { return $item->toHash(); }, $stored_people); } else { $display['stored_people'] = []; $display['people'][] = array('firstname' => 'Jeff', 'surname' => 'Stelling'); $display['people'][] = array('firstname' => 'Chris', 'surname' => 'Kamara'); $display['people'][] = array('firstname' => 'Alex', 'surname' => 'Hammond'); $display['people'][] = array('firstname' => 'Jim', 'surname' => 'White'); $display['people'][] = array('firstname' => 'Natalie', 'surname' => 'Sawyer'); } $display['button_OK'] = merge_params($url_string, array('action' => 'save')); render(CONFIG::get('ABSPATH') . '/src/views/templates/people/list.php', CONFIG::get('ABSPATH') . '/src/views/layouts/flat.php');