id
int32 0
241k
| 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
224,000
|
secrethash/trickster
|
src/Trickster.php
|
Trickster.currencyConvert
|
public function currencyConvert($amount, $from, $to)
{
if($from===$to)
{
return round($amount, 2);
}
if ($this->_currencyConverter==='currencylayer')
{
return self::currencyLayerConvert($amount, $from, $to);
}
elseif ($this->_currencyConverter==='exchangerate')
{
return self::exchangeRateConvert($amount, $from, $to);
}
return self::smartConvert($amount, $from, $to);
}
|
php
|
public function currencyConvert($amount, $from, $to)
{
if($from===$to)
{
return round($amount, 2);
}
if ($this->_currencyConverter==='currencylayer')
{
return self::currencyLayerConvert($amount, $from, $to);
}
elseif ($this->_currencyConverter==='exchangerate')
{
return self::exchangeRateConvert($amount, $from, $to);
}
return self::smartConvert($amount, $from, $to);
}
|
[
"public",
"function",
"currencyConvert",
"(",
"$",
"amount",
",",
"$",
"from",
",",
"$",
"to",
")",
"{",
"if",
"(",
"$",
"from",
"===",
"$",
"to",
")",
"{",
"return",
"round",
"(",
"$",
"amount",
",",
"2",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_currencyConverter",
"===",
"'currencylayer'",
")",
"{",
"return",
"self",
"::",
"currencyLayerConvert",
"(",
"$",
"amount",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_currencyConverter",
"===",
"'exchangerate'",
")",
"{",
"return",
"self",
"::",
"exchangeRateConvert",
"(",
"$",
"amount",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"}",
"return",
"self",
"::",
"smartConvert",
"(",
"$",
"amount",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"}"
] |
This function converts the currency in desired form.
@access public
@param init $amount Amount to be converted
@param string $from Currency Code to convert "from"
@param string $to Currency code to convert "to" Default=INR
@return string Return json data
|
[
"This",
"function",
"converts",
"the",
"currency",
"in",
"desired",
"form",
"."
] |
8105dc7c028bc9b56988a339a4422c19e2185d83
|
https://github.com/secrethash/trickster/blob/8105dc7c028bc9b56988a339a4422c19e2185d83/src/Trickster.php#L606-L625
|
224,001
|
secrethash/trickster
|
src/Trickster.php
|
Trickster.smartConvert
|
public function smartConvert($amount, $from, $to)
{
// Smart Convert Logic
Log::info('Running Smart Currency Conversion');
if ($this->_currencyLayerApiKey != NULL)
{
$conv = self::currencyLayerConvert($amount, $from, $to);
if(!$conv)
{
if ($this->_exchangeRateApiKey != NULL)
{
return self::exchangeRateConvert($amount, $from, $to);
}
return false;
}
return $conv;
}
elseif ($this->_exchangeRateApiKey != NULL)
{
return self::exchangeRateConvert($amount, $from, $to);
}
return false;
}
|
php
|
public function smartConvert($amount, $from, $to)
{
// Smart Convert Logic
Log::info('Running Smart Currency Conversion');
if ($this->_currencyLayerApiKey != NULL)
{
$conv = self::currencyLayerConvert($amount, $from, $to);
if(!$conv)
{
if ($this->_exchangeRateApiKey != NULL)
{
return self::exchangeRateConvert($amount, $from, $to);
}
return false;
}
return $conv;
}
elseif ($this->_exchangeRateApiKey != NULL)
{
return self::exchangeRateConvert($amount, $from, $to);
}
return false;
}
|
[
"public",
"function",
"smartConvert",
"(",
"$",
"amount",
",",
"$",
"from",
",",
"$",
"to",
")",
"{",
"// Smart Convert Logic",
"Log",
"::",
"info",
"(",
"'Running Smart Currency Conversion'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_currencyLayerApiKey",
"!=",
"NULL",
")",
"{",
"$",
"conv",
"=",
"self",
"::",
"currencyLayerConvert",
"(",
"$",
"amount",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"if",
"(",
"!",
"$",
"conv",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_exchangeRateApiKey",
"!=",
"NULL",
")",
"{",
"return",
"self",
"::",
"exchangeRateConvert",
"(",
"$",
"amount",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"}",
"return",
"false",
";",
"}",
"return",
"$",
"conv",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_exchangeRateApiKey",
"!=",
"NULL",
")",
"{",
"return",
"self",
"::",
"exchangeRateConvert",
"(",
"$",
"amount",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Smart Currency Conversion
This uses the activated APIs and increases your monthly quotas
@return float
|
[
"Smart",
"Currency",
"Conversion",
"This",
"uses",
"the",
"activated",
"APIs",
"and",
"increases",
"your",
"monthly",
"quotas"
] |
8105dc7c028bc9b56988a339a4422c19e2185d83
|
https://github.com/secrethash/trickster/blob/8105dc7c028bc9b56988a339a4422c19e2185d83/src/Trickster.php#L715-L741
|
224,002
|
secrethash/trickster
|
src/Trickster.php
|
Trickster.exchangeRateCalculate
|
protected function exchangeRateCalculate($rate, $amount)
{
// code
$conv = $amount * $rate;
$resque = round($conv, 2);
return $resque;
}
|
php
|
protected function exchangeRateCalculate($rate, $amount)
{
// code
$conv = $amount * $rate;
$resque = round($conv, 2);
return $resque;
}
|
[
"protected",
"function",
"exchangeRateCalculate",
"(",
"$",
"rate",
",",
"$",
"amount",
")",
"{",
"// code",
"$",
"conv",
"=",
"$",
"amount",
"*",
"$",
"rate",
";",
"$",
"resque",
"=",
"round",
"(",
"$",
"conv",
",",
"2",
")",
";",
"return",
"$",
"resque",
";",
"}"
] |
Calculation of the converted currency
@access protected
@return float
|
[
"Calculation",
"of",
"the",
"converted",
"currency"
] |
8105dc7c028bc9b56988a339a4422c19e2185d83
|
https://github.com/secrethash/trickster/blob/8105dc7c028bc9b56988a339a4422c19e2185d83/src/Trickster.php#L747-L753
|
224,003
|
secrethash/trickster
|
src/Trickster.php
|
Trickster._socialCurl
|
private function _socialCurl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/json'));
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
return $result;
}
|
php
|
private function _socialCurl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/json'));
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
return $result;
}
|
[
"private",
"function",
"_socialCurl",
"(",
"$",
"url",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"array",
"(",
"'Content-Type: text/json'",
")",
")",
";",
"$",
"result",
"=",
"json_decode",
"(",
"curl_exec",
"(",
"$",
"ch",
")",
",",
"true",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
This function used for return tweets and likes with curl
@access private
@param string $url Url need for curl to get data
@return string Return json data
|
[
"This",
"function",
"used",
"for",
"return",
"tweets",
"and",
"likes",
"with",
"curl"
] |
8105dc7c028bc9b56988a339a4422c19e2185d83
|
https://github.com/secrethash/trickster/blob/8105dc7c028bc9b56988a339a4422c19e2185d83/src/Trickster.php#L769-L778
|
224,004
|
blar/openssl
|
lib/Blar/OpenSSL/CertificateSigningRequestGenerator.php
|
CertificateSigningRequestGenerator.writeCustomConfigFile
|
protected function writeCustomConfigFile(string $fileName, array $subjectAltNames) {
$content = implode(PHP_EOL, [
'[req]',
'prompt = no',
'string_mask = utf8only',
'distinguished_name = req_distinguished_name',
'[req_distinguished_name]',
'[req_extensions]',
'subjectAltName = '.implode(',', $subjectAltNames)
]);
file_put_contents($fileName, $content);
}
|
php
|
protected function writeCustomConfigFile(string $fileName, array $subjectAltNames) {
$content = implode(PHP_EOL, [
'[req]',
'prompt = no',
'string_mask = utf8only',
'distinguished_name = req_distinguished_name',
'[req_distinguished_name]',
'[req_extensions]',
'subjectAltName = '.implode(',', $subjectAltNames)
]);
file_put_contents($fileName, $content);
}
|
[
"protected",
"function",
"writeCustomConfigFile",
"(",
"string",
"$",
"fileName",
",",
"array",
"$",
"subjectAltNames",
")",
"{",
"$",
"content",
"=",
"implode",
"(",
"PHP_EOL",
",",
"[",
"'[req]'",
",",
"'prompt = no'",
",",
"'string_mask = utf8only'",
",",
"'distinguished_name = req_distinguished_name'",
",",
"'[req_distinguished_name]'",
",",
"'[req_extensions]'",
",",
"'subjectAltName = '",
".",
"implode",
"(",
"','",
",",
"$",
"subjectAltNames",
")",
"]",
")",
";",
"file_put_contents",
"(",
"$",
"fileName",
",",
"$",
"content",
")",
";",
"}"
] |
The subjectAltName can only be defined in the openssl config. So we need a temporary config file.
@param string $fileName
@param array $subjectAltNames
|
[
"The",
"subjectAltName",
"can",
"only",
"be",
"defined",
"in",
"the",
"openssl",
"config",
".",
"So",
"we",
"need",
"a",
"temporary",
"config",
"file",
"."
] |
9a7faf31492cefe8c8b166ef775a6e2eba04c3ec
|
https://github.com/blar/openssl/blob/9a7faf31492cefe8c8b166ef775a6e2eba04c3ec/lib/Blar/OpenSSL/CertificateSigningRequestGenerator.php#L161-L172
|
224,005
|
Eluinhost/minecraft-auth
|
src/Protocol/DataTypeEncoders/VarInt.php
|
VarInt.read
|
private static function read($fd, $length)
{
$bytes = fread($fd, $length);
if (false === $bytes) {
return false;
}
return $bytes;
}
|
php
|
private static function read($fd, $length)
{
$bytes = fread($fd, $length);
if (false === $bytes) {
return false;
}
return $bytes;
}
|
[
"private",
"static",
"function",
"read",
"(",
"$",
"fd",
",",
"$",
"length",
")",
"{",
"$",
"bytes",
"=",
"fread",
"(",
"$",
"fd",
",",
"$",
"length",
")",
";",
"if",
"(",
"false",
"===",
"$",
"bytes",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"bytes",
";",
"}"
] |
Reads from the stream
@param $fd resource the stream to read from
@param $length int the length to read
@return string|false the read bytes or false if read failed
|
[
"Reads",
"from",
"the",
"stream"
] |
ebe9a09d1de45dbc765545137514c8cf7c8e075f
|
https://github.com/Eluinhost/minecraft-auth/blob/ebe9a09d1de45dbc765545137514c8cf7c8e075f/src/Protocol/DataTypeEncoders/VarInt.php#L15-L23
|
224,006
|
Eluinhost/minecraft-auth
|
src/Protocol/DataTypeEncoders/VarInt.php
|
VarInt.readUnsignedVarInt
|
public static function readUnsignedVarInt($data)
{
$fd = fopen('data://text/plain,' . urlencode($data), 'rb');
$original = '';
$result = $shift = 0;
do {
$readValue = self::read($fd, 1);
if(false === $readValue || $readValue === null) {
return false;
}
$original .= $readValue;
$byte = ord($readValue);
$result |= ($byte & 0x7f) << $shift++ * 7;
if($shift > 5) {
throw new InvalidDataException('VarInt greater than allowed range');
}
} while ($byte > 0x7f);
return new VarInt($result, $original, $shift);
}
|
php
|
public static function readUnsignedVarInt($data)
{
$fd = fopen('data://text/plain,' . urlencode($data), 'rb');
$original = '';
$result = $shift = 0;
do {
$readValue = self::read($fd, 1);
if(false === $readValue || $readValue === null) {
return false;
}
$original .= $readValue;
$byte = ord($readValue);
$result |= ($byte & 0x7f) << $shift++ * 7;
if($shift > 5) {
throw new InvalidDataException('VarInt greater than allowed range');
}
} while ($byte > 0x7f);
return new VarInt($result, $original, $shift);
}
|
[
"public",
"static",
"function",
"readUnsignedVarInt",
"(",
"$",
"data",
")",
"{",
"$",
"fd",
"=",
"fopen",
"(",
"'data://text/plain,'",
".",
"urlencode",
"(",
"$",
"data",
")",
",",
"'rb'",
")",
";",
"$",
"original",
"=",
"''",
";",
"$",
"result",
"=",
"$",
"shift",
"=",
"0",
";",
"do",
"{",
"$",
"readValue",
"=",
"self",
"::",
"read",
"(",
"$",
"fd",
",",
"1",
")",
";",
"if",
"(",
"false",
"===",
"$",
"readValue",
"||",
"$",
"readValue",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"original",
".=",
"$",
"readValue",
";",
"$",
"byte",
"=",
"ord",
"(",
"$",
"readValue",
")",
";",
"$",
"result",
"|=",
"(",
"$",
"byte",
"&",
"0x7f",
")",
"<<",
"$",
"shift",
"++",
"*",
"7",
";",
"if",
"(",
"$",
"shift",
">",
"5",
")",
"{",
"throw",
"new",
"InvalidDataException",
"(",
"'VarInt greater than allowed range'",
")",
";",
"}",
"}",
"while",
"(",
"$",
"byte",
">",
"0x7f",
")",
";",
"return",
"new",
"VarInt",
"(",
"$",
"result",
",",
"$",
"original",
",",
"$",
"shift",
")",
";",
"}"
] |
Read a varint from beginning of the string.
@param $data String the data
@throws InvalidDataException on invalid data
@return VarInt|false the parsed VarInt if parsed, false if not enough data
|
[
"Read",
"a",
"varint",
"from",
"beginning",
"of",
"the",
"string",
"."
] |
ebe9a09d1de45dbc765545137514c8cf7c8e075f
|
https://github.com/Eluinhost/minecraft-auth/blob/ebe9a09d1de45dbc765545137514c8cf7c8e075f/src/Protocol/DataTypeEncoders/VarInt.php#L32-L53
|
224,007
|
Eluinhost/minecraft-auth
|
src/Protocol/DataTypeEncoders/VarInt.php
|
VarInt.writeUnsignedVarInt
|
public static function writeUnsignedVarInt($data) {
if($data < 0) {
throw new InvalidDataException('Cannot write negative values');
}
$orig = $data;
//single bytes don't need encoding
if ($data < 0x80) {
return new VarInt($data, pack('C', $data), 1);
}
$encodedBytes = [];
while ($data > 0) {
$encodedBytes[] = 0x80 | ($data & 0x7f);
$data >>= 7;
}
//remove most sig bit from final value
$encodedBytes[count($encodedBytes)-1] &= 0x7f;
//build the actual bytes from the encoded array
$bytes = call_user_func_array('pack', array_merge(array('C*'), $encodedBytes));;
return new VarInt($orig, $bytes, strlen($bytes));
}
|
php
|
public static function writeUnsignedVarInt($data) {
if($data < 0) {
throw new InvalidDataException('Cannot write negative values');
}
$orig = $data;
//single bytes don't need encoding
if ($data < 0x80) {
return new VarInt($data, pack('C', $data), 1);
}
$encodedBytes = [];
while ($data > 0) {
$encodedBytes[] = 0x80 | ($data & 0x7f);
$data >>= 7;
}
//remove most sig bit from final value
$encodedBytes[count($encodedBytes)-1] &= 0x7f;
//build the actual bytes from the encoded array
$bytes = call_user_func_array('pack', array_merge(array('C*'), $encodedBytes));;
return new VarInt($orig, $bytes, strlen($bytes));
}
|
[
"public",
"static",
"function",
"writeUnsignedVarInt",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidDataException",
"(",
"'Cannot write negative values'",
")",
";",
"}",
"$",
"orig",
"=",
"$",
"data",
";",
"//single bytes don't need encoding",
"if",
"(",
"$",
"data",
"<",
"0x80",
")",
"{",
"return",
"new",
"VarInt",
"(",
"$",
"data",
",",
"pack",
"(",
"'C'",
",",
"$",
"data",
")",
",",
"1",
")",
";",
"}",
"$",
"encodedBytes",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"data",
">",
"0",
")",
"{",
"$",
"encodedBytes",
"[",
"]",
"=",
"0x80",
"|",
"(",
"$",
"data",
"&",
"0x7f",
")",
";",
"$",
"data",
">>=",
"7",
";",
"}",
"//remove most sig bit from final value",
"$",
"encodedBytes",
"[",
"count",
"(",
"$",
"encodedBytes",
")",
"-",
"1",
"]",
"&=",
"0x7f",
";",
"//build the actual bytes from the encoded array",
"$",
"bytes",
"=",
"call_user_func_array",
"(",
"'pack'",
",",
"array_merge",
"(",
"array",
"(",
"'C*'",
")",
",",
"$",
"encodedBytes",
")",
")",
";",
";",
"return",
"new",
"VarInt",
"(",
"$",
"orig",
",",
"$",
"bytes",
",",
"strlen",
"(",
"$",
"bytes",
")",
")",
";",
"}"
] |
Writes a VarInt
@param $data int the value to write
@return VarInt the encoded value
@throws InvalidDataException
|
[
"Writes",
"a",
"VarInt"
] |
ebe9a09d1de45dbc765545137514c8cf7c8e075f
|
https://github.com/Eluinhost/minecraft-auth/blob/ebe9a09d1de45dbc765545137514c8cf7c8e075f/src/Protocol/DataTypeEncoders/VarInt.php#L62-L86
|
224,008
|
Eluinhost/minecraft-auth
|
src/Protocol/Packets/HandshakePacket.php
|
HandshakePacket.fromRawData
|
function fromRawData($data)
{
$versionVarInt = VarInt::readUnsignedVarInt($data);
$data = substr($data, $versionVarInt->getDataLength());
$addressStringLength = VarInt::readUnsignedVarInt($data);
$data = substr($data, $addressStringLength->getDataLength());
$address = substr($data, 0, $addressStringLength->getValue());
$data = substr($data, $addressStringLength->getValue());
$portShort = unpack('nshort', substr($data, 0, 2))['short'];
$data = substr($data, 2);
$nextVarInt = VarInt::readUnsignedVarInt($data);
try {
$nextStage = Stage::get($nextVarInt->getValue());
//disconnect if not a valid stage
if ($nextStage != Stage::LOGIN() && $nextStage != Stage::STATUS()) {
throw new InvalidDataException('Stage must be LOGIN or STATUS on handshake');
}
//set all of the data
$this->setNextStage($nextStage)
->setServerPort($portShort)
->setProtocolVersion($versionVarInt->getValue())
->setServerAddress($address);
} catch (InvalidArgumentException $ex) {
throw new InvalidDataException('Stage is not a valid number');
}
}
|
php
|
function fromRawData($data)
{
$versionVarInt = VarInt::readUnsignedVarInt($data);
$data = substr($data, $versionVarInt->getDataLength());
$addressStringLength = VarInt::readUnsignedVarInt($data);
$data = substr($data, $addressStringLength->getDataLength());
$address = substr($data, 0, $addressStringLength->getValue());
$data = substr($data, $addressStringLength->getValue());
$portShort = unpack('nshort', substr($data, 0, 2))['short'];
$data = substr($data, 2);
$nextVarInt = VarInt::readUnsignedVarInt($data);
try {
$nextStage = Stage::get($nextVarInt->getValue());
//disconnect if not a valid stage
if ($nextStage != Stage::LOGIN() && $nextStage != Stage::STATUS()) {
throw new InvalidDataException('Stage must be LOGIN or STATUS on handshake');
}
//set all of the data
$this->setNextStage($nextStage)
->setServerPort($portShort)
->setProtocolVersion($versionVarInt->getValue())
->setServerAddress($address);
} catch (InvalidArgumentException $ex) {
throw new InvalidDataException('Stage is not a valid number');
}
}
|
[
"function",
"fromRawData",
"(",
"$",
"data",
")",
"{",
"$",
"versionVarInt",
"=",
"VarInt",
"::",
"readUnsignedVarInt",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"$",
"versionVarInt",
"->",
"getDataLength",
"(",
")",
")",
";",
"$",
"addressStringLength",
"=",
"VarInt",
"::",
"readUnsignedVarInt",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"$",
"addressStringLength",
"->",
"getDataLength",
"(",
")",
")",
";",
"$",
"address",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"$",
"addressStringLength",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"$",
"addressStringLength",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"portShort",
"=",
"unpack",
"(",
"'nshort'",
",",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"2",
")",
")",
"[",
"'short'",
"]",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"2",
")",
";",
"$",
"nextVarInt",
"=",
"VarInt",
"::",
"readUnsignedVarInt",
"(",
"$",
"data",
")",
";",
"try",
"{",
"$",
"nextStage",
"=",
"Stage",
"::",
"get",
"(",
"$",
"nextVarInt",
"->",
"getValue",
"(",
")",
")",
";",
"//disconnect if not a valid stage",
"if",
"(",
"$",
"nextStage",
"!=",
"Stage",
"::",
"LOGIN",
"(",
")",
"&&",
"$",
"nextStage",
"!=",
"Stage",
"::",
"STATUS",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidDataException",
"(",
"'Stage must be LOGIN or STATUS on handshake'",
")",
";",
"}",
"//set all of the data",
"$",
"this",
"->",
"setNextStage",
"(",
"$",
"nextStage",
")",
"->",
"setServerPort",
"(",
"$",
"portShort",
")",
"->",
"setProtocolVersion",
"(",
"$",
"versionVarInt",
"->",
"getValue",
"(",
")",
")",
"->",
"setServerAddress",
"(",
"$",
"address",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"ex",
")",
"{",
"throw",
"new",
"InvalidDataException",
"(",
"'Stage is not a valid number'",
")",
";",
"}",
"}"
] |
Parse the raw data
@param $data String the raw data to parse (minus packet ID and packet length
@throws InvalidDataException
|
[
"Parse",
"the",
"raw",
"data"
] |
ebe9a09d1de45dbc765545137514c8cf7c8e075f
|
https://github.com/Eluinhost/minecraft-auth/blob/ebe9a09d1de45dbc765545137514c8cf7c8e075f/src/Protocol/Packets/HandshakePacket.php#L115-L147
|
224,009
|
blar/openssl
|
lib/Blar/OpenSSL/CertificateSigningRequestSigner.php
|
CertificateSigningRequestSigner.setPkcs12
|
public function setPkcs12(Pkcs12 $pkcs12) {
$this->setCertificate($pkcs12->getCertificate());
$this->setPrivateKey($pkcs12->getPrivateKey());
}
|
php
|
public function setPkcs12(Pkcs12 $pkcs12) {
$this->setCertificate($pkcs12->getCertificate());
$this->setPrivateKey($pkcs12->getPrivateKey());
}
|
[
"public",
"function",
"setPkcs12",
"(",
"Pkcs12",
"$",
"pkcs12",
")",
"{",
"$",
"this",
"->",
"setCertificate",
"(",
"$",
"pkcs12",
"->",
"getCertificate",
"(",
")",
")",
";",
"$",
"this",
"->",
"setPrivateKey",
"(",
"$",
"pkcs12",
"->",
"getPrivateKey",
"(",
")",
")",
";",
"}"
] |
Set private key and certificate of the certificate authority from PKCS12.
@param Pkcs12 $pkcs12
|
[
"Set",
"private",
"key",
"and",
"certificate",
"of",
"the",
"certificate",
"authority",
"from",
"PKCS12",
"."
] |
9a7faf31492cefe8c8b166ef775a6e2eba04c3ec
|
https://github.com/blar/openssl/blob/9a7faf31492cefe8c8b166ef775a6e2eba04c3ec/lib/Blar/OpenSSL/CertificateSigningRequestSigner.php#L83-L86
|
224,010
|
blar/openssl
|
lib/Blar/OpenSSL/CertificateSigningRequestSigner.php
|
CertificateSigningRequestSigner.sign
|
public function sign(CertificateSigningRequest $csr, int $serial = 0): Certificate {
$certificate = openssl_csr_sign(
$csr->export(),
$this->getCertificate(),
$this->getPrivateKey(),
$this->getLifetime(),
$this->getOptions(),
$serial
);
return new Certificate($certificate);
}
|
php
|
public function sign(CertificateSigningRequest $csr, int $serial = 0): Certificate {
$certificate = openssl_csr_sign(
$csr->export(),
$this->getCertificate(),
$this->getPrivateKey(),
$this->getLifetime(),
$this->getOptions(),
$serial
);
return new Certificate($certificate);
}
|
[
"public",
"function",
"sign",
"(",
"CertificateSigningRequest",
"$",
"csr",
",",
"int",
"$",
"serial",
"=",
"0",
")",
":",
"Certificate",
"{",
"$",
"certificate",
"=",
"openssl_csr_sign",
"(",
"$",
"csr",
"->",
"export",
"(",
")",
",",
"$",
"this",
"->",
"getCertificate",
"(",
")",
",",
"$",
"this",
"->",
"getPrivateKey",
"(",
")",
",",
"$",
"this",
"->",
"getLifetime",
"(",
")",
",",
"$",
"this",
"->",
"getOptions",
"(",
")",
",",
"$",
"serial",
")",
";",
"return",
"new",
"Certificate",
"(",
"$",
"certificate",
")",
";",
"}"
] |
Create a new Certificate.
@param CertificateSigningRequest $csr
@param int $serial
@return Certificate
|
[
"Create",
"a",
"new",
"Certificate",
"."
] |
9a7faf31492cefe8c8b166ef775a6e2eba04c3ec
|
https://github.com/blar/openssl/blob/9a7faf31492cefe8c8b166ef775a6e2eba04c3ec/lib/Blar/OpenSSL/CertificateSigningRequestSigner.php#L155-L165
|
224,011
|
blar/openssl
|
lib/Blar/OpenSSL/CertificateSigningRequestSigner.php
|
CertificateSigningRequestSigner.selfSign
|
public function selfSign(CertificateSigningRequest $csr, int $serial = 0): Certificate {
$certificate = openssl_csr_sign(
$csr->export(),
NULL,
$this->getPrivateKey(),
$this->getLifetime(),
$this->getOptions(),
$serial
);
return new Certificate($certificate);
}
|
php
|
public function selfSign(CertificateSigningRequest $csr, int $serial = 0): Certificate {
$certificate = openssl_csr_sign(
$csr->export(),
NULL,
$this->getPrivateKey(),
$this->getLifetime(),
$this->getOptions(),
$serial
);
return new Certificate($certificate);
}
|
[
"public",
"function",
"selfSign",
"(",
"CertificateSigningRequest",
"$",
"csr",
",",
"int",
"$",
"serial",
"=",
"0",
")",
":",
"Certificate",
"{",
"$",
"certificate",
"=",
"openssl_csr_sign",
"(",
"$",
"csr",
"->",
"export",
"(",
")",
",",
"NULL",
",",
"$",
"this",
"->",
"getPrivateKey",
"(",
")",
",",
"$",
"this",
"->",
"getLifetime",
"(",
")",
",",
"$",
"this",
"->",
"getOptions",
"(",
")",
",",
"$",
"serial",
")",
";",
"return",
"new",
"Certificate",
"(",
"$",
"certificate",
")",
";",
"}"
] |
Create a self signed certificate.
@param CertificateSigningRequest $csr
@param int $serial
@return Certificate
|
[
"Create",
"a",
"self",
"signed",
"certificate",
"."
] |
9a7faf31492cefe8c8b166ef775a6e2eba04c3ec
|
https://github.com/blar/openssl/blob/9a7faf31492cefe8c8b166ef775a6e2eba04c3ec/lib/Blar/OpenSSL/CertificateSigningRequestSigner.php#L175-L185
|
224,012
|
adamlc/address-format
|
src/Adamlc/AddressFormat/PopulateLocales.php
|
PopulateLocales.fetchData
|
public function fetchData()
{
$locales = json_decode(file_get_contents($this->locale_data_url));
if (isset($locales->countries)) {
//For some reason the countries are seperated by a tilde
$countries = explode('~', $locales->countries);
$data_dir = __DIR__ . '/i18n';
//Loop countries and grab the corrosponding json data
foreach ($countries as $country) {
$file = $data_dir . '/' . $country . '.json';
file_put_contents($file, file_get_contents($this->locale_data_url . '/' . $country));
}
}
}
|
php
|
public function fetchData()
{
$locales = json_decode(file_get_contents($this->locale_data_url));
if (isset($locales->countries)) {
//For some reason the countries are seperated by a tilde
$countries = explode('~', $locales->countries);
$data_dir = __DIR__ . '/i18n';
//Loop countries and grab the corrosponding json data
foreach ($countries as $country) {
$file = $data_dir . '/' . $country . '.json';
file_put_contents($file, file_get_contents($this->locale_data_url . '/' . $country));
}
}
}
|
[
"public",
"function",
"fetchData",
"(",
")",
"{",
"$",
"locales",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"locale_data_url",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"locales",
"->",
"countries",
")",
")",
"{",
"//For some reason the countries are seperated by a tilde",
"$",
"countries",
"=",
"explode",
"(",
"'~'",
",",
"$",
"locales",
"->",
"countries",
")",
";",
"$",
"data_dir",
"=",
"__DIR__",
".",
"'/i18n'",
";",
"//Loop countries and grab the corrosponding json data",
"foreach",
"(",
"$",
"countries",
"as",
"$",
"country",
")",
"{",
"$",
"file",
"=",
"$",
"data_dir",
".",
"'/'",
".",
"$",
"country",
".",
"'.json'",
";",
"file_put_contents",
"(",
"$",
"file",
",",
"file_get_contents",
"(",
"$",
"this",
"->",
"locale_data_url",
".",
"'/'",
".",
"$",
"country",
")",
")",
";",
"}",
"}",
"}"
] |
Function to fetch data from Google API and populate local files.
@access public
@return void
|
[
"Function",
"to",
"fetch",
"data",
"from",
"Google",
"API",
"and",
"populate",
"local",
"files",
"."
] |
130d8276d5cd8bf5cc046e00ccc4c59a3a8b8ac8
|
https://github.com/adamlc/address-format/blob/130d8276d5cd8bf5cc046e00ccc4c59a3a8b8ac8/src/Adamlc/AddressFormat/PopulateLocales.php#L26-L43
|
224,013
|
Eluinhost/minecraft-auth
|
src/AuthServer/AuthServer.php
|
AuthServer.onConnection
|
public function onConnection(AuthClient $connection)
{
//bubble the events up
$connection->on('login_success', function(AuthClient $client, DisconnectPacket $packet) {
$this->emit('login_success', [$client->getUsername(), $client->getUUID(), $packet]);
});
$connection->on('status_request', function(StatusResponsePacket $packet) {
$this->emit('status_request', [$packet]);
});
$connection->on('close', function() use (&$connection) {
$amount = count($this->clients);
for($i = 0; $i<$amount; $i++) {
/** @var $checkclient AuthClient */
$checkclient = $this->clients[$i];
//if we found our connection
if($checkclient === $connection) {
//remove from array and reset the keys
unset($this->clients[$i]);
$this->clients = array_values($this->clients);
echo "A client disconnected. Now there are total ". ($amount - 1) . " clients.\n";
$this->emit('disconnect', []);
return;
}
}
});
//if there is an error with the connection echo the error and end the connection
$connection->on('error', function($error, Connection $connection) {
echo "ERROR: $error\n";
$connection->end();
});
//add the connection to the list of tracked connections
$this->clients[] = $connection;
//echo how many are now online
$count = count($this->clients);
echo "New client conected: {$connection->getRemoteAddress()}. Clients online: $count.\n";
}
|
php
|
public function onConnection(AuthClient $connection)
{
//bubble the events up
$connection->on('login_success', function(AuthClient $client, DisconnectPacket $packet) {
$this->emit('login_success', [$client->getUsername(), $client->getUUID(), $packet]);
});
$connection->on('status_request', function(StatusResponsePacket $packet) {
$this->emit('status_request', [$packet]);
});
$connection->on('close', function() use (&$connection) {
$amount = count($this->clients);
for($i = 0; $i<$amount; $i++) {
/** @var $checkclient AuthClient */
$checkclient = $this->clients[$i];
//if we found our connection
if($checkclient === $connection) {
//remove from array and reset the keys
unset($this->clients[$i]);
$this->clients = array_values($this->clients);
echo "A client disconnected. Now there are total ". ($amount - 1) . " clients.\n";
$this->emit('disconnect', []);
return;
}
}
});
//if there is an error with the connection echo the error and end the connection
$connection->on('error', function($error, Connection $connection) {
echo "ERROR: $error\n";
$connection->end();
});
//add the connection to the list of tracked connections
$this->clients[] = $connection;
//echo how many are now online
$count = count($this->clients);
echo "New client conected: {$connection->getRemoteAddress()}. Clients online: $count.\n";
}
|
[
"public",
"function",
"onConnection",
"(",
"AuthClient",
"$",
"connection",
")",
"{",
"//bubble the events up",
"$",
"connection",
"->",
"on",
"(",
"'login_success'",
",",
"function",
"(",
"AuthClient",
"$",
"client",
",",
"DisconnectPacket",
"$",
"packet",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'login_success'",
",",
"[",
"$",
"client",
"->",
"getUsername",
"(",
")",
",",
"$",
"client",
"->",
"getUUID",
"(",
")",
",",
"$",
"packet",
"]",
")",
";",
"}",
")",
";",
"$",
"connection",
"->",
"on",
"(",
"'status_request'",
",",
"function",
"(",
"StatusResponsePacket",
"$",
"packet",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'status_request'",
",",
"[",
"$",
"packet",
"]",
")",
";",
"}",
")",
";",
"$",
"connection",
"->",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"connection",
")",
"{",
"$",
"amount",
"=",
"count",
"(",
"$",
"this",
"->",
"clients",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"amount",
";",
"$",
"i",
"++",
")",
"{",
"/** @var $checkclient AuthClient */",
"$",
"checkclient",
"=",
"$",
"this",
"->",
"clients",
"[",
"$",
"i",
"]",
";",
"//if we found our connection",
"if",
"(",
"$",
"checkclient",
"===",
"$",
"connection",
")",
"{",
"//remove from array and reset the keys",
"unset",
"(",
"$",
"this",
"->",
"clients",
"[",
"$",
"i",
"]",
")",
";",
"$",
"this",
"->",
"clients",
"=",
"array_values",
"(",
"$",
"this",
"->",
"clients",
")",
";",
"echo",
"\"A client disconnected. Now there are total \"",
".",
"(",
"$",
"amount",
"-",
"1",
")",
".",
"\" clients.\\n\"",
";",
"$",
"this",
"->",
"emit",
"(",
"'disconnect'",
",",
"[",
"]",
")",
";",
"return",
";",
"}",
"}",
"}",
")",
";",
"//if there is an error with the connection echo the error and end the connection",
"$",
"connection",
"->",
"on",
"(",
"'error'",
",",
"function",
"(",
"$",
"error",
",",
"Connection",
"$",
"connection",
")",
"{",
"echo",
"\"ERROR: $error\\n\"",
";",
"$",
"connection",
"->",
"end",
"(",
")",
";",
"}",
")",
";",
"//add the connection to the list of tracked connections",
"$",
"this",
"->",
"clients",
"[",
"]",
"=",
"$",
"connection",
";",
"//echo how many are now online",
"$",
"count",
"=",
"count",
"(",
"$",
"this",
"->",
"clients",
")",
";",
"echo",
"\"New client conected: {$connection->getRemoteAddress()}. Clients online: $count.\\n\"",
";",
"}"
] |
Called on event 'connection'
@param AuthClient $connection
|
[
"Called",
"on",
"event",
"connection"
] |
ebe9a09d1de45dbc765545137514c8cf7c8e075f
|
https://github.com/Eluinhost/minecraft-auth/blob/ebe9a09d1de45dbc765545137514c8cf7c8e075f/src/AuthServer/AuthServer.php#L70-L110
|
224,014
|
sgomez/SSPGuardBundle
|
SimpleSAMLphp/AuthSourceRegistry.php
|
AuthSourceRegistry.getAuthSource
|
public function getAuthSource($key)
{
if (!isset($this->authSources[$key])) {
throw new \InvalidArgumentException(sprintf(
'There is no AuthSource called "%s". Available are: %s',
$key,
implode(', ', array_keys($this->authSources))
));
}
return $this->container->get($this->authSources[$key]);
}
|
php
|
public function getAuthSource($key)
{
if (!isset($this->authSources[$key])) {
throw new \InvalidArgumentException(sprintf(
'There is no AuthSource called "%s". Available are: %s',
$key,
implode(', ', array_keys($this->authSources))
));
}
return $this->container->get($this->authSources[$key]);
}
|
[
"public",
"function",
"getAuthSource",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"authSources",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'There is no AuthSource called \"%s\". Available are: %s'",
",",
"$",
"key",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"this",
"->",
"authSources",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"this",
"->",
"authSources",
"[",
"$",
"key",
"]",
")",
";",
"}"
] |
Get SSPAuthSource.
@param $key
@return SSPAuthSource
|
[
"Get",
"SSPAuthSource",
"."
] |
9655bfdb62e0321b9929209587f5eaab8cc6a38b
|
https://github.com/sgomez/SSPGuardBundle/blob/9655bfdb62e0321b9929209587f5eaab8cc6a38b/SimpleSAMLphp/AuthSourceRegistry.php#L47-L58
|
224,015
|
kalfheim/sanitizer
|
src/Sanitizer.php
|
Sanitizer.rules
|
public function rules($ruleset)
{
if (! is_array($ruleset)) {
$ruleset = [static::GLOBAL_KEY => $ruleset];
}
foreach ($ruleset as $key => $rules) {
$this->addRule($key, $rules);
}
return $this;
}
|
php
|
public function rules($ruleset)
{
if (! is_array($ruleset)) {
$ruleset = [static::GLOBAL_KEY => $ruleset];
}
foreach ($ruleset as $key => $rules) {
$this->addRule($key, $rules);
}
return $this;
}
|
[
"public",
"function",
"rules",
"(",
"$",
"ruleset",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ruleset",
")",
")",
"{",
"$",
"ruleset",
"=",
"[",
"static",
"::",
"GLOBAL_KEY",
"=>",
"$",
"ruleset",
"]",
";",
"}",
"foreach",
"(",
"$",
"ruleset",
"as",
"$",
"key",
"=>",
"$",
"rules",
")",
"{",
"$",
"this",
"->",
"addRule",
"(",
"$",
"key",
",",
"$",
"rules",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add rules to the sanitizer.
@param string|array $ruleset The sanitation rules.
@return \Alfheim\Sanitizer\Sanitizer $this
|
[
"Add",
"rules",
"to",
"the",
"sanitizer",
"."
] |
67aa0df0d1fcdc292d1904ce4e7618232bea964e
|
https://github.com/kalfheim/sanitizer/blob/67aa0df0d1fcdc292d1904ce4e7618232bea964e/src/Sanitizer.php#L52-L63
|
224,016
|
kalfheim/sanitizer
|
src/Sanitizer.php
|
Sanitizer.sanitize
|
public function sanitize($data)
{
if ($this->hasGlobals()) {
if (! is_array($data)) {
return $this->sanitizeValueFor(static::GLOBAL_KEY, $data);
}
foreach ($data as $key => $value) {
$data[$key] = $this->sanitizeValueFor(static::GLOBAL_KEY, $value);
}
}
foreach ($data as $key => $value) {
if (! $this->shouldSanitize($key)) {
continue;
}
$data[$key] = $this->sanitizeValueFor($key, $value);
}
return $data;
}
|
php
|
public function sanitize($data)
{
if ($this->hasGlobals()) {
if (! is_array($data)) {
return $this->sanitizeValueFor(static::GLOBAL_KEY, $data);
}
foreach ($data as $key => $value) {
$data[$key] = $this->sanitizeValueFor(static::GLOBAL_KEY, $value);
}
}
foreach ($data as $key => $value) {
if (! $this->shouldSanitize($key)) {
continue;
}
$data[$key] = $this->sanitizeValueFor($key, $value);
}
return $data;
}
|
[
"public",
"function",
"sanitize",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasGlobals",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sanitizeValueFor",
"(",
"static",
"::",
"GLOBAL_KEY",
",",
"$",
"data",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"sanitizeValueFor",
"(",
"static",
"::",
"GLOBAL_KEY",
",",
"$",
"value",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"shouldSanitize",
"(",
"$",
"key",
")",
")",
"{",
"continue",
";",
"}",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"sanitizeValueFor",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Sanitize some data.
@param mixed $data
@return mixed
|
[
"Sanitize",
"some",
"data",
"."
] |
67aa0df0d1fcdc292d1904ce4e7618232bea964e
|
https://github.com/kalfheim/sanitizer/blob/67aa0df0d1fcdc292d1904ce4e7618232bea964e/src/Sanitizer.php#L72-L93
|
224,017
|
kalfheim/sanitizer
|
src/Sanitizer.php
|
Sanitizer.sanitizeValueFor
|
protected function sanitizeValueFor($key, $value)
{
foreach ($this->rules[$key] as $rule) {
$value = call_user_func_array(
$this->getCallable($rule[0], $key),
$this->buildArguments($value, isset($rule[1]) ? $rule[1] : null)
);
}
return $value;
}
|
php
|
protected function sanitizeValueFor($key, $value)
{
foreach ($this->rules[$key] as $rule) {
$value = call_user_func_array(
$this->getCallable($rule[0], $key),
$this->buildArguments($value, isset($rule[1]) ? $rule[1] : null)
);
}
return $value;
}
|
[
"protected",
"function",
"sanitizeValueFor",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
"as",
"$",
"rule",
")",
"{",
"$",
"value",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"getCallable",
"(",
"$",
"rule",
"[",
"0",
"]",
",",
"$",
"key",
")",
",",
"$",
"this",
"->",
"buildArguments",
"(",
"$",
"value",
",",
"isset",
"(",
"$",
"rule",
"[",
"1",
"]",
")",
"?",
"$",
"rule",
"[",
"1",
"]",
":",
"null",
")",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Sanitize a single value for a given key.
@param string $key
@param mixed $value
@return mixed
|
[
"Sanitize",
"a",
"single",
"value",
"for",
"a",
"given",
"key",
"."
] |
67aa0df0d1fcdc292d1904ce4e7618232bea964e
|
https://github.com/kalfheim/sanitizer/blob/67aa0df0d1fcdc292d1904ce4e7618232bea964e/src/Sanitizer.php#L159-L169
|
224,018
|
kalfheim/sanitizer
|
src/Sanitizer.php
|
Sanitizer.getCallable
|
protected function getCallable($value, $key)
{
// If the value is a string, a registrar is set and the value is
// registred with the registrar, resolve it there.
if (
is_string($value) &&
$this->hasRegistrar() &&
$this->registrar->isRegistred($value)
) {
$value = $this->registrar->resolve($value);
}
// If the value is now a callable, go ahead and return it...
if (is_callable($value)) {
return $value;
}
// However, if we've got an object and a filter method for the key
// exists, we'll return that as a callable.
if (
is_object($value) &&
method_exists($value, $method = $this->getFilterMethodName($key))
) {
return [$value, $method];
}
throw new InvalidArgumentException(sprintf(
'Could not resolve callable for [%s]', $value
));
}
|
php
|
protected function getCallable($value, $key)
{
// If the value is a string, a registrar is set and the value is
// registred with the registrar, resolve it there.
if (
is_string($value) &&
$this->hasRegistrar() &&
$this->registrar->isRegistred($value)
) {
$value = $this->registrar->resolve($value);
}
// If the value is now a callable, go ahead and return it...
if (is_callable($value)) {
return $value;
}
// However, if we've got an object and a filter method for the key
// exists, we'll return that as a callable.
if (
is_object($value) &&
method_exists($value, $method = $this->getFilterMethodName($key))
) {
return [$value, $method];
}
throw new InvalidArgumentException(sprintf(
'Could not resolve callable for [%s]', $value
));
}
|
[
"protected",
"function",
"getCallable",
"(",
"$",
"value",
",",
"$",
"key",
")",
"{",
"// If the value is a string, a registrar is set and the value is",
"// registred with the registrar, resolve it there.",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"$",
"this",
"->",
"hasRegistrar",
"(",
")",
"&&",
"$",
"this",
"->",
"registrar",
"->",
"isRegistred",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"registrar",
"->",
"resolve",
"(",
"$",
"value",
")",
";",
"}",
"// If the value is now a callable, go ahead and return it...",
"if",
"(",
"is_callable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"// However, if we've got an object and a filter method for the key",
"// exists, we'll return that as a callable.",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"method_exists",
"(",
"$",
"value",
",",
"$",
"method",
"=",
"$",
"this",
"->",
"getFilterMethodName",
"(",
"$",
"key",
")",
")",
")",
"{",
"return",
"[",
"$",
"value",
",",
"$",
"method",
"]",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Could not resolve callable for [%s]'",
",",
"$",
"value",
")",
")",
";",
"}"
] |
Resolve the callable for a given rule.
@param mixed $value
@param string $key
@return callable
@throws \InvalidArgumentException
|
[
"Resolve",
"the",
"callable",
"for",
"a",
"given",
"rule",
"."
] |
67aa0df0d1fcdc292d1904ce4e7618232bea964e
|
https://github.com/kalfheim/sanitizer/blob/67aa0df0d1fcdc292d1904ce4e7618232bea964e/src/Sanitizer.php#L181-L210
|
224,019
|
kalfheim/sanitizer
|
src/Sanitizer.php
|
Sanitizer.buildArguments
|
protected function buildArguments($value, array $args = null)
{
if (! $args) {
return (array) $value;
}
$valuePosition = array_search(static::PLACEHOLDER_VALUE, $args, true);
if ($valuePosition === false) {
return array_merge((array) $value, $args);
} else {
$args[$valuePosition] = $value;
}
return $args;
}
|
php
|
protected function buildArguments($value, array $args = null)
{
if (! $args) {
return (array) $value;
}
$valuePosition = array_search(static::PLACEHOLDER_VALUE, $args, true);
if ($valuePosition === false) {
return array_merge((array) $value, $args);
} else {
$args[$valuePosition] = $value;
}
return $args;
}
|
[
"protected",
"function",
"buildArguments",
"(",
"$",
"value",
",",
"array",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"args",
")",
"{",
"return",
"(",
"array",
")",
"$",
"value",
";",
"}",
"$",
"valuePosition",
"=",
"array_search",
"(",
"static",
"::",
"PLACEHOLDER_VALUE",
",",
"$",
"args",
",",
"true",
")",
";",
"if",
"(",
"$",
"valuePosition",
"===",
"false",
")",
"{",
"return",
"array_merge",
"(",
"(",
"array",
")",
"$",
"value",
",",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"args",
"[",
"$",
"valuePosition",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"args",
";",
"}"
] |
Build the arguments for a callback.
@param mixed $value
@param array|null $args
@return array
|
[
"Build",
"the",
"arguments",
"for",
"a",
"callback",
"."
] |
67aa0df0d1fcdc292d1904ce4e7618232bea964e
|
https://github.com/kalfheim/sanitizer/blob/67aa0df0d1fcdc292d1904ce4e7618232bea964e/src/Sanitizer.php#L220-L235
|
224,020
|
kalfheim/sanitizer
|
src/Sanitizer.php
|
Sanitizer.addRule
|
protected function addRule($key, $rules)
{
if ($this->shouldSanitize($key)) {
throw new InvalidArgumentException(sprintf(
'Sanitation rules are already defined for field [%s]', $key
));
}
$this->rules[$key] = $this->buildRules($rules);
}
|
php
|
protected function addRule($key, $rules)
{
if ($this->shouldSanitize($key)) {
throw new InvalidArgumentException(sprintf(
'Sanitation rules are already defined for field [%s]', $key
));
}
$this->rules[$key] = $this->buildRules($rules);
}
|
[
"protected",
"function",
"addRule",
"(",
"$",
"key",
",",
"$",
"rules",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldSanitize",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Sanitation rules are already defined for field [%s]'",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"buildRules",
"(",
"$",
"rules",
")",
";",
"}"
] |
Add a rule to the sanitizer factory.
@param string $key
@param string|array|\Closure $rules
@return void
@throws \InvalidArgumentException
|
[
"Add",
"a",
"rule",
"to",
"the",
"sanitizer",
"factory",
"."
] |
67aa0df0d1fcdc292d1904ce4e7618232bea964e
|
https://github.com/kalfheim/sanitizer/blob/67aa0df0d1fcdc292d1904ce4e7618232bea964e/src/Sanitizer.php#L247-L256
|
224,021
|
kalfheim/sanitizer
|
src/Sanitizer.php
|
Sanitizer.buildRules
|
protected function buildRules($rules)
{
if (is_string($rules)) {
$rules = explode('|', $rules);
} elseif (is_object($rules)) {
$rules = [$rules];
}
$built = [];
foreach ((array) $rules as $rule) {
if (is_string($rule) && strpos($rule, ':') !== false) {
$args = explode(':', $rule);
$rule = array_shift($args);
$built[] = [$rule, $args];
} else {
$built[] = [$rule];
}
}
return $built;
}
|
php
|
protected function buildRules($rules)
{
if (is_string($rules)) {
$rules = explode('|', $rules);
} elseif (is_object($rules)) {
$rules = [$rules];
}
$built = [];
foreach ((array) $rules as $rule) {
if (is_string($rule) && strpos($rule, ':') !== false) {
$args = explode(':', $rule);
$rule = array_shift($args);
$built[] = [$rule, $args];
} else {
$built[] = [$rule];
}
}
return $built;
}
|
[
"protected",
"function",
"buildRules",
"(",
"$",
"rules",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"rules",
")",
")",
"{",
"$",
"rules",
"=",
"explode",
"(",
"'|'",
",",
"$",
"rules",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"rules",
")",
")",
"{",
"$",
"rules",
"=",
"[",
"$",
"rules",
"]",
";",
"}",
"$",
"built",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"rule",
")",
"&&",
"strpos",
"(",
"$",
"rule",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"$",
"args",
"=",
"explode",
"(",
"':'",
",",
"$",
"rule",
")",
";",
"$",
"rule",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"built",
"[",
"]",
"=",
"[",
"$",
"rule",
",",
"$",
"args",
"]",
";",
"}",
"else",
"{",
"$",
"built",
"[",
"]",
"=",
"[",
"$",
"rule",
"]",
";",
"}",
"}",
"return",
"$",
"built",
";",
"}"
] |
Build a valid set of rules.
@param string|array|\Closure $rules
@return array
|
[
"Build",
"a",
"valid",
"set",
"of",
"rules",
"."
] |
67aa0df0d1fcdc292d1904ce4e7618232bea964e
|
https://github.com/kalfheim/sanitizer/blob/67aa0df0d1fcdc292d1904ce4e7618232bea964e/src/Sanitizer.php#L265-L287
|
224,022
|
blar/openssl
|
lib/Blar/OpenSSL/OpenSSL.php
|
OpenSSL.getStrongPseudoRandomBytes
|
public static function getStrongPseudoRandomBytes(int $length): string {
$result = openssl_random_pseudo_bytes($length, $strong);
if(!$strong) {
throw new RuntimeException('Not strong enough');
}
return $result;
}
|
php
|
public static function getStrongPseudoRandomBytes(int $length): string {
$result = openssl_random_pseudo_bytes($length, $strong);
if(!$strong) {
throw new RuntimeException('Not strong enough');
}
return $result;
}
|
[
"public",
"static",
"function",
"getStrongPseudoRandomBytes",
"(",
"int",
"$",
"length",
")",
":",
"string",
"{",
"$",
"result",
"=",
"openssl_random_pseudo_bytes",
"(",
"$",
"length",
",",
"$",
"strong",
")",
";",
"if",
"(",
"!",
"$",
"strong",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Not strong enough'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Get strong random bytes.
@param int $length
@return string
|
[
"Get",
"strong",
"random",
"bytes",
"."
] |
9a7faf31492cefe8c8b166ef775a6e2eba04c3ec
|
https://github.com/blar/openssl/blob/9a7faf31492cefe8c8b166ef775a6e2eba04c3ec/lib/Blar/OpenSSL/OpenSSL.php#L33-L39
|
224,023
|
blar/openssl
|
lib/Blar/OpenSSL/CertificateSigningRequest.php
|
CertificateSigningRequest.export
|
public function export(bool $verbose = false): string {
openssl_csr_export($this->getHandle(), $output, !$verbose);
return $output;
}
|
php
|
public function export(bool $verbose = false): string {
openssl_csr_export($this->getHandle(), $output, !$verbose);
return $output;
}
|
[
"public",
"function",
"export",
"(",
"bool",
"$",
"verbose",
"=",
"false",
")",
":",
"string",
"{",
"openssl_csr_export",
"(",
"$",
"this",
"->",
"getHandle",
"(",
")",
",",
"$",
"output",
",",
"!",
"$",
"verbose",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Export as string.
@param bool $verbose Add additional text output.
@return string
|
[
"Export",
"as",
"string",
"."
] |
9a7faf31492cefe8c8b166ef775a6e2eba04c3ec
|
https://github.com/blar/openssl/blob/9a7faf31492cefe8c8b166ef775a6e2eba04c3ec/lib/Blar/OpenSSL/CertificateSigningRequest.php#L54-L57
|
224,024
|
blar/openssl
|
lib/Blar/OpenSSL/CertificateSigningRequest.php
|
CertificateSigningRequest.exportToFile
|
public function exportToFile(string $fileName, bool $verbose = false) {
openssl_csr_export_to_file($this->getHandle(), $fileName, !$verbose);
}
|
php
|
public function exportToFile(string $fileName, bool $verbose = false) {
openssl_csr_export_to_file($this->getHandle(), $fileName, !$verbose);
}
|
[
"public",
"function",
"exportToFile",
"(",
"string",
"$",
"fileName",
",",
"bool",
"$",
"verbose",
"=",
"false",
")",
"{",
"openssl_csr_export_to_file",
"(",
"$",
"this",
"->",
"getHandle",
"(",
")",
",",
"$",
"fileName",
",",
"!",
"$",
"verbose",
")",
";",
"}"
] |
Export to a file.
@param string $fileName
@param bool $verbose Add additional text output.
|
[
"Export",
"to",
"a",
"file",
"."
] |
9a7faf31492cefe8c8b166ef775a6e2eba04c3ec
|
https://github.com/blar/openssl/blob/9a7faf31492cefe8c8b166ef775a6e2eba04c3ec/lib/Blar/OpenSSL/CertificateSigningRequest.php#L65-L67
|
224,025
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.getPaginated
|
public function getPaginated($paged = 15, $orderBy = 'created_at', $sort = 'desc')
{
$query = function () use ($paged, $orderBy, $sort) {
return $this->model
->with($this->requiredRelationships)
->orderBy($orderBy, $sort)
->paginate($paged);
};
return $this->doQuery($query);
}
|
php
|
public function getPaginated($paged = 15, $orderBy = 'created_at', $sort = 'desc')
{
$query = function () use ($paged, $orderBy, $sort) {
return $this->model
->with($this->requiredRelationships)
->orderBy($orderBy, $sort)
->paginate($paged);
};
return $this->doQuery($query);
}
|
[
"public",
"function",
"getPaginated",
"(",
"$",
"paged",
"=",
"15",
",",
"$",
"orderBy",
"=",
"'created_at'",
",",
"$",
"sort",
"=",
"'desc'",
")",
"{",
"$",
"query",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"paged",
",",
"$",
"orderBy",
",",
"$",
"sort",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"with",
"(",
"$",
"this",
"->",
"requiredRelationships",
")",
"->",
"orderBy",
"(",
"$",
"orderBy",
",",
"$",
"sort",
")",
"->",
"paginate",
"(",
"$",
"paged",
")",
";",
"}",
";",
"return",
"$",
"this",
"->",
"doQuery",
"(",
"$",
"query",
")",
";",
"}"
] |
Get paged items
@param integer $paged Items per page
@param string $orderBy Column to sort by
@param string $sort Sort direction
@return \Illuminate\Pagination\Paginator
|
[
"Get",
"paged",
"items"
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L78-L89
|
224,026
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.getForSelect
|
public function getForSelect($data, $key = 'id', $orderBy = 'created_at', $sort = 'desc')
{
$query = function () use ($data, $key, $orderBy, $sort) {
return $this->model
->with($this->requiredRelationships)
->orderBy($orderBy, $sort)
->lists($data, $key)
->all();
};
return $this->doQuery($query);
}
|
php
|
public function getForSelect($data, $key = 'id', $orderBy = 'created_at', $sort = 'desc')
{
$query = function () use ($data, $key, $orderBy, $sort) {
return $this->model
->with($this->requiredRelationships)
->orderBy($orderBy, $sort)
->lists($data, $key)
->all();
};
return $this->doQuery($query);
}
|
[
"public",
"function",
"getForSelect",
"(",
"$",
"data",
",",
"$",
"key",
"=",
"'id'",
",",
"$",
"orderBy",
"=",
"'created_at'",
",",
"$",
"sort",
"=",
"'desc'",
")",
"{",
"$",
"query",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"data",
",",
"$",
"key",
",",
"$",
"orderBy",
",",
"$",
"sort",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"with",
"(",
"$",
"this",
"->",
"requiredRelationships",
")",
"->",
"orderBy",
"(",
"$",
"orderBy",
",",
"$",
"sort",
")",
"->",
"lists",
"(",
"$",
"data",
",",
"$",
"key",
")",
"->",
"all",
"(",
")",
";",
"}",
";",
"return",
"$",
"this",
"->",
"doQuery",
"(",
"$",
"query",
")",
";",
"}"
] |
Items for select options
@param string $data column to display in the option
@param string $key column to be used as the value in option
@param string $orderBy column to sort by
@param string $sort sort direction
@return array array with key value pairs
|
[
"Items",
"for",
"select",
"options"
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L100-L111
|
224,027
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.getById
|
public function getById($id)
{
$query = function () use ($id) {
return $this->model
->with($this->requiredRelationships)
->find($id);
};
return $this->doQuery($query);
}
|
php
|
public function getById($id)
{
$query = function () use ($id) {
return $this->model
->with($this->requiredRelationships)
->find($id);
};
return $this->doQuery($query);
}
|
[
"public",
"function",
"getById",
"(",
"$",
"id",
")",
"{",
"$",
"query",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"with",
"(",
"$",
"this",
"->",
"requiredRelationships",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"}",
";",
"return",
"$",
"this",
"->",
"doQuery",
"(",
"$",
"query",
")",
";",
"}"
] |
Get item by its id
@param integer $id
@return \Illuminate\Database\Eloquent\Model
|
[
"Get",
"item",
"by",
"its",
"id"
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L119-L128
|
224,028
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.getActively
|
public function getActively($term, $column = 'slug')
{
if (is_numeric($term)) {
return $this->getById($term);
}
return $this->getItemByColumn($term, $column);
}
|
php
|
public function getActively($term, $column = 'slug')
{
if (is_numeric($term)) {
return $this->getById($term);
}
return $this->getItemByColumn($term, $column);
}
|
[
"public",
"function",
"getActively",
"(",
"$",
"term",
",",
"$",
"column",
"=",
"'slug'",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"term",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getById",
"(",
"$",
"term",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getItemByColumn",
"(",
"$",
"term",
",",
"$",
"column",
")",
";",
"}"
] |
Get item by id or column
@param mixed $term id or term
@param string $column column to search
@return \Illuminate\Database\Eloquent\Model
|
[
"Get",
"item",
"by",
"id",
"or",
"column"
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L175-L182
|
224,029
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.update
|
public function update($id, array $data)
{
return $this->model->where($this->model->getKeyName(), $id)->update($data);
}
|
php
|
public function update($id, array $data)
{
return $this->model->where($this->model->getKeyName(), $id)->update($data);
}
|
[
"public",
"function",
"update",
"(",
"$",
"id",
",",
"array",
"$",
"data",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"$",
"this",
"->",
"model",
"->",
"getKeyName",
"(",
")",
",",
"$",
"id",
")",
"->",
"update",
"(",
"$",
"data",
")",
";",
"}"
] |
Update a record using the primary key.
@param $id mixed primary key
@param $data array
|
[
"Update",
"a",
"record",
"using",
"the",
"primary",
"key",
"."
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L201-L204
|
224,030
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.updateOrCreate
|
public function updateOrCreate(array $identifiers, array $data)
{
$existing = $this->model->where(array_only($data, $identifiers))->first();
if ($existing) {
$existing->update($data);
return $existing;
}
return $this->create($data);
}
|
php
|
public function updateOrCreate(array $identifiers, array $data)
{
$existing = $this->model->where(array_only($data, $identifiers))->first();
if ($existing) {
$existing->update($data);
return $existing;
}
return $this->create($data);
}
|
[
"public",
"function",
"updateOrCreate",
"(",
"array",
"$",
"identifiers",
",",
"array",
"$",
"data",
")",
"{",
"$",
"existing",
"=",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"array_only",
"(",
"$",
"data",
",",
"$",
"identifiers",
")",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"existing",
")",
"{",
"$",
"existing",
"->",
"update",
"(",
"$",
"data",
")",
";",
"return",
"$",
"existing",
";",
"}",
"return",
"$",
"this",
"->",
"create",
"(",
"$",
"data",
")",
";",
"}"
] |
Update or crate a record and return the entity
@param array $identifiers columns to search for
@param array $data
@return mixed
|
[
"Update",
"or",
"crate",
"a",
"record",
"and",
"return",
"the",
"entity"
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L213-L224
|
224,031
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.delete
|
public function delete($id)
{
return $this->model->where($this->model->getKeyName(), $id)->delete();
}
|
php
|
public function delete($id)
{
return $this->model->where($this->model->getKeyName(), $id)->delete();
}
|
[
"public",
"function",
"delete",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"$",
"this",
"->",
"model",
"->",
"getKeyName",
"(",
")",
",",
"$",
"id",
")",
"->",
"delete",
"(",
")",
";",
"}"
] |
Delete a record by the primary key.
@param $id
@return bool
|
[
"Delete",
"a",
"record",
"by",
"the",
"primary",
"key",
"."
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L232-L235
|
224,032
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.with
|
public function with($relationships)
{
$this->requiredRelationships = [];
if ($relationships == 'all') {
$this->requiredRelationships = $this->relationships;
} elseif (is_array($relationships)) {
$this->requiredRelationships = array_filter($relationships, function ($value) {
return in_array($value, $this->relationships);
});
} elseif (is_string($relationships)) {
array_push($this->requiredRelationships, $relationships);
}
return $this;
}
|
php
|
public function with($relationships)
{
$this->requiredRelationships = [];
if ($relationships == 'all') {
$this->requiredRelationships = $this->relationships;
} elseif (is_array($relationships)) {
$this->requiredRelationships = array_filter($relationships, function ($value) {
return in_array($value, $this->relationships);
});
} elseif (is_string($relationships)) {
array_push($this->requiredRelationships, $relationships);
}
return $this;
}
|
[
"public",
"function",
"with",
"(",
"$",
"relationships",
")",
"{",
"$",
"this",
"->",
"requiredRelationships",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"relationships",
"==",
"'all'",
")",
"{",
"$",
"this",
"->",
"requiredRelationships",
"=",
"$",
"this",
"->",
"relationships",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"relationships",
")",
")",
"{",
"$",
"this",
"->",
"requiredRelationships",
"=",
"array_filter",
"(",
"$",
"relationships",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"relationships",
")",
";",
"}",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"relationships",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"requiredRelationships",
",",
"$",
"relationships",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Choose what relationships to return with query.
@param mixed $relationships
@return $this
|
[
"Choose",
"what",
"relationships",
"to",
"return",
"with",
"query",
"."
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L243-L258
|
224,033
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.doQuery
|
protected function doQuery($callback)
{
$previousMethod = debug_backtrace(null, 2)[1];
$methodName = $previousMethod['function'];
$arguments = $previousMethod['args'];
$result = $this->doBeforeQuery($callback, $methodName, $arguments);
return $this->doAfterQuery($result, $methodName, $arguments);
}
|
php
|
protected function doQuery($callback)
{
$previousMethod = debug_backtrace(null, 2)[1];
$methodName = $previousMethod['function'];
$arguments = $previousMethod['args'];
$result = $this->doBeforeQuery($callback, $methodName, $arguments);
return $this->doAfterQuery($result, $methodName, $arguments);
}
|
[
"protected",
"function",
"doQuery",
"(",
"$",
"callback",
")",
"{",
"$",
"previousMethod",
"=",
"debug_backtrace",
"(",
"null",
",",
"2",
")",
"[",
"1",
"]",
";",
"$",
"methodName",
"=",
"$",
"previousMethod",
"[",
"'function'",
"]",
";",
"$",
"arguments",
"=",
"$",
"previousMethod",
"[",
"'args'",
"]",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doBeforeQuery",
"(",
"$",
"callback",
",",
"$",
"methodName",
",",
"$",
"arguments",
")",
";",
"return",
"$",
"this",
"->",
"doAfterQuery",
"(",
"$",
"result",
",",
"$",
"methodName",
",",
"$",
"arguments",
")",
";",
"}"
] |
Perform the repository query.
@param $callback
@return mixed
|
[
"Perform",
"the",
"repository",
"query",
"."
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L266-L275
|
224,034
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.doBeforeQuery
|
private function doBeforeQuery($callback, $methodName, $arguments)
{
$traits = $this->getUsedTraits();
if (in_array(CacheResults::class, $traits) && $this->caching && $this->isCacheableMethod($methodName)) {
return $this->processCacheRequest($callback, $methodName, $arguments);
}
return $callback();
}
|
php
|
private function doBeforeQuery($callback, $methodName, $arguments)
{
$traits = $this->getUsedTraits();
if (in_array(CacheResults::class, $traits) && $this->caching && $this->isCacheableMethod($methodName)) {
return $this->processCacheRequest($callback, $methodName, $arguments);
}
return $callback();
}
|
[
"private",
"function",
"doBeforeQuery",
"(",
"$",
"callback",
",",
"$",
"methodName",
",",
"$",
"arguments",
")",
"{",
"$",
"traits",
"=",
"$",
"this",
"->",
"getUsedTraits",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"CacheResults",
"::",
"class",
",",
"$",
"traits",
")",
"&&",
"$",
"this",
"->",
"caching",
"&&",
"$",
"this",
"->",
"isCacheableMethod",
"(",
"$",
"methodName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"processCacheRequest",
"(",
"$",
"callback",
",",
"$",
"methodName",
",",
"$",
"arguments",
")",
";",
"}",
"return",
"$",
"callback",
"(",
")",
";",
"}"
] |
Apply any modifiers to the query.
@param $callback
@param $methodName
@param $arguments
@return mixed
|
[
"Apply",
"any",
"modifiers",
"to",
"the",
"query",
"."
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L285-L294
|
224,035
|
dannyweeks/laravel-base-repository
|
src/BaseEloquentRepository.php
|
BaseEloquentRepository.doAfterQuery
|
private function doAfterQuery($result, $methodName, $arguments)
{
$traits = $this->getUsedTraits();
if (in_array(CacheResults::class, $traits)) {
// Reset caching to enabled in case it has just been disabled.
$this->caching = true;
}
if (in_array(ThrowsHttpExceptions::class, $traits)) {
if ($this->shouldThrowHttpException($result, $methodName)) {
$this->throwNotFoundHttpException($methodName, $arguments);
}
$this->exceptionsDisabled = false;
}
return $result;
}
|
php
|
private function doAfterQuery($result, $methodName, $arguments)
{
$traits = $this->getUsedTraits();
if (in_array(CacheResults::class, $traits)) {
// Reset caching to enabled in case it has just been disabled.
$this->caching = true;
}
if (in_array(ThrowsHttpExceptions::class, $traits)) {
if ($this->shouldThrowHttpException($result, $methodName)) {
$this->throwNotFoundHttpException($methodName, $arguments);
}
$this->exceptionsDisabled = false;
}
return $result;
}
|
[
"private",
"function",
"doAfterQuery",
"(",
"$",
"result",
",",
"$",
"methodName",
",",
"$",
"arguments",
")",
"{",
"$",
"traits",
"=",
"$",
"this",
"->",
"getUsedTraits",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"CacheResults",
"::",
"class",
",",
"$",
"traits",
")",
")",
"{",
"// Reset caching to enabled in case it has just been disabled.",
"$",
"this",
"->",
"caching",
"=",
"true",
";",
"}",
"if",
"(",
"in_array",
"(",
"ThrowsHttpExceptions",
"::",
"class",
",",
"$",
"traits",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldThrowHttpException",
"(",
"$",
"result",
",",
"$",
"methodName",
")",
")",
"{",
"$",
"this",
"->",
"throwNotFoundHttpException",
"(",
"$",
"methodName",
",",
"$",
"arguments",
")",
";",
"}",
"$",
"this",
"->",
"exceptionsDisabled",
"=",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Handle the query result.
@param $result
@param $methodName
@param $arguments
@return mixed
|
[
"Handle",
"the",
"query",
"result",
"."
] |
69f294898b98a10cb84b9a6f664e789a5ff24122
|
https://github.com/dannyweeks/laravel-base-repository/blob/69f294898b98a10cb84b9a6f664e789a5ff24122/src/BaseEloquentRepository.php#L304-L323
|
224,036
|
lexik/LexikMonologBrowserBundle
|
Model/LogRepository.php
|
LogRepository.getLogById
|
public function getLogById($id)
{
$log = $this->createQueryBuilder()
->select('l.*')
->from($this->tableName, 'l')
->where('l.id = :id')
->setParameter(':id', $id)
->execute()
->fetch();
if (false !== $log) {
return new Log($log);
}
}
|
php
|
public function getLogById($id)
{
$log = $this->createQueryBuilder()
->select('l.*')
->from($this->tableName, 'l')
->where('l.id = :id')
->setParameter(':id', $id)
->execute()
->fetch();
if (false !== $log) {
return new Log($log);
}
}
|
[
"public",
"function",
"getLogById",
"(",
"$",
"id",
")",
"{",
"$",
"log",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'l.*'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"tableName",
",",
"'l'",
")",
"->",
"where",
"(",
"'l.id = :id'",
")",
"->",
"setParameter",
"(",
"':id'",
",",
"$",
"id",
")",
"->",
"execute",
"(",
")",
"->",
"fetch",
"(",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"log",
")",
"{",
"return",
"new",
"Log",
"(",
"$",
"log",
")",
";",
"}",
"}"
] |
Retrieve a log entry by his ID.
@param integer $id
@return Log|null
|
[
"Retrieve",
"a",
"log",
"entry",
"by",
"his",
"ID",
"."
] |
f9c7a9323763dc392e2b20aa995d44570f10bde4
|
https://github.com/lexik/LexikMonologBrowserBundle/blob/f9c7a9323763dc392e2b20aa995d44570f10bde4/Model/LogRepository.php#L63-L76
|
224,037
|
lexik/LexikMonologBrowserBundle
|
Model/LogRepository.php
|
LogRepository.getLastLog
|
public function getLastLog()
{
$log = $this->createQueryBuilder()
->select('l.*')
->from($this->tableName, 'l')
->orderBy('l.id', 'DESC')
->setMaxResults(1)
->execute()
->fetch();
if (false !== $log) {
return new Log($log);
}
}
|
php
|
public function getLastLog()
{
$log = $this->createQueryBuilder()
->select('l.*')
->from($this->tableName, 'l')
->orderBy('l.id', 'DESC')
->setMaxResults(1)
->execute()
->fetch();
if (false !== $log) {
return new Log($log);
}
}
|
[
"public",
"function",
"getLastLog",
"(",
")",
"{",
"$",
"log",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'l.*'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"tableName",
",",
"'l'",
")",
"->",
"orderBy",
"(",
"'l.id'",
",",
"'DESC'",
")",
"->",
"setMaxResults",
"(",
"1",
")",
"->",
"execute",
"(",
")",
"->",
"fetch",
"(",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"log",
")",
"{",
"return",
"new",
"Log",
"(",
"$",
"log",
")",
";",
"}",
"}"
] |
Retrieve last log entry.
@return Log|null
|
[
"Retrieve",
"last",
"log",
"entry",
"."
] |
f9c7a9323763dc392e2b20aa995d44570f10bde4
|
https://github.com/lexik/LexikMonologBrowserBundle/blob/f9c7a9323763dc392e2b20aa995d44570f10bde4/Model/LogRepository.php#L83-L96
|
224,038
|
lexik/LexikMonologBrowserBundle
|
Model/LogRepository.php
|
LogRepository.getSimilarLogsQueryBuilder
|
public function getSimilarLogsQueryBuilder(Log $log)
{
return $this->createQueryBuilder()
->select('l.id, l.channel, l.level, l.level_name, l.message, l.datetime')
->from($this->tableName, 'l')
->andWhere('l.message = :message')
->andWhere('l.channel = :channel')
->andWhere('l.level = :level')
->andWhere('l.id != :id')
->setParameter(':message', $log->getMessage())
->setParameter(':channel', $log->getChannel())
->setParameter(':level', $log->getLevel())
->setParameter(':id', $log->getId());
}
|
php
|
public function getSimilarLogsQueryBuilder(Log $log)
{
return $this->createQueryBuilder()
->select('l.id, l.channel, l.level, l.level_name, l.message, l.datetime')
->from($this->tableName, 'l')
->andWhere('l.message = :message')
->andWhere('l.channel = :channel')
->andWhere('l.level = :level')
->andWhere('l.id != :id')
->setParameter(':message', $log->getMessage())
->setParameter(':channel', $log->getChannel())
->setParameter(':level', $log->getLevel())
->setParameter(':id', $log->getId());
}
|
[
"public",
"function",
"getSimilarLogsQueryBuilder",
"(",
"Log",
"$",
"log",
")",
"{",
"return",
"$",
"this",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'l.id, l.channel, l.level, l.level_name, l.message, l.datetime'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"tableName",
",",
"'l'",
")",
"->",
"andWhere",
"(",
"'l.message = :message'",
")",
"->",
"andWhere",
"(",
"'l.channel = :channel'",
")",
"->",
"andWhere",
"(",
"'l.level = :level'",
")",
"->",
"andWhere",
"(",
"'l.id != :id'",
")",
"->",
"setParameter",
"(",
"':message'",
",",
"$",
"log",
"->",
"getMessage",
"(",
")",
")",
"->",
"setParameter",
"(",
"':channel'",
",",
"$",
"log",
"->",
"getChannel",
"(",
")",
")",
"->",
"setParameter",
"(",
"':level'",
",",
"$",
"log",
"->",
"getLevel",
"(",
")",
")",
"->",
"setParameter",
"(",
"':id'",
",",
"$",
"log",
"->",
"getId",
"(",
")",
")",
";",
"}"
] |
Retrieve similar logs of the given one.
@param Log $log
@return \Doctrine\DBAL\Query\QueryBuilder
|
[
"Retrieve",
"similar",
"logs",
"of",
"the",
"given",
"one",
"."
] |
f9c7a9323763dc392e2b20aa995d44570f10bde4
|
https://github.com/lexik/LexikMonologBrowserBundle/blob/f9c7a9323763dc392e2b20aa995d44570f10bde4/Model/LogRepository.php#L105-L118
|
224,039
|
lexik/LexikMonologBrowserBundle
|
Model/LogRepository.php
|
LogRepository.getLogsLevel
|
public function getLogsLevel()
{
$levels = $this->createQueryBuilder()
->select('l.level, l.level_name, COUNT(l.id) AS count')
->from($this->tableName, 'l')
->groupBy('l.level, l.level_name')
->orderBy('l.level', 'DESC')
->execute()
->fetchAll();
$normalizedLevels = array();
foreach ($levels as $level) {
$normalizedLevels[$level['level']] = sprintf('%s (%s)', $level['level_name'], $level['count']);
}
return $normalizedLevels;
}
|
php
|
public function getLogsLevel()
{
$levels = $this->createQueryBuilder()
->select('l.level, l.level_name, COUNT(l.id) AS count')
->from($this->tableName, 'l')
->groupBy('l.level, l.level_name')
->orderBy('l.level', 'DESC')
->execute()
->fetchAll();
$normalizedLevels = array();
foreach ($levels as $level) {
$normalizedLevels[$level['level']] = sprintf('%s (%s)', $level['level_name'], $level['count']);
}
return $normalizedLevels;
}
|
[
"public",
"function",
"getLogsLevel",
"(",
")",
"{",
"$",
"levels",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'l.level, l.level_name, COUNT(l.id) AS count'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"tableName",
",",
"'l'",
")",
"->",
"groupBy",
"(",
"'l.level, l.level_name'",
")",
"->",
"orderBy",
"(",
"'l.level'",
",",
"'DESC'",
")",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
")",
";",
"$",
"normalizedLevels",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"levels",
"as",
"$",
"level",
")",
"{",
"$",
"normalizedLevels",
"[",
"$",
"level",
"[",
"'level'",
"]",
"]",
"=",
"sprintf",
"(",
"'%s (%s)'",
",",
"$",
"level",
"[",
"'level_name'",
"]",
",",
"$",
"level",
"[",
"'count'",
"]",
")",
";",
"}",
"return",
"$",
"normalizedLevels",
";",
"}"
] |
Returns a array of levels with count entries used by logs.
@return array
|
[
"Returns",
"a",
"array",
"of",
"levels",
"with",
"count",
"entries",
"used",
"by",
"logs",
"."
] |
f9c7a9323763dc392e2b20aa995d44570f10bde4
|
https://github.com/lexik/LexikMonologBrowserBundle/blob/f9c7a9323763dc392e2b20aa995d44570f10bde4/Model/LogRepository.php#L125-L141
|
224,040
|
sulu/SuluProductBundle
|
Controller/ProductMediaController.php
|
ProductMediaController.postAction
|
public function postAction(Request $request, $productId)
{
$locale = $this->getLocale($request);
$mediaId = $request->get('mediaId', '');
try {
$em = $this->getDoctrine()->getManager();
/** @var Product $product */
$product = $this->getProductManager()->findByIdAndLocale($productId, $locale);
$media = $this->getMediaManager()->getById($mediaId, $locale);
if (!$product) {
throw new EntityNotFoundException($this->getProductEntityName(), $productId);
}
if (!$media) {
throw new EntityNotFoundException($this->getMediaEntityName(), $mediaId);
}
if ($product->containsMedia($media)) {
throw new RestException('Relation already exists');
}
//FIXME this is just a temporary solution
// issue https://github.com/massiveart/POOL-ALPIN/issues/1467
$this->removeDefaultPrices($product);
$product->addMedia($media);
$em->flush();
$view = $this->view($media, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (\Exception $e) {
$view = $this->view($e->getMessage(), 400);
}
return $this->handleView($view);
}
|
php
|
public function postAction(Request $request, $productId)
{
$locale = $this->getLocale($request);
$mediaId = $request->get('mediaId', '');
try {
$em = $this->getDoctrine()->getManager();
/** @var Product $product */
$product = $this->getProductManager()->findByIdAndLocale($productId, $locale);
$media = $this->getMediaManager()->getById($mediaId, $locale);
if (!$product) {
throw new EntityNotFoundException($this->getProductEntityName(), $productId);
}
if (!$media) {
throw new EntityNotFoundException($this->getMediaEntityName(), $mediaId);
}
if ($product->containsMedia($media)) {
throw new RestException('Relation already exists');
}
//FIXME this is just a temporary solution
// issue https://github.com/massiveart/POOL-ALPIN/issues/1467
$this->removeDefaultPrices($product);
$product->addMedia($media);
$em->flush();
$view = $this->view($media, 200);
} catch (EntityNotFoundException $enfe) {
$view = $this->view($enfe->toArray(), 404);
} catch (RestException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (\Exception $e) {
$view = $this->view($e->getMessage(), 400);
}
return $this->handleView($view);
}
|
[
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
",",
"$",
"productId",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"mediaId",
"=",
"$",
"request",
"->",
"get",
"(",
"'mediaId'",
",",
"''",
")",
";",
"try",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"/** @var Product $product */",
"$",
"product",
"=",
"$",
"this",
"->",
"getProductManager",
"(",
")",
"->",
"findByIdAndLocale",
"(",
"$",
"productId",
",",
"$",
"locale",
")",
";",
"$",
"media",
"=",
"$",
"this",
"->",
"getMediaManager",
"(",
")",
"->",
"getById",
"(",
"$",
"mediaId",
",",
"$",
"locale",
")",
";",
"if",
"(",
"!",
"$",
"product",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getProductEntityName",
"(",
")",
",",
"$",
"productId",
")",
";",
"}",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getMediaEntityName",
"(",
")",
",",
"$",
"mediaId",
")",
";",
"}",
"if",
"(",
"$",
"product",
"->",
"containsMedia",
"(",
"$",
"media",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Relation already exists'",
")",
";",
"}",
"//FIXME this is just a temporary solution",
"// issue https://github.com/massiveart/POOL-ALPIN/issues/1467",
"$",
"this",
"->",
"removeDefaultPrices",
"(",
"$",
"product",
")",
";",
"$",
"product",
"->",
"addMedia",
"(",
"$",
"media",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"media",
",",
"200",
")",
";",
"}",
"catch",
"(",
"EntityNotFoundException",
"$",
"enfe",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"enfe",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"RestException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Adds a new media to the product.
@param Request $request
@param int $productId
@return Response
|
[
"Adds",
"a",
"new",
"media",
"to",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductMediaController.php#L69-L108
|
224,041
|
sulu/SuluProductBundle
|
Controller/ProductMediaController.php
|
ProductMediaController.putAction
|
public function putAction(Request $request, $productId)
{
$mediaIds = $request->get('mediaIds');
if (null === $mediaIds || !is_array($mediaIds)) {
throw new ProductException('No media ids given.');
}
/** @var Product $product */
$product = $this->getProductRepository()->find($productId);
if (!$product) {
throw new EntityNotFoundException($this->getProductEntityName(), $productId);
}
$this->getProductMediaManager()->save($product, $mediaIds);
$this->getEntityManager()->flush();
$view = $this->view(null, Response::HTTP_NO_CONTENT);
return $this->handleView($view);
}
|
php
|
public function putAction(Request $request, $productId)
{
$mediaIds = $request->get('mediaIds');
if (null === $mediaIds || !is_array($mediaIds)) {
throw new ProductException('No media ids given.');
}
/** @var Product $product */
$product = $this->getProductRepository()->find($productId);
if (!$product) {
throw new EntityNotFoundException($this->getProductEntityName(), $productId);
}
$this->getProductMediaManager()->save($product, $mediaIds);
$this->getEntityManager()->flush();
$view = $this->view(null, Response::HTTP_NO_CONTENT);
return $this->handleView($view);
}
|
[
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"productId",
")",
"{",
"$",
"mediaIds",
"=",
"$",
"request",
"->",
"get",
"(",
"'mediaIds'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"mediaIds",
"||",
"!",
"is_array",
"(",
"$",
"mediaIds",
")",
")",
"{",
"throw",
"new",
"ProductException",
"(",
"'No media ids given.'",
")",
";",
"}",
"/** @var Product $product */",
"$",
"product",
"=",
"$",
"this",
"->",
"getProductRepository",
"(",
")",
"->",
"find",
"(",
"$",
"productId",
")",
";",
"if",
"(",
"!",
"$",
"product",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getProductEntityName",
"(",
")",
",",
"$",
"productId",
")",
";",
"}",
"$",
"this",
"->",
"getProductMediaManager",
"(",
")",
"->",
"save",
"(",
"$",
"product",
",",
"$",
"mediaIds",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"Response",
"::",
"HTTP_NO_CONTENT",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Updates media of a product.
@param Request $request
@param int $productId
@throws EntityNotFoundException
@throws ProductException
@return Response
|
[
"Updates",
"media",
"of",
"a",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductMediaController.php#L121-L141
|
224,042
|
sulu/SuluProductBundle
|
Controller/ProductMediaController.php
|
ProductMediaController.deleteAction
|
public function deleteAction($productId, $mediaId)
{
/** @var Product $product */
$product = $this->getProductRepository()->find($productId);
if (!$product) {
throw new EntityNotFoundException($this->getProductEntityName(), $productId);
}
$this->getProductMediaManager()->delete($product, [$mediaId]);
$view = $this->view(null, Response::HTTP_NO_CONTENT);
$this->getEntityManager()->flush();
return $this->handleView($view);
}
|
php
|
public function deleteAction($productId, $mediaId)
{
/** @var Product $product */
$product = $this->getProductRepository()->find($productId);
if (!$product) {
throw new EntityNotFoundException($this->getProductEntityName(), $productId);
}
$this->getProductMediaManager()->delete($product, [$mediaId]);
$view = $this->view(null, Response::HTTP_NO_CONTENT);
$this->getEntityManager()->flush();
return $this->handleView($view);
}
|
[
"public",
"function",
"deleteAction",
"(",
"$",
"productId",
",",
"$",
"mediaId",
")",
"{",
"/** @var Product $product */",
"$",
"product",
"=",
"$",
"this",
"->",
"getProductRepository",
"(",
")",
"->",
"find",
"(",
"$",
"productId",
")",
";",
"if",
"(",
"!",
"$",
"product",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getProductEntityName",
"(",
")",
",",
"$",
"productId",
")",
";",
"}",
"$",
"this",
"->",
"getProductMediaManager",
"(",
")",
"->",
"delete",
"(",
"$",
"product",
",",
"[",
"$",
"mediaId",
"]",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"Response",
"::",
"HTTP_NO_CONTENT",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Removes a media from the relation.
@param int $productId
@param int $mediaId
@throws EntityNotFoundException
@throws ProductException
@return Response
|
[
"Removes",
"a",
"media",
"from",
"the",
"relation",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductMediaController.php#L154-L168
|
224,043
|
sulu/SuluProductBundle
|
Controller/ProductMediaController.php
|
ProductMediaController.removeDefaultPrices
|
private function removeDefaultPrices(Product $product)
{
$defaultPrices = [];
// get default prices
foreach ($product->getPrices() as $price) {
if ($price->getId() === null) {
$defaultPrices[] = $price;
}
}
foreach ($defaultPrices as $price) {
$product->removePrice($price->getEntity());
}
}
|
php
|
private function removeDefaultPrices(Product $product)
{
$defaultPrices = [];
// get default prices
foreach ($product->getPrices() as $price) {
if ($price->getId() === null) {
$defaultPrices[] = $price;
}
}
foreach ($defaultPrices as $price) {
$product->removePrice($price->getEntity());
}
}
|
[
"private",
"function",
"removeDefaultPrices",
"(",
"Product",
"$",
"product",
")",
"{",
"$",
"defaultPrices",
"=",
"[",
"]",
";",
"// get default prices",
"foreach",
"(",
"$",
"product",
"->",
"getPrices",
"(",
")",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getId",
"(",
")",
"===",
"null",
")",
"{",
"$",
"defaultPrices",
"[",
"]",
"=",
"$",
"price",
";",
"}",
"}",
"foreach",
"(",
"$",
"defaultPrices",
"as",
"$",
"price",
")",
"{",
"$",
"product",
"->",
"removePrice",
"(",
"$",
"price",
"->",
"getEntity",
"(",
")",
")",
";",
"}",
"}"
] |
Removes default prices from product.
@param Product $product
|
[
"Removes",
"default",
"prices",
"from",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductMediaController.php#L354-L368
|
224,044
|
unreal4u/mqtt
|
src/Internals/EventManager.php
|
EventManager.analyzeHeaders
|
public function analyzeHeaders(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
{
if ($rawMQTTHeaders === '') {
$this->logger->debug('Empty headers, returning an empty object');
return new EmptyReadableResponse($this->logger);
}
$controlPacketType = \ord($rawMQTTHeaders[0]) >> 4;
if (isset(self::$readableObjects[$controlPacketType])) {
$this->currentObjectType = self::$readableObjects[$controlPacketType];
$this->logger->info('Found a matching object, instantiating', [
'type' => $this->currentObjectType,
'controlPacketNumber' => $controlPacketType,
]);
/** @var ReadableContentInterface $readableContent */
$readableContent = new $this->currentObjectType($this->logger);
$readableContent->instantiateObject($rawMQTTHeaders, $client);
} else {
$this->logger->error('Invalid control packet type found', ['controlPacketType' => $controlPacketType]);
throw new \DomainException(sprintf('Invalid control packet found (%d)', $controlPacketType));
}
return $readableContent;
}
|
php
|
public function analyzeHeaders(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
{
if ($rawMQTTHeaders === '') {
$this->logger->debug('Empty headers, returning an empty object');
return new EmptyReadableResponse($this->logger);
}
$controlPacketType = \ord($rawMQTTHeaders[0]) >> 4;
if (isset(self::$readableObjects[$controlPacketType])) {
$this->currentObjectType = self::$readableObjects[$controlPacketType];
$this->logger->info('Found a matching object, instantiating', [
'type' => $this->currentObjectType,
'controlPacketNumber' => $controlPacketType,
]);
/** @var ReadableContentInterface $readableContent */
$readableContent = new $this->currentObjectType($this->logger);
$readableContent->instantiateObject($rawMQTTHeaders, $client);
} else {
$this->logger->error('Invalid control packet type found', ['controlPacketType' => $controlPacketType]);
throw new \DomainException(sprintf('Invalid control packet found (%d)', $controlPacketType));
}
return $readableContent;
}
|
[
"public",
"function",
"analyzeHeaders",
"(",
"string",
"$",
"rawMQTTHeaders",
",",
"ClientInterface",
"$",
"client",
")",
":",
"ReadableContentInterface",
"{",
"if",
"(",
"$",
"rawMQTTHeaders",
"===",
"''",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Empty headers, returning an empty object'",
")",
";",
"return",
"new",
"EmptyReadableResponse",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"$",
"controlPacketType",
"=",
"\\",
"ord",
"(",
"$",
"rawMQTTHeaders",
"[",
"0",
"]",
")",
">>",
"4",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"readableObjects",
"[",
"$",
"controlPacketType",
"]",
")",
")",
"{",
"$",
"this",
"->",
"currentObjectType",
"=",
"self",
"::",
"$",
"readableObjects",
"[",
"$",
"controlPacketType",
"]",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Found a matching object, instantiating'",
",",
"[",
"'type'",
"=>",
"$",
"this",
"->",
"currentObjectType",
",",
"'controlPacketNumber'",
"=>",
"$",
"controlPacketType",
",",
"]",
")",
";",
"/** @var ReadableContentInterface $readableContent */",
"$",
"readableContent",
"=",
"new",
"$",
"this",
"->",
"currentObjectType",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"$",
"readableContent",
"->",
"instantiateObject",
"(",
"$",
"rawMQTTHeaders",
",",
"$",
"client",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"'Invalid control packet type found'",
",",
"[",
"'controlPacketType'",
"=>",
"$",
"controlPacketType",
"]",
")",
";",
"throw",
"new",
"\\",
"DomainException",
"(",
"sprintf",
"(",
"'Invalid control packet found (%d)'",
",",
"$",
"controlPacketType",
")",
")",
";",
"}",
"return",
"$",
"readableContent",
";",
"}"
] |
Will check within all the Readable objects whether one of those is the correct packet we are looking for
@param string $rawMQTTHeaders Arbitrary size of minimum 1 incoming byte(s)
@param ClientInterface $client Used if the object itself needs to process some more stuff
@return ReadableContentInterface
@throws \DomainException
|
[
"Will",
"check",
"within",
"all",
"the",
"Readable",
"objects",
"whether",
"one",
"of",
"those",
"is",
"the",
"correct",
"packet",
"we",
"are",
"looking",
"for"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/EventManager.php#L76-L99
|
224,045
|
sulu/SuluProductBundle
|
Entity/BaseProduct.php
|
BaseProduct.isValidShopProduct
|
public function isValidShopProduct($defaultCurrency)
{
$isValid = false;
if (method_exists($this, 'getPrices') &&
$this->getStatus()->getId() == Status::ACTIVE &&
$this->getPrices() &&
count($this->getPrices()) > 0 &&
$this->hasPriceInDefaultCurrency($this->getPrices(), $defaultCurrency) &&
$this->getSupplier()
) {
$isValid = true;
}
return $isValid;
}
|
php
|
public function isValidShopProduct($defaultCurrency)
{
$isValid = false;
if (method_exists($this, 'getPrices') &&
$this->getStatus()->getId() == Status::ACTIVE &&
$this->getPrices() &&
count($this->getPrices()) > 0 &&
$this->hasPriceInDefaultCurrency($this->getPrices(), $defaultCurrency) &&
$this->getSupplier()
) {
$isValid = true;
}
return $isValid;
}
|
[
"public",
"function",
"isValidShopProduct",
"(",
"$",
"defaultCurrency",
")",
"{",
"$",
"isValid",
"=",
"false",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'getPrices'",
")",
"&&",
"$",
"this",
"->",
"getStatus",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"Status",
"::",
"ACTIVE",
"&&",
"$",
"this",
"->",
"getPrices",
"(",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"getPrices",
"(",
")",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"hasPriceInDefaultCurrency",
"(",
"$",
"this",
"->",
"getPrices",
"(",
")",
",",
"$",
"defaultCurrency",
")",
"&&",
"$",
"this",
"->",
"getSupplier",
"(",
")",
")",
"{",
"$",
"isValid",
"=",
"true",
";",
"}",
"return",
"$",
"isValid",
";",
"}"
] |
Helper method to check if the product is
a valid shop product.
@param string $defaultCurrency
@return bool
|
[
"Helper",
"method",
"to",
"check",
"if",
"the",
"product",
"is",
"a",
"valid",
"shop",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/BaseProduct.php#L1103-L1118
|
224,046
|
sulu/SuluProductBundle
|
Entity/BaseProduct.php
|
BaseProduct.hasPriceInDefaultCurrency
|
private function hasPriceInDefaultCurrency($prices, $defaultCurrency)
{
foreach ($prices as $price) {
if ($price->getCurrency()->getCode() === $defaultCurrency) {
return true;
}
}
return false;
}
|
php
|
private function hasPriceInDefaultCurrency($prices, $defaultCurrency)
{
foreach ($prices as $price) {
if ($price->getCurrency()->getCode() === $defaultCurrency) {
return true;
}
}
return false;
}
|
[
"private",
"function",
"hasPriceInDefaultCurrency",
"(",
"$",
"prices",
",",
"$",
"defaultCurrency",
")",
"{",
"foreach",
"(",
"$",
"prices",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getCode",
"(",
")",
"===",
"$",
"defaultCurrency",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks if price in default currency exists.
@param ProductPrice[] $prices
@param string $defaultCurrency
@return bool
|
[
"Checks",
"if",
"price",
"in",
"default",
"currency",
"exists",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/BaseProduct.php#L1128-L1137
|
224,047
|
laravelflare/mail-debug
|
src/MailDebug/Providers/RouteServiceProvider.php
|
RouteServiceProvider.registerRoutes
|
protected function registerRoutes(Router $router)
{
$debug = $this->app->make(MailDebugManager::class);
$router->get('mail-debug/{file}', function ($file) use ($debug) {
if (file_exists($path = $debug->storage().'/'.$file)) {
include $path;
return;
}
return abort(404);
})->name('mail-debug');
}
|
php
|
protected function registerRoutes(Router $router)
{
$debug = $this->app->make(MailDebugManager::class);
$router->get('mail-debug/{file}', function ($file) use ($debug) {
if (file_exists($path = $debug->storage().'/'.$file)) {
include $path;
return;
}
return abort(404);
})->name('mail-debug');
}
|
[
"protected",
"function",
"registerRoutes",
"(",
"Router",
"$",
"router",
")",
"{",
"$",
"debug",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"MailDebugManager",
"::",
"class",
")",
";",
"$",
"router",
"->",
"get",
"(",
"'mail-debug/{file}'",
",",
"function",
"(",
"$",
"file",
")",
"use",
"(",
"$",
"debug",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
"=",
"$",
"debug",
"->",
"storage",
"(",
")",
".",
"'/'",
".",
"$",
"file",
")",
")",
"{",
"include",
"$",
"path",
";",
"return",
";",
"}",
"return",
"abort",
"(",
"404",
")",
";",
"}",
")",
"->",
"name",
"(",
"'mail-debug'",
")",
";",
"}"
] |
Register the Mail Debug Routes.
@param Router $router
|
[
"Register",
"the",
"Mail",
"Debug",
"Routes",
"."
] |
337642f5afd6d585ccfe9fd16efa95a60db9500d
|
https://github.com/laravelflare/mail-debug/blob/337642f5afd6d585ccfe9fd16efa95a60db9500d/src/MailDebug/Providers/RouteServiceProvider.php#L51-L63
|
224,048
|
sulu/SuluProductBundle
|
Product/Mapper/ProductContentMapper.php
|
ProductContentMapper.parseContentToArray
|
private function parseContentToArray(ProductTranslation $productTranslation)
{
$routePath = null;
if ($productTranslation->getRoute()) {
$routePath = $productTranslation->getRoute()->getPath();
}
return [
'title' => $productTranslation->getContentTitle(),
'routePath' => $routePath,
];
}
|
php
|
private function parseContentToArray(ProductTranslation $productTranslation)
{
$routePath = null;
if ($productTranslation->getRoute()) {
$routePath = $productTranslation->getRoute()->getPath();
}
return [
'title' => $productTranslation->getContentTitle(),
'routePath' => $routePath,
];
}
|
[
"private",
"function",
"parseContentToArray",
"(",
"ProductTranslation",
"$",
"productTranslation",
")",
"{",
"$",
"routePath",
"=",
"null",
";",
"if",
"(",
"$",
"productTranslation",
"->",
"getRoute",
"(",
")",
")",
"{",
"$",
"routePath",
"=",
"$",
"productTranslation",
"->",
"getRoute",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"}",
"return",
"[",
"'title'",
"=>",
"$",
"productTranslation",
"->",
"getContentTitle",
"(",
")",
",",
"'routePath'",
"=>",
"$",
"routePath",
",",
"]",
";",
"}"
] |
Parses product content data to an array.
@param ProductTranslation $productTranslation
@return array
|
[
"Parses",
"product",
"content",
"data",
"to",
"an",
"array",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/Mapper/ProductContentMapper.php#L82-L93
|
224,049
|
unreal4u/mqtt
|
src/DataTypes/TopicName.php
|
TopicName.setTopicName
|
private function setTopicName(string $topicName): self
{
$this->generalRulesCheck($topicName);
// A topic name has some additional checks, as no wildcard characters are allowed
if (strpbrk($topicName, '#+') !== false) {
throw new \InvalidArgumentException('Topic names can not contain wildcard characters');
}
$this->topicName = $topicName;
return $this;
}
|
php
|
private function setTopicName(string $topicName): self
{
$this->generalRulesCheck($topicName);
// A topic name has some additional checks, as no wildcard characters are allowed
if (strpbrk($topicName, '#+') !== false) {
throw new \InvalidArgumentException('Topic names can not contain wildcard characters');
}
$this->topicName = $topicName;
return $this;
}
|
[
"private",
"function",
"setTopicName",
"(",
"string",
"$",
"topicName",
")",
":",
"self",
"{",
"$",
"this",
"->",
"generalRulesCheck",
"(",
"$",
"topicName",
")",
";",
"// A topic name has some additional checks, as no wildcard characters are allowed",
"if",
"(",
"strpbrk",
"(",
"$",
"topicName",
",",
"'#+'",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Topic names can not contain wildcard characters'",
")",
";",
"}",
"$",
"this",
"->",
"topicName",
"=",
"$",
"topicName",
";",
"return",
"$",
"this",
";",
"}"
] |
Contains the name of the TopicFilter Filter
@param string $topicName
@return TopicName
@throws \OutOfBoundsException
@throws \InvalidArgumentException
|
[
"Contains",
"the",
"name",
"of",
"the",
"TopicFilter",
"Filter"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/DataTypes/TopicName.php#L42-L53
|
224,050
|
ibuildingsnl/qa-tools
|
src/Core/Task/Executor/Sigints.php
|
Sigints.resetTrap
|
public static function resetTrap()
{
if (!self::$registered) {
throw new RuntimeException('Signal handler has not been registered');
}
if (!pcntl_signal_dispatch()) {
throw new RuntimeException(
sprintf('Call to pcntl_signal_dispatch() failed (PHP error: "%s")', @error_get_last()['message'])
);
}
if (!pcntl_signal(SIGINT, SIG_DFL)) {
throw new RuntimeException(
sprintf(
'Could not relinquish control to PHP by registering default signal handler (PHP error: "%s")',
@error_get_last()['message']
)
);
}
self::$registered = false;
}
|
php
|
public static function resetTrap()
{
if (!self::$registered) {
throw new RuntimeException('Signal handler has not been registered');
}
if (!pcntl_signal_dispatch()) {
throw new RuntimeException(
sprintf('Call to pcntl_signal_dispatch() failed (PHP error: "%s")', @error_get_last()['message'])
);
}
if (!pcntl_signal(SIGINT, SIG_DFL)) {
throw new RuntimeException(
sprintf(
'Could not relinquish control to PHP by registering default signal handler (PHP error: "%s")',
@error_get_last()['message']
)
);
}
self::$registered = false;
}
|
[
"public",
"static",
"function",
"resetTrap",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"registered",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Signal handler has not been registered'",
")",
";",
"}",
"if",
"(",
"!",
"pcntl_signal_dispatch",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Call to pcntl_signal_dispatch() failed (PHP error: \"%s\")'",
",",
"@",
"error_get_last",
"(",
")",
"[",
"'message'",
"]",
")",
")",
";",
"}",
"if",
"(",
"!",
"pcntl_signal",
"(",
"SIGINT",
",",
"SIG_DFL",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Could not relinquish control to PHP by registering default signal handler (PHP error: \"%s\")'",
",",
"@",
"error_get_last",
"(",
")",
"[",
"'message'",
"]",
")",
")",
";",
"}",
"self",
"::",
"$",
"registered",
"=",
"false",
";",
"}"
] |
Relinquish control to PHP.
@return void
|
[
"Relinquish",
"control",
"to",
"PHP",
"."
] |
0c4999a74c55b03a826e1c881f75ee3fba6329f7
|
https://github.com/ibuildingsnl/qa-tools/blob/0c4999a74c55b03a826e1c881f75ee3fba6329f7/src/Core/Task/Executor/Sigints.php#L37-L57
|
224,051
|
unreal4u/mqtt
|
src/Internals/PacketIdentifierFunctionality.php
|
PacketIdentifierFunctionality.setPacketIdentifierFromRawHeaders
|
final public function setPacketIdentifierFromRawHeaders(string $rawMQTTHeaders): self
{
$this->packetIdentifier = new PacketIdentifier(
Utilities::convertBinaryStringToNumber($rawMQTTHeaders{2} . $rawMQTTHeaders{3})
);
return $this;
}
|
php
|
final public function setPacketIdentifierFromRawHeaders(string $rawMQTTHeaders): self
{
$this->packetIdentifier = new PacketIdentifier(
Utilities::convertBinaryStringToNumber($rawMQTTHeaders{2} . $rawMQTTHeaders{3})
);
return $this;
}
|
[
"final",
"public",
"function",
"setPacketIdentifierFromRawHeaders",
"(",
"string",
"$",
"rawMQTTHeaders",
")",
":",
"self",
"{",
"$",
"this",
"->",
"packetIdentifier",
"=",
"new",
"PacketIdentifier",
"(",
"Utilities",
"::",
"convertBinaryStringToNumber",
"(",
"$",
"rawMQTTHeaders",
"{",
"2",
"}",
".",
"$",
"rawMQTTHeaders",
"{",
"3",
"}",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the packet identifier straight from the raw MQTT headers
@param string $rawMQTTHeaders
@return self
@throws \OutOfRangeException
|
[
"Sets",
"the",
"packet",
"identifier",
"straight",
"from",
"the",
"raw",
"MQTT",
"headers"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/PacketIdentifierFunctionality.php#L56-L63
|
224,052
|
unreal4u/mqtt
|
src/Internals/PacketIdentifierFunctionality.php
|
PacketIdentifierFunctionality.controlPacketIdentifiers
|
private function controlPacketIdentifiers(WritableContentInterface $originalRequest): bool
{
/** @var PacketIdentifierFunctionality $originalRequest */
if ($this->getPacketIdentifier() !== $originalRequest->getPacketIdentifier()) {
$e = new NonMatchingPacketIdentifiers('Packet identifiers do not match');
$e->setOriginPacketIdentifier(new PacketIdentifier($originalRequest->getPacketIdentifier()));
$e->setReturnedPacketIdentifier($this->packetIdentifier);
throw $e;
}
return true;
}
|
php
|
private function controlPacketIdentifiers(WritableContentInterface $originalRequest): bool
{
/** @var PacketIdentifierFunctionality $originalRequest */
if ($this->getPacketIdentifier() !== $originalRequest->getPacketIdentifier()) {
$e = new NonMatchingPacketIdentifiers('Packet identifiers do not match');
$e->setOriginPacketIdentifier(new PacketIdentifier($originalRequest->getPacketIdentifier()));
$e->setReturnedPacketIdentifier($this->packetIdentifier);
throw $e;
}
return true;
}
|
[
"private",
"function",
"controlPacketIdentifiers",
"(",
"WritableContentInterface",
"$",
"originalRequest",
")",
":",
"bool",
"{",
"/** @var PacketIdentifierFunctionality $originalRequest */",
"if",
"(",
"$",
"this",
"->",
"getPacketIdentifier",
"(",
")",
"!==",
"$",
"originalRequest",
"->",
"getPacketIdentifier",
"(",
")",
")",
"{",
"$",
"e",
"=",
"new",
"NonMatchingPacketIdentifiers",
"(",
"'Packet identifiers do not match'",
")",
";",
"$",
"e",
"->",
"setOriginPacketIdentifier",
"(",
"new",
"PacketIdentifier",
"(",
"$",
"originalRequest",
"->",
"getPacketIdentifier",
"(",
")",
")",
")",
";",
"$",
"e",
"->",
"setReturnedPacketIdentifier",
"(",
"$",
"this",
"->",
"packetIdentifier",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks whether the original request with the current stored packet identifier matches
@param WritableContentInterface $originalRequest
@throws NonMatchingPacketIdentifiers
@return bool
|
[
"Checks",
"whether",
"the",
"original",
"request",
"with",
"the",
"current",
"stored",
"packet",
"identifier",
"matches"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/PacketIdentifierFunctionality.php#L89-L100
|
224,053
|
culturekings/afterpay
|
src/Service/InStore/Order.php
|
Order.createOrReverse
|
public function createOrReverse(
Model\InStore\Order $order,
Model\InStore\Reversal $orderReversal = null,
HandlerStack $stack = null
) {
try {
return $this->create($order, $stack);
} catch (ApiException $orderException) {
// http://docs.afterpay.com.au/instore-api-v1.html#create-order
// Should a success or error response (with exception to 409 conflict) not be received,
// the POS should queue the request ID for reversal
if ($orderException->getErrorResponse()->getErrorCode() === self::ERROR_CONFLICT) {
throw $orderException;
}
$errorResponse = $orderException->getErrorResponse();
} catch (RequestException $orderException) {
// a timeout or other exception has occurred. attempt a reversal
$errorResponse = new Model\ErrorResponse();
$errorResponse->setHttpStatusCode(
$orderException->getResponse() ? $orderException->getResponse()->getStatusCode() : self::ERROR_INTERNAL_ERROR
);
$errorResponse->setMessage($orderException->getMessage());
}
if ($orderReversal === null) {
$orderReversal = new Model\InStore\Reversal();
$orderReversal->setReversingRequestId($order->getRequestId());
$orderReversal->setRequestedAt(new DateTime());
}
try {
$reversal = $this->reverse($orderReversal, $stack);
$reversal->setErrorReason($errorResponse);
return $reversal;
} catch (ApiException $reversalException) {
$reversalErrorResponse = $reversalException->getErrorResponse();
if ($reversalErrorResponse->getErrorCode() === self::ERROR_MSG_PRECONDITION_FAILED) {
// there was trouble reversing probably because the order failed
throw $orderException;
}
throw $reversalException;
}
}
|
php
|
public function createOrReverse(
Model\InStore\Order $order,
Model\InStore\Reversal $orderReversal = null,
HandlerStack $stack = null
) {
try {
return $this->create($order, $stack);
} catch (ApiException $orderException) {
// http://docs.afterpay.com.au/instore-api-v1.html#create-order
// Should a success or error response (with exception to 409 conflict) not be received,
// the POS should queue the request ID for reversal
if ($orderException->getErrorResponse()->getErrorCode() === self::ERROR_CONFLICT) {
throw $orderException;
}
$errorResponse = $orderException->getErrorResponse();
} catch (RequestException $orderException) {
// a timeout or other exception has occurred. attempt a reversal
$errorResponse = new Model\ErrorResponse();
$errorResponse->setHttpStatusCode(
$orderException->getResponse() ? $orderException->getResponse()->getStatusCode() : self::ERROR_INTERNAL_ERROR
);
$errorResponse->setMessage($orderException->getMessage());
}
if ($orderReversal === null) {
$orderReversal = new Model\InStore\Reversal();
$orderReversal->setReversingRequestId($order->getRequestId());
$orderReversal->setRequestedAt(new DateTime());
}
try {
$reversal = $this->reverse($orderReversal, $stack);
$reversal->setErrorReason($errorResponse);
return $reversal;
} catch (ApiException $reversalException) {
$reversalErrorResponse = $reversalException->getErrorResponse();
if ($reversalErrorResponse->getErrorCode() === self::ERROR_MSG_PRECONDITION_FAILED) {
// there was trouble reversing probably because the order failed
throw $orderException;
}
throw $reversalException;
}
}
|
[
"public",
"function",
"createOrReverse",
"(",
"Model",
"\\",
"InStore",
"\\",
"Order",
"$",
"order",
",",
"Model",
"\\",
"InStore",
"\\",
"Reversal",
"$",
"orderReversal",
"=",
"null",
",",
"HandlerStack",
"$",
"stack",
"=",
"null",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"create",
"(",
"$",
"order",
",",
"$",
"stack",
")",
";",
"}",
"catch",
"(",
"ApiException",
"$",
"orderException",
")",
"{",
"// http://docs.afterpay.com.au/instore-api-v1.html#create-order",
"// Should a success or error response (with exception to 409 conflict) not be received,",
"// the POS should queue the request ID for reversal",
"if",
"(",
"$",
"orderException",
"->",
"getErrorResponse",
"(",
")",
"->",
"getErrorCode",
"(",
")",
"===",
"self",
"::",
"ERROR_CONFLICT",
")",
"{",
"throw",
"$",
"orderException",
";",
"}",
"$",
"errorResponse",
"=",
"$",
"orderException",
"->",
"getErrorResponse",
"(",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"orderException",
")",
"{",
"// a timeout or other exception has occurred. attempt a reversal",
"$",
"errorResponse",
"=",
"new",
"Model",
"\\",
"ErrorResponse",
"(",
")",
";",
"$",
"errorResponse",
"->",
"setHttpStatusCode",
"(",
"$",
"orderException",
"->",
"getResponse",
"(",
")",
"?",
"$",
"orderException",
"->",
"getResponse",
"(",
")",
"->",
"getStatusCode",
"(",
")",
":",
"self",
"::",
"ERROR_INTERNAL_ERROR",
")",
";",
"$",
"errorResponse",
"->",
"setMessage",
"(",
"$",
"orderException",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"orderReversal",
"===",
"null",
")",
"{",
"$",
"orderReversal",
"=",
"new",
"Model",
"\\",
"InStore",
"\\",
"Reversal",
"(",
")",
";",
"$",
"orderReversal",
"->",
"setReversingRequestId",
"(",
"$",
"order",
"->",
"getRequestId",
"(",
")",
")",
";",
"$",
"orderReversal",
"->",
"setRequestedAt",
"(",
"new",
"DateTime",
"(",
")",
")",
";",
"}",
"try",
"{",
"$",
"reversal",
"=",
"$",
"this",
"->",
"reverse",
"(",
"$",
"orderReversal",
",",
"$",
"stack",
")",
";",
"$",
"reversal",
"->",
"setErrorReason",
"(",
"$",
"errorResponse",
")",
";",
"return",
"$",
"reversal",
";",
"}",
"catch",
"(",
"ApiException",
"$",
"reversalException",
")",
"{",
"$",
"reversalErrorResponse",
"=",
"$",
"reversalException",
"->",
"getErrorResponse",
"(",
")",
";",
"if",
"(",
"$",
"reversalErrorResponse",
"->",
"getErrorCode",
"(",
")",
"===",
"self",
"::",
"ERROR_MSG_PRECONDITION_FAILED",
")",
"{",
"// there was trouble reversing probably because the order failed",
"throw",
"$",
"orderException",
";",
"}",
"throw",
"$",
"reversalException",
";",
"}",
"}"
] |
Helper method to automatically attempt to reverse an order if an error occurs.
Order reversal model does not have to be passed in and will be automatically generated if not.
@param Model\InStore\Order $order
@param Model\InStore\Reversal|null $orderReversal
@param HandlerStack|null $stack
@return Model\InStore\Order|Model\InStore\Reversal|array|\JMS\Serializer\scalar|object
|
[
"Helper",
"method",
"to",
"automatically",
"attempt",
"to",
"reverse",
"an",
"order",
"if",
"an",
"error",
"occurs",
"."
] |
d2fde2eed6d6102464ffd9d3bea7623f31e77a61
|
https://github.com/culturekings/afterpay/blob/d2fde2eed6d6102464ffd9d3bea7623f31e77a61/src/Service/InStore/Order.php#L100-L146
|
224,054
|
mrclay/shibalike
|
src/Shibalike/SP.php
|
SP.makeAuthRequest
|
public function makeAuthRequest($returnUrl = null)
{
if (empty($returnUrl)) {
$returnUrl = $this->getReturnUrl();
}
$this->_stateMgr->set('authRequest', new AuthRequest($returnUrl));
$this->_stateMgr->set('authResult');
}
|
php
|
public function makeAuthRequest($returnUrl = null)
{
if (empty($returnUrl)) {
$returnUrl = $this->getReturnUrl();
}
$this->_stateMgr->set('authRequest', new AuthRequest($returnUrl));
$this->_stateMgr->set('authResult');
}
|
[
"public",
"function",
"makeAuthRequest",
"(",
"$",
"returnUrl",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"returnUrl",
")",
")",
"{",
"$",
"returnUrl",
"=",
"$",
"this",
"->",
"getReturnUrl",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_stateMgr",
"->",
"set",
"(",
"'authRequest'",
",",
"new",
"AuthRequest",
"(",
"$",
"returnUrl",
")",
")",
";",
"$",
"this",
"->",
"_stateMgr",
"->",
"set",
"(",
"'authResult'",
")",
";",
"}"
] |
Instruct IdP that this user wishes to be authenticated
@param string $returnUrl if null, getReturnUrl() is used
|
[
"Instruct",
"IdP",
"that",
"this",
"user",
"wishes",
"to",
"be",
"authenticated"
] |
04242301ed18f5a1b02493bcc193f5efd255112e
|
https://github.com/mrclay/shibalike/blob/04242301ed18f5a1b02493bcc193f5efd255112e/src/Shibalike/SP.php#L78-L85
|
224,055
|
mrclay/shibalike
|
src/Shibalike/SP.php
|
SP.createFileBased
|
public static function createFileBased($idpUrl, $cookieName = 'SHIBALIKE', $sessionPath = null)
{
if (empty($sessionPath)) {
$sessionPath = sys_get_temp_dir();
}
$session = SessionBuilder::instance()
->setName($cookieName)
->setSavePath($sessionPath)
->build();
$stateMgr = new UserlandSessionStateMgr($session);
$config = new Config();
$config->idpUrl = $idpUrl;
return new self($stateMgr, $config);
}
|
php
|
public static function createFileBased($idpUrl, $cookieName = 'SHIBALIKE', $sessionPath = null)
{
if (empty($sessionPath)) {
$sessionPath = sys_get_temp_dir();
}
$session = SessionBuilder::instance()
->setName($cookieName)
->setSavePath($sessionPath)
->build();
$stateMgr = new UserlandSessionStateMgr($session);
$config = new Config();
$config->idpUrl = $idpUrl;
return new self($stateMgr, $config);
}
|
[
"public",
"static",
"function",
"createFileBased",
"(",
"$",
"idpUrl",
",",
"$",
"cookieName",
"=",
"'SHIBALIKE'",
",",
"$",
"sessionPath",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sessionPath",
")",
")",
"{",
"$",
"sessionPath",
"=",
"sys_get_temp_dir",
"(",
")",
";",
"}",
"$",
"session",
"=",
"SessionBuilder",
"::",
"instance",
"(",
")",
"->",
"setName",
"(",
"$",
"cookieName",
")",
"->",
"setSavePath",
"(",
"$",
"sessionPath",
")",
"->",
"build",
"(",
")",
";",
"$",
"stateMgr",
"=",
"new",
"UserlandSessionStateMgr",
"(",
"$",
"session",
")",
";",
"$",
"config",
"=",
"new",
"Config",
"(",
")",
";",
"$",
"config",
"->",
"idpUrl",
"=",
"$",
"idpUrl",
";",
"return",
"new",
"self",
"(",
"$",
"stateMgr",
",",
"$",
"config",
")",
";",
"}"
] |
Creates an SP that stores session data in files
@param string $idpUrl URL where the IdP class is used to handle SP auth requests
@param string $cookieName
@param string $sessionPath path where session files are stored
@return SP|false false if a UserlandSession already exists under this cookie name
|
[
"Creates",
"an",
"SP",
"that",
"stores",
"session",
"data",
"in",
"files"
] |
04242301ed18f5a1b02493bcc193f5efd255112e
|
https://github.com/mrclay/shibalike/blob/04242301ed18f5a1b02493bcc193f5efd255112e/src/Shibalike/SP.php#L119-L133
|
224,056
|
sulu/SuluProductBundle
|
Product/CurrencyManager.php
|
CurrencyManager.findAll
|
public function findAll($locale)
{
$currencies = $this->currencyRepository->findAll();
array_walk(
$currencies,
function (&$currency) use ($locale) {
$currency = new Currency($currency, $locale);
}
);
return $currencies;
}
|
php
|
public function findAll($locale)
{
$currencies = $this->currencyRepository->findAll();
array_walk(
$currencies,
function (&$currency) use ($locale) {
$currency = new Currency($currency, $locale);
}
);
return $currencies;
}
|
[
"public",
"function",
"findAll",
"(",
"$",
"locale",
")",
"{",
"$",
"currencies",
"=",
"$",
"this",
"->",
"currencyRepository",
"->",
"findAll",
"(",
")",
";",
"array_walk",
"(",
"$",
"currencies",
",",
"function",
"(",
"&",
"$",
"currency",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"$",
"currency",
"=",
"new",
"Currency",
"(",
"$",
"currency",
",",
"$",
"locale",
")",
";",
"}",
")",
";",
"return",
"$",
"currencies",
";",
"}"
] |
Find all currencies.
@param $locale
@return Currency[]
|
[
"Find",
"all",
"currencies",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/CurrencyManager.php#L39-L51
|
224,057
|
sulu/SuluProductBundle
|
Product/CurrencyManager.php
|
CurrencyManager.findById
|
public function findById($id, $locale)
{
$currency = $this->currencyRepository->findById($id);
return new Currency($currency, $locale);
}
|
php
|
public function findById($id, $locale)
{
$currency = $this->currencyRepository->findById($id);
return new Currency($currency, $locale);
}
|
[
"public",
"function",
"findById",
"(",
"$",
"id",
",",
"$",
"locale",
")",
"{",
"$",
"currency",
"=",
"$",
"this",
"->",
"currencyRepository",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"return",
"new",
"Currency",
"(",
"$",
"currency",
",",
"$",
"locale",
")",
";",
"}"
] |
Finds a currency by id and locale.
@param $id
@param $locale
@return \Sulu\Bundle\ProductBundle\Api\Currency
|
[
"Finds",
"a",
"currency",
"by",
"id",
"and",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/CurrencyManager.php#L77-L82
|
224,058
|
kesar/PhpOpenSubtitles
|
src/kesar/PhpOpenSubtitles/SubtitlesManager.php
|
SubtitlesManager.logIn
|
private function logIn()
{
$request = xmlrpc_encode_request(
"LogIn",
array($this->username, $this->password, $this->lang, $this->userAgent)
);
$response = $this->generateResponse($request);
if (($response && xmlrpc_is_fault($response))) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
if ($this->isWrongStatus($response)) {
trigger_error('no login');
} else {
return $response['token'];
}
}
return false;
}
|
php
|
private function logIn()
{
$request = xmlrpc_encode_request(
"LogIn",
array($this->username, $this->password, $this->lang, $this->userAgent)
);
$response = $this->generateResponse($request);
if (($response && xmlrpc_is_fault($response))) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
if ($this->isWrongStatus($response)) {
trigger_error('no login');
} else {
return $response['token'];
}
}
return false;
}
|
[
"private",
"function",
"logIn",
"(",
")",
"{",
"$",
"request",
"=",
"xmlrpc_encode_request",
"(",
"\"LogIn\"",
",",
"array",
"(",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"this",
"->",
"lang",
",",
"$",
"this",
"->",
"userAgent",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"generateResponse",
"(",
"$",
"request",
")",
";",
"if",
"(",
"(",
"$",
"response",
"&&",
"xmlrpc_is_fault",
"(",
"$",
"response",
")",
")",
")",
"{",
"trigger_error",
"(",
"\"xmlrpc: $response[faultString] ($response[faultCode])\"",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"isWrongStatus",
"(",
"$",
"response",
")",
")",
"{",
"trigger_error",
"(",
"'no login'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"response",
"[",
"'token'",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Log in the OpenSubtitles.org API
|
[
"Log",
"in",
"the",
"OpenSubtitles",
".",
"org",
"API"
] |
8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3
|
https://github.com/kesar/PhpOpenSubtitles/blob/8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3/src/kesar/PhpOpenSubtitles/SubtitlesManager.php#L30-L48
|
224,059
|
kesar/PhpOpenSubtitles
|
src/kesar/PhpOpenSubtitles/SubtitlesManager.php
|
SubtitlesManager.searchSubtitles
|
private function searchSubtitles($userToken, $movieToken, $fileSize)
{
$request = xmlrpc_encode_request(
"SearchSubtitles",
array(
$userToken,
array(
array('sublanguageid' => $this->lang, 'moviehash' => $movieToken, 'moviebytesize' => $fileSize)
)
)
);
$response = $this->generateResponse($request);
if (($response && xmlrpc_is_fault($response))) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
if ($this->isWrongStatus($response)) {
trigger_error('no login');
} else {
return $response;
}
}
return array();
}
|
php
|
private function searchSubtitles($userToken, $movieToken, $fileSize)
{
$request = xmlrpc_encode_request(
"SearchSubtitles",
array(
$userToken,
array(
array('sublanguageid' => $this->lang, 'moviehash' => $movieToken, 'moviebytesize' => $fileSize)
)
)
);
$response = $this->generateResponse($request);
if (($response && xmlrpc_is_fault($response))) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
if ($this->isWrongStatus($response)) {
trigger_error('no login');
} else {
return $response;
}
}
return array();
}
|
[
"private",
"function",
"searchSubtitles",
"(",
"$",
"userToken",
",",
"$",
"movieToken",
",",
"$",
"fileSize",
")",
"{",
"$",
"request",
"=",
"xmlrpc_encode_request",
"(",
"\"SearchSubtitles\"",
",",
"array",
"(",
"$",
"userToken",
",",
"array",
"(",
"array",
"(",
"'sublanguageid'",
"=>",
"$",
"this",
"->",
"lang",
",",
"'moviehash'",
"=>",
"$",
"movieToken",
",",
"'moviebytesize'",
"=>",
"$",
"fileSize",
")",
")",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"generateResponse",
"(",
"$",
"request",
")",
";",
"if",
"(",
"(",
"$",
"response",
"&&",
"xmlrpc_is_fault",
"(",
"$",
"response",
")",
")",
")",
"{",
"trigger_error",
"(",
"\"xmlrpc: $response[faultString] ($response[faultCode])\"",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"isWrongStatus",
"(",
"$",
"response",
")",
")",
"{",
"trigger_error",
"(",
"'no login'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"response",
";",
"}",
"}",
"return",
"array",
"(",
")",
";",
"}"
] |
Search for a list of subtitles in opensubtitles.org
@param string $userToken
@param string $movieToken
@param int $fileSize
@return array
|
[
"Search",
"for",
"a",
"list",
"of",
"subtitles",
"in",
"opensubtitles",
".",
"org"
] |
8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3
|
https://github.com/kesar/PhpOpenSubtitles/blob/8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3/src/kesar/PhpOpenSubtitles/SubtitlesManager.php#L64-L87
|
224,060
|
amsgames/laravel-shop-gateway-paypal
|
src/GatewayPayPalExpress.php
|
GatewayPayPalExpress.onCallbackSuccess
|
public function onCallbackSuccess($order, $data = null)
{
$paymentId = is_array($data) ? $data['paymentId'] : $data->paymentId;
$payerId = is_array($data) ? $data['PayerID'] : $data->PayerID;
$this->statusCode = 'failed';
$this->detail = sprintf('Payment failed. Ref: %s', $paymentId);
// Begin paypal
try {
$this->setContext();
$payment = Payment::get($paymentId, $this->apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
$payment->execute($execution, $this->apiContext);
$payment = Payment::get($paymentId, $this->apiContext);
$this->statusCode = 'completed';
$this->transactionId = $payment->id;
$this->detail = 'Success';
} catch (PayPalConnectionException $e) {
$response = json_decode($e->getData());
throw new GatewayException(
sprintf(
'%s: %s',
$response->name,
isset($response->message) ? $response->message : 'Paypal payment Failed.'
),
1001,
$e
);
} catch (\Exception $e) {
throw new GatewayException(
$e->getMessage(),
1000,
$e
);
}
}
|
php
|
public function onCallbackSuccess($order, $data = null)
{
$paymentId = is_array($data) ? $data['paymentId'] : $data->paymentId;
$payerId = is_array($data) ? $data['PayerID'] : $data->PayerID;
$this->statusCode = 'failed';
$this->detail = sprintf('Payment failed. Ref: %s', $paymentId);
// Begin paypal
try {
$this->setContext();
$payment = Payment::get($paymentId, $this->apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
$payment->execute($execution, $this->apiContext);
$payment = Payment::get($paymentId, $this->apiContext);
$this->statusCode = 'completed';
$this->transactionId = $payment->id;
$this->detail = 'Success';
} catch (PayPalConnectionException $e) {
$response = json_decode($e->getData());
throw new GatewayException(
sprintf(
'%s: %s',
$response->name,
isset($response->message) ? $response->message : 'Paypal payment Failed.'
),
1001,
$e
);
} catch (\Exception $e) {
throw new GatewayException(
$e->getMessage(),
1000,
$e
);
}
}
|
[
"public",
"function",
"onCallbackSuccess",
"(",
"$",
"order",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"paymentId",
"=",
"is_array",
"(",
"$",
"data",
")",
"?",
"$",
"data",
"[",
"'paymentId'",
"]",
":",
"$",
"data",
"->",
"paymentId",
";",
"$",
"payerId",
"=",
"is_array",
"(",
"$",
"data",
")",
"?",
"$",
"data",
"[",
"'PayerID'",
"]",
":",
"$",
"data",
"->",
"PayerID",
";",
"$",
"this",
"->",
"statusCode",
"=",
"'failed'",
";",
"$",
"this",
"->",
"detail",
"=",
"sprintf",
"(",
"'Payment failed. Ref: %s'",
",",
"$",
"paymentId",
")",
";",
"// Begin paypal",
"try",
"{",
"$",
"this",
"->",
"setContext",
"(",
")",
";",
"$",
"payment",
"=",
"Payment",
"::",
"get",
"(",
"$",
"paymentId",
",",
"$",
"this",
"->",
"apiContext",
")",
";",
"$",
"execution",
"=",
"new",
"PaymentExecution",
"(",
")",
";",
"$",
"execution",
"->",
"setPayerId",
"(",
"$",
"payerId",
")",
";",
"$",
"payment",
"->",
"execute",
"(",
"$",
"execution",
",",
"$",
"this",
"->",
"apiContext",
")",
";",
"$",
"payment",
"=",
"Payment",
"::",
"get",
"(",
"$",
"paymentId",
",",
"$",
"this",
"->",
"apiContext",
")",
";",
"$",
"this",
"->",
"statusCode",
"=",
"'completed'",
";",
"$",
"this",
"->",
"transactionId",
"=",
"$",
"payment",
"->",
"id",
";",
"$",
"this",
"->",
"detail",
"=",
"'Success'",
";",
"}",
"catch",
"(",
"PayPalConnectionException",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"e",
"->",
"getData",
"(",
")",
")",
";",
"throw",
"new",
"GatewayException",
"(",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"response",
"->",
"name",
",",
"isset",
"(",
"$",
"response",
"->",
"message",
")",
"?",
"$",
"response",
"->",
"message",
":",
"'Paypal payment Failed.'",
")",
",",
"1001",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"GatewayException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"1000",
",",
"$",
"e",
")",
";",
"}",
"}"
] |
Called on callback.
@param Order $order Order.
@param mixed $data Request input from callback.
@return bool
|
[
"Called",
"on",
"callback",
"."
] |
c0ba041bda3fdcc696e4a01278647f386e9d8715
|
https://github.com/amsgames/laravel-shop-gateway-paypal/blob/c0ba041bda3fdcc696e4a01278647f386e9d8715/src/GatewayPayPalExpress.php#L170-L224
|
224,061
|
amsgames/laravel-shop-gateway-paypal
|
src/GatewayPayPalExpress.php
|
GatewayPayPalExpress.setContext
|
private function setContext()
{
$this->apiContext = new ApiContext(new OAuthTokenCredential(
Config::get('services.paypal.client_id'),
Config::get('services.paypal.secret')
));
if (!Config::get('services.paypal.sandbox'))
$this->apiContext->setConfig(['mode' => 'live']);
}
|
php
|
private function setContext()
{
$this->apiContext = new ApiContext(new OAuthTokenCredential(
Config::get('services.paypal.client_id'),
Config::get('services.paypal.secret')
));
if (!Config::get('services.paypal.sandbox'))
$this->apiContext->setConfig(['mode' => 'live']);
}
|
[
"private",
"function",
"setContext",
"(",
")",
"{",
"$",
"this",
"->",
"apiContext",
"=",
"new",
"ApiContext",
"(",
"new",
"OAuthTokenCredential",
"(",
"Config",
"::",
"get",
"(",
"'services.paypal.client_id'",
")",
",",
"Config",
"::",
"get",
"(",
"'services.paypal.secret'",
")",
")",
")",
";",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'services.paypal.sandbox'",
")",
")",
"$",
"this",
"->",
"apiContext",
"->",
"setConfig",
"(",
"[",
"'mode'",
"=>",
"'live'",
"]",
")",
";",
"}"
] |
Setups contexts for api calls.
|
[
"Setups",
"contexts",
"for",
"api",
"calls",
"."
] |
c0ba041bda3fdcc696e4a01278647f386e9d8715
|
https://github.com/amsgames/laravel-shop-gateway-paypal/blob/c0ba041bda3fdcc696e4a01278647f386e9d8715/src/GatewayPayPalExpress.php#L229-L238
|
224,062
|
mrclay/shibalike
|
src/Shibalike/Junction.php
|
Junction.getValidAuthResult
|
public function getValidAuthResult()
{
$authResult = $this->_stateMgr->get('authResult');
/* @var AuthResult $authResult */
if ($authResult && $authResult->isFresh($this->_config->timeout)) {
return $authResult;
}
return null;
}
|
php
|
public function getValidAuthResult()
{
$authResult = $this->_stateMgr->get('authResult');
/* @var AuthResult $authResult */
if ($authResult && $authResult->isFresh($this->_config->timeout)) {
return $authResult;
}
return null;
}
|
[
"public",
"function",
"getValidAuthResult",
"(",
")",
"{",
"$",
"authResult",
"=",
"$",
"this",
"->",
"_stateMgr",
"->",
"get",
"(",
"'authResult'",
")",
";",
"/* @var AuthResult $authResult */",
"if",
"(",
"$",
"authResult",
"&&",
"$",
"authResult",
"->",
"isFresh",
"(",
"$",
"this",
"->",
"_config",
"->",
"timeout",
")",
")",
"{",
"return",
"$",
"authResult",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the User object from the state manager
@return AuthResult|null
|
[
"Get",
"the",
"User",
"object",
"from",
"the",
"state",
"manager"
] |
04242301ed18f5a1b02493bcc193f5efd255112e
|
https://github.com/mrclay/shibalike/blob/04242301ed18f5a1b02493bcc193f5efd255112e/src/Shibalike/Junction.php#L37-L45
|
224,063
|
Gregwar/GnuPlot
|
GnuPlot.php
|
GnuPlot.reset
|
public function reset()
{
$this->values = array();
$this->xlabel = null;
$this->ylabel = null;
$this->labels = array();
$this->titles = array();
$this->xrange = null;
$this->yrange = null;
$this->title = null;
}
|
php
|
public function reset()
{
$this->values = array();
$this->xlabel = null;
$this->ylabel = null;
$this->labels = array();
$this->titles = array();
$this->xrange = null;
$this->yrange = null;
$this->title = null;
}
|
[
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"values",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"xlabel",
"=",
"null",
";",
"$",
"this",
"->",
"ylabel",
"=",
"null",
";",
"$",
"this",
"->",
"labels",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"titles",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"xrange",
"=",
"null",
";",
"$",
"this",
"->",
"yrange",
"=",
"null",
";",
"$",
"this",
"->",
"title",
"=",
"null",
";",
"}"
] |
Reset all the values
|
[
"Reset",
"all",
"the",
"values"
] |
6277ca7dc0457ea118958fa149f091f14e23c1cb
|
https://github.com/Gregwar/GnuPlot/blob/6277ca7dc0457ea118958fa149f091f14e23c1cb/GnuPlot.php#L81-L91
|
224,064
|
Gregwar/GnuPlot
|
GnuPlot.php
|
GnuPlot.sendInit
|
protected function sendInit()
{
$this->sendCommand('set grid');
if ($this->title) {
$this->sendCommand('set title "'.$this->title.'"');
}
if ($this->xlabel) {
$this->sendCommand('set xlabel "'.$this->xlabel.'"');
}
if ($this->timeFormat) {
$this->sendCommand('set xdata time');
$this->sendCommand('set timefmt "'.$this->timeFormat.'"');
$this->sendCommand('set xtics rotate by 45 offset -6,-3');
if ($this->timeFormatString) {
$this->sendCommand('set format x "'.$this->timeFormatString.'"');
}
}
if ($this->ylabel) {
$this->sendCommand('set ylabel "'.$this->ylabel.'"');
}
if ($this->yformat) {
$this->sendCommand('set format y "'.$this->yformat.'"');
}
if ($this->xrange) {
$this->sendCommand('set xrange ['.$this->xrange[0].':'.$this->xrange[1].']');
}
if ($this->yrange) {
$this->sendCommand('set yrange ['.$this->yrange[0].':'.$this->yrange[1].']');
}
foreach ($this->labels as $label) {
$this->sendCommand('set label "'.$label[2].'" at '.$label[0].', '.$label[1]);
}
}
|
php
|
protected function sendInit()
{
$this->sendCommand('set grid');
if ($this->title) {
$this->sendCommand('set title "'.$this->title.'"');
}
if ($this->xlabel) {
$this->sendCommand('set xlabel "'.$this->xlabel.'"');
}
if ($this->timeFormat) {
$this->sendCommand('set xdata time');
$this->sendCommand('set timefmt "'.$this->timeFormat.'"');
$this->sendCommand('set xtics rotate by 45 offset -6,-3');
if ($this->timeFormatString) {
$this->sendCommand('set format x "'.$this->timeFormatString.'"');
}
}
if ($this->ylabel) {
$this->sendCommand('set ylabel "'.$this->ylabel.'"');
}
if ($this->yformat) {
$this->sendCommand('set format y "'.$this->yformat.'"');
}
if ($this->xrange) {
$this->sendCommand('set xrange ['.$this->xrange[0].':'.$this->xrange[1].']');
}
if ($this->yrange) {
$this->sendCommand('set yrange ['.$this->yrange[0].':'.$this->yrange[1].']');
}
foreach ($this->labels as $label) {
$this->sendCommand('set label "'.$label[2].'" at '.$label[0].', '.$label[1]);
}
}
|
[
"protected",
"function",
"sendInit",
"(",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set grid'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"title",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set title \"'",
".",
"$",
"this",
"->",
"title",
".",
"'\"'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"xlabel",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set xlabel \"'",
".",
"$",
"this",
"->",
"xlabel",
".",
"'\"'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"timeFormat",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set xdata time'",
")",
";",
"$",
"this",
"->",
"sendCommand",
"(",
"'set timefmt \"'",
".",
"$",
"this",
"->",
"timeFormat",
".",
"'\"'",
")",
";",
"$",
"this",
"->",
"sendCommand",
"(",
"'set xtics rotate by 45 offset -6,-3'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"timeFormatString",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set format x \"'",
".",
"$",
"this",
"->",
"timeFormatString",
".",
"'\"'",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"ylabel",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set ylabel \"'",
".",
"$",
"this",
"->",
"ylabel",
".",
"'\"'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"yformat",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set format y \"'",
".",
"$",
"this",
"->",
"yformat",
".",
"'\"'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"xrange",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set xrange ['",
".",
"$",
"this",
"->",
"xrange",
"[",
"0",
"]",
".",
"':'",
".",
"$",
"this",
"->",
"xrange",
"[",
"1",
"]",
".",
"']'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"yrange",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set yrange ['",
".",
"$",
"this",
"->",
"yrange",
"[",
"0",
"]",
".",
"':'",
".",
"$",
"this",
"->",
"yrange",
"[",
"1",
"]",
".",
"']'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"labels",
"as",
"$",
"label",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'set label \"'",
".",
"$",
"label",
"[",
"2",
"]",
".",
"'\" at '",
".",
"$",
"label",
"[",
"0",
"]",
".",
"', '",
".",
"$",
"label",
"[",
"1",
"]",
")",
";",
"}",
"}"
] |
Create the pipe
|
[
"Create",
"the",
"pipe"
] |
6277ca7dc0457ea118958fa149f091f14e23c1cb
|
https://github.com/Gregwar/GnuPlot/blob/6277ca7dc0457ea118958fa149f091f14e23c1cb/GnuPlot.php#L181-L221
|
224,065
|
Gregwar/GnuPlot
|
GnuPlot.php
|
GnuPlot.plot
|
public function plot($replot = false)
{
if ($replot) {
$this->sendCommand('replot');
} else {
$this->sendCommand('plot '.$this->getUsings());
}
$this->plotted = true;
$this->sendData();
}
|
php
|
public function plot($replot = false)
{
if ($replot) {
$this->sendCommand('replot');
} else {
$this->sendCommand('plot '.$this->getUsings());
}
$this->plotted = true;
$this->sendData();
}
|
[
"public",
"function",
"plot",
"(",
"$",
"replot",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"replot",
")",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'replot'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"sendCommand",
"(",
"'plot '",
".",
"$",
"this",
"->",
"getUsings",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"plotted",
"=",
"true",
";",
"$",
"this",
"->",
"sendData",
"(",
")",
";",
"}"
] |
Runs the plot to the given pipe
|
[
"Runs",
"the",
"plot",
"to",
"the",
"given",
"pipe"
] |
6277ca7dc0457ea118958fa149f091f14e23c1cb
|
https://github.com/Gregwar/GnuPlot/blob/6277ca7dc0457ea118958fa149f091f14e23c1cb/GnuPlot.php#L226-L235
|
224,066
|
Gregwar/GnuPlot
|
GnuPlot.php
|
GnuPlot.addLabel
|
public function addLabel($x, $y, $text)
{
$this->labels[] = array($x, $y, $text);
return $this;
}
|
php
|
public function addLabel($x, $y, $text)
{
$this->labels[] = array($x, $y, $text);
return $this;
}
|
[
"public",
"function",
"addLabel",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"text",
")",
"{",
"$",
"this",
"->",
"labels",
"[",
"]",
"=",
"array",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"text",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a label text
|
[
"Add",
"a",
"label",
"text"
] |
6277ca7dc0457ea118958fa149f091f14e23c1cb
|
https://github.com/Gregwar/GnuPlot/blob/6277ca7dc0457ea118958fa149f091f14e23c1cb/GnuPlot.php#L364-L369
|
224,067
|
Gregwar/GnuPlot
|
GnuPlot.php
|
GnuPlot.getUsings
|
protected function getUsings()
{
$usings = array();
for ($i=0; $i<count($this->values); $i++) {
$using = '"-" using 1:2 with '.$this->mode;
if (isset($this->titles[$i])) {
$using .= ' title "'.$this->titles[$i].'"';
}
$usings[] = $using;
}
return implode(', ', $usings);
}
|
php
|
protected function getUsings()
{
$usings = array();
for ($i=0; $i<count($this->values); $i++) {
$using = '"-" using 1:2 with '.$this->mode;
if (isset($this->titles[$i])) {
$using .= ' title "'.$this->titles[$i].'"';
}
$usings[] = $using;
}
return implode(', ', $usings);
}
|
[
"protected",
"function",
"getUsings",
"(",
")",
"{",
"$",
"usings",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"values",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"using",
"=",
"'\"-\" using 1:2 with '",
".",
"$",
"this",
"->",
"mode",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"titles",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"using",
".=",
"' title \"'",
".",
"$",
"this",
"->",
"titles",
"[",
"$",
"i",
"]",
".",
"'\"'",
";",
"}",
"$",
"usings",
"[",
"]",
"=",
"$",
"using",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"usings",
")",
";",
"}"
] |
Gets the "using" line
|
[
"Gets",
"the",
"using",
"line"
] |
6277ca7dc0457ea118958fa149f091f14e23c1cb
|
https://github.com/Gregwar/GnuPlot/blob/6277ca7dc0457ea118958fa149f091f14e23c1cb/GnuPlot.php#L384-L397
|
224,068
|
Gregwar/GnuPlot
|
GnuPlot.php
|
GnuPlot.sendData
|
protected function sendData()
{
foreach ($this->values as $index => $data) {
foreach ($data as $xy) {
list($x, $y) = $xy;
$this->sendCommand($x.' '.$y);
}
$this->sendCommand('e');
}
}
|
php
|
protected function sendData()
{
foreach ($this->values as $index => $data) {
foreach ($data as $xy) {
list($x, $y) = $xy;
$this->sendCommand($x.' '.$y);
}
$this->sendCommand('e');
}
}
|
[
"protected",
"function",
"sendData",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"index",
"=>",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"xy",
")",
"{",
"list",
"(",
"$",
"x",
",",
"$",
"y",
")",
"=",
"$",
"xy",
";",
"$",
"this",
"->",
"sendCommand",
"(",
"$",
"x",
".",
"' '",
".",
"$",
"y",
")",
";",
"}",
"$",
"this",
"->",
"sendCommand",
"(",
"'e'",
")",
";",
"}",
"}"
] |
Sends all the command to the given pipe to give it the
current data
|
[
"Sends",
"all",
"the",
"command",
"to",
"the",
"given",
"pipe",
"to",
"give",
"it",
"the",
"current",
"data"
] |
6277ca7dc0457ea118958fa149f091f14e23c1cb
|
https://github.com/Gregwar/GnuPlot/blob/6277ca7dc0457ea118958fa149f091f14e23c1cb/GnuPlot.php#L403-L412
|
224,069
|
Gregwar/GnuPlot
|
GnuPlot.php
|
GnuPlot.openPipe
|
protected function openPipe()
{
$descriptorspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'r')
);
$this->process = proc_open('gnuplot', $descriptorspec, $pipes);
if (!is_resource($this->process)) {
throw new \Exception('Unable to run GnuPlot');
}
$this->stdin = $pipes[0];
$this->stdout = $pipes[1];
}
|
php
|
protected function openPipe()
{
$descriptorspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'r')
);
$this->process = proc_open('gnuplot', $descriptorspec, $pipes);
if (!is_resource($this->process)) {
throw new \Exception('Unable to run GnuPlot');
}
$this->stdin = $pipes[0];
$this->stdout = $pipes[1];
}
|
[
"protected",
"function",
"openPipe",
"(",
")",
"{",
"$",
"descriptorspec",
"=",
"array",
"(",
"0",
"=>",
"array",
"(",
"'pipe'",
",",
"'r'",
")",
",",
"1",
"=>",
"array",
"(",
"'pipe'",
",",
"'w'",
")",
",",
"2",
"=>",
"array",
"(",
"'pipe'",
",",
"'r'",
")",
")",
";",
"$",
"this",
"->",
"process",
"=",
"proc_open",
"(",
"'gnuplot'",
",",
"$",
"descriptorspec",
",",
"$",
"pipes",
")",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"process",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unable to run GnuPlot'",
")",
";",
"}",
"$",
"this",
"->",
"stdin",
"=",
"$",
"pipes",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"stdout",
"=",
"$",
"pipes",
"[",
"1",
"]",
";",
"}"
] |
Open the pipe
|
[
"Open",
"the",
"pipe"
] |
6277ca7dc0457ea118958fa149f091f14e23c1cb
|
https://github.com/Gregwar/GnuPlot/blob/6277ca7dc0457ea118958fa149f091f14e23c1cb/GnuPlot.php#L426-L442
|
224,070
|
sulu/SuluProductBundle
|
Controller/ProductController.php
|
ProductController.getAction
|
public function getAction(Request $request, $id)
{
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
$view = $this->responseGetById(
$id,
function ($id) use ($locale) {
/** @var Product $product */
$product = $this->getManager()->findByIdAndLocale($id, $locale);
return $product;
}
);
return $this->handleView($view);
}
|
php
|
public function getAction(Request $request, $id)
{
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
$view = $this->responseGetById(
$id,
function ($id) use ($locale) {
/** @var Product $product */
$product = $this->getManager()->findByIdAndLocale($id, $locale);
return $product;
}
);
return $this->handleView($view);
}
|
[
"public",
"function",
"getAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getProductLocaleManager",
"(",
")",
"->",
"retrieveLocale",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
",",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"id",
",",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"/** @var Product $product */",
"$",
"product",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"findByIdAndLocale",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"return",
"$",
"product",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Retrieves and shows a product with the given ID.
@param Request $request
@param int $id product ID
@return Response
|
[
"Retrieves",
"and",
"shows",
"a",
"product",
"with",
"the",
"given",
"ID",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductController.php#L89-L103
|
224,071
|
sulu/SuluProductBundle
|
Controller/ProductController.php
|
ProductController.cgetAction
|
public function cgetAction(Request $request)
{
$filter = $this->getManager()->getFilters($request);
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
if ($request->get('flat') == 'true') {
$filterFieldDescriptors = $this->getManager()->getFilterFieldDescriptors();
$fieldDescriptors = $this->getManager()->getFieldDescriptors(
$locale
);
$list = $this->flatResponse(
$request,
$filter,
$filterFieldDescriptors,
$fieldDescriptors,
static::$entityName
);
} elseif ($request->get('ids') !== '') {
$list = new CollectionRepresentation(
$this->getManager()->findAllByIdsAndLocale($locale, $request->get('ids')),
self::$entityKey
);
} else {
$list = new CollectionRepresentation(
$this->getManager()->findAllByLocale($locale, $filter),
self::$entityKey
);
}
$view = $this->view($list, 200);
return $this->handleView($view);
}
|
php
|
public function cgetAction(Request $request)
{
$filter = $this->getManager()->getFilters($request);
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
if ($request->get('flat') == 'true') {
$filterFieldDescriptors = $this->getManager()->getFilterFieldDescriptors();
$fieldDescriptors = $this->getManager()->getFieldDescriptors(
$locale
);
$list = $this->flatResponse(
$request,
$filter,
$filterFieldDescriptors,
$fieldDescriptors,
static::$entityName
);
} elseif ($request->get('ids') !== '') {
$list = new CollectionRepresentation(
$this->getManager()->findAllByIdsAndLocale($locale, $request->get('ids')),
self::$entityKey
);
} else {
$list = new CollectionRepresentation(
$this->getManager()->findAllByLocale($locale, $filter),
self::$entityKey
);
}
$view = $this->view($list, 200);
return $this->handleView($view);
}
|
[
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getFilters",
"(",
"$",
"request",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getProductLocaleManager",
"(",
")",
"->",
"retrieveLocale",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
",",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
";",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
"==",
"'true'",
")",
"{",
"$",
"filterFieldDescriptors",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getFilterFieldDescriptors",
"(",
")",
";",
"$",
"fieldDescriptors",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getFieldDescriptors",
"(",
"$",
"locale",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"flatResponse",
"(",
"$",
"request",
",",
"$",
"filter",
",",
"$",
"filterFieldDescriptors",
",",
"$",
"fieldDescriptors",
",",
"static",
"::",
"$",
"entityName",
")",
";",
"}",
"elseif",
"(",
"$",
"request",
"->",
"get",
"(",
"'ids'",
")",
"!==",
"''",
")",
"{",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"findAllByIdsAndLocale",
"(",
"$",
"locale",
",",
"$",
"request",
"->",
"get",
"(",
"'ids'",
")",
")",
",",
"self",
"::",
"$",
"entityKey",
")",
";",
"}",
"else",
"{",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"findAllByLocale",
"(",
"$",
"locale",
",",
"$",
"filter",
")",
",",
"self",
"::",
"$",
"entityKey",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Returns a list of products.
@param Request $request
@return Response
|
[
"Returns",
"a",
"list",
"of",
"products",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductController.php#L112-L145
|
224,072
|
sulu/SuluProductBundle
|
Controller/ProductController.php
|
ProductController.flatResponse
|
protected function flatResponse(
Request $request,
$filter,
$filterFieldDescriptors,
$fieldDescriptors,
$entityName
) {
$listBuilder = $this->getListBuilder($entityName, $fieldDescriptors);
foreach ($filter as $key => $value) {
if (is_array($value)) {
$listBuilder->in($filterFieldDescriptors[$key], $value);
} else {
$listBuilder->where($filterFieldDescriptors[$key], $value);
}
}
$ids = null;
if (null !== $request->get('ids')) {
$ids = array_filter(explode(',', $request->get('ids', '')));
$listBuilder->in($fieldDescriptors['id'], $ids);
$listBuilder->limit(count($ids));
}
// Only add group by id if categories are processed.
$fieldsParam = $request->get('fields');
$fields = explode(',', $fieldsParam);
if (isset($filter['categories']) ||
!$fieldsParam ||
array_search('categories', $fields) !== false
) {
$listBuilder->addGroupBy($fieldDescriptors['id']);
}
// Do not show product variants in list.
$listBuilder->where(
$filterFieldDescriptors['type_id'],
$this->getProductTypesMap()['PRODUCT_VARIANT'],
DoctrineListBuilder::WHERE_COMPARATOR_UNEQUAL
);
if (json_decode($request->get('disablePagination'))) {
return [
'_embedded' => [
'products' => $listBuilder->execute(),
],
];
}
$list = new ListRepresentation(
$listBuilder->execute(),
self::$entityKey,
'get_products',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
return $list;
}
|
php
|
protected function flatResponse(
Request $request,
$filter,
$filterFieldDescriptors,
$fieldDescriptors,
$entityName
) {
$listBuilder = $this->getListBuilder($entityName, $fieldDescriptors);
foreach ($filter as $key => $value) {
if (is_array($value)) {
$listBuilder->in($filterFieldDescriptors[$key], $value);
} else {
$listBuilder->where($filterFieldDescriptors[$key], $value);
}
}
$ids = null;
if (null !== $request->get('ids')) {
$ids = array_filter(explode(',', $request->get('ids', '')));
$listBuilder->in($fieldDescriptors['id'], $ids);
$listBuilder->limit(count($ids));
}
// Only add group by id if categories are processed.
$fieldsParam = $request->get('fields');
$fields = explode(',', $fieldsParam);
if (isset($filter['categories']) ||
!$fieldsParam ||
array_search('categories', $fields) !== false
) {
$listBuilder->addGroupBy($fieldDescriptors['id']);
}
// Do not show product variants in list.
$listBuilder->where(
$filterFieldDescriptors['type_id'],
$this->getProductTypesMap()['PRODUCT_VARIANT'],
DoctrineListBuilder::WHERE_COMPARATOR_UNEQUAL
);
if (json_decode($request->get('disablePagination'))) {
return [
'_embedded' => [
'products' => $listBuilder->execute(),
],
];
}
$list = new ListRepresentation(
$listBuilder->execute(),
self::$entityKey,
'get_products',
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
return $list;
}
|
[
"protected",
"function",
"flatResponse",
"(",
"Request",
"$",
"request",
",",
"$",
"filter",
",",
"$",
"filterFieldDescriptors",
",",
"$",
"fieldDescriptors",
",",
"$",
"entityName",
")",
"{",
"$",
"listBuilder",
"=",
"$",
"this",
"->",
"getListBuilder",
"(",
"$",
"entityName",
",",
"$",
"fieldDescriptors",
")",
";",
"foreach",
"(",
"$",
"filter",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"listBuilder",
"->",
"in",
"(",
"$",
"filterFieldDescriptors",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"filterFieldDescriptors",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"ids",
"=",
"null",
";",
"if",
"(",
"null",
"!==",
"$",
"request",
"->",
"get",
"(",
"'ids'",
")",
")",
"{",
"$",
"ids",
"=",
"array_filter",
"(",
"explode",
"(",
"','",
",",
"$",
"request",
"->",
"get",
"(",
"'ids'",
",",
"''",
")",
")",
")",
";",
"$",
"listBuilder",
"->",
"in",
"(",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
",",
"$",
"ids",
")",
";",
"$",
"listBuilder",
"->",
"limit",
"(",
"count",
"(",
"$",
"ids",
")",
")",
";",
"}",
"// Only add group by id if categories are processed.",
"$",
"fieldsParam",
"=",
"$",
"request",
"->",
"get",
"(",
"'fields'",
")",
";",
"$",
"fields",
"=",
"explode",
"(",
"','",
",",
"$",
"fieldsParam",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"filter",
"[",
"'categories'",
"]",
")",
"||",
"!",
"$",
"fieldsParam",
"||",
"array_search",
"(",
"'categories'",
",",
"$",
"fields",
")",
"!==",
"false",
")",
"{",
"$",
"listBuilder",
"->",
"addGroupBy",
"(",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
")",
";",
"}",
"// Do not show product variants in list.",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"filterFieldDescriptors",
"[",
"'type_id'",
"]",
",",
"$",
"this",
"->",
"getProductTypesMap",
"(",
")",
"[",
"'PRODUCT_VARIANT'",
"]",
",",
"DoctrineListBuilder",
"::",
"WHERE_COMPARATOR_UNEQUAL",
")",
";",
"if",
"(",
"json_decode",
"(",
"$",
"request",
"->",
"get",
"(",
"'disablePagination'",
")",
")",
")",
"{",
"return",
"[",
"'_embedded'",
"=>",
"[",
"'products'",
"=>",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
",",
"]",
",",
"]",
";",
"}",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
",",
"self",
"::",
"$",
"entityKey",
",",
"'get_products'",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"return",
"$",
"list",
";",
"}"
] |
Processes the request for a flat response.
@param Request $request
@param array $filter
@param array $filterFieldDescriptors
@param array $fieldDescriptors
@param string $entityName
@return ListRepresentation
|
[
"Processes",
"the",
"request",
"for",
"a",
"flat",
"response",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductController.php#L182-L242
|
224,073
|
sulu/SuluProductBundle
|
Controller/ProductController.php
|
ProductController.putAction
|
public function putAction(Request $request, $id)
{
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
try {
$product = $this->getManager()->save(
$request->request->all(),
$locale,
$this->getUser()->getId(),
$id
);
$view = $this->view($product, 200);
} catch (ProductNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 404);
} catch (ProductDependencyNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 400);
} catch (MissingProductAttributeException $exc) {
$exception = new MissingArgumentException(static::$entityName, $exc->getAttribute());
$view = $this->view($exception->toArray(), 400);
} catch (EntityIdAlreadySetException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (ProductException $exc) {
$exception = new RestException($exc->getMessage(), $exc->getCode());
$view = $this->view($exception->toArray(), 400);
}
return $this->handleView($view);
}
|
php
|
public function putAction(Request $request, $id)
{
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
try {
$product = $this->getManager()->save(
$request->request->all(),
$locale,
$this->getUser()->getId(),
$id
);
$view = $this->view($product, 200);
} catch (ProductNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 404);
} catch (ProductDependencyNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 400);
} catch (MissingProductAttributeException $exc) {
$exception = new MissingArgumentException(static::$entityName, $exc->getAttribute());
$view = $this->view($exception->toArray(), 400);
} catch (EntityIdAlreadySetException $exc) {
$view = $this->view($exc->toArray(), 400);
} catch (ProductException $exc) {
$exception = new RestException($exc->getMessage(), $exc->getCode());
$view = $this->view($exception->toArray(), 400);
}
return $this->handleView($view);
}
|
[
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getProductLocaleManager",
"(",
")",
"->",
"retrieveLocale",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
",",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
";",
"try",
"{",
"$",
"product",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"save",
"(",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
",",
"$",
"locale",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"id",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"product",
",",
"200",
")",
";",
"}",
"catch",
"(",
"ProductNotFoundException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"EntityNotFoundException",
"(",
"$",
"exc",
"->",
"getEntityName",
"(",
")",
",",
"$",
"exc",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"catch",
"(",
"ProductDependencyNotFoundException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"EntityNotFoundException",
"(",
"$",
"exc",
"->",
"getEntityName",
"(",
")",
",",
"$",
"exc",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"MissingProductAttributeException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"MissingArgumentException",
"(",
"static",
"::",
"$",
"entityName",
",",
"$",
"exc",
"->",
"getAttribute",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"EntityIdAlreadySetException",
"$",
"exc",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exc",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"ProductException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"RestException",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
",",
"$",
"exc",
"->",
"getCode",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Change a product entry by the given product id.
@param Request $request
@param int $id product ID
@return Response
|
[
"Change",
"a",
"product",
"entry",
"by",
"the",
"given",
"product",
"id",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductController.php#L252-L282
|
224,074
|
sulu/SuluProductBundle
|
Controller/ProductController.php
|
ProductController.deleteAction
|
public function deleteAction(Request $request, $id)
{
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
$delete = function ($id) use ($locale) {
try {
$this->getManager()->delete($id, $this->getUser()->getId());
} catch (ProductChildrenExistException $exc) {
throw new RestException('Deletion not allowed, because the product has sub products', 400);
}
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
}
|
php
|
public function deleteAction(Request $request, $id)
{
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
$delete = function ($id) use ($locale) {
try {
$this->getManager()->delete($id, $this->getUser()->getId());
} catch (ProductChildrenExistException $exc) {
throw new RestException('Deletion not allowed, because the product has sub products', 400);
}
};
$view = $this->responseDelete($id, $delete);
return $this->handleView($view);
}
|
[
"public",
"function",
"deleteAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getProductLocaleManager",
"(",
")",
"->",
"retrieveLocale",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
",",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
";",
"$",
"delete",
"=",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"delete",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ProductChildrenExistException",
"$",
"exc",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Deletion not allowed, because the product has sub products'",
",",
"400",
")",
";",
"}",
"}",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseDelete",
"(",
"$",
"id",
",",
"$",
"delete",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Delete a product with the given id.
@param Request $request
@param int $id product id
@return Response
|
[
"Delete",
"a",
"product",
"with",
"the",
"given",
"id",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductController.php#L325-L339
|
224,075
|
sulu/SuluProductBundle
|
Controller/ProductController.php
|
ProductController.patchAction
|
public function patchAction(Request $request, $id)
{
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
try {
$product = $this->getManager()->partialUpdate(
$request->request->all(),
$locale,
$this->getUser()->getId(),
$id
);
$this->getEntityManager()->flush();
$view = $this->view($product, 200);
} catch (ProductNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 404);
}
return $this->handleView($view);
}
|
php
|
public function patchAction(Request $request, $id)
{
$locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
try {
$product = $this->getManager()->partialUpdate(
$request->request->all(),
$locale,
$this->getUser()->getId(),
$id
);
$this->getEntityManager()->flush();
$view = $this->view($product, 200);
} catch (ProductNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 404);
}
return $this->handleView($view);
}
|
[
"public",
"function",
"patchAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getProductLocaleManager",
"(",
")",
"->",
"retrieveLocale",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
",",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
")",
";",
"try",
"{",
"$",
"product",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"partialUpdate",
"(",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
",",
"$",
"locale",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"id",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"product",
",",
"200",
")",
";",
"}",
"catch",
"(",
"ProductNotFoundException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"EntityNotFoundException",
"(",
"$",
"exc",
"->",
"getEntityName",
"(",
")",
",",
"$",
"exc",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Make a partial update of a product.
@param Request $request
@param int $id
@return Response
|
[
"Make",
"a",
"partial",
"update",
"of",
"a",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductController.php#L357-L378
|
224,076
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getSupplier
|
public function getSupplier()
{
$values = null;
$supplier = $this->entity->getSupplier();
if ($supplier !== null) {
// Returns no api entity because it will cause a nesting level exception
$values = [
'id' => $supplier->getId(),
'name' => $supplier->getName(),
];
}
return $values;
}
|
php
|
public function getSupplier()
{
$values = null;
$supplier = $this->entity->getSupplier();
if ($supplier !== null) {
// Returns no api entity because it will cause a nesting level exception
$values = [
'id' => $supplier->getId(),
'name' => $supplier->getName(),
];
}
return $values;
}
|
[
"public",
"function",
"getSupplier",
"(",
")",
"{",
"$",
"values",
"=",
"null",
";",
"$",
"supplier",
"=",
"$",
"this",
"->",
"entity",
"->",
"getSupplier",
"(",
")",
";",
"if",
"(",
"$",
"supplier",
"!==",
"null",
")",
"{",
"// Returns no api entity because it will cause a nesting level exception",
"$",
"values",
"=",
"[",
"'id'",
"=>",
"$",
"supplier",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"supplier",
"->",
"getName",
"(",
")",
",",
"]",
";",
"}",
"return",
"$",
"values",
";",
"}"
] |
Returns the supplier of the product.
@VirtualProperty
@SerializedName("supplier")
@return object The supplier of the product
|
[
"Returns",
"the",
"supplier",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L402-L415
|
224,077
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getParent
|
public function getParent()
{
$parent = $this->entity->getParent();
if (!$parent) {
return null;
}
return $this->productFactory->createApiEntity($parent, $this->locale);
}
|
php
|
public function getParent()
{
$parent = $this->entity->getParent();
if (!$parent) {
return null;
}
return $this->productFactory->createApiEntity($parent, $this->locale);
}
|
[
"public",
"function",
"getParent",
"(",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"entity",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"parent",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"productFactory",
"->",
"createApiEntity",
"(",
"$",
"parent",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}"
] |
Returns the parent of the product.
@VirtualProperty
@SerializedName("parent")
@return ProductInterface The parent of the product
|
[
"Returns",
"the",
"parent",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L495-L504
|
224,078
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.setParent
|
public function setParent(Product $parent = null)
{
if ($parent != null) {
$this->entity->setParent($parent->getEntity());
} else {
$this->entity->setParent(null);
}
}
|
php
|
public function setParent(Product $parent = null)
{
if ($parent != null) {
$this->entity->setParent($parent->getEntity());
} else {
$this->entity->setParent(null);
}
}
|
[
"public",
"function",
"setParent",
"(",
"Product",
"$",
"parent",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"parent",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"entity",
"->",
"setParent",
"(",
"$",
"parent",
"->",
"getEntity",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"entity",
"->",
"setParent",
"(",
"null",
")",
";",
"}",
"}"
] |
Sets the parent of the product.
@param Product $parent The parent of the product
|
[
"Sets",
"the",
"parent",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L511-L518
|
224,079
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getType
|
public function getType()
{
if ($this->entity->getType()) {
return new Type($this->entity->getType(), $this->locale);
}
return null;
}
|
php
|
public function getType()
{
if ($this->entity->getType()) {
return new Type($this->entity->getType(), $this->locale);
}
return null;
}
|
[
"public",
"function",
"getType",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"entity",
"->",
"getType",
"(",
")",
")",
"{",
"return",
"new",
"Type",
"(",
"$",
"this",
"->",
"entity",
"->",
"getType",
"(",
")",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the type of the product.
@VirtualProperty
@SerializedName("type")
@return Type|null The type of the product
|
[
"Returns",
"the",
"type",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L548-L555
|
224,080
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getDeliveryStatus
|
public function getDeliveryStatus()
{
$status = $this->entity->getDeliveryStatus();
if ($status !== null) {
return new DeliveryStatus($status, $this->locale);
}
return null;
}
|
php
|
public function getDeliveryStatus()
{
$status = $this->entity->getDeliveryStatus();
if ($status !== null) {
return new DeliveryStatus($status, $this->locale);
}
return null;
}
|
[
"public",
"function",
"getDeliveryStatus",
"(",
")",
"{",
"$",
"status",
"=",
"$",
"this",
"->",
"entity",
"->",
"getDeliveryStatus",
"(",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"null",
")",
"{",
"return",
"new",
"DeliveryStatus",
"(",
"$",
"status",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the delivery status of the product.
@VirtualProperty
@SerializedName("deliveryStatus")
@return DeliveryStatus The delivery status of the product
|
[
"Returns",
"the",
"delivery",
"status",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L598-L606
|
224,081
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getOrderUnit
|
public function getOrderUnit()
{
$unit = $this->entity->getOrderUnit();
if (!is_null($unit)) {
return new Unit($unit, $this->locale);
}
return null;
}
|
php
|
public function getOrderUnit()
{
$unit = $this->entity->getOrderUnit();
if (!is_null($unit)) {
return new Unit($unit, $this->locale);
}
return null;
}
|
[
"public",
"function",
"getOrderUnit",
"(",
")",
"{",
"$",
"unit",
"=",
"$",
"this",
"->",
"entity",
"->",
"getOrderUnit",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"unit",
")",
")",
"{",
"return",
"new",
"Unit",
"(",
"$",
"unit",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the orderUnit of the product.
@VirtualProperty
@SerializedName("orderUnit")
@Groups({"cart"})
@return Unit
|
[
"Returns",
"the",
"orderUnit",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L627-L635
|
224,082
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getContentUnit
|
public function getContentUnit()
{
$unit = $this->entity->getContentUnit();
if (!is_null($unit)) {
return new Unit($unit, $this->locale);
}
return null;
}
|
php
|
public function getContentUnit()
{
$unit = $this->entity->getContentUnit();
if (!is_null($unit)) {
return new Unit($unit, $this->locale);
}
return null;
}
|
[
"public",
"function",
"getContentUnit",
"(",
")",
"{",
"$",
"unit",
"=",
"$",
"this",
"->",
"entity",
"->",
"getContentUnit",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"unit",
")",
")",
"{",
"return",
"new",
"Unit",
"(",
"$",
"unit",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the contentUnit of the product.
@VirtualProperty
@SerializedName("contentUnit")
@Groups({"cart"})
@return Unit
|
[
"Returns",
"the",
"contentUnit",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L656-L664
|
224,083
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getTaxClass
|
public function getTaxClass()
{
$taxClass = $this->entity->getTaxClass();
if ($taxClass) {
return new TaxClass($this->entity->getTaxClass(), $this->locale);
}
return null;
}
|
php
|
public function getTaxClass()
{
$taxClass = $this->entity->getTaxClass();
if ($taxClass) {
return new TaxClass($this->entity->getTaxClass(), $this->locale);
}
return null;
}
|
[
"public",
"function",
"getTaxClass",
"(",
")",
"{",
"$",
"taxClass",
"=",
"$",
"this",
"->",
"entity",
"->",
"getTaxClass",
"(",
")",
";",
"if",
"(",
"$",
"taxClass",
")",
"{",
"return",
"new",
"TaxClass",
"(",
"$",
"this",
"->",
"entity",
"->",
"getTaxClass",
"(",
")",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the tax class of the product.
@VirtualProperty
@SerializedName("taxClass")
@return TaxClass The status of the product
|
[
"Returns",
"the",
"tax",
"class",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L684-L692
|
224,084
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getAttributeSet
|
public function getAttributeSet()
{
$attributeSet = $this->entity->getAttributeSet();
if ($attributeSet) {
return new AttributeSet($attributeSet, $this->locale);
}
return null;
}
|
php
|
public function getAttributeSet()
{
$attributeSet = $this->entity->getAttributeSet();
if ($attributeSet) {
return new AttributeSet($attributeSet, $this->locale);
}
return null;
}
|
[
"public",
"function",
"getAttributeSet",
"(",
")",
"{",
"$",
"attributeSet",
"=",
"$",
"this",
"->",
"entity",
"->",
"getAttributeSet",
"(",
")",
";",
"if",
"(",
"$",
"attributeSet",
")",
"{",
"return",
"new",
"AttributeSet",
"(",
"$",
"attributeSet",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the attribute set of the product.
@VirtualProperty
@SerializedName("attributeSet")
@return AttributeSet The attribute set of the product
|
[
"Returns",
"the",
"attribute",
"set",
"of",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L712-L720
|
224,085
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getPrices
|
public function getPrices()
{
$priceEntities = $this->entity->getPrices();
$prices = [];
foreach ($priceEntities as $priceEntity) {
$prices[] = new ProductPrice($priceEntity, $this->locale);
}
return $prices;
}
|
php
|
public function getPrices()
{
$priceEntities = $this->entity->getPrices();
$prices = [];
foreach ($priceEntities as $priceEntity) {
$prices[] = new ProductPrice($priceEntity, $this->locale);
}
return $prices;
}
|
[
"public",
"function",
"getPrices",
"(",
")",
"{",
"$",
"priceEntities",
"=",
"$",
"this",
"->",
"entity",
"->",
"getPrices",
"(",
")",
";",
"$",
"prices",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"priceEntities",
"as",
"$",
"priceEntity",
")",
"{",
"$",
"prices",
"[",
"]",
"=",
"new",
"ProductPrice",
"(",
"$",
"priceEntity",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"$",
"prices",
";",
"}"
] |
Returns the prices for the product.
@VirtualProperty
@SerializedName("prices")
@return ProductPrice[]
|
[
"Returns",
"the",
"prices",
"for",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L750-L760
|
224,086
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getScalePriceForCurrency
|
public function getScalePriceForCurrency($currency = 'EUR')
{
$scalePrice = null;
$prices = $this->entity->getPrices();
if ($prices) {
foreach ($prices as $price) {
if ($price->getCurrency()->getCode() == $currency) {
$scalePrice[] = $price;
}
}
}
return $scalePrice;
}
|
php
|
public function getScalePriceForCurrency($currency = 'EUR')
{
$scalePrice = null;
$prices = $this->entity->getPrices();
if ($prices) {
foreach ($prices as $price) {
if ($price->getCurrency()->getCode() == $currency) {
$scalePrice[] = $price;
}
}
}
return $scalePrice;
}
|
[
"public",
"function",
"getScalePriceForCurrency",
"(",
"$",
"currency",
"=",
"'EUR'",
")",
"{",
"$",
"scalePrice",
"=",
"null",
";",
"$",
"prices",
"=",
"$",
"this",
"->",
"entity",
"->",
"getPrices",
"(",
")",
";",
"if",
"(",
"$",
"prices",
")",
"{",
"foreach",
"(",
"$",
"prices",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getCode",
"(",
")",
"==",
"$",
"currency",
")",
"{",
"$",
"scalePrice",
"[",
"]",
"=",
"$",
"price",
";",
"}",
"}",
"}",
"return",
"$",
"scalePrice",
";",
"}"
] |
Returns the scale price for a certain currency.
@param string $currency
@return ProductPrice[]
|
[
"Returns",
"the",
"scale",
"price",
"for",
"a",
"certain",
"currency",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L769-L782
|
224,087
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getFormattedSpecialPriceForCurrency
|
public function getFormattedSpecialPriceForCurrency($currency = 'EUR', $formatterLocale = null)
{
$price = $this->getSpecialPriceForCurrency($currency);
if ($price) {
return $this->getFormattedPrice($price->getPrice(), $currency, $formatterLocale);
}
return '';
}
|
php
|
public function getFormattedSpecialPriceForCurrency($currency = 'EUR', $formatterLocale = null)
{
$price = $this->getSpecialPriceForCurrency($currency);
if ($price) {
return $this->getFormattedPrice($price->getPrice(), $currency, $formatterLocale);
}
return '';
}
|
[
"public",
"function",
"getFormattedSpecialPriceForCurrency",
"(",
"$",
"currency",
"=",
"'EUR'",
",",
"$",
"formatterLocale",
"=",
"null",
")",
"{",
"$",
"price",
"=",
"$",
"this",
"->",
"getSpecialPriceForCurrency",
"(",
"$",
"currency",
")",
";",
"if",
"(",
"$",
"price",
")",
"{",
"return",
"$",
"this",
"->",
"getFormattedPrice",
"(",
"$",
"price",
"->",
"getPrice",
"(",
")",
",",
"$",
"currency",
",",
"$",
"formatterLocale",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Returns the formatted special price for the product by a given currency and locale.
@param string $currency
@param null|string $formatterLocale
@return string
|
[
"Returns",
"the",
"formatted",
"special",
"price",
"for",
"the",
"product",
"by",
"a",
"given",
"currency",
"and",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L792-L800
|
224,088
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getSpecialPriceForCurrency
|
public function getSpecialPriceForCurrency($currency = 'EUR')
{
$specialPrices = $this->entity->getSpecialPrices();
if ($specialPrices) {
foreach ($specialPrices as $specialPriceEntity) {
if ($specialPriceEntity->getCurrency()->getCode() == $currency) {
$startDate = $specialPriceEntity->getStartDate();
$endDate = $specialPriceEntity->getEndDate();
$now = new \DateTime();
if (($now >= $startDate && $now <= $endDate) ||
($now >= $startDate && empty($endDate)) ||
(empty($startDate) && empty($endDate))
) {
return $specialPriceEntity;
}
}
}
}
return null;
}
|
php
|
public function getSpecialPriceForCurrency($currency = 'EUR')
{
$specialPrices = $this->entity->getSpecialPrices();
if ($specialPrices) {
foreach ($specialPrices as $specialPriceEntity) {
if ($specialPriceEntity->getCurrency()->getCode() == $currency) {
$startDate = $specialPriceEntity->getStartDate();
$endDate = $specialPriceEntity->getEndDate();
$now = new \DateTime();
if (($now >= $startDate && $now <= $endDate) ||
($now >= $startDate && empty($endDate)) ||
(empty($startDate) && empty($endDate))
) {
return $specialPriceEntity;
}
}
}
}
return null;
}
|
[
"public",
"function",
"getSpecialPriceForCurrency",
"(",
"$",
"currency",
"=",
"'EUR'",
")",
"{",
"$",
"specialPrices",
"=",
"$",
"this",
"->",
"entity",
"->",
"getSpecialPrices",
"(",
")",
";",
"if",
"(",
"$",
"specialPrices",
")",
"{",
"foreach",
"(",
"$",
"specialPrices",
"as",
"$",
"specialPriceEntity",
")",
"{",
"if",
"(",
"$",
"specialPriceEntity",
"->",
"getCurrency",
"(",
")",
"->",
"getCode",
"(",
")",
"==",
"$",
"currency",
")",
"{",
"$",
"startDate",
"=",
"$",
"specialPriceEntity",
"->",
"getStartDate",
"(",
")",
";",
"$",
"endDate",
"=",
"$",
"specialPriceEntity",
"->",
"getEndDate",
"(",
")",
";",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"if",
"(",
"(",
"$",
"now",
">=",
"$",
"startDate",
"&&",
"$",
"now",
"<=",
"$",
"endDate",
")",
"||",
"(",
"$",
"now",
">=",
"$",
"startDate",
"&&",
"empty",
"(",
"$",
"endDate",
")",
")",
"||",
"(",
"empty",
"(",
"$",
"startDate",
")",
"&&",
"empty",
"(",
"$",
"endDate",
")",
")",
")",
"{",
"return",
"$",
"specialPriceEntity",
";",
"}",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the special price for a certain currency.
@param string $currency
@return ProductPrice[]
|
[
"Returns",
"the",
"special",
"price",
"for",
"a",
"certain",
"currency",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L809-L829
|
224,089
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getFormattedBasePriceForCurrency
|
public function getFormattedBasePriceForCurrency($currency = 'EUR')
{
$price = $this->getBasePriceForCurrency($currency);
if ($price) {
return $this->getFormattedPrice($price->getPrice(), $currency, $this->locale);
}
return '';
}
|
php
|
public function getFormattedBasePriceForCurrency($currency = 'EUR')
{
$price = $this->getBasePriceForCurrency($currency);
if ($price) {
return $this->getFormattedPrice($price->getPrice(), $currency, $this->locale);
}
return '';
}
|
[
"public",
"function",
"getFormattedBasePriceForCurrency",
"(",
"$",
"currency",
"=",
"'EUR'",
")",
"{",
"$",
"price",
"=",
"$",
"this",
"->",
"getBasePriceForCurrency",
"(",
"$",
"currency",
")",
";",
"if",
"(",
"$",
"price",
")",
"{",
"return",
"$",
"this",
"->",
"getFormattedPrice",
"(",
"$",
"price",
"->",
"getPrice",
"(",
")",
",",
"$",
"currency",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Returns the formatted base price for the product by a given currency and locale.
@param string $currency
@return string
|
[
"Returns",
"the",
"formatted",
"base",
"price",
"for",
"the",
"product",
"by",
"a",
"given",
"currency",
"and",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L866-L874
|
224,090
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getBasePriceForCurrency
|
public function getBasePriceForCurrency($currency = 'EUR')
{
$prices = $this->entity->getPrices();
if ($prices) {
foreach ($prices as $price) {
if ($price->getCurrency()->getCode() == $currency && $price->getMinimumQuantity() == 0) {
return new ProductPrice($price, $this->locale);
}
}
}
return null;
}
|
php
|
public function getBasePriceForCurrency($currency = 'EUR')
{
$prices = $this->entity->getPrices();
if ($prices) {
foreach ($prices as $price) {
if ($price->getCurrency()->getCode() == $currency && $price->getMinimumQuantity() == 0) {
return new ProductPrice($price, $this->locale);
}
}
}
return null;
}
|
[
"public",
"function",
"getBasePriceForCurrency",
"(",
"$",
"currency",
"=",
"'EUR'",
")",
"{",
"$",
"prices",
"=",
"$",
"this",
"->",
"entity",
"->",
"getPrices",
"(",
")",
";",
"if",
"(",
"$",
"prices",
")",
"{",
"foreach",
"(",
"$",
"prices",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getCode",
"(",
")",
"==",
"$",
"currency",
"&&",
"$",
"price",
"->",
"getMinimumQuantity",
"(",
")",
"==",
"0",
")",
"{",
"return",
"new",
"ProductPrice",
"(",
"$",
"price",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the base price for the product by a given currency.
@param string $currency
@return ProductPrice
|
[
"Returns",
"the",
"base",
"price",
"for",
"the",
"product",
"by",
"a",
"given",
"currency",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L883-L895
|
224,091
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getAttributes
|
public function getAttributes()
{
$attributeEntities = $this->entity->getProductAttributes();
$attributes = [];
foreach ($attributeEntities as $attributesEntity) {
$attributes[] = new ProductAttribute(
$attributesEntity,
$this->locale,
$this->productLocaleManager->getFallbackLocale()
);
}
return $attributes;
}
|
php
|
public function getAttributes()
{
$attributeEntities = $this->entity->getProductAttributes();
$attributes = [];
foreach ($attributeEntities as $attributesEntity) {
$attributes[] = new ProductAttribute(
$attributesEntity,
$this->locale,
$this->productLocaleManager->getFallbackLocale()
);
}
return $attributes;
}
|
[
"public",
"function",
"getAttributes",
"(",
")",
"{",
"$",
"attributeEntities",
"=",
"$",
"this",
"->",
"entity",
"->",
"getProductAttributes",
"(",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attributeEntities",
"as",
"$",
"attributesEntity",
")",
"{",
"$",
"attributes",
"[",
"]",
"=",
"new",
"ProductAttribute",
"(",
"$",
"attributesEntity",
",",
"$",
"this",
"->",
"locale",
",",
"$",
"this",
"->",
"productLocaleManager",
"->",
"getFallbackLocale",
"(",
")",
")",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] |
Returns the attributes for the product.
@VirtualProperty
@SerializedName("attributes")
@return ProductAttributes[]
|
[
"Returns",
"the",
"attributes",
"for",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L926-L940
|
224,092
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getCategories
|
public function getCategories()
{
$categoryEntities = $this->entity->getCategories();
$categories = [];
if ($categoryEntities) {
foreach ($categoryEntities as $categoryEntity) {
$categories[] = new Category($categoryEntity, $this->locale);
}
}
return $categories;
}
|
php
|
public function getCategories()
{
$categoryEntities = $this->entity->getCategories();
$categories = [];
if ($categoryEntities) {
foreach ($categoryEntities as $categoryEntity) {
$categories[] = new Category($categoryEntity, $this->locale);
}
}
return $categories;
}
|
[
"public",
"function",
"getCategories",
"(",
")",
"{",
"$",
"categoryEntities",
"=",
"$",
"this",
"->",
"entity",
"->",
"getCategories",
"(",
")",
";",
"$",
"categories",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"categoryEntities",
")",
"{",
"foreach",
"(",
"$",
"categoryEntities",
"as",
"$",
"categoryEntity",
")",
"{",
"$",
"categories",
"[",
"]",
"=",
"new",
"Category",
"(",
"$",
"categoryEntity",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"}",
"return",
"$",
"categories",
";",
"}"
] |
Returns the categories for the product.
@VirtualProperty
@SerializedName("categories")
@return CategoryEntity[]
|
[
"Returns",
"the",
"categories",
"for",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L970-L982
|
224,093
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getMedia
|
public function getMedia()
{
// if media was set by setMedia() use this->media
if ($this->media) {
return $this->media;
}
$mediaCollection = [];
$media = $this->entity->getMedia();
if (!$media) {
return $mediaCollection;
}
foreach ($media as $medium) {
$mediaCollection[] = new Media($medium, $this->locale);
}
return $mediaCollection;
}
|
php
|
public function getMedia()
{
// if media was set by setMedia() use this->media
if ($this->media) {
return $this->media;
}
$mediaCollection = [];
$media = $this->entity->getMedia();
if (!$media) {
return $mediaCollection;
}
foreach ($media as $medium) {
$mediaCollection[] = new Media($medium, $this->locale);
}
return $mediaCollection;
}
|
[
"public",
"function",
"getMedia",
"(",
")",
"{",
"// if media was set by setMedia() use this->media",
"if",
"(",
"$",
"this",
"->",
"media",
")",
"{",
"return",
"$",
"this",
"->",
"media",
";",
"}",
"$",
"mediaCollection",
"=",
"[",
"]",
";",
"$",
"media",
"=",
"$",
"this",
"->",
"entity",
"->",
"getMedia",
"(",
")",
";",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"return",
"$",
"mediaCollection",
";",
"}",
"foreach",
"(",
"$",
"media",
"as",
"$",
"medium",
")",
"{",
"$",
"mediaCollection",
"[",
"]",
"=",
"new",
"Media",
"(",
"$",
"medium",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"$",
"mediaCollection",
";",
"}"
] |
Returns the media for the product.
@VirtualProperty
@SerializedName("media")
@Groups({"cart"})
@return Media[]
|
[
"Returns",
"the",
"media",
"for",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L1071-L1087
|
224,094
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getMediaByType
|
private function getMediaByType($type)
{
$collection = [];
$media = $this->getMedia();
if (!$media) {
return $collection;
}
foreach ($media as $asset) {
if ($asset->isTypeOf($type)) {
$collection[] = $asset;
}
}
return $collection;
}
|
php
|
private function getMediaByType($type)
{
$collection = [];
$media = $this->getMedia();
if (!$media) {
return $collection;
}
foreach ($media as $asset) {
if ($asset->isTypeOf($type)) {
$collection[] = $asset;
}
}
return $collection;
}
|
[
"private",
"function",
"getMediaByType",
"(",
"$",
"type",
")",
"{",
"$",
"collection",
"=",
"[",
"]",
";",
"$",
"media",
"=",
"$",
"this",
"->",
"getMedia",
"(",
")",
";",
"if",
"(",
"!",
"$",
"media",
")",
"{",
"return",
"$",
"collection",
";",
"}",
"foreach",
"(",
"$",
"media",
"as",
"$",
"asset",
")",
"{",
"if",
"(",
"$",
"asset",
"->",
"isTypeOf",
"(",
"$",
"type",
")",
")",
"{",
"$",
"collection",
"[",
"]",
"=",
"$",
"asset",
";",
"}",
"}",
"return",
"$",
"collection",
";",
"}"
] |
Returns a media array by a given type for the product.
@param string
@return array
|
[
"Returns",
"a",
"media",
"array",
"by",
"a",
"given",
"type",
"for",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L1187-L1201
|
224,095
|
sulu/SuluProductBundle
|
Api/Product.php
|
Product.getSpecialPrices
|
public function getSpecialPrices()
{
$specialPrices = $this->entity->getSpecialPrices();
$specialPricesList = [];
foreach ($specialPrices as $specialPrice) {
$specialPricesList[] = new SpecialPrice($specialPrice, $this->locale);
}
return $specialPricesList;
}
|
php
|
public function getSpecialPrices()
{
$specialPrices = $this->entity->getSpecialPrices();
$specialPricesList = [];
foreach ($specialPrices as $specialPrice) {
$specialPricesList[] = new SpecialPrice($specialPrice, $this->locale);
}
return $specialPricesList;
}
|
[
"public",
"function",
"getSpecialPrices",
"(",
")",
"{",
"$",
"specialPrices",
"=",
"$",
"this",
"->",
"entity",
"->",
"getSpecialPrices",
"(",
")",
";",
"$",
"specialPricesList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"specialPrices",
"as",
"$",
"specialPrice",
")",
"{",
"$",
"specialPricesList",
"[",
"]",
"=",
"new",
"SpecialPrice",
"(",
"$",
"specialPrice",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"return",
"$",
"specialPricesList",
";",
"}"
] |
Returns the special prices for the product.
@VirtualProperty
@SerializedName("specialPrices")
@return \Sulu\Bundle\ProductBundle\Api\SpecialPrice[]
|
[
"Returns",
"the",
"special",
"prices",
"for",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Product.php#L1228-L1238
|
224,096
|
kesar/PhpOpenSubtitles
|
src/kesar/PhpOpenSubtitles/FileGenerator.php
|
FileGenerator.downloadSubtitle
|
public function downloadSubtitle($url, $originalFile)
{
$subtitleFile = preg_replace("/\\.[^.\\s]{3,4}$/", "", $originalFile) . '.srt';
$subtitleContent = gzdecode(file_get_contents($url));
file_put_contents($subtitleFile, $subtitleContent);
}
|
php
|
public function downloadSubtitle($url, $originalFile)
{
$subtitleFile = preg_replace("/\\.[^.\\s]{3,4}$/", "", $originalFile) . '.srt';
$subtitleContent = gzdecode(file_get_contents($url));
file_put_contents($subtitleFile, $subtitleContent);
}
|
[
"public",
"function",
"downloadSubtitle",
"(",
"$",
"url",
",",
"$",
"originalFile",
")",
"{",
"$",
"subtitleFile",
"=",
"preg_replace",
"(",
"\"/\\\\.[^.\\\\s]{3,4}$/\"",
",",
"\"\"",
",",
"$",
"originalFile",
")",
".",
"'.srt'",
";",
"$",
"subtitleContent",
"=",
"gzdecode",
"(",
"file_get_contents",
"(",
"$",
"url",
")",
")",
";",
"file_put_contents",
"(",
"$",
"subtitleFile",
",",
"$",
"subtitleContent",
")",
";",
"}"
] |
Download subtitle and put it in the same folder than the video with the same name + srt
@param string $url
@param string $originalFile
|
[
"Download",
"subtitle",
"and",
"put",
"it",
"in",
"the",
"same",
"folder",
"than",
"the",
"video",
"with",
"the",
"same",
"name",
"+",
"srt"
] |
8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3
|
https://github.com/kesar/PhpOpenSubtitles/blob/8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3/src/kesar/PhpOpenSubtitles/FileGenerator.php#L13-L19
|
224,097
|
actualreports/pdfgeneratorapi-laravel
|
src/Repositories/DataRepository.php
|
DataRepository.getUrl
|
public function getUrl()
{
$data = $this->getRawData();
/**
* If data is already an url don't save new file
*/
if ($data && !filter_var($data, FILTER_VALIDATE_URL) !== false)
{
if(!is_string($data))
{
$data = \GuzzleHttp\json_encode($data);
}
$identifier = Auth::guest() ? time() : Auth::id();
$file = $this->dataFolder.DIRECTORY_SEPARATOR.md5($identifier).'.json';
Storage::disk('public')->put($file, $data);
$data = asset($this->publicStorageFolder.DIRECTORY_SEPARATOR.$file);
}
return $data;
}
|
php
|
public function getUrl()
{
$data = $this->getRawData();
/**
* If data is already an url don't save new file
*/
if ($data && !filter_var($data, FILTER_VALIDATE_URL) !== false)
{
if(!is_string($data))
{
$data = \GuzzleHttp\json_encode($data);
}
$identifier = Auth::guest() ? time() : Auth::id();
$file = $this->dataFolder.DIRECTORY_SEPARATOR.md5($identifier).'.json';
Storage::disk('public')->put($file, $data);
$data = asset($this->publicStorageFolder.DIRECTORY_SEPARATOR.$file);
}
return $data;
}
|
[
"public",
"function",
"getUrl",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getRawData",
"(",
")",
";",
"/**\n * If data is already an url don't save new file\n */",
"if",
"(",
"$",
"data",
"&&",
"!",
"filter_var",
"(",
"$",
"data",
",",
"FILTER_VALIDATE_URL",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"\\",
"GuzzleHttp",
"\\",
"json_encode",
"(",
"$",
"data",
")",
";",
"}",
"$",
"identifier",
"=",
"Auth",
"::",
"guest",
"(",
")",
"?",
"time",
"(",
")",
":",
"Auth",
"::",
"id",
"(",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"dataFolder",
".",
"DIRECTORY_SEPARATOR",
".",
"md5",
"(",
"$",
"identifier",
")",
".",
"'.json'",
";",
"Storage",
"::",
"disk",
"(",
"'public'",
")",
"->",
"put",
"(",
"$",
"file",
",",
"$",
"data",
")",
";",
"$",
"data",
"=",
"asset",
"(",
"$",
"this",
"->",
"publicStorageFolder",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Saves a temporary json file and generates public url that is sent to PDF Generator service
@return string
|
[
"Saves",
"a",
"temporary",
"json",
"file",
"and",
"generates",
"public",
"url",
"that",
"is",
"sent",
"to",
"PDF",
"Generator",
"service"
] |
f5fb75cb7c5f15029844378f9c9c098f7126178a
|
https://github.com/actualreports/pdfgeneratorapi-laravel/blob/f5fb75cb7c5f15029844378f9c9c098f7126178a/src/Repositories/DataRepository.php#L29-L49
|
224,098
|
sulu/SuluProductBundle
|
Product/DeliveryStatusManager.php
|
DeliveryStatusManager.findAll
|
public function findAll($locale)
{
$statuses = $this->deliveryStatusRepository->findAllByLocale($locale);
array_walk(
$statuses,
function (&$status) use ($locale) {
$status = new DeliveryStatus($status, $locale);
}
);
return $statuses;
}
|
php
|
public function findAll($locale)
{
$statuses = $this->deliveryStatusRepository->findAllByLocale($locale);
array_walk(
$statuses,
function (&$status) use ($locale) {
$status = new DeliveryStatus($status, $locale);
}
);
return $statuses;
}
|
[
"public",
"function",
"findAll",
"(",
"$",
"locale",
")",
"{",
"$",
"statuses",
"=",
"$",
"this",
"->",
"deliveryStatusRepository",
"->",
"findAllByLocale",
"(",
"$",
"locale",
")",
";",
"array_walk",
"(",
"$",
"statuses",
",",
"function",
"(",
"&",
"$",
"status",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"$",
"status",
"=",
"new",
"DeliveryStatus",
"(",
"$",
"status",
",",
"$",
"locale",
")",
";",
"}",
")",
";",
"return",
"$",
"statuses",
";",
"}"
] |
Returns all delivery statuses by given locale.
@param string $locale
@return null|DeliveryStatus[]
|
[
"Returns",
"all",
"delivery",
"statuses",
"by",
"given",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/DeliveryStatusManager.php#L46-L58
|
224,099
|
sulu/SuluProductBundle
|
Product/DeliveryStatusManager.php
|
DeliveryStatusManager.retrieveTranslationByIdAndLocale
|
public function retrieveTranslationByIdAndLocale($deliveryStatusId, $locale)
{
/** @var DeliveryStatusEntity $deliveryStatus */
$deliveryStatus = $this->deliveryStatusRepository->find($deliveryStatusId);
if (!$deliveryStatus || $deliveryStatus->getTranslations()->count() < 1) {
return null;
}
$deliveryStatusTranslation = $deliveryStatus->getTranslations()->first();
/** @var DeliveryStatusTranslation $translation */
foreach ($deliveryStatus->getTranslations() as $translation) {
if ($translation->getLocale() === $locale) {
$deliveryStatusTranslation = $translation;
break;
}
}
return $deliveryStatusTranslation;
}
|
php
|
public function retrieveTranslationByIdAndLocale($deliveryStatusId, $locale)
{
/** @var DeliveryStatusEntity $deliveryStatus */
$deliveryStatus = $this->deliveryStatusRepository->find($deliveryStatusId);
if (!$deliveryStatus || $deliveryStatus->getTranslations()->count() < 1) {
return null;
}
$deliveryStatusTranslation = $deliveryStatus->getTranslations()->first();
/** @var DeliveryStatusTranslation $translation */
foreach ($deliveryStatus->getTranslations() as $translation) {
if ($translation->getLocale() === $locale) {
$deliveryStatusTranslation = $translation;
break;
}
}
return $deliveryStatusTranslation;
}
|
[
"public",
"function",
"retrieveTranslationByIdAndLocale",
"(",
"$",
"deliveryStatusId",
",",
"$",
"locale",
")",
"{",
"/** @var DeliveryStatusEntity $deliveryStatus */",
"$",
"deliveryStatus",
"=",
"$",
"this",
"->",
"deliveryStatusRepository",
"->",
"find",
"(",
"$",
"deliveryStatusId",
")",
";",
"if",
"(",
"!",
"$",
"deliveryStatus",
"||",
"$",
"deliveryStatus",
"->",
"getTranslations",
"(",
")",
"->",
"count",
"(",
")",
"<",
"1",
")",
"{",
"return",
"null",
";",
"}",
"$",
"deliveryStatusTranslation",
"=",
"$",
"deliveryStatus",
"->",
"getTranslations",
"(",
")",
"->",
"first",
"(",
")",
";",
"/** @var DeliveryStatusTranslation $translation */",
"foreach",
"(",
"$",
"deliveryStatus",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"translation",
")",
"{",
"if",
"(",
"$",
"translation",
"->",
"getLocale",
"(",
")",
"===",
"$",
"locale",
")",
"{",
"$",
"deliveryStatusTranslation",
"=",
"$",
"translation",
";",
"break",
";",
"}",
"}",
"return",
"$",
"deliveryStatusTranslation",
";",
"}"
] |
Returns DeliveryStatusTranslation by given DeliveryStatus-id and locale.
@param int $deliveryStatusId
@param string $locale
@return null|DeliveryStatusTranslation
|
[
"Returns",
"DeliveryStatusTranslation",
"by",
"given",
"DeliveryStatus",
"-",
"id",
"and",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/DeliveryStatusManager.php#L68-L88
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.