1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace jumper423\decaptcha\services; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class RuCaptchaGrid. |
7
|
|
|
*/ |
8
|
|
|
class RuCaptchaClick extends RuCaptchaGrid |
9
|
|
|
{ |
10
|
|
|
public function init() |
11
|
|
|
{ |
12
|
|
|
parent::init(); |
13
|
|
|
|
14
|
|
|
unset( |
15
|
|
|
$this->paramsNames[static::ACTION_FIELD_RECAPTCHA], |
16
|
|
|
$this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_RECAPTCHA] |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
$this->paramsNames[static::ACTION_FIELD_COORDINATE] = 'coordinatescaptcha'; |
20
|
|
|
|
21
|
|
|
$this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_INSTRUCTIONS][static::PARAM_SLUG_REQUIRE] = false; |
22
|
|
|
$this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_COORDINATE] = [ |
23
|
|
|
static::PARAM_SLUG_DEFAULT => 1, |
24
|
|
|
static::PARAM_SLUG_TYPE => static::PARAM_FIELD_TYPE_INTEGER, |
25
|
|
|
static::PARAM_SLUG_NOTWIKI => true, |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
$this->wiki->setText(['service', 'name'], 'RuCaptcha ClickCaptcha'); |
29
|
|
|
$this->wiki->setText(['recognize', 'price'], [ |
30
|
|
|
'ru' => 'Стоимость 1000 распознаний данной капчи - 70 рублей.', |
31
|
|
|
'en' => 'It costs $1,2 to recognize 1000 CAPTCHAs this way.', |
32
|
|
|
]); |
33
|
|
|
$this->wiki->setText(['recognize', 'desc'], [ |
34
|
|
|
'ru' => 'Распознание любой ClickCaptcha (в том числе и ReCaptcha 2.0). В ответ приходит массив координат, от верхнего левого угла.', |
35
|
|
|
'en' => 'Recognizing any ClickCaptcha (including ReCaptcha 2.0). In response comes an array of coordinates from the top left corner.', |
36
|
|
|
]); |
37
|
|
|
$this->wiki->setText(['recognize', 'data'], [ |
38
|
|
|
static::ACTION_FIELD_INSTRUCTIONS => 'Where\'s the cat?', |
39
|
|
|
]); |
40
|
|
|
$this->wiki->setText(['menu', 'from_service'], [ |
41
|
|
|
RuCaptcha::class, |
42
|
|
|
RuCaptchaInstruction::class, |
43
|
|
|
RuCaptchaGrid::class, |
44
|
|
|
RuCaptchaReCaptcha::class, |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
public function getCode() |
52
|
|
|
{ |
53
|
|
|
$code = parent::getCode(); |
54
|
|
|
$code = explode(':', $code)[1]; |
55
|
|
|
$code = explode(';', $code); |
56
|
|
|
$result = []; |
57
|
|
|
foreach ($code as $row) { |
58
|
|
|
$rowCoord = explode(',', $row); |
59
|
|
|
foreach ($rowCoord as &$rowCoordOne) { |
60
|
|
|
$rowCoordOne = substr($rowCoordOne, 2); |
61
|
|
|
} |
62
|
|
|
$result[] = $rowCoord; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $result; |
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.