repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
brick/money | src/MoneyBag.php | MoneyBag.subtract | public function subtract(MoneyContainer $money) : MoneyBag
{
foreach ($money->getAmounts() as $currencyCode => $amount) {
$this->amounts[$currencyCode] = $this->getAmount($currencyCode)->minus($amount);
}
return $this;
} | php | public function subtract(MoneyContainer $money) : MoneyBag
{
foreach ($money->getAmounts() as $currencyCode => $amount) {
$this->amounts[$currencyCode] = $this->getAmount($currencyCode)->minus($amount);
}
return $this;
} | [
"public",
"function",
"subtract",
"(",
"MoneyContainer",
"$",
"money",
")",
":",
"MoneyBag",
"{",
"foreach",
"(",
"$",
"money",
"->",
"getAmounts",
"(",
")",
"as",
"$",
"currencyCode",
"=>",
"$",
"amount",
")",
"{",
"$",
"this",
"->",
"amounts",
"[",
"... | Subtracts money from this bag.
@param MoneyContainer $money A Money, RationalMoney, or MoneyBag instance.
@return MoneyBag This instance. | [
"Subtracts",
"money",
"from",
"this",
"bag",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/MoneyBag.php#L72-L79 | train |
brick/money | src/AbstractMoney.php | AbstractMoney.to | final public function to(Context $context, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
return Money::create($this->getAmount(), $this->getCurrency(), $context, $roundingMode);
} | php | final public function to(Context $context, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
return Money::create($this->getAmount(), $this->getCurrency(), $context, $roundingMode);
} | [
"final",
"public",
"function",
"to",
"(",
"Context",
"$",
"context",
",",
"int",
"$",
"roundingMode",
"=",
"RoundingMode",
"::",
"UNNECESSARY",
")",
":",
"Money",
"{",
"return",
"Money",
"::",
"create",
"(",
"$",
"this",
"->",
"getAmount",
"(",
")",
",",... | Converts this money to a Money in the given Context.
@param Context $context The context.
@param int $roundingMode The rounding mode, if necessary.
@return Money
@throws RoundingNecessaryException If RoundingMode::UNNECESSARY is used but rounding is necessary. | [
"Converts",
"this",
"money",
"to",
"a",
"Money",
"in",
"the",
"given",
"Context",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/AbstractMoney.php#L39-L42 | train |
brick/money | src/AbstractMoney.php | AbstractMoney.getAmountOf | final protected function getAmountOf($that)
{
if ($that instanceof AbstractMoney) {
if (! $that->getCurrency()->is($this->getCurrency())) {
throw MoneyMismatchException::currencyMismatch($this->getCurrency(), $that->getCurrency());
}
return $that->getAmount();
}
return $that;
} | php | final protected function getAmountOf($that)
{
if ($that instanceof AbstractMoney) {
if (! $that->getCurrency()->is($this->getCurrency())) {
throw MoneyMismatchException::currencyMismatch($this->getCurrency(), $that->getCurrency());
}
return $that->getAmount();
}
return $that;
} | [
"final",
"protected",
"function",
"getAmountOf",
"(",
"$",
"that",
")",
"{",
"if",
"(",
"$",
"that",
"instanceof",
"AbstractMoney",
")",
"{",
"if",
"(",
"!",
"$",
"that",
"->",
"getCurrency",
"(",
")",
"->",
"is",
"(",
"$",
"this",
"->",
"getCurrency",... | Returns the amount of the given parameter.
If the parameter is a money, its currency is checked against this money's currency.
@param AbstractMoney|BigNumber|number|string $that A money or amount.
@return BigNumber|number|string
@throws MoneyMismatchException If currencies don't match. | [
"Returns",
"the",
"amount",
"of",
"the",
"given",
"parameter",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/AbstractMoney.php#L217-L228 | train |
brick/money | src/ISOCurrencyProvider.php | ISOCurrencyProvider.getInstance | public static function getInstance() : ISOCurrencyProvider
{
if (self::$instance === null) {
self::$instance = new ISOCurrencyProvider();
}
return self::$instance;
} | php | public static function getInstance() : ISOCurrencyProvider
{
if (self::$instance === null) {
self::$instance = new ISOCurrencyProvider();
}
return self::$instance;
} | [
"public",
"static",
"function",
"getInstance",
"(",
")",
":",
"ISOCurrencyProvider",
"{",
"if",
"(",
"self",
"::",
"$",
"instance",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"instance",
"=",
"new",
"ISOCurrencyProvider",
"(",
")",
";",
"}",
"return",
"... | Returns the singleton instance of ISOCurrencyProvider.
@return ISOCurrencyProvider | [
"Returns",
"the",
"singleton",
"instance",
"of",
"ISOCurrencyProvider",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/ISOCurrencyProvider.php#L75-L82 | train |
brick/money | src/ISOCurrencyProvider.php | ISOCurrencyProvider.getCurrency | public function getCurrency($currencyCode) : Currency
{
if (isset($this->currencies[$currencyCode])) {
return $this->currencies[$currencyCode];
}
if (! isset($this->currencyData[$currencyCode])) {
if ($this->numericToCurrency === null) {
$this->numericToCurrency = require __DIR__ . '/../data/numeric-to-currency.php';
}
if (isset($this->numericToCurrency[$currencyCode])) {
return $this->getCurrency($this->numericToCurrency[$currencyCode]);
}
throw UnknownCurrencyException::unknownCurrency($currencyCode);
}
$currency = new Currency(... $this->currencyData[$currencyCode]);
return $this->currencies[$currencyCode] = $currency;
} | php | public function getCurrency($currencyCode) : Currency
{
if (isset($this->currencies[$currencyCode])) {
return $this->currencies[$currencyCode];
}
if (! isset($this->currencyData[$currencyCode])) {
if ($this->numericToCurrency === null) {
$this->numericToCurrency = require __DIR__ . '/../data/numeric-to-currency.php';
}
if (isset($this->numericToCurrency[$currencyCode])) {
return $this->getCurrency($this->numericToCurrency[$currencyCode]);
}
throw UnknownCurrencyException::unknownCurrency($currencyCode);
}
$currency = new Currency(... $this->currencyData[$currencyCode]);
return $this->currencies[$currencyCode] = $currency;
} | [
"public",
"function",
"getCurrency",
"(",
"$",
"currencyCode",
")",
":",
"Currency",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"currencies",
"[",
"$",
"currencyCode",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"currencies",
"[",
"$",
"curr... | Returns the currency matching the given currency code.
@param string|int $currencyCode The 3-letter or numeric ISO 4217 currency code.
@return Currency The currency.
@throws UnknownCurrencyException If the currency code is not known. | [
"Returns",
"the",
"currency",
"matching",
"the",
"given",
"currency",
"code",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/ISOCurrencyProvider.php#L93-L114 | train |
brick/money | src/ISOCurrencyProvider.php | ISOCurrencyProvider.getAvailableCurrencies | public function getAvailableCurrencies() : array
{
if ($this->isPartial) {
foreach ($this->currencyData as $currencyCode => $data) {
if (! isset($this->currencies[$currencyCode])) {
$this->currencies[$currencyCode] = new Currency(... $data);
}
}
ksort($this->currencies);
$this->isPartial = false;
}
return $this->currencies;
} | php | public function getAvailableCurrencies() : array
{
if ($this->isPartial) {
foreach ($this->currencyData as $currencyCode => $data) {
if (! isset($this->currencies[$currencyCode])) {
$this->currencies[$currencyCode] = new Currency(... $data);
}
}
ksort($this->currencies);
$this->isPartial = false;
}
return $this->currencies;
} | [
"public",
"function",
"getAvailableCurrencies",
"(",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"isPartial",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"currencyData",
"as",
"$",
"currencyCode",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"!",... | Returns all the available currencies.
@return Currency[] The currencies, indexed by currency code. | [
"Returns",
"all",
"the",
"available",
"currencies",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/ISOCurrencyProvider.php#L121-L136 | train |
brick/money | src/ISOCurrencyProvider.php | ISOCurrencyProvider.getCurrencyForCountry | public function getCurrencyForCountry(string $countryCode) : Currency
{
$currencies = $this->getCurrenciesForCountry($countryCode);
$count = count($currencies);
if ($count === 1) {
return $currencies[0];
}
if ($count === 0) {
throw UnknownCurrencyException::noCurrencyForCountry($countryCode);
}
$currencyCodes = [];
foreach ($currencies as $currency) {
$currencyCodes[] = $currency->getCurrencyCode();
}
throw UnknownCurrencyException::noSingleCurrencyForCountry($countryCode, $currencyCodes);
} | php | public function getCurrencyForCountry(string $countryCode) : Currency
{
$currencies = $this->getCurrenciesForCountry($countryCode);
$count = count($currencies);
if ($count === 1) {
return $currencies[0];
}
if ($count === 0) {
throw UnknownCurrencyException::noCurrencyForCountry($countryCode);
}
$currencyCodes = [];
foreach ($currencies as $currency) {
$currencyCodes[] = $currency->getCurrencyCode();
}
throw UnknownCurrencyException::noSingleCurrencyForCountry($countryCode, $currencyCodes);
} | [
"public",
"function",
"getCurrencyForCountry",
"(",
"string",
"$",
"countryCode",
")",
":",
"Currency",
"{",
"$",
"currencies",
"=",
"$",
"this",
"->",
"getCurrenciesForCountry",
"(",
"$",
"countryCode",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"curre... | Returns the currency for the given ISO country code.
@param string $countryCode The 2-letter ISO 3166-1 country code.
@return Currency
@throws UnknownCurrencyException If the country code is not known, or the country has no single currency. | [
"Returns",
"the",
"currency",
"for",
"the",
"given",
"ISO",
"country",
"code",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/ISOCurrencyProvider.php#L147-L168 | train |
brick/money | src/ISOCurrencyProvider.php | ISOCurrencyProvider.getCurrenciesForCountry | public function getCurrenciesForCountry(string $countryCode) : array
{
if ($this->countryToCurrency === null) {
$this->countryToCurrency = require __DIR__ . '/../data/country-to-currency.php';
}
$result = [];
if (isset($this->countryToCurrency[$countryCode])) {
foreach ($this->countryToCurrency[$countryCode] as $currencyCode) {
$result[] = $this->getCurrency($currencyCode);
}
}
return $result;
} | php | public function getCurrenciesForCountry(string $countryCode) : array
{
if ($this->countryToCurrency === null) {
$this->countryToCurrency = require __DIR__ . '/../data/country-to-currency.php';
}
$result = [];
if (isset($this->countryToCurrency[$countryCode])) {
foreach ($this->countryToCurrency[$countryCode] as $currencyCode) {
$result[] = $this->getCurrency($currencyCode);
}
}
return $result;
} | [
"public",
"function",
"getCurrenciesForCountry",
"(",
"string",
"$",
"countryCode",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"countryToCurrency",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"countryToCurrency",
"=",
"require",
"__DIR__",
".",
"'... | Returns the currencies for the given ISO country code.
If the country code is not known, or if the country has no official currency, an empty array is returned.
@param string $countryCode The 2-letter ISO 3166-1 country code.
@return Currency[] | [
"Returns",
"the",
"currencies",
"for",
"the",
"given",
"ISO",
"country",
"code",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/ISOCurrencyProvider.php#L179-L194 | train |
brick/money | src/Currency.php | Currency.is | public function is($currency) : bool
{
if ($currency instanceof Currency) {
return $this->currencyCode === $currency->currencyCode;
}
return $this->currencyCode === (string) $currency
|| ($this->numericCode !== 0 && $this->numericCode === (int) $currency);
} | php | public function is($currency) : bool
{
if ($currency instanceof Currency) {
return $this->currencyCode === $currency->currencyCode;
}
return $this->currencyCode === (string) $currency
|| ($this->numericCode !== 0 && $this->numericCode === (int) $currency);
} | [
"public",
"function",
"is",
"(",
"$",
"currency",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"currency",
"instanceof",
"Currency",
")",
"{",
"return",
"$",
"this",
"->",
"currencyCode",
"===",
"$",
"currency",
"->",
"currencyCode",
";",
"}",
"return",
"$",
... | Returns whether this currency is equal to the given currency.
The currencies are considered equal if their currency codes are equal.
@param Currency|string|int $currency The Currency instance, currency code or numeric currency code.
@return bool | [
"Returns",
"whether",
"this",
"currency",
"is",
"equal",
"to",
"the",
"given",
"currency",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Currency.php#L168-L176 | train |
brick/money | src/RationalMoney.php | RationalMoney.of | public static function of($amount, $currency) : RationalMoney
{
$amount = BigRational::of($amount);
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
return new RationalMoney($amount, $currency);
} | php | public static function of($amount, $currency) : RationalMoney
{
$amount = BigRational::of($amount);
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
return new RationalMoney($amount, $currency);
} | [
"public",
"static",
"function",
"of",
"(",
"$",
"amount",
",",
"$",
"currency",
")",
":",
"RationalMoney",
"{",
"$",
"amount",
"=",
"BigRational",
"::",
"of",
"(",
"$",
"amount",
")",
";",
"if",
"(",
"!",
"$",
"currency",
"instanceof",
"Currency",
")",... | Convenience factory method.
@param BigNumber|number|string $amount The monetary amount.
@param Currency|string $currency The Currency instance, ISO currency code or ISO numeric currency code.
@return RationalMoney | [
"Convenience",
"factory",
"method",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/RationalMoney.php#L53-L62 | train |
brick/money | src/RationalMoney.php | RationalMoney.plus | public function plus($that) : RationalMoney
{
$that = $this->getAmountOf($that);
$amount = $this->amount->plus($that);
return new self($amount, $this->currency);
} | php | public function plus($that) : RationalMoney
{
$that = $this->getAmountOf($that);
$amount = $this->amount->plus($that);
return new self($amount, $this->currency);
} | [
"public",
"function",
"plus",
"(",
"$",
"that",
")",
":",
"RationalMoney",
"{",
"$",
"that",
"=",
"$",
"this",
"->",
"getAmountOf",
"(",
"$",
"that",
")",
";",
"$",
"amount",
"=",
"$",
"this",
"->",
"amount",
"->",
"plus",
"(",
"$",
"that",
")",
... | Returns the sum of this RationalMoney and the given amount.
@param AbstractMoney|BigNumber|number|string $that The money or amount to add.
@return RationalMoney
@throws MathException If the argument is not a valid number.
@throws MoneyMismatchException If the argument is a money in another currency. | [
"Returns",
"the",
"sum",
"of",
"this",
"RationalMoney",
"and",
"the",
"given",
"amount",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/RationalMoney.php#L90-L96 | train |
brick/money | src/RationalMoney.php | RationalMoney.minus | public function minus($that) : RationalMoney
{
$that = $this->getAmountOf($that);
$amount = $this->amount->minus($that);
return new self($amount, $this->currency);
} | php | public function minus($that) : RationalMoney
{
$that = $this->getAmountOf($that);
$amount = $this->amount->minus($that);
return new self($amount, $this->currency);
} | [
"public",
"function",
"minus",
"(",
"$",
"that",
")",
":",
"RationalMoney",
"{",
"$",
"that",
"=",
"$",
"this",
"->",
"getAmountOf",
"(",
"$",
"that",
")",
";",
"$",
"amount",
"=",
"$",
"this",
"->",
"amount",
"->",
"minus",
"(",
"$",
"that",
")",
... | Returns the difference of this RationalMoney and the given amount.
@param AbstractMoney|BigNumber|number|string $that The money or amount to subtract.
@return RationalMoney
@throws MathException If the argument is not a valid number.
@throws MoneyMismatchException If the argument is a money in another currency. | [
"Returns",
"the",
"difference",
"of",
"this",
"RationalMoney",
"and",
"the",
"given",
"amount",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/RationalMoney.php#L108-L114 | train |
brick/money | src/RationalMoney.php | RationalMoney.multipliedBy | public function multipliedBy($that) : RationalMoney
{
$amount = $this->amount->multipliedBy($that);
return new self($amount, $this->currency);
} | php | public function multipliedBy($that) : RationalMoney
{
$amount = $this->amount->multipliedBy($that);
return new self($amount, $this->currency);
} | [
"public",
"function",
"multipliedBy",
"(",
"$",
"that",
")",
":",
"RationalMoney",
"{",
"$",
"amount",
"=",
"$",
"this",
"->",
"amount",
"->",
"multipliedBy",
"(",
"$",
"that",
")",
";",
"return",
"new",
"self",
"(",
"$",
"amount",
",",
"$",
"this",
... | Returns the product of this RationalMoney and the given number.
@param BigNumber|number|string $that The multiplier.
@return RationalMoney
@throws MathException If the argument is not a valid number. | [
"Returns",
"the",
"product",
"of",
"this",
"RationalMoney",
"and",
"the",
"given",
"number",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/RationalMoney.php#L125-L130 | train |
brick/money | src/RationalMoney.php | RationalMoney.dividedBy | public function dividedBy($that) : RationalMoney
{
$amount = $this->amount->dividedBy($that);
return new self($amount, $this->currency);
} | php | public function dividedBy($that) : RationalMoney
{
$amount = $this->amount->dividedBy($that);
return new self($amount, $this->currency);
} | [
"public",
"function",
"dividedBy",
"(",
"$",
"that",
")",
":",
"RationalMoney",
"{",
"$",
"amount",
"=",
"$",
"this",
"->",
"amount",
"->",
"dividedBy",
"(",
"$",
"that",
")",
";",
"return",
"new",
"self",
"(",
"$",
"amount",
",",
"$",
"this",
"->",
... | Returns the result of the division of this RationalMoney by the given number.
@param BigNumber|number|string $that The divisor.
@return RationalMoney
@throws MathException If the argument is not a valid number. | [
"Returns",
"the",
"result",
"of",
"the",
"division",
"of",
"this",
"RationalMoney",
"by",
"the",
"given",
"number",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/RationalMoney.php#L141-L146 | train |
brick/money | src/Money.php | Money.min | public static function min(Money $money, Money ...$monies) : Money
{
$min = $money;
foreach ($monies as $money) {
if ($money->isLessThan($min)) {
$min = $money;
}
}
return $min;
} | php | public static function min(Money $money, Money ...$monies) : Money
{
$min = $money;
foreach ($monies as $money) {
if ($money->isLessThan($min)) {
$min = $money;
}
}
return $min;
} | [
"public",
"static",
"function",
"min",
"(",
"Money",
"$",
"money",
",",
"Money",
"...",
"$",
"monies",
")",
":",
"Money",
"{",
"$",
"min",
"=",
"$",
"money",
";",
"foreach",
"(",
"$",
"monies",
"as",
"$",
"money",
")",
"{",
"if",
"(",
"$",
"money... | Returns the minimum of the given monies.
If several monies are equal to the minimum value, the first one is returned.
@param Money $money The first money.
@param Money ...$monies The subsequent monies.
@return Money
@throws MoneyMismatchException If all the monies are not in the same currency. | [
"Returns",
"the",
"minimum",
"of",
"the",
"given",
"monies",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L80-L91 | train |
brick/money | src/Money.php | Money.max | public static function max(Money $money, Money ...$monies) : Money
{
$max = $money;
foreach ($monies as $money) {
if ($money->isGreaterThan($max)) {
$max = $money;
}
}
return $max;
} | php | public static function max(Money $money, Money ...$monies) : Money
{
$max = $money;
foreach ($monies as $money) {
if ($money->isGreaterThan($max)) {
$max = $money;
}
}
return $max;
} | [
"public",
"static",
"function",
"max",
"(",
"Money",
"$",
"money",
",",
"Money",
"...",
"$",
"monies",
")",
":",
"Money",
"{",
"$",
"max",
"=",
"$",
"money",
";",
"foreach",
"(",
"$",
"monies",
"as",
"$",
"money",
")",
"{",
"if",
"(",
"$",
"money... | Returns the maximum of the given monies.
If several monies are equal to the maximum value, the first one is returned.
@param Money $money The first money.
@param Money ...$monies The subsequent monies.
@return Money
@throws MoneyMismatchException If all the monies are not in the same currency. | [
"Returns",
"the",
"maximum",
"of",
"the",
"given",
"monies",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L105-L116 | train |
brick/money | src/Money.php | Money.total | public static function total(Money $money, Money ...$monies) : Money
{
$total = $money;
foreach ($monies as $money) {
$total = $total->plus($money);
}
return $total;
} | php | public static function total(Money $money, Money ...$monies) : Money
{
$total = $money;
foreach ($monies as $money) {
$total = $total->plus($money);
}
return $total;
} | [
"public",
"static",
"function",
"total",
"(",
"Money",
"$",
"money",
",",
"Money",
"...",
"$",
"monies",
")",
":",
"Money",
"{",
"$",
"total",
"=",
"$",
"money",
";",
"foreach",
"(",
"$",
"monies",
"as",
"$",
"money",
")",
"{",
"$",
"total",
"=",
... | Returns the total of the given monies.
The monies must share the same currency and context.
@param Money $money The first money.
@param Money ...$monies The subsequent monies.
@return Money
@throws MoneyMismatchException If all the monies are not in the same currency and context. | [
"Returns",
"the",
"total",
"of",
"the",
"given",
"monies",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L130-L139 | train |
brick/money | src/Money.php | Money.create | public static function create(BigNumber $amount, Currency $currency, Context $context, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
$amount = $context->applyTo($amount, $currency, $roundingMode);
return new Money($amount, $currency, $context);
} | php | public static function create(BigNumber $amount, Currency $currency, Context $context, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
$amount = $context->applyTo($amount, $currency, $roundingMode);
return new Money($amount, $currency, $context);
} | [
"public",
"static",
"function",
"create",
"(",
"BigNumber",
"$",
"amount",
",",
"Currency",
"$",
"currency",
",",
"Context",
"$",
"context",
",",
"int",
"$",
"roundingMode",
"=",
"RoundingMode",
"::",
"UNNECESSARY",
")",
":",
"Money",
"{",
"$",
"amount",
"... | Creates a Money from a rational amount, a currency, and a context.
@param BigNumber $amount The amount.
@param Currency $currency The currency.
@param Context $context The context.
@param int $roundingMode An optional rounding mode if the amount does not fit the context.
@return Money
@throws RoundingNecessaryException If RoundingMode::UNNECESSARY is used but rounding is necessary. | [
"Creates",
"a",
"Money",
"from",
"a",
"rational",
"amount",
"a",
"currency",
"and",
"a",
"context",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L153-L158 | train |
brick/money | src/Money.php | Money.of | public static function of($amount, $currency, Context $context = null, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
if ($context === null) {
$context = new DefaultContext();
}
$amount = BigNumber::of($amount);
return self::create($amount, $currency, $context, $roundingMode);
} | php | public static function of($amount, $currency, Context $context = null, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
if ($context === null) {
$context = new DefaultContext();
}
$amount = BigNumber::of($amount);
return self::create($amount, $currency, $context, $roundingMode);
} | [
"public",
"static",
"function",
"of",
"(",
"$",
"amount",
",",
"$",
"currency",
",",
"Context",
"$",
"context",
"=",
"null",
",",
"int",
"$",
"roundingMode",
"=",
"RoundingMode",
"::",
"UNNECESSARY",
")",
":",
"Money",
"{",
"if",
"(",
"!",
"$",
"curren... | Returns a Money of the given amount and currency.
By default, the money is created with a DefaultContext. This means that the amount is scaled to match the
currency's default fraction digits. For example, `Money::of('2.5', 'USD')` will yield `USD 2.50`.
If the amount cannot be safely converted to this scale, an exception is thrown.
To override this behaviour, a Context instance can be provided.
Operations on this Money return a Money with the same context.
@param BigNumber|number|string $amount The monetary amount.
@param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
@param Context|null $context An optional Context.
@param int $roundingMode An optional RoundingMode, if the amount does not fit the context.
@return Money
@throws NumberFormatException If the amount is a string in a non-supported format.
@throws RoundingNecessaryException If the rounding was necessary to represent the amount at the requested scale. | [
"Returns",
"a",
"Money",
"of",
"the",
"given",
"amount",
"and",
"currency",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L180-L193 | train |
brick/money | src/Money.php | Money.ofMinor | public static function ofMinor($minorAmount, $currency, Context $context = null, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
if ($context === null) {
$context = new DefaultContext();
}
$amount = BigRational::of($minorAmount)->dividedBy(10 ** $currency->getDefaultFractionDigits());
return self::create($amount, $currency, $context, $roundingMode);
} | php | public static function ofMinor($minorAmount, $currency, Context $context = null, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
if ($context === null) {
$context = new DefaultContext();
}
$amount = BigRational::of($minorAmount)->dividedBy(10 ** $currency->getDefaultFractionDigits());
return self::create($amount, $currency, $context, $roundingMode);
} | [
"public",
"static",
"function",
"ofMinor",
"(",
"$",
"minorAmount",
",",
"$",
"currency",
",",
"Context",
"$",
"context",
"=",
"null",
",",
"int",
"$",
"roundingMode",
"=",
"RoundingMode",
"::",
"UNNECESSARY",
")",
":",
"Money",
"{",
"if",
"(",
"!",
"$",... | Returns a Money from a number of minor units.
By default, the money is created with a DefaultContext. This means that the amount is scaled to match the
currency's default fraction digits. For example, `Money::ofMinor(1234, 'USD')` will yield `USD 12.34`.
If the amount cannot be safely converted to this scale, an exception is thrown.
@param BigNumber|number|string $minorAmount The amount, in minor currency units.
@param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
@param Context|null $context An optional Context.
@param int $roundingMode An optional RoundingMode, if the amount does not fit the context.
@return Money
@throws UnknownCurrencyException If the currency is an unknown currency code.
@throws MathException If the amount cannot be converted to a BigInteger. | [
"Returns",
"a",
"Money",
"from",
"a",
"number",
"of",
"minor",
"units",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L212-L225 | train |
brick/money | src/Money.php | Money.zero | public static function zero($currency, Context $context = null) : Money
{
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
if ($context === null) {
$context = new DefaultContext();
}
$amount = BigDecimal::zero();
return self::create($amount, $currency, $context);
} | php | public static function zero($currency, Context $context = null) : Money
{
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
if ($context === null) {
$context = new DefaultContext();
}
$amount = BigDecimal::zero();
return self::create($amount, $currency, $context);
} | [
"public",
"static",
"function",
"zero",
"(",
"$",
"currency",
",",
"Context",
"$",
"context",
"=",
"null",
")",
":",
"Money",
"{",
"if",
"(",
"!",
"$",
"currency",
"instanceof",
"Currency",
")",
"{",
"$",
"currency",
"=",
"Currency",
"::",
"of",
"(",
... | Returns a Money with zero value, in the given currency.
By default, the money is created with a DefaultContext: it has the default scale for the currency.
A Context instance can be provided to override the default.
@param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
@param Context|null $context An optional context.
@return Money | [
"Returns",
"a",
"Money",
"with",
"zero",
"value",
"in",
"the",
"given",
"currency",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L238-L251 | train |
brick/money | src/Money.php | Money.plus | public function plus($that, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
$amount = $this->getAmountOf($that);
if ($that instanceof Money) {
$this->checkContext($that->getContext(), __FUNCTION__);
if ($this->context->isFixedScale()) {
return new Money($this->amount->plus($that->amount), $this->currency, $this->context);
}
}
$amount = $this->amount->toBigRational()->plus($amount);
return self::create($amount, $this->currency, $this->context, $roundingMode);
} | php | public function plus($that, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
$amount = $this->getAmountOf($that);
if ($that instanceof Money) {
$this->checkContext($that->getContext(), __FUNCTION__);
if ($this->context->isFixedScale()) {
return new Money($this->amount->plus($that->amount), $this->currency, $this->context);
}
}
$amount = $this->amount->toBigRational()->plus($amount);
return self::create($amount, $this->currency, $this->context, $roundingMode);
} | [
"public",
"function",
"plus",
"(",
"$",
"that",
",",
"int",
"$",
"roundingMode",
"=",
"RoundingMode",
"::",
"UNNECESSARY",
")",
":",
"Money",
"{",
"$",
"amount",
"=",
"$",
"this",
"->",
"getAmountOf",
"(",
"$",
"that",
")",
";",
"if",
"(",
"$",
"that... | Returns the sum of this Money and the given amount.
If the operand is a Money, it must have the same context as this Money, or an exception is thrown.
This is by design, to ensure that contexts are not mixed accidentally.
If you do need to add a Money in a different context, you can use `plus($money->toRational())`.
The resulting Money has the same context as this Money. If the result needs rounding to fit this context, a
rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is
thrown.
@param AbstractMoney|BigNumber|number|string $that The money or amount to add.
@param int $roundingMode An optional RoundingMode constant.
@return Money
@throws MathException If the argument is an invalid number or rounding is necessary.
@throws MoneyMismatchException If the argument is a money in a different currency or in a different context. | [
"Returns",
"the",
"sum",
"of",
"this",
"Money",
"and",
"the",
"given",
"amount",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L329-L344 | train |
brick/money | src/Money.php | Money.multipliedBy | public function multipliedBy($that, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
$amount = $this->amount->toBigRational()->multipliedBy($that);
return self::create($amount, $this->currency, $this->context, $roundingMode);
} | php | public function multipliedBy($that, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
$amount = $this->amount->toBigRational()->multipliedBy($that);
return self::create($amount, $this->currency, $this->context, $roundingMode);
} | [
"public",
"function",
"multipliedBy",
"(",
"$",
"that",
",",
"int",
"$",
"roundingMode",
"=",
"RoundingMode",
"::",
"UNNECESSARY",
")",
":",
"Money",
"{",
"$",
"amount",
"=",
"$",
"this",
"->",
"amount",
"->",
"toBigRational",
"(",
")",
"->",
"multipliedBy... | Returns the product of this Money and the given number.
The resulting Money has the same context as this Money. If the result needs rounding to fit this context, a
rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is
thrown.
@param BigNumber|number|string $that The multiplier.
@param int $roundingMode An optional RoundingMode constant.
@return Money
@throws MathException If the argument is an invalid number or rounding is necessary. | [
"Returns",
"the",
"product",
"of",
"this",
"Money",
"and",
"the",
"given",
"number",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L396-L401 | train |
brick/money | src/Money.php | Money.quotient | public function quotient($that) : Money
{
$that = BigInteger::of($that);
$step = $this->context->getStep();
$scale = $this->amount->getScale();
$amount = $this->amount->withPointMovedRight($scale)->dividedBy($step);
$q = $amount->quotient($that);
$q = $q->multipliedBy($step)->withPointMovedLeft($scale);
return new Money($q, $this->currency, $this->context);
} | php | public function quotient($that) : Money
{
$that = BigInteger::of($that);
$step = $this->context->getStep();
$scale = $this->amount->getScale();
$amount = $this->amount->withPointMovedRight($scale)->dividedBy($step);
$q = $amount->quotient($that);
$q = $q->multipliedBy($step)->withPointMovedLeft($scale);
return new Money($q, $this->currency, $this->context);
} | [
"public",
"function",
"quotient",
"(",
"$",
"that",
")",
":",
"Money",
"{",
"$",
"that",
"=",
"BigInteger",
"::",
"of",
"(",
"$",
"that",
")",
";",
"$",
"step",
"=",
"$",
"this",
"->",
"context",
"->",
"getStep",
"(",
")",
";",
"$",
"scale",
"=",... | Returns the quotient of the division of this Money by the given number.
The given number must be a integer value. The resulting Money has the same context as this Money.
This method can serve as a basis for a money allocation algorithm.
@param BigNumber|number|string $that The divisor. Must be convertible to a BigInteger.
@return Money
@throws MathException If the divisor cannot be converted to a BigInteger. | [
"Returns",
"the",
"quotient",
"of",
"the",
"division",
"of",
"this",
"Money",
"by",
"the",
"given",
"number",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L436-L448 | train |
brick/money | src/Money.php | Money.allocate | public function allocate(int ...$ratios) : array
{
if (! $ratios) {
throw new \InvalidArgumentException('Cannot allocate() an empty list of ratios.');
}
foreach ($ratios as $ratio) {
if ($ratio < 0) {
throw new \InvalidArgumentException('Cannot allocate() negative ratios.');
}
}
$total = array_sum($ratios);
if ($total === 0) {
throw new \InvalidArgumentException('Cannot allocate() to zero ratios only.');
}
$step = $this->context->getStep();
$monies = [];
$unit = BigDecimal::ofUnscaledValue($step, $this->amount->getScale());
$unit = new Money($unit, $this->currency, $this->context);
if ($this->isNegative()) {
$unit = $unit->negated();
}
$remainder = $this;
foreach ($ratios as $ratio) {
$money = $this->multipliedBy($ratio)->quotient($total);
$remainder = $remainder->minus($money);
$monies[] = $money;
}
foreach ($monies as $key => $money) {
if ($remainder->isZero()) {
break;
}
$monies[$key] = $money->plus($unit);
$remainder = $remainder->minus($unit);
}
return $monies;
} | php | public function allocate(int ...$ratios) : array
{
if (! $ratios) {
throw new \InvalidArgumentException('Cannot allocate() an empty list of ratios.');
}
foreach ($ratios as $ratio) {
if ($ratio < 0) {
throw new \InvalidArgumentException('Cannot allocate() negative ratios.');
}
}
$total = array_sum($ratios);
if ($total === 0) {
throw new \InvalidArgumentException('Cannot allocate() to zero ratios only.');
}
$step = $this->context->getStep();
$monies = [];
$unit = BigDecimal::ofUnscaledValue($step, $this->amount->getScale());
$unit = new Money($unit, $this->currency, $this->context);
if ($this->isNegative()) {
$unit = $unit->negated();
}
$remainder = $this;
foreach ($ratios as $ratio) {
$money = $this->multipliedBy($ratio)->quotient($total);
$remainder = $remainder->minus($money);
$monies[] = $money;
}
foreach ($monies as $key => $money) {
if ($remainder->isZero()) {
break;
}
$monies[$key] = $money->plus($unit);
$remainder = $remainder->minus($unit);
}
return $monies;
} | [
"public",
"function",
"allocate",
"(",
"int",
"...",
"$",
"ratios",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"ratios",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Cannot allocate() an empty list of ratios.'",
")",
";",
"}",
"foreach"... | Allocates this Money according to a list of ratios.
If the allocation yields a remainder, its amount is split over the first monies in the list,
so that the total of the resulting monies is always equal to this Money.
For example, given a `USD 49.99` money in the default context,
`allocate(1, 2, 3, 4)` returns [`USD 5.00`, `USD 10.00`, `USD 15.00`, `USD 19.99`]
The resulting monies have the same context as this Money.
@param int[] $ratios The ratios.
@return Money[]
@throws \InvalidArgumentException If called with invalid parameters. | [
"Allocates",
"this",
"Money",
"according",
"to",
"a",
"list",
"of",
"ratios",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L498-L545 | train |
brick/money | src/Money.php | Money.abs | public function abs() : Money
{
return new Money($this->amount->abs(), $this->currency, $this->context);
} | php | public function abs() : Money
{
return new Money($this->amount->abs(), $this->currency, $this->context);
} | [
"public",
"function",
"abs",
"(",
")",
":",
"Money",
"{",
"return",
"new",
"Money",
"(",
"$",
"this",
"->",
"amount",
"->",
"abs",
"(",
")",
",",
"$",
"this",
"->",
"currency",
",",
"$",
"this",
"->",
"context",
")",
";",
"}"
] | Returns a Money whose value is the absolute value of this Money.
The resulting Money has the same context as this Money.
@return Money | [
"Returns",
"a",
"Money",
"whose",
"value",
"is",
"the",
"absolute",
"value",
"of",
"this",
"Money",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L580-L583 | train |
brick/money | src/Money.php | Money.negated | public function negated() : Money
{
return new Money($this->amount->negated(), $this->currency, $this->context);
} | php | public function negated() : Money
{
return new Money($this->amount->negated(), $this->currency, $this->context);
} | [
"public",
"function",
"negated",
"(",
")",
":",
"Money",
"{",
"return",
"new",
"Money",
"(",
"$",
"this",
"->",
"amount",
"->",
"negated",
"(",
")",
",",
"$",
"this",
"->",
"currency",
",",
"$",
"this",
"->",
"context",
")",
";",
"}"
] | Returns a Money whose value is the negated value of this Money.
The resulting Money has the same context as this Money.
@return Money | [
"Returns",
"a",
"Money",
"whose",
"value",
"is",
"the",
"negated",
"value",
"of",
"this",
"Money",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L592-L595 | train |
brick/money | src/Money.php | Money.convertedTo | public function convertedTo($currency, $exchangeRate, Context $context = null, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
if ($context === null) {
$context = $this->context;
}
$amount = $this->amount->toBigRational()->multipliedBy($exchangeRate);
return self::create($amount, $currency, $context, $roundingMode);
} | php | public function convertedTo($currency, $exchangeRate, Context $context = null, int $roundingMode = RoundingMode::UNNECESSARY) : Money
{
if (! $currency instanceof Currency) {
$currency = Currency::of($currency);
}
if ($context === null) {
$context = $this->context;
}
$amount = $this->amount->toBigRational()->multipliedBy($exchangeRate);
return self::create($amount, $currency, $context, $roundingMode);
} | [
"public",
"function",
"convertedTo",
"(",
"$",
"currency",
",",
"$",
"exchangeRate",
",",
"Context",
"$",
"context",
"=",
"null",
",",
"int",
"$",
"roundingMode",
"=",
"RoundingMode",
"::",
"UNNECESSARY",
")",
":",
"Money",
"{",
"if",
"(",
"!",
"$",
"cur... | Converts this Money to another currency, using an exchange rate.
By default, the resulting Money has the same context as this Money.
This can be overridden by providing a Context.
For example, converting a default money of `USD 1.23` to `EUR` with an exchange rate of `0.91` and
RoundingMode::UP will yield `EUR 1.12`.
@param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
@param BigNumber|number|string $exchangeRate The exchange rate to multiply by.
@param Context|null $context An optional context.
@param int $roundingMode An optional rounding mode.
@return Money
@throws UnknownCurrencyException If an unknown currency code is given.
@throws MathException If the exchange rate or rounding mode is invalid, or rounding is necessary. | [
"Converts",
"this",
"Money",
"to",
"another",
"currency",
"using",
"an",
"exchange",
"rate",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L616-L629 | train |
brick/money | src/Money.php | Money.formatWith | public function formatWith(\NumberFormatter $formatter) : string
{
return $formatter->formatCurrency(
$this->amount->toFloat(),
$this->currency->getCurrencyCode()
);
} | php | public function formatWith(\NumberFormatter $formatter) : string
{
return $formatter->formatCurrency(
$this->amount->toFloat(),
$this->currency->getCurrencyCode()
);
} | [
"public",
"function",
"formatWith",
"(",
"\\",
"NumberFormatter",
"$",
"formatter",
")",
":",
"string",
"{",
"return",
"$",
"formatter",
"->",
"formatCurrency",
"(",
"$",
"this",
"->",
"amount",
"->",
"toFloat",
"(",
")",
",",
"$",
"this",
"->",
"currency"... | Formats this Money with the given NumberFormatter.
Note that NumberFormatter internally represents values using floating point arithmetic,
so discrepancies can appear when formatting very large monetary values.
@param \NumberFormatter $formatter The formatter to format with.
@return string | [
"Formats",
"this",
"Money",
"with",
"the",
"given",
"NumberFormatter",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L641-L647 | train |
brick/money | src/Money.php | Money.formatTo | public function formatTo(string $locale, bool $allowWholeNumber = false) : string
{
$scale = $this->amount->getScale();
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
if ($allowWholeNumber && ! $this->amount->hasNonZeroFractionalPart()) {
$scale = 0;
}
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $scale);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $scale);
return $this->formatWith($formatter);
} | php | public function formatTo(string $locale, bool $allowWholeNumber = false) : string
{
$scale = $this->amount->getScale();
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
if ($allowWholeNumber && ! $this->amount->hasNonZeroFractionalPart()) {
$scale = 0;
}
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $scale);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $scale);
return $this->formatWith($formatter);
} | [
"public",
"function",
"formatTo",
"(",
"string",
"$",
"locale",
",",
"bool",
"$",
"allowWholeNumber",
"=",
"false",
")",
":",
"string",
"{",
"$",
"scale",
"=",
"$",
"this",
"->",
"amount",
"->",
"getScale",
"(",
")",
";",
"$",
"formatter",
"=",
"new",
... | Formats this Money to the given locale.
Note that this method uses NumberFormatter, which internally represents values using floating point arithmetic,
so discrepancies can appear when formatting very large monetary values.
@param string $locale The locale to format to.
@param bool $allowWholeNumber Whether to allow formatting as a whole number if the amount has no fraction.
@return string | [
"Formats",
"this",
"Money",
"to",
"the",
"given",
"locale",
"."
] | 7ff8dce2546878097714e7380e2a228408c0edc7 | https://github.com/brick/money/blob/7ff8dce2546878097714e7380e2a228408c0edc7/src/Money.php#L660-L674 | train |
guzzle/guzzle3 | src/Guzzle/Http/Exception/BadResponseException.php | BadResponseException.factory | public static function factory(RequestInterface $request, Response $response)
{
if ($response->isClientError()) {
$label = 'Client error response';
$class = __NAMESPACE__ . '\\ClientErrorResponseException';
} elseif ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
$message = $label . PHP_EOL . implode(PHP_EOL, array(
'[status code] ' . $response->getStatusCode(),
'[reason phrase] ' . $response->getReasonPhrase(),
'[url] ' . $request->getUrl(),
));
$e = new $class($message);
$e->setResponse($response);
$e->setRequest($request);
return $e;
} | php | public static function factory(RequestInterface $request, Response $response)
{
if ($response->isClientError()) {
$label = 'Client error response';
$class = __NAMESPACE__ . '\\ClientErrorResponseException';
} elseif ($response->isServerError()) {
$label = 'Server error response';
$class = __NAMESPACE__ . '\\ServerErrorResponseException';
} else {
$label = 'Unsuccessful response';
$class = __CLASS__;
}
$message = $label . PHP_EOL . implode(PHP_EOL, array(
'[status code] ' . $response->getStatusCode(),
'[reason phrase] ' . $response->getReasonPhrase(),
'[url] ' . $request->getUrl(),
));
$e = new $class($message);
$e->setResponse($response);
$e->setRequest($request);
return $e;
} | [
"public",
"static",
"function",
"factory",
"(",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"response",
"->",
"isClientError",
"(",
")",
")",
"{",
"$",
"label",
"=",
"'Client error response'",
";",
"$",
"... | Factory method to create a new response exception based on the response code.
@param RequestInterface $request Request
@param Response $response Response received
@return BadResponseException | [
"Factory",
"method",
"to",
"create",
"a",
"new",
"response",
"exception",
"based",
"on",
"the",
"response",
"code",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Exception/BadResponseException.php#L24-L48 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Parameter.php | Parameter.setData | public function setData($nameOrData, $data = null)
{
if (is_array($nameOrData)) {
$this->data = $nameOrData;
} else {
$this->data[$nameOrData] = $data;
}
return $this;
} | php | public function setData($nameOrData, $data = null)
{
if (is_array($nameOrData)) {
$this->data = $nameOrData;
} else {
$this->data[$nameOrData] = $data;
}
return $this;
} | [
"public",
"function",
"setData",
"(",
"$",
"nameOrData",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"nameOrData",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"nameOrData",
";",
"}",
"else",
"{",
"$",
"this",
... | Set the extra data properties of the parameter or set a specific extra property
@param string|array|null $nameOrData The name of a specific extra to set or an array of extras to set
@param mixed|null $data When setting a specific extra property, specify the data to set for it
@return self | [
"Set",
"the",
"extra",
"data",
"properties",
"of",
"the",
"parameter",
"or",
"set",
"a",
"specific",
"extra",
"property"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Parameter.php#L589-L598 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Parameter.php | Parameter.getProperty | public function getProperty($name)
{
if (!isset($this->properties[$name])) {
return null;
}
if (!($this->properties[$name] instanceof self)) {
$this->properties[$name]['name'] = $name;
$this->properties[$name] = new static($this->properties[$name], $this->serviceDescription);
$this->properties[$name]->setParent($this);
}
return $this->properties[$name];
} | php | public function getProperty($name)
{
if (!isset($this->properties[$name])) {
return null;
}
if (!($this->properties[$name] instanceof self)) {
$this->properties[$name]['name'] = $name;
$this->properties[$name] = new static($this->properties[$name], $this->serviceDescription);
$this->properties[$name]->setParent($this);
}
return $this->properties[$name];
} | [
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"properties"... | Get a specific property from the parameter
@param string $name Name of the property to retrieve
@return null|Parameter | [
"Get",
"a",
"specific",
"property",
"from",
"the",
"parameter"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Parameter.php#L724-L737 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Parameter.php | Parameter.addProperty | public function addProperty(Parameter $property)
{
$this->properties[$property->getName()] = $property;
$property->setParent($this);
$this->propertiesCache = null;
return $this;
} | php | public function addProperty(Parameter $property)
{
$this->properties[$property->getName()] = $property;
$property->setParent($this);
$this->propertiesCache = null;
return $this;
} | [
"public",
"function",
"addProperty",
"(",
"Parameter",
"$",
"property",
")",
"{",
"$",
"this",
"->",
"properties",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"property",
";",
"$",
"property",
"->",
"setParent",
"(",
"$",
"this",
")... | Add a property to the parameter
@param Parameter $property Properties to set
@return self | [
"Add",
"a",
"property",
"to",
"the",
"parameter"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Parameter.php#L761-L768 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Parameter.php | Parameter.setItems | public function setItems(Parameter $items = null)
{
if ($this->items = $items) {
$this->items->setParent($this);
}
return $this;
} | php | public function setItems(Parameter $items = null)
{
if ($this->items = $items) {
$this->items->setParent($this);
}
return $this;
} | [
"public",
"function",
"setItems",
"(",
"Parameter",
"$",
"items",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"items",
"=",
"$",
"items",
")",
"{",
"$",
"this",
"->",
"items",
"->",
"setParent",
"(",
"$",
"this",
")",
";",
"}",
"return",
... | Set the items data of the parameter
@param Parameter|null $items Items to set
@return self | [
"Set",
"the",
"items",
"data",
"of",
"the",
"parameter"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Parameter.php#L806-L813 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Parameter.php | Parameter.getItems | public function getItems()
{
if (is_array($this->items)) {
$this->items = new static($this->items, $this->serviceDescription);
$this->items->setParent($this);
}
return $this->items;
} | php | public function getItems()
{
if (is_array($this->items)) {
$this->items = new static($this->items, $this->serviceDescription);
$this->items->setParent($this);
}
return $this->items;
} | [
"public",
"function",
"getItems",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"items",
")",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"new",
"static",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"this",
"->",
"serviceDescription",
... | Get the item data of the parameter
@return Parameter|null | [
"Get",
"the",
"item",
"data",
"of",
"the",
"parameter"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Parameter.php#L820-L828 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/Factory/CompositeFactory.php | CompositeFactory.getDefaultChain | public static function getDefaultChain(ClientInterface $client)
{
$factories = array();
if ($description = $client->getDescription()) {
$factories[] = new ServiceDescriptionFactory($description);
}
$factories[] = new ConcreteClassFactory($client);
return new static($factories);
} | php | public static function getDefaultChain(ClientInterface $client)
{
$factories = array();
if ($description = $client->getDescription()) {
$factories[] = new ServiceDescriptionFactory($description);
}
$factories[] = new ConcreteClassFactory($client);
return new static($factories);
} | [
"public",
"static",
"function",
"getDefaultChain",
"(",
"ClientInterface",
"$",
"client",
")",
"{",
"$",
"factories",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"description",
"=",
"$",
"client",
"->",
"getDescription",
"(",
")",
")",
"{",
"$",
"factor... | Get the default chain to use with clients
@param ClientInterface $client Client to base the chain on
@return self | [
"Get",
"the",
"default",
"chain",
"to",
"use",
"with",
"clients"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/Factory/CompositeFactory.php#L23-L32 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/Factory/CompositeFactory.php | CompositeFactory.add | public function add(FactoryInterface $factory, $before = null)
{
$pos = null;
if ($before) {
foreach ($this->factories as $i => $f) {
if ($before instanceof FactoryInterface) {
if ($f === $before) {
$pos = $i;
break;
}
} elseif (is_string($before)) {
if ($f instanceof $before) {
$pos = $i;
break;
}
}
}
}
if ($pos === null) {
$this->factories[] = $factory;
} else {
array_splice($this->factories, $i, 0, array($factory));
}
return $this;
} | php | public function add(FactoryInterface $factory, $before = null)
{
$pos = null;
if ($before) {
foreach ($this->factories as $i => $f) {
if ($before instanceof FactoryInterface) {
if ($f === $before) {
$pos = $i;
break;
}
} elseif (is_string($before)) {
if ($f instanceof $before) {
$pos = $i;
break;
}
}
}
}
if ($pos === null) {
$this->factories[] = $factory;
} else {
array_splice($this->factories, $i, 0, array($factory));
}
return $this;
} | [
"public",
"function",
"add",
"(",
"FactoryInterface",
"$",
"factory",
",",
"$",
"before",
"=",
"null",
")",
"{",
"$",
"pos",
"=",
"null",
";",
"if",
"(",
"$",
"before",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"factories",
"as",
"$",
"i",
"=>",... | Add a command factory to the chain
@param FactoryInterface $factory Factory to add
@param string|FactoryInterface $before Insert the new command factory before a command factory class or object
matching a class name.
@return CompositeFactory | [
"Add",
"a",
"command",
"factory",
"to",
"the",
"chain"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/Factory/CompositeFactory.php#L50-L77 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/Factory/CompositeFactory.php | CompositeFactory.remove | public function remove($factory = null)
{
if (!($factory instanceof FactoryInterface)) {
$factory = $this->find($factory);
}
$this->factories = array_values(array_filter($this->factories, function($f) use ($factory) {
return $f !== $factory;
}));
return $this;
} | php | public function remove($factory = null)
{
if (!($factory instanceof FactoryInterface)) {
$factory = $this->find($factory);
}
$this->factories = array_values(array_filter($this->factories, function($f) use ($factory) {
return $f !== $factory;
}));
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"factory",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"factory",
"instanceof",
"FactoryInterface",
")",
")",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"factory",
")",
";",
"}",
"$... | Remove a specific command factory from the chain
@param string|FactoryInterface $factory Factory to remove by name or instance
@return CompositeFactory | [
"Remove",
"a",
"specific",
"command",
"factory",
"from",
"the",
"chain"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/Factory/CompositeFactory.php#L98-L109 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/Factory/CompositeFactory.php | CompositeFactory.find | public function find($factory)
{
foreach ($this->factories as $f) {
if ($factory === $f || (is_string($factory) && $f instanceof $factory)) {
return $f;
}
}
} | php | public function find($factory)
{
foreach ($this->factories as $f) {
if ($factory === $f || (is_string($factory) && $f instanceof $factory)) {
return $f;
}
}
} | [
"public",
"function",
"find",
"(",
"$",
"factory",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"factories",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"factory",
"===",
"$",
"f",
"||",
"(",
"is_string",
"(",
"$",
"factory",
")",
"&&",
"$",
"f",
... | Get a command factory by class name
@param string|FactoryInterface $factory Command factory class or instance
@return null|FactoryInterface | [
"Get",
"a",
"command",
"factory",
"by",
"class",
"name"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/Factory/CompositeFactory.php#L118-L125 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/Factory/CompositeFactory.php | CompositeFactory.factory | public function factory($name, array $args = array())
{
foreach ($this->factories as $factory) {
$command = $factory->factory($name, $args);
if ($command) {
return $command;
}
}
} | php | public function factory($name, array $args = array())
{
foreach ($this->factories as $factory) {
$command = $factory->factory($name, $args);
if ($command) {
return $command;
}
}
} | [
"public",
"function",
"factory",
"(",
"$",
"name",
",",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"factories",
"as",
"$",
"factory",
")",
"{",
"$",
"command",
"=",
"$",
"factory",
"->",
"factory",
"(... | Create a command using the associated command factories
@param string $name Name of the command
@param array $args Command arguments
@return CommandInterface | [
"Create",
"a",
"command",
"using",
"the",
"associated",
"command",
"factories"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/Factory/CompositeFactory.php#L135-L143 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/DefaultCacheStorage.php | DefaultCacheStorage.getCacheKey | protected function getCacheKey(RequestInterface $request)
{
// Allow cache.key_filter to trim down the URL cache key by removing generate query string values (e.g. auth)
if ($filter = $request->getParams()->get('cache.key_filter')) {
$url = $request->getUrl(true);
foreach (explode(',', $filter) as $remove) {
$url->getQuery()->remove(trim($remove));
}
} else {
$url = $request->getUrl();
}
return $this->keyPrefix . md5($request->getMethod() . ' ' . $url);
} | php | protected function getCacheKey(RequestInterface $request)
{
// Allow cache.key_filter to trim down the URL cache key by removing generate query string values (e.g. auth)
if ($filter = $request->getParams()->get('cache.key_filter')) {
$url = $request->getUrl(true);
foreach (explode(',', $filter) as $remove) {
$url->getQuery()->remove(trim($remove));
}
} else {
$url = $request->getUrl();
}
return $this->keyPrefix . md5($request->getMethod() . ' ' . $url);
} | [
"protected",
"function",
"getCacheKey",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"// Allow cache.key_filter to trim down the URL cache key by removing generate query string values (e.g. auth)",
"if",
"(",
"$",
"filter",
"=",
"$",
"request",
"->",
"getParams",
"(",
"... | Hash a request URL into a string that returns cache metadata
@param RequestInterface $request
@return string | [
"Hash",
"a",
"request",
"URL",
"into",
"a",
"string",
"that",
"returns",
"cache",
"metadata"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/DefaultCacheStorage.php#L181-L194 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/DefaultCacheStorage.php | DefaultCacheStorage.getBodyKey | protected function getBodyKey($url, EntityBodyInterface $body)
{
return $this->keyPrefix . md5($url) . $body->getContentMd5();
} | php | protected function getBodyKey($url, EntityBodyInterface $body)
{
return $this->keyPrefix . md5($url) . $body->getContentMd5();
} | [
"protected",
"function",
"getBodyKey",
"(",
"$",
"url",
",",
"EntityBodyInterface",
"$",
"body",
")",
"{",
"return",
"$",
"this",
"->",
"keyPrefix",
".",
"md5",
"(",
"$",
"url",
")",
".",
"$",
"body",
"->",
"getContentMd5",
"(",
")",
";",
"}"
] | Create a cache key for a response's body
@param string $url URL of the entry
@param EntityBodyInterface $body Response body
@return string | [
"Create",
"a",
"cache",
"key",
"for",
"a",
"response",
"s",
"body"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/DefaultCacheStorage.php#L204-L207 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/DefaultCacheStorage.php | DefaultCacheStorage.requestsMatch | private function requestsMatch($vary, $r1, $r2)
{
if ($vary) {
foreach (explode(',', $vary) as $header) {
$key = trim(strtolower($header));
$v1 = isset($r1[$key]) ? $r1[$key] : null;
$v2 = isset($r2[$key]) ? $r2[$key] : null;
if ($v1 !== $v2) {
return false;
}
}
}
return true;
} | php | private function requestsMatch($vary, $r1, $r2)
{
if ($vary) {
foreach (explode(',', $vary) as $header) {
$key = trim(strtolower($header));
$v1 = isset($r1[$key]) ? $r1[$key] : null;
$v2 = isset($r2[$key]) ? $r2[$key] : null;
if ($v1 !== $v2) {
return false;
}
}
}
return true;
} | [
"private",
"function",
"requestsMatch",
"(",
"$",
"vary",
",",
"$",
"r1",
",",
"$",
"r2",
")",
"{",
"if",
"(",
"$",
"vary",
")",
"{",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"vary",
")",
"as",
"$",
"header",
")",
"{",
"$",
"key",
"=",
... | Determines whether two Request HTTP header sets are non-varying
@param string $vary Response vary header
@param array $r1 HTTP header array
@param array $r2 HTTP header array
@return bool | [
"Determines",
"whether",
"two",
"Request",
"HTTP",
"header",
"sets",
"are",
"non",
"-",
"varying"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/DefaultCacheStorage.php#L218-L232 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/DefaultCacheStorage.php | DefaultCacheStorage.persistHeaders | private function persistHeaders(MessageInterface $message)
{
// Headers are excluded from the caching (see RFC 2616:13.5.1)
static $noCache = array(
'age' => true,
'connection' => true,
'keep-alive' => true,
'proxy-authenticate' => true,
'proxy-authorization' => true,
'te' => true,
'trailers' => true,
'transfer-encoding' => true,
'upgrade' => true,
'set-cookie' => true,
'set-cookie2' => true
);
// Clone the response to not destroy any necessary headers when caching
$headers = $message->getHeaders()->getAll();
$headers = array_diff_key($headers, $noCache);
// Cast the headers to a string
$headers = array_map(function ($h) { return (string) $h; }, $headers);
return $headers;
} | php | private function persistHeaders(MessageInterface $message)
{
// Headers are excluded from the caching (see RFC 2616:13.5.1)
static $noCache = array(
'age' => true,
'connection' => true,
'keep-alive' => true,
'proxy-authenticate' => true,
'proxy-authorization' => true,
'te' => true,
'trailers' => true,
'transfer-encoding' => true,
'upgrade' => true,
'set-cookie' => true,
'set-cookie2' => true
);
// Clone the response to not destroy any necessary headers when caching
$headers = $message->getHeaders()->getAll();
$headers = array_diff_key($headers, $noCache);
// Cast the headers to a string
$headers = array_map(function ($h) { return (string) $h; }, $headers);
return $headers;
} | [
"private",
"function",
"persistHeaders",
"(",
"MessageInterface",
"$",
"message",
")",
"{",
"// Headers are excluded from the caching (see RFC 2616:13.5.1)",
"static",
"$",
"noCache",
"=",
"array",
"(",
"'age'",
"=>",
"true",
",",
"'connection'",
"=>",
"true",
",",
"'... | Creates an array of cacheable and normalized message headers
@param MessageInterface $message
@return array | [
"Creates",
"an",
"array",
"of",
"cacheable",
"and",
"normalized",
"message",
"headers"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/DefaultCacheStorage.php#L241-L265 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Operation.php | Operation.addParam | public function addParam(Parameter $param)
{
$this->parameters[$param->getName()] = $param;
$param->setParent($this);
return $this;
} | php | public function addParam(Parameter $param)
{
$this->parameters[$param->getName()] = $param;
$param->setParent($this);
return $this;
} | [
"public",
"function",
"addParam",
"(",
"Parameter",
"$",
"param",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"$",
"param",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"param",
";",
"$",
"param",
"->",
"setParent",
"(",
"$",
"this",
")",
";",
"re... | Add a parameter to the command
@param Parameter $param Parameter to add
@return self | [
"Add",
"a",
"parameter",
"to",
"the",
"command"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Operation.php#L208-L214 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Operation.php | Operation.setResponseType | public function setResponseType($responseType)
{
static $types = array(
self::TYPE_PRIMITIVE => true,
self::TYPE_CLASS => true,
self::TYPE_MODEL => true,
self::TYPE_DOCUMENTATION => true
);
if (!isset($types[$responseType])) {
throw new InvalidArgumentException('responseType must be one of ' . implode(', ', array_keys($types)));
}
$this->responseType = $responseType;
return $this;
} | php | public function setResponseType($responseType)
{
static $types = array(
self::TYPE_PRIMITIVE => true,
self::TYPE_CLASS => true,
self::TYPE_MODEL => true,
self::TYPE_DOCUMENTATION => true
);
if (!isset($types[$responseType])) {
throw new InvalidArgumentException('responseType must be one of ' . implode(', ', array_keys($types)));
}
$this->responseType = $responseType;
return $this;
} | [
"public",
"function",
"setResponseType",
"(",
"$",
"responseType",
")",
"{",
"static",
"$",
"types",
"=",
"array",
"(",
"self",
"::",
"TYPE_PRIMITIVE",
"=>",
"true",
",",
"self",
"::",
"TYPE_CLASS",
"=>",
"true",
",",
"self",
"::",
"TYPE_MODEL",
"=>",
"tru... | Set qualifying information about the responseClass. One of 'primitive', 'class', 'model', or 'documentation'
@param string $responseType Response type information
@return self
@throws InvalidArgumentException | [
"Set",
"qualifying",
"information",
"about",
"the",
"responseClass",
".",
"One",
"of",
"primitive",
"class",
"model",
"or",
"documentation"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Operation.php#L378-L393 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Operation.php | Operation.setAdditionalParameters | public function setAdditionalParameters($parameter)
{
if ($this->additionalParameters = $parameter) {
$this->additionalParameters->setParent($this);
}
return $this;
} | php | public function setAdditionalParameters($parameter)
{
if ($this->additionalParameters = $parameter) {
$this->additionalParameters->setParent($this);
}
return $this;
} | [
"public",
"function",
"setAdditionalParameters",
"(",
"$",
"parameter",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"additionalParameters",
"=",
"$",
"parameter",
")",
"{",
"$",
"this",
"->",
"additionalParameters",
"->",
"setParent",
"(",
"$",
"this",
")",
";",... | Set the additionalParameters of the operation
@param Parameter|null $parameter Parameter to set
@return self | [
"Set",
"the",
"additionalParameters",
"of",
"the",
"operation"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Operation.php#L524-L531 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/Operation.php | Operation.inferResponseType | protected function inferResponseType()
{
static $primitives = array('array' => 1, 'boolean' => 1, 'string' => 1, 'integer' => 1, '' => 1);
if (isset($primitives[$this->responseClass])) {
$this->responseType = self::TYPE_PRIMITIVE;
} elseif ($this->description && $this->description->hasModel($this->responseClass)) {
$this->responseType = self::TYPE_MODEL;
} else {
$this->responseType = self::TYPE_CLASS;
}
} | php | protected function inferResponseType()
{
static $primitives = array('array' => 1, 'boolean' => 1, 'string' => 1, 'integer' => 1, '' => 1);
if (isset($primitives[$this->responseClass])) {
$this->responseType = self::TYPE_PRIMITIVE;
} elseif ($this->description && $this->description->hasModel($this->responseClass)) {
$this->responseType = self::TYPE_MODEL;
} else {
$this->responseType = self::TYPE_CLASS;
}
} | [
"protected",
"function",
"inferResponseType",
"(",
")",
"{",
"static",
"$",
"primitives",
"=",
"array",
"(",
"'array'",
"=>",
"1",
",",
"'boolean'",
"=>",
"1",
",",
"'string'",
"=>",
"1",
",",
"'integer'",
"=>",
"1",
",",
"''",
"=>",
"1",
")",
";",
"... | Infer the response type from the responseClass value | [
"Infer",
"the",
"response",
"type",
"from",
"the",
"responseClass",
"value"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/Operation.php#L536-L546 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/HeaderCollection.php | HeaderCollection.add | public function add(HeaderInterface $header)
{
$this->headers[strtolower($header->getName())] = $header;
return $this;
} | php | public function add(HeaderInterface $header)
{
$this->headers[strtolower($header->getName())] = $header;
return $this;
} | [
"public",
"function",
"add",
"(",
"HeaderInterface",
"$",
"header",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"strtolower",
"(",
"$",
"header",
"->",
"getName",
"(",
")",
")",
"]",
"=",
"$",
"header",
";",
"return",
"$",
"this",
";",
"}"
] | Set a header on the collection
@param HeaderInterface $header Header to add
@return self | [
"Set",
"a",
"header",
"on",
"the",
"collection"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/HeaderCollection.php#L42-L47 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/RequestMediator.php | RequestMediator.progress | public function progress($downloadSize, $downloaded, $uploadSize, $uploaded, $handle = null)
{
$this->request->dispatch('curl.callback.progress', array(
'request' => $this->request,
'handle' => $handle,
'download_size' => $downloadSize,
'downloaded' => $downloaded,
'upload_size' => $uploadSize,
'uploaded' => $uploaded
));
} | php | public function progress($downloadSize, $downloaded, $uploadSize, $uploaded, $handle = null)
{
$this->request->dispatch('curl.callback.progress', array(
'request' => $this->request,
'handle' => $handle,
'download_size' => $downloadSize,
'downloaded' => $downloaded,
'upload_size' => $uploadSize,
'uploaded' => $uploaded
));
} | [
"public",
"function",
"progress",
"(",
"$",
"downloadSize",
",",
"$",
"downloaded",
",",
"$",
"uploadSize",
",",
"$",
"uploaded",
",",
"$",
"handle",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"request",
"->",
"dispatch",
"(",
"'curl.callback.progress'",
",... | Received a progress notification
@param int $downloadSize Total download size
@param int $downloaded Amount of bytes downloaded
@param int $uploadSize Total upload size
@param int $uploaded Amount of bytes uploaded
@param resource $handle CurlHandle object | [
"Received",
"a",
"progress",
"notification"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/RequestMediator.php#L90-L100 | train |
guzzle/guzzle3 | src/Guzzle/Parser/Message/AbstractMessageParser.php | AbstractMessageParser.getUrlPartsFromMessage | protected function getUrlPartsFromMessage($requestUrl, array $parts)
{
// Parse the URL information from the message
$urlParts = array(
'path' => $requestUrl,
'scheme' => 'http'
);
// Check for the Host header
if (isset($parts['headers']['Host'])) {
$urlParts['host'] = $parts['headers']['Host'];
} elseif (isset($parts['headers']['host'])) {
$urlParts['host'] = $parts['headers']['host'];
} else {
$urlParts['host'] = null;
}
if (false === strpos($urlParts['host'], ':')) {
$urlParts['port'] = '';
} else {
$hostParts = explode(':', $urlParts['host']);
$urlParts['host'] = trim($hostParts[0]);
$urlParts['port'] = (int) trim($hostParts[1]);
if ($urlParts['port'] == 443) {
$urlParts['scheme'] = 'https';
}
}
// Check if a query is present
$path = $urlParts['path'];
$qpos = strpos($path, '?');
if ($qpos) {
$urlParts['query'] = substr($path, $qpos + 1);
$urlParts['path'] = substr($path, 0, $qpos);
} else {
$urlParts['query'] = '';
}
return $urlParts;
} | php | protected function getUrlPartsFromMessage($requestUrl, array $parts)
{
// Parse the URL information from the message
$urlParts = array(
'path' => $requestUrl,
'scheme' => 'http'
);
// Check for the Host header
if (isset($parts['headers']['Host'])) {
$urlParts['host'] = $parts['headers']['Host'];
} elseif (isset($parts['headers']['host'])) {
$urlParts['host'] = $parts['headers']['host'];
} else {
$urlParts['host'] = null;
}
if (false === strpos($urlParts['host'], ':')) {
$urlParts['port'] = '';
} else {
$hostParts = explode(':', $urlParts['host']);
$urlParts['host'] = trim($hostParts[0]);
$urlParts['port'] = (int) trim($hostParts[1]);
if ($urlParts['port'] == 443) {
$urlParts['scheme'] = 'https';
}
}
// Check if a query is present
$path = $urlParts['path'];
$qpos = strpos($path, '?');
if ($qpos) {
$urlParts['query'] = substr($path, $qpos + 1);
$urlParts['path'] = substr($path, 0, $qpos);
} else {
$urlParts['query'] = '';
}
return $urlParts;
} | [
"protected",
"function",
"getUrlPartsFromMessage",
"(",
"$",
"requestUrl",
",",
"array",
"$",
"parts",
")",
"{",
"// Parse the URL information from the message",
"$",
"urlParts",
"=",
"array",
"(",
"'path'",
"=>",
"$",
"requestUrl",
",",
"'scheme'",
"=>",
"'http'",
... | Create URL parts from HTTP message parts
@param string $requestUrl Associated URL
@param array $parts HTTP message parts
@return array | [
"Create",
"URL",
"parts",
"from",
"HTTP",
"message",
"parts"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Parser/Message/AbstractMessageParser.php#L18-L57 | train |
guzzle/guzzle3 | src/Guzzle/Inflection/MemoizingInflector.php | MemoizingInflector.pruneCache | protected function pruneCache($cache)
{
if (count($this->cache[$cache]) == $this->maxCacheSize) {
$this->cache[$cache] = array_slice($this->cache[$cache], $this->maxCacheSize * 0.2);
}
} | php | protected function pruneCache($cache)
{
if (count($this->cache[$cache]) == $this->maxCacheSize) {
$this->cache[$cache] = array_slice($this->cache[$cache], $this->maxCacheSize * 0.2);
}
} | [
"protected",
"function",
"pruneCache",
"(",
"$",
"cache",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"cache",
"]",
")",
"==",
"$",
"this",
"->",
"maxCacheSize",
")",
"{",
"$",
"this",
"->",
"cache",
"[",
"$",
"cache",
... | Prune one of the named caches by removing 20% of the cache if it is full
@param string $cache Type of cache to prune | [
"Prune",
"one",
"of",
"the",
"named",
"caches",
"by",
"removing",
"20%",
"of",
"the",
"cache",
"if",
"it",
"is",
"full"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Inflection/MemoizingInflector.php#L64-L69 | train |
guzzle/guzzle3 | src/Guzzle/Batch/Batch.php | Batch.createBatches | protected function createBatches()
{
if (count($this->queue)) {
if ($batches = $this->divisionStrategy->createBatches($this->queue)) {
// Convert arrays into iterators
if (is_array($batches)) {
$batches = new \ArrayIterator($batches);
}
$this->dividedBatches[] = $batches;
}
}
} | php | protected function createBatches()
{
if (count($this->queue)) {
if ($batches = $this->divisionStrategy->createBatches($this->queue)) {
// Convert arrays into iterators
if (is_array($batches)) {
$batches = new \ArrayIterator($batches);
}
$this->dividedBatches[] = $batches;
}
}
} | [
"protected",
"function",
"createBatches",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"queue",
")",
")",
"{",
"if",
"(",
"$",
"batches",
"=",
"$",
"this",
"->",
"divisionStrategy",
"->",
"createBatches",
"(",
"$",
"this",
"->",
"queue",
... | Create batches for any queued items | [
"Create",
"batches",
"for",
"any",
"queued",
"items"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Batch/Batch.php#L80-L91 | train |
guzzle/guzzle3 | src/Guzzle/Common/Exception/ExceptionCollection.php | ExceptionCollection.setExceptions | public function setExceptions(array $exceptions)
{
$this->exceptions = array();
foreach ($exceptions as $exception) {
$this->add($exception);
}
return $this;
} | php | public function setExceptions(array $exceptions)
{
$this->exceptions = array();
foreach ($exceptions as $exception) {
$this->add($exception);
}
return $this;
} | [
"public",
"function",
"setExceptions",
"(",
"array",
"$",
"exceptions",
")",
"{",
"$",
"this",
"->",
"exceptions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"exceptions",
"as",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"... | Set all of the exceptions
@param array $exceptions Array of exceptions
@return self | [
"Set",
"all",
"of",
"the",
"exceptions"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Common/Exception/ExceptionCollection.php#L29-L37 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlMultiProxy.php | CurlMultiProxy.cleanupHandles | protected function cleanupHandles()
{
if ($diff = max(0, count($this->handles) - $this->maxHandles)) {
for ($i = count($this->handles) - 1; $i > 0 && $diff > 0; $i--) {
if (!count($this->handles[$i])) {
unset($this->handles[$i]);
$diff--;
}
}
$this->handles = array_values($this->handles);
}
} | php | protected function cleanupHandles()
{
if ($diff = max(0, count($this->handles) - $this->maxHandles)) {
for ($i = count($this->handles) - 1; $i > 0 && $diff > 0; $i--) {
if (!count($this->handles[$i])) {
unset($this->handles[$i]);
$diff--;
}
}
$this->handles = array_values($this->handles);
}
} | [
"protected",
"function",
"cleanupHandles",
"(",
")",
"{",
"if",
"(",
"$",
"diff",
"=",
"max",
"(",
"0",
",",
"count",
"(",
"$",
"this",
"->",
"handles",
")",
"-",
"$",
"this",
"->",
"maxHandles",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"count",... | Trims down unused CurlMulti handles to limit the number of open connections | [
"Trims",
"down",
"unused",
"CurlMulti",
"handles",
"to",
"limit",
"the",
"number",
"of",
"open",
"connections"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlMultiProxy.php#L138-L149 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Request.php | Request.onRequestError | public static function onRequestError(Event $event)
{
$e = BadResponseException::factory($event['request'], $event['response']);
$event['request']->setState(self::STATE_ERROR, array('exception' => $e) + $event->toArray());
throw $e;
} | php | public static function onRequestError(Event $event)
{
$e = BadResponseException::factory($event['request'], $event['response']);
$event['request']->setState(self::STATE_ERROR, array('exception' => $e) + $event->toArray());
throw $e;
} | [
"public",
"static",
"function",
"onRequestError",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"e",
"=",
"BadResponseException",
"::",
"factory",
"(",
"$",
"event",
"[",
"'request'",
"]",
",",
"$",
"event",
"[",
"'response'",
"]",
")",
";",
"$",
"event",
... | Default method that will throw exceptions if an unsuccessful response is received.
@param Event $event Received
@throws BadResponseException if the response is not successful | [
"Default",
"method",
"that",
"will",
"throw",
"exceptions",
"if",
"an",
"unsuccessful",
"response",
"is",
"received",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Request.php#L143-L148 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Request.php | Request.processResponse | protected function processResponse(array $context = array())
{
if (!$this->response) {
// If no response, then processResponse shouldn't have been called
$e = new RequestException('Error completing request');
$e->setRequest($this);
throw $e;
}
$this->state = self::STATE_COMPLETE;
// A request was sent, but we don't know if we'll send more or if the final response will be successful
$this->dispatch('request.sent', $this->getEventArray() + $context);
// Some response processors will remove the response or reset the state (example: ExponentialBackoffPlugin)
if ($this->state == RequestInterface::STATE_COMPLETE) {
// The request completed, so the HTTP transaction is complete
$this->dispatch('request.complete', $this->getEventArray());
// If the response is bad, allow listeners to modify it or throw exceptions. You can change the response by
// modifying the Event object in your listeners or calling setResponse() on the request
if ($this->response->isError()) {
$event = new Event($this->getEventArray());
$this->getEventDispatcher()->dispatch('request.error', $event);
// Allow events of request.error to quietly change the response
if ($event['response'] !== $this->response) {
$this->response = $event['response'];
}
}
// If a successful response was received, dispatch an event
if ($this->response->isSuccessful()) {
$this->dispatch('request.success', $this->getEventArray());
}
}
} | php | protected function processResponse(array $context = array())
{
if (!$this->response) {
// If no response, then processResponse shouldn't have been called
$e = new RequestException('Error completing request');
$e->setRequest($this);
throw $e;
}
$this->state = self::STATE_COMPLETE;
// A request was sent, but we don't know if we'll send more or if the final response will be successful
$this->dispatch('request.sent', $this->getEventArray() + $context);
// Some response processors will remove the response or reset the state (example: ExponentialBackoffPlugin)
if ($this->state == RequestInterface::STATE_COMPLETE) {
// The request completed, so the HTTP transaction is complete
$this->dispatch('request.complete', $this->getEventArray());
// If the response is bad, allow listeners to modify it or throw exceptions. You can change the response by
// modifying the Event object in your listeners or calling setResponse() on the request
if ($this->response->isError()) {
$event = new Event($this->getEventArray());
$this->getEventDispatcher()->dispatch('request.error', $event);
// Allow events of request.error to quietly change the response
if ($event['response'] !== $this->response) {
$this->response = $event['response'];
}
}
// If a successful response was received, dispatch an event
if ($this->response->isSuccessful()) {
$this->dispatch('request.success', $this->getEventArray());
}
}
} | [
"protected",
"function",
"processResponse",
"(",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"response",
")",
"{",
"// If no response, then processResponse shouldn't have been called",
"$",
"e",
"=",
"new",
"Requ... | Process a received response
@param array $context Contextual information
@throws RequestException|BadResponseException on unsuccessful responses | [
"Process",
"a",
"received",
"response"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Request.php#L565-L601 | train |
guzzle/guzzle3 | src/Guzzle/Http/Exception/CurlException.php | CurlException.setError | public function setError($error, $number)
{
$this->curlError = $error;
$this->curlErrorNo = $number;
return $this;
} | php | public function setError($error, $number)
{
$this->curlError = $error;
$this->curlErrorNo = $number;
return $this;
} | [
"public",
"function",
"setError",
"(",
"$",
"error",
",",
"$",
"number",
")",
"{",
"$",
"this",
"->",
"curlError",
"=",
"$",
"error",
";",
"$",
"this",
"->",
"curlErrorNo",
"=",
"$",
"number",
";",
"return",
"$",
"this",
";",
"}"
] | Set the cURL error message
@param string $error Curl error
@param int $number Curl error number
@return self | [
"Set",
"the",
"cURL",
"error",
"message"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Exception/CurlException.php#L25-L31 | train |
guzzle/guzzle3 | src/Guzzle/Service/AbstractConfigLoader.php | AbstractConfigLoader.mergeIncludes | protected function mergeIncludes(&$config, $basePath = null)
{
if (!empty($config['includes'])) {
foreach ($config['includes'] as &$path) {
// Account for relative paths
if ($path[0] != DIRECTORY_SEPARATOR && !isset($this->aliases[$path]) && $basePath) {
$path = "{$basePath}/{$path}";
}
// Don't load the same files more than once
if (!isset($this->loadedFiles[$path])) {
$this->loadedFiles[$path] = true;
$config = $this->mergeData($this->loadFile($path), $config);
}
}
}
} | php | protected function mergeIncludes(&$config, $basePath = null)
{
if (!empty($config['includes'])) {
foreach ($config['includes'] as &$path) {
// Account for relative paths
if ($path[0] != DIRECTORY_SEPARATOR && !isset($this->aliases[$path]) && $basePath) {
$path = "{$basePath}/{$path}";
}
// Don't load the same files more than once
if (!isset($this->loadedFiles[$path])) {
$this->loadedFiles[$path] = true;
$config = $this->mergeData($this->loadFile($path), $config);
}
}
}
} | [
"protected",
"function",
"mergeIncludes",
"(",
"&",
"$",
"config",
",",
"$",
"basePath",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'includes'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"[",
"'includes'",
"]",... | Merges in all include files
@param array $config Config data that contains includes
@param string $basePath Base path to use when a relative path is encountered
@return array Returns the merged and included data | [
"Merges",
"in",
"all",
"include",
"files"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/AbstractConfigLoader.php#L148-L163 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php | ArrayCookieJar.serialize | public function serialize()
{
// Only serialize long term cookies and unexpired cookies
return json_encode(array_map(function (Cookie $cookie) {
return $cookie->toArray();
}, $this->all(null, null, null, true, true)));
} | php | public function serialize()
{
// Only serialize long term cookies and unexpired cookies
return json_encode(array_map(function (Cookie $cookie) {
return $cookie->toArray();
}, $this->all(null, null, null, true, true)));
} | [
"public",
"function",
"serialize",
"(",
")",
"{",
"// Only serialize long term cookies and unexpired cookies",
"return",
"json_encode",
"(",
"array_map",
"(",
"function",
"(",
"Cookie",
"$",
"cookie",
")",
"{",
"return",
"$",
"cookie",
"->",
"toArray",
"(",
")",
"... | Serializes the cookie cookieJar
@return string | [
"Serializes",
"the",
"cookie",
"cookieJar"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php#L145-L151 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php | ArrayCookieJar.unserialize | public function unserialize($data)
{
$data = json_decode($data, true);
if (empty($data)) {
$this->cookies = array();
} else {
$this->cookies = array_map(function (array $cookie) {
return new Cookie($cookie);
}, $data);
}
} | php | public function unserialize($data)
{
$data = json_decode($data, true);
if (empty($data)) {
$this->cookies = array();
} else {
$this->cookies = array_map(function (array $cookie) {
return new Cookie($cookie);
}, $data);
}
} | [
"public",
"function",
"unserialize",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"cookies",
"=",
"array",
"(",
")",
... | Unserializes the cookie cookieJar | [
"Unserializes",
"the",
"cookie",
"cookieJar"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php#L156-L166 | train |
guzzle/guzzle3 | src/Guzzle/Http/Client.php | Client.setDefaultOption | public function setDefaultOption($keyOrPath, $value)
{
$keyOrPath = self::REQUEST_OPTIONS . '/' . $keyOrPath;
$this->config->setPath($keyOrPath, $value);
return $this;
} | php | public function setDefaultOption($keyOrPath, $value)
{
$keyOrPath = self::REQUEST_OPTIONS . '/' . $keyOrPath;
$this->config->setPath($keyOrPath, $value);
return $this;
} | [
"public",
"function",
"setDefaultOption",
"(",
"$",
"keyOrPath",
",",
"$",
"value",
")",
"{",
"$",
"keyOrPath",
"=",
"self",
"::",
"REQUEST_OPTIONS",
".",
"'/'",
".",
"$",
"keyOrPath",
";",
"$",
"this",
"->",
"config",
"->",
"setPath",
"(",
"$",
"keyOrPa... | Set a default request option on the client that will be used as a default for each request
@param string $keyOrPath request.options key (e.g. allow_redirects) or path to a nested key (e.g. headers/foo)
@param mixed $value Value to set
@return $this | [
"Set",
"a",
"default",
"request",
"option",
"on",
"the",
"client",
"that",
"will",
"be",
"used",
"as",
"a",
"default",
"for",
"each",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Client.php#L112-L118 | train |
guzzle/guzzle3 | src/Guzzle/Http/Client.php | Client.getDefaultOption | public function getDefaultOption($keyOrPath)
{
$keyOrPath = self::REQUEST_OPTIONS . '/' . $keyOrPath;
return $this->config->getPath($keyOrPath);
} | php | public function getDefaultOption($keyOrPath)
{
$keyOrPath = self::REQUEST_OPTIONS . '/' . $keyOrPath;
return $this->config->getPath($keyOrPath);
} | [
"public",
"function",
"getDefaultOption",
"(",
"$",
"keyOrPath",
")",
"{",
"$",
"keyOrPath",
"=",
"self",
"::",
"REQUEST_OPTIONS",
".",
"'/'",
".",
"$",
"keyOrPath",
";",
"return",
"$",
"this",
"->",
"config",
"->",
"getPath",
"(",
"$",
"keyOrPath",
")",
... | Retrieve a default request option from the client
@param string $keyOrPath request.options key (e.g. allow_redirects) or path to a nested key (e.g. headers/foo)
@return mixed|null | [
"Retrieve",
"a",
"default",
"request",
"option",
"from",
"the",
"client"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Client.php#L127-L132 | train |
guzzle/guzzle3 | src/Guzzle/Http/Client.php | Client.expandTemplate | protected function expandTemplate($template, array $variables = null)
{
$expansionVars = $this->getConfig()->toArray();
if ($variables) {
$expansionVars = $variables + $expansionVars;
}
return $this->getUriTemplate()->expand($template, $expansionVars);
} | php | protected function expandTemplate($template, array $variables = null)
{
$expansionVars = $this->getConfig()->toArray();
if ($variables) {
$expansionVars = $variables + $expansionVars;
}
return $this->getUriTemplate()->expand($template, $expansionVars);
} | [
"protected",
"function",
"expandTemplate",
"(",
"$",
"template",
",",
"array",
"$",
"variables",
"=",
"null",
")",
"{",
"$",
"expansionVars",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"$",
"variables",
")... | Expand a URI template while merging client config settings into the template variables
@param string $template Template to expand
@param array $variables Variables to inject
@return string | [
"Expand",
"a",
"URI",
"template",
"while",
"merging",
"client",
"config",
"settings",
"into",
"the",
"template",
"variables"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Client.php#L349-L357 | train |
guzzle/guzzle3 | src/Guzzle/Http/Client.php | Client.getUriTemplate | protected function getUriTemplate()
{
if (!$this->uriTemplate) {
$this->uriTemplate = ParserRegistry::getInstance()->getParser('uri_template');
}
return $this->uriTemplate;
} | php | protected function getUriTemplate()
{
if (!$this->uriTemplate) {
$this->uriTemplate = ParserRegistry::getInstance()->getParser('uri_template');
}
return $this->uriTemplate;
} | [
"protected",
"function",
"getUriTemplate",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"uriTemplate",
")",
"{",
"$",
"this",
"->",
"uriTemplate",
"=",
"ParserRegistry",
"::",
"getInstance",
"(",
")",
"->",
"getParser",
"(",
"'uri_template'",
")",
";"... | Get the URI template expander used by the client
@return UriTemplateInterface | [
"Get",
"the",
"URI",
"template",
"expander",
"used",
"by",
"the",
"client"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Client.php#L364-L371 | train |
guzzle/guzzle3 | src/Guzzle/Http/Client.php | Client.sendMultiple | protected function sendMultiple(array $requests)
{
$curlMulti = $this->getCurlMulti();
foreach ($requests as $request) {
$curlMulti->add($request);
}
$curlMulti->send();
/** @var $request RequestInterface */
$result = array();
foreach ($requests as $request) {
$result[] = $request->getResponse();
}
return $result;
} | php | protected function sendMultiple(array $requests)
{
$curlMulti = $this->getCurlMulti();
foreach ($requests as $request) {
$curlMulti->add($request);
}
$curlMulti->send();
/** @var $request RequestInterface */
$result = array();
foreach ($requests as $request) {
$result[] = $request->getResponse();
}
return $result;
} | [
"protected",
"function",
"sendMultiple",
"(",
"array",
"$",
"requests",
")",
"{",
"$",
"curlMulti",
"=",
"$",
"this",
"->",
"getCurlMulti",
"(",
")",
";",
"foreach",
"(",
"$",
"requests",
"as",
"$",
"request",
")",
"{",
"$",
"curlMulti",
"->",
"add",
"... | Send multiple requests in parallel
@param array $requests Array of RequestInterface objects
@return array Returns an array of Response objects | [
"Send",
"multiple",
"requests",
"in",
"parallel"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Client.php#L380-L395 | train |
guzzle/guzzle3 | src/Guzzle/Http/Client.php | Client.prepareRequest | protected function prepareRequest(RequestInterface $request, array $options = array())
{
$request->setClient($this)->setEventDispatcher(clone $this->getEventDispatcher());
if ($curl = $this->config[self::CURL_OPTIONS]) {
$request->getCurlOptions()->overwriteWith(CurlHandle::parseCurlConfig($curl));
}
if ($params = $this->config[self::REQUEST_PARAMS]) {
Version::warn('request.params is deprecated. Use request.options to add default request options.');
$request->getParams()->overwriteWith($params);
}
if ($this->userAgent && !$request->hasHeader('User-Agent')) {
$request->setHeader('User-Agent', $this->userAgent);
}
if ($defaults = $this->config[self::REQUEST_OPTIONS]) {
$this->requestFactory->applyOptions($request, $defaults, RequestFactoryInterface::OPTIONS_AS_DEFAULTS);
}
if ($options) {
$this->requestFactory->applyOptions($request, $options);
}
$this->dispatch('client.create_request', array('client' => $this, 'request' => $request));
return $request;
} | php | protected function prepareRequest(RequestInterface $request, array $options = array())
{
$request->setClient($this)->setEventDispatcher(clone $this->getEventDispatcher());
if ($curl = $this->config[self::CURL_OPTIONS]) {
$request->getCurlOptions()->overwriteWith(CurlHandle::parseCurlConfig($curl));
}
if ($params = $this->config[self::REQUEST_PARAMS]) {
Version::warn('request.params is deprecated. Use request.options to add default request options.');
$request->getParams()->overwriteWith($params);
}
if ($this->userAgent && !$request->hasHeader('User-Agent')) {
$request->setHeader('User-Agent', $this->userAgent);
}
if ($defaults = $this->config[self::REQUEST_OPTIONS]) {
$this->requestFactory->applyOptions($request, $defaults, RequestFactoryInterface::OPTIONS_AS_DEFAULTS);
}
if ($options) {
$this->requestFactory->applyOptions($request, $options);
}
$this->dispatch('client.create_request', array('client' => $this, 'request' => $request));
return $request;
} | [
"protected",
"function",
"prepareRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"request",
"->",
"setClient",
"(",
"$",
"this",
")",
"->",
"setEventDispatcher",
"(",
"clone",
"$",
"th... | Prepare a request to be sent from the Client by adding client specific behaviors and properties to the request.
@param RequestInterface $request Request to prepare for the client
@param array $options Options to apply to the request
@return RequestInterface | [
"Prepare",
"a",
"request",
"to",
"be",
"sent",
"from",
"the",
"Client",
"by",
"adding",
"client",
"specific",
"behaviors",
"and",
"properties",
"to",
"the",
"request",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Client.php#L405-L433 | train |
guzzle/guzzle3 | src/Guzzle/Http/Client.php | Client.extractPharCacert | public static function extractPharCacert($pharCacertPath)
{
// Copy the cacert.pem file from the phar if it is not in the temp
// folder.
$certFile = sys_get_temp_dir() . '/guzzle-cacert.pem';
if (!file_exists($pharCacertPath)) {
throw new \RuntimeException("Could not find $pharCacertPath");
}
if (!file_exists($certFile) ||
filesize($certFile) != filesize($pharCacertPath)
) {
if (!copy($pharCacertPath, $certFile)) {
throw new \RuntimeException(
"Could not copy {$pharCacertPath} to {$certFile}: "
. var_export(error_get_last(), true)
);
}
}
return $certFile;
} | php | public static function extractPharCacert($pharCacertPath)
{
// Copy the cacert.pem file from the phar if it is not in the temp
// folder.
$certFile = sys_get_temp_dir() . '/guzzle-cacert.pem';
if (!file_exists($pharCacertPath)) {
throw new \RuntimeException("Could not find $pharCacertPath");
}
if (!file_exists($certFile) ||
filesize($certFile) != filesize($pharCacertPath)
) {
if (!copy($pharCacertPath, $certFile)) {
throw new \RuntimeException(
"Could not copy {$pharCacertPath} to {$certFile}: "
. var_export(error_get_last(), true)
);
}
}
return $certFile;
} | [
"public",
"static",
"function",
"extractPharCacert",
"(",
"$",
"pharCacertPath",
")",
"{",
"// Copy the cacert.pem file from the phar if it is not in the temp",
"// folder.",
"$",
"certFile",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/guzzle-cacert.pem'",
";",
"if",
"(",
... | Copies the phar cacert from a phar into the temp directory.
@param string $pharCacertPath Path to the phar cacert. For example:
'phar://aws.phar/Guzzle/Http/Resources/cacert.pem'
@return string Returns the path to the extracted cacert file.
@throws \RuntimeException Throws if the phar cacert cannot be found or
the file cannot be copied to the temp dir. | [
"Copies",
"the",
"phar",
"cacert",
"from",
"a",
"phar",
"into",
"the",
"temp",
"directory",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Client.php#L501-L523 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Backoff/BackoffPlugin.php | BackoffPlugin.getExponentialBackoff | public static function getExponentialBackoff(
$maxRetries = 3,
array $httpCodes = null,
array $curlCodes = null
) {
return new self(new TruncatedBackoffStrategy($maxRetries,
new HttpBackoffStrategy($httpCodes,
new CurlBackoffStrategy($curlCodes,
new ExponentialBackoffStrategy()
)
)
));
} | php | public static function getExponentialBackoff(
$maxRetries = 3,
array $httpCodes = null,
array $curlCodes = null
) {
return new self(new TruncatedBackoffStrategy($maxRetries,
new HttpBackoffStrategy($httpCodes,
new CurlBackoffStrategy($curlCodes,
new ExponentialBackoffStrategy()
)
)
));
} | [
"public",
"static",
"function",
"getExponentialBackoff",
"(",
"$",
"maxRetries",
"=",
"3",
",",
"array",
"$",
"httpCodes",
"=",
"null",
",",
"array",
"$",
"curlCodes",
"=",
"null",
")",
"{",
"return",
"new",
"self",
"(",
"new",
"TruncatedBackoffStrategy",
"(... | Retrieve a basic truncated exponential backoff plugin that will retry HTTP errors and cURL errors
@param int $maxRetries Maximum number of retries
@param array $httpCodes HTTP response codes to retry
@param array $curlCodes cURL error codes to retry
@return self | [
"Retrieve",
"a",
"basic",
"truncated",
"exponential",
"backoff",
"plugin",
"that",
"will",
"retry",
"HTTP",
"errors",
"and",
"cURL",
"errors"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Backoff/BackoffPlugin.php#L43-L55 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Backoff/BackoffPlugin.php | BackoffPlugin.onRequestPoll | public function onRequestPoll(Event $event)
{
$request = $event['request'];
$delay = $request->getParams()->get(self::DELAY_PARAM);
// If the duration of the delay has passed, retry the request using the pool
if (null !== $delay && microtime(true) >= $delay) {
// Remove the request from the pool and then add it back again. This is required for cURL to know that we
// want to retry sending the easy handle.
$request->getParams()->remove(self::DELAY_PARAM);
// Rewind the request body if possible
if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()) {
$request->getBody()->seek(0);
}
$multi = $event['curl_multi'];
$multi->remove($request);
$multi->add($request);
}
} | php | public function onRequestPoll(Event $event)
{
$request = $event['request'];
$delay = $request->getParams()->get(self::DELAY_PARAM);
// If the duration of the delay has passed, retry the request using the pool
if (null !== $delay && microtime(true) >= $delay) {
// Remove the request from the pool and then add it back again. This is required for cURL to know that we
// want to retry sending the easy handle.
$request->getParams()->remove(self::DELAY_PARAM);
// Rewind the request body if possible
if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()) {
$request->getBody()->seek(0);
}
$multi = $event['curl_multi'];
$multi->remove($request);
$multi->add($request);
}
} | [
"public",
"function",
"onRequestPoll",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]",
";",
"$",
"delay",
"=",
"$",
"request",
"->",
"getParams",
"(",
")",
"->",
"get",
"(",
"self",
"::",
"DELAY_PARAM",
... | Called when a request is polling in the curl multi object
@param Event $event | [
"Called",
"when",
"a",
"request",
"is",
"polling",
"in",
"the",
"curl",
"multi",
"object"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Backoff/BackoffPlugin.php#L107-L125 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/OperationResponseParser.php | OperationResponseParser.addVisitor | public function addVisitor($location, ResponseVisitorInterface $visitor)
{
$this->factory->addResponseVisitor($location, $visitor);
return $this;
} | php | public function addVisitor($location, ResponseVisitorInterface $visitor)
{
$this->factory->addResponseVisitor($location, $visitor);
return $this;
} | [
"public",
"function",
"addVisitor",
"(",
"$",
"location",
",",
"ResponseVisitorInterface",
"$",
"visitor",
")",
"{",
"$",
"this",
"->",
"factory",
"->",
"addResponseVisitor",
"(",
"$",
"location",
",",
"$",
"visitor",
")",
";",
"return",
"$",
"this",
";",
... | Add a location visitor to the command
@param string $location Location to associate with the visitor
@param ResponseVisitorInterface $visitor Visitor to attach
@return self | [
"Add",
"a",
"location",
"visitor",
"to",
"the",
"command"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/OperationResponseParser.php#L59-L64 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/OperationResponseParser.php | OperationResponseParser.parseClass | protected function parseClass(CommandInterface $command)
{
// Emit the operation.parse_class event. If a listener injects a 'result' property, then that will be the result
$event = new CreateResponseClassEvent(array('command' => $command));
$command->getClient()->getEventDispatcher()->dispatch('command.parse_response', $event);
if ($result = $event->getResult()) {
return $result;
}
$className = $command->getOperation()->getResponseClass();
if (!method_exists($className, 'fromCommand')) {
throw new ResponseClassException("{$className} must exist and implement a static fromCommand() method");
}
return $className::fromCommand($command);
} | php | protected function parseClass(CommandInterface $command)
{
// Emit the operation.parse_class event. If a listener injects a 'result' property, then that will be the result
$event = new CreateResponseClassEvent(array('command' => $command));
$command->getClient()->getEventDispatcher()->dispatch('command.parse_response', $event);
if ($result = $event->getResult()) {
return $result;
}
$className = $command->getOperation()->getResponseClass();
if (!method_exists($className, 'fromCommand')) {
throw new ResponseClassException("{$className} must exist and implement a static fromCommand() method");
}
return $className::fromCommand($command);
} | [
"protected",
"function",
"parseClass",
"(",
"CommandInterface",
"$",
"command",
")",
"{",
"// Emit the operation.parse_class event. If a listener injects a 'result' property, then that will be the result",
"$",
"event",
"=",
"new",
"CreateResponseClassEvent",
"(",
"array",
"(",
"... | Parse a class object
@param CommandInterface $command Command to parse into an object
@return mixed
@throws ResponseClassException | [
"Parse",
"a",
"class",
"object"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/OperationResponseParser.php#L98-L113 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/OperationResponseParser.php | OperationResponseParser.visitResult | protected function visitResult(Parameter $model, CommandInterface $command, Response $response)
{
$foundVisitors = $result = $knownProps = array();
$props = $model->getProperties();
foreach ($props as $schema) {
if ($location = $schema->getLocation()) {
// Trigger the before method on the first found visitor of this type
if (!isset($foundVisitors[$location])) {
$foundVisitors[$location] = $this->factory->getResponseVisitor($location);
$foundVisitors[$location]->before($command, $result);
}
}
}
// Visit additional properties when it is an actual schema
if (($additional = $model->getAdditionalProperties()) instanceof Parameter) {
$this->visitAdditionalProperties($model, $command, $response, $additional, $result, $foundVisitors);
}
// Apply the parameter value with the location visitor
foreach ($props as $schema) {
$knownProps[$schema->getName()] = 1;
if ($location = $schema->getLocation()) {
$foundVisitors[$location]->visit($command, $response, $schema, $result);
}
}
// Remove any unknown and potentially unsafe top-level properties
if ($additional === false) {
$result = array_intersect_key($result, $knownProps);
}
// Call the after() method of each found visitor
foreach ($foundVisitors as $visitor) {
$visitor->after($command);
}
return $result;
} | php | protected function visitResult(Parameter $model, CommandInterface $command, Response $response)
{
$foundVisitors = $result = $knownProps = array();
$props = $model->getProperties();
foreach ($props as $schema) {
if ($location = $schema->getLocation()) {
// Trigger the before method on the first found visitor of this type
if (!isset($foundVisitors[$location])) {
$foundVisitors[$location] = $this->factory->getResponseVisitor($location);
$foundVisitors[$location]->before($command, $result);
}
}
}
// Visit additional properties when it is an actual schema
if (($additional = $model->getAdditionalProperties()) instanceof Parameter) {
$this->visitAdditionalProperties($model, $command, $response, $additional, $result, $foundVisitors);
}
// Apply the parameter value with the location visitor
foreach ($props as $schema) {
$knownProps[$schema->getName()] = 1;
if ($location = $schema->getLocation()) {
$foundVisitors[$location]->visit($command, $response, $schema, $result);
}
}
// Remove any unknown and potentially unsafe top-level properties
if ($additional === false) {
$result = array_intersect_key($result, $knownProps);
}
// Call the after() method of each found visitor
foreach ($foundVisitors as $visitor) {
$visitor->after($command);
}
return $result;
} | [
"protected",
"function",
"visitResult",
"(",
"Parameter",
"$",
"model",
",",
"CommandInterface",
"$",
"command",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"foundVisitors",
"=",
"$",
"result",
"=",
"$",
"knownProps",
"=",
"array",
"(",
")",
";",
"$",... | Perform transformations on the result array
@param Parameter $model Model that defines the structure
@param CommandInterface $command Command that performed the operation
@param Response $response Response received
@return array Returns the array of result data | [
"Perform",
"transformations",
"on",
"the",
"result",
"array"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/OperationResponseParser.php#L124-L163 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php | XmlVisitor.processArray | protected function processArray(Parameter $param, &$value)
{
// Convert the node if it was meant to be an array
if (!isset($value[0])) {
// Collections fo nodes are sometimes wrapped in an additional array. For example:
// <Items><Item><a>1</a></Item><Item><a>2</a></Item></Items> should become:
// array('Items' => array(array('a' => 1), array('a' => 2))
// Some nodes are not wrapped. For example: <Foo><a>1</a></Foo><Foo><a>2</a></Foo>
// should become array('Foo' => array(array('a' => 1), array('a' => 2))
if ($param->getItems() && isset($value[$param->getItems()->getWireName()])) {
// Account for the case of a collection wrapping wrapped nodes: Items => Item[]
$value = $value[$param->getItems()->getWireName()];
// If the wrapped node only had one value, then make it an array of nodes
if (!isset($value[0]) || !is_array($value)) {
$value = array($value);
}
} elseif (!empty($value)) {
// Account for repeated nodes that must be an array: Foo => Baz, Foo => Baz, but only if the
// value is set and not empty
$value = array($value);
}
}
foreach ($value as &$item) {
$this->recursiveProcess($param->getItems(), $item);
}
} | php | protected function processArray(Parameter $param, &$value)
{
// Convert the node if it was meant to be an array
if (!isset($value[0])) {
// Collections fo nodes are sometimes wrapped in an additional array. For example:
// <Items><Item><a>1</a></Item><Item><a>2</a></Item></Items> should become:
// array('Items' => array(array('a' => 1), array('a' => 2))
// Some nodes are not wrapped. For example: <Foo><a>1</a></Foo><Foo><a>2</a></Foo>
// should become array('Foo' => array(array('a' => 1), array('a' => 2))
if ($param->getItems() && isset($value[$param->getItems()->getWireName()])) {
// Account for the case of a collection wrapping wrapped nodes: Items => Item[]
$value = $value[$param->getItems()->getWireName()];
// If the wrapped node only had one value, then make it an array of nodes
if (!isset($value[0]) || !is_array($value)) {
$value = array($value);
}
} elseif (!empty($value)) {
// Account for repeated nodes that must be an array: Foo => Baz, Foo => Baz, but only if the
// value is set and not empty
$value = array($value);
}
}
foreach ($value as &$item) {
$this->recursiveProcess($param->getItems(), $item);
}
} | [
"protected",
"function",
"processArray",
"(",
"Parameter",
"$",
"param",
",",
"&",
"$",
"value",
")",
"{",
"// Convert the node if it was meant to be an array",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"0",
"]",
")",
")",
"{",
"// Collections fo nodes ar... | Process an array
@param Parameter $param API parameter being parsed
@param mixed $value Value to process | [
"Process",
"an",
"array"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php#L73-L99 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php | XmlVisitor.processXmlAttribute | protected function processXmlAttribute(Parameter $property, array &$value)
{
$sentAs = $property->getWireName();
if (isset($value['@attributes'][$sentAs])) {
$value[$property->getName()] = $value['@attributes'][$sentAs];
unset($value['@attributes'][$sentAs]);
if (empty($value['@attributes'])) {
unset($value['@attributes']);
}
}
} | php | protected function processXmlAttribute(Parameter $property, array &$value)
{
$sentAs = $property->getWireName();
if (isset($value['@attributes'][$sentAs])) {
$value[$property->getName()] = $value['@attributes'][$sentAs];
unset($value['@attributes'][$sentAs]);
if (empty($value['@attributes'])) {
unset($value['@attributes']);
}
}
} | [
"protected",
"function",
"processXmlAttribute",
"(",
"Parameter",
"$",
"property",
",",
"array",
"&",
"$",
"value",
")",
"{",
"$",
"sentAs",
"=",
"$",
"property",
"->",
"getWireName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'@attribut... | Process an XML attribute property
@param Parameter $property Property to process
@param array $value Value to process and update | [
"Process",
"an",
"XML",
"attribute",
"property"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php#L140-L150 | train |
guzzle/guzzle3 | src/Guzzle/Parser/ParserRegistry.php | ParserRegistry.getParser | public function getParser($name)
{
if (!isset($this->instances[$name])) {
if (!isset($this->mapping[$name])) {
return null;
}
$class = $this->mapping[$name];
$this->instances[$name] = new $class();
}
return $this->instances[$name];
} | php | public function getParser($name)
{
if (!isset($this->instances[$name])) {
if (!isset($this->mapping[$name])) {
return null;
}
$class = $this->mapping[$name];
$this->instances[$name] = new $class();
}
return $this->instances[$name];
} | [
"public",
"function",
"getParser",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"instances",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"mapping",
"[",
"$",
"name",
"]"... | Get a parser by name from an instance
@param string $name Name of the parser to retrieve
@return mixed|null | [
"Get",
"a",
"parser",
"by",
"name",
"from",
"an",
"instance"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Parser/ParserRegistry.php#L52-L63 | train |
guzzle/guzzle3 | src/Guzzle/Common/Collection.php | Collection.fromConfig | public static function fromConfig(array $config = array(), array $defaults = array(), array $required = array())
{
$data = $config + $defaults;
if ($missing = array_diff($required, array_keys($data))) {
throw new InvalidArgumentException('Config is missing the following keys: ' . implode(', ', $missing));
}
return new self($data);
} | php | public static function fromConfig(array $config = array(), array $defaults = array(), array $required = array())
{
$data = $config + $defaults;
if ($missing = array_diff($required, array_keys($data))) {
throw new InvalidArgumentException('Config is missing the following keys: ' . implode(', ', $missing));
}
return new self($data);
} | [
"public",
"static",
"function",
"fromConfig",
"(",
"array",
"$",
"config",
"=",
"array",
"(",
")",
",",
"array",
"$",
"defaults",
"=",
"array",
"(",
")",
",",
"array",
"$",
"required",
"=",
"array",
"(",
")",
")",
"{",
"$",
"data",
"=",
"$",
"confi... | Create a new collection from an array, validate the keys, and add default values where missing
@param array $config Configuration values to apply.
@param array $defaults Default parameters
@param array $required Required parameter names
@return self
@throws InvalidArgumentException if a parameter is missing | [
"Create",
"a",
"new",
"collection",
"from",
"an",
"array",
"validate",
"the",
"keys",
"and",
"add",
"default",
"values",
"where",
"missing"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Common/Collection.php#L34-L43 | train |
guzzle/guzzle3 | src/Guzzle/Common/Collection.php | Collection.getAll | public function getAll(array $keys = null)
{
return $keys ? array_intersect_key($this->data, array_flip($keys)) : $this->data;
} | php | public function getAll(array $keys = null)
{
return $keys ? array_intersect_key($this->data, array_flip($keys)) : $this->data;
} | [
"public",
"function",
"getAll",
"(",
"array",
"$",
"keys",
"=",
"null",
")",
"{",
"return",
"$",
"keys",
"?",
"array_intersect_key",
"(",
"$",
"this",
"->",
"data",
",",
"array_flip",
"(",
"$",
"keys",
")",
")",
":",
"$",
"this",
"->",
"data",
";",
... | Get all or a subset of matching key value pairs
@param array $keys Pass an array of keys to retrieve only a subset of key value pairs
@return array Returns an array of all matching key value pairs | [
"Get",
"all",
"or",
"a",
"subset",
"of",
"matching",
"key",
"value",
"pairs"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Common/Collection.php#L79-L82 | train |
guzzle/guzzle3 | src/Guzzle/Common/Collection.php | Collection.keySearch | public function keySearch($key)
{
foreach (array_keys($this->data) as $k) {
if (!strcasecmp($k, $key)) {
return $k;
}
}
return false;
} | php | public function keySearch($key)
{
foreach (array_keys($this->data) as $k) {
if (!strcasecmp($k, $key)) {
return $k;
}
}
return false;
} | [
"public",
"function",
"keySearch",
"(",
"$",
"key",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"data",
")",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"!",
"strcasecmp",
"(",
"$",
"k",
",",
"$",
"key",
")",
")",
"{",
"return",
"$... | Case insensitive search the keys in the collection
@param string $key Key to search for
@return bool|string Returns false if not found, otherwise returns the key | [
"Case",
"insensitive",
"search",
"the",
"keys",
"in",
"the",
"collection"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Common/Collection.php#L176-L185 | train |
guzzle/guzzle3 | src/Guzzle/Common/Collection.php | Collection.overwriteWith | public function overwriteWith($data)
{
if (is_array($data)) {
$this->data = $data + $this->data;
} elseif ($data instanceof Collection) {
$this->data = $data->toArray() + $this->data;
} else {
foreach ($data as $key => $value) {
$this->data[$key] = $value;
}
}
return $this;
} | php | public function overwriteWith($data)
{
if (is_array($data)) {
$this->data = $data + $this->data;
} elseif ($data instanceof Collection) {
$this->data = $data->toArray() + $this->data;
} else {
foreach ($data as $key => $value) {
$this->data[$key] = $value;
}
}
return $this;
} | [
"public",
"function",
"overwriteWith",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
"+",
"$",
"this",
"->",
"data",
";",
"}",
"elseif",
"(",
"$",
"data",
"instanc... | Over write key value pairs in this collection with all of the data from an array or collection.
@param array|\Traversable $data Values to override over this config
@return self | [
"Over",
"write",
"key",
"value",
"pairs",
"in",
"this",
"collection",
"with",
"all",
"of",
"the",
"data",
"from",
"an",
"array",
"or",
"collection",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Common/Collection.php#L236-L249 | train |
guzzle/guzzle3 | src/Guzzle/Common/Collection.php | Collection.inject | public function inject($input)
{
Version::warn(__METHOD__ . ' is deprecated');
$replace = array();
foreach ($this->data as $key => $val) {
$replace['{' . $key . '}'] = $val;
}
return strtr($input, $replace);
} | php | public function inject($input)
{
Version::warn(__METHOD__ . ' is deprecated');
$replace = array();
foreach ($this->data as $key => $val) {
$replace['{' . $key . '}'] = $val;
}
return strtr($input, $replace);
} | [
"public",
"function",
"inject",
"(",
"$",
"input",
")",
"{",
"Version",
"::",
"warn",
"(",
"__METHOD__",
".",
"' is deprecated'",
")",
";",
"$",
"replace",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"key",
"=>"... | Inject configuration settings into an input string
@param string $input Input to inject
@return string
@deprecated | [
"Inject",
"configuration",
"settings",
"into",
"an",
"input",
"string"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Common/Collection.php#L393-L402 | train |
guzzle/guzzle3 | phing/tasks/GuzzleSubSplitTask.php | GuzzleSubSplitTask.subsplitUpdate | public function subsplitUpdate()
{
$repo = $this->getRepository();
$this->log('git-subsplit update...');
$cmd = $this->client->getCommand('subsplit');
$cmd->addArgument('update');
try {
$cmd->execute();
} catch (Exception $e) {
throw new BuildException('git subsplit update failed'. $e);
}
chdir($repo . '/.subsplit');
passthru('php ../composer.phar update --dev');
chdir($repo);
} | php | public function subsplitUpdate()
{
$repo = $this->getRepository();
$this->log('git-subsplit update...');
$cmd = $this->client->getCommand('subsplit');
$cmd->addArgument('update');
try {
$cmd->execute();
} catch (Exception $e) {
throw new BuildException('git subsplit update failed'. $e);
}
chdir($repo . '/.subsplit');
passthru('php ../composer.phar update --dev');
chdir($repo);
} | [
"public",
"function",
"subsplitUpdate",
"(",
")",
"{",
"$",
"repo",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'git-subsplit update...'",
")",
";",
"$",
"cmd",
"=",
"$",
"this",
"->",
"client",
"->",
"getCom... | Runs `git subsplit update` | [
"Runs",
"git",
"subsplit",
"update"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/phing/tasks/GuzzleSubSplitTask.php#L222-L236 | train |
guzzle/guzzle3 | phing/tasks/GuzzleSubSplitTask.php | GuzzleSubSplitTask.subsplitInit | public function subsplitInit()
{
$remote = $this->getRemote();
$cmd = $this->client->getCommand('subsplit');
$this->log('running git-subsplit init ' . $remote);
$cmd->setArguments(array(
'init',
$remote
));
try {
$output = $cmd->execute();
} catch (Exception $e) {
throw new BuildException('git subsplit init failed'. $e);
}
$this->log(trim($output), Project::MSG_INFO);
$repo = $this->getRepository();
chdir($repo . '/.subsplit');
passthru('php ../composer.phar install --dev');
chdir($repo);
} | php | public function subsplitInit()
{
$remote = $this->getRemote();
$cmd = $this->client->getCommand('subsplit');
$this->log('running git-subsplit init ' . $remote);
$cmd->setArguments(array(
'init',
$remote
));
try {
$output = $cmd->execute();
} catch (Exception $e) {
throw new BuildException('git subsplit init failed'. $e);
}
$this->log(trim($output), Project::MSG_INFO);
$repo = $this->getRepository();
chdir($repo . '/.subsplit');
passthru('php ../composer.phar install --dev');
chdir($repo);
} | [
"public",
"function",
"subsplitInit",
"(",
")",
"{",
"$",
"remote",
"=",
"$",
"this",
"->",
"getRemote",
"(",
")",
";",
"$",
"cmd",
"=",
"$",
"this",
"->",
"client",
"->",
"getCommand",
"(",
"'subsplit'",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'... | Runs `git subsplit init` based on the remote repository. | [
"Runs",
"git",
"subsplit",
"init",
"based",
"on",
"the",
"remote",
"repository",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/phing/tasks/GuzzleSubSplitTask.php#L241-L262 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cookie/CookiePlugin.php | CookiePlugin.onRequestBeforeSend | public function onRequestBeforeSend(Event $event)
{
$request = $event['request'];
if (!$request->getParams()->get('cookies.disable')) {
$request->removeHeader('Cookie');
// Find cookies that match this request
foreach ($this->cookieJar->getMatchingCookies($request) as $cookie) {
$request->addCookie($cookie->getName(), $cookie->getValue());
}
}
} | php | public function onRequestBeforeSend(Event $event)
{
$request = $event['request'];
if (!$request->getParams()->get('cookies.disable')) {
$request->removeHeader('Cookie');
// Find cookies that match this request
foreach ($this->cookieJar->getMatchingCookies($request) as $cookie) {
$request->addCookie($cookie->getName(), $cookie->getValue());
}
}
} | [
"public",
"function",
"onRequestBeforeSend",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]",
";",
"if",
"(",
"!",
"$",
"request",
"->",
"getParams",
"(",
")",
"->",
"get",
"(",
"'cookies.disable'",
")",
"... | Add cookies before a request is sent
@param Event $event | [
"Add",
"cookies",
"before",
"a",
"request",
"is",
"sent"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cookie/CookiePlugin.php#L49-L59 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cookie/Cookie.php | Cookie.getInvalidCharacters | protected static function getInvalidCharacters()
{
if (!self::$invalidCharString) {
self::$invalidCharString = implode('', array_map('chr', array_merge(
range(0, 32),
array(34, 40, 41, 44, 47),
array(58, 59, 60, 61, 62, 63, 64, 91, 92, 93, 123, 125, 127)
)));
}
return self::$invalidCharString;
} | php | protected static function getInvalidCharacters()
{
if (!self::$invalidCharString) {
self::$invalidCharString = implode('', array_map('chr', array_merge(
range(0, 32),
array(34, 40, 41, 44, 47),
array(58, 59, 60, 61, 62, 63, 64, 91, 92, 93, 123, 125, 127)
)));
}
return self::$invalidCharString;
} | [
"protected",
"static",
"function",
"getInvalidCharacters",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"invalidCharString",
")",
"{",
"self",
"::",
"$",
"invalidCharString",
"=",
"implode",
"(",
"''",
",",
"array_map",
"(",
"'chr'",
",",
"array_merge",... | Gets an array of invalid cookie characters
@return array | [
"Gets",
"an",
"array",
"of",
"invalid",
"cookie",
"characters"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cookie/Cookie.php#L29-L40 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cookie/Cookie.php | Cookie.getAttribute | public function getAttribute($name)
{
return array_key_exists($name, $this->data['data']) ? $this->data['data'][$name] : null;
} | php | public function getAttribute($name)
{
return array_key_exists($name, $this->data['data']) ? $this->data['data'][$name] : null;
} | [
"public",
"function",
"getAttribute",
"(",
"$",
"name",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"data",
"[",
"'data'",
"]",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"'data'",
"]",
"[",
"$",
"name",
"]",
":... | Get a specific data point from the extra cookie data
@param string $name Name of the data point to retrieve
@return null|string | [
"Get",
"a",
"specific",
"data",
"point",
"from",
"the",
"extra",
"cookie",
"data"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cookie/Cookie.php#L386-L389 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cookie/Cookie.php | Cookie.matchesPath | public function matchesPath($path)
{
// RFC6265 http://tools.ietf.org/search/rfc6265#section-5.1.4
// A request-path path-matches a given cookie-path if at least one of
// the following conditions holds:
// o The cookie-path and the request-path are identical.
if ($path == $this->getPath()) {
return true;
}
$pos = stripos($path, $this->getPath());
if ($pos === 0) {
// o The cookie-path is a prefix of the request-path, and the last
// character of the cookie-path is %x2F ("/").
if (substr($this->getPath(), -1, 1) === "/") {
return true;
}
// o The cookie-path is a prefix of the request-path, and the first
// character of the request-path that is not included in the cookie-
// path is a %x2F ("/") character.
if (substr($path, strlen($this->getPath()), 1) === "/") {
return true;
}
}
return false;
} | php | public function matchesPath($path)
{
// RFC6265 http://tools.ietf.org/search/rfc6265#section-5.1.4
// A request-path path-matches a given cookie-path if at least one of
// the following conditions holds:
// o The cookie-path and the request-path are identical.
if ($path == $this->getPath()) {
return true;
}
$pos = stripos($path, $this->getPath());
if ($pos === 0) {
// o The cookie-path is a prefix of the request-path, and the last
// character of the cookie-path is %x2F ("/").
if (substr($this->getPath(), -1, 1) === "/") {
return true;
}
// o The cookie-path is a prefix of the request-path, and the first
// character of the request-path that is not included in the cookie-
// path is a %x2F ("/") character.
if (substr($path, strlen($this->getPath()), 1) === "/") {
return true;
}
}
return false;
} | [
"public",
"function",
"matchesPath",
"(",
"$",
"path",
")",
"{",
"// RFC6265 http://tools.ietf.org/search/rfc6265#section-5.1.4",
"// A request-path path-matches a given cookie-path if at least one of",
"// the following conditions holds:",
"// o The cookie-path and the request-path are ident... | Check if the cookie matches a path value
@param string $path Path to check against
@return bool | [
"Check",
"if",
"the",
"cookie",
"matches",
"a",
"path",
"value"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cookie/Cookie.php#L413-L441 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/CacheControl.php | CacheControl.getDirective | public function getDirective($param)
{
$directives = $this->getDirectives();
return isset($directives[$param]) ? $directives[$param] : null;
} | php | public function getDirective($param)
{
$directives = $this->getDirectives();
return isset($directives[$param]) ? $directives[$param] : null;
} | [
"public",
"function",
"getDirective",
"(",
"$",
"param",
")",
"{",
"$",
"directives",
"=",
"$",
"this",
"->",
"getDirectives",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"directives",
"[",
"$",
"param",
"]",
")",
"?",
"$",
"directives",
"[",
"$",
"p... | Get a specific cache control directive
@param string $param Directive to retrieve
@return string|bool|null | [
"Get",
"a",
"specific",
"cache",
"control",
"directive"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/CacheControl.php#L48-L53 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/CacheControl.php | CacheControl.addDirective | public function addDirective($param, $value)
{
$directives = $this->getDirectives();
$directives[$param] = $value;
$this->updateFromDirectives($directives);
return $this;
} | php | public function addDirective($param, $value)
{
$directives = $this->getDirectives();
$directives[$param] = $value;
$this->updateFromDirectives($directives);
return $this;
} | [
"public",
"function",
"addDirective",
"(",
"$",
"param",
",",
"$",
"value",
")",
"{",
"$",
"directives",
"=",
"$",
"this",
"->",
"getDirectives",
"(",
")",
";",
"$",
"directives",
"[",
"$",
"param",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"... | Add a cache control directive
@param string $param Directive to add
@param string $value Value to set
@return self | [
"Add",
"a",
"cache",
"control",
"directive"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/CacheControl.php#L63-L70 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/CacheControl.php | CacheControl.removeDirective | public function removeDirective($param)
{
$directives = $this->getDirectives();
unset($directives[$param]);
$this->updateFromDirectives($directives);
return $this;
} | php | public function removeDirective($param)
{
$directives = $this->getDirectives();
unset($directives[$param]);
$this->updateFromDirectives($directives);
return $this;
} | [
"public",
"function",
"removeDirective",
"(",
"$",
"param",
")",
"{",
"$",
"directives",
"=",
"$",
"this",
"->",
"getDirectives",
"(",
")",
";",
"unset",
"(",
"$",
"directives",
"[",
"$",
"param",
"]",
")",
";",
"$",
"this",
"->",
"updateFromDirectives",... | Remove a cache control directive by name
@param string $param Directive to remove
@return self | [
"Remove",
"a",
"cache",
"control",
"directive",
"by",
"name"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/CacheControl.php#L79-L86 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/CacheControl.php | CacheControl.getDirectives | public function getDirectives()
{
if ($this->directives === null) {
$this->directives = array();
foreach ($this->parseParams() as $collection) {
foreach ($collection as $key => $value) {
$this->directives[$key] = $value === '' ? true : $value;
}
}
}
return $this->directives;
} | php | public function getDirectives()
{
if ($this->directives === null) {
$this->directives = array();
foreach ($this->parseParams() as $collection) {
foreach ($collection as $key => $value) {
$this->directives[$key] = $value === '' ? true : $value;
}
}
}
return $this->directives;
} | [
"public",
"function",
"getDirectives",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"directives",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"directives",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"parseParams",
"(",
")",
"as",... | Get an associative array of cache control directives
@return array | [
"Get",
"an",
"associative",
"array",
"of",
"cache",
"control",
"directives"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/CacheControl.php#L93-L105 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/CacheControl.php | CacheControl.updateFromDirectives | protected function updateFromDirectives(array $directives)
{
$this->directives = $directives;
$this->values = array();
foreach ($directives as $key => $value) {
$this->values[] = $value === true ? $key : "{$key}={$value}";
}
} | php | protected function updateFromDirectives(array $directives)
{
$this->directives = $directives;
$this->values = array();
foreach ($directives as $key => $value) {
$this->values[] = $value === true ? $key : "{$key}={$value}";
}
} | [
"protected",
"function",
"updateFromDirectives",
"(",
"array",
"$",
"directives",
")",
"{",
"$",
"this",
"->",
"directives",
"=",
"$",
"directives",
";",
"$",
"this",
"->",
"values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"directives",
"as",
"... | Updates the header value based on the parsed directives
@param array $directives Array of cache control directives | [
"Updates",
"the",
"header",
"value",
"based",
"on",
"the",
"parsed",
"directives"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/CacheControl.php#L112-L120 | train |
guzzle/guzzle3 | src/Guzzle/Stream/Stream.php | Stream.rebuildCache | protected function rebuildCache()
{
$this->cache = stream_get_meta_data($this->stream);
$this->cache[self::IS_LOCAL] = stream_is_local($this->stream);
$this->cache[self::IS_READABLE] = isset(self::$readWriteHash['read'][$this->cache['mode']]);
$this->cache[self::IS_WRITABLE] = isset(self::$readWriteHash['write'][$this->cache['mode']]);
} | php | protected function rebuildCache()
{
$this->cache = stream_get_meta_data($this->stream);
$this->cache[self::IS_LOCAL] = stream_is_local($this->stream);
$this->cache[self::IS_READABLE] = isset(self::$readWriteHash['read'][$this->cache['mode']]);
$this->cache[self::IS_WRITABLE] = isset(self::$readWriteHash['write'][$this->cache['mode']]);
} | [
"protected",
"function",
"rebuildCache",
"(",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"stream",
")",
";",
"$",
"this",
"->",
"cache",
"[",
"self",
"::",
"IS_LOCAL",
"]",
"=",
"stream_is_local",
"(",
"$",... | Reprocess stream metadata | [
"Reprocess",
"stream",
"metadata"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Stream/Stream.php#L282-L288 | train |
guzzle/guzzle3 | src/Guzzle/Service/Exception/CommandTransferException.php | CommandTransferException.fromMultiTransferException | public static function fromMultiTransferException(MultiTransferException $e)
{
$ce = new self($e->getMessage(), $e->getCode(), $e->getPrevious());
$ce->setSuccessfulRequests($e->getSuccessfulRequests());
$alreadyAddedExceptions = array();
foreach ($e->getFailedRequests() as $request) {
if ($re = $e->getExceptionForFailedRequest($request)) {
$alreadyAddedExceptions[] = $re;
$ce->addFailedRequestWithException($request, $re);
} else {
$ce->addFailedRequest($request);
}
}
// Add any exceptions that did not map to a request
if (count($alreadyAddedExceptions) < count($e)) {
foreach ($e as $ex) {
if (!in_array($ex, $alreadyAddedExceptions)) {
$ce->add($ex);
}
}
}
return $ce;
} | php | public static function fromMultiTransferException(MultiTransferException $e)
{
$ce = new self($e->getMessage(), $e->getCode(), $e->getPrevious());
$ce->setSuccessfulRequests($e->getSuccessfulRequests());
$alreadyAddedExceptions = array();
foreach ($e->getFailedRequests() as $request) {
if ($re = $e->getExceptionForFailedRequest($request)) {
$alreadyAddedExceptions[] = $re;
$ce->addFailedRequestWithException($request, $re);
} else {
$ce->addFailedRequest($request);
}
}
// Add any exceptions that did not map to a request
if (count($alreadyAddedExceptions) < count($e)) {
foreach ($e as $ex) {
if (!in_array($ex, $alreadyAddedExceptions)) {
$ce->add($ex);
}
}
}
return $ce;
} | [
"public",
"static",
"function",
"fromMultiTransferException",
"(",
"MultiTransferException",
"$",
"e",
")",
"{",
"$",
"ce",
"=",
"new",
"self",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
... | Creates a new CommandTransferException from a MultiTransferException
@param MultiTransferException $e Exception to base a new exception on
@return self | [
"Creates",
"a",
"new",
"CommandTransferException",
"from",
"a",
"MultiTransferException"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Exception/CommandTransferException.php#L23-L48 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/CurlAuth/CurlAuthPlugin.php | CurlAuthPlugin.onRequestCreate | public function onRequestCreate(Event $event)
{
$event['request']->setAuth($this->username, $this->password, $this->scheme);
} | php | public function onRequestCreate(Event $event)
{
$event['request']->setAuth($this->username, $this->password, $this->scheme);
} | [
"public",
"function",
"onRequestCreate",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"event",
"[",
"'request'",
"]",
"->",
"setAuth",
"(",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"this",
"->",
"scheme",
")",
";",
"... | Add basic auth
@param Event $event | [
"Add",
"basic",
"auth"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/CurlAuth/CurlAuthPlugin.php#L42-L45 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Request/HeaderVisitor.php | HeaderVisitor.addPrefixedHeaders | protected function addPrefixedHeaders(RequestInterface $request, Parameter $param, $value)
{
if (!is_array($value)) {
throw new InvalidArgumentException('An array of mapped headers expected, but received a single value');
}
$prefix = $param->getSentAs();
foreach ($value as $headerName => $headerValue) {
$request->setHeader($prefix . $headerName, $headerValue);
}
} | php | protected function addPrefixedHeaders(RequestInterface $request, Parameter $param, $value)
{
if (!is_array($value)) {
throw new InvalidArgumentException('An array of mapped headers expected, but received a single value');
}
$prefix = $param->getSentAs();
foreach ($value as $headerName => $headerValue) {
$request->setHeader($prefix . $headerName, $headerValue);
}
} | [
"protected",
"function",
"addPrefixedHeaders",
"(",
"RequestInterface",
"$",
"request",
",",
"Parameter",
"$",
"param",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"("... | Add a prefixed array of headers to the request
@param RequestInterface $request Request to update
@param Parameter $param Parameter object
@param array $value Header array to add
@throws InvalidArgumentException | [
"Add",
"a",
"prefixed",
"array",
"of",
"headers",
"to",
"the",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Request/HeaderVisitor.php#L34-L43 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php | FileCookieJar.persist | protected function persist()
{
if (false === file_put_contents($this->filename, $this->serialize())) {
// @codeCoverageIgnoreStart
throw new RuntimeException('Unable to open file ' . $this->filename);
// @codeCoverageIgnoreEnd
}
} | php | protected function persist()
{
if (false === file_put_contents($this->filename, $this->serialize())) {
// @codeCoverageIgnoreStart
throw new RuntimeException('Unable to open file ' . $this->filename);
// @codeCoverageIgnoreEnd
}
} | [
"protected",
"function",
"persist",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"file_put_contents",
"(",
"$",
"this",
"->",
"filename",
",",
"$",
"this",
"->",
"serialize",
"(",
")",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"new",
"RuntimeExcept... | Save the contents of the data array to the file
@throws RuntimeException if the file cannot be found or created | [
"Save",
"the",
"contents",
"of",
"the",
"data",
"array",
"to",
"the",
"file"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php#L41-L48 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php | FileCookieJar.load | protected function load()
{
$json = file_get_contents($this->filename);
if (false === $json) {
// @codeCoverageIgnoreStart
throw new RuntimeException('Unable to open file ' . $this->filename);
// @codeCoverageIgnoreEnd
}
$this->unserialize($json);
$this->cookies = $this->cookies ?: array();
} | php | protected function load()
{
$json = file_get_contents($this->filename);
if (false === $json) {
// @codeCoverageIgnoreStart
throw new RuntimeException('Unable to open file ' . $this->filename);
// @codeCoverageIgnoreEnd
}
$this->unserialize($json);
$this->cookies = $this->cookies ?: array();
} | [
"protected",
"function",
"load",
"(",
")",
"{",
"$",
"json",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"filename",
")",
";",
"if",
"(",
"false",
"===",
"$",
"json",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"new",
"RuntimeException",
"(",
"... | Load the contents of the json formatted file into the data array and discard any unsaved state | [
"Load",
"the",
"contents",
"of",
"the",
"json",
"formatted",
"file",
"into",
"the",
"data",
"array",
"and",
"discard",
"any",
"unsaved",
"state"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php#L53-L64 | train |
guzzle/guzzle3 | phing/tasks/ComposerLintTask.php | ComposerLintTask.findComposer | protected function findComposer()
{
$basedir = $this->project->getBasedir();
$php = $this->project->getProperty('php.interpreter');
if (file_exists($basedir . '/composer.phar')) {
$this->composer = "$php $basedir/composer.phar";
} else {
$out = array();
exec('which composer', $out);
if (empty($out)) {
throw new BuildException(
'Could not determine composer location.'
);
}
$this->composer = $out[0];
}
} | php | protected function findComposer()
{
$basedir = $this->project->getBasedir();
$php = $this->project->getProperty('php.interpreter');
if (file_exists($basedir . '/composer.phar')) {
$this->composer = "$php $basedir/composer.phar";
} else {
$out = array();
exec('which composer', $out);
if (empty($out)) {
throw new BuildException(
'Could not determine composer location.'
);
}
$this->composer = $out[0];
}
} | [
"protected",
"function",
"findComposer",
"(",
")",
"{",
"$",
"basedir",
"=",
"$",
"this",
"->",
"project",
"->",
"getBasedir",
"(",
")",
";",
"$",
"php",
"=",
"$",
"this",
"->",
"project",
"->",
"getProperty",
"(",
"'php.interpreter'",
")",
";",
"if",
... | Find composer installation | [
"Find",
"composer",
"installation"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/phing/tasks/ComposerLintTask.php#L134-L151 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.