コード例 #1
0
ファイル: Chrome.php プロジェクト: ngnpope/jerity
 /**
  * Sorts the given array by priority and then strips the priority information.
  *
  * @param  &array  $items  The array to sort.
  */
 protected static function sortExternalsByPriority(array &$items)
 {
     uasort($items, function ($a, $b) {
         return Number::intcmp($a['priority'], $b['priority']);
     });
     $items = array_map(function ($a) {
         return $a['attrs'];
     }, $items);
 }
コード例 #2
0
ファイル: Benchmark.php プロジェクト: ngnpope/jerity
 /**
  * Gets information about PHP caching.
  *
  * @return  array  Information about cache.
  */
 protected static function getCacheInfo()
 {
     if (!extension_loaded('apc')) {
         return null;
     }
     if (PHP_SAPI === 'cli' && !ini_get('apc.cli_enabled')) {
         return null;
     }
     if (!function_exists('apc_cache_info')) {
         return null;
     }
     $info = apc_cache_info();
     static $limit = null;
     if (is_null($limit)) {
         $memory = ini_get('apc.shm_size');
         $segments = ini_get('apc.shm_segments');
         $memory = isset($memory) ? $memory : 30;
         $segments = isset($segments) ? $segments : 1;
         $limit = Number::parseBytes($memory * $segments . 'MiB');
     }
     return array('hits' => isset($info['num_hits']) ? $info['num_hits'] : null, 'misses' => isset($info['num_misses']) ? $info['num_misses'] : null, 'memory_used' => isset($info['mem_size']) ? $info['mem_size'] : null, 'memory_limit' => $limit);
 }
コード例 #3
0
ファイル: NumberTest.php プロジェクト: ngnpope/jerity
 /**
  * @dataProvider  parseBytesExceptionProvider
  */
 public function testParseBytesException($a, $b, $c)
 {
     $this->setExpectedException($c);
     Number::parseBytes($a, $b);
 }
コード例 #4
0
ファイル: String.php プロジェクト: ngnpope/jerity
 /**
  * Converts the value provided into a formatted string specifying the value 
  * in the desired multiples of bytes or bits.
  *
  * To force a specific prefix to be returned, and because they vary depending
  * on whether SI units are used or not, the $prefix parameter must be one of 
  * the following values: '', 'K', 'M', 'G', 'T', 'P', 'E', 'Z'.
  *
  * @param  bool    $bytes   Whether to format as bytes or bits.
  * @param  mixed   $n       The value to format.
  * @param  bool    $si      Whether to output SI units.
  * @param  int     $dp      How many decimal places to output.
  * @param  string  $prefix  Force a prefix, e.g. 'K', 'M' (null = automatic)
  * @param  bool    $symbol  Whether to output symbols or names of unit.
  *
  * @return  string  The formatted byte value.
  */
 protected static function formatBytesOrBits($bytes, $n, $si = false, $dp = 0, $prefix = null, $symbol = true)
 {
     $s = '';
     $exponent = null;
     # Parse the value provided first.
     $n = $bytes ? Number::parseBytes($n) : Number::parseBits($n);
     # Check decimal place is valid.
     $dp = min(max(0, $dp), ini_get('precision'));
     # Get unit prefix list.
     $prefixes = $si ? $symbol ? Number::$SI_PREFIX_SYMBOL : Number::$SI_PREFIX_NAME : ($symbol ? Number::$IEC_PREFIX_SYMBOL : Number::$IEC_PREFIX_NAME);
     # Get unit postfix.
     $postfix = $bytes ? $symbol ? 'B' : 'byte' : ($symbol ? 'b' : 'bit');
     # Determine whether to automatically determine the prefix.
     if (!is_null($prefix)) {
         $exponent = array_search(strtoupper($prefix), array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z'));
         if ($exponent === false) {
             $exponent = null;
             # Invalid, so just automatically choose.
         }
     }
     # Calculate the correct numeric value.
     $base = $si ? 1000 : 1024;
     if (!is_null($exponent)) {
         $n /= pow($base, $exponent);
     } else {
         $exponent = 0;
         while ($n >= $base && $exponent < count($prefixes) - 1) {
             $n /= $base;
             $exponent++;
         }
     }
     # Generate string.
     $n = number_format($n, $dp, nl_langinfo(RADIXCHAR), nl_langinfo(THOUSEP));
     $s = sprintf('%s %s', $n, $prefixes[$exponent] . $postfix);
     if (!$symbol) {
         $s = self::pluralize($s);
     }
     return $s;
 }