1 | <?php |
||
17 | final class Factory |
||
18 | { |
||
19 | /** |
||
20 | * not need Authorization |
||
21 | * @var array { |
||
22 | * 'origin.example.com' => x |
||
23 | * } |
||
24 | */ |
||
25 | private static $connections = array(); |
||
26 | |||
27 | /** |
||
28 | * need Authorization header |
||
29 | * @var array { |
||
30 | * 'origin.example.com' => x |
||
31 | * } |
||
32 | */ |
||
33 | private static $authConnections = array(); |
||
34 | |||
35 | /** |
||
36 | * get cached curl handler |
||
37 | * @param string $origin |
||
38 | * @param bool $auth |
||
39 | * @return resource<curl> |
||
|
|||
40 | */ |
||
41 | 7 | public static function getConnection($origin, $auth = false) |
|
42 | { |
||
43 | 7 | if ($auth) { |
|
44 | 1 | if (isset(self::$authConnections[$origin])) { |
|
45 | 1 | return self::$authConnections[$origin]; |
|
46 | } |
||
47 | |||
48 | 1 | return self::$authConnections[$origin] = curl_init(); |
|
49 | } else { |
||
50 | 7 | if (isset(self::$connections[$origin])) { |
|
51 | 6 | return self::$connections[$origin]; |
|
52 | } |
||
53 | |||
54 | 2 | return self::$connections[$origin] = curl_init(); |
|
55 | } |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param string $origin domain text |
||
60 | * @param string $url |
||
61 | * @param IO\IOInterface $io |
||
62 | * @param CConfig $config |
||
63 | * @param array $pluginConfig |
||
64 | * @return Aspects\HttpGetRequest |
||
65 | */ |
||
66 | 9 | public static function getHttpGetRequest($origin, $url, IO\IOInterface $io, CConfig $config, array $pluginConfig) |
|
85 | |||
86 | 9 | private static function getRequestClass($origin, $config) |
|
96 | |||
97 | /** |
||
98 | * @return Aspects\JoinPoint |
||
99 | */ |
||
100 | 9 | public static function getPreEvent(Aspects\HttpGetRequest $req) |
|
101 | { |
||
102 | 9 | $pre = new Aspects\JoinPoint('pre-download', $req); |
|
103 | 9 | $pre->attach(static::getAspectAuth()); |
|
104 | 9 | $pre->attach(new Aspects\AspectRedirect); |
|
105 | 9 | $pre->attach(new Aspects\AspectProxy); |
|
106 | 9 | return $pre; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return Aspects\JoinPoint |
||
111 | */ |
||
112 | 7 | public static function getPostEvent(Aspects\HttpGetRequest $req) |
|
113 | { |
||
114 | 7 | $post = new Aspects\JoinPoint('post-download', $req); |
|
115 | 7 | $post->attach(static::getAspectAuth()); |
|
116 | 7 | return $post; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return Aspects\AspectAuth (same instance) |
||
121 | */ |
||
122 | 10 | public static function getAspectAuth() |
|
127 | } |
||
128 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.