示例#1
0
 /**
 @param	mimes	array of either whole mimes "part/part", or the last part of the mime "part"
 */
 static function notMime($v, $name, $mimes)
 {
     $mimes = Arrays::toArray($mimes);
     $mime = File::mime($_FILES[$name]['tmp_name']);
     foreach ($mimes as $matchMime) {
         if (preg_match('@' . preg_quote($matchMime) . '$@', $mime)) {
             $mimes = implode(', ', $mimes);
             Debug::toss(['type' => 'notMime', 'detail' => $mimes], 'InputException');
         }
     }
     return true;
 }
示例#2
0
文件: Db.php 项目: grithin/phpdb
 /**
 Ex:
 	- row('select * from user where id = 20') vs row('user',20);
 	- rows('select name from user where id > 20') vs sRows('user',array('id?>'=>20),'name')
 @param	from	table, array of tables, or from statement
 @param	where	see self::$where()
 @param	columns	list of columns; either string or array.	"*" default.
 @param	order	order by columns
 @param	limit	result limit
 @return sql string
 @note	this function is just designed for simple queries
 */
 protected function select($from, $where = null, $columns = '*', $order = null, $limit = null)
 {
     if (!$columns) {
         $columns = '*';
     }
     if (is_array($from)) {
         implode(', ', array_map([$this, 'quoteIdentity'], $from));
     } elseif (strpos($from, ' ') === false) {
         //ensure no space; don't quote a from statement
         $from = $this->quoteIdentity($from);
     }
     if (is_array($columns)) {
         $columns = implode(', ', array_map([$this, 'quoteIdentity'], $columns));
     }
     $select = 'SELECT ' . $columns . "\nFROM " . $from . $this->where($where);
     if ($order) {
         if (!is_array($order)) {
             $order = Arrays::toArray($order);
         }
         $orders = array();
         foreach ($order as $part) {
             $part = explode(' ', $part);
             if (!$part[1]) {
                 $part[1] = 'ASC';
             }
             //'"' works with functions like "sum(cost)"
             $orders[] = $this->quoteIdentity($part[0]) . ' ' . $part[1];
         }
         $select .= "\nORDER BY " . implode(',', $orders);
     }
     if ($limit) {
         $select .= "\nLIMIT " . $limit;
     }
     return $select;
 }
示例#3
0
 static function getAttributes($tag, $attributes)
 {
     $attributes = Arrays::toArray($attributes);
     $collected = array();
     foreach ($attributes as $attribute) {
         preg_match('@' . $attribute . '=([\'"]).+?\\1@i', $tag, $match);
         if ($match) {
             $collected[] = $match[0];
         }
     }
     return $collected;
 }
示例#4
0
 /**
 @param	mimes	array of either whole mimes "part/part", or the last part of the mime "part"
 
 @note To get mime: $mime = \Grithin\File::mime($_FILES[$name]['tmp_name']);
 */
 function mime($v, $mimes)
 {
     $mimes = Arrays::toArray($mimes);
     foreach ($mimes as $matchMime) {
         if (preg_match('@' . preg_quote($matchMime) . '$@', $v)) {
             return $v;
         }
     }
     self::error();
 }
示例#5
0
 static function prefixWithRule($rule, $rules = [])
 {
     $rules = \Grithin\Arrays::toArray($rules);
     array_unshift($rules, $rule);
     return $rules;
 }