repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
4devs/ElfinderPhpConnector | Driver/LocalDriver.php | LocalDriver.getFileInfo | private function getFileInfo($file)
{
if (!file_exists($file)) {
throw new NotFoundException(sprintf('file "%s" not found', $file));
}
$fileStat = stat($file);
$directory = dirname($file) == '.' ? '' : dirname($file);
$fileInfo = new FileInfo($this->basename($file), $this->getDriverId(), $fileStat['mtime'], $directory);
$fileInfo->setSize($fileStat['size']);
$fileInfo->setWrite(is_writable($file));
$fileInfo->setMime($this->getMimeType($file));
$fileInfo->setLocked($this->driverOptions['locked']);
$this->setDirs($fileInfo, $file);
$tmb = $this->getThumb($file);
if (!file_exists($tmb) && in_array($fileInfo->getMime(), ['image/jpeg', 'image/png', 'image/gif'])) {
$fileInfo->setTmb(1);
} elseif (file_exists($tmb)) {
$fileInfo->setTmb(DIRECTORY_SEPARATOR.$tmb);
}
return $fileInfo;
} | php | private function getFileInfo($file)
{
if (!file_exists($file)) {
throw new NotFoundException(sprintf('file "%s" not found', $file));
}
$fileStat = stat($file);
$directory = dirname($file) == '.' ? '' : dirname($file);
$fileInfo = new FileInfo($this->basename($file), $this->getDriverId(), $fileStat['mtime'], $directory);
$fileInfo->setSize($fileStat['size']);
$fileInfo->setWrite(is_writable($file));
$fileInfo->setMime($this->getMimeType($file));
$fileInfo->setLocked($this->driverOptions['locked']);
$this->setDirs($fileInfo, $file);
$tmb = $this->getThumb($file);
if (!file_exists($tmb) && in_array($fileInfo->getMime(), ['image/jpeg', 'image/png', 'image/gif'])) {
$fileInfo->setTmb(1);
} elseif (file_exists($tmb)) {
$fileInfo->setTmb(DIRECTORY_SEPARATOR.$tmb);
}
return $fileInfo;
} | [
"private",
"function",
"getFileInfo",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"sprintf",
"(",
"'file \"%s\" not found'",
",",
"$",
"file",
")",
")",
";",
"}",
"$",
"fileStat",
"=",
"stat",
"(",
"$",
"file",
")",
";",
"$",
"directory",
"=",
"dirname",
"(",
"$",
"file",
")",
"==",
"'.'",
"?",
"''",
":",
"dirname",
"(",
"$",
"file",
")",
";",
"$",
"fileInfo",
"=",
"new",
"FileInfo",
"(",
"$",
"this",
"->",
"basename",
"(",
"$",
"file",
")",
",",
"$",
"this",
"->",
"getDriverId",
"(",
")",
",",
"$",
"fileStat",
"[",
"'mtime'",
"]",
",",
"$",
"directory",
")",
";",
"$",
"fileInfo",
"->",
"setSize",
"(",
"$",
"fileStat",
"[",
"'size'",
"]",
")",
";",
"$",
"fileInfo",
"->",
"setWrite",
"(",
"is_writable",
"(",
"$",
"file",
")",
")",
";",
"$",
"fileInfo",
"->",
"setMime",
"(",
"$",
"this",
"->",
"getMimeType",
"(",
"$",
"file",
")",
")",
";",
"$",
"fileInfo",
"->",
"setLocked",
"(",
"$",
"this",
"->",
"driverOptions",
"[",
"'locked'",
"]",
")",
";",
"$",
"this",
"->",
"setDirs",
"(",
"$",
"fileInfo",
",",
"$",
"file",
")",
";",
"$",
"tmb",
"=",
"$",
"this",
"->",
"getThumb",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"tmb",
")",
"&&",
"in_array",
"(",
"$",
"fileInfo",
"->",
"getMime",
"(",
")",
",",
"[",
"'image/jpeg'",
",",
"'image/png'",
",",
"'image/gif'",
"]",
")",
")",
"{",
"$",
"fileInfo",
"->",
"setTmb",
"(",
"1",
")",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"tmb",
")",
")",
"{",
"$",
"fileInfo",
"->",
"setTmb",
"(",
"DIRECTORY_SEPARATOR",
".",
"$",
"tmb",
")",
";",
"}",
"return",
"$",
"fileInfo",
";",
"}"
]
| get file info by full path file name.
@param string $file
@return FileInfo | [
"get",
"file",
"info",
"by",
"full",
"path",
"file",
"name",
"."
]
| train | https://github.com/4devs/ElfinderPhpConnector/blob/510e295dcafeaa0f796986ad87b3ed5f6b0d9338/Driver/LocalDriver.php#L525-L546 |
4devs/ElfinderPhpConnector | Driver/LocalDriver.php | LocalDriver.getMimeType | private function getMimeType($file)
{
$type = FileInfo::DIRECTORY_MIME_TYPE;
if (is_file($file)) {
if (class_exists('finfo')) {
$finfo = new \finfo(FILEINFO_MIME);
$type = $finfo->file($file);
} else {
$type = MimeType::getTypeByExt(pathinfo($file, PATHINFO_EXTENSION));
}
}
$type = strstr($type, ';', true) ?: $type;
return isset(MimeType::$internalType[$type]) ? MimeType::$internalType[$type] : $type;
} | php | private function getMimeType($file)
{
$type = FileInfo::DIRECTORY_MIME_TYPE;
if (is_file($file)) {
if (class_exists('finfo')) {
$finfo = new \finfo(FILEINFO_MIME);
$type = $finfo->file($file);
} else {
$type = MimeType::getTypeByExt(pathinfo($file, PATHINFO_EXTENSION));
}
}
$type = strstr($type, ';', true) ?: $type;
return isset(MimeType::$internalType[$type]) ? MimeType::$internalType[$type] : $type;
} | [
"private",
"function",
"getMimeType",
"(",
"$",
"file",
")",
"{",
"$",
"type",
"=",
"FileInfo",
"::",
"DIRECTORY_MIME_TYPE",
";",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'finfo'",
")",
")",
"{",
"$",
"finfo",
"=",
"new",
"\\",
"finfo",
"(",
"FILEINFO_MIME",
")",
";",
"$",
"type",
"=",
"$",
"finfo",
"->",
"file",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"MimeType",
"::",
"getTypeByExt",
"(",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
")",
";",
"}",
"}",
"$",
"type",
"=",
"strstr",
"(",
"$",
"type",
",",
"';'",
",",
"true",
")",
"?",
":",
"$",
"type",
";",
"return",
"isset",
"(",
"MimeType",
"::",
"$",
"internalType",
"[",
"$",
"type",
"]",
")",
"?",
"MimeType",
"::",
"$",
"internalType",
"[",
"$",
"type",
"]",
":",
"$",
"type",
";",
"}"
]
| get Mime Type by File.
@param string $file
@return string | [
"get",
"Mime",
"Type",
"by",
"File",
"."
]
| train | https://github.com/4devs/ElfinderPhpConnector/blob/510e295dcafeaa0f796986ad87b3ed5f6b0d9338/Driver/LocalDriver.php#L555-L569 |
4devs/ElfinderPhpConnector | Driver/LocalDriver.php | LocalDriver.scanDir | private function scanDir($dir, $onlyDir = 0)
{
$files = array();
foreach (glob($dir.'/*', $onlyDir) as $name) {
if ($this->isShowFile($name, $this->driverOptions['showHidden'])) {
$file = $this->getFileInfo($name);
$this->setDirs($file, $name);
$files[] = $file;
}
}
return $files;
} | php | private function scanDir($dir, $onlyDir = 0)
{
$files = array();
foreach (glob($dir.'/*', $onlyDir) as $name) {
if ($this->isShowFile($name, $this->driverOptions['showHidden'])) {
$file = $this->getFileInfo($name);
$this->setDirs($file, $name);
$files[] = $file;
}
}
return $files;
} | [
"private",
"function",
"scanDir",
"(",
"$",
"dir",
",",
"$",
"onlyDir",
"=",
"0",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"glob",
"(",
"$",
"dir",
".",
"'/*'",
",",
"$",
"onlyDir",
")",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isShowFile",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"driverOptions",
"[",
"'showHidden'",
"]",
")",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileInfo",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"setDirs",
"(",
"$",
"file",
",",
"$",
"name",
")",
";",
"$",
"files",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"}",
"return",
"$",
"files",
";",
"}"
]
| get Files by dir name.
@param string $dir
@param int $onlyDir
@return FileInfo[] | [
"get",
"Files",
"by",
"dir",
"name",
"."
]
| train | https://github.com/4devs/ElfinderPhpConnector/blob/510e295dcafeaa0f796986ad87b3ed5f6b0d9338/Driver/LocalDriver.php#L579-L591 |
4devs/ElfinderPhpConnector | Driver/LocalDriver.php | LocalDriver.setDirs | private function setDirs(FileInfo $file, $fulName)
{
if ($file->isDir()) {
if (count(glob($fulName.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR))) {
$file->setDirs(1);
}
}
} | php | private function setDirs(FileInfo $file, $fulName)
{
if ($file->isDir()) {
if (count(glob($fulName.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR))) {
$file->setDirs(1);
}
}
} | [
"private",
"function",
"setDirs",
"(",
"FileInfo",
"$",
"file",
",",
"$",
"fulName",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"if",
"(",
"count",
"(",
"glob",
"(",
"$",
"fulName",
".",
"DIRECTORY_SEPARATOR",
".",
"'*'",
",",
"GLOB_ONLYDIR",
")",
")",
")",
"{",
"$",
"file",
"->",
"setDirs",
"(",
"1",
")",
";",
"}",
"}",
"}"
]
| set dit $file if it has folders.
@param FileInfo $file
@param string $fulName | [
"set",
"dit",
"$file",
"if",
"it",
"has",
"folders",
"."
]
| train | https://github.com/4devs/ElfinderPhpConnector/blob/510e295dcafeaa0f796986ad87b3ed5f6b0d9338/Driver/LocalDriver.php#L606-L613 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/HTTPClient.php | HTTPClient.execute | protected function execute($method, $ressource, array $params = array())
{
$this->lastException = null;
$url = $this->APIURL.$ressource;
// If we need a request body, it's the last element of the params array
// Otherwise it's null
if($method == 'POST' || $method == 'PUT')
{
$data = array_pop($params);
if($this->serializeCallback)
{
$data = call_user_func($this->serializeCallback, $data);
}
}
else
{
$data = null;
}
// The rest of the params array is urlencode'd and sprintf'ed
// into the ressource itself
if($params)
{
$params = array_map('urlencode', $params);
array_unshift($params, $url);
$url = call_user_func_array('sprintf', $params);
}
// Let's prepare the CURL request options and HTTP header
$options = array();
$header = array();
$header['accept'] = 'Accept: '.$this->accept;
$header['content-type'] = 'Content-type: '.$this->contentType;
$header = array_merge($header, $this->headers);
switch($method)
{
case 'GET':
// Nothing to do
break;
case 'POST':
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $data;
break;
case 'PUT':
$fh = fopen('php://temp', 'rw');
fwrite($fh, $data);
rewind($fh);
$options[CURLOPT_PUT] = true;
$options[CURLOPT_INFILE] = $fh;
$options[CURLOPT_INFILESIZE] = strlen($data);
break;
case 'DELETE':
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = '';
$options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
break;
default:
throw new \InvalidArgumentException('Unsupported HTTP method: '.$method);
}
$options[CURLOPT_URL] = $url;
$options[CURLOPT_HTTPHEADER] = $header;
if($this->enableAuth && $this->username)
{
$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
$options[CURLOPT_USERPWD] = $this->username.':'.$this->password;
}
$options[CURLOPT_TIMEOUT] = 10;
$options[CURLOPT_CONNECTTIMEOUT] = 10;
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_USERAGENT] = 'maniaplanet-ws-sdk/'.self::VERSION;
$options[CURLOPT_SSL_VERIFYHOST] = 0;
$options[CURLOPT_SSL_VERIFYPEER] = 0;
try
{
$ch = curl_init();
curl_setopt_array($ch, $options);
$responseBody = curl_exec($ch);
$responseBodyRaw = $responseBody;
$responseInfo = curl_getinfo($ch);
// Instrumentation
$this->lastRequestExecTime = round($responseInfo['total_time'] * 1000);
if($this->slowRequestThreshold)
{
if(class_exists('\ManiaLib\Utils\Logger') && $this->lastRequestExecTime > $this->slowRequestThreshold)
{
$message = sprintf('%s ms: %s %s', $this->lastRequestExecTime, $method, $url);
\ManiaLib\Utils\Logger::info($message);
}
}
$curlError = curl_error($ch);
$curlErrorNo = curl_errno($ch);
curl_close($ch);
}
catch(\Exception $e)
{
if($ch)
{
curl_close($ch);
}
throw $e;
}
if($responseInfo['http_code'] == 200)
{
if($responseBody)
{
if($this->unserializeCallback)
{
$responseBody = call_user_func($this->unserializeCallback, $responseBody);
}
}
return $responseBody;
}
else
{
$message = $curlError;
$code = $curlErrorNo;
$statusCode = $responseInfo['http_code'];
$statusMessage = null;
if(array_key_exists($statusCode, self::$HTTPStatusCodes))
{
$statusMessage = self::$HTTPStatusCodes[$statusCode];
}
if($responseBody)
{
if($this->unserializeCallback)
{
$responseBody = call_user_func($this->unserializeCallback, $responseBody);
}
if(is_object($responseBody))
{
if(property_exists($responseBody, 'message'))
{
$message = $responseBody->message;
}
elseif(property_exists($responseBody, 'error'))
{
$message = $responseBody->error;
}
if(property_exists($responseBody, 'code'))
{
$code = $responseBody->message;
}
}
}
$exception = new Exception($message, $code, $statusCode, $statusMessage);
if($this->throwExceptions)
{
throw $exception;
}
else
{
$this->lastException = $exception;
return false;
}
}
} | php | protected function execute($method, $ressource, array $params = array())
{
$this->lastException = null;
$url = $this->APIURL.$ressource;
// If we need a request body, it's the last element of the params array
// Otherwise it's null
if($method == 'POST' || $method == 'PUT')
{
$data = array_pop($params);
if($this->serializeCallback)
{
$data = call_user_func($this->serializeCallback, $data);
}
}
else
{
$data = null;
}
// The rest of the params array is urlencode'd and sprintf'ed
// into the ressource itself
if($params)
{
$params = array_map('urlencode', $params);
array_unshift($params, $url);
$url = call_user_func_array('sprintf', $params);
}
// Let's prepare the CURL request options and HTTP header
$options = array();
$header = array();
$header['accept'] = 'Accept: '.$this->accept;
$header['content-type'] = 'Content-type: '.$this->contentType;
$header = array_merge($header, $this->headers);
switch($method)
{
case 'GET':
// Nothing to do
break;
case 'POST':
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $data;
break;
case 'PUT':
$fh = fopen('php://temp', 'rw');
fwrite($fh, $data);
rewind($fh);
$options[CURLOPT_PUT] = true;
$options[CURLOPT_INFILE] = $fh;
$options[CURLOPT_INFILESIZE] = strlen($data);
break;
case 'DELETE':
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = '';
$options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
break;
default:
throw new \InvalidArgumentException('Unsupported HTTP method: '.$method);
}
$options[CURLOPT_URL] = $url;
$options[CURLOPT_HTTPHEADER] = $header;
if($this->enableAuth && $this->username)
{
$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
$options[CURLOPT_USERPWD] = $this->username.':'.$this->password;
}
$options[CURLOPT_TIMEOUT] = 10;
$options[CURLOPT_CONNECTTIMEOUT] = 10;
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_USERAGENT] = 'maniaplanet-ws-sdk/'.self::VERSION;
$options[CURLOPT_SSL_VERIFYHOST] = 0;
$options[CURLOPT_SSL_VERIFYPEER] = 0;
try
{
$ch = curl_init();
curl_setopt_array($ch, $options);
$responseBody = curl_exec($ch);
$responseBodyRaw = $responseBody;
$responseInfo = curl_getinfo($ch);
// Instrumentation
$this->lastRequestExecTime = round($responseInfo['total_time'] * 1000);
if($this->slowRequestThreshold)
{
if(class_exists('\ManiaLib\Utils\Logger') && $this->lastRequestExecTime > $this->slowRequestThreshold)
{
$message = sprintf('%s ms: %s %s', $this->lastRequestExecTime, $method, $url);
\ManiaLib\Utils\Logger::info($message);
}
}
$curlError = curl_error($ch);
$curlErrorNo = curl_errno($ch);
curl_close($ch);
}
catch(\Exception $e)
{
if($ch)
{
curl_close($ch);
}
throw $e;
}
if($responseInfo['http_code'] == 200)
{
if($responseBody)
{
if($this->unserializeCallback)
{
$responseBody = call_user_func($this->unserializeCallback, $responseBody);
}
}
return $responseBody;
}
else
{
$message = $curlError;
$code = $curlErrorNo;
$statusCode = $responseInfo['http_code'];
$statusMessage = null;
if(array_key_exists($statusCode, self::$HTTPStatusCodes))
{
$statusMessage = self::$HTTPStatusCodes[$statusCode];
}
if($responseBody)
{
if($this->unserializeCallback)
{
$responseBody = call_user_func($this->unserializeCallback, $responseBody);
}
if(is_object($responseBody))
{
if(property_exists($responseBody, 'message'))
{
$message = $responseBody->message;
}
elseif(property_exists($responseBody, 'error'))
{
$message = $responseBody->error;
}
if(property_exists($responseBody, 'code'))
{
$code = $responseBody->message;
}
}
}
$exception = new Exception($message, $code, $statusCode, $statusMessage);
if($this->throwExceptions)
{
throw $exception;
}
else
{
$this->lastException = $exception;
return false;
}
}
} | [
"protected",
"function",
"execute",
"(",
"$",
"method",
",",
"$",
"ressource",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"lastException",
"=",
"null",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"APIURL",
".",
"$",
"ressource",
";",
"// If we need a request body, it's the last element of the params array",
"// Otherwise it's null",
"if",
"(",
"$",
"method",
"==",
"'POST'",
"||",
"$",
"method",
"==",
"'PUT'",
")",
"{",
"$",
"data",
"=",
"array_pop",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"this",
"->",
"serializeCallback",
")",
"{",
"$",
"data",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"serializeCallback",
",",
"$",
"data",
")",
";",
"}",
"}",
"else",
"{",
"$",
"data",
"=",
"null",
";",
"}",
"// The rest of the params array is urlencode'd and sprintf'ed",
"// into the ressource itself",
"if",
"(",
"$",
"params",
")",
"{",
"$",
"params",
"=",
"array_map",
"(",
"'urlencode'",
",",
"$",
"params",
")",
";",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"url",
")",
";",
"$",
"url",
"=",
"call_user_func_array",
"(",
"'sprintf'",
",",
"$",
"params",
")",
";",
"}",
"// Let's prepare the CURL request options and HTTP header",
"$",
"options",
"=",
"array",
"(",
")",
";",
"$",
"header",
"=",
"array",
"(",
")",
";",
"$",
"header",
"[",
"'accept'",
"]",
"=",
"'Accept: '",
".",
"$",
"this",
"->",
"accept",
";",
"$",
"header",
"[",
"'content-type'",
"]",
"=",
"'Content-type: '",
".",
"$",
"this",
"->",
"contentType",
";",
"$",
"header",
"=",
"array_merge",
"(",
"$",
"header",
",",
"$",
"this",
"->",
"headers",
")",
";",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'GET'",
":",
"// Nothing to do",
"break",
";",
"case",
"'POST'",
":",
"$",
"options",
"[",
"CURLOPT_POST",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"$",
"data",
";",
"break",
";",
"case",
"'PUT'",
":",
"$",
"fh",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'rw'",
")",
";",
"fwrite",
"(",
"$",
"fh",
",",
"$",
"data",
")",
";",
"rewind",
"(",
"$",
"fh",
")",
";",
"$",
"options",
"[",
"CURLOPT_PUT",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"CURLOPT_INFILE",
"]",
"=",
"$",
"fh",
";",
"$",
"options",
"[",
"CURLOPT_INFILESIZE",
"]",
"=",
"strlen",
"(",
"$",
"data",
")",
";",
"break",
";",
"case",
"'DELETE'",
":",
"$",
"options",
"[",
"CURLOPT_POST",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"''",
";",
"$",
"options",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"'DELETE'",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unsupported HTTP method: '",
".",
"$",
"method",
")",
";",
"}",
"$",
"options",
"[",
"CURLOPT_URL",
"]",
"=",
"$",
"url",
";",
"$",
"options",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"$",
"header",
";",
"if",
"(",
"$",
"this",
"->",
"enableAuth",
"&&",
"$",
"this",
"->",
"username",
")",
"{",
"$",
"options",
"[",
"CURLOPT_HTTPAUTH",
"]",
"=",
"CURLAUTH_BASIC",
";",
"$",
"options",
"[",
"CURLOPT_USERPWD",
"]",
"=",
"$",
"this",
"->",
"username",
".",
"':'",
".",
"$",
"this",
"->",
"password",
";",
"}",
"$",
"options",
"[",
"CURLOPT_TIMEOUT",
"]",
"=",
"10",
";",
"$",
"options",
"[",
"CURLOPT_CONNECTTIMEOUT",
"]",
"=",
"10",
";",
"$",
"options",
"[",
"CURLOPT_RETURNTRANSFER",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"CURLOPT_USERAGENT",
"]",
"=",
"'maniaplanet-ws-sdk/'",
".",
"self",
"::",
"VERSION",
";",
"$",
"options",
"[",
"CURLOPT_SSL_VERIFYHOST",
"]",
"=",
"0",
";",
"$",
"options",
"[",
"CURLOPT_SSL_VERIFYPEER",
"]",
"=",
"0",
";",
"try",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt_array",
"(",
"$",
"ch",
",",
"$",
"options",
")",
";",
"$",
"responseBody",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"responseBodyRaw",
"=",
"$",
"responseBody",
";",
"$",
"responseInfo",
"=",
"curl_getinfo",
"(",
"$",
"ch",
")",
";",
"// Instrumentation",
"$",
"this",
"->",
"lastRequestExecTime",
"=",
"round",
"(",
"$",
"responseInfo",
"[",
"'total_time'",
"]",
"*",
"1000",
")",
";",
"if",
"(",
"$",
"this",
"->",
"slowRequestThreshold",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\ManiaLib\\Utils\\Logger'",
")",
"&&",
"$",
"this",
"->",
"lastRequestExecTime",
">",
"$",
"this",
"->",
"slowRequestThreshold",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'%s ms: %s %s'",
",",
"$",
"this",
"->",
"lastRequestExecTime",
",",
"$",
"method",
",",
"$",
"url",
")",
";",
"\\",
"ManiaLib",
"\\",
"Utils",
"\\",
"Logger",
"::",
"info",
"(",
"$",
"message",
")",
";",
"}",
"}",
"$",
"curlError",
"=",
"curl_error",
"(",
"$",
"ch",
")",
";",
"$",
"curlErrorNo",
"=",
"curl_errno",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"ch",
")",
"{",
"curl_close",
"(",
"$",
"ch",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"$",
"responseInfo",
"[",
"'http_code'",
"]",
"==",
"200",
")",
"{",
"if",
"(",
"$",
"responseBody",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"unserializeCallback",
")",
"{",
"$",
"responseBody",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"unserializeCallback",
",",
"$",
"responseBody",
")",
";",
"}",
"}",
"return",
"$",
"responseBody",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"$",
"curlError",
";",
"$",
"code",
"=",
"$",
"curlErrorNo",
";",
"$",
"statusCode",
"=",
"$",
"responseInfo",
"[",
"'http_code'",
"]",
";",
"$",
"statusMessage",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"statusCode",
",",
"self",
"::",
"$",
"HTTPStatusCodes",
")",
")",
"{",
"$",
"statusMessage",
"=",
"self",
"::",
"$",
"HTTPStatusCodes",
"[",
"$",
"statusCode",
"]",
";",
"}",
"if",
"(",
"$",
"responseBody",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"unserializeCallback",
")",
"{",
"$",
"responseBody",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"unserializeCallback",
",",
"$",
"responseBody",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"responseBody",
")",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"responseBody",
",",
"'message'",
")",
")",
"{",
"$",
"message",
"=",
"$",
"responseBody",
"->",
"message",
";",
"}",
"elseif",
"(",
"property_exists",
"(",
"$",
"responseBody",
",",
"'error'",
")",
")",
"{",
"$",
"message",
"=",
"$",
"responseBody",
"->",
"error",
";",
"}",
"if",
"(",
"property_exists",
"(",
"$",
"responseBody",
",",
"'code'",
")",
")",
"{",
"$",
"code",
"=",
"$",
"responseBody",
"->",
"message",
";",
"}",
"}",
"}",
"$",
"exception",
"=",
"new",
"Exception",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"statusCode",
",",
"$",
"statusMessage",
")",
";",
"if",
"(",
"$",
"this",
"->",
"throwExceptions",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"lastException",
"=",
"$",
"exception",
";",
"return",
"false",
";",
"}",
"}",
"}"
]
| Executes a HTTP request on the API.
The usage of the $ressource and $params parameters is similar to the use
of the sprintf() function. You can PUT sprintf() placeholders in the
$ressource, and the first elements of the $params array will be
urlencode'd and sprintf()'ed in the ressource. The last element of the
$params array will be serialized and used for request body if using
POST or PUT methods.
Examples:
<code>
$obj->execute('GET', '/stuff/%s/', array('foobar')); // => /stuff/foobar/
$obj->execute('GET', '/stuff/%s/', array('foo bar')); // => /stuff/foo%20bar/
$obj->execute('GET', '/stuff/%s/%d/', array('foobar', 1)); // => /stuff/foobar/1/
$obj->execute('POST', '/stuff/', array($someDataToPost)); // => /stuff/
$obj->execute('POST', '/stuff/%s/', array('foobar', $someDataToPost)); // => /stuff/foobar/
</code>
@param string $method The HTTP method to use. Only GET, POST, PUT and DELETE are supported for now.
@param string $ressource The ressource (path after the URL + query string)
@param array $params The parameters
@return mixed The unserialized API response
@throws \Maniaplanet\WebServices\Exception | [
"Executes",
"a",
"HTTP",
"request",
"on",
"the",
"API",
"."
]
| train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/HTTPClient.php#L208-L381 |
sparwelt/imgix-lib | src/Components/HtmlTransformer.php | HtmlTransformer.transformHtml | public function transformHtml($originalHtml, array $attributesFilters = [])
{
// regex is used because:
// 1 - preserves the original html, that would otherwise change when converted to a DOM abstraction
// 2 - works with invalid surrounding html
return preg_replace_callback('/(<img[^>]+>)/i', function ($matches) use ($attributesFilters) {
try {
return $this->imageTransformer->transformImage($matches[0], $attributesFilters);
} catch (\Exception $e) {
if ($e instanceof ResolutionException || $e instanceof TransformationException) {
return $matches[0];
}
throw $e;
}
}, $originalHtml);
} | php | public function transformHtml($originalHtml, array $attributesFilters = [])
{
// regex is used because:
// 1 - preserves the original html, that would otherwise change when converted to a DOM abstraction
// 2 - works with invalid surrounding html
return preg_replace_callback('/(<img[^>]+>)/i', function ($matches) use ($attributesFilters) {
try {
return $this->imageTransformer->transformImage($matches[0], $attributesFilters);
} catch (\Exception $e) {
if ($e instanceof ResolutionException || $e instanceof TransformationException) {
return $matches[0];
}
throw $e;
}
}, $originalHtml);
} | [
"public",
"function",
"transformHtml",
"(",
"$",
"originalHtml",
",",
"array",
"$",
"attributesFilters",
"=",
"[",
"]",
")",
"{",
"// regex is used because:",
"// 1 - preserves the original html, that would otherwise change when converted to a DOM abstraction",
"// 2 - works with invalid surrounding html",
"return",
"preg_replace_callback",
"(",
"'/(<img[^>]+>)/i'",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"attributesFilters",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"imageTransformer",
"->",
"transformImage",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"$",
"attributesFilters",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"instanceof",
"ResolutionException",
"||",
"$",
"e",
"instanceof",
"TransformationException",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"}",
",",
"$",
"originalHtml",
")",
";",
"}"
]
| @param string $originalHtml
@param array $attributesFilters
@return null|string|string[] | [
"@param",
"string",
"$originalHtml",
"@param",
"array",
"$attributesFilters"
]
| train | https://github.com/sparwelt/imgix-lib/blob/330e1db2bed71bc283e5a2da6246528f240939ec/src/Components/HtmlTransformer.php#L36-L51 |
factorio-item-browser/export-data | src/Entity/Machine.php | Machine.writeData | public function writeData(): array
{
$dataBuilder = new DataBuilder();
$dataBuilder->setString('n', $this->name, '')
->setArray('l', $this->labels->writeData(), null, [])
->setArray('d', $this->descriptions->writeData(), null, [])
->setArray('c', array_values(array_unique($this->craftingCategories)), 'strval', [])
->setFloat('s', $this->craftingSpeed, 1.)
->setInteger('i', $this->numberOfItemSlots, 0)
->setInteger('f', $this->numberOfFluidInputSlots, 0)
->setInteger('u', $this->numberOfFluidOutputSlots, 0)
->setInteger('m', $this->numberOfModuleSlots, 0)
->setFloat('e', $this->energyUsage, 0.)
->setString('r', $this->energyUsageUnit, 'W')
->setString('o', $this->iconHash, '');
return $dataBuilder->getData();
} | php | public function writeData(): array
{
$dataBuilder = new DataBuilder();
$dataBuilder->setString('n', $this->name, '')
->setArray('l', $this->labels->writeData(), null, [])
->setArray('d', $this->descriptions->writeData(), null, [])
->setArray('c', array_values(array_unique($this->craftingCategories)), 'strval', [])
->setFloat('s', $this->craftingSpeed, 1.)
->setInteger('i', $this->numberOfItemSlots, 0)
->setInteger('f', $this->numberOfFluidInputSlots, 0)
->setInteger('u', $this->numberOfFluidOutputSlots, 0)
->setInteger('m', $this->numberOfModuleSlots, 0)
->setFloat('e', $this->energyUsage, 0.)
->setString('r', $this->energyUsageUnit, 'W')
->setString('o', $this->iconHash, '');
return $dataBuilder->getData();
} | [
"public",
"function",
"writeData",
"(",
")",
":",
"array",
"{",
"$",
"dataBuilder",
"=",
"new",
"DataBuilder",
"(",
")",
";",
"$",
"dataBuilder",
"->",
"setString",
"(",
"'n'",
",",
"$",
"this",
"->",
"name",
",",
"''",
")",
"->",
"setArray",
"(",
"'l'",
",",
"$",
"this",
"->",
"labels",
"->",
"writeData",
"(",
")",
",",
"null",
",",
"[",
"]",
")",
"->",
"setArray",
"(",
"'d'",
",",
"$",
"this",
"->",
"descriptions",
"->",
"writeData",
"(",
")",
",",
"null",
",",
"[",
"]",
")",
"->",
"setArray",
"(",
"'c'",
",",
"array_values",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"craftingCategories",
")",
")",
",",
"'strval'",
",",
"[",
"]",
")",
"->",
"setFloat",
"(",
"'s'",
",",
"$",
"this",
"->",
"craftingSpeed",
",",
"1.",
")",
"->",
"setInteger",
"(",
"'i'",
",",
"$",
"this",
"->",
"numberOfItemSlots",
",",
"0",
")",
"->",
"setInteger",
"(",
"'f'",
",",
"$",
"this",
"->",
"numberOfFluidInputSlots",
",",
"0",
")",
"->",
"setInteger",
"(",
"'u'",
",",
"$",
"this",
"->",
"numberOfFluidOutputSlots",
",",
"0",
")",
"->",
"setInteger",
"(",
"'m'",
",",
"$",
"this",
"->",
"numberOfModuleSlots",
",",
"0",
")",
"->",
"setFloat",
"(",
"'e'",
",",
"$",
"this",
"->",
"energyUsage",
",",
"0.",
")",
"->",
"setString",
"(",
"'r'",
",",
"$",
"this",
"->",
"energyUsageUnit",
",",
"'W'",
")",
"->",
"setString",
"(",
"'o'",
",",
"$",
"this",
"->",
"iconHash",
",",
"''",
")",
";",
"return",
"$",
"dataBuilder",
"->",
"getData",
"(",
")",
";",
"}"
]
| Writes the entity data to an array.
@return array | [
"Writes",
"the",
"entity",
"data",
"to",
"an",
"array",
"."
]
| train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Machine.php#L364-L380 |
factorio-item-browser/export-data | src/Entity/Machine.php | Machine.readData | public function readData(DataContainer $data)
{
$this->name = $data->getString('n', '');
$this->labels->readData($data->getObject('l'));
$this->descriptions->readData($data->getObject('d'));
$this->craftingCategories = array_map('strval', $data->getArray('c'));
$this->craftingSpeed = $data->getFloat('s', 1.);
$this->numberOfItemSlots = $data->getInteger('i', 0);
$this->numberOfFluidInputSlots = $data->getInteger('f', 0);
$this->numberOfFluidOutputSlots = $data->getInteger('u', 0);
$this->numberOfModuleSlots = $data->getInteger('m', 0);
$this->energyUsage = $data->getFloat('e', 0.);
$this->energyUsageUnit = $data->getString('r', 'W');
$this->iconHash = $data->getString('o');
return $this;
} | php | public function readData(DataContainer $data)
{
$this->name = $data->getString('n', '');
$this->labels->readData($data->getObject('l'));
$this->descriptions->readData($data->getObject('d'));
$this->craftingCategories = array_map('strval', $data->getArray('c'));
$this->craftingSpeed = $data->getFloat('s', 1.);
$this->numberOfItemSlots = $data->getInteger('i', 0);
$this->numberOfFluidInputSlots = $data->getInteger('f', 0);
$this->numberOfFluidOutputSlots = $data->getInteger('u', 0);
$this->numberOfModuleSlots = $data->getInteger('m', 0);
$this->energyUsage = $data->getFloat('e', 0.);
$this->energyUsageUnit = $data->getString('r', 'W');
$this->iconHash = $data->getString('o');
return $this;
} | [
"public",
"function",
"readData",
"(",
"DataContainer",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"data",
"->",
"getString",
"(",
"'n'",
",",
"''",
")",
";",
"$",
"this",
"->",
"labels",
"->",
"readData",
"(",
"$",
"data",
"->",
"getObject",
"(",
"'l'",
")",
")",
";",
"$",
"this",
"->",
"descriptions",
"->",
"readData",
"(",
"$",
"data",
"->",
"getObject",
"(",
"'d'",
")",
")",
";",
"$",
"this",
"->",
"craftingCategories",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"data",
"->",
"getArray",
"(",
"'c'",
")",
")",
";",
"$",
"this",
"->",
"craftingSpeed",
"=",
"$",
"data",
"->",
"getFloat",
"(",
"'s'",
",",
"1.",
")",
";",
"$",
"this",
"->",
"numberOfItemSlots",
"=",
"$",
"data",
"->",
"getInteger",
"(",
"'i'",
",",
"0",
")",
";",
"$",
"this",
"->",
"numberOfFluidInputSlots",
"=",
"$",
"data",
"->",
"getInteger",
"(",
"'f'",
",",
"0",
")",
";",
"$",
"this",
"->",
"numberOfFluidOutputSlots",
"=",
"$",
"data",
"->",
"getInteger",
"(",
"'u'",
",",
"0",
")",
";",
"$",
"this",
"->",
"numberOfModuleSlots",
"=",
"$",
"data",
"->",
"getInteger",
"(",
"'m'",
",",
"0",
")",
";",
"$",
"this",
"->",
"energyUsage",
"=",
"$",
"data",
"->",
"getFloat",
"(",
"'e'",
",",
"0.",
")",
";",
"$",
"this",
"->",
"energyUsageUnit",
"=",
"$",
"data",
"->",
"getString",
"(",
"'r'",
",",
"'W'",
")",
";",
"$",
"this",
"->",
"iconHash",
"=",
"$",
"data",
"->",
"getString",
"(",
"'o'",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Reads the entity data.
@param DataContainer $data
@return $this | [
"Reads",
"the",
"entity",
"data",
"."
]
| train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Machine.php#L387-L402 |
factorio-item-browser/export-data | src/Entity/Machine.php | Machine.calculateHash | public function calculateHash(): string
{
return EntityUtils::calculateHashOfArray([
$this->name,
$this->labels->calculateHash(),
$this->descriptions->calculateHash(),
$this->craftingCategories,
$this->craftingSpeed,
$this->numberOfItemSlots,
$this->numberOfFluidInputSlots,
$this->numberOfFluidOutputSlots,
$this->numberOfModuleSlots,
$this->energyUsage,
$this->energyUsageUnit,
$this->iconHash,
]);
} | php | public function calculateHash(): string
{
return EntityUtils::calculateHashOfArray([
$this->name,
$this->labels->calculateHash(),
$this->descriptions->calculateHash(),
$this->craftingCategories,
$this->craftingSpeed,
$this->numberOfItemSlots,
$this->numberOfFluidInputSlots,
$this->numberOfFluidOutputSlots,
$this->numberOfModuleSlots,
$this->energyUsage,
$this->energyUsageUnit,
$this->iconHash,
]);
} | [
"public",
"function",
"calculateHash",
"(",
")",
":",
"string",
"{",
"return",
"EntityUtils",
"::",
"calculateHashOfArray",
"(",
"[",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"labels",
"->",
"calculateHash",
"(",
")",
",",
"$",
"this",
"->",
"descriptions",
"->",
"calculateHash",
"(",
")",
",",
"$",
"this",
"->",
"craftingCategories",
",",
"$",
"this",
"->",
"craftingSpeed",
",",
"$",
"this",
"->",
"numberOfItemSlots",
",",
"$",
"this",
"->",
"numberOfFluidInputSlots",
",",
"$",
"this",
"->",
"numberOfFluidOutputSlots",
",",
"$",
"this",
"->",
"numberOfModuleSlots",
",",
"$",
"this",
"->",
"energyUsage",
",",
"$",
"this",
"->",
"energyUsageUnit",
",",
"$",
"this",
"->",
"iconHash",
",",
"]",
")",
";",
"}"
]
| Calculates a hash value representing the entity.
@return string | [
"Calculates",
"a",
"hash",
"value",
"representing",
"the",
"entity",
"."
]
| train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Machine.php#L408-L424 |
matthewbdaly/postcode-client | src/Client.php | Client.get | public function get(string $postcode)
{
$url = $this->getBaseUrl() . rawurlencode($postcode) . '?' . http_build_query([
'api_key' => $this->getKey()
]);
$request = $this->messageFactory->createRequest(
'GET',
$url,
[],
null,
'1.1'
);
$response = $this->client->sendRequest($request);
if ($response->getStatusCode() == 402) {
throw new PaymentRequired;
}
if ($response->getStatusCode() == 404) {
throw new PostcodeNotFound;
}
$data = json_decode($response->getBody()->getContents(), true);
return $data;
} | php | public function get(string $postcode)
{
$url = $this->getBaseUrl() . rawurlencode($postcode) . '?' . http_build_query([
'api_key' => $this->getKey()
]);
$request = $this->messageFactory->createRequest(
'GET',
$url,
[],
null,
'1.1'
);
$response = $this->client->sendRequest($request);
if ($response->getStatusCode() == 402) {
throw new PaymentRequired;
}
if ($response->getStatusCode() == 404) {
throw new PostcodeNotFound;
}
$data = json_decode($response->getBody()->getContents(), true);
return $data;
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"postcode",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
".",
"rawurlencode",
"(",
"$",
"postcode",
")",
".",
"'?'",
".",
"http_build_query",
"(",
"[",
"'api_key'",
"=>",
"$",
"this",
"->",
"getKey",
"(",
")",
"]",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"messageFactory",
"->",
"createRequest",
"(",
"'GET'",
",",
"$",
"url",
",",
"[",
"]",
",",
"null",
",",
"'1.1'",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"sendRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"==",
"402",
")",
"{",
"throw",
"new",
"PaymentRequired",
";",
"}",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"==",
"404",
")",
"{",
"throw",
"new",
"PostcodeNotFound",
";",
"}",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
",",
"true",
")",
";",
"return",
"$",
"data",
";",
"}"
]
| Make the HTTP request
@param string $postcode The postcode to look up.
@return mixed
@throws PaymentRequired Payment required to perform the lookup.
@throws PostcodeNotFound Postcode not found. | [
"Make",
"the",
"HTTP",
"request"
]
| train | https://github.com/matthewbdaly/postcode-client/blob/0900247f2b26d60c7d4141e846f123f660756421/src/Client.php#L86-L107 |
SAREhub/PHP_Commons | src/SAREhub/Commons/Misc/PeriodicTimer.php | PeriodicTimer.update | public function update($now)
{
if ($now >= ($this->lastCallTime + $this->interval)) {
$this->lastCallTime = $now;
$this->callNow();
}
} | php | public function update($now)
{
if ($now >= ($this->lastCallTime + $this->interval)) {
$this->lastCallTime = $now;
$this->callNow();
}
} | [
"public",
"function",
"update",
"(",
"$",
"now",
")",
"{",
"if",
"(",
"$",
"now",
">=",
"(",
"$",
"this",
"->",
"lastCallTime",
"+",
"$",
"this",
"->",
"interval",
")",
")",
"{",
"$",
"this",
"->",
"lastCallTime",
"=",
"$",
"now",
";",
"$",
"this",
"->",
"callNow",
"(",
")",
";",
"}",
"}"
]
| Updates that timer if is after next call its calls callback.
@param int $now | [
"Updates",
"that",
"timer",
"if",
"is",
"after",
"next",
"call",
"its",
"calls",
"callback",
"."
]
| train | https://github.com/SAREhub/PHP_Commons/blob/4e1769ab6411a584112df1151dcc90e6b82fe2bb/src/SAREhub/Commons/Misc/PeriodicTimer.php#L52-L58 |
GrahamDeprecated/CMS-Core | src/Seeds/CommentsTableSeeder.php | CommentsTableSeeder.run | public function run()
{
DB::table('comments')->delete();
$comment = array(
'body' => 'This is an example comment.',
'user_id' => 1,
'post_id' => 1,
'created_at' => new DateTime,
'updated_at' => new DateTime
);
DB::table('comments')->insert($comment);
} | php | public function run()
{
DB::table('comments')->delete();
$comment = array(
'body' => 'This is an example comment.',
'user_id' => 1,
'post_id' => 1,
'created_at' => new DateTime,
'updated_at' => new DateTime
);
DB::table('comments')->insert($comment);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"DB",
"::",
"table",
"(",
"'comments'",
")",
"->",
"delete",
"(",
")",
";",
"$",
"comment",
"=",
"array",
"(",
"'body'",
"=>",
"'This is an example comment.'",
",",
"'user_id'",
"=>",
"1",
",",
"'post_id'",
"=>",
"1",
",",
"'created_at'",
"=>",
"new",
"DateTime",
",",
"'updated_at'",
"=>",
"new",
"DateTime",
")",
";",
"DB",
"::",
"table",
"(",
"'comments'",
")",
"->",
"insert",
"(",
"$",
"comment",
")",
";",
"}"
]
| Run the database seeding.
@return void | [
"Run",
"the",
"database",
"seeding",
"."
]
| train | https://github.com/GrahamDeprecated/CMS-Core/blob/5603e2bfa2fac6cf46ca3ed62d21518f2f653675/src/Seeds/CommentsTableSeeder.php#L39-L52 |
digitalkaoz/versioneye-php | src/Api/Products.php | Products.search | public function search($query, $language = null, $group = null)
{
$url = sprintf('products/search/%s?%s', $query, http_build_query([
'lang' => $language,
'g' => $group,
'page' => 1,
]));
return $this->request($url);
} | php | public function search($query, $language = null, $group = null)
{
$url = sprintf('products/search/%s?%s', $query, http_build_query([
'lang' => $language,
'g' => $group,
'page' => 1,
]));
return $this->request($url);
} | [
"public",
"function",
"search",
"(",
"$",
"query",
",",
"$",
"language",
"=",
"null",
",",
"$",
"group",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"sprintf",
"(",
"'products/search/%s?%s'",
",",
"$",
"query",
",",
"http_build_query",
"(",
"[",
"'lang'",
"=>",
"$",
"language",
",",
"'g'",
"=>",
"$",
"group",
",",
"'page'",
"=>",
"1",
",",
"]",
")",
")",
";",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"url",
")",
";",
"}"
]
| search packages.
@param string $query
@param string $language
@param string $group
@return array | [
"search",
"packages",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/Products.php#L23-L32 |
digitalkaoz/versioneye-php | src/Api/Products.php | Products.show | public function show($language, $product)
{
return $this->request(sprintf('products/%s/%s', $language, $this->transform($product)));
} | php | public function show($language, $product)
{
return $this->request(sprintf('products/%s/%s', $language, $this->transform($product)));
} | [
"public",
"function",
"show",
"(",
"$",
"language",
",",
"$",
"product",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"sprintf",
"(",
"'products/%s/%s'",
",",
"$",
"language",
",",
"$",
"this",
"->",
"transform",
"(",
"$",
"product",
")",
")",
")",
";",
"}"
]
| detailed information for specific package.
@param string $language
@param string $product
@return array | [
"detailed",
"information",
"for",
"specific",
"package",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/Products.php#L42-L45 |
digitalkaoz/versioneye-php | src/Api/Products.php | Products.followStatus | public function followStatus($language, $product)
{
return $this->request(sprintf('products/%s/%s/follow', $language, $this->transform($product)));
} | php | public function followStatus($language, $product)
{
return $this->request(sprintf('products/%s/%s/follow', $language, $this->transform($product)));
} | [
"public",
"function",
"followStatus",
"(",
"$",
"language",
",",
"$",
"product",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"sprintf",
"(",
"'products/%s/%s/follow'",
",",
"$",
"language",
",",
"$",
"this",
"->",
"transform",
"(",
"$",
"product",
")",
")",
")",
";",
"}"
]
| check your following status.
@param string $language
@param string $product
@return array | [
"check",
"your",
"following",
"status",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/Products.php#L55-L58 |
digitalkaoz/versioneye-php | src/Api/Products.php | Products.follow | public function follow($language, $product)
{
return $this->request(sprintf('products/%s/%s/follow', $language, $this->transform($product)), 'POST');
} | php | public function follow($language, $product)
{
return $this->request(sprintf('products/%s/%s/follow', $language, $this->transform($product)), 'POST');
} | [
"public",
"function",
"follow",
"(",
"$",
"language",
",",
"$",
"product",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"sprintf",
"(",
"'products/%s/%s/follow'",
",",
"$",
"language",
",",
"$",
"this",
"->",
"transform",
"(",
"$",
"product",
")",
")",
",",
"'POST'",
")",
";",
"}"
]
| follow your favorite software package.
@param string $language
@param string $product
@return array | [
"follow",
"your",
"favorite",
"software",
"package",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/Products.php#L68-L71 |
digitalkaoz/versioneye-php | src/Api/Products.php | Products.unfollow | public function unfollow($language, $product)
{
return $this->request(sprintf('products/%s/%s/follow', $language, $this->transform($product)), 'DELETE');
} | php | public function unfollow($language, $product)
{
return $this->request(sprintf('products/%s/%s/follow', $language, $this->transform($product)), 'DELETE');
} | [
"public",
"function",
"unfollow",
"(",
"$",
"language",
",",
"$",
"product",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"sprintf",
"(",
"'products/%s/%s/follow'",
",",
"$",
"language",
",",
"$",
"this",
"->",
"transform",
"(",
"$",
"product",
")",
")",
",",
"'DELETE'",
")",
";",
"}"
]
| unfollow given software package.
@param string $language
@param string $product
@return array | [
"unfollow",
"given",
"software",
"package",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/Products.php#L81-L84 |
digitalkaoz/versioneye-php | src/Api/Products.php | Products.references | public function references($language, $product)
{
return $this->request(sprintf('products/%s/%s/references?page=%d', $language, $this->transform($product), 1));
} | php | public function references($language, $product)
{
return $this->request(sprintf('products/%s/%s/references?page=%d', $language, $this->transform($product), 1));
} | [
"public",
"function",
"references",
"(",
"$",
"language",
",",
"$",
"product",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"sprintf",
"(",
"'products/%s/%s/references?page=%d'",
",",
"$",
"language",
",",
"$",
"this",
"->",
"transform",
"(",
"$",
"product",
")",
",",
"1",
")",
")",
";",
"}"
]
| shows all references for the given package.
@param string $language
@param string $product
@return array | [
"shows",
"all",
"references",
"for",
"the",
"given",
"package",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/Products.php#L94-L97 |
digitalkaoz/versioneye-php | src/Api/Products.php | Products.versions | public function versions($language, $product)
{
return $this->request(sprintf('products/%s/%s/versions', $language, $this->transform($product)));
} | php | public function versions($language, $product)
{
return $this->request(sprintf('products/%s/%s/versions', $language, $this->transform($product)));
} | [
"public",
"function",
"versions",
"(",
"$",
"language",
",",
"$",
"product",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"sprintf",
"(",
"'products/%s/%s/versions'",
",",
"$",
"language",
",",
"$",
"this",
"->",
"transform",
"(",
"$",
"product",
")",
")",
")",
";",
"}"
]
| shows all version for the given package.
@param string $language
@param string $product
@return array | [
"shows",
"all",
"version",
"for",
"the",
"given",
"package",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/Products.php#L107-L110 |
mihai-stancu/serializer | Serializer/Normalizer/DateTimeNormalizer.php | DateTimeNormalizer.normalize | public function normalize($object, $format = null, array $context = array())
{
if (!$object instanceof \DateTimeInterface) {
throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".');
}
$format = isset($context[static::CONTEXT_FORMAT]) ? $context[self::CONTEXT_FORMAT] : $this->format;
return $object->format($format);
} | php | public function normalize($object, $format = null, array $context = array())
{
if (!$object instanceof \DateTimeInterface) {
throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".');
}
$format = isset($context[static::CONTEXT_FORMAT]) ? $context[self::CONTEXT_FORMAT] : $this->format;
return $object->format($format);
} | [
"public",
"function",
"normalize",
"(",
"$",
"object",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"\\",
"DateTimeInterface",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The object must implement the \"\\DateTimeInterface\".'",
")",
";",
"}",
"$",
"format",
"=",
"isset",
"(",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_FORMAT",
"]",
")",
"?",
"$",
"context",
"[",
"self",
"::",
"CONTEXT_FORMAT",
"]",
":",
"$",
"this",
"->",
"format",
";",
"return",
"$",
"object",
"->",
"format",
"(",
"$",
"format",
")",
";",
"}"
]
| @param object $object
@param string $format
@param array $context
@return string | [
"@param",
"object",
"$object",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DateTimeNormalizer.php#L64-L73 |
mihai-stancu/serializer | Serializer/Normalizer/DateTimeNormalizer.php | DateTimeNormalizer.denormalize | public function denormalize($data, $class, $format = null, array $context = array())
{
preg_match(static::REGEX, $data, $parts);
$format = '';
$format .= !empty($parts['date']) ? 'Y-m-d' : '';
$format .= !empty($parts['tsep']) ? str_replace('T', '\T', $parts['tsep']) : '';
$format .= !empty($parts['time']) ? 'H:i:s' : '';
$format .= !empty($parts['usec']) ? '.u' : '';
$format .= !empty($parts['zsep']) ? ' ' : '';
$format .= !empty($parts['zone']) ? (($parts['zone'][3] === ':') ? 'P' : 'O') : '';
$object = \DateTime::createFromFormat($format, $data);
if ($object === false) {
throw new \InvalidArgumentException('The provided data or format are not valid.');
}
return $object;
} | php | public function denormalize($data, $class, $format = null, array $context = array())
{
preg_match(static::REGEX, $data, $parts);
$format = '';
$format .= !empty($parts['date']) ? 'Y-m-d' : '';
$format .= !empty($parts['tsep']) ? str_replace('T', '\T', $parts['tsep']) : '';
$format .= !empty($parts['time']) ? 'H:i:s' : '';
$format .= !empty($parts['usec']) ? '.u' : '';
$format .= !empty($parts['zsep']) ? ' ' : '';
$format .= !empty($parts['zone']) ? (($parts['zone'][3] === ':') ? 'P' : 'O') : '';
$object = \DateTime::createFromFormat($format, $data);
if ($object === false) {
throw new \InvalidArgumentException('The provided data or format are not valid.');
}
return $object;
} | [
"public",
"function",
"denormalize",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"preg_match",
"(",
"static",
"::",
"REGEX",
",",
"$",
"data",
",",
"$",
"parts",
")",
";",
"$",
"format",
"=",
"''",
";",
"$",
"format",
".=",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'date'",
"]",
")",
"?",
"'Y-m-d'",
":",
"''",
";",
"$",
"format",
".=",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'tsep'",
"]",
")",
"?",
"str_replace",
"(",
"'T'",
",",
"'\\T'",
",",
"$",
"parts",
"[",
"'tsep'",
"]",
")",
":",
"''",
";",
"$",
"format",
".=",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'time'",
"]",
")",
"?",
"'H:i:s'",
":",
"''",
";",
"$",
"format",
".=",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'usec'",
"]",
")",
"?",
"'.u'",
":",
"''",
";",
"$",
"format",
".=",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'zsep'",
"]",
")",
"?",
"' '",
":",
"''",
";",
"$",
"format",
".=",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'zone'",
"]",
")",
"?",
"(",
"(",
"$",
"parts",
"[",
"'zone'",
"]",
"[",
"3",
"]",
"===",
"':'",
")",
"?",
"'P'",
":",
"'O'",
")",
":",
"''",
";",
"$",
"object",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"object",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The provided data or format are not valid.'",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
]
| @param string $data
@param string $class
@param string $format
@param array $context
@return \DateTimeInterface | [
"@param",
"string",
"$data",
"@param",
"string",
"$class",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DateTimeNormalizer.php#L94-L112 |
mihai-stancu/serializer | Serializer/Normalizer/DateTimeNormalizer.php | DateTimeNormalizer.supportsDenormalization | public function supportsDenormalization($data, $type, $format = null)
{
return in_array($type, static::$classes) or in_array($type, static::$types)
and is_string($data) and preg_match(static::REGEX, $data) > 0;
} | php | public function supportsDenormalization($data, $type, $format = null)
{
return in_array($type, static::$classes) or in_array($type, static::$types)
and is_string($data) and preg_match(static::REGEX, $data) > 0;
} | [
"public",
"function",
"supportsDenormalization",
"(",
"$",
"data",
",",
"$",
"type",
",",
"$",
"format",
"=",
"null",
")",
"{",
"return",
"in_array",
"(",
"$",
"type",
",",
"static",
"::",
"$",
"classes",
")",
"or",
"in_array",
"(",
"$",
"type",
",",
"static",
"::",
"$",
"types",
")",
"and",
"is_string",
"(",
"$",
"data",
")",
"and",
"preg_match",
"(",
"static",
"::",
"REGEX",
",",
"$",
"data",
")",
">",
"0",
";",
"}"
]
| @param mixed $data
@param string $type
@param string $format
@return bool | [
"@param",
"mixed",
"$data",
"@param",
"string",
"$type",
"@param",
"string",
"$format"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DateTimeNormalizer.php#L121-L125 |
ondrakoupil/tools | src/Time.php | Time.convert | static function convert($input,$outputFormat=self::PHP) {
if ($input===false) {
$input=time();
}
if ($input instanceof \DateTime) {
if ($outputFormat===self::INT) return $input->getTimestamp();
if (is_string($outputFormat)) return date($outputFormat,$input->getTimestamp());
if ($outputFormat===self::PHP) return $input;
return null;
}
if (!is_numeric($input)) {
$origInput = $input;
$input=@strtotime($input);
if ($input === false or $input === -1) {
$input = str_replace(" ","",$origInput); // Helps with formats like 13. 5. 2013
$input=@strtotime($input);
if ($input === false or $input === -1) {
throw new \InvalidArgumentException("Invalid input to Time::convert: $origInput");
}
}
}
if ($outputFormat===self::INT) return $input;
if (is_string($outputFormat)) return date($outputFormat,$input);
if ($outputFormat===self::PHP) {
$d=new \DateTime();
return $d->setTimestamp($input);
}
return null;
} | php | static function convert($input,$outputFormat=self::PHP) {
if ($input===false) {
$input=time();
}
if ($input instanceof \DateTime) {
if ($outputFormat===self::INT) return $input->getTimestamp();
if (is_string($outputFormat)) return date($outputFormat,$input->getTimestamp());
if ($outputFormat===self::PHP) return $input;
return null;
}
if (!is_numeric($input)) {
$origInput = $input;
$input=@strtotime($input);
if ($input === false or $input === -1) {
$input = str_replace(" ","",$origInput); // Helps with formats like 13. 5. 2013
$input=@strtotime($input);
if ($input === false or $input === -1) {
throw new \InvalidArgumentException("Invalid input to Time::convert: $origInput");
}
}
}
if ($outputFormat===self::INT) return $input;
if (is_string($outputFormat)) return date($outputFormat,$input);
if ($outputFormat===self::PHP) {
$d=new \DateTime();
return $d->setTimestamp($input);
}
return null;
} | [
"static",
"function",
"convert",
"(",
"$",
"input",
",",
"$",
"outputFormat",
"=",
"self",
"::",
"PHP",
")",
"{",
"if",
"(",
"$",
"input",
"===",
"false",
")",
"{",
"$",
"input",
"=",
"time",
"(",
")",
";",
"}",
"if",
"(",
"$",
"input",
"instanceof",
"\\",
"DateTime",
")",
"{",
"if",
"(",
"$",
"outputFormat",
"===",
"self",
"::",
"INT",
")",
"return",
"$",
"input",
"->",
"getTimestamp",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"outputFormat",
")",
")",
"return",
"date",
"(",
"$",
"outputFormat",
",",
"$",
"input",
"->",
"getTimestamp",
"(",
")",
")",
";",
"if",
"(",
"$",
"outputFormat",
"===",
"self",
"::",
"PHP",
")",
"return",
"$",
"input",
";",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"input",
")",
")",
"{",
"$",
"origInput",
"=",
"$",
"input",
";",
"$",
"input",
"=",
"@",
"strtotime",
"(",
"$",
"input",
")",
";",
"if",
"(",
"$",
"input",
"===",
"false",
"or",
"$",
"input",
"===",
"-",
"1",
")",
"{",
"$",
"input",
"=",
"str_replace",
"(",
"\" \"",
",",
"\"\"",
",",
"$",
"origInput",
")",
";",
"// Helps with formats like 13. 5. 2013",
"$",
"input",
"=",
"@",
"strtotime",
"(",
"$",
"input",
")",
";",
"if",
"(",
"$",
"input",
"===",
"false",
"or",
"$",
"input",
"===",
"-",
"1",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid input to Time::convert: $origInput\"",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"outputFormat",
"===",
"self",
"::",
"INT",
")",
"return",
"$",
"input",
";",
"if",
"(",
"is_string",
"(",
"$",
"outputFormat",
")",
")",
"return",
"date",
"(",
"$",
"outputFormat",
",",
"$",
"input",
")",
";",
"if",
"(",
"$",
"outputFormat",
"===",
"self",
"::",
"PHP",
")",
"{",
"$",
"d",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"return",
"$",
"d",
"->",
"setTimestamp",
"(",
"$",
"input",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Konverze časového údaje do různých formátů.
@param bool|int|string|\DateTime $input Vstupní čas. False = aktuální čas.
@param int $outputFormat Konstanty
@return \DateTime|string|int
@throws \InvalidArgumentException | [
"Konverze",
"časového",
"údaje",
"do",
"různých",
"formátů",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Time.php#L73-L104 |
ondrakoupil/tools | src/Time.php | Time.relative | static function relative($time, $alwaysTime = false) {
$time=self::convert($time, self::PHP);
$today=date("Ymd");
if ($time->format("Ymd")==$today) {
return "dnes v ".$time->format("H.i");
}
$time2=clone $time;
if ($time2->add(new DateInterval("P1D"))->format("Ymd")==$today) {
return "včera v ".$time->format("H.i");
}
$time2=clone $time;
if ($time2->add(new DateInterval("P2D"))->format("Ymd")==$today) {
return "předevčírem v ".$time->format("H.i");
}
if ($time->format("Y")==date("Y")) {
return $time->format("j. n.").($alwaysTime?(" v ".$time->format("H.i")):"");
}
return $time->format("j. n. Y").($alwaysTime?(" v ".$time->format("H.i")):"");
} | php | static function relative($time, $alwaysTime = false) {
$time=self::convert($time, self::PHP);
$today=date("Ymd");
if ($time->format("Ymd")==$today) {
return "dnes v ".$time->format("H.i");
}
$time2=clone $time;
if ($time2->add(new DateInterval("P1D"))->format("Ymd")==$today) {
return "včera v ".$time->format("H.i");
}
$time2=clone $time;
if ($time2->add(new DateInterval("P2D"))->format("Ymd")==$today) {
return "předevčírem v ".$time->format("H.i");
}
if ($time->format("Y")==date("Y")) {
return $time->format("j. n.").($alwaysTime?(" v ".$time->format("H.i")):"");
}
return $time->format("j. n. Y").($alwaysTime?(" v ".$time->format("H.i")):"");
} | [
"static",
"function",
"relative",
"(",
"$",
"time",
",",
"$",
"alwaysTime",
"=",
"false",
")",
"{",
"$",
"time",
"=",
"self",
"::",
"convert",
"(",
"$",
"time",
",",
"self",
"::",
"PHP",
")",
";",
"$",
"today",
"=",
"date",
"(",
"\"Ymd\"",
")",
";",
"if",
"(",
"$",
"time",
"->",
"format",
"(",
"\"Ymd\"",
")",
"==",
"$",
"today",
")",
"{",
"return",
"\"dnes v \"",
".",
"$",
"time",
"->",
"format",
"(",
"\"H.i\"",
")",
";",
"}",
"$",
"time2",
"=",
"clone",
"$",
"time",
";",
"if",
"(",
"$",
"time2",
"->",
"add",
"(",
"new",
"DateInterval",
"(",
"\"P1D\"",
")",
")",
"->",
"format",
"(",
"\"Ymd\"",
")",
"==",
"$",
"today",
")",
"{",
"return",
"\"včera v \".",
"$",
"t",
"ime-",
">f",
"ormat(",
"\"",
"H.i\")",
";",
"",
"}",
"$",
"time2",
"=",
"clone",
"$",
"time",
";",
"if",
"(",
"$",
"time2",
"->",
"add",
"(",
"new",
"DateInterval",
"(",
"\"P2D\"",
")",
")",
"->",
"format",
"(",
"\"Ymd\"",
")",
"==",
"$",
"today",
")",
"{",
"return",
"\"předevčírem v \".$t",
"i",
"m",
"e->f",
"or",
"mat(\"H",
".",
"i\");",
"",
"",
"}",
"if",
"(",
"$",
"time",
"->",
"format",
"(",
"\"Y\"",
")",
"==",
"date",
"(",
"\"Y\"",
")",
")",
"{",
"return",
"$",
"time",
"->",
"format",
"(",
"\"j. n.\"",
")",
".",
"(",
"$",
"alwaysTime",
"?",
"(",
"\" v \"",
".",
"$",
"time",
"->",
"format",
"(",
"\"H.i\"",
")",
")",
":",
"\"\"",
")",
";",
"}",
"return",
"$",
"time",
"->",
"format",
"(",
"\"j. n. Y\"",
")",
".",
"(",
"$",
"alwaysTime",
"?",
"(",
"\" v \"",
".",
"$",
"time",
"->",
"format",
"(",
"\"H.i\"",
")",
")",
":",
"\"\"",
")",
";",
"}"
]
| České vyjádření relativního času k dnešku. Česky.
@param mixed $time Cokoliv, co umí přijmout convertTime()
@param bool $alwaysTime True = i u starých událostí přidávat čas dne
@return string | [
"České",
"vyjádření",
"relativního",
"času",
"k",
"dnešku",
".",
"Česky",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Time.php#L112-L130 |
ondrakoupil/tools | src/Time.php | Time.age | static function age($kdy) {
$kdy = self::convert($kdy, self::INT);
$stari=floor((time()-$kdy)/60);
if ($stari<60) {$stari=$stari." ".Strings::plural($stari,"minuta","minuty","minut");}
else {$stari=floor($stari/60);
if ($stari>=24) {$stari=(floor($stari/24)); $stari.=" ".Strings::plural($stari,"den","dny","dnů");}
else $stari=$stari." ".Strings::plural($stari,"hodina","hodiny","hodin");
}
if ($stari==-1 or $stari=="0 minut") $stari="úplně nové";
return $stari;
} | php | static function age($kdy) {
$kdy = self::convert($kdy, self::INT);
$stari=floor((time()-$kdy)/60);
if ($stari<60) {$stari=$stari." ".Strings::plural($stari,"minuta","minuty","minut");}
else {$stari=floor($stari/60);
if ($stari>=24) {$stari=(floor($stari/24)); $stari.=" ".Strings::plural($stari,"den","dny","dnů");}
else $stari=$stari." ".Strings::plural($stari,"hodina","hodiny","hodin");
}
if ($stari==-1 or $stari=="0 minut") $stari="úplně nové";
return $stari;
} | [
"static",
"function",
"age",
"(",
"$",
"kdy",
")",
"{",
"$",
"kdy",
"=",
"self",
"::",
"convert",
"(",
"$",
"kdy",
",",
"self",
"::",
"INT",
")",
";",
"$",
"stari",
"=",
"floor",
"(",
"(",
"time",
"(",
")",
"-",
"$",
"kdy",
")",
"/",
"60",
")",
";",
"if",
"(",
"$",
"stari",
"<",
"60",
")",
"{",
"$",
"stari",
"=",
"$",
"stari",
".",
"\" \"",
".",
"Strings",
"::",
"plural",
"(",
"$",
"stari",
",",
"\"minuta\"",
",",
"\"minuty\"",
",",
"\"minut\"",
")",
";",
"}",
"else",
"{",
"$",
"stari",
"=",
"floor",
"(",
"$",
"stari",
"/",
"60",
")",
";",
"if",
"(",
"$",
"stari",
">=",
"24",
")",
"{",
"$",
"stari",
"=",
"(",
"floor",
"(",
"$",
"stari",
"/",
"24",
")",
")",
";",
"$",
"stari",
".=",
"\" \"",
".",
"Strings",
"::",
"plural",
"(",
"$",
"stari",
",",
"\"den\"",
",",
"\"dny\"",
",",
"\"dnů\")",
";",
"}",
"",
"else",
"$",
"stari",
"=",
"$",
"stari",
".",
"\" \"",
".",
"Strings",
"::",
"plural",
"(",
"$",
"stari",
",",
"\"hodina\"",
",",
"\"hodiny\"",
",",
"\"hodin\"",
")",
";",
"}",
"if",
"(",
"$",
"stari",
"==",
"-",
"1",
"or",
"$",
"stari",
"==",
"\"0 minut\"",
")",
"$",
"stari",
"=",
"\"úplně nové\";",
"",
"return",
"$",
"stari",
";",
"}"
]
| Vrátí textový údaj o stáří něčeho; používá různé jednotky. Pouze v češtině.
@param int|\DateTime $kdy Doba, kdy se stalo to něco (timestamp)
@return string Nějaký text typu '8 dní' nebo '7 minut' | [
"Vrátí",
"textový",
"údaj",
"o",
"stáří",
"něčeho",
";",
"používá",
"různé",
"jednotky",
".",
"Pouze",
"v",
"češtině",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Time.php#L139-L149 |
ondrakoupil/tools | src/Time.php | Time.holiday | static function holiday($time, $weekends = true) {
$date = self::convert($time, self::PHP);
if ($weekends) {
$w = $date->format("w");
if ($w == 0 or $w == 6) return 2;
}
$day = $date->format("dm");
if ($day == "0101" or $day == "0105" or $day == "0805" or $day == "0507" or $day == "0607"
or $day == "2809" or $day == "2810" or $day == "1711" or $day == "2412" or $day == "2512" or $day == "2612") {
return 1;
}
$day = $date->format("Ymd");
// podpora pro velikonoce do roku 2020
if ($day == "20100405" or $day == "20110425" or $day == "20120409" or $day == "20130401" or $day == "20140421"
or $day == "20150406" or $day == "20160328" or $day == "20170417" or $day == "20180402" or $day == "20190422" or $day == "20200413") {
return 1;
}
return 0;
} | php | static function holiday($time, $weekends = true) {
$date = self::convert($time, self::PHP);
if ($weekends) {
$w = $date->format("w");
if ($w == 0 or $w == 6) return 2;
}
$day = $date->format("dm");
if ($day == "0101" or $day == "0105" or $day == "0805" or $day == "0507" or $day == "0607"
or $day == "2809" or $day == "2810" or $day == "1711" or $day == "2412" or $day == "2512" or $day == "2612") {
return 1;
}
$day = $date->format("Ymd");
// podpora pro velikonoce do roku 2020
if ($day == "20100405" or $day == "20110425" or $day == "20120409" or $day == "20130401" or $day == "20140421"
or $day == "20150406" or $day == "20160328" or $day == "20170417" or $day == "20180402" or $day == "20190422" or $day == "20200413") {
return 1;
}
return 0;
} | [
"static",
"function",
"holiday",
"(",
"$",
"time",
",",
"$",
"weekends",
"=",
"true",
")",
"{",
"$",
"date",
"=",
"self",
"::",
"convert",
"(",
"$",
"time",
",",
"self",
"::",
"PHP",
")",
";",
"if",
"(",
"$",
"weekends",
")",
"{",
"$",
"w",
"=",
"$",
"date",
"->",
"format",
"(",
"\"w\"",
")",
";",
"if",
"(",
"$",
"w",
"==",
"0",
"or",
"$",
"w",
"==",
"6",
")",
"return",
"2",
";",
"}",
"$",
"day",
"=",
"$",
"date",
"->",
"format",
"(",
"\"dm\"",
")",
";",
"if",
"(",
"$",
"day",
"==",
"\"0101\"",
"or",
"$",
"day",
"==",
"\"0105\"",
"or",
"$",
"day",
"==",
"\"0805\"",
"or",
"$",
"day",
"==",
"\"0507\"",
"or",
"$",
"day",
"==",
"\"0607\"",
"or",
"$",
"day",
"==",
"\"2809\"",
"or",
"$",
"day",
"==",
"\"2810\"",
"or",
"$",
"day",
"==",
"\"1711\"",
"or",
"$",
"day",
"==",
"\"2412\"",
"or",
"$",
"day",
"==",
"\"2512\"",
"or",
"$",
"day",
"==",
"\"2612\"",
")",
"{",
"return",
"1",
";",
"}",
"$",
"day",
"=",
"$",
"date",
"->",
"format",
"(",
"\"Ymd\"",
")",
";",
"// podpora pro velikonoce do roku 2020",
"if",
"(",
"$",
"day",
"==",
"\"20100405\"",
"or",
"$",
"day",
"==",
"\"20110425\"",
"or",
"$",
"day",
"==",
"\"20120409\"",
"or",
"$",
"day",
"==",
"\"20130401\"",
"or",
"$",
"day",
"==",
"\"20140421\"",
"or",
"$",
"day",
"==",
"\"20150406\"",
"or",
"$",
"day",
"==",
"\"20160328\"",
"or",
"$",
"day",
"==",
"\"20170417\"",
"or",
"$",
"day",
"==",
"\"20180402\"",
"or",
"$",
"day",
"==",
"\"20190422\"",
"or",
"$",
"day",
"==",
"\"20200413\"",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
]
| Ověří, zda v daný den je nějaký svátek a tudíž není pracovní den. Bude fungovat do roku 2020, pak bude třeba doplnit velikonoce.
@param mixed $time
@param bool $weekends True = Vyhodnocovat i víkendy. False = jen státní svátky.
@return int 0 = pracovní den. 1 = svátek. 2 = víkend (if $weekends) | [
"Ověří",
"zda",
"v",
"daný",
"den",
"je",
"nějaký",
"svátek",
"a",
"tudíž",
"není",
"pracovní",
"den",
".",
"Bude",
"fungovat",
"do",
"roku",
"2020",
"pak",
"bude",
"třeba",
"doplnit",
"velikonoce",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Time.php#L157-L181 |
ondrakoupil/tools | src/Time.php | Time.convertInterval | static function convertInterval(DateInterval $d) {
$i = 0;
$i += $d->s;
$i += $d->i * self::MINUTE;
$i += $d->h * self::HOUR;
$i += $d->d * self::DAY;
$i += $d->m * self::MONTH;
$i += $d->y * self::YEAR;
return $i;
} | php | static function convertInterval(DateInterval $d) {
$i = 0;
$i += $d->s;
$i += $d->i * self::MINUTE;
$i += $d->h * self::HOUR;
$i += $d->d * self::DAY;
$i += $d->m * self::MONTH;
$i += $d->y * self::YEAR;
return $i;
} | [
"static",
"function",
"convertInterval",
"(",
"DateInterval",
"$",
"d",
")",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"+=",
"$",
"d",
"->",
"s",
";",
"$",
"i",
"+=",
"$",
"d",
"->",
"i",
"*",
"self",
"::",
"MINUTE",
";",
"$",
"i",
"+=",
"$",
"d",
"->",
"h",
"*",
"self",
"::",
"HOUR",
";",
"$",
"i",
"+=",
"$",
"d",
"->",
"d",
"*",
"self",
"::",
"DAY",
";",
"$",
"i",
"+=",
"$",
"d",
"->",
"m",
"*",
"self",
"::",
"MONTH",
";",
"$",
"i",
"+=",
"$",
"d",
"->",
"y",
"*",
"self",
"::",
"YEAR",
";",
"return",
"$",
"i",
";",
"}"
]
| Převede DateInterval na počet sekund.
Pokud je interval delší než 1 měsíc, pracuje jen přibližně (za měsíc se považuje cca 30,4 dne)
@param DateInterval $d
@return int | [
"Převede",
"DateInterval",
"na",
"počet",
"sekund",
".",
"Pokud",
"je",
"interval",
"delší",
"než",
"1",
"měsíc",
"pracuje",
"jen",
"přibližně",
"(",
"za",
"měsíc",
"se",
"považuje",
"cca",
"30",
"4",
"dne",
")"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Time.php#L190-L200 |
UnionOfRAD/li3_behaviors | data/model/Behaviors.php | Behaviors._initializeBehaviors | protected static function _initializeBehaviors() {
$model = get_called_class();
if (!empty(static::$_initializedBehaviors[$model])) {
return;
}
static::$_initializedBehaviors[$model] = true;
$self = $model::_object();
if (!property_exists($self, '_actsAs')) {
return;
}
foreach (Set::normalize($self->_actsAs) as $name => $config) {
static::bindBehavior($name, $config ?: []);
}
} | php | protected static function _initializeBehaviors() {
$model = get_called_class();
if (!empty(static::$_initializedBehaviors[$model])) {
return;
}
static::$_initializedBehaviors[$model] = true;
$self = $model::_object();
if (!property_exists($self, '_actsAs')) {
return;
}
foreach (Set::normalize($self->_actsAs) as $name => $config) {
static::bindBehavior($name, $config ?: []);
}
} | [
"protected",
"static",
"function",
"_initializeBehaviors",
"(",
")",
"{",
"$",
"model",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"_initializedBehaviors",
"[",
"$",
"model",
"]",
")",
")",
"{",
"return",
";",
"}",
"static",
"::",
"$",
"_initializedBehaviors",
"[",
"$",
"model",
"]",
"=",
"true",
";",
"$",
"self",
"=",
"$",
"model",
"::",
"_object",
"(",
")",
";",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"self",
",",
"'_actsAs'",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"Set",
"::",
"normalize",
"(",
"$",
"self",
"->",
"_actsAs",
")",
"as",
"$",
"name",
"=>",
"$",
"config",
")",
"{",
"static",
"::",
"bindBehavior",
"(",
"$",
"name",
",",
"$",
"config",
"?",
":",
"[",
"]",
")",
";",
"}",
"}"
]
| Initializes behaviors from the `$_actsAs` property of the model.
@return void | [
"Initializes",
"behaviors",
"from",
"the",
"$_actsAs",
"property",
"of",
"the",
"model",
"."
]
| train | https://github.com/UnionOfRAD/li3_behaviors/blob/b7051a300f91323f8776088b20e84c79790015ea/data/model/Behaviors.php#L93-L109 |
UnionOfRAD/li3_behaviors | data/model/Behaviors.php | Behaviors.bindBehavior | public static function bindBehavior($name, array $config = []) {
list($model, $class) = static::_classesForBehavior($name);
static::_initializeBehaviors();
if (is_object($name)) {
$name->config($config);
} else {
if (!class_exists($class)) {
$message = "Behavior class `{$class}` does not exist. ";
$message .= "Its name might be misspelled. Behavior was requested by ";
$message .= "model `{$model}`.";
throw new Exception($message);
}
$name = new $class($config + compact('model'));
}
static::$_behaviors[$model][$class] = $name;
} | php | public static function bindBehavior($name, array $config = []) {
list($model, $class) = static::_classesForBehavior($name);
static::_initializeBehaviors();
if (is_object($name)) {
$name->config($config);
} else {
if (!class_exists($class)) {
$message = "Behavior class `{$class}` does not exist. ";
$message .= "Its name might be misspelled. Behavior was requested by ";
$message .= "model `{$model}`.";
throw new Exception($message);
}
$name = new $class($config + compact('model'));
}
static::$_behaviors[$model][$class] = $name;
} | [
"public",
"static",
"function",
"bindBehavior",
"(",
"$",
"name",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"model",
",",
"$",
"class",
")",
"=",
"static",
"::",
"_classesForBehavior",
"(",
"$",
"name",
")",
";",
"static",
"::",
"_initializeBehaviors",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"->",
"config",
"(",
"$",
"config",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"message",
"=",
"\"Behavior class `{$class}` does not exist. \"",
";",
"$",
"message",
".=",
"\"Its name might be misspelled. Behavior was requested by \"",
";",
"$",
"message",
".=",
"\"model `{$model}`.\"",
";",
"throw",
"new",
"Exception",
"(",
"$",
"message",
")",
";",
"}",
"$",
"name",
"=",
"new",
"$",
"class",
"(",
"$",
"config",
"+",
"compact",
"(",
"'model'",
")",
")",
";",
"}",
"static",
"::",
"$",
"_behaviors",
"[",
"$",
"model",
"]",
"[",
"$",
"class",
"]",
"=",
"$",
"name",
";",
"}"
]
| Binds a new instance of a behavior to the model using given config or
entirely replacing an existing behavior instance with new config.
@param string|object $name The name of the behavior or an instance of it.
@param array $config Configuration for the behavior instance. | [
"Binds",
"a",
"new",
"instance",
"of",
"a",
"behavior",
"to",
"the",
"model",
"using",
"given",
"config",
"or",
"entirely",
"replacing",
"an",
"existing",
"behavior",
"instance",
"with",
"new",
"config",
"."
]
| train | https://github.com/UnionOfRAD/li3_behaviors/blob/b7051a300f91323f8776088b20e84c79790015ea/data/model/Behaviors.php#L196-L212 |
UnionOfRAD/li3_behaviors | data/model/Behaviors.php | Behaviors.unbindBehavior | public static function unbindBehavior($name) {
list($model, $class) = static::_classesForBehavior($name);
static::_initializeBehaviors();
if (!isset(static::$_behaviors[$model][$class])) {
throw new RuntimeException("Behavior `{$class}` not bound to model `{$model}`.");
}
unset(static::$_behaviors[$model][$class]);
} | php | public static function unbindBehavior($name) {
list($model, $class) = static::_classesForBehavior($name);
static::_initializeBehaviors();
if (!isset(static::$_behaviors[$model][$class])) {
throw new RuntimeException("Behavior `{$class}` not bound to model `{$model}`.");
}
unset(static::$_behaviors[$model][$class]);
} | [
"public",
"static",
"function",
"unbindBehavior",
"(",
"$",
"name",
")",
"{",
"list",
"(",
"$",
"model",
",",
"$",
"class",
")",
"=",
"static",
"::",
"_classesForBehavior",
"(",
"$",
"name",
")",
";",
"static",
"::",
"_initializeBehaviors",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_behaviors",
"[",
"$",
"model",
"]",
"[",
"$",
"class",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Behavior `{$class}` not bound to model `{$model}`.\"",
")",
";",
"}",
"unset",
"(",
"static",
"::",
"$",
"_behaviors",
"[",
"$",
"model",
"]",
"[",
"$",
"class",
"]",
")",
";",
"}"
]
| Unbinds an instance of a behavior from the model. Will throw
an exception if behavior is not bound.
@param string $name The name of the behavior. | [
"Unbinds",
"an",
"instance",
"of",
"a",
"behavior",
"from",
"the",
"model",
".",
"Will",
"throw",
"an",
"exception",
"if",
"behavior",
"is",
"not",
"bound",
"."
]
| train | https://github.com/UnionOfRAD/li3_behaviors/blob/b7051a300f91323f8776088b20e84c79790015ea/data/model/Behaviors.php#L220-L228 |
UnionOfRAD/li3_behaviors | data/model/Behaviors.php | Behaviors.hasBehavior | public static function hasBehavior($name) {
static::_initializeBehaviors();
try {
list($model, $class) = static::_classesForBehavior($name);
} catch (Exception $e) {
return false;
}
return isset(static::$_behaviors[$model][$class]);
} | php | public static function hasBehavior($name) {
static::_initializeBehaviors();
try {
list($model, $class) = static::_classesForBehavior($name);
} catch (Exception $e) {
return false;
}
return isset(static::$_behaviors[$model][$class]);
} | [
"public",
"static",
"function",
"hasBehavior",
"(",
"$",
"name",
")",
"{",
"static",
"::",
"_initializeBehaviors",
"(",
")",
";",
"try",
"{",
"list",
"(",
"$",
"model",
",",
"$",
"class",
")",
"=",
"static",
"::",
"_classesForBehavior",
"(",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"isset",
"(",
"static",
"::",
"$",
"_behaviors",
"[",
"$",
"model",
"]",
"[",
"$",
"class",
"]",
")",
";",
"}"
]
| Allows to check if a certain behavior is bound to the model.
@param string $name The name of the behavior.
@return boolean | [
"Allows",
"to",
"check",
"if",
"a",
"certain",
"behavior",
"is",
"bound",
"to",
"the",
"model",
"."
]
| train | https://github.com/UnionOfRAD/li3_behaviors/blob/b7051a300f91323f8776088b20e84c79790015ea/data/model/Behaviors.php#L236-L245 |
UnionOfRAD/li3_behaviors | data/model/Behaviors.php | Behaviors._classesForBehavior | protected static function _classesForBehavior($name) {
$model = get_called_class();
if (is_object($name)) {
$class = get_class($name);
} elseif (!$class = Libraries::locate('behavior', $name)) {
throw new RuntimeException("No behavior named `{$name}` found.");
}
return [$model, $class];
} | php | protected static function _classesForBehavior($name) {
$model = get_called_class();
if (is_object($name)) {
$class = get_class($name);
} elseif (!$class = Libraries::locate('behavior', $name)) {
throw new RuntimeException("No behavior named `{$name}` found.");
}
return [$model, $class];
} | [
"protected",
"static",
"function",
"_classesForBehavior",
"(",
"$",
"name",
")",
"{",
"$",
"model",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"name",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"name",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"class",
"=",
"Libraries",
"::",
"locate",
"(",
"'behavior'",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"No behavior named `{$name}` found.\"",
")",
";",
"}",
"return",
"[",
"$",
"model",
",",
"$",
"class",
"]",
";",
"}"
]
| Helper method to retrieve current model class and behavior class for name.
@param string|object $name The name of the behavior or an instance of it.
@return array An array usable with `list()` with the model and behavior classes. | [
"Helper",
"method",
"to",
"retrieve",
"current",
"model",
"class",
"and",
"behavior",
"class",
"for",
"name",
"."
]
| train | https://github.com/UnionOfRAD/li3_behaviors/blob/b7051a300f91323f8776088b20e84c79790015ea/data/model/Behaviors.php#L253-L262 |
kuria/event | src/EventSubscriber.php | EventSubscriber.listen | protected function listen(string $event, string $methodName, int $priority = 0): EventListener
{
return new EventListener($event, [$this, $methodName], $priority);
} | php | protected function listen(string $event, string $methodName, int $priority = 0): EventListener
{
return new EventListener($event, [$this, $methodName], $priority);
} | [
"protected",
"function",
"listen",
"(",
"string",
"$",
"event",
",",
"string",
"$",
"methodName",
",",
"int",
"$",
"priority",
"=",
"0",
")",
":",
"EventListener",
"{",
"return",
"new",
"EventListener",
"(",
"$",
"event",
",",
"[",
"$",
"this",
",",
"$",
"methodName",
"]",
",",
"$",
"priority",
")",
";",
"}"
]
| Create an event listener and map it to a method of this class | [
"Create",
"an",
"event",
"listener",
"and",
"map",
"it",
"to",
"a",
"method",
"of",
"this",
"class"
]
| train | https://github.com/kuria/event/blob/9ee95e751270831d5aca04f3a34a2e03b786ff41/src/EventSubscriber.php#L47-L50 |
webforge-labs/psc-cms | lib/Psc/Doctrine/TypeExporter.php | TypeExporter.getPscType | public function getPscType($dcTypeConstant) {
if ($dcTypeConstant === NULL) throw new TypeConversionException('dcTypeConstant kann nicht NULL sein');
$flip = array_flip($this->casts);
if (!array_key_exists($dcTypeConstant, $flip)) {
throw TypeConversionException::typeTarget('Doctrine-Type: '.$dcTypeConstant, 'Psc-Type');
}
return Type::create($flip[$dcTypeConstant]);
} | php | public function getPscType($dcTypeConstant) {
if ($dcTypeConstant === NULL) throw new TypeConversionException('dcTypeConstant kann nicht NULL sein');
$flip = array_flip($this->casts);
if (!array_key_exists($dcTypeConstant, $flip)) {
throw TypeConversionException::typeTarget('Doctrine-Type: '.$dcTypeConstant, 'Psc-Type');
}
return Type::create($flip[$dcTypeConstant]);
} | [
"public",
"function",
"getPscType",
"(",
"$",
"dcTypeConstant",
")",
"{",
"if",
"(",
"$",
"dcTypeConstant",
"===",
"NULL",
")",
"throw",
"new",
"TypeConversionException",
"(",
"'dcTypeConstant kann nicht NULL sein'",
")",
";",
"$",
"flip",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"casts",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"dcTypeConstant",
",",
"$",
"flip",
")",
")",
"{",
"throw",
"TypeConversionException",
"::",
"typeTarget",
"(",
"'Doctrine-Type: '",
".",
"$",
"dcTypeConstant",
",",
"'Psc-Type'",
")",
";",
"}",
"return",
"Type",
"::",
"create",
"(",
"$",
"flip",
"[",
"$",
"dcTypeConstant",
"]",
")",
";",
"}"
]
| Wandelt einen Doctrine Type in einen Psc Type um
@return Webforge\Types\Type | [
"Wandelt",
"einen",
"Doctrine",
"Type",
"in",
"einen",
"Psc",
"Type",
"um"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/TypeExporter.php#L67-L77 |
danrevah/shortify-punit | src/Matcher/ArgumentMatcher.php | ArgumentMatcher.checkMatchingArguments | protected static function checkMatchingArguments($returnValues, $arguments)
{
// if doesn't have exactly the arguments check for Hamcrest-PHP functions to validate
foreach ($returnValues as $currentMethodArguments => $currentMethod)
{
// if not its not an Hamcrest Function
if (strpos($currentMethodArguments, 'Hamcrest\\') === false) {
continue;
}
$hamcrest = unserialize($currentMethodArguments);
try
{
// Loop both hamcrest and arguments
foreach ($arguments as $index => $arg)
{
if ( ! array_key_exists($index, $hamcrest)) {
throw new AssertionError('not enough hamcrest indexes');
}
// @throws Assertion error on failure
if ($hamcrest[$index] instanceof Matcher) {
assertThat($arg, $hamcrest[$index]);
} else if ($arg != $hamcrest[$index]) {
throw new AssertionError();
}
}
}
catch(AssertionError $e) {
continue;
}
// if didn't cached assert error then its matching an hamcrest
return $currentMethodArguments;
}
return NULL;
} | php | protected static function checkMatchingArguments($returnValues, $arguments)
{
// if doesn't have exactly the arguments check for Hamcrest-PHP functions to validate
foreach ($returnValues as $currentMethodArguments => $currentMethod)
{
// if not its not an Hamcrest Function
if (strpos($currentMethodArguments, 'Hamcrest\\') === false) {
continue;
}
$hamcrest = unserialize($currentMethodArguments);
try
{
// Loop both hamcrest and arguments
foreach ($arguments as $index => $arg)
{
if ( ! array_key_exists($index, $hamcrest)) {
throw new AssertionError('not enough hamcrest indexes');
}
// @throws Assertion error on failure
if ($hamcrest[$index] instanceof Matcher) {
assertThat($arg, $hamcrest[$index]);
} else if ($arg != $hamcrest[$index]) {
throw new AssertionError();
}
}
}
catch(AssertionError $e) {
continue;
}
// if didn't cached assert error then its matching an hamcrest
return $currentMethodArguments;
}
return NULL;
} | [
"protected",
"static",
"function",
"checkMatchingArguments",
"(",
"$",
"returnValues",
",",
"$",
"arguments",
")",
"{",
"// if doesn't have exactly the arguments check for Hamcrest-PHP functions to validate",
"foreach",
"(",
"$",
"returnValues",
"as",
"$",
"currentMethodArguments",
"=>",
"$",
"currentMethod",
")",
"{",
"// if not its not an Hamcrest Function",
"if",
"(",
"strpos",
"(",
"$",
"currentMethodArguments",
",",
"'Hamcrest\\\\'",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"$",
"hamcrest",
"=",
"unserialize",
"(",
"$",
"currentMethodArguments",
")",
";",
"try",
"{",
"// Loop both hamcrest and arguments",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"index",
"=>",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"hamcrest",
")",
")",
"{",
"throw",
"new",
"AssertionError",
"(",
"'not enough hamcrest indexes'",
")",
";",
"}",
"// @throws Assertion error on failure",
"if",
"(",
"$",
"hamcrest",
"[",
"$",
"index",
"]",
"instanceof",
"Matcher",
")",
"{",
"assertThat",
"(",
"$",
"arg",
",",
"$",
"hamcrest",
"[",
"$",
"index",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"arg",
"!=",
"$",
"hamcrest",
"[",
"$",
"index",
"]",
")",
"{",
"throw",
"new",
"AssertionError",
"(",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"AssertionError",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"// if didn't cached assert error then its matching an hamcrest",
"return",
"$",
"currentMethodArguments",
";",
"}",
"return",
"NULL",
";",
"}"
]
| Checking if there is a matching Hamcrest Function
in case of founding returns the Hamcrest object otherwise returns NULL
@param $returnValues - Current return values hierarchy with the current method name
@param $arguments - Arguments to match
@return NULL or Hamcrest | [
"Checking",
"if",
"there",
"is",
"a",
"matching",
"Hamcrest",
"Function",
"in",
"case",
"of",
"founding",
"returns",
"the",
"Hamcrest",
"object",
"otherwise",
"returns",
"NULL"
]
| train | https://github.com/danrevah/shortify-punit/blob/cedd08f31de8e7409a07d2630701ef4e924cc5f0/src/Matcher/ArgumentMatcher.php#L21-L61 |
VincentChalnot/SidusAdminBundle | Form/FormHelper.php | FormHelper.getEmptyForm | public function getEmptyForm(
Action $action,
Request $request,
$data
): FormInterface {
$dataId = $data && method_exists($data, 'getId') ? $data->getId() : null;
$formOptions = $this->getDefaultFormOptions($action, $request, $dataId);
return $this->formFactory->createNamedBuilder(
"form_{$action->getAdmin()->getCode()}_{$action->getCode()}",
FormType::class,
null,
$formOptions
)->getForm();
} | php | public function getEmptyForm(
Action $action,
Request $request,
$data
): FormInterface {
$dataId = $data && method_exists($data, 'getId') ? $data->getId() : null;
$formOptions = $this->getDefaultFormOptions($action, $request, $dataId);
return $this->formFactory->createNamedBuilder(
"form_{$action->getAdmin()->getCode()}_{$action->getCode()}",
FormType::class,
null,
$formOptions
)->getForm();
} | [
"public",
"function",
"getEmptyForm",
"(",
"Action",
"$",
"action",
",",
"Request",
"$",
"request",
",",
"$",
"data",
")",
":",
"FormInterface",
"{",
"$",
"dataId",
"=",
"$",
"data",
"&&",
"method_exists",
"(",
"$",
"data",
",",
"'getId'",
")",
"?",
"$",
"data",
"->",
"getId",
"(",
")",
":",
"null",
";",
"$",
"formOptions",
"=",
"$",
"this",
"->",
"getDefaultFormOptions",
"(",
"$",
"action",
",",
"$",
"request",
",",
"$",
"dataId",
")",
";",
"return",
"$",
"this",
"->",
"formFactory",
"->",
"createNamedBuilder",
"(",
"\"form_{$action->getAdmin()->getCode()}_{$action->getCode()}\"",
",",
"FormType",
"::",
"class",
",",
"null",
",",
"$",
"formOptions",
")",
"->",
"getForm",
"(",
")",
";",
"}"
]
| @param Action $action
@param Request $request
@param mixed $data
@return FormInterface | [
"@param",
"Action",
"$action",
"@param",
"Request",
"$request",
"@param",
"mixed",
"$data"
]
| train | https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Form/FormHelper.php#L65-L79 |
VincentChalnot/SidusAdminBundle | Form/FormHelper.php | FormHelper.getDefaultFormOptions | public function getDefaultFormOptions(Action $action, Request $request, $dataId = null): array
{
$dataId = $dataId ?: 'new';
return array_merge(
$action->getFormOptions(),
[
'action' => $this->routingHelper->getCurrentUri($action, $request),
'attr' => [
'novalidate' => 'novalidate',
'id' => "form_{$action->getAdmin()->getCode()}_{$action->getCode()}_{$dataId}",
],
'method' => 'post',
]
);
} | php | public function getDefaultFormOptions(Action $action, Request $request, $dataId = null): array
{
$dataId = $dataId ?: 'new';
return array_merge(
$action->getFormOptions(),
[
'action' => $this->routingHelper->getCurrentUri($action, $request),
'attr' => [
'novalidate' => 'novalidate',
'id' => "form_{$action->getAdmin()->getCode()}_{$action->getCode()}_{$dataId}",
],
'method' => 'post',
]
);
} | [
"public",
"function",
"getDefaultFormOptions",
"(",
"Action",
"$",
"action",
",",
"Request",
"$",
"request",
",",
"$",
"dataId",
"=",
"null",
")",
":",
"array",
"{",
"$",
"dataId",
"=",
"$",
"dataId",
"?",
":",
"'new'",
";",
"return",
"array_merge",
"(",
"$",
"action",
"->",
"getFormOptions",
"(",
")",
",",
"[",
"'action'",
"=>",
"$",
"this",
"->",
"routingHelper",
"->",
"getCurrentUri",
"(",
"$",
"action",
",",
"$",
"request",
")",
",",
"'attr'",
"=>",
"[",
"'novalidate'",
"=>",
"'novalidate'",
",",
"'id'",
"=>",
"\"form_{$action->getAdmin()->getCode()}_{$action->getCode()}_{$dataId}\"",
",",
"]",
",",
"'method'",
"=>",
"'post'",
",",
"]",
")",
";",
"}"
]
| @param Action $action
@param Request $request
@param null $dataId
@return array | [
"@param",
"Action",
"$action",
"@param",
"Request",
"$request",
"@param",
"null",
"$dataId"
]
| train | https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Form/FormHelper.php#L112-L127 |
CakeCMS/Core | src/View/Helper/UrlHelper.php | UrlHelper.assetPath | public function assetPath($source, $type = null)
{
$ext = FS::ext($source);
$type = (empty($type)) ? $ext : $type;
$path = FS::clean(WWW_ROOT . '/' . $source, '/');
if (FS::isFile($path)) {
return $path;
}
$path = FS::clean(WWW_ROOT . '/' . $type . '/' . $source, '/');
if (FS::isFile($path)) {
return $path;
}
$path = $this->_findPluginAsset($source, $type);
return $path;
} | php | public function assetPath($source, $type = null)
{
$ext = FS::ext($source);
$type = (empty($type)) ? $ext : $type;
$path = FS::clean(WWW_ROOT . '/' . $source, '/');
if (FS::isFile($path)) {
return $path;
}
$path = FS::clean(WWW_ROOT . '/' . $type . '/' . $source, '/');
if (FS::isFile($path)) {
return $path;
}
$path = $this->_findPluginAsset($source, $type);
return $path;
} | [
"public",
"function",
"assetPath",
"(",
"$",
"source",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"ext",
"=",
"FS",
"::",
"ext",
"(",
"$",
"source",
")",
";",
"$",
"type",
"=",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"?",
"$",
"ext",
":",
"$",
"type",
";",
"$",
"path",
"=",
"FS",
"::",
"clean",
"(",
"WWW_ROOT",
".",
"'/'",
".",
"$",
"source",
",",
"'/'",
")",
";",
"if",
"(",
"FS",
"::",
"isFile",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"path",
";",
"}",
"$",
"path",
"=",
"FS",
"::",
"clean",
"(",
"WWW_ROOT",
".",
"'/'",
".",
"$",
"type",
".",
"'/'",
".",
"$",
"source",
",",
"'/'",
")",
";",
"if",
"(",
"FS",
"::",
"isFile",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"path",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"_findPluginAsset",
"(",
"$",
"source",
",",
"$",
"type",
")",
";",
"return",
"$",
"path",
";",
"}"
]
| Get absolute asset path.
@param string $source Plugin.path/to/file.css
@param null|string $type Assets folder - default is file ext
@return bool|string | [
"Get",
"absolute",
"asset",
"path",
"."
]
| train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/UrlHelper.php#L38-L56 |
CakeCMS/Core | src/View/Helper/UrlHelper.php | UrlHelper._findPluginAsset | protected function _findPluginAsset($source, $type = null)
{
list($plugin, $path) = pluginSplit($source);
$plugin = (string) $plugin;
if (Plugin::loaded($plugin)) {
$plgPath = implode('/', [Plugin::path($plugin), Configure::read('App.webroot'), $type, $path]);
$plgPath = FS::clean($plgPath, '/');
if (FS::isFile($plgPath)) {
return $plgPath;
}
}
return false;
} | php | protected function _findPluginAsset($source, $type = null)
{
list($plugin, $path) = pluginSplit($source);
$plugin = (string) $plugin;
if (Plugin::loaded($plugin)) {
$plgPath = implode('/', [Plugin::path($plugin), Configure::read('App.webroot'), $type, $path]);
$plgPath = FS::clean($plgPath, '/');
if (FS::isFile($plgPath)) {
return $plgPath;
}
}
return false;
} | [
"protected",
"function",
"_findPluginAsset",
"(",
"$",
"source",
",",
"$",
"type",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"plugin",
",",
"$",
"path",
")",
"=",
"pluginSplit",
"(",
"$",
"source",
")",
";",
"$",
"plugin",
"=",
"(",
"string",
")",
"$",
"plugin",
";",
"if",
"(",
"Plugin",
"::",
"loaded",
"(",
"$",
"plugin",
")",
")",
"{",
"$",
"plgPath",
"=",
"implode",
"(",
"'/'",
",",
"[",
"Plugin",
"::",
"path",
"(",
"$",
"plugin",
")",
",",
"Configure",
"::",
"read",
"(",
"'App.webroot'",
")",
",",
"$",
"type",
",",
"$",
"path",
"]",
")",
";",
"$",
"plgPath",
"=",
"FS",
"::",
"clean",
"(",
"$",
"plgPath",
",",
"'/'",
")",
";",
"if",
"(",
"FS",
"::",
"isFile",
"(",
"$",
"plgPath",
")",
")",
"{",
"return",
"$",
"plgPath",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Find plugin assets by source.
@param string $source
@param null|string $type
@return bool|string | [
"Find",
"plugin",
"assets",
"by",
"source",
"."
]
| train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/UrlHelper.php#L65-L78 |
aedart/laravel-helpers | src/Traits/Queue/QueueFactoryTrait.php | QueueFactoryTrait.getQueueFactory | public function getQueueFactory(): ?Factory
{
if (!$this->hasQueueFactory()) {
$this->setQueueFactory($this->getDefaultQueueFactory());
}
return $this->queueFactory;
} | php | public function getQueueFactory(): ?Factory
{
if (!$this->hasQueueFactory()) {
$this->setQueueFactory($this->getDefaultQueueFactory());
}
return $this->queueFactory;
} | [
"public",
"function",
"getQueueFactory",
"(",
")",
":",
"?",
"Factory",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasQueueFactory",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setQueueFactory",
"(",
"$",
"this",
"->",
"getDefaultQueueFactory",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"queueFactory",
";",
"}"
]
| Get queue factory
If no queue factory has been set, this method will
set and return a default queue factory, if any such
value is available
@see getDefaultQueueFactory()
@return Factory|null queue factory or null if none queue factory has been set | [
"Get",
"queue",
"factory"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Queue/QueueFactoryTrait.php#L53-L59 |
iocaste/microservice-foundation | src/MicroserviceServiceProvider.php | MicroserviceServiceProvider.register | public function register()
{
$this->setupConfig();
$services = config('microservice.services');
$currentEnv = app()->environment();
/** @var array $services */
foreach ($services as $service) {
if ($service['enabled'] && $this->isInCurrentEnv($currentEnv, $service['environments'])) {
if (array_get($service, 'config')) {
$this->app->configure($service['config']);
}
$this->app->register($service['provider']);
}
}
app()->middleware(ConvertEmptyStringsToNull::class);
} | php | public function register()
{
$this->setupConfig();
$services = config('microservice.services');
$currentEnv = app()->environment();
/** @var array $services */
foreach ($services as $service) {
if ($service['enabled'] && $this->isInCurrentEnv($currentEnv, $service['environments'])) {
if (array_get($service, 'config')) {
$this->app->configure($service['config']);
}
$this->app->register($service['provider']);
}
}
app()->middleware(ConvertEmptyStringsToNull::class);
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"setupConfig",
"(",
")",
";",
"$",
"services",
"=",
"config",
"(",
"'microservice.services'",
")",
";",
"$",
"currentEnv",
"=",
"app",
"(",
")",
"->",
"environment",
"(",
")",
";",
"/** @var array $services */",
"foreach",
"(",
"$",
"services",
"as",
"$",
"service",
")",
"{",
"if",
"(",
"$",
"service",
"[",
"'enabled'",
"]",
"&&",
"$",
"this",
"->",
"isInCurrentEnv",
"(",
"$",
"currentEnv",
",",
"$",
"service",
"[",
"'environments'",
"]",
")",
")",
"{",
"if",
"(",
"array_get",
"(",
"$",
"service",
",",
"'config'",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"configure",
"(",
"$",
"service",
"[",
"'config'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"$",
"service",
"[",
"'provider'",
"]",
")",
";",
"}",
"}",
"app",
"(",
")",
"->",
"middleware",
"(",
"ConvertEmptyStringsToNull",
"::",
"class",
")",
";",
"}"
]
| Register the application services. | [
"Register",
"the",
"application",
"services",
"."
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/MicroserviceServiceProvider.php#L26-L45 |
iocaste/microservice-foundation | src/MicroserviceServiceProvider.php | MicroserviceServiceProvider.isInCurrentEnv | protected function isInCurrentEnv(string $currentEnv = '*', array $envList = []): bool
{
if (in_array('*', $envList, false)) {
return true;
}
if (in_array($currentEnv, $envList, false)) {
return true;
}
return false;
} | php | protected function isInCurrentEnv(string $currentEnv = '*', array $envList = []): bool
{
if (in_array('*', $envList, false)) {
return true;
}
if (in_array($currentEnv, $envList, false)) {
return true;
}
return false;
} | [
"protected",
"function",
"isInCurrentEnv",
"(",
"string",
"$",
"currentEnv",
"=",
"'*'",
",",
"array",
"$",
"envList",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"if",
"(",
"in_array",
"(",
"'*'",
",",
"$",
"envList",
",",
"false",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"currentEnv",
",",
"$",
"envList",
",",
"false",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| @param string $currentEnv
@param array $envList
@return bool | [
"@param",
"string",
"$currentEnv",
"@param",
"array",
"$envList"
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/MicroserviceServiceProvider.php#L69-L80 |
inpsyde/inpsyde-filter | src/WordPress/SanitizeKey.php | SanitizeKey.filter | public function filter( $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not string or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
return sanitize_key( $value );
} | php | public function filter( $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not string or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
return sanitize_key( $value );
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
"||",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"do_action",
"(",
"'inpsyde.filter.error'",
",",
"'The given value is not string or empty.'",
",",
"[",
"'method'",
"=>",
"__METHOD__",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"return",
"$",
"value",
";",
"}",
"return",
"sanitize_key",
"(",
"$",
"value",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/WordPress/SanitizeKey.php#L18-L27 |
ruvents/ruwork-upload-bundle | DependencyInjection/RuworkUploadExtension.php | RuworkUploadExtension.loadInternal | public function loadInternal(array $config, ContainerBuilder $container): void
{
(new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')))
->load('services.php');
$container->setParameter('ruwork_upload.uploads_dir', $config['uploads_dir']);
$container->findDefinition(PathGenerator::class)
->setArgument('$publicDir', $config['public_dir']);
$container->registerForAutoconfiguration(SourceHandlerInterface::class)
->addTag('ruwork_upload.source_handler');
} | php | public function loadInternal(array $config, ContainerBuilder $container): void
{
(new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')))
->load('services.php');
$container->setParameter('ruwork_upload.uploads_dir', $config['uploads_dir']);
$container->findDefinition(PathGenerator::class)
->setArgument('$publicDir', $config['public_dir']);
$container->registerForAutoconfiguration(SourceHandlerInterface::class)
->addTag('ruwork_upload.source_handler');
} | [
"public",
"function",
"loadInternal",
"(",
"array",
"$",
"config",
",",
"ContainerBuilder",
"$",
"container",
")",
":",
"void",
"{",
"(",
"new",
"PhpFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
")",
"->",
"load",
"(",
"'services.php'",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'ruwork_upload.uploads_dir'",
",",
"$",
"config",
"[",
"'uploads_dir'",
"]",
")",
";",
"$",
"container",
"->",
"findDefinition",
"(",
"PathGenerator",
"::",
"class",
")",
"->",
"setArgument",
"(",
"'$publicDir'",
",",
"$",
"config",
"[",
"'public_dir'",
"]",
")",
";",
"$",
"container",
"->",
"registerForAutoconfiguration",
"(",
"SourceHandlerInterface",
"::",
"class",
")",
"->",
"addTag",
"(",
"'ruwork_upload.source_handler'",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/ruvents/ruwork-upload-bundle/blob/8ad09cc2dce6ab389105c440d791346696da43af/DependencyInjection/RuworkUploadExtension.php#L19-L31 |
ClanCats/Core | src/classes/CCIn.php | CCIn.instance | public static function instance( $set = null )
{
if ( is_null( $set ) )
{
return static::$_instance;
}
if ( !$set instanceof CCIn_Instance )
{
throw new \InvalidArgumentException('CCIn::set() - only CCIn_Instance object can be passed.');
}
static::$_instance = $set;
} | php | public static function instance( $set = null )
{
if ( is_null( $set ) )
{
return static::$_instance;
}
if ( !$set instanceof CCIn_Instance )
{
throw new \InvalidArgumentException('CCIn::set() - only CCIn_Instance object can be passed.');
}
static::$_instance = $set;
} | [
"public",
"static",
"function",
"instance",
"(",
"$",
"set",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"set",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_instance",
";",
"}",
"if",
"(",
"!",
"$",
"set",
"instanceof",
"CCIn_Instance",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'CCIn::set() - only CCIn_Instance object can be passed.'",
")",
";",
"}",
"static",
"::",
"$",
"_instance",
"=",
"$",
"set",
";",
"}"
]
| get the current input instance
@param CCIn_Instance $set if set the current instance gets updated
@return CCIn_Instance | [
"get",
"the",
"current",
"input",
"instance"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn.php#L29-L42 |
ClanCats/Core | src/classes/CCIn.php | CCIn.create | public static function create( $get, $post, $cookie, $files, $server )
{
return new CCIn_Instance( $get, $post, $cookie, $files, $server );
} | php | public static function create( $get, $post, $cookie, $files, $server )
{
return new CCIn_Instance( $get, $post, $cookie, $files, $server );
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"get",
",",
"$",
"post",
",",
"$",
"cookie",
",",
"$",
"files",
",",
"$",
"server",
")",
"{",
"return",
"new",
"CCIn_Instance",
"(",
"$",
"get",
",",
"$",
"post",
",",
"$",
"cookie",
",",
"$",
"files",
",",
"$",
"server",
")",
";",
"}"
]
| create new instance
assign the main vars GET, POST, COOKIE, FILES, SERVER here
@param array $get
@param array $post
@param array $cookie
@param array $files
@param array $server | [
"create",
"new",
"instance",
"assign",
"the",
"main",
"vars",
"GET",
"POST",
"COOKIE",
"FILES",
"SERVER",
"here"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn.php#L54-L57 |
qcubed/orm | src/Database/PostgreSql/Database.php | Database.connect | public function connect()
{
// Lookup Adapter-Specific Connection Properties
$strServer = $this->Server;
$strName = $this->Database;
$strUsername = $this->Username;
$strPassword = $this->Password;
$strPort = $this->Port;
// Connect to the Database Server
$this->objPgSql = pg_connect(sprintf('host=%s dbname=%s user=%s password=%s port=%s', $strServer, $strName,
$strUsername, $strPassword, $strPort));
if (!$this->objPgSql) {
throw new \Exception("Unable to connect to Database", -1, null);
}
// Update Connected Flag
$this->blnConnectedFlag = true;
} | php | public function connect()
{
// Lookup Adapter-Specific Connection Properties
$strServer = $this->Server;
$strName = $this->Database;
$strUsername = $this->Username;
$strPassword = $this->Password;
$strPort = $this->Port;
// Connect to the Database Server
$this->objPgSql = pg_connect(sprintf('host=%s dbname=%s user=%s password=%s port=%s', $strServer, $strName,
$strUsername, $strPassword, $strPort));
if (!$this->objPgSql) {
throw new \Exception("Unable to connect to Database", -1, null);
}
// Update Connected Flag
$this->blnConnectedFlag = true;
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"// Lookup Adapter-Specific Connection Properties",
"$",
"strServer",
"=",
"$",
"this",
"->",
"Server",
";",
"$",
"strName",
"=",
"$",
"this",
"->",
"Database",
";",
"$",
"strUsername",
"=",
"$",
"this",
"->",
"Username",
";",
"$",
"strPassword",
"=",
"$",
"this",
"->",
"Password",
";",
"$",
"strPort",
"=",
"$",
"this",
"->",
"Port",
";",
"// Connect to the Database Server",
"$",
"this",
"->",
"objPgSql",
"=",
"pg_connect",
"(",
"sprintf",
"(",
"'host=%s dbname=%s user=%s password=%s port=%s'",
",",
"$",
"strServer",
",",
"$",
"strName",
",",
"$",
"strUsername",
",",
"$",
"strPassword",
",",
"$",
"strPort",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"objPgSql",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Unable to connect to Database\"",
",",
"-",
"1",
",",
"null",
")",
";",
"}",
"// Update Connected Flag",
"$",
"this",
"->",
"blnConnectedFlag",
"=",
"true",
";",
"}"
]
| Connects to the database
@throws Exception | [
"Connects",
"to",
"the",
"database"
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Database/PostgreSql/Database.php#L248-L267 |
qcubed/orm | src/Database/PostgreSql/Database.php | Database.getTables | public function getTables()
{
$objResult = $this->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = current_schema() AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME ASC");
$strToReturn = array();
while ($strRowArray = $objResult->fetchRow()) {
array_push($strToReturn, $strRowArray[0]);
}
return $strToReturn;
} | php | public function getTables()
{
$objResult = $this->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = current_schema() AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME ASC");
$strToReturn = array();
while ($strRowArray = $objResult->fetchRow()) {
array_push($strToReturn, $strRowArray[0]);
}
return $strToReturn;
} | [
"public",
"function",
"getTables",
"(",
")",
"{",
"$",
"objResult",
"=",
"$",
"this",
"->",
"query",
"(",
"\"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = current_schema() AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME ASC\"",
")",
";",
"$",
"strToReturn",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"strRowArray",
"=",
"$",
"objResult",
"->",
"fetchRow",
"(",
")",
")",
"{",
"array_push",
"(",
"$",
"strToReturn",
",",
"$",
"strRowArray",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"strToReturn",
";",
"}"
]
| Returns the list of tables in the database as string
@return array List of tables in the database as string | [
"Returns",
"the",
"list",
"of",
"tables",
"in",
"the",
"database",
"as",
"string"
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Database/PostgreSql/Database.php#L323-L331 |
ppetermann/king23 | src/Controller/Controller.php | Controller.dispatch | public function dispatch($action, ServerRequestInterface $request) : ResponseInterface
{
$this->getLogger()->debug('dispatching to action: '.$action);
if (!method_exists($this, $action) && !method_exists($this, '__call')) {
throw new ActionDoesNotExistException();
}
$response = $this->$action($request);
return $response;
} | php | public function dispatch($action, ServerRequestInterface $request) : ResponseInterface
{
$this->getLogger()->debug('dispatching to action: '.$action);
if (!method_exists($this, $action) && !method_exists($this, '__call')) {
throw new ActionDoesNotExistException();
}
$response = $this->$action($request);
return $response;
} | [
"public",
"function",
"dispatch",
"(",
"$",
"action",
",",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"'dispatching to action: '",
".",
"$",
"action",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"action",
")",
"&&",
"!",
"method_exists",
"(",
"$",
"this",
",",
"'__call'",
")",
")",
"{",
"throw",
"new",
"ActionDoesNotExistException",
"(",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"$",
"action",
"(",
"$",
"request",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| function to dispatch requests coming through the router
@param $action
@param ServerRequestInterface $request
@return ResponseInterface
@throws ActionDoesNotExistException | [
"function",
"to",
"dispatch",
"requests",
"coming",
"through",
"the",
"router"
]
| train | https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Controller/Controller.php#L52-L61 |
Falc/FlysystemLocalSymlinkPlugin | src/DeleteSymlink.php | DeleteSymlink.handle | public function handle($symlink)
{
$symlink = $this->filesystem->getAdapter()->applyPathPrefix($symlink);
if (!is_link($symlink)) {
return false;
}
return unlink($symlink);
} | php | public function handle($symlink)
{
$symlink = $this->filesystem->getAdapter()->applyPathPrefix($symlink);
if (!is_link($symlink)) {
return false;
}
return unlink($symlink);
} | [
"public",
"function",
"handle",
"(",
"$",
"symlink",
")",
"{",
"$",
"symlink",
"=",
"$",
"this",
"->",
"filesystem",
"->",
"getAdapter",
"(",
")",
"->",
"applyPathPrefix",
"(",
"$",
"symlink",
")",
";",
"if",
"(",
"!",
"is_link",
"(",
"$",
"symlink",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"unlink",
"(",
"$",
"symlink",
")",
";",
"}"
]
| Method logic.
Deletes a symlink.
@see http://php.net/manual/en/function.unlink.php Documentation of unlink().
@param string $symlink Symlink name.
@return boolean True on success. False on failure. | [
"Method",
"logic",
"."
]
| train | https://github.com/Falc/FlysystemLocalSymlinkPlugin/blob/9301f51f172a030d07e49472d11f3e6b10a6a459/src/DeleteSymlink.php#L59-L68 |
periaptio/empress-generator | src/Generators/MigrationGenerator.php | MigrationGenerator.generateMigrationFile | public function generateMigrationFile($method, $tables)
{
if ($method == 'create') {
$function = 'getFields';
$prefix = 'create';
} elseif ($method = 'foreign_keys') {
$function = 'getForeignKeyConstraints';
$prefix = 'add_foreign_keys_to';
$method = 'table';
} else {
return;
}
$this->method = $method;
foreach ($tables as $table) {
$migrationName = $prefix . '_' . $table . '_table';
$fields = $this->schemaParser->{$function}($table);
if (empty($fields)) {
continue;
}
$filename = $this->datePrefix . '_' . $migrationName.'.php';
$templateData = $this->getTemplateData($fields, [
'CLASS' => ucwords(camel_case($migrationName)),
'TABLE' => $table,
'METHOD' => $method,
]);
$this->generateFile($filename, $templateData);
}
} | php | public function generateMigrationFile($method, $tables)
{
if ($method == 'create') {
$function = 'getFields';
$prefix = 'create';
} elseif ($method = 'foreign_keys') {
$function = 'getForeignKeyConstraints';
$prefix = 'add_foreign_keys_to';
$method = 'table';
} else {
return;
}
$this->method = $method;
foreach ($tables as $table) {
$migrationName = $prefix . '_' . $table . '_table';
$fields = $this->schemaParser->{$function}($table);
if (empty($fields)) {
continue;
}
$filename = $this->datePrefix . '_' . $migrationName.'.php';
$templateData = $this->getTemplateData($fields, [
'CLASS' => ucwords(camel_case($migrationName)),
'TABLE' => $table,
'METHOD' => $method,
]);
$this->generateFile($filename, $templateData);
}
} | [
"public",
"function",
"generateMigrationFile",
"(",
"$",
"method",
",",
"$",
"tables",
")",
"{",
"if",
"(",
"$",
"method",
"==",
"'create'",
")",
"{",
"$",
"function",
"=",
"'getFields'",
";",
"$",
"prefix",
"=",
"'create'",
";",
"}",
"elseif",
"(",
"$",
"method",
"=",
"'foreign_keys'",
")",
"{",
"$",
"function",
"=",
"'getForeignKeyConstraints'",
";",
"$",
"prefix",
"=",
"'add_foreign_keys_to'",
";",
"$",
"method",
"=",
"'table'",
";",
"}",
"else",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"method",
"=",
"$",
"method",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"migrationName",
"=",
"$",
"prefix",
".",
"'_'",
".",
"$",
"table",
".",
"'_table'",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"schemaParser",
"->",
"{",
"$",
"function",
"}",
"(",
"$",
"table",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"continue",
";",
"}",
"$",
"filename",
"=",
"$",
"this",
"->",
"datePrefix",
".",
"'_'",
".",
"$",
"migrationName",
".",
"'.php'",
";",
"$",
"templateData",
"=",
"$",
"this",
"->",
"getTemplateData",
"(",
"$",
"fields",
",",
"[",
"'CLASS'",
"=>",
"ucwords",
"(",
"camel_case",
"(",
"$",
"migrationName",
")",
")",
",",
"'TABLE'",
"=>",
"$",
"table",
",",
"'METHOD'",
"=>",
"$",
"method",
",",
"]",
")",
";",
"$",
"this",
"->",
"generateFile",
"(",
"$",
"filename",
",",
"$",
"templateData",
")",
";",
"}",
"}"
]
| Generate Migrations
@param string $method Create Tables or Foreign Keys ['create', 'foreign_keys']
@param array $tables List of tables to create migrations for
@throws MethodNotFoundException
@return void | [
"Generate",
"Migrations"
]
| train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Generators/MigrationGenerator.php#L63-L96 |
periaptio/empress-generator | src/Generators/MigrationGenerator.php | MigrationGenerator.getTemplateData | public function getTemplateData($fields, $data = [])
{
if ($data['METHOD'] == 'create') {
$up = (new AddToTable)->run($fields, $data['TABLE']);
$down = '';
} else {
$up = (new AddForeignKeysToTable)->run($fields, $data['TABLE']);
$down = (new RemoveForeignKeysFromTable)->run($fields, $data['TABLE']);
}
return array_merge($data, [
'UP' => $up,
'DOWN' => $down
]);
} | php | public function getTemplateData($fields, $data = [])
{
if ($data['METHOD'] == 'create') {
$up = (new AddToTable)->run($fields, $data['TABLE']);
$down = '';
} else {
$up = (new AddForeignKeysToTable)->run($fields, $data['TABLE']);
$down = (new RemoveForeignKeysFromTable)->run($fields, $data['TABLE']);
}
return array_merge($data, [
'UP' => $up,
'DOWN' => $down
]);
} | [
"public",
"function",
"getTemplateData",
"(",
"$",
"fields",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"'METHOD'",
"]",
"==",
"'create'",
")",
"{",
"$",
"up",
"=",
"(",
"new",
"AddToTable",
")",
"->",
"run",
"(",
"$",
"fields",
",",
"$",
"data",
"[",
"'TABLE'",
"]",
")",
";",
"$",
"down",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"up",
"=",
"(",
"new",
"AddForeignKeysToTable",
")",
"->",
"run",
"(",
"$",
"fields",
",",
"$",
"data",
"[",
"'TABLE'",
"]",
")",
";",
"$",
"down",
"=",
"(",
"new",
"RemoveForeignKeysFromTable",
")",
"->",
"run",
"(",
"$",
"fields",
",",
"$",
"data",
"[",
"'TABLE'",
"]",
")",
";",
"}",
"return",
"array_merge",
"(",
"$",
"data",
",",
"[",
"'UP'",
"=>",
"$",
"up",
",",
"'DOWN'",
"=>",
"$",
"down",
"]",
")",
";",
"}"
]
| Fetch the template data
@return array | [
"Fetch",
"the",
"template",
"data"
]
| train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Generators/MigrationGenerator.php#L103-L117 |
aedart/laravel-helpers | src/Traits/Auth/AuthTrait.php | AuthTrait.getAuth | public function getAuth(): ?Guard
{
if (!$this->hasAuth()) {
$this->setAuth($this->getDefaultAuth());
}
return $this->auth;
} | php | public function getAuth(): ?Guard
{
if (!$this->hasAuth()) {
$this->setAuth($this->getDefaultAuth());
}
return $this->auth;
} | [
"public",
"function",
"getAuth",
"(",
")",
":",
"?",
"Guard",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasAuth",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setAuth",
"(",
"$",
"this",
"->",
"getDefaultAuth",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"auth",
";",
"}"
]
| Get auth
If no auth has been set, this method will
set and return a default auth, if any such
value is available
@see getDefaultAuth()
@return Guard|null auth or null if none auth has been set | [
"Get",
"auth"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Auth/AuthTrait.php#L53-L59 |
aedart/laravel-helpers | src/Traits/Auth/AuthTrait.php | AuthTrait.getDefaultAuth | public function getDefaultAuth(): ?Guard
{
// By default, the Auth Facade does not return the
// any actual authentication guard, but rather an
// instance of \Illuminate\Auth\AuthManager.
// Therefore, we make sure only to obtain its
// "default guard", to make sure that its only the guard
// instance that we obtain.
$manager = Auth::getFacadeRoot();
if (isset($manager)) {
return $manager->guard();
}
return $manager;
} | php | public function getDefaultAuth(): ?Guard
{
// By default, the Auth Facade does not return the
// any actual authentication guard, but rather an
// instance of \Illuminate\Auth\AuthManager.
// Therefore, we make sure only to obtain its
// "default guard", to make sure that its only the guard
// instance that we obtain.
$manager = Auth::getFacadeRoot();
if (isset($manager)) {
return $manager->guard();
}
return $manager;
} | [
"public",
"function",
"getDefaultAuth",
"(",
")",
":",
"?",
"Guard",
"{",
"// By default, the Auth Facade does not return the",
"// any actual authentication guard, but rather an",
"// instance of \\Illuminate\\Auth\\AuthManager.",
"// Therefore, we make sure only to obtain its",
"// \"default guard\", to make sure that its only the guard",
"// instance that we obtain.",
"$",
"manager",
"=",
"Auth",
"::",
"getFacadeRoot",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"manager",
")",
")",
"{",
"return",
"$",
"manager",
"->",
"guard",
"(",
")",
";",
"}",
"return",
"$",
"manager",
";",
"}"
]
| Get a default auth value, if any is available
@return Guard|null A default auth value or Null if no default value is available | [
"Get",
"a",
"default",
"auth",
"value",
"if",
"any",
"is",
"available"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Auth/AuthTrait.php#L76-L89 |
krzysztofmazur/ntp-client | src/Impl/UdpNtpClient.php | UdpNtpClient.getUnixTime | public function getUnixTime(): int
{
$socket = $this->connect();
$this->sendInitPackage($socket);
$response = $this->readResponse($socket, 48);
$this->close($socket);
return $this->extractTime($response) - self::SINCE_1900_TO_UNIX;
} | php | public function getUnixTime(): int
{
$socket = $this->connect();
$this->sendInitPackage($socket);
$response = $this->readResponse($socket, 48);
$this->close($socket);
return $this->extractTime($response) - self::SINCE_1900_TO_UNIX;
} | [
"public",
"function",
"getUnixTime",
"(",
")",
":",
"int",
"{",
"$",
"socket",
"=",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"$",
"this",
"->",
"sendInitPackage",
"(",
"$",
"socket",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"readResponse",
"(",
"$",
"socket",
",",
"48",
")",
";",
"$",
"this",
"->",
"close",
"(",
"$",
"socket",
")",
";",
"return",
"$",
"this",
"->",
"extractTime",
"(",
"$",
"response",
")",
"-",
"self",
"::",
"SINCE_1900_TO_UNIX",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/krzysztofmazur/ntp-client/blob/3e15ce8ee26d6e2e57a8bdbdf67273762e3fbfd2/src/Impl/UdpNtpClient.php#L31-L39 |
askupasoftware/amarkal | Template/Controller.php | Controller.render | public function render( $echo = false ){
$rendered_image = '';
if( file_exists( $this->get_script_path() ) )
{
ob_start();
include( $this->get_script_path() );
$rendered_image = ob_get_clean();
}
else
{
throw new TemplateNotFoundException( "Error: cannot render HTML, template file not found at " . $this->get_script_path() );
}
if( !$echo )
{
return $rendered_image;
}
echo $rendered_image;
} | php | public function render( $echo = false ){
$rendered_image = '';
if( file_exists( $this->get_script_path() ) )
{
ob_start();
include( $this->get_script_path() );
$rendered_image = ob_get_clean();
}
else
{
throw new TemplateNotFoundException( "Error: cannot render HTML, template file not found at " . $this->get_script_path() );
}
if( !$echo )
{
return $rendered_image;
}
echo $rendered_image;
} | [
"public",
"function",
"render",
"(",
"$",
"echo",
"=",
"false",
")",
"{",
"$",
"rendered_image",
"=",
"''",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"get_script_path",
"(",
")",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"include",
"(",
"$",
"this",
"->",
"get_script_path",
"(",
")",
")",
";",
"$",
"rendered_image",
"=",
"ob_get_clean",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"TemplateNotFoundException",
"(",
"\"Error: cannot render HTML, template file not found at \"",
".",
"$",
"this",
"->",
"get_script_path",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"echo",
")",
"{",
"return",
"$",
"rendered_image",
";",
"}",
"echo",
"$",
"rendered_image",
";",
"}"
]
| Render the template with the local properties.
@return string The rendered template.
@throws TemplateNotFoundException Thrown if the template file can
not found. | [
"Render",
"the",
"template",
"with",
"the",
"local",
"properties",
"."
]
| train | https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Template/Controller.php#L60-L80 |
askupasoftware/amarkal | Template/Controller.php | Controller.get_script_path | protected function get_script_path()
{
if( null == $this->script_path )
{
$class_name = substr( get_called_class() , strrpos( get_called_class(), '\\') + 1);
$this->script_path = $this->get_dir() . '/' . $class_name . '.phtml';
}
return $this->script_path;
} | php | protected function get_script_path()
{
if( null == $this->script_path )
{
$class_name = substr( get_called_class() , strrpos( get_called_class(), '\\') + 1);
$this->script_path = $this->get_dir() . '/' . $class_name . '.phtml';
}
return $this->script_path;
} | [
"protected",
"function",
"get_script_path",
"(",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"this",
"->",
"script_path",
")",
"{",
"$",
"class_name",
"=",
"substr",
"(",
"get_called_class",
"(",
")",
",",
"strrpos",
"(",
"get_called_class",
"(",
")",
",",
"'\\\\'",
")",
"+",
"1",
")",
";",
"$",
"this",
"->",
"script_path",
"=",
"$",
"this",
"->",
"get_dir",
"(",
")",
".",
"'/'",
".",
"$",
"class_name",
".",
"'.phtml'",
";",
"}",
"return",
"$",
"this",
"->",
"script_path",
";",
"}"
]
| Get the full path to the template file.
@return string The full path. | [
"Get",
"the",
"full",
"path",
"to",
"the",
"template",
"file",
"."
]
| train | https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Template/Controller.php#L87-L95 |
steeffeen/FancyManiaLinks | FML/Components/ValuePicker.php | ValuePicker.createEntry | protected function createEntry()
{
$entry = new Entry();
$entry->setVisible(false)
->setName($this->name);
$this->setEntry($entry);
return $entry;
} | php | protected function createEntry()
{
$entry = new Entry();
$entry->setVisible(false)
->setName($this->name);
$this->setEntry($entry);
return $entry;
} | [
"protected",
"function",
"createEntry",
"(",
")",
"{",
"$",
"entry",
"=",
"new",
"Entry",
"(",
")",
";",
"$",
"entry",
"->",
"setVisible",
"(",
"false",
")",
"->",
"setName",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"this",
"->",
"setEntry",
"(",
"$",
"entry",
")",
";",
"return",
"$",
"entry",
";",
"}"
]
| Create the hidden Entry
@return Entry | [
"Create",
"the",
"hidden",
"Entry"
]
| train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Components/ValuePicker.php#L202-L209 |
aedart/laravel-helpers | src/Traits/Session/SessionTrait.php | SessionTrait.getSession | public function getSession(): ?Session
{
if (!$this->hasSession()) {
$this->setSession($this->getDefaultSession());
}
return $this->session;
} | php | public function getSession(): ?Session
{
if (!$this->hasSession()) {
$this->setSession($this->getDefaultSession());
}
return $this->session;
} | [
"public",
"function",
"getSession",
"(",
")",
":",
"?",
"Session",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasSession",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setSession",
"(",
"$",
"this",
"->",
"getDefaultSession",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"session",
";",
"}"
]
| Get session
If no session has been set, this method will
set and return a default session, if any such
value is available
@see getDefaultSession()
@return Session|null session or null if none session has been set | [
"Get",
"session"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Session/SessionTrait.php#L53-L59 |
aedart/laravel-helpers | src/Traits/Session/SessionTrait.php | SessionTrait.getDefaultSession | public function getDefaultSession(): ?Session
{
// By default, the Session Facade does not return the
// any actual session instance, but rather an
// instance of \Illuminate\Session\SessionManager.
// Therefore, we make sure only to obtain its
// "driver", to make sure that its only the connection
// instance that we obtain.
$manager = SessionFacade::getFacadeRoot();
if (isset($manager)) {
return $manager->driver();
}
return $manager;
} | php | public function getDefaultSession(): ?Session
{
// By default, the Session Facade does not return the
// any actual session instance, but rather an
// instance of \Illuminate\Session\SessionManager.
// Therefore, we make sure only to obtain its
// "driver", to make sure that its only the connection
// instance that we obtain.
$manager = SessionFacade::getFacadeRoot();
if (isset($manager)) {
return $manager->driver();
}
return $manager;
} | [
"public",
"function",
"getDefaultSession",
"(",
")",
":",
"?",
"Session",
"{",
"// By default, the Session Facade does not return the",
"// any actual session instance, but rather an",
"// instance of \\Illuminate\\Session\\SessionManager.",
"// Therefore, we make sure only to obtain its",
"// \"driver\", to make sure that its only the connection",
"// instance that we obtain.",
"$",
"manager",
"=",
"SessionFacade",
"::",
"getFacadeRoot",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"manager",
")",
")",
"{",
"return",
"$",
"manager",
"->",
"driver",
"(",
")",
";",
"}",
"return",
"$",
"manager",
";",
"}"
]
| Get a default session value, if any is available
@return Session|null A default session value or Null if no default value is available | [
"Get",
"a",
"default",
"session",
"value",
"if",
"any",
"is",
"available"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Session/SessionTrait.php#L76-L89 |
simple-php-mvc/simple-php-mvc | src/MVC/Provider/Provider.php | Provider.getOption | final public function getOption($name)
{
if (!isset($this->options[$name])) {
throw new \LogicException(sprintf('The option "%s" don\'t exists.', $name));
}
return $this->options[$name];
} | php | final public function getOption($name)
{
if (!isset($this->options[$name])) {
throw new \LogicException(sprintf('The option "%s" don\'t exists.', $name));
}
return $this->options[$name];
} | [
"final",
"public",
"function",
"getOption",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'The option \"%s\" don\\'t exists.'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"name",
"]",
";",
"}"
]
| Get option value from name
@param string $name
@return mixed
@throws \LogicException | [
"Get",
"option",
"value",
"from",
"name"
]
| train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Provider/Provider.php#L61-L67 |
webforge-labs/psc-cms | lib/Psc/HTML/HTML.php | HTML.string2class | public static function string2class($stringValue) {
// dirty hack: Psc\Code\Code::camelCase2dash benutzt dies hier: also aufpassen, bei großen Änderungen refactorn
$stringValue = trim($stringValue);
if ($stringValue === '') {
return $stringValue;
}
if (Preg::match($stringValue, '/^[A-Z0-9]+$/')) {
return mb_strtolower($stringValue);
}
$specials = preg_quote(implode("", array('.','@','\\',' ','[',']','(',')')), '/');
$stringValue = Preg::replace(// in
$stringValue,
// what
sprintf('/%s|[%s]/',
"(?<=\w)([A-Z]|[0-9])",
$specials
),
// with
'-\\1'
);
$stringValue = mb_strtolower($stringValue);
return $stringValue;
} | php | public static function string2class($stringValue) {
// dirty hack: Psc\Code\Code::camelCase2dash benutzt dies hier: also aufpassen, bei großen Änderungen refactorn
$stringValue = trim($stringValue);
if ($stringValue === '') {
return $stringValue;
}
if (Preg::match($stringValue, '/^[A-Z0-9]+$/')) {
return mb_strtolower($stringValue);
}
$specials = preg_quote(implode("", array('.','@','\\',' ','[',']','(',')')), '/');
$stringValue = Preg::replace(// in
$stringValue,
// what
sprintf('/%s|[%s]/',
"(?<=\w)([A-Z]|[0-9])",
$specials
),
// with
'-\\1'
);
$stringValue = mb_strtolower($stringValue);
return $stringValue;
} | [
"public",
"static",
"function",
"string2class",
"(",
"$",
"stringValue",
")",
"{",
"// dirty hack: Psc\\Code\\Code::camelCase2dash benutzt dies hier: also aufpassen, bei großen Änderungen refactorn",
"$",
"stringValue",
"=",
"trim",
"(",
"$",
"stringValue",
")",
";",
"if",
"(",
"$",
"stringValue",
"===",
"''",
")",
"{",
"return",
"$",
"stringValue",
";",
"}",
"if",
"(",
"Preg",
"::",
"match",
"(",
"$",
"stringValue",
",",
"'/^[A-Z0-9]+$/'",
")",
")",
"{",
"return",
"mb_strtolower",
"(",
"$",
"stringValue",
")",
";",
"}",
"$",
"specials",
"=",
"preg_quote",
"(",
"implode",
"(",
"\"\"",
",",
"array",
"(",
"'.'",
",",
"'@'",
",",
"'\\\\'",
",",
"' '",
",",
"'['",
",",
"']'",
",",
"'('",
",",
"')'",
")",
")",
",",
"'/'",
")",
";",
"$",
"stringValue",
"=",
"Preg",
"::",
"replace",
"(",
"// in",
"$",
"stringValue",
",",
"// what",
"sprintf",
"(",
"'/%s|[%s]/'",
",",
"\"(?<=\\w)([A-Z]|[0-9])\"",
",",
"$",
"specials",
")",
",",
"// with",
"'-\\\\1'",
")",
";",
"$",
"stringValue",
"=",
"mb_strtolower",
"(",
"$",
"stringValue",
")",
";",
"return",
"$",
"stringValue",
";",
"}"
]
| Erstells aus einem CamelCase Namen oder einer Klasse oder einem String eine html-klasse | [
"Erstells",
"aus",
"einem",
"CamelCase",
"Namen",
"oder",
"einer",
"Klasse",
"oder",
"einem",
"String",
"eine",
"html",
"-",
"klasse"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/HTML/HTML.php#L37-L64 |
ray-di/Ray.ValidateModule | docs/demo/1.on_failure.php | Fake1.onInvalidOnPost | public function onInvalidOnPost(FailureInterface $failure)
{
$msg = $failure->getMessages();
$args = (array) $failure->getInvocation()->getArguments();
return [$msg, $args];
} | php | public function onInvalidOnPost(FailureInterface $failure)
{
$msg = $failure->getMessages();
$args = (array) $failure->getInvocation()->getArguments();
return [$msg, $args];
} | [
"public",
"function",
"onInvalidOnPost",
"(",
"FailureInterface",
"$",
"failure",
")",
"{",
"$",
"msg",
"=",
"$",
"failure",
"->",
"getMessages",
"(",
")",
";",
"$",
"args",
"=",
"(",
"array",
")",
"$",
"failure",
"->",
"getInvocation",
"(",
")",
"->",
"getArguments",
"(",
")",
";",
"return",
"[",
"$",
"msg",
",",
"$",
"args",
"]",
";",
"}"
]
| @param FailureInterface $failure
@OnFailure | [
"@param",
"FailureInterface",
"$failure"
]
| train | https://github.com/ray-di/Ray.ValidateModule/blob/7e4e3c4a05e11dc989d689202ac6ae625695588e/docs/demo/1.on_failure.php#L51-L57 |
kherge-abandoned/php-wise | src/lib/Herrera/Wise/Loader/LoaderResolver.php | LoaderResolver.setResourceCollector | public function setResourceCollector(ResourceCollectorInterface $collector)
{
$this->collector = $collector;
foreach ($this->getLoaders() as $loader) {
if ($loader instanceof ResourceAwareInterface) {
$loader->setResourceCollector($collector);
}
}
} | php | public function setResourceCollector(ResourceCollectorInterface $collector)
{
$this->collector = $collector;
foreach ($this->getLoaders() as $loader) {
if ($loader instanceof ResourceAwareInterface) {
$loader->setResourceCollector($collector);
}
}
} | [
"public",
"function",
"setResourceCollector",
"(",
"ResourceCollectorInterface",
"$",
"collector",
")",
"{",
"$",
"this",
"->",
"collector",
"=",
"$",
"collector",
";",
"foreach",
"(",
"$",
"this",
"->",
"getLoaders",
"(",
")",
"as",
"$",
"loader",
")",
"{",
"if",
"(",
"$",
"loader",
"instanceof",
"ResourceAwareInterface",
")",
"{",
"$",
"loader",
"->",
"setResourceCollector",
"(",
"$",
"collector",
")",
";",
"}",
"}",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/kherge-abandoned/php-wise/blob/7621e0be7dbb2a015d68197d290fe8469f539a4d/src/lib/Herrera/Wise/Loader/LoaderResolver.php#L70-L79 |
kherge-abandoned/php-wise | src/lib/Herrera/Wise/Loader/LoaderResolver.php | LoaderResolver.setWise | public function setWise(Wise $wise)
{
$this->wise = $wise;
foreach ($this->getLoaders() as $loader) {
if ($loader instanceof WiseAwareInterface) {
$loader->setWise($wise);
}
}
} | php | public function setWise(Wise $wise)
{
$this->wise = $wise;
foreach ($this->getLoaders() as $loader) {
if ($loader instanceof WiseAwareInterface) {
$loader->setWise($wise);
}
}
} | [
"public",
"function",
"setWise",
"(",
"Wise",
"$",
"wise",
")",
"{",
"$",
"this",
"->",
"wise",
"=",
"$",
"wise",
";",
"foreach",
"(",
"$",
"this",
"->",
"getLoaders",
"(",
")",
"as",
"$",
"loader",
")",
"{",
"if",
"(",
"$",
"loader",
"instanceof",
"WiseAwareInterface",
")",
"{",
"$",
"loader",
"->",
"setWise",
"(",
"$",
"wise",
")",
";",
"}",
"}",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/kherge-abandoned/php-wise/blob/7621e0be7dbb2a015d68197d290fe8469f539a4d/src/lib/Herrera/Wise/Loader/LoaderResolver.php#L84-L93 |
ClanCats/Core | src/bundles/Mail/Transporter/File.php | Transporter_File.send | public function send( CCMail $mail )
{
$data = $mail->export_data();
$filename = 'mails/'.date( 'Y-m' ).'/'.date( 'd' ).'/'.date("H-i-s").'-'.\CCStr::clean_url( $data['subject'] ).'.log';
\CCFile::append( \CCStorage::path( $filename ), \CCJson::encode( $data, true ) );
} | php | public function send( CCMail $mail )
{
$data = $mail->export_data();
$filename = 'mails/'.date( 'Y-m' ).'/'.date( 'd' ).'/'.date("H-i-s").'-'.\CCStr::clean_url( $data['subject'] ).'.log';
\CCFile::append( \CCStorage::path( $filename ), \CCJson::encode( $data, true ) );
} | [
"public",
"function",
"send",
"(",
"CCMail",
"$",
"mail",
")",
"{",
"$",
"data",
"=",
"$",
"mail",
"->",
"export_data",
"(",
")",
";",
"$",
"filename",
"=",
"'mails/'",
".",
"date",
"(",
"'Y-m'",
")",
".",
"'/'",
".",
"date",
"(",
"'d'",
")",
".",
"'/'",
".",
"date",
"(",
"\"H-i-s\"",
")",
".",
"'-'",
".",
"\\",
"CCStr",
"::",
"clean_url",
"(",
"$",
"data",
"[",
"'subject'",
"]",
")",
".",
"'.log'",
";",
"\\",
"CCFile",
"::",
"append",
"(",
"\\",
"CCStorage",
"::",
"path",
"(",
"$",
"filename",
")",
",",
"\\",
"CCJson",
"::",
"encode",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"}"
]
| Send the mail
@param CCMail $mail The mail object.
@return void
@throws Mail\Exception | [
"Send",
"the",
"mail"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/Transporter/File.php#L25-L32 |
netgen/ngopengraph | classes/ngopengraphimage.php | ngOpenGraphImage.getData | public function getData()
{
if ( $this->ContentObjectAttribute->hasContent() )
{
$imageAliasHandler = $this->ContentObjectAttribute->attribute( 'content' );
$imageAlias = $imageAliasHandler->imageAlias( 'opengraph' );
if ( $imageAlias['is_valid'] == 1 )
{
return eZSys::serverURL() . '/' . $imageAlias['full_path'];
}
}
return eZSys::serverURL() . eZURLOperator::eZImage( null, 'opengraph_default_image.png', '' );
} | php | public function getData()
{
if ( $this->ContentObjectAttribute->hasContent() )
{
$imageAliasHandler = $this->ContentObjectAttribute->attribute( 'content' );
$imageAlias = $imageAliasHandler->imageAlias( 'opengraph' );
if ( $imageAlias['is_valid'] == 1 )
{
return eZSys::serverURL() . '/' . $imageAlias['full_path'];
}
}
return eZSys::serverURL() . eZURLOperator::eZImage( null, 'opengraph_default_image.png', '' );
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ContentObjectAttribute",
"->",
"hasContent",
"(",
")",
")",
"{",
"$",
"imageAliasHandler",
"=",
"$",
"this",
"->",
"ContentObjectAttribute",
"->",
"attribute",
"(",
"'content'",
")",
";",
"$",
"imageAlias",
"=",
"$",
"imageAliasHandler",
"->",
"imageAlias",
"(",
"'opengraph'",
")",
";",
"if",
"(",
"$",
"imageAlias",
"[",
"'is_valid'",
"]",
"==",
"1",
")",
"{",
"return",
"eZSys",
"::",
"serverURL",
"(",
")",
".",
"'/'",
".",
"$",
"imageAlias",
"[",
"'full_path'",
"]",
";",
"}",
"}",
"return",
"eZSys",
"::",
"serverURL",
"(",
")",
".",
"eZURLOperator",
"::",
"eZImage",
"(",
"null",
",",
"'opengraph_default_image.png'",
",",
"''",
")",
";",
"}"
]
| Returns data for the attribute
@return string | [
"Returns",
"data",
"for",
"the",
"attribute"
]
| train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/classes/ngopengraphimage.php#L10-L24 |
digitalkaoz/versioneye-php | src/Api/BaseApi.php | BaseApi.request | protected function request($url, $method = 'GET', array $params = [])
{
$url = $this->sanitizeQuery($url);
$response = $this->client->request($method, $url, $params);
if (is_array($response) && isset($response['paging'])) {
$response = $this->injectPager($response, $method, $url, $params);
}
return $response;
} | php | protected function request($url, $method = 'GET', array $params = [])
{
$url = $this->sanitizeQuery($url);
$response = $this->client->request($method, $url, $params);
if (is_array($response) && isset($response['paging'])) {
$response = $this->injectPager($response, $method, $url, $params);
}
return $response;
} | [
"protected",
"function",
"request",
"(",
"$",
"url",
",",
"$",
"method",
"=",
"'GET'",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"sanitizeQuery",
"(",
"$",
"url",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"response",
")",
"&&",
"isset",
"(",
"$",
"response",
"[",
"'paging'",
"]",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"injectPager",
"(",
"$",
"response",
",",
"$",
"method",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| performs the request.
@param string $url
@param string $method
@param array $params
@return array | [
"performs",
"the",
"request",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/BaseApi.php#L37-L48 |
digitalkaoz/versioneye-php | src/Api/BaseApi.php | BaseApi.sanitizeQuery | private function sanitizeQuery($query)
{
$parts = parse_url($query);
$path = $parts['path'];
if (!isset($parts['query'])) {
return $query;
}
$vars = explode('&', $parts['query']);
$final = [];
if (!empty($vars)) {
foreach ($vars as $var) {
$parts = explode('=', $var);
$key = $parts[0];
$val = $parts[1];
if (!array_key_exists($key, $final) && !empty($val)) {
$final[$key] = $val;
}
}
}
return $path . '?' . http_build_query($final);
} | php | private function sanitizeQuery($query)
{
$parts = parse_url($query);
$path = $parts['path'];
if (!isset($parts['query'])) {
return $query;
}
$vars = explode('&', $parts['query']);
$final = [];
if (!empty($vars)) {
foreach ($vars as $var) {
$parts = explode('=', $var);
$key = $parts[0];
$val = $parts[1];
if (!array_key_exists($key, $final) && !empty($val)) {
$final[$key] = $val;
}
}
}
return $path . '?' . http_build_query($final);
} | [
"private",
"function",
"sanitizeQuery",
"(",
"$",
"query",
")",
"{",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"query",
")",
";",
"$",
"path",
"=",
"$",
"parts",
"[",
"'path'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
")",
"{",
"return",
"$",
"query",
";",
"}",
"$",
"vars",
"=",
"explode",
"(",
"'&'",
",",
"$",
"parts",
"[",
"'query'",
"]",
")",
";",
"$",
"final",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"vars",
")",
")",
"{",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"var",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'='",
",",
"$",
"var",
")",
";",
"$",
"key",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"val",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"final",
")",
"&&",
"!",
"empty",
"(",
"$",
"val",
")",
")",
"{",
"$",
"final",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"}",
"return",
"$",
"path",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"final",
")",
";",
"}"
]
| removes empty query string parameters.
@param string $query
@return string | [
"removes",
"empty",
"query",
"string",
"parameters",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/BaseApi.php#L69-L96 |
digitalkaoz/versioneye-php | src/Api/BaseApi.php | BaseApi.injectPager | private function injectPager(array $response, $method, $url, array $params = [])
{
while (next($response)) {
if ('paging' === key($response)) {
prev($response);
break;
}
}
$pageableKey = key($response);
$response[$pageableKey] = new Pager($response, $pageableKey, $this->client, $method, $url, $params);
reset($response);
return $response;
} | php | private function injectPager(array $response, $method, $url, array $params = [])
{
while (next($response)) {
if ('paging' === key($response)) {
prev($response);
break;
}
}
$pageableKey = key($response);
$response[$pageableKey] = new Pager($response, $pageableKey, $this->client, $method, $url, $params);
reset($response);
return $response;
} | [
"private",
"function",
"injectPager",
"(",
"array",
"$",
"response",
",",
"$",
"method",
",",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"while",
"(",
"next",
"(",
"$",
"response",
")",
")",
"{",
"if",
"(",
"'paging'",
"===",
"key",
"(",
"$",
"response",
")",
")",
"{",
"prev",
"(",
"$",
"response",
")",
";",
"break",
";",
"}",
"}",
"$",
"pageableKey",
"=",
"key",
"(",
"$",
"response",
")",
";",
"$",
"response",
"[",
"$",
"pageableKey",
"]",
"=",
"new",
"Pager",
"(",
"$",
"response",
",",
"$",
"pageableKey",
",",
"$",
"this",
"->",
"client",
",",
"$",
"method",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"reset",
"(",
"$",
"response",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| converts the pageable data into a real pager.
@param array $response
@param string $method
@param string $url
@param array $params
@return array | [
"converts",
"the",
"pageable",
"data",
"into",
"a",
"real",
"pager",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Api/BaseApi.php#L108-L124 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.addProvider | public function addProvider($provider)
{
if (!in_array($provider, $this->getServiceProviders())) {
$quote = $this->getQuoteType('providers');
$separator = $this->getArrayItemsSeparator('providers');
$anchor = $this->getInsertPoint('providers');
$insert = $separator . $quote . $provider . $quote . ',';
$this->write($insert, $anchor);
}
} | php | public function addProvider($provider)
{
if (!in_array($provider, $this->getServiceProviders())) {
$quote = $this->getQuoteType('providers');
$separator = $this->getArrayItemsSeparator('providers');
$anchor = $this->getInsertPoint('providers');
$insert = $separator . $quote . $provider . $quote . ',';
$this->write($insert, $anchor);
}
} | [
"public",
"function",
"addProvider",
"(",
"$",
"provider",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"provider",
",",
"$",
"this",
"->",
"getServiceProviders",
"(",
")",
")",
")",
"{",
"$",
"quote",
"=",
"$",
"this",
"->",
"getQuoteType",
"(",
"'providers'",
")",
";",
"$",
"separator",
"=",
"$",
"this",
"->",
"getArrayItemsSeparator",
"(",
"'providers'",
")",
";",
"$",
"anchor",
"=",
"$",
"this",
"->",
"getInsertPoint",
"(",
"'providers'",
")",
";",
"$",
"insert",
"=",
"$",
"separator",
".",
"$",
"quote",
".",
"$",
"provider",
".",
"$",
"quote",
".",
"','",
";",
"$",
"this",
"->",
"write",
"(",
"$",
"insert",
",",
"$",
"anchor",
")",
";",
"}",
"}"
]
| Add specified provider.
@param $provider | [
"Add",
"specified",
"provider",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L110-L121 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.getQuoteType | protected function getQuoteType($item)
{
$bounds = $this->getConfigItemBounds($item);
if (!$bounds[0] or !$bounds[1]) {
return $this->defaultQuoteType;
}
$file = $this->getFileContents();
$substr = substr($file, $bounds[0], $bounds[1] - $bounds[0] + 1);
return substr_count($substr, '"') > substr_count($substr, "'") ? '"' : "'";
} | php | protected function getQuoteType($item)
{
$bounds = $this->getConfigItemBounds($item);
if (!$bounds[0] or !$bounds[1]) {
return $this->defaultQuoteType;
}
$file = $this->getFileContents();
$substr = substr($file, $bounds[0], $bounds[1] - $bounds[0] + 1);
return substr_count($substr, '"') > substr_count($substr, "'") ? '"' : "'";
} | [
"protected",
"function",
"getQuoteType",
"(",
"$",
"item",
")",
"{",
"$",
"bounds",
"=",
"$",
"this",
"->",
"getConfigItemBounds",
"(",
"$",
"item",
")",
";",
"if",
"(",
"!",
"$",
"bounds",
"[",
"0",
"]",
"or",
"!",
"$",
"bounds",
"[",
"1",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"defaultQuoteType",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileContents",
"(",
")",
";",
"$",
"substr",
"=",
"substr",
"(",
"$",
"file",
",",
"$",
"bounds",
"[",
"0",
"]",
",",
"$",
"bounds",
"[",
"1",
"]",
"-",
"$",
"bounds",
"[",
"0",
"]",
"+",
"1",
")",
";",
"return",
"substr_count",
"(",
"$",
"substr",
",",
"'\"'",
")",
">",
"substr_count",
"(",
"$",
"substr",
",",
"\"'\"",
")",
"?",
"'\"'",
":",
"\"'\"",
";",
"}"
]
| Detect quote type used in selected config item (providers, aliases).
@param $item
@return string | [
"Detect",
"quote",
"type",
"used",
"in",
"selected",
"config",
"item",
"(",
"providers",
"aliases",
")",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L130-L141 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.getConfigItemBounds | protected function getConfigItemBounds($item)
{
$file = $this->getFileContents();
if (!$file) {
return [null, null];
}
$searchStart = '/[\'"]' . $item . '[\'"]/';
preg_match($searchStart, $file, $matchStart, PREG_OFFSET_CAPTURE);
$start = array_get(reset($matchStart), 1);
$end = $start + 1;
// search for array closing that is not commented
$match = [')', ']'];
for ($i = $start; $i <= strlen($file); ++$i) {
$char = $file[$i];
if (in_array($char, $match)) {
if (!$this->isCharInComment($file, $i)) {
$end = $i;
break;
}
}
}
return [$start, $end];
} | php | protected function getConfigItemBounds($item)
{
$file = $this->getFileContents();
if (!$file) {
return [null, null];
}
$searchStart = '/[\'"]' . $item . '[\'"]/';
preg_match($searchStart, $file, $matchStart, PREG_OFFSET_CAPTURE);
$start = array_get(reset($matchStart), 1);
$end = $start + 1;
// search for array closing that is not commented
$match = [')', ']'];
for ($i = $start; $i <= strlen($file); ++$i) {
$char = $file[$i];
if (in_array($char, $match)) {
if (!$this->isCharInComment($file, $i)) {
$end = $i;
break;
}
}
}
return [$start, $end];
} | [
"protected",
"function",
"getConfigItemBounds",
"(",
"$",
"item",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileContents",
"(",
")",
";",
"if",
"(",
"!",
"$",
"file",
")",
"{",
"return",
"[",
"null",
",",
"null",
"]",
";",
"}",
"$",
"searchStart",
"=",
"'/[\\'\"]'",
".",
"$",
"item",
".",
"'[\\'\"]/'",
";",
"preg_match",
"(",
"$",
"searchStart",
",",
"$",
"file",
",",
"$",
"matchStart",
",",
"PREG_OFFSET_CAPTURE",
")",
";",
"$",
"start",
"=",
"array_get",
"(",
"reset",
"(",
"$",
"matchStart",
")",
",",
"1",
")",
";",
"$",
"end",
"=",
"$",
"start",
"+",
"1",
";",
"// search for array closing that is not commented",
"$",
"match",
"=",
"[",
"')'",
",",
"']'",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"start",
";",
"$",
"i",
"<=",
"strlen",
"(",
"$",
"file",
")",
";",
"++",
"$",
"i",
")",
"{",
"$",
"char",
"=",
"$",
"file",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"char",
",",
"$",
"match",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCharInComment",
"(",
"$",
"file",
",",
"$",
"i",
")",
")",
"{",
"$",
"end",
"=",
"$",
"i",
";",
"break",
";",
"}",
"}",
"}",
"return",
"[",
"$",
"start",
",",
"$",
"end",
"]",
";",
"}"
]
| Get bite bounds of selected config item (providers, aliases) in file.
@param $item
@return array | [
"Get",
"bite",
"bounds",
"of",
"selected",
"config",
"item",
"(",
"providers",
"aliases",
")",
"in",
"file",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L150-L176 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.getArrayItemsSeparator | protected function getArrayItemsSeparator($item)
{
$cfg = $this->file->getRequire($this->configFile);
if (!$cfg) {
return $this->defaultSeparator;
}
$file = $this->getFileContents();
$arr = array_get($cfg, $item);
$lastItem = end($arr);
$preLastItem = prev($arr);
if (!$lastItem or !$preLastItem) {
return $this->defaultSeparator;
}
preg_match('/\,/', $file, $matchStart, PREG_OFFSET_CAPTURE, strpos($file, $preLastItem));
$start = array_get(reset($matchStart), 1);
$searchEnd = preg_match('/[\'"]/', $file, $matchEnd, PREG_OFFSET_CAPTURE, $start);
$end = array_get(reset($matchEnd), 1);
$separator = substr($file, $start, $end - $start);
// remove comments
$separator = preg_replace('/\/\/.*/ui', '', $separator);
$separator = preg_replace('/#.*/ui', '', $separator);
$separator = preg_replace('/\/\*(.*)\*\//ui', '', $separator);
return $separator;
} | php | protected function getArrayItemsSeparator($item)
{
$cfg = $this->file->getRequire($this->configFile);
if (!$cfg) {
return $this->defaultSeparator;
}
$file = $this->getFileContents();
$arr = array_get($cfg, $item);
$lastItem = end($arr);
$preLastItem = prev($arr);
if (!$lastItem or !$preLastItem) {
return $this->defaultSeparator;
}
preg_match('/\,/', $file, $matchStart, PREG_OFFSET_CAPTURE, strpos($file, $preLastItem));
$start = array_get(reset($matchStart), 1);
$searchEnd = preg_match('/[\'"]/', $file, $matchEnd, PREG_OFFSET_CAPTURE, $start);
$end = array_get(reset($matchEnd), 1);
$separator = substr($file, $start, $end - $start);
// remove comments
$separator = preg_replace('/\/\/.*/ui', '', $separator);
$separator = preg_replace('/#.*/ui', '', $separator);
$separator = preg_replace('/\/\*(.*)\*\//ui', '', $separator);
return $separator;
} | [
"protected",
"function",
"getArrayItemsSeparator",
"(",
"$",
"item",
")",
"{",
"$",
"cfg",
"=",
"$",
"this",
"->",
"file",
"->",
"getRequire",
"(",
"$",
"this",
"->",
"configFile",
")",
";",
"if",
"(",
"!",
"$",
"cfg",
")",
"{",
"return",
"$",
"this",
"->",
"defaultSeparator",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileContents",
"(",
")",
";",
"$",
"arr",
"=",
"array_get",
"(",
"$",
"cfg",
",",
"$",
"item",
")",
";",
"$",
"lastItem",
"=",
"end",
"(",
"$",
"arr",
")",
";",
"$",
"preLastItem",
"=",
"prev",
"(",
"$",
"arr",
")",
";",
"if",
"(",
"!",
"$",
"lastItem",
"or",
"!",
"$",
"preLastItem",
")",
"{",
"return",
"$",
"this",
"->",
"defaultSeparator",
";",
"}",
"preg_match",
"(",
"'/\\,/'",
",",
"$",
"file",
",",
"$",
"matchStart",
",",
"PREG_OFFSET_CAPTURE",
",",
"strpos",
"(",
"$",
"file",
",",
"$",
"preLastItem",
")",
")",
";",
"$",
"start",
"=",
"array_get",
"(",
"reset",
"(",
"$",
"matchStart",
")",
",",
"1",
")",
";",
"$",
"searchEnd",
"=",
"preg_match",
"(",
"'/[\\'\"]/'",
",",
"$",
"file",
",",
"$",
"matchEnd",
",",
"PREG_OFFSET_CAPTURE",
",",
"$",
"start",
")",
";",
"$",
"end",
"=",
"array_get",
"(",
"reset",
"(",
"$",
"matchEnd",
")",
",",
"1",
")",
";",
"$",
"separator",
"=",
"substr",
"(",
"$",
"file",
",",
"$",
"start",
",",
"$",
"end",
"-",
"$",
"start",
")",
";",
"// remove comments",
"$",
"separator",
"=",
"preg_replace",
"(",
"'/\\/\\/.*/ui'",
",",
"''",
",",
"$",
"separator",
")",
";",
"$",
"separator",
"=",
"preg_replace",
"(",
"'/#.*/ui'",
",",
"''",
",",
"$",
"separator",
")",
";",
"$",
"separator",
"=",
"preg_replace",
"(",
"'/\\/\\*(.*)\\*\\//ui'",
",",
"''",
",",
"$",
"separator",
")",
";",
"return",
"$",
"separator",
";",
"}"
]
| Detect config items separator used in selected config item (providers, aliases).
@param $item
@return string | [
"Detect",
"config",
"items",
"separator",
"used",
"in",
"selected",
"config",
"item",
"(",
"providers",
"aliases",
")",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L185-L218 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.getInsertPoint | protected function getInsertPoint($for)
{
$bound = $this->getConfigItemBounds($for);
$file = $this->getFileContents();
$match = ['\'', '"', ','];
$matches = [];
for ($i = $bound[0]; $i <= $bound[1]; ++$i) {
$char = $file[$i];
if (in_array($char, $match)) {
if (!$this->isCharInComment($file, $i)) {
$matches[] = ['position' => $i + 1, 'symbol' => $char];
}
}
}
return end($matches);
} | php | protected function getInsertPoint($for)
{
$bound = $this->getConfigItemBounds($for);
$file = $this->getFileContents();
$match = ['\'', '"', ','];
$matches = [];
for ($i = $bound[0]; $i <= $bound[1]; ++$i) {
$char = $file[$i];
if (in_array($char, $match)) {
if (!$this->isCharInComment($file, $i)) {
$matches[] = ['position' => $i + 1, 'symbol' => $char];
}
}
}
return end($matches);
} | [
"protected",
"function",
"getInsertPoint",
"(",
"$",
"for",
")",
"{",
"$",
"bound",
"=",
"$",
"this",
"->",
"getConfigItemBounds",
"(",
"$",
"for",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileContents",
"(",
")",
";",
"$",
"match",
"=",
"[",
"'\\''",
",",
"'\"'",
",",
"','",
"]",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"bound",
"[",
"0",
"]",
";",
"$",
"i",
"<=",
"$",
"bound",
"[",
"1",
"]",
";",
"++",
"$",
"i",
")",
"{",
"$",
"char",
"=",
"$",
"file",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"char",
",",
"$",
"match",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCharInComment",
"(",
"$",
"file",
",",
"$",
"i",
")",
")",
"{",
"$",
"matches",
"[",
"]",
"=",
"[",
"'position'",
"=>",
"$",
"i",
"+",
"1",
",",
"'symbol'",
"=>",
"$",
"char",
"]",
";",
"}",
"}",
"}",
"return",
"end",
"(",
"$",
"matches",
")",
";",
"}"
]
| Detect point where to insert new data for selected config item (providers, aliases).
@param $for
@return array | [
"Detect",
"point",
"where",
"to",
"insert",
"new",
"data",
"for",
"selected",
"config",
"item",
"(",
"providers",
"aliases",
")",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L227-L243 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.isCharInComment | protected function isCharInComment($haystack, $charPosition)
{
// check for line comment
for ($c = $charPosition; $c > 0; --$c) {
if ($haystack[$c] === PHP_EOL) {
break;
} elseif ($haystack[$c] === '#' or ($haystack[$c] === '/'
and ($haystack[$c + 1] === '/' or $haystack[$c - 1] === '/'))
) {
return true;
}
}
// check for block comment
$openingsCount = 0;
$closingsCount = 0;
for ($c = $charPosition; $c > 0; --$c) {
if ($haystack[$c] === '*' and $haystack[$c - 1] === '/') {
++$openingsCount;
}
if ($haystack[$c] === '/' and $haystack[$c - 1] === '*') {
++$closingsCount;
}
}
if ($openingsCount !== $closingsCount) {
return true;
}
return false;
} | php | protected function isCharInComment($haystack, $charPosition)
{
// check for line comment
for ($c = $charPosition; $c > 0; --$c) {
if ($haystack[$c] === PHP_EOL) {
break;
} elseif ($haystack[$c] === '#' or ($haystack[$c] === '/'
and ($haystack[$c + 1] === '/' or $haystack[$c - 1] === '/'))
) {
return true;
}
}
// check for block comment
$openingsCount = 0;
$closingsCount = 0;
for ($c = $charPosition; $c > 0; --$c) {
if ($haystack[$c] === '*' and $haystack[$c - 1] === '/') {
++$openingsCount;
}
if ($haystack[$c] === '/' and $haystack[$c - 1] === '*') {
++$closingsCount;
}
}
if ($openingsCount !== $closingsCount) {
return true;
}
return false;
} | [
"protected",
"function",
"isCharInComment",
"(",
"$",
"haystack",
",",
"$",
"charPosition",
")",
"{",
"// check for line comment",
"for",
"(",
"$",
"c",
"=",
"$",
"charPosition",
";",
"$",
"c",
">",
"0",
";",
"--",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"haystack",
"[",
"$",
"c",
"]",
"===",
"PHP_EOL",
")",
"{",
"break",
";",
"}",
"elseif",
"(",
"$",
"haystack",
"[",
"$",
"c",
"]",
"===",
"'#'",
"or",
"(",
"$",
"haystack",
"[",
"$",
"c",
"]",
"===",
"'/'",
"and",
"(",
"$",
"haystack",
"[",
"$",
"c",
"+",
"1",
"]",
"===",
"'/'",
"or",
"$",
"haystack",
"[",
"$",
"c",
"-",
"1",
"]",
"===",
"'/'",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"// check for block comment",
"$",
"openingsCount",
"=",
"0",
";",
"$",
"closingsCount",
"=",
"0",
";",
"for",
"(",
"$",
"c",
"=",
"$",
"charPosition",
";",
"$",
"c",
">",
"0",
";",
"--",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"haystack",
"[",
"$",
"c",
"]",
"===",
"'*'",
"and",
"$",
"haystack",
"[",
"$",
"c",
"-",
"1",
"]",
"===",
"'/'",
")",
"{",
"++",
"$",
"openingsCount",
";",
"}",
"if",
"(",
"$",
"haystack",
"[",
"$",
"c",
"]",
"===",
"'/'",
"and",
"$",
"haystack",
"[",
"$",
"c",
"-",
"1",
"]",
"===",
"'*'",
")",
"{",
"++",
"$",
"closingsCount",
";",
"}",
"}",
"if",
"(",
"$",
"openingsCount",
"!==",
"$",
"closingsCount",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Detect is character at specified position is inside of a comment
@param $haystack
@param $charPosition
@return bool | [
"Detect",
"is",
"character",
"at",
"specified",
"position",
"is",
"inside",
"of",
"a",
"comment"
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L253-L280 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.write | protected function write($text, $anchor)
{
$this->backup();
$file = $this->getFileContents();
if ($anchor['symbol'] === ',') {
$text = ltrim($text, ',');
}
$file = substr_replace($file, $text, $anchor['position'], 0);
$this->file->put($this->configFile, $file);
$this->cleanup();
} | php | protected function write($text, $anchor)
{
$this->backup();
$file = $this->getFileContents();
if ($anchor['symbol'] === ',') {
$text = ltrim($text, ',');
}
$file = substr_replace($file, $text, $anchor['position'], 0);
$this->file->put($this->configFile, $file);
$this->cleanup();
} | [
"protected",
"function",
"write",
"(",
"$",
"text",
",",
"$",
"anchor",
")",
"{",
"$",
"this",
"->",
"backup",
"(",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileContents",
"(",
")",
";",
"if",
"(",
"$",
"anchor",
"[",
"'symbol'",
"]",
"===",
"','",
")",
"{",
"$",
"text",
"=",
"ltrim",
"(",
"$",
"text",
",",
"','",
")",
";",
"}",
"$",
"file",
"=",
"substr_replace",
"(",
"$",
"file",
",",
"$",
"text",
",",
"$",
"anchor",
"[",
"'position'",
"]",
",",
"0",
")",
";",
"$",
"this",
"->",
"file",
"->",
"put",
"(",
"$",
"this",
"->",
"configFile",
",",
"$",
"file",
")",
";",
"$",
"this",
"->",
"cleanup",
"(",
")",
";",
"}"
]
| Write new data to config file for selected config item (providers, aliases).
@param $text
@param $anchor | [
"Write",
"new",
"data",
"to",
"config",
"file",
"for",
"selected",
"config",
"item",
"(",
"providers",
"aliases",
")",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L288-L298 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.backup | protected function backup()
{
$from = $this->configFile;
$pathinfo = pathinfo($from);
$to = $pathinfo['dirname'] . DIRECTORY_SEPARATOR . $pathinfo['filename'] . '.bak.php';
$this->file->copy($from, $to);
} | php | protected function backup()
{
$from = $this->configFile;
$pathinfo = pathinfo($from);
$to = $pathinfo['dirname'] . DIRECTORY_SEPARATOR . $pathinfo['filename'] . '.bak.php';
$this->file->copy($from, $to);
} | [
"protected",
"function",
"backup",
"(",
")",
"{",
"$",
"from",
"=",
"$",
"this",
"->",
"configFile",
";",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"from",
")",
";",
"$",
"to",
"=",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"pathinfo",
"[",
"'filename'",
"]",
".",
"'.bak.php'",
";",
"$",
"this",
"->",
"file",
"->",
"copy",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"}"
]
| Backup config file | [
"Backup",
"config",
"file"
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L303-L309 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.cleanup | protected function cleanup()
{
$pathinfo = pathinfo($this->configFile);
$backup = $pathinfo['dirname'] . DIRECTORY_SEPARATOR . $pathinfo['filename'] . '.bak.php';
$this->file->delete($backup);
} | php | protected function cleanup()
{
$pathinfo = pathinfo($this->configFile);
$backup = $pathinfo['dirname'] . DIRECTORY_SEPARATOR . $pathinfo['filename'] . '.bak.php';
$this->file->delete($backup);
} | [
"protected",
"function",
"cleanup",
"(",
")",
"{",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"configFile",
")",
";",
"$",
"backup",
"=",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"pathinfo",
"[",
"'filename'",
"]",
".",
"'.bak.php'",
";",
"$",
"this",
"->",
"file",
"->",
"delete",
"(",
"$",
"backup",
")",
";",
"}"
]
| Cleanup backup | [
"Cleanup",
"backup"
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L314-L319 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.addAlias | public function addAlias($alias, $facade)
{
if ($facadeCurrent = array_get($this->getAliases(), $alias)) {
if ($facadeCurrent === $facade) {
return;
}
$this->commentOut($alias, 'aliases');
}
$quote = $this->getQuoteType('aliases');
$separator = $this->getArrayItemsSeparator('aliases');
$anchor = $this->getInsertPoint('aliases');
$insert = $separator . $quote . $alias . $quote . ' => ' . $quote . $facade . $quote . ',';
$this->write($insert, $anchor);
} | php | public function addAlias($alias, $facade)
{
if ($facadeCurrent = array_get($this->getAliases(), $alias)) {
if ($facadeCurrent === $facade) {
return;
}
$this->commentOut($alias, 'aliases');
}
$quote = $this->getQuoteType('aliases');
$separator = $this->getArrayItemsSeparator('aliases');
$anchor = $this->getInsertPoint('aliases');
$insert = $separator . $quote . $alias . $quote . ' => ' . $quote . $facade . $quote . ',';
$this->write($insert, $anchor);
} | [
"public",
"function",
"addAlias",
"(",
"$",
"alias",
",",
"$",
"facade",
")",
"{",
"if",
"(",
"$",
"facadeCurrent",
"=",
"array_get",
"(",
"$",
"this",
"->",
"getAliases",
"(",
")",
",",
"$",
"alias",
")",
")",
"{",
"if",
"(",
"$",
"facadeCurrent",
"===",
"$",
"facade",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"commentOut",
"(",
"$",
"alias",
",",
"'aliases'",
")",
";",
"}",
"$",
"quote",
"=",
"$",
"this",
"->",
"getQuoteType",
"(",
"'aliases'",
")",
";",
"$",
"separator",
"=",
"$",
"this",
"->",
"getArrayItemsSeparator",
"(",
"'aliases'",
")",
";",
"$",
"anchor",
"=",
"$",
"this",
"->",
"getInsertPoint",
"(",
"'aliases'",
")",
";",
"$",
"insert",
"=",
"$",
"separator",
".",
"$",
"quote",
".",
"$",
"alias",
".",
"$",
"quote",
".",
"' => '",
".",
"$",
"quote",
".",
"$",
"facade",
".",
"$",
"quote",
".",
"','",
";",
"$",
"this",
"->",
"write",
"(",
"$",
"insert",
",",
"$",
"anchor",
")",
";",
"}"
]
| Add specified facade.
@param $alias
@param $facade | [
"Add",
"specified",
"facade",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L327-L343 |
terion-name/package-installer | src/Terion/PackageInstaller/ConfigUpdater.php | ConfigUpdater.commentOut | protected function commentOut($search, $from)
{
$bounds = $this->getConfigItemBounds($from);
$file = $this->getFileContents();
$cutted = substr($file, 0, $bounds[1]);
preg_match_all(
'/[\'"]' . preg_quote($search) . '[\'"]/',
$cutted,
$matchFacade,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
);
foreach ($matchFacade as $match) {
if (!$this->isCharInComment($cutted, $match[0][1])) {
$commentFrom = $match[0][1];
$comma = strpos($cutted, ',', $commentFrom);
while ($this->isCharInComment($cutted, $comma)) {
$comma = strpos($cutted, ',', $comma);
}
$commentTill = $comma + 1;
$this->write('*/', ['position' => $commentTill, 'symbol' => '']);
$this->write('/*', ['position' => $commentFrom, 'symbol' => '']);
}
}
} | php | protected function commentOut($search, $from)
{
$bounds = $this->getConfigItemBounds($from);
$file = $this->getFileContents();
$cutted = substr($file, 0, $bounds[1]);
preg_match_all(
'/[\'"]' . preg_quote($search) . '[\'"]/',
$cutted,
$matchFacade,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
);
foreach ($matchFacade as $match) {
if (!$this->isCharInComment($cutted, $match[0][1])) {
$commentFrom = $match[0][1];
$comma = strpos($cutted, ',', $commentFrom);
while ($this->isCharInComment($cutted, $comma)) {
$comma = strpos($cutted, ',', $comma);
}
$commentTill = $comma + 1;
$this->write('*/', ['position' => $commentTill, 'symbol' => '']);
$this->write('/*', ['position' => $commentFrom, 'symbol' => '']);
}
}
} | [
"protected",
"function",
"commentOut",
"(",
"$",
"search",
",",
"$",
"from",
")",
"{",
"$",
"bounds",
"=",
"$",
"this",
"->",
"getConfigItemBounds",
"(",
"$",
"from",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileContents",
"(",
")",
";",
"$",
"cutted",
"=",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"$",
"bounds",
"[",
"1",
"]",
")",
";",
"preg_match_all",
"(",
"'/[\\'\"]'",
".",
"preg_quote",
"(",
"$",
"search",
")",
".",
"'[\\'\"]/'",
",",
"$",
"cutted",
",",
"$",
"matchFacade",
",",
"PREG_OFFSET_CAPTURE",
"|",
"PREG_SET_ORDER",
")",
";",
"foreach",
"(",
"$",
"matchFacade",
"as",
"$",
"match",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCharInComment",
"(",
"$",
"cutted",
",",
"$",
"match",
"[",
"0",
"]",
"[",
"1",
"]",
")",
")",
"{",
"$",
"commentFrom",
"=",
"$",
"match",
"[",
"0",
"]",
"[",
"1",
"]",
";",
"$",
"comma",
"=",
"strpos",
"(",
"$",
"cutted",
",",
"','",
",",
"$",
"commentFrom",
")",
";",
"while",
"(",
"$",
"this",
"->",
"isCharInComment",
"(",
"$",
"cutted",
",",
"$",
"comma",
")",
")",
"{",
"$",
"comma",
"=",
"strpos",
"(",
"$",
"cutted",
",",
"','",
",",
"$",
"comma",
")",
";",
"}",
"$",
"commentTill",
"=",
"$",
"comma",
"+",
"1",
";",
"$",
"this",
"->",
"write",
"(",
"'*/'",
",",
"[",
"'position'",
"=>",
"$",
"commentTill",
",",
"'symbol'",
"=>",
"''",
"]",
")",
";",
"$",
"this",
"->",
"write",
"(",
"'/*'",
",",
"[",
"'position'",
"=>",
"$",
"commentFrom",
",",
"'symbol'",
"=>",
"''",
"]",
")",
";",
"}",
"}",
"}"
]
| Comment item
@param $search
@param $from | [
"Comment",
"item"
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/ConfigUpdater.php#L351-L375 |
nodes-php/database | src/Support/Traits/Date.php | Date.getDateHumanReadable | public function getDateHumanReadable($column, $format = 'd-m-Y H:i:s', $maxDays = 3)
{
// Retrieve value of column
$date = $this->{$column};
// Make sure date is a Carbon object
// otherwise just return untouched value
if (! $date instanceof Carbon) {
return $column;
}
// If date is older than $maxDays
// we'll return the date and time
$daysDifference = $date->diffInDays();
if ($daysDifference > $maxDays) {
return $date->format($format);
}
return $date->diffForHumans();
} | php | public function getDateHumanReadable($column, $format = 'd-m-Y H:i:s', $maxDays = 3)
{
// Retrieve value of column
$date = $this->{$column};
// Make sure date is a Carbon object
// otherwise just return untouched value
if (! $date instanceof Carbon) {
return $column;
}
// If date is older than $maxDays
// we'll return the date and time
$daysDifference = $date->diffInDays();
if ($daysDifference > $maxDays) {
return $date->format($format);
}
return $date->diffForHumans();
} | [
"public",
"function",
"getDateHumanReadable",
"(",
"$",
"column",
",",
"$",
"format",
"=",
"'d-m-Y H:i:s'",
",",
"$",
"maxDays",
"=",
"3",
")",
"{",
"// Retrieve value of column",
"$",
"date",
"=",
"$",
"this",
"->",
"{",
"$",
"column",
"}",
";",
"// Make sure date is a Carbon object",
"// otherwise just return untouched value",
"if",
"(",
"!",
"$",
"date",
"instanceof",
"Carbon",
")",
"{",
"return",
"$",
"column",
";",
"}",
"// If date is older than $maxDays",
"// we'll return the date and time",
"$",
"daysDifference",
"=",
"$",
"date",
"->",
"diffInDays",
"(",
")",
";",
"if",
"(",
"$",
"daysDifference",
">",
"$",
"maxDays",
")",
"{",
"return",
"$",
"date",
"->",
"format",
"(",
"$",
"format",
")",
";",
"}",
"return",
"$",
"date",
"->",
"diffForHumans",
"(",
")",
";",
"}"
]
| Convert date to human-readable
E.g. "2 hours ago".
@author Morten Rugaard <[email protected]>
@date 21-10-2015
@param string $column
@param string $format
@param int $maxDays
@return string | [
"Convert",
"date",
"to",
"human",
"-",
"readable",
"E",
".",
"g",
".",
"2",
"hours",
"ago",
"."
]
| train | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Support/Traits/Date.php#L26-L45 |
webforge-labs/psc-cms | lib/Psc/CMS/Controller/ContentStreamController.php | ContentStreamController.processEntityFormRequest | protected function processEntityFormRequest(Entity $entity, FormData $requestData, $revision) {
$dataName = 'layoutManager';
if (isset($requestData->$dataName) && count($requestData->$dataName) > 0) {
$serialized = $requestData->$dataName;
} /*else {
throw $this->err->validationError($dataName, NULL, new \Psc\Exception('Das Layout muss mindestens 1 Element enthalten'));
}*/
// da wir keine unique constraints haben und neu sortieren müssen , nehmen wir die holzhammer methode:
// delete all
foreach ($entity->getEntries() as $entry) {
// den entry selbst löschen
$this->repository->remove($entry);
}
// auch aus dem CS löschen, weil der sonst automatisch persisted und das remove oben keinen effect hat
$entity->getEntries()->clear();
/*
PS: im Moment werden Entries von ContentStreams innerhalb des ContentStreams nicht mit delete all gelöscht
d.h. hier bleiben relativ viele leichen übrig (auch contentstreams selbst). Bei unserialize wird im
sub-ContentStream einfach eine neue instanz erzeugt die dann automatisch persisted wird
*/
if (isset($serialized)) {
// persist new
$this->getContentStreamConverter()->convertUnserialized($requestData->$dataName, $entity);
}
} | php | protected function processEntityFormRequest(Entity $entity, FormData $requestData, $revision) {
$dataName = 'layoutManager';
if (isset($requestData->$dataName) && count($requestData->$dataName) > 0) {
$serialized = $requestData->$dataName;
} /*else {
throw $this->err->validationError($dataName, NULL, new \Psc\Exception('Das Layout muss mindestens 1 Element enthalten'));
}*/
// da wir keine unique constraints haben und neu sortieren müssen , nehmen wir die holzhammer methode:
// delete all
foreach ($entity->getEntries() as $entry) {
// den entry selbst löschen
$this->repository->remove($entry);
}
// auch aus dem CS löschen, weil der sonst automatisch persisted und das remove oben keinen effect hat
$entity->getEntries()->clear();
/*
PS: im Moment werden Entries von ContentStreams innerhalb des ContentStreams nicht mit delete all gelöscht
d.h. hier bleiben relativ viele leichen übrig (auch contentstreams selbst). Bei unserialize wird im
sub-ContentStream einfach eine neue instanz erzeugt die dann automatisch persisted wird
*/
if (isset($serialized)) {
// persist new
$this->getContentStreamConverter()->convertUnserialized($requestData->$dataName, $entity);
}
} | [
"protected",
"function",
"processEntityFormRequest",
"(",
"Entity",
"$",
"entity",
",",
"FormData",
"$",
"requestData",
",",
"$",
"revision",
")",
"{",
"$",
"dataName",
"=",
"'layoutManager'",
";",
"if",
"(",
"isset",
"(",
"$",
"requestData",
"->",
"$",
"dataName",
")",
"&&",
"count",
"(",
"$",
"requestData",
"->",
"$",
"dataName",
")",
">",
"0",
")",
"{",
"$",
"serialized",
"=",
"$",
"requestData",
"->",
"$",
"dataName",
";",
"}",
"/*else {\n throw $this->err->validationError($dataName, NULL, new \\Psc\\Exception('Das Layout muss mindestens 1 Element enthalten'));\n }*/",
"// da wir keine unique constraints haben und neu sortieren müssen , nehmen wir die holzhammer methode:",
"// delete all",
"foreach",
"(",
"$",
"entity",
"->",
"getEntries",
"(",
")",
"as",
"$",
"entry",
")",
"{",
"// den entry selbst löschen",
"$",
"this",
"->",
"repository",
"->",
"remove",
"(",
"$",
"entry",
")",
";",
"}",
"// auch aus dem CS löschen, weil der sonst automatisch persisted und das remove oben keinen effect hat",
"$",
"entity",
"->",
"getEntries",
"(",
")",
"->",
"clear",
"(",
")",
";",
"/*\n PS: im Moment werden Entries von ContentStreams innerhalb des ContentStreams nicht mit delete all gelöscht\n d.h. hier bleiben relativ viele leichen übrig (auch contentstreams selbst). Bei unserialize wird im \n sub-ContentStream einfach eine neue instanz erzeugt die dann automatisch persisted wird\n */",
"if",
"(",
"isset",
"(",
"$",
"serialized",
")",
")",
"{",
"// persist new",
"$",
"this",
"->",
"getContentStreamConverter",
"(",
")",
"->",
"convertUnserialized",
"(",
"$",
"requestData",
"->",
"$",
"dataName",
",",
"$",
"entity",
")",
";",
"}",
"}"
]
| Überschreibt die AbstractEntityController FUnktion die den FormPanel abspeichert | [
"Überschreibt",
"die",
"AbstractEntityController",
"FUnktion",
"die",
"den",
"FormPanel",
"abspeichert"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/Controller/ContentStreamController.php#L71-L99 |
webforge-labs/psc-cms | lib/Psc/CMS/Controller/ContentStreamController.php | ContentStreamController.prepareFor | public function prepareFor(ContentStreamAware $entity, $type, $locale, $revision = 'default', $save = TRUE) {
try {
$contentStream =
$entity->getContentStream()
->locale($locale)
->type($type)
->revision($revision)
->one()
;
} catch (NoContentStreamsFoundException $e) {
$contentStream =
$this->createEmptyEntity($revision)
->setLocale($locale)
->setRevision($revision)
->setType($type);
$entity->addContentStream($contentStream);
if ($save) {
$this->repository->save($contentStream);
$this->repository->persist($entity);
}
}
return $contentStream;
} | php | public function prepareFor(ContentStreamAware $entity, $type, $locale, $revision = 'default', $save = TRUE) {
try {
$contentStream =
$entity->getContentStream()
->locale($locale)
->type($type)
->revision($revision)
->one()
;
} catch (NoContentStreamsFoundException $e) {
$contentStream =
$this->createEmptyEntity($revision)
->setLocale($locale)
->setRevision($revision)
->setType($type);
$entity->addContentStream($contentStream);
if ($save) {
$this->repository->save($contentStream);
$this->repository->persist($entity);
}
}
return $contentStream;
} | [
"public",
"function",
"prepareFor",
"(",
"ContentStreamAware",
"$",
"entity",
",",
"$",
"type",
",",
"$",
"locale",
",",
"$",
"revision",
"=",
"'default'",
",",
"$",
"save",
"=",
"TRUE",
")",
"{",
"try",
"{",
"$",
"contentStream",
"=",
"$",
"entity",
"->",
"getContentStream",
"(",
")",
"->",
"locale",
"(",
"$",
"locale",
")",
"->",
"type",
"(",
"$",
"type",
")",
"->",
"revision",
"(",
"$",
"revision",
")",
"->",
"one",
"(",
")",
";",
"}",
"catch",
"(",
"NoContentStreamsFoundException",
"$",
"e",
")",
"{",
"$",
"contentStream",
"=",
"$",
"this",
"->",
"createEmptyEntity",
"(",
"$",
"revision",
")",
"->",
"setLocale",
"(",
"$",
"locale",
")",
"->",
"setRevision",
"(",
"$",
"revision",
")",
"->",
"setType",
"(",
"$",
"type",
")",
";",
"$",
"entity",
"->",
"addContentStream",
"(",
"$",
"contentStream",
")",
";",
"if",
"(",
"$",
"save",
")",
"{",
"$",
"this",
"->",
"repository",
"->",
"save",
"(",
"$",
"contentStream",
")",
";",
"$",
"this",
"->",
"repository",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"}",
"}",
"return",
"$",
"contentStream",
";",
"}"
]
| Adds or returns a new ContentStream for the entity
@param bool $save per default the new contentStream (if created) is persisted and the em is flushed(!)
@return ContentStream (created or fetched from db) | [
"Adds",
"or",
"returns",
"a",
"new",
"ContentStream",
"for",
"the",
"entity"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/Controller/ContentStreamController.php#L147-L173 |
webforge-labs/psc-cms | lib/Psc/Data/ArrayCollection.php | ArrayCollection.deleteDiff | public function deleteDiff(Collection $collection, $compareFunction) {
return new ArrayCollection(array_merge(
$this->difference($this->toArray(), $collection->toArray(), $compareFunction)
));
} | php | public function deleteDiff(Collection $collection, $compareFunction) {
return new ArrayCollection(array_merge(
$this->difference($this->toArray(), $collection->toArray(), $compareFunction)
));
} | [
"public",
"function",
"deleteDiff",
"(",
"Collection",
"$",
"collection",
",",
"$",
"compareFunction",
")",
"{",
"return",
"new",
"ArrayCollection",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"difference",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
",",
"$",
"collection",
"->",
"toArray",
"(",
")",
",",
"$",
"compareFunction",
")",
")",
")",
";",
"}"
]
| Gibt alle Elemente zurück, die in dieser Collection, aber nicht in $collection sind
man müsste also die elemente dieser Ausgabe von $this entfernen, um zu $collection gleich zu sein
die $compareFunction bekommt 2 Parameter: $item1 und $item2. Diese sind aus $collection und $this
Bei Gleichheit muss sie 0 zurückgeben
ist $item1 in der Reihenfolge vor $item2 muss sie 1 zurückgeben ansonsten -1
Wird die Reihenfolge falsch ermittelt ist das Ergebnis des Diffs falsch!
für self::COMPARE_OBJECTS wird nach spl_object_hash() compared und sortiert (das ist dann === für objekte, geht jedoch nicht für basis-werte)
für self::COMPARE_TOSTRING ist die Gleichheit (string) $item1 === (string) $item2
@return ArrayCollection eine Liste der Diffs. Schlüssel bleiben nicht erhalten | [
"Gibt",
"alle",
"Elemente",
"zurück",
"die",
"in",
"dieser",
"Collection",
"aber",
"nicht",
"in",
"$collection",
"sind"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/ArrayCollection.php#L88-L92 |
webforge-labs/psc-cms | lib/Psc/Data/ArrayCollection.php | ArrayCollection.isSame | public function isSame(Collection $collection, $compareFunction) {
// ungleiche Anzahl ist nie gleich => fastcheck
if (count($this) !== count($collection)) return FALSE;
// Anzahl ist gleich, d. h. es sollte keine Elemente geben, die an einem Index nicht dem anderen Array identisch sind
$compareFunction = $this->compileCompareFunction($compareFunction);
foreach ($this as $key => $element) {
if (($otherElement = $collection->get($key)) === NULL) {
return FALSE;
}
if ($compareFunction($element, $otherElement) !== 0) {
return FALSE;
}
}
return TRUE;
} | php | public function isSame(Collection $collection, $compareFunction) {
// ungleiche Anzahl ist nie gleich => fastcheck
if (count($this) !== count($collection)) return FALSE;
// Anzahl ist gleich, d. h. es sollte keine Elemente geben, die an einem Index nicht dem anderen Array identisch sind
$compareFunction = $this->compileCompareFunction($compareFunction);
foreach ($this as $key => $element) {
if (($otherElement = $collection->get($key)) === NULL) {
return FALSE;
}
if ($compareFunction($element, $otherElement) !== 0) {
return FALSE;
}
}
return TRUE;
} | [
"public",
"function",
"isSame",
"(",
"Collection",
"$",
"collection",
",",
"$",
"compareFunction",
")",
"{",
"// ungleiche Anzahl ist nie gleich => fastcheck",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"!==",
"count",
"(",
"$",
"collection",
")",
")",
"return",
"FALSE",
";",
"// Anzahl ist gleich, d. h. es sollte keine Elemente geben, die an einem Index nicht dem anderen Array identisch sind",
"$",
"compareFunction",
"=",
"$",
"this",
"->",
"compileCompareFunction",
"(",
"$",
"compareFunction",
")",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"key",
"=>",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"otherElement",
"=",
"$",
"collection",
"->",
"get",
"(",
"$",
"key",
")",
")",
"===",
"NULL",
")",
"{",
"return",
"FALSE",
";",
"}",
"if",
"(",
"$",
"compareFunction",
"(",
"$",
"element",
",",
"$",
"otherElement",
")",
"!==",
"0",
")",
"{",
"return",
"FALSE",
";",
"}",
"}",
"return",
"TRUE",
";",
"}"
]
| Vergleicht die Collections auf identische Inhalte
Die Inhalte 2er Collections sind identisch, für alle Elemente an der Position $x der collections gilt:
$compareFunction($this[$x], $collection[$x]) === 0
die angegebene $compareFunction kann unabhängig von einer Reihenfolge der Elemente sein. (nur Ausgabe === 0 ist wichtig)
@return bool | [
"Vergleicht",
"die",
"Collections",
"auf",
"identische",
"Inhalte"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/ArrayCollection.php#L153-L171 |
webforge-labs/psc-cms | lib/Psc/Data/ArrayCollection.php | ArrayCollection.isEqual | public function isEqual(Collection $collection, $compareFunction) {
// ungleiche Anzahl ist nie gleich => fastcheck
if (count($this) !== count($collection)) return FALSE;
if (count($this->insertDiff($collection, $compareFunction)) > 0) return FALSE;
if (count($this->deleteDiff($collection, $compareFunction)) > 0) return FALSE;
return TRUE;
} | php | public function isEqual(Collection $collection, $compareFunction) {
// ungleiche Anzahl ist nie gleich => fastcheck
if (count($this) !== count($collection)) return FALSE;
if (count($this->insertDiff($collection, $compareFunction)) > 0) return FALSE;
if (count($this->deleteDiff($collection, $compareFunction)) > 0) return FALSE;
return TRUE;
} | [
"public",
"function",
"isEqual",
"(",
"Collection",
"$",
"collection",
",",
"$",
"compareFunction",
")",
"{",
"// ungleiche Anzahl ist nie gleich => fastcheck",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"!==",
"count",
"(",
"$",
"collection",
")",
")",
"return",
"FALSE",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"insertDiff",
"(",
"$",
"collection",
",",
"$",
"compareFunction",
")",
")",
">",
"0",
")",
"return",
"FALSE",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"deleteDiff",
"(",
"$",
"collection",
",",
"$",
"compareFunction",
")",
")",
">",
"0",
")",
"return",
"FALSE",
";",
"return",
"TRUE",
";",
"}"
]
| Vergleicht die Inhalte zweier Collections
die Schlüssel der Elemente sind nicht relevant (anders als bei isSame)
@return bool | [
"Vergleicht",
"die",
"Inhalte",
"zweier",
"Collections"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/ArrayCollection.php#L179-L187 |
webforge-labs/psc-cms | lib/Psc/Data/ArrayCollection.php | ArrayCollection.computeCUDSets | public function computeCUDSets(Collection $collection, $compareFunction, $uniqueHashFunction = NULL) {
$compareFunction = $this->compileCompareFunction($compareFunction);
if (!isset($uniqueHashFunction)) {
$uniqueHashFunction = function ($o) {
return spl_object_hash($o);
};
}
$updates = array();
$deletes = array();
$intersect = array();
$collection = $collection->toArray();
usort($collection, $compareFunction); // aufsteigend sortieren
foreach ($this->toArray() as $key => $item) {
$found = FALSE;
foreach ($collection as $other) {
if (($r = $compareFunction($item, $other)) === 0) {
$updates[] = $item;
$intersect[$uniqueHashFunction($item)] = TRUE;
$found = TRUE;
break;
} elseif ($r === -1) { // wir müssen nicht weiter prüfen, da ja $collection aufsteigend sortiert ist
break;
}
}
if (!$found) { // jedes element welches nicht in $collection ist, wurde gelöscht
$deletes[] = $item;
}
}
$inserts = array();
foreach ($collection as $other) {
// jedes elemente welches in collection ist, aber nicht in $this, wurde eingefügt
if (!array_key_exists($uniqueHashFunction($other), $intersect)) {
$inserts[] = $other;
}
}
return array(new ArrayCollection($inserts), new ArrayCollection($updates), new ArrayCollection($deletes));
} | php | public function computeCUDSets(Collection $collection, $compareFunction, $uniqueHashFunction = NULL) {
$compareFunction = $this->compileCompareFunction($compareFunction);
if (!isset($uniqueHashFunction)) {
$uniqueHashFunction = function ($o) {
return spl_object_hash($o);
};
}
$updates = array();
$deletes = array();
$intersect = array();
$collection = $collection->toArray();
usort($collection, $compareFunction); // aufsteigend sortieren
foreach ($this->toArray() as $key => $item) {
$found = FALSE;
foreach ($collection as $other) {
if (($r = $compareFunction($item, $other)) === 0) {
$updates[] = $item;
$intersect[$uniqueHashFunction($item)] = TRUE;
$found = TRUE;
break;
} elseif ($r === -1) { // wir müssen nicht weiter prüfen, da ja $collection aufsteigend sortiert ist
break;
}
}
if (!$found) { // jedes element welches nicht in $collection ist, wurde gelöscht
$deletes[] = $item;
}
}
$inserts = array();
foreach ($collection as $other) {
// jedes elemente welches in collection ist, aber nicht in $this, wurde eingefügt
if (!array_key_exists($uniqueHashFunction($other), $intersect)) {
$inserts[] = $other;
}
}
return array(new ArrayCollection($inserts), new ArrayCollection($updates), new ArrayCollection($deletes));
} | [
"public",
"function",
"computeCUDSets",
"(",
"Collection",
"$",
"collection",
",",
"$",
"compareFunction",
",",
"$",
"uniqueHashFunction",
"=",
"NULL",
")",
"{",
"$",
"compareFunction",
"=",
"$",
"this",
"->",
"compileCompareFunction",
"(",
"$",
"compareFunction",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"uniqueHashFunction",
")",
")",
"{",
"$",
"uniqueHashFunction",
"=",
"function",
"(",
"$",
"o",
")",
"{",
"return",
"spl_object_hash",
"(",
"$",
"o",
")",
";",
"}",
";",
"}",
"$",
"updates",
"=",
"array",
"(",
")",
";",
"$",
"deletes",
"=",
"array",
"(",
")",
";",
"$",
"intersect",
"=",
"array",
"(",
")",
";",
"$",
"collection",
"=",
"$",
"collection",
"->",
"toArray",
"(",
")",
";",
"usort",
"(",
"$",
"collection",
",",
"$",
"compareFunction",
")",
";",
"// aufsteigend sortieren",
"foreach",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"found",
"=",
"FALSE",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"other",
")",
"{",
"if",
"(",
"(",
"$",
"r",
"=",
"$",
"compareFunction",
"(",
"$",
"item",
",",
"$",
"other",
")",
")",
"===",
"0",
")",
"{",
"$",
"updates",
"[",
"]",
"=",
"$",
"item",
";",
"$",
"intersect",
"[",
"$",
"uniqueHashFunction",
"(",
"$",
"item",
")",
"]",
"=",
"TRUE",
";",
"$",
"found",
"=",
"TRUE",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"r",
"===",
"-",
"1",
")",
"{",
"// wir müssen nicht weiter prüfen, da ja $collection aufsteigend sortiert ist",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"// jedes element welches nicht in $collection ist, wurde gelöscht",
"$",
"deletes",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"$",
"inserts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"other",
")",
"{",
"// jedes elemente welches in collection ist, aber nicht in $this, wurde eingefügt",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"uniqueHashFunction",
"(",
"$",
"other",
")",
",",
"$",
"intersect",
")",
")",
"{",
"$",
"inserts",
"[",
"]",
"=",
"$",
"other",
";",
"}",
"}",
"return",
"array",
"(",
"new",
"ArrayCollection",
"(",
"$",
"inserts",
")",
",",
"new",
"ArrayCollection",
"(",
"$",
"updates",
")",
",",
"new",
"ArrayCollection",
"(",
"$",
"deletes",
")",
")",
";",
"}"
]
| Berechnet updates / inserts / deletes (komplettes diff) 2er Collections
Natürlich ist es auch möglich diese mit insertDiff/deleteDiff/Intersect zu berechnen. Diese Funktion ist aber schneller und benötigt dafür nur ein uniqueHash-Kriterium (welches standardmäßig der spl_object_hash ist).
D. h. im DefaultFall funkioniert diese Funktion nur mit Objekten
die $uniqueHashFunction bekommt ein argument und sollte ein int / string (irgendwas für einen array-key-geeignetes) zurückgeben
diese Variante ist ca 10-25% schneller als 2 diffs und intersect
@return list(ArrayCollection $inserts, ArrayCollection $updates, ArrayCollection $deletes) | [
"Berechnet",
"updates",
"/",
"inserts",
"/",
"deletes",
"(",
"komplettes",
"diff",
")",
"2er",
"Collections"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/ArrayCollection.php#L200-L241 |
webforge-labs/psc-cms | lib/Psc/CMS/Controller/ExcelController.php | ExcelController.convert | public function convert(\stdClass $table, $excelFile = NULL, $removeEmpty = TRUE) {
$excelFile = $excelFile ?: $this->v->validateUploadedFile('excelFile');
$reader = PHPExcel_IOFactory::createReaderForFile((string) $excelFile);
$excel = $reader->load((string) $excelFile);
$sheet = $excel->getSheet(0);
$columns = isset($table->columns) ? (array) $table->columns : array();
$nullValue = ''; // sadly json macht aus NULL den string "null" in js
$data = array();
$mCell = 0;
foreach ($sheet->getRowIterator() as $wsRow) {
$row = array();
$empty = TRUE;
foreach ($wsRow->getCellIterator() as $cell) {
// $cell->getDataType() gibts sogar auch
$cellIndex = h::getColumnIndex($cell->getColumn());
$mCell = max($mCell, $cellIndex+1);
$row[$cellIndex] = $value = $this->convertValue(
$cell->getValue(),
isset($columns[$cellIndex]) && isset($columns[$cellIndex]->type) ? $columns[$cellIndex]->type : NULL
);
if ($value != '') {
$empty = FALSE;
}
}
if (!$removeEmpty || !$empty) {
ksort($row);
$data[] = array_replace(array_fill(0, $mCell, $nullValue), $row);
}
}
return new ServiceResponse(Service::OK, $data, ServiceResponse::JSON_UPLOAD_RESPONSE);
} | php | public function convert(\stdClass $table, $excelFile = NULL, $removeEmpty = TRUE) {
$excelFile = $excelFile ?: $this->v->validateUploadedFile('excelFile');
$reader = PHPExcel_IOFactory::createReaderForFile((string) $excelFile);
$excel = $reader->load((string) $excelFile);
$sheet = $excel->getSheet(0);
$columns = isset($table->columns) ? (array) $table->columns : array();
$nullValue = ''; // sadly json macht aus NULL den string "null" in js
$data = array();
$mCell = 0;
foreach ($sheet->getRowIterator() as $wsRow) {
$row = array();
$empty = TRUE;
foreach ($wsRow->getCellIterator() as $cell) {
// $cell->getDataType() gibts sogar auch
$cellIndex = h::getColumnIndex($cell->getColumn());
$mCell = max($mCell, $cellIndex+1);
$row[$cellIndex] = $value = $this->convertValue(
$cell->getValue(),
isset($columns[$cellIndex]) && isset($columns[$cellIndex]->type) ? $columns[$cellIndex]->type : NULL
);
if ($value != '') {
$empty = FALSE;
}
}
if (!$removeEmpty || !$empty) {
ksort($row);
$data[] = array_replace(array_fill(0, $mCell, $nullValue), $row);
}
}
return new ServiceResponse(Service::OK, $data, ServiceResponse::JSON_UPLOAD_RESPONSE);
} | [
"public",
"function",
"convert",
"(",
"\\",
"stdClass",
"$",
"table",
",",
"$",
"excelFile",
"=",
"NULL",
",",
"$",
"removeEmpty",
"=",
"TRUE",
")",
"{",
"$",
"excelFile",
"=",
"$",
"excelFile",
"?",
":",
"$",
"this",
"->",
"v",
"->",
"validateUploadedFile",
"(",
"'excelFile'",
")",
";",
"$",
"reader",
"=",
"PHPExcel_IOFactory",
"::",
"createReaderForFile",
"(",
"(",
"string",
")",
"$",
"excelFile",
")",
";",
"$",
"excel",
"=",
"$",
"reader",
"->",
"load",
"(",
"(",
"string",
")",
"$",
"excelFile",
")",
";",
"$",
"sheet",
"=",
"$",
"excel",
"->",
"getSheet",
"(",
"0",
")",
";",
"$",
"columns",
"=",
"isset",
"(",
"$",
"table",
"->",
"columns",
")",
"?",
"(",
"array",
")",
"$",
"table",
"->",
"columns",
":",
"array",
"(",
")",
";",
"$",
"nullValue",
"=",
"''",
";",
"// sadly json macht aus NULL den string \"null\" in js",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"mCell",
"=",
"0",
";",
"foreach",
"(",
"$",
"sheet",
"->",
"getRowIterator",
"(",
")",
"as",
"$",
"wsRow",
")",
"{",
"$",
"row",
"=",
"array",
"(",
")",
";",
"$",
"empty",
"=",
"TRUE",
";",
"foreach",
"(",
"$",
"wsRow",
"->",
"getCellIterator",
"(",
")",
"as",
"$",
"cell",
")",
"{",
"// $cell->getDataType() gibts sogar auch",
"$",
"cellIndex",
"=",
"h",
"::",
"getColumnIndex",
"(",
"$",
"cell",
"->",
"getColumn",
"(",
")",
")",
";",
"$",
"mCell",
"=",
"max",
"(",
"$",
"mCell",
",",
"$",
"cellIndex",
"+",
"1",
")",
";",
"$",
"row",
"[",
"$",
"cellIndex",
"]",
"=",
"$",
"value",
"=",
"$",
"this",
"->",
"convertValue",
"(",
"$",
"cell",
"->",
"getValue",
"(",
")",
",",
"isset",
"(",
"$",
"columns",
"[",
"$",
"cellIndex",
"]",
")",
"&&",
"isset",
"(",
"$",
"columns",
"[",
"$",
"cellIndex",
"]",
"->",
"type",
")",
"?",
"$",
"columns",
"[",
"$",
"cellIndex",
"]",
"->",
"type",
":",
"NULL",
")",
";",
"if",
"(",
"$",
"value",
"!=",
"''",
")",
"{",
"$",
"empty",
"=",
"FALSE",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"removeEmpty",
"||",
"!",
"$",
"empty",
")",
"{",
"ksort",
"(",
"$",
"row",
")",
";",
"$",
"data",
"[",
"]",
"=",
"array_replace",
"(",
"array_fill",
"(",
"0",
",",
"$",
"mCell",
",",
"$",
"nullValue",
")",
",",
"$",
"row",
")",
";",
"}",
"}",
"return",
"new",
"ServiceResponse",
"(",
"Service",
"::",
"OK",
",",
"$",
"data",
",",
"ServiceResponse",
"::",
"JSON_UPLOAD_RESPONSE",
")",
";",
"}"
]
| Konvertiert ein Excel in einen Array
Erwartet excelFile als Uploaded File
der zurückgegebene Array hat jedoch keine Zahlen Columns sondern auch einen 0 basierten index
auch die Rows sind 0 basierend
@controller-api
@return array | [
"Konvertiert",
"ein",
"Excel",
"in",
"einen",
"Array"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/Controller/ExcelController.php#L95-L132 |
4devs/ElfinderPhpConnector | Util/ImageManagerTrait.php | ImageManagerTrait.setImageManager | public function setImageManager(ImageManager $imageManager = null, array $config = [])
{
if (!$imageManager) {
$imageManager = new ImageManager($config);
}
$this->imageManager = $imageManager;
return $this;
} | php | public function setImageManager(ImageManager $imageManager = null, array $config = [])
{
if (!$imageManager) {
$imageManager = new ImageManager($config);
}
$this->imageManager = $imageManager;
return $this;
} | [
"public",
"function",
"setImageManager",
"(",
"ImageManager",
"$",
"imageManager",
"=",
"null",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"imageManager",
")",
"{",
"$",
"imageManager",
"=",
"new",
"ImageManager",
"(",
"$",
"config",
")",
";",
"}",
"$",
"this",
"->",
"imageManager",
"=",
"$",
"imageManager",
";",
"return",
"$",
"this",
";",
"}"
]
| @param ImageManager $imageManager
@param array $config
@return $this | [
"@param",
"ImageManager",
"$imageManager",
"@param",
"array",
"$config"
]
| train | https://github.com/4devs/ElfinderPhpConnector/blob/510e295dcafeaa0f796986ad87b3ed5f6b0d9338/Util/ImageManagerTrait.php#L18-L26 |
spiral-modules/auth | source/Auth/Operators/Bridges/CookieBridge.php | CookieBridge.hasToken | public function hasToken(Request $request): bool
{
$cookies = $request->getCookieParams();
return isset($cookies[$this->cookie]);
} | php | public function hasToken(Request $request): bool
{
$cookies = $request->getCookieParams();
return isset($cookies[$this->cookie]);
} | [
"public",
"function",
"hasToken",
"(",
"Request",
"$",
"request",
")",
":",
"bool",
"{",
"$",
"cookies",
"=",
"$",
"request",
"->",
"getCookieParams",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"cookies",
"[",
"$",
"this",
"->",
"cookie",
"]",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Operators/Bridges/CookieBridge.php#L45-L50 |
spiral-modules/auth | source/Auth/Operators/Bridges/CookieBridge.php | CookieBridge.fetchToken | public function fetchToken(Request $request)
{
$cookies = $request->getCookieParams();
return isset($cookies[$this->cookie]) ? $cookies[$this->cookie] : null;
} | php | public function fetchToken(Request $request)
{
$cookies = $request->getCookieParams();
return isset($cookies[$this->cookie]) ? $cookies[$this->cookie] : null;
} | [
"public",
"function",
"fetchToken",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"cookies",
"=",
"$",
"request",
"->",
"getCookieParams",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"cookies",
"[",
"$",
"this",
"->",
"cookie",
"]",
")",
"?",
"$",
"cookies",
"[",
"$",
"this",
"->",
"cookie",
"]",
":",
"null",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Operators/Bridges/CookieBridge.php#L55-L60 |
spiral-modules/auth | source/Auth/Operators/Bridges/CookieBridge.php | CookieBridge.writeToken | public function writeToken(
Request $request,
Response $response,
int $lifetime,
string $token = null
): Response {
$cookies = $request->getCookieParams();
if (isset($cookies[$this->cookie]) && $cookies[$this->cookie] == $token) {
//Nothing to do
return $response;
}
$cookie = Cookie::create(
$this->cookie,
$token,
$lifetime,
$this->httpConfig->basePath(),
$this->httpConfig->cookiesDomain($request->getUri())
);
return $response->withAddedHeader('Set-Cookie', $cookie->createHeader());
} | php | public function writeToken(
Request $request,
Response $response,
int $lifetime,
string $token = null
): Response {
$cookies = $request->getCookieParams();
if (isset($cookies[$this->cookie]) && $cookies[$this->cookie] == $token) {
//Nothing to do
return $response;
}
$cookie = Cookie::create(
$this->cookie,
$token,
$lifetime,
$this->httpConfig->basePath(),
$this->httpConfig->cookiesDomain($request->getUri())
);
return $response->withAddedHeader('Set-Cookie', $cookie->createHeader());
} | [
"public",
"function",
"writeToken",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
",",
"int",
"$",
"lifetime",
",",
"string",
"$",
"token",
"=",
"null",
")",
":",
"Response",
"{",
"$",
"cookies",
"=",
"$",
"request",
"->",
"getCookieParams",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"cookies",
"[",
"$",
"this",
"->",
"cookie",
"]",
")",
"&&",
"$",
"cookies",
"[",
"$",
"this",
"->",
"cookie",
"]",
"==",
"$",
"token",
")",
"{",
"//Nothing to do",
"return",
"$",
"response",
";",
"}",
"$",
"cookie",
"=",
"Cookie",
"::",
"create",
"(",
"$",
"this",
"->",
"cookie",
",",
"$",
"token",
",",
"$",
"lifetime",
",",
"$",
"this",
"->",
"httpConfig",
"->",
"basePath",
"(",
")",
",",
"$",
"this",
"->",
"httpConfig",
"->",
"cookiesDomain",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
")",
")",
";",
"return",
"$",
"response",
"->",
"withAddedHeader",
"(",
"'Set-Cookie'",
",",
"$",
"cookie",
"->",
"createHeader",
"(",
")",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Operators/Bridges/CookieBridge.php#L65-L87 |
picamator/CacheManager | src/Data/SearchCriteriaBuilder.php | SearchCriteriaBuilder.build | public function build() : SearchCriteriaInterface
{
/** @var SearchCriteriaInterface $result */
$result = $this->objectManager->create($this->className, $this->data);
$this->cleanData();
return $result;
} | php | public function build() : SearchCriteriaInterface
{
/** @var SearchCriteriaInterface $result */
$result = $this->objectManager->create($this->className, $this->data);
$this->cleanData();
return $result;
} | [
"public",
"function",
"build",
"(",
")",
":",
"SearchCriteriaInterface",
"{",
"/** @var SearchCriteriaInterface $result */",
"$",
"result",
"=",
"$",
"this",
"->",
"objectManager",
"->",
"create",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"this",
"->",
"data",
")",
";",
"$",
"this",
"->",
"cleanData",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Data/SearchCriteriaBuilder.php#L104-L111 |
picamator/CacheManager | src/Data/SearchCriteriaBuilder.php | SearchCriteriaBuilder.cleanData | private function cleanData()
{
foreach ($this->data as &$item) {
$item = is_array($item) ? [] : null;
}
unset($item); // prevent unexpected behaviour
} | php | private function cleanData()
{
foreach ($this->data as &$item) {
$item = is_array($item) ? [] : null;
}
unset($item); // prevent unexpected behaviour
} | [
"private",
"function",
"cleanData",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"&",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"is_array",
"(",
"$",
"item",
")",
"?",
"[",
"]",
":",
"null",
";",
"}",
"unset",
"(",
"$",
"item",
")",
";",
"// prevent unexpected behaviour",
"}"
]
| Clean data. | [
"Clean",
"data",
"."
]
| train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Data/SearchCriteriaBuilder.php#L116-L122 |
jacobemerick/pqp | src/PhpQuickProfiler.php | PhpQuickProfiler.gatherFileData | public function gatherFileData()
{
$files = get_included_files();
$data = array();
foreach ($files as $file) {
array_push($data, array(
'name' => $file,
'size' => filesize($file)
));
}
return $data;
} | php | public function gatherFileData()
{
$files = get_included_files();
$data = array();
foreach ($files as $file) {
array_push($data, array(
'name' => $file,
'size' => filesize($file)
));
}
return $data;
} | [
"public",
"function",
"gatherFileData",
"(",
")",
"{",
"$",
"files",
"=",
"get_included_files",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"array_push",
"(",
"$",
"data",
",",
"array",
"(",
"'name'",
"=>",
"$",
"file",
",",
"'size'",
"=>",
"filesize",
"(",
"$",
"file",
")",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Get data about files loaded for the application to current point
@returns array | [
"Get",
"data",
"about",
"files",
"loaded",
"for",
"the",
"application",
"to",
"current",
"point"
]
| train | https://github.com/jacobemerick/pqp/blob/08276f050425d1ab71e7ca3b897eb8c409ccbe70/src/PhpQuickProfiler.php#L64-L75 |
jacobemerick/pqp | src/PhpQuickProfiler.php | PhpQuickProfiler.gatherQueryData | public function gatherQueryData($dbConnection = null)
{
if (is_null($dbConnection)) {
return array();
}
if (empty($this->profiledQueries) && property_exists($dbConnection, 'queries')) {
$this->setProfiledQueries($dbConnection->queries);
}
$data = array();
foreach ($this->profiledQueries as $query) {
array_push($data, array(
'sql' => $query['sql'],
'explain' => $this->explainQuery($dbConnection, $query['sql'], $query['parameters']),
'time' => $query['time']
));
}
return $data;
} | php | public function gatherQueryData($dbConnection = null)
{
if (is_null($dbConnection)) {
return array();
}
if (empty($this->profiledQueries) && property_exists($dbConnection, 'queries')) {
$this->setProfiledQueries($dbConnection->queries);
}
$data = array();
foreach ($this->profiledQueries as $query) {
array_push($data, array(
'sql' => $query['sql'],
'explain' => $this->explainQuery($dbConnection, $query['sql'], $query['parameters']),
'time' => $query['time']
));
}
return $data;
} | [
"public",
"function",
"gatherQueryData",
"(",
"$",
"dbConnection",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"dbConnection",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"profiledQueries",
")",
"&&",
"property_exists",
"(",
"$",
"dbConnection",
",",
"'queries'",
")",
")",
"{",
"$",
"this",
"->",
"setProfiledQueries",
"(",
"$",
"dbConnection",
"->",
"queries",
")",
";",
"}",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"profiledQueries",
"as",
"$",
"query",
")",
"{",
"array_push",
"(",
"$",
"data",
",",
"array",
"(",
"'sql'",
"=>",
"$",
"query",
"[",
"'sql'",
"]",
",",
"'explain'",
"=>",
"$",
"this",
"->",
"explainQuery",
"(",
"$",
"dbConnection",
",",
"$",
"query",
"[",
"'sql'",
"]",
",",
"$",
"query",
"[",
"'parameters'",
"]",
")",
",",
"'time'",
"=>",
"$",
"query",
"[",
"'time'",
"]",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Get data about sql usage of the application
@param object $dbConnection
@returns array | [
"Get",
"data",
"about",
"sql",
"usage",
"of",
"the",
"application"
]
| train | https://github.com/jacobemerick/pqp/blob/08276f050425d1ab71e7ca3b897eb8c409ccbe70/src/PhpQuickProfiler.php#L106-L125 |
jacobemerick/pqp | src/PhpQuickProfiler.php | PhpQuickProfiler.explainQuery | protected function explainQuery($dbConnection, $query, $parameters = array())
{
$driver = $dbConnection->getAttribute(\PDO::ATTR_DRIVER_NAME);
$query = $this->getExplainQuery($query, $driver);
$statement = $dbConnection->prepare($query);
if ($statement === false) {
throw new Exception('Invalid query passed to explainQuery method');
}
$statement->execute($parameters);
$result = $statement->fetch(\PDO::FETCH_ASSOC);
if ($result === false) {
throw new Exception('Query could not be explained with given parameters');
}
return $result;
} | php | protected function explainQuery($dbConnection, $query, $parameters = array())
{
$driver = $dbConnection->getAttribute(\PDO::ATTR_DRIVER_NAME);
$query = $this->getExplainQuery($query, $driver);
$statement = $dbConnection->prepare($query);
if ($statement === false) {
throw new Exception('Invalid query passed to explainQuery method');
}
$statement->execute($parameters);
$result = $statement->fetch(\PDO::FETCH_ASSOC);
if ($result === false) {
throw new Exception('Query could not be explained with given parameters');
}
return $result;
} | [
"protected",
"function",
"explainQuery",
"(",
"$",
"dbConnection",
",",
"$",
"query",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"driver",
"=",
"$",
"dbConnection",
"->",
"getAttribute",
"(",
"\\",
"PDO",
"::",
"ATTR_DRIVER_NAME",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getExplainQuery",
"(",
"$",
"query",
",",
"$",
"driver",
")",
";",
"$",
"statement",
"=",
"$",
"dbConnection",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"statement",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Invalid query passed to explainQuery method'",
")",
";",
"}",
"$",
"statement",
"->",
"execute",
"(",
"$",
"parameters",
")",
";",
"$",
"result",
"=",
"$",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Query could not be explained with given parameters'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Attempts to explain a query
@param object $dbConnection
@param string $query
@param array $parameters
@throws Exception
@return array | [
"Attempts",
"to",
"explain",
"a",
"query"
]
| train | https://github.com/jacobemerick/pqp/blob/08276f050425d1ab71e7ca3b897eb8c409ccbe70/src/PhpQuickProfiler.php#L136-L150 |
jacobemerick/pqp | src/PhpQuickProfiler.php | PhpQuickProfiler.gatherSpeedData | public function gatherSpeedData()
{
$elapsedTime = microtime(true) - $this->startTime;
$elapsedTime = round($elapsedTime, 3);
$allowedTime = ini_get('max_execution_time');
return array(
'elapsed' => $elapsedTime,
'allowed' => $allowedTime
);
} | php | public function gatherSpeedData()
{
$elapsedTime = microtime(true) - $this->startTime;
$elapsedTime = round($elapsedTime, 3);
$allowedTime = ini_get('max_execution_time');
return array(
'elapsed' => $elapsedTime,
'allowed' => $allowedTime
);
} | [
"public",
"function",
"gatherSpeedData",
"(",
")",
"{",
"$",
"elapsedTime",
"=",
"microtime",
"(",
"true",
")",
"-",
"$",
"this",
"->",
"startTime",
";",
"$",
"elapsedTime",
"=",
"round",
"(",
"$",
"elapsedTime",
",",
"3",
")",
";",
"$",
"allowedTime",
"=",
"ini_get",
"(",
"'max_execution_time'",
")",
";",
"return",
"array",
"(",
"'elapsed'",
"=>",
"$",
"elapsedTime",
",",
"'allowed'",
"=>",
"$",
"allowedTime",
")",
";",
"}"
]
| Get data about speed of the application
@returns array | [
"Get",
"data",
"about",
"speed",
"of",
"the",
"application"
]
| train | https://github.com/jacobemerick/pqp/blob/08276f050425d1ab71e7ca3b897eb8c409ccbe70/src/PhpQuickProfiler.php#L175-L184 |
jacobemerick/pqp | src/PhpQuickProfiler.php | PhpQuickProfiler.display | public function display($dbConnection = null)
{
if (!isset($this->display)) {
throw new Exception('Display object has not been injected into Profiler');
}
if (!isset($this->console)) {
throw new Exception('Console object has not been injected into Profiler');
}
$this->display->setStartTime($this->startTime);
$this->display->setConsole($this->console);
$this->display->setFileData($this->gatherFileData());
$this->display->setMemoryData($this->gatherMemoryData());
$this->display->setQueryData($this->gatherQueryData($dbConnection));
$this->display->setSpeedData($this->gatherSpeedData());
$this->display->__invoke();
} | php | public function display($dbConnection = null)
{
if (!isset($this->display)) {
throw new Exception('Display object has not been injected into Profiler');
}
if (!isset($this->console)) {
throw new Exception('Console object has not been injected into Profiler');
}
$this->display->setStartTime($this->startTime);
$this->display->setConsole($this->console);
$this->display->setFileData($this->gatherFileData());
$this->display->setMemoryData($this->gatherMemoryData());
$this->display->setQueryData($this->gatherQueryData($dbConnection));
$this->display->setSpeedData($this->gatherSpeedData());
$this->display->__invoke();
} | [
"public",
"function",
"display",
"(",
"$",
"dbConnection",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"display",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Display object has not been injected into Profiler'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"console",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Console object has not been injected into Profiler'",
")",
";",
"}",
"$",
"this",
"->",
"display",
"->",
"setStartTime",
"(",
"$",
"this",
"->",
"startTime",
")",
";",
"$",
"this",
"->",
"display",
"->",
"setConsole",
"(",
"$",
"this",
"->",
"console",
")",
";",
"$",
"this",
"->",
"display",
"->",
"setFileData",
"(",
"$",
"this",
"->",
"gatherFileData",
"(",
")",
")",
";",
"$",
"this",
"->",
"display",
"->",
"setMemoryData",
"(",
"$",
"this",
"->",
"gatherMemoryData",
"(",
")",
")",
";",
"$",
"this",
"->",
"display",
"->",
"setQueryData",
"(",
"$",
"this",
"->",
"gatherQueryData",
"(",
"$",
"dbConnection",
")",
")",
";",
"$",
"this",
"->",
"display",
"->",
"setSpeedData",
"(",
"$",
"this",
"->",
"gatherSpeedData",
"(",
")",
")",
";",
"$",
"this",
"->",
"display",
"->",
"__invoke",
"(",
")",
";",
"}"
]
| Triggers end display of the profiling data
@param object $dbConnection
@throws Exception | [
"Triggers",
"end",
"display",
"of",
"the",
"profiling",
"data"
]
| train | https://github.com/jacobemerick/pqp/blob/08276f050425d1ab71e7ca3b897eb8c409ccbe70/src/PhpQuickProfiler.php#L192-L209 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.