Guest User

Untitled

a guest
May 9th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.03 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.1.0.1
  8. * @ Author : DeZender
  9. * @ Release on : 29.08.2020
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class ShCommon
  15. {
  16. /**
  17. * @var string имя библиотеки
  18. */
  19. static protected $libName;
  20. /**
  21. * @var string путь к серверу с обновлениями
  22. */
  23. static protected $apiUrl = 'https://dev.shahfil.com/scripts/update.php';
  24.  
  25. /**
  26. * Инициализация модуля
  27. *
  28. * @return void
  29. */
  30. static public function init()
  31. {
  32. $updateDiff = static::getLibraryTimeFromUpdate();
  33.  
  34. if (86400 < $updateDiff) {
  35. static::sendVersionToServer();
  36. @touch(__FILE__);
  37. }
  38.  
  39. $buildDiff = static::getLibraryTimeFromBuild();
  40.  
  41. if (7776000 < $buildDiff) {
  42. static::updateLibrary();
  43. return NULL;
  44. }
  45.  
  46. $sapiName = php_sapi_name();
  47.  
  48. if ($sapiName == 'cli') {
  49. $runName = (empty($_SERVER['argv'][0]) ? __FILE__ : $_SERVER['argv'][0]);
  50. $runName = basename($runName);
  51.  
  52. if ($runName == 'tmpupd.php') {
  53. static::cmdVersion();
  54. exit();
  55. }
  56.  
  57. $cmd = (empty($_SERVER['argv'][1]) ? 'none' : $_SERVER['argv'][1]);
  58.  
  59. if ($cmd == 'version') {
  60. static::cmdVersion();
  61. exit();
  62. }
  63. else if ($cmd == 'update') {
  64. static::cmdUpdate();
  65. exit();
  66. }
  67. }
  68.  
  69. if (!empty($_GET['libcmd'])) {
  70. $cmd = urldecode($_GET['libcmd']);
  71.  
  72. switch ($cmd) {
  73. case 'version':
  74. static::cmdVersion();
  75. exit();
  76. case 'update':
  77. static::cmdUpdate();
  78. exit();
  79. }
  80. }
  81.  
  82. return NULL;
  83. }
  84.  
  85. /**
  86. * Имя текущей библиотеки
  87. *
  88. * @return string
  89. */
  90. static public function getLibraryName()
  91. {
  92. if (isset(static::$libName)) {
  93. return static::$libName;
  94. }
  95.  
  96. if (defined('SHLIBRARYNAME')) {
  97. static::$libName = SHLIBRARYNAME;
  98. }
  99. else if (class_exists('SmartApp')) {
  100. static::$libName = 'smartlib';
  101. }
  102. else if (defined('CJLIBVERSION')) {
  103. static::$libName = 'cjlibs';
  104. }
  105. else {
  106. static::$libName = 'unknown_' . basename(__FILE__);
  107. }
  108.  
  109. return static::$libName;
  110. }
  111.  
  112. /**
  113. * Версия библиотеки
  114. *
  115. * @return string
  116. */
  117. static public function getLibraryVersion()
  118. {
  119. $version = '1.5.7';
  120.  
  121. if (strpos($version, '}')) {
  122. $version = '0.0.0';
  123. }
  124.  
  125. return $version;
  126. }
  127.  
  128. /**
  129. * Версия библиотеки на сервере
  130. *
  131. * @return string
  132. */
  133. static public function getServerVersion()
  134. {
  135. $libraryName = static::getLibraryName();
  136. $host = (empty($_SERVER['HTTP_HOST']) ? php_sapi_name() : $_SERVER['HTTP_HOST']);
  137. $host = str_replace('www.', '', $host);
  138. $version = static::getLibraryVersion();
  139. $buildTime = static::getLibraryBuildTime();
  140. $apiLink = static::$apiUrl . '?cmd=version' . '&lib=' . $libraryName . '&version=' . $version . '&host=' . urlencode($host) . '&buildtime=' . $buildTime;
  141. $ch = curl_init();
  142. curl_setopt($ch, CURLOPT_URL, $apiLink);
  143. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  144. curl_setopt($ch, CURLOPT_HEADER, false);
  145. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  146. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  147. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  148. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  149. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
  150. curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  151. $html = curl_exec($ch);
  152. preg_match('|<version>([\\d\\.]+)</version>|', $html, $match);
  153.  
  154. if (empty($match[1])) {
  155. return '0.0.0';
  156. }
  157.  
  158. $serverVersion = $match[1];
  159. return $serverVersion;
  160. }
  161.  
  162. /**
  163. * Проверка на наличие новой версии
  164. *
  165. * @return boolean
  166. */
  167. static public function needUpdate()
  168. {
  169. $currentVersion = static::getLibraryVersion();
  170. $serverVersion = static::getServerVersion();
  171.  
  172. if ($serverVersion == '0.0.0') {
  173. return false;
  174. }
  175.  
  176. if ($currentVersion == $serverVersion) {
  177. return false;
  178. }
  179.  
  180. return true;
  181. }
  182.  
  183. /**
  184. * Время сборки библиотеки
  185. *
  186. * @return integer
  187. */
  188. static public function getLibraryBuildTime()
  189. {
  190. $buildTime = '1620379532';
  191.  
  192. if (strpos($buildTime, '}')) {
  193. $buildTime = date('U');
  194. }
  195.  
  196. $buildTime = intval($buildTime);
  197. return $buildTime;
  198. }
  199.  
  200. /**
  201. * Время до которого библиотека актуальна
  202. *
  203. * @return integer
  204. */
  205. static public function getLibraryExpiryTime()
  206. {
  207. $expireTime = '0';
  208.  
  209. if (strpos($expireTime, '}')) {
  210. $expireTime = 0;
  211. }
  212.  
  213. $expireTime = intval($expireTime);
  214. return $expireTime;
  215. }
  216.  
  217. /**
  218. * Количество дней до окончания работы
  219. *
  220. * @return integer
  221. */
  222. static public function getExpiryDays()
  223. {
  224. $expireTime = static::getLibraryExpiryTime();
  225.  
  226. if (empty($expireTime)) {
  227. return 999;
  228. }
  229.  
  230. $currentTime = date('U');
  231. $expireDiff = ceil(($expireTime - $currentTime) / 24 / 60 / 60);
  232. return $expireDiff;
  233. }
  234.  
  235. /**
  236. * Количество дней с момента сборки
  237. *
  238. * @return integer
  239. */
  240. static public function getLibraryTimeFromBuild()
  241. {
  242. $buildTime = static::getLibraryBuildTime();
  243. $currentTime = date('U');
  244. $buildDiff = $currentTime - $buildTime;
  245. return $buildDiff;
  246. }
  247.  
  248. /**
  249. * Количество дней с момента обновления
  250. *
  251. * @return integer
  252. */
  253. static public function getLibraryTimeFromUpdate()
  254. {
  255. $updateTime = filemtime(__FILE__);
  256.  
  257. if (false === $updateTime) {
  258. $updateTime = date('U');
  259. }
  260.  
  261. $currentTime = date('U');
  262. $buildDiff = $currentTime - $updateTime;
  263. return $buildDiff;
  264. }
  265.  
  266. /**
  267. * Отметка на сервере о текущей версии
  268. *
  269. * @return void
  270. */
  271. static public function sendVersionToServer()
  272. {
  273. $libraryName = static::getLibraryName();
  274. $host = (empty($_SERVER['HTTP_HOST']) ? 'localhost' : $_SERVER['HTTP_HOST']);
  275. $host = str_replace('www.', '', $host);
  276. $i = strpos($host, ':');
  277.  
  278. if (0 < $i) {
  279. $host = substr($host, 0, $i);
  280. }
  281.  
  282. $version = static::getLibraryVersion();
  283. $buildTime = static::getLibraryBuildTime();
  284. $expireTime = static::getLibraryExpiryTime();
  285. $apiLink = static::$apiUrl . '?cmd=touch' . '&lib=' . $libraryName . '&version=' . $version . '&host=' . $host . '&buildtime=' . $buildTime . '&expiretime=' . $expireTime;
  286. $ch = curl_init();
  287. curl_setopt($ch, CURLOPT_URL, $apiLink);
  288. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  289. curl_setopt($ch, CURLOPT_HEADER, false);
  290. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  291. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  292. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  293. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  294. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
  295. curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  296. $html = curl_exec($ch);
  297. return NULL;
  298. }
  299.  
  300. /**
  301. * Обновление библиотеки с сервера
  302. *
  303. * @return void
  304. */
  305. static public function updateLibrary()
  306. {
  307. $libraryName = static::getLibraryName();
  308. $host = (empty($_SERVER['HTTP_HOST']) ? 'localhost' : $_SERVER['HTTP_HOST']);
  309. $host = str_replace('www.', '', $host);
  310. $version = static::getLibraryVersion();
  311. $buildTime = static::getLibraryBuildTime();
  312. $apiLink = static::$apiUrl . '?cmd=get' . '&lib=' . $libraryName . '&version=' . $version . '&host=' . $host . '&buildtime=' . $buildTime;
  313. $updatedFile = file_get_contents($apiLink);
  314. $i = strpos($updatedFile, '<!-- start file: ');
  315.  
  316. if ($i < 1) {
  317. return false;
  318. }
  319.  
  320. preg_match('|crc: ([\\d\\w]+) --/>|', $updatedFile, $match);
  321.  
  322. if (empty($match[1])) {
  323. return false;
  324. }
  325.  
  326. $serverCrc = $match[1];
  327. $updatedFile = substr($updatedFile, $i);
  328. $i = strpos($updatedFile, '--/>');
  329. $updatedFile = substr($updatedFile, $i + 4);
  330. $i = strpos($updatedFile, '<!-- end file');
  331.  
  332. if ($i < 1) {
  333. return false;
  334. }
  335.  
  336. $updatedFile = substr($updatedFile, 0, $i);
  337. $updatedFile = trim($updatedFile);
  338. $updatedFile = base64_decode($updatedFile);
  339. $loadCrc = md5($updatedFile);
  340.  
  341. if ($serverCrc != $loadCrc) {
  342. return false;
  343. }
  344.  
  345. $serverVersion = static::getServerVersion();
  346. $tmpFile = __DIR__ . '/tmpupd.php';
  347.  
  348. if (!is_writable(__FILE__)) {
  349. return false;
  350. }
  351.  
  352. if (file_exists($tmpFile)) {
  353. $updateTime = filemtime($tmpFile);
  354. $nowTime = date('U');
  355.  
  356. if (($nowTime - $updateTime) < 600) {
  357. return false;
  358. }
  359. }
  360.  
  361. file_put_contents($tmpFile, $updatedFile);
  362. $output = shell_exec('php ' . $tmpFile . ' version 2>&1');
  363.  
  364. if (strpos($output, 'error')) {
  365. @unlink($tmpFile);
  366. return false;
  367. }
  368.  
  369. if (!strpos($output, $serverVersion)) {
  370. @unlink($tmpFile);
  371. return false;
  372. }
  373.  
  374. @unlink(__FILE__ . '.bak');
  375. rename(__FILE__, __FILE__ . '.bak');
  376. rename($tmpFile, __FILE__);
  377. return true;
  378. }
  379.  
  380. /**
  381. * Команда вывода версии
  382. */
  383. static protected function cmdVersion()
  384. {
  385. echo '<library>' . static::getLibraryName() . '</library>' . "\n";
  386. echo '<version>' . static::getLibraryVersion() . '</version>' . "\n";
  387. echo '<build>' . static::getLibraryBuildTime() . '</build>' . "\n";
  388. $expireTime = static::getLibraryExpiryTime();
  389.  
  390. if (!empty($expireTime)) {
  391. echo '<expire>' . $expireTime . '</expire>' . "\n";
  392. echo '<expiredays>' . static::getExpiryDays() . '</expiredays>' . "\n";
  393. }
  394.  
  395. return NULL;
  396. }
  397.  
  398. /**
  399. * Команда обновления
  400. */
  401. static protected function cmdUpdate()
  402. {
  403. echo 'Module: ' . static::getLibraryName() . ' <br />' . "\n";
  404. echo 'Current version: ' . static::getLibraryVersion() . ' <br />' . "\n";
  405. echo 'Latest version: ' . static::getServerVersion() . ' <br />' . "\n";
  406.  
  407. if (!static::needUpdate()) {
  408. return NULL;
  409. }
  410.  
  411. echo 'Updating... ';
  412. $res = static::updateLibrary();
  413.  
  414. if ($res) {
  415. echo 'done. <br />' . "\n";
  416. }
  417. else {
  418. echo 'failed. <br />' . "\n";
  419. }
  420.  
  421. return NULL;
  422. }
  423.  
  424. /**
  425. * Отправка сообщения в телешрам
  426. */
  427. static public function sendToTelegram($msg, $chatID = '33043900')
  428. {
  429. $apiKey = '610297819:AAFFwG-sdkPnu81Kz-ti7CrkRY7ljW8JP_I';
  430. $msg = urlencode($msg);
  431. $apiUrl = 'https://api.telegram.org/bot' . $apiKey . '/sendMessage?chat_id=' . $chatID . '&text=' . $msg;
  432. $ch = curl_init();
  433. curl_setopt($ch, CURLOPT_URL, $apiUrl);
  434. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  435. $output = curl_exec($ch);
  436. curl_close($ch);
  437. return NULL;
  438. }
  439. }
  440.  
  441. abstract class AbstractChannel
  442. {
  443. const PROTOCOL_080 = '0.8';
  444. const PROTOCOL_091 = '0.9.1';
  445.  
  446. static public $PROTOCOL_CONSTANTS_CLASS;
  447. /** @var array */
  448. protected $frame_queue;
  449. /** @var array */
  450. protected $method_queue;
  451. /** @var bool */
  452. protected $auto_decode;
  453. /** @var string */
  454. protected $amqp_protocol_header;
  455. /** @var \PhpAmqpLib\Helper\DebugHelper */
  456. protected $debug;
  457. /** @var \PhpAmqpLib\Connection\AbstractConnection */
  458. protected $connection;
  459. /** @var string */
  460. protected $protocolVersion;
  461. /** @var int */
  462. protected $maxBodySize;
  463. /** @var \PhpAmqpLib\Helper\Protocol\Protocol080|\PhpAmqpLib\Helper\Protocol\Protocol091 */
  464. protected $protocolWriter;
  465. /** @var \PhpAmqpLib\Helper\Protocol\Wait080|\PhpAmqpLib\Helper\Protocol\Wait091 */
  466. protected $waitHelper;
  467. /** @var \PhpAmqpLib\Helper\Protocol\MethodMap080|\PhpAmqpLib\Helper\Protocol\MethodMap091 */
  468. protected $methodMap;
  469. /** @var string */
  470. protected $channel_id;
  471. /** @var \PhpAmqpLib\Wire\AMQPReader */
  472. protected $msg_property_reader;
  473. /** @var \PhpAmqpLib\Wire\AMQPReader */
  474. protected $wait_content_reader;
  475. /** @var \PhpAmqpLib\Wire\AMQPReader */
  476. protected $dispatch_reader;
  477.  
  478. /**
  479. * @param AbstractConnection $connection
  480. * @param string $channel_id
  481. * @throws AMQPRuntimeException
  482. */
  483. public function __construct(AbstractConnection $connection, $channel_id)
  484. {
  485. $this->connection = $connection;
  486. $this->channel_id = $channel_id;
  487. $connection->channels[$channel_id] = $this;
  488. $this->frame_queue = [];
  489. $this->method_queue = [];
  490. $this->auto_decode = false;
  491. $this->msg_property_reader = new AMQPReader(NULL);
  492. $this->wait_content_reader = new AMQPReader(NULL);
  493. $this->dispatch_reader = new AMQPReader(NULL);
  494. $this->protocolVersion = self::getProtocolVersion();
  495.  
  496. switch ($this->protocolVersion) {
  497. case '0.9.1':
  498. self::$PROTOCOL_CONSTANTS_CLASS = 'Constants091';
  499. $c = self::$PROTOCOL_CONSTANTS_CLASS;
  500. $this->debug = new DebugHelper($c);
  501. $this->amqp_protocol_header = $c::$AMQP_PROTOCOL_HEADER;
  502. $this->protocolWriter = new Protocol091();
  503. $this->waitHelper = new Wait091();
  504. $this->methodMap = new MethodMap091();
  505. break;
  506. case '0.8':
  507. self::$PROTOCOL_CONSTANTS_CLASS = 'Constants080';
  508. $c = self::$PROTOCOL_CONSTANTS_CLASS;
  509. $this->debug = new DebugHelper($c);
  510. $this->amqp_protocol_header = $c::$AMQP_PROTOCOL_HEADER;
  511. $this->protocolWriter = new Protocol080();
  512. $this->waitHelper = new Wait080();
  513. $this->methodMap = new MethodMap080();
  514. break;
  515. default:
  516. throw new AMQPNotImplementedException(sprintf('Protocol: %s not implemented.', $this->protocolVersion));
  517. }
  518. }
  519.  
  520. /**
  521. * @return string
  522. * @throws AMQPOutOfRangeException
  523. */
  524. static public function getProtocolVersion()
  525. {
  526. $protocol = (defined('AMQP_PROTOCOL') ? AMQP_PROTOCOL : '0.9.1');
  527.  
  528. if (!in_array($protocol, ['0.8', '0.9.1'], true)) {
  529. throw new AMQPOutOfRangeException(sprintf('Protocol version %s not implemented.', $protocol));
  530. }
  531.  
  532. return $protocol;
  533. }
  534.  
  535. /**
  536. * @return string
  537. */
  538. public function getChannelId()
  539. {
  540. return $this->channel_id;
  541. }
  542.  
  543. /**
  544. * @param int $max_bytes Max message body size for this channel
  545. * @return $this
  546. */
  547. public function setBodySizeLimit($max_bytes)
  548. {
  549. $max_bytes = (int) $max_bytes;
  550.  
  551. if (0 < $max_bytes) {
  552. $this->maxBodySize = $max_bytes;
  553. }
  554.  
  555. return $this;
  556. }
  557.  
  558. /**
  559. * @return AbstractConnection
  560. */
  561. public function getConnection()
  562. {
  563. return $this->connection;
  564. }
  565.  
  566. /**
  567. * @return array
  568. */
  569. public function getMethodQueue()
  570. {
  571. return $this->method_queue;
  572. }
  573.  
  574. /**
  575. * @return bool
  576. */
  577. public function hasPendingMethods()
  578. {
  579. return !empty($this->method_queue);
  580. }
  581.  
  582. /**
  583. * @param string $method_sig
  584. * @param string $args
  585. * @param AMQPMessage|null $amqpMessage
  586. * @return mixed
  587. * @throws AMQPRuntimeException
  588. */
  589. public function dispatch($method_sig, $args, $amqpMessage)
  590. {
  591. if (!$this->methodMap->valid_method($method_sig)) {
  592. throw new AMQPNotImplementedException(sprintf('Unknown AMQP method "%s"', $method_sig));
  593. }
  594.  
  595. $amqp_method = $this->methodMap->get_method($method_sig);
  596.  
  597. if (!method_exists($this, $amqp_method)) {
  598. throw new AMQPNotImplementedException(sprintf('Method: "%s" not implemented by class: %s', $amqp_method, get_class($this)));
  599. }
  600.  
  601. $this->dispatch_reader->reuse($args);
  602.  
  603. if ($amqpMessage == NULL) {
  604. return call_user_func([$this, $amqp_method], $this->dispatch_reader);
  605. }
  606.  
  607. return call_user_func([$this, $amqp_method], $this->dispatch_reader, $amqpMessage);
  608. }
  609.  
  610. /**
  611. * @param int|float|null $timeout
  612. * @return array|mixed
  613. */
  614. public function next_frame($timeout = 0)
  615. {
  616. $this->debug->debug_msg('waiting for a new frame');
  617.  
  618. if (!empty($this->frame_queue)) {
  619. return array_shift($this->frame_queue);
  620. }
  621.  
  622. return $this->connection->wait_channel($this->channel_id, $timeout);
  623. }
  624.  
  625. /**
  626. * @param array $method_sig
  627. * @param AMQPWriter|string $args
  628. */
  629. protected function send_method_frame($method_sig, $args = '')
  630. {
  631. if ($this->connection === NULL) {
  632. throw new AMQPChannelClosedException('Channel connection is closed.');
  633. }
  634.  
  635. $this->connection->send_channel_method_frame($this->channel_id, $method_sig, $args);
  636. }
  637.  
  638. /**
  639. * This is here for performance reasons to batch calls to fwrite from basic.publish
  640. *
  641. * @param array $method_sig
  642. * @param AMQPWriter|string $args
  643. * @param AMQPWriter $pkt
  644. * @return AMQPWriter
  645. */
  646. protected function prepare_method_frame($method_sig, $args = '', $pkt = NULL)
  647. {
  648. return $this->connection->prepare_channel_method_frame($this->channel_id, $method_sig, $args, $pkt);
  649. }
  650.  
  651. /**
  652. * @return AMQPMessage
  653. * @throws AMQPRuntimeException
  654. */
  655. public function wait_content()
  656. {
  657. list($frame_type, $payload) = $this->next_frame();
  658. $this->validate_header_frame($frame_type);
  659. $this->wait_content_reader->reuse(mb_substr($payload, 0, 12, 'ASCII'));
  660. $class_id = $this->wait_content_reader->read_short();
  661. $weight = $this->wait_content_reader->read_short();
  662. $this->msg_property_reader->reuse(mb_substr($payload, 12, mb_strlen($payload, 'ASCII') - 12, 'ASCII'));
  663. return $this->createMessage($this->msg_property_reader, $this->wait_content_reader);
  664. }
  665.  
  666. /**
  667. * @param AMQPReader $propertyReader
  668. * @param AMQPReader $contentReader
  669. * @return AMQPMessage
  670. */
  671. protected function createMessage($propertyReader, $contentReader)
  672. {
  673. $bodyChunks = [];
  674. $bodyReceivedBytes = 0;
  675. $message = new AMQPMessage();
  676. $message->load_properties($propertyReader)->setBodySize($contentReader->read_longlong());
  677.  
  678. while (bccomp($message->getBodySize(), $bodyReceivedBytes, 0) == 1) {
  679. list($frame_type, $payload) = $this->next_frame();
  680. $this->validate_body_frame($frame_type);
  681. $bodyReceivedBytes = bcadd($bodyReceivedBytes, mb_strlen($payload, 'ASCII'), 0);
  682. if (is_int($this->maxBodySize) && ($this->maxBodySize < $bodyReceivedBytes)) {
  683. $message->setIsTruncated(true);
  684. continue;
  685. }
  686.  
  687. $bodyChunks[] = $payload;
  688. }
  689.  
  690. $message->setBody(implode('', $bodyChunks));
  691. return $message;
  692. }
  693.  
  694. /**
  695. * Wait for some expected AMQP methods and dispatch to them.
  696. * Unexpected methods are queued up for later calls to this PHP
  697. * method.
  698. *
  699. * @param array $allowed_methods
  700. * @param bool $non_blocking
  701. * @param int|float|null $timeout
  702. * @return mixed
  703. * @throws AMQPRuntimeException
  704. * @throws AMQPTimeoutException
  705. * @throws \ErrorException
  706. * @throws AMQPOutOfBoundsException
  707. */
  708. public function wait($allowed_methods = NULL, $non_blocking = false, $timeout = 0)
  709. {
  710. $this->debug->debug_allowed_methods($allowed_methods);
  711. $deferred = $this->process_deferred_methods($allowed_methods);
  712.  
  713. if ($deferred['dispatch'] === true) {
  714. return $this->dispatch_deferred_method($deferred['queued_method']);
  715. }
  716.  
  717. if (true === $non_blocking) {
  718. $timeout = NULL;
  719. }
  720.  
  721. while (true) {
  722. try {
  723. list($frame_type, $payload) = $this->next_frame($timeout);
  724. }
  725. catch (AMQPNoDataException $e) {
  726. break;
  727. }
  728.  
  729. $this->validate_method_frame($frame_type);
  730. $this->validate_frame_payload($payload);
  731. $method_sig = $this->build_method_signature($payload);
  732. $args = $this->extract_args($payload);
  733. $this->debug->debug_method_signature('> %s', $method_sig);
  734. $amqpMessage = $this->maybe_wait_for_content($method_sig);
  735.  
  736. if ($this->should_dispatch_method($allowed_methods, $method_sig)) {
  737. return $this->dispatch($method_sig, $args, $amqpMessage);
  738. }
  739.  
  740. $this->debug->debug_method_signature('Queueing for later: %s', $method_sig);
  741. $this->method_queue[] = [$method_sig, $args, $amqpMessage];
  742.  
  743. if ($non_blocking) {
  744. break;
  745. }
  746. }
  747. }
  748.  
  749. /**
  750. * @param array $allowed_methods
  751. * @return array
  752. */
  753. protected function process_deferred_methods($allowed_methods)
  754. {
  755. $dispatch = false;
  756. $queued_method = [];
  757.  
  758. foreach ($this->method_queue as $qk => $qm) {
  759. $this->debug->debug_msg('checking queue method ' . $qk);
  760. $method_sig = $qm[0];
  761. if (($allowed_methods == NULL) || in_array($method_sig, $allowed_methods)) {
  762. unset($this->method_queue[$qk]);
  763. $dispatch = true;
  764. $queued_method = $qm;
  765. break;
  766. }
  767. }
  768.  
  769. return ['dispatch' => $dispatch, 'queued_method' => $queued_method];
  770. }
  771.  
  772. /**
  773. * @param array $queued_method
  774. * @return mixed
  775. */
  776. protected function dispatch_deferred_method($queued_method)
  777. {
  778. $this->debug->debug_method_signature('Executing queued method: %s', $queued_method[0]);
  779. ....................................................................
  780. .................................
  781. .............
Add Comment
Please, Sign In to add comment