diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
commit | 4f5b44bd3bd490309eb2ba7b44df4769816ba729 (patch) | |
tree | 6cefe170dfe0a5a361cb1e2d1fc4d580a3316d02 /vendor/symfony/form/Symfony/Component/Form/Guess/Guess.php | |
parent | 2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff) | |
download | wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip |
twig implementation
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Guess/Guess.php')
-rw-r--r-- | vendor/symfony/form/Symfony/Component/Form/Guess/Guess.php | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Guess/Guess.php b/vendor/symfony/form/Symfony/Component/Form/Guess/Guess.php new file mode 100644 index 00000000..b33c3d80 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Guess/Guess.php | |||
@@ -0,0 +1,113 @@ | |||
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\Form\Guess; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\InvalidArgumentException; | ||
15 | |||
16 | /** | ||
17 | * Base class for guesses made by TypeGuesserInterface implementation | ||
18 | * | ||
19 | * Each instance contains a confidence value about the correctness of the guess. | ||
20 | * Thus an instance with confidence HIGH_CONFIDENCE is more likely to be | ||
21 | * correct than an instance with confidence LOW_CONFIDENCE. | ||
22 | * | ||
23 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
24 | */ | ||
25 | abstract class Guess | ||
26 | { | ||
27 | /** | ||
28 | * Marks an instance with a value that is extremely likely to be correct | ||
29 | * @var integer | ||
30 | */ | ||
31 | const VERY_HIGH_CONFIDENCE = 3; | ||
32 | |||
33 | /** | ||
34 | * Marks an instance with a value that is very likely to be correct | ||
35 | * @var integer | ||
36 | */ | ||
37 | const HIGH_CONFIDENCE = 2; | ||
38 | |||
39 | /** | ||
40 | * Marks an instance with a value that is likely to be correct | ||
41 | * @var integer | ||
42 | */ | ||
43 | const MEDIUM_CONFIDENCE = 1; | ||
44 | |||
45 | /** | ||
46 | * Marks an instance with a value that may be correct | ||
47 | * @var integer | ||
48 | */ | ||
49 | const LOW_CONFIDENCE = 0; | ||
50 | |||
51 | /** | ||
52 | * The confidence about the correctness of the value | ||
53 | * | ||
54 | * One of VERY_HIGH_CONFIDENCE, HIGH_CONFIDENCE, MEDIUM_CONFIDENCE | ||
55 | * and LOW_CONFIDENCE. | ||
56 | * | ||
57 | * @var integer | ||
58 | */ | ||
59 | private $confidence; | ||
60 | |||
61 | /** | ||
62 | * Returns the guess most likely to be correct from a list of guesses | ||
63 | * | ||
64 | * If there are multiple guesses with the same, highest confidence, the | ||
65 | * returned guess is any of them. | ||
66 | * | ||
67 | * @param array $guesses A list of guesses | ||
68 | * | ||
69 | * @return Guess The guess with the highest confidence | ||
70 | */ | ||
71 | public static function getBestGuess(array $guesses) | ||
72 | { | ||
73 | $result = null; | ||
74 | $maxConfidence = -1; | ||
75 | |||
76 | foreach ($guesses as $guess) { | ||
77 | if ($maxConfidence < $confidence = $guess->getConfidence()) { | ||
78 | $maxConfidence = $confidence; | ||
79 | $result = $guess; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | return $result; | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * Constructor | ||
88 | * | ||
89 | * @param integer $confidence The confidence | ||
90 | * | ||
91 | * @throws InvalidArgumentException if the given value of confidence is unknown | ||
92 | */ | ||
93 | public function __construct($confidence) | ||
94 | { | ||
95 | if (self::VERY_HIGH_CONFIDENCE !== $confidence && self::HIGH_CONFIDENCE !== $confidence && | ||
96 | self::MEDIUM_CONFIDENCE !== $confidence && self::LOW_CONFIDENCE !== $confidence) { | ||
97 | throw new InvalidArgumentException('The confidence should be one of the constants defined in Guess.'); | ||
98 | } | ||
99 | |||
100 | $this->confidence = $confidence; | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * Returns the confidence that the guessed value is correct | ||
105 | * | ||
106 | * @return integer One of the constants VERY_HIGH_CONFIDENCE, | ||
107 | * HIGH_CONFIDENCE, MEDIUM_CONFIDENCE and LOW_CONFIDENCE | ||
108 | */ | ||
109 | public function getConfidence() | ||
110 | { | ||
111 | return $this->confidence; | ||
112 | } | ||
113 | } | ||