File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
14
14
### Changed
15
15
- Switched to v3 API which uses updated language detection model
16
- - ⚠️ ` simpleDetect ` method renamed to ` detectCode `
17
16
- ⚠️ ` detect ` method result fields are ` language ` and ` score `
18
- - ⚠️ ` detect ` method no longer accept arrays - use ` detectBatch ` instead
19
- - HTTPS is used by default. Removed secure mode configuration.
17
+ - ⚠️ ` simpleDetect ` deprecated, use ` detectCode ` instead
18
+ - ⚠️ ` detect ` for batch detection is deprecated, use ` detectBatch ` instead
19
+
20
+ ### Removed
21
+ - Secure mode configuration. HTTPS is always used.
Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ public static function setApiKey($apiKey)
59
59
public static function detect ($ text )
60
60
{
61
61
if (is_array ($ text )) {
62
- throw new Error ('detect method does not accept arrays, use detectBatch instead ' );
62
+ trigger_error ('detect method does not accept arrays, use detectBatch instead ' , E_USER_DEPRECATED );
63
+ return self ::detectBatch ($ text );
63
64
}
64
65
65
66
return Client::request ('POST ' , 'detect ' , array ('q ' => $ text ));
@@ -115,4 +116,17 @@ public static function getLanguages()
115
116
{
116
117
return Client::request ('GET ' , 'languages ' );
117
118
}
119
+
120
+ // DEPRECATED METHODS
121
+
122
+ /**
123
+ * @deprecated use self::detectCode instead
124
+ * @param string $text The text for language detection
125
+ * @return string|null detected language code
126
+ */
127
+ public static function simpleDetect ($ text )
128
+ {
129
+ trigger_error ('simpleDetect method is deprecated, use detectCode instead ' , E_USER_DEPRECATED );
130
+ return self ::detectCode ($ text );
131
+ }
118
132
}
Original file line number Diff line number Diff line change @@ -38,8 +38,10 @@ public function testDetect()
38
38
39
39
public function testDetectWithArray ()
40
40
{
41
- $ this ->expectException ('\DetectLanguage\Error ' );
42
41
$ result = DetectLanguage::detect (array ('Hello world ' ));
42
+
43
+ $ this ->assertEquals ('en ' , $ result [0 ][0 ]->language ,
44
+ 'To detect English language. ' );
43
45
}
44
46
45
47
public function testDetectCode ()
@@ -50,6 +52,13 @@ public function testDetectCode()
50
52
'To detect English language. ' );
51
53
}
52
54
55
+ public function testSimpleDetect ()
56
+ {
57
+ $ result = DetectLanguage::simpleDetect ('Hello world ' );
58
+ $ this ->assertEquals ('en ' , $ result ,
59
+ 'To detect English language. ' );
60
+ }
61
+
53
62
public function testCurlRequest ()
54
63
{
55
64
$ this ->setRequestEngine ('curl ' );
You can’t perform that action at this time.
0 commit comments