[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/Requests/src/ -> Port.php (source)

   1  <?php
   2  /**
   3   * Port utilities for Requests
   4   *
   5   * @package Requests\Utilities
   6   * @since   2.0.0
   7   */
   8  
   9  namespace WpOrg\Requests;
  10  
  11  use WpOrg\Requests\Exception;
  12  use WpOrg\Requests\Exception\InvalidArgument;
  13  
  14  /**
  15   * Find the correct port depending on the Request type.
  16   *
  17   * @package Requests\Utilities
  18   * @since   2.0.0
  19   */
  20  final class Port {
  21  
  22      /**
  23       * Port to use with Acap requests.
  24       *
  25       * @var int
  26       */
  27      const ACAP = 674;
  28  
  29      /**
  30       * Port to use with Dictionary requests.
  31       *
  32       * @var int
  33       */
  34      const DICT = 2628;
  35  
  36      /**
  37       * Port to use with HTTP requests.
  38       *
  39       * @var int
  40       */
  41      const HTTP = 80;
  42  
  43      /**
  44       * Port to use with HTTP over SSL requests.
  45       *
  46       * @var int
  47       */
  48      const HTTPS = 443;
  49  
  50      /**
  51       * Retrieve the port number to use.
  52       *
  53       * @param string $type Request type.
  54       *                     The following requests types are supported:
  55       *                     'acap', 'dict', 'http' and 'https'.
  56       *
  57       * @return int
  58       *
  59       * @throws \WpOrg\Requests\Exception\InvalidArgument When a non-string input has been passed.
  60       * @throws \WpOrg\Requests\Exception                 When a non-supported port is requested ('portnotsupported').
  61       */
  62  	public static function get($type) {
  63          if (!is_string($type)) {
  64              throw InvalidArgument::create(1, '$type', 'string', gettype($type));
  65          }
  66  
  67          $type = strtoupper($type);
  68          if (!defined("self::{$type}")) {
  69              $message = sprintf('Invalid port type (%s) passed', $type);
  70              throw new Exception($message, 'portnotsupported');
  71          }
  72  
  73          return constant("self::{$type}");
  74      }
  75  }


Generated : Sun Apr 28 08:20:02 2024 Cross-referenced by PHPXref