|
2 | 2 | * Generated by build-library.php, Please DO NOT modify!
|
3 | 3 | */
|
4 | 4 |
|
5 |
| -zend::eval("\nfunction swoole_array_walk(&$array, callable $callback, $userdata = null)\n{\n foreach ($array as $key => &$item) {\n $callback($item, $key, $userdata);\n }\n}\n\nfunction swoole_array_walk_recursive(&$array, callable $callback, $userdata = null)\n{\n foreach ($array as $key => &$item) {\n if (is_array($item)) {\n swoole_array_walk_recursive($item, $callback, $userdata);\n } else {\n $callback($item, $key, $userdata);\n }\n }\n}\n", "/path/to/swoole-src/library/array.php"); |
6 |
| -zend::eval("\ndefine('SWOOLE_LIBRARY', true);\n", "/path/to/swoole-src/library/constant.php"); |
7 |
| -zend::eval("\n\nclass swoole_curl_handler\n{\n /**\n * @var Swoole\\Coroutine\\Http\\Client\n */\n private $client;\n private $info;\n private $outputStream;\n\n /**\n * @var callable\n */\n private $headerFunction ;\n\n /**\n * @var callable\n */\n private $readFunction;\n\n private $writeFunction;\n\n private $progressFunction;\n\n public $return_transfer = true;\n public $method;\n public $headers = [];\n\n function create($url)\n {\n $info = parse_url($url);\n if ($info['scheme'] == 'https') {\n $ssl = true;\n } else {\n $ssl = false;\n }\n if (empty($info['port'])) {\n $port = $ssl ? 443 : 80;\n } else {\n $port = intval($info['port']);\n }\n $this->info = $info;\n $this->client = new Swoole\\Coroutine\\Http\\Client($info['host'], $port, $ssl);\n }\n\n function execute()\n {\n $client = $this->client;\n $client->setMethod($this->method);\n if ($this->headers) {\n $client->setHeaders($this->headers);\n }\n if (!$client->execute($this->getUrl())) {\n return false;\n }\n\n if ($client->headers and $this->headerFunction) {\n $cb = $this->headerFunction;\n if ($client->statusCode == 200) {\n $cb($this, \"HTTP/1.1 200 OK\\r\\n\");\n }\n foreach ($client->headers as $k => $v) {\n $cb($this, \"$k: $v\\r\\n\");\n }\n $cb($this, '');\n }\n\n if ($client->body and $this->readFunction) {\n $cb = $this->readFunction;\n $cb($this, $this->outputStream, strlen($client->body));\n }\n\n if ($this->return_transfer) {\n return $client->body;\n } else {\n if ($this->outputStream) {\n fwrite($this->outputStream, $client->body);\n } else {\n echo $this->outputStream;\n }\n return true;\n }\n }\n\n function close()\n {\n $this->client = null;\n return true;\n }\n\n function getErrorCode()\n {\n return $this->client->errCode;\n }\n\n function getErrorMsg()\n {\n return $this->client->errMsg;\n }\n\n private function getUrl()\n {\n if (empty($this->info['path'])) {\n $url = '/';\n } else {\n $url = $this->info['path'];\n }\n if (!empty($this->info['query'])) {\n $url .= '?' . $this->info['query'];\n }\n if (!empty($this->info['query'])) {\n $url .= '#' . $this->info['fragment'];\n }\n return $url;\n }\n\n function setOption($opt, $value)\n {\n switch ($opt) {\n case CURLOPT_URL:\n $this->create($value);\n break;\n case CURLOPT_RETURNTRANSFER:\n $this->return_transfer = $value;\n break;\n case CURLOPT_ENCODING:\n if (empty($value)) {\n $value = 'gzip';\n }\n $this->headers['Accept-Encoding'] = $value;\n break;\n case CURLOPT_POST:\n $this->method = 'post';\n break;\n case CURLOPT_HTTPHEADER:\n foreach ($value as $header) {\n list($k, $v) = explode(':', $header);\n $v = trim($v);\n if ($v) {\n $this->headers[$k] = $v;\n }\n }\n break;\n case CURLOPT_CUSTOMREQUEST:\n break;\n case CURLOPT_PROTOCOLS:\n if ($value > 3) {\n throw new swoole_curl_exception(\"option[$opt=$value] is not supports.\");\n }\n break;\n case CURLOPT_HTTP_VERSION:\n break;\n case CURLOPT_SSL_VERIFYHOST:\n break;\n case CURLOPT_SSL_VERIFYPEER:\n $this->client->set(['ssl_verify_peer' => $value]);\n break;\n case CURLOPT_CONNECTTIMEOUT:\n $this->client->set(['connect_timeout' => $value]);\n break;\n case CURLOPT_FILE:\n $this->outputStream = $value;\n break;\n case CURLOPT_HEADER:\n break;\n case CURLOPT_HEADERFUNCTION:\n $this->headerFunction = $value;\n break;\n case CURLOPT_READFUNCTION:\n $this->readFunction = $value;\n break;\n case CURLOPT_WRITEFUNCTION:\n $this->writeFunction = $value;\n break;\n case CURLOPT_PROGRESSFUNCTION:\n $this->progressFunction = $value;\n break;\n default:\n var_dump($opt, $value);\n throw new swoole_curl_exception(\"option[$opt] is not supports.\");\n }\n return true;\n }\n\n function reset()\n {\n $this->client->body = '';\n }\n}\n\nclass swoole_curl_exception extends RuntimeException\n{\n\n}\n\nfunction swoole_curl_init()\n{\n return new swoole_curl_handler();\n}\n\nfunction swoole_curl_setopt(swoole_curl_handler $obj, $opt, $value)\n{\n return $obj->setOption($opt, $value);\n}\n\nfunction swoole_curl_setopt_array(swoole_curl_handler $obj, $array)\n{\n foreach ($array as $k => $v) {\n if ($obj->setOption($k, $v) === false) {\n return false;\n }\n }\n return true;\n}\n\n\nfunction swoole_curl_exec(swoole_curl_handler $obj)\n{\n return $obj->execute();\n}\n\n\nfunction swoole_curl_close(swoole_curl_handler $obj)\n{\n return $obj->close();\n}\n\nfunction swoole_curl_error(swoole_curl_handler $obj)\n{\n return $obj->getErrorMsg();\n}\n\nfunction swoole_curl_errno(swoole_curl_handler $obj)\n{\n return $obj->getErrorCode();\n}\n\nfunction swoole_curl_reset(swoole_curl_handler $obj)\n{\n return $obj->reset();\n}\n", "/path/to/swoole-src/library/curl.php"); |
| 5 | +zend::eval( |
| 6 | + "\n" |
| 7 | + "function swoole_array_walk(&$array, callable $callback, $userdata = null)\n" |
| 8 | + "{\n" |
| 9 | + " foreach ($array as $key => &$item) {\n" |
| 10 | + " $callback($item, $key, $userdata);\n" |
| 11 | + " }\n" |
| 12 | + "}\n" |
| 13 | + "\n" |
| 14 | + "function swoole_array_walk_recursive(&$array, callable $callback, $userdata = null)\n" |
| 15 | + "{\n" |
| 16 | + " foreach ($array as $key => &$item) {\n" |
| 17 | + " if (is_array($item)) {\n" |
| 18 | + " swoole_array_walk_recursive($item, $callback, $userdata);\n" |
| 19 | + " } else {\n" |
| 20 | + " $callback($item, $key, $userdata);\n" |
| 21 | + " }\n" |
| 22 | + " }\n" |
| 23 | + "}\n", |
| 24 | + "/path/to/swoole-src/library/array.php" |
| 25 | +); |
| 26 | + |
| 27 | +zend::eval( |
| 28 | + "\n" |
| 29 | + "define('SWOOLE_LIBRARY', true);\n", |
| 30 | + "/path/to/swoole-src/library/constant.php" |
| 31 | +); |
| 32 | + |
| 33 | +zend::eval( |
| 34 | + "\n" |
| 35 | + "\n" |
| 36 | + "class swoole_curl_handler\n" |
| 37 | + "{\n" |
| 38 | + " /**\n" |
| 39 | + " * @var Swoole\\Coroutine\\Http\\Client\n" |
| 40 | + " */\n" |
| 41 | + " private $client;\n" |
| 42 | + " private $info;\n" |
| 43 | + " private $outputStream;\n" |
| 44 | + "\n" |
| 45 | + " /**\n" |
| 46 | + " * @var callable\n" |
| 47 | + " */\n" |
| 48 | + " private $headerFunction ;\n" |
| 49 | + "\n" |
| 50 | + " /**\n" |
| 51 | + " * @var callable\n" |
| 52 | + " */\n" |
| 53 | + " private $readFunction;\n" |
| 54 | + "\n" |
| 55 | + " private $writeFunction;\n" |
| 56 | + "\n" |
| 57 | + " private $progressFunction;\n" |
| 58 | + "\n" |
| 59 | + " public $return_transfer = true;\n" |
| 60 | + " public $method;\n" |
| 61 | + " public $headers = [];\n" |
| 62 | + "\n" |
| 63 | + " function create($url)\n" |
| 64 | + " {\n" |
| 65 | + " $info = parse_url($url);\n" |
| 66 | + " if ($info['scheme'] == 'https') {\n" |
| 67 | + " $ssl = true;\n" |
| 68 | + " } else {\n" |
| 69 | + " $ssl = false;\n" |
| 70 | + " }\n" |
| 71 | + " if (empty($info['port'])) {\n" |
| 72 | + " $port = $ssl ? 443 : 80;\n" |
| 73 | + " } else {\n" |
| 74 | + " $port = intval($info['port']);\n" |
| 75 | + " }\n" |
| 76 | + " $this->info = $info;\n" |
| 77 | + " $this->client = new Swoole\\Coroutine\\Http\\Client($info['host'], $port, $ssl);\n" |
| 78 | + " }\n" |
| 79 | + "\n" |
| 80 | + " function execute()\n" |
| 81 | + " {\n" |
| 82 | + " $client = $this->client;\n" |
| 83 | + " $client->setMethod($this->method);\n" |
| 84 | + " if ($this->headers) {\n" |
| 85 | + " $client->setHeaders($this->headers);\n" |
| 86 | + " }\n" |
| 87 | + " if (!$client->execute($this->getUrl())) {\n" |
| 88 | + " return false;\n" |
| 89 | + " }\n" |
| 90 | + "\n" |
| 91 | + " if ($client->headers and $this->headerFunction) {\n" |
| 92 | + " $cb = $this->headerFunction;\n" |
| 93 | + " if ($client->statusCode == 200) {\n" |
| 94 | + " $cb($this, \"HTTP/1.1 200 OK\\r\\n\");\n" |
| 95 | + " }\n" |
| 96 | + " foreach ($client->headers as $k => $v) {\n" |
| 97 | + " $cb($this, \"$k: $v\\r\\n\");\n" |
| 98 | + " }\n" |
| 99 | + " $cb($this, '');\n" |
| 100 | + " }\n" |
| 101 | + "\n" |
| 102 | + " if ($client->body and $this->readFunction) {\n" |
| 103 | + " $cb = $this->readFunction;\n" |
| 104 | + " $cb($this, $this->outputStream, strlen($client->body));\n" |
| 105 | + " }\n" |
| 106 | + "\n" |
| 107 | + " if ($this->return_transfer) {\n" |
| 108 | + " return $client->body;\n" |
| 109 | + " } else {\n" |
| 110 | + " if ($this->outputStream) {\n" |
| 111 | + " fwrite($this->outputStream, $client->body);\n" |
| 112 | + " } else {\n" |
| 113 | + " echo $this->outputStream;\n" |
| 114 | + " }\n" |
| 115 | + " return true;\n" |
| 116 | + " }\n" |
| 117 | + " }\n" |
| 118 | + "\n" |
| 119 | + " function close()\n" |
| 120 | + " {\n" |
| 121 | + " $this->client = null;\n" |
| 122 | + " return true;\n" |
| 123 | + " }\n" |
| 124 | + "\n" |
| 125 | + " function getErrorCode()\n" |
| 126 | + " {\n" |
| 127 | + " return $this->client->errCode;\n" |
| 128 | + " }\n" |
| 129 | + "\n" |
| 130 | + " function getErrorMsg()\n" |
| 131 | + " {\n" |
| 132 | + " return $this->client->errMsg;\n" |
| 133 | + " }\n" |
| 134 | + "\n" |
| 135 | + " private function getUrl()\n" |
| 136 | + " {\n" |
| 137 | + " if (empty($this->info['path'])) {\n" |
| 138 | + " $url = '/';\n" |
| 139 | + " } else {\n" |
| 140 | + " $url = $this->info['path'];\n" |
| 141 | + " }\n" |
| 142 | + " if (!empty($this->info['query'])) {\n" |
| 143 | + " $url .= '?' . $this->info['query'];\n" |
| 144 | + " }\n" |
| 145 | + " if (!empty($this->info['query'])) {\n" |
| 146 | + " $url .= '#' . $this->info['fragment'];\n" |
| 147 | + " }\n" |
| 148 | + " return $url;\n" |
| 149 | + " }\n" |
| 150 | + "\n" |
| 151 | + " function setOption($opt, $value)\n" |
| 152 | + " {\n" |
| 153 | + " switch ($opt) {\n" |
| 154 | + " case CURLOPT_URL:\n" |
| 155 | + " $this->create($value);\n" |
| 156 | + " break;\n" |
| 157 | + " case CURLOPT_RETURNTRANSFER:\n" |
| 158 | + " $this->return_transfer = $value;\n" |
| 159 | + " break;\n" |
| 160 | + " case CURLOPT_ENCODING:\n" |
| 161 | + " if (empty($value)) {\n" |
| 162 | + " $value = 'gzip';\n" |
| 163 | + " }\n" |
| 164 | + " $this->headers['Accept-Encoding'] = $value;\n" |
| 165 | + " break;\n" |
| 166 | + " case CURLOPT_POST:\n" |
| 167 | + " $this->method = 'post';\n" |
| 168 | + " break;\n" |
| 169 | + " case CURLOPT_HTTPHEADER:\n" |
| 170 | + " foreach ($value as $header) {\n" |
| 171 | + " list($k, $v) = explode(':', $header);\n" |
| 172 | + " $v = trim($v);\n" |
| 173 | + " if ($v) {\n" |
| 174 | + " $this->headers[$k] = $v;\n" |
| 175 | + " }\n" |
| 176 | + " }\n" |
| 177 | + " break;\n" |
| 178 | + " case CURLOPT_CUSTOMREQUEST:\n" |
| 179 | + " break;\n" |
| 180 | + " case CURLOPT_PROTOCOLS:\n" |
| 181 | + " if ($value > 3) {\n" |
| 182 | + " throw new swoole_curl_exception(\"option[$opt=$value] is not supports.\");\n" |
| 183 | + " }\n" |
| 184 | + " break;\n" |
| 185 | + " case CURLOPT_HTTP_VERSION:\n" |
| 186 | + " break;\n" |
| 187 | + " case CURLOPT_SSL_VERIFYHOST:\n" |
| 188 | + " break;\n" |
| 189 | + " case CURLOPT_SSL_VERIFYPEER:\n" |
| 190 | + " $this->client->set(['ssl_verify_peer' => $value]);\n" |
| 191 | + " break;\n" |
| 192 | + " case CURLOPT_CONNECTTIMEOUT:\n" |
| 193 | + " $this->client->set(['connect_timeout' => $value]);\n" |
| 194 | + " break;\n" |
| 195 | + " case CURLOPT_FILE:\n" |
| 196 | + " $this->outputStream = $value;\n" |
| 197 | + " break;\n" |
| 198 | + " case CURLOPT_HEADER:\n" |
| 199 | + " break;\n" |
| 200 | + " case CURLOPT_HEADERFUNCTION:\n" |
| 201 | + " $this->headerFunction = $value;\n" |
| 202 | + " break;\n" |
| 203 | + " case CURLOPT_READFUNCTION:\n" |
| 204 | + " $this->readFunction = $value;\n" |
| 205 | + " break;\n" |
| 206 | + " case CURLOPT_WRITEFUNCTION:\n" |
| 207 | + " $this->writeFunction = $value;\n" |
| 208 | + " break;\n" |
| 209 | + " case CURLOPT_PROGRESSFUNCTION:\n" |
| 210 | + " $this->progressFunction = $value;\n" |
| 211 | + " break;\n" |
| 212 | + " default:\n" |
| 213 | + " var_dump($opt, $value);\n" |
| 214 | + " throw new swoole_curl_exception(\"option[$opt] is not supports.\");\n" |
| 215 | + " }\n" |
| 216 | + " return true;\n" |
| 217 | + " }\n" |
| 218 | + "\n" |
| 219 | + " function reset()\n" |
| 220 | + " {\n" |
| 221 | + " $this->client->body = '';\n" |
| 222 | + " }\n" |
| 223 | + "}\n" |
| 224 | + "\n" |
| 225 | + "class swoole_curl_exception extends RuntimeException\n" |
| 226 | + "{\n" |
| 227 | + "\n" |
| 228 | + "}\n" |
| 229 | + "\n" |
| 230 | + "function swoole_curl_init()\n" |
| 231 | + "{\n" |
| 232 | + " return new swoole_curl_handler();\n" |
| 233 | + "}\n" |
| 234 | + "\n" |
| 235 | + "function swoole_curl_setopt(swoole_curl_handler $obj, $opt, $value)\n" |
| 236 | + "{\n" |
| 237 | + " return $obj->setOption($opt, $value);\n" |
| 238 | + "}\n" |
| 239 | + "\n" |
| 240 | + "function swoole_curl_setopt_array(swoole_curl_handler $obj, $array)\n" |
| 241 | + "{\n" |
| 242 | + " foreach ($array as $k => $v) {\n" |
| 243 | + " if ($obj->setOption($k, $v) === false) {\n" |
| 244 | + " return false;\n" |
| 245 | + " }\n" |
| 246 | + " }\n" |
| 247 | + " return true;\n" |
| 248 | + "}\n" |
| 249 | + "\n" |
| 250 | + "\n" |
| 251 | + "function swoole_curl_exec(swoole_curl_handler $obj)\n" |
| 252 | + "{\n" |
| 253 | + " return $obj->execute();\n" |
| 254 | + "}\n" |
| 255 | + "\n" |
| 256 | + "\n" |
| 257 | + "function swoole_curl_close(swoole_curl_handler $obj)\n" |
| 258 | + "{\n" |
| 259 | + " return $obj->close();\n" |
| 260 | + "}\n" |
| 261 | + "\n" |
| 262 | + "function swoole_curl_error(swoole_curl_handler $obj)\n" |
| 263 | + "{\n" |
| 264 | + " return $obj->getErrorMsg();\n" |
| 265 | + "}\n" |
| 266 | + "\n" |
| 267 | + "function swoole_curl_errno(swoole_curl_handler $obj)\n" |
| 268 | + "{\n" |
| 269 | + " return $obj->getErrorCode();\n" |
| 270 | + "}\n" |
| 271 | + "\n" |
| 272 | + "function swoole_curl_reset(swoole_curl_handler $obj)\n" |
| 273 | + "{\n" |
| 274 | + " return $obj->reset();\n" |
| 275 | + "}\n", |
| 276 | + "/path/to/swoole-src/library/curl.php" |
| 277 | +); |
0 commit comments