TYPO3  7.6
NumberComparator.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Finder\Comparator;
13 
36 {
44  public function __construct($test)
45  {
46  if (!preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
47  throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test));
48  }
49 
50  $target = $matches[2];
51  if (!is_numeric($target)) {
52  throw new \InvalidArgumentException(sprintf('Invalid number "%s".', $target));
53  }
54  if (isset($matches[3])) {
55  // magnitude
56  switch (strtolower($matches[3])) {
57  case 'k':
58  $target *= 1000;
59  break;
60  case 'ki':
61  $target *= 1024;
62  break;
63  case 'm':
64  $target *= 1000000;
65  break;
66  case 'mi':
67  $target *= 1024 * 1024;
68  break;
69  case 'g':
70  $target *= 1000000000;
71  break;
72  case 'gi':
73  $target *= 1024 * 1024 * 1024;
74  break;
75  }
76  }
77 
78  $this->setTarget($target);
79  $this->setOperator(isset($matches[1]) ? $matches[1] : '==');
80  }
81 }