function run() { foreach ($this->_testCases as $target) { $pos = strrpos(basename($target), '.'); $class = ucfirst(substr(basename($target), 0, $pos)) . 'Test'; require_once $target; $start = date('Y-m-d G-i-s'); $TestCase = new $class(); $TestCase->init(); $result = $TestCase->run(); $end = date('Y-m-d G-i-s'); $name = get_class($TestCase); $count = 0; $error_count = 0; $msg = ""; foreach ($result as $k => $r) { $count++; if (XUtil::arrayGetOr($r, 'status', 'NG') != "OK") { $error_count++; $msg = $k . ":" . XUtil::arrayGetOr($r, 'status', 'NG') . "\n" . implode("\n", XUtil::arrayGetOr($r, 'errors', array())); } } echo "\n"; echo "Start->{$name} start={$start}\n"; echo "{$name} test={$count} errors={$error_count}\n"; echo !empty($msg) ? "{$msg}\n" : ""; echo "End->{$name} end={$end}\n"; } }
function __construct($default, $option) { $option = XUtil::safeArray($option, array('file' => false)); /* for required config check*/ if ($option['file'] === false) { throw new XStoreSqliteException('store type sqlite require option["file"]'); } $this->file = $option['file']; $this->init(); }
public function open() { // if logger is not opend now open if ($this->_opend === false) { $this->_line_format = str_replace(array_keys($this->_format_map), $this->_format_map, $this->_line_format); $file = XUtil::makePath($this->_dirname, $this->_filename); $this->_fp = fopen($file, $this->_append ? 'a' : 'w'); flock($this->_fp, LOCK_EX); } $this->_opend = true; }
public static function autoLoad($name) { if (preg_match('/X([A-Z][a-z]+)([A-Z][a-z]+)/', $name, $m)) { $dir = strtolower($m[1]); $name = strtolower($m[2]) . '.class.php'; require_once XUtil::makePath($dir, $name); return true; } elseif (preg_match('/X(.*)/', $name, $m)) { $file = strtolower($m[1]) . '.class.php'; require_once $file; } }
function testLogMask() { $handler = XLog::factory('file', 'default', array('append' => 0, 'dirname' => $this->dirname, 'filename' => 'test1.log'), XLOG_WARNING); $handler->open(); $handler->info("TEST"); $handler->notice("TEST"); $handler->debug("TEST"); $handler->warning("TEST"); $handler->err("TEST"); $handler->crit("TEST"); $handler->close(); $this->assertEquala(3, count(file(XUtil::makePath($this->dirname, 'test1.log'))), 'Log Write Failed'); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $response = new stdClass(); $statusCode = 201; $in = Input::only('name', 'lat', 'lng', 'cid'); $rules = array('name' => 'required | alpha_spaces | unique:churches', 'lat' => 'numeric', 'lng' => 'numeric', 'cid' => 'integer'); $vd = Validator::make($in, $rules); if ($vd->fails()) { $errs = $vd->messages(); $statusCode = 400; $response = $errs->all(); if ($errs->has('name')) { // 教會已有建檔,嘗試建立教會與使用者之間的關係 $cid = Church::where('name', $in['name'])->pluck('id'); $statusCode = 201; // 先檢查是否已經加入教會 $uc = UserChurch::where('uid', Auth::user()->id)->first(); if ($uc && $uc->uid === Auth::user()->id) { $uc->cid = $cid; $uc->save(); } else { $relation = array('cid' => $cid, 'uid' => Auth::user()->id); UserChurch::firstOrCreate($relation); } $response = new stdClass(); return Response::json($response, $statusCode); } } else { $in['qlink'] = XUtil::makeQlink($in['name']); $church = Church::create($in); // 先檢查是否已經加入教會 $uc = UserChurch::where('uid', Auth::user()->id)->first(); if ($uc && $uc->uid === Auth::user()->id) { $uc->cid = $church->id; $uc->save(); } else { // 建立教會與使用者之間的關係 $relation = array('cid' => $church->id, 'uid' => Auth::user()->id); UserChurch::firstOrCreate($relation); } $response = new stdClass(); } return Response::json($response, $statusCode); }
/** * gettin resource handler * * @param string name */ function getResourceHandler($type) { // if alrady loaded handler exists if (isset($this->plugin['resource'][$type])) { return $this->plugin['resource'][$type]; } // info $fileName = "resource.{$type}.plugin.class.php"; $class = "XTemplaterResource" . ucfirst($type); $file = false; // search in plugin directorys foreach ($this->pluginDir as $d) { $file = XUtil::makePath($d, $fileName); if (file_exists($file)) { break; } } // if not found if ($file == false) { return false; } require_once $file; // if class not found if (!class_exists($class)) { return false; } // create instance $o = new $class($this); // save as resource handler return $this->registerResourceHandler($type, array($o, 'get'), array($o, 'getExpiredTime'), array($o, 'hasCache'), array($o, 'getCache'), array($o, 'putCache'), array($o, 'gcCache')); }
function init() { $this->dirname = dirname(__FILE__) . '/data'; $this->FW = XSystem::factory(XUtil::makePath($this->dirname, "site.ini"), array('root' => $this->dirname)); }
<?php require_once '../../lib/base/util.class.php'; XUtil::addIncludePath(XUtil::makePath("../..", 'class'), XUtil::makePath("../..", 'lib')); require_once 'XSystem.class.php'; $file = "../etc/site.ini"; define("SITE_ROOT", realpath("../")); $Mes = new XMessage(); $Mes->set('type', 'display'); $Mes->set('app', 'bbs'); $Mes->set('function', 'run'); $Mes->set('data', array()); $FW = XSystem::factory($file, array('site.root' => SITE_ROOT)); $FW->accept($Mes);
private function _getTagInfo($text) { $tagInfo = explode(" ", $text, 2); $tagName = $tagInfo[0]; $tagArg = XUtil::arrayGetOr($tagInfo, 1, ""); return array($tagName, $tagArg); }
<?php define('XROOT', realpath(dirname(__FILE__) . '/../')); require_once XROOT . '/lib/base/util.class.php'; XUtil::addIncludePath(XUtil::makePath(XROOT, 'class'), XUtil::makePath(XROOT, 'lib')); spl_autoload_register(array('XUtil', 'autoLoad')); // Error to Exception function exception_error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler");