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
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Larium/http-client | src/Http/Client.php | Client.createStreamFromArray | public function createStreamFromArray(array $params)
{
$string = "";
foreach ($params as $key => $value) {
$string .= $key . '=' . urlencode(trim($value)) . '&';
}
$string = rtrim($string, "&");
return $this->createStream($string);
} | php | public function createStreamFromArray(array $params)
{
$string = "";
foreach ($params as $key => $value) {
$string .= $key . '=' . urlencode(trim($value)) . '&';
}
$string = rtrim($string, "&");
return $this->createStream($string);
} | [
"public",
"function",
"createStreamFromArray",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"string",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"string",
".=",
"$",
"key",
".",
"'='",
".",
"urlencode",
"(",
"trim",
"(",
"$",
"value",
")",
")",
".",
"'&'",
";",
"}",
"$",
"string",
"=",
"rtrim",
"(",
"$",
"string",
",",
"\"&\"",
")",
";",
"return",
"$",
"this",
"->",
"createStream",
"(",
"$",
"string",
")",
";",
"}"
] | Helper method to create a string stream from given array.
@param array $params
@return resource | [
"Helper",
"method",
"to",
"create",
"a",
"string",
"stream",
"from",
"given",
"array",
"."
] | b87934843f32da37ce60ec3878ccf090c981989d | https://github.com/Larium/http-client/blob/b87934843f32da37ce60ec3878ccf090c981989d/src/Http/Client.php#L158-L168 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/WebServiceProxy.php | WebServiceProxy.callMethod | public function callMethod($name, $httpMethod = "POST", $params = array(), $payload = null, $returnClass = null, $expectedExceptions = null) {
$objectToFormatConverter = $this->dataFormat == self::DATA_FORMAT_JSON ? new ObjectToJSONConverter() : new ObjectToXMLConverter();
$formatToObjectConverter = $this->dataFormat == self::DATA_FORMAT_JSON ? new JSONToObjectConverter() : new XMLToObjectConverter();
if (!is_array($expectedExceptions)) {
$expectedExceptions = array();
}
if (!ArrayUtils::isAssociative($expectedExceptions)) {
$expectedExceptions = array_combine($expectedExceptions, $expectedExceptions);
}
$parameters = $this->globalParameters;
if (is_array($parameters) && is_array($params)) {
$parameters = array_merge($parameters, $params);
}
foreach ($parameters as $key => $value) {
$parameters[$key] = $value;
}
if ($payload) {
$payload = $objectToFormatConverter->convert($payload);
}
$request = new HttpRemoteRequest($this->webServiceURL . "/" . $name, $httpMethod, $parameters, $payload);
try {
$result = $request->dispatch();
if ($this->dataFormat == self::DATA_FORMAT_JSON) {
$result = $formatToObjectConverter->convert($result);
}
if ($returnClass) {
$result = SerialisableArrayUtils::convertArrayToSerialisableObjects($result, $returnClass);
}
return $result;
} catch (HttpRequestErrorException $e) {
$response = $e->getResponse();
if ($this->dataFormat == self::DATA_FORMAT_JSON) {
$response = $formatToObjectConverter->convert($response);
if ($response["exceptionClass"] && isset($expectedExceptions[$response["exceptionClass"]])) {
$response = SerialisableArrayUtils::convertArrayToSerialisableObjects($response, $expectedExceptions[$response["exceptionClass"]]);
}
}
if ($response instanceof SerialisableException) {
throw $response;
} else {
throw $e;
}
}
} | php | public function callMethod($name, $httpMethod = "POST", $params = array(), $payload = null, $returnClass = null, $expectedExceptions = null) {
$objectToFormatConverter = $this->dataFormat == self::DATA_FORMAT_JSON ? new ObjectToJSONConverter() : new ObjectToXMLConverter();
$formatToObjectConverter = $this->dataFormat == self::DATA_FORMAT_JSON ? new JSONToObjectConverter() : new XMLToObjectConverter();
if (!is_array($expectedExceptions)) {
$expectedExceptions = array();
}
if (!ArrayUtils::isAssociative($expectedExceptions)) {
$expectedExceptions = array_combine($expectedExceptions, $expectedExceptions);
}
$parameters = $this->globalParameters;
if (is_array($parameters) && is_array($params)) {
$parameters = array_merge($parameters, $params);
}
foreach ($parameters as $key => $value) {
$parameters[$key] = $value;
}
if ($payload) {
$payload = $objectToFormatConverter->convert($payload);
}
$request = new HttpRemoteRequest($this->webServiceURL . "/" . $name, $httpMethod, $parameters, $payload);
try {
$result = $request->dispatch();
if ($this->dataFormat == self::DATA_FORMAT_JSON) {
$result = $formatToObjectConverter->convert($result);
}
if ($returnClass) {
$result = SerialisableArrayUtils::convertArrayToSerialisableObjects($result, $returnClass);
}
return $result;
} catch (HttpRequestErrorException $e) {
$response = $e->getResponse();
if ($this->dataFormat == self::DATA_FORMAT_JSON) {
$response = $formatToObjectConverter->convert($response);
if ($response["exceptionClass"] && isset($expectedExceptions[$response["exceptionClass"]])) {
$response = SerialisableArrayUtils::convertArrayToSerialisableObjects($response, $expectedExceptions[$response["exceptionClass"]]);
}
}
if ($response instanceof SerialisableException) {
throw $response;
} else {
throw $e;
}
}
} | [
"public",
"function",
"callMethod",
"(",
"$",
"name",
",",
"$",
"httpMethod",
"=",
"\"POST\"",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"payload",
"=",
"null",
",",
"$",
"returnClass",
"=",
"null",
",",
"$",
"expectedExceptions",
"=",
"null",
")",
"{",
"$",
"objectToFormatConverter",
"=",
"$",
"this",
"->",
"dataFormat",
"==",
"self",
"::",
"DATA_FORMAT_JSON",
"?",
"new",
"ObjectToJSONConverter",
"(",
")",
":",
"new",
"ObjectToXMLConverter",
"(",
")",
";",
"$",
"formatToObjectConverter",
"=",
"$",
"this",
"->",
"dataFormat",
"==",
"self",
"::",
"DATA_FORMAT_JSON",
"?",
"new",
"JSONToObjectConverter",
"(",
")",
":",
"new",
"XMLToObjectConverter",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"expectedExceptions",
")",
")",
"{",
"$",
"expectedExceptions",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"ArrayUtils",
"::",
"isAssociative",
"(",
"$",
"expectedExceptions",
")",
")",
"{",
"$",
"expectedExceptions",
"=",
"array_combine",
"(",
"$",
"expectedExceptions",
",",
"$",
"expectedExceptions",
")",
";",
"}",
"$",
"parameters",
"=",
"$",
"this",
"->",
"globalParameters",
";",
"if",
"(",
"is_array",
"(",
"$",
"parameters",
")",
"&&",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"$",
"parameters",
"=",
"array_merge",
"(",
"$",
"parameters",
",",
"$",
"params",
")",
";",
"}",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"parameters",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"payload",
")",
"{",
"$",
"payload",
"=",
"$",
"objectToFormatConverter",
"->",
"convert",
"(",
"$",
"payload",
")",
";",
"}",
"$",
"request",
"=",
"new",
"HttpRemoteRequest",
"(",
"$",
"this",
"->",
"webServiceURL",
".",
"\"/\"",
".",
"$",
"name",
",",
"$",
"httpMethod",
",",
"$",
"parameters",
",",
"$",
"payload",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"request",
"->",
"dispatch",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dataFormat",
"==",
"self",
"::",
"DATA_FORMAT_JSON",
")",
"{",
"$",
"result",
"=",
"$",
"formatToObjectConverter",
"->",
"convert",
"(",
"$",
"result",
")",
";",
"}",
"if",
"(",
"$",
"returnClass",
")",
"{",
"$",
"result",
"=",
"SerialisableArrayUtils",
"::",
"convertArrayToSerialisableObjects",
"(",
"$",
"result",
",",
"$",
"returnClass",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"catch",
"(",
"HttpRequestErrorException",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dataFormat",
"==",
"self",
"::",
"DATA_FORMAT_JSON",
")",
"{",
"$",
"response",
"=",
"$",
"formatToObjectConverter",
"->",
"convert",
"(",
"$",
"response",
")",
";",
"if",
"(",
"$",
"response",
"[",
"\"exceptionClass\"",
"]",
"&&",
"isset",
"(",
"$",
"expectedExceptions",
"[",
"$",
"response",
"[",
"\"exceptionClass\"",
"]",
"]",
")",
")",
"{",
"$",
"response",
"=",
"SerialisableArrayUtils",
"::",
"convertArrayToSerialisableObjects",
"(",
"$",
"response",
",",
"$",
"expectedExceptions",
"[",
"$",
"response",
"[",
"\"exceptionClass\"",
"]",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"response",
"instanceof",
"SerialisableException",
")",
"{",
"throw",
"$",
"response",
";",
"}",
"else",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}"
] | Implement the call method to call a proxy service
@param string $name
@param $httpMethod
@param array $params
@param mixed $payload
@param string $returnClass
@param array $expectedExceptions an array of expected exceptions. This can simply be a values array of class names or an associative array defining mappings to client classes. | [
"Implement",
"the",
"call",
"method",
"to",
"call",
"a",
"proxy",
"service"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/WebServiceProxy.php#L62-L128 | train |
azettl/php-nano-template | template.php | template.setTemplateFile | public function setTemplateFile(string $sRelativePathToFile) : void
{
if(!is_file($sRelativePathToFile)) {
throw new \Exception('Template file not found.');
}
$sFileContent = file_get_contents($sRelativePathToFile);
$this->setTemplate($sFileContent);
} | php | public function setTemplateFile(string $sRelativePathToFile) : void
{
if(!is_file($sRelativePathToFile)) {
throw new \Exception('Template file not found.');
}
$sFileContent = file_get_contents($sRelativePathToFile);
$this->setTemplate($sFileContent);
} | [
"public",
"function",
"setTemplateFile",
"(",
"string",
"$",
"sRelativePathToFile",
")",
":",
"void",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"sRelativePathToFile",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Template file not found.'",
")",
";",
"}",
"$",
"sFileContent",
"=",
"file_get_contents",
"(",
"$",
"sRelativePathToFile",
")",
";",
"$",
"this",
"->",
"setTemplate",
"(",
"$",
"sFileContent",
")",
";",
"}"
] | This method is used to set the template from a relative
path.
@param string $sRelativePathToFile the relative path to the template
@throws Exception if the file is not found
@return void | [
"This",
"method",
"is",
"used",
"to",
"set",
"the",
"template",
"from",
"a",
"relative",
"path",
"."
] | bd1100ad15d290d8d6e2a58d94ad7c977f69d859 | https://github.com/azettl/php-nano-template/blob/bd1100ad15d290d8d6e2a58d94ad7c977f69d859/template.php#L77-L85 | train |
azettl/php-nano-template | template.php | template.render | public function render() : string
{
$sOutput = preg_replace_callback(
'/{(.*?)}/',
function ($aResult){
$aToSearch = explode('.', $aResult[1]);
$aSearchIn = $this->getData();
foreach ($aToSearch as $sKey) {
list(
$sFormattedKey,
$mParam
) = self::getFunctionNameAndParameter($sKey);
$mValue = $aSearchIn[$sFormattedKey];
if(is_string($mValue)) {
return $mValue;
} else if(is_object($mValue)) {
if($mParam){
return $mValue($mParam);
}
return $mValue();
}
$aSearchIn = $mValue;
}
return (
$this->hasShowEmpty()
?
$aResult[0]
:
''
);
},
$this->getTemplate()
);
return preg_replace('/^\s+|\n|\r|\t/m', '', $sOutput);
} | php | public function render() : string
{
$sOutput = preg_replace_callback(
'/{(.*?)}/',
function ($aResult){
$aToSearch = explode('.', $aResult[1]);
$aSearchIn = $this->getData();
foreach ($aToSearch as $sKey) {
list(
$sFormattedKey,
$mParam
) = self::getFunctionNameAndParameter($sKey);
$mValue = $aSearchIn[$sFormattedKey];
if(is_string($mValue)) {
return $mValue;
} else if(is_object($mValue)) {
if($mParam){
return $mValue($mParam);
}
return $mValue();
}
$aSearchIn = $mValue;
}
return (
$this->hasShowEmpty()
?
$aResult[0]
:
''
);
},
$this->getTemplate()
);
return preg_replace('/^\s+|\n|\r|\t/m', '', $sOutput);
} | [
"public",
"function",
"render",
"(",
")",
":",
"string",
"{",
"$",
"sOutput",
"=",
"preg_replace_callback",
"(",
"'/{(.*?)}/'",
",",
"function",
"(",
"$",
"aResult",
")",
"{",
"$",
"aToSearch",
"=",
"explode",
"(",
"'.'",
",",
"$",
"aResult",
"[",
"1",
"]",
")",
";",
"$",
"aSearchIn",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"foreach",
"(",
"$",
"aToSearch",
"as",
"$",
"sKey",
")",
"{",
"list",
"(",
"$",
"sFormattedKey",
",",
"$",
"mParam",
")",
"=",
"self",
"::",
"getFunctionNameAndParameter",
"(",
"$",
"sKey",
")",
";",
"$",
"mValue",
"=",
"$",
"aSearchIn",
"[",
"$",
"sFormattedKey",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"mValue",
")",
")",
"{",
"return",
"$",
"mValue",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"mValue",
")",
")",
"{",
"if",
"(",
"$",
"mParam",
")",
"{",
"return",
"$",
"mValue",
"(",
"$",
"mParam",
")",
";",
"}",
"return",
"$",
"mValue",
"(",
")",
";",
"}",
"$",
"aSearchIn",
"=",
"$",
"mValue",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"hasShowEmpty",
"(",
")",
"?",
"$",
"aResult",
"[",
"0",
"]",
":",
"''",
")",
";",
"}",
",",
"$",
"this",
"->",
"getTemplate",
"(",
")",
")",
";",
"return",
"preg_replace",
"(",
"'/^\\s+|\\n|\\r|\\t/m'",
",",
"''",
",",
"$",
"sOutput",
")",
";",
"}"
] | This method replaces the placeholders in the template string with
the values from the data object and returns the new string.
@return string the string with the replaced placeholders | [
"This",
"method",
"replaces",
"the",
"placeholders",
"in",
"the",
"template",
"string",
"with",
"the",
"values",
"from",
"the",
"data",
"object",
"and",
"returns",
"the",
"new",
"string",
"."
] | bd1100ad15d290d8d6e2a58d94ad7c977f69d859 | https://github.com/azettl/php-nano-template/blob/bd1100ad15d290d8d6e2a58d94ad7c977f69d859/template.php#L154-L196 | train |
SlabPHP/cache-manager | src/Providers/File.php | File.safelyReadData | private function safelyReadData($path)
{
$fp = fopen($path, 'r');
$retries = 0;
do {
if ($retries > 0) {
usleep(static::MS_BETWEEN_RETRIES * 1000); //100ms
}
$retries++;
} while (!flock($fp, LOCK_SH | LOCK_NB) && $retries <= static::MAX_RETRIES);
if ($retries == static::MAX_RETRIES) {
return false;
}
$data = file_get_contents($path);
flock($fp, LOCK_UN);
fclose($fp);
return $data;
} | php | private function safelyReadData($path)
{
$fp = fopen($path, 'r');
$retries = 0;
do {
if ($retries > 0) {
usleep(static::MS_BETWEEN_RETRIES * 1000); //100ms
}
$retries++;
} while (!flock($fp, LOCK_SH | LOCK_NB) && $retries <= static::MAX_RETRIES);
if ($retries == static::MAX_RETRIES) {
return false;
}
$data = file_get_contents($path);
flock($fp, LOCK_UN);
fclose($fp);
return $data;
} | [
"private",
"function",
"safelyReadData",
"(",
"$",
"path",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"path",
",",
"'r'",
")",
";",
"$",
"retries",
"=",
"0",
";",
"do",
"{",
"if",
"(",
"$",
"retries",
">",
"0",
")",
"{",
"usleep",
"(",
"static",
"::",
"MS_BETWEEN_RETRIES",
"*",
"1000",
")",
";",
"//100ms",
"}",
"$",
"retries",
"++",
";",
"}",
"while",
"(",
"!",
"flock",
"(",
"$",
"fp",
",",
"LOCK_SH",
"|",
"LOCK_NB",
")",
"&&",
"$",
"retries",
"<=",
"static",
"::",
"MAX_RETRIES",
")",
";",
"if",
"(",
"$",
"retries",
"==",
"static",
"::",
"MAX_RETRIES",
")",
"{",
"return",
"false",
";",
"}",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"flock",
"(",
"$",
"fp",
",",
"LOCK_UN",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Safely read data from a file
@param string $path
@return mixed | [
"Safely",
"read",
"data",
"from",
"a",
"file"
] | 7bbf9fe6519071fe14d382e98925cd3e10010a3a | https://github.com/SlabPHP/cache-manager/blob/7bbf9fe6519071fe14d382e98925cd3e10010a3a/src/Providers/File.php#L96-L119 | train |
SlabPHP/cache-manager | src/Providers/File.php | File.safelyWriteData | private function safelyWriteData($path, $mode, $data)
{
$fp = fopen($path, $mode);
$retries = 0;
if (empty($fp)) {
return false;
}
do {
if ($retries > 0) {
usleep(static::MS_BETWEEN_RETRIES * 1000);
}
$retries++;
} while (!flock($fp, LOCK_EX) && $retries <= static::MAX_RETRIES);
if ($retries == static::MAX_RETRIES) {
return false;
}
fwrite($fp, "$data\n");
flock($fp, LOCK_UN);
fclose($fp);
return true;
} | php | private function safelyWriteData($path, $mode, $data)
{
$fp = fopen($path, $mode);
$retries = 0;
if (empty($fp)) {
return false;
}
do {
if ($retries > 0) {
usleep(static::MS_BETWEEN_RETRIES * 1000);
}
$retries++;
} while (!flock($fp, LOCK_EX) && $retries <= static::MAX_RETRIES);
if ($retries == static::MAX_RETRIES) {
return false;
}
fwrite($fp, "$data\n");
flock($fp, LOCK_UN);
fclose($fp);
return true;
} | [
"private",
"function",
"safelyWriteData",
"(",
"$",
"path",
",",
"$",
"mode",
",",
"$",
"data",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"path",
",",
"$",
"mode",
")",
";",
"$",
"retries",
"=",
"0",
";",
"if",
"(",
"empty",
"(",
"$",
"fp",
")",
")",
"{",
"return",
"false",
";",
"}",
"do",
"{",
"if",
"(",
"$",
"retries",
">",
"0",
")",
"{",
"usleep",
"(",
"static",
"::",
"MS_BETWEEN_RETRIES",
"*",
"1000",
")",
";",
"}",
"$",
"retries",
"++",
";",
"}",
"while",
"(",
"!",
"flock",
"(",
"$",
"fp",
",",
"LOCK_EX",
")",
"&&",
"$",
"retries",
"<=",
"static",
"::",
"MAX_RETRIES",
")",
";",
"if",
"(",
"$",
"retries",
"==",
"static",
"::",
"MAX_RETRIES",
")",
"{",
"return",
"false",
";",
"}",
"fwrite",
"(",
"$",
"fp",
",",
"\"$data\\n\"",
")",
";",
"flock",
"(",
"$",
"fp",
",",
"LOCK_UN",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"true",
";",
"}"
] | Safely write data to a file
@param string $path
@param string $mode
@param string $data
@return boolean | [
"Safely",
"write",
"data",
"to",
"a",
"file"
] | 7bbf9fe6519071fe14d382e98925cd3e10010a3a | https://github.com/SlabPHP/cache-manager/blob/7bbf9fe6519071fe14d382e98925cd3e10010a3a/src/Providers/File.php#L130-L158 | train |
SlabPHP/cache-manager | src/Providers/File.php | File.processKey | protected function processKey($key)
{
$key = trim(strtolower($key));
$key = preg_replace('#[^a-z0-9\.]#', '-', $key) . '~' . $this->keySuffix;
return $key;
} | php | protected function processKey($key)
{
$key = trim(strtolower($key));
$key = preg_replace('#[^a-z0-9\.]#', '-', $key) . '~' . $this->keySuffix;
return $key;
} | [
"protected",
"function",
"processKey",
"(",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"key",
")",
")",
";",
"$",
"key",
"=",
"preg_replace",
"(",
"'#[^a-z0-9\\.]#'",
",",
"'-'",
",",
"$",
"key",
")",
".",
"'~'",
".",
"$",
"this",
"->",
"keySuffix",
";",
"return",
"$",
"key",
";",
"}"
] | Process the key to be filename safe
@param string $key
@return string | [
"Process",
"the",
"key",
"to",
"be",
"filename",
"safe"
] | 7bbf9fe6519071fe14d382e98925cd3e10010a3a | https://github.com/SlabPHP/cache-manager/blob/7bbf9fe6519071fe14d382e98925cd3e10010a3a/src/Providers/File.php#L215-L221 | train |
phossa/phossa-db | src/Phossa/Db/Statement/StatementAbstract.php | StatementAbstract.closePrevious | protected function closePrevious()
{
static $previous = [];
$id = spl_object_hash($this->getDriver());
if (isset($previous[$id]) && $previous[$id] !== $this->prepared) {
$this->realClose($previous[$id]);
}
$previous[$id] = $this->prepared;
return $this;
} | php | protected function closePrevious()
{
static $previous = [];
$id = spl_object_hash($this->getDriver());
if (isset($previous[$id]) && $previous[$id] !== $this->prepared) {
$this->realClose($previous[$id]);
}
$previous[$id] = $this->prepared;
return $this;
} | [
"protected",
"function",
"closePrevious",
"(",
")",
"{",
"static",
"$",
"previous",
"=",
"[",
"]",
";",
"$",
"id",
"=",
"spl_object_hash",
"(",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"previous",
"[",
"$",
"id",
"]",
")",
"&&",
"$",
"previous",
"[",
"$",
"id",
"]",
"!==",
"$",
"this",
"->",
"prepared",
")",
"{",
"$",
"this",
"->",
"realClose",
"(",
"$",
"previous",
"[",
"$",
"id",
"]",
")",
";",
"}",
"$",
"previous",
"[",
"$",
"id",
"]",
"=",
"$",
"this",
"->",
"prepared",
";",
"return",
"$",
"this",
";",
"}"
] | Close previous prepared statement
@return $this
@access protected | [
"Close",
"previous",
"prepared",
"statement"
] | 9ef2c0e0c3047f4ff2ce6b0a218187025ac64d29 | https://github.com/phossa/phossa-db/blob/9ef2c0e0c3047f4ff2ce6b0a218187025ac64d29/src/Phossa/Db/Statement/StatementAbstract.php#L187-L198 | train |
phossa/phossa-db | src/Phossa/Db/Statement/StatementAbstract.php | StatementAbstract.setError | protected function setError($resource)
{
if (is_string($resource)) {
$this->getDriver()->setError(
$resource, -1
);
} else {
$this->getDriver()->setError(
$this->realError($resource),
$this->realErrorCode($resource)
);
}
} | php | protected function setError($resource)
{
if (is_string($resource)) {
$this->getDriver()->setError(
$resource, -1
);
} else {
$this->getDriver()->setError(
$this->realError($resource),
$this->realErrorCode($resource)
);
}
} | [
"protected",
"function",
"setError",
"(",
"$",
"resource",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"resource",
")",
")",
"{",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"setError",
"(",
"$",
"resource",
",",
"-",
"1",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"setError",
"(",
"$",
"this",
"->",
"realError",
"(",
"$",
"resource",
")",
",",
"$",
"this",
"->",
"realErrorCode",
"(",
"$",
"resource",
")",
")",
";",
"}",
"}"
] | Set driver error
@param mixed $resource
@access protected | [
"Set",
"driver",
"error"
] | 9ef2c0e0c3047f4ff2ce6b0a218187025ac64d29 | https://github.com/phossa/phossa-db/blob/9ef2c0e0c3047f4ff2ce6b0a218187025ac64d29/src/Phossa/Db/Statement/StatementAbstract.php#L206-L218 | train |
blueblazeassociates/geocode-postalcodes | src/php/PostalCodes/Geocoders/PostalCodeGeocoderFactory.php | PostalCodeGeocoderFactory.createGeocodingProvider | public static function createGeocodingProvider( $provider_code = GeocodingProviders::GOOGLE_MAPS ) {
if ( GeocodingProviders::GOOGLE_MAPS != $provider_code ) {
throw new GeocodingException( 'Geocoding provider \'' . $provider_code . '\' not found.' );
}
return new \BlueBlazeAssociates\Geocoding\PostalCodes\Providers\GoogleMapsProvider();
// TODO Create a map between provider keys and implementation class names.
} | php | public static function createGeocodingProvider( $provider_code = GeocodingProviders::GOOGLE_MAPS ) {
if ( GeocodingProviders::GOOGLE_MAPS != $provider_code ) {
throw new GeocodingException( 'Geocoding provider \'' . $provider_code . '\' not found.' );
}
return new \BlueBlazeAssociates\Geocoding\PostalCodes\Providers\GoogleMapsProvider();
// TODO Create a map between provider keys and implementation class names.
} | [
"public",
"static",
"function",
"createGeocodingProvider",
"(",
"$",
"provider_code",
"=",
"GeocodingProviders",
"::",
"GOOGLE_MAPS",
")",
"{",
"if",
"(",
"GeocodingProviders",
"::",
"GOOGLE_MAPS",
"!=",
"$",
"provider_code",
")",
"{",
"throw",
"new",
"GeocodingException",
"(",
"'Geocoding provider \\''",
".",
"$",
"provider_code",
".",
"'\\' not found.'",
")",
";",
"}",
"return",
"new",
"\\",
"BlueBlazeAssociates",
"\\",
"Geocoding",
"\\",
"PostalCodes",
"\\",
"Providers",
"\\",
"GoogleMapsProvider",
"(",
")",
";",
"// TODO Create a map between provider keys and implementation class names.",
"}"
] | Creates a geocoding provider based on a set code.
@param string $provider_code
@return PostalCodeGeocodingProvider
@throws GeocodingException Throws exception if geocoding provider can't be found. | [
"Creates",
"a",
"geocoding",
"provider",
"based",
"on",
"a",
"set",
"code",
"."
] | 3a9b6c68327b13f5dc15015e78223dd215e8d4ea | https://github.com/blueblazeassociates/geocode-postalcodes/blob/3a9b6c68327b13f5dc15015e78223dd215e8d4ea/src/php/PostalCodes/Geocoders/PostalCodeGeocoderFactory.php#L23-L31 | train |
blueblazeassociates/geocode-postalcodes | src/php/PostalCodes/Geocoders/PostalCodeGeocoderFactory.php | PostalCodeGeocoderFactory.createGeocoder | public static function createGeocoder( $country_code = CountryCodes::US, $provider_code = GeocodingProviders::GOOGLE_MAPS ) {
if ( CountryCodes::US != $country_code ) {
throw new GeocodingException( 'PostalCode geocoder for country \'' . $country_code . '\' not found.' );
}
$geocoding_provider = static::createGeocodingProvider( $provider_code );
return new \BlueBlazeAssociates\Geocoding\PostalCodes\Geocoders\USPostalCodeGeocoder( $geocoding_provider );
// TODO Create a map between country codes and implementation class names.
} | php | public static function createGeocoder( $country_code = CountryCodes::US, $provider_code = GeocodingProviders::GOOGLE_MAPS ) {
if ( CountryCodes::US != $country_code ) {
throw new GeocodingException( 'PostalCode geocoder for country \'' . $country_code . '\' not found.' );
}
$geocoding_provider = static::createGeocodingProvider( $provider_code );
return new \BlueBlazeAssociates\Geocoding\PostalCodes\Geocoders\USPostalCodeGeocoder( $geocoding_provider );
// TODO Create a map between country codes and implementation class names.
} | [
"public",
"static",
"function",
"createGeocoder",
"(",
"$",
"country_code",
"=",
"CountryCodes",
"::",
"US",
",",
"$",
"provider_code",
"=",
"GeocodingProviders",
"::",
"GOOGLE_MAPS",
")",
"{",
"if",
"(",
"CountryCodes",
"::",
"US",
"!=",
"$",
"country_code",
")",
"{",
"throw",
"new",
"GeocodingException",
"(",
"'PostalCode geocoder for country \\''",
".",
"$",
"country_code",
".",
"'\\' not found.'",
")",
";",
"}",
"$",
"geocoding_provider",
"=",
"static",
"::",
"createGeocodingProvider",
"(",
"$",
"provider_code",
")",
";",
"return",
"new",
"\\",
"BlueBlazeAssociates",
"\\",
"Geocoding",
"\\",
"PostalCodes",
"\\",
"Geocoders",
"\\",
"USPostalCodeGeocoder",
"(",
"$",
"geocoding_provider",
")",
";",
"// TODO Create a map between country codes and implementation class names.",
"}"
] | Create a country specific geocoder for postal codes.
@param CountryCode $countrycode
@return BasePostalCodeGeocoder
@throws GeocodingException Throws exception if country code isn't supported.
@throws GeocodingException Throws exception if geocoding provider can't be found. | [
"Create",
"a",
"country",
"specific",
"geocoder",
"for",
"postal",
"codes",
"."
] | 3a9b6c68327b13f5dc15015e78223dd215e8d4ea | https://github.com/blueblazeassociates/geocode-postalcodes/blob/3a9b6c68327b13f5dc15015e78223dd215e8d4ea/src/php/PostalCodes/Geocoders/PostalCodeGeocoderFactory.php#L43-L53 | train |
fridge-project/dbal | src/Fridge/DBAL/ConnectionFactory.php | ConnectionFactory.create | public static function create(array $parameters, Configuration $configuration = null)
{
if (isset($parameters['driver_class'])) {
if (!in_array('Fridge\DBAL\Driver\DriverInterface', class_implements($parameters['driver_class']))) {
throw FactoryException::driverMustImplementDriverInterface($parameters['driver_class']);
}
$driverClass = $parameters['driver_class'];
} elseif (isset($parameters['driver'])) {
if (!isset(self::$mappedDriverClasses[$parameters['driver']])) {
throw FactoryException::driverDoesNotExist($parameters['driver'], self::getAvailableDrivers());
}
$driverClass = self::$mappedDriverClasses[$parameters['driver']];
} else {
throw FactoryException::driverRequired(self::getAvailableDrivers());
}
if (isset($parameters['connection_class'])) {
if (!in_array(
'Fridge\DBAL\Connection\ConnectionInterface',
class_implements($parameters['connection_class'])
)) {
throw FactoryException::connectionMustImplementConnectionInterface($parameters['connection_class']);
}
$connectionClass = $parameters['connection_class'];
} else {
$connectionClass = 'Fridge\DBAL\Connection\Connection';
}
return new $connectionClass($parameters, new $driverClass(), $configuration);
} | php | public static function create(array $parameters, Configuration $configuration = null)
{
if (isset($parameters['driver_class'])) {
if (!in_array('Fridge\DBAL\Driver\DriverInterface', class_implements($parameters['driver_class']))) {
throw FactoryException::driverMustImplementDriverInterface($parameters['driver_class']);
}
$driverClass = $parameters['driver_class'];
} elseif (isset($parameters['driver'])) {
if (!isset(self::$mappedDriverClasses[$parameters['driver']])) {
throw FactoryException::driverDoesNotExist($parameters['driver'], self::getAvailableDrivers());
}
$driverClass = self::$mappedDriverClasses[$parameters['driver']];
} else {
throw FactoryException::driverRequired(self::getAvailableDrivers());
}
if (isset($parameters['connection_class'])) {
if (!in_array(
'Fridge\DBAL\Connection\ConnectionInterface',
class_implements($parameters['connection_class'])
)) {
throw FactoryException::connectionMustImplementConnectionInterface($parameters['connection_class']);
}
$connectionClass = $parameters['connection_class'];
} else {
$connectionClass = 'Fridge\DBAL\Connection\Connection';
}
return new $connectionClass($parameters, new $driverClass(), $configuration);
} | [
"public",
"static",
"function",
"create",
"(",
"array",
"$",
"parameters",
",",
"Configuration",
"$",
"configuration",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"'driver_class'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"'Fridge\\DBAL\\Driver\\DriverInterface'",
",",
"class_implements",
"(",
"$",
"parameters",
"[",
"'driver_class'",
"]",
")",
")",
")",
"{",
"throw",
"FactoryException",
"::",
"driverMustImplementDriverInterface",
"(",
"$",
"parameters",
"[",
"'driver_class'",
"]",
")",
";",
"}",
"$",
"driverClass",
"=",
"$",
"parameters",
"[",
"'driver_class'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"'driver'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"mappedDriverClasses",
"[",
"$",
"parameters",
"[",
"'driver'",
"]",
"]",
")",
")",
"{",
"throw",
"FactoryException",
"::",
"driverDoesNotExist",
"(",
"$",
"parameters",
"[",
"'driver'",
"]",
",",
"self",
"::",
"getAvailableDrivers",
"(",
")",
")",
";",
"}",
"$",
"driverClass",
"=",
"self",
"::",
"$",
"mappedDriverClasses",
"[",
"$",
"parameters",
"[",
"'driver'",
"]",
"]",
";",
"}",
"else",
"{",
"throw",
"FactoryException",
"::",
"driverRequired",
"(",
"self",
"::",
"getAvailableDrivers",
"(",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"'connection_class'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"'Fridge\\DBAL\\Connection\\ConnectionInterface'",
",",
"class_implements",
"(",
"$",
"parameters",
"[",
"'connection_class'",
"]",
")",
")",
")",
"{",
"throw",
"FactoryException",
"::",
"connectionMustImplementConnectionInterface",
"(",
"$",
"parameters",
"[",
"'connection_class'",
"]",
")",
";",
"}",
"$",
"connectionClass",
"=",
"$",
"parameters",
"[",
"'connection_class'",
"]",
";",
"}",
"else",
"{",
"$",
"connectionClass",
"=",
"'Fridge\\DBAL\\Connection\\Connection'",
";",
"}",
"return",
"new",
"$",
"connectionClass",
"(",
"$",
"parameters",
",",
"new",
"$",
"driverClass",
"(",
")",
",",
"$",
"configuration",
")",
";",
"}"
] | Creates a DBAL connection.
$parameters must contain at least:
- driver (string) (ex: pdo_mysql, pdo_pgsql)
OR
- driver_class (string) (ex: Fridge\DBAL\Driver\MySQLDriver)
If you use driver & driver_class parameters simultaneously, the driver_class will be used.
$parameters can contain:
- connection_class (string) (ex: Fridge\DBAL\Connection\Connection)
- username (string)
- password (string)
- dbname (string)
- host (string)
- port (integer)
If you don't use the connection_class parameter, the class Fridge\DBAL\Connection\Connection will be used.
$parameters can contain some specific database parameters:
- pdo_mysql: unix_socket (string), charset (string), driver_options (array)
- pdo_pgsql: driver_options (array)
- mysqli: unix_socket (string), charset (string)
@param array $parameters The connection parameters.
@param \Fridge\DBAL\Configuration $configuration The connection configuration.
@throws \Fridge\DBAL\Exception\FactoryException If there is no driver, it the driver does not exist, if the
driver class does not implement the DriverInterface or if the
connection class does not implement the ConnectionInterface
@return \Fridge\DBAL\Connection\ConnectionInterface The DBAL Connection. | [
"Creates",
"a",
"DBAL",
"connection",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/ConnectionFactory.php#L78-L110 | train |
radioactivehamster/temporal | src/Calendar/Day.php | Day.getName | public function getName()
{
switch ($this->ofWeek) {
case Carbon::MONDAY:
$name = 'Monday';
break;
case Carbon::TUESDAY:
$name = 'Tuesday';
break;
case Carbon::WEDNESDAY:
$name = 'Wednesday';
break;
case Carbon::THURSDAY:
$name = 'Thursday';
break;
case Carbon::FRIDAY:
$name = 'Friday';
break;
case Carbon::SATURDAY:
$name = 'Saturday';
break;
case Carbon::SUNDAY:
$name = 'Sunday';
break;
default:
throw new LogicException;
}
return $name;
} | php | public function getName()
{
switch ($this->ofWeek) {
case Carbon::MONDAY:
$name = 'Monday';
break;
case Carbon::TUESDAY:
$name = 'Tuesday';
break;
case Carbon::WEDNESDAY:
$name = 'Wednesday';
break;
case Carbon::THURSDAY:
$name = 'Thursday';
break;
case Carbon::FRIDAY:
$name = 'Friday';
break;
case Carbon::SATURDAY:
$name = 'Saturday';
break;
case Carbon::SUNDAY:
$name = 'Sunday';
break;
default:
throw new LogicException;
}
return $name;
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"ofWeek",
")",
"{",
"case",
"Carbon",
"::",
"MONDAY",
":",
"$",
"name",
"=",
"'Monday'",
";",
"break",
";",
"case",
"Carbon",
"::",
"TUESDAY",
":",
"$",
"name",
"=",
"'Tuesday'",
";",
"break",
";",
"case",
"Carbon",
"::",
"WEDNESDAY",
":",
"$",
"name",
"=",
"'Wednesday'",
";",
"break",
";",
"case",
"Carbon",
"::",
"THURSDAY",
":",
"$",
"name",
"=",
"'Thursday'",
";",
"break",
";",
"case",
"Carbon",
"::",
"FRIDAY",
":",
"$",
"name",
"=",
"'Friday'",
";",
"break",
";",
"case",
"Carbon",
"::",
"SATURDAY",
":",
"$",
"name",
"=",
"'Saturday'",
";",
"break",
";",
"case",
"Carbon",
"::",
"SUNDAY",
":",
"$",
"name",
"=",
"'Sunday'",
";",
"break",
";",
"default",
":",
"throw",
"new",
"LogicException",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Gets the day's name.
@return string | [
"Gets",
"the",
"day",
"s",
"name",
"."
] | bfdfc853af70af507165f50d9e92ad78ad75897c | https://github.com/radioactivehamster/temporal/blob/bfdfc853af70af507165f50d9e92ad78ad75897c/src/Calendar/Day.php#L86-L122 | train |
CQD/minorwork | src/App.php | App.get | public function get($name)
{
if (isset($this->items[$name])) {
return $this->items[$name];
}
if (!isset($this->itemSetting[$name])) {
return null;
}
$itemSetting = $this->itemSetting[$name];
if (is_callable($itemSetting)) {
$item = $itemSetting();
} elseif (is_string($itemSetting) && class_exists($itemSetting)) {
$item = new $itemSetting;
} else {
$item = $itemSetting;
}
$this->items[$name] = $item;
return $item;
} | php | public function get($name)
{
if (isset($this->items[$name])) {
return $this->items[$name];
}
if (!isset($this->itemSetting[$name])) {
return null;
}
$itemSetting = $this->itemSetting[$name];
if (is_callable($itemSetting)) {
$item = $itemSetting();
} elseif (is_string($itemSetting) && class_exists($itemSetting)) {
$item = new $itemSetting;
} else {
$item = $itemSetting;
}
$this->items[$name] = $item;
return $item;
} | [
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"itemSetting",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"itemSetting",
"=",
"$",
"this",
"->",
"itemSetting",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"itemSetting",
")",
")",
"{",
"$",
"item",
"=",
"$",
"itemSetting",
"(",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"itemSetting",
")",
"&&",
"class_exists",
"(",
"$",
"itemSetting",
")",
")",
"{",
"$",
"item",
"=",
"new",
"$",
"itemSetting",
";",
"}",
"else",
"{",
"$",
"item",
"=",
"$",
"itemSetting",
";",
"}",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
"=",
"$",
"item",
";",
"return",
"$",
"item",
";",
"}"
] | Get an item from container
@param string $name name for desired item | [
"Get",
"an",
"item",
"from",
"container"
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L56-L77 | train |
CQD/minorwork | src/App.php | App.set | public function set($name, $value = null)
{
$values = is_array($name) ? $name : [$name => $value];
foreach ($values as $name => $value) {
$this->itemSetting[$name] = $value;
}
unset($this->items[$name]);
} | php | public function set($name, $value = null)
{
$values = is_array($name) ? $name : [$name => $value];
foreach ($values as $name => $value) {
$this->itemSetting[$name] = $value;
}
unset($this->items[$name]);
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"values",
"=",
"is_array",
"(",
"$",
"name",
")",
"?",
"$",
"name",
":",
"[",
"$",
"name",
"=>",
"$",
"value",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"itemSetting",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Set one or multiple items, or factory function of items, or class of items, into DI container. | [
"Set",
"one",
"or",
"multiple",
"items",
"or",
"factory",
"function",
"of",
"items",
"or",
"class",
"of",
"items",
"into",
"DI",
"container",
"."
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L87-L95 | train |
CQD/minorwork | src/App.php | App.setRouting | public function setRouting(array $routings = [])
{
$this->dispatcher = null;
$this->routings = $routings + $this->routings;
foreach ($this->routings as $name => &$routing) {
if (1 == count($routing)) {
array_unshift($routing, '/' . ltrim($name, '/'));
}
if (2 == count($routing)) {
array_unshift($routing, ['GET', 'POST']);
}
}
} | php | public function setRouting(array $routings = [])
{
$this->dispatcher = null;
$this->routings = $routings + $this->routings;
foreach ($this->routings as $name => &$routing) {
if (1 == count($routing)) {
array_unshift($routing, '/' . ltrim($name, '/'));
}
if (2 == count($routing)) {
array_unshift($routing, ['GET', 'POST']);
}
}
} | [
"public",
"function",
"setRouting",
"(",
"array",
"$",
"routings",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"dispatcher",
"=",
"null",
";",
"$",
"this",
"->",
"routings",
"=",
"$",
"routings",
"+",
"$",
"this",
"->",
"routings",
";",
"foreach",
"(",
"$",
"this",
"->",
"routings",
"as",
"$",
"name",
"=>",
"&",
"$",
"routing",
")",
"{",
"if",
"(",
"1",
"==",
"count",
"(",
"$",
"routing",
")",
")",
"{",
"array_unshift",
"(",
"$",
"routing",
",",
"'/'",
".",
"ltrim",
"(",
"$",
"name",
",",
"'/'",
")",
")",
";",
"}",
"if",
"(",
"2",
"==",
"count",
"(",
"$",
"routing",
")",
")",
"{",
"array_unshift",
"(",
"$",
"routing",
",",
"[",
"'GET'",
",",
"'POST'",
"]",
")",
";",
"}",
"}",
"}"
] | Set app routing.
TODO group routing support | [
"Set",
"app",
"routing",
"."
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L107-L120 | train |
CQD/minorwork | src/App.php | App.handlerAlias | public function handlerAlias($name, $value = null)
{
$alias = is_array($name) ? $name : [$name => $value];
$this->handlerAlias = $alias + $this->handlerAlias;
} | php | public function handlerAlias($name, $value = null)
{
$alias = is_array($name) ? $name : [$name => $value];
$this->handlerAlias = $alias + $this->handlerAlias;
} | [
"public",
"function",
"handlerAlias",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"alias",
"=",
"is_array",
"(",
"$",
"name",
")",
"?",
"$",
"name",
":",
"[",
"$",
"name",
"=>",
"$",
"value",
"]",
";",
"$",
"this",
"->",
"handlerAlias",
"=",
"$",
"alias",
"+",
"$",
"this",
"->",
"handlerAlias",
";",
"}"
] | Set alias name for request handlers | [
"Set",
"alias",
"name",
"for",
"request",
"handlers"
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L125-L129 | train |
CQD/minorwork | src/App.php | App.route | public function route($method, $uri)
{
// Remove subfolder from URI if needed
$baseDir = $this->get('___.baseDir');
if ("/" !== $baseDir && 0 === strpos($uri, $baseDir)) {
$uri = substr($uri, strlen($baseDir));
}
// Check which route is being used.
$routings = $this->routings;
$this->dispatcher = $this->dispatcher ?: \FastRoute\simpleDispatcher(function(\FastRoute\RouteCollector $r) use ($routings) {
foreach ($routings as $name => $routing) {
// 'GET', '/user/{id:\d+}', $routeName
$r->addRoute($routing[0], $routing[1], $name);
}
});
$routeInfo = $this->dispatcher->dispatch($method, $uri);
if (\FastRoute\Dispatcher::FOUND === $routeInfo[0]) {
return array_slice($routeInfo, 1);
}
return null;
} | php | public function route($method, $uri)
{
// Remove subfolder from URI if needed
$baseDir = $this->get('___.baseDir');
if ("/" !== $baseDir && 0 === strpos($uri, $baseDir)) {
$uri = substr($uri, strlen($baseDir));
}
// Check which route is being used.
$routings = $this->routings;
$this->dispatcher = $this->dispatcher ?: \FastRoute\simpleDispatcher(function(\FastRoute\RouteCollector $r) use ($routings) {
foreach ($routings as $name => $routing) {
// 'GET', '/user/{id:\d+}', $routeName
$r->addRoute($routing[0], $routing[1], $name);
}
});
$routeInfo = $this->dispatcher->dispatch($method, $uri);
if (\FastRoute\Dispatcher::FOUND === $routeInfo[0]) {
return array_slice($routeInfo, 1);
}
return null;
} | [
"public",
"function",
"route",
"(",
"$",
"method",
",",
"$",
"uri",
")",
"{",
"// Remove subfolder from URI if needed",
"$",
"baseDir",
"=",
"$",
"this",
"->",
"get",
"(",
"'___.baseDir'",
")",
";",
"if",
"(",
"\"/\"",
"!==",
"$",
"baseDir",
"&&",
"0",
"===",
"strpos",
"(",
"$",
"uri",
",",
"$",
"baseDir",
")",
")",
"{",
"$",
"uri",
"=",
"substr",
"(",
"$",
"uri",
",",
"strlen",
"(",
"$",
"baseDir",
")",
")",
";",
"}",
"// Check which route is being used.",
"$",
"routings",
"=",
"$",
"this",
"->",
"routings",
";",
"$",
"this",
"->",
"dispatcher",
"=",
"$",
"this",
"->",
"dispatcher",
"?",
":",
"\\",
"FastRoute",
"\\",
"simpleDispatcher",
"(",
"function",
"(",
"\\",
"FastRoute",
"\\",
"RouteCollector",
"$",
"r",
")",
"use",
"(",
"$",
"routings",
")",
"{",
"foreach",
"(",
"$",
"routings",
"as",
"$",
"name",
"=>",
"$",
"routing",
")",
"{",
"// 'GET', '/user/{id:\\d+}', $routeName",
"$",
"r",
"->",
"addRoute",
"(",
"$",
"routing",
"[",
"0",
"]",
",",
"$",
"routing",
"[",
"1",
"]",
",",
"$",
"name",
")",
";",
"}",
"}",
")",
";",
"$",
"routeInfo",
"=",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"$",
"method",
",",
"$",
"uri",
")",
";",
"if",
"(",
"\\",
"FastRoute",
"\\",
"Dispatcher",
"::",
"FOUND",
"===",
"$",
"routeInfo",
"[",
"0",
"]",
")",
"{",
"return",
"array_slice",
"(",
"$",
"routeInfo",
",",
"1",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Determin which route to use and parameters in uri.
@param string $method HTTP Method used
@param string $uri request path, without query string
@return array|null [$routeName, $params] | [
"Determin",
"which",
"route",
"to",
"use",
"and",
"parameters",
"in",
"uri",
"."
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L146-L170 | train |
CQD/minorwork | src/App.php | App.patternToPath | private function patternToPath($pattern, $params)
{
// Inspired by https://github.com/nikic/FastRoute/issues/66
// but uses named params, don't care param order and size
$routeParser = new RouteParserStd;
$routes = $routeParser->parse($pattern);
// check from the longest route to the shortest route
// first (longest) full match is the route we need
for ($i = count($routes) - 1; $i >= 0; $i--) {
$url = '';
foreach ($routes[$i] as $part) {
// replace placeholder to actual value
if (is_array($part)) {
$part = @$params[$part[0]];
}
// if route contains part not defined in $params, abandan this route
if (null === $part) {
continue 2;
}
$url .= $part;
}
// first full match, this is our hero url
return $url;
}
// no full match, throw Exception
throw new \Exception(sprintf("Can't make path for '%s' with param: %s.", $pattern, json_encode($params)));
} | php | private function patternToPath($pattern, $params)
{
// Inspired by https://github.com/nikic/FastRoute/issues/66
// but uses named params, don't care param order and size
$routeParser = new RouteParserStd;
$routes = $routeParser->parse($pattern);
// check from the longest route to the shortest route
// first (longest) full match is the route we need
for ($i = count($routes) - 1; $i >= 0; $i--) {
$url = '';
foreach ($routes[$i] as $part) {
// replace placeholder to actual value
if (is_array($part)) {
$part = @$params[$part[0]];
}
// if route contains part not defined in $params, abandan this route
if (null === $part) {
continue 2;
}
$url .= $part;
}
// first full match, this is our hero url
return $url;
}
// no full match, throw Exception
throw new \Exception(sprintf("Can't make path for '%s' with param: %s.", $pattern, json_encode($params)));
} | [
"private",
"function",
"patternToPath",
"(",
"$",
"pattern",
",",
"$",
"params",
")",
"{",
"// Inspired by https://github.com/nikic/FastRoute/issues/66",
"// but uses named params, don't care param order and size",
"$",
"routeParser",
"=",
"new",
"RouteParserStd",
";",
"$",
"routes",
"=",
"$",
"routeParser",
"->",
"parse",
"(",
"$",
"pattern",
")",
";",
"// check from the longest route to the shortest route",
"// first (longest) full match is the route we need",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"routes",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"$",
"url",
"=",
"''",
";",
"foreach",
"(",
"$",
"routes",
"[",
"$",
"i",
"]",
"as",
"$",
"part",
")",
"{",
"// replace placeholder to actual value",
"if",
"(",
"is_array",
"(",
"$",
"part",
")",
")",
"{",
"$",
"part",
"=",
"@",
"$",
"params",
"[",
"$",
"part",
"[",
"0",
"]",
"]",
";",
"}",
"// if route contains part not defined in $params, abandan this route",
"if",
"(",
"null",
"===",
"$",
"part",
")",
"{",
"continue",
"2",
";",
"}",
"$",
"url",
".=",
"$",
"part",
";",
"}",
"// first full match, this is our hero url",
"return",
"$",
"url",
";",
"}",
"// no full match, throw Exception",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"\"Can't make path for '%s' with param: %s.\"",
",",
"$",
"pattern",
",",
"json_encode",
"(",
"$",
"params",
")",
")",
")",
";",
"}"
] | Convert url pattern to actual path | [
"Convert",
"url",
"pattern",
"to",
"actual",
"path"
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L218-L248 | train |
CQD/minorwork | src/App.php | App.run | public function run($options = [])
{
$method = @$options['method'] ?: $_SERVER['REQUEST_METHOD'];
$uri = @$options['uri'] ?: rawurldecode($_SERVER['REQUEST_URI']);
if (false !== $pos = strpos($uri, '?')) {
$uri = substr($uri, 0, $pos);
}
$routeInfo = $this->route($method, $uri);
if (!$routeInfo) {
$routeInfo = ['default', []];
}
list($routeName, $params) = $routeInfo;
try {
return $this->runAs($routeName, $params);
} catch (\Exception $e) {
$params[] = $e;
return $this->runAs('defaultError', $params);
}
} | php | public function run($options = [])
{
$method = @$options['method'] ?: $_SERVER['REQUEST_METHOD'];
$uri = @$options['uri'] ?: rawurldecode($_SERVER['REQUEST_URI']);
if (false !== $pos = strpos($uri, '?')) {
$uri = substr($uri, 0, $pos);
}
$routeInfo = $this->route($method, $uri);
if (!$routeInfo) {
$routeInfo = ['default', []];
}
list($routeName, $params) = $routeInfo;
try {
return $this->runAs($routeName, $params);
} catch (\Exception $e) {
$params[] = $e;
return $this->runAs('defaultError', $params);
}
} | [
"public",
"function",
"run",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"method",
"=",
"@",
"$",
"options",
"[",
"'method'",
"]",
"?",
":",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
";",
"$",
"uri",
"=",
"@",
"$",
"options",
"[",
"'uri'",
"]",
"?",
":",
"rawurldecode",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"uri",
",",
"'?'",
")",
")",
"{",
"$",
"uri",
"=",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"$",
"pos",
")",
";",
"}",
"$",
"routeInfo",
"=",
"$",
"this",
"->",
"route",
"(",
"$",
"method",
",",
"$",
"uri",
")",
";",
"if",
"(",
"!",
"$",
"routeInfo",
")",
"{",
"$",
"routeInfo",
"=",
"[",
"'default'",
",",
"[",
"]",
"]",
";",
"}",
"list",
"(",
"$",
"routeName",
",",
"$",
"params",
")",
"=",
"$",
"routeInfo",
";",
"try",
"{",
"return",
"$",
"this",
"->",
"runAs",
"(",
"$",
"routeName",
",",
"$",
"params",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"e",
";",
"return",
"$",
"this",
"->",
"runAs",
"(",
"'defaultError'",
",",
"$",
"params",
")",
";",
"}",
"}"
] | Entry point for application | [
"Entry",
"point",
"for",
"application"
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L253-L275 | train |
CQD/minorwork | src/App.php | App.runAs | public function runAs($routeName, $params = [])
{
if (!isset($this->routings[$routeName])) {
throw new \Exception("Route name '{$routeName}' not found!");
}
// populate handler queue
$handler = end($this->routings[$routeName]);
$this->appendHandlerQueue($handler);
// Run everything in handler queue
$output = null;
while ($handler = array_shift($this->handlerQueue)) {
$output = $this->executeHandler($handler, $params, $output);
}
echo $this->get('view');
return $output;
} | php | public function runAs($routeName, $params = [])
{
if (!isset($this->routings[$routeName])) {
throw new \Exception("Route name '{$routeName}' not found!");
}
// populate handler queue
$handler = end($this->routings[$routeName]);
$this->appendHandlerQueue($handler);
// Run everything in handler queue
$output = null;
while ($handler = array_shift($this->handlerQueue)) {
$output = $this->executeHandler($handler, $params, $output);
}
echo $this->get('view');
return $output;
} | [
"public",
"function",
"runAs",
"(",
"$",
"routeName",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"routings",
"[",
"$",
"routeName",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Route name '{$routeName}' not found!\"",
")",
";",
"}",
"// populate handler queue",
"$",
"handler",
"=",
"end",
"(",
"$",
"this",
"->",
"routings",
"[",
"$",
"routeName",
"]",
")",
";",
"$",
"this",
"->",
"appendHandlerQueue",
"(",
"$",
"handler",
")",
";",
"// Run everything in handler queue",
"$",
"output",
"=",
"null",
";",
"while",
"(",
"$",
"handler",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"handlerQueue",
")",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"executeHandler",
"(",
"$",
"handler",
",",
"$",
"params",
",",
"$",
"output",
")",
";",
"}",
"echo",
"$",
"this",
"->",
"get",
"(",
"'view'",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Handle current request using specificed route handler | [
"Handle",
"current",
"request",
"using",
"specificed",
"route",
"handler"
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L280-L298 | train |
CQD/minorwork | src/App.php | App.executeHandler | public function executeHandler($handler, $params, $prevOutput = null)
{
// a function(-ish) thing which can be called
if (is_callable($handler)) {
return $handler($this, $params, $prevOutput);
}
// aliased handler
if ($actualHandler = @$this->handlerAlias[$handler]) {
return $this->executeHandler($actualHandler, $params, $prevOutput);
}
// only callable and controller/method pair (`:` seprated string) can be accepted
if (!is_string($handler)) {
$type = gettype($handler);
throw new \Exception("'{$type}' can not be used as handler, should be a callable or controller/method pair!");
}
if (false === $pos = strpos($handler, ':')) {
throw new \Exception("Can not parse '{$handler}' for corresponding controller/method!");
}
// controller/method pair
list($class, $method) = explode(':', $handler, 2);
$class = $this->handlerClassPrefix ? "{$this->handlerClassPrefix}{$class}" : $class;
$controller = new $class;
return $controller->$method($this, $params, $prevOutput);
} | php | public function executeHandler($handler, $params, $prevOutput = null)
{
// a function(-ish) thing which can be called
if (is_callable($handler)) {
return $handler($this, $params, $prevOutput);
}
// aliased handler
if ($actualHandler = @$this->handlerAlias[$handler]) {
return $this->executeHandler($actualHandler, $params, $prevOutput);
}
// only callable and controller/method pair (`:` seprated string) can be accepted
if (!is_string($handler)) {
$type = gettype($handler);
throw new \Exception("'{$type}' can not be used as handler, should be a callable or controller/method pair!");
}
if (false === $pos = strpos($handler, ':')) {
throw new \Exception("Can not parse '{$handler}' for corresponding controller/method!");
}
// controller/method pair
list($class, $method) = explode(':', $handler, 2);
$class = $this->handlerClassPrefix ? "{$this->handlerClassPrefix}{$class}" : $class;
$controller = new $class;
return $controller->$method($this, $params, $prevOutput);
} | [
"public",
"function",
"executeHandler",
"(",
"$",
"handler",
",",
"$",
"params",
",",
"$",
"prevOutput",
"=",
"null",
")",
"{",
"// a function(-ish) thing which can be called",
"if",
"(",
"is_callable",
"(",
"$",
"handler",
")",
")",
"{",
"return",
"$",
"handler",
"(",
"$",
"this",
",",
"$",
"params",
",",
"$",
"prevOutput",
")",
";",
"}",
"// aliased handler",
"if",
"(",
"$",
"actualHandler",
"=",
"@",
"$",
"this",
"->",
"handlerAlias",
"[",
"$",
"handler",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"executeHandler",
"(",
"$",
"actualHandler",
",",
"$",
"params",
",",
"$",
"prevOutput",
")",
";",
"}",
"// only callable and controller/method pair (`:` seprated string) can be accepted",
"if",
"(",
"!",
"is_string",
"(",
"$",
"handler",
")",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"handler",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"\"'{$type}' can not be used as handler, should be a callable or controller/method pair!\"",
")",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"handler",
",",
"':'",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not parse '{$handler}' for corresponding controller/method!\"",
")",
";",
"}",
"// controller/method pair",
"list",
"(",
"$",
"class",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"handler",
",",
"2",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"handlerClassPrefix",
"?",
"\"{$this->handlerClassPrefix}{$class}\"",
":",
"$",
"class",
";",
"$",
"controller",
"=",
"new",
"$",
"class",
";",
"return",
"$",
"controller",
"->",
"$",
"method",
"(",
"$",
"this",
",",
"$",
"params",
",",
"$",
"prevOutput",
")",
";",
"}"
] | Parse and execute request handler | [
"Parse",
"and",
"execute",
"request",
"handler"
] | 281ad61cf350603bdf026a36c98b32c70e728297 | https://github.com/CQD/minorwork/blob/281ad61cf350603bdf026a36c98b32c70e728297/src/App.php#L335-L362 | train |
Steveorevo/GString | src/GString.php | GString.hashCode | public function hashCode() {
$h = $this->hash;
$l = $this->length();
if ( $h == 0 && $l > 0 ) {
for ( $i = 0; $i < $l; $i ++ ) {
$h = (int) ( 31 * $h + $this->charCodeAt( $i ) );
}
$this->hash = $h;
}
return $h;
} | php | public function hashCode() {
$h = $this->hash;
$l = $this->length();
if ( $h == 0 && $l > 0 ) {
for ( $i = 0; $i < $l; $i ++ ) {
$h = (int) ( 31 * $h + $this->charCodeAt( $i ) );
}
$this->hash = $h;
}
return $h;
} | [
"public",
"function",
"hashCode",
"(",
")",
"{",
"$",
"h",
"=",
"$",
"this",
"->",
"hash",
";",
"$",
"l",
"=",
"$",
"this",
"->",
"length",
"(",
")",
";",
"if",
"(",
"$",
"h",
"==",
"0",
"&&",
"$",
"l",
">",
"0",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"l",
";",
"$",
"i",
"++",
")",
"{",
"$",
"h",
"=",
"(",
"int",
")",
"(",
"31",
"*",
"$",
"h",
"+",
"$",
"this",
"->",
"charCodeAt",
"(",
"$",
"i",
")",
")",
";",
"}",
"$",
"this",
"->",
"hash",
"=",
"$",
"h",
";",
"}",
"return",
"$",
"h",
";",
"}"
] | Returns a hash code for this string.
@access public
@return int a hash code for this string. | [
"Returns",
"a",
"hash",
"code",
"for",
"this",
"string",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L246-L257 | train |
Steveorevo/GString | src/GString.php | GString.indexOf | public function indexOf( $sequence, $fromIndex = 0, $ignoreCase = false ) {
if ( $fromIndex < 0 ) {
$fromIndex = 0;
} else if ( $fromIndex >= $this->length() ) {
return - 1;
}
if ( $ignoreCase == false ) {
$index = strpos( $this->value, $sequence, $fromIndex );
} else {
$index = stripos( $this->value, $sequence, $fromIndex );
}
return $index === false ? - 1 : $index;
} | php | public function indexOf( $sequence, $fromIndex = 0, $ignoreCase = false ) {
if ( $fromIndex < 0 ) {
$fromIndex = 0;
} else if ( $fromIndex >= $this->length() ) {
return - 1;
}
if ( $ignoreCase == false ) {
$index = strpos( $this->value, $sequence, $fromIndex );
} else {
$index = stripos( $this->value, $sequence, $fromIndex );
}
return $index === false ? - 1 : $index;
} | [
"public",
"function",
"indexOf",
"(",
"$",
"sequence",
",",
"$",
"fromIndex",
"=",
"0",
",",
"$",
"ignoreCase",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"fromIndex",
"<",
"0",
")",
"{",
"$",
"fromIndex",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"$",
"fromIndex",
">=",
"$",
"this",
"->",
"length",
"(",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"$",
"ignoreCase",
"==",
"false",
")",
"{",
"$",
"index",
"=",
"strpos",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"sequence",
",",
"$",
"fromIndex",
")",
";",
"}",
"else",
"{",
"$",
"index",
"=",
"stripos",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"sequence",
",",
"$",
"fromIndex",
")",
";",
"}",
"return",
"$",
"index",
"===",
"false",
"?",
"-",
"1",
":",
"$",
"index",
";",
"}"
] | Returns the index within this string of the first occurrence of the specified
string, optionally starting the search at the specified index.
@access public
@param string $sequence A string
@param int $fromIndex The index to start the search from
@param boolean $ignoreCase If true, ignore case
@return int the index of the first occurrence of the sequence. | [
"Returns",
"the",
"index",
"within",
"this",
"string",
"of",
"the",
"first",
"occurrence",
"of",
"the",
"specified",
"string",
"optionally",
"starting",
"the",
"search",
"at",
"the",
"specified",
"index",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L271-L284 | train |
Steveorevo/GString | src/GString.php | GString.lastIndexOf | public function lastIndexOf( $sequence, $fromIndex = 0, $ignoreCase = false ) {
if ( $fromIndex < 0 ) {
$fromIndex = 0;
} else if ( $fromIndex >= $this->length() ) {
return - 1;
}
if ( $ignoreCase == false ) {
$index = strrpos( $this->value, $sequence, $fromIndex );
} else {
$index = strripos( $this->value, $sequence, $fromIndex );
}
return $index === false ? - 1 : $index;
} | php | public function lastIndexOf( $sequence, $fromIndex = 0, $ignoreCase = false ) {
if ( $fromIndex < 0 ) {
$fromIndex = 0;
} else if ( $fromIndex >= $this->length() ) {
return - 1;
}
if ( $ignoreCase == false ) {
$index = strrpos( $this->value, $sequence, $fromIndex );
} else {
$index = strripos( $this->value, $sequence, $fromIndex );
}
return $index === false ? - 1 : $index;
} | [
"public",
"function",
"lastIndexOf",
"(",
"$",
"sequence",
",",
"$",
"fromIndex",
"=",
"0",
",",
"$",
"ignoreCase",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"fromIndex",
"<",
"0",
")",
"{",
"$",
"fromIndex",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"$",
"fromIndex",
">=",
"$",
"this",
"->",
"length",
"(",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"$",
"ignoreCase",
"==",
"false",
")",
"{",
"$",
"index",
"=",
"strrpos",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"sequence",
",",
"$",
"fromIndex",
")",
";",
"}",
"else",
"{",
"$",
"index",
"=",
"strripos",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"sequence",
",",
"$",
"fromIndex",
")",
";",
"}",
"return",
"$",
"index",
"===",
"false",
"?",
"-",
"1",
":",
"$",
"index",
";",
"}"
] | Returns the index within this string of the last occurrence of the specified
string, searching backward starting at the specified index.
@access public
@param string $sequence A string
@param int $fromIndex The index to start the search from
@param boolean $ignoreCase If true, ignore case
@return int the index of the first occurrence of the sequence. | [
"Returns",
"the",
"index",
"within",
"this",
"string",
"of",
"the",
"last",
"occurrence",
"of",
"the",
"specified",
"string",
"searching",
"backward",
"starting",
"at",
"the",
"specified",
"index",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L338-L351 | train |
Steveorevo/GString | src/GString.php | GString.matches | public function matches( $regex, & $matches = null ) {
$match = preg_match( $regex, $this->value, $matches );
for ( $i = 0, $l = count( $matches ); $i < $l; $i ++ ) {
$matches[ $i ] = new GString( $matches[ $i ] );
}
return $match == 1;
} | php | public function matches( $regex, & $matches = null ) {
$match = preg_match( $regex, $this->value, $matches );
for ( $i = 0, $l = count( $matches ); $i < $l; $i ++ ) {
$matches[ $i ] = new GString( $matches[ $i ] );
}
return $match == 1;
} | [
"public",
"function",
"matches",
"(",
"$",
"regex",
",",
"&",
"$",
"matches",
"=",
"null",
")",
"{",
"$",
"match",
"=",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"this",
"->",
"value",
",",
"$",
"matches",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"l",
"=",
"count",
"(",
"$",
"matches",
")",
";",
"$",
"i",
"<",
"$",
"l",
";",
"$",
"i",
"++",
")",
"{",
"$",
"matches",
"[",
"$",
"i",
"]",
"=",
"new",
"GString",
"(",
"$",
"matches",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"$",
"match",
"==",
"1",
";",
"}"
] | Tells whether or not this string matches the given regular expression.
@access public
@param string $regex The regular expression to which this string is to be matched
@param array $matches This will be set to the results of the search
@return boolean true if the string matches the given regular expression. | [
"Tells",
"whether",
"or",
"not",
"this",
"string",
"matches",
"the",
"given",
"regular",
"expression",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L389-L396 | train |
Steveorevo/GString | src/GString.php | GString.padLeft | public function padLeft( $length, $padString ) {
return new GString( str_pad( $this->value, $length, $padString, STR_PAD_LEFT ) );
} | php | public function padLeft( $length, $padString ) {
return new GString( str_pad( $this->value, $length, $padString, STR_PAD_LEFT ) );
} | [
"public",
"function",
"padLeft",
"(",
"$",
"length",
",",
"$",
"padString",
")",
"{",
"return",
"new",
"GString",
"(",
"str_pad",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"length",
",",
"$",
"padString",
",",
"STR_PAD_LEFT",
")",
")",
";",
"}"
] | Returns the left padded string to a certain length with the specified string.
@access public
@param int $length The length to pad the string to
@param string $padString The string to pad with
@return \String the resulting string. | [
"Returns",
"the",
"left",
"padded",
"string",
"to",
"a",
"certain",
"length",
"with",
"the",
"specified",
"string",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L408-L410 | train |
Steveorevo/GString | src/GString.php | GString.padRight | public function padRight( $length, $padString ) {
return new GString( str_pad( $this->value, $length, $padString, STR_PAD_RIGHT ) );
} | php | public function padRight( $length, $padString ) {
return new GString( str_pad( $this->value, $length, $padString, STR_PAD_RIGHT ) );
} | [
"public",
"function",
"padRight",
"(",
"$",
"length",
",",
"$",
"padString",
")",
"{",
"return",
"new",
"GString",
"(",
"str_pad",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"length",
",",
"$",
"padString",
",",
"STR_PAD_RIGHT",
")",
")",
";",
"}"
] | Returns the right padded string to a certain length with the specified string.
@access public
@param int $length The length to pad the string to
@param string $padString The string to pad with
@return \String the resulting string. | [
"Returns",
"the",
"right",
"padded",
"string",
"to",
"a",
"certain",
"length",
"with",
"the",
"specified",
"string",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L422-L424 | train |
Steveorevo/GString | src/GString.php | GString.regionCompare | public function regionCompare( $offseta, $str, $offsetb, $length, $ignoreCase = false ) {
$a = $this->substring( $offseta );
$b = new GString( $str );
$b = $b->substring( $offsetb );
if ( $ignoreCase == false ) {
return strncmp( $a, $b, $length );
} else {
return strncasecmp( $a, $b, $length );
}
} | php | public function regionCompare( $offseta, $str, $offsetb, $length, $ignoreCase = false ) {
$a = $this->substring( $offseta );
$b = new GString( $str );
$b = $b->substring( $offsetb );
if ( $ignoreCase == false ) {
return strncmp( $a, $b, $length );
} else {
return strncasecmp( $a, $b, $length );
}
} | [
"public",
"function",
"regionCompare",
"(",
"$",
"offseta",
",",
"$",
"str",
",",
"$",
"offsetb",
",",
"$",
"length",
",",
"$",
"ignoreCase",
"=",
"false",
")",
"{",
"$",
"a",
"=",
"$",
"this",
"->",
"substring",
"(",
"$",
"offseta",
")",
";",
"$",
"b",
"=",
"new",
"GString",
"(",
"$",
"str",
")",
";",
"$",
"b",
"=",
"$",
"b",
"->",
"substring",
"(",
"$",
"offsetb",
")",
";",
"if",
"(",
"$",
"ignoreCase",
"==",
"false",
")",
"{",
"return",
"strncmp",
"(",
"$",
"a",
",",
"$",
"b",
",",
"$",
"length",
")",
";",
"}",
"else",
"{",
"return",
"strncasecmp",
"(",
"$",
"a",
",",
"$",
"b",
",",
"$",
"length",
")",
";",
"}",
"}"
] | Compare two string regions.
@access public
@param int $offseta The starting offset of the subregion in this string
@param string $str The string argument
@param int $offsetb The starting offset of the subregion in the string argument
@param int $length The number of characters to compare
@param boolean $ignoreCase If true, ignore case
@return int the value 0 if regions are equal, 1 or -1. | [
"Compare",
"two",
"string",
"regions",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L439-L448 | train |
Steveorevo/GString | src/GString.php | GString.regionCompareIgnoreCase | public function regionCompareIgnoreCase( $offseta, $str, $offsetb, $length ) {
return $this->regionCompare( $offseta, $str, $offsetb, $length, true );
} | php | public function regionCompareIgnoreCase( $offseta, $str, $offsetb, $length ) {
return $this->regionCompare( $offseta, $str, $offsetb, $length, true );
} | [
"public",
"function",
"regionCompareIgnoreCase",
"(",
"$",
"offseta",
",",
"$",
"str",
",",
"$",
"offsetb",
",",
"$",
"length",
")",
"{",
"return",
"$",
"this",
"->",
"regionCompare",
"(",
"$",
"offseta",
",",
"$",
"str",
",",
"$",
"offsetb",
",",
"$",
"length",
",",
"true",
")",
";",
"}"
] | Compare two string regions, ignoring case differences.
@access public
@param int $offseta The starting offset of the subregion in this string
@param string $str The string argument
@param int $offsetb The starting offset of the subregion in the string argument
@param int $length The number of characters to compare
@return int the value 0 if regions are equal, 1 or -1. | [
"Compare",
"two",
"string",
"regions",
"ignoring",
"case",
"differences",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L462-L464 | train |
Steveorevo/GString | src/GString.php | GString.regionMatches | public function regionMatches( $offseta, $str, $offsetb, $length ) {
return $this->regionCompare( $offseta, $str, $offsetb, $length ) == 0;
} | php | public function regionMatches( $offseta, $str, $offsetb, $length ) {
return $this->regionCompare( $offseta, $str, $offsetb, $length ) == 0;
} | [
"public",
"function",
"regionMatches",
"(",
"$",
"offseta",
",",
"$",
"str",
",",
"$",
"offsetb",
",",
"$",
"length",
")",
"{",
"return",
"$",
"this",
"->",
"regionCompare",
"(",
"$",
"offseta",
",",
"$",
"str",
",",
"$",
"offsetb",
",",
"$",
"length",
")",
"==",
"0",
";",
"}"
] | Tests if two string regions are equal.
@access public
@param int $offseta The starting offset of the subregion in this string
@param string $str The string argument
@param int $offsetb The starting offset of the subregion in the string argument
@param int $length The number of characters to compare
@return bool true if the regions match. | [
"Tests",
"if",
"two",
"string",
"regions",
"are",
"equal",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L478-L480 | train |
Steveorevo/GString | src/GString.php | GString.regionMatchesIgnoreCase | public function regionMatchesIgnoreCase( $offseta, $str, $offsetb, $length ) {
return $this->regionCompareIgnoreCase( $offseta, $str, $offsetb, $length ) == 0;
} | php | public function regionMatchesIgnoreCase( $offseta, $str, $offsetb, $length ) {
return $this->regionCompareIgnoreCase( $offseta, $str, $offsetb, $length ) == 0;
} | [
"public",
"function",
"regionMatchesIgnoreCase",
"(",
"$",
"offseta",
",",
"$",
"str",
",",
"$",
"offsetb",
",",
"$",
"length",
")",
"{",
"return",
"$",
"this",
"->",
"regionCompareIgnoreCase",
"(",
"$",
"offseta",
",",
"$",
"str",
",",
"$",
"offsetb",
",",
"$",
"length",
")",
"==",
"0",
";",
"}"
] | Tests if two string regions are equal, ignoring case differences.
@access public
@param int $offseta The starting offset of the subregion in this string
@param string $str The string argument
@param int $offsetb The starting offset of the subregion in the string argument
@param int $length The number of characters to compare
@return bool true if the regions match. | [
"Tests",
"if",
"two",
"string",
"regions",
"are",
"equal",
"ignoring",
"case",
"differences",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L494-L496 | train |
Steveorevo/GString | src/GString.php | GString.replace | public function replace( $search, $replacement, & $count = 0 ) {
return new GString( str_replace( $search, $replacement, $this->value, $count ) );
} | php | public function replace( $search, $replacement, & $count = 0 ) {
return new GString( str_replace( $search, $replacement, $this->value, $count ) );
} | [
"public",
"function",
"replace",
"(",
"$",
"search",
",",
"$",
"replacement",
",",
"&",
"$",
"count",
"=",
"0",
")",
"{",
"return",
"new",
"GString",
"(",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"value",
",",
"$",
"count",
")",
")",
";",
"}"
] | Returns a new GString resulting from replacing all occurrences of the search
string with the replacement string.
@access public
@param string $search The old string
@param string $replacement The new GString
@param int $count This will be set to the number of replacements performed
@return \String the resulting string. | [
"Returns",
"a",
"new",
"GString",
"resulting",
"from",
"replacing",
"all",
"occurrences",
"of",
"the",
"search",
"string",
"with",
"the",
"replacement",
"string",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L510-L512 | train |
Steveorevo/GString | src/GString.php | GString.replaceAll | public function replaceAll( $regex, $replacement, $limit = - 1, & $count = 0 ) {
return new GString( preg_replace( $regex, $replacement, $this->value, $limit, $count ) );
} | php | public function replaceAll( $regex, $replacement, $limit = - 1, & $count = 0 ) {
return new GString( preg_replace( $regex, $replacement, $this->value, $limit, $count ) );
} | [
"public",
"function",
"replaceAll",
"(",
"$",
"regex",
",",
"$",
"replacement",
",",
"$",
"limit",
"=",
"-",
"1",
",",
"&",
"$",
"count",
"=",
"0",
")",
"{",
"return",
"new",
"GString",
"(",
"preg_replace",
"(",
"$",
"regex",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"value",
",",
"$",
"limit",
",",
"$",
"count",
")",
")",
";",
"}"
] | Replaces each substring of this string that matches the given regular
expression with the given replacement.
@access public
@param string $regex The regular expression to which this string is to be matched
@param string $replacement The string to be substituted for each match
@param int $limit The limit threshold
@param int $count This will be set to the number of replacements performed
@return \String the resulting string. | [
"Replaces",
"each",
"substring",
"of",
"this",
"string",
"that",
"matches",
"the",
"given",
"regular",
"expression",
"with",
"the",
"given",
"replacement",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L527-L529 | train |
Steveorevo/GString | src/GString.php | GString.replaceIgnoreCase | public function replaceIgnoreCase( $search, $replacement, & $count = 0 ) {
return new GString( str_ireplace( $search, $replacement, $this->value, $count ) );
} | php | public function replaceIgnoreCase( $search, $replacement, & $count = 0 ) {
return new GString( str_ireplace( $search, $replacement, $this->value, $count ) );
} | [
"public",
"function",
"replaceIgnoreCase",
"(",
"$",
"search",
",",
"$",
"replacement",
",",
"&",
"$",
"count",
"=",
"0",
")",
"{",
"return",
"new",
"GString",
"(",
"str_ireplace",
"(",
"$",
"search",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"value",
",",
"$",
"count",
")",
")",
";",
"}"
] | Returns a new GString resulting from replacing all occurrences of the search
string with the replacement string, ignoring case differences.
@access public
@param string $search The old string
@param string $replacement The new GString
@param int $count This will be set to the number of replacements performed
@return \String the resulting string. | [
"Returns",
"a",
"new",
"GString",
"resulting",
"from",
"replacing",
"all",
"occurrences",
"of",
"the",
"search",
"string",
"with",
"the",
"replacement",
"string",
"ignoring",
"case",
"differences",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L558-L560 | train |
Steveorevo/GString | src/GString.php | GString.split | public function split( $regex, $limit = - 1 ) {
$parts = preg_split( $regex, $this->value, $limit );
for ( $i = 0, $l = count( $parts ); $i < $l; $i ++ ) {
$parts[ $i ] = new GString( $parts[ $i ] );
}
return $parts;
} | php | public function split( $regex, $limit = - 1 ) {
$parts = preg_split( $regex, $this->value, $limit );
for ( $i = 0, $l = count( $parts ); $i < $l; $i ++ ) {
$parts[ $i ] = new GString( $parts[ $i ] );
}
return $parts;
} | [
"public",
"function",
"split",
"(",
"$",
"regex",
",",
"$",
"limit",
"=",
"-",
"1",
")",
"{",
"$",
"parts",
"=",
"preg_split",
"(",
"$",
"regex",
",",
"$",
"this",
"->",
"value",
",",
"$",
"limit",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"l",
"=",
"count",
"(",
"$",
"parts",
")",
";",
"$",
"i",
"<",
"$",
"l",
";",
"$",
"i",
"++",
")",
"{",
"$",
"parts",
"[",
"$",
"i",
"]",
"=",
"new",
"GString",
"(",
"$",
"parts",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"$",
"parts",
";",
"}"
] | Splits this string around matches of the given regular expression.
@access public
@param string $regex The delimiting regular expression
@param int $limit The result threshold
@return array the resulting array of strings. | [
"Splits",
"this",
"string",
"around",
"matches",
"of",
"the",
"given",
"regular",
"expression",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L582-L589 | train |
Steveorevo/GString | src/GString.php | GString.startsWith | public function startsWith( $prefix, $fromIndex = 0 ) {
$pattern = "/^" . preg_quote( $prefix ) . "/";
return $this->substring( $fromIndex )->matches( $pattern );
} | php | public function startsWith( $prefix, $fromIndex = 0 ) {
$pattern = "/^" . preg_quote( $prefix ) . "/";
return $this->substring( $fromIndex )->matches( $pattern );
} | [
"public",
"function",
"startsWith",
"(",
"$",
"prefix",
",",
"$",
"fromIndex",
"=",
"0",
")",
"{",
"$",
"pattern",
"=",
"\"/^\"",
".",
"preg_quote",
"(",
"$",
"prefix",
")",
".",
"\"/\"",
";",
"return",
"$",
"this",
"->",
"substring",
"(",
"$",
"fromIndex",
")",
"->",
"matches",
"(",
"$",
"pattern",
")",
";",
"}"
] | Tests if this string starts with the specified prefix, optionally checking
for a match at the specified index.
@access public
@param string $prefix The prefix
@param int $fromIndex Where to begin looking in this string
@return boolean true if the string starts with the given prefix. | [
"Tests",
"if",
"this",
"string",
"starts",
"with",
"the",
"specified",
"prefix",
"optionally",
"checking",
"for",
"a",
"match",
"at",
"the",
"specified",
"index",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L602-L606 | train |
Steveorevo/GString | src/GString.php | GString.substring | public function substring( $beginIndex, $endIndex = null ) {
if ( $beginIndex < 0 ) {
throw new GStringIndexOutOfBoundsException( $beginIndex );
} else if ( $beginIndex == $this->length() ) {
return new GString( "" );
}
if ( $endIndex === null ) {
$length = $this->length() - $beginIndex;
if ( $length < 0 ) {
throw new GStringIndexOutOfBoundsException( $length );
}
if ( $beginIndex == 0 ) {
return $this;
} else {
return new GString( $this->value, $beginIndex, $length );
}
} else {
if ( $endIndex > $this->length() ) {
throw new GStringIndexOutOfBoundsException( $endIndex );
}
$length = $endIndex - $beginIndex;
if ( $length < 0 ) {
throw new GStringIndexOutOfBoundsException( $length );
}
if ( $beginIndex == 0 && $endIndex == $this->length() ) {
return $this;
} else {
return new GString( $this->value, $beginIndex, $length );
}
}
} | php | public function substring( $beginIndex, $endIndex = null ) {
if ( $beginIndex < 0 ) {
throw new GStringIndexOutOfBoundsException( $beginIndex );
} else if ( $beginIndex == $this->length() ) {
return new GString( "" );
}
if ( $endIndex === null ) {
$length = $this->length() - $beginIndex;
if ( $length < 0 ) {
throw new GStringIndexOutOfBoundsException( $length );
}
if ( $beginIndex == 0 ) {
return $this;
} else {
return new GString( $this->value, $beginIndex, $length );
}
} else {
if ( $endIndex > $this->length() ) {
throw new GStringIndexOutOfBoundsException( $endIndex );
}
$length = $endIndex - $beginIndex;
if ( $length < 0 ) {
throw new GStringIndexOutOfBoundsException( $length );
}
if ( $beginIndex == 0 && $endIndex == $this->length() ) {
return $this;
} else {
return new GString( $this->value, $beginIndex, $length );
}
}
} | [
"public",
"function",
"substring",
"(",
"$",
"beginIndex",
",",
"$",
"endIndex",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"beginIndex",
"<",
"0",
")",
"{",
"throw",
"new",
"GStringIndexOutOfBoundsException",
"(",
"$",
"beginIndex",
")",
";",
"}",
"else",
"if",
"(",
"$",
"beginIndex",
"==",
"$",
"this",
"->",
"length",
"(",
")",
")",
"{",
"return",
"new",
"GString",
"(",
"\"\"",
")",
";",
"}",
"if",
"(",
"$",
"endIndex",
"===",
"null",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"length",
"(",
")",
"-",
"$",
"beginIndex",
";",
"if",
"(",
"$",
"length",
"<",
"0",
")",
"{",
"throw",
"new",
"GStringIndexOutOfBoundsException",
"(",
"$",
"length",
")",
";",
"}",
"if",
"(",
"$",
"beginIndex",
"==",
"0",
")",
"{",
"return",
"$",
"this",
";",
"}",
"else",
"{",
"return",
"new",
"GString",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"beginIndex",
",",
"$",
"length",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"endIndex",
">",
"$",
"this",
"->",
"length",
"(",
")",
")",
"{",
"throw",
"new",
"GStringIndexOutOfBoundsException",
"(",
"$",
"endIndex",
")",
";",
"}",
"$",
"length",
"=",
"$",
"endIndex",
"-",
"$",
"beginIndex",
";",
"if",
"(",
"$",
"length",
"<",
"0",
")",
"{",
"throw",
"new",
"GStringIndexOutOfBoundsException",
"(",
"$",
"length",
")",
";",
"}",
"if",
"(",
"$",
"beginIndex",
"==",
"0",
"&&",
"$",
"endIndex",
"==",
"$",
"this",
"->",
"length",
"(",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"else",
"{",
"return",
"new",
"GString",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"beginIndex",
",",
"$",
"length",
")",
";",
"}",
"}",
"}"
] | Returns a new GString that is a substring of this string.
@access public
@param int $beginIndex The beginning index, inclusive
@param int $endIndex The ending index, exclusive
@return \String the specified substring.
@throws StringIndexOutOfBoundsException | [
"Returns",
"a",
"new",
"GString",
"that",
"is",
"a",
"substring",
"of",
"this",
"string",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L619-L649 | train |
Steveorevo/GString | src/GString.php | GString.delRightMost | public function delRightMost( $sSearch ) {
$sSource = $this->value;
for ( $i = strlen( $sSource ); $i >= 0; $i = $i - 1 ) {
$f = strpos( $sSource, $sSearch, $i );
if ( $f !== false ) {
return new GString( substr( $sSource, 0, $f ) );
break;
}
}
return new GString( $sSource );
} | php | public function delRightMost( $sSearch ) {
$sSource = $this->value;
for ( $i = strlen( $sSource ); $i >= 0; $i = $i - 1 ) {
$f = strpos( $sSource, $sSearch, $i );
if ( $f !== false ) {
return new GString( substr( $sSource, 0, $f ) );
break;
}
}
return new GString( $sSource );
} | [
"public",
"function",
"delRightMost",
"(",
"$",
"sSearch",
")",
"{",
"$",
"sSource",
"=",
"$",
"this",
"->",
"value",
";",
"for",
"(",
"$",
"i",
"=",
"strlen",
"(",
"$",
"sSource",
")",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"=",
"$",
"i",
"-",
"1",
")",
"{",
"$",
"f",
"=",
"strpos",
"(",
"$",
"sSource",
",",
"$",
"sSearch",
",",
"$",
"i",
")",
";",
"if",
"(",
"$",
"f",
"!==",
"false",
")",
"{",
"return",
"new",
"GString",
"(",
"substr",
"(",
"$",
"sSource",
",",
"0",
",",
"$",
"f",
")",
")",
";",
"break",
";",
"}",
"}",
"return",
"new",
"GString",
"(",
"$",
"sSource",
")",
";",
"}"
] | Deletes the right most string from the found search string
starting from right to left, including the search string itself.
@access public
@return string | [
"Deletes",
"the",
"right",
"most",
"string",
"from",
"the",
"found",
"search",
"string",
"starting",
"from",
"right",
"to",
"left",
"including",
"the",
"search",
"string",
"itself",
"."
] | 69150558cdbeca33ae03b4becce47c7cc0de495c | https://github.com/Steveorevo/GString/blob/69150558cdbeca33ae03b4becce47c7cc0de495c/src/GString.php#L730-L741 | train |
shgysk8zer0/core_api | traits/url.php | URL.URLToString | final protected function URLToString(array $components = array(
'scheme',
'user',
'pass',
'host',
'port',
'path',
'query',
'fragment'
))
{
$url = '';
$query = "{$this->query}";
if (in_array('scheme', $components)) {
if (is_string($this->_url_data['scheme'])) {
$url .= rtrim($this->_url_data['scheme'], ':/') . '://';
} else {
$url .= 'http://';
}
}
if (@is_string($this->_url_data['user']) and in_array('user', $components)) {
$url .= urlencode($this->_url_data['user']);
if (@is_string($this->_url_data['pass']) and in_array('pass', $components)) {
$url .= ':' . urlencode($this->_url_data['pass']);
}
$url .= '@';
}
if (in_array('host', $components)) {
if (@is_string($this->_url_data['host'])) {
$url .= $this->_url_data['host'];
} else {
$url .= 'localhost';
}
}
if (
is_int($this->_url_data['port'])
and ! $this->isDefaultPort($this->_url_data['scheme'], $this->_url_data['port'])
) {
$url .= ":{$this->_url_data['port']}";
}
if (in_array('path', $components)) {
if (@is_string($this->_url_data['path'])) {
$url .= '/' . ltrim($this->_url_data['path'], '/');
} else {
$url .= '/';
}
}
if(
strlen($query) !== 0 and in_array('query', $components)
) {
$url .= "?$query";
}
if (@is_string($this->_url_data['fragment']) and in_array('fragment', $components)) {
$url .= '#' . ltrim($this->_url_data['fragment'], '#');
}
return $url;
} | php | final protected function URLToString(array $components = array(
'scheme',
'user',
'pass',
'host',
'port',
'path',
'query',
'fragment'
))
{
$url = '';
$query = "{$this->query}";
if (in_array('scheme', $components)) {
if (is_string($this->_url_data['scheme'])) {
$url .= rtrim($this->_url_data['scheme'], ':/') . '://';
} else {
$url .= 'http://';
}
}
if (@is_string($this->_url_data['user']) and in_array('user', $components)) {
$url .= urlencode($this->_url_data['user']);
if (@is_string($this->_url_data['pass']) and in_array('pass', $components)) {
$url .= ':' . urlencode($this->_url_data['pass']);
}
$url .= '@';
}
if (in_array('host', $components)) {
if (@is_string($this->_url_data['host'])) {
$url .= $this->_url_data['host'];
} else {
$url .= 'localhost';
}
}
if (
is_int($this->_url_data['port'])
and ! $this->isDefaultPort($this->_url_data['scheme'], $this->_url_data['port'])
) {
$url .= ":{$this->_url_data['port']}";
}
if (in_array('path', $components)) {
if (@is_string($this->_url_data['path'])) {
$url .= '/' . ltrim($this->_url_data['path'], '/');
} else {
$url .= '/';
}
}
if(
strlen($query) !== 0 and in_array('query', $components)
) {
$url .= "?$query";
}
if (@is_string($this->_url_data['fragment']) and in_array('fragment', $components)) {
$url .= '#' . ltrim($this->_url_data['fragment'], '#');
}
return $url;
} | [
"final",
"protected",
"function",
"URLToString",
"(",
"array",
"$",
"components",
"=",
"array",
"(",
"'scheme'",
",",
"'user'",
",",
"'pass'",
",",
"'host'",
",",
"'port'",
",",
"'path'",
",",
"'query'",
",",
"'fragment'",
")",
")",
"{",
"$",
"url",
"=",
"''",
";",
"$",
"query",
"=",
"\"{$this->query}\"",
";",
"if",
"(",
"in_array",
"(",
"'scheme'",
",",
"$",
"components",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'scheme'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"rtrim",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'scheme'",
"]",
",",
"':/'",
")",
".",
"'://'",
";",
"}",
"else",
"{",
"$",
"url",
".=",
"'http://'",
";",
"}",
"}",
"if",
"(",
"@",
"is_string",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'user'",
"]",
")",
"and",
"in_array",
"(",
"'user'",
",",
"$",
"components",
")",
")",
"{",
"$",
"url",
".=",
"urlencode",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'user'",
"]",
")",
";",
"if",
"(",
"@",
"is_string",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'pass'",
"]",
")",
"and",
"in_array",
"(",
"'pass'",
",",
"$",
"components",
")",
")",
"{",
"$",
"url",
".=",
"':'",
".",
"urlencode",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'pass'",
"]",
")",
";",
"}",
"$",
"url",
".=",
"'@'",
";",
"}",
"if",
"(",
"in_array",
"(",
"'host'",
",",
"$",
"components",
")",
")",
"{",
"if",
"(",
"@",
"is_string",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'host'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"$",
"this",
"->",
"_url_data",
"[",
"'host'",
"]",
";",
"}",
"else",
"{",
"$",
"url",
".=",
"'localhost'",
";",
"}",
"}",
"if",
"(",
"is_int",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'port'",
"]",
")",
"and",
"!",
"$",
"this",
"->",
"isDefaultPort",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'scheme'",
"]",
",",
"$",
"this",
"->",
"_url_data",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"\":{$this->_url_data['port']}\"",
";",
"}",
"if",
"(",
"in_array",
"(",
"'path'",
",",
"$",
"components",
")",
")",
"{",
"if",
"(",
"@",
"is_string",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"'/'",
".",
"ltrim",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'path'",
"]",
",",
"'/'",
")",
";",
"}",
"else",
"{",
"$",
"url",
".=",
"'/'",
";",
"}",
"}",
"if",
"(",
"strlen",
"(",
"$",
"query",
")",
"!==",
"0",
"and",
"in_array",
"(",
"'query'",
",",
"$",
"components",
")",
")",
"{",
"$",
"url",
".=",
"\"?$query\"",
";",
"}",
"if",
"(",
"@",
"is_string",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'fragment'",
"]",
")",
"and",
"in_array",
"(",
"'fragment'",
",",
"$",
"components",
")",
")",
"{",
"$",
"url",
".=",
"'#'",
".",
"ltrim",
"(",
"$",
"this",
"->",
"_url_data",
"[",
"'fragment'",
"]",
",",
"'#'",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Combine URL components into a URL string
@param void
@return string | [
"Combine",
"URL",
"components",
"into",
"a",
"URL",
"string"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/url.php#L147-L206 | train |
freialib/fenrir.system | src/Trait/SQLStatementCommon.php | SQLStatementCommonTrait.fetch_calc | function fetch_calc($on_null = null) {
$calc_entry = $this->fetch_entry();
$value = array_pop($calc_entry);
if ($value !== null) {
return $value;
}
else { // null value
return $on_null;
}
} | php | function fetch_calc($on_null = null) {
$calc_entry = $this->fetch_entry();
$value = array_pop($calc_entry);
if ($value !== null) {
return $value;
}
else { // null value
return $on_null;
}
} | [
"function",
"fetch_calc",
"(",
"$",
"on_null",
"=",
"null",
")",
"{",
"$",
"calc_entry",
"=",
"$",
"this",
"->",
"fetch_entry",
"(",
")",
";",
"$",
"value",
"=",
"array_pop",
"(",
"$",
"calc_entry",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"return",
"$",
"value",
";",
"}",
"else",
"{",
"// null value",
"return",
"$",
"on_null",
";",
"}",
"}"
] | Shorthand for retrieving value from a querie that performs a COUNT, SUM
or some other calculation.
@return mixed | [
"Shorthand",
"for",
"retrieving",
"value",
"from",
"a",
"querie",
"that",
"performs",
"a",
"COUNT",
"SUM",
"or",
"some",
"other",
"calculation",
"."
] | 388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8 | https://github.com/freialib/fenrir.system/blob/388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8/src/Trait/SQLStatementCommon.php#L57-L67 | train |
horntell/php-sdk | src/Horntell/Horn.php | Horn.toProfiles | public function toProfiles($profiles, $horn)
{
$horn = array_merge(['profile_uids' => $profiles], $horn);
return $this->request->send('POST', "/profiles/horns", $horn);
} | php | public function toProfiles($profiles, $horn)
{
$horn = array_merge(['profile_uids' => $profiles], $horn);
return $this->request->send('POST', "/profiles/horns", $horn);
} | [
"public",
"function",
"toProfiles",
"(",
"$",
"profiles",
",",
"$",
"horn",
")",
"{",
"$",
"horn",
"=",
"array_merge",
"(",
"[",
"'profile_uids'",
"=>",
"$",
"profiles",
"]",
",",
"$",
"horn",
")",
";",
"return",
"$",
"this",
"->",
"request",
"->",
"send",
"(",
"'POST'",
",",
"\"/profiles/horns\"",
",",
"$",
"horn",
")",
";",
"}"
] | Sends a horn to a multiple profiles
@param array $horn
@return Horntell\Http\Response | [
"Sends",
"a",
"horn",
"to",
"a",
"multiple",
"profiles"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/src/Horntell/Horn.php#L38-L43 | train |
Ydle/HubBundle | Entity/Node.php | Node.hasType | public function hasType(NodeType $type)
{
foreach ($this->types as $t) {
if ($t->getId() == $type->getId()) { return true; }
}
return false;
} | php | public function hasType(NodeType $type)
{
foreach ($this->types as $t) {
if ($t->getId() == $type->getId()) { return true; }
}
return false;
} | [
"public",
"function",
"hasType",
"(",
"NodeType",
"$",
"type",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"types",
"as",
"$",
"t",
")",
"{",
"if",
"(",
"$",
"t",
"->",
"getId",
"(",
")",
"==",
"$",
"type",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if a node got a specific type
@param Ydle\HubBundle\Entity\NodeType $type
@return boolean | [
"Check",
"if",
"a",
"node",
"got",
"a",
"specific",
"type"
] | 7fa423241246bcfd115f2ed3ad3997b4b63adb01 | https://github.com/Ydle/HubBundle/blob/7fa423241246bcfd115f2ed3ad3997b4b63adb01/Entity/Node.php#L265-L272 | train |
nails/module-blog | admin/controllers/Category.php | Category.delete | public function delete()
{
if (!userHasPermission('admin:blog:category:' . $this->blog->id . ':delete')) {
unauthorised();
}
// --------------------------------------------------------------------------
$id = $this->uri->segment(6);
if ($this->blog_category_model->delete($id)) {
$this->session->set_flashdata('success', 'Category was deleted successfully.');
} else {
$status = 'error';
$message = 'There was a problem deleting the Category. ';
$message .= $this->blog_category_model->lastError();
$this->session->set_flashdata($status, $message);
}
redirect('admin/blog/category/index/' . $this->blog->id . $this->isModal);
} | php | public function delete()
{
if (!userHasPermission('admin:blog:category:' . $this->blog->id . ':delete')) {
unauthorised();
}
// --------------------------------------------------------------------------
$id = $this->uri->segment(6);
if ($this->blog_category_model->delete($id)) {
$this->session->set_flashdata('success', 'Category was deleted successfully.');
} else {
$status = 'error';
$message = 'There was a problem deleting the Category. ';
$message .= $this->blog_category_model->lastError();
$this->session->set_flashdata($status, $message);
}
redirect('admin/blog/category/index/' . $this->blog->id . $this->isModal);
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"if",
"(",
"!",
"userHasPermission",
"(",
"'admin:blog:category:'",
".",
"$",
"this",
"->",
"blog",
"->",
"id",
".",
"':delete'",
")",
")",
"{",
"unauthorised",
"(",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"$",
"id",
"=",
"$",
"this",
"->",
"uri",
"->",
"segment",
"(",
"6",
")",
";",
"if",
"(",
"$",
"this",
"->",
"blog_category_model",
"->",
"delete",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"set_flashdata",
"(",
"'success'",
",",
"'Category was deleted successfully.'",
")",
";",
"}",
"else",
"{",
"$",
"status",
"=",
"'error'",
";",
"$",
"message",
"=",
"'There was a problem deleting the Category. '",
";",
"$",
"message",
".=",
"$",
"this",
"->",
"blog_category_model",
"->",
"lastError",
"(",
")",
";",
"$",
"this",
"->",
"session",
"->",
"set_flashdata",
"(",
"$",
"status",
",",
"$",
"message",
")",
";",
"}",
"redirect",
"(",
"'admin/blog/category/index/'",
".",
"$",
"this",
"->",
"blog",
"->",
"id",
".",
"$",
"this",
"->",
"isModal",
")",
";",
"}"
] | Delete a blog category
@return void | [
"Delete",
"a",
"blog",
"category"
] | 7b369c5209f4343fff7c7e2a22c237d5a95c8c24 | https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/admin/controllers/Category.php#L332-L356 | train |
jbouzekri/SculpinTagCloudBundle | Component/Strategy/AlphaStrategy.php | AlphaStrategy.process | public function process(\Jb\Bundle\TagCloudBundle\Model\TagCloud $cloud)
{
$keys = array_keys($cloud->getTags());
asort($keys);
$new = array();
$old = $cloud->getTags();
foreach($keys as $key) {
$new[$key] = $old[$key];
}
$cloud->setTags($new);
} | php | public function process(\Jb\Bundle\TagCloudBundle\Model\TagCloud $cloud)
{
$keys = array_keys($cloud->getTags());
asort($keys);
$new = array();
$old = $cloud->getTags();
foreach($keys as $key) {
$new[$key] = $old[$key];
}
$cloud->setTags($new);
} | [
"public",
"function",
"process",
"(",
"\\",
"Jb",
"\\",
"Bundle",
"\\",
"TagCloudBundle",
"\\",
"Model",
"\\",
"TagCloud",
"$",
"cloud",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"cloud",
"->",
"getTags",
"(",
")",
")",
";",
"asort",
"(",
"$",
"keys",
")",
";",
"$",
"new",
"=",
"array",
"(",
")",
";",
"$",
"old",
"=",
"$",
"cloud",
"->",
"getTags",
"(",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"new",
"[",
"$",
"key",
"]",
"=",
"$",
"old",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"cloud",
"->",
"setTags",
"(",
"$",
"new",
")",
";",
"}"
] | Sort the tag in the cloud
@param \Jb\Bundle\TagCloudBundle\Model\TagCloud $cloud | [
"Sort",
"the",
"tag",
"in",
"the",
"cloud"
] | 936cf34ce60cb8fb4774931b1841fc775a3e9208 | https://github.com/jbouzekri/SculpinTagCloudBundle/blob/936cf34ce60cb8fb4774931b1841fc775a3e9208/Component/Strategy/AlphaStrategy.php#L17-L30 | train |
bkstg/schedule-bundle | Controller/EventController.php | EventController.createAction | public function createAction(
string $production_slug,
AuthorizationCheckerInterface $auth,
TokenStorageInterface $token_storage,
Request $request
): Response {
// Lookup the production by production_slug.
$production_repo = $this->em->getRepository(Production::class);
if (null === $production = $production_repo->findOneBy(['slug' => $production_slug])) {
throw new NotFoundHttpException();
}
// Check permissions for this action.
if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
throw new AccessDeniedException();
}
// Create a new event with author and production.
$user = $token_storage->getToken()->getUser();
$event = new Event();
$event->addGroup($production);
$event->setAuthor($user->getUsername());
$event->setActive(true);
// Create a new invitation for the current user.
$invitation = new Invitation();
$invitation->setInvitee($user->getUsername());
$event->addInvitation($invitation);
// Set start and end times using closest 1 hour intervals.
$start = new \DateTime();
$start->modify('+1 hour');
$start->modify('-' . $start->format('i') . ' minutes');
$event->setStart($start);
$end = new \DateTime('+1 hour');
$end->modify('+1 hour');
$end->modify('-' . $end->format('i') . ' minutes');
$event->setEnd($end);
// Create and handle the form.
$form = $this->form->create(EventType::class, $event);
$form->handleRequest($request);
// If the form is submitted and valid persist the event.
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($event);
$this->em->flush();
// Set success message and redirect.
$this->session->getFlashBag()->add(
'success',
$this->translator->trans('event.created', [
'%event%' => $event->getName(),
], BkstgScheduleBundle::TRANSLATION_DOMAIN)
);
return new RedirectResponse($this->url_generator->generate(
'bkstg_event_read',
['id' => $event->getId(), 'production_slug' => $production->getSlug()]
));
}
// Render the form.
return new Response($this->templating->render('@BkstgSchedule/Event/create.html.twig', [
'form' => $form->createView(),
'production' => $production,
]));
} | php | public function createAction(
string $production_slug,
AuthorizationCheckerInterface $auth,
TokenStorageInterface $token_storage,
Request $request
): Response {
// Lookup the production by production_slug.
$production_repo = $this->em->getRepository(Production::class);
if (null === $production = $production_repo->findOneBy(['slug' => $production_slug])) {
throw new NotFoundHttpException();
}
// Check permissions for this action.
if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
throw new AccessDeniedException();
}
// Create a new event with author and production.
$user = $token_storage->getToken()->getUser();
$event = new Event();
$event->addGroup($production);
$event->setAuthor($user->getUsername());
$event->setActive(true);
// Create a new invitation for the current user.
$invitation = new Invitation();
$invitation->setInvitee($user->getUsername());
$event->addInvitation($invitation);
// Set start and end times using closest 1 hour intervals.
$start = new \DateTime();
$start->modify('+1 hour');
$start->modify('-' . $start->format('i') . ' minutes');
$event->setStart($start);
$end = new \DateTime('+1 hour');
$end->modify('+1 hour');
$end->modify('-' . $end->format('i') . ' minutes');
$event->setEnd($end);
// Create and handle the form.
$form = $this->form->create(EventType::class, $event);
$form->handleRequest($request);
// If the form is submitted and valid persist the event.
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($event);
$this->em->flush();
// Set success message and redirect.
$this->session->getFlashBag()->add(
'success',
$this->translator->trans('event.created', [
'%event%' => $event->getName(),
], BkstgScheduleBundle::TRANSLATION_DOMAIN)
);
return new RedirectResponse($this->url_generator->generate(
'bkstg_event_read',
['id' => $event->getId(), 'production_slug' => $production->getSlug()]
));
}
// Render the form.
return new Response($this->templating->render('@BkstgSchedule/Event/create.html.twig', [
'form' => $form->createView(),
'production' => $production,
]));
} | [
"public",
"function",
"createAction",
"(",
"string",
"$",
"production_slug",
",",
"AuthorizationCheckerInterface",
"$",
"auth",
",",
"TokenStorageInterface",
"$",
"token_storage",
",",
"Request",
"$",
"request",
")",
":",
"Response",
"{",
"// Lookup the production by production_slug.",
"$",
"production_repo",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"Production",
"::",
"class",
")",
";",
"if",
"(",
"null",
"===",
"$",
"production",
"=",
"$",
"production_repo",
"->",
"findOneBy",
"(",
"[",
"'slug'",
"=>",
"$",
"production_slug",
"]",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"// Check permissions for this action.",
"if",
"(",
"!",
"$",
"auth",
"->",
"isGranted",
"(",
"'GROUP_ROLE_EDITOR'",
",",
"$",
"production",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}",
"// Create a new event with author and production.",
"$",
"user",
"=",
"$",
"token_storage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"event",
"=",
"new",
"Event",
"(",
")",
";",
"$",
"event",
"->",
"addGroup",
"(",
"$",
"production",
")",
";",
"$",
"event",
"->",
"setAuthor",
"(",
"$",
"user",
"->",
"getUsername",
"(",
")",
")",
";",
"$",
"event",
"->",
"setActive",
"(",
"true",
")",
";",
"// Create a new invitation for the current user.",
"$",
"invitation",
"=",
"new",
"Invitation",
"(",
")",
";",
"$",
"invitation",
"->",
"setInvitee",
"(",
"$",
"user",
"->",
"getUsername",
"(",
")",
")",
";",
"$",
"event",
"->",
"addInvitation",
"(",
"$",
"invitation",
")",
";",
"// Set start and end times using closest 1 hour intervals.",
"$",
"start",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"start",
"->",
"modify",
"(",
"'+1 hour'",
")",
";",
"$",
"start",
"->",
"modify",
"(",
"'-'",
".",
"$",
"start",
"->",
"format",
"(",
"'i'",
")",
".",
"' minutes'",
")",
";",
"$",
"event",
"->",
"setStart",
"(",
"$",
"start",
")",
";",
"$",
"end",
"=",
"new",
"\\",
"DateTime",
"(",
"'+1 hour'",
")",
";",
"$",
"end",
"->",
"modify",
"(",
"'+1 hour'",
")",
";",
"$",
"end",
"->",
"modify",
"(",
"'-'",
".",
"$",
"end",
"->",
"format",
"(",
"'i'",
")",
".",
"' minutes'",
")",
";",
"$",
"event",
"->",
"setEnd",
"(",
"$",
"end",
")",
";",
"// Create and handle the form.",
"$",
"form",
"=",
"$",
"this",
"->",
"form",
"->",
"create",
"(",
"EventType",
"::",
"class",
",",
"$",
"event",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"// If the form is submitted and valid persist the event.",
"if",
"(",
"$",
"form",
"->",
"isSubmitted",
"(",
")",
"&&",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"event",
")",
";",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"// Set success message and redirect.",
"$",
"this",
"->",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'event.created'",
",",
"[",
"'%event%'",
"=>",
"$",
"event",
"->",
"getName",
"(",
")",
",",
"]",
",",
"BkstgScheduleBundle",
"::",
"TRANSLATION_DOMAIN",
")",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"url_generator",
"->",
"generate",
"(",
"'bkstg_event_read'",
",",
"[",
"'id'",
"=>",
"$",
"event",
"->",
"getId",
"(",
")",
",",
"'production_slug'",
"=>",
"$",
"production",
"->",
"getSlug",
"(",
")",
"]",
")",
")",
";",
"}",
"// Render the form.",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"templating",
"->",
"render",
"(",
"'@BkstgSchedule/Event/create.html.twig'",
",",
"[",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"'production'",
"=>",
"$",
"production",
",",
"]",
")",
")",
";",
"}"
] | Create a new standalone event.
@param string $production_slug The slug for the production.
@param AuthorizationCheckerInterface $auth The authorization checker service.
@param TokenStorageInterface $token_storage The token storage service.
@param Request $request The request.
@throws NotFoundHttpException When the production does not exist.
@throws AccessDeniedException When the user is not an editor.
@return Response The response. | [
"Create",
"a",
"new",
"standalone",
"event",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Controller/EventController.php#L45-L113 | train |
bkstg/schedule-bundle | Controller/EventController.php | EventController.readAction | public function readAction(
string $production_slug,
int $id,
AuthorizationCheckerInterface $auth
): Response {
// Get the event and production for this action.
list($event, $production) = $this->lookupEntity(Event::class, $id, $production_slug);
// If this event is handled by a schedule redirect there.
if (null !== $redirect = $this->checkSchedule($event, $production)) {
return $redirect;
}
// Check permissions for this action.
if (!$auth->isGranted('view', $event)) {
throw new AccessDeniedException();
}
// Render the event.
return new Response($this->templating->render('@BkstgSchedule/Event/read.html.twig', [
'production' => $production,
'event' => $event,
]));
} | php | public function readAction(
string $production_slug,
int $id,
AuthorizationCheckerInterface $auth
): Response {
// Get the event and production for this action.
list($event, $production) = $this->lookupEntity(Event::class, $id, $production_slug);
// If this event is handled by a schedule redirect there.
if (null !== $redirect = $this->checkSchedule($event, $production)) {
return $redirect;
}
// Check permissions for this action.
if (!$auth->isGranted('view', $event)) {
throw new AccessDeniedException();
}
// Render the event.
return new Response($this->templating->render('@BkstgSchedule/Event/read.html.twig', [
'production' => $production,
'event' => $event,
]));
} | [
"public",
"function",
"readAction",
"(",
"string",
"$",
"production_slug",
",",
"int",
"$",
"id",
",",
"AuthorizationCheckerInterface",
"$",
"auth",
")",
":",
"Response",
"{",
"// Get the event and production for this action.",
"list",
"(",
"$",
"event",
",",
"$",
"production",
")",
"=",
"$",
"this",
"->",
"lookupEntity",
"(",
"Event",
"::",
"class",
",",
"$",
"id",
",",
"$",
"production_slug",
")",
";",
"// If this event is handled by a schedule redirect there.",
"if",
"(",
"null",
"!==",
"$",
"redirect",
"=",
"$",
"this",
"->",
"checkSchedule",
"(",
"$",
"event",
",",
"$",
"production",
")",
")",
"{",
"return",
"$",
"redirect",
";",
"}",
"// Check permissions for this action.",
"if",
"(",
"!",
"$",
"auth",
"->",
"isGranted",
"(",
"'view'",
",",
"$",
"event",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}",
"// Render the event.",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"templating",
"->",
"render",
"(",
"'@BkstgSchedule/Event/read.html.twig'",
",",
"[",
"'production'",
"=>",
"$",
"production",
",",
"'event'",
"=>",
"$",
"event",
",",
"]",
")",
")",
";",
"}"
] | Show a single event.
@param string $production_slug The slug for the production.
@param int $id The event id.
@param AuthorizationCheckerInterface $auth The authorization checker service.
@throws AccessDeniedException When the user is not in the group.
@return Response The response. | [
"Show",
"a",
"single",
"event",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Controller/EventController.php#L126-L149 | train |
bkstg/schedule-bundle | Controller/EventController.php | EventController.updateAction | public function updateAction(
string $production_slug,
int $id,
AuthorizationCheckerInterface $auth,
TokenStorageInterface $token,
Request $request
): Response {
// Get the event and production for this action.
list($event, $production) = $this->lookupEntity(Event::class, $id, $production_slug);
// If this event is handled by a schedule redirect there.
if (null !== $redirect = $this->checkSchedule($event, $production)) {
return $redirect;
}
// Check permissions for this action.
if (!$auth->isGranted('edit', $event)) {
throw new AccessDeniedException();
}
// Create an index of invitations for checking later.
$invitations = new ArrayCollection();
foreach ($event->getInvitations() as $invitation) {
$invitations->add($invitation);
}
// Create and handle the form.
$form = $this->form->create(EventType::class, $event);
$form->handleRequest($request);
// If the form is submitted and valid persist the event.
if ($form->isSubmitted() && $form->isValid()) {
// Remove unneeded invitations.
foreach ($invitations as $invitation) {
if (false === $event->getInvitations()->contains($invitation)) {
$this->em->remove($invitation);
}
}
$this->em->persist($event);
$this->em->flush();
// Set success message and redirect.
$this->session->getFlashBag()->add(
'success',
$this->translator->trans('event.updated', [
'%event%' => $event->getName(),
], BkstgScheduleBundle::TRANSLATION_DOMAIN)
);
return new RedirectResponse($this->url_generator->generate(
'bkstg_event_read',
['id' => $event->getId(), 'production_slug' => $production->getSlug()]
));
}
// Render the form.
return new Response($this->templating->render('@BkstgSchedule/Event/update.html.twig', [
'event' => $event,
'production' => $production,
'form' => $form->createView(),
]));
} | php | public function updateAction(
string $production_slug,
int $id,
AuthorizationCheckerInterface $auth,
TokenStorageInterface $token,
Request $request
): Response {
// Get the event and production for this action.
list($event, $production) = $this->lookupEntity(Event::class, $id, $production_slug);
// If this event is handled by a schedule redirect there.
if (null !== $redirect = $this->checkSchedule($event, $production)) {
return $redirect;
}
// Check permissions for this action.
if (!$auth->isGranted('edit', $event)) {
throw new AccessDeniedException();
}
// Create an index of invitations for checking later.
$invitations = new ArrayCollection();
foreach ($event->getInvitations() as $invitation) {
$invitations->add($invitation);
}
// Create and handle the form.
$form = $this->form->create(EventType::class, $event);
$form->handleRequest($request);
// If the form is submitted and valid persist the event.
if ($form->isSubmitted() && $form->isValid()) {
// Remove unneeded invitations.
foreach ($invitations as $invitation) {
if (false === $event->getInvitations()->contains($invitation)) {
$this->em->remove($invitation);
}
}
$this->em->persist($event);
$this->em->flush();
// Set success message and redirect.
$this->session->getFlashBag()->add(
'success',
$this->translator->trans('event.updated', [
'%event%' => $event->getName(),
], BkstgScheduleBundle::TRANSLATION_DOMAIN)
);
return new RedirectResponse($this->url_generator->generate(
'bkstg_event_read',
['id' => $event->getId(), 'production_slug' => $production->getSlug()]
));
}
// Render the form.
return new Response($this->templating->render('@BkstgSchedule/Event/update.html.twig', [
'event' => $event,
'production' => $production,
'form' => $form->createView(),
]));
} | [
"public",
"function",
"updateAction",
"(",
"string",
"$",
"production_slug",
",",
"int",
"$",
"id",
",",
"AuthorizationCheckerInterface",
"$",
"auth",
",",
"TokenStorageInterface",
"$",
"token",
",",
"Request",
"$",
"request",
")",
":",
"Response",
"{",
"// Get the event and production for this action.",
"list",
"(",
"$",
"event",
",",
"$",
"production",
")",
"=",
"$",
"this",
"->",
"lookupEntity",
"(",
"Event",
"::",
"class",
",",
"$",
"id",
",",
"$",
"production_slug",
")",
";",
"// If this event is handled by a schedule redirect there.",
"if",
"(",
"null",
"!==",
"$",
"redirect",
"=",
"$",
"this",
"->",
"checkSchedule",
"(",
"$",
"event",
",",
"$",
"production",
")",
")",
"{",
"return",
"$",
"redirect",
";",
"}",
"// Check permissions for this action.",
"if",
"(",
"!",
"$",
"auth",
"->",
"isGranted",
"(",
"'edit'",
",",
"$",
"event",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}",
"// Create an index of invitations for checking later.",
"$",
"invitations",
"=",
"new",
"ArrayCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"event",
"->",
"getInvitations",
"(",
")",
"as",
"$",
"invitation",
")",
"{",
"$",
"invitations",
"->",
"add",
"(",
"$",
"invitation",
")",
";",
"}",
"// Create and handle the form.",
"$",
"form",
"=",
"$",
"this",
"->",
"form",
"->",
"create",
"(",
"EventType",
"::",
"class",
",",
"$",
"event",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"// If the form is submitted and valid persist the event.",
"if",
"(",
"$",
"form",
"->",
"isSubmitted",
"(",
")",
"&&",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"// Remove unneeded invitations.",
"foreach",
"(",
"$",
"invitations",
"as",
"$",
"invitation",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"event",
"->",
"getInvitations",
"(",
")",
"->",
"contains",
"(",
"$",
"invitation",
")",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"invitation",
")",
";",
"}",
"}",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"event",
")",
";",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"// Set success message and redirect.",
"$",
"this",
"->",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'event.updated'",
",",
"[",
"'%event%'",
"=>",
"$",
"event",
"->",
"getName",
"(",
")",
",",
"]",
",",
"BkstgScheduleBundle",
"::",
"TRANSLATION_DOMAIN",
")",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"url_generator",
"->",
"generate",
"(",
"'bkstg_event_read'",
",",
"[",
"'id'",
"=>",
"$",
"event",
"->",
"getId",
"(",
")",
",",
"'production_slug'",
"=>",
"$",
"production",
"->",
"getSlug",
"(",
")",
"]",
")",
")",
";",
"}",
"// Render the form.",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"templating",
"->",
"render",
"(",
"'@BkstgSchedule/Event/update.html.twig'",
",",
"[",
"'event'",
"=>",
"$",
"event",
",",
"'production'",
"=>",
"$",
"production",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"]",
")",
")",
";",
"}"
] | Update a standalone event.
@param string $production_slug The slug for the production.
@param int $id The event id.
@param AuthorizationCheckerInterface $auth The authorization checker service.
@param TokenStorageInterface $token The token storage service.
@param Request $request The request.
@throws AccessDeniedException When the user is not an editor.
@return Response The response. | [
"Update",
"a",
"standalone",
"event",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Controller/EventController.php#L164-L226 | train |
bkstg/schedule-bundle | Controller/EventController.php | EventController.archiveAction | public function archiveAction(
string $production_slug,
PaginatorInterface $paginator,
AuthorizationCheckerInterface $auth,
Request $request
): Response {
// Lookup the production by production_slug.
$production_repo = $this->em->getRepository(Production::class);
if (null === $production = $production_repo->findOneBy(['slug' => $production_slug])) {
throw new NotFoundHttpException();
}
// Check permissions for this action.
if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
throw new AccessDeniedException();
}
// Get a list of archived events.
$event_repo = $this->em->getRepository(Event::class);
$query = $event_repo->findArchivedEventsQuery($production);
// Paginate and render the results.
$events = $paginator->paginate($query, $request->query->getInt('page', 1));
return new Response($this->templating->render('@BkstgSchedule/Event/archive.html.twig', [
'events' => $events,
'production' => $production,
]));
} | php | public function archiveAction(
string $production_slug,
PaginatorInterface $paginator,
AuthorizationCheckerInterface $auth,
Request $request
): Response {
// Lookup the production by production_slug.
$production_repo = $this->em->getRepository(Production::class);
if (null === $production = $production_repo->findOneBy(['slug' => $production_slug])) {
throw new NotFoundHttpException();
}
// Check permissions for this action.
if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
throw new AccessDeniedException();
}
// Get a list of archived events.
$event_repo = $this->em->getRepository(Event::class);
$query = $event_repo->findArchivedEventsQuery($production);
// Paginate and render the results.
$events = $paginator->paginate($query, $request->query->getInt('page', 1));
return new Response($this->templating->render('@BkstgSchedule/Event/archive.html.twig', [
'events' => $events,
'production' => $production,
]));
} | [
"public",
"function",
"archiveAction",
"(",
"string",
"$",
"production_slug",
",",
"PaginatorInterface",
"$",
"paginator",
",",
"AuthorizationCheckerInterface",
"$",
"auth",
",",
"Request",
"$",
"request",
")",
":",
"Response",
"{",
"// Lookup the production by production_slug.",
"$",
"production_repo",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"Production",
"::",
"class",
")",
";",
"if",
"(",
"null",
"===",
"$",
"production",
"=",
"$",
"production_repo",
"->",
"findOneBy",
"(",
"[",
"'slug'",
"=>",
"$",
"production_slug",
"]",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"// Check permissions for this action.",
"if",
"(",
"!",
"$",
"auth",
"->",
"isGranted",
"(",
"'GROUP_ROLE_EDITOR'",
",",
"$",
"production",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}",
"// Get a list of archived events.",
"$",
"event_repo",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"Event",
"::",
"class",
")",
";",
"$",
"query",
"=",
"$",
"event_repo",
"->",
"findArchivedEventsQuery",
"(",
"$",
"production",
")",
";",
"// Paginate and render the results.",
"$",
"events",
"=",
"$",
"paginator",
"->",
"paginate",
"(",
"$",
"query",
",",
"$",
"request",
"->",
"query",
"->",
"getInt",
"(",
"'page'",
",",
"1",
")",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"templating",
"->",
"render",
"(",
"'@BkstgSchedule/Event/archive.html.twig'",
",",
"[",
"'events'",
"=>",
"$",
"events",
",",
"'production'",
"=>",
"$",
"production",
",",
"]",
")",
")",
";",
"}"
] | Show a list of archived events.
@param string $production_slug The production to look in.
@param PaginatorInterface $paginator The paginator service.
@param AuthorizationCheckerInterface $auth The authorization checker service.
@param Request $request The incoming request.
@throws NotFoundHttpException When the production does not exist.
@throws AccessDeniedException When the user is not an editor.
@return Response | [
"Show",
"a",
"list",
"of",
"archived",
"events",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Controller/EventController.php#L305-L333 | train |
bkstg/schedule-bundle | Controller/EventController.php | EventController.checkSchedule | private function checkSchedule(Event $event, Production $production): ?RedirectResponse
{
// If this event is handled by a schedule generate a redirect there.
if (null !== $schedule = $event->getSchedule()) {
return new RedirectResponse($this->url_generator->generate(
'bkstg_schedule_read',
[
'production_slug' => $production->getSlug(),
'id' => $schedule->getId(),
]
));
}
return null;
} | php | private function checkSchedule(Event $event, Production $production): ?RedirectResponse
{
// If this event is handled by a schedule generate a redirect there.
if (null !== $schedule = $event->getSchedule()) {
return new RedirectResponse($this->url_generator->generate(
'bkstg_schedule_read',
[
'production_slug' => $production->getSlug(),
'id' => $schedule->getId(),
]
));
}
return null;
} | [
"private",
"function",
"checkSchedule",
"(",
"Event",
"$",
"event",
",",
"Production",
"$",
"production",
")",
":",
"?",
"RedirectResponse",
"{",
"// If this event is handled by a schedule generate a redirect there.",
"if",
"(",
"null",
"!==",
"$",
"schedule",
"=",
"$",
"event",
"->",
"getSchedule",
"(",
")",
")",
"{",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"url_generator",
"->",
"generate",
"(",
"'bkstg_schedule_read'",
",",
"[",
"'production_slug'",
"=>",
"$",
"production",
"->",
"getSlug",
"(",
")",
",",
"'id'",
"=>",
"$",
"schedule",
"->",
"getId",
"(",
")",
",",
"]",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Check if an event has a parent schedule.
@param Event $event The event to check.
@param Production $production The production this event is in.
@return RedirectResponse | [
"Check",
"if",
"an",
"event",
"has",
"a",
"parent",
"schedule",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Controller/EventController.php#L343-L357 | train |
kkthek/diqa-util | src/Util/FileUtils.php | FileUtils.last_lines | public static function last_lines($path, $line_count, $offset = 0, $block_size = 512){
$lines = array();
// we will always have a fragment of a non-complete line
// keep this in here till we have our next entire line.
$leftover = "";
$fh = fopen($path, 'r');
$storeOffset = $offset;
// go to the end of the file
fseek($fh, $offset, SEEK_END);
do{
// need to know whether we can actually go back
// $block_size bytes
$can_read = $block_size;
if(ftell($fh) < $block_size){
$can_read = ftell($fh);
}
$storeOffset -= $can_read;
// go back as many bytes as we can
// read them to $data and then move the file pointer
// back to where we were.
fseek($fh, -$can_read, SEEK_CUR);
$data = @fread($fh, $can_read);
$data .= $leftover;
fseek($fh, -$can_read, SEEK_CUR);
// split lines by \n. Then reverse them,
// now the last line is most likely not a complete
// line which is why we do not directly add it, but
// append it to the data read the next time.
$split_data = array_reverse(explode("\n", $data));
$new_lines = array_slice($split_data, 0, -1);
$lines = array_merge($lines, $new_lines);
$leftover = $split_data[count($split_data) - 1];
}
while(count($lines) < $line_count && ftell($fh) != 0);
if(ftell($fh) == 0){
$lines[] = $leftover;
}
fclose($fh);
// Usually, we will read too many lines, correct that here.
return [ 'lines' => array_slice($lines, 0, $line_count),
'offset' => $storeOffset
];
} | php | public static function last_lines($path, $line_count, $offset = 0, $block_size = 512){
$lines = array();
// we will always have a fragment of a non-complete line
// keep this in here till we have our next entire line.
$leftover = "";
$fh = fopen($path, 'r');
$storeOffset = $offset;
// go to the end of the file
fseek($fh, $offset, SEEK_END);
do{
// need to know whether we can actually go back
// $block_size bytes
$can_read = $block_size;
if(ftell($fh) < $block_size){
$can_read = ftell($fh);
}
$storeOffset -= $can_read;
// go back as many bytes as we can
// read them to $data and then move the file pointer
// back to where we were.
fseek($fh, -$can_read, SEEK_CUR);
$data = @fread($fh, $can_read);
$data .= $leftover;
fseek($fh, -$can_read, SEEK_CUR);
// split lines by \n. Then reverse them,
// now the last line is most likely not a complete
// line which is why we do not directly add it, but
// append it to the data read the next time.
$split_data = array_reverse(explode("\n", $data));
$new_lines = array_slice($split_data, 0, -1);
$lines = array_merge($lines, $new_lines);
$leftover = $split_data[count($split_data) - 1];
}
while(count($lines) < $line_count && ftell($fh) != 0);
if(ftell($fh) == 0){
$lines[] = $leftover;
}
fclose($fh);
// Usually, we will read too many lines, correct that here.
return [ 'lines' => array_slice($lines, 0, $line_count),
'offset' => $storeOffset
];
} | [
"public",
"static",
"function",
"last_lines",
"(",
"$",
"path",
",",
"$",
"line_count",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"block_size",
"=",
"512",
")",
"{",
"$",
"lines",
"=",
"array",
"(",
")",
";",
"// we will always have a fragment of a non-complete line",
"// keep this in here till we have our next entire line.",
"$",
"leftover",
"=",
"\"\"",
";",
"$",
"fh",
"=",
"fopen",
"(",
"$",
"path",
",",
"'r'",
")",
";",
"$",
"storeOffset",
"=",
"$",
"offset",
";",
"// go to the end of the file",
"fseek",
"(",
"$",
"fh",
",",
"$",
"offset",
",",
"SEEK_END",
")",
";",
"do",
"{",
"// need to know whether we can actually go back",
"// $block_size bytes",
"$",
"can_read",
"=",
"$",
"block_size",
";",
"if",
"(",
"ftell",
"(",
"$",
"fh",
")",
"<",
"$",
"block_size",
")",
"{",
"$",
"can_read",
"=",
"ftell",
"(",
"$",
"fh",
")",
";",
"}",
"$",
"storeOffset",
"-=",
"$",
"can_read",
";",
"// go back as many bytes as we can",
"// read them to $data and then move the file pointer",
"// back to where we were.",
"fseek",
"(",
"$",
"fh",
",",
"-",
"$",
"can_read",
",",
"SEEK_CUR",
")",
";",
"$",
"data",
"=",
"@",
"fread",
"(",
"$",
"fh",
",",
"$",
"can_read",
")",
";",
"$",
"data",
".=",
"$",
"leftover",
";",
"fseek",
"(",
"$",
"fh",
",",
"-",
"$",
"can_read",
",",
"SEEK_CUR",
")",
";",
"// split lines by \\n. Then reverse them,",
"// now the last line is most likely not a complete",
"// line which is why we do not directly add it, but",
"// append it to the data read the next time.",
"$",
"split_data",
"=",
"array_reverse",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
")",
")",
";",
"$",
"new_lines",
"=",
"array_slice",
"(",
"$",
"split_data",
",",
"0",
",",
"-",
"1",
")",
";",
"$",
"lines",
"=",
"array_merge",
"(",
"$",
"lines",
",",
"$",
"new_lines",
")",
";",
"$",
"leftover",
"=",
"$",
"split_data",
"[",
"count",
"(",
"$",
"split_data",
")",
"-",
"1",
"]",
";",
"}",
"while",
"(",
"count",
"(",
"$",
"lines",
")",
"<",
"$",
"line_count",
"&&",
"ftell",
"(",
"$",
"fh",
")",
"!=",
"0",
")",
";",
"if",
"(",
"ftell",
"(",
"$",
"fh",
")",
"==",
"0",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"leftover",
";",
"}",
"fclose",
"(",
"$",
"fh",
")",
";",
"// Usually, we will read too many lines, correct that here.",
"return",
"[",
"'lines'",
"=>",
"array_slice",
"(",
"$",
"lines",
",",
"0",
",",
"$",
"line_count",
")",
",",
"'offset'",
"=>",
"$",
"storeOffset",
"]",
";",
"}"
] | Shows the last lines of a text-file.
@param string $path
@param int $line_count
@param ont $offset (negative value from the end of file)
@param int $block_size
@return multitype: | [
"Shows",
"the",
"last",
"lines",
"of",
"a",
"text",
"-",
"file",
"."
] | df35d16403b5dbf0f7570daded6cfa26814ae7e0 | https://github.com/kkthek/diqa-util/blob/df35d16403b5dbf0f7570daded6cfa26814ae7e0/src/Util/FileUtils.php#L15-L60 | train |
ScaraMVC/Framework | src/Scara/Validation/Validator.php | Validator.getLang | private function getLang()
{
$path = $this->_config->get('langpath')
.$this->_config->get('lang');
if (file_exists($path.'/validation.php')) {
$this->_lang = require_once $path.'/validation.php';
} else {
$this->_lang = require_once $this->_config->get('langpath').'/en_US/validation.php';
}
// Handle any custom language validation values
// by parser
$this->_parser = new ValidationParser($this->_lang, $this->_config->get('validation'));
} | php | private function getLang()
{
$path = $this->_config->get('langpath')
.$this->_config->get('lang');
if (file_exists($path.'/validation.php')) {
$this->_lang = require_once $path.'/validation.php';
} else {
$this->_lang = require_once $this->_config->get('langpath').'/en_US/validation.php';
}
// Handle any custom language validation values
// by parser
$this->_parser = new ValidationParser($this->_lang, $this->_config->get('validation'));
} | [
"private",
"function",
"getLang",
"(",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_config",
"->",
"get",
"(",
"'langpath'",
")",
".",
"$",
"this",
"->",
"_config",
"->",
"get",
"(",
"'lang'",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
".",
"'/validation.php'",
")",
")",
"{",
"$",
"this",
"->",
"_lang",
"=",
"require_once",
"$",
"path",
".",
"'/validation.php'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_lang",
"=",
"require_once",
"$",
"this",
"->",
"_config",
"->",
"get",
"(",
"'langpath'",
")",
".",
"'/en_US/validation.php'",
";",
"}",
"// Handle any custom language validation values",
"// by parser",
"$",
"this",
"->",
"_parser",
"=",
"new",
"ValidationParser",
"(",
"$",
"this",
"->",
"_lang",
",",
"$",
"this",
"->",
"_config",
"->",
"get",
"(",
"'validation'",
")",
")",
";",
"}"
] | Gets the language pack.
@return void | [
"Gets",
"the",
"language",
"pack",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Validation/Validator.php#L63-L77 | train |
ScaraMVC/Framework | src/Scara/Validation/Validator.php | Validator.make | public function make($input, $rules = [])
{
$this->_input = $input;
foreach ($rules as $key => $value) {
$this->validateInput($input, $rules, $key);
}
return $this;
} | php | public function make($input, $rules = [])
{
$this->_input = $input;
foreach ($rules as $key => $value) {
$this->validateInput($input, $rules, $key);
}
return $this;
} | [
"public",
"function",
"make",
"(",
"$",
"input",
",",
"$",
"rules",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_input",
"=",
"$",
"input",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"validateInput",
"(",
"$",
"input",
",",
"$",
"rules",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Creates validation.
@param array $input - Form input array
@param array $rules - Validation rules
@return \Scara\Validation\Validator | [
"Creates",
"validation",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Validation/Validator.php#L87-L95 | train |
ScaraMVC/Framework | src/Scara/Validation/Validator.php | Validator.isValid | public function isValid()
{
$valid = true;
foreach ($this->_errors as $input => $message) {
foreach ($message as $item) {
if (!empty($item)) {
$valid = false;
}
}
}
foreach ($this->_input as $key => $value) {
\Session::delete('input.'.$key);
}
return $valid;
} | php | public function isValid()
{
$valid = true;
foreach ($this->_errors as $input => $message) {
foreach ($message as $item) {
if (!empty($item)) {
$valid = false;
}
}
}
foreach ($this->_input as $key => $value) {
\Session::delete('input.'.$key);
}
return $valid;
} | [
"public",
"function",
"isValid",
"(",
")",
"{",
"$",
"valid",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"_errors",
"as",
"$",
"input",
"=>",
"$",
"message",
")",
"{",
"foreach",
"(",
"$",
"message",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"item",
")",
")",
"{",
"$",
"valid",
"=",
"false",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_input",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"\\",
"Session",
"::",
"delete",
"(",
"'input.'",
".",
"$",
"key",
")",
";",
"}",
"return",
"$",
"valid",
";",
"}"
] | Checks to see if the validation passed.
@return bool | [
"Checks",
"to",
"see",
"if",
"the",
"validation",
"passed",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Validation/Validator.php#L102-L118 | train |
ScaraMVC/Framework | src/Scara/Validation/Validator.php | Validator.validateInput | private function validateInput($input, $rules, $key)
{
if (isset($input[$key]) && isset($rules[$key])) {
$ruleExp = explode('|', $rules[$key]);
foreach ($ruleExp as $rule) {
$this->parseRule($rule, $input, $key);
}
}
} | php | private function validateInput($input, $rules, $key)
{
if (isset($input[$key]) && isset($rules[$key])) {
$ruleExp = explode('|', $rules[$key]);
foreach ($ruleExp as $rule) {
$this->parseRule($rule, $input, $key);
}
}
} | [
"private",
"function",
"validateInput",
"(",
"$",
"input",
",",
"$",
"rules",
",",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"input",
"[",
"$",
"key",
"]",
")",
"&&",
"isset",
"(",
"$",
"rules",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"ruleExp",
"=",
"explode",
"(",
"'|'",
",",
"$",
"rules",
"[",
"$",
"key",
"]",
")",
";",
"foreach",
"(",
"$",
"ruleExp",
"as",
"$",
"rule",
")",
"{",
"$",
"this",
"->",
"parseRule",
"(",
"$",
"rule",
",",
"$",
"input",
",",
"$",
"key",
")",
";",
"}",
"}",
"}"
] | Validates the given input.
@param array $input - Form input array
@param array $rules - Validation rules
@param string $key - Validation option
@return void | [
"Validates",
"the",
"given",
"input",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Validation/Validator.php#L139-L148 | train |
ScaraMVC/Framework | src/Scara/Validation/Validator.php | Validator.parseRule | private function parseRule($rule, $input, $key)
{
$ruleExp = explode(':', $rule);
if (count($ruleExp) > 1) {
switch ($ruleExp[0]) {
case 'match':
$this->_errors[$key][] = $this->_parser->match($input, $key, $ruleExp[1], $this->_lang['match']);
break;
case 'min':
$this->_errors[$key][] = $this->_parser->min($input, $key, $ruleExp[1], $this->_lang['min']);
break;
case 'max':
$this->_errors[$key][] = $this->_parser->max($input, $key, $ruleExp[1], $this->_lang['max']);
break;
case 'from':
$this->_errors[$key][] = $this->_parser->from($input, $key, $rule, $this->_lang['from']);
break;
}
} else {
switch ($rule) {
case 'required':
$this->_errors[$key][] = $this->_parser->required($input, $key, $this->_lang['required']);
break;
case 'email':
$this->_errors[$key][] = $this->_parser->email($input, $key, $this->_lang['email']);
break;
case 'url':
$this->_errors[$key][] = $this->_parser->url($input, $key, $this->_lang['url']);
break;
}
}
} | php | private function parseRule($rule, $input, $key)
{
$ruleExp = explode(':', $rule);
if (count($ruleExp) > 1) {
switch ($ruleExp[0]) {
case 'match':
$this->_errors[$key][] = $this->_parser->match($input, $key, $ruleExp[1], $this->_lang['match']);
break;
case 'min':
$this->_errors[$key][] = $this->_parser->min($input, $key, $ruleExp[1], $this->_lang['min']);
break;
case 'max':
$this->_errors[$key][] = $this->_parser->max($input, $key, $ruleExp[1], $this->_lang['max']);
break;
case 'from':
$this->_errors[$key][] = $this->_parser->from($input, $key, $rule, $this->_lang['from']);
break;
}
} else {
switch ($rule) {
case 'required':
$this->_errors[$key][] = $this->_parser->required($input, $key, $this->_lang['required']);
break;
case 'email':
$this->_errors[$key][] = $this->_parser->email($input, $key, $this->_lang['email']);
break;
case 'url':
$this->_errors[$key][] = $this->_parser->url($input, $key, $this->_lang['url']);
break;
}
}
} | [
"private",
"function",
"parseRule",
"(",
"$",
"rule",
",",
"$",
"input",
",",
"$",
"key",
")",
"{",
"$",
"ruleExp",
"=",
"explode",
"(",
"':'",
",",
"$",
"rule",
")",
";",
"if",
"(",
"count",
"(",
"$",
"ruleExp",
")",
">",
"1",
")",
"{",
"switch",
"(",
"$",
"ruleExp",
"[",
"0",
"]",
")",
"{",
"case",
"'match'",
":",
"$",
"this",
"->",
"_errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"_parser",
"->",
"match",
"(",
"$",
"input",
",",
"$",
"key",
",",
"$",
"ruleExp",
"[",
"1",
"]",
",",
"$",
"this",
"->",
"_lang",
"[",
"'match'",
"]",
")",
";",
"break",
";",
"case",
"'min'",
":",
"$",
"this",
"->",
"_errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"_parser",
"->",
"min",
"(",
"$",
"input",
",",
"$",
"key",
",",
"$",
"ruleExp",
"[",
"1",
"]",
",",
"$",
"this",
"->",
"_lang",
"[",
"'min'",
"]",
")",
";",
"break",
";",
"case",
"'max'",
":",
"$",
"this",
"->",
"_errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"_parser",
"->",
"max",
"(",
"$",
"input",
",",
"$",
"key",
",",
"$",
"ruleExp",
"[",
"1",
"]",
",",
"$",
"this",
"->",
"_lang",
"[",
"'max'",
"]",
")",
";",
"break",
";",
"case",
"'from'",
":",
"$",
"this",
"->",
"_errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"_parser",
"->",
"from",
"(",
"$",
"input",
",",
"$",
"key",
",",
"$",
"rule",
",",
"$",
"this",
"->",
"_lang",
"[",
"'from'",
"]",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"switch",
"(",
"$",
"rule",
")",
"{",
"case",
"'required'",
":",
"$",
"this",
"->",
"_errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"_parser",
"->",
"required",
"(",
"$",
"input",
",",
"$",
"key",
",",
"$",
"this",
"->",
"_lang",
"[",
"'required'",
"]",
")",
";",
"break",
";",
"case",
"'email'",
":",
"$",
"this",
"->",
"_errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"_parser",
"->",
"email",
"(",
"$",
"input",
",",
"$",
"key",
",",
"$",
"this",
"->",
"_lang",
"[",
"'email'",
"]",
")",
";",
"break",
";",
"case",
"'url'",
":",
"$",
"this",
"->",
"_errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"_parser",
"->",
"url",
"(",
"$",
"input",
",",
"$",
"key",
",",
"$",
"this",
"->",
"_lang",
"[",
"'url'",
"]",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Parses a given rule with the given input.
@param string $rule - The rule being parsed
@param array $input - Form input array
@param string $key - Validation option | [
"Parses",
"a",
"given",
"rule",
"with",
"the",
"given",
"input",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Validation/Validator.php#L157-L188 | train |
ApatisArchive/ArrayStorage | src/Collection.php | Collection.sort | public function sort($sort = null)
{
if ($sort !== null && ! is_int($sort)) {
throw new \InvalidArgumentException(
'Invalid sort type. Sort type must ne integer.',
E_USER_ERROR
);
}
return $sort === null
? sort($this->storedData)
: sort($this->storedData, $sort);
} | php | public function sort($sort = null)
{
if ($sort !== null && ! is_int($sort)) {
throw new \InvalidArgumentException(
'Invalid sort type. Sort type must ne integer.',
E_USER_ERROR
);
}
return $sort === null
? sort($this->storedData)
: sort($this->storedData, $sort);
} | [
"public",
"function",
"sort",
"(",
"$",
"sort",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"sort",
"!==",
"null",
"&&",
"!",
"is_int",
"(",
"$",
"sort",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid sort type. Sort type must ne integer.'",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"$",
"sort",
"===",
"null",
"?",
"sort",
"(",
"$",
"this",
"->",
"storedData",
")",
":",
"sort",
"(",
"$",
"this",
"->",
"storedData",
",",
"$",
"sort",
")",
";",
"}"
] | Sort an array collection
@param null|int $sort
@return bool
@throws \InvalidArgumentException | [
"Sort",
"an",
"array",
"collection"
] | 4f6515164352f2997275278b89884fc1e885e7d9 | https://github.com/ApatisArchive/ArrayStorage/blob/4f6515164352f2997275278b89884fc1e885e7d9/src/Collection.php#L264-L276 | train |
ekyna/Table | Registry.php | Registry.resolveColumnType | private function resolveColumnType(Column\ColumnTypeInterface $type)
{
$typeExtensions = [];
$parentType = $type->getParent();
$class = get_class($type);
foreach ($this->extensions as $extension) {
$typeExtensions = array_merge(
$typeExtensions,
$extension->getColumnTypeExtensions($class)
);
}
return $this->resolvedTypeFactory->createResolvedColumnType(
$type,
$typeExtensions,
$parentType ? $this->getColumnType($parentType) : null
);
} | php | private function resolveColumnType(Column\ColumnTypeInterface $type)
{
$typeExtensions = [];
$parentType = $type->getParent();
$class = get_class($type);
foreach ($this->extensions as $extension) {
$typeExtensions = array_merge(
$typeExtensions,
$extension->getColumnTypeExtensions($class)
);
}
return $this->resolvedTypeFactory->createResolvedColumnType(
$type,
$typeExtensions,
$parentType ? $this->getColumnType($parentType) : null
);
} | [
"private",
"function",
"resolveColumnType",
"(",
"Column",
"\\",
"ColumnTypeInterface",
"$",
"type",
")",
"{",
"$",
"typeExtensions",
"=",
"[",
"]",
";",
"$",
"parentType",
"=",
"$",
"type",
"->",
"getParent",
"(",
")",
";",
"$",
"class",
"=",
"get_class",
"(",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"typeExtensions",
"=",
"array_merge",
"(",
"$",
"typeExtensions",
",",
"$",
"extension",
"->",
"getColumnTypeExtensions",
"(",
"$",
"class",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resolvedTypeFactory",
"->",
"createResolvedColumnType",
"(",
"$",
"type",
",",
"$",
"typeExtensions",
",",
"$",
"parentType",
"?",
"$",
"this",
"->",
"getColumnType",
"(",
"$",
"parentType",
")",
":",
"null",
")",
";",
"}"
] | Wraps a type into a ResolvedColumnTypeInterface implementation
and connects it with its parent type.
@param Column\ColumnTypeInterface $type The type to resolve
@return Column\ResolvedColumnTypeInterface The resolved type | [
"Wraps",
"a",
"type",
"into",
"a",
"ResolvedColumnTypeInterface",
"implementation",
"and",
"connects",
"it",
"with",
"its",
"parent",
"type",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Registry.php#L181-L199 | train |
ekyna/Table | Registry.php | Registry.resolveFilterType | private function resolveFilterType(Filter\FilterTypeInterface $type)
{
$typeExtensions = [];
$parentType = $type->getParent();
$class = get_class($type);
foreach ($this->extensions as $extension) {
$typeExtensions = array_merge(
$typeExtensions,
$extension->getFilterTypeExtensions($class)
);
}
return $this->resolvedTypeFactory->createResolvedFilterType(
$type,
$typeExtensions,
$parentType ? $this->getFilterType($parentType) : null
);
} | php | private function resolveFilterType(Filter\FilterTypeInterface $type)
{
$typeExtensions = [];
$parentType = $type->getParent();
$class = get_class($type);
foreach ($this->extensions as $extension) {
$typeExtensions = array_merge(
$typeExtensions,
$extension->getFilterTypeExtensions($class)
);
}
return $this->resolvedTypeFactory->createResolvedFilterType(
$type,
$typeExtensions,
$parentType ? $this->getFilterType($parentType) : null
);
} | [
"private",
"function",
"resolveFilterType",
"(",
"Filter",
"\\",
"FilterTypeInterface",
"$",
"type",
")",
"{",
"$",
"typeExtensions",
"=",
"[",
"]",
";",
"$",
"parentType",
"=",
"$",
"type",
"->",
"getParent",
"(",
")",
";",
"$",
"class",
"=",
"get_class",
"(",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"typeExtensions",
"=",
"array_merge",
"(",
"$",
"typeExtensions",
",",
"$",
"extension",
"->",
"getFilterTypeExtensions",
"(",
"$",
"class",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resolvedTypeFactory",
"->",
"createResolvedFilterType",
"(",
"$",
"type",
",",
"$",
"typeExtensions",
",",
"$",
"parentType",
"?",
"$",
"this",
"->",
"getFilterType",
"(",
"$",
"parentType",
")",
":",
"null",
")",
";",
"}"
] | Wraps a type into a ResolvedFilterTypeInterface implementation
and connects it with its parent type.
@param Filter\FilterTypeInterface $type The type to resolve
@return Filter\ResolvedFilterTypeInterface The resolved type | [
"Wraps",
"a",
"type",
"into",
"a",
"ResolvedFilterTypeInterface",
"implementation",
"and",
"connects",
"it",
"with",
"its",
"parent",
"type",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Registry.php#L257-L275 | train |
ekyna/Table | Registry.php | Registry.resolveActionType | private function resolveActionType(Action\ActionTypeInterface $type)
{
$typeExtensions = [];
$parentType = $type->getParent();
$class = get_class($type);
foreach ($this->extensions as $extension) {
$typeExtensions = array_merge(
$typeExtensions,
$extension->getActionTypeExtensions($class)
);
}
return $this->resolvedTypeFactory->createResolvedActionType(
$type,
$typeExtensions,
$parentType ? $this->getActionType($parentType) : null
);
} | php | private function resolveActionType(Action\ActionTypeInterface $type)
{
$typeExtensions = [];
$parentType = $type->getParent();
$class = get_class($type);
foreach ($this->extensions as $extension) {
$typeExtensions = array_merge(
$typeExtensions,
$extension->getActionTypeExtensions($class)
);
}
return $this->resolvedTypeFactory->createResolvedActionType(
$type,
$typeExtensions,
$parentType ? $this->getActionType($parentType) : null
);
} | [
"private",
"function",
"resolveActionType",
"(",
"Action",
"\\",
"ActionTypeInterface",
"$",
"type",
")",
"{",
"$",
"typeExtensions",
"=",
"[",
"]",
";",
"$",
"parentType",
"=",
"$",
"type",
"->",
"getParent",
"(",
")",
";",
"$",
"class",
"=",
"get_class",
"(",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"typeExtensions",
"=",
"array_merge",
"(",
"$",
"typeExtensions",
",",
"$",
"extension",
"->",
"getActionTypeExtensions",
"(",
"$",
"class",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resolvedTypeFactory",
"->",
"createResolvedActionType",
"(",
"$",
"type",
",",
"$",
"typeExtensions",
",",
"$",
"parentType",
"?",
"$",
"this",
"->",
"getActionType",
"(",
"$",
"parentType",
")",
":",
"null",
")",
";",
"}"
] | Wraps a type into a ResolvedActionTypeInterface implementation
and connects it with its parent type.
@param Action\ActionTypeInterface $type The type to resolve
@return Action\ResolvedActionTypeInterface The resolved type | [
"Wraps",
"a",
"type",
"into",
"a",
"ResolvedActionTypeInterface",
"implementation",
"and",
"connects",
"it",
"with",
"its",
"parent",
"type",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Registry.php#L333-L351 | train |
fulgurio/LightCMSBundle | Controller/AdminMenuController.php | AdminMenuController.upAction | public function upAction($pageId, $menuName)
{
$pageMenuRepo = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMenu');
$pageMenu = $pageMenuRepo->findOneBy(array('page' => $pageId, 'label' => $menuName));
$position = $pageMenu->getPosition();
if ($position > 1)
{
$pageMenuRepo->downMenuPagesPosition($menuName, $position - 1, $position);
$pageMenu->setPosition($position - 1);
$em = $this->getDoctrine()->getManager();
$em->persist($pageMenu);
$em->flush();
$this->get('session')->getFlashBag()->add(
'notice',
$this->get('translator')->trans('fulgurio.lightcms.menus.moving_success_msg', array(), 'admin'));
}
return $this->redirect($this->generateUrl('AdminMenus'));
} | php | public function upAction($pageId, $menuName)
{
$pageMenuRepo = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMenu');
$pageMenu = $pageMenuRepo->findOneBy(array('page' => $pageId, 'label' => $menuName));
$position = $pageMenu->getPosition();
if ($position > 1)
{
$pageMenuRepo->downMenuPagesPosition($menuName, $position - 1, $position);
$pageMenu->setPosition($position - 1);
$em = $this->getDoctrine()->getManager();
$em->persist($pageMenu);
$em->flush();
$this->get('session')->getFlashBag()->add(
'notice',
$this->get('translator')->trans('fulgurio.lightcms.menus.moving_success_msg', array(), 'admin'));
}
return $this->redirect($this->generateUrl('AdminMenus'));
} | [
"public",
"function",
"upAction",
"(",
"$",
"pageId",
",",
"$",
"menuName",
")",
"{",
"$",
"pageMenuRepo",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"'FulgurioLightCMSBundle:PageMenu'",
")",
";",
"$",
"pageMenu",
"=",
"$",
"pageMenuRepo",
"->",
"findOneBy",
"(",
"array",
"(",
"'page'",
"=>",
"$",
"pageId",
",",
"'label'",
"=>",
"$",
"menuName",
")",
")",
";",
"$",
"position",
"=",
"$",
"pageMenu",
"->",
"getPosition",
"(",
")",
";",
"if",
"(",
"$",
"position",
">",
"1",
")",
"{",
"$",
"pageMenuRepo",
"->",
"downMenuPagesPosition",
"(",
"$",
"menuName",
",",
"$",
"position",
"-",
"1",
",",
"$",
"position",
")",
";",
"$",
"pageMenu",
"->",
"setPosition",
"(",
"$",
"position",
"-",
"1",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"pageMenu",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'notice'",
",",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'fulgurio.lightcms.menus.moving_success_msg'",
",",
"array",
"(",
")",
",",
"'admin'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'AdminMenus'",
")",
")",
";",
"}"
] | Move up page position in menu
@param number $pageId
@param string $menuName
@return | [
"Move",
"up",
"page",
"position",
"in",
"menu"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Controller/AdminMenuController.php#L46-L63 | train |
fulgurio/LightCMSBundle | Controller/AdminMenuController.php | AdminMenuController.changePositionAction | public function changePositionAction($pageId, $menuName, $newPosition)
{
if ($this->getRequest()->isXmlHttpRequest())
{
$pageMenuRepo = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMenu');
$pageMenu = $pageMenuRepo->findOneBy(array('page' => $pageId, 'label' => $menuName));
if ($pageMenu)
{
if ($newPosition == $pageMenu->getPosition())
{
// No change
}
else if ($newPosition > $pageMenu->getPosition())
{
if ($newPosition <= $pageMenuRepo->getLastMenuPosition($pageMenu->getLabel()))
{
// Down !
$pageMenuRepo->upMenuPagesPosition($pageMenu->getLabel(), $pageMenu->getPosition() + 1, $newPosition);
$pageMenu->setPosition($newPosition);
$em = $this->getDoctrine()->getManager();
$em->persist($pageMenu);
$em->flush();
}
}
else if ($pageMenu->getPosition() > 1)
{
// Up !
$pageMenuRepo->downMenuPagesPosition($pageMenu->getLabel(), $newPosition, $pageMenu->getPosition());
$pageMenu->setPosition($newPosition);
$em = $this->getDoctrine()->getManager();
$em->persist($pageMenu);
$em->flush();
}
else {
// doesn t happen
}
}
return new Response();
}
throw new AccessDeniedException();
} | php | public function changePositionAction($pageId, $menuName, $newPosition)
{
if ($this->getRequest()->isXmlHttpRequest())
{
$pageMenuRepo = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMenu');
$pageMenu = $pageMenuRepo->findOneBy(array('page' => $pageId, 'label' => $menuName));
if ($pageMenu)
{
if ($newPosition == $pageMenu->getPosition())
{
// No change
}
else if ($newPosition > $pageMenu->getPosition())
{
if ($newPosition <= $pageMenuRepo->getLastMenuPosition($pageMenu->getLabel()))
{
// Down !
$pageMenuRepo->upMenuPagesPosition($pageMenu->getLabel(), $pageMenu->getPosition() + 1, $newPosition);
$pageMenu->setPosition($newPosition);
$em = $this->getDoctrine()->getManager();
$em->persist($pageMenu);
$em->flush();
}
}
else if ($pageMenu->getPosition() > 1)
{
// Up !
$pageMenuRepo->downMenuPagesPosition($pageMenu->getLabel(), $newPosition, $pageMenu->getPosition());
$pageMenu->setPosition($newPosition);
$em = $this->getDoctrine()->getManager();
$em->persist($pageMenu);
$em->flush();
}
else {
// doesn t happen
}
}
return new Response();
}
throw new AccessDeniedException();
} | [
"public",
"function",
"changePositionAction",
"(",
"$",
"pageId",
",",
"$",
"menuName",
",",
"$",
"newPosition",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"$",
"pageMenuRepo",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"'FulgurioLightCMSBundle:PageMenu'",
")",
";",
"$",
"pageMenu",
"=",
"$",
"pageMenuRepo",
"->",
"findOneBy",
"(",
"array",
"(",
"'page'",
"=>",
"$",
"pageId",
",",
"'label'",
"=>",
"$",
"menuName",
")",
")",
";",
"if",
"(",
"$",
"pageMenu",
")",
"{",
"if",
"(",
"$",
"newPosition",
"==",
"$",
"pageMenu",
"->",
"getPosition",
"(",
")",
")",
"{",
"// No change",
"}",
"else",
"if",
"(",
"$",
"newPosition",
">",
"$",
"pageMenu",
"->",
"getPosition",
"(",
")",
")",
"{",
"if",
"(",
"$",
"newPosition",
"<=",
"$",
"pageMenuRepo",
"->",
"getLastMenuPosition",
"(",
"$",
"pageMenu",
"->",
"getLabel",
"(",
")",
")",
")",
"{",
"// Down !",
"$",
"pageMenuRepo",
"->",
"upMenuPagesPosition",
"(",
"$",
"pageMenu",
"->",
"getLabel",
"(",
")",
",",
"$",
"pageMenu",
"->",
"getPosition",
"(",
")",
"+",
"1",
",",
"$",
"newPosition",
")",
";",
"$",
"pageMenu",
"->",
"setPosition",
"(",
"$",
"newPosition",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"pageMenu",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"pageMenu",
"->",
"getPosition",
"(",
")",
">",
"1",
")",
"{",
"// Up !",
"$",
"pageMenuRepo",
"->",
"downMenuPagesPosition",
"(",
"$",
"pageMenu",
"->",
"getLabel",
"(",
")",
",",
"$",
"newPosition",
",",
"$",
"pageMenu",
"->",
"getPosition",
"(",
")",
")",
";",
"$",
"pageMenu",
"->",
"setPosition",
"(",
"$",
"newPosition",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"pageMenu",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"else",
"{",
"// doesn t happen",
"}",
"}",
"return",
"new",
"Response",
"(",
")",
";",
"}",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}"
] | Change position of page in menu, in ajax
@throws AccessDeniedException
@param number $pageId
@param string $menuName
@param number $newPosition
@return Response | [
"Change",
"position",
"of",
"page",
"in",
"menu",
"in",
"ajax"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Controller/AdminMenuController.php#L100-L140 | train |
bytic/MediaLibrary | src/Media/Traits/FileMethodsTrait.php | FileMethodsTrait.getPath | public function getPath(string $conversionName = ''): string
{
if (!$this->hasFile()) {
throw new Exception('Error getting path for media with no file');
}
$path = $this->getFile()->getPath();
if ($conversionName) {
$path = $this->getBasePath()
. DIRECTORY_SEPARATOR . $conversionName
. DIRECTORY_SEPARATOR . $this->getName();
}
return $path;
} | php | public function getPath(string $conversionName = ''): string
{
if (!$this->hasFile()) {
throw new Exception('Error getting path for media with no file');
}
$path = $this->getFile()->getPath();
if ($conversionName) {
$path = $this->getBasePath()
. DIRECTORY_SEPARATOR . $conversionName
. DIRECTORY_SEPARATOR . $this->getName();
}
return $path;
} | [
"public",
"function",
"getPath",
"(",
"string",
"$",
"conversionName",
"=",
"''",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasFile",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Error getting path for media with no file'",
")",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"getFile",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"conversionName",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getBasePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"conversionName",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Get the path to the original media file.
@param string $conversionName
@return string
@throws Exception | [
"Get",
"the",
"path",
"to",
"the",
"original",
"media",
"file",
"."
] | c52783e726b512184bd72e04d829d6f93242a61d | https://github.com/bytic/MediaLibrary/blob/c52783e726b512184bd72e04d829d6f93242a61d/src/Media/Traits/FileMethodsTrait.php#L92-L107 | train |
ptlis/grep-db | src/Metadata/MySQL/TableMetadata.php | TableMetadata.getColumnMetadata | public function getColumnMetadata(string $columnName): ColumnMetadata
{
if (!array_key_exists($columnName, $this->columnMetadataList)) {
throw new \RuntimeException('Table "' . $this->tableName . '" doesn\'t contain column "' . $columnName . '"');
}
return $this->columnMetadataList[$columnName];
} | php | public function getColumnMetadata(string $columnName): ColumnMetadata
{
if (!array_key_exists($columnName, $this->columnMetadataList)) {
throw new \RuntimeException('Table "' . $this->tableName . '" doesn\'t contain column "' . $columnName . '"');
}
return $this->columnMetadataList[$columnName];
} | [
"public",
"function",
"getColumnMetadata",
"(",
"string",
"$",
"columnName",
")",
":",
"ColumnMetadata",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"columnName",
",",
"$",
"this",
"->",
"columnMetadataList",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Table \"'",
".",
"$",
"this",
"->",
"tableName",
".",
"'\" doesn\\'t contain column \"'",
".",
"$",
"columnName",
".",
"'\"'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"columnMetadataList",
"[",
"$",
"columnName",
"]",
";",
"}"
] | Get the metadata for a single column.
@throws \RuntimeException when the column does not exist. | [
"Get",
"the",
"metadata",
"for",
"a",
"single",
"column",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Metadata/MySQL/TableMetadata.php#L103-L110 | train |
ptlis/grep-db | src/Metadata/MySQL/TableMetadata.php | TableMetadata.hasStringTypeColumn | public function hasStringTypeColumn(): bool
{
$hasStringType = false;
foreach ($this->columnMetadataList as $columnMetadata) {
$hasStringType = $hasStringType || $columnMetadata->isStringType();
}
return $hasStringType;
} | php | public function hasStringTypeColumn(): bool
{
$hasStringType = false;
foreach ($this->columnMetadataList as $columnMetadata) {
$hasStringType = $hasStringType || $columnMetadata->isStringType();
}
return $hasStringType;
} | [
"public",
"function",
"hasStringTypeColumn",
"(",
")",
":",
"bool",
"{",
"$",
"hasStringType",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"columnMetadataList",
"as",
"$",
"columnMetadata",
")",
"{",
"$",
"hasStringType",
"=",
"$",
"hasStringType",
"||",
"$",
"columnMetadata",
"->",
"isStringType",
"(",
")",
";",
"}",
"return",
"$",
"hasStringType",
";",
"}"
] | Returns true if the table has at least one column that is a string type. | [
"Returns",
"true",
"if",
"the",
"table",
"has",
"at",
"least",
"one",
"column",
"that",
"is",
"a",
"string",
"type",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Metadata/MySQL/TableMetadata.php#L125-L132 | train |
ptlis/grep-db | src/Metadata/MySQL/TableMetadata.php | TableMetadata.getPrimaryKeyMetadata | public function getPrimaryKeyMetadata(): ?ColumnMetadata
{
$filteredColumnList = array_filter($this->columnMetadataList, function (ColumnMetadata $columnMetadata) {
return $columnMetadata->isPrimaryKey();
});
return (count($filteredColumnList)) ? current($filteredColumnList) : null;
} | php | public function getPrimaryKeyMetadata(): ?ColumnMetadata
{
$filteredColumnList = array_filter($this->columnMetadataList, function (ColumnMetadata $columnMetadata) {
return $columnMetadata->isPrimaryKey();
});
return (count($filteredColumnList)) ? current($filteredColumnList) : null;
} | [
"public",
"function",
"getPrimaryKeyMetadata",
"(",
")",
":",
"?",
"ColumnMetadata",
"{",
"$",
"filteredColumnList",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"columnMetadataList",
",",
"function",
"(",
"ColumnMetadata",
"$",
"columnMetadata",
")",
"{",
"return",
"$",
"columnMetadata",
"->",
"isPrimaryKey",
"(",
")",
";",
"}",
")",
";",
"return",
"(",
"count",
"(",
"$",
"filteredColumnList",
")",
")",
"?",
"current",
"(",
"$",
"filteredColumnList",
")",
":",
"null",
";",
"}"
] | Returns the primary key column metadata. | [
"Returns",
"the",
"primary",
"key",
"column",
"metadata",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Metadata/MySQL/TableMetadata.php#L137-L144 | train |
erenmustafaozdal/laravel-modules-base | src/Repositories/ImageRepository.php | ImageRepository.moveImage | public function moveImage($photo, $photoKey, $model, $request)
{
$path = $this->getUploadPath($model);
$photos['fileName'] = $this->fileName;
$photos['fileSize'] = $this->fileSize;
$photos['original'] = $this->original($photo, $path['original']);
$photos['thumbnails'] = $this->thumbnails($photo, $photoKey, $path['thumbnails'], $request);
return $photos;
} | php | public function moveImage($photo, $photoKey, $model, $request)
{
$path = $this->getUploadPath($model);
$photos['fileName'] = $this->fileName;
$photos['fileSize'] = $this->fileSize;
$photos['original'] = $this->original($photo, $path['original']);
$photos['thumbnails'] = $this->thumbnails($photo, $photoKey, $path['thumbnails'], $request);
return $photos;
} | [
"public",
"function",
"moveImage",
"(",
"$",
"photo",
",",
"$",
"photoKey",
",",
"$",
"model",
",",
"$",
"request",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getUploadPath",
"(",
"$",
"model",
")",
";",
"$",
"photos",
"[",
"'fileName'",
"]",
"=",
"$",
"this",
"->",
"fileName",
";",
"$",
"photos",
"[",
"'fileSize'",
"]",
"=",
"$",
"this",
"->",
"fileSize",
";",
"$",
"photos",
"[",
"'original'",
"]",
"=",
"$",
"this",
"->",
"original",
"(",
"$",
"photo",
",",
"$",
"path",
"[",
"'original'",
"]",
")",
";",
"$",
"photos",
"[",
"'thumbnails'",
"]",
"=",
"$",
"this",
"->",
"thumbnails",
"(",
"$",
"photo",
",",
"$",
"photoKey",
",",
"$",
"path",
"[",
"'thumbnails'",
"]",
",",
"$",
"request",
")",
";",
"return",
"$",
"photos",
";",
"}"
] | move upload image
@param $photo
@param integer $photoKey
@param \Illuminate\Database\Eloquent\Model $model
@param \Illuminate\Http\Request $request
@return array | [
"move",
"upload",
"image"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Repositories/ImageRepository.php#L59-L68 | train |
erenmustafaozdal/laravel-modules-base | src/Repositories/ImageRepository.php | ImageRepository.getUploadPath | public function getUploadPath($model)
{
$path = $this->options['path'] . '/' . $model->id;
$paths = [];
$paths['original'] = $path . '/original';
$paths['thumbnails'] = $path . '/thumbnails';
return $paths;
} | php | public function getUploadPath($model)
{
$path = $this->options['path'] . '/' . $model->id;
$paths = [];
$paths['original'] = $path . '/original';
$paths['thumbnails'] = $path . '/thumbnails';
return $paths;
} | [
"public",
"function",
"getUploadPath",
"(",
"$",
"model",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"options",
"[",
"'path'",
"]",
".",
"'/'",
".",
"$",
"model",
"->",
"id",
";",
"$",
"paths",
"=",
"[",
"]",
";",
"$",
"paths",
"[",
"'original'",
"]",
"=",
"$",
"path",
".",
"'/original'",
";",
"$",
"paths",
"[",
"'thumbnails'",
"]",
"=",
"$",
"path",
".",
"'/thumbnails'",
";",
"return",
"$",
"paths",
";",
"}"
] | get upload path
@param $model
@return string|\Illuminate\Support\Collection | [
"get",
"upload",
"path"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Repositories/ImageRepository.php#L76-L84 | train |
erenmustafaozdal/laravel-modules-base | src/Repositories/ImageRepository.php | ImageRepository.getCropTypeSize | public function getCropTypeSize($thumbnail,$crop_type)
{
if ($crop_type === 'square') {
return [
'width' => $thumbnail['width'],
'height' => $thumbnail['width']
];
}
$ratio = $thumbnail['width'] / $thumbnail['height'];
if ($crop_type === 'vertical') {
return [
'width' => $ratio == 1 || $ratio < 1 ? $thumbnail['width'] : $thumbnail['height'],
'height' => $ratio == 1 ? $thumbnail['width'] / $this->options['vertical_ratio'] : ($ratio < 1 ? $thumbnail['height'] : $thumbnail['width'])
];
}
return [
'width' => $ratio == 1 || $ratio > 1 ? $thumbnail['width'] : $thumbnail['height'],
'height' => $ratio == 1 ? $thumbnail['width'] / $this->options['horizontal_ratio'] : ($ratio > 1 ? $thumbnail['height'] : $thumbnail['width'])
];
} | php | public function getCropTypeSize($thumbnail,$crop_type)
{
if ($crop_type === 'square') {
return [
'width' => $thumbnail['width'],
'height' => $thumbnail['width']
];
}
$ratio = $thumbnail['width'] / $thumbnail['height'];
if ($crop_type === 'vertical') {
return [
'width' => $ratio == 1 || $ratio < 1 ? $thumbnail['width'] : $thumbnail['height'],
'height' => $ratio == 1 ? $thumbnail['width'] / $this->options['vertical_ratio'] : ($ratio < 1 ? $thumbnail['height'] : $thumbnail['width'])
];
}
return [
'width' => $ratio == 1 || $ratio > 1 ? $thumbnail['width'] : $thumbnail['height'],
'height' => $ratio == 1 ? $thumbnail['width'] / $this->options['horizontal_ratio'] : ($ratio > 1 ? $thumbnail['height'] : $thumbnail['width'])
];
} | [
"public",
"function",
"getCropTypeSize",
"(",
"$",
"thumbnail",
",",
"$",
"crop_type",
")",
"{",
"if",
"(",
"$",
"crop_type",
"===",
"'square'",
")",
"{",
"return",
"[",
"'width'",
"=>",
"$",
"thumbnail",
"[",
"'width'",
"]",
",",
"'height'",
"=>",
"$",
"thumbnail",
"[",
"'width'",
"]",
"]",
";",
"}",
"$",
"ratio",
"=",
"$",
"thumbnail",
"[",
"'width'",
"]",
"/",
"$",
"thumbnail",
"[",
"'height'",
"]",
";",
"if",
"(",
"$",
"crop_type",
"===",
"'vertical'",
")",
"{",
"return",
"[",
"'width'",
"=>",
"$",
"ratio",
"==",
"1",
"||",
"$",
"ratio",
"<",
"1",
"?",
"$",
"thumbnail",
"[",
"'width'",
"]",
":",
"$",
"thumbnail",
"[",
"'height'",
"]",
",",
"'height'",
"=>",
"$",
"ratio",
"==",
"1",
"?",
"$",
"thumbnail",
"[",
"'width'",
"]",
"/",
"$",
"this",
"->",
"options",
"[",
"'vertical_ratio'",
"]",
":",
"(",
"$",
"ratio",
"<",
"1",
"?",
"$",
"thumbnail",
"[",
"'height'",
"]",
":",
"$",
"thumbnail",
"[",
"'width'",
"]",
")",
"]",
";",
"}",
"return",
"[",
"'width'",
"=>",
"$",
"ratio",
"==",
"1",
"||",
"$",
"ratio",
">",
"1",
"?",
"$",
"thumbnail",
"[",
"'width'",
"]",
":",
"$",
"thumbnail",
"[",
"'height'",
"]",
",",
"'height'",
"=>",
"$",
"ratio",
"==",
"1",
"?",
"$",
"thumbnail",
"[",
"'width'",
"]",
"/",
"$",
"this",
"->",
"options",
"[",
"'horizontal_ratio'",
"]",
":",
"(",
"$",
"ratio",
">",
"1",
"?",
"$",
"thumbnail",
"[",
"'height'",
"]",
":",
"$",
"thumbnail",
"[",
"'width'",
"]",
")",
"]",
";",
"}"
] | get crop type size
@param array $thumbnail
@param string $crop_type
@return array | [
"get",
"crop",
"type",
"size"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Repositories/ImageRepository.php#L163-L184 | train |
erenmustafaozdal/laravel-modules-base | src/Repositories/ImageRepository.php | ImageRepository.getSizeParameters | private function getSizeParameters($request)
{
$input = isset($this->options['group'])
? "{$this->options['group']}.{$this->options['index']}"
: (isset($this->options['inputPrefix']) && $this->options['inputPrefix'] ? "{$this->options['inputPrefix']}" : '');
return [
'x' => is_array($request->input("{$input}x"))
? $request->input("{$input}x")
: [$request->input("{$input}x")],
'y' => is_array($request->input("{$input}y"))
? $request->input("{$input}y")
: [$request->input("{$input}y")],
'width' => is_array($request->input("{$input}width"))
? $request->input("{$input}width")
: [$request->input("{$input}width")],
'height'=> is_array($request->input("{$input}height"))
? $request->input("{$input}height")
: [$request->input("{$input}height")],
];
} | php | private function getSizeParameters($request)
{
$input = isset($this->options['group'])
? "{$this->options['group']}.{$this->options['index']}"
: (isset($this->options['inputPrefix']) && $this->options['inputPrefix'] ? "{$this->options['inputPrefix']}" : '');
return [
'x' => is_array($request->input("{$input}x"))
? $request->input("{$input}x")
: [$request->input("{$input}x")],
'y' => is_array($request->input("{$input}y"))
? $request->input("{$input}y")
: [$request->input("{$input}y")],
'width' => is_array($request->input("{$input}width"))
? $request->input("{$input}width")
: [$request->input("{$input}width")],
'height'=> is_array($request->input("{$input}height"))
? $request->input("{$input}height")
: [$request->input("{$input}height")],
];
} | [
"private",
"function",
"getSizeParameters",
"(",
"$",
"request",
")",
"{",
"$",
"input",
"=",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'group'",
"]",
")",
"?",
"\"{$this->options['group']}.{$this->options['index']}\"",
":",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'inputPrefix'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'inputPrefix'",
"]",
"?",
"\"{$this->options['inputPrefix']}\"",
":",
"''",
")",
";",
"return",
"[",
"'x'",
"=>",
"is_array",
"(",
"$",
"request",
"->",
"input",
"(",
"\"{$input}x\"",
")",
")",
"?",
"$",
"request",
"->",
"input",
"(",
"\"{$input}x\"",
")",
":",
"[",
"$",
"request",
"->",
"input",
"(",
"\"{$input}x\"",
")",
"]",
",",
"'y'",
"=>",
"is_array",
"(",
"$",
"request",
"->",
"input",
"(",
"\"{$input}y\"",
")",
")",
"?",
"$",
"request",
"->",
"input",
"(",
"\"{$input}y\"",
")",
":",
"[",
"$",
"request",
"->",
"input",
"(",
"\"{$input}y\"",
")",
"]",
",",
"'width'",
"=>",
"is_array",
"(",
"$",
"request",
"->",
"input",
"(",
"\"{$input}width\"",
")",
")",
"?",
"$",
"request",
"->",
"input",
"(",
"\"{$input}width\"",
")",
":",
"[",
"$",
"request",
"->",
"input",
"(",
"\"{$input}width\"",
")",
"]",
",",
"'height'",
"=>",
"is_array",
"(",
"$",
"request",
"->",
"input",
"(",
"\"{$input}height\"",
")",
")",
"?",
"$",
"request",
"->",
"input",
"(",
"\"{$input}height\"",
")",
":",
"[",
"$",
"request",
"->",
"input",
"(",
"\"{$input}height\"",
")",
"]",
",",
"]",
";",
"}"
] | get size request parameter
@param $request
@return array | [
"get",
"size",
"request",
"parameter"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Repositories/ImageRepository.php#L192-L211 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/Request.php | Request.allFiles | public function allFiles()
{
$files = $this->files->all();
return $this->convertedFiles ? $this->convertedFiles : $this->convertedFiles = $this->convertUploadedFiles( $files );
} | php | public function allFiles()
{
$files = $this->files->all();
return $this->convertedFiles ? $this->convertedFiles : $this->convertedFiles = $this->convertUploadedFiles( $files );
} | [
"public",
"function",
"allFiles",
"(",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"files",
"->",
"all",
"(",
")",
";",
"return",
"$",
"this",
"->",
"convertedFiles",
"?",
"$",
"this",
"->",
"convertedFiles",
":",
"$",
"this",
"->",
"convertedFiles",
"=",
"$",
"this",
"->",
"convertUploadedFiles",
"(",
"$",
"files",
")",
";",
"}"
] | Get an array of all of the files on the request.
@return array | [
"Get",
"an",
"array",
"of",
"all",
"of",
"the",
"files",
"on",
"the",
"request",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Request.php#L452-L457 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/Request.php | Request.convertUploadedFiles | protected function convertUploadedFiles( array $files )
{
return array_map( function ( $file )
{
if ( is_null( $file ) || ( is_array( $file ) && empty( array_filter( $file ) ) ) )
return $file;
return is_array( $file ) ? $this->convertUploadedFiles( $file ) : UploadedFile::createFromBase( $file );
}, $files );
} | php | protected function convertUploadedFiles( array $files )
{
return array_map( function ( $file )
{
if ( is_null( $file ) || ( is_array( $file ) && empty( array_filter( $file ) ) ) )
return $file;
return is_array( $file ) ? $this->convertUploadedFiles( $file ) : UploadedFile::createFromBase( $file );
}, $files );
} | [
"protected",
"function",
"convertUploadedFiles",
"(",
"array",
"$",
"files",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"file",
")",
"||",
"(",
"is_array",
"(",
"$",
"file",
")",
"&&",
"empty",
"(",
"array_filter",
"(",
"$",
"file",
")",
")",
")",
")",
"return",
"$",
"file",
";",
"return",
"is_array",
"(",
"$",
"file",
")",
"?",
"$",
"this",
"->",
"convertUploadedFiles",
"(",
"$",
"file",
")",
":",
"UploadedFile",
"::",
"createFromBase",
"(",
"$",
"file",
")",
";",
"}",
",",
"$",
"files",
")",
";",
"}"
] | Convert the given array of Symfony UploadedFiles to custom Framework UploadedFiles.
@param array $files
@return array | [
"Convert",
"the",
"given",
"array",
"of",
"Symfony",
"UploadedFiles",
"to",
"custom",
"Framework",
"UploadedFiles",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Request.php#L465-L474 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/Request.php | Request.prefers | public function prefers( $contentTypes )
{
$accepts = $this->getAcceptableContentTypes();
$contentTypes = (array) $contentTypes;
foreach ( $accepts as $accept )
{
if ( in_array( $accept, ['*/*', '*'] ) )
return $contentTypes[0];
foreach ( $contentTypes as $contentType )
{
$type = $contentType;
if ( !is_null( $mimeType = $this->getMimeType( $contentType ) ) )
$type = $mimeType;
if ( $this->matchesType( $type, $accept ) || $accept === strtok( $type, '/' ) . '/*' )
return $contentType;
}
}
} | php | public function prefers( $contentTypes )
{
$accepts = $this->getAcceptableContentTypes();
$contentTypes = (array) $contentTypes;
foreach ( $accepts as $accept )
{
if ( in_array( $accept, ['*/*', '*'] ) )
return $contentTypes[0];
foreach ( $contentTypes as $contentType )
{
$type = $contentType;
if ( !is_null( $mimeType = $this->getMimeType( $contentType ) ) )
$type = $mimeType;
if ( $this->matchesType( $type, $accept ) || $accept === strtok( $type, '/' ) . '/*' )
return $contentType;
}
}
} | [
"public",
"function",
"prefers",
"(",
"$",
"contentTypes",
")",
"{",
"$",
"accepts",
"=",
"$",
"this",
"->",
"getAcceptableContentTypes",
"(",
")",
";",
"$",
"contentTypes",
"=",
"(",
"array",
")",
"$",
"contentTypes",
";",
"foreach",
"(",
"$",
"accepts",
"as",
"$",
"accept",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"accept",
",",
"[",
"'*/*'",
",",
"'*'",
"]",
")",
")",
"return",
"$",
"contentTypes",
"[",
"0",
"]",
";",
"foreach",
"(",
"$",
"contentTypes",
"as",
"$",
"contentType",
")",
"{",
"$",
"type",
"=",
"$",
"contentType",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"mimeType",
"=",
"$",
"this",
"->",
"getMimeType",
"(",
"$",
"contentType",
")",
")",
")",
"$",
"type",
"=",
"$",
"mimeType",
";",
"if",
"(",
"$",
"this",
"->",
"matchesType",
"(",
"$",
"type",
",",
"$",
"accept",
")",
"||",
"$",
"accept",
"===",
"strtok",
"(",
"$",
"type",
",",
"'/'",
")",
".",
"'/*'",
")",
"return",
"$",
"contentType",
";",
"}",
"}",
"}"
] | Return the most suitable content type from the given array based on content negotiation.
@param string|array $contentTypes
@return string|null | [
"Return",
"the",
"most",
"suitable",
"content",
"type",
"from",
"the",
"given",
"array",
"based",
"on",
"content",
"negotiation",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Request.php#L772-L794 | train |
jdmaymeow/cake-utility | src/Random/XorShift.php | XorShift.getRand | public function getRand($min = 0, $max = 0x7fffffff)
{
$t = ($this->x ^ ($this->x << 11)) & 0x7fffffff;
$this->x = $this->y;
$this->y = $this->z;
$this->z = $this->w;
$this->w = ( $this->w ^ ($this->w >> 19) ^ ( $t ^ ( $t >> 8 )) );
return $this->w % ($max - $min + 1) + $min;
} | php | public function getRand($min = 0, $max = 0x7fffffff)
{
$t = ($this->x ^ ($this->x << 11)) & 0x7fffffff;
$this->x = $this->y;
$this->y = $this->z;
$this->z = $this->w;
$this->w = ( $this->w ^ ($this->w >> 19) ^ ( $t ^ ( $t >> 8 )) );
return $this->w % ($max - $min + 1) + $min;
} | [
"public",
"function",
"getRand",
"(",
"$",
"min",
"=",
"0",
",",
"$",
"max",
"=",
"0x7fffffff",
")",
"{",
"$",
"t",
"=",
"(",
"$",
"this",
"->",
"x",
"^",
"(",
"$",
"this",
"->",
"x",
"<<",
"11",
")",
")",
"&",
"0x7fffffff",
";",
"$",
"this",
"->",
"x",
"=",
"$",
"this",
"->",
"y",
";",
"$",
"this",
"->",
"y",
"=",
"$",
"this",
"->",
"z",
";",
"$",
"this",
"->",
"z",
"=",
"$",
"this",
"->",
"w",
";",
"$",
"this",
"->",
"w",
"=",
"(",
"$",
"this",
"->",
"w",
"^",
"(",
"$",
"this",
"->",
"w",
">>",
"19",
")",
"^",
"(",
"$",
"t",
"^",
"(",
"$",
"t",
">>",
"8",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"w",
"%",
"(",
"$",
"max",
"-",
"$",
"min",
"+",
"1",
")",
"+",
"$",
"min",
";",
"}"
] | Function getTrand
Return random number between max and min
@param int $min Minimum value
@param int $max Maximum value
@return int | [
"Function",
"getTrand",
"Return",
"random",
"number",
"between",
"max",
"and",
"min"
] | 9da54f12a0f41fb1d590924db0c1130978b6e94e | https://github.com/jdmaymeow/cake-utility/blob/9da54f12a0f41fb1d590924db0c1130978b6e94e/src/Random/XorShift.php#L31-L39 | train |
carno-php/http | src/Client.php | Client.close | public function close() : Promised
{
return
($this->pool
? $this->pool->shutdown()
: (
$this->session
? $this->session->close()
: Promise::resolved()
)
)->sync($this->closed())
;
} | php | public function close() : Promised
{
return
($this->pool
? $this->pool->shutdown()
: (
$this->session
? $this->session->close()
: Promise::resolved()
)
)->sync($this->closed())
;
} | [
"public",
"function",
"close",
"(",
")",
":",
"Promised",
"{",
"return",
"(",
"$",
"this",
"->",
"pool",
"?",
"$",
"this",
"->",
"pool",
"->",
"shutdown",
"(",
")",
":",
"(",
"$",
"this",
"->",
"session",
"?",
"$",
"this",
"->",
"session",
"->",
"close",
"(",
")",
":",
"Promise",
"::",
"resolved",
"(",
")",
")",
")",
"->",
"sync",
"(",
"$",
"this",
"->",
"closed",
"(",
")",
")",
";",
"}"
] | close pool connections or session client
@return Promised | [
"close",
"pool",
"connections",
"or",
"session",
"client"
] | 0a873d1feb9ae6ec50e84e03f2075ac87997aa44 | https://github.com/carno-php/http/blob/0a873d1feb9ae6ec50e84e03f2075ac87997aa44/src/Client.php#L131-L143 | train |
donatj/mddom | src/AbstractNestingElement.php | AbstractNestingElement.appendChild | public function appendChild( $child = null /* .. AbstractElement $element .. */ ) {
$arg_list = func_get_args();
foreach( $arg_list as $arg ) {
if( $arg instanceof AbstractElement ) {
$inject = $arg;
} elseif( is_scalar($arg) ) {
$inject = new Text($arg);
} else {
throw new \InvalidArgumentException;
}
$inject->_setParent($this);
$this->childElements[] = $inject;
}
return $this;
} | php | public function appendChild( $child = null /* .. AbstractElement $element .. */ ) {
$arg_list = func_get_args();
foreach( $arg_list as $arg ) {
if( $arg instanceof AbstractElement ) {
$inject = $arg;
} elseif( is_scalar($arg) ) {
$inject = new Text($arg);
} else {
throw new \InvalidArgumentException;
}
$inject->_setParent($this);
$this->childElements[] = $inject;
}
return $this;
} | [
"public",
"function",
"appendChild",
"(",
"$",
"child",
"=",
"null",
"/* .. AbstractElement $element .. */",
")",
"{",
"$",
"arg_list",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"arg_list",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"$",
"arg",
"instanceof",
"AbstractElement",
")",
"{",
"$",
"inject",
"=",
"$",
"arg",
";",
"}",
"elseif",
"(",
"is_scalar",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"inject",
"=",
"new",
"Text",
"(",
"$",
"arg",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
";",
"}",
"$",
"inject",
"->",
"_setParent",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"childElements",
"[",
"]",
"=",
"$",
"inject",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Inject One Or More Elements
@param AbstractElement|int|float|string $child,... Child Elements to Append
@return $this
@throws \InvalidArgumentException | [
"Inject",
"One",
"Or",
"More",
"Elements"
] | c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d | https://github.com/donatj/mddom/blob/c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d/src/AbstractNestingElement.php#L30-L47 | train |
donatj/mddom | src/AbstractNestingElement.php | AbstractNestingElement.removeChild | public function removeChild( AbstractElement $element ) {
$index = $this->indexOf($element);
if( $index !== null ) {
unset($this->childElements[$index]);
//Remove any gaps
$this->childElements = array_values($this->childElements);
return true;
}
return false;
} | php | public function removeChild( AbstractElement $element ) {
$index = $this->indexOf($element);
if( $index !== null ) {
unset($this->childElements[$index]);
//Remove any gaps
$this->childElements = array_values($this->childElements);
return true;
}
return false;
} | [
"public",
"function",
"removeChild",
"(",
"AbstractElement",
"$",
"element",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"indexOf",
"(",
"$",
"element",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"null",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"childElements",
"[",
"$",
"index",
"]",
")",
";",
"//Remove any gaps",
"$",
"this",
"->",
"childElements",
"=",
"array_values",
"(",
"$",
"this",
"->",
"childElements",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Remove a child element
@param AbstractElement $element
@return bool False if the given element was not found. | [
"Remove",
"a",
"child",
"element"
] | c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d | https://github.com/donatj/mddom/blob/c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d/src/AbstractNestingElement.php#L55-L67 | train |
donatj/mddom | src/AbstractNestingElement.php | AbstractNestingElement.indexOf | public function indexOf( AbstractElement $element ) {
$search_result = array_search($element, $this->childElements, true);
return $search_result === false ? null : $search_result;
} | php | public function indexOf( AbstractElement $element ) {
$search_result = array_search($element, $this->childElements, true);
return $search_result === false ? null : $search_result;
} | [
"public",
"function",
"indexOf",
"(",
"AbstractElement",
"$",
"element",
")",
"{",
"$",
"search_result",
"=",
"array_search",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"childElements",
",",
"true",
")",
";",
"return",
"$",
"search_result",
"===",
"false",
"?",
"null",
":",
"$",
"search_result",
";",
"}"
] | Get the index of a child element or null if not found.
@param AbstractElement $element
@return int|null | [
"Get",
"the",
"index",
"of",
"a",
"child",
"element",
"or",
"null",
"if",
"not",
"found",
"."
] | c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d | https://github.com/donatj/mddom/blob/c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d/src/AbstractNestingElement.php#L93-L97 | train |
donatj/mddom | src/AbstractNestingElement.php | AbstractNestingElement.childAtIndex | public function childAtIndex( $index ) {
if( $index !== null && isset($this->childElements[$index]) ) {
return $this->childElements[$index];
}
return null;
} | php | public function childAtIndex( $index ) {
if( $index !== null && isset($this->childElements[$index]) ) {
return $this->childElements[$index];
}
return null;
} | [
"public",
"function",
"childAtIndex",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"index",
"!==",
"null",
"&&",
"isset",
"(",
"$",
"this",
"->",
"childElements",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"childElements",
"[",
"$",
"index",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Gets the child element at a given index or null if not found.
@param int $index
@return AbstractElement|null | [
"Gets",
"the",
"child",
"element",
"at",
"a",
"given",
"index",
"or",
"null",
"if",
"not",
"found",
"."
] | c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d | https://github.com/donatj/mddom/blob/c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d/src/AbstractNestingElement.php#L105-L111 | train |
donatj/mddom | src/AbstractNestingElement.php | AbstractNestingElement.getNextSiblingOf | public function getNextSiblingOf( AbstractElement $element ) {
$index = $this->indexOf($element);
return $this->childAtIndex($index + 1);
} | php | public function getNextSiblingOf( AbstractElement $element ) {
$index = $this->indexOf($element);
return $this->childAtIndex($index + 1);
} | [
"public",
"function",
"getNextSiblingOf",
"(",
"AbstractElement",
"$",
"element",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"indexOf",
"(",
"$",
"element",
")",
";",
"return",
"$",
"this",
"->",
"childAtIndex",
"(",
"$",
"index",
"+",
"1",
")",
";",
"}"
] | Get the next sibling of a given child element or null if not found
@param AbstractElement $element
@return AbstractElement|null | [
"Get",
"the",
"next",
"sibling",
"of",
"a",
"given",
"child",
"element",
"or",
"null",
"if",
"not",
"found"
] | c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d | https://github.com/donatj/mddom/blob/c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d/src/AbstractNestingElement.php#L119-L123 | train |
donatj/mddom | src/AbstractNestingElement.php | AbstractNestingElement.getPreviousSiblingOf | public function getPreviousSiblingOf( AbstractElement $element ) {
$index = $this->indexOf($element);
return $this->childAtIndex($index - 1);
} | php | public function getPreviousSiblingOf( AbstractElement $element ) {
$index = $this->indexOf($element);
return $this->childAtIndex($index - 1);
} | [
"public",
"function",
"getPreviousSiblingOf",
"(",
"AbstractElement",
"$",
"element",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"indexOf",
"(",
"$",
"element",
")",
";",
"return",
"$",
"this",
"->",
"childAtIndex",
"(",
"$",
"index",
"-",
"1",
")",
";",
"}"
] | Get the previous sibling of a given child element or null if not found
@param AbstractElement $element
@return AbstractElement|null | [
"Get",
"the",
"previous",
"sibling",
"of",
"a",
"given",
"child",
"element",
"or",
"null",
"if",
"not",
"found"
] | c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d | https://github.com/donatj/mddom/blob/c6b66a4f5dfeaec9aeefe07c05d667d5bac70f8d/src/AbstractNestingElement.php#L131-L135 | train |
fxpio/fxp-doctrine-extensions | Validator/Constraints/DoctrineCallback.php | DoctrineCallback.initArrayCallbackOption | protected function initArrayCallbackOption($options)
{
if (!isset($options['callback']) && !isset($options['groups']) && \is_callable($options)) {
$options = ['callback' => $options];
}
return $options;
} | php | protected function initArrayCallbackOption($options)
{
if (!isset($options['callback']) && !isset($options['groups']) && \is_callable($options)) {
$options = ['callback' => $options];
}
return $options;
} | [
"protected",
"function",
"initArrayCallbackOption",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'callback'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"options",
"[",
"'groups'",
"]",
")",
"&&",
"\\",
"is_callable",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"'callback'",
"=>",
"$",
"options",
"]",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | Init callback options.
@param array $options
@return array | [
"Init",
"callback",
"options",
"."
] | 82942f51d47cdd79a20a5725ee1b3ecfc69e9d77 | https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Validator/Constraints/DoctrineCallback.php#L81-L88 | train |
WellBloud/sovacore-core | src/model/CoreRepository.php | CoreRepository.fillData | public function fillData($entity,
ArrayHash $values)
{
$properties = $this->getEntityProperties($entity);
foreach ($properties as $property) {
if (array_key_exists($property, $values)) {
// You may want to process Collection property elsewhere
if (!$entity->$property instanceof Collection) {
$entity->$property = $values->$property;
}
}
}
$entity->modifiedOn = new DateTime();
return $entity;
} | php | public function fillData($entity,
ArrayHash $values)
{
$properties = $this->getEntityProperties($entity);
foreach ($properties as $property) {
if (array_key_exists($property, $values)) {
// You may want to process Collection property elsewhere
if (!$entity->$property instanceof Collection) {
$entity->$property = $values->$property;
}
}
}
$entity->modifiedOn = new DateTime();
return $entity;
} | [
"public",
"function",
"fillData",
"(",
"$",
"entity",
",",
"ArrayHash",
"$",
"values",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"getEntityProperties",
"(",
"$",
"entity",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"property",
",",
"$",
"values",
")",
")",
"{",
"// You may want to process Collection property elsewhere",
"if",
"(",
"!",
"$",
"entity",
"->",
"$",
"property",
"instanceof",
"Collection",
")",
"{",
"$",
"entity",
"->",
"$",
"property",
"=",
"$",
"values",
"->",
"$",
"property",
";",
"}",
"}",
"}",
"$",
"entity",
"->",
"modifiedOn",
"=",
"new",
"DateTime",
"(",
")",
";",
"return",
"$",
"entity",
";",
"}"
] | Fills entity with set data from form
@param type $entity
@param ArrayHash $values
@return $entity | [
"Fills",
"entity",
"with",
"set",
"data",
"from",
"form"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/CoreRepository.php#L46-L60 | train |
WellBloud/sovacore-core | src/model/CoreRepository.php | CoreRepository.getEntityArrayValues | public function getEntityArrayValues($entity)
{
$values = [];
$properties = $this->getEntityProperties($entity);
$metadata = $this->em->getClassMetadata(get_class($entity));
foreach ($properties as $property) {
$values[$property] = $metadata->getFieldValue($entity, $property);
}
return $values;
} | php | public function getEntityArrayValues($entity)
{
$values = [];
$properties = $this->getEntityProperties($entity);
$metadata = $this->em->getClassMetadata(get_class($entity));
foreach ($properties as $property) {
$values[$property] = $metadata->getFieldValue($entity, $property);
}
return $values;
} | [
"public",
"function",
"getEntityArrayValues",
"(",
"$",
"entity",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"properties",
"=",
"$",
"this",
"->",
"getEntityProperties",
"(",
"$",
"entity",
")",
";",
"$",
"metadata",
"=",
"$",
"this",
"->",
"em",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"entity",
")",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"$",
"values",
"[",
"$",
"property",
"]",
"=",
"$",
"metadata",
"->",
"getFieldValue",
"(",
"$",
"entity",
",",
"$",
"property",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Returns default values for forms
@param type $entity
@return array | [
"Returns",
"default",
"values",
"for",
"forms"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/CoreRepository.php#L119-L128 | train |
WellBloud/sovacore-core | src/model/CoreRepository.php | CoreRepository.getEntityProperties | public function getEntityProperties($entity)
{
$metadata = $this->em->getClassMetadata(get_class($entity));
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
} | php | public function getEntityProperties($entity)
{
$metadata = $this->em->getClassMetadata(get_class($entity));
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
} | [
"public",
"function",
"getEntityProperties",
"(",
"$",
"entity",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"em",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"entity",
")",
")",
";",
"return",
"array_merge",
"(",
"$",
"metadata",
"->",
"getFieldNames",
"(",
")",
",",
"$",
"metadata",
"->",
"getAssociationNames",
"(",
")",
")",
";",
"}"
] | Return entity properties names
@param type $entity
@return array | [
"Return",
"entity",
"properties",
"names"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/CoreRepository.php#L135-L139 | train |
phospr/DoubleEntryBundle | Model/AccountHandler.php | AccountHandler.getChartOfAccounts | public function getChartOfAccounts()
{
$organization = $this->oh->getOrganization();
if (!$organization->getChartOfAccounts()) {
$chart = $this->createChartOfAccounts($organization);
$this->em->persist($organization);
$this->em->flush();
}
return $organization->getChartOfAccounts();
} | php | public function getChartOfAccounts()
{
$organization = $this->oh->getOrganization();
if (!$organization->getChartOfAccounts()) {
$chart = $this->createChartOfAccounts($organization);
$this->em->persist($organization);
$this->em->flush();
}
return $organization->getChartOfAccounts();
} | [
"public",
"function",
"getChartOfAccounts",
"(",
")",
"{",
"$",
"organization",
"=",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
";",
"if",
"(",
"!",
"$",
"organization",
"->",
"getChartOfAccounts",
"(",
")",
")",
"{",
"$",
"chart",
"=",
"$",
"this",
"->",
"createChartOfAccounts",
"(",
"$",
"organization",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"organization",
")",
";",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"return",
"$",
"organization",
"->",
"getChartOfAccounts",
"(",
")",
";",
"}"
] | Get chart of accounts for current Organization
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@return Account | [
"Get",
"chart",
"of",
"accounts",
"for",
"current",
"Organization"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/AccountHandler.php#L101-L113 | train |
phospr/DoubleEntryBundle | Model/AccountHandler.php | AccountHandler.createChartOfAccounts | public function createChartOfAccounts(OrganizationInterface $organization)
{
$account = $this->accountFqcn;
$chart = new $account($organization->getName());
$organization->setChartOfAccounts($chart);
$chart->addChild($assets = new $account('Assets'));
$assets->addChild($bank = new $account('Bank'));
$bank->addChild($checking = new $account('Checking'));
$chart->addChild($equity = new $account('Equity'));
$equity->addChild($opening = new $account('Opening Balance'));
$chart->addChild($expenses = new $account('Expenses'));
$expenses->addChild($food = new $account('Food'));
$expenses->addChild($auto = new $account('Auto'));
$auto->addChild($gas = new $account('Gas'));
$expenses->addChild($childcare = new $account('Childcare'));
$chart->addChild($income = new $account('Income'));
$income->addChild($salary = new $account('Salary'));
$chart->addChild($liabilities = new $account('Liabilities'));
$liabilities->addChild($cc = new $account('Credit Cards'));
return $chart;
} | php | public function createChartOfAccounts(OrganizationInterface $organization)
{
$account = $this->accountFqcn;
$chart = new $account($organization->getName());
$organization->setChartOfAccounts($chart);
$chart->addChild($assets = new $account('Assets'));
$assets->addChild($bank = new $account('Bank'));
$bank->addChild($checking = new $account('Checking'));
$chart->addChild($equity = new $account('Equity'));
$equity->addChild($opening = new $account('Opening Balance'));
$chart->addChild($expenses = new $account('Expenses'));
$expenses->addChild($food = new $account('Food'));
$expenses->addChild($auto = new $account('Auto'));
$auto->addChild($gas = new $account('Gas'));
$expenses->addChild($childcare = new $account('Childcare'));
$chart->addChild($income = new $account('Income'));
$income->addChild($salary = new $account('Salary'));
$chart->addChild($liabilities = new $account('Liabilities'));
$liabilities->addChild($cc = new $account('Credit Cards'));
return $chart;
} | [
"public",
"function",
"createChartOfAccounts",
"(",
"OrganizationInterface",
"$",
"organization",
")",
"{",
"$",
"account",
"=",
"$",
"this",
"->",
"accountFqcn",
";",
"$",
"chart",
"=",
"new",
"$",
"account",
"(",
"$",
"organization",
"->",
"getName",
"(",
")",
")",
";",
"$",
"organization",
"->",
"setChartOfAccounts",
"(",
"$",
"chart",
")",
";",
"$",
"chart",
"->",
"addChild",
"(",
"$",
"assets",
"=",
"new",
"$",
"account",
"(",
"'Assets'",
")",
")",
";",
"$",
"assets",
"->",
"addChild",
"(",
"$",
"bank",
"=",
"new",
"$",
"account",
"(",
"'Bank'",
")",
")",
";",
"$",
"bank",
"->",
"addChild",
"(",
"$",
"checking",
"=",
"new",
"$",
"account",
"(",
"'Checking'",
")",
")",
";",
"$",
"chart",
"->",
"addChild",
"(",
"$",
"equity",
"=",
"new",
"$",
"account",
"(",
"'Equity'",
")",
")",
";",
"$",
"equity",
"->",
"addChild",
"(",
"$",
"opening",
"=",
"new",
"$",
"account",
"(",
"'Opening Balance'",
")",
")",
";",
"$",
"chart",
"->",
"addChild",
"(",
"$",
"expenses",
"=",
"new",
"$",
"account",
"(",
"'Expenses'",
")",
")",
";",
"$",
"expenses",
"->",
"addChild",
"(",
"$",
"food",
"=",
"new",
"$",
"account",
"(",
"'Food'",
")",
")",
";",
"$",
"expenses",
"->",
"addChild",
"(",
"$",
"auto",
"=",
"new",
"$",
"account",
"(",
"'Auto'",
")",
")",
";",
"$",
"auto",
"->",
"addChild",
"(",
"$",
"gas",
"=",
"new",
"$",
"account",
"(",
"'Gas'",
")",
")",
";",
"$",
"expenses",
"->",
"addChild",
"(",
"$",
"childcare",
"=",
"new",
"$",
"account",
"(",
"'Childcare'",
")",
")",
";",
"$",
"chart",
"->",
"addChild",
"(",
"$",
"income",
"=",
"new",
"$",
"account",
"(",
"'Income'",
")",
")",
";",
"$",
"income",
"->",
"addChild",
"(",
"$",
"salary",
"=",
"new",
"$",
"account",
"(",
"'Salary'",
")",
")",
";",
"$",
"chart",
"->",
"addChild",
"(",
"$",
"liabilities",
"=",
"new",
"$",
"account",
"(",
"'Liabilities'",
")",
")",
";",
"$",
"liabilities",
"->",
"addChild",
"(",
"$",
"cc",
"=",
"new",
"$",
"account",
"(",
"'Credit Cards'",
")",
")",
";",
"return",
"$",
"chart",
";",
"}"
] | Create new chart of accounts
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@param OrganizationInterface $organization
@return Account | [
"Create",
"new",
"chart",
"of",
"accounts"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/AccountHandler.php#L125-L152 | train |
phospr/DoubleEntryBundle | Model/AccountHandler.php | AccountHandler.findAccountForPath | public function findAccountForPath($path)
{
$dql = '
SELECT a,p,j,op
FROM %s a
LEFT JOIN a.postings p
LEFT JOIN p.journal j
LEFT JOIN j.postings op
WHERE a.path = :path
AND a.organization = :organization
';
return $this->em
->createQuery(sprintf($dql, $this->accountFqcn))
->setParameter('path', $path)
->setParameter('organization', $this->oh->getOrganization())
->getSingleResult()
;
} | php | public function findAccountForPath($path)
{
$dql = '
SELECT a,p,j,op
FROM %s a
LEFT JOIN a.postings p
LEFT JOIN p.journal j
LEFT JOIN j.postings op
WHERE a.path = :path
AND a.organization = :organization
';
return $this->em
->createQuery(sprintf($dql, $this->accountFqcn))
->setParameter('path', $path)
->setParameter('organization', $this->oh->getOrganization())
->getSingleResult()
;
} | [
"public",
"function",
"findAccountForPath",
"(",
"$",
"path",
")",
"{",
"$",
"dql",
"=",
"'\n SELECT a,p,j,op\n FROM %s a\n LEFT JOIN a.postings p\n LEFT JOIN p.journal j\n LEFT JOIN j.postings op\n WHERE a.path = :path\n AND a.organization = :organization\n '",
";",
"return",
"$",
"this",
"->",
"em",
"->",
"createQuery",
"(",
"sprintf",
"(",
"$",
"dql",
",",
"$",
"this",
"->",
"accountFqcn",
")",
")",
"->",
"setParameter",
"(",
"'path'",
",",
"$",
"path",
")",
"->",
"setParameter",
"(",
"'organization'",
",",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
")",
"->",
"getSingleResult",
"(",
")",
";",
"}"
] | Find Account for path
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@param string $path | [
"Find",
"Account",
"for",
"path"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/AccountHandler.php#L178-L196 | train |
phospr/DoubleEntryBundle | Model/AccountHandler.php | AccountHandler.createAccountsFromSegmentation | public function createAccountsFromSegmentation($segmentation)
{
$segments = explode(':', $segmentation);
$account = $this->oh->getOrganization()->getChartOfAccounts();
foreach ($segments as $segment) {
$parent = $account;
if (!$account = $account->getChildForName($segment)) {
$account = new $this->accountFqcn($segment);
$parent->addChild($account);
}
}
return $account;
} | php | public function createAccountsFromSegmentation($segmentation)
{
$segments = explode(':', $segmentation);
$account = $this->oh->getOrganization()->getChartOfAccounts();
foreach ($segments as $segment) {
$parent = $account;
if (!$account = $account->getChildForName($segment)) {
$account = new $this->accountFqcn($segment);
$parent->addChild($account);
}
}
return $account;
} | [
"public",
"function",
"createAccountsFromSegmentation",
"(",
"$",
"segmentation",
")",
"{",
"$",
"segments",
"=",
"explode",
"(",
"':'",
",",
"$",
"segmentation",
")",
";",
"$",
"account",
"=",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
"->",
"getChartOfAccounts",
"(",
")",
";",
"foreach",
"(",
"$",
"segments",
"as",
"$",
"segment",
")",
"{",
"$",
"parent",
"=",
"$",
"account",
";",
"if",
"(",
"!",
"$",
"account",
"=",
"$",
"account",
"->",
"getChildForName",
"(",
"$",
"segment",
")",
")",
"{",
"$",
"account",
"=",
"new",
"$",
"this",
"->",
"accountFqcn",
"(",
"$",
"segment",
")",
";",
"$",
"parent",
"->",
"addChild",
"(",
"$",
"account",
")",
";",
"}",
"}",
"return",
"$",
"account",
";",
"}"
] | Create Account tree from segmentation
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@param AccountInterface $chart
@param AccountSegmentation $segmentation | [
"Create",
"Account",
"tree",
"from",
"segmentation"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/AccountHandler.php#L220-L236 | train |
phospr/DoubleEntryBundle | Model/AccountHandler.php | AccountHandler.createAccount | public function createAccount($name = null)
{
$account = new $this->accountFqcn($name);
$account->setOrganization($this->oh->getOrganization());
return $account;
} | php | public function createAccount($name = null)
{
$account = new $this->accountFqcn($name);
$account->setOrganization($this->oh->getOrganization());
return $account;
} | [
"public",
"function",
"createAccount",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"account",
"=",
"new",
"$",
"this",
"->",
"accountFqcn",
"(",
"$",
"name",
")",
";",
"$",
"account",
"->",
"setOrganization",
"(",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
")",
";",
"return",
"$",
"account",
";",
"}"
] | Create new Account
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@param string $name
@return Account | [
"Create",
"new",
"Account"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/AccountHandler.php#L248-L254 | train |
phospr/DoubleEntryBundle | Model/AccountHandler.php | AccountHandler.renderArray | public function renderArray(AccountInterface $account)
{
$array = array(
'name' => $account->getName(),
);
foreach ($account->getChildren() as $child) {
$array['children'][] = $this->renderArray($child);
}
return $array;
} | php | public function renderArray(AccountInterface $account)
{
$array = array(
'name' => $account->getName(),
);
foreach ($account->getChildren() as $child) {
$array['children'][] = $this->renderArray($child);
}
return $array;
} | [
"public",
"function",
"renderArray",
"(",
"AccountInterface",
"$",
"account",
")",
"{",
"$",
"array",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"account",
"->",
"getName",
"(",
")",
",",
")",
";",
"foreach",
"(",
"$",
"account",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"array",
"[",
"'children'",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"renderArray",
"(",
"$",
"child",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Render Account tree as a multi-level array
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@param AccountInterface $account
@return array | [
"Render",
"Account",
"tree",
"as",
"a",
"multi",
"-",
"level",
"array"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/AccountHandler.php#L266-L277 | train |
phospr/DoubleEntryBundle | Model/AccountHandler.php | AccountHandler.getFavouriteAccountsForUser | public function getFavouriteAccountsForUser(UserInterface $user)
{
$criteria = new Criteria();
$criteria
->where($criteria->expr()->in(
'id',
$user->getMyFavouriteAccountIds()
))
;
return $this->oh->getOrganization()
->getAccounts()
->matching($criteria)
;
} | php | public function getFavouriteAccountsForUser(UserInterface $user)
{
$criteria = new Criteria();
$criteria
->where($criteria->expr()->in(
'id',
$user->getMyFavouriteAccountIds()
))
;
return $this->oh->getOrganization()
->getAccounts()
->matching($criteria)
;
} | [
"public",
"function",
"getFavouriteAccountsForUser",
"(",
"UserInterface",
"$",
"user",
")",
"{",
"$",
"criteria",
"=",
"new",
"Criteria",
"(",
")",
";",
"$",
"criteria",
"->",
"where",
"(",
"$",
"criteria",
"->",
"expr",
"(",
")",
"->",
"in",
"(",
"'id'",
",",
"$",
"user",
"->",
"getMyFavouriteAccountIds",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
"->",
"getAccounts",
"(",
")",
"->",
"matching",
"(",
"$",
"criteria",
")",
";",
"}"
] | Get a collection of favourite Accounts for User
@author Tom Haskins-Vaughan <[email protected]>
@since 0.10.0
@return Collection | [
"Get",
"a",
"collection",
"of",
"favourite",
"Accounts",
"for",
"User"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/AccountHandler.php#L287-L301 | train |
anime-db/catalog-bundle | src/Command/ScanStoragesCommand.php | ScanStoragesCommand.getItemsOfDeletedFiles | protected function getItemsOfDeletedFiles(Storage $storage, Finder $finder)
{
$items = [];
// check of delete file for item
foreach ($storage->getItems() as $item) {
foreach ($finder as $file) {
if (pathinfo($item->getPath(), PATHINFO_BASENAME) == $file->getFilename()) {
continue 2;
}
}
$items[] = $item;
}
return $items;
} | php | protected function getItemsOfDeletedFiles(Storage $storage, Finder $finder)
{
$items = [];
// check of delete file for item
foreach ($storage->getItems() as $item) {
foreach ($finder as $file) {
if (pathinfo($item->getPath(), PATHINFO_BASENAME) == $file->getFilename()) {
continue 2;
}
}
$items[] = $item;
}
return $items;
} | [
"protected",
"function",
"getItemsOfDeletedFiles",
"(",
"Storage",
"$",
"storage",
",",
"Finder",
"$",
"finder",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"// check of delete file for item",
"foreach",
"(",
"$",
"storage",
"->",
"getItems",
"(",
")",
"as",
"$",
"item",
")",
"{",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"pathinfo",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
",",
"PATHINFO_BASENAME",
")",
"==",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
"{",
"continue",
"2",
";",
"}",
"}",
"$",
"items",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Get items of deleted files.
@param Storage $storage
@param Finder $finder
@return array | [
"Get",
"items",
"of",
"deleted",
"files",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Command/ScanStoragesCommand.php#L244-L258 | train |
anime-db/catalog-bundle | src/Command/ScanStoragesCommand.php | ScanStoragesCommand.getItemFromFile | protected function getItemFromFile(Storage $storage, SplFileInfo $file)
{
/* @var $item Item */
foreach ($storage->getItems() as $item) {
if (pathinfo($item->getPath(), PATHINFO_BASENAME) == $file->getFilename()) {
return $item;
}
}
return false;
} | php | protected function getItemFromFile(Storage $storage, SplFileInfo $file)
{
/* @var $item Item */
foreach ($storage->getItems() as $item) {
if (pathinfo($item->getPath(), PATHINFO_BASENAME) == $file->getFilename()) {
return $item;
}
}
return false;
} | [
"protected",
"function",
"getItemFromFile",
"(",
"Storage",
"$",
"storage",
",",
"SplFileInfo",
"$",
"file",
")",
"{",
"/* @var $item Item */",
"foreach",
"(",
"$",
"storage",
"->",
"getItems",
"(",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"pathinfo",
"(",
"$",
"item",
"->",
"getPath",
"(",
")",
",",
"PATHINFO_BASENAME",
")",
"==",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
"{",
"return",
"$",
"item",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get item from files.
@param Storage $storage
@param SplFileInfo $file
@return Item|bool | [
"Get",
"item",
"from",
"files",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Command/ScanStoragesCommand.php#L268-L278 | train |
anime-db/catalog-bundle | src/Command/ScanStoragesCommand.php | ScanStoragesCommand.isAllowFile | protected function isAllowFile(SplFileInfo $file)
{
return in_array(strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION)), $this->allow_ext);
} | php | protected function isAllowFile(SplFileInfo $file)
{
return in_array(strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION)), $this->allow_ext);
} | [
"protected",
"function",
"isAllowFile",
"(",
"SplFileInfo",
"$",
"file",
")",
"{",
"return",
"in_array",
"(",
"strtolower",
"(",
"pathinfo",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"PATHINFO_EXTENSION",
")",
")",
",",
"$",
"this",
"->",
"allow_ext",
")",
";",
"}"
] | Is allow file.
@param SplFileInfo $file
@return bool | [
"Is",
"allow",
"file",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Command/ScanStoragesCommand.php#L303-L306 | train |
anime-db/catalog-bundle | src/Command/ScanStoragesCommand.php | ScanStoragesCommand.checkStorageId | protected function checkStorageId($path, Storage $storage, StorageRepository $rep)
{
if (!file_exists($path.StorageListener::ID_FILE)) {
// path is free. reserve for me
file_put_contents($path.StorageListener::ID_FILE, $storage->getId());
} elseif (file_get_contents($path.StorageListener::ID_FILE) == $storage->getId()) {
// it is my path. do nothing
} elseif (!($duplicate = $rep->find(file_get_contents($path.StorageListener::ID_FILE)))) {
// this path is reserved storage that was removed and now this path is free
file_put_contents($path.StorageListener::ID_FILE, $storage->getId());
} else {
return $duplicate;
}
return true;
} | php | protected function checkStorageId($path, Storage $storage, StorageRepository $rep)
{
if (!file_exists($path.StorageListener::ID_FILE)) {
// path is free. reserve for me
file_put_contents($path.StorageListener::ID_FILE, $storage->getId());
} elseif (file_get_contents($path.StorageListener::ID_FILE) == $storage->getId()) {
// it is my path. do nothing
} elseif (!($duplicate = $rep->find(file_get_contents($path.StorageListener::ID_FILE)))) {
// this path is reserved storage that was removed and now this path is free
file_put_contents($path.StorageListener::ID_FILE, $storage->getId());
} else {
return $duplicate;
}
return true;
} | [
"protected",
"function",
"checkStorageId",
"(",
"$",
"path",
",",
"Storage",
"$",
"storage",
",",
"StorageRepository",
"$",
"rep",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
".",
"StorageListener",
"::",
"ID_FILE",
")",
")",
"{",
"// path is free. reserve for me",
"file_put_contents",
"(",
"$",
"path",
".",
"StorageListener",
"::",
"ID_FILE",
",",
"$",
"storage",
"->",
"getId",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"file_get_contents",
"(",
"$",
"path",
".",
"StorageListener",
"::",
"ID_FILE",
")",
"==",
"$",
"storage",
"->",
"getId",
"(",
")",
")",
"{",
"// it is my path. do nothing",
"}",
"elseif",
"(",
"!",
"(",
"$",
"duplicate",
"=",
"$",
"rep",
"->",
"find",
"(",
"file_get_contents",
"(",
"$",
"path",
".",
"StorageListener",
"::",
"ID_FILE",
")",
")",
")",
")",
"{",
"// this path is reserved storage that was removed and now this path is free",
"file_put_contents",
"(",
"$",
"path",
".",
"StorageListener",
"::",
"ID_FILE",
",",
"$",
"storage",
"->",
"getId",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"duplicate",
";",
"}",
"return",
"true",
";",
"}"
] | Update storage id.
@param string $path
@param Storage $storage
@param StorageRepository $rep
@return Storage|bool | [
"Update",
"storage",
"id",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Command/ScanStoragesCommand.php#L317-L332 | train |
anime-db/catalog-bundle | src/Command/ScanStoragesCommand.php | ScanStoragesCommand.getProgress | protected function getProgress(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('no-progress')) {
$output = new NullOutput();
}
// export progress only for one storage
if (!$input->getArgument('storage')) {
$input->setOption('export', null);
}
if ($export_file = $input->getOption('export')) {
// progress is redirected to the export file
$input->setOption('no-progress', true);
$progress = new Export($this->getHelperSet()->get('progress'), new NullOutput(), $export_file);
} else {
$progress = new PresetOutput($this->getHelperSet()->get('progress'), $output);
}
$progress->setBarCharacter('<comment>=</comment>');
return $progress;
} | php | protected function getProgress(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('no-progress')) {
$output = new NullOutput();
}
// export progress only for one storage
if (!$input->getArgument('storage')) {
$input->setOption('export', null);
}
if ($export_file = $input->getOption('export')) {
// progress is redirected to the export file
$input->setOption('no-progress', true);
$progress = new Export($this->getHelperSet()->get('progress'), new NullOutput(), $export_file);
} else {
$progress = new PresetOutput($this->getHelperSet()->get('progress'), $output);
}
$progress->setBarCharacter('<comment>=</comment>');
return $progress;
} | [
"protected",
"function",
"getProgress",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'no-progress'",
")",
")",
"{",
"$",
"output",
"=",
"new",
"NullOutput",
"(",
")",
";",
"}",
"// export progress only for one storage",
"if",
"(",
"!",
"$",
"input",
"->",
"getArgument",
"(",
"'storage'",
")",
")",
"{",
"$",
"input",
"->",
"setOption",
"(",
"'export'",
",",
"null",
")",
";",
"}",
"if",
"(",
"$",
"export_file",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'export'",
")",
")",
"{",
"// progress is redirected to the export file",
"$",
"input",
"->",
"setOption",
"(",
"'no-progress'",
",",
"true",
")",
";",
"$",
"progress",
"=",
"new",
"Export",
"(",
"$",
"this",
"->",
"getHelperSet",
"(",
")",
"->",
"get",
"(",
"'progress'",
")",
",",
"new",
"NullOutput",
"(",
")",
",",
"$",
"export_file",
")",
";",
"}",
"else",
"{",
"$",
"progress",
"=",
"new",
"PresetOutput",
"(",
"$",
"this",
"->",
"getHelperSet",
"(",
")",
"->",
"get",
"(",
"'progress'",
")",
",",
"$",
"output",
")",
";",
"}",
"$",
"progress",
"->",
"setBarCharacter",
"(",
"'<comment>=</comment>'",
")",
";",
"return",
"$",
"progress",
";",
"}"
] | Get progress.
@param InputInterface $input
@param OutputInterface $output
@return Decorator | [
"Get",
"progress",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Command/ScanStoragesCommand.php#L342-L364 | train |
Becklyn/Gluggi | src/Controller/CoreController.php | CoreController.indexAction | public function indexAction ()
{
$layoutGroups = array_map(
function ($elementType)
{
return [
"title" => ucfirst($elementType) . "s",
"elementType" => $elementType,
"elements" => $this->elementTypesModel->getListedElements($elementType),
];
},
$this->elementTypesModel->getAllElementTypes()
);
return $this->twig->render("@core/index.twig", [
"layoutGroups" => $layoutGroups,
"downloads" => $this->downloadModel->getAllDownloads(),
]);
} | php | public function indexAction ()
{
$layoutGroups = array_map(
function ($elementType)
{
return [
"title" => ucfirst($elementType) . "s",
"elementType" => $elementType,
"elements" => $this->elementTypesModel->getListedElements($elementType),
];
},
$this->elementTypesModel->getAllElementTypes()
);
return $this->twig->render("@core/index.twig", [
"layoutGroups" => $layoutGroups,
"downloads" => $this->downloadModel->getAllDownloads(),
]);
} | [
"public",
"function",
"indexAction",
"(",
")",
"{",
"$",
"layoutGroups",
"=",
"array_map",
"(",
"function",
"(",
"$",
"elementType",
")",
"{",
"return",
"[",
"\"title\"",
"=>",
"ucfirst",
"(",
"$",
"elementType",
")",
".",
"\"s\"",
",",
"\"elementType\"",
"=>",
"$",
"elementType",
",",
"\"elements\"",
"=>",
"$",
"this",
"->",
"elementTypesModel",
"->",
"getListedElements",
"(",
"$",
"elementType",
")",
",",
"]",
";",
"}",
",",
"$",
"this",
"->",
"elementTypesModel",
"->",
"getAllElementTypes",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"\"@core/index.twig\"",
",",
"[",
"\"layoutGroups\"",
"=>",
"$",
"layoutGroups",
",",
"\"downloads\"",
"=>",
"$",
"this",
"->",
"downloadModel",
"->",
"getAllDownloads",
"(",
")",
",",
"]",
")",
";",
"}"
] | Handles the index action
@return string | [
"Handles",
"the",
"index",
"action"
] | 837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786 | https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Controller/CoreController.php#L52-L71 | train |
Becklyn/Gluggi | src/Controller/CoreController.php | CoreController.showElementAction | public function showElementAction ($elementType, $key)
{
try
{
$element = $this->elementTypesModel->getElement($key, $elementType);
if ((null === $element) || $element->isHidden())
{
throw new NotFoundHttpException("Element '{$key}' of type '{$elementType}' not found.");
}
$templateSuffix = $this->elementTypesModel->isFullPageElementType($elementType) ? "_fullpage" : "";
return $this->twig->render("@core/show_element{$templateSuffix}.twig", [
"element" => $element
]);
}
catch (\InvalidArgumentException $e)
{
throw new NotFoundHttpException("Unknown element type '{$elementType}'.", $e);
}
} | php | public function showElementAction ($elementType, $key)
{
try
{
$element = $this->elementTypesModel->getElement($key, $elementType);
if ((null === $element) || $element->isHidden())
{
throw new NotFoundHttpException("Element '{$key}' of type '{$elementType}' not found.");
}
$templateSuffix = $this->elementTypesModel->isFullPageElementType($elementType) ? "_fullpage" : "";
return $this->twig->render("@core/show_element{$templateSuffix}.twig", [
"element" => $element
]);
}
catch (\InvalidArgumentException $e)
{
throw new NotFoundHttpException("Unknown element type '{$elementType}'.", $e);
}
} | [
"public",
"function",
"showElementAction",
"(",
"$",
"elementType",
",",
"$",
"key",
")",
"{",
"try",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"elementTypesModel",
"->",
"getElement",
"(",
"$",
"key",
",",
"$",
"elementType",
")",
";",
"if",
"(",
"(",
"null",
"===",
"$",
"element",
")",
"||",
"$",
"element",
"->",
"isHidden",
"(",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"\"Element '{$key}' of type '{$elementType}' not found.\"",
")",
";",
"}",
"$",
"templateSuffix",
"=",
"$",
"this",
"->",
"elementTypesModel",
"->",
"isFullPageElementType",
"(",
"$",
"elementType",
")",
"?",
"\"_fullpage\"",
":",
"\"\"",
";",
"return",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"\"@core/show_element{$templateSuffix}.twig\"",
",",
"[",
"\"element\"",
"=>",
"$",
"element",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"\"Unknown element type '{$elementType}'.\"",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Displays a preview file
@param string $elementType
@param string $key
@return string|Response | [
"Displays",
"a",
"preview",
"file"
] | 837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786 | https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Controller/CoreController.php#L83-L104 | train |
Becklyn/Gluggi | src/Controller/CoreController.php | CoreController.elementsOverviewAction | public function elementsOverviewAction ($elementType)
{
try
{
$elementReferences = array_map(
function (Element $element)
{
return $element->getReference();
},
$this->elementTypesModel->getListedElements($elementType)
);
return $this->twig->render("@core/elements_overview_page.twig", [
"elementReferences" => $elementReferences
]);
}
catch (\InvalidArgumentException $e)
{
throw new NotFoundHttpException("Unknown element type '{$elementType}'.", $e);
}
} | php | public function elementsOverviewAction ($elementType)
{
try
{
$elementReferences = array_map(
function (Element $element)
{
return $element->getReference();
},
$this->elementTypesModel->getListedElements($elementType)
);
return $this->twig->render("@core/elements_overview_page.twig", [
"elementReferences" => $elementReferences
]);
}
catch (\InvalidArgumentException $e)
{
throw new NotFoundHttpException("Unknown element type '{$elementType}'.", $e);
}
} | [
"public",
"function",
"elementsOverviewAction",
"(",
"$",
"elementType",
")",
"{",
"try",
"{",
"$",
"elementReferences",
"=",
"array_map",
"(",
"function",
"(",
"Element",
"$",
"element",
")",
"{",
"return",
"$",
"element",
"->",
"getReference",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"elementTypesModel",
"->",
"getListedElements",
"(",
"$",
"elementType",
")",
")",
";",
"return",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"\"@core/elements_overview_page.twig\"",
",",
"[",
"\"elementReferences\"",
"=>",
"$",
"elementReferences",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"\"Unknown element type '{$elementType}'.\"",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Returns a list of all elements of the given type
@param $elementType
@return string | [
"Returns",
"a",
"list",
"of",
"all",
"elements",
"of",
"the",
"given",
"type"
] | 837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786 | https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Controller/CoreController.php#L115-L135 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.