idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
34,600
public static function fromMessage ( $ message ) { $ data = ParserRegistry :: getInstance ( ) -> getParser ( 'message' ) -> parseResponse ( $ message ) ; if ( ! $ data ) { return false ; } $ response = new static ( $ data [ 'code' ] , $ data [ 'headers' ] , $ data [ 'body' ] ) ; $ response -> setProtocol ( $ data [ 'pr...
Create a new Response based on a raw response message
34,601
public function setProtocol ( $ protocol , $ version ) { $ this -> protocol = $ protocol ; $ this -> protocolVersion = $ version ; return $ this ; }
Set the protocol and protocol version of the response
34,602
public function getInfo ( $ key = null ) { if ( $ key === null ) { return $ this -> info ; } elseif ( array_key_exists ( $ key , $ this -> info ) ) { return $ this -> info [ $ key ] ; } else { return null ; } }
Get a cURL transfer information
34,603
public function setStatus ( $ statusCode , $ reasonPhrase = '' ) { $ this -> statusCode = ( int ) $ statusCode ; if ( ! $ reasonPhrase && isset ( self :: $ statusTexts [ $ this -> statusCode ] ) ) { $ this -> reasonPhrase = self :: $ statusTexts [ $ this -> statusCode ] ; } else { $ this -> reasonPhrase = $ reasonPhras...
Set the response status
34,604
public function getMessage ( ) { $ message = $ this -> getRawHeaders ( ) ; $ size = $ this -> body -> getSize ( ) ; if ( $ size < 2097152 ) { $ message .= ( string ) $ this -> body ; } return $ message ; }
Get the entire response as a string
34,605
public function getRawHeaders ( ) { $ headers = 'HTTP/1.1 ' . $ this -> statusCode . ' ' . $ this -> reasonPhrase . "\r\n" ; $ lines = $ this -> getHeaderLines ( ) ; if ( ! empty ( $ lines ) ) { $ headers .= implode ( "\r\n" , $ lines ) . "\r\n" ; } return $ headers . "\r\n" ; }
Get the the raw message headers as a string
34,606
public function calculateAge ( ) { $ age = $ this -> getHeader ( 'Age' ) ; if ( $ age === null && $ this -> getDate ( ) ) { $ age = time ( ) - strtotime ( $ this -> getDate ( ) ) ; } return $ age === null ? null : ( int ) ( string ) $ age ; }
Calculate the age of the response
34,607
public function isMethodAllowed ( $ method ) { $ allow = $ this -> getHeader ( 'Allow' ) ; if ( $ allow ) { foreach ( explode ( ',' , $ allow ) as $ allowable ) { if ( ! strcasecmp ( trim ( $ allowable ) , $ method ) ) { return true ; } } } return false ; }
Check if an HTTP method is allowed by checking the Allow response header
34,608
public function canCache ( ) { if ( ! in_array ( ( int ) $ this -> getStatusCode ( ) , self :: $ cacheResponseCodes ) ) { return false ; } if ( ( ! $ this -> getBody ( ) -> isReadable ( ) || ! $ this -> getBody ( ) -> isSeekable ( ) ) && ( $ this -> getContentLength ( ) > 0 || $ this -> getTransferEncoding ( ) == 'chun...
Check if the response can be cached based on the response headers
34,609
public function getMaxAge ( ) { if ( $ header = $ this -> getHeader ( 'Cache-Control' ) ) { if ( $ age = $ header -> getDirective ( 's-maxage' ) ) { return $ age ; } if ( $ age = $ header -> getDirective ( 'max-age' ) ) { return $ age ; } } if ( $ this -> getHeader ( 'Expires' ) ) { return strtotime ( $ this -> getExpi...
Gets the number of seconds from the current time in which this response is still considered fresh
34,610
public function json ( ) { $ data = json_decode ( ( string ) $ this -> body , true ) ; if ( JSON_ERROR_NONE !== json_last_error ( ) ) { throw new RuntimeException ( 'Unable to parse response body into JSON: ' . json_last_error ( ) ) ; } return $ data === null ? array ( ) : $ data ; }
Parse the JSON response body and return an array
34,611
public function xml ( ) { $ errorMessage = null ; $ internalErrors = libxml_use_internal_errors ( true ) ; $ disableEntities = libxml_disable_entity_loader ( true ) ; libxml_clear_errors ( ) ; try { $ xml = new \ SimpleXMLElement ( ( string ) $ this -> body ? : '<root />' , LIBXML_NONET ) ; if ( $ error = libxml_get_la...
Parse the XML response body and return a \ SimpleXMLElement .
34,612
public static function factory ( $ resource = '' , $ size = null ) { if ( $ resource instanceof EntityBodyInterface ) { return $ resource ; } switch ( gettype ( $ resource ) ) { case 'string' : return self :: fromString ( $ resource ) ; case 'resource' : return new static ( $ resource , $ size ) ; case 'object' : if ( ...
Create a new EntityBody based on the input type
34,613
public static function fromString ( $ string ) { $ stream = fopen ( 'php://temp' , 'r+' ) ; if ( $ string !== '' ) { fwrite ( $ stream , $ string ) ; rewind ( $ stream ) ; } return new static ( $ stream ) ; }
Create a new EntityBody from a string
34,614
public static function calculateMd5 ( EntityBodyInterface $ body , $ rawOutput = false , $ base64Encode = false ) { Version :: warn ( __CLASS__ . ' is deprecated. Use getContentMd5()' ) ; return $ body -> getContentMd5 ( $ rawOutput , $ base64Encode ) ; }
Calculate the MD5 hash of an entity body
34,615
protected function setContextValue ( $ wrapper , $ name , $ value , $ overwrite = false ) { if ( ! isset ( $ this -> contextOptions [ $ wrapper ] ) ) { $ this -> contextOptions [ $ wrapper ] = array ( $ name => $ value ) ; } elseif ( ! $ overwrite && isset ( $ this -> contextOptions [ $ wrapper ] [ $ name ] ) ) { retur...
Set an option on the context and the internal options array
34,616
protected function createContext ( array $ params ) { $ options = $ this -> contextOptions ; $ this -> context = $ this -> createResource ( function ( ) use ( $ params , $ options ) { return stream_context_create ( $ options , $ params ) ; } ) ; }
Create a stream context
34,617
protected function setUrl ( RequestInterface $ request ) { $ this -> url = $ request -> getUrl ( true ) ; if ( $ request -> getUsername ( ) ) { $ this -> url -> setUsername ( $ request -> getUsername ( ) ) ; } if ( $ request -> getPassword ( ) ) { $ this -> url -> setPassword ( $ request -> getPassword ( ) ) ; } }
Set the URL to use with the factory
34,618
protected function addSslOptions ( RequestInterface $ request ) { if ( $ request -> getCurlOptions ( ) -> get ( CURLOPT_SSL_VERIFYPEER ) ) { $ this -> setContextValue ( 'ssl' , 'verify_peer' , true , true ) ; if ( $ cafile = $ request -> getCurlOptions ( ) -> get ( CURLOPT_CAINFO ) ) { $ this -> setContextValue ( 'ssl'...
Add SSL options to the stream context
34,619
protected function addProxyOptions ( RequestInterface $ request ) { if ( $ proxy = $ request -> getCurlOptions ( ) -> get ( CURLOPT_PROXY ) ) { $ this -> setContextValue ( 'http' , 'proxy' , $ proxy ) ; } }
Add proxy parameters to the context if needed
34,620
protected function createStream ( array $ params ) { $ http_response_header = null ; $ url = $ this -> url ; $ context = $ this -> context ; $ fp = $ this -> createResource ( function ( ) use ( $ context , $ url , & $ http_response_header ) { return fopen ( ( string ) $ url , 'r' , false , $ context ) ; } ) ; $ classNa...
Create the stream for the request with the context options
34,621
protected function processResponseHeaders ( StreamInterface $ stream ) { foreach ( $ this -> lastResponseHeaders as $ header ) { if ( ( stripos ( $ header , 'Content-Length:' ) ) === 0 ) { $ stream -> setSize ( trim ( substr ( $ header , 15 ) ) ) ; } } }
Process response headers
34,622
private static function createObject ( $ className , array $ args = null ) { try { if ( ! $ args ) { return new $ className ; } else { $ c = new \ ReflectionClass ( $ className ) ; return $ c -> newInstanceArgs ( $ args ) ; } } catch ( \ Exception $ e ) { throw new RuntimeException ( $ e -> getMessage ( ) , $ e -> getC...
Create a class using an array of constructor arguments
34,623
protected function resolveRecursively ( array $ value , Parameter $ param ) { foreach ( $ value as $ name => & $ v ) { switch ( $ param -> getType ( ) ) { case 'object' : if ( $ subParam = $ param -> getProperty ( $ name ) ) { $ key = $ subParam -> getWireName ( ) ; $ value [ $ key ] = $ this -> prepareValue ( $ v , $ ...
Map nested parameters into the location_key based parameters
34,624
public function onCommandBeforeSend ( Event $ event ) { $ command = $ event [ 'command' ] ; if ( $ operation = $ command -> getOperation ( ) ) { if ( $ operation -> getErrorResponses ( ) ) { $ request = $ command -> getRequest ( ) ; $ request -> getEventDispatcher ( ) -> addListener ( 'request.complete' , $ this -> get...
Adds a listener to requests before they sent from a command
34,625
public static function getDebugPlugin ( $ wireBodies = true , $ stream = null ) { if ( $ stream === null ) { if ( defined ( 'STDERR' ) ) { $ stream = STDERR ; } else { $ stream = fopen ( 'php://output' , 'w' ) ; } } return new self ( new ClosureLogAdapter ( function ( $ m ) use ( $ stream ) { fwrite ( $ stream , $ m . ...
Get a log plugin that outputs full request response and curl error information to stderr
34,626
public function onCurlRead ( Event $ event ) { if ( $ wire = $ event [ 'request' ] -> getParams ( ) -> get ( 'request_wire' ) ) { $ wire -> write ( $ event [ 'read' ] ) ; } }
Event triggered when curl data is read from a request
34,627
public function onCurlWrite ( Event $ event ) { if ( $ wire = $ event [ 'request' ] -> getParams ( ) -> get ( 'response_wire' ) ) { $ wire -> write ( $ event [ 'write' ] ) ; } }
Event triggered when curl data is written to a response
34,628
public function onRequestBeforeSend ( Event $ event ) { if ( $ this -> wireBodies ) { $ request = $ event [ 'request' ] ; $ request -> getCurlOptions ( ) -> set ( 'emit_io' , true ) ; if ( $ request instanceof EntityEnclosingRequestInterface && $ request -> getBody ( ) && ( ! $ request -> getBody ( ) -> isSeekable ( ) ...
Called before a request is sent
34,629
public function onRequestSent ( Event $ event ) { $ request = $ event [ 'request' ] ; $ response = $ event [ 'response' ] ; $ handle = $ event [ 'handle' ] ; if ( $ wire = $ request -> getParams ( ) -> get ( 'request_wire' ) ) { $ request = clone $ request ; $ request -> setBody ( $ wire ) ; } if ( $ wire = $ request -...
Triggers the actual log write when a request completes
34,630
public static function mount ( $ className = 'Guzzle' , ClientInterface $ client = null ) { class_alias ( __CLASS__ , $ className ) ; if ( $ client ) { self :: $ client = $ client ; } }
Mount the client to a simpler class name for a specific client
34,631
public function getIterator ( ) { return new \ ArrayIterator ( array_map ( function ( $ entry ) { $ entry [ 'request' ] -> getParams ( ) -> set ( 'actual_response' , $ entry [ 'response' ] ) ; return $ entry [ 'request' ] ; } , $ this -> transactions ) ) ; }
Get the requests in the history
34,632
protected function createCurlHandle ( RequestInterface $ request ) { $ wrapper = CurlHandle :: factory ( $ request ) ; $ this -> handles [ $ request ] = $ wrapper ; $ this -> resourceHash [ ( int ) $ wrapper -> getHandle ( ) ] = $ request ; return $ wrapper ; }
Create a curl handle for a request
34,633
private function executeHandles ( ) { $ selectTimeout = 0.001 ; $ active = false ; do { while ( ( $ mrc = curl_multi_exec ( $ this -> multiHandle , $ active ) ) == CURLM_CALL_MULTI_PERFORM ) ; $ this -> checkCurlResult ( $ mrc ) ; $ this -> processMessages ( ) ; if ( $ active && curl_multi_select ( $ this -> multiHandl...
Execute and select curl handles
34,634
private function processMessages ( ) { while ( $ done = curl_multi_info_read ( $ this -> multiHandle ) ) { $ request = $ this -> resourceHash [ ( int ) $ done [ 'handle' ] ] ; try { $ this -> processResponse ( $ request , $ this -> handles [ $ request ] , $ done ) ; $ this -> successful [ ] = $ request ; } catch ( \ Ex...
Process any received curl multi messages
34,635
private function isCurlException ( RequestInterface $ request , CurlHandle $ handle , array $ curl ) { if ( CURLM_OK == $ curl [ 'result' ] || CURLM_CALL_MULTI_PERFORM == $ curl [ 'result' ] ) { return false ; } $ handle -> setErrorNo ( $ curl [ 'result' ] ) ; $ e = new CurlException ( sprintf ( '[curl] %s: %s [url] %s...
Check if a cURL transfer resulted in what should be an exception
34,636
private function checkCurlResult ( $ code ) { if ( $ code != CURLM_OK && $ code != CURLM_CALL_MULTI_PERFORM ) { throw new CurlException ( isset ( $ this -> multiErrors [ $ code ] ) ? "cURL error: {$code} ({$this->multiErrors[$code][0]}): cURL message: {$this->multiErrors[$code][1]}" : 'Unexpected cURL error: ' . $ code...
Throw an exception for a cURL multi response if needed
34,637
public function apply ( $ perBatch = 50 ) { $ this -> iterated = $ this -> batches = $ batches = 0 ; $ that = $ this ; $ it = $ this -> iterator ; $ callback = $ this -> callback ; $ batch = BatchBuilder :: factory ( ) -> createBatchesWith ( new BatchSizeDivisor ( $ perBatch ) ) -> transferWith ( new BatchClosureTransf...
Apply the callback to the contents of the resource iterator
34,638
public static function factory ( $ config = null , array $ globalParameters = array ( ) ) { if ( ! static :: $ cachedFactory ) { static :: $ cachedFactory = new ServiceBuilderLoader ( ) ; } return self :: $ cachedFactory -> load ( $ config , $ globalParameters ) ; }
Create a new ServiceBuilder using configuration data sourced from an array . js| . json or . php file .
34,639
public function getData ( $ name ) { return isset ( $ this -> builderConfig [ $ name ] ) ? $ this -> builderConfig [ $ name ] : null ; }
Get data from the service builder without triggering the building of a service
34,640
public function cleanupRequest ( Event $ event ) { $ params = $ event [ 'request' ] -> getParams ( ) ; unset ( $ params [ self :: REDIRECT_COUNT ] ) ; unset ( $ params [ self :: PARENT_REQUEST ] ) ; }
Clean up the parameters of a request when it is cloned
34,641
protected function getOriginalRequest ( RequestInterface $ request ) { $ original = $ request ; while ( $ parent = $ original -> getParams ( ) -> get ( self :: PARENT_REQUEST ) ) { $ original = $ parent ; } return $ original ; }
Get the original request that initiated a series of redirects
34,642
protected function prepareRedirection ( RequestInterface $ original , RequestInterface $ request , Response $ response ) { $ params = $ original -> getParams ( ) ; $ current = $ params [ self :: REDIRECT_COUNT ] + 1 ; $ params [ self :: REDIRECT_COUNT ] = $ current ; $ max = isset ( $ params [ self :: MAX_REDIRECTS ] )...
Prepare the request for redirection and enforce the maximum number of allowed redirects per client
34,643
protected function sendRedirectRequest ( RequestInterface $ original , RequestInterface $ request , Response $ response ) { if ( $ redirectRequest = $ this -> prepareRedirection ( $ original , $ request , $ response ) ) { try { $ redirectRequest -> send ( ) ; } catch ( BadResponseException $ e ) { $ e -> getResponse ( ...
Send a redirect request and handle any errors
34,644
protected function throwTooManyRedirectsException ( RequestInterface $ original , $ max ) { $ original -> getEventDispatcher ( ) -> addListener ( 'request.complete' , $ func = function ( $ e ) use ( & $ func , $ original , $ max ) { $ original -> getEventDispatcher ( ) -> removeListener ( 'request.complete' , $ func ) ...
Throw a too many redirects exception for a request
34,645
protected function processPrefixedHeaders ( Response $ response , Parameter $ param , & $ value ) { if ( $ prefix = $ param -> getSentAs ( ) ) { $ container = $ param -> getName ( ) ; $ len = strlen ( $ prefix ) ; foreach ( $ response -> getHeaders ( ) -> toArray ( ) as $ key => $ header ) { if ( stripos ( $ key , $ pr...
Process a prefixed header array
34,646
public function getDecorators ( ) { $ found = array ( $ this ) ; if ( method_exists ( $ this -> decoratedBatch , 'getDecorators' ) ) { $ found = array_merge ( $ found , $ this -> decoratedBatch -> getDecorators ( ) ) ; } return $ found ; }
Trace the decorators associated with the batch
34,647
protected function createRootElement ( Operation $ operation ) { static $ defaultRoot = array ( 'name' => 'Request' ) ; $ root = $ operation -> getData ( 'xmlRoot' ) ? : $ defaultRoot ; $ encoding = $ operation -> getData ( 'xmlEncoding' ) ; $ xmlWriter = $ this -> startDocument ( $ encoding ) ; $ xmlWriter -> startEle...
Create the root XML element to use with a request
34,648
protected function addXmlArray ( \ XMLWriter $ xmlWriter , Parameter $ param , & $ value ) { if ( $ items = $ param -> getItems ( ) ) { foreach ( $ value as $ v ) { $ this -> addXml ( $ xmlWriter , $ items , $ v ) ; } } }
Add an array to the XML
34,649
protected function addXmlObject ( \ XMLWriter $ xmlWriter , Parameter $ param , & $ value ) { $ noAttributes = array ( ) ; foreach ( $ value as $ name => $ v ) { if ( $ property = $ param -> getProperty ( $ name ) ) { if ( $ property -> getData ( 'xmlAttribute' ) ) { $ this -> addXml ( $ xmlWriter , $ property , $ v ) ...
Add an object to the XML
34,650
public function onRequestRetry ( Event $ event ) { $ this -> logger -> log ( $ this -> formatter -> format ( $ event [ 'request' ] , $ event [ 'response' ] , $ event [ 'handle' ] , array ( 'retries' => $ event [ 'retries' ] , 'delay' => $ event [ 'delay' ] ) ) ) ; }
Called when a request is being retried
34,651
public function setHost ( $ host ) { if ( strpos ( $ host , ':' ) === false ) { $ this -> host = $ host ; } else { list ( $ host , $ port ) = explode ( ':' , $ host ) ; $ this -> host = $ host ; $ this -> setPort ( $ port ) ; } return $ this ; }
Set the host of the request .
34,652
public function combine ( $ url , $ strictRfc3986 = false ) { $ url = self :: factory ( $ url ) ; if ( ! $ this -> isAbsolute ( ) && $ url -> isAbsolute ( ) ) { $ url = $ url -> combine ( $ this ) ; } if ( $ buffer = $ url -> getScheme ( ) ) { $ this -> scheme = $ buffer ; $ this -> host = $ url -> getHost ( ) ; $ this...
Combine the URL with another URL . Follows the rules specific in RFC 3986 section 5 . 4 .
34,653
public function normalize ( ) { $ values = $ this -> toArray ( ) ; for ( $ i = 0 , $ total = count ( $ values ) ; $ i < $ total ; $ i ++ ) { if ( strpos ( $ values [ $ i ] , $ this -> glue ) !== false ) { foreach ( preg_split ( '/' . preg_quote ( $ this -> glue ) . '(?=([^"]*"[^"]*")*[^"]*$)/' , $ values [ $ i ] ) as $...
Normalize the header to be a single header with an array of values .
34,654
protected function handleBadResponse ( BadResponseException $ e ) { if ( $ e -> getResponse ( ) -> getStatusCode ( ) == 404 ) { $ this -> storage -> delete ( $ e -> getRequest ( ) ) ; throw $ e ; } }
Handles a bad response when attempting to revalidate
34,655
protected function createRevalidationRequest ( RequestInterface $ request , Response $ response ) { $ revalidate = clone $ request ; $ revalidate -> removeHeader ( 'Pragma' ) -> removeHeader ( 'Cache-Control' ) ; if ( $ response -> getLastModified ( ) ) { $ revalidate -> setHeader ( 'If-Modified-Since' , $ response -> ...
Creates a request to use for revalidation
34,656
protected function handle200Response ( RequestInterface $ request , Response $ validateResponse ) { $ request -> setResponse ( $ validateResponse ) ; if ( $ this -> canCache -> canCacheResponse ( $ validateResponse ) ) { $ this -> storage -> cache ( $ request , $ validateResponse ) ; } return false ; }
Handles a 200 response response from revalidating . The server does not support validation so use this response .
34,657
protected function handle304Response ( RequestInterface $ request , Response $ validateResponse , Response $ response ) { static $ replaceHeaders = array ( 'Date' , 'Expires' , 'Cache-Control' , 'ETag' , 'Last-Modified' ) ; if ( $ validateResponse -> getEtag ( ) != $ response -> getEtag ( ) ) { return false ; } $ modif...
Handle a 304 response and ensure that it is still valid
34,658
public function addFailedRequestWithException ( RequestInterface $ request , \ Exception $ exception ) { $ this -> add ( $ exception ) -> addFailedRequest ( $ request ) -> exceptionForRequest [ spl_object_hash ( $ request ) ] = $ exception ; return $ this ; }
Add to the array of failed requests and associate with exceptions
34,659
public function containsRequest ( RequestInterface $ request ) { return in_array ( $ request , $ this -> failedRequests , true ) || in_array ( $ request , $ this -> successfulRequests , true ) ; }
Check if the exception object contains a request
34,660
public function onCurlProgress ( Event $ event ) { if ( $ event [ 'handle' ] && ( $ event [ 'downloaded' ] || ( isset ( $ event [ 'uploaded' ] ) && $ event [ 'upload_size' ] === $ event [ 'uploaded' ] ) ) ) { curl_setopt ( $ event [ 'handle' ] , CURLOPT_TIMEOUT_MS , 1 ) ; if ( $ event [ 'uploaded' ] ) { curl_setopt ( $...
Event emitted when a curl progress function is called . When the amount of data uploaded == the amount of data to upload OR any bytes have been downloaded then time the request out after 1ms because we re done with transmitting the request and tell curl not download a body .
34,661
public function setAggregator ( QueryAggregatorInterface $ aggregator = null ) { if ( ! $ aggregator ) { if ( ! self :: $ defaultAggregator ) { self :: $ defaultAggregator = new PhpAggregator ( ) ; } $ aggregator = self :: $ defaultAggregator ; } $ this -> aggregator = $ aggregator ; return $ this ; }
Provide a function for combining multi - valued query string parameters into a single or multiple fields
34,662
public function useUrlEncoding ( $ encode ) { $ this -> urlEncode = ( $ encode === true ) ? self :: RFC_3986 : $ encode ; return $ this ; }
Set whether or not field names and values should be rawurlencoded
34,663
public function encodeValue ( $ value ) { if ( $ this -> urlEncode == self :: RFC_3986 ) { return rawurlencode ( $ value ) ; } elseif ( $ this -> urlEncode == self :: FORM_URLENCODED ) { return urlencode ( $ value ) ; } else { return ( string ) $ value ; } }
URL encodes a value based on the url encoding type of the query string object
34,664
protected function prepareData ( array $ data ) { if ( ! $ this -> aggregator ) { $ this -> setAggregator ( null ) ; } $ temp = array ( ) ; foreach ( $ data as $ key => $ value ) { if ( $ value === false || $ value === null ) { $ temp [ $ this -> encodeValue ( $ key ) ] = $ value ; } elseif ( is_array ( $ value ) ) { $...
Url encode parameter data and convert nested query strings into a flattened hash .
34,665
private function convertKvp ( $ name , $ value ) { if ( $ value === self :: BLANK || $ value === null || $ value === false ) { return $ name ; } elseif ( ! is_array ( $ value ) ) { return $ name . $ this -> valueSeparator . $ value ; } $ result = '' ; foreach ( $ value as $ v ) { $ result .= $ this -> convertKvp ( $ na...
Converts a key value pair that can contain strings nulls false or arrays into a single string .
34,666
protected function process ( ) { $ this -> result = $ this [ self :: RESPONSE_PROCESSING ] != self :: TYPE_RAW ? DefaultResponseParser :: getInstance ( ) -> parse ( $ this ) : $ this -> request -> getResponse ( ) ; }
Create the result of the command after the request has been completed . Override this method in subclasses to customize this behavior
34,667
protected function validate ( ) { if ( $ this [ self :: DISABLE_VALIDATION ] ) { return ; } $ errors = array ( ) ; $ validator = $ this -> getValidator ( ) ; foreach ( $ this -> operation -> getParams ( ) as $ name => $ schema ) { $ value = $ this [ $ name ] ; if ( ! $ validator -> validate ( $ schema , $ value ) ) { $...
Validate and prepare the command based on the schema and rules defined by the command s Operation object
34,668
private function getKey ( $ key ) { if ( ! isset ( $ this -> cache [ $ key ] ) ) { if ( ! isset ( $ this -> mappings [ $ key ] ) ) { list ( $ type , $ name ) = explode ( '.' , $ key ) ; throw new InvalidArgumentException ( "No {$type} visitor has been mapped for {$name}" ) ; } $ this -> cache [ $ key ] = new $ this -> ...
Get a visitor by key value name
34,669
public function get ( $ type ) { $ version = $ this -> getAll ( ) ; return isset ( $ version [ $ type ] ) ? $ version [ $ type ] : false ; }
Get a specific type of curl information
34,670
protected function executeMultiple ( $ commands ) { $ requests = array ( ) ; $ commandRequests = new \ SplObjectStorage ( ) ; foreach ( $ commands as $ command ) { $ request = $ this -> prepareCommand ( $ command ) ; $ commandRequests [ $ request ] = $ command ; $ requests [ ] = $ request ; } try { $ this -> send ( $ r...
Execute multiple commands in parallel
34,671
protected function getCommandFactory ( ) { if ( ! $ this -> commandFactory ) { $ this -> commandFactory = CompositeFactory :: getDefaultChain ( $ this ) ; } return $ this -> commandFactory ; }
Get the command factory associated with the client
34,672
public static function getMockFile ( $ path ) { if ( ! file_exists ( $ path ) ) { throw new InvalidArgumentException ( 'Unable to open mock file: ' . $ path ) ; } return Response :: fromMessage ( file_get_contents ( $ path ) ) ; }
Get a mock response from a file
34,673
public function dequeue ( RequestInterface $ request ) { $ this -> dispatch ( 'mock.request' , array ( 'plugin' => $ this , 'request' => $ request ) ) ; $ item = array_shift ( $ this -> queue ) ; if ( $ item instanceof Response ) { if ( $ this -> readBodies && $ request instanceof EntityEnclosingRequestInterface ) { $ ...
Get a response from the front of the list and add it to a request
34,674
public function onRequestBeforeSend ( Event $ event ) { if ( ! $ this -> queue ) { throw new \ OutOfBoundsException ( 'Mock queue is empty' ) ; } $ request = $ event [ 'request' ] ; $ this -> received [ ] = $ request ; if ( $ this -> temporary && count ( $ this -> queue ) == 1 && $ request -> getClient ( ) ) { $ reques...
Called when a request is about to be sent
34,675
public function build ( ) { if ( ! $ this -> transferStrategy ) { throw new RuntimeException ( 'No transfer strategy has been specified' ) ; } if ( ! $ this -> divisorStrategy ) { throw new RuntimeException ( 'No divisor strategy has been specified' ) ; } $ batch = new Batch ( $ this -> transferStrategy , $ this -> div...
Create and return the instantiated batch
34,676
public function addLink ( $ url , $ rel , array $ params = array ( ) ) { $ values = array ( "<{$url}>" , "rel=\"{$rel}\"" ) ; foreach ( $ params as $ k => $ v ) { $ values [ ] = "{$k}=\"{$v}\"" ; } return $ this -> add ( implode ( '; ' , $ values ) ) ; }
Add a link to the header
34,677
public function getLink ( $ rel ) { foreach ( $ this -> getLinks ( ) as $ link ) { if ( isset ( $ link [ 'rel' ] ) && $ link [ 'rel' ] == $ rel ) { return $ link ; } } return null ; }
Get a specific link for a given rel attribute
34,678
public function getLinks ( ) { $ links = $ this -> parseParams ( ) ; foreach ( $ links as & $ link ) { $ key = key ( $ link ) ; unset ( $ link [ $ key ] ) ; $ link [ 'url' ] = trim ( $ key , '<> ' ) ; } return $ links ; }
Get an associative array of links
34,679
public function getErrorNo ( ) { if ( $ this -> errorNo ) { return $ this -> errorNo ; } return $ this -> isAvailable ( ) ? curl_errno ( $ this -> handle ) : CURLE_OK ; }
Get the last error number that occurred on the cURL handle
34,680
public function getStderr ( $ asResource = false ) { $ stderr = $ this -> getOptions ( ) -> get ( CURLOPT_STDERR ) ; if ( ! $ stderr ) { return null ; } if ( $ asResource ) { return $ stderr ; } fseek ( $ stderr , 0 ) ; $ e = stream_get_contents ( $ stderr ) ; fseek ( $ stderr , 0 , SEEK_END ) ; return $ e ; }
Get the stderr output
34,681
public function updateRequestFromTransfer ( RequestInterface $ request ) { if ( ! $ request -> getResponse ( ) ) { return ; } $ request -> getResponse ( ) -> setInfo ( $ this -> getInfo ( ) ) ; if ( ! $ log = $ this -> getStderr ( true ) ) { return ; } $ headers = '' ; fseek ( $ log , 0 ) ; while ( ( $ line = fgets ( $...
Update a request based on the log messages of the CurlHandle
34,682
public function addOperation ( OperationInterface $ operation ) { $ this -> operations [ $ operation -> getName ( ) ] = $ operation -> setServiceDescription ( $ this ) ; return $ this ; }
Add a operation to the service description
34,683
protected function fromArray ( array $ config ) { static $ defaultKeys = array ( 'name' , 'models' , 'apiVersion' , 'baseUrl' , 'description' ) ; foreach ( $ defaultKeys as $ key ) { if ( isset ( $ config [ $ key ] ) ) { $ this -> { $ key } = $ config [ $ key ] ; } } if ( isset ( $ config [ 'basePath' ] ) ) { $ this ->...
Initialize the state from an array
34,684
protected function getFactory ( CommandInterface $ command ) { foreach ( $ this -> factories as $ factory ) { if ( $ factory -> canBuild ( $ command ) ) { return $ factory ; } } return false ; }
Get the factory that matches the command object
34,685
protected function calculatePageSize ( ) { if ( $ this -> limit && $ this -> iteratedCount + $ this -> pageSize > $ this -> limit ) { return 1 + ( $ this -> limit - $ this -> iteratedCount ) ; } return ( int ) $ this -> pageSize ; }
Returns the value that should be specified for the page size for a request that will maintain any hard limits but still honor the specified pageSize if the number of items retrieved + pageSize < hard limit
34,686
protected function determineType ( $ type , $ value ) { foreach ( ( array ) $ type as $ t ) { if ( $ t == 'string' && ( is_string ( $ value ) || ( is_object ( $ value ) && method_exists ( $ value , '__toString' ) ) ) ) { return 'string' ; } elseif ( $ t == 'object' && ( is_array ( $ value ) || is_object ( $ value ) ) )...
From the allowable types determine the type that the variable matches
34,687
public function onRequestBeforeSend ( Event $ event ) { $ request = $ event [ 'request' ] ; $ request -> addHeader ( 'Via' , sprintf ( '%s GuzzleCache/%s' , $ request -> getProtocolVersion ( ) , Version :: VERSION ) ) ; if ( ! $ this -> canCache -> canCacheRequest ( $ request ) ) { switch ( $ request -> getMethod ( ) )...
Check if a response in cache will satisfy the request before sending
34,688
public function onRequestSent ( Event $ event ) { $ request = $ event [ 'request' ] ; $ response = $ event [ 'response' ] ; if ( $ request -> getParams ( ) -> get ( 'cache.hit' ) === null && $ this -> canCache -> canCacheRequest ( $ request ) && $ this -> canCache -> canCacheResponse ( $ response ) ) { $ this -> storag...
If possible store a response in cache after sending
34,689
public function onRequestError ( Event $ event ) { $ request = $ event [ 'request' ] ; if ( ! $ this -> canCache -> canCacheRequest ( $ request ) ) { return ; } if ( $ response = $ this -> storage -> fetch ( $ request ) ) { $ response -> setHeader ( 'Age' , time ( ) - strtotime ( $ response -> getLastModified ( ) ? : $...
If possible return a cache response on an error
34,690
public function onRequestException ( Event $ event ) { if ( ! $ event [ 'exception' ] instanceof CurlException ) { return ; } $ request = $ event [ 'request' ] ; if ( ! $ this -> canCache -> canCacheRequest ( $ request ) ) { return ; } if ( $ response = $ this -> storage -> fetch ( $ request ) ) { $ response -> setHead...
If possible set a cache response on a cURL exception
34,691
public function canResponseSatisfyRequest ( RequestInterface $ request , Response $ response ) { $ responseAge = $ response -> calculateAge ( ) ; $ reqc = $ request -> getHeader ( 'Cache-Control' ) ; $ resc = $ response -> getHeader ( 'Cache-Control' ) ; if ( $ reqc && $ reqc -> hasDirective ( 'max-age' ) && $ response...
Check if a cache response satisfies a request s caching constraints
34,692
public function canResponseSatisfyFailedRequest ( RequestInterface $ request , Response $ response ) { $ reqc = $ request -> getHeader ( 'Cache-Control' ) ; $ resc = $ response -> getHeader ( 'Cache-Control' ) ; $ requestStaleIfError = $ reqc ? $ reqc -> getDirective ( 'stale-if-error' ) : null ; $ responseStaleIfError...
Check if a cache response satisfies a failed request s caching constraints
34,693
public function purge ( $ url ) { $ url = $ url instanceof RequestInterface ? $ url -> getUrl ( ) : $ url ; $ this -> storage -> purge ( $ url ) ; }
Purge all cache entries for a given URL
34,694
protected function addResponseHeaders ( RequestInterface $ request , Response $ response ) { $ params = $ request -> getParams ( ) ; $ response -> setHeader ( 'Via' , sprintf ( '%s GuzzleCache/%s' , $ request -> getProtocolVersion ( ) , Version :: VERSION ) ) ; $ lookup = ( $ params [ 'cache.lookup' ] === true ? 'HIT' ...
Add the plugin s headers to a response
34,695
protected function processPostFields ( ) { if ( ! $ this -> postFiles ) { $ this -> removeHeader ( 'Expect' ) -> setHeader ( 'Content-Type' , self :: URL_ENCODED ) ; } else { $ this -> setHeader ( 'Content-Type' , self :: MULTIPART ) ; if ( $ this -> expectCutoff !== false ) { $ this -> setHeader ( 'Expect' , '100-Cont...
Determine what type of request should be sent based on post fields
34,696
public function addVisitor ( $ location , RequestVisitorInterface $ visitor ) { $ this -> factory -> addRequestVisitor ( $ location , $ visitor ) ; return $ this ; }
Add a location visitor to the serializer
34,697
protected function prepareAdditionalParameters ( OperationInterface $ operation , CommandInterface $ command , RequestInterface $ request , Parameter $ additional ) { if ( ! ( $ location = $ additional -> getLocation ( ) ) ) { return ; } $ visitor = $ this -> factory -> getRequestVisitor ( $ location ) ; $ hidden = $ c...
Serialize additional parameters
34,698
protected function addExpectHeader ( EntityEnclosingRequestInterface $ request , EntityBodyInterface $ body , $ expect ) { if ( $ expect === false ) { $ request -> removeHeader ( 'Expect' ) ; } elseif ( $ expect !== true ) { $ expect = $ expect ? : 1048576 ; if ( is_numeric ( $ expect ) && $ body -> getSize ( ) ) { if ...
Add the appropriate expect header to a request
34,699
private function getField ( $ key ) { return isset ( $ this -> data [ $ key ] ) ? $ this -> data [ $ key ] : null ; }
Returns a field from the Graph node data .