Documentation

Command
in package

HTTP client curl command class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
6.0.0

Table of Contents

Methods

addQuotes()  : string
Trim quotes from value
clientToCommand()  : string
Create a compatible command string to execute with the curl CLI application
commandToClient()  : Client
Create a client object from a command string from the Curl CLI application
convertCommandOptions()  : array<string|int, mixed>
Convert CLI options to usable values for the Curl handler and request
extractCommandOptionValues()  : array<string|int, mixed>
Extract command option values
parseCommandOptions()  : array<string|int, mixed>
Parse the CLI command options string
trimQuotes()  : string
Trim quotes from value
lastNonNullOptionValue()  : string|null
extractCommandOptionValues() collects every occurrence of a repeated CLI flag into an array. Most single-value options follow curl's own "last occurrence wins" semantics when repeated (e.g. -u/--user, -A/--user-agent) - this extracts the last non-null string from such an array, a bare scalar value unchanged, or null if every repeated occurrence was valueless. Cumulative flags (-H/--header, -d/--data, -F/--form) have their own dedicated array-handling logic and don't use this helper.
tokenize()  : array<string|int, mixed>
Tokenize a command-line string into words, respecting single/double quotes so a space-then-dash inside a quoted value isn't mistaken for the start of a new option.
urlEncodedContentType()  : string
The application/x-www-form-urlencoded content type string, broken out as its own method purely so it isn't a magic string duplicated inline.

Methods

addQuotes()

Trim quotes from value

public static addQuotes(string $value[, string $quote = '"' ]) : string
Parameters
$value : string
$quote : string = '"'
Return values
string

clientToCommand()

Create a compatible command string to execute with the curl CLI application

public static clientToCommand(Client $client) : string
Parameters
$client : Client
Return values
string

commandToClient()

Create a client object from a command string from the Curl CLI application

public static commandToClient(string $command) : Client
Parameters
$command : string
Return values
Client

convertCommandOptions()

Convert CLI options to usable values for the Curl handler and request

public static convertCommandOptions(array<string|int, mixed> $options, Curl $curl, Request $request) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>
$curl : Curl
$request : Request
Return values
array<string|int, mixed>

extractCommandOptionValues()

Extract command option values

public static extractCommandOptionValues(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>
Return values
array<string|int, mixed>

parseCommandOptions()

Parse the CLI command options string

public static parseCommandOptions(string $optionString) : array<string|int, mixed>
Parameters
$optionString : string
Return values
array<string|int, mixed>

trimQuotes()

Trim quotes from value

public static trimQuotes(string $value) : string
Parameters
$value : string
Return values
string

lastNonNullOptionValue()

extractCommandOptionValues() collects every occurrence of a repeated CLI flag into an array. Most single-value options follow curl's own "last occurrence wins" semantics when repeated (e.g. -u/--user, -A/--user-agent) - this extracts the last non-null string from such an array, a bare scalar value unchanged, or null if every repeated occurrence was valueless. Cumulative flags (-H/--header, -d/--data, -F/--form) have their own dedicated array-handling logic and don't use this helper.

protected static lastNonNullOptionValue(mixed $value) : string|null
Parameters
$value : mixed
Return values
string|null

tokenize()

Tokenize a command-line string into words, respecting single/double quotes so a space-then-dash inside a quoted value isn't mistaken for the start of a new option.

protected static tokenize(string $string) : array<string|int, mixed>

Each token is returned as ['value' => string, 'quoted' => bool] rather than a plain string: the quote characters themselves are consumed here and never appear in 'value', so once tokenizing is done there is no way to tell from the value alone whether a token like '-foo=bar' was a quoted value or a real flag - callers (parseCommandOptions()) need the 'quoted' flag to make that distinction. 'quoted' is true only when the token's very FIRST character came from inside a quote (e.g. '-foo=bar' or "-foo=bar"), not merely whether a quote appears anywhere in the token - a compact flag+value like -d"foo=bar" (no space, unquoted -d prefix) must still be recognized as starting with a real, unquoted dash.

Parameters
$string : string
Return values
array<string|int, mixed>

urlEncodedContentType()

The application/x-www-form-urlencoded content type string, broken out as its own method purely so it isn't a magic string duplicated inline.

protected static urlEncodedContentType() : string
Return values
string

        
On this page

Search results