diff options
Diffstat (limited to 'src/NeonXP/DozorApi.php')
-rw-r--r-- | src/NeonXP/DozorApi.php | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/src/NeonXP/DozorApi.php b/src/NeonXP/DozorApi.php index da724a9..4865e96 100644 --- a/src/NeonXP/DozorApi.php +++ b/src/NeonXP/DozorApi.php @@ -2,16 +2,15 @@ /** * @author Alexander "NeonXP" Kiryukhin */ + namespace NeonXP; + use Doctrine\Common\Cache\CacheProvider; use NeonXP\TelegramApi\Types\Chat; -use Symfony\Component\CssSelector\Node\AbstractNode; use Symfony\Component\DomCrawler\Crawler; - /** - * Class DozorApi - * @package NeonXP + * Class DozorApi. */ class DozorApi { @@ -22,6 +21,7 @@ class DozorApi /** * DozorApi constructor. + * * @param CacheProvider $cache */ public function __construct(CacheProvider $cache) @@ -32,31 +32,35 @@ class DozorApi public function sendCode(Chat $chat, $code) { $params = [ - "log" => 'on', - "mes" => '', - "legend" => 'on', - "nostat" => '', - "notext" => '', - "refresh" => '0', - "bonus" => '', - "kladMap" => '', - "notags" => '', - "cod" => $code, - "action" => 'entcod', + 'log' => 'on', + 'mes' => '', + 'legend' => 'on', + 'nostat' => '', + 'notext' => '', + 'refresh' => '0', + 'bonus' => '', + 'kladMap' => '', + 'notags' => '', + 'cod' => $code, + 'action' => 'entcod', ]; $data = http_build_query($params); $contextData = [ 'http' => [ 'method' => 'POST', - 'header' => 'Content-type: application/x-www-form-urlencoded', - 'content' => $data - ] + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => $data, + ], ]; $context = stream_context_create($contextData); + if (!$this->getLink($chat)) { + throw new \Exception('Не задана ссылка'); + } $result = file_get_contents($this->getLink($chat), false, $context); $contextData['result'] = $result; - file_put_contents(getenv('OPENSHIFT_DATA_DIR') . 'log.txt', serialize($contextData)); + file_put_contents(getenv('OPENSHIFT_DATA_DIR').'log.txt', serialize($contextData)); + return $this->parseResult($result); } @@ -66,7 +70,7 @@ class DozorApi $answer = [ $this->parseCodeEnter($html), - $this->parseTask($crawler) + $this->parseTask($crawler), ]; $answer = array_merge($answer, $this->parseCodes($crawler)); @@ -78,9 +82,10 @@ class DozorApi private function parseCodeEnter($html) { $html = iconv('cp1251', 'utf8', $html); - $regex = '/\<\!\-\-errorText\-\-\>\<p\>\<strong\>(.+?)\<\/strong\>\<\/p\>\<\!\-\-errorTextEnd\-\-\>'; + $regex = '/\<\!\-\-errorText\-\-\>\<p\>\<strong\>(.+?)\<\/strong\>\<\/p\>\<\!\-\-errorTextEnd\-\-\>/i'; $result = []; preg_match($regex, $html, $result); + return $result[1]; } |