Ejemplo n.º 1
0
 protected function request($url, $default_controller, $default_action)
 {
     $tmp = array_filter(explode('/', $url), function ($str) {
         return $str !== '';
     });
     $name = is_array($tmp) && count($tmp) ? array_shift($tmp) : $default_controller;
     $action = is_array($tmp) && count($tmp) ? array_shift($tmp) : $default_action;
     $params = is_array($tmp) && count($tmp) ? $tmp : array();
     $name = Str::camelize($name);
     $class = 'App\\' . APP . '\\Controller\\' . $name . 'Controller';
     $path = DIR_CONTROLLERS . "/{$name}Controller.php";
     return array('url' => $url, 'name' => $name, 'class' => $class, 'path' => $path, 'action' => strtolower($action), 'params' => $params);
 }
Ejemplo n.º 2
0
 public function check($data)
 {
     foreach ($this->rules as $item) {
         $field = $item[0];
         $value = isset($data[$field]) ? $data[$field] : null;
         $rule = $item[1];
         $param1 = isset($item[2]) ? $item[2] : null;
         $param2 = isset($item[3]) ? $item[3] : null;
         $message = isset($item[4]) ? $item[4] : $this->messages[$rule];
         if ($rule == 'matches') {
             $valid = Valid::matches($data, $field, $param1);
         } elseif ($rule == 'notEmpty' || $rule == 'is') {
             $valid = Valid::$rule($value, $param1, $param2);
         } else {
             $valid = !$value || Valid::$rule($value, $param1, $param2);
         }
         if (!$valid && empty($this->errors[$field])) {
             $message = Str::insert($message, compact('field', 'value', 'rule', 'param1', 'param2'));
             $this->errors[$field] = $message;
         }
     }
     return $this->errors;
 }
Ejemplo n.º 3
0
 public static function quoteInto($str, $data, $options = array())
 {
     return Str::insert($str, self::quote($data), $options);
 }
Ejemplo n.º 4
0
 public function testPregReplace()
 {
     $this->assertEquals('Foo-DEF? Gh: 12', Str::preg_replace('Ąbć-DEF? Gh: 12', '/Ąb./', 'Foo'));
 }
 /**
 	设置缓存,默认永不过期
 */
 function set($key, $value, $minutes = null)
 {
     if (!$minutes) {
         $minutes = 0;
     }
     $a = $this->file($key);
     if (!$value || is_array($value) && count($value) < 1) {
         $value = '#sun#kang#zhang#yi';
     }
     $value = Str::cookie($value);
     file_put_contents($a[0], $value);
     file_put_contents($a[1], $minutes);
 }
Ejemplo n.º 6
0
 function indexAction()
 {
     $hash = $_POST['hash'];
     $chunk = $_POST['chunk'];
     $chunks = $_POST['chunks'];
     $ret['fileNameReturn'] = $n = $_POST['fileNameReturn'];
     if (!in_array($mime, $this->allowMime)) {
     }
     if ($hash) {
         $one = (array) $this->obj->findOne(['hash' => $hash]);
         if ($one) {
             unset($one['_id'], $one['uid'], $one['time']);
             exit(json_encode($one + $ret));
         }
     }
     $mime = $_FILES['file']['type'];
     $size = $_FILES['file']['size'];
     $mr = $this->mime->findExtensions($mime);
     $ext = $mr[1] ?: $mr[0];
     ///
     $dir = '/' . $this->upload_dir . '/' . date('Ymd');
     if (!is_dir(WEB . $dir)) {
         mkdir(WEB . $dir, 0777, true);
     }
     /////////
     $name = $dir . '/' . Str::rand(8) . "." . $ext;
     $filePath = WEB . $name;
     if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
         $contentType = $_SERVER["HTTP_CONTENT_TYPE"];
     }
     if (isset($_SERVER["CONTENT_TYPE"])) {
         $contentType = $_SERVER["CONTENT_TYPE"];
     }
     // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
     if (strpos($contentType, "multipart") !== false) {
         if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
             // Open temp file
             $out = fopen($filePath, $chunk == 0 ? "wb" : "ab");
             if ($out) {
                 // Read binary input stream and append it to temp file
                 $in = fopen($_FILES['file']['tmp_name'], "rb");
                 if ($in) {
                     while ($buff = fread($in, 4096)) {
                         fwrite($out, $buff);
                     }
                 } else {
                 }
                 fclose($in);
                 fclose($out);
                 @unlink($_FILES['file']['tmp_name']);
             }
         }
     } else {
         $out = fopen($filePath, $chunk == 0 ? "wb" : "ab");
         if ($out) {
             $in = fopen("php://input", "rb");
             if ($in) {
                 while ($buff = fread($in, 4096)) {
                     fwrite($out, $buff);
                 }
             } else {
             }
             fclose($in);
             fclose($out);
         }
     }
     if ($chunk && $_POST['chunk'] + 1 != $_POST['chunks']) {
         exit(json_encode(['error' => 1, 'msg' => '分块上传进行中']));
     }
     $data = array('name' => $name, 'extension' => $ext, 'mime' => $mime, 'size' => $size, 'hash' => $hash);
     $uid = cookie('id');
     if ($uid) {
         $data['uid'] = $uid;
     }
     $nid = $this->obj->insert($data);
     if (!$hash) {
         $this->obj->update(['_id' => $nid], ['hash' => $h1]);
         $data['hash'] = $h1;
     }
     exit(json_encode($data + $ret));
 }
Ejemplo n.º 7
0
 /**
  * @return StrObject
  */
 public function preg_replace($search, $replace = null)
 {
     if (is_array($search) && func_num_args() == 1) {
         $replace = array_values($search);
         $search = array_keys($search);
     }
     $value = Str::preg_replace($this->value, $search, $replace);
     return new self($value);
 }
Ejemplo n.º 8
0
 public static function isLength($str, $length)
 {
     return Str::len($str) == $length;
 }
Ejemplo n.º 9
0
 function setELE()
 {
     $this->var = "uploader_" . Str::rand(4);
     $this->uploadBtn = "uploader_btn_" . Str::rand(4);
 }