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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_PaymentObject.loadBasicPaymentMethodClass | protected function loadBasicPaymentMethodClass()
{
if (!class_exists("Icepay_Api_Basic"))
return $this;
$this->pm_class = Icepay_Api_Basic::getInstance()
->readFolder()
->getClassByPaymentMethodCode($this->data->ic_paymentmethod);
if (count($this->pm_class->getSupportedIssuers()) == 1) {
$this->setIssuer(current($this->pm_class->getSupportedIssuers()));
}
return $this;
} | php | protected function loadBasicPaymentMethodClass()
{
if (!class_exists("Icepay_Api_Basic"))
return $this;
$this->pm_class = Icepay_Api_Basic::getInstance()
->readFolder()
->getClassByPaymentMethodCode($this->data->ic_paymentmethod);
if (count($this->pm_class->getSupportedIssuers()) == 1) {
$this->setIssuer(current($this->pm_class->getSupportedIssuers()));
}
return $this;
} | [
"protected",
"function",
"loadBasicPaymentMethodClass",
"(",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"\"Icepay_Api_Basic\"",
")",
")",
"return",
"$",
"this",
";",
"$",
"this",
"->",
"pm_class",
"=",
"Icepay_Api_Basic",
"::",
"getInstance",
"(",
")",
"->... | Load a paymentmethod class for Basic
@since version 2.1.0
@access protected | [
"Load",
"a",
"paymentmethod",
"class",
"for",
"Basic"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L205-L219 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_PaymentObject.setCountry | public function setCountry($country)
{
$country = strtoupper($country);
if (!Icepay_Parameter_Validation::country($country))
throw new Exception('Country not valid');
$this->data->ic_country = $country;
return $this;
} | php | public function setCountry($country)
{
$country = strtoupper($country);
if (!Icepay_Parameter_Validation::country($country))
throw new Exception('Country not valid');
$this->data->ic_country = $country;
return $this;
} | [
"public",
"function",
"setCountry",
"(",
"$",
"country",
")",
"{",
"$",
"country",
"=",
"strtoupper",
"(",
"$",
"country",
")",
";",
"if",
"(",
"!",
"Icepay_Parameter_Validation",
"::",
"country",
"(",
"$",
"country",
")",
")",
"throw",
"new",
"Exception",... | Set the country field
@since version 1.0.0
@access public
@param string $currency Country ISO 3166-1-alpha-2 code !Required
@example setCountry("NL") // Netherlands | [
"Set",
"the",
"country",
"field"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L239-L246 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_PaymentObject.setLanguage | public function setLanguage($lang)
{
if (!Icepay_Parameter_Validation::language($lang))
throw new Exception('Language not valid');
$this->data->ic_language = $lang;
return $this;
} | php | public function setLanguage($lang)
{
if (!Icepay_Parameter_Validation::language($lang))
throw new Exception('Language not valid');
$this->data->ic_language = $lang;
return $this;
} | [
"public",
"function",
"setLanguage",
"(",
"$",
"lang",
")",
"{",
"if",
"(",
"!",
"Icepay_Parameter_Validation",
"::",
"language",
"(",
"$",
"lang",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Language not valid'",
")",
";",
"$",
"this",
"->",
"data",
"->... | Set the language field
@since version 1.0.0
@access public
@param string $lang Language ISO 639-1 code !Required
@example setLanguage("EN") // English | [
"Set",
"the",
"language",
"field"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L268-L274 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_PaymentObject.setAmount | public function setAmount($amount)
{
$amount = (int) (string) $amount;
if (!Icepay_Parameter_Validation::amount($amount))
throw new Exception('Amount not valid');
$this->data->ic_amount = $amount;
return $this;
} | php | public function setAmount($amount)
{
$amount = (int) (string) $amount;
if (!Icepay_Parameter_Validation::amount($amount))
throw new Exception('Amount not valid');
$this->data->ic_amount = $amount;
return $this;
} | [
"public",
"function",
"setAmount",
"(",
"$",
"amount",
")",
"{",
"$",
"amount",
"=",
"(",
"int",
")",
"(",
"string",
")",
"$",
"amount",
";",
"if",
"(",
"!",
"Icepay_Parameter_Validation",
"::",
"amount",
"(",
"$",
"amount",
")",
")",
"throw",
"new",
... | Set the amount field
@since version 1.0.0
@access public
@param int $amount !Required | [
"Set",
"the",
"amount",
"field"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L282-L290 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Api_Base.setMerchantID | public function setMerchantID($merchantID)
{
if (!Icepay_Parameter_Validation::merchantID($merchantID))
throw new Exception('MerchantID not valid');
$this->_merchantID = (int) $merchantID;
return $this;
} | php | public function setMerchantID($merchantID)
{
if (!Icepay_Parameter_Validation::merchantID($merchantID))
throw new Exception('MerchantID not valid');
$this->_merchantID = (int) $merchantID;
return $this;
} | [
"public",
"function",
"setMerchantID",
"(",
"$",
"merchantID",
")",
"{",
"if",
"(",
"!",
"Icepay_Parameter_Validation",
"::",
"merchantID",
"(",
"$",
"merchantID",
")",
")",
"throw",
"new",
"Exception",
"(",
"'MerchantID not valid'",
")",
";",
"$",
"this",
"->... | Set the Merchant ID field
@since 1.0.0
@access public
@param (int) $merchantID | [
"Set",
"the",
"Merchant",
"ID",
"field"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L691-L699 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Api_Base.setSecretCode | public function setSecretCode($secretCode)
{
if (!Icepay_Parameter_Validation::secretCode($secretCode))
throw new Exception('Secretcode not valid');
$this->_secretCode = (string) $secretCode;
return $this;
} | php | public function setSecretCode($secretCode)
{
if (!Icepay_Parameter_Validation::secretCode($secretCode))
throw new Exception('Secretcode not valid');
$this->_secretCode = (string) $secretCode;
return $this;
} | [
"public",
"function",
"setSecretCode",
"(",
"$",
"secretCode",
")",
"{",
"if",
"(",
"!",
"Icepay_Parameter_Validation",
"::",
"secretCode",
"(",
"$",
"secretCode",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Secretcode not valid'",
")",
";",
"$",
"this",
"->... | Set the Secret Code field
@since 1.0.0
@access public
@param (string) $secretCode | [
"Set",
"the",
"Secret",
"Code",
"field"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L718-L725 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Api_Base.setPinCode | public function setPinCode($pinCode)
{
if (!Icepay_Parameter_Validation::pinCode($pinCode))
throw new Exception('Pincode not valid');
$this->_pinCode = (string) $pinCode;
return $this;
} | php | public function setPinCode($pinCode)
{
if (!Icepay_Parameter_Validation::pinCode($pinCode))
throw new Exception('Pincode not valid');
$this->_pinCode = (string) $pinCode;
return $this;
} | [
"public",
"function",
"setPinCode",
"(",
"$",
"pinCode",
")",
"{",
"if",
"(",
"!",
"Icepay_Parameter_Validation",
"::",
"pinCode",
"(",
"$",
"pinCode",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Pincode not valid'",
")",
";",
"$",
"this",
"->",
"_pinCode"... | Set the Pin Code field
@since 1.0.1
@access public
@param (int) $pinCode | [
"Set",
"the",
"Pin",
"Code",
"field"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L744-L752 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Api_Logger.logToFunction | public function logToFunction($className = null, $logFunction = null, $bool = true)
{
$this->_logToHook = $bool;
if (class_exists($className))
$this->_logHookClass = new $className;
if (is_callable($logFunction))
$this->_logHookFunc = $logFunction;
return $this;
} | php | public function logToFunction($className = null, $logFunction = null, $bool = true)
{
$this->_logToHook = $bool;
if (class_exists($className))
$this->_logHookClass = new $className;
if (is_callable($logFunction))
$this->_logHookFunc = $logFunction;
return $this;
} | [
"public",
"function",
"logToFunction",
"(",
"$",
"className",
"=",
"null",
",",
"$",
"logFunction",
"=",
"null",
",",
"$",
"bool",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_logToHook",
"=",
"$",
"bool",
";",
"if",
"(",
"class_exists",
"(",
"$",
"cl... | Enable or disable logging to a hooked class
@since 2.1.0
@access public
@param string $className
@param string $logFunction
@param bool $bool
@return \Icepay_Basicmode | [
"Enable",
"or",
"disable",
"logging",
"to",
"a",
"hooked",
"class"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1020-L1031 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Api_Logger.setLoggingLevel | public function setLoggingLevel($level)
{
switch ($level) {
case Icepay_Api_Logger::LEVEL_ALL:
$this->_setLoggingFlag(Icepay_Api_Logger::NOTICE);
$this->_setLoggingFlag(Icepay_Api_Logger::TRANSACTION);
$this->_setLoggingFlag(Icepay_Api_Logger::ERROR);
break;
case Icepay_Api_Logger::LEVEL_ERRORS:
$this->_setLoggingFlag(Icepay_Api_Logger::NOTICE, false);
$this->_setLoggingFlag(Icepay_Api_Logger::TRANSACTION, false);
$this->_setLoggingFlag(Icepay_Api_Logger::ERROR);
break;
case Icepay_Api_Logger::LEVEL_TRANSACTION:
$this->_setLoggingFlag(Icepay_Api_Logger::NOTICE, false);
$this->_setLoggingFlag(Icepay_Api_Logger::TRANSACTION);
$this->_setLoggingFlag(Icepay_Api_Logger::ERROR, false);
break;
case Icepay_Api_Logger::LEVEL_ERRORS_AND_TRANSACTION:
$this->_setLoggingFlag(Icepay_Api_Logger::NOTICE, false);
$this->_setLoggingFlag(Icepay_Api_Logger::TRANSACTION);
$this->_setLoggingFlag(Icepay_Api_Logger::ERROR);
break;
}
return $this;
} | php | public function setLoggingLevel($level)
{
switch ($level) {
case Icepay_Api_Logger::LEVEL_ALL:
$this->_setLoggingFlag(Icepay_Api_Logger::NOTICE);
$this->_setLoggingFlag(Icepay_Api_Logger::TRANSACTION);
$this->_setLoggingFlag(Icepay_Api_Logger::ERROR);
break;
case Icepay_Api_Logger::LEVEL_ERRORS:
$this->_setLoggingFlag(Icepay_Api_Logger::NOTICE, false);
$this->_setLoggingFlag(Icepay_Api_Logger::TRANSACTION, false);
$this->_setLoggingFlag(Icepay_Api_Logger::ERROR);
break;
case Icepay_Api_Logger::LEVEL_TRANSACTION:
$this->_setLoggingFlag(Icepay_Api_Logger::NOTICE, false);
$this->_setLoggingFlag(Icepay_Api_Logger::TRANSACTION);
$this->_setLoggingFlag(Icepay_Api_Logger::ERROR, false);
break;
case Icepay_Api_Logger::LEVEL_ERRORS_AND_TRANSACTION:
$this->_setLoggingFlag(Icepay_Api_Logger::NOTICE, false);
$this->_setLoggingFlag(Icepay_Api_Logger::TRANSACTION);
$this->_setLoggingFlag(Icepay_Api_Logger::ERROR);
break;
}
return $this;
} | [
"public",
"function",
"setLoggingLevel",
"(",
"$",
"level",
")",
"{",
"switch",
"(",
"$",
"level",
")",
"{",
"case",
"Icepay_Api_Logger",
"::",
"LEVEL_ALL",
":",
"$",
"this",
"->",
"_setLoggingFlag",
"(",
"Icepay_Api_Logger",
"::",
"NOTICE",
")",
";",
"$",
... | Set the logging level
@since 2.1.0
@access public
@param int $level | [
"Set",
"the",
"logging",
"level"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1072-L1098 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Api_Logger.log | public function log($line, $level = 1)
{
// Check if logging is enabled
if (!$this->_loggingEnabled)
return false;
// Check if the level is within the required level
if (!$this->_isLoggingSet($level))
return false;
$dateTime = date("H:i:s", time());
$line = "{$dateTime} [ICEPAY]: {$line}" . PHP_EOL;
// Log to Screen
if ($this->_logToScreen)
echo "{$line} <br />";
// Log to Hooked Class
if ($this->_logToHook && $this->_logHookClass && $this->_logHookFunc) {
$function = $this->_logHookFunc;
$this->_logHookClass->$function($line);
}
// Log to Default File
if ($this->_logToFile) {
$file = $this->_loggingDirectory . DS . $this->_loggingFile;
try {
$fp = fopen($file, "a");
fwrite($fp, $line);
fclose($fp);
} catch (Exception $e) {
throw new Exception($e->getMessage());
};
}
} | php | public function log($line, $level = 1)
{
// Check if logging is enabled
if (!$this->_loggingEnabled)
return false;
// Check if the level is within the required level
if (!$this->_isLoggingSet($level))
return false;
$dateTime = date("H:i:s", time());
$line = "{$dateTime} [ICEPAY]: {$line}" . PHP_EOL;
// Log to Screen
if ($this->_logToScreen)
echo "{$line} <br />";
// Log to Hooked Class
if ($this->_logToHook && $this->_logHookClass && $this->_logHookFunc) {
$function = $this->_logHookFunc;
$this->_logHookClass->$function($line);
}
// Log to Default File
if ($this->_logToFile) {
$file = $this->_loggingDirectory . DS . $this->_loggingFile;
try {
$fp = fopen($file, "a");
fwrite($fp, $line);
fclose($fp);
} catch (Exception $e) {
throw new Exception($e->getMessage());
};
}
} | [
"public",
"function",
"log",
"(",
"$",
"line",
",",
"$",
"level",
"=",
"1",
")",
"{",
"// Check if logging is enabled",
"if",
"(",
"!",
"$",
"this",
"->",
"_loggingEnabled",
")",
"return",
"false",
";",
"// Check if the level is within the required level",
"if",
... | Log given line
@since 2.1.0
@access public
@param string $line
@param int $level
@return boolean
@throws Exception | [
"Log",
"given",
"line"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1142-L1178 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Postback.getTransactionString | public function getTransactionString()
{
return sprintf(
"Paymentmethod: %s \n| OrderID: %s \n| Status: %s \n| StatusCode: %s \n| PaymentID: %s \n| TransactionID: %s \n| Amount: %s", isset($this->data->paymentMethod) ? $this->data->paymentMethod : "", isset($this->data->orderID) ? $this->data->orderID : "", isset($this->data->status) ? $this->data->status : "", isset($this->data->statusCode) ? $this->data->statusCode : "", isset($this->data->paymentID) ? $this->data->paymentID : "", isset($this->data->transactionID) ? $this->data->transactionID : "", isset($this->data->amount) ? $this->data->amount : ""
);
} | php | public function getTransactionString()
{
return sprintf(
"Paymentmethod: %s \n| OrderID: %s \n| Status: %s \n| StatusCode: %s \n| PaymentID: %s \n| TransactionID: %s \n| Amount: %s", isset($this->data->paymentMethod) ? $this->data->paymentMethod : "", isset($this->data->orderID) ? $this->data->orderID : "", isset($this->data->status) ? $this->data->status : "", isset($this->data->statusCode) ? $this->data->statusCode : "", isset($this->data->paymentID) ? $this->data->paymentID : "", isset($this->data->transactionID) ? $this->data->transactionID : "", isset($this->data->amount) ? $this->data->amount : ""
);
} | [
"public",
"function",
"getTransactionString",
"(",
")",
"{",
"return",
"sprintf",
"(",
"\"Paymentmethod: %s \\n| OrderID: %s \\n| Status: %s \\n| StatusCode: %s \\n| PaymentID: %s \\n| TransactionID: %s \\n| Amount: %s\"",
",",
"isset",
"(",
"$",
"this",
"->",
"data",
"->",
"paym... | Return minimized transactional data
@since version 1.0.0
@access public
@return string | [
"Return",
"minimized",
"transactional",
"data"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1231-L1236 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Postback.generateChecksumForPostback | protected function generateChecksumForPostback()
{
return sha1(
sprintf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s", $this->_secretCode, $this->_merchantID, $this->data->status, $this->data->statusCode, $this->data->orderID, $this->data->paymentID, $this->data->reference, $this->data->transactionID, $this->data->amount, $this->data->currency, $this->data->duration, $this->data->consumerIPAddress
)
);
} | php | protected function generateChecksumForPostback()
{
return sha1(
sprintf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s", $this->_secretCode, $this->_merchantID, $this->data->status, $this->data->statusCode, $this->data->orderID, $this->data->paymentID, $this->data->reference, $this->data->transactionID, $this->data->amount, $this->data->currency, $this->data->duration, $this->data->consumerIPAddress
)
);
} | [
"protected",
"function",
"generateChecksumForPostback",
"(",
")",
"{",
"return",
"sha1",
"(",
"sprintf",
"(",
"\"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\"",
",",
"$",
"this",
"->",
"_secretCode",
",",
"$",
"this",
"->",
"_merchantID",
",",
"$",
"this",
"->",
"data",
... | Return the postback checksum
@since version 1.0.0
@access protected
@return string SHA1 encoded | [
"Return",
"the",
"postback",
"checksum"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1266-L1272 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Postback.generateChecksumForVersion | protected function generateChecksumForVersion()
{
return sha1(
sprintf("%s|%s|%s|%s", $this->_secretCode, $this->_merchantID, $this->data->status, substr(strval(time()), 0, 8)
)
);
} | php | protected function generateChecksumForVersion()
{
return sha1(
sprintf("%s|%s|%s|%s", $this->_secretCode, $this->_merchantID, $this->data->status, substr(strval(time()), 0, 8)
)
);
} | [
"protected",
"function",
"generateChecksumForVersion",
"(",
")",
"{",
"return",
"sha1",
"(",
"sprintf",
"(",
"\"%s|%s|%s|%s\"",
",",
"$",
"this",
"->",
"_secretCode",
",",
"$",
"this",
"->",
"_merchantID",
",",
"$",
"this",
"->",
"data",
"->",
"status",
",",... | Return the version checksum
@since version 1.0.2
@access protected
@return string SHA1 encoded | [
"Return",
"the",
"version",
"checksum"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1280-L1286 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Postback.validateVersion | public function validateVersion()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->_logger->log('Invalid request method', Icepay_Api_Logger::ERROR);
return false;
}
if ($this->generateChecksumForVersion() != $this->data->checksum) {
$this->_logger->log('Checksum does not match', Icepay_Api_Logger::ERROR);
return false;
}
return true;
} | php | public function validateVersion()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->_logger->log('Invalid request method', Icepay_Api_Logger::ERROR);
return false;
}
if ($this->generateChecksumForVersion() != $this->data->checksum) {
$this->_logger->log('Checksum does not match', Icepay_Api_Logger::ERROR);
return false;
}
return true;
} | [
"public",
"function",
"validateVersion",
"(",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"!=",
"'POST'",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"log",
"(",
"'Invalid request method'",
",",
"Icepay_Api_Logger",
"::",
"ERROR",
")... | Validate for version check
@since version 1.0.2
@access public
@return boolean | [
"Validate",
"for",
"version",
"check"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1328-L1341 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Postback.isVersionCheck | public function isVersionCheck()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->_logger->log('Invalid request method', Icepay_Api_Logger::ERROR);
return false;
}
if ($this->data->status != "VCHECK")
return false;
return true;
} | php | public function isVersionCheck()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->_logger->log('Invalid request method', Icepay_Api_Logger::ERROR);
return false;
}
if ($this->data->status != "VCHECK")
return false;
return true;
} | [
"public",
"function",
"isVersionCheck",
"(",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"!=",
"'POST'",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"log",
"(",
"'Invalid request method'",
",",
"Icepay_Api_Logger",
"::",
"ERROR",
")"... | Has Version Check status
@since version 1.0.2
@access public
@return boolean | [
"Has",
"Version",
"Check",
"status"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1349-L1360 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Postback.validate | public function validate()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->_logger->log("Invalid request method", Icepay_Api_Logger::ERROR);
return false;
};
$this->_logger->log(sprintf("Postback: %s", serialize($_POST)), Icepay_Api_Logger::TRANSACTION);
/* @since version 1.0.2 */
foreach ($this->getPostbackResponseFields() as $obj => $param) {
$this->data->$obj = (isset($_POST[$param])) ? $_POST[$param] : "";
}
if ($this->isVersionCheck())
return false;
if (!Icepay_Parameter_Validation::merchantID($this->data->merchant)) {
$this->_logger->log("Merchant ID is not numeric: {$this->data->merchant}", Icepay_Api_Logger::ERROR);
return false;
}
if (!Icepay_Parameter_Validation::amount($this->data->amount)) {
$this->_logger->log("Amount is not numeric: {$this->data->amount}", Icepay_Api_Logger::ERROR);
return false;
}
if ($this->_merchantID != $this->data->merchant) {
$this->_logger->log("Invalid Merchant ID: {$this->data->merchant}", Icepay_Api_Logger::ERROR);
return false;
}
if (!in_array(strtoupper($this->data->status), array(
Icepay_StatusCode::OPEN,
Icepay_StatusCode::AUTHORIZED,
Icepay_StatusCode::SUCCESS,
Icepay_StatusCode::ERROR,
Icepay_StatusCode::REFUND,
Icepay_StatusCode::CHARGEBACK
))) {
$this->_logger->log("Unknown status: {$this->data->status}", Icepay_Api_Logger::ERROR);
return false;
}
if ($this->generateChecksumForPostback() != $this->data->checksum) {
$this->_logger->log("Checksum does not match", Icepay_Api_Logger::ERROR);
return false;
}
return true;
} | php | public function validate()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->_logger->log("Invalid request method", Icepay_Api_Logger::ERROR);
return false;
};
$this->_logger->log(sprintf("Postback: %s", serialize($_POST)), Icepay_Api_Logger::TRANSACTION);
/* @since version 1.0.2 */
foreach ($this->getPostbackResponseFields() as $obj => $param) {
$this->data->$obj = (isset($_POST[$param])) ? $_POST[$param] : "";
}
if ($this->isVersionCheck())
return false;
if (!Icepay_Parameter_Validation::merchantID($this->data->merchant)) {
$this->_logger->log("Merchant ID is not numeric: {$this->data->merchant}", Icepay_Api_Logger::ERROR);
return false;
}
if (!Icepay_Parameter_Validation::amount($this->data->amount)) {
$this->_logger->log("Amount is not numeric: {$this->data->amount}", Icepay_Api_Logger::ERROR);
return false;
}
if ($this->_merchantID != $this->data->merchant) {
$this->_logger->log("Invalid Merchant ID: {$this->data->merchant}", Icepay_Api_Logger::ERROR);
return false;
}
if (!in_array(strtoupper($this->data->status), array(
Icepay_StatusCode::OPEN,
Icepay_StatusCode::AUTHORIZED,
Icepay_StatusCode::SUCCESS,
Icepay_StatusCode::ERROR,
Icepay_StatusCode::REFUND,
Icepay_StatusCode::CHARGEBACK
))) {
$this->_logger->log("Unknown status: {$this->data->status}", Icepay_Api_Logger::ERROR);
return false;
}
if ($this->generateChecksumForPostback() != $this->data->checksum) {
$this->_logger->log("Checksum does not match", Icepay_Api_Logger::ERROR);
return false;
}
return true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"!=",
"'POST'",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"log",
"(",
"\"Invalid request method\"",
",",
"Icepay_Api_Logger",
"::",
"ERROR",
")",
... | Validate the postback data
@since version 1.0.0
@access public
@return boolean | [
"Validate",
"the",
"postback",
"data"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1368-L1417 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Postback.canUpdateStatus | public function canUpdateStatus($currentStatus)
{
if (!isset($this->data->status)) {
$this->_logger->log("Status not set", Icepay_Api_Logger::ERROR);
return false;
}
switch ($this->data->status) {
case Icepay_StatusCode::SUCCESS: return ($currentStatus == Icepay_StatusCode::ERROR || $currentStatus == Icepay_StatusCode::AUTHORIZED || $currentStatus == Icepay_StatusCode::OPEN);
case Icepay_StatusCode::OPEN: return ($currentStatus == Icepay_StatusCode::OPEN);
case Icepay_StatusCode::AUTHORIZED: return ($currentStatus == Icepay_StatusCode::OPEN);
case Icepay_StatusCode::ERROR: return ($currentStatus == Icepay_StatusCode::OPEN || $currentStatus == Icepay_StatusCode::AUTHORIZED);
case Icepay_StatusCode::CHARGEBACK: return ($currentStatus == Icepay_StatusCode::SUCCESS);
case Icepay_StatusCode::REFUND: return ($currentStatus == Icepay_StatusCode::SUCCESS);
default:
return false;
};
} | php | public function canUpdateStatus($currentStatus)
{
if (!isset($this->data->status)) {
$this->_logger->log("Status not set", Icepay_Api_Logger::ERROR);
return false;
}
switch ($this->data->status) {
case Icepay_StatusCode::SUCCESS: return ($currentStatus == Icepay_StatusCode::ERROR || $currentStatus == Icepay_StatusCode::AUTHORIZED || $currentStatus == Icepay_StatusCode::OPEN);
case Icepay_StatusCode::OPEN: return ($currentStatus == Icepay_StatusCode::OPEN);
case Icepay_StatusCode::AUTHORIZED: return ($currentStatus == Icepay_StatusCode::OPEN);
case Icepay_StatusCode::ERROR: return ($currentStatus == Icepay_StatusCode::OPEN || $currentStatus == Icepay_StatusCode::AUTHORIZED);
case Icepay_StatusCode::CHARGEBACK: return ($currentStatus == Icepay_StatusCode::SUCCESS);
case Icepay_StatusCode::REFUND: return ($currentStatus == Icepay_StatusCode::SUCCESS);
default:
return false;
};
} | [
"public",
"function",
"canUpdateStatus",
"(",
"$",
"currentStatus",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"->",
"status",
")",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"log",
"(",
"\"Status not set\"",
",",
"Icepay_Api_L... | Check between ICEPAY statuscodes whether the status can be updated.
@since version 1.0.0
@access public
@param string $currentStatus The ICEPAY statuscode of the order before a statuschange
@return boolean | [
"Check",
"between",
"ICEPAY",
"statuscodes",
"whether",
"the",
"status",
"can",
"be",
"updated",
"."
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1437-L1454 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Result.validate | public function validate()
{
if ($_SERVER['REQUEST_METHOD'] != 'GET') {
$this->_logger->log("Invalid request method", Icepay_Api_Logger::ERROR);
return false;
}
$this->_logger->log(sprintf("Page data: %s", serialize($_GET)), Icepay_Api_Logger::NOTICE);
$this->data->status = (isset($_GET['Status'])) ? $_GET['Status'] : "";
$this->data->statusCode = (isset($_GET['StatusCode'])) ? $_GET['StatusCode'] : "";
$this->data->merchant = (isset($_GET['Merchant'])) ? $_GET['Merchant'] : "";
$this->data->orderID = (isset($_GET['OrderID'])) ? $_GET['OrderID'] : "";
$this->data->paymentID = (isset($_GET['PaymentID'])) ? $_GET['PaymentID'] : "";
$this->data->reference = (isset($_GET['Reference'])) ? $_GET['Reference'] : "";
$this->data->transactionID = (isset($_GET['TransactionID'])) ? $_GET['TransactionID'] : "";
$this->data->checksum = (isset($_GET['Checksum'])) ? $_GET['Checksum'] : "";
if ($this->generateChecksumForPage() != $this->data->checksum) {
$this->_logger->log("Checksum does not match", Icepay_Api_Logger::ERROR);
return false;
}
return true;
} | php | public function validate()
{
if ($_SERVER['REQUEST_METHOD'] != 'GET') {
$this->_logger->log("Invalid request method", Icepay_Api_Logger::ERROR);
return false;
}
$this->_logger->log(sprintf("Page data: %s", serialize($_GET)), Icepay_Api_Logger::NOTICE);
$this->data->status = (isset($_GET['Status'])) ? $_GET['Status'] : "";
$this->data->statusCode = (isset($_GET['StatusCode'])) ? $_GET['StatusCode'] : "";
$this->data->merchant = (isset($_GET['Merchant'])) ? $_GET['Merchant'] : "";
$this->data->orderID = (isset($_GET['OrderID'])) ? $_GET['OrderID'] : "";
$this->data->paymentID = (isset($_GET['PaymentID'])) ? $_GET['PaymentID'] : "";
$this->data->reference = (isset($_GET['Reference'])) ? $_GET['Reference'] : "";
$this->data->transactionID = (isset($_GET['TransactionID'])) ? $_GET['TransactionID'] : "";
$this->data->checksum = (isset($_GET['Checksum'])) ? $_GET['Checksum'] : "";
if ($this->generateChecksumForPage() != $this->data->checksum) {
$this->_logger->log("Checksum does not match", Icepay_Api_Logger::ERROR);
return false;
}
return true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"!=",
"'GET'",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"log",
"(",
"\"Invalid request method\"",
",",
"Icepay_Api_Logger",
"::",
"ERROR",
")",
"... | Validate the ICEPAY GET data
@since version 1.0.0
@access public
@return boolean | [
"Validate",
"the",
"ICEPAY",
"GET",
"data"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1479-L1503 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Result.getStatus | public function getStatus($includeStatusCode = false)
{
if (!isset($this->data->status))
return null;
return ($includeStatusCode) ? sprintf("%s: %s", $this->data->status, $this->data->statusCode) : $this->data->status;
} | php | public function getStatus($includeStatusCode = false)
{
if (!isset($this->data->status))
return null;
return ($includeStatusCode) ? sprintf("%s: %s", $this->data->status, $this->data->statusCode) : $this->data->status;
} | [
"public",
"function",
"getStatus",
"(",
"$",
"includeStatusCode",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"->",
"status",
")",
")",
"return",
"null",
";",
"return",
"(",
"$",
"includeStatusCode",
")",
"?",
"spri... | Get the ICEPAY status
@since version 1.0.0
@access public
@param boolean $includeStatusCode Add the statuscode message to the returned string for display purposes
@return string ICEPAY statuscode (and statuscode message) | [
"Get",
"the",
"ICEPAY",
"status"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1512-L1517 | train |
ICEPAY/deprecated-i | src/icepay_api_base.php | Icepay_Result.generateChecksumForPage | protected function generateChecksumForPage()
{
return sha1(
sprintf("%s|%s|%s|%s|%s|%s|%s|%s", $this->_secretCode, $this->data->merchant, $this->data->status, $this->data->statusCode, $this->data->orderID, $this->data->paymentID, $this->data->reference, $this->data->transactionID
)
);
} | php | protected function generateChecksumForPage()
{
return sha1(
sprintf("%s|%s|%s|%s|%s|%s|%s|%s", $this->_secretCode, $this->data->merchant, $this->data->status, $this->data->statusCode, $this->data->orderID, $this->data->paymentID, $this->data->reference, $this->data->transactionID
)
);
} | [
"protected",
"function",
"generateChecksumForPage",
"(",
")",
"{",
"return",
"sha1",
"(",
"sprintf",
"(",
"\"%s|%s|%s|%s|%s|%s|%s|%s\"",
",",
"$",
"this",
"->",
"_secretCode",
",",
"$",
"this",
"->",
"data",
"->",
"merchant",
",",
"$",
"this",
"->",
"data",
... | Return the result page checksum
@since version 1.0.0
@access protected
@return string SHA1 hash | [
"Return",
"the",
"result",
"page",
"checksum"
] | 9a22271dfaea7f318a555c00d7e3f8cca9f2a28e | https://github.com/ICEPAY/deprecated-i/blob/9a22271dfaea7f318a555c00d7e3f8cca9f2a28e/src/icepay_api_base.php#L1536-L1542 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.addWarningMessages | public function addWarningMessages($message)
{
if (!empty($message)) {
if (is_array($message)) {
$this->warningMessages = array_merge($this->warningMessages, $message);
} else {
$this->warningMessages[] = $message;
}
}
return $this;
} | php | public function addWarningMessages($message)
{
if (!empty($message)) {
if (is_array($message)) {
$this->warningMessages = array_merge($this->warningMessages, $message);
} else {
$this->warningMessages[] = $message;
}
}
return $this;
} | [
"public",
"function",
"addWarningMessages",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"message",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"this",
"->",
"warningMessages",
"=",
"array_merge",... | Adds 1 or more warning messages.
To be used by web shop specific form handling to add a message to the
list of messages to display.
@param string|string[] $message
A warning message or an array of warning messages. If empty, nothing
will be added.
@return $this | [
"Adds",
"1",
"or",
"more",
"warning",
"messages",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L232-L243 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.addErrorMessages | public function addErrorMessages($message)
{
if (!empty($message)) {
if (is_array($message)) {
$this->errorMessages = array_merge($this->errorMessages, $message);
} else {
$this->errorMessages[] = $message;
}
}
return $this;
} | php | public function addErrorMessages($message)
{
if (!empty($message)) {
if (is_array($message)) {
$this->errorMessages = array_merge($this->errorMessages, $message);
} else {
$this->errorMessages[] = $message;
}
}
return $this;
} | [
"public",
"function",
"addErrorMessages",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"message",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"this",
"->",
"errorMessages",
"=",
"array_merge",
"... | Adds 1 or more error messages.
To be used by web shop specific form handling to add a message to the list
of messages to display.
@param string|string[] $message
An error message or an array of error messages. If empty, nothing
will be added.
@return $this | [
"Adds",
"1",
"or",
"more",
"error",
"messages",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L274-L285 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.setFormValues | protected function setFormValues()
{
if (!$this->formValuesSet) {
// Start by assuring the field definitions are constructed.
$this->getFields();
// 1: Hard coded default value for form fields: empty string.
$this->formValues = array_fill_keys($this->getKeys(), '');
// 2: Overwrite with the default values from the field definitions,
// but do so with some special array handling.
$defaultFormValues = $this->getDefaultFormValues();
foreach ($defaultFormValues as $key => $defaultFormValue) {
// We start with a simple overwrite.
if (array_key_exists($key, $this->formValues)) {
$this->formValues[$key] = $defaultFormValue;
} elseif (is_array($defaultFormValue)) {
// Distribute keyed arrays over separate values if existing.
foreach ($defaultFormValue as $arrayKey => $arrayValue) {
$fullKey = "{$key}[{$arrayKey}]";
if (array_key_exists($fullKey, $this->formValues)) {
$this->formValues[$fullKey] = $arrayValue;
}
}
}
}
// 3: Overwrite with the submitted values.
if (!empty($this->submittedValues)) {
$this->formValues = array_merge($this->formValues, $this->submittedValues);
}
// 4: Overwrite with the (hard set) values as set in the field
// definitions.
$this->formValues = array_merge($this->formValues, $this->getFieldValues($this->getFields()));
// 5: Allow for any web shop specific processing of the values.
// Known usages:
// - Prepend (checked) checkboxes with their collection name
// (PrestaShop).
// - Place (checked) checkboxes in their collection (Magento).
$this->formValues = $this->formHelper->alterFormValues($this->formValues);
$this->formValuesSet = true;
}
} | php | protected function setFormValues()
{
if (!$this->formValuesSet) {
// Start by assuring the field definitions are constructed.
$this->getFields();
// 1: Hard coded default value for form fields: empty string.
$this->formValues = array_fill_keys($this->getKeys(), '');
// 2: Overwrite with the default values from the field definitions,
// but do so with some special array handling.
$defaultFormValues = $this->getDefaultFormValues();
foreach ($defaultFormValues as $key => $defaultFormValue) {
// We start with a simple overwrite.
if (array_key_exists($key, $this->formValues)) {
$this->formValues[$key] = $defaultFormValue;
} elseif (is_array($defaultFormValue)) {
// Distribute keyed arrays over separate values if existing.
foreach ($defaultFormValue as $arrayKey => $arrayValue) {
$fullKey = "{$key}[{$arrayKey}]";
if (array_key_exists($fullKey, $this->formValues)) {
$this->formValues[$fullKey] = $arrayValue;
}
}
}
}
// 3: Overwrite with the submitted values.
if (!empty($this->submittedValues)) {
$this->formValues = array_merge($this->formValues, $this->submittedValues);
}
// 4: Overwrite with the (hard set) values as set in the field
// definitions.
$this->formValues = array_merge($this->formValues, $this->getFieldValues($this->getFields()));
// 5: Allow for any web shop specific processing of the values.
// Known usages:
// - Prepend (checked) checkboxes with their collection name
// (PrestaShop).
// - Place (checked) checkboxes in their collection (Magento).
$this->formValues = $this->formHelper->alterFormValues($this->formValues);
$this->formValuesSet = true;
}
} | [
"protected",
"function",
"setFormValues",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"formValuesSet",
")",
"{",
"// Start by assuring the field definitions are constructed.",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"// 1: Hard coded default value for form ... | Sets the form values to use.
This is typically the union of the default values, any submitted values,
and explicitly set field values. | [
"Sets",
"the",
"form",
"values",
"to",
"use",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L313-L358 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.getFormValue | protected function getFormValue($name)
{
$this->setFormValues();
return isset($this->formValues[$name]) ? $this->formValues[$name] : '';
} | php | protected function getFormValue($name)
{
$this->setFormValues();
return isset($this->formValues[$name]) ? $this->formValues[$name] : '';
} | [
"protected",
"function",
"getFormValue",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"setFormValues",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"formValues",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"formValues",
"[",
"$... | Returns the value for a specific form field.
@param string $name
The name of the form field.
@return string
The value for this form field or the empty string if not set. | [
"Returns",
"the",
"value",
"for",
"a",
"specific",
"form",
"field",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L385-L389 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.addValuesToFields | protected function addValuesToFields(array $fields)
{
foreach ($fields as $name => &$field) {
if (!empty($field['fields'])) {
$field['fields'] = $this->addValuesToFields($field['fields']);
} elseif ($field['type'] === 'checkbox') {
// Value is a list of checked options.
$value = array();
foreach ($field['options'] as $optionName => $optionLabel) {
if ($this->getFormValue($optionName)) {
$value[] = $optionName;
}
}
$field['value'] = $value;
} elseif (!isset($field['value'])) {
// Explicitly set values (in the 'value' key) take precedence
// over submitted values, which in turn take precedence over
// default values (gathered via getDefaultFormValues()).
$field['value'] = $this->getFormValue($name);
}
}
return $fields;
} | php | protected function addValuesToFields(array $fields)
{
foreach ($fields as $name => &$field) {
if (!empty($field['fields'])) {
$field['fields'] = $this->addValuesToFields($field['fields']);
} elseif ($field['type'] === 'checkbox') {
// Value is a list of checked options.
$value = array();
foreach ($field['options'] as $optionName => $optionLabel) {
if ($this->getFormValue($optionName)) {
$value[] = $optionName;
}
}
$field['value'] = $value;
} elseif (!isset($field['value'])) {
// Explicitly set values (in the 'value' key) take precedence
// over submitted values, which in turn take precedence over
// default values (gathered via getDefaultFormValues()).
$field['value'] = $this->getFormValue($name);
}
}
return $fields;
} | [
"protected",
"function",
"addValuesToFields",
"(",
"array",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"name",
"=>",
"&",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"field",
"[",
"'fields'",
"]",
")",
")",
"{... | Adds the form values to the field definitions.
This internal version of addValues() passes the fields as a parameter to
allow to recursively process field sets.
@param array[] $fields
@return array[] | [
"Adds",
"the",
"form",
"values",
"to",
"the",
"field",
"definitions",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L427-L449 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.getFieldValues | protected function getFieldValues($fields)
{
$result = array();
foreach ($fields as $id => $field) {
if (isset($field['value'])) {
$result[$id] = $field['value'];
}
if (!empty($field['fields'])) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$result = array_merge($result, $this->getFieldValues($field['fields']));
}
}
return $result;
} | php | protected function getFieldValues($fields)
{
$result = array();
foreach ($fields as $id => $field) {
if (isset($field['value'])) {
$result[$id] = $field['value'];
}
if (!empty($field['fields'])) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$result = array_merge($result, $this->getFieldValues($field['fields']));
}
}
return $result;
} | [
"protected",
"function",
"getFieldValues",
"(",
"$",
"fields",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"id",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'value'"... | Returns the set of values directly assigned to the field definitions.
These take precedence over default values
@param array[] $fields
@return array An array of values keyed by the form field names.
An array of values keyed by the form field names. | [
"Returns",
"the",
"set",
"of",
"values",
"directly",
"assigned",
"to",
"the",
"field",
"definitions",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L475-L488 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.getSubmittedValue | protected function getSubmittedValue($name, $default = null)
{
if (empty($this->submittedValues)) {
$this->setSubmittedValues();
}
return array_key_exists($name, $this->submittedValues) ? $this->submittedValues[$name] : $default;
} | php | protected function getSubmittedValue($name, $default = null)
{
if (empty($this->submittedValues)) {
$this->setSubmittedValues();
}
return array_key_exists($name, $this->submittedValues) ? $this->submittedValues[$name] : $default;
} | [
"protected",
"function",
"getSubmittedValue",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"submittedValues",
")",
")",
"{",
"$",
"this",
"->",
"setSubmittedValues",
"(",
")",
";",
"}",
"retu... | Returns a submitted value.
@param string $name
The name of the value to return
@param string|null $default
The default to return when this value was not submitted.
@return string|null
The submitted value, or the default if the value was not submitted. | [
"Returns",
"a",
"submitted",
"value",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L512-L518 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.getFields | public function getFields()
{
if (empty($this->fields)) {
$this->fields = $this->getFieldDefinitions();
$this->fields = $this->formHelper->addMetaField($this->fields);
}
return $this->fields;
} | php | public function getFields()
{
if (empty($this->fields)) {
$this->fields = $this->getFieldDefinitions();
$this->fields = $this->formHelper->addMetaField($this->fields);
}
return $this->fields;
} | [
"public",
"function",
"getFields",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"fields",
")",
")",
"{",
"$",
"this",
"->",
"fields",
"=",
"$",
"this",
"->",
"getFieldDefinitions",
"(",
")",
";",
"$",
"this",
"->",
"fields",
"=",
"$",... | Returns a definition of the form fields.
This should NOT include any:
- Submit or cancel buttons. These are often added by the webshop software
in their specific way.
- Tokens, form-id's or other (hidden) fields used by the webshop software
to protect against certain attacks or to facilitate internal form
processing.
This is a recursive, keyed array defining each form field. The key
defines the name of the form field, to be used for the name, and possibly
id, attribute. The values are a keyed array, that can have the following
keys:
- type: (required, string) fieldset, details, text, email, password,
date, textarea, select, radio, checkbox, markup.
- legend/summary: (string) human readable title for a fieldset/details.
- label: (string) human readable label, legend or summary.
- description: (string) human readable help text.
- value: (string) the value for the form field.
- attributes: (array) keyed array with other, possibly html5, attributes
to be rendered. Possible keys include e.g:
- size
- class
- required: (bool) whether the field is required.
- fields: (array) If the type = 'fieldset' or 'details', this value
defines the (possibly recursive) fields of a fieldset/details element.
- options: (array) If the type = checkbox, select or radio, this value
contains the options as a keyed array, the keys being the value to
submit if that choice is selected and the value being the label to
show.
Do NOT override this method, instead override getFieldDefinitions().
@return array[]
The definition of the form. | [
"Returns",
"a",
"definition",
"of",
"the",
"form",
"fields",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L625-L632 | train |
SIELOnline/libAcumulus | src/Helpers/Form.php | Form.addIfIsset | protected function addIfIsset(array &$target, $key, array $source)
{
if (isset($source[$key])) {
$target[$key] = $source[$key];
return true;
}
return false;
} | php | protected function addIfIsset(array &$target, $key, array $source)
{
if (isset($source[$key])) {
$target[$key] = $source[$key];
return true;
}
return false;
} | [
"protected",
"function",
"addIfIsset",
"(",
"array",
"&",
"$",
"target",
",",
"$",
"key",
",",
"array",
"$",
"source",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"source",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"target",
"[",
"$",
"key",
"]",
"... | Helper method to copy a value from one array to another array.
@param array $target
@param string $key
@param array $source
@return bool
True if the value is set and has been copied, false otherwise. | [
"Helper",
"method",
"to",
"copy",
"a",
"value",
"from",
"one",
"array",
"to",
"another",
"array",
"."
] | 82f8d6c9c4929c41948c97d6cfdfac3f27c37255 | https://github.com/SIELOnline/libAcumulus/blob/82f8d6c9c4929c41948c97d6cfdfac3f27c37255/src/Helpers/Form.php#L709-L716 | train |
php-cache/cache | src/Encryption/EncryptedItemDecorator.php | EncryptedItemDecorator.transform | private function transform(array $item)
{
$value = static::jsonDeArmor($item['value']);
if ($item['type'] === 'object' || $item['type'] === 'array') {
return unserialize($value);
}
settype($value, $item['type']);
return $value;
} | php | private function transform(array $item)
{
$value = static::jsonDeArmor($item['value']);
if ($item['type'] === 'object' || $item['type'] === 'array') {
return unserialize($value);
}
settype($value, $item['type']);
return $value;
} | [
"private",
"function",
"transform",
"(",
"array",
"$",
"item",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"jsonDeArmor",
"(",
"$",
"item",
"[",
"'value'",
"]",
")",
";",
"if",
"(",
"$",
"item",
"[",
"'type'",
"]",
"===",
"'object'",
"||",
"$",
"i... | Transform value back to it original type.
@param array $item
@return mixed | [
"Transform",
"value",
"back",
"to",
"it",
"original",
"type",
"."
] | 5f7543f58b43714d708b67b233869e4b2ecae9c8 | https://github.com/php-cache/cache/blob/5f7543f58b43714d708b67b233869e4b2ecae9c8/src/Encryption/EncryptedItemDecorator.php#L159-L170 | train |
php-cache/cache | src/Adapter/Redis/RedisCachePool.php | RedisCachePool.clearAllObjectsFromCacheCluster | protected function clearAllObjectsFromCacheCluster()
{
$nodes = $this->cache->_masters();
foreach ($nodes as $node) {
if (!$this->cache->flushDB($node)) {
return false;
}
}
return true;
} | php | protected function clearAllObjectsFromCacheCluster()
{
$nodes = $this->cache->_masters();
foreach ($nodes as $node) {
if (!$this->cache->flushDB($node)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"clearAllObjectsFromCacheCluster",
"(",
")",
"{",
"$",
"nodes",
"=",
"$",
"this",
"->",
"cache",
"->",
"_masters",
"(",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"... | Clear all objects from all nodes in the cluster.
@return bool false if error | [
"Clear",
"all",
"objects",
"from",
"all",
"nodes",
"in",
"the",
"cluster",
"."
] | 5f7543f58b43714d708b67b233869e4b2ecae9c8 | https://github.com/php-cache/cache/blob/5f7543f58b43714d708b67b233869e4b2ecae9c8/src/Adapter/Redis/RedisCachePool.php#L93-L104 | train |
php-cache/cache | src/Adapter/PHPArray/ArrayCachePool.php | ArrayCachePool.cacheToolkit | private function cacheToolkit($keys, $value = null, $unset = false)
{
$element = &$this->cache;
while ($keys && ($key = array_shift($keys))) {
if (!$keys && is_null($value) && $unset) {
unset($element[$key]);
unset($element);
$element = null;
} else {
$element =&$element[$key];
}
}
if (!$unset && !is_null($value)) {
$element = $value;
}
return $element;
} | php | private function cacheToolkit($keys, $value = null, $unset = false)
{
$element = &$this->cache;
while ($keys && ($key = array_shift($keys))) {
if (!$keys && is_null($value) && $unset) {
unset($element[$key]);
unset($element);
$element = null;
} else {
$element =&$element[$key];
}
}
if (!$unset && !is_null($value)) {
$element = $value;
}
return $element;
} | [
"private",
"function",
"cacheToolkit",
"(",
"$",
"keys",
",",
"$",
"value",
"=",
"null",
",",
"$",
"unset",
"=",
"false",
")",
"{",
"$",
"element",
"=",
"&",
"$",
"this",
"->",
"cache",
";",
"while",
"(",
"$",
"keys",
"&&",
"(",
"$",
"key",
"=",
... | Used to manipulate cached data by extracting, inserting or deleting value.
@param array $keys
@param null|mixed $value
@param bool $unset
@return mixed | [
"Used",
"to",
"manipulate",
"cached",
"data",
"by",
"extracting",
"inserting",
"or",
"deleting",
"value",
"."
] | 5f7543f58b43714d708b67b233869e4b2ecae9c8 | https://github.com/php-cache/cache/blob/5f7543f58b43714d708b67b233869e4b2ecae9c8/src/Adapter/PHPArray/ArrayCachePool.php#L211-L230 | train |
php-cache/cache | src/Adapter/PHPArray/ArrayCachePool.php | ArrayCachePool.cacheIsset | private function cacheIsset($keys)
{
$has = false;
$array = $this->cache;
foreach ($keys as $key) {
if ($has = array_key_exists($key, $array)) {
$array = $array[$key];
}
}
if (is_array($array)) {
$has = $has && array_key_exists(0, $array);
}
return $has;
} | php | private function cacheIsset($keys)
{
$has = false;
$array = $this->cache;
foreach ($keys as $key) {
if ($has = array_key_exists($key, $array)) {
$array = $array[$key];
}
}
if (is_array($array)) {
$has = $has && array_key_exists(0, $array);
}
return $has;
} | [
"private",
"function",
"cacheIsset",
"(",
"$",
"keys",
")",
"{",
"$",
"has",
"=",
"false",
";",
"$",
"array",
"=",
"$",
"this",
"->",
"cache",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"has",
"=",
"array_key_ex... | Checking if given keys exists and is valid.
@param array $keys
@return bool | [
"Checking",
"if",
"given",
"keys",
"exists",
"and",
"is",
"valid",
"."
] | 5f7543f58b43714d708b67b233869e4b2ecae9c8 | https://github.com/php-cache/cache/blob/5f7543f58b43714d708b67b233869e4b2ecae9c8/src/Adapter/PHPArray/ArrayCachePool.php#L239-L255 | train |
irazasyed/laravel-gamp | src/LaravelGAMPServiceProvider.php | LaravelGAMPServiceProvider.registerAnalytics | protected function registerAnalytics(Application $app)
{
$app->singleton('gamp', function ($app) {
$config = $app['config'];
$analytics = new Analytics($config->get('gamp.is_ssl', false), $config->get('gamp.is_disabled', false));
$analytics->setProtocolVersion($config->get('gamp.protocol_version', 1))
->setTrackingId($config->get('gamp.tracking_id'));
if ($config->get('gamp.anonymize_ip', false)) {
$analytics->setAnonymizeIp('1');
}
if ($config->get('gamp.async_requests', false)) {
$analytics->setAsyncRequest(true);
}
return $analytics;
});
$app->alias('gamp', Analytics::class);
} | php | protected function registerAnalytics(Application $app)
{
$app->singleton('gamp', function ($app) {
$config = $app['config'];
$analytics = new Analytics($config->get('gamp.is_ssl', false), $config->get('gamp.is_disabled', false));
$analytics->setProtocolVersion($config->get('gamp.protocol_version', 1))
->setTrackingId($config->get('gamp.tracking_id'));
if ($config->get('gamp.anonymize_ip', false)) {
$analytics->setAnonymizeIp('1');
}
if ($config->get('gamp.async_requests', false)) {
$analytics->setAsyncRequest(true);
}
return $analytics;
});
$app->alias('gamp', Analytics::class);
} | [
"protected",
"function",
"registerAnalytics",
"(",
"Application",
"$",
"app",
")",
"{",
"$",
"app",
"->",
"singleton",
"(",
"'gamp'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"config",
"=",
"$",
"app",
"[",
"'config'",
"]",
";",
"$",
"analytics... | Initialize Analytics Library with Default Config.
@param \Illuminate\Contracts\Container\Container $app | [
"Initialize",
"Analytics",
"Library",
"with",
"Default",
"Config",
"."
] | d935785977bc04930ea58cceb4f023bf36ecae71 | https://github.com/irazasyed/laravel-gamp/blob/d935785977bc04930ea58cceb4f023bf36ecae71/src/LaravelGAMPServiceProvider.php#L59-L81 | train |
dpods/plaid-api-php-client | src/Api/AssetReport.php | AssetReport.create | public function create($accessTokens, $daysRequested, $options = [])
{
return $this->client()->post('/asset_report/create', [
'access_tokens' => $accessTokens,
'days_requested' => $daysRequested,
'options' => $options,
]);
} | php | public function create($accessTokens, $daysRequested, $options = [])
{
return $this->client()->post('/asset_report/create', [
'access_tokens' => $accessTokens,
'days_requested' => $daysRequested,
'options' => $options,
]);
} | [
"public",
"function",
"create",
"(",
"$",
"accessTokens",
",",
"$",
"daysRequested",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"(",
")",
"->",
"post",
"(",
"'/asset_report/create'",
",",
"[",
"'access_tokens'",
... | Creates an Asset Report with all accounts linked to each Item associated with passed accessTokens.
@link https://plaid.com/docs/#create-asset-report-request
@param array $accessTokens An array of access tokens, one token for each Item to be included in the Asset Report.
@param int $daysRequested Days of transaction history requested to be included in the Asset Report.
@param object $options Optional. See docs for list of options. | [
"Creates",
"an",
"Asset",
"Report",
"with",
"all",
"accounts",
"linked",
"to",
"each",
"Item",
"associated",
"with",
"passed",
"accessTokens",
"."
] | 1c3da929ef87ef96914bd554567510bd32bc6f1d | https://github.com/dpods/plaid-api-php-client/blob/1c3da929ef87ef96914bd554567510bd32bc6f1d/src/Api/AssetReport.php#L19-L26 | train |
dpods/plaid-api-php-client | src/Api/AssetReport.php | AssetReport.refresh | public function refresh($assetReportToken, $daysRequested = null, $options = [])
{
$data = ['asset_report_token' => $assetReportToken];
if (!is_null($daysRequested)) {
$data['days_requested'] = $daysRequested;
}
if (!empty($options)) {
$data['options'] = $options;
}
return $this->client()->post('/asset_report/refresh', $data);
} | php | public function refresh($assetReportToken, $daysRequested = null, $options = [])
{
$data = ['asset_report_token' => $assetReportToken];
if (!is_null($daysRequested)) {
$data['days_requested'] = $daysRequested;
}
if (!empty($options)) {
$data['options'] = $options;
}
return $this->client()->post('/asset_report/refresh', $data);
} | [
"public",
"function",
"refresh",
"(",
"$",
"assetReportToken",
",",
"$",
"daysRequested",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"[",
"'asset_report_token'",
"=>",
"$",
"assetReportToken",
"]",
";",
"if",
"(",
"!",
... | Refresh a previously created Asset Report.
@link https://plaid.com/docs/#refreshing-an-asset-report
@param string $assetReportToken The token returned in create or filter response.
@param int $daysRequested Override the days_requested on previously created/filtered report.
@param array $options Override the options array on previously created/filtered report. | [
"Refresh",
"a",
"previously",
"created",
"Asset",
"Report",
"."
] | 1c3da929ef87ef96914bd554567510bd32bc6f1d | https://github.com/dpods/plaid-api-php-client/blob/1c3da929ef87ef96914bd554567510bd32bc6f1d/src/Api/AssetReport.php#L93-L106 | train |
Sibyx/phpGPX | src/phpGPX/Models/Stats.php | Stats.reset | public function reset()
{
$this->distance = null;
$this->averageSpeed = null;
$this->averagePace = null;
$this->minAltitude = null;
$this->maxAltitude = null;
$this->cumulativeElevationGain = null;
$this->cumulativeElevationLoss = null;
$this->startedAt = null;
$this->finishedAt = null;
} | php | public function reset()
{
$this->distance = null;
$this->averageSpeed = null;
$this->averagePace = null;
$this->minAltitude = null;
$this->maxAltitude = null;
$this->cumulativeElevationGain = null;
$this->cumulativeElevationLoss = null;
$this->startedAt = null;
$this->finishedAt = null;
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"distance",
"=",
"null",
";",
"$",
"this",
"->",
"averageSpeed",
"=",
"null",
";",
"$",
"this",
"->",
"averagePace",
"=",
"null",
";",
"$",
"this",
"->",
"minAltitude",
"=",
"null",
";"... | Reset all stats | [
"Reset",
"all",
"stats"
] | 13a5b2810915c5cc055f46abd7938419acf14124 | https://github.com/Sibyx/phpGPX/blob/13a5b2810915c5cc055f46abd7938419acf14124/src/phpGPX/Models/Stats.php#L82-L93 | train |
Sibyx/phpGPX | src/phpGPX/phpGPX.php | phpGPX.parse | public static function parse($xml)
{
$xml = simplexml_load_string($xml);
$gpx = new GpxFile();
// Parse creator
$gpx->creator = isset($xml['creator']) ? (string)$xml['creator'] : null;
// Parse metadata
$gpx->metadata = isset($xml->metadata) ? MetadataParser::parse($xml->metadata) : null;
// Parse waypoints
$gpx->waypoints = isset($xml->wpt) ? WaypointParser::parse($xml->wpt) : [];
// Parse tracks
$gpx->tracks = isset($xml->trk) ? TrackParser::parse($xml->trk) : [];
// Parse routes
$gpx->routes = isset($xml->rte) ? RouteParser::parse($xml->rte) : [];
return $gpx;
} | php | public static function parse($xml)
{
$xml = simplexml_load_string($xml);
$gpx = new GpxFile();
// Parse creator
$gpx->creator = isset($xml['creator']) ? (string)$xml['creator'] : null;
// Parse metadata
$gpx->metadata = isset($xml->metadata) ? MetadataParser::parse($xml->metadata) : null;
// Parse waypoints
$gpx->waypoints = isset($xml->wpt) ? WaypointParser::parse($xml->wpt) : [];
// Parse tracks
$gpx->tracks = isset($xml->trk) ? TrackParser::parse($xml->trk) : [];
// Parse routes
$gpx->routes = isset($xml->rte) ? RouteParser::parse($xml->rte) : [];
return $gpx;
} | [
"public",
"static",
"function",
"parse",
"(",
"$",
"xml",
")",
"{",
"$",
"xml",
"=",
"simplexml_load_string",
"(",
"$",
"xml",
")",
";",
"$",
"gpx",
"=",
"new",
"GpxFile",
"(",
")",
";",
"// Parse creator",
"$",
"gpx",
"->",
"creator",
"=",
"isset",
... | Parse GPX data string.
@param $xml
@return GpxFile | [
"Parse",
"GPX",
"data",
"string",
"."
] | 13a5b2810915c5cc055f46abd7938419acf14124 | https://github.com/Sibyx/phpGPX/blob/13a5b2810915c5cc055f46abd7938419acf14124/src/phpGPX/phpGPX.php#L112-L134 | train |
Sibyx/phpGPX | src/phpGPX/Models/GpxFile.php | GpxFile.toXML | public function toXML()
{
$document = new \DOMDocument("1.0", 'UTF-8');
$gpx = $document->createElementNS("http://www.topografix.com/GPX/1/1", "gpx");
$gpx->setAttribute("version", "1.1");
$gpx->setAttribute("creator", $this->creator ? $this->creator : phpGPX::getSignature());
ExtensionParser::$usedNamespaces = [];
if (!empty($this->metadata)) {
$gpx->appendChild(MetadataParser::toXML($this->metadata, $document));
}
foreach ($this->waypoints as $waypoint) {
$gpx->appendChild(PointParser::toXML($waypoint, $document));
}
foreach ($this->routes as $route) {
$gpx->appendChild(RouteParser::toXML($route, $document));
}
foreach ($this->tracks as $track) {
$gpx->appendChild(TrackParser::toXML($track, $document));
}
if (!empty($this->extensions)) {
$gpx->appendChild(ExtensionParser::toXML($this->extensions, $document));
}
// Namespaces
$schemaLocationArray = [
'http://www.topografix.com/GPX/1/1',
'http://www.topografix.com/GPX/1/1/gpx.xsd'
];
foreach (ExtensionParser::$usedNamespaces as $usedNamespace) {
$gpx->setAttributeNS(
"http://www.w3.org/2000/xmlns/",
sprintf("xmlns:%s", $usedNamespace['prefix']),
$usedNamespace['namespace']
);
$schemaLocationArray[] = $usedNamespace['namespace'];
$schemaLocationArray[] = $usedNamespace['xsd'];
}
$gpx->setAttributeNS(
'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation',
implode(" ", $schemaLocationArray)
);
$document->appendChild($gpx);
if (phpGPX::$PRETTY_PRINT) {
$document->formatOutput = true;
$document->preserveWhiteSpace = true;
}
return $document;
} | php | public function toXML()
{
$document = new \DOMDocument("1.0", 'UTF-8');
$gpx = $document->createElementNS("http://www.topografix.com/GPX/1/1", "gpx");
$gpx->setAttribute("version", "1.1");
$gpx->setAttribute("creator", $this->creator ? $this->creator : phpGPX::getSignature());
ExtensionParser::$usedNamespaces = [];
if (!empty($this->metadata)) {
$gpx->appendChild(MetadataParser::toXML($this->metadata, $document));
}
foreach ($this->waypoints as $waypoint) {
$gpx->appendChild(PointParser::toXML($waypoint, $document));
}
foreach ($this->routes as $route) {
$gpx->appendChild(RouteParser::toXML($route, $document));
}
foreach ($this->tracks as $track) {
$gpx->appendChild(TrackParser::toXML($track, $document));
}
if (!empty($this->extensions)) {
$gpx->appendChild(ExtensionParser::toXML($this->extensions, $document));
}
// Namespaces
$schemaLocationArray = [
'http://www.topografix.com/GPX/1/1',
'http://www.topografix.com/GPX/1/1/gpx.xsd'
];
foreach (ExtensionParser::$usedNamespaces as $usedNamespace) {
$gpx->setAttributeNS(
"http://www.w3.org/2000/xmlns/",
sprintf("xmlns:%s", $usedNamespace['prefix']),
$usedNamespace['namespace']
);
$schemaLocationArray[] = $usedNamespace['namespace'];
$schemaLocationArray[] = $usedNamespace['xsd'];
}
$gpx->setAttributeNS(
'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation',
implode(" ", $schemaLocationArray)
);
$document->appendChild($gpx);
if (phpGPX::$PRETTY_PRINT) {
$document->formatOutput = true;
$document->preserveWhiteSpace = true;
}
return $document;
} | [
"public",
"function",
"toXML",
"(",
")",
"{",
"$",
"document",
"=",
"new",
"\\",
"DOMDocument",
"(",
"\"1.0\"",
",",
"'UTF-8'",
")",
";",
"$",
"gpx",
"=",
"$",
"document",
"->",
"createElementNS",
"(",
"\"http://www.topografix.com/GPX/1/1\"",
",",
"\"gpx\"",
... | Create XML representation of GPX file.
@return \DOMDocument | [
"Create",
"XML",
"representation",
"of",
"GPX",
"file",
"."
] | 13a5b2810915c5cc055f46abd7938419acf14124 | https://github.com/Sibyx/phpGPX/blob/13a5b2810915c5cc055f46abd7938419acf14124/src/phpGPX/Models/GpxFile.php#L103-L163 | train |
Sibyx/phpGPX | src/phpGPX/Models/GpxFile.php | GpxFile.save | public function save($path, $format)
{
switch ($format) {
case phpGPX::XML_FORMAT:
$document = $this->toXML();
$document->save($path);
break;
case phpGPX::JSON_FORMAT:
file_put_contents($path, $this->toJSON());
break;
default:
throw new \RuntimeException("Unsupported file format!");
};
} | php | public function save($path, $format)
{
switch ($format) {
case phpGPX::XML_FORMAT:
$document = $this->toXML();
$document->save($path);
break;
case phpGPX::JSON_FORMAT:
file_put_contents($path, $this->toJSON());
break;
default:
throw new \RuntimeException("Unsupported file format!");
};
} | [
"public",
"function",
"save",
"(",
"$",
"path",
",",
"$",
"format",
")",
"{",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"phpGPX",
"::",
"XML_FORMAT",
":",
"$",
"document",
"=",
"$",
"this",
"->",
"toXML",
"(",
")",
";",
"$",
"document",
"->",... | Save data to file according to selected format.
@param string $path
@param string $format | [
"Save",
"data",
"to",
"file",
"according",
"to",
"selected",
"format",
"."
] | 13a5b2810915c5cc055f46abd7938419acf14124 | https://github.com/Sibyx/phpGPX/blob/13a5b2810915c5cc055f46abd7938419acf14124/src/phpGPX/Models/GpxFile.php#L170-L183 | train |
Sibyx/phpGPX | src/phpGPX/Parsers/BoundsParser.php | BoundsParser.parse | public static function parse(\SimpleXMLElement $node)
{
if ($node->getName() != self::$tagName) {
return null;
}
$bounds = new Bounds();
$bounds->minLatitude = isset($node['minlat']) ? (float) $node['minlat'] : null;
$bounds->minLongitude = isset($node['minlon']) ? (float) $node['minlon'] : null;
$bounds->maxLatitude = isset($node['maxlat']) ? (float) $node['maxlat'] : null;
$bounds->maxLongitude = isset($node['maxlon']) ? (float) $node['maxlon'] : null;
return $bounds;
} | php | public static function parse(\SimpleXMLElement $node)
{
if ($node->getName() != self::$tagName) {
return null;
}
$bounds = new Bounds();
$bounds->minLatitude = isset($node['minlat']) ? (float) $node['minlat'] : null;
$bounds->minLongitude = isset($node['minlon']) ? (float) $node['minlon'] : null;
$bounds->maxLatitude = isset($node['maxlat']) ? (float) $node['maxlat'] : null;
$bounds->maxLongitude = isset($node['maxlon']) ? (float) $node['maxlon'] : null;
return $bounds;
} | [
"public",
"static",
"function",
"parse",
"(",
"\\",
"SimpleXMLElement",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"getName",
"(",
")",
"!=",
"self",
"::",
"$",
"tagName",
")",
"{",
"return",
"null",
";",
"}",
"$",
"bounds",
"=",
"new",
"... | Parse data from XML.
@param \SimpleXMLElement $node
@return Bounds|null | [
"Parse",
"data",
"from",
"XML",
"."
] | 13a5b2810915c5cc055f46abd7938419acf14124 | https://github.com/Sibyx/phpGPX/blob/13a5b2810915c5cc055f46abd7938419acf14124/src/phpGPX/Parsers/BoundsParser.php#L24-L38 | train |
Sibyx/phpGPX | src/phpGPX/Parsers/BoundsParser.php | BoundsParser.toXML | public static function toXML(Bounds $bounds, \DOMDocument &$document)
{
$node = $document->createElement(self::$tagName);
if (!is_null($bounds->minLatitude)) {
$node->setAttribute('minlat', $bounds->minLatitude);
}
if (!is_null($bounds->minLongitude)) {
$node->setAttribute('minlon', $bounds->minLongitude);
}
if (!is_null($bounds->maxLatitude)) {
$node->setAttribute('maxlat', $bounds->maxLatitude);
}
if (!is_null($bounds->maxLongitude)) {
$node->setAttribute('maxlon', $bounds->maxLongitude);
}
return $node;
} | php | public static function toXML(Bounds $bounds, \DOMDocument &$document)
{
$node = $document->createElement(self::$tagName);
if (!is_null($bounds->minLatitude)) {
$node->setAttribute('minlat', $bounds->minLatitude);
}
if (!is_null($bounds->minLongitude)) {
$node->setAttribute('minlon', $bounds->minLongitude);
}
if (!is_null($bounds->maxLatitude)) {
$node->setAttribute('maxlat', $bounds->maxLatitude);
}
if (!is_null($bounds->maxLongitude)) {
$node->setAttribute('maxlon', $bounds->maxLongitude);
}
return $node;
} | [
"public",
"static",
"function",
"toXML",
"(",
"Bounds",
"$",
"bounds",
",",
"\\",
"DOMDocument",
"&",
"$",
"document",
")",
"{",
"$",
"node",
"=",
"$",
"document",
"->",
"createElement",
"(",
"self",
"::",
"$",
"tagName",
")",
";",
"if",
"(",
"!",
"i... | Create XML representation.
@param Bounds $bounds
@param \DOMDocument $document
@return \DOMElement | [
"Create",
"XML",
"representation",
"."
] | 13a5b2810915c5cc055f46abd7938419acf14124 | https://github.com/Sibyx/phpGPX/blob/13a5b2810915c5cc055f46abd7938419acf14124/src/phpGPX/Parsers/BoundsParser.php#L46-L67 | train |
Sibyx/phpGPX | src/phpGPX/Helpers/GeoHelper.php | GeoHelper.getDistance | public static function getDistance(Point $point1, Point $point2)
{
$latFrom = deg2rad($point1->latitude);
$lonFrom = deg2rad($point1->longitude);
$latTo = deg2rad($point2->latitude);
$lonTo = deg2rad($point2->longitude);
$lonDelta = $lonTo - $lonFrom;
$a = pow(cos($latTo) * sin($lonDelta), 2) + pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2);
$b = sin($latFrom) * sin($latTo) + cos($latFrom) * cos($latTo) * cos($lonDelta);
$angle = atan2(sqrt($a), $b);
return $angle * self::EARTH_RADIUS;
} | php | public static function getDistance(Point $point1, Point $point2)
{
$latFrom = deg2rad($point1->latitude);
$lonFrom = deg2rad($point1->longitude);
$latTo = deg2rad($point2->latitude);
$lonTo = deg2rad($point2->longitude);
$lonDelta = $lonTo - $lonFrom;
$a = pow(cos($latTo) * sin($lonDelta), 2) + pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2);
$b = sin($latFrom) * sin($latTo) + cos($latFrom) * cos($latTo) * cos($lonDelta);
$angle = atan2(sqrt($a), $b);
return $angle * self::EARTH_RADIUS;
} | [
"public",
"static",
"function",
"getDistance",
"(",
"Point",
"$",
"point1",
",",
"Point",
"$",
"point2",
")",
"{",
"$",
"latFrom",
"=",
"deg2rad",
"(",
"$",
"point1",
"->",
"latitude",
")",
";",
"$",
"lonFrom",
"=",
"deg2rad",
"(",
"$",
"point1",
"->",... | Returns distance in meters between two Points according to GPX coordinates.
@see Point
@param Point $point1
@param Point $point2
@return float | [
"Returns",
"distance",
"in",
"meters",
"between",
"two",
"Points",
"according",
"to",
"GPX",
"coordinates",
"."
] | 13a5b2810915c5cc055f46abd7938419acf14124 | https://github.com/Sibyx/phpGPX/blob/13a5b2810915c5cc055f46abd7938419acf14124/src/phpGPX/Helpers/GeoHelper.php#L27-L40 | train |
tylercd100/lern | src/Components/Notifier.php | Notifier.getMessage | public function getMessage(Exception $e)
{
$msg = $this->getMessageViaView($e);
if ($msg === false) {
$msg = $this->getMessageViaCallback($e);
}
if ($msg === false) {
$msg = $this->getMessageViaDefault($e);
}
return $msg;
} | php | public function getMessage(Exception $e)
{
$msg = $this->getMessageViaView($e);
if ($msg === false) {
$msg = $this->getMessageViaCallback($e);
}
if ($msg === false) {
$msg = $this->getMessageViaDefault($e);
}
return $msg;
} | [
"public",
"function",
"getMessage",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"$",
"this",
"->",
"getMessageViaView",
"(",
"$",
"e",
")",
";",
"if",
"(",
"$",
"msg",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"$",
"this",
"->",
"getM... | Returns the result of the message closure
@param Exception $e The Exception instance that you want to build the message around
@return string The message string | [
"Returns",
"the",
"result",
"of",
"the",
"message",
"closure"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Notifier.php#L76-L89 | train |
tylercd100/lern | src/Components/Notifier.php | Notifier.getMessageViaDefault | public function getMessageViaDefault(Exception $e)
{
$msg = get_class($e)." was thrown! \n".$e->getMessage();
if ($this->config['includeExceptionStackTrace'] === true) {
$msg .= "\n\n".$e->getTraceAsString();
}
return $msg;
} | php | public function getMessageViaDefault(Exception $e)
{
$msg = get_class($e)." was thrown! \n".$e->getMessage();
if ($this->config['includeExceptionStackTrace'] === true) {
$msg .= "\n\n".$e->getTraceAsString();
}
return $msg;
} | [
"public",
"function",
"getMessageViaDefault",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"get_class",
"(",
"$",
"e",
")",
".",
"\" was thrown! \\n\"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",... | Gets a basic Exception message
@param Exception $e The Exception instance that you want to build the message around
@return String Returns the message string | [
"Gets",
"a",
"basic",
"Exception",
"message"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Notifier.php#L96-L103 | train |
tylercd100/lern | src/Components/Notifier.php | Notifier.getMessageViaCallback | public function getMessageViaCallback(Exception $e)
{
if (is_callable($this->messageCb)) {
return $this->messageCb->__invoke($e);
}
return false;
} | php | public function getMessageViaCallback(Exception $e)
{
if (is_callable($this->messageCb)) {
return $this->messageCb->__invoke($e);
}
return false;
} | [
"public",
"function",
"getMessageViaCallback",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"messageCb",
")",
")",
"{",
"return",
"$",
"this",
"->",
"messageCb",
"->",
"__invoke",
"(",
"$",
"e",
")",
";",
"}",... | Gets the Exception message using a callback if it is set
@param Exception $e The Exception instance that you want to build the message around
@return String|false Returns the message string or false | [
"Gets",
"the",
"Exception",
"message",
"using",
"a",
"callback",
"if",
"it",
"is",
"set"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Notifier.php#L110-L116 | train |
tylercd100/lern | src/Components/Notifier.php | Notifier.getMessageViaView | public function getMessageViaView(Exception $e)
{
$path = @$this->config["view"];
if (!empty($path) && View::exists($path)) {
return View::make($path, [
"exception" => $e,
"url" => Request::url(),
"method" => Request::method(),
"input" => Input::all(),
"user" => Auth::user(),
])->render();
}
return false;
} | php | public function getMessageViaView(Exception $e)
{
$path = @$this->config["view"];
if (!empty($path) && View::exists($path)) {
return View::make($path, [
"exception" => $e,
"url" => Request::url(),
"method" => Request::method(),
"input" => Input::all(),
"user" => Auth::user(),
])->render();
}
return false;
} | [
"public",
"function",
"getMessageViaView",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"path",
"=",
"@",
"$",
"this",
"->",
"config",
"[",
"\"view\"",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"path",
")",
"&&",
"View",
"::",
"exists",
"(",
"$",
... | Gets the Exception message using a Laravel view file
@param Exception $e The Exception instance that you want to build the message around
@return String|false Returns the message string or false | [
"Gets",
"the",
"Exception",
"message",
"using",
"a",
"Laravel",
"view",
"file"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Notifier.php#L123-L136 | train |
tylercd100/lern | src/Components/Notifier.php | Notifier.getSubject | public function getSubject(Exception $e)
{
if (is_callable($this->subjectCb)) {
return $this->subjectCb->__invoke($e);
} else {
return get_class($e);
}
} | php | public function getSubject(Exception $e)
{
if (is_callable($this->subjectCb)) {
return $this->subjectCb->__invoke($e);
} else {
return get_class($e);
}
} | [
"public",
"function",
"getSubject",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"subjectCb",
")",
")",
"{",
"return",
"$",
"this",
"->",
"subjectCb",
"->",
"__invoke",
"(",
"$",
"e",
")",
";",
"}",
"else",
... | Returns the result of the subject closure
@param Exception $e The Exception instance that you want to build the subject around
@return string The subject string | [
"Returns",
"the",
"result",
"of",
"the",
"subject",
"closure"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Notifier.php#L154-L161 | train |
tylercd100/lern | src/Components/Notifier.php | Notifier.getContext | public function getContext(Exception $e, $context = [])
{
//This needs a better solution. How do I set specific context needs for different drivers?
if (in_array('pushover', $this->config['drivers'])) {
$context['sound'] = $this->config['pushover']['sound'];
}
// Call the callback or return the default
if (is_callable($this->contextCb)) {
return $this->contextCb->__invoke($e, $context);
} else {
return $context;
}
} | php | public function getContext(Exception $e, $context = [])
{
//This needs a better solution. How do I set specific context needs for different drivers?
if (in_array('pushover', $this->config['drivers'])) {
$context['sound'] = $this->config['pushover']['sound'];
}
// Call the callback or return the default
if (is_callable($this->contextCb)) {
return $this->contextCb->__invoke($e, $context);
} else {
return $context;
}
} | [
"public",
"function",
"getContext",
"(",
"Exception",
"$",
"e",
",",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"//This needs a better solution. How do I set specific context needs for different drivers?\r",
"if",
"(",
"in_array",
"(",
"'pushover'",
",",
"$",
"this",
"-... | Returns the result of the context closure
@param Exception $e The Exception instance that you want to build the context around
@return array The context array | [
"Returns",
"the",
"result",
"of",
"the",
"context",
"closure"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Notifier.php#L179-L192 | train |
tylercd100/lern | src/Components/Notifier.php | Notifier.send | public function send(Exception $e, array $context = [])
{
if ($this->shouldntHandle($e)) {
return false;
}
$message = $this->getMessage($e);
$subject = $this->getSubject($e);
$context = $this->getContext($e, $context);
try {
$notify = new Notify($this->config, $this->log, $subject);
$level = (array_key_exists('log_level', $this->config) && !empty($this->config['log_level']))
? $this->config['log_level']
: 'critical';
$notify->{$level}($message, $context);
Cache::forever($this->getCacheKey($e), Carbon::now());
return true;
} catch (Exception $e) {
$code = (is_int($e->getCode()) ? $e->getCode() : 0);
throw new NotifierFailedException($e->getMessage(), $code, $e);
}
} | php | public function send(Exception $e, array $context = [])
{
if ($this->shouldntHandle($e)) {
return false;
}
$message = $this->getMessage($e);
$subject = $this->getSubject($e);
$context = $this->getContext($e, $context);
try {
$notify = new Notify($this->config, $this->log, $subject);
$level = (array_key_exists('log_level', $this->config) && !empty($this->config['log_level']))
? $this->config['log_level']
: 'critical';
$notify->{$level}($message, $context);
Cache::forever($this->getCacheKey($e), Carbon::now());
return true;
} catch (Exception $e) {
$code = (is_int($e->getCode()) ? $e->getCode() : 0);
throw new NotifierFailedException($e->getMessage(), $code, $e);
}
} | [
"public",
"function",
"send",
"(",
"Exception",
"$",
"e",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldntHandle",
"(",
"$",
"e",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"message",
"=",
"$",
... | Triggers the Monolog Logger instance to log an error to all handlers
@param Exception $e The exception to use
@param array $context Additional information that you would like to pass to Monolog
@return bool
@throws NotifierFailedException | [
"Triggers",
"the",
"Monolog",
"Logger",
"instance",
"to",
"log",
"an",
"error",
"to",
"all",
"handlers"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Notifier.php#L232-L258 | train |
tylercd100/lern | src/LERN.php | LERN.handle | public function handle(Exception $e)
{
$this->exception = $e;
$this->notify($e);
return $this->record($e);
} | php | public function handle(Exception $e)
{
$this->exception = $e;
$this->notify($e);
return $this->record($e);
} | [
"public",
"function",
"handle",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"exception",
"=",
"$",
"e",
";",
"$",
"this",
"->",
"notify",
"(",
"$",
"e",
")",
";",
"return",
"$",
"this",
"->",
"record",
"(",
"$",
"e",
")",
";",
"}"
... | Will execute record and notify methods
@param Exception $e The exception to use
@return ExceptionModel the recorded Eloquent Model | [
"Will",
"execute",
"record",
"and",
"notify",
"methods"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/LERN.php#L47-L52 | train |
tylercd100/lern | src/LERN.php | LERN.record | public function record(Exception $e)
{
$this->exception = $e;
return $this->recorder->record($e);
} | php | public function record(Exception $e)
{
$this->exception = $e;
return $this->recorder->record($e);
} | [
"public",
"function",
"record",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"exception",
"=",
"$",
"e",
";",
"return",
"$",
"this",
"->",
"recorder",
"->",
"record",
"(",
"$",
"e",
")",
";",
"}"
] | Stores the exception in the database
@param Exception $e The exception to use
@return \Tylercd100\LERN\Models\ExceptionModel|false The recorded Exception as an Eloquent Model | [
"Stores",
"the",
"exception",
"in",
"the",
"database"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/LERN.php#L59-L63 | train |
tylercd100/lern | src/LERN.php | LERN.notify | public function notify(Exception $e)
{
$this->exception = $e;
$this->notifier->send($e);
} | php | public function notify(Exception $e)
{
$this->exception = $e;
$this->notifier->send($e);
} | [
"public",
"function",
"notify",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"exception",
"=",
"$",
"e",
";",
"$",
"this",
"->",
"notifier",
"->",
"send",
"(",
"$",
"e",
")",
";",
"}"
] | Will send the exception to all monolog handlers
@param Exception $e The exception to use
@return void | [
"Will",
"send",
"the",
"exception",
"to",
"all",
"monolog",
"handlers"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/LERN.php#L70-L74 | train |
tylercd100/lern | src/LERN.php | LERN.buildNotifier | protected function buildNotifier(Notifier $notifier = null)
{
$class = config('lern.notify.class');
$class = !empty($class) ? $class : Notifier::class;
if (empty($notifier)) {
$notifier = new $class();
}
if ($notifier instanceof Notifier) {
return $notifier;
} else {
throw new NotifierFailedException("LERN was expecting an instance of ".Notifier::class);
}
} | php | protected function buildNotifier(Notifier $notifier = null)
{
$class = config('lern.notify.class');
$class = !empty($class) ? $class : Notifier::class;
if (empty($notifier)) {
$notifier = new $class();
}
if ($notifier instanceof Notifier) {
return $notifier;
} else {
throw new NotifierFailedException("LERN was expecting an instance of ".Notifier::class);
}
} | [
"protected",
"function",
"buildNotifier",
"(",
"Notifier",
"$",
"notifier",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"config",
"(",
"'lern.notify.class'",
")",
";",
"$",
"class",
"=",
"!",
"empty",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"Noti... | Constructs a Notifier
@param Notifier $notifier
@return Notifier | [
"Constructs",
"a",
"Notifier"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/LERN.php#L174-L186 | train |
tylercd100/lern | src/LERN.php | LERN.buildRecorder | protected function buildRecorder(Recorder $recorder = null)
{
$class = config('lern.record.class');
$class = !empty($class) ? $class : Recorder::class;
if (empty($recorder)) {
$recorder = new $class();
}
if ($recorder instanceof Recorder) {
return $recorder;
} else {
throw new RecorderFailedException("LERN was expecting an instance of ".Recorder::class);
}
} | php | protected function buildRecorder(Recorder $recorder = null)
{
$class = config('lern.record.class');
$class = !empty($class) ? $class : Recorder::class;
if (empty($recorder)) {
$recorder = new $class();
}
if ($recorder instanceof Recorder) {
return $recorder;
} else {
throw new RecorderFailedException("LERN was expecting an instance of ".Recorder::class);
}
} | [
"protected",
"function",
"buildRecorder",
"(",
"Recorder",
"$",
"recorder",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"config",
"(",
"'lern.record.class'",
")",
";",
"$",
"class",
"=",
"!",
"empty",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"Reco... | Constructs a Recorder
@param Recorder $recorder
@return Recorder | [
"Constructs",
"a",
"Recorder"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/LERN.php#L194-L206 | train |
tylercd100/lern | src/Components/Component.php | Component.shouldntHandle | protected function shouldntHandle(Exception $e) {
$dontHandle = array_merge($this->dontHandle, $this->absolutelyDontHandle);
foreach ($dontHandle as $type) {
if ($e instanceof $type) {
return true;
}
}
$sent_at = Cache::get($this->getCacheKey($e));
if (empty($sent_at) || $sent_at->addSeconds(config('lern.ratelimit', 1))->lte(Carbon::now())) {
return false; // The cache is empty or enough time has passed, so lets continue
} else {
return true;
}
} | php | protected function shouldntHandle(Exception $e) {
$dontHandle = array_merge($this->dontHandle, $this->absolutelyDontHandle);
foreach ($dontHandle as $type) {
if ($e instanceof $type) {
return true;
}
}
$sent_at = Cache::get($this->getCacheKey($e));
if (empty($sent_at) || $sent_at->addSeconds(config('lern.ratelimit', 1))->lte(Carbon::now())) {
return false; // The cache is empty or enough time has passed, so lets continue
} else {
return true;
}
} | [
"protected",
"function",
"shouldntHandle",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"dontHandle",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dontHandle",
",",
"$",
"this",
"->",
"absolutelyDontHandle",
")",
";",
"foreach",
"(",
"$",
"dontHandle",
"as",
... | Determine if the exception is in the "do not handle" list.
@param \Exception $e
@return bool | [
"Determine",
"if",
"the",
"exception",
"is",
"in",
"the",
"do",
"not",
"handle",
"list",
"."
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Component.php#L29-L44 | train |
tylercd100/lern | src/Components/Recorder.php | Recorder.record | public function record(Exception $e)
{
if ($this->shouldntHandle($e)) {
return false;
}
$opts = [
'class' => get_class($e),
'file' => $e->getFile(),
'line' => $e->getLine(),
'code' => (is_int($e->getCode()) ? $e->getCode() : 0),
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
];
$configDependant = array_keys($this->config['collect']);
foreach ($configDependant as $key) {
if ($this->canCollect($key)) {
$value = $this->collect($key, $e);
if ($value !== null) {
$opts[$key] = $value;
}
}
}
$class = config('lern.recorder.model');
$class = !empty($class) ? $class : ExceptionModel::class;
$model = new $class();
foreach($opts as $key => $value) {
$model->{$key} = $value;
}
$model->save();
Cache::forever($this->getCacheKey($e), Carbon::now());
return $model;
} | php | public function record(Exception $e)
{
if ($this->shouldntHandle($e)) {
return false;
}
$opts = [
'class' => get_class($e),
'file' => $e->getFile(),
'line' => $e->getLine(),
'code' => (is_int($e->getCode()) ? $e->getCode() : 0),
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
];
$configDependant = array_keys($this->config['collect']);
foreach ($configDependant as $key) {
if ($this->canCollect($key)) {
$value = $this->collect($key, $e);
if ($value !== null) {
$opts[$key] = $value;
}
}
}
$class = config('lern.recorder.model');
$class = !empty($class) ? $class : ExceptionModel::class;
$model = new $class();
foreach($opts as $key => $value) {
$model->{$key} = $value;
}
$model->save();
Cache::forever($this->getCacheKey($e), Carbon::now());
return $model;
} | [
"public",
"function",
"record",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldntHandle",
"(",
"$",
"e",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"opts",
"=",
"[",
"'class'",
"=>",
"get_class",
"(",
"$",
"e",
"... | Records an Exception to the database
@param Exception $e The exception you want to record
@return false|ExceptionModel
@throws RecorderFailedException | [
"Records",
"an",
"Exception",
"to",
"the",
"database"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Recorder.php#L43-L82 | train |
tylercd100/lern | src/Components/Recorder.php | Recorder.canCollect | private function canCollect($type) {
if (!empty($this->config) && !empty($this->config['collect']) && !empty($this->config['collect'][$type])) {
return $this->config['collect'][$type] === true;
}
return false;
} | php | private function canCollect($type) {
if (!empty($this->config) && !empty($this->config['collect']) && !empty($this->config['collect'][$type])) {
return $this->config['collect'][$type] === true;
}
return false;
} | [
"private",
"function",
"canCollect",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'collect'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this... | Checks the config to see if you can collect certain information
@param string $type the config value you want to check
@return boolean | [
"Checks",
"the",
"config",
"to",
"see",
"if",
"you",
"can",
"collect",
"certain",
"information"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Recorder.php#L89-L94 | train |
tylercd100/lern | src/Components/Recorder.php | Recorder.getUserId | protected function getUserId() {
$user = Auth::user();
if (is_object($user) && !empty($user->id)) {
return $user->id;
} else {
return null;
}
} | php | protected function getUserId() {
$user = Auth::user();
if (is_object($user) && !empty($user->id)) {
return $user->id;
} else {
return null;
}
} | [
"protected",
"function",
"getUserId",
"(",
")",
"{",
"$",
"user",
"=",
"Auth",
"::",
"user",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"user",
")",
"&&",
"!",
"empty",
"(",
"$",
"user",
"->",
"id",
")",
")",
"{",
"return",
"$",
"user",
"... | Gets the ID of the User that is logged in
@return integer|null The ID of the User or Null if not logged in | [
"Gets",
"the",
"ID",
"of",
"the",
"User",
"that",
"is",
"logged",
"in"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Recorder.php#L128-L135 | train |
tylercd100/lern | src/Components/Recorder.php | Recorder.getData | protected function getData() {
$data = Input::all();
if (is_array($data)) {
return $this->excludeKeys($data);
} else {
return null;
}
} | php | protected function getData() {
$data = Input::all();
if (is_array($data)) {
return $this->excludeKeys($data);
} else {
return null;
}
} | [
"protected",
"function",
"getData",
"(",
")",
"{",
"$",
"data",
"=",
"Input",
"::",
"all",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"excludeKeys",
"(",
"$",
"data",
")",
";",
"}",
"else",... | Gets the input data of the Request
@return array|null The Input data or null | [
"Gets",
"the",
"input",
"data",
"of",
"the",
"Request"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Recorder.php#L154-L161 | train |
tylercd100/lern | src/Components/Recorder.php | Recorder.excludeKeys | protected function excludeKeys(array $data) {
$keys = isset($this->config['excludeKeys']) ? $this->config['excludeKeys'] : [];
foreach ($data as $key => &$value) {
if (in_array($key, $keys)) {
unset($data[$key]);
} else if (is_array($value)) {
$value = $this->excludeKeys($value);
}
}
return $data;
} | php | protected function excludeKeys(array $data) {
$keys = isset($this->config['excludeKeys']) ? $this->config['excludeKeys'] : [];
foreach ($data as $key => &$value) {
if (in_array($key, $keys)) {
unset($data[$key]);
} else if (is_array($value)) {
$value = $this->excludeKeys($value);
}
}
return $data;
} | [
"protected",
"function",
"excludeKeys",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"keys",
"=",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'excludeKeys'",
"]",
")",
"?",
"$",
"this",
"->",
"config",
"[",
"'excludeKeys'",
"]",
":",
"[",
"]",
";",... | This function will remove all keys from an array recursively as defined in the config file
@param array $data The array to remove keys from
@return void | [
"This",
"function",
"will",
"remove",
"all",
"keys",
"from",
"an",
"array",
"recursively",
"as",
"defined",
"in",
"the",
"config",
"file"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Recorder.php#L203-L214 | train |
BKWLD/decoy | classes/Commands/Admin.php | Admin.handle | public function handle()
{
$firstName = $this->ask('First Name');
$lastName = $this->ask('Last Name');
$email = $this->ask('Email');
// Check the email to see if its already being used
if ($admin = BkwldAdmin::where('email', $email)->exists()) {
$this->error('That email is already in use');
return;
}
$password = $this->secret('Enter your password');
$confirm = $this->secret('Confirm your password');
// password matching check
if ($password != $confirm) {
$this->error('Your passwords do not match.');
return;
}
// Create a new admin
$admin = new BkwldAdmin;
$admin->first_name = $firstName;
$admin->last_name = $lastName;
$admin->email = $email;
$admin->password = $password;
// Save out the new admin
$admin->save();
$this->info('Admin created!');
} | php | public function handle()
{
$firstName = $this->ask('First Name');
$lastName = $this->ask('Last Name');
$email = $this->ask('Email');
// Check the email to see if its already being used
if ($admin = BkwldAdmin::where('email', $email)->exists()) {
$this->error('That email is already in use');
return;
}
$password = $this->secret('Enter your password');
$confirm = $this->secret('Confirm your password');
// password matching check
if ($password != $confirm) {
$this->error('Your passwords do not match.');
return;
}
// Create a new admin
$admin = new BkwldAdmin;
$admin->first_name = $firstName;
$admin->last_name = $lastName;
$admin->email = $email;
$admin->password = $password;
// Save out the new admin
$admin->save();
$this->info('Admin created!');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"firstName",
"=",
"$",
"this",
"->",
"ask",
"(",
"'First Name'",
")",
";",
"$",
"lastName",
"=",
"$",
"this",
"->",
"ask",
"(",
"'Last Name'",
")",
";",
"$",
"email",
"=",
"$",
"this",
"->",
"ask"... | Create the new admin with input from the user
@return void | [
"Create",
"the",
"new",
"admin",
"with",
"input",
"from",
"the",
"user"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Commands/Admin.php#L29-L62 | train |
BKWLD/decoy | classes/Models/RedirectRule.php | RedirectRule.onValidating | public function onValidating($validation)
{
// Clean up "from" route, stripping host and leading slash
$this->from = preg_replace('#^([^/]*//[^/]+)?/?#', '', $this->from);
// Make an absolute path if the current domain is entered
$this->to = Utils\URL::urlToAbsolutePath($this->to);
// Add row exception for unique
if ($this->exists) {
$rules = $validation->getRules();
$rules['from'][1] .= ','.$this->getKey();
$validation->setRules($rules);
}
} | php | public function onValidating($validation)
{
// Clean up "from" route, stripping host and leading slash
$this->from = preg_replace('#^([^/]*//[^/]+)?/?#', '', $this->from);
// Make an absolute path if the current domain is entered
$this->to = Utils\URL::urlToAbsolutePath($this->to);
// Add row exception for unique
if ($this->exists) {
$rules = $validation->getRules();
$rules['from'][1] .= ','.$this->getKey();
$validation->setRules($rules);
}
} | [
"public",
"function",
"onValidating",
"(",
"$",
"validation",
")",
"{",
"// Clean up \"from\" route, stripping host and leading slash",
"$",
"this",
"->",
"from",
"=",
"preg_replace",
"(",
"'#^([^/]*//[^/]+)?/?#'",
",",
"''",
",",
"$",
"this",
"->",
"from",
")",
";"... | Pre-validation rules
@param Illuminate\Validation\Validator $validation
@return null | [
"Pre",
"-",
"validation",
"rules"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/RedirectRule.php#L72-L86 | train |
BKWLD/decoy | classes/Models/RedirectRule.php | RedirectRule.scopeMatchUsingRequest | public function scopeMatchUsingRequest($query)
{
return $query->where(function ($query) {
$from = $this->pathAndQuery();
$escaped_from = DB::connection()->getPdo()->quote($from);
$from_col = DB::getDriverName() == 'sqlsrv' ? '[from]' : '`from`';
$query->where('from', $from)->orWhereRaw("{$escaped_from} LIKE {$from_col}");
if (Config::get('decoy::core.allow_regex_in_redirects')) {
$query->orWhereRaw("{$escaped_from} REGEXP {$from_col}");
}
});
} | php | public function scopeMatchUsingRequest($query)
{
return $query->where(function ($query) {
$from = $this->pathAndQuery();
$escaped_from = DB::connection()->getPdo()->quote($from);
$from_col = DB::getDriverName() == 'sqlsrv' ? '[from]' : '`from`';
$query->where('from', $from)->orWhereRaw("{$escaped_from} LIKE {$from_col}");
if (Config::get('decoy::core.allow_regex_in_redirects')) {
$query->orWhereRaw("{$escaped_from} REGEXP {$from_col}");
}
});
} | [
"public",
"function",
"scopeMatchUsingRequest",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"from",
"=",
"$",
"this",
"->",
"pathAndQuery",
"(",
")",
";",
"$",
"escaped_from",
"... | See if the current request matches the "FROM" using progressively more
expensive ways to match the from column.
@param Illuminate\Database\Query\Builder $query
@return void | [
"See",
"if",
"the",
"current",
"request",
"matches",
"the",
"FROM",
"using",
"progressively",
"more",
"expensive",
"ways",
"to",
"match",
"the",
"from",
"column",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/RedirectRule.php#L107-L118 | train |
BKWLD/decoy | classes/Models/RedirectRule.php | RedirectRule.pathAndQuery | public function pathAndQuery()
{
$query = Request::getQueryString();
$path = ltrim(Request::path(), '/'); // ltrim fixes homepage
return $query ? $path.'?'.$query : $path;
} | php | public function pathAndQuery()
{
$query = Request::getQueryString();
$path = ltrim(Request::path(), '/'); // ltrim fixes homepage
return $query ? $path.'?'.$query : $path;
} | [
"public",
"function",
"pathAndQuery",
"(",
")",
"{",
"$",
"query",
"=",
"Request",
"::",
"getQueryString",
"(",
")",
";",
"$",
"path",
"=",
"ltrim",
"(",
"Request",
"::",
"path",
"(",
")",
",",
"'/'",
")",
";",
"// ltrim fixes homepage",
"return",
"$",
... | Get the path and query from the request
@return string | [
"Get",
"the",
"path",
"and",
"query",
"from",
"the",
"request"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/RedirectRule.php#L125-L130 | train |
BKWLD/decoy | classes/Fields/Listing.php | Listing.createFromController | public static function createFromController($controller, $items)
{
$model = $controller->model();
return Former::listing($model, null, null, null, [
'controller' => $controller,
'items' => $items,
]);
} | php | public static function createFromController($controller, $items)
{
$model = $controller->model();
return Former::listing($model, null, null, null, [
'controller' => $controller,
'items' => $items,
]);
} | [
"public",
"static",
"function",
"createFromController",
"(",
"$",
"controller",
",",
"$",
"items",
")",
"{",
"$",
"model",
"=",
"$",
"controller",
"->",
"model",
"(",
")",
";",
"return",
"Former",
"::",
"listing",
"(",
"$",
"model",
",",
"null",
",",
"... | A factory to create an instance using the passed controller. This is to prevent
duplicate controller instantations when invoked from the base controller.
@param Bkwld\Decoy\Controllers\Base $controller
@param LengthAwarePaginator $items
@return Bkwld\Decoy\Field\Listing | [
"A",
"factory",
"to",
"create",
"an",
"instance",
"using",
"the",
"passed",
"controller",
".",
"This",
"is",
"to",
"prevent",
"duplicate",
"controller",
"instantations",
"when",
"invoked",
"from",
"the",
"base",
"controller",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L136-L144 | train |
BKWLD/decoy | classes/Fields/Listing.php | Listing.controller | public function controller($controller)
{
// Instantiate a string controller
if (is_string($controller)
&& class_exists($controller)
&& is_subclass_of($controller, 'Bkwld\Decoy\Controllers\Base')) {
$this->controller_name = $controller;
$this->controller = new $controller;
// Apply the parent if one was set
if ($this->parent_item && $this->controller) {
$this->controller->parent($this->parent_item);
}
// Or, validate a passed controller instance
} elseif (is_object($controller)
&& is_a($controller, 'Bkwld\Decoy\Controllers\Base')) {
$this->controller_name = get_class($controller);
$this->controller = $controller;
}
// Chain
return $this;
} | php | public function controller($controller)
{
// Instantiate a string controller
if (is_string($controller)
&& class_exists($controller)
&& is_subclass_of($controller, 'Bkwld\Decoy\Controllers\Base')) {
$this->controller_name = $controller;
$this->controller = new $controller;
// Apply the parent if one was set
if ($this->parent_item && $this->controller) {
$this->controller->parent($this->parent_item);
}
// Or, validate a passed controller instance
} elseif (is_object($controller)
&& is_a($controller, 'Bkwld\Decoy\Controllers\Base')) {
$this->controller_name = get_class($controller);
$this->controller = $controller;
}
// Chain
return $this;
} | [
"public",
"function",
"controller",
"(",
"$",
"controller",
")",
"{",
"// Instantiate a string controller",
"if",
"(",
"is_string",
"(",
"$",
"controller",
")",
"&&",
"class_exists",
"(",
"$",
"controller",
")",
"&&",
"is_subclass_of",
"(",
"$",
"controller",
",... | Replace the controller
@param Bkwld\Decoy\Controllers\Base | string $controller
@return Field This field | [
"Replace",
"the",
"controller"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L152-L176 | train |
BKWLD/decoy | classes/Fields/Listing.php | Listing.wrapAndRender | public function wrapAndRender()
{
// Don't set an id
$this->setAttribute('id', false);
// Because it's a field, Former will add this. But it's not really
// appropriate for a listing
$this->removeClass('form-control');
// Render the markup
if ($this->layout == 'form') {
return $this->wrapInControlGroup();
}
return $this->render();
} | php | public function wrapAndRender()
{
// Don't set an id
$this->setAttribute('id', false);
// Because it's a field, Former will add this. But it's not really
// appropriate for a listing
$this->removeClass('form-control');
// Render the markup
if ($this->layout == 'form') {
return $this->wrapInControlGroup();
}
return $this->render();
} | [
"public",
"function",
"wrapAndRender",
"(",
")",
"{",
"// Don't set an id",
"$",
"this",
"->",
"setAttribute",
"(",
"'id'",
",",
"false",
")",
";",
"// Because it's a field, Former will add this. But it's not really",
"// appropriate for a listing",
"$",
"this",
"->",
"r... | Render the layout, .i.e. put it in a control group or a different
wrapper
@return string HTML | [
"Render",
"the",
"layout",
".",
"i",
".",
"e",
".",
"put",
"it",
"in",
"a",
"control",
"group",
"or",
"a",
"different",
"wrapper"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L254-L269 | train |
BKWLD/decoy | classes/Fields/Listing.php | Listing.wrapInControlGroup | protected function wrapInControlGroup()
{
// Add generic stuff
$this->addGroupClass('list-form-group');
// Use the controller description for blockhelp
if (!$this->hasHelp()) {
$this->blockhelp($this->controller->description());
}
// Show no results if there is no parent specified
if (empty($this->parent_item)) {
$this->addGroupClass('note');
return $this->group->wrapField(Former::note($this->label_text, trans('decoy::form.listing.pending_save', ['model' => $this->label_text, 'description' => $this->controller->description()])));
}
// Add create button if we have permission and if there is a parent item
if (app('decoy.user')->can('create', $this->controller)) {
$this->group->setLabel(
'<a href="'.$this->getIndexURL().'">'
.$this->label_text
.'</a>'
.$this->makeCreateBtn()
);
}
// Return the wrapped field
return $this->group->wrapField($this);
} | php | protected function wrapInControlGroup()
{
// Add generic stuff
$this->addGroupClass('list-form-group');
// Use the controller description for blockhelp
if (!$this->hasHelp()) {
$this->blockhelp($this->controller->description());
}
// Show no results if there is no parent specified
if (empty($this->parent_item)) {
$this->addGroupClass('note');
return $this->group->wrapField(Former::note($this->label_text, trans('decoy::form.listing.pending_save', ['model' => $this->label_text, 'description' => $this->controller->description()])));
}
// Add create button if we have permission and if there is a parent item
if (app('decoy.user')->can('create', $this->controller)) {
$this->group->setLabel(
'<a href="'.$this->getIndexURL().'">'
.$this->label_text
.'</a>'
.$this->makeCreateBtn()
);
}
// Return the wrapped field
return $this->group->wrapField($this);
} | [
"protected",
"function",
"wrapInControlGroup",
"(",
")",
"{",
"// Add generic stuff",
"$",
"this",
"->",
"addGroupClass",
"(",
"'list-form-group'",
")",
";",
"// Use the controller description for blockhelp",
"if",
"(",
"!",
"$",
"this",
"->",
"hasHelp",
"(",
")",
"... | Add customization to the control group rendering
@return string HTML | [
"Add",
"customization",
"to",
"the",
"control",
"group",
"rendering"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L276-L305 | train |
BKWLD/decoy | classes/Fields/Listing.php | Listing.getIndexURL | protected function getIndexURL()
{
return $this->controller->isChildInManyToMany() ?
DecoyURL::action($this->controller_name.'@index') :
DecoyURL::relative('index', null, $this->controller_name);
} | php | protected function getIndexURL()
{
return $this->controller->isChildInManyToMany() ?
DecoyURL::action($this->controller_name.'@index') :
DecoyURL::relative('index', null, $this->controller_name);
} | [
"protected",
"function",
"getIndexURL",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"controller",
"->",
"isChildInManyToMany",
"(",
")",
"?",
"DecoyURL",
"::",
"action",
"(",
"$",
"this",
"->",
"controller_name",
".",
"'@index'",
")",
":",
"DecoyURL",
"::",
... | Get the index URL for this controller
@return string URL | [
"Get",
"the",
"index",
"URL",
"for",
"this",
"controller"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L383-L388 | train |
BKWLD/decoy | classes/Fields/Listing.php | Listing.getColumns | protected function getColumns($controller)
{
// If user has defined columns, use them
if ($this->columns) {
return $this->columns;
}
// Read columns from the controller
$columns = $controller->columns();
// If showing in sidebar, only show the first column
// http://stackoverflow.com/a/1028677/59160
if ($this->layout == 'sidebar') {
$val = reset($columns); // Making sure this gets called before `key()`
return [key($columns) => $val];
// Otherwise, just return all columns
}
return $columns;
} | php | protected function getColumns($controller)
{
// If user has defined columns, use them
if ($this->columns) {
return $this->columns;
}
// Read columns from the controller
$columns = $controller->columns();
// If showing in sidebar, only show the first column
// http://stackoverflow.com/a/1028677/59160
if ($this->layout == 'sidebar') {
$val = reset($columns); // Making sure this gets called before `key()`
return [key($columns) => $val];
// Otherwise, just return all columns
}
return $columns;
} | [
"protected",
"function",
"getColumns",
"(",
"$",
"controller",
")",
"{",
"// If user has defined columns, use them",
"if",
"(",
"$",
"this",
"->",
"columns",
")",
"{",
"return",
"$",
"this",
"->",
"columns",
";",
"}",
"// Read columns from the controller",
"$",
"c... | Get the list of columns of the controller
@param Bkwld\Decoy\Controller\Base $controller A controller instance
@return array Associative array of column keys and values | [
"Get",
"the",
"list",
"of",
"columns",
"of",
"the",
"controller"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L408-L428 | train |
BKWLD/decoy | classes/Fields/Listing.php | Listing.queryForItems | protected function queryForItems()
{
// If there is a parent, run the query through the relationship to this model
// from the parent
if ($this->parent_item) {
$relationship = Decoy::hasManyName($this->name);
$query = $this->parent_item->$relationship()->ordered();
}
// Otherwise, open up the query using ordered
else {
$query = call_user_func($this->name.'::ordered');
}
// Apply any custom scope
if ($this->scope) {
call_user_func($this->scope, $query);
}
// Retrieve the results through paginator
return $query->paginate($this->perPage());
} | php | protected function queryForItems()
{
// If there is a parent, run the query through the relationship to this model
// from the parent
if ($this->parent_item) {
$relationship = Decoy::hasManyName($this->name);
$query = $this->parent_item->$relationship()->ordered();
}
// Otherwise, open up the query using ordered
else {
$query = call_user_func($this->name.'::ordered');
}
// Apply any custom scope
if ($this->scope) {
call_user_func($this->scope, $query);
}
// Retrieve the results through paginator
return $query->paginate($this->perPage());
} | [
"protected",
"function",
"queryForItems",
"(",
")",
"{",
"// If there is a parent, run the query through the relationship to this model",
"// from the parent",
"if",
"(",
"$",
"this",
"->",
"parent_item",
")",
"{",
"$",
"relationship",
"=",
"Decoy",
"::",
"hasManyName",
"... | Write an execute a query to get the list of items
@return LengthAwarePaginator | [
"Write",
"an",
"execute",
"a",
"query",
"to",
"get",
"the",
"list",
"of",
"items"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L451-L472 | train |
BKWLD/decoy | classes/Fields/Listing.php | Listing.perPage | protected function perPage()
{
// If the user specified a limit, use it
if ($this->take) {
return $this->take;
}
// If a sidebar, use the default
if ($this->layout == 'sidebar') {
$name = $this->controller_name;
return $name::$per_sidebar;
}
// Else, use the controller's pagination logic
return $this->controller->perPage();
} | php | protected function perPage()
{
// If the user specified a limit, use it
if ($this->take) {
return $this->take;
}
// If a sidebar, use the default
if ($this->layout == 'sidebar') {
$name = $this->controller_name;
return $name::$per_sidebar;
}
// Else, use the controller's pagination logic
return $this->controller->perPage();
} | [
"protected",
"function",
"perPage",
"(",
")",
"{",
"// If the user specified a limit, use it",
"if",
"(",
"$",
"this",
"->",
"take",
")",
"{",
"return",
"$",
"this",
"->",
"take",
";",
"}",
"// If a sidebar, use the default",
"if",
"(",
"$",
"this",
"->",
"lay... | Get the amount per page be looking at a number of different sources
@return int The amount | [
"Get",
"the",
"amount",
"per",
"page",
"be",
"looking",
"at",
"a",
"number",
"of",
"different",
"sources"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L479-L495 | train |
BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.registerDirectories | public function registerDirectories()
{
// Publish config files
$this->publishes([
__DIR__.'/../config' => config_path('decoy')
], 'config');
// Publish decoy css and js to public directory
$this->publishes([
__DIR__.'/../dist' => public_path('assets/decoy')
], 'assets');
// Publish lanaguage files
$this->publishes([
__DIR__.'/../lang' => resource_path('lang/vendor/decoy')
], 'lang');
// Register views
$this->loadViewsFrom(__DIR__.'/../views', 'decoy');
// Load translations
$this->loadTranslationsFrom(__DIR__.'/../lang', 'decoy');
// Load migrations
$this->loadMigrationsFrom(__DIR__.'/../migrations/');
} | php | public function registerDirectories()
{
// Publish config files
$this->publishes([
__DIR__.'/../config' => config_path('decoy')
], 'config');
// Publish decoy css and js to public directory
$this->publishes([
__DIR__.'/../dist' => public_path('assets/decoy')
], 'assets');
// Publish lanaguage files
$this->publishes([
__DIR__.'/../lang' => resource_path('lang/vendor/decoy')
], 'lang');
// Register views
$this->loadViewsFrom(__DIR__.'/../views', 'decoy');
// Load translations
$this->loadTranslationsFrom(__DIR__.'/../lang', 'decoy');
// Load migrations
$this->loadMigrationsFrom(__DIR__.'/../migrations/');
} | [
"public",
"function",
"registerDirectories",
"(",
")",
"{",
"// Publish config files",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../config'",
"=>",
"config_path",
"(",
"'decoy'",
")",
"]",
",",
"'config'",
")",
";",
"// Publish decoy css and js ... | Register configs, migrations, etc
@return void | [
"Register",
"configs",
"migrations",
"etc"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L61-L86 | train |
BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.usingAdmin | public function usingAdmin()
{
// Define constants that Decoy uses
if (!defined('FORMAT_DATE')) {
define('FORMAT_DATE', __('decoy::base.constants.format_date'));
}
if (!defined('FORMAT_DATETIME')) {
define('FORMAT_DATETIME', __('decoy::base.constants.format_datetime'));
}
if (!defined('FORMAT_TIME')) {
define('FORMAT_TIME', __('decoy::base.constants.format_time'));
}
// Register global and named middlewares
$this->registerMiddlewares();
// Use Decoy's auth by default, while at an admin path
Config::set('auth.defaults', [
'guard' => 'decoy',
'passwords' => 'decoy',
]);
// Set the default mailer settings
Config::set('mail.from', [
'address' => Config::get('decoy.core.mail_from_address'),
'name' => Config::get('decoy.core.mail_from_name'),
]);
// Config Former
$this->configureFormer();
// Delegate events to Decoy observers
$this->delegateAdminObservers();
// Use Boostrap 3 classes in Laravel 5.6
if (method_exists(Paginator::class, 'useBootstrapThree')) {
Paginator::useBootstrapThree();
}
} | php | public function usingAdmin()
{
// Define constants that Decoy uses
if (!defined('FORMAT_DATE')) {
define('FORMAT_DATE', __('decoy::base.constants.format_date'));
}
if (!defined('FORMAT_DATETIME')) {
define('FORMAT_DATETIME', __('decoy::base.constants.format_datetime'));
}
if (!defined('FORMAT_TIME')) {
define('FORMAT_TIME', __('decoy::base.constants.format_time'));
}
// Register global and named middlewares
$this->registerMiddlewares();
// Use Decoy's auth by default, while at an admin path
Config::set('auth.defaults', [
'guard' => 'decoy',
'passwords' => 'decoy',
]);
// Set the default mailer settings
Config::set('mail.from', [
'address' => Config::get('decoy.core.mail_from_address'),
'name' => Config::get('decoy.core.mail_from_name'),
]);
// Config Former
$this->configureFormer();
// Delegate events to Decoy observers
$this->delegateAdminObservers();
// Use Boostrap 3 classes in Laravel 5.6
if (method_exists(Paginator::class, 'useBootstrapThree')) {
Paginator::useBootstrapThree();
}
} | [
"public",
"function",
"usingAdmin",
"(",
")",
"{",
"// Define constants that Decoy uses",
"if",
"(",
"!",
"defined",
"(",
"'FORMAT_DATE'",
")",
")",
"{",
"define",
"(",
"'FORMAT_DATE'",
",",
"__",
"(",
"'decoy::base.constants.format_date'",
")",
")",
";",
"}",
"... | Things that happen only if the request is for the admin | [
"Things",
"that",
"happen",
"only",
"if",
"the",
"request",
"is",
"for",
"the",
"admin"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L91-L130 | train |
BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.bootAuth | public function bootAuth()
{
// Inject Decoy's auth config
Config::set('auth.guards.decoy', [
'driver' => 'session',
'provider' => 'decoy',
]);
Config::set('auth.providers.decoy', [
'driver' => 'eloquent',
'model' => Models\Admin::class,
]);
Config::set('auth.passwords.decoy', [
'provider' => 'decoy',
'email' => 'decoy::emails.reset',
'table' => 'password_resets',
'expire' => 60,
]);
// Point to the Gate policy
$this->app[Gate::class]->define('decoy.auth', config('decoy.core.policy'));
} | php | public function bootAuth()
{
// Inject Decoy's auth config
Config::set('auth.guards.decoy', [
'driver' => 'session',
'provider' => 'decoy',
]);
Config::set('auth.providers.decoy', [
'driver' => 'eloquent',
'model' => Models\Admin::class,
]);
Config::set('auth.passwords.decoy', [
'provider' => 'decoy',
'email' => 'decoy::emails.reset',
'table' => 'password_resets',
'expire' => 60,
]);
// Point to the Gate policy
$this->app[Gate::class]->define('decoy.auth', config('decoy.core.policy'));
} | [
"public",
"function",
"bootAuth",
"(",
")",
"{",
"// Inject Decoy's auth config",
"Config",
"::",
"set",
"(",
"'auth.guards.decoy'",
",",
"[",
"'driver'",
"=>",
"'session'",
",",
"'provider'",
"=>",
"'decoy'",
",",
"]",
")",
";",
"Config",
"::",
"set",
"(",
... | Boot Decoy's auth integration
@return void | [
"Boot",
"Decoy",
"s",
"auth",
"integration"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L137-L159 | train |
BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.delegateAdminObservers | protected function delegateAdminObservers()
{
$this->app['events']->listen('eloquent.saving:*',
'Bkwld\Decoy\Observers\Localize');
$this->app['events']->listen('eloquent.saving:*',
'Bkwld\Decoy\Observers\Encoding@onSaving');
$this->app['events']->listen('eloquent.saved:*',
'Bkwld\Decoy\Observers\ManyToManyChecklist');
$this->app['events']->listen('eloquent.deleted:*',
'Bkwld\Decoy\Observers\Encoding@onDeleted');
$this->app['events']->listen('decoy::model.validating:*',
'Bkwld\Decoy\Observers\ValidateExistingFiles@onValidating');
} | php | protected function delegateAdminObservers()
{
$this->app['events']->listen('eloquent.saving:*',
'Bkwld\Decoy\Observers\Localize');
$this->app['events']->listen('eloquent.saving:*',
'Bkwld\Decoy\Observers\Encoding@onSaving');
$this->app['events']->listen('eloquent.saved:*',
'Bkwld\Decoy\Observers\ManyToManyChecklist');
$this->app['events']->listen('eloquent.deleted:*',
'Bkwld\Decoy\Observers\Encoding@onDeleted');
$this->app['events']->listen('decoy::model.validating:*',
'Bkwld\Decoy\Observers\ValidateExistingFiles@onValidating');
} | [
"protected",
"function",
"delegateAdminObservers",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
"->",
"listen",
"(",
"'eloquent.saving:*'",
",",
"'Bkwld\\Decoy\\Observers\\Localize'",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
... | Delegate events to Decoy observers
@return void | [
"Delegate",
"events",
"to",
"Decoy",
"observers"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L191-L203 | train |
BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.registerPackages | private function registerPackages()
{
// Form field generation
AliasLoader::getInstance()->alias('Former', \Former\Facades\Former::class);
$this->app->register('Former\FormerServiceProvider');
// Image resizing
AliasLoader::getInstance()->alias('Croppa', \Bkwld\Croppa\Facade::class);
$this->app->register('Bkwld\Croppa\ServiceProvider');
// PHP utils
$this->app->register('Bkwld\Library\ServiceProvider');
// HAML
$this->app->register('Bkwld\LaravelHaml\ServiceProvider');
// BrowserDetect
AliasLoader::getInstance()->alias('Agent', \Jenssegers\Agent\Facades\Agent::class);
$this->app->register('Jenssegers\Agent\AgentServiceProvider');
// File uploading
$this->app->register('Bkwld\Upchuck\ServiceProvider');
// Creation of slugs
$this->app->register('Cviebrock\EloquentSluggable\ServiceProvider');
// Support for cloning models
$this->app->register('Bkwld\Cloner\ServiceProvider');
} | php | private function registerPackages()
{
// Form field generation
AliasLoader::getInstance()->alias('Former', \Former\Facades\Former::class);
$this->app->register('Former\FormerServiceProvider');
// Image resizing
AliasLoader::getInstance()->alias('Croppa', \Bkwld\Croppa\Facade::class);
$this->app->register('Bkwld\Croppa\ServiceProvider');
// PHP utils
$this->app->register('Bkwld\Library\ServiceProvider');
// HAML
$this->app->register('Bkwld\LaravelHaml\ServiceProvider');
// BrowserDetect
AliasLoader::getInstance()->alias('Agent', \Jenssegers\Agent\Facades\Agent::class);
$this->app->register('Jenssegers\Agent\AgentServiceProvider');
// File uploading
$this->app->register('Bkwld\Upchuck\ServiceProvider');
// Creation of slugs
$this->app->register('Cviebrock\EloquentSluggable\ServiceProvider');
// Support for cloning models
$this->app->register('Bkwld\Cloner\ServiceProvider');
} | [
"private",
"function",
"registerPackages",
"(",
")",
"{",
"// Form field generation",
"AliasLoader",
"::",
"getInstance",
"(",
")",
"->",
"alias",
"(",
"'Former'",
",",
"\\",
"Former",
"\\",
"Facades",
"\\",
"Former",
"::",
"class",
")",
";",
"$",
"this",
"-... | Register external dependencies | [
"Register",
"external",
"dependencies"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L330-L358 | train |
BKWLD/decoy | classes/Models/Traits/Exportable.php | Exportable.mapExportAttributes | protected function mapExportAttributes($attributes)
{
return collect($attributes->toArray())->map(function($value, $key) {
return $this->mapExportAttribute($value, $key);
})->toArray();
} | php | protected function mapExportAttributes($attributes)
{
return collect($attributes->toArray())->map(function($value, $key) {
return $this->mapExportAttribute($value, $key);
})->toArray();
} | [
"protected",
"function",
"mapExportAttributes",
"(",
"$",
"attributes",
")",
"{",
"return",
"collect",
"(",
"$",
"attributes",
"->",
"toArray",
"(",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"{",
"return",
"$",
"t... | Massage attribute values. The CSV needs a flat array.
@return array | [
"Massage",
"attribute",
"values",
".",
"The",
"CSV",
"needs",
"a",
"flat",
"array",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Exportable.php#L64-L69 | train |
BKWLD/decoy | classes/Models/Traits/Exportable.php | Exportable.mapExportAttribute | protected function mapExportAttribute($value, $key)
{
// If an images relationship
if ($key == 'images') {
return implode(',', array_map(function($image) {
return $image['file'];
}, $value));
}
// If another array...
if (is_array($value)) {
return implode(',', array_map(function($child) {
// If sub array, like if this was some relation, return the id
// so this becomes an array of those ids
if (is_array($child) && isset($child['id'])) {
return $child['id'];
}
// If anything else, just return it
return $child;
}, $value));
}
// Otherwise, just pass through value
return $value;
} | php | protected function mapExportAttribute($value, $key)
{
// If an images relationship
if ($key == 'images') {
return implode(',', array_map(function($image) {
return $image['file'];
}, $value));
}
// If another array...
if (is_array($value)) {
return implode(',', array_map(function($child) {
// If sub array, like if this was some relation, return the id
// so this becomes an array of those ids
if (is_array($child) && isset($child['id'])) {
return $child['id'];
}
// If anything else, just return it
return $child;
}, $value));
}
// Otherwise, just pass through value
return $value;
} | [
"protected",
"function",
"mapExportAttribute",
"(",
"$",
"value",
",",
"$",
"key",
")",
"{",
"// If an images relationship",
"if",
"(",
"$",
"key",
"==",
"'images'",
")",
"{",
"return",
"implode",
"(",
"','",
",",
"array_map",
"(",
"function",
"(",
"$",
"i... | Massage attribute values for export
@return scalar | [
"Massage",
"attribute",
"values",
"for",
"export"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Exportable.php#L76-L102 | train |
BKWLD/decoy | classes/Models/Traits/Exportable.php | Exportable.makeCsvHeaderNames | public function makeCsvHeaderNames()
{
$headers = array_keys($this->forExport());
return array_map(function($key) {
switch($key) {
// id must be lowercase for opening in excel
// https://annalear.ca/2010/06/10/why-excel-thinks-your-csv-is-a-sylk/
case 'id': return $key;
// Make common acronyms upper case
case 'uid':
case 'pid':
case 'guid':
case 'cta':
case 'url': return strtoupper($key);
// Default to title casing fields
default: return TextUtils::titleFromKey($key);
}
}, $headers);
} | php | public function makeCsvHeaderNames()
{
$headers = array_keys($this->forExport());
return array_map(function($key) {
switch($key) {
// id must be lowercase for opening in excel
// https://annalear.ca/2010/06/10/why-excel-thinks-your-csv-is-a-sylk/
case 'id': return $key;
// Make common acronyms upper case
case 'uid':
case 'pid':
case 'guid':
case 'cta':
case 'url': return strtoupper($key);
// Default to title casing fields
default: return TextUtils::titleFromKey($key);
}
}, $headers);
} | [
"public",
"function",
"makeCsvHeaderNames",
"(",
")",
"{",
"$",
"headers",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"forExport",
"(",
")",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"key",
")",
"{",
"switch",
"(",
"$",
"key",
")",
... | Make the header the CSV header row
@return array | [
"Make",
"the",
"header",
"the",
"CSV",
"header",
"row"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Exportable.php#L109-L130 | train |
BKWLD/decoy | classes/Models/Image.php | Image.deletedBecauseEmpty | public function deletedBecauseEmpty()
{
if ($file = $this->getAttributeValue('file')) {
return false;
}
if ($this->exists) {
$this->delete();
}
return true;
} | php | public function deletedBecauseEmpty()
{
if ($file = $this->getAttributeValue('file')) {
return false;
}
if ($this->exists) {
$this->delete();
}
return true;
} | [
"public",
"function",
"deletedBecauseEmpty",
"(",
")",
"{",
"if",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"'file'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"exists",
")",
"{",
"$",
"this",... | If the file attribtue is empty, this Image has been marked for deletion.
Return true to signal the image was deleted
@return bool | [
"If",
"the",
"file",
"attribtue",
"is",
"empty",
"this",
"Image",
"has",
"been",
"marked",
"for",
"deletion",
".",
"Return",
"true",
"to",
"signal",
"the",
"image",
"was",
"deleted"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L169-L180 | train |
BKWLD/decoy | classes/Models/Image.php | Image.populateFileMeta | public function populateFileMeta()
{
$file = $this->getAttributeValue('file');
if (!is_a($file, UploadedFile::class)) {
return;
}
$size = getimagesize($file->getPathname());
$this->fill([
'file_type' => $this->guessFileType($file),
'file_size' => $file->getSize(),
'width' => $size[0],
'height' => $size[1],
]);
} | php | public function populateFileMeta()
{
$file = $this->getAttributeValue('file');
if (!is_a($file, UploadedFile::class)) {
return;
}
$size = getimagesize($file->getPathname());
$this->fill([
'file_type' => $this->guessFileType($file),
'file_size' => $file->getSize(),
'width' => $size[0],
'height' => $size[1],
]);
} | [
"public",
"function",
"populateFileMeta",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"'file'",
")",
";",
"if",
"(",
"!",
"is_a",
"(",
"$",
"file",
",",
"UploadedFile",
"::",
"class",
")",
")",
"{",
"return",
";",
"}... | Store file meta info in the database if a new File object is present
@return void | [
"Store",
"file",
"meta",
"info",
"in",
"the",
"database",
"if",
"a",
"new",
"File",
"object",
"is",
"present"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L187-L200 | train |
BKWLD/decoy | classes/Models/Image.php | Image.crop | public function crop($width = null, $height = null, $options = null)
{
$this->config = [
'width' => $width,
'height' => $height,
'options' => $options,
];
return $this;
} | php | public function crop($width = null, $height = null, $options = null)
{
$this->config = [
'width' => $width,
'height' => $height,
'options' => $options,
];
return $this;
} | [
"public",
"function",
"crop",
"(",
"$",
"width",
"=",
"null",
",",
"$",
"height",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"[",
"'width'",
"=>",
"$",
"width",
",",
"'height'",
"=>",
"$",
"height",
... | Set the crop dimenions
@param integer $width
@param integer $height
@param array $options Croppa options array
@return $this | [
"Set",
"the",
"crop",
"dimenions"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L241-L250 | train |
BKWLD/decoy | classes/Models/Image.php | Image.getConfig | public function getConfig()
{
// Create default keys for the config
$config = array_merge([
'width' => null,
'height' => null,
'options' => null,
], $this->config);
// Add crops
if ($crop = $this->getAttributeValue('crop_box')) {
if (!is_array($config['options'])) {
$config['options'] = [];
}
$config['options']['trim_perc'] = [
round($crop->x1, 4),
round($crop->y1, 4),
round($crop->x2, 4),
round($crop->y2, 4),
];
}
// Return config
return $config;
} | php | public function getConfig()
{
// Create default keys for the config
$config = array_merge([
'width' => null,
'height' => null,
'options' => null,
], $this->config);
// Add crops
if ($crop = $this->getAttributeValue('crop_box')) {
if (!is_array($config['options'])) {
$config['options'] = [];
}
$config['options']['trim_perc'] = [
round($crop->x1, 4),
round($crop->y1, 4),
round($crop->x2, 4),
round($crop->y2, 4),
];
}
// Return config
return $config;
} | [
"public",
"function",
"getConfig",
"(",
")",
"{",
"// Create default keys for the config",
"$",
"config",
"=",
"array_merge",
"(",
"[",
"'width'",
"=>",
"null",
",",
"'height'",
"=>",
"null",
",",
"'options'",
"=>",
"null",
",",
"]",
",",
"$",
"this",
"->",
... | Get the config, merging defaults in so that all keys in the array are
present. This also applies the crop choices from the DB.
@return array | [
"Get",
"the",
"config",
"merging",
"defaults",
"in",
"so",
"that",
"all",
"keys",
"in",
"the",
"array",
"are",
"present",
".",
"This",
"also",
"applies",
"the",
"crop",
"choices",
"from",
"the",
"DB",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L258-L282 | train |
BKWLD/decoy | classes/Models/Image.php | Image.urlify | public function urlify($size, $multiplier = 1)
{
// Get fluent config
$config = $this->getConfig();
// Setup vars
$size = $this->sizes[$size];
$scale = $size[0] / $this->bench;
$width = $height = null;
// Figure out percentage sizes. First one of the dimensnios is tested
// to see if it looks a percentage. If so, make it a percentage of one of
// the hard coded sizes. Otherwise, scale the dimension by comaring the
// size to a the benchmark (laptop).
if ($perc = $this->perc($config['width'])) {
$width = $perc * $size[0] * $multiplier;
} elseif ($config['width']) {
$width = $config['width'] * $scale * $multiplier;
}
if ($perc = $this->perc($config['height'])) {
$height = $perc * $size[1] * $multiplier;
} elseif ($config['height']) {
$height = $config['height'] * $scale * $multiplier;
}
// Produce the Croppa URL
$path = Croppa::url($this->getAttributeValue('file'),
$width,
$height,
$config['options']
);
if ($path) {
return asset($path);
}
} | php | public function urlify($size, $multiplier = 1)
{
// Get fluent config
$config = $this->getConfig();
// Setup vars
$size = $this->sizes[$size];
$scale = $size[0] / $this->bench;
$width = $height = null;
// Figure out percentage sizes. First one of the dimensnios is tested
// to see if it looks a percentage. If so, make it a percentage of one of
// the hard coded sizes. Otherwise, scale the dimension by comaring the
// size to a the benchmark (laptop).
if ($perc = $this->perc($config['width'])) {
$width = $perc * $size[0] * $multiplier;
} elseif ($config['width']) {
$width = $config['width'] * $scale * $multiplier;
}
if ($perc = $this->perc($config['height'])) {
$height = $perc * $size[1] * $multiplier;
} elseif ($config['height']) {
$height = $config['height'] * $scale * $multiplier;
}
// Produce the Croppa URL
$path = Croppa::url($this->getAttributeValue('file'),
$width,
$height,
$config['options']
);
if ($path) {
return asset($path);
}
} | [
"public",
"function",
"urlify",
"(",
"$",
"size",
",",
"$",
"multiplier",
"=",
"1",
")",
"{",
"// Get fluent config",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"// Setup vars",
"$",
"size",
"=",
"$",
"this",
"->",
"sizes",
"[",... | Make paths full URLs so these can be used directly in APIs or for Open
Graph tags, for example.
@param string $size
@param number $scale
@return string url | [
"Make",
"paths",
"full",
"URLs",
"so",
"these",
"can",
"be",
"used",
"directly",
"in",
"APIs",
"or",
"for",
"Open",
"Graph",
"tags",
"for",
"example",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L482-L516 | train |
BKWLD/decoy | classes/Commands/Generate.php | Generate.generateModel | private function generateModel()
{
// Figure out the naming
$model = ucfirst($this->argument('model'));
$path = 'app/'.$model.'.php';
$file = base_path().'/'.$path;
// Copy the stub over
if (file_exists($file)) {
return $this->comment('Model already exists: '.$path);
}
file_put_contents($file, str_replace('{{model}}', $model, file_get_contents($this->stubs.'/model.stub')));
$this->info('Model created: '.$path);
} | php | private function generateModel()
{
// Figure out the naming
$model = ucfirst($this->argument('model'));
$path = 'app/'.$model.'.php';
$file = base_path().'/'.$path;
// Copy the stub over
if (file_exists($file)) {
return $this->comment('Model already exists: '.$path);
}
file_put_contents($file, str_replace('{{model}}', $model, file_get_contents($this->stubs.'/model.stub')));
$this->info('Model created: '.$path);
} | [
"private",
"function",
"generateModel",
"(",
")",
"{",
"// Figure out the naming",
"$",
"model",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"argument",
"(",
"'model'",
")",
")",
";",
"$",
"path",
"=",
"'app/'",
".",
"$",
"model",
".",
"'.php'",
";",
"$",
... | Create the model file | [
"Create",
"the",
"model",
"file"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Commands/Generate.php#L49-L62 | train |
BKWLD/decoy | classes/Commands/Generate.php | Generate.generateView | private function generateView()
{
// Figure out the naming
$path = 'resources/views/admin/'
. Str::plural(Str::snake($this->argument('model')))
. '/edit.haml';
$file = base_path().'/'.$path;
// Copy the stub over
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0744, true);
}
if (file_exists($file)) {
return $this->comment('View already exists: '.$path);
}
copy($this->stubs.'/view.stub', $file);
$this->info('View created: '.$path);
} | php | private function generateView()
{
// Figure out the naming
$path = 'resources/views/admin/'
. Str::plural(Str::snake($this->argument('model')))
. '/edit.haml';
$file = base_path().'/'.$path;
// Copy the stub over
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0744, true);
}
if (file_exists($file)) {
return $this->comment('View already exists: '.$path);
}
copy($this->stubs.'/view.stub', $file);
$this->info('View created: '.$path);
} | [
"private",
"function",
"generateView",
"(",
")",
"{",
"// Figure out the naming",
"$",
"path",
"=",
"'resources/views/admin/'",
".",
"Str",
"::",
"plural",
"(",
"Str",
"::",
"snake",
"(",
"$",
"this",
"->",
"argument",
"(",
"'model'",
")",
")",
")",
".",
"... | Create the view file | [
"Create",
"the",
"view",
"file"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Commands/Generate.php#L67-L84 | train |
BKWLD/decoy | classes/Commands/Generate.php | Generate.generateController | private function generateController()
{
// Figure out the naming
$controller = Str::plural(ucfirst($this->argument('model')));
$path = 'app/Http/Controllers/Admin/'.$controller.'.php';
$file = base_path().'/'.$path;
// Copy the stub over
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0744, true);
}
if (file_exists($file)) {
return $this->comment('Controller already exists: '.$path);
}
file_put_contents($file, str_replace('{{controller}}', $controller, file_get_contents($this->stubs.'/controller.stub')));
$this->info('Controller created: '.$path);
} | php | private function generateController()
{
// Figure out the naming
$controller = Str::plural(ucfirst($this->argument('model')));
$path = 'app/Http/Controllers/Admin/'.$controller.'.php';
$file = base_path().'/'.$path;
// Copy the stub over
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0744, true);
}
if (file_exists($file)) {
return $this->comment('Controller already exists: '.$path);
}
file_put_contents($file, str_replace('{{controller}}', $controller, file_get_contents($this->stubs.'/controller.stub')));
$this->info('Controller created: '.$path);
} | [
"private",
"function",
"generateController",
"(",
")",
"{",
"// Figure out the naming",
"$",
"controller",
"=",
"Str",
"::",
"plural",
"(",
"ucfirst",
"(",
"$",
"this",
"->",
"argument",
"(",
"'model'",
")",
")",
")",
";",
"$",
"path",
"=",
"'app/Http/Contro... | Create the controller file | [
"Create",
"the",
"controller",
"file"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Commands/Generate.php#L89-L105 | train |
BKWLD/decoy | classes/Input/Localize.php | Localize.item | public function item($item)
{
if (!$this->model) {
$this->model = get_class($item);
}
$this->item = $item;
return $this;
} | php | public function item($item)
{
if (!$this->model) {
$this->model = get_class($item);
}
$this->item = $item;
return $this;
} | [
"public",
"function",
"item",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"model",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"get_class",
"(",
"$",
"item",
")",
";",
"}",
"$",
"this",
"->",
"item",
"=",
"$",
"item",
";",
"... | Store a model instance
@param Illuminate\Database\Eloquent\Model $item
@return $this | [
"Store",
"a",
"model",
"instance"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Localize.php#L44-L53 | train |
BKWLD/decoy | classes/Input/Localize.php | Localize.hidden | public function hidden()
{
$class = $this->model; // Must be a local var to test
// There aren't multiple locales specified
if (count(config('decoy.site.locales')) <= 1 ) return true;
// We're editing a model with no locale attribute
if ($this->item && !$this->item->locale) return true;
// The model was explicitly disabled
if ($class::$localizable === false ) return true;
// Auto localize is turned on and we're on a child model
if (config('decoy.site.auto_localize_root_models')
&& app('decoy.wildcard')->detectParent()) return true;
// If auto-localizeable is turned off and this model doesn't have it
// turned on
if (!config('decoy.site.auto_localize_root_models')
&& !$class::$localizable) return true;
// Otherwise, allow localization
return false;
} | php | public function hidden()
{
$class = $this->model; // Must be a local var to test
// There aren't multiple locales specified
if (count(config('decoy.site.locales')) <= 1 ) return true;
// We're editing a model with no locale attribute
if ($this->item && !$this->item->locale) return true;
// The model was explicitly disabled
if ($class::$localizable === false ) return true;
// Auto localize is turned on and we're on a child model
if (config('decoy.site.auto_localize_root_models')
&& app('decoy.wildcard')->detectParent()) return true;
// If auto-localizeable is turned off and this model doesn't have it
// turned on
if (!config('decoy.site.auto_localize_root_models')
&& !$class::$localizable) return true;
// Otherwise, allow localization
return false;
} | [
"public",
"function",
"hidden",
"(",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"model",
";",
"// Must be a local var to test",
"// There aren't multiple locales specified",
"if",
"(",
"count",
"(",
"config",
"(",
"'decoy.site.locales'",
")",
")",
"<=",
"1",
... | Check if the localize UI should be displayed
@return boolean | [
"Check",
"if",
"the",
"localize",
"UI",
"should",
"be",
"displayed"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Localize.php#L86-L110 | train |
BKWLD/decoy | classes/Input/Localize.php | Localize.localizableLocales | public function localizableLocales()
{
// Keep only locales that don't exist in ...
return array_diff_key(
Config::get('decoy.site.locales'),
// ... the locales of other localizations ...
$this->other()->pluck('locale')->flip()->toArray(),
// ... and the model's locale
[$this->item->locale => null]
);
} | php | public function localizableLocales()
{
// Keep only locales that don't exist in ...
return array_diff_key(
Config::get('decoy.site.locales'),
// ... the locales of other localizations ...
$this->other()->pluck('locale')->flip()->toArray(),
// ... and the model's locale
[$this->item->locale => null]
);
} | [
"public",
"function",
"localizableLocales",
"(",
")",
"{",
"// Keep only locales that don't exist in ...",
"return",
"array_diff_key",
"(",
"Config",
"::",
"get",
"(",
"'decoy.site.locales'",
")",
",",
"// ... the locales of other localizations ...",
"$",
"this",
"->",
"oth... | Get a hash of locales that are available for the item
@return array | [
"Get",
"a",
"hash",
"of",
"locales",
"that",
"are",
"available",
"for",
"the",
"item"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Localize.php#L117-L129 | train |
BKWLD/decoy | classes/Input/Localize.php | Localize.other | public function other()
{
if ($this->other_localizations === null) {
$this->other_localizations = $this->item->otherLocalizations()->get();
}
return $this->other_localizations;
} | php | public function other()
{
if ($this->other_localizations === null) {
$this->other_localizations = $this->item->otherLocalizations()->get();
}
return $this->other_localizations;
} | [
"public",
"function",
"other",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"other_localizations",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"other_localizations",
"=",
"$",
"this",
"->",
"item",
"->",
"otherLocalizations",
"(",
")",
"->",
"get",
"(",
... | Get other localizations, storing them internally for use in multiple places
@return Illuminate\Database\Eloquent\Collection | [
"Get",
"other",
"localizations",
"storing",
"them",
"internally",
"for",
"use",
"in",
"multiple",
"places"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Localize.php#L136-L143 | train |
BKWLD/decoy | classes/Controllers/Admins.php | Admins.search | public function search()
{
$options = [
'first_name' => [
'label' => __('decoy::admins.controller.search.first_name'),
'type' => 'text',
],
'last_name' => [
'label' => __('decoy::admins.controller.search.last_name'),
'type' => 'text',
],
'email' => [
'label' => __('decoy::admins.controller.search.email'),
'type' => 'text',
],
'status' => [
'label' => __('decoy::admins.controller.search.status'),
'type' => 'select',
'options' => [
1 => __('decoy::admins.controller.search.enabled'),
0 => __('decoy::admins.controller.search.disabled'),
],
],
];
if (($roles = Admin::getRoleTitles()) && count($roles)) {
$options['role'] = [
'label' => __('decoy::admins.controller.search.role'),
'type' => 'select',
'options' => $roles,
];
}
return $options;
} | php | public function search()
{
$options = [
'first_name' => [
'label' => __('decoy::admins.controller.search.first_name'),
'type' => 'text',
],
'last_name' => [
'label' => __('decoy::admins.controller.search.last_name'),
'type' => 'text',
],
'email' => [
'label' => __('decoy::admins.controller.search.email'),
'type' => 'text',
],
'status' => [
'label' => __('decoy::admins.controller.search.status'),
'type' => 'select',
'options' => [
1 => __('decoy::admins.controller.search.enabled'),
0 => __('decoy::admins.controller.search.disabled'),
],
],
];
if (($roles = Admin::getRoleTitles()) && count($roles)) {
$options['role'] = [
'label' => __('decoy::admins.controller.search.role'),
'type' => 'select',
'options' => $roles,
];
}
return $options;
} | [
"public",
"function",
"search",
"(",
")",
"{",
"$",
"options",
"=",
"[",
"'first_name'",
"=>",
"[",
"'label'",
"=>",
"__",
"(",
"'decoy::admins.controller.search.first_name'",
")",
",",
"'type'",
"=>",
"'text'",
",",
"]",
",",
"'last_name'",
"=>",
"[",
"'lab... | Make search options dependent on whether the site is using roles
@return array | [
"Make",
"search",
"options",
"dependent",
"on",
"whether",
"the",
"site",
"is",
"using",
"roles"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Admins.php#L26-L60 | train |
BKWLD/decoy | classes/Controllers/Admins.php | Admins.update | public function update($id)
{
// Encorce permissions on updating ones own role
if (!app('decoy.user')->can('update', 'admins') && Request::has('role')) {
throw new AccessDeniedHttpException;
}
// If the password is empty, remove the key from the input so it isn't cleared
if (!Request::has('password')) {
Request::replace(array_except(Request::input(), ['password']));
}
// Continue processing
return parent::update($id);
} | php | public function update($id)
{
// Encorce permissions on updating ones own role
if (!app('decoy.user')->can('update', 'admins') && Request::has('role')) {
throw new AccessDeniedHttpException;
}
// If the password is empty, remove the key from the input so it isn't cleared
if (!Request::has('password')) {
Request::replace(array_except(Request::input(), ['password']));
}
// Continue processing
return parent::update($id);
} | [
"public",
"function",
"update",
"(",
"$",
"id",
")",
"{",
"// Encorce permissions on updating ones own role",
"if",
"(",
"!",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'update'",
",",
"'admins'",
")",
"&&",
"Request",
"::",
"has",
"(",
"'role'",
")... | Don't let unauthorize folks update their role by passing in role values
in the GET
@param int $id Model key
@throws AccessDeniedHttpException
@return Symfony\Component\HttpFoundation\Response | [
"Don",
"t",
"let",
"unauthorize",
"folks",
"update",
"their",
"role",
"by",
"passing",
"in",
"role",
"values",
"in",
"the",
"GET"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Admins.php#L110-L124 | train |
BKWLD/decoy | classes/Controllers/Admins.php | Admins.enable | public function enable($id)
{
if (!app('decoy.user')->can('grant', 'admins')) {
throw new AccessDeniedHttpException;
}
if (!($admin = Admin::find($id))) {
return App::abort(404);
}
$admin->active = 1;
$admin->save();
return Redirect::back();
} | php | public function enable($id)
{
if (!app('decoy.user')->can('grant', 'admins')) {
throw new AccessDeniedHttpException;
}
if (!($admin = Admin::find($id))) {
return App::abort(404);
}
$admin->active = 1;
$admin->save();
return Redirect::back();
} | [
"public",
"function",
"enable",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'grant'",
",",
"'admins'",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
";",
"}",
"if",
"(",
"!",
"(",
"$",
... | Enable the admin
@return Illuminate\Http\RedirectResponse | [
"Enable",
"the",
"admin"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Admins.php#L152-L166 | train |
BKWLD/decoy | classes/Controllers/Base.php | Base.init | private function init()
{
// Set the layout from the Config file
$this->layout = View::make(config('decoy.core.layout'));
// Store the controller class for routing
$this->controller = get_class($this);
// Get the controller name
$controller_name = $this->controllerName($this->controller);
// Make a default title based on the controller name
if (empty($this->title)) {
$this->title = $this->title($controller_name);
}
// Figure out what the show view should be. This is the path to the show
// view file. Such as 'admin.news.edit'
if (empty($this->show_view)) {
$this->show_view = $this->detailPath($this->controller);
}
// Try to suss out the model by singularizing the controller
if (empty($this->model)) {
$this->model = $this->model($this->controller);
if (!class_exists($this->model)) {
$this->model = null;
}
}
// If the input contains info on the parent, immediately instantiate
// the parent instance. These are populated by some AJAX calls like
// autocomplete on a many to many and the attach method.
if (($parent_id = request('parent_id'))
&& ($parent_controller = request('parent_controller'))) {
$parent_model_class = $this->model($parent_controller);
$this->parent($parent_model_class::findOrFail($parent_id));
}
} | php | private function init()
{
// Set the layout from the Config file
$this->layout = View::make(config('decoy.core.layout'));
// Store the controller class for routing
$this->controller = get_class($this);
// Get the controller name
$controller_name = $this->controllerName($this->controller);
// Make a default title based on the controller name
if (empty($this->title)) {
$this->title = $this->title($controller_name);
}
// Figure out what the show view should be. This is the path to the show
// view file. Such as 'admin.news.edit'
if (empty($this->show_view)) {
$this->show_view = $this->detailPath($this->controller);
}
// Try to suss out the model by singularizing the controller
if (empty($this->model)) {
$this->model = $this->model($this->controller);
if (!class_exists($this->model)) {
$this->model = null;
}
}
// If the input contains info on the parent, immediately instantiate
// the parent instance. These are populated by some AJAX calls like
// autocomplete on a many to many and the attach method.
if (($parent_id = request('parent_id'))
&& ($parent_controller = request('parent_controller'))) {
$parent_model_class = $this->model($parent_controller);
$this->parent($parent_model_class::findOrFail($parent_id));
}
} | [
"private",
"function",
"init",
"(",
")",
"{",
"// Set the layout from the Config file",
"$",
"this",
"->",
"layout",
"=",
"View",
"::",
"make",
"(",
"config",
"(",
"'decoy.core.layout'",
")",
")",
";",
"// Store the controller class for routing",
"$",
"this",
"->",
... | Populate the controller's protected properties
@return void | [
"Populate",
"the",
"controller",
"s",
"protected",
"properties"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L180-L218 | train |
BKWLD/decoy | classes/Controllers/Base.php | Base.title | public function title($controller_name = null)
{
// For when this is invoked as a getter for $this->title
if (!$controller_name) {
return $this->title;
}
// Do the de-studlying
preg_match_all('#[a-z]+|[A-Z][a-z]*#', $controller_name, $matches);
return implode(" ", $matches[0]);
} | php | public function title($controller_name = null)
{
// For when this is invoked as a getter for $this->title
if (!$controller_name) {
return $this->title;
}
// Do the de-studlying
preg_match_all('#[a-z]+|[A-Z][a-z]*#', $controller_name, $matches);
return implode(" ", $matches[0]);
} | [
"public",
"function",
"title",
"(",
"$",
"controller_name",
"=",
"null",
")",
"{",
"// For when this is invoked as a getter for $this->title",
"if",
"(",
"!",
"$",
"controller_name",
")",
"{",
"return",
"$",
"this",
"->",
"title",
";",
"}",
"// Do the de-studlying",... | Get the title for the controller based on the controller name. Basically,
it's a de-studdly-er
@param string $controller_name ex: 'Admins' or 'CarLovers'
@return string ex: 'Admins' or 'Car Lovers' | [
"Get",
"the",
"title",
"for",
"the",
"controller",
"based",
"on",
"the",
"controller",
"name",
".",
"Basically",
"it",
"s",
"a",
"de",
"-",
"studdly",
"-",
"er"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L247-L258 | train |
BKWLD/decoy | classes/Controllers/Base.php | Base.detailPath | public function detailPath($class)
{
// Remove Decoy from the class
$path = str_replace('Bkwld\Decoy\Controllers\\', '', $class, $is_decoy);
// Remove the App controller prefix
$path = str_replace('App\Http\Controllers\\', '', $path);
// Break up all the remainder of the class and de-study them (which is what
// title() does)
$parts = explode('\\', $path);
foreach ($parts as &$part) {
$part = str_replace(' ', '_', strtolower($this->title($part)));
}
$path = implode('.', $parts);
// If the controller is part of Decoy, add it to the path
if ($is_decoy) {
$path = 'decoy::'.$path;
}
// Done
return $path.'.edit';
} | php | public function detailPath($class)
{
// Remove Decoy from the class
$path = str_replace('Bkwld\Decoy\Controllers\\', '', $class, $is_decoy);
// Remove the App controller prefix
$path = str_replace('App\Http\Controllers\\', '', $path);
// Break up all the remainder of the class and de-study them (which is what
// title() does)
$parts = explode('\\', $path);
foreach ($parts as &$part) {
$part = str_replace(' ', '_', strtolower($this->title($part)));
}
$path = implode('.', $parts);
// If the controller is part of Decoy, add it to the path
if ($is_decoy) {
$path = 'decoy::'.$path;
}
// Done
return $path.'.edit';
} | [
"public",
"function",
"detailPath",
"(",
"$",
"class",
")",
"{",
"// Remove Decoy from the class",
"$",
"path",
"=",
"str_replace",
"(",
"'Bkwld\\Decoy\\Controllers\\\\'",
",",
"''",
",",
"$",
"class",
",",
"$",
"is_decoy",
")",
";",
"// Remove the App controller pr... | Get the directory for the detail views. It's based off the controller name.
This is basically a conversion to snake case from studyly case
@param string $class ex: 'Admin\NewsController'
@return string ex: admins.edit or car_lovers.edit | [
"Get",
"the",
"directory",
"for",
"the",
"detail",
"views",
".",
"It",
"s",
"based",
"off",
"the",
"controller",
"name",
".",
"This",
"is",
"basically",
"a",
"conversion",
"to",
"snake",
"case",
"from",
"studyly",
"case"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L311-L336 | train |
BKWLD/decoy | classes/Controllers/Base.php | Base.parent | public function parent($parent)
{
// Save out the passed reference
$this->parent = $parent;
// Save out sub properties that I hope to deprecate
$this->parent_model = get_class($this->parent);
$this->parent_controller = Decoy::controllerForModel($this->parent_model);
// Figure out what the relationship function to the child (this controller's
// model) on the parent model . It will be the plural version of this
// model's name.
$this->parent_to_self = Decoy::hasManyName($this->model);
// If the parent is the same as this controller, assume that it's a
// many-to-many-to-self relationship. Thus, expect a relationship method to
// be defined on the model called "RELATIONSHIPAsChild". I.e. "postsAsChild"
if ($this->parent_controller == $this->controller && method_exists($this->model, $this->parent_to_self.'AsChild')) {
$this->self_to_parent = $this->parent_to_self.'AsChild';
// If the parent relationship is a polymorphic one-many, then the
// relationship function on the child model will be the model name plus
// "able". For instance, the Link model would have it's relationship to
// parent called "linkable".
} elseif (is_a($this->parentRelation(), 'Illuminate\Database\Eloquent\Relations\MorphMany')) {
$this->self_to_parent = Decoy::belongsToName($this->model).'able';
// Save out to self to parent relationship. It will be singular if the
// relationship is a many to many.
} else {
$this->self_to_parent = $this->isChildInManyToMany()?
Decoy::hasManyName($this->parent_model):
Decoy::belongsToName($this->parent_model);
}
// Make chainable
return $this;
} | php | public function parent($parent)
{
// Save out the passed reference
$this->parent = $parent;
// Save out sub properties that I hope to deprecate
$this->parent_model = get_class($this->parent);
$this->parent_controller = Decoy::controllerForModel($this->parent_model);
// Figure out what the relationship function to the child (this controller's
// model) on the parent model . It will be the plural version of this
// model's name.
$this->parent_to_self = Decoy::hasManyName($this->model);
// If the parent is the same as this controller, assume that it's a
// many-to-many-to-self relationship. Thus, expect a relationship method to
// be defined on the model called "RELATIONSHIPAsChild". I.e. "postsAsChild"
if ($this->parent_controller == $this->controller && method_exists($this->model, $this->parent_to_self.'AsChild')) {
$this->self_to_parent = $this->parent_to_self.'AsChild';
// If the parent relationship is a polymorphic one-many, then the
// relationship function on the child model will be the model name plus
// "able". For instance, the Link model would have it's relationship to
// parent called "linkable".
} elseif (is_a($this->parentRelation(), 'Illuminate\Database\Eloquent\Relations\MorphMany')) {
$this->self_to_parent = Decoy::belongsToName($this->model).'able';
// Save out to self to parent relationship. It will be singular if the
// relationship is a many to many.
} else {
$this->self_to_parent = $this->isChildInManyToMany()?
Decoy::hasManyName($this->parent_model):
Decoy::belongsToName($this->parent_model);
}
// Make chainable
return $this;
} | [
"public",
"function",
"parent",
"(",
"$",
"parent",
")",
"{",
"// Save out the passed reference",
"$",
"this",
"->",
"parent",
"=",
"$",
"parent",
";",
"// Save out sub properties that I hope to deprecate",
"$",
"this",
"->",
"parent_model",
"=",
"get_class",
"(",
"... | Give this controller a parent model instance. For instance, this makes the
index view a listing of just the children of the parent.
@param Illuminate\Database\Eloquent\Model $parent
@return $this | [
"Give",
"this",
"controller",
"a",
"parent",
"model",
"instance",
".",
"For",
"instance",
"this",
"makes",
"the",
"index",
"view",
"a",
"listing",
"of",
"just",
"the",
"children",
"of",
"the",
"parent",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L360-L397 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.