private function __magic_call($method, array $args = []) { $prefix = substr($method, 0, 3); $class = get_called_class(); switch ($prefix) { case 'set': $attr = \unCamelCase(str_replace('set', '', $method)); $rc = new \ReflectionClass($class); if ($rc->hasMethod('set')) { array_unshift($args, $attr); return call_user_func_array([$this, 'set'], $args); } $this->{$attr} = $args[0]; return $this; case 'get': $attr = \unCamelCase(str_replace('get', '', $method)); $rc = new \ReflectionClass($class); if ($rc->hasMethod('get')) { array_unshift($args, $attr); return call_user_func_array([$this, 'get'], $args); } return $this->{$attr}; } throw new \Leno\Exception(get_called_class() . '::' . $method . ' Not Defined'); }
protected function handleHelp($command) { $this->output(sprintf('用法:<keyword>leno %s %s %s </keyword>', strtolower(preg_replace('/^.*\\\\/', '', unCamelCase(get_called_class()))), $command, '[参数]')); $this->output("\n" . $this->describeCommand($command) . "\n"); $this->output('支持的参数:'); $opts = $this->getArgsInfo($command); foreach ($opts as $opt) { $this->output(sprintf("<keyword> %s\t\t</keyword>%s", implode(",", $opt['looks']), $opt['description'])); } }
public function __call($method, array $args = []) { $series = array_filter(explode('_', unCamelCase($method))); $methods = array_splice($series, 0, 1); array_unshift($args, implode('_', $series)); if (in_array($methods[0], ['get', 'set'])) { return call_user_func_array([$this, $method], $args); } throw new MethodNotFoundException('Controller::' . $method); }
/** * __call魔术方法,提供group,order,field系列函数入口 * * @param string method 方法名 * @param mixed parameters 参数 * * @return this */ public function __call($method, array $args = []) { try { return parent::__call($method, $args); } catch (\Exception $ex) { $series = explode('_', unCamelCase($method, '_')); $type = $series[0]; array_splice($series, 0, 1); array_unshift($args, implode('_', $series)); switch ($type) { case 'order': return call_user_func_array([$this, 'order'], $args); case 'group': return call_user_func_array([$this, 'group'], $args); case 'field': return call_user_func_array([$this, 'field'], $args); } throw new \Exception(get_class() . '::' . $method . ' Not Found'); } }
/** * examine() * * - Loads in the structure of a fresh SMF install via sql_to_array * - Looks at each table in the current installation and determines if it is a default table * and if so finds extra columns or indexes that should be removed. * * @return */ function examine() { global $smcFunc, $db_prefix, $extra, $table_prefix, $version; // will allow for this == THIS and thisVar == this_var on col / index names to avoid false positives, set to true for more hits $strict_case = false; $tables = sql_to_array(dirname(__FILE__) . '/sql' . $version . '.sql'); $mset = file_to_array(dirname(__FILE__) . '/modsettings' . $version . '.txt'); $real_prefix = preg_match('~^(`?)(.+?)\\1\\.(.*?)$~', $db_prefix, $match) === 1 ? $match[3] : $db_prefix; $extra = array(); // make sure this is gone for a clean run if (isset($_SESSION['db_cleaner'])) { unset($_SESSION['db_cleaner']); } // examine each table in this installation $current_tables = $smcFunc['db_list_tables'](); foreach ($current_tables as $table) { $table = preg_replace('~^' . $real_prefix . '~', '', $table); // Table itself does not exist in a fresh install if (!isset($tables[$table])) { $extra['tables'][] = $table; continue; } // It exists in a fresh install, lets check if there are any extra columns in it $current_columns = $smcFunc['db_list_columns']($table_prefix . $table, false); foreach ($current_columns as $column) { if (!isset($tables[$table]['columns'][$column]) && $strict_case) { $extra['columns'][$table][] = $column; } elseif (!$strict_case && !isset($tables[$table]['columns'][strtolower($column)])) { $extra['columns'][$table][] = $column; } } // or extra indexes taking up space $current_indexes = $smcFunc['db_list_indexes']($table_prefix . $table, true); foreach ($current_indexes as $key => $index) { if (!isset($tables[$table]['indexes'][$key])) { // keys don't match ... v1 to v2 upgrade appears to reuse old smf1 index names (upper or camel) .. if ($version == 2 && $key != 'PRIMARY' && !$strict_case) { // lets see if a lowercase or camelCase version of the key will work $tempkey = isset($tables[$table]['indexes'][strtolower($key)]) ? strtolower($key) : (isset($tables[$table]['indexes'][unCamelCase($key)]) ? unCamelCase($key) : ''); if (!empty($tempkey)) { // Probably found it, but are the index type and index cols exactly the same as well? if ($current_indexes[$key]['type'] != $tables[$table]['indexes'][$tempkey]['type'] || count(array_diff($current_indexes[$key]['columns'], $tables[$table]['indexes'][$tempkey]['columns'])) != 0) { unset($tempkey); } } if (empty($tempkey)) { $extra['indexes'][$table][] = $index; } } else { $extra['indexes'][$table][] = $index; } } } } // modSettings that are not from standard SMF $current_settings = array(); $request = $smcFunc['db_query']('', ' SELECT variable FROM {db_prefix}settings', array()); while ($row = $version == 1 ? mysql_fetch_row($request) : $smcFunc['db_fetch_row']($request)) { $current_settings[$row[0]] = $row[0]; } $version == 1 ? mysql_free_result($request) : $smcFunc['db_free_result']($request); // check what could be there vs what it ;) foreach ($current_settings as $mod) { if (!isset($mset[$mod])) { // check for a multi settings like bbc or integration tags $submod = explode('_', $mod); if (isset($mset[$submod[0] . '_']) && strpos($mod, $mset[$submod[0] . '_']) == 0) { continue; } $extra['settings'][] = $mod; } } }
function printDeployOptions($deployOptions) { if (array_key_exists('testLevel', $deployOptions)) { $editable = false; } else { $editable = true; } print "<table>\n"; foreach ($deployOptions as $optionName => $optionValue) { print "<tr><td style='text-align: right; padding-right: 2em; padding-bottom: 0.5em;'>" . "<label for='{$optionName}'>" . unCamelCase($optionName) . "</label></td><td>"; if (is_bool($optionValue)) { print "<input id='{$optionName}' type='checkbox' name='{$optionName}' " . (isset($optionValue) && $optionValue ? "checked='checked'" : "") . "/>"; } else { if ($optionName == TEST_LEVEL_DEPLOY_OPTION) { $targetElementId = RUN_TESTS_DEPLOY_OPTION; $valueToLookFor = RUN_SPECIFIED_TESTS_TEST_LEVEL; print "<select id='{$optionName}' name='{$optionName}' onchange=\"var el = document.getElementById('{$targetElementId}');this.value == '{$valueToLookFor}' ? el.removeAttribute('disabled') : el.disabled='disabled';\">"; $testLevelValues = array("NoTestRun", "RunLocalTests", "RunAllTestsInOrg", RUN_SPECIFIED_TESTS_TEST_LEVEL); foreach ($testLevelValues as $testLevelValue) { print "<option value='{$testLevelValue}'>{$testLevelValue}</option>"; } print "</select>"; } else { if ($optionName == RUN_TESTS_DEPLOY_OPTION) { print "<input id='{$optionName}' type='text' name='{$optionName}' value='" . implode(",", $optionValue) . "'" . " " . ($editable ? "" : "disabled='disabled'") . "/>"; } } } print "</td></tr>\n"; } print "</table>\n"; }
function printStatusCell($resultName, $resultValue) { print "<td style='text-align: right; padding-right: 2em; font-weight: bold;'>" . unCamelCase($resultName) . "</td><td>"; if (is_bool($resultValue)) { print $resultValue ? "true" : "false"; } else { print localizeDateTimes($resultValue); } print "</td>"; }
function printDeployOptions($deployOptions, $editable) { print "<table>\n"; foreach ($deployOptions as $optionName => $optionValue) { print "<tr><td style='text-align: right; padding-right: 2em; padding-bottom: 0.5em;'>" . "<label for='{$optionName}'>" . unCamelCase($optionName) . "</label></td><td>"; if (is_bool($optionValue)) { print "<input id='{$optionName}' type='checkbox' name='{$optionName}' " . (isset($optionValue) && $optionValue ? "checked='checked'" : "") . " " . ($editable ? "" : "disabled='disabled'") . "/>"; } else { if (is_array($optionValue)) { print "<input id='{$optionName}' type='text' name='{$optionName}' value='" . implode(",", $optionValue) . "'" . " " . ($editable ? "" : "disabled='disabled'") . "/>"; } } print "</td></tr>\n"; } print "</table>\n"; }
/** * examine() * * - Loads in the structure of a fresh SMF install via sql_to_array * - Looks at each table in the current installation and determines if it is a default table * and if so finds extra columns or indexes that should be removed. * * @return */ function examine() { global $db_prefix, $extra, $table_prefix; $db = database(); $table_db = db_table(); // Will allow for this == THIS and thisVar == this_var on col / index names to avoid false positives, set to true for more hits $strict_case = false; // Load in our standards files $tables = sql_to_array(dirname(__FILE__) . '/install_sql.sql'); // Some tables are created not installed, others? $tables['log_search_words'] = array('indexes' => array('PRIMARY' => array('name' => 'PRIMARY', 'type' => 'primary', 'columns' => 'id_word, id_msg')), 'columns' => array('id_word' => array('name' => 'id_word'), 'id_msg' => array('name' => 'id_msg'))); // All of the known modSettings $mset = file_to_array(dirname(__FILE__) . '/modsettings.txt'); $real_prefix = preg_match('~^(`?)(.+?)\\1\\.(.*?)$~', $db_prefix, $match) === 1 ? $match[3] : $db_prefix; $extra = array(); // Make sure this is gone for a clean run if (isset($_SESSION['db_cleaner'])) { unset($_SESSION['db_cleaner']); } // Examine each table in this installation $current_tables = $db->db_list_tables(); foreach ($current_tables as $table) { $table = preg_replace('~^' . $real_prefix . '~', '', $table); // Table itself does not exist in a fresh install if (!isset($tables[$table])) { $extra['tables'][] = $table; continue; } // It exists in a fresh install, lets check if there are any extra columns in it $current_columns = $table_db->db_list_columns($table_prefix . $table, false); foreach ($current_columns as $column) { if (!isset($tables[$table]['columns'][$column]) && $strict_case) { $extra['columns'][$table][] = $column; } elseif (!$strict_case && !isset($tables[$table]['columns'][strtolower($column)])) { $extra['columns'][$table][] = $column; } } // Or extra indexes taking up space $current_indexes = $table_db->db_list_indexes($table_prefix . $table, true); foreach ($current_indexes as $key => $index) { if (!isset($tables[$table]['indexes'][$key])) { // keys don't match, upgrade issue? if ($key != 'PRIMARY' && !$strict_case) { // lets see if a lowercase or camelCase version of the key will work $tempkey = isset($tables[$table]['indexes'][strtolower($key)]) ? strtolower($key) : (isset($tables[$table]['indexes'][unCamelCase($key)]) ? unCamelCase($key) : ''); if (!empty($tempkey)) { // Probably found it, but are the index type and index cols exactly the same as well? if ($current_indexes[$key]['type'] != $tables[$table]['indexes'][$tempkey]['type'] || count(array_diff($current_indexes[$key]['columns'], $tables[$table]['indexes'][$tempkey]['columns'])) != 0) { unset($tempkey); } } if (empty($tempkey)) { $extra['indexes'][$table][] = $index; } } else { $extra['indexes'][$table][] = $index; } } } } // modSettings that are not from standard Elkarte $current_settings = array(); $request = $db->query('', ' SELECT variable FROM {db_prefix}settings', array()); while ($row = $db->fetch_row($request)) { $current_settings[$row[0]] = $row[0]; } $db->free_result($request); // Check what could be there vs what it ;) foreach ($current_settings as $mod) { if (!isset($mset[$mod])) { // check for a multi settings like bbc or integration tags $submod = explode('_', $mod); if (isset($mset[$submod[0] . '_']) && strpos($mod, $mset[$submod[0] . '_']) == 0) { continue; } $extra['settings'][] = $mod; } } }
public static function processResults($raw, $groupTopLevelScalarsIn = null, $unCamelCaseKeys = false) { $processed = array(); foreach (array(true, false) as $scalarProcessing) { foreach ($raw as $rawKey => $rawValue) { if (is_array($rawValue) || is_object($rawValue)) { if ($scalarProcessing) { continue; } $processedSubResults = self::processResults($rawValue, null, $unCamelCaseKeys); $subCount = " (" . count($processedSubResults) . ")"; if (isset($rawValue->name) && $rawValue->name != "") { $processed[$rawValue->name] = $processedSubResults; } else { if (isset($rawValue->fileName) && $rawValue->fileName != "") { $processed[$rawValue->fileName] = $processedSubResults; } else { if (isset($rawValue->fullName) && $rawValue->fullName != "") { $processed[$rawValue->fullName] = $processedSubResults; } else { if (isset($rawValue->label) && $rawValue->label != "") { $processed[$rawValue->label] = $processedSubResults; } else { if (isset($rawValue->column) && isset($rawValue->line)) { $processed[$rawValue->column . ":" . $rawValue->line] = $processedSubResults; krsort($processed); } else { if (isset($rawValue->childSObject) && isset($rawValue->field)) { $processed[$rawValue->childSObject . "." . $rawValue->field] = $processedSubResults; } else { if ($unCamelCaseKeys) { $processed[unCamelCase($rawKey) . $subCount] = $processedSubResults; } else { $processed[$rawKey . $subCount] = $processedSubResults; } } } } } } } } else { if ($groupTopLevelScalarsIn != null) { $processed[$groupTopLevelScalarsIn][$rawKey] = $rawValue; } else { $processed[$rawKey] = $rawValue; } } } } return $processed; }
/** * Checks if the given name is found in the array, either in camelCased or * un_camel_cased form. * @param string $name: The name to check, both CC'd and unCC'd * @param Array $array: Array to check * @return mixed: matched name form, or boolean false */ function cciInArray($name, $array) { if (!$array || !$name) { return false; } $ucc_name = unCamelCase($name); $ccName = toCamelCase($name); if (in_array($ucc_name, $array, true)) { return $ucc_name; } if (in_array($ccName, $array, true)) { return $ccName; } return false; }
/** * 魔术方法定义可以方便的使用set,get,add, inc, dec方法,该方法有一些性能开销, * 那么请直接使用 set,get,add, inc, dec方法 * * ### example * * ```php * $this->setHelloWorld('hello world') === $this->set('hello_world', 'hello world') * $this->getHelloWorld() === $this->get('hello_world') * $this->addHelloWorld('hello world') === $this->add('hello_world', 'hello world') * ``` */ public function __call($method, array $args = []) { $series = array_filter(explode('_', unCamelCase($method, '_'))); if (!isset($series[0])) { throw new MethodNotFoundException(get_called_class() . '::' . $method); } $type = array_splice($series, 0, 1)[0]; array_unshift($args, implode('_', $series)); $supports = ['set', 'get', 'add', 'inc', 'dec']; if (in_array($type, $supports)) { return call_user_func_array([$this, $type], $args); } throw new MethodNotFoundException(get_called_class() . '::' . $method); }
/** * __call方法,该方法提供by系列函数,on系列函数, set系列函数,get系列函数的入口 * * @param string method 方法名 * @param array|null parameters 调用参数 * */ public function __call($method, array $args = []) { $series = explode('_', unCamelCase($method, '_')); if (!isset($series[0])) { throw new \Exception(get_called_class() . '::' . $method . ' Not Found'); } $first = array_splice($series, 0, 1)[0]; $opers = array('set', 'reset'); if (in_array($first, $opers)) { array_unshift($args, implode('_', $series)); return call_user_func_array([$this, $first], $args); } $condi = [self::TYPE_CONDI_BY, self::TYPE_CONDI_ON]; if (in_array($first, $condi) && ($ret = $this->callCondition($series, $args, $first))) { return $ret; } throw new \Exception(get_class() . '::' . $method . ' Not Found'); }