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 |
|---|---|---|---|---|---|---|---|---|---|---|
amphp/byte-stream | lib/InMemoryStream.php | InMemoryStream.read | public function read(): Promise
{
if ($this->contents === null) {
return new Success;
}
$promise = new Success($this->contents);
$this->contents = null;
return $promise;
} | php | public function read(): Promise
{
if ($this->contents === null) {
return new Success;
}
$promise = new Success($this->contents);
$this->contents = null;
return $promise;
} | [
"public",
"function",
"read",
"(",
")",
":",
"Promise",
"{",
"if",
"(",
"$",
"this",
"->",
"contents",
"===",
"null",
")",
"{",
"return",
"new",
"Success",
";",
"}",
"$",
"promise",
"=",
"new",
"Success",
"(",
"$",
"this",
"->",
"contents",
")",
";",
"$",
"this",
"->",
"contents",
"=",
"null",
";",
"return",
"$",
"promise",
";",
"}"
] | Reads data from the stream.
@return Promise Resolves with the full contents or `null` if the stream has closed / already been consumed. | [
"Reads",
"data",
"from",
"the",
"stream",
"."
] | train | https://github.com/amphp/byte-stream/blob/d5cd42a76516f91672143fa5662df2fdaa4ebe57/lib/InMemoryStream.php#L28-L38 |
amphp/byte-stream | lib/Payload.php | Payload.read | final public function read(): Promise
{
if ($this->promise) {
throw new \Error("Cannot stream message data once a buffered message has been requested");
}
return $this->lastRead = $this->stream->read();
} | php | final public function read(): Promise
{
if ($this->promise) {
throw new \Error("Cannot stream message data once a buffered message has been requested");
}
return $this->lastRead = $this->stream->read();
} | [
"final",
"public",
"function",
"read",
"(",
")",
":",
"Promise",
"{",
"if",
"(",
"$",
"this",
"->",
"promise",
")",
"{",
"throw",
"new",
"\\",
"Error",
"(",
"\"Cannot stream message data once a buffered message has been requested\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"lastRead",
"=",
"$",
"this",
"->",
"stream",
"->",
"read",
"(",
")",
";",
"}"
] | @inheritdoc
@throws \Error If a buffered message was requested by calling buffer(). | [
"@inheritdoc"
] | train | https://github.com/amphp/byte-stream/blob/d5cd42a76516f91672143fa5662df2fdaa4ebe57/lib/Payload.php#L60-L67 |
amphp/byte-stream | lib/Payload.php | Payload.buffer | final public function buffer(): Promise
{
if ($this->promise) {
return $this->promise;
}
return $this->promise = call(function () {
$buffer = '';
if ($this->lastRead && null === yield $this->lastRead) {
return $buffer;
}
while (null !== $chunk = yield $this->stream->read()) {
$buffer .= $chunk;
}
return $buffer;
});
} | php | final public function buffer(): Promise
{
if ($this->promise) {
return $this->promise;
}
return $this->promise = call(function () {
$buffer = '';
if ($this->lastRead && null === yield $this->lastRead) {
return $buffer;
}
while (null !== $chunk = yield $this->stream->read()) {
$buffer .= $chunk;
}
return $buffer;
});
} | [
"final",
"public",
"function",
"buffer",
"(",
")",
":",
"Promise",
"{",
"if",
"(",
"$",
"this",
"->",
"promise",
")",
"{",
"return",
"$",
"this",
"->",
"promise",
";",
"}",
"return",
"$",
"this",
"->",
"promise",
"=",
"call",
"(",
"function",
"(",
")",
"{",
"$",
"buffer",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"lastRead",
"&&",
"null",
"===",
"yield",
"$",
"this",
"->",
"lastRead",
")",
"{",
"return",
"$",
"buffer",
";",
"}",
"while",
"(",
"null",
"!==",
"$",
"chunk",
"=",
"yield",
"$",
"this",
"->",
"stream",
"->",
"read",
"(",
")",
")",
"{",
"$",
"buffer",
".=",
"$",
"chunk",
";",
"}",
"return",
"$",
"buffer",
";",
"}",
")",
";",
"}"
] | Buffers the entire message and resolves the returned promise then.
@return Promise<string> Resolves with the entire message contents. | [
"Buffers",
"the",
"entire",
"message",
"and",
"resolves",
"the",
"returned",
"promise",
"then",
"."
] | train | https://github.com/amphp/byte-stream/blob/d5cd42a76516f91672143fa5662df2fdaa4ebe57/lib/Payload.php#L74-L91 |
amphp/byte-stream | lib/ResourceInputStream.php | ResourceInputStream.close | public function close()
{
if ($this->resource) {
// Error suppression, as resource might already be closed
$meta = @\stream_get_meta_data($this->resource);
if ($meta && \strpos($meta["mode"], "+") !== false) {
@\stream_socket_shutdown($this->resource, \STREAM_SHUT_RD);
} else {
@\fclose($this->resource);
}
$this->resource = null;
}
$this->free();
} | php | public function close()
{
if ($this->resource) {
// Error suppression, as resource might already be closed
$meta = @\stream_get_meta_data($this->resource);
if ($meta && \strpos($meta["mode"], "+") !== false) {
@\stream_socket_shutdown($this->resource, \STREAM_SHUT_RD);
} else {
@\fclose($this->resource);
}
$this->resource = null;
}
$this->free();
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resource",
")",
"{",
"// Error suppression, as resource might already be closed",
"$",
"meta",
"=",
"@",
"\\",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"if",
"(",
"$",
"meta",
"&&",
"\\",
"strpos",
"(",
"$",
"meta",
"[",
"\"mode\"",
"]",
",",
"\"+\"",
")",
"!==",
"false",
")",
"{",
"@",
"\\",
"stream_socket_shutdown",
"(",
"$",
"this",
"->",
"resource",
",",
"\\",
"STREAM_SHUT_RD",
")",
";",
"}",
"else",
"{",
"@",
"\\",
"fclose",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"}",
"$",
"this",
"->",
"resource",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"free",
"(",
")",
";",
"}"
] | Closes the stream forcefully. Multiple `close()` calls are ignored.
@return void | [
"Closes",
"the",
"stream",
"forcefully",
".",
"Multiple",
"close",
"()",
"calls",
"are",
"ignored",
"."
] | train | https://github.com/amphp/byte-stream/blob/d5cd42a76516f91672143fa5662df2fdaa4ebe57/lib/ResourceInputStream.php#L162-L177 |
amphp/byte-stream | lib/ResourceInputStream.php | ResourceInputStream.free | private function free()
{
$this->readable = false;
if ($this->deferred !== null) {
$deferred = $this->deferred;
$this->deferred = null;
$deferred->resolve();
}
Loop::cancel($this->watcher);
if ($this->immediateWatcher !== null) {
Loop::cancel($this->immediateWatcher);
}
} | php | private function free()
{
$this->readable = false;
if ($this->deferred !== null) {
$deferred = $this->deferred;
$this->deferred = null;
$deferred->resolve();
}
Loop::cancel($this->watcher);
if ($this->immediateWatcher !== null) {
Loop::cancel($this->immediateWatcher);
}
} | [
"private",
"function",
"free",
"(",
")",
"{",
"$",
"this",
"->",
"readable",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"deferred",
"!==",
"null",
")",
"{",
"$",
"deferred",
"=",
"$",
"this",
"->",
"deferred",
";",
"$",
"this",
"->",
"deferred",
"=",
"null",
";",
"$",
"deferred",
"->",
"resolve",
"(",
")",
";",
"}",
"Loop",
"::",
"cancel",
"(",
"$",
"this",
"->",
"watcher",
")",
";",
"if",
"(",
"$",
"this",
"->",
"immediateWatcher",
"!==",
"null",
")",
"{",
"Loop",
"::",
"cancel",
"(",
"$",
"this",
"->",
"immediateWatcher",
")",
";",
"}",
"}"
] | Nulls reference to resource, marks stream unreadable, and succeeds any pending read with null. | [
"Nulls",
"reference",
"to",
"resource",
"marks",
"stream",
"unreadable",
"and",
"succeeds",
"any",
"pending",
"read",
"with",
"null",
"."
] | train | https://github.com/amphp/byte-stream/blob/d5cd42a76516f91672143fa5662df2fdaa4ebe57/lib/ResourceInputStream.php#L182-L197 |
amphp/byte-stream | lib/ResourceOutputStream.php | ResourceOutputStream.close | public function close()
{
if ($this->resource) {
// Error suppression, as resource might already be closed
$meta = @\stream_get_meta_data($this->resource);
if ($meta && \strpos($meta["mode"], "+") !== false) {
@\stream_socket_shutdown($this->resource, \STREAM_SHUT_WR);
} else {
@\fclose($this->resource);
}
}
$this->free();
} | php | public function close()
{
if ($this->resource) {
// Error suppression, as resource might already be closed
$meta = @\stream_get_meta_data($this->resource);
if ($meta && \strpos($meta["mode"], "+") !== false) {
@\stream_socket_shutdown($this->resource, \STREAM_SHUT_WR);
} else {
@\fclose($this->resource);
}
}
$this->free();
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resource",
")",
"{",
"// Error suppression, as resource might already be closed",
"$",
"meta",
"=",
"@",
"\\",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"if",
"(",
"$",
"meta",
"&&",
"\\",
"strpos",
"(",
"$",
"meta",
"[",
"\"mode\"",
"]",
",",
"\"+\"",
")",
"!==",
"false",
")",
"{",
"@",
"\\",
"stream_socket_shutdown",
"(",
"$",
"this",
"->",
"resource",
",",
"\\",
"STREAM_SHUT_WR",
")",
";",
"}",
"else",
"{",
"@",
"\\",
"fclose",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"}",
"}",
"$",
"this",
"->",
"free",
"(",
")",
";",
"}"
] | Closes the stream forcefully. Multiple `close()` calls are ignored.
@return void | [
"Closes",
"the",
"stream",
"forcefully",
".",
"Multiple",
"close",
"()",
"calls",
"are",
"ignored",
"."
] | train | https://github.com/amphp/byte-stream/blob/d5cd42a76516f91672143fa5662df2fdaa4ebe57/lib/ResourceOutputStream.php#L233-L247 |
amphp/byte-stream | lib/ResourceOutputStream.php | ResourceOutputStream.free | private function free()
{
$this->resource = null;
$this->writable = false;
if (!$this->writes->isEmpty()) {
$exception = new ClosedException("The socket was closed before writing completed");
do {
/** @var \Amp\Deferred $deferred */
list(, , $deferred) = $this->writes->shift();
$deferred->fail($exception);
} while (!$this->writes->isEmpty());
}
Loop::cancel($this->watcher);
} | php | private function free()
{
$this->resource = null;
$this->writable = false;
if (!$this->writes->isEmpty()) {
$exception = new ClosedException("The socket was closed before writing completed");
do {
/** @var \Amp\Deferred $deferred */
list(, , $deferred) = $this->writes->shift();
$deferred->fail($exception);
} while (!$this->writes->isEmpty());
}
Loop::cancel($this->watcher);
} | [
"private",
"function",
"free",
"(",
")",
"{",
"$",
"this",
"->",
"resource",
"=",
"null",
";",
"$",
"this",
"->",
"writable",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"writes",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"exception",
"=",
"new",
"ClosedException",
"(",
"\"The socket was closed before writing completed\"",
")",
";",
"do",
"{",
"/** @var \\Amp\\Deferred $deferred */",
"list",
"(",
",",
",",
"$",
"deferred",
")",
"=",
"$",
"this",
"->",
"writes",
"->",
"shift",
"(",
")",
";",
"$",
"deferred",
"->",
"fail",
"(",
"$",
"exception",
")",
";",
"}",
"while",
"(",
"!",
"$",
"this",
"->",
"writes",
"->",
"isEmpty",
"(",
")",
")",
";",
"}",
"Loop",
"::",
"cancel",
"(",
"$",
"this",
"->",
"watcher",
")",
";",
"}"
] | Nulls reference to resource, marks stream unwritable, and fails any pending write. | [
"Nulls",
"reference",
"to",
"resource",
"marks",
"stream",
"unwritable",
"and",
"fails",
"any",
"pending",
"write",
"."
] | train | https://github.com/amphp/byte-stream/blob/d5cd42a76516f91672143fa5662df2fdaa4ebe57/lib/ResourceOutputStream.php#L252-L267 |
bowphp/tintin | src/Loader/Filesystem.php | Filesystem.getFileResolvedPath | public function getFileResolvedPath($filename)
{
$filename = str_replace('.', '/', $filename);
return $this->config['path'].'/'.$filename.'.'.$this->getExtension();
} | php | public function getFileResolvedPath($filename)
{
$filename = str_replace('.', '/', $filename);
return $this->config['path'].'/'.$filename.'.'.$this->getExtension();
} | [
"public",
"function",
"getFileResolvedPath",
"(",
"$",
"filename",
")",
"{",
"$",
"filename",
"=",
"str_replace",
"(",
"'.'",
",",
"'/'",
",",
"$",
"filename",
")",
";",
"return",
"$",
"this",
"->",
"config",
"[",
"'path'",
"]",
".",
"'/'",
".",
"$",
"filename",
".",
"'.'",
".",
"$",
"this",
"->",
"getExtension",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Loader/Filesystem.php#L31-L36 |
bowphp/tintin | src/Loader/Filesystem.php | Filesystem.getCacheFileResolvedPath | public function getCacheFileResolvedPath($filename)
{
if (!$this->exists($filename)) {
$this->failLoading($filename . ' file not exists !');
}
$md5 = sha1($filename);
$dirname = substr($md5, 0, 2);
return $this->getCachePath().'/'.$dirname.'/'.$md5.'.php';
} | php | public function getCacheFileResolvedPath($filename)
{
if (!$this->exists($filename)) {
$this->failLoading($filename . ' file not exists !');
}
$md5 = sha1($filename);
$dirname = substr($md5, 0, 2);
return $this->getCachePath().'/'.$dirname.'/'.$md5.'.php';
} | [
"public",
"function",
"getCacheFileResolvedPath",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"this",
"->",
"failLoading",
"(",
"$",
"filename",
".",
"' file not exists !'",
")",
";",
"}",
"$",
"md5",
"=",
"sha1",
"(",
"$",
"filename",
")",
";",
"$",
"dirname",
"=",
"substr",
"(",
"$",
"md5",
",",
"0",
",",
"2",
")",
";",
"return",
"$",
"this",
"->",
"getCachePath",
"(",
")",
".",
"'/'",
".",
"$",
"dirname",
".",
"'/'",
".",
"$",
"md5",
".",
"'.php'",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Loader/Filesystem.php#L41-L52 |
bowphp/tintin | src/Loader/Filesystem.php | Filesystem.isExpirated | public function isExpirated($filename)
{
if (!$this->isCached($filename)) {
return true;
}
$fileatime = filemtime(
$this->getFileResolvedPath($filename)
);
$cache_filetime = fileatime(
$this->getCacheFileResolvedPath($filename)
);
return $fileatime > $cache_filetime;
} | php | public function isExpirated($filename)
{
if (!$this->isCached($filename)) {
return true;
}
$fileatime = filemtime(
$this->getFileResolvedPath($filename)
);
$cache_filetime = fileatime(
$this->getCacheFileResolvedPath($filename)
);
return $fileatime > $cache_filetime;
} | [
"public",
"function",
"isExpirated",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCached",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"fileatime",
"=",
"filemtime",
"(",
"$",
"this",
"->",
"getFileResolvedPath",
"(",
"$",
"filename",
")",
")",
";",
"$",
"cache_filetime",
"=",
"fileatime",
"(",
"$",
"this",
"->",
"getCacheFileResolvedPath",
"(",
"$",
"filename",
")",
")",
";",
"return",
"$",
"fileatime",
">",
"$",
"cache_filetime",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Loader/Filesystem.php#L81-L96 |
bowphp/tintin | src/Loader/Filesystem.php | Filesystem.cache | public function cache($filename, $config)
{
$md5 = sha1($filename);
$dirname = substr($md5, 0, 2);
if (! is_dir($this->getCachePath().'/'.$dirname)) {
mkdir($this->getCachePath().'/'.$dirname);
}
$path = $this->getCachePath().'/'.$dirname.'/'.$md5.'.php';
return file_put_contents($path, $config);
} | php | public function cache($filename, $config)
{
$md5 = sha1($filename);
$dirname = substr($md5, 0, 2);
if (! is_dir($this->getCachePath().'/'.$dirname)) {
mkdir($this->getCachePath().'/'.$dirname);
}
$path = $this->getCachePath().'/'.$dirname.'/'.$md5.'.php';
return file_put_contents($path, $config);
} | [
"public",
"function",
"cache",
"(",
"$",
"filename",
",",
"$",
"config",
")",
"{",
"$",
"md5",
"=",
"sha1",
"(",
"$",
"filename",
")",
";",
"$",
"dirname",
"=",
"substr",
"(",
"$",
"md5",
",",
"0",
",",
"2",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"getCachePath",
"(",
")",
".",
"'/'",
".",
"$",
"dirname",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"getCachePath",
"(",
")",
".",
"'/'",
".",
"$",
"dirname",
")",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"getCachePath",
"(",
")",
".",
"'/'",
".",
"$",
"dirname",
".",
"'/'",
".",
"$",
"md5",
".",
"'.php'",
";",
"return",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"config",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Loader/Filesystem.php#L121-L134 |
bowphp/tintin | src/Stacker/StackManager.php | StackManager.includeFile | public function includeFile($filename, $data = [], $context = [])
{
$this->tintin->pushSharedData(array_merge($context, $data));
$data = $this->tintin->getSharedData();
return $this->tintin->render($filename, $data);
} | php | public function includeFile($filename, $data = [], $context = [])
{
$this->tintin->pushSharedData(array_merge($context, $data));
$data = $this->tintin->getSharedData();
return $this->tintin->render($filename, $data);
} | [
"public",
"function",
"includeFile",
"(",
"$",
"filename",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"tintin",
"->",
"pushSharedData",
"(",
"array_merge",
"(",
"$",
"context",
",",
"$",
"data",
")",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"tintin",
"->",
"getSharedData",
"(",
")",
";",
"return",
"$",
"this",
"->",
"tintin",
"->",
"render",
"(",
"$",
"filename",
",",
"$",
"data",
")",
";",
"}"
] | Include a file to compile
@param string $filename
@param array $data
@param array $context
@return string | [
"Include",
"a",
"file",
"to",
"compile"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Stacker/StackManager.php#L51-L58 |
bowphp/tintin | src/Stacker/StackManager.php | StackManager.startStack | public function startStack($name, $content = null)
{
if (is_null($content)) {
ob_start();
}
$this->stacks[] = $name;
$this->pushes[$name] = $content;
} | php | public function startStack($name, $content = null)
{
if (is_null($content)) {
ob_start();
}
$this->stacks[] = $name;
$this->pushes[$name] = $content;
} | [
"public",
"function",
"startStack",
"(",
"$",
"name",
",",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"content",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"}",
"$",
"this",
"->",
"stacks",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"pushes",
"[",
"$",
"name",
"]",
"=",
"$",
"content",
";",
"}"
] | Open the stream for a #block
@param string $name
@param string $content
@return void | [
"Open",
"the",
"stream",
"for",
"a",
"#block"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Stacker/StackManager.php#L68-L77 |
bowphp/tintin | src/Stacker/StackManager.php | StackManager.endStack | public function endStack()
{
$stacks = array_pop($this->stacks);
$stacks = (array) $stacks;
foreach ($stacks as $block) {
$content = $this->pushes[$block];
if (is_null($content)) {
$content = $this->tintin->getCompiler()->compile(ob_get_clean());
}
$this->pushes[$block] = trim($content, "\n");
}
} | php | public function endStack()
{
$stacks = array_pop($this->stacks);
$stacks = (array) $stacks;
foreach ($stacks as $block) {
$content = $this->pushes[$block];
if (is_null($content)) {
$content = $this->tintin->getCompiler()->compile(ob_get_clean());
}
$this->pushes[$block] = trim($content, "\n");
}
} | [
"public",
"function",
"endStack",
"(",
")",
"{",
"$",
"stacks",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"stacks",
")",
";",
"$",
"stacks",
"=",
"(",
"array",
")",
"$",
"stacks",
";",
"foreach",
"(",
"$",
"stacks",
"as",
"$",
"block",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"pushes",
"[",
"$",
"block",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"content",
")",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"tintin",
"->",
"getCompiler",
"(",
")",
"->",
"compile",
"(",
"ob_get_clean",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"pushes",
"[",
"$",
"block",
"]",
"=",
"trim",
"(",
"$",
"content",
",",
"\"\\n\"",
")",
";",
"}",
"}"
] | Closes the current flow
@return void | [
"Closes",
"the",
"current",
"flow"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Stacker/StackManager.php#L84-L99 |
bowphp/tintin | src/Stacker/StackManager.php | StackManager.getStack | public function getStack($name, $default = null)
{
if (array_key_exists($name, $this->pushes)) {
return $this->tintin->renderString(
$this->pushes[$name],
['__tintin' => $this->tintin]
);
}
return $default;
} | php | public function getStack($name, $default = null)
{
if (array_key_exists($name, $this->pushes)) {
return $this->tintin->renderString(
$this->pushes[$name],
['__tintin' => $this->tintin]
);
}
return $default;
} | [
"public",
"function",
"getStack",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"pushes",
")",
")",
"{",
"return",
"$",
"this",
"->",
"tintin",
"->",
"renderString",
"(",
"$",
"this",
"->",
"pushes",
"[",
"$",
"name",
"]",
",",
"[",
"'__tintin'",
"=>",
"$",
"this",
"->",
"tintin",
"]",
")",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Allows you to retrieve the contents of a stack
@param string $name
@param string $default
@return mixed|null | [
"Allows",
"you",
"to",
"retrieve",
"the",
"contents",
"of",
"a",
"stack"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Stacker/StackManager.php#L109-L119 |
bowphp/tintin | src/Lexique/CompileIf.php | CompileIf.compileIfStack | protected function compileIfStack($expression)
{
foreach (['UnLess', 'If', 'ElseIf', 'ElseIfAlias', 'Else', 'EndIf'] as $token) {
$out = $this->{'compile'.$token}($expression);
if (strlen($out) !== 0) {
$expression = $out;
}
}
return $expression;
} | php | protected function compileIfStack($expression)
{
foreach (['UnLess', 'If', 'ElseIf', 'ElseIfAlias', 'Else', 'EndIf'] as $token) {
$out = $this->{'compile'.$token}($expression);
if (strlen($out) !== 0) {
$expression = $out;
}
}
return $expression;
} | [
"protected",
"function",
"compileIfStack",
"(",
"$",
"expression",
")",
"{",
"foreach",
"(",
"[",
"'UnLess'",
",",
"'If'",
",",
"'ElseIf'",
",",
"'ElseIfAlias'",
",",
"'Else'",
",",
"'EndIf'",
"]",
"as",
"$",
"token",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"{",
"'compile'",
".",
"$",
"token",
"}",
"(",
"$",
"expression",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"out",
")",
"!==",
"0",
")",
"{",
"$",
"expression",
"=",
"$",
"out",
";",
"}",
"}",
"return",
"$",
"expression",
";",
"}"
] | Compile the if statement stack
@param string $expression
@return string | [
"Compile",
"the",
"if",
"statement",
"stack"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileIf.php#L14-L25 |
bowphp/tintin | src/Lexique/CompileIf.php | CompileIf.compileEndIf | protected function compileEndIf($expression)
{
$output = preg_replace_callback('/\n*(#endif|#endunless)\n*/', function ($match) {
array_shift($match);
return "<?php endif; ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | php | protected function compileEndIf($expression)
{
$output = preg_replace_callback('/\n*(#endif|#endunless)\n*/', function ($match) {
array_shift($match);
return "<?php endif; ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | [
"protected",
"function",
"compileEndIf",
"(",
"$",
"expression",
")",
"{",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"'/\\n*(#endif|#endunless)\\n*/'",
",",
"function",
"(",
"$",
"match",
")",
"{",
"array_shift",
"(",
"$",
"match",
")",
";",
"return",
"\"<?php endif; ?>\"",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the #endif statement
@param string $expression
@return string | [
"Compile",
"the",
"#endif",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileIf.php#L126-L135 |
bowphp/tintin | src/Lexique/CompileEchos.php | CompileEchos.compileEchoStack | protected function compileEchoStack($expression)
{
foreach (['RawEcho', 'Echo'] as $token) {
$out = $this->{'compile'.$token}($expression);
if (strlen($out) !== 0) {
$expression = $out;
}
}
return $expression;
} | php | protected function compileEchoStack($expression)
{
foreach (['RawEcho', 'Echo'] as $token) {
$out = $this->{'compile'.$token}($expression);
if (strlen($out) !== 0) {
$expression = $out;
}
}
return $expression;
} | [
"protected",
"function",
"compileEchoStack",
"(",
"$",
"expression",
")",
"{",
"foreach",
"(",
"[",
"'RawEcho'",
",",
"'Echo'",
"]",
"as",
"$",
"token",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"{",
"'compile'",
".",
"$",
"token",
"}",
"(",
"$",
"expression",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"out",
")",
"!==",
"0",
")",
"{",
"$",
"expression",
"=",
"$",
"out",
";",
"}",
"}",
"return",
"$",
"expression",
";",
"}"
] | Compile the echo statement concept
@param string $expression
@return mixed | [
"Compile",
"the",
"echo",
"statement",
"concept"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileEchos.php#L14-L25 |
bowphp/tintin | src/Lexique/CompileEchos.php | CompileEchos.compileEcho | protected function compileEcho($expression)
{
$regex = sprintf(
'/((?:%s\s*(.+?)\s*%s))+/',
$this->echo_tags[0],
$this->echo_tags[1]
);
$output = preg_replace_callback($regex, function ($match) {
array_shift($match);
return '<?php echo htmlspecialchars('.$match[1].', ENT_QUOTES); ?>';
}, $expression);
return $output == $expression ? '' : $output;
} | php | protected function compileEcho($expression)
{
$regex = sprintf(
'/((?:%s\s*(.+?)\s*%s))+/',
$this->echo_tags[0],
$this->echo_tags[1]
);
$output = preg_replace_callback($regex, function ($match) {
array_shift($match);
return '<?php echo htmlspecialchars('.$match[1].', ENT_QUOTES); ?>';
}, $expression);
return $output == $expression ? '' : $output;
} | [
"protected",
"function",
"compileEcho",
"(",
"$",
"expression",
")",
"{",
"$",
"regex",
"=",
"sprintf",
"(",
"'/((?:%s\\s*(.+?)\\s*%s))+/'",
",",
"$",
"this",
"->",
"echo_tags",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"echo_tags",
"[",
"1",
"]",
")",
";",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"$",
"regex",
",",
"function",
"(",
"$",
"match",
")",
"{",
"array_shift",
"(",
"$",
"match",
")",
";",
"return",
"'<?php echo htmlspecialchars('",
".",
"$",
"match",
"[",
"1",
"]",
".",
"', ENT_QUOTES); ?>'",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the {{ $name }} statement
@param string $expression
@return string | [
"Compile",
"the",
"{{",
"$name",
"}}",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileEchos.php#L34-L49 |
bowphp/tintin | src/Lexique/CompileEchos.php | CompileEchos.compileRawEcho | protected function compileRawEcho($expression)
{
$regex = sprintf(
'/((?:%s\s*(.+?)\s*%s))+/',
$this->raw_echo_tags[0],
$this->raw_echo_tags[1]
);
$output = preg_replace_callback($regex, function ($match) {
array_shift($match);
return '<?php echo '.$match[1].'; ?>';
}, $expression);
return $output == $expression ? '' : $output;
} | php | protected function compileRawEcho($expression)
{
$regex = sprintf(
'/((?:%s\s*(.+?)\s*%s))+/',
$this->raw_echo_tags[0],
$this->raw_echo_tags[1]
);
$output = preg_replace_callback($regex, function ($match) {
array_shift($match);
return '<?php echo '.$match[1].'; ?>';
}, $expression);
return $output == $expression ? '' : $output;
} | [
"protected",
"function",
"compileRawEcho",
"(",
"$",
"expression",
")",
"{",
"$",
"regex",
"=",
"sprintf",
"(",
"'/((?:%s\\s*(.+?)\\s*%s))+/'",
",",
"$",
"this",
"->",
"raw_echo_tags",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"raw_echo_tags",
"[",
"1",
"]",
")",
";",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"$",
"regex",
",",
"function",
"(",
"$",
"match",
")",
"{",
"array_shift",
"(",
"$",
"match",
")",
";",
"return",
"'<?php echo '",
".",
"$",
"match",
"[",
"1",
"]",
".",
"'; ?>'",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the {{{ $name }}} statement
@param string $expression
@return string | [
"Compile",
"the",
"{{{",
"$name",
"}}}",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileEchos.php#L58-L73 |
bowphp/tintin | src/Compiler.php | Compiler.compile | public function compile($data)
{
$data = preg_split('/\n|\r\n/', $data);
foreach ($data as $value) {
if (strlen($value) > 0) {
$value = $this->compileToken($value);
$this->result .= strlen($value) == 0 || $value == ' ' ? trim($value) : $value."\n";
}
}
return $this->resetCompilatorAccumulator();
} | php | public function compile($data)
{
$data = preg_split('/\n|\r\n/', $data);
foreach ($data as $value) {
if (strlen($value) > 0) {
$value = $this->compileToken($value);
$this->result .= strlen($value) == 0 || $value == ' ' ? trim($value) : $value."\n";
}
}
return $this->resetCompilatorAccumulator();
} | [
"public",
"function",
"compile",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"preg_split",
"(",
"'/\\n|\\r\\n/'",
",",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
">",
"0",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"compileToken",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"result",
".=",
"strlen",
"(",
"$",
"value",
")",
"==",
"0",
"||",
"$",
"value",
"==",
"' '",
"?",
"trim",
"(",
"$",
"value",
")",
":",
"$",
"value",
".",
"\"\\n\"",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"resetCompilatorAccumulator",
"(",
")",
";",
"}"
] | Launch the compilation
@param array|string $data
@return string | [
"Launch",
"the",
"compilation"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Compiler.php#L113-L126 |
bowphp/tintin | src/Compiler.php | Compiler.compileToken | private function compileToken($value)
{
foreach ($this->tokens as $token) {
$out = $this->{'compile'.$token}($value);
if ($token == 'Comments') {
if (strlen($out) == 0) {
return "";
}
}
if (strlen($out) !== 0) {
$value = $out;
}
}
return $value;
} | php | private function compileToken($value)
{
foreach ($this->tokens as $token) {
$out = $this->{'compile'.$token}($value);
if ($token == 'Comments') {
if (strlen($out) == 0) {
return "";
}
}
if (strlen($out) !== 0) {
$value = $out;
}
}
return $value;
} | [
"private",
"function",
"compileToken",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tokens",
"as",
"$",
"token",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"{",
"'compile'",
".",
"$",
"token",
"}",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"token",
"==",
"'Comments'",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"out",
")",
"==",
"0",
")",
"{",
"return",
"\"\"",
";",
"}",
"}",
"if",
"(",
"strlen",
"(",
"$",
"out",
")",
"!==",
"0",
")",
"{",
"$",
"value",
"=",
"$",
"out",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | Compile All define token
@param string $value
@return string | [
"Compile",
"All",
"define",
"token"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Compiler.php#L135-L152 |
bowphp/tintin | src/Compiler.php | Compiler.resetCompilatorAccumulator | private function resetCompilatorAccumulator()
{
$result = $this->result.implode("\n", $this->footer);
$this->result = '';
$this->footer = [];
return $result;
} | php | private function resetCompilatorAccumulator()
{
$result = $this->result.implode("\n", $this->footer);
$this->result = '';
$this->footer = [];
return $result;
} | [
"private",
"function",
"resetCompilatorAccumulator",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"result",
".",
"implode",
"(",
"\"\\n\"",
",",
"$",
"this",
"->",
"footer",
")",
";",
"$",
"this",
"->",
"result",
"=",
"''",
";",
"$",
"this",
"->",
"footer",
"=",
"[",
"]",
";",
"return",
"$",
"result",
";",
"}"
] | Reset Compilation accumulatior
@return string | [
"Reset",
"Compilation",
"accumulatior"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Compiler.php#L159-L168 |
bowphp/tintin | src/Compiler.php | Compiler.pushDirective | public function pushDirective($name, $handler, $broken = false)
{
if (in_array($name, $this->directivesProtected)) {
throw new DirectiveNotAllowException('The ' . $name . ' directive is not allow.');
}
$this->directives[$name] = compact('handler', 'broken');
} | php | public function pushDirective($name, $handler, $broken = false)
{
if (in_array($name, $this->directivesProtected)) {
throw new DirectiveNotAllowException('The ' . $name . ' directive is not allow.');
}
$this->directives[$name] = compact('handler', 'broken');
} | [
"public",
"function",
"pushDirective",
"(",
"$",
"name",
",",
"$",
"handler",
",",
"$",
"broken",
"=",
"false",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"directivesProtected",
")",
")",
"{",
"throw",
"new",
"DirectiveNotAllowException",
"(",
"'The '",
".",
"$",
"name",
".",
"' directive is not allow.'",
")",
";",
"}",
"$",
"this",
"->",
"directives",
"[",
"$",
"name",
"]",
"=",
"compact",
"(",
"'handler'",
",",
"'broken'",
")",
";",
"}"
] | Push more directive in template system
@param string $name
@param callable $handler
@param boolean $broken
@return void
@throws DirectiveNotAllowException | [
"Push",
"more",
"directive",
"in",
"template",
"system"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Compiler.php#L180-L187 |
bowphp/tintin | src/Lexique/CompileCustomDirective.php | CompileCustomDirective.compileCustomDirective | protected function compileCustomDirective($expression)
{
$output = preg_replace_callback($this->getCustomDirectivePartern(), function ($match) {
$name = $match[1];
if (!isset($this->directives[$name])) {
return null;
}
$directive = $this->directives[$name];
if ($directive['broken']) {
return $this->_____executeCustomDirectory(
$name,
isset($match[3]) ? $match[3] : null
);
}
$params = isset($match[3]) ? $match[3] : 'null';
return "<?php echo \$__tintin->getCompiler()->_____executeCustomDirectory(\"$name\", $params);";
}, $expression);
return is_null($output) ? $expression : $output;
} | php | protected function compileCustomDirective($expression)
{
$output = preg_replace_callback($this->getCustomDirectivePartern(), function ($match) {
$name = $match[1];
if (!isset($this->directives[$name])) {
return null;
}
$directive = $this->directives[$name];
if ($directive['broken']) {
return $this->_____executeCustomDirectory(
$name,
isset($match[3]) ? $match[3] : null
);
}
$params = isset($match[3]) ? $match[3] : 'null';
return "<?php echo \$__tintin->getCompiler()->_____executeCustomDirectory(\"$name\", $params);";
}, $expression);
return is_null($output) ? $expression : $output;
} | [
"protected",
"function",
"compileCustomDirective",
"(",
"$",
"expression",
")",
"{",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"$",
"this",
"->",
"getCustomDirectivePartern",
"(",
")",
",",
"function",
"(",
"$",
"match",
")",
"{",
"$",
"name",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"directives",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"directive",
"=",
"$",
"this",
"->",
"directives",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"$",
"directive",
"[",
"'broken'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"_____executeCustomDirectory",
"(",
"$",
"name",
",",
"isset",
"(",
"$",
"match",
"[",
"3",
"]",
")",
"?",
"$",
"match",
"[",
"3",
"]",
":",
"null",
")",
";",
"}",
"$",
"params",
"=",
"isset",
"(",
"$",
"match",
"[",
"3",
"]",
")",
"?",
"$",
"match",
"[",
"3",
"]",
":",
"'null'",
";",
"return",
"\"<?php echo \\$__tintin->getCompiler()->_____executeCustomDirectory(\\\"$name\\\", $params);\"",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"is_null",
"(",
"$",
"output",
")",
"?",
"$",
"expression",
":",
"$",
"output",
";",
"}"
] | Compile the custom statement
@param string $expression
@return string | [
"Compile",
"the",
"custom",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileCustomDirective.php#L14-L38 |
bowphp/tintin | src/Laravel/TintinServiceProvider.php | TintinServiceProvider.loadConfiguration | protected function loadConfiguration()
{
$config_path = __DIR__.'/../../config/tintin.php';
if (!$this->isLumen()) {
$this->publishes([
$config_path => config_path('view.php')
], 'config');
}
$this->mergeConfigFrom($config_path, 'view');
} | php | protected function loadConfiguration()
{
$config_path = __DIR__.'/../../config/tintin.php';
if (!$this->isLumen()) {
$this->publishes([
$config_path => config_path('view.php')
], 'config');
}
$this->mergeConfigFrom($config_path, 'view');
} | [
"protected",
"function",
"loadConfiguration",
"(",
")",
"{",
"$",
"config_path",
"=",
"__DIR__",
".",
"'/../../config/tintin.php'",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isLumen",
"(",
")",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"config_path",
"=>",
"config_path",
"(",
"'view.php'",
")",
"]",
",",
"'config'",
")",
";",
"}",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"$",
"config_path",
",",
"'view'",
")",
";",
"}"
] | Load the configuration files and allow them to be published.
@return void | [
"Load",
"the",
"configuration",
"files",
"and",
"allow",
"them",
"to",
"be",
"published",
"."
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Laravel/TintinServiceProvider.php#L53-L64 |
bowphp/tintin | src/Lexique/CompileComments.php | CompileComments.compileComments | protected function compileComments($value)
{
$pattern = sprintf('/%s(.*?)%s/', $this->comments[0], $this->comments[1]);
return preg_replace($pattern, '', $value);
} | php | protected function compileComments($value)
{
$pattern = sprintf('/%s(.*?)%s/', $this->comments[0], $this->comments[1]);
return preg_replace($pattern, '', $value);
} | [
"protected",
"function",
"compileComments",
"(",
"$",
"value",
")",
"{",
"$",
"pattern",
"=",
"sprintf",
"(",
"'/%s(.*?)%s/'",
",",
"$",
"this",
"->",
"comments",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"comments",
"[",
"1",
"]",
")",
";",
"return",
"preg_replace",
"(",
"$",
"pattern",
",",
"''",
",",
"$",
"value",
")",
";",
"}"
] | Compile the {# commentes #} statement
@param string $value
@return string | [
"Compile",
"the",
"{",
"#",
"commentes",
"#",
"}",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileComments.php#L14-L19 |
bowphp/tintin | src/Bow/TintinConfiguration.php | TintinConfiguration.create | public function create(Loader $config)
{
$this->container->bind('view', function () use ($config) {
View::pushEngine('tintin', TintinEngine::class);
View::configure($config);
return View::getInstance();
});
} | php | public function create(Loader $config)
{
$this->container->bind('view', function () use ($config) {
View::pushEngine('tintin', TintinEngine::class);
View::configure($config);
return View::getInstance();
});
} | [
"public",
"function",
"create",
"(",
"Loader",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"container",
"->",
"bind",
"(",
"'view'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"View",
"::",
"pushEngine",
"(",
"'tintin'",
",",
"TintinEngine",
"::",
"class",
")",
";",
"View",
"::",
"configure",
"(",
"$",
"config",
")",
";",
"return",
"View",
"::",
"getInstance",
"(",
")",
";",
"}",
")",
";",
"}"
] | {@inheritdoc}
@throws | [
"{"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Bow/TintinConfiguration.php#L16-L25 |
bowphp/tintin | src/Bow/TintinConfiguration.php | TintinConfiguration.run | public function run()
{
$view = $this->container->make('view');
$this->customizer($view->getTemplate()->getTemplate());
} | php | public function run()
{
$view = $this->container->make('view');
$this->customizer($view->getTemplate()->getTemplate());
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"'view'",
")",
";",
"$",
"this",
"->",
"customizer",
"(",
"$",
"view",
"->",
"getTemplate",
"(",
")",
"->",
"getTemplate",
"(",
")",
")",
";",
"}"
] | {@inheritdoc}
@throws | [
"{"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Bow/TintinConfiguration.php#L31-L36 |
bowphp/tintin | src/Lexique/CompileExtends.php | CompileExtends.compileExtendsStack | protected function compileExtendsStack($expression)
{
foreach (['Block', 'EndBlock', 'Include', 'Inject', 'Extends'] as $token) {
$out = $this->{'compile'.$token}($expression);
if (strlen($out) !== 0) {
$expression = $out;
}
}
return $expression;
} | php | protected function compileExtendsStack($expression)
{
foreach (['Block', 'EndBlock', 'Include', 'Inject', 'Extends'] as $token) {
$out = $this->{'compile'.$token}($expression);
if (strlen($out) !== 0) {
$expression = $out;
}
}
return $expression;
} | [
"protected",
"function",
"compileExtendsStack",
"(",
"$",
"expression",
")",
"{",
"foreach",
"(",
"[",
"'Block'",
",",
"'EndBlock'",
",",
"'Include'",
",",
"'Inject'",
",",
"'Extends'",
"]",
"as",
"$",
"token",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"{",
"'compile'",
".",
"$",
"token",
"}",
"(",
"$",
"expression",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"out",
")",
"!==",
"0",
")",
"{",
"$",
"expression",
"=",
"$",
"out",
";",
"}",
"}",
"return",
"$",
"expression",
";",
"}"
] | Compile the inherit concept statement
@param string $expression
@return string | [
"Compile",
"the",
"inherit",
"concept",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileExtends.php#L14-L25 |
bowphp/tintin | src/Lexique/CompileExtends.php | CompileExtends.compileBlock | protected function compileBlock($expression)
{
$output = preg_replace_callback(
"/\n*\#block\s*\((.+?)(?:,(.+?))?\)\n*/m",
function ($match) {
array_shift($match);
$content = null;
if (count($match) == 2) {
$content = $match[1];
}
if (is_null($content)) {
return "<?php \$__tintin->getStackManager()->startStack({$match[0]}); ?>";
} else {
return "<?php \$__tintin->getStackManager()->startStack({$match[0]}, $content); ?>";
}
},
$expression
);
return $output == $expression ? '' : $output;
} | php | protected function compileBlock($expression)
{
$output = preg_replace_callback(
"/\n*\#block\s*\((.+?)(?:,(.+?))?\)\n*/m",
function ($match) {
array_shift($match);
$content = null;
if (count($match) == 2) {
$content = $match[1];
}
if (is_null($content)) {
return "<?php \$__tintin->getStackManager()->startStack({$match[0]}); ?>";
} else {
return "<?php \$__tintin->getStackManager()->startStack({$match[0]}, $content); ?>";
}
},
$expression
);
return $output == $expression ? '' : $output;
} | [
"protected",
"function",
"compileBlock",
"(",
"$",
"expression",
")",
"{",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"\"/\\n*\\#block\\s*\\((.+?)(?:,(.+?))?\\)\\n*/m\"",
",",
"function",
"(",
"$",
"match",
")",
"{",
"array_shift",
"(",
"$",
"match",
")",
";",
"$",
"content",
"=",
"null",
";",
"if",
"(",
"count",
"(",
"$",
"match",
")",
"==",
"2",
")",
"{",
"$",
"content",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"content",
")",
")",
"{",
"return",
"\"<?php \\$__tintin->getStackManager()->startStack({$match[0]}); ?>\"",
";",
"}",
"else",
"{",
"return",
"\"<?php \\$__tintin->getStackManager()->startStack({$match[0]}, $content); ?>\"",
";",
"}",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the #block statement
@param string $expression
@return string | [
"Compile",
"the",
"#block",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileExtends.php#L34-L57 |
bowphp/tintin | src/Lexique/CompileExtends.php | CompileExtends.compileInclude | protected function compileInclude($expression)
{
$regex = "/\#include\s*\(((?:\n|\s|\t)*(?:.+?)(?:\n|\s|\t)*)\)/sm";
$output = preg_replace_callback($regex, function ($match) {
return "<?php echo \$__tintin->getStackManager()->includeFile({$match[1]}, ['__tintin' => \$__tintin]); ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | php | protected function compileInclude($expression)
{
$regex = "/\#include\s*\(((?:\n|\s|\t)*(?:.+?)(?:\n|\s|\t)*)\)/sm";
$output = preg_replace_callback($regex, function ($match) {
return "<?php echo \$__tintin->getStackManager()->includeFile({$match[1]}, ['__tintin' => \$__tintin]); ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | [
"protected",
"function",
"compileInclude",
"(",
"$",
"expression",
")",
"{",
"$",
"regex",
"=",
"\"/\\#include\\s*\\(((?:\\n|\\s|\\t)*(?:.+?)(?:\\n|\\s|\\t)*)\\)/sm\"",
";",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"$",
"regex",
",",
"function",
"(",
"$",
"match",
")",
"{",
"return",
"\"<?php echo \\$__tintin->getStackManager()->includeFile({$match[1]}, ['__tintin' => \\$__tintin]); ?>\"",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the #include statement
@param string $expression
@return string | [
"Compile",
"the",
"#include",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileExtends.php#L82-L91 |
bowphp/tintin | src/Lexique/CompileExtends.php | CompileExtends.compileExtends | protected function compileExtends($expression)
{
$regex = "/\#extends\s*\(((?:\n|\s|\t)*(?:.+?)(?:\n|\s|\t)*)\)/sm";
if (preg_match($regex, $expression, $match)) {
$this->footer[] = "<?php echo \$__tintin->getStackManager()->includeFile({$match[1]}, ['__tintin' => \$__tintin]); ?>";
return ' ';
}
return $expression;
} | php | protected function compileExtends($expression)
{
$regex = "/\#extends\s*\(((?:\n|\s|\t)*(?:.+?)(?:\n|\s|\t)*)\)/sm";
if (preg_match($regex, $expression, $match)) {
$this->footer[] = "<?php echo \$__tintin->getStackManager()->includeFile({$match[1]}, ['__tintin' => \$__tintin]); ?>";
return ' ';
}
return $expression;
} | [
"protected",
"function",
"compileExtends",
"(",
"$",
"expression",
")",
"{",
"$",
"regex",
"=",
"\"/\\#extends\\s*\\(((?:\\n|\\s|\\t)*(?:.+?)(?:\\n|\\s|\\t)*)\\)/sm\"",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"expression",
",",
"$",
"match",
")",
")",
"{",
"$",
"this",
"->",
"footer",
"[",
"]",
"=",
"\"<?php echo \\$__tintin->getStackManager()->includeFile({$match[1]}, ['__tintin' => \\$__tintin]); ?>\"",
";",
"return",
"' '",
";",
"}",
"return",
"$",
"expression",
";",
"}"
] | Compile the #extends statement
@param string $expression
@return string | [
"Compile",
"the",
"#extends",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileExtends.php#L100-L111 |
bowphp/tintin | src/Lexique/CompileExtends.php | CompileExtends.compileInject | protected function compileInject($expression)
{
$regex = "/\#inject\s*\(((?:\n|\s|\t)*(?:.+?)(?:\n|\s|\t)*)\)/sm";
$output = preg_replace_callback($regex, function ($match) {
return "<?php echo \$__tintin->getStackManager()->getStack({$match[1]}); ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | php | protected function compileInject($expression)
{
$regex = "/\#inject\s*\(((?:\n|\s|\t)*(?:.+?)(?:\n|\s|\t)*)\)/sm";
$output = preg_replace_callback($regex, function ($match) {
return "<?php echo \$__tintin->getStackManager()->getStack({$match[1]}); ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | [
"protected",
"function",
"compileInject",
"(",
"$",
"expression",
")",
"{",
"$",
"regex",
"=",
"\"/\\#inject\\s*\\(((?:\\n|\\s|\\t)*(?:.+?)(?:\\n|\\s|\\t)*)\\)/sm\"",
";",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"$",
"regex",
",",
"function",
"(",
"$",
"match",
")",
"{",
"return",
"\"<?php echo \\$__tintin->getStackManager()->getStack({$match[1]}); ?>\"",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the #inject statement
@param string $expression
@return string | [
"Compile",
"the",
"#inject",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileExtends.php#L120-L129 |
bowphp/tintin | src/Tintin.php | Tintin.render | public function render($template, array $data = [])
{
if (is_null($this->loader)) {
return $this->renderString($template, $data);
}
if (! $this->loader->exists($template)) {
$this->loader->failLoading($template .' not found');
}
$this->pushSharedData($data);
$__tintin = $this;
extract($this->getSharedData());
/**
* Load template when is not a cached file
*/
if (! $this->loader->isExpirated($template)) {
$this->obFlushAndStar();
require $this->loader->getCacheFileResolvedPath($template);
return $this->obGetContent();
}
/**
* Put the template into cache
*/
$content = $this->loader->getFileContent($template);
$this->loader->cache(
$template,
$this->compiler->compile($content)
);
$this->obFlushAndStar();
require $this->loader->getCacheFileResolvedPath($template);
return $this->obGetContent();
} | php | public function render($template, array $data = [])
{
if (is_null($this->loader)) {
return $this->renderString($template, $data);
}
if (! $this->loader->exists($template)) {
$this->loader->failLoading($template .' not found');
}
$this->pushSharedData($data);
$__tintin = $this;
extract($this->getSharedData());
/**
* Load template when is not a cached file
*/
if (! $this->loader->isExpirated($template)) {
$this->obFlushAndStar();
require $this->loader->getCacheFileResolvedPath($template);
return $this->obGetContent();
}
/**
* Put the template into cache
*/
$content = $this->loader->getFileContent($template);
$this->loader->cache(
$template,
$this->compiler->compile($content)
);
$this->obFlushAndStar();
require $this->loader->getCacheFileResolvedPath($template);
return $this->obGetContent();
} | [
"public",
"function",
"render",
"(",
"$",
"template",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"loader",
")",
")",
"{",
"return",
"$",
"this",
"->",
"renderString",
"(",
"$",
"template",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"loader",
"->",
"exists",
"(",
"$",
"template",
")",
")",
"{",
"$",
"this",
"->",
"loader",
"->",
"failLoading",
"(",
"$",
"template",
".",
"' not found'",
")",
";",
"}",
"$",
"this",
"->",
"pushSharedData",
"(",
"$",
"data",
")",
";",
"$",
"__tintin",
"=",
"$",
"this",
";",
"extract",
"(",
"$",
"this",
"->",
"getSharedData",
"(",
")",
")",
";",
"/**\n * Load template when is not a cached file\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"loader",
"->",
"isExpirated",
"(",
"$",
"template",
")",
")",
"{",
"$",
"this",
"->",
"obFlushAndStar",
"(",
")",
";",
"require",
"$",
"this",
"->",
"loader",
"->",
"getCacheFileResolvedPath",
"(",
"$",
"template",
")",
";",
"return",
"$",
"this",
"->",
"obGetContent",
"(",
")",
";",
"}",
"/**\n * Put the template into cache\n */",
"$",
"content",
"=",
"$",
"this",
"->",
"loader",
"->",
"getFileContent",
"(",
"$",
"template",
")",
";",
"$",
"this",
"->",
"loader",
"->",
"cache",
"(",
"$",
"template",
",",
"$",
"this",
"->",
"compiler",
"->",
"compile",
"(",
"$",
"content",
")",
")",
";",
"$",
"this",
"->",
"obFlushAndStar",
"(",
")",
";",
"require",
"$",
"this",
"->",
"loader",
"->",
"getCacheFileResolvedPath",
"(",
"$",
"template",
")",
";",
"return",
"$",
"this",
"->",
"obGetContent",
"(",
")",
";",
"}"
] | Make template rendering
@param string $template
@param array $data
@return string
@throws | [
"Make",
"template",
"rendering"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Tintin.php#L101-L143 |
bowphp/tintin | src/Tintin.php | Tintin.renderString | public function renderString($template, array $data = [])
{
return $this->executePlainRendering(
trim($this->compiler->compile($template)),
array_merge($data, ['__tintin' => $this])
);
} | php | public function renderString($template, array $data = [])
{
return $this->executePlainRendering(
trim($this->compiler->compile($template)),
array_merge($data, ['__tintin' => $this])
);
} | [
"public",
"function",
"renderString",
"(",
"$",
"template",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"executePlainRendering",
"(",
"trim",
"(",
"$",
"this",
"->",
"compiler",
"->",
"compile",
"(",
"$",
"template",
")",
")",
",",
"array_merge",
"(",
"$",
"data",
",",
"[",
"'__tintin'",
"=>",
"$",
"this",
"]",
")",
")",
";",
"}"
] | Compile simple template code
@param string $template
@param array $data
@return string | [
"Compile",
"simple",
"template",
"code"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Tintin.php#L153-L159 |
bowphp/tintin | src/Tintin.php | Tintin.executePlainRendering | private function executePlainRendering($content, $data)
{
$this->obFlushAndStar();
extract($data);
$filename = $this->createTmpFile($content);
require $filename;
@unlink($filename);
return $this->obGetContent();
} | php | private function executePlainRendering($content, $data)
{
$this->obFlushAndStar();
extract($data);
$filename = $this->createTmpFile($content);
require $filename;
@unlink($filename);
return $this->obGetContent();
} | [
"private",
"function",
"executePlainRendering",
"(",
"$",
"content",
",",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"obFlushAndStar",
"(",
")",
";",
"extract",
"(",
"$",
"data",
")",
";",
"$",
"filename",
"=",
"$",
"this",
"->",
"createTmpFile",
"(",
"$",
"content",
")",
";",
"require",
"$",
"filename",
";",
"@",
"unlink",
"(",
"$",
"filename",
")",
";",
"return",
"$",
"this",
"->",
"obGetContent",
"(",
")",
";",
"}"
] | Execute plain rendering code
@param string $content
@param array $data
@return string | [
"Execute",
"plain",
"rendering",
"code"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Tintin.php#L169-L182 |
bowphp/tintin | src/Tintin.php | Tintin.createTmpFile | private function createTmpFile($content)
{
$tmp_dir = sys_get_temp_dir().'/__tintin';
if (!is_dir($tmp_dir)) {
mkdir($tmp_dir, 0777);
}
$file = $tmp_dir.'/'.md5(microtime(true)).'.php';
file_put_contents($file, $content);
return $file;
} | php | private function createTmpFile($content)
{
$tmp_dir = sys_get_temp_dir().'/__tintin';
if (!is_dir($tmp_dir)) {
mkdir($tmp_dir, 0777);
}
$file = $tmp_dir.'/'.md5(microtime(true)).'.php';
file_put_contents($file, $content);
return $file;
} | [
"private",
"function",
"createTmpFile",
"(",
"$",
"content",
")",
"{",
"$",
"tmp_dir",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/__tintin'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"tmp_dir",
")",
")",
"{",
"mkdir",
"(",
"$",
"tmp_dir",
",",
"0777",
")",
";",
"}",
"$",
"file",
"=",
"$",
"tmp_dir",
".",
"'/'",
".",
"md5",
"(",
"microtime",
"(",
"true",
")",
")",
".",
"'.php'",
";",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"content",
")",
";",
"return",
"$",
"file",
";",
"}"
] | Create tmp compile file
@param string $content
@return string | [
"Create",
"tmp",
"compile",
"file"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Tintin.php#L213-L226 |
bowphp/tintin | src/Tintin.php | Tintin.directive | public function directive($name, $handler, $broken = false)
{
$this->compiler->pushDirective($name, $handler, $broken);
} | php | public function directive($name, $handler, $broken = false)
{
$this->compiler->pushDirective($name, $handler, $broken);
} | [
"public",
"function",
"directive",
"(",
"$",
"name",
",",
"$",
"handler",
",",
"$",
"broken",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"compiler",
"->",
"pushDirective",
"(",
"$",
"name",
",",
"$",
"handler",
",",
"$",
"broken",
")",
";",
"}"
] | Push more directive in template system
@param string $name
@param callable $handler
@param boolean $broken
@return mixed
@throws DirectiveNotAllowException | [
"Push",
"more",
"directive",
"in",
"template",
"system"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Tintin.php#L248-L251 |
bowphp/tintin | src/Bow/TintinEngine.php | TintinEngine.render | public function render($filename, array $data = [])
{
$filename = $this->checkParseFile($filename, false);
return $this->template->render($filename, $data);
} | php | public function render($filename, array $data = [])
{
$filename = $this->checkParseFile($filename, false);
return $this->template->render($filename, $data);
} | [
"public",
"function",
"render",
"(",
"$",
"filename",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"checkParseFile",
"(",
"$",
"filename",
",",
"false",
")",
";",
"return",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
"$",
"filename",
",",
"$",
"data",
")",
";",
"}"
] | {@inheritdoc}
@throws | [
"{"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Bow/TintinEngine.php#L50-L55 |
bowphp/tintin | src/Lexique/CompileRawPhp.php | CompileRawPhp.compileRawPhp | protected function compileRawPhp($expression)
{
$expression = trim($expression);
$output = preg_replace_callback(
'/\n*\#raw\s*(\n*(?:.+?)\n*)\#endraw\n*/m',
function ($match) {
array_shift($match);
return "<?php ".trim($match[0])." ?>";
},
$expression
);
return $output == $expression ? '' : $output;
} | php | protected function compileRawPhp($expression)
{
$expression = trim($expression);
$output = preg_replace_callback(
'/\n*\#raw\s*(\n*(?:.+?)\n*)\#endraw\n*/m',
function ($match) {
array_shift($match);
return "<?php ".trim($match[0])." ?>";
},
$expression
);
return $output == $expression ? '' : $output;
} | [
"protected",
"function",
"compileRawPhp",
"(",
"$",
"expression",
")",
"{",
"$",
"expression",
"=",
"trim",
"(",
"$",
"expression",
")",
";",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"'/\\n*\\#raw\\s*(\\n*(?:.+?)\\n*)\\#endraw\\n*/m'",
",",
"function",
"(",
"$",
"match",
")",
"{",
"array_shift",
"(",
"$",
"match",
")",
";",
"return",
"\"<?php \"",
".",
"trim",
"(",
"$",
"match",
"[",
"0",
"]",
")",
".",
"\" ?>\"",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the #raw...#endraw statement
@param string $expression
@return string | [
"Compile",
"the",
"#raw",
"...",
"#endraw",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileRawPhp.php#L14-L29 |
bowphp/tintin | src/Lexique/CompileLoop.php | CompileLoop.compileLoopStack | protected function compileLoopStack($expression)
{
foreach ($this->getLoopStack() as $token) {
$out = $this->{'compile'.$token}($expression);
if (strlen($out) !== 0) {
$expression = $out;
}
}
return $expression;
} | php | protected function compileLoopStack($expression)
{
foreach ($this->getLoopStack() as $token) {
$out = $this->{'compile'.$token}($expression);
if (strlen($out) !== 0) {
$expression = $out;
}
}
return $expression;
} | [
"protected",
"function",
"compileLoopStack",
"(",
"$",
"expression",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getLoopStack",
"(",
")",
"as",
"$",
"token",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"{",
"'compile'",
".",
"$",
"token",
"}",
"(",
"$",
"expression",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"out",
")",
"!==",
"0",
")",
"{",
"$",
"expression",
"=",
"$",
"out",
";",
"}",
"}",
"return",
"$",
"expression",
";",
"}"
] | Compile the loop statement stack
@param string $expression
@return string | [
"Compile",
"the",
"loop",
"statement",
"stack"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileLoop.php#L33-L44 |
bowphp/tintin | src/Lexique/CompileLoop.php | CompileLoop.compileLoop | private function compileLoop($expression, $lexic, $o_lexic)
{
$regex = sprintf($this->condition_patern, $lexic);
$output = preg_replace_callback($regex, function ($match) use ($o_lexic) {
array_shift($match);
return "<?php $o_lexic ({$match[1]}): ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | php | private function compileLoop($expression, $lexic, $o_lexic)
{
$regex = sprintf($this->condition_patern, $lexic);
$output = preg_replace_callback($regex, function ($match) use ($o_lexic) {
array_shift($match);
return "<?php $o_lexic ({$match[1]}): ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | [
"private",
"function",
"compileLoop",
"(",
"$",
"expression",
",",
"$",
"lexic",
",",
"$",
"o_lexic",
")",
"{",
"$",
"regex",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"condition_patern",
",",
"$",
"lexic",
")",
";",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"$",
"regex",
",",
"function",
"(",
"$",
"match",
")",
"use",
"(",
"$",
"o_lexic",
")",
"{",
"array_shift",
"(",
"$",
"match",
")",
";",
"return",
"\"<?php $o_lexic ({$match[1]}): ?>\"",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the #loop statement
@param string $expression
@param string $lexic
@param string $o_lexic
@return string | [
"Compile",
"the",
"#loop",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileLoop.php#L55-L66 |
bowphp/tintin | src/Lexique/CompileLoop.php | CompileLoop.compileEndLoop | private function compileEndLoop($expression, $lexic, $o_lexic)
{
$output = preg_replace_callback("/\n*$lexic\n*/", function () use ($o_lexic) {
return "<?php $o_lexic; ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | php | private function compileEndLoop($expression, $lexic, $o_lexic)
{
$output = preg_replace_callback("/\n*$lexic\n*/", function () use ($o_lexic) {
return "<?php $o_lexic; ?>";
}, $expression);
return $output == $expression ? '' : $output;
} | [
"private",
"function",
"compileEndLoop",
"(",
"$",
"expression",
",",
"$",
"lexic",
",",
"$",
"o_lexic",
")",
"{",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"\"/\\n*$lexic\\n*/\"",
",",
"function",
"(",
")",
"use",
"(",
"$",
"o_lexic",
")",
"{",
"return",
"\"<?php $o_lexic; ?>\"",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the #endloop statement
@param string $expression
@param string $lexic
@param string $o_lexic
@return string | [
"Compile",
"the",
"#endloop",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileLoop.php#L77-L84 |
bowphp/tintin | src/Lexique/CompileLoop.php | CompileLoop.compileBreaker | private function compileBreaker($expression, $lexic, $o_lexic)
{
$output = preg_replace_callback(
"/($lexic *(\(.+?\))|$lexic)/s",
function ($match) use ($lexic, $o_lexic) {
array_shift($match);
if (trim($match[0]) == $lexic) {
return "<?php $o_lexic; ?>";
}
return "<?php if {$match[1]}: $o_lexic; endif; ?>";
},
$expression
);
return $output == $expression ? '' : $output;
} | php | private function compileBreaker($expression, $lexic, $o_lexic)
{
$output = preg_replace_callback(
"/($lexic *(\(.+?\))|$lexic)/s",
function ($match) use ($lexic, $o_lexic) {
array_shift($match);
if (trim($match[0]) == $lexic) {
return "<?php $o_lexic; ?>";
}
return "<?php if {$match[1]}: $o_lexic; endif; ?>";
},
$expression
);
return $output == $expression ? '' : $output;
} | [
"private",
"function",
"compileBreaker",
"(",
"$",
"expression",
",",
"$",
"lexic",
",",
"$",
"o_lexic",
")",
"{",
"$",
"output",
"=",
"preg_replace_callback",
"(",
"\"/($lexic *(\\(.+?\\))|$lexic)/s\"",
",",
"function",
"(",
"$",
"match",
")",
"use",
"(",
"$",
"lexic",
",",
"$",
"o_lexic",
")",
"{",
"array_shift",
"(",
"$",
"match",
")",
";",
"if",
"(",
"trim",
"(",
"$",
"match",
"[",
"0",
"]",
")",
"==",
"$",
"lexic",
")",
"{",
"return",
"\"<?php $o_lexic; ?>\"",
";",
"}",
"return",
"\"<?php if {$match[1]}: $o_lexic; endif; ?>\"",
";",
"}",
",",
"$",
"expression",
")",
";",
"return",
"$",
"output",
"==",
"$",
"expression",
"?",
"''",
":",
"$",
"output",
";",
"}"
] | Compile the loop breaker statement
@param string $expression
@param string $lexic
@param string $o_lexic
@return string | [
"Compile",
"the",
"loop",
"breaker",
"statement"
] | train | https://github.com/bowphp/tintin/blob/80d7a4d18d1fac01448b97c7d9a9e575f32927df/src/Lexique/CompileLoop.php#L95-L112 |
koolphp/koolreport | src/core/AssetManager.php | AssetManager.publish | public function publish($assetFolder)
{
$widgetSourceAssetPath = dirname(Utility::getClassPath($this->widget))
."/".$assetFolder;
if (!is_dir($widgetSourceAssetPath)) {
throw new \Exception("Widget's assets folder is not existed");
}
$widgetSourceAssetPath = Utility::standardizePathSeparator(
realpath($widgetSourceAssetPath)
);
$this->assetUrl = $this->widget->getReport()->getResourceManager()->publishAssetFolder($widgetSourceAssetPath, $this->widget->version());
} | php | public function publish($assetFolder)
{
$widgetSourceAssetPath = dirname(Utility::getClassPath($this->widget))
."/".$assetFolder;
if (!is_dir($widgetSourceAssetPath)) {
throw new \Exception("Widget's assets folder is not existed");
}
$widgetSourceAssetPath = Utility::standardizePathSeparator(
realpath($widgetSourceAssetPath)
);
$this->assetUrl = $this->widget->getReport()->getResourceManager()->publishAssetFolder($widgetSourceAssetPath, $this->widget->version());
} | [
"public",
"function",
"publish",
"(",
"$",
"assetFolder",
")",
"{",
"$",
"widgetSourceAssetPath",
"=",
"dirname",
"(",
"Utility",
"::",
"getClassPath",
"(",
"$",
"this",
"->",
"widget",
")",
")",
".",
"\"/\"",
".",
"$",
"assetFolder",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"widgetSourceAssetPath",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Widget's assets folder is not existed\"",
")",
";",
"}",
"$",
"widgetSourceAssetPath",
"=",
"Utility",
"::",
"standardizePathSeparator",
"(",
"realpath",
"(",
"$",
"widgetSourceAssetPath",
")",
")",
";",
"$",
"this",
"->",
"assetUrl",
"=",
"$",
"this",
"->",
"widget",
"->",
"getReport",
"(",
")",
"->",
"getResourceManager",
"(",
")",
"->",
"publishAssetFolder",
"(",
"$",
"widgetSourceAssetPath",
",",
"$",
"this",
"->",
"widget",
"->",
"version",
"(",
")",
")",
";",
"}"
] | Publish an asset folder to public place
It will ask the report resource manager to check if widget resource
folder is available at public place. If not, then the resource manager
will copy local asset folder of widget to public place
@param string $assetFolder The local asset folder of a widget
@return null | [
"Publish",
"an",
"asset",
"folder",
"to",
"public",
"place"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/AssetManager.php#L96-L108 |
koolphp/koolreport | src/processes/CopyColumn.php | CopyColumn.onInput | public function onInput($data)
{
//Process data here
foreach ($this->params as $copy => $original) {
$data[$copy] = $data[$original];
}
$this->next($data);
} | php | public function onInput($data)
{
//Process data here
foreach ($this->params as $copy => $original) {
$data[$copy] = $data[$original];
}
$this->next($data);
} | [
"public",
"function",
"onInput",
"(",
"$",
"data",
")",
"{",
"//Process data here",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"copy",
"=>",
"$",
"original",
")",
"{",
"$",
"data",
"[",
"$",
"copy",
"]",
"=",
"$",
"data",
"[",
"$",
"original",
"]",
";",
"}",
"$",
"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/CopyColumn.php#L59-L66 |
koolphp/koolreport | src/core/ProcessGroup.php | ProcessGroup.receiveMeta | public function receiveMeta($metaData,$source)
{
$this->streamingSource = $source;
$this->metaData = $metaData;
$this->startProcess->receiveMeta($metaData, $this);
} | php | public function receiveMeta($metaData,$source)
{
$this->streamingSource = $source;
$this->metaData = $metaData;
$this->startProcess->receiveMeta($metaData, $this);
} | [
"public",
"function",
"receiveMeta",
"(",
"$",
"metaData",
",",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"streamingSource",
"=",
"$",
"source",
";",
"$",
"this",
"->",
"metaData",
"=",
"$",
"metaData",
";",
"$",
"this",
"->",
"startProcess",
"->",
"receiveMeta",
"(",
"$",
"metaData",
",",
"$",
"this",
")",
";",
"}"
] | Receive the meta data from source
@param array $metaData Metadata sent from source nodes
@param Process $source The source process
@return null | [
"Receive",
"the",
"meta",
"data",
"from",
"source"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ProcessGroup.php#L120-L125 |
koolphp/koolreport | src/core/Utility.php | Utility.guessType | static function guessType($value)
{
$map = array(
"float"=>"number",
"double"=>"number",
"int"=>"number",
"integer"=>"number",
"bool"=>"number",
"numeric"=>"number",
"string"=>"string",
);
$type = strtolower(gettype($value));
foreach ($map as $key=>$value) {
if (strpos($type, $key)!==false) {
return $value;
}
}
return "unknown";
} | php | static function guessType($value)
{
$map = array(
"float"=>"number",
"double"=>"number",
"int"=>"number",
"integer"=>"number",
"bool"=>"number",
"numeric"=>"number",
"string"=>"string",
);
$type = strtolower(gettype($value));
foreach ($map as $key=>$value) {
if (strpos($type, $key)!==false) {
return $value;
}
}
return "unknown";
} | [
"static",
"function",
"guessType",
"(",
"$",
"value",
")",
"{",
"$",
"map",
"=",
"array",
"(",
"\"float\"",
"=>",
"\"number\"",
",",
"\"double\"",
"=>",
"\"number\"",
",",
"\"int\"",
"=>",
"\"number\"",
",",
"\"integer\"",
"=>",
"\"number\"",
",",
"\"bool\"",
"=>",
"\"number\"",
",",
"\"numeric\"",
"=>",
"\"number\"",
",",
"\"string\"",
"=>",
"\"string\"",
",",
")",
";",
"$",
"type",
"=",
"strtolower",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"$",
"key",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"return",
"\"unknown\"",
";",
"}"
] | Try to get type of a value
@param mixed $value A value needed to guess type
@return string Possible type of a value | [
"Try",
"to",
"get",
"type",
"of",
"a",
"value"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L53-L72 |
koolphp/koolreport | src/core/Utility.php | Utility.format | static function format($value,$format)
{
$f = Utility::get($format, "format", true);
if ($f===false) {
return $value;
}
$type = Utility::get($format, "type", "unknown");
switch($type)
{
case "number":
$decimals = Utility::get($format, "decimals", 0);
$dec_point = Utility::get(
$format,
"decPoint",
Utility::get(
$format,
"decimalPoint",
Utility::get(
$format,
"dec_point",
"."
)
)
);
$thousand_sep = Utility::get(
$format,
"thousandSep",
Utility::get(
$format,
"thousandSeparator",
Utility::get(
$format,
"thousand_sep",
","
)
)
);
$prefix = Utility::get($format, "prefix", "");
$suffix = Utility::get($format, "suffix", "");
return $prefix
.number_format($value, $decimals, $dec_point, $thousand_sep)
.$suffix;
break;
case "string":
$prefix = Utility::get($format, "prefix", "");
$suffix = Utility::get($format, "suffix", "");
return $prefix.$value.$suffix;
break;
case "datetime":
$dateFormat = Utility::get($format, "format", "Y-m-d H:i:s");
case "date":
$dateFormat = isset($dateFormat)
?$dateFormat
:Utility::get($format, "format", "Y-m-d");
case "time":
$dateFormat = isset($dateFormat)
?$dateFormat
:Utility::get($format, "format", "H:i:s");
$displayFormat = Utility::get($format, "displayFormat");
if ($displayFormat && $value) {
if ($fvalue = \DateTime::createFromFormat($dateFormat, $value)) {
return $fvalue->format($displayFormat);
}
}
break;
}
return $value;
} | php | static function format($value,$format)
{
$f = Utility::get($format, "format", true);
if ($f===false) {
return $value;
}
$type = Utility::get($format, "type", "unknown");
switch($type)
{
case "number":
$decimals = Utility::get($format, "decimals", 0);
$dec_point = Utility::get(
$format,
"decPoint",
Utility::get(
$format,
"decimalPoint",
Utility::get(
$format,
"dec_point",
"."
)
)
);
$thousand_sep = Utility::get(
$format,
"thousandSep",
Utility::get(
$format,
"thousandSeparator",
Utility::get(
$format,
"thousand_sep",
","
)
)
);
$prefix = Utility::get($format, "prefix", "");
$suffix = Utility::get($format, "suffix", "");
return $prefix
.number_format($value, $decimals, $dec_point, $thousand_sep)
.$suffix;
break;
case "string":
$prefix = Utility::get($format, "prefix", "");
$suffix = Utility::get($format, "suffix", "");
return $prefix.$value.$suffix;
break;
case "datetime":
$dateFormat = Utility::get($format, "format", "Y-m-d H:i:s");
case "date":
$dateFormat = isset($dateFormat)
?$dateFormat
:Utility::get($format, "format", "Y-m-d");
case "time":
$dateFormat = isset($dateFormat)
?$dateFormat
:Utility::get($format, "format", "H:i:s");
$displayFormat = Utility::get($format, "displayFormat");
if ($displayFormat && $value) {
if ($fvalue = \DateTime::createFromFormat($dateFormat, $value)) {
return $fvalue->format($displayFormat);
}
}
break;
}
return $value;
} | [
"static",
"function",
"format",
"(",
"$",
"value",
",",
"$",
"format",
")",
"{",
"$",
"f",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"format\"",
",",
"true",
")",
";",
"if",
"(",
"$",
"f",
"===",
"false",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"type",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"type\"",
",",
"\"unknown\"",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"\"number\"",
":",
"$",
"decimals",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"decimals\"",
",",
"0",
")",
";",
"$",
"dec_point",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"decPoint\"",
",",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"decimalPoint\"",
",",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"dec_point\"",
",",
"\".\"",
")",
")",
")",
";",
"$",
"thousand_sep",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"thousandSep\"",
",",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"thousandSeparator\"",
",",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"thousand_sep\"",
",",
"\",\"",
")",
")",
")",
";",
"$",
"prefix",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"prefix\"",
",",
"\"\"",
")",
";",
"$",
"suffix",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"suffix\"",
",",
"\"\"",
")",
";",
"return",
"$",
"prefix",
".",
"number_format",
"(",
"$",
"value",
",",
"$",
"decimals",
",",
"$",
"dec_point",
",",
"$",
"thousand_sep",
")",
".",
"$",
"suffix",
";",
"break",
";",
"case",
"\"string\"",
":",
"$",
"prefix",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"prefix\"",
",",
"\"\"",
")",
";",
"$",
"suffix",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"suffix\"",
",",
"\"\"",
")",
";",
"return",
"$",
"prefix",
".",
"$",
"value",
".",
"$",
"suffix",
";",
"break",
";",
"case",
"\"datetime\"",
":",
"$",
"dateFormat",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"format\"",
",",
"\"Y-m-d H:i:s\"",
")",
";",
"case",
"\"date\"",
":",
"$",
"dateFormat",
"=",
"isset",
"(",
"$",
"dateFormat",
")",
"?",
"$",
"dateFormat",
":",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"format\"",
",",
"\"Y-m-d\"",
")",
";",
"case",
"\"time\"",
":",
"$",
"dateFormat",
"=",
"isset",
"(",
"$",
"dateFormat",
")",
"?",
"$",
"dateFormat",
":",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"format\"",
",",
"\"H:i:s\"",
")",
";",
"$",
"displayFormat",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"displayFormat\"",
")",
";",
"if",
"(",
"$",
"displayFormat",
"&&",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"fvalue",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"dateFormat",
",",
"$",
"value",
")",
")",
"{",
"return",
"$",
"fvalue",
"->",
"format",
"(",
"$",
"displayFormat",
")",
";",
"}",
"}",
"break",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Format the value with provided format settings
@param mixed $value Value we want to format
@param array $format The format settings of the value
@return string Formatted value in string | [
"Format",
"the",
"value",
"with",
"provided",
"format",
"settings"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L106-L175 |
koolphp/koolreport | src/core/Utility.php | Utility.mark_js_function | static function mark_js_function(&$obj,&$marks=array())
{
foreach ($obj as $k=>&$v) {
switch(gettype($v))
{
case "object":
case "array":
Utility::mark_js_function($v, $marks);
break;
case "string":
$tsv = trim(strtolower($v));
if (strpos($tsv, "function")===0
&& (strrpos($tsv, "}")===strlen($tsv)-1
|| strrpos($tsv, "()")===strlen($tsv)-2)
) {
$marks[] = trim($v);
$obj[$k] = "--js(".(count($marks)-1).")";
}
break;
}
}
return $marks;
} | php | static function mark_js_function(&$obj,&$marks=array())
{
foreach ($obj as $k=>&$v) {
switch(gettype($v))
{
case "object":
case "array":
Utility::mark_js_function($v, $marks);
break;
case "string":
$tsv = trim(strtolower($v));
if (strpos($tsv, "function")===0
&& (strrpos($tsv, "}")===strlen($tsv)-1
|| strrpos($tsv, "()")===strlen($tsv)-2)
) {
$marks[] = trim($v);
$obj[$k] = "--js(".(count($marks)-1).")";
}
break;
}
}
return $marks;
} | [
"static",
"function",
"mark_js_function",
"(",
"&",
"$",
"obj",
",",
"&",
"$",
"marks",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"obj",
"as",
"$",
"k",
"=>",
"&",
"$",
"v",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"v",
")",
")",
"{",
"case",
"\"object\"",
":",
"case",
"\"array\"",
":",
"Utility",
"::",
"mark_js_function",
"(",
"$",
"v",
",",
"$",
"marks",
")",
";",
"break",
";",
"case",
"\"string\"",
":",
"$",
"tsv",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"v",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"tsv",
",",
"\"function\"",
")",
"===",
"0",
"&&",
"(",
"strrpos",
"(",
"$",
"tsv",
",",
"\"}\"",
")",
"===",
"strlen",
"(",
"$",
"tsv",
")",
"-",
"1",
"||",
"strrpos",
"(",
"$",
"tsv",
",",
"\"()\"",
")",
"===",
"strlen",
"(",
"$",
"tsv",
")",
"-",
"2",
")",
")",
"{",
"$",
"marks",
"[",
"]",
"=",
"trim",
"(",
"$",
"v",
")",
";",
"$",
"obj",
"[",
"$",
"k",
"]",
"=",
"\"--js(\"",
".",
"(",
"count",
"(",
"$",
"marks",
")",
"-",
"1",
")",
".",
"\")\"",
";",
"}",
"break",
";",
"}",
"}",
"return",
"$",
"marks",
";",
"}"
] | Traverse through the structure of object and find the js function
@param object $obj The object
@param array $marks The mark
@return array The new marks | [
"Traverse",
"through",
"the",
"structure",
"of",
"object",
"and",
"find",
"the",
"js",
"function"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L200-L222 |
koolphp/koolreport | src/core/Utility.php | Utility.jsonEncode | static function jsonEncode($object,$option=0)
{
$marks = Utility::mark_js_function($object);
$text = json_encode($object, $option);
foreach ($marks as $i=>$js) {
$text = str_replace("\"--js($i)\"", $js, $text);
}
return $text;
} | php | static function jsonEncode($object,$option=0)
{
$marks = Utility::mark_js_function($object);
$text = json_encode($object, $option);
foreach ($marks as $i=>$js) {
$text = str_replace("\"--js($i)\"", $js, $text);
}
return $text;
} | [
"static",
"function",
"jsonEncode",
"(",
"$",
"object",
",",
"$",
"option",
"=",
"0",
")",
"{",
"$",
"marks",
"=",
"Utility",
"::",
"mark_js_function",
"(",
"$",
"object",
")",
";",
"$",
"text",
"=",
"json_encode",
"(",
"$",
"object",
",",
"$",
"option",
")",
";",
"foreach",
"(",
"$",
"marks",
"as",
"$",
"i",
"=>",
"$",
"js",
")",
"{",
"$",
"text",
"=",
"str_replace",
"(",
"\"\\\"--js($i)\\\"\"",
",",
"$",
"js",
",",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Get the json of an object
@param object $object The object needs to be encoded
@param int $option The json_encode() additional option
@return string The json string of objects | [
"Get",
"the",
"json",
"of",
"an",
"object"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L232-L240 |
koolphp/koolreport | src/core/Utility.php | Utility.isAssoc | static function isAssoc($arr)
{
if (gettype($arr)!="array") {
return false;
}
if ($arr===null || $arr===array()) {
return false;
}
if (array_keys($arr)===range(0, count($arr)-1)) {
return false;
}
return true;
} | php | static function isAssoc($arr)
{
if (gettype($arr)!="array") {
return false;
}
if ($arr===null || $arr===array()) {
return false;
}
if (array_keys($arr)===range(0, count($arr)-1)) {
return false;
}
return true;
} | [
"static",
"function",
"isAssoc",
"(",
"$",
"arr",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"arr",
")",
"!=",
"\"array\"",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"arr",
"===",
"null",
"||",
"$",
"arr",
"===",
"array",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"array_keys",
"(",
"$",
"arr",
")",
"===",
"range",
"(",
"0",
",",
"count",
"(",
"$",
"arr",
")",
"-",
"1",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Get wether an array is an associate array
@param array $arr The array that you want to test
@return bool Whether the array is an associate array | [
"Get",
"wether",
"an",
"array",
"is",
"an",
"associate",
"array"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L249-L261 |
koolphp/koolreport | src/core/Utility.php | Utility.get | static function get($arr,$keys,$default=null)
{
if (! is_array($arr)) {
return $default;
}
if (is_array($keys) and count($keys) > 0) {
foreach ($keys as $key) {
$arr = self::get($arr, $key, $default);
}
return $arr;
}
if (is_string($keys) || is_int($keys)) {
return isset($arr[$keys]) ? $arr[$keys] : $default;
}
return $default;
} | php | static function get($arr,$keys,$default=null)
{
if (! is_array($arr)) {
return $default;
}
if (is_array($keys) and count($keys) > 0) {
foreach ($keys as $key) {
$arr = self::get($arr, $key, $default);
}
return $arr;
}
if (is_string($keys) || is_int($keys)) {
return isset($arr[$keys]) ? $arr[$keys] : $default;
}
return $default;
} | [
"static",
"function",
"get",
"(",
"$",
"arr",
",",
"$",
"keys",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arr",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"keys",
")",
"and",
"count",
"(",
"$",
"keys",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"arr",
"=",
"self",
"::",
"get",
"(",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"arr",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"keys",
")",
"||",
"is_int",
"(",
"$",
"keys",
")",
")",
"{",
"return",
"isset",
"(",
"$",
"arr",
"[",
"$",
"keys",
"]",
")",
"?",
"$",
"arr",
"[",
"$",
"keys",
"]",
":",
"$",
"default",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Get value from array with keys, return default if not found
The function support the list of keys in order as well
@param array $arr The array that you want to test
@param mixed $keys Could be name of key or an array containing list of key path
@param mixed $default Default value if no value for key is found
@return mixed Value at key path | [
"Get",
"value",
"from",
"array",
"with",
"keys",
"return",
"default",
"if",
"not",
"found"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L274-L289 |
koolphp/koolreport | src/core/Utility.php | Utility.init | static function init(&$arr, $key, $default = null)
{
if (! isset($arr[$key])) {
$arr[$key] = $default;
}
return $arr[$key];
} | php | static function init(&$arr, $key, $default = null)
{
if (! isset($arr[$key])) {
$arr[$key] = $default;
}
return $arr[$key];
} | [
"static",
"function",
"init",
"(",
"&",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"arr",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"arr",
"[",
"$",
"key",
"]",
"=",
"$",
"default",
";",
"}",
"return",
"$",
"arr",
"[",
"$",
"key",
"]",
";",
"}"
] | Init an key value inside an array
@param array $arr The array
@param string $key The key
@param mixed $default The default value to fill if key is not found
@return array The array | [
"Init",
"an",
"key",
"value",
"inside",
"an",
"array"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L299-L305 |
koolphp/koolreport | src/core/Utility.php | Utility.getArray | static function getArray($arr,$key,$default=array())
{
$value = Utility::get($arr, $key);
return ($value!=null)?explode(',', $value):$default;
} | php | static function getArray($arr,$key,$default=array())
{
$value = Utility::get($arr, $key);
return ($value!=null)?explode(',', $value):$default;
} | [
"static",
"function",
"getArray",
"(",
"$",
"arr",
",",
"$",
"key",
",",
"$",
"default",
"=",
"array",
"(",
")",
")",
"{",
"$",
"value",
"=",
"Utility",
"::",
"get",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"return",
"(",
"$",
"value",
"!=",
"null",
")",
"?",
"explode",
"(",
"','",
",",
"$",
"value",
")",
":",
"$",
"default",
";",
"}"
] | Get array if the value inside an array is a string
@param array $arr The array
@param string $key The key
@param mixed $default The default value
@return array Return array result | [
"Get",
"array",
"if",
"the",
"value",
"inside",
"an",
"array",
"is",
"a",
"string"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L316-L320 |
koolphp/koolreport | src/core/Utility.php | Utility.filterIn | static function filterIn($arr,$keys)
{
$keys = explode(",", $keys);
$result = array();
foreach ($arr as $key=>$value) {
if (in_array($key, $keys)) {
$result[$key] = $value;
}
}
return $result;
} | php | static function filterIn($arr,$keys)
{
$keys = explode(",", $keys);
$result = array();
foreach ($arr as $key=>$value) {
if (in_array($key, $keys)) {
$result[$key] = $value;
}
}
return $result;
} | [
"static",
"function",
"filterIn",
"(",
"$",
"arr",
",",
"$",
"keys",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"\",\"",
",",
"$",
"keys",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"keys",
")",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get only some of the keys from an array
@param array $arr The array
@param string $keys List of keys in string and separate with comma(,)
@return array The filtered array with only specified keys | [
"Get",
"only",
"some",
"of",
"the",
"keys",
"from",
"an",
"array"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L330-L340 |
koolphp/koolreport | src/core/Utility.php | Utility.strReplace | static function strReplace($str,$params)
{
foreach ($params as $k=>$v) {
$str = str_replace($k, $v, $str);
}
return $str;
} | php | static function strReplace($str,$params)
{
foreach ($params as $k=>$v) {
$str = str_replace($k, $v, $str);
}
return $str;
} | [
"static",
"function",
"strReplace",
"(",
"$",
"str",
",",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"str",
"=",
"str_replace",
"(",
"$",
"k",
",",
"$",
"v",
",",
"$",
"str",
")",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | A mass string replace with parameters
@param string $str The template string
@param array $params An associate array containing key value to replace
@return string The string that is replaced key with value | [
"A",
"mass",
"string",
"replace",
"with",
"parameters"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L369-L375 |
koolphp/koolreport | src/core/Utility.php | Utility.str_replace_first | static function str_replace_first($from, $to, $content)
{
$from = '/'.preg_quote($from, '/').'/';
return preg_replace($from, $to, $content, 1);
} | php | static function str_replace_first($from, $to, $content)
{
$from = '/'.preg_quote($from, '/').'/';
return preg_replace($from, $to, $content, 1);
} | [
"static",
"function",
"str_replace_first",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"content",
")",
"{",
"$",
"from",
"=",
"'/'",
".",
"preg_quote",
"(",
"$",
"from",
",",
"'/'",
")",
".",
"'/'",
";",
"return",
"preg_replace",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"content",
",",
"1",
")",
";",
"}"
] | Return string with replaced first occurerence only
@param string $from The needle
@param string $to The replacement
@param string $content The haystack
@return string String with replaced first occurerence only | [
"Return",
"string",
"with",
"replaced",
"first",
"occurerence",
"only"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L413-L417 |
koolphp/koolreport | src/core/Utility.php | Utility.getDocumentRoot | static function getDocumentRoot()
{
//The old method is to use the document_root from $_SERVER
//Howerver in some hosting the document root is not the same
//with the root folder of the website, so we add backup with
//second way to calculate the document root with script_name
//and script_filename
$old_way = str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"]));
$script_filename = str_replace(
"\\",
"/",
realpath($_SERVER["SCRIPT_FILENAME"])
);
$script_name = str_replace("\\", "/", realpath($_SERVER["SCRIPT_NAME"]));
$new_way = str_replace($script_name, "", $script_filename);
if ($old_way==$new_way) {
return $old_way;
} else if (is_dir($old_way)) {
return $old_way;
} else {
return $new_way;
}
} | php | static function getDocumentRoot()
{
//The old method is to use the document_root from $_SERVER
//Howerver in some hosting the document root is not the same
//with the root folder of the website, so we add backup with
//second way to calculate the document root with script_name
//and script_filename
$old_way = str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"]));
$script_filename = str_replace(
"\\",
"/",
realpath($_SERVER["SCRIPT_FILENAME"])
);
$script_name = str_replace("\\", "/", realpath($_SERVER["SCRIPT_NAME"]));
$new_way = str_replace($script_name, "", $script_filename);
if ($old_way==$new_way) {
return $old_way;
} else if (is_dir($old_way)) {
return $old_way;
} else {
return $new_way;
}
} | [
"static",
"function",
"getDocumentRoot",
"(",
")",
"{",
"//The old method is to use the document_root from $_SERVER",
"//Howerver in some hosting the document root is not the same",
"//with the root folder of the website, so we add backup with",
"//second way to calculate the document root with script_name ",
"//and script_filename",
"$",
"old_way",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"realpath",
"(",
"$",
"_SERVER",
"[",
"\"DOCUMENT_ROOT\"",
"]",
")",
")",
";",
"$",
"script_filename",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"realpath",
"(",
"$",
"_SERVER",
"[",
"\"SCRIPT_FILENAME\"",
"]",
")",
")",
";",
"$",
"script_name",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"realpath",
"(",
"$",
"_SERVER",
"[",
"\"SCRIPT_NAME\"",
"]",
")",
")",
";",
"$",
"new_way",
"=",
"str_replace",
"(",
"$",
"script_name",
",",
"\"\"",
",",
"$",
"script_filename",
")",
";",
"if",
"(",
"$",
"old_way",
"==",
"$",
"new_way",
")",
"{",
"return",
"$",
"old_way",
";",
"}",
"else",
"if",
"(",
"is_dir",
"(",
"$",
"old_way",
")",
")",
"{",
"return",
"$",
"old_way",
";",
"}",
"else",
"{",
"return",
"$",
"new_way",
";",
"}",
"}"
] | Get the doument root
@return string the document root path | [
"Get",
"the",
"doument",
"root"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L424-L447 |
koolphp/koolreport | src/core/Utility.php | Utility.getSymbolicPath | static function getSymbolicPath($realpath)
{
$root = $_SERVER['DOCUMENT_ROOT'];
$script = $_SERVER['SCRIPT_FILENAME'];
$root = str_replace('\\', '/', $root);
$script = str_replace('\\', '/', $script);
$realpath = str_replace('\\', '/', $realpath);
$dir = str_replace($root, '', $script);
$pos = false;
$dir = self::getDir($dir);
while (! empty($dir)) {
$pos = strpos($realpath, $dir);
if ($pos) {
break;
}
$dir = self::getDir($dir);
}
if ($pos) {
$realpath = $root . substr($realpath, $pos);
}
return $realpath;
} | php | static function getSymbolicPath($realpath)
{
$root = $_SERVER['DOCUMENT_ROOT'];
$script = $_SERVER['SCRIPT_FILENAME'];
$root = str_replace('\\', '/', $root);
$script = str_replace('\\', '/', $script);
$realpath = str_replace('\\', '/', $realpath);
$dir = str_replace($root, '', $script);
$pos = false;
$dir = self::getDir($dir);
while (! empty($dir)) {
$pos = strpos($realpath, $dir);
if ($pos) {
break;
}
$dir = self::getDir($dir);
}
if ($pos) {
$realpath = $root . substr($realpath, $pos);
}
return $realpath;
} | [
"static",
"function",
"getSymbolicPath",
"(",
"$",
"realpath",
")",
"{",
"$",
"root",
"=",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
";",
"$",
"script",
"=",
"$",
"_SERVER",
"[",
"'SCRIPT_FILENAME'",
"]",
";",
"$",
"root",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"root",
")",
";",
"$",
"script",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"script",
")",
";",
"$",
"realpath",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"realpath",
")",
";",
"$",
"dir",
"=",
"str_replace",
"(",
"$",
"root",
",",
"''",
",",
"$",
"script",
")",
";",
"$",
"pos",
"=",
"false",
";",
"$",
"dir",
"=",
"self",
"::",
"getDir",
"(",
"$",
"dir",
")",
";",
"while",
"(",
"!",
"empty",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"realpath",
",",
"$",
"dir",
")",
";",
"if",
"(",
"$",
"pos",
")",
"{",
"break",
";",
"}",
"$",
"dir",
"=",
"self",
"::",
"getDir",
"(",
"$",
"dir",
")",
";",
"}",
"if",
"(",
"$",
"pos",
")",
"{",
"$",
"realpath",
"=",
"$",
"root",
".",
"substr",
"(",
"$",
"realpath",
",",
"$",
"pos",
")",
";",
"}",
"return",
"$",
"realpath",
";",
"}"
] | Get the dirname
@param string $realpath The real path
@return string Return the symbolic path | [
"Get",
"the",
"dirname"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Utility.php#L481-L503 |
koolphp/koolreport | src/datasources/PdoDataSource.php | PdoDataSource.onInit | protected function onInit()
{
// $this->connection = Util::get($this->params,"connection",null);
$connectionString = Util::get($this->params, "connectionString", "");
$username = Util::get($this->params, "username", "");
$password = Util::get($this->params, "password", "");
$charset = Util::get($this->params, "charset");
$key = md5($connectionString.$username.$password);
if (PdoDataSource::$connections==null) {
PdoDataSource::$connections = array();
}
if (isset(PdoDataSource::$connections[$key])) {
$this->connection = PdoDataSource::$connections[$key];
} else {
$this->connection = new PDO($connectionString, $username, $password);
PdoDataSource::$connections[$key] = $this->connection;
}
if ($charset) {
$this->connection->exec("set names '$charset'");
}
} | php | protected function onInit()
{
// $this->connection = Util::get($this->params,"connection",null);
$connectionString = Util::get($this->params, "connectionString", "");
$username = Util::get($this->params, "username", "");
$password = Util::get($this->params, "password", "");
$charset = Util::get($this->params, "charset");
$key = md5($connectionString.$username.$password);
if (PdoDataSource::$connections==null) {
PdoDataSource::$connections = array();
}
if (isset(PdoDataSource::$connections[$key])) {
$this->connection = PdoDataSource::$connections[$key];
} else {
$this->connection = new PDO($connectionString, $username, $password);
PdoDataSource::$connections[$key] = $this->connection;
}
if ($charset) {
$this->connection->exec("set names '$charset'");
}
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"// $this->connection = Util::get($this->params,\"connection\",null);",
"$",
"connectionString",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"connectionString\"",
",",
"\"\"",
")",
";",
"$",
"username",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"username\"",
",",
"\"\"",
")",
";",
"$",
"password",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"password\"",
",",
"\"\"",
")",
";",
"$",
"charset",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"charset\"",
")",
";",
"$",
"key",
"=",
"md5",
"(",
"$",
"connectionString",
".",
"$",
"username",
".",
"$",
"password",
")",
";",
"if",
"(",
"PdoDataSource",
"::",
"$",
"connections",
"==",
"null",
")",
"{",
"PdoDataSource",
"::",
"$",
"connections",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"PdoDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"PdoDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"connection",
"=",
"new",
"PDO",
"(",
"$",
"connectionString",
",",
"$",
"username",
",",
"$",
"password",
")",
";",
"PdoDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"connection",
";",
"}",
"if",
"(",
"$",
"charset",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"exec",
"(",
"\"set names '$charset'\"",
")",
";",
"}",
"}"
] | Datasource initiation
@return null | [
"Datasource",
"initiation"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PdoDataSource.php#L94-L115 |
koolphp/koolreport | src/datasources/PdoDataSource.php | PdoDataSource.query | public function query($query,$sqlParams=null)
{
$this->query = (string)$query;
if ($sqlParams!=null) {
$this->sqlParams = $sqlParams;
}
return $this;
} | php | public function query($query,$sqlParams=null)
{
$this->query = (string)$query;
if ($sqlParams!=null) {
$this->sqlParams = $sqlParams;
}
return $this;
} | [
"public",
"function",
"query",
"(",
"$",
"query",
",",
"$",
"sqlParams",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"query",
"=",
"(",
"string",
")",
"$",
"query",
";",
"if",
"(",
"$",
"sqlParams",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"sqlParams",
"=",
"$",
"sqlParams",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the query and params
@param string $query The SQL query statement
@param array $sqlParams The parameters of SQL query
@return PdoDataSource This datasource object | [
"Set",
"the",
"query",
"and",
"params"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PdoDataSource.php#L125-L132 |
koolphp/koolreport | src/datasources/PdoDataSource.php | PdoDataSource.queryProcessing | public function queryProcessing($queryParams)
{
$driver = strtolower($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME));
//drivers = Array ( [0] => mysql [1] => oci [2] => pgsql [3] => sqlite [4] => sqlsrv )
switch ($driver) {
case 'mysql':
list($this->query, $this->totalQuery, $this->filterQuery)
= MySQLDataSource::processQuery($this->query, $queryParams);
break;
case 'oci':
list($this->query, $this->totalQuery, $this->filterQuery)
= OracleDataSource::processQuery($this->query, $queryParams);
break;
case 'pgsql':
list($this->query, $this->totalQuery, $this->filterQuery)
= PostgreSQLDataSource::processQuery($this->query, $queryParams);
break;
case 'sqlsrv':
list($this->query, $this->totalQuery, $this->filterQuery)
= SQLSRVDataSource::processQuery($this->query, $queryParams);
break;
default:
break;
}
$this->countTotal = Util::get($queryParams, 'countTotal', false);
$this->countFilter = Util::get($queryParams, 'countFilter', false);
return $this;
} | php | public function queryProcessing($queryParams)
{
$driver = strtolower($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME));
//drivers = Array ( [0] => mysql [1] => oci [2] => pgsql [3] => sqlite [4] => sqlsrv )
switch ($driver) {
case 'mysql':
list($this->query, $this->totalQuery, $this->filterQuery)
= MySQLDataSource::processQuery($this->query, $queryParams);
break;
case 'oci':
list($this->query, $this->totalQuery, $this->filterQuery)
= OracleDataSource::processQuery($this->query, $queryParams);
break;
case 'pgsql':
list($this->query, $this->totalQuery, $this->filterQuery)
= PostgreSQLDataSource::processQuery($this->query, $queryParams);
break;
case 'sqlsrv':
list($this->query, $this->totalQuery, $this->filterQuery)
= SQLSRVDataSource::processQuery($this->query, $queryParams);
break;
default:
break;
}
$this->countTotal = Util::get($queryParams, 'countTotal', false);
$this->countFilter = Util::get($queryParams, 'countFilter', false);
return $this;
} | [
"public",
"function",
"queryProcessing",
"(",
"$",
"queryParams",
")",
"{",
"$",
"driver",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"connection",
"->",
"getAttribute",
"(",
"PDO",
"::",
"ATTR_DRIVER_NAME",
")",
")",
";",
"//drivers = Array ( [0] => mysql [1] => oci [2] => pgsql [3] => sqlite [4] => sqlsrv )",
"switch",
"(",
"$",
"driver",
")",
"{",
"case",
"'mysql'",
":",
"list",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"totalQuery",
",",
"$",
"this",
"->",
"filterQuery",
")",
"=",
"MySQLDataSource",
"::",
"processQuery",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"queryParams",
")",
";",
"break",
";",
"case",
"'oci'",
":",
"list",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"totalQuery",
",",
"$",
"this",
"->",
"filterQuery",
")",
"=",
"OracleDataSource",
"::",
"processQuery",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"queryParams",
")",
";",
"break",
";",
"case",
"'pgsql'",
":",
"list",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"totalQuery",
",",
"$",
"this",
"->",
"filterQuery",
")",
"=",
"PostgreSQLDataSource",
"::",
"processQuery",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"queryParams",
")",
";",
"break",
";",
"case",
"'sqlsrv'",
":",
"list",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"totalQuery",
",",
"$",
"this",
"->",
"filterQuery",
")",
"=",
"SQLSRVDataSource",
"::",
"processQuery",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"queryParams",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"$",
"this",
"->",
"countTotal",
"=",
"Util",
"::",
"get",
"(",
"$",
"queryParams",
",",
"'countTotal'",
",",
"false",
")",
";",
"$",
"this",
"->",
"countFilter",
"=",
"Util",
"::",
"get",
"(",
"$",
"queryParams",
",",
"'countFilter'",
",",
"false",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Transform query
@param array $queryParams Parameters of query
@return null | [
"Transform",
"query"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PdoDataSource.php#L141-L168 |
koolphp/koolreport | src/datasources/PdoDataSource.php | PdoDataSource.prepareParams | protected function prepareParams($query, $sqlParams)
{
if (empty($sqlParams)) {
$sqlParams = [];
}
uksort(
$sqlParams,
function ($k1, $k2) {
return strlen($k1) < strlen($k2);
}
);
$resultQuery = $query;
$paramNum = 0;
foreach ($sqlParams as $paName => $paValue) {
if (gettype($paValue)==="array") {
$paramList = [];
foreach ($paValue as $i=>$value) {
// $paramList[] = $paName . "_param$i";
$paramList[] = ":pdoParam$paramNum";
$paramNum++;
}
$resultQuery = str_replace($paName, implode(",", $paramList), $resultQuery);
}
}
return $resultQuery;
} | php | protected function prepareParams($query, $sqlParams)
{
if (empty($sqlParams)) {
$sqlParams = [];
}
uksort(
$sqlParams,
function ($k1, $k2) {
return strlen($k1) < strlen($k2);
}
);
$resultQuery = $query;
$paramNum = 0;
foreach ($sqlParams as $paName => $paValue) {
if (gettype($paValue)==="array") {
$paramList = [];
foreach ($paValue as $i=>$value) {
// $paramList[] = $paName . "_param$i";
$paramList[] = ":pdoParam$paramNum";
$paramNum++;
}
$resultQuery = str_replace($paName, implode(",", $paramList), $resultQuery);
}
}
return $resultQuery;
} | [
"protected",
"function",
"prepareParams",
"(",
"$",
"query",
",",
"$",
"sqlParams",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sqlParams",
")",
")",
"{",
"$",
"sqlParams",
"=",
"[",
"]",
";",
"}",
"uksort",
"(",
"$",
"sqlParams",
",",
"function",
"(",
"$",
"k1",
",",
"$",
"k2",
")",
"{",
"return",
"strlen",
"(",
"$",
"k1",
")",
"<",
"strlen",
"(",
"$",
"k2",
")",
";",
"}",
")",
";",
"$",
"resultQuery",
"=",
"$",
"query",
";",
"$",
"paramNum",
"=",
"0",
";",
"foreach",
"(",
"$",
"sqlParams",
"as",
"$",
"paName",
"=>",
"$",
"paValue",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"paValue",
")",
"===",
"\"array\"",
")",
"{",
"$",
"paramList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"paValue",
"as",
"$",
"i",
"=>",
"$",
"value",
")",
"{",
"// $paramList[] = $paName . \"_param$i\";",
"$",
"paramList",
"[",
"]",
"=",
"\":pdoParam$paramNum\"",
";",
"$",
"paramNum",
"++",
";",
"}",
"$",
"resultQuery",
"=",
"str_replace",
"(",
"$",
"paName",
",",
"implode",
"(",
"\",\"",
",",
"$",
"paramList",
")",
",",
"$",
"resultQuery",
")",
";",
"}",
"}",
"return",
"$",
"resultQuery",
";",
"}"
] | Prepare SQL statement
@param string $query Query need to bind params
@param array $sqlParams The parameters will be bound to query
@return string Procesed query | [
"Prepare",
"SQL",
"statement"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PdoDataSource.php#L191-L216 |
koolphp/koolreport | src/datasources/PdoDataSource.php | PdoDataSource.typeToPDOParamType | protected function typeToPDOParamType($type)
{
switch ($type) {
case "boolean":
return PDO::PARAM_BOOL;
case "integer":
return PDO::PARAM_STR;
case "NULL":
return PDO::PARAM_NULL;
case "resource":
return PDO::PARAM_LOB;
case "double":
case "string":
default:
return PDO::PARAM_STR;
}
} | php | protected function typeToPDOParamType($type)
{
switch ($type) {
case "boolean":
return PDO::PARAM_BOOL;
case "integer":
return PDO::PARAM_STR;
case "NULL":
return PDO::PARAM_NULL;
case "resource":
return PDO::PARAM_LOB;
case "double":
case "string":
default:
return PDO::PARAM_STR;
}
} | [
"protected",
"function",
"typeToPDOParamType",
"(",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"\"boolean\"",
":",
"return",
"PDO",
"::",
"PARAM_BOOL",
";",
"case",
"\"integer\"",
":",
"return",
"PDO",
"::",
"PARAM_STR",
";",
"case",
"\"NULL\"",
":",
"return",
"PDO",
"::",
"PARAM_NULL",
";",
"case",
"\"resource\"",
":",
"return",
"PDO",
"::",
"PARAM_LOB",
";",
"case",
"\"double\"",
":",
"case",
"\"string\"",
":",
"default",
":",
"return",
"PDO",
"::",
"PARAM_STR",
";",
"}",
"}"
] | Convert type to PdoParamType
@param string $type Type
@return intger The PDO Param Type | [
"Convert",
"type",
"to",
"PdoParamType"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PdoDataSource.php#L225-L241 |
koolphp/koolreport | src/datasources/PdoDataSource.php | PdoDataSource.bindParams | protected function bindParams($stm, $sqlParams)
{
if (empty($sqlParams)) {
$sqlParams = [];
}
uksort(
$sqlParams,
function ($k1, $k2) {
return strlen($k1) < strlen($k2);
}
);
$paramNum = 0;
foreach ($sqlParams as $paName => $paValue) {
$type = gettype($paValue);
if ($type === 'array') {
foreach ($paValue as $i=>$value) {
$paramType = $this->typeToPDOParamType(gettype($value));
$paramName = ":pdoParam$paramNum";
$paramNum++;
// $stm->bindValue($paName . "_param$i", $value, $paramType);
$stm->bindValue($paramName, $value, $paramType);
}
} else {
$paramType = $this->typeToPDOParamType($type);
$stm->bindValue($paName, $paValue, $paramType);
}
}
} | php | protected function bindParams($stm, $sqlParams)
{
if (empty($sqlParams)) {
$sqlParams = [];
}
uksort(
$sqlParams,
function ($k1, $k2) {
return strlen($k1) < strlen($k2);
}
);
$paramNum = 0;
foreach ($sqlParams as $paName => $paValue) {
$type = gettype($paValue);
if ($type === 'array') {
foreach ($paValue as $i=>$value) {
$paramType = $this->typeToPDOParamType(gettype($value));
$paramName = ":pdoParam$paramNum";
$paramNum++;
// $stm->bindValue($paName . "_param$i", $value, $paramType);
$stm->bindValue($paramName, $value, $paramType);
}
} else {
$paramType = $this->typeToPDOParamType($type);
$stm->bindValue($paName, $paValue, $paramType);
}
}
} | [
"protected",
"function",
"bindParams",
"(",
"$",
"stm",
",",
"$",
"sqlParams",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sqlParams",
")",
")",
"{",
"$",
"sqlParams",
"=",
"[",
"]",
";",
"}",
"uksort",
"(",
"$",
"sqlParams",
",",
"function",
"(",
"$",
"k1",
",",
"$",
"k2",
")",
"{",
"return",
"strlen",
"(",
"$",
"k1",
")",
"<",
"strlen",
"(",
"$",
"k2",
")",
";",
"}",
")",
";",
"$",
"paramNum",
"=",
"0",
";",
"foreach",
"(",
"$",
"sqlParams",
"as",
"$",
"paName",
"=>",
"$",
"paValue",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"paValue",
")",
";",
"if",
"(",
"$",
"type",
"===",
"'array'",
")",
"{",
"foreach",
"(",
"$",
"paValue",
"as",
"$",
"i",
"=>",
"$",
"value",
")",
"{",
"$",
"paramType",
"=",
"$",
"this",
"->",
"typeToPDOParamType",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
";",
"$",
"paramName",
"=",
"\":pdoParam$paramNum\"",
";",
"$",
"paramNum",
"++",
";",
"// $stm->bindValue($paName . \"_param$i\", $value, $paramType);",
"$",
"stm",
"->",
"bindValue",
"(",
"$",
"paramName",
",",
"$",
"value",
",",
"$",
"paramType",
")",
";",
"}",
"}",
"else",
"{",
"$",
"paramType",
"=",
"$",
"this",
"->",
"typeToPDOParamType",
"(",
"$",
"type",
")",
";",
"$",
"stm",
"->",
"bindValue",
"(",
"$",
"paName",
",",
"$",
"paValue",
",",
"$",
"paramType",
")",
";",
"}",
"}",
"}"
] | Perform data binding
@param string $stm Query need to bind params
@param array $sqlParams The parameters will be bound to query
@return null | [
"Perform",
"data",
"binding"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PdoDataSource.php#L251-L278 |
koolphp/koolreport | src/datasources/PdoDataSource.php | PdoDataSource.guessType | protected function guessType($native_type)
{
$map = array(
"character"=>"string",
"char"=>"string",
"string"=>"string",
"str"=>"string",
"text"=>"string",
"blob"=>"string",
"binary"=>"string",
"enum"=>"string",
"set"=>"string",
"int"=>"number",
"double"=>"number",
"float"=>"number",
"long"=>"number",
"numeric"=>"number",
"decimal"=>"number",
"real"=>"number",
"tinyint"=>"number",
"bit"=>"number",
"boolean"=>"number",
"datetime"=>"datetime",
"date"=>"date",
"time"=>"time",
"year"=>"datetime",
);
$native_type = strtolower($native_type);
foreach ($map as $key=>$value) {
if (strpos($native_type, $key)!==false) {
return $value;
}
}
return "unknown";
} | php | protected function guessType($native_type)
{
$map = array(
"character"=>"string",
"char"=>"string",
"string"=>"string",
"str"=>"string",
"text"=>"string",
"blob"=>"string",
"binary"=>"string",
"enum"=>"string",
"set"=>"string",
"int"=>"number",
"double"=>"number",
"float"=>"number",
"long"=>"number",
"numeric"=>"number",
"decimal"=>"number",
"real"=>"number",
"tinyint"=>"number",
"bit"=>"number",
"boolean"=>"number",
"datetime"=>"datetime",
"date"=>"date",
"time"=>"time",
"year"=>"datetime",
);
$native_type = strtolower($native_type);
foreach ($map as $key=>$value) {
if (strpos($native_type, $key)!==false) {
return $value;
}
}
return "unknown";
} | [
"protected",
"function",
"guessType",
"(",
"$",
"native_type",
")",
"{",
"$",
"map",
"=",
"array",
"(",
"\"character\"",
"=>",
"\"string\"",
",",
"\"char\"",
"=>",
"\"string\"",
",",
"\"string\"",
"=>",
"\"string\"",
",",
"\"str\"",
"=>",
"\"string\"",
",",
"\"text\"",
"=>",
"\"string\"",
",",
"\"blob\"",
"=>",
"\"string\"",
",",
"\"binary\"",
"=>",
"\"string\"",
",",
"\"enum\"",
"=>",
"\"string\"",
",",
"\"set\"",
"=>",
"\"string\"",
",",
"\"int\"",
"=>",
"\"number\"",
",",
"\"double\"",
"=>",
"\"number\"",
",",
"\"float\"",
"=>",
"\"number\"",
",",
"\"long\"",
"=>",
"\"number\"",
",",
"\"numeric\"",
"=>",
"\"number\"",
",",
"\"decimal\"",
"=>",
"\"number\"",
",",
"\"real\"",
"=>",
"\"number\"",
",",
"\"tinyint\"",
"=>",
"\"number\"",
",",
"\"bit\"",
"=>",
"\"number\"",
",",
"\"boolean\"",
"=>",
"\"number\"",
",",
"\"datetime\"",
"=>",
"\"datetime\"",
",",
"\"date\"",
"=>",
"\"date\"",
",",
"\"time\"",
"=>",
"\"time\"",
",",
"\"year\"",
"=>",
"\"datetime\"",
",",
")",
";",
"$",
"native_type",
"=",
"strtolower",
"(",
"$",
"native_type",
")",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"native_type",
",",
"$",
"key",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"return",
"\"unknown\"",
";",
"}"
] | Guess type
@param string $native_type Native type of PDO
@return string KoolReport type | [
"Guess",
"type"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PdoDataSource.php#L287-L323 |
koolphp/koolreport | src/datasources/PdoDataSource.php | PdoDataSource.start | public function start()
{
$metaData = array("columns"=>array());
if ($this->countTotal) {
$totalQuery = $this->prepareParams($this->totalQuery, $this->sqlParams);
$stm = $this->connection->prepare($totalQuery);
$this->bindParams($stm, $this->sqlParams);
$stm->execute();
$error = $stm->errorInfo();
if ($error[2]!=null) {
throw new \Exception("Query Error >> [".$error[2]."] >> $totalQuery");
return;
}
$row = $stm->fetch();
$result = $row[0];
$metaData['totalRecords'] = $result;
}
if ($this->countFilter) {
$filterQuery = $this->prepareParams($this->filterQuery, $this->sqlParams);
$stm = $this->connection->prepare($filterQuery);
$this->bindParams($stm, $this->sqlParams);
$stm->execute();
$error = $stm->errorInfo();
if ($error[2]!=null) {
throw new \Exception("Query Error >> [".$error[2]."] >> $filterQuery");
return;
}
$row = $stm->fetch();
$result = $row[0];
$metaData['filterRecords'] = $result;
}
$row = null;
$query = $this->prepareParams($this->query, $this->sqlParams);
// echo "pdodatasource start query=$query <br>";
$stm = $this->connection->prepare($query);
$this->bindParams($stm, $this->sqlParams);
$stm->execute();
$error = $stm->errorInfo();
// if($error[2]!=null)
if ($error[0]!='00000') {
throw new \Exception("Query Error >> [".$error[2]."] >> $query");
return;
}
$driver = strtolower($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME));
$metaSupportDrivers = array('dblib', 'mysql', 'pgsql', 'sqlite');
$metaSupport = false;
foreach ($metaSupportDrivers as $supportDriver) {
if (strpos($driver, $supportDriver) !== false) {
$metaSupport = true;
}
}
if (!$metaSupport) {
$row = $stm->fetch(PDO::FETCH_ASSOC);
$cNames = empty($row) ? array() : array_keys($row);
$numcols = count($cNames);
} else {
$numcols = $stm->columnCount();
}
// $metaData = array("columns"=>array());
for ($i=0;$i<$numcols;$i++) {
if (! $metaSupport) {
$cName = $cNames[$i];
$cType = $this->guessTypeFromValue($row[$cName]);
} else {
$info = $stm->getColumnMeta($i);
$cName = $info["name"];
$cType = $this->guessType($info["native_type"]);
}
$metaData["columns"][$cName] = array(
"type"=>$cType,
);
switch($cType)
{
case "datetime":
$metaData["columns"][$cName]["format"] = "Y-m-d H:i:s";
break;
case "date":
$metaData["columns"][$cName]["format"] = "Y-m-d";
break;
case "time":
$metaData["columns"][$cName]["format"] = "H:i:s";
break;
}
}
$this->sendMeta($metaData, $this);
$this->startInput(null);
$numberColumnList = array();
foreach ($metaData["columns"] as $cName=>$cMeta) {
if ($cMeta["type"]=="number") {
array_push($numberColumnList, $cName);
}
}
if (! isset($row)) {
$row=$stm->fetch(PDO::FETCH_ASSOC);
}
while ($row) {
// print_r($row); echo '<br>';
foreach ($numberColumnList as $cName) {
$row[$cName]+=0;
}
$this->next($row, $this);
$row=$stm->fetch(PDO::FETCH_ASSOC);
}
$this->endInput(null);
} | php | public function start()
{
$metaData = array("columns"=>array());
if ($this->countTotal) {
$totalQuery = $this->prepareParams($this->totalQuery, $this->sqlParams);
$stm = $this->connection->prepare($totalQuery);
$this->bindParams($stm, $this->sqlParams);
$stm->execute();
$error = $stm->errorInfo();
if ($error[2]!=null) {
throw new \Exception("Query Error >> [".$error[2]."] >> $totalQuery");
return;
}
$row = $stm->fetch();
$result = $row[0];
$metaData['totalRecords'] = $result;
}
if ($this->countFilter) {
$filterQuery = $this->prepareParams($this->filterQuery, $this->sqlParams);
$stm = $this->connection->prepare($filterQuery);
$this->bindParams($stm, $this->sqlParams);
$stm->execute();
$error = $stm->errorInfo();
if ($error[2]!=null) {
throw new \Exception("Query Error >> [".$error[2]."] >> $filterQuery");
return;
}
$row = $stm->fetch();
$result = $row[0];
$metaData['filterRecords'] = $result;
}
$row = null;
$query = $this->prepareParams($this->query, $this->sqlParams);
// echo "pdodatasource start query=$query <br>";
$stm = $this->connection->prepare($query);
$this->bindParams($stm, $this->sqlParams);
$stm->execute();
$error = $stm->errorInfo();
// if($error[2]!=null)
if ($error[0]!='00000') {
throw new \Exception("Query Error >> [".$error[2]."] >> $query");
return;
}
$driver = strtolower($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME));
$metaSupportDrivers = array('dblib', 'mysql', 'pgsql', 'sqlite');
$metaSupport = false;
foreach ($metaSupportDrivers as $supportDriver) {
if (strpos($driver, $supportDriver) !== false) {
$metaSupport = true;
}
}
if (!$metaSupport) {
$row = $stm->fetch(PDO::FETCH_ASSOC);
$cNames = empty($row) ? array() : array_keys($row);
$numcols = count($cNames);
} else {
$numcols = $stm->columnCount();
}
// $metaData = array("columns"=>array());
for ($i=0;$i<$numcols;$i++) {
if (! $metaSupport) {
$cName = $cNames[$i];
$cType = $this->guessTypeFromValue($row[$cName]);
} else {
$info = $stm->getColumnMeta($i);
$cName = $info["name"];
$cType = $this->guessType($info["native_type"]);
}
$metaData["columns"][$cName] = array(
"type"=>$cType,
);
switch($cType)
{
case "datetime":
$metaData["columns"][$cName]["format"] = "Y-m-d H:i:s";
break;
case "date":
$metaData["columns"][$cName]["format"] = "Y-m-d";
break;
case "time":
$metaData["columns"][$cName]["format"] = "H:i:s";
break;
}
}
$this->sendMeta($metaData, $this);
$this->startInput(null);
$numberColumnList = array();
foreach ($metaData["columns"] as $cName=>$cMeta) {
if ($cMeta["type"]=="number") {
array_push($numberColumnList, $cName);
}
}
if (! isset($row)) {
$row=$stm->fetch(PDO::FETCH_ASSOC);
}
while ($row) {
// print_r($row); echo '<br>';
foreach ($numberColumnList as $cName) {
$row[$cName]+=0;
}
$this->next($row, $this);
$row=$stm->fetch(PDO::FETCH_ASSOC);
}
$this->endInput(null);
} | [
"public",
"function",
"start",
"(",
")",
"{",
"$",
"metaData",
"=",
"array",
"(",
"\"columns\"",
"=>",
"array",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"countTotal",
")",
"{",
"$",
"totalQuery",
"=",
"$",
"this",
"->",
"prepareParams",
"(",
"$",
"this",
"->",
"totalQuery",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"stm",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"totalQuery",
")",
";",
"$",
"this",
"->",
"bindParams",
"(",
"$",
"stm",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"stm",
"->",
"execute",
"(",
")",
";",
"$",
"error",
"=",
"$",
"stm",
"->",
"errorInfo",
"(",
")",
";",
"if",
"(",
"$",
"error",
"[",
"2",
"]",
"!=",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Query Error >> [\"",
".",
"$",
"error",
"[",
"2",
"]",
".",
"\"] >> $totalQuery\"",
")",
";",
"return",
";",
"}",
"$",
"row",
"=",
"$",
"stm",
"->",
"fetch",
"(",
")",
";",
"$",
"result",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"$",
"metaData",
"[",
"'totalRecords'",
"]",
"=",
"$",
"result",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"countFilter",
")",
"{",
"$",
"filterQuery",
"=",
"$",
"this",
"->",
"prepareParams",
"(",
"$",
"this",
"->",
"filterQuery",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"stm",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"filterQuery",
")",
";",
"$",
"this",
"->",
"bindParams",
"(",
"$",
"stm",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"stm",
"->",
"execute",
"(",
")",
";",
"$",
"error",
"=",
"$",
"stm",
"->",
"errorInfo",
"(",
")",
";",
"if",
"(",
"$",
"error",
"[",
"2",
"]",
"!=",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Query Error >> [\"",
".",
"$",
"error",
"[",
"2",
"]",
".",
"\"] >> $filterQuery\"",
")",
";",
"return",
";",
"}",
"$",
"row",
"=",
"$",
"stm",
"->",
"fetch",
"(",
")",
";",
"$",
"result",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"$",
"metaData",
"[",
"'filterRecords'",
"]",
"=",
"$",
"result",
";",
"}",
"$",
"row",
"=",
"null",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"prepareParams",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"// echo \"pdodatasource start query=$query <br>\";",
"$",
"stm",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"this",
"->",
"bindParams",
"(",
"$",
"stm",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"stm",
"->",
"execute",
"(",
")",
";",
"$",
"error",
"=",
"$",
"stm",
"->",
"errorInfo",
"(",
")",
";",
"// if($error[2]!=null)",
"if",
"(",
"$",
"error",
"[",
"0",
"]",
"!=",
"'00000'",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Query Error >> [\"",
".",
"$",
"error",
"[",
"2",
"]",
".",
"\"] >> $query\"",
")",
";",
"return",
";",
"}",
"$",
"driver",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"connection",
"->",
"getAttribute",
"(",
"PDO",
"::",
"ATTR_DRIVER_NAME",
")",
")",
";",
"$",
"metaSupportDrivers",
"=",
"array",
"(",
"'dblib'",
",",
"'mysql'",
",",
"'pgsql'",
",",
"'sqlite'",
")",
";",
"$",
"metaSupport",
"=",
"false",
";",
"foreach",
"(",
"$",
"metaSupportDrivers",
"as",
"$",
"supportDriver",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"driver",
",",
"$",
"supportDriver",
")",
"!==",
"false",
")",
"{",
"$",
"metaSupport",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"metaSupport",
")",
"{",
"$",
"row",
"=",
"$",
"stm",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"cNames",
"=",
"empty",
"(",
"$",
"row",
")",
"?",
"array",
"(",
")",
":",
"array_keys",
"(",
"$",
"row",
")",
";",
"$",
"numcols",
"=",
"count",
"(",
"$",
"cNames",
")",
";",
"}",
"else",
"{",
"$",
"numcols",
"=",
"$",
"stm",
"->",
"columnCount",
"(",
")",
";",
"}",
"// $metaData = array(\"columns\"=>array());",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"numcols",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"$",
"metaSupport",
")",
"{",
"$",
"cName",
"=",
"$",
"cNames",
"[",
"$",
"i",
"]",
";",
"$",
"cType",
"=",
"$",
"this",
"->",
"guessTypeFromValue",
"(",
"$",
"row",
"[",
"$",
"cName",
"]",
")",
";",
"}",
"else",
"{",
"$",
"info",
"=",
"$",
"stm",
"->",
"getColumnMeta",
"(",
"$",
"i",
")",
";",
"$",
"cName",
"=",
"$",
"info",
"[",
"\"name\"",
"]",
";",
"$",
"cType",
"=",
"$",
"this",
"->",
"guessType",
"(",
"$",
"info",
"[",
"\"native_type\"",
"]",
")",
";",
"}",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"cName",
"]",
"=",
"array",
"(",
"\"type\"",
"=>",
"$",
"cType",
",",
")",
";",
"switch",
"(",
"$",
"cType",
")",
"{",
"case",
"\"datetime\"",
":",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"cName",
"]",
"[",
"\"format\"",
"]",
"=",
"\"Y-m-d H:i:s\"",
";",
"break",
";",
"case",
"\"date\"",
":",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"cName",
"]",
"[",
"\"format\"",
"]",
"=",
"\"Y-m-d\"",
";",
"break",
";",
"case",
"\"time\"",
":",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"cName",
"]",
"[",
"\"format\"",
"]",
"=",
"\"H:i:s\"",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"sendMeta",
"(",
"$",
"metaData",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"startInput",
"(",
"null",
")",
";",
"$",
"numberColumnList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"as",
"$",
"cName",
"=>",
"$",
"cMeta",
")",
"{",
"if",
"(",
"$",
"cMeta",
"[",
"\"type\"",
"]",
"==",
"\"number\"",
")",
"{",
"array_push",
"(",
"$",
"numberColumnList",
",",
"$",
"cName",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
")",
")",
"{",
"$",
"row",
"=",
"$",
"stm",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}",
"while",
"(",
"$",
"row",
")",
"{",
"// print_r($row); echo '<br>';",
"foreach",
"(",
"$",
"numberColumnList",
"as",
"$",
"cName",
")",
"{",
"$",
"row",
"[",
"$",
"cName",
"]",
"+=",
"0",
";",
"}",
"$",
"this",
"->",
"next",
"(",
"$",
"row",
",",
"$",
"this",
")",
";",
"$",
"row",
"=",
"$",
"stm",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}",
"$",
"this",
"->",
"endInput",
"(",
"null",
")",
";",
"}"
] | Start piping data
@return null | [
"Start",
"piping",
"data"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PdoDataSource.php#L358-L474 |
koolphp/koolreport | src/processes/DifferenceColumn.php | DifferenceColumn.onMetaReceived | protected function onMetaReceived($metaData)
{
foreach ($this->params as $copy => $original) {
$metaData["columns"][$copy] = $metaData["columns"][$original];
$metaData["columns"][$copy]["type"] = "number";
}
return $metaData;
} | php | protected function onMetaReceived($metaData)
{
foreach ($this->params as $copy => $original) {
$metaData["columns"][$copy] = $metaData["columns"][$original];
$metaData["columns"][$copy]["type"] = "number";
}
return $metaData;
} | [
"protected",
"function",
"onMetaReceived",
"(",
"$",
"metaData",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"copy",
"=>",
"$",
"original",
")",
"{",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"copy",
"]",
"=",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"original",
"]",
";",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"copy",
"]",
"[",
"\"type\"",
"]",
"=",
"\"number\"",
";",
"}",
"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/DifferenceColumn.php#L45-L52 |
koolphp/koolreport | src/processes/DifferenceColumn.php | DifferenceColumn.onInput | public function onInput($row)
{
//Process data here
foreach ($this->params as $copy => $original) {
$row[$copy] = $row[$original] - Utility::get($this->previousRow, $original, 0);
}
$this->previousRow = $row;
$this->next($row);
} | php | public function onInput($row)
{
//Process data here
foreach ($this->params as $copy => $original) {
$row[$copy] = $row[$original] - Utility::get($this->previousRow, $original, 0);
}
$this->previousRow = $row;
$this->next($row);
} | [
"public",
"function",
"onInput",
"(",
"$",
"row",
")",
"{",
"//Process data here",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"copy",
"=>",
"$",
"original",
")",
"{",
"$",
"row",
"[",
"$",
"copy",
"]",
"=",
"$",
"row",
"[",
"$",
"original",
"]",
"-",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"previousRow",
",",
"$",
"original",
",",
"0",
")",
";",
"}",
"$",
"this",
"->",
"previousRow",
"=",
"$",
"row",
";",
"$",
"this",
"->",
"next",
"(",
"$",
"row",
")",
";",
"}"
] | 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/DifferenceColumn.php#L71-L79 |
koolphp/koolreport | src/processes/ColumnMeta.php | ColumnMeta.onInit | protected function onInit()
{
if (is_array($this->params)) {
$this->override = Utility::get($this->params, "{override}", false);
}
} | php | protected function onInit()
{
if (is_array($this->params)) {
$this->override = Utility::get($this->params, "{override}", false);
}
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"params",
")",
")",
"{",
"$",
"this",
"->",
"override",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"{override}\"",
",",
"false",
")",
";",
"}",
"}"
] | Handle on initiation
@return null | [
"Handle",
"on",
"initiation"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/ColumnMeta.php#L54-L60 |
koolphp/koolreport | src/processes/ColumnMeta.php | ColumnMeta.onMetaReceived | protected function onMetaReceived($metaData)
{
if (is_array($this->params)) {
foreach ($this->params as $columnName => $columnInfo) {
if (isset($metaData["columns"][$columnName])) {
$newColumnName = Utility::get($columnInfo, "name");
$currentColumnInfo = $metaData["columns"][$columnName];
if ($newColumnName) {
unset($columnInfo["name"]);
unset($metaData["columns"][$columnName]);
}
if ($this->override) {
$metaData["columns"][($newColumnName) ? $newColumnName : $columnName] = $columnInfo;
} else {
$metaData["columns"][($newColumnName) ? $newColumnName : $columnName] = array_merge($currentColumnInfo, $columnInfo);
}
}
}
} else if (is_callable($this->params)) {
$func = $this->params;
$columns = $metaData['columns'];
$pos = 0;
foreach ($columns as $c => $cMeta) {
$newMeta = $func($c, $cMeta, $pos);
if (isset($newMeta['name'])) {
$newName = $newMeta['name'];
$this->nameMap[$c] = $newName;
// unset($columns[$c]);
unset($newMeta['name']);
$columns[$newName] = $newMeta;
} else {
$columns[$c] = $newMeta;
}
$pos++;
}
$metaData['columns'] = $columns;
}
return $metaData;
} | php | protected function onMetaReceived($metaData)
{
if (is_array($this->params)) {
foreach ($this->params as $columnName => $columnInfo) {
if (isset($metaData["columns"][$columnName])) {
$newColumnName = Utility::get($columnInfo, "name");
$currentColumnInfo = $metaData["columns"][$columnName];
if ($newColumnName) {
unset($columnInfo["name"]);
unset($metaData["columns"][$columnName]);
}
if ($this->override) {
$metaData["columns"][($newColumnName) ? $newColumnName : $columnName] = $columnInfo;
} else {
$metaData["columns"][($newColumnName) ? $newColumnName : $columnName] = array_merge($currentColumnInfo, $columnInfo);
}
}
}
} else if (is_callable($this->params)) {
$func = $this->params;
$columns = $metaData['columns'];
$pos = 0;
foreach ($columns as $c => $cMeta) {
$newMeta = $func($c, $cMeta, $pos);
if (isset($newMeta['name'])) {
$newName = $newMeta['name'];
$this->nameMap[$c] = $newName;
// unset($columns[$c]);
unset($newMeta['name']);
$columns[$newName] = $newMeta;
} else {
$columns[$c] = $newMeta;
}
$pos++;
}
$metaData['columns'] = $columns;
}
return $metaData;
} | [
"protected",
"function",
"onMetaReceived",
"(",
"$",
"metaData",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"params",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"columnName",
"=>",
"$",
"columnInfo",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"columnName",
"]",
")",
")",
"{",
"$",
"newColumnName",
"=",
"Utility",
"::",
"get",
"(",
"$",
"columnInfo",
",",
"\"name\"",
")",
";",
"$",
"currentColumnInfo",
"=",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"columnName",
"]",
";",
"if",
"(",
"$",
"newColumnName",
")",
"{",
"unset",
"(",
"$",
"columnInfo",
"[",
"\"name\"",
"]",
")",
";",
"unset",
"(",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"columnName",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"override",
")",
"{",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"(",
"$",
"newColumnName",
")",
"?",
"$",
"newColumnName",
":",
"$",
"columnName",
"]",
"=",
"$",
"columnInfo",
";",
"}",
"else",
"{",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"(",
"$",
"newColumnName",
")",
"?",
"$",
"newColumnName",
":",
"$",
"columnName",
"]",
"=",
"array_merge",
"(",
"$",
"currentColumnInfo",
",",
"$",
"columnInfo",
")",
";",
"}",
"}",
"}",
"}",
"else",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"params",
")",
")",
"{",
"$",
"func",
"=",
"$",
"this",
"->",
"params",
";",
"$",
"columns",
"=",
"$",
"metaData",
"[",
"'columns'",
"]",
";",
"$",
"pos",
"=",
"0",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"c",
"=>",
"$",
"cMeta",
")",
"{",
"$",
"newMeta",
"=",
"$",
"func",
"(",
"$",
"c",
",",
"$",
"cMeta",
",",
"$",
"pos",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"newMeta",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"newName",
"=",
"$",
"newMeta",
"[",
"'name'",
"]",
";",
"$",
"this",
"->",
"nameMap",
"[",
"$",
"c",
"]",
"=",
"$",
"newName",
";",
"// unset($columns[$c]);",
"unset",
"(",
"$",
"newMeta",
"[",
"'name'",
"]",
")",
";",
"$",
"columns",
"[",
"$",
"newName",
"]",
"=",
"$",
"newMeta",
";",
"}",
"else",
"{",
"$",
"columns",
"[",
"$",
"c",
"]",
"=",
"$",
"newMeta",
";",
"}",
"$",
"pos",
"++",
";",
"}",
"$",
"metaData",
"[",
"'columns'",
"]",
"=",
"$",
"columns",
";",
"}",
"return",
"$",
"metaData",
";",
"}"
] | Handle on meta received
@param array $metaData Meta received
@return array New meta data | [
"Handle",
"on",
"meta",
"received"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/ColumnMeta.php#L69-L108 |
koolphp/koolreport | src/processes/ColumnMeta.php | ColumnMeta.onInput | protected function onInput($data)
{
if (is_array($this->params)) {
foreach ($this->params as $columnName => $columnInfo) {
if (isset($columnInfo["name"])) {
$columnValue = $data[$columnName];
unset($data[$columnName]);
$data[$columnInfo["name"]] = $columnValue;
}
}
} else {
foreach ($this->nameMap as $oldName => $newName) {
$value = $data[$oldName];
unset($data[$oldName]);
$data[$newName] = $value;
}
}
$this->next($data);
} | php | protected function onInput($data)
{
if (is_array($this->params)) {
foreach ($this->params as $columnName => $columnInfo) {
if (isset($columnInfo["name"])) {
$columnValue = $data[$columnName];
unset($data[$columnName]);
$data[$columnInfo["name"]] = $columnValue;
}
}
} else {
foreach ($this->nameMap as $oldName => $newName) {
$value = $data[$oldName];
unset($data[$oldName]);
$data[$newName] = $value;
}
}
$this->next($data);
} | [
"protected",
"function",
"onInput",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"params",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"columnName",
"=>",
"$",
"columnInfo",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"columnInfo",
"[",
"\"name\"",
"]",
")",
")",
"{",
"$",
"columnValue",
"=",
"$",
"data",
"[",
"$",
"columnName",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"columnName",
"]",
")",
";",
"$",
"data",
"[",
"$",
"columnInfo",
"[",
"\"name\"",
"]",
"]",
"=",
"$",
"columnValue",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"nameMap",
"as",
"$",
"oldName",
"=>",
"$",
"newName",
")",
"{",
"$",
"value",
"=",
"$",
"data",
"[",
"$",
"oldName",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"oldName",
"]",
")",
";",
"$",
"data",
"[",
"$",
"newName",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"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/ColumnMeta.php#L117-L135 |
koolphp/koolreport | src/core/Widget.php | Widget.clientSideReady | protected function clientSideReady($name=null)
{
//If no name specified then use default $this->name
//If not then if $name=="", understand that there is no passing object
//Otherwise try to pass the custom name
if ($name==null && $this->onReady!=null) {
echo "(".$this->onReady.")(".$this->name.");";
} else if ($this->onReady!=null) {
if ($name=="") {
echo "(".$this->onReady.")();";
} else {
echo "(".$this->onReady.")(".$name.");";
}
}
} | php | protected function clientSideReady($name=null)
{
//If no name specified then use default $this->name
//If not then if $name=="", understand that there is no passing object
//Otherwise try to pass the custom name
if ($name==null && $this->onReady!=null) {
echo "(".$this->onReady.")(".$this->name.");";
} else if ($this->onReady!=null) {
if ($name=="") {
echo "(".$this->onReady.")();";
} else {
echo "(".$this->onReady.")(".$name.");";
}
}
} | [
"protected",
"function",
"clientSideReady",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"//If no name specified then use default $this->name",
"//If not then if $name==\"\", understand that there is no passing object",
"//Otherwise try to pass the custom name",
"if",
"(",
"$",
"name",
"==",
"null",
"&&",
"$",
"this",
"->",
"onReady",
"!=",
"null",
")",
"{",
"echo",
"\"(\"",
".",
"$",
"this",
"->",
"onReady",
".",
"\")(\"",
".",
"$",
"this",
"->",
"name",
".",
"\");\"",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"onReady",
"!=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"\"\"",
")",
"{",
"echo",
"\"(\"",
".",
"$",
"this",
"->",
"onReady",
".",
"\")();\"",
";",
"}",
"else",
"{",
"echo",
"\"(\"",
".",
"$",
"this",
"->",
"onReady",
".",
"\")(\"",
".",
"$",
"name",
".",
"\");\"",
";",
"}",
"}",
"}"
] | Render javascript code to implement user's custom script
when widget is ready at client-side
@param string $name The name of widget
@return null | [
"Render",
"javascript",
"code",
"to",
"implement",
"user",
"s",
"custom",
"script",
"when",
"widget",
"is",
"ready",
"at",
"client",
"-",
"side"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L182-L196 |
koolphp/koolreport | src/core/Widget.php | Widget.getResources | protected function getResources($settings=null)
{
$resources = array(
"js"=>array(),
"css"=>array()
);
if ($settings==null) {
$settings = $this->resourceSettings();
}
//Default settings
if ($settings && isset($settings["folder"])) {
$this->getAssetManager()->publish($settings["folder"]);
$css = Utility::get($settings, "css");
$js = Utility::get($settings, "js");
if ($css) {
$this->convertHierachicalResources($css);
$resources["css"] = $css;
}
if ($js) {
$this->convertHierachicalResources($js);
$resources["js"] = $js;
}
}
//Extra from theme
$theme = $this->getReport()->getTheme();
if ($theme && $theme->doesSupport($this)) {
$extra = $theme->getWidgetResourcesFor($this);
//Extra Js
if ($extra["replacingJs"]!=array()) {
$resources["js"] = $extra["replacingJs"];
} else if ($resources["js"]==array()) {
$resources["js"] = $extra["js"];
} else if ($extra["js"]!=array()) {
$this->attachResourceToEnd($resources["js"], $extra["js"]);
}
//Extra Css
if ($extra["replacingCss"]!=array()) {
$resources["css"] = $extra["replacingCss"];
} else if ($resources["css"]==array()) {
$resources["css"] = $extra["css"];
} else if ($extra["css"]!=array()) {
$this->attachResourceToEnd($resources["css"], $extra["css"]);
}
}
//Library
if ($settings) {
$library = Utility::get($settings, "library");
if ($library) {
$lib = array(
"css"=>array(),
"js"=>array(),
);
foreach ($library as $libName) {
switch(strtolower($libName))
{
case "jquery":
$publicAssetUrl = $this->getReport()
->getResourceManager()
->publishAssetFolder(
realpath(dirname(__FILE__)."/../clients/jquery")
);
array_push($lib["js"], $publicAssetUrl."/jquery.min.js");
break;
case "jqueryui":
$publicAssetUrl = $this->getReport()
->getResourceManager()
->publishAssetFolder(
realpath(dirname(__FILE__)."/../clients/jquery")
);
array_push($lib["js"], $publicAssetUrl."/jquery-ui.min.js");
break;
case "raphael":
$publicAssetUrl = $this->getReport()->getResourceManager()->publishAssetFolder(realpath(dirname(__FILE__)."/../clients/raphael"));
array_push($lib["js"], $publicAssetUrl."/raphael.min.js");
break;
case "font-awesome":
$publicAssetUrl = $this->getReport()->getResourceManager()->publishAssetFolder(realpath(dirname(__FILE__)."/../clients/font-awesome"));
array_push(
$lib["css"],
$publicAssetUrl."/css/font-awesome.min.css"
);
break;
break;
}
}
if ($lib["js"]!=array()) {
$resources["js"] = array_merge(
$lib["js"],
array($resources["js"])
);
}
if ($lib["css"]!=array()) {
$resources["css"] = array_merge(
$lib["css"],
array($resources["css"])
);
}
}
}
return $resources;
} | php | protected function getResources($settings=null)
{
$resources = array(
"js"=>array(),
"css"=>array()
);
if ($settings==null) {
$settings = $this->resourceSettings();
}
//Default settings
if ($settings && isset($settings["folder"])) {
$this->getAssetManager()->publish($settings["folder"]);
$css = Utility::get($settings, "css");
$js = Utility::get($settings, "js");
if ($css) {
$this->convertHierachicalResources($css);
$resources["css"] = $css;
}
if ($js) {
$this->convertHierachicalResources($js);
$resources["js"] = $js;
}
}
//Extra from theme
$theme = $this->getReport()->getTheme();
if ($theme && $theme->doesSupport($this)) {
$extra = $theme->getWidgetResourcesFor($this);
//Extra Js
if ($extra["replacingJs"]!=array()) {
$resources["js"] = $extra["replacingJs"];
} else if ($resources["js"]==array()) {
$resources["js"] = $extra["js"];
} else if ($extra["js"]!=array()) {
$this->attachResourceToEnd($resources["js"], $extra["js"]);
}
//Extra Css
if ($extra["replacingCss"]!=array()) {
$resources["css"] = $extra["replacingCss"];
} else if ($resources["css"]==array()) {
$resources["css"] = $extra["css"];
} else if ($extra["css"]!=array()) {
$this->attachResourceToEnd($resources["css"], $extra["css"]);
}
}
//Library
if ($settings) {
$library = Utility::get($settings, "library");
if ($library) {
$lib = array(
"css"=>array(),
"js"=>array(),
);
foreach ($library as $libName) {
switch(strtolower($libName))
{
case "jquery":
$publicAssetUrl = $this->getReport()
->getResourceManager()
->publishAssetFolder(
realpath(dirname(__FILE__)."/../clients/jquery")
);
array_push($lib["js"], $publicAssetUrl."/jquery.min.js");
break;
case "jqueryui":
$publicAssetUrl = $this->getReport()
->getResourceManager()
->publishAssetFolder(
realpath(dirname(__FILE__)."/../clients/jquery")
);
array_push($lib["js"], $publicAssetUrl."/jquery-ui.min.js");
break;
case "raphael":
$publicAssetUrl = $this->getReport()->getResourceManager()->publishAssetFolder(realpath(dirname(__FILE__)."/../clients/raphael"));
array_push($lib["js"], $publicAssetUrl."/raphael.min.js");
break;
case "font-awesome":
$publicAssetUrl = $this->getReport()->getResourceManager()->publishAssetFolder(realpath(dirname(__FILE__)."/../clients/font-awesome"));
array_push(
$lib["css"],
$publicAssetUrl."/css/font-awesome.min.css"
);
break;
break;
}
}
if ($lib["js"]!=array()) {
$resources["js"] = array_merge(
$lib["js"],
array($resources["js"])
);
}
if ($lib["css"]!=array()) {
$resources["css"] = array_merge(
$lib["css"],
array($resources["css"])
);
}
}
}
return $resources;
} | [
"protected",
"function",
"getResources",
"(",
"$",
"settings",
"=",
"null",
")",
"{",
"$",
"resources",
"=",
"array",
"(",
"\"js\"",
"=>",
"array",
"(",
")",
",",
"\"css\"",
"=>",
"array",
"(",
")",
")",
";",
"if",
"(",
"$",
"settings",
"==",
"null",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"resourceSettings",
"(",
")",
";",
"}",
"//Default settings",
"if",
"(",
"$",
"settings",
"&&",
"isset",
"(",
"$",
"settings",
"[",
"\"folder\"",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getAssetManager",
"(",
")",
"->",
"publish",
"(",
"$",
"settings",
"[",
"\"folder\"",
"]",
")",
";",
"$",
"css",
"=",
"Utility",
"::",
"get",
"(",
"$",
"settings",
",",
"\"css\"",
")",
";",
"$",
"js",
"=",
"Utility",
"::",
"get",
"(",
"$",
"settings",
",",
"\"js\"",
")",
";",
"if",
"(",
"$",
"css",
")",
"{",
"$",
"this",
"->",
"convertHierachicalResources",
"(",
"$",
"css",
")",
";",
"$",
"resources",
"[",
"\"css\"",
"]",
"=",
"$",
"css",
";",
"}",
"if",
"(",
"$",
"js",
")",
"{",
"$",
"this",
"->",
"convertHierachicalResources",
"(",
"$",
"js",
")",
";",
"$",
"resources",
"[",
"\"js\"",
"]",
"=",
"$",
"js",
";",
"}",
"}",
"//Extra from theme",
"$",
"theme",
"=",
"$",
"this",
"->",
"getReport",
"(",
")",
"->",
"getTheme",
"(",
")",
";",
"if",
"(",
"$",
"theme",
"&&",
"$",
"theme",
"->",
"doesSupport",
"(",
"$",
"this",
")",
")",
"{",
"$",
"extra",
"=",
"$",
"theme",
"->",
"getWidgetResourcesFor",
"(",
"$",
"this",
")",
";",
"//Extra Js",
"if",
"(",
"$",
"extra",
"[",
"\"replacingJs\"",
"]",
"!=",
"array",
"(",
")",
")",
"{",
"$",
"resources",
"[",
"\"js\"",
"]",
"=",
"$",
"extra",
"[",
"\"replacingJs\"",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"resources",
"[",
"\"js\"",
"]",
"==",
"array",
"(",
")",
")",
"{",
"$",
"resources",
"[",
"\"js\"",
"]",
"=",
"$",
"extra",
"[",
"\"js\"",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"extra",
"[",
"\"js\"",
"]",
"!=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"attachResourceToEnd",
"(",
"$",
"resources",
"[",
"\"js\"",
"]",
",",
"$",
"extra",
"[",
"\"js\"",
"]",
")",
";",
"}",
"//Extra Css",
"if",
"(",
"$",
"extra",
"[",
"\"replacingCss\"",
"]",
"!=",
"array",
"(",
")",
")",
"{",
"$",
"resources",
"[",
"\"css\"",
"]",
"=",
"$",
"extra",
"[",
"\"replacingCss\"",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"resources",
"[",
"\"css\"",
"]",
"==",
"array",
"(",
")",
")",
"{",
"$",
"resources",
"[",
"\"css\"",
"]",
"=",
"$",
"extra",
"[",
"\"css\"",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"extra",
"[",
"\"css\"",
"]",
"!=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"attachResourceToEnd",
"(",
"$",
"resources",
"[",
"\"css\"",
"]",
",",
"$",
"extra",
"[",
"\"css\"",
"]",
")",
";",
"}",
"}",
"//Library",
"if",
"(",
"$",
"settings",
")",
"{",
"$",
"library",
"=",
"Utility",
"::",
"get",
"(",
"$",
"settings",
",",
"\"library\"",
")",
";",
"if",
"(",
"$",
"library",
")",
"{",
"$",
"lib",
"=",
"array",
"(",
"\"css\"",
"=>",
"array",
"(",
")",
",",
"\"js\"",
"=>",
"array",
"(",
")",
",",
")",
";",
"foreach",
"(",
"$",
"library",
"as",
"$",
"libName",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"libName",
")",
")",
"{",
"case",
"\"jquery\"",
":",
"$",
"publicAssetUrl",
"=",
"$",
"this",
"->",
"getReport",
"(",
")",
"->",
"getResourceManager",
"(",
")",
"->",
"publishAssetFolder",
"(",
"realpath",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/../clients/jquery\"",
")",
")",
";",
"array_push",
"(",
"$",
"lib",
"[",
"\"js\"",
"]",
",",
"$",
"publicAssetUrl",
".",
"\"/jquery.min.js\"",
")",
";",
"break",
";",
"case",
"\"jqueryui\"",
":",
"$",
"publicAssetUrl",
"=",
"$",
"this",
"->",
"getReport",
"(",
")",
"->",
"getResourceManager",
"(",
")",
"->",
"publishAssetFolder",
"(",
"realpath",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/../clients/jquery\"",
")",
")",
";",
"array_push",
"(",
"$",
"lib",
"[",
"\"js\"",
"]",
",",
"$",
"publicAssetUrl",
".",
"\"/jquery-ui.min.js\"",
")",
";",
"break",
";",
"case",
"\"raphael\"",
":",
"$",
"publicAssetUrl",
"=",
"$",
"this",
"->",
"getReport",
"(",
")",
"->",
"getResourceManager",
"(",
")",
"->",
"publishAssetFolder",
"(",
"realpath",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/../clients/raphael\"",
")",
")",
";",
"array_push",
"(",
"$",
"lib",
"[",
"\"js\"",
"]",
",",
"$",
"publicAssetUrl",
".",
"\"/raphael.min.js\"",
")",
";",
"break",
";",
"case",
"\"font-awesome\"",
":",
"$",
"publicAssetUrl",
"=",
"$",
"this",
"->",
"getReport",
"(",
")",
"->",
"getResourceManager",
"(",
")",
"->",
"publishAssetFolder",
"(",
"realpath",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/../clients/font-awesome\"",
")",
")",
";",
"array_push",
"(",
"$",
"lib",
"[",
"\"css\"",
"]",
",",
"$",
"publicAssetUrl",
".",
"\"/css/font-awesome.min.css\"",
")",
";",
"break",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"lib",
"[",
"\"js\"",
"]",
"!=",
"array",
"(",
")",
")",
"{",
"$",
"resources",
"[",
"\"js\"",
"]",
"=",
"array_merge",
"(",
"$",
"lib",
"[",
"\"js\"",
"]",
",",
"array",
"(",
"$",
"resources",
"[",
"\"js\"",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"lib",
"[",
"\"css\"",
"]",
"!=",
"array",
"(",
")",
")",
"{",
"$",
"resources",
"[",
"\"css\"",
"]",
"=",
"array_merge",
"(",
"$",
"lib",
"[",
"\"css\"",
"]",
",",
"array",
"(",
"$",
"resources",
"[",
"\"css\"",
"]",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"resources",
";",
"}"
] | Get the resources for Widget
The method will read the resource settings and
work with report's resource manager
to make widget's resources available to report user.
@param array $settings The resource settings in short form
@return array The list of resource in array | [
"Get",
"the",
"resources",
"for",
"Widget"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L235-L347 |
koolphp/koolreport | src/core/Widget.php | Widget.attachResourceToEnd | protected function attachResourceToEnd(&$destination,$attachment)
{
for ($i=count($destination)-1;$i>-1;$i--) {
if (is_array($destination[$i])) {
if ($this->attachResourceToEnd($destination[$i], $attachment)) {
return true;
}
}
}
array_push($destination, $attachment);
return true;
} | php | protected function attachResourceToEnd(&$destination,$attachment)
{
for ($i=count($destination)-1;$i>-1;$i--) {
if (is_array($destination[$i])) {
if ($this->attachResourceToEnd($destination[$i], $attachment)) {
return true;
}
}
}
array_push($destination, $attachment);
return true;
} | [
"protected",
"function",
"attachResourceToEnd",
"(",
"&",
"$",
"destination",
",",
"$",
"attachment",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"destination",
")",
"-",
"1",
";",
"$",
"i",
">",
"-",
"1",
";",
"$",
"i",
"--",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"destination",
"[",
"$",
"i",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"attachResourceToEnd",
"(",
"$",
"destination",
"[",
"$",
"i",
"]",
",",
"$",
"attachment",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"array_push",
"(",
"$",
"destination",
",",
"$",
"attachment",
")",
";",
"return",
"true",
";",
"}"
] | Attach an resource to end of queue line
@param array $destination Destination
@param array $attachment Attachment
@return bool Return true if resource has been attached | [
"Attach",
"an",
"resource",
"to",
"end",
"of",
"queue",
"line"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L357-L368 |
koolphp/koolreport | src/core/Widget.php | Widget.convertHierachicalResources | protected function convertHierachicalResources(&$resources)
{
foreach ($resources as &$resource) {
if (gettype($resource)=="string") {
$resource = $this->getAssetManager()->getAssetUrl($resource);
} else if (gettype($resource)=="array") {
$this->convertHierachicalResources($resource);
}
}
return $resources;
} | php | protected function convertHierachicalResources(&$resources)
{
foreach ($resources as &$resource) {
if (gettype($resource)=="string") {
$resource = $this->getAssetManager()->getAssetUrl($resource);
} else if (gettype($resource)=="array") {
$this->convertHierachicalResources($resource);
}
}
return $resources;
} | [
"protected",
"function",
"convertHierachicalResources",
"(",
"&",
"$",
"resources",
")",
"{",
"foreach",
"(",
"$",
"resources",
"as",
"&",
"$",
"resource",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"resource",
")",
"==",
"\"string\"",
")",
"{",
"$",
"resource",
"=",
"$",
"this",
"->",
"getAssetManager",
"(",
")",
"->",
"getAssetUrl",
"(",
"$",
"resource",
")",
";",
"}",
"else",
"if",
"(",
"gettype",
"(",
"$",
"resource",
")",
"==",
"\"array\"",
")",
"{",
"$",
"this",
"->",
"convertHierachicalResources",
"(",
"$",
"resource",
")",
";",
"}",
"}",
"return",
"$",
"resources",
";",
"}"
] | The resources settings from short form will be converted to long form
which include full url to each resource
@param array $resources Resources
@return array $resource Resource settings after converted | [
"The",
"resources",
"settings",
"from",
"short",
"form",
"will",
"be",
"converted",
"to",
"long",
"form",
"which",
"include",
"full",
"url",
"to",
"each",
"resource"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L378-L388 |
koolphp/koolreport | src/core/Widget.php | Widget.useAutoName | protected function useAutoName($prefix="widget")
{
if ($this->name==null) {
$this->name = $prefix.Utility::getUniqueId();
}
} | php | protected function useAutoName($prefix="widget")
{
if ($this->name==null) {
$this->name = $prefix.Utility::getUniqueId();
}
} | [
"protected",
"function",
"useAutoName",
"(",
"$",
"prefix",
"=",
"\"widget\"",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"name",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"prefix",
".",
"Utility",
"::",
"getUniqueId",
"(",
")",
";",
"}",
"}"
] | Use by descendant widget class to take name settings
If the name is set by user, the method will not change name
If the name is not set then method will set an unique name for it.
@param string $prefix The prefix to the widget name if
the name is generated automatically.
@return null | [
"Use",
"by",
"descendant",
"widget",
"class",
"to",
"take",
"name",
"settings"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L416-L421 |
koolphp/koolreport | src/core/Widget.php | Widget.standardizeDataSource | protected function standardizeDataSource($dataSource, $args)
{
$finalDataSource = null;
if ($dataSource!==null) {
if (is_callable($dataSource)) {
// If datasource is a function then call it and pass all the available
// parameters from useDataSource()
$dataSource = call_user_func_array($dataSource, $args);
}
if ($dataSource instanceof DataStore) {
$finalDataSource = $dataSource;
} else if (($dataSource instanceof DataSource) || ($dataSource instanceof Process)) {
$finalDataSource = $this->onFurtherProcessRequest($dataSource)->pipe(new DataStore());
} else {
//Should be array or collection
if (count($dataSource)>0) {
$finalDataSource = new DataStore();
$rowType = null; //"assoc","object"
foreach ($dataSource as $i=>$row) {
if ($i==1 && $rowType=="array") {
$meta = $finalDataSource->meta();
$cKeys = array_keys($meta["columns"]);
foreach ($row as $i=>$cValue) {
$meta["columns"][$cKeys[$i]]["type"] = Utility::guessType($cValue);
}
$finalDataSource->meta($meta);
}
if ($i==0) {
$meta = array("columns"=>array());
if (gettype($row)=="object") {
$rowType = "object";
foreach (get_object_vars($row) as $cKey=>$cValue) {
$meta["columns"][$cKey] = array(
"type"=>Utility::guessType($cValue),
);
}
} else if (gettype($row)=="array" && Utility::isAssoc($row)) {
$rowType = "assoc";
foreach ($row as $cKey=>$cValue) {
$meta["columns"][$cKey] = array(
"type"=>Utility::guessType($cValue),
);
}
} else if (gettype($row)=="array") {
$rowType = "array";
foreach ($row as $cValue) {
$meta["columns"][$cValue] = array();
}
$keys_for_array = $row;
} else {
//Nothing yet
}
$finalDataSource->meta($meta);
}
switch($rowType)
{
case "object":
$finalDataSource->push(get_object_vars($row));
break;
case "assoc":
$finalDataSource->push($row);
break;
case "array":
if ($i>0) {
$finalDataSource->push(
array_combine($keys_for_array, $row)
);
}
break;
}
}
} else {
$finalDataSource = new DataStore();
$finalDataSource->data(array());
$finalDataSource->meta(
array(
"columns"=>array(),
)
);
}
}
if (!$finalDataSource->isEnded()) {
$finalDataSource->requestDataSending();
}
}
return $finalDataSource;
} | php | protected function standardizeDataSource($dataSource, $args)
{
$finalDataSource = null;
if ($dataSource!==null) {
if (is_callable($dataSource)) {
// If datasource is a function then call it and pass all the available
// parameters from useDataSource()
$dataSource = call_user_func_array($dataSource, $args);
}
if ($dataSource instanceof DataStore) {
$finalDataSource = $dataSource;
} else if (($dataSource instanceof DataSource) || ($dataSource instanceof Process)) {
$finalDataSource = $this->onFurtherProcessRequest($dataSource)->pipe(new DataStore());
} else {
//Should be array or collection
if (count($dataSource)>0) {
$finalDataSource = new DataStore();
$rowType = null; //"assoc","object"
foreach ($dataSource as $i=>$row) {
if ($i==1 && $rowType=="array") {
$meta = $finalDataSource->meta();
$cKeys = array_keys($meta["columns"]);
foreach ($row as $i=>$cValue) {
$meta["columns"][$cKeys[$i]]["type"] = Utility::guessType($cValue);
}
$finalDataSource->meta($meta);
}
if ($i==0) {
$meta = array("columns"=>array());
if (gettype($row)=="object") {
$rowType = "object";
foreach (get_object_vars($row) as $cKey=>$cValue) {
$meta["columns"][$cKey] = array(
"type"=>Utility::guessType($cValue),
);
}
} else if (gettype($row)=="array" && Utility::isAssoc($row)) {
$rowType = "assoc";
foreach ($row as $cKey=>$cValue) {
$meta["columns"][$cKey] = array(
"type"=>Utility::guessType($cValue),
);
}
} else if (gettype($row)=="array") {
$rowType = "array";
foreach ($row as $cValue) {
$meta["columns"][$cValue] = array();
}
$keys_for_array = $row;
} else {
//Nothing yet
}
$finalDataSource->meta($meta);
}
switch($rowType)
{
case "object":
$finalDataSource->push(get_object_vars($row));
break;
case "assoc":
$finalDataSource->push($row);
break;
case "array":
if ($i>0) {
$finalDataSource->push(
array_combine($keys_for_array, $row)
);
}
break;
}
}
} else {
$finalDataSource = new DataStore();
$finalDataSource->data(array());
$finalDataSource->meta(
array(
"columns"=>array(),
)
);
}
}
if (!$finalDataSource->isEnded()) {
$finalDataSource->requestDataSending();
}
}
return $finalDataSource;
} | [
"protected",
"function",
"standardizeDataSource",
"(",
"$",
"dataSource",
",",
"$",
"args",
")",
"{",
"$",
"finalDataSource",
"=",
"null",
";",
"if",
"(",
"$",
"dataSource",
"!==",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"dataSource",
")",
")",
"{",
"// If datasource is a function then call it and pass all the available",
"// parameters from useDataSource()",
"$",
"dataSource",
"=",
"call_user_func_array",
"(",
"$",
"dataSource",
",",
"$",
"args",
")",
";",
"}",
"if",
"(",
"$",
"dataSource",
"instanceof",
"DataStore",
")",
"{",
"$",
"finalDataSource",
"=",
"$",
"dataSource",
";",
"}",
"else",
"if",
"(",
"(",
"$",
"dataSource",
"instanceof",
"DataSource",
")",
"||",
"(",
"$",
"dataSource",
"instanceof",
"Process",
")",
")",
"{",
"$",
"finalDataSource",
"=",
"$",
"this",
"->",
"onFurtherProcessRequest",
"(",
"$",
"dataSource",
")",
"->",
"pipe",
"(",
"new",
"DataStore",
"(",
")",
")",
";",
"}",
"else",
"{",
"//Should be array or collection",
"if",
"(",
"count",
"(",
"$",
"dataSource",
")",
">",
"0",
")",
"{",
"$",
"finalDataSource",
"=",
"new",
"DataStore",
"(",
")",
";",
"$",
"rowType",
"=",
"null",
";",
"//\"assoc\",\"object\"",
"foreach",
"(",
"$",
"dataSource",
"as",
"$",
"i",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"i",
"==",
"1",
"&&",
"$",
"rowType",
"==",
"\"array\"",
")",
"{",
"$",
"meta",
"=",
"$",
"finalDataSource",
"->",
"meta",
"(",
")",
";",
"$",
"cKeys",
"=",
"array_keys",
"(",
"$",
"meta",
"[",
"\"columns\"",
"]",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"i",
"=>",
"$",
"cValue",
")",
"{",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"cKeys",
"[",
"$",
"i",
"]",
"]",
"[",
"\"type\"",
"]",
"=",
"Utility",
"::",
"guessType",
"(",
"$",
"cValue",
")",
";",
"}",
"$",
"finalDataSource",
"->",
"meta",
"(",
"$",
"meta",
")",
";",
"}",
"if",
"(",
"$",
"i",
"==",
"0",
")",
"{",
"$",
"meta",
"=",
"array",
"(",
"\"columns\"",
"=>",
"array",
"(",
")",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"row",
")",
"==",
"\"object\"",
")",
"{",
"$",
"rowType",
"=",
"\"object\"",
";",
"foreach",
"(",
"get_object_vars",
"(",
"$",
"row",
")",
"as",
"$",
"cKey",
"=>",
"$",
"cValue",
")",
"{",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"cKey",
"]",
"=",
"array",
"(",
"\"type\"",
"=>",
"Utility",
"::",
"guessType",
"(",
"$",
"cValue",
")",
",",
")",
";",
"}",
"}",
"else",
"if",
"(",
"gettype",
"(",
"$",
"row",
")",
"==",
"\"array\"",
"&&",
"Utility",
"::",
"isAssoc",
"(",
"$",
"row",
")",
")",
"{",
"$",
"rowType",
"=",
"\"assoc\"",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"cKey",
"=>",
"$",
"cValue",
")",
"{",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"cKey",
"]",
"=",
"array",
"(",
"\"type\"",
"=>",
"Utility",
"::",
"guessType",
"(",
"$",
"cValue",
")",
",",
")",
";",
"}",
"}",
"else",
"if",
"(",
"gettype",
"(",
"$",
"row",
")",
"==",
"\"array\"",
")",
"{",
"$",
"rowType",
"=",
"\"array\"",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"cValue",
")",
"{",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"cValue",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"keys_for_array",
"=",
"$",
"row",
";",
"}",
"else",
"{",
"//Nothing yet",
"}",
"$",
"finalDataSource",
"->",
"meta",
"(",
"$",
"meta",
")",
";",
"}",
"switch",
"(",
"$",
"rowType",
")",
"{",
"case",
"\"object\"",
":",
"$",
"finalDataSource",
"->",
"push",
"(",
"get_object_vars",
"(",
"$",
"row",
")",
")",
";",
"break",
";",
"case",
"\"assoc\"",
":",
"$",
"finalDataSource",
"->",
"push",
"(",
"$",
"row",
")",
";",
"break",
";",
"case",
"\"array\"",
":",
"if",
"(",
"$",
"i",
">",
"0",
")",
"{",
"$",
"finalDataSource",
"->",
"push",
"(",
"array_combine",
"(",
"$",
"keys_for_array",
",",
"$",
"row",
")",
")",
";",
"}",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"finalDataSource",
"=",
"new",
"DataStore",
"(",
")",
";",
"$",
"finalDataSource",
"->",
"data",
"(",
"array",
"(",
")",
")",
";",
"$",
"finalDataSource",
"->",
"meta",
"(",
"array",
"(",
"\"columns\"",
"=>",
"array",
"(",
")",
",",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"finalDataSource",
"->",
"isEnded",
"(",
")",
")",
"{",
"$",
"finalDataSource",
"->",
"requestDataSending",
"(",
")",
";",
"}",
"}",
"return",
"$",
"finalDataSource",
";",
"}"
] | This function takes $dataSource in all forms and return data source in form of standard
DataStore
@param mixed $dataSource Mixed source include array,collection, DataStore, DataSource, Process
@param array $args Any args will be sent to function used to initiate datasource
@return DataStore A DataStore containing data. | [
"This",
"function",
"takes",
"$dataSource",
"in",
"all",
"forms",
"and",
"return",
"data",
"source",
"in",
"form",
"of",
"standard",
"DataStore"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L432-L524 |
koolphp/koolreport | src/core/Widget.php | Widget.useDataSource | protected function useDataSource()
{
$args = func_get_args();
$dataSource = Utility::get(
$this->params,
"dataSource",
Utility::get($this->params, "dataStore")
);
$this->dataStore = $this->standardizeDataSource($dataSource, $args);
} | php | protected function useDataSource()
{
$args = func_get_args();
$dataSource = Utility::get(
$this->params,
"dataSource",
Utility::get($this->params, "dataStore")
);
$this->dataStore = $this->standardizeDataSource($dataSource, $args);
} | [
"protected",
"function",
"useDataSource",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"dataSource",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"dataSource\"",
",",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"dataStore\"",
")",
")",
";",
"$",
"this",
"->",
"dataStore",
"=",
"$",
"this",
"->",
"standardizeDataSource",
"(",
"$",
"dataSource",
",",
"$",
"args",
")",
";",
"}"
] | Use by descendant widget class to initiate the datasource
@return null | [
"Use",
"by",
"descendant",
"widget",
"class",
"to",
"initiate",
"the",
"datasource"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L531-L540 |
koolphp/koolreport | src/core/Widget.php | Widget.useLanguage | protected function useLanguage()
{
$this->language = Utility::get($this->params, "language");
if ($this->language!==null) {
if (gettype($this->language)=="string") {
$languageFile = $this->getWidgetFolder()
."/languages/"
.Utility::getClassName($this)
."."
.strtolower($this->language)
.".json";
if (is_file($languageFile)) {
$this->languageMap = json_decode(
file_get_contents($languageFile),
true
);
} else {
throw new \Exception("Could not load [$this->language] language file.");
}
} else {
$this->languageMap = $this->language;
}
}
} | php | protected function useLanguage()
{
$this->language = Utility::get($this->params, "language");
if ($this->language!==null) {
if (gettype($this->language)=="string") {
$languageFile = $this->getWidgetFolder()
."/languages/"
.Utility::getClassName($this)
."."
.strtolower($this->language)
.".json";
if (is_file($languageFile)) {
$this->languageMap = json_decode(
file_get_contents($languageFile),
true
);
} else {
throw new \Exception("Could not load [$this->language] language file.");
}
} else {
$this->languageMap = $this->language;
}
}
} | [
"protected",
"function",
"useLanguage",
"(",
")",
"{",
"$",
"this",
"->",
"language",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"language\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"language",
"!==",
"null",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"this",
"->",
"language",
")",
"==",
"\"string\"",
")",
"{",
"$",
"languageFile",
"=",
"$",
"this",
"->",
"getWidgetFolder",
"(",
")",
".",
"\"/languages/\"",
".",
"Utility",
"::",
"getClassName",
"(",
"$",
"this",
")",
".",
"\".\"",
".",
"strtolower",
"(",
"$",
"this",
"->",
"language",
")",
".",
"\".json\"",
";",
"if",
"(",
"is_file",
"(",
"$",
"languageFile",
")",
")",
"{",
"$",
"this",
"->",
"languageMap",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"languageFile",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not load [$this->language] language file.\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"languageMap",
"=",
"$",
"this",
"->",
"language",
";",
"}",
"}",
"}"
] | Register using language settings for widget
@return null | [
"Register",
"using",
"language",
"settings",
"for",
"widget"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L561-L584 |
koolphp/koolreport | src/core/Widget.php | Widget.render | public function render()
{
if ($this->report->fireEvent("OnBeforeWidgetRender", $this)) {
$type=str_replace('\\', '/', get_class($this));
echo "<krwidget widget-name='$this->name' widget-type='$type'"
.($this->themeCssClass?" class='$this->themeCssClass'":"").">";
$this->onRender();
echo "</krwidget>";
}
$this->report->fireEvent("OnWidgetRender", $this);
} | php | public function render()
{
if ($this->report->fireEvent("OnBeforeWidgetRender", $this)) {
$type=str_replace('\\', '/', get_class($this));
echo "<krwidget widget-name='$this->name' widget-type='$type'"
.($this->themeCssClass?" class='$this->themeCssClass'":"").">";
$this->onRender();
echo "</krwidget>";
}
$this->report->fireEvent("OnWidgetRender", $this);
} | [
"public",
"function",
"render",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"report",
"->",
"fireEvent",
"(",
"\"OnBeforeWidgetRender\"",
",",
"$",
"this",
")",
")",
"{",
"$",
"type",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"echo",
"\"<krwidget widget-name='$this->name' widget-type='$type'\"",
".",
"(",
"$",
"this",
"->",
"themeCssClass",
"?",
"\" class='$this->themeCssClass'\"",
":",
"\"\"",
")",
".",
"\">\"",
";",
"$",
"this",
"->",
"onRender",
"(",
")",
";",
"echo",
"\"</krwidget>\"",
";",
"}",
"$",
"this",
"->",
"report",
"->",
"fireEvent",
"(",
"\"OnWidgetRender\"",
",",
"$",
"this",
")",
";",
"}"
] | Render this widget
@return null | [
"Render",
"this",
"widget"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L670-L680 |
koolphp/koolreport | src/core/Widget.php | Widget.template | protected function template($template=null,$variables=null,$return=false)
{
if (!$template) {
$template = Utility::getClassName($this);
} else if (gettype($template)=="array") {
if (gettype($variables)=="boolean") {
$return = $variables;
}
$variables = $template;
$template = Utility::getClassName($this);
}
$currentDir = $this->getWidgetFolder();
$themeBase = $this->getThemeBase();
if ($themeBase && is_file($currentDir."/$template.$themeBase.tpl.php")) {
$template.=".$themeBase";
}
//Try the template with base, if found then use it
if (!is_file($currentDir."/$template.tpl.php")) {
throw new \Exception("Could not find template [$template.tpl.php]");
}
ob_start();
if ($variables) {
foreach ($variables as $key=>$value) {
$$key = $value;
}
}
include $currentDir."/$template.tpl.php";
$output = ob_get_clean();
//$output = preg_replace('/\s+/S'," ", $output);
if ($return) {
return $output;
} else {
echo $output;
}
} | php | protected function template($template=null,$variables=null,$return=false)
{
if (!$template) {
$template = Utility::getClassName($this);
} else if (gettype($template)=="array") {
if (gettype($variables)=="boolean") {
$return = $variables;
}
$variables = $template;
$template = Utility::getClassName($this);
}
$currentDir = $this->getWidgetFolder();
$themeBase = $this->getThemeBase();
if ($themeBase && is_file($currentDir."/$template.$themeBase.tpl.php")) {
$template.=".$themeBase";
}
//Try the template with base, if found then use it
if (!is_file($currentDir."/$template.tpl.php")) {
throw new \Exception("Could not find template [$template.tpl.php]");
}
ob_start();
if ($variables) {
foreach ($variables as $key=>$value) {
$$key = $value;
}
}
include $currentDir."/$template.tpl.php";
$output = ob_get_clean();
//$output = preg_replace('/\s+/S'," ", $output);
if ($return) {
return $output;
} else {
echo $output;
}
} | [
"protected",
"function",
"template",
"(",
"$",
"template",
"=",
"null",
",",
"$",
"variables",
"=",
"null",
",",
"$",
"return",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"template",
")",
"{",
"$",
"template",
"=",
"Utility",
"::",
"getClassName",
"(",
"$",
"this",
")",
";",
"}",
"else",
"if",
"(",
"gettype",
"(",
"$",
"template",
")",
"==",
"\"array\"",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"variables",
")",
"==",
"\"boolean\"",
")",
"{",
"$",
"return",
"=",
"$",
"variables",
";",
"}",
"$",
"variables",
"=",
"$",
"template",
";",
"$",
"template",
"=",
"Utility",
"::",
"getClassName",
"(",
"$",
"this",
")",
";",
"}",
"$",
"currentDir",
"=",
"$",
"this",
"->",
"getWidgetFolder",
"(",
")",
";",
"$",
"themeBase",
"=",
"$",
"this",
"->",
"getThemeBase",
"(",
")",
";",
"if",
"(",
"$",
"themeBase",
"&&",
"is_file",
"(",
"$",
"currentDir",
".",
"\"/$template.$themeBase.tpl.php\"",
")",
")",
"{",
"$",
"template",
".=",
"\".$themeBase\"",
";",
"}",
"//Try the template with base, if found then use it",
"if",
"(",
"!",
"is_file",
"(",
"$",
"currentDir",
".",
"\"/$template.tpl.php\"",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not find template [$template.tpl.php]\"",
")",
";",
"}",
"ob_start",
"(",
")",
";",
"if",
"(",
"$",
"variables",
")",
"{",
"foreach",
"(",
"$",
"variables",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"}",
"include",
"$",
"currentDir",
".",
"\"/$template.tpl.php\"",
";",
"$",
"output",
"=",
"ob_get_clean",
"(",
")",
";",
"//$output = preg_replace('/\\s+/S',\" \", $output);",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"output",
";",
"}",
"else",
"{",
"echo",
"$",
"output",
";",
"}",
"}"
] | Loading template and inject parameters
@param string $template The template name that will be used
to render widget content.
@param array $variables The variables to fill the template
@param bool $return Whether template will render content or
return the content
@return string It could return html of widget
if $return parameter is set to true | [
"Loading",
"template",
"and",
"inject",
"parameters"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L706-L745 |
koolphp/koolreport | src/core/Widget.php | Widget.create | static function create($params,$return=false)
{
$class = get_called_class();
$component = new $class($params);
if ($return) {
ob_start();
$component->render();
return ob_get_clean();
} else {
$component->render();
}
} | php | static function create($params,$return=false)
{
$class = get_called_class();
$component = new $class($params);
if ($return) {
ob_start();
$component->render();
return ob_get_clean();
} else {
$component->render();
}
} | [
"static",
"function",
"create",
"(",
"$",
"params",
",",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"$",
"component",
"=",
"new",
"$",
"class",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"component",
"->",
"render",
"(",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}",
"else",
"{",
"$",
"component",
"->",
"render",
"(",
")",
";",
"}",
"}"
] | Create widget object
@param array $params The settings of widget
@param bool $return Set to true if you want to get html rather than
rendering widget directly
@return string Return html string if $return is set to true | [
"Create",
"widget",
"object"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Widget.php#L755-L766 |
koolphp/koolreport | src/datasources/PostgreSQLDataSource.php | PostgreSQLDataSource.onInit | protected function onInit()
{
$host = Util::get($this->params, "host", "");//host\instanceName
$username = Util::get($this->params, "username", "");
$password = Util::get($this->params, "password", "");
$dbname = Util::get($this->params, "dbname", "");
$connString = "host=$host dbname=$dbname user=$username password=$password";
$key = md5($connString);
if (isset(PostgreSQLDataSource::$connections[$key])) {
$this->connection = PostgreSQLDataSource::$connections[$key];
} else {
$conn = pg_connect($connString);
if ($conn) {
$this->connection = $conn;
} else {
throw new \Exception("Could not connect to database");
}
PostgreSQLDataSource::$connections[$key] = $this->connection;
}
} | php | protected function onInit()
{
$host = Util::get($this->params, "host", "");//host\instanceName
$username = Util::get($this->params, "username", "");
$password = Util::get($this->params, "password", "");
$dbname = Util::get($this->params, "dbname", "");
$connString = "host=$host dbname=$dbname user=$username password=$password";
$key = md5($connString);
if (isset(PostgreSQLDataSource::$connections[$key])) {
$this->connection = PostgreSQLDataSource::$connections[$key];
} else {
$conn = pg_connect($connString);
if ($conn) {
$this->connection = $conn;
} else {
throw new \Exception("Could not connect to database");
}
PostgreSQLDataSource::$connections[$key] = $this->connection;
}
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"$",
"host",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"host\"",
",",
"\"\"",
")",
";",
"//host\\instanceName",
"$",
"username",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"username\"",
",",
"\"\"",
")",
";",
"$",
"password",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"password\"",
",",
"\"\"",
")",
";",
"$",
"dbname",
"=",
"Util",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"dbname\"",
",",
"\"\"",
")",
";",
"$",
"connString",
"=",
"\"host=$host dbname=$dbname user=$username password=$password\"",
";",
"$",
"key",
"=",
"md5",
"(",
"$",
"connString",
")",
";",
"if",
"(",
"isset",
"(",
"PostgreSQLDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"PostgreSQLDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"conn",
"=",
"pg_connect",
"(",
"$",
"connString",
")",
";",
"if",
"(",
"$",
"conn",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"$",
"conn",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not connect to database\"",
")",
";",
"}",
"PostgreSQLDataSource",
"::",
"$",
"connections",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"connection",
";",
"}",
"}"
] | DataSource initiation
@return null | [
"DataSource",
"initiation"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PostgreSQLDataSource.php#L87-L109 |
koolphp/koolreport | src/datasources/PostgreSQLDataSource.php | PostgreSQLDataSource.queryProcessing | public function queryProcessing($queryParams)
{
list($this->query, $this->totalQuery, $this->filterQuery)
= self::processQuery($this->query, $queryParams);
$this->countTotal = Util::get($queryParams, 'countTotal', false);
$this->countFilter = Util::get($queryParams, 'countFilter', false);
return $this;
} | php | public function queryProcessing($queryParams)
{
list($this->query, $this->totalQuery, $this->filterQuery)
= self::processQuery($this->query, $queryParams);
$this->countTotal = Util::get($queryParams, 'countTotal', false);
$this->countFilter = Util::get($queryParams, 'countFilter', false);
return $this;
} | [
"public",
"function",
"queryProcessing",
"(",
"$",
"queryParams",
")",
"{",
"list",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"totalQuery",
",",
"$",
"this",
"->",
"filterQuery",
")",
"=",
"self",
"::",
"processQuery",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"queryParams",
")",
";",
"$",
"this",
"->",
"countTotal",
"=",
"Util",
"::",
"get",
"(",
"$",
"queryParams",
",",
"'countTotal'",
",",
"false",
")",
";",
"$",
"this",
"->",
"countFilter",
"=",
"Util",
"::",
"get",
"(",
"$",
"queryParams",
",",
"'countFilter'",
",",
"false",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Transform query
@param array $queryParams Parameters of query
@return PostgreSQLDataSource Return itself for cascade | [
"Transform",
"query"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PostgreSQLDataSource.php#L162-L171 |
koolphp/koolreport | src/datasources/PostgreSQLDataSource.php | PostgreSQLDataSource.bindParams | protected function bindParams($query, $sqlParams)
{
if (empty($sqlParams)) {
$sqlParams = [];
}
uksort(
$sqlParams,
function ($k1, $k2) {
return strlen($k1) < strlen($k2);
}
);
foreach ($sqlParams as $key=>$value) {
if (gettype($value)==="array") {
$value = array_map(
function ($v) {
return $this->escape($v);
},
$value
);
$value = "(".implode(",", $value).")";
$query = str_replace($key, $value, $query);
} else {
$query = str_replace($key, $this->escape($value), $query);
}
}
return $query;
} | php | protected function bindParams($query, $sqlParams)
{
if (empty($sqlParams)) {
$sqlParams = [];
}
uksort(
$sqlParams,
function ($k1, $k2) {
return strlen($k1) < strlen($k2);
}
);
foreach ($sqlParams as $key=>$value) {
if (gettype($value)==="array") {
$value = array_map(
function ($v) {
return $this->escape($v);
},
$value
);
$value = "(".implode(",", $value).")";
$query = str_replace($key, $value, $query);
} else {
$query = str_replace($key, $this->escape($value), $query);
}
}
return $query;
} | [
"protected",
"function",
"bindParams",
"(",
"$",
"query",
",",
"$",
"sqlParams",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sqlParams",
")",
")",
"{",
"$",
"sqlParams",
"=",
"[",
"]",
";",
"}",
"uksort",
"(",
"$",
"sqlParams",
",",
"function",
"(",
"$",
"k1",
",",
"$",
"k2",
")",
"{",
"return",
"strlen",
"(",
"$",
"k1",
")",
"<",
"strlen",
"(",
"$",
"k2",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"sqlParams",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"value",
")",
"===",
"\"array\"",
")",
"{",
"$",
"value",
"=",
"array_map",
"(",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"$",
"this",
"->",
"escape",
"(",
"$",
"v",
")",
";",
"}",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"\"(\"",
".",
"implode",
"(",
"\",\"",
",",
"$",
"value",
")",
".",
"\")\"",
";",
"$",
"query",
"=",
"str_replace",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"query",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"str_replace",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"escape",
"(",
"$",
"value",
")",
",",
"$",
"query",
")",
";",
"}",
"}",
"return",
"$",
"query",
";",
"}"
] | Perform data binding
@param string $query Query need to bind params
@param array $sqlParams The parameters will be bound to query
@return string Procesed query | [
"Perform",
"data",
"binding"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/PostgreSQLDataSource.php#L194-L220 |
koolphp/koolreport | src/datasources/PostgreSQLDataSource.php | PostgreSQLDataSource.mapFieldTypeToBindType | protected function mapFieldTypeToBindType($native_type)
{
$pg_to_php = array(
'bit' => 'number',
'boolean' => 'string',
'box' => 'string',
'character' => 'string',
'char' => 'number',
'bytea' => 'number',
'cidr' => 'string',
'circle' => 'string',
'date' => 'datetime',
'daterange' => 'datetime',
'real' => 'number',
'double precision' => 'number',
'inet' => 'number',
'smallint' => 'number',
'smallserial' => 'number',
'integer' => 'number',
'serial' => 'number',
'int4range' => 'number',
'bigint' => 'number',
'bigserial' => 'number',
'int8range' => 'number',
'interval' => 'number',
'json' => 'string',
'lseg' => 'string',
'macaddr' => 'string',
'money' => 'number',
'decimal' => 'number',
'numeric' => 'number',
'numrange' => 'number',
'path' => 'string',
'point' => 'string',
'polygon' => 'string',
'text' => 'string',
'time' => 'datetime',
'time without time zone' => 'datetime',
'timestamp' => 'datetime',
'timestamp without time zone' => 'datetime',
'timestamp with time zone' => 'datetime',
'time with time zone' => 'datetime',
'tsquery' => 'string',
'tsrange' => 'string',
'tstzrange' => 'string',
'tsvector' => 'string',
'uuid' => 'number',
'bit varying' => 'number',
'character varying' => 'string',
'varchar' => 'string',
'xml' => 'string'
);
$native_type = strtolower($native_type);
foreach ($pg_to_php as $key=>$value) {
if (strpos($native_type, $key)!==false) {
return $value;
}
}
return "unknown";
} | php | protected function mapFieldTypeToBindType($native_type)
{
$pg_to_php = array(
'bit' => 'number',
'boolean' => 'string',
'box' => 'string',
'character' => 'string',
'char' => 'number',
'bytea' => 'number',
'cidr' => 'string',
'circle' => 'string',
'date' => 'datetime',
'daterange' => 'datetime',
'real' => 'number',
'double precision' => 'number',
'inet' => 'number',
'smallint' => 'number',
'smallserial' => 'number',
'integer' => 'number',
'serial' => 'number',
'int4range' => 'number',
'bigint' => 'number',
'bigserial' => 'number',
'int8range' => 'number',
'interval' => 'number',
'json' => 'string',
'lseg' => 'string',
'macaddr' => 'string',
'money' => 'number',
'decimal' => 'number',
'numeric' => 'number',
'numrange' => 'number',
'path' => 'string',
'point' => 'string',
'polygon' => 'string',
'text' => 'string',
'time' => 'datetime',
'time without time zone' => 'datetime',
'timestamp' => 'datetime',
'timestamp without time zone' => 'datetime',
'timestamp with time zone' => 'datetime',
'time with time zone' => 'datetime',
'tsquery' => 'string',
'tsrange' => 'string',
'tstzrange' => 'string',
'tsvector' => 'string',
'uuid' => 'number',
'bit varying' => 'number',
'character varying' => 'string',
'varchar' => 'string',
'xml' => 'string'
);
$native_type = strtolower($native_type);
foreach ($pg_to_php as $key=>$value) {
if (strpos($native_type, $key)!==false) {
return $value;
}
}
return "unknown";
} | [
"protected",
"function",
"mapFieldTypeToBindType",
"(",
"$",
"native_type",
")",
"{",
"$",
"pg_to_php",
"=",
"array",
"(",
"'bit'",
"=>",
"'number'",
",",
"'boolean'",
"=>",
"'string'",
",",
"'box'",
"=>",
"'string'",
",",
"'character'",
"=>",
"'string'",
",",
"'char'",
"=>",
"'number'",
",",
"'bytea'",
"=>",
"'number'",
",",
"'cidr'",
"=>",
"'string'",
",",
"'circle'",
"=>",
"'string'",
",",
"'date'",
"=>",
"'datetime'",
",",
"'daterange'",
"=>",
"'datetime'",
",",
"'real'",
"=>",
"'number'",
",",
"'double precision'",
"=>",
"'number'",
",",
"'inet'",
"=>",
"'number'",
",",
"'smallint'",
"=>",
"'number'",
",",
"'smallserial'",
"=>",
"'number'",
",",
"'integer'",
"=>",
"'number'",
",",
"'serial'",
"=>",
"'number'",
",",
"'int4range'",
"=>",
"'number'",
",",
"'bigint'",
"=>",
"'number'",
",",
"'bigserial'",
"=>",
"'number'",
",",
"'int8range'",
"=>",
"'number'",
",",
"'interval'",
"=>",
"'number'",
",",
"'json'",
"=>",
"'string'",
",",
"'lseg'",
"=>",
"'string'",
",",
"'macaddr'",
"=>",
"'string'",
",",
"'money'",
"=>",
"'number'",
",",
"'decimal'",
"=>",
"'number'",
",",
"'numeric'",
"=>",
"'number'",
",",
"'numrange'",
"=>",
"'number'",
",",
"'path'",
"=>",
"'string'",
",",
"'point'",
"=>",
"'string'",
",",
"'polygon'",
"=>",
"'string'",
",",
"'text'",
"=>",
"'string'",
",",
"'time'",
"=>",
"'datetime'",
",",
"'time without time zone'",
"=>",
"'datetime'",
",",
"'timestamp'",
"=>",
"'datetime'",
",",
"'timestamp without time zone'",
"=>",
"'datetime'",
",",
"'timestamp with time zone'",
"=>",
"'datetime'",
",",
"'time with time zone'",
"=>",
"'datetime'",
",",
"'tsquery'",
"=>",
"'string'",
",",
"'tsrange'",
"=>",
"'string'",
",",
"'tstzrange'",
"=>",
"'string'",
",",
"'tsvector'",
"=>",
"'string'",
",",
"'uuid'",
"=>",
"'number'",
",",
"'bit varying'",
"=>",
"'number'",
",",
"'character varying'",
"=>",
"'string'",
",",
"'varchar'",
"=>",
"'string'",
",",
"'xml'",
"=>",
"'string'",
")",
";",
"$",
"native_type",
"=",
"strtolower",
"(",
"$",
"native_type",
")",
";",
"foreach",
"(",
"$",
"pg_to_php",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"native_type",
",",
"$",
"key",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"return",
"\"unknown\"",
";",
"}"
] | Map field type to bind type
@param strng $native_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/PostgreSQLDataSource.php#L260-L321 |
koolphp/koolreport | src/datasources/PostgreSQLDataSource.php | PostgreSQLDataSource.start | public function start()
{
$metaData = array("columns"=>array());
if ($this->countTotal) {
$totalQuery = $this->bindParams($this->totalQuery, $this->sqlParams);
$totalResult = pg_query($this->connection, $totalQuery);
if (!$totalResult) {
echo pg_last_error($this->connection);
exit;
}
$row = pg_fetch_array($totalResult);
$total = $row[0];
$metaData['totalRecords'] = $total;
}
if ($this->countFilter) {
$filterQuery = $this->bindParams($this->filterQuery, $this->sqlParams);
$filterResult = pg_query($this->connection, $filterQuery);
if (!$filterResult) {
echo pg_last_error($this->connection);
exit;
}
$row = pg_fetch_array($filterResult);
$total = $row[0];
$metaData['filterRecords'] = $total;
}
$query = $this->bindParams($this->query, $this->sqlParams);
$result = pg_query($this->connection, $query);
if (! $result) {
echo pg_last_error($this->connection);
exit;
}
$num_fields = pg_num_fields($result);
for ($i=0; $i<$num_fields; $i++) {
$name = pg_field_name($result, $i);
$type = pg_field_type($result, $i);
$type = $this->mapFieldTypeToBindType($type);
$metaData["columns"][$name] = array(
"type"=>$type,
);
switch($type)
{
case "datetime":
$metaData["columns"][$name]["format"] = "Y-m-d H:i:s";
break;
case "date":
$metaData["columns"][$name]["format"] = "Y-m-d";
break;
}
}
$this->sendMeta($metaData, $this);
$this->startInput(null);
while ($row = pg_fetch_assoc($result)) {
$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 = pg_query($this->connection, $totalQuery);
if (!$totalResult) {
echo pg_last_error($this->connection);
exit;
}
$row = pg_fetch_array($totalResult);
$total = $row[0];
$metaData['totalRecords'] = $total;
}
if ($this->countFilter) {
$filterQuery = $this->bindParams($this->filterQuery, $this->sqlParams);
$filterResult = pg_query($this->connection, $filterQuery);
if (!$filterResult) {
echo pg_last_error($this->connection);
exit;
}
$row = pg_fetch_array($filterResult);
$total = $row[0];
$metaData['filterRecords'] = $total;
}
$query = $this->bindParams($this->query, $this->sqlParams);
$result = pg_query($this->connection, $query);
if (! $result) {
echo pg_last_error($this->connection);
exit;
}
$num_fields = pg_num_fields($result);
for ($i=0; $i<$num_fields; $i++) {
$name = pg_field_name($result, $i);
$type = pg_field_type($result, $i);
$type = $this->mapFieldTypeToBindType($type);
$metaData["columns"][$name] = array(
"type"=>$type,
);
switch($type)
{
case "datetime":
$metaData["columns"][$name]["format"] = "Y-m-d H:i:s";
break;
case "date":
$metaData["columns"][$name]["format"] = "Y-m-d";
break;
}
}
$this->sendMeta($metaData, $this);
$this->startInput(null);
while ($row = pg_fetch_assoc($result)) {
$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",
"=",
"pg_query",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"totalQuery",
")",
";",
"if",
"(",
"!",
"$",
"totalResult",
")",
"{",
"echo",
"pg_last_error",
"(",
"$",
"this",
"->",
"connection",
")",
";",
"exit",
";",
"}",
"$",
"row",
"=",
"pg_fetch_array",
"(",
"$",
"totalResult",
")",
";",
"$",
"total",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"$",
"metaData",
"[",
"'totalRecords'",
"]",
"=",
"$",
"total",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"countFilter",
")",
"{",
"$",
"filterQuery",
"=",
"$",
"this",
"->",
"bindParams",
"(",
"$",
"this",
"->",
"filterQuery",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"filterResult",
"=",
"pg_query",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"filterQuery",
")",
";",
"if",
"(",
"!",
"$",
"filterResult",
")",
"{",
"echo",
"pg_last_error",
"(",
"$",
"this",
"->",
"connection",
")",
";",
"exit",
";",
"}",
"$",
"row",
"=",
"pg_fetch_array",
"(",
"$",
"filterResult",
")",
";",
"$",
"total",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"$",
"metaData",
"[",
"'filterRecords'",
"]",
"=",
"$",
"total",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"bindParams",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"this",
"->",
"sqlParams",
")",
";",
"$",
"result",
"=",
"pg_query",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"query",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"echo",
"pg_last_error",
"(",
"$",
"this",
"->",
"connection",
")",
";",
"exit",
";",
"}",
"$",
"num_fields",
"=",
"pg_num_fields",
"(",
"$",
"result",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"num_fields",
";",
"$",
"i",
"++",
")",
"{",
"$",
"name",
"=",
"pg_field_name",
"(",
"$",
"result",
",",
"$",
"i",
")",
";",
"$",
"type",
"=",
"pg_field_type",
"(",
"$",
"result",
",",
"$",
"i",
")",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"mapFieldTypeToBindType",
"(",
"$",
"type",
")",
";",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
"\"type\"",
"=>",
"$",
"type",
",",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"\"datetime\"",
":",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"name",
"]",
"[",
"\"format\"",
"]",
"=",
"\"Y-m-d H:i:s\"",
";",
"break",
";",
"case",
"\"date\"",
":",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"name",
"]",
"[",
"\"format\"",
"]",
"=",
"\"Y-m-d\"",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"sendMeta",
"(",
"$",
"metaData",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"startInput",
"(",
"null",
")",
";",
"while",
"(",
"$",
"row",
"=",
"pg_fetch_assoc",
"(",
"$",
"result",
")",
")",
"{",
"$",
"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/PostgreSQLDataSource.php#L328-L392 |
koolphp/koolreport | src/processes/OnlyColumn.php | OnlyColumn.onMetaReceived | protected function onMetaReceived($metaData)
{
$meta = $metaData;
$meta["columns"] = array();
foreach ($this->params as $colname) {
if (isset($metaData["columns"][$colname])) {
$meta["columns"][$colname] = $metaData["columns"][$colname];
}
}
return $meta;
} | php | protected function onMetaReceived($metaData)
{
$meta = $metaData;
$meta["columns"] = array();
foreach ($this->params as $colname) {
if (isset($metaData["columns"][$colname])) {
$meta["columns"][$colname] = $metaData["columns"][$colname];
}
}
return $meta;
} | [
"protected",
"function",
"onMetaReceived",
"(",
"$",
"metaData",
")",
"{",
"$",
"meta",
"=",
"$",
"metaData",
";",
"$",
"meta",
"[",
"\"columns\"",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"colname",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"colname",
"]",
")",
")",
"{",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"colname",
"]",
"=",
"$",
"metaData",
"[",
"\"columns\"",
"]",
"[",
"$",
"colname",
"]",
";",
"}",
"}",
"return",
"$",
"meta",
";",
"}"
] | 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/OnlyColumn.php#L44-L54 |
koolphp/koolreport | src/processes/OnlyColumn.php | OnlyColumn.onInput | protected function onInput($data)
{
$ndata = array();
foreach ($this->params as $colname) {
if (isset($data[$colname])) {
$ndata[$colname] = $data[$colname];
}
}
$this->next($ndata);
} | php | protected function onInput($data)
{
$ndata = array();
foreach ($this->params as $colname) {
if (isset($data[$colname])) {
$ndata[$colname] = $data[$colname];
}
}
$this->next($ndata);
} | [
"protected",
"function",
"onInput",
"(",
"$",
"data",
")",
"{",
"$",
"ndata",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"colname",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"colname",
"]",
")",
")",
"{",
"$",
"ndata",
"[",
"$",
"colname",
"]",
"=",
"$",
"data",
"[",
"$",
"colname",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"next",
"(",
"$",
"ndata",
")",
";",
"}"
] | 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/OnlyColumn.php#L63-L73 |
koolphp/koolreport | src/widgets/google/Chart.php | Chart.onInit | protected function onInit()
{
$this->useDataSource();
$this->useAutoName("gchart");
$this->clientEvents = Utility::get($this->params, "clientEvents", array());
$this->columns = Utility::get($this->params, "columns", null);
$this->options = Utility::get($this->params, "options", array());
$this->width = Utility::get($this->params, "width", "100%");
$this->height = Utility::get($this->params, "height", "400px");
$this->title = Utility::get($this->params, "title");
$this->pointerOnHover = Utility::get($this->params, "pointerOnHover");
$this->mapsApiKey = Utility::get($this->params, "mapsApiKey", '');
if (!$this->dataStore) {
//Backward compatible with setting through "data"
$data = Utility::get($this->params, "data");
if (is_array($data)) {
if (count($data) > 0) {
$this->dataStore = new DataStore;
$this->dataStore->data($data);
$row = $data[0];
$meta = array("columns" => array());
foreach ($row as $cKey => $cValue) {
$meta["columns"][$cKey] = array(
"type" => Utility::guessType($cValue),
);
}
$this->dataStore->meta($meta);
} else {
$this->dataStore = new DataStore;
$this->dataStore->data(array());
$this->dataStore->meta(array("columns" => array()));
}
}
if ($this->dataStore == null) {
throw new \Exception("dataSource is required");
return;
}
}
$this->type = Utility::getClassName($this);
if ($this->type == "Chart") {
$this->type = Utility::get($this->params, "type");
}
//Color Scheme
$this->colorScheme = Utility::get($this->params, "colorScheme");
if (!is_array($this->colorScheme)) {
$theme = $this->getReport()->getTheme();
if ($theme) {
$theme->applyColorScheme($this->colorScheme);
}
}
if (!is_array($this->colorScheme)) {
$this->colorScheme = null;
}
} | php | protected function onInit()
{
$this->useDataSource();
$this->useAutoName("gchart");
$this->clientEvents = Utility::get($this->params, "clientEvents", array());
$this->columns = Utility::get($this->params, "columns", null);
$this->options = Utility::get($this->params, "options", array());
$this->width = Utility::get($this->params, "width", "100%");
$this->height = Utility::get($this->params, "height", "400px");
$this->title = Utility::get($this->params, "title");
$this->pointerOnHover = Utility::get($this->params, "pointerOnHover");
$this->mapsApiKey = Utility::get($this->params, "mapsApiKey", '');
if (!$this->dataStore) {
//Backward compatible with setting through "data"
$data = Utility::get($this->params, "data");
if (is_array($data)) {
if (count($data) > 0) {
$this->dataStore = new DataStore;
$this->dataStore->data($data);
$row = $data[0];
$meta = array("columns" => array());
foreach ($row as $cKey => $cValue) {
$meta["columns"][$cKey] = array(
"type" => Utility::guessType($cValue),
);
}
$this->dataStore->meta($meta);
} else {
$this->dataStore = new DataStore;
$this->dataStore->data(array());
$this->dataStore->meta(array("columns" => array()));
}
}
if ($this->dataStore == null) {
throw new \Exception("dataSource is required");
return;
}
}
$this->type = Utility::getClassName($this);
if ($this->type == "Chart") {
$this->type = Utility::get($this->params, "type");
}
//Color Scheme
$this->colorScheme = Utility::get($this->params, "colorScheme");
if (!is_array($this->colorScheme)) {
$theme = $this->getReport()->getTheme();
if ($theme) {
$theme->applyColorScheme($this->colorScheme);
}
}
if (!is_array($this->colorScheme)) {
$this->colorScheme = null;
}
} | [
"protected",
"function",
"onInit",
"(",
")",
"{",
"$",
"this",
"->",
"useDataSource",
"(",
")",
";",
"$",
"this",
"->",
"useAutoName",
"(",
"\"gchart\"",
")",
";",
"$",
"this",
"->",
"clientEvents",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"clientEvents\"",
",",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"columns",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"columns\"",
",",
"null",
")",
";",
"$",
"this",
"->",
"options",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"options\"",
",",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"width",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"width\"",
",",
"\"100%\"",
")",
";",
"$",
"this",
"->",
"height",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"height\"",
",",
"\"400px\"",
")",
";",
"$",
"this",
"->",
"title",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"title\"",
")",
";",
"$",
"this",
"->",
"pointerOnHover",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"pointerOnHover\"",
")",
";",
"$",
"this",
"->",
"mapsApiKey",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"mapsApiKey\"",
",",
"''",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"dataStore",
")",
"{",
"//Backward compatible with setting through \"data\"",
"$",
"data",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"data\"",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"data",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"dataStore",
"=",
"new",
"DataStore",
";",
"$",
"this",
"->",
"dataStore",
"->",
"data",
"(",
"$",
"data",
")",
";",
"$",
"row",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"$",
"meta",
"=",
"array",
"(",
"\"columns\"",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"cKey",
"=>",
"$",
"cValue",
")",
"{",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"cKey",
"]",
"=",
"array",
"(",
"\"type\"",
"=>",
"Utility",
"::",
"guessType",
"(",
"$",
"cValue",
")",
",",
")",
";",
"}",
"$",
"this",
"->",
"dataStore",
"->",
"meta",
"(",
"$",
"meta",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"dataStore",
"=",
"new",
"DataStore",
";",
"$",
"this",
"->",
"dataStore",
"->",
"data",
"(",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"dataStore",
"->",
"meta",
"(",
"array",
"(",
"\"columns\"",
"=>",
"array",
"(",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"dataStore",
"==",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"dataSource is required\"",
")",
";",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"type",
"=",
"Utility",
"::",
"getClassName",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"\"Chart\"",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"type\"",
")",
";",
"}",
"//Color Scheme",
"$",
"this",
"->",
"colorScheme",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"\"colorScheme\"",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"colorScheme",
")",
")",
"{",
"$",
"theme",
"=",
"$",
"this",
"->",
"getReport",
"(",
")",
"->",
"getTheme",
"(",
")",
";",
"if",
"(",
"$",
"theme",
")",
"{",
"$",
"theme",
"->",
"applyColorScheme",
"(",
"$",
"this",
"->",
"colorScheme",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"colorScheme",
")",
")",
"{",
"$",
"this",
"->",
"colorScheme",
"=",
"null",
";",
"}",
"}"
] | Return the resource settings for table
@return array The resource settings of table widget | [
"Return",
"the",
"resource",
"settings",
"for",
"table"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/Chart.php#L66-L122 |
koolphp/koolreport | src/widgets/google/Chart.php | Chart.getColumnSettings | protected function getColumnSettings()
{
//If there is the user input columns then parse them to columns from user input
//If the user does not input collumns then take the default by looking at data
// Then mixed with default in meta
$meta = $this->dataStore->meta();
$columns = array();
if ($this->columns != null) {
foreach ($this->columns as $cKey => $cValue) {
if (gettype($cValue) == "array") {
$columns[$cKey] = array_merge($meta["columns"][$cKey], $cValue);
} else {
$columns[$cValue] = $meta["columns"][$cValue];
}
}
} else {
$keys = array_keys($this->dataStore[0]);
foreach ($keys as $ckey) {
$columns[$ckey] = $meta["columns"][$ckey];
}
}
return $columns;
} | php | protected function getColumnSettings()
{
//If there is the user input columns then parse them to columns from user input
//If the user does not input collumns then take the default by looking at data
// Then mixed with default in meta
$meta = $this->dataStore->meta();
$columns = array();
if ($this->columns != null) {
foreach ($this->columns as $cKey => $cValue) {
if (gettype($cValue) == "array") {
$columns[$cKey] = array_merge($meta["columns"][$cKey], $cValue);
} else {
$columns[$cValue] = $meta["columns"][$cValue];
}
}
} else {
$keys = array_keys($this->dataStore[0]);
foreach ($keys as $ckey) {
$columns[$ckey] = $meta["columns"][$ckey];
}
}
return $columns;
} | [
"protected",
"function",
"getColumnSettings",
"(",
")",
"{",
"//If there is the user input columns then parse them to columns from user input",
"//If the user does not input collumns then take the default by looking at data",
"// Then mixed with default in meta",
"$",
"meta",
"=",
"$",
"this",
"->",
"dataStore",
"->",
"meta",
"(",
")",
";",
"$",
"columns",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"columns",
"!=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"cKey",
"=>",
"$",
"cValue",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"cValue",
")",
"==",
"\"array\"",
")",
"{",
"$",
"columns",
"[",
"$",
"cKey",
"]",
"=",
"array_merge",
"(",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"cKey",
"]",
",",
"$",
"cValue",
")",
";",
"}",
"else",
"{",
"$",
"columns",
"[",
"$",
"cValue",
"]",
"=",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"cValue",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"dataStore",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"ckey",
")",
"{",
"$",
"columns",
"[",
"$",
"ckey",
"]",
"=",
"$",
"meta",
"[",
"\"columns\"",
"]",
"[",
"$",
"ckey",
"]",
";",
"}",
"}",
"return",
"$",
"columns",
";",
"}"
] | Improve the column settings
@return array Collumn section | [
"Improve",
"the",
"column",
"settings"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/Chart.php#L147-L169 |
koolphp/koolreport | src/widgets/google/Chart.php | Chart.prepareData | protected function prepareData()
{
//Now we have $columns contain all real columns settings
$columns = $this->getColumnSettings();
$data = array();
$header = array();
$columnExtraRoles = array("annotation", "annotationText", "certainty", "emphasis", "interval", "scope", "style", "tooltip");
foreach ($columns as $cKey => $cSetting) {
array_push($header, "" . Utility::get($cSetting, "label", $cKey));
foreach ($columnExtraRoles as $cRole) {
if (isset($cSetting[$cRole])) {
array_push(
$header,
array(
"role" => $cRole,
)
);
}
}
}
array_push($data, $header);
foreach ($this->dataStore as $row) {
$gRow = array();
foreach ($columns as $cKey => $cSetting) {
$value = $row[$cKey];
$cType = Utility::get($cSetting, "type", "unknown");
if ($cType === "number") {
$value = floatval($value);
} else if ($cType === "string") {
$value = "$value";
}
$fValue = $this->formatValue($value, $cSetting, $row);
array_push(
$gRow,
($fValue === $value)
? $value
: array("v" => $value, "f" => $fValue)
);
foreach ($columnExtraRoles as $cRole) {
if (isset($cSetting[$cRole])) {
array_push(
$gRow,
(gettype($cSetting[$cRole]) == "object") ?
$cSetting[$cRole]($row) :
$cSetting[$cRole]
);
}
}
}
array_push($data, $gRow);
}
return $data;
} | php | protected function prepareData()
{
//Now we have $columns contain all real columns settings
$columns = $this->getColumnSettings();
$data = array();
$header = array();
$columnExtraRoles = array("annotation", "annotationText", "certainty", "emphasis", "interval", "scope", "style", "tooltip");
foreach ($columns as $cKey => $cSetting) {
array_push($header, "" . Utility::get($cSetting, "label", $cKey));
foreach ($columnExtraRoles as $cRole) {
if (isset($cSetting[$cRole])) {
array_push(
$header,
array(
"role" => $cRole,
)
);
}
}
}
array_push($data, $header);
foreach ($this->dataStore as $row) {
$gRow = array();
foreach ($columns as $cKey => $cSetting) {
$value = $row[$cKey];
$cType = Utility::get($cSetting, "type", "unknown");
if ($cType === "number") {
$value = floatval($value);
} else if ($cType === "string") {
$value = "$value";
}
$fValue = $this->formatValue($value, $cSetting, $row);
array_push(
$gRow,
($fValue === $value)
? $value
: array("v" => $value, "f" => $fValue)
);
foreach ($columnExtraRoles as $cRole) {
if (isset($cSetting[$cRole])) {
array_push(
$gRow,
(gettype($cSetting[$cRole]) == "object") ?
$cSetting[$cRole]($row) :
$cSetting[$cRole]
);
}
}
}
array_push($data, $gRow);
}
return $data;
} | [
"protected",
"function",
"prepareData",
"(",
")",
"{",
"//Now we have $columns contain all real columns settings",
"$",
"columns",
"=",
"$",
"this",
"->",
"getColumnSettings",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"header",
"=",
"array",
"(",
")",
";",
"$",
"columnExtraRoles",
"=",
"array",
"(",
"\"annotation\"",
",",
"\"annotationText\"",
",",
"\"certainty\"",
",",
"\"emphasis\"",
",",
"\"interval\"",
",",
"\"scope\"",
",",
"\"style\"",
",",
"\"tooltip\"",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"cKey",
"=>",
"$",
"cSetting",
")",
"{",
"array_push",
"(",
"$",
"header",
",",
"\"\"",
".",
"Utility",
"::",
"get",
"(",
"$",
"cSetting",
",",
"\"label\"",
",",
"$",
"cKey",
")",
")",
";",
"foreach",
"(",
"$",
"columnExtraRoles",
"as",
"$",
"cRole",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cSetting",
"[",
"$",
"cRole",
"]",
")",
")",
"{",
"array_push",
"(",
"$",
"header",
",",
"array",
"(",
"\"role\"",
"=>",
"$",
"cRole",
",",
")",
")",
";",
"}",
"}",
"}",
"array_push",
"(",
"$",
"data",
",",
"$",
"header",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"dataStore",
"as",
"$",
"row",
")",
"{",
"$",
"gRow",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"cKey",
"=>",
"$",
"cSetting",
")",
"{",
"$",
"value",
"=",
"$",
"row",
"[",
"$",
"cKey",
"]",
";",
"$",
"cType",
"=",
"Utility",
"::",
"get",
"(",
"$",
"cSetting",
",",
"\"type\"",
",",
"\"unknown\"",
")",
";",
"if",
"(",
"$",
"cType",
"===",
"\"number\"",
")",
"{",
"$",
"value",
"=",
"floatval",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"cType",
"===",
"\"string\"",
")",
"{",
"$",
"value",
"=",
"\"$value\"",
";",
"}",
"$",
"fValue",
"=",
"$",
"this",
"->",
"formatValue",
"(",
"$",
"value",
",",
"$",
"cSetting",
",",
"$",
"row",
")",
";",
"array_push",
"(",
"$",
"gRow",
",",
"(",
"$",
"fValue",
"===",
"$",
"value",
")",
"?",
"$",
"value",
":",
"array",
"(",
"\"v\"",
"=>",
"$",
"value",
",",
"\"f\"",
"=>",
"$",
"fValue",
")",
")",
";",
"foreach",
"(",
"$",
"columnExtraRoles",
"as",
"$",
"cRole",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cSetting",
"[",
"$",
"cRole",
"]",
")",
")",
"{",
"array_push",
"(",
"$",
"gRow",
",",
"(",
"gettype",
"(",
"$",
"cSetting",
"[",
"$",
"cRole",
"]",
")",
"==",
"\"object\"",
")",
"?",
"$",
"cSetting",
"[",
"$",
"cRole",
"]",
"(",
"$",
"row",
")",
":",
"$",
"cSetting",
"[",
"$",
"cRole",
"]",
")",
";",
"}",
"}",
"}",
"array_push",
"(",
"$",
"data",
",",
"$",
"gRow",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Prepare data
@return null | [
"Prepare",
"data"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/Chart.php#L176-L233 |
koolphp/koolreport | src/widgets/google/Chart.php | Chart.formatValue | protected function formatValue($value, $format, $row = null)
{
$formatValue = Utility::get($format, "formatValue", null);
if (is_string($formatValue)) {
eval('$fv="' . str_replace('@value', '$value', $formatValue) . '";');
return $fv;
} else if (is_callable($formatValue)) {
return $formatValue($value, $row);
} else {
return Utility::format($value, $format);
}
} | php | protected function formatValue($value, $format, $row = null)
{
$formatValue = Utility::get($format, "formatValue", null);
if (is_string($formatValue)) {
eval('$fv="' . str_replace('@value', '$value', $formatValue) . '";');
return $fv;
} else if (is_callable($formatValue)) {
return $formatValue($value, $row);
} else {
return Utility::format($value, $format);
}
} | [
"protected",
"function",
"formatValue",
"(",
"$",
"value",
",",
"$",
"format",
",",
"$",
"row",
"=",
"null",
")",
"{",
"$",
"formatValue",
"=",
"Utility",
"::",
"get",
"(",
"$",
"format",
",",
"\"formatValue\"",
",",
"null",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"formatValue",
")",
")",
"{",
"eval",
"(",
"'$fv=\"'",
".",
"str_replace",
"(",
"'@value'",
",",
"'$value'",
",",
"$",
"formatValue",
")",
".",
"'\";'",
")",
";",
"return",
"$",
"fv",
";",
"}",
"else",
"if",
"(",
"is_callable",
"(",
"$",
"formatValue",
")",
")",
"{",
"return",
"$",
"formatValue",
"(",
"$",
"value",
",",
"$",
"row",
")",
";",
"}",
"else",
"{",
"return",
"Utility",
"::",
"format",
"(",
"$",
"value",
",",
"$",
"format",
")",
";",
"}",
"}"
] | Return the formatted value
@param mixed $value The value needed to be formatted
@param array $format The format
@param array $row The row containing this value
@return null | [
"Return",
"the",
"formatted",
"value"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/Chart.php#L244-L256 |
koolphp/koolreport | src/widgets/google/Chart.php | Chart.onRender | protected function onRender()
{
if ($this->dataStore->countData() > 0) {
//Update options
$options = $this->options;
if ($this->title) {
$options["title"] = $this->title;
}
if ($this->colorScheme) {
$options["colors"] = $this->colorScheme;
}
//Render
$this->template(
"Chart",
array(
"chartType" => $this->type,
"options" => $options,
"data" => $this->prepareData(),
"cKeys" => array_keys($this->getColumnSettings()),
"loader"=>array(
"package"=>$this->package,
"stability"=>$this->stability,
"mapsApiKey"=>$this->mapsApiKey
)
)
);
} else {
$this->template("NoData");
}
} | php | protected function onRender()
{
if ($this->dataStore->countData() > 0) {
//Update options
$options = $this->options;
if ($this->title) {
$options["title"] = $this->title;
}
if ($this->colorScheme) {
$options["colors"] = $this->colorScheme;
}
//Render
$this->template(
"Chart",
array(
"chartType" => $this->type,
"options" => $options,
"data" => $this->prepareData(),
"cKeys" => array_keys($this->getColumnSettings()),
"loader"=>array(
"package"=>$this->package,
"stability"=>$this->stability,
"mapsApiKey"=>$this->mapsApiKey
)
)
);
} else {
$this->template("NoData");
}
} | [
"protected",
"function",
"onRender",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dataStore",
"->",
"countData",
"(",
")",
">",
"0",
")",
"{",
"//Update options",
"$",
"options",
"=",
"$",
"this",
"->",
"options",
";",
"if",
"(",
"$",
"this",
"->",
"title",
")",
"{",
"$",
"options",
"[",
"\"title\"",
"]",
"=",
"$",
"this",
"->",
"title",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"colorScheme",
")",
"{",
"$",
"options",
"[",
"\"colors\"",
"]",
"=",
"$",
"this",
"->",
"colorScheme",
";",
"}",
"//Render",
"$",
"this",
"->",
"template",
"(",
"\"Chart\"",
",",
"array",
"(",
"\"chartType\"",
"=>",
"$",
"this",
"->",
"type",
",",
"\"options\"",
"=>",
"$",
"options",
",",
"\"data\"",
"=>",
"$",
"this",
"->",
"prepareData",
"(",
")",
",",
"\"cKeys\"",
"=>",
"array_keys",
"(",
"$",
"this",
"->",
"getColumnSettings",
"(",
")",
")",
",",
"\"loader\"",
"=>",
"array",
"(",
"\"package\"",
"=>",
"$",
"this",
"->",
"package",
",",
"\"stability\"",
"=>",
"$",
"this",
"->",
"stability",
",",
"\"mapsApiKey\"",
"=>",
"$",
"this",
"->",
"mapsApiKey",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"template",
"(",
"\"NoData\"",
")",
";",
"}",
"}"
] | Handle on render
@return null | [
"Handle",
"on",
"render"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/Chart.php#L263-L292 |
koolphp/koolreport | src/processes/Transpose2.php | Transpose2.onInputEnd | protected function onInputEnd()
{
//Send meta
$countRow = count($this->data);
$oldCKeys = array_keys($this->metaData['columns']);
$cMetas = [
'c0' => array("type" => "string"),
];
foreach ($this->data as $row) {
$cMetas[$row[$oldCKeys[0]]] = ['type' => 'unknown'];
}
// Utility::prettyPrint($cMetas); echo '<br>';
$newMeta = array(
"columns" => $cMetas,
);
$this->sendMeta($newMeta);
foreach ($oldCKeys as $i => $oldCKey) {
if ($i === 0) {
continue;
}
$newRow = ['c0' => $oldCKey];
foreach ($this->data as $row) {
$newRow[$row[$oldCKeys[0]]] = $row[$oldCKey];
}
$this->next($newRow);
}
} | php | protected function onInputEnd()
{
//Send meta
$countRow = count($this->data);
$oldCKeys = array_keys($this->metaData['columns']);
$cMetas = [
'c0' => array("type" => "string"),
];
foreach ($this->data as $row) {
$cMetas[$row[$oldCKeys[0]]] = ['type' => 'unknown'];
}
// Utility::prettyPrint($cMetas); echo '<br>';
$newMeta = array(
"columns" => $cMetas,
);
$this->sendMeta($newMeta);
foreach ($oldCKeys as $i => $oldCKey) {
if ($i === 0) {
continue;
}
$newRow = ['c0' => $oldCKey];
foreach ($this->data as $row) {
$newRow[$row[$oldCKeys[0]]] = $row[$oldCKey];
}
$this->next($newRow);
}
} | [
"protected",
"function",
"onInputEnd",
"(",
")",
"{",
"//Send meta",
"$",
"countRow",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"oldCKeys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"metaData",
"[",
"'columns'",
"]",
")",
";",
"$",
"cMetas",
"=",
"[",
"'c0'",
"=>",
"array",
"(",
"\"type\"",
"=>",
"\"string\"",
")",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"cMetas",
"[",
"$",
"row",
"[",
"$",
"oldCKeys",
"[",
"0",
"]",
"]",
"]",
"=",
"[",
"'type'",
"=>",
"'unknown'",
"]",
";",
"}",
"// Utility::prettyPrint($cMetas); echo '<br>';",
"$",
"newMeta",
"=",
"array",
"(",
"\"columns\"",
"=>",
"$",
"cMetas",
",",
")",
";",
"$",
"this",
"->",
"sendMeta",
"(",
"$",
"newMeta",
")",
";",
"foreach",
"(",
"$",
"oldCKeys",
"as",
"$",
"i",
"=>",
"$",
"oldCKey",
")",
"{",
"if",
"(",
"$",
"i",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"newRow",
"=",
"[",
"'c0'",
"=>",
"$",
"oldCKey",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"newRow",
"[",
"$",
"row",
"[",
"$",
"oldCKeys",
"[",
"0",
"]",
"]",
"]",
"=",
"$",
"row",
"[",
"$",
"oldCKey",
"]",
";",
"}",
"$",
"this",
"->",
"next",
"(",
"$",
"newRow",
")",
";",
"}",
"}"
] | Handle on data input end
@return null | [
"Handle",
"on",
"data",
"input",
"end"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Transpose2.php#L76-L105 |
koolphp/koolreport | src/processes/ColumnsSort.php | ColumnsSort.onInit | public function onInit()
{
$this->nameSort = Utility::get($this->params, '{name}', null);
$this->labelSort = Utility::get($this->params, '{label}', null);
$this->fixedColumns = Utility::get($this->params, 'fixedColumns', null);
} | php | public function onInit()
{
$this->nameSort = Utility::get($this->params, '{name}', null);
$this->labelSort = Utility::get($this->params, '{label}', null);
$this->fixedColumns = Utility::get($this->params, 'fixedColumns', null);
} | [
"public",
"function",
"onInit",
"(",
")",
"{",
"$",
"this",
"->",
"nameSort",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"'{name}'",
",",
"null",
")",
";",
"$",
"this",
"->",
"labelSort",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"'{label}'",
",",
"null",
")",
";",
"$",
"this",
"->",
"fixedColumns",
"=",
"Utility",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
",",
"'fixedColumns'",
",",
"null",
")",
";",
"}"
] | Process initiation
@return null | [
"Process",
"initiation"
] | train | https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/ColumnsSort.php#L49-L54 |
koolphp/koolreport | src/processes/ColumnsSort.php | ColumnsSort.onInput | protected function onInput($row)
{
if (!isset($this->sortedColumns)) {
$columns = array_keys($row);
$columnsToSort = array();
$fixedColumns = isset($this->fixedColumns) ? $this->fixedColumns : array();
foreach ($columns as $i => $colName) {
if (!array_key_exists($i, $fixedColumns)
&& !array_key_exists($colName, $fixedColumns)
) {
$columnsToSort[$i] = $colName;
}
}
if (isset($this->nameSort)) {
$sort = $this->nameSort;
uasort(
$columnsToSort,
function ($a, $b) use ($sort) {
$cmp = 0;
if (is_string($sort)) {
$cmp = is_numeric($a) && is_numeric($b) ?
$a - $b : strcmp($a, $b);
$cmp = $sort === 'asc' ? $cmp : -$cmp;
} else if (is_callable($sort)) {
$cmp = $sort($a, $b);
}
return $cmp;
}
);
}
if (isset($this->labelSort)) {
$sort = $this->nameSort;
$meta = $this->meta;
uasort(
$columnsToSort,
function ($a, $b) use ($sort, $meta) {
$cmp = 0;
$a = isset($meta[$a]['label']) ? $meta[$a]['label'] : '';
$b = isset($meta[$b]['label']) ? $meta[$a]['label'] : '';
if (is_string($sort)) {
$cmp = is_numeric($a) && is_numeric($b) ?
$a - $b : strcmp($a, $b);
$cmp = $sort === 'asc' ? $cmp : -$cmp;
} else if (is_callable($sort)) {
$cmp = $sort($a, $b);
}
return $cmp;
}
);
}
$sortedColumns = array();
foreach ($fixedColumns as $i => $pos) {
if (is_numeric($i)) {
$sortedColumns[$pos] = $columns[$i];
} else {
$sortedColumns[$pos] = $i;
}
}
$i = 0;
foreach ($columnsToSort as $column) {
while (isset($sortedColumns[$i])) {
$i++;
}
$sortedColumns[$i] = $column;
$i++;
}
ksort($sortedColumns);
$this->sortedColumns = $sortedColumns;
}
$newRow = array();
foreach ($this->sortedColumns as $column) {
$newRow[$column] = $row[$column];
}
$this->next($newRow);
} | php | protected function onInput($row)
{
if (!isset($this->sortedColumns)) {
$columns = array_keys($row);
$columnsToSort = array();
$fixedColumns = isset($this->fixedColumns) ? $this->fixedColumns : array();
foreach ($columns as $i => $colName) {
if (!array_key_exists($i, $fixedColumns)
&& !array_key_exists($colName, $fixedColumns)
) {
$columnsToSort[$i] = $colName;
}
}
if (isset($this->nameSort)) {
$sort = $this->nameSort;
uasort(
$columnsToSort,
function ($a, $b) use ($sort) {
$cmp = 0;
if (is_string($sort)) {
$cmp = is_numeric($a) && is_numeric($b) ?
$a - $b : strcmp($a, $b);
$cmp = $sort === 'asc' ? $cmp : -$cmp;
} else if (is_callable($sort)) {
$cmp = $sort($a, $b);
}
return $cmp;
}
);
}
if (isset($this->labelSort)) {
$sort = $this->nameSort;
$meta = $this->meta;
uasort(
$columnsToSort,
function ($a, $b) use ($sort, $meta) {
$cmp = 0;
$a = isset($meta[$a]['label']) ? $meta[$a]['label'] : '';
$b = isset($meta[$b]['label']) ? $meta[$a]['label'] : '';
if (is_string($sort)) {
$cmp = is_numeric($a) && is_numeric($b) ?
$a - $b : strcmp($a, $b);
$cmp = $sort === 'asc' ? $cmp : -$cmp;
} else if (is_callable($sort)) {
$cmp = $sort($a, $b);
}
return $cmp;
}
);
}
$sortedColumns = array();
foreach ($fixedColumns as $i => $pos) {
if (is_numeric($i)) {
$sortedColumns[$pos] = $columns[$i];
} else {
$sortedColumns[$pos] = $i;
}
}
$i = 0;
foreach ($columnsToSort as $column) {
while (isset($sortedColumns[$i])) {
$i++;
}
$sortedColumns[$i] = $column;
$i++;
}
ksort($sortedColumns);
$this->sortedColumns = $sortedColumns;
}
$newRow = array();
foreach ($this->sortedColumns as $column) {
$newRow[$column] = $row[$column];
}
$this->next($newRow);
} | [
"protected",
"function",
"onInput",
"(",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"sortedColumns",
")",
")",
"{",
"$",
"columns",
"=",
"array_keys",
"(",
"$",
"row",
")",
";",
"$",
"columnsToSort",
"=",
"array",
"(",
")",
";",
"$",
"fixedColumns",
"=",
"isset",
"(",
"$",
"this",
"->",
"fixedColumns",
")",
"?",
"$",
"this",
"->",
"fixedColumns",
":",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"i",
"=>",
"$",
"colName",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"i",
",",
"$",
"fixedColumns",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"colName",
",",
"$",
"fixedColumns",
")",
")",
"{",
"$",
"columnsToSort",
"[",
"$",
"i",
"]",
"=",
"$",
"colName",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"nameSort",
")",
")",
"{",
"$",
"sort",
"=",
"$",
"this",
"->",
"nameSort",
";",
"uasort",
"(",
"$",
"columnsToSort",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"sort",
")",
"{",
"$",
"cmp",
"=",
"0",
";",
"if",
"(",
"is_string",
"(",
"$",
"sort",
")",
")",
"{",
"$",
"cmp",
"=",
"is_numeric",
"(",
"$",
"a",
")",
"&&",
"is_numeric",
"(",
"$",
"b",
")",
"?",
"$",
"a",
"-",
"$",
"b",
":",
"strcmp",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"$",
"cmp",
"=",
"$",
"sort",
"===",
"'asc'",
"?",
"$",
"cmp",
":",
"-",
"$",
"cmp",
";",
"}",
"else",
"if",
"(",
"is_callable",
"(",
"$",
"sort",
")",
")",
"{",
"$",
"cmp",
"=",
"$",
"sort",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"}",
"return",
"$",
"cmp",
";",
"}",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"labelSort",
")",
")",
"{",
"$",
"sort",
"=",
"$",
"this",
"->",
"nameSort",
";",
"$",
"meta",
"=",
"$",
"this",
"->",
"meta",
";",
"uasort",
"(",
"$",
"columnsToSort",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"sort",
",",
"$",
"meta",
")",
"{",
"$",
"cmp",
"=",
"0",
";",
"$",
"a",
"=",
"isset",
"(",
"$",
"meta",
"[",
"$",
"a",
"]",
"[",
"'label'",
"]",
")",
"?",
"$",
"meta",
"[",
"$",
"a",
"]",
"[",
"'label'",
"]",
":",
"''",
";",
"$",
"b",
"=",
"isset",
"(",
"$",
"meta",
"[",
"$",
"b",
"]",
"[",
"'label'",
"]",
")",
"?",
"$",
"meta",
"[",
"$",
"a",
"]",
"[",
"'label'",
"]",
":",
"''",
";",
"if",
"(",
"is_string",
"(",
"$",
"sort",
")",
")",
"{",
"$",
"cmp",
"=",
"is_numeric",
"(",
"$",
"a",
")",
"&&",
"is_numeric",
"(",
"$",
"b",
")",
"?",
"$",
"a",
"-",
"$",
"b",
":",
"strcmp",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"$",
"cmp",
"=",
"$",
"sort",
"===",
"'asc'",
"?",
"$",
"cmp",
":",
"-",
"$",
"cmp",
";",
"}",
"else",
"if",
"(",
"is_callable",
"(",
"$",
"sort",
")",
")",
"{",
"$",
"cmp",
"=",
"$",
"sort",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"}",
"return",
"$",
"cmp",
";",
"}",
")",
";",
"}",
"$",
"sortedColumns",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fixedColumns",
"as",
"$",
"i",
"=>",
"$",
"pos",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"i",
")",
")",
"{",
"$",
"sortedColumns",
"[",
"$",
"pos",
"]",
"=",
"$",
"columns",
"[",
"$",
"i",
"]",
";",
"}",
"else",
"{",
"$",
"sortedColumns",
"[",
"$",
"pos",
"]",
"=",
"$",
"i",
";",
"}",
"}",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"columnsToSort",
"as",
"$",
"column",
")",
"{",
"while",
"(",
"isset",
"(",
"$",
"sortedColumns",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"i",
"++",
";",
"}",
"$",
"sortedColumns",
"[",
"$",
"i",
"]",
"=",
"$",
"column",
";",
"$",
"i",
"++",
";",
"}",
"ksort",
"(",
"$",
"sortedColumns",
")",
";",
"$",
"this",
"->",
"sortedColumns",
"=",
"$",
"sortedColumns",
";",
"}",
"$",
"newRow",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"sortedColumns",
"as",
"$",
"column",
")",
"{",
"$",
"newRow",
"[",
"$",
"column",
"]",
"=",
"$",
"row",
"[",
"$",
"column",
"]",
";",
"}",
"$",
"this",
"->",
"next",
"(",
"$",
"newRow",
")",
";",
"}"
] | 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/ColumnsSort.php#L76-L156 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.