repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
koolphp/koolreport | src/core/ResourceManager.php | ResourceManager.addStyle | public function addStyle($style,$options=array())
{
$options["type"] = Utility::get($options, "type", "text/css");
$this->tags[md5($style)] = array(
"at"=>'begin',
"tag"=>"style",
"options"=>$options,
"content"=>$style,
);
return $this;
} | php | public function addStyle($style,$options=array())
{
$options["type"] = Utility::get($options, "type", "text/css");
$this->tags[md5($style)] = array(
"at"=>'begin',
"tag"=>"style",
"options"=>$options,
"content"=>$style,
);
return $this;
} | [
"public",
"function",
"addStyle",
"(",
"$",
"style",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"[",
"\"type\"",
"]",
"=",
"Utility",
"::",
"get",
"(",
"$",
"options",
",",
"\"type\"",
",",
"\"text/css\"",
")",
";",
"$",
"this",
"->",
"tags",
"[",
"md5",
"(",
"$",
"style",
")",
"]",
"=",
"array",
"(",
"\"at\"",
"=>",
"'begin'",
",",
"\"tag\"",
"=>",
"\"style\"",
",",
"\"options\"",
"=>",
"$",
"options",
",",
"\"content\"",
"=>",
"$",
"style",
",",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adding a css style to report
@param string $style The css style you want to add
@param array $options Additional options for style tag
@return ResourceManager This resource manager object | [
"Adding",
"a",
"css",
"style",
"to",
"report"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ResourceManager.php#L283-L294 |
koolphp/koolreport | src/core/ResourceManager.php | ResourceManager.addCssFile | public function addCssFile($href,$options=array())
{
$options["type"] = Utility::get($options, "type", "text/css");
$options["rel"] = Utility::get($options, "rel", "stylesheet");
$options["href"] = $href;
$this->tags[md5($href)] = array(
"at"=>'begin',
"tag"=>"link",
"options"=>$options,
"content"=>"",
);
return $this;
} | php | public function addCssFile($href,$options=array())
{
$options["type"] = Utility::get($options, "type", "text/css");
$options["rel"] = Utility::get($options, "rel", "stylesheet");
$options["href"] = $href;
$this->tags[md5($href)] = array(
"at"=>'begin',
"tag"=>"link",
"options"=>$options,
"content"=>"",
);
return $this;
} | [
"public",
"function",
"addCssFile",
"(",
"$",
"href",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"[",
"\"type\"",
"]",
"=",
"Utility",
"::",
"get",
"(",
"$",
"options",
",",
"\"type\"",
",",
"\"text/css\"",
")",
";",
"$",
"options",
"[",
"\"rel\"",
"]",
"=",
"Utility",
"::",
"get",
"(",
"$",
"options",
",",
"\"rel\"",
",",
"\"stylesheet\"",
")",
";",
"$",
"options",
"[",
"\"href\"",
"]",
"=",
"$",
"href",
";",
"$",
"this",
"->",
"tags",
"[",
"md5",
"(",
"$",
"href",
")",
"]",
"=",
"array",
"(",
"\"at\"",
"=>",
"'begin'",
",",
"\"tag\"",
"=>",
"\"link\"",
",",
"\"options\"",
"=>",
"$",
"options",
",",
"\"content\"",
"=>",
"\"\"",
",",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adding a css file to the report
@param string $href The url link to css file
@param array $options Additional settings you want to add to link tag
@return ResourceManager This resource manager object | [
"Adding",
"a",
"css",
"file",
"to",
"the",
"report"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ResourceManager.php#L304-L317 |
koolphp/koolreport | src/core/ResourceManager.php | ResourceManager.addLinkTag | public function addLinkTag($options)
{
$unique = "u";
foreach ($options as $key=>$value) {
$unique.="[$key=$value]";
}
$this->tags[md5($unique)] = array(
"at"=>'begin',
"tag"=>"link",
"options"=>$options,
"content"=>"",
);
return $this;
} | php | public function addLinkTag($options)
{
$unique = "u";
foreach ($options as $key=>$value) {
$unique.="[$key=$value]";
}
$this->tags[md5($unique)] = array(
"at"=>'begin',
"tag"=>"link",
"options"=>$options,
"content"=>"",
);
return $this;
} | [
"public",
"function",
"addLinkTag",
"(",
"$",
"options",
")",
"{",
"$",
"unique",
"=",
"\"u\"",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"unique",
".=",
"\"[$key=$value]\"",
";",
"}",
"$",
"this",
"->",
"tags",
"[",
"md5",
"(",
"$",
"unique",
")",
"]",
"=",
"array",
"(",
"\"at\"",
"=>",
"'begin'",
",",
"\"tag\"",
"=>",
"\"link\"",
",",
"\"options\"",
"=>",
"$",
"options",
",",
"\"content\"",
"=>",
"\"\"",
",",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a link tag to the page
Beside css, there could be another type of resources
you want to add via link tag
@param array $options The options you want to add to link tag
@return ResourceManager This resource manager object | [
"Add",
"a",
"link",
"tag",
"to",
"the",
"page"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ResourceManager.php#L329-L342 |
koolphp/koolreport | src/core/ResourceManager.php | ResourceManager.renderTag | public function renderTag($tag)
{
$str = "<".$tag["tag"];
foreach ($tag["options"] as $key=>$value) {
$str.=" $key='$value'";
}
$str.=">".$tag["content"]."</".$tag["tag"].">";
return $str;
} | php | public function renderTag($tag)
{
$str = "<".$tag["tag"];
foreach ($tag["options"] as $key=>$value) {
$str.=" $key='$value'";
}
$str.=">".$tag["content"]."</".$tag["tag"].">";
return $str;
} | [
"public",
"function",
"renderTag",
"(",
"$",
"tag",
")",
"{",
"$",
"str",
"=",
"\"<\"",
".",
"$",
"tag",
"[",
"\"tag\"",
"]",
";",
"foreach",
"(",
"$",
"tag",
"[",
"\"options\"",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"str",
".=",
"\" $key='$value'\"",
";",
"}",
"$",
"str",
".=",
"\">\"",
".",
"$",
"tag",
"[",
"\"content\"",
"]",
".",
"\"</\"",
".",
"$",
"tag",
"[",
"\"tag\"",
"]",
".",
"\">\"",
";",
"return",
"$",
"str",
";",
"}"
] | Render a tag
@param array $tag Tag settings
@return string The hmtl string representing the tag | [
"Render",
"a",
"tag"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ResourceManager.php#L351-L359 |
koolphp/koolreport | src/core/ResourceManager.php | ResourceManager.process | public function process(&$content)
{
//Add resources to the content
$begin = "";
$end = "";
foreach ($this->tags as $tag) {
if ($tag["at"]=="begin") {
$begin.=$this->renderTag($tag);
} else {
$end.=$this->renderTag($tag);
}
}
if ($begin!=='') {
$count=0;
$content=preg_replace(
'/(<body\b[^>]*>)/is',
'$1<###begin###>',
$content,
1,
$count
);
if ($count) {
$content=str_replace('<###begin###>', $begin, $content);
} else {
$content=$begin.$content;
}
}
if ($end!=='') {
$count=0;
$content=preg_replace(
'/(<\\/body\s*>)/is',
'<###end###>$1',
$content,
1,
$count
);
if ($count) {
$content=str_replace('<###end###>', $end, $content);
} else {
$content=$content.$end;
}
}
} | php | public function process(&$content)
{
//Add resources to the content
$begin = "";
$end = "";
foreach ($this->tags as $tag) {
if ($tag["at"]=="begin") {
$begin.=$this->renderTag($tag);
} else {
$end.=$this->renderTag($tag);
}
}
if ($begin!=='') {
$count=0;
$content=preg_replace(
'/(<body\b[^>]*>)/is',
'$1<###begin###>',
$content,
1,
$count
);
if ($count) {
$content=str_replace('<###begin###>', $begin, $content);
} else {
$content=$begin.$content;
}
}
if ($end!=='') {
$count=0;
$content=preg_replace(
'/(<\\/body\s*>)/is',
'<###end###>$1',
$content,
1,
$count
);
if ($count) {
$content=str_replace('<###end###>', $end, $content);
} else {
$content=$content.$end;
}
}
} | [
"public",
"function",
"process",
"(",
"&",
"$",
"content",
")",
"{",
"//Add resources to the content",
"$",
"begin",
"=",
"\"\"",
";",
"$",
"end",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"tags",
"as",
"$",
"tag",
")",
"{",
"if",
"(",
"$",
"tag",
"[",
"\"at\"",
"]",
"==",
"\"begin\"",
")",
"{",
"$",
"begin",
".=",
"$",
"this",
"->",
"renderTag",
"(",
"$",
"tag",
")",
";",
"}",
"else",
"{",
"$",
"end",
".=",
"$",
"this",
"->",
"renderTag",
"(",
"$",
"tag",
")",
";",
"}",
"}",
"if",
"(",
"$",
"begin",
"!==",
"''",
")",
"{",
"$",
"count",
"=",
"0",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"'/(<body\\b[^>]*>)/is'",
",",
"'$1<###begin###>'",
",",
"$",
"content",
",",
"1",
",",
"$",
"count",
")",
";",
"if",
"(",
"$",
"count",
")",
"{",
"$",
"content",
"=",
"str_replace",
"(",
"'<###begin###>'",
",",
"$",
"begin",
",",
"$",
"content",
")",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"$",
"begin",
".",
"$",
"content",
";",
"}",
"}",
"if",
"(",
"$",
"end",
"!==",
"''",
")",
"{",
"$",
"count",
"=",
"0",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"'/(<\\\\/body\\s*>)/is'",
",",
"'<###end###>$1'",
",",
"$",
"content",
",",
"1",
",",
"$",
"count",
")",
";",
"if",
"(",
"$",
"count",
")",
"{",
"$",
"content",
"=",
"str_replace",
"(",
"'<###end###>'",
",",
"$",
"end",
",",
"$",
"content",
")",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"$",
"content",
".",
"$",
"end",
";",
"}",
"}",
"}"
] | Take content of report and adds resource to content
@param string $content Content of report
@return null | [
"Take",
"content",
"of",
"report",
"and",
"adds",
"resource",
"to",
"content"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ResourceManager.php#L368-L413 |
koolphp/koolreport | src/processes/StringTrim.php | StringTrim.onInit | protected function onInit()
{
if (isset($this->params["character_mask"])) {
$this->character_mask = $this->params["character_mask"];
unset($this->params["character_mask"]);
}
} | php | protected function onInit()
{
if (isset($this->params["character_mask"])) {
$this->character_mask = $this->params["character_mask"];
unset($this->params["character_mask"]);
}
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"\"character_mask\"",
"]",
")",
")",
"{",
"$",
"this",
"->",
"character_mask",
"=",
"$",
"this",
"->",
"params",
"[",
"\"character_mask\"",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"params",
"[",
"\"character_mask\"",
"]",
")",
";",
"}",
"}"
] | Handle on initiation
@return null | [
"Handle",
"on",
"initiation"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/StringTrim.php#L50-L56 |
koolphp/koolreport | src/processes/StringTrim.php | StringTrim.onInput | protected function onInput($data)
{
//Process data here
foreach ($this->params as $column) {
if ($this->character_mask) {
$data[$column] = trim($data[$column], $this->character_mask);
} else {
$data[$column] = trim($data[$column]);
}
}
$this->next($data);
} | php | protected function onInput($data)
{
//Process data here
foreach ($this->params as $column) {
if ($this->character_mask) {
$data[$column] = trim($data[$column], $this->character_mask);
} else {
$data[$column] = trim($data[$column]);
}
}
$this->next($data);
} | [
"protected",
"function",
"onInput",
"(",
"$",
"data",
")",
"{",
"//Process data here",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"character_mask",
")",
"{",
"$",
"data",
"[",
"$",
"column",
"]",
"=",
"trim",
"(",
"$",
"data",
"[",
"$",
"column",
"]",
",",
"$",
"this",
"->",
"character_mask",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"column",
"]",
"=",
"trim",
"(",
"$",
"data",
"[",
"$",
"column",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"next",
"(",
"$",
"data",
")",
";",
"}"
] | Handle on data input
@param array $data The input data row
@return null | [
"Handle",
"on",
"data",
"input"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/StringTrim.php#L65-L76 |
koolphp/koolreport | src/core/Node.php | Node.pipe | public function pipe($node)
{
array_push($this->destinations, $node);
$node->source($this);
return $node;
} | php | public function pipe($node)
{
array_push($this->destinations, $node);
$node->source($this);
return $node;
} | [
"public",
"function",
"pipe",
"(",
"$",
"node",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"destinations",
",",
"$",
"node",
")",
";",
"$",
"node",
"->",
"source",
"(",
"$",
"this",
")",
";",
"return",
"$",
"node",
";",
"}"
] | Add a new node that this node will send data to
@param Node $node The node that data will be sent to
@return Node The new node | [
"Add",
"a",
"new",
"node",
"that",
"this",
"node",
"will",
"send",
"data",
"to"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Node.php#L84-L89 |
koolphp/koolreport | src/core/Node.php | Node.previous | public function previous($index=0)
{
if (count($this->sources)>0) {
return Utility::get($this->sources, $index);
}
return null;
} | php | public function previous($index=0)
{
if (count($this->sources)>0) {
return Utility::get($this->sources, $index);
}
return null;
} | [
"public",
"function",
"previous",
"(",
"$",
"index",
"=",
"0",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"sources",
")",
">",
"0",
")",
"{",
"return",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"sources",
",",
"$",
"index",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get the previous source that send data to this node
This method is very helpful if we want to go trace back to the root
source that is sending data. Since a node can receive data from
multiple sources, the $index params help to return the node you need.
By default $index is 0 meaning the first node that streams data to this
node.
@param integer $index The index of the source that you want to get
@return Node The source that sends data to this node | [
"Get",
"the",
"previous",
"source",
"that",
"send",
"data",
"to",
"this",
"node"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Node.php#L104-L110 |
koolphp/koolreport | src/core/Node.php | Node.next | public function next($data)
{
if ($this->destinations!=null) {
foreach ($this->destinations as $node) {
$node->input($data, $this);
}
}
} | php | public function next($data)
{
if ($this->destinations!=null) {
foreach ($this->destinations as $node) {
$node->input($data, $this);
}
}
} | [
"public",
"function",
"next",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"destinations",
"!=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"destinations",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"input",
"(",
"$",
"data",
",",
"$",
"this",
")",
";",
"}",
"}",
"}"
] | Send data row to the next destinations
@param array $data An associate array epresenting a row of data
@return null | [
"Send",
"data",
"row",
"to",
"the",
"next",
"destinations"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Node.php#L155-L162 |
koolphp/koolreport | src/core/Node.php | Node.startInput | public function startInput($source)
{
$this->streamingSource = $source;
$this->is_ended = false;
$this->onInputStart();
foreach ($this->destinations as $node) {
$node->startInput($this);
}
} | php | public function startInput($source)
{
$this->streamingSource = $source;
$this->is_ended = false;
$this->onInputStart();
foreach ($this->destinations as $node) {
$node->startInput($this);
}
} | [
"public",
"function",
"startInput",
"(",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"streamingSource",
"=",
"$",
"source",
";",
"$",
"this",
"->",
"is_ended",
"=",
"false",
";",
"$",
"this",
"->",
"onInputStart",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"destinations",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"startInput",
"(",
"$",
"this",
")",
";",
"}",
"}"
] | Receive signal from source node that this node will be about to receive data
@param Node $source The source that is about to send data
@return null | [
"Receive",
"signal",
"from",
"source",
"node",
"that",
"this",
"node",
"will",
"be",
"about",
"to",
"receive",
"data"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Node.php#L171-L179 |
koolphp/koolreport | src/core/Node.php | Node.endInput | public function endInput($source)
{
$this->streamingSource = $source;
$sourceAllEnded = true;
foreach ($this->sources as $src) {
$sourceAllEnded &= $src->isEnded();
}
if ($sourceAllEnded) {
$this->is_ended = true;
$this->onInputEnd();
foreach ($this->destinations as $node) {
$node->endInput($this);
}
}
} | php | public function endInput($source)
{
$this->streamingSource = $source;
$sourceAllEnded = true;
foreach ($this->sources as $src) {
$sourceAllEnded &= $src->isEnded();
}
if ($sourceAllEnded) {
$this->is_ended = true;
$this->onInputEnd();
foreach ($this->destinations as $node) {
$node->endInput($this);
}
}
} | [
"public",
"function",
"endInput",
"(",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"streamingSource",
"=",
"$",
"source",
";",
"$",
"sourceAllEnded",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"sources",
"as",
"$",
"src",
")",
"{",
"$",
"sourceAllEnded",
"&=",
"$",
"src",
"->",
"isEnded",
"(",
")",
";",
"}",
"if",
"(",
"$",
"sourceAllEnded",
")",
"{",
"$",
"this",
"->",
"is_ended",
"=",
"true",
";",
"$",
"this",
"->",
"onInputEnd",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"destinations",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"endInput",
"(",
"$",
"this",
")",
";",
"}",
"}",
"}"
] | The source will call this method to tell that it finishes sending data
@param Node $source The source that sends data to
@return null | [
"The",
"source",
"will",
"call",
"this",
"method",
"to",
"tell",
"that",
"it",
"finishes",
"sending",
"data"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Node.php#L224-L238 |
koolphp/koolreport | src/core/Node.php | Node.sendMeta | protected function sendMeta($metaData)
{
foreach ($this->destinations as $node) {
$node->receiveMeta($metaData, $this);
}
} | php | protected function sendMeta($metaData)
{
foreach ($this->destinations as $node) {
$node->receiveMeta($metaData, $this);
}
} | [
"protected",
"function",
"sendMeta",
"(",
"$",
"metaData",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"destinations",
"as",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"receiveMeta",
"(",
"$",
"metaData",
",",
"$",
"this",
")",
";",
"}",
"}"
] | Sending meta data to next nodes
@param array $metaData the meta data that will be sent to next nodes
@return null | [
"Sending",
"meta",
"data",
"to",
"next",
"nodes"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Node.php#L279-L284 |
koolphp/koolreport | src/core/Node.php | Node.receiveMeta | public function receiveMeta($metaData,$source)
{
$this->streamingSource = $source;
$this->metaData = $metaData;
$metaData = $this->onMetaReceived($metaData);
$this->sendMeta($metaData);
} | php | public function receiveMeta($metaData,$source)
{
$this->streamingSource = $source;
$this->metaData = $metaData;
$metaData = $this->onMetaReceived($metaData);
$this->sendMeta($metaData);
} | [
"public",
"function",
"receiveMeta",
"(",
"$",
"metaData",
",",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"streamingSource",
"=",
"$",
"source",
";",
"$",
"this",
"->",
"metaData",
"=",
"$",
"metaData",
";",
"$",
"metaData",
"=",
"$",
"this",
"->",
"onMetaReceived",
"(",
"$",
"metaData",
")",
";",
"$",
"this",
"->",
"sendMeta",
"(",
"$",
"metaData",
")",
";",
"}"
] | Recieving meta data from the source
@param array $metaData The meta data receiving from sources
@param array $source The source that sends meta data
@return null | [
"Recieving",
"meta",
"data",
"from",
"the",
"source"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Node.php#L294-L300 |
koolphp/koolreport | src/core/Node.php | Node.requestDataSending | public function requestDataSending()
{
if (!$this->isEnded()) {
foreach ($this->sources as $source) {
$source->requestDataSending();
}
}
return $this;
} | php | public function requestDataSending()
{
if (!$this->isEnded()) {
foreach ($this->sources as $source) {
$source->requestDataSending();
}
}
return $this;
} | [
"public",
"function",
"requestDataSending",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isEnded",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sources",
"as",
"$",
"source",
")",
"{",
"$",
"source",
"->",
"requestDataSending",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Request source nodes to send data.
@return Node This node object | [
"Request",
"source",
"nodes",
"to",
"send",
"data",
"."
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Node.php#L319-L327 |
koolphp/koolreport | src/processes/AppendRow.php | AppendRow.onInputEnd | protected function onInputEnd()
{
$data = array();
if (Utility::isAssoc($this->params)) {
$data = array($this->params);
} else {
$data = $this->params;
}
foreach ($data as $row) {
$this->next($row);
}
} | php | protected function onInputEnd()
{
$data = array();
if (Utility::isAssoc($this->params)) {
$data = array($this->params);
} else {
$data = $this->params;
}
foreach ($data as $row) {
$this->next($row);
}
} | [
"protected",
"function",
"onInputEnd",
"(",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"Utility",
"::",
"isAssoc",
"(",
"$",
"this",
"->",
"params",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"$",
"this",
"->",
"params",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"params",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"next",
"(",
"$",
"row",
")",
";",
"}",
"}"
] | Handle on input end
@return null | [
"Handle",
"on",
"input",
"end"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/AppendRow.php#L46-L57 |
koolphp/koolreport | src/processes/ColumnRename.php | ColumnRename.onMetaReceived | protected function onMetaReceived($metaData)
{
$keys = array_keys($metaData["columns"]);
$values = array_values($metaData["columns"]);
for ($i = 0; $i < count($keys); $i++) {
if (isset($this->params[$keys[$i]])) {
$keys[$i] = $this->params[$keys[$i]];
}
}
$metaData["columns"] = array_combine($keys, $values);
return $metaData;
} | php | protected function onMetaReceived($metaData)
{
$keys = array_keys($metaData["columns"]);
$values = array_values($metaData["columns"]);
for ($i = 0; $i < count($keys); $i++) {
if (isset($this->params[$keys[$i]])) {
$keys[$i] = $this->params[$keys[$i]];
}
}
$metaData["columns"] = array_combine($keys, $values);
return $metaData;
} | [
"protected",
"function",
"onMetaReceived",
"(",
"$",
"metaData",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"metaData",
"[",
"\"columns\"",
"]",
")",
";",
"$",
"values",
"=",
"array_values",
"(",
"$",
"metaData",
"[",
"\"columns\"",
"]",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"keys",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"$",
"keys",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"$",
"keys",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"$",
"keys",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"}",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"=",
"array_combine",
"(",
"$",
"keys",
",",
"$",
"values",
")",
";",
"return",
"$",
"metaData",
";",
"}"
] | Handle on meta received
@param array $metaData The meta data
@return array New meta data | [
"Handle",
"on",
"meta",
"received"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/ColumnRename.php#L44-L56 |
koolphp/koolreport | src/processes/ColumnRename.php | ColumnRename.onInput | public function onInput($row)
{
$keys = array_keys($row);
$values = array_values($row);
for ($i = 0; $i < count($keys); $i++) {
if (isset($this->params[$keys[$i]])) {
$keys[$i] = $this->params[$keys[$i]];
}
}
$this->next(array_combine($keys, $values));
} | php | public function onInput($row)
{
$keys = array_keys($row);
$values = array_values($row);
for ($i = 0; $i < count($keys); $i++) {
if (isset($this->params[$keys[$i]])) {
$keys[$i] = $this->params[$keys[$i]];
}
}
$this->next(array_combine($keys, $values));
} | [
"public",
"function",
"onInput",
"(",
"$",
"row",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"row",
")",
";",
"$",
"values",
"=",
"array_values",
"(",
"$",
"row",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"keys",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"$",
"keys",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"$",
"keys",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"$",
"keys",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"next",
"(",
"array_combine",
"(",
"$",
"keys",
",",
"$",
"values",
")",
")",
";",
"}"
] | Handle on data input
@param array $row The input data row
@return null | [
"Handle",
"on",
"data",
"input"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/ColumnRename.php#L65-L75 |
koolphp/koolreport | src/processes/AggregatedColumn.php | AggregatedColumn.onInputEnd | protected function onInputEnd()
{
$countRows = count($this->data);
$storage = array();
foreach ($this->params as $cKey=>$cValue) {
$storage[$cKey] = array(
"count"=>$countRows,
"sum"=>0,
"min"=>INF,
"max"=>-INF,
);
}
foreach ($this->data as $row) {
foreach ($this->params as $cKey=>$cValue) {
switch(strtolower($cValue[0]))
{
case "sum":
case "avg":
$storage[$cKey]["sum"]+=$row[$cValue[1]];
break;
case "min":
if ($storage[$cKey]["min"]>$row[$cValue[1]]) {
$storage[$cKey]["min"] = $row[$cValue[1]];
}
break;
case "max":
if ($storage[$cKey]["max"]<$row[$cValue[1]]) {
$storage[$cKey]["max"] = $row[$cValue[1]];
}
break;
}
}
}
foreach ($this->data as &$row) {
foreach ($this->params as $cKey=>$cValue) {
switch(strtolower($cValue[0]))
{
case "count":
$row[$cKey] = $storage[$cKey]["count"];
break;
case "sum":
$row[$cKey] = $storage[$cKey]["sum"];
break;
case "min":
$row[$cKey] = $storage[$cKey]["min"];
break;
case "max":
$row[$cKey] = $storage[$cKey]["max"];
break;
case "avg":
if (!isset($storage[$cKey]["avg"])) {
$storage[$cKey]["avg"] = $storage[$cKey]["sum"]/$storage[$cKey]["count"];
}
$row[$cKey] = $storage[$cKey]["avg"];
break;
case "acml":
if (!isset($storage[$cKey]["acml"])) {
$storage[$cKey]["acml"] = 0;
}
$row[$cKey] = $storage[$cKey]["acml"]+$row[$cValue[1]];
$storage[$cKey]["acml"] = $row[$cKey];
break;
}
}
}
while ($item = array_shift($this->data)) {
$this->next($item);
}
} | php | protected function onInputEnd()
{
$countRows = count($this->data);
$storage = array();
foreach ($this->params as $cKey=>$cValue) {
$storage[$cKey] = array(
"count"=>$countRows,
"sum"=>0,
"min"=>INF,
"max"=>-INF,
);
}
foreach ($this->data as $row) {
foreach ($this->params as $cKey=>$cValue) {
switch(strtolower($cValue[0]))
{
case "sum":
case "avg":
$storage[$cKey]["sum"]+=$row[$cValue[1]];
break;
case "min":
if ($storage[$cKey]["min"]>$row[$cValue[1]]) {
$storage[$cKey]["min"] = $row[$cValue[1]];
}
break;
case "max":
if ($storage[$cKey]["max"]<$row[$cValue[1]]) {
$storage[$cKey]["max"] = $row[$cValue[1]];
}
break;
}
}
}
foreach ($this->data as &$row) {
foreach ($this->params as $cKey=>$cValue) {
switch(strtolower($cValue[0]))
{
case "count":
$row[$cKey] = $storage[$cKey]["count"];
break;
case "sum":
$row[$cKey] = $storage[$cKey]["sum"];
break;
case "min":
$row[$cKey] = $storage[$cKey]["min"];
break;
case "max":
$row[$cKey] = $storage[$cKey]["max"];
break;
case "avg":
if (!isset($storage[$cKey]["avg"])) {
$storage[$cKey]["avg"] = $storage[$cKey]["sum"]/$storage[$cKey]["count"];
}
$row[$cKey] = $storage[$cKey]["avg"];
break;
case "acml":
if (!isset($storage[$cKey]["acml"])) {
$storage[$cKey]["acml"] = 0;
}
$row[$cKey] = $storage[$cKey]["acml"]+$row[$cValue[1]];
$storage[$cKey]["acml"] = $row[$cKey];
break;
}
}
}
while ($item = array_shift($this->data)) {
$this->next($item);
}
} | [
"protected",
"function",
"onInputEnd",
"(",
")",
"{",
"$",
"countRows",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"storage",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"cKey",
"=>",
"$",
"cValue",
")",
"{",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"=",
"array",
"(",
"\"count\"",
"=>",
"$",
"countRows",
",",
"\"sum\"",
"=>",
"0",
",",
"\"min\"",
"=>",
"INF",
",",
"\"max\"",
"=>",
"-",
"INF",
",",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"row",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"cKey",
"=>",
"$",
"cValue",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"cValue",
"[",
"0",
"]",
")",
")",
"{",
"case",
"\"sum\"",
":",
"case",
"\"avg\"",
":",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"sum\"",
"]",
"+=",
"$",
"row",
"[",
"$",
"cValue",
"[",
"1",
"]",
"]",
";",
"break",
";",
"case",
"\"min\"",
":",
"if",
"(",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"min\"",
"]",
">",
"$",
"row",
"[",
"$",
"cValue",
"[",
"1",
"]",
"]",
")",
"{",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"min\"",
"]",
"=",
"$",
"row",
"[",
"$",
"cValue",
"[",
"1",
"]",
"]",
";",
"}",
"break",
";",
"case",
"\"max\"",
":",
"if",
"(",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"max\"",
"]",
"<",
"$",
"row",
"[",
"$",
"cValue",
"[",
"1",
"]",
"]",
")",
"{",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"max\"",
"]",
"=",
"$",
"row",
"[",
"$",
"cValue",
"[",
"1",
"]",
"]",
";",
"}",
"break",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"&",
"$",
"row",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"cKey",
"=>",
"$",
"cValue",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"cValue",
"[",
"0",
"]",
")",
")",
"{",
"case",
"\"count\"",
":",
"$",
"row",
"[",
"$",
"cKey",
"]",
"=",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"count\"",
"]",
";",
"break",
";",
"case",
"\"sum\"",
":",
"$",
"row",
"[",
"$",
"cKey",
"]",
"=",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"sum\"",
"]",
";",
"break",
";",
"case",
"\"min\"",
":",
"$",
"row",
"[",
"$",
"cKey",
"]",
"=",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"min\"",
"]",
";",
"break",
";",
"case",
"\"max\"",
":",
"$",
"row",
"[",
"$",
"cKey",
"]",
"=",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"max\"",
"]",
";",
"break",
";",
"case",
"\"avg\"",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"avg\"",
"]",
")",
")",
"{",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"avg\"",
"]",
"=",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"sum\"",
"]",
"/",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"count\"",
"]",
";",
"}",
"$",
"row",
"[",
"$",
"cKey",
"]",
"=",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"avg\"",
"]",
";",
"break",
";",
"case",
"\"acml\"",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"acml\"",
"]",
")",
")",
"{",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"acml\"",
"]",
"=",
"0",
";",
"}",
"$",
"row",
"[",
"$",
"cKey",
"]",
"=",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"acml\"",
"]",
"+",
"$",
"row",
"[",
"$",
"cValue",
"[",
"1",
"]",
"]",
";",
"$",
"storage",
"[",
"$",
"cKey",
"]",
"[",
"\"acml\"",
"]",
"=",
"$",
"row",
"[",
"$",
"cKey",
"]",
";",
"break",
";",
"}",
"}",
"}",
"while",
"(",
"$",
"item",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"next",
"(",
"$",
"item",
")",
";",
"}",
"}"
] | Handle on input end
@return null | [
"Handle",
"on",
"input",
"end"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/AggregatedColumn.php#L89-L159 |
koolphp/koolreport | src/KoolReport.php | KoolReport.js | public static function js()
{
$jsPath = dirname(__FILE__) . "/clients/core/KoolReport.js";
if (is_file($jsPath)) {
return "<script type='text/javascript'>"
.preg_replace('/\s+/S', " ", file_get_contents($jsPath))
."</script>";
} else {
throw new \Exception("Could not find KoolReport.js");
}
} | php | public static function js()
{
$jsPath = dirname(__FILE__) . "/clients/core/KoolReport.js";
if (is_file($jsPath)) {
return "<script type='text/javascript'>"
.preg_replace('/\s+/S', " ", file_get_contents($jsPath))
."</script>";
} else {
throw new \Exception("Could not find KoolReport.js");
}
} | [
"public",
"static",
"function",
"js",
"(",
")",
"{",
"$",
"jsPath",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/clients/core/KoolReport.js\"",
";",
"if",
"(",
"is_file",
"(",
"$",
"jsPath",
")",
")",
"{",
"return",
"\"<script type='text/javascript'>\"",
".",
"preg_replace",
"(",
"'/\\s+/S'",
",",
"\" \"",
",",
"file_get_contents",
"(",
"$",
"jsPath",
")",
")",
".",
"\"</script>\"",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not find KoolReport.js\"",
")",
";",
"}",
"}"
] | Return the javascript of KoolReport
@return string Javascript of KoolReport | [
"Return",
"the",
"javascript",
"of",
"KoolReport"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L54-L64 |
koolphp/koolreport | src/KoolReport.php | KoolReport.registerEvent | public function registerEvent($name, $methodName, $prepend = false)
{
if (!isset($this->events[$name])) {
$this->events[$name] = array();
}
if (!in_array($methodName, $this->events[$name])) {
if ($prepend) {
array_unshift($this->events[$name], $methodName);
} else {
array_push($this->events[$name], $methodName);
}
}
return $this;
} | php | public function registerEvent($name, $methodName, $prepend = false)
{
if (!isset($this->events[$name])) {
$this->events[$name] = array();
}
if (!in_array($methodName, $this->events[$name])) {
if ($prepend) {
array_unshift($this->events[$name], $methodName);
} else {
array_push($this->events[$name], $methodName);
}
}
return $this;
} | [
"public",
"function",
"registerEvent",
"(",
"$",
"name",
",",
"$",
"methodName",
",",
"$",
"prepend",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"methodName",
",",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"$",
"prepend",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
",",
"$",
"methodName",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
",",
"$",
"methodName",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Register callback function to be called on certain events
@param string $name Name of event
@param function $methodName A anonymous function to be called
@param bool $prepend Whether the event should be prepended.
@return KoolReport the report object | [
"Register",
"callback",
"function",
"to",
"be",
"called",
"on",
"certain",
"events"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L114-L127 |
koolphp/koolreport | src/KoolReport.php | KoolReport.fireEvent | public function fireEvent($name, $params = null)
{
$handleList = Utility::get($this->events, $name, null);
$result = true;
if ($handleList) {
foreach ($handleList as $methodName) {
if (gettype($methodName) == "string") {
$return = $this->$methodName($params);
} else {
$return = $methodName($params);
}
$result &= ($return !== null) ? $return : true;
}
}
//Allow to write event handle in the report
if (method_exists($this, $name)) {
$return = $this->$name($params);
$result &= ($return !== null) ? $return : true;
}
return $result;
} | php | public function fireEvent($name, $params = null)
{
$handleList = Utility::get($this->events, $name, null);
$result = true;
if ($handleList) {
foreach ($handleList as $methodName) {
if (gettype($methodName) == "string") {
$return = $this->$methodName($params);
} else {
$return = $methodName($params);
}
$result &= ($return !== null) ? $return : true;
}
}
//Allow to write event handle in the report
if (method_exists($this, $name)) {
$return = $this->$name($params);
$result &= ($return !== null) ? $return : true;
}
return $result;
} | [
"public",
"function",
"fireEvent",
"(",
"$",
"name",
",",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"handleList",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"events",
",",
"$",
"name",
",",
"null",
")",
";",
"$",
"result",
"=",
"true",
";",
"if",
"(",
"$",
"handleList",
")",
"{",
"foreach",
"(",
"$",
"handleList",
"as",
"$",
"methodName",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"methodName",
")",
"==",
"\"string\"",
")",
"{",
"$",
"return",
"=",
"$",
"this",
"->",
"$",
"methodName",
"(",
"$",
"params",
")",
";",
"}",
"else",
"{",
"$",
"return",
"=",
"$",
"methodName",
"(",
"$",
"params",
")",
";",
"}",
"$",
"result",
"&=",
"(",
"$",
"return",
"!==",
"null",
")",
"?",
"$",
"return",
":",
"true",
";",
"}",
"}",
"//Allow to write event handle in the report",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"name",
")",
")",
"{",
"$",
"return",
"=",
"$",
"this",
"->",
"$",
"name",
"(",
"$",
"params",
")",
";",
"$",
"result",
"&=",
"(",
"$",
"return",
"!==",
"null",
")",
"?",
"$",
"return",
":",
"true",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Fire an event with parameters in array form
@param string $name Name of event
@param array $params Parameters going with the event
@return bool Approve or disapprove action | [
"Fire",
"an",
"event",
"with",
"parameters",
"in",
"array",
"form"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L137-L157 |
koolphp/koolreport | src/KoolReport.php | KoolReport.getServiceConstructs | protected function getServiceConstructs()
{
$serviceConstructs = array();
$public_methods = get_class_methods($this);
foreach ($public_methods as $method) {
if (strpos($method, "__construct") === 0 && strlen($method) > 11) {
array_push($serviceConstructs, $method);
}
}
return $serviceConstructs;
} | php | protected function getServiceConstructs()
{
$serviceConstructs = array();
$public_methods = get_class_methods($this);
foreach ($public_methods as $method) {
if (strpos($method, "__construct") === 0 && strlen($method) > 11) {
array_push($serviceConstructs, $method);
}
}
return $serviceConstructs;
} | [
"protected",
"function",
"getServiceConstructs",
"(",
")",
"{",
"$",
"serviceConstructs",
"=",
"array",
"(",
")",
";",
"$",
"public_methods",
"=",
"get_class_methods",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"public_methods",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"method",
",",
"\"__construct\"",
")",
"===",
"0",
"&&",
"strlen",
"(",
"$",
"method",
")",
">",
"11",
")",
"{",
"array_push",
"(",
"$",
"serviceConstructs",
",",
"$",
"method",
")",
";",
"}",
"}",
"return",
"$",
"serviceConstructs",
";",
"}"
] | Return list of contruction methods of services
@return array List of construction methods | [
"Return",
"list",
"of",
"contruction",
"methods",
"of",
"services"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L164-L174 |
koolphp/koolreport | src/KoolReport.php | KoolReport.src | protected function src($name = null)
{
$dataSources = Utility::get($this->reportSettings, "dataSources", array());
if (count($dataSources) == 0) {
throw new \Exception("There is no source available, please add at least one in the settings()");
return false;
}
if (!$name) {
$name = Utility::get(array_keys($dataSources), 0);
}
$dataSourceSetting = Utility::get($dataSources, $name);
if (!$dataSourceSetting) {
throw new \Exception("Datasource not found '$name'");
return false;
}
$dataSourceClass = Utility::get(
$dataSourceSetting,
"class",
'\koolreport\datasources\PdoDataSource'
);
$dataSourceClass = str_replace("/", "\\", $dataSourceClass);
$dataSource = new $dataSourceClass($dataSourceSetting, $this);
array_push($this->dataSources, $dataSource);
return $dataSource;
} | php | protected function src($name = null)
{
$dataSources = Utility::get($this->reportSettings, "dataSources", array());
if (count($dataSources) == 0) {
throw new \Exception("There is no source available, please add at least one in the settings()");
return false;
}
if (!$name) {
$name = Utility::get(array_keys($dataSources), 0);
}
$dataSourceSetting = Utility::get($dataSources, $name);
if (!$dataSourceSetting) {
throw new \Exception("Datasource not found '$name'");
return false;
}
$dataSourceClass = Utility::get(
$dataSourceSetting,
"class",
'\koolreport\datasources\PdoDataSource'
);
$dataSourceClass = str_replace("/", "\\", $dataSourceClass);
$dataSource = new $dataSourceClass($dataSourceSetting, $this);
array_push($this->dataSources, $dataSource);
return $dataSource;
} | [
"protected",
"function",
"src",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"dataSources",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"reportSettings",
",",
"\"dataSources\"",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"dataSources",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"There is no source available, please add at least one in the settings()\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"Utility",
"::",
"get",
"(",
"array_keys",
"(",
"$",
"dataSources",
")",
",",
"0",
")",
";",
"}",
"$",
"dataSourceSetting",
"=",
"Utility",
"::",
"get",
"(",
"$",
"dataSources",
",",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"dataSourceSetting",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Datasource not found '$name'\"",
")",
";",
"return",
"false",
";",
"}",
"$",
"dataSourceClass",
"=",
"Utility",
"::",
"get",
"(",
"$",
"dataSourceSetting",
",",
"\"class\"",
",",
"'\\koolreport\\datasources\\PdoDataSource'",
")",
";",
"$",
"dataSourceClass",
"=",
"str_replace",
"(",
"\"/\"",
",",
"\"\\\\\"",
",",
"$",
"dataSourceClass",
")",
";",
"$",
"dataSource",
"=",
"new",
"$",
"dataSourceClass",
"(",
"$",
"dataSourceSetting",
",",
"$",
"this",
")",
";",
"array_push",
"(",
"$",
"this",
"->",
"dataSources",
",",
"$",
"dataSource",
")",
";",
"return",
"$",
"dataSource",
";",
"}"
] | Get a new source
@param string $name Name of the source, if no name specified
then get the first one
@return DataSource The data source object | [
"Get",
"a",
"new",
"source"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L238-L266 |
koolphp/koolreport | src/KoolReport.php | KoolReport.dataStore | public function dataStore($name)
{
if (gettype($name) == "string") {
if (!isset($this->dataStores[$name])) {
$this->dataStores[$name] = new DataStore;
}
return $this->dataStores[$name];
} else {
//$name's type is different from string
//return everything for further process
return $name;
}
} | php | public function dataStore($name)
{
if (gettype($name) == "string") {
if (!isset($this->dataStores[$name])) {
$this->dataStores[$name] = new DataStore;
}
return $this->dataStores[$name];
} else {
//$name's type is different from string
//return everything for further process
return $name;
}
} | [
"public",
"function",
"dataStore",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"name",
")",
"==",
"\"string\"",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"dataStores",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"dataStores",
"[",
"$",
"name",
"]",
"=",
"new",
"DataStore",
";",
"}",
"return",
"$",
"this",
"->",
"dataStores",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"//$name's type is different from string",
"//return everything for further process",
"return",
"$",
"name",
";",
"}",
"}"
] | Get the data store with a name, if not found, create a new one
@param string $name The name of data store
@return DataStore The datastore object | [
"Get",
"the",
"data",
"store",
"with",
"a",
"name",
"if",
"not",
"found",
"create",
"a",
"new",
"one"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L275-L287 |
koolphp/koolreport | src/KoolReport.php | KoolReport.run | public function run()
{
if ($this->fireEvent("OnBeforeRun")) {
if ($this->dataSources != null) {
foreach ($this->dataSources as $dataSource) {
if (!$dataSource->isEnded()) {
$dataSource->start();
}
}
}
}
$this->fireEvent("OnRunEnd");
return $this;
} | php | public function run()
{
if ($this->fireEvent("OnBeforeRun")) {
if ($this->dataSources != null) {
foreach ($this->dataSources as $dataSource) {
if (!$dataSource->isEnded()) {
$dataSource->start();
}
}
}
}
$this->fireEvent("OnRunEnd");
return $this;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fireEvent",
"(",
"\"OnBeforeRun\"",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dataSources",
"!=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dataSources",
"as",
"$",
"dataSource",
")",
"{",
"if",
"(",
"!",
"$",
"dataSource",
"->",
"isEnded",
"(",
")",
")",
"{",
"$",
"dataSource",
"->",
"start",
"(",
")",
";",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"fireEvent",
"(",
"\"OnRunEnd\"",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Run the report
@return KoolReport Return this report object | [
"Run",
"the",
"report"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L294-L307 |
koolphp/koolreport | src/KoolReport.php | KoolReport.debug | public function debug()
{
$oldActiveReport = (isset($GLOBALS["__ACTIVE_KOOLREPORT__"]))
? $GLOBALS["__ACTIVE_KOOLREPORT__"] : null;
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $this;
include dirname(__FILE__) . "/debug.view.php";
if ($oldActiveReport === null) {
unset($GLOBALS["__ACTIVE_KOOLREPORT__"]);
} else {
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $oldActiveReport;
}
} | php | public function debug()
{
$oldActiveReport = (isset($GLOBALS["__ACTIVE_KOOLREPORT__"]))
? $GLOBALS["__ACTIVE_KOOLREPORT__"] : null;
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $this;
include dirname(__FILE__) . "/debug.view.php";
if ($oldActiveReport === null) {
unset($GLOBALS["__ACTIVE_KOOLREPORT__"]);
} else {
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $oldActiveReport;
}
} | [
"public",
"function",
"debug",
"(",
")",
"{",
"$",
"oldActiveReport",
"=",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
")",
")",
"?",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
":",
"null",
";",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
"=",
"$",
"this",
";",
"include",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/debug.view.php\"",
";",
"if",
"(",
"$",
"oldActiveReport",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
")",
";",
"}",
"else",
"{",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
"=",
"$",
"oldActiveReport",
";",
"}",
"}"
] | Return debug view
@return null | [
"Return",
"debug",
"view"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L314-L325 |
koolphp/koolreport | src/KoolReport.php | KoolReport.innerView | public function innerView($view, $params = null, $return = false)
{
$currentDir = dirname(Utility::getClassPath($this));
ob_start();
if ($params) {
foreach ($params as $key => $value) {
$$key = $value;
}
}
include $currentDir . "/" . $view . ".view.php";
$content = ob_get_clean();
if ($return) {
return $content;
} else {
echo $content;
}
} | php | public function innerView($view, $params = null, $return = false)
{
$currentDir = dirname(Utility::getClassPath($this));
ob_start();
if ($params) {
foreach ($params as $key => $value) {
$$key = $value;
}
}
include $currentDir . "/" . $view . ".view.php";
$content = ob_get_clean();
if ($return) {
return $content;
} else {
echo $content;
}
} | [
"public",
"function",
"innerView",
"(",
"$",
"view",
",",
"$",
"params",
"=",
"null",
",",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"currentDir",
"=",
"dirname",
"(",
"Utility",
"::",
"getClassPath",
"(",
"$",
"this",
")",
")",
";",
"ob_start",
"(",
")",
";",
"if",
"(",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"}",
"include",
"$",
"currentDir",
".",
"\"/\"",
".",
"$",
"view",
".",
"\".view.php\"",
";",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"content",
";",
"}",
"else",
"{",
"echo",
"$",
"content",
";",
"}",
"}"
] | Render inner view
@param string $view The view name
@param array $params Parameters for the view
@param bool $return Wher the string should be return of be rendered
@return string If the $return is set to true then string representing
the view will be return. | [
"Render",
"inner",
"view"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L337-L353 |
koolphp/koolreport | src/KoolReport.php | KoolReport.render | public function render($view = null, $return = false)
{
if ($view === null) {
$view = Utility::getClassName($this);
} else {
if (gettype($view) == "boolean") {
$return = $view;
$view = Utility::getClassName($this);
}
}
$currentDir = dirname(Utility::getClassPath($this));
if (is_file($currentDir . "/" . $view . ".view.php")) {
$content = "";
if ($this->fireEvent("OnBeforeRender")) {
ob_start();
if (!isset($_POST["@subReport"])) {
//If this is subreport request, we dont want to render
//KoolReport.widget.js again
$this->registerEvent(
"OnResourceInit",
function () {
$this->getResourceManager()->addScriptFileOnBegin(
$this->getResourceManager()->publishAssetFolder(
realpath(dirname(__FILE__) . "/clients/core")
) . "/KoolReport.js"
);
},
true
); //Register on top
}
$this->getResourceManager()->init();
$oldActiveReport = (isset($GLOBALS["__ACTIVE_KOOLREPORT__"]))
? $GLOBALS["__ACTIVE_KOOLREPORT__"] : null;
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $this;
include $currentDir . "/" . $view . ".view.php";
$content = ob_get_clean();
//This will help to solve issue of report inside report
if ($oldActiveReport === null) {
unset($GLOBALS["__ACTIVE_KOOLREPORT__"]);
} else {
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $oldActiveReport;
}
//Adding resource to content
if ($this->fireEvent("OnBeforeResourceAttached")) {
$this->getResourceManager()->process($content);
$this->fireEvent("OnResourceAttached");
}
$this->fireEvent("OnRenderEnd", array('content' => &$content));
if ($return) {
return $content;
} else {
echo $content;
}
}
} else {
$this->debug();
}
} | php | public function render($view = null, $return = false)
{
if ($view === null) {
$view = Utility::getClassName($this);
} else {
if (gettype($view) == "boolean") {
$return = $view;
$view = Utility::getClassName($this);
}
}
$currentDir = dirname(Utility::getClassPath($this));
if (is_file($currentDir . "/" . $view . ".view.php")) {
$content = "";
if ($this->fireEvent("OnBeforeRender")) {
ob_start();
if (!isset($_POST["@subReport"])) {
//If this is subreport request, we dont want to render
//KoolReport.widget.js again
$this->registerEvent(
"OnResourceInit",
function () {
$this->getResourceManager()->addScriptFileOnBegin(
$this->getResourceManager()->publishAssetFolder(
realpath(dirname(__FILE__) . "/clients/core")
) . "/KoolReport.js"
);
},
true
); //Register on top
}
$this->getResourceManager()->init();
$oldActiveReport = (isset($GLOBALS["__ACTIVE_KOOLREPORT__"]))
? $GLOBALS["__ACTIVE_KOOLREPORT__"] : null;
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $this;
include $currentDir . "/" . $view . ".view.php";
$content = ob_get_clean();
//This will help to solve issue of report inside report
if ($oldActiveReport === null) {
unset($GLOBALS["__ACTIVE_KOOLREPORT__"]);
} else {
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $oldActiveReport;
}
//Adding resource to content
if ($this->fireEvent("OnBeforeResourceAttached")) {
$this->getResourceManager()->process($content);
$this->fireEvent("OnResourceAttached");
}
$this->fireEvent("OnRenderEnd", array('content' => &$content));
if ($return) {
return $content;
} else {
echo $content;
}
}
} else {
$this->debug();
}
} | [
"public",
"function",
"render",
"(",
"$",
"view",
"=",
"null",
",",
"$",
"return",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"view",
"===",
"null",
")",
"{",
"$",
"view",
"=",
"Utility",
"::",
"getClassName",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"if",
"(",
"gettype",
"(",
"$",
"view",
")",
"==",
"\"boolean\"",
")",
"{",
"$",
"return",
"=",
"$",
"view",
";",
"$",
"view",
"=",
"Utility",
"::",
"getClassName",
"(",
"$",
"this",
")",
";",
"}",
"}",
"$",
"currentDir",
"=",
"dirname",
"(",
"Utility",
"::",
"getClassPath",
"(",
"$",
"this",
")",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"currentDir",
".",
"\"/\"",
".",
"$",
"view",
".",
"\".view.php\"",
")",
")",
"{",
"$",
"content",
"=",
"\"\"",
";",
"if",
"(",
"$",
"this",
"->",
"fireEvent",
"(",
"\"OnBeforeRender\"",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"\"@subReport\"",
"]",
")",
")",
"{",
"//If this is subreport request, we dont want to render ",
"//KoolReport.widget.js again",
"$",
"this",
"->",
"registerEvent",
"(",
"\"OnResourceInit\"",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"addScriptFileOnBegin",
"(",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"publishAssetFolder",
"(",
"realpath",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/clients/core\"",
")",
")",
".",
"\"/KoolReport.js\"",
")",
";",
"}",
",",
"true",
")",
";",
"//Register on top",
"}",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"init",
"(",
")",
";",
"$",
"oldActiveReport",
"=",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
")",
")",
"?",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
":",
"null",
";",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
"=",
"$",
"this",
";",
"include",
"$",
"currentDir",
".",
"\"/\"",
".",
"$",
"view",
".",
"\".view.php\"",
";",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"//This will help to solve issue of report inside report",
"if",
"(",
"$",
"oldActiveReport",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
")",
";",
"}",
"else",
"{",
"$",
"GLOBALS",
"[",
"\"__ACTIVE_KOOLREPORT__\"",
"]",
"=",
"$",
"oldActiveReport",
";",
"}",
"//Adding resource to content",
"if",
"(",
"$",
"this",
"->",
"fireEvent",
"(",
"\"OnBeforeResourceAttached\"",
")",
")",
"{",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"process",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"fireEvent",
"(",
"\"OnResourceAttached\"",
")",
";",
"}",
"$",
"this",
"->",
"fireEvent",
"(",
"\"OnRenderEnd\"",
",",
"array",
"(",
"'content'",
"=>",
"&",
"$",
"content",
")",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"content",
";",
"}",
"else",
"{",
"echo",
"$",
"content",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"debug",
"(",
")",
";",
"}",
"}"
] | Reder the view, if no view specified then try to look for the
view with name {report_class}.view.php
If not found, render debug view
@param string $view The view name
@param bool $return Whether return the view intead of rendering
@return bool If true the view will be returned
instead of being rendered | [
"Reder",
"the",
"view",
"if",
"no",
"view",
"specified",
"then",
"try",
"to",
"look",
"for",
"the",
"view",
"with",
"name",
"{",
"report_class",
"}",
".",
"view",
".",
"php",
"If",
"not",
"found",
"render",
"debug",
"view"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/KoolReport.php#L366-L426 |
koolphp/koolreport | src/processes/Limit.php | Limit.onInit | protected function onInit()
{
$this->limit = Utility::get($this->params, 0, 10);
$this->offset = Utility::get($this->params, 1, 0);
} | php | protected function onInit()
{
$this->limit = Utility::get($this->params, 0, 10);
$this->offset = Utility::get($this->params, 1, 0);
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"$",
"this",
"->",
"limit",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"0",
",",
"10",
")",
";",
"$",
"this",
"->",
"offset",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"1",
",",
"0",
")",
";",
"}"
] | Handle on initiation
@return null | [
"Handle",
"on",
"initiation"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Limit.php#L45-L49 |
koolphp/koolreport | src/processes/Limit.php | Limit.onInput | protected function onInput($data)
{
$this->index++;
if ($this->index >= $this->offset && $this->index < $this->offset + $this->limit) {
$this->next($data);
}
} | php | protected function onInput($data)
{
$this->index++;
if ($this->index >= $this->offset && $this->index < $this->offset + $this->limit) {
$this->next($data);
}
} | [
"protected",
"function",
"onInput",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"index",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"index",
">=",
"$",
"this",
"->",
"offset",
"&&",
"$",
"this",
"->",
"index",
"<",
"$",
"this",
"->",
"offset",
"+",
"$",
"this",
"->",
"limit",
")",
"{",
"$",
"this",
"->",
"next",
"(",
"$",
"data",
")",
";",
"}",
"}"
] | Handle on data input
@param array $data The input data row
@return null | [
"Handle",
"on",
"data",
"input"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Limit.php#L68-L74 |
koolphp/koolreport | src/datasources/CSVDataSource.php | CSVDataSource.onInit | protected function onInit()
{
$this->filePath = Utility::get($this->params, "filePath");
$this->fieldSeparator = Utility::get($this->params, "fieldSeparator", ",");
$this->charset = Utility::get($this->params, "charset");
$this->precision = Utility::get($this->params, "precision", 100);
$this->firstRowData = Utility::get($this->params, "firstRowData", false);
} | php | protected function onInit()
{
$this->filePath = Utility::get($this->params, "filePath");
$this->fieldSeparator = Utility::get($this->params, "fieldSeparator", ",");
$this->charset = Utility::get($this->params, "charset");
$this->precision = Utility::get($this->params, "precision", 100);
$this->firstRowData = Utility::get($this->params, "firstRowData", false);
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"$",
"this",
"->",
"filePath",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"filePath\"",
")",
";",
"$",
"this",
"->",
"fieldSeparator",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"fieldSeparator\"",
",",
"\",\"",
")",
";",
"$",
"this",
"->",
"charset",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"charset\"",
")",
";",
"$",
"this",
"->",
"precision",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"precision\"",
",",
"100",
")",
";",
"$",
"this",
"->",
"firstRowData",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"firstRowData\"",
",",
"false",
")",
";",
"}"
] | Init the datasource
@return null | [
"Init",
"the",
"datasource"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/CSVDataSource.php#L79-L86 |
koolphp/koolreport | src/datasources/CSVDataSource.php | CSVDataSource.start | public function start()
{
// $offset = 0;
// //Go to where we were when we ended the last batch
// fseek($fileHandle, $offset);
// fgetcsv($fileHandle)
// $offset = ftell($fileHandle);
$data = array();
if (($handle = fopen($this->filePath, "r")) !== false) {
$row = fgetcsv($handle, 0, $this->fieldSeparator);
//Convert to UTF8 if assign charset to utf8
$row = array_map(
function ($item) {
return ($this->charset=="utf8" && is_string($item))
?utf8_encode($item):$item;
},
$row
);
if (is_array($row)) {
if (!$this->firstRowData) {
$columnNames = $row;
} else {
$columnNames = array();
for ($i = 0; $i < count($row); $i++) {
array_push($columnNames, 'Column ' . $i);
}
}
$metaData = array("columns" => array());
for ($i = 0; $i < count($columnNames); $i++) {
$metaData["columns"][$columnNames[$i]] = array(
"type" => (isset($row))
?$this->guessType($row[$i]) : "unknown"
);
}
$this->sendMeta($metaData, $this);
$this->startInput(null);
if ($this->firstRowData) {
$this->next(array_combine($columnNames, $row), $this);
}
}
while (($row = fgetcsv($handle, 0, $this->fieldSeparator)) !== false) {
$row = array_map(
function ($item) {
return ($this->charset=="utf8" && is_string($item))
?utf8_encode($item):$item;
},
$row
);
$this->next(array_combine($columnNames, $row), $this);
}
} else {
throw new \Exception('Failed to open ' . $this->filePath);
}
$this->endInput(null);
} | php | public function start()
{
// $offset = 0;
// //Go to where we were when we ended the last batch
// fseek($fileHandle, $offset);
// fgetcsv($fileHandle)
// $offset = ftell($fileHandle);
$data = array();
if (($handle = fopen($this->filePath, "r")) !== false) {
$row = fgetcsv($handle, 0, $this->fieldSeparator);
//Convert to UTF8 if assign charset to utf8
$row = array_map(
function ($item) {
return ($this->charset=="utf8" && is_string($item))
?utf8_encode($item):$item;
},
$row
);
if (is_array($row)) {
if (!$this->firstRowData) {
$columnNames = $row;
} else {
$columnNames = array();
for ($i = 0; $i < count($row); $i++) {
array_push($columnNames, 'Column ' . $i);
}
}
$metaData = array("columns" => array());
for ($i = 0; $i < count($columnNames); $i++) {
$metaData["columns"][$columnNames[$i]] = array(
"type" => (isset($row))
?$this->guessType($row[$i]) : "unknown"
);
}
$this->sendMeta($metaData, $this);
$this->startInput(null);
if ($this->firstRowData) {
$this->next(array_combine($columnNames, $row), $this);
}
}
while (($row = fgetcsv($handle, 0, $this->fieldSeparator)) !== false) {
$row = array_map(
function ($item) {
return ($this->charset=="utf8" && is_string($item))
?utf8_encode($item):$item;
},
$row
);
$this->next(array_combine($columnNames, $row), $this);
}
} else {
throw new \Exception('Failed to open ' . $this->filePath);
}
$this->endInput(null);
} | [
"public",
"function",
"start",
"(",
")",
"{",
"// $offset = 0;",
"// //Go to where we were when we ended the last batch",
"// fseek($fileHandle, $offset);",
"// fgetcsv($fileHandle)",
"// $offset = ftell($fileHandle);",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"(",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"filePath",
",",
"\"r\"",
")",
")",
"!==",
"false",
")",
"{",
"$",
"row",
"=",
"fgetcsv",
"(",
"$",
"handle",
",",
"0",
",",
"$",
"this",
"->",
"fieldSeparator",
")",
";",
"//Convert to UTF8 if assign charset to utf8",
"$",
"row",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"charset",
"==",
"\"utf8\"",
"&&",
"is_string",
"(",
"$",
"item",
")",
")",
"?",
"utf8_encode",
"(",
"$",
"item",
")",
":",
"$",
"item",
";",
"}",
",",
"$",
"row",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"row",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"firstRowData",
")",
"{",
"$",
"columnNames",
"=",
"$",
"row",
";",
"}",
"else",
"{",
"$",
"columnNames",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"row",
")",
";",
"$",
"i",
"++",
")",
"{",
"array_push",
"(",
"$",
"columnNames",
",",
"'Column '",
".",
"$",
"i",
")",
";",
"}",
"}",
"$",
"metaData",
"=",
"array",
"(",
"\"columns\"",
"=>",
"array",
"(",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"columnNames",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"columnNames",
"[",
"$",
"i",
"]",
"]",
"=",
"array",
"(",
"\"type\"",
"=>",
"(",
"isset",
"(",
"$",
"row",
")",
")",
"?",
"$",
"this",
"->",
"guessType",
"(",
"$",
"row",
"[",
"$",
"i",
"]",
")",
":",
"\"unknown\"",
")",
";",
"}",
"$",
"this",
"->",
"sendMeta",
"(",
"$",
"metaData",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"startInput",
"(",
"null",
")",
";",
"if",
"(",
"$",
"this",
"->",
"firstRowData",
")",
"{",
"$",
"this",
"->",
"next",
"(",
"array_combine",
"(",
"$",
"columnNames",
",",
"$",
"row",
")",
",",
"$",
"this",
")",
";",
"}",
"}",
"while",
"(",
"(",
"$",
"row",
"=",
"fgetcsv",
"(",
"$",
"handle",
",",
"0",
",",
"$",
"this",
"->",
"fieldSeparator",
")",
")",
"!==",
"false",
")",
"{",
"$",
"row",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"charset",
"==",
"\"utf8\"",
"&&",
"is_string",
"(",
"$",
"item",
")",
")",
"?",
"utf8_encode",
"(",
"$",
"item",
")",
":",
"$",
"item",
";",
"}",
",",
"$",
"row",
")",
";",
"$",
"this",
"->",
"next",
"(",
"array_combine",
"(",
"$",
"columnNames",
",",
"$",
"row",
")",
",",
"$",
"this",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Failed to open '",
".",
"$",
"this",
"->",
"filePath",
")",
";",
"}",
"$",
"this",
"->",
"endInput",
"(",
"null",
")",
";",
"}"
] | Start piping data
@return null | [
"Start",
"piping",
"data"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/CSVDataSource.php#L121-L180 |
koolphp/koolreport | src/clients/jQuery.php | jQuery.__constructjQuery | public function __constructjQuery()
{
$this->registerEvent(
'OnResourceInit',
function () {
$publicAssetUrl = $this->getResourceManager()
->publishAssetFolder(realpath(dirname(__FILE__))."/jquery");
$this->getResourceManager()
->addScriptFileOnBegin($publicAssetUrl."/jquery.min.js");
}
);
} | php | public function __constructjQuery()
{
$this->registerEvent(
'OnResourceInit',
function () {
$publicAssetUrl = $this->getResourceManager()
->publishAssetFolder(realpath(dirname(__FILE__))."/jquery");
$this->getResourceManager()
->addScriptFileOnBegin($publicAssetUrl."/jquery.min.js");
}
);
} | [
"public",
"function",
"__constructjQuery",
"(",
")",
"{",
"$",
"this",
"->",
"registerEvent",
"(",
"'OnResourceInit'",
",",
"function",
"(",
")",
"{",
"$",
"publicAssetUrl",
"=",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"publishAssetFolder",
"(",
"realpath",
"(",
"dirname",
"(",
"__FILE__",
")",
")",
".",
"\"/jquery\"",
")",
";",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"addScriptFileOnBegin",
"(",
"$",
"publicAssetUrl",
".",
"\"/jquery.min.js\"",
")",
";",
"}",
")",
";",
"}"
] | Service construction | [
"Service",
"construction"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/clients/jQuery.php#L31-L42 |
koolphp/koolreport | src/datasources/MySQLDataSource.php | MySQLDataSource.onInit | protected function onInit()
{
$host = Util::get($this->params, "host", "");
$username = Util::get($this->params, "username", "");
$password = Util::get($this->params, "password", "");
$dbname = Util::get($this->params, "dbname", "");
$charset = Util::get($this->params, "charset", null);
$key = md5($host.$username.$password.$dbname);
if (isset(MySQLDataSource::$connections[$key])) {
$this->connection = MySQLDataSource::$connections[$key];
} else {
$this->connection = new \mysqli($host, $username, $password, $dbname);
/* check connection */
if ($this->connection->connect_errno) {
throw new \Exception(
"Failed to connect to MySQL: ("
.$this->connection->connect_errno
.") "
.$this->connection->connect_error
);
}
MySQLDataSource::$connections[$key] = $this->connection;
}
/* change character set */
if (isset($charset) && ! $this->connection->set_charset($charset)) {
throw new \Exception(
"Error loading character set $charset: "
.$this->connection->error
);
}
} | php | protected function onInit()
{
$host = Util::get($this->params, "host", "");
$username = Util::get($this->params, "username", "");
$password = Util::get($this->params, "password", "");
$dbname = Util::get($this->params, "dbname", "");
$charset = Util::get($this->params, "charset", null);
$key = md5($host.$username.$password.$dbname);
if (isset(MySQLDataSource::$connections[$key])) {
$this->connection = MySQLDataSource::$connections[$key];
} else {
$this->connection = new \mysqli($host, $username, $password, $dbname);
/* check connection */
if ($this->connection->connect_errno) {
throw new \Exception(
"Failed to connect to MySQL: ("
.$this->connection->connect_errno
.") "
.$this->connection->connect_error
);
}
MySQLDataSource::$connections[$key] = $this->connection;
}
/* change character set */
if (isset($charset) && ! $this->connection->set_charset($charset)) {
throw new \Exception(
"Error loading character set $charset: "
.$this->connection->error
);
}
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"$",
"host",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"host\"",
",",
"\"\"",
")",
";",
"$",
"username",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"username\"",
",",
"\"\"",
")",
";",
"$",
"password",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"password\"",
",",
"\"\"",
")",
";",
"$",
"dbname",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"dbname\"",
",",
"\"\"",
")",
";",
"$",
"charset",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"charset\"",
",",
"null",
")",
";",
"$",
"key",
"=",
"md5",
"(",
"$",
"host",
".",
"$",
"username",
".",
"$",
"password",
".",
"$",
"dbname",
")",
";",
"if",
"(",
"isset",
"(",
"MySQLDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"MySQLDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"connection",
"=",
"new",
"\\",
"mysqli",
"(",
"$",
"host",
",",
"$",
"username",
",",
"$",
"password",
",",
"$",
"dbname",
")",
";",
"/* check connection */",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"connect_errno",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Failed to connect to MySQL: (\"",
".",
"$",
"this",
"->",
"connection",
"->",
"connect_errno",
".",
"\") \"",
".",
"$",
"this",
"->",
"connection",
"->",
"connect_error",
")",
";",
"}",
"MySQLDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"connection",
";",
"}",
"/* change character set */",
"if",
"(",
"isset",
"(",
"$",
"charset",
")",
"&&",
"!",
"$",
"this",
"->",
"connection",
"->",
"set_charset",
"(",
"$",
"charset",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error loading character set $charset: \"",
".",
"$",
"this",
"->",
"connection",
"->",
"error",
")",
";",
"}",
"}"
] | Init MySQLdataSource
@return null | [
"Init",
"MySQLdataSource"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/MySQLDataSource.php#L87-L119 |
koolphp/koolreport | src/datasources/MySQLDataSource.php | MySQLDataSource.mapFieldTypeToBindType | function mapFieldTypeToBindType($field_type)
{
switch ($field_type) {
case MYSQLI_TYPE_DECIMAL:
case MYSQLI_TYPE_NEWDECIMAL:
case MYSQLI_TYPE_FLOAT:
case MYSQLI_TYPE_DOUBLE:
case MYSQLI_TYPE_BIT:
case MYSQLI_TYPE_TINY:
case MYSQLI_TYPE_SHORT:
case MYSQLI_TYPE_LONG:
case MYSQLI_TYPE_LONGLONG:
case MYSQLI_TYPE_INT24:
case MYSQLI_TYPE_YEAR:
case MYSQLI_TYPE_ENUM:
return 'number';
case MYSQLI_TYPE_DATE:
return 'date';
case MYSQLI_TYPE_TIME:
return 'time';
case MYSQLI_TYPE_TIMESTAMP:
case MYSQLI_TYPE_DATETIME:
case MYSQLI_TYPE_NEWDATE:
return 'datetime';
case MYSQLI_TYPE_VAR_STRING:
case MYSQLI_TYPE_STRING:
case MYSQLI_TYPE_CHAR:
case MYSQLI_TYPE_GEOMETRY:
case MYSQLI_TYPE_TINY_BLOB:
case MYSQLI_TYPE_MEDIUM_BLOB:
case MYSQLI_TYPE_LONG_BLOB:
case MYSQLI_TYPE_BLOB:
return 'string';
default:
return 'unknown';
}
} | php | function mapFieldTypeToBindType($field_type)
{
switch ($field_type) {
case MYSQLI_TYPE_DECIMAL:
case MYSQLI_TYPE_NEWDECIMAL:
case MYSQLI_TYPE_FLOAT:
case MYSQLI_TYPE_DOUBLE:
case MYSQLI_TYPE_BIT:
case MYSQLI_TYPE_TINY:
case MYSQLI_TYPE_SHORT:
case MYSQLI_TYPE_LONG:
case MYSQLI_TYPE_LONGLONG:
case MYSQLI_TYPE_INT24:
case MYSQLI_TYPE_YEAR:
case MYSQLI_TYPE_ENUM:
return 'number';
case MYSQLI_TYPE_DATE:
return 'date';
case MYSQLI_TYPE_TIME:
return 'time';
case MYSQLI_TYPE_TIMESTAMP:
case MYSQLI_TYPE_DATETIME:
case MYSQLI_TYPE_NEWDATE:
return 'datetime';
case MYSQLI_TYPE_VAR_STRING:
case MYSQLI_TYPE_STRING:
case MYSQLI_TYPE_CHAR:
case MYSQLI_TYPE_GEOMETRY:
case MYSQLI_TYPE_TINY_BLOB:
case MYSQLI_TYPE_MEDIUM_BLOB:
case MYSQLI_TYPE_LONG_BLOB:
case MYSQLI_TYPE_BLOB:
return 'string';
default:
return 'unknown';
}
} | [
"function",
"mapFieldTypeToBindType",
"(",
"$",
"field_type",
")",
"{",
"switch",
"(",
"$",
"field_type",
")",
"{",
"case",
"MYSQLI_TYPE_DECIMAL",
":",
"case",
"MYSQLI_TYPE_NEWDECIMAL",
":",
"case",
"MYSQLI_TYPE_FLOAT",
":",
"case",
"MYSQLI_TYPE_DOUBLE",
":",
"case",
"MYSQLI_TYPE_BIT",
":",
"case",
"MYSQLI_TYPE_TINY",
":",
"case",
"MYSQLI_TYPE_SHORT",
":",
"case",
"MYSQLI_TYPE_LONG",
":",
"case",
"MYSQLI_TYPE_LONGLONG",
":",
"case",
"MYSQLI_TYPE_INT24",
":",
"case",
"MYSQLI_TYPE_YEAR",
":",
"case",
"MYSQLI_TYPE_ENUM",
":",
"return",
"'number'",
";",
"case",
"MYSQLI_TYPE_DATE",
":",
"return",
"'date'",
";",
"case",
"MYSQLI_TYPE_TIME",
":",
"return",
"'time'",
";",
"case",
"MYSQLI_TYPE_TIMESTAMP",
":",
"case",
"MYSQLI_TYPE_DATETIME",
":",
"case",
"MYSQLI_TYPE_NEWDATE",
":",
"return",
"'datetime'",
";",
"case",
"MYSQLI_TYPE_VAR_STRING",
":",
"case",
"MYSQLI_TYPE_STRING",
":",
"case",
"MYSQLI_TYPE_CHAR",
":",
"case",
"MYSQLI_TYPE_GEOMETRY",
":",
"case",
"MYSQLI_TYPE_TINY_BLOB",
":",
"case",
"MYSQLI_TYPE_MEDIUM_BLOB",
":",
"case",
"MYSQLI_TYPE_LONG_BLOB",
":",
"case",
"MYSQLI_TYPE_BLOB",
":",
"return",
"'string'",
";",
"default",
":",
"return",
"'unknown'",
";",
"}",
"}"
] | Map field type to bind type
@param strng $field_type The type of field
@return string KoolReport type of field | [
"Map",
"field",
"type",
"to",
"bind",
"type"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/MySQLDataSource.php#L271-L311 |
koolphp/koolreport | src/datasources/MySQLDataSource.php | MySQLDataSource.start | public function start()
{
$metaData = array("columns"=>array());
if ($this->countTotal) {
$totalQuery = $this->bindParams($this->totalQuery, $this->sqlParams);
$totalResult = $this->connection->query($totalQuery);
if ($totalResult===false) {
throw new \Exception("Error on query >>> ".$this->connection->error);
}
$row = $totalResult->fetch_array();
$result = $row[0];
$metaData['totalRecords'] = $result;
}
if ($this->countFilter) {
$filterQuery = $this->bindParams($this->filterQuery, $this->sqlParams);
$filterResult = $this->connection->query($filterQuery);
if ($filterResult===false) {
throw new \Exception("Error on query >>> ".$this->connection->error);
}
$row = $filterResult->fetch_array();
$result = $row[0];
$metaData['filterRecords'] = $result;
}
$query = $this->bindParams($this->query, $this->sqlParams);
$result = $this->connection->query($query);
if ($result===false) {
throw new \Exception("Error on query >>> ".$this->connection->error);
}
$finfo = $result->fetch_fields();
$numcols = count($finfo);
for ($i=0; $i<$numcols; $i++) {
$type = $this->mapFieldTypeToBindType($finfo[$i]->type);
$metaData["columns"][$finfo[$i]->name] = array(
"type"=>$type,
);
switch($type)
{
case "datetime":
$metaData["columns"][$finfo[$i]->name]["format"] = "Y-m-d H:i:s";
break;
case "date":
$metaData["columns"][$finfo[$i]->name]["format"] = "Y-m-d";
break;
case "time":
$metaData["columns"][$finfo[$i]->name]["format"] = "H:i:s";
break;
}
}
$this->sendMeta($metaData, $this);
$this->startInput(null);
while ($row = $result->fetch_assoc()) {
$this->next($row, $this);
}
$this->endInput(null);
} | php | public function start()
{
$metaData = array("columns"=>array());
if ($this->countTotal) {
$totalQuery = $this->bindParams($this->totalQuery, $this->sqlParams);
$totalResult = $this->connection->query($totalQuery);
if ($totalResult===false) {
throw new \Exception("Error on query >>> ".$this->connection->error);
}
$row = $totalResult->fetch_array();
$result = $row[0];
$metaData['totalRecords'] = $result;
}
if ($this->countFilter) {
$filterQuery = $this->bindParams($this->filterQuery, $this->sqlParams);
$filterResult = $this->connection->query($filterQuery);
if ($filterResult===false) {
throw new \Exception("Error on query >>> ".$this->connection->error);
}
$row = $filterResult->fetch_array();
$result = $row[0];
$metaData['filterRecords'] = $result;
}
$query = $this->bindParams($this->query, $this->sqlParams);
$result = $this->connection->query($query);
if ($result===false) {
throw new \Exception("Error on query >>> ".$this->connection->error);
}
$finfo = $result->fetch_fields();
$numcols = count($finfo);
for ($i=0; $i<$numcols; $i++) {
$type = $this->mapFieldTypeToBindType($finfo[$i]->type);
$metaData["columns"][$finfo[$i]->name] = array(
"type"=>$type,
);
switch($type)
{
case "datetime":
$metaData["columns"][$finfo[$i]->name]["format"] = "Y-m-d H:i:s";
break;
case "date":
$metaData["columns"][$finfo[$i]->name]["format"] = "Y-m-d";
break;
case "time":
$metaData["columns"][$finfo[$i]->name]["format"] = "H:i:s";
break;
}
}
$this->sendMeta($metaData, $this);
$this->startInput(null);
while ($row = $result->fetch_assoc()) {
$this->next($row, $this);
}
$this->endInput(null);
} | [
"public",
"function",
"start",
"(",
")",
"{",
"$",
"metaData",
"=",
"array",
"(",
"\"columns\"",
"=>",
"array",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"countTotal",
")",
"{",
"$",
"totalQuery",
"=",
"$",
"this",
"->",
"bindParams",
"(",
"$",
"this",
"->",
"totalQuery",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"totalResult",
"=",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"$",
"totalQuery",
")",
";",
"if",
"(",
"$",
"totalResult",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error on query >>> \"",
".",
"$",
"this",
"->",
"connection",
"->",
"error",
")",
";",
"}",
"$",
"row",
"=",
"$",
"totalResult",
"->",
"fetch_array",
"(",
")",
";",
"$",
"result",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"$",
"metaData",
"[",
"'totalRecords'",
"]",
"=",
"$",
"result",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"countFilter",
")",
"{",
"$",
"filterQuery",
"=",
"$",
"this",
"->",
"bindParams",
"(",
"$",
"this",
"->",
"filterQuery",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"filterResult",
"=",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"$",
"filterQuery",
")",
";",
"if",
"(",
"$",
"filterResult",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error on query >>> \"",
".",
"$",
"this",
"->",
"connection",
"->",
"error",
")",
";",
"}",
"$",
"row",
"=",
"$",
"filterResult",
"->",
"fetch_array",
"(",
")",
";",
"$",
"result",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"$",
"metaData",
"[",
"'filterRecords'",
"]",
"=",
"$",
"result",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"bindParams",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error on query >>> \"",
".",
"$",
"this",
"->",
"connection",
"->",
"error",
")",
";",
"}",
"$",
"finfo",
"=",
"$",
"result",
"->",
"fetch_fields",
"(",
")",
";",
"$",
"numcols",
"=",
"count",
"(",
"$",
"finfo",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"numcols",
";",
"$",
"i",
"++",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"mapFieldTypeToBindType",
"(",
"$",
"finfo",
"[",
"$",
"i",
"]",
"->",
"type",
")",
";",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"finfo",
"[",
"$",
"i",
"]",
"->",
"name",
"]",
"=",
"array",
"(",
"\"type\"",
"=>",
"$",
"type",
",",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"\"datetime\"",
":",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"finfo",
"[",
"$",
"i",
"]",
"->",
"name",
"]",
"[",
"\"format\"",
"]",
"=",
"\"Y-m-d H:i:s\"",
";",
"break",
";",
"case",
"\"date\"",
":",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"finfo",
"[",
"$",
"i",
"]",
"->",
"name",
"]",
"[",
"\"format\"",
"]",
"=",
"\"Y-m-d\"",
";",
"break",
";",
"case",
"\"time\"",
":",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"finfo",
"[",
"$",
"i",
"]",
"->",
"name",
"]",
"[",
"\"format\"",
"]",
"=",
"\"H:i:s\"",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"sendMeta",
"(",
"$",
"metaData",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"startInput",
"(",
"null",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"$",
"this",
"->",
"next",
"(",
"$",
"row",
",",
"$",
"this",
")",
";",
"}",
"$",
"this",
"->",
"endInput",
"(",
"null",
")",
";",
"}"
] | Start piping data
@return null | [
"Start",
"piping",
"data"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/MySQLDataSource.php#L318-L383 |
koolphp/koolreport | src/processes/TimeBucket.php | TimeBucket.onInit | protected function onInit()
{
foreach ($this->params as $cName => $cParams) {
if (gettype($cParams) == "array") {
$bucket = Utility::get($cParams, "bucket");
$formatString = Utility::get($cParams, "formatString");
$this->params[$cName] = array(
"bucket" => $bucket,
"formatString" => $formatString ? $formatString : $this->defaultFormatString($bucket),
);
} else {
//cParams now is bucket
$this->params[$cName] = array(
"bucket" => $cParams,
"formatString" => $this->defaultFormatString($cParams),
);
}
}
} | php | protected function onInit()
{
foreach ($this->params as $cName => $cParams) {
if (gettype($cParams) == "array") {
$bucket = Utility::get($cParams, "bucket");
$formatString = Utility::get($cParams, "formatString");
$this->params[$cName] = array(
"bucket" => $bucket,
"formatString" => $formatString ? $formatString : $this->defaultFormatString($bucket),
);
} else {
//cParams now is bucket
$this->params[$cName] = array(
"bucket" => $cParams,
"formatString" => $this->defaultFormatString($cParams),
);
}
}
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"cName",
"=>",
"$",
"cParams",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"cParams",
")",
"==",
"\"array\"",
")",
"{",
"$",
"bucket",
"=",
"Utility",
"::",
"get",
"(",
"$",
"cParams",
",",
"\"bucket\"",
")",
";",
"$",
"formatString",
"=",
"Utility",
"::",
"get",
"(",
"$",
"cParams",
",",
"\"formatString\"",
")",
";",
"$",
"this",
"->",
"params",
"[",
"$",
"cName",
"]",
"=",
"array",
"(",
"\"bucket\"",
"=>",
"$",
"bucket",
",",
"\"formatString\"",
"=>",
"$",
"formatString",
"?",
"$",
"formatString",
":",
"$",
"this",
"->",
"defaultFormatString",
"(",
"$",
"bucket",
")",
",",
")",
";",
"}",
"else",
"{",
"//cParams now is bucket",
"$",
"this",
"->",
"params",
"[",
"$",
"cName",
"]",
"=",
"array",
"(",
"\"bucket\"",
"=>",
"$",
"cParams",
",",
"\"formatString\"",
"=>",
"$",
"this",
"->",
"defaultFormatString",
"(",
"$",
"cParams",
")",
",",
")",
";",
"}",
"}",
"}"
] | Handle on initiation
@return null | [
"Handle",
"on",
"initiation"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/TimeBucket.php#L59-L78 |
koolphp/koolreport | src/processes/TimeBucket.php | TimeBucket.onInput | protected function onInput($data)
{
//Process data here
foreach ($this->params as $cName => $cParams) {
if ($data[$cName]) {
//Only if the value of column is not empty
$format = Utility::get($this->metaData["columns"][$cName], "format");
$datetime = ($format) ? \DateTime::createFromFormat($format, $data[$cName]) : new \DateTime($data[$cName]);
$data[$cName] = $datetime->format($cParams["formatString"]);
if ($cParams["bucket"] == "quarter") {
$data[$cName] = Utility::strReplace(
$data[$cName],
array(
"{q}" => ceil(intval($datetime->format("n")) / 3),
)
);
}
}
}
$this->next($data);
} | php | protected function onInput($data)
{
//Process data here
foreach ($this->params as $cName => $cParams) {
if ($data[$cName]) {
//Only if the value of column is not empty
$format = Utility::get($this->metaData["columns"][$cName], "format");
$datetime = ($format) ? \DateTime::createFromFormat($format, $data[$cName]) : new \DateTime($data[$cName]);
$data[$cName] = $datetime->format($cParams["formatString"]);
if ($cParams["bucket"] == "quarter") {
$data[$cName] = Utility::strReplace(
$data[$cName],
array(
"{q}" => ceil(intval($datetime->format("n")) / 3),
)
);
}
}
}
$this->next($data);
} | [
"protected",
"function",
"onInput",
"(",
"$",
"data",
")",
"{",
"//Process data here",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"cName",
"=>",
"$",
"cParams",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"$",
"cName",
"]",
")",
"{",
"//Only if the value of column is not empty",
"$",
"format",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"cName",
"]",
",",
"\"format\"",
")",
";",
"$",
"datetime",
"=",
"(",
"$",
"format",
")",
"?",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"data",
"[",
"$",
"cName",
"]",
")",
":",
"new",
"\\",
"DateTime",
"(",
"$",
"data",
"[",
"$",
"cName",
"]",
")",
";",
"$",
"data",
"[",
"$",
"cName",
"]",
"=",
"$",
"datetime",
"->",
"format",
"(",
"$",
"cParams",
"[",
"\"formatString\"",
"]",
")",
";",
"if",
"(",
"$",
"cParams",
"[",
"\"bucket\"",
"]",
"==",
"\"quarter\"",
")",
"{",
"$",
"data",
"[",
"$",
"cName",
"]",
"=",
"Utility",
"::",
"strReplace",
"(",
"$",
"data",
"[",
"$",
"cName",
"]",
",",
"array",
"(",
"\"{q}\"",
"=>",
"ceil",
"(",
"intval",
"(",
"$",
"datetime",
"->",
"format",
"(",
"\"n\"",
")",
")",
"/",
"3",
")",
",",
")",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"next",
"(",
"$",
"data",
")",
";",
"}"
] | Handle on data input
@param array $data The input data row
@return null | [
"Handle",
"on",
"data",
"input"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/TimeBucket.php#L127-L149 |
koolphp/koolreport | src/datasources/ReportDataSource.php | ReportDataSource.onInit | protected function onInit()
{
$key = Utility::get($this->params, "key", "");
$reportSource = Utility::get($this->params, "report");
$reportParams = Utility::get($this->params, "params", array());
if ($reportSource==null) {
throw new \Exception("ReportDataSource require 'source' parameter which is the classname of source report");
}
if (ReportDataSource::$reports==null) {
ReportDataSource::$reports = array();
}
if (isset(ReportDataSource::$reports[$reportSource.$key])) {
$this->report = ReportDataSource::$reports[$reportSource.$key];
} else {
try
{
$this->report = new $reportSource($reportParams);
}
catch(\Exception $e)
{
throw new \Exception("Could not create report '$reportSource'");
}
ReportDataSource::$reports[$reportSource.$key]=$this->report;
$this->report->run();
}
} | php | protected function onInit()
{
$key = Utility::get($this->params, "key", "");
$reportSource = Utility::get($this->params, "report");
$reportParams = Utility::get($this->params, "params", array());
if ($reportSource==null) {
throw new \Exception("ReportDataSource require 'source' parameter which is the classname of source report");
}
if (ReportDataSource::$reports==null) {
ReportDataSource::$reports = array();
}
if (isset(ReportDataSource::$reports[$reportSource.$key])) {
$this->report = ReportDataSource::$reports[$reportSource.$key];
} else {
try
{
$this->report = new $reportSource($reportParams);
}
catch(\Exception $e)
{
throw new \Exception("Could not create report '$reportSource'");
}
ReportDataSource::$reports[$reportSource.$key]=$this->report;
$this->report->run();
}
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"$",
"key",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"key\"",
",",
"\"\"",
")",
";",
"$",
"reportSource",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"report\"",
")",
";",
"$",
"reportParams",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"params\"",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"$",
"reportSource",
"==",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"ReportDataSource require 'source' parameter which is the classname of source report\"",
")",
";",
"}",
"if",
"(",
"ReportDataSource",
"::",
"$",
"reports",
"==",
"null",
")",
"{",
"ReportDataSource",
"::",
"$",
"reports",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"ReportDataSource",
"::",
"$",
"reports",
"[",
"$",
"reportSource",
".",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"report",
"=",
"ReportDataSource",
"::",
"$",
"reports",
"[",
"$",
"reportSource",
".",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"try",
"{",
"$",
"this",
"->",
"report",
"=",
"new",
"$",
"reportSource",
"(",
"$",
"reportParams",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not create report '$reportSource'\"",
")",
";",
"}",
"ReportDataSource",
"::",
"$",
"reports",
"[",
"$",
"reportSource",
".",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"report",
";",
"$",
"this",
"->",
"report",
"->",
"run",
"(",
")",
";",
"}",
"}"
] | Datasource initiation
@return null | [
"Datasource",
"initiation"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/ReportDataSource.php#L55-L84 |
koolphp/koolreport | src/datasources/ReportDataSource.php | ReportDataSource.start | public function start()
{
$this->sendMeta($this->report->dataStore($this->storeName)->meta());
$this->startInput(null);
$this->report->dataStore($this->storeName)->popStart();
while ($row = $this->report->dataStore($this->storeName)->pop()) {
$this->next($row, $this);
}
$this->endInput(null);
} | php | public function start()
{
$this->sendMeta($this->report->dataStore($this->storeName)->meta());
$this->startInput(null);
$this->report->dataStore($this->storeName)->popStart();
while ($row = $this->report->dataStore($this->storeName)->pop()) {
$this->next($row, $this);
}
$this->endInput(null);
} | [
"public",
"function",
"start",
"(",
")",
"{",
"$",
"this",
"->",
"sendMeta",
"(",
"$",
"this",
"->",
"report",
"->",
"dataStore",
"(",
"$",
"this",
"->",
"storeName",
")",
"->",
"meta",
"(",
")",
")",
";",
"$",
"this",
"->",
"startInput",
"(",
"null",
")",
";",
"$",
"this",
"->",
"report",
"->",
"dataStore",
"(",
"$",
"this",
"->",
"storeName",
")",
"->",
"popStart",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"this",
"->",
"report",
"->",
"dataStore",
"(",
"$",
"this",
"->",
"storeName",
")",
"->",
"pop",
"(",
")",
")",
"{",
"$",
"this",
"->",
"next",
"(",
"$",
"row",
",",
"$",
"this",
")",
";",
"}",
"$",
"this",
"->",
"endInput",
"(",
"null",
")",
";",
"}"
] | Start piping data
@return null | [
"Start",
"piping",
"data"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/ReportDataSource.php#L104-L113 |
deployphp/phar-update | src/Exception/Exception.php | Exception.create | public static function create($format, $value = null)
{
if (0 < func_num_args()) {
$format = vsprintf($format, array_slice(func_get_args(), 1));
}
return new static($format);
} | php | public static function create($format, $value = null)
{
if (0 < func_num_args()) {
$format = vsprintf($format, array_slice(func_get_args(), 1));
}
return new static($format);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"format",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"0",
"<",
"func_num_args",
"(",
")",
")",
"{",
"$",
"format",
"=",
"vsprintf",
"(",
"$",
"format",
",",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"1",
")",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"format",
")",
";",
"}"
] | Creates a new exception using a format and values.
@param string $format The format.
@param mixed $value,... The value(s).
@return Exception The exception. | [
"Creates",
"a",
"new",
"exception",
"using",
"a",
"format",
"and",
"values",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Exception/Exception.php#L20-L27 |
deployphp/phar-update | src/Version/Dumper.php | Dumper.toComponents | public static function toComponents(Version $version)
{
return array(
Parser::MAJOR => $version->getMajor(),
Parser::MINOR => $version->getMinor(),
Parser::PATCH => $version->getPatch(),
Parser::PRE_RELEASE => $version->getPreRelease(),
Parser::BUILD => $version->getBuild()
);
} | php | public static function toComponents(Version $version)
{
return array(
Parser::MAJOR => $version->getMajor(),
Parser::MINOR => $version->getMinor(),
Parser::PATCH => $version->getPatch(),
Parser::PRE_RELEASE => $version->getPreRelease(),
Parser::BUILD => $version->getBuild()
);
} | [
"public",
"static",
"function",
"toComponents",
"(",
"Version",
"$",
"version",
")",
"{",
"return",
"array",
"(",
"Parser",
"::",
"MAJOR",
"=>",
"$",
"version",
"->",
"getMajor",
"(",
")",
",",
"Parser",
"::",
"MINOR",
"=>",
"$",
"version",
"->",
"getMinor",
"(",
")",
",",
"Parser",
"::",
"PATCH",
"=>",
"$",
"version",
"->",
"getPatch",
"(",
")",
",",
"Parser",
"::",
"PRE_RELEASE",
"=>",
"$",
"version",
"->",
"getPreRelease",
"(",
")",
",",
"Parser",
"::",
"BUILD",
"=>",
"$",
"version",
"->",
"getBuild",
"(",
")",
")",
";",
"}"
] | Returns the components of a Version instance.
@param Version $version A version.
@return array The components. | [
"Returns",
"the",
"components",
"of",
"a",
"Version",
"instance",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Dumper.php#L19-L28 |
deployphp/phar-update | src/Version/Dumper.php | Dumper.toString | public static function toString(Version $version)
{
return sprintf(
'%d.%d.%d%s%s',
$version->getMajor(),
$version->getMinor(),
$version->getPatch(),
$version->getPreRelease()
? '-' . join('.', $version->getPreRelease())
: '',
$version->getBuild()
? '+' . join('.', $version->getBuild())
: ''
);
} | php | public static function toString(Version $version)
{
return sprintf(
'%d.%d.%d%s%s',
$version->getMajor(),
$version->getMinor(),
$version->getPatch(),
$version->getPreRelease()
? '-' . join('.', $version->getPreRelease())
: '',
$version->getBuild()
? '+' . join('.', $version->getBuild())
: ''
);
} | [
"public",
"static",
"function",
"toString",
"(",
"Version",
"$",
"version",
")",
"{",
"return",
"sprintf",
"(",
"'%d.%d.%d%s%s'",
",",
"$",
"version",
"->",
"getMajor",
"(",
")",
",",
"$",
"version",
"->",
"getMinor",
"(",
")",
",",
"$",
"version",
"->",
"getPatch",
"(",
")",
",",
"$",
"version",
"->",
"getPreRelease",
"(",
")",
"?",
"'-'",
".",
"join",
"(",
"'.'",
",",
"$",
"version",
"->",
"getPreRelease",
"(",
")",
")",
":",
"''",
",",
"$",
"version",
"->",
"getBuild",
"(",
")",
"?",
"'+'",
".",
"join",
"(",
"'.'",
",",
"$",
"version",
"->",
"getBuild",
"(",
")",
")",
":",
"''",
")",
";",
"}"
] | Returns the string representation of a Version instance.
@param Version $version A version.
@return string The string representation. | [
"Returns",
"the",
"string",
"representation",
"of",
"a",
"Version",
"instance",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Dumper.php#L37-L51 |
deployphp/phar-update | src/Version/Comparator.php | Comparator.compareTo | public static function compareTo(Version $left, Version $right)
{
switch (true) {
case ($left->getMajor() < $right->getMajor()):
return self::LESS_THAN;
case ($left->getMajor() > $right->getMajor()):
return self::GREATER_THAN;
case ($left->getMinor() > $right->getMinor()):
return self::GREATER_THAN;
case ($left->getMinor() < $right->getMinor()):
return self::LESS_THAN;
case ($left->getPatch() > $right->getPatch()):
return self::GREATER_THAN;
case ($left->getPatch() < $right->getPatch()):
return self::LESS_THAN;
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
return self::compareIdentifiers(
$left->getPreRelease(),
$right->getPreRelease()
);
} | php | public static function compareTo(Version $left, Version $right)
{
switch (true) {
case ($left->getMajor() < $right->getMajor()):
return self::LESS_THAN;
case ($left->getMajor() > $right->getMajor()):
return self::GREATER_THAN;
case ($left->getMinor() > $right->getMinor()):
return self::GREATER_THAN;
case ($left->getMinor() < $right->getMinor()):
return self::LESS_THAN;
case ($left->getPatch() > $right->getPatch()):
return self::GREATER_THAN;
case ($left->getPatch() < $right->getPatch()):
return self::LESS_THAN;
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
return self::compareIdentifiers(
$left->getPreRelease(),
$right->getPreRelease()
);
} | [
"public",
"static",
"function",
"compareTo",
"(",
"Version",
"$",
"left",
",",
"Version",
"$",
"right",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"$",
"left",
"->",
"getMajor",
"(",
")",
"<",
"$",
"right",
"->",
"getMajor",
"(",
")",
")",
":",
"return",
"self",
"::",
"LESS_THAN",
";",
"case",
"(",
"$",
"left",
"->",
"getMajor",
"(",
")",
">",
"$",
"right",
"->",
"getMajor",
"(",
")",
")",
":",
"return",
"self",
"::",
"GREATER_THAN",
";",
"case",
"(",
"$",
"left",
"->",
"getMinor",
"(",
")",
">",
"$",
"right",
"->",
"getMinor",
"(",
")",
")",
":",
"return",
"self",
"::",
"GREATER_THAN",
";",
"case",
"(",
"$",
"left",
"->",
"getMinor",
"(",
")",
"<",
"$",
"right",
"->",
"getMinor",
"(",
")",
")",
":",
"return",
"self",
"::",
"LESS_THAN",
";",
"case",
"(",
"$",
"left",
"->",
"getPatch",
"(",
")",
">",
"$",
"right",
"->",
"getPatch",
"(",
")",
")",
":",
"return",
"self",
"::",
"GREATER_THAN",
";",
"case",
"(",
"$",
"left",
"->",
"getPatch",
"(",
")",
"<",
"$",
"right",
"->",
"getPatch",
"(",
")",
")",
":",
"return",
"self",
"::",
"LESS_THAN",
";",
"// @codeCoverageIgnoreStart",
"}",
"// @codeCoverageIgnoreEnd",
"return",
"self",
"::",
"compareIdentifiers",
"(",
"$",
"left",
"->",
"getPreRelease",
"(",
")",
",",
"$",
"right",
"->",
"getPreRelease",
"(",
")",
")",
";",
"}"
] | Compares one version with another.
@param Version $left The left version to compare.
@param Version $right The right version to compare.
@return integer Returns Comparator::EQUAL_TO if the two versions are
equal. If the left version is less than the right
version, Comparator::LESS_THAN is returned. If the left
version is greater than the right version,
Comparator::GREATER_THAN is returned. | [
"Compares",
"one",
"version",
"with",
"another",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Comparator.php#L39-L62 |
deployphp/phar-update | src/Version/Comparator.php | Comparator.isEqualTo | public static function isEqualTo(Version $left, Version $right)
{
return (self::EQUAL_TO === self::compareTo($left, $right));
} | php | public static function isEqualTo(Version $left, Version $right)
{
return (self::EQUAL_TO === self::compareTo($left, $right));
} | [
"public",
"static",
"function",
"isEqualTo",
"(",
"Version",
"$",
"left",
",",
"Version",
"$",
"right",
")",
"{",
"return",
"(",
"self",
"::",
"EQUAL_TO",
"===",
"self",
"::",
"compareTo",
"(",
"$",
"left",
",",
"$",
"right",
")",
")",
";",
"}"
] | Checks if the left version is equal to the right.
@param Version $left The left version to compare.
@param Version $right The right version to compare.
@return boolean TRUE if the left version is equal to the right, FALSE
if not. | [
"Checks",
"if",
"the",
"left",
"version",
"is",
"equal",
"to",
"the",
"right",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Comparator.php#L73-L76 |
deployphp/phar-update | src/Version/Comparator.php | Comparator.isGreaterThan | public static function isGreaterThan(Version $left, Version $right)
{
return (self::GREATER_THAN === self::compareTo($left, $right));
} | php | public static function isGreaterThan(Version $left, Version $right)
{
return (self::GREATER_THAN === self::compareTo($left, $right));
} | [
"public",
"static",
"function",
"isGreaterThan",
"(",
"Version",
"$",
"left",
",",
"Version",
"$",
"right",
")",
"{",
"return",
"(",
"self",
"::",
"GREATER_THAN",
"===",
"self",
"::",
"compareTo",
"(",
"$",
"left",
",",
"$",
"right",
")",
")",
";",
"}"
] | Checks if the left version is greater than the right.
@param Version $left The left version to compare.
@param Version $right The right version to compare.
@return boolean TRUE if the left version is greater than the right,
FALSE if not. | [
"Checks",
"if",
"the",
"left",
"version",
"is",
"greater",
"than",
"the",
"right",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Comparator.php#L87-L90 |
deployphp/phar-update | src/Version/Comparator.php | Comparator.isLessThan | public static function isLessThan(Version $left, Version $right)
{
return (self::LESS_THAN === self::compareTo($left, $right));
} | php | public static function isLessThan(Version $left, Version $right)
{
return (self::LESS_THAN === self::compareTo($left, $right));
} | [
"public",
"static",
"function",
"isLessThan",
"(",
"Version",
"$",
"left",
",",
"Version",
"$",
"right",
")",
"{",
"return",
"(",
"self",
"::",
"LESS_THAN",
"===",
"self",
"::",
"compareTo",
"(",
"$",
"left",
",",
"$",
"right",
")",
")",
";",
"}"
] | Checks if the left version is less than the right.
@param Version $left The left version to compare.
@param Version $right The right version to compare.
@return boolean TRUE if the left version is less than the right,
FALSE if not. | [
"Checks",
"if",
"the",
"left",
"version",
"is",
"less",
"than",
"the",
"right",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Comparator.php#L101-L104 |
deployphp/phar-update | src/Version/Comparator.php | Comparator.compareIdentifiers | public static function compareIdentifiers(array $left, array $right)
{
if ($left && empty($right)) {
return self::LESS_THAN;
} elseif (empty($left) && $right) {
return self::GREATER_THAN;
}
$l = $left;
$r = $right;
$x = self::GREATER_THAN;
$y = self::LESS_THAN;
if (count($l) < count($r)) {
$l = $right;
$r = $left;
$x = self::LESS_THAN;
$y = self::GREATER_THAN;
}
foreach (array_keys($l) as $i) {
if (!isset($r[$i])) {
return $x;
}
if ($l[$i] === $r[$i]) {
continue;
}
if (true === ($li = (false != preg_match('/^\d+$/', $l[$i])))) {
$l[$i] = intval($l[$i]);
}
if (true === ($ri = (false != preg_match('/^\d+$/', $r[$i])))) {
$r[$i] = intval($r[$i]);
}
if ($li && $ri) {
return ($l[$i] > $r[$i]) ? $x : $y;
} elseif (!$li && $ri) {
return $x;
} elseif ($li && !$ri) {
return $y;
}
$result = strcmp($l[$i], $r[$i]);
if ($result > 0) {
return $x;
} elseif ($result < 0) {
return $y;
}
}
return self::EQUAL_TO;
} | php | public static function compareIdentifiers(array $left, array $right)
{
if ($left && empty($right)) {
return self::LESS_THAN;
} elseif (empty($left) && $right) {
return self::GREATER_THAN;
}
$l = $left;
$r = $right;
$x = self::GREATER_THAN;
$y = self::LESS_THAN;
if (count($l) < count($r)) {
$l = $right;
$r = $left;
$x = self::LESS_THAN;
$y = self::GREATER_THAN;
}
foreach (array_keys($l) as $i) {
if (!isset($r[$i])) {
return $x;
}
if ($l[$i] === $r[$i]) {
continue;
}
if (true === ($li = (false != preg_match('/^\d+$/', $l[$i])))) {
$l[$i] = intval($l[$i]);
}
if (true === ($ri = (false != preg_match('/^\d+$/', $r[$i])))) {
$r[$i] = intval($r[$i]);
}
if ($li && $ri) {
return ($l[$i] > $r[$i]) ? $x : $y;
} elseif (!$li && $ri) {
return $x;
} elseif ($li && !$ri) {
return $y;
}
$result = strcmp($l[$i], $r[$i]);
if ($result > 0) {
return $x;
} elseif ($result < 0) {
return $y;
}
}
return self::EQUAL_TO;
} | [
"public",
"static",
"function",
"compareIdentifiers",
"(",
"array",
"$",
"left",
",",
"array",
"$",
"right",
")",
"{",
"if",
"(",
"$",
"left",
"&&",
"empty",
"(",
"$",
"right",
")",
")",
"{",
"return",
"self",
"::",
"LESS_THAN",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"left",
")",
"&&",
"$",
"right",
")",
"{",
"return",
"self",
"::",
"GREATER_THAN",
";",
"}",
"$",
"l",
"=",
"$",
"left",
";",
"$",
"r",
"=",
"$",
"right",
";",
"$",
"x",
"=",
"self",
"::",
"GREATER_THAN",
";",
"$",
"y",
"=",
"self",
"::",
"LESS_THAN",
";",
"if",
"(",
"count",
"(",
"$",
"l",
")",
"<",
"count",
"(",
"$",
"r",
")",
")",
"{",
"$",
"l",
"=",
"$",
"right",
";",
"$",
"r",
"=",
"$",
"left",
";",
"$",
"x",
"=",
"self",
"::",
"LESS_THAN",
";",
"$",
"y",
"=",
"self",
"::",
"GREATER_THAN",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"l",
")",
"as",
"$",
"i",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"r",
"[",
"$",
"i",
"]",
")",
")",
"{",
"return",
"$",
"x",
";",
"}",
"if",
"(",
"$",
"l",
"[",
"$",
"i",
"]",
"===",
"$",
"r",
"[",
"$",
"i",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"true",
"===",
"(",
"$",
"li",
"=",
"(",
"false",
"!=",
"preg_match",
"(",
"'/^\\d+$/'",
",",
"$",
"l",
"[",
"$",
"i",
"]",
")",
")",
")",
")",
"{",
"$",
"l",
"[",
"$",
"i",
"]",
"=",
"intval",
"(",
"$",
"l",
"[",
"$",
"i",
"]",
")",
";",
"}",
"if",
"(",
"true",
"===",
"(",
"$",
"ri",
"=",
"(",
"false",
"!=",
"preg_match",
"(",
"'/^\\d+$/'",
",",
"$",
"r",
"[",
"$",
"i",
"]",
")",
")",
")",
")",
"{",
"$",
"r",
"[",
"$",
"i",
"]",
"=",
"intval",
"(",
"$",
"r",
"[",
"$",
"i",
"]",
")",
";",
"}",
"if",
"(",
"$",
"li",
"&&",
"$",
"ri",
")",
"{",
"return",
"(",
"$",
"l",
"[",
"$",
"i",
"]",
">",
"$",
"r",
"[",
"$",
"i",
"]",
")",
"?",
"$",
"x",
":",
"$",
"y",
";",
"}",
"elseif",
"(",
"!",
"$",
"li",
"&&",
"$",
"ri",
")",
"{",
"return",
"$",
"x",
";",
"}",
"elseif",
"(",
"$",
"li",
"&&",
"!",
"$",
"ri",
")",
"{",
"return",
"$",
"y",
";",
"}",
"$",
"result",
"=",
"strcmp",
"(",
"$",
"l",
"[",
"$",
"i",
"]",
",",
"$",
"r",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"$",
"result",
">",
"0",
")",
"{",
"return",
"$",
"x",
";",
"}",
"elseif",
"(",
"$",
"result",
"<",
"0",
")",
"{",
"return",
"$",
"y",
";",
"}",
"}",
"return",
"self",
"::",
"EQUAL_TO",
";",
"}"
] | Compares the identifier components of the left and right versions.
@param array $left The left identifiers.
@param array $right The right identifiers.
@return integer Returns Comparator::EQUAL_TO if the two identifiers are
equal. If the left identifiers is less than the right
identifiers, Comparator::LESS_THAN is returned. If the
left identifiers is greater than the right identifiers,
Comparator::GREATER_THAN is returned. | [
"Compares",
"the",
"identifier",
"components",
"of",
"the",
"left",
"and",
"right",
"versions",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Comparator.php#L118-L173 |
deployphp/phar-update | src/Manifest.php | Manifest.findRecent | public function findRecent(Version $version, $major = false, $pre = false)
{
/** @var $current Update */
$current = null;
$major = $major ? $version->getMajor() : null;
foreach ($this->updates as $update) {
if ($major && ($major !== $update->getVersion()->getMajor())) {
continue;
}
if ((false === $pre)
&& !$update->getVersion()->isStable()) {
continue;
}
$test = $current ? $current->getVersion() : $version;
if (false === $update->isNewer($test)) {
continue;
}
$current = $update;
}
return $current;
} | php | public function findRecent(Version $version, $major = false, $pre = false)
{
/** @var $current Update */
$current = null;
$major = $major ? $version->getMajor() : null;
foreach ($this->updates as $update) {
if ($major && ($major !== $update->getVersion()->getMajor())) {
continue;
}
if ((false === $pre)
&& !$update->getVersion()->isStable()) {
continue;
}
$test = $current ? $current->getVersion() : $version;
if (false === $update->isNewer($test)) {
continue;
}
$current = $update;
}
return $current;
} | [
"public",
"function",
"findRecent",
"(",
"Version",
"$",
"version",
",",
"$",
"major",
"=",
"false",
",",
"$",
"pre",
"=",
"false",
")",
"{",
"/** @var $current Update */",
"$",
"current",
"=",
"null",
";",
"$",
"major",
"=",
"$",
"major",
"?",
"$",
"version",
"->",
"getMajor",
"(",
")",
":",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"updates",
"as",
"$",
"update",
")",
"{",
"if",
"(",
"$",
"major",
"&&",
"(",
"$",
"major",
"!==",
"$",
"update",
"->",
"getVersion",
"(",
")",
"->",
"getMajor",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"(",
"false",
"===",
"$",
"pre",
")",
"&&",
"!",
"$",
"update",
"->",
"getVersion",
"(",
")",
"->",
"isStable",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"test",
"=",
"$",
"current",
"?",
"$",
"current",
"->",
"getVersion",
"(",
")",
":",
"$",
"version",
";",
"if",
"(",
"false",
"===",
"$",
"update",
"->",
"isNewer",
"(",
"$",
"test",
")",
")",
"{",
"continue",
";",
"}",
"$",
"current",
"=",
"$",
"update",
";",
"}",
"return",
"$",
"current",
";",
"}"
] | Finds the most recent update and returns it.
@param Version $version The current version.
@param boolean $major Lock to major version?
@param boolean $pre Allow pre-releases?
@return Update The update. | [
"Finds",
"the",
"most",
"recent",
"update",
"and",
"returns",
"it",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Manifest.php#L42-L68 |
deployphp/phar-update | src/Console/Command.php | Command.configure | protected function configure()
{
$this->setDescription('Updates the application.');
$this->addOption(
'pre',
'p',
InputOption::VALUE_NONE,
'Allow pre-release updates.'
);
$this->addOption(
'redo',
'r',
InputOption::VALUE_NONE,
'Redownload update if already using current version.'
);
if (false === $this->disableUpgrade) {
$this->addOption(
'upgrade',
'u',
InputOption::VALUE_NONE,
'Upgrade to next major release, if available.'
);
}
} | php | protected function configure()
{
$this->setDescription('Updates the application.');
$this->addOption(
'pre',
'p',
InputOption::VALUE_NONE,
'Allow pre-release updates.'
);
$this->addOption(
'redo',
'r',
InputOption::VALUE_NONE,
'Redownload update if already using current version.'
);
if (false === $this->disableUpgrade) {
$this->addOption(
'upgrade',
'u',
InputOption::VALUE_NONE,
'Upgrade to next major release, if available.'
);
}
} | [
"protected",
"function",
"configure",
"(",
")",
"{",
"$",
"this",
"->",
"setDescription",
"(",
"'Updates the application.'",
")",
";",
"$",
"this",
"->",
"addOption",
"(",
"'pre'",
",",
"'p'",
",",
"InputOption",
"::",
"VALUE_NONE",
",",
"'Allow pre-release updates.'",
")",
";",
"$",
"this",
"->",
"addOption",
"(",
"'redo'",
",",
"'r'",
",",
"InputOption",
"::",
"VALUE_NONE",
",",
"'Redownload update if already using current version.'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"disableUpgrade",
")",
"{",
"$",
"this",
"->",
"addOption",
"(",
"'upgrade'",
",",
"'u'",
",",
"InputOption",
"::",
"VALUE_NONE",
",",
"'Upgrade to next major release, if available.'",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Console/Command.php#L55-L79 |
deployphp/phar-update | src/Console/Command.php | Command.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->manifestUri) {
throw new LogicException(
'No manifest URI has been configured.'
);
}
$output->writeln('Looking for updates...');
/** @var $pharUpdate Helper */
$pharUpdate = $this->getHelper('phar-update');
$manager = $pharUpdate->getManager($this->manifestUri);
if ($manager->update(
$this->getApplication()->getVersion(),
$this->disableUpgrade ?: (false === $input->getOption('upgrade')),
$input->getOption('pre')
)){
$output->writeln('<info>Update successful!</info>');
} else {
$output->writeln('<comment>Already up-to-date.</comment>');
}
// Force exit to prevent warnings
die(0);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->manifestUri) {
throw new LogicException(
'No manifest URI has been configured.'
);
}
$output->writeln('Looking for updates...');
/** @var $pharUpdate Helper */
$pharUpdate = $this->getHelper('phar-update');
$manager = $pharUpdate->getManager($this->manifestUri);
if ($manager->update(
$this->getApplication()->getVersion(),
$this->disableUpgrade ?: (false === $input->getOption('upgrade')),
$input->getOption('pre')
)){
$output->writeln('<info>Update successful!</info>');
} else {
$output->writeln('<comment>Already up-to-date.</comment>');
}
// Force exit to prevent warnings
die(0);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"manifestUri",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'No manifest URI has been configured.'",
")",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"'Looking for updates...'",
")",
";",
"/** @var $pharUpdate Helper */",
"$",
"pharUpdate",
"=",
"$",
"this",
"->",
"getHelper",
"(",
"'phar-update'",
")",
";",
"$",
"manager",
"=",
"$",
"pharUpdate",
"->",
"getManager",
"(",
"$",
"this",
"->",
"manifestUri",
")",
";",
"if",
"(",
"$",
"manager",
"->",
"update",
"(",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"getVersion",
"(",
")",
",",
"$",
"this",
"->",
"disableUpgrade",
"?",
":",
"(",
"false",
"===",
"$",
"input",
"->",
"getOption",
"(",
"'upgrade'",
")",
")",
",",
"$",
"input",
"->",
"getOption",
"(",
"'pre'",
")",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'<info>Update successful!</info>'",
")",
";",
"}",
"else",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'<comment>Already up-to-date.</comment>'",
")",
";",
"}",
"// Force exit to prevent warnings",
"die",
"(",
"0",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Console/Command.php#L84-L110 |
deployphp/phar-update | src/Update.php | Update.copyTo | public function copyTo($file)
{
if (null === $this->file) {
throw LogicException::create(
'The update file has not been downloaded.'
);
}
$mode = 0755;
if (file_exists($file)) {
$mode = fileperms($file) & 511;
}
if (false === @copy($this->file, $file)) {
throw FileException::lastError();
}
if (false === @chmod($file, $mode)) {
throw FileException::lastError();
}
$key = $file . '.pubkey';
if (file_exists($this->file . '.pubkey')) {
if (false === @copy($this->file . '.pubkey', $key)) {
throw FileException::lastError();
}
} elseif (file_exists($key)) {
if (false === @unlink($key)) {
throw FileException::lastError();
}
}
} | php | public function copyTo($file)
{
if (null === $this->file) {
throw LogicException::create(
'The update file has not been downloaded.'
);
}
$mode = 0755;
if (file_exists($file)) {
$mode = fileperms($file) & 511;
}
if (false === @copy($this->file, $file)) {
throw FileException::lastError();
}
if (false === @chmod($file, $mode)) {
throw FileException::lastError();
}
$key = $file . '.pubkey';
if (file_exists($this->file . '.pubkey')) {
if (false === @copy($this->file . '.pubkey', $key)) {
throw FileException::lastError();
}
} elseif (file_exists($key)) {
if (false === @unlink($key)) {
throw FileException::lastError();
}
}
} | [
"public",
"function",
"copyTo",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"file",
")",
"{",
"throw",
"LogicException",
"::",
"create",
"(",
"'The update file has not been downloaded.'",
")",
";",
"}",
"$",
"mode",
"=",
"0755",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"mode",
"=",
"fileperms",
"(",
"$",
"file",
")",
"&",
"511",
";",
"}",
"if",
"(",
"false",
"===",
"@",
"copy",
"(",
"$",
"this",
"->",
"file",
",",
"$",
"file",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"if",
"(",
"false",
"===",
"@",
"chmod",
"(",
"$",
"file",
",",
"$",
"mode",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"$",
"key",
"=",
"$",
"file",
".",
"'.pubkey'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"file",
".",
"'.pubkey'",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"copy",
"(",
"$",
"this",
"->",
"file",
".",
"'.pubkey'",
",",
"$",
"key",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"unlink",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"}",
"}"
] | Copies the update file to the destination.
@param string $file The target file.
@throws Exception\Exception
@throws FileException If the file could not be replaced. | [
"Copies",
"the",
"update",
"file",
"to",
"the",
"destination",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Update.php#L94-L127 |
deployphp/phar-update | src/Update.php | Update.deleteFile | public function deleteFile()
{
if ($this->file) {
if (file_exists($this->file)) {
if (false === @unlink($this->file)) {
throw FileException::lastError();
}
}
if (file_exists($this->file . '.pubkey')) {
if (false === @unlink($this->file . '.pubkey')) {
throw FileException::lastError();
}
}
$dir = dirname($this->file);
if (file_exists($dir)) {
if (false === @rmdir($dir)) {
throw FileException::lastError();
}
}
$this->file = null;
}
} | php | public function deleteFile()
{
if ($this->file) {
if (file_exists($this->file)) {
if (false === @unlink($this->file)) {
throw FileException::lastError();
}
}
if (file_exists($this->file . '.pubkey')) {
if (false === @unlink($this->file . '.pubkey')) {
throw FileException::lastError();
}
}
$dir = dirname($this->file);
if (file_exists($dir)) {
if (false === @rmdir($dir)) {
throw FileException::lastError();
}
}
$this->file = null;
}
} | [
"public",
"function",
"deleteFile",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"file",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"file",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"unlink",
"(",
"$",
"this",
"->",
"file",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"file",
".",
"'.pubkey'",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"unlink",
"(",
"$",
"this",
"->",
"file",
".",
"'.pubkey'",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"}",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"this",
"->",
"file",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"rmdir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"file",
"=",
"null",
";",
"}",
"}"
] | Cleans up by deleting the temporary update file.
@throws FileException If the file could not be deleted. | [
"Cleans",
"up",
"by",
"deleting",
"the",
"temporary",
"update",
"file",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Update.php#L134-L159 |
deployphp/phar-update | src/Update.php | Update.getFile | public function getFile()
{
if (null === $this->file) {
unlink($this->file = tempnam(sys_get_temp_dir(), 'upd'));
mkdir($this->file);
$this->file .= DIRECTORY_SEPARATOR . $this->name;
$in = new SplFileObject($this->url, 'rb', false);
$out = new SplFileObject($this->file, 'wb', false);
while (false === $in->eof()) {
$out->fwrite($in->fgets());
}
unset($in, $out);
if ($this->publicKey) {
$in = new SplFileObject($this->publicKey, 'r', false);
$out = new SplFileObject($this->file . '.pubkey', 'w', false);
while (false === $in->eof()) {
$out->fwrite($in->fgets());
}
unset($in, $out);
}
if ($this->sha1 !== ($sha1 = sha1_file($this->file))) {
$this->deleteFile();
throw FileException::create(
'Mismatch of the SHA1 checksum (%s) of the downloaded file (%s).',
$this->sha1,
$sha1
);
}
// double check
try {
new Phar($this->file);
} catch (UnexpectedValueException $exception) {
$this->deleteFile();
throw $exception;
}
}
return $this->file;
} | php | public function getFile()
{
if (null === $this->file) {
unlink($this->file = tempnam(sys_get_temp_dir(), 'upd'));
mkdir($this->file);
$this->file .= DIRECTORY_SEPARATOR . $this->name;
$in = new SplFileObject($this->url, 'rb', false);
$out = new SplFileObject($this->file, 'wb', false);
while (false === $in->eof()) {
$out->fwrite($in->fgets());
}
unset($in, $out);
if ($this->publicKey) {
$in = new SplFileObject($this->publicKey, 'r', false);
$out = new SplFileObject($this->file . '.pubkey', 'w', false);
while (false === $in->eof()) {
$out->fwrite($in->fgets());
}
unset($in, $out);
}
if ($this->sha1 !== ($sha1 = sha1_file($this->file))) {
$this->deleteFile();
throw FileException::create(
'Mismatch of the SHA1 checksum (%s) of the downloaded file (%s).',
$this->sha1,
$sha1
);
}
// double check
try {
new Phar($this->file);
} catch (UnexpectedValueException $exception) {
$this->deleteFile();
throw $exception;
}
}
return $this->file;
} | [
"public",
"function",
"getFile",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"file",
")",
"{",
"unlink",
"(",
"$",
"this",
"->",
"file",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'upd'",
")",
")",
";",
"mkdir",
"(",
"$",
"this",
"->",
"file",
")",
";",
"$",
"this",
"->",
"file",
".=",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"name",
";",
"$",
"in",
"=",
"new",
"SplFileObject",
"(",
"$",
"this",
"->",
"url",
",",
"'rb'",
",",
"false",
")",
";",
"$",
"out",
"=",
"new",
"SplFileObject",
"(",
"$",
"this",
"->",
"file",
",",
"'wb'",
",",
"false",
")",
";",
"while",
"(",
"false",
"===",
"$",
"in",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"out",
"->",
"fwrite",
"(",
"$",
"in",
"->",
"fgets",
"(",
")",
")",
";",
"}",
"unset",
"(",
"$",
"in",
",",
"$",
"out",
")",
";",
"if",
"(",
"$",
"this",
"->",
"publicKey",
")",
"{",
"$",
"in",
"=",
"new",
"SplFileObject",
"(",
"$",
"this",
"->",
"publicKey",
",",
"'r'",
",",
"false",
")",
";",
"$",
"out",
"=",
"new",
"SplFileObject",
"(",
"$",
"this",
"->",
"file",
".",
"'.pubkey'",
",",
"'w'",
",",
"false",
")",
";",
"while",
"(",
"false",
"===",
"$",
"in",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"out",
"->",
"fwrite",
"(",
"$",
"in",
"->",
"fgets",
"(",
")",
")",
";",
"}",
"unset",
"(",
"$",
"in",
",",
"$",
"out",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"sha1",
"!==",
"(",
"$",
"sha1",
"=",
"sha1_file",
"(",
"$",
"this",
"->",
"file",
")",
")",
")",
"{",
"$",
"this",
"->",
"deleteFile",
"(",
")",
";",
"throw",
"FileException",
"::",
"create",
"(",
"'Mismatch of the SHA1 checksum (%s) of the downloaded file (%s).'",
",",
"$",
"this",
"->",
"sha1",
",",
"$",
"sha1",
")",
";",
"}",
"// double check",
"try",
"{",
"new",
"Phar",
"(",
"$",
"this",
"->",
"file",
")",
";",
"}",
"catch",
"(",
"UnexpectedValueException",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"deleteFile",
"(",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"file",
";",
"}"
] | Downloads the update file to a temporary location.
@return string The temporary file path.
@throws Exception\Exception
@throws FileException If the SHA1 checksum differs.
@throws UnexpectedValueException If the Phar is corrupt. | [
"Downloads",
"the",
"update",
"file",
"to",
"a",
"temporary",
"location",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Update.php#L170-L219 |
deployphp/phar-update | src/Manager.php | Manager.getRunningFile | public function getRunningFile()
{
if (null === $this->runningFile) {
$this->runningFile = realpath($_SERVER['argv'][0]);
}
return $this->runningFile;
} | php | public function getRunningFile()
{
if (null === $this->runningFile) {
$this->runningFile = realpath($_SERVER['argv'][0]);
}
return $this->runningFile;
} | [
"public",
"function",
"getRunningFile",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"runningFile",
")",
"{",
"$",
"this",
"->",
"runningFile",
"=",
"realpath",
"(",
"$",
"_SERVER",
"[",
"'argv'",
"]",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"runningFile",
";",
"}"
] | Returns the running file (the Phar that will be updated).
@return string The file. | [
"Returns",
"the",
"running",
"file",
"(",
"the",
"Phar",
"that",
"will",
"be",
"updated",
")",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Manager.php#L55-L62 |
deployphp/phar-update | src/Manager.php | Manager.setRunningFile | public function setRunningFile($file)
{
if (false === is_file($file)) {
throw InvalidArgumentException::create(
'The file "%s" is not a file or it does not exist.',
$file
);
}
$this->runningFile = $file;
} | php | public function setRunningFile($file)
{
if (false === is_file($file)) {
throw InvalidArgumentException::create(
'The file "%s" is not a file or it does not exist.',
$file
);
}
$this->runningFile = $file;
} | [
"public",
"function",
"setRunningFile",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"false",
"===",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"InvalidArgumentException",
"::",
"create",
"(",
"'The file \"%s\" is not a file or it does not exist.'",
",",
"$",
"file",
")",
";",
"}",
"$",
"this",
"->",
"runningFile",
"=",
"$",
"file",
";",
"}"
] | Sets the running file (the Phar that will be updated).
@param string $file The file name or path.
@throws Exception\Exception
@throws InvalidArgumentException If the file path is invalid. | [
"Sets",
"the",
"running",
"file",
"(",
"the",
"Phar",
"that",
"will",
"be",
"updated",
")",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Manager.php#L72-L82 |
deployphp/phar-update | src/Manager.php | Manager.update | public function update($version, $major = false, $pre = false)
{
if (false === ($version instanceof Version)) {
$version = Parser::toVersion($version);
}
if (null !== ($update = $this->manifest->findRecent(
$version,
$major,
$pre
))) {
$update->getFile();
$update->copyTo($this->getRunningFile());
return true;
}
return false;
} | php | public function update($version, $major = false, $pre = false)
{
if (false === ($version instanceof Version)) {
$version = Parser::toVersion($version);
}
if (null !== ($update = $this->manifest->findRecent(
$version,
$major,
$pre
))) {
$update->getFile();
$update->copyTo($this->getRunningFile());
return true;
}
return false;
} | [
"public",
"function",
"update",
"(",
"$",
"version",
",",
"$",
"major",
"=",
"false",
",",
"$",
"pre",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"version",
"instanceof",
"Version",
")",
")",
"{",
"$",
"version",
"=",
"Parser",
"::",
"toVersion",
"(",
"$",
"version",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"update",
"=",
"$",
"this",
"->",
"manifest",
"->",
"findRecent",
"(",
"$",
"version",
",",
"$",
"major",
",",
"$",
"pre",
")",
")",
")",
"{",
"$",
"update",
"->",
"getFile",
"(",
")",
";",
"$",
"update",
"->",
"copyTo",
"(",
"$",
"this",
"->",
"getRunningFile",
"(",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Updates the running Phar if any is available.
@param string|Version $version The current version.
@param boolean $major Lock to current major version?
@param boolean $pre Allow pre-releases?
@return boolean TRUE if an update was performed, FALSE if none available. | [
"Updates",
"the",
"running",
"Phar",
"if",
"any",
"is",
"available",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Manager.php#L93-L111 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.callMethod | public function callMethod($class, $method, array $args = array())
{
$method = $this->findMethod($class, $method);
$method->setAccessible(true);
return $method->invokeArgs(
is_object($class) ? $class : null,
$args
);
} | php | public function callMethod($class, $method, array $args = array())
{
$method = $this->findMethod($class, $method);
$method->setAccessible(true);
return $method->invokeArgs(
is_object($class) ? $class : null,
$args
);
} | [
"public",
"function",
"callMethod",
"(",
"$",
"class",
",",
"$",
"method",
",",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"findMethod",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"$",
"method",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"method",
"->",
"invokeArgs",
"(",
"is_object",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"null",
",",
"$",
"args",
")",
";",
"}"
] | Calls a class or object method.
@param object|string $class The class name or object.
@param string $method The method name.
@param array $args The method arguments.
@return mixed The method result. | [
"Calls",
"a",
"class",
"or",
"object",
"method",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L36-L45 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.copyPath | public function copyPath($from, $to, $replace = true, $purge = true)
{
if (false === file_exists($from)) {
throw FileSystemException::invalidPath($from);
}
if (is_dir($from)) {
if (false === file_exists($to)) {
if (false === @ mkdir($to)) {
throw FileSystemException::lastError(
$to,
"The directory \"$to\" could not be created: "
);
}
}
if (false === ($dh = @ opendir($from))) {
throw FileSystemException::lastError(
$to,
"The directory \"$from\" could not be opened: "
);
}
while (false !== ($item = readdir($dh))) {
if (('.' === $item) || ('..' === $item)) {
continue;
}
$this->copyPath(
$from . DIRECTORY_SEPARATOR . $item,
$to . DIRECTORY_SEPARATOR . $item,
$replace,
false
);
}
closedir($dh);
} elseif (false === (file_exists($to) && (false === $replace))) {
if (false === @ copy($from, $to)) {
throw FileSystemException::lastError($to);
}
}
if ($purge) {
$this->purgePaths[] = $to;
}
} | php | public function copyPath($from, $to, $replace = true, $purge = true)
{
if (false === file_exists($from)) {
throw FileSystemException::invalidPath($from);
}
if (is_dir($from)) {
if (false === file_exists($to)) {
if (false === @ mkdir($to)) {
throw FileSystemException::lastError(
$to,
"The directory \"$to\" could not be created: "
);
}
}
if (false === ($dh = @ opendir($from))) {
throw FileSystemException::lastError(
$to,
"The directory \"$from\" could not be opened: "
);
}
while (false !== ($item = readdir($dh))) {
if (('.' === $item) || ('..' === $item)) {
continue;
}
$this->copyPath(
$from . DIRECTORY_SEPARATOR . $item,
$to . DIRECTORY_SEPARATOR . $item,
$replace,
false
);
}
closedir($dh);
} elseif (false === (file_exists($to) && (false === $replace))) {
if (false === @ copy($from, $to)) {
throw FileSystemException::lastError($to);
}
}
if ($purge) {
$this->purgePaths[] = $to;
}
} | [
"public",
"function",
"copyPath",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"replace",
"=",
"true",
",",
"$",
"purge",
"=",
"true",
")",
"{",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"from",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"invalidPath",
"(",
"$",
"from",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"from",
")",
")",
"{",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"to",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"mkdir",
"(",
"$",
"to",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"to",
",",
"\"The directory \\\"$to\\\" could not be created: \"",
")",
";",
"}",
"}",
"if",
"(",
"false",
"===",
"(",
"$",
"dh",
"=",
"@",
"opendir",
"(",
"$",
"from",
")",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"to",
",",
"\"The directory \\\"$from\\\" could not be opened: \"",
")",
";",
"}",
"while",
"(",
"false",
"!==",
"(",
"$",
"item",
"=",
"readdir",
"(",
"$",
"dh",
")",
")",
")",
"{",
"if",
"(",
"(",
"'.'",
"===",
"$",
"item",
")",
"||",
"(",
"'..'",
"===",
"$",
"item",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"copyPath",
"(",
"$",
"from",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"item",
",",
"$",
"to",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"item",
",",
"$",
"replace",
",",
"false",
")",
";",
"}",
"closedir",
"(",
"$",
"dh",
")",
";",
"}",
"elseif",
"(",
"false",
"===",
"(",
"file_exists",
"(",
"$",
"to",
")",
"&&",
"(",
"false",
"===",
"$",
"replace",
")",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"copy",
"(",
"$",
"from",
",",
"$",
"to",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"to",
")",
";",
"}",
"}",
"if",
"(",
"$",
"purge",
")",
"{",
"$",
"this",
"->",
"purgePaths",
"[",
"]",
"=",
"$",
"to",
";",
"}",
"}"
] | Recursively copies a file or directory tree to another location.
@param string $from The source file system path.
@param string $to The target file system path.
@param boolean $replace Replacing existing files?
@param boolean $purge Automatically purge?
@throws FileSystemException If the path could not be copied. | [
"Recursively",
"copies",
"a",
"file",
"or",
"directory",
"tree",
"to",
"another",
"location",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L57-L103 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.createDir | public function createDir($name = null)
{
unlink($dir = $this->createFile());
if (false === mkdir($dir)) {
throw FileSystemException::lastError($dir);
}
if (null !== $name) {
$dir .= DIRECTORY_SEPARATOR . $name;
if (false === mkdir($dir)) {
throw FileSystemException::lastError($dir);
}
}
return $dir;
} | php | public function createDir($name = null)
{
unlink($dir = $this->createFile());
if (false === mkdir($dir)) {
throw FileSystemException::lastError($dir);
}
if (null !== $name) {
$dir .= DIRECTORY_SEPARATOR . $name;
if (false === mkdir($dir)) {
throw FileSystemException::lastError($dir);
}
}
return $dir;
} | [
"public",
"function",
"createDir",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"unlink",
"(",
"$",
"dir",
"=",
"$",
"this",
"->",
"createFile",
"(",
")",
")",
";",
"if",
"(",
"false",
"===",
"mkdir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"dir",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"name",
")",
"{",
"$",
"dir",
".=",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
";",
"if",
"(",
"false",
"===",
"mkdir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"dir",
")",
";",
"}",
"}",
"return",
"$",
"dir",
";",
"}"
] | Creates a temporary directory path that will be automatically purged
at the end of the test.
@param string $name The directory name.
@return string The directory path.
@throws FileSystemException If the directory could not be created. | [
"Creates",
"a",
"temporary",
"directory",
"path",
"that",
"will",
"be",
"automatically",
"purged",
"at",
"the",
"end",
"of",
"the",
"test",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L115-L132 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.createFile | public function createFile($name = null)
{
if (null === $name) {
if (false === ($file = tempnam(sys_get_temp_dir(), 'tst'))) {
throw FileSystemException::lastError($name);
}
$this->purgePaths[] = $file;
} else {
if (false === touch(
$file = $this->createDir() . DIRECTORY_SEPARATOR . $name
)){
throw FileSystemException::lastError($file);
}
}
return $file;
} | php | public function createFile($name = null)
{
if (null === $name) {
if (false === ($file = tempnam(sys_get_temp_dir(), 'tst'))) {
throw FileSystemException::lastError($name);
}
$this->purgePaths[] = $file;
} else {
if (false === touch(
$file = $this->createDir() . DIRECTORY_SEPARATOR . $name
)){
throw FileSystemException::lastError($file);
}
}
return $file;
} | [
"public",
"function",
"createFile",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"file",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'tst'",
")",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"name",
")",
";",
"}",
"$",
"this",
"->",
"purgePaths",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"else",
"{",
"if",
"(",
"false",
"===",
"touch",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"createDir",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"file",
")",
";",
"}",
"}",
"return",
"$",
"file",
";",
"}"
] | Creates a temporary file path that will be automatically purged at the
end of the test.
@param string $name The file name.
@return string The file path.
@throws FileSystemException If the file could not be created. | [
"Creates",
"a",
"temporary",
"file",
"path",
"that",
"will",
"be",
"automatically",
"purged",
"at",
"the",
"end",
"of",
"the",
"test",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L144-L161 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.findMethod | public function findMethod($class, $name)
{
$reflection = new ReflectionClass($class);
while (false === $reflection->hasMethod($name)) {
if (false === ($reflection = $reflection->getParentClass())) {
throw new ReflectionException(sprintf(
'The method "%s" does not exist in the class "%s".',
$name,
is_object($class) ? get_class($class) : $class
));
}
}
return $reflection->getMethod($name);
} | php | public function findMethod($class, $name)
{
$reflection = new ReflectionClass($class);
while (false === $reflection->hasMethod($name)) {
if (false === ($reflection = $reflection->getParentClass())) {
throw new ReflectionException(sprintf(
'The method "%s" does not exist in the class "%s".',
$name,
is_object($class) ? get_class($class) : $class
));
}
}
return $reflection->getMethod($name);
} | [
"public",
"function",
"findMethod",
"(",
"$",
"class",
",",
"$",
"name",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"while",
"(",
"false",
"===",
"$",
"reflection",
"->",
"hasMethod",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"reflection",
"=",
"$",
"reflection",
"->",
"getParentClass",
"(",
")",
")",
")",
"{",
"throw",
"new",
"ReflectionException",
"(",
"sprintf",
"(",
"'The method \"%s\" does not exist in the class \"%s\".'",
",",
"$",
"name",
",",
"is_object",
"(",
"$",
"class",
")",
"?",
"get_class",
"(",
"$",
"class",
")",
":",
"$",
"class",
")",
")",
";",
"}",
"}",
"return",
"$",
"reflection",
"->",
"getMethod",
"(",
"$",
"name",
")",
";",
"}"
] | Finds a class method and returns the ReflectionMethod instance.
@param object|string $class The class name or object.
@param string $name The method name.
@return ReflectionMethod The method name.
@throws ReflectionException If the method does not exist. | [
"Finds",
"a",
"class",
"method",
"and",
"returns",
"the",
"ReflectionMethod",
"instance",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L173-L188 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.findProperty | public function findProperty($class, $name)
{
$reflection = new ReflectionClass($class);
while (false === $reflection->hasProperty($name)) {
if (false === ($reflection = $reflection->getParentClass())) {
throw new ReflectionException(sprintf(
'The property "%s" does not exist in the class "%s".',
$name,
is_object($class) ? get_class($class) : $class
));
}
}
return $reflection->getProperty($name);
} | php | public function findProperty($class, $name)
{
$reflection = new ReflectionClass($class);
while (false === $reflection->hasProperty($name)) {
if (false === ($reflection = $reflection->getParentClass())) {
throw new ReflectionException(sprintf(
'The property "%s" does not exist in the class "%s".',
$name,
is_object($class) ? get_class($class) : $class
));
}
}
return $reflection->getProperty($name);
} | [
"public",
"function",
"findProperty",
"(",
"$",
"class",
",",
"$",
"name",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"while",
"(",
"false",
"===",
"$",
"reflection",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"reflection",
"=",
"$",
"reflection",
"->",
"getParentClass",
"(",
")",
")",
")",
"{",
"throw",
"new",
"ReflectionException",
"(",
"sprintf",
"(",
"'The property \"%s\" does not exist in the class \"%s\".'",
",",
"$",
"name",
",",
"is_object",
"(",
"$",
"class",
")",
"?",
"get_class",
"(",
"$",
"class",
")",
":",
"$",
"class",
")",
")",
";",
"}",
"}",
"return",
"$",
"reflection",
"->",
"getProperty",
"(",
"$",
"name",
")",
";",
"}"
] | Finds a class property and returns the ReflectionProperty instance.
@param object|string $class The class name or object.
@param string $name The property name.
@return ReflectionProperty The property instance.
@throws ReflectionException If the property is not found. | [
"Finds",
"a",
"class",
"property",
"and",
"returns",
"the",
"ReflectionProperty",
"instance",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L200-L215 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.getPropertyValue | public function getPropertyValue($class, $name)
{
$property = $this->findProperty($class, $name);
$property->setAccessible(true);
return $property->getValue(is_object($class) ? $class : null);
} | php | public function getPropertyValue($class, $name)
{
$property = $this->findProperty($class, $name);
$property->setAccessible(true);
return $property->getValue(is_object($class) ? $class : null);
} | [
"public",
"function",
"getPropertyValue",
"(",
"$",
"class",
",",
"$",
"name",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"findProperty",
"(",
"$",
"class",
",",
"$",
"name",
")",
";",
"$",
"property",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"property",
"->",
"getValue",
"(",
"is_object",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"null",
")",
";",
"}"
] | Returns the value of the property.
@param object|string $class The class name or object.
@param string $name The property name.
@return mixed The value of the property. | [
"Returns",
"the",
"value",
"of",
"the",
"property",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L225-L231 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.purgePath | public function purgePath($path)
{
if (false === file_exists($path)) {
throw FileSystemException::invalidPath($path);
}
if (is_dir($path)) {
if (false === ($dh = @ opendir($path))) {
throw FileSystemException::lastError($path);
}
while (false !== ($item = readdir($dh))) {
if (('.' === $item) || ('..' === $item)) {
continue;
}
$this->purgePath($path . DIRECTORY_SEPARATOR . $item);
}
closedir($dh);
if (false === @ rmdir($path)) {
throw FileSystemException::lastError($path);
}
} else {
if (false === @ unlink($path)) {
throw FileSystemException::lastError($path);
}
}
} | php | public function purgePath($path)
{
if (false === file_exists($path)) {
throw FileSystemException::invalidPath($path);
}
if (is_dir($path)) {
if (false === ($dh = @ opendir($path))) {
throw FileSystemException::lastError($path);
}
while (false !== ($item = readdir($dh))) {
if (('.' === $item) || ('..' === $item)) {
continue;
}
$this->purgePath($path . DIRECTORY_SEPARATOR . $item);
}
closedir($dh);
if (false === @ rmdir($path)) {
throw FileSystemException::lastError($path);
}
} else {
if (false === @ unlink($path)) {
throw FileSystemException::lastError($path);
}
}
} | [
"public",
"function",
"purgePath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"invalidPath",
"(",
"$",
"path",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"dh",
"=",
"@",
"opendir",
"(",
"$",
"path",
")",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"path",
")",
";",
"}",
"while",
"(",
"false",
"!==",
"(",
"$",
"item",
"=",
"readdir",
"(",
"$",
"dh",
")",
")",
")",
"{",
"if",
"(",
"(",
"'.'",
"===",
"$",
"item",
")",
"||",
"(",
"'..'",
"===",
"$",
"item",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"purgePath",
"(",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"item",
")",
";",
"}",
"closedir",
"(",
"$",
"dh",
")",
";",
"if",
"(",
"false",
"===",
"@",
"rmdir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"path",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"false",
"===",
"@",
"unlink",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"FileSystemException",
"::",
"lastError",
"(",
"$",
"path",
")",
";",
"}",
"}",
"}"
] | Recursively deletes a file or directory tree.
@param string $path The file or directory path.
@throws FileSystemException If the path could not be purged.
s | [
"Recursively",
"deletes",
"a",
"file",
"or",
"directory",
"tree",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L240-L269 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.setPropertyValue | public function setPropertyValue($class, $name, $value)
{
$property = $this->findProperty($class, $name);
$property->setAccessible(true);
$property->setValue(
is_object($class) ? $class : null,
$value
);
} | php | public function setPropertyValue($class, $name, $value)
{
$property = $this->findProperty($class, $name);
$property->setAccessible(true);
$property->setValue(
is_object($class) ? $class : null,
$value
);
} | [
"public",
"function",
"setPropertyValue",
"(",
"$",
"class",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"findProperty",
"(",
"$",
"class",
",",
"$",
"name",
")",
";",
"$",
"property",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"property",
"->",
"setValue",
"(",
"is_object",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"null",
",",
"$",
"value",
")",
";",
"}"
] | Sets the value of the property.
@param object|string $class The class name or object.
@param string $name The property name.
@param mixed $value The property value. | [
"Sets",
"the",
"value",
"of",
"the",
"property",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L294-L302 |
deployphp/phar-update | src/PHPUnit/Extras.php | Extras.tearDown | protected function tearDown()
{
foreach ($this->purgePaths as $path) {
if (file_exists($path)) {
$this->purgePath($path);
}
}
} | php | protected function tearDown()
{
foreach ($this->purgePaths as $path) {
if (file_exists($path)) {
$this->purgePath($path);
}
}
} | [
"protected",
"function",
"tearDown",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"purgePaths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"purgePath",
"(",
"$",
"path",
")",
";",
"}",
"}",
"}"
] | Purges the created paths and reverts changes made by Runkit. | [
"Purges",
"the",
"created",
"paths",
"and",
"reverts",
"changes",
"made",
"by",
"Runkit",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/PHPUnit/Extras.php#L307-L314 |
deployphp/phar-update | src/Version/Builder.php | Builder.getVersion | public function getVersion()
{
return new Version(
$this->major,
$this->minor,
$this->patch,
$this->preRelease,
$this->build
);
} | php | public function getVersion()
{
return new Version(
$this->major,
$this->minor,
$this->patch,
$this->preRelease,
$this->build
);
} | [
"public",
"function",
"getVersion",
"(",
")",
"{",
"return",
"new",
"Version",
"(",
"$",
"this",
"->",
"major",
",",
"$",
"this",
"->",
"minor",
",",
"$",
"this",
"->",
"patch",
",",
"$",
"this",
"->",
"preRelease",
",",
"$",
"this",
"->",
"build",
")",
";",
"}"
] | Returns a readonly Version instance.
@return Version The readonly Version instance. | [
"Returns",
"a",
"readonly",
"Version",
"instance",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L50-L59 |
deployphp/phar-update | src/Version/Builder.php | Builder.importComponents | public function importComponents(array $components)
{
if (isset($components[Parser::BUILD])) {
$this->build = $components[Parser::BUILD];
} else {
$this->build = array();
}
if (isset($components[Parser::MAJOR])) {
$this->major = $components[Parser::MAJOR];
} else {
$this->major = 0;
}
if (isset($components[Parser::MINOR])) {
$this->minor = $components[Parser::MINOR];
} else {
$this->minor = 0;
}
if (isset($components[Parser::PATCH])) {
$this->patch = $components[Parser::PATCH];
} else {
$this->patch = 0;
}
if (isset($components[Parser::PRE_RELEASE])) {
$this->preRelease = $components[Parser::PRE_RELEASE];
} else {
$this->preRelease = array();
}
return $this;
} | php | public function importComponents(array $components)
{
if (isset($components[Parser::BUILD])) {
$this->build = $components[Parser::BUILD];
} else {
$this->build = array();
}
if (isset($components[Parser::MAJOR])) {
$this->major = $components[Parser::MAJOR];
} else {
$this->major = 0;
}
if (isset($components[Parser::MINOR])) {
$this->minor = $components[Parser::MINOR];
} else {
$this->minor = 0;
}
if (isset($components[Parser::PATCH])) {
$this->patch = $components[Parser::PATCH];
} else {
$this->patch = 0;
}
if (isset($components[Parser::PRE_RELEASE])) {
$this->preRelease = $components[Parser::PRE_RELEASE];
} else {
$this->preRelease = array();
}
return $this;
} | [
"public",
"function",
"importComponents",
"(",
"array",
"$",
"components",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"components",
"[",
"Parser",
"::",
"BUILD",
"]",
")",
")",
"{",
"$",
"this",
"->",
"build",
"=",
"$",
"components",
"[",
"Parser",
"::",
"BUILD",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"build",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"components",
"[",
"Parser",
"::",
"MAJOR",
"]",
")",
")",
"{",
"$",
"this",
"->",
"major",
"=",
"$",
"components",
"[",
"Parser",
"::",
"MAJOR",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"major",
"=",
"0",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"components",
"[",
"Parser",
"::",
"MINOR",
"]",
")",
")",
"{",
"$",
"this",
"->",
"minor",
"=",
"$",
"components",
"[",
"Parser",
"::",
"MINOR",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"minor",
"=",
"0",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"components",
"[",
"Parser",
"::",
"PATCH",
"]",
")",
")",
"{",
"$",
"this",
"->",
"patch",
"=",
"$",
"components",
"[",
"Parser",
"::",
"PATCH",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"patch",
"=",
"0",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"components",
"[",
"Parser",
"::",
"PRE_RELEASE",
"]",
")",
")",
"{",
"$",
"this",
"->",
"preRelease",
"=",
"$",
"components",
"[",
"Parser",
"::",
"PRE_RELEASE",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"preRelease",
"=",
"array",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Imports the version components.
@param array $components The components.
@return Builder The Version builder. | [
"Imports",
"the",
"version",
"components",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L68-L101 |
deployphp/phar-update | src/Version/Builder.php | Builder.importVersion | public function importVersion($version)
{
return $this
->setMajor($version->getMajor())
->setMinor($version->getMinor())
->setPatch($version->getPatch())
->setPreRelease($version->getPreRelease())
->setBuild($version->getBuild());
} | php | public function importVersion($version)
{
return $this
->setMajor($version->getMajor())
->setMinor($version->getMinor())
->setPatch($version->getPatch())
->setPreRelease($version->getPreRelease())
->setBuild($version->getBuild());
} | [
"public",
"function",
"importVersion",
"(",
"$",
"version",
")",
"{",
"return",
"$",
"this",
"->",
"setMajor",
"(",
"$",
"version",
"->",
"getMajor",
"(",
")",
")",
"->",
"setMinor",
"(",
"$",
"version",
"->",
"getMinor",
"(",
")",
")",
"->",
"setPatch",
"(",
"$",
"version",
"->",
"getPatch",
"(",
")",
")",
"->",
"setPreRelease",
"(",
"$",
"version",
"->",
"getPreRelease",
"(",
")",
")",
"->",
"setBuild",
"(",
"$",
"version",
"->",
"getBuild",
"(",
")",
")",
";",
"}"
] | Imports an existing Version instance.
@param Version $version A Version instance.
@return Builder The Version builder. | [
"Imports",
"an",
"existing",
"Version",
"instance",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L122-L130 |
deployphp/phar-update | src/Version/Builder.php | Builder.incrementMajor | public function incrementMajor($amount = 1)
{
$this->major += $amount;
$this->minor = 0;
$this->patch = 0;
return $this;
} | php | public function incrementMajor($amount = 1)
{
$this->major += $amount;
$this->minor = 0;
$this->patch = 0;
return $this;
} | [
"public",
"function",
"incrementMajor",
"(",
"$",
"amount",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"major",
"+=",
"$",
"amount",
";",
"$",
"this",
"->",
"minor",
"=",
"0",
";",
"$",
"this",
"->",
"patch",
"=",
"0",
";",
"return",
"$",
"this",
";",
"}"
] | Increments the major version number and resets the minor and patch
version numbers to zero.
@param integer $amount Increment by what amount?
@return Builder The Version builder. | [
"Increments",
"the",
"major",
"version",
"number",
"and",
"resets",
"the",
"minor",
"and",
"patch",
"version",
"numbers",
"to",
"zero",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L140-L147 |
deployphp/phar-update | src/Version/Builder.php | Builder.setBuild | public function setBuild(array $identifiers)
{
foreach ($identifiers as $identifier) {
if (!Validator::isIdentifier($identifier)) {
throw new InvalidIdentifierException($identifier);
}
}
$this->build = $identifiers;
return $this;
} | php | public function setBuild(array $identifiers)
{
foreach ($identifiers as $identifier) {
if (!Validator::isIdentifier($identifier)) {
throw new InvalidIdentifierException($identifier);
}
}
$this->build = $identifiers;
return $this;
} | [
"public",
"function",
"setBuild",
"(",
"array",
"$",
"identifiers",
")",
"{",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"identifier",
")",
"{",
"if",
"(",
"!",
"Validator",
"::",
"isIdentifier",
"(",
"$",
"identifier",
")",
")",
"{",
"throw",
"new",
"InvalidIdentifierException",
"(",
"$",
"identifier",
")",
";",
"}",
"}",
"$",
"this",
"->",
"build",
"=",
"$",
"identifiers",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the build metadata identifiers.
@param array $identifiers The build metadata identifiers.
@return Builder The Version builder.
@throws InvalidIdentifierException If an identifier is invalid. | [
"Sets",
"the",
"build",
"metadata",
"identifiers",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L188-L199 |
deployphp/phar-update | src/Version/Builder.php | Builder.setMajor | public function setMajor($number)
{
if (!Validator::isNumber($number)) {
throw new InvalidNumberException($number);
}
$this->major = intval($number);
return $this;
} | php | public function setMajor($number)
{
if (!Validator::isNumber($number)) {
throw new InvalidNumberException($number);
}
$this->major = intval($number);
return $this;
} | [
"public",
"function",
"setMajor",
"(",
"$",
"number",
")",
"{",
"if",
"(",
"!",
"Validator",
"::",
"isNumber",
"(",
"$",
"number",
")",
")",
"{",
"throw",
"new",
"InvalidNumberException",
"(",
"$",
"number",
")",
";",
"}",
"$",
"this",
"->",
"major",
"=",
"intval",
"(",
"$",
"number",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the major version number.
@param integer $number The major version number.
@return Builder The Version builder.
@throws InvalidNumberException If the number is invalid. | [
"Sets",
"the",
"major",
"version",
"number",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L210-L219 |
deployphp/phar-update | src/Version/Builder.php | Builder.setMinor | public function setMinor($number)
{
if (!Validator::isNumber($number)) {
throw new InvalidNumberException($number);
}
$this->minor = intval($number);
return $this;
} | php | public function setMinor($number)
{
if (!Validator::isNumber($number)) {
throw new InvalidNumberException($number);
}
$this->minor = intval($number);
return $this;
} | [
"public",
"function",
"setMinor",
"(",
"$",
"number",
")",
"{",
"if",
"(",
"!",
"Validator",
"::",
"isNumber",
"(",
"$",
"number",
")",
")",
"{",
"throw",
"new",
"InvalidNumberException",
"(",
"$",
"number",
")",
";",
"}",
"$",
"this",
"->",
"minor",
"=",
"intval",
"(",
"$",
"number",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the minor version number.
@param integer $number The minor version number.
@return Builder The Version builder.
@throws InvalidNumberException If the number is invalid. | [
"Sets",
"the",
"minor",
"version",
"number",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L230-L239 |
deployphp/phar-update | src/Version/Builder.php | Builder.setPatch | public function setPatch($number)
{
if (!Validator::isNumber($number)) {
throw new InvalidNumberException($number);
}
$this->patch = intval($number);
return $this;
} | php | public function setPatch($number)
{
if (!Validator::isNumber($number)) {
throw new InvalidNumberException($number);
}
$this->patch = intval($number);
return $this;
} | [
"public",
"function",
"setPatch",
"(",
"$",
"number",
")",
"{",
"if",
"(",
"!",
"Validator",
"::",
"isNumber",
"(",
"$",
"number",
")",
")",
"{",
"throw",
"new",
"InvalidNumberException",
"(",
"$",
"number",
")",
";",
"}",
"$",
"this",
"->",
"patch",
"=",
"intval",
"(",
"$",
"number",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the patch version number.
@param integer $number The patch version number.
@return Builder The Version builder.
@throws InvalidNumberException If the number is invalid. | [
"Sets",
"the",
"patch",
"version",
"number",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L250-L259 |
deployphp/phar-update | src/Version/Builder.php | Builder.setPreRelease | public function setPreRelease(array $identifiers)
{
foreach ($identifiers as $identifier) {
if (!Validator::isIdentifier($identifier)) {
throw new InvalidIdentifierException($identifier);
}
}
$this->preRelease = $identifiers;
return $this;
} | php | public function setPreRelease(array $identifiers)
{
foreach ($identifiers as $identifier) {
if (!Validator::isIdentifier($identifier)) {
throw new InvalidIdentifierException($identifier);
}
}
$this->preRelease = $identifiers;
return $this;
} | [
"public",
"function",
"setPreRelease",
"(",
"array",
"$",
"identifiers",
")",
"{",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"identifier",
")",
"{",
"if",
"(",
"!",
"Validator",
"::",
"isIdentifier",
"(",
"$",
"identifier",
")",
")",
"{",
"throw",
"new",
"InvalidIdentifierException",
"(",
"$",
"identifier",
")",
";",
"}",
"}",
"$",
"this",
"->",
"preRelease",
"=",
"$",
"identifiers",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the pre-release version identifiers.
@param array $identifiers The pre-release version identifiers.
@return Builder The Version builder.
@throws InvalidIdentifierException If an identifier is invalid. | [
"Sets",
"the",
"pre",
"-",
"release",
"version",
"identifiers",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Builder.php#L270-L281 |
deployphp/phar-update | src/Version/Parser.php | Parser.toComponents | public static function toComponents($version)
{
if (!Validator::isVersion($version)) {
throw new InvalidStringRepresentationException($version);
}
if (false !== strpos($version, '+')) {
list($version, $build) = explode('+', $version);
$build = explode('.', $build);
}
if (false !== strpos($version, '-')) {
list($version, $pre) = explode('-', $version);
$pre = explode('.', $pre);
}
list(
$major,
$minor,
$patch
) = explode('.', $version);
return array(
self::MAJOR => intval($major),
self::MINOR => intval($minor),
self::PATCH => intval($patch),
self::PRE_RELEASE => isset($pre) ? $pre : array(),
self::BUILD => isset($build) ? $build : array(),
);
} | php | public static function toComponents($version)
{
if (!Validator::isVersion($version)) {
throw new InvalidStringRepresentationException($version);
}
if (false !== strpos($version, '+')) {
list($version, $build) = explode('+', $version);
$build = explode('.', $build);
}
if (false !== strpos($version, '-')) {
list($version, $pre) = explode('-', $version);
$pre = explode('.', $pre);
}
list(
$major,
$minor,
$patch
) = explode('.', $version);
return array(
self::MAJOR => intval($major),
self::MINOR => intval($minor),
self::PATCH => intval($patch),
self::PRE_RELEASE => isset($pre) ? $pre : array(),
self::BUILD => isset($build) ? $build : array(),
);
} | [
"public",
"static",
"function",
"toComponents",
"(",
"$",
"version",
")",
"{",
"if",
"(",
"!",
"Validator",
"::",
"isVersion",
"(",
"$",
"version",
")",
")",
"{",
"throw",
"new",
"InvalidStringRepresentationException",
"(",
"$",
"version",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"version",
",",
"'+'",
")",
")",
"{",
"list",
"(",
"$",
"version",
",",
"$",
"build",
")",
"=",
"explode",
"(",
"'+'",
",",
"$",
"version",
")",
";",
"$",
"build",
"=",
"explode",
"(",
"'.'",
",",
"$",
"build",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"version",
",",
"'-'",
")",
")",
"{",
"list",
"(",
"$",
"version",
",",
"$",
"pre",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"version",
")",
";",
"$",
"pre",
"=",
"explode",
"(",
"'.'",
",",
"$",
"pre",
")",
";",
"}",
"list",
"(",
"$",
"major",
",",
"$",
"minor",
",",
"$",
"patch",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"version",
")",
";",
"return",
"array",
"(",
"self",
"::",
"MAJOR",
"=>",
"intval",
"(",
"$",
"major",
")",
",",
"self",
"::",
"MINOR",
"=>",
"intval",
"(",
"$",
"minor",
")",
",",
"self",
"::",
"PATCH",
"=>",
"intval",
"(",
"$",
"patch",
")",
",",
"self",
"::",
"PRE_RELEASE",
"=>",
"isset",
"(",
"$",
"pre",
")",
"?",
"$",
"pre",
":",
"array",
"(",
")",
",",
"self",
"::",
"BUILD",
"=>",
"isset",
"(",
"$",
"build",
")",
"?",
"$",
"build",
":",
"array",
"(",
")",
",",
")",
";",
"}"
] | Returns the components of the string representation.
@param string $version The string representation.
@return array The components of the version.
@throws InvalidStringRepresentationException If the string representation
is invalid. | [
"Returns",
"the",
"components",
"of",
"the",
"string",
"representation",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Parser.php#L63-L94 |
deployphp/phar-update | src/Version/Parser.php | Parser.toVersion | public static function toVersion($version)
{
$components = self::toComponents($version);
return new Version(
$components['major'],
$components['minor'],
$components['patch'],
$components['pre'],
$components['build']
);
} | php | public static function toVersion($version)
{
$components = self::toComponents($version);
return new Version(
$components['major'],
$components['minor'],
$components['patch'],
$components['pre'],
$components['build']
);
} | [
"public",
"static",
"function",
"toVersion",
"(",
"$",
"version",
")",
"{",
"$",
"components",
"=",
"self",
"::",
"toComponents",
"(",
"$",
"version",
")",
";",
"return",
"new",
"Version",
"(",
"$",
"components",
"[",
"'major'",
"]",
",",
"$",
"components",
"[",
"'minor'",
"]",
",",
"$",
"components",
"[",
"'patch'",
"]",
",",
"$",
"components",
"[",
"'pre'",
"]",
",",
"$",
"components",
"[",
"'build'",
"]",
")",
";",
"}"
] | Returns a Version instance for the string representation.
@param string $version The string representation.
@return Version A Version instance. | [
"Returns",
"a",
"Version",
"instance",
"for",
"the",
"string",
"representation",
"."
] | train | https://github.com/deployphp/phar-update/blob/a6c7c3a1b2eb6983ebeb59cd1dc1c2e9df115c4a/src/Version/Parser.php#L103-L114 |
tightenco/nova-google-analytics | src/PageViewsMetric.php | PageViewsMetric.calculate | public function calculate(Request $request)
{
$lookups = [
1 => $this->pageViewsOneDay(),
'MTD' => $this->pageViewsOneMonth(),
'YTD' => $this->pageViewsOneYear(),
];
$data = array_get($lookups, $request->get('range'), ['result' => 0, 'previous' => 0]);
return $this
->result($data['result'])
->previous($data['previous']);
} | php | public function calculate(Request $request)
{
$lookups = [
1 => $this->pageViewsOneDay(),
'MTD' => $this->pageViewsOneMonth(),
'YTD' => $this->pageViewsOneYear(),
];
$data = array_get($lookups, $request->get('range'), ['result' => 0, 'previous' => 0]);
return $this
->result($data['result'])
->previous($data['previous']);
} | [
"public",
"function",
"calculate",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"lookups",
"=",
"[",
"1",
"=>",
"$",
"this",
"->",
"pageViewsOneDay",
"(",
")",
",",
"'MTD'",
"=>",
"$",
"this",
"->",
"pageViewsOneMonth",
"(",
")",
",",
"'YTD'",
"=>",
"$",
"this",
"->",
"pageViewsOneYear",
"(",
")",
",",
"]",
";",
"$",
"data",
"=",
"array_get",
"(",
"$",
"lookups",
",",
"$",
"request",
"->",
"get",
"(",
"'range'",
")",
",",
"[",
"'result'",
"=>",
"0",
",",
"'previous'",
"=>",
"0",
"]",
")",
";",
"return",
"$",
"this",
"->",
"result",
"(",
"$",
"data",
"[",
"'result'",
"]",
")",
"->",
"previous",
"(",
"$",
"data",
"[",
"'previous'",
"]",
")",
";",
"}"
] | Calculate the value of the metric.
@param \Illuminate\Http\Request $request
@return mixed | [
"Calculate",
"the",
"value",
"of",
"the",
"metric",
"."
] | train | https://github.com/tightenco/nova-google-analytics/blob/f1c31d0aab3493f01f2bb06e1a35de44deeffd12/src/PageViewsMetric.php#L21-L34 |
tightenco/nova-google-analytics | src/VisitorsMetric.php | VisitorsMetric.calculate | public function calculate(Request $request)
{
$lookups = [
1 => $this->visitorsOneDay(),
'MTD' => $this->visitorsOneMonth(),
'YTD' => $this->visitorsOneYear(),
];
$data = array_get($lookups, $request->get('range'), ['result' => 0, 'previous' => 0]);
return $this
->result($data['result'])
->previous($data['previous']);
} | php | public function calculate(Request $request)
{
$lookups = [
1 => $this->visitorsOneDay(),
'MTD' => $this->visitorsOneMonth(),
'YTD' => $this->visitorsOneYear(),
];
$data = array_get($lookups, $request->get('range'), ['result' => 0, 'previous' => 0]);
return $this
->result($data['result'])
->previous($data['previous']);
} | [
"public",
"function",
"calculate",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"lookups",
"=",
"[",
"1",
"=>",
"$",
"this",
"->",
"visitorsOneDay",
"(",
")",
",",
"'MTD'",
"=>",
"$",
"this",
"->",
"visitorsOneMonth",
"(",
")",
",",
"'YTD'",
"=>",
"$",
"this",
"->",
"visitorsOneYear",
"(",
")",
",",
"]",
";",
"$",
"data",
"=",
"array_get",
"(",
"$",
"lookups",
",",
"$",
"request",
"->",
"get",
"(",
"'range'",
")",
",",
"[",
"'result'",
"=>",
"0",
",",
"'previous'",
"=>",
"0",
"]",
")",
";",
"return",
"$",
"this",
"->",
"result",
"(",
"$",
"data",
"[",
"'result'",
"]",
")",
"->",
"previous",
"(",
"$",
"data",
"[",
"'previous'",
"]",
")",
";",
"}"
] | Calculate the value of the metric.
@param \Illuminate\Http\Request $request
@return mixed | [
"Calculate",
"the",
"value",
"of",
"the",
"metric",
"."
] | train | https://github.com/tightenco/nova-google-analytics/blob/f1c31d0aab3493f01f2bb06e1a35de44deeffd12/src/VisitorsMetric.php#L21-L34 |
dvaknheo/DNMVCS | src/Basic/SuperGlobal.php | SuperGlobal.& | public function &_GLOBALS($k, $v=null)
{
if (!isset($this->GLOBALS[$k])) {
$this->GLOBALS[$k]=$v;
}
return $this->GLOBALS[$k];
} | php | public function &_GLOBALS($k, $v=null)
{
if (!isset($this->GLOBALS[$k])) {
$this->GLOBALS[$k]=$v;
}
return $this->GLOBALS[$k];
} | [
"public",
"function",
"&",
"_GLOBALS",
"(",
"$",
"k",
",",
"$",
"v",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"GLOBALS",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"this",
"->",
"GLOBALS",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"this",
"->",
"GLOBALS",
"[",
"$",
"k",
"]",
";",
"}"
] | ///////////////////////////// | [
"/////////////////////////////"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Basic/SuperGlobal.php#L67-L73 |
dvaknheo/DNMVCS | src/Ext/RouteHookDirectoryMode.php | RouteHookDirectoryMode.hook | public function hook($route)
{
$route->setURLHandler([$this,'onURL']); //todo once ?
$route->path_info=$this->adjustPathinfo($route->path_info, $route->document_root);
$route->calling_path=$route->path_info;
} | php | public function hook($route)
{
$route->setURLHandler([$this,'onURL']); //todo once ?
$route->path_info=$this->adjustPathinfo($route->path_info, $route->document_root);
$route->calling_path=$route->path_info;
} | [
"public",
"function",
"hook",
"(",
"$",
"route",
")",
"{",
"$",
"route",
"->",
"setURLHandler",
"(",
"[",
"$",
"this",
",",
"'onURL'",
"]",
")",
";",
"//todo once ?",
"$",
"route",
"->",
"path_info",
"=",
"$",
"this",
"->",
"adjustPathinfo",
"(",
"$",
"route",
"->",
"path_info",
",",
"$",
"route",
"->",
"document_root",
")",
";",
"$",
"route",
"->",
"calling_path",
"=",
"$",
"route",
"->",
"path_info",
";",
"}"
] | abc/d/e.php/g/h?act=z abc/d/e/g | [
"abc",
"/",
"d",
"/",
"e",
".",
"php",
"/",
"g",
"/",
"h?act",
"=",
"z",
"abc",
"/",
"d",
"/",
"e",
"/",
"g"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Ext/RouteHookDirectoryMode.php#L94-L100 |
dvaknheo/DNMVCS | src/Base/Pager.php | Pager.init | public function init($options=[], $context=null)
{
$this->url=$options['url']??static::SG()->_SERVER['REQUEST_URI'];
$this->key=$options['key']??$this->key;
$this->page_size=$options['page_size']??$this->page_size;
$this->handel_get_url=$options['rewrite']??$this->handel_get_url;
$this->current_page=$options['current']??intval(static::SG()->_GET[$this->key]??1);
$this->current_page=$this->current_page>1?$this->current_page:1;
} | php | public function init($options=[], $context=null)
{
$this->url=$options['url']??static::SG()->_SERVER['REQUEST_URI'];
$this->key=$options['key']??$this->key;
$this->page_size=$options['page_size']??$this->page_size;
$this->handel_get_url=$options['rewrite']??$this->handel_get_url;
$this->current_page=$options['current']??intval(static::SG()->_GET[$this->key]??1);
$this->current_page=$this->current_page>1?$this->current_page:1;
} | [
"public",
"function",
"init",
"(",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"$",
"options",
"[",
"'url'",
"]",
"??",
"static",
"::",
"SG",
"(",
")",
"->",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"$",
"this",
"->",
"key",
"=",
"$",
"options",
"[",
"'key'",
"]",
"??",
"$",
"this",
"->",
"key",
";",
"$",
"this",
"->",
"page_size",
"=",
"$",
"options",
"[",
"'page_size'",
"]",
"??",
"$",
"this",
"->",
"page_size",
";",
"$",
"this",
"->",
"handel_get_url",
"=",
"$",
"options",
"[",
"'rewrite'",
"]",
"??",
"$",
"this",
"->",
"handel_get_url",
";",
"$",
"this",
"->",
"current_page",
"=",
"$",
"options",
"[",
"'current'",
"]",
"??",
"intval",
"(",
"static",
"::",
"SG",
"(",
")",
"->",
"_GET",
"[",
"$",
"this",
"->",
"key",
"]",
"??",
"1",
")",
";",
"$",
"this",
"->",
"current_page",
"=",
"$",
"this",
"->",
"current_page",
">",
"1",
"?",
"$",
"this",
"->",
"current_page",
":",
"1",
";",
"}"
] | options: url, key,rewrite,current | [
"options",
":",
"url",
"key",
"rewrite",
"current"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Base/Pager.php#L48-L58 |
dvaknheo/DNMVCS | src/SwooleHttpd/SwooleHttpd.php | SwooleHttpd.checkOverride | protected function checkOverride($options)
{
if ($this->skip_override) {
return null;
}
$base_class=isset($options['base_class'])?$options['base_class']:self::DEFAULT_OPTIONS['base_class'];
$base_class=ltrim($base_class, '\\');
if (!$base_class || !class_exists($base_class)) {
return null;
}
if (static::class===$base_class) {
return null;
}
return static::G($base_class::G());
} | php | protected function checkOverride($options)
{
if ($this->skip_override) {
return null;
}
$base_class=isset($options['base_class'])?$options['base_class']:self::DEFAULT_OPTIONS['base_class'];
$base_class=ltrim($base_class, '\\');
if (!$base_class || !class_exists($base_class)) {
return null;
}
if (static::class===$base_class) {
return null;
}
return static::G($base_class::G());
} | [
"protected",
"function",
"checkOverride",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"skip_override",
")",
"{",
"return",
"null",
";",
"}",
"$",
"base_class",
"=",
"isset",
"(",
"$",
"options",
"[",
"'base_class'",
"]",
")",
"?",
"$",
"options",
"[",
"'base_class'",
"]",
":",
"self",
"::",
"DEFAULT_OPTIONS",
"[",
"'base_class'",
"]",
";",
"$",
"base_class",
"=",
"ltrim",
"(",
"$",
"base_class",
",",
"'\\\\'",
")",
";",
"if",
"(",
"!",
"$",
"base_class",
"||",
"!",
"class_exists",
"(",
"$",
"base_class",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"static",
"::",
"class",
"===",
"$",
"base_class",
")",
"{",
"return",
"null",
";",
"}",
"return",
"static",
"::",
"G",
"(",
"$",
"base_class",
"::",
"G",
"(",
")",
")",
";",
"}"
] | /////////////////////// | [
"///////////////////////"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/SwooleHttpd/SwooleHttpd.php#L296-L311 |
dvaknheo/DNMVCS | src/InnerExt/DIExt.php | DIExt.init | public function init($options=[], $context=null)
{
if ($context) {
$this->initContext($options, $context);
}
return $this;
} | php | public function init($options=[], $context=null)
{
if ($context) {
$this->initContext($options, $context);
}
return $this;
} | [
"public",
"function",
"init",
"(",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"context",
")",
"{",
"$",
"this",
"->",
"initContext",
"(",
"$",
"options",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | ////////// | [
"//////////"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/InnerExt/DIExt.php#L24-L30 |
dvaknheo/DNMVCS | src/DNMVCS.php | DNMVCS_Misc._Import | public function _Import($file)
{
if ($this->path_lib===null) {
$this->path_lib=$this->path.rtrim($this->options['path_lib'], '/').'/';
}
$file=rtrim($file, '.php').'.php';
require_once($this->path_lib.$file);
} | php | public function _Import($file)
{
if ($this->path_lib===null) {
$this->path_lib=$this->path.rtrim($this->options['path_lib'], '/').'/';
}
$file=rtrim($file, '.php').'.php';
require_once($this->path_lib.$file);
} | [
"public",
"function",
"_Import",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"path_lib",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"path_lib",
"=",
"$",
"this",
"->",
"path",
".",
"rtrim",
"(",
"$",
"this",
"->",
"options",
"[",
"'path_lib'",
"]",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"$",
"file",
"=",
"rtrim",
"(",
"$",
"file",
",",
"'.php'",
")",
".",
"'.php'",
";",
"require_once",
"(",
"$",
"this",
"->",
"path_lib",
".",
"$",
"file",
")",
";",
"}"
] | /////////////////// | [
"///////////////////"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/DNMVCS.php#L286-L293 |
dvaknheo/DNMVCS | src/DNMVCS.php | DNMVCS.RunWithoutPathInfo | public static function RunWithoutPathInfo($options=[])
{
$default_options=[
'ext'=>[
'Ext\RouteHookOneFileMode'=>[
'mode_onefile'=>true,
'mode_onefile_key_for_action'=>'_',
],
],
];
$options=array_replace_recursive($default_options, $options);
return static::G()->init($options)->run();
} | php | public static function RunWithoutPathInfo($options=[])
{
$default_options=[
'ext'=>[
'Ext\RouteHookOneFileMode'=>[
'mode_onefile'=>true,
'mode_onefile_key_for_action'=>'_',
],
],
];
$options=array_replace_recursive($default_options, $options);
return static::G()->init($options)->run();
} | [
"public",
"static",
"function",
"RunWithoutPathInfo",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"default_options",
"=",
"[",
"'ext'",
"=>",
"[",
"'Ext\\RouteHookOneFileMode'",
"=>",
"[",
"'mode_onefile'",
"=>",
"true",
",",
"'mode_onefile_key_for_action'",
"=>",
"'_'",
",",
"]",
",",
"]",
",",
"]",
";",
"$",
"options",
"=",
"array_replace_recursive",
"(",
"$",
"default_options",
",",
"$",
"options",
")",
";",
"return",
"static",
"::",
"G",
"(",
")",
"->",
"init",
"(",
"$",
"options",
")",
"->",
"run",
"(",
")",
";",
"}"
] | // RunMode | [
"//",
"RunMode"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/DNMVCS.php#L62-L74 |
dvaknheo/DNMVCS | src/SwooleHttpd/SwooleCoroutineSingleton.php | SwooleCoroutineSingleton._DumpString | public function _DumpString()
{
$cid = \Swoole\Coroutine::getuid();
$ret="==== SwooleCoroutineSingleton List Current cid [{$cid}] ==== ;\n";
foreach (self::$_instances as $cid=>$v) {
foreach ($v as $cid_class=>$object) {
$hash=$object?md5(spl_object_hash($object)):'';
$class=$object?get_class($object):'';
$class=$cid_class===$class?'':$class;
$ret.="[$hash]$cid $cid_class($class)\n";
}
}
return "{{$ret}}\n";
} | php | public function _DumpString()
{
$cid = \Swoole\Coroutine::getuid();
$ret="==== SwooleCoroutineSingleton List Current cid [{$cid}] ==== ;\n";
foreach (self::$_instances as $cid=>$v) {
foreach ($v as $cid_class=>$object) {
$hash=$object?md5(spl_object_hash($object)):'';
$class=$object?get_class($object):'';
$class=$cid_class===$class?'':$class;
$ret.="[$hash]$cid $cid_class($class)\n";
}
}
return "{{$ret}}\n";
} | [
"public",
"function",
"_DumpString",
"(",
")",
"{",
"$",
"cid",
"=",
"\\",
"Swoole",
"\\",
"Coroutine",
"::",
"getuid",
"(",
")",
";",
"$",
"ret",
"=",
"\"==== SwooleCoroutineSingleton List Current cid [{$cid}] ==== ;\\n\"",
";",
"foreach",
"(",
"self",
"::",
"$",
"_instances",
"as",
"$",
"cid",
"=>",
"$",
"v",
")",
"{",
"foreach",
"(",
"$",
"v",
"as",
"$",
"cid_class",
"=>",
"$",
"object",
")",
"{",
"$",
"hash",
"=",
"$",
"object",
"?",
"md5",
"(",
"spl_object_hash",
"(",
"$",
"object",
")",
")",
":",
"''",
";",
"$",
"class",
"=",
"$",
"object",
"?",
"get_class",
"(",
"$",
"object",
")",
":",
"''",
";",
"$",
"class",
"=",
"$",
"cid_class",
"===",
"$",
"class",
"?",
"''",
":",
"$",
"class",
";",
"$",
"ret",
".=",
"\"[$hash]$cid $cid_class($class)\\n\"",
";",
"}",
"}",
"return",
"\"{{$ret}}\\n\"",
";",
"}"
] | ///////////////////// | [
"/////////////////////"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/SwooleHttpd/SwooleCoroutineSingleton.php#L134-L147 |
dvaknheo/DNMVCS | src/InnerExt/StrictCheck.php | StrictCheck.getCallerByLevel | protected function getCallerByLevel($level)
{
$level+=1;
$backtrace=debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, static::MAX_TRACE_LEVEL);
$caller_class=$backtrace[$level]['class']??'';
if ($this->dn_class && (is_subclass_of($this->dn_class, $caller_class) || $this->dn_class===$caller_class)) {
$caller_class=$backtrace[$level+1]['class']??'';
}
return $caller_class;
} | php | protected function getCallerByLevel($level)
{
$level+=1;
$backtrace=debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, static::MAX_TRACE_LEVEL);
$caller_class=$backtrace[$level]['class']??'';
if ($this->dn_class && (is_subclass_of($this->dn_class, $caller_class) || $this->dn_class===$caller_class)) {
$caller_class=$backtrace[$level+1]['class']??'';
}
return $caller_class;
} | [
"protected",
"function",
"getCallerByLevel",
"(",
"$",
"level",
")",
"{",
"$",
"level",
"+=",
"1",
";",
"$",
"backtrace",
"=",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
",",
"static",
"::",
"MAX_TRACE_LEVEL",
")",
";",
"$",
"caller_class",
"=",
"$",
"backtrace",
"[",
"$",
"level",
"]",
"[",
"'class'",
"]",
"??",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"dn_class",
"&&",
"(",
"is_subclass_of",
"(",
"$",
"this",
"->",
"dn_class",
",",
"$",
"caller_class",
")",
"||",
"$",
"this",
"->",
"dn_class",
"===",
"$",
"caller_class",
")",
")",
"{",
"$",
"caller_class",
"=",
"$",
"backtrace",
"[",
"$",
"level",
"+",
"1",
"]",
"[",
"'class'",
"]",
"??",
"''",
";",
"}",
"return",
"$",
"caller_class",
";",
"}"
] | ///////////////////////////////////////////////////////// | [
"/////////////////////////////////////////////////////////"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/InnerExt/StrictCheck.php#L29-L40 |
dvaknheo/DNMVCS | src/Core/App.php | Core_Redirect._ExitJson | public function _ExitJson($ret)
{
static::header('Content-Type:text/json');
$flag= JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK;
if ($this->is_debug) {
$flag=$flag | JSON_PRETTY_PRINT;
}
echo json_encode($ret, $flag);
static::exit_system();
} | php | public function _ExitJson($ret)
{
static::header('Content-Type:text/json');
$flag= JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK;
if ($this->is_debug) {
$flag=$flag | JSON_PRETTY_PRINT;
}
echo json_encode($ret, $flag);
static::exit_system();
} | [
"public",
"function",
"_ExitJson",
"(",
"$",
"ret",
")",
"{",
"static",
"::",
"header",
"(",
"'Content-Type:text/json'",
")",
";",
"$",
"flag",
"=",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_NUMERIC_CHECK",
";",
"if",
"(",
"$",
"this",
"->",
"is_debug",
")",
"{",
"$",
"flag",
"=",
"$",
"flag",
"|",
"JSON_PRETTY_PRINT",
";",
"}",
"echo",
"json_encode",
"(",
"$",
"ret",
",",
"$",
"flag",
")",
";",
"static",
"::",
"exit_system",
"(",
")",
";",
"}"
] | // | [
"//"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Core/App.php#L460-L470 |
dvaknheo/DNMVCS | src/Core/App.php | Core_Helper._Show | public function _Show($data=[], $view=null)
{
$view=$view??Route::G()->getRouteCallingPath();
foreach ($this->beforeShowHandlers as $v) {
($v)();
}
$this->is_before_show_done=true;
if ($this->options['skip_view_notice_error']) {
RuntimeState::G()->skipNoticeError();
}
return View::G()->_Show($data, $view);
} | php | public function _Show($data=[], $view=null)
{
$view=$view??Route::G()->getRouteCallingPath();
foreach ($this->beforeShowHandlers as $v) {
($v)();
}
$this->is_before_show_done=true;
if ($this->options['skip_view_notice_error']) {
RuntimeState::G()->skipNoticeError();
}
return View::G()->_Show($data, $view);
} | [
"public",
"function",
"_Show",
"(",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"view",
"=",
"null",
")",
"{",
"$",
"view",
"=",
"$",
"view",
"??",
"Route",
"::",
"G",
"(",
")",
"->",
"getRouteCallingPath",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"beforeShowHandlers",
"as",
"$",
"v",
")",
"{",
"(",
"$",
"v",
")",
"(",
")",
";",
"}",
"$",
"this",
"->",
"is_before_show_done",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'skip_view_notice_error'",
"]",
")",
"{",
"RuntimeState",
"::",
"G",
"(",
")",
"->",
"skipNoticeError",
"(",
")",
";",
"}",
"return",
"View",
"::",
"G",
"(",
")",
"->",
"_Show",
"(",
"$",
"data",
",",
"$",
"view",
")",
";",
"}"
] | // | [
"//"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Core/App.php#L511-L522 |
dvaknheo/DNMVCS | src/Core/App.php | Core_Glue.addRouteHook | public function addRouteHook($hook, $prepend=false, $once=true)
{
return Route::G()->addRouteHook($hook, $prepend, $once);
} | php | public function addRouteHook($hook, $prepend=false, $once=true)
{
return Route::G()->addRouteHook($hook, $prepend, $once);
} | [
"public",
"function",
"addRouteHook",
"(",
"$",
"hook",
",",
"$",
"prepend",
"=",
"false",
",",
"$",
"once",
"=",
"true",
")",
"{",
"return",
"Route",
"::",
"G",
"(",
")",
"->",
"addRouteHook",
"(",
"$",
"hook",
",",
"$",
"prepend",
",",
"$",
"once",
")",
";",
"}"
] | route | [
"route"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Core/App.php#L619-L622 |
dvaknheo/DNMVCS | src/Core/App.php | Core_Glue.setViewWrapper | public function setViewWrapper($head_file=null, $foot_file=null)
{
return View::G()->setViewWrapper($head_file, $foot_file);
} | php | public function setViewWrapper($head_file=null, $foot_file=null)
{
return View::G()->setViewWrapper($head_file, $foot_file);
} | [
"public",
"function",
"setViewWrapper",
"(",
"$",
"head_file",
"=",
"null",
",",
"$",
"foot_file",
"=",
"null",
")",
"{",
"return",
"View",
"::",
"G",
"(",
")",
"->",
"setViewWrapper",
"(",
"$",
"head_file",
",",
"$",
"foot_file",
")",
";",
"}"
] | view | [
"view"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Core/App.php#L637-L640 |
dvaknheo/DNMVCS | src/Ext/Lazybones.php | Lazybones.runRoute | public function runRoute()
{
$path_info=Route::G()->path_info;
$enable_paramters=Route::G()->controller_enable_paramters;
$class_blocks=explode('/', $path_info);
$method=array_pop($class_blocks);
$class_path=implode('/', $class_blocks);
$full_class=$this->getFullClassByNoNameSpace($class_path);
$callback=Route::G()->getCallback($full_class, $method);
if ($callback) {
return $callback;
}
if (!$enable_paramters) {
return null;
}
list($full_class, $the_method, $parameters, $calling_path)=$this->getRouteDispatchInfo($class_blocks, $method);
if (!$full_class) {
return null;
}
$method=$the_method;
Route::G()->parameters=$parameters;
Route::G()->calling_path=$calling_path;
return Route::G()->getCallback($full_class, $method);
} | php | public function runRoute()
{
$path_info=Route::G()->path_info;
$enable_paramters=Route::G()->controller_enable_paramters;
$class_blocks=explode('/', $path_info);
$method=array_pop($class_blocks);
$class_path=implode('/', $class_blocks);
$full_class=$this->getFullClassByNoNameSpace($class_path);
$callback=Route::G()->getCallback($full_class, $method);
if ($callback) {
return $callback;
}
if (!$enable_paramters) {
return null;
}
list($full_class, $the_method, $parameters, $calling_path)=$this->getRouteDispatchInfo($class_blocks, $method);
if (!$full_class) {
return null;
}
$method=$the_method;
Route::G()->parameters=$parameters;
Route::G()->calling_path=$calling_path;
return Route::G()->getCallback($full_class, $method);
} | [
"public",
"function",
"runRoute",
"(",
")",
"{",
"$",
"path_info",
"=",
"Route",
"::",
"G",
"(",
")",
"->",
"path_info",
";",
"$",
"enable_paramters",
"=",
"Route",
"::",
"G",
"(",
")",
"->",
"controller_enable_paramters",
";",
"$",
"class_blocks",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path_info",
")",
";",
"$",
"method",
"=",
"array_pop",
"(",
"$",
"class_blocks",
")",
";",
"$",
"class_path",
"=",
"implode",
"(",
"'/'",
",",
"$",
"class_blocks",
")",
";",
"$",
"full_class",
"=",
"$",
"this",
"->",
"getFullClassByNoNameSpace",
"(",
"$",
"class_path",
")",
";",
"$",
"callback",
"=",
"Route",
"::",
"G",
"(",
")",
"->",
"getCallback",
"(",
"$",
"full_class",
",",
"$",
"method",
")",
";",
"if",
"(",
"$",
"callback",
")",
"{",
"return",
"$",
"callback",
";",
"}",
"if",
"(",
"!",
"$",
"enable_paramters",
")",
"{",
"return",
"null",
";",
"}",
"list",
"(",
"$",
"full_class",
",",
"$",
"the_method",
",",
"$",
"parameters",
",",
"$",
"calling_path",
")",
"=",
"$",
"this",
"->",
"getRouteDispatchInfo",
"(",
"$",
"class_blocks",
",",
"$",
"method",
")",
";",
"if",
"(",
"!",
"$",
"full_class",
")",
"{",
"return",
"null",
";",
"}",
"$",
"method",
"=",
"$",
"the_method",
";",
"Route",
"::",
"G",
"(",
")",
"->",
"parameters",
"=",
"$",
"parameters",
";",
"Route",
"::",
"G",
"(",
")",
"->",
"calling_path",
"=",
"$",
"calling_path",
";",
"return",
"Route",
"::",
"G",
"(",
")",
"->",
"getCallback",
"(",
"$",
"full_class",
",",
"$",
"method",
")",
";",
"}"
] | // | [
"//"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Ext/Lazybones.php#L84-L109 |
dvaknheo/DNMVCS | src/Ext/Lazybones.php | Lazybones.checkLoadClass | protected function checkLoadClass($path_class)
{
$namespace_controller=Route::G()->namespace_controller;
$path_class_simple=str_replace('/', '__', $path_class);
$class=($this->lazy_controller_class)?$this->lazy_controller_class:'';
if (class_exists($class)) {
return $class;
}
$class=$this->lazy_class_prefix.$path_class_simple;
if (class_exists($class)) {
return $class;
}
$class=($this->lazy_controller_class)?$namespace_controller.'\\'.$this->lazy_controller_class:'';
if (class_exists($class)) {
return $class;
}
$class=($this->lazy_controller_class)?$namespace_controller.'\\'.$path_class_simple:'';
if (class_exists($class)) {
return $class;
}
return null;
} | php | protected function checkLoadClass($path_class)
{
$namespace_controller=Route::G()->namespace_controller;
$path_class_simple=str_replace('/', '__', $path_class);
$class=($this->lazy_controller_class)?$this->lazy_controller_class:'';
if (class_exists($class)) {
return $class;
}
$class=$this->lazy_class_prefix.$path_class_simple;
if (class_exists($class)) {
return $class;
}
$class=($this->lazy_controller_class)?$namespace_controller.'\\'.$this->lazy_controller_class:'';
if (class_exists($class)) {
return $class;
}
$class=($this->lazy_controller_class)?$namespace_controller.'\\'.$path_class_simple:'';
if (class_exists($class)) {
return $class;
}
return null;
} | [
"protected",
"function",
"checkLoadClass",
"(",
"$",
"path_class",
")",
"{",
"$",
"namespace_controller",
"=",
"Route",
"::",
"G",
"(",
")",
"->",
"namespace_controller",
";",
"$",
"path_class_simple",
"=",
"str_replace",
"(",
"'/'",
",",
"'__'",
",",
"$",
"path_class",
")",
";",
"$",
"class",
"=",
"(",
"$",
"this",
"->",
"lazy_controller_class",
")",
"?",
"$",
"this",
"->",
"lazy_controller_class",
":",
"''",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"lazy_class_prefix",
".",
"$",
"path_class_simple",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"$",
"class",
"=",
"(",
"$",
"this",
"->",
"lazy_controller_class",
")",
"?",
"$",
"namespace_controller",
".",
"'\\\\'",
".",
"$",
"this",
"->",
"lazy_controller_class",
":",
"''",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"$",
"class",
"=",
"(",
"$",
"this",
"->",
"lazy_controller_class",
")",
"?",
"$",
"namespace_controller",
".",
"'\\\\'",
".",
"$",
"path_class_simple",
":",
"''",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"return",
"null",
";",
"}"
] | MyProject\Controller\AA__BB__CC | [
"MyProject",
"\\",
"Controller",
"\\",
"AA__BB__CC"
] | train | https://github.com/dvaknheo/DNMVCS/blob/b0f81796bff33677c8c4797300de2726eeba4b2f/src/Ext/Lazybones.php#L159-L182 |
tuupola/cors-middleware | src/CorsMiddleware.php | CorsMiddleware.process | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = (new ResponseFactory)->createResponse();
$analyzer = CorsAnalyzer::instance($this->buildSettings($request, $response));
if ($this->logger) {
$analyzer->setLogger($this->logger);
}
$cors = $analyzer->analyze($request);
switch ($cors->getRequestType()) {
case CorsAnalysisResultInterface::ERR_ORIGIN_NOT_ALLOWED:
$response = $response->withStatus(401);
return $this->processError($request, $response, [
"message" => "CORS request origin is not allowed.",
]);
case CorsAnalysisResultInterface::ERR_METHOD_NOT_SUPPORTED:
$response = $response->withStatus(401);
return $this->processError($request, $response, [
"message" => "CORS requested method is not supported.",
]);
case CorsAnalysisResultInterface::ERR_HEADERS_NOT_SUPPORTED:
$response = $response->withStatus(401);
return $this->processError($request, $response, [
"message" => "CORS requested header is not allowed.",
]);
case CorsAnalysisResultInterface::TYPE_PRE_FLIGHT_REQUEST:
$cors_headers = $cors->getResponseHeaders();
foreach ($cors_headers as $header => $value) {
/* Diactoros errors on integer values. */
if (false === is_array($value)) {
$value = (string)$value;
}
$response = $response->withHeader($header, $value);
}
return $response->withStatus(200);
case CorsAnalysisResultInterface::TYPE_REQUEST_OUT_OF_CORS_SCOPE:
return $handler->handle($request);
default:
/* Actual CORS request. */
$response = $handler->handle($request);
$cors_headers = $cors->getResponseHeaders();
foreach ($cors_headers as $header => $value) {
/* Diactoros errors on integer values. */
if (false === is_array($value)) {
$value = (string)$value;
}
$response = $response->withHeader($header, $value);
}
return $response;
}
} | php | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = (new ResponseFactory)->createResponse();
$analyzer = CorsAnalyzer::instance($this->buildSettings($request, $response));
if ($this->logger) {
$analyzer->setLogger($this->logger);
}
$cors = $analyzer->analyze($request);
switch ($cors->getRequestType()) {
case CorsAnalysisResultInterface::ERR_ORIGIN_NOT_ALLOWED:
$response = $response->withStatus(401);
return $this->processError($request, $response, [
"message" => "CORS request origin is not allowed.",
]);
case CorsAnalysisResultInterface::ERR_METHOD_NOT_SUPPORTED:
$response = $response->withStatus(401);
return $this->processError($request, $response, [
"message" => "CORS requested method is not supported.",
]);
case CorsAnalysisResultInterface::ERR_HEADERS_NOT_SUPPORTED:
$response = $response->withStatus(401);
return $this->processError($request, $response, [
"message" => "CORS requested header is not allowed.",
]);
case CorsAnalysisResultInterface::TYPE_PRE_FLIGHT_REQUEST:
$cors_headers = $cors->getResponseHeaders();
foreach ($cors_headers as $header => $value) {
/* Diactoros errors on integer values. */
if (false === is_array($value)) {
$value = (string)$value;
}
$response = $response->withHeader($header, $value);
}
return $response->withStatus(200);
case CorsAnalysisResultInterface::TYPE_REQUEST_OUT_OF_CORS_SCOPE:
return $handler->handle($request);
default:
/* Actual CORS request. */
$response = $handler->handle($request);
$cors_headers = $cors->getResponseHeaders();
foreach ($cors_headers as $header => $value) {
/* Diactoros errors on integer values. */
if (false === is_array($value)) {
$value = (string)$value;
}
$response = $response->withHeader($header, $value);
}
return $response;
}
} | [
"public",
"function",
"process",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"RequestHandlerInterface",
"$",
"handler",
")",
":",
"ResponseInterface",
"{",
"$",
"response",
"=",
"(",
"new",
"ResponseFactory",
")",
"->",
"createResponse",
"(",
")",
";",
"$",
"analyzer",
"=",
"CorsAnalyzer",
"::",
"instance",
"(",
"$",
"this",
"->",
"buildSettings",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"analyzer",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"$",
"cors",
"=",
"$",
"analyzer",
"->",
"analyze",
"(",
"$",
"request",
")",
";",
"switch",
"(",
"$",
"cors",
"->",
"getRequestType",
"(",
")",
")",
"{",
"case",
"CorsAnalysisResultInterface",
"::",
"ERR_ORIGIN_NOT_ALLOWED",
":",
"$",
"response",
"=",
"$",
"response",
"->",
"withStatus",
"(",
"401",
")",
";",
"return",
"$",
"this",
"->",
"processError",
"(",
"$",
"request",
",",
"$",
"response",
",",
"[",
"\"message\"",
"=>",
"\"CORS request origin is not allowed.\"",
",",
"]",
")",
";",
"case",
"CorsAnalysisResultInterface",
"::",
"ERR_METHOD_NOT_SUPPORTED",
":",
"$",
"response",
"=",
"$",
"response",
"->",
"withStatus",
"(",
"401",
")",
";",
"return",
"$",
"this",
"->",
"processError",
"(",
"$",
"request",
",",
"$",
"response",
",",
"[",
"\"message\"",
"=>",
"\"CORS requested method is not supported.\"",
",",
"]",
")",
";",
"case",
"CorsAnalysisResultInterface",
"::",
"ERR_HEADERS_NOT_SUPPORTED",
":",
"$",
"response",
"=",
"$",
"response",
"->",
"withStatus",
"(",
"401",
")",
";",
"return",
"$",
"this",
"->",
"processError",
"(",
"$",
"request",
",",
"$",
"response",
",",
"[",
"\"message\"",
"=>",
"\"CORS requested header is not allowed.\"",
",",
"]",
")",
";",
"case",
"CorsAnalysisResultInterface",
"::",
"TYPE_PRE_FLIGHT_REQUEST",
":",
"$",
"cors_headers",
"=",
"$",
"cors",
"->",
"getResponseHeaders",
"(",
")",
";",
"foreach",
"(",
"$",
"cors_headers",
"as",
"$",
"header",
"=>",
"$",
"value",
")",
"{",
"/* Diactoros errors on integer values. */",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"$",
"header",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"response",
"->",
"withStatus",
"(",
"200",
")",
";",
"case",
"CorsAnalysisResultInterface",
"::",
"TYPE_REQUEST_OUT_OF_CORS_SCOPE",
":",
"return",
"$",
"handler",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"default",
":",
"/* Actual CORS request. */",
"$",
"response",
"=",
"$",
"handler",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"$",
"cors_headers",
"=",
"$",
"cors",
"->",
"getResponseHeaders",
"(",
")",
";",
"foreach",
"(",
"$",
"cors_headers",
"as",
"$",
"header",
"=>",
"$",
"value",
")",
"{",
"/* Diactoros errors on integer values. */",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"$",
"header",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"response",
";",
"}",
"}"
] | Execute as PSR-15 middleware. | [
"Execute",
"as",
"PSR",
"-",
"15",
"middleware",
"."
] | train | https://github.com/tuupola/cors-middleware/blob/10c77e5ff19270380c4174cc8c95849d23521d9c/src/CorsMiddleware.php#L75-L126 |
tuupola/cors-middleware | src/CorsMiddleware.php | CorsMiddleware.buildSettings | private function buildSettings(ServerRequestInterface $request, ResponseInterface $response): CorsSettings
{
$settings = new CorsSettings;
$origin = array_fill_keys((array) $this->options["origin"], true);
$settings->setRequestAllowedOrigins($origin);
if (is_callable($this->options["methods"])) {
$methods = (array) $this->options["methods"]($request, $response);
} else {
$methods = $this->options["methods"];
}
$methods = array_fill_keys($methods, true);
$settings->setRequestAllowedMethods($methods);
$headers = array_fill_keys($this->options["headers.allow"], true);
$headers = array_change_key_case($headers, CASE_LOWER);
$settings->setRequestAllowedHeaders($headers);
$headers = array_fill_keys($this->options["headers.expose"], true);
$settings->setResponseExposedHeaders($headers);
$settings->setRequestCredentialsSupported($this->options["credentials"]);
if (is_string($this->options["origin.server"])) {
$settings->setServerOrigin($this->options["origin.server"]);
}
$settings->setPreFlightCacheMaxAge($this->options["cache"]);
return $settings;
} | php | private function buildSettings(ServerRequestInterface $request, ResponseInterface $response): CorsSettings
{
$settings = new CorsSettings;
$origin = array_fill_keys((array) $this->options["origin"], true);
$settings->setRequestAllowedOrigins($origin);
if (is_callable($this->options["methods"])) {
$methods = (array) $this->options["methods"]($request, $response);
} else {
$methods = $this->options["methods"];
}
$methods = array_fill_keys($methods, true);
$settings->setRequestAllowedMethods($methods);
$headers = array_fill_keys($this->options["headers.allow"], true);
$headers = array_change_key_case($headers, CASE_LOWER);
$settings->setRequestAllowedHeaders($headers);
$headers = array_fill_keys($this->options["headers.expose"], true);
$settings->setResponseExposedHeaders($headers);
$settings->setRequestCredentialsSupported($this->options["credentials"]);
if (is_string($this->options["origin.server"])) {
$settings->setServerOrigin($this->options["origin.server"]);
}
$settings->setPreFlightCacheMaxAge($this->options["cache"]);
return $settings;
} | [
"private",
"function",
"buildSettings",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
":",
"CorsSettings",
"{",
"$",
"settings",
"=",
"new",
"CorsSettings",
";",
"$",
"origin",
"=",
"array_fill_keys",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"options",
"[",
"\"origin\"",
"]",
",",
"true",
")",
";",
"$",
"settings",
"->",
"setRequestAllowedOrigins",
"(",
"$",
"origin",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"options",
"[",
"\"methods\"",
"]",
")",
")",
"{",
"$",
"methods",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"options",
"[",
"\"methods\"",
"]",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"else",
"{",
"$",
"methods",
"=",
"$",
"this",
"->",
"options",
"[",
"\"methods\"",
"]",
";",
"}",
"$",
"methods",
"=",
"array_fill_keys",
"(",
"$",
"methods",
",",
"true",
")",
";",
"$",
"settings",
"->",
"setRequestAllowedMethods",
"(",
"$",
"methods",
")",
";",
"$",
"headers",
"=",
"array_fill_keys",
"(",
"$",
"this",
"->",
"options",
"[",
"\"headers.allow\"",
"]",
",",
"true",
")",
";",
"$",
"headers",
"=",
"array_change_key_case",
"(",
"$",
"headers",
",",
"CASE_LOWER",
")",
";",
"$",
"settings",
"->",
"setRequestAllowedHeaders",
"(",
"$",
"headers",
")",
";",
"$",
"headers",
"=",
"array_fill_keys",
"(",
"$",
"this",
"->",
"options",
"[",
"\"headers.expose\"",
"]",
",",
"true",
")",
";",
"$",
"settings",
"->",
"setResponseExposedHeaders",
"(",
"$",
"headers",
")",
";",
"$",
"settings",
"->",
"setRequestCredentialsSupported",
"(",
"$",
"this",
"->",
"options",
"[",
"\"credentials\"",
"]",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"options",
"[",
"\"origin.server\"",
"]",
")",
")",
"{",
"$",
"settings",
"->",
"setServerOrigin",
"(",
"$",
"this",
"->",
"options",
"[",
"\"origin.server\"",
"]",
")",
";",
"}",
"$",
"settings",
"->",
"setPreFlightCacheMaxAge",
"(",
"$",
"this",
"->",
"options",
"[",
"\"cache\"",
"]",
")",
";",
"return",
"$",
"settings",
";",
"}"
] | Build a CORS settings object. | [
"Build",
"a",
"CORS",
"settings",
"object",
"."
] | train | https://github.com/tuupola/cors-middleware/blob/10c77e5ff19270380c4174cc8c95849d23521d9c/src/CorsMiddleware.php#L153-L184 |
tuupola/cors-middleware | src/CorsMiddleware.php | CorsMiddleware.methods | private function methods($methods): void
{
if (is_callable($methods)) {
if ($methods instanceof Closure) {
$this->options["methods"] = $methods->bindTo($this);
} else {
$this->options["methods"] = $methods;
}
} else {
$this->options["methods"] = (array) $methods;
}
} | php | private function methods($methods): void
{
if (is_callable($methods)) {
if ($methods instanceof Closure) {
$this->options["methods"] = $methods->bindTo($this);
} else {
$this->options["methods"] = $methods;
}
} else {
$this->options["methods"] = (array) $methods;
}
} | [
"private",
"function",
"methods",
"(",
"$",
"methods",
")",
":",
"void",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"methods",
")",
")",
"{",
"if",
"(",
"$",
"methods",
"instanceof",
"Closure",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"\"methods\"",
"]",
"=",
"$",
"methods",
"->",
"bindTo",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"options",
"[",
"\"methods\"",
"]",
"=",
"$",
"methods",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"options",
"[",
"\"methods\"",
"]",
"=",
"(",
"array",
")",
"$",
"methods",
";",
"}",
"}"
] | Set request methods to be allowed. | [
"Set",
"request",
"methods",
"to",
"be",
"allowed",
"."
] | train | https://github.com/tuupola/cors-middleware/blob/10c77e5ff19270380c4174cc8c95849d23521d9c/src/CorsMiddleware.php#L197-L208 |
tuupola/cors-middleware | src/CorsMiddleware.php | CorsMiddleware.processError | private function processError(ServerRequestInterface $request, ResponseInterface $response, array $arguments = null)
{
if (is_callable($this->options["error"])) {
$handler_response = $this->options["error"]($request, $response, $arguments);
if (is_a($handler_response, "\Psr\Http\Message\ResponseInterface")) {
return $handler_response;
}
}
return $response;
} | php | private function processError(ServerRequestInterface $request, ResponseInterface $response, array $arguments = null)
{
if (is_callable($this->options["error"])) {
$handler_response = $this->options["error"]($request, $response, $arguments);
if (is_a($handler_response, "\Psr\Http\Message\ResponseInterface")) {
return $handler_response;
}
}
return $response;
} | [
"private",
"function",
"processError",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"array",
"$",
"arguments",
"=",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"options",
"[",
"\"error\"",
"]",
")",
")",
"{",
"$",
"handler_response",
"=",
"$",
"this",
"->",
"options",
"[",
"\"error\"",
"]",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"arguments",
")",
";",
"if",
"(",
"is_a",
"(",
"$",
"handler_response",
",",
"\"\\Psr\\Http\\Message\\ResponseInterface\"",
")",
")",
"{",
"return",
"$",
"handler_response",
";",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] | Call the error handler if it exists. | [
"Call",
"the",
"error",
"handler",
"if",
"it",
"exists",
"."
] | train | https://github.com/tuupola/cors-middleware/blob/10c77e5ff19270380c4174cc8c95849d23521d9c/src/CorsMiddleware.php#L273-L282 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.