mirror of
https://github.com/ledccn/IYUUPlus.git
synced 2024-09-20 07:05:28 +00:00
优化:设置curl组件 301跟随2次,解决瓷器、城市等站点的跳转问题
This commit is contained in:
parent
4e7dc9c830
commit
b2b47055af
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace IYUU\Library\Event;
|
||||
namespace app\common\event;
|
||||
|
||||
use Throwable;
|
||||
|
||||
|
@ -8,7 +8,7 @@ use Throwable;
|
|||
* 事件调度器
|
||||
* Class EventDispatcher
|
||||
*/
|
||||
class EventDispatcher implements ListenerProviderInterface
|
||||
class EventDispatcher implements ListenerProviderInterface,EventDispatcherInterface
|
||||
{
|
||||
/**
|
||||
* @var EventListenerInterface
|
||||
|
@ -33,15 +33,15 @@ class EventDispatcher implements ListenerProviderInterface
|
|||
/**
|
||||
* 检出当前事件的所有监听器
|
||||
*
|
||||
* @param string $event
|
||||
* @param object $event
|
||||
* An event for which to return the relevant listeners.
|
||||
* @return iterable[callable]
|
||||
* An iterable (array, iterator, or generator) of callables. Each
|
||||
* callable MUST be type-compatible with $event.
|
||||
*/
|
||||
public function getListenersForEvent(string $event): iterable
|
||||
public function getListenersForEvent(object $event): iterable
|
||||
{
|
||||
$class = $event;
|
||||
$class = get_class($event);
|
||||
$listeners = $this->eventListeners[$class] ?? [];
|
||||
$iterable = [];
|
||||
foreach ($listeners as $listener) {
|
||||
|
@ -53,11 +53,11 @@ class EventDispatcher implements ListenerProviderInterface
|
|||
/**
|
||||
* 派发当前事件到所有监听器的process处理方法
|
||||
*
|
||||
* @param string $event 当前事件对象
|
||||
* @param object $event 当前事件对象
|
||||
* @return string
|
||||
* The Event that was passed, now modified by listeners.
|
||||
*/
|
||||
public function dispatch(string $event)
|
||||
public function dispatch(object $event)
|
||||
{
|
||||
foreach ($this->getListenersForEvent($event) as $callback) {
|
||||
try {
|
21
app/common/event/EventDispatcherInterface.php
Normal file
21
app/common/event/EventDispatcherInterface.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\event;
|
||||
|
||||
/**
|
||||
* Defines a dispatcher for events.
|
||||
*/
|
||||
interface EventDispatcherInterface
|
||||
{
|
||||
/**
|
||||
* Provide all relevant listeners with an event to process.
|
||||
*
|
||||
* @param object $event
|
||||
* The object to process.
|
||||
*
|
||||
* @return object
|
||||
* The Event that was passed, now modified by listeners.
|
||||
*/
|
||||
public function dispatch(object $event);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace IYUU\Library\Event;
|
||||
namespace app\common\event;
|
||||
|
||||
/**
|
||||
* 事件监听器接口
|
||||
|
@ -16,7 +16,7 @@ interface EventListenerInterface
|
|||
|
||||
/**
|
||||
* 处理事件
|
||||
* @param string $event
|
||||
* @param object $event
|
||||
*/
|
||||
public function process(string $event): void;
|
||||
public function process(object $event): void;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace IYUU\Library\Event;
|
||||
namespace app\common\event;
|
||||
|
||||
/**
|
||||
* Mapper from an event to the listeners that are applicable to that event.
|
||||
|
@ -8,11 +8,11 @@ namespace IYUU\Library\Event;
|
|||
interface ListenerProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $event
|
||||
* @param object $event
|
||||
* An event for which to return the relevant listeners.
|
||||
* @return iterable[callable]
|
||||
* An iterable (array, iterator, or generator) of callables. Each
|
||||
* callable MUST be type-compatible with $event.
|
||||
*/
|
||||
public function getListenersForEvent(string $event) : iterable;
|
||||
public function getListenersForEvent(object $event) : iterable;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace IYUU\Library\Event;
|
||||
namespace app\common\event;
|
||||
|
||||
/**
|
||||
* An Event whose processing may be interrupted when the event has been handled.
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace IYUU\Library\EventListen;
|
||||
|
||||
use IYUU\Library\Event\EventListenerInterface;
|
||||
use app\common\event\EventListenerInterface;
|
||||
|
||||
class send implements EventListenerInterface
|
||||
{
|
||||
|
|
|
@ -168,6 +168,8 @@ abstract class AbstractRss
|
|||
//$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2); // 检查证书
|
||||
$this->curl->setOpt(CURLOPT_CONNECTTIMEOUT, self::CONNECTTIMEOUT); // 超时
|
||||
$this->curl->setOpt(CURLOPT_TIMEOUT, self::TIMEOUT); // 超时
|
||||
$this->curl->setOpt(CURLOPT_FOLLOWLOCATION, 1); // 自动跳转,跟随请求Location
|
||||
$this->curl->setOpt(CURLOPT_MAXREDIRS, 2); // 递归次数
|
||||
$this->curl->setUserAgent(static::getUserAgent());
|
||||
}
|
||||
|
||||
|
@ -290,6 +292,7 @@ abstract class AbstractRss
|
|||
echo $this->site." 正在请求RSS... {$url}". PHP_EOL;
|
||||
$url = (stripos($url, 'http://') === 0 || stripos($url, 'https://') === 0) ? $url : $this->host . $url;
|
||||
$res = $this->curl->get($url);
|
||||
//cli($res);exit;
|
||||
if ($res->http_status_code == 200) {
|
||||
echo "RSS获取信息,成功!". PHP_EOL;
|
||||
return $res->response;
|
||||
|
|
Loading…
Reference in New Issue
Block a user