PageRenderTime 3520ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 1ms

/Http/Client.php

https://bitbucket.org/bigstylee/zend-framework
PHP | 1564 lines | 763 code | 198 blank | 603 comment | 189 complexity | 8075122da53fb2ea5e5e79ec6abe6b2e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Http
  17. * @subpackage Client
  18. * @version $Id: Client.php 24593 2012-01-05 20:35:02Z matthew $
  19. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /**
  23. * @see Zend_Loader
  24. */
  25. require_once 'Zend/Loader.php';
  26. /**
  27. * @see Zend_Uri
  28. */
  29. require_once 'Zend/Uri.php';
  30. /**
  31. * @see Zend_Http_Client_Adapter_Interface
  32. */
  33. require_once 'Zend/Http/Client/Adapter/Interface.php';
  34. /**
  35. * @see Zend_Http_Response
  36. */
  37. require_once 'Zend/Http/Response.php';
  38. /**
  39. * @see Zend_Http_Response_Stream
  40. */
  41. require_once 'Zend/Http/Response/Stream.php';
  42. /**
  43. * Zend_Http_Client is an implementation of an HTTP client in PHP. The client
  44. * supports basic features like sending different HTTP requests and handling
  45. * redirections, as well as more advanced features like proxy settings, HTTP
  46. * authentication and cookie persistence (using a Zend_Http_CookieJar object)
  47. *
  48. * @todo Implement proxy settings
  49. * @category Zend
  50. * @package Zend_Http
  51. * @subpackage Client
  52. * @throws Zend_Http_Client_Exception
  53. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  54. * @license http://framework.zend.com/license/new-bsd New BSD License
  55. */
  56. class Zend_Http_Client
  57. {
  58. /**
  59. * HTTP request methods
  60. */
  61. const GET = 'GET';
  62. const POST = 'POST';
  63. const PUT = 'PUT';
  64. const HEAD = 'HEAD';
  65. const DELETE = 'DELETE';
  66. const TRACE = 'TRACE';
  67. const OPTIONS = 'OPTIONS';
  68. const CONNECT = 'CONNECT';
  69. const MERGE = 'MERGE';
  70. /**
  71. * Supported HTTP Authentication methods
  72. */
  73. const AUTH_BASIC = 'basic';
  74. //const AUTH_DIGEST = 'digest'; <-- not implemented yet
  75. /**
  76. * HTTP protocol versions
  77. */
  78. const HTTP_1 = '1.1';
  79. const HTTP_0 = '1.0';
  80. /**
  81. * Content attributes
  82. */
  83. const CONTENT_TYPE = 'Content-Type';
  84. const CONTENT_LENGTH = 'Content-Length';
  85. /**
  86. * POST data encoding methods
  87. */
  88. const ENC_URLENCODED = 'application/x-www-form-urlencoded';
  89. const ENC_FORMDATA = 'multipart/form-data';
  90. /**
  91. * Value types for Body key/value pairs
  92. */
  93. const VTYPE_SCALAR = 'SCALAR';
  94. const VTYPE_FILE = 'FILE';
  95. /**
  96. * Configuration array, set using the constructor or using ::setConfig()
  97. *
  98. * @var array
  99. */
  100. protected $config = array(
  101. 'maxredirects' => 5,
  102. 'strictredirects' => false,
  103. 'useragent' => 'Zend_Http_Client',
  104. 'timeout' => 10,
  105. 'adapter' => 'Zend_Http_Client_Adapter_Socket',
  106. 'httpversion' => self::HTTP_1,
  107. 'keepalive' => false,
  108. 'storeresponse' => true,
  109. 'strict' => true,
  110. 'output_stream' => false,
  111. 'encodecookies' => true,
  112. 'rfc3986_strict' => false
  113. );
  114. /**
  115. * The adapter used to perform the actual connection to the server
  116. *
  117. * @var Zend_Http_Client_Adapter_Interface
  118. */
  119. protected $adapter = null;
  120. /**
  121. * Request URI
  122. *
  123. * @var Zend_Uri_Http
  124. */
  125. protected $uri = null;
  126. /**
  127. * Associative array of request headers
  128. *
  129. * @var array
  130. */
  131. protected $headers = array();
  132. /**
  133. * HTTP request method
  134. *
  135. * @var string
  136. */
  137. protected $method = self::GET;
  138. /**
  139. * Associative array of GET parameters
  140. *
  141. * @var array
  142. */
  143. protected $paramsGet = array();
  144. /**
  145. * Associative array of POST parameters
  146. *
  147. * @var array
  148. */
  149. protected $paramsPost = array();
  150. /**
  151. * Request body content type (for POST requests)
  152. *
  153. * @var string
  154. */
  155. protected $enctype = null;
  156. /**
  157. * The raw post data to send. Could be set by setRawData($data, $enctype).
  158. *
  159. * @var string
  160. */
  161. protected $raw_post_data = null;
  162. /**
  163. * HTTP Authentication settings
  164. *
  165. * Expected to be an associative array with this structure:
  166. * $this->auth = array('user' => 'username', 'password' => 'password', 'type' => 'basic')
  167. * Where 'type' should be one of the supported authentication types (see the AUTH_*
  168. * constants), for example 'basic' or 'digest'.
  169. *
  170. * If null, no authentication will be used.
  171. *
  172. * @var array|null
  173. */
  174. protected $auth;
  175. /**
  176. * File upload arrays (used in POST requests)
  177. *
  178. * An associative array, where each element is of the format:
  179. * 'name' => array('filename.txt', 'text/plain', 'This is the actual file contents')
  180. *
  181. * @var array
  182. */
  183. protected $files = array();
  184. /**
  185. * Ordered list of keys from key/value pair data to include in body
  186. *
  187. * An associative array, where each element is of the format:
  188. * '<field name>' => VTYPE_SCALAR | VTYPE_FILE
  189. *
  190. * @var array
  191. */
  192. protected $body_field_order = array();
  193. /**
  194. * The client's cookie jar
  195. *
  196. * @var Zend_Http_CookieJar
  197. */
  198. protected $cookiejar = null;
  199. /**
  200. * The last HTTP request sent by the client, as string
  201. *
  202. * @var string
  203. */
  204. protected $last_request = null;
  205. /**
  206. * The last HTTP response received by the client
  207. *
  208. * @var Zend_Http_Response
  209. */
  210. protected $last_response = null;
  211. /**
  212. * Redirection counter
  213. *
  214. * @var int
  215. */
  216. protected $redirectCounter = 0;
  217. /**
  218. * Status for unmasking GET array params
  219. *
  220. * @var boolean
  221. */
  222. protected $_unmaskStatus = false;
  223. /**
  224. * Status if the http_build_query function escapes brackets
  225. *
  226. * @var boolean
  227. */
  228. protected $_queryBracketsEscaped = true;
  229. /**
  230. * Fileinfo magic database resource
  231. *
  232. * This variable is populated the first time _detectFileMimeType is called
  233. * and is then reused on every call to this method
  234. *
  235. * @var resource
  236. */
  237. static protected $_fileInfoDb = null;
  238. /**
  239. * Constructor method. Will create a new HTTP client. Accepts the target
  240. * URL and optionally configuration array.
  241. *
  242. * @param Zend_Uri_Http|string $uri
  243. * @param array $config Configuration key-value pairs.
  244. */
  245. public function __construct($uri = null, $config = null)
  246. {
  247. if ($uri !== null) {
  248. $this->setUri($uri);
  249. }
  250. if ($config !== null) {
  251. $this->setConfig($config);
  252. }
  253. $this->_queryBracketsEscaped = version_compare(phpversion(), '5.1.3', '>=');
  254. }
  255. /**
  256. * Set the URI for the next request
  257. *
  258. * @param Zend_Uri_Http|string $uri
  259. * @return Zend_Http_Client
  260. * @throws Zend_Http_Client_Exception
  261. */
  262. public function setUri($uri)
  263. {
  264. if ($uri instanceof Zend_Uri_Http) {
  265. // clone the URI in order to keep the passed parameter constant
  266. $uri = clone $uri;
  267. } elseif (is_string($uri)) {
  268. $uri = Zend_Uri::factory($uri);
  269. }
  270. if (!$uri instanceof Zend_Uri_Http) {
  271. /** @see Zend_Http_Client_Exception */
  272. require_once 'Zend/Http/Client/Exception.php';
  273. throw new Zend_Http_Client_Exception('Passed parameter is not a valid HTTP URI.');
  274. }
  275. // Set auth if username and password has been specified in the uri
  276. if ($uri->getUsername() && $uri->getPassword()) {
  277. $this->setAuth($uri->getUsername(), $uri->getPassword());
  278. }
  279. // We have no ports, set the defaults
  280. if (! $uri->getPort()) {
  281. $uri->setPort(($uri->getScheme() == 'https' ? 443 : 80));
  282. }
  283. $this->uri = $uri;
  284. return $this;
  285. }
  286. /**
  287. * Get the URI for the next request
  288. *
  289. * @param boolean $as_string If true, will return the URI as a string
  290. * @return Zend_Uri_Http|string
  291. */
  292. public function getUri($as_string = false)
  293. {
  294. if ($as_string && $this->uri instanceof Zend_Uri_Http) {
  295. return $this->uri->__toString();
  296. } else {
  297. return $this->uri;
  298. }
  299. }
  300. /**
  301. * Set configuration parameters for this HTTP client
  302. *
  303. * @param Zend_Config | array $config
  304. * @return Zend_Http_Client
  305. * @throws Zend_Http_Client_Exception
  306. */
  307. public function setConfig($config = array())
  308. {
  309. if ($config instanceof Zend_Config) {
  310. $config = $config->toArray();
  311. } elseif (! is_array($config)) {
  312. /** @see Zend_Http_Client_Exception */
  313. require_once 'Zend/Http/Client/Exception.php';
  314. throw new Zend_Http_Client_Exception('Array or Zend_Config object expected, got ' . gettype($config));
  315. }
  316. foreach ($config as $k => $v) {
  317. $this->config[strtolower($k)] = $v;
  318. }
  319. // Pass configuration options to the adapter if it exists
  320. if ($this->adapter instanceof Zend_Http_Client_Adapter_Interface) {
  321. $this->adapter->setConfig($config);
  322. }
  323. return $this;
  324. }
  325. /**
  326. * Set the next request's method
  327. *
  328. * Validated the passed method and sets it. If we have files set for
  329. * POST requests, and the new method is not POST, the files are silently
  330. * dropped.
  331. *
  332. * @param string $method
  333. * @return Zend_Http_Client
  334. * @throws Zend_Http_Client_Exception
  335. */
  336. public function setMethod($method = self::GET)
  337. {
  338. if (! preg_match('/^[^\x00-\x1f\x7f-\xff\(\)<>@,;:\\\\"\/\[\]\?={}\s]+$/', $method)) {
  339. /** @see Zend_Http_Client_Exception */
  340. require_once 'Zend/Http/Client/Exception.php';
  341. throw new Zend_Http_Client_Exception("'{$method}' is not a valid HTTP request method.");
  342. }
  343. if (($method == self::POST || $method == self::PUT || $method == self::DELETE) && $this->enctype === null) {
  344. $this->setEncType(self::ENC_URLENCODED);
  345. }
  346. $this->method = $method;
  347. return $this;
  348. }
  349. /**
  350. * Set one or more request headers
  351. *
  352. * This function can be used in several ways to set the client's request
  353. * headers:
  354. * 1. By providing two parameters: $name as the header to set (e.g. 'Host')
  355. * and $value as it's value (e.g. 'www.example.com').
  356. * 2. By providing a single header string as the only parameter
  357. * e.g. 'Host: www.example.com'
  358. * 3. By providing an array of headers as the first parameter
  359. * e.g. array('host' => 'www.example.com', 'x-foo: bar'). In This case
  360. * the function will call itself recursively for each array item.
  361. *
  362. * @param string|array $name Header name, full header string ('Header: value')
  363. * or an array of headers
  364. * @param mixed $value Header value or null
  365. * @return Zend_Http_Client
  366. * @throws Zend_Http_Client_Exception
  367. */
  368. public function setHeaders($name, $value = null)
  369. {
  370. // If we got an array, go recursive!
  371. if (is_array($name)) {
  372. foreach ($name as $k => $v) {
  373. if (is_string($k)) {
  374. $this->setHeaders($k, $v);
  375. } else {
  376. $this->setHeaders($v, null);
  377. }
  378. }
  379. } else {
  380. // Check if $name needs to be split
  381. if ($value === null && (strpos($name, ':') > 0)) {
  382. list($name, $value) = explode(':', $name, 2);
  383. }
  384. // Make sure the name is valid if we are in strict mode
  385. if ($this->config['strict'] && (! preg_match('/^[a-zA-Z0-9-]+$/', $name))) {
  386. /** @see Zend_Http_Client_Exception */
  387. require_once 'Zend/Http/Client/Exception.php';
  388. throw new Zend_Http_Client_Exception("{$name} is not a valid HTTP header name");
  389. }
  390. $normalized_name = strtolower($name);
  391. // If $value is null or false, unset the header
  392. if ($value === null || $value === false) {
  393. unset($this->headers[$normalized_name]);
  394. // Else, set the header
  395. } else {
  396. // Header names are stored lowercase internally.
  397. if (is_string($value)) {
  398. $value = trim($value);
  399. }
  400. $this->headers[$normalized_name] = array($name, $value);
  401. }
  402. }
  403. return $this;
  404. }
  405. /**
  406. * Get the value of a specific header
  407. *
  408. * Note that if the header has more than one value, an array
  409. * will be returned.
  410. *
  411. * @param string $key
  412. * @return string|array|null The header value or null if it is not set
  413. */
  414. public function getHeader($key)
  415. {
  416. $key = strtolower($key);
  417. if (isset($this->headers[$key])) {
  418. return $this->headers[$key][1];
  419. } else {
  420. return null;
  421. }
  422. }
  423. /**
  424. * Set a GET parameter for the request. Wrapper around _setParameter
  425. *
  426. * @param string|array $name
  427. * @param string $value
  428. * @return Zend_Http_Client
  429. */
  430. public function setParameterGet($name, $value = null)
  431. {
  432. if (is_array($name)) {
  433. foreach ($name as $k => $v)
  434. $this->_setParameter('GET', $k, $v);
  435. } else {
  436. $this->_setParameter('GET', $name, $value);
  437. }
  438. return $this;
  439. }
  440. /**
  441. * Set a POST parameter for the request. Wrapper around _setParameter
  442. *
  443. * @param string|array $name
  444. * @param string $value
  445. * @return Zend_Http_Client
  446. */
  447. public function setParameterPost($name, $value = null)
  448. {
  449. if (is_array($name)) {
  450. foreach ($name as $k => $v)
  451. $this->_setParameter('POST', $k, $v);
  452. } else {
  453. $this->_setParameter('POST', $name, $value);
  454. }
  455. return $this;
  456. }
  457. /**
  458. * Set a GET or POST parameter - used by SetParameterGet and SetParameterPost
  459. *
  460. * @param string $type GET or POST
  461. * @param string $name
  462. * @param string $value
  463. * @return null
  464. */
  465. protected function _setParameter($type, $name, $value)
  466. {
  467. $parray = array();
  468. $type = strtolower($type);
  469. switch ($type) {
  470. case 'get':
  471. $parray = &$this->paramsGet;
  472. break;
  473. case 'post':
  474. $parray = &$this->paramsPost;
  475. if ( $value === null ) {
  476. if (isset($this->body_field_order[$name]))
  477. unset($this->body_field_order[$name]);
  478. } else {
  479. $this->body_field_order[$name] = self::VTYPE_SCALAR;
  480. }
  481. break;
  482. }
  483. if ($value === null) {
  484. if (isset($parray[$name])) unset($parray[$name]);
  485. } else {
  486. $parray[$name] = $value;
  487. }
  488. }
  489. /**
  490. * Get the number of redirections done on the last request
  491. *
  492. * @return int
  493. */
  494. public function getRedirectionsCount()
  495. {
  496. return $this->redirectCounter;
  497. }
  498. /**
  499. * Set HTTP authentication parameters
  500. *
  501. * $type should be one of the supported types - see the self::AUTH_*
  502. * constants.
  503. *
  504. * To enable authentication:
  505. * <code>
  506. * $this->setAuth('shahar', 'secret', Zend_Http_Client::AUTH_BASIC);
  507. * </code>
  508. *
  509. * To disable authentication:
  510. * <code>
  511. * $this->setAuth(false);
  512. * </code>
  513. *
  514. * @see http://www.faqs.org/rfcs/rfc2617.html
  515. * @param string|false $user User name or false disable authentication
  516. * @param string $password Password
  517. * @param string $type Authentication type
  518. * @return Zend_Http_Client
  519. * @throws Zend_Http_Client_Exception
  520. */
  521. public function setAuth($user, $password = '', $type = self::AUTH_BASIC)
  522. {
  523. // If we got false or null, disable authentication
  524. if ($user === false || $user === null) {
  525. $this->auth = null;
  526. // Clear the auth information in the uri instance as well
  527. if ($this->uri instanceof Zend_Uri_Http) {
  528. $this->getUri()->setUsername('');
  529. $this->getUri()->setPassword('');
  530. }
  531. // Else, set up authentication
  532. } else {
  533. // Check we got a proper authentication type
  534. if (! defined('self::AUTH_' . strtoupper($type))) {
  535. /** @see Zend_Http_Client_Exception */
  536. require_once 'Zend/Http/Client/Exception.php';
  537. throw new Zend_Http_Client_Exception("Invalid or not supported authentication type: '$type'");
  538. }
  539. $this->auth = array(
  540. 'user' => (string) $user,
  541. 'password' => (string) $password,
  542. 'type' => $type
  543. );
  544. }
  545. return $this;
  546. }
  547. /**
  548. * Set the HTTP client's cookie jar.
  549. *
  550. * A cookie jar is an object that holds and maintains cookies across HTTP requests
  551. * and responses.
  552. *
  553. * @param Zend_Http_CookieJar|boolean $cookiejar Existing cookiejar object, true to create a new one, false to disable
  554. * @return Zend_Http_Client
  555. * @throws Zend_Http_Client_Exception
  556. */
  557. public function setCookieJar($cookiejar = true)
  558. {
  559. Zend_Loader::loadClass('Zend_Http_CookieJar');
  560. if ($cookiejar instanceof Zend_Http_CookieJar) {
  561. $this->cookiejar = $cookiejar;
  562. } elseif ($cookiejar === true) {
  563. $this->cookiejar = new Zend_Http_CookieJar();
  564. } elseif (! $cookiejar) {
  565. $this->cookiejar = null;
  566. } else {
  567. /** @see Zend_Http_Client_Exception */
  568. require_once 'Zend/Http/Client/Exception.php';
  569. throw new Zend_Http_Client_Exception('Invalid parameter type passed as CookieJar');
  570. }
  571. return $this;
  572. }
  573. /**
  574. * Return the current cookie jar or null if none.
  575. *
  576. * @return Zend_Http_CookieJar|null
  577. */
  578. public function getCookieJar()
  579. {
  580. return $this->cookiejar;
  581. }
  582. /**
  583. * Add a cookie to the request. If the client has no Cookie Jar, the cookies
  584. * will be added directly to the headers array as "Cookie" headers.
  585. *
  586. * @param Zend_Http_Cookie|string $cookie
  587. * @param string|null $value If "cookie" is a string, this is the cookie value.
  588. * @return Zend_Http_Client
  589. * @throws Zend_Http_Client_Exception
  590. */
  591. public function setCookie($cookie, $value = null)
  592. {
  593. Zend_Loader::loadClass('Zend_Http_Cookie');
  594. if (is_array($cookie)) {
  595. foreach ($cookie as $c => $v) {
  596. if (is_string($c)) {
  597. $this->setCookie($c, $v);
  598. } else {
  599. $this->setCookie($v);
  600. }
  601. }
  602. return $this;
  603. }
  604. if ($value !== null && $this->config['encodecookies']) {
  605. $value = urlencode($value);
  606. }
  607. if (isset($this->cookiejar)) {
  608. if ($cookie instanceof Zend_Http_Cookie) {
  609. $this->cookiejar->addCookie($cookie);
  610. } elseif (is_string($cookie) && $value !== null) {
  611. $cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}",
  612. $this->uri,
  613. $this->config['encodecookies']);
  614. $this->cookiejar->addCookie($cookie);
  615. }
  616. } else {
  617. if ($cookie instanceof Zend_Http_Cookie) {
  618. $name = $cookie->getName();
  619. $value = $cookie->getValue();
  620. $cookie = $name;
  621. }
  622. if (preg_match("/[=,; \t\r\n\013\014]/", $cookie)) {
  623. /** @see Zend_Http_Client_Exception */
  624. require_once 'Zend/Http/Client/Exception.php';
  625. throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\013\014 ({$cookie})");
  626. }
  627. $value = addslashes($value);
  628. if (! isset($this->headers['cookie'])) {
  629. $this->headers['cookie'] = array('Cookie', '');
  630. }
  631. $this->headers['cookie'][1] .= $cookie . '=' . $value . '; ';
  632. }
  633. return $this;
  634. }
  635. /**
  636. * Set a file to upload (using a POST request)
  637. *
  638. * Can be used in two ways:
  639. *
  640. * 1. $data is null (default): $filename is treated as the name if a local file which
  641. * will be read and sent. Will try to guess the content type using mime_content_type().
  642. * 2. $data is set - $filename is sent as the file name, but $data is sent as the file
  643. * contents and no file is read from the file system. In this case, you need to
  644. * manually set the Content-Type ($ctype) or it will default to
  645. * application/octet-stream.
  646. *
  647. * @param string $filename Name of file to upload, or name to save as
  648. * @param string $formname Name of form element to send as
  649. * @param string $data Data to send (if null, $filename is read and sent)
  650. * @param string $ctype Content type to use (if $data is set and $ctype is
  651. * null, will be application/octet-stream)
  652. * @return Zend_Http_Client
  653. * @throws Zend_Http_Client_Exception
  654. */
  655. public function setFileUpload($filename, $formname, $data = null, $ctype = null)
  656. {
  657. if ($data === null) {
  658. if (($data = @file_get_contents($filename)) === false) {
  659. /** @see Zend_Http_Client_Exception */
  660. require_once 'Zend/Http/Client/Exception.php';
  661. throw new Zend_Http_Client_Exception("Unable to read file '{$filename}' for upload");
  662. }
  663. if (! $ctype) {
  664. $ctype = $this->_detectFileMimeType($filename);
  665. }
  666. }
  667. // Force enctype to multipart/form-data
  668. $this->setEncType(self::ENC_FORMDATA);
  669. $this->files[] = array(
  670. 'formname' => $formname,
  671. 'filename' => basename($filename),
  672. 'ctype' => $ctype,
  673. 'data' => $data
  674. );
  675. $this->body_field_order[$formname] = self::VTYPE_FILE;
  676. return $this;
  677. }
  678. /**
  679. * Set the encoding type for POST data
  680. *
  681. * @param string $enctype
  682. * @return Zend_Http_Client
  683. */
  684. public function setEncType($enctype = self::ENC_URLENCODED)
  685. {
  686. $this->enctype = $enctype;
  687. return $this;
  688. }
  689. /**
  690. * Set the raw (already encoded) POST data.
  691. *
  692. * This function is here for two reasons:
  693. * 1. For advanced user who would like to set their own data, already encoded
  694. * 2. For backwards compatibilty: If someone uses the old post($data) method.
  695. * this method will be used to set the encoded data.
  696. *
  697. * $data can also be stream (such as file) from which the data will be read.
  698. *
  699. * @param string|resource $data
  700. * @param string $enctype
  701. * @return Zend_Http_Client
  702. */
  703. public function setRawData($data, $enctype = null)
  704. {
  705. $this->raw_post_data = $data;
  706. $this->setEncType($enctype);
  707. if (is_resource($data)) {
  708. // We've got stream data
  709. $stat = @fstat($data);
  710. if($stat) {
  711. $this->setHeaders(self::CONTENT_LENGTH, $stat['size']);
  712. }
  713. }
  714. return $this;
  715. }
  716. /**
  717. * Set the unmask feature for GET parameters as array
  718. *
  719. * Example:
  720. * foo%5B0%5D=a&foo%5B1%5D=b
  721. * becomes
  722. * foo=a&foo=b
  723. *
  724. * This is usefull for some services
  725. *
  726. * @param boolean $status
  727. * @return Zend_Http_Client
  728. */
  729. public function setUnmaskStatus($status = true)
  730. {
  731. $this->_unmaskStatus = (BOOL)$status;
  732. return $this;
  733. }
  734. /**
  735. * Returns the currently configured unmask status
  736. *
  737. * @return boolean
  738. */
  739. public function getUnmaskStatus()
  740. {
  741. return $this->_unmaskStatus;
  742. }
  743. /**
  744. * Clear all GET and POST parameters
  745. *
  746. * Should be used to reset the request parameters if the client is
  747. * used for several concurrent requests.
  748. *
  749. * clearAll parameter controls if we clean just parameters or also
  750. * headers and last_*
  751. *
  752. * @param bool $clearAll Should all data be cleared?
  753. * @return Zend_Http_Client
  754. */
  755. public function resetParameters($clearAll = false)
  756. {
  757. // Reset parameter data
  758. $this->paramsGet = array();
  759. $this->paramsPost = array();
  760. $this->files = array();
  761. $this->raw_post_data = null;
  762. $this->enctype = null;
  763. if($clearAll) {
  764. $this->headers = array();
  765. $this->last_request = null;
  766. $this->last_response = null;
  767. } else {
  768. // Clear outdated headers
  769. if (isset($this->headers[strtolower(self::CONTENT_TYPE)])) {
  770. unset($this->headers[strtolower(self::CONTENT_TYPE)]);
  771. }
  772. if (isset($this->headers[strtolower(self::CONTENT_LENGTH)])) {
  773. unset($this->headers[strtolower(self::CONTENT_LENGTH)]);
  774. }
  775. }
  776. return $this;
  777. }
  778. /**
  779. * Get the last HTTP request as string
  780. *
  781. * @return string
  782. */
  783. public function getLastRequest()
  784. {
  785. return $this->last_request;
  786. }
  787. /**
  788. * Get the last HTTP response received by this client
  789. *
  790. * If $config['storeresponse'] is set to false, or no response was
  791. * stored yet, will return null
  792. *
  793. * @return Zend_Http_Response or null if none
  794. */
  795. public function getLastResponse()
  796. {
  797. return $this->last_response;
  798. }
  799. /**
  800. * Load the connection adapter
  801. *
  802. * While this method is not called more than one for a client, it is
  803. * seperated from ->request() to preserve logic and readability
  804. *
  805. * @param Zend_Http_Client_Adapter_Interface|string $adapter
  806. * @return null
  807. * @throws Zend_Http_Client_Exception
  808. */
  809. public function setAdapter($adapter)
  810. {
  811. if (is_string($adapter)) {
  812. try {
  813. Zend_Loader::loadClass($adapter);
  814. } catch (Zend_Exception $e) {
  815. /** @see Zend_Http_Client_Exception */
  816. require_once 'Zend/Http/Client/Exception.php';
  817. throw new Zend_Http_Client_Exception("Unable to load adapter '$adapter': {$e->getMessage()}", 0, $e);
  818. }
  819. $adapter = new $adapter;
  820. }
  821. if (! $adapter instanceof Zend_Http_Client_Adapter_Interface) {
  822. /** @see Zend_Http_Client_Exception */
  823. require_once 'Zend/Http/Client/Exception.php';
  824. throw new Zend_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
  825. }
  826. $this->adapter = $adapter;
  827. $config = $this->config;
  828. unset($config['adapter']);
  829. $this->adapter->setConfig($config);
  830. }
  831. /**
  832. * Load the connection adapter
  833. *
  834. * @return Zend_Http_Client_Adapter_Interface $adapter
  835. */
  836. public function getAdapter()
  837. {
  838. if (null === $this->adapter) {
  839. $this->setAdapter($this->config['adapter']);
  840. }
  841. return $this->adapter;
  842. }
  843. /**
  844. * Set streaming for received data
  845. *
  846. * @param string|boolean $streamfile Stream file, true for temp file, false/null for no streaming
  847. * @return Zend_Http_Client
  848. */
  849. public function setStream($streamfile = true)
  850. {
  851. $this->setConfig(array("output_stream" => $streamfile));
  852. return $this;
  853. }
  854. /**
  855. * Get status of streaming for received data
  856. * @return boolean|string
  857. */
  858. public function getStream()
  859. {
  860. return $this->config["output_stream"];
  861. }
  862. /**
  863. * Create temporary stream
  864. *
  865. * @return resource
  866. */
  867. protected function _openTempStream()
  868. {
  869. $this->_stream_name = $this->config['output_stream'];
  870. if(!is_string($this->_stream_name)) {
  871. // If name is not given, create temp name
  872. $this->_stream_name = tempnam(isset($this->config['stream_tmp_dir'])?$this->config['stream_tmp_dir']:sys_get_temp_dir(),
  873. 'Zend_Http_Client');
  874. }
  875. if (false === ($fp = @fopen($this->_stream_name, "w+b"))) {
  876. if ($this->adapter instanceof Zend_Http_Client_Adapter_Interface) {
  877. $this->adapter->close();
  878. }
  879. require_once 'Zend/Http/Client/Exception.php';
  880. throw new Zend_Http_Client_Exception("Could not open temp file {$this->_stream_name}");
  881. }
  882. return $fp;
  883. }
  884. /**
  885. * Send the HTTP request and return an HTTP response object
  886. *
  887. * @param string $method
  888. * @return Zend_Http_Response
  889. * @throws Zend_Http_Client_Exception
  890. */
  891. public function request($method = null)
  892. {
  893. if (! $this->uri instanceof Zend_Uri_Http) {
  894. /** @see Zend_Http_Client_Exception */
  895. require_once 'Zend/Http/Client/Exception.php';
  896. throw new Zend_Http_Client_Exception('No valid URI has been passed to the client');
  897. }
  898. if ($method) {
  899. $this->setMethod($method);
  900. }
  901. $this->redirectCounter = 0;
  902. $response = null;
  903. // Make sure the adapter is loaded
  904. if ($this->adapter == null) {
  905. $this->setAdapter($this->config['adapter']);
  906. }
  907. // Send the first request. If redirected, continue.
  908. do {
  909. // Clone the URI and add the additional GET parameters to it
  910. $uri = clone $this->uri;
  911. if (! empty($this->paramsGet)) {
  912. $query = $uri->getQuery();
  913. if (! empty($query)) {
  914. $query .= '&';
  915. }
  916. $query .= http_build_query($this->paramsGet, null, '&');
  917. if ($this->config['rfc3986_strict']) {
  918. $query = str_replace('+', '%20', $query);
  919. }
  920. // @see ZF-11671 to unmask for some services to foo=val1&foo=val2
  921. if ($this->getUnmaskStatus()) {
  922. if ($this->_queryBracketsEscaped) {
  923. $query = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $query);
  924. } else {
  925. $query = preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/', '=', $query);
  926. }
  927. }
  928. $uri->setQuery($query);
  929. }
  930. $body = $this->_prepareBody();
  931. $headers = $this->_prepareHeaders();
  932. // check that adapter supports streaming before using it
  933. if(is_resource($body) && !($this->adapter instanceof Zend_Http_Client_Adapter_Stream)) {
  934. /** @see Zend_Http_Client_Exception */
  935. require_once 'Zend/Http/Client/Exception.php';
  936. throw new Zend_Http_Client_Exception('Adapter does not support streaming');
  937. }
  938. // Open the connection, send the request and read the response
  939. $this->adapter->connect($uri->getHost(), $uri->getPort(),
  940. ($uri->getScheme() == 'https' ? true : false));
  941. if($this->config['output_stream']) {
  942. if($this->adapter instanceof Zend_Http_Client_Adapter_Stream) {
  943. $stream = $this->_openTempStream();
  944. $this->adapter->setOutputStream($stream);
  945. } else {
  946. /** @see Zend_Http_Client_Exception */
  947. require_once 'Zend/Http/Client/Exception.php';
  948. throw new Zend_Http_Client_Exception('Adapter does not support streaming');
  949. }
  950. }
  951. $this->last_request = $this->adapter->write($this->method,
  952. $uri, $this->config['httpversion'], $headers, $body);
  953. $response = $this->adapter->read();
  954. if (! $response) {
  955. /** @see Zend_Http_Client_Exception */
  956. require_once 'Zend/Http/Client/Exception.php';
  957. throw new Zend_Http_Client_Exception('Unable to read response, or response is empty');
  958. }
  959. if($this->config['output_stream']) {
  960. $streamMetaData = stream_get_meta_data($stream);
  961. if ($streamMetaData['seekable']) {
  962. rewind($stream);
  963. }
  964. // cleanup the adapter
  965. $this->adapter->setOutputStream(null);
  966. $response = Zend_Http_Response_Stream::fromStream($response, $stream);
  967. $response->setStreamName($this->_stream_name);
  968. if(!is_string($this->config['output_stream'])) {
  969. // we used temp name, will need to clean up
  970. $response->setCleanup(true);
  971. }
  972. } else {
  973. $response = Zend_Http_Response::fromString($response);
  974. }
  975. if ($this->config['storeresponse']) {
  976. $this->last_response = $response;
  977. }
  978. // Load cookies into cookie jar
  979. if (isset($this->cookiejar)) {
  980. $this->cookiejar->addCookiesFromResponse($response, $uri, $this->config['encodecookies']);
  981. }
  982. // If we got redirected, look for the Location header
  983. if ($response->isRedirect() && ($location = $response->getHeader('location'))) {
  984. // Avoid problems with buggy servers that add whitespace at the
  985. // end of some headers (See ZF-11283)
  986. $location = trim($location);
  987. // Check whether we send the exact same request again, or drop the parameters
  988. // and send a GET request
  989. if ($response->getStatus() == 303 ||
  990. ((! $this->config['strictredirects']) && ($response->getStatus() == 302 ||
  991. $response->getStatus() == 301))) {
  992. $this->resetParameters();
  993. $this->setMethod(self::GET);
  994. }
  995. // If we got a well formed absolute URI
  996. if (($scheme = substr($location, 0, 6)) && ($scheme == 'http:/' || $scheme == 'https:')) {
  997. $this->setHeaders('host', null);
  998. $this->setUri($location);
  999. } else {
  1000. // Split into path and query and set the query
  1001. if (strpos($location, '?') !== false) {
  1002. list($location, $query) = explode('?', $location, 2);
  1003. } else {
  1004. $query = '';
  1005. }
  1006. $this->uri->setQuery($query);
  1007. // Else, if we got just an absolute path, set it
  1008. if(strpos($location, '/') === 0) {
  1009. $this->uri->setPath($location);
  1010. // Else, assume we have a relative path
  1011. } else {
  1012. // Get the current path directory, removing any trailing slashes
  1013. $path = $this->uri->getPath();
  1014. $path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
  1015. $this->uri->setPath($path . '/' . $location);
  1016. }
  1017. }
  1018. ++$this->redirectCounter;
  1019. } else {
  1020. // If we didn't get any location, stop redirecting
  1021. break;
  1022. }
  1023. } while ($this->redirectCounter < $this->config['maxredirects']);
  1024. return $response;
  1025. }
  1026. /**
  1027. * Prepare the request headers
  1028. *
  1029. * @return array
  1030. */
  1031. protected function _prepareHeaders()
  1032. {
  1033. $headers = array();
  1034. // Set the host header
  1035. if (! isset($this->headers['host'])) {
  1036. $host = $this->uri->getHost();
  1037. // If the port is not default, add it
  1038. if (! (($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80) ||
  1039. ($this->uri->getScheme() == 'https' && $this->uri->getPort() == 443))) {
  1040. $host .= ':' . $this->uri->getPort();
  1041. }
  1042. $headers[] = "Host: {$host}";
  1043. }
  1044. // Set the connection header
  1045. if (! isset($this->headers['connection'])) {
  1046. if (! $this->config['keepalive']) {
  1047. $headers[] = "Connection: close";
  1048. }
  1049. }
  1050. // Set the Accept-encoding header if not set - depending on whether
  1051. // zlib is available or not.
  1052. if (! isset($this->headers['accept-encoding'])) {
  1053. if (function_exists('gzinflate')) {
  1054. $headers[] = 'Accept-encoding: gzip, deflate';
  1055. } else {
  1056. $headers[] = 'Accept-encoding: identity';
  1057. }
  1058. }
  1059. // Set the Content-Type header
  1060. if (($this->method == self::POST || $this->method == self::PUT) &&
  1061. (! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
  1062. $headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
  1063. }
  1064. // Set the user agent header
  1065. if (! isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
  1066. $headers[] = "User-Agent: {$this->config['useragent']}";
  1067. }
  1068. // Set HTTP authentication if needed
  1069. if (is_array($this->auth)) {
  1070. $auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
  1071. $headers[] = "Authorization: {$auth}";
  1072. }
  1073. // Load cookies from cookie jar
  1074. if (isset($this->cookiejar)) {
  1075. $cookstr = $this->cookiejar->getMatchingCookies($this->uri,
  1076. true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
  1077. if ($cookstr) {
  1078. $headers[] = "Cookie: {$cookstr}";
  1079. }
  1080. }
  1081. // Add all other user defined headers
  1082. foreach ($this->headers as $header) {
  1083. list($name, $value) = $header;
  1084. if (is_array($value)) {
  1085. $value = implode(', ', $value);
  1086. }
  1087. $headers[] = "$name: $value";
  1088. }
  1089. return $headers;
  1090. }
  1091. /**
  1092. * Prepare the request body (for POST and PUT requests)
  1093. *
  1094. * @return string
  1095. * @throws Zend_Http_Client_Exception
  1096. */
  1097. protected function _prepareBody()
  1098. {
  1099. // According to RFC2616, a TRACE request should not have a body.
  1100. if ($this->method == self::TRACE) {
  1101. return '';
  1102. }
  1103. if (isset($this->raw_post_data) && is_resource($this->raw_post_data)) {
  1104. return $this->raw_post_data;
  1105. }
  1106. // If mbstring overloads substr and strlen functions, we have to
  1107. // override it's internal encoding
  1108. if (function_exists('mb_internal_encoding') &&
  1109. ((int) ini_get('mbstring.func_overload')) & 2) {
  1110. $mbIntEnc = mb_internal_encoding();
  1111. mb_internal_encoding('ASCII');
  1112. }
  1113. // If we have raw_post_data set, just use it as the body.
  1114. if (isset($this->raw_post_data)) {
  1115. $this->setHeaders(self::CONTENT_LENGTH, strlen($this->raw_post_data));
  1116. if (isset($mbIntEnc)) {
  1117. mb_internal_encoding($mbIntEnc);
  1118. }
  1119. return $this->raw_post_data;
  1120. }
  1121. $body = '';
  1122. // If we have files to upload, force enctype to multipart/form-data
  1123. if (count ($this->files) > 0) {
  1124. $this->setEncType(self::ENC_FORMDATA);
  1125. }
  1126. // If we have POST parameters or files, encode and add them to the body
  1127. if (count($this->paramsPost) > 0 || count($this->files) > 0) {
  1128. switch($this->enctype) {
  1129. case self::ENC_FORMDATA:
  1130. // Encode body as multipart/form-data
  1131. $boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
  1132. $this->setHeaders(self::CONTENT_TYPE, self::ENC_FORMDATA . "; boundary={$boundary}");
  1133. // Encode all files and POST vars in the order they were given
  1134. foreach ($this->body_field_order as $fieldName=>$fieldType) {
  1135. switch ($fieldType) {
  1136. case self::VTYPE_FILE:
  1137. foreach ($this->files as $file) {
  1138. if ($file['formname']===$fieldName) {
  1139. $fhead = array(self::CONTENT_TYPE => $file['ctype']);
  1140. $body .= self::encodeFormData($boundary, $file['formname'], $file['data'], $file['filename'], $fhead);
  1141. }
  1142. }
  1143. break;
  1144. case self::VTYPE_SCALAR:
  1145. if (isset($this->paramsPost[$fieldName])) {
  1146. if (is_array($this->paramsPost[$fieldName])) {
  1147. $flattened = self::_flattenParametersArray($this->paramsPost[$fieldName], $fieldName);
  1148. foreach ($flattened as $pp) {
  1149. $body .= self::encodeFormData($boundary, $pp[0], $pp[1]);
  1150. }
  1151. } else {
  1152. $body .= self::encodeFormData($boundary, $fieldName, $this->paramsPost[$fieldName]);
  1153. }
  1154. }
  1155. break;
  1156. }
  1157. }
  1158. $body .= "--{$boundary}--\r\n";
  1159. break;
  1160. case self::ENC_URLENCODED:
  1161. // Encode body as application/x-www-form-urlencoded
  1162. $this->setHeaders(self::CONTENT_TYPE, self::ENC_URLENCODED);
  1163. $body = http_build_query($this->paramsPost, '', '&');
  1164. break;
  1165. default:
  1166. if (isset($mbIntEnc)) {
  1167. mb_internal_encoding($mbIntEnc);
  1168. }
  1169. /** @see Zend_Http_Client_Exception */
  1170. require_once 'Zend/Http/Client/Exception.php';
  1171. throw new Zend_Http_Client_Exception("Cannot handle content type '{$this->enctype}' automatically." .
  1172. " Please use Zend_Http_Client::setRawData to send this kind of content.");
  1173. break;
  1174. }
  1175. }
  1176. // Set the Content-Length if we have a body or if request is POST/PUT
  1177. if ($body || $this->method == self::POST || $this->method == self::PUT) {
  1178. $this->setHeaders(self::CONTENT_LENGTH, strlen($body));
  1179. }
  1180. if (isset($mbIntEnc)) {
  1181. mb_internal_encoding($mbIntEnc);
  1182. }
  1183. return $body;
  1184. }
  1185. /**
  1186. * Helper method that gets a possibly multi-level parameters array (get or
  1187. * post) and flattens it.
  1188. *
  1189. * The method returns an array of (key, value) pairs (because keys are not
  1190. * necessarily unique. If one of the parameters in as array, it will also
  1191. * add a [] suffix to the key.
  1192. *
  1193. * This method is deprecated since Zend Framework 1.9 in favour of
  1194. * self::_flattenParametersArray() and will be dropped in 2.0
  1195. *
  1196. * @deprecated since 1.9
  1197. *
  1198. * @param array $parray The parameters array
  1199. * @param bool $urlencode Whether to urlencode the name and value
  1200. * @return array
  1201. */
  1202. protected function _getParametersRecursive($parray, $urlencode = false)
  1203. {
  1204. // Issue a deprecated notice
  1205. trigger_error("The " . __METHOD__ . " method is deprecated and will be dropped in 2.0.",
  1206. E_USER_NOTICE);
  1207. if (! is_array($parray)) {
  1208. return $parray;
  1209. }
  1210. $parameters = array();
  1211. foreach ($parray as $name => $value) {
  1212. if ($urlencode) {
  1213. $name = urlencode($name);
  1214. }
  1215. // If $value is an array, iterate over it
  1216. if (is_array($value)) {
  1217. $name .= ($urlencode ? '%5B%5D' : '[]');
  1218. foreach ($value as $subval) {
  1219. if ($urlencode) {
  1220. $subval = urlencode($subval);
  1221. }
  1222. $parameters[] = array($name, $subval);
  1223. }
  1224. } else {
  1225. if ($urlencode) {
  1226. $value = urlencode($value);
  1227. }
  1228. $parameters[] = array($name, $value);
  1229. }
  1230. }
  1231. return $parameters;
  1232. }
  1233. /**
  1234. * Attempt to detect the MIME type of a file using available extensions
  1235. *
  1236. * This method will try to detect the MIME type of a file. If the fileinfo
  1237. * extension is available, it will be used. If not, the mime_magic
  1238. * extension which is deprected but is still available in many PHP setups
  1239. * will be tried.
  1240. *
  1241. * If neither extension is available, the default application/octet-stream
  1242. * MIME type will be returned
  1243. *
  1244. * @param string $file File path
  1245. * @return string MIME type
  1246. */
  1247. protected function _detectFileMimeType($file)
  1248. {
  1249. $type = null;
  1250. // First try with fileinfo functions
  1251. if (function_exists('finfo_open')) {
  1252. if (self::$_fileInfoDb === null) {
  1253. self::$_fileInfoDb = @finfo_open(FILEINFO_MIME);
  1254. }
  1255. if (self::$_fileInfoDb) {
  1256. $type = finfo_file(self::$_fileInfoDb, $file);
  1257. }
  1258. } elseif (function_exists('mime_content_type')) {
  1259. $type = mime_content_type($file);
  1260. }
  1261. // Fallback to the default application/octet-stream
  1262. if (! $type) {
  1263. $type = 'application/octet-stream';
  1264. }
  1265. return $type;
  1266. }
  1267. /**
  1268. * Encode data to a multipart/form-data part suitable for a POST request.
  1269. *
  1270. * @param string $boundary
  1271. * @param string $name
  1272. * @param mixed $value
  1273. * @param string $filename
  1274. * @param array $headers Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary")
  1275. * @return string
  1276. */
  1277. public static function encodeFormData($boundary, $name, $value, $filename = null, $headers = array()) {
  1278. $ret = "--{$boundary}\r\n" .
  1279. 'Content-Disposition: form-data; name="' . $name .'"';
  1280. if ($filename) {
  1281. $ret .= '; filename="' . $filename . '"';
  1282. }
  1283. $ret .= "\r\n";
  1284. foreach ($headers as $hname => $hvalue) {
  1285. $ret .= "{$hname}: {$hvalue}\r\n";
  1286. }
  1287. $ret .= "\r\n";
  1288. $ret .= "{$value}\r\n";
  1289. return $ret;
  1290. }
  1291. /**
  1292. * Create a HTTP authentication "Authorization:" header according to the
  1293. * specified user, password and authentication method.
  1294. *
  1295. * @see http://www.faqs.org/rfcs/rfc2617.html
  1296. * @param string $user
  1297. * @param string $password
  1298. * @param string $type
  1299. * @return string
  1300. * @throws Zend_Http_Client_Exception
  1301. */
  1302. public static function encodeAuthHeader($user, $password, $type = self::AUTH_BASIC)
  1303. {
  1304. $authHeader = null;
  1305. switch ($type) {
  1306. case self::AUTH_BASIC:
  1307. // In basic authentication, the user name cannot contain ":"
  1308. if (strpos($user, ':') !== false) {
  1309. /** @see Zend_Http_Client_Exception */
  1310. require_once 'Zend/Http/Client/Exception.php';
  1311. throw new Zend_Http_Client_Exception("The user name cannot contain ':' in 'Basic' HTTP authentication");
  1312. }
  1313. $authHeader = 'Basic ' . base64_encode($user . ':' . $password);
  1314. break;
  1315. //case self::AUTH_DIGEST:
  1316. /**
  1317. * @todo Implement digest authentication
  1318. */
  1319. // break;
  1320. default:
  1321. /** @see Zend_Http_Client_Exception */
  1322. require_once 'Zend/Http/Client/Exception.php';
  1323. throw new Zend_Http_Client_Exception("Not a supported HTTP authentication type: '$type'");
  1324. }
  1325. return $authHeader;
  1326. }
  1327. /**
  1328. * Convert an array of parameters into a flat array of (key, value) pairs
  1329. *
  1330. * Will flatten a potentially multi-dimentional array of parameters (such
  1331. * as POST parameters) into a flat array of (key, value) paris. In case
  1332. * of multi-dimentional arrays, square brackets ([]) will be added to the
  1333. * key to indicate an array.
  1334. *
  1335. * @since 1.9
  1336. *
  1337. * @param array $parray
  1338. * @param string $prefix
  1339. * @return array
  1340. */
  1341. static protected function _flattenParametersArray($parray, $prefix = null)
  1342. {
  1343. if (! is_array($parray)) {
  1344. return $parray;
  1345. }
  1346. $parameters = array();
  1347. foreach($parray as $name => $value) {
  1348. // Calculate array key
  1349. if ($prefix) {
  1350. if (is_int($name)) {
  1351. $key = $prefix . '[]';
  1352. } else {
  1353. $key = $prefix . "[$name]";

Large files files are truncated, but you can click here to view the full file