Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Curl.php

class Curl

Tries to retrieve JSON schemas from a URI using cURL library

@author Sander Coolen <sander@jibber.nl>

Hierarchy

  • class \JsonSchema\Uri\Retrievers\AbstractRetriever implements \JsonSchema\Uri\Retrievers\UriRetrieverInterface
    • class \JsonSchema\Uri\Retrievers\Curl extends \JsonSchema\Uri\Retrievers\AbstractRetriever

Expanded class hierarchy of Curl

4 string references to 'Curl'
CurlClient::available in vendor/open-telemetry/sdk/Common/Http/Psr/Client/Discovery/CurlClient.php
@phan-suppress PhanUndeclaredClassReference
DiagnoseCommand::getCurlVersion in vendor/composer/composer/src/Composer/Command/DiagnoseCommand.php
HttpDownloader::isCurlEnabled in vendor/composer/composer/src/Composer/Util/HttpDownloader.php
@internal
PlatformRepository::initialize in vendor/composer/composer/src/Composer/Repository/PlatformRepository.php
Initializes the packages array. Mostly meant as an extension point.

File

vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/Curl.php, line 20

Namespace

JsonSchema\Uri\Retrievers
View source
class Curl extends AbstractRetriever {
    protected $messageBody;
    public function __construct() {
        if (!function_exists('curl_init')) {
            // Cannot test this, because curl_init is present on all test platforms plus mock
            throw new RuntimeException('cURL not installed');
            // @codeCoverageIgnore
        }
    }
    
    /**
     * {@inheritdoc}
     *
     * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
     */
    public function retrieve($uri) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $uri);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: ' . Validator::SCHEMA_MEDIA_TYPE,
        ));
        $response = curl_exec($ch);
        if (false === $response) {
            throw new \JsonSchema\Exception\ResourceNotFoundException('JSON schema not found');
        }
        $this->fetchMessageBody($response);
        $this->fetchContentType($response);
        curl_close($ch);
        return $this->messageBody;
    }
    
    /**
     * @param string $response cURL HTTP response
     */
    private function fetchMessageBody($response) {
        preg_match("/(?:\r\n){2}(.*)\$/ms", $response, $match);
        $this->messageBody = $match[1];
    }
    
    /**
     * @param string $response cURL HTTP response
     *
     * @return bool Whether the Content-Type header was found or not
     */
    protected function fetchContentType($response) {
        if (0 < preg_match("/Content-Type:(\\V*)/ims", $response, $match)) {
            $this->contentType = trim($match[1]);
            return true;
        }
        return false;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractRetriever::$contentType protected property Media content type
AbstractRetriever::getContentType public function Overrides UriRetrieverInterface::getContentType
Curl::$messageBody protected property
Curl::fetchContentType protected function
Curl::fetchMessageBody private function
Curl::retrieve public function Overrides UriRetrieverInterface::retrieve
Curl::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal