本文整理汇总了PHP中pts_strings类的典型用法代码示例。如果您正苦于以下问题:PHP pts_strings类的具体用法?PHP pts_strings怎么用?PHP pts_strings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了pts_strings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
public static function delete($object, $ignore_files = null, $remove_root_directory = false)
{
// Delete files and/or directories
if ($object == false) {
return false;
}
if (is_dir($object)) {
$object = pts_strings::add_trailing_slash($object);
}
foreach (pts_file_io::glob($object . '*') as $to_remove) {
if (is_file($to_remove) || is_link($to_remove)) {
if (is_array($ignore_files) && in_array(basename($to_remove), $ignore_files)) {
continue;
// Don't remove the file
} else {
unlink($to_remove);
}
} else {
if (is_dir($to_remove)) {
self::delete($to_remove, $ignore_files, true);
}
}
}
if ($remove_root_directory && is_dir($object) && count(pts_file_io::glob($object . '/*')) == 0) {
rmdir($object);
}
}
示例2: render_graph_identifiers
protected function render_graph_identifiers()
{
$key_strings = array();
foreach (array_keys($this->graph_identifiers) as $i) {
$percent = pts_math::set_precision($this->graph_data[0][$i] / $this->i['pie_sum'] * 100, 2);
array_push($key_strings, '[' . $percent . "%]");
//array_push($key_strings, '[' . $this->graph_data[0][$i] . ' / ' . $percent . "%]");
}
$key_count = count($key_strings);
$key_item_width = 18 + $this->text_string_width(pts_strings::find_longest_string($this->graph_identifiers), self::$c['size']['key']);
$key_item_width_value = 12 + $this->text_string_width(pts_strings::find_longest_string($key_strings), self::$c['size']['key']);
$keys_per_line = floor(($this->i['graph_left_end'] - $this->i['left_start'] - 14) / ($key_item_width + $key_item_width_value));
if ($keys_per_line < 1) {
$keys_per_line = 1;
}
$key_line_height = 14;
$this->i['top_start'] += 12;
$c_y = $this->i['top_start'] - $key_line_height - 5;
//$this->reset_paint_index();
for ($i = 0; $i < $key_count; $i++) {
$this_color = $this->get_paint_color($i);
if ($i > 0 && $i % $keys_per_line == 0) {
$c_y += $key_line_height;
$this->i['top_start'] += $key_line_height;
}
$c_x = $this->i['left_start'] + 13 + ($key_item_width + $key_item_width_value) * ($i % $keys_per_line);
$this->svg_dom->add_element('rect', array('x' => $c_x - 13, 'y' => $c_y - 5, 'width' => 10, 'height' => 10, 'fill' => $this_color, 'stroke' => self::$c['color']['notches'], 'stroke-width' => 1));
$this->svg_dom->add_text_element($this->graph_identifiers[$i], array('x' => $c_x, 'y' => $c_y, 'font-size' => self::$c['size']['key'], 'fill' => $this_color, 'text-anchor' => 'start', 'dominant-baseline' => 'middle'));
$this->svg_dom->add_text_element($key_strings[$i], array('x' => $c_x + $key_item_width + 30, 'y' => $c_y, 'font-size' => self::$c['size']['key'], 'fill' => $this_color, 'text-anchor' => 'end', 'dominant-baseline' => 'middle'));
}
}
示例3: read_osx_system_profiler
public static function read_osx_system_profiler($data_type, $object, $multiple_objects = false, $ignore_values = array())
{
$value = $multiple_objects ? array() : false;
if (pts_client::executable_in_path('system_profiler')) {
$info = trim(shell_exec('system_profiler ' . $data_type . ' 2>&1'));
$lines = explode("\n", $info);
for ($i = 0; $i < count($lines) && ($value == false || $multiple_objects); $i++) {
$line = pts_strings::colon_explode($lines[$i]);
if (isset($line[0]) == false) {
continue;
}
$line_object = str_replace(' ', null, $line[0]);
if (($cut_point = strpos($line_object, '(')) > 0) {
$line_object = substr($line_object, 0, $cut_point);
}
if (strtolower($line_object) == strtolower($object) && isset($line[1])) {
$this_value = trim($line[1]);
if (!empty($this_value) && !in_array($this_value, $ignore_values)) {
if ($multiple_objects) {
array_push($value, $this_value);
} else {
$value = $this_value;
}
}
}
}
}
return $value;
}
示例4: mem_usage_bsd
private function mem_usage_bsd($TYPE = 'TOTAL', $READ = 'USED')
{
$vmstats = explode("\n", shell_exec('vm_stat 2>&1'));
// buffers_and_cache
foreach ($vmstats as $vmstat_line) {
$line_parts = pts_strings::colon_explode($vmstat_line);
if (self::$page_size == -1) {
strtok($vmstat_line, ':');
$tok = strtok(' ');
while (self::$page_size == -1) {
if (is_numeric($tok)) {
self::$page_size = $tok;
} else {
$tok = strtok(' ');
}
}
continue;
}
//$line_parts[1] = pts_strings::trim_spaces($line_parts[1]);
$line_type = strtok($vmstat_line, ':');
$line_value = strtok(' .');
if ($TYPE == 'MEMORY') {
if ($line_type == 'Pages active' && $READ == 'USED') {
$mem_usage = $line_value / (1048576 / self::$page_size);
break;
}
if ($line_type == 'Pages free' && $READ == 'FREE') {
$mem_usage = $line_value / (1048576 / self::$page_size);
break;
}
}
}
return pts_math::set_precision($mem_usage);
}
示例5: render_graph_bars
protected function render_graph_bars()
{
$bar_count = count($this->graph_data);
$separator_width = ($a = 8 - floor($bar_count / 2) * 2) > 0 ? $a : 0;
$bar_width = floor(($this->i['identifier_width'] - $separator_width - $bar_count * $separator_width) / $bar_count);
for ($i_o = 0; $i_o < $bar_count; $i_o++) {
$paint_color = $this->get_paint_color(isset($this->graph_data_title[$i_o]) ? $this->graph_data_title[$i_o] : null);
foreach (array_keys($this->graph_data[$i_o]) as $i) {
$value = pts_math::set_precision($this->graph_data[$i_o][$i], 2);
$graph_size = round($value / $this->i['graph_max_value'] * ($this->i['graph_top_end'] - $this->i['top_start']));
$value_plot_top = max($this->i['graph_top_end'] + 1 - $graph_size, 1);
$px_bound_left = $this->i['left_start'] + $this->i['identifier_width'] * $i + $bar_width * $i_o + $separator_width * ($i_o + 1);
$px_bound_right = $px_bound_left + $bar_width;
$title_tooltip = $this->graph_identifiers[$i] . ': ' . $value;
$run_std_deviation = isset($this->graph_data_raw[$i_o][$i]) ? pts_math::standard_deviation(pts_strings::colon_explode($this->graph_data_raw[$i_o][$i])) : 0;
if ($run_std_deviation > 0) {
$title_tooltip .= ' || ' . pts_math::set_precision($run_std_deviation, 1) . ' STD';
}
$this->svg_dom->add_element('rect', array('x' => $px_bound_left + 1, 'y' => $value_plot_top, 'width' => $bar_width, 'height' => $this->i['graph_top_end'] - $value_plot_top, 'fill' => in_array($this->graph_identifiers[$i], $this->value_highlights) ? self::$c['color']['alert'] : $paint_color, 'stroke' => self::$c['color']['body_light'], 'stroke-width' => 1, 'xlink:title' => $title_tooltip));
if ($px_bound_right - $px_bound_left < 15) {
// The bars are too skinny to be able to plot anything on them
continue;
}
$x = $px_bound_left + ($px_bound_right - $px_bound_left) / 2;
if ($graph_size > 18) {
$this->svg_dom->add_text_element($value, array('x' => $x, 'y' => $value_plot_top + 2, 'font-size' => floor(self::$c['size']['bars'] * 0.9), 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
} else {
// Make things more compact
$this->svg_dom->add_text_element($value, array('x' => $x, 'y' => $value_plot_top + 2, 'font-size' => floor(self::$c['size']['bars'] * 0.6), 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
}
}
}
// write a new line along the bottom since the draw_rectangle_with_border above had written on top of it
$this->svg_dom->draw_svg_line($this->i['left_start'], $this->i['graph_top_end'], $this->i['graph_left_end'], $this->i['graph_top_end'], self::$c['color']['notches'], 1);
}
示例6: read_sensor
public static function read_sensor()
{
// Determine current percentage for processor usage
if (phodevi::is_linux() || phodevi::is_bsd()) {
$start_load = self::cpu_load_array(-1);
sleep(1);
$end_load = self::cpu_load_array(-1);
for ($i = 0; $i < count($end_load); $i++) {
$end_load[$i] -= $start_load[$i];
}
$percent = ($sum = array_sum($end_load)) == 0 ? 0 : 100 - $end_load[count($end_load) - 1] * 100 / $sum;
} else {
if (phodevi::is_solaris()) {
// TODO: Add support for monitoring load on a per-core basis (through mpstat maybe?)
$info = explode(' ', pts_strings::trim_spaces(pts_arrays::last_element(explode("\n", trim(shell_exec('sar -u 1 1 2>&1'))))));
$percent = $info[1] + $info[2];
} else {
if (phodevi::is_macosx()) {
// CPU usage for user
$top = shell_exec('top -n 1 -l 1 2>&1');
$top = substr($top, strpos($top, 'CPU usage: ') + 11);
$percent = substr($top, 0, strpos($top, '%'));
} else {
$percent = null;
}
}
}
if (!is_numeric($percent) || $percent < 0 || $percent > 100) {
$percent = -1;
}
return pts_math::set_precision($percent, 2);
}
示例7: render_graph_candle_sticks
protected function render_graph_candle_sticks()
{
$bar_count = count($this->graph_data_raw);
$bar_width = floor($this->i['identifier_width'] / $bar_count) - $bar_count * 16;
for ($i_o = 0; $i_o < $bar_count; $i_o++) {
$paint_color = $this->get_paint_color(isset($this->graph_data_title[$i_o]) ? $this->graph_data_title[$i_o] : null);
for ($i = 0; $i < count($this->graph_data_raw[$i_o]); $i++) {
$run_values_r = pts_strings::colon_explode($this->graph_data_raw[$i_o][$i]);
$start_value = $run_values_r[0];
$end_value = $run_values_r[count($run_values_r) - 1];
$average_value = array_sum($run_values_r) / count($run_values_r);
sort($run_values_r);
$low_value = $run_values_r[0];
$high_value = $run_values_r[count($run_values_r) - 1];
$px_bound_left = $this->i['left_start'] + $this->i['identifier_width'] * $i + $bar_width * $i_o + 8;
$px_bound_center = $px_bound_left + round($bar_width / 2);
$top_diff = $this->i['graph_top_end'] - $this->i['top_start'];
$plot_wick_lowest = $this->i['graph_top_end'] + 1 - round($low_value / $this->i['graph_max_value'] * $top_diff);
$plot_wick_highest = $this->i['graph_top_end'] + 1 - round($high_value / $this->i['graph_max_value'] * $top_diff);
$plot_body_start = $this->i['graph_top_end'] + 1 - round($start_value / $this->i['graph_max_value'] * $top_diff);
$plot_body_end = $this->i['graph_top_end'] + 1 - round($end_value / $this->i['graph_max_value'] * $top_diff);
if ($start_value > $end_value) {
$body_color = self::$c['color']['body'];
$plot_body_high = $plot_body_start;
$plot_body_low = $plot_body_end;
} else {
$body_color = $paint_color;
$plot_body_low = $plot_body_start;
$plot_body_high = $plot_body_end;
}
$this->svg_dom->draw_svg_line($px_bound_center, $plot_wick_lowest, $px_bound_center, $plot_wick_highest, self::$c['color']['body_light'], 1);
$this->svg_dom->add_element('rect', array('x' => $px_bound_left, 'y' => $plot_body_low, 'width' => $bar_width, 'height' => $plot_body_high - $plot_body_low, 'fill' => $body_color, 'stroke' => self::$c['color']['body_light'], 'stroke-width' => 1));
}
}
}
示例8: user_home_directory
public static function user_home_directory()
{
// Gets the system user's home directory
static $userhome = null;
if ($userhome == null) {
if (function_exists('posix_getpwuid') && function_exists('posix_getuid')) {
$userinfo = posix_getpwuid(posix_getuid());
$userhome = $userinfo['dir'];
} else {
if ($home = pts_client::read_env('HOME')) {
$userhome = $home;
} else {
if ($home = pts_client::read_env('HOMEPATH')) {
$userhome = pts_client::read_env('HOMEDRIVE') . $home;
} else {
if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
$userhome = PTS_USER_PATH;
} else {
if (!is_writable('/')) {
echo PHP_EOL . 'ERROR: Cannot find home directory.' . PHP_EOL;
}
$userhome = null;
}
}
}
}
$userhome = pts_strings::add_trailing_slash($userhome);
}
return $userhome;
}
示例9: client_commands_array
public static function client_commands_array()
{
$options = array('Test Installation' => array(), 'Testing' => array(), 'Batch Testing' => array(), 'OpenBenchmarking.org' => array(), 'System' => array(), 'Information' => array(), 'Asset Creation' => array(), 'Result Management' => array(), 'Result Analytics' => array(), 'Other' => array());
foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php_file) {
$option_php = basename($option_php_file, '.php');
$name = str_replace('_', '-', $option_php);
if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'task'))) {
include_once $option_php_file;
$reflect = new ReflectionClass($option_php);
$constants = $reflect->getConstants();
$doc_description = isset($constants['doc_description']) ? constant($option_php . '::doc_description') : 'No summary is available.';
$doc_section = isset($constants['doc_section']) ? constant($option_php . '::doc_section') : 'Other';
$name = isset($constants['doc_use_alias']) ? constant($option_php . '::doc_use_alias') : $name;
$skip = isset($constants['doc_skip']) ? constant($option_php . '::doc_skip') : false;
$doc_args = array();
if ($skip) {
continue;
}
if (method_exists($option_php, 'argument_checks')) {
$doc_args = call_user_func(array($option_php, 'argument_checks'));
}
if (!empty($doc_section) && !isset($options[$doc_section])) {
$options[$doc_section] = array();
}
array_push($options[$doc_section], array($name, $doc_args, $doc_description));
}
}
return $options;
}
示例10: get_package_format
public function get_package_format($distro_package = null, $file_check = null, $arch_specific = null)
{
if (!is_array($arch_specific)) {
$arch_specific = pts_strings::comma_explode($arch_specific);
}
return array('os_package' => $distro_package, 'file_check' => $file_check, 'arch_specific' => $arch_specific);
}
示例11: __pre_run_process
public static function __pre_run_process(&$test_run_manager)
{
if ($test_run_manager->get_file_name() == null) {
return false;
}
self::$result_identifier = $test_run_manager->get_results_identifier();
self::post_to_pushover('Now running ' . self::$result_identifier . ' in ' . $test_run_manager->get_title() . '. Estimated time to completion: ' . pts_strings::format_time($test_run_manager->get_estimated_run_time(), 'SECONDS', true, 60) . '.');
}
示例12: clean_save_name_string
public function clean_save_name_string($input)
{
$input = strtolower($input);
$input = pts_strings::remove_redundant(pts_strings::keep_in_string(str_replace(' ', '-', trim($input)), pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DASH), '-');
if (strlen($input) > 126) {
$input = substr($input, 0, 126);
}
return $input;
}
示例13: get_identifier_base_name
public function get_identifier_base_name()
{
$identifier = basename($this->identifier);
if (($s = strrpos($identifier, '-')) !== false) {
$post_dash = substr($identifier, $s + 1);
// If the version is attached, remove it
if (pts_strings::is_version($post_dash)) {
$identifier = substr($identifier, 0, $s);
}
}
return $identifier;
}
示例14: run
public static function run($r)
{
$options = array();
foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php) {
$name = str_replace('_', '-', basename($option_php, '.php'));
if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'debug', 'task'))) {
array_push($options, $name);
}
}
$is_true = isset($r[0]) && $r[0] == 'TRUE';
echo implode($is_true ? ' ' : PHP_EOL, $options) . ($is_true ? null : PHP_EOL);
}
示例15: __construct
public function __construct($result_file)
{
$result_object = null;
parent::__construct($result_object, $result_file);
// System Identifiers
if ($result_file->is_multi_way_comparison()) {
// Multi way comparisons currently render the overview graph as blank
$this->skip_graph = true;
return;
}
$this->system_identifiers = $result_file->get_system_identifiers();
if (count($this->system_identifiers) < 2) {
// No point in generating this when there is only one identifier
$this->skip_graph = true;
return;
}
$result_objects = array();
$test_titles = array();
foreach ($result_file->get_result_objects() as $result_object) {
if ($result_object->test_profile->get_display_format() == 'BAR_GRAPH') {
array_push($result_objects, $result_object);
array_push($test_titles, $result_object->test_profile->get_title());
foreach ($result_object->test_result_buffer->buffer_items as &$buffer_item) {
pts_arrays::unique_push($this->graph_identifiers, $buffer_item->get_result_identifier());
}
}
}
$result_object_count = count($result_objects);
if ($result_object_count < 3) {
// No point in generating this if there aren't many tests
$this->skip_graph = true;
return;
}
$result_file->override_result_objects($result_objects);
// Test Titles
$this->i['identifier_size'] = 6.5;
$this->i['graph_width'] = 1000;
list($longest_title_width, $longest_title_height) = pts_svg_dom::estimate_text_dimensions(pts_strings::find_longest_string($test_titles), $this->i['identifier_size']);
$this->i['left_start'] += 20;
$this->graphs_per_row = min(count($this->system_identifiers) > 10 ? 6 : 10, floor(($this->i['graph_width'] - $this->i['left_start'] - $this->i['left_end_right']) / ($longest_title_width + 4)));
$this->graph_item_width = floor(($this->i['graph_width'] - $this->i['left_start'] - $this->i['left_end_right']) / $this->graphs_per_row);
$this->graph_row_count = ceil($result_object_count / $this->graphs_per_row);
$this->i['top_start'] += 20 + count($this->system_identifiers) / 3 * $this->i['identifier_size'];
$height = $this->i['top_start'] + $this->graph_row_count * ($this->graph_row_height + 15);
$this->graph_title = $result_file->get_title();
$this->graph_y_title = null;
$this->i['graph_proportion'] = 'HIB';
$this->i['show_background_lines'] = true;
$this->update_graph_dimensions($this->i['graph_width'], $height, true);
$this->result_file = $result_file;
return true;
}