[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Part of the Joomla Framework Http Package 4 * 5 * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE 7 */ 8 9 namespace Joomla\Http; 10 11 /** 12 * Abstract transport class. 13 * 14 * @since 2.0.0 15 */ 16 abstract class AbstractTransport implements TransportInterface 17 { 18 /** 19 * The client options. 20 * 21 * @var array|\ArrayAccess 22 * @since 2.0.0 23 */ 24 protected $options; 25 26 /** 27 * Constructor. 28 * 29 * @param array|\ArrayAccess $options Client options array. 30 * 31 * @since 2.0.0 32 * @throws \RuntimeException 33 */ 34 public function __construct($options = []) 35 { 36 if (!static::isSupported()) 37 { 38 throw new \RuntimeException(sprintf('The %s transport is not supported in this environment.', \get_class($this))); 39 } 40 41 if (!\is_array($options) && !($options instanceof \ArrayAccess)) 42 { 43 throw new \InvalidArgumentException( 44 'The options param must be an array or implement the ArrayAccess interface.' 45 ); 46 } 47 48 $this->options = $options; 49 } 50 51 /** 52 * Get an option from the HTTP transport. 53 * 54 * @param string $key The name of the option to get. 55 * @param mixed $default The default value if the option is not set. 56 * 57 * @return mixed The option value. 58 * 59 * @since 2.0.0 60 */ 61 protected function getOption(string $key, $default = null) 62 { 63 return $this->options[$key] ?? $default; 64 } 65 66 /** 67 * Processes the headers from a transport's response data. 68 * 69 * @param array $headers The headers to process. 70 * 71 * @return array 72 * 73 * @since 2.0.0 74 */ 75 protected function processHeaders(array $headers): array 76 { 77 $verifiedHeaders = []; 78 79 // Add the response headers to the response object. 80 foreach ($headers as $header) 81 { 82 $pos = strpos($header, ':'); 83 $keyName = trim(substr($header, 0, $pos)); 84 85 if (!isset($verifiedHeaders[$keyName])) 86 { 87 $verifiedHeaders[$keyName] = []; 88 } 89 90 $verifiedHeaders[$keyName][] = trim(substr($header, ($pos + 1))); 91 } 92 93 return $verifiedHeaders; 94 } 95 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |