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
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
simple-php-mvc/simple-php-mvc | src/MVC/Server/Route.php | Route.setMethods | public function setMethods($methods)
{
if (is_string($methods)) {
if (!isset(self::$validMethods[strtolower($methods)])) {
throw new \LogicException(sprintf('Route method "%s" is invalid. Params expected "%s"', $methods, implode(', ', array_keys(self::$validMethods))));
}
$this->methods = array($methods);
}
if (is_array($methods)) {
$this->methods = $methods;
}
return $this;
} | php | public function setMethods($methods)
{
if (is_string($methods)) {
if (!isset(self::$validMethods[strtolower($methods)])) {
throw new \LogicException(sprintf('Route method "%s" is invalid. Params expected "%s"', $methods, implode(', ', array_keys(self::$validMethods))));
}
$this->methods = array($methods);
}
if (is_array($methods)) {
$this->methods = $methods;
}
return $this;
} | [
"public",
"function",
"setMethods",
"(",
"$",
"methods",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"methods",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"validMethods",
"[",
"strtolower",
"(",
"$",
"methods",
")",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Route method \"%s\" is invalid. Params expected \"%s\"'",
",",
"$",
"methods",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"self",
"::",
"$",
"validMethods",
")",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"methods",
"=",
"array",
"(",
"$",
"methods",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"methods",
")",
")",
"{",
"$",
"this",
"->",
"methods",
"=",
"$",
"methods",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set methods
@param string|array $methods
@return Route
@throws \LogicException | [
"Set",
"methods"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Server/Route.php#L161-L175 |
simple-php-mvc/simple-php-mvc | src/MVC/Server/Route.php | Route.setName | public function setName($name)
{
if (!is_string($name)) {
throw new \LogicException(sprintf('Route name given "%s" is invalid. String expected.', gettype($name)));
}
$this->name = $name;
return $this;
} | php | public function setName($name)
{
if (!is_string($name)) {
throw new \LogicException(sprintf('Route name given "%s" is invalid. String expected.', gettype($name)));
}
$this->name = $name;
return $this;
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Route name given \"%s\" is invalid. String expected.'",
",",
"gettype",
"(",
"$",
"name",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] | Set name
@param string $name
@return Route
@throws \LogicException | [
"Set",
"name"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Server/Route.php#L184-L192 |
simple-php-mvc/simple-php-mvc | src/MVC/Server/Route.php | Route.setPatternUri | public function setPatternUri($patternUri)
{
if (!is_string($patternUri)) {
throw new \LogicException(sprintf('Route pattern given "%s" is invalid. String expected.', gettype($patternUri)));
}
$this->patternUri = $patternUri;
return $this;
} | php | public function setPatternUri($patternUri)
{
if (!is_string($patternUri)) {
throw new \LogicException(sprintf('Route pattern given "%s" is invalid. String expected.', gettype($patternUri)));
}
$this->patternUri = $patternUri;
return $this;
} | [
"public",
"function",
"setPatternUri",
"(",
"$",
"patternUri",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"patternUri",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Route pattern given \"%s\" is invalid. String expected.'",
",",
"gettype",
"(",
"$",
"patternUri",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"patternUri",
"=",
"$",
"patternUri",
";",
"return",
"$",
"this",
";",
"}"
] | Set patternUri
@param string $patternUri
@return Route
@throws \LogicException | [
"Set",
"patternUri"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Server/Route.php#L201-L209 |
aalfiann/parallel-request-php | src/ParallelRequest.php | ParallelRequest.addRequest | public function addRequest($url,$params=array(),$formdata=true){
if(!empty($params)){
if ($formdata){
$this->request[] = [
'url' => $url,
'post' => $params
];
} else {
$this->request[] = $url.'?'.(!empty($params)?http_build_query($params,'','&'):'');
}
} else {
$this->request[] = $url;
}
return $this;
} | php | public function addRequest($url,$params=array(),$formdata=true){
if(!empty($params)){
if ($formdata){
$this->request[] = [
'url' => $url,
'post' => $params
];
} else {
$this->request[] = $url.'?'.(!empty($params)?http_build_query($params,'','&'):'');
}
} else {
$this->request[] = $url;
}
return $this;
} | [
"public",
"function",
"addRequest",
"(",
"$",
"url",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"formdata",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"if",
"(",
"$",
"formdata",
")",
"{",
"$",
"this",
"->",
"request",
"[",
"]",
"=",
"[",
"'url'",
"=>",
"$",
"url",
",",
"'post'",
"=>",
"$",
"params",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"request",
"[",
"]",
"=",
"$",
"url",
".",
"'?'",
".",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
"?",
"http_build_query",
"(",
"$",
"params",
",",
"''",
",",
"'&'",
")",
":",
"''",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"request",
"[",
"]",
"=",
"$",
"url",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add request
@param url = input the request url here (string only)
@param params = is the array parameter data to be send for the request (array). This is optional and default is empty.
@param formdata = if set to false then will convert params array to url parameter. Default is true means as form-data.
@return this | [
"Add",
"request"
] | train | https://github.com/aalfiann/parallel-request-php/blob/2b36485215b9004d0c12422b6f0afb0b9419d6c1/src/ParallelRequest.php#L32-L46 |
aalfiann/parallel-request-php | src/ParallelRequest.php | ParallelRequest.send | public function send() {
if(!extension_loaded('curl')) throw new Exception('CURL library not loaded!');
// cleanup any response
$this->response = array();
// array of curl handles
$curly = array();
// data to be returned
$result = array();
// multi handle
$mh = curl_multi_init();
// make sure request is array
if (is_string($this->request)) $this->request = array($this->request);
// loop through data request and create curl handles then add them to the multi-handle
foreach ($this->request as $id => $d) {
$curly[$id] = curl_init();
$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
curl_setopt($curly[$id], CURLOPT_URL, $url);
if ($this->httpStatusOnly) curl_setopt($curly[$id], CURLOPT_NOBODY, 1);
// contains data to post?
if (is_array($d)) {
if (!empty($d['post'])) {
curl_setopt($curly[$id], CURLOPT_POST, 1);
if ($this->encoded && is_array($d['post'])) {
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, http_build_query($d['post']));
} else {
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
}
}
}
// set options?
if (!empty($this->options)) {
curl_setopt_array($curly[$id], $this->options);
} else {
curl_setopt($curly[$id], CURLOPT_HEADER, 0);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
}
// activate curl response message
if($this->httpInfo === 'detail'){
if (empty($this->options[CURLOPT_FAILONERROR]) || (!empty($this->options[CURLOPT_FAILONERROR]) && $this->options[CURLOPT_FAILONERROR] == false)){
curl_setopt($curly[$id], CURLOPT_FAILONERROR, 1);
}
}
curl_multi_add_handle($mh, $curly[$id]);
}
// execute the handles
$running = null;
do {
$mrc =curl_multi_exec($mh, $running);
} while($mrc == CURLM_CALL_MULTI_PERFORM);
// perform multi select
while ($running && $mrc == CURLM_OK) {
if (curl_multi_select($mh) == -1) {
// delay time for cpu take a rest in every 10ms
usleep($this->delayTime);
}
do {
$mrc = curl_multi_exec($mh, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
// get content and remove handles
foreach($curly as $id => $c) {
if ($this->httpStatusOnly){
$result[$id] = curl_getinfo($c, CURLINFO_HTTP_CODE);
} else {
if ($this->httpInfo){
$curl_errno = curl_errno($c);
if($this->httpInfo === 'detail'){
$http_code = curl_getinfo($c, CURLINFO_HTTP_CODE);
$curl_error = curl_error($c);
$result[$id] = [
'code' => $http_code,
'info' => [
'url' => curl_getinfo($c, CURLINFO_EFFECTIVE_URL),
'content_type' => curl_getinfo($c, CURLINFO_CONTENT_TYPE),
'content_length' => curl_getinfo($c, CURLINFO_CONTENT_LENGTH_DOWNLOAD),
'total_time' => curl_getinfo($c, CURLINFO_TOTAL_TIME),
'debug' => 'CURLcode ['.$curl_errno.']: '.$this->getCurlCode($curl_errno),
'message' => (($curl_error)?$curl_error:(($http_code == 0)?'The requested URL returned error: Unknown':'Request URL finished'))
],
'response' => curl_multi_getcontent($c)
];
} else {
$result[$id] = [
'code' => curl_getinfo($c, CURLINFO_HTTP_CODE),
'debug' => $this->getCurlCode($curl_errno),
'response' => curl_multi_getcontent($c)
];
}
} else {
$result[$id] = curl_multi_getcontent($c);
}
}
curl_multi_remove_handle($mh, $c);
}
// close when all is done
curl_multi_close($mh);
if (count($result) <= 1) {
$this->response = $result[0];
} else {
$this->response = $result;
}
return $this;
} | php | public function send() {
if(!extension_loaded('curl')) throw new Exception('CURL library not loaded!');
// cleanup any response
$this->response = array();
// array of curl handles
$curly = array();
// data to be returned
$result = array();
// multi handle
$mh = curl_multi_init();
// make sure request is array
if (is_string($this->request)) $this->request = array($this->request);
// loop through data request and create curl handles then add them to the multi-handle
foreach ($this->request as $id => $d) {
$curly[$id] = curl_init();
$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
curl_setopt($curly[$id], CURLOPT_URL, $url);
if ($this->httpStatusOnly) curl_setopt($curly[$id], CURLOPT_NOBODY, 1);
// contains data to post?
if (is_array($d)) {
if (!empty($d['post'])) {
curl_setopt($curly[$id], CURLOPT_POST, 1);
if ($this->encoded && is_array($d['post'])) {
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, http_build_query($d['post']));
} else {
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
}
}
}
// set options?
if (!empty($this->options)) {
curl_setopt_array($curly[$id], $this->options);
} else {
curl_setopt($curly[$id], CURLOPT_HEADER, 0);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
}
// activate curl response message
if($this->httpInfo === 'detail'){
if (empty($this->options[CURLOPT_FAILONERROR]) || (!empty($this->options[CURLOPT_FAILONERROR]) && $this->options[CURLOPT_FAILONERROR] == false)){
curl_setopt($curly[$id], CURLOPT_FAILONERROR, 1);
}
}
curl_multi_add_handle($mh, $curly[$id]);
}
// execute the handles
$running = null;
do {
$mrc =curl_multi_exec($mh, $running);
} while($mrc == CURLM_CALL_MULTI_PERFORM);
// perform multi select
while ($running && $mrc == CURLM_OK) {
if (curl_multi_select($mh) == -1) {
// delay time for cpu take a rest in every 10ms
usleep($this->delayTime);
}
do {
$mrc = curl_multi_exec($mh, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
// get content and remove handles
foreach($curly as $id => $c) {
if ($this->httpStatusOnly){
$result[$id] = curl_getinfo($c, CURLINFO_HTTP_CODE);
} else {
if ($this->httpInfo){
$curl_errno = curl_errno($c);
if($this->httpInfo === 'detail'){
$http_code = curl_getinfo($c, CURLINFO_HTTP_CODE);
$curl_error = curl_error($c);
$result[$id] = [
'code' => $http_code,
'info' => [
'url' => curl_getinfo($c, CURLINFO_EFFECTIVE_URL),
'content_type' => curl_getinfo($c, CURLINFO_CONTENT_TYPE),
'content_length' => curl_getinfo($c, CURLINFO_CONTENT_LENGTH_DOWNLOAD),
'total_time' => curl_getinfo($c, CURLINFO_TOTAL_TIME),
'debug' => 'CURLcode ['.$curl_errno.']: '.$this->getCurlCode($curl_errno),
'message' => (($curl_error)?$curl_error:(($http_code == 0)?'The requested URL returned error: Unknown':'Request URL finished'))
],
'response' => curl_multi_getcontent($c)
];
} else {
$result[$id] = [
'code' => curl_getinfo($c, CURLINFO_HTTP_CODE),
'debug' => $this->getCurlCode($curl_errno),
'response' => curl_multi_getcontent($c)
];
}
} else {
$result[$id] = curl_multi_getcontent($c);
}
}
curl_multi_remove_handle($mh, $c);
}
// close when all is done
curl_multi_close($mh);
if (count($result) <= 1) {
$this->response = $result[0];
} else {
$this->response = $result;
}
return $this;
} | [
"public",
"function",
"send",
"(",
")",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"'curl'",
")",
")",
"throw",
"new",
"Exception",
"(",
"'CURL library not loaded!'",
")",
";",
"// cleanup any response",
"$",
"this",
"->",
"response",
"=",
"array",
"(",
")",
";",
"// array of curl handles",
"$",
"curly",
"=",
"array",
"(",
")",
";",
"// data to be returned",
"$",
"result",
"=",
"array",
"(",
")",
";",
"// multi handle",
"$",
"mh",
"=",
"curl_multi_init",
"(",
")",
";",
"// make sure request is array",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"request",
")",
")",
"$",
"this",
"->",
"request",
"=",
"array",
"(",
"$",
"this",
"->",
"request",
")",
";",
"// loop through data request and create curl handles then add them to the multi-handle",
"foreach",
"(",
"$",
"this",
"->",
"request",
"as",
"$",
"id",
"=>",
"$",
"d",
")",
"{",
"$",
"curly",
"[",
"$",
"id",
"]",
"=",
"curl_init",
"(",
")",
";",
"$",
"url",
"=",
"(",
"is_array",
"(",
"$",
"d",
")",
"&&",
"!",
"empty",
"(",
"$",
"d",
"[",
"'url'",
"]",
")",
")",
"?",
"$",
"d",
"[",
"'url'",
"]",
":",
"$",
"d",
";",
"curl_setopt",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"if",
"(",
"$",
"this",
"->",
"httpStatusOnly",
")",
"curl_setopt",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"CURLOPT_NOBODY",
",",
"1",
")",
";",
"// contains data to post?",
"if",
"(",
"is_array",
"(",
"$",
"d",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"d",
"[",
"'post'",
"]",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"CURLOPT_POST",
",",
"1",
")",
";",
"if",
"(",
"$",
"this",
"->",
"encoded",
"&&",
"is_array",
"(",
"$",
"d",
"[",
"'post'",
"]",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"CURLOPT_POSTFIELDS",
",",
"http_build_query",
"(",
"$",
"d",
"[",
"'post'",
"]",
")",
")",
";",
"}",
"else",
"{",
"curl_setopt",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"d",
"[",
"'post'",
"]",
")",
";",
"}",
"}",
"}",
"// set options?",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"options",
")",
")",
"{",
"curl_setopt_array",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"$",
"this",
"->",
"options",
")",
";",
"}",
"else",
"{",
"curl_setopt",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"CURLOPT_HEADER",
",",
"0",
")",
";",
"curl_setopt",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"}",
"// activate curl response message",
"if",
"(",
"$",
"this",
"->",
"httpInfo",
"===",
"'detail'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"options",
"[",
"CURLOPT_FAILONERROR",
"]",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"options",
"[",
"CURLOPT_FAILONERROR",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"CURLOPT_FAILONERROR",
"]",
"==",
"false",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"curly",
"[",
"$",
"id",
"]",
",",
"CURLOPT_FAILONERROR",
",",
"1",
")",
";",
"}",
"}",
"curl_multi_add_handle",
"(",
"$",
"mh",
",",
"$",
"curly",
"[",
"$",
"id",
"]",
")",
";",
"}",
"// execute the handles",
"$",
"running",
"=",
"null",
";",
"do",
"{",
"$",
"mrc",
"=",
"curl_multi_exec",
"(",
"$",
"mh",
",",
"$",
"running",
")",
";",
"}",
"while",
"(",
"$",
"mrc",
"==",
"CURLM_CALL_MULTI_PERFORM",
")",
";",
"// perform multi select",
"while",
"(",
"$",
"running",
"&&",
"$",
"mrc",
"==",
"CURLM_OK",
")",
"{",
"if",
"(",
"curl_multi_select",
"(",
"$",
"mh",
")",
"==",
"-",
"1",
")",
"{",
"// delay time for cpu take a rest in every 10ms",
"usleep",
"(",
"$",
"this",
"->",
"delayTime",
")",
";",
"}",
"do",
"{",
"$",
"mrc",
"=",
"curl_multi_exec",
"(",
"$",
"mh",
",",
"$",
"running",
")",
";",
"}",
"while",
"(",
"$",
"mrc",
"==",
"CURLM_CALL_MULTI_PERFORM",
")",
";",
"}",
"// get content and remove handles",
"foreach",
"(",
"$",
"curly",
"as",
"$",
"id",
"=>",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"httpStatusOnly",
")",
"{",
"$",
"result",
"[",
"$",
"id",
"]",
"=",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"httpInfo",
")",
"{",
"$",
"curl_errno",
"=",
"curl_errno",
"(",
"$",
"c",
")",
";",
"if",
"(",
"$",
"this",
"->",
"httpInfo",
"===",
"'detail'",
")",
"{",
"$",
"http_code",
"=",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"$",
"curl_error",
"=",
"curl_error",
"(",
"$",
"c",
")",
";",
"$",
"result",
"[",
"$",
"id",
"]",
"=",
"[",
"'code'",
"=>",
"$",
"http_code",
",",
"'info'",
"=>",
"[",
"'url'",
"=>",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_EFFECTIVE_URL",
")",
",",
"'content_type'",
"=>",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_CONTENT_TYPE",
")",
",",
"'content_length'",
"=>",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_CONTENT_LENGTH_DOWNLOAD",
")",
",",
"'total_time'",
"=>",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_TOTAL_TIME",
")",
",",
"'debug'",
"=>",
"'CURLcode ['",
".",
"$",
"curl_errno",
".",
"']: '",
".",
"$",
"this",
"->",
"getCurlCode",
"(",
"$",
"curl_errno",
")",
",",
"'message'",
"=>",
"(",
"(",
"$",
"curl_error",
")",
"?",
"$",
"curl_error",
":",
"(",
"(",
"$",
"http_code",
"==",
"0",
")",
"?",
"'The requested URL returned error: Unknown'",
":",
"'Request URL finished'",
")",
")",
"]",
",",
"'response'",
"=>",
"curl_multi_getcontent",
"(",
"$",
"c",
")",
"]",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"id",
"]",
"=",
"[",
"'code'",
"=>",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_HTTP_CODE",
")",
",",
"'debug'",
"=>",
"$",
"this",
"->",
"getCurlCode",
"(",
"$",
"curl_errno",
")",
",",
"'response'",
"=>",
"curl_multi_getcontent",
"(",
"$",
"c",
")",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"id",
"]",
"=",
"curl_multi_getcontent",
"(",
"$",
"c",
")",
";",
"}",
"}",
"curl_multi_remove_handle",
"(",
"$",
"mh",
",",
"$",
"c",
")",
";",
"}",
"// close when all is done",
"curl_multi_close",
"(",
"$",
"mh",
")",
";",
"if",
"(",
"count",
"(",
"$",
"result",
")",
"<=",
"1",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"$",
"result",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"response",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Send a parallel request with using curl_multi_exec
@return this for chaining purpose | [
"Send",
"a",
"parallel",
"request",
"with",
"using",
"curl_multi_exec"
] | train | https://github.com/aalfiann/parallel-request-php/blob/2b36485215b9004d0c12422b6f0afb0b9419d6c1/src/ParallelRequest.php#L116-L234 |
inblank/yii2-transliter | src/Transliter.php | Transliter.translate | public function translate($str, $spacer = null, $toLower = null)
{
if ($spacer === null) {
$spacer = $this->spacer;
}
if ($toLower === null) {
$toLower = $this->toLower;
}
$str = strtr($str, $this->table);
if (is_callable($this->after)) {
$str = call_user_func($this->after, $str);
}
// replace all non alpha-numeric characters
$str = preg_replace('~[^' . ($this->useDot ? '\.' : '') . '\s\w\d_\-]~uism', empty($this->replaceSpecial) ? '' : $this->replaceSpecial, $str);
// replace spaces
$str = preg_replace('/\s/u', $spacer, $str);
if ($toLower) {
$str = strtolower($str);
}
return $str;
} | php | public function translate($str, $spacer = null, $toLower = null)
{
if ($spacer === null) {
$spacer = $this->spacer;
}
if ($toLower === null) {
$toLower = $this->toLower;
}
$str = strtr($str, $this->table);
if (is_callable($this->after)) {
$str = call_user_func($this->after, $str);
}
// replace all non alpha-numeric characters
$str = preg_replace('~[^' . ($this->useDot ? '\.' : '') . '\s\w\d_\-]~uism', empty($this->replaceSpecial) ? '' : $this->replaceSpecial, $str);
// replace spaces
$str = preg_replace('/\s/u', $spacer, $str);
if ($toLower) {
$str = strtolower($str);
}
return $str;
} | [
"public",
"function",
"translate",
"(",
"$",
"str",
",",
"$",
"spacer",
"=",
"null",
",",
"$",
"toLower",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"spacer",
"===",
"null",
")",
"{",
"$",
"spacer",
"=",
"$",
"this",
"->",
"spacer",
";",
"}",
"if",
"(",
"$",
"toLower",
"===",
"null",
")",
"{",
"$",
"toLower",
"=",
"$",
"this",
"->",
"toLower",
";",
"}",
"$",
"str",
"=",
"strtr",
"(",
"$",
"str",
",",
"$",
"this",
"->",
"table",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"after",
")",
")",
"{",
"$",
"str",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"after",
",",
"$",
"str",
")",
";",
"}",
"// replace all non alpha-numeric characters",
"$",
"str",
"=",
"preg_replace",
"(",
"'~[^'",
".",
"(",
"$",
"this",
"->",
"useDot",
"?",
"'\\.'",
":",
"''",
")",
".",
"'\\s\\w\\d_\\-]~uism'",
",",
"empty",
"(",
"$",
"this",
"->",
"replaceSpecial",
")",
"?",
"''",
":",
"$",
"this",
"->",
"replaceSpecial",
",",
"$",
"str",
")",
";",
"// replace spaces",
"$",
"str",
"=",
"preg_replace",
"(",
"'/\\s/u'",
",",
"$",
"spacer",
",",
"$",
"str",
")",
";",
"if",
"(",
"$",
"toLower",
")",
"{",
"$",
"str",
"=",
"strtolower",
"(",
"$",
"str",
")",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Transliterate method
@param string $str input string
@param null|string $spacer space replacer. If null uses Transliter::$spacer
@param null|bool $toLower convert result to lowercase. If null uses Transliter::$toLower
@return string | [
"Transliterate",
"method"
] | train | https://github.com/inblank/yii2-transliter/blob/9b66651b533f940cc9f7c5d34518ec2222708c92/src/Transliter.php#L73-L93 |
slashworks/control-bundle | src/Slashworks/AppBundle/Command/ApiCommand.php | ApiCommand.configure | protected function configure()
{
// get systemname
$sAppName = SystemSettings::get('app_name');
// set cli options
$this->setName($sAppName . ':remote:cron')->addOption('app', null, InputOption::VALUE_REQUIRED, 'run only for specific remote app', false)->addOption('force', null, InputOption::VALUE_NONE, 'force to run remote app / ignore cron settings')->setDescription('Run/Crawl registered remote apps');
} | php | protected function configure()
{
// get systemname
$sAppName = SystemSettings::get('app_name');
// set cli options
$this->setName($sAppName . ':remote:cron')->addOption('app', null, InputOption::VALUE_REQUIRED, 'run only for specific remote app', false)->addOption('force', null, InputOption::VALUE_NONE, 'force to run remote app / ignore cron settings')->setDescription('Run/Crawl registered remote apps');
} | [
"protected",
"function",
"configure",
"(",
")",
"{",
"// get systemname",
"$",
"sAppName",
"=",
"SystemSettings",
"::",
"get",
"(",
"'app_name'",
")",
";",
"// set cli options",
"$",
"this",
"->",
"setName",
"(",
"$",
"sAppName",
".",
"':remote:cron'",
")",
"->",
"addOption",
"(",
"'app'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_REQUIRED",
",",
"'run only for specific remote app'",
",",
"false",
")",
"->",
"addOption",
"(",
"'force'",
",",
"null",
",",
"InputOption",
"::",
"VALUE_NONE",
",",
"'force to run remote app / ignore cron settings'",
")",
"->",
"setDescription",
"(",
"'Run/Crawl registered remote apps'",
")",
";",
"}"
] | configure cli command for making api calls | [
"configure",
"cli",
"command",
"for",
"making",
"api",
"calls"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Command/ApiCommand.php#L45-L53 |
slashworks/control-bundle | src/Slashworks/AppBundle/Command/ApiCommand.php | ApiCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
// define colors if verbose
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$oErrStyle = new OutputFormatterStyle('red', null, array('bold'));
$oOkStyle = new OutputFormatterStyle('green', null, array('bold'));
$oLogoStyle = new OutputFormatterStyle('cyan', null);
$output->getFormatter()->setStyle('err', $oErrStyle);
$output->getFormatter()->setStyle('ok', $oOkStyle);
$output->getFormatter()->setStyle('sw', $oLogoStyle);
}
}
// define colors if verbose
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$this->_printLogo($output);
}
}
$bForce = false;
$sAppId = $input->getOption('app');
if ($input->hasOption('force')) {
$bForce = ($input->getOption('force'));
}
// run command for single app?
if (!$sAppId) {
// Get active remote apps
$aRemoteApps = RemoteAppQuery::create()->findByActivated(true);
} else {
$oRemoteApp = RemoteAppQuery::create()->findOneById($sAppId);
$aRemoteApps = array($oRemoteApp);
}
$iCnt = 0;
$iStarttime = microtime(true);
// iterate through apps and run api call
foreach ($aRemoteApps as $oRemoteApp) {
// get cron string
$sCron = $oRemoteApp->getCron();
if (strlen($sCron) > 1) {
// parse cronstring and check time
$bRun = $this->_parseCrontab(date('d.m.Y H:i'), $oRemoteApp->getCron());
if ($bRun || $bForce) {
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$output->write(' ' . date('d.m.Y H:i') . ' <comment>Job:</comment> <fg=magenta>' . $oRemoteApp->getName() . '</fg=magenta> <comment>runnning...</comment>');
}
}
// make api call
$aResponse = $this->_makeCall($oRemoteApp);
// save response to database
$this->_saveResponse($aResponse, $oRemoteApp);
// print status if verbose
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$output->write("\t\t" . $this->_getStatus($aResponse['status']) . "\n");
}else {
$output->write(json_encode($aResponse));
}
}else {
$output->write(json_encode($aResponse));
}
$iCnt++;
} else {
// current app ignored because of cronsettings
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$output->write(' ' . date('d.m.Y H:i') . ' <fg=magenta>' . $oRemoteApp->getName() . "</fg=magenta> <comment>not running because of cron settings.</comment>\n");
}
}
}
}
}
// calculate elapsed time
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$iEndtime = microtime(true);
$iSeconds = round($iEndtime - $iStarttime);
$iMinutes = round($iSeconds / 60);
if ($iSeconds < 10) {
$iSeconds = '0' . $iSeconds;
}
$iHour = round($iMinutes / 60);
if ($iMinutes < 10) {
$iMinutes = '0' . $iMinutes;
}
if ($iHour < 10) {
$iHour = '0' . $iHour;
}
// green text
$output->writeln("\n<fg=white;options=bold> " . $iCnt . ' Job(s) done in ' . $iHour . ':' . $iMinutes . ':' . $iSeconds . "</fg=white;options=bold>\n");
}
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
// define colors if verbose
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$oErrStyle = new OutputFormatterStyle('red', null, array('bold'));
$oOkStyle = new OutputFormatterStyle('green', null, array('bold'));
$oLogoStyle = new OutputFormatterStyle('cyan', null);
$output->getFormatter()->setStyle('err', $oErrStyle);
$output->getFormatter()->setStyle('ok', $oOkStyle);
$output->getFormatter()->setStyle('sw', $oLogoStyle);
}
}
// define colors if verbose
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$this->_printLogo($output);
}
}
$bForce = false;
$sAppId = $input->getOption('app');
if ($input->hasOption('force')) {
$bForce = ($input->getOption('force'));
}
// run command for single app?
if (!$sAppId) {
// Get active remote apps
$aRemoteApps = RemoteAppQuery::create()->findByActivated(true);
} else {
$oRemoteApp = RemoteAppQuery::create()->findOneById($sAppId);
$aRemoteApps = array($oRemoteApp);
}
$iCnt = 0;
$iStarttime = microtime(true);
// iterate through apps and run api call
foreach ($aRemoteApps as $oRemoteApp) {
// get cron string
$sCron = $oRemoteApp->getCron();
if (strlen($sCron) > 1) {
// parse cronstring and check time
$bRun = $this->_parseCrontab(date('d.m.Y H:i'), $oRemoteApp->getCron());
if ($bRun || $bForce) {
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$output->write(' ' . date('d.m.Y H:i') . ' <comment>Job:</comment> <fg=magenta>' . $oRemoteApp->getName() . '</fg=magenta> <comment>runnning...</comment>');
}
}
// make api call
$aResponse = $this->_makeCall($oRemoteApp);
// save response to database
$this->_saveResponse($aResponse, $oRemoteApp);
// print status if verbose
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$output->write("\t\t" . $this->_getStatus($aResponse['status']) . "\n");
}else {
$output->write(json_encode($aResponse));
}
}else {
$output->write(json_encode($aResponse));
}
$iCnt++;
} else {
// current app ignored because of cronsettings
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$output->write(' ' . date('d.m.Y H:i') . ' <fg=magenta>' . $oRemoteApp->getName() . "</fg=magenta> <comment>not running because of cron settings.</comment>\n");
}
}
}
}
}
// calculate elapsed time
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$iEndtime = microtime(true);
$iSeconds = round($iEndtime - $iStarttime);
$iMinutes = round($iSeconds / 60);
if ($iSeconds < 10) {
$iSeconds = '0' . $iSeconds;
}
$iHour = round($iMinutes / 60);
if ($iMinutes < 10) {
$iMinutes = '0' . $iMinutes;
}
if ($iHour < 10) {
$iHour = '0' . $iHour;
}
// green text
$output->writeln("\n<fg=white;options=bold> " . $iCnt . ' Job(s) done in ' . $iHour . ':' . $iMinutes . ':' . $iSeconds . "</fg=white;options=bold>\n");
}
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"// define colors if verbose",
"if",
"(",
"$",
"input",
"->",
"hasOption",
"(",
"'verbose'",
")",
")",
"{",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'verbose'",
")",
")",
"{",
"$",
"oErrStyle",
"=",
"new",
"OutputFormatterStyle",
"(",
"'red'",
",",
"null",
",",
"array",
"(",
"'bold'",
")",
")",
";",
"$",
"oOkStyle",
"=",
"new",
"OutputFormatterStyle",
"(",
"'green'",
",",
"null",
",",
"array",
"(",
"'bold'",
")",
")",
";",
"$",
"oLogoStyle",
"=",
"new",
"OutputFormatterStyle",
"(",
"'cyan'",
",",
"null",
")",
";",
"$",
"output",
"->",
"getFormatter",
"(",
")",
"->",
"setStyle",
"(",
"'err'",
",",
"$",
"oErrStyle",
")",
";",
"$",
"output",
"->",
"getFormatter",
"(",
")",
"->",
"setStyle",
"(",
"'ok'",
",",
"$",
"oOkStyle",
")",
";",
"$",
"output",
"->",
"getFormatter",
"(",
")",
"->",
"setStyle",
"(",
"'sw'",
",",
"$",
"oLogoStyle",
")",
";",
"}",
"}",
"// define colors if verbose",
"if",
"(",
"$",
"input",
"->",
"hasOption",
"(",
"'verbose'",
")",
")",
"{",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'verbose'",
")",
")",
"{",
"$",
"this",
"->",
"_printLogo",
"(",
"$",
"output",
")",
";",
"}",
"}",
"$",
"bForce",
"=",
"false",
";",
"$",
"sAppId",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'app'",
")",
";",
"if",
"(",
"$",
"input",
"->",
"hasOption",
"(",
"'force'",
")",
")",
"{",
"$",
"bForce",
"=",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'force'",
")",
")",
";",
"}",
"// run command for single app?",
"if",
"(",
"!",
"$",
"sAppId",
")",
"{",
"// Get active remote apps",
"$",
"aRemoteApps",
"=",
"RemoteAppQuery",
"::",
"create",
"(",
")",
"->",
"findByActivated",
"(",
"true",
")",
";",
"}",
"else",
"{",
"$",
"oRemoteApp",
"=",
"RemoteAppQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"sAppId",
")",
";",
"$",
"aRemoteApps",
"=",
"array",
"(",
"$",
"oRemoteApp",
")",
";",
"}",
"$",
"iCnt",
"=",
"0",
";",
"$",
"iStarttime",
"=",
"microtime",
"(",
"true",
")",
";",
"// iterate through apps and run api call",
"foreach",
"(",
"$",
"aRemoteApps",
"as",
"$",
"oRemoteApp",
")",
"{",
"// get cron string",
"$",
"sCron",
"=",
"$",
"oRemoteApp",
"->",
"getCron",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"sCron",
")",
">",
"1",
")",
"{",
"// parse cronstring and check time",
"$",
"bRun",
"=",
"$",
"this",
"->",
"_parseCrontab",
"(",
"date",
"(",
"'d.m.Y H:i'",
")",
",",
"$",
"oRemoteApp",
"->",
"getCron",
"(",
")",
")",
";",
"if",
"(",
"$",
"bRun",
"||",
"$",
"bForce",
")",
"{",
"if",
"(",
"$",
"input",
"->",
"hasOption",
"(",
"'verbose'",
")",
")",
"{",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'verbose'",
")",
")",
"{",
"$",
"output",
"->",
"write",
"(",
"' '",
".",
"date",
"(",
"'d.m.Y H:i'",
")",
".",
"' <comment>Job:</comment> <fg=magenta>'",
".",
"$",
"oRemoteApp",
"->",
"getName",
"(",
")",
".",
"'</fg=magenta> <comment>runnning...</comment>'",
")",
";",
"}",
"}",
"// make api call",
"$",
"aResponse",
"=",
"$",
"this",
"->",
"_makeCall",
"(",
"$",
"oRemoteApp",
")",
";",
"// save response to database",
"$",
"this",
"->",
"_saveResponse",
"(",
"$",
"aResponse",
",",
"$",
"oRemoteApp",
")",
";",
"// print status if verbose",
"if",
"(",
"$",
"input",
"->",
"hasOption",
"(",
"'verbose'",
")",
")",
"{",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'verbose'",
")",
")",
"{",
"$",
"output",
"->",
"write",
"(",
"\"\\t\\t\"",
".",
"$",
"this",
"->",
"_getStatus",
"(",
"$",
"aResponse",
"[",
"'status'",
"]",
")",
".",
"\"\\n\"",
")",
";",
"}",
"else",
"{",
"$",
"output",
"->",
"write",
"(",
"json_encode",
"(",
"$",
"aResponse",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"output",
"->",
"write",
"(",
"json_encode",
"(",
"$",
"aResponse",
")",
")",
";",
"}",
"$",
"iCnt",
"++",
";",
"}",
"else",
"{",
"// current app ignored because of cronsettings",
"if",
"(",
"$",
"input",
"->",
"hasOption",
"(",
"'verbose'",
")",
")",
"{",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'verbose'",
")",
")",
"{",
"$",
"output",
"->",
"write",
"(",
"' '",
".",
"date",
"(",
"'d.m.Y H:i'",
")",
".",
"' <fg=magenta>'",
".",
"$",
"oRemoteApp",
"->",
"getName",
"(",
")",
".",
"\"</fg=magenta> <comment>not running because of cron settings.</comment>\\n\"",
")",
";",
"}",
"}",
"}",
"}",
"}",
"// calculate elapsed time",
"if",
"(",
"$",
"input",
"->",
"hasOption",
"(",
"'verbose'",
")",
")",
"{",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'verbose'",
")",
")",
"{",
"$",
"iEndtime",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"iSeconds",
"=",
"round",
"(",
"$",
"iEndtime",
"-",
"$",
"iStarttime",
")",
";",
"$",
"iMinutes",
"=",
"round",
"(",
"$",
"iSeconds",
"/",
"60",
")",
";",
"if",
"(",
"$",
"iSeconds",
"<",
"10",
")",
"{",
"$",
"iSeconds",
"=",
"'0'",
".",
"$",
"iSeconds",
";",
"}",
"$",
"iHour",
"=",
"round",
"(",
"$",
"iMinutes",
"/",
"60",
")",
";",
"if",
"(",
"$",
"iMinutes",
"<",
"10",
")",
"{",
"$",
"iMinutes",
"=",
"'0'",
".",
"$",
"iMinutes",
";",
"}",
"if",
"(",
"$",
"iHour",
"<",
"10",
")",
"{",
"$",
"iHour",
"=",
"'0'",
".",
"$",
"iHour",
";",
"}",
"// green text",
"$",
"output",
"->",
"writeln",
"(",
"\"\\n<fg=white;options=bold> \"",
".",
"$",
"iCnt",
".",
"' Job(s) done in '",
".",
"$",
"iHour",
".",
"':'",
".",
"$",
"iMinutes",
".",
"':'",
".",
"$",
"iSeconds",
".",
"\"</fg=white;options=bold>\\n\"",
")",
";",
"}",
"}",
"}"
] | execute api command
@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
@return void | [
"execute",
"api",
"command"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Command/ApiCommand.php#L64-L169 |
slashworks/control-bundle | src/Slashworks/AppBundle/Command/ApiCommand.php | ApiCommand._parseCrontab | private function _parseCrontab($sDatetime, $sCrontab)
{
$aTime = explode(' ', date('i G j n w', strtotime($sDatetime)));
$sCrontab = explode(' ', $sCrontab);
foreach ($sCrontab as $k => &$v) {
$v = explode(',', $v);
foreach ($v as &$v1) {
$v1 = preg_replace(array(
'/^\*$/',
'/^\d+$/',
'/^(\d+)\-(\d+)$/',
'/^\*\/(\d+)$/'
), array(
'true',
intval($aTime[$k]) . '===\0',
'(\1<=' . intval($aTime[$k]) . ' and ' . intval($aTime[$k]) . '<=\2)',
intval($aTime[$k]) . '%\1===0'
), $v1);
}
$v = '(' . implode(' or ', $v) . ')';
}
$sCrontab = implode(' and ', $sCrontab);
return eval('return ' . $sCrontab . ';');
} | php | private function _parseCrontab($sDatetime, $sCrontab)
{
$aTime = explode(' ', date('i G j n w', strtotime($sDatetime)));
$sCrontab = explode(' ', $sCrontab);
foreach ($sCrontab as $k => &$v) {
$v = explode(',', $v);
foreach ($v as &$v1) {
$v1 = preg_replace(array(
'/^\*$/',
'/^\d+$/',
'/^(\d+)\-(\d+)$/',
'/^\*\/(\d+)$/'
), array(
'true',
intval($aTime[$k]) . '===\0',
'(\1<=' . intval($aTime[$k]) . ' and ' . intval($aTime[$k]) . '<=\2)',
intval($aTime[$k]) . '%\1===0'
), $v1);
}
$v = '(' . implode(' or ', $v) . ')';
}
$sCrontab = implode(' and ', $sCrontab);
return eval('return ' . $sCrontab . ';');
} | [
"private",
"function",
"_parseCrontab",
"(",
"$",
"sDatetime",
",",
"$",
"sCrontab",
")",
"{",
"$",
"aTime",
"=",
"explode",
"(",
"' '",
",",
"date",
"(",
"'i G j n w'",
",",
"strtotime",
"(",
"$",
"sDatetime",
")",
")",
")",
";",
"$",
"sCrontab",
"=",
"explode",
"(",
"' '",
",",
"$",
"sCrontab",
")",
";",
"foreach",
"(",
"$",
"sCrontab",
"as",
"$",
"k",
"=>",
"&",
"$",
"v",
")",
"{",
"$",
"v",
"=",
"explode",
"(",
"','",
",",
"$",
"v",
")",
";",
"foreach",
"(",
"$",
"v",
"as",
"&",
"$",
"v1",
")",
"{",
"$",
"v1",
"=",
"preg_replace",
"(",
"array",
"(",
"'/^\\*$/'",
",",
"'/^\\d+$/'",
",",
"'/^(\\d+)\\-(\\d+)$/'",
",",
"'/^\\*\\/(\\d+)$/'",
")",
",",
"array",
"(",
"'true'",
",",
"intval",
"(",
"$",
"aTime",
"[",
"$",
"k",
"]",
")",
".",
"'===\\0'",
",",
"'(\\1<='",
".",
"intval",
"(",
"$",
"aTime",
"[",
"$",
"k",
"]",
")",
".",
"' and '",
".",
"intval",
"(",
"$",
"aTime",
"[",
"$",
"k",
"]",
")",
".",
"'<=\\2)'",
",",
"intval",
"(",
"$",
"aTime",
"[",
"$",
"k",
"]",
")",
".",
"'%\\1===0'",
")",
",",
"$",
"v1",
")",
";",
"}",
"$",
"v",
"=",
"'('",
".",
"implode",
"(",
"' or '",
",",
"$",
"v",
")",
".",
"')'",
";",
"}",
"$",
"sCrontab",
"=",
"implode",
"(",
"' and '",
",",
"$",
"sCrontab",
")",
";",
"return",
"eval",
"(",
"'return '",
".",
"$",
"sCrontab",
".",
"';'",
")",
";",
"}"
] | Parse cron time string
@param $sDatetime
@param $sCrontab
@return mixed | [
"Parse",
"cron",
"time",
"string"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Command/ApiCommand.php#L180-L205 |
slashworks/control-bundle | src/Slashworks/AppBundle/Command/ApiCommand.php | ApiCommand._makeCall | private function _makeCall($oRemoteApp)
{
// get class
$this->getContainer()->get('API');
// do call
Api::$_container = $this->getContainer();
$aReturn = Api::call('getData', array(
array(
'log' => $oRemoteApp->getIncludelog(),
'format' => 'json'
)
), $oRemoteApp->getFullApiUrl(), $oRemoteApp->getPublicKey(), $oRemoteApp);
// build json response
$sStatuscode = $aReturn['statuscode'];
$aReturn = json_decode($aReturn['result'], true);
if (!isset($aReturn['status'])) {
$aReturn['status'] = true;
}
$aReturn['statuscode'] = $sStatuscode;
if($sStatuscode != 200) {
$this->getContainer()->get('logger')->error("ERROR in ".__FILE__." on line ".__LINE__." - ".json_encode($aReturn), array("Method" => __METHOD__,
"RemoteApp" => $oRemoteApp->getName(),
"RemoteURL" => $oRemoteApp->getFullApiUrl()
));
}
return $aReturn;
} | php | private function _makeCall($oRemoteApp)
{
// get class
$this->getContainer()->get('API');
// do call
Api::$_container = $this->getContainer();
$aReturn = Api::call('getData', array(
array(
'log' => $oRemoteApp->getIncludelog(),
'format' => 'json'
)
), $oRemoteApp->getFullApiUrl(), $oRemoteApp->getPublicKey(), $oRemoteApp);
// build json response
$sStatuscode = $aReturn['statuscode'];
$aReturn = json_decode($aReturn['result'], true);
if (!isset($aReturn['status'])) {
$aReturn['status'] = true;
}
$aReturn['statuscode'] = $sStatuscode;
if($sStatuscode != 200) {
$this->getContainer()->get('logger')->error("ERROR in ".__FILE__." on line ".__LINE__." - ".json_encode($aReturn), array("Method" => __METHOD__,
"RemoteApp" => $oRemoteApp->getName(),
"RemoteURL" => $oRemoteApp->getFullApiUrl()
));
}
return $aReturn;
} | [
"private",
"function",
"_makeCall",
"(",
"$",
"oRemoteApp",
")",
"{",
"// get class",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'API'",
")",
";",
"// do call",
"Api",
"::",
"$",
"_container",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
";",
"$",
"aReturn",
"=",
"Api",
"::",
"call",
"(",
"'getData'",
",",
"array",
"(",
"array",
"(",
"'log'",
"=>",
"$",
"oRemoteApp",
"->",
"getIncludelog",
"(",
")",
",",
"'format'",
"=>",
"'json'",
")",
")",
",",
"$",
"oRemoteApp",
"->",
"getFullApiUrl",
"(",
")",
",",
"$",
"oRemoteApp",
"->",
"getPublicKey",
"(",
")",
",",
"$",
"oRemoteApp",
")",
";",
"// build json response",
"$",
"sStatuscode",
"=",
"$",
"aReturn",
"[",
"'statuscode'",
"]",
";",
"$",
"aReturn",
"=",
"json_decode",
"(",
"$",
"aReturn",
"[",
"'result'",
"]",
",",
"true",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"aReturn",
"[",
"'status'",
"]",
")",
")",
"{",
"$",
"aReturn",
"[",
"'status'",
"]",
"=",
"true",
";",
"}",
"$",
"aReturn",
"[",
"'statuscode'",
"]",
"=",
"$",
"sStatuscode",
";",
"if",
"(",
"$",
"sStatuscode",
"!=",
"200",
")",
"{",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'logger'",
")",
"->",
"error",
"(",
"\"ERROR in \"",
".",
"__FILE__",
".",
"\" on line \"",
".",
"__LINE__",
".",
"\" - \"",
".",
"json_encode",
"(",
"$",
"aReturn",
")",
",",
"array",
"(",
"\"Method\"",
"=>",
"__METHOD__",
",",
"\"RemoteApp\"",
"=>",
"$",
"oRemoteApp",
"->",
"getName",
"(",
")",
",",
"\"RemoteURL\"",
"=>",
"$",
"oRemoteApp",
"->",
"getFullApiUrl",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"aReturn",
";",
"}"
] | perform api call
@param RemoteApp $oRemoteApp
@return mixed | [
"perform",
"api",
"call"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Command/ApiCommand.php#L215-L245 |
slashworks/control-bundle | src/Slashworks/AppBundle/Command/ApiCommand.php | ApiCommand._saveResponse | private function _saveResponse($aResponse, $oRemoteApp)
{
// get model by app-type
$sClassName = '\Slashworks\AppBundle\Model\RemoteHistory' . ucfirst($oRemoteApp->getType());
$sQueryClassName = '\Slashworks\AppBundle\Model\RemoteHistory' . ucfirst($oRemoteApp->getType() . 'Query');
// if class exists, proceed...
if (class_exists($sClassName)) {
// find histories for remote-app
$aHistories = $sQueryClassName::create()->findByRemoteAppId($oRemoteApp->getId());
// create new history-entry
$oRemoteHistoryClass = new $sClassName();
$oRemoteHistoryClass->setRemoteApp($oRemoteApp);
$oRemoteHistoryClass->setData($aResponse);
// convert created class to array for comparsion
$aNewHistory = $oRemoteHistoryClass->toArray();
$aNewHistory['Extensions'] = $aNewHistory['Extensions']->getArrayCopy();
if (is_object($aNewHistory['Log'])) {
$aNewHistory['Log'] = $aNewHistory['Log']->getArrayCopy();
} else {
$aNewHistory['Log'] = array();
}
unset($aNewHistory['Id']);
// interate old histories and convert to array for comparsion
foreach ($aHistories as $oHistory) {
$aHistory = $oHistory->toArray();
$aHistory['Extensions'] = $aHistory['Extensions']->getArrayCopy();
if (is_object($aHistory['Log'])) {
$aHistory['Log'] = $aHistory['Log']->getArrayCopy();
} else {
$aHistory['Log'] = array();
}
unset($aHistory['Id']);
// if api-call was not successful, send notifiations if configured
if ($aResponse['statuscode'] != 200) {
if ($oRemoteApp->checkNotificationSetting("NotificationError")) {
$this->_sendErrorNotification($oRemoteApp, $aResponse);
}
} else {
// if api-call was successful, compare old and new history and send differences to user
$aNew = $this->arrayRecursiveDiff($aNewHistory, $aHistory);
// diff exists?
if (!empty($aNew) && $oRemoteApp->checkNotificationSetting("NotificationChange")) {
$aOld = $this->arrayRecursiveDiff($aHistory, $aNewHistory);
$this->_sendNotification(array(
'old' => $aOld,
'new' => $aNew
), $oRemoteApp, $aNewHistory);
}
}
// delete old history
$oHistory->delete();
}
// save created history
$oRemoteHistoryClass->save();
$oRemoteApp->setLastRun(time());
$oRemoteApp->save();
} else {
$this->getContainer()->get('logger')->error('Class \'' . $sClassName . '\' not found... ', array("Method" => __METHOD__,
"RemoteApp" => $oRemoteApp->getName(),
"RemoteURL" => $oRemoteApp->getFullApiUrl()
));
throw new \Exception('Class \'' . $sClassName . '\' not found... ');
}
} | php | private function _saveResponse($aResponse, $oRemoteApp)
{
// get model by app-type
$sClassName = '\Slashworks\AppBundle\Model\RemoteHistory' . ucfirst($oRemoteApp->getType());
$sQueryClassName = '\Slashworks\AppBundle\Model\RemoteHistory' . ucfirst($oRemoteApp->getType() . 'Query');
// if class exists, proceed...
if (class_exists($sClassName)) {
// find histories for remote-app
$aHistories = $sQueryClassName::create()->findByRemoteAppId($oRemoteApp->getId());
// create new history-entry
$oRemoteHistoryClass = new $sClassName();
$oRemoteHistoryClass->setRemoteApp($oRemoteApp);
$oRemoteHistoryClass->setData($aResponse);
// convert created class to array for comparsion
$aNewHistory = $oRemoteHistoryClass->toArray();
$aNewHistory['Extensions'] = $aNewHistory['Extensions']->getArrayCopy();
if (is_object($aNewHistory['Log'])) {
$aNewHistory['Log'] = $aNewHistory['Log']->getArrayCopy();
} else {
$aNewHistory['Log'] = array();
}
unset($aNewHistory['Id']);
// interate old histories and convert to array for comparsion
foreach ($aHistories as $oHistory) {
$aHistory = $oHistory->toArray();
$aHistory['Extensions'] = $aHistory['Extensions']->getArrayCopy();
if (is_object($aHistory['Log'])) {
$aHistory['Log'] = $aHistory['Log']->getArrayCopy();
} else {
$aHistory['Log'] = array();
}
unset($aHistory['Id']);
// if api-call was not successful, send notifiations if configured
if ($aResponse['statuscode'] != 200) {
if ($oRemoteApp->checkNotificationSetting("NotificationError")) {
$this->_sendErrorNotification($oRemoteApp, $aResponse);
}
} else {
// if api-call was successful, compare old and new history and send differences to user
$aNew = $this->arrayRecursiveDiff($aNewHistory, $aHistory);
// diff exists?
if (!empty($aNew) && $oRemoteApp->checkNotificationSetting("NotificationChange")) {
$aOld = $this->arrayRecursiveDiff($aHistory, $aNewHistory);
$this->_sendNotification(array(
'old' => $aOld,
'new' => $aNew
), $oRemoteApp, $aNewHistory);
}
}
// delete old history
$oHistory->delete();
}
// save created history
$oRemoteHistoryClass->save();
$oRemoteApp->setLastRun(time());
$oRemoteApp->save();
} else {
$this->getContainer()->get('logger')->error('Class \'' . $sClassName . '\' not found... ', array("Method" => __METHOD__,
"RemoteApp" => $oRemoteApp->getName(),
"RemoteURL" => $oRemoteApp->getFullApiUrl()
));
throw new \Exception('Class \'' . $sClassName . '\' not found... ');
}
} | [
"private",
"function",
"_saveResponse",
"(",
"$",
"aResponse",
",",
"$",
"oRemoteApp",
")",
"{",
"// get model by app-type",
"$",
"sClassName",
"=",
"'\\Slashworks\\AppBundle\\Model\\RemoteHistory'",
".",
"ucfirst",
"(",
"$",
"oRemoteApp",
"->",
"getType",
"(",
")",
")",
";",
"$",
"sQueryClassName",
"=",
"'\\Slashworks\\AppBundle\\Model\\RemoteHistory'",
".",
"ucfirst",
"(",
"$",
"oRemoteApp",
"->",
"getType",
"(",
")",
".",
"'Query'",
")",
";",
"// if class exists, proceed...",
"if",
"(",
"class_exists",
"(",
"$",
"sClassName",
")",
")",
"{",
"// find histories for remote-app",
"$",
"aHistories",
"=",
"$",
"sQueryClassName",
"::",
"create",
"(",
")",
"->",
"findByRemoteAppId",
"(",
"$",
"oRemoteApp",
"->",
"getId",
"(",
")",
")",
";",
"// create new history-entry",
"$",
"oRemoteHistoryClass",
"=",
"new",
"$",
"sClassName",
"(",
")",
";",
"$",
"oRemoteHistoryClass",
"->",
"setRemoteApp",
"(",
"$",
"oRemoteApp",
")",
";",
"$",
"oRemoteHistoryClass",
"->",
"setData",
"(",
"$",
"aResponse",
")",
";",
"// convert created class to array for comparsion",
"$",
"aNewHistory",
"=",
"$",
"oRemoteHistoryClass",
"->",
"toArray",
"(",
")",
";",
"$",
"aNewHistory",
"[",
"'Extensions'",
"]",
"=",
"$",
"aNewHistory",
"[",
"'Extensions'",
"]",
"->",
"getArrayCopy",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"aNewHistory",
"[",
"'Log'",
"]",
")",
")",
"{",
"$",
"aNewHistory",
"[",
"'Log'",
"]",
"=",
"$",
"aNewHistory",
"[",
"'Log'",
"]",
"->",
"getArrayCopy",
"(",
")",
";",
"}",
"else",
"{",
"$",
"aNewHistory",
"[",
"'Log'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"aNewHistory",
"[",
"'Id'",
"]",
")",
";",
"// interate old histories and convert to array for comparsion",
"foreach",
"(",
"$",
"aHistories",
"as",
"$",
"oHistory",
")",
"{",
"$",
"aHistory",
"=",
"$",
"oHistory",
"->",
"toArray",
"(",
")",
";",
"$",
"aHistory",
"[",
"'Extensions'",
"]",
"=",
"$",
"aHistory",
"[",
"'Extensions'",
"]",
"->",
"getArrayCopy",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"aHistory",
"[",
"'Log'",
"]",
")",
")",
"{",
"$",
"aHistory",
"[",
"'Log'",
"]",
"=",
"$",
"aHistory",
"[",
"'Log'",
"]",
"->",
"getArrayCopy",
"(",
")",
";",
"}",
"else",
"{",
"$",
"aHistory",
"[",
"'Log'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"aHistory",
"[",
"'Id'",
"]",
")",
";",
"// if api-call was not successful, send notifiations if configured",
"if",
"(",
"$",
"aResponse",
"[",
"'statuscode'",
"]",
"!=",
"200",
")",
"{",
"if",
"(",
"$",
"oRemoteApp",
"->",
"checkNotificationSetting",
"(",
"\"NotificationError\"",
")",
")",
"{",
"$",
"this",
"->",
"_sendErrorNotification",
"(",
"$",
"oRemoteApp",
",",
"$",
"aResponse",
")",
";",
"}",
"}",
"else",
"{",
"// if api-call was successful, compare old and new history and send differences to user",
"$",
"aNew",
"=",
"$",
"this",
"->",
"arrayRecursiveDiff",
"(",
"$",
"aNewHistory",
",",
"$",
"aHistory",
")",
";",
"// diff exists?",
"if",
"(",
"!",
"empty",
"(",
"$",
"aNew",
")",
"&&",
"$",
"oRemoteApp",
"->",
"checkNotificationSetting",
"(",
"\"NotificationChange\"",
")",
")",
"{",
"$",
"aOld",
"=",
"$",
"this",
"->",
"arrayRecursiveDiff",
"(",
"$",
"aHistory",
",",
"$",
"aNewHistory",
")",
";",
"$",
"this",
"->",
"_sendNotification",
"(",
"array",
"(",
"'old'",
"=>",
"$",
"aOld",
",",
"'new'",
"=>",
"$",
"aNew",
")",
",",
"$",
"oRemoteApp",
",",
"$",
"aNewHistory",
")",
";",
"}",
"}",
"// delete old history",
"$",
"oHistory",
"->",
"delete",
"(",
")",
";",
"}",
"// save created history",
"$",
"oRemoteHistoryClass",
"->",
"save",
"(",
")",
";",
"$",
"oRemoteApp",
"->",
"setLastRun",
"(",
"time",
"(",
")",
")",
";",
"$",
"oRemoteApp",
"->",
"save",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'logger'",
")",
"->",
"error",
"(",
"'Class \\''",
".",
"$",
"sClassName",
".",
"'\\' not found... '",
",",
"array",
"(",
"\"Method\"",
"=>",
"__METHOD__",
",",
"\"RemoteApp\"",
"=>",
"$",
"oRemoteApp",
"->",
"getName",
"(",
")",
",",
"\"RemoteURL\"",
"=>",
"$",
"oRemoteApp",
"->",
"getFullApiUrl",
"(",
")",
")",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"'Class \\''",
".",
"$",
"sClassName",
".",
"'\\' not found... '",
")",
";",
"}",
"}"
] | Save response to database
@param array $aResponse
@param RemoteApp $oRemoteApp
@throws \Exception
@return void | [
"Save",
"response",
"to",
"database"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Command/ApiCommand.php#L258-L331 |
slashworks/control-bundle | src/Slashworks/AppBundle/Command/ApiCommand.php | ApiCommand._sendErrorNotification | private function _sendErrorNotification(&$oRemoteApp, $aResponse)
{
$iStatusCode = $aResponse['statuscode'];
/*
* Parse template by statuscode
*/
if ($iStatusCode === 404) {
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_error_404_notification.html.twig', array(
'remote_app' => $oRemoteApp,
'response' => $aResponse,
'controlurl' => $this->_getSiteURL()
));
} elseif ($iStatusCode === 500) {
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_error_500_notification.html.twig', array(
'remote_app' => $oRemoteApp,
'response' => $aResponse,
'controlurl' => $this->_getSiteURL()
));
} elseif ($iStatusCode === 403) {
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_error_403_notification.html.twig', array(
'remote_app' => $oRemoteApp,
'response' => $aResponse,
'controlurl' => $this->_getSiteURL()
));
} else {
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_error_notification.html.twig', array(
'remote_app' => $oRemoteApp,
'response' => $aResponse,
'controlurl' => $this->_getSiteURL()
));
}
// translate Subject
$sSubject = $this->getContainer()->get('translator')->trans('system.email.error.' . $iStatusCode . '.subject');
// get recipients and sender
$sRecipient = $oRemoteApp->getNotificationRecipient();
$sSender = $oRemoteApp->getNotificationSender();
$sMessage = \Swift_Message::newInstance()->setSubject($sSubject)->setFrom($sSender)->setTo($sRecipient)->setContentType('text/html')->setBody($sHtml, 'text/html')->addPart($sHtml, 'text/html');
// send notification
$this->getContainer()->get('mailer')->send($sMessage);
} | php | private function _sendErrorNotification(&$oRemoteApp, $aResponse)
{
$iStatusCode = $aResponse['statuscode'];
/*
* Parse template by statuscode
*/
if ($iStatusCode === 404) {
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_error_404_notification.html.twig', array(
'remote_app' => $oRemoteApp,
'response' => $aResponse,
'controlurl' => $this->_getSiteURL()
));
} elseif ($iStatusCode === 500) {
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_error_500_notification.html.twig', array(
'remote_app' => $oRemoteApp,
'response' => $aResponse,
'controlurl' => $this->_getSiteURL()
));
} elseif ($iStatusCode === 403) {
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_error_403_notification.html.twig', array(
'remote_app' => $oRemoteApp,
'response' => $aResponse,
'controlurl' => $this->_getSiteURL()
));
} else {
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_error_notification.html.twig', array(
'remote_app' => $oRemoteApp,
'response' => $aResponse,
'controlurl' => $this->_getSiteURL()
));
}
// translate Subject
$sSubject = $this->getContainer()->get('translator')->trans('system.email.error.' . $iStatusCode . '.subject');
// get recipients and sender
$sRecipient = $oRemoteApp->getNotificationRecipient();
$sSender = $oRemoteApp->getNotificationSender();
$sMessage = \Swift_Message::newInstance()->setSubject($sSubject)->setFrom($sSender)->setTo($sRecipient)->setContentType('text/html')->setBody($sHtml, 'text/html')->addPart($sHtml, 'text/html');
// send notification
$this->getContainer()->get('mailer')->send($sMessage);
} | [
"private",
"function",
"_sendErrorNotification",
"(",
"&",
"$",
"oRemoteApp",
",",
"$",
"aResponse",
")",
"{",
"$",
"iStatusCode",
"=",
"$",
"aResponse",
"[",
"'statuscode'",
"]",
";",
"/*\n * Parse template by statuscode\n */",
"if",
"(",
"$",
"iStatusCode",
"===",
"404",
")",
"{",
"$",
"sHtml",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'templating'",
")",
"->",
"render",
"(",
"'SlashworksAppBundle:Email:cron_error_404_notification.html.twig'",
",",
"array",
"(",
"'remote_app'",
"=>",
"$",
"oRemoteApp",
",",
"'response'",
"=>",
"$",
"aResponse",
",",
"'controlurl'",
"=>",
"$",
"this",
"->",
"_getSiteURL",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"iStatusCode",
"===",
"500",
")",
"{",
"$",
"sHtml",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'templating'",
")",
"->",
"render",
"(",
"'SlashworksAppBundle:Email:cron_error_500_notification.html.twig'",
",",
"array",
"(",
"'remote_app'",
"=>",
"$",
"oRemoteApp",
",",
"'response'",
"=>",
"$",
"aResponse",
",",
"'controlurl'",
"=>",
"$",
"this",
"->",
"_getSiteURL",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"iStatusCode",
"===",
"403",
")",
"{",
"$",
"sHtml",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'templating'",
")",
"->",
"render",
"(",
"'SlashworksAppBundle:Email:cron_error_403_notification.html.twig'",
",",
"array",
"(",
"'remote_app'",
"=>",
"$",
"oRemoteApp",
",",
"'response'",
"=>",
"$",
"aResponse",
",",
"'controlurl'",
"=>",
"$",
"this",
"->",
"_getSiteURL",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"sHtml",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'templating'",
")",
"->",
"render",
"(",
"'SlashworksAppBundle:Email:cron_error_notification.html.twig'",
",",
"array",
"(",
"'remote_app'",
"=>",
"$",
"oRemoteApp",
",",
"'response'",
"=>",
"$",
"aResponse",
",",
"'controlurl'",
"=>",
"$",
"this",
"->",
"_getSiteURL",
"(",
")",
")",
")",
";",
"}",
"// translate Subject",
"$",
"sSubject",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'system.email.error.'",
".",
"$",
"iStatusCode",
".",
"'.subject'",
")",
";",
"// get recipients and sender",
"$",
"sRecipient",
"=",
"$",
"oRemoteApp",
"->",
"getNotificationRecipient",
"(",
")",
";",
"$",
"sSender",
"=",
"$",
"oRemoteApp",
"->",
"getNotificationSender",
"(",
")",
";",
"$",
"sMessage",
"=",
"\\",
"Swift_Message",
"::",
"newInstance",
"(",
")",
"->",
"setSubject",
"(",
"$",
"sSubject",
")",
"->",
"setFrom",
"(",
"$",
"sSender",
")",
"->",
"setTo",
"(",
"$",
"sRecipient",
")",
"->",
"setContentType",
"(",
"'text/html'",
")",
"->",
"setBody",
"(",
"$",
"sHtml",
",",
"'text/html'",
")",
"->",
"addPart",
"(",
"$",
"sHtml",
",",
"'text/html'",
")",
";",
"// send notification",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mailer'",
")",
"->",
"send",
"(",
"$",
"sMessage",
")",
";",
"}"
] | Send Error-Notification to user
@param $oRemoteApp
@param $aResponse | [
"Send",
"Error",
"-",
"Notification",
"to",
"user"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Command/ApiCommand.php#L340-L383 |
slashworks/control-bundle | src/Slashworks/AppBundle/Command/ApiCommand.php | ApiCommand._sendNotification | private function _sendNotification($aDiff, &$oRemoteApp, $aNewHistory)
{
// parse template
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_notification.html.twig', array(
'diff' => $aDiff,
'log' => $aNewHistory['Log'],
'remote_app' => $oRemoteApp,
'controlurl' => $this->_getSiteURL()
));
// get recipients
$sRecipient = $oRemoteApp->getNotificationRecipient();
// get sender
$sSender = $oRemoteApp->getNotificationSender();
// set subject and body of mail
$sMessage = \Swift_Message::newInstance()->setSubject($this->getContainer()->get('translator')->trans('system.email.change.subject'))->setFrom($sSender)->setTo($sRecipient)->setContentType('text/html')->setBody($sHtml, 'text/html')->addPart($sHtml, 'text/html');
// send email
$this->getContainer()->get('mailer')->send($sMessage);
} | php | private function _sendNotification($aDiff, &$oRemoteApp, $aNewHistory)
{
// parse template
$sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_notification.html.twig', array(
'diff' => $aDiff,
'log' => $aNewHistory['Log'],
'remote_app' => $oRemoteApp,
'controlurl' => $this->_getSiteURL()
));
// get recipients
$sRecipient = $oRemoteApp->getNotificationRecipient();
// get sender
$sSender = $oRemoteApp->getNotificationSender();
// set subject and body of mail
$sMessage = \Swift_Message::newInstance()->setSubject($this->getContainer()->get('translator')->trans('system.email.change.subject'))->setFrom($sSender)->setTo($sRecipient)->setContentType('text/html')->setBody($sHtml, 'text/html')->addPart($sHtml, 'text/html');
// send email
$this->getContainer()->get('mailer')->send($sMessage);
} | [
"private",
"function",
"_sendNotification",
"(",
"$",
"aDiff",
",",
"&",
"$",
"oRemoteApp",
",",
"$",
"aNewHistory",
")",
"{",
"// parse template",
"$",
"sHtml",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'templating'",
")",
"->",
"render",
"(",
"'SlashworksAppBundle:Email:cron_notification.html.twig'",
",",
"array",
"(",
"'diff'",
"=>",
"$",
"aDiff",
",",
"'log'",
"=>",
"$",
"aNewHistory",
"[",
"'Log'",
"]",
",",
"'remote_app'",
"=>",
"$",
"oRemoteApp",
",",
"'controlurl'",
"=>",
"$",
"this",
"->",
"_getSiteURL",
"(",
")",
")",
")",
";",
"// get recipients",
"$",
"sRecipient",
"=",
"$",
"oRemoteApp",
"->",
"getNotificationRecipient",
"(",
")",
";",
"// get sender",
"$",
"sSender",
"=",
"$",
"oRemoteApp",
"->",
"getNotificationSender",
"(",
")",
";",
"// set subject and body of mail",
"$",
"sMessage",
"=",
"\\",
"Swift_Message",
"::",
"newInstance",
"(",
")",
"->",
"setSubject",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'system.email.change.subject'",
")",
")",
"->",
"setFrom",
"(",
"$",
"sSender",
")",
"->",
"setTo",
"(",
"$",
"sRecipient",
")",
"->",
"setContentType",
"(",
"'text/html'",
")",
"->",
"setBody",
"(",
"$",
"sHtml",
",",
"'text/html'",
")",
"->",
"addPart",
"(",
"$",
"sHtml",
",",
"'text/html'",
")",
";",
"// send email",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mailer'",
")",
"->",
"send",
"(",
"$",
"sMessage",
")",
";",
"}"
] | Send Notification to user
@param array $aDiff
@param RemoteApp $oRemoteApp
@param RemoteHistoryContao $aNewHistory
@return void | [
"Send",
"Notification",
"to",
"user"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Command/ApiCommand.php#L395-L416 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Section/MemoryImage.php | PHPWord_Section_MemoryImage._setFunctions | private function _setFunctions() {
switch($this->_imageType) {
case 'image/png':
$this->_imageCreateFunc = 'imagecreatefrompng';
$this->_imageFunc = 'imagepng';
$this->_imageExtension = 'png';
break;
case 'image/gif':
$this->_imageCreateFunc = 'imagecreatefromgif';
$this->_imageFunc = 'imagegif';
$this->_imageExtension = 'gif';
break;
case 'image/jpeg': case 'image/jpg':
$this->_imageCreateFunc = 'imagecreatefromjpeg';
$this->_imageFunc = 'imagejpeg';
$this->_imageExtension = 'jpg';
break;
}
} | php | private function _setFunctions() {
switch($this->_imageType) {
case 'image/png':
$this->_imageCreateFunc = 'imagecreatefrompng';
$this->_imageFunc = 'imagepng';
$this->_imageExtension = 'png';
break;
case 'image/gif':
$this->_imageCreateFunc = 'imagecreatefromgif';
$this->_imageFunc = 'imagegif';
$this->_imageExtension = 'gif';
break;
case 'image/jpeg': case 'image/jpg':
$this->_imageCreateFunc = 'imagecreatefromjpeg';
$this->_imageFunc = 'imagejpeg';
$this->_imageExtension = 'jpg';
break;
}
} | [
"private",
"function",
"_setFunctions",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"_imageType",
")",
"{",
"case",
"'image/png'",
":",
"$",
"this",
"->",
"_imageCreateFunc",
"=",
"'imagecreatefrompng'",
";",
"$",
"this",
"->",
"_imageFunc",
"=",
"'imagepng'",
";",
"$",
"this",
"->",
"_imageExtension",
"=",
"'png'",
";",
"break",
";",
"case",
"'image/gif'",
":",
"$",
"this",
"->",
"_imageCreateFunc",
"=",
"'imagecreatefromgif'",
";",
"$",
"this",
"->",
"_imageFunc",
"=",
"'imagegif'",
";",
"$",
"this",
"->",
"_imageExtension",
"=",
"'gif'",
";",
"break",
";",
"case",
"'image/jpeg'",
":",
"case",
"'image/jpg'",
":",
"$",
"this",
"->",
"_imageCreateFunc",
"=",
"'imagecreatefromjpeg'",
";",
"$",
"this",
"->",
"_imageFunc",
"=",
"'imagejpeg'",
";",
"$",
"this",
"->",
"_imageExtension",
"=",
"'jpg'",
";",
"break",
";",
"}",
"}"
] | Set Functions | [
"Set",
"Functions"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/MemoryImage.php#L129-L147 |
JBZoo/Less | src/Cache.php | Cache.isExpired | public function isExpired()
{
if (!FS::isFile($this->_resultFile)) {
return true;
}
$fileAge = abs(time() - filemtime($this->_resultFile));
if ($fileAge >= $this->_cache_ttl) {
return true;
}
$firstLine = trim(FS::firstLine($this->_resultFile));
$expected = trim($this->_getHeader());
if ($expected === $firstLine) {
return false;
}
return true;
} | php | public function isExpired()
{
if (!FS::isFile($this->_resultFile)) {
return true;
}
$fileAge = abs(time() - filemtime($this->_resultFile));
if ($fileAge >= $this->_cache_ttl) {
return true;
}
$firstLine = trim(FS::firstLine($this->_resultFile));
$expected = trim($this->_getHeader());
if ($expected === $firstLine) {
return false;
}
return true;
} | [
"public",
"function",
"isExpired",
"(",
")",
"{",
"if",
"(",
"!",
"FS",
"::",
"isFile",
"(",
"$",
"this",
"->",
"_resultFile",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"fileAge",
"=",
"abs",
"(",
"time",
"(",
")",
"-",
"filemtime",
"(",
"$",
"this",
"->",
"_resultFile",
")",
")",
";",
"if",
"(",
"$",
"fileAge",
">=",
"$",
"this",
"->",
"_cache_ttl",
")",
"{",
"return",
"true",
";",
"}",
"$",
"firstLine",
"=",
"trim",
"(",
"FS",
"::",
"firstLine",
"(",
"$",
"this",
"->",
"_resultFile",
")",
")",
";",
"$",
"expected",
"=",
"trim",
"(",
"$",
"this",
"->",
"_getHeader",
"(",
")",
")",
";",
"if",
"(",
"$",
"expected",
"===",
"$",
"firstLine",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check is current cache is expired | [
"Check",
"is",
"current",
"cache",
"is",
"expired"
] | train | https://github.com/JBZoo/Less/blob/9e9c41e3c7b76222c0d81379dead222413f2f042/src/Cache.php#L86-L104 |
JBZoo/Less | src/Cache.php | Cache.save | public function save($content)
{
$content = $this->_getHeader() . $content;
$result = file_put_contents($this->_resultFile, $content);
if (!$result) {
throw new Exception('JBZoo/Less: File not save - ' . $this->_resultFile); // @codeCoverageIgnore
}
} | php | public function save($content)
{
$content = $this->_getHeader() . $content;
$result = file_put_contents($this->_resultFile, $content);
if (!$result) {
throw new Exception('JBZoo/Less: File not save - ' . $this->_resultFile); // @codeCoverageIgnore
}
} | [
"public",
"function",
"save",
"(",
"$",
"content",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"_getHeader",
"(",
")",
".",
"$",
"content",
";",
"$",
"result",
"=",
"file_put_contents",
"(",
"$",
"this",
"->",
"_resultFile",
",",
"$",
"content",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'JBZoo/Less: File not save - '",
".",
"$",
"this",
"->",
"_resultFile",
")",
";",
"// @codeCoverageIgnore",
"}",
"}"
] | Save result to cache
@param string $content
@throws Exception | [
"Save",
"result",
"to",
"cache"
] | train | https://github.com/JBZoo/Less/blob/9e9c41e3c7b76222c0d81379dead222413f2f042/src/Cache.php#L169-L177 |
claroline/ForumBundle | Manager/Manager.php | Manager.subscribe | public function subscribe(Forum $forum, User $user, $selfActivation = true)
{
$this->om->startFlushSuite();
$notification = new Notification();
$notification->setUser($user);
$notification->setForum($forum);
$notification->setSelfActivation($selfActivation);
$this->om->persist($notification);
$this->dispatch(new SubscribeForumEvent($forum));
$this->om->endFlushSuite();
} | php | public function subscribe(Forum $forum, User $user, $selfActivation = true)
{
$this->om->startFlushSuite();
$notification = new Notification();
$notification->setUser($user);
$notification->setForum($forum);
$notification->setSelfActivation($selfActivation);
$this->om->persist($notification);
$this->dispatch(new SubscribeForumEvent($forum));
$this->om->endFlushSuite();
} | [
"public",
"function",
"subscribe",
"(",
"Forum",
"$",
"forum",
",",
"User",
"$",
"user",
",",
"$",
"selfActivation",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"notification",
"=",
"new",
"Notification",
"(",
")",
";",
"$",
"notification",
"->",
"setUser",
"(",
"$",
"user",
")",
";",
"$",
"notification",
"->",
"setForum",
"(",
"$",
"forum",
")",
";",
"$",
"notification",
"->",
"setSelfActivation",
"(",
"$",
"selfActivation",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"notification",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"SubscribeForumEvent",
"(",
"$",
"forum",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Subscribe a user to a forum. A mail will be sent to the user each time
a message is posted.
@param \Claroline\ForumBundle\Entity\Forum $forum
@param \Claroline\CoreBundle\Entity\User $user | [
"Subscribe",
"a",
"user",
"to",
"a",
"forum",
".",
"A",
"mail",
"will",
"be",
"sent",
"to",
"the",
"user",
"each",
"time",
"a",
"message",
"is",
"posted",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L133-L143 |
claroline/ForumBundle | Manager/Manager.php | Manager.unsubscribe | public function unsubscribe(Forum $forum, User $user)
{
$this->om->startFlushSuite();
$notification = $this->notificationRepo->findOneBy(array('forum' => $forum, 'user' => $user));
$this->om->remove($notification);
$this->dispatch(new UnsubscribeForumEvent($forum));
$this->om->endFlushSuite();
} | php | public function unsubscribe(Forum $forum, User $user)
{
$this->om->startFlushSuite();
$notification = $this->notificationRepo->findOneBy(array('forum' => $forum, 'user' => $user));
$this->om->remove($notification);
$this->dispatch(new UnsubscribeForumEvent($forum));
$this->om->endFlushSuite();
} | [
"public",
"function",
"unsubscribe",
"(",
"Forum",
"$",
"forum",
",",
"User",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"notification",
"=",
"$",
"this",
"->",
"notificationRepo",
"->",
"findOneBy",
"(",
"array",
"(",
"'forum'",
"=>",
"$",
"forum",
",",
"'user'",
"=>",
"$",
"user",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"remove",
"(",
"$",
"notification",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"UnsubscribeForumEvent",
"(",
"$",
"forum",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Unsubscribe a user from a forum.
@param \Claroline\ForumBundle\Entity\Forum $forum
@param \Claroline\CoreBundle\Entity\User $user | [
"Unsubscribe",
"a",
"user",
"from",
"a",
"forum",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L151-L158 |
claroline/ForumBundle | Manager/Manager.php | Manager.createCategory | public function createCategory(Forum $forum, $name, $autolog = true)
{
$this->om->startFlushSuite();
$category = new Category();
$category->setName($name);
$category->setForum($forum);
$this->om->persist($category);
//required for the default category
$this->om->persist($forum);
//default category is not logged because the resource node doesn't exist yet
if ($autolog) {
$this->dispatch(new CreateCategoryEvent($category));
}
$this->om->endFlushSuite();
return $category;
} | php | public function createCategory(Forum $forum, $name, $autolog = true)
{
$this->om->startFlushSuite();
$category = new Category();
$category->setName($name);
$category->setForum($forum);
$this->om->persist($category);
//required for the default category
$this->om->persist($forum);
//default category is not logged because the resource node doesn't exist yet
if ($autolog) {
$this->dispatch(new CreateCategoryEvent($category));
}
$this->om->endFlushSuite();
return $category;
} | [
"public",
"function",
"createCategory",
"(",
"Forum",
"$",
"forum",
",",
"$",
"name",
",",
"$",
"autolog",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"category",
"=",
"new",
"Category",
"(",
")",
";",
"$",
"category",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"category",
"->",
"setForum",
"(",
"$",
"forum",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"category",
")",
";",
"//required for the default category",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"forum",
")",
";",
"//default category is not logged because the resource node doesn't exist yet",
"if",
"(",
"$",
"autolog",
")",
"{",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"CreateCategoryEvent",
"(",
"$",
"category",
")",
")",
";",
"}",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"return",
"$",
"category",
";",
"}"
] | Create a category.
@param \Claroline\ForumBundle\Entity\Forum $forum
@param string $name The category name
@param boolean $autolog
@return \Claroline\ForumBundle\Entity\Category | [
"Create",
"a",
"category",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L169-L188 |
claroline/ForumBundle | Manager/Manager.php | Manager.createMessage | public function createMessage(Message $message, Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->sc->isGranted('post', $collection)) {
throw new AccessDeniedHttpException($collection->getErrorsForDisplay());
}
$user = $this->sc->getToken()->getUser();
$message->setCreator($user);
$message->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
$message->setSubject($subject);
$this->om->persist($message);
$this->om->flush();
$this->dispatch(new CreateMessageEvent($message));
$this->sendMessageNotification($message, $message->getCreator());
return $message;
} | php | public function createMessage(Message $message, Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->sc->isGranted('post', $collection)) {
throw new AccessDeniedHttpException($collection->getErrorsForDisplay());
}
$user = $this->sc->getToken()->getUser();
$message->setCreator($user);
$message->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
$message->setSubject($subject);
$this->om->persist($message);
$this->om->flush();
$this->dispatch(new CreateMessageEvent($message));
$this->sendMessageNotification($message, $message->getCreator());
return $message;
} | [
"public",
"function",
"createMessage",
"(",
"Message",
"$",
"message",
",",
"Subject",
"$",
"subject",
")",
"{",
"$",
"forum",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"sc",
"->",
"isGranted",
"(",
"'post'",
",",
"$",
"collection",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
"$",
"collection",
"->",
"getErrorsForDisplay",
"(",
")",
")",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"sc",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"message",
"->",
"setCreator",
"(",
"$",
"user",
")",
";",
"$",
"message",
"->",
"setAuthor",
"(",
"$",
"user",
"->",
"getFirstName",
"(",
")",
".",
"' '",
".",
"$",
"user",
"->",
"getLastName",
"(",
")",
")",
";",
"$",
"message",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"om",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"CreateMessageEvent",
"(",
"$",
"message",
")",
")",
";",
"$",
"this",
"->",
"sendMessageNotification",
"(",
"$",
"message",
",",
"$",
"message",
"->",
"getCreator",
"(",
")",
")",
";",
"return",
"$",
"message",
";",
"}"
] | @param \Claroline\ForumBundle\Entity\Message $message
@param \Claroline\ForumBundle\Entity\Subject $subject
@throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
@return \Claroline\ForumBundle\Entity\Message | [
"@param",
"\\",
"Claroline",
"\\",
"ForumBundle",
"\\",
"Entity",
"\\",
"Message",
"$message"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L208-L227 |
claroline/ForumBundle | Manager/Manager.php | Manager.createSubject | public function createSubject(Subject $subject)
{
$this->om->startFlushSuite();
$this->om->persist($subject);
$this->dispatch(new CreateSubjectEvent($subject));
$this->om->endFlushSuite();
return $subject;
} | php | public function createSubject(Subject $subject)
{
$this->om->startFlushSuite();
$this->om->persist($subject);
$this->dispatch(new CreateSubjectEvent($subject));
$this->om->endFlushSuite();
return $subject;
} | [
"public",
"function",
"createSubject",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"CreateSubjectEvent",
"(",
"$",
"subject",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"return",
"$",
"subject",
";",
"}"
] | @param \Claroline\ForumBundle\Entity\Subject $subject
@return \Claroline\ForumBundle\Entity\Subject $subject | [
"@param",
"\\",
"Claroline",
"\\",
"ForumBundle",
"\\",
"Entity",
"\\",
"Subject",
"$subject"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L256-L264 |
claroline/ForumBundle | Manager/Manager.php | Manager.sendMessageNotification | public function sendMessageNotification(Message $message, User $user)
{
$forum = $message->getSubject()->getCategory()->getForum();
$notifications = $this->notificationRepo->findBy(array('forum' => $forum));
$users = array();
foreach ($notifications as $notification) {
$users[] = $notification->getUser();
}
$title = $this->translator->trans(
'forum_new_message',
array('%forum%' => $forum->getResourceNode()->getName(), '%subject%' => $message->getSubject()->getTitle(), '%author%' => $message->getCreator()->getUsername()),
'forum'
);
$url = $this->router->generate(
'claro_forum_subjects', array('category' => $message->getSubject()->getCategory()->getId()), true
);
$body = "<a href='{$url}'>{$title}</a><hr>{$message->getContent()}";
$this->mailManager->send($title, $body, $users);
} | php | public function sendMessageNotification(Message $message, User $user)
{
$forum = $message->getSubject()->getCategory()->getForum();
$notifications = $this->notificationRepo->findBy(array('forum' => $forum));
$users = array();
foreach ($notifications as $notification) {
$users[] = $notification->getUser();
}
$title = $this->translator->trans(
'forum_new_message',
array('%forum%' => $forum->getResourceNode()->getName(), '%subject%' => $message->getSubject()->getTitle(), '%author%' => $message->getCreator()->getUsername()),
'forum'
);
$url = $this->router->generate(
'claro_forum_subjects', array('category' => $message->getSubject()->getCategory()->getId()), true
);
$body = "<a href='{$url}'>{$title}</a><hr>{$message->getContent()}";
$this->mailManager->send($title, $body, $users);
} | [
"public",
"function",
"sendMessageNotification",
"(",
"Message",
"$",
"message",
",",
"User",
"$",
"user",
")",
"{",
"$",
"forum",
"=",
"$",
"message",
"->",
"getSubject",
"(",
")",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"notifications",
"=",
"$",
"this",
"->",
"notificationRepo",
"->",
"findBy",
"(",
"array",
"(",
"'forum'",
"=>",
"$",
"forum",
")",
")",
";",
"$",
"users",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"notifications",
"as",
"$",
"notification",
")",
"{",
"$",
"users",
"[",
"]",
"=",
"$",
"notification",
"->",
"getUser",
"(",
")",
";",
"}",
"$",
"title",
"=",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'forum_new_message'",
",",
"array",
"(",
"'%forum%'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'%subject%'",
"=>",
"$",
"message",
"->",
"getSubject",
"(",
")",
"->",
"getTitle",
"(",
")",
",",
"'%author%'",
"=>",
"$",
"message",
"->",
"getCreator",
"(",
")",
"->",
"getUsername",
"(",
")",
")",
",",
"'forum'",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"message",
"->",
"getSubject",
"(",
")",
"->",
"getCategory",
"(",
")",
"->",
"getId",
"(",
")",
")",
",",
"true",
")",
";",
"$",
"body",
"=",
"\"<a href='{$url}'>{$title}</a><hr>{$message->getContent()}\"",
";",
"$",
"this",
"->",
"mailManager",
"->",
"send",
"(",
"$",
"title",
",",
"$",
"body",
",",
"$",
"users",
")",
";",
"}"
] | Send a notification to a user about a message.
@param \Claroline\ForumBundle\Entity\Message $message
@param \Claroline\CoreBundle\Entity\User $user | [
"Send",
"a",
"notification",
"to",
"a",
"user",
"about",
"a",
"message",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L284-L307 |
claroline/ForumBundle | Manager/Manager.php | Manager.moveMessage | public function moveMessage(Message $message, Subject $newSubject)
{
$this->om->startFlushSuite();
$oldSubject = $message->getSubject();
$message->setSubject($newSubject);
$this->om->persist($message);
$this->dispatch(new MoveMessageEvent($message, $oldSubject, $newSubject));
$this->om->endFlushSuite();
} | php | public function moveMessage(Message $message, Subject $newSubject)
{
$this->om->startFlushSuite();
$oldSubject = $message->getSubject();
$message->setSubject($newSubject);
$this->om->persist($message);
$this->dispatch(new MoveMessageEvent($message, $oldSubject, $newSubject));
$this->om->endFlushSuite();
} | [
"public",
"function",
"moveMessage",
"(",
"Message",
"$",
"message",
",",
"Subject",
"$",
"newSubject",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"oldSubject",
"=",
"$",
"message",
"->",
"getSubject",
"(",
")",
";",
"$",
"message",
"->",
"setSubject",
"(",
"$",
"newSubject",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"MoveMessageEvent",
"(",
"$",
"message",
",",
"$",
"oldSubject",
",",
"$",
"newSubject",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Move a message to an other subject.
@param \Claroline\ForumBundle\Entity\Message $message
@param \Claroline\ForumBundle\Entity\Subject $newSubject | [
"Move",
"a",
"message",
"to",
"an",
"other",
"subject",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L342-L350 |
claroline/ForumBundle | Manager/Manager.php | Manager.moveSubject | public function moveSubject(Subject $subject, Category $newCategory)
{
$this->om->startFlushSuite();
$oldCategory = $subject->getCategory();
$subject->setCategory($newCategory);
$this->om->persist($subject);
$this->dispatch(new MoveSubjectEvent($subject, $oldCategory, $newCategory));
$this->om->endFlushSuite();
} | php | public function moveSubject(Subject $subject, Category $newCategory)
{
$this->om->startFlushSuite();
$oldCategory = $subject->getCategory();
$subject->setCategory($newCategory);
$this->om->persist($subject);
$this->dispatch(new MoveSubjectEvent($subject, $oldCategory, $newCategory));
$this->om->endFlushSuite();
} | [
"public",
"function",
"moveSubject",
"(",
"Subject",
"$",
"subject",
",",
"Category",
"$",
"newCategory",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"oldCategory",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
";",
"$",
"subject",
"->",
"setCategory",
"(",
"$",
"newCategory",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"MoveSubjectEvent",
"(",
"$",
"subject",
",",
"$",
"oldCategory",
",",
"$",
"newCategory",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Move a subject to an other category.
@param \Claroline\ForumBundle\Entity\Subject $subject
@param \Claroline\ForumBundle\Entity\Category $newCategory | [
"Move",
"a",
"subject",
"to",
"an",
"other",
"category",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L358-L366 |
claroline/ForumBundle | Manager/Manager.php | Manager.stickSubject | public function stickSubject(Subject $subject)
{
$this->om->startFlushSuite();
$subject->setIsSticked(true);
$this->om->persist($subject);
$this->dispatch(new StickSubjectEvent($subject));
$this->om->endFlushSuite();
} | php | public function stickSubject(Subject $subject)
{
$this->om->startFlushSuite();
$subject->setIsSticked(true);
$this->om->persist($subject);
$this->dispatch(new StickSubjectEvent($subject));
$this->om->endFlushSuite();
} | [
"public",
"function",
"stickSubject",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"subject",
"->",
"setIsSticked",
"(",
"true",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"StickSubjectEvent",
"(",
"$",
"subject",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Stick a subject at the top of the subject list.
@param \Claroline\ForumBundle\Entity\Subject $subject | [
"Stick",
"a",
"subject",
"at",
"the",
"top",
"of",
"the",
"subject",
"list",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L373-L380 |
claroline/ForumBundle | Manager/Manager.php | Manager.unstickSubject | public function unstickSubject(Subject $subject)
{
$this->om->startFlushSuite();
$subject->setIsSticked(false);
$this->om->persist($subject);
$this->dispatch(new UnstickSubjectEvent($subject));
$this->om->endFlushSuite();
} | php | public function unstickSubject(Subject $subject)
{
$this->om->startFlushSuite();
$subject->setIsSticked(false);
$this->om->persist($subject);
$this->dispatch(new UnstickSubjectEvent($subject));
$this->om->endFlushSuite();
} | [
"public",
"function",
"unstickSubject",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"subject",
"->",
"setIsSticked",
"(",
"false",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"UnstickSubjectEvent",
"(",
"$",
"subject",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Unstick a subject from the top of the subject list.
@param \Claroline\ForumBundle\Entity\Subject $subject | [
"Unstick",
"a",
"subject",
"from",
"the",
"top",
"of",
"the",
"subject",
"list",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L387-L394 |
claroline/ForumBundle | Manager/Manager.php | Manager.closeSubject | public function closeSubject(Subject $subject)
{
$this->om->startFlushSuite();
$subject->setIsClosed(true);
$this->om->persist($subject);
$this->dispatch(new CloseSubjectEvent($subject));
$this->om->endFlushSuite();
} | php | public function closeSubject(Subject $subject)
{
$this->om->startFlushSuite();
$subject->setIsClosed(true);
$this->om->persist($subject);
$this->dispatch(new CloseSubjectEvent($subject));
$this->om->endFlushSuite();
} | [
"public",
"function",
"closeSubject",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"subject",
"->",
"setIsClosed",
"(",
"true",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"CloseSubjectEvent",
"(",
"$",
"subject",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Close a subject and no one can write in it.
@param \Claroline\ForumBundle\Entity\Subject $subject | [
"Close",
"a",
"subject",
"and",
"no",
"one",
"can",
"write",
"in",
"it",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L401-L408 |
claroline/ForumBundle | Manager/Manager.php | Manager.openSubject | public function openSubject(Subject $subject)
{
$this->om->startFlushSuite();
$subject->setIsClosed(false);
$this->om->persist($subject);
$this->dispatch(new OpenSubjectEvent($subject));
$this->om->endFlushSuite();
} | php | public function openSubject(Subject $subject)
{
$this->om->startFlushSuite();
$subject->setIsClosed(false);
$this->om->persist($subject);
$this->dispatch(new OpenSubjectEvent($subject));
$this->om->endFlushSuite();
} | [
"public",
"function",
"openSubject",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"subject",
"->",
"setIsClosed",
"(",
"false",
")",
";",
"$",
"this",
"->",
"om",
"->",
"persist",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"OpenSubjectEvent",
"(",
"$",
"subject",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Open a subject.
@param \Claroline\ForumBundle\Entity\Subject $subject | [
"Open",
"a",
"subject",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L415-L422 |
claroline/ForumBundle | Manager/Manager.php | Manager.getSubjectsPager | public function getSubjectsPager(Category $category, $page = 1, $max = 20)
{
$subjects = $this->forumRepo->findSubjects($category);
return $this->pagerFactory->createPagerFromArray($subjects, $page, $max);
} | php | public function getSubjectsPager(Category $category, $page = 1, $max = 20)
{
$subjects = $this->forumRepo->findSubjects($category);
return $this->pagerFactory->createPagerFromArray($subjects, $page, $max);
} | [
"public",
"function",
"getSubjectsPager",
"(",
"Category",
"$",
"category",
",",
"$",
"page",
"=",
"1",
",",
"$",
"max",
"=",
"20",
")",
"{",
"$",
"subjects",
"=",
"$",
"this",
"->",
"forumRepo",
"->",
"findSubjects",
"(",
"$",
"category",
")",
";",
"return",
"$",
"this",
"->",
"pagerFactory",
"->",
"createPagerFromArray",
"(",
"$",
"subjects",
",",
"$",
"page",
",",
"$",
"max",
")",
";",
"}"
] | Get the pager for the subject list of a category.
@param \Claroline\ForumBundle\Entity\Category $category
@param integer $page
@param integer $max
@return \Pagerfanta\Pagerfanta | [
"Get",
"the",
"pager",
"for",
"the",
"subject",
"list",
"of",
"a",
"category",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L433-L438 |
claroline/ForumBundle | Manager/Manager.php | Manager.getMessagesPager | public function getMessagesPager(Subject $subject, $page = 1, $max = 20)
{
$messages = $this->messageRepo->findBySubject($subject);
return $this->pagerFactory->createPagerFromArray($messages, $page, $max);
} | php | public function getMessagesPager(Subject $subject, $page = 1, $max = 20)
{
$messages = $this->messageRepo->findBySubject($subject);
return $this->pagerFactory->createPagerFromArray($messages, $page, $max);
} | [
"public",
"function",
"getMessagesPager",
"(",
"Subject",
"$",
"subject",
",",
"$",
"page",
"=",
"1",
",",
"$",
"max",
"=",
"20",
")",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"messageRepo",
"->",
"findBySubject",
"(",
"$",
"subject",
")",
";",
"return",
"$",
"this",
"->",
"pagerFactory",
"->",
"createPagerFromArray",
"(",
"$",
"messages",
",",
"$",
"page",
",",
"$",
"max",
")",
";",
"}"
] | Get the pager for the message list of a subject.
@param \Claroline\ForumBundle\Entity\Subject $subject
@param integer $page
@param integer $max
@return \Pagerfanta\Pagerfanta | [
"Get",
"the",
"pager",
"for",
"the",
"message",
"list",
"of",
"a",
"subject",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L449-L454 |
claroline/ForumBundle | Manager/Manager.php | Manager.searchPager | public function searchPager(Forum $forum, $search, $page)
{
$query = $this->forumRepo->search($forum, $search);
return $this->pagerFactory->createPager($query, $page);
} | php | public function searchPager(Forum $forum, $search, $page)
{
$query = $this->forumRepo->search($forum, $search);
return $this->pagerFactory->createPager($query, $page);
} | [
"public",
"function",
"searchPager",
"(",
"Forum",
"$",
"forum",
",",
"$",
"search",
",",
"$",
"page",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"forumRepo",
"->",
"search",
"(",
"$",
"forum",
",",
"$",
"search",
")",
";",
"return",
"$",
"this",
"->",
"pagerFactory",
"->",
"createPager",
"(",
"$",
"query",
",",
"$",
"page",
")",
";",
"}"
] | Get the pager for the forum search.
@param \Claroline\ForumBundle\Entity\Forum $forum
@param string $search
@param integer $page
@return \Pagerfanta\Pagerfanta | [
"Get",
"the",
"pager",
"for",
"the",
"forum",
"search",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L465-L470 |
claroline/ForumBundle | Manager/Manager.php | Manager.removeNotification | private function removeNotification(Forum $forum, Notification $notification)
{
$this->om->startFlushSuite();
$this->om->remove($notification);
$this->dispatch(new UnsubscribeForumEvent($forum));
$this->om->endFlushSuite();
} | php | private function removeNotification(Forum $forum, Notification $notification)
{
$this->om->startFlushSuite();
$this->om->remove($notification);
$this->dispatch(new UnsubscribeForumEvent($forum));
$this->om->endFlushSuite();
} | [
"private",
"function",
"removeNotification",
"(",
"Forum",
"$",
"forum",
",",
"Notification",
"$",
"notification",
")",
"{",
"$",
"this",
"->",
"om",
"->",
"startFlushSuite",
"(",
")",
";",
"$",
"this",
"->",
"om",
"->",
"remove",
"(",
"$",
"notification",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"new",
"UnsubscribeForumEvent",
"(",
"$",
"forum",
")",
")",
";",
"$",
"this",
"->",
"om",
"->",
"endFlushSuite",
"(",
")",
";",
"}"
] | Unsubscribe a user from a forum.
@param \Claroline\ForumBundle\Entity\Forum $forum
@param \Claroline\ForumBundle\Entity\Notification $notification | [
"Unsubscribe",
"a",
"user",
"from",
"a",
"forum",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Manager/Manager.php#L634-L640 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Http/Client.php | Zend_Http_Client._setParameter | protected function _setParameter($type, $name, $value)
{
$parray = array();
$type = strtolower($type);
switch ($type) {
case 'get':
$parray = &$this->paramsGet;
break;
case 'post':
$parray = &$this->paramsPost;
break;
}
if ($value === null) {
if (isset($parray[$name])) unset($parray[$name]);
} else {
$parray[$name] = $value;
}
} | php | protected function _setParameter($type, $name, $value)
{
$parray = array();
$type = strtolower($type);
switch ($type) {
case 'get':
$parray = &$this->paramsGet;
break;
case 'post':
$parray = &$this->paramsPost;
break;
}
if ($value === null) {
if (isset($parray[$name])) unset($parray[$name]);
} else {
$parray[$name] = $value;
}
} | [
"protected",
"function",
"_setParameter",
"(",
"$",
"type",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"parray",
"=",
"array",
"(",
")",
";",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'get'",
":",
"$",
"parray",
"=",
"&",
"$",
"this",
"->",
"paramsGet",
";",
"break",
";",
"case",
"'post'",
":",
"$",
"parray",
"=",
"&",
"$",
"this",
"->",
"paramsPost",
";",
"break",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parray",
"[",
"$",
"name",
"]",
")",
")",
"unset",
"(",
"$",
"parray",
"[",
"$",
"name",
"]",
")",
";",
"}",
"else",
"{",
"$",
"parray",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Set a GET or POST parameter - used by SetParameterGet and SetParameterPost
@param string $type GET or POST
@param string $name
@param string $value
@return null | [
"Set",
"a",
"GET",
"or",
"POST",
"parameter",
"-",
"used",
"by",
"SetParameterGet",
"and",
"SetParameterPost"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Http/Client.php#L476-L494 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Http/Client.php | Zend_Http_Client.setAuth | public function setAuth($user, $password = '', $type = self::AUTH_BASIC)
{
// If we got false or null, disable authentication
if ($user === false || $user === null) {
$this->auth = null;
// Else, set up authentication
} else {
// Check we got a proper authentication type
if (! defined('self::AUTH_' . strtoupper($type))) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Invalid or not supported authentication type: '$type'");
}
$this->auth = array(
'user' => (string) $user,
'password' => (string) $password,
'type' => $type
);
}
return $this;
} | php | public function setAuth($user, $password = '', $type = self::AUTH_BASIC)
{
// If we got false or null, disable authentication
if ($user === false || $user === null) {
$this->auth = null;
// Else, set up authentication
} else {
// Check we got a proper authentication type
if (! defined('self::AUTH_' . strtoupper($type))) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Invalid or not supported authentication type: '$type'");
}
$this->auth = array(
'user' => (string) $user,
'password' => (string) $password,
'type' => $type
);
}
return $this;
} | [
"public",
"function",
"setAuth",
"(",
"$",
"user",
",",
"$",
"password",
"=",
"''",
",",
"$",
"type",
"=",
"self",
"::",
"AUTH_BASIC",
")",
"{",
"// If we got false or null, disable authentication",
"if",
"(",
"$",
"user",
"===",
"false",
"||",
"$",
"user",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"auth",
"=",
"null",
";",
"// Else, set up authentication",
"}",
"else",
"{",
"// Check we got a proper authentication type",
"if",
"(",
"!",
"defined",
"(",
"'self::AUTH_'",
".",
"strtoupper",
"(",
"$",
"type",
")",
")",
")",
"{",
"/** @see Zend_Http_Client_Exception */",
"require_once",
"'Zend/Http/Client/Exception.php'",
";",
"throw",
"new",
"Zend_Http_Client_Exception",
"(",
"\"Invalid or not supported authentication type: '$type'\"",
")",
";",
"}",
"$",
"this",
"->",
"auth",
"=",
"array",
"(",
"'user'",
"=>",
"(",
"string",
")",
"$",
"user",
",",
"'password'",
"=>",
"(",
"string",
")",
"$",
"password",
",",
"'type'",
"=>",
"$",
"type",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set HTTP authentication parameters
$type should be one of the supported types - see the self::AUTH_*
constants.
To enable authentication:
<code>
$this->setAuth('shahar', 'secret', Zend_Http_Client::AUTH_BASIC);
</code>
To disable authentication:
<code>
$this->setAuth(false);
</code>
@see http://www.faqs.org/rfcs/rfc2617.html
@param string|false $user User name or false disable authentication
@param string $password Password
@param string $type Authentication type
@return Zend_Http_Client
@throws Zend_Http_Client_Exception | [
"Set",
"HTTP",
"authentication",
"parameters"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Http/Client.php#L529-L552 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Http/Client.php | Zend_Http_Client.setCookieJar | public function setCookieJar($cookiejar = true)
{
if (! class_exists('Zend_Http_CookieJar')) {
require_once 'Zend/Http/CookieJar.php';
}
if ($cookiejar instanceof Zend_Http_CookieJar) {
$this->cookiejar = $cookiejar;
} elseif ($cookiejar === true) {
$this->cookiejar = new Zend_Http_CookieJar();
} elseif (! $cookiejar) {
$this->cookiejar = null;
} else {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception('Invalid parameter type passed as CookieJar');
}
return $this;
} | php | public function setCookieJar($cookiejar = true)
{
if (! class_exists('Zend_Http_CookieJar')) {
require_once 'Zend/Http/CookieJar.php';
}
if ($cookiejar instanceof Zend_Http_CookieJar) {
$this->cookiejar = $cookiejar;
} elseif ($cookiejar === true) {
$this->cookiejar = new Zend_Http_CookieJar();
} elseif (! $cookiejar) {
$this->cookiejar = null;
} else {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception('Invalid parameter type passed as CookieJar');
}
return $this;
} | [
"public",
"function",
"setCookieJar",
"(",
"$",
"cookiejar",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'Zend_Http_CookieJar'",
")",
")",
"{",
"require_once",
"'Zend/Http/CookieJar.php'",
";",
"}",
"if",
"(",
"$",
"cookiejar",
"instanceof",
"Zend_Http_CookieJar",
")",
"{",
"$",
"this",
"->",
"cookiejar",
"=",
"$",
"cookiejar",
";",
"}",
"elseif",
"(",
"$",
"cookiejar",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"cookiejar",
"=",
"new",
"Zend_Http_CookieJar",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"cookiejar",
")",
"{",
"$",
"this",
"->",
"cookiejar",
"=",
"null",
";",
"}",
"else",
"{",
"/** @see Zend_Http_Client_Exception */",
"require_once",
"'Zend/Http/Client/Exception.php'",
";",
"throw",
"new",
"Zend_Http_Client_Exception",
"(",
"'Invalid parameter type passed as CookieJar'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the HTTP client's cookie jar.
A cookie jar is an object that holds and maintains cookies across HTTP requests
and responses.
@param Zend_Http_CookieJar|boolean $cookiejar Existing cookiejar object, true to create a new one, false to disable
@return Zend_Http_Client
@throws Zend_Http_Client_Exception | [
"Set",
"the",
"HTTP",
"client",
"s",
"cookie",
"jar",
"."
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Http/Client.php#L564-L583 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Http/Client.php | Zend_Http_Client.resetParameters | public function resetParameters()
{
// Reset parameter data
$this->paramsGet = array();
$this->paramsPost = array();
$this->files = array();
$this->raw_post_data = null;
// Clear outdated headers
if (isset($this->headers[strtolower(self::CONTENT_TYPE)])) {
unset($this->headers[strtolower(self::CONTENT_TYPE)]);
}
if (isset($this->headers[strtolower(self::CONTENT_LENGTH)])) {
unset($this->headers[strtolower(self::CONTENT_LENGTH)]);
}
return $this;
} | php | public function resetParameters()
{
// Reset parameter data
$this->paramsGet = array();
$this->paramsPost = array();
$this->files = array();
$this->raw_post_data = null;
// Clear outdated headers
if (isset($this->headers[strtolower(self::CONTENT_TYPE)])) {
unset($this->headers[strtolower(self::CONTENT_TYPE)]);
}
if (isset($this->headers[strtolower(self::CONTENT_LENGTH)])) {
unset($this->headers[strtolower(self::CONTENT_LENGTH)]);
}
return $this;
} | [
"public",
"function",
"resetParameters",
"(",
")",
"{",
"// Reset parameter data",
"$",
"this",
"->",
"paramsGet",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"paramsPost",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"files",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"raw_post_data",
"=",
"null",
";",
"// Clear outdated headers",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"strtolower",
"(",
"self",
"::",
"CONTENT_TYPE",
")",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"headers",
"[",
"strtolower",
"(",
"self",
"::",
"CONTENT_TYPE",
")",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"strtolower",
"(",
"self",
"::",
"CONTENT_LENGTH",
")",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"headers",
"[",
"strtolower",
"(",
"self",
"::",
"CONTENT_LENGTH",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Clear all GET and POST parameters
Should be used to reset the request parameters if the client is
used for several concurrent requests.
@return Zend_Http_Client | [
"Clear",
"all",
"GET",
"and",
"POST",
"parameters"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Http/Client.php#L740-L757 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Http/Client.php | Zend_Http_Client._prepareHeaders | protected function _prepareHeaders()
{
$headers = array();
// Set the host header
if (! isset($this->headers['host'])) {
$host = $this->uri->getHost();
// If the port is not default, add it
if (! (($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80) ||
($this->uri->getScheme() == 'https' && $this->uri->getPort() == 443))) {
$host .= ':' . $this->uri->getPort();
}
$headers[] = "Host: {$host}";
}
// Set the connection header
if (! isset($this->headers['connection'])) {
if (! $this->config['keepalive']) {
$headers[] = "Connection: close";
}
}
// Set the Accept-encoding header if not set - depending on whether
// zlib is available or not.
if (! isset($this->headers['accept-encoding'])) {
if (function_exists('gzinflate')) {
$headers[] = 'Accept-encoding: gzip, deflate';
} else {
$headers[] = 'Accept-encoding: identity';
}
}
// Set the Content-Type header
if ($this->method == self::POST &&
(! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
$headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
}
// Set the user agent header
if (! isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
$headers[] = "User-Agent: {$this->config['useragent']}";
}
// Set HTTP authentication if needed
if (is_array($this->auth)) {
$auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
$headers[] = "Authorization: {$auth}";
}
// Load cookies from cookie jar
if (isset($this->cookiejar)) {
$cookstr = $this->cookiejar->getMatchingCookies($this->uri,
true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
if ($cookstr) {
$headers[] = "Cookie: {$cookstr}";
}
}
// Add all other user defined headers
foreach ($this->headers as $header) {
list($name, $value) = $header;
if (is_array($value)) {
$value = implode(', ', $value);
}
$headers[] = "$name: $value";
}
return $headers;
} | php | protected function _prepareHeaders()
{
$headers = array();
// Set the host header
if (! isset($this->headers['host'])) {
$host = $this->uri->getHost();
// If the port is not default, add it
if (! (($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80) ||
($this->uri->getScheme() == 'https' && $this->uri->getPort() == 443))) {
$host .= ':' . $this->uri->getPort();
}
$headers[] = "Host: {$host}";
}
// Set the connection header
if (! isset($this->headers['connection'])) {
if (! $this->config['keepalive']) {
$headers[] = "Connection: close";
}
}
// Set the Accept-encoding header if not set - depending on whether
// zlib is available or not.
if (! isset($this->headers['accept-encoding'])) {
if (function_exists('gzinflate')) {
$headers[] = 'Accept-encoding: gzip, deflate';
} else {
$headers[] = 'Accept-encoding: identity';
}
}
// Set the Content-Type header
if ($this->method == self::POST &&
(! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
$headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
}
// Set the user agent header
if (! isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
$headers[] = "User-Agent: {$this->config['useragent']}";
}
// Set HTTP authentication if needed
if (is_array($this->auth)) {
$auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
$headers[] = "Authorization: {$auth}";
}
// Load cookies from cookie jar
if (isset($this->cookiejar)) {
$cookstr = $this->cookiejar->getMatchingCookies($this->uri,
true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
if ($cookstr) {
$headers[] = "Cookie: {$cookstr}";
}
}
// Add all other user defined headers
foreach ($this->headers as $header) {
list($name, $value) = $header;
if (is_array($value)) {
$value = implode(', ', $value);
}
$headers[] = "$name: $value";
}
return $headers;
} | [
"protected",
"function",
"_prepareHeaders",
"(",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"// Set the host header",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'host'",
"]",
")",
")",
"{",
"$",
"host",
"=",
"$",
"this",
"->",
"uri",
"->",
"getHost",
"(",
")",
";",
"// If the port is not default, add it",
"if",
"(",
"!",
"(",
"(",
"$",
"this",
"->",
"uri",
"->",
"getScheme",
"(",
")",
"==",
"'http'",
"&&",
"$",
"this",
"->",
"uri",
"->",
"getPort",
"(",
")",
"==",
"80",
")",
"||",
"(",
"$",
"this",
"->",
"uri",
"->",
"getScheme",
"(",
")",
"==",
"'https'",
"&&",
"$",
"this",
"->",
"uri",
"->",
"getPort",
"(",
")",
"==",
"443",
")",
")",
")",
"{",
"$",
"host",
".=",
"':'",
".",
"$",
"this",
"->",
"uri",
"->",
"getPort",
"(",
")",
";",
"}",
"$",
"headers",
"[",
"]",
"=",
"\"Host: {$host}\"",
";",
"}",
"// Set the connection header",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'connection'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"[",
"'keepalive'",
"]",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"\"Connection: close\"",
";",
"}",
"}",
"// Set the Accept-encoding header if not set - depending on whether",
"// zlib is available or not.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'accept-encoding'",
"]",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'gzinflate'",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Accept-encoding: gzip, deflate'",
";",
"}",
"else",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Accept-encoding: identity'",
";",
"}",
"}",
"// Set the Content-Type header",
"if",
"(",
"$",
"this",
"->",
"method",
"==",
"self",
"::",
"POST",
"&&",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"strtolower",
"(",
"self",
"::",
"CONTENT_TYPE",
")",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"enctype",
")",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"self",
"::",
"CONTENT_TYPE",
".",
"': '",
".",
"$",
"this",
"->",
"enctype",
";",
"}",
"// Set the user agent header",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'user-agent'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'useragent'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"\"User-Agent: {$this->config['useragent']}\"",
";",
"}",
"// Set HTTP authentication if needed",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"auth",
")",
")",
"{",
"$",
"auth",
"=",
"self",
"::",
"encodeAuthHeader",
"(",
"$",
"this",
"->",
"auth",
"[",
"'user'",
"]",
",",
"$",
"this",
"->",
"auth",
"[",
"'password'",
"]",
",",
"$",
"this",
"->",
"auth",
"[",
"'type'",
"]",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"\"Authorization: {$auth}\"",
";",
"}",
"// Load cookies from cookie jar",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cookiejar",
")",
")",
"{",
"$",
"cookstr",
"=",
"$",
"this",
"->",
"cookiejar",
"->",
"getMatchingCookies",
"(",
"$",
"this",
"->",
"uri",
",",
"true",
",",
"Zend_Http_CookieJar",
"::",
"COOKIE_STRING_CONCAT",
")",
";",
"if",
"(",
"$",
"cookstr",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"\"Cookie: {$cookstr}\"",
";",
"}",
"}",
"// Add all other user defined headers",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"header",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"$",
"header",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"implode",
"(",
"', '",
",",
"$",
"value",
")",
";",
"}",
"$",
"headers",
"[",
"]",
"=",
"\"$name: $value\"",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] | Prepare the request headers
@return array | [
"Prepare",
"the",
"request",
"headers"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Http/Client.php#L942-L1015 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Http/Client.php | Zend_Http_Client._prepareBody | protected function _prepareBody()
{
// According to RFC2616, a TRACE request should not have a body.
if ($this->method == self::TRACE) {
return '';
}
// If we have raw_post_data set, just use it as the body.
if (isset($this->raw_post_data)) {
$this->setHeaders(self::CONTENT_LENGTH, strlen($this->raw_post_data));
return $this->raw_post_data;
}
$body = '';
// If we have files to upload, force enctype to multipart/form-data
if (count ($this->files) > 0) {
$this->setEncType(self::ENC_FORMDATA);
}
// If we have POST parameters or files, encode and add them to the body
if (count($this->paramsPost) > 0 || count($this->files) > 0) {
switch($this->enctype) {
case self::ENC_FORMDATA:
// Encode body as multipart/form-data
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
$this->setHeaders(self::CONTENT_TYPE, self::ENC_FORMDATA . "; boundary={$boundary}");
// Get POST parameters and encode them
$params = $this->_getParametersRecursive($this->paramsPost);
foreach ($params as $pp) {
$body .= self::encodeFormData($boundary, $pp[0], $pp[1]);
}
// Encode files
foreach ($this->files as $name => $file) {
$fhead = array(self::CONTENT_TYPE => $file[1]);
$body .= self::encodeFormData($boundary, $name, $file[2], $file[0], $fhead);
}
$body .= "--{$boundary}--\r\n";
break;
case self::ENC_URLENCODED:
// Encode body as application/x-www-form-urlencoded
$this->setHeaders(self::CONTENT_TYPE, self::ENC_URLENCODED);
$body = http_build_query($this->paramsPost, '', '&');
break;
default:
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Cannot handle content type '{$this->enctype}' automatically." .
" Please use Zend_Http_Client::setRawData to send this kind of content.");
break;
}
}
// Set the Content-Length if we have a body or if request is POST/PUT
if ($body || $this->method == self::POST || $this->method == self::PUT) {
$this->setHeaders(self::CONTENT_LENGTH, strlen($body));
}
return $body;
} | php | protected function _prepareBody()
{
// According to RFC2616, a TRACE request should not have a body.
if ($this->method == self::TRACE) {
return '';
}
// If we have raw_post_data set, just use it as the body.
if (isset($this->raw_post_data)) {
$this->setHeaders(self::CONTENT_LENGTH, strlen($this->raw_post_data));
return $this->raw_post_data;
}
$body = '';
// If we have files to upload, force enctype to multipart/form-data
if (count ($this->files) > 0) {
$this->setEncType(self::ENC_FORMDATA);
}
// If we have POST parameters or files, encode and add them to the body
if (count($this->paramsPost) > 0 || count($this->files) > 0) {
switch($this->enctype) {
case self::ENC_FORMDATA:
// Encode body as multipart/form-data
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
$this->setHeaders(self::CONTENT_TYPE, self::ENC_FORMDATA . "; boundary={$boundary}");
// Get POST parameters and encode them
$params = $this->_getParametersRecursive($this->paramsPost);
foreach ($params as $pp) {
$body .= self::encodeFormData($boundary, $pp[0], $pp[1]);
}
// Encode files
foreach ($this->files as $name => $file) {
$fhead = array(self::CONTENT_TYPE => $file[1]);
$body .= self::encodeFormData($boundary, $name, $file[2], $file[0], $fhead);
}
$body .= "--{$boundary}--\r\n";
break;
case self::ENC_URLENCODED:
// Encode body as application/x-www-form-urlencoded
$this->setHeaders(self::CONTENT_TYPE, self::ENC_URLENCODED);
$body = http_build_query($this->paramsPost, '', '&');
break;
default:
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Cannot handle content type '{$this->enctype}' automatically." .
" Please use Zend_Http_Client::setRawData to send this kind of content.");
break;
}
}
// Set the Content-Length if we have a body or if request is POST/PUT
if ($body || $this->method == self::POST || $this->method == self::PUT) {
$this->setHeaders(self::CONTENT_LENGTH, strlen($body));
}
return $body;
} | [
"protected",
"function",
"_prepareBody",
"(",
")",
"{",
"// According to RFC2616, a TRACE request should not have a body.",
"if",
"(",
"$",
"this",
"->",
"method",
"==",
"self",
"::",
"TRACE",
")",
"{",
"return",
"''",
";",
"}",
"// If we have raw_post_data set, just use it as the body.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw_post_data",
")",
")",
"{",
"$",
"this",
"->",
"setHeaders",
"(",
"self",
"::",
"CONTENT_LENGTH",
",",
"strlen",
"(",
"$",
"this",
"->",
"raw_post_data",
")",
")",
";",
"return",
"$",
"this",
"->",
"raw_post_data",
";",
"}",
"$",
"body",
"=",
"''",
";",
"// If we have files to upload, force enctype to multipart/form-data",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"files",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setEncType",
"(",
"self",
"::",
"ENC_FORMDATA",
")",
";",
"}",
"// If we have POST parameters or files, encode and add them to the body",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"paramsPost",
")",
">",
"0",
"||",
"count",
"(",
"$",
"this",
"->",
"files",
")",
">",
"0",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"enctype",
")",
"{",
"case",
"self",
"::",
"ENC_FORMDATA",
":",
"// Encode body as multipart/form-data",
"$",
"boundary",
"=",
"'---ZENDHTTPCLIENT-'",
".",
"md5",
"(",
"microtime",
"(",
")",
")",
";",
"$",
"this",
"->",
"setHeaders",
"(",
"self",
"::",
"CONTENT_TYPE",
",",
"self",
"::",
"ENC_FORMDATA",
".",
"\"; boundary={$boundary}\"",
")",
";",
"// Get POST parameters and encode them",
"$",
"params",
"=",
"$",
"this",
"->",
"_getParametersRecursive",
"(",
"$",
"this",
"->",
"paramsPost",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"pp",
")",
"{",
"$",
"body",
".=",
"self",
"::",
"encodeFormData",
"(",
"$",
"boundary",
",",
"$",
"pp",
"[",
"0",
"]",
",",
"$",
"pp",
"[",
"1",
"]",
")",
";",
"}",
"// Encode files",
"foreach",
"(",
"$",
"this",
"->",
"files",
"as",
"$",
"name",
"=>",
"$",
"file",
")",
"{",
"$",
"fhead",
"=",
"array",
"(",
"self",
"::",
"CONTENT_TYPE",
"=>",
"$",
"file",
"[",
"1",
"]",
")",
";",
"$",
"body",
".=",
"self",
"::",
"encodeFormData",
"(",
"$",
"boundary",
",",
"$",
"name",
",",
"$",
"file",
"[",
"2",
"]",
",",
"$",
"file",
"[",
"0",
"]",
",",
"$",
"fhead",
")",
";",
"}",
"$",
"body",
".=",
"\"--{$boundary}--\\r\\n\"",
";",
"break",
";",
"case",
"self",
"::",
"ENC_URLENCODED",
":",
"// Encode body as application/x-www-form-urlencoded",
"$",
"this",
"->",
"setHeaders",
"(",
"self",
"::",
"CONTENT_TYPE",
",",
"self",
"::",
"ENC_URLENCODED",
")",
";",
"$",
"body",
"=",
"http_build_query",
"(",
"$",
"this",
"->",
"paramsPost",
",",
"''",
",",
"'&'",
")",
";",
"break",
";",
"default",
":",
"/** @see Zend_Http_Client_Exception */",
"require_once",
"'Zend/Http/Client/Exception.php'",
";",
"throw",
"new",
"Zend_Http_Client_Exception",
"(",
"\"Cannot handle content type '{$this->enctype}' automatically.\"",
".",
"\" Please use Zend_Http_Client::setRawData to send this kind of content.\"",
")",
";",
"break",
";",
"}",
"}",
"// Set the Content-Length if we have a body or if request is POST/PUT",
"if",
"(",
"$",
"body",
"||",
"$",
"this",
"->",
"method",
"==",
"self",
"::",
"POST",
"||",
"$",
"this",
"->",
"method",
"==",
"self",
"::",
"PUT",
")",
"{",
"$",
"this",
"->",
"setHeaders",
"(",
"self",
"::",
"CONTENT_LENGTH",
",",
"strlen",
"(",
"$",
"body",
")",
")",
";",
"}",
"return",
"$",
"body",
";",
"}"
] | Prepare the request body (for POST and PUT requests)
@return string
@throws Zend_Http_Client_Exception | [
"Prepare",
"the",
"request",
"body",
"(",
"for",
"POST",
"and",
"PUT",
"requests",
")"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Http/Client.php#L1023-L1087 |
PeekAndPoke/psi | src/Operation/FullSet/ReverseOperation.php | ReverseOperation.apply | public function apply(\Iterator $set)
{
$data = iterator_to_array($set);
$reversed = array_reverse($data);
return new \ArrayIterator($reversed);
} | php | public function apply(\Iterator $set)
{
$data = iterator_to_array($set);
$reversed = array_reverse($data);
return new \ArrayIterator($reversed);
} | [
"public",
"function",
"apply",
"(",
"\\",
"Iterator",
"$",
"set",
")",
"{",
"$",
"data",
"=",
"iterator_to_array",
"(",
"$",
"set",
")",
";",
"$",
"reversed",
"=",
"array_reverse",
"(",
"$",
"data",
")",
";",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"reversed",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Operation/FullSet/ReverseOperation.php#L22-L29 |
fyuze/framework | src/Fyuze/Http/Kernel.php | Kernel.resolve | protected function resolve($action, $params)
{
if ($action instanceof Closure) {
return $action($params);
}
list($controller, $method) = $action;
$reflect = new ReflectionClass($controller);
foreach (array_filter($reflect->getMethod($method)->getParameters(), $this->getParams()) as $param) {
array_unshift($params, $this->registry->make(
$param->getClass()->getName()
));
}
return $reflect->getMethod($method)->invokeArgs(
$this->registry->make($controller),
$params
);
} | php | protected function resolve($action, $params)
{
if ($action instanceof Closure) {
return $action($params);
}
list($controller, $method) = $action;
$reflect = new ReflectionClass($controller);
foreach (array_filter($reflect->getMethod($method)->getParameters(), $this->getParams()) as $param) {
array_unshift($params, $this->registry->make(
$param->getClass()->getName()
));
}
return $reflect->getMethod($method)->invokeArgs(
$this->registry->make($controller),
$params
);
} | [
"protected",
"function",
"resolve",
"(",
"$",
"action",
",",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"action",
"instanceof",
"Closure",
")",
"{",
"return",
"$",
"action",
"(",
"$",
"params",
")",
";",
"}",
"list",
"(",
"$",
"controller",
",",
"$",
"method",
")",
"=",
"$",
"action",
";",
"$",
"reflect",
"=",
"new",
"ReflectionClass",
"(",
"$",
"controller",
")",
";",
"foreach",
"(",
"array_filter",
"(",
"$",
"reflect",
"->",
"getMethod",
"(",
"$",
"method",
")",
"->",
"getParameters",
"(",
")",
",",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
"as",
"$",
"param",
")",
"{",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"this",
"->",
"registry",
"->",
"make",
"(",
"$",
"param",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"reflect",
"->",
"getMethod",
"(",
"$",
"method",
")",
"->",
"invokeArgs",
"(",
"$",
"this",
"->",
"registry",
"->",
"make",
"(",
"$",
"controller",
")",
",",
"$",
"params",
")",
";",
"}"
] | Method injection resolver
@param $action
@param $params
@return mixed | [
"Method",
"injection",
"resolver"
] | train | https://github.com/fyuze/framework/blob/89b3984f7225e24bfcdafb090ee197275b3222c9/src/Fyuze/Http/Kernel.php#L76-L97 |
ufocoder/yii2-SyncSocial | src/components/services/Twitter.php | Twitter.publishPost | public function publishPost( $message, $url = null ) {
return $this->parsePublishPost(
$this->service->api( 'statuses/update.json', 'POST', [
'status' => $message
] ),
'id',
[
'service_id_author' => 'user.id',
'service_id_post' => 'id',
'time_created' => 'created_at'
] );
} | php | public function publishPost( $message, $url = null ) {
return $this->parsePublishPost(
$this->service->api( 'statuses/update.json', 'POST', [
'status' => $message
] ),
'id',
[
'service_id_author' => 'user.id',
'service_id_post' => 'id',
'time_created' => 'created_at'
] );
} | [
"public",
"function",
"publishPost",
"(",
"$",
"message",
",",
"$",
"url",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"parsePublishPost",
"(",
"$",
"this",
"->",
"service",
"->",
"api",
"(",
"'statuses/update.json'",
",",
"'POST'",
",",
"[",
"'status'",
"=>",
"$",
"message",
"]",
")",
",",
"'id'",
",",
"[",
"'service_id_author'",
"=>",
"'user.id'",
",",
"'service_id_post'",
"=>",
"'id'",
",",
"'time_created'",
"=>",
"'created_at'",
"]",
")",
";",
"}"
] | @param $message
@param null $url
@return array
@throws \yii\base\Exception | [
"@param",
"$message",
"@param",
"null",
"$url"
] | train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/components/services/Twitter.php#L37-L49 |
ufocoder/yii2-SyncSocial | src/components/services/Twitter.php | Twitter.deletePost | public function deletePost( $id ) {
$response = $this->service->api( 'statuses/destroy/' . $id . '.json', 'POST' );
return isset( $response['id'] ) && $response['id'] == $id;
} | php | public function deletePost( $id ) {
$response = $this->service->api( 'statuses/destroy/' . $id . '.json', 'POST' );
return isset( $response['id'] ) && $response['id'] == $id;
} | [
"public",
"function",
"deletePost",
"(",
"$",
"id",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"api",
"(",
"'statuses/destroy/'",
".",
"$",
"id",
".",
"'.json'",
",",
"'POST'",
")",
";",
"return",
"isset",
"(",
"$",
"response",
"[",
"'id'",
"]",
")",
"&&",
"$",
"response",
"[",
"'id'",
"]",
"==",
"$",
"id",
";",
"}"
] | @param $id
@return bool | [
"@param",
"$id"
] | train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/components/services/Twitter.php#L56-L60 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Validate/Sitemap/Lastmod.php | Zend_Validate_Sitemap_Lastmod.isValid | public function isValid($value)
{
$this->_setValue($value);
if (!is_string($value)) {
return false;
}
return @preg_match(self::LASTMOD_REGEX, $value) == 1;
} | php | public function isValid($value)
{
$this->_setValue($value);
if (!is_string($value)) {
return false;
}
return @preg_match(self::LASTMOD_REGEX, $value) == 1;
} | [
"public",
"function",
"isValid",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_setValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"@",
"preg_match",
"(",
"self",
"::",
"LASTMOD_REGEX",
",",
"$",
"value",
")",
"==",
"1",
";",
"}"
] | Validates if a string is valid as a sitemap lastmod
@link http://www.sitemaps.org/protocol.php#lastmoddef <lastmod>
@param string $value value to validate
@return boolean | [
"Validates",
"if",
"a",
"string",
"is",
"valid",
"as",
"a",
"sitemap",
"lastmod"
] | train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Validate/Sitemap/Lastmod.php#L69-L78 |
yuncms/framework | src/sphinx/ActiveRecord.php | ActiveRecord.create | public static function create(array $attributes, $runValidation = true)
{
$model = new static();
$model->load($attributes, '');
if ($model->save($runValidation)) {
return $model;
}
return null;
} | php | public static function create(array $attributes, $runValidation = true)
{
$model = new static();
$model->load($attributes, '');
if ($model->save($runValidation)) {
return $model;
}
return null;
} | [
"public",
"static",
"function",
"create",
"(",
"array",
"$",
"attributes",
",",
"$",
"runValidation",
"=",
"true",
")",
"{",
"$",
"model",
"=",
"new",
"static",
"(",
")",
";",
"$",
"model",
"->",
"load",
"(",
"$",
"attributes",
",",
"''",
")",
";",
"if",
"(",
"$",
"model",
"->",
"save",
"(",
"$",
"runValidation",
")",
")",
"{",
"return",
"$",
"model",
";",
"}",
"return",
"null",
";",
"}"
] | 快速创建实例
@param array $attributes
@param boolean $runValidation
@return null|ActiveRecord | [
"快速创建实例"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sphinx/ActiveRecord.php#L95-L103 |
simplisti/jasper-starter | src/Starter.php | Starter.compile | public function compile (Report $report, bool $skipExec = false)
{
$sourceFullPath = $report->getSourceFile(); // $this->sourcePath . DIRECTORY_SEPARATOR . $report->getSourceFile();
$compiledPath = $this->compiledPath;
$this->shellCommand = $this->executablePath . " cp -o $compiledPath $sourceFullPath";
if (!$skipExec) {
$oldcwd = getcwd();
chdir($this->sourcePath);
$error = shell_exec(escapeshellcmd($this->shellCommand));
chdir($oldcwd);
if (!empty($error)) {
throw new \Exception($error);
}
}
return $compiledPath;
} | php | public function compile (Report $report, bool $skipExec = false)
{
$sourceFullPath = $report->getSourceFile(); // $this->sourcePath . DIRECTORY_SEPARATOR . $report->getSourceFile();
$compiledPath = $this->compiledPath;
$this->shellCommand = $this->executablePath . " cp -o $compiledPath $sourceFullPath";
if (!$skipExec) {
$oldcwd = getcwd();
chdir($this->sourcePath);
$error = shell_exec(escapeshellcmd($this->shellCommand));
chdir($oldcwd);
if (!empty($error)) {
throw new \Exception($error);
}
}
return $compiledPath;
} | [
"public",
"function",
"compile",
"(",
"Report",
"$",
"report",
",",
"bool",
"$",
"skipExec",
"=",
"false",
")",
"{",
"$",
"sourceFullPath",
"=",
"$",
"report",
"->",
"getSourceFile",
"(",
")",
";",
"// $this->sourcePath . DIRECTORY_SEPARATOR . $report->getSourceFile(); \r",
"$",
"compiledPath",
"=",
"$",
"this",
"->",
"compiledPath",
";",
"$",
"this",
"->",
"shellCommand",
"=",
"$",
"this",
"->",
"executablePath",
".",
"\" cp -o $compiledPath $sourceFullPath\"",
";",
"if",
"(",
"!",
"$",
"skipExec",
")",
"{",
"$",
"oldcwd",
"=",
"getcwd",
"(",
")",
";",
"chdir",
"(",
"$",
"this",
"->",
"sourcePath",
")",
";",
"$",
"error",
"=",
"shell_exec",
"(",
"escapeshellcmd",
"(",
"$",
"this",
"->",
"shellCommand",
")",
")",
";",
"chdir",
"(",
"$",
"oldcwd",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"error",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"error",
")",
";",
"}",
"}",
"return",
"$",
"compiledPath",
";",
"}"
] | Compile JRXML files into JASPER for processing.
@return self | [
"Compile",
"JRXML",
"files",
"into",
"JASPER",
"for",
"processing",
"."
] | train | https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/Starter.php#L75-L95 |
simplisti/jasper-starter | src/Starter.php | Starter.process | public function process (Report $report, bool $skipExec = false)
{
$compiledFullPath = $this->compiledPath . DIRECTORY_SEPARATOR . pathinfo($report->getSourceFile(), PATHINFO_FILENAME) . '.jasper';
$processedFullPath = $this->processedPath . DIRECTORY_SEPARATOR . uniqid('ASB');
$format = ' -f ' . $report->getTargetType();
$value = empty($report->getDataSource()) ? $this->getDataSource() : $report->getDataSource();
$type = "-t $value ";
$datafile = '';
if (!empty($report->getFile('file'))) {
$datafile .= $this->processCsvFileOptions($report);
}
$database = $this->processDatabaseOptions($report);
$parameters = $this->processReportParameters($report);
$this->shellCommand = $this->executablePath . " pr -o $processedFullPath $compiledFullPath $format $type $database $datafile $parameters";
if (!$skipExec) {
$oldcwd = getcwd();
chdir($this->sourcePath);
$error = shell_exec(escapeshellcmd($this->shellCommand));
chdir($oldcwd);
if (!empty($error)) {
throw new \Exception($error);
}
}
return $processedFullPath . '.' . $report->getTargetType();
} | php | public function process (Report $report, bool $skipExec = false)
{
$compiledFullPath = $this->compiledPath . DIRECTORY_SEPARATOR . pathinfo($report->getSourceFile(), PATHINFO_FILENAME) . '.jasper';
$processedFullPath = $this->processedPath . DIRECTORY_SEPARATOR . uniqid('ASB');
$format = ' -f ' . $report->getTargetType();
$value = empty($report->getDataSource()) ? $this->getDataSource() : $report->getDataSource();
$type = "-t $value ";
$datafile = '';
if (!empty($report->getFile('file'))) {
$datafile .= $this->processCsvFileOptions($report);
}
$database = $this->processDatabaseOptions($report);
$parameters = $this->processReportParameters($report);
$this->shellCommand = $this->executablePath . " pr -o $processedFullPath $compiledFullPath $format $type $database $datafile $parameters";
if (!$skipExec) {
$oldcwd = getcwd();
chdir($this->sourcePath);
$error = shell_exec(escapeshellcmd($this->shellCommand));
chdir($oldcwd);
if (!empty($error)) {
throw new \Exception($error);
}
}
return $processedFullPath . '.' . $report->getTargetType();
} | [
"public",
"function",
"process",
"(",
"Report",
"$",
"report",
",",
"bool",
"$",
"skipExec",
"=",
"false",
")",
"{",
"$",
"compiledFullPath",
"=",
"$",
"this",
"->",
"compiledPath",
".",
"DIRECTORY_SEPARATOR",
".",
"pathinfo",
"(",
"$",
"report",
"->",
"getSourceFile",
"(",
")",
",",
"PATHINFO_FILENAME",
")",
".",
"'.jasper'",
";",
"$",
"processedFullPath",
"=",
"$",
"this",
"->",
"processedPath",
".",
"DIRECTORY_SEPARATOR",
".",
"uniqid",
"(",
"'ASB'",
")",
";",
"$",
"format",
"=",
"' -f '",
".",
"$",
"report",
"->",
"getTargetType",
"(",
")",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDataSource",
"(",
")",
")",
"?",
"$",
"this",
"->",
"getDataSource",
"(",
")",
":",
"$",
"report",
"->",
"getDataSource",
"(",
")",
";",
"$",
"type",
"=",
"\"-t $value \"",
";",
"$",
"datafile",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"report",
"->",
"getFile",
"(",
"'file'",
")",
")",
")",
"{",
"$",
"datafile",
".=",
"$",
"this",
"->",
"processCsvFileOptions",
"(",
"$",
"report",
")",
";",
"}",
"$",
"database",
"=",
"$",
"this",
"->",
"processDatabaseOptions",
"(",
"$",
"report",
")",
";",
"$",
"parameters",
"=",
"$",
"this",
"->",
"processReportParameters",
"(",
"$",
"report",
")",
";",
"$",
"this",
"->",
"shellCommand",
"=",
"$",
"this",
"->",
"executablePath",
".",
"\" pr -o $processedFullPath $compiledFullPath $format $type $database $datafile $parameters\"",
";",
"if",
"(",
"!",
"$",
"skipExec",
")",
"{",
"$",
"oldcwd",
"=",
"getcwd",
"(",
")",
";",
"chdir",
"(",
"$",
"this",
"->",
"sourcePath",
")",
";",
"$",
"error",
"=",
"shell_exec",
"(",
"escapeshellcmd",
"(",
"$",
"this",
"->",
"shellCommand",
")",
")",
";",
"chdir",
"(",
"$",
"oldcwd",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"error",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"error",
")",
";",
"}",
"}",
"return",
"$",
"processedFullPath",
".",
"'.'",
".",
"$",
"report",
"->",
"getTargetType",
"(",
")",
";",
"}"
] | Process JASPER file into PDF or similar output format.
@return $this | [
"Process",
"JASPER",
"file",
"into",
"PDF",
"or",
"similar",
"output",
"format",
"."
] | train | https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/Starter.php#L102-L134 |
simplisti/jasper-starter | src/Starter.php | Starter.processCsvFileOptions | protected function processCsvFileOptions (Report $report)
{
$value = $report->getFile('file');
$csvSwitch = "--data-file $value ";
// NOTE: If column headers array is empty than we assume CSV first row
$value = $report->getCsvfile('columnHeaderNames');
if (empty($value)) {
$csvSwitch .= '--csv-first-row ';
}
else {
$csvSwitch .= "--csv-columns " . implode(',', $value) . ' ';
}
$value = $report->getCsvfile('charSet');
$database = "--csv-charset $value ";
$value = $report->getCsvfile('delimField');
$database = "--csv-field-del $value ";
$value = $report->getCsvfile('delimNewLine');
$database = "--csv-record-del $value ";
return $csvSwitch;
} | php | protected function processCsvFileOptions (Report $report)
{
$value = $report->getFile('file');
$csvSwitch = "--data-file $value ";
// NOTE: If column headers array is empty than we assume CSV first row
$value = $report->getCsvfile('columnHeaderNames');
if (empty($value)) {
$csvSwitch .= '--csv-first-row ';
}
else {
$csvSwitch .= "--csv-columns " . implode(',', $value) . ' ';
}
$value = $report->getCsvfile('charSet');
$database = "--csv-charset $value ";
$value = $report->getCsvfile('delimField');
$database = "--csv-field-del $value ";
$value = $report->getCsvfile('delimNewLine');
$database = "--csv-record-del $value ";
return $csvSwitch;
} | [
"protected",
"function",
"processCsvFileOptions",
"(",
"Report",
"$",
"report",
")",
"{",
"$",
"value",
"=",
"$",
"report",
"->",
"getFile",
"(",
"'file'",
")",
";",
"$",
"csvSwitch",
"=",
"\"--data-file $value \"",
";",
"// NOTE: If column headers array is empty than we assume CSV first row\r",
"$",
"value",
"=",
"$",
"report",
"->",
"getCsvfile",
"(",
"'columnHeaderNames'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"csvSwitch",
".=",
"'--csv-first-row '",
";",
"}",
"else",
"{",
"$",
"csvSwitch",
".=",
"\"--csv-columns \"",
".",
"implode",
"(",
"','",
",",
"$",
"value",
")",
".",
"' '",
";",
"}",
"$",
"value",
"=",
"$",
"report",
"->",
"getCsvfile",
"(",
"'charSet'",
")",
";",
"$",
"database",
"=",
"\"--csv-charset $value \"",
";",
"$",
"value",
"=",
"$",
"report",
"->",
"getCsvfile",
"(",
"'delimField'",
")",
";",
"$",
"database",
"=",
"\"--csv-field-del $value \"",
";",
"$",
"value",
"=",
"$",
"report",
"->",
"getCsvfile",
"(",
"'delimNewLine'",
")",
";",
"$",
"database",
"=",
"\"--csv-record-del $value \"",
";",
"return",
"$",
"csvSwitch",
";",
"}"
] | Process CSV file details
@return $this | [
"Process",
"CSV",
"file",
"details"
] | train | https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/Starter.php#L141-L165 |
simplisti/jasper-starter | src/Starter.php | Starter.processDatabaseOptions | protected function processDatabaseOptions (Report $report)
{
// NOTE: Check whether database connection details have been set
if (false === $this->getDatabase('name') && false === $report->getDatabase('name')) {
return '';
}
// NOTE: Initialize $value for each command option testing the individual
// report values for emptiness and defaulting to controlling object
$database = '';
$value = empty($report->getDatabase('host')) ? $this->getDatabase('host') : $report->getDatabase('host');
$database .= empty($value) ? '' : "-H $value ";
$value = empty($report->getDatabase('user')) ? $this->getDatabase('user') : $report->getDatabase('user');
$database .= empty($value) ? '' : "-u $value ";
$value = empty($report->getDatabase('pass')) ? $this->getDatabase('pass') : $report->getDatabase('pass');
$database .= empty($value) ? '' : "-p $value ";
$value = empty($report->getDatabase('name')) ? $this->getDatabase('name') : $report->getDatabase('name');
$database .= empty($value) ? '' : "-n $value ";
$value = empty($report->getDatabase('port')) ? $this->getDatabase('port') : $report->getDatabase('port');
$database .= empty($value) ? '' : "--db-port $value ";
// JDBC options
$value = empty($report->getDatabase('url')) ? $this->getDatabase('url') : $report->getDatabase('url');
$database .= empty($value) ? '' : "--db-url $value";
$value = empty($report->getDatabase('dir')) ? $this->getDatabase('dir') : $report->getDatabase('dir');
$database .= empty($value) ? '' : "--jdbc-dir $value ";
$value = empty($report->getDatabase('class')) ? $this->getDatabase('class') : $report->getDatabase('class');
$database .= empty($value) ? '' : "--db-driver $value ";
// Oracle SID
$value = empty($report->getDatabase('sid')) ? $this->getDatabase('sid') : $report->getDatabase('sid');
$database .= empty($value) ? '' : "--db-sid $value ";
return $database;
} | php | protected function processDatabaseOptions (Report $report)
{
// NOTE: Check whether database connection details have been set
if (false === $this->getDatabase('name') && false === $report->getDatabase('name')) {
return '';
}
// NOTE: Initialize $value for each command option testing the individual
// report values for emptiness and defaulting to controlling object
$database = '';
$value = empty($report->getDatabase('host')) ? $this->getDatabase('host') : $report->getDatabase('host');
$database .= empty($value) ? '' : "-H $value ";
$value = empty($report->getDatabase('user')) ? $this->getDatabase('user') : $report->getDatabase('user');
$database .= empty($value) ? '' : "-u $value ";
$value = empty($report->getDatabase('pass')) ? $this->getDatabase('pass') : $report->getDatabase('pass');
$database .= empty($value) ? '' : "-p $value ";
$value = empty($report->getDatabase('name')) ? $this->getDatabase('name') : $report->getDatabase('name');
$database .= empty($value) ? '' : "-n $value ";
$value = empty($report->getDatabase('port')) ? $this->getDatabase('port') : $report->getDatabase('port');
$database .= empty($value) ? '' : "--db-port $value ";
// JDBC options
$value = empty($report->getDatabase('url')) ? $this->getDatabase('url') : $report->getDatabase('url');
$database .= empty($value) ? '' : "--db-url $value";
$value = empty($report->getDatabase('dir')) ? $this->getDatabase('dir') : $report->getDatabase('dir');
$database .= empty($value) ? '' : "--jdbc-dir $value ";
$value = empty($report->getDatabase('class')) ? $this->getDatabase('class') : $report->getDatabase('class');
$database .= empty($value) ? '' : "--db-driver $value ";
// Oracle SID
$value = empty($report->getDatabase('sid')) ? $this->getDatabase('sid') : $report->getDatabase('sid');
$database .= empty($value) ? '' : "--db-sid $value ";
return $database;
} | [
"protected",
"function",
"processDatabaseOptions",
"(",
"Report",
"$",
"report",
")",
"{",
"// NOTE: Check whether database connection details have been set\r",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"getDatabase",
"(",
"'name'",
")",
"&&",
"false",
"===",
"$",
"report",
"->",
"getDatabase",
"(",
"'name'",
")",
")",
"{",
"return",
"''",
";",
"}",
"// NOTE: Initialize $value for each command option testing the individual \r",
"// report values for emptiness and defaulting to controlling object\r",
"$",
"database",
"=",
"''",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'host'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'host'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'host'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"-H $value \"",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'user'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'user'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'user'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"-u $value \"",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'pass'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'pass'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'pass'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"-p $value \"",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'name'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'name'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'name'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"-n $value \"",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'port'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'port'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'port'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"--db-port $value \"",
";",
"// JDBC options\r",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'url'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'url'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'url'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"--db-url $value\"",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'dir'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'dir'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'dir'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"--jdbc-dir $value \"",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'class'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'class'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'class'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"--db-driver $value \"",
";",
"// Oracle SID\r",
"$",
"value",
"=",
"empty",
"(",
"$",
"report",
"->",
"getDatabase",
"(",
"'sid'",
")",
")",
"?",
"$",
"this",
"->",
"getDatabase",
"(",
"'sid'",
")",
":",
"$",
"report",
"->",
"getDatabase",
"(",
"'sid'",
")",
";",
"$",
"database",
".=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"\"--db-sid $value \"",
";",
"return",
"$",
"database",
";",
"}"
] | Process RDBMS file details (ie: mysql, etc)
@return $this | [
"Process",
"RDBMS",
"file",
"details",
"(",
"ie",
":",
"mysql",
"etc",
")"
] | train | https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/Starter.php#L172-L213 |
simplisti/jasper-starter | src/Starter.php | Starter.processReportParameters | protected function processReportParameters (Report $report)
{
// NOTE: Remove parameters which have NULL values, etc
$globalParameters = $this->resetEmptyParameters();
$reportParameters = $report->resetEmptyParameters();
// NOTE: Report parameters will over-write the global Starter parameters
$mergedParameters = array_merge($globalParameters, $reportParameters);
$parameters = '';
if (!empty($mergedParameters)) {
$parameters = '-P ';
foreach ($mergedParameters as $name => $value) {
$value = is_numeric($value) ? $value : "'$value'";
$parameters .= "$name=$value ";
}
}
return $parameters;
} | php | protected function processReportParameters (Report $report)
{
// NOTE: Remove parameters which have NULL values, etc
$globalParameters = $this->resetEmptyParameters();
$reportParameters = $report->resetEmptyParameters();
// NOTE: Report parameters will over-write the global Starter parameters
$mergedParameters = array_merge($globalParameters, $reportParameters);
$parameters = '';
if (!empty($mergedParameters)) {
$parameters = '-P ';
foreach ($mergedParameters as $name => $value) {
$value = is_numeric($value) ? $value : "'$value'";
$parameters .= "$name=$value ";
}
}
return $parameters;
} | [
"protected",
"function",
"processReportParameters",
"(",
"Report",
"$",
"report",
")",
"{",
"// NOTE: Remove parameters which have NULL values, etc\r",
"$",
"globalParameters",
"=",
"$",
"this",
"->",
"resetEmptyParameters",
"(",
")",
";",
"$",
"reportParameters",
"=",
"$",
"report",
"->",
"resetEmptyParameters",
"(",
")",
";",
"// NOTE: Report parameters will over-write the global Starter parameters\r",
"$",
"mergedParameters",
"=",
"array_merge",
"(",
"$",
"globalParameters",
",",
"$",
"reportParameters",
")",
";",
"$",
"parameters",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"mergedParameters",
")",
")",
"{",
"$",
"parameters",
"=",
"'-P '",
";",
"foreach",
"(",
"$",
"mergedParameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"is_numeric",
"(",
"$",
"value",
")",
"?",
"$",
"value",
":",
"\"'$value'\"",
";",
"$",
"parameters",
".=",
"\"$name=$value \"",
";",
"}",
"}",
"return",
"$",
"parameters",
";",
"}"
] | Process parameters
@return $this | [
"Process",
"parameters"
] | train | https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/Starter.php#L220-L239 |
crypto-markets/common | src/Common/Client.php | Client.createRequest | public function createRequest($method, $uri, array $headers = [], $body = null, $protocol = '1.1')
{
if (is_array($body)) {
$body = http_build_query($body, '', '&');
}
if ($method == 'GET') {
$uri .= ((strpos('?', $uri) === false) ? '?' : '&').$body;
$body = '';
}
return $this->requestFactory->createRequest($method, $uri, $headers, $body, $protocol);
} | php | public function createRequest($method, $uri, array $headers = [], $body = null, $protocol = '1.1')
{
if (is_array($body)) {
$body = http_build_query($body, '', '&');
}
if ($method == 'GET') {
$uri .= ((strpos('?', $uri) === false) ? '?' : '&').$body;
$body = '';
}
return $this->requestFactory->createRequest($method, $uri, $headers, $body, $protocol);
} | [
"public",
"function",
"createRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
",",
"$",
"protocol",
"=",
"'1.1'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"body",
")",
")",
"{",
"$",
"body",
"=",
"http_build_query",
"(",
"$",
"body",
",",
"''",
",",
"'&'",
")",
";",
"}",
"if",
"(",
"$",
"method",
"==",
"'GET'",
")",
"{",
"$",
"uri",
".=",
"(",
"(",
"strpos",
"(",
"'?'",
",",
"$",
"uri",
")",
"===",
"false",
")",
"?",
"'?'",
":",
"'&'",
")",
".",
"$",
"body",
";",
"$",
"body",
"=",
"''",
";",
"}",
"return",
"$",
"this",
"->",
"requestFactory",
"->",
"createRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"protocol",
")",
";",
"}"
] | Creates a new PSR-7 request.
@param string $method
@param mixed $uri
@param array $headers
@param mixed $body
@param string $protocol
@return \Psr\Http\Message\RequestInterface | [
"Creates",
"a",
"new",
"PSR",
"-",
"7",
"request",
"."
] | train | https://github.com/crypto-markets/common/blob/206b1d9b88502d3fb73cef1323cd086156d3e633/src/Common/Client.php#L47-L59 |
webforge-labs/psc-cms | lib/Psc/PSC.php | PSC.getRoot | public static function getRoot() {
if (!isset(self::$root)) {
try {
$root = getenv('PSC_CMS');
if (!empty($root)) {
return self::$root = new Dir($root);
}
} catch (\Webforge\Common\System\Exception $e) {}
throw MissingEnvironmentVariableException::factory('PSC_CMS', 'The variable should reference a directory, where the host-config.php can live. Use trailing slash/backslash.');
}
return self::$root;
} | php | public static function getRoot() {
if (!isset(self::$root)) {
try {
$root = getenv('PSC_CMS');
if (!empty($root)) {
return self::$root = new Dir($root);
}
} catch (\Webforge\Common\System\Exception $e) {}
throw MissingEnvironmentVariableException::factory('PSC_CMS', 'The variable should reference a directory, where the host-config.php can live. Use trailing slash/backslash.');
}
return self::$root;
} | [
"public",
"static",
"function",
"getRoot",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"root",
")",
")",
"{",
"try",
"{",
"$",
"root",
"=",
"getenv",
"(",
"'PSC_CMS'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"root",
")",
")",
"{",
"return",
"self",
"::",
"$",
"root",
"=",
"new",
"Dir",
"(",
"$",
"root",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Webforge",
"\\",
"Common",
"\\",
"System",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"throw",
"MissingEnvironmentVariableException",
"::",
"factory",
"(",
"'PSC_CMS'",
",",
"'The variable should reference a directory, where the host-config.php can live. Use trailing slash/backslash.'",
")",
";",
"}",
"return",
"self",
"::",
"$",
"root",
";",
"}"
] | Returns the root directory of the host where the host-config lives
@return Psc\System\Directory
@throws Psc\MissingEnvironmentVariableException | [
"Returns",
"the",
"root",
"directory",
"of",
"the",
"host",
"where",
"the",
"host",
"-",
"config",
"lives"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PSC.php#L90-L106 |
webforge-labs/psc-cms | lib/Psc/PSC.php | PSC.getFullClassName | public static function getFullClassName(File $classFile, Dir $classPath = NULL) {
$classPath = $classPath ?: self::getProject()->getClassPath()->up();
try {
$parts = $classFile->getDirectory()->makeRelativeTo($classPath)->getPathArray();
} catch (\Webforge\Common\System\Exception $e) {
throw new Exception('ClassFile: "'.$classFile.'" liegt nicht im Verzeichnis: "'.$classPath.'"!',0,$e);
}
array_shift($parts); // den . entfernen
$parts[] = $classFile->getName(File::WITHOUT_EXTENSION);
$className = '\\'.implode('\\',$parts);
return $className;
} | php | public static function getFullClassName(File $classFile, Dir $classPath = NULL) {
$classPath = $classPath ?: self::getProject()->getClassPath()->up();
try {
$parts = $classFile->getDirectory()->makeRelativeTo($classPath)->getPathArray();
} catch (\Webforge\Common\System\Exception $e) {
throw new Exception('ClassFile: "'.$classFile.'" liegt nicht im Verzeichnis: "'.$classPath.'"!',0,$e);
}
array_shift($parts); // den . entfernen
$parts[] = $classFile->getName(File::WITHOUT_EXTENSION);
$className = '\\'.implode('\\',$parts);
return $className;
} | [
"public",
"static",
"function",
"getFullClassName",
"(",
"File",
"$",
"classFile",
",",
"Dir",
"$",
"classPath",
"=",
"NULL",
")",
"{",
"$",
"classPath",
"=",
"$",
"classPath",
"?",
":",
"self",
"::",
"getProject",
"(",
")",
"->",
"getClassPath",
"(",
")",
"->",
"up",
"(",
")",
";",
"try",
"{",
"$",
"parts",
"=",
"$",
"classFile",
"->",
"getDirectory",
"(",
")",
"->",
"makeRelativeTo",
"(",
"$",
"classPath",
")",
"->",
"getPathArray",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Webforge",
"\\",
"Common",
"\\",
"System",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'ClassFile: \"'",
".",
"$",
"classFile",
".",
"'\" liegt nicht im Verzeichnis: \"'",
".",
"$",
"classPath",
".",
"'\"!'",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"array_shift",
"(",
"$",
"parts",
")",
";",
"// den . entfernen",
"$",
"parts",
"[",
"]",
"=",
"$",
"classFile",
"->",
"getName",
"(",
"File",
"::",
"WITHOUT_EXTENSION",
")",
";",
"$",
"className",
"=",
"'\\\\'",
".",
"implode",
"(",
"'\\\\'",
",",
"$",
"parts",
")",
";",
"return",
"$",
"className",
";",
"}"
] | Gibt den vollen Namen der Klasse aus der Datei zurück
dies parsed nicht den Code der Datei, sondern geht von der Klassen-Struktur wie in Konventionen beschrieben aus
@return string | [
"Gibt",
"den",
"vollen",
"Namen",
"der",
"Klasse",
"aus",
"der",
"Datei",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PSC.php#L224-L237 |
geekwright/Po | src/PoFile.php | PoFile.createKey | public static function createKey(?string $msgid, ?string $msgctxt = null, ?string $msgid_plural = null): string
{
$key = '';
if (!empty($msgctxt)) {
$key .= $msgctxt . '|';
}
$key .= (string) $msgid;
if (!empty($msgid_plural)) {
$key .= '|' . $msgid_plural;
}
return $key;
} | php | public static function createKey(?string $msgid, ?string $msgctxt = null, ?string $msgid_plural = null): string
{
$key = '';
if (!empty($msgctxt)) {
$key .= $msgctxt . '|';
}
$key .= (string) $msgid;
if (!empty($msgid_plural)) {
$key .= '|' . $msgid_plural;
}
return $key;
} | [
"public",
"static",
"function",
"createKey",
"(",
"?",
"string",
"$",
"msgid",
",",
"?",
"string",
"$",
"msgctxt",
"=",
"null",
",",
"?",
"string",
"$",
"msgid_plural",
"=",
"null",
")",
":",
"string",
"{",
"$",
"key",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"msgctxt",
")",
")",
"{",
"$",
"key",
".=",
"$",
"msgctxt",
".",
"'|'",
";",
"}",
"$",
"key",
".=",
"(",
"string",
")",
"$",
"msgid",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"msgid_plural",
")",
")",
"{",
"$",
"key",
".=",
"'|'",
".",
"$",
"msgid_plural",
";",
"}",
"return",
"$",
"key",
";",
"}"
] | Build the internal entries array key from id, context and plural id
@param string|null $msgid the untranslated message of the entry
@param string|null $msgctxt the context of the entry, if any
@param string|null $msgid_plural the untranslated plural message of the entry, if any
@return string | [
"Build",
"the",
"internal",
"entries",
"array",
"key",
"from",
"id",
"context",
"and",
"plural",
"id"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L72-L83 |
geekwright/Po | src/PoFile.php | PoFile.createKeyFromEntry | public function createKeyFromEntry(PoEntry $entry): string
{
return $this->createKey(
$entry->getAsString(PoTokens::MESSAGE),
$entry->getAsString(PoTokens::CONTEXT),
$entry->getAsString(PoTokens::PLURAL)
);
} | php | public function createKeyFromEntry(PoEntry $entry): string
{
return $this->createKey(
$entry->getAsString(PoTokens::MESSAGE),
$entry->getAsString(PoTokens::CONTEXT),
$entry->getAsString(PoTokens::PLURAL)
);
} | [
"public",
"function",
"createKeyFromEntry",
"(",
"PoEntry",
"$",
"entry",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"createKey",
"(",
"$",
"entry",
"->",
"getAsString",
"(",
"PoTokens",
"::",
"MESSAGE",
")",
",",
"$",
"entry",
"->",
"getAsString",
"(",
"PoTokens",
"::",
"CONTEXT",
")",
",",
"$",
"entry",
"->",
"getAsString",
"(",
"PoTokens",
"::",
"PLURAL",
")",
")",
";",
"}"
] | Build an internal entries array key from a PoEntry
@param PoEntry $entry the PoEntry to build key from
@return string | [
"Build",
"an",
"internal",
"entries",
"array",
"key",
"from",
"a",
"PoEntry"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L92-L99 |
geekwright/Po | src/PoFile.php | PoFile.addEntry | public function addEntry(PoEntry $entry, bool $replace = true): bool
{
$key = $this->createKeyFromEntry($entry);
// some entires, such as obsolete entries, have no key
// for some uses, these are dead weight - need better strategy for that case
if (empty($key)) {
$this->unkeyedEntries[] = $entry;
return true;
}
if (isset($this->entries[$key]) && !$replace) {
return false;
} else {
$this->entries[$key] = $entry;
return true;
}
} | php | public function addEntry(PoEntry $entry, bool $replace = true): bool
{
$key = $this->createKeyFromEntry($entry);
// some entires, such as obsolete entries, have no key
// for some uses, these are dead weight - need better strategy for that case
if (empty($key)) {
$this->unkeyedEntries[] = $entry;
return true;
}
if (isset($this->entries[$key]) && !$replace) {
return false;
} else {
$this->entries[$key] = $entry;
return true;
}
} | [
"public",
"function",
"addEntry",
"(",
"PoEntry",
"$",
"entry",
",",
"bool",
"$",
"replace",
"=",
"true",
")",
":",
"bool",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"createKeyFromEntry",
"(",
"$",
"entry",
")",
";",
"// some entires, such as obsolete entries, have no key",
"// for some uses, these are dead weight - need better strategy for that case",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"unkeyedEntries",
"[",
"]",
"=",
"$",
"entry",
";",
"return",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"$",
"replace",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
"=",
"$",
"entry",
";",
"return",
"true",
";",
"}",
"}"
] | Add an entry to the PoFile using internal key
@param PoEntry $entry the PoEntry to add
@param boolean $replace true to replace any existing entry matching this key,
false to not change the PoFile for a duplicated key
@return boolean true if added, false if not | [
"Add",
"an",
"entry",
"to",
"the",
"PoFile",
"using",
"internal",
"key"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L164-L181 |
geekwright/Po | src/PoFile.php | PoFile.mergeEntry | public function mergeEntry(PoEntry $newEntry): bool
{
$key = $this->createKeyFromEntry($newEntry);
// keyed entries only
if (empty($key)) {
return false;
}
if (isset($this->entries[$key])) {
$existingEntry = $this->entries[$key];
$mergeTokens = array(PoTokens::REFERENCE, PoTokens::EXTRACTED_COMMENTS);
foreach ($mergeTokens as $type) {
$toMerge = $newEntry->get($type);
if (!empty($toMerge)) {
$toMerge = is_array($toMerge) ? $toMerge : array($toMerge);
foreach ($toMerge as $value) {
$existingEntry->add($type, $value);
}
}
}
} else {
$this->entries[$key] = $newEntry;
}
return true;
} | php | public function mergeEntry(PoEntry $newEntry): bool
{
$key = $this->createKeyFromEntry($newEntry);
// keyed entries only
if (empty($key)) {
return false;
}
if (isset($this->entries[$key])) {
$existingEntry = $this->entries[$key];
$mergeTokens = array(PoTokens::REFERENCE, PoTokens::EXTRACTED_COMMENTS);
foreach ($mergeTokens as $type) {
$toMerge = $newEntry->get($type);
if (!empty($toMerge)) {
$toMerge = is_array($toMerge) ? $toMerge : array($toMerge);
foreach ($toMerge as $value) {
$existingEntry->add($type, $value);
}
}
}
} else {
$this->entries[$key] = $newEntry;
}
return true;
} | [
"public",
"function",
"mergeEntry",
"(",
"PoEntry",
"$",
"newEntry",
")",
":",
"bool",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"createKeyFromEntry",
"(",
"$",
"newEntry",
")",
";",
"// keyed entries only",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"existingEntry",
"=",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
";",
"$",
"mergeTokens",
"=",
"array",
"(",
"PoTokens",
"::",
"REFERENCE",
",",
"PoTokens",
"::",
"EXTRACTED_COMMENTS",
")",
";",
"foreach",
"(",
"$",
"mergeTokens",
"as",
"$",
"type",
")",
"{",
"$",
"toMerge",
"=",
"$",
"newEntry",
"->",
"get",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"toMerge",
")",
")",
"{",
"$",
"toMerge",
"=",
"is_array",
"(",
"$",
"toMerge",
")",
"?",
"$",
"toMerge",
":",
"array",
"(",
"$",
"toMerge",
")",
";",
"foreach",
"(",
"$",
"toMerge",
"as",
"$",
"value",
")",
"{",
"$",
"existingEntry",
"->",
"add",
"(",
"$",
"type",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
"=",
"$",
"newEntry",
";",
"}",
"return",
"true",
";",
"}"
] | Merge an entry with any existing entry with the same key. If the key does
not exist, add the entry, otherwise merge comments, references, and flags.
This is intended for use in building a POT, where the handling of translated
strings is not a factor.
@param PoEntry $newEntry the PoEntry to merge
@return boolean true if merged or added, false if not | [
"Merge",
"an",
"entry",
"with",
"any",
"existing",
"entry",
"with",
"the",
"same",
"key",
".",
"If",
"the",
"key",
"does",
"not",
"exist",
"add",
"the",
"entry",
"otherwise",
"merge",
"comments",
"references",
"and",
"flags",
"."
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L194-L219 |
geekwright/Po | src/PoFile.php | PoFile.findEntry | public function findEntry(string $msgid, ?string $msgctxt = null, ?string $msgid_plural = null): ?PoEntry
{
$key = $this->createKey($msgid, $msgctxt, $msgid_plural);
$entry = null;
if (!empty($key) && isset($this->entries[$key])) {
$entry = $this->entries[$key];
}
return $entry;
} | php | public function findEntry(string $msgid, ?string $msgctxt = null, ?string $msgid_plural = null): ?PoEntry
{
$key = $this->createKey($msgid, $msgctxt, $msgid_plural);
$entry = null;
if (!empty($key) && isset($this->entries[$key])) {
$entry = $this->entries[$key];
}
return $entry;
} | [
"public",
"function",
"findEntry",
"(",
"string",
"$",
"msgid",
",",
"?",
"string",
"$",
"msgctxt",
"=",
"null",
",",
"?",
"string",
"$",
"msgid_plural",
"=",
"null",
")",
":",
"?",
"PoEntry",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"createKey",
"(",
"$",
"msgid",
",",
"$",
"msgctxt",
",",
"$",
"msgid_plural",
")",
";",
"$",
"entry",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"key",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"entry",
";",
"}"
] | Get an entry based on key values - msgid, msgctxt and msgid_plural
@param string $msgid the untranslated message of the entry
@param string|null $msgctxt the context of the entry, if any
@param string|null $msgid_plural the untranslated plural message of the entry, if any
@return PoEntry|null matching entry, or null if not found | [
"Get",
"an",
"entry",
"based",
"on",
"key",
"values",
"-",
"msgid",
"msgctxt",
"and",
"msgid_plural"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L230-L240 |
geekwright/Po | src/PoFile.php | PoFile.removeEntry | public function removeEntry(PoEntry $entry): bool
{
$key = $this->createKeyFromEntry($entry);
// try by the key first.
if (!empty($key) && isset($this->entries[$key])) {
if ($entry === $this->entries[$key]) {
unset($this->entries[$key]);
return true;
}
}
// the entry can't be matched by key, so we have to loop :(
foreach ($this->entries as $key => $value) {
if ($entry === $value) {
unset($this->entries[$key]);
return true;
}
}
// no match found in main entries, try the unkeyedEntries
foreach ($this->unkeyedEntries as $key => $value) {
if ($entry === $value) {
unset($this->unkeyedEntries[$key]);
return true;
}
}
return false;
} | php | public function removeEntry(PoEntry $entry): bool
{
$key = $this->createKeyFromEntry($entry);
// try by the key first.
if (!empty($key) && isset($this->entries[$key])) {
if ($entry === $this->entries[$key]) {
unset($this->entries[$key]);
return true;
}
}
// the entry can't be matched by key, so we have to loop :(
foreach ($this->entries as $key => $value) {
if ($entry === $value) {
unset($this->entries[$key]);
return true;
}
}
// no match found in main entries, try the unkeyedEntries
foreach ($this->unkeyedEntries as $key => $value) {
if ($entry === $value) {
unset($this->unkeyedEntries[$key]);
return true;
}
}
return false;
} | [
"public",
"function",
"removeEntry",
"(",
"PoEntry",
"$",
"entry",
")",
":",
"bool",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"createKeyFromEntry",
"(",
"$",
"entry",
")",
";",
"// try by the key first.",
"if",
"(",
"!",
"empty",
"(",
"$",
"key",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"$",
"entry",
"===",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"}",
"// the entry can't be matched by key, so we have to loop :(",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"entry",
"===",
"$",
"value",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"}",
"// no match found in main entries, try the unkeyedEntries",
"foreach",
"(",
"$",
"this",
"->",
"unkeyedEntries",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"entry",
"===",
"$",
"value",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"unkeyedEntries",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Remove an entry from the PoFile
In simple cases, the entry can be found by key. There are several cases
where it is not that easy to locate the PoEntry to be removed:
- the PoEntry was altered, making the generated and stored key different
- the entry is not keyed and is in unkeyedEntries
In any of these cases, we must loop thru the entry arrays looking for an
exact object match, so the cost of the remove goes up
@param PoEntry $entry the PoEntry to merge
@return boolean true if remove, false if not | [
"Remove",
"an",
"entry",
"from",
"the",
"PoFile"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L257-L286 |
geekwright/Po | src/PoFile.php | PoFile.writePoFile | public function writePoFile(string $file): void
{
$source = $this->dumpString();
$testName = file_exists($file) ? $file : dirname($file);
$status = is_writable($testName);
if ($status === true) {
$status = file_put_contents($file, $source);
}
if (false === $status) {
throw new FileNotWritableException($file);
}
} | php | public function writePoFile(string $file): void
{
$source = $this->dumpString();
$testName = file_exists($file) ? $file : dirname($file);
$status = is_writable($testName);
if ($status === true) {
$status = file_put_contents($file, $source);
}
if (false === $status) {
throw new FileNotWritableException($file);
}
} | [
"public",
"function",
"writePoFile",
"(",
"string",
"$",
"file",
")",
":",
"void",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"dumpString",
"(",
")",
";",
"$",
"testName",
"=",
"file_exists",
"(",
"$",
"file",
")",
"?",
"$",
"file",
":",
"dirname",
"(",
"$",
"file",
")",
";",
"$",
"status",
"=",
"is_writable",
"(",
"$",
"testName",
")",
";",
"if",
"(",
"$",
"status",
"===",
"true",
")",
"{",
"$",
"status",
"=",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"source",
")",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"status",
")",
"{",
"throw",
"new",
"FileNotWritableException",
"(",
"$",
"file",
")",
";",
"}",
"}"
] | Write any current contents to a po file
@param string $file po file to write
@return void
@throws FileNotWritableException | [
"Write",
"any",
"current",
"contents",
"to",
"a",
"po",
"file"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L297-L308 |
geekwright/Po | src/PoFile.php | PoFile.dumpString | public function dumpString(): string
{
if ($this->header === null) {
$this->header = new PoHeader;
$this->header->buildDefaultHeader();
}
$output = '';
$output .= $this->header->dumpEntry();
foreach ($this->entries as $entry) {
$output .= $entry->dumpEntry();
}
foreach ($this->unkeyedEntries as $entry) {
$output .= $entry->dumpEntry();
}
$output .= "\n";
return $output;
} | php | public function dumpString(): string
{
if ($this->header === null) {
$this->header = new PoHeader;
$this->header->buildDefaultHeader();
}
$output = '';
$output .= $this->header->dumpEntry();
foreach ($this->entries as $entry) {
$output .= $entry->dumpEntry();
}
foreach ($this->unkeyedEntries as $entry) {
$output .= $entry->dumpEntry();
}
$output .= "\n";
return $output;
} | [
"public",
"function",
"dumpString",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"header",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"header",
"=",
"new",
"PoHeader",
";",
"$",
"this",
"->",
"header",
"->",
"buildDefaultHeader",
"(",
")",
";",
"}",
"$",
"output",
"=",
"''",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"header",
"->",
"dumpEntry",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"entry",
")",
"{",
"$",
"output",
".=",
"$",
"entry",
"->",
"dumpEntry",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"unkeyedEntries",
"as",
"$",
"entry",
")",
"{",
"$",
"output",
".=",
"$",
"entry",
"->",
"dumpEntry",
"(",
")",
";",
"}",
"$",
"output",
".=",
"\"\\n\"",
";",
"return",
"$",
"output",
";",
"}"
] | Dump the current contents in PO format to a string
@return string | [
"Dump",
"the",
"current",
"contents",
"in",
"PO",
"format",
"to",
"a",
"string"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L315-L333 |
geekwright/Po | src/PoFile.php | PoFile.readPoFile | public function readPoFile(string $file, ?resource $context = null): void
{
$oldEr = error_reporting(E_ALL ^ E_WARNING);
$source = file_get_contents($file, false, $context);
error_reporting($oldEr);
if (false===$source) {
throw new FileNotReadableException($file);
}
$this->parsePoSource($source);
} | php | public function readPoFile(string $file, ?resource $context = null): void
{
$oldEr = error_reporting(E_ALL ^ E_WARNING);
$source = file_get_contents($file, false, $context);
error_reporting($oldEr);
if (false===$source) {
throw new FileNotReadableException($file);
}
$this->parsePoSource($source);
} | [
"public",
"function",
"readPoFile",
"(",
"string",
"$",
"file",
",",
"?",
"resource",
"$",
"context",
"=",
"null",
")",
":",
"void",
"{",
"$",
"oldEr",
"=",
"error_reporting",
"(",
"E_ALL",
"^",
"E_WARNING",
")",
";",
"$",
"source",
"=",
"file_get_contents",
"(",
"$",
"file",
",",
"false",
",",
"$",
"context",
")",
";",
"error_reporting",
"(",
"$",
"oldEr",
")",
";",
"if",
"(",
"false",
"===",
"$",
"source",
")",
"{",
"throw",
"new",
"FileNotReadableException",
"(",
"$",
"file",
")",
";",
"}",
"$",
"this",
"->",
"parsePoSource",
"(",
"$",
"source",
")",
";",
"}"
] | Replace any current contents with entries from a file
@param string $file po file/stream to read
@param resource|null $context context for stream if required
@return void
@throws FileNotReadableException | [
"Replace",
"any",
"current",
"contents",
"with",
"entries",
"from",
"a",
"file"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L346-L355 |
geekwright/Po | src/PoFile.php | PoFile.parsePoSource | public function parsePoSource(string $source): void
{
/**
* This is an incredibly ugly regex pattern that breaks a line of a po file into
* pieces that can be analyzed and acted upon.
*
* The matches array in preg_match will break out like this:
* [0] full string
* [1] mostly useless broad match of initial token, including trailing space
* [2] bare token, or full msgstr[n] clause
* [3] 'n' of a msgstr[n] line
* [4] '"' if a data line
* [5] remaining line
* [6] a bare or malformed comment
*/
$pattern = '/(^(#|#.|#;|#,|#\||msgid|msgid_plural|msgctxt|msgstr|msgstr\[([0-9]+)\])\s|(^"))(.+)|(^#.*)/';
$source_lines = explode("\n", $source);
$wsBreak = false;
$inHeader = true;
$headerEntry = new PoHeader;
$entry = $headerEntry;
$unrecognized = array();
$lastKey = '';
$currentPlural = 0;
foreach ($source_lines as $line => $s) {
$result = preg_match($pattern, $s, $matches);
if (!$result) {
$lastKey = '';
if ($s=='' || ctype_space($s)) {
if ($inHeader) {
$this->setHeaderEntry($headerEntry);
$entry = null;
$inHeader = false;
}
if (!$wsBreak) {
if (!($entry === null)) {
$this->addEntry($entry);
}
$entry = null;
$wsBreak=true;
}
} else {
$wsBreak=false;
$unrecognized[$line+1] = $s;
}
} else {
if ($entry === null) {
$entry = new PoEntry;
}
$wsBreak=false;
$currentKey = $matches[2]; // will be used to set last key
switch ($matches[2]) {
case PoTokens::TRANSLATOR_COMMENTS:
case PoTokens::EXTRACTED_COMMENTS:
case PoTokens::REFERENCE:
case PoTokens::FLAG:
case PoTokens::OBSOLETE:
case PoTokens::PREVIOUS:
$entry->add($matches[2], $matches[5]);
break;
case PoTokens::CONTEXT:
case PoTokens::MESSAGE:
case PoTokens::PLURAL:
case PoTokens::TRANSLATED:
$entry->addQuoted($matches[2], $matches[5]);
break;
default:
if ($matches[4]==PoTokens::CONTINUED_DATA) {
$currentKey = $lastKey; // keep the previous key
if ($currentKey==PoTokens::TRANSLATED_PLURAL) {
$entry->addQuotedAtPosition(
PoTokens::TRANSLATED,
$currentPlural,
'"' . $matches[5]
);
} else {
$entry->addQuoted($currentKey, '"' . $matches[5]);
}
} elseif (substr($matches[2], 0, 7)==PoTokens::TRANSLATED_PLURAL) {
$currentKey = PoTokens::TRANSLATED_PLURAL;
$currentPlural = $matches[3];
$entry->addQuotedAtPosition(
PoTokens::TRANSLATED,
$currentPlural,
$matches[5]
);
} elseif (isset($matches[6][0])
&& $matches[6][0]==PoTokens::TRANSLATOR_COMMENTS) {
$value = substr($matches[6], 1);
$value = empty($value) ? '' : $value;
$entry->add(PoTokens::TRANSLATOR_COMMENTS, $value);
} else {
$unrecognized[$line+1] = $s;
}
break;
}
$lastKey = $currentKey;
}
}
if (!($entry === null)) {
$this->addEntry($entry);
}
// throw at the very end, anything recognized has been processed
$this->unrecognizedInput = $unrecognized;
if (count($unrecognized)) {
throw new UnrecognizedInputException();
}
} | php | public function parsePoSource(string $source): void
{
/**
* This is an incredibly ugly regex pattern that breaks a line of a po file into
* pieces that can be analyzed and acted upon.
*
* The matches array in preg_match will break out like this:
* [0] full string
* [1] mostly useless broad match of initial token, including trailing space
* [2] bare token, or full msgstr[n] clause
* [3] 'n' of a msgstr[n] line
* [4] '"' if a data line
* [5] remaining line
* [6] a bare or malformed comment
*/
$pattern = '/(^(#|#.|#;|#,|#\||msgid|msgid_plural|msgctxt|msgstr|msgstr\[([0-9]+)\])\s|(^"))(.+)|(^#.*)/';
$source_lines = explode("\n", $source);
$wsBreak = false;
$inHeader = true;
$headerEntry = new PoHeader;
$entry = $headerEntry;
$unrecognized = array();
$lastKey = '';
$currentPlural = 0;
foreach ($source_lines as $line => $s) {
$result = preg_match($pattern, $s, $matches);
if (!$result) {
$lastKey = '';
if ($s=='' || ctype_space($s)) {
if ($inHeader) {
$this->setHeaderEntry($headerEntry);
$entry = null;
$inHeader = false;
}
if (!$wsBreak) {
if (!($entry === null)) {
$this->addEntry($entry);
}
$entry = null;
$wsBreak=true;
}
} else {
$wsBreak=false;
$unrecognized[$line+1] = $s;
}
} else {
if ($entry === null) {
$entry = new PoEntry;
}
$wsBreak=false;
$currentKey = $matches[2]; // will be used to set last key
switch ($matches[2]) {
case PoTokens::TRANSLATOR_COMMENTS:
case PoTokens::EXTRACTED_COMMENTS:
case PoTokens::REFERENCE:
case PoTokens::FLAG:
case PoTokens::OBSOLETE:
case PoTokens::PREVIOUS:
$entry->add($matches[2], $matches[5]);
break;
case PoTokens::CONTEXT:
case PoTokens::MESSAGE:
case PoTokens::PLURAL:
case PoTokens::TRANSLATED:
$entry->addQuoted($matches[2], $matches[5]);
break;
default:
if ($matches[4]==PoTokens::CONTINUED_DATA) {
$currentKey = $lastKey; // keep the previous key
if ($currentKey==PoTokens::TRANSLATED_PLURAL) {
$entry->addQuotedAtPosition(
PoTokens::TRANSLATED,
$currentPlural,
'"' . $matches[5]
);
} else {
$entry->addQuoted($currentKey, '"' . $matches[5]);
}
} elseif (substr($matches[2], 0, 7)==PoTokens::TRANSLATED_PLURAL) {
$currentKey = PoTokens::TRANSLATED_PLURAL;
$currentPlural = $matches[3];
$entry->addQuotedAtPosition(
PoTokens::TRANSLATED,
$currentPlural,
$matches[5]
);
} elseif (isset($matches[6][0])
&& $matches[6][0]==PoTokens::TRANSLATOR_COMMENTS) {
$value = substr($matches[6], 1);
$value = empty($value) ? '' : $value;
$entry->add(PoTokens::TRANSLATOR_COMMENTS, $value);
} else {
$unrecognized[$line+1] = $s;
}
break;
}
$lastKey = $currentKey;
}
}
if (!($entry === null)) {
$this->addEntry($entry);
}
// throw at the very end, anything recognized has been processed
$this->unrecognizedInput = $unrecognized;
if (count($unrecognized)) {
throw new UnrecognizedInputException();
}
} | [
"public",
"function",
"parsePoSource",
"(",
"string",
"$",
"source",
")",
":",
"void",
"{",
"/**\n * This is an incredibly ugly regex pattern that breaks a line of a po file into\n * pieces that can be analyzed and acted upon.\n *\n * The matches array in preg_match will break out like this:\n * [0] full string\n * [1] mostly useless broad match of initial token, including trailing space\n * [2] bare token, or full msgstr[n] clause\n * [3] 'n' of a msgstr[n] line\n * [4] '\"' if a data line\n * [5] remaining line\n * [6] a bare or malformed comment\n */",
"$",
"pattern",
"=",
"'/(^(#|#.|#;|#,|#\\||msgid|msgid_plural|msgctxt|msgstr|msgstr\\[([0-9]+)\\])\\s|(^\"))(.+)|(^#.*)/'",
";",
"$",
"source_lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"source",
")",
";",
"$",
"wsBreak",
"=",
"false",
";",
"$",
"inHeader",
"=",
"true",
";",
"$",
"headerEntry",
"=",
"new",
"PoHeader",
";",
"$",
"entry",
"=",
"$",
"headerEntry",
";",
"$",
"unrecognized",
"=",
"array",
"(",
")",
";",
"$",
"lastKey",
"=",
"''",
";",
"$",
"currentPlural",
"=",
"0",
";",
"foreach",
"(",
"$",
"source_lines",
"as",
"$",
"line",
"=>",
"$",
"s",
")",
"{",
"$",
"result",
"=",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"s",
",",
"$",
"matches",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"$",
"lastKey",
"=",
"''",
";",
"if",
"(",
"$",
"s",
"==",
"''",
"||",
"ctype_space",
"(",
"$",
"s",
")",
")",
"{",
"if",
"(",
"$",
"inHeader",
")",
"{",
"$",
"this",
"->",
"setHeaderEntry",
"(",
"$",
"headerEntry",
")",
";",
"$",
"entry",
"=",
"null",
";",
"$",
"inHeader",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"wsBreak",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"entry",
"===",
"null",
")",
")",
"{",
"$",
"this",
"->",
"addEntry",
"(",
"$",
"entry",
")",
";",
"}",
"$",
"entry",
"=",
"null",
";",
"$",
"wsBreak",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"$",
"wsBreak",
"=",
"false",
";",
"$",
"unrecognized",
"[",
"$",
"line",
"+",
"1",
"]",
"=",
"$",
"s",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"entry",
"===",
"null",
")",
"{",
"$",
"entry",
"=",
"new",
"PoEntry",
";",
"}",
"$",
"wsBreak",
"=",
"false",
";",
"$",
"currentKey",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"// will be used to set last key",
"switch",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"{",
"case",
"PoTokens",
"::",
"TRANSLATOR_COMMENTS",
":",
"case",
"PoTokens",
"::",
"EXTRACTED_COMMENTS",
":",
"case",
"PoTokens",
"::",
"REFERENCE",
":",
"case",
"PoTokens",
"::",
"FLAG",
":",
"case",
"PoTokens",
"::",
"OBSOLETE",
":",
"case",
"PoTokens",
"::",
"PREVIOUS",
":",
"$",
"entry",
"->",
"add",
"(",
"$",
"matches",
"[",
"2",
"]",
",",
"$",
"matches",
"[",
"5",
"]",
")",
";",
"break",
";",
"case",
"PoTokens",
"::",
"CONTEXT",
":",
"case",
"PoTokens",
"::",
"MESSAGE",
":",
"case",
"PoTokens",
"::",
"PLURAL",
":",
"case",
"PoTokens",
"::",
"TRANSLATED",
":",
"$",
"entry",
"->",
"addQuoted",
"(",
"$",
"matches",
"[",
"2",
"]",
",",
"$",
"matches",
"[",
"5",
"]",
")",
";",
"break",
";",
"default",
":",
"if",
"(",
"$",
"matches",
"[",
"4",
"]",
"==",
"PoTokens",
"::",
"CONTINUED_DATA",
")",
"{",
"$",
"currentKey",
"=",
"$",
"lastKey",
";",
"// keep the previous key",
"if",
"(",
"$",
"currentKey",
"==",
"PoTokens",
"::",
"TRANSLATED_PLURAL",
")",
"{",
"$",
"entry",
"->",
"addQuotedAtPosition",
"(",
"PoTokens",
"::",
"TRANSLATED",
",",
"$",
"currentPlural",
",",
"'\"'",
".",
"$",
"matches",
"[",
"5",
"]",
")",
";",
"}",
"else",
"{",
"$",
"entry",
"->",
"addQuoted",
"(",
"$",
"currentKey",
",",
"'\"'",
".",
"$",
"matches",
"[",
"5",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"matches",
"[",
"2",
"]",
",",
"0",
",",
"7",
")",
"==",
"PoTokens",
"::",
"TRANSLATED_PLURAL",
")",
"{",
"$",
"currentKey",
"=",
"PoTokens",
"::",
"TRANSLATED_PLURAL",
";",
"$",
"currentPlural",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"$",
"entry",
"->",
"addQuotedAtPosition",
"(",
"PoTokens",
"::",
"TRANSLATED",
",",
"$",
"currentPlural",
",",
"$",
"matches",
"[",
"5",
"]",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"matches",
"[",
"6",
"]",
"[",
"0",
"]",
")",
"&&",
"$",
"matches",
"[",
"6",
"]",
"[",
"0",
"]",
"==",
"PoTokens",
"::",
"TRANSLATOR_COMMENTS",
")",
"{",
"$",
"value",
"=",
"substr",
"(",
"$",
"matches",
"[",
"6",
"]",
",",
"1",
")",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"value",
")",
"?",
"''",
":",
"$",
"value",
";",
"$",
"entry",
"->",
"add",
"(",
"PoTokens",
"::",
"TRANSLATOR_COMMENTS",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"unrecognized",
"[",
"$",
"line",
"+",
"1",
"]",
"=",
"$",
"s",
";",
"}",
"break",
";",
"}",
"$",
"lastKey",
"=",
"$",
"currentKey",
";",
"}",
"}",
"if",
"(",
"!",
"(",
"$",
"entry",
"===",
"null",
")",
")",
"{",
"$",
"this",
"->",
"addEntry",
"(",
"$",
"entry",
")",
";",
"}",
"// throw at the very end, anything recognized has been processed",
"$",
"this",
"->",
"unrecognizedInput",
"=",
"$",
"unrecognized",
";",
"if",
"(",
"count",
"(",
"$",
"unrecognized",
")",
")",
"{",
"throw",
"new",
"UnrecognizedInputException",
"(",
")",
";",
"}",
"}"
] | Replace any current contents with header and entries from PO souce string
@param string $source po formatted string to parse
@return void
@throws UnrecognizedInputException | [
"Replace",
"any",
"current",
"contents",
"with",
"header",
"and",
"entries",
"from",
"PO",
"souce",
"string"
] | train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoFile.php#L366-L476 |
simple-php-mvc/simple-php-mvc | src/MVC/View.php | View.addTemplatePath | public function addTemplatePath($path)
{
if (is_array($this->templatesPath)) {
if (array_search($path, $this->templatesPath)) {
throw new \LogicException(sprintf('Templates path "%s" exists.', $path));
} else {
$this->templatesPath[] = $path;
}
} else if (is_string($this->templatesPath)) {
$lastTemplate = $this->templatesPath;
$this->templatesPath = array(
$lastTemplate, $path
);
}
} | php | public function addTemplatePath($path)
{
if (is_array($this->templatesPath)) {
if (array_search($path, $this->templatesPath)) {
throw new \LogicException(sprintf('Templates path "%s" exists.', $path));
} else {
$this->templatesPath[] = $path;
}
} else if (is_string($this->templatesPath)) {
$lastTemplate = $this->templatesPath;
$this->templatesPath = array(
$lastTemplate, $path
);
}
} | [
"public",
"function",
"addTemplatePath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"templatesPath",
")",
")",
"{",
"if",
"(",
"array_search",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"templatesPath",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Templates path \"%s\" exists.'",
",",
"$",
"path",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"templatesPath",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"templatesPath",
")",
")",
"{",
"$",
"lastTemplate",
"=",
"$",
"this",
"->",
"templatesPath",
";",
"$",
"this",
"->",
"templatesPath",
"=",
"array",
"(",
"$",
"lastTemplate",
",",
"$",
"path",
")",
";",
"}",
"}"
] | Add Template Path
@param string $path Templates path | [
"Add",
"Template",
"Path"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/View.php#L26-L40 |
simple-php-mvc/simple-php-mvc | src/MVC/View.php | View.render | public function render($file, $vars = null)
{
$template = '';
if (is_null($this->templatesPath)) {
throw new \LogicException('Variable "templatesPath" can\'t be NULL.');
} else if (is_string($this->templatesPath) && !file_exists($this->templatesPath)) {
throw new \LogicException(sprintf('Folder "%s" don\'t exists.', $this->templatesPath));
} else if (is_array($this->templatesPath)) {
foreach ($this->templatesPath as $folderPath) {
if (file_exists($template = "$folderPath/{$file}")) {
break;
}
}
}
if (!$template) {
$template = "$this->templatesPath/{$file}";
}
if(!file_exists($template)){
throw new \LogicException(sprintf('View "%s" don\'t exists.', $template));
}
if (is_array($vars)) {
extract($vars);
foreach ($vars as $key => $value) {
$key = $value;
}
}
ob_start();
require $template;
return ob_get_clean();
} | php | public function render($file, $vars = null)
{
$template = '';
if (is_null($this->templatesPath)) {
throw new \LogicException('Variable "templatesPath" can\'t be NULL.');
} else if (is_string($this->templatesPath) && !file_exists($this->templatesPath)) {
throw new \LogicException(sprintf('Folder "%s" don\'t exists.', $this->templatesPath));
} else if (is_array($this->templatesPath)) {
foreach ($this->templatesPath as $folderPath) {
if (file_exists($template = "$folderPath/{$file}")) {
break;
}
}
}
if (!$template) {
$template = "$this->templatesPath/{$file}";
}
if(!file_exists($template)){
throw new \LogicException(sprintf('View "%s" don\'t exists.', $template));
}
if (is_array($vars)) {
extract($vars);
foreach ($vars as $key => $value) {
$key = $value;
}
}
ob_start();
require $template;
return ob_get_clean();
} | [
"public",
"function",
"render",
"(",
"$",
"file",
",",
"$",
"vars",
"=",
"null",
")",
"{",
"$",
"template",
"=",
"''",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"templatesPath",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Variable \"templatesPath\" can\\'t be NULL.'",
")",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"templatesPath",
")",
"&&",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"templatesPath",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Folder \"%s\" don\\'t exists.'",
",",
"$",
"this",
"->",
"templatesPath",
")",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"templatesPath",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"templatesPath",
"as",
"$",
"folderPath",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"template",
"=",
"\"$folderPath/{$file}\"",
")",
")",
"{",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"template",
")",
"{",
"$",
"template",
"=",
"\"$this->templatesPath/{$file}\"",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"template",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'View \"%s\" don\\'t exists.'",
",",
"$",
"template",
")",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"vars",
")",
")",
"{",
"extract",
"(",
"$",
"vars",
")",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"}",
"ob_start",
"(",
")",
";",
"require",
"$",
"template",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
] | Renders a given file with the supplied variables.
@access public
@param string $file The file to be rendered.
@param mixed $vars The variables to be substituted in the view.
@return string
@throws \LogicException | [
"Renders",
"a",
"given",
"file",
"with",
"the",
"supplied",
"variables",
"."
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/View.php#L76-L110 |
whisller/IrcBotBundle | Connection/Socket.php | Socket.connect | public function connect()
{
$this->socket = stream_socket_client($this->server.':'.$this->port);
if (!$this->isConnected()) {
throw new Exception('Unable to connect to server via fsockopen with server: "'.$this->server.'" and port: "'.$this->port.'".');
}
$this->dispatcher->dispatch('whisnet_irc_bot.post_connection', new PostConnectionEvent());
} | php | public function connect()
{
$this->socket = stream_socket_client($this->server.':'.$this->port);
if (!$this->isConnected()) {
throw new Exception('Unable to connect to server via fsockopen with server: "'.$this->server.'" and port: "'.$this->port.'".');
}
$this->dispatcher->dispatch('whisnet_irc_bot.post_connection', new PostConnectionEvent());
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"$",
"this",
"->",
"socket",
"=",
"stream_socket_client",
"(",
"$",
"this",
"->",
"server",
".",
"':'",
".",
"$",
"this",
"->",
"port",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to connect to server via fsockopen with server: \"'",
".",
"$",
"this",
"->",
"server",
".",
"'\" and port: \"'",
".",
"$",
"this",
"->",
"port",
".",
"'\".'",
")",
";",
"}",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"'whisnet_irc_bot.post_connection'",
",",
"new",
"PostConnectionEvent",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/whisller/IrcBotBundle/blob/d8bcafc1599cbbc7756b0a59f51ee988a2de0f2e/Connection/Socket.php#L85-L93 |
zodream/thirdparty | src/OAuth/PayPal.php | PayPal.setMode | public function setMode($arg) {
$this->mode = strtolower($arg) == self::LIVE ? self::LIVE : self::SANDBOX;
return $this;
} | php | public function setMode($arg) {
$this->mode = strtolower($arg) == self::LIVE ? self::LIVE : self::SANDBOX;
return $this;
} | [
"public",
"function",
"setMode",
"(",
"$",
"arg",
")",
"{",
"$",
"this",
"->",
"mode",
"=",
"strtolower",
"(",
"$",
"arg",
")",
"==",
"self",
"::",
"LIVE",
"?",
"self",
"::",
"LIVE",
":",
"self",
"::",
"SANDBOX",
";",
"return",
"$",
"this",
";",
"}"
] | IS TEST OR LIVE
@param string $arg
@return $this | [
"IS",
"TEST",
"OR",
"LIVE"
] | train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/OAuth/PayPal.php#L95-L98 |
anime-db/app-bundle | src/Service/WidgetsContainer.php | WidgetsContainer.getWidgetsForPlace | public function getWidgetsForPlace($place)
{
// send the event to those who did not add widgets could do it
$this->dispatcher->dispatch(StoreEvents::GET, new Get($this, $place));
return isset($this->widgets[$place]) ? $this->widgets[$place] : [];
} | php | public function getWidgetsForPlace($place)
{
// send the event to those who did not add widgets could do it
$this->dispatcher->dispatch(StoreEvents::GET, new Get($this, $place));
return isset($this->widgets[$place]) ? $this->widgets[$place] : [];
} | [
"public",
"function",
"getWidgetsForPlace",
"(",
"$",
"place",
")",
"{",
"// send the event to those who did not add widgets could do it",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"StoreEvents",
"::",
"GET",
",",
"new",
"Get",
"(",
"$",
"this",
",",
"$",
"place",
")",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
")",
"?",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
":",
"[",
"]",
";",
"}"
] | @param string $place
@return array | [
"@param",
"string",
"$place"
] | train | https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Service/WidgetsContainer.php#L40-L46 |
anime-db/app-bundle | src/Service/WidgetsContainer.php | WidgetsContainer.registr | public function registr($place, $controller)
{
if (preg_match('/^[a-z0-9]+:[a-z0-9]+:[_a-z0-9]+$/i', $controller)) {
if (!isset($this->widgets[$place])) {
$this->widgets[$place][] = $controller;
} elseif (!in_array($controller, $this->widgets[$place])) {
$this->widgets[$place][] = $controller;
}
return true;
}
return false;
} | php | public function registr($place, $controller)
{
if (preg_match('/^[a-z0-9]+:[a-z0-9]+:[_a-z0-9]+$/i', $controller)) {
if (!isset($this->widgets[$place])) {
$this->widgets[$place][] = $controller;
} elseif (!in_array($controller, $this->widgets[$place])) {
$this->widgets[$place][] = $controller;
}
return true;
}
return false;
} | [
"public",
"function",
"registr",
"(",
"$",
"place",
",",
"$",
"controller",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^[a-z0-9]+:[a-z0-9]+:[_a-z0-9]+$/i'",
",",
"$",
"controller",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
")",
")",
"{",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
"[",
"]",
"=",
"$",
"controller",
";",
"}",
"elseif",
"(",
"!",
"in_array",
"(",
"$",
"controller",
",",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
")",
")",
"{",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
"[",
"]",
"=",
"$",
"controller",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Regist widget.
Controller example:
AcmeDemoBundle:Welcome:index
AcmeArticleBundle:Article:show
@param string $place
@param string $controller
@return bool | [
"Regist",
"widget",
"."
] | train | https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Service/WidgetsContainer.php#L60-L73 |
anime-db/app-bundle | src/Service/WidgetsContainer.php | WidgetsContainer.unregistr | public function unregistr($place, $controller)
{
if (isset($this->widgets[$place]) &&
($key = array_search($controller, $this->widgets[$place])) !== false
) {
unset($this->widgets[$place][$key]);
return true;
}
return false;
} | php | public function unregistr($place, $controller)
{
if (isset($this->widgets[$place]) &&
($key = array_search($controller, $this->widgets[$place])) !== false
) {
unset($this->widgets[$place][$key]);
return true;
}
return false;
} | [
"public",
"function",
"unregistr",
"(",
"$",
"place",
",",
"$",
"controller",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
")",
"&&",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"controller",
",",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"widgets",
"[",
"$",
"place",
"]",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | @param string $place
@param string $controller
@return bool | [
"@param",
"string",
"$place",
"@param",
"string",
"$controller"
] | train | https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Service/WidgetsContainer.php#L81-L92 |
redaigbaria/oauth2 | src/TokenType/MAC.php | MAC.generateResponse | public function generateResponse()
{
$macKey = SecureKey::generate();
$this->server->getMacStorage()->create($macKey, $this->getParam('access_token'));
$response = [
'access_token' => $this->getParam('access_token'),
'token_type' => 'mac',
'expires_in' => $this->getParam('expires_in'),
'mac_key' => $macKey,
'mac_algorithm' => 'hmac-sha-256',
];
if (!is_null($this->getParam('refresh_token'))) {
$response['refresh_token'] = $this->getParam('refresh_token');
}
return $response;
} | php | public function generateResponse()
{
$macKey = SecureKey::generate();
$this->server->getMacStorage()->create($macKey, $this->getParam('access_token'));
$response = [
'access_token' => $this->getParam('access_token'),
'token_type' => 'mac',
'expires_in' => $this->getParam('expires_in'),
'mac_key' => $macKey,
'mac_algorithm' => 'hmac-sha-256',
];
if (!is_null($this->getParam('refresh_token'))) {
$response['refresh_token'] = $this->getParam('refresh_token');
}
return $response;
} | [
"public",
"function",
"generateResponse",
"(",
")",
"{",
"$",
"macKey",
"=",
"SecureKey",
"::",
"generate",
"(",
")",
";",
"$",
"this",
"->",
"server",
"->",
"getMacStorage",
"(",
")",
"->",
"create",
"(",
"$",
"macKey",
",",
"$",
"this",
"->",
"getParam",
"(",
"'access_token'",
")",
")",
";",
"$",
"response",
"=",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"getParam",
"(",
"'access_token'",
")",
",",
"'token_type'",
"=>",
"'mac'",
",",
"'expires_in'",
"=>",
"$",
"this",
"->",
"getParam",
"(",
"'expires_in'",
")",
",",
"'mac_key'",
"=>",
"$",
"macKey",
",",
"'mac_algorithm'",
"=>",
"'hmac-sha-256'",
",",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"getParam",
"(",
"'refresh_token'",
")",
")",
")",
"{",
"$",
"response",
"[",
"'refresh_token'",
"]",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'refresh_token'",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/TokenType/MAC.php#L26-L44 |
redaigbaria/oauth2 | src/TokenType/MAC.php | MAC.determineAccessTokenInHeader | public function determineAccessTokenInHeader(Request $request)
{
if ($request->headers->has('Authorization') === false) {
return;
}
$header = $request->headers->get('Authorization');
if (substr($header, 0, 4) !== 'MAC ') {
return;
}
// Find all the parameters expressed in the header
$paramsRaw = explode(',', substr($header, 4));
$params = new ParameterBag();
array_map(function ($param) use (&$params) {
$param = trim($param);
preg_match_all('/([a-zA-Z]*)="([\w=\/+]*)"/', $param, $matches);
// @codeCoverageIgnoreStart
if (count($matches) !== 3) {
return;
}
// @codeCoverageIgnoreEnd
$key = reset($matches[1]);
$value = trim(reset($matches[2]));
if (empty($value)) {
return;
}
$params->set($key, $value);
}, $paramsRaw);
// Validate parameters
if ($params->has('id') === false || $params->has('ts') === false || $params->has('nonce') === false || $params->has('mac') === false) {
return;
}
if (abs($params->get('ts') - time()) > 300) {
return;
}
$accessToken = $params->get('id');
$timestamp = (int) $params->get('ts');
$nonce = $params->get('nonce');
$signature = $params->get('mac');
// Try to find the MAC key for the access token
$macKey = $this->server->getMacStorage()->getByAccessToken($accessToken);
if ($macKey === null) {
return;
}
// Calculate and compare the signature
$calculatedSignatureParts = [
$timestamp,
$nonce,
strtoupper($request->getMethod()),
$request->getRequestUri(),
$request->getHost(),
$request->getPort(),
];
if ($params->has('ext')) {
$calculatedSignatureParts[] = $params->get('ext');
}
$calculatedSignature = base64_encode(
hash_hmac(
'sha256',
implode("\n", $calculatedSignatureParts),
$macKey,
true // raw_output: outputs raw binary data
)
);
// Return the access token if the signature matches
return ($this->hash_equals($calculatedSignature, $signature)) ? $accessToken : null;
} | php | public function determineAccessTokenInHeader(Request $request)
{
if ($request->headers->has('Authorization') === false) {
return;
}
$header = $request->headers->get('Authorization');
if (substr($header, 0, 4) !== 'MAC ') {
return;
}
// Find all the parameters expressed in the header
$paramsRaw = explode(',', substr($header, 4));
$params = new ParameterBag();
array_map(function ($param) use (&$params) {
$param = trim($param);
preg_match_all('/([a-zA-Z]*)="([\w=\/+]*)"/', $param, $matches);
// @codeCoverageIgnoreStart
if (count($matches) !== 3) {
return;
}
// @codeCoverageIgnoreEnd
$key = reset($matches[1]);
$value = trim(reset($matches[2]));
if (empty($value)) {
return;
}
$params->set($key, $value);
}, $paramsRaw);
// Validate parameters
if ($params->has('id') === false || $params->has('ts') === false || $params->has('nonce') === false || $params->has('mac') === false) {
return;
}
if (abs($params->get('ts') - time()) > 300) {
return;
}
$accessToken = $params->get('id');
$timestamp = (int) $params->get('ts');
$nonce = $params->get('nonce');
$signature = $params->get('mac');
// Try to find the MAC key for the access token
$macKey = $this->server->getMacStorage()->getByAccessToken($accessToken);
if ($macKey === null) {
return;
}
// Calculate and compare the signature
$calculatedSignatureParts = [
$timestamp,
$nonce,
strtoupper($request->getMethod()),
$request->getRequestUri(),
$request->getHost(),
$request->getPort(),
];
if ($params->has('ext')) {
$calculatedSignatureParts[] = $params->get('ext');
}
$calculatedSignature = base64_encode(
hash_hmac(
'sha256',
implode("\n", $calculatedSignatureParts),
$macKey,
true // raw_output: outputs raw binary data
)
);
// Return the access token if the signature matches
return ($this->hash_equals($calculatedSignature, $signature)) ? $accessToken : null;
} | [
"public",
"function",
"determineAccessTokenInHeader",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"headers",
"->",
"has",
"(",
"'Authorization'",
")",
"===",
"false",
")",
"{",
"return",
";",
"}",
"$",
"header",
"=",
"$",
"request",
"->",
"headers",
"->",
"get",
"(",
"'Authorization'",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"header",
",",
"0",
",",
"4",
")",
"!==",
"'MAC '",
")",
"{",
"return",
";",
"}",
"// Find all the parameters expressed in the header",
"$",
"paramsRaw",
"=",
"explode",
"(",
"','",
",",
"substr",
"(",
"$",
"header",
",",
"4",
")",
")",
";",
"$",
"params",
"=",
"new",
"ParameterBag",
"(",
")",
";",
"array_map",
"(",
"function",
"(",
"$",
"param",
")",
"use",
"(",
"&",
"$",
"params",
")",
"{",
"$",
"param",
"=",
"trim",
"(",
"$",
"param",
")",
";",
"preg_match_all",
"(",
"'/([a-zA-Z]*)=\"([\\w=\\/+]*)\"/'",
",",
"$",
"param",
",",
"$",
"matches",
")",
";",
"// @codeCoverageIgnoreStart",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"!==",
"3",
")",
"{",
"return",
";",
"}",
"// @codeCoverageIgnoreEnd",
"$",
"key",
"=",
"reset",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"reset",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
";",
"}",
"$",
"params",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
",",
"$",
"paramsRaw",
")",
";",
"// Validate parameters",
"if",
"(",
"$",
"params",
"->",
"has",
"(",
"'id'",
")",
"===",
"false",
"||",
"$",
"params",
"->",
"has",
"(",
"'ts'",
")",
"===",
"false",
"||",
"$",
"params",
"->",
"has",
"(",
"'nonce'",
")",
"===",
"false",
"||",
"$",
"params",
"->",
"has",
"(",
"'mac'",
")",
"===",
"false",
")",
"{",
"return",
";",
"}",
"if",
"(",
"abs",
"(",
"$",
"params",
"->",
"get",
"(",
"'ts'",
")",
"-",
"time",
"(",
")",
")",
">",
"300",
")",
"{",
"return",
";",
"}",
"$",
"accessToken",
"=",
"$",
"params",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"timestamp",
"=",
"(",
"int",
")",
"$",
"params",
"->",
"get",
"(",
"'ts'",
")",
";",
"$",
"nonce",
"=",
"$",
"params",
"->",
"get",
"(",
"'nonce'",
")",
";",
"$",
"signature",
"=",
"$",
"params",
"->",
"get",
"(",
"'mac'",
")",
";",
"// Try to find the MAC key for the access token",
"$",
"macKey",
"=",
"$",
"this",
"->",
"server",
"->",
"getMacStorage",
"(",
")",
"->",
"getByAccessToken",
"(",
"$",
"accessToken",
")",
";",
"if",
"(",
"$",
"macKey",
"===",
"null",
")",
"{",
"return",
";",
"}",
"// Calculate and compare the signature",
"$",
"calculatedSignatureParts",
"=",
"[",
"$",
"timestamp",
",",
"$",
"nonce",
",",
"strtoupper",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
",",
"$",
"request",
"->",
"getRequestUri",
"(",
")",
",",
"$",
"request",
"->",
"getHost",
"(",
")",
",",
"$",
"request",
"->",
"getPort",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"params",
"->",
"has",
"(",
"'ext'",
")",
")",
"{",
"$",
"calculatedSignatureParts",
"[",
"]",
"=",
"$",
"params",
"->",
"get",
"(",
"'ext'",
")",
";",
"}",
"$",
"calculatedSignature",
"=",
"base64_encode",
"(",
"hash_hmac",
"(",
"'sha256'",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"calculatedSignatureParts",
")",
",",
"$",
"macKey",
",",
"true",
"// raw_output: outputs raw binary data",
")",
")",
";",
"// Return the access token if the signature matches",
"return",
"(",
"$",
"this",
"->",
"hash_equals",
"(",
"$",
"calculatedSignature",
",",
"$",
"signature",
")",
")",
"?",
"$",
"accessToken",
":",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/TokenType/MAC.php#L49-L132 |
redaigbaria/oauth2 | src/TokenType/MAC.php | MAC.hash_equals | private function hash_equals($knownString, $userString)
{
if (function_exists('\hash_equals')) {
return \hash_equals($knownString, $userString);
}
if (strlen($knownString) !== strlen($userString)) {
return false;
}
$len = strlen($knownString);
$result = 0;
for ($i = 0; $i < $len; $i++) {
$result |= (ord($knownString[$i]) ^ ord($userString[$i]));
}
// They are only identical strings if $result is exactly 0...
return 0 === $result;
} | php | private function hash_equals($knownString, $userString)
{
if (function_exists('\hash_equals')) {
return \hash_equals($knownString, $userString);
}
if (strlen($knownString) !== strlen($userString)) {
return false;
}
$len = strlen($knownString);
$result = 0;
for ($i = 0; $i < $len; $i++) {
$result |= (ord($knownString[$i]) ^ ord($userString[$i]));
}
// They are only identical strings if $result is exactly 0...
return 0 === $result;
} | [
"private",
"function",
"hash_equals",
"(",
"$",
"knownString",
",",
"$",
"userString",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'\\hash_equals'",
")",
")",
"{",
"return",
"\\",
"hash_equals",
"(",
"$",
"knownString",
",",
"$",
"userString",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"knownString",
")",
"!==",
"strlen",
"(",
"$",
"userString",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"len",
"=",
"strlen",
"(",
"$",
"knownString",
")",
";",
"$",
"result",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"|=",
"(",
"ord",
"(",
"$",
"knownString",
"[",
"$",
"i",
"]",
")",
"^",
"ord",
"(",
"$",
"userString",
"[",
"$",
"i",
"]",
")",
")",
";",
"}",
"// They are only identical strings if $result is exactly 0...",
"return",
"0",
"===",
"$",
"result",
";",
"}"
] | Prevent timing attack
@param string $knownString
@param string $userString
@return bool | [
"Prevent",
"timing",
"attack"
] | train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/TokenType/MAC.php#L140-L155 |
aedart/config-loader | src/Traits/ParserFactoryTrait.php | ParserFactoryTrait.getParserFactory | public function getParserFactory(): ?ParserFactory
{
if (!$this->hasParserFactory()) {
$this->setParserFactory($this->getDefaultParserFactory());
}
return $this->parserFactory;
} | php | public function getParserFactory(): ?ParserFactory
{
if (!$this->hasParserFactory()) {
$this->setParserFactory($this->getDefaultParserFactory());
}
return $this->parserFactory;
} | [
"public",
"function",
"getParserFactory",
"(",
")",
":",
"?",
"ParserFactory",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasParserFactory",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setParserFactory",
"(",
"$",
"this",
"->",
"getDefaultParserFactory",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parserFactory",
";",
"}"
] | Get parser factory
If no parser factory has been set, this method will
set and return a default parser factory, if any such
value is available
@see getDefaultParserFactory()
@return ParserFactory|null parser factory or null if none parser factory has been set | [
"Get",
"parser",
"factory"
] | train | https://github.com/aedart/config-loader/blob/9e1cf592bee46ba4930bb9c352aaf475d81266ea/src/Traits/ParserFactoryTrait.php#L53-L59 |
CakeCMS/Core | src/View/Helper/FilterHelper.php | FilterHelper.render | public function render($model, array $fields = [], $element = self::DEFAULT_ELEMENT, array $data = [])
{
$data = Hash::merge([
'clearUrl' => [],
'model' => $model,
'formFields' => $fields,
], $data);
return $this->_View->element($element, $data);
} | php | public function render($model, array $fields = [], $element = self::DEFAULT_ELEMENT, array $data = [])
{
$data = Hash::merge([
'clearUrl' => [],
'model' => $model,
'formFields' => $fields,
], $data);
return $this->_View->element($element, $data);
} | [
"public",
"function",
"render",
"(",
"$",
"model",
",",
"array",
"$",
"fields",
"=",
"[",
"]",
",",
"$",
"element",
"=",
"self",
"::",
"DEFAULT_ELEMENT",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"Hash",
"::",
"merge",
"(",
"[",
"'clearUrl'",
"=>",
"[",
"]",
",",
"'model'",
"=>",
"$",
"model",
",",
"'formFields'",
"=>",
"$",
"fields",
",",
"]",
",",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"_View",
"->",
"element",
"(",
"$",
"element",
",",
"$",
"data",
")",
";",
"}"
] | Render filter element.
@param string $model
@param array $fields
@param string $element
@param array $data
@return string | [
"Render",
"filter",
"element",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FilterHelper.php#L39-L48 |
qcubed/orm | src/Database/Mysqli5/Database.php | Database.executeProcedure | public function executeProcedure($strProcName, $params = null)
{
$strParams = '';
if ($params) {
$a = array_map(function ($val) {
return $this->sqlVariable($val);
}, $params);
$strParams = implode(',', $a);
}
$strSql = "call {$strProcName}({$strParams})";
return $this->multiQuery($strSql);
} | php | public function executeProcedure($strProcName, $params = null)
{
$strParams = '';
if ($params) {
$a = array_map(function ($val) {
return $this->sqlVariable($val);
}, $params);
$strParams = implode(',', $a);
}
$strSql = "call {$strProcName}({$strParams})";
return $this->multiQuery($strSql);
} | [
"public",
"function",
"executeProcedure",
"(",
"$",
"strProcName",
",",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"strParams",
"=",
"''",
";",
"if",
"(",
"$",
"params",
")",
"{",
"$",
"a",
"=",
"array_map",
"(",
"function",
"(",
"$",
"val",
")",
"{",
"return",
"$",
"this",
"->",
"sqlVariable",
"(",
"$",
"val",
")",
";",
"}",
",",
"$",
"params",
")",
";",
"$",
"strParams",
"=",
"implode",
"(",
"','",
",",
"$",
"a",
")",
";",
"}",
"$",
"strSql",
"=",
"\"call {$strProcName}({$strParams})\"",
";",
"return",
"$",
"this",
"->",
"multiQuery",
"(",
"$",
"strSql",
")",
";",
"}"
] | Generic stored procedure executor. For Mysql 5, you can have your stored procedure return results by
"SELECT"ing the results. The results will be returned as an array.
@param string $strProcName Name of stored procedure
@param array|null $params
@return Result[]
@throws MysqliException | [
"Generic",
"stored",
"procedure",
"executor",
".",
"For",
"Mysql",
"5",
"you",
"can",
"have",
"your",
"stored",
"procedure",
"return",
"results",
"by",
"SELECT",
"ing",
"the",
"results",
".",
"The",
"results",
"will",
"be",
"returned",
"as",
"an",
"array",
"."
] | train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Database/Mysqli5/Database.php#L122-L133 |
phrest/sdk | src/Generator/Helper/ClassGen.php | ClassGen.classGen | public static function classGen(
$name,
$namespace,
$uses = [],
$extends = '',
$implements = []
)
{
$class = new ClassGenerator();
$class
->setName($name)
->setNamespaceName($namespace)
->setExtendedClass($extends)
->setImplementedInterfaces($implements)
->setIndentation(Generator::$indentation);
foreach ($uses as $use)
{
$class->addUse($use);
}
return $class;
} | php | public static function classGen(
$name,
$namespace,
$uses = [],
$extends = '',
$implements = []
)
{
$class = new ClassGenerator();
$class
->setName($name)
->setNamespaceName($namespace)
->setExtendedClass($extends)
->setImplementedInterfaces($implements)
->setIndentation(Generator::$indentation);
foreach ($uses as $use)
{
$class->addUse($use);
}
return $class;
} | [
"public",
"static",
"function",
"classGen",
"(",
"$",
"name",
",",
"$",
"namespace",
",",
"$",
"uses",
"=",
"[",
"]",
",",
"$",
"extends",
"=",
"''",
",",
"$",
"implements",
"=",
"[",
"]",
")",
"{",
"$",
"class",
"=",
"new",
"ClassGenerator",
"(",
")",
";",
"$",
"class",
"->",
"setName",
"(",
"$",
"name",
")",
"->",
"setNamespaceName",
"(",
"$",
"namespace",
")",
"->",
"setExtendedClass",
"(",
"$",
"extends",
")",
"->",
"setImplementedInterfaces",
"(",
"$",
"implements",
")",
"->",
"setIndentation",
"(",
"Generator",
"::",
"$",
"indentation",
")",
";",
"foreach",
"(",
"$",
"uses",
"as",
"$",
"use",
")",
"{",
"$",
"class",
"->",
"addUse",
"(",
"$",
"use",
")",
";",
"}",
"return",
"$",
"class",
";",
"}"
] | @param $name
@param $namespace
@param $uses
@param string $extends
@param array $implements
@return ClassGenerator | [
"@param",
"$name",
"@param",
"$namespace",
"@param",
"$uses",
"@param",
"string",
"$extends",
"@param",
"array",
"$implements"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/Generator/Helper/ClassGen.php#L26-L49 |
phrest/sdk | src/Generator/Helper/ClassGen.php | ClassGen.property | public static function property(
$name,
$visibility = 'public',
$default = null,
$type = 'mixed'
)
{
$property = (new PropertyGenerator($name, $default))
->setVisibility($visibility);
$property->setIndentation(Generator::$indentation);
$docBlock = new DocBlockGenerator();
$docBlock->setIndentation(Generator::$indentation);
$tag = new Tag();
$tag->setName('var');
$tag->setContent($type);
$tag->setIndentation(Generator::$indentation);
$docBlock->setTag($tag);
$property->setDocBlock($docBlock);
return $property;
} | php | public static function property(
$name,
$visibility = 'public',
$default = null,
$type = 'mixed'
)
{
$property = (new PropertyGenerator($name, $default))
->setVisibility($visibility);
$property->setIndentation(Generator::$indentation);
$docBlock = new DocBlockGenerator();
$docBlock->setIndentation(Generator::$indentation);
$tag = new Tag();
$tag->setName('var');
$tag->setContent($type);
$tag->setIndentation(Generator::$indentation);
$docBlock->setTag($tag);
$property->setDocBlock($docBlock);
return $property;
} | [
"public",
"static",
"function",
"property",
"(",
"$",
"name",
",",
"$",
"visibility",
"=",
"'public'",
",",
"$",
"default",
"=",
"null",
",",
"$",
"type",
"=",
"'mixed'",
")",
"{",
"$",
"property",
"=",
"(",
"new",
"PropertyGenerator",
"(",
"$",
"name",
",",
"$",
"default",
")",
")",
"->",
"setVisibility",
"(",
"$",
"visibility",
")",
";",
"$",
"property",
"->",
"setIndentation",
"(",
"Generator",
"::",
"$",
"indentation",
")",
";",
"$",
"docBlock",
"=",
"new",
"DocBlockGenerator",
"(",
")",
";",
"$",
"docBlock",
"->",
"setIndentation",
"(",
"Generator",
"::",
"$",
"indentation",
")",
";",
"$",
"tag",
"=",
"new",
"Tag",
"(",
")",
";",
"$",
"tag",
"->",
"setName",
"(",
"'var'",
")",
";",
"$",
"tag",
"->",
"setContent",
"(",
"$",
"type",
")",
";",
"$",
"tag",
"->",
"setIndentation",
"(",
"Generator",
"::",
"$",
"indentation",
")",
";",
"$",
"docBlock",
"->",
"setTag",
"(",
"$",
"tag",
")",
";",
"$",
"property",
"->",
"setDocBlock",
"(",
"$",
"docBlock",
")",
";",
"return",
"$",
"property",
";",
"}"
] | @param $name
@param $visibility
@param $default
@param $type
@return PropertyGenerator | [
"@param",
"$name",
"@param",
"$visibility",
"@param",
"$default",
"@param",
"$type"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/Generator/Helper/ClassGen.php#L59-L84 |
phrest/sdk | src/Generator/Helper/ClassGen.php | ClassGen.method | public static function method(
$name,
$params = [],
$visibility = 'public',
$body = '//todo',
$docblock = ''
)
{
if (empty($docblock))
{
if (!empty($params))
{
$docblock = new DocBlockGenerator();
foreach ($params as $param)
{
$tag = new Tag('param', $param->getType() . ' $' . $param->getName());
$docblock->setTag($tag);
}
}
}
return (new MethodGenerator($name, $params))
->setBody($body)
->setVisibility($visibility)
->setDocBlock($docblock)
->setIndentation(Generator::$indentation);
} | php | public static function method(
$name,
$params = [],
$visibility = 'public',
$body = '//todo',
$docblock = ''
)
{
if (empty($docblock))
{
if (!empty($params))
{
$docblock = new DocBlockGenerator();
foreach ($params as $param)
{
$tag = new Tag('param', $param->getType() . ' $' . $param->getName());
$docblock->setTag($tag);
}
}
}
return (new MethodGenerator($name, $params))
->setBody($body)
->setVisibility($visibility)
->setDocBlock($docblock)
->setIndentation(Generator::$indentation);
} | [
"public",
"static",
"function",
"method",
"(",
"$",
"name",
",",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"visibility",
"=",
"'public'",
",",
"$",
"body",
"=",
"'//todo'",
",",
"$",
"docblock",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"docblock",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"$",
"docblock",
"=",
"new",
"DocBlockGenerator",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"tag",
"=",
"new",
"Tag",
"(",
"'param'",
",",
"$",
"param",
"->",
"getType",
"(",
")",
".",
"' $'",
".",
"$",
"param",
"->",
"getName",
"(",
")",
")",
";",
"$",
"docblock",
"->",
"setTag",
"(",
"$",
"tag",
")",
";",
"}",
"}",
"}",
"return",
"(",
"new",
"MethodGenerator",
"(",
"$",
"name",
",",
"$",
"params",
")",
")",
"->",
"setBody",
"(",
"$",
"body",
")",
"->",
"setVisibility",
"(",
"$",
"visibility",
")",
"->",
"setDocBlock",
"(",
"$",
"docblock",
")",
"->",
"setIndentation",
"(",
"Generator",
"::",
"$",
"indentation",
")",
";",
"}"
] | @param $name
@param ParameterGenerator[] $params
@param string $visibility
@param string $body
@param string|DocBlockGenerator $docblock
@return \Zend\Code\Generator\MethodGenerator | [
"@param",
"$name",
"@param",
"ParameterGenerator",
"[]",
"$params",
"@param",
"string",
"$visibility",
"@param",
"string",
"$body",
"@param",
"string|DocBlockGenerator",
"$docblock"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/Generator/Helper/ClassGen.php#L95-L121 |
phrest/sdk | src/Generator/Helper/ClassGen.php | ClassGen.constructor | public static function constructor($params)
{
$constructor = self::method('__construct', $params);
$body = '';
foreach ($params as $param)
{
$body .= "\$this->{$param->getName()} = \${$param->getName()};" . PHP_EOL;
}
$constructor->setBody($body);
return $constructor;
} | php | public static function constructor($params)
{
$constructor = self::method('__construct', $params);
$body = '';
foreach ($params as $param)
{
$body .= "\$this->{$param->getName()} = \${$param->getName()};" . PHP_EOL;
}
$constructor->setBody($body);
return $constructor;
} | [
"public",
"static",
"function",
"constructor",
"(",
"$",
"params",
")",
"{",
"$",
"constructor",
"=",
"self",
"::",
"method",
"(",
"'__construct'",
",",
"$",
"params",
")",
";",
"$",
"body",
"=",
"''",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"body",
".=",
"\"\\$this->{$param->getName()} = \\${$param->getName()};\"",
".",
"PHP_EOL",
";",
"}",
"$",
"constructor",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"return",
"$",
"constructor",
";",
"}"
] | @param ParameterGenerator[] $params
@return MethodGenerator | [
"@param",
"ParameterGenerator",
"[]",
"$params"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/Generator/Helper/ClassGen.php#L128-L142 |
phrest/sdk | src/Generator/Helper/ClassGen.php | ClassGen.setter | public static function setter($name, $type)
{
$setter = self::method(
'set' . ucfirst($name),
[
new ParameterGenerator($name, $type)
]
);
$setter->getDocBlock()->setTag(new GenericTag('return', 'static'));
$body = "\$this->{$name} = \${$name};" . PHP_EOL
. "return \$this;" . PHP_EOL;
$setter->setBody($body);
return $setter;
} | php | public static function setter($name, $type)
{
$setter = self::method(
'set' . ucfirst($name),
[
new ParameterGenerator($name, $type)
]
);
$setter->getDocBlock()->setTag(new GenericTag('return', 'static'));
$body = "\$this->{$name} = \${$name};" . PHP_EOL
. "return \$this;" . PHP_EOL;
$setter->setBody($body);
return $setter;
} | [
"public",
"static",
"function",
"setter",
"(",
"$",
"name",
",",
"$",
"type",
")",
"{",
"$",
"setter",
"=",
"self",
"::",
"method",
"(",
"'set'",
".",
"ucfirst",
"(",
"$",
"name",
")",
",",
"[",
"new",
"ParameterGenerator",
"(",
"$",
"name",
",",
"$",
"type",
")",
"]",
")",
";",
"$",
"setter",
"->",
"getDocBlock",
"(",
")",
"->",
"setTag",
"(",
"new",
"GenericTag",
"(",
"'return'",
",",
"'static'",
")",
")",
";",
"$",
"body",
"=",
"\"\\$this->{$name} = \\${$name};\"",
".",
"PHP_EOL",
".",
"\"return \\$this;\"",
".",
"PHP_EOL",
";",
"$",
"setter",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"return",
"$",
"setter",
";",
"}"
] | @param string $name
@param string $type
@return MethodGenerator | [
"@param",
"string",
"$name",
"@param",
"string",
"$type"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/Generator/Helper/ClassGen.php#L150-L167 |
boekkooi/tactician-amqp | src/Middleware/MessageCapturingMiddleware.php | MessageCapturingMiddleware.execute | public function execute($command, callable $next)
{
if (!$command instanceof Message) {
return $next($command);
}
$this->capturer->publish($command);
return null;
} | php | public function execute($command, callable $next)
{
if (!$command instanceof Message) {
return $next($command);
}
$this->capturer->publish($command);
return null;
} | [
"public",
"function",
"execute",
"(",
"$",
"command",
",",
"callable",
"$",
"next",
")",
"{",
"if",
"(",
"!",
"$",
"command",
"instanceof",
"Message",
")",
"{",
"return",
"$",
"next",
"(",
"$",
"command",
")",
";",
"}",
"$",
"this",
"->",
"capturer",
"->",
"publish",
"(",
"$",
"command",
")",
";",
"return",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/boekkooi/tactician-amqp/blob/55cbb8b9e20aab7891e6a6090b248377c599360e/src/Middleware/MessageCapturingMiddleware.php#L29-L38 |
webforge-labs/psc-cms | lib/Psc/CMS/ContactFormMailer.php | ContactFormMailer.setAutoReply | public function setAutoReply($emailFieldName, $text, $subject = NULL) {
$this->autoReply = (object) array(
'emailField'=>$emailFieldName,
'subject'=>$subject,
'text'=>$text
);
} | php | public function setAutoReply($emailFieldName, $text, $subject = NULL) {
$this->autoReply = (object) array(
'emailField'=>$emailFieldName,
'subject'=>$subject,
'text'=>$text
);
} | [
"public",
"function",
"setAutoReply",
"(",
"$",
"emailFieldName",
",",
"$",
"text",
",",
"$",
"subject",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"autoReply",
"=",
"(",
"object",
")",
"array",
"(",
"'emailField'",
"=>",
"$",
"emailFieldName",
",",
"'subject'",
"=>",
"$",
"subject",
",",
"'text'",
"=>",
"$",
"text",
")",
";",
"}"
] | You can use %xx% variables from your fields in $data
for the template text | [
"You",
"can",
"use",
"%xx%",
"variables",
"from",
"your",
"fields",
"in",
"$data",
"for",
"the",
"template",
"text"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/ContactFormMailer.php#L188-L194 |
spiral-modules/scaffolder | source/Scaffolder/Declarations/EntityDeclaration.php | EntityDeclaration.addField | public function addField(string $name, $value)
{
$schema = $this->constant('SCHEMA')->getValue();
$schema[$name] = $value;
$this->constant('SCHEMA')->setValue($schema);
} | php | public function addField(string $name, $value)
{
$schema = $this->constant('SCHEMA')->getValue();
$schema[$name] = $value;
$this->constant('SCHEMA')->setValue($schema);
} | [
"public",
"function",
"addField",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"constant",
"(",
"'SCHEMA'",
")",
"->",
"getValue",
"(",
")",
";",
"$",
"schema",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"constant",
"(",
"'SCHEMA'",
")",
"->",
"setValue",
"(",
"$",
"schema",
")",
";",
"}"
] | Add field into schema.
@param string $name
@param mixed $value | [
"Add",
"field",
"into",
"schema",
"."
] | train | https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Declarations/EntityDeclaration.php#L44-L49 |
echo58/sms | src/AbstractProvider.php | AbstractProvider.assertRequiredOptions | protected function assertRequiredOptions($key, array $options)
{
$missing = array_diff_key(array_flip($this->getRequiredOptions($key)), $options);
if (!empty($missing)) {
throw new \InvalidArgumentException(
'参数不完整,请指定'.$key.'参数: '.implode(', ', array_keys($missing))
);
}
} | php | protected function assertRequiredOptions($key, array $options)
{
$missing = array_diff_key(array_flip($this->getRequiredOptions($key)), $options);
if (!empty($missing)) {
throw new \InvalidArgumentException(
'参数不完整,请指定'.$key.'参数: '.implode(', ', array_keys($missing))
);
}
} | [
"protected",
"function",
"assertRequiredOptions",
"(",
"$",
"key",
",",
"array",
"$",
"options",
")",
"{",
"$",
"missing",
"=",
"array_diff_key",
"(",
"array_flip",
"(",
"$",
"this",
"->",
"getRequiredOptions",
"(",
"$",
"key",
")",
")",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"missing",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'参数不完整,请指定'.$key.'参数: '.implo",
"d",
"e",
"(',",
" ",
"', array_k",
"e",
"ys($mis",
"s",
"ing)",
")",
"",
"",
"",
"",
"",
"",
")",
";",
"}",
"}"
] | 验证是否必须的参数都存在
@param string $key
@param array $options
@return void
@throws \InvalidArgumentException | [
"验证是否必须的参数都存在"
] | train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/AbstractProvider.php#L135-L143 |
echo58/sms | src/AbstractProvider.php | AbstractProvider.createRequest | protected function createRequest($method, $url, $requestHeaders, $requestPayload, $protocolVersion)
{
$request = new Request(
$method,
$url,
$requestHeaders,
$requestPayload,
$protocolVersion
);
return $request;
} | php | protected function createRequest($method, $url, $requestHeaders, $requestPayload, $protocolVersion)
{
$request = new Request(
$method,
$url,
$requestHeaders,
$requestPayload,
$protocolVersion
);
return $request;
} | [
"protected",
"function",
"createRequest",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"requestHeaders",
",",
"$",
"requestPayload",
",",
"$",
"protocolVersion",
")",
"{",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"requestHeaders",
",",
"$",
"requestPayload",
",",
"$",
"protocolVersion",
")",
";",
"return",
"$",
"request",
";",
"}"
] | 创建向短信接口的发送请求
@param null|string $method
@param null|string $url
@param array $requestHeaders
@param $requestPayload
@param string $protocolVersion
@return Request
@throws \InvalidArgumentException | [
"创建向短信接口的发送请求"
] | train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/AbstractProvider.php#L253-L264 |
echo58/sms | src/AbstractProvider.php | AbstractProvider.parseJson | protected function parseJson($content)
{
$content = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \UnexpectedValueException(sprintf(
"JSON 解析失败: %s",
json_last_error_msg()
));
}
return $content;
} | php | protected function parseJson($content)
{
$content = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \UnexpectedValueException(sprintf(
"JSON 解析失败: %s",
json_last_error_msg()
));
}
return $content;
} | [
"protected",
"function",
"parseJson",
"(",
"$",
"content",
")",
"{",
"$",
"content",
"=",
"json_decode",
"(",
"$",
"content",
",",
"true",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"\"JSON 解析失败: %s\",",
"",
"json_last_error_msg",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | 解析 JSON 格式的字符串
@param string $content
@return array
@throws \UnexpectedValueException | [
"解析",
"JSON",
"格式的字符串"
] | train | https://github.com/echo58/sms/blob/2921c4137edf8f21b1cee29ff1b48cd1a0810f40/src/AbstractProvider.php#L282-L293 |
tbreuss/pvc | src/View/View.php | View.registerHelper | public function registerHelper(string $name, callable $callback): self
{
$this->helpers->add($name, $callback);
return $this;
} | php | public function registerHelper(string $name, callable $callback): self
{
$this->helpers->add($name, $callback);
return $this;
} | [
"public",
"function",
"registerHelper",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
")",
":",
"self",
"{",
"$",
"this",
"->",
"helpers",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"callback",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Register a new template function.
@param string $name;
@param callback $callback;
@return $this | [
"Register",
"a",
"new",
"template",
"function",
"."
] | train | https://github.com/tbreuss/pvc/blob/ae100351010a8c9f645ccb918f70a26e167de7a7/src/View/View.php#L123-L127 |
meccado/acl-admin-control-panel | src/Http/Controllers/Admin/PermissionController.php | PermissionController.store | public function store(Request $request)
{
Permission::create($request->all());
\Session::flash('flash_message', 'Permission added!');
return \Redirect::route('api.v1.permissions.index', [
])->withMessage(trans('acl::permission.permissions-controller-successfully_created'));
} | php | public function store(Request $request)
{
Permission::create($request->all());
\Session::flash('flash_message', 'Permission added!');
return \Redirect::route('api.v1.permissions.index', [
])->withMessage(trans('acl::permission.permissions-controller-successfully_created'));
} | [
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"Permission",
"::",
"create",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"\\",
"Session",
"::",
"flash",
"(",
"'flash_message'",
",",
"'Permission added!'",
")",
";",
"return",
"\\",
"Redirect",
"::",
"route",
"(",
"'api.v1.permissions.index'",
",",
"[",
"]",
")",
"->",
"withMessage",
"(",
"trans",
"(",
"'acl::permission.permissions-controller-successfully_created'",
")",
")",
";",
"}"
] | Store a newly created resource in storage.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\RedirectResponse | [
"Store",
"a",
"newly",
"created",
"resource",
"in",
"storage",
"."
] | train | https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/PermissionController.php#L57-L63 |
meccado/acl-admin-control-panel | src/Http/Controllers/Admin/PermissionController.php | PermissionController.update | public function update(Request $request, $id)
{
$permission = Permission::findOrFail($id)->update($request->only('name', 'label'));
\Session::flash('flash_message', 'Permission updated!');
return \Redirect::route('admin.permissions.index', [
])->withMessage(trans('acl::permission.permissions-controller-successfully_updated'));
} | php | public function update(Request $request, $id)
{
$permission = Permission::findOrFail($id)->update($request->only('name', 'label'));
\Session::flash('flash_message', 'Permission updated!');
return \Redirect::route('admin.permissions.index', [
])->withMessage(trans('acl::permission.permissions-controller-successfully_updated'));
} | [
"public",
"function",
"update",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"permission",
"=",
"Permission",
"::",
"findOrFail",
"(",
"$",
"id",
")",
"->",
"update",
"(",
"$",
"request",
"->",
"only",
"(",
"'name'",
",",
"'label'",
")",
")",
";",
"\\",
"Session",
"::",
"flash",
"(",
"'flash_message'",
",",
"'Permission updated!'",
")",
";",
"return",
"\\",
"Redirect",
"::",
"route",
"(",
"'admin.permissions.index'",
",",
"[",
"]",
")",
"->",
"withMessage",
"(",
"trans",
"(",
"'acl::permission.permissions-controller-successfully_updated'",
")",
")",
";",
"}"
] | Update the specified resource in storage.
@param \Illuminate\Http\Request $request
@param int $id
@return \Illuminate\Http\RedirectResponse | [
"Update",
"the",
"specified",
"resource",
"in",
"storage",
"."
] | train | https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/PermissionController.php#L99-L105 |
meccado/acl-admin-control-panel | src/Http/Controllers/Admin/PermissionController.php | PermissionController.destroy | public function destroy($id)
{
Permission::destroy($id);
\Session::flash('flash_message', 'Permission deleted!');
return \Redirect::route('admin.permissions.index', [
])->withMessage(trans('acl::permission.permissions-controller-successfully_deleted'));
} | php | public function destroy($id)
{
Permission::destroy($id);
\Session::flash('flash_message', 'Permission deleted!');
return \Redirect::route('admin.permissions.index', [
])->withMessage(trans('acl::permission.permissions-controller-successfully_deleted'));
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"Permission",
"::",
"destroy",
"(",
"$",
"id",
")",
";",
"\\",
"Session",
"::",
"flash",
"(",
"'flash_message'",
",",
"'Permission deleted!'",
")",
";",
"return",
"\\",
"Redirect",
"::",
"route",
"(",
"'admin.permissions.index'",
",",
"[",
"]",
")",
"->",
"withMessage",
"(",
"trans",
"(",
"'acl::permission.permissions-controller-successfully_deleted'",
")",
")",
";",
"}"
] | Remove the specified resource from storage.
@param int $id
@return \Illuminate\Http\RedirectResponse | [
"Remove",
"the",
"specified",
"resource",
"from",
"storage",
"."
] | train | https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/PermissionController.php#L113-L119 |
jenwachter/html-form | src/Elements/Parents/Textbox.php | Textbox.compile | public function compile($value = "")
{
$html = $this->compiledLabel;
if (!empty($this->help)) {
$html .= "<div class='help'>{$this->help}</div>";
}
$html .= "<input type=\"{$this->type}\" name=\"{$this->name}\" {$this->compiledAttr} value=\"{$value}\" />";
return $html;
} | php | public function compile($value = "")
{
$html = $this->compiledLabel;
if (!empty($this->help)) {
$html .= "<div class='help'>{$this->help}</div>";
}
$html .= "<input type=\"{$this->type}\" name=\"{$this->name}\" {$this->compiledAttr} value=\"{$value}\" />";
return $html;
} | [
"public",
"function",
"compile",
"(",
"$",
"value",
"=",
"\"\"",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"compiledLabel",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"help",
")",
")",
"{",
"$",
"html",
".=",
"\"<div class='help'>{$this->help}</div>\"",
";",
"}",
"$",
"html",
".=",
"\"<input type=\\\"{$this->type}\\\" name=\\\"{$this->name}\\\" {$this->compiledAttr} value=\\\"{$value}\\\" />\"",
";",
"return",
"$",
"html",
";",
"}"
] | Builds the HTML of the form field.
@param string $value Value of the form field
@return null | [
"Builds",
"the",
"HTML",
"of",
"the",
"form",
"field",
"."
] | train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Parents/Textbox.php#L19-L30 |
spiral-modules/scaffolder | source/ScaffolderModule.php | ScaffolderModule.publish | public function publish(PublisherInterface $publisher, DirectoriesInterface $directories)
{
$publisher->publish(
__DIR__ . '/../resources/config.php',
$directories->directory('config') . ScaffolderConfig::CONFIG . '.php'
);
} | php | public function publish(PublisherInterface $publisher, DirectoriesInterface $directories)
{
$publisher->publish(
__DIR__ . '/../resources/config.php',
$directories->directory('config') . ScaffolderConfig::CONFIG . '.php'
);
} | [
"public",
"function",
"publish",
"(",
"PublisherInterface",
"$",
"publisher",
",",
"DirectoriesInterface",
"$",
"directories",
")",
"{",
"$",
"publisher",
"->",
"publish",
"(",
"__DIR__",
".",
"'/../resources/config.php'",
",",
"$",
"directories",
"->",
"directory",
"(",
"'config'",
")",
".",
"ScaffolderConfig",
"::",
"CONFIG",
".",
"'.php'",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/ScaffolderModule.php#L33-L39 |
parsnick/steak | src/Boot/RunBootstrapsFromConfig.php | RunBootstrapsFromConfig.boot | public function boot(Container $app)
{
$toBoot = (array) $app['config']->get('bootstrap', []);
foreach ($toBoot as $bootstrapClass) {
$app->make($bootstrapClass)->boot($app);
}
} | php | public function boot(Container $app)
{
$toBoot = (array) $app['config']->get('bootstrap', []);
foreach ($toBoot as $bootstrapClass) {
$app->make($bootstrapClass)->boot($app);
}
} | [
"public",
"function",
"boot",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"toBoot",
"=",
"(",
"array",
")",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'bootstrap'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"toBoot",
"as",
"$",
"bootstrapClass",
")",
"{",
"$",
"app",
"->",
"make",
"(",
"$",
"bootstrapClass",
")",
"->",
"boot",
"(",
"$",
"app",
")",
";",
"}",
"}"
] | Call any other bootstraps defined by config.
@param Container $app | [
"Call",
"any",
"other",
"bootstraps",
"defined",
"by",
"config",
"."
] | train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Boot/RunBootstrapsFromConfig.php#L14-L21 |
afrittella/back-project | src/app/Console/Commands/SeedDefaultMenus.php | SeedDefaultMenus.handle | public function handle()
{
$nodes = [
'name' => 'admin-menu',
'title' => 'Administrator Menu',
'description' => 'A default menu you can use for back office purposes',
'route' => null,
'icon' => null,
'is_active' => 1,
'is_protected' => 1,
'children' => [
[
'name' => 'dashboard',
'permission' => 'backend',
'title' => 'Dashboard',
'description' => 'Your dashboard',
'route' => config('back-project.route_prefix').'/dashboard',
'icon' => 'fa fa-dashboard',
'is_active' => 1,
'is_protected' => 1,
],
[
'name' => 'auth',
'title' => 'Authorization',
'description' => 'Manage Users, Roles and Permissions',
'route' => null,
'icon' => 'fa fa-key',
'is_active' => 1,
'children' => [
[
'name' => 'users',
'permission' => 'administration',
'title' => 'Users',
'description' => 'Manage Users',
'route' => config('back-project.route_prefix').'/users',
'icon' => 'fa fa-users',
'is_active' => 1
],
[
'name' => 'roles',
'permission' => 'administration',
'title' => 'Roles',
'description' => 'Manage Roles',
'route' => config('back-project.route_prefix').'/roles',
'icon' => 'fa fa-group',
'is_active' => 1
],
[
'name' => 'permissions',
'permission' => 'administration',
'title' => 'Permissions',
'description' => 'Manage Permissions',
'route' => config('back-project.route_prefix').'/permissions',
'icon' => 'fa fa-group',
'is_active' => 1
]
]
],
[
'name' => 'menus',
'permission' => 'administration',
'title' => 'Menus',
'description' => 'Manage menus',
'route' => config('back-project.route_prefix').'/menus',
'icon' => 'fa fa-ellipsis-v',
'is_active' => 1,
'is_protected' => 1,
],
[
'name' => 'attachments',
'permission' => 'backend',
'title' => 'My Media',
'description' => 'Manage attachments',
'route' => config('back-project.route_prefix').'/attachments',
'icon' => 'fa fa-user-circle-o',
'is_active' => 1,
'is_protected' => 1,
],
[
'name' => 'admin-attachments',
'permission' => 'administration',
'title' => 'All Media',
'description' => 'Manage all user\'s attachments',
'route' => config('back-project.route_prefix').'/media',
'icon' => 'fa fa-file-image-o',
'is_active' => 1,
'is_protected' => 1,
],
]
];
// Truncate menu table
DB::table('menus')->truncate();
Menu::create($nodes);
$menus = DB::table('menus')->select('permission')->where('permission', '<>', '')->groupBy('permission')->get();
$role = Role::where('name', '=', 'administrator')->first();
$user_role = Role::where('name', '=', 'user')->first();
foreach ($menus as $menu):
if (!empty($menu->permission)) {
$permission = Permission::firstOrCreate(['name' => $menu->permission]);
if (!$role->hasPermissionTo($menu->permission)) {
$role->givePermissionTo($menu->permission);
}
if ($menu->permission == 'backend' and !$role->hasPermissionTo($menu->permission)) {
$user_role->givePermissionTo($menu->permission);
}
}
endforeach;
$this->info('Seeding admin-menu'.'...');
} | php | public function handle()
{
$nodes = [
'name' => 'admin-menu',
'title' => 'Administrator Menu',
'description' => 'A default menu you can use for back office purposes',
'route' => null,
'icon' => null,
'is_active' => 1,
'is_protected' => 1,
'children' => [
[
'name' => 'dashboard',
'permission' => 'backend',
'title' => 'Dashboard',
'description' => 'Your dashboard',
'route' => config('back-project.route_prefix').'/dashboard',
'icon' => 'fa fa-dashboard',
'is_active' => 1,
'is_protected' => 1,
],
[
'name' => 'auth',
'title' => 'Authorization',
'description' => 'Manage Users, Roles and Permissions',
'route' => null,
'icon' => 'fa fa-key',
'is_active' => 1,
'children' => [
[
'name' => 'users',
'permission' => 'administration',
'title' => 'Users',
'description' => 'Manage Users',
'route' => config('back-project.route_prefix').'/users',
'icon' => 'fa fa-users',
'is_active' => 1
],
[
'name' => 'roles',
'permission' => 'administration',
'title' => 'Roles',
'description' => 'Manage Roles',
'route' => config('back-project.route_prefix').'/roles',
'icon' => 'fa fa-group',
'is_active' => 1
],
[
'name' => 'permissions',
'permission' => 'administration',
'title' => 'Permissions',
'description' => 'Manage Permissions',
'route' => config('back-project.route_prefix').'/permissions',
'icon' => 'fa fa-group',
'is_active' => 1
]
]
],
[
'name' => 'menus',
'permission' => 'administration',
'title' => 'Menus',
'description' => 'Manage menus',
'route' => config('back-project.route_prefix').'/menus',
'icon' => 'fa fa-ellipsis-v',
'is_active' => 1,
'is_protected' => 1,
],
[
'name' => 'attachments',
'permission' => 'backend',
'title' => 'My Media',
'description' => 'Manage attachments',
'route' => config('back-project.route_prefix').'/attachments',
'icon' => 'fa fa-user-circle-o',
'is_active' => 1,
'is_protected' => 1,
],
[
'name' => 'admin-attachments',
'permission' => 'administration',
'title' => 'All Media',
'description' => 'Manage all user\'s attachments',
'route' => config('back-project.route_prefix').'/media',
'icon' => 'fa fa-file-image-o',
'is_active' => 1,
'is_protected' => 1,
],
]
];
// Truncate menu table
DB::table('menus')->truncate();
Menu::create($nodes);
$menus = DB::table('menus')->select('permission')->where('permission', '<>', '')->groupBy('permission')->get();
$role = Role::where('name', '=', 'administrator')->first();
$user_role = Role::where('name', '=', 'user')->first();
foreach ($menus as $menu):
if (!empty($menu->permission)) {
$permission = Permission::firstOrCreate(['name' => $menu->permission]);
if (!$role->hasPermissionTo($menu->permission)) {
$role->givePermissionTo($menu->permission);
}
if ($menu->permission == 'backend' and !$role->hasPermissionTo($menu->permission)) {
$user_role->givePermissionTo($menu->permission);
}
}
endforeach;
$this->info('Seeding admin-menu'.'...');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"nodes",
"=",
"[",
"'name'",
"=>",
"'admin-menu'",
",",
"'title'",
"=>",
"'Administrator Menu'",
",",
"'description'",
"=>",
"'A default menu you can use for back office purposes'",
",",
"'route'",
"=>",
"null",
",",
"'icon'",
"=>",
"null",
",",
"'is_active'",
"=>",
"1",
",",
"'is_protected'",
"=>",
"1",
",",
"'children'",
"=>",
"[",
"[",
"'name'",
"=>",
"'dashboard'",
",",
"'permission'",
"=>",
"'backend'",
",",
"'title'",
"=>",
"'Dashboard'",
",",
"'description'",
"=>",
"'Your dashboard'",
",",
"'route'",
"=>",
"config",
"(",
"'back-project.route_prefix'",
")",
".",
"'/dashboard'",
",",
"'icon'",
"=>",
"'fa fa-dashboard'",
",",
"'is_active'",
"=>",
"1",
",",
"'is_protected'",
"=>",
"1",
",",
"]",
",",
"[",
"'name'",
"=>",
"'auth'",
",",
"'title'",
"=>",
"'Authorization'",
",",
"'description'",
"=>",
"'Manage Users, Roles and Permissions'",
",",
"'route'",
"=>",
"null",
",",
"'icon'",
"=>",
"'fa fa-key'",
",",
"'is_active'",
"=>",
"1",
",",
"'children'",
"=>",
"[",
"[",
"'name'",
"=>",
"'users'",
",",
"'permission'",
"=>",
"'administration'",
",",
"'title'",
"=>",
"'Users'",
",",
"'description'",
"=>",
"'Manage Users'",
",",
"'route'",
"=>",
"config",
"(",
"'back-project.route_prefix'",
")",
".",
"'/users'",
",",
"'icon'",
"=>",
"'fa fa-users'",
",",
"'is_active'",
"=>",
"1",
"]",
",",
"[",
"'name'",
"=>",
"'roles'",
",",
"'permission'",
"=>",
"'administration'",
",",
"'title'",
"=>",
"'Roles'",
",",
"'description'",
"=>",
"'Manage Roles'",
",",
"'route'",
"=>",
"config",
"(",
"'back-project.route_prefix'",
")",
".",
"'/roles'",
",",
"'icon'",
"=>",
"'fa fa-group'",
",",
"'is_active'",
"=>",
"1",
"]",
",",
"[",
"'name'",
"=>",
"'permissions'",
",",
"'permission'",
"=>",
"'administration'",
",",
"'title'",
"=>",
"'Permissions'",
",",
"'description'",
"=>",
"'Manage Permissions'",
",",
"'route'",
"=>",
"config",
"(",
"'back-project.route_prefix'",
")",
".",
"'/permissions'",
",",
"'icon'",
"=>",
"'fa fa-group'",
",",
"'is_active'",
"=>",
"1",
"]",
"]",
"]",
",",
"[",
"'name'",
"=>",
"'menus'",
",",
"'permission'",
"=>",
"'administration'",
",",
"'title'",
"=>",
"'Menus'",
",",
"'description'",
"=>",
"'Manage menus'",
",",
"'route'",
"=>",
"config",
"(",
"'back-project.route_prefix'",
")",
".",
"'/menus'",
",",
"'icon'",
"=>",
"'fa fa-ellipsis-v'",
",",
"'is_active'",
"=>",
"1",
",",
"'is_protected'",
"=>",
"1",
",",
"]",
",",
"[",
"'name'",
"=>",
"'attachments'",
",",
"'permission'",
"=>",
"'backend'",
",",
"'title'",
"=>",
"'My Media'",
",",
"'description'",
"=>",
"'Manage attachments'",
",",
"'route'",
"=>",
"config",
"(",
"'back-project.route_prefix'",
")",
".",
"'/attachments'",
",",
"'icon'",
"=>",
"'fa fa-user-circle-o'",
",",
"'is_active'",
"=>",
"1",
",",
"'is_protected'",
"=>",
"1",
",",
"]",
",",
"[",
"'name'",
"=>",
"'admin-attachments'",
",",
"'permission'",
"=>",
"'administration'",
",",
"'title'",
"=>",
"'All Media'",
",",
"'description'",
"=>",
"'Manage all user\\'s attachments'",
",",
"'route'",
"=>",
"config",
"(",
"'back-project.route_prefix'",
")",
".",
"'/media'",
",",
"'icon'",
"=>",
"'fa fa-file-image-o'",
",",
"'is_active'",
"=>",
"1",
",",
"'is_protected'",
"=>",
"1",
",",
"]",
",",
"]",
"]",
";",
"// Truncate menu table",
"DB",
"::",
"table",
"(",
"'menus'",
")",
"->",
"truncate",
"(",
")",
";",
"Menu",
"::",
"create",
"(",
"$",
"nodes",
")",
";",
"$",
"menus",
"=",
"DB",
"::",
"table",
"(",
"'menus'",
")",
"->",
"select",
"(",
"'permission'",
")",
"->",
"where",
"(",
"'permission'",
",",
"'<>'",
",",
"''",
")",
"->",
"groupBy",
"(",
"'permission'",
")",
"->",
"get",
"(",
")",
";",
"$",
"role",
"=",
"Role",
"::",
"where",
"(",
"'name'",
",",
"'='",
",",
"'administrator'",
")",
"->",
"first",
"(",
")",
";",
"$",
"user_role",
"=",
"Role",
"::",
"where",
"(",
"'name'",
",",
"'='",
",",
"'user'",
")",
"->",
"first",
"(",
")",
";",
"foreach",
"(",
"$",
"menus",
"as",
"$",
"menu",
")",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"menu",
"->",
"permission",
")",
")",
"{",
"$",
"permission",
"=",
"Permission",
"::",
"firstOrCreate",
"(",
"[",
"'name'",
"=>",
"$",
"menu",
"->",
"permission",
"]",
")",
";",
"if",
"(",
"!",
"$",
"role",
"->",
"hasPermissionTo",
"(",
"$",
"menu",
"->",
"permission",
")",
")",
"{",
"$",
"role",
"->",
"givePermissionTo",
"(",
"$",
"menu",
"->",
"permission",
")",
";",
"}",
"if",
"(",
"$",
"menu",
"->",
"permission",
"==",
"'backend'",
"and",
"!",
"$",
"role",
"->",
"hasPermissionTo",
"(",
"$",
"menu",
"->",
"permission",
")",
")",
"{",
"$",
"user_role",
"->",
"givePermissionTo",
"(",
"$",
"menu",
"->",
"permission",
")",
";",
"}",
"}",
"endforeach",
";",
"$",
"this",
"->",
"info",
"(",
"'Seeding admin-menu'",
".",
"'...'",
")",
";",
"}"
] | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/afrittella/back-project/blob/e1aa2e3ee03d453033f75a4b16f073c60b5f32d1/src/app/Console/Commands/SeedDefaultMenus.php#L26-L144 |
phpmob/changmin | src/PhpMob/CoreBundle/Context/WebUserBasedLocaleContext.php | WebUserBasedLocaleContext.getLocaleCode | public function getLocaleCode(): string
{
$token = $this->tokenStorage->getToken();
if (null === $token) {
throw new LocaleNotFoundException();
}
$user = $token->getUser();
if (!$user instanceof WebUserInterface) {
throw new LocaleNotFoundException();
}
if (null === $user->getLocale()) {
throw new LocaleNotFoundException();
}
return $user->getLocale()->getCode();
} | php | public function getLocaleCode(): string
{
$token = $this->tokenStorage->getToken();
if (null === $token) {
throw new LocaleNotFoundException();
}
$user = $token->getUser();
if (!$user instanceof WebUserInterface) {
throw new LocaleNotFoundException();
}
if (null === $user->getLocale()) {
throw new LocaleNotFoundException();
}
return $user->getLocale()->getCode();
} | [
"public",
"function",
"getLocaleCode",
"(",
")",
":",
"string",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"token",
")",
"{",
"throw",
"new",
"LocaleNotFoundException",
"(",
")",
";",
"}",
"$",
"user",
"=",
"$",
"token",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"instanceof",
"WebUserInterface",
")",
"{",
"throw",
"new",
"LocaleNotFoundException",
"(",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"user",
"->",
"getLocale",
"(",
")",
")",
"{",
"throw",
"new",
"LocaleNotFoundException",
"(",
")",
";",
"}",
"return",
"$",
"user",
"->",
"getLocale",
"(",
")",
"->",
"getCode",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CoreBundle/Context/WebUserBasedLocaleContext.php#L42-L61 |
afrittella/back-project | src/app/Listeners/SendRegistrationEmail.php | SendRegistrationEmail.handle | public function handle(UserRegistered $event)
{
//try {
$user = $this->users->findBy('id', $event->user_id);
$user->notify(new RegistrationEmail($user));
//} catch(\Exception $e) {
//Log::error('lavoro fallito');
//}
} | php | public function handle(UserRegistered $event)
{
//try {
$user = $this->users->findBy('id', $event->user_id);
$user->notify(new RegistrationEmail($user));
//} catch(\Exception $e) {
//Log::error('lavoro fallito');
//}
} | [
"public",
"function",
"handle",
"(",
"UserRegistered",
"$",
"event",
")",
"{",
"//try {",
"$",
"user",
"=",
"$",
"this",
"->",
"users",
"->",
"findBy",
"(",
"'id'",
",",
"$",
"event",
"->",
"user_id",
")",
";",
"$",
"user",
"->",
"notify",
"(",
"new",
"RegistrationEmail",
"(",
"$",
"user",
")",
")",
";",
"//} catch(\\Exception $e) {",
"//Log::error('lavoro fallito');",
"//}",
"}"
] | Handle the event.
@param UserRegistered $event
@return void
@internal param $Event =UserRegistered $event | [
"Handle",
"the",
"event",
"."
] | train | https://github.com/afrittella/back-project/blob/e1aa2e3ee03d453033f75a4b16f073c60b5f32d1/src/app/Listeners/SendRegistrationEmail.php#L30-L39 |
2amigos/yiifoundation | widgets/Pager.php | Pager.run | public function run()
{
$this->registerClientScript();
$buttons = $this->createPageButtons();
if (empty($buttons))
return true;
if ($this->centered) {
echo \CHtml::openTag('div', array('class' => Enum::PAGINATION_CENTERED));
}
echo \CHtml::tag('ul', $this->htmlOptions, implode("\n", $buttons));
if ($this->centered) {
echo \CHtml::closeTag('div');
}
} | php | public function run()
{
$this->registerClientScript();
$buttons = $this->createPageButtons();
if (empty($buttons))
return true;
if ($this->centered) {
echo \CHtml::openTag('div', array('class' => Enum::PAGINATION_CENTERED));
}
echo \CHtml::tag('ul', $this->htmlOptions, implode("\n", $buttons));
if ($this->centered) {
echo \CHtml::closeTag('div');
}
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"this",
"->",
"registerClientScript",
"(",
")",
";",
"$",
"buttons",
"=",
"$",
"this",
"->",
"createPageButtons",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"buttons",
")",
")",
"return",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"centered",
")",
"{",
"echo",
"\\",
"CHtml",
"::",
"openTag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"Enum",
"::",
"PAGINATION_CENTERED",
")",
")",
";",
"}",
"echo",
"\\",
"CHtml",
"::",
"tag",
"(",
"'ul'",
",",
"$",
"this",
"->",
"htmlOptions",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"buttons",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"centered",
")",
"{",
"echo",
"\\",
"CHtml",
"::",
"closeTag",
"(",
"'div'",
")",
";",
"}",
"}"
] | Runs the widget. | [
"Runs",
"the",
"widget",
"."
] | train | https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Pager.php#L69-L83 |
2amigos/yiifoundation | widgets/Pager.php | Pager.registerCssFile | public static function registerCssFile($url = null)
{
if ($url !== null) {
\Yii::app()->getClientScript()->registerCssFile($url);
} else {
Foundation::registerCoreCss();
}
} | php | public static function registerCssFile($url = null)
{
if ($url !== null) {
\Yii::app()->getClientScript()->registerCssFile($url);
} else {
Foundation::registerCoreCss();
}
} | [
"public",
"static",
"function",
"registerCssFile",
"(",
"$",
"url",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"url",
"!==",
"null",
")",
"{",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"getClientScript",
"(",
")",
"->",
"registerCssFile",
"(",
"$",
"url",
")",
";",
"}",
"else",
"{",
"Foundation",
"::",
"registerCoreCss",
"(",
")",
";",
"}",
"}"
] | Registers the needed CSS file.
@param string $url the CSS URL. If null, a default CSS URL will be used. | [
"Registers",
"the",
"needed",
"CSS",
"file",
"."
] | train | https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Pager.php#L90-L98 |
lootils/archiver | src/Lootils/Archiver/TarArchive.php | TarArchive.add | public function add($file, $entry_name = null)
{
$result = $this->tar->addModify($file, '', dirname($file));
if ($result === false) {
throw new ArchiveException('Error adding file ' . $file);
}
return $this;
} | php | public function add($file, $entry_name = null)
{
$result = $this->tar->addModify($file, '', dirname($file));
if ($result === false) {
throw new ArchiveException('Error adding file ' . $file);
}
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"file",
",",
"$",
"entry_name",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"tar",
"->",
"addModify",
"(",
"$",
"file",
",",
"''",
",",
"dirname",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"ArchiveException",
"(",
"'Error adding file '",
".",
"$",
"file",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add the given file to the file archive. | [
"Add",
"the",
"given",
"file",
"to",
"the",
"file",
"archive",
"."
] | train | https://github.com/lootils/archiver/blob/5b801bddfe15f7378a118c4094f04b37abb5a53e/src/Lootils/Archiver/TarArchive.php#L33-L41 |
lootils/archiver | src/Lootils/Archiver/TarArchive.php | TarArchive.extractTo | public function extractTo($destination, $entries = array())
{
$result = false;
if (!empty($entries)) {
$result = $this->tar->extractList($entries, $destination);
} else {
$result = $this->tar->extract($destination, true);
}
if ($result === false) {
throw new ArchiveException('Error extracting archive.');
}
return $this;
} | php | public function extractTo($destination, $entries = array())
{
$result = false;
if (!empty($entries)) {
$result = $this->tar->extractList($entries, $destination);
} else {
$result = $this->tar->extract($destination, true);
}
if ($result === false) {
throw new ArchiveException('Error extracting archive.');
}
return $this;
} | [
"public",
"function",
"extractTo",
"(",
"$",
"destination",
",",
"$",
"entries",
"=",
"array",
"(",
")",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"entries",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"tar",
"->",
"extractList",
"(",
"$",
"entries",
",",
"$",
"destination",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"tar",
"->",
"extract",
"(",
"$",
"destination",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"ArchiveException",
"(",
"'Error extracting archive.'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Extract the given files to the destination. | [
"Extract",
"the",
"given",
"files",
"to",
"the",
"destination",
"."
] | train | https://github.com/lootils/archiver/blob/5b801bddfe15f7378a118c4094f04b37abb5a53e/src/Lootils/Archiver/TarArchive.php#L54-L67 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.