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 |
---|---|---|---|---|---|---|---|---|---|---|---|
blockcypher/php-client | lib/BlockCypher/Client/AddressClient.php | AddressClient.getMultipleFullAddresses | public function getMultipleFullAddresses($array, $params = array(), $apiContext = null, $restCall = null)
{
ArgumentArrayValidator::validate($array, 'array');
ArgumentGetParamsValidator::validate($params, 'params');
$allowedParams = array(
'unspentOnly' => 1, // TODO: not present in docs ?
'before' => 1,
'after' => 1,
'limit' => 1,
'txlimit' => 1,
'confirmations' => 1,
'confidence' => 1,
'includeHex' => 1,
'includeConfidence' => 1,
'omitWalletAddresses' => 1,
);
$params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
$addressList = implode(";", $array);
$payLoad = "";
$chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
$json = $this->executeCall(
"$chainUrlPrefix/addrs/$addressList/full?" . http_build_query($params),
"GET",
$payLoad,
null,
$apiContext,
$restCall
);
return FullAddress::getList($json);
} | php | public function getMultipleFullAddresses($array, $params = array(), $apiContext = null, $restCall = null)
{
ArgumentArrayValidator::validate($array, 'array');
ArgumentGetParamsValidator::validate($params, 'params');
$allowedParams = array(
'unspentOnly' => 1, // TODO: not present in docs ?
'before' => 1,
'after' => 1,
'limit' => 1,
'txlimit' => 1,
'confirmations' => 1,
'confidence' => 1,
'includeHex' => 1,
'includeConfidence' => 1,
'omitWalletAddresses' => 1,
);
$params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
$addressList = implode(";", $array);
$payLoad = "";
$chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
$json = $this->executeCall(
"$chainUrlPrefix/addrs/$addressList/full?" . http_build_query($params),
"GET",
$payLoad,
null,
$apiContext,
$restCall
);
return FullAddress::getList($json);
} | [
"public",
"function",
"getMultipleFullAddresses",
"(",
"$",
"array",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"apiContext",
"=",
"null",
",",
"$",
"restCall",
"=",
"null",
")",
"{",
"ArgumentArrayValidator",
"::",
"validate",
"(",
"$",
"array",
",",
"'array'",
")",
";",
"ArgumentGetParamsValidator",
"::",
"validate",
"(",
"$",
"params",
",",
"'params'",
")",
";",
"$",
"allowedParams",
"=",
"array",
"(",
"'unspentOnly'",
"=>",
"1",
",",
"// TODO: not present in docs ?",
"'before'",
"=>",
"1",
",",
"'after'",
"=>",
"1",
",",
"'limit'",
"=>",
"1",
",",
"'txlimit'",
"=>",
"1",
",",
"'confirmations'",
"=>",
"1",
",",
"'confidence'",
"=>",
"1",
",",
"'includeHex'",
"=>",
"1",
",",
"'includeConfidence'",
"=>",
"1",
",",
"'omitWalletAddresses'",
"=>",
"1",
",",
")",
";",
"$",
"params",
"=",
"ArgumentGetParamsValidator",
"::",
"sanitize",
"(",
"$",
"params",
",",
"$",
"allowedParams",
")",
";",
"$",
"addressList",
"=",
"implode",
"(",
"\";\"",
",",
"$",
"array",
")",
";",
"$",
"payLoad",
"=",
"\"\"",
";",
"$",
"chainUrlPrefix",
"=",
"$",
"this",
"->",
"getChainUrlPrefix",
"(",
"$",
"apiContext",
")",
";",
"$",
"json",
"=",
"$",
"this",
"->",
"executeCall",
"(",
"\"$chainUrlPrefix/addrs/$addressList/full?\"",
".",
"http_build_query",
"(",
"$",
"params",
")",
",",
"\"GET\"",
",",
"$",
"payLoad",
",",
"null",
",",
"$",
"apiContext",
",",
"$",
"restCall",
")",
";",
"return",
"FullAddress",
"::",
"getList",
"(",
"$",
"json",
")",
";",
"}"
]
| Obtain multiple FullAddress resources for the given identifiers.
@param string[] $array
@param array $params Parameters. Options: unspentOnly, and before
@param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
@return FullAddress[] | [
"Obtain",
"multiple",
"FullAddress",
"resources",
"for",
"the",
"given",
"identifiers",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Client/AddressClient.php#L235-L267 | train |
blockcypher/php-client | lib/BlockCypher/Client/AddressClient.php | AddressClient.getMultipleBalances | public function getMultipleBalances($array, $params = array(), $apiContext = null, $restCall = null)
{
ArgumentArrayValidator::validate($array, 'array');
ArgumentGetParamsValidator::validate($params, 'params');
$allowedParams = array(
'omitWalletAddresses' => 1,
);
$params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
$payLoad = "";
$addressList = implode(";", $array);
$chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
$json = $this->executeCall(
"$chainUrlPrefix/addrs/$addressList/balance" . http_build_query(array_intersect_key($params, $allowedParams)),
"GET",
$payLoad,
null,
$apiContext,
$restCall
);
return AddressBalance::getList($json);
} | php | public function getMultipleBalances($array, $params = array(), $apiContext = null, $restCall = null)
{
ArgumentArrayValidator::validate($array, 'array');
ArgumentGetParamsValidator::validate($params, 'params');
$allowedParams = array(
'omitWalletAddresses' => 1,
);
$params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
$payLoad = "";
$addressList = implode(";", $array);
$chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
$json = $this->executeCall(
"$chainUrlPrefix/addrs/$addressList/balance" . http_build_query(array_intersect_key($params, $allowedParams)),
"GET",
$payLoad,
null,
$apiContext,
$restCall
);
return AddressBalance::getList($json);
} | [
"public",
"function",
"getMultipleBalances",
"(",
"$",
"array",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"apiContext",
"=",
"null",
",",
"$",
"restCall",
"=",
"null",
")",
"{",
"ArgumentArrayValidator",
"::",
"validate",
"(",
"$",
"array",
",",
"'array'",
")",
";",
"ArgumentGetParamsValidator",
"::",
"validate",
"(",
"$",
"params",
",",
"'params'",
")",
";",
"$",
"allowedParams",
"=",
"array",
"(",
"'omitWalletAddresses'",
"=>",
"1",
",",
")",
";",
"$",
"params",
"=",
"ArgumentGetParamsValidator",
"::",
"sanitize",
"(",
"$",
"params",
",",
"$",
"allowedParams",
")",
";",
"$",
"payLoad",
"=",
"\"\"",
";",
"$",
"addressList",
"=",
"implode",
"(",
"\";\"",
",",
"$",
"array",
")",
";",
"$",
"chainUrlPrefix",
"=",
"$",
"this",
"->",
"getChainUrlPrefix",
"(",
"$",
"apiContext",
")",
";",
"$",
"json",
"=",
"$",
"this",
"->",
"executeCall",
"(",
"\"$chainUrlPrefix/addrs/$addressList/balance\"",
".",
"http_build_query",
"(",
"array_intersect_key",
"(",
"$",
"params",
",",
"$",
"allowedParams",
")",
")",
",",
"\"GET\"",
",",
"$",
"payLoad",
",",
"null",
",",
"$",
"apiContext",
",",
"$",
"restCall",
")",
";",
"return",
"AddressBalance",
"::",
"getList",
"(",
"$",
"json",
")",
";",
"}"
]
| Obtain multiple AddressBalances resources for the given identifiers.
@param string[] $array
@param array $params Parameters
@param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
@return AddressBalance[] | [
"Obtain",
"multiple",
"AddressBalances",
"resources",
"for",
"the",
"given",
"identifiers",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Client/AddressClient.php#L313-L337 | train |
blockcypher/php-client | lib/BlockCypher/Converter/BtcConverter.php | BtcConverter.satoshisToBtc | public static function satoshisToBtc($satoshis)
{
if (!is_numeric($satoshis))
throw new \InvalidArgumentException("$satoshis must be numeric");
return (float)($satoshis) / (float)(self::SATOSHIS_PER_BTC);
} | php | public static function satoshisToBtc($satoshis)
{
if (!is_numeric($satoshis))
throw new \InvalidArgumentException("$satoshis must be numeric");
return (float)($satoshis) / (float)(self::SATOSHIS_PER_BTC);
} | [
"public",
"static",
"function",
"satoshisToBtc",
"(",
"$",
"satoshis",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"satoshis",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"$satoshis must be numeric\"",
")",
";",
"return",
"(",
"float",
")",
"(",
"$",
"satoshis",
")",
"/",
"(",
"float",
")",
"(",
"self",
"::",
"SATOSHIS_PER_BTC",
")",
";",
"}"
]
| Convert satoshis to BTC
@param int|float $satoshis
@return float | [
"Convert",
"satoshis",
"to",
"BTC"
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Converter/BtcConverter.php#L54-L60 | train |
blockcypher/php-client | lib/BlockCypher/Handler/TokenRestHandler.php | TokenRestHandler.urlContainsToken | private function urlContainsToken($url)
{
// TODO: add test for this method.
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $params);
if (isset($params["token"])) {
return true;
} else {
return false;
}
} | php | private function urlContainsToken($url)
{
// TODO: add test for this method.
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $params);
if (isset($params["token"])) {
return true;
} else {
return false;
}
} | [
"private",
"function",
"urlContainsToken",
"(",
"$",
"url",
")",
"{",
"// TODO: add test for this method.",
"$",
"query",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_QUERY",
")",
";",
"parse_str",
"(",
"$",
"query",
",",
"$",
"params",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"\"token\"",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Return true if the given url contains a parameter called 'token'.
@param $url
@return bool | [
"Return",
"true",
"if",
"the",
"given",
"url",
"contains",
"a",
"parameter",
"called",
"token",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Handler/TokenRestHandler.php#L130-L141 | train |
blockcypher/php-client | lib/BlockCypher/Api/Address.php | Address.create | public static function create($addressKeyChain = null, $apiContext = null, $restCall = null)
{
if ($addressKeyChain === null) {
$payLoad = "";
} else {
// multisig address
$payLoad = $addressKeyChain->toJSON();
}
$chainUrlPrefix = self::getChainUrlPrefix($apiContext);
$json = self::executeCall(
"$chainUrlPrefix/addrs",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new AddressKeyChain();
$ret->fromJson($json);
return $ret;
} | php | public static function create($addressKeyChain = null, $apiContext = null, $restCall = null)
{
if ($addressKeyChain === null) {
$payLoad = "";
} else {
// multisig address
$payLoad = $addressKeyChain->toJSON();
}
$chainUrlPrefix = self::getChainUrlPrefix($apiContext);
$json = self::executeCall(
"$chainUrlPrefix/addrs",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new AddressKeyChain();
$ret->fromJson($json);
return $ret;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"addressKeyChain",
"=",
"null",
",",
"$",
"apiContext",
"=",
"null",
",",
"$",
"restCall",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"addressKeyChain",
"===",
"null",
")",
"{",
"$",
"payLoad",
"=",
"\"\"",
";",
"}",
"else",
"{",
"// multisig address",
"$",
"payLoad",
"=",
"$",
"addressKeyChain",
"->",
"toJSON",
"(",
")",
";",
"}",
"$",
"chainUrlPrefix",
"=",
"self",
"::",
"getChainUrlPrefix",
"(",
"$",
"apiContext",
")",
";",
"$",
"json",
"=",
"self",
"::",
"executeCall",
"(",
"\"$chainUrlPrefix/addrs\"",
",",
"\"POST\"",
",",
"$",
"payLoad",
",",
"null",
",",
"$",
"apiContext",
",",
"$",
"restCall",
")",
";",
"$",
"ret",
"=",
"new",
"AddressKeyChain",
"(",
")",
";",
"$",
"ret",
"->",
"fromJson",
"(",
"$",
"json",
")",
";",
"return",
"$",
"ret",
";",
"}"
]
| Create a new address.
@deprecated since version 1.2. Use AddressClient.
@param AddressKeyChain $addressKeyChain
@param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
@return AddressKeyChain | [
"Create",
"a",
"new",
"address",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Api/Address.php#L48-L70 | train |
blockcypher/php-client | lib/BlockCypher/Api/Address.php | Address.addTxref | public function addTxref($txref)
{
if (!$this->getTxrefs()) {
return $this->setTxrefs(array($txref));
} else {
return $this->setTxrefs(
array_merge($this->getTxrefs(), array($txref))
);
}
} | php | public function addTxref($txref)
{
if (!$this->getTxrefs()) {
return $this->setTxrefs(array($txref));
} else {
return $this->setTxrefs(
array_merge($this->getTxrefs(), array($txref))
);
}
} | [
"public",
"function",
"addTxref",
"(",
"$",
"txref",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getTxrefs",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setTxrefs",
"(",
"array",
"(",
"$",
"txref",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"setTxrefs",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"getTxrefs",
"(",
")",
",",
"array",
"(",
"$",
"txref",
")",
")",
")",
";",
"}",
"}"
]
| Append TXRef to the list.
@param \BlockCypher\Api\TXRef $txref
@return $this | [
"Append",
"TXRef",
"to",
"the",
"list",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Api/Address.php#L452-L461 | train |
blockcypher/php-client | lib/BlockCypher/Api/Address.php | Address.addUnconfirmedTxref | public function addUnconfirmedTxref($unconfirmedTxref)
{
if (!$this->getUnconfirmedTxrefs()) {
return $this->setUnconfirmedTxrefs(array($unconfirmedTxref));
} else {
return $this->setUnconfirmedTxrefs(
array_merge($this->getUnconfirmedTxrefs(), array($unconfirmedTxref))
);
}
} | php | public function addUnconfirmedTxref($unconfirmedTxref)
{
if (!$this->getUnconfirmedTxrefs()) {
return $this->setUnconfirmedTxrefs(array($unconfirmedTxref));
} else {
return $this->setUnconfirmedTxrefs(
array_merge($this->getUnconfirmedTxrefs(), array($unconfirmedTxref))
);
}
} | [
"public",
"function",
"addUnconfirmedTxref",
"(",
"$",
"unconfirmedTxref",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getUnconfirmedTxrefs",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setUnconfirmedTxrefs",
"(",
"array",
"(",
"$",
"unconfirmedTxref",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"setUnconfirmedTxrefs",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"getUnconfirmedTxrefs",
"(",
")",
",",
"array",
"(",
"$",
"unconfirmedTxref",
")",
")",
")",
";",
"}",
"}"
]
| Append Unconfirmed TXRef to the list.
@param \BlockCypher\Api\TXRef $unconfirmedTxref
@return $this | [
"Append",
"Unconfirmed",
"TXRef",
"to",
"the",
"list",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Api/Address.php#L505-L514 | train |
blockcypher/php-client | lib/BlockCypher/Api/Address.php | Address.getAllTxrefs | public function getAllTxrefs()
{
$allTxrefs = array();
if (is_array($this->txrefs)) {
$allTxrefs = array_merge($allTxrefs, $this->txrefs);
}
if (is_array($this->unconfirmed_txrefs)) {
$allTxrefs = array_merge($allTxrefs, $this->unconfirmed_txrefs);
}
if (count($allTxrefs) == 0)
return null;
else
return $allTxrefs;
} | php | public function getAllTxrefs()
{
$allTxrefs = array();
if (is_array($this->txrefs)) {
$allTxrefs = array_merge($allTxrefs, $this->txrefs);
}
if (is_array($this->unconfirmed_txrefs)) {
$allTxrefs = array_merge($allTxrefs, $this->unconfirmed_txrefs);
}
if (count($allTxrefs) == 0)
return null;
else
return $allTxrefs;
} | [
"public",
"function",
"getAllTxrefs",
"(",
")",
"{",
"$",
"allTxrefs",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"txrefs",
")",
")",
"{",
"$",
"allTxrefs",
"=",
"array_merge",
"(",
"$",
"allTxrefs",
",",
"$",
"this",
"->",
"txrefs",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"unconfirmed_txrefs",
")",
")",
"{",
"$",
"allTxrefs",
"=",
"array_merge",
"(",
"$",
"allTxrefs",
",",
"$",
"this",
"->",
"unconfirmed_txrefs",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"allTxrefs",
")",
"==",
"0",
")",
"return",
"null",
";",
"else",
"return",
"$",
"allTxrefs",
";",
"}"
]
| All transactions refs for confirmed and unconfirmed transactions.
@return \BlockCypher\Api\TXRef[] | [
"All",
"transactions",
"refs",
"for",
"confirmed",
"and",
"unconfirmed",
"transactions",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Api/Address.php#L556-L570 | train |
blockcypher/php-client | lib/BlockCypher/Crypto/PrivateKeyList.php | PrivateKeyList.addPrivateKey | public function addPrivateKey(PrivateKeyInterface $privateKey)
{
$pubKeyHex = $privateKey->getPublicKey()->getHex();
$this->privateKeys[$pubKeyHex] = $privateKey;
} | php | public function addPrivateKey(PrivateKeyInterface $privateKey)
{
$pubKeyHex = $privateKey->getPublicKey()->getHex();
$this->privateKeys[$pubKeyHex] = $privateKey;
} | [
"public",
"function",
"addPrivateKey",
"(",
"PrivateKeyInterface",
"$",
"privateKey",
")",
"{",
"$",
"pubKeyHex",
"=",
"$",
"privateKey",
"->",
"getPublicKey",
"(",
")",
"->",
"getHex",
"(",
")",
";",
"$",
"this",
"->",
"privateKeys",
"[",
"$",
"pubKeyHex",
"]",
"=",
"$",
"privateKey",
";",
"}"
]
| Append private key to the list.
@param PrivateKeyInterface $privateKey
@return $this | [
"Append",
"private",
"key",
"to",
"the",
"list",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Crypto/PrivateKeyList.php#L54-L58 | train |
blockcypher/php-client | lib/BlockCypher/Api/HDWallet.php | HDWallet.addSubchainIndex | public function addSubchainIndex($subchainIndex)
{
if (!$this->getSubchainIndexes()) {
return $this->setSubchainIndexes(array($subchainIndex));
} else {
return $this->setSubchainIndexes(
array_merge($this->getSubchainIndexes(), array($subchainIndex))
);
}
} | php | public function addSubchainIndex($subchainIndex)
{
if (!$this->getSubchainIndexes()) {
return $this->setSubchainIndexes(array($subchainIndex));
} else {
return $this->setSubchainIndexes(
array_merge($this->getSubchainIndexes(), array($subchainIndex))
);
}
} | [
"public",
"function",
"addSubchainIndex",
"(",
"$",
"subchainIndex",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getSubchainIndexes",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setSubchainIndexes",
"(",
"array",
"(",
"$",
"subchainIndex",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"setSubchainIndexes",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"getSubchainIndexes",
"(",
")",
",",
"array",
"(",
"$",
"subchainIndex",
")",
")",
")",
";",
"}",
"}"
]
| Append subchain index to the list.
@param int $subchainIndex
@return $this | [
"Append",
"subchain",
"index",
"to",
"the",
"list",
"."
]
| c1f875cdbad4e0e19fa697749309e5d7c28b7b4a | https://github.com/blockcypher/php-client/blob/c1f875cdbad4e0e19fa697749309e5d7c28b7b4a/lib/BlockCypher/Api/HDWallet.php#L296-L305 | train |
silverstripe/silverstripe-versioned-admin | src/Controllers/HistoryControllerFactory.php | HistoryControllerFactory.isEnabled | public function isEnabled(SiteTree $record)
{
$enabledResults = $this->extend('updateIsEnabled', $record);
return (empty($enabledResults) || min($enabledResults) !== false);
} | php | public function isEnabled(SiteTree $record)
{
$enabledResults = $this->extend('updateIsEnabled', $record);
return (empty($enabledResults) || min($enabledResults) !== false);
} | [
"public",
"function",
"isEnabled",
"(",
"SiteTree",
"$",
"record",
")",
"{",
"$",
"enabledResults",
"=",
"$",
"this",
"->",
"extend",
"(",
"'updateIsEnabled'",
",",
"$",
"record",
")",
";",
"return",
"(",
"empty",
"(",
"$",
"enabledResults",
")",
"||",
"min",
"(",
"$",
"enabledResults",
")",
"!==",
"false",
")",
";",
"}"
]
| Only deactivate for pages that have a history viewer capability removed. Extensions can provide their
own two cents about this criteria.
@param SiteTree $record
@return bool | [
"Only",
"deactivate",
"for",
"pages",
"that",
"have",
"a",
"history",
"viewer",
"capability",
"removed",
".",
"Extensions",
"can",
"provide",
"their",
"own",
"two",
"cents",
"about",
"this",
"criteria",
"."
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Controllers/HistoryControllerFactory.php#L56-L60 | train |
silverstripe/silverstripe-versioned-admin | src/Controllers/HistoryViewerController.php | HistoryViewerController.schema | public function schema($request)
{
$formName = $request->param('FormName');
if (!in_array($formName, $this->formNames)) {
return parent::schema($request);
}
return $this->generateSchemaForForm($formName, $request);
} | php | public function schema($request)
{
$formName = $request->param('FormName');
if (!in_array($formName, $this->formNames)) {
return parent::schema($request);
}
return $this->generateSchemaForForm($formName, $request);
} | [
"public",
"function",
"schema",
"(",
"$",
"request",
")",
"{",
"$",
"formName",
"=",
"$",
"request",
"->",
"param",
"(",
"'FormName'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"formName",
",",
"$",
"this",
"->",
"formNames",
")",
")",
"{",
"return",
"parent",
"::",
"schema",
"(",
"$",
"request",
")",
";",
"}",
"return",
"$",
"this",
"->",
"generateSchemaForForm",
"(",
"$",
"formName",
",",
"$",
"request",
")",
";",
"}"
]
| Gets a JSON schema representing the current version detail form.
WARNING: Experimental API.
@internal
@param HTTPRequest $request
@return HTTPResponse | [
"Gets",
"a",
"JSON",
"schema",
"representing",
"the",
"current",
"version",
"detail",
"form",
"."
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Controllers/HistoryViewerController.php#L76-L84 | train |
silverstripe/silverstripe-versioned-admin | src/Controllers/HistoryViewerController.php | HistoryViewerController.getRecordVersion | protected function getRecordVersion($recordClass, $recordId, $recordVersion)
{
$record = Versioned::get_version($recordClass, $recordId, $recordVersion);
if (!$record) {
$this->jsonError(404);
return null;
}
if (!$record->canView()) {
$this->jsonError(403, _t(
__CLASS__.'.ErrorItemViewPermissionDenied',
"You don't have the necessary permissions to view {ObjectTitle}",
['ObjectTitle' => $record->i18n_singular_name()]
));
return null;
}
return $record;
} | php | protected function getRecordVersion($recordClass, $recordId, $recordVersion)
{
$record = Versioned::get_version($recordClass, $recordId, $recordVersion);
if (!$record) {
$this->jsonError(404);
return null;
}
if (!$record->canView()) {
$this->jsonError(403, _t(
__CLASS__.'.ErrorItemViewPermissionDenied',
"You don't have the necessary permissions to view {ObjectTitle}",
['ObjectTitle' => $record->i18n_singular_name()]
));
return null;
}
return $record;
} | [
"protected",
"function",
"getRecordVersion",
"(",
"$",
"recordClass",
",",
"$",
"recordId",
",",
"$",
"recordVersion",
")",
"{",
"$",
"record",
"=",
"Versioned",
"::",
"get_version",
"(",
"$",
"recordClass",
",",
"$",
"recordId",
",",
"$",
"recordVersion",
")",
";",
"if",
"(",
"!",
"$",
"record",
")",
"{",
"$",
"this",
"->",
"jsonError",
"(",
"404",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"record",
"->",
"canView",
"(",
")",
")",
"{",
"$",
"this",
"->",
"jsonError",
"(",
"403",
",",
"_t",
"(",
"__CLASS__",
".",
"'.ErrorItemViewPermissionDenied'",
",",
"\"You don't have the necessary permissions to view {ObjectTitle}\"",
",",
"[",
"'ObjectTitle'",
"=>",
"$",
"record",
"->",
"i18n_singular_name",
"(",
")",
"]",
")",
")",
";",
"return",
"null",
";",
"}",
"return",
"$",
"record",
";",
"}"
]
| Fetches record version and checks canView permission for result
@param string $recordClass
@param int $recordId
@param int $recordVersion
@return DataObject|null | [
"Fetches",
"record",
"version",
"and",
"checks",
"canView",
"permission",
"for",
"result"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Controllers/HistoryViewerController.php#L162-L181 | train |
silverstripe/silverstripe-versioned-admin | src/Controllers/HistoryViewerController.php | HistoryViewerController.validateInput | protected function validateInput(array $context, array $requiredFields = [])
{
foreach ($requiredFields as $requiredField) {
if (empty($context[$requiredField])) {
throw new InvalidArgumentException('Missing required field ' . $requiredField);
}
}
return true;
} | php | protected function validateInput(array $context, array $requiredFields = [])
{
foreach ($requiredFields as $requiredField) {
if (empty($context[$requiredField])) {
throw new InvalidArgumentException('Missing required field ' . $requiredField);
}
}
return true;
} | [
"protected",
"function",
"validateInput",
"(",
"array",
"$",
"context",
",",
"array",
"$",
"requiredFields",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"requiredFields",
"as",
"$",
"requiredField",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"context",
"[",
"$",
"requiredField",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Missing required field '",
".",
"$",
"requiredField",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Perform some centralised validation checks on the input request and data within it
@param array $context
@param string[] $requiredFields
@return bool
@throws InvalidArgumentException | [
"Perform",
"some",
"centralised",
"validation",
"checks",
"on",
"the",
"input",
"request",
"and",
"data",
"within",
"it"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Controllers/HistoryViewerController.php#L268-L276 | train |
silverstripe/silverstripe-versioned-admin | src/Controllers/HistoryViewerController.php | HistoryViewerController.scaffoldForm | protected function scaffoldForm($formName, array $context = [], array $extra = [])
{
/** @var FormFactory $scaffolder */
$scaffolder = Injector::inst()->get(DataObjectVersionFormFactory::class);
$form = $scaffolder->getForm($this, $formName, $context);
// Set form handler with class name, ID and VersionID
return $form->setRequestHandler(
LeftAndMainFormRequestHandler::create($form, $extra)
);
} | php | protected function scaffoldForm($formName, array $context = [], array $extra = [])
{
/** @var FormFactory $scaffolder */
$scaffolder = Injector::inst()->get(DataObjectVersionFormFactory::class);
$form = $scaffolder->getForm($this, $formName, $context);
// Set form handler with class name, ID and VersionID
return $form->setRequestHandler(
LeftAndMainFormRequestHandler::create($form, $extra)
);
} | [
"protected",
"function",
"scaffoldForm",
"(",
"$",
"formName",
",",
"array",
"$",
"context",
"=",
"[",
"]",
",",
"array",
"$",
"extra",
"=",
"[",
"]",
")",
"{",
"/** @var FormFactory $scaffolder */",
"$",
"scaffolder",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"DataObjectVersionFormFactory",
"::",
"class",
")",
";",
"$",
"form",
"=",
"$",
"scaffolder",
"->",
"getForm",
"(",
"$",
"this",
",",
"$",
"formName",
",",
"$",
"context",
")",
";",
"// Set form handler with class name, ID and VersionID",
"return",
"$",
"form",
"->",
"setRequestHandler",
"(",
"LeftAndMainFormRequestHandler",
"::",
"create",
"(",
"$",
"form",
",",
"$",
"extra",
")",
")",
";",
"}"
]
| Given some context, scaffold a form using the FormFactory and return it
@param string $formName The name for the returned {@link Form}
@param array $context Context arguments for the {@link FormFactory}
@param array $extra Context arguments for the {@link LeftAndMainFormRequestHandler}
@return Form | [
"Given",
"some",
"context",
"scaffold",
"a",
"form",
"using",
"the",
"FormFactory",
"and",
"return",
"it"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Controllers/HistoryViewerController.php#L286-L296 | train |
silverstripe/silverstripe-versioned-admin | src/Extensions/ArchiveRestoreAction.php | ArchiveRestoreAction.updateItemEditForm | public function updateItemEditForm(Form $form)
{
$record = $this->owner->getRecord();
if ($this->shouldDisplayAction($record)) {
$restoreToRoot = RestoreAction::shouldRestoreToRoot($record);
$title = $restoreToRoot
? _t('SilverStripe\\Versioned\\RestoreAction.RESTORE_TO_ROOT', 'Restore to draft at top level')
: _t('SilverStripe\\Versioned\\RestoreAction.RESTORE', 'Restore to draft');
$description = $restoreToRoot
? _t(
'SilverStripe\\Versioned\\RestoreAction.RESTORE_TO_ROOT_DESC',
'Restore the archived version to draft as a top level item'
)
: _t(
'SilverStripe\\Versioned\\RestoreAction.RESTORE_DESC',
'Restore the archived version to draft'
);
$form->actions = FieldList::create(
FormAction::create('doRestore', $title)
->setDescription($description)
->setAttribute('data-to-root', $restoreToRoot)
->addExtraClass('btn-warning font-icon-back-in-time ArchiveAdmin__action--restore')
->setUseButtonTag(true)
);
$form->unsetValidator();
}
} | php | public function updateItemEditForm(Form $form)
{
$record = $this->owner->getRecord();
if ($this->shouldDisplayAction($record)) {
$restoreToRoot = RestoreAction::shouldRestoreToRoot($record);
$title = $restoreToRoot
? _t('SilverStripe\\Versioned\\RestoreAction.RESTORE_TO_ROOT', 'Restore to draft at top level')
: _t('SilverStripe\\Versioned\\RestoreAction.RESTORE', 'Restore to draft');
$description = $restoreToRoot
? _t(
'SilverStripe\\Versioned\\RestoreAction.RESTORE_TO_ROOT_DESC',
'Restore the archived version to draft as a top level item'
)
: _t(
'SilverStripe\\Versioned\\RestoreAction.RESTORE_DESC',
'Restore the archived version to draft'
);
$form->actions = FieldList::create(
FormAction::create('doRestore', $title)
->setDescription($description)
->setAttribute('data-to-root', $restoreToRoot)
->addExtraClass('btn-warning font-icon-back-in-time ArchiveAdmin__action--restore')
->setUseButtonTag(true)
);
$form->unsetValidator();
}
} | [
"public",
"function",
"updateItemEditForm",
"(",
"Form",
"$",
"form",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"owner",
"->",
"getRecord",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"shouldDisplayAction",
"(",
"$",
"record",
")",
")",
"{",
"$",
"restoreToRoot",
"=",
"RestoreAction",
"::",
"shouldRestoreToRoot",
"(",
"$",
"record",
")",
";",
"$",
"title",
"=",
"$",
"restoreToRoot",
"?",
"_t",
"(",
"'SilverStripe\\\\Versioned\\\\RestoreAction.RESTORE_TO_ROOT'",
",",
"'Restore to draft at top level'",
")",
":",
"_t",
"(",
"'SilverStripe\\\\Versioned\\\\RestoreAction.RESTORE'",
",",
"'Restore to draft'",
")",
";",
"$",
"description",
"=",
"$",
"restoreToRoot",
"?",
"_t",
"(",
"'SilverStripe\\\\Versioned\\\\RestoreAction.RESTORE_TO_ROOT_DESC'",
",",
"'Restore the archived version to draft as a top level item'",
")",
":",
"_t",
"(",
"'SilverStripe\\\\Versioned\\\\RestoreAction.RESTORE_DESC'",
",",
"'Restore the archived version to draft'",
")",
";",
"$",
"form",
"->",
"actions",
"=",
"FieldList",
"::",
"create",
"(",
"FormAction",
"::",
"create",
"(",
"'doRestore'",
",",
"$",
"title",
")",
"->",
"setDescription",
"(",
"$",
"description",
")",
"->",
"setAttribute",
"(",
"'data-to-root'",
",",
"$",
"restoreToRoot",
")",
"->",
"addExtraClass",
"(",
"'btn-warning font-icon-back-in-time ArchiveAdmin__action--restore'",
")",
"->",
"setUseButtonTag",
"(",
"true",
")",
")",
";",
"$",
"form",
"->",
"unsetValidator",
"(",
")",
";",
"}",
"}"
]
| Updates the edit form with a restore button if it is being viewed
@param Form $form
@return mixed | [
"Updates",
"the",
"edit",
"form",
"with",
"a",
"restore",
"button",
"if",
"it",
"is",
"being",
"viewed"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Extensions/ArchiveRestoreAction.php#L27-L57 | train |
silverstripe/silverstripe-versioned-admin | src/Extensions/ArchiveRestoreAction.php | ArchiveRestoreAction.shouldDisplayAction | protected function shouldDisplayAction($record)
{
$admin = $this->owner->popupController;
// If the record is a File, check if the file binary was archived
$hasFileSaved = $record instanceof File ? $record->exists() : true;
return (
$hasFileSaved &&
$admin instanceof ArchiveAdmin &&
DataObject::has_extension($record, Versioned::class) &&
$record->canRestoreToDraft()
);
} | php | protected function shouldDisplayAction($record)
{
$admin = $this->owner->popupController;
// If the record is a File, check if the file binary was archived
$hasFileSaved = $record instanceof File ? $record->exists() : true;
return (
$hasFileSaved &&
$admin instanceof ArchiveAdmin &&
DataObject::has_extension($record, Versioned::class) &&
$record->canRestoreToDraft()
);
} | [
"protected",
"function",
"shouldDisplayAction",
"(",
"$",
"record",
")",
"{",
"$",
"admin",
"=",
"$",
"this",
"->",
"owner",
"->",
"popupController",
";",
"// If the record is a File, check if the file binary was archived",
"$",
"hasFileSaved",
"=",
"$",
"record",
"instanceof",
"File",
"?",
"$",
"record",
"->",
"exists",
"(",
")",
":",
"true",
";",
"return",
"(",
"$",
"hasFileSaved",
"&&",
"$",
"admin",
"instanceof",
"ArchiveAdmin",
"&&",
"DataObject",
"::",
"has_extension",
"(",
"$",
"record",
",",
"Versioned",
"::",
"class",
")",
"&&",
"$",
"record",
"->",
"canRestoreToDraft",
"(",
")",
")",
";",
"}"
]
| Returns whether the restore action should be displayed
@param $record
@return bool | [
"Returns",
"whether",
"the",
"restore",
"action",
"should",
"be",
"displayed"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Extensions/ArchiveRestoreAction.php#L65-L76 | train |
silverstripe/silverstripe-versioned-admin | src/Extensions/ArchiveRestoreAction.php | ArchiveRestoreAction.doRestore | public function doRestore($data, $form)
{
$record = $this->owner->getRecord();
$message = RestoreAction::restore($record);
$controller = $this->owner->popupController;
$controller->getRequest()->addHeader('X-Pjax', 'Content');
$controller->getEditForm()->sessionMessage($message['text'], $message['type'], ValidationResult::CAST_HTML);
return $controller->redirect($controller->Link(), 'index');
} | php | public function doRestore($data, $form)
{
$record = $this->owner->getRecord();
$message = RestoreAction::restore($record);
$controller = $this->owner->popupController;
$controller->getRequest()->addHeader('X-Pjax', 'Content');
$controller->getEditForm()->sessionMessage($message['text'], $message['type'], ValidationResult::CAST_HTML);
return $controller->redirect($controller->Link(), 'index');
} | [
"public",
"function",
"doRestore",
"(",
"$",
"data",
",",
"$",
"form",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"owner",
"->",
"getRecord",
"(",
")",
";",
"$",
"message",
"=",
"RestoreAction",
"::",
"restore",
"(",
"$",
"record",
")",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"owner",
"->",
"popupController",
";",
"$",
"controller",
"->",
"getRequest",
"(",
")",
"->",
"addHeader",
"(",
"'X-Pjax'",
",",
"'Content'",
")",
";",
"$",
"controller",
"->",
"getEditForm",
"(",
")",
"->",
"sessionMessage",
"(",
"$",
"message",
"[",
"'text'",
"]",
",",
"$",
"message",
"[",
"'type'",
"]",
",",
"ValidationResult",
"::",
"CAST_HTML",
")",
";",
"return",
"$",
"controller",
"->",
"redirect",
"(",
"$",
"controller",
"->",
"Link",
"(",
")",
",",
"'index'",
")",
";",
"}"
]
| Restore the record to its original place or top level if that's not possible
@param array $data
@param Form $form
@return HTTPResponse | [
"Restore",
"the",
"record",
"to",
"its",
"original",
"place",
"or",
"top",
"level",
"if",
"that",
"s",
"not",
"possible"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Extensions/ArchiveRestoreAction.php#L85-L96 | train |
silverstripe/silverstripe-versioned-admin | src/Forms/HistoryViewerField.php | HistoryViewerField.getPreviewEnabled | public function getPreviewEnabled()
{
$record = $this->getSourceRecord();
$previewEnabled = $record && $record instanceof CMSPreviewable;
$this->extend('updatePreviewEnabled', $previewEnabled, $record);
return $previewEnabled;
} | php | public function getPreviewEnabled()
{
$record = $this->getSourceRecord();
$previewEnabled = $record && $record instanceof CMSPreviewable;
$this->extend('updatePreviewEnabled', $previewEnabled, $record);
return $previewEnabled;
} | [
"public",
"function",
"getPreviewEnabled",
"(",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"getSourceRecord",
"(",
")",
";",
"$",
"previewEnabled",
"=",
"$",
"record",
"&&",
"$",
"record",
"instanceof",
"CMSPreviewable",
";",
"$",
"this",
"->",
"extend",
"(",
"'updatePreviewEnabled'",
",",
"$",
"previewEnabled",
",",
"$",
"record",
")",
";",
"return",
"$",
"previewEnabled",
";",
"}"
]
| Get whether the record is previewable
@return boolean | [
"Get",
"whether",
"the",
"record",
"is",
"previewable"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Forms/HistoryViewerField.php#L62-L70 | train |
silverstripe/silverstripe-versioned-admin | src/Forms/HistoryViewerField.php | HistoryViewerField.getSchemaDataDefaults | public function getSchemaDataDefaults()
{
$data = parent::getSchemaDataDefaults();
$sourceRecord = $this->getSourceRecord();
$data['data'] = array_merge($data['data'], [
'recordId' => $sourceRecord ? $sourceRecord->ID : null,
'recordClass' => $sourceRecord ? $sourceRecord->ClassName : null,
'contextKey' => $this->getContextKey(),
'isPreviewable' => $this->getPreviewEnabled(),
'limit' => $this->config()->get('default_page_size'),
'offset' => 0,
'page' => 0,
]);
return $data;
} | php | public function getSchemaDataDefaults()
{
$data = parent::getSchemaDataDefaults();
$sourceRecord = $this->getSourceRecord();
$data['data'] = array_merge($data['data'], [
'recordId' => $sourceRecord ? $sourceRecord->ID : null,
'recordClass' => $sourceRecord ? $sourceRecord->ClassName : null,
'contextKey' => $this->getContextKey(),
'isPreviewable' => $this->getPreviewEnabled(),
'limit' => $this->config()->get('default_page_size'),
'offset' => 0,
'page' => 0,
]);
return $data;
} | [
"public",
"function",
"getSchemaDataDefaults",
"(",
")",
"{",
"$",
"data",
"=",
"parent",
"::",
"getSchemaDataDefaults",
"(",
")",
";",
"$",
"sourceRecord",
"=",
"$",
"this",
"->",
"getSourceRecord",
"(",
")",
";",
"$",
"data",
"[",
"'data'",
"]",
"=",
"array_merge",
"(",
"$",
"data",
"[",
"'data'",
"]",
",",
"[",
"'recordId'",
"=>",
"$",
"sourceRecord",
"?",
"$",
"sourceRecord",
"->",
"ID",
":",
"null",
",",
"'recordClass'",
"=>",
"$",
"sourceRecord",
"?",
"$",
"sourceRecord",
"->",
"ClassName",
":",
"null",
",",
"'contextKey'",
"=>",
"$",
"this",
"->",
"getContextKey",
"(",
")",
",",
"'isPreviewable'",
"=>",
"$",
"this",
"->",
"getPreviewEnabled",
"(",
")",
",",
"'limit'",
"=>",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'default_page_size'",
")",
",",
"'offset'",
"=>",
"0",
",",
"'page'",
"=>",
"0",
",",
"]",
")",
";",
"return",
"$",
"data",
";",
"}"
]
| Provide the necessary input data for React to power the history viewer
{@inheritDoc} | [
"Provide",
"the",
"necessary",
"input",
"data",
"for",
"React",
"to",
"power",
"the",
"history",
"viewer"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Forms/HistoryViewerField.php#L93-L110 | train |
silverstripe/silverstripe-versioned-admin | src/ArchiveAdmin.php | ArchiveAdmin.getEditForm | public function getEditForm($id = null, $fields = null)
{
$fields = FieldList::create();
$modelClass = $this->request->getVar('others') ? 'others' : $this->modelClass;
$classInst = Injector::inst()->get($this->modelClass);
if (ClassInfo::hasMethod($classInst, 'getArchiveField')) {
$listField = $classInst->getArchiveField();
$fields->push($listField);
} else {
$otherVersionedObjects = $this->getVersionedModels('other');
$modelSelectField = $this->getOtherModelSelectorField($modelClass);
$fields->push($modelSelectField);
// If a valid other model name is passed via a request param
// then show a gridfield with archived records
if (array_search($modelClass, $otherVersionedObjects)) {
$listField = $this->createArchiveGridField('Others', $modelClass);
$listColumns = $listField->getConfig()->getComponentByType(GridFieldDataColumns::class);
$listColumns->setDisplayFields([
'Title' => _t(__CLASS__ . '.COLUMN_TITLE', 'Title'),
'Versions.first.LastEdited' => _t(__CLASS__ . '.COLUMN_DATEARCHIVED', 'Date Archived'),
'Versions.first.Author.Name' => _t(__CLASS__ . '.COLUMN_ARCHIVEDBY', 'Archived By'),
]);
$listColumns->setFieldFormatting([
'Versions.first.LastEdited' => function ($val, $item) {
return DBDatetime::create_field('Datetime', $val)->Ago();
},
]);
$fields->push($listField);
}
}
$form = Form::create(
$this,
'EditForm',
$fields,
FieldList::create()
)->setHTMLID('Form_EditForm');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
$form->setAttribute('data-pjax-fragment', 'CurrentForm');
$form->addExtraClass(
'ArchiveAdmin discardchanges cms-edit-form cms-panel-padded center flexbox-area-grow '.
$this->BaseCSSClasses()
);
$form->setFormAction(Controller::join_links(
$this->Link($this->sanitiseClassName($this->modelClass)),
'EditForm'
));
$this->extend('updateEditForm', $form);
return $form;
} | php | public function getEditForm($id = null, $fields = null)
{
$fields = FieldList::create();
$modelClass = $this->request->getVar('others') ? 'others' : $this->modelClass;
$classInst = Injector::inst()->get($this->modelClass);
if (ClassInfo::hasMethod($classInst, 'getArchiveField')) {
$listField = $classInst->getArchiveField();
$fields->push($listField);
} else {
$otherVersionedObjects = $this->getVersionedModels('other');
$modelSelectField = $this->getOtherModelSelectorField($modelClass);
$fields->push($modelSelectField);
// If a valid other model name is passed via a request param
// then show a gridfield with archived records
if (array_search($modelClass, $otherVersionedObjects)) {
$listField = $this->createArchiveGridField('Others', $modelClass);
$listColumns = $listField->getConfig()->getComponentByType(GridFieldDataColumns::class);
$listColumns->setDisplayFields([
'Title' => _t(__CLASS__ . '.COLUMN_TITLE', 'Title'),
'Versions.first.LastEdited' => _t(__CLASS__ . '.COLUMN_DATEARCHIVED', 'Date Archived'),
'Versions.first.Author.Name' => _t(__CLASS__ . '.COLUMN_ARCHIVEDBY', 'Archived By'),
]);
$listColumns->setFieldFormatting([
'Versions.first.LastEdited' => function ($val, $item) {
return DBDatetime::create_field('Datetime', $val)->Ago();
},
]);
$fields->push($listField);
}
}
$form = Form::create(
$this,
'EditForm',
$fields,
FieldList::create()
)->setHTMLID('Form_EditForm');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
$form->setAttribute('data-pjax-fragment', 'CurrentForm');
$form->addExtraClass(
'ArchiveAdmin discardchanges cms-edit-form cms-panel-padded center flexbox-area-grow '.
$this->BaseCSSClasses()
);
$form->setFormAction(Controller::join_links(
$this->Link($this->sanitiseClassName($this->modelClass)),
'EditForm'
));
$this->extend('updateEditForm', $form);
return $form;
} | [
"public",
"function",
"getEditForm",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"$",
"fields",
"=",
"FieldList",
"::",
"create",
"(",
")",
";",
"$",
"modelClass",
"=",
"$",
"this",
"->",
"request",
"->",
"getVar",
"(",
"'others'",
")",
"?",
"'others'",
":",
"$",
"this",
"->",
"modelClass",
";",
"$",
"classInst",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"modelClass",
")",
";",
"if",
"(",
"ClassInfo",
"::",
"hasMethod",
"(",
"$",
"classInst",
",",
"'getArchiveField'",
")",
")",
"{",
"$",
"listField",
"=",
"$",
"classInst",
"->",
"getArchiveField",
"(",
")",
";",
"$",
"fields",
"->",
"push",
"(",
"$",
"listField",
")",
";",
"}",
"else",
"{",
"$",
"otherVersionedObjects",
"=",
"$",
"this",
"->",
"getVersionedModels",
"(",
"'other'",
")",
";",
"$",
"modelSelectField",
"=",
"$",
"this",
"->",
"getOtherModelSelectorField",
"(",
"$",
"modelClass",
")",
";",
"$",
"fields",
"->",
"push",
"(",
"$",
"modelSelectField",
")",
";",
"// If a valid other model name is passed via a request param",
"// then show a gridfield with archived records",
"if",
"(",
"array_search",
"(",
"$",
"modelClass",
",",
"$",
"otherVersionedObjects",
")",
")",
"{",
"$",
"listField",
"=",
"$",
"this",
"->",
"createArchiveGridField",
"(",
"'Others'",
",",
"$",
"modelClass",
")",
";",
"$",
"listColumns",
"=",
"$",
"listField",
"->",
"getConfig",
"(",
")",
"->",
"getComponentByType",
"(",
"GridFieldDataColumns",
"::",
"class",
")",
";",
"$",
"listColumns",
"->",
"setDisplayFields",
"(",
"[",
"'Title'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.COLUMN_TITLE'",
",",
"'Title'",
")",
",",
"'Versions.first.LastEdited'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.COLUMN_DATEARCHIVED'",
",",
"'Date Archived'",
")",
",",
"'Versions.first.Author.Name'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.COLUMN_ARCHIVEDBY'",
",",
"'Archived By'",
")",
",",
"]",
")",
";",
"$",
"listColumns",
"->",
"setFieldFormatting",
"(",
"[",
"'Versions.first.LastEdited'",
"=>",
"function",
"(",
"$",
"val",
",",
"$",
"item",
")",
"{",
"return",
"DBDatetime",
"::",
"create_field",
"(",
"'Datetime'",
",",
"$",
"val",
")",
"->",
"Ago",
"(",
")",
";",
"}",
",",
"]",
")",
";",
"$",
"fields",
"->",
"push",
"(",
"$",
"listField",
")",
";",
"}",
"}",
"$",
"form",
"=",
"Form",
"::",
"create",
"(",
"$",
"this",
",",
"'EditForm'",
",",
"$",
"fields",
",",
"FieldList",
"::",
"create",
"(",
")",
")",
"->",
"setHTMLID",
"(",
"'Form_EditForm'",
")",
";",
"$",
"form",
"->",
"setTemplate",
"(",
"$",
"this",
"->",
"getTemplatesWithSuffix",
"(",
"'_EditForm'",
")",
")",
";",
"$",
"form",
"->",
"setAttribute",
"(",
"'data-pjax-fragment'",
",",
"'CurrentForm'",
")",
";",
"$",
"form",
"->",
"addExtraClass",
"(",
"'ArchiveAdmin discardchanges cms-edit-form cms-panel-padded center flexbox-area-grow '",
".",
"$",
"this",
"->",
"BaseCSSClasses",
"(",
")",
")",
";",
"$",
"form",
"->",
"setFormAction",
"(",
"Controller",
"::",
"join_links",
"(",
"$",
"this",
"->",
"Link",
"(",
"$",
"this",
"->",
"sanitiseClassName",
"(",
"$",
"this",
"->",
"modelClass",
")",
")",
",",
"'EditForm'",
")",
")",
";",
"$",
"this",
"->",
"extend",
"(",
"'updateEditForm'",
",",
"$",
"form",
")",
";",
"return",
"$",
"form",
";",
"}"
]
| Produces an edit form with relevant prioritised tabs for Pages, Blocks and Files
@param int|null $id
@param FieldList|null $fields
@return Form A Form object with one tab per {@link \SilverStripe\Forms\GridField\GridField} | [
"Produces",
"an",
"edit",
"form",
"with",
"relevant",
"prioritised",
"tabs",
"for",
"Pages",
"Blocks",
"and",
"Files"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/ArchiveAdmin.php#L64-L119 | train |
silverstripe/silverstripe-versioned-admin | src/ArchiveAdmin.php | ArchiveAdmin.createArchiveGridField | public static function createArchiveGridField($title, $class)
{
$config = GridFieldConfig_Base::create();
$config->removeComponentsByType(VersionedGridFieldState::class);
$config->removeComponentsByType(GridFieldFilterHeader::class);
$config->addComponent(new GridFieldDetailForm);
$config->addComponent(new GridFieldViewButton);
$config->addComponent(new GridFieldRestoreAction);
$config->addComponent(new GridField_ActionMenu);
$list = singleton($class)->get();
$baseTable = singleton($list->dataClass())->baseTable();
$liveTable = $baseTable . '_Live';
$list = $list
->setDataQueryParam('Versioned.mode', 'latest_versions');
// Join a temporary alias BaseTable_Draft, renaming this on execution to BaseTable
// See Versioned::augmentSQL() For reference on this alias
$draftTable = $baseTable . '_Draft';
$list = $list
->leftJoin(
$draftTable,
"\"{$baseTable}\".\"ID\" = \"{$draftTable}\".\"ID\""
);
$list = $list->leftJoin(
$liveTable,
"\"{$baseTable}\".\"ID\" = \"{$liveTable}\".\"ID\""
);
$list = $list->where("\"{$draftTable}\".\"ID\" IS NULL");
$list = $list->sort('LastEdited DESC');
$field = GridField::create(
$title,
false,
$list,
$config
);
$field->setModelClass($class);
return $field;
} | php | public static function createArchiveGridField($title, $class)
{
$config = GridFieldConfig_Base::create();
$config->removeComponentsByType(VersionedGridFieldState::class);
$config->removeComponentsByType(GridFieldFilterHeader::class);
$config->addComponent(new GridFieldDetailForm);
$config->addComponent(new GridFieldViewButton);
$config->addComponent(new GridFieldRestoreAction);
$config->addComponent(new GridField_ActionMenu);
$list = singleton($class)->get();
$baseTable = singleton($list->dataClass())->baseTable();
$liveTable = $baseTable . '_Live';
$list = $list
->setDataQueryParam('Versioned.mode', 'latest_versions');
// Join a temporary alias BaseTable_Draft, renaming this on execution to BaseTable
// See Versioned::augmentSQL() For reference on this alias
$draftTable = $baseTable . '_Draft';
$list = $list
->leftJoin(
$draftTable,
"\"{$baseTable}\".\"ID\" = \"{$draftTable}\".\"ID\""
);
$list = $list->leftJoin(
$liveTable,
"\"{$baseTable}\".\"ID\" = \"{$liveTable}\".\"ID\""
);
$list = $list->where("\"{$draftTable}\".\"ID\" IS NULL");
$list = $list->sort('LastEdited DESC');
$field = GridField::create(
$title,
false,
$list,
$config
);
$field->setModelClass($class);
return $field;
} | [
"public",
"static",
"function",
"createArchiveGridField",
"(",
"$",
"title",
",",
"$",
"class",
")",
"{",
"$",
"config",
"=",
"GridFieldConfig_Base",
"::",
"create",
"(",
")",
";",
"$",
"config",
"->",
"removeComponentsByType",
"(",
"VersionedGridFieldState",
"::",
"class",
")",
";",
"$",
"config",
"->",
"removeComponentsByType",
"(",
"GridFieldFilterHeader",
"::",
"class",
")",
";",
"$",
"config",
"->",
"addComponent",
"(",
"new",
"GridFieldDetailForm",
")",
";",
"$",
"config",
"->",
"addComponent",
"(",
"new",
"GridFieldViewButton",
")",
";",
"$",
"config",
"->",
"addComponent",
"(",
"new",
"GridFieldRestoreAction",
")",
";",
"$",
"config",
"->",
"addComponent",
"(",
"new",
"GridField_ActionMenu",
")",
";",
"$",
"list",
"=",
"singleton",
"(",
"$",
"class",
")",
"->",
"get",
"(",
")",
";",
"$",
"baseTable",
"=",
"singleton",
"(",
"$",
"list",
"->",
"dataClass",
"(",
")",
")",
"->",
"baseTable",
"(",
")",
";",
"$",
"liveTable",
"=",
"$",
"baseTable",
".",
"'_Live'",
";",
"$",
"list",
"=",
"$",
"list",
"->",
"setDataQueryParam",
"(",
"'Versioned.mode'",
",",
"'latest_versions'",
")",
";",
"// Join a temporary alias BaseTable_Draft, renaming this on execution to BaseTable",
"// See Versioned::augmentSQL() For reference on this alias",
"$",
"draftTable",
"=",
"$",
"baseTable",
".",
"'_Draft'",
";",
"$",
"list",
"=",
"$",
"list",
"->",
"leftJoin",
"(",
"$",
"draftTable",
",",
"\"\\\"{$baseTable}\\\".\\\"ID\\\" = \\\"{$draftTable}\\\".\\\"ID\\\"\"",
")",
";",
"$",
"list",
"=",
"$",
"list",
"->",
"leftJoin",
"(",
"$",
"liveTable",
",",
"\"\\\"{$baseTable}\\\".\\\"ID\\\" = \\\"{$liveTable}\\\".\\\"ID\\\"\"",
")",
";",
"$",
"list",
"=",
"$",
"list",
"->",
"where",
"(",
"\"\\\"{$draftTable}\\\".\\\"ID\\\" IS NULL\"",
")",
";",
"$",
"list",
"=",
"$",
"list",
"->",
"sort",
"(",
"'LastEdited DESC'",
")",
";",
"$",
"field",
"=",
"GridField",
"::",
"create",
"(",
"$",
"title",
",",
"false",
",",
"$",
"list",
",",
"$",
"config",
")",
";",
"$",
"field",
"->",
"setModelClass",
"(",
"$",
"class",
")",
";",
"return",
"$",
"field",
";",
"}"
]
| Create a gridfield which displays archived objects
@param string $title
@param string $class
@return GridField | [
"Create",
"a",
"gridfield",
"which",
"displays",
"archived",
"objects"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/ArchiveAdmin.php#L128-L170 | train |
silverstripe/silverstripe-versioned-admin | src/ArchiveAdmin.php | ArchiveAdmin.Breadcrumbs | public function Breadcrumbs($unlinked = false)
{
$items = parent::Breadcrumbs($unlinked);
$items[0]->Title = $this->menu_title();
return $items;
} | php | public function Breadcrumbs($unlinked = false)
{
$items = parent::Breadcrumbs($unlinked);
$items[0]->Title = $this->menu_title();
return $items;
} | [
"public",
"function",
"Breadcrumbs",
"(",
"$",
"unlinked",
"=",
"false",
")",
"{",
"$",
"items",
"=",
"parent",
"::",
"Breadcrumbs",
"(",
"$",
"unlinked",
")",
";",
"$",
"items",
"[",
"0",
"]",
"->",
"Title",
"=",
"$",
"this",
"->",
"menu_title",
"(",
")",
";",
"return",
"$",
"items",
";",
"}"
]
| Use 'Archives' as the top title rather than the model title
@param bool $unlinked
@return ArrayList | [
"Use",
"Archives",
"as",
"the",
"top",
"title",
"rather",
"than",
"the",
"model",
"title"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/ArchiveAdmin.php#L297-L304 | train |
silverstripe/silverstripe-versioned-admin | src/ArchiveAdmin.php | ArchiveAdmin.getManagedModels | public function getManagedModels()
{
$models = $this->getVersionedModels();
// Normalize models to have their model class in array key and all names as the value are uppercased
foreach ($models as $k => $v) {
$archivedModels[$v] = array('title' => ucfirst(singleton($v)->i18n_plural_name()));
unset($archivedModels[$k]);
}
return $archivedModels;
} | php | public function getManagedModels()
{
$models = $this->getVersionedModels();
// Normalize models to have their model class in array key and all names as the value are uppercased
foreach ($models as $k => $v) {
$archivedModels[$v] = array('title' => ucfirst(singleton($v)->i18n_plural_name()));
unset($archivedModels[$k]);
}
return $archivedModels;
} | [
"public",
"function",
"getManagedModels",
"(",
")",
"{",
"$",
"models",
"=",
"$",
"this",
"->",
"getVersionedModels",
"(",
")",
";",
"// Normalize models to have their model class in array key and all names as the value are uppercased",
"foreach",
"(",
"$",
"models",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"archivedModels",
"[",
"$",
"v",
"]",
"=",
"array",
"(",
"'title'",
"=>",
"ucfirst",
"(",
"singleton",
"(",
"$",
"v",
")",
"->",
"i18n_plural_name",
"(",
")",
")",
")",
";",
"unset",
"(",
"$",
"archivedModels",
"[",
"$",
"k",
"]",
")",
";",
"}",
"return",
"$",
"archivedModels",
";",
"}"
]
| Archive admin needs some extra logic for whether an archive tab should be shown
@return array Map of class name to an array of 'title' (see {@link $managed_models}) | [
"Archive",
"admin",
"needs",
"some",
"extra",
"logic",
"for",
"whether",
"an",
"archive",
"tab",
"should",
"be",
"shown"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/ArchiveAdmin.php#L311-L322 | train |
silverstripe/silverstripe-versioned-admin | src/ArchiveAdmin.php | ArchiveAdmin.getManagedModelTabs | public function getManagedModelTabs()
{
$forms = ArrayList::create();
$mainModels = $this->getVersionedModels('main', true);
foreach ($mainModels as $class => $title) {
$classInst = Injector::inst()->get($class);
if (ClassInfo::hasMethod($classInst, 'isArchiveFieldEnabled')
&& $classInst->isArchiveFieldEnabled()
) {
$forms->push(ArrayData::create([
'Title' => $title,
'ClassName' => $class,
'Link' => $this->Link($this->sanitiseClassName($class)),
'LinkOrCurrent' => ($class === $this->modelClass) ? 'current' : 'link'
]));
}
}
$otherModels = $this->getVersionedModels('other', true);
if ($otherModels) {
$isOtherActive = (
$this->request->getVar('others') !== null ||
array_key_exists($this->modelClass, $otherModels)
);
$forms->push(ArrayData::create([
'Title' => _t(__CLASS__ . '.TAB_OTHERS', 'Others'),
'ClassName' => 'Others',
'Link' => $this->Link('?others=1'),
'LinkOrCurrent' => ($isOtherActive ? 'current' : 'link')
]));
}
$forms->first()->LinkOrCurrent = 'link';
return $forms;
} | php | public function getManagedModelTabs()
{
$forms = ArrayList::create();
$mainModels = $this->getVersionedModels('main', true);
foreach ($mainModels as $class => $title) {
$classInst = Injector::inst()->get($class);
if (ClassInfo::hasMethod($classInst, 'isArchiveFieldEnabled')
&& $classInst->isArchiveFieldEnabled()
) {
$forms->push(ArrayData::create([
'Title' => $title,
'ClassName' => $class,
'Link' => $this->Link($this->sanitiseClassName($class)),
'LinkOrCurrent' => ($class === $this->modelClass) ? 'current' : 'link'
]));
}
}
$otherModels = $this->getVersionedModels('other', true);
if ($otherModels) {
$isOtherActive = (
$this->request->getVar('others') !== null ||
array_key_exists($this->modelClass, $otherModels)
);
$forms->push(ArrayData::create([
'Title' => _t(__CLASS__ . '.TAB_OTHERS', 'Others'),
'ClassName' => 'Others',
'Link' => $this->Link('?others=1'),
'LinkOrCurrent' => ($isOtherActive ? 'current' : 'link')
]));
}
$forms->first()->LinkOrCurrent = 'link';
return $forms;
} | [
"public",
"function",
"getManagedModelTabs",
"(",
")",
"{",
"$",
"forms",
"=",
"ArrayList",
"::",
"create",
"(",
")",
";",
"$",
"mainModels",
"=",
"$",
"this",
"->",
"getVersionedModels",
"(",
"'main'",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"mainModels",
"as",
"$",
"class",
"=>",
"$",
"title",
")",
"{",
"$",
"classInst",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"class",
")",
";",
"if",
"(",
"ClassInfo",
"::",
"hasMethod",
"(",
"$",
"classInst",
",",
"'isArchiveFieldEnabled'",
")",
"&&",
"$",
"classInst",
"->",
"isArchiveFieldEnabled",
"(",
")",
")",
"{",
"$",
"forms",
"->",
"push",
"(",
"ArrayData",
"::",
"create",
"(",
"[",
"'Title'",
"=>",
"$",
"title",
",",
"'ClassName'",
"=>",
"$",
"class",
",",
"'Link'",
"=>",
"$",
"this",
"->",
"Link",
"(",
"$",
"this",
"->",
"sanitiseClassName",
"(",
"$",
"class",
")",
")",
",",
"'LinkOrCurrent'",
"=>",
"(",
"$",
"class",
"===",
"$",
"this",
"->",
"modelClass",
")",
"?",
"'current'",
":",
"'link'",
"]",
")",
")",
";",
"}",
"}",
"$",
"otherModels",
"=",
"$",
"this",
"->",
"getVersionedModels",
"(",
"'other'",
",",
"true",
")",
";",
"if",
"(",
"$",
"otherModels",
")",
"{",
"$",
"isOtherActive",
"=",
"(",
"$",
"this",
"->",
"request",
"->",
"getVar",
"(",
"'others'",
")",
"!==",
"null",
"||",
"array_key_exists",
"(",
"$",
"this",
"->",
"modelClass",
",",
"$",
"otherModels",
")",
")",
";",
"$",
"forms",
"->",
"push",
"(",
"ArrayData",
"::",
"create",
"(",
"[",
"'Title'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.TAB_OTHERS'",
",",
"'Others'",
")",
",",
"'ClassName'",
"=>",
"'Others'",
",",
"'Link'",
"=>",
"$",
"this",
"->",
"Link",
"(",
"'?others=1'",
")",
",",
"'LinkOrCurrent'",
"=>",
"(",
"$",
"isOtherActive",
"?",
"'current'",
":",
"'link'",
")",
"]",
")",
")",
";",
"}",
"$",
"forms",
"->",
"first",
"(",
")",
"->",
"LinkOrCurrent",
"=",
"'link'",
";",
"return",
"$",
"forms",
";",
"}"
]
| Add the special 'Others' tab
@return ArrayList An ArrayList of all managed models to build the tabs for this ModelAdmin | [
"Add",
"the",
"special",
"Others",
"tab"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/ArchiveAdmin.php#L329-L365 | train |
silverstripe/silverstripe-versioned-admin | src/Forms/DataObjectVersionFormFactory.php | DataObjectVersionFormFactory.removeSelectedRightTitles | protected function removeSelectedRightTitles(FieldList $fields)
{
$noRightTitle = ['MetaDescription', 'ExtraMeta'];
foreach ($noRightTitle as $fieldName) {
if ($field = $fields->dataFieldByName($fieldName)) {
$field->setRightTitle('');
}
}
} | php | protected function removeSelectedRightTitles(FieldList $fields)
{
$noRightTitle = ['MetaDescription', 'ExtraMeta'];
foreach ($noRightTitle as $fieldName) {
if ($field = $fields->dataFieldByName($fieldName)) {
$field->setRightTitle('');
}
}
} | [
"protected",
"function",
"removeSelectedRightTitles",
"(",
"FieldList",
"$",
"fields",
")",
"{",
"$",
"noRightTitle",
"=",
"[",
"'MetaDescription'",
",",
"'ExtraMeta'",
"]",
";",
"foreach",
"(",
"$",
"noRightTitle",
"as",
"$",
"fieldName",
")",
"{",
"if",
"(",
"$",
"field",
"=",
"$",
"fields",
"->",
"dataFieldByName",
"(",
"$",
"fieldName",
")",
")",
"{",
"$",
"field",
"->",
"setRightTitle",
"(",
"''",
")",
";",
"}",
"}",
"}"
]
| Remove right titles from selected form fields by default
@param FieldList $fields | [
"Remove",
"right",
"titles",
"from",
"selected",
"form",
"fields",
"by",
"default"
]
| 1b63f375e3a34694158ac47a86f8f34b02daf847 | https://github.com/silverstripe/silverstripe-versioned-admin/blob/1b63f375e3a34694158ac47a86f8f34b02daf847/src/Forms/DataObjectVersionFormFactory.php#L134-L143 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuth.php | OAuth.getRequestToken | public function getRequestToken($callback = 'oob')
{
$request = $this->createRequest('/oauth/request_token', OAuthResponse::FORMAT_STR);
$request->setOAuthParameter('oauth_callback', $callback);
$this->signRequest($request, new OAuthToken());
return $this->createOAuthToken($this->sendRequest($request));
} | php | public function getRequestToken($callback = 'oob')
{
$request = $this->createRequest('/oauth/request_token', OAuthResponse::FORMAT_STR);
$request->setOAuthParameter('oauth_callback', $callback);
$this->signRequest($request, new OAuthToken());
return $this->createOAuthToken($this->sendRequest($request));
} | [
"public",
"function",
"getRequestToken",
"(",
"$",
"callback",
"=",
"'oob'",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"'/oauth/request_token'",
",",
"OAuthResponse",
"::",
"FORMAT_STR",
")",
";",
"$",
"request",
"->",
"setOAuthParameter",
"(",
"'oauth_callback'",
",",
"$",
"callback",
")",
";",
"$",
"this",
"->",
"signRequest",
"(",
"$",
"request",
",",
"new",
"OAuthToken",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"createOAuthToken",
"(",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"request",
")",
")",
";",
"}"
]
| Gets a request token.
@param string $callback The OAuth callback.
@return \Widop\Twitter\OAuth\Token\OAuthToken The request token. | [
"Gets",
"a",
"request",
"token",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuth.php#L173-L180 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuth.php | OAuth.getAccessToken | public function getAccessToken(OAuthToken $requestToken, $verifier)
{
$request = $this->createRequest('/oauth/access_token', OAuthResponse::FORMAT_STR);
$request->setOAuthParameter('oauth_verifier', $verifier);
$this->signRequest($request, $requestToken);
return $this->createOAuthToken($this->sendRequest($request));
} | php | public function getAccessToken(OAuthToken $requestToken, $verifier)
{
$request = $this->createRequest('/oauth/access_token', OAuthResponse::FORMAT_STR);
$request->setOAuthParameter('oauth_verifier', $verifier);
$this->signRequest($request, $requestToken);
return $this->createOAuthToken($this->sendRequest($request));
} | [
"public",
"function",
"getAccessToken",
"(",
"OAuthToken",
"$",
"requestToken",
",",
"$",
"verifier",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"'/oauth/access_token'",
",",
"OAuthResponse",
"::",
"FORMAT_STR",
")",
";",
"$",
"request",
"->",
"setOAuthParameter",
"(",
"'oauth_verifier'",
",",
"$",
"verifier",
")",
";",
"$",
"this",
"->",
"signRequest",
"(",
"$",
"request",
",",
"$",
"requestToken",
")",
";",
"return",
"$",
"this",
"->",
"createOAuthToken",
"(",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"request",
")",
")",
";",
"}"
]
| Gets an access token.
@param \Widop\Twitter\OAuth\Token\OAuthToken $requestToken The request token.
@param string $verifier The OAuth verifier.
@return \Widop\Twitter\OAuth\Token\OAuthToken The access token. | [
"Gets",
"an",
"access",
"token",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuth.php#L214-L221 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuth.php | OAuth.getBearerToken | public function getBearerToken($grantType = 'client_credentials')
{
$request = $this->createRequest('/oauth2/token');
$request->setPostParameter('grant_type', $grantType);
$this->signRequest($request, new BasicToken());
return $this->createBearerToken($this->sendRequest($request));
} | php | public function getBearerToken($grantType = 'client_credentials')
{
$request = $this->createRequest('/oauth2/token');
$request->setPostParameter('grant_type', $grantType);
$this->signRequest($request, new BasicToken());
return $this->createBearerToken($this->sendRequest($request));
} | [
"public",
"function",
"getBearerToken",
"(",
"$",
"grantType",
"=",
"'client_credentials'",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"'/oauth2/token'",
")",
";",
"$",
"request",
"->",
"setPostParameter",
"(",
"'grant_type'",
",",
"$",
"grantType",
")",
";",
"$",
"this",
"->",
"signRequest",
"(",
"$",
"request",
",",
"new",
"BasicToken",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"createBearerToken",
"(",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"request",
")",
")",
";",
"}"
]
| Gets a bearer token.
@param string $grantType The OAuth grant type.
@return \Widop\Twitter\OAuth\Token\BearerToken The bearer token. | [
"Gets",
"a",
"bearer",
"token",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuth.php#L230-L237 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuth.php | OAuth.invalidateBearerToken | public function invalidateBearerToken(BearerToken $token)
{
$request = $this->createRequest('/oauth2/invalidate_token');
$request->setPostParameter('access_token', $token->getValue());
$this->signRequest($request, new BasicToken());
$response = $this->sendRequest($request);
if ($token->getValue() !== $response->getData('access_token')) {
throw new OAuthException('An error occured when invalidating the bearer token.', $response);
}
} | php | public function invalidateBearerToken(BearerToken $token)
{
$request = $this->createRequest('/oauth2/invalidate_token');
$request->setPostParameter('access_token', $token->getValue());
$this->signRequest($request, new BasicToken());
$response = $this->sendRequest($request);
if ($token->getValue() !== $response->getData('access_token')) {
throw new OAuthException('An error occured when invalidating the bearer token.', $response);
}
} | [
"public",
"function",
"invalidateBearerToken",
"(",
"BearerToken",
"$",
"token",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"'/oauth2/invalidate_token'",
")",
";",
"$",
"request",
"->",
"setPostParameter",
"(",
"'access_token'",
",",
"$",
"token",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"this",
"->",
"signRequest",
"(",
"$",
"request",
",",
"new",
"BasicToken",
"(",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"token",
"->",
"getValue",
"(",
")",
"!==",
"$",
"response",
"->",
"getData",
"(",
"'access_token'",
")",
")",
"{",
"throw",
"new",
"OAuthException",
"(",
"'An error occured when invalidating the bearer token.'",
",",
"$",
"response",
")",
";",
"}",
"}"
]
| Invalidates the bearer token.
@param \Widop\Twitter\OAuth\BearerToken $token The bearer token.
@throws \RuntimeException If the token was not invalidated. | [
"Invalidates",
"the",
"bearer",
"token",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuth.php#L246-L257 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuth.php | OAuth.sendRequest | public function sendRequest(OAuthRequest $request)
{
switch ($request->getMethod()) {
case OAuthRequest::METHOD_GET:
$httpResponse = $this->httpAdapter->getContent($request->getUrl(), $request->getHeaders());
break;
case OAuthRequest::METHOD_POST:
$postParameters = array();
foreach ($request->getPostParameters() as $name => $value) {
$postParameters[rawurldecode($name)] = rawurldecode($value);
}
$httpResponse = $this->httpAdapter->postContent(
$request->getUrl(),
$request->getHeaders(),
$postParameters,
$request->getFileParameters()
);
break;
default:
throw new \RuntimeException(sprintf(
'The request method "%s" is not supported.',
$request->getMethod()
));
}
$response = new OAuthResponse($httpResponse, $request->getResponseFormat());
if (!$response->isValid()) {
throw new OAuthException('The http response is not valid.', $response);
}
return $response;
} | php | public function sendRequest(OAuthRequest $request)
{
switch ($request->getMethod()) {
case OAuthRequest::METHOD_GET:
$httpResponse = $this->httpAdapter->getContent($request->getUrl(), $request->getHeaders());
break;
case OAuthRequest::METHOD_POST:
$postParameters = array();
foreach ($request->getPostParameters() as $name => $value) {
$postParameters[rawurldecode($name)] = rawurldecode($value);
}
$httpResponse = $this->httpAdapter->postContent(
$request->getUrl(),
$request->getHeaders(),
$postParameters,
$request->getFileParameters()
);
break;
default:
throw new \RuntimeException(sprintf(
'The request method "%s" is not supported.',
$request->getMethod()
));
}
$response = new OAuthResponse($httpResponse, $request->getResponseFormat());
if (!$response->isValid()) {
throw new OAuthException('The http response is not valid.', $response);
}
return $response;
} | [
"public",
"function",
"sendRequest",
"(",
"OAuthRequest",
"$",
"request",
")",
"{",
"switch",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"case",
"OAuthRequest",
"::",
"METHOD_GET",
":",
"$",
"httpResponse",
"=",
"$",
"this",
"->",
"httpAdapter",
"->",
"getContent",
"(",
"$",
"request",
"->",
"getUrl",
"(",
")",
",",
"$",
"request",
"->",
"getHeaders",
"(",
")",
")",
";",
"break",
";",
"case",
"OAuthRequest",
"::",
"METHOD_POST",
":",
"$",
"postParameters",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"request",
"->",
"getPostParameters",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"postParameters",
"[",
"rawurldecode",
"(",
"$",
"name",
")",
"]",
"=",
"rawurldecode",
"(",
"$",
"value",
")",
";",
"}",
"$",
"httpResponse",
"=",
"$",
"this",
"->",
"httpAdapter",
"->",
"postContent",
"(",
"$",
"request",
"->",
"getUrl",
"(",
")",
",",
"$",
"request",
"->",
"getHeaders",
"(",
")",
",",
"$",
"postParameters",
",",
"$",
"request",
"->",
"getFileParameters",
"(",
")",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The request method \"%s\" is not supported.'",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}",
"$",
"response",
"=",
"new",
"OAuthResponse",
"(",
"$",
"httpResponse",
",",
"$",
"request",
"->",
"getResponseFormat",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"response",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"OAuthException",
"(",
"'The http response is not valid.'",
",",
"$",
"response",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Sends an OAuth request.
@param \Widop\Twitter\OAuth\OAuthRequest $request The OAuth request.
@throws \RuntimeException If the request method is not supported.
@return \Widop\Twitter\OAuth\OAuthResponse The OAuth response. | [
"Sends",
"an",
"OAuth",
"request",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuth.php#L279-L314 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuth.php | OAuth.createRequest | private function createRequest($path, $responseFormat = OAuthResponse::FORMAT_JSON)
{
$request = new OAuthRequest();
$request->setBaseUrl($this->getUrl());
$request->setPath($path);
$request->setMethod(OAuthRequest::METHOD_POST);
$request->setResponseFormat($responseFormat);
return $request;
} | php | private function createRequest($path, $responseFormat = OAuthResponse::FORMAT_JSON)
{
$request = new OAuthRequest();
$request->setBaseUrl($this->getUrl());
$request->setPath($path);
$request->setMethod(OAuthRequest::METHOD_POST);
$request->setResponseFormat($responseFormat);
return $request;
} | [
"private",
"function",
"createRequest",
"(",
"$",
"path",
",",
"$",
"responseFormat",
"=",
"OAuthResponse",
"::",
"FORMAT_JSON",
")",
"{",
"$",
"request",
"=",
"new",
"OAuthRequest",
"(",
")",
";",
"$",
"request",
"->",
"setBaseUrl",
"(",
"$",
"this",
"->",
"getUrl",
"(",
")",
")",
";",
"$",
"request",
"->",
"setPath",
"(",
"$",
"path",
")",
";",
"$",
"request",
"->",
"setMethod",
"(",
"OAuthRequest",
"::",
"METHOD_POST",
")",
";",
"$",
"request",
"->",
"setResponseFormat",
"(",
"$",
"responseFormat",
")",
";",
"return",
"$",
"request",
";",
"}"
]
| Creates an OAuth request.
@param string $path The OAuth path.
@param string $responseFormat The response format.
@return \Widop\Twitter\OAuth\OAuthRequest The OAuth request. | [
"Creates",
"an",
"OAuth",
"request",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuth.php#L324-L333 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuth.php | OAuth.createOAuthToken | private function createOAuthToken(OAuthResponse $response)
{
if (!$response->hasData('oauth_token') || !$response->hasData('oauth_token_secret')) {
throw new OAuthException('An error occured when creating the OAuth token.', $response);
}
return new OAuthToken($response->getData('oauth_token'), $response->getData('oauth_token_secret'));
} | php | private function createOAuthToken(OAuthResponse $response)
{
if (!$response->hasData('oauth_token') || !$response->hasData('oauth_token_secret')) {
throw new OAuthException('An error occured when creating the OAuth token.', $response);
}
return new OAuthToken($response->getData('oauth_token'), $response->getData('oauth_token_secret'));
} | [
"private",
"function",
"createOAuthToken",
"(",
"OAuthResponse",
"$",
"response",
")",
"{",
"if",
"(",
"!",
"$",
"response",
"->",
"hasData",
"(",
"'oauth_token'",
")",
"||",
"!",
"$",
"response",
"->",
"hasData",
"(",
"'oauth_token_secret'",
")",
")",
"{",
"throw",
"new",
"OAuthException",
"(",
"'An error occured when creating the OAuth token.'",
",",
"$",
"response",
")",
";",
"}",
"return",
"new",
"OAuthToken",
"(",
"$",
"response",
"->",
"getData",
"(",
"'oauth_token'",
")",
",",
"$",
"response",
"->",
"getData",
"(",
"'oauth_token_secret'",
")",
")",
";",
"}"
]
| Creates an oauth token according to an OAuth response.
@param \Widop\Twitter\OAuth\OAuthResponse $response The OAuth response.
@throws \Widop\Twitter\OAuth\OAuthException If the token cannot be created.
@return \Widop\Twitter\OAuth\Token\OAuthToken The OAuth token. | [
"Creates",
"an",
"oauth",
"token",
"according",
"to",
"an",
"OAuth",
"response",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuth.php#L344-L351 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuth.php | OAuth.createBearerToken | private function createBearerToken(OAuthResponse $response)
{
if (!$response->hasData('token_type') || !$response->hasData('access_token')) {
throw new OAuthException('An error occured when creating the bearer token.', $response);
}
return new BearerToken($response->getData('access_token'));
} | php | private function createBearerToken(OAuthResponse $response)
{
if (!$response->hasData('token_type') || !$response->hasData('access_token')) {
throw new OAuthException('An error occured when creating the bearer token.', $response);
}
return new BearerToken($response->getData('access_token'));
} | [
"private",
"function",
"createBearerToken",
"(",
"OAuthResponse",
"$",
"response",
")",
"{",
"if",
"(",
"!",
"$",
"response",
"->",
"hasData",
"(",
"'token_type'",
")",
"||",
"!",
"$",
"response",
"->",
"hasData",
"(",
"'access_token'",
")",
")",
"{",
"throw",
"new",
"OAuthException",
"(",
"'An error occured when creating the bearer token.'",
",",
"$",
"response",
")",
";",
"}",
"return",
"new",
"BearerToken",
"(",
"$",
"response",
"->",
"getData",
"(",
"'access_token'",
")",
")",
";",
"}"
]
| Creates a bearer token according to an OAuth response.
@param \Widop\Twitter\OAuth\OAuthResponse $response The OAuth response.
@throws \Widop\Twitter\OAuth\OAuthException If the token cannot be created.
@return \Widop\Twitter\OAuth\Token\BearerToken The Bearer token. | [
"Creates",
"a",
"bearer",
"token",
"according",
"to",
"an",
"OAuth",
"response",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuth.php#L362-L369 | train |
sendwithus/sendwithus_php | lib/API.php | API.resend | public function resend($log_id){
$endpoint = "resend";
$payload = array(
"log_id" => $log_id
);
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | php | public function resend($log_id){
$endpoint = "resend";
$payload = array(
"log_id" => $log_id
);
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | [
"public",
"function",
"resend",
"(",
"$",
"log_id",
")",
"{",
"$",
"endpoint",
"=",
"\"resend\"",
";",
"$",
"payload",
"=",
"array",
"(",
"\"log_id\"",
"=>",
"$",
"log_id",
")",
";",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_POST",
",",
"$",
"payload",
")",
";",
"}"
]
| Resend a specific email by id
@param string $log_id log id
@return array API response object | [
"Resend",
"a",
"specific",
"email",
"by",
"id"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L125-L133 | train |
sendwithus/sendwithus_php | lib/API.php | API.get_template | public function get_template($template_id, $version_id = null){
$endpoint = "templates/" . $template_id;
if($version_id){
$endpoint .= "/versions/" . $version_id;
}
return $this->api_request($endpoint, self::HTTP_GET);
} | php | public function get_template($template_id, $version_id = null){
$endpoint = "templates/" . $template_id;
if($version_id){
$endpoint .= "/versions/" . $version_id;
}
return $this->api_request($endpoint, self::HTTP_GET);
} | [
"public",
"function",
"get_template",
"(",
"$",
"template_id",
",",
"$",
"version_id",
"=",
"null",
")",
"{",
"$",
"endpoint",
"=",
"\"templates/\"",
".",
"$",
"template_id",
";",
"if",
"(",
"$",
"version_id",
")",
"{",
"$",
"endpoint",
".=",
"\"/versions/\"",
".",
"$",
"version_id",
";",
"}",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_GET",
")",
";",
"}"
]
| Get a specific template
@param string $template_id template id
@param string $version_id optional version id to get template version
@return array API response object | [
"Get",
"a",
"specific",
"template"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L153-L161 | train |
sendwithus/sendwithus_php | lib/API.php | API.create_email | public function create_email($name, $subject, $html, $text=null) {
$endpoint = "templates";
$payload = array(
"name" => $name,
"subject" => $subject,
"html" => $html
);
// set optional text
if ($text) {
$payload["text"] = $text;
}
if ($this->DEBUG) {
$this->log_message(sprintf("creating email with name %s and subject %s\n", $name, $subject));
}
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | php | public function create_email($name, $subject, $html, $text=null) {
$endpoint = "templates";
$payload = array(
"name" => $name,
"subject" => $subject,
"html" => $html
);
// set optional text
if ($text) {
$payload["text"] = $text;
}
if ($this->DEBUG) {
$this->log_message(sprintf("creating email with name %s and subject %s\n", $name, $subject));
}
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | [
"public",
"function",
"create_email",
"(",
"$",
"name",
",",
"$",
"subject",
",",
"$",
"html",
",",
"$",
"text",
"=",
"null",
")",
"{",
"$",
"endpoint",
"=",
"\"templates\"",
";",
"$",
"payload",
"=",
"array",
"(",
"\"name\"",
"=>",
"$",
"name",
",",
"\"subject\"",
"=>",
"$",
"subject",
",",
"\"html\"",
"=>",
"$",
"html",
")",
";",
"// set optional text",
"if",
"(",
"$",
"text",
")",
"{",
"$",
"payload",
"[",
"\"text\"",
"]",
"=",
"$",
"text",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"DEBUG",
")",
"{",
"$",
"this",
"->",
"log_message",
"(",
"sprintf",
"(",
"\"creating email with name %s and subject %s\\n\"",
",",
"$",
"name",
",",
"$",
"subject",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_POST",
",",
"$",
"payload",
")",
";",
"}"
]
| Create an Email
@param string $name name of the email template
@param string $subject subject line for the email template
@param string $html HTML code for the email template
@param string $text Optional text version of the email template
@return array API response object | [
"Create",
"an",
"Email"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L249-L268 | train |
sendwithus/sendwithus_php | lib/API.php | API.update_template_version | public function update_template_version($name, $subject, $template_id, $version_id, $html, $text=null) {
$endpoint = "templates/" . $template_id . "/versions/" . $version_id;
$payload = array(
"name" => $name,
"subject" => $subject,
"html" => $html
);
// set optional text
if ($text) {
$payload["text"] = $text;
}
if ($this->DEBUG) {
$this->log_message(
sprintf(
"updating template\n ID:%s\nVERSION:%s\n with name %s and subject %s\n",
$template_id,
$version_id,
$name,
$subject
)
);
}
return $this->api_request($endpoint, self::HTTP_PUT, $payload);
} | php | public function update_template_version($name, $subject, $template_id, $version_id, $html, $text=null) {
$endpoint = "templates/" . $template_id . "/versions/" . $version_id;
$payload = array(
"name" => $name,
"subject" => $subject,
"html" => $html
);
// set optional text
if ($text) {
$payload["text"] = $text;
}
if ($this->DEBUG) {
$this->log_message(
sprintf(
"updating template\n ID:%s\nVERSION:%s\n with name %s and subject %s\n",
$template_id,
$version_id,
$name,
$subject
)
);
}
return $this->api_request($endpoint, self::HTTP_PUT, $payload);
} | [
"public",
"function",
"update_template_version",
"(",
"$",
"name",
",",
"$",
"subject",
",",
"$",
"template_id",
",",
"$",
"version_id",
",",
"$",
"html",
",",
"$",
"text",
"=",
"null",
")",
"{",
"$",
"endpoint",
"=",
"\"templates/\"",
".",
"$",
"template_id",
".",
"\"/versions/\"",
".",
"$",
"version_id",
";",
"$",
"payload",
"=",
"array",
"(",
"\"name\"",
"=>",
"$",
"name",
",",
"\"subject\"",
"=>",
"$",
"subject",
",",
"\"html\"",
"=>",
"$",
"html",
")",
";",
"// set optional text",
"if",
"(",
"$",
"text",
")",
"{",
"$",
"payload",
"[",
"\"text\"",
"]",
"=",
"$",
"text",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"DEBUG",
")",
"{",
"$",
"this",
"->",
"log_message",
"(",
"sprintf",
"(",
"\"updating template\\n ID:%s\\nVERSION:%s\\n with name %s and subject %s\\n\"",
",",
"$",
"template_id",
",",
"$",
"version_id",
",",
"$",
"name",
",",
"$",
"subject",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_PUT",
",",
"$",
"payload",
")",
";",
"}"
]
| Update template version
@param string $name name of the email template
@param string $subject subject line for the email template
@param string $template_id template id
@param string $version_id template version id
@param string $html HTML code for the email template
@param string $text Optional text version of the email template
@return array API response object | [
"Update",
"template",
"version"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L312-L339 | train |
sendwithus/sendwithus_php | lib/API.php | API.drip_unsubscribe | public function drip_unsubscribe($email_address) {
$endpoint = "drips/unsubscribe";
$payload = array(
"email_address" => $email_address
);
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | php | public function drip_unsubscribe($email_address) {
$endpoint = "drips/unsubscribe";
$payload = array(
"email_address" => $email_address
);
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | [
"public",
"function",
"drip_unsubscribe",
"(",
"$",
"email_address",
")",
"{",
"$",
"endpoint",
"=",
"\"drips/unsubscribe\"",
";",
"$",
"payload",
"=",
"array",
"(",
"\"email_address\"",
"=>",
"$",
"email_address",
")",
";",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_POST",
",",
"$",
"payload",
")",
";",
"}"
]
| Unsubscribe email address from active drips
@param string $email_address the email to unsubscribe from active drips
@return array API response object | [
"Unsubscribe",
"email",
"address",
"from",
"active",
"drips"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L371-L379 | train |
sendwithus/sendwithus_php | lib/API.php | API.start_on_drip_campaign | public function start_on_drip_campaign($recipient_address, $drip_campaign_id, $data=null, $args=null){
$endpoint = "drip_campaigns/" . $drip_campaign_id . "/activate";
$payload = array();
if (is_array($recipient_address)) {
$payload["recipient"] = $recipient_address;
} else if (is_string($recipient_address)){
$payload = array(
"recipient_address" => $recipient_address
);
}
if (is_array($data)) {
$payload['email_data'] = $data;
}
if (is_array($args)) {
$payload = array_merge($args, $payload);
}
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | php | public function start_on_drip_campaign($recipient_address, $drip_campaign_id, $data=null, $args=null){
$endpoint = "drip_campaigns/" . $drip_campaign_id . "/activate";
$payload = array();
if (is_array($recipient_address)) {
$payload["recipient"] = $recipient_address;
} else if (is_string($recipient_address)){
$payload = array(
"recipient_address" => $recipient_address
);
}
if (is_array($data)) {
$payload['email_data'] = $data;
}
if (is_array($args)) {
$payload = array_merge($args, $payload);
}
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | [
"public",
"function",
"start_on_drip_campaign",
"(",
"$",
"recipient_address",
",",
"$",
"drip_campaign_id",
",",
"$",
"data",
"=",
"null",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"endpoint",
"=",
"\"drip_campaigns/\"",
".",
"$",
"drip_campaign_id",
".",
"\"/activate\"",
";",
"$",
"payload",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"recipient_address",
")",
")",
"{",
"$",
"payload",
"[",
"\"recipient\"",
"]",
"=",
"$",
"recipient_address",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"recipient_address",
")",
")",
"{",
"$",
"payload",
"=",
"array",
"(",
"\"recipient_address\"",
"=>",
"$",
"recipient_address",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"payload",
"[",
"'email_data'",
"]",
"=",
"$",
"data",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"args",
")",
")",
"{",
"$",
"payload",
"=",
"array_merge",
"(",
"$",
"args",
",",
"$",
"payload",
")",
";",
"}",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_POST",
",",
"$",
"payload",
")",
";",
"}"
]
| Start on drip campaign
The additional optional parameters for $args are as follows:
'sender' - Default is null. Array ("address", "name", "reply_to") of sender.
'cc' - Default is null. Array of ("address", "name") for carbon copy.
'bcc' - Default is null. Array of ("address", "name") for blind carbon copy.
'tags' - Default is null. Array of strings to tag email send with.
'esp' - Default is null. Value of ("esp_account": "esp_id")
@param array $recipient_address array of ("address", "name") to send to
@param string $drip_campaign_id drip campaign being added to
@param array (optional) $data email data being sent with drip
@param array (optional) $args additional options being sent with email (tags, cc's, etc)
@return array API response object | [
"Start",
"on",
"drip",
"campaign"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L419-L440 | train |
sendwithus/sendwithus_php | lib/API.php | API.remove_from_drip_campaign | public function remove_from_drip_campaign($recipient_address, $drip_campaign_id){
$endpoint = "drip_campaigns/" . $drip_campaign_id . "/deactivate";
$payload = array(
"recipient_address" => $recipient_address
);
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | php | public function remove_from_drip_campaign($recipient_address, $drip_campaign_id){
$endpoint = "drip_campaigns/" . $drip_campaign_id . "/deactivate";
$payload = array(
"recipient_address" => $recipient_address
);
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | [
"public",
"function",
"remove_from_drip_campaign",
"(",
"$",
"recipient_address",
",",
"$",
"drip_campaign_id",
")",
"{",
"$",
"endpoint",
"=",
"\"drip_campaigns/\"",
".",
"$",
"drip_campaign_id",
".",
"\"/deactivate\"",
";",
"$",
"payload",
"=",
"array",
"(",
"\"recipient_address\"",
"=>",
"$",
"recipient_address",
")",
";",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_POST",
",",
"$",
"payload",
")",
";",
"}"
]
| Remove customer from drip campaign
@param string $recipient_address email address being removed drip campaign
@param string $drip_campaign_id drip campaign being removed to
@return array API response object | [
"Remove",
"customer",
"from",
"drip",
"campaign"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L449-L457 | train |
sendwithus/sendwithus_php | lib/API.php | API.remove_from_all_drip_campaigns | public function remove_from_all_drip_campaigns($recipient_address){
$endpoint = "drip_campaigns/deactivate";
$payload = array(
"recipient_address" => $recipient_address
);
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | php | public function remove_from_all_drip_campaigns($recipient_address){
$endpoint = "drip_campaigns/deactivate";
$payload = array(
"recipient_address" => $recipient_address
);
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | [
"public",
"function",
"remove_from_all_drip_campaigns",
"(",
"$",
"recipient_address",
")",
"{",
"$",
"endpoint",
"=",
"\"drip_campaigns/deactivate\"",
";",
"$",
"payload",
"=",
"array",
"(",
"\"recipient_address\"",
"=>",
"$",
"recipient_address",
")",
";",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_POST",
",",
"$",
"payload",
")",
";",
"}"
]
| Remove customer from all drip campaigns
@param string $recipient_address email address being removed from all drip campaigns
@return array API response object | [
"Remove",
"customer",
"from",
"all",
"drip",
"campaigns"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L465-L473 | train |
sendwithus/sendwithus_php | lib/API.php | API.start_batch | public function start_batch() {
return new BatchAPI(
$this->API_KEY,
array(
'API_HOST' => $this->API_HOST,
'API_PROTO' => $this->API_PROTO,
'API_PORT' => $this->API_PORT,
'API_VERSION' => $this->API_VERSION,
'DEBUG' => $this->DEBUG,
)
);
} | php | public function start_batch() {
return new BatchAPI(
$this->API_KEY,
array(
'API_HOST' => $this->API_HOST,
'API_PROTO' => $this->API_PROTO,
'API_PORT' => $this->API_PORT,
'API_VERSION' => $this->API_VERSION,
'DEBUG' => $this->DEBUG,
)
);
} | [
"public",
"function",
"start_batch",
"(",
")",
"{",
"return",
"new",
"BatchAPI",
"(",
"$",
"this",
"->",
"API_KEY",
",",
"array",
"(",
"'API_HOST'",
"=>",
"$",
"this",
"->",
"API_HOST",
",",
"'API_PROTO'",
"=>",
"$",
"this",
"->",
"API_PROTO",
",",
"'API_PORT'",
"=>",
"$",
"this",
"->",
"API_PORT",
",",
"'API_VERSION'",
"=>",
"$",
"this",
"->",
"API_VERSION",
",",
"'DEBUG'",
"=>",
"$",
"this",
"->",
"DEBUG",
",",
")",
")",
";",
"}"
]
| Start Batch API transaction
@return BatchAPI object | [
"Start",
"Batch",
"API",
"transaction"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L480-L491 | train |
sendwithus/sendwithus_php | lib/API.php | API.render | public function render($email_id, $args = null) {
$endpoint = "render";
$payload = array(
"template_id" => $email_id
);
if (is_array($args)) {
$payload = array_merge($args, $payload);
}
if ($this->DEBUG) {
$this->log_message(sprintf(
"rendering template `%s` with \n%s",
$email_id,
print_r($payload, true)
));
}
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | php | public function render($email_id, $args = null) {
$endpoint = "render";
$payload = array(
"template_id" => $email_id
);
if (is_array($args)) {
$payload = array_merge($args, $payload);
}
if ($this->DEBUG) {
$this->log_message(sprintf(
"rendering template `%s` with \n%s",
$email_id,
print_r($payload, true)
));
}
return $this->api_request($endpoint, self::HTTP_POST, $payload);
} | [
"public",
"function",
"render",
"(",
"$",
"email_id",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"endpoint",
"=",
"\"render\"",
";",
"$",
"payload",
"=",
"array",
"(",
"\"template_id\"",
"=>",
"$",
"email_id",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"args",
")",
")",
"{",
"$",
"payload",
"=",
"array_merge",
"(",
"$",
"args",
",",
"$",
"payload",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"DEBUG",
")",
"{",
"$",
"this",
"->",
"log_message",
"(",
"sprintf",
"(",
"\"rendering template `%s` with \\n%s\"",
",",
"$",
"email_id",
",",
"print_r",
"(",
"$",
"payload",
",",
"true",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"api_request",
"(",
"$",
"endpoint",
",",
"self",
"::",
"HTTP_POST",
",",
"$",
"payload",
")",
";",
"}"
]
| Render an email template with the provided data
The additional optional parameters are as follows:
'template_data' - Default is null. Array of variables to merge into the template.
@param string $email_id ID of email to send
@param array $args (optional) additional optional parameters
@return array API response object | [
"Render",
"an",
"email",
"template",
"with",
"the",
"provided",
"data"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L503-L523 | train |
sendwithus/sendwithus_php | lib/API.php | API.encode_attachment | protected function encode_attachment($path) {
if (!is_string($path)) {
$e = sprintf("inline parameter must be path to file as string, received: %s", gettype($path));
throw new API_Error($e);
}
$file_data = file_get_contents($path);
return base64_encode($file_data);
} | php | protected function encode_attachment($path) {
if (!is_string($path)) {
$e = sprintf("inline parameter must be path to file as string, received: %s", gettype($path));
throw new API_Error($e);
}
$file_data = file_get_contents($path);
return base64_encode($file_data);
} | [
"protected",
"function",
"encode_attachment",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"$",
"e",
"=",
"sprintf",
"(",
"\"inline parameter must be path to file as string, received: %s\"",
",",
"gettype",
"(",
"$",
"path",
")",
")",
";",
"throw",
"new",
"API_Error",
"(",
"$",
"e",
")",
";",
"}",
"$",
"file_data",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"return",
"base64_encode",
"(",
"$",
"file_data",
")",
";",
"}"
]
| Helper function to Base64 encode files and return the encoded data
@param string $path Local path of the file to encode
@return string/false the encoded file data or false on failure | [
"Helper",
"function",
"to",
"Base64",
"encode",
"files",
"and",
"return",
"the",
"encoded",
"data"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L531-L540 | train |
sendwithus/sendwithus_php | lib/API.php | API.log_message | protected function log_message($message, $priority_level = self::LOG_DEBUG)
{
if (
$this->DEBUG &&
$this->API_DEBUG_HANDLER &&
is_callable($this->API_DEBUG_HANDLER)
) {
$response = call_user_func($this->API_DEBUG_HANDLER, $message, $priority_level);
} else {
$response = error_log($message);
}
return $response;
} | php | protected function log_message($message, $priority_level = self::LOG_DEBUG)
{
if (
$this->DEBUG &&
$this->API_DEBUG_HANDLER &&
is_callable($this->API_DEBUG_HANDLER)
) {
$response = call_user_func($this->API_DEBUG_HANDLER, $message, $priority_level);
} else {
$response = error_log($message);
}
return $response;
} | [
"protected",
"function",
"log_message",
"(",
"$",
"message",
",",
"$",
"priority_level",
"=",
"self",
"::",
"LOG_DEBUG",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"DEBUG",
"&&",
"$",
"this",
"->",
"API_DEBUG_HANDLER",
"&&",
"is_callable",
"(",
"$",
"this",
"->",
"API_DEBUG_HANDLER",
")",
")",
"{",
"$",
"response",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"API_DEBUG_HANDLER",
",",
"$",
"message",
",",
"$",
"priority_level",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"error_log",
"(",
"$",
"message",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Log debug messages using the custom handler passed as an option in the constructor.
If not handler is defined it falls back to using 'error_log'.
@param $message string the logged message
@param string $priority_level based on syslog priority levels http://php.net/manual/en/function.syslog.php
@return bool true on success or false on failure | [
"Log",
"debug",
"messages",
"using",
"the",
"custom",
"handler",
"passed",
"as",
"an",
"option",
"in",
"the",
"constructor",
".",
"If",
"not",
"handler",
"is",
"defined",
"it",
"falls",
"back",
"to",
"using",
"error_log",
"."
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L640-L653 | train |
sendwithus/sendwithus_php | lib/API.php | BatchAPI.execute | public function execute() {
$endpoint = "batch";
$path = $this->build_path($endpoint);
$ch = curl_init($path);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, self::HTTP_POST);
// set payload
$payload_string = json_encode($this->commands);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_string);
// set headers
$httpheaders = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload_string),
$this->API_HEADER_KEY . ": " . $this->API_KEY,
$this->API_HEADER_CLIENT . ": " . $this->API_CLIENT_STUB
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/data/ca-certificates.pem');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheaders);
if ($this->DEBUG) {
// enable curl verbose output to STDERR
curl_setopt($ch, CURLOPT_VERBOSE, true);
$this->log_message(sprintf("payload: %s\r\npath: %s\r\n", $payload_string, $path));
}
$code = null;
try {
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response = json_decode( $result );
if ($code != 200) {
throw new API_Error("Request was not successful", $code, $result, $response);
}
} catch (API_Error $e) {
if ($this->DEBUG) {
$this->log_message(
sprintf("Caught exception: %s\r\n%s", $e->getMessage(), print_r($e, true)),
self::LOG_ERR
);
}
$response = (object) array(
'code' => $code,
'status' => "error",
'success' => false,
'exception' => $e
);
}
curl_close($ch);
$this->commands = array();
return $response;
} | php | public function execute() {
$endpoint = "batch";
$path = $this->build_path($endpoint);
$ch = curl_init($path);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, self::HTTP_POST);
// set payload
$payload_string = json_encode($this->commands);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_string);
// set headers
$httpheaders = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload_string),
$this->API_HEADER_KEY . ": " . $this->API_KEY,
$this->API_HEADER_CLIENT . ": " . $this->API_CLIENT_STUB
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/data/ca-certificates.pem');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheaders);
if ($this->DEBUG) {
// enable curl verbose output to STDERR
curl_setopt($ch, CURLOPT_VERBOSE, true);
$this->log_message(sprintf("payload: %s\r\npath: %s\r\n", $payload_string, $path));
}
$code = null;
try {
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response = json_decode( $result );
if ($code != 200) {
throw new API_Error("Request was not successful", $code, $result, $response);
}
} catch (API_Error $e) {
if ($this->DEBUG) {
$this->log_message(
sprintf("Caught exception: %s\r\n%s", $e->getMessage(), print_r($e, true)),
self::LOG_ERR
);
}
$response = (object) array(
'code' => $code,
'status' => "error",
'success' => false,
'exception' => $e
);
}
curl_close($ch);
$this->commands = array();
return $response;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"endpoint",
"=",
"\"batch\"",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"build_path",
"(",
"$",
"endpoint",
")",
";",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"path",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"self",
"::",
"HTTP_POST",
")",
";",
"// set payload",
"$",
"payload_string",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"commands",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"payload_string",
")",
";",
"// set headers",
"$",
"httpheaders",
"=",
"array",
"(",
"'Content-Type: application/json'",
",",
"'Content-Length: '",
".",
"strlen",
"(",
"$",
"payload_string",
")",
",",
"$",
"this",
"->",
"API_HEADER_KEY",
".",
"\": \"",
".",
"$",
"this",
"->",
"API_KEY",
",",
"$",
"this",
"->",
"API_HEADER_CLIENT",
".",
"\": \"",
".",
"$",
"this",
"->",
"API_CLIENT_STUB",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CAINFO",
",",
"dirname",
"(",
"__FILE__",
")",
".",
"'/data/ca-certificates.pem'",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"httpheaders",
")",
";",
"if",
"(",
"$",
"this",
"->",
"DEBUG",
")",
"{",
"// enable curl verbose output to STDERR",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_VERBOSE",
",",
"true",
")",
";",
"$",
"this",
"->",
"log_message",
"(",
"sprintf",
"(",
"\"payload: %s\\r\\npath: %s\\r\\n\"",
",",
"$",
"payload_string",
",",
"$",
"path",
")",
")",
";",
"}",
"$",
"code",
"=",
"null",
";",
"try",
"{",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"code",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"code",
"!=",
"200",
")",
"{",
"throw",
"new",
"API_Error",
"(",
"\"Request was not successful\"",
",",
"$",
"code",
",",
"$",
"result",
",",
"$",
"response",
")",
";",
"}",
"}",
"catch",
"(",
"API_Error",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"DEBUG",
")",
"{",
"$",
"this",
"->",
"log_message",
"(",
"sprintf",
"(",
"\"Caught exception: %s\\r\\n%s\"",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"print_r",
"(",
"$",
"e",
",",
"true",
")",
")",
",",
"self",
"::",
"LOG_ERR",
")",
";",
"}",
"$",
"response",
"=",
"(",
"object",
")",
"array",
"(",
"'code'",
"=>",
"$",
"code",
",",
"'status'",
"=>",
"\"error\"",
",",
"'success'",
"=>",
"false",
",",
"'exception'",
"=>",
"$",
"e",
")",
";",
"}",
"curl_close",
"(",
"$",
"ch",
")",
";",
"$",
"this",
"->",
"commands",
"=",
"array",
"(",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Execute all currently queued commands
@return array BatchAPI response object. | [
"Execute",
"all",
"currently",
"queued",
"commands"
]
| 9b96c3f18e05616eed65dce2b2a7fdefb4d563c1 | https://github.com/sendwithus/sendwithus_php/blob/9b96c3f18e05616eed65dce2b2a7fdefb4d563c1/lib/API.php#L695-L757 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthResponse.php | OAuthResponse.hasData | public function hasData($name = null)
{
if ($name !== null) {
return is_array($this->data) && isset($this->data[$name]);
}
return !empty($this->data);
} | php | public function hasData($name = null)
{
if ($name !== null) {
return is_array($this->data) && isset($this->data[$name]);
}
return !empty($this->data);
} | [
"public",
"function",
"hasData",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"{",
"return",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}"
]
| Checks if there is data or a specific data.
@param string $name The data name.
@return boolean TRUE if there is data else FALSE. | [
"Checks",
"if",
"there",
"is",
"data",
"or",
"a",
"specific",
"data",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthResponse.php#L116-L123 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.getHeader | public function getHeader($name)
{
if (!$this->hasHeader($name)) {
throw new \InvalidArgumentException(sprintf('The request header "%s" does not exist.', $name));
}
return $this->headers[$name];
} | php | public function getHeader($name)
{
if (!$this->hasHeader($name)) {
throw new \InvalidArgumentException(sprintf('The request header "%s" does not exist.', $name));
}
return $this->headers[$name];
} | [
"public",
"function",
"getHeader",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasHeader",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The request header \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
";",
"}"
]
| Gets a specific request header.
@param string $name The request header name.
@throws \InvalidArgumentException If the header name does not exist.
@return string The request header value. | [
"Gets",
"a",
"specific",
"request",
"header",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L220-L227 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.removeHeader | public function removeHeader($name)
{
if (!$this->hasHeader($name)) {
throw new \InvalidArgumentException(sprintf('The request header "%s" does not exist.', $name));
}
unset($this->headers[$name]);
} | php | public function removeHeader($name)
{
if (!$this->hasHeader($name)) {
throw new \InvalidArgumentException(sprintf('The request header "%s" does not exist.', $name));
}
unset($this->headers[$name]);
} | [
"public",
"function",
"removeHeader",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasHeader",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The request header \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
";",
"}"
]
| Removes a request header.
@param string $name The request header name.
@throws \InvalidArgumentException If the request header name does not exist. | [
"Removes",
"a",
"request",
"header",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L247-L254 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.getOAuthParameters | public function getOAuthParameters()
{
if (!$this->hasOAuthParameter('oauth_nonce')) {
$this->setOAuthParameter('oauth_nonce', md5(uniqid('widop', true)));
}
if (!$this->hasOAuthParameter('oauth_timestamp')) {
$this->setOAuthParameter('oauth_timestamp', time());
}
return $this->oauthParameters;
} | php | public function getOAuthParameters()
{
if (!$this->hasOAuthParameter('oauth_nonce')) {
$this->setOAuthParameter('oauth_nonce', md5(uniqid('widop', true)));
}
if (!$this->hasOAuthParameter('oauth_timestamp')) {
$this->setOAuthParameter('oauth_timestamp', time());
}
return $this->oauthParameters;
} | [
"public",
"function",
"getOAuthParameters",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOAuthParameter",
"(",
"'oauth_nonce'",
")",
")",
"{",
"$",
"this",
"->",
"setOAuthParameter",
"(",
"'oauth_nonce'",
",",
"md5",
"(",
"uniqid",
"(",
"'widop'",
",",
"true",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOAuthParameter",
"(",
"'oauth_timestamp'",
")",
")",
"{",
"$",
"this",
"->",
"setOAuthParameter",
"(",
"'oauth_timestamp'",
",",
"time",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"oauthParameters",
";",
"}"
]
| Gets the request OAuth parameters.
@return array The request OAuth parameters. | [
"Gets",
"the",
"request",
"OAuth",
"parameters",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L271-L282 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.setOAuthParameters | public function setOAuthParameters(array $oauthParameters)
{
foreach ($oauthParameters as $name => $value) {
$this->setOAuthParameter($name, $value);
}
} | php | public function setOAuthParameters(array $oauthParameters)
{
foreach ($oauthParameters as $name => $value) {
$this->setOAuthParameter($name, $value);
}
} | [
"public",
"function",
"setOAuthParameters",
"(",
"array",
"$",
"oauthParameters",
")",
"{",
"foreach",
"(",
"$",
"oauthParameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setOAuthParameter",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Sets the request OAuth parameters.
@param array $oauthParameters The request OAuth parameters. | [
"Sets",
"the",
"request",
"OAuth",
"parameters",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L289-L294 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.getOAuthParameter | public function getOAuthParameter($name)
{
if (!$this->hasOAuthParameter($name)) {
throw new \InvalidArgumentException(sprintf('The OAuth request parameter "%s" does not exist.', $name));
}
return $this->oauthParameters[rawurlencode($name)];
} | php | public function getOAuthParameter($name)
{
if (!$this->hasOAuthParameter($name)) {
throw new \InvalidArgumentException(sprintf('The OAuth request parameter "%s" does not exist.', $name));
}
return $this->oauthParameters[rawurlencode($name)];
} | [
"public",
"function",
"getOAuthParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOAuthParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The OAuth request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"oauthParameters",
"[",
"rawurlencode",
"(",
"$",
"name",
")",
"]",
";",
"}"
]
| Gets a specific request OAuth parameter.
@param string $name The request OAuth parameter name.
@throws \InvalidArgumentException If the request OAuth parameter name does not exist.
@return string The request OAuth parameter value. | [
"Gets",
"a",
"specific",
"request",
"OAuth",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L317-L324 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.removeOAuthParameter | public function removeOAuthParameter($name)
{
if (!$this->hasOAuthParameter($name)) {
throw new \InvalidArgumentException(sprintf('The OAuth request parameter "%s" does not exist.', $name));
}
unset($this->oauthParameters[rawurlencode($name)]);
} | php | public function removeOAuthParameter($name)
{
if (!$this->hasOAuthParameter($name)) {
throw new \InvalidArgumentException(sprintf('The OAuth request parameter "%s" does not exist.', $name));
}
unset($this->oauthParameters[rawurlencode($name)]);
} | [
"public",
"function",
"removeOAuthParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOAuthParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The OAuth request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"oauthParameters",
"[",
"rawurlencode",
"(",
"$",
"name",
")",
"]",
")",
";",
"}"
]
| Removes a request OAuth parameter.
@param string $name The request OAuth parameter name.
@throws \InvalidArgumentException If the request OAuth parameter name does not exist. | [
"Removes",
"a",
"request",
"OAuth",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L344-L351 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.setPathParameters | public function setPathParameters(array $pathParameters)
{
foreach ($pathParameters as $name => $value) {
$this->setPathParameter($name, $value);
}
} | php | public function setPathParameters(array $pathParameters)
{
foreach ($pathParameters as $name => $value) {
$this->setPathParameter($name, $value);
}
} | [
"public",
"function",
"setPathParameters",
"(",
"array",
"$",
"pathParameters",
")",
"{",
"foreach",
"(",
"$",
"pathParameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setPathParameter",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Sets the request path parameters.
@param array $pathParameters The request path parameters. | [
"Sets",
"the",
"request",
"path",
"parameters",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L378-L383 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.getPathParameter | public function getPathParameter($name)
{
if (!$this->hasPathParameter($name)) {
throw new \InvalidArgumentException(sprintf('The path request parameter "%s" does not exist.', $name));
}
return $this->pathParameters[$name];
} | php | public function getPathParameter($name)
{
if (!$this->hasPathParameter($name)) {
throw new \InvalidArgumentException(sprintf('The path request parameter "%s" does not exist.', $name));
}
return $this->pathParameters[$name];
} | [
"public",
"function",
"getPathParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasPathParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The path request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pathParameters",
"[",
"$",
"name",
"]",
";",
"}"
]
| Gets a specific request path parameter.
@param string $name The request path parameter name.
@throws \InvalidArgumentException If the request path parameter name does not exist.
@return string The request path parameter value. | [
"Gets",
"a",
"specific",
"request",
"path",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L406-L413 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.removePathParameter | public function removePathParameter($name)
{
if (!$this->hasPathParameter($name)) {
throw new \InvalidArgumentException(sprintf('The path request parameter "%s" does not exist.', $name));
}
unset($this->pathParameters[$name]);
} | php | public function removePathParameter($name)
{
if (!$this->hasPathParameter($name)) {
throw new \InvalidArgumentException(sprintf('The path request parameter "%s" does not exist.', $name));
}
unset($this->pathParameters[$name]);
} | [
"public",
"function",
"removePathParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasPathParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The path request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"pathParameters",
"[",
"$",
"name",
"]",
")",
";",
"}"
]
| Removes a specific request path parameter.
@param string $name The request path parameter name.
@throws \InvalidArgumentException If the request path parameter name does not exist. | [
"Removes",
"a",
"specific",
"request",
"path",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L433-L440 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.setGetParameters | public function setGetParameters($getParameters)
{
foreach ($getParameters as $name => $value) {
$this->setGetParameter($name, $value);
}
} | php | public function setGetParameters($getParameters)
{
foreach ($getParameters as $name => $value) {
$this->setGetParameter($name, $value);
}
} | [
"public",
"function",
"setGetParameters",
"(",
"$",
"getParameters",
")",
"{",
"foreach",
"(",
"$",
"getParameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setGetParameter",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Sets the GET request parameters.
@param array $getParameters The GET request parameters. | [
"Sets",
"the",
"GET",
"request",
"parameters",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L467-L472 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.getGetParameter | public function getGetParameter($name)
{
if (!$this->hasGetParameter($name)) {
throw new \InvalidArgumentException(sprintf('The GET request parameter "%s" does not exist.', $name));
}
return $this->getParameters[rawurlencode($name)];
} | php | public function getGetParameter($name)
{
if (!$this->hasGetParameter($name)) {
throw new \InvalidArgumentException(sprintf('The GET request parameter "%s" does not exist.', $name));
}
return $this->getParameters[rawurlencode($name)];
} | [
"public",
"function",
"getGetParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasGetParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The GET request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getParameters",
"[",
"rawurlencode",
"(",
"$",
"name",
")",
"]",
";",
"}"
]
| Gets a specific GET request parameter.
@param string $name The GET request parameter name.
@throws \InvalidArgumentException If the GET parameter does not exist.
@return string The GET request parameter. | [
"Gets",
"a",
"specific",
"GET",
"request",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L495-L502 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.removeGetParameter | public function removeGetParameter($name)
{
if (!$this->hasGetParameter($name)) {
throw new \InvalidArgumentException(sprintf('The GET request parameter "%s" does not exist.', $name));
}
unset($this->getParameters[rawurlencode($name)]);
} | php | public function removeGetParameter($name)
{
if (!$this->hasGetParameter($name)) {
throw new \InvalidArgumentException(sprintf('The GET request parameter "%s" does not exist.', $name));
}
unset($this->getParameters[rawurlencode($name)]);
} | [
"public",
"function",
"removeGetParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasGetParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The GET request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"getParameters",
"[",
"rawurlencode",
"(",
"$",
"name",
")",
"]",
")",
";",
"}"
]
| Removes a request GET parameter.
@param string $name The request GET parameter.
@throws \InvalidArgumentException If the GET parameter does not exist. | [
"Removes",
"a",
"request",
"GET",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L522-L529 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.setPostParameters | public function setPostParameters(array $postParameters)
{
foreach ($postParameters as $name => $value) {
$this->setPostParameter($name, $value);
}
} | php | public function setPostParameters(array $postParameters)
{
foreach ($postParameters as $name => $value) {
$this->setPostParameter($name, $value);
}
} | [
"public",
"function",
"setPostParameters",
"(",
"array",
"$",
"postParameters",
")",
"{",
"foreach",
"(",
"$",
"postParameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setPostParameter",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Sets the POST request parameters.
@param array $postParameters The POST request parameters. | [
"Sets",
"the",
"POST",
"request",
"parameters",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L556-L561 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.getPostParameter | public function getPostParameter($name)
{
if (!$this->hasPostParameter($name)) {
throw new \InvalidArgumentException(sprintf('The POST request parameter "%s" does not exist.', $name));
}
return $this->postParameters[rawurlencode($name)];
} | php | public function getPostParameter($name)
{
if (!$this->hasPostParameter($name)) {
throw new \InvalidArgumentException(sprintf('The POST request parameter "%s" does not exist.', $name));
}
return $this->postParameters[rawurlencode($name)];
} | [
"public",
"function",
"getPostParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasPostParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The POST request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"postParameters",
"[",
"rawurlencode",
"(",
"$",
"name",
")",
"]",
";",
"}"
]
| Gets a request POST parameter.
@param string $name The request POST parameter name.
@throws \InvalidArgumentException If the request POST parameter does not exist.
@return string The request POST parameter. | [
"Gets",
"a",
"request",
"POST",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L584-L591 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.removePostParameter | public function removePostParameter($name)
{
if (!$this->hasPostParameter($name)) {
throw new \InvalidArgumentException(sprintf('The POST request parameter "%s" does not exist.', $name));
}
unset($this->postParameters[rawurlencode($name)]);
} | php | public function removePostParameter($name)
{
if (!$this->hasPostParameter($name)) {
throw new \InvalidArgumentException(sprintf('The POST request parameter "%s" does not exist.', $name));
}
unset($this->postParameters[rawurlencode($name)]);
} | [
"public",
"function",
"removePostParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasPostParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The POST request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"postParameters",
"[",
"rawurlencode",
"(",
"$",
"name",
")",
"]",
")",
";",
"}"
]
| Removes a request POST parameter.
@param string $name The request POST parameter name.
@throws \InvalidArgumentException If the request POST parameter does not exist. | [
"Removes",
"a",
"request",
"POST",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L611-L618 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.setFileParameters | public function setFileParameters(array $fileParameters)
{
foreach ($fileParameters as $name => $value) {
$this->setFileParameter($name, $value);
}
} | php | public function setFileParameters(array $fileParameters)
{
foreach ($fileParameters as $name => $value) {
$this->setFileParameter($name, $value);
}
} | [
"public",
"function",
"setFileParameters",
"(",
"array",
"$",
"fileParameters",
")",
"{",
"foreach",
"(",
"$",
"fileParameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setFileParameter",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Sets the file request parameters.
@param array $fileParameters The file request parameters. | [
"Sets",
"the",
"file",
"request",
"parameters",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L645-L650 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.getFileParameter | public function getFileParameter($name)
{
if (!$this->hasFileParameter($name)) {
throw new \InvalidArgumentException(sprintf('The file request parameter "%s" does not exist.', $name));
}
return $this->fileParameters[$name];
} | php | public function getFileParameter($name)
{
if (!$this->hasFileParameter($name)) {
throw new \InvalidArgumentException(sprintf('The file request parameter "%s" does not exist.', $name));
}
return $this->fileParameters[$name];
} | [
"public",
"function",
"getFileParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasFileParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The file request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"fileParameters",
"[",
"$",
"name",
"]",
";",
"}"
]
| Gets a request file parameter.
@param string $name The request file parameter name.
@throws \InvalidArgumentException If the request file parameter does not exist.
@return string The request file parameter. | [
"Gets",
"a",
"request",
"file",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L673-L680 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.removeFileParameter | public function removeFileParameter($name)
{
if (!$this->hasFileParameter($name)) {
throw new \InvalidArgumentException(sprintf('The file request parameter "%s" does not exist.', $name));
}
unset($this->fileParameters[$name]);
} | php | public function removeFileParameter($name)
{
if (!$this->hasFileParameter($name)) {
throw new \InvalidArgumentException(sprintf('The file request parameter "%s" does not exist.', $name));
}
unset($this->fileParameters[$name]);
} | [
"public",
"function",
"removeFileParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasFileParameter",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The file request parameter \"%s\" does not exist.'",
",",
"$",
"name",
")",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"fileParameters",
"[",
"$",
"name",
"]",
")",
";",
"}"
]
| Removes a request file parameter.
@param string $name The request file parameter name.
@throws \InvalidArgumentException If the request file parameter does not exist. | [
"Removes",
"a",
"request",
"file",
"parameter",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L700-L707 | train |
widop/twitter-oauth | src/Widop/Twitter/OAuth/OAuthRequest.php | OAuthRequest.getSignature | public function getSignature()
{
if ($this->hasFileParameters()) {
$elements = $this->getOAuthParameters();
} else {
$elements = array_merge(
$this->getOAuthParameters(),
$this->getGetParameters(),
$this->getPostParameters()
);
}
ksort($elements);
$stringSignature = array();
foreach ($elements as $key => $value) {
$stringSignature[] = sprintf('%s=%s', $key, $value);
}
$signature = array(
$this->getMethod(),
rawurlencode($this->getSignatureUrl()),
rawurlencode(implode('&', $stringSignature)),
);
return implode('&', $signature);
} | php | public function getSignature()
{
if ($this->hasFileParameters()) {
$elements = $this->getOAuthParameters();
} else {
$elements = array_merge(
$this->getOAuthParameters(),
$this->getGetParameters(),
$this->getPostParameters()
);
}
ksort($elements);
$stringSignature = array();
foreach ($elements as $key => $value) {
$stringSignature[] = sprintf('%s=%s', $key, $value);
}
$signature = array(
$this->getMethod(),
rawurlencode($this->getSignatureUrl()),
rawurlencode(implode('&', $stringSignature)),
);
return implode('&', $signature);
} | [
"public",
"function",
"getSignature",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasFileParameters",
"(",
")",
")",
"{",
"$",
"elements",
"=",
"$",
"this",
"->",
"getOAuthParameters",
"(",
")",
";",
"}",
"else",
"{",
"$",
"elements",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getOAuthParameters",
"(",
")",
",",
"$",
"this",
"->",
"getGetParameters",
"(",
")",
",",
"$",
"this",
"->",
"getPostParameters",
"(",
")",
")",
";",
"}",
"ksort",
"(",
"$",
"elements",
")",
";",
"$",
"stringSignature",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"stringSignature",
"[",
"]",
"=",
"sprintf",
"(",
"'%s=%s'",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"signature",
"=",
"array",
"(",
"$",
"this",
"->",
"getMethod",
"(",
")",
",",
"rawurlencode",
"(",
"$",
"this",
"->",
"getSignatureUrl",
"(",
")",
")",
",",
"rawurlencode",
"(",
"implode",
"(",
"'&'",
",",
"$",
"stringSignature",
")",
")",
",",
")",
";",
"return",
"implode",
"(",
"'&'",
",",
"$",
"signature",
")",
";",
"}"
]
| Gets the request signature.
@return string The request signature. | [
"Gets",
"the",
"request",
"signature",
"."
]
| 2fb30fdef1e7934b28adc19dae0eb47e4c672891 | https://github.com/widop/twitter-oauth/blob/2fb30fdef1e7934b28adc19dae0eb47e4c672891/src/Widop/Twitter/OAuth/OAuthRequest.php#L734-L760 | train |
akDeveloper/Aktive-Merchant | lib/AktiveMerchant/Common/Country.php | Country.find | public static function find($name)
{
if (empty($name)) {
throw new \InvalidArgumentException('Cannot lookup country for an empty name');
}
if (strlen($name) == 2 || strlen($name) == 3) {
$upcase_name = strtoupper($name);
$country_code = new CountryCode($name);
$country_format = $country_code->getFormat();
foreach (self::$COUNTRIES as $c) {
if ($c[$country_format] == $upcase_name) {
$country = $c;
break;
}
}
} else {
foreach (self::$COUNTRIES as $c) {
if ($c['name'] == $name) {
$country = $c;
break;
}
}
}
if (!isset($country)) {
throw new \OutOfRangeException("No country could be found for name {$name}");
}
return new Country($country);
} | php | public static function find($name)
{
if (empty($name)) {
throw new \InvalidArgumentException('Cannot lookup country for an empty name');
}
if (strlen($name) == 2 || strlen($name) == 3) {
$upcase_name = strtoupper($name);
$country_code = new CountryCode($name);
$country_format = $country_code->getFormat();
foreach (self::$COUNTRIES as $c) {
if ($c[$country_format] == $upcase_name) {
$country = $c;
break;
}
}
} else {
foreach (self::$COUNTRIES as $c) {
if ($c['name'] == $name) {
$country = $c;
break;
}
}
}
if (!isset($country)) {
throw new \OutOfRangeException("No country could be found for name {$name}");
}
return new Country($country);
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Cannot lookup country for an empty name'",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"name",
")",
"==",
"2",
"||",
"strlen",
"(",
"$",
"name",
")",
"==",
"3",
")",
"{",
"$",
"upcase_name",
"=",
"strtoupper",
"(",
"$",
"name",
")",
";",
"$",
"country_code",
"=",
"new",
"CountryCode",
"(",
"$",
"name",
")",
";",
"$",
"country_format",
"=",
"$",
"country_code",
"->",
"getFormat",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"COUNTRIES",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"c",
"[",
"$",
"country_format",
"]",
"==",
"$",
"upcase_name",
")",
"{",
"$",
"country",
"=",
"$",
"c",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"self",
"::",
"$",
"COUNTRIES",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"c",
"[",
"'name'",
"]",
"==",
"$",
"name",
")",
"{",
"$",
"country",
"=",
"$",
"c",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"country",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfRangeException",
"(",
"\"No country could be found for name {$name}\"",
")",
";",
"}",
"return",
"new",
"Country",
"(",
"$",
"country",
")",
";",
"}"
]
| Returns a Country object based on a given alpha or numeric code.
<code>
$country = Country::find(300);
$country = Country::find('GR');
$country = Country::find('GRC');
</code>
@param string|integer Alpha name or numeric code of a country
@return Country A Country object. | [
"Returns",
"a",
"Country",
"object",
"based",
"on",
"a",
"given",
"alpha",
"or",
"numeric",
"code",
"."
]
| 00df4840e732ed1938a0a1718dfb50d67119d9a1 | https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Common/Country.php#L93-L122 | train |
akDeveloper/Aktive-Merchant | lib/AktiveMerchant/Common/Address.php | Address.getMappedFields | public function getMappedFields()
{
$mapped = array();
foreach ($this->fields as $key => $value) {
if (array_key_exists($key, $this->mappings)) {
$map = $this->mappings[$key];
$mapped[$map] = $value;
}
}
return $mapped;
} | php | public function getMappedFields()
{
$mapped = array();
foreach ($this->fields as $key => $value) {
if (array_key_exists($key, $this->mappings)) {
$map = $this->mappings[$key];
$mapped[$map] = $value;
}
}
return $mapped;
} | [
"public",
"function",
"getMappedFields",
"(",
")",
"{",
"$",
"mapped",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"mappings",
")",
")",
"{",
"$",
"map",
"=",
"$",
"this",
"->",
"mappings",
"[",
"$",
"key",
"]",
";",
"$",
"mapped",
"[",
"$",
"map",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"mapped",
";",
"}"
]
| Gets an array with mapped address fields.
@access public
@return array | [
"Gets",
"an",
"array",
"with",
"mapped",
"address",
"fields",
"."
]
| 00df4840e732ed1938a0a1718dfb50d67119d9a1 | https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Common/Address.php#L111-L123 | train |
joomla-framework/filesystem | src/Helper.php | Helper.remotefsize | public static function remotefsize($url)
{
$sch = parse_url($url, PHP_URL_SCHEME);
if (!\in_array($sch, array('http', 'https', 'ftp', 'ftps'), true))
{
return false;
}
if (\in_array($sch, array('http', 'https'), true))
{
$headers = @ get_headers($url, 1);
if (!$headers || (!array_key_exists('Content-Length', $headers)))
{
return false;
}
return $headers['Content-Length'];
}
if (\in_array($sch, array('ftp', 'ftps'), true))
{
$server = parse_url($url, PHP_URL_HOST);
$port = parse_url($url, PHP_URL_PORT);
$path = parse_url($url, PHP_URL_PATH);
$user = parse_url($url, PHP_URL_USER);
$pass = parse_url($url, PHP_URL_PASS);
if ((!$server) || (!$path))
{
return false;
}
if (!$port)
{
$port = 21;
}
if (!$user)
{
$user = 'anonymous';
}
if (!$pass)
{
$pass = '';
}
$ftpid = null;
switch ($sch)
{
case 'ftp':
$ftpid = @ftp_connect($server, $port);
break;
case 'ftps':
$ftpid = @ftp_ssl_connect($server, $port);
break;
}
if (!$ftpid)
{
return false;
}
$login = @ftp_login($ftpid, $user, $pass);
if (!$login)
{
return false;
}
$ftpsize = ftp_size($ftpid, $path);
ftp_close($ftpid);
if ($ftpsize == -1)
{
return false;
}
return $ftpsize;
}
} | php | public static function remotefsize($url)
{
$sch = parse_url($url, PHP_URL_SCHEME);
if (!\in_array($sch, array('http', 'https', 'ftp', 'ftps'), true))
{
return false;
}
if (\in_array($sch, array('http', 'https'), true))
{
$headers = @ get_headers($url, 1);
if (!$headers || (!array_key_exists('Content-Length', $headers)))
{
return false;
}
return $headers['Content-Length'];
}
if (\in_array($sch, array('ftp', 'ftps'), true))
{
$server = parse_url($url, PHP_URL_HOST);
$port = parse_url($url, PHP_URL_PORT);
$path = parse_url($url, PHP_URL_PATH);
$user = parse_url($url, PHP_URL_USER);
$pass = parse_url($url, PHP_URL_PASS);
if ((!$server) || (!$path))
{
return false;
}
if (!$port)
{
$port = 21;
}
if (!$user)
{
$user = 'anonymous';
}
if (!$pass)
{
$pass = '';
}
$ftpid = null;
switch ($sch)
{
case 'ftp':
$ftpid = @ftp_connect($server, $port);
break;
case 'ftps':
$ftpid = @ftp_ssl_connect($server, $port);
break;
}
if (!$ftpid)
{
return false;
}
$login = @ftp_login($ftpid, $user, $pass);
if (!$login)
{
return false;
}
$ftpsize = ftp_size($ftpid, $path);
ftp_close($ftpid);
if ($ftpsize == -1)
{
return false;
}
return $ftpsize;
}
} | [
"public",
"static",
"function",
"remotefsize",
"(",
"$",
"url",
")",
"{",
"$",
"sch",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_SCHEME",
")",
";",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"sch",
",",
"array",
"(",
"'http'",
",",
"'https'",
",",
"'ftp'",
",",
"'ftps'",
")",
",",
"true",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"sch",
",",
"array",
"(",
"'http'",
",",
"'https'",
")",
",",
"true",
")",
")",
"{",
"$",
"headers",
"=",
"@",
"get_headers",
"(",
"$",
"url",
",",
"1",
")",
";",
"if",
"(",
"!",
"$",
"headers",
"||",
"(",
"!",
"array_key_exists",
"(",
"'Content-Length'",
",",
"$",
"headers",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"headers",
"[",
"'Content-Length'",
"]",
";",
"}",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"sch",
",",
"array",
"(",
"'ftp'",
",",
"'ftps'",
")",
",",
"true",
")",
")",
"{",
"$",
"server",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_HOST",
")",
";",
"$",
"port",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_PORT",
")",
";",
"$",
"path",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_PATH",
")",
";",
"$",
"user",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_USER",
")",
";",
"$",
"pass",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_PASS",
")",
";",
"if",
"(",
"(",
"!",
"$",
"server",
")",
"||",
"(",
"!",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"port",
")",
"{",
"$",
"port",
"=",
"21",
";",
"}",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"$",
"user",
"=",
"'anonymous'",
";",
"}",
"if",
"(",
"!",
"$",
"pass",
")",
"{",
"$",
"pass",
"=",
"''",
";",
"}",
"$",
"ftpid",
"=",
"null",
";",
"switch",
"(",
"$",
"sch",
")",
"{",
"case",
"'ftp'",
":",
"$",
"ftpid",
"=",
"@",
"ftp_connect",
"(",
"$",
"server",
",",
"$",
"port",
")",
";",
"break",
";",
"case",
"'ftps'",
":",
"$",
"ftpid",
"=",
"@",
"ftp_ssl_connect",
"(",
"$",
"server",
",",
"$",
"port",
")",
";",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"ftpid",
")",
"{",
"return",
"false",
";",
"}",
"$",
"login",
"=",
"@",
"ftp_login",
"(",
"$",
"ftpid",
",",
"$",
"user",
",",
"$",
"pass",
")",
";",
"if",
"(",
"!",
"$",
"login",
")",
"{",
"return",
"false",
";",
"}",
"$",
"ftpsize",
"=",
"ftp_size",
"(",
"$",
"ftpid",
",",
"$",
"path",
")",
";",
"ftp_close",
"(",
"$",
"ftpid",
")",
";",
"if",
"(",
"$",
"ftpsize",
"==",
"-",
"1",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"ftpsize",
";",
"}",
"}"
]
| Remote file size function for streams that don't support it
@param string $url TODO Add text
@return mixed
@link https://www.php.net/manual/en/function.filesize.php#71098
@since 1.0 | [
"Remote",
"file",
"size",
"function",
"for",
"streams",
"that",
"don",
"t",
"support",
"it"
]
| c3682aabfb64a68ca1e1409c4c76b55968c9cd15 | https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Helper.php#L30-L116 | train |
joomla-framework/filesystem | src/Folder.php | Folder.folders | public static function folders($path, $filter = '.', $recurse = false, $full = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'),
$excludeFilter = array('^\..*')
)
{
// Check to make sure the path valid and clean
$path = Path::clean($path);
// Is the path a folder?
if (!is_dir($path))
{
throw new \UnexpectedValueException(sprintf('%1$s: Path is not a folder. Path: %2$s', __METHOD__, $path));
}
// Compute the excludefilter string
if (\count($excludeFilter))
{
$excludeFilterString = '/(' . implode('|', $excludeFilter) . ')/';
}
else
{
$excludeFilterString = '';
}
// Get the folders
$arr = self::_items($path, $filter, $recurse, $full, $exclude, $excludeFilterString, false);
// Sort the folders
asort($arr);
return array_values($arr);
} | php | public static function folders($path, $filter = '.', $recurse = false, $full = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'),
$excludeFilter = array('^\..*')
)
{
// Check to make sure the path valid and clean
$path = Path::clean($path);
// Is the path a folder?
if (!is_dir($path))
{
throw new \UnexpectedValueException(sprintf('%1$s: Path is not a folder. Path: %2$s', __METHOD__, $path));
}
// Compute the excludefilter string
if (\count($excludeFilter))
{
$excludeFilterString = '/(' . implode('|', $excludeFilter) . ')/';
}
else
{
$excludeFilterString = '';
}
// Get the folders
$arr = self::_items($path, $filter, $recurse, $full, $exclude, $excludeFilterString, false);
// Sort the folders
asort($arr);
return array_values($arr);
} | [
"public",
"static",
"function",
"folders",
"(",
"$",
"path",
",",
"$",
"filter",
"=",
"'.'",
",",
"$",
"recurse",
"=",
"false",
",",
"$",
"full",
"=",
"false",
",",
"$",
"exclude",
"=",
"array",
"(",
"'.svn'",
",",
"'CVS'",
",",
"'.DS_Store'",
",",
"'__MACOSX'",
")",
",",
"$",
"excludeFilter",
"=",
"array",
"(",
"'^\\..*'",
")",
")",
"{",
"// Check to make sure the path valid and clean",
"$",
"path",
"=",
"Path",
"::",
"clean",
"(",
"$",
"path",
")",
";",
"// Is the path a folder?",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'%1$s: Path is not a folder. Path: %2$s'",
",",
"__METHOD__",
",",
"$",
"path",
")",
")",
";",
"}",
"// Compute the excludefilter string",
"if",
"(",
"\\",
"count",
"(",
"$",
"excludeFilter",
")",
")",
"{",
"$",
"excludeFilterString",
"=",
"'/('",
".",
"implode",
"(",
"'|'",
",",
"$",
"excludeFilter",
")",
".",
"')/'",
";",
"}",
"else",
"{",
"$",
"excludeFilterString",
"=",
"''",
";",
"}",
"// Get the folders",
"$",
"arr",
"=",
"self",
"::",
"_items",
"(",
"$",
"path",
",",
"$",
"filter",
",",
"$",
"recurse",
",",
"$",
"full",
",",
"$",
"exclude",
",",
"$",
"excludeFilterString",
",",
"false",
")",
";",
"// Sort the folders",
"asort",
"(",
"$",
"arr",
")",
";",
"return",
"array_values",
"(",
"$",
"arr",
")",
";",
"}"
]
| Utility function to read the folders in a folder.
@param string $path The path of the folder to read.
@param string $filter A filter for folder names.
@param mixed $recurse True to recursively search into sub-folders, or an integer to specify the maximum depth.
@param boolean $full True to return the full path to the folders.
@param array $exclude Array with names of folders which should not be shown in the result.
@param array $excludeFilter Array with regular expressions matching folders which should not be shown in the result.
@return array Folders in the given folder.
@since 1.0
@throws \UnexpectedValueException | [
"Utility",
"function",
"to",
"read",
"the",
"folders",
"in",
"a",
"folder",
"."
]
| c3682aabfb64a68ca1e1409c4c76b55968c9cd15 | https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Folder.php#L405-L435 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/Socket.php | Socket.send | function send($msg, $type = '')
{
// Set a short timeout to prevent long hangs
stream_set_timeout($this->handle, 2);
// Send message over connection
fwrite($this->handle, $msg);
// Check what type is required
if ($type == 'array') {
// If array loop and create array
$response = array();
$line_num = 0;
while (!feof($this->handle)) {
if (($response[$line_num] = fgets($this->handle, 4096)) === false) {
break;
} else {
$line_num++;
}
}
// Return response as array
return $response;
} elseif ($type == 'string') {
// If string, loop and create string
$response = '';
while (!feof($this->handle)) {
$response .= fgets($this->handle, 4096);
}
// Return response as string
return $response;
} else {
// If anything else, return nothing but a true
return true;
}
} | php | function send($msg, $type = '')
{
// Set a short timeout to prevent long hangs
stream_set_timeout($this->handle, 2);
// Send message over connection
fwrite($this->handle, $msg);
// Check what type is required
if ($type == 'array') {
// If array loop and create array
$response = array();
$line_num = 0;
while (!feof($this->handle)) {
if (($response[$line_num] = fgets($this->handle, 4096)) === false) {
break;
} else {
$line_num++;
}
}
// Return response as array
return $response;
} elseif ($type == 'string') {
// If string, loop and create string
$response = '';
while (!feof($this->handle)) {
$response .= fgets($this->handle, 4096);
}
// Return response as string
return $response;
} else {
// If anything else, return nothing but a true
return true;
}
} | [
"function",
"send",
"(",
"$",
"msg",
",",
"$",
"type",
"=",
"''",
")",
"{",
"// Set a short timeout to prevent long hangs\r",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"handle",
",",
"2",
")",
";",
"// Send message over connection\r",
"fwrite",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"msg",
")",
";",
"// Check what type is required\r",
"if",
"(",
"$",
"type",
"==",
"'array'",
")",
"{",
"// If array loop and create array\r",
"$",
"response",
"=",
"array",
"(",
")",
";",
"$",
"line_num",
"=",
"0",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"handle",
")",
")",
"{",
"if",
"(",
"(",
"$",
"response",
"[",
"$",
"line_num",
"]",
"=",
"fgets",
"(",
"$",
"this",
"->",
"handle",
",",
"4096",
")",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"else",
"{",
"$",
"line_num",
"++",
";",
"}",
"}",
"// Return response as array\r",
"return",
"$",
"response",
";",
"}",
"elseif",
"(",
"$",
"type",
"==",
"'string'",
")",
"{",
"// If string, loop and create string\r",
"$",
"response",
"=",
"''",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"handle",
")",
")",
"{",
"$",
"response",
".=",
"fgets",
"(",
"$",
"this",
"->",
"handle",
",",
"4096",
")",
";",
"}",
"// Return response as string\r",
"return",
"$",
"response",
";",
"}",
"else",
"{",
"// If anything else, return nothing but a true\r",
"return",
"true",
";",
"}",
"}"
]
| Send data through the socket and listen for a return
@param string $msg Data to send
@param string $type The type of data to return (array or string)
@return string|array | [
"Send",
"data",
"through",
"the",
"socket",
"and",
"listen",
"for",
"a",
"return"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/Socket.php#L69-L102 | train |
akDeveloper/Aktive-Merchant | lib/AktiveMerchant/Billing/Gateways/Eway.php | Eway.authorize | public function authorize($money, CreditCard $creditcard, $options = array())
{
$this->required_options('address,order_id', $options);
$this->post = array();
$this->addInvoice($options);
$this->addCreditcard($creditcard);
$this->addAddress($options);
$this->addCustomerData($options);
$this->addOptionalData();
$this->post['TotalAmount'] = $this->amount($money);
return $this->commit('xmlauth', $money, $options);
} | php | public function authorize($money, CreditCard $creditcard, $options = array())
{
$this->required_options('address,order_id', $options);
$this->post = array();
$this->addInvoice($options);
$this->addCreditcard($creditcard);
$this->addAddress($options);
$this->addCustomerData($options);
$this->addOptionalData();
$this->post['TotalAmount'] = $this->amount($money);
return $this->commit('xmlauth', $money, $options);
} | [
"public",
"function",
"authorize",
"(",
"$",
"money",
",",
"CreditCard",
"$",
"creditcard",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"required_options",
"(",
"'address,order_id'",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"post",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"addInvoice",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"addCreditcard",
"(",
"$",
"creditcard",
")",
";",
"$",
"this",
"->",
"addAddress",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"addCustomerData",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"addOptionalData",
"(",
")",
";",
"$",
"this",
"->",
"post",
"[",
"'TotalAmount'",
"]",
"=",
"$",
"this",
"->",
"amount",
"(",
"$",
"money",
")",
";",
"return",
"$",
"this",
"->",
"commit",
"(",
"'xmlauth'",
",",
"$",
"money",
",",
"$",
"options",
")",
";",
"}"
]
| Binds the given amount to customer creditcard
creditcard is not charged yet. a capture action required for charging the
creditcard.
@param number $money
@param CreditCard $creditcard
@param array $options
@return Response | [
"Binds",
"the",
"given",
"amount",
"to",
"customer",
"creditcard"
]
| 00df4840e732ed1938a0a1718dfb50d67119d9a1 | https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Eway.php#L122-L137 | train |
akDeveloper/Aktive-Merchant | lib/AktiveMerchant/Billing/Gateways/Eway.php | Eway.capture | public function capture($money, $authorization, $options = array())
{
$this->required_options("order_id", $options);
$this->post = array(
"AuthTrxnNumber" => $authorization,
"TotalAmount" => $this->amount($money)
);
$cc = new CreditCard(array());
$this->addCreditcard($cc);
#$this->addInvoice($options);
$this->addOptionalData();
return $this->commit("xmlauthcomplete", $money);
} | php | public function capture($money, $authorization, $options = array())
{
$this->required_options("order_id", $options);
$this->post = array(
"AuthTrxnNumber" => $authorization,
"TotalAmount" => $this->amount($money)
);
$cc = new CreditCard(array());
$this->addCreditcard($cc);
#$this->addInvoice($options);
$this->addOptionalData();
return $this->commit("xmlauthcomplete", $money);
} | [
"public",
"function",
"capture",
"(",
"$",
"money",
",",
"$",
"authorization",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"required_options",
"(",
"\"order_id\"",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"post",
"=",
"array",
"(",
"\"AuthTrxnNumber\"",
"=>",
"$",
"authorization",
",",
"\"TotalAmount\"",
"=>",
"$",
"this",
"->",
"amount",
"(",
"$",
"money",
")",
")",
";",
"$",
"cc",
"=",
"new",
"CreditCard",
"(",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"addCreditcard",
"(",
"$",
"cc",
")",
";",
"#$this->addInvoice($options);",
"$",
"this",
"->",
"addOptionalData",
"(",
")",
";",
"return",
"$",
"this",
"->",
"commit",
"(",
"\"xmlauthcomplete\"",
",",
"$",
"money",
")",
";",
"}"
]
| Captures the given amount which was previously authorized
Doesn't use authorization here for consistency with authorize (uses order_id instead)
@param number $money
@param string $authorization ignored
@param array $options
@return Response | [
"Captures",
"the",
"given",
"amount",
"which",
"was",
"previously",
"authorized"
]
| 00df4840e732ed1938a0a1718dfb50d67119d9a1 | https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Eway.php#L150-L164 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/MySqlResult.php | MySqlResult.fetch | public function fetch()
{
if ($row = mysql_fetch_array($this->query)) {
return $row;
} else if ($this->size() > 0) {
mysql_data_seek($this->query, 0);
return false;
} else {
return false;
}
} | php | public function fetch()
{
if ($row = mysql_fetch_array($this->query)) {
return $row;
} else if ($this->size() > 0) {
mysql_data_seek($this->query, 0);
return false;
} else {
return false;
}
} | [
"public",
"function",
"fetch",
"(",
")",
"{",
"if",
"(",
"$",
"row",
"=",
"mysql_fetch_array",
"(",
"$",
"this",
"->",
"query",
")",
")",
"{",
"return",
"$",
"row",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"size",
"(",
")",
">",
"0",
")",
"{",
"mysql_data_seek",
"(",
"$",
"this",
"->",
"query",
",",
"0",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Fetches the next result
@return array | [
"Fetches",
"the",
"next",
"result"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/MySqlResult.php#L41-L51 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getFriends | public function getFriends($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getfriends',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->friends->user) > 0) {
$i = 0;
foreach ($call->friends->user as $user) {
$friends[$i]['name'] = (string) $user->name;
$friends[$i]['images']['small'] = (string) $user->image[0];
$friends[$i]['images']['medium'] = (string) $user->image[1];
$friends[$i]['images']['large'] = (string) $user->image[2];
$friends[$i]['url'] = (string) $user->url;
if (!empty($recentTracks)) {
$friends[$i]['recenttrack']['artist']['name'] = (string) $user->recenttrack->artist->name;
$friends[$i]['recenttrack']['artist']['mbid'] = (string) $user->recenttrack->artist->mbid;
$friends[$i]['recenttrack']['artist']['url'] = (string) $user->recenttrack->artist->url;
$friends[$i]['recenttrack']['name'] = (string) $user->recenttrack->name;
$friends[$i]['recenttrack']['mbid'] = (string) $user->recenttrack->mbid;
$friends[$i]['recenttrack']['url'] = (string) $user->recenttrack->url;
}
$i++;
}
return $friends;
} else {
throw new NoResultsException('This user has no friends');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getFriends($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getfriends',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->friends->user) > 0) {
$i = 0;
foreach ($call->friends->user as $user) {
$friends[$i]['name'] = (string) $user->name;
$friends[$i]['images']['small'] = (string) $user->image[0];
$friends[$i]['images']['medium'] = (string) $user->image[1];
$friends[$i]['images']['large'] = (string) $user->image[2];
$friends[$i]['url'] = (string) $user->url;
if (!empty($recentTracks)) {
$friends[$i]['recenttrack']['artist']['name'] = (string) $user->recenttrack->artist->name;
$friends[$i]['recenttrack']['artist']['mbid'] = (string) $user->recenttrack->artist->mbid;
$friends[$i]['recenttrack']['artist']['url'] = (string) $user->recenttrack->artist->url;
$friends[$i]['recenttrack']['name'] = (string) $user->recenttrack->name;
$friends[$i]['recenttrack']['mbid'] = (string) $user->recenttrack->mbid;
$friends[$i]['recenttrack']['url'] = (string) $user->recenttrack->url;
}
$i++;
}
return $friends;
} else {
throw new NoResultsException('This user has no friends');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getFriends",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getfriends'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"call",
"->",
"friends",
"->",
"user",
")",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"friends",
"->",
"user",
"as",
"$",
"user",
")",
"{",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"name",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'small'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"image",
"[",
"0",
"]",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'medium'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"image",
"[",
"1",
"]",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'large'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"image",
"[",
"2",
"]",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"url",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"recentTracks",
")",
")",
"{",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'recenttrack'",
"]",
"[",
"'artist'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"recenttrack",
"->",
"artist",
"->",
"name",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'recenttrack'",
"]",
"[",
"'artist'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"recenttrack",
"->",
"artist",
"->",
"mbid",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'recenttrack'",
"]",
"[",
"'artist'",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"recenttrack",
"->",
"artist",
"->",
"url",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'recenttrack'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"recenttrack",
"->",
"name",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'recenttrack'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"recenttrack",
"->",
"mbid",
";",
"$",
"friends",
"[",
"$",
"i",
"]",
"[",
"'recenttrack'",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"recenttrack",
"->",
"url",
";",
"}",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"friends",
";",
"}",
"else",
"{",
"throw",
"new",
"NoResultsException",
"(",
"'This user has no friends'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get a list of the user's friends on Last.fm
@param array $methodVars An array with the following required values: <i>user</i>
@return array | [
"Get",
"a",
"list",
"of",
"the",
"user",
"s",
"friends",
"on",
"Last",
".",
"fm"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L79-L119 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getLovedTracks | public function getLovedTracks($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getlovedtracks',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->lovedtracks->track) > 0) {
$i = 0;
foreach ($call->lovedtracks->track as $track) {
$lovedTracks[$i]['name'] = (string) $track->name;
$lovedTracks[$i]['mbid'] = (string) $track->mbid;
$lovedTracks[$i]['url'] = (string) $track->url;
$lovedTracks[$i]['date'] = (string) $track->date['uts'];
$lovedTracks[$i]['artist']['name'] = (string) $track->artist->name;
$lovedTracks[$i]['artist']['mbid'] = (string) $track->artist->mbid;
$lovedTracks[$i]['artist']['url'] = (string) $track->artist->url;
$lovedTracks[$i]['images']['small'] = (string) $track->image[0];
$lovedTracks[$i]['images']['medium'] = (string) $track->image[1];
$lovedTracks[$i]['images']['large'] = (string) $track->image[2];
$i++;
}
return $lovedTracks;
} else {
throw new NoResultsException('This user has no loved tracks');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getLovedTracks($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getlovedtracks',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->lovedtracks->track) > 0) {
$i = 0;
foreach ($call->lovedtracks->track as $track) {
$lovedTracks[$i]['name'] = (string) $track->name;
$lovedTracks[$i]['mbid'] = (string) $track->mbid;
$lovedTracks[$i]['url'] = (string) $track->url;
$lovedTracks[$i]['date'] = (string) $track->date['uts'];
$lovedTracks[$i]['artist']['name'] = (string) $track->artist->name;
$lovedTracks[$i]['artist']['mbid'] = (string) $track->artist->mbid;
$lovedTracks[$i]['artist']['url'] = (string) $track->artist->url;
$lovedTracks[$i]['images']['small'] = (string) $track->image[0];
$lovedTracks[$i]['images']['medium'] = (string) $track->image[1];
$lovedTracks[$i]['images']['large'] = (string) $track->image[2];
$i++;
}
return $lovedTracks;
} else {
throw new NoResultsException('This user has no loved tracks');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getLovedTracks",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getlovedtracks'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"call",
"->",
"lovedtracks",
"->",
"track",
")",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"lovedtracks",
"->",
"track",
"as",
"$",
"track",
")",
"{",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"name",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"mbid",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"url",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'date'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"date",
"[",
"'uts'",
"]",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
"->",
"name",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
"->",
"mbid",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
"->",
"url",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'small'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"0",
"]",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'medium'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"1",
"]",
";",
"$",
"lovedTracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'large'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"2",
"]",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"lovedTracks",
";",
"}",
"else",
"{",
"throw",
"new",
"NoResultsException",
"(",
"'This user has no loved tracks'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get the last 50 tracks loved by a user
@param array $methodVars An array with the following required values: <i>user</i>
@return array | [
"Get",
"the",
"last",
"50",
"tracks",
"loved",
"by",
"a",
"user"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L166-L203 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getNeighbours | public function getNeighbours($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getneighbours',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if (!empty($methodVars['limit'])) {
$vars['limit'] = $methodVars['limit'];
}
if ($call = $this->apiGetCall($vars)) {
if (count($call->neighbours->user) > 0) {
$i = 0;
foreach ($call->neighbours->user as $user) {
$neighbours[$i]['name'] = (string) $user->name;
$neighbours[$i]['url'] = (string) $user->url;
$neighbours[$i]['image'] = (string) $user->image;
$neighbours[$i]['match'] = (string) $user->match;
$i++;
}
return $neighbours;
} else {
throw new NoResultsException('This user has no neighbours');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getNeighbours($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getneighbours',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if (!empty($methodVars['limit'])) {
$vars['limit'] = $methodVars['limit'];
}
if ($call = $this->apiGetCall($vars)) {
if (count($call->neighbours->user) > 0) {
$i = 0;
foreach ($call->neighbours->user as $user) {
$neighbours[$i]['name'] = (string) $user->name;
$neighbours[$i]['url'] = (string) $user->url;
$neighbours[$i]['image'] = (string) $user->image;
$neighbours[$i]['match'] = (string) $user->match;
$i++;
}
return $neighbours;
} else {
throw new NoResultsException('This user has no neighbours');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getNeighbours",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getneighbours'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"vars",
"[",
"'limit'",
"]",
"=",
"$",
"methodVars",
"[",
"'limit'",
"]",
";",
"}",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"call",
"->",
"neighbours",
"->",
"user",
")",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"neighbours",
"->",
"user",
"as",
"$",
"user",
")",
"{",
"$",
"neighbours",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"name",
";",
"$",
"neighbours",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"url",
";",
"$",
"neighbours",
"[",
"$",
"i",
"]",
"[",
"'image'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"image",
";",
"$",
"neighbours",
"[",
"$",
"i",
"]",
"[",
"'match'",
"]",
"=",
"(",
"string",
")",
"$",
"user",
"->",
"match",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"neighbours",
";",
"}",
"else",
"{",
"throw",
"new",
"NoResultsException",
"(",
"'This user has no neighbours'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get a list of a user's neighbours on Last.fm
@deprecated as of march 15 2016, 'user.getneighbours' method is not available
@param array $methodVars An array with the following required values: <i>user</i>
@return array | [
"Get",
"a",
"list",
"of",
"a",
"user",
"s",
"neighbours",
"on",
"Last",
".",
"fm"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L211-L245 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getPlaylists | public function getPlaylists($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getplaylists',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->playlists->playlist) > 0) {
$i = 0;
foreach ($call->playlists->playlist as $playlist) {
$playlists[$i]['id'] = (string) $playlist->id;
$playlists[$i]['title'] = (string) $playlist->title;
$playlists[$i]['date'] = strtotime(trim((string) $playlist->date));
$playlists[$i]['size'] = (string) $playlist->size;
$playlists[$i]['streamalbe'] = (string) $playlist->streamable;
$playlists[$i]['creator'] = (string) $playlist->creator;
$i++;
}
return $playlists;
} else {
throw new NoResultsException('This user has no past events');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getPlaylists($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getplaylists',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->playlists->playlist) > 0) {
$i = 0;
foreach ($call->playlists->playlist as $playlist) {
$playlists[$i]['id'] = (string) $playlist->id;
$playlists[$i]['title'] = (string) $playlist->title;
$playlists[$i]['date'] = strtotime(trim((string) $playlist->date));
$playlists[$i]['size'] = (string) $playlist->size;
$playlists[$i]['streamalbe'] = (string) $playlist->streamable;
$playlists[$i]['creator'] = (string) $playlist->creator;
$i++;
}
return $playlists;
} else {
throw new NoResultsException('This user has no past events');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getPlaylists",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getplaylists'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"call",
"->",
"playlists",
"->",
"playlist",
")",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"playlists",
"->",
"playlist",
"as",
"$",
"playlist",
")",
"{",
"$",
"playlists",
"[",
"$",
"i",
"]",
"[",
"'id'",
"]",
"=",
"(",
"string",
")",
"$",
"playlist",
"->",
"id",
";",
"$",
"playlists",
"[",
"$",
"i",
"]",
"[",
"'title'",
"]",
"=",
"(",
"string",
")",
"$",
"playlist",
"->",
"title",
";",
"$",
"playlists",
"[",
"$",
"i",
"]",
"[",
"'date'",
"]",
"=",
"strtotime",
"(",
"trim",
"(",
"(",
"string",
")",
"$",
"playlist",
"->",
"date",
")",
")",
";",
"$",
"playlists",
"[",
"$",
"i",
"]",
"[",
"'size'",
"]",
"=",
"(",
"string",
")",
"$",
"playlist",
"->",
"size",
";",
"$",
"playlists",
"[",
"$",
"i",
"]",
"[",
"'streamalbe'",
"]",
"=",
"(",
"string",
")",
"$",
"playlist",
"->",
"streamable",
";",
"$",
"playlists",
"[",
"$",
"i",
"]",
"[",
"'creator'",
"]",
"=",
"(",
"string",
")",
"$",
"playlist",
"->",
"creator",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"playlists",
";",
"}",
"else",
"{",
"throw",
"new",
"NoResultsException",
"(",
"'This user has no past events'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get a list of a user's playlists on Last.fm
@deprecated as of march 15 2016, 'user.getplaylists' method is not available
@param array $methodVars An array with the following required values: <i>user</i>
@return array | [
"Get",
"a",
"list",
"of",
"a",
"user",
"s",
"playlists",
"on",
"Last",
".",
"fm"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L313-L346 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getRecentTracks | public function getRecentTracks($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getrecenttracks',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->recenttracks->track) > 0) {
$i = 0;
foreach ($call->recenttracks->track as $track) {
$recentTracks[$i]['name'] = (string) $track->name;
if (isset($track['nowplaying'])) {
$recentTracks[$i]['nowplaying'] = true;
}
$recentTracks[$i]['mbid'] = (string) $track->mbid;
$recentTracks[$i]['url'] = (string) $track->url;
$recentTracks[$i]['date'] = (string) $track->date['uts'];
$recentTracks[$i]['streamable'] = (string) $track->streamable;
$recentTracks[$i]['artist']['name'] = (string) $track->artist;
$recentTracks[$i]['artist']['mbid'] = (string) $track->artist['mbid'];
$recentTracks[$i]['album']['name'] = (string) $track->album;
$recentTracks[$i]['album']['mbid'] = (string) $track->album['mbid'];
$recentTracks[$i]['images']['small'] = (string) $track->image[0];
$recentTracks[$i]['images']['medium'] = (string) $track->image[1];
$recentTracks[$i]['images']['large'] = (string) $track->image[2];
$i++;
}
return $recentTracks;
} else {
throw new NoResultsException('This user has no recent tracks');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getRecentTracks($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getrecenttracks',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->recenttracks->track) > 0) {
$i = 0;
foreach ($call->recenttracks->track as $track) {
$recentTracks[$i]['name'] = (string) $track->name;
if (isset($track['nowplaying'])) {
$recentTracks[$i]['nowplaying'] = true;
}
$recentTracks[$i]['mbid'] = (string) $track->mbid;
$recentTracks[$i]['url'] = (string) $track->url;
$recentTracks[$i]['date'] = (string) $track->date['uts'];
$recentTracks[$i]['streamable'] = (string) $track->streamable;
$recentTracks[$i]['artist']['name'] = (string) $track->artist;
$recentTracks[$i]['artist']['mbid'] = (string) $track->artist['mbid'];
$recentTracks[$i]['album']['name'] = (string) $track->album;
$recentTracks[$i]['album']['mbid'] = (string) $track->album['mbid'];
$recentTracks[$i]['images']['small'] = (string) $track->image[0];
$recentTracks[$i]['images']['medium'] = (string) $track->image[1];
$recentTracks[$i]['images']['large'] = (string) $track->image[2];
$i++;
}
return $recentTracks;
} else {
throw new NoResultsException('This user has no recent tracks');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getRecentTracks",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getrecenttracks'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"call",
"->",
"recenttracks",
"->",
"track",
")",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"recenttracks",
"->",
"track",
"as",
"$",
"track",
")",
"{",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"name",
";",
"if",
"(",
"isset",
"(",
"$",
"track",
"[",
"'nowplaying'",
"]",
")",
")",
"{",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'nowplaying'",
"]",
"=",
"true",
";",
"}",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"mbid",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"url",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'date'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"date",
"[",
"'uts'",
"]",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'streamable'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"streamable",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
"[",
"'mbid'",
"]",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'album'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"album",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'album'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"album",
"[",
"'mbid'",
"]",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'small'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"0",
"]",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'medium'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"1",
"]",
";",
"$",
"recentTracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'large'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"2",
"]",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"recentTracks",
";",
"}",
"else",
"{",
"throw",
"new",
"NoResultsException",
"(",
"'This user has no recent tracks'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get a list of the recent tracks listened to by this user. Indicates now playing track if the user is currently listening
@param array $methodVars An array with the following required values: <i>user</i>
@return array | [
"Get",
"a",
"list",
"of",
"the",
"recent",
"tracks",
"listened",
"to",
"by",
"this",
"user",
".",
"Indicates",
"now",
"playing",
"track",
"if",
"the",
"user",
"is",
"currently",
"listening"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L353-L395 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getTopAlbums | public function getTopAlbums($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.gettopalbums',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->topalbums->album) > 0) {
$i = 0;
foreach ($call->topalbums->album as $album) {
$topalbums[$i]['name'] = (string) $album->name;
$topalbums[$i]['playcount'] = (string) $album->playcount;
$topalbums[$i]['mbid'] = (string) $album->mbid;
$topalbums[$i]['url'] = (string) $album->url;
$topalbums[$i]['artist']['name'] = (string) $album->artist->name;
$topalbums[$i]['artist']['mbid'] = (string) $album->artist->mbid;
$topalbums[$i]['artist']['url'] = (string) $album->artist->url;
$topalbums[$i]['images']['small'] = (string) $album->image[0];
$topalbums[$i]['images']['medium'] = (string) $album->image[1];
$topalbums[$i]['images']['large'] = (string) $album->image[2];
$i++;
}
return $topalbums;
} else {
throw new NoResultsException('This user has no top albums');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getTopAlbums($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.gettopalbums',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->topalbums->album) > 0) {
$i = 0;
foreach ($call->topalbums->album as $album) {
$topalbums[$i]['name'] = (string) $album->name;
$topalbums[$i]['playcount'] = (string) $album->playcount;
$topalbums[$i]['mbid'] = (string) $album->mbid;
$topalbums[$i]['url'] = (string) $album->url;
$topalbums[$i]['artist']['name'] = (string) $album->artist->name;
$topalbums[$i]['artist']['mbid'] = (string) $album->artist->mbid;
$topalbums[$i]['artist']['url'] = (string) $album->artist->url;
$topalbums[$i]['images']['small'] = (string) $album->image[0];
$topalbums[$i]['images']['medium'] = (string) $album->image[1];
$topalbums[$i]['images']['large'] = (string) $album->image[2];
$i++;
}
return $topalbums;
} else {
throw new NoResultsException('This user has no top albums');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getTopAlbums",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.gettopalbums'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"call",
"->",
"topalbums",
"->",
"album",
")",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"topalbums",
"->",
"album",
"as",
"$",
"album",
")",
"{",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"name",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'playcount'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"playcount",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"mbid",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"url",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"artist",
"->",
"name",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"artist",
"->",
"mbid",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"artist",
"->",
"url",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'small'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"image",
"[",
"0",
"]",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'medium'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"image",
"[",
"1",
"]",
";",
"$",
"topalbums",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'large'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"image",
"[",
"2",
"]",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"topalbums",
";",
"}",
"else",
"{",
"throw",
"new",
"NoResultsException",
"(",
"'This user has no top albums'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get the top albums listened to by a user. You can stipulate a time period. Sends the overall chart by default
@param array $methodVars An array with the following required values: <i>user</i> and optional value: <i>period</i>
@return array | [
"Get",
"the",
"top",
"albums",
"listened",
"to",
"by",
"a",
"user",
".",
"You",
"can",
"stipulate",
"a",
"time",
"period",
".",
"Sends",
"the",
"overall",
"chart",
"by",
"default"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L559-L596 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getTopArtists | public function getTopArtists($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.gettopartists',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->topartists->artist) > 0) {
$i = 0;
foreach ($call->topartists->artist as $artist) {
$topartists[$i]['name'] = (string) $artist->name;
$topartists[$i]['rank'] = (string) $artist['rank'];
$topartists[$i]['playcount'] = (string) $artist->playcount;
$topartists[$i]['mbid'] = (string) $artist->mbid;
$topartists[$i]['url'] = (string) $artist->url;
$topartists[$i]['streamable'] = (string) $artist->streamable;
$topartists[$i]['images']['small'] = (string) $artist->image[0];
$topartists[$i]['images']['medium'] = (string) $artist->image[1];
$topartists[$i]['images']['large'] = (string) $artist->image[2];
$i++;
}
return $topartists;
} else {
throw new NoResultsException('This user has no top artists');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getTopArtists($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.gettopartists',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->topartists->artist) > 0) {
$i = 0;
foreach ($call->topartists->artist as $artist) {
$topartists[$i]['name'] = (string) $artist->name;
$topartists[$i]['rank'] = (string) $artist['rank'];
$topartists[$i]['playcount'] = (string) $artist->playcount;
$topartists[$i]['mbid'] = (string) $artist->mbid;
$topartists[$i]['url'] = (string) $artist->url;
$topartists[$i]['streamable'] = (string) $artist->streamable;
$topartists[$i]['images']['small'] = (string) $artist->image[0];
$topartists[$i]['images']['medium'] = (string) $artist->image[1];
$topartists[$i]['images']['large'] = (string) $artist->image[2];
$i++;
}
return $topartists;
} else {
throw new NoResultsException('This user has no top artists');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getTopArtists",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.gettopartists'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"call",
"->",
"topartists",
"->",
"artist",
")",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"topartists",
"->",
"artist",
"as",
"$",
"artist",
")",
"{",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"name",
";",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'rank'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"[",
"'rank'",
"]",
";",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'playcount'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"playcount",
";",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"mbid",
";",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"url",
";",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'streamable'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"streamable",
";",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'small'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"image",
"[",
"0",
"]",
";",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'medium'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"image",
"[",
"1",
"]",
";",
"$",
"topartists",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'large'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"image",
"[",
"2",
"]",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"topartists",
";",
"}",
"else",
"{",
"throw",
"new",
"NoResultsException",
"(",
"'This user has no top artists'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get the top artists listened to by a user. You can stipulate a time period. Sends the overall chart by default
@param array $methodVars An array with the following required values: <i>user</i> and optional value: <i>period</i>
@return array | [
"Get",
"the",
"top",
"artists",
"listened",
"to",
"by",
"a",
"user",
".",
"You",
"can",
"stipulate",
"a",
"time",
"period",
".",
"Sends",
"the",
"overall",
"chart",
"by",
"default"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L603-L639 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getTopTracks | public function getTopTracks($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.gettoptracks',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->toptracks->track) > 0) {
$i = 0;
foreach ($call->toptracks->track as $track) {
$toptracks[$i]['name'] = (string) $track->name;
$toptracks[$i]['rank'] = (string) $track['rank'];
$toptracks[$i]['playcount'] = (string) $track->playcount;
$toptracks[$i]['mbid'] = (string) $track->mbid;
$toptracks[$i]['url'] = (string) $track->url;
$toptracks[$i]['streamable'] = (string) $track->streamable;
$toptracks[$i]['fulltrack'] = (string) $track->streamable['fulltrack'];
$toptracks[$i]['artist']['name'] = (string) $track->artist->name;
$toptracks[$i]['artist']['mbid'] = (string) $track->artist->mbid;
$toptracks[$i]['artist']['url'] = (string) $track->artist->url;
$toptracks[$i]['images']['small'] = (string) $track->image[0];
$toptracks[$i]['images']['medium'] = (string) $track->image[1];
$toptracks[$i]['images']['large'] = (string) $track->image[2];
$i++;
}
return $toptracks;
} else {
throw new NoResultsException('This user has no top tracks');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getTopTracks($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.gettoptracks',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
if (count($call->toptracks->track) > 0) {
$i = 0;
foreach ($call->toptracks->track as $track) {
$toptracks[$i]['name'] = (string) $track->name;
$toptracks[$i]['rank'] = (string) $track['rank'];
$toptracks[$i]['playcount'] = (string) $track->playcount;
$toptracks[$i]['mbid'] = (string) $track->mbid;
$toptracks[$i]['url'] = (string) $track->url;
$toptracks[$i]['streamable'] = (string) $track->streamable;
$toptracks[$i]['fulltrack'] = (string) $track->streamable['fulltrack'];
$toptracks[$i]['artist']['name'] = (string) $track->artist->name;
$toptracks[$i]['artist']['mbid'] = (string) $track->artist->mbid;
$toptracks[$i]['artist']['url'] = (string) $track->artist->url;
$toptracks[$i]['images']['small'] = (string) $track->image[0];
$toptracks[$i]['images']['medium'] = (string) $track->image[1];
$toptracks[$i]['images']['large'] = (string) $track->image[2];
$i++;
}
return $toptracks;
} else {
throw new NoResultsException('This user has no top tracks');
}
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getTopTracks",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.gettoptracks'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"call",
"->",
"toptracks",
"->",
"track",
")",
">",
"0",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"toptracks",
"->",
"track",
"as",
"$",
"track",
")",
"{",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"name",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'rank'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"[",
"'rank'",
"]",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'playcount'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"playcount",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"mbid",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"url",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'streamable'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"streamable",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'fulltrack'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"streamable",
"[",
"'fulltrack'",
"]",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
"->",
"name",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
"->",
"mbid",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
"->",
"url",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'small'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"0",
"]",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'medium'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"1",
"]",
";",
"$",
"toptracks",
"[",
"$",
"i",
"]",
"[",
"'images'",
"]",
"[",
"'large'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"image",
"[",
"2",
"]",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"toptracks",
";",
"}",
"else",
"{",
"throw",
"new",
"NoResultsException",
"(",
"'This user has no top tracks'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get the top tracks listened to by a user. You can stipulate a time period. Sends the overall chart by default
@param array $methodVars An array with the following required values: <i>user</i> and optional value: <i>period</i>
@return array | [
"Get",
"the",
"top",
"tracks",
"listened",
"to",
"by",
"a",
"user",
".",
"You",
"can",
"stipulate",
"a",
"time",
"period",
".",
"Sends",
"the",
"overall",
"chart",
"by",
"default"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L683-L723 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getWeeklyAlbumChart | public function getWeeklyAlbumChart($methodVars)
{
$weeklyalbums = array();
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getweeklyalbumchart',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
$i = 0;
foreach ($call->weeklyalbumchart->album as $album) {
$weeklyalbums[$i]['name'] = (string) $album->name;
$weeklyalbums[$i]['rank'] = (string) $album['rank'];
$weeklyalbums[$i]['artist']['name'] = (string) $album->artist;
$weeklyalbums[$i]['artist']['mbid'] = (string) $album->artist['mbid'];
$weeklyalbums[$i]['mbid'] = (string) $album->mbid;
$weeklyalbums[$i]['playcount'] = (string) $album->playcount;
$weeklyalbums[$i]['url'] = (string) $album->url;
$i++;
}
return $weeklyalbums;
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getWeeklyAlbumChart($methodVars)
{
$weeklyalbums = array();
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getweeklyalbumchart',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
$i = 0;
foreach ($call->weeklyalbumchart->album as $album) {
$weeklyalbums[$i]['name'] = (string) $album->name;
$weeklyalbums[$i]['rank'] = (string) $album['rank'];
$weeklyalbums[$i]['artist']['name'] = (string) $album->artist;
$weeklyalbums[$i]['artist']['mbid'] = (string) $album->artist['mbid'];
$weeklyalbums[$i]['mbid'] = (string) $album->mbid;
$weeklyalbums[$i]['playcount'] = (string) $album->playcount;
$weeklyalbums[$i]['url'] = (string) $album->url;
$i++;
}
return $weeklyalbums;
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getWeeklyAlbumChart",
"(",
"$",
"methodVars",
")",
"{",
"$",
"weeklyalbums",
"=",
"array",
"(",
")",
";",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getweeklyalbumchart'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"weeklyalbumchart",
"->",
"album",
"as",
"$",
"album",
")",
"{",
"$",
"weeklyalbums",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"name",
";",
"$",
"weeklyalbums",
"[",
"$",
"i",
"]",
"[",
"'rank'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"[",
"'rank'",
"]",
";",
"$",
"weeklyalbums",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"artist",
";",
"$",
"weeklyalbums",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"artist",
"[",
"'mbid'",
"]",
";",
"$",
"weeklyalbums",
"[",
"$",
"i",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"mbid",
";",
"$",
"weeklyalbums",
"[",
"$",
"i",
"]",
"[",
"'playcount'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"playcount",
";",
"$",
"weeklyalbums",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"album",
"->",
"url",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"weeklyalbums",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get an album chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent album chart for this user
@param array $methodVars An array with the following required values: <i>user</i> and optional values: <i>to</i>, <i>from</i>
@return array | [
"Get",
"an",
"album",
"chart",
"for",
"a",
"user",
"profile",
"for",
"a",
"given",
"date",
"range",
".",
"If",
"no",
"date",
"range",
"is",
"supplied",
"it",
"will",
"return",
"the",
"most",
"recent",
"album",
"chart",
"for",
"this",
"user"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L730-L761 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getWeeklyArtistChart | public function getWeeklyArtistChart($methodVars)
{
$weeklyartists = array();
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getweeklyartistchart',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
$i = 0;
foreach ($call->weeklyartistchart->artist as $artist) {
$weeklyartists[$i]['name'] = (string) $artist->name;
$weeklyartists[$i]['rank'] = (string) $artist['rank'];
$weeklyartists[$i]['mbid'] = (string) $artist->mbid;
$weeklyartists[$i]['playcount'] = (string) $artist->playcount;
$weeklyartists[$i]['url'] = (string) $artist->url;
$i++;
}
return $weeklyartists;
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getWeeklyArtistChart($methodVars)
{
$weeklyartists = array();
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getweeklyartistchart',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
$i = 0;
foreach ($call->weeklyartistchart->artist as $artist) {
$weeklyartists[$i]['name'] = (string) $artist->name;
$weeklyartists[$i]['rank'] = (string) $artist['rank'];
$weeklyartists[$i]['mbid'] = (string) $artist->mbid;
$weeklyartists[$i]['playcount'] = (string) $artist->playcount;
$weeklyartists[$i]['url'] = (string) $artist->url;
$i++;
}
return $weeklyartists;
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getWeeklyArtistChart",
"(",
"$",
"methodVars",
")",
"{",
"$",
"weeklyartists",
"=",
"array",
"(",
")",
";",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getweeklyartistchart'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"weeklyartistchart",
"->",
"artist",
"as",
"$",
"artist",
")",
"{",
"$",
"weeklyartists",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"name",
";",
"$",
"weeklyartists",
"[",
"$",
"i",
"]",
"[",
"'rank'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"[",
"'rank'",
"]",
";",
"$",
"weeklyartists",
"[",
"$",
"i",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"mbid",
";",
"$",
"weeklyartists",
"[",
"$",
"i",
"]",
"[",
"'playcount'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"playcount",
";",
"$",
"weeklyartists",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"artist",
"->",
"url",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"weeklyartists",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get an artist chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent artist chart for this user
@param array $methodVars An array with the following required values: <i>user</i> and optional values: <i>to</i>, <i>from</i>
@return array | [
"Get",
"an",
"artist",
"chart",
"for",
"a",
"user",
"profile",
"for",
"a",
"given",
"date",
"range",
".",
"If",
"no",
"date",
"range",
"is",
"supplied",
"it",
"will",
"return",
"the",
"most",
"recent",
"artist",
"chart",
"for",
"this",
"user"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L768-L798 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getWeeklyChartList | public function getWeeklyChartList($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getweeklychartlist',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
$i = 0;
foreach ($call->weeklychartlist->chart as $chart) {
$weeklychartlist[$i]['from'] = (string) $chart['from'];
$weeklychartlist[$i]['to'] = (string) $chart['to'];
$i++;
}
return $weeklychartlist;
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getWeeklyChartList($methodVars)
{
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getweeklychartlist',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
$i = 0;
foreach ($call->weeklychartlist->chart as $chart) {
$weeklychartlist[$i]['from'] = (string) $chart['from'];
$weeklychartlist[$i]['to'] = (string) $chart['to'];
$i++;
}
return $weeklychartlist;
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getWeeklyChartList",
"(",
"$",
"methodVars",
")",
"{",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getweeklychartlist'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"weeklychartlist",
"->",
"chart",
"as",
"$",
"chart",
")",
"{",
"$",
"weeklychartlist",
"[",
"$",
"i",
"]",
"[",
"'from'",
"]",
"=",
"(",
"string",
")",
"$",
"chart",
"[",
"'from'",
"]",
";",
"$",
"weeklychartlist",
"[",
"$",
"i",
"]",
"[",
"'to'",
"]",
"=",
"(",
"string",
")",
"$",
"chart",
"[",
"'to'",
"]",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"weeklychartlist",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get a list of available charts for this user, expressed as date ranges which can be sent to the chart services
@param array $methodVars An array with the following required values: <i>user</i>
@return array | [
"Get",
"a",
"list",
"of",
"available",
"charts",
"for",
"this",
"user",
"expressed",
"as",
"date",
"ranges",
"which",
"can",
"be",
"sent",
"to",
"the",
"chart",
"services"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L805-L830 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Api/UserApi.php | UserApi.getWeeklyTrackChart | public function getWeeklyTrackChart($methodVars)
{
$weeklytracks = array();
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getweeklytrackchart',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
$i = 0;
foreach ($call->weeklytrackchart->track as $track) {
$weeklytracks[$i]['name'] = (string) $track->name;
$weeklytracks[$i]['rank'] = (string) $track['rank'];
$weeklytracks[$i]['artist']['name'] = (string) $track->artist;
$weeklytracks[$i]['artist']['mbid'] = (string) $track->artist['mbid'];
$weeklytracks[$i]['mbid'] = (string) $track->mbid;
$weeklytracks[$i]['playcount'] = (string) $track->playcount;
$weeklytracks[$i]['url'] = (string) $track->url;
$i++;
}
return $weeklytracks;
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | php | public function getWeeklyTrackChart($methodVars)
{
$weeklytracks = array();
// Check for required variables
if (!empty($methodVars['user'])) {
$vars = array(
'method' => 'user.getweeklytrackchart',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ($call = $this->apiGetCall($vars)) {
$i = 0;
foreach ($call->weeklytrackchart->track as $track) {
$weeklytracks[$i]['name'] = (string) $track->name;
$weeklytracks[$i]['rank'] = (string) $track['rank'];
$weeklytracks[$i]['artist']['name'] = (string) $track->artist;
$weeklytracks[$i]['artist']['mbid'] = (string) $track->artist['mbid'];
$weeklytracks[$i]['mbid'] = (string) $track->mbid;
$weeklytracks[$i]['playcount'] = (string) $track->playcount;
$weeklytracks[$i]['url'] = (string) $track->url;
$i++;
}
return $weeklytracks;
} else {
return false;
}
} else {
throw new InvalidArgumentException('You must include artist variable in the call for this method');
}
} | [
"public",
"function",
"getWeeklyTrackChart",
"(",
"$",
"methodVars",
")",
"{",
"$",
"weeklytracks",
"=",
"array",
"(",
")",
";",
"// Check for required variables\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodVars",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'method'",
"=>",
"'user.getweeklytrackchart'",
",",
"'api_key'",
"=>",
"$",
"this",
"->",
"auth",
"->",
"apiKey",
")",
";",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"vars",
",",
"$",
"methodVars",
")",
";",
"if",
"(",
"$",
"call",
"=",
"$",
"this",
"->",
"apiGetCall",
"(",
"$",
"vars",
")",
")",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"call",
"->",
"weeklytrackchart",
"->",
"track",
"as",
"$",
"track",
")",
"{",
"$",
"weeklytracks",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"name",
";",
"$",
"weeklytracks",
"[",
"$",
"i",
"]",
"[",
"'rank'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"[",
"'rank'",
"]",
";",
"$",
"weeklytracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'name'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
";",
"$",
"weeklytracks",
"[",
"$",
"i",
"]",
"[",
"'artist'",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"artist",
"[",
"'mbid'",
"]",
";",
"$",
"weeklytracks",
"[",
"$",
"i",
"]",
"[",
"'mbid'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"mbid",
";",
"$",
"weeklytracks",
"[",
"$",
"i",
"]",
"[",
"'playcount'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"playcount",
";",
"$",
"weeklytracks",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
"=",
"(",
"string",
")",
"$",
"track",
"->",
"url",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"weeklytracks",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You must include artist variable in the call for this method'",
")",
";",
"}",
"}"
]
| Get a track chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent track chart for this user
@param array $methodVars An array with the following required values: <i>user</i> and optional values: <i>to</i>, <i>from</i>
@return array | [
"Get",
"a",
"track",
"chart",
"for",
"a",
"user",
"profile",
"for",
"a",
"given",
"date",
"range",
".",
"If",
"no",
"date",
"range",
"is",
"supplied",
"it",
"will",
"return",
"the",
"most",
"recent",
"track",
"chart",
"for",
"this",
"user"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/UserApi.php#L837-L869 | train |
joomla-framework/filesystem | src/Path.php | Path.canChmod | public static function canChmod($path)
{
if (!file_exists($path))
{
return false;
}
$perms = @fileperms($path);
if ($perms !== false)
{
if (@chmod($path, $perms ^ 0001))
{
@chmod($path, $perms);
return true;
}
}
return false;
} | php | public static function canChmod($path)
{
if (!file_exists($path))
{
return false;
}
$perms = @fileperms($path);
if ($perms !== false)
{
if (@chmod($path, $perms ^ 0001))
{
@chmod($path, $perms);
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"canChmod",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"perms",
"=",
"@",
"fileperms",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"perms",
"!==",
"false",
")",
"{",
"if",
"(",
"@",
"chmod",
"(",
"$",
"path",
",",
"$",
"perms",
"^",
"0001",
")",
")",
"{",
"@",
"chmod",
"(",
"$",
"path",
",",
"$",
"perms",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Checks if a path's permissions can be changed.
@param string $path Path to check.
@return boolean True if path can have mode changed.
@since 1.0 | [
"Checks",
"if",
"a",
"path",
"s",
"permissions",
"can",
"be",
"changed",
"."
]
| c3682aabfb64a68ca1e1409c4c76b55968c9cd15 | https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Path.php#L34-L54 | train |
akDeveloper/Aktive-Merchant | lib/AktiveMerchant/Billing/Gateways/Stripe.php | Stripe.addInvoice | private function addInvoice($money, $options)
{
$this->post['amount'] = $this->amount($money / 100);
$this->post['currency'] = self::$default_currency;
$this->post['description'] = $options['description'];
} | php | private function addInvoice($money, $options)
{
$this->post['amount'] = $this->amount($money / 100);
$this->post['currency'] = self::$default_currency;
$this->post['description'] = $options['description'];
} | [
"private",
"function",
"addInvoice",
"(",
"$",
"money",
",",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"post",
"[",
"'amount'",
"]",
"=",
"$",
"this",
"->",
"amount",
"(",
"$",
"money",
"/",
"100",
")",
";",
"$",
"this",
"->",
"post",
"[",
"'currency'",
"]",
"=",
"self",
"::",
"$",
"default_currency",
";",
"$",
"this",
"->",
"post",
"[",
"'description'",
"]",
"=",
"$",
"options",
"[",
"'description'",
"]",
";",
"}"
]
| Adds invoice info if exist.
@param array $options | [
"Adds",
"invoice",
"info",
"if",
"exist",
"."
]
| 00df4840e732ed1938a0a1718dfb50d67119d9a1 | https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Stripe.php#L258-L263 | train |
joomla-framework/filesystem | src/Patcher.php | Patcher.reset | public function reset()
{
$this->sources = array();
$this->destinations = array();
$this->removals = array();
$this->patches = array();
return $this;
} | php | public function reset()
{
$this->sources = array();
$this->destinations = array();
$this->removals = array();
$this->patches = array();
return $this;
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"sources",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"destinations",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"removals",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"patches",
"=",
"array",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Reset the pacher
@return Patcher This object for chaining
@since 1.0 | [
"Reset",
"the",
"pacher"
]
| c3682aabfb64a68ca1e1409c4c76b55968c9cd15 | https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Patcher.php#L104-L112 | train |
joomla-framework/filesystem | src/Patcher.php | Patcher.addFile | public function addFile($filename, $root = JPATH_ROOT, $strip = 0)
{
return $this->add(file_get_contents($filename), $root, $strip);
} | php | public function addFile($filename, $root = JPATH_ROOT, $strip = 0)
{
return $this->add(file_get_contents($filename), $root, $strip);
} | [
"public",
"function",
"addFile",
"(",
"$",
"filename",
",",
"$",
"root",
"=",
"JPATH_ROOT",
",",
"$",
"strip",
"=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"add",
"(",
"file_get_contents",
"(",
"$",
"filename",
")",
",",
"$",
"root",
",",
"$",
"strip",
")",
";",
"}"
]
| Add a unified diff file to the patcher
@param string $filename Path to the unified diff file
@param string $root The files root path
@param integer $strip The number of '/' to strip
@return Patcher $this for chaining
@since 1.0 | [
"Add",
"a",
"unified",
"diff",
"file",
"to",
"the",
"patcher"
]
| c3682aabfb64a68ca1e1409c4c76b55968c9cd15 | https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Patcher.php#L218-L221 | train |
joomla-framework/filesystem | src/Patcher.php | Patcher.& | protected function &getSource($src)
{
if (!isset($this->sources[$src]))
{
if (is_readable($src))
{
$this->sources[$src] = self::splitLines(file_get_contents($src));
}
else
{
$this->sources[$src] = null;
}
}
return $this->sources[$src];
} | php | protected function &getSource($src)
{
if (!isset($this->sources[$src]))
{
if (is_readable($src))
{
$this->sources[$src] = self::splitLines(file_get_contents($src));
}
else
{
$this->sources[$src] = null;
}
}
return $this->sources[$src];
} | [
"protected",
"function",
"&",
"getSource",
"(",
"$",
"src",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"sources",
"[",
"$",
"src",
"]",
")",
")",
"{",
"if",
"(",
"is_readable",
"(",
"$",
"src",
")",
")",
"{",
"$",
"this",
"->",
"sources",
"[",
"$",
"src",
"]",
"=",
"self",
"::",
"splitLines",
"(",
"file_get_contents",
"(",
"$",
"src",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"sources",
"[",
"$",
"src",
"]",
"=",
"null",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"sources",
"[",
"$",
"src",
"]",
";",
"}"
]
| Get the lines of a source file
@param string $src The path of a file
@return array The lines of the source file
@since 1.0 | [
"Get",
"the",
"lines",
"of",
"a",
"source",
"file"
]
| c3682aabfb64a68ca1e1409c4c76b55968c9cd15 | https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Patcher.php#L503-L518 | train |
joomla-framework/filesystem | src/Patcher.php | Patcher.& | protected function &getDestination($dst, $src)
{
if (!isset($this->destinations[$dst]))
{
$this->destinations[$dst] = $this->getSource($src);
}
return $this->destinations[$dst];
} | php | protected function &getDestination($dst, $src)
{
if (!isset($this->destinations[$dst]))
{
$this->destinations[$dst] = $this->getSource($src);
}
return $this->destinations[$dst];
} | [
"protected",
"function",
"&",
"getDestination",
"(",
"$",
"dst",
",",
"$",
"src",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"destinations",
"[",
"$",
"dst",
"]",
")",
")",
"{",
"$",
"this",
"->",
"destinations",
"[",
"$",
"dst",
"]",
"=",
"$",
"this",
"->",
"getSource",
"(",
"$",
"src",
")",
";",
"}",
"return",
"$",
"this",
"->",
"destinations",
"[",
"$",
"dst",
"]",
";",
"}"
]
| Get the lines of a destination file
@param string $dst The path of a destination file
@param string $src The path of a source file
@return array The lines of the destination file
@since 1.0 | [
"Get",
"the",
"lines",
"of",
"a",
"destination",
"file"
]
| c3682aabfb64a68ca1e1409c4c76b55968c9cd15 | https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Patcher.php#L530-L538 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/MySql.php | MySql.connectToDb | private function connectToDb()
{
if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) {
$this->handleError();
} else if (!@mysql_select_db($this->dbName, $this->dbConn)) {
$this->handleError();
}
} | php | private function connectToDb()
{
if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) {
$this->handleError();
} else if (!@mysql_select_db($this->dbName, $this->dbConn)) {
$this->handleError();
}
} | [
"private",
"function",
"connectToDb",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dbConn",
"=",
"@",
"mysql_connect",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"dbUser",
",",
"$",
"this",
"->",
"dbPass",
")",
")",
"{",
"$",
"this",
"->",
"handleError",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"@",
"mysql_select_db",
"(",
"$",
"this",
"->",
"dbName",
",",
"$",
"this",
"->",
"dbConn",
")",
")",
"{",
"$",
"this",
"->",
"handleError",
"(",
")",
";",
"}",
"}"
]
| Internal command to connect to the database
@return void | [
"Internal",
"command",
"to",
"connect",
"to",
"the",
"database"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/MySql.php#L75-L82 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/MySql.php | MySql.query | public function query($sql)
{
if (!$queryResource = mysql_query($sql, $this->dbConn)) {
echo mysql_error();
$this->handleError();
} else {
return new MySqlResult($this, $queryResource);
}
} | php | public function query($sql)
{
if (!$queryResource = mysql_query($sql, $this->dbConn)) {
echo mysql_error();
$this->handleError();
} else {
return new MySqlResult($this, $queryResource);
}
} | [
"public",
"function",
"query",
"(",
"$",
"sql",
")",
"{",
"if",
"(",
"!",
"$",
"queryResource",
"=",
"mysql_query",
"(",
"$",
"sql",
",",
"$",
"this",
"->",
"dbConn",
")",
")",
"{",
"echo",
"mysql_error",
"(",
")",
";",
"$",
"this",
"->",
"handleError",
"(",
")",
";",
"}",
"else",
"{",
"return",
"new",
"MySqlResult",
"(",
"$",
"this",
",",
"$",
"queryResource",
")",
";",
"}",
"}"
]
| Command which runs queries. Returns a class on success and flase on error
@param string $sql The SQL query to run
@return class
@uses lastfmApiDatabase_result | [
"Command",
"which",
"runs",
"queries",
".",
"Returns",
"a",
"class",
"on",
"success",
"and",
"flase",
"on",
"error"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/MySql.php#L99-L107 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/Cache.php | Cache.check_if_enabled | private function check_if_enabled()
{
if ($this->config['enabled'] == true && extension_loaded('sqlite3')) {
$this->enabled = true;
} else {
$this->enabled = false;
}
} | php | private function check_if_enabled()
{
if ($this->config['enabled'] == true && extension_loaded('sqlite3')) {
$this->enabled = true;
} else {
$this->enabled = false;
}
} | [
"private",
"function",
"check_if_enabled",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'enabled'",
"]",
"==",
"true",
"&&",
"extension_loaded",
"(",
"'sqlite3'",
")",
")",
"{",
"$",
"this",
"->",
"enabled",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"enabled",
"=",
"false",
";",
"}",
"}"
]
| Internal method to chack if caching is enabled
@access private
@return void | [
"Internal",
"method",
"to",
"chack",
"if",
"caching",
"is",
"enabled"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/Cache.php#L100-L107 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/Cache.php | Cache.check_table_exists | private function check_table_exists()
{
if ($this->type == 'sqlite') {
$query = "SELECT count(*) FROM sqlite_master WHERE name='cache'";
$result = $this->db->query($query);
$numbers = $result->fetchAll();
if ($numbers[0]['count(*)'] > 0) {
// Ok
} else {
$this->create_table();
}
} else {
$query = "show tables like 'cache'";
$result = $this->db->query($query);
if ($result->size() > 0) {
// Ok
} else {
$this->create_table();
}
}
} | php | private function check_table_exists()
{
if ($this->type == 'sqlite') {
$query = "SELECT count(*) FROM sqlite_master WHERE name='cache'";
$result = $this->db->query($query);
$numbers = $result->fetchAll();
if ($numbers[0]['count(*)'] > 0) {
// Ok
} else {
$this->create_table();
}
} else {
$query = "show tables like 'cache'";
$result = $this->db->query($query);
if ($result->size() > 0) {
// Ok
} else {
$this->create_table();
}
}
} | [
"private",
"function",
"check_table_exists",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"'sqlite'",
")",
"{",
"$",
"query",
"=",
"\"SELECT count(*) FROM sqlite_master WHERE name='cache'\"",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
";",
"$",
"numbers",
"=",
"$",
"result",
"->",
"fetchAll",
"(",
")",
";",
"if",
"(",
"$",
"numbers",
"[",
"0",
"]",
"[",
"'count(*)'",
"]",
">",
"0",
")",
"{",
"// Ok\r",
"}",
"else",
"{",
"$",
"this",
"->",
"create_table",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"query",
"=",
"\"show tables like 'cache'\"",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"result",
"->",
"size",
"(",
")",
">",
"0",
")",
"{",
"// Ok\r",
"}",
"else",
"{",
"$",
"this",
"->",
"create_table",
"(",
")",
";",
"}",
"}",
"}"
]
| Internal method to check if the table exists
@access private
@return void | [
"Internal",
"method",
"to",
"check",
"if",
"the",
"table",
"exists"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/Cache.php#L114-L134 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/Cache.php | Cache.create_table | private function create_table()
{
if ($this->type == 'sqlite') {
$auto_increase = '';
} else {
$auto_increase = ' AUTO_INCREMENT';
}
$query = "CREATE TABLE cache (cache_id INTEGER PRIMARY KEY" . $auto_increase . ", unique_vars TEXT, expires INT, body TEXT)";
if ($this->db->query($query)) {
// Ok
} else {
// TODO: Handle error
echo $this->db->error;
}
} | php | private function create_table()
{
if ($this->type == 'sqlite') {
$auto_increase = '';
} else {
$auto_increase = ' AUTO_INCREMENT';
}
$query = "CREATE TABLE cache (cache_id INTEGER PRIMARY KEY" . $auto_increase . ", unique_vars TEXT, expires INT, body TEXT)";
if ($this->db->query($query)) {
// Ok
} else {
// TODO: Handle error
echo $this->db->error;
}
} | [
"private",
"function",
"create_table",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"'sqlite'",
")",
"{",
"$",
"auto_increase",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"auto_increase",
"=",
"' AUTO_INCREMENT'",
";",
"}",
"$",
"query",
"=",
"\"CREATE TABLE cache (cache_id INTEGER PRIMARY KEY\"",
".",
"$",
"auto_increase",
".",
"\", unique_vars TEXT, expires INT, body TEXT)\"",
";",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
")",
"{",
"// Ok\r",
"}",
"else",
"{",
"// TODO: Handle error\r",
"echo",
"$",
"this",
"->",
"db",
"->",
"error",
";",
"}",
"}"
]
| Internal method to create the table if it doesn't exist
@access private
@return void | [
"Internal",
"method",
"to",
"create",
"the",
"table",
"if",
"it",
"doesn",
"t",
"exist"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/Cache.php#L141-L155 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/Cache.php | Cache.get | public function get($unique_vars)
{
if ($this->enabled == true) {
$query = "SELECT expires, body FROM cache WHERE unique_vars='" . htmlentities(serialize($unique_vars), ENT_QUOTES, 'UTF-8') . "' LIMIT 1";
if ($result = $this->db->query($query)) {
if ($result->size() > 0) {
$row = $result->fetch();
if ($row['expires'] < time()) {
$this->del($unique_vars);
return false;
} else {
//print_r(unserialize(html_entity_decode($row['body'], ENT_QUOTES, 'UTF-8')));
return unserialize(html_entity_decode($row['body'], ENT_QUOTES, 'UTF-8'));
}
} else {
return false;
}
} else {
// TODO: Handle error
return false;
}
} else {
return false;
}
} | php | public function get($unique_vars)
{
if ($this->enabled == true) {
$query = "SELECT expires, body FROM cache WHERE unique_vars='" . htmlentities(serialize($unique_vars), ENT_QUOTES, 'UTF-8') . "' LIMIT 1";
if ($result = $this->db->query($query)) {
if ($result->size() > 0) {
$row = $result->fetch();
if ($row['expires'] < time()) {
$this->del($unique_vars);
return false;
} else {
//print_r(unserialize(html_entity_decode($row['body'], ENT_QUOTES, 'UTF-8')));
return unserialize(html_entity_decode($row['body'], ENT_QUOTES, 'UTF-8'));
}
} else {
return false;
}
} else {
// TODO: Handle error
return false;
}
} else {
return false;
}
} | [
"public",
"function",
"get",
"(",
"$",
"unique_vars",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabled",
"==",
"true",
")",
"{",
"$",
"query",
"=",
"\"SELECT expires, body FROM cache WHERE unique_vars='\"",
".",
"htmlentities",
"(",
"serialize",
"(",
"$",
"unique_vars",
")",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
".",
"\"' LIMIT 1\"",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
")",
"{",
"if",
"(",
"$",
"result",
"->",
"size",
"(",
")",
">",
"0",
")",
"{",
"$",
"row",
"=",
"$",
"result",
"->",
"fetch",
"(",
")",
";",
"if",
"(",
"$",
"row",
"[",
"'expires'",
"]",
"<",
"time",
"(",
")",
")",
"{",
"$",
"this",
"->",
"del",
"(",
"$",
"unique_vars",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"//print_r(unserialize(html_entity_decode($row['body'], ENT_QUOTES, 'UTF-8')));\r",
"return",
"unserialize",
"(",
"html_entity_decode",
"(",
"$",
"row",
"[",
"'body'",
"]",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"// TODO: Handle error\r",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Searches the database for the cahce date. Returns an array if it exists or false if it doesn't
@access public
@param array $unique_vars Array of variables that are unique to this piece of cached data
@return string | [
"Searches",
"the",
"database",
"for",
"the",
"cahce",
"date",
".",
"Returns",
"an",
"array",
"if",
"it",
"exists",
"or",
"false",
"if",
"it",
"doesn",
"t"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/Cache.php#L163-L187 | train |
matt-oakes/PHP-Last.fm-API | src/lastfmapi/Lib/Cache.php | Cache.set | public function set($unique_vars, $body)
{
if ($this->enabled == true) {
$expire = time() + $this->config['cache_length'];
$query = "INSERT INTO cache (unique_vars, expires, body) VALUES ('" . htmlentities(serialize($unique_vars), ENT_QUOTES, 'UTF-8') . "', '" . $expire . "', \"" . htmlentities(serialize($body), ENT_QUOTES, 'UTF-8') . "\")";
if ($this->db->query($query)) {
return true;
} else {
// TODO: Handle error
return false;
}
} else {
return false;
}
} | php | public function set($unique_vars, $body)
{
if ($this->enabled == true) {
$expire = time() + $this->config['cache_length'];
$query = "INSERT INTO cache (unique_vars, expires, body) VALUES ('" . htmlentities(serialize($unique_vars), ENT_QUOTES, 'UTF-8') . "', '" . $expire . "', \"" . htmlentities(serialize($body), ENT_QUOTES, 'UTF-8') . "\")";
if ($this->db->query($query)) {
return true;
} else {
// TODO: Handle error
return false;
}
} else {
return false;
}
} | [
"public",
"function",
"set",
"(",
"$",
"unique_vars",
",",
"$",
"body",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabled",
"==",
"true",
")",
"{",
"$",
"expire",
"=",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"config",
"[",
"'cache_length'",
"]",
";",
"$",
"query",
"=",
"\"INSERT INTO cache (unique_vars, expires, body) VALUES ('\"",
".",
"htmlentities",
"(",
"serialize",
"(",
"$",
"unique_vars",
")",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
".",
"\"', '\"",
".",
"$",
"expire",
".",
"\"', \\\"\"",
".",
"htmlentities",
"(",
"serialize",
"(",
"$",
"body",
")",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
".",
"\"\\\")\"",
";",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"// TODO: Handle error\r",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Adds new cache data to the database
@access public
@param array $unique_vars Array of variables that are unique to this piece of cached data
@param string $body The contents of the cache to put into the database
@return boolean | [
"Adds",
"new",
"cache",
"data",
"to",
"the",
"database"
]
| 5c639597517167c49bd28419dde4d378efe5ed50 | https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/Cache.php#L196-L210 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.