Example #1
0
 /**
  * @return string
  */
 public function generateCSRFCode()
 {
     $ip = Request::get()->getRequest()->ip;
     $url = Request::get()->getRequest()->url;
     $str = FormatUtils::randStr(10);
     $tm = time();
     $code = md5("CSRF_{$ip};{$url};{$str};{$tm}");
     getCache()->set($code, 1, $this->ttl);
     return $code;
 }
Example #2
0
 /**
  * @param string $domain
  * @param array $config
  * @return Logger
  */
 public function registerLogger($domain, array $config)
 {
     $logger = new Logger($domain);
     $level = isset($config['level']) ? self::getLevel($config['level']) : '';
     $name = isset($config['title']) ? $config['title'] : "{$domain}.log";
     $max = isset($config['max_logfile']) ? intval($config['max_logfile']) : 10;
     $handler = new RotatingFileHandler(FormatUtils::formatPathArray([$this->logDir, $name]), $max, $level, true, 0777);
     $logger->pushHandler($handler);
     $this->loggers[$domain] = $logger;
     return $this->loggers[$domain];
 }
Example #3
0
 /**
  * @param array $conf
  * @return IView
  */
 protected function loadConfig($conf)
 {
     $dir = isset($conf['view_dir']) ? FormatUtils::formatPath($conf['view_dir']) : '';
     $loader = new \Twig_Loader_Filesystem($dir);
     if (isDebug()) {
         $conf['debug'] = true;
         $this->twig = new \Twig_Environment($loader, $conf);
         $this->twig->addExtension(new \Twig_Extension_Debug());
     } else {
         $this->twig = new \Twig_Environment($loader, $conf);
     }
     return $this;
 }
Example #4
0
 /**
  * @param $prefix
  * @param $file
  * @return string
  */
 private function formatPath($prefix, $file)
 {
     return $prefix ? FormatUtils::formatWebPathArray([getConfig()->get('base_url'), $prefix, $file]) : $file;
 }
Example #5
0
 public function testPathinfo()
 {
     $test = ['\\home\\a\\b.txt', 'cc.xml', '\\home\\aaa', '\\bb\\cc\\', 'C:\\aa\\bb', 'C:\\downloads', '\\dd.tsv'];
     foreach ($test as $t) {
         $this->assertEquals(pathinfo($t), FormatUtils::pathInfo($t));
     }
     $test2 = ['文件.txt' => ['dirname' => '.', 'basename' => '文件.txt', 'extension' => 'txt', 'filename' => '文件'], 'F:\\downloads\\20150303 网页图片' => ['dirname' => 'F:\\downloads', 'basename' => '20150303 网页图片', 'filename' => '20150303 网页图片'], '\\网页图片1.doc' => ['dirname' => '\\', 'basename' => '网页图片1.doc', 'extension' => 'doc', 'filename' => '网页图片1'], '\\网页图片\\中文1.php' => ['dirname' => '\\网页图片', 'basename' => '中文1.php', 'extension' => 'php', 'filename' => '中文1']];
     foreach ($test2 as $t => $e) {
         $pi = FormatUtils::pathInfo($t);
         $this->assertEquals($e, $pi);
     }
 }
Example #6
0
 /**
  * @param string $locale
  * @param string $domain
  */
 public function addResource($locale, $domain = 'messages')
 {
     $resource = $domain;
     if (substr($domain, -4, 4) != '.php') {
         $resource .= '.php';
     } else {
         $domain = substr($domain, 0, strlen($domain) - 4);
     }
     $file = FormatUtils::formatPathArray([$this->path, $locale, $resource]);
     if (file_exists($file)) {
         $re = (include "{$file}");
         $this->translator->addResource('array', $re, $locale, $domain);
     }
 }