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
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Lib/Cache.php
Cache.del
private function del($unique_vars) { $query = "DELETE FROM cache WHERE unique_vars='" . htmlentities(serialize($unique_vars), ENT_QUOTES, 'UTF-8') . "'"; if ($this->db->query($query)) { return true; } else { // TODO: Handle error return false; } }
php
private function del($unique_vars) { $query = "DELETE FROM cache WHERE unique_vars='" . htmlentities(serialize($unique_vars), ENT_QUOTES, 'UTF-8') . "'"; if ($this->db->query($query)) { return true; } else { // TODO: Handle error return false; } }
[ "private", "function", "del", "(", "$", "unique_vars", ")", "{", "$", "query", "=", "\"DELETE FROM cache WHERE unique_vars='\"", ".", "htmlentities", "(", "serialize", "(", "$", "unique_vars", ")", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ".", "\"'\"", ";", "if", "(", "$", "this", "->", "db", "->", "query", "(", "$", "query", ")", ")", "{", "return", "true", ";", "}", "else", "{", "// TODO: Handle error\r", "return", "false", ";", "}", "}" ]
Internal method to delete unneeded cache data @access private @param array $unique_vars Array of variables that are unique to this piece of cached data @return boolean
[ "Internal", "method", "to", "delete", "unneeded", "cache", "data" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Lib/Cache.php#L218-L227
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Psigate.php
Psigate.packAuthorizationValues
private function packAuthorizationValues($orderid, $transactionid) { return implode("&", array(self::AUTHSTR_VERSION, urlencode($orderid), urlencode($transactionid))); }
php
private function packAuthorizationValues($orderid, $transactionid) { return implode("&", array(self::AUTHSTR_VERSION, urlencode($orderid), urlencode($transactionid))); }
[ "private", "function", "packAuthorizationValues", "(", "$", "orderid", ",", "$", "transactionid", ")", "{", "return", "implode", "(", "\"&\"", ",", "array", "(", "self", "::", "AUTHSTR_VERSION", ",", "urlencode", "(", "$", "orderid", ")", ",", "urlencode", "(", "$", "transactionid", ")", ")", ")", ";", "}" ]
Create a string with required transaction data. PSiGate always requires the order ID to complete or modify past transactions, and sometimes requires the transaction ID. This function packs them both into one string, which can be used for any of these purposes. @param string $orderid @param string $transactionid
[ "Create", "a", "string", "with", "required", "transaction", "data", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Psigate.php#L125-L128
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Support/GatewaySupport.php
GatewaySupport.getGateways
public function getGateways() { $gateways = array(); foreach ($this->supported_gateways as $gateway) { $class = 'AktiveMerchant\\Billing\\Gateways\\' . $gateway; $gateways[Inflect::underscore($gateway)] = $class::$display_name; } return $gateways; }
php
public function getGateways() { $gateways = array(); foreach ($this->supported_gateways as $gateway) { $class = 'AktiveMerchant\\Billing\\Gateways\\' . $gateway; $gateways[Inflect::underscore($gateway)] = $class::$display_name; } return $gateways; }
[ "public", "function", "getGateways", "(", ")", "{", "$", "gateways", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "supported_gateways", "as", "$", "gateway", ")", "{", "$", "class", "=", "'AktiveMerchant\\\\Billing\\\\Gateways\\\\'", ".", "$", "gateway", ";", "$", "gateways", "[", "Inflect", "::", "underscore", "(", "$", "gateway", ")", "]", "=", "$", "class", "::", "$", "display_name", ";", "}", "return", "$", "gateways", ";", "}" ]
Gets an array with Gateways. @access public @return array
[ "Gets", "an", "array", "with", "Gateways", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Support/GatewaySupport.php#L38-L47
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Support/GatewaySupport.php
GatewaySupport.getSupportedActions
public function getSupportedActions($gateway) { if (!is_string($gateway)) { $gateway = get_class($gateway); } $gateway = Inflect::camelize($gateway); $class = new \ReflectionClass('AktiveMerchant\\Billing\\Gateways\\' . $gateway); $actions = array(); foreach ($this->actions as $action) { if ($class->hasMethod($action)) { $actions[] = $action; } } return $actions; }
php
public function getSupportedActions($gateway) { if (!is_string($gateway)) { $gateway = get_class($gateway); } $gateway = Inflect::camelize($gateway); $class = new \ReflectionClass('AktiveMerchant\\Billing\\Gateways\\' . $gateway); $actions = array(); foreach ($this->actions as $action) { if ($class->hasMethod($action)) { $actions[] = $action; } } return $actions; }
[ "public", "function", "getSupportedActions", "(", "$", "gateway", ")", "{", "if", "(", "!", "is_string", "(", "$", "gateway", ")", ")", "{", "$", "gateway", "=", "get_class", "(", "$", "gateway", ")", ";", "}", "$", "gateway", "=", "Inflect", "::", "camelize", "(", "$", "gateway", ")", ";", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "'AktiveMerchant\\\\Billing\\\\Gateways\\\\'", ".", "$", "gateway", ")", ";", "$", "actions", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "actions", "as", "$", "action", ")", "{", "if", "(", "$", "class", "->", "hasMethod", "(", "$", "action", ")", ")", "{", "$", "actions", "[", "]", "=", "$", "action", ";", "}", "}", "return", "$", "actions", ";", "}" ]
Gets an array with supported actions for given gateway. @param string|Gateway $gateway @access public @return array
[ "Gets", "an", "array", "with", "supported", "actions", "for", "given", "gateway", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Support/GatewaySupport.php#L56-L73
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/PiraeusPaycenter.php
PiraeusPaycenter.addCentinelData
private function addCentinelData($options) { $this->required_options('cavv, eci_flag, xid, enrolled, pares_status, signature_verification', $options); $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['Cavv'] = $options['cavv']; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['Eci'] = $options['eci_flag']; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['Xid'] = $options['xid']; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['Enrolled'] = $this->ENROLLED_MAPPINGS[$options['enrolled']]; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['PAResStatus'] = $this->PARES_MAPPINGS[$options['pares_status']]; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['SignatureVerification'] = $this->SIGNATURE_MAPPINGS[$options['signature_verification']]; }
php
private function addCentinelData($options) { $this->required_options('cavv, eci_flag, xid, enrolled, pares_status, signature_verification', $options); $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['Cavv'] = $options['cavv']; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['Eci'] = $options['eci_flag']; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['Xid'] = $options['xid']; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['Enrolled'] = $this->ENROLLED_MAPPINGS[$options['enrolled']]; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['PAResStatus'] = $this->PARES_MAPPINGS[$options['pares_status']]; $this->post['ProcessTransaction']['TransactionRequest']['Body']['TransactionInfo']['AuthInfo']['SignatureVerification'] = $this->SIGNATURE_MAPPINGS[$options['signature_verification']]; }
[ "private", "function", "addCentinelData", "(", "$", "options", ")", "{", "$", "this", "->", "required_options", "(", "'cavv, eci_flag, xid, enrolled, pares_status, signature_verification'", ",", "$", "options", ")", ";", "$", "this", "->", "post", "[", "'ProcessTransaction'", "]", "[", "'TransactionRequest'", "]", "[", "'Body'", "]", "[", "'TransactionInfo'", "]", "[", "'AuthInfo'", "]", "[", "'Cavv'", "]", "=", "$", "options", "[", "'cavv'", "]", ";", "$", "this", "->", "post", "[", "'ProcessTransaction'", "]", "[", "'TransactionRequest'", "]", "[", "'Body'", "]", "[", "'TransactionInfo'", "]", "[", "'AuthInfo'", "]", "[", "'Eci'", "]", "=", "$", "options", "[", "'eci_flag'", "]", ";", "$", "this", "->", "post", "[", "'ProcessTransaction'", "]", "[", "'TransactionRequest'", "]", "[", "'Body'", "]", "[", "'TransactionInfo'", "]", "[", "'AuthInfo'", "]", "[", "'Xid'", "]", "=", "$", "options", "[", "'xid'", "]", ";", "$", "this", "->", "post", "[", "'ProcessTransaction'", "]", "[", "'TransactionRequest'", "]", "[", "'Body'", "]", "[", "'TransactionInfo'", "]", "[", "'AuthInfo'", "]", "[", "'Enrolled'", "]", "=", "$", "this", "->", "ENROLLED_MAPPINGS", "[", "$", "options", "[", "'enrolled'", "]", "]", ";", "$", "this", "->", "post", "[", "'ProcessTransaction'", "]", "[", "'TransactionRequest'", "]", "[", "'Body'", "]", "[", "'TransactionInfo'", "]", "[", "'AuthInfo'", "]", "[", "'PAResStatus'", "]", "=", "$", "this", "->", "PARES_MAPPINGS", "[", "$", "options", "[", "'pares_status'", "]", "]", ";", "$", "this", "->", "post", "[", "'ProcessTransaction'", "]", "[", "'TransactionRequest'", "]", "[", "'Body'", "]", "[", "'TransactionInfo'", "]", "[", "'AuthInfo'", "]", "[", "'SignatureVerification'", "]", "=", "$", "this", "->", "SIGNATURE_MAPPINGS", "[", "$", "options", "[", "'signature_verification'", "]", "]", ";", "}" ]
Add required data from 3D centinel verification @param array $options
[ "Add", "required", "data", "from", "3D", "centinel", "verification" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/PiraeusPaycenter.php#L320-L330
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.authorize
public function authorize($money, CreditCard $creditcard, $options = array()) { $this->required_options('order_id', $options); $this->buildPurchaseOrAuthorizationRequest('authorization', $money, $creditcard, $options); return $this->commit(); }
php
public function authorize($money, CreditCard $creditcard, $options = array()) { $this->required_options('order_id', $options); $this->buildPurchaseOrAuthorizationRequest('authorization', $money, $creditcard, $options); return $this->commit(); }
[ "public", "function", "authorize", "(", "$", "money", ",", "CreditCard", "$", "creditcard", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "required_options", "(", "'order_id'", ",", "$", "options", ")", ";", "$", "this", "->", "buildPurchaseOrAuthorizationRequest", "(", "'authorization'", ",", "$", "money", ",", "$", "creditcard", ",", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", ")", ";", "}" ]
Performs an authorization, which reserves the funds on the customer's credit card, but does not charge the card. @param string $money The amount to be authorized. Either an Integer value in cents or a Money object. @param CreditCard $creditcard The CreditCard details for the transaction. @param array $options Optional parameters. @return Response
[ "Performs", "an", "authorization", "which", "reserves", "the", "funds", "on", "the", "customer", "s", "credit", "card", "but", "does", "not", "charge", "the", "card", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L126-L132
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.capture
public function capture($money, $authorization, $options = array()) { $this->required_options('pasref, order_id', $options); $this->buildCaptureRequest($authorization, $options); return $this->commit(); }
php
public function capture($money, $authorization, $options = array()) { $this->required_options('pasref, order_id', $options); $this->buildCaptureRequest($authorization, $options); return $this->commit(); }
[ "public", "function", "capture", "(", "$", "money", ",", "$", "authorization", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "required_options", "(", "'pasref, order_id'", ",", "$", "options", ")", ";", "$", "this", "->", "buildCaptureRequest", "(", "$", "authorization", ",", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", ")", ";", "}" ]
Captures the funds from an authorized transaction. @param string $money The amount to be authorized. Either an Integer value in cents or a Money object. @param string $authorization The authorization returned from the previous authorize request. @param array $options Optional parameters. @return Response
[ "Captures", "the", "funds", "from", "an", "authorized", "transaction", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L160-L166
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.credit
public function credit($money, $authorization, $options = array()) { $this->required_options('pasref, order_id', $options); $this->buildCreditRequest($money, $authorization, $options); return $this->commit(); }
php
public function credit($money, $authorization, $options = array()) { $this->required_options('pasref, order_id', $options); $this->buildCreditRequest($money, $authorization, $options); return $this->commit(); }
[ "public", "function", "credit", "(", "$", "money", ",", "$", "authorization", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "required_options", "(", "'pasref, order_id'", ",", "$", "options", ")", ";", "$", "this", "->", "buildCreditRequest", "(", "$", "money", ",", "$", "authorization", ",", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", ")", ";", "}" ]
Credit an account. This transaction is also referred to as a Refund (or Rebate) and indicates to the gateway that money should flow from the merchant to the customer. @param string $money The amount to be rebated. Either an Integer value in cents or a Money object. @param string $authorization The authorization returned from the previous authorize request. @param array $options Optional parameters. ` @return Response
[ "Credit", "an", "account", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L180-L186
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.void
public function void($authorization, $options = array()) { $this->required_options('pasref, order_id', $options); $this->buildVoidRequest($authorization, $options); return $this->commit(); }
php
public function void($authorization, $options = array()) { $this->required_options('pasref, order_id', $options); $this->buildVoidRequest($authorization, $options); return $this->commit(); }
[ "public", "function", "void", "(", "$", "authorization", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "required_options", "(", "'pasref, order_id'", ",", "$", "options", ")", ";", "$", "this", "->", "buildVoidRequest", "(", "$", "authorization", ",", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", ")", ";", "}" ]
Void a previous transaction @param string $authorization The authorization returned from the previous authorize request. @param array $options Optional parameters. @return Response
[ "Void", "a", "previous", "transaction" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L196-L202
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.recurring
public function recurring($money, CreditCard $creditcard, $options = array()) { $this->required_options('order_id', $options); $this->buildReceiptInRequest($money, $options); return $this->commit('recurring'); }
php
public function recurring($money, CreditCard $creditcard, $options = array()) { $this->required_options('order_id', $options); $this->buildReceiptInRequest($money, $options); return $this->commit('recurring'); }
[ "public", "function", "recurring", "(", "$", "money", ",", "CreditCard", "$", "creditcard", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "required_options", "(", "'order_id'", ",", "$", "options", ")", ";", "$", "this", "->", "buildReceiptInRequest", "(", "$", "money", ",", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", "'recurring'", ")", ";", "}" ]
Process a recurring payment transaction @param string $money The amount to be authorized. Either an Integer value in cents or a Money object. @param array $options Optional parameters. @return Response
[ "Process", "a", "recurring", "payment", "transaction" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L216-L222
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.store
public function store(CreditCard $creditcard, $options = array()) { $this->required_options('order_id', $options); $this->buildNewCardRequest($creditcard, $options); return $this->commit('recurring'); }
php
public function store(CreditCard $creditcard, $options = array()) { $this->required_options('order_id', $options); $this->buildNewCardRequest($creditcard, $options); return $this->commit('recurring'); }
[ "public", "function", "store", "(", "CreditCard", "$", "creditcard", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "required_options", "(", "'order_id'", ",", "$", "options", ")", ";", "$", "this", "->", "buildNewCardRequest", "(", "$", "creditcard", ",", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", "'recurring'", ")", ";", "}" ]
Store new card information in Realex RealVault @param CreditCard $creditcard The CreditCard details for the transaction. @param array $options Optional parameters. @return Response
[ "Store", "new", "card", "information", "in", "Realex", "RealVault" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L240-L245
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.unstore
public function unstore($reference, $options = array()) { $this->required_options('order_id', $options); $this->buildCancelCardRequest($options); return $this->commit('recurring'); }
php
public function unstore($reference, $options = array()) { $this->required_options('order_id', $options); $this->buildCancelCardRequest($options); return $this->commit('recurring'); }
[ "public", "function", "unstore", "(", "$", "reference", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "required_options", "(", "'order_id'", ",", "$", "options", ")", ";", "$", "this", "->", "buildCancelCardRequest", "(", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", "'recurring'", ")", ";", "}" ]
Remove card information from Realex RealVault @param CreditCard $creditcard The CreditCard details for the transaction. @param array $options Optional parameters. @return Response
[ "Remove", "card", "information", "from", "Realex", "RealVault" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L255-L260
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.storeUser
public function storeUser($options) { $this->required_options('order_id', $options); $this->buildNewPayerRequest($options); return $this->commit('recurring'); }
php
public function storeUser($options) { $this->required_options('order_id', $options); $this->buildNewPayerRequest($options); return $this->commit('recurring'); }
[ "public", "function", "storeUser", "(", "$", "options", ")", "{", "$", "this", "->", "required_options", "(", "'order_id'", ",", "$", "options", ")", ";", "$", "this", "->", "buildNewPayerRequest", "(", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", "'recurring'", ")", ";", "}" ]
Store User information in the Realex RealVault @param array $options Parameters. @return Response
[ "Store", "User", "information", "in", "the", "Realex", "RealVault" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L269-L274
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.messageFrom
private function messageFrom($response) { $result = (string) $response->result; $response_message = (string) $response->message; switch ($result) { case '00': $message = $this->messages['SUCCESS']; break; case '101': case '102': case '103': $message = ($this->inTestMode($response)) ? $response_message : $this->messages['DECLINED']; break; case (bool) preg_match("/^2[0-9][0-9]/", $result, $matches): $message = $this->messages['BANK_ERROR']; break; case (bool) preg_match("/^3[0-9][0-9]/", $result, $matches): $message = $this->messages['REALEX_ERROR']; break; case (bool) preg_match("/^5[0-9][0-9]/", $result, $matches): $message = $response_message; break; case '600': case '601': case '602': $message = $this->messages['ERROR']; break; case '666': $message = $this->messages['CLIENT_DEACTIVATED']; break; default: $message = $this->messages['DECLINED']; break; } return $message; }
php
private function messageFrom($response) { $result = (string) $response->result; $response_message = (string) $response->message; switch ($result) { case '00': $message = $this->messages['SUCCESS']; break; case '101': case '102': case '103': $message = ($this->inTestMode($response)) ? $response_message : $this->messages['DECLINED']; break; case (bool) preg_match("/^2[0-9][0-9]/", $result, $matches): $message = $this->messages['BANK_ERROR']; break; case (bool) preg_match("/^3[0-9][0-9]/", $result, $matches): $message = $this->messages['REALEX_ERROR']; break; case (bool) preg_match("/^5[0-9][0-9]/", $result, $matches): $message = $response_message; break; case '600': case '601': case '602': $message = $this->messages['ERROR']; break; case '666': $message = $this->messages['CLIENT_DEACTIVATED']; break; default: $message = $this->messages['DECLINED']; break; } return $message; }
[ "private", "function", "messageFrom", "(", "$", "response", ")", "{", "$", "result", "=", "(", "string", ")", "$", "response", "->", "result", ";", "$", "response_message", "=", "(", "string", ")", "$", "response", "->", "message", ";", "switch", "(", "$", "result", ")", "{", "case", "'00'", ":", "$", "message", "=", "$", "this", "->", "messages", "[", "'SUCCESS'", "]", ";", "break", ";", "case", "'101'", ":", "case", "'102'", ":", "case", "'103'", ":", "$", "message", "=", "(", "$", "this", "->", "inTestMode", "(", "$", "response", ")", ")", "?", "$", "response_message", ":", "$", "this", "->", "messages", "[", "'DECLINED'", "]", ";", "break", ";", "case", "(", "bool", ")", "preg_match", "(", "\"/^2[0-9][0-9]/\"", ",", "$", "result", ",", "$", "matches", ")", ":", "$", "message", "=", "$", "this", "->", "messages", "[", "'BANK_ERROR'", "]", ";", "break", ";", "case", "(", "bool", ")", "preg_match", "(", "\"/^3[0-9][0-9]/\"", ",", "$", "result", ",", "$", "matches", ")", ":", "$", "message", "=", "$", "this", "->", "messages", "[", "'REALEX_ERROR'", "]", ";", "break", ";", "case", "(", "bool", ")", "preg_match", "(", "\"/^5[0-9][0-9]/\"", ",", "$", "result", ",", "$", "matches", ")", ":", "$", "message", "=", "$", "response_message", ";", "break", ";", "case", "'600'", ":", "case", "'601'", ":", "case", "'602'", ":", "$", "message", "=", "$", "this", "->", "messages", "[", "'ERROR'", "]", ";", "break", ";", "case", "'666'", ":", "$", "message", "=", "$", "this", "->", "messages", "[", "'CLIENT_DEACTIVATED'", "]", ";", "break", ";", "default", ":", "$", "message", "=", "$", "this", "->", "messages", "[", "'DECLINED'", "]", ";", "break", ";", "}", "return", "$", "message", ";", "}" ]
Parse the message from the response @param string $response @return string
[ "Parse", "the", "message", "from", "the", "response" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L716-L753
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.paramsFrom
private function paramsFrom($response) { $attribs = $response->attributes(); $params = array(); $params['result'] = (string) $response->result; $params['pasref'] = (string) $response->pasref; $params['order_id'] = (string) $response->orderid; $params['batch_id'] = (string) $response->batchid; $params['account'] = (string) $response->account; $params['timestamp'] = (int) $attribs['timestamp']; return $params; }
php
private function paramsFrom($response) { $attribs = $response->attributes(); $params = array(); $params['result'] = (string) $response->result; $params['pasref'] = (string) $response->pasref; $params['order_id'] = (string) $response->orderid; $params['batch_id'] = (string) $response->batchid; $params['account'] = (string) $response->account; $params['timestamp'] = (int) $attribs['timestamp']; return $params; }
[ "private", "function", "paramsFrom", "(", "$", "response", ")", "{", "$", "attribs", "=", "$", "response", "->", "attributes", "(", ")", ";", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'result'", "]", "=", "(", "string", ")", "$", "response", "->", "result", ";", "$", "params", "[", "'pasref'", "]", "=", "(", "string", ")", "$", "response", "->", "pasref", ";", "$", "params", "[", "'order_id'", "]", "=", "(", "string", ")", "$", "response", "->", "orderid", ";", "$", "params", "[", "'batch_id'", "]", "=", "(", "string", ")", "$", "response", "->", "batchid", ";", "$", "params", "[", "'account'", "]", "=", "(", "string", ")", "$", "response", "->", "account", ";", "$", "params", "[", "'timestamp'", "]", "=", "(", "int", ")", "$", "attribs", "[", "'timestamp'", "]", ";", "return", "$", "params", ";", "}" ]
get the params from the XML response @param SimpleXMLElement Object @return array
[ "get", "the", "params", "from", "the", "XML", "response" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L808-L821
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Realex.php
Realex.optionsFrom
private function optionsFrom($response) { $options = array(); $options['test'] = (strstr((string) $response->message, '[ test system ]')) ? true : false; $options['authorization'] = (string) $response->authcode; $options['cvv_result'] = (string) $response->cvnresult; $options['avs_result'] = array( 'street_match' => (string) $response->avspostcoderesponse, 'postal_match' => (string) $response->avspostcoderesponse ); return $options; }
php
private function optionsFrom($response) { $options = array(); $options['test'] = (strstr((string) $response->message, '[ test system ]')) ? true : false; $options['authorization'] = (string) $response->authcode; $options['cvv_result'] = (string) $response->cvnresult; $options['avs_result'] = array( 'street_match' => (string) $response->avspostcoderesponse, 'postal_match' => (string) $response->avspostcoderesponse ); return $options; }
[ "private", "function", "optionsFrom", "(", "$", "response", ")", "{", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "'test'", "]", "=", "(", "strstr", "(", "(", "string", ")", "$", "response", "->", "message", ",", "'[ test system ]'", ")", ")", "?", "true", ":", "false", ";", "$", "options", "[", "'authorization'", "]", "=", "(", "string", ")", "$", "response", "->", "authcode", ";", "$", "options", "[", "'cvv_result'", "]", "=", "(", "string", ")", "$", "response", "->", "cvnresult", ";", "$", "options", "[", "'avs_result'", "]", "=", "array", "(", "'street_match'", "=>", "(", "string", ")", "$", "response", "->", "avspostcoderesponse", ",", "'postal_match'", "=>", "(", "string", ")", "$", "response", "->", "avspostcoderesponse", ")", ";", "return", "$", "options", ";", "}" ]
get the options from the XML response @param SimpleXMLElement Object @return array
[ "get", "the", "options", "from", "the", "XML", "response" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Realex.php#L830-L842
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/TagApi.php
TagApi.getSimilar
public function getSimilar($methodVars) { // Check for required variables if (!empty($methodVars['tag'])) { $vars = array( 'method' => 'tag.getsimilar', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); $similar = array(); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->similartags->tag as $tag) { $similar[$i]['name'] = (string) $tag->name; $similar[$i]['url'] = (string) $tag->url; $similar[$i]['streamable'] = (string) $tag->streamable; $i++; } return $similar; } else { return false; } } else { throw new InvalidArgumentException('You must include tag variable in the call for this method'); } }
php
public function getSimilar($methodVars) { // Check for required variables if (!empty($methodVars['tag'])) { $vars = array( 'method' => 'tag.getsimilar', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); $similar = array(); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->similartags->tag as $tag) { $similar[$i]['name'] = (string) $tag->name; $similar[$i]['url'] = (string) $tag->url; $similar[$i]['streamable'] = (string) $tag->streamable; $i++; } return $similar; } else { return false; } } else { throw new InvalidArgumentException('You must include tag variable in the call for this method'); } }
[ "public", "function", "getSimilar", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'tag'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'tag.getsimilar'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "$", "similar", "=", "array", "(", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "similartags", "->", "tag", "as", "$", "tag", ")", "{", "$", "similar", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "tag", "->", "name", ";", "$", "similar", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "tag", "->", "url", ";", "$", "similar", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "tag", "->", "streamable", ";", "$", "i", "++", ";", "}", "return", "$", "similar", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include tag variable in the call for this method'", ")", ";", "}", "}" ]
Search for tags similar to this one. Returns tags ranked by similarity, based on listening data @param array $methodVars An array with the following required values: <i>tag</i> @return array
[ "Search", "for", "tags", "similar", "to", "this", "one", ".", "Returns", "tags", "ranked", "by", "similarity", "based", "on", "listening", "data" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/TagApi.php#L18-L43
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/TagApi.php
TagApi.getTopAlbums
public function getTopAlbums($methodVars) { // Check for required variables if (!empty($methodVars['tag'])) { $vars = array( 'method' => 'tag.gettopalbums', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->albums->album as $album) { $topAlbums[$i]['name'] = (string) $album->name; $topAlbums[$i]['tagcount'] = (string) $album->tagcount; $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]['image']['small'] = (string) $album->image[0]; $topAlbums[$i]['image']['medium'] = (string) $album->image[1]; $topAlbums[$i]['image']['large'] = (string) $album->image[2]; $i++; } return $topAlbums; } else { return false; } } else { throw new InvalidArgumentException('You must include tag variable in the call for this method'); } }
php
public function getTopAlbums($methodVars) { // Check for required variables if (!empty($methodVars['tag'])) { $vars = array( 'method' => 'tag.gettopalbums', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->albums->album as $album) { $topAlbums[$i]['name'] = (string) $album->name; $topAlbums[$i]['tagcount'] = (string) $album->tagcount; $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]['image']['small'] = (string) $album->image[0]; $topAlbums[$i]['image']['medium'] = (string) $album->image[1]; $topAlbums[$i]['image']['large'] = (string) $album->image[2]; $i++; } return $topAlbums; } else { return false; } } else { throw new InvalidArgumentException('You must include tag variable in the call for this method'); } }
[ "public", "function", "getTopAlbums", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'tag'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'tag.gettopalbums'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "albums", "->", "album", "as", "$", "album", ")", "{", "$", "topAlbums", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "album", "->", "name", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'tagcount'", "]", "=", "(", "string", ")", "$", "album", "->", "tagcount", ";", "$", "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", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "0", "]", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "1", "]", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "topAlbums", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include tag variable in the call for this method'", ")", ";", "}", "}" ]
Get the top albums tagged by this tag, ordered by tag count @param array $methodVars An array with the following required values: <i>tag</i> @return array
[ "Get", "the", "top", "albums", "tagged", "by", "this", "tag", "ordered", "by", "tag", "count" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/TagApi.php#L50-L81
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/TagApi.php
TagApi.getTopArtists
public function getTopArtists($methodVars) { // Check for required variables if (!empty($methodVars['tag'])) { $vars = array( 'method' => 'tag.gettopartists', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->topartists->artist as $artist) { $topArtists[$i]['name'] = (string) $artist->name; $topArtists[$i]['tagcount'] = (string) $artist->tagcount; $topArtists[$i]['url'] = (string) $artist->url; $topArtists[$i]['mbid'] = (string) $artist->mbid; $topArtists[$i]['streamable'] = (string) $artist->streamable; $topArtists[$i]['image']['small'] = (string) $artist->image[0]; $topArtists[$i]['image']['medium'] = (string) $artist->image[1]; $topArtists[$i]['image']['large'] = (string) $artist->image[2]; $i++; } return $topArtists; } else { return false; } } else { throw new InvalidArgumentException('You must include tag variable in the call for this method'); } }
php
public function getTopArtists($methodVars) { // Check for required variables if (!empty($methodVars['tag'])) { $vars = array( 'method' => 'tag.gettopartists', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->topartists->artist as $artist) { $topArtists[$i]['name'] = (string) $artist->name; $topArtists[$i]['tagcount'] = (string) $artist->tagcount; $topArtists[$i]['url'] = (string) $artist->url; $topArtists[$i]['mbid'] = (string) $artist->mbid; $topArtists[$i]['streamable'] = (string) $artist->streamable; $topArtists[$i]['image']['small'] = (string) $artist->image[0]; $topArtists[$i]['image']['medium'] = (string) $artist->image[1]; $topArtists[$i]['image']['large'] = (string) $artist->image[2]; $i++; } return $topArtists; } else { return false; } } else { throw new InvalidArgumentException('You must include tag variable in the call for this method'); } }
[ "public", "function", "getTopArtists", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'tag'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'tag.gettopartists'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "topartists", "->", "artist", "as", "$", "artist", ")", "{", "$", "topArtists", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "artist", "->", "name", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'tagcount'", "]", "=", "(", "string", ")", "$", "artist", "->", "tagcount", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "artist", "->", "url", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "artist", "->", "mbid", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "artist", "->", "streamable", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "0", "]", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "1", "]", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "topArtists", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include tag variable in the call for this method'", ")", ";", "}", "}" ]
Get the top artists tagged by this tag, ordered by tag count @param array $methodVars An array with the following required values: <i>tag</i> @return array
[ "Get", "the", "top", "artists", "tagged", "by", "this", "tag", "ordered", "by", "tag", "count" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/TagApi.php#L88-L118
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/TagApi.php
TagApi.search
public function search($methodVars) { // Check for required variables if (!empty($methodVars['tag'])) { $vars = array( 'method' => 'tag.search', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/'); if ($opensearch->totalResults > 0) { $searchResults['totalResults'] = (string) $opensearch->totalResults; $searchResults['startIndex'] = (string) $opensearch->startIndex; $searchResults['itemsPerPage'] = (string) $opensearch->itemsPerPage; $i = 0; foreach ($call->results->tagmatches->tag as $tag) { $searchResults['results'][$i]['name'] = (string) $tag->name; $searchResults['results'][$i]['count'] = (string) $tag->count; $searchResults['results'][$i]['url'] = (string) $tag->url; $i++; } return $searchResults; } else { throw new NoResultsException('No results'); } } else { return false; } } else { throw new InvalidArgumentException('You must include tag variable in the call for this method'); } }
php
public function search($methodVars) { // Check for required variables if (!empty($methodVars['tag'])) { $vars = array( 'method' => 'tag.search', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/'); if ($opensearch->totalResults > 0) { $searchResults['totalResults'] = (string) $opensearch->totalResults; $searchResults['startIndex'] = (string) $opensearch->startIndex; $searchResults['itemsPerPage'] = (string) $opensearch->itemsPerPage; $i = 0; foreach ($call->results->tagmatches->tag as $tag) { $searchResults['results'][$i]['name'] = (string) $tag->name; $searchResults['results'][$i]['count'] = (string) $tag->count; $searchResults['results'][$i]['url'] = (string) $tag->url; $i++; } return $searchResults; } else { throw new NoResultsException('No results'); } } else { return false; } } else { throw new InvalidArgumentException('You must include tag variable in the call for this method'); } }
[ "public", "function", "search", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'tag'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'tag.search'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "opensearch", "=", "$", "call", "->", "results", "->", "children", "(", "'http://a9.com/-/spec/opensearch/1.1/'", ")", ";", "if", "(", "$", "opensearch", "->", "totalResults", ">", "0", ")", "{", "$", "searchResults", "[", "'totalResults'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "totalResults", ";", "$", "searchResults", "[", "'startIndex'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "startIndex", ";", "$", "searchResults", "[", "'itemsPerPage'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "itemsPerPage", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "results", "->", "tagmatches", "->", "tag", "as", "$", "tag", ")", "{", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "tag", "->", "name", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'count'", "]", "=", "(", "string", ")", "$", "tag", "->", "count", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "tag", "->", "url", ";", "$", "i", "++", ";", "}", "return", "$", "searchResults", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'No results'", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include tag variable in the call for this method'", ")", ";", "}", "}" ]
Search for a tag by name. Returns matches sorted by relevance @deprecated as of march 15 2016, 'tag.search' method is not available @param array $methodVars An array with the following required values: <i>tag</i> @return array
[ "Search", "for", "a", "tag", "by", "name", ".", "Returns", "matches", "sorted", "by", "relevance" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/TagApi.php#L260-L293
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateway.php
Gateway.ssl_request
protected function ssl_request($method, $endpoint, $data, array $options = array()) { $request = $this->request ?: new Request( $endpoint, $method, $options ); $request->setMethod($method); $request->setUrl($endpoint); $request->setBody($data); $request->setDispatcher($this->getDispatcher()); $request->setAdapter($this->getAdapter()); if (true == $request->send()) { return $request->getResponseBody(); } }
php
protected function ssl_request($method, $endpoint, $data, array $options = array()) { $request = $this->request ?: new Request( $endpoint, $method, $options ); $request->setMethod($method); $request->setUrl($endpoint); $request->setBody($data); $request->setDispatcher($this->getDispatcher()); $request->setAdapter($this->getAdapter()); if (true == $request->send()) { return $request->getResponseBody(); } }
[ "protected", "function", "ssl_request", "(", "$", "method", ",", "$", "endpoint", ",", "$", "data", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "request", "=", "$", "this", "->", "request", "?", ":", "new", "Request", "(", "$", "endpoint", ",", "$", "method", ",", "$", "options", ")", ";", "$", "request", "->", "setMethod", "(", "$", "method", ")", ";", "$", "request", "->", "setUrl", "(", "$", "endpoint", ")", ";", "$", "request", "->", "setBody", "(", "$", "data", ")", ";", "$", "request", "->", "setDispatcher", "(", "$", "this", "->", "getDispatcher", "(", ")", ")", ";", "$", "request", "->", "setAdapter", "(", "$", "this", "->", "getAdapter", "(", ")", ")", ";", "if", "(", "true", "==", "$", "request", "->", "send", "(", ")", ")", "{", "return", "$", "request", "->", "getResponseBody", "(", ")", ";", "}", "}" ]
Send a request to a remote server, and return the response. @param string $method Method to use ('post' or 'get') @param string $endpoint URL of remote endpoint to connect to @param string $data Body to include with the request @param array $options Additional options for the request (see {@link AktiveMerchant\Http\Request}) @throws AktiveMerchant\Billing\Exception If the request fails at the HTTP layer @return string Response from server
[ "Send", "a", "request", "to", "a", "remote", "server", "and", "return", "the", "response", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateway.php#L294-L312
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateway.php
Gateway.urlize
protected function urlize($params) { $string = ""; foreach ($params as $key => $value) { $string .= $key . '=' . urlencode(trim($value)) . '&'; } return rtrim($string, "& "); }
php
protected function urlize($params) { $string = ""; foreach ($params as $key => $value) { $string .= $key . '=' . urlencode(trim($value)) . '&'; } return rtrim($string, "& "); }
[ "protected", "function", "urlize", "(", "$", "params", ")", "{", "$", "string", "=", "\"\"", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "string", ".=", "$", "key", ".", "'='", ".", "urlencode", "(", "trim", "(", "$", "value", ")", ")", ".", "'&'", ";", "}", "return", "rtrim", "(", "$", "string", ",", "\"& \"", ")", ";", "}" ]
Convert an associative array to url parameters @param array key/value hash of parameters @return string
[ "Convert", "an", "associative", "array", "to", "url", "parameters" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateway.php#L352-L359
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateway.php
Gateway.cc_format
protected function cc_format($number, $options) { if (empty($number)) { return ''; } switch ($options) { case 'two_digits': $number = sprintf("%02d", $number); return substr($number, -2); break; case 'four_digits': return sprintf("%04d", $number); break; default: return $number; break; } }
php
protected function cc_format($number, $options) { if (empty($number)) { return ''; } switch ($options) { case 'two_digits': $number = sprintf("%02d", $number); return substr($number, -2); break; case 'four_digits': return sprintf("%04d", $number); break; default: return $number; break; } }
[ "protected", "function", "cc_format", "(", "$", "number", ",", "$", "options", ")", "{", "if", "(", "empty", "(", "$", "number", ")", ")", "{", "return", "''", ";", "}", "switch", "(", "$", "options", ")", "{", "case", "'two_digits'", ":", "$", "number", "=", "sprintf", "(", "\"%02d\"", ",", "$", "number", ")", ";", "return", "substr", "(", "$", "number", ",", "-", "2", ")", ";", "break", ";", "case", "'four_digits'", ":", "return", "sprintf", "(", "\"%04d\"", ",", "$", "number", ")", ";", "break", ";", "default", ":", "return", "$", "number", ";", "break", ";", "}", "}" ]
Formats values from a credit card. Used to format mont or year values to 2 or 4 digit numbers. @param integer $number The number to format @param string $options 'two_digits' or 'four_digits' @return string
[ "Formats", "values", "from", "a", "credit", "card", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateway.php#L384-L402
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateway.php
Gateway.currency_lookup
protected function currency_lookup($code) { $currency = new CurrencyCode(); if (isset($currency[$code])) { return $currency[$code]; } return false; }
php
protected function currency_lookup($code) { $currency = new CurrencyCode(); if (isset($currency[$code])) { return $currency[$code]; } return false; }
[ "protected", "function", "currency_lookup", "(", "$", "code", ")", "{", "$", "currency", "=", "new", "CurrencyCode", "(", ")", ";", "if", "(", "isset", "(", "$", "currency", "[", "$", "code", "]", ")", ")", "{", "return", "$", "currency", "[", "$", "code", "]", ";", "}", "return", "false", ";", "}" ]
Lookup for numeric currency codes and returns numeric represantation of ISO 4217 currency code. @param string $code @return string|false
[ "Lookup", "for", "numeric", "currency", "codes", "and", "returns", "numeric", "represantation", "of", "ISO", "4217", "currency", "code", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateway.php#L412-L421
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateway.php
Gateway.addListener
public function addListener($eventName, $listener, $priority = 0) { $this->getDispatcher()->addListener($eventName, $listener, $priority); }
php
public function addListener($eventName, $listener, $priority = 0) { $this->getDispatcher()->addListener($eventName, $listener, $priority); }
[ "public", "function", "addListener", "(", "$", "eventName", ",", "$", "listener", ",", "$", "priority", "=", "0", ")", "{", "$", "this", "->", "getDispatcher", "(", ")", "->", "addListener", "(", "$", "eventName", ",", "$", "listener", ",", "$", "priority", ")", ";", "}" ]
Add a listener to gateway event. @param string $eventName @param string $listener @param int $priority @return void
[ "Add", "a", "listener", "to", "gateway", "event", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateway.php#L432-L435
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/AuthorizeNet.php
AuthorizeNet.parse
private function parse($body) { if (empty($body)) { throw new Exception('Error parsing credit card response: Empty response'); } $fields = explode('|', $body); if (count($fields) < 39) { throw new Exception('Error parsing credit card response: Too few fields'); } $response = array( 'response_code' => $fields[self::RESPONSE_CODE], 'response_reason_code' => $fields[self::RESPONSE_REASON_CODE], 'response_reason_text' => $fields[self::RESPONSE_REASON_TEXT], 'avs_result_code' => $fields[self::AVS_RESULT_CODE], 'transaction_id' => $fields[self::TRANSACTION_ID], 'card_code' => $fields[self::CARD_CODE_RESPONSE_CODE] ); return $response; }
php
private function parse($body) { if (empty($body)) { throw new Exception('Error parsing credit card response: Empty response'); } $fields = explode('|', $body); if (count($fields) < 39) { throw new Exception('Error parsing credit card response: Too few fields'); } $response = array( 'response_code' => $fields[self::RESPONSE_CODE], 'response_reason_code' => $fields[self::RESPONSE_REASON_CODE], 'response_reason_text' => $fields[self::RESPONSE_REASON_TEXT], 'avs_result_code' => $fields[self::AVS_RESULT_CODE], 'transaction_id' => $fields[self::TRANSACTION_ID], 'card_code' => $fields[self::CARD_CODE_RESPONSE_CODE] ); return $response; }
[ "private", "function", "parse", "(", "$", "body", ")", "{", "if", "(", "empty", "(", "$", "body", ")", ")", "{", "throw", "new", "Exception", "(", "'Error parsing credit card response: Empty response'", ")", ";", "}", "$", "fields", "=", "explode", "(", "'|'", ",", "$", "body", ")", ";", "if", "(", "count", "(", "$", "fields", ")", "<", "39", ")", "{", "throw", "new", "Exception", "(", "'Error parsing credit card response: Too few fields'", ")", ";", "}", "$", "response", "=", "array", "(", "'response_code'", "=>", "$", "fields", "[", "self", "::", "RESPONSE_CODE", "]", ",", "'response_reason_code'", "=>", "$", "fields", "[", "self", "::", "RESPONSE_REASON_CODE", "]", ",", "'response_reason_text'", "=>", "$", "fields", "[", "self", "::", "RESPONSE_REASON_TEXT", "]", ",", "'avs_result_code'", "=>", "$", "fields", "[", "self", "::", "AVS_RESULT_CODE", "]", ",", "'transaction_id'", "=>", "$", "fields", "[", "self", "::", "TRANSACTION_ID", "]", ",", "'card_code'", "=>", "$", "fields", "[", "self", "::", "CARD_CODE_RESPONSE_CODE", "]", ")", ";", "return", "$", "response", ";", "}" ]
Parse raw gateway body response. @param string $body raw gateway response @return array gateway response in array format.
[ "Parse", "raw", "gateway", "body", "response", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/AuthorizeNet.php#L393-L415
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/AuthApi.php
AuthApi.getSession
private function getSession() { $vars = array( 'method' => 'auth.getSession', 'api_key' => $this->apiKey, 'token' => $this->token ); $sig = $this->apiSig($this->apiSecret, $vars); $vars['api_sig'] = $sig; if ($call = $this->apiGetCall($vars)) { $this->username = (string) $call->session->name; $this->sessionKey = (string) $call->session->key; $this->subscriber = (string) $call->session->subscriber; } else { return false; } }
php
private function getSession() { $vars = array( 'method' => 'auth.getSession', 'api_key' => $this->apiKey, 'token' => $this->token ); $sig = $this->apiSig($this->apiSecret, $vars); $vars['api_sig'] = $sig; if ($call = $this->apiGetCall($vars)) { $this->username = (string) $call->session->name; $this->sessionKey = (string) $call->session->key; $this->subscriber = (string) $call->session->subscriber; } else { return false; } }
[ "private", "function", "getSession", "(", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'auth.getSession'", ",", "'api_key'", "=>", "$", "this", "->", "apiKey", ",", "'token'", "=>", "$", "this", "->", "token", ")", ";", "$", "sig", "=", "$", "this", "->", "apiSig", "(", "$", "this", "->", "apiSecret", ",", "$", "vars", ")", ";", "$", "vars", "[", "'api_sig'", "]", "=", "$", "sig", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "this", "->", "username", "=", "(", "string", ")", "$", "call", "->", "session", "->", "name", ";", "$", "this", "->", "sessionKey", "=", "(", "string", ")", "$", "call", "->", "session", "->", "key", ";", "$", "this", "->", "subscriber", "=", "(", "string", ")", "$", "call", "->", "session", "->", "subscriber", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Internal method uses to get a new session via an api call @return void @access private
[ "Internal", "method", "uses", "to", "get", "a", "new", "session", "via", "an", "api", "call" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/AuthApi.php#L106-L123
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/AuthApi.php
AuthApi.getToken
private function getToken() { $vars = array( 'method' => 'auth.getToken', 'api_key' => $this->apiKey ); $sig = $this->apiSig($this->apiSecret, $vars); $vars['api_sig'] = $sig; if ($call = $this->apiGetCall($vars)) { $this->token = $call->token; } else { return false; } }
php
private function getToken() { $vars = array( 'method' => 'auth.getToken', 'api_key' => $this->apiKey ); $sig = $this->apiSig($this->apiSecret, $vars); $vars['api_sig'] = $sig; if ($call = $this->apiGetCall($vars)) { $this->token = $call->token; } else { return false; } }
[ "private", "function", "getToken", "(", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'auth.getToken'", ",", "'api_key'", "=>", "$", "this", "->", "apiKey", ")", ";", "$", "sig", "=", "$", "this", "->", "apiSig", "(", "$", "this", "->", "apiSecret", ",", "$", "vars", ")", ";", "$", "vars", "[", "'api_sig'", "]", "=", "$", "sig", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "this", "->", "token", "=", "$", "call", "->", "token", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Internal method uses to get a new token via an api call @return void @access private
[ "Internal", "method", "uses", "to", "get", "a", "new", "token", "via", "an", "api", "call" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/AuthApi.php#L130-L145
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/LibraryApi.php
LibraryApi.getAlbums
public function getAlbums($methodVars) { // Check for required variables if (!empty($methodVars['user'])) { $vars = array( 'method' => 'library.getalbums', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $albums['page'] = (string) $call->albums['page']; $albums['perPage'] = (string) $call->albums['perPage']; $albums['totalPages'] = (string) $call->albums['totalPages']; $i = 0; foreach ($call->albums->album as $album) { $albums['results'][$i]['name'] = (string) $album->name; // THIS DOESN'T WORK AS DOCUMENTED --- $albums['results'][$i]['rank'] = (string) $album['rank']; $albums['results'][$i]['playcount'] = (string) $album->playcount; $albums['results'][$i]['tagcount'] = (string) $album->tagcount; $albums['results'][$i]['mbid'] = (string) $album->mbid; $albums['results'][$i]['url'] = (string) $album->url; $albums['results'][$i]['artist']['name'] = (string) $album->artist->name; $albums['results'][$i]['artist']['mbid'] = (string) $album->artist->mbid; $albums['results'][$i]['artist']['url'] = (string) $album->artist->url; $albums['results'][$i]['image']['small'] = (string) $album->image[0]; $albums['results'][$i]['image']['medium'] = (string) $album->image[1]; $albums['results'][$i]['image']['large'] = (string) $album->image[2]; $i++; } return $albums; } else { return false; } } else { throw new InvalidArgumentException('You must include a user variable in the call for this method'); } }
php
public function getAlbums($methodVars) { // Check for required variables if (!empty($methodVars['user'])) { $vars = array( 'method' => 'library.getalbums', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $albums['page'] = (string) $call->albums['page']; $albums['perPage'] = (string) $call->albums['perPage']; $albums['totalPages'] = (string) $call->albums['totalPages']; $i = 0; foreach ($call->albums->album as $album) { $albums['results'][$i]['name'] = (string) $album->name; // THIS DOESN'T WORK AS DOCUMENTED --- $albums['results'][$i]['rank'] = (string) $album['rank']; $albums['results'][$i]['playcount'] = (string) $album->playcount; $albums['results'][$i]['tagcount'] = (string) $album->tagcount; $albums['results'][$i]['mbid'] = (string) $album->mbid; $albums['results'][$i]['url'] = (string) $album->url; $albums['results'][$i]['artist']['name'] = (string) $album->artist->name; $albums['results'][$i]['artist']['mbid'] = (string) $album->artist->mbid; $albums['results'][$i]['artist']['url'] = (string) $album->artist->url; $albums['results'][$i]['image']['small'] = (string) $album->image[0]; $albums['results'][$i]['image']['medium'] = (string) $album->image[1]; $albums['results'][$i]['image']['large'] = (string) $album->image[2]; $i++; } return $albums; } else { return false; } } else { throw new InvalidArgumentException('You must include a user variable in the call for this method'); } }
[ "public", "function", "getAlbums", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'user'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'library.getalbums'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "albums", "[", "'page'", "]", "=", "(", "string", ")", "$", "call", "->", "albums", "[", "'page'", "]", ";", "$", "albums", "[", "'perPage'", "]", "=", "(", "string", ")", "$", "call", "->", "albums", "[", "'perPage'", "]", ";", "$", "albums", "[", "'totalPages'", "]", "=", "(", "string", ")", "$", "call", "->", "albums", "[", "'totalPages'", "]", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "albums", "->", "album", "as", "$", "album", ")", "{", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "album", "->", "name", ";", "// THIS DOESN'T WORK AS DOCUMENTED --- $albums['results'][$i]['rank'] = (string) $album['rank'];", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'playcount'", "]", "=", "(", "string", ")", "$", "album", "->", "playcount", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'tagcount'", "]", "=", "(", "string", ")", "$", "album", "->", "tagcount", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "album", "->", "mbid", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "album", "->", "url", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "album", "->", "artist", "->", "name", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "album", "->", "artist", "->", "mbid", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "album", "->", "artist", "->", "url", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "0", "]", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "1", "]", ";", "$", "albums", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "albums", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include a user variable in the call for this method'", ")", ";", "}", "}" ]
A paginated list of all the albums in a user's library, with play counts and tag counts @deprecated as of march 15 2016, 'library.getalbums' service is not available @param array $methodVars An array with the following required values: <i>user</i> and optional values: <i>page</i>, <i>limit</i> @return array
[ "A", "paginated", "list", "of", "all", "the", "albums", "in", "a", "user", "s", "library", "with", "play", "counts", "and", "tag", "counts" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/LibraryApi.php#L117-L154
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/LibraryApi.php
LibraryApi.getArtists
public function getArtists($methodVars) { // Check for required variables if (!empty($methodVars['user'])) { $vars = array( 'method' => 'library.getartists', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $artists['page'] = (string) $call->artists['page']; $artists['perPage'] = (string) $call->artists['perPage']; $artists['totalPages'] = (string) $call->artists['totalPages']; $i = 0; foreach ($call->artists->artist as $artist) { $artists['results'][$i]['name'] = (string) $artist->name; // THIS DOESN'T WORK AS DOCUMENTED --- $artists['results'][$i]['rank'] = (string) $artist['rank']; $artists['results'][$i]['playcount'] = (string) $artist->playcount; $artists['results'][$i]['tagcount'] = (string) $artist->tagcount; $artists['results'][$i]['mbid'] = (string) $artist->mbid; $artists['results'][$i]['url'] = (string) $artist->url; $artists['results'][$i]['streamable'] = (string) $artist->streamable; $artists['results'][$i]['image']['small'] = (string) $artist->image[0]; $artists['results'][$i]['image']['medium'] = (string) $artist->image[1]; $artists['results'][$i]['image']['large'] = (string) $artist->image[2]; $i++; } return $artists; } else { return false; } } else { throw new InvalidArgumentException('You must include a user variable in the call for this method'); } }
php
public function getArtists($methodVars) { // Check for required variables if (!empty($methodVars['user'])) { $vars = array( 'method' => 'library.getartists', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $artists['page'] = (string) $call->artists['page']; $artists['perPage'] = (string) $call->artists['perPage']; $artists['totalPages'] = (string) $call->artists['totalPages']; $i = 0; foreach ($call->artists->artist as $artist) { $artists['results'][$i]['name'] = (string) $artist->name; // THIS DOESN'T WORK AS DOCUMENTED --- $artists['results'][$i]['rank'] = (string) $artist['rank']; $artists['results'][$i]['playcount'] = (string) $artist->playcount; $artists['results'][$i]['tagcount'] = (string) $artist->tagcount; $artists['results'][$i]['mbid'] = (string) $artist->mbid; $artists['results'][$i]['url'] = (string) $artist->url; $artists['results'][$i]['streamable'] = (string) $artist->streamable; $artists['results'][$i]['image']['small'] = (string) $artist->image[0]; $artists['results'][$i]['image']['medium'] = (string) $artist->image[1]; $artists['results'][$i]['image']['large'] = (string) $artist->image[2]; $i++; } return $artists; } else { return false; } } else { throw new InvalidArgumentException('You must include a user variable in the call for this method'); } }
[ "public", "function", "getArtists", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'user'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'library.getartists'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "artists", "[", "'page'", "]", "=", "(", "string", ")", "$", "call", "->", "artists", "[", "'page'", "]", ";", "$", "artists", "[", "'perPage'", "]", "=", "(", "string", ")", "$", "call", "->", "artists", "[", "'perPage'", "]", ";", "$", "artists", "[", "'totalPages'", "]", "=", "(", "string", ")", "$", "call", "->", "artists", "[", "'totalPages'", "]", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "artists", "->", "artist", "as", "$", "artist", ")", "{", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "artist", "->", "name", ";", "// THIS DOESN'T WORK AS DOCUMENTED --- $artists['results'][$i]['rank'] = (string) $artist['rank'];", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'playcount'", "]", "=", "(", "string", ")", "$", "artist", "->", "playcount", ";", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'tagcount'", "]", "=", "(", "string", ")", "$", "artist", "->", "tagcount", ";", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "artist", "->", "mbid", ";", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "artist", "->", "url", ";", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "artist", "->", "streamable", ";", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "0", "]", ";", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "1", "]", ";", "$", "artists", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "artists", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include a user variable in the call for this method'", ")", ";", "}", "}" ]
A paginated list of all the artists in a user's library, with play counts and tag counts @param array $methodVars An array with the following required values: <i>user</i> and optional values: <i>page</i>, <i>limit</i> @return array
[ "A", "paginated", "list", "of", "all", "the", "artists", "in", "a", "user", "s", "library", "with", "play", "counts", "and", "tag", "counts" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/LibraryApi.php#L161-L196
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/LibraryApi.php
LibraryApi.getTracks
public function getTracks($methodVars) { // Check for required variables if (!empty($methodVars['user'])) { $vars = array( 'method' => 'library.gettracks', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $tracks['page'] = (string) $call->tracks['page']; $tracks['perPage'] = (string) $call->tracks['perPage']; $tracks['totalPages'] = (string) $call->tracks['totalPages']; $i = 0; foreach ($call->tracks->track as $track) { $tracks['results'][$i]['name'] = (string) $track->name; // THIS DOESN'T WORK AS DOCUMENTED --- $tracks['results'][$i]['rank'] = (string) $track['rank']; $tracks['results'][$i]['playcount'] = (string) $track->playcount; $tracks['results'][$i]['tagcount'] = (string) $track->tagcount; $tracks['results'][$i]['url'] = (string) $track->url; $tracks['results'][$i]['streamable'] = (string) $track->streamable; $tracks['results'][$i]['fulltrack'] = (string) $track->streamable['fulltrack']; $tracks['results'][$i]['artist']['name'] = (string) $track->artist->name; $tracks['results'][$i]['artist']['mbid'] = (string) $track->artist->mbid; $tracks['results'][$i]['artist']['url'] = (string) $track->artist->url; $tracks['results'][$i]['image']['small'] = (string) $track->image[0]; $tracks['results'][$i]['image']['medium'] = (string) $track->image[1]; $tracks['results'][$i]['image']['large'] = (string) $track->image[2]; $i++; } return $tracks; } else { return false; } } else { throw new InvalidArgumentException('You must include a user variable in the call for this method'); } }
php
public function getTracks($methodVars) { // Check for required variables if (!empty($methodVars['user'])) { $vars = array( 'method' => 'library.gettracks', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $tracks['page'] = (string) $call->tracks['page']; $tracks['perPage'] = (string) $call->tracks['perPage']; $tracks['totalPages'] = (string) $call->tracks['totalPages']; $i = 0; foreach ($call->tracks->track as $track) { $tracks['results'][$i]['name'] = (string) $track->name; // THIS DOESN'T WORK AS DOCUMENTED --- $tracks['results'][$i]['rank'] = (string) $track['rank']; $tracks['results'][$i]['playcount'] = (string) $track->playcount; $tracks['results'][$i]['tagcount'] = (string) $track->tagcount; $tracks['results'][$i]['url'] = (string) $track->url; $tracks['results'][$i]['streamable'] = (string) $track->streamable; $tracks['results'][$i]['fulltrack'] = (string) $track->streamable['fulltrack']; $tracks['results'][$i]['artist']['name'] = (string) $track->artist->name; $tracks['results'][$i]['artist']['mbid'] = (string) $track->artist->mbid; $tracks['results'][$i]['artist']['url'] = (string) $track->artist->url; $tracks['results'][$i]['image']['small'] = (string) $track->image[0]; $tracks['results'][$i]['image']['medium'] = (string) $track->image[1]; $tracks['results'][$i]['image']['large'] = (string) $track->image[2]; $i++; } return $tracks; } else { return false; } } else { throw new InvalidArgumentException('You must include a user variable in the call for this method'); } }
[ "public", "function", "getTracks", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'user'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'library.gettracks'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "tracks", "[", "'page'", "]", "=", "(", "string", ")", "$", "call", "->", "tracks", "[", "'page'", "]", ";", "$", "tracks", "[", "'perPage'", "]", "=", "(", "string", ")", "$", "call", "->", "tracks", "[", "'perPage'", "]", ";", "$", "tracks", "[", "'totalPages'", "]", "=", "(", "string", ")", "$", "call", "->", "tracks", "[", "'totalPages'", "]", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "tracks", "->", "track", "as", "$", "track", ")", "{", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "track", "->", "name", ";", "// THIS DOESN'T WORK AS DOCUMENTED --- $tracks['results'][$i]['rank'] = (string) $track['rank'];", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'playcount'", "]", "=", "(", "string", ")", "$", "track", "->", "playcount", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'tagcount'", "]", "=", "(", "string", ")", "$", "track", "->", "tagcount", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "track", "->", "url", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "track", "->", "streamable", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'fulltrack'", "]", "=", "(", "string", ")", "$", "track", "->", "streamable", "[", "'fulltrack'", "]", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "track", "->", "artist", "->", "name", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "track", "->", "artist", "->", "mbid", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "track", "->", "artist", "->", "url", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "0", "]", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "1", "]", ";", "$", "tracks", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "tracks", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include a user variable in the call for this method'", ")", ";", "}", "}" ]
A paginated list of all the tracks in a user's library, with play counts and tag counts @param array $methodVars An array with the following required values: <i>user</i> and optional values: <i>page</i>, <i>limit</i> @return array
[ "A", "paginated", "list", "of", "all", "the", "tracks", "in", "a", "user", "s", "library", "with", "play", "counts", "and", "tag", "counts" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/LibraryApi.php#L203-L241
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Modirum.php
Modirum.calculateDigest
protected function calculateDigest($xml) { $xml = $this->canonicalize($xml); $utf8 = utf8_encode($xml . $this->options['shared_secret']); return base64_encode(sha1($utf8, true)); }
php
protected function calculateDigest($xml) { $xml = $this->canonicalize($xml); $utf8 = utf8_encode($xml . $this->options['shared_secret']); return base64_encode(sha1($utf8, true)); }
[ "protected", "function", "calculateDigest", "(", "$", "xml", ")", "{", "$", "xml", "=", "$", "this", "->", "canonicalize", "(", "$", "xml", ")", ";", "$", "utf8", "=", "utf8_encode", "(", "$", "xml", ".", "$", "this", "->", "options", "[", "'shared_secret'", "]", ")", ";", "return", "base64_encode", "(", "sha1", "(", "$", "utf8", ",", "true", ")", ")", ";", "}" ]
Calculate digest for message. @param string $xml @return string
[ "Calculate", "digest", "for", "message", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Modirum.php#L492-L498
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/Modirum.php
Modirum.canonicalize
protected function canonicalize($xml) { $xml = str_replace('<?xml version="1.0" encoding="UTF-8"?>', null, $xml); $replacement = 'xmlns="http://www.modirum.com/schemas" '; $start = 0; $length = 9; $xml = substr($xml, $start, $length) . substr_replace($xml, $replacement, $start, $length); $dom = new \DOMDocument("1.0", "utf-8"); $dom->loadXML($xml); $xml = $dom->C14N(); return $xml; }
php
protected function canonicalize($xml) { $xml = str_replace('<?xml version="1.0" encoding="UTF-8"?>', null, $xml); $replacement = 'xmlns="http://www.modirum.com/schemas" '; $start = 0; $length = 9; $xml = substr($xml, $start, $length) . substr_replace($xml, $replacement, $start, $length); $dom = new \DOMDocument("1.0", "utf-8"); $dom->loadXML($xml); $xml = $dom->C14N(); return $xml; }
[ "protected", "function", "canonicalize", "(", "$", "xml", ")", "{", "$", "xml", "=", "str_replace", "(", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'", ",", "null", ",", "$", "xml", ")", ";", "$", "replacement", "=", "'xmlns=\"http://www.modirum.com/schemas\" '", ";", "$", "start", "=", "0", ";", "$", "length", "=", "9", ";", "$", "xml", "=", "substr", "(", "$", "xml", ",", "$", "start", ",", "$", "length", ")", ".", "substr_replace", "(", "$", "xml", ",", "$", "replacement", ",", "$", "start", ",", "$", "length", ")", ";", "$", "dom", "=", "new", "\\", "DOMDocument", "(", "\"1.0\"", ",", "\"utf-8\"", ")", ";", "$", "dom", "->", "loadXML", "(", "$", "xml", ")", ";", "$", "xml", "=", "$", "dom", "->", "C14N", "(", ")", ";", "return", "$", "xml", ";", "}" ]
Canonicalize message element according to specs. @param string $message @return string
[ "Canonicalize", "message", "element", "according", "to", "specs", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/Modirum.php#L506-L522
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Base.php
Base.gateway
public static function gateway($name = null, $options = array()) { $gateway = "\\AktiveMerchant\\Billing\\Gateways\\" . Inflect::camelize($name); if (class_exists($gateway)) { return new $gateway($options); } throw new Exception("Unable to load class: {$gateway}."); }
php
public static function gateway($name = null, $options = array()) { $gateway = "\\AktiveMerchant\\Billing\\Gateways\\" . Inflect::camelize($name); if (class_exists($gateway)) { return new $gateway($options); } throw new Exception("Unable to load class: {$gateway}."); }
[ "public", "static", "function", "gateway", "(", "$", "name", "=", "null", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "gateway", "=", "\"\\\\AktiveMerchant\\\\Billing\\\\Gateways\\\\\"", ".", "Inflect", "::", "camelize", "(", "$", "name", ")", ";", "if", "(", "class_exists", "(", "$", "gateway", ")", ")", "{", "return", "new", "$", "gateway", "(", "$", "options", ")", ";", "}", "throw", "new", "Exception", "(", "\"Unable to load class: {$gateway}.\"", ")", ";", "}" ]
Factory method for gateways. Return the matching gateway for the provider $name must be the name of the gateway class in underscore format for AuthorizeNet gateway will be authorize_net <code> AktiveMerchant\Billing\Base::gateway('authorize_net'); </code> @param string $name the underscored name of the gateway. @param array $options the options for gateway construct. @return \AktiveMerchant\Billing\Gateway the gateway instance
[ "Factory", "method", "for", "gateways", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Base.php#L72-L81
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ChartApi.php
ChartApi.getTopArtists
public function getTopArtists($methodVars) { $vars = array( 'method' => 'chart.gettopartists', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->artists->artist as $artist) { $topArtists[$i]['name'] = (string) $artist->name; $topArtists[$i]['playcount'] = (string) $artist->playcount; $topArtists[$i]['listeners'] = (string) $artist->listeners; $topArtists[$i]['mbid'] = (string) $artist->mbid; $topArtists[$i]['url'] = (string) $artist->url; $topArtists[$i]['streamable'] = (string) $artist->streamable; $topArtists[$i]['image']['small'] = (string) $artist->image[0]; $topArtists[$i]['image']['medium'] = (string) $artist->image[1]; $topArtists[$i]['image']['large'] = (string) $artist->image[2]; $topArtists[$i]['image']['extralarge'] = (string) $artist->image[3]; $topArtists[$i]['image']['mega'] = (string) $artist->image[4]; $i++; } return $topArtists; } else { return false; } }
php
public function getTopArtists($methodVars) { $vars = array( 'method' => 'chart.gettopartists', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->artists->artist as $artist) { $topArtists[$i]['name'] = (string) $artist->name; $topArtists[$i]['playcount'] = (string) $artist->playcount; $topArtists[$i]['listeners'] = (string) $artist->listeners; $topArtists[$i]['mbid'] = (string) $artist->mbid; $topArtists[$i]['url'] = (string) $artist->url; $topArtists[$i]['streamable'] = (string) $artist->streamable; $topArtists[$i]['image']['small'] = (string) $artist->image[0]; $topArtists[$i]['image']['medium'] = (string) $artist->image[1]; $topArtists[$i]['image']['large'] = (string) $artist->image[2]; $topArtists[$i]['image']['extralarge'] = (string) $artist->image[3]; $topArtists[$i]['image']['mega'] = (string) $artist->image[4]; $i++; } return $topArtists; } else { return false; } }
[ "public", "function", "getTopArtists", "(", "$", "methodVars", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'chart.gettopartists'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "artists", "->", "artist", "as", "$", "artist", ")", "{", "$", "topArtists", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "artist", "->", "name", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'playcount'", "]", "=", "(", "string", ")", "$", "artist", "->", "playcount", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'listeners'", "]", "=", "(", "string", ")", "$", "artist", "->", "listeners", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "artist", "->", "mbid", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "artist", "->", "url", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "artist", "->", "streamable", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "0", "]", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "1", "]", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "2", "]", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'image'", "]", "[", "'extralarge'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "3", "]", ";", "$", "topArtists", "[", "$", "i", "]", "[", "'image'", "]", "[", "'mega'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "4", "]", ";", "$", "i", "++", ";", "}", "return", "$", "topArtists", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Get the top artists chart @param array $methodVars An array with the optional value: <i>limit</i>, <i>page</i> @return array|false
[ "Get", "the", "top", "artists", "chart" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ChartApi.php#L16-L45
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ChartApi.php
ChartApi.getTopTags
public function getTopTags($methodVars) { $vars = array( 'method' => 'chart.gettoptags', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->tags->tag as $tags) { $topTags[$i]['name'] = (string) $tags->name; $topTags[$i]['playcount'] = (string) $tags->playcount; $topTags[$i]['listeners'] = (string) $tags->listeners; $topTags[$i]['mbid'] = (string) $tags->mbid; $topTags[$i]['url'] = (string) $tags->url; $topTags[$i]['streamable'] = (string) $tags->streamable; $topTags[$i]['image']['small'] = (string) $tags->image[0]; $topTags[$i]['image']['medium'] = (string) $tags->image[1]; $topTags[$i]['image']['large'] = (string) $tags->image[2]; $topTags[$i]['image']['extralarge'] = (string) $tags->image[3]; $topTags[$i]['image']['mega'] = (string) $tags->image[4]; $i++; } return $topTags; } else { return false; } }
php
public function getTopTags($methodVars) { $vars = array( 'method' => 'chart.gettoptags', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->tags->tag as $tags) { $topTags[$i]['name'] = (string) $tags->name; $topTags[$i]['playcount'] = (string) $tags->playcount; $topTags[$i]['listeners'] = (string) $tags->listeners; $topTags[$i]['mbid'] = (string) $tags->mbid; $topTags[$i]['url'] = (string) $tags->url; $topTags[$i]['streamable'] = (string) $tags->streamable; $topTags[$i]['image']['small'] = (string) $tags->image[0]; $topTags[$i]['image']['medium'] = (string) $tags->image[1]; $topTags[$i]['image']['large'] = (string) $tags->image[2]; $topTags[$i]['image']['extralarge'] = (string) $tags->image[3]; $topTags[$i]['image']['mega'] = (string) $tags->image[4]; $i++; } return $topTags; } else { return false; } }
[ "public", "function", "getTopTags", "(", "$", "methodVars", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'chart.gettoptags'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "tags", "->", "tag", "as", "$", "tags", ")", "{", "$", "topTags", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "tags", "->", "name", ";", "$", "topTags", "[", "$", "i", "]", "[", "'playcount'", "]", "=", "(", "string", ")", "$", "tags", "->", "playcount", ";", "$", "topTags", "[", "$", "i", "]", "[", "'listeners'", "]", "=", "(", "string", ")", "$", "tags", "->", "listeners", ";", "$", "topTags", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "tags", "->", "mbid", ";", "$", "topTags", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "tags", "->", "url", ";", "$", "topTags", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "tags", "->", "streamable", ";", "$", "topTags", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "tags", "->", "image", "[", "0", "]", ";", "$", "topTags", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "tags", "->", "image", "[", "1", "]", ";", "$", "topTags", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "tags", "->", "image", "[", "2", "]", ";", "$", "topTags", "[", "$", "i", "]", "[", "'image'", "]", "[", "'extralarge'", "]", "=", "(", "string", ")", "$", "tags", "->", "image", "[", "3", "]", ";", "$", "topTags", "[", "$", "i", "]", "[", "'image'", "]", "[", "'mega'", "]", "=", "(", "string", ")", "$", "tags", "->", "image", "[", "4", "]", ";", "$", "i", "++", ";", "}", "return", "$", "topTags", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Get the top tags chart @param array $methodVars An array with the optional value: <i>limit</i>, <i>page</i> @return array|false
[ "Get", "the", "top", "tags", "chart" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ChartApi.php#L52-L81
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ChartApi.php
ChartApi.getTopTracks
public function getTopTracks($methodVars) { $vars = array( 'method' => 'chart.gettoptracks', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->tracks->track as $track) { $topTracks[$i]['name'] = (string) $track->name; $topTracks[$i]['playcount'] = (string) $track->playcount; $topTracks[$i]['listeners'] = (string) $track->listeners; $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]['image']['small'] = (string) $track->image[0]; $topTracks[$i]['image']['medium'] = (string) $track->image[1]; $topTracks[$i]['image']['large'] = (string) $track->image[2]; // $topTracks[$i]['image']['extralarge'] = (string) $track->image[3]; // $topTracks[$i]['image']['mega'] = (string) $track->image[4]; $i++; } return $topTracks; } else { return false; } }
php
public function getTopTracks($methodVars) { $vars = array( 'method' => 'chart.gettoptracks', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $i = 0; foreach ($call->tracks->track as $track) { $topTracks[$i]['name'] = (string) $track->name; $topTracks[$i]['playcount'] = (string) $track->playcount; $topTracks[$i]['listeners'] = (string) $track->listeners; $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]['image']['small'] = (string) $track->image[0]; $topTracks[$i]['image']['medium'] = (string) $track->image[1]; $topTracks[$i]['image']['large'] = (string) $track->image[2]; // $topTracks[$i]['image']['extralarge'] = (string) $track->image[3]; // $topTracks[$i]['image']['mega'] = (string) $track->image[4]; $i++; } return $topTracks; } else { return false; } }
[ "public", "function", "getTopTracks", "(", "$", "methodVars", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'chart.gettoptracks'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "tracks", "->", "track", "as", "$", "track", ")", "{", "$", "topTracks", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "track", "->", "name", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'playcount'", "]", "=", "(", "string", ")", "$", "track", "->", "playcount", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'listeners'", "]", "=", "(", "string", ")", "$", "track", "->", "listeners", ";", "$", "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", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "0", "]", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "1", "]", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "2", "]", ";", "// $topTracks[$i]['image']['extralarge'] = (string) $track->image[3];", "// $topTracks[$i]['image']['mega'] = (string) $track->image[4];", "$", "i", "++", ";", "}", "return", "$", "topTracks", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Get the top tracks chart @param array $methodVars An array with the optional value: <i>limit</i>, <i>page</i> @return array|false
[ "Get", "the", "top", "tracks", "chart" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ChartApi.php#L88-L121
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/TrackApi.php
TrackApi.getSimilar
public function getSimilar($methodVars) { // Check for required variables if ( !empty($methodVars['artist']) && !empty($methodVars['track']) ) { $vars = array( 'method' => 'track.getsimilar', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ( $call = $this->apiGetCall($vars) ) { if ( count($call->similartracks->track) > 0 ) { $i = 0; foreach ( $call->similartracks->track as $track ) { $similar[$i]['name'] = (string) $track->name; $similar[$i]['match'] = (string) $track->match; $similar[$i]['mbid'] = (string) $track->mbid; $similar[$i]['url'] = (string) $track->url; $similar[$i]['streamable'] = (string) $track->streamable; $similar[$i]['fulltrack'] = (string) $track->streamable['fulltrack']; $similar[$i]['artist']['name'] = (string) $track->artist->name; $similar[$i]['artist']['mbid'] = (string) $track->artist->mbid; $similar[$i]['artist']['url'] = (string) $track->artist->url; $similar[$i]['images']['small'] = (string) $track->image[0]; $similar[$i]['images']['medium'] = (string) $track->image[1]; $similar[$i]['images']['large'] = (string) $track->image[2]; $i++; } return $similar; } else { throw new NoResultsException('This track has no similar tracks'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist and track varialbes in the call for this method'); } }
php
public function getSimilar($methodVars) { // Check for required variables if ( !empty($methodVars['artist']) && !empty($methodVars['track']) ) { $vars = array( 'method' => 'track.getsimilar', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ( $call = $this->apiGetCall($vars) ) { if ( count($call->similartracks->track) > 0 ) { $i = 0; foreach ( $call->similartracks->track as $track ) { $similar[$i]['name'] = (string) $track->name; $similar[$i]['match'] = (string) $track->match; $similar[$i]['mbid'] = (string) $track->mbid; $similar[$i]['url'] = (string) $track->url; $similar[$i]['streamable'] = (string) $track->streamable; $similar[$i]['fulltrack'] = (string) $track->streamable['fulltrack']; $similar[$i]['artist']['name'] = (string) $track->artist->name; $similar[$i]['artist']['mbid'] = (string) $track->artist->mbid; $similar[$i]['artist']['url'] = (string) $track->artist->url; $similar[$i]['images']['small'] = (string) $track->image[0]; $similar[$i]['images']['medium'] = (string) $track->image[1]; $similar[$i]['images']['large'] = (string) $track->image[2]; $i++; } return $similar; } else { throw new NoResultsException('This track has no similar tracks'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist and track varialbes in the call for this method'); } }
[ "public", "function", "getSimilar", "(", "$", "methodVars", ")", "{", "// Check for required variables\r", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", "&&", "!", "empty", "(", "$", "methodVars", "[", "'track'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'track.getsimilar'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "if", "(", "count", "(", "$", "call", "->", "similartracks", "->", "track", ")", ">", "0", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "similartracks", "->", "track", "as", "$", "track", ")", "{", "$", "similar", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "track", "->", "name", ";", "$", "similar", "[", "$", "i", "]", "[", "'match'", "]", "=", "(", "string", ")", "$", "track", "->", "match", ";", "$", "similar", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "track", "->", "mbid", ";", "$", "similar", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "track", "->", "url", ";", "$", "similar", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "track", "->", "streamable", ";", "$", "similar", "[", "$", "i", "]", "[", "'fulltrack'", "]", "=", "(", "string", ")", "$", "track", "->", "streamable", "[", "'fulltrack'", "]", ";", "$", "similar", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "track", "->", "artist", "->", "name", ";", "$", "similar", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "track", "->", "artist", "->", "mbid", ";", "$", "similar", "[", "$", "i", "]", "[", "'artist'", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "track", "->", "artist", "->", "url", ";", "$", "similar", "[", "$", "i", "]", "[", "'images'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "0", "]", ";", "$", "similar", "[", "$", "i", "]", "[", "'images'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "1", "]", ";", "$", "similar", "[", "$", "i", "]", "[", "'images'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "track", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "similar", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'This track has no similar tracks'", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include artist and track varialbes in the call for this method'", ")", ";", "}", "}" ]
Get the similar tracks for this track on Last.fm, based on listening data @param array $methodVars An array with the following required values: <i>artist</i>, <i>track</i> @return array
[ "Get", "the", "similar", "tracks", "for", "this", "track", "on", "Last", ".", "fm", "based", "on", "listening", "data" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/TrackApi.php#L152-L192
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/TrackApi.php
TrackApi.getTopTags
public function getTopTags($methodVars) { // Check for required variables if ( !empty($methodVars['artist']) && !empty($methodVars['track']) ) { $vars = array( 'method' => 'track.gettoptags', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ( $call = $this->apiGetCall($vars) ) { if ( count($call->toptags->tag) > 0 ) { $topTags['artist'] = (string) $call->toptags['artist']; $topTags['track'] = (string) $call->toptags['track']; $i = 0; foreach ( $call->toptags->tag as $tag ) { $topTags['tags'][$i]['name'] = (string) $tag->name; $topTags['tags'][$i]['count'] = (string) $tag->count; $topTags['tags'][$i]['url'] = (string) $tag->url; $i++; } return $topTags; } else { throw new NoResultsException('This track has no tags'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist and track varialbes in the call for this method'); } }
php
public function getTopTags($methodVars) { // Check for required variables if ( !empty($methodVars['artist']) && !empty($methodVars['track']) ) { $vars = array( 'method' => 'track.gettoptags', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ( $call = $this->apiGetCall($vars) ) { if ( count($call->toptags->tag) > 0 ) { $topTags['artist'] = (string) $call->toptags['artist']; $topTags['track'] = (string) $call->toptags['track']; $i = 0; foreach ( $call->toptags->tag as $tag ) { $topTags['tags'][$i]['name'] = (string) $tag->name; $topTags['tags'][$i]['count'] = (string) $tag->count; $topTags['tags'][$i]['url'] = (string) $tag->url; $i++; } return $topTags; } else { throw new NoResultsException('This track has no tags'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist and track varialbes in the call for this method'); } }
[ "public", "function", "getTopTags", "(", "$", "methodVars", ")", "{", "// Check for required variables\r", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", "&&", "!", "empty", "(", "$", "methodVars", "[", "'track'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'track.gettoptags'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "if", "(", "count", "(", "$", "call", "->", "toptags", "->", "tag", ")", ">", "0", ")", "{", "$", "topTags", "[", "'artist'", "]", "=", "(", "string", ")", "$", "call", "->", "toptags", "[", "'artist'", "]", ";", "$", "topTags", "[", "'track'", "]", "=", "(", "string", ")", "$", "call", "->", "toptags", "[", "'track'", "]", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "toptags", "->", "tag", "as", "$", "tag", ")", "{", "$", "topTags", "[", "'tags'", "]", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "tag", "->", "name", ";", "$", "topTags", "[", "'tags'", "]", "[", "$", "i", "]", "[", "'count'", "]", "=", "(", "string", ")", "$", "tag", "->", "count", ";", "$", "topTags", "[", "'tags'", "]", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "tag", "->", "url", ";", "$", "i", "++", ";", "}", "return", "$", "topTags", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'This track has no tags'", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include artist and track varialbes in the call for this method'", ")", ";", "}", "}" ]
Get the top tags for this track on Last.fm, ordered by tag count @param array $methodVars An array with the following required values: <i>artist</i>, <i>track</i> @return array
[ "Get", "the", "top", "tags", "for", "this", "track", "on", "Last", ".", "fm", "ordered", "by", "tag", "count" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/TrackApi.php#L292-L325
train
joomla-framework/filesystem
src/Stream/StringWrapper.php
StringWrapper.url_stat
public function url_stat($path, $flags = 0) { $now = time(); $refPath = StringController::getRef(str_replace('string://', '', $path)); $string = &$refPath; $stat = array( 'dev' => 0, 'ino' => 0, 'mode' => 0, 'nlink' => 1, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => \strlen($string), 'atime' => $now, 'mtime' => $now, 'ctime' => $now, 'blksize' => '512', 'blocks' => ceil(\strlen($string) / 512), ); return $stat; }
php
public function url_stat($path, $flags = 0) { $now = time(); $refPath = StringController::getRef(str_replace('string://', '', $path)); $string = &$refPath; $stat = array( 'dev' => 0, 'ino' => 0, 'mode' => 0, 'nlink' => 1, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => \strlen($string), 'atime' => $now, 'mtime' => $now, 'ctime' => $now, 'blksize' => '512', 'blocks' => ceil(\strlen($string) / 512), ); return $stat; }
[ "public", "function", "url_stat", "(", "$", "path", ",", "$", "flags", "=", "0", ")", "{", "$", "now", "=", "time", "(", ")", ";", "$", "refPath", "=", "StringController", "::", "getRef", "(", "str_replace", "(", "'string://'", ",", "''", ",", "$", "path", ")", ")", ";", "$", "string", "=", "&", "$", "refPath", ";", "$", "stat", "=", "array", "(", "'dev'", "=>", "0", ",", "'ino'", "=>", "0", ",", "'mode'", "=>", "0", ",", "'nlink'", "=>", "1", ",", "'uid'", "=>", "0", ",", "'gid'", "=>", "0", ",", "'rdev'", "=>", "0", ",", "'size'", "=>", "\\", "strlen", "(", "$", "string", ")", ",", "'atime'", "=>", "$", "now", ",", "'mtime'", "=>", "$", "now", ",", "'ctime'", "=>", "$", "now", ",", "'blksize'", "=>", "'512'", ",", "'blocks'", "=>", "ceil", "(", "\\", "strlen", "(", "$", "string", ")", "/", "512", ")", ",", ")", ";", "return", "$", "stat", ";", "}" ]
Method to retrieve information about a file. @param string $path File path or URL to stat @param integer $flags Additional flags set by the streams API @return array @link https://www.php.net/manual/en/streamwrapper.url-stat.php @since 1.3.0
[ "Method", "to", "retrieve", "information", "about", "a", "file", "." ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Stream/StringWrapper.php#L142-L164
train
joomla-framework/filesystem
src/Stream/StringWrapper.php
StringWrapper.stream_read
public function stream_read($count) { $result = substr($this->currentString, $this->pos, $count); $this->pos += $count; return $result; }
php
public function stream_read($count) { $result = substr($this->currentString, $this->pos, $count); $this->pos += $count; return $result; }
[ "public", "function", "stream_read", "(", "$", "count", ")", "{", "$", "result", "=", "substr", "(", "$", "this", "->", "currentString", ",", "$", "this", "->", "pos", ",", "$", "count", ")", ";", "$", "this", "->", "pos", "+=", "$", "count", ";", "return", "$", "result", ";", "}" ]
Method to read a given number of bytes starting at the current position and moving to the end of the string defined by the current position plus the given number. @param integer $count Bytes of data from the current position should be returned. @return string @link https://www.php.net/manual/en/streamwrapper.stream-read.php @since 1.3.0
[ "Method", "to", "read", "a", "given", "number", "of", "bytes", "starting", "at", "the", "current", "position", "and", "moving", "to", "the", "end", "of", "the", "string", "defined", "by", "the", "current", "position", "plus", "the", "given", "number", "." ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Stream/StringWrapper.php#L178-L184
train
joomla-framework/filesystem
src/Clients/FtpClient.php
FtpClient.setOptions
public function setOptions(array $options) { if (isset($options['type'])) { $this->type = $options['type']; } if (isset($options['timeout'])) { $this->timeout = $options['timeout']; } return true; }
php
public function setOptions(array $options) { if (isset($options['type'])) { $this->type = $options['type']; } if (isset($options['timeout'])) { $this->timeout = $options['timeout']; } return true; }
[ "public", "function", "setOptions", "(", "array", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'type'", "]", ")", ")", "{", "$", "this", "->", "type", "=", "$", "options", "[", "'type'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'timeout'", "]", ")", ")", "{", "$", "this", "->", "timeout", "=", "$", "options", "[", "'timeout'", "]", ";", "}", "return", "true", ";", "}" ]
Set client options @param array $options Associative array of options to set @return boolean True if successful @since 1.0
[ "Set", "client", "options" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Clients/FtpClient.php#L243-L256
train
joomla-framework/filesystem
src/Clients/FtpClient.php
FtpClient.connect
public function connect($host = '127.0.0.1', $port = 21) { $errno = null; $err = null; // If already connected, return if (\is_resource($this->conn)) { return true; } // If native FTP support is enabled let's use it... if (FTP_NATIVE) { $this->conn = @ftp_connect($host, $port, $this->timeout); if ($this->conn === false) { throw new FilesystemException(sprintf('%1$s: Could not connect to host " %2$s " on port " %3$s "', __METHOD__, $host, $port)); } // Set the timeout for this connection ftp_set_option($this->conn, FTP_TIMEOUT_SEC, $this->timeout); return true; } // Connect to the FTP server. $this->conn = @ fsockopen($host, $port, $errno, $err, $this->timeout); if (!$this->conn) { throw new FilesystemException( sprintf( '%1$s: Could not connect to host " %2$s " on port " %3$s ". Socket error number: %4$s and error message: %5$s', __METHOD__, $host, $port, $errno, $err ) ); } // Set the timeout for this connection socket_set_timeout($this->conn, $this->timeout, 0); // Check for welcome response code if (!$this->_verifyResponse(220)) { throw new FilesystemException(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 220]', __METHOD__, $this->response)); } return true; }
php
public function connect($host = '127.0.0.1', $port = 21) { $errno = null; $err = null; // If already connected, return if (\is_resource($this->conn)) { return true; } // If native FTP support is enabled let's use it... if (FTP_NATIVE) { $this->conn = @ftp_connect($host, $port, $this->timeout); if ($this->conn === false) { throw new FilesystemException(sprintf('%1$s: Could not connect to host " %2$s " on port " %3$s "', __METHOD__, $host, $port)); } // Set the timeout for this connection ftp_set_option($this->conn, FTP_TIMEOUT_SEC, $this->timeout); return true; } // Connect to the FTP server. $this->conn = @ fsockopen($host, $port, $errno, $err, $this->timeout); if (!$this->conn) { throw new FilesystemException( sprintf( '%1$s: Could not connect to host " %2$s " on port " %3$s ". Socket error number: %4$s and error message: %5$s', __METHOD__, $host, $port, $errno, $err ) ); } // Set the timeout for this connection socket_set_timeout($this->conn, $this->timeout, 0); // Check for welcome response code if (!$this->_verifyResponse(220)) { throw new FilesystemException(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 220]', __METHOD__, $this->response)); } return true; }
[ "public", "function", "connect", "(", "$", "host", "=", "'127.0.0.1'", ",", "$", "port", "=", "21", ")", "{", "$", "errno", "=", "null", ";", "$", "err", "=", "null", ";", "// If already connected, return", "if", "(", "\\", "is_resource", "(", "$", "this", "->", "conn", ")", ")", "{", "return", "true", ";", "}", "// If native FTP support is enabled let's use it...", "if", "(", "FTP_NATIVE", ")", "{", "$", "this", "->", "conn", "=", "@", "ftp_connect", "(", "$", "host", ",", "$", "port", ",", "$", "this", "->", "timeout", ")", ";", "if", "(", "$", "this", "->", "conn", "===", "false", ")", "{", "throw", "new", "FilesystemException", "(", "sprintf", "(", "'%1$s: Could not connect to host \" %2$s \" on port \" %3$s \"'", ",", "__METHOD__", ",", "$", "host", ",", "$", "port", ")", ")", ";", "}", "// Set the timeout for this connection", "ftp_set_option", "(", "$", "this", "->", "conn", ",", "FTP_TIMEOUT_SEC", ",", "$", "this", "->", "timeout", ")", ";", "return", "true", ";", "}", "// Connect to the FTP server.", "$", "this", "->", "conn", "=", "@", "fsockopen", "(", "$", "host", ",", "$", "port", ",", "$", "errno", ",", "$", "err", ",", "$", "this", "->", "timeout", ")", ";", "if", "(", "!", "$", "this", "->", "conn", ")", "{", "throw", "new", "FilesystemException", "(", "sprintf", "(", "'%1$s: Could not connect to host \" %2$s \" on port \" %3$s \". Socket error number: %4$s and error message: %5$s'", ",", "__METHOD__", ",", "$", "host", ",", "$", "port", ",", "$", "errno", ",", "$", "err", ")", ")", ";", "}", "// Set the timeout for this connection", "socket_set_timeout", "(", "$", "this", "->", "conn", ",", "$", "this", "->", "timeout", ",", "0", ")", ";", "// Check for welcome response code", "if", "(", "!", "$", "this", "->", "_verifyResponse", "(", "220", ")", ")", "{", "throw", "new", "FilesystemException", "(", "sprintf", "(", "'%1$s: Bad response. Server response: %2$s [Expected: 220]'", ",", "__METHOD__", ",", "$", "this", "->", "response", ")", ")", ";", "}", "return", "true", ";", "}" ]
Method to connect to a FTP server @param string $host Host to connect to [Default: 127.0.0.1] @param integer $port Port to connect on [Default: port 21] @return boolean True if successful @since 1.0 @throws FilesystemException
[ "Method", "to", "connect", "to", "a", "FTP", "server" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Clients/FtpClient.php#L269-L323
train
joomla-framework/filesystem
src/Clients/FtpClient.php
FtpClient.quit
public function quit() { // If native FTP support is enabled lets use it... if (FTP_NATIVE) { @ftp_close($this->conn); return true; } // Logout and close connection @fwrite($this->conn, "QUIT\r\n"); @fclose($this->conn); return true; }
php
public function quit() { // If native FTP support is enabled lets use it... if (FTP_NATIVE) { @ftp_close($this->conn); return true; } // Logout and close connection @fwrite($this->conn, "QUIT\r\n"); @fclose($this->conn); return true; }
[ "public", "function", "quit", "(", ")", "{", "// If native FTP support is enabled lets use it...", "if", "(", "FTP_NATIVE", ")", "{", "@", "ftp_close", "(", "$", "this", "->", "conn", ")", ";", "return", "true", ";", "}", "// Logout and close connection", "@", "fwrite", "(", "$", "this", "->", "conn", ",", "\"QUIT\\r\\n\"", ")", ";", "@", "fclose", "(", "$", "this", "->", "conn", ")", ";", "return", "true", ";", "}" ]
Method to quit and close the connection @return boolean True if successful @since 1.0
[ "Method", "to", "quit", "and", "close", "the", "connection" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Clients/FtpClient.php#L391-L406
train
joomla-framework/filesystem
src/Clients/FtpClient.php
FtpClient.reinit
public function reinit() { // If native FTP support is enabled let's use it... if (FTP_NATIVE) { if (@ftp_site($this->conn, 'REIN') === false) { throw new FilesystemException(__METHOD__ . 'Bad response.'); } return true; } // Send reinitialise command to the server if (!$this->_putCmd('REIN', 220)) { throw new FilesystemException(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 220]', __METHOD__, $this->response)); } return true; }
php
public function reinit() { // If native FTP support is enabled let's use it... if (FTP_NATIVE) { if (@ftp_site($this->conn, 'REIN') === false) { throw new FilesystemException(__METHOD__ . 'Bad response.'); } return true; } // Send reinitialise command to the server if (!$this->_putCmd('REIN', 220)) { throw new FilesystemException(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 220]', __METHOD__, $this->response)); } return true; }
[ "public", "function", "reinit", "(", ")", "{", "// If native FTP support is enabled let's use it...", "if", "(", "FTP_NATIVE", ")", "{", "if", "(", "@", "ftp_site", "(", "$", "this", "->", "conn", ",", "'REIN'", ")", "===", "false", ")", "{", "throw", "new", "FilesystemException", "(", "__METHOD__", ".", "'Bad response.'", ")", ";", "}", "return", "true", ";", "}", "// Send reinitialise command to the server", "if", "(", "!", "$", "this", "->", "_putCmd", "(", "'REIN'", ",", "220", ")", ")", "{", "throw", "new", "FilesystemException", "(", "sprintf", "(", "'%1$s: Bad response. Server response: %2$s [Expected: 220]'", ",", "__METHOD__", ",", "$", "this", "->", "response", ")", ")", ";", "}", "return", "true", ";", "}" ]
Method to reinitialise the server, ie. need to login again NOTE: This command not available on all servers @return boolean True if successful @since 1.0 @throws FilesystemException
[ "Method", "to", "reinitialise", "the", "server", "ie", ".", "need", "to", "login", "again" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Clients/FtpClient.php#L535-L555
train
joomla-framework/filesystem
src/Clients/FtpClient.php
FtpClient.chmod
public function chmod($path, $mode) { // If no filename is given, we assume the current directory is the target if ($path == '') { $path = '.'; } // Convert the mode to a string if (\is_int($mode)) { $mode = decoct($mode); } // If native FTP support is enabled let's use it... if (FTP_NATIVE) { if (@ftp_site($this->conn, 'CHMOD ' . $mode . ' ' . $path) === false) { if (!\defined('PHP_WINDOWS_VERSION_MAJOR')) { throw new FilesystemException(__METHOD__ . 'Bad response.'); } return false; } return true; } // Send change mode command and verify success [must convert mode from octal] if (!$this->_putCmd('SITE CHMOD ' . $mode . ' ' . $path, array(200, 250))) { if (!\defined('PHP_WINDOWS_VERSION_MAJOR')) { throw new FilesystemException( sprintf( '%1$s: Bad response. Server response: %2$s [Expected: 250]. Path sent: %3$s. Mode sent: %4$s', __METHOD__, $this->response, $path, $mode ) ); } return false; } return true; }
php
public function chmod($path, $mode) { // If no filename is given, we assume the current directory is the target if ($path == '') { $path = '.'; } // Convert the mode to a string if (\is_int($mode)) { $mode = decoct($mode); } // If native FTP support is enabled let's use it... if (FTP_NATIVE) { if (@ftp_site($this->conn, 'CHMOD ' . $mode . ' ' . $path) === false) { if (!\defined('PHP_WINDOWS_VERSION_MAJOR')) { throw new FilesystemException(__METHOD__ . 'Bad response.'); } return false; } return true; } // Send change mode command and verify success [must convert mode from octal] if (!$this->_putCmd('SITE CHMOD ' . $mode . ' ' . $path, array(200, 250))) { if (!\defined('PHP_WINDOWS_VERSION_MAJOR')) { throw new FilesystemException( sprintf( '%1$s: Bad response. Server response: %2$s [Expected: 250]. Path sent: %3$s. Mode sent: %4$s', __METHOD__, $this->response, $path, $mode ) ); } return false; } return true; }
[ "public", "function", "chmod", "(", "$", "path", ",", "$", "mode", ")", "{", "// If no filename is given, we assume the current directory is the target", "if", "(", "$", "path", "==", "''", ")", "{", "$", "path", "=", "'.'", ";", "}", "// Convert the mode to a string", "if", "(", "\\", "is_int", "(", "$", "mode", ")", ")", "{", "$", "mode", "=", "decoct", "(", "$", "mode", ")", ";", "}", "// If native FTP support is enabled let's use it...", "if", "(", "FTP_NATIVE", ")", "{", "if", "(", "@", "ftp_site", "(", "$", "this", "->", "conn", ",", "'CHMOD '", ".", "$", "mode", ".", "' '", ".", "$", "path", ")", "===", "false", ")", "{", "if", "(", "!", "\\", "defined", "(", "'PHP_WINDOWS_VERSION_MAJOR'", ")", ")", "{", "throw", "new", "FilesystemException", "(", "__METHOD__", ".", "'Bad response.'", ")", ";", "}", "return", "false", ";", "}", "return", "true", ";", "}", "// Send change mode command and verify success [must convert mode from octal]", "if", "(", "!", "$", "this", "->", "_putCmd", "(", "'SITE CHMOD '", ".", "$", "mode", ".", "' '", ".", "$", "path", ",", "array", "(", "200", ",", "250", ")", ")", ")", "{", "if", "(", "!", "\\", "defined", "(", "'PHP_WINDOWS_VERSION_MAJOR'", ")", ")", "{", "throw", "new", "FilesystemException", "(", "sprintf", "(", "'%1$s: Bad response. Server response: %2$s [Expected: 250]. Path sent: %3$s. Mode sent: %4$s'", ",", "__METHOD__", ",", "$", "this", "->", "response", ",", "$", "path", ",", "$", "mode", ")", ")", ";", "}", "return", "false", ";", "}", "return", "true", ";", "}" ]
Method to change mode for a path on the FTP server @param string $path Path to change mode on @param mixed $mode Octal value to change mode to, e.g. '0777', 0777 or 511 (string or integer) @return boolean True if successful @since 1.0 @throws FilesystemException
[ "Method", "to", "change", "mode", "for", "a", "path", "on", "the", "FTP", "server" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Clients/FtpClient.php#L611-L661
train
joomla-framework/filesystem
src/Clients/FtpClient.php
FtpClient.listNames
public function listNames($path = null) { $data = null; // If native FTP support is enabled let's use it... if (FTP_NATIVE) { // Turn passive mode on if (@ftp_pasv($this->conn, true) === false) { throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.'); } if (($list = @ftp_nlist($this->conn, $path)) === false) { // Workaround for empty directories on some servers if ($this->listDetails($path, 'files') === array()) { return array(); } throw new FilesystemException(__METHOD__ . 'Bad response.'); } $list = preg_replace('#^' . preg_quote($path, '#') . '[/\\\\]?#', '', $list); if ($keys = array_merge(array_keys($list, '.'), array_keys($list, '..'))) { foreach ($keys as $key) { unset($list[$key]); } } return $list; } // If a path exists, prepend a space if ($path != null) { $path = ' ' . $path; } // Start passive mode if (!$this->_passive()) { throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.'); } if (!$this->_putCmd('NLST' . $path, array(150, 125))) { @ fclose($this->dataconn); // Workaround for empty directories on some servers if ($this->listDetails($path, 'files') === array()) { return array(); } throw new FilesystemException( sprintf('%1$s: Bad response. Server response: %2$s [Expected: 150 or 125]. Path sent: %3$s', __METHOD__, $this->response, $path) ); } // Read in the file listing. while (!feof($this->dataconn)) { $data .= fread($this->dataconn, 4096); } fclose($this->dataconn); // Everything go okay? if (!$this->_verifyResponse(226)) { throw new FilesystemException( sprintf('%1$s: Transfer failed. Server response: %2$s [Expected: 226]. Path sent: %3$s', __METHOD__, $this->response, $path) ); } $data = preg_split('/[' . CRLF . ']+/', $data, -1, PREG_SPLIT_NO_EMPTY); $data = preg_replace('#^' . preg_quote(substr($path, 1), '#') . '[/\\\\]?#', '', $data); if ($keys = array_merge(array_keys($data, '.'), array_keys($data, '..'))) { foreach ($keys as $key) { unset($data[$key]); } } return $data; }
php
public function listNames($path = null) { $data = null; // If native FTP support is enabled let's use it... if (FTP_NATIVE) { // Turn passive mode on if (@ftp_pasv($this->conn, true) === false) { throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.'); } if (($list = @ftp_nlist($this->conn, $path)) === false) { // Workaround for empty directories on some servers if ($this->listDetails($path, 'files') === array()) { return array(); } throw new FilesystemException(__METHOD__ . 'Bad response.'); } $list = preg_replace('#^' . preg_quote($path, '#') . '[/\\\\]?#', '', $list); if ($keys = array_merge(array_keys($list, '.'), array_keys($list, '..'))) { foreach ($keys as $key) { unset($list[$key]); } } return $list; } // If a path exists, prepend a space if ($path != null) { $path = ' ' . $path; } // Start passive mode if (!$this->_passive()) { throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.'); } if (!$this->_putCmd('NLST' . $path, array(150, 125))) { @ fclose($this->dataconn); // Workaround for empty directories on some servers if ($this->listDetails($path, 'files') === array()) { return array(); } throw new FilesystemException( sprintf('%1$s: Bad response. Server response: %2$s [Expected: 150 or 125]. Path sent: %3$s', __METHOD__, $this->response, $path) ); } // Read in the file listing. while (!feof($this->dataconn)) { $data .= fread($this->dataconn, 4096); } fclose($this->dataconn); // Everything go okay? if (!$this->_verifyResponse(226)) { throw new FilesystemException( sprintf('%1$s: Transfer failed. Server response: %2$s [Expected: 226]. Path sent: %3$s', __METHOD__, $this->response, $path) ); } $data = preg_split('/[' . CRLF . ']+/', $data, -1, PREG_SPLIT_NO_EMPTY); $data = preg_replace('#^' . preg_quote(substr($path, 1), '#') . '[/\\\\]?#', '', $data); if ($keys = array_merge(array_keys($data, '.'), array_keys($data, '..'))) { foreach ($keys as $key) { unset($data[$key]); } } return $data; }
[ "public", "function", "listNames", "(", "$", "path", "=", "null", ")", "{", "$", "data", "=", "null", ";", "// If native FTP support is enabled let's use it...", "if", "(", "FTP_NATIVE", ")", "{", "// Turn passive mode on", "if", "(", "@", "ftp_pasv", "(", "$", "this", "->", "conn", ",", "true", ")", "===", "false", ")", "{", "throw", "new", "FilesystemException", "(", "__METHOD__", ".", "': Unable to use passive mode.'", ")", ";", "}", "if", "(", "(", "$", "list", "=", "@", "ftp_nlist", "(", "$", "this", "->", "conn", ",", "$", "path", ")", ")", "===", "false", ")", "{", "// Workaround for empty directories on some servers", "if", "(", "$", "this", "->", "listDetails", "(", "$", "path", ",", "'files'", ")", "===", "array", "(", ")", ")", "{", "return", "array", "(", ")", ";", "}", "throw", "new", "FilesystemException", "(", "__METHOD__", ".", "'Bad response.'", ")", ";", "}", "$", "list", "=", "preg_replace", "(", "'#^'", ".", "preg_quote", "(", "$", "path", ",", "'#'", ")", ".", "'[/\\\\\\\\]?#'", ",", "''", ",", "$", "list", ")", ";", "if", "(", "$", "keys", "=", "array_merge", "(", "array_keys", "(", "$", "list", ",", "'.'", ")", ",", "array_keys", "(", "$", "list", ",", "'..'", ")", ")", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "unset", "(", "$", "list", "[", "$", "key", "]", ")", ";", "}", "}", "return", "$", "list", ";", "}", "// If a path exists, prepend a space", "if", "(", "$", "path", "!=", "null", ")", "{", "$", "path", "=", "' '", ".", "$", "path", ";", "}", "// Start passive mode", "if", "(", "!", "$", "this", "->", "_passive", "(", ")", ")", "{", "throw", "new", "FilesystemException", "(", "__METHOD__", ".", "': Unable to use passive mode.'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "_putCmd", "(", "'NLST'", ".", "$", "path", ",", "array", "(", "150", ",", "125", ")", ")", ")", "{", "@", "fclose", "(", "$", "this", "->", "dataconn", ")", ";", "// Workaround for empty directories on some servers", "if", "(", "$", "this", "->", "listDetails", "(", "$", "path", ",", "'files'", ")", "===", "array", "(", ")", ")", "{", "return", "array", "(", ")", ";", "}", "throw", "new", "FilesystemException", "(", "sprintf", "(", "'%1$s: Bad response. Server response: %2$s [Expected: 150 or 125]. Path sent: %3$s'", ",", "__METHOD__", ",", "$", "this", "->", "response", ",", "$", "path", ")", ")", ";", "}", "// Read in the file listing.", "while", "(", "!", "feof", "(", "$", "this", "->", "dataconn", ")", ")", "{", "$", "data", ".=", "fread", "(", "$", "this", "->", "dataconn", ",", "4096", ")", ";", "}", "fclose", "(", "$", "this", "->", "dataconn", ")", ";", "// Everything go okay?", "if", "(", "!", "$", "this", "->", "_verifyResponse", "(", "226", ")", ")", "{", "throw", "new", "FilesystemException", "(", "sprintf", "(", "'%1$s: Transfer failed. Server response: %2$s [Expected: 226]. Path sent: %3$s'", ",", "__METHOD__", ",", "$", "this", "->", "response", ",", "$", "path", ")", ")", ";", "}", "$", "data", "=", "preg_split", "(", "'/['", ".", "CRLF", ".", "']+/'", ",", "$", "data", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", ";", "$", "data", "=", "preg_replace", "(", "'#^'", ".", "preg_quote", "(", "substr", "(", "$", "path", ",", "1", ")", ",", "'#'", ")", ".", "'[/\\\\\\\\]?#'", ",", "''", ",", "$", "data", ")", ";", "if", "(", "$", "keys", "=", "array_merge", "(", "array_keys", "(", "$", "data", ",", "'.'", ")", ",", "array_keys", "(", "$", "data", ",", "'..'", ")", ")", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "unset", "(", "$", "data", "[", "$", "key", "]", ")", ";", "}", "}", "return", "$", "data", ";", "}" ]
Method to list the filenames of the contents of a directory on the FTP server Note: Some servers also return folder names. However, to be sure to list folders on all servers, you should use listDetails() instead if you also need to deal with folders @param string $path Path local file to store on the FTP server @return string Directory listing @since 1.0 @throws FilesystemException
[ "Method", "to", "list", "the", "filenames", "of", "the", "contents", "of", "a", "directory", "on", "the", "FTP", "server" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Clients/FtpClient.php#L1222-L1314
train
joomla-framework/filesystem
src/Clients/FtpClient.php
FtpClient._findMode
protected function _findMode($fileName) { if ($this->type == FTP_AUTOASCII) { $dot = strrpos($fileName, '.') + 1; $ext = substr($fileName, $dot); if (\in_array($ext, $this->autoAscii)) { $mode = FTP_ASCII; } else { $mode = FTP_BINARY; } } elseif ($this->type == FTP_ASCII) { $mode = FTP_ASCII; } else { $mode = FTP_BINARY; } return $mode; }
php
protected function _findMode($fileName) { if ($this->type == FTP_AUTOASCII) { $dot = strrpos($fileName, '.') + 1; $ext = substr($fileName, $dot); if (\in_array($ext, $this->autoAscii)) { $mode = FTP_ASCII; } else { $mode = FTP_BINARY; } } elseif ($this->type == FTP_ASCII) { $mode = FTP_ASCII; } else { $mode = FTP_BINARY; } return $mode; }
[ "protected", "function", "_findMode", "(", "$", "fileName", ")", "{", "if", "(", "$", "this", "->", "type", "==", "FTP_AUTOASCII", ")", "{", "$", "dot", "=", "strrpos", "(", "$", "fileName", ",", "'.'", ")", "+", "1", ";", "$", "ext", "=", "substr", "(", "$", "fileName", ",", "$", "dot", ")", ";", "if", "(", "\\", "in_array", "(", "$", "ext", ",", "$", "this", "->", "autoAscii", ")", ")", "{", "$", "mode", "=", "FTP_ASCII", ";", "}", "else", "{", "$", "mode", "=", "FTP_BINARY", ";", "}", "}", "elseif", "(", "$", "this", "->", "type", "==", "FTP_ASCII", ")", "{", "$", "mode", "=", "FTP_ASCII", ";", "}", "else", "{", "$", "mode", "=", "FTP_BINARY", ";", "}", "return", "$", "mode", ";", "}" ]
Method to find out the correct transfer mode for a specific file @param string $fileName Name of the file @return integer Transfer-mode for this filetype [FTP_ASCII|FTP_BINARY] @since 1.0
[ "Method", "to", "find", "out", "the", "correct", "transfer", "mode", "for", "a", "specific", "file" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Clients/FtpClient.php#L1734-L1760
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/PaypalExpress.php
PaypalExpress.void
public function void($authorization, $options = array()) { $this->post = array(); $params = array( 'METHOD' => 'DoVoid', 'AUTHORIZATIONID' => $authorization ); if (isset($options['note'])) { $params['NOTE'] = $options['note']; } if (isset($options['message'])) { $params['MSGSUBID'] = $options['message']; } $this->post = array_merge( $this->post, $params ); return $this->commit('DoVoid'); }
php
public function void($authorization, $options = array()) { $this->post = array(); $params = array( 'METHOD' => 'DoVoid', 'AUTHORIZATIONID' => $authorization ); if (isset($options['note'])) { $params['NOTE'] = $options['note']; } if (isset($options['message'])) { $params['MSGSUBID'] = $options['message']; } $this->post = array_merge( $this->post, $params ); return $this->commit('DoVoid'); }
[ "public", "function", "void", "(", "$", "authorization", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "post", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'METHOD'", "=>", "'DoVoid'", ",", "'AUTHORIZATIONID'", "=>", "$", "authorization", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'note'", "]", ")", ")", "{", "$", "params", "[", "'NOTE'", "]", "=", "$", "options", "[", "'note'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'message'", "]", ")", ")", "{", "$", "params", "[", "'MSGSUBID'", "]", "=", "$", "options", "[", "'message'", "]", ";", "}", "$", "this", "->", "post", "=", "array_merge", "(", "$", "this", "->", "post", ",", "$", "params", ")", ";", "return", "$", "this", "->", "commit", "(", "'DoVoid'", ")", ";", "}" ]
Void an authorization. Available option fields are: - note: (Optional) Informational note about this void that is displayed to the buyer in email and in their transaction history. Character length and limitations: 255 single-byte characters - message: (Optional) A message ID used for idempotence to uniquely identify a message. This ID can later be used to request the latest results for a previous request without generating a new request. Examples of this include requests due to timeouts or errors during the original request. Character length and limitations: 38 single-byte characters {@inheritdoc }
[ "Void", "an", "authorization", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/PaypalExpress.php#L162-L185
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/AlbumApi.php
AlbumApi.getTags
public function getTags($methodVars) { // Only allow full authed calls if ($this->getFullAuth() === true) { // Check for required variables if (!empty($methodVars['album']) && !empty($methodVars['artist'])) { // Set the variables $vars = array( 'method' => 'album.gettags', 'api_key' => $this->getAuth()->apiKey, 'sk' => $this->getAuth()->sessionKey ); $vars = array_merge($vars, $methodVars); // Generate a call signiture $sig = $this->apiSig($this->getAuth()->apiSecret, $vars); $vars['api_sig'] = $sig; $tags = array(); // Make the call if ($call = $this->apiGetCall($vars)) { if (count($call->tags->tag) > 0) { $i = 0; foreach ($call->tags->tag as $tag) { $tags[$i]['name'] = (string) $tag->name; $tags[$i]['url'] = (string) $tag->url; $i++; } return $tags; } else { throw new NoResultsException('User has no tags for this artist'); } } else { return false; } } else { throw new InvalidArgumentException('You must include album, artist and tags variables in the call for this method'); } } else { throw new NotAuthenticatedException('Method requires full auth. Call auth.getSession using lastfmApiAuth class'); } }
php
public function getTags($methodVars) { // Only allow full authed calls if ($this->getFullAuth() === true) { // Check for required variables if (!empty($methodVars['album']) && !empty($methodVars['artist'])) { // Set the variables $vars = array( 'method' => 'album.gettags', 'api_key' => $this->getAuth()->apiKey, 'sk' => $this->getAuth()->sessionKey ); $vars = array_merge($vars, $methodVars); // Generate a call signiture $sig = $this->apiSig($this->getAuth()->apiSecret, $vars); $vars['api_sig'] = $sig; $tags = array(); // Make the call if ($call = $this->apiGetCall($vars)) { if (count($call->tags->tag) > 0) { $i = 0; foreach ($call->tags->tag as $tag) { $tags[$i]['name'] = (string) $tag->name; $tags[$i]['url'] = (string) $tag->url; $i++; } return $tags; } else { throw new NoResultsException('User has no tags for this artist'); } } else { return false; } } else { throw new InvalidArgumentException('You must include album, artist and tags variables in the call for this method'); } } else { throw new NotAuthenticatedException('Method requires full auth. Call auth.getSession using lastfmApiAuth class'); } }
[ "public", "function", "getTags", "(", "$", "methodVars", ")", "{", "// Only allow full authed calls", "if", "(", "$", "this", "->", "getFullAuth", "(", ")", "===", "true", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'album'", "]", ")", "&&", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", ")", "{", "// Set the variables", "$", "vars", "=", "array", "(", "'method'", "=>", "'album.gettags'", ",", "'api_key'", "=>", "$", "this", "->", "getAuth", "(", ")", "->", "apiKey", ",", "'sk'", "=>", "$", "this", "->", "getAuth", "(", ")", "->", "sessionKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "// Generate a call signiture", "$", "sig", "=", "$", "this", "->", "apiSig", "(", "$", "this", "->", "getAuth", "(", ")", "->", "apiSecret", ",", "$", "vars", ")", ";", "$", "vars", "[", "'api_sig'", "]", "=", "$", "sig", ";", "$", "tags", "=", "array", "(", ")", ";", "// Make the call", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "if", "(", "count", "(", "$", "call", "->", "tags", "->", "tag", ")", ">", "0", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "tags", "->", "tag", "as", "$", "tag", ")", "{", "$", "tags", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "tag", "->", "name", ";", "$", "tags", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "tag", "->", "url", ";", "$", "i", "++", ";", "}", "return", "$", "tags", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'User has no tags for this artist'", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include album, artist and tags variables in the call for this method'", ")", ";", "}", "}", "else", "{", "throw", "new", "NotAuthenticatedException", "(", "'Method requires full auth. Call auth.getSession using lastfmApiAuth class'", ")", ";", "}", "}" ]
Get the tags applied by an individual user to an album on Last.fm @param array $methodVars An array with the following required values: <i>album</i>, <i>artist</i> @return array
[ "Get", "the", "tags", "applied", "by", "an", "individual", "user", "to", "an", "album", "on", "Last", ".", "fm" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/AlbumApi.php#L135-L177
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/AlbumApi.php
AlbumApi.search
public function search($methodVars) { // Check for required variables if (!empty($methodVars['album'])) { $vars = array( 'method' => 'album.search', 'api_key' => $this->getAuth()->apiKey ); $vars = array_merge($vars, $methodVars); $searchresults = array(); if ($call = $this->apiGetCall($vars)) { $callNamespaces = $call->getDocNamespaces(true); // fix missing namespace (sic) if (!isset($callNamespaces['opensearch'])) { $call->results->addAttribute('xmlns:xmlns:opensearch', 'http://a9.com/-/spec/opensearch/1.1/'); $call = new SimpleXMLElement($call->asXML()); } $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/'); if ($opensearch->totalResults > 0) { $searchresults['totalResults'] = (string) $opensearch->totalResults; $searchresults['startIndex'] = (string) $opensearch->startIndex; $searchresults['itemsPerPage'] = (string) $opensearch->itemsPerPage; $i = 0; foreach ($call->results->albummatches->album as $album) { $searchresults['results'][$i]['name'] = (string) $album->name; $searchresults['results'][$i]['artist'] = (string) $album->artist; $searchresults['results'][$i]['id'] = (string) $album->id; $searchresults['results'][$i]['mbid'] = (string) $album->mbid; $searchresults['results'][$i]['url'] = (string) $album->url; $searchresults['results'][$i]['streamable'] = (string) $album->streamable; $searchresults['results'][$i]['image']['small'] = (string) $album->image[0]; $searchresults['results'][$i]['image']['medium'] = (string) $album->image[1]; $searchresults['results'][$i]['image']['large'] = (string) $album->image[2]; $i++; } return $searchresults; } else { throw new NoResultsException('No results', 90); } } else { return false; } } else { throw new InvalidArgumentException('You must include album variable in the call for this method'); } }
php
public function search($methodVars) { // Check for required variables if (!empty($methodVars['album'])) { $vars = array( 'method' => 'album.search', 'api_key' => $this->getAuth()->apiKey ); $vars = array_merge($vars, $methodVars); $searchresults = array(); if ($call = $this->apiGetCall($vars)) { $callNamespaces = $call->getDocNamespaces(true); // fix missing namespace (sic) if (!isset($callNamespaces['opensearch'])) { $call->results->addAttribute('xmlns:xmlns:opensearch', 'http://a9.com/-/spec/opensearch/1.1/'); $call = new SimpleXMLElement($call->asXML()); } $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/'); if ($opensearch->totalResults > 0) { $searchresults['totalResults'] = (string) $opensearch->totalResults; $searchresults['startIndex'] = (string) $opensearch->startIndex; $searchresults['itemsPerPage'] = (string) $opensearch->itemsPerPage; $i = 0; foreach ($call->results->albummatches->album as $album) { $searchresults['results'][$i]['name'] = (string) $album->name; $searchresults['results'][$i]['artist'] = (string) $album->artist; $searchresults['results'][$i]['id'] = (string) $album->id; $searchresults['results'][$i]['mbid'] = (string) $album->mbid; $searchresults['results'][$i]['url'] = (string) $album->url; $searchresults['results'][$i]['streamable'] = (string) $album->streamable; $searchresults['results'][$i]['image']['small'] = (string) $album->image[0]; $searchresults['results'][$i]['image']['medium'] = (string) $album->image[1]; $searchresults['results'][$i]['image']['large'] = (string) $album->image[2]; $i++; } return $searchresults; } else { throw new NoResultsException('No results', 90); } } else { return false; } } else { throw new InvalidArgumentException('You must include album variable in the call for this method'); } }
[ "public", "function", "search", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'album'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'album.search'", ",", "'api_key'", "=>", "$", "this", "->", "getAuth", "(", ")", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "$", "searchresults", "=", "array", "(", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "callNamespaces", "=", "$", "call", "->", "getDocNamespaces", "(", "true", ")", ";", "// fix missing namespace (sic)", "if", "(", "!", "isset", "(", "$", "callNamespaces", "[", "'opensearch'", "]", ")", ")", "{", "$", "call", "->", "results", "->", "addAttribute", "(", "'xmlns:xmlns:opensearch'", ",", "'http://a9.com/-/spec/opensearch/1.1/'", ")", ";", "$", "call", "=", "new", "SimpleXMLElement", "(", "$", "call", "->", "asXML", "(", ")", ")", ";", "}", "$", "opensearch", "=", "$", "call", "->", "results", "->", "children", "(", "'http://a9.com/-/spec/opensearch/1.1/'", ")", ";", "if", "(", "$", "opensearch", "->", "totalResults", ">", "0", ")", "{", "$", "searchresults", "[", "'totalResults'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "totalResults", ";", "$", "searchresults", "[", "'startIndex'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "startIndex", ";", "$", "searchresults", "[", "'itemsPerPage'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "itemsPerPage", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "results", "->", "albummatches", "->", "album", "as", "$", "album", ")", "{", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "album", "->", "name", ";", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'artist'", "]", "=", "(", "string", ")", "$", "album", "->", "artist", ";", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'id'", "]", "=", "(", "string", ")", "$", "album", "->", "id", ";", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "album", "->", "mbid", ";", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "album", "->", "url", ";", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "album", "->", "streamable", ";", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "0", "]", ";", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "1", "]", ";", "$", "searchresults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "searchresults", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'No results'", ",", "90", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include album variable in the call for this method'", ")", ";", "}", "}" ]
Search for an album by name. Returns album matches sorted by relevance @param array $methodVars An array with the following required values: <i>album</i> @return array
[ "Search", "for", "an", "album", "by", "name", ".", "Returns", "album", "matches", "sorted", "by", "relevance" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/AlbumApi.php#L221-L268
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/ePDQ.php
ePDQ.addTransactionElement
private function addTransactionElement($amount, $type, $options) { if ($type == 'PreAuth' || $type == 'Auth') { $this->xml .= <<<XML <Transaction> <Type DataType="String">{$type}</Type> <CurrentTotals> <Totals> <Total DataType="Money" Currency="{$this->currency_lookup(self::$default_currency)}">{$amount}</Total> </Totals> </CurrentTotals> </Transaction> XML; } elseif ($type == 'PostAuth' || $type == 'Void') { $this->xml .= <<<XML <Transaction> <Type DataType="String">{$type}</Type> <Id DataType="String">{$options['authorization']}</Id> <CurrentTotals> <Totals> <Total DataType="Money" Currency="{$this->currency_lookup(self::$default_currency)}">{$amount}</Total> </Totals> </CurrentTotals> </Transaction> XML; } }
php
private function addTransactionElement($amount, $type, $options) { if ($type == 'PreAuth' || $type == 'Auth') { $this->xml .= <<<XML <Transaction> <Type DataType="String">{$type}</Type> <CurrentTotals> <Totals> <Total DataType="Money" Currency="{$this->currency_lookup(self::$default_currency)}">{$amount}</Total> </Totals> </CurrentTotals> </Transaction> XML; } elseif ($type == 'PostAuth' || $type == 'Void') { $this->xml .= <<<XML <Transaction> <Type DataType="String">{$type}</Type> <Id DataType="String">{$options['authorization']}</Id> <CurrentTotals> <Totals> <Total DataType="Money" Currency="{$this->currency_lookup(self::$default_currency)}">{$amount}</Total> </Totals> </CurrentTotals> </Transaction> XML; } }
[ "private", "function", "addTransactionElement", "(", "$", "amount", ",", "$", "type", ",", "$", "options", ")", "{", "if", "(", "$", "type", "==", "'PreAuth'", "||", "$", "type", "==", "'Auth'", ")", "{", "$", "this", "->", "xml", ".=", " <<<XML\n <Transaction>\n <Type DataType=\"String\">{$type}</Type>\n <CurrentTotals>\n <Totals>\n <Total DataType=\"Money\" Currency=\"{$this->currency_lookup(self::$default_currency)}\">{$amount}</Total>\n </Totals>\n </CurrentTotals>\n </Transaction>\nXML", ";", "}", "elseif", "(", "$", "type", "==", "'PostAuth'", "||", "$", "type", "==", "'Void'", ")", "{", "$", "this", "->", "xml", ".=", " <<<XML\n <Transaction>\n <Type DataType=\"String\">{$type}</Type>\n <Id DataType=\"String\">{$options['authorization']}</Id>\n <CurrentTotals>\n <Totals>\n <Total DataType=\"Money\" Currency=\"{$this->currency_lookup(self::$default_currency)}\">{$amount}</Total>\n </Totals>\n </CurrentTotals>\n </Transaction>\nXML", ";", "}", "}" ]
Add Transaction Element @param int @param string @param array
[ "Add", "Transaction", "Element" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/ePDQ.php#L212-L239
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/ePDQ.php
ePDQ.optionsFrom
private function optionsFrom($response) { $options = array(); $options['authorization'] = $response['transaction_id']; $options['test'] = empty($response['mode']) || $response['mode'] != 'P'; $options['fraud_review'] = in_array($response['return_code'], $this->FRAUDULENT); if (!empty($response['cvv2_resp'])) { $options['cvv_result'] = $this->CVV_RESPONSE_MAPPINGS[$response['cvv2_resp']]; } $options['avs_result'] = $this->avsCodeFrom($response); }
php
private function optionsFrom($response) { $options = array(); $options['authorization'] = $response['transaction_id']; $options['test'] = empty($response['mode']) || $response['mode'] != 'P'; $options['fraud_review'] = in_array($response['return_code'], $this->FRAUDULENT); if (!empty($response['cvv2_resp'])) { $options['cvv_result'] = $this->CVV_RESPONSE_MAPPINGS[$response['cvv2_resp']]; } $options['avs_result'] = $this->avsCodeFrom($response); }
[ "private", "function", "optionsFrom", "(", "$", "response", ")", "{", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "'authorization'", "]", "=", "$", "response", "[", "'transaction_id'", "]", ";", "$", "options", "[", "'test'", "]", "=", "empty", "(", "$", "response", "[", "'mode'", "]", ")", "||", "$", "response", "[", "'mode'", "]", "!=", "'P'", ";", "$", "options", "[", "'fraud_review'", "]", "=", "in_array", "(", "$", "response", "[", "'return_code'", "]", ",", "$", "this", "->", "FRAUDULENT", ")", ";", "if", "(", "!", "empty", "(", "$", "response", "[", "'cvv2_resp'", "]", ")", ")", "{", "$", "options", "[", "'cvv_result'", "]", "=", "$", "this", "->", "CVV_RESPONSE_MAPPINGS", "[", "$", "response", "[", "'cvv2_resp'", "]", "]", ";", "}", "$", "options", "[", "'avs_result'", "]", "=", "$", "this", "->", "avsCodeFrom", "(", "$", "response", ")", ";", "}" ]
Options from Response @param array
[ "Options", "from", "Response" ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/ePDQ.php#L451-L462
train
joomla-framework/filesystem
src/File.php
File.makeSafe
public static function makeSafe($file, array $stripChars = array('#^\.#')) { $regex = array_merge(array('#(\.){2,}#', '#[^A-Za-z0-9\.\_\- ]#'), $stripChars); $file = preg_replace($regex, '', $file); // Remove any trailing dots, as those aren't ever valid file names. $file = rtrim($file, '.'); return $file; }
php
public static function makeSafe($file, array $stripChars = array('#^\.#')) { $regex = array_merge(array('#(\.){2,}#', '#[^A-Za-z0-9\.\_\- ]#'), $stripChars); $file = preg_replace($regex, '', $file); // Remove any trailing dots, as those aren't ever valid file names. $file = rtrim($file, '.'); return $file; }
[ "public", "static", "function", "makeSafe", "(", "$", "file", ",", "array", "$", "stripChars", "=", "array", "(", "'#^\\.#'", ")", ")", "{", "$", "regex", "=", "array_merge", "(", "array", "(", "'#(\\.){2,}#'", ",", "'#[^A-Za-z0-9\\.\\_\\- ]#'", ")", ",", "$", "stripChars", ")", ";", "$", "file", "=", "preg_replace", "(", "$", "regex", ",", "''", ",", "$", "file", ")", ";", "// Remove any trailing dots, as those aren't ever valid file names.", "$", "file", "=", "rtrim", "(", "$", "file", ",", "'.'", ")", ";", "return", "$", "file", ";", "}" ]
Makes the file name safe to use @param string $file The name of the file [not full path] @param array $stripChars Array of regex (by default will remove any leading periods) @return string The sanitised string @since 1.0
[ "Makes", "the", "file", "name", "safe", "to", "use" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/File.php#L44-L54
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Common/CountryCode.php
CountryCode.detectFormat
private function detectFormat() { if (preg_match('/^[[:alpha:]]{2}$/', $this->value)) { $this->format = 'alpha2'; } elseif (preg_match('/^[[:alpha:]]{3}$/', $this->value)) { $this->format = 'alpha3'; } elseif (preg_match('/^[[:digit:]]{3}$/', $this->value)) { $this->format = 'numeric'; } else { throw new Exception("The country code is not formatted correctly {$this->value}"); } }
php
private function detectFormat() { if (preg_match('/^[[:alpha:]]{2}$/', $this->value)) { $this->format = 'alpha2'; } elseif (preg_match('/^[[:alpha:]]{3}$/', $this->value)) { $this->format = 'alpha3'; } elseif (preg_match('/^[[:digit:]]{3}$/', $this->value)) { $this->format = 'numeric'; } else { throw new Exception("The country code is not formatted correctly {$this->value}"); } }
[ "private", "function", "detectFormat", "(", ")", "{", "if", "(", "preg_match", "(", "'/^[[:alpha:]]{2}$/'", ",", "$", "this", "->", "value", ")", ")", "{", "$", "this", "->", "format", "=", "'alpha2'", ";", "}", "elseif", "(", "preg_match", "(", "'/^[[:alpha:]]{3}$/'", ",", "$", "this", "->", "value", ")", ")", "{", "$", "this", "->", "format", "=", "'alpha3'", ";", "}", "elseif", "(", "preg_match", "(", "'/^[[:digit:]]{3}$/'", ",", "$", "this", "->", "value", ")", ")", "{", "$", "this", "->", "format", "=", "'numeric'", ";", "}", "else", "{", "throw", "new", "Exception", "(", "\"The country code is not formatted correctly {$this->value}\"", ")", ";", "}", "}" ]
Detects the format of country name from the given value. @throws \Exception @return void
[ "Detects", "the", "format", "of", "country", "name", "from", "the", "given", "value", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Common/CountryCode.php#L58-L69
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ArtistApi.php
ArtistApi.getImages
public function getImages($methodVars) { $vars = array( 'method' => 'artist.getinfo', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $info['image']['small'] = isset($call->artist->image[0]) ? (string) $call->artist->image[0] : null; $info['image']['medium'] = isset($call->artist->image[1]) ? (string) $call->artist->image[1] : null; $info['image']['large'] = isset($call->artist->image[2]) ? (string) $call->artist->image[2] : null; $info['image']['extralarge'] = isset($call->artist->image[3]) ? (string) $call->artist->image[3] : null; $info['image']['mega'] = isset($call->artist->image[4]) ? (string) $call->artist->image[4] : null; return $info; } else { return false; } }
php
public function getImages($methodVars) { $vars = array( 'method' => 'artist.getinfo', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $info['image']['small'] = isset($call->artist->image[0]) ? (string) $call->artist->image[0] : null; $info['image']['medium'] = isset($call->artist->image[1]) ? (string) $call->artist->image[1] : null; $info['image']['large'] = isset($call->artist->image[2]) ? (string) $call->artist->image[2] : null; $info['image']['extralarge'] = isset($call->artist->image[3]) ? (string) $call->artist->image[3] : null; $info['image']['mega'] = isset($call->artist->image[4]) ? (string) $call->artist->image[4] : null; return $info; } else { return false; } }
[ "public", "function", "getImages", "(", "$", "methodVars", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'artist.getinfo'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "info", "[", "'image'", "]", "[", "'small'", "]", "=", "isset", "(", "$", "call", "->", "artist", "->", "image", "[", "0", "]", ")", "?", "(", "string", ")", "$", "call", "->", "artist", "->", "image", "[", "0", "]", ":", "null", ";", "$", "info", "[", "'image'", "]", "[", "'medium'", "]", "=", "isset", "(", "$", "call", "->", "artist", "->", "image", "[", "1", "]", ")", "?", "(", "string", ")", "$", "call", "->", "artist", "->", "image", "[", "1", "]", ":", "null", ";", "$", "info", "[", "'image'", "]", "[", "'large'", "]", "=", "isset", "(", "$", "call", "->", "artist", "->", "image", "[", "2", "]", ")", "?", "(", "string", ")", "$", "call", "->", "artist", "->", "image", "[", "2", "]", ":", "null", ";", "$", "info", "[", "'image'", "]", "[", "'extralarge'", "]", "=", "isset", "(", "$", "call", "->", "artist", "->", "image", "[", "3", "]", ")", "?", "(", "string", ")", "$", "call", "->", "artist", "->", "image", "[", "3", "]", ":", "null", ";", "$", "info", "[", "'image'", "]", "[", "'mega'", "]", "=", "isset", "(", "$", "call", "->", "artist", "->", "image", "[", "4", "]", ")", "?", "(", "string", ")", "$", "call", "->", "artist", "->", "image", "[", "4", "]", ":", "null", ";", "return", "$", "info", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Get all images for an artist on Last.fm. @param array $methodVars An array with the following values: <i>artist</i> or <i>mbid</i> @return array
[ "Get", "all", "images", "for", "an", "artist", "on", "Last", ".", "fm", "." ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ArtistApi.php#L129-L148
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ArtistApi.php
ArtistApi.getShouts
public function getShouts($methodVars) { if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.getshouts', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $shouts['artist'] = (string) $call->shouts['artist']; $shouts['total'] = (string) $call->shouts['total']; $i = 0; foreach ($call->shouts->shout as $shout) { $shouts['shouts'][$i]['body'] = (string) $shout->body; $shouts['shouts'][$i]['author'] = (string) $shout->author; $shouts['shouts'][$i]['date'] = strtotime((string) $shout->date); $i++; } return $shouts; } else { return false; } } else { throw new InvalidArgumentException('You must include artist variable in the call for this method'); } }
php
public function getShouts($methodVars) { if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.getshouts', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $shouts['artist'] = (string) $call->shouts['artist']; $shouts['total'] = (string) $call->shouts['total']; $i = 0; foreach ($call->shouts->shout as $shout) { $shouts['shouts'][$i]['body'] = (string) $shout->body; $shouts['shouts'][$i]['author'] = (string) $shout->author; $shouts['shouts'][$i]['date'] = strtotime((string) $shout->date); $i++; } return $shouts; } else { return false; } } else { throw new InvalidArgumentException('You must include artist variable in the call for this method'); } }
[ "public", "function", "getShouts", "(", "$", "methodVars", ")", "{", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", "||", "!", "empty", "(", "$", "methodVars", "[", "'mbid'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'artist.getshouts'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "shouts", "[", "'artist'", "]", "=", "(", "string", ")", "$", "call", "->", "shouts", "[", "'artist'", "]", ";", "$", "shouts", "[", "'total'", "]", "=", "(", "string", ")", "$", "call", "->", "shouts", "[", "'total'", "]", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "shouts", "->", "shout", "as", "$", "shout", ")", "{", "$", "shouts", "[", "'shouts'", "]", "[", "$", "i", "]", "[", "'body'", "]", "=", "(", "string", ")", "$", "shout", "->", "body", ";", "$", "shouts", "[", "'shouts'", "]", "[", "$", "i", "]", "[", "'author'", "]", "=", "(", "string", ")", "$", "shout", "->", "author", ";", "$", "shouts", "[", "'shouts'", "]", "[", "$", "i", "]", "[", "'date'", "]", "=", "strtotime", "(", "(", "string", ")", "$", "shout", "->", "date", ")", ";", "$", "i", "++", ";", "}", "return", "$", "shouts", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include artist variable in the call for this method'", ")", ";", "}", "}" ]
Get shouts for this artist. @deprecated as of march 15 2016, 'artist.getshouts' service is not available @param array $methodVars An array with the following required values: <i>artist</i> @return array
[ "Get", "shouts", "for", "this", "artist", "." ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ArtistApi.php#L214-L241
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ArtistApi.php
ArtistApi.getSimilar
public function getSimilar($methodVars) { // Check for required variables if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.getsimilar', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $similar = array(); $i = 0; foreach ($call->similarartists->artist as $artist) { $similar[$i]['name'] = (string) $artist->name; $similar[$i]['mbid'] = (string) $artist->mbid; $similar[$i]['match'] = (string) $artist->match; $similar[$i]['url'] = (string) $artist->url; $similar[$i]['image'] = (string) $artist->image; $i++; } return $similar; } else { return false; } } else { throw new InvalidArgumentException('You must include artist variable in the call for this method'); } }
php
public function getSimilar($methodVars) { // Check for required variables if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.getsimilar', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $similar = array(); $i = 0; foreach ($call->similarartists->artist as $artist) { $similar[$i]['name'] = (string) $artist->name; $similar[$i]['mbid'] = (string) $artist->mbid; $similar[$i]['match'] = (string) $artist->match; $similar[$i]['url'] = (string) $artist->url; $similar[$i]['image'] = (string) $artist->image; $i++; } return $similar; } else { return false; } } else { throw new InvalidArgumentException('You must include artist variable in the call for this method'); } }
[ "public", "function", "getSimilar", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", "||", "!", "empty", "(", "$", "methodVars", "[", "'mbid'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'artist.getsimilar'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "similar", "=", "array", "(", ")", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "similarartists", "->", "artist", "as", "$", "artist", ")", "{", "$", "similar", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "artist", "->", "name", ";", "$", "similar", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "artist", "->", "mbid", ";", "$", "similar", "[", "$", "i", "]", "[", "'match'", "]", "=", "(", "string", ")", "$", "artist", "->", "match", ";", "$", "similar", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "artist", "->", "url", ";", "$", "similar", "[", "$", "i", "]", "[", "'image'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", ";", "$", "i", "++", ";", "}", "return", "$", "similar", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include artist variable in the call for this method'", ")", ";", "}", "}" ]
Get all the artists similar to this artist @param array $methodVars An array with the following required value: <i>artist</i> and optional value: <i>limit</i> @return array
[ "Get", "all", "the", "artists", "similar", "to", "this", "artist" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ArtistApi.php#L248-L277
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ArtistApi.php
ArtistApi.getTopAlbums
public function getTopAlbums($methodVars) { // Check for required variables if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.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]['rank'] = (string) $album['rank']; $topAlbums[$i]['name'] = (string) $album->name; $topAlbums[$i]['mbid'] = (string) $album->mbid; $topAlbums[$i]['playcount'] = (string) $album->playcount; $topAlbums[$i]['url'] = (string) $album->url; $topAlbums[$i]['image']['small'] = (string) $album->image[0]; $topAlbums[$i]['image']['medium'] = (string) $album->image[1]; $topAlbums[$i]['image']['large'] = (string) $album->image[2]; $i++; } return $topAlbums; } else { throw new NoResultsException('Artist has no top albums'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist varialbe in the call for this method'); } }
php
public function getTopAlbums($methodVars) { // Check for required variables if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.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]['rank'] = (string) $album['rank']; $topAlbums[$i]['name'] = (string) $album->name; $topAlbums[$i]['mbid'] = (string) $album->mbid; $topAlbums[$i]['playcount'] = (string) $album->playcount; $topAlbums[$i]['url'] = (string) $album->url; $topAlbums[$i]['image']['small'] = (string) $album->image[0]; $topAlbums[$i]['image']['medium'] = (string) $album->image[1]; $topAlbums[$i]['image']['large'] = (string) $album->image[2]; $i++; } return $topAlbums; } else { throw new NoResultsException('Artist has no top albums'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist varialbe in the call for this method'); } }
[ "public", "function", "getTopAlbums", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", "||", "!", "empty", "(", "$", "methodVars", "[", "'mbid'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'artist.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", "]", "[", "'rank'", "]", "=", "(", "string", ")", "$", "album", "[", "'rank'", "]", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "album", "->", "name", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "album", "->", "mbid", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'playcount'", "]", "=", "(", "string", ")", "$", "album", "->", "playcount", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "album", "->", "url", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "0", "]", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "1", "]", ";", "$", "topAlbums", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "album", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "topAlbums", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'Artist has no top albums'", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include artist varialbe in the call for this method'", ")", ";", "}", "}" ]
Get the top albums for an artist on Last.fm, ordered by popularity @param array $methodVars An array with the following required values: <i>artist</i> and optional value: <i>limit</i>, <i></i> @return array
[ "Get", "the", "top", "albums", "for", "an", "artist", "on", "Last", ".", "fm", "ordered", "by", "popularity" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ArtistApi.php#L328-L363
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ArtistApi.php
ArtistApi.getTopFans
public function getTopFans($methodVars) { // Check for required variables if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.gettopfans', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { if (count($call->topfans->user) > 0) { $i = 0; foreach ($call->topfans->user as $user) { $topFans[$i]['name'] = (string) $user->name; $topFans[$i]['url'] = (string) $user->url; $topFans[$i]['image']['small'] = (string) $user->image[0]; $topFans[$i]['image']['medium'] = (string) $user->image[1]; $topFans[$i]['image']['large'] = (string) $user->image[2]; $topFans[$i]['weight'] = (string) $user->weight; $i++; } return $topFans; } else { throw new NoResultsException('Artist has no top users'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist varialbe in the call for this method'); } }
php
public function getTopFans($methodVars) { // Check for required variables if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.gettopfans', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { if (count($call->topfans->user) > 0) { $i = 0; foreach ($call->topfans->user as $user) { $topFans[$i]['name'] = (string) $user->name; $topFans[$i]['url'] = (string) $user->url; $topFans[$i]['image']['small'] = (string) $user->image[0]; $topFans[$i]['image']['medium'] = (string) $user->image[1]; $topFans[$i]['image']['large'] = (string) $user->image[2]; $topFans[$i]['weight'] = (string) $user->weight; $i++; } return $topFans; } else { throw new NoResultsException('Artist has no top users'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist varialbe in the call for this method'); } }
[ "public", "function", "getTopFans", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", "||", "!", "empty", "(", "$", "methodVars", "[", "'mbid'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'artist.gettopfans'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "if", "(", "count", "(", "$", "call", "->", "topfans", "->", "user", ")", ">", "0", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "topfans", "->", "user", "as", "$", "user", ")", "{", "$", "topFans", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "user", "->", "name", ";", "$", "topFans", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "user", "->", "url", ";", "$", "topFans", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "user", "->", "image", "[", "0", "]", ";", "$", "topFans", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "user", "->", "image", "[", "1", "]", ";", "$", "topFans", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "user", "->", "image", "[", "2", "]", ";", "$", "topFans", "[", "$", "i", "]", "[", "'weight'", "]", "=", "(", "string", ")", "$", "user", "->", "weight", ";", "$", "i", "++", ";", "}", "return", "$", "topFans", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'Artist has no top users'", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include artist varialbe in the call for this method'", ")", ";", "}", "}" ]
Get the top fans for an artist on Last.fm, based on listening data @deprecated as of march 15 2016, 'artist.gettopfans' service is not available @param array $methodVars An array with the following required values: <i>artist</i> @return array
[ "Get", "the", "top", "fans", "for", "an", "artist", "on", "Last", ".", "fm", "based", "on", "listening", "data" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ArtistApi.php#L371-L404
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ArtistApi.php
ArtistApi.getTopTracks
public function getTopTracks($methodVars) { // Check for required variables if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.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 $tracks) { $topTracks[$i]['rank'] = (string) $tracks['rank']; $topTracks[$i]['name'] = (string) $tracks->name; $topTracks[$i]['playcount'] = (string) $tracks->playcount; $topTracks[$i]['streamable'] = (string) $tracks->streamable; $topTracks[$i]['url'] = (string) $tracks->url; $topTracks[$i]['image']['small'] = (string) $tracks->image[0]; $topTracks[$i]['image']['medium'] = (string) $tracks->image[1]; $topTracks[$i]['image']['large'] = (string) $tracks->image[2]; $i++; } return $topTracks; } else { throw new NoResultsException('Artist has no top tracks'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist varialbe in the call for this method'); } }
php
public function getTopTracks($methodVars) { // Check for required variables if (!empty($methodVars['artist']) || !empty($methodVars['mbid'])) { $vars = array( 'method' => 'artist.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 $tracks) { $topTracks[$i]['rank'] = (string) $tracks['rank']; $topTracks[$i]['name'] = (string) $tracks->name; $topTracks[$i]['playcount'] = (string) $tracks->playcount; $topTracks[$i]['streamable'] = (string) $tracks->streamable; $topTracks[$i]['url'] = (string) $tracks->url; $topTracks[$i]['image']['small'] = (string) $tracks->image[0]; $topTracks[$i]['image']['medium'] = (string) $tracks->image[1]; $topTracks[$i]['image']['large'] = (string) $tracks->image[2]; $i++; } return $topTracks; } else { throw new NoResultsException('Artist has no top tracks'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist varialbe in the call for this method'); } }
[ "public", "function", "getTopTracks", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", "||", "!", "empty", "(", "$", "methodVars", "[", "'mbid'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'artist.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", "$", "tracks", ")", "{", "$", "topTracks", "[", "$", "i", "]", "[", "'rank'", "]", "=", "(", "string", ")", "$", "tracks", "[", "'rank'", "]", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "tracks", "->", "name", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'playcount'", "]", "=", "(", "string", ")", "$", "tracks", "->", "playcount", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "tracks", "->", "streamable", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "tracks", "->", "url", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "tracks", "->", "image", "[", "0", "]", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "tracks", "->", "image", "[", "1", "]", ";", "$", "topTracks", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "tracks", "->", "image", "[", "2", "]", ";", "$", "i", "++", ";", "}", "return", "$", "topTracks", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'Artist has no top tracks'", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include artist varialbe in the call for this method'", ")", ";", "}", "}" ]
Get the top tracks by an artist on Last.fm, ordered by popularity @param array $methodVars An array with the following required values: <i>artist</i> and optional value: <i>limit</i> @return array
[ "Get", "the", "top", "tracks", "by", "an", "artist", "on", "Last", ".", "fm", "ordered", "by", "popularity" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ArtistApi.php#L447-L482
train
matt-oakes/PHP-Last.fm-API
src/lastfmapi/Api/ArtistApi.php
ArtistApi.search
public function search($methodVars) { // Check for required variables if (!empty($methodVars['artist'])) { $vars = array( 'method' => 'artist.search', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $callNamespaces = $call->getDocNamespaces(true); // fix missing namespace (sic) if (!isset($callNamespaces['opensearch'])) { $call->results->addAttribute('xmlns:xmlns:opensearch', 'http://a9.com/-/spec/opensearch/1.1/'); $call = new SimpleXMLElement($call->asXML()); } $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/'); if ($opensearch->totalResults > 0) { $searchResults['totalResults'] = (string) $opensearch->totalResults; $searchResults['startIndex'] = (string) $opensearch->startIndex; $searchResults['itemsPerPage'] = (string) $opensearch->itemsPerPage; $i = 0; foreach ($call->results->artistmatches->artist as $artist) { $searchResults['results'][$i]['name'] = (string) $artist->name; $searchResults['results'][$i]['mbid'] = (string) $artist->mbid; $searchResults['results'][$i]['url'] = (string) $artist->url; $searchResults['results'][$i]['streamable'] = (string) $artist->streamable; $searchResults['results'][$i]['image']['small'] = (string) $artist->image[0]; $searchResults['results'][$i]['image']['medium'] = (string) $artist->image[1]; $searchResults['results'][$i]['image']['large'] = (string) $artist->image[2]; $searchResults['results'][$i]['image']['extralarge'] = (string) $artist->image[3]; $searchResults['results'][$i]['image']['mega'] = (string) $artist->image[4]; $i++; } return $searchResults; } else { throw new NoResultsException('No results'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist variable in the call for this method'); } }
php
public function search($methodVars) { // Check for required variables if (!empty($methodVars['artist'])) { $vars = array( 'method' => 'artist.search', 'api_key' => $this->auth->apiKey ); $vars = array_merge($vars, $methodVars); if ($call = $this->apiGetCall($vars)) { $callNamespaces = $call->getDocNamespaces(true); // fix missing namespace (sic) if (!isset($callNamespaces['opensearch'])) { $call->results->addAttribute('xmlns:xmlns:opensearch', 'http://a9.com/-/spec/opensearch/1.1/'); $call = new SimpleXMLElement($call->asXML()); } $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/'); if ($opensearch->totalResults > 0) { $searchResults['totalResults'] = (string) $opensearch->totalResults; $searchResults['startIndex'] = (string) $opensearch->startIndex; $searchResults['itemsPerPage'] = (string) $opensearch->itemsPerPage; $i = 0; foreach ($call->results->artistmatches->artist as $artist) { $searchResults['results'][$i]['name'] = (string) $artist->name; $searchResults['results'][$i]['mbid'] = (string) $artist->mbid; $searchResults['results'][$i]['url'] = (string) $artist->url; $searchResults['results'][$i]['streamable'] = (string) $artist->streamable; $searchResults['results'][$i]['image']['small'] = (string) $artist->image[0]; $searchResults['results'][$i]['image']['medium'] = (string) $artist->image[1]; $searchResults['results'][$i]['image']['large'] = (string) $artist->image[2]; $searchResults['results'][$i]['image']['extralarge'] = (string) $artist->image[3]; $searchResults['results'][$i]['image']['mega'] = (string) $artist->image[4]; $i++; } return $searchResults; } else { throw new NoResultsException('No results'); } } else { return false; } } else { throw new InvalidArgumentException('You must include artist variable in the call for this method'); } }
[ "public", "function", "search", "(", "$", "methodVars", ")", "{", "// Check for required variables", "if", "(", "!", "empty", "(", "$", "methodVars", "[", "'artist'", "]", ")", ")", "{", "$", "vars", "=", "array", "(", "'method'", "=>", "'artist.search'", ",", "'api_key'", "=>", "$", "this", "->", "auth", "->", "apiKey", ")", ";", "$", "vars", "=", "array_merge", "(", "$", "vars", ",", "$", "methodVars", ")", ";", "if", "(", "$", "call", "=", "$", "this", "->", "apiGetCall", "(", "$", "vars", ")", ")", "{", "$", "callNamespaces", "=", "$", "call", "->", "getDocNamespaces", "(", "true", ")", ";", "// fix missing namespace (sic)", "if", "(", "!", "isset", "(", "$", "callNamespaces", "[", "'opensearch'", "]", ")", ")", "{", "$", "call", "->", "results", "->", "addAttribute", "(", "'xmlns:xmlns:opensearch'", ",", "'http://a9.com/-/spec/opensearch/1.1/'", ")", ";", "$", "call", "=", "new", "SimpleXMLElement", "(", "$", "call", "->", "asXML", "(", ")", ")", ";", "}", "$", "opensearch", "=", "$", "call", "->", "results", "->", "children", "(", "'http://a9.com/-/spec/opensearch/1.1/'", ")", ";", "if", "(", "$", "opensearch", "->", "totalResults", ">", "0", ")", "{", "$", "searchResults", "[", "'totalResults'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "totalResults", ";", "$", "searchResults", "[", "'startIndex'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "startIndex", ";", "$", "searchResults", "[", "'itemsPerPage'", "]", "=", "(", "string", ")", "$", "opensearch", "->", "itemsPerPage", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "call", "->", "results", "->", "artistmatches", "->", "artist", "as", "$", "artist", ")", "{", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'name'", "]", "=", "(", "string", ")", "$", "artist", "->", "name", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'mbid'", "]", "=", "(", "string", ")", "$", "artist", "->", "mbid", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'url'", "]", "=", "(", "string", ")", "$", "artist", "->", "url", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'streamable'", "]", "=", "(", "string", ")", "$", "artist", "->", "streamable", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'small'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "0", "]", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'medium'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "1", "]", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'large'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "2", "]", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'extralarge'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "3", "]", ";", "$", "searchResults", "[", "'results'", "]", "[", "$", "i", "]", "[", "'image'", "]", "[", "'mega'", "]", "=", "(", "string", ")", "$", "artist", "->", "image", "[", "4", "]", ";", "$", "i", "++", ";", "}", "return", "$", "searchResults", ";", "}", "else", "{", "throw", "new", "NoResultsException", "(", "'No results'", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You must include artist variable in the call for this method'", ")", ";", "}", "}" ]
Search for an artist by name. Returns artist matches sorted by relevance @param array $methodVars An array with the following required value: <i>artist</i> and optional values: <i>limite</i>, <i>page</i> @return array
[ "Search", "for", "an", "artist", "by", "name", ".", "Returns", "artist", "matches", "sorted", "by", "relevance" ]
5c639597517167c49bd28419dde4d378efe5ed50
https://github.com/matt-oakes/PHP-Last.fm-API/blob/5c639597517167c49bd28419dde4d378efe5ed50/src/lastfmapi/Api/ArtistApi.php#L522-L568
train
joomla-framework/filesystem
src/Stream.php
Stream._buildContext
public function _buildContext() { // According to the manual this always works! if (\count($this->contextOptions)) { $this->context = @stream_context_create($this->contextOptions); } else { $this->context = null; } }
php
public function _buildContext() { // According to the manual this always works! if (\count($this->contextOptions)) { $this->context = @stream_context_create($this->contextOptions); } else { $this->context = null; } }
[ "public", "function", "_buildContext", "(", ")", "{", "// According to the manual this always works!", "if", "(", "\\", "count", "(", "$", "this", "->", "contextOptions", ")", ")", "{", "$", "this", "->", "context", "=", "@", "stream_context_create", "(", "$", "this", "->", "contextOptions", ")", ";", "}", "else", "{", "$", "this", "->", "context", "=", "null", ";", "}", "}" ]
Stream contexts Builds the context from the array @return void @since 1.0
[ "Stream", "contexts", "Builds", "the", "context", "from", "the", "array" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Stream.php#L941-L952
train
joomla-framework/filesystem
src/Stream.php
Stream.addContextEntry
public function addContextEntry($wrapper, $name, $value) { $this->contextOptions[$wrapper][$name] = $value; $this->_buildContext(); }
php
public function addContextEntry($wrapper, $name, $value) { $this->contextOptions[$wrapper][$name] = $value; $this->_buildContext(); }
[ "public", "function", "addContextEntry", "(", "$", "wrapper", ",", "$", "name", ",", "$", "value", ")", "{", "$", "this", "->", "contextOptions", "[", "$", "wrapper", "]", "[", "$", "name", "]", "=", "$", "value", ";", "$", "this", "->", "_buildContext", "(", ")", ";", "}" ]
Adds a particular options to the context @param string $wrapper The wrapper to use @param string $name The option to set @param string $value The value of the option @return void @link https://www.php.net/stream_context_create Stream Context Creation @link https://www.php.net/manual/en/context.php Context Options for various streams @since 1.0
[ "Adds", "a", "particular", "options", "to", "the", "context" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Stream.php#L985-L989
train
joomla-framework/filesystem
src/Stream.php
Stream.deleteContextEntry
public function deleteContextEntry($wrapper, $name) { // Check whether the wrapper is set if (isset($this->contextOptions[$wrapper])) { // Check that entry is set for that wrapper if (isset($this->contextOptions[$wrapper][$name])) { // Unset the item unset($this->contextOptions[$wrapper][$name]); // Check that there are still items there if (!\count($this->contextOptions[$wrapper])) { // Clean up an empty wrapper context option unset($this->contextOptions[$wrapper]); } } } // Rebuild the context and apply it to the stream $this->_buildContext(); }
php
public function deleteContextEntry($wrapper, $name) { // Check whether the wrapper is set if (isset($this->contextOptions[$wrapper])) { // Check that entry is set for that wrapper if (isset($this->contextOptions[$wrapper][$name])) { // Unset the item unset($this->contextOptions[$wrapper][$name]); // Check that there are still items there if (!\count($this->contextOptions[$wrapper])) { // Clean up an empty wrapper context option unset($this->contextOptions[$wrapper]); } } } // Rebuild the context and apply it to the stream $this->_buildContext(); }
[ "public", "function", "deleteContextEntry", "(", "$", "wrapper", ",", "$", "name", ")", "{", "// Check whether the wrapper is set", "if", "(", "isset", "(", "$", "this", "->", "contextOptions", "[", "$", "wrapper", "]", ")", ")", "{", "// Check that entry is set for that wrapper", "if", "(", "isset", "(", "$", "this", "->", "contextOptions", "[", "$", "wrapper", "]", "[", "$", "name", "]", ")", ")", "{", "// Unset the item", "unset", "(", "$", "this", "->", "contextOptions", "[", "$", "wrapper", "]", "[", "$", "name", "]", ")", ";", "// Check that there are still items there", "if", "(", "!", "\\", "count", "(", "$", "this", "->", "contextOptions", "[", "$", "wrapper", "]", ")", ")", "{", "// Clean up an empty wrapper context option", "unset", "(", "$", "this", "->", "contextOptions", "[", "$", "wrapper", "]", ")", ";", "}", "}", "}", "// Rebuild the context and apply it to the stream", "$", "this", "->", "_buildContext", "(", ")", ";", "}" ]
Deletes a particular setting from a context @param string $wrapper The wrapper to use @param string $name The option to unset @return void @link https://www.php.net/stream_context_create @since 1.0
[ "Deletes", "a", "particular", "setting", "from", "a", "context" ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Stream.php#L1002-L1024
train
joomla-framework/filesystem
src/Stream.php
Stream.writeFile
public function writeFile($filename, &$buffer, $appendToFile = false) { $fileMode = 'w'; // Switch the filemode when we want to append to the file if ($appendToFile) { $fileMode = 'a'; } if ($this->open($filename, $fileMode)) { $result = $this->write($buffer); $this->chmod(); $this->close(); return $result; } return false; }
php
public function writeFile($filename, &$buffer, $appendToFile = false) { $fileMode = 'w'; // Switch the filemode when we want to append to the file if ($appendToFile) { $fileMode = 'a'; } if ($this->open($filename, $fileMode)) { $result = $this->write($buffer); $this->chmod(); $this->close(); return $result; } return false; }
[ "public", "function", "writeFile", "(", "$", "filename", ",", "&", "$", "buffer", ",", "$", "appendToFile", "=", "false", ")", "{", "$", "fileMode", "=", "'w'", ";", "// Switch the filemode when we want to append to the file", "if", "(", "$", "appendToFile", ")", "{", "$", "fileMode", "=", "'a'", ";", "}", "if", "(", "$", "this", "->", "open", "(", "$", "filename", ",", "$", "fileMode", ")", ")", "{", "$", "result", "=", "$", "this", "->", "write", "(", "$", "buffer", ")", ";", "$", "this", "->", "chmod", "(", ")", ";", "$", "this", "->", "close", "(", ")", ";", "return", "$", "result", ";", "}", "return", "false", ";", "}" ]
Writes a chunk of data to a file. @param string $filename The file name. @param string $buffer The data to write to the file. @param boolean $appendToFile Append to the file and not overwrite it. @return boolean @since 1.0
[ "Writes", "a", "chunk", "of", "data", "to", "a", "file", "." ]
c3682aabfb64a68ca1e1409c4c76b55968c9cd15
https://github.com/joomla-framework/filesystem/blob/c3682aabfb64a68ca1e1409c4c76b55968c9cd15/src/Stream.php#L1376-L1396
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/FatZebra.php
FatZebra.purchase
public function purchase($money, $creditcard, $options = array()) { Options::required('order_id, ip', $options); $this->post = array(); $options = new Options($options); $this->addInvoice($options->order_id, $money); if (is_string($creditcard)) { Options::required('cvv', $options); $this->post['card_token'] = $creditcard; } else { $this->addCreditcard($creditcard); } $this->addCustomerData($options); return $this->commit('purchases'); }
php
public function purchase($money, $creditcard, $options = array()) { Options::required('order_id, ip', $options); $this->post = array(); $options = new Options($options); $this->addInvoice($options->order_id, $money); if (is_string($creditcard)) { Options::required('cvv', $options); $this->post['card_token'] = $creditcard; } else { $this->addCreditcard($creditcard); } $this->addCustomerData($options); return $this->commit('purchases'); }
[ "public", "function", "purchase", "(", "$", "money", ",", "$", "creditcard", ",", "$", "options", "=", "array", "(", ")", ")", "{", "Options", "::", "required", "(", "'order_id, ip'", ",", "$", "options", ")", ";", "$", "this", "->", "post", "=", "array", "(", ")", ";", "$", "options", "=", "new", "Options", "(", "$", "options", ")", ";", "$", "this", "->", "addInvoice", "(", "$", "options", "->", "order_id", ",", "$", "money", ")", ";", "if", "(", "is_string", "(", "$", "creditcard", ")", ")", "{", "Options", "::", "required", "(", "'cvv'", ",", "$", "options", ")", ";", "$", "this", "->", "post", "[", "'card_token'", "]", "=", "$", "creditcard", ";", "}", "else", "{", "$", "this", "->", "addCreditcard", "(", "$", "creditcard", ")", ";", "}", "$", "this", "->", "addCustomerData", "(", "$", "options", ")", ";", "return", "$", "this", "->", "commit", "(", "'purchases'", ")", ";", "}" ]
Charge a credit card. @param number $money Amount of money to charge @param CreditCard | string $creditcard Credit card to charge or a token from a stored credit card @param array $options The order_id reference and coustomer ip. @access public @throws \AktiveMerchant\Billing\Exception If the request fails @return \AktiveMerchant\Billing\Response Response object
[ "Charge", "a", "credit", "card", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/FatZebra.php#L106-L127
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/FatZebra.php
FatZebra.store
public function store(CreditCard $creditcard, $options = array()) { $this->post = array(); $this->addCreditcard($creditcard); return $this->commit('credit_cards'); }
php
public function store(CreditCard $creditcard, $options = array()) { $this->post = array(); $this->addCreditcard($creditcard); return $this->commit('credit_cards'); }
[ "public", "function", "store", "(", "CreditCard", "$", "creditcard", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "post", "=", "array", "(", ")", ";", "$", "this", "->", "addCreditcard", "(", "$", "creditcard", ")", ";", "return", "$", "this", "->", "commit", "(", "'credit_cards'", ")", ";", "}" ]
Stores a reference of a credit card. @param CreditCard $creditcard @access public @return void
[ "Stores", "a", "reference", "of", "a", "credit", "card", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/FatZebra.php#L159-L166
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/FatZebra.php
FatZebra.recurring
public function recurring($plan, CreditCard $creditcard, $options = array()) { $this->post = array(); Options::required('first_name, last_name, email, customer_id, start_date, period', $options); $options = new Options($options); if (null === $options->customer_id) { $response = $this->createCustomer($creditcard, $options); $customer_id = $response->params()->id; } else { $customer_id = $options->customer_id; } $this->post['customer'] = $customer_id; $start_date = $options->start_date instanceof \DateTime ? $options->start_date : new \DateTime(strtotime($options->start_date)); $this->post['start_date'] = $start_date->format('Y-m-d'); $this->post['plan'] = $plan; $this->post['frequency'] = $options->period; $this->post['is_active'] = true; $this->post['reference'] = $options->customer_id; return $this->commit('subscriptions'); }
php
public function recurring($plan, CreditCard $creditcard, $options = array()) { $this->post = array(); Options::required('first_name, last_name, email, customer_id, start_date, period', $options); $options = new Options($options); if (null === $options->customer_id) { $response = $this->createCustomer($creditcard, $options); $customer_id = $response->params()->id; } else { $customer_id = $options->customer_id; } $this->post['customer'] = $customer_id; $start_date = $options->start_date instanceof \DateTime ? $options->start_date : new \DateTime(strtotime($options->start_date)); $this->post['start_date'] = $start_date->format('Y-m-d'); $this->post['plan'] = $plan; $this->post['frequency'] = $options->period; $this->post['is_active'] = true; $this->post['reference'] = $options->customer_id; return $this->commit('subscriptions'); }
[ "public", "function", "recurring", "(", "$", "plan", ",", "CreditCard", "$", "creditcard", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "post", "=", "array", "(", ")", ";", "Options", "::", "required", "(", "'first_name, last_name, email, customer_id, start_date, period'", ",", "$", "options", ")", ";", "$", "options", "=", "new", "Options", "(", "$", "options", ")", ";", "if", "(", "null", "===", "$", "options", "->", "customer_id", ")", "{", "$", "response", "=", "$", "this", "->", "createCustomer", "(", "$", "creditcard", ",", "$", "options", ")", ";", "$", "customer_id", "=", "$", "response", "->", "params", "(", ")", "->", "id", ";", "}", "else", "{", "$", "customer_id", "=", "$", "options", "->", "customer_id", ";", "}", "$", "this", "->", "post", "[", "'customer'", "]", "=", "$", "customer_id", ";", "$", "start_date", "=", "$", "options", "->", "start_date", "instanceof", "\\", "DateTime", "?", "$", "options", "->", "start_date", ":", "new", "\\", "DateTime", "(", "strtotime", "(", "$", "options", "->", "start_date", ")", ")", ";", "$", "this", "->", "post", "[", "'start_date'", "]", "=", "$", "start_date", "->", "format", "(", "'Y-m-d'", ")", ";", "$", "this", "->", "post", "[", "'plan'", "]", "=", "$", "plan", ";", "$", "this", "->", "post", "[", "'frequency'", "]", "=", "$", "options", "->", "period", ";", "$", "this", "->", "post", "[", "'is_active'", "]", "=", "true", ";", "$", "this", "->", "post", "[", "'reference'", "]", "=", "$", "options", "->", "customer_id", ";", "return", "$", "this", "->", "commit", "(", "'subscriptions'", ")", ";", "}" ]
Creates a recurring billing subscription for a customer. Available options for period are: "Daily", "Weekly", "Fortnightly", "Monthly", "Quarterly", "Bi-Annually", "Annually" start_date can be a DateTime object a timestamp or a string the can be parsed via strtime function. customer_id can be a string with id returned when you created a customer (XXX-C-XXXXXXXX). if customer_id ommited then a new customer will be cteated. @param string $plan The plan id returned when you created a plan (XXX-PL-XXXXXXXX). @param CreditCard $creditcard @param array $options @access public @return void
[ "Creates", "a", "recurring", "billing", "subscription", "for", "a", "customer", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/FatZebra.php#L186-L210
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/FatZebra.php
FatZebra.updatePlan
public function updatePlan($plan_id, array $attrs = array()) { $this->post = array(); $attrs = new Options($attrs); $plan_id = urlencode(trim($plan_id)); if ($attrs->name) { $this->post['name'] = $attrs->name; } if ($attrs->description) { $this->post['description'] = $attrs->description; } return $this->commit("plans/{$plan_id}", RequestInterface::METHOD_PUT); }
php
public function updatePlan($plan_id, array $attrs = array()) { $this->post = array(); $attrs = new Options($attrs); $plan_id = urlencode(trim($plan_id)); if ($attrs->name) { $this->post['name'] = $attrs->name; } if ($attrs->description) { $this->post['description'] = $attrs->description; } return $this->commit("plans/{$plan_id}", RequestInterface::METHOD_PUT); }
[ "public", "function", "updatePlan", "(", "$", "plan_id", ",", "array", "$", "attrs", "=", "array", "(", ")", ")", "{", "$", "this", "->", "post", "=", "array", "(", ")", ";", "$", "attrs", "=", "new", "Options", "(", "$", "attrs", ")", ";", "$", "plan_id", "=", "urlencode", "(", "trim", "(", "$", "plan_id", ")", ")", ";", "if", "(", "$", "attrs", "->", "name", ")", "{", "$", "this", "->", "post", "[", "'name'", "]", "=", "$", "attrs", "->", "name", ";", "}", "if", "(", "$", "attrs", "->", "description", ")", "{", "$", "this", "->", "post", "[", "'description'", "]", "=", "$", "attrs", "->", "description", ";", "}", "return", "$", "this", "->", "commit", "(", "\"plans/{$plan_id}\"", ",", "RequestInterface", "::", "METHOD_PUT", ")", ";", "}" ]
Update attributes of a plan. Valid attributes are name and or description. <code> $attrs = array( 'name' => 'New Name', 'description' => 'New description' ); </code> @param string $plan_id The plan id of a plant to update. @param array $attrs An array holding the attributes to update @return Response
[ "Update", "attributes", "of", "a", "plan", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/FatZebra.php#L272-L287
train
akDeveloper/Aktive-Merchant
lib/AktiveMerchant/Billing/Gateways/FatZebra.php
FatZebra.updateCustomer
public function updateCustomer($customer_id, CreditCard $creditcard = null, $options = array()) { $this->post = array(); $options = new Options($options); $this->addCustomerData($options); $this->addAddress($options); $address = $this->post['address']; unset($this->post['address']); $this->post = array_merge($this->post, $address); if (null !== $creditcard) { $this->addRecurringCreditcard($creditcard); } $customer_id = urlencode(trim($customer_id)); return $this->commit("customers/{$customer_id}", RequestInterface::METHOD_PUT); }
php
public function updateCustomer($customer_id, CreditCard $creditcard = null, $options = array()) { $this->post = array(); $options = new Options($options); $this->addCustomerData($options); $this->addAddress($options); $address = $this->post['address']; unset($this->post['address']); $this->post = array_merge($this->post, $address); if (null !== $creditcard) { $this->addRecurringCreditcard($creditcard); } $customer_id = urlencode(trim($customer_id)); return $this->commit("customers/{$customer_id}", RequestInterface::METHOD_PUT); }
[ "public", "function", "updateCustomer", "(", "$", "customer_id", ",", "CreditCard", "$", "creditcard", "=", "null", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "post", "=", "array", "(", ")", ";", "$", "options", "=", "new", "Options", "(", "$", "options", ")", ";", "$", "this", "->", "addCustomerData", "(", "$", "options", ")", ";", "$", "this", "->", "addAddress", "(", "$", "options", ")", ";", "$", "address", "=", "$", "this", "->", "post", "[", "'address'", "]", ";", "unset", "(", "$", "this", "->", "post", "[", "'address'", "]", ")", ";", "$", "this", "->", "post", "=", "array_merge", "(", "$", "this", "->", "post", ",", "$", "address", ")", ";", "if", "(", "null", "!==", "$", "creditcard", ")", "{", "$", "this", "->", "addRecurringCreditcard", "(", "$", "creditcard", ")", ";", "}", "$", "customer_id", "=", "urlencode", "(", "trim", "(", "$", "customer_id", ")", ")", ";", "return", "$", "this", "->", "commit", "(", "\"customers/{$customer_id}\"", ",", "RequestInterface", "::", "METHOD_PUT", ")", ";", "}" ]
Updates customer information. @param string $customer_id The id returned from gateway when the customer record creted to the gateway. @param CreditCard $creditcard @param array $options @access public @return void
[ "Updates", "customer", "information", "." ]
00df4840e732ed1938a0a1718dfb50d67119d9a1
https://github.com/akDeveloper/Aktive-Merchant/blob/00df4840e732ed1938a0a1718dfb50d67119d9a1/lib/AktiveMerchant/Billing/Gateways/FatZebra.php#L314-L333
train
rdohms/dms-filter-bundle
src/DMS/Bundle/FilterBundle/Form/EventListener/DelegatingFilterListener.php
DelegatingFilterListener.getRootFormCascadeOption
public function getRootFormCascadeOption(FormInterface $form) { if (! $form->isRoot()) { return $this->getRootFormCascadeOption($form->getParent()); } return $form->getConfig()->getOption('cascade_filter', false); }
php
public function getRootFormCascadeOption(FormInterface $form) { if (! $form->isRoot()) { return $this->getRootFormCascadeOption($form->getParent()); } return $form->getConfig()->getOption('cascade_filter', false); }
[ "public", "function", "getRootFormCascadeOption", "(", "FormInterface", "$", "form", ")", "{", "if", "(", "!", "$", "form", "->", "isRoot", "(", ")", ")", "{", "return", "$", "this", "->", "getRootFormCascadeOption", "(", "$", "form", "->", "getParent", "(", ")", ")", ";", "}", "return", "$", "form", "->", "getConfig", "(", ")", "->", "getOption", "(", "'cascade_filter'", ",", "false", ")", ";", "}" ]
Navigates to the Root form to define if cascading should be done. @param FormInterface $form @return boolean
[ "Navigates", "to", "the", "Root", "form", "to", "define", "if", "cascading", "should", "be", "done", "." ]
25ff741f3339a41bec7c170a4f0d086a05960b90
https://github.com/rdohms/dms-filter-bundle/blob/25ff741f3339a41bec7c170a4f0d086a05960b90/src/DMS/Bundle/FilterBundle/Form/EventListener/DelegatingFilterListener.php#L74-L81
train
dereuromark/cakephp-setup
src/Shell/MaintenanceModeShell.php
MaintenanceModeShell.activate
public function activate() { $duration = (int)$this->params['duration']; $this->Maintenance->setMaintenanceMode($duration); $this->out('Maintenance mode activated ...'); }
php
public function activate() { $duration = (int)$this->params['duration']; $this->Maintenance->setMaintenanceMode($duration); $this->out('Maintenance mode activated ...'); }
[ "public", "function", "activate", "(", ")", "{", "$", "duration", "=", "(", "int", ")", "$", "this", "->", "params", "[", "'duration'", "]", ";", "$", "this", "->", "Maintenance", "->", "setMaintenanceMode", "(", "$", "duration", ")", ";", "$", "this", "->", "out", "(", "'Maintenance mode activated ...'", ")", ";", "}" ]
Activate maintenance mode with an optional timeout setting. @return void
[ "Activate", "maintenance", "mode", "with", "an", "optional", "timeout", "setting", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/MaintenanceModeShell.php#L62-L66
train
dereuromark/cakephp-setup
src/Shell/MaintenanceModeShell.php
MaintenanceModeShell.whitelist
public function whitelist() { if ($this->params['remove']) { $this->Maintenance->clearWhitelist(); } $ips = $this->args; if (!empty($ips)) { foreach ($ips as $ip) { if (!Validation::ip($ip)) { $this->abort($ip . ' is not a valid IP address.'); } } if ($this->params['remove']) { $this->Maintenance->clearWhitelist($ips); } else { $this->Maintenance->whitelist($ips, $this->params['debug']); } $this->out('Done!', 2); } $this->out('Current whitelist:'); $ips = $this->Maintenance->whitelist(); if (!$ips) { $this->out('n/a'); } else { $this->out($ips); } }
php
public function whitelist() { if ($this->params['remove']) { $this->Maintenance->clearWhitelist(); } $ips = $this->args; if (!empty($ips)) { foreach ($ips as $ip) { if (!Validation::ip($ip)) { $this->abort($ip . ' is not a valid IP address.'); } } if ($this->params['remove']) { $this->Maintenance->clearWhitelist($ips); } else { $this->Maintenance->whitelist($ips, $this->params['debug']); } $this->out('Done!', 2); } $this->out('Current whitelist:'); $ips = $this->Maintenance->whitelist(); if (!$ips) { $this->out('n/a'); } else { $this->out($ips); } }
[ "public", "function", "whitelist", "(", ")", "{", "if", "(", "$", "this", "->", "params", "[", "'remove'", "]", ")", "{", "$", "this", "->", "Maintenance", "->", "clearWhitelist", "(", ")", ";", "}", "$", "ips", "=", "$", "this", "->", "args", ";", "if", "(", "!", "empty", "(", "$", "ips", ")", ")", "{", "foreach", "(", "$", "ips", "as", "$", "ip", ")", "{", "if", "(", "!", "Validation", "::", "ip", "(", "$", "ip", ")", ")", "{", "$", "this", "->", "abort", "(", "$", "ip", ".", "' is not a valid IP address.'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "params", "[", "'remove'", "]", ")", "{", "$", "this", "->", "Maintenance", "->", "clearWhitelist", "(", "$", "ips", ")", ";", "}", "else", "{", "$", "this", "->", "Maintenance", "->", "whitelist", "(", "$", "ips", ",", "$", "this", "->", "params", "[", "'debug'", "]", ")", ";", "}", "$", "this", "->", "out", "(", "'Done!'", ",", "2", ")", ";", "}", "$", "this", "->", "out", "(", "'Current whitelist:'", ")", ";", "$", "ips", "=", "$", "this", "->", "Maintenance", "->", "whitelist", "(", ")", ";", "if", "(", "!", "$", "ips", ")", "{", "$", "this", "->", "out", "(", "'n/a'", ")", ";", "}", "else", "{", "$", "this", "->", "out", "(", "$", "ips", ")", ";", "}", "}" ]
Whitelist specific IPs. Each argument is a single IP. Not passing any argument will output the current whitelist. @return int|null
[ "Whitelist", "specific", "IPs", ".", "Each", "argument", "is", "a", "single", "IP", ".", "Not", "passing", "any", "argument", "will", "output", "the", "current", "whitelist", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/MaintenanceModeShell.php#L74-L101
train
middlewares/client-ip
src/ClientIp.php
ClientIp.proxy
public function proxy( array $ips = [], array $headers = [ 'Forwarded', 'Forwarded-For', 'X-Forwarded', 'X-Forwarded-For', 'X-Cluster-Client-Ip', 'Client-Ip', ] ): self { $this->proxyIps = $ips; $this->proxyHeaders = $headers; return $this; }
php
public function proxy( array $ips = [], array $headers = [ 'Forwarded', 'Forwarded-For', 'X-Forwarded', 'X-Forwarded-For', 'X-Cluster-Client-Ip', 'Client-Ip', ] ): self { $this->proxyIps = $ips; $this->proxyHeaders = $headers; return $this; }
[ "public", "function", "proxy", "(", "array", "$", "ips", "=", "[", "]", ",", "array", "$", "headers", "=", "[", "'Forwarded'", ",", "'Forwarded-For'", ",", "'X-Forwarded'", ",", "'X-Forwarded-For'", ",", "'X-Cluster-Client-Ip'", ",", "'Client-Ip'", ",", "]", ")", ":", "self", "{", "$", "this", "->", "proxyIps", "=", "$", "ips", ";", "$", "this", "->", "proxyHeaders", "=", "$", "headers", ";", "return", "$", "this", ";", "}" ]
Configure the proxy.
[ "Configure", "the", "proxy", "." ]
514d62f13839a045db095b03c25faeeaf0509c9c
https://github.com/middlewares/client-ip/blob/514d62f13839a045db095b03c25faeeaf0509c9c/src/ClientIp.php#L36-L51
train
middlewares/client-ip
src/ClientIp.php
ClientIp.isInProxiedIps
private function isInProxiedIps(string $ip): bool { foreach ($this->proxyIps as $proxyIp) { if ($ip === $proxyIp || self::isInCIDR($ip, $proxyIp)) { return true; } } return false; }
php
private function isInProxiedIps(string $ip): bool { foreach ($this->proxyIps as $proxyIp) { if ($ip === $proxyIp || self::isInCIDR($ip, $proxyIp)) { return true; } } return false; }
[ "private", "function", "isInProxiedIps", "(", "string", "$", "ip", ")", ":", "bool", "{", "foreach", "(", "$", "this", "->", "proxyIps", "as", "$", "proxyIp", ")", "{", "if", "(", "$", "ip", "===", "$", "proxyIp", "||", "self", "::", "isInCIDR", "(", "$", "ip", ",", "$", "proxyIp", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
checks if the given ip address is in the list of proxied ips provided @param string $ip @return bool
[ "checks", "if", "the", "given", "ip", "address", "is", "in", "the", "list", "of", "proxied", "ips", "provided" ]
514d62f13839a045db095b03c25faeeaf0509c9c
https://github.com/middlewares/client-ip/blob/514d62f13839a045db095b03c25faeeaf0509c9c/src/ClientIp.php#L122-L130
train
middlewares/client-ip
src/ClientIp.php
ClientIp.getRemoteIp
private function getRemoteIp() { if ($this->remote) { $ip = file_get_contents('http://ipecho.net/plain'); if ($ip && self::isValid($ip)) { return $ip; } } }
php
private function getRemoteIp() { if ($this->remote) { $ip = file_get_contents('http://ipecho.net/plain'); if ($ip && self::isValid($ip)) { return $ip; } } }
[ "private", "function", "getRemoteIp", "(", ")", "{", "if", "(", "$", "this", "->", "remote", ")", "{", "$", "ip", "=", "file_get_contents", "(", "'http://ipecho.net/plain'", ")", ";", "if", "(", "$", "ip", "&&", "self", "::", "isValid", "(", "$", "ip", ")", ")", "{", "return", "$", "ip", ";", "}", "}", "}" ]
Returns the IP address from remote service. @return string|null
[ "Returns", "the", "IP", "address", "from", "remote", "service", "." ]
514d62f13839a045db095b03c25faeeaf0509c9c
https://github.com/middlewares/client-ip/blob/514d62f13839a045db095b03c25faeeaf0509c9c/src/ClientIp.php#L151-L160
train
middlewares/client-ip
src/ClientIp.php
ClientIp.getForwardedHeaderIp
private function getForwardedHeaderIp(string $header) { foreach (array_reverse(array_map('trim', explode(',', strtolower($header)))) as $values) { foreach (array_reverse(array_map('trim', explode(';', $values))) as $directive) { if (strpos($directive, 'for=') !== 0) { continue; } $ip = trim(substr($directive, 4)); if (self::isValid($ip) && !$this->isInProxiedIps($ip)) { return $ip; } } } }
php
private function getForwardedHeaderIp(string $header) { foreach (array_reverse(array_map('trim', explode(',', strtolower($header)))) as $values) { foreach (array_reverse(array_map('trim', explode(';', $values))) as $directive) { if (strpos($directive, 'for=') !== 0) { continue; } $ip = trim(substr($directive, 4)); if (self::isValid($ip) && !$this->isInProxiedIps($ip)) { return $ip; } } } }
[ "private", "function", "getForwardedHeaderIp", "(", "string", "$", "header", ")", "{", "foreach", "(", "array_reverse", "(", "array_map", "(", "'trim'", ",", "explode", "(", "','", ",", "strtolower", "(", "$", "header", ")", ")", ")", ")", "as", "$", "values", ")", "{", "foreach", "(", "array_reverse", "(", "array_map", "(", "'trim'", ",", "explode", "(", "';'", ",", "$", "values", ")", ")", ")", "as", "$", "directive", ")", "{", "if", "(", "strpos", "(", "$", "directive", ",", "'for='", ")", "!==", "0", ")", "{", "continue", ";", "}", "$", "ip", "=", "trim", "(", "substr", "(", "$", "directive", ",", "4", ")", ")", ";", "if", "(", "self", "::", "isValid", "(", "$", "ip", ")", "&&", "!", "$", "this", "->", "isInProxiedIps", "(", "$", "ip", ")", ")", "{", "return", "$", "ip", ";", "}", "}", "}", "}" ]
Returns the first valid ip found in the Forwarded or X-Forwarded header. @return string|null
[ "Returns", "the", "first", "valid", "ip", "found", "in", "the", "Forwarded", "or", "X", "-", "Forwarded", "header", "." ]
514d62f13839a045db095b03c25faeeaf0509c9c
https://github.com/middlewares/client-ip/blob/514d62f13839a045db095b03c25faeeaf0509c9c/src/ClientIp.php#L204-L219
train
dereuromark/cakephp-setup
src/Shell/ClearShell.php
ClearShell.startup
public function startup() { parent::startup(); if (!empty($this->params['dry-run'])) { $this->out('<warning>Dry-run mode enabled!</warning>', 1, Shell::QUIET); } }
php
public function startup() { parent::startup(); if (!empty($this->params['dry-run'])) { $this->out('<warning>Dry-run mode enabled!</warning>', 1, Shell::QUIET); } }
[ "public", "function", "startup", "(", ")", "{", "parent", "::", "startup", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "params", "[", "'dry-run'", "]", ")", ")", "{", "$", "this", "->", "out", "(", "'<warning>Dry-run mode enabled!</warning>'", ",", "1", ",", "Shell", "::", "QUIET", ")", ";", "}", "}" ]
Shell startup, prints info message about dry run. @return void
[ "Shell", "startup", "prints", "info", "message", "about", "dry", "run", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/ClearShell.php#L24-L29
train
dereuromark/cakephp-setup
src/Shell/ClearShell.php
ClearShell.emptyFolders
public function emptyFolders($path = null) { if ($path) { $path = realpath($path); } if (!$path) { $path = ROOT . DS; } $this->out('Clearing empty folders in ' . $path); $this->_clearEmpty($path); }
php
public function emptyFolders($path = null) { if ($path) { $path = realpath($path); } if (!$path) { $path = ROOT . DS; } $this->out('Clearing empty folders in ' . $path); $this->_clearEmpty($path); }
[ "public", "function", "emptyFolders", "(", "$", "path", "=", "null", ")", "{", "if", "(", "$", "path", ")", "{", "$", "path", "=", "realpath", "(", "$", "path", ")", ";", "}", "if", "(", "!", "$", "path", ")", "{", "$", "path", "=", "ROOT", ".", "DS", ";", "}", "$", "this", "->", "out", "(", "'Clearing empty folders in '", ".", "$", "path", ")", ";", "$", "this", "->", "_clearEmpty", "(", "$", "path", ")", ";", "}" ]
Clean out empty folders that only contain an "empty" placeholder file. @param string|null $path @return void
[ "Clean", "out", "empty", "folders", "that", "only", "contain", "an", "empty", "placeholder", "file", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/ClearShell.php#L47-L58
train
dereuromark/cakephp-tags
src/Model/Behavior/TagBehavior.php
TagBehavior.beforeMarshal
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) { $field = $this->getConfig('field'); $property = $this->getConfig('tagsAssoc.propertyName'); $options['accessibleFields'][$property] = true; if (isset($data[$field])) { $data[$property] = $this->normalizeTags($data[$field]); } elseif ($field !== $property) { if (isset($data[$property]) && !is_array($data[$property])) { throw new RuntimeException('Your `' . $property . '` property is malformed (expected array instead of string). You configured to save list of tags in `' . $field . '` field.'); } } if (isset($data[$field]) && empty($data[$field])) { unset($data[$field]); } }
php
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) { $field = $this->getConfig('field'); $property = $this->getConfig('tagsAssoc.propertyName'); $options['accessibleFields'][$property] = true; if (isset($data[$field])) { $data[$property] = $this->normalizeTags($data[$field]); } elseif ($field !== $property) { if (isset($data[$property]) && !is_array($data[$property])) { throw new RuntimeException('Your `' . $property . '` property is malformed (expected array instead of string). You configured to save list of tags in `' . $field . '` field.'); } } if (isset($data[$field]) && empty($data[$field])) { unset($data[$field]); } }
[ "public", "function", "beforeMarshal", "(", "Event", "$", "event", ",", "ArrayObject", "$", "data", ",", "ArrayObject", "$", "options", ")", "{", "$", "field", "=", "$", "this", "->", "getConfig", "(", "'field'", ")", ";", "$", "property", "=", "$", "this", "->", "getConfig", "(", "'tagsAssoc.propertyName'", ")", ";", "$", "options", "[", "'accessibleFields'", "]", "[", "$", "property", "]", "=", "true", ";", "if", "(", "isset", "(", "$", "data", "[", "$", "field", "]", ")", ")", "{", "$", "data", "[", "$", "property", "]", "=", "$", "this", "->", "normalizeTags", "(", "$", "data", "[", "$", "field", "]", ")", ";", "}", "elseif", "(", "$", "field", "!==", "$", "property", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "property", "]", ")", "&&", "!", "is_array", "(", "$", "data", "[", "$", "property", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Your `'", ".", "$", "property", ".", "'` property is malformed (expected array instead of string). You configured to save list of tags in `'", ".", "$", "field", ".", "'` field.'", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "data", "[", "$", "field", "]", ")", "&&", "empty", "(", "$", "data", "[", "$", "field", "]", ")", ")", "{", "unset", "(", "$", "data", "[", "$", "field", "]", ")", ";", "}", "}" ]
Before marshal callback @param \Cake\Event\Event $event The Model.beforeMarshal event. @param \ArrayObject $data Data. @param \ArrayObject $options Options. @return void @throws \RuntimeException
[ "Before", "marshal", "callback" ]
22f4502bffa0254e90d40507c5e6b84abcb800af
https://github.com/dereuromark/cakephp-tags/blob/22f4502bffa0254e90d40507c5e6b84abcb800af/src/Model/Behavior/TagBehavior.php#L104-L120
train
dereuromark/cakephp-tags
src/Model/Behavior/TagBehavior.php
TagBehavior._tagExists
protected function _tagExists($tag) { $tagsTable = $this->_table->{$this->getConfig('tagsAlias')}->getTarget(); $result = $tagsTable->find() ->where([ $tagsTable->aliasField('slug') => $tag, ]) ->select([ $tagsTable->aliasField($tagsTable->getPrimaryKey()) ]) ->first(); if (!empty($result)) { return $result->id; } return null; }
php
protected function _tagExists($tag) { $tagsTable = $this->_table->{$this->getConfig('tagsAlias')}->getTarget(); $result = $tagsTable->find() ->where([ $tagsTable->aliasField('slug') => $tag, ]) ->select([ $tagsTable->aliasField($tagsTable->getPrimaryKey()) ]) ->first(); if (!empty($result)) { return $result->id; } return null; }
[ "protected", "function", "_tagExists", "(", "$", "tag", ")", "{", "$", "tagsTable", "=", "$", "this", "->", "_table", "->", "{", "$", "this", "->", "getConfig", "(", "'tagsAlias'", ")", "}", "->", "getTarget", "(", ")", ";", "$", "result", "=", "$", "tagsTable", "->", "find", "(", ")", "->", "where", "(", "[", "$", "tagsTable", "->", "aliasField", "(", "'slug'", ")", "=>", "$", "tag", ",", "]", ")", "->", "select", "(", "[", "$", "tagsTable", "->", "aliasField", "(", "$", "tagsTable", "->", "getPrimaryKey", "(", ")", ")", "]", ")", "->", "first", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "result", ")", ")", "{", "return", "$", "result", "->", "id", ";", "}", "return", "null", ";", "}" ]
Checks if a tag already exists and returns the id if yes. @param string $tag Tag key. @return null|int
[ "Checks", "if", "a", "tag", "already", "exists", "and", "returns", "the", "id", "if", "yes", "." ]
22f4502bffa0254e90d40507c5e6b84abcb800af
https://github.com/dereuromark/cakephp-tags/blob/22f4502bffa0254e90d40507c5e6b84abcb800af/src/Model/Behavior/TagBehavior.php#L423-L437
train
dereuromark/cakephp-tags
src/Model/Behavior/TagBehavior.php
TagBehavior._normalizeTag
protected function _normalizeTag($tag) { $namespace = null; $label = $tag; $separator = $this->getConfig('separator'); if ($separator === null) { return [ null, $tag, ]; } if (strpos($tag, $separator) !== false) { list($namespace, $label) = explode($separator, $tag); } return [ trim($namespace), trim($label) ]; }
php
protected function _normalizeTag($tag) { $namespace = null; $label = $tag; $separator = $this->getConfig('separator'); if ($separator === null) { return [ null, $tag, ]; } if (strpos($tag, $separator) !== false) { list($namespace, $label) = explode($separator, $tag); } return [ trim($namespace), trim($label) ]; }
[ "protected", "function", "_normalizeTag", "(", "$", "tag", ")", "{", "$", "namespace", "=", "null", ";", "$", "label", "=", "$", "tag", ";", "$", "separator", "=", "$", "this", "->", "getConfig", "(", "'separator'", ")", ";", "if", "(", "$", "separator", "===", "null", ")", "{", "return", "[", "null", ",", "$", "tag", ",", "]", ";", "}", "if", "(", "strpos", "(", "$", "tag", ",", "$", "separator", ")", "!==", "false", ")", "{", "list", "(", "$", "namespace", ",", "$", "label", ")", "=", "explode", "(", "$", "separator", ",", "$", "tag", ")", ";", "}", "return", "[", "trim", "(", "$", "namespace", ")", ",", "trim", "(", "$", "label", ")", "]", ";", "}" ]
Normalizes a tag string by trimming unnecessary whitespace and extracting the tag identifier from a tag in case it exists. @param string $tag Tag. @return array The tag's ID and label.
[ "Normalizes", "a", "tag", "string", "by", "trimming", "unnecessary", "whitespace", "and", "extracting", "the", "tag", "identifier", "from", "a", "tag", "in", "case", "it", "exists", "." ]
22f4502bffa0254e90d40507c5e6b84abcb800af
https://github.com/dereuromark/cakephp-tags/blob/22f4502bffa0254e90d40507c5e6b84abcb800af/src/Model/Behavior/TagBehavior.php#L446-L465
train
dereuromark/cakephp-setup
src/Shell/SuperfluousWhitespaceShell.php
SuperfluousWhitespaceShell.eof
public function eof() { if (!empty($this->args[0])) { $folder = realpath($this->args[0]); } else { $folder = APP; } $App = new Folder($folder); $this->out('Checking *.php in ' . $folder); $files = $App->findRecursive('.*\.php'); $this->out('Found ' . count($files) . ' files.'); $action = $this->in('Continue? [y]/[n]', ['y', 'n'], 'n'); if ($action !== 'y') { $this->abort('Aborted'); } foreach ($files as $file) { $this->out('Processing ' . $file, 1, Shell::VERBOSE); $content = $store = file_get_contents($file); $content = trim($content); $ext = pathinfo($file, PATHINFO_EXTENSION); if ($ext === 'php' && substr($content, -2, 2) === '?>') { $content = substr($content, 0, -2); } $x = substr_count($content, "\r\n"); if ($x > 0) { $newline = "\r\n"; } else { $newline = "\n"; } // add one new line at the end $content = trim($content) . $newline; if ($content !== $store) { file_put_contents($file, $content); } } $this->out('Done'); }
php
public function eof() { if (!empty($this->args[0])) { $folder = realpath($this->args[0]); } else { $folder = APP; } $App = new Folder($folder); $this->out('Checking *.php in ' . $folder); $files = $App->findRecursive('.*\.php'); $this->out('Found ' . count($files) . ' files.'); $action = $this->in('Continue? [y]/[n]', ['y', 'n'], 'n'); if ($action !== 'y') { $this->abort('Aborted'); } foreach ($files as $file) { $this->out('Processing ' . $file, 1, Shell::VERBOSE); $content = $store = file_get_contents($file); $content = trim($content); $ext = pathinfo($file, PATHINFO_EXTENSION); if ($ext === 'php' && substr($content, -2, 2) === '?>') { $content = substr($content, 0, -2); } $x = substr_count($content, "\r\n"); if ($x > 0) { $newline = "\r\n"; } else { $newline = "\n"; } // add one new line at the end $content = trim($content) . $newline; if ($content !== $store) { file_put_contents($file, $content); } } $this->out('Done'); }
[ "public", "function", "eof", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "args", "[", "0", "]", ")", ")", "{", "$", "folder", "=", "realpath", "(", "$", "this", "->", "args", "[", "0", "]", ")", ";", "}", "else", "{", "$", "folder", "=", "APP", ";", "}", "$", "App", "=", "new", "Folder", "(", "$", "folder", ")", ";", "$", "this", "->", "out", "(", "'Checking *.php in '", ".", "$", "folder", ")", ";", "$", "files", "=", "$", "App", "->", "findRecursive", "(", "'.*\\.php'", ")", ";", "$", "this", "->", "out", "(", "'Found '", ".", "count", "(", "$", "files", ")", ".", "' files.'", ")", ";", "$", "action", "=", "$", "this", "->", "in", "(", "'Continue? [y]/[n]'", ",", "[", "'y'", ",", "'n'", "]", ",", "'n'", ")", ";", "if", "(", "$", "action", "!==", "'y'", ")", "{", "$", "this", "->", "abort", "(", "'Aborted'", ")", ";", "}", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "this", "->", "out", "(", "'Processing '", ".", "$", "file", ",", "1", ",", "Shell", "::", "VERBOSE", ")", ";", "$", "content", "=", "$", "store", "=", "file_get_contents", "(", "$", "file", ")", ";", "$", "content", "=", "trim", "(", "$", "content", ")", ";", "$", "ext", "=", "pathinfo", "(", "$", "file", ",", "PATHINFO_EXTENSION", ")", ";", "if", "(", "$", "ext", "===", "'php'", "&&", "substr", "(", "$", "content", ",", "-", "2", ",", "2", ")", "===", "'?>'", ")", "{", "$", "content", "=", "substr", "(", "$", "content", ",", "0", ",", "-", "2", ")", ";", "}", "$", "x", "=", "substr_count", "(", "$", "content", ",", "\"\\r\\n\"", ")", ";", "if", "(", "$", "x", ">", "0", ")", "{", "$", "newline", "=", "\"\\r\\n\"", ";", "}", "else", "{", "$", "newline", "=", "\"\\n\"", ";", "}", "// add one new line at the end", "$", "content", "=", "trim", "(", "$", "content", ")", ".", "$", "newline", ";", "if", "(", "$", "content", "!==", "$", "store", ")", "{", "file_put_contents", "(", "$", "file", ",", "$", "content", ")", ";", "}", "}", "$", "this", "->", "out", "(", "'Done'", ")", ";", "}" ]
Whitespaces at the end of the file If PHP file with trailing ?> that will be removed as per coding standards. @return void
[ "Whitespaces", "at", "the", "end", "of", "the", "file", "If", "PHP", "file", "with", "trailing", "?", ">", "that", "will", "be", "removed", "as", "per", "coding", "standards", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/SuperfluousWhitespaceShell.php#L126-L167
train
dereuromark/cakephp-setup
src/Utility/Setup.php
Setup.cleanedUrl
public static function cleanedUrl($type, $urlArray) { $types = (array)$type; foreach ($types as $type) { if (isset($urlArray['?'][$type])) { unset($urlArray['?'][$type]); } } $pass = !empty($urlArray['pass']) ? $urlArray['pass'] : []; $returnArray = []; if (isset($urlArray['controller'])) { $returnArray['controller'] = $urlArray['controller']; } if (isset($urlArray['action'])) { $returnArray['action'] = $urlArray['action']; } if (isset($urlArray['plugin'])) { $returnArray['plugin'] = $urlArray['plugin']; } if (isset($urlArray['prefix'])) { $returnArray['prefix'] = $urlArray['prefix']; } foreach ($pass as $val) { $returnArray[] = $val; } $returnArray['?'] = $urlArray['?']; return $returnArray; }
php
public static function cleanedUrl($type, $urlArray) { $types = (array)$type; foreach ($types as $type) { if (isset($urlArray['?'][$type])) { unset($urlArray['?'][$type]); } } $pass = !empty($urlArray['pass']) ? $urlArray['pass'] : []; $returnArray = []; if (isset($urlArray['controller'])) { $returnArray['controller'] = $urlArray['controller']; } if (isset($urlArray['action'])) { $returnArray['action'] = $urlArray['action']; } if (isset($urlArray['plugin'])) { $returnArray['plugin'] = $urlArray['plugin']; } if (isset($urlArray['prefix'])) { $returnArray['prefix'] = $urlArray['prefix']; } foreach ($pass as $val) { $returnArray[] = $val; } $returnArray['?'] = $urlArray['?']; return $returnArray; }
[ "public", "static", "function", "cleanedUrl", "(", "$", "type", ",", "$", "urlArray", ")", "{", "$", "types", "=", "(", "array", ")", "$", "type", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "urlArray", "[", "'?'", "]", "[", "$", "type", "]", ")", ")", "{", "unset", "(", "$", "urlArray", "[", "'?'", "]", "[", "$", "type", "]", ")", ";", "}", "}", "$", "pass", "=", "!", "empty", "(", "$", "urlArray", "[", "'pass'", "]", ")", "?", "$", "urlArray", "[", "'pass'", "]", ":", "[", "]", ";", "$", "returnArray", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "urlArray", "[", "'controller'", "]", ")", ")", "{", "$", "returnArray", "[", "'controller'", "]", "=", "$", "urlArray", "[", "'controller'", "]", ";", "}", "if", "(", "isset", "(", "$", "urlArray", "[", "'action'", "]", ")", ")", "{", "$", "returnArray", "[", "'action'", "]", "=", "$", "urlArray", "[", "'action'", "]", ";", "}", "if", "(", "isset", "(", "$", "urlArray", "[", "'plugin'", "]", ")", ")", "{", "$", "returnArray", "[", "'plugin'", "]", "=", "$", "urlArray", "[", "'plugin'", "]", ";", "}", "if", "(", "isset", "(", "$", "urlArray", "[", "'prefix'", "]", ")", ")", "{", "$", "returnArray", "[", "'prefix'", "]", "=", "$", "urlArray", "[", "'prefix'", "]", ";", "}", "foreach", "(", "$", "pass", "as", "$", "val", ")", "{", "$", "returnArray", "[", "]", "=", "$", "val", ";", "}", "$", "returnArray", "[", "'?'", "]", "=", "$", "urlArray", "[", "'?'", "]", ";", "return", "$", "returnArray", ";", "}" ]
Removes specific query strings from parsed URL array. @param string $type Type to remove @param array $urlArray Array containing the current URL @return array Cleaned URL array
[ "Removes", "specific", "query", "strings", "from", "parsed", "URL", "array", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Utility/Setup.php#L17-L47
train
dereuromark/cakephp-tags
src/Model/Table/TaggedTable.php
TaggedTable.findCloud
public function findCloud(Query $query) { $groupBy = ['Tagged.tag_id', 'Tags.id', 'Tags.slug', 'Tags.label']; $fields = $groupBy; $fields['counter'] = $query->func()->count('*'); // FIXME or remove // Support old code without the counter cache // This is related to https://github.com/CakeDC/tags/issues/10 to work around a limitation of postgres /* $field = $this->getDataSource()->fields($this->Tag); $field = array_merge($field, $this->getDataSource()->fields($this, null, 'Tagged.tag_id')); $fields = 'DISTINCT ' . implode(',', $field); $groupBy = null; */ $options = [ 'minSize' => 10, 'maxSize' => 20, //'page' => '', //'limit' => '', //'order' => '', //'joins' => array(), //'offset' => '', 'contain' => 'Tags', //'conditions' => array(), 'fields' => $fields, 'group' => $groupBy ]; $query->formatResults(function (CollectionInterface $results) { $results = static::calculateWeights($results->toArray()); return $results; }); return $query->find('all', $options); }
php
public function findCloud(Query $query) { $groupBy = ['Tagged.tag_id', 'Tags.id', 'Tags.slug', 'Tags.label']; $fields = $groupBy; $fields['counter'] = $query->func()->count('*'); // FIXME or remove // Support old code without the counter cache // This is related to https://github.com/CakeDC/tags/issues/10 to work around a limitation of postgres /* $field = $this->getDataSource()->fields($this->Tag); $field = array_merge($field, $this->getDataSource()->fields($this, null, 'Tagged.tag_id')); $fields = 'DISTINCT ' . implode(',', $field); $groupBy = null; */ $options = [ 'minSize' => 10, 'maxSize' => 20, //'page' => '', //'limit' => '', //'order' => '', //'joins' => array(), //'offset' => '', 'contain' => 'Tags', //'conditions' => array(), 'fields' => $fields, 'group' => $groupBy ]; $query->formatResults(function (CollectionInterface $results) { $results = static::calculateWeights($results->toArray()); return $results; }); return $query->find('all', $options); }
[ "public", "function", "findCloud", "(", "Query", "$", "query", ")", "{", "$", "groupBy", "=", "[", "'Tagged.tag_id'", ",", "'Tags.id'", ",", "'Tags.slug'", ",", "'Tags.label'", "]", ";", "$", "fields", "=", "$", "groupBy", ";", "$", "fields", "[", "'counter'", "]", "=", "$", "query", "->", "func", "(", ")", "->", "count", "(", "'*'", ")", ";", "// FIXME or remove", "// Support old code without the counter cache", "// This is related to https://github.com/CakeDC/tags/issues/10 to work around a limitation of postgres", "/*\n\t\t$field = $this->getDataSource()->fields($this->Tag);\n\t\t$field = array_merge($field, $this->getDataSource()->fields($this, null, 'Tagged.tag_id'));\n\t\t$fields = 'DISTINCT ' . implode(',', $field);\n\t\t$groupBy = null;\n\t\t*/", "$", "options", "=", "[", "'minSize'", "=>", "10", ",", "'maxSize'", "=>", "20", ",", "//'page' => '',", "//'limit' => '',", "//'order' => '',", "//'joins' => array(),", "//'offset' => '',", "'contain'", "=>", "'Tags'", ",", "//'conditions' => array(),", "'fields'", "=>", "$", "fields", ",", "'group'", "=>", "$", "groupBy", "]", ";", "$", "query", "->", "formatResults", "(", "function", "(", "CollectionInterface", "$", "results", ")", "{", "$", "results", "=", "static", "::", "calculateWeights", "(", "$", "results", "->", "toArray", "(", ")", ")", ";", "return", "$", "results", ";", "}", ")", ";", "return", "$", "query", "->", "find", "(", "'all'", ",", "$", "options", ")", ";", "}" ]
Returns a tag cloud The result contains a "weight" field which has a normalized size of the tag counter set. The min and max size can be set by passing 'minSize" and 'maxSize' to the query. This value can be used in the view to control the size of the tag font. @param \Cake\ORM\Query $query Query array. @return \Cake\ORM\Query
[ "Returns", "a", "tag", "cloud" ]
22f4502bffa0254e90d40507c5e6b84abcb800af
https://github.com/dereuromark/cakephp-tags/blob/22f4502bffa0254e90d40507c5e6b84abcb800af/src/Model/Table/TaggedTable.php#L53-L89
train
dereuromark/cakephp-tags
src/Model/Table/TaggedTable.php
TaggedTable.beforeFind
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) { $order = $query->clause('order'); if ($order !== null) { return $query; } if (!isset($this->order)) { $contain = $query->getContain(); if (!isset($contain[$this->Tags->getAlias()])) { return $query; } $order = [$this->Tags->getAlias() . '.label' => 'ASC']; } else { $order = $this->order; } if (!empty($order)) { $query->order($order); } return $query; }
php
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) { $order = $query->clause('order'); if ($order !== null) { return $query; } if (!isset($this->order)) { $contain = $query->getContain(); if (!isset($contain[$this->Tags->getAlias()])) { return $query; } $order = [$this->Tags->getAlias() . '.label' => 'ASC']; } else { $order = $this->order; } if (!empty($order)) { $query->order($order); } return $query; }
[ "public", "function", "beforeFind", "(", "Event", "$", "event", ",", "Query", "$", "query", ",", "ArrayObject", "$", "options", ",", "$", "primary", ")", "{", "$", "order", "=", "$", "query", "->", "clause", "(", "'order'", ")", ";", "if", "(", "$", "order", "!==", "null", ")", "{", "return", "$", "query", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "order", ")", ")", "{", "$", "contain", "=", "$", "query", "->", "getContain", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "contain", "[", "$", "this", "->", "Tags", "->", "getAlias", "(", ")", "]", ")", ")", "{", "return", "$", "query", ";", "}", "$", "order", "=", "[", "$", "this", "->", "Tags", "->", "getAlias", "(", ")", ".", "'.label'", "=>", "'ASC'", "]", ";", "}", "else", "{", "$", "order", "=", "$", "this", "->", "order", ";", "}", "if", "(", "!", "empty", "(", "$", "order", ")", ")", "{", "$", "query", "->", "order", "(", "$", "order", ")", ";", "}", "return", "$", "query", ";", "}" ]
Sets the default ordering. If you don't want that, don't call parent when overwriting it in extending classes or just set the order to an empty array. This will only trigger for order clause of null. @param \Cake\Event\Event $event @param \Cake\ORM\Query $query @param \ArrayObject $options @param bool $primary @return \Cake\ORM\Query
[ "Sets", "the", "default", "ordering", "." ]
22f4502bffa0254e90d40507c5e6b84abcb800af
https://github.com/dereuromark/cakephp-tags/blob/22f4502bffa0254e90d40507c5e6b84abcb800af/src/Model/Table/TaggedTable.php#L135-L157
train
dereuromark/cakephp-setup
src/Maintenance/Maintenance.php
Maintenance.checkMaintenance
public function checkMaintenance($ipAddress = null, $exit = true) { if ($ipAddress === null) { $ipAddress = env('REMOTE_ADDRESS'); } if (!$this->isMaintenanceMode($ipAddress)) { return; } $Response = new Response(); $Response->statusCode(503); $Response->header('Retry-After', DAY); $body = __d('setup', 'Maintenance work'); $template = APP . 'Template' . DS . 'Error' . DS . $this->template; if (file_exists($template)) { $body = file_get_contents($template); } $Response->body($body); if ($exit) { $Response->send(); exit; } }
php
public function checkMaintenance($ipAddress = null, $exit = true) { if ($ipAddress === null) { $ipAddress = env('REMOTE_ADDRESS'); } if (!$this->isMaintenanceMode($ipAddress)) { return; } $Response = new Response(); $Response->statusCode(503); $Response->header('Retry-After', DAY); $body = __d('setup', 'Maintenance work'); $template = APP . 'Template' . DS . 'Error' . DS . $this->template; if (file_exists($template)) { $body = file_get_contents($template); } $Response->body($body); if ($exit) { $Response->send(); exit; } }
[ "public", "function", "checkMaintenance", "(", "$", "ipAddress", "=", "null", ",", "$", "exit", "=", "true", ")", "{", "if", "(", "$", "ipAddress", "===", "null", ")", "{", "$", "ipAddress", "=", "env", "(", "'REMOTE_ADDRESS'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "isMaintenanceMode", "(", "$", "ipAddress", ")", ")", "{", "return", ";", "}", "$", "Response", "=", "new", "Response", "(", ")", ";", "$", "Response", "->", "statusCode", "(", "503", ")", ";", "$", "Response", "->", "header", "(", "'Retry-After'", ",", "DAY", ")", ";", "$", "body", "=", "__d", "(", "'setup'", ",", "'Maintenance work'", ")", ";", "$", "template", "=", "APP", ".", "'Template'", ".", "DS", ".", "'Error'", ".", "DS", ".", "$", "this", "->", "template", ";", "if", "(", "file_exists", "(", "$", "template", ")", ")", "{", "$", "body", "=", "file_get_contents", "(", "$", "template", ")", ";", "}", "$", "Response", "->", "body", "(", "$", "body", ")", ";", "if", "(", "$", "exit", ")", "{", "$", "Response", "->", "send", "(", ")", ";", "exit", ";", "}", "}" ]
Main functionality to trigger maintenance mode. Will automatically set the appropriate headers. Tip: Check for non CLI first if (php_sapi_name() !== 'cli') { App::uses('MaintenanceLib', 'Setup.Lib'); $Maintenance = new MaintenanceLib(); $Maintenance->checkMaintenance(); } @param string|null $ipAddress @param bool $exit If Response should be sent and exited. @return void @deprecated Use Maintenance DispatcherFilter
[ "Main", "functionality", "to", "trigger", "maintenance", "mode", ".", "Will", "automatically", "set", "the", "appropriate", "headers", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Maintenance/Maintenance.php#L46-L67
train
dereuromark/cakephp-setup
src/Maintenance/Maintenance.php
Maintenance.isMaintenanceMode
public function isMaintenanceMode($ipAddress = null) { if ($ipAddress) { $this->enableDebugModeForWhitelist($ipAddress); } if (!file_exists($this->file)) { return false; } $content = file_get_contents($this->file); if ($content === false) { return false; } if ($content > 0 && $content < time()) { $this->setMaintenanceMode(false); return false; } if ($ipAddress) { $file = TMP . 'maintenanceOverride-' . $this->_slugIp($ipAddress) . '.txt'; if (file_exists($file)) { Configure::write('Maintenance.overwrite', $ipAddress); return false; } } return true; }
php
public function isMaintenanceMode($ipAddress = null) { if ($ipAddress) { $this->enableDebugModeForWhitelist($ipAddress); } if (!file_exists($this->file)) { return false; } $content = file_get_contents($this->file); if ($content === false) { return false; } if ($content > 0 && $content < time()) { $this->setMaintenanceMode(false); return false; } if ($ipAddress) { $file = TMP . 'maintenanceOverride-' . $this->_slugIp($ipAddress) . '.txt'; if (file_exists($file)) { Configure::write('Maintenance.overwrite', $ipAddress); return false; } } return true; }
[ "public", "function", "isMaintenanceMode", "(", "$", "ipAddress", "=", "null", ")", "{", "if", "(", "$", "ipAddress", ")", "{", "$", "this", "->", "enableDebugModeForWhitelist", "(", "$", "ipAddress", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "this", "->", "file", ")", ")", "{", "return", "false", ";", "}", "$", "content", "=", "file_get_contents", "(", "$", "this", "->", "file", ")", ";", "if", "(", "$", "content", "===", "false", ")", "{", "return", "false", ";", "}", "if", "(", "$", "content", ">", "0", "&&", "$", "content", "<", "time", "(", ")", ")", "{", "$", "this", "->", "setMaintenanceMode", "(", "false", ")", ";", "return", "false", ";", "}", "if", "(", "$", "ipAddress", ")", "{", "$", "file", "=", "TMP", ".", "'maintenanceOverride-'", ".", "$", "this", "->", "_slugIp", "(", "$", "ipAddress", ")", ".", "'.txt'", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "Configure", "::", "write", "(", "'Maintenance.overwrite'", ",", "$", "ipAddress", ")", ";", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check if maintenance mode is on. If overwritable, it will set Configure value 'Maintenance.overwrite' with the corresponding IP so the SetupComponent can trigger a warning message here. @param string|null $ipAddress If passed it allows access when it matches whitelisted IPs. @return bool Success
[ "Check", "if", "maintenance", "mode", "is", "on", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Maintenance/Maintenance.php#L78-L105
train
dereuromark/cakephp-setup
src/Maintenance/Maintenance.php
Maintenance.setMaintenanceMode
public function setMaintenanceMode($value) { if ($value === false) { if (!file_exists($this->file)) { return true; } return unlink($this->file); } if ($value) { $value = time() + $value * MINUTE; } return (bool)file_put_contents($this->file, $value); }
php
public function setMaintenanceMode($value) { if ($value === false) { if (!file_exists($this->file)) { return true; } return unlink($this->file); } if ($value) { $value = time() + $value * MINUTE; } return (bool)file_put_contents($this->file, $value); }
[ "public", "function", "setMaintenanceMode", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "false", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "file", ")", ")", "{", "return", "true", ";", "}", "return", "unlink", "(", "$", "this", "->", "file", ")", ";", "}", "if", "(", "$", "value", ")", "{", "$", "value", "=", "time", "(", ")", "+", "$", "value", "*", "MINUTE", ";", "}", "return", "(", "bool", ")", "file_put_contents", "(", "$", "this", "->", "file", ",", "$", "value", ")", ";", "}" ]
Set maintenance mode. Integer (in minutes) to activate with timeout. Using 0 it will have no timeout. @param int|false $value False to deactivate, or Integer to activate. @return bool Success
[ "Set", "maintenance", "mode", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Maintenance/Maintenance.php#L131-L144
train
dereuromark/cakephp-setup
src/Maintenance/Maintenance.php
Maintenance.clearWhitelist
public function clearWhitelist($ips = []) { $files = glob(TMP . 'maintenanceOverride-*.txt'); foreach ($files as $file) { $ip = pathinfo($file, PATHINFO_FILENAME); $ip = substr($ip, strpos($ip, '-') + 1); if (!$ips || in_array($this->_unslugIp($ip), $ips)) { if (!unlink($file)) { return false; } } } return true; }
php
public function clearWhitelist($ips = []) { $files = glob(TMP . 'maintenanceOverride-*.txt'); foreach ($files as $file) { $ip = pathinfo($file, PATHINFO_FILENAME); $ip = substr($ip, strpos($ip, '-') + 1); if (!$ips || in_array($this->_unslugIp($ip), $ips)) { if (!unlink($file)) { return false; } } } return true; }
[ "public", "function", "clearWhitelist", "(", "$", "ips", "=", "[", "]", ")", "{", "$", "files", "=", "glob", "(", "TMP", ".", "'maintenanceOverride-*.txt'", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "ip", "=", "pathinfo", "(", "$", "file", ",", "PATHINFO_FILENAME", ")", ";", "$", "ip", "=", "substr", "(", "$", "ip", ",", "strpos", "(", "$", "ip", ",", "'-'", ")", "+", "1", ")", ";", "if", "(", "!", "$", "ips", "||", "in_array", "(", "$", "this", "->", "_unslugIp", "(", "$", "ip", ")", ",", "$", "ips", ")", ")", "{", "if", "(", "!", "unlink", "(", "$", "file", ")", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Clear whitelist. If IPs are passed, only those will be removed, otherwise all. @param array $ips @return bool Success
[ "Clear", "whitelist", ".", "If", "IPs", "are", "passed", "only", "those", "will", "be", "removed", "otherwise", "all", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Maintenance/Maintenance.php#L178-L190
train
dereuromark/cakephp-setup
src/Controller/Component/SetupComponent.php
SetupComponent.setLayout
public function setLayout($layout) { if (!$layout) { $this->request->getSession()->delete('Setup.layout'); return; } $this->request->getSession()->write('Setup.layout', $layout); }
php
public function setLayout($layout) { if (!$layout) { $this->request->getSession()->delete('Setup.layout'); return; } $this->request->getSession()->write('Setup.layout', $layout); }
[ "public", "function", "setLayout", "(", "$", "layout", ")", "{", "if", "(", "!", "$", "layout", ")", "{", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "delete", "(", "'Setup.layout'", ")", ";", "return", ";", "}", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "write", "(", "'Setup.layout'", ",", "$", "layout", ")", ";", "}" ]
Set layout for this session. @param string $layout @return void
[ "Set", "layout", "for", "this", "session", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Controller/Component/SetupComponent.php#L224-L230
train
dereuromark/cakephp-setup
src/Controller/Component/SetupComponent.php
SetupComponent.setMaintenance
public function setMaintenance($maintenance) { $ip = env('REMOTE_ADDR'); // optional length in minutes $length = (int)$this->Controller->request->getQuery('duration'); $Maintenance = new Maintenance(); if (!$Maintenance->setMaintenanceMode($maintenance ? $length : false)) { return false; } if (!$Maintenance->whitelist([$ip])) { return false; } return true; }
php
public function setMaintenance($maintenance) { $ip = env('REMOTE_ADDR'); // optional length in minutes $length = (int)$this->Controller->request->getQuery('duration'); $Maintenance = new Maintenance(); if (!$Maintenance->setMaintenanceMode($maintenance ? $length : false)) { return false; } if (!$Maintenance->whitelist([$ip])) { return false; } return true; }
[ "public", "function", "setMaintenance", "(", "$", "maintenance", ")", "{", "$", "ip", "=", "env", "(", "'REMOTE_ADDR'", ")", ";", "// optional length in minutes", "$", "length", "=", "(", "int", ")", "$", "this", "->", "Controller", "->", "request", "->", "getQuery", "(", "'duration'", ")", ";", "$", "Maintenance", "=", "new", "Maintenance", "(", ")", ";", "if", "(", "!", "$", "Maintenance", "->", "setMaintenanceMode", "(", "$", "maintenance", "?", "$", "length", ":", "false", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "Maintenance", "->", "whitelist", "(", "[", "$", "ip", "]", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Set maintance mode for everybody except for the own IP which will be whitelisted. Alternatively, this can and should be done using the CLI shell. URL Options: - `duration` query string can be used to set a timeout maintenance window @param mixed $maintenance @return bool Success
[ "Set", "maintance", "mode", "for", "everybody", "except", "for", "the", "own", "IP", "which", "will", "be", "whitelisted", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Controller/Component/SetupComponent.php#L244-L258
train
dereuromark/cakephp-setup
src/Controller/Component/SetupComponent.php
SetupComponent.setDebug
public function setDebug($level, $type = 'session') { $level = (int)$level; if ($type === 'session') { if ($level < 0) { $this->request->getSession()->delete('Setup.debug'); return false; } $this->request->getSession()->write('Setup.debug', $level); return true; } $cookieName = Configure::read('Session.cookie'); if (empty($cookieName)) { $cookieName = 'CAKEPHP'; } $id = null; if ($type === 'session') { $id = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : ''; } elseif ($type === 'ip') { $ip = env('REMOTE_ADDR'); $host = 'unknown'; if (!empty($ip)) { $host = gethostbyaddr($ip); } $id = $ip . '-' . $host; } if ($id === null) { throw new Exception('Invalid type'); } $file = TMP . 'debugOverride-' . $id . '.txt'; if ($level < 0) { if (file_exists($file)) { unlink($file); } return false; } if (!empty($id)) { if (file_put_contents($file, $level)) { return (bool)$level; } } return false; }
php
public function setDebug($level, $type = 'session') { $level = (int)$level; if ($type === 'session') { if ($level < 0) { $this->request->getSession()->delete('Setup.debug'); return false; } $this->request->getSession()->write('Setup.debug', $level); return true; } $cookieName = Configure::read('Session.cookie'); if (empty($cookieName)) { $cookieName = 'CAKEPHP'; } $id = null; if ($type === 'session') { $id = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : ''; } elseif ($type === 'ip') { $ip = env('REMOTE_ADDR'); $host = 'unknown'; if (!empty($ip)) { $host = gethostbyaddr($ip); } $id = $ip . '-' . $host; } if ($id === null) { throw new Exception('Invalid type'); } $file = TMP . 'debugOverride-' . $id . '.txt'; if ($level < 0) { if (file_exists($file)) { unlink($file); } return false; } if (!empty($id)) { if (file_put_contents($file, $level)) { return (bool)$level; } } return false; }
[ "public", "function", "setDebug", "(", "$", "level", ",", "$", "type", "=", "'session'", ")", "{", "$", "level", "=", "(", "int", ")", "$", "level", ";", "if", "(", "$", "type", "===", "'session'", ")", "{", "if", "(", "$", "level", "<", "0", ")", "{", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "delete", "(", "'Setup.debug'", ")", ";", "return", "false", ";", "}", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "write", "(", "'Setup.debug'", ",", "$", "level", ")", ";", "return", "true", ";", "}", "$", "cookieName", "=", "Configure", "::", "read", "(", "'Session.cookie'", ")", ";", "if", "(", "empty", "(", "$", "cookieName", ")", ")", "{", "$", "cookieName", "=", "'CAKEPHP'", ";", "}", "$", "id", "=", "null", ";", "if", "(", "$", "type", "===", "'session'", ")", "{", "$", "id", "=", "isset", "(", "$", "_COOKIE", "[", "$", "cookieName", "]", ")", "?", "$", "_COOKIE", "[", "$", "cookieName", "]", ":", "''", ";", "}", "elseif", "(", "$", "type", "===", "'ip'", ")", "{", "$", "ip", "=", "env", "(", "'REMOTE_ADDR'", ")", ";", "$", "host", "=", "'unknown'", ";", "if", "(", "!", "empty", "(", "$", "ip", ")", ")", "{", "$", "host", "=", "gethostbyaddr", "(", "$", "ip", ")", ";", "}", "$", "id", "=", "$", "ip", ".", "'-'", ".", "$", "host", ";", "}", "if", "(", "$", "id", "===", "null", ")", "{", "throw", "new", "Exception", "(", "'Invalid type'", ")", ";", "}", "$", "file", "=", "TMP", ".", "'debugOverride-'", ".", "$", "id", ".", "'.txt'", ";", "if", "(", "$", "level", "<", "0", ")", "{", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "unlink", "(", "$", "file", ")", ";", "}", "return", "false", ";", "}", "if", "(", "!", "empty", "(", "$", "id", ")", ")", "{", "if", "(", "file_put_contents", "(", "$", "file", ",", "$", "level", ")", ")", "{", "return", "(", "bool", ")", "$", "level", ";", "}", "}", "return", "false", ";", "}" ]
Override debug level 0/1 to set, or -1 to unset. @param int $level Debug level @param string $type Type - session/ip [optional] (defaults to session) @return bool Success
[ "Override", "debug", "level" ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Controller/Component/SetupComponent.php#L269-L317
train
dereuromark/cakephp-setup
src/Controller/Component/SetupComponent.php
SetupComponent.clearCache
public function clearCache($type = null) { $config = $type ?: 'default'; Cache::clear(false, $config); return true; }
php
public function clearCache($type = null) { $config = $type ?: 'default'; Cache::clear(false, $config); return true; }
[ "public", "function", "clearCache", "(", "$", "type", "=", "null", ")", "{", "$", "config", "=", "$", "type", "?", ":", "'default'", ";", "Cache", "::", "clear", "(", "false", ",", "$", "config", ")", ";", "return", "true", ";", "}" ]
Clear cache of tmp folders @param string|null $type @return bool Success
[ "Clear", "cache", "of", "tmp", "folders" ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Controller/Component/SetupComponent.php#L325-L330
train
dereuromark/cakephp-setup
src/Controller/Component/SetupComponent.php
SetupComponent._cleanedUrl
protected function _cleanedUrl($type) { $type = (array)$type; if (Configure::read('Config.productive')) { $type[] = 'pwd'; } return Setup::cleanedUrl($type, $this->Controller->request->getAttribute('params') + ['?' => $this->Controller->request->getQuery()]); }
php
protected function _cleanedUrl($type) { $type = (array)$type; if (Configure::read('Config.productive')) { $type[] = 'pwd'; } return Setup::cleanedUrl($type, $this->Controller->request->getAttribute('params') + ['?' => $this->Controller->request->getQuery()]); }
[ "protected", "function", "_cleanedUrl", "(", "$", "type", ")", "{", "$", "type", "=", "(", "array", ")", "$", "type", ";", "if", "(", "Configure", "::", "read", "(", "'Config.productive'", ")", ")", "{", "$", "type", "[", "]", "=", "'pwd'", ";", "}", "return", "Setup", "::", "cleanedUrl", "(", "$", "type", ",", "$", "this", "->", "Controller", "->", "request", "->", "getAttribute", "(", "'params'", ")", "+", "[", "'?'", "=>", "$", "this", "->", "Controller", "->", "request", "->", "getQuery", "(", ")", "]", ")", ";", "}" ]
Remove specific named param from parsed url array @param string|array $type @return array URL
[ "Remove", "specific", "named", "param", "from", "parsed", "url", "array" ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Controller/Component/SetupComponent.php#L348-L355
train
dereuromark/cakephp-setup
src/Shell/IndentShell.php
IndentShell.folder
public function folder() { if (!empty($this->params['extensions'])) { $this->settings['files'] = Text::tokenize($this->params['extensions']); } if (!empty($this->params['again'])) { $this->settings['againWithHalf'] = true; } $folder = null; if (!empty($this->args)) { if (!empty($this->args[0]) && $this->args[0] !== 'app') { $folder = $this->args[0]; if ($folder === '/') { $folder = APP; } $folder = realpath($folder); if (!file_exists($folder)) { $this->abort('folder not exists: ' . $folder . ''); } $this->_paths[] = $folder; } elseif ($this->args[0] === 'app') { $this->_paths[] = APP; } if (!empty($this->params['files'])) { $this->settings['files'] = explode(',', $this->params['files']); } $this->out($folder); $this->out('searching...'); $this->_searchFiles(); $this->out('found: ' . count($this->_files)); if (empty($this->params['dry-run'])) { if (!$this->params['force']) { $continue = $this->in('Modifying files! Continue?', ['y', 'n'], 'n'); if (mb_strtolower($continue) !== 'y' && mb_strtolower($continue) !== 'yes') { $this->abort('...aborted'); } } $this->_correctFiles(); $this->out('DONE'); } } else { $this->out('Usage: cake intend folder'); $this->out('"folder" is then intended recursivly'); $this->out('default file types are'); $this->out('[' . implode(', ', $this->settings['files']) . ']'); $this->out(''); $this->out('Specify file types manually:'); $this->out('-files php,js,css'); } }
php
public function folder() { if (!empty($this->params['extensions'])) { $this->settings['files'] = Text::tokenize($this->params['extensions']); } if (!empty($this->params['again'])) { $this->settings['againWithHalf'] = true; } $folder = null; if (!empty($this->args)) { if (!empty($this->args[0]) && $this->args[0] !== 'app') { $folder = $this->args[0]; if ($folder === '/') { $folder = APP; } $folder = realpath($folder); if (!file_exists($folder)) { $this->abort('folder not exists: ' . $folder . ''); } $this->_paths[] = $folder; } elseif ($this->args[0] === 'app') { $this->_paths[] = APP; } if (!empty($this->params['files'])) { $this->settings['files'] = explode(',', $this->params['files']); } $this->out($folder); $this->out('searching...'); $this->_searchFiles(); $this->out('found: ' . count($this->_files)); if (empty($this->params['dry-run'])) { if (!$this->params['force']) { $continue = $this->in('Modifying files! Continue?', ['y', 'n'], 'n'); if (mb_strtolower($continue) !== 'y' && mb_strtolower($continue) !== 'yes') { $this->abort('...aborted'); } } $this->_correctFiles(); $this->out('DONE'); } } else { $this->out('Usage: cake intend folder'); $this->out('"folder" is then intended recursivly'); $this->out('default file types are'); $this->out('[' . implode(', ', $this->settings['files']) . ']'); $this->out(''); $this->out('Specify file types manually:'); $this->out('-files php,js,css'); } }
[ "public", "function", "folder", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "params", "[", "'extensions'", "]", ")", ")", "{", "$", "this", "->", "settings", "[", "'files'", "]", "=", "Text", "::", "tokenize", "(", "$", "this", "->", "params", "[", "'extensions'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "params", "[", "'again'", "]", ")", ")", "{", "$", "this", "->", "settings", "[", "'againWithHalf'", "]", "=", "true", ";", "}", "$", "folder", "=", "null", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "args", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "args", "[", "0", "]", ")", "&&", "$", "this", "->", "args", "[", "0", "]", "!==", "'app'", ")", "{", "$", "folder", "=", "$", "this", "->", "args", "[", "0", "]", ";", "if", "(", "$", "folder", "===", "'/'", ")", "{", "$", "folder", "=", "APP", ";", "}", "$", "folder", "=", "realpath", "(", "$", "folder", ")", ";", "if", "(", "!", "file_exists", "(", "$", "folder", ")", ")", "{", "$", "this", "->", "abort", "(", "'folder not exists: '", ".", "$", "folder", ".", "''", ")", ";", "}", "$", "this", "->", "_paths", "[", "]", "=", "$", "folder", ";", "}", "elseif", "(", "$", "this", "->", "args", "[", "0", "]", "===", "'app'", ")", "{", "$", "this", "->", "_paths", "[", "]", "=", "APP", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "params", "[", "'files'", "]", ")", ")", "{", "$", "this", "->", "settings", "[", "'files'", "]", "=", "explode", "(", "','", ",", "$", "this", "->", "params", "[", "'files'", "]", ")", ";", "}", "$", "this", "->", "out", "(", "$", "folder", ")", ";", "$", "this", "->", "out", "(", "'searching...'", ")", ";", "$", "this", "->", "_searchFiles", "(", ")", ";", "$", "this", "->", "out", "(", "'found: '", ".", "count", "(", "$", "this", "->", "_files", ")", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "params", "[", "'dry-run'", "]", ")", ")", "{", "if", "(", "!", "$", "this", "->", "params", "[", "'force'", "]", ")", "{", "$", "continue", "=", "$", "this", "->", "in", "(", "'Modifying files! Continue?'", ",", "[", "'y'", ",", "'n'", "]", ",", "'n'", ")", ";", "if", "(", "mb_strtolower", "(", "$", "continue", ")", "!==", "'y'", "&&", "mb_strtolower", "(", "$", "continue", ")", "!==", "'yes'", ")", "{", "$", "this", "->", "abort", "(", "'...aborted'", ")", ";", "}", "}", "$", "this", "->", "_correctFiles", "(", ")", ";", "$", "this", "->", "out", "(", "'DONE'", ")", ";", "}", "}", "else", "{", "$", "this", "->", "out", "(", "'Usage: cake intend folder'", ")", ";", "$", "this", "->", "out", "(", "'\"folder\" is then intended recursivly'", ")", ";", "$", "this", "->", "out", "(", "'default file types are'", ")", ";", "$", "this", "->", "out", "(", "'['", ".", "implode", "(", "', '", ",", "$", "this", "->", "settings", "[", "'files'", "]", ")", ".", "']'", ")", ";", "$", "this", "->", "out", "(", "''", ")", ";", "$", "this", "->", "out", "(", "'Specify file types manually:'", ")", ";", "$", "this", "->", "out", "(", "'-files php,js,css'", ")", ";", "}", "}" ]
Main execution function to indent a folder recursivly @return int|null
[ "Main", "execution", "function", "to", "indent", "a", "folder", "recursivly" ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/IndentShell.php#L73-L129
train
dereuromark/cakephp-setup
src/Shell/IndentShell.php
IndentShell._searchFiles
protected function _searchFiles() { foreach ($this->_paths as $path) { $Folder = new Folder($path); $files = $Folder->findRecursive('.*\.(' . implode('|', $this->settings['files']) . ')', true); foreach ($files as $file) { if (strpos($file, DS . 'Vendor' . DS) !== false) { continue; } $this->_files[] = $file; } } }
php
protected function _searchFiles() { foreach ($this->_paths as $path) { $Folder = new Folder($path); $files = $Folder->findRecursive('.*\.(' . implode('|', $this->settings['files']) . ')', true); foreach ($files as $file) { if (strpos($file, DS . 'Vendor' . DS) !== false) { continue; } $this->_files[] = $file; } } }
[ "protected", "function", "_searchFiles", "(", ")", "{", "foreach", "(", "$", "this", "->", "_paths", "as", "$", "path", ")", "{", "$", "Folder", "=", "new", "Folder", "(", "$", "path", ")", ";", "$", "files", "=", "$", "Folder", "->", "findRecursive", "(", "'.*\\.('", ".", "implode", "(", "'|'", ",", "$", "this", "->", "settings", "[", "'files'", "]", ")", ".", "')'", ",", "true", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "strpos", "(", "$", "file", ",", "DS", ".", "'Vendor'", ".", "DS", ")", "!==", "false", ")", "{", "continue", ";", "}", "$", "this", "->", "_files", "[", "]", "=", "$", "file", ";", "}", "}", "}" ]
Search files that may contain translateable strings @return void
[ "Search", "files", "that", "may", "contain", "translateable", "strings" ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/IndentShell.php#L261-L272
train
dereuromark/cakephp-setup
src/Shell/DbMaintenanceShell.php
DbMaintenanceShell.engine
public function engine($engine = null) { $db = $this->_getConnection(); $config = $db->config(); $database = $config['database']; $prefix = ''; //$config['prefix']; $engines = ['InnoDB', 'MyISAM']; while (!$engine) { $engine = $this->in('Please select target engine', $engines); } if (!in_array($engine, $engines)) { $this->abort('Please provide a valid target format/engine.'); } $script = <<<SQL SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=$engine;') AS statement FROM information_schema.tables AS tb WHERE table_schema = '$database' AND table_name LIKE '$prefix%' AND `ENGINE` != '$engine' AND `TABLE_TYPE` = 'BASE TABLE'; SQL; /** @var \Cake\Database\Statement\StatementDecorator $res */ $res = $db->query($script); if (!$res) { $this->abort('Nothing to do...'); } $script = ''; foreach ($res as $r) { $this->out($r['statement'], 1, Shell::VERBOSE); $script .= $r['statement']; } if (!$this->param('dry-run')) { $continue = $this->in(count($res) . ' tables will be altered.', ['Y', 'N'], 'N'); if (strtoupper($continue) !== 'Y') { $this->abort('Aborted!'); } } if (!$this->params['dry-run']) { $db->query($script); } else { $this->out($script); } $this->out('Done :)'); }
php
public function engine($engine = null) { $db = $this->_getConnection(); $config = $db->config(); $database = $config['database']; $prefix = ''; //$config['prefix']; $engines = ['InnoDB', 'MyISAM']; while (!$engine) { $engine = $this->in('Please select target engine', $engines); } if (!in_array($engine, $engines)) { $this->abort('Please provide a valid target format/engine.'); } $script = <<<SQL SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=$engine;') AS statement FROM information_schema.tables AS tb WHERE table_schema = '$database' AND table_name LIKE '$prefix%' AND `ENGINE` != '$engine' AND `TABLE_TYPE` = 'BASE TABLE'; SQL; /** @var \Cake\Database\Statement\StatementDecorator $res */ $res = $db->query($script); if (!$res) { $this->abort('Nothing to do...'); } $script = ''; foreach ($res as $r) { $this->out($r['statement'], 1, Shell::VERBOSE); $script .= $r['statement']; } if (!$this->param('dry-run')) { $continue = $this->in(count($res) . ' tables will be altered.', ['Y', 'N'], 'N'); if (strtoupper($continue) !== 'Y') { $this->abort('Aborted!'); } } if (!$this->params['dry-run']) { $db->query($script); } else { $this->out($script); } $this->out('Done :)'); }
[ "public", "function", "engine", "(", "$", "engine", "=", "null", ")", "{", "$", "db", "=", "$", "this", "->", "_getConnection", "(", ")", ";", "$", "config", "=", "$", "db", "->", "config", "(", ")", ";", "$", "database", "=", "$", "config", "[", "'database'", "]", ";", "$", "prefix", "=", "''", ";", "//$config['prefix'];", "$", "engines", "=", "[", "'InnoDB'", ",", "'MyISAM'", "]", ";", "while", "(", "!", "$", "engine", ")", "{", "$", "engine", "=", "$", "this", "->", "in", "(", "'Please select target engine'", ",", "$", "engines", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "engine", ",", "$", "engines", ")", ")", "{", "$", "this", "->", "abort", "(", "'Please provide a valid target format/engine.'", ")", ";", "}", "$", "script", "=", " <<<SQL\nSELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=$engine;') AS statement\nFROM information_schema.tables AS tb\nWHERE table_schema = '$database'\nAND table_name LIKE '$prefix%'\nAND `ENGINE` != '$engine'\nAND `TABLE_TYPE` = 'BASE TABLE';\nSQL", ";", "/** @var \\Cake\\Database\\Statement\\StatementDecorator $res */", "$", "res", "=", "$", "db", "->", "query", "(", "$", "script", ")", ";", "if", "(", "!", "$", "res", ")", "{", "$", "this", "->", "abort", "(", "'Nothing to do...'", ")", ";", "}", "$", "script", "=", "''", ";", "foreach", "(", "$", "res", "as", "$", "r", ")", "{", "$", "this", "->", "out", "(", "$", "r", "[", "'statement'", "]", ",", "1", ",", "Shell", "::", "VERBOSE", ")", ";", "$", "script", ".=", "$", "r", "[", "'statement'", "]", ";", "}", "if", "(", "!", "$", "this", "->", "param", "(", "'dry-run'", ")", ")", "{", "$", "continue", "=", "$", "this", "->", "in", "(", "count", "(", "$", "res", ")", ".", "' tables will be altered.'", ",", "[", "'Y'", ",", "'N'", "]", ",", "'N'", ")", ";", "if", "(", "strtoupper", "(", "$", "continue", ")", "!==", "'Y'", ")", "{", "$", "this", "->", "abort", "(", "'Aborted!'", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "params", "[", "'dry-run'", "]", ")", "{", "$", "db", "->", "query", "(", "$", "script", ")", ";", "}", "else", "{", "$", "this", "->", "out", "(", "$", "script", ")", ";", "}", "$", "this", "->", "out", "(", "'Done :)'", ")", ";", "}" ]
Convert database table engine. Args (optional) - target engine (MyIsam, InnoDB) @param string|null $engine Engine to convert to. @return void
[ "Convert", "database", "table", "engine", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/DbMaintenanceShell.php#L113-L160
train
dereuromark/cakephp-setup
src/Shell/DbMaintenanceShell.php
DbMaintenanceShell.tablePrefix
public function tablePrefix($action = null, $prefix = null) { $db = $this->_getConnection(); $config = $db->config(); $database = $config['database']; if (!empty($this->params['database'])) { $database = $this->params['database']; } while (!$action || !in_array($action, ['A', 'R'], true)) { $action = $this->in('Add or remove?', ['A', 'R']); } while (!$prefix) { $prefix = $this->in('Please select prefix:'); } $space = "\n"; if ($action === 'R') { $length = mb_strlen($prefix) + 1; $script = <<<SQL SELECT CONCAT('RENAME TABLE `$database`.`', table_name, '` TO `$database`.`', SUBSTR(table_name, $length), '`;$space') AS statement FROM information_schema.tables AS tb WHERE table_schema = '$database' AND table_name LIKE '$prefix%' AND `TABLE_TYPE` = 'BASE TABLE'; SQL; } else { $script = <<<SQL SELECT CONCAT('RENAME TABLE `$database`.`', table_name, '` TO `$database`.`$prefix', table_name, '`;$space') AS statement FROM information_schema.tables AS tb WHERE table_schema = '$database' AND table_name NOT LIKE '$prefix%' AND `TABLE_TYPE` = 'BASE TABLE'; SQL; } /** @var \Cake\Database\Statement\StatementDecorator $res */ $res = $db->query($script); if (!$res->count()) { $this->abort('Nothing to do...'); } $script = ''; foreach ($res as $r) { $script .= $r['statement']; $this->out($r['statement'], 1, Shell::VERBOSE); } if (!$this->param('dry-run')) { $continue = $this->in($res->count() . ' tables will be altered.', ['Y', 'N'], 'N'); if (strtoupper($continue) !== 'Y') { $this->abort('Aborted!'); } } if (!$this->params['dry-run']) { $db->query($script); } else { $this->out($script); } $this->out('Done :)'); }
php
public function tablePrefix($action = null, $prefix = null) { $db = $this->_getConnection(); $config = $db->config(); $database = $config['database']; if (!empty($this->params['database'])) { $database = $this->params['database']; } while (!$action || !in_array($action, ['A', 'R'], true)) { $action = $this->in('Add or remove?', ['A', 'R']); } while (!$prefix) { $prefix = $this->in('Please select prefix:'); } $space = "\n"; if ($action === 'R') { $length = mb_strlen($prefix) + 1; $script = <<<SQL SELECT CONCAT('RENAME TABLE `$database`.`', table_name, '` TO `$database`.`', SUBSTR(table_name, $length), '`;$space') AS statement FROM information_schema.tables AS tb WHERE table_schema = '$database' AND table_name LIKE '$prefix%' AND `TABLE_TYPE` = 'BASE TABLE'; SQL; } else { $script = <<<SQL SELECT CONCAT('RENAME TABLE `$database`.`', table_name, '` TO `$database`.`$prefix', table_name, '`;$space') AS statement FROM information_schema.tables AS tb WHERE table_schema = '$database' AND table_name NOT LIKE '$prefix%' AND `TABLE_TYPE` = 'BASE TABLE'; SQL; } /** @var \Cake\Database\Statement\StatementDecorator $res */ $res = $db->query($script); if (!$res->count()) { $this->abort('Nothing to do...'); } $script = ''; foreach ($res as $r) { $script .= $r['statement']; $this->out($r['statement'], 1, Shell::VERBOSE); } if (!$this->param('dry-run')) { $continue = $this->in($res->count() . ' tables will be altered.', ['Y', 'N'], 'N'); if (strtoupper($continue) !== 'Y') { $this->abort('Aborted!'); } } if (!$this->params['dry-run']) { $db->query($script); } else { $this->out($script); } $this->out('Done :)'); }
[ "public", "function", "tablePrefix", "(", "$", "action", "=", "null", ",", "$", "prefix", "=", "null", ")", "{", "$", "db", "=", "$", "this", "->", "_getConnection", "(", ")", ";", "$", "config", "=", "$", "db", "->", "config", "(", ")", ";", "$", "database", "=", "$", "config", "[", "'database'", "]", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "params", "[", "'database'", "]", ")", ")", "{", "$", "database", "=", "$", "this", "->", "params", "[", "'database'", "]", ";", "}", "while", "(", "!", "$", "action", "||", "!", "in_array", "(", "$", "action", ",", "[", "'A'", ",", "'R'", "]", ",", "true", ")", ")", "{", "$", "action", "=", "$", "this", "->", "in", "(", "'Add or remove?'", ",", "[", "'A'", ",", "'R'", "]", ")", ";", "}", "while", "(", "!", "$", "prefix", ")", "{", "$", "prefix", "=", "$", "this", "->", "in", "(", "'Please select prefix:'", ")", ";", "}", "$", "space", "=", "\"\\n\"", ";", "if", "(", "$", "action", "===", "'R'", ")", "{", "$", "length", "=", "mb_strlen", "(", "$", "prefix", ")", "+", "1", ";", "$", "script", "=", " <<<SQL\nSELECT CONCAT('RENAME TABLE `$database`.`', table_name, '` TO `$database`.`', SUBSTR(table_name, $length), '`;$space') AS statement\nFROM information_schema.tables AS tb\nWHERE table_schema = '$database'\nAND table_name LIKE '$prefix%'\nAND `TABLE_TYPE` = 'BASE TABLE';\nSQL", ";", "}", "else", "{", "$", "script", "=", " <<<SQL\nSELECT CONCAT('RENAME TABLE `$database`.`', table_name, '` TO `$database`.`$prefix', table_name, '`;$space') AS statement\nFROM information_schema.tables AS tb\nWHERE table_schema = '$database'\nAND table_name NOT LIKE '$prefix%'\nAND `TABLE_TYPE` = 'BASE TABLE';\nSQL", ";", "}", "/** @var \\Cake\\Database\\Statement\\StatementDecorator $res */", "$", "res", "=", "$", "db", "->", "query", "(", "$", "script", ")", ";", "if", "(", "!", "$", "res", "->", "count", "(", ")", ")", "{", "$", "this", "->", "abort", "(", "'Nothing to do...'", ")", ";", "}", "$", "script", "=", "''", ";", "foreach", "(", "$", "res", "as", "$", "r", ")", "{", "$", "script", ".=", "$", "r", "[", "'statement'", "]", ";", "$", "this", "->", "out", "(", "$", "r", "[", "'statement'", "]", ",", "1", ",", "Shell", "::", "VERBOSE", ")", ";", "}", "if", "(", "!", "$", "this", "->", "param", "(", "'dry-run'", ")", ")", "{", "$", "continue", "=", "$", "this", "->", "in", "(", "$", "res", "->", "count", "(", ")", ".", "' tables will be altered.'", ",", "[", "'Y'", ",", "'N'", "]", ",", "'N'", ")", ";", "if", "(", "strtoupper", "(", "$", "continue", ")", "!==", "'Y'", ")", "{", "$", "this", "->", "abort", "(", "'Aborted!'", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "params", "[", "'dry-run'", "]", ")", "{", "$", "db", "->", "query", "(", "$", "script", ")", ";", "}", "else", "{", "$", "this", "->", "out", "(", "$", "script", ")", ";", "}", "$", "this", "->", "out", "(", "'Done :)'", ")", ";", "}" ]
Adds or removes table prefixes. Since CakePHP 3.0 does not support them, this is very useful when migrating 2.x apps that use those prefixes. @param string|null $action @param string|null $prefix @return void
[ "Adds", "or", "removes", "table", "prefixes", "." ]
8642d546652bf3d75beb1513370dcf3490b17389
https://github.com/dereuromark/cakephp-setup/blob/8642d546652bf3d75beb1513370dcf3490b17389/src/Shell/DbMaintenanceShell.php#L172-L233
train