private static function __verifyPlaces($places) { if ($places == 'ALL') { if (HTTPRequest::__isCLI()) { if (!is_associative($_SERVER['argv'])) { $aux = $_SERVER['argv']; $_SERVER['argv'] = array(); for ($i = 1; $i < $_SERVER['argc']; $i++) { if (($pos = strpos($aux[$i], "=")) === false) { $_SERVER['argv'][$aux[$i]] = true; continue; } $param = explode('=', trim($aux[$i])); $_SERVER['argv'][trim($param[0])] = $param[1]; } } $places = array('SERVER[\'argv\']'); } else { $places = array('GET', 'POST', 'COOKIE'); } } else { if (is_string($places)) { $places = explode(',', $places); } } return $places; }
/** * Build an instance or an array of instances given an indexed array. * * @param array $attributes * @return mixed */ public function build(array $attributes) { $callable = [$this->model, 'newInstance']; // The callable function. if (!is_associative($attributes)) { return array_map($callable, $attributes); } return call_user_func_array($callable, [$attributes]); }
function array_top($array) { $c = count($array); if ($c == 0) { return null; } if (is_associative($array)) { $keys = array_keys($array); return $array[$keys[$c - 1]]; } return $array[$c - 1]; }
/** * Get User's social status * * * * @access public * @param array * @return array */ function check_user($data = array()) { // Check for valid data if (empty($data) or !is_associative($data)) { // Invalid data, return FALSE return FALSE; } // Retrieve the query from the database $query = $this->db->where($data)->get('user_extend', 1); // Check if query row exists if ($query->row()) { // Query row exists, return query row return $query->row(); } else { // Query row doesn't exist, return FALSE return FALSE; } }
function dump_value($value) { if (is_object($value)) { return get_class($value) . ' object'; } else { if (is_array($value)) { if (is_associative($value)) { $ret = array(); foreach ($value as $key => $value) { $ret[] = dump_value($key) . ' => ' . _dump_inner_value($value); } return '{' . implode(', ', $ret) . '}'; } else { return '[' . implode(', ', array_map('_dump_inner_value', $value)) . ']'; } } else { return var_export($value, true); } } }
function printDump($var, $title = '') { $printBigAssoc = function ($assoc, $t = 1) use(&$printBigAssoc) { $is_object = null; if (is_array($assoc) || ($is_object = is_object($assoc))) { $cassoc = $is_object ? get_class($assoc) : count($assoc); $mt = 20; $display = "display: " . ($t == 1 ? 'block' : 'none') . ';'; $script = !$is_object && $cassoc > 0 ? "> <div style=\"position: absolute; top: 1px; left: -15px; width: 10px; height: 10px; border: 1px solid #000; background: #fff; cursor: pointer; line-height: 8px; text-align: center; \" onclick=\"javascript: var list=this.parentNode.parentNode.getElementsByClassName('list')[0]; var is_hidden = list.style.display == 'none'; list.style.display= is_hidden ? 'block' : 'none'; this.innerHTML = is_hidden ? '-' : '+'; \">+</div" : ''; if ($is_object) { $assoc = print_r_reverse(print_r($assoc, true)); $title = 'Object'; } $is_associative = is_associative($assoc); if (!$is_object) { $title = $is_associative ? 'Associative' : 'Array'; } $contenido = "<span{$script}>{$title} ({$cassoc})</span><div class=\"list\" style=\"{$display}\">\n"; foreach ($assoc as $k => $v) { $v = $printBigAssoc($v, $t + 1); if ($is_associative) { $k = "<span style=\"font-weight: bold; \">{$k}</span>"; } $contenido .= "\n <div style=\"margin-left: {$mt}px; position: relative; top: 0px; left: 0px; \">\n {$k} : {$v}\n </div>\n "; } return $contenido . "</div>\n"; } if (is_bool($assoc)) { return $assoc ? 'TRUE' : 'FALSE'; } if (is_null($assoc)) { return 'NULL'; } return $assoc; }; $title = $title ? "<div style=\"position: absolute; top: 3px; left: 10px; font-size: 15px; font-weight: bold; color: #666; \">{$title}</div>" : ''; echo "<div style=\"position: absolute; top: 50px; right: 50px; width: 600px; height: 400px; border: 1px solid #000; background: #f0f0f0; \">" . $title . "<div style=\"position: absolute; top: 5px; right: 12px; font-size: 15px; font-weight: bold; color: #666; \">" . printSize(sizeofvar($var)) . "</div>" . "<div style=\"position: absolute; top: 28px; left: 10px; right: 10px; bottom: 10px; overflow: auto; font-size: 13px; \">" . $printBigAssoc($var) . "</div>" . "</div>"; }
function jsonEncodeUTF8($obj) { switch (true) { case is_array($obj): if (is_associative($obj)) { $arr_out = array(); foreach ($obj as $key => $val) { $arr_out[$key] = jsonEncodeUTF8($val); } return $arr_out; } $arr_out = array(); $ct = count($obj); for ($j = 0; $j < $ct; $j++) { $arr_out[] = jsonEncodeUTF8($obj[$j]); } return $arr_out; case is_int($obj) || is_bool($obj): return $obj; default: return utf8_encode($obj); } }
function __printArray($array, $tab = 1) { $t = ''; for ($i = 0; $i < $tab; $i++) { $t .= "\t"; } $is_associative = is_associative($array); $res = ''; foreach ($array as $k => $v) { switch (true) { case is_string($v) && strpos($v, "\n"): $v = str_replace(array('\\$', '$'), '\\$', $v); $v = "<<<PPP\n{$v}\n\nPPP\n\n"; break; case is_string($v): $v = "'" . str_replace("'", "\\'", $v) . "'"; break; case is_bool($v): $v = $v ? 'true' : 'false'; break; case is_array($v): $v = $this->__printArray($v, $tab + 1); break; //case is_callable($v): // $v = $v(); // break; } $res .= $is_associative ? "{$t}\"{$k}\" => {$v},\n" : "{$t}{$v},\n"; } $t = $tab > 1 ? substr($t, ($tab - 1) * -1) : ''; return "array(\n{$res}{$t})"; }
/** * Update Comment * * Updates a gallery comment in the database * * @access public * @param int * @param array * @return bool */ function update_comment($comment_id = 0, $data = array()) { // Check to see if we have valid data if ($comment_id == '0' or empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Check if comment exists if (!($comment = $this->get_comment(array('comment_id' => $comment_id)))) { // Comment doesn't exist, return FALSE return FALSE; } // Data is valid, comment exists, update the data in the database return $this->db->update('gallery_comments', $data, array('comment_id' => $comment_id)); }
function list_contains_keys($items, $list, $greedy = true) { $items = explode(':', $items); $count = count($list); if ($count === 0) { $count = 1000; } //if original list is empty, set to a random number while (list($key, $value) = each($list)) { foreach ($items as $item) { if ($key == $item) { $count -= 1; } } } $results = false; if (is_associative($list)) { if ($greedy == true) { if ($count == 0) { $results = true; } else { $results = false; } } else { if ($count < count($list)) { $results = true; } } } return $results; }
/** * Get Comments * * Retrieves all gallery comments from the database * * @access public * @param int * @param int * @param array * @return array */ function get_comments($limit = 0, $offset = 0, $data = array()) { // Check for valid data if ($data && !is_array($data) && !is_associative($data)) { // Invalid data, return FALSE return FALSE; } // Check if limit exists if ($limit == 0) { // Limit doesn't exist, assign limit $limit = ''; } // Retrieve the query from the database $query = $this->db->order_by('comment_id', 'desc')->limit($limit, $offset)->where($data)->get('wall_comments'); // Check if query result exists if ($query->result()) { // Query result exists, return query result return $query->result(); } else { // Query result doesn't exist, return FALSE return FALSE; } }
/** * Count Articles * * Count the number of shouts in the database * * @access public * @param array * @return array */ function count_shouts($data = array()) { // Check for valid data if ($data && !is_array($data) && !is_associative($data)) { // Invalid data, return FALSE return FALSE; } // Retrieve the query from the database $query = $this->db->from('shoutbox')->where($data)->count_all_results(); // Return query return $query; }
public function resolveCallableDependencies($callback, $params) { if (is_array($callback)) { if (count($callback) < 2) { throw new RuntimeException('callable定义错误'); } $reflection = new ReflectionMethod($callback[0], $callback[1]); } else { $reflection = new ReflectionFunction($callback); } // 是否为关联数组 $isAssociative = is_associative($params); $args = []; if ($isAssociative) { // 是关联数组 - 键值对 键为string foreach ($reflection->getParameters() as $param) { $name = $param->getName(); $class = $param->getClass(); if ($class !== null) { $className = $class->getName(); if (isset($params[$className])) { $args[] = $params[$className]; unset($params[$className]); } else { $args[] = $this->get($className); } } else { $args[] = $params[$name]; } } } else { // 是索引数组 foreach ($reflection->getParameters() as $param) { $name = $param->getName(); $class = $param->getClass(); if ($class !== null) { $className = $class->getName(); if (isset($params[0]) && $params[0] instanceof $className) { $args[] = array_shift($params); } else { $args[] = $this->get($className); } } else { $args[] = array_shift($params); } } } return $args; // foreach ($reflection->getParameters() as $param) { // // 获取变量名 // $name = $param->getName(); // if ($class = $param->getClass() !== null) { // // 有类型提示的 // $className = $class->getName(); // if (isset($params[$className])) { // $args[] = $params[$className]; // unset($params[$className]); // } elseif (! $isAssociative && isset($params[0]) && $params[0] instanceof $className) { // $args[] = array_shift($params); // } else { // $args[] = $this->get($className); // } // } elseif ($associative && isset($params[$name])) { // } // } }
/** * Update Match * * Updates a match in the database * * @access public * @param int * @param array * @return bool */ function update_match($match_id = 0, $data = array()) { // Check to see if we have valid data if ($match_id == '0' or empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Check if match exists if (!($match = $this->get_match(array('match_id' => $match_id)))) { // Match doesn't exist, return FALSE return FALSE; } // Data is valid, match exists, update the data in the database return $this->db->update('matches', $data, array('match_id' => $match_id)); }
/** * Update Vote * * Updates a event vote in the database * * @access public * @param int * @param array * @return bool */ function update_vote($vote_id = 0, $data = array()) { // Check to see if we have valid data if ($vote_id == 0 or empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Check if vote exists if (!($vote = $this->get_vote(array('vote_id' => $vote_id)))) { // Vote doesn't exist, return FALSE return FALSE; } // Data is valid, vote exists, update the data in the database return $this->db->update('event_votes', $data, array('vote_id' => $vote_id)); }
/** * Update Sponsor * * Updates a sponsor in the database * * @access public * @param int * @param array * @return bool */ function update_sponsor($sponsor_id = 0, $data = array()) { // Check to see if we have valid data if ($sponsor_id == 0 or empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Check if sponsor exists if (!($sponsor = $this->get_sponsor(array('sponsor_id' => $sponsor_id)))) { // Sponsor doesn't exist, return FALSE return FALSE; } // Data is valid, sponsor exists, update the data in the database return $this->db->update('sponsors', $data, array('sponsor_id' => $sponsor_id)); }
/** * Update Alert * * Updates a alert in the database * * @access public * @param int * @param array * @return bool */ function update_alert($alert_id = 0, $data = array()) { // Check to see if we have valid data if ($alert_id == '0' or empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Check if alert exists if (!($alert = $this->get_alert(array('alert_id' => $alert_id)))) { // Alert doesn't exist, return FALSE return FALSE; } // Data is valid, alert exists, update the data in the database return $this->db->update('alerts', $data, array('alert_id' => $alert_id)); }
/** * Update Setting * * Updates a setting in the database * * @access public * @param int * @param array * @return bool */ function update_setting($setting_id = 0, $data = array()) { // Check to see if we have valid data if ($setting_id == '0' or empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Check if setting exists if (!($setting = $this->get_setting(array('setting_id' => $setting_id)))) { // Setting doesn't exist, return FALSE return FALSE; } // Data is valid, setting exists, update the data in the database return $this->db->update('settings', $data, array('setting_id' => $setting_id)); }
/** * Insert Private Message * * Inserts a private message into the database * * @access public * @param array * @return bool */ function insert_privmsg($data = array()) { // Check to see if we have valid data if (empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Data is valid, insert the data in the database return $this->db->insert('privmsgs', $data); }
/** * Update Category * * Updates a category in the database * * @access public * @param int * @param array * @return bool */ function update_category($category_id = 0, $data = array()) { // Check to see if we have valid data if ($category_id == '0' or empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Check if article exists if (!($category = $this->get_category(array('category_id' => $category_id)))) { // Article doesn't exist, return FALSE return FALSE; } // Data is valid, article exists, update the data in the database return $this->db->update('article_categories', $data, array('category_id' => $article_id)); }
function addConfiguration($arr, $complement = false) { if (!is_array($arr) || !is_associative($arr)) { return false; } $func = $complement ? 'array_merge_recursive' : 'array_merge'; $GLOBALS['tt780'][$this->id]['configuration'] = $func($GLOBALS['tt780'][$this->id]['configuration'], $arr); }
/** * Update Widget * * Updates a widget in the database * * @access public * @param int * @param array * @return bool */ function update_widget($widget_id = 0, $data = array()) { // Check to see if we have valid data if ($widget_id == 0 or empty($data) or !is_associative($data)) { // Data is invalid, return FALSE return FALSE; } // Check if widget exists if (!($widget = $this->get_widget(array('widget_id' => $widget_id)))) { // Widget doesn't exist, return FALSE return FALSE; } // Data is valid, widget exists, update the data in the database return $this->db->update('widgets', $data, array('widget_id' => $widget_id)); }