id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
35,800 | goto-bus-stop/recanalyst | src/Model/Player.php | Player.startingAge | public function startingAge()
{
if (!is_null($this->rec)) {
return $this->rec->trans('ages', $this->initialState->startingAge);
}
return null;
} | php | public function startingAge()
{
if (!is_null($this->rec)) {
return $this->rec->trans('ages', $this->initialState->startingAge);
}
return null;
} | [
"public",
"function",
"startingAge",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"rec",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rec",
"->",
"trans",
"(",
"'ages'",
",",
"$",
"this",
"->",
"initialState",
"->",
"startingAge",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get the player's starting age.
@see \RecAnalyst\Model\InitialState::$startingAge
@return string Name of the starting age. | [
"Get",
"the",
"player",
"s",
"starting",
"age",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/Player.php#L326-L332 |
35,801 | goto-bus-stop/recanalyst | src/Analyzers/Analyzer.php | Analyzer.analyze | public function analyze(RecordedGame $game)
{
$this->rec = $game;
$this->header = $game->getHeaderContents();
$this->body = $game->getBodyContents();
$this->headerSize = strlen($this->header);
$this->bodySize = strlen($this->body);
return $this->run();
} | php | public function analyze(RecordedGame $game)
{
$this->rec = $game;
$this->header = $game->getHeaderContents();
$this->body = $game->getBodyContents();
$this->headerSize = strlen($this->header);
$this->bodySize = strlen($this->body);
return $this->run();
} | [
"public",
"function",
"analyze",
"(",
"RecordedGame",
"$",
"game",
")",
"{",
"$",
"this",
"->",
"rec",
"=",
"$",
"game",
";",
"$",
"this",
"->",
"header",
"=",
"$",
"game",
"->",
"getHeaderContents",
"(",
")",
";",
"$",
"this",
"->",
"body",
"=",
"$",
"game",
"->",
"getBodyContents",
"(",
")",
";",
"$",
"this",
"->",
"headerSize",
"=",
"strlen",
"(",
"$",
"this",
"->",
"header",
")",
";",
"$",
"this",
"->",
"bodySize",
"=",
"strlen",
"(",
"$",
"this",
"->",
"body",
")",
";",
"return",
"$",
"this",
"->",
"run",
"(",
")",
";",
"}"
] | Run this analysis on a recorded game.
@param \RecAnalyst\RecordedGame $game Recorded game to analyze.
@return mixed Result of the analysis. | [
"Run",
"this",
"analysis",
"on",
"a",
"recorded",
"game",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/Analyzer.php#L32-L41 |
35,802 | goto-bus-stop/recanalyst | src/Analyzers/Analyzer.php | Analyzer.get | protected function get($analyzer, $arg = null)
{
return $this->rec->getAnalysis($analyzer, $arg)->analysis;
} | php | protected function get($analyzer, $arg = null)
{
return $this->rec->getAnalysis($analyzer, $arg)->analysis;
} | [
"protected",
"function",
"get",
"(",
"$",
"analyzer",
",",
"$",
"arg",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"rec",
"->",
"getAnalysis",
"(",
"$",
"analyzer",
",",
"$",
"arg",
")",
"->",
"analysis",
";",
"}"
] | Get the result of another analyzer.
@param string $analyzer Analyzer class name.
@param mixed $arg Optional argument to the analyzer.
@return mixed Result of the analyzer. | [
"Get",
"the",
"result",
"of",
"another",
"analyzer",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/Analyzer.php#L50-L53 |
35,803 | goto-bus-stop/recanalyst | src/Analyzers/Analyzer.php | Analyzer.read | protected function read($analyzer, $arg = null)
{
$result = $this->rec->getAnalysis($analyzer, $arg, $this->position);
$this->position = $result->position;
return $result->analysis;
} | php | protected function read($analyzer, $arg = null)
{
$result = $this->rec->getAnalysis($analyzer, $arg, $this->position);
$this->position = $result->position;
return $result->analysis;
} | [
"protected",
"function",
"read",
"(",
"$",
"analyzer",
",",
"$",
"arg",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"rec",
"->",
"getAnalysis",
"(",
"$",
"analyzer",
",",
"$",
"arg",
",",
"$",
"this",
"->",
"position",
")",
";",
"$",
"this",
"->",
"position",
"=",
"$",
"result",
"->",
"position",
";",
"return",
"$",
"result",
"->",
"analysis",
";",
"}"
] | Compose another analyzer. Starts reading at the current position, and
uses the composed analyzer's final position as the new position.
@param string $analyzer Analyzer class name.
@param mixed $arg Optional argument to the analyzer.
@return mixed Result of the analyzer. | [
"Compose",
"another",
"analyzer",
".",
"Starts",
"reading",
"at",
"the",
"current",
"position",
"and",
"uses",
"the",
"composed",
"analyzer",
"s",
"final",
"position",
"as",
"the",
"new",
"position",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/Analyzer.php#L63-L68 |
35,804 | goto-bus-stop/recanalyst | src/Analyzers/Analyzer.php | Analyzer.readHeader | protected function readHeader($type, $size)
{
if ($this->position + $size > $this->headerSize) {
throw new \Exception('Can\'t read ' . $size . ' bytes');
}
$data = unpack($type, substr($this->header, $this->position, $size));
$this->position += $size;
return $data[1];
} | php | protected function readHeader($type, $size)
{
if ($this->position + $size > $this->headerSize) {
throw new \Exception('Can\'t read ' . $size . ' bytes');
}
$data = unpack($type, substr($this->header, $this->position, $size));
$this->position += $size;
return $data[1];
} | [
"protected",
"function",
"readHeader",
"(",
"$",
"type",
",",
"$",
"size",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"position",
"+",
"$",
"size",
">",
"$",
"this",
"->",
"headerSize",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Can\\'t read '",
".",
"$",
"size",
".",
"' bytes'",
")",
";",
"}",
"$",
"data",
"=",
"unpack",
"(",
"$",
"type",
",",
"substr",
"(",
"$",
"this",
"->",
"header",
",",
"$",
"this",
"->",
"position",
",",
"$",
"size",
")",
")",
";",
"$",
"this",
"->",
"position",
"+=",
"$",
"size",
";",
"return",
"$",
"data",
"[",
"1",
"]",
";",
"}"
] | Read and unpack data from the header of the recorded game file.
@see https://secure.php.net/pack For documentation on data unpack format.
@param string $type Data type.
@param int $size Size of the data.
@return mixed Result. | [
"Read",
"and",
"unpack",
"data",
"from",
"the",
"header",
"of",
"the",
"recorded",
"game",
"file",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/Analyzer.php#L78-L86 |
35,805 | goto-bus-stop/recanalyst | src/Analyzers/Analyzer.php | Analyzer.readHeaderRaw | protected function readHeaderRaw($size)
{
if ($this->position + $size > $this->headerSize) {
throw new \Exception('Can\'t read ' . $size . ' bytes');
}
$data = substr($this->header, $this->position, $size);
$this->position += $size;
return $data;
} | php | protected function readHeaderRaw($size)
{
if ($this->position + $size > $this->headerSize) {
throw new \Exception('Can\'t read ' . $size . ' bytes');
}
$data = substr($this->header, $this->position, $size);
$this->position += $size;
return $data;
} | [
"protected",
"function",
"readHeaderRaw",
"(",
"$",
"size",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"position",
"+",
"$",
"size",
">",
"$",
"this",
"->",
"headerSize",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Can\\'t read '",
".",
"$",
"size",
".",
"' bytes'",
")",
";",
"}",
"$",
"data",
"=",
"substr",
"(",
"$",
"this",
"->",
"header",
",",
"$",
"this",
"->",
"position",
",",
"$",
"size",
")",
";",
"$",
"this",
"->",
"position",
"+=",
"$",
"size",
";",
"return",
"$",
"data",
";",
"}"
] | Read raw strings from the header of the recorded game file.
@param int $size Amount of characters to read.
@return string Result. | [
"Read",
"raw",
"strings",
"from",
"the",
"header",
"of",
"the",
"recorded",
"game",
"file",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/Analyzer.php#L94-L102 |
35,806 | goto-bus-stop/recanalyst | src/Analyzers/Analyzer.php | Analyzer.readBody | protected function readBody($type, $size)
{
$data = unpack($type, substr($this->body, $this->position, $size));
$this->position += $size;
return $data[1];
} | php | protected function readBody($type, $size)
{
$data = unpack($type, substr($this->body, $this->position, $size));
$this->position += $size;
return $data[1];
} | [
"protected",
"function",
"readBody",
"(",
"$",
"type",
",",
"$",
"size",
")",
"{",
"$",
"data",
"=",
"unpack",
"(",
"$",
"type",
",",
"substr",
"(",
"$",
"this",
"->",
"body",
",",
"$",
"this",
"->",
"position",
",",
"$",
"size",
")",
")",
";",
"$",
"this",
"->",
"position",
"+=",
"$",
"size",
";",
"return",
"$",
"data",
"[",
"1",
"]",
";",
"}"
] | Read and unpack data from the body of the recorded game file.
@see https://secure.php.net/pack For documentation on data unpack format.
@param string $type Data type.
@param int $size Size of the data.
@return mixed Result. | [
"Read",
"and",
"unpack",
"data",
"from",
"the",
"body",
"of",
"the",
"recorded",
"game",
"file",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/Analyzer.php#L112-L117 |
35,807 | goto-bus-stop/recanalyst | src/Analyzers/Analyzer.php | Analyzer.readBodyRaw | protected function readBodyRaw($size)
{
$data = substr($this->body, $this->position, $size);
$this->position += $size;
return $data;
} | php | protected function readBodyRaw($size)
{
$data = substr($this->body, $this->position, $size);
$this->position += $size;
return $data;
} | [
"protected",
"function",
"readBodyRaw",
"(",
"$",
"size",
")",
"{",
"$",
"data",
"=",
"substr",
"(",
"$",
"this",
"->",
"body",
",",
"$",
"this",
"->",
"position",
",",
"$",
"size",
")",
";",
"$",
"this",
"->",
"position",
"+=",
"$",
"size",
";",
"return",
"$",
"data",
";",
"}"
] | Read raw strings from the body of the recorded game file.
@param int $size Amount of characters to read.
@return string Result. | [
"Read",
"raw",
"strings",
"from",
"the",
"body",
"of",
"the",
"recorded",
"game",
"file",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/Analyzer.php#L125-L130 |
35,808 | digiaonline/lumen-elasticsearch | src/ElasticsearchServiceProvider.php | ElasticsearchServiceProvider.registerBindings | protected function registerBindings()
{
/** @noinspection PhpUndefinedMethodInspection */
$config = $this->app['config']->get('elasticsearch', []);
$this->app->/** @scrutinizer ignore-call */ singleton(ElasticsearchServiceContract::class, function () use ($config) {
return new ElasticsearchService(ClientBuilder::fromConfig($config));
});
} | php | protected function registerBindings()
{
/** @noinspection PhpUndefinedMethodInspection */
$config = $this->app['config']->get('elasticsearch', []);
$this->app->/** @scrutinizer ignore-call */ singleton(ElasticsearchServiceContract::class, function () use ($config) {
return new ElasticsearchService(ClientBuilder::fromConfig($config));
});
} | [
"protected",
"function",
"registerBindings",
"(",
")",
"{",
"/** @noinspection PhpUndefinedMethodInspection */",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'elasticsearch'",
",",
"[",
"]",
")",
";",
"$",
"this",
"->",
"app",
"->",
"/** @scrutinizer ignore-call */",
"singleton",
"(",
"ElasticsearchServiceContract",
"::",
"class",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"return",
"new",
"ElasticsearchService",
"(",
"ClientBuilder",
"::",
"fromConfig",
"(",
"$",
"config",
")",
")",
";",
"}",
")",
";",
"}"
] | Register bindings. | [
"Register",
"bindings",
"."
] | 45a2729afe131842b6ff70a8415aa829068075bd | https://github.com/digiaonline/lumen-elasticsearch/blob/45a2729afe131842b6ff70a8415aa829068075bd/src/ElasticsearchServiceProvider.php#L27-L35 |
35,809 | digiaonline/lumen-elasticsearch | src/Pipelines/Stages/ReIndexStage.php | ReIndexStage.renderProgressBar | protected function renderProgressBar(array $task): void
{
// Use a progress bar to indicate how far a long the re-indexing has come
$progressBar = null;
do {
$response = ['completed' => false];
// Ignore ServerErrorResponseException, re-indexing can make these requests time out
try {
$response = $this->elasticsearchService->tasks()->get([
'task_id' => $task['task'],
]);
$total = $response['task']['status']['total'];
// Initialize the progress bar once Elasticsearch knows the total amount of items
if ($progressBar === null && $total > 0) {
$progressBar = new ProgressBar(new ConsoleOutput(), $total);
} elseif ($progressBar !== null) {
$progressBar->setProgress($response['task']['status']['created']);
}
} catch (ServerErrorResponseException $e) {
}
sleep(1);
} while ((bool)$response['completed'] === false);
// For very short migrations we may never get a progress bar, because the task finishes too quickly
if ($progressBar !== null) {
$progressBar->finish();
}
echo PHP_EOL;
} | php | protected function renderProgressBar(array $task): void
{
// Use a progress bar to indicate how far a long the re-indexing has come
$progressBar = null;
do {
$response = ['completed' => false];
// Ignore ServerErrorResponseException, re-indexing can make these requests time out
try {
$response = $this->elasticsearchService->tasks()->get([
'task_id' => $task['task'],
]);
$total = $response['task']['status']['total'];
// Initialize the progress bar once Elasticsearch knows the total amount of items
if ($progressBar === null && $total > 0) {
$progressBar = new ProgressBar(new ConsoleOutput(), $total);
} elseif ($progressBar !== null) {
$progressBar->setProgress($response['task']['status']['created']);
}
} catch (ServerErrorResponseException $e) {
}
sleep(1);
} while ((bool)$response['completed'] === false);
// For very short migrations we may never get a progress bar, because the task finishes too quickly
if ($progressBar !== null) {
$progressBar->finish();
}
echo PHP_EOL;
} | [
"protected",
"function",
"renderProgressBar",
"(",
"array",
"$",
"task",
")",
":",
"void",
"{",
"// Use a progress bar to indicate how far a long the re-indexing has come",
"$",
"progressBar",
"=",
"null",
";",
"do",
"{",
"$",
"response",
"=",
"[",
"'completed'",
"=>",
"false",
"]",
";",
"// Ignore ServerErrorResponseException, re-indexing can make these requests time out",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"elasticsearchService",
"->",
"tasks",
"(",
")",
"->",
"get",
"(",
"[",
"'task_id'",
"=>",
"$",
"task",
"[",
"'task'",
"]",
",",
"]",
")",
";",
"$",
"total",
"=",
"$",
"response",
"[",
"'task'",
"]",
"[",
"'status'",
"]",
"[",
"'total'",
"]",
";",
"// Initialize the progress bar once Elasticsearch knows the total amount of items",
"if",
"(",
"$",
"progressBar",
"===",
"null",
"&&",
"$",
"total",
">",
"0",
")",
"{",
"$",
"progressBar",
"=",
"new",
"ProgressBar",
"(",
"new",
"ConsoleOutput",
"(",
")",
",",
"$",
"total",
")",
";",
"}",
"elseif",
"(",
"$",
"progressBar",
"!==",
"null",
")",
"{",
"$",
"progressBar",
"->",
"setProgress",
"(",
"$",
"response",
"[",
"'task'",
"]",
"[",
"'status'",
"]",
"[",
"'created'",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"ServerErrorResponseException",
"$",
"e",
")",
"{",
"}",
"sleep",
"(",
"1",
")",
";",
"}",
"while",
"(",
"(",
"bool",
")",
"$",
"response",
"[",
"'completed'",
"]",
"===",
"false",
")",
";",
"// For very short migrations we may never get a progress bar, because the task finishes too quickly",
"if",
"(",
"$",
"progressBar",
"!==",
"null",
")",
"{",
"$",
"progressBar",
"->",
"finish",
"(",
")",
";",
"}",
"echo",
"PHP_EOL",
";",
"}"
] | Renders a progress bar until the specified re-indexing task is completed
@param array $task | [
"Renders",
"a",
"progress",
"bar",
"until",
"the",
"specified",
"re",
"-",
"indexing",
"task",
"is",
"completed"
] | 45a2729afe131842b6ff70a8415aa829068075bd | https://github.com/digiaonline/lumen-elasticsearch/blob/45a2729afe131842b6ff70a8415aa829068075bd/src/Pipelines/Stages/ReIndexStage.php#L74-L108 |
35,810 | inouet/file-cache | src/FileCache.php | FileCache.getDirectory | protected function getDirectory($id)
{
$hash = sha1($id, false);
$dirs = array(
$this->getCacheDirectory(),
substr($hash, 0, 2),
substr($hash, 2, 2)
);
return join(DIRECTORY_SEPARATOR, $dirs);
} | php | protected function getDirectory($id)
{
$hash = sha1($id, false);
$dirs = array(
$this->getCacheDirectory(),
substr($hash, 0, 2),
substr($hash, 2, 2)
);
return join(DIRECTORY_SEPARATOR, $dirs);
} | [
"protected",
"function",
"getDirectory",
"(",
"$",
"id",
")",
"{",
"$",
"hash",
"=",
"sha1",
"(",
"$",
"id",
",",
"false",
")",
";",
"$",
"dirs",
"=",
"array",
"(",
"$",
"this",
"->",
"getCacheDirectory",
"(",
")",
",",
"substr",
"(",
"$",
"hash",
",",
"0",
",",
"2",
")",
",",
"substr",
"(",
"$",
"hash",
",",
"2",
",",
"2",
")",
")",
";",
"return",
"join",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"dirs",
")",
";",
"}"
] | Fetches a directory to store the cache data
@param string $id
@return string | [
"Fetches",
"a",
"directory",
"to",
"store",
"the",
"cache",
"data"
] | cb11041657925c95c358ca0bf70bd401a671efa3 | https://github.com/inouet/file-cache/blob/cb11041657925c95c358ca0bf70bd401a671efa3/src/FileCache.php#L117-L126 |
35,811 | inouet/file-cache | src/FileCache.php | FileCache.getFileName | protected function getFileName($id)
{
$directory = $this->getDirectory($id);
$hash = sha1($id, false);
$file = $directory . DIRECTORY_SEPARATOR . $hash . '.cache';
return $file;
} | php | protected function getFileName($id)
{
$directory = $this->getDirectory($id);
$hash = sha1($id, false);
$file = $directory . DIRECTORY_SEPARATOR . $hash . '.cache';
return $file;
} | [
"protected",
"function",
"getFileName",
"(",
"$",
"id",
")",
"{",
"$",
"directory",
"=",
"$",
"this",
"->",
"getDirectory",
"(",
"$",
"id",
")",
";",
"$",
"hash",
"=",
"sha1",
"(",
"$",
"id",
",",
"false",
")",
";",
"$",
"file",
"=",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"hash",
".",
"'.cache'",
";",
"return",
"$",
"file",
";",
"}"
] | Fetches a file path of the cache data
@param string $id
@return string | [
"Fetches",
"a",
"file",
"path",
"of",
"the",
"cache",
"data"
] | cb11041657925c95c358ca0bf70bd401a671efa3 | https://github.com/inouet/file-cache/blob/cb11041657925c95c358ca0bf70bd401a671efa3/src/FileCache.php#L145-L151 |
35,812 | denissimon/prediction-builder | src/PredictionBuilder.php | readData.readFromArray | public function readFromArray(array $data) {
$callback =
function ($v) {
if ((!isset($v[0])) || (!isset($v[1]))) {
throw new \InvalidArgumentException('Mismatch in the number of x and y in the dataset.');
} else {
$this->xVector[] = $v[0];
$this->yVector[] = $v[1];
}
};
array_walk($data, $callback);
} | php | public function readFromArray(array $data) {
$callback =
function ($v) {
if ((!isset($v[0])) || (!isset($v[1]))) {
throw new \InvalidArgumentException('Mismatch in the number of x and y in the dataset.');
} else {
$this->xVector[] = $v[0];
$this->yVector[] = $v[1];
}
};
array_walk($data, $callback);
} | [
"public",
"function",
"readFromArray",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"callback",
"=",
"function",
"(",
"$",
"v",
")",
"{",
"if",
"(",
"(",
"!",
"isset",
"(",
"$",
"v",
"[",
"0",
"]",
")",
")",
"||",
"(",
"!",
"isset",
"(",
"$",
"v",
"[",
"1",
"]",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Mismatch in the number of x and y in the dataset.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"xVector",
"[",
"]",
"=",
"$",
"v",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"yVector",
"[",
"]",
"=",
"$",
"v",
"[",
"1",
"]",
";",
"}",
"}",
";",
"array_walk",
"(",
"$",
"data",
",",
"$",
"callback",
")",
";",
"}"
] | Reads the data from a given array
@param array $data
@throws \InvalidArgumentException | [
"Reads",
"the",
"data",
"from",
"a",
"given",
"array"
] | fe02c342ec59861c49d075836f351250fb7163a7 | https://github.com/denissimon/prediction-builder/blob/fe02c342ec59861c49d075836f351250fb7163a7/src/PredictionBuilder.php#L21-L32 |
35,813 | denissimon/prediction-builder | src/PredictionBuilder.php | PredictionBuilder.sumSquared | private function sumSquared(array $vector) {
return array_reduce(
$vector,
function($v, $w) { return $v += $this->square($w); }
);
} | php | private function sumSquared(array $vector) {
return array_reduce(
$vector,
function($v, $w) { return $v += $this->square($w); }
);
} | [
"private",
"function",
"sumSquared",
"(",
"array",
"$",
"vector",
")",
"{",
"return",
"array_reduce",
"(",
"$",
"vector",
",",
"function",
"(",
"$",
"v",
",",
"$",
"w",
")",
"{",
"return",
"$",
"v",
"+=",
"$",
"this",
"->",
"square",
"(",
"$",
"w",
")",
";",
"}",
")",
";",
"}"
] | Sum of the vector squared values
@param array $vector
@return number | [
"Sum",
"of",
"the",
"vector",
"squared",
"values"
] | fe02c342ec59861c49d075836f351250fb7163a7 | https://github.com/denissimon/prediction-builder/blob/fe02c342ec59861c49d075836f351250fb7163a7/src/PredictionBuilder.php#L103-L108 |
35,814 | denissimon/prediction-builder | src/PredictionBuilder.php | PredictionBuilder.build | public function build() {
// Check the number of observations in a given dataset
if ($this->count < 3) {
throw new \InvalidArgumentException('The dataset should contain a minimum of 3 observations.');
}
$b = $this->round_($this->bSlope());
$a = $this->round_($this->aIntercept($b));
$model = $this->createModel($a, $b);
$y = $this->round_($model($this->x));
$result = new \stdClass();
$result->ln_model = (string) ($a.'+'.$b.'x');
$result->cor = $this->round_($this->corCoefficient($b));
$result->x = $this->x;
$result->y = $y;
return $result;
} | php | public function build() {
// Check the number of observations in a given dataset
if ($this->count < 3) {
throw new \InvalidArgumentException('The dataset should contain a minimum of 3 observations.');
}
$b = $this->round_($this->bSlope());
$a = $this->round_($this->aIntercept($b));
$model = $this->createModel($a, $b);
$y = $this->round_($model($this->x));
$result = new \stdClass();
$result->ln_model = (string) ($a.'+'.$b.'x');
$result->cor = $this->round_($this->corCoefficient($b));
$result->x = $this->x;
$result->y = $y;
return $result;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"// Check the number of observations in a given dataset",
"if",
"(",
"$",
"this",
"->",
"count",
"<",
"3",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The dataset should contain a minimum of 3 observations.'",
")",
";",
"}",
"$",
"b",
"=",
"$",
"this",
"->",
"round_",
"(",
"$",
"this",
"->",
"bSlope",
"(",
")",
")",
";",
"$",
"a",
"=",
"$",
"this",
"->",
"round_",
"(",
"$",
"this",
"->",
"aIntercept",
"(",
"$",
"b",
")",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"$",
"y",
"=",
"$",
"this",
"->",
"round_",
"(",
"$",
"model",
"(",
"$",
"this",
"->",
"x",
")",
")",
";",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"ln_model",
"=",
"(",
"string",
")",
"(",
"$",
"a",
".",
"'+'",
".",
"$",
"b",
".",
"'x'",
")",
";",
"$",
"result",
"->",
"cor",
"=",
"$",
"this",
"->",
"round_",
"(",
"$",
"this",
"->",
"corCoefficient",
"(",
"$",
"b",
")",
")",
";",
"$",
"result",
"->",
"x",
"=",
"$",
"this",
"->",
"x",
";",
"$",
"result",
"->",
"y",
"=",
"$",
"y",
";",
"return",
"$",
"result",
";",
"}"
] | Builds a prediction of the expected value of y for a given x, based on a linear regression model.
@return \stdClass
@throws \InvalidArgumentException | [
"Builds",
"a",
"prediction",
"of",
"the",
"expected",
"value",
"of",
"y",
"for",
"a",
"given",
"x",
"based",
"on",
"a",
"linear",
"regression",
"model",
"."
] | fe02c342ec59861c49d075836f351250fb7163a7 | https://github.com/denissimon/prediction-builder/blob/fe02c342ec59861c49d075836f351250fb7163a7/src/PredictionBuilder.php#L206-L224 |
35,815 | davestewart/laravel-sketchpad | src/help/docs/HelpersController.php | HelpersController.code | public function code($arguments = 'php')
{
$params =
[
'php' => [
'desc' => 'raw PHP',
'func' => 'output',
'args' => ['$a + $b === 100 ? true : false']
],
'js' => [
'desc' => 'raw JavaScript',
'func' => 'output',
'args' => ['a + b === 100 ? true : false', 'javascript']
],
'file' => [
'desc' => 'this file',
'func' => 'file',
'args' => [__FILE__]
],
'section' => [
'desc' => 'lines 17 - 44 of this file',
'func' => 'section',
'args' => [__FILE__, 18, 45]
],
'sectionu' => [
'desc' => 'lines 17 - 44 of this file (without indent)',
'func' => 'section',
'args' => [__FILE__, 18, 45, true]
],
'class' => [
'desc' => 'this class',
'func' => 'classfile',
'args' => [__CLASS__]
],
'classc' => [
'desc' => 'this class (with doc-comment)',
'func' => 'classfile',
'args' => [__CLASS__, true]
],
'method' => [
'desc' => 'this method',
'func' => 'method',
'args' => [__CLASS__, 'code']
],
'methodc' => [
'desc' => 'this method (with doc-comment)',
'func' => 'method',
'args' => [__CLASS__, 'code', true]
],
];
$data = $params[$arguments];
$data['signature'] = Code::signature($data['args']);
return view('sketchpad::help/helpers/code', $data);
} | php | public function code($arguments = 'php')
{
$params =
[
'php' => [
'desc' => 'raw PHP',
'func' => 'output',
'args' => ['$a + $b === 100 ? true : false']
],
'js' => [
'desc' => 'raw JavaScript',
'func' => 'output',
'args' => ['a + b === 100 ? true : false', 'javascript']
],
'file' => [
'desc' => 'this file',
'func' => 'file',
'args' => [__FILE__]
],
'section' => [
'desc' => 'lines 17 - 44 of this file',
'func' => 'section',
'args' => [__FILE__, 18, 45]
],
'sectionu' => [
'desc' => 'lines 17 - 44 of this file (without indent)',
'func' => 'section',
'args' => [__FILE__, 18, 45, true]
],
'class' => [
'desc' => 'this class',
'func' => 'classfile',
'args' => [__CLASS__]
],
'classc' => [
'desc' => 'this class (with doc-comment)',
'func' => 'classfile',
'args' => [__CLASS__, true]
],
'method' => [
'desc' => 'this method',
'func' => 'method',
'args' => [__CLASS__, 'code']
],
'methodc' => [
'desc' => 'this method (with doc-comment)',
'func' => 'method',
'args' => [__CLASS__, 'code', true]
],
];
$data = $params[$arguments];
$data['signature'] = Code::signature($data['args']);
return view('sketchpad::help/helpers/code', $data);
} | [
"public",
"function",
"code",
"(",
"$",
"arguments",
"=",
"'php'",
")",
"{",
"$",
"params",
"=",
"[",
"'php'",
"=>",
"[",
"'desc'",
"=>",
"'raw PHP'",
",",
"'func'",
"=>",
"'output'",
",",
"'args'",
"=>",
"[",
"'$a + $b === 100 ? true : false'",
"]",
"]",
",",
"'js'",
"=>",
"[",
"'desc'",
"=>",
"'raw JavaScript'",
",",
"'func'",
"=>",
"'output'",
",",
"'args'",
"=>",
"[",
"'a + b === 100 ? true : false'",
",",
"'javascript'",
"]",
"]",
",",
"'file'",
"=>",
"[",
"'desc'",
"=>",
"'this file'",
",",
"'func'",
"=>",
"'file'",
",",
"'args'",
"=>",
"[",
"__FILE__",
"]",
"]",
",",
"'section'",
"=>",
"[",
"'desc'",
"=>",
"'lines 17 - 44 of this file'",
",",
"'func'",
"=>",
"'section'",
",",
"'args'",
"=>",
"[",
"__FILE__",
",",
"18",
",",
"45",
"]",
"]",
",",
"'sectionu'",
"=>",
"[",
"'desc'",
"=>",
"'lines 17 - 44 of this file (without indent)'",
",",
"'func'",
"=>",
"'section'",
",",
"'args'",
"=>",
"[",
"__FILE__",
",",
"18",
",",
"45",
",",
"true",
"]",
"]",
",",
"'class'",
"=>",
"[",
"'desc'",
"=>",
"'this class'",
",",
"'func'",
"=>",
"'classfile'",
",",
"'args'",
"=>",
"[",
"__CLASS__",
"]",
"]",
",",
"'classc'",
"=>",
"[",
"'desc'",
"=>",
"'this class (with doc-comment)'",
",",
"'func'",
"=>",
"'classfile'",
",",
"'args'",
"=>",
"[",
"__CLASS__",
",",
"true",
"]",
"]",
",",
"'method'",
"=>",
"[",
"'desc'",
"=>",
"'this method'",
",",
"'func'",
"=>",
"'method'",
",",
"'args'",
"=>",
"[",
"__CLASS__",
",",
"'code'",
"]",
"]",
",",
"'methodc'",
"=>",
"[",
"'desc'",
"=>",
"'this method (with doc-comment)'",
",",
"'func'",
"=>",
"'method'",
",",
"'args'",
"=>",
"[",
"__CLASS__",
",",
"'code'",
",",
"true",
"]",
"]",
",",
"]",
";",
"$",
"data",
"=",
"$",
"params",
"[",
"$",
"arguments",
"]",
";",
"$",
"data",
"[",
"'signature'",
"]",
"=",
"Code",
"::",
"signature",
"(",
"$",
"data",
"[",
"'args'",
"]",
")",
";",
"return",
"view",
"(",
"'sketchpad::help/helpers/code'",
",",
"$",
"data",
")",
";",
"}"
] | Output code with formatting and html entities converted
@field select $arguments options:Raw PHP=php,Raw JavaScript=js,File=file,Section=section,Section (without indent)=sectionu,Class=class,Class (with doc-comment)=classc,Method=method,Method (with doc-comment)=methodc | [
"Output",
"code",
"with",
"formatting",
"and",
"html",
"entities",
"converted"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/docs/HelpersController.php#L65-L118 |
35,816 | davestewart/laravel-sketchpad | src/help/docs/HelpersController.php | HelpersController.icon | public function icon()
{
$input = [
[icon('plane'), "icon('plane');", ],
[icon('bolt'), "icon('bolt');", ],
[icon('bolt', '#FF00FF'), "icon('bolt', '#FF00FF');", ],
[icon('info', 'info'), "icon('info', 'info');", ],
[icon(true), "icon(true);", ],
[icon(false), "icon(false);", ],
];
$data = array_reduce($input, function ($output, $arr)
{
$output[] = (object) ['code' => $arr[1], 'icon' => $arr[0]];
return $output;
}, []);
return view('sketchpad::help/helpers/icon', compact('data'));
} | php | public function icon()
{
$input = [
[icon('plane'), "icon('plane');", ],
[icon('bolt'), "icon('bolt');", ],
[icon('bolt', '#FF00FF'), "icon('bolt', '#FF00FF');", ],
[icon('info', 'info'), "icon('info', 'info');", ],
[icon(true), "icon(true);", ],
[icon(false), "icon(false);", ],
];
$data = array_reduce($input, function ($output, $arr)
{
$output[] = (object) ['code' => $arr[1], 'icon' => $arr[0]];
return $output;
}, []);
return view('sketchpad::help/helpers/icon', compact('data'));
} | [
"public",
"function",
"icon",
"(",
")",
"{",
"$",
"input",
"=",
"[",
"[",
"icon",
"(",
"'plane'",
")",
",",
"\"icon('plane');\"",
",",
"]",
",",
"[",
"icon",
"(",
"'bolt'",
")",
",",
"\"icon('bolt');\"",
",",
"]",
",",
"[",
"icon",
"(",
"'bolt'",
",",
"'#FF00FF'",
")",
",",
"\"icon('bolt', '#FF00FF');\"",
",",
"]",
",",
"[",
"icon",
"(",
"'info'",
",",
"'info'",
")",
",",
"\"icon('info', 'info');\"",
",",
"]",
",",
"[",
"icon",
"(",
"true",
")",
",",
"\"icon(true);\"",
",",
"]",
",",
"[",
"icon",
"(",
"false",
")",
",",
"\"icon(false);\"",
",",
"]",
",",
"]",
";",
"$",
"data",
"=",
"array_reduce",
"(",
"$",
"input",
",",
"function",
"(",
"$",
"output",
",",
"$",
"arr",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'code'",
"=>",
"$",
"arr",
"[",
"1",
"]",
",",
"'icon'",
"=>",
"$",
"arr",
"[",
"0",
"]",
"]",
";",
"return",
"$",
"output",
";",
"}",
",",
"[",
"]",
")",
";",
"return",
"view",
"(",
"'sketchpad::help/helpers/icon'",
",",
"compact",
"(",
"'data'",
")",
")",
";",
"}"
] | Create a Font Awesome icon simply and easily | [
"Create",
"a",
"Font",
"Awesome",
"icon",
"simply",
"and",
"easily"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/docs/HelpersController.php#L149-L165 |
35,817 | davestewart/laravel-sketchpad | src/controllers/ApiController.php | ApiController.run | public function run(Request $request, $path = '')
{
// data
$data = $request->get('_data', []);
if (is_string($data))
{
$data = json_decode($data, JSON_OBJECT_AS_ARRAY);
}
// form
$form = $request->get('_form', null);
parse_str($form, $form);
// run
return $this->sketchpad->run($path, $data, $form);
} | php | public function run(Request $request, $path = '')
{
// data
$data = $request->get('_data', []);
if (is_string($data))
{
$data = json_decode($data, JSON_OBJECT_AS_ARRAY);
}
// form
$form = $request->get('_form', null);
parse_str($form, $form);
// run
return $this->sketchpad->run($path, $data, $form);
} | [
"public",
"function",
"run",
"(",
"Request",
"$",
"request",
",",
"$",
"path",
"=",
"''",
")",
"{",
"// data",
"$",
"data",
"=",
"$",
"request",
"->",
"get",
"(",
"'_data'",
",",
"[",
"]",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"JSON_OBJECT_AS_ARRAY",
")",
";",
"}",
"// form",
"$",
"form",
"=",
"$",
"request",
"->",
"get",
"(",
"'_form'",
",",
"null",
")",
";",
"parse_str",
"(",
"$",
"form",
",",
"$",
"form",
")",
";",
"// run",
"return",
"$",
"this",
"->",
"sketchpad",
"->",
"run",
"(",
"$",
"path",
",",
"$",
"data",
",",
"$",
"form",
")",
";",
"}"
] | Run a controller method
@param Request $request
@param string $path
@return \Illuminate\View\View|mixed|string | [
"Run",
"a",
"controller",
"method"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/controllers/ApiController.php#L54-L69 |
35,818 | davestewart/laravel-sketchpad | src/controllers/ApiController.php | ApiController.settings | public function settings(Request $request, SketchpadConfig $config)
{
if (!$config->admin->settings)
{
return response()->json($config->settings);
}
function textToArray ($text)
{
return array_values(array_filter(array_map('trim', explode("\n", trim($text))), 'strlen'));
}
if($request->isMethod('post'))
{
// convert data
$data = json_decode($request->get('settings'));
// trim values
$data->livereload->paths = textToArray($data->livereload->paths);
// save
$config->settings->save((array) $data);
}
return response()->json($config->settings);
} | php | public function settings(Request $request, SketchpadConfig $config)
{
if (!$config->admin->settings)
{
return response()->json($config->settings);
}
function textToArray ($text)
{
return array_values(array_filter(array_map('trim', explode("\n", trim($text))), 'strlen'));
}
if($request->isMethod('post'))
{
// convert data
$data = json_decode($request->get('settings'));
// trim values
$data->livereload->paths = textToArray($data->livereload->paths);
// save
$config->settings->save((array) $data);
}
return response()->json($config->settings);
} | [
"public",
"function",
"settings",
"(",
"Request",
"$",
"request",
",",
"SketchpadConfig",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"$",
"config",
"->",
"admin",
"->",
"settings",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"config",
"->",
"settings",
")",
";",
"}",
"function",
"textToArray",
"(",
"$",
"text",
")",
"{",
"return",
"array_values",
"(",
"array_filter",
"(",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"\"\\n\"",
",",
"trim",
"(",
"$",
"text",
")",
")",
")",
",",
"'strlen'",
")",
")",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"isMethod",
"(",
"'post'",
")",
")",
"{",
"// convert data",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"request",
"->",
"get",
"(",
"'settings'",
")",
")",
";",
"// trim values",
"$",
"data",
"->",
"livereload",
"->",
"paths",
"=",
"textToArray",
"(",
"$",
"data",
"->",
"livereload",
"->",
"paths",
")",
";",
"// save",
"$",
"config",
"->",
"settings",
"->",
"save",
"(",
"(",
"array",
")",
"$",
"data",
")",
";",
"}",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"config",
"->",
"settings",
")",
";",
"}"
] | Loads or saves settings data
@method POST
@method GET
@param Request $request
@param SketchpadConfig $config
@return SketchpadSettings | [
"Loads",
"or",
"saves",
"settings",
"data"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/controllers/ApiController.php#L104-L128 |
35,819 | davestewart/laravel-sketchpad | src/controllers/ApiController.php | ApiController.path | public function path(Request $request)
{
$relpath = $request->get('path');
$abspath = base_path($relpath);
return [
'relpath' => $relpath,
'abspath' => $abspath,
'exists' => file_exists($abspath)
];
} | php | public function path(Request $request)
{
$relpath = $request->get('path');
$abspath = base_path($relpath);
return [
'relpath' => $relpath,
'abspath' => $abspath,
'exists' => file_exists($abspath)
];
} | [
"public",
"function",
"path",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"relpath",
"=",
"$",
"request",
"->",
"get",
"(",
"'path'",
")",
";",
"$",
"abspath",
"=",
"base_path",
"(",
"$",
"relpath",
")",
";",
"return",
"[",
"'relpath'",
"=>",
"$",
"relpath",
",",
"'abspath'",
"=>",
"$",
"abspath",
",",
"'exists'",
"=>",
"file_exists",
"(",
"$",
"abspath",
")",
"]",
";",
"}"
] | Validates existence of a path
@method GET
@param Request $request
@return array | [
"Validates",
"existence",
"of",
"a",
"path"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/controllers/ApiController.php#L137-L146 |
35,820 | esbenp/onion | src/Onion.php | Onion.peel | public function peel($object, Closure $core)
{
$coreFunction = $this->createCoreFunction($core);
// Since we will be "currying" the functions starting with the first
// in the array, the first function will be "closer" to the core.
// This also means it will be run last. However, if the reverse the
// order of the array, the first in the list will be the outer layers.
$layers = array_reverse($this->layers);
// We create the onion by starting initially with the core and then
// gradually wrap it in layers. Each layer will have the next layer "curried"
// into it and will have the current state (the object) passed to it.
$completeOnion = array_reduce($layers, function($nextLayer, $layer){
return $this->createLayer($nextLayer, $layer);
}, $coreFunction);
// We now have the complete onion and can start passing the object
// down through the layers.
return $completeOnion($object);
} | php | public function peel($object, Closure $core)
{
$coreFunction = $this->createCoreFunction($core);
// Since we will be "currying" the functions starting with the first
// in the array, the first function will be "closer" to the core.
// This also means it will be run last. However, if the reverse the
// order of the array, the first in the list will be the outer layers.
$layers = array_reverse($this->layers);
// We create the onion by starting initially with the core and then
// gradually wrap it in layers. Each layer will have the next layer "curried"
// into it and will have the current state (the object) passed to it.
$completeOnion = array_reduce($layers, function($nextLayer, $layer){
return $this->createLayer($nextLayer, $layer);
}, $coreFunction);
// We now have the complete onion and can start passing the object
// down through the layers.
return $completeOnion($object);
} | [
"public",
"function",
"peel",
"(",
"$",
"object",
",",
"Closure",
"$",
"core",
")",
"{",
"$",
"coreFunction",
"=",
"$",
"this",
"->",
"createCoreFunction",
"(",
"$",
"core",
")",
";",
"// Since we will be \"currying\" the functions starting with the first",
"// in the array, the first function will be \"closer\" to the core.",
"// This also means it will be run last. However, if the reverse the",
"// order of the array, the first in the list will be the outer layers.",
"$",
"layers",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"layers",
")",
";",
"// We create the onion by starting initially with the core and then",
"// gradually wrap it in layers. Each layer will have the next layer \"curried\"",
"// into it and will have the current state (the object) passed to it.",
"$",
"completeOnion",
"=",
"array_reduce",
"(",
"$",
"layers",
",",
"function",
"(",
"$",
"nextLayer",
",",
"$",
"layer",
")",
"{",
"return",
"$",
"this",
"->",
"createLayer",
"(",
"$",
"nextLayer",
",",
"$",
"layer",
")",
";",
"}",
",",
"$",
"coreFunction",
")",
";",
"// We now have the complete onion and can start passing the object",
"// down through the layers.",
"return",
"$",
"completeOnion",
"(",
"$",
"object",
")",
";",
"}"
] | Run middleware around core function and pass an
object through it
@param mixed $object
@param Closure $core
@return mixed | [
"Run",
"middleware",
"around",
"core",
"function",
"and",
"pass",
"an",
"object",
"through",
"it"
] | 71014ae0727c289213f54c867933665342345d91 | https://github.com/esbenp/onion/blob/71014ae0727c289213f54c867933665342345d91/src/Onion.php#L47-L67 |
35,821 | esbenp/onion | src/Onion.php | Onion.createLayer | private function createLayer($nextLayer, $layer)
{
return function($object) use($nextLayer, $layer){
return $layer->peel($object, $nextLayer);
};
} | php | private function createLayer($nextLayer, $layer)
{
return function($object) use($nextLayer, $layer){
return $layer->peel($object, $nextLayer);
};
} | [
"private",
"function",
"createLayer",
"(",
"$",
"nextLayer",
",",
"$",
"layer",
")",
"{",
"return",
"function",
"(",
"$",
"object",
")",
"use",
"(",
"$",
"nextLayer",
",",
"$",
"layer",
")",
"{",
"return",
"$",
"layer",
"->",
"peel",
"(",
"$",
"object",
",",
"$",
"nextLayer",
")",
";",
"}",
";",
"}"
] | Get an onion layer function.
This function will get the object from a previous layer and pass it inwards
@param LayerInterface $nextLayer
@param LayerInterface $layer
@return Closure | [
"Get",
"an",
"onion",
"layer",
"function",
".",
"This",
"function",
"will",
"get",
"the",
"object",
"from",
"a",
"previous",
"layer",
"and",
"pass",
"it",
"inwards"
] | 71014ae0727c289213f54c867933665342345d91 | https://github.com/esbenp/onion/blob/71014ae0727c289213f54c867933665342345d91/src/Onion.php#L98-L103 |
35,822 | davestewart/laravel-sketchpad | src/services/Sketchpad.php | Sketchpad.getController | public function getController($route = null)
{
$router = $this->init($route == null)->router;
return $route
? $router->getController($route)
: $router->getControllers();
} | php | public function getController($route = null)
{
$router = $this->init($route == null)->router;
return $route
? $router->getController($route)
: $router->getControllers();
} | [
"public",
"function",
"getController",
"(",
"$",
"route",
"=",
"null",
")",
"{",
"$",
"router",
"=",
"$",
"this",
"->",
"init",
"(",
"$",
"route",
"==",
"null",
")",
"->",
"router",
";",
"return",
"$",
"route",
"?",
"$",
"router",
"->",
"getController",
"(",
"$",
"route",
")",
":",
"$",
"router",
"->",
"getControllers",
"(",
")",
";",
"}"
] | Returns a sketchpad\objects\reflection\Controller that can be converted to JSON
@param string $route The relative route to the controller
@return Controller The Controller | [
"Returns",
"a",
"sketchpad",
"\\",
"objects",
"\\",
"reflection",
"\\",
"Controller",
"that",
"can",
"be",
"converted",
"to",
"JSON"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/services/Sketchpad.php#L99-L105 |
35,823 | davestewart/laravel-sketchpad | src/services/Sketchpad.php | Sketchpad.run | public function run($route = '', array $params, array $form = null)
{
// set up the router, but don't scan
$this->init();
/** @var CallReference $ref */
$ref = $this->router->getCall($route, $params);
//vd([$ref, $route, $params]);
//exit;
// controller has method
if($ref instanceof CallReference)
{
// test controller / method exists
try
{
new ReflectionMethod($ref->class, $ref->method);
}
catch(\Exception $e)
{
if($e instanceof \ReflectionException)
{
//$sketchpad = str_replace($this->config->route, '', $ref->route) . $ref->method . '/';
$this->abort($ref->route . '::' . $ref->method . '()', 'method');
}
}
// assign static properties
Sketchpad::$route = $ref->route . '/' . $ref->method . '/';
Sketchpad::$params = $ref->params;
Sketchpad::$form = empty($form) ? null : $form;
// get controller response or content
ob_start();
$response = $this->exec($ref->class, $ref->method, $ref->params);
$content = ob_get_contents();
ob_end_clean();
// handle echoed output
if ($content)
{
return $content;
}
// handle laravel view responses
if ($response instanceof \Illuminate\Contracts\View\View)
{
return $response;
}
// handle laravel json responses
if ($response instanceof \Illuminate\Http\JsonResponse)
{
return json($response->getData());
}
// handle Arrrayable
if ($response instanceof \Illuminate\Contracts\Support\Arrayable)
{
return json($response->toArray());
}
// handle Jsonable
if ($response instanceof \Illuminate\Contracts\Support\Jsonable)
{
return json(json_decode($response->toJson()));
}
// anything else send as JSON (classes, objects, arrays, numbers, strings, booleans)
return json($response);
}
// if there's not a valid controller or method, it's a 404
$this->abort($route, 'path');
return false;
} | php | public function run($route = '', array $params, array $form = null)
{
// set up the router, but don't scan
$this->init();
/** @var CallReference $ref */
$ref = $this->router->getCall($route, $params);
//vd([$ref, $route, $params]);
//exit;
// controller has method
if($ref instanceof CallReference)
{
// test controller / method exists
try
{
new ReflectionMethod($ref->class, $ref->method);
}
catch(\Exception $e)
{
if($e instanceof \ReflectionException)
{
//$sketchpad = str_replace($this->config->route, '', $ref->route) . $ref->method . '/';
$this->abort($ref->route . '::' . $ref->method . '()', 'method');
}
}
// assign static properties
Sketchpad::$route = $ref->route . '/' . $ref->method . '/';
Sketchpad::$params = $ref->params;
Sketchpad::$form = empty($form) ? null : $form;
// get controller response or content
ob_start();
$response = $this->exec($ref->class, $ref->method, $ref->params);
$content = ob_get_contents();
ob_end_clean();
// handle echoed output
if ($content)
{
return $content;
}
// handle laravel view responses
if ($response instanceof \Illuminate\Contracts\View\View)
{
return $response;
}
// handle laravel json responses
if ($response instanceof \Illuminate\Http\JsonResponse)
{
return json($response->getData());
}
// handle Arrrayable
if ($response instanceof \Illuminate\Contracts\Support\Arrayable)
{
return json($response->toArray());
}
// handle Jsonable
if ($response instanceof \Illuminate\Contracts\Support\Jsonable)
{
return json(json_decode($response->toJson()));
}
// anything else send as JSON (classes, objects, arrays, numbers, strings, booleans)
return json($response);
}
// if there's not a valid controller or method, it's a 404
$this->abort($route, 'path');
return false;
} | [
"public",
"function",
"run",
"(",
"$",
"route",
"=",
"''",
",",
"array",
"$",
"params",
",",
"array",
"$",
"form",
"=",
"null",
")",
"{",
"// set up the router, but don't scan",
"$",
"this",
"->",
"init",
"(",
")",
";",
"/** @var CallReference $ref */",
"$",
"ref",
"=",
"$",
"this",
"->",
"router",
"->",
"getCall",
"(",
"$",
"route",
",",
"$",
"params",
")",
";",
"//vd([$ref, $route, $params]);",
"//exit;",
"// controller has method",
"if",
"(",
"$",
"ref",
"instanceof",
"CallReference",
")",
"{",
"// test controller / method exists",
"try",
"{",
"new",
"ReflectionMethod",
"(",
"$",
"ref",
"->",
"class",
",",
"$",
"ref",
"->",
"method",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"instanceof",
"\\",
"ReflectionException",
")",
"{",
"//$sketchpad = str_replace($this->config->route, '', $ref->route) . $ref->method . '/';",
"$",
"this",
"->",
"abort",
"(",
"$",
"ref",
"->",
"route",
".",
"'::'",
".",
"$",
"ref",
"->",
"method",
".",
"'()'",
",",
"'method'",
")",
";",
"}",
"}",
"// assign static properties",
"Sketchpad",
"::",
"$",
"route",
"=",
"$",
"ref",
"->",
"route",
".",
"'/'",
".",
"$",
"ref",
"->",
"method",
".",
"'/'",
";",
"Sketchpad",
"::",
"$",
"params",
"=",
"$",
"ref",
"->",
"params",
";",
"Sketchpad",
"::",
"$",
"form",
"=",
"empty",
"(",
"$",
"form",
")",
"?",
"null",
":",
"$",
"form",
";",
"// get controller response or content",
"ob_start",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"exec",
"(",
"$",
"ref",
"->",
"class",
",",
"$",
"ref",
"->",
"method",
",",
"$",
"ref",
"->",
"params",
")",
";",
"$",
"content",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"// handle echoed output",
"if",
"(",
"$",
"content",
")",
"{",
"return",
"$",
"content",
";",
"}",
"// handle laravel view responses",
"if",
"(",
"$",
"response",
"instanceof",
"\\",
"Illuminate",
"\\",
"Contracts",
"\\",
"View",
"\\",
"View",
")",
"{",
"return",
"$",
"response",
";",
"}",
"// handle laravel json responses",
"if",
"(",
"$",
"response",
"instanceof",
"\\",
"Illuminate",
"\\",
"Http",
"\\",
"JsonResponse",
")",
"{",
"return",
"json",
"(",
"$",
"response",
"->",
"getData",
"(",
")",
")",
";",
"}",
"// handle Arrrayable",
"if",
"(",
"$",
"response",
"instanceof",
"\\",
"Illuminate",
"\\",
"Contracts",
"\\",
"Support",
"\\",
"Arrayable",
")",
"{",
"return",
"json",
"(",
"$",
"response",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"// handle Jsonable",
"if",
"(",
"$",
"response",
"instanceof",
"\\",
"Illuminate",
"\\",
"Contracts",
"\\",
"Support",
"\\",
"Jsonable",
")",
"{",
"return",
"json",
"(",
"json_decode",
"(",
"$",
"response",
"->",
"toJson",
"(",
")",
")",
")",
";",
"}",
"// anything else send as JSON (classes, objects, arrays, numbers, strings, booleans)",
"return",
"json",
"(",
"$",
"response",
")",
";",
"}",
"// if there's not a valid controller or method, it's a 404",
"$",
"this",
"->",
"abort",
"(",
"$",
"route",
",",
"'path'",
")",
";",
"return",
"false",
";",
"}"
] | Initial function that works out the controller, method and parameters to call from the URI string
@param string $route
@param array $params
@param array $form
@return mixed|string | [
"Initial",
"function",
"that",
"works",
"out",
"the",
"controller",
"method",
"and",
"parameters",
"to",
"call",
"from",
"the",
"URI",
"string"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/services/Sketchpad.php#L119-L195 |
35,824 | davestewart/laravel-sketchpad | src/services/Sketchpad.php | Sketchpad.exec | public function exec($controller, $method, $params = null)
{
$callable = "$controller@$method";
return $params
? App::call($callable, $this->getCallParams($controller, $method, $params))
: App::call($callable);
} | php | public function exec($controller, $method, $params = null)
{
$callable = "$controller@$method";
return $params
? App::call($callable, $this->getCallParams($controller, $method, $params))
: App::call($callable);
} | [
"public",
"function",
"exec",
"(",
"$",
"controller",
",",
"$",
"method",
",",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"callable",
"=",
"\"$controller@$method\"",
";",
"return",
"$",
"params",
"?",
"App",
"::",
"call",
"(",
"$",
"callable",
",",
"$",
"this",
"->",
"getCallParams",
"(",
"$",
"controller",
",",
"$",
"method",
",",
"$",
"params",
")",
")",
":",
"App",
"::",
"call",
"(",
"$",
"callable",
")",
";",
"}"
] | Calls a controller and methods, resolving any dependency injection
@param string $controller The FQ name of the controller
@param string $method The name of the method
@param array|null $params An optional array of parameters
@return mixed The result of the call | [
"Calls",
"a",
"controller",
"and",
"methods",
"resolving",
"any",
"dependency",
"injection"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/services/Sketchpad.php#L209-L215 |
35,825 | davestewart/laravel-sketchpad | src/traits/SaveFileTrait.php | SaveFileTrait._save | protected function _save($file, $data)
{
// variables
$folder = dirname($file);
// ensure folder exists
if(!file_exists($folder))
{
mkdir($folder, 0777, true);
}
// ensure folder is writable
else if(!is_writable($folder))
{
chmod($folder, 0777);
}
// write file
if (file_exists($file) && !is_writable($file))
{
chmod($file, 0644);
}
file_put_contents($file, $data);
} | php | protected function _save($file, $data)
{
// variables
$folder = dirname($file);
// ensure folder exists
if(!file_exists($folder))
{
mkdir($folder, 0777, true);
}
// ensure folder is writable
else if(!is_writable($folder))
{
chmod($folder, 0777);
}
// write file
if (file_exists($file) && !is_writable($file))
{
chmod($file, 0644);
}
file_put_contents($file, $data);
} | [
"protected",
"function",
"_save",
"(",
"$",
"file",
",",
"$",
"data",
")",
"{",
"// variables",
"$",
"folder",
"=",
"dirname",
"(",
"$",
"file",
")",
";",
"// ensure folder exists",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"folder",
")",
")",
"{",
"mkdir",
"(",
"$",
"folder",
",",
"0777",
",",
"true",
")",
";",
"}",
"// ensure folder is writable",
"else",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"folder",
")",
")",
"{",
"chmod",
"(",
"$",
"folder",
",",
"0777",
")",
";",
"}",
"// write file",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
"&&",
"!",
"is_writable",
"(",
"$",
"file",
")",
")",
"{",
"chmod",
"(",
"$",
"file",
",",
"0644",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"data",
")",
";",
"}"
] | Saves content to a file, updating file permissions to ensure a save
@param string $file
@param string $data | [
"Saves",
"content",
"to",
"a",
"file",
"updating",
"file",
"permissions",
"to",
"ensure",
"a",
"save"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/traits/SaveFileTrait.php#L14-L37 |
35,826 | davestewart/laravel-sketchpad | src/utils/Options.php | Options.parse | public function parse($input)
{
$output = [];
$options = explode('|', $input);
foreach($options as $option)
{
$name = $option;
$value = 1;
if(strpos($option, ':') !== false)
{
list($name, $value) = explode(':', $option, 2);
}
if (strstr($value, ',') !== false)
{
$values = explode(',', $value);
if (strstr($value, '=') !== false)
{
$pairs = [];
foreach($values as $value)
{
list($n, $v) = explode('=', $value, 2);
$pairs[$n] = $v;
}
$values = $pairs;
}
$value = $values;
}
$output[$name] = $value;
}
return $output;
} | php | public function parse($input)
{
$output = [];
$options = explode('|', $input);
foreach($options as $option)
{
$name = $option;
$value = 1;
if(strpos($option, ':') !== false)
{
list($name, $value) = explode(':', $option, 2);
}
if (strstr($value, ',') !== false)
{
$values = explode(',', $value);
if (strstr($value, '=') !== false)
{
$pairs = [];
foreach($values as $value)
{
list($n, $v) = explode('=', $value, 2);
$pairs[$n] = $v;
}
$values = $pairs;
}
$value = $values;
}
$output[$name] = $value;
}
return $output;
} | [
"public",
"function",
"parse",
"(",
"$",
"input",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"$",
"options",
"=",
"explode",
"(",
"'|'",
",",
"$",
"input",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"$",
"name",
"=",
"$",
"option",
";",
"$",
"value",
"=",
"1",
";",
"if",
"(",
"strpos",
"(",
"$",
"option",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"option",
",",
"2",
")",
";",
"}",
"if",
"(",
"strstr",
"(",
"$",
"value",
",",
"','",
")",
"!==",
"false",
")",
"{",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"if",
"(",
"strstr",
"(",
"$",
"value",
",",
"'='",
")",
"!==",
"false",
")",
"{",
"$",
"pairs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"list",
"(",
"$",
"n",
",",
"$",
"v",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"value",
",",
"2",
")",
";",
"$",
"pairs",
"[",
"$",
"n",
"]",
"=",
"$",
"v",
";",
"}",
"$",
"values",
"=",
"$",
"pairs",
";",
"}",
"$",
"value",
"=",
"$",
"values",
";",
"}",
"$",
"output",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Converts string options to a hash
Operation:
- splits options by |
- splits arguments by :
- splits argument members by ,
- splits argument member names and values by =
Example:
index|html:path|pre:path,methods|values:One=1,Two=2,Three=3
@param $input
@return array | [
"Converts",
"string",
"options",
"to",
"a",
"hash"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Options.php#L82-L112 |
35,827 | davestewart/laravel-sketchpad | src/traits/ReflectionTraits.php | ReflectionTraits.getLabel | public function getLabel($default = null)
{
$label = $this->getTag('label');
if( ! $label )
{
$label = $default ?: $this->ref->getName();
$label = preg_replace('/^(.+)Controller$/', '$1', $label);
//$label = preg_replace('/_/', ' ', $label);
//$label = preg_replace('/([a-z])([A-Z0-9])/', '$1 $2', $label);
//$label = strtolower($label);
}
return $label;
} | php | public function getLabel($default = null)
{
$label = $this->getTag('label');
if( ! $label )
{
$label = $default ?: $this->ref->getName();
$label = preg_replace('/^(.+)Controller$/', '$1', $label);
//$label = preg_replace('/_/', ' ', $label);
//$label = preg_replace('/([a-z])([A-Z0-9])/', '$1 $2', $label);
//$label = strtolower($label);
}
return $label;
} | [
"public",
"function",
"getLabel",
"(",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"getTag",
"(",
"'label'",
")",
";",
"if",
"(",
"!",
"$",
"label",
")",
"{",
"$",
"label",
"=",
"$",
"default",
"?",
":",
"$",
"this",
"->",
"ref",
"->",
"getName",
"(",
")",
";",
"$",
"label",
"=",
"preg_replace",
"(",
"'/^(.+)Controller$/'",
",",
"'$1'",
",",
"$",
"label",
")",
";",
"//$label = preg_replace('/_/', ' ', $label);",
"//$label = preg_replace('/([a-z])([A-Z0-9])/', '$1 $2', $label);",
"//$label = strtolower($label);",
"}",
"return",
"$",
"label",
";",
"}"
] | Determines the label for the element
Returns a @label parameter, if available, otherwise, humanizes the element name
@param null $default
@return null|string | [
"Determines",
"the",
"label",
"for",
"the",
"element"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/traits/ReflectionTraits.php#L61-L73 |
35,828 | davestewart/laravel-sketchpad | src/traits/ReflectionTraits.php | ReflectionTraits.getTag | public function getTag($name)
{
$comment = $this->ref->getDocComment();
preg_match('/@' .$name. '\s+(.+)/', $comment, $matches);
return $matches ? $matches[1] : null;
} | php | public function getTag($name)
{
$comment = $this->ref->getDocComment();
preg_match('/@' .$name. '\s+(.+)/', $comment, $matches);
return $matches ? $matches[1] : null;
} | [
"public",
"function",
"getTag",
"(",
"$",
"name",
")",
"{",
"$",
"comment",
"=",
"$",
"this",
"->",
"ref",
"->",
"getDocComment",
"(",
")",
";",
"preg_match",
"(",
"'/@'",
".",
"$",
"name",
".",
"'\\s+(.+)/'",
",",
"$",
"comment",
",",
"$",
"matches",
")",
";",
"return",
"$",
"matches",
"?",
"$",
"matches",
"[",
"1",
"]",
":",
"null",
";",
"}"
] | Gets the first available value of a tag
@param string $name
@return string|null | [
"Gets",
"the",
"first",
"available",
"value",
"of",
"a",
"tag"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/traits/ReflectionTraits.php#L81-L86 |
35,829 | davestewart/laravel-sketchpad | src/objects/route/CallReference.php | CallReference.setMethod | public function setMethod($route)
{
// variables
$methodUri = trim(substr($route, strlen($this->route)), '/');
$segments = explode(',', $methodUri);
// properties
$this->method = array_shift($segments);
// return
return $this;
} | php | public function setMethod($route)
{
// variables
$methodUri = trim(substr($route, strlen($this->route)), '/');
$segments = explode(',', $methodUri);
// properties
$this->method = array_shift($segments);
// return
return $this;
} | [
"public",
"function",
"setMethod",
"(",
"$",
"route",
")",
"{",
"// variables",
"$",
"methodUri",
"=",
"trim",
"(",
"substr",
"(",
"$",
"route",
",",
"strlen",
"(",
"$",
"this",
"->",
"route",
")",
")",
",",
"'/'",
")",
";",
"$",
"segments",
"=",
"explode",
"(",
"','",
",",
"$",
"methodUri",
")",
";",
"// properties",
"$",
"this",
"->",
"method",
"=",
"array_shift",
"(",
"$",
"segments",
")",
";",
"// return",
"return",
"$",
"this",
";",
"}"
] | Determines the method to call
@param $route
@return $this | [
"Determines",
"the",
"method",
"to",
"call"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/route/CallReference.php#L77-L88 |
35,830 | davestewart/laravel-sketchpad | src/objects/route/CallReference.php | CallReference.setParams | public function setParams($params)
{
$this->params = [];
foreach ($params as $param)
{
// variables
$name = $param['name'];
$type = $param['type'];
$value = $param['value'];
// properties
$this->params[$name] = $this->convert($type, $value);
}
// return
return $this;
} | php | public function setParams($params)
{
$this->params = [];
foreach ($params as $param)
{
// variables
$name = $param['name'];
$type = $param['type'];
$value = $param['value'];
// properties
$this->params[$name] = $this->convert($type, $value);
}
// return
return $this;
} | [
"public",
"function",
"setParams",
"(",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"// variables",
"$",
"name",
"=",
"$",
"param",
"[",
"'name'",
"]",
";",
"$",
"type",
"=",
"$",
"param",
"[",
"'type'",
"]",
";",
"$",
"value",
"=",
"$",
"param",
"[",
"'value'",
"]",
";",
"// properties",
"$",
"this",
"->",
"params",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"convert",
"(",
"$",
"type",
",",
"$",
"value",
")",
";",
"}",
"// return",
"return",
"$",
"this",
";",
"}"
] | Sets the calling parameters from the submitted front end data
@param \StdClass[] $params
@return $this | [
"Sets",
"the",
"calling",
"parameters",
"from",
"the",
"submitted",
"front",
"end",
"data"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/route/CallReference.php#L96-L112 |
35,831 | davestewart/laravel-sketchpad | src/objects/route/CallReference.php | CallReference.convert | protected function convert ($type, $value)
{
switch ($type)
{
case 'string':
return (string) $value;
case 'number':
return is_float($value)
? (float) $value
: (int) $value;
case 'boolean':
return $value === true || $value === 'true' || $value === '1' || $value === 'on';
default:
if (is_float($value))
{
return $this->convert('number', $value);
}
if (is_numeric($value))
{
return strpos($value, '.') !== FALSE
? (float) $value
: (int) $value;
}
if ($value === 'true' || $value === 'false')
{
return $value === 'true';
}
if ($value === '')
{
return null;
}
}
return $value;
} | php | protected function convert ($type, $value)
{
switch ($type)
{
case 'string':
return (string) $value;
case 'number':
return is_float($value)
? (float) $value
: (int) $value;
case 'boolean':
return $value === true || $value === 'true' || $value === '1' || $value === 'on';
default:
if (is_float($value))
{
return $this->convert('number', $value);
}
if (is_numeric($value))
{
return strpos($value, '.') !== FALSE
? (float) $value
: (int) $value;
}
if ($value === 'true' || $value === 'false')
{
return $value === 'true';
}
if ($value === '')
{
return null;
}
}
return $value;
} | [
"protected",
"function",
"convert",
"(",
"$",
"type",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'string'",
":",
"return",
"(",
"string",
")",
"$",
"value",
";",
"case",
"'number'",
":",
"return",
"is_float",
"(",
"$",
"value",
")",
"?",
"(",
"float",
")",
"$",
"value",
":",
"(",
"int",
")",
"$",
"value",
";",
"case",
"'boolean'",
":",
"return",
"$",
"value",
"===",
"true",
"||",
"$",
"value",
"===",
"'true'",
"||",
"$",
"value",
"===",
"'1'",
"||",
"$",
"value",
"===",
"'on'",
";",
"default",
":",
"if",
"(",
"is_float",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"convert",
"(",
"'number'",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"strpos",
"(",
"$",
"value",
",",
"'.'",
")",
"!==",
"FALSE",
"?",
"(",
"float",
")",
"$",
"value",
":",
"(",
"int",
")",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"'true'",
"||",
"$",
"value",
"===",
"'false'",
")",
"{",
"return",
"$",
"value",
"===",
"'true'",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | Utility used to convert values to the correct type
@param string $type
@param mixed $value
@return mixed | [
"Utility",
"used",
"to",
"convert",
"values",
"to",
"the",
"correct",
"type"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/route/CallReference.php#L125-L161 |
35,832 | davestewart/laravel-sketchpad | src/help/demo/ToolsController.php | ToolsController.viewUsers | public function viewUsers()
{
$users = \DB::table('users')
->select('id', 'name', 'email', 'created_at')
->limit(1)
->paginate(15);
if($users)
{
tb($users);
echo $users;
return;
}
p('Unable to show users');
} | php | public function viewUsers()
{
$users = \DB::table('users')
->select('id', 'name', 'email', 'created_at')
->limit(1)
->paginate(15);
if($users)
{
tb($users);
echo $users;
return;
}
p('Unable to show users');
} | [
"public",
"function",
"viewUsers",
"(",
")",
"{",
"$",
"users",
"=",
"\\",
"DB",
"::",
"table",
"(",
"'users'",
")",
"->",
"select",
"(",
"'id'",
",",
"'name'",
",",
"'email'",
",",
"'created_at'",
")",
"->",
"limit",
"(",
"1",
")",
"->",
"paginate",
"(",
"15",
")",
";",
"if",
"(",
"$",
"users",
")",
"{",
"tb",
"(",
"$",
"users",
")",
";",
"echo",
"$",
"users",
";",
"return",
";",
"}",
"p",
"(",
"'Unable to show users'",
")",
";",
"}"
] | Show users in a table | [
"Show",
"users",
"in",
"a",
"table"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/demo/ToolsController.php#L31-L46 |
35,833 | davestewart/laravel-sketchpad | src/help/demo/ToolsController.php | ToolsController.browseFilesystem | public function browseFilesystem($path = '')
{
// helpers
function getBreadcrumbs($base, $path)
{
$paths = ['/' => $base];
$path = trim($path, '/');
if ($path !== '')
{
$segments = explode('/', $path);
$current = '/';
foreach($segments as $segment)
{
$current .= $segment . '/';
$paths[$current] = $segment;
}
}
return $paths;
}
// paths
$path = str_replace('../', '', $path);
$path = '/' . trim(preg_replace('%[\\/]+%', '/', $path), '/');
$realpath = realpath(base_path($path));
$base = pathinfo(base_path())['basename'];
// found
if($realpath)
{
try
{
$objects = array_diff(scandir($realpath), ['.','..']);
$breadcrumbs = getBreadcrumbs($base, $path);
$folders = array_filter($objects, function($f) use ($realpath) { return is_dir($realpath . '/' . $f); });
$files = array_filter($objects, function($f) use ($realpath) { return is_file($realpath . '/' . $f); });
$path = rtrim($path, '/') . '/';
$parent = $path !== '/' ? preg_replace('%[^/]+/$%', '', $path) : '/';
return view('sketchpad::help/tools/folder', compact('parent', 'path', 'folders', 'files', 'breadcrumbs'));
}
catch(\Exception $e)
{
return "Unable to read folder '$path'";
}
}
// not found
return "Path '$path' not found";
} | php | public function browseFilesystem($path = '')
{
// helpers
function getBreadcrumbs($base, $path)
{
$paths = ['/' => $base];
$path = trim($path, '/');
if ($path !== '')
{
$segments = explode('/', $path);
$current = '/';
foreach($segments as $segment)
{
$current .= $segment . '/';
$paths[$current] = $segment;
}
}
return $paths;
}
// paths
$path = str_replace('../', '', $path);
$path = '/' . trim(preg_replace('%[\\/]+%', '/', $path), '/');
$realpath = realpath(base_path($path));
$base = pathinfo(base_path())['basename'];
// found
if($realpath)
{
try
{
$objects = array_diff(scandir($realpath), ['.','..']);
$breadcrumbs = getBreadcrumbs($base, $path);
$folders = array_filter($objects, function($f) use ($realpath) { return is_dir($realpath . '/' . $f); });
$files = array_filter($objects, function($f) use ($realpath) { return is_file($realpath . '/' . $f); });
$path = rtrim($path, '/') . '/';
$parent = $path !== '/' ? preg_replace('%[^/]+/$%', '', $path) : '/';
return view('sketchpad::help/tools/folder', compact('parent', 'path', 'folders', 'files', 'breadcrumbs'));
}
catch(\Exception $e)
{
return "Unable to read folder '$path'";
}
}
// not found
return "Path '$path' not found";
} | [
"public",
"function",
"browseFilesystem",
"(",
"$",
"path",
"=",
"''",
")",
"{",
"// helpers",
"function",
"getBreadcrumbs",
"(",
"$",
"base",
",",
"$",
"path",
")",
"{",
"$",
"paths",
"=",
"[",
"'/'",
"=>",
"$",
"base",
"]",
";",
"$",
"path",
"=",
"trim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"path",
"!==",
"''",
")",
"{",
"$",
"segments",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"current",
"=",
"'/'",
";",
"foreach",
"(",
"$",
"segments",
"as",
"$",
"segment",
")",
"{",
"$",
"current",
".=",
"$",
"segment",
".",
"'/'",
";",
"$",
"paths",
"[",
"$",
"current",
"]",
"=",
"$",
"segment",
";",
"}",
"}",
"return",
"$",
"paths",
";",
"}",
"// paths",
"$",
"path",
"=",
"str_replace",
"(",
"'../'",
",",
"''",
",",
"$",
"path",
")",
";",
"$",
"path",
"=",
"'/'",
".",
"trim",
"(",
"preg_replace",
"(",
"'%[\\\\/]+%'",
",",
"'/'",
",",
"$",
"path",
")",
",",
"'/'",
")",
";",
"$",
"realpath",
"=",
"realpath",
"(",
"base_path",
"(",
"$",
"path",
")",
")",
";",
"$",
"base",
"=",
"pathinfo",
"(",
"base_path",
"(",
")",
")",
"[",
"'basename'",
"]",
";",
"// found",
"if",
"(",
"$",
"realpath",
")",
"{",
"try",
"{",
"$",
"objects",
"=",
"array_diff",
"(",
"scandir",
"(",
"$",
"realpath",
")",
",",
"[",
"'.'",
",",
"'..'",
"]",
")",
";",
"$",
"breadcrumbs",
"=",
"getBreadcrumbs",
"(",
"$",
"base",
",",
"$",
"path",
")",
";",
"$",
"folders",
"=",
"array_filter",
"(",
"$",
"objects",
",",
"function",
"(",
"$",
"f",
")",
"use",
"(",
"$",
"realpath",
")",
"{",
"return",
"is_dir",
"(",
"$",
"realpath",
".",
"'/'",
".",
"$",
"f",
")",
";",
"}",
")",
";",
"$",
"files",
"=",
"array_filter",
"(",
"$",
"objects",
",",
"function",
"(",
"$",
"f",
")",
"use",
"(",
"$",
"realpath",
")",
"{",
"return",
"is_file",
"(",
"$",
"realpath",
".",
"'/'",
".",
"$",
"f",
")",
";",
"}",
")",
";",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'/'",
";",
"$",
"parent",
"=",
"$",
"path",
"!==",
"'/'",
"?",
"preg_replace",
"(",
"'%[^/]+/$%'",
",",
"''",
",",
"$",
"path",
")",
":",
"'/'",
";",
"return",
"view",
"(",
"'sketchpad::help/tools/folder'",
",",
"compact",
"(",
"'parent'",
",",
"'path'",
",",
"'folders'",
",",
"'files'",
",",
"'breadcrumbs'",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"\"Unable to read folder '$path'\"",
";",
"}",
"}",
"// not found",
"return",
"\"Path '$path' not found\"",
";",
"}"
] | Browse your local filesystem
@param string $path
@return View|string | [
"Browse",
"your",
"local",
"filesystem"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/demo/ToolsController.php#L83-L131 |
35,834 | davestewart/laravel-sketchpad | src/help/demo/ToolsController.php | ToolsController.sketchpadSettings | public function sketchpadSettings(SketchpadConfig $config)
{
p('Settings:');
json($config->settings);
p('Admin:');
json($config->admin);
} | php | public function sketchpadSettings(SketchpadConfig $config)
{
p('Settings:');
json($config->settings);
p('Admin:');
json($config->admin);
} | [
"public",
"function",
"sketchpadSettings",
"(",
"SketchpadConfig",
"$",
"config",
")",
"{",
"p",
"(",
"'Settings:'",
")",
";",
"json",
"(",
"$",
"config",
"->",
"settings",
")",
";",
"p",
"(",
"'Admin:'",
")",
";",
"json",
"(",
"$",
"config",
"->",
"admin",
")",
";",
"}"
] | Check your sketchpad settings | [
"Check",
"your",
"sketchpad",
"settings"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/demo/ToolsController.php#L146-L152 |
35,835 | davestewart/laravel-sketchpad | src/help/docs/SetupController.php | SetupController.assets | public function assets(SketchpadConfig $config)
{
$assets = $config->settings->get('paths.assets');
$views = $config->settings->get('paths.views');
md('sketchpad::help/setup/assets', compact('assets', 'views'));
} | php | public function assets(SketchpadConfig $config)
{
$assets = $config->settings->get('paths.assets');
$views = $config->settings->get('paths.views');
md('sketchpad::help/setup/assets', compact('assets', 'views'));
} | [
"public",
"function",
"assets",
"(",
"SketchpadConfig",
"$",
"config",
")",
"{",
"$",
"assets",
"=",
"$",
"config",
"->",
"settings",
"->",
"get",
"(",
"'paths.assets'",
")",
";",
"$",
"views",
"=",
"$",
"config",
"->",
"settings",
"->",
"get",
"(",
"'paths.views'",
")",
";",
"md",
"(",
"'sketchpad::help/setup/assets'",
",",
"compact",
"(",
"'assets'",
",",
"'views'",
")",
")",
";",
"}"
] | Load user scripts and styles to augment your Sketchpad development | [
"Load",
"user",
"scripts",
"and",
"styles",
"to",
"augment",
"your",
"Sketchpad",
"development"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/docs/SetupController.php#L42-L47 |
35,836 | davestewart/laravel-sketchpad | src/help/docs/SetupController.php | SetupController.head | public function head(Paths $paths, SketchpadConfig $config)
{
$head = $config->getView('head');
$path = $paths->package('setup/views/head.blade.php');
$html = file_get_contents($path);
md('sketchpad::help/setup/head', compact('head', 'html'));
} | php | public function head(Paths $paths, SketchpadConfig $config)
{
$head = $config->getView('head');
$path = $paths->package('setup/views/head.blade.php');
$html = file_get_contents($path);
md('sketchpad::help/setup/head', compact('head', 'html'));
} | [
"public",
"function",
"head",
"(",
"Paths",
"$",
"paths",
",",
"SketchpadConfig",
"$",
"config",
")",
"{",
"$",
"head",
"=",
"$",
"config",
"->",
"getView",
"(",
"'head'",
")",
";",
"$",
"path",
"=",
"$",
"paths",
"->",
"package",
"(",
"'setup/views/head.blade.php'",
")",
";",
"$",
"html",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"md",
"(",
"'sketchpad::help/setup/head'",
",",
"compact",
"(",
"'head'",
",",
"'html'",
")",
")",
";",
"}"
] | Add 3rd-party libraries, tracking or other head content | [
"Add",
"3rd",
"-",
"party",
"libraries",
"tracking",
"or",
"other",
"head",
"content"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/docs/SetupController.php#L82-L88 |
35,837 | davestewart/laravel-sketchpad | src/utils/Html.php | Html.code | public static function code($source)
{
if (class_exists($source))
{
@list ($class, $method, $comment) = func_get_args();
return is_string($method)
? Code::method($class, $method, $comment)
: Code::classfile($class, $method);
}
else if (file_exists($source))
{
@list ($path, $start, $end, $undent) = func_get_args();
return is_int($start)
? Code::section($path, $start, $end, $undent)
: Code::file($path, $start);
}
return Code::output($source);
} | php | public static function code($source)
{
if (class_exists($source))
{
@list ($class, $method, $comment) = func_get_args();
return is_string($method)
? Code::method($class, $method, $comment)
: Code::classfile($class, $method);
}
else if (file_exists($source))
{
@list ($path, $start, $end, $undent) = func_get_args();
return is_int($start)
? Code::section($path, $start, $end, $undent)
: Code::file($path, $start);
}
return Code::output($source);
} | [
"public",
"static",
"function",
"code",
"(",
"$",
"source",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"source",
")",
")",
"{",
"@",
"list",
"(",
"$",
"class",
",",
"$",
"method",
",",
"$",
"comment",
")",
"=",
"func_get_args",
"(",
")",
";",
"return",
"is_string",
"(",
"$",
"method",
")",
"?",
"Code",
"::",
"method",
"(",
"$",
"class",
",",
"$",
"method",
",",
"$",
"comment",
")",
":",
"Code",
"::",
"classfile",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"}",
"else",
"if",
"(",
"file_exists",
"(",
"$",
"source",
")",
")",
"{",
"@",
"list",
"(",
"$",
"path",
",",
"$",
"start",
",",
"$",
"end",
",",
"$",
"undent",
")",
"=",
"func_get_args",
"(",
")",
";",
"return",
"is_int",
"(",
"$",
"start",
")",
"?",
"Code",
"::",
"section",
"(",
"$",
"path",
",",
"$",
"start",
",",
"$",
"end",
",",
"$",
"undent",
")",
":",
"Code",
"::",
"file",
"(",
"$",
"path",
",",
"$",
"start",
")",
";",
"}",
"return",
"Code",
"::",
"output",
"(",
"$",
"source",
")",
";",
"}"
] | Return code with optional highlighting
@param string $source
@return string | [
"Return",
"code",
"with",
"optional",
"highlighting"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Html.php#L55-L72 |
35,838 | davestewart/laravel-sketchpad | src/utils/Html.php | Html.icon | public static function icon($name, $color = '')
{
if (is_bool($name))
{
$color = $name ? 'success' : 'danger';
$name = $name ? 'check' : 'times';
}
$class = "icon fa fa-$name";
$style = '';
if (preg_match('/(info|success|warning|danger)/', $color))
{
$class .= ' text-' . $color;
}
else if ($color !== '')
{
$style = ' style="color:' .$color. '"';
}
return '<i class="' .$class. '" ' .$style. '></i>';
} | php | public static function icon($name, $color = '')
{
if (is_bool($name))
{
$color = $name ? 'success' : 'danger';
$name = $name ? 'check' : 'times';
}
$class = "icon fa fa-$name";
$style = '';
if (preg_match('/(info|success|warning|danger)/', $color))
{
$class .= ' text-' . $color;
}
else if ($color !== '')
{
$style = ' style="color:' .$color. '"';
}
return '<i class="' .$class. '" ' .$style. '></i>';
} | [
"public",
"static",
"function",
"icon",
"(",
"$",
"name",
",",
"$",
"color",
"=",
"''",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"name",
")",
")",
"{",
"$",
"color",
"=",
"$",
"name",
"?",
"'success'",
":",
"'danger'",
";",
"$",
"name",
"=",
"$",
"name",
"?",
"'check'",
":",
"'times'",
";",
"}",
"$",
"class",
"=",
"\"icon fa fa-$name\"",
";",
"$",
"style",
"=",
"''",
";",
"if",
"(",
"preg_match",
"(",
"'/(info|success|warning|danger)/'",
",",
"$",
"color",
")",
")",
"{",
"$",
"class",
".=",
"' text-'",
".",
"$",
"color",
";",
"}",
"else",
"if",
"(",
"$",
"color",
"!==",
"''",
")",
"{",
"$",
"style",
"=",
"' style=\"color:'",
".",
"$",
"color",
".",
"'\"'",
";",
"}",
"return",
"'<i class=\"'",
".",
"$",
"class",
".",
"'\" '",
".",
"$",
"style",
".",
"'></i>'",
";",
"}"
] | Return a Font Awesome icon
@param string|bool $name A FontAwesome icon name, or a boolean for colored tick/cross
@param string $color An optional colour
@return string | [
"Return",
"a",
"Font",
"Awesome",
"icon"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Html.php#L104-L122 |
35,839 | davestewart/laravel-sketchpad | src/utils/Html.php | Html.ls | public static function ls($values, $options = '')
{
$opts = new Options($options);
$data =
[
'values' => $values,
'style' => $opts->get('style', ''),
'class' => $opts->get('class', ''),
];
if($opts->pre === 1)
{
$data['class'] .= ' pre';
}
if($opts->wide)
{
$data['style'] .= ';width:100%;';
}
return view('sketchpad::html.list', $data);
} | php | public static function ls($values, $options = '')
{
$opts = new Options($options);
$data =
[
'values' => $values,
'style' => $opts->get('style', ''),
'class' => $opts->get('class', ''),
];
if($opts->pre === 1)
{
$data['class'] .= ' pre';
}
if($opts->wide)
{
$data['style'] .= ';width:100%;';
}
return view('sketchpad::html.list', $data);
} | [
"public",
"static",
"function",
"ls",
"(",
"$",
"values",
",",
"$",
"options",
"=",
"''",
")",
"{",
"$",
"opts",
"=",
"new",
"Options",
"(",
"$",
"options",
")",
";",
"$",
"data",
"=",
"[",
"'values'",
"=>",
"$",
"values",
",",
"'style'",
"=>",
"$",
"opts",
"->",
"get",
"(",
"'style'",
",",
"''",
")",
",",
"'class'",
"=>",
"$",
"opts",
"->",
"get",
"(",
"'class'",
",",
"''",
")",
",",
"]",
";",
"if",
"(",
"$",
"opts",
"->",
"pre",
"===",
"1",
")",
"{",
"$",
"data",
"[",
"'class'",
"]",
".=",
"' pre'",
";",
"}",
"if",
"(",
"$",
"opts",
"->",
"wide",
")",
"{",
"$",
"data",
"[",
"'style'",
"]",
".=",
"';width:100%;'",
";",
"}",
"return",
"view",
"(",
"'sketchpad::html.list'",
",",
"$",
"data",
")",
";",
"}"
] | List an object's properties in a nicely formatted table
@param mixed $values
@param string $options
@return string | [
"List",
"an",
"object",
"s",
"properties",
"in",
"a",
"nicely",
"formatted",
"table"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Html.php#L164-L182 |
35,840 | davestewart/laravel-sketchpad | src/utils/Html.php | Html.md | public static function md($path, $data = [])
{
// find file
$abspath = preg_match('%^(/|[a-z]:)%i', $path) === 1
? $path
: \View::getFinder()->find($path);
// get contents
$contents = file_get_contents($abspath);
// update values
$data['route'] = app(SketchpadConfig::class)->route;
foreach ($data as $key => $value)
{
$contents = preg_replace('/\{\{\s*' .$key. '\s*\}\}/', $value, $contents);
}
// return
return '<div data-format="markdown">' .$contents. '</div>';
} | php | public static function md($path, $data = [])
{
// find file
$abspath = preg_match('%^(/|[a-z]:)%i', $path) === 1
? $path
: \View::getFinder()->find($path);
// get contents
$contents = file_get_contents($abspath);
// update values
$data['route'] = app(SketchpadConfig::class)->route;
foreach ($data as $key => $value)
{
$contents = preg_replace('/\{\{\s*' .$key. '\s*\}\}/', $value, $contents);
}
// return
return '<div data-format="markdown">' .$contents. '</div>';
} | [
"public",
"static",
"function",
"md",
"(",
"$",
"path",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"// find file",
"$",
"abspath",
"=",
"preg_match",
"(",
"'%^(/|[a-z]:)%i'",
",",
"$",
"path",
")",
"===",
"1",
"?",
"$",
"path",
":",
"\\",
"View",
"::",
"getFinder",
"(",
")",
"->",
"find",
"(",
"$",
"path",
")",
";",
"// get contents",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"abspath",
")",
";",
"// update values",
"$",
"data",
"[",
"'route'",
"]",
"=",
"app",
"(",
"SketchpadConfig",
"::",
"class",
")",
"->",
"route",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"contents",
"=",
"preg_replace",
"(",
"'/\\{\\{\\s*'",
".",
"$",
"key",
".",
"'\\s*\\}\\}/'",
",",
"$",
"value",
",",
"$",
"contents",
")",
";",
"}",
"// return",
"return",
"'<div data-format=\"markdown\">'",
".",
"$",
"contents",
".",
"'</div>'",
";",
"}"
] | Loads a Markdown file, and instructs Sketchpad to transform it in the front end
@param string $path An absolute or relative file reference
@param array $data
@return string | [
"Loads",
"a",
"Markdown",
"file",
"and",
"instructs",
"Sketchpad",
"to",
"transform",
"it",
"in",
"the",
"front",
"end"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Html.php#L310-L329 |
35,841 | davestewart/laravel-sketchpad | src/utils/Html.php | Html.vue | public static function vue($path, array $data = null)
{
$path = \View::getFinder()->find($path);
$str = file_get_contents($path);
if($data)
{
$tag1 = '<scr'.'ipt>';
$tag2 = '</scr'.'ipt>';
$json = json_encode($data);
$str = str_replace($tag1, $tag1 . "(function () {\n\tvar \$data = $json;", $str);
$str = str_replace($tag2, '}())' . $tag2, $str);
}
return $str;
} | php | public static function vue($path, array $data = null)
{
$path = \View::getFinder()->find($path);
$str = file_get_contents($path);
if($data)
{
$tag1 = '<scr'.'ipt>';
$tag2 = '</scr'.'ipt>';
$json = json_encode($data);
$str = str_replace($tag1, $tag1 . "(function () {\n\tvar \$data = $json;", $str);
$str = str_replace($tag2, '}())' . $tag2, $str);
}
return $str;
} | [
"public",
"static",
"function",
"vue",
"(",
"$",
"path",
",",
"array",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"path",
"=",
"\\",
"View",
"::",
"getFinder",
"(",
")",
"->",
"find",
"(",
"$",
"path",
")",
";",
"$",
"str",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"tag1",
"=",
"'<scr'",
".",
"'ipt>'",
";",
"$",
"tag2",
"=",
"'</scr'",
".",
"'ipt>'",
";",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"$",
"str",
"=",
"str_replace",
"(",
"$",
"tag1",
",",
"$",
"tag1",
".",
"\"(function () {\\n\\tvar \\$data = $json;\"",
",",
"$",
"str",
")",
";",
"$",
"str",
"=",
"str_replace",
"(",
"$",
"tag2",
",",
"'}())'",
".",
"$",
"tag2",
",",
"$",
"str",
")",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Loads a Vue file and optionally injects data into it
@param string $path
@param mixed $data
@return string | [
"Loads",
"a",
"Vue",
"file",
"and",
"optionally",
"injects",
"data",
"into",
"it"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Html.php#L338-L351 |
35,842 | davestewart/laravel-sketchpad | src/help/docs/MethodsController.php | MethodsController.run | public function run()
{
list($s, $m) = explode(".", microtime(true));
$date = date('H:i:s', $s) . '.' . $m;
return view('sketchpad::help/methods/run', compact('date'));
} | php | public function run()
{
list($s, $m) = explode(".", microtime(true));
$date = date('H:i:s', $s) . '.' . $m;
return view('sketchpad::help/methods/run', compact('date'));
} | [
"public",
"function",
"run",
"(",
")",
"{",
"list",
"(",
"$",
"s",
",",
"$",
"m",
")",
"=",
"explode",
"(",
"\".\"",
",",
"microtime",
"(",
"true",
")",
")",
";",
"$",
"date",
"=",
"date",
"(",
"'H:i:s'",
",",
"$",
"s",
")",
".",
"'.'",
".",
"$",
"m",
";",
"return",
"view",
"(",
"'sketchpad::help/methods/run'",
",",
"compact",
"(",
"'date'",
")",
")",
";",
"}"
] | Run a method just by clicking on its label
@group Execution | [
"Run",
"a",
"method",
"just",
"by",
"clicking",
"on",
"its",
"label"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/docs/MethodsController.php#L27-L33 |
35,843 | davestewart/laravel-sketchpad | src/help/docs/MethodsController.php | MethodsController.variables | public function variables(SketchpadConfig $config)
{
$route = $config->route;
$views = $config->views;
$fullroute = Sketchpad::$route;
return view('sketchpad::help/methods/variables', compact('route', 'fullroute', 'views'));
} | php | public function variables(SketchpadConfig $config)
{
$route = $config->route;
$views = $config->views;
$fullroute = Sketchpad::$route;
return view('sketchpad::help/methods/variables', compact('route', 'fullroute', 'views'));
} | [
"public",
"function",
"variables",
"(",
"SketchpadConfig",
"$",
"config",
")",
"{",
"$",
"route",
"=",
"$",
"config",
"->",
"route",
";",
"$",
"views",
"=",
"$",
"config",
"->",
"views",
";",
"$",
"fullroute",
"=",
"Sketchpad",
"::",
"$",
"route",
";",
"return",
"view",
"(",
"'sketchpad::help/methods/variables'",
",",
"compact",
"(",
"'route'",
",",
"'fullroute'",
",",
"'views'",
")",
")",
";",
"}"
] | Sketchpad makes a few classes and variables available to you | [
"Sketchpad",
"makes",
"a",
"few",
"classes",
"and",
"variables",
"available",
"to",
"you"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/docs/MethodsController.php#L96-L102 |
35,844 | davestewart/laravel-sketchpad | src/services/Router.php | Router.getCall | public function getCall($route, array $params = [])
{
// variables
$route = AbstractScanner::folderize($route);
$routes = $this->getRoutes();
// debug
// pr($route, $routes);
// first, attempt to find an exact match
// an exact match will either be a controller or a folder
if(isset($routes[$route]))
{
return $routes[$route];
}
// otherwise, the passed path will be at least a "controller/method" in which case,
// we need to find the nearest partial match, then extract the component parts
else
{
// variables
/** @var CallReference $ref */
$ref = null;
// loop over routes and grab matches
// the last full match will be the one that we want
foreach($routes as $key => $value)
{
//pr('KEY', $key, $value);
if(strpos($route, $key) === 0)
{
$ref = $value;
}
}
// debug
//pr('REF', $ref);
// if we got a matching route, update the ref with method and params
if($ref instanceof ControllerReference)
{
return CallReference::fromControllerRef($ref)
->setMethod($route)
->setParams($params);
}
if($ref instanceof ControllerErrorReference)
{
return CallReference::fromRef($ref)
->setMethod($route)
->setParams($params);
}
}
// return
return null;
} | php | public function getCall($route, array $params = [])
{
// variables
$route = AbstractScanner::folderize($route);
$routes = $this->getRoutes();
// debug
// pr($route, $routes);
// first, attempt to find an exact match
// an exact match will either be a controller or a folder
if(isset($routes[$route]))
{
return $routes[$route];
}
// otherwise, the passed path will be at least a "controller/method" in which case,
// we need to find the nearest partial match, then extract the component parts
else
{
// variables
/** @var CallReference $ref */
$ref = null;
// loop over routes and grab matches
// the last full match will be the one that we want
foreach($routes as $key => $value)
{
//pr('KEY', $key, $value);
if(strpos($route, $key) === 0)
{
$ref = $value;
}
}
// debug
//pr('REF', $ref);
// if we got a matching route, update the ref with method and params
if($ref instanceof ControllerReference)
{
return CallReference::fromControllerRef($ref)
->setMethod($route)
->setParams($params);
}
if($ref instanceof ControllerErrorReference)
{
return CallReference::fromRef($ref)
->setMethod($route)
->setParams($params);
}
}
// return
return null;
} | [
"public",
"function",
"getCall",
"(",
"$",
"route",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"// variables",
"$",
"route",
"=",
"AbstractScanner",
"::",
"folderize",
"(",
"$",
"route",
")",
";",
"$",
"routes",
"=",
"$",
"this",
"->",
"getRoutes",
"(",
")",
";",
"// debug",
"// pr($route, $routes);",
"// first, attempt to find an exact match",
"// an exact match will either be a controller or a folder",
"if",
"(",
"isset",
"(",
"$",
"routes",
"[",
"$",
"route",
"]",
")",
")",
"{",
"return",
"$",
"routes",
"[",
"$",
"route",
"]",
";",
"}",
"// otherwise, the passed path will be at least a \"controller/method\" in which case,",
"// we need to find the nearest partial match, then extract the component parts",
"else",
"{",
"// variables",
"/** @var CallReference $ref */",
"$",
"ref",
"=",
"null",
";",
"// loop over routes and grab matches",
"// the last full match will be the one that we want",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"//pr('KEY', $key, $value);",
"if",
"(",
"strpos",
"(",
"$",
"route",
",",
"$",
"key",
")",
"===",
"0",
")",
"{",
"$",
"ref",
"=",
"$",
"value",
";",
"}",
"}",
"// debug",
"//pr('REF', $ref);",
"// if we got a matching route, update the ref with method and params",
"if",
"(",
"$",
"ref",
"instanceof",
"ControllerReference",
")",
"{",
"return",
"CallReference",
"::",
"fromControllerRef",
"(",
"$",
"ref",
")",
"->",
"setMethod",
"(",
"$",
"route",
")",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"}",
"if",
"(",
"$",
"ref",
"instanceof",
"ControllerErrorReference",
")",
"{",
"return",
"CallReference",
"::",
"fromRef",
"(",
"$",
"ref",
")",
"->",
"setMethod",
"(",
"$",
"route",
")",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"}",
"}",
"// return",
"return",
"null",
";",
"}"
] | Reverse route lookup
Compares a given route against routes determined when controllers were scanned
Determines the controller, method and parameters to call if there is a match
@param string $route
@param $params
@return ControllerReference|FolderReference|null | [
"Reverse",
"route",
"lookup"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/services/Router.php#L114-L171 |
35,845 | davestewart/laravel-sketchpad | src/utils/Code.php | Code.file | public static function file($path, $format = '')
{
if ($format === '')
{
$format = self::getExtension($path);
}
$text = file_get_contents($path);
return self::output($text, $format);
} | php | public static function file($path, $format = '')
{
if ($format === '')
{
$format = self::getExtension($path);
}
$text = file_get_contents($path);
return self::output($text, $format);
} | [
"public",
"static",
"function",
"file",
"(",
"$",
"path",
",",
"$",
"format",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"format",
"===",
"''",
")",
"{",
"$",
"format",
"=",
"self",
"::",
"getExtension",
"(",
"$",
"path",
")",
";",
"}",
"$",
"text",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"return",
"self",
"::",
"output",
"(",
"$",
"text",
",",
"$",
"format",
")",
";",
"}"
] | Output the contents of an entire file
@param string $path
@param string $format
@return string | [
"Output",
"the",
"contents",
"of",
"an",
"entire",
"file"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Code.php#L29-L37 |
35,846 | davestewart/laravel-sketchpad | src/utils/Code.php | Code.section | public static function section($path, $start = 0, $end = 0, $undent = false)
{
$format = self::getExtension($path);
$text = file_get_contents($path);
if ($start !== 0 || $end !== 0)
{
$text = self::lines($text, $start, $end);
if ($undent)
{
$text = self::undent($text);
}
}
return self::output($text, $format);
} | php | public static function section($path, $start = 0, $end = 0, $undent = false)
{
$format = self::getExtension($path);
$text = file_get_contents($path);
if ($start !== 0 || $end !== 0)
{
$text = self::lines($text, $start, $end);
if ($undent)
{
$text = self::undent($text);
}
}
return self::output($text, $format);
} | [
"public",
"static",
"function",
"section",
"(",
"$",
"path",
",",
"$",
"start",
"=",
"0",
",",
"$",
"end",
"=",
"0",
",",
"$",
"undent",
"=",
"false",
")",
"{",
"$",
"format",
"=",
"self",
"::",
"getExtension",
"(",
"$",
"path",
")",
";",
"$",
"text",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"start",
"!==",
"0",
"||",
"$",
"end",
"!==",
"0",
")",
"{",
"$",
"text",
"=",
"self",
"::",
"lines",
"(",
"$",
"text",
",",
"$",
"start",
",",
"$",
"end",
")",
";",
"if",
"(",
"$",
"undent",
")",
"{",
"$",
"text",
"=",
"self",
"::",
"undent",
"(",
"$",
"text",
")",
";",
"}",
"}",
"return",
"self",
"::",
"output",
"(",
"$",
"text",
",",
"$",
"format",
")",
";",
"}"
] | Output a section of a single file
@param string $path
@param int $start
@param int $end
@param bool $undent
@return string | [
"Output",
"a",
"section",
"of",
"a",
"single",
"file"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Code.php#L48-L61 |
35,847 | davestewart/laravel-sketchpad | src/utils/Code.php | Code.method | public static function method($class, $method, $comment = false)
{
$ref = new \ReflectionMethod($class, $method);
$start = $ref->getStartLine();
$end = $ref->getEndLine();
$text = file_get_contents($ref->getFileName());
$text = self::lines($text, $start, $end);
$text = self::undent($text);
if ($comment)
{
$text = preg_replace('/^\s+\*/m', ' *', $ref->getDocComment()) . PHP_EOL . $text;
}
return self::output($text, 'php');
} | php | public static function method($class, $method, $comment = false)
{
$ref = new \ReflectionMethod($class, $method);
$start = $ref->getStartLine();
$end = $ref->getEndLine();
$text = file_get_contents($ref->getFileName());
$text = self::lines($text, $start, $end);
$text = self::undent($text);
if ($comment)
{
$text = preg_replace('/^\s+\*/m', ' *', $ref->getDocComment()) . PHP_EOL . $text;
}
return self::output($text, 'php');
} | [
"public",
"static",
"function",
"method",
"(",
"$",
"class",
",",
"$",
"method",
",",
"$",
"comment",
"=",
"false",
")",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"$",
"start",
"=",
"$",
"ref",
"->",
"getStartLine",
"(",
")",
";",
"$",
"end",
"=",
"$",
"ref",
"->",
"getEndLine",
"(",
")",
";",
"$",
"text",
"=",
"file_get_contents",
"(",
"$",
"ref",
"->",
"getFileName",
"(",
")",
")",
";",
"$",
"text",
"=",
"self",
"::",
"lines",
"(",
"$",
"text",
",",
"$",
"start",
",",
"$",
"end",
")",
";",
"$",
"text",
"=",
"self",
"::",
"undent",
"(",
"$",
"text",
")",
";",
"if",
"(",
"$",
"comment",
")",
"{",
"$",
"text",
"=",
"preg_replace",
"(",
"'/^\\s+\\*/m'",
",",
"' *'",
",",
"$",
"ref",
"->",
"getDocComment",
"(",
")",
")",
".",
"PHP_EOL",
".",
"$",
"text",
";",
"}",
"return",
"self",
"::",
"output",
"(",
"$",
"text",
",",
"'php'",
")",
";",
"}"
] | Output the contents of a method
@param string $class
@param string $method
@param bool $comment
@return string | [
"Output",
"the",
"contents",
"of",
"a",
"method"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Code.php#L71-L84 |
35,848 | davestewart/laravel-sketchpad | src/utils/Code.php | Code.classfile | public static function classfile($class, $comment = false)
{
$ref = new \ReflectionClass($class);
$start = $ref->getStartLine();
$end = $ref->getEndLine();
$text = file_get_contents($ref->getFileName());
$text = self::lines($text, $start, $end);
if ($comment)
{
$text = preg_replace('/^\s+\*/m', ' *', $ref->getDocComment()) . PHP_EOL . $text;
}
return self::output($text, 'php');
} | php | public static function classfile($class, $comment = false)
{
$ref = new \ReflectionClass($class);
$start = $ref->getStartLine();
$end = $ref->getEndLine();
$text = file_get_contents($ref->getFileName());
$text = self::lines($text, $start, $end);
if ($comment)
{
$text = preg_replace('/^\s+\*/m', ' *', $ref->getDocComment()) . PHP_EOL . $text;
}
return self::output($text, 'php');
} | [
"public",
"static",
"function",
"classfile",
"(",
"$",
"class",
",",
"$",
"comment",
"=",
"false",
")",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"start",
"=",
"$",
"ref",
"->",
"getStartLine",
"(",
")",
";",
"$",
"end",
"=",
"$",
"ref",
"->",
"getEndLine",
"(",
")",
";",
"$",
"text",
"=",
"file_get_contents",
"(",
"$",
"ref",
"->",
"getFileName",
"(",
")",
")",
";",
"$",
"text",
"=",
"self",
"::",
"lines",
"(",
"$",
"text",
",",
"$",
"start",
",",
"$",
"end",
")",
";",
"if",
"(",
"$",
"comment",
")",
"{",
"$",
"text",
"=",
"preg_replace",
"(",
"'/^\\s+\\*/m'",
",",
"' *'",
",",
"$",
"ref",
"->",
"getDocComment",
"(",
")",
")",
".",
"PHP_EOL",
".",
"$",
"text",
";",
"}",
"return",
"self",
"::",
"output",
"(",
"$",
"text",
",",
"'php'",
")",
";",
"}"
] | Output the contents of a class
@param string $class
@param bool $comment
@return string | [
"Output",
"the",
"contents",
"of",
"a",
"class"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Code.php#L93-L105 |
35,849 | davestewart/laravel-sketchpad | src/utils/Code.php | Code.lines | public static function lines($text, $start, $end)
{
$lines = explode(PHP_EOL, $text);
$code = implode(PHP_EOL, array_slice($lines, $start - 1, $end - $start + 1));
return $code;
} | php | public static function lines($text, $start, $end)
{
$lines = explode(PHP_EOL, $text);
$code = implode(PHP_EOL, array_slice($lines, $start - 1, $end - $start + 1));
return $code;
} | [
"public",
"static",
"function",
"lines",
"(",
"$",
"text",
",",
"$",
"start",
",",
"$",
"end",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"text",
")",
";",
"$",
"code",
"=",
"implode",
"(",
"PHP_EOL",
",",
"array_slice",
"(",
"$",
"lines",
",",
"$",
"start",
"-",
"1",
",",
"$",
"end",
"-",
"$",
"start",
"+",
"1",
")",
")",
";",
"return",
"$",
"code",
";",
"}"
] | Return a range of lines from a block of text
@param string $text
@param int $start
@param int $end
@return string | [
"Return",
"a",
"range",
"of",
"lines",
"from",
"a",
"block",
"of",
"text"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Code.php#L115-L120 |
35,850 | davestewart/laravel-sketchpad | src/utils/Code.php | Code.signature | public static function signature($args = [])
{
$values = array_map(function ($v) {
return is_string($v)
? "'$v'"
: (is_bool($v)
? !! $v ? 'true' : 'false'
: $v);
}, $args);
return '(' . implode(', ', $values) . ')';
} | php | public static function signature($args = [])
{
$values = array_map(function ($v) {
return is_string($v)
? "'$v'"
: (is_bool($v)
? !! $v ? 'true' : 'false'
: $v);
}, $args);
return '(' . implode(', ', $values) . ')';
} | [
"public",
"static",
"function",
"signature",
"(",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"values",
"=",
"array_map",
"(",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"is_string",
"(",
"$",
"v",
")",
"?",
"\"'$v'\"",
":",
"(",
"is_bool",
"(",
"$",
"v",
")",
"?",
"!",
"!",
"$",
"v",
"?",
"'true'",
":",
"'false'",
":",
"$",
"v",
")",
";",
"}",
",",
"$",
"args",
")",
";",
"return",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
".",
"')'",
";",
"}"
] | Return a formatted function signature
@param array $args
@return string | [
"Return",
"a",
"formatted",
"function",
"signature"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Code.php#L128-L138 |
35,851 | davestewart/laravel-sketchpad | src/utils/Code.php | Code.undent | public static function undent($text)
{
preg_match('/^\s+/', $text, $matches);
list ($indent) = $matches;
if ($indent)
{
$text = preg_replace("/^$indent/m", '', $text);
}
return $text;
} | php | public static function undent($text)
{
preg_match('/^\s+/', $text, $matches);
list ($indent) = $matches;
if ($indent)
{
$text = preg_replace("/^$indent/m", '', $text);
}
return $text;
} | [
"public",
"static",
"function",
"undent",
"(",
"$",
"text",
")",
"{",
"preg_match",
"(",
"'/^\\s+/'",
",",
"$",
"text",
",",
"$",
"matches",
")",
";",
"list",
"(",
"$",
"indent",
")",
"=",
"$",
"matches",
";",
"if",
"(",
"$",
"indent",
")",
"{",
"$",
"text",
"=",
"preg_replace",
"(",
"\"/^$indent/m\"",
",",
"''",
",",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Remove any indent from a block of text, based on the first line
@param string $text
@return string | [
"Remove",
"any",
"indent",
"from",
"a",
"block",
"of",
"text",
"based",
"on",
"the",
"first",
"line"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/utils/Code.php#L146-L155 |
35,852 | davestewart/laravel-sketchpad | src/services/Setup.php | Setup.view | public function view()
{
// default variables
$finder = new Finder();
$finder->start();
// config
$config = app(SketchpadConfig::class);
// base name
$basePath = Paths::fix(base_path('/'));
$baseSegments = explode('/', rtrim($basePath, '/'));
$baseName = array_pop($baseSegments) . '/';
// view path
$viewPaths = Config::get('view.paths');
$viewPath = substr(Paths::fix($viewPaths[0]), strlen($basePath));
// variables
$app = app();
$data =
[
'route' => $config->route,
'assets' => $config->route . 'assets/',
'settings' =>
[
'route' => $config->route,
'basepath' => $basePath,
'basename' => $baseName,
'viewpath' => $viewPath,
'storagepath' => Paths::relative($config->settings->src),
'controllerpath' => trim(Paths::relative($finder->path), '/'),
'namespace' => method_exists($app, 'getNamespace')
? trim($app->getNamespace(), '\\')
: 'App\\',
'namespaces' => (new JSON('composer.json'))->get('autoload.psr-4')
]
];
// return view
return view('sketchpad::setup', $data);
} | php | public function view()
{
// default variables
$finder = new Finder();
$finder->start();
// config
$config = app(SketchpadConfig::class);
// base name
$basePath = Paths::fix(base_path('/'));
$baseSegments = explode('/', rtrim($basePath, '/'));
$baseName = array_pop($baseSegments) . '/';
// view path
$viewPaths = Config::get('view.paths');
$viewPath = substr(Paths::fix($viewPaths[0]), strlen($basePath));
// variables
$app = app();
$data =
[
'route' => $config->route,
'assets' => $config->route . 'assets/',
'settings' =>
[
'route' => $config->route,
'basepath' => $basePath,
'basename' => $baseName,
'viewpath' => $viewPath,
'storagepath' => Paths::relative($config->settings->src),
'controllerpath' => trim(Paths::relative($finder->path), '/'),
'namespace' => method_exists($app, 'getNamespace')
? trim($app->getNamespace(), '\\')
: 'App\\',
'namespaces' => (new JSON('composer.json'))->get('autoload.psr-4')
]
];
// return view
return view('sketchpad::setup', $data);
} | [
"public",
"function",
"view",
"(",
")",
"{",
"// default variables",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"start",
"(",
")",
";",
"// config",
"$",
"config",
"=",
"app",
"(",
"SketchpadConfig",
"::",
"class",
")",
";",
"// base name",
"$",
"basePath",
"=",
"Paths",
"::",
"fix",
"(",
"base_path",
"(",
"'/'",
")",
")",
";",
"$",
"baseSegments",
"=",
"explode",
"(",
"'/'",
",",
"rtrim",
"(",
"$",
"basePath",
",",
"'/'",
")",
")",
";",
"$",
"baseName",
"=",
"array_pop",
"(",
"$",
"baseSegments",
")",
".",
"'/'",
";",
"// view path",
"$",
"viewPaths",
"=",
"Config",
"::",
"get",
"(",
"'view.paths'",
")",
";",
"$",
"viewPath",
"=",
"substr",
"(",
"Paths",
"::",
"fix",
"(",
"$",
"viewPaths",
"[",
"0",
"]",
")",
",",
"strlen",
"(",
"$",
"basePath",
")",
")",
";",
"// variables",
"$",
"app",
"=",
"app",
"(",
")",
";",
"$",
"data",
"=",
"[",
"'route'",
"=>",
"$",
"config",
"->",
"route",
",",
"'assets'",
"=>",
"$",
"config",
"->",
"route",
".",
"'assets/'",
",",
"'settings'",
"=>",
"[",
"'route'",
"=>",
"$",
"config",
"->",
"route",
",",
"'basepath'",
"=>",
"$",
"basePath",
",",
"'basename'",
"=>",
"$",
"baseName",
",",
"'viewpath'",
"=>",
"$",
"viewPath",
",",
"'storagepath'",
"=>",
"Paths",
"::",
"relative",
"(",
"$",
"config",
"->",
"settings",
"->",
"src",
")",
",",
"'controllerpath'",
"=>",
"trim",
"(",
"Paths",
"::",
"relative",
"(",
"$",
"finder",
"->",
"path",
")",
",",
"'/'",
")",
",",
"'namespace'",
"=>",
"method_exists",
"(",
"$",
"app",
",",
"'getNamespace'",
")",
"?",
"trim",
"(",
"$",
"app",
"->",
"getNamespace",
"(",
")",
",",
"'\\\\'",
")",
":",
"'App\\\\'",
",",
"'namespaces'",
"=>",
"(",
"new",
"JSON",
"(",
"'composer.json'",
")",
")",
"->",
"get",
"(",
"'autoload.psr-4'",
")",
"]",
"]",
";",
"// return view",
"return",
"view",
"(",
"'sketchpad::setup'",
",",
"$",
"data",
")",
";",
"}"
] | Shows the setup form view
@return mixed | [
"Shows",
"the",
"setup",
"form",
"view"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/services/Setup.php#L44-L85 |
35,853 | davestewart/laravel-sketchpad | src/objects/file/Folder.php | Folder.process | public function process($recursive = false)
{
// reset
$this->folders = [];
$this->controllers = [];
// variables
$files = array_diff(scandir($this->path), ['.', '..']);
// loop
foreach ($files as $file)
{
$path = $this->path . $file;
if(is_dir($path))
{
$this->folders[] = new Folder($path, $recursive);
}
else if(is_file($path) && preg_match('/Controller.php$/', $path))
{
$this->controllers[] = new Controller($path);
}
}
} | php | public function process($recursive = false)
{
// reset
$this->folders = [];
$this->controllers = [];
// variables
$files = array_diff(scandir($this->path), ['.', '..']);
// loop
foreach ($files as $file)
{
$path = $this->path . $file;
if(is_dir($path))
{
$this->folders[] = new Folder($path, $recursive);
}
else if(is_file($path) && preg_match('/Controller.php$/', $path))
{
$this->controllers[] = new Controller($path);
}
}
} | [
"public",
"function",
"process",
"(",
"$",
"recursive",
"=",
"false",
")",
"{",
"// reset\r",
"$",
"this",
"->",
"folders",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"controllers",
"=",
"[",
"]",
";",
"// variables\r",
"$",
"files",
"=",
"array_diff",
"(",
"scandir",
"(",
"$",
"this",
"->",
"path",
")",
",",
"[",
"'.'",
",",
"'..'",
"]",
")",
";",
"// loop\r",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"path",
".",
"$",
"file",
";",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"folders",
"[",
"]",
"=",
"new",
"Folder",
"(",
"$",
"path",
",",
"$",
"recursive",
")",
";",
"}",
"else",
"if",
"(",
"is_file",
"(",
"$",
"path",
")",
"&&",
"preg_match",
"(",
"'/Controller.php$/'",
",",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"controllers",
"[",
"]",
"=",
"new",
"Controller",
"(",
"$",
"path",
")",
";",
"}",
"}",
"}"
] | Process contained folders and controllers
@param bool $recursive An optional flag to recursively get child folders | [
"Process",
"contained",
"folders",
"and",
"controllers"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/file/Folder.php#L71-L93 |
35,854 | davestewart/laravel-sketchpad | src/objects/install/FilesystemObject.php | FilesystemObject.makePath | protected function makePath($path)
{
$path = $this->fs->isAbsolutePath($path)
? $path
: base_path($path);
return Paths::fix($path);
} | php | protected function makePath($path)
{
$path = $this->fs->isAbsolutePath($path)
? $path
: base_path($path);
return Paths::fix($path);
} | [
"protected",
"function",
"makePath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"fs",
"->",
"isAbsolutePath",
"(",
"$",
"path",
")",
"?",
"$",
"path",
":",
"base_path",
"(",
"$",
"path",
")",
";",
"return",
"Paths",
"::",
"fix",
"(",
"$",
"path",
")",
";",
"}"
] | Utility function to return an absolute path from a relative or absolute path
@param $path
@return string | [
"Utility",
"function",
"to",
"return",
"an",
"absolute",
"path",
"from",
"a",
"relative",
"or",
"absolute",
"path"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/install/FilesystemObject.php#L24-L30 |
35,855 | davestewart/laravel-sketchpad | src/config/Paths.php | Paths.make | public static function make($path, $relative = false)
{
return $relative
? Paths::relative($path)
: Paths::fix($path);
} | php | public static function make($path, $relative = false)
{
return $relative
? Paths::relative($path)
: Paths::fix($path);
} | [
"public",
"static",
"function",
"make",
"(",
"$",
"path",
",",
"$",
"relative",
"=",
"false",
")",
"{",
"return",
"$",
"relative",
"?",
"Paths",
"::",
"relative",
"(",
"$",
"path",
")",
":",
"Paths",
"::",
"fix",
"(",
"$",
"path",
")",
";",
"}"
] | Utility method to create a path; fixing and optionally making relative to the base path
@param string $path The path to process
@param bool $relative An optional flag to return the path relative to the base path
@return string The final path | [
"Utility",
"method",
"to",
"create",
"a",
"path",
";",
"fixing",
"and",
"optionally",
"making",
"relative",
"to",
"the",
"base",
"path"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/config/Paths.php#L79-L84 |
35,856 | davestewart/laravel-sketchpad | src/config/Paths.php | Paths.folder | public static function folder($path, $relative = false)
{
$path = Paths::make($path, $relative);
return rtrim($path, '/') . '/';
} | php | public static function folder($path, $relative = false)
{
$path = Paths::make($path, $relative);
return rtrim($path, '/') . '/';
} | [
"public",
"static",
"function",
"folder",
"(",
"$",
"path",
",",
"$",
"relative",
"=",
"false",
")",
"{",
"$",
"path",
"=",
"Paths",
"::",
"make",
"(",
"$",
"path",
",",
"$",
"relative",
")",
";",
"return",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'/'",
";",
"}"
] | Utility method to return a path with a trailing slash
@param string $path The path to process
@param bool $relative An optional flag to return the path relative to the base path
@return string The final path | [
"Utility",
"method",
"to",
"return",
"a",
"path",
"with",
"a",
"trailing",
"slash"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/config/Paths.php#L104-L108 |
35,857 | davestewart/laravel-sketchpad | src/help/docs/OutputController.php | OutputController.pagination | public function pagination($start = 1, $length = 10)
{
// manually create paginator
$data = array_map(function ($num) {
return ['id' => $num, 'value' => "Item $num"];
}, range(1, 100));
$page = Paginator::resolveCurrentPage('page');
$path = Paginator::resolveCurrentPath();
$items = array_slice($data, abs($start - 1) + (($page - 1) * $length), $length);
$paginator = new LengthAwarePaginator($items, count($data), $length, $page, [
'path' => $path,
'pageName' => 'page',
]);
// append existing parameters
$paginator->appends(Sketchpad::$params);
// output
return view('sketchpad::help/output/pagination', compact('items', 'paginator'));
} | php | public function pagination($start = 1, $length = 10)
{
// manually create paginator
$data = array_map(function ($num) {
return ['id' => $num, 'value' => "Item $num"];
}, range(1, 100));
$page = Paginator::resolveCurrentPage('page');
$path = Paginator::resolveCurrentPath();
$items = array_slice($data, abs($start - 1) + (($page - 1) * $length), $length);
$paginator = new LengthAwarePaginator($items, count($data), $length, $page, [
'path' => $path,
'pageName' => 'page',
]);
// append existing parameters
$paginator->appends(Sketchpad::$params);
// output
return view('sketchpad::help/output/pagination', compact('items', 'paginator'));
} | [
"public",
"function",
"pagination",
"(",
"$",
"start",
"=",
"1",
",",
"$",
"length",
"=",
"10",
")",
"{",
"// manually create paginator",
"$",
"data",
"=",
"array_map",
"(",
"function",
"(",
"$",
"num",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"num",
",",
"'value'",
"=>",
"\"Item $num\"",
"]",
";",
"}",
",",
"range",
"(",
"1",
",",
"100",
")",
")",
";",
"$",
"page",
"=",
"Paginator",
"::",
"resolveCurrentPage",
"(",
"'page'",
")",
";",
"$",
"path",
"=",
"Paginator",
"::",
"resolveCurrentPath",
"(",
")",
";",
"$",
"items",
"=",
"array_slice",
"(",
"$",
"data",
",",
"abs",
"(",
"$",
"start",
"-",
"1",
")",
"+",
"(",
"(",
"$",
"page",
"-",
"1",
")",
"*",
"$",
"length",
")",
",",
"$",
"length",
")",
";",
"$",
"paginator",
"=",
"new",
"LengthAwarePaginator",
"(",
"$",
"items",
",",
"count",
"(",
"$",
"data",
")",
",",
"$",
"length",
",",
"$",
"page",
",",
"[",
"'path'",
"=>",
"$",
"path",
",",
"'pageName'",
"=>",
"'page'",
",",
"]",
")",
";",
"// append existing parameters",
"$",
"paginator",
"->",
"appends",
"(",
"Sketchpad",
"::",
"$",
"params",
")",
";",
"// output",
"return",
"view",
"(",
"'sketchpad::help/output/pagination'",
",",
"compact",
"(",
"'items'",
",",
"'paginator'",
")",
")",
";",
"}"
] | Sketchpad is designed to work invisibly with pagination, by preserving URL variables between front and back end
@param int $start
@param int $length | [
"Sketchpad",
"is",
"designed",
"to",
"work",
"invisibly",
"with",
"pagination",
"by",
"preserving",
"URL",
"variables",
"between",
"front",
"and",
"back",
"end"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/docs/OutputController.php#L134-L154 |
35,858 | davestewart/laravel-sketchpad | src/objects/reflection/Comment.php | Comment.getField | public function getField($name)
{
return isset($this->fields[$name])
? $this->fields[$name]
: null;
} | php | public function getField($name)
{
return isset($this->fields[$name])
? $this->fields[$name]
: null;
} | [
"public",
"function",
"getField",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | Returns a field by name
@param string $name
@return Field|null | [
"Returns",
"a",
"field",
"by",
"name"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/reflection/Comment.php#L175-L180 |
35,859 | davestewart/laravel-sketchpad | src/objects/reflection/Parameter.php | Parameter.getType | protected function getType($param, $value, $type = null)
{
// attempt to get the type
$type = method_exists($param, 'getType')
? $param->getType()
: $type
? $type
: gettype($value);
// coerce type to something javascript will understand
if($type == 'double' || $type == 'float' || $type == 'integer' || $type == 'int')
{
$type = 'number';
}
else if($type == 'bool')
{
$type = 'boolean';
}
else if($type == 'NULL')
{
$type = 'null';
}
// return
return $type;
} | php | protected function getType($param, $value, $type = null)
{
// attempt to get the type
$type = method_exists($param, 'getType')
? $param->getType()
: $type
? $type
: gettype($value);
// coerce type to something javascript will understand
if($type == 'double' || $type == 'float' || $type == 'integer' || $type == 'int')
{
$type = 'number';
}
else if($type == 'bool')
{
$type = 'boolean';
}
else if($type == 'NULL')
{
$type = 'null';
}
// return
return $type;
} | [
"protected",
"function",
"getType",
"(",
"$",
"param",
",",
"$",
"value",
",",
"$",
"type",
"=",
"null",
")",
"{",
"// attempt to get the type\r",
"$",
"type",
"=",
"method_exists",
"(",
"$",
"param",
",",
"'getType'",
")",
"?",
"$",
"param",
"->",
"getType",
"(",
")",
":",
"$",
"type",
"?",
"$",
"type",
":",
"gettype",
"(",
"$",
"value",
")",
";",
"// coerce type to something javascript will understand\r",
"if",
"(",
"$",
"type",
"==",
"'double'",
"||",
"$",
"type",
"==",
"'float'",
"||",
"$",
"type",
"==",
"'integer'",
"||",
"$",
"type",
"==",
"'int'",
")",
"{",
"$",
"type",
"=",
"'number'",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"==",
"'bool'",
")",
"{",
"$",
"type",
"=",
"'boolean'",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"==",
"'NULL'",
")",
"{",
"$",
"type",
"=",
"'null'",
";",
"}",
"// return\r",
"return",
"$",
"type",
";",
"}"
] | Gets the parameter type
@param ReflectionParameter $param
@param mixed $value
@param string $type
@return string | [
"Gets",
"the",
"parameter",
"type"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/reflection/Parameter.php#L111-L136 |
35,860 | davestewart/laravel-sketchpad | src/controllers/SetupController.php | SetupController.submit | public function submit(Request $request)
{
$input = $request->all();
$state = $this->setup->saveData($input);
$result = [
'step' => 'config',
'success' => $state,
'message' => $state ? 'Config saved OK' : 'Unable to save config',
'data' => $input
];
if($state)
{
return $this->install();
}
return $result;
} | php | public function submit(Request $request)
{
$input = $request->all();
$state = $this->setup->saveData($input);
$result = [
'step' => 'config',
'success' => $state,
'message' => $state ? 'Config saved OK' : 'Unable to save config',
'data' => $input
];
if($state)
{
return $this->install();
}
return $result;
} | [
"public",
"function",
"submit",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"input",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"setup",
"->",
"saveData",
"(",
"$",
"input",
")",
";",
"$",
"result",
"=",
"[",
"'step'",
"=>",
"'config'",
",",
"'success'",
"=>",
"$",
"state",
",",
"'message'",
"=>",
"$",
"state",
"?",
"'Config saved OK'",
":",
"'Unable to save config'",
",",
"'data'",
"=>",
"$",
"input",
"]",
";",
"if",
"(",
"$",
"state",
")",
"{",
"return",
"$",
"this",
"->",
"install",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Handles form data from the setup controller
@method POST
@param Request $request
@return array | [
"Handles",
"form",
"data",
"from",
"the",
"setup",
"controller"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/controllers/SetupController.php#L75-L90 |
35,861 | davestewart/laravel-sketchpad | src/objects/scanners/Scanner.php | Scanner.scan | protected function scan($path = '')
{
// add folder
$this->addFolder($path);
// get elements
$root = AbstractScanner::folderize($this->path . $path);
$els = array_diff(scandir($root), ['.', '..']);
// split elements
$files = [];
$folders = [];
foreach ($els as $el)
{
is_dir($root . $el)
? array_push($folders, $el)
: array_push($files, $el);
}
// get all controllers
$controllers = [];
$ordered = [];
foreach ($files as $file)
{
$abspath = $root . $file;
if($this->isController($abspath))
{
$controller = $this->addController($abspath, $path);
if ($controller)
{
property_exists($controller, 'order') && $controller->order !== 0
? array_push($ordered, $controller)
: array_push($controllers, $controller);
}
}
}
// re-insert ordered controllers
uasort($ordered, function ($a, $b) { return $a->order - $b->order; });
foreach($ordered as $c)
{
array_splice($controllers, $c->order - 1, 0, [$c]);
}
// add controllers
$this->controllers = array_merge($this->controllers, array_values($controllers));
// folders
foreach ($folders as $folder)
{
$relpath = $path . $folder;
$this->scan($relpath . '/');
}
} | php | protected function scan($path = '')
{
// add folder
$this->addFolder($path);
// get elements
$root = AbstractScanner::folderize($this->path . $path);
$els = array_diff(scandir($root), ['.', '..']);
// split elements
$files = [];
$folders = [];
foreach ($els as $el)
{
is_dir($root . $el)
? array_push($folders, $el)
: array_push($files, $el);
}
// get all controllers
$controllers = [];
$ordered = [];
foreach ($files as $file)
{
$abspath = $root . $file;
if($this->isController($abspath))
{
$controller = $this->addController($abspath, $path);
if ($controller)
{
property_exists($controller, 'order') && $controller->order !== 0
? array_push($ordered, $controller)
: array_push($controllers, $controller);
}
}
}
// re-insert ordered controllers
uasort($ordered, function ($a, $b) { return $a->order - $b->order; });
foreach($ordered as $c)
{
array_splice($controllers, $c->order - 1, 0, [$c]);
}
// add controllers
$this->controllers = array_merge($this->controllers, array_values($controllers));
// folders
foreach ($folders as $folder)
{
$relpath = $path . $folder;
$this->scan($relpath . '/');
}
} | [
"protected",
"function",
"scan",
"(",
"$",
"path",
"=",
"''",
")",
"{",
"// add folder",
"$",
"this",
"->",
"addFolder",
"(",
"$",
"path",
")",
";",
"// get elements",
"$",
"root",
"=",
"AbstractScanner",
"::",
"folderize",
"(",
"$",
"this",
"->",
"path",
".",
"$",
"path",
")",
";",
"$",
"els",
"=",
"array_diff",
"(",
"scandir",
"(",
"$",
"root",
")",
",",
"[",
"'.'",
",",
"'..'",
"]",
")",
";",
"// split elements",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"folders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"els",
"as",
"$",
"el",
")",
"{",
"is_dir",
"(",
"$",
"root",
".",
"$",
"el",
")",
"?",
"array_push",
"(",
"$",
"folders",
",",
"$",
"el",
")",
":",
"array_push",
"(",
"$",
"files",
",",
"$",
"el",
")",
";",
"}",
"// get all controllers",
"$",
"controllers",
"=",
"[",
"]",
";",
"$",
"ordered",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"abspath",
"=",
"$",
"root",
".",
"$",
"file",
";",
"if",
"(",
"$",
"this",
"->",
"isController",
"(",
"$",
"abspath",
")",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"addController",
"(",
"$",
"abspath",
",",
"$",
"path",
")",
";",
"if",
"(",
"$",
"controller",
")",
"{",
"property_exists",
"(",
"$",
"controller",
",",
"'order'",
")",
"&&",
"$",
"controller",
"->",
"order",
"!==",
"0",
"?",
"array_push",
"(",
"$",
"ordered",
",",
"$",
"controller",
")",
":",
"array_push",
"(",
"$",
"controllers",
",",
"$",
"controller",
")",
";",
"}",
"}",
"}",
"// re-insert ordered controllers",
"uasort",
"(",
"$",
"ordered",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"$",
"a",
"->",
"order",
"-",
"$",
"b",
"->",
"order",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"ordered",
"as",
"$",
"c",
")",
"{",
"array_splice",
"(",
"$",
"controllers",
",",
"$",
"c",
"->",
"order",
"-",
"1",
",",
"0",
",",
"[",
"$",
"c",
"]",
")",
";",
"}",
"// add controllers",
"$",
"this",
"->",
"controllers",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"controllers",
",",
"array_values",
"(",
"$",
"controllers",
")",
")",
";",
"// folders",
"foreach",
"(",
"$",
"folders",
"as",
"$",
"folder",
")",
"{",
"$",
"relpath",
"=",
"$",
"path",
".",
"$",
"folder",
";",
"$",
"this",
"->",
"scan",
"(",
"$",
"relpath",
".",
"'/'",
")",
";",
"}",
"}"
] | Recursively finds all controllers and folders
Sets controllers and folders elements as they are found
@param string $path The sketchpad controllers path-relative path to the folder, i.e. "foo/bar/" | [
"Recursively",
"finds",
"all",
"controllers",
"and",
"folders"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/scanners/Scanner.php#L96-L150 |
35,862 | davestewart/laravel-sketchpad | src/objects/scanners/Scanner.php | Scanner.addFolder | protected function addFolder($path)
{
$route = rtrim($this->route . $path, '/');
$ref = new FolderReference($route, $this->path . $path);
$this->addRoute($route, $ref);
} | php | protected function addFolder($path)
{
$route = rtrim($this->route . $path, '/');
$ref = new FolderReference($route, $this->path . $path);
$this->addRoute($route, $ref);
} | [
"protected",
"function",
"addFolder",
"(",
"$",
"path",
")",
"{",
"$",
"route",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"route",
".",
"$",
"path",
",",
"'/'",
")",
";",
"$",
"ref",
"=",
"new",
"FolderReference",
"(",
"$",
"route",
",",
"$",
"this",
"->",
"path",
".",
"$",
"path",
")",
";",
"$",
"this",
"->",
"addRoute",
"(",
"$",
"route",
",",
"$",
"ref",
")",
";",
"}"
] | Adds a folder to the internal routes array
@param string $path The controller-root relative path to the folder | [
"Adds",
"a",
"folder",
"to",
"the",
"internal",
"routes",
"array"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/scanners/Scanner.php#L157-L162 |
35,863 | davestewart/laravel-sketchpad | src/objects/scanners/Scanner.php | Scanner.addController | protected function addController($abspath, $route)
{
// variables
$name = pathinfo($abspath, PATHINFO_FILENAME);
$segment = preg_replace('/Controller$/', '', $name);
$route = strtolower($this->route . $route . $segment);
// objects
$instance = Controller::fromPath($abspath, $route);
// add
if($instance instanceof Controller)
{
// controller isn't abstract, has methods, isn't private
if ($instance->isValid())
{
$ref = $instance->getReference();
$this->addRoute($route, $ref);
return $instance;
}
}
else
{
$ref = $instance->getReference();
$this->addRoute($route, $ref);
return $instance;
}
} | php | protected function addController($abspath, $route)
{
// variables
$name = pathinfo($abspath, PATHINFO_FILENAME);
$segment = preg_replace('/Controller$/', '', $name);
$route = strtolower($this->route . $route . $segment);
// objects
$instance = Controller::fromPath($abspath, $route);
// add
if($instance instanceof Controller)
{
// controller isn't abstract, has methods, isn't private
if ($instance->isValid())
{
$ref = $instance->getReference();
$this->addRoute($route, $ref);
return $instance;
}
}
else
{
$ref = $instance->getReference();
$this->addRoute($route, $ref);
return $instance;
}
} | [
"protected",
"function",
"addController",
"(",
"$",
"abspath",
",",
"$",
"route",
")",
"{",
"// variables",
"$",
"name",
"=",
"pathinfo",
"(",
"$",
"abspath",
",",
"PATHINFO_FILENAME",
")",
";",
"$",
"segment",
"=",
"preg_replace",
"(",
"'/Controller$/'",
",",
"''",
",",
"$",
"name",
")",
";",
"$",
"route",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"route",
".",
"$",
"route",
".",
"$",
"segment",
")",
";",
"// objects",
"$",
"instance",
"=",
"Controller",
"::",
"fromPath",
"(",
"$",
"abspath",
",",
"$",
"route",
")",
";",
"// add",
"if",
"(",
"$",
"instance",
"instanceof",
"Controller",
")",
"{",
"// controller isn't abstract, has methods, isn't private",
"if",
"(",
"$",
"instance",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"ref",
"=",
"$",
"instance",
"->",
"getReference",
"(",
")",
";",
"$",
"this",
"->",
"addRoute",
"(",
"$",
"route",
",",
"$",
"ref",
")",
";",
"return",
"$",
"instance",
";",
"}",
"}",
"else",
"{",
"$",
"ref",
"=",
"$",
"instance",
"->",
"getReference",
"(",
")",
";",
"$",
"this",
"->",
"addRoute",
"(",
"$",
"route",
",",
"$",
"ref",
")",
";",
"return",
"$",
"instance",
";",
"}",
"}"
] | Adds a controller to the internal routes array
@param string $abspath
@param string $route
@return Controller|\davestewart\sketchpad\objects\reflection\ControllerError | [
"Adds",
"a",
"controller",
"to",
"the",
"internal",
"routes",
"array"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/scanners/Scanner.php#L171-L199 |
35,864 | davestewart/laravel-sketchpad | src/objects/install/NamespaceResolver.php | NamespaceResolver.loadNamespaces | public function loadNamespaces()
{
$data = json_decode(file_get_contents(base_path('composer.json')), JSON_OBJECT_AS_ARRAY);
$namespaces = array_get($data, 'autoload.psr-4');
$this->setNamespaces($namespaces);
return $this;
} | php | public function loadNamespaces()
{
$data = json_decode(file_get_contents(base_path('composer.json')), JSON_OBJECT_AS_ARRAY);
$namespaces = array_get($data, 'autoload.psr-4');
$this->setNamespaces($namespaces);
return $this;
} | [
"public",
"function",
"loadNamespaces",
"(",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"base_path",
"(",
"'composer.json'",
")",
")",
",",
"JSON_OBJECT_AS_ARRAY",
")",
";",
"$",
"namespaces",
"=",
"array_get",
"(",
"$",
"data",
",",
"'autoload.psr-4'",
")",
";",
"$",
"this",
"->",
"setNamespaces",
"(",
"$",
"namespaces",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Loads namespaces from composer.json
@return $this | [
"Loads",
"namespaces",
"from",
"composer",
".",
"json"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/install/NamespaceResolver.php#L25-L31 |
35,865 | davestewart/laravel-sketchpad | src/objects/install/NamespaceResolver.php | NamespaceResolver.getNamespace | public function getNamespace($file, $defaultToPath = false)
{
// massage file path into a format compatible with PSR-4 entries
$file = str_replace('\\', '/', $file);
$base = str_replace('\\', '/', base_path()) . '/';
$file = str_replace($base, '', $file);
// compare file path against existing entries
foreach($this->namespaces as $ns => $path)
{
// convert paths to all use forward slashes
$path = str_replace('\\', '/', $path);
// if the file starts with the namespace path
if(strpos($file, $path) === 0)
{
$file = substr($file, strlen($path));
$file = preg_replace('%/[^/]+$%', '', $file);
$file = str_replace('/', '\\', $file);
// defensive trim, in case any double slashes
return trim($ns . $file, '\\');
}
}
// namespace could not be resolved
$info = pathinfo($file);
return $defaultToPath
? str_replace('/', '\\', $info['dirname'])
: null;
} | php | public function getNamespace($file, $defaultToPath = false)
{
// massage file path into a format compatible with PSR-4 entries
$file = str_replace('\\', '/', $file);
$base = str_replace('\\', '/', base_path()) . '/';
$file = str_replace($base, '', $file);
// compare file path against existing entries
foreach($this->namespaces as $ns => $path)
{
// convert paths to all use forward slashes
$path = str_replace('\\', '/', $path);
// if the file starts with the namespace path
if(strpos($file, $path) === 0)
{
$file = substr($file, strlen($path));
$file = preg_replace('%/[^/]+$%', '', $file);
$file = str_replace('/', '\\', $file);
// defensive trim, in case any double slashes
return trim($ns . $file, '\\');
}
}
// namespace could not be resolved
$info = pathinfo($file);
return $defaultToPath
? str_replace('/', '\\', $info['dirname'])
: null;
} | [
"public",
"function",
"getNamespace",
"(",
"$",
"file",
",",
"$",
"defaultToPath",
"=",
"false",
")",
"{",
"// massage file path into a format compatible with PSR-4 entries",
"$",
"file",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"file",
")",
";",
"$",
"base",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"base_path",
"(",
")",
")",
".",
"'/'",
";",
"$",
"file",
"=",
"str_replace",
"(",
"$",
"base",
",",
"''",
",",
"$",
"file",
")",
";",
"// compare file path against existing entries",
"foreach",
"(",
"$",
"this",
"->",
"namespaces",
"as",
"$",
"ns",
"=>",
"$",
"path",
")",
"{",
"// convert paths to all use forward slashes",
"$",
"path",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
";",
"// if the file starts with the namespace path",
"if",
"(",
"strpos",
"(",
"$",
"file",
",",
"$",
"path",
")",
"===",
"0",
")",
"{",
"$",
"file",
"=",
"substr",
"(",
"$",
"file",
",",
"strlen",
"(",
"$",
"path",
")",
")",
";",
"$",
"file",
"=",
"preg_replace",
"(",
"'%/[^/]+$%'",
",",
"''",
",",
"$",
"file",
")",
";",
"$",
"file",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"file",
")",
";",
"// defensive trim, in case any double slashes",
"return",
"trim",
"(",
"$",
"ns",
".",
"$",
"file",
",",
"'\\\\'",
")",
";",
"}",
"}",
"// namespace could not be resolved",
"$",
"info",
"=",
"pathinfo",
"(",
"$",
"file",
")",
";",
"return",
"$",
"defaultToPath",
"?",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"info",
"[",
"'dirname'",
"]",
")",
":",
"null",
";",
"}"
] | Attempts to get the namespace for a file
@param string $file base-relative file path
@param bool $defaultToPath flag to use file path as namespace if namespace cannot be matched
@return null|string | [
"Attempts",
"to",
"get",
"the",
"namespace",
"for",
"a",
"file"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/objects/install/NamespaceResolver.php#L52-L84 |
35,866 | davestewart/laravel-sketchpad | src/help/docs/TagsController.php | TagsController.field | public function field($select = 1, $range = 0, $date = '2015-01-01', $color = 'ff0000')
{
$splits =
[
[
'operator' => '<code>|</code>',
'grouping' => 'attributes',
'example' => '<code>min:0|max:100</code>',
],
[
'operator' => '<code>:</code>',
'grouping' => 'attribute name / attribute value',
'example' => '<code>step:5</code>',
],
[
'operator' => '<code>,</code>',
'grouping' => 'options (<code>select</code> and <code>datalist</code> only)',
'example' => '<code>foo,bar,baz</code>',
],
[
'operator' => '<code>=</code>',
'grouping' => 'option text / option value',
'example' => '<code>Yes=1</code>',
],
];
$format = 'html:example|cols:100,400,200';
$params = Sketchpad::$params;
return view('sketchpad::help/tags/field', compact('types', 'attributes', 'format', 'params', 'splits'));
} | php | public function field($select = 1, $range = 0, $date = '2015-01-01', $color = 'ff0000')
{
$splits =
[
[
'operator' => '<code>|</code>',
'grouping' => 'attributes',
'example' => '<code>min:0|max:100</code>',
],
[
'operator' => '<code>:</code>',
'grouping' => 'attribute name / attribute value',
'example' => '<code>step:5</code>',
],
[
'operator' => '<code>,</code>',
'grouping' => 'options (<code>select</code> and <code>datalist</code> only)',
'example' => '<code>foo,bar,baz</code>',
],
[
'operator' => '<code>=</code>',
'grouping' => 'option text / option value',
'example' => '<code>Yes=1</code>',
],
];
$format = 'html:example|cols:100,400,200';
$params = Sketchpad::$params;
return view('sketchpad::help/tags/field', compact('types', 'attributes', 'format', 'params', 'splits'));
} | [
"public",
"function",
"field",
"(",
"$",
"select",
"=",
"1",
",",
"$",
"range",
"=",
"0",
",",
"$",
"date",
"=",
"'2015-01-01'",
",",
"$",
"color",
"=",
"'ff0000'",
")",
"{",
"$",
"splits",
"=",
"[",
"[",
"'operator'",
"=>",
"'<code>|</code>'",
",",
"'grouping'",
"=>",
"'attributes'",
",",
"'example'",
"=>",
"'<code>min:0|max:100</code>'",
",",
"]",
",",
"[",
"'operator'",
"=>",
"'<code>:</code>'",
",",
"'grouping'",
"=>",
"'attribute name / attribute value'",
",",
"'example'",
"=>",
"'<code>step:5</code>'",
",",
"]",
",",
"[",
"'operator'",
"=>",
"'<code>,</code>'",
",",
"'grouping'",
"=>",
"'options (<code>select</code> and <code>datalist</code> only)'",
",",
"'example'",
"=>",
"'<code>foo,bar,baz</code>'",
",",
"]",
",",
"[",
"'operator'",
"=>",
"'<code>=</code>'",
",",
"'grouping'",
"=>",
"'option text / option value'",
",",
"'example'",
"=>",
"'<code>Yes=1</code>'",
",",
"]",
",",
"]",
";",
"$",
"format",
"=",
"'html:example|cols:100,400,200'",
";",
"$",
"params",
"=",
"Sketchpad",
"::",
"$",
"params",
";",
"return",
"view",
"(",
"'sketchpad::help/tags/field'",
",",
"compact",
"(",
"'types'",
",",
"'attributes'",
",",
"'format'",
",",
"'params'",
",",
"'splits'",
")",
")",
";",
"}"
] | Override basic HTML inputs with more complex HTML input types and attributes
@group Input / Output
@param int $select
@field select $select options:One=1,Two=2,Three=3
@param int $range
@field number $range min:0|max:100|step:5
@param string $date
@field date $date
@param string $color
@field color $color | [
"Override",
"basic",
"HTML",
"inputs",
"with",
"more",
"complex",
"HTML",
"input",
"types",
"and",
"attributes"
] | ebd3365265f8844f7d400d7d530605512a20011c | https://github.com/davestewart/laravel-sketchpad/blob/ebd3365265f8844f7d400d7d530605512a20011c/src/help/docs/TagsController.php#L113-L144 |
35,867 | thecatontheflat/atlassian-connect-bundle | Service/JWTGenerator.php | JWTGenerator.generate | public static function generate(RequestInterface $request, string $issuer, string $secret): string
{
$data = [
'iss' => $issuer,
'iat' => \time(),
'exp' => \strtotime('+1 day'),
'qsh' => QSHGenerator::generate((string) $request->getUri(), $request->getMethod()),
];
return JWT::encode($data, $secret);
} | php | public static function generate(RequestInterface $request, string $issuer, string $secret): string
{
$data = [
'iss' => $issuer,
'iat' => \time(),
'exp' => \strtotime('+1 day'),
'qsh' => QSHGenerator::generate((string) $request->getUri(), $request->getMethod()),
];
return JWT::encode($data, $secret);
} | [
"public",
"static",
"function",
"generate",
"(",
"RequestInterface",
"$",
"request",
",",
"string",
"$",
"issuer",
",",
"string",
"$",
"secret",
")",
":",
"string",
"{",
"$",
"data",
"=",
"[",
"'iss'",
"=>",
"$",
"issuer",
",",
"'iat'",
"=>",
"\\",
"time",
"(",
")",
",",
"'exp'",
"=>",
"\\",
"strtotime",
"(",
"'+1 day'",
")",
",",
"'qsh'",
"=>",
"QSHGenerator",
"::",
"generate",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
",",
"]",
";",
"return",
"JWT",
"::",
"encode",
"(",
"$",
"data",
",",
"$",
"secret",
")",
";",
"}"
] | Create JWT token used by Atlassian REST API request
@param RequestInterface $request
@param string $issuer Key of the add-on
@param string $secret Shared secret of the Tenant
@return string | [
"Create",
"JWT",
"token",
"used",
"by",
"Atlassian",
"REST",
"API",
"request"
] | 4691ae2410eb55dce1140733f5f6821b6f230ca8 | https://github.com/thecatontheflat/atlassian-connect-bundle/blob/4691ae2410eb55dce1140733f5f6821b6f230ca8/Service/JWTGenerator.php#L22-L32 |
35,868 | thecatontheflat/atlassian-connect-bundle | Service/GuzzleJWTMiddleware.php | GuzzleJWTMiddleware.authTokenMiddleware | public static function authTokenMiddleware(string $issuer, string $secret): callable
{
return Middleware::mapRequest(
function (RequestInterface $request) use ($issuer, $secret) {
return new Request(
$request->getMethod(),
$request->getUri(),
\array_merge($request->getHeaders(), ['Authorization' => 'JWT '.JWTGenerator::generate($request, $issuer, $secret)]),
$request->getBody()
);
}
);
} | php | public static function authTokenMiddleware(string $issuer, string $secret): callable
{
return Middleware::mapRequest(
function (RequestInterface $request) use ($issuer, $secret) {
return new Request(
$request->getMethod(),
$request->getUri(),
\array_merge($request->getHeaders(), ['Authorization' => 'JWT '.JWTGenerator::generate($request, $issuer, $secret)]),
$request->getBody()
);
}
);
} | [
"public",
"static",
"function",
"authTokenMiddleware",
"(",
"string",
"$",
"issuer",
",",
"string",
"$",
"secret",
")",
":",
"callable",
"{",
"return",
"Middleware",
"::",
"mapRequest",
"(",
"function",
"(",
"RequestInterface",
"$",
"request",
")",
"use",
"(",
"$",
"issuer",
",",
"$",
"secret",
")",
"{",
"return",
"new",
"Request",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"\\",
"array_merge",
"(",
"$",
"request",
"->",
"getHeaders",
"(",
")",
",",
"[",
"'Authorization'",
"=>",
"'JWT '",
".",
"JWTGenerator",
"::",
"generate",
"(",
"$",
"request",
",",
"$",
"issuer",
",",
"$",
"secret",
")",
"]",
")",
",",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] | JWT Authentication middleware for Guzzle
@param string $issuer Add-on key in most cases
@param string $secret Shared secret
@return callable | [
"JWT",
"Authentication",
"middleware",
"for",
"Guzzle"
] | 4691ae2410eb55dce1140733f5f6821b6f230ca8 | https://github.com/thecatontheflat/atlassian-connect-bundle/blob/4691ae2410eb55dce1140733f5f6821b6f230ca8/Service/GuzzleJWTMiddleware.php#L23-L35 |
35,869 | summerblue/laravel-taggable | src/Model/Tag.php | Tag.scopeByTagName | public function scopeByTagName($query, $tag_name)
{
// mormalize string
$tag_name = app(TaggingUtility::class)->normalizeTagName(trim($tag_name));
return $query->where('name', $tag_name);
} | php | public function scopeByTagName($query, $tag_name)
{
// mormalize string
$tag_name = app(TaggingUtility::class)->normalizeTagName(trim($tag_name));
return $query->where('name', $tag_name);
} | [
"public",
"function",
"scopeByTagName",
"(",
"$",
"query",
",",
"$",
"tag_name",
")",
"{",
"// mormalize string",
"$",
"tag_name",
"=",
"app",
"(",
"TaggingUtility",
"::",
"class",
")",
"->",
"normalizeTagName",
"(",
"trim",
"(",
"$",
"tag_name",
")",
")",
";",
"return",
"$",
"query",
"->",
"where",
"(",
"'name'",
",",
"$",
"tag_name",
")",
";",
"}"
] | Get one Tag item by tag name | [
"Get",
"one",
"Tag",
"item",
"by",
"tag",
"name"
] | 35125bdc29d6d454c91ab65c457a9d8bdc1f7b86 | https://github.com/summerblue/laravel-taggable/blob/35125bdc29d6d454c91ab65c457a9d8bdc1f7b86/src/Model/Tag.php#L108-L113 |
35,870 | summerblue/laravel-taggable | src/Model/Tag.php | Tag.scopeByTagNames | public function scopeByTagNames($query, $tag_names)
{
$normalize_tag_names = [];
foreach ($tag_names as $tag_name) {
// mormalize string
$normalize_tag_names[] = app(TaggingUtility::class)->normalizeTagName(trim($tag_name));
}
return $query->whereIn('name', $normalize_tag_names);
} | php | public function scopeByTagNames($query, $tag_names)
{
$normalize_tag_names = [];
foreach ($tag_names as $tag_name) {
// mormalize string
$normalize_tag_names[] = app(TaggingUtility::class)->normalizeTagName(trim($tag_name));
}
return $query->whereIn('name', $normalize_tag_names);
} | [
"public",
"function",
"scopeByTagNames",
"(",
"$",
"query",
",",
"$",
"tag_names",
")",
"{",
"$",
"normalize_tag_names",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tag_names",
"as",
"$",
"tag_name",
")",
"{",
"// mormalize string",
"$",
"normalize_tag_names",
"[",
"]",
"=",
"app",
"(",
"TaggingUtility",
"::",
"class",
")",
"->",
"normalizeTagName",
"(",
"trim",
"(",
"$",
"tag_name",
")",
")",
";",
"}",
"return",
"$",
"query",
"->",
"whereIn",
"(",
"'name'",
",",
"$",
"normalize_tag_names",
")",
";",
"}"
] | Get Tag collection by tag name array | [
"Get",
"Tag",
"collection",
"by",
"tag",
"name",
"array"
] | 35125bdc29d6d454c91ab65c457a9d8bdc1f7b86 | https://github.com/summerblue/laravel-taggable/blob/35125bdc29d6d454c91ab65c457a9d8bdc1f7b86/src/Model/Tag.php#L121-L129 |
35,871 | thecatontheflat/atlassian-connect-bundle | Service/AtlassianRestClient.php | AtlassianRestClient.createClient | private function createClient(): Client
{
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
if ($this->user === null) {
$stack->push(GuzzleJWTMiddleware::authTokenMiddleware(
$this->tenant->getAddonKey(),
$this->tenant->getSharedSecret()
));
} else {
$stack->push(GuzzleJWTMiddleware::authUserTokenMiddleware(
$this->tenant->getOauthClientId(),
$this->tenant->getSharedSecret(),
$this->tenant->getBaseUrl(),
$this->user
));
}
return new Client(['handler' => $stack]);
} | php | private function createClient(): Client
{
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
if ($this->user === null) {
$stack->push(GuzzleJWTMiddleware::authTokenMiddleware(
$this->tenant->getAddonKey(),
$this->tenant->getSharedSecret()
));
} else {
$stack->push(GuzzleJWTMiddleware::authUserTokenMiddleware(
$this->tenant->getOauthClientId(),
$this->tenant->getSharedSecret(),
$this->tenant->getBaseUrl(),
$this->user
));
}
return new Client(['handler' => $stack]);
} | [
"private",
"function",
"createClient",
"(",
")",
":",
"Client",
"{",
"$",
"stack",
"=",
"new",
"HandlerStack",
"(",
")",
";",
"$",
"stack",
"->",
"setHandler",
"(",
"new",
"CurlHandler",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"user",
"===",
"null",
")",
"{",
"$",
"stack",
"->",
"push",
"(",
"GuzzleJWTMiddleware",
"::",
"authTokenMiddleware",
"(",
"$",
"this",
"->",
"tenant",
"->",
"getAddonKey",
"(",
")",
",",
"$",
"this",
"->",
"tenant",
"->",
"getSharedSecret",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"stack",
"->",
"push",
"(",
"GuzzleJWTMiddleware",
"::",
"authUserTokenMiddleware",
"(",
"$",
"this",
"->",
"tenant",
"->",
"getOauthClientId",
"(",
")",
",",
"$",
"this",
"->",
"tenant",
"->",
"getSharedSecret",
"(",
")",
",",
"$",
"this",
"->",
"tenant",
"->",
"getBaseUrl",
"(",
")",
",",
"$",
"this",
"->",
"user",
")",
")",
";",
"}",
"return",
"new",
"Client",
"(",
"[",
"'handler'",
"=>",
"$",
"stack",
"]",
")",
";",
"}"
] | Create a HTTP client
@return Client | [
"Create",
"a",
"HTTP",
"client"
] | 4691ae2410eb55dce1140733f5f6821b6f230ca8 | https://github.com/thecatontheflat/atlassian-connect-bundle/blob/4691ae2410eb55dce1140733f5f6821b6f230ca8/Service/AtlassianRestClient.php#L151-L171 |
35,872 | thecatontheflat/atlassian-connect-bundle | Service/QSHGenerator.php | QSHGenerator.generate | public static function generate(string $url, string $method): string
{
$parts = \parse_url($url);
// Remove "/wiki" part from the path for the Confluence
// Really, I didn't find this part in the docs, but it works
$path = \str_replace('/wiki', '', $parts['path']);
$canonicalQuery = '';
if (!empty($parts['query'])) {
$query = $parts['query'];
$queryParts = \explode('&', $query);
$queryArray = [];
foreach ($queryParts as $queryPart) {
$pieces = \explode('=', $queryPart);
$key = \array_shift($pieces);
$key = \rawurlencode($key);
$value = \mb_substr($queryPart, \mb_strlen($key) + 1);
$value = \rawurlencode($value);
$queryArray[$key][] = $value;
}
\ksort($queryArray);
foreach ($queryArray as $key => $pieceOfQuery) {
$pieceOfQuery = \implode(',', $pieceOfQuery);
$canonicalQuery .= $key.'='.$pieceOfQuery.'&';
}
$canonicalQuery = \rtrim($canonicalQuery, '&');
}
return \hash('sha256', \implode('&', [\mb_strtoupper($method), $path, $canonicalQuery]));
} | php | public static function generate(string $url, string $method): string
{
$parts = \parse_url($url);
// Remove "/wiki" part from the path for the Confluence
// Really, I didn't find this part in the docs, but it works
$path = \str_replace('/wiki', '', $parts['path']);
$canonicalQuery = '';
if (!empty($parts['query'])) {
$query = $parts['query'];
$queryParts = \explode('&', $query);
$queryArray = [];
foreach ($queryParts as $queryPart) {
$pieces = \explode('=', $queryPart);
$key = \array_shift($pieces);
$key = \rawurlencode($key);
$value = \mb_substr($queryPart, \mb_strlen($key) + 1);
$value = \rawurlencode($value);
$queryArray[$key][] = $value;
}
\ksort($queryArray);
foreach ($queryArray as $key => $pieceOfQuery) {
$pieceOfQuery = \implode(',', $pieceOfQuery);
$canonicalQuery .= $key.'='.$pieceOfQuery.'&';
}
$canonicalQuery = \rtrim($canonicalQuery, '&');
}
return \hash('sha256', \implode('&', [\mb_strtoupper($method), $path, $canonicalQuery]));
} | [
"public",
"static",
"function",
"generate",
"(",
"string",
"$",
"url",
",",
"string",
"$",
"method",
")",
":",
"string",
"{",
"$",
"parts",
"=",
"\\",
"parse_url",
"(",
"$",
"url",
")",
";",
"// Remove \"/wiki\" part from the path for the Confluence",
"// Really, I didn't find this part in the docs, but it works",
"$",
"path",
"=",
"\\",
"str_replace",
"(",
"'/wiki'",
",",
"''",
",",
"$",
"parts",
"[",
"'path'",
"]",
")",
";",
"$",
"canonicalQuery",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"query",
"=",
"$",
"parts",
"[",
"'query'",
"]",
";",
"$",
"queryParts",
"=",
"\\",
"explode",
"(",
"'&'",
",",
"$",
"query",
")",
";",
"$",
"queryArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"queryParts",
"as",
"$",
"queryPart",
")",
"{",
"$",
"pieces",
"=",
"\\",
"explode",
"(",
"'='",
",",
"$",
"queryPart",
")",
";",
"$",
"key",
"=",
"\\",
"array_shift",
"(",
"$",
"pieces",
")",
";",
"$",
"key",
"=",
"\\",
"rawurlencode",
"(",
"$",
"key",
")",
";",
"$",
"value",
"=",
"\\",
"mb_substr",
"(",
"$",
"queryPart",
",",
"\\",
"mb_strlen",
"(",
"$",
"key",
")",
"+",
"1",
")",
";",
"$",
"value",
"=",
"\\",
"rawurlencode",
"(",
"$",
"value",
")",
";",
"$",
"queryArray",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"\\",
"ksort",
"(",
"$",
"queryArray",
")",
";",
"foreach",
"(",
"$",
"queryArray",
"as",
"$",
"key",
"=>",
"$",
"pieceOfQuery",
")",
"{",
"$",
"pieceOfQuery",
"=",
"\\",
"implode",
"(",
"','",
",",
"$",
"pieceOfQuery",
")",
";",
"$",
"canonicalQuery",
".=",
"$",
"key",
".",
"'='",
".",
"$",
"pieceOfQuery",
".",
"'&'",
";",
"}",
"$",
"canonicalQuery",
"=",
"\\",
"rtrim",
"(",
"$",
"canonicalQuery",
",",
"'&'",
")",
";",
"}",
"return",
"\\",
"hash",
"(",
"'sha256'",
",",
"\\",
"implode",
"(",
"'&'",
",",
"[",
"\\",
"mb_strtoupper",
"(",
"$",
"method",
")",
",",
"$",
"path",
",",
"$",
"canonicalQuery",
"]",
")",
")",
";",
"}"
] | Create Query String Hash
More details:
https://developer.atlassian.com/static/connect/docs/latest/concepts/understanding-jwt.html#creating-token
@param string $url URL of the request
@param string $method HTTP method
@return string | [
"Create",
"Query",
"String",
"Hash"
] | 4691ae2410eb55dce1140733f5f6821b6f230ca8 | https://github.com/thecatontheflat/atlassian-connect-bundle/blob/4691ae2410eb55dce1140733f5f6821b6f230ca8/Service/QSHGenerator.php#L21-L50 |
35,873 | summerblue/laravel-taggable | src/Util.php | Util.uniqueSlug | public function uniqueSlug($slug_str, $tag_name)
{
$model = $this->tagModelString();
if (!empty($slug_str) && $tag = $model::where('slug', $slug_str)->first()) {
// 只有当 slug 一样但 tagname 不一样的情况下,才自动设置随机 slug 后缀
if ($tag->name != $this->normalizeTagName($tag_name)) {
$slug_str .= '-'. mt_rand(1000, 9999);
}
}
return $slug_str;
} | php | public function uniqueSlug($slug_str, $tag_name)
{
$model = $this->tagModelString();
if (!empty($slug_str) && $tag = $model::where('slug', $slug_str)->first()) {
// 只有当 slug 一样但 tagname 不一样的情况下,才自动设置随机 slug 后缀
if ($tag->name != $this->normalizeTagName($tag_name)) {
$slug_str .= '-'. mt_rand(1000, 9999);
}
}
return $slug_str;
} | [
"public",
"function",
"uniqueSlug",
"(",
"$",
"slug_str",
",",
"$",
"tag_name",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"tagModelString",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"slug_str",
")",
"&&",
"$",
"tag",
"=",
"$",
"model",
"::",
"where",
"(",
"'slug'",
",",
"$",
"slug_str",
")",
"->",
"first",
"(",
")",
")",
"{",
"// 只有当 slug 一样但 tagname 不一样的情况下,才自动设置随机 slug 后缀",
"if",
"(",
"$",
"tag",
"->",
"name",
"!=",
"$",
"this",
"->",
"normalizeTagName",
"(",
"$",
"tag_name",
")",
")",
"{",
"$",
"slug_str",
".=",
"'-'",
".",
"mt_rand",
"(",
"1000",
",",
"9999",
")",
";",
"}",
"}",
"return",
"$",
"slug_str",
";",
"}"
] | Check DB Slug Dulplication | [
"Check",
"DB",
"Slug",
"Dulplication"
] | 35125bdc29d6d454c91ab65c457a9d8bdc1f7b86 | https://github.com/summerblue/laravel-taggable/blob/35125bdc29d6d454c91ab65c457a9d8bdc1f7b86/src/Util.php#L222-L232 |
35,874 | KnpLabs/KnpZendCacheBundle | DependencyInjection/KnpZendCacheExtension.php | KnpZendCacheExtension.load | public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('manager.xml');
$templates = array();
foreach ($configs as $config) {
$templates = array_merge($templates, $config['templates']);
}
foreach($templates as $name => $template) {
$container->findDefinition('knp_zend_cache.manager')->addMethodCall('setCacheTemplate', array($name, $template));
}
} | php | public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('manager.xml');
$templates = array();
foreach ($configs as $config) {
$templates = array_merge($templates, $config['templates']);
}
foreach($templates as $name => $template) {
$container->findDefinition('knp_zend_cache.manager')->addMethodCall('setCacheTemplate', array($name, $template));
}
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"loader",
"=",
"new",
"XmlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'manager.xml'",
")",
";",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"configs",
"as",
"$",
"config",
")",
"{",
"$",
"templates",
"=",
"array_merge",
"(",
"$",
"templates",
",",
"$",
"config",
"[",
"'templates'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"templates",
"as",
"$",
"name",
"=>",
"$",
"template",
")",
"{",
"$",
"container",
"->",
"findDefinition",
"(",
"'knp_zend_cache.manager'",
")",
"->",
"addMethodCall",
"(",
"'setCacheTemplate'",
",",
"array",
"(",
"$",
"name",
",",
"$",
"template",
")",
")",
";",
"}",
"}"
] | Loads the cache manager configuration. | [
"Loads",
"the",
"cache",
"manager",
"configuration",
"."
] | 36b0815c274a5a8114de9bc8dcd4dfeae95c7265 | https://github.com/KnpLabs/KnpZendCacheBundle/blob/36b0815c274a5a8114de9bc8dcd4dfeae95c7265/DependencyInjection/KnpZendCacheExtension.php#L25-L38 |
35,875 | UnionOfRAD/li3_docs | doc/Docblock.php | Docblock.tag | public function tag($name) {
if (!isset($this->_tags[$name])) {
return false;
}
foreach ($this->_tags[$name] as $item) {
return $item;
}
} | php | public function tag($name) {
if (!isset($this->_tags[$name])) {
return false;
}
foreach ($this->_tags[$name] as $item) {
return $item;
}
} | [
"public",
"function",
"tag",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_tags",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_tags",
"[",
"$",
"name",
"]",
"as",
"$",
"item",
")",
"{",
"return",
"$",
"item",
";",
"}",
"}"
] | Retrieve a single tag item. Good for i.e. `return` tags, that can
by definition only appear once.
@param string $name The tag name to retrieve.
@return array|boolean The tag information or `false` if tag does not exist. | [
"Retrieve",
"a",
"single",
"tag",
"item",
".",
"Good",
"for",
"i",
".",
"e",
".",
"return",
"tags",
"that",
"can",
"by",
"definition",
"only",
"appear",
"once",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/doc/Docblock.php#L86-L93 |
35,876 | UnionOfRAD/li3_docs | doc/Docblock.php | Docblock._parse | protected function _parse($comment) {
$summary = null;
$description = null;
$tags = array();
$comment = trim(preg_replace('/^(\s*\/\*\*|\s*\*{1,2}\/|\s*\* ?)/m', '', $comment));
$comment = str_replace("\r\n", "\n", $comment);
if ($items = preg_split('/\n@/ms', $comment, 2)) {
list($summary, $tags) = $items + array('', '');
$this->_tags = $tags ? $this->_parseTags("@{$tags}") : array();
}
if (strpos($summary, "\n\n")) {
list($summary, $description) = explode("\n\n", $summary, 2);
}
$this->_summary = $this->_clean($summary);
$this->_description = $this->_clean($description);
} | php | protected function _parse($comment) {
$summary = null;
$description = null;
$tags = array();
$comment = trim(preg_replace('/^(\s*\/\*\*|\s*\*{1,2}\/|\s*\* ?)/m', '', $comment));
$comment = str_replace("\r\n", "\n", $comment);
if ($items = preg_split('/\n@/ms', $comment, 2)) {
list($summary, $tags) = $items + array('', '');
$this->_tags = $tags ? $this->_parseTags("@{$tags}") : array();
}
if (strpos($summary, "\n\n")) {
list($summary, $description) = explode("\n\n", $summary, 2);
}
$this->_summary = $this->_clean($summary);
$this->_description = $this->_clean($description);
} | [
"protected",
"function",
"_parse",
"(",
"$",
"comment",
")",
"{",
"$",
"summary",
"=",
"null",
";",
"$",
"description",
"=",
"null",
";",
"$",
"tags",
"=",
"array",
"(",
")",
";",
"$",
"comment",
"=",
"trim",
"(",
"preg_replace",
"(",
"'/^(\\s*\\/\\*\\*|\\s*\\*{1,2}\\/|\\s*\\* ?)/m'",
",",
"''",
",",
"$",
"comment",
")",
")",
";",
"$",
"comment",
"=",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"comment",
")",
";",
"if",
"(",
"$",
"items",
"=",
"preg_split",
"(",
"'/\\n@/ms'",
",",
"$",
"comment",
",",
"2",
")",
")",
"{",
"list",
"(",
"$",
"summary",
",",
"$",
"tags",
")",
"=",
"$",
"items",
"+",
"array",
"(",
"''",
",",
"''",
")",
";",
"$",
"this",
"->",
"_tags",
"=",
"$",
"tags",
"?",
"$",
"this",
"->",
"_parseTags",
"(",
"\"@{$tags}\"",
")",
":",
"array",
"(",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"summary",
",",
"\"\\n\\n\"",
")",
")",
"{",
"list",
"(",
"$",
"summary",
",",
"$",
"description",
")",
"=",
"explode",
"(",
"\"\\n\\n\"",
",",
"$",
"summary",
",",
"2",
")",
";",
"}",
"$",
"this",
"->",
"_summary",
"=",
"$",
"this",
"->",
"_clean",
"(",
"$",
"summary",
")",
";",
"$",
"this",
"->",
"_description",
"=",
"$",
"this",
"->",
"_clean",
"(",
"$",
"description",
")",
";",
"}"
] | Parses a docblock into its major components of `summary`, `description` and `tags`.
@param string $comment The docblock string to be parsed
@return void | [
"Parses",
"a",
"docblock",
"into",
"its",
"major",
"components",
"of",
"summary",
"description",
"and",
"tags",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/doc/Docblock.php#L116-L133 |
35,877 | UnionOfRAD/li3_docs | doc/Docblock.php | Docblock._parseTag | protected function _parseTag($string, array $keys = []) {
$parts = explode(' ', $string, count($keys));
$result = array_fill_keys($keys, null);
foreach ($keys as $i => $key) {
if (isset($parts[$i])) {
if ($key === 'description') {
$result[$key] = $this->_clean($parts[$i]);
} else {
$result[$key] = $parts[$i];
}
}
}
return $result;
} | php | protected function _parseTag($string, array $keys = []) {
$parts = explode(' ', $string, count($keys));
$result = array_fill_keys($keys, null);
foreach ($keys as $i => $key) {
if (isset($parts[$i])) {
if ($key === 'description') {
$result[$key] = $this->_clean($parts[$i]);
} else {
$result[$key] = $parts[$i];
}
}
}
return $result;
} | [
"protected",
"function",
"_parseTag",
"(",
"$",
"string",
",",
"array",
"$",
"keys",
"=",
"[",
"]",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"' '",
",",
"$",
"string",
",",
"count",
"(",
"$",
"keys",
")",
")",
";",
"$",
"result",
"=",
"array_fill_keys",
"(",
"$",
"keys",
",",
"null",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"i",
"=>",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"$",
"i",
"]",
")",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'description'",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"_clean",
"(",
"$",
"parts",
"[",
"$",
"i",
"]",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"parts",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Parses space delimited docblock tags to separate out keys.
@param string
@param array Keys (order matters) to parse out.
@return array Returns an array containing the given keys. | [
"Parses",
"space",
"delimited",
"docblock",
"tags",
"to",
"separate",
"out",
"keys",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/doc/Docblock.php#L191-L205 |
35,878 | UnionOfRAD/li3_docs | controllers/ApisController.php | ApisController.view | public function view() {
$index = Indexes::find('first', [
'conditions' => [
'type' => 'api',
'name' => $this->request->name,
// $this->request->version gives HTTP version.
'version' => isset($this->request->params['version']) ? $this->request->params['version'] : null
]
]);
if (!$index) {
throw new Exception('Index not found.');
}
if (!$this->request->symbol && $index->namespace) {
return $this->redirect([
'library' => 'li3_docs',
'controller' => 'Apis',
'action' => 'view',
'name' => $index->name,
'version' => $index->version,
'symbol' => $index->namespace
]);
}
if (!$symbol = $index->symbol($this->request->symbol)) {
// Just class members are handled below.
if (strpos($this->request->symbol, '::') === false) {
throw new Exception('Symbol not found.');
}
// As Markdown does not allow closing () on method links or sends
// them out as just ) or ( we'll see if there's method symbol
// similiar to this one and redirect to that.
$fixed = rtrim($this->request->symbol, '()') . '()';
if ($symbol = $index->symbol($fixed)) {
return $this->redirect([
'library' => 'li3_docs',
'controller' => 'Apis',
'action' => 'view',
'name' => $index->name,
'version' => $index->version,
'symbol' => $symbol->name
]);
}
// From documentation links may be generated to inherited
// members of a class. We redirect to the class where they
// were defined. Document::$_parent -> Entity::$_parent
list($class, $member) = explode('::', $this->request->symbol, 2) + [null, null];
if (!$symbol = $index->symbol($class)) {
throw new Exception('Symbol not found.');
}
if ($member[0] === '$') {
$type = 'property';
} elseif (strtoupper($member[0]) === $member[0]) {
$type = 'constant';
} else {
$type = 'method';
}
$symbol = $symbol->members(compact('type'))->first(function($item) use ($member) {
return $item->title(['last' => true]) === $member;
});
if (!$symbol) {
throw new Exception('Symbol not found.');
}
return $this->redirect([
'library' => 'li3_docs',
'controller' => 'Apis',
'action' => 'view',
'name' => $index->name,
'version' => $index->version,
'symbol' => $symbol->name
]);
}
$crumbs = $this->_crumbsForSymbol($index, $symbol);
return compact('index', 'symbol', 'crumbs');
} | php | public function view() {
$index = Indexes::find('first', [
'conditions' => [
'type' => 'api',
'name' => $this->request->name,
// $this->request->version gives HTTP version.
'version' => isset($this->request->params['version']) ? $this->request->params['version'] : null
]
]);
if (!$index) {
throw new Exception('Index not found.');
}
if (!$this->request->symbol && $index->namespace) {
return $this->redirect([
'library' => 'li3_docs',
'controller' => 'Apis',
'action' => 'view',
'name' => $index->name,
'version' => $index->version,
'symbol' => $index->namespace
]);
}
if (!$symbol = $index->symbol($this->request->symbol)) {
// Just class members are handled below.
if (strpos($this->request->symbol, '::') === false) {
throw new Exception('Symbol not found.');
}
// As Markdown does not allow closing () on method links or sends
// them out as just ) or ( we'll see if there's method symbol
// similiar to this one and redirect to that.
$fixed = rtrim($this->request->symbol, '()') . '()';
if ($symbol = $index->symbol($fixed)) {
return $this->redirect([
'library' => 'li3_docs',
'controller' => 'Apis',
'action' => 'view',
'name' => $index->name,
'version' => $index->version,
'symbol' => $symbol->name
]);
}
// From documentation links may be generated to inherited
// members of a class. We redirect to the class where they
// were defined. Document::$_parent -> Entity::$_parent
list($class, $member) = explode('::', $this->request->symbol, 2) + [null, null];
if (!$symbol = $index->symbol($class)) {
throw new Exception('Symbol not found.');
}
if ($member[0] === '$') {
$type = 'property';
} elseif (strtoupper($member[0]) === $member[0]) {
$type = 'constant';
} else {
$type = 'method';
}
$symbol = $symbol->members(compact('type'))->first(function($item) use ($member) {
return $item->title(['last' => true]) === $member;
});
if (!$symbol) {
throw new Exception('Symbol not found.');
}
return $this->redirect([
'library' => 'li3_docs',
'controller' => 'Apis',
'action' => 'view',
'name' => $index->name,
'version' => $index->version,
'symbol' => $symbol->name
]);
}
$crumbs = $this->_crumbsForSymbol($index, $symbol);
return compact('index', 'symbol', 'crumbs');
} | [
"public",
"function",
"view",
"(",
")",
"{",
"$",
"index",
"=",
"Indexes",
"::",
"find",
"(",
"'first'",
",",
"[",
"'conditions'",
"=>",
"[",
"'type'",
"=>",
"'api'",
",",
"'name'",
"=>",
"$",
"this",
"->",
"request",
"->",
"name",
",",
"// $this->request->version gives HTTP version.",
"'version'",
"=>",
"isset",
"(",
"$",
"this",
"->",
"request",
"->",
"params",
"[",
"'version'",
"]",
")",
"?",
"$",
"this",
"->",
"request",
"->",
"params",
"[",
"'version'",
"]",
":",
"null",
"]",
"]",
")",
";",
"if",
"(",
"!",
"$",
"index",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Index not found.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"request",
"->",
"symbol",
"&&",
"$",
"index",
"->",
"namespace",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'library'",
"=>",
"'li3_docs'",
",",
"'controller'",
"=>",
"'Apis'",
",",
"'action'",
"=>",
"'view'",
",",
"'name'",
"=>",
"$",
"index",
"->",
"name",
",",
"'version'",
"=>",
"$",
"index",
"->",
"version",
",",
"'symbol'",
"=>",
"$",
"index",
"->",
"namespace",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"symbol",
"=",
"$",
"index",
"->",
"symbol",
"(",
"$",
"this",
"->",
"request",
"->",
"symbol",
")",
")",
"{",
"// Just class members are handled below.",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"request",
"->",
"symbol",
",",
"'::'",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Symbol not found.'",
")",
";",
"}",
"// As Markdown does not allow closing () on method links or sends",
"// them out as just ) or ( we'll see if there's method symbol",
"// similiar to this one and redirect to that.",
"$",
"fixed",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"request",
"->",
"symbol",
",",
"'()'",
")",
".",
"'()'",
";",
"if",
"(",
"$",
"symbol",
"=",
"$",
"index",
"->",
"symbol",
"(",
"$",
"fixed",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'library'",
"=>",
"'li3_docs'",
",",
"'controller'",
"=>",
"'Apis'",
",",
"'action'",
"=>",
"'view'",
",",
"'name'",
"=>",
"$",
"index",
"->",
"name",
",",
"'version'",
"=>",
"$",
"index",
"->",
"version",
",",
"'symbol'",
"=>",
"$",
"symbol",
"->",
"name",
"]",
")",
";",
"}",
"// From documentation links may be generated to inherited",
"// members of a class. We redirect to the class where they",
"// were defined. Document::$_parent -> Entity::$_parent",
"list",
"(",
"$",
"class",
",",
"$",
"member",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"this",
"->",
"request",
"->",
"symbol",
",",
"2",
")",
"+",
"[",
"null",
",",
"null",
"]",
";",
"if",
"(",
"!",
"$",
"symbol",
"=",
"$",
"index",
"->",
"symbol",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Symbol not found.'",
")",
";",
"}",
"if",
"(",
"$",
"member",
"[",
"0",
"]",
"===",
"'$'",
")",
"{",
"$",
"type",
"=",
"'property'",
";",
"}",
"elseif",
"(",
"strtoupper",
"(",
"$",
"member",
"[",
"0",
"]",
")",
"===",
"$",
"member",
"[",
"0",
"]",
")",
"{",
"$",
"type",
"=",
"'constant'",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"'method'",
";",
"}",
"$",
"symbol",
"=",
"$",
"symbol",
"->",
"members",
"(",
"compact",
"(",
"'type'",
")",
")",
"->",
"first",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"member",
")",
"{",
"return",
"$",
"item",
"->",
"title",
"(",
"[",
"'last'",
"=>",
"true",
"]",
")",
"===",
"$",
"member",
";",
"}",
")",
";",
"if",
"(",
"!",
"$",
"symbol",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Symbol not found.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'library'",
"=>",
"'li3_docs'",
",",
"'controller'",
"=>",
"'Apis'",
",",
"'action'",
"=>",
"'view'",
",",
"'name'",
"=>",
"$",
"index",
"->",
"name",
",",
"'version'",
"=>",
"$",
"index",
"->",
"version",
",",
"'symbol'",
"=>",
"$",
"symbol",
"->",
"name",
"]",
")",
";",
"}",
"$",
"crumbs",
"=",
"$",
"this",
"->",
"_crumbsForSymbol",
"(",
"$",
"index",
",",
"$",
"symbol",
")",
";",
"return",
"compact",
"(",
"'index'",
",",
"'symbol'",
",",
"'crumbs'",
")",
";",
"}"
] | This action renders the detail page for all API elements, including namespaces, classes,
properties and methods. The action determines what type of entity is being displayed, and
gathers all available data on it. Any wiki text embedded in the data is then post-processed
and prepped for display.
Handles broken URL parsers by matching method URLs with no closing ) or no () at all
and redirecting.
@return array Returns an array with the following keys:
- `'name'`: A string containing the full name of the entity being displayed
- `'library'`: An array with the details of the current class library being
browsed, in which the current entity is contained.
- `'object'`: A multi-level array containing all data extracted about the
current entity. | [
"This",
"action",
"renders",
"the",
"detail",
"page",
"for",
"all",
"API",
"elements",
"including",
"namespaces",
"classes",
"properties",
"and",
"methods",
".",
"The",
"action",
"determines",
"what",
"type",
"of",
"entity",
"is",
"being",
"displayed",
"and",
"gathers",
"all",
"available",
"data",
"on",
"it",
".",
"Any",
"wiki",
"text",
"embedded",
"in",
"the",
"data",
"is",
"then",
"post",
"-",
"processed",
"and",
"prepped",
"for",
"display",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/controllers/ApisController.php#L41-L116 |
35,879 | UnionOfRAD/li3_docs | models/Pages.php | Pages._parse | protected static function _parse($file) {
$header = '';
$content = '';
if (!$stream = fopen($file, 'r')) {
throw new Exception('Failed to open file.');
}
$isHeader = false;
while (!feof($stream)) {
$line = rtrim(fgets($stream));
if ($line === '---') {
$isHeader = !$isHeader;
continue;
}
if ($isHeader) {
$header .= $line . "\n";
} else {
$content .= $line . "\n";
}
}
if ($header) {
$info = Yaml::parse($header);
} else {
$info = [];
}
fclose($stream);
return [$info, $content];
} | php | protected static function _parse($file) {
$header = '';
$content = '';
if (!$stream = fopen($file, 'r')) {
throw new Exception('Failed to open file.');
}
$isHeader = false;
while (!feof($stream)) {
$line = rtrim(fgets($stream));
if ($line === '---') {
$isHeader = !$isHeader;
continue;
}
if ($isHeader) {
$header .= $line . "\n";
} else {
$content .= $line . "\n";
}
}
if ($header) {
$info = Yaml::parse($header);
} else {
$info = [];
}
fclose($stream);
return [$info, $content];
} | [
"protected",
"static",
"function",
"_parse",
"(",
"$",
"file",
")",
"{",
"$",
"header",
"=",
"''",
";",
"$",
"content",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"stream",
"=",
"fopen",
"(",
"$",
"file",
",",
"'r'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Failed to open file.'",
")",
";",
"}",
"$",
"isHeader",
"=",
"false",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"stream",
")",
")",
"{",
"$",
"line",
"=",
"rtrim",
"(",
"fgets",
"(",
"$",
"stream",
")",
")",
";",
"if",
"(",
"$",
"line",
"===",
"'---'",
")",
"{",
"$",
"isHeader",
"=",
"!",
"$",
"isHeader",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"isHeader",
")",
"{",
"$",
"header",
".=",
"$",
"line",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"$",
"content",
".=",
"$",
"line",
".",
"\"\\n\"",
";",
"}",
"}",
"if",
"(",
"$",
"header",
")",
"{",
"$",
"info",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"header",
")",
";",
"}",
"else",
"{",
"$",
"info",
"=",
"[",
"]",
";",
"}",
"fclose",
"(",
"$",
"stream",
")",
";",
"return",
"[",
"$",
"info",
",",
"$",
"content",
"]",
";",
"}"
] | Does not parse file body. | [
"Does",
"not",
"parse",
"file",
"body",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/models/Pages.php#L100-L131 |
35,880 | UnionOfRAD/li3_docs | extensions/command/Docs.php | Docs.index | public function index() {
$pdo = Pages::connection()->connection;
$pdo->beginTransaction();
$this->out('Removing all pages and symbols...');
Pages::remove();
Symbols::remove();
foreach (Indexes::find('all') as $index) {
$this->out('Processing index:' . var_export($index->data(), true));
if ($index->type === 'api') {
$this->out('Harvesting symbols...');
if (!Symbols::harvest($index)) {
$this->error('FAILED');
$pdo->rollback();
return false;
}
}
$this->out('Harvesting pages...');
if (!Pages::harvest($index)) {
$this->error('FAILED');
$pdo->rollback();
return false;
}
}
$pdo->commit();
} | php | public function index() {
$pdo = Pages::connection()->connection;
$pdo->beginTransaction();
$this->out('Removing all pages and symbols...');
Pages::remove();
Symbols::remove();
foreach (Indexes::find('all') as $index) {
$this->out('Processing index:' . var_export($index->data(), true));
if ($index->type === 'api') {
$this->out('Harvesting symbols...');
if (!Symbols::harvest($index)) {
$this->error('FAILED');
$pdo->rollback();
return false;
}
}
$this->out('Harvesting pages...');
if (!Pages::harvest($index)) {
$this->error('FAILED');
$pdo->rollback();
return false;
}
}
$pdo->commit();
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"pdo",
"=",
"Pages",
"::",
"connection",
"(",
")",
"->",
"connection",
";",
"$",
"pdo",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"this",
"->",
"out",
"(",
"'Removing all pages and symbols...'",
")",
";",
"Pages",
"::",
"remove",
"(",
")",
";",
"Symbols",
"::",
"remove",
"(",
")",
";",
"foreach",
"(",
"Indexes",
"::",
"find",
"(",
"'all'",
")",
"as",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"'Processing index:'",
".",
"var_export",
"(",
"$",
"index",
"->",
"data",
"(",
")",
",",
"true",
")",
")",
";",
"if",
"(",
"$",
"index",
"->",
"type",
"===",
"'api'",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"'Harvesting symbols...'",
")",
";",
"if",
"(",
"!",
"Symbols",
"::",
"harvest",
"(",
"$",
"index",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'FAILED'",
")",
";",
"$",
"pdo",
"->",
"rollback",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
"$",
"this",
"->",
"out",
"(",
"'Harvesting pages...'",
")",
";",
"if",
"(",
"!",
"Pages",
"::",
"harvest",
"(",
"$",
"index",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'FAILED'",
")",
";",
"$",
"pdo",
"->",
"rollback",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
"$",
"pdo",
"->",
"commit",
"(",
")",
";",
"}"
] | Generates index for registered libraries. | [
"Generates",
"index",
"for",
"registered",
"libraries",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/extensions/command/Docs.php#L20-L49 |
35,881 | UnionOfRAD/li3_docs | doc/UorMarkdown.php | UorMarkdown.renderHeadline | protected function renderHeadline($block) {
$tag = 'h' . $block['level'];
$text = $this->renderAbsy($block['content']);
$slug = strtolower(Inflector::slug($text));
return sprintf(
'<%s><a id="%s" class="anchor" href="%s">%s</a></%s>' . "\n",
$tag,
$slug,
'#' . $slug,
$text,
$tag
);
} | php | protected function renderHeadline($block) {
$tag = 'h' . $block['level'];
$text = $this->renderAbsy($block['content']);
$slug = strtolower(Inflector::slug($text));
return sprintf(
'<%s><a id="%s" class="anchor" href="%s">%s</a></%s>' . "\n",
$tag,
$slug,
'#' . $slug,
$text,
$tag
);
} | [
"protected",
"function",
"renderHeadline",
"(",
"$",
"block",
")",
"{",
"$",
"tag",
"=",
"'h'",
".",
"$",
"block",
"[",
"'level'",
"]",
";",
"$",
"text",
"=",
"$",
"this",
"->",
"renderAbsy",
"(",
"$",
"block",
"[",
"'content'",
"]",
")",
";",
"$",
"slug",
"=",
"strtolower",
"(",
"Inflector",
"::",
"slug",
"(",
"$",
"text",
")",
")",
";",
"return",
"sprintf",
"(",
"'<%s><a id=\"%s\" class=\"anchor\" href=\"%s\">%s</a></%s>'",
".",
"\"\\n\"",
",",
"$",
"tag",
",",
"$",
"slug",
",",
"'#'",
".",
"$",
"slug",
",",
"$",
"text",
",",
"$",
"tag",
")",
";",
"}"
] | Overwritten to make headlines linkable. | [
"Overwritten",
"to",
"make",
"headlines",
"linkable",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/doc/UorMarkdown.php#L26-L39 |
35,882 | UnionOfRAD/li3_docs | doc/UorMarkdown.php | UorMarkdown.consumeFencedCode | protected function consumeFencedCode($lines, $current) {
list($block, $i) = parent::consumeFencedCode($lines, $current);
if (empty($block['language'])) {
$block['language'] = 'php';
}
return [$block, $i];
} | php | protected function consumeFencedCode($lines, $current) {
list($block, $i) = parent::consumeFencedCode($lines, $current);
if (empty($block['language'])) {
$block['language'] = 'php';
}
return [$block, $i];
} | [
"protected",
"function",
"consumeFencedCode",
"(",
"$",
"lines",
",",
"$",
"current",
")",
"{",
"list",
"(",
"$",
"block",
",",
"$",
"i",
")",
"=",
"parent",
"::",
"consumeFencedCode",
"(",
"$",
"lines",
",",
"$",
"current",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"block",
"[",
"'language'",
"]",
")",
")",
"{",
"$",
"block",
"[",
"'language'",
"]",
"=",
"'php'",
";",
"}",
"return",
"[",
"$",
"block",
",",
"$",
"i",
"]",
";",
"}"
] | Overwritten to default to PHP language in code blocks. | [
"Overwritten",
"to",
"default",
"to",
"PHP",
"language",
"in",
"code",
"blocks",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/doc/UorMarkdown.php#L44-L51 |
35,883 | UnionOfRAD/li3_docs | models/Symbols.php | Symbols.page | public function page($entity) {
if ($entity->type !== 'namespace') {
return false;
}
return Pages::find('first', [
'conditions' => [
'index' => $entity->index,
'name' => $entity->name
]
]);
} | php | public function page($entity) {
if ($entity->type !== 'namespace') {
return false;
}
return Pages::find('first', [
'conditions' => [
'index' => $entity->index,
'name' => $entity->name
]
]);
} | [
"public",
"function",
"page",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"entity",
"->",
"type",
"!==",
"'namespace'",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Pages",
"::",
"find",
"(",
"'first'",
",",
"[",
"'conditions'",
"=>",
"[",
"'index'",
"=>",
"$",
"entity",
"->",
"index",
",",
"'name'",
"=>",
"$",
"entity",
"->",
"name",
"]",
"]",
")",
";",
"}"
] | Namespace symbols may have a corresponding page. | [
"Namespace",
"symbols",
"may",
"have",
"a",
"corresponding",
"page",
"."
] | 4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c | https://github.com/UnionOfRAD/li3_docs/blob/4ee7c26c0bef0ef49b078a98a6762c1e7f03d36c/models/Symbols.php#L194-L204 |
35,884 | bitrix-expert/bbc-module | lib/helpers/componentparameters.php | ComponentParameters.getParameters | public static function getParameters($component, $prepareParams = [], $arCurrentValues, $selectOnlyListed = false)
{
$additionalComponentParams = [];
$componentParams = \CComponentUtil::GetComponentProps($component, $arCurrentValues);
if ($componentParams === false)
{
throw new Main\LoaderException('Failed loading parameters for ' . $component);
}
if (!empty($prepareParams))
{
foreach ($componentParams['PARAMETERS'] as $code => &$params)
{
if ($prepareParams[$code]['DELETE'] || ($selectOnlyListed === true && !isset($prepareParams[$code])))
{
unset($componentParams['PARAMETERS'][$code]);
continue;
}
if ($prepareParams[$code]['MOVE'])
{
$params['PARENT'] = $prepareParams[$code]['MOVE'];
}
if ($prepareParams[$code]['NAME'])
{
$params['NAME'] = $prepareParams[$code]['NAME'];
}
if ($prepareParams[$code]['RENAME'])
{
$additionalComponentParams[$prepareParams[$code]['RENAME']] = $params;
unset($componentParams['PARAMETERS'][$code]);
}
}
unset($params);
$componentParams['PARAMETERS'] = array_replace_recursive($componentParams['PARAMETERS'], $additionalComponentParams);
}
return $componentParams;
} | php | public static function getParameters($component, $prepareParams = [], $arCurrentValues, $selectOnlyListed = false)
{
$additionalComponentParams = [];
$componentParams = \CComponentUtil::GetComponentProps($component, $arCurrentValues);
if ($componentParams === false)
{
throw new Main\LoaderException('Failed loading parameters for ' . $component);
}
if (!empty($prepareParams))
{
foreach ($componentParams['PARAMETERS'] as $code => &$params)
{
if ($prepareParams[$code]['DELETE'] || ($selectOnlyListed === true && !isset($prepareParams[$code])))
{
unset($componentParams['PARAMETERS'][$code]);
continue;
}
if ($prepareParams[$code]['MOVE'])
{
$params['PARENT'] = $prepareParams[$code]['MOVE'];
}
if ($prepareParams[$code]['NAME'])
{
$params['NAME'] = $prepareParams[$code]['NAME'];
}
if ($prepareParams[$code]['RENAME'])
{
$additionalComponentParams[$prepareParams[$code]['RENAME']] = $params;
unset($componentParams['PARAMETERS'][$code]);
}
}
unset($params);
$componentParams['PARAMETERS'] = array_replace_recursive($componentParams['PARAMETERS'], $additionalComponentParams);
}
return $componentParams;
} | [
"public",
"static",
"function",
"getParameters",
"(",
"$",
"component",
",",
"$",
"prepareParams",
"=",
"[",
"]",
",",
"$",
"arCurrentValues",
",",
"$",
"selectOnlyListed",
"=",
"false",
")",
"{",
"$",
"additionalComponentParams",
"=",
"[",
"]",
";",
"$",
"componentParams",
"=",
"\\",
"CComponentUtil",
"::",
"GetComponentProps",
"(",
"$",
"component",
",",
"$",
"arCurrentValues",
")",
";",
"if",
"(",
"$",
"componentParams",
"===",
"false",
")",
"{",
"throw",
"new",
"Main",
"\\",
"LoaderException",
"(",
"'Failed loading parameters for '",
".",
"$",
"component",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"prepareParams",
")",
")",
"{",
"foreach",
"(",
"$",
"componentParams",
"[",
"'PARAMETERS'",
"]",
"as",
"$",
"code",
"=>",
"&",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"prepareParams",
"[",
"$",
"code",
"]",
"[",
"'DELETE'",
"]",
"||",
"(",
"$",
"selectOnlyListed",
"===",
"true",
"&&",
"!",
"isset",
"(",
"$",
"prepareParams",
"[",
"$",
"code",
"]",
")",
")",
")",
"{",
"unset",
"(",
"$",
"componentParams",
"[",
"'PARAMETERS'",
"]",
"[",
"$",
"code",
"]",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"prepareParams",
"[",
"$",
"code",
"]",
"[",
"'MOVE'",
"]",
")",
"{",
"$",
"params",
"[",
"'PARENT'",
"]",
"=",
"$",
"prepareParams",
"[",
"$",
"code",
"]",
"[",
"'MOVE'",
"]",
";",
"}",
"if",
"(",
"$",
"prepareParams",
"[",
"$",
"code",
"]",
"[",
"'NAME'",
"]",
")",
"{",
"$",
"params",
"[",
"'NAME'",
"]",
"=",
"$",
"prepareParams",
"[",
"$",
"code",
"]",
"[",
"'NAME'",
"]",
";",
"}",
"if",
"(",
"$",
"prepareParams",
"[",
"$",
"code",
"]",
"[",
"'RENAME'",
"]",
")",
"{",
"$",
"additionalComponentParams",
"[",
"$",
"prepareParams",
"[",
"$",
"code",
"]",
"[",
"'RENAME'",
"]",
"]",
"=",
"$",
"params",
";",
"unset",
"(",
"$",
"componentParams",
"[",
"'PARAMETERS'",
"]",
"[",
"$",
"code",
"]",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"params",
")",
";",
"$",
"componentParams",
"[",
"'PARAMETERS'",
"]",
"=",
"array_replace_recursive",
"(",
"$",
"componentParams",
"[",
"'PARAMETERS'",
"]",
",",
"$",
"additionalComponentParams",
")",
";",
"}",
"return",
"$",
"componentParams",
";",
"}"
] | Prepare and returns parameters of the component
@param string $component Component name. For example: basis:elements.list
@param array $prepareParams Array with settings for prepare parameters of merged the component. For example:
<code>
[
'SELECT_FIELDS' => array(
'RENAME' => 'LIST_SELECT_FIELDS',
'MOVE' => 'LIST'
]
</code>
Options:
<ul>
<li> RENAME — rename parameter
<li> NAME — add new name (title) for parameter
<li> MOVE — move parameter to another parameter group
<li> DELETE — true or false
</ul>
@param array $arCurrentValues Don't change the name! It's used in the .parameters.php file (Hello from Bitrix)
@param bool $selectOnlyListed Select parameters only listed in $prepareParams
@return array Array for use in variable $arComponentParameters in the .parameters.php
@throws \Bitrix\Main\LoaderException | [
"Prepare",
"and",
"returns",
"parameters",
"of",
"the",
"component"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/helpers/componentparameters.php#L60-L105 |
35,885 | bitrix-expert/bbc-module | lib/traits/common.php | Common.startAjax | private function startAjax()
{
if ($this->arParams['USE_AJAX'] !== 'Y')
{
return false;
}
if (strlen($this->arParams['AJAX_PARAM_NAME']) <= 0)
{
$this->arParams['AJAX_PARAM_NAME'] = 'compid';
}
if (strlen($this->arParams['AJAX_COMPONENT_ID']) <= 0)
{
$this->arParams['AJAX_COMPONENT_ID'] = \CAjax::GetComponentID($this->getName(), $this->getTemplateName(), $this->ajaxComponentIdSalt);
}
if ($this->isAjax())
{
global $APPLICATION;
if ($this->arParams['AJAX_HEAD_RELOAD'] === 'Y')
{
$APPLICATION->ShowAjaxHead();
}
else
{
$APPLICATION->RestartBuffer();
}
if ($this->arParams['AJAX_TYPE'] === 'JSON')
{
header('Content-Type: application/json');
}
if (strlen($this->arParams['AJAX_TEMPLATE_PAGE']) > 0)
{
$this->templatePage = basename($this->arParams['AJAX_TEMPLATE_PAGE']);
}
}
} | php | private function startAjax()
{
if ($this->arParams['USE_AJAX'] !== 'Y')
{
return false;
}
if (strlen($this->arParams['AJAX_PARAM_NAME']) <= 0)
{
$this->arParams['AJAX_PARAM_NAME'] = 'compid';
}
if (strlen($this->arParams['AJAX_COMPONENT_ID']) <= 0)
{
$this->arParams['AJAX_COMPONENT_ID'] = \CAjax::GetComponentID($this->getName(), $this->getTemplateName(), $this->ajaxComponentIdSalt);
}
if ($this->isAjax())
{
global $APPLICATION;
if ($this->arParams['AJAX_HEAD_RELOAD'] === 'Y')
{
$APPLICATION->ShowAjaxHead();
}
else
{
$APPLICATION->RestartBuffer();
}
if ($this->arParams['AJAX_TYPE'] === 'JSON')
{
header('Content-Type: application/json');
}
if (strlen($this->arParams['AJAX_TEMPLATE_PAGE']) > 0)
{
$this->templatePage = basename($this->arParams['AJAX_TEMPLATE_PAGE']);
}
}
} | [
"private",
"function",
"startAjax",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'USE_AJAX'",
"]",
"!==",
"'Y'",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_PARAM_NAME'",
"]",
")",
"<=",
"0",
")",
"{",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_PARAM_NAME'",
"]",
"=",
"'compid'",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_COMPONENT_ID'",
"]",
")",
"<=",
"0",
")",
"{",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_COMPONENT_ID'",
"]",
"=",
"\\",
"CAjax",
"::",
"GetComponentID",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"getTemplateName",
"(",
")",
",",
"$",
"this",
"->",
"ajaxComponentIdSalt",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isAjax",
"(",
")",
")",
"{",
"global",
"$",
"APPLICATION",
";",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_HEAD_RELOAD'",
"]",
"===",
"'Y'",
")",
"{",
"$",
"APPLICATION",
"->",
"ShowAjaxHead",
"(",
")",
";",
"}",
"else",
"{",
"$",
"APPLICATION",
"->",
"RestartBuffer",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_TYPE'",
"]",
"===",
"'JSON'",
")",
"{",
"header",
"(",
"'Content-Type: application/json'",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_TEMPLATE_PAGE'",
"]",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"templatePage",
"=",
"basename",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_TEMPLATE_PAGE'",
"]",
")",
";",
"}",
"}",
"}"
] | Restart buffer if AJAX request | [
"Restart",
"buffer",
"if",
"AJAX",
"request"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/common.php#L182-L222 |
35,886 | bitrix-expert/bbc-module | lib/traits/common.php | Common.return404 | public function return404($notifier = false, \Exception $exception = null)
{
if (!defined('ERROR_404'))
{
define('ERROR_404', 'Y');
}
\CHTTP::SetStatus('404 Not Found');
if ($exception !== false)
{
if ($notifier === false)
{
$this->exceptionNotifier = false;
}
if ($exception instanceof \Exception)
{
throw $exception;
}
else
{
throw new \Exception('Page not found');
}
}
} | php | public function return404($notifier = false, \Exception $exception = null)
{
if (!defined('ERROR_404'))
{
define('ERROR_404', 'Y');
}
\CHTTP::SetStatus('404 Not Found');
if ($exception !== false)
{
if ($notifier === false)
{
$this->exceptionNotifier = false;
}
if ($exception instanceof \Exception)
{
throw $exception;
}
else
{
throw new \Exception('Page not found');
}
}
} | [
"public",
"function",
"return404",
"(",
"$",
"notifier",
"=",
"false",
",",
"\\",
"Exception",
"$",
"exception",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'ERROR_404'",
")",
")",
"{",
"define",
"(",
"'ERROR_404'",
",",
"'Y'",
")",
";",
"}",
"\\",
"CHTTP",
"::",
"SetStatus",
"(",
"'404 Not Found'",
")",
";",
"if",
"(",
"$",
"exception",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"notifier",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"exceptionNotifier",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"exception",
"instanceof",
"\\",
"Exception",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Page not found'",
")",
";",
"}",
"}",
"}"
] | Set status 404 and throw exception
@param bool $notifier Sent notify to admin email
@param \Exception|null|false $exception Exception which will be throwing or "false" what not throwing exceptions. Default — throw new \Exception()
@throws \Exception | [
"Set",
"status",
"404",
"and",
"throw",
"exception"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/common.php#L354-L379 |
35,887 | bitrix-expert/bbc-module | lib/traits/common.php | Common.catchException | protected function catchException(\Exception $exception, $notifier = null)
{
global $USER;
$this->abortCache();
if ($USER->IsAdmin())
{
$this->showExceptionAdmin($exception);
}
else
{
$this->showExceptionUser($exception);
}
if (($notifier === true) || ($this->exceptionNotifier && $notifier !== false) && BX_EXC_NOTIFY !== false)
{
$this->sendNotifyException($exception);
}
} | php | protected function catchException(\Exception $exception, $notifier = null)
{
global $USER;
$this->abortCache();
if ($USER->IsAdmin())
{
$this->showExceptionAdmin($exception);
}
else
{
$this->showExceptionUser($exception);
}
if (($notifier === true) || ($this->exceptionNotifier && $notifier !== false) && BX_EXC_NOTIFY !== false)
{
$this->sendNotifyException($exception);
}
} | [
"protected",
"function",
"catchException",
"(",
"\\",
"Exception",
"$",
"exception",
",",
"$",
"notifier",
"=",
"null",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"this",
"->",
"abortCache",
"(",
")",
";",
"if",
"(",
"$",
"USER",
"->",
"IsAdmin",
"(",
")",
")",
"{",
"$",
"this",
"->",
"showExceptionAdmin",
"(",
"$",
"exception",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"showExceptionUser",
"(",
"$",
"exception",
")",
";",
"}",
"if",
"(",
"(",
"$",
"notifier",
"===",
"true",
")",
"||",
"(",
"$",
"this",
"->",
"exceptionNotifier",
"&&",
"$",
"notifier",
"!==",
"false",
")",
"&&",
"BX_EXC_NOTIFY",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"sendNotifyException",
"(",
"$",
"exception",
")",
";",
"}",
"}"
] | Called when an error occurs
Resets the cache, show error message (two mode: for users and for admins),
sending notification to admin email
@param \Exception $exception
@param bool $notifier Sent notify to admin email. Default — value of property $this->exceptionNotifier
@uses exceptionNotifier | [
"Called",
"when",
"an",
"error",
"occurs"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/common.php#L391-L410 |
35,888 | bitrix-expert/bbc-module | lib/traits/common.php | Common.isAjax | public function isAjax()
{
if (
strlen($this->arParams['AJAX_COMPONENT_ID']) > 0
&& strlen($this->arParams['AJAX_PARAM_NAME']) > 0
&& $_REQUEST[$this->arParams['AJAX_PARAM_NAME']] === $this->arParams['AJAX_COMPONENT_ID']
&& isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'
)
{
return true;
}
return false;
} | php | public function isAjax()
{
if (
strlen($this->arParams['AJAX_COMPONENT_ID']) > 0
&& strlen($this->arParams['AJAX_PARAM_NAME']) > 0
&& $_REQUEST[$this->arParams['AJAX_PARAM_NAME']] === $this->arParams['AJAX_COMPONENT_ID']
&& isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'
)
{
return true;
}
return false;
} | [
"public",
"function",
"isAjax",
"(",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_COMPONENT_ID'",
"]",
")",
">",
"0",
"&&",
"strlen",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_PARAM_NAME'",
"]",
")",
">",
"0",
"&&",
"$",
"_REQUEST",
"[",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_PARAM_NAME'",
"]",
"]",
"===",
"$",
"this",
"->",
"arParams",
"[",
"'AJAX_COMPONENT_ID'",
"]",
"&&",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_REQUESTED_WITH'",
"]",
")",
"&&",
"strtolower",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_REQUESTED_WITH'",
"]",
")",
"===",
"'xmlhttprequest'",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Is AJAX request
@return bool | [
"Is",
"AJAX",
"request"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/common.php#L478-L492 |
35,889 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.setSeoTags | protected function setSeoTags()
{
global $APPLICATION;
if ($this->arParams['SET_SEO_TAGS'] !== 'Y')
{
return false;
}
if ($this->arResult['SEO_TAGS']['TITLE'])
{
$APPLICATION->SetPageProperty('title', $this->arResult['SEO_TAGS']['TITLE']);
}
if ($this->arResult['SEO_TAGS']['DESCRIPTION'])
{
$APPLICATION->SetPageProperty('description', $this->arResult['SEO_TAGS']['DESCRIPTION']);
}
if ($this->arResult['SEO_TAGS']['KEYWORDS'])
{
$APPLICATION->SetPageProperty('keywords', $this->arResult['SEO_TAGS']['KEYWORDS']);
}
} | php | protected function setSeoTags()
{
global $APPLICATION;
if ($this->arParams['SET_SEO_TAGS'] !== 'Y')
{
return false;
}
if ($this->arResult['SEO_TAGS']['TITLE'])
{
$APPLICATION->SetPageProperty('title', $this->arResult['SEO_TAGS']['TITLE']);
}
if ($this->arResult['SEO_TAGS']['DESCRIPTION'])
{
$APPLICATION->SetPageProperty('description', $this->arResult['SEO_TAGS']['DESCRIPTION']);
}
if ($this->arResult['SEO_TAGS']['KEYWORDS'])
{
$APPLICATION->SetPageProperty('keywords', $this->arResult['SEO_TAGS']['KEYWORDS']);
}
} | [
"protected",
"function",
"setSeoTags",
"(",
")",
"{",
"global",
"$",
"APPLICATION",
";",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'SET_SEO_TAGS'",
"]",
"!==",
"'Y'",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arResult",
"[",
"'SEO_TAGS'",
"]",
"[",
"'TITLE'",
"]",
")",
"{",
"$",
"APPLICATION",
"->",
"SetPageProperty",
"(",
"'title'",
",",
"$",
"this",
"->",
"arResult",
"[",
"'SEO_TAGS'",
"]",
"[",
"'TITLE'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arResult",
"[",
"'SEO_TAGS'",
"]",
"[",
"'DESCRIPTION'",
"]",
")",
"{",
"$",
"APPLICATION",
"->",
"SetPageProperty",
"(",
"'description'",
",",
"$",
"this",
"->",
"arResult",
"[",
"'SEO_TAGS'",
"]",
"[",
"'DESCRIPTION'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arResult",
"[",
"'SEO_TAGS'",
"]",
"[",
"'KEYWORDS'",
"]",
")",
"{",
"$",
"APPLICATION",
"->",
"SetPageProperty",
"(",
"'keywords'",
",",
"$",
"this",
"->",
"arResult",
"[",
"'SEO_TAGS'",
"]",
"[",
"'KEYWORDS'",
"]",
")",
";",
"}",
"}"
] | Setting meta tags
<ul> Uses:
<li> title
<li> description
<li> keywords
</ul>
@uses arResult['SEO_TAGS'] | [
"Setting",
"meta",
"tags"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L342-L365 |
35,890 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.setOgTags | protected function setOgTags()
{
if ($this->arResult['OG_TAGS']['TITLE'])
{
Asset::getInstance()->addString('<meta property="og:title" content="'.$this->arResult['OG_TAGS']['TITLE'].'" />', true);
}
if ($this->arResult['OG_TAGS']['DESCRIPTION'])
{
Asset::getInstance()->addString('<meta property="og:description" content="'.$this->arResult['OG_TAGS']['DESCRIPTION'].'" />', true);
}
if ($this->arResult['OG_TAGS']['URL'])
{
Asset::getInstance()->addString('<meta property="og:url" content="'.$this->arResult['OG_TAGS']['URL'].'" />', true);
}
if ($this->arResult['OG_TAGS']['IMAGE'])
{
Asset::getInstance()->addString('<meta property="og:image" content="'.$this->arResult['OG_TAGS']['IMAGE'].'" />', true);
}
} | php | protected function setOgTags()
{
if ($this->arResult['OG_TAGS']['TITLE'])
{
Asset::getInstance()->addString('<meta property="og:title" content="'.$this->arResult['OG_TAGS']['TITLE'].'" />', true);
}
if ($this->arResult['OG_TAGS']['DESCRIPTION'])
{
Asset::getInstance()->addString('<meta property="og:description" content="'.$this->arResult['OG_TAGS']['DESCRIPTION'].'" />', true);
}
if ($this->arResult['OG_TAGS']['URL'])
{
Asset::getInstance()->addString('<meta property="og:url" content="'.$this->arResult['OG_TAGS']['URL'].'" />', true);
}
if ($this->arResult['OG_TAGS']['IMAGE'])
{
Asset::getInstance()->addString('<meta property="og:image" content="'.$this->arResult['OG_TAGS']['IMAGE'].'" />', true);
}
} | [
"protected",
"function",
"setOgTags",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"arResult",
"[",
"'OG_TAGS'",
"]",
"[",
"'TITLE'",
"]",
")",
"{",
"Asset",
"::",
"getInstance",
"(",
")",
"->",
"addString",
"(",
"'<meta property=\"og:title\" content=\"'",
".",
"$",
"this",
"->",
"arResult",
"[",
"'OG_TAGS'",
"]",
"[",
"'TITLE'",
"]",
".",
"'\" />'",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arResult",
"[",
"'OG_TAGS'",
"]",
"[",
"'DESCRIPTION'",
"]",
")",
"{",
"Asset",
"::",
"getInstance",
"(",
")",
"->",
"addString",
"(",
"'<meta property=\"og:description\" content=\"'",
".",
"$",
"this",
"->",
"arResult",
"[",
"'OG_TAGS'",
"]",
"[",
"'DESCRIPTION'",
"]",
".",
"'\" />'",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arResult",
"[",
"'OG_TAGS'",
"]",
"[",
"'URL'",
"]",
")",
"{",
"Asset",
"::",
"getInstance",
"(",
")",
"->",
"addString",
"(",
"'<meta property=\"og:url\" content=\"'",
".",
"$",
"this",
"->",
"arResult",
"[",
"'OG_TAGS'",
"]",
"[",
"'URL'",
"]",
".",
"'\" />'",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arResult",
"[",
"'OG_TAGS'",
"]",
"[",
"'IMAGE'",
"]",
")",
"{",
"Asset",
"::",
"getInstance",
"(",
")",
"->",
"addString",
"(",
"'<meta property=\"og:image\" content=\"'",
".",
"$",
"this",
"->",
"arResult",
"[",
"'OG_TAGS'",
"]",
"[",
"'IMAGE'",
"]",
".",
"'\" />'",
",",
"true",
")",
";",
"}",
"}"
] | Setting open graph tags for current page
<ul> Uses:
<li> og:title
<li> og:url
<li> og:image
</ul>
@uses arResult['OG_TAGS'] | [
"Setting",
"open",
"graph",
"tags",
"for",
"current",
"page"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L403-L424 |
35,891 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.setEditButtons | protected function setEditButtons()
{
global $APPLICATION;
if (!$APPLICATION->GetShowIncludeAreas() || $this->showEditButtons === false)
{
return false;
}
$buttons = \CIBlock::GetPanelButtons(
$this->arParams['IBLOCK_ID'],
$this->arResult['ID'],
$this->arParams['SECTION_ID'],
[]
);
$this->addIncludeAreaIcons(\CIBlock::GetComponentMenu($APPLICATION->GetPublicShowMode(), $buttons));
if (is_array($buttons['intranet']))
{
Asset::getInstance()->addJs(BX_ROOT.'/js/main/utils.js');
foreach ($buttons['intranet'] as $button)
{
$this->addEditButton($button);
}
}
} | php | protected function setEditButtons()
{
global $APPLICATION;
if (!$APPLICATION->GetShowIncludeAreas() || $this->showEditButtons === false)
{
return false;
}
$buttons = \CIBlock::GetPanelButtons(
$this->arParams['IBLOCK_ID'],
$this->arResult['ID'],
$this->arParams['SECTION_ID'],
[]
);
$this->addIncludeAreaIcons(\CIBlock::GetComponentMenu($APPLICATION->GetPublicShowMode(), $buttons));
if (is_array($buttons['intranet']))
{
Asset::getInstance()->addJs(BX_ROOT.'/js/main/utils.js');
foreach ($buttons['intranet'] as $button)
{
$this->addEditButton($button);
}
}
} | [
"protected",
"function",
"setEditButtons",
"(",
")",
"{",
"global",
"$",
"APPLICATION",
";",
"if",
"(",
"!",
"$",
"APPLICATION",
"->",
"GetShowIncludeAreas",
"(",
")",
"||",
"$",
"this",
"->",
"showEditButtons",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"buttons",
"=",
"\\",
"CIBlock",
"::",
"GetPanelButtons",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'IBLOCK_ID'",
"]",
",",
"$",
"this",
"->",
"arResult",
"[",
"'ID'",
"]",
",",
"$",
"this",
"->",
"arParams",
"[",
"'SECTION_ID'",
"]",
",",
"[",
"]",
")",
";",
"$",
"this",
"->",
"addIncludeAreaIcons",
"(",
"\\",
"CIBlock",
"::",
"GetComponentMenu",
"(",
"$",
"APPLICATION",
"->",
"GetPublicShowMode",
"(",
")",
",",
"$",
"buttons",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"buttons",
"[",
"'intranet'",
"]",
")",
")",
"{",
"Asset",
"::",
"getInstance",
"(",
")",
"->",
"addJs",
"(",
"BX_ROOT",
".",
"'/js/main/utils.js'",
")",
";",
"foreach",
"(",
"$",
"buttons",
"[",
"'intranet'",
"]",
"as",
"$",
"button",
")",
"{",
"$",
"this",
"->",
"addEditButton",
"(",
"$",
"button",
")",
";",
"}",
"}",
"}"
] | Add to page buttons for edit elements and sections of info-block | [
"Add",
"to",
"page",
"buttons",
"for",
"edit",
"elements",
"and",
"sections",
"of",
"info",
"-",
"block"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L429-L456 |
35,892 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.setParamsFilters | protected function setParamsFilters()
{
if ($this->arParams['IBLOCK_TYPE'])
{
$this->filterParams['IBLOCK_TYPE'] = $this->arParams['IBLOCK_TYPE'];
}
if ($this->arParams['IBLOCK_ID'])
{
$this->filterParams['IBLOCK_ID'] = $this->arParams['IBLOCK_ID'];
}
if ($this->arParams['SECTION_CODE'])
{
$this->filterParams['SECTION_CODE'] = $this->arParams['SECTION_CODE'];
}
elseif ($this->arParams['SECTION_ID'])
{
$this->filterParams['SECTION_ID'] = $this->arParams['SECTION_ID'];
}
if ($this->arParams['INCLUDE_SUBSECTIONS'] === 'Y')
{
$this->filterParams['INCLUDE_SUBSECTIONS'] = 'Y';
}
if ($this->arParams['ELEMENT_CODE'])
{
$this->filterParams['CODE'] = $this->arParams['ELEMENT_CODE'];
}
elseif ($this->arParams['ELEMENT_ID'])
{
$this->filterParams['ID'] = $this->arParams['ELEMENT_ID'];
}
if ($this->arParams['CHECK_PERMISSIONS'])
{
$this->filterParams['CHECK_PERMISSIONS'] = $this->arParams['CHECK_PERMISSIONS'];
}
if (!isset($this->filterParams['ACTIVE']))
{
$this->filterParams['ACTIVE'] = 'Y';
}
if (strlen($this->arParams['EX_FILTER_NAME']) > 0
&& preg_match("/^[A-Za-z_][A-Za-z01-9_]*$/", $this->arParams['EX_FILTER_NAME'])
&& is_array($GLOBALS[$this->arParams['EX_FILTER_NAME']])
)
{
$this->filterParams = array_merge_recursive($this->filterParams, $GLOBALS[$this->arParams['EX_FILTER_NAME']]);
$this->addCacheAdditionalId($GLOBALS[$this->arParams['EX_FILTER_NAME']]);
}
} | php | protected function setParamsFilters()
{
if ($this->arParams['IBLOCK_TYPE'])
{
$this->filterParams['IBLOCK_TYPE'] = $this->arParams['IBLOCK_TYPE'];
}
if ($this->arParams['IBLOCK_ID'])
{
$this->filterParams['IBLOCK_ID'] = $this->arParams['IBLOCK_ID'];
}
if ($this->arParams['SECTION_CODE'])
{
$this->filterParams['SECTION_CODE'] = $this->arParams['SECTION_CODE'];
}
elseif ($this->arParams['SECTION_ID'])
{
$this->filterParams['SECTION_ID'] = $this->arParams['SECTION_ID'];
}
if ($this->arParams['INCLUDE_SUBSECTIONS'] === 'Y')
{
$this->filterParams['INCLUDE_SUBSECTIONS'] = 'Y';
}
if ($this->arParams['ELEMENT_CODE'])
{
$this->filterParams['CODE'] = $this->arParams['ELEMENT_CODE'];
}
elseif ($this->arParams['ELEMENT_ID'])
{
$this->filterParams['ID'] = $this->arParams['ELEMENT_ID'];
}
if ($this->arParams['CHECK_PERMISSIONS'])
{
$this->filterParams['CHECK_PERMISSIONS'] = $this->arParams['CHECK_PERMISSIONS'];
}
if (!isset($this->filterParams['ACTIVE']))
{
$this->filterParams['ACTIVE'] = 'Y';
}
if (strlen($this->arParams['EX_FILTER_NAME']) > 0
&& preg_match("/^[A-Za-z_][A-Za-z01-9_]*$/", $this->arParams['EX_FILTER_NAME'])
&& is_array($GLOBALS[$this->arParams['EX_FILTER_NAME']])
)
{
$this->filterParams = array_merge_recursive($this->filterParams, $GLOBALS[$this->arParams['EX_FILTER_NAME']]);
$this->addCacheAdditionalId($GLOBALS[$this->arParams['EX_FILTER_NAME']]);
}
} | [
"protected",
"function",
"setParamsFilters",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'IBLOCK_TYPE'",
"]",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'IBLOCK_TYPE'",
"]",
"=",
"$",
"this",
"->",
"arParams",
"[",
"'IBLOCK_TYPE'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'IBLOCK_ID'",
"]",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'IBLOCK_ID'",
"]",
"=",
"$",
"this",
"->",
"arParams",
"[",
"'IBLOCK_ID'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'SECTION_CODE'",
"]",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'SECTION_CODE'",
"]",
"=",
"$",
"this",
"->",
"arParams",
"[",
"'SECTION_CODE'",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'SECTION_ID'",
"]",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'SECTION_ID'",
"]",
"=",
"$",
"this",
"->",
"arParams",
"[",
"'SECTION_ID'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'INCLUDE_SUBSECTIONS'",
"]",
"===",
"'Y'",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'INCLUDE_SUBSECTIONS'",
"]",
"=",
"'Y'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'ELEMENT_CODE'",
"]",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'CODE'",
"]",
"=",
"$",
"this",
"->",
"arParams",
"[",
"'ELEMENT_CODE'",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'ELEMENT_ID'",
"]",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'ID'",
"]",
"=",
"$",
"this",
"->",
"arParams",
"[",
"'ELEMENT_ID'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'CHECK_PERMISSIONS'",
"]",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'CHECK_PERMISSIONS'",
"]",
"=",
"$",
"this",
"->",
"arParams",
"[",
"'CHECK_PERMISSIONS'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"filterParams",
"[",
"'ACTIVE'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"filterParams",
"[",
"'ACTIVE'",
"]",
"=",
"'Y'",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'EX_FILTER_NAME'",
"]",
")",
">",
"0",
"&&",
"preg_match",
"(",
"\"/^[A-Za-z_][A-Za-z01-9_]*$/\"",
",",
"$",
"this",
"->",
"arParams",
"[",
"'EX_FILTER_NAME'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"GLOBALS",
"[",
"$",
"this",
"->",
"arParams",
"[",
"'EX_FILTER_NAME'",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"filterParams",
"=",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"filterParams",
",",
"$",
"GLOBALS",
"[",
"$",
"this",
"->",
"arParams",
"[",
"'EX_FILTER_NAME'",
"]",
"]",
")",
";",
"$",
"this",
"->",
"addCacheAdditionalId",
"(",
"$",
"GLOBALS",
"[",
"$",
"this",
"->",
"arParams",
"[",
"'EX_FILTER_NAME'",
"]",
"]",
")",
";",
"}",
"}"
] | Getting global filter and write his to component parameters | [
"Getting",
"global",
"filter",
"and",
"write",
"his",
"to",
"component",
"parameters"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L461-L515 |
35,893 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.addGlobalFilters | public function addGlobalFilters(array $fields, $recursiveMerge = false)
{
if (is_array($fields) && !empty($fields))
{
if ($recursiveMerge)
{
$this->filterParams = array_merge_recursive($this->filterParams, $fields);
}
else
{
$this->filterParams = array_merge($this->filterParams, $fields);
}
$this->addCacheAdditionalId($fields);
}
} | php | public function addGlobalFilters(array $fields, $recursiveMerge = false)
{
if (is_array($fields) && !empty($fields))
{
if ($recursiveMerge)
{
$this->filterParams = array_merge_recursive($this->filterParams, $fields);
}
else
{
$this->filterParams = array_merge($this->filterParams, $fields);
}
$this->addCacheAdditionalId($fields);
}
} | [
"public",
"function",
"addGlobalFilters",
"(",
"array",
"$",
"fields",
",",
"$",
"recursiveMerge",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
"&&",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"if",
"(",
"$",
"recursiveMerge",
")",
"{",
"$",
"this",
"->",
"filterParams",
"=",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"filterParams",
",",
"$",
"fields",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"filterParams",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"filterParams",
",",
"$",
"fields",
")",
";",
"}",
"$",
"this",
"->",
"addCacheAdditionalId",
"(",
"$",
"fields",
")",
";",
"}",
"}"
] | Add new fields to global filter
@param array $fields Array with fields
@param bool $recursiveMerge If true, $fields will be recursive merged with
other parameters (used array_merge_recursive()), otherwise not recursive merge (used array_merge()). | [
"Add",
"new",
"fields",
"to",
"global",
"filter"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L524-L539 |
35,894 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.addParamsGrouping | public function addParamsGrouping($fields = [])
{
if (is_array($fields) && !empty($fields))
{
$this->groupingParams = array_merge(is_array($this->groupingParams) ? $this->groupingParams : [], $fields);
}
} | php | public function addParamsGrouping($fields = [])
{
if (is_array($fields) && !empty($fields))
{
$this->groupingParams = array_merge(is_array($this->groupingParams) ? $this->groupingParams : [], $fields);
}
} | [
"public",
"function",
"addParamsGrouping",
"(",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
"&&",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"this",
"->",
"groupingParams",
"=",
"array_merge",
"(",
"is_array",
"(",
"$",
"this",
"->",
"groupingParams",
")",
"?",
"$",
"this",
"->",
"groupingParams",
":",
"[",
"]",
",",
"$",
"fields",
")",
";",
"}",
"}"
] | Add parameters to grouping
@param array $fields
@uses groupingParams | [
"Add",
"parameters",
"to",
"grouping"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L547-L553 |
35,895 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.addParamsNavStart | public function addParamsNavStart($params = [])
{
if (is_array($params) && !empty($params))
{
$this->navStartParams = array_merge(is_array($this->navStartParams) ? $this->navStartParams : array(), $params);
}
} | php | public function addParamsNavStart($params = [])
{
if (is_array($params) && !empty($params))
{
$this->navStartParams = array_merge(is_array($this->navStartParams) ? $this->navStartParams : array(), $params);
}
} | [
"public",
"function",
"addParamsNavStart",
"(",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"params",
")",
"&&",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"navStartParams",
"=",
"array_merge",
"(",
"is_array",
"(",
"$",
"this",
"->",
"navStartParams",
")",
"?",
"$",
"this",
"->",
"navStartParams",
":",
"array",
"(",
")",
",",
"$",
"params",
")",
";",
"}",
"}"
] | Add parameters to pagination settings
@param array $params
@uses navStartParams | [
"Add",
"parameters",
"to",
"pagination",
"settings"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L561-L567 |
35,896 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.addParamsSelected | public function addParamsSelected($fields = null, $props = null)
{
if (is_array($fields) && !empty($fields))
{
$this->arParams['SELECT_FIELDS'] = array_merge($this->arParams['SELECT_FIELDS'], $fields);
}
if (is_array($props) && !empty($props))
{
$this->arParams['SELECT_PROPS'] = array_merge($this->arParams['SELECT_PROPS'], $props);
}
} | php | public function addParamsSelected($fields = null, $props = null)
{
if (is_array($fields) && !empty($fields))
{
$this->arParams['SELECT_FIELDS'] = array_merge($this->arParams['SELECT_FIELDS'], $fields);
}
if (is_array($props) && !empty($props))
{
$this->arParams['SELECT_PROPS'] = array_merge($this->arParams['SELECT_PROPS'], $props);
}
} | [
"public",
"function",
"addParamsSelected",
"(",
"$",
"fields",
"=",
"null",
",",
"$",
"props",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
"&&",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"this",
"->",
"arParams",
"[",
"'SELECT_FIELDS'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'SELECT_FIELDS'",
"]",
",",
"$",
"fields",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"props",
")",
"&&",
"!",
"empty",
"(",
"$",
"props",
")",
")",
"{",
"$",
"this",
"->",
"arParams",
"[",
"'SELECT_PROPS'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'SELECT_PROPS'",
"]",
",",
"$",
"props",
")",
";",
"}",
"}"
] | Add selected fields and properties to parameters
@param array $fields
@param array $props | [
"Add",
"selected",
"fields",
"and",
"properties",
"to",
"parameters"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L575-L586 |
35,897 | bitrix-expert/bbc-module | lib/traits/elements.php | Elements.processingElementsResult | protected function processingElementsResult($element)
{
$arElement = $element;
if ($this->arParams['RESULT_PROCESSING_MODE'] === 'EXTENDED')
{
$arElement = $element->GetFields();
$arElement['PROPS'] = $element->GetProperties();
}
elseif (!empty($this->arParams['SELECT_PROPS']))
{
foreach ($this->arParams['SELECT_PROPS'] as $propCode)
{
if (trim($propCode))
{
$arProp = explode('.', $propCode);
$propCode = array_shift($arProp);
$propValue = $element['PROPERTY_'.$propCode.'_VALUE'];
$propDescr = $element['PROPERTY_'.$propCode.'_DESCRIPTION'];
if ($propValue)
{
$arElement['PROPS'][$propCode]['VALUE'] = $propValue;
}
if ($propDescr)
{
$arElement['PROPS'][$propCode]['DESCRIPTION'] = $propDescr;
}
if (!empty($arElement['PROPS'][$propCode]))
{
foreach ($arProp as $field)
{
$arElement['PROPS'][$propCode]['LINKED'][$field] = $element['PROPERTY_'.$propCode.'_'.$field];
}
}
}
}
}
if ($arElement = $this->prepareElementsResult($arElement))
{
return $arElement;
}
else
{
return false;
}
} | php | protected function processingElementsResult($element)
{
$arElement = $element;
if ($this->arParams['RESULT_PROCESSING_MODE'] === 'EXTENDED')
{
$arElement = $element->GetFields();
$arElement['PROPS'] = $element->GetProperties();
}
elseif (!empty($this->arParams['SELECT_PROPS']))
{
foreach ($this->arParams['SELECT_PROPS'] as $propCode)
{
if (trim($propCode))
{
$arProp = explode('.', $propCode);
$propCode = array_shift($arProp);
$propValue = $element['PROPERTY_'.$propCode.'_VALUE'];
$propDescr = $element['PROPERTY_'.$propCode.'_DESCRIPTION'];
if ($propValue)
{
$arElement['PROPS'][$propCode]['VALUE'] = $propValue;
}
if ($propDescr)
{
$arElement['PROPS'][$propCode]['DESCRIPTION'] = $propDescr;
}
if (!empty($arElement['PROPS'][$propCode]))
{
foreach ($arProp as $field)
{
$arElement['PROPS'][$propCode]['LINKED'][$field] = $element['PROPERTY_'.$propCode.'_'.$field];
}
}
}
}
}
if ($arElement = $this->prepareElementsResult($arElement))
{
return $arElement;
}
else
{
return false;
}
} | [
"protected",
"function",
"processingElementsResult",
"(",
"$",
"element",
")",
"{",
"$",
"arElement",
"=",
"$",
"element",
";",
"if",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'RESULT_PROCESSING_MODE'",
"]",
"===",
"'EXTENDED'",
")",
"{",
"$",
"arElement",
"=",
"$",
"element",
"->",
"GetFields",
"(",
")",
";",
"$",
"arElement",
"[",
"'PROPS'",
"]",
"=",
"$",
"element",
"->",
"GetProperties",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'SELECT_PROPS'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"arParams",
"[",
"'SELECT_PROPS'",
"]",
"as",
"$",
"propCode",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"propCode",
")",
")",
"{",
"$",
"arProp",
"=",
"explode",
"(",
"'.'",
",",
"$",
"propCode",
")",
";",
"$",
"propCode",
"=",
"array_shift",
"(",
"$",
"arProp",
")",
";",
"$",
"propValue",
"=",
"$",
"element",
"[",
"'PROPERTY_'",
".",
"$",
"propCode",
".",
"'_VALUE'",
"]",
";",
"$",
"propDescr",
"=",
"$",
"element",
"[",
"'PROPERTY_'",
".",
"$",
"propCode",
".",
"'_DESCRIPTION'",
"]",
";",
"if",
"(",
"$",
"propValue",
")",
"{",
"$",
"arElement",
"[",
"'PROPS'",
"]",
"[",
"$",
"propCode",
"]",
"[",
"'VALUE'",
"]",
"=",
"$",
"propValue",
";",
"}",
"if",
"(",
"$",
"propDescr",
")",
"{",
"$",
"arElement",
"[",
"'PROPS'",
"]",
"[",
"$",
"propCode",
"]",
"[",
"'DESCRIPTION'",
"]",
"=",
"$",
"propDescr",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"arElement",
"[",
"'PROPS'",
"]",
"[",
"$",
"propCode",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"arProp",
"as",
"$",
"field",
")",
"{",
"$",
"arElement",
"[",
"'PROPS'",
"]",
"[",
"$",
"propCode",
"]",
"[",
"'LINKED'",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"element",
"[",
"'PROPERTY_'",
".",
"$",
"propCode",
".",
"'_'",
".",
"$",
"field",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"arElement",
"=",
"$",
"this",
"->",
"prepareElementsResult",
"(",
"$",
"arElement",
")",
")",
"{",
"return",
"$",
"arElement",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Processing request of the elements
@param \CIBlockResult $element
@return array | [
"Processing",
"request",
"of",
"the",
"elements"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/traits/elements.php#L754-L803 |
35,898 | bitrix-expert/bbc-module | lib/basis.php | Basis.executeTraits | private function executeTraits($type)
{
if (empty($this->usedTraits))
{
return;
}
switch ($type)
{
case 'prolog':
$type = 'Prolog';
break;
case 'main':
$type = 'Main';
break;
default:
$type = 'Epilog';
break;
}
foreach ($this->usedTraits as $trait => $name)
{
$method = 'execute'.$type.$name;
if (method_exists($trait, $method))
{
$this->$method();
}
}
} | php | private function executeTraits($type)
{
if (empty($this->usedTraits))
{
return;
}
switch ($type)
{
case 'prolog':
$type = 'Prolog';
break;
case 'main':
$type = 'Main';
break;
default:
$type = 'Epilog';
break;
}
foreach ($this->usedTraits as $trait => $name)
{
$method = 'execute'.$type.$name;
if (method_exists($trait, $method))
{
$this->$method();
}
}
} | [
"private",
"function",
"executeTraits",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"usedTraits",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'prolog'",
":",
"$",
"type",
"=",
"'Prolog'",
";",
"break",
";",
"case",
"'main'",
":",
"$",
"type",
"=",
"'Main'",
";",
"break",
";",
"default",
":",
"$",
"type",
"=",
"'Epilog'",
";",
"break",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"usedTraits",
"as",
"$",
"trait",
"=>",
"$",
"name",
")",
"{",
"$",
"method",
"=",
"'execute'",
".",
"$",
"type",
".",
"$",
"name",
";",
"if",
"(",
"method_exists",
"(",
"$",
"trait",
",",
"$",
"method",
")",
")",
"{",
"$",
"this",
"->",
"$",
"method",
"(",
")",
";",
"}",
"}",
"}"
] | Executing methods prolog, getResult and epilog included traits
@param string $type prolog, getResult or epilog | [
"Executing",
"methods",
"prolog",
"getResult",
"and",
"epilog",
"included",
"traits"
] | cc51b307e91b88ef8658e34a500ec4134be03689 | https://github.com/bitrix-expert/bbc-module/blob/cc51b307e91b88ef8658e34a500ec4134be03689/lib/basis.php#L34-L65 |
35,899 | tipsyphp/tipsy | src/Resource.php | Resource.load | public function load($id = null) {
// fill the object with blank properties based on the fields of that table
$fields = $this->fields();
foreach ($fields as $key => $field) {
$this->{$key} = $this->{$key} ? $this->{$key} : '';
}
if (!$id && $this->dbId()) {
$id = $this->dbId();
}
if (is_object($id)) {
$node = $id;
} elseif (is_array($id)) {
$node = (object)$id;
} elseif ($id) {
if (!$node) {
$node = (object)$this->db()->get('select * from `' . $this->table() . '` where `'.$this->idVar().'` = ? limit 1', [$id])[0];
}
}
if (!$node) {
$node = new Model;
}
if (isset($node)) {
foreach(get_object_vars($node) as $var => $value) {
$this->$var = $value;
}
}
foreach ($this->fields() as $field) {
switch ($field->type) {
case 'int':
$this->{$field->field} = (int)$this->{$field->field};
break;
case 'boolean':
$this->{$field->field} = $this->{$field->field} ? true : false;
break;
}
}
if ($this->tipsy() && $this->tipsy()->config()['tipsy']['factory'] !== false) {
$this->tipsy()->factory($this);
}
return $this;
} | php | public function load($id = null) {
// fill the object with blank properties based on the fields of that table
$fields = $this->fields();
foreach ($fields as $key => $field) {
$this->{$key} = $this->{$key} ? $this->{$key} : '';
}
if (!$id && $this->dbId()) {
$id = $this->dbId();
}
if (is_object($id)) {
$node = $id;
} elseif (is_array($id)) {
$node = (object)$id;
} elseif ($id) {
if (!$node) {
$node = (object)$this->db()->get('select * from `' . $this->table() . '` where `'.$this->idVar().'` = ? limit 1', [$id])[0];
}
}
if (!$node) {
$node = new Model;
}
if (isset($node)) {
foreach(get_object_vars($node) as $var => $value) {
$this->$var = $value;
}
}
foreach ($this->fields() as $field) {
switch ($field->type) {
case 'int':
$this->{$field->field} = (int)$this->{$field->field};
break;
case 'boolean':
$this->{$field->field} = $this->{$field->field} ? true : false;
break;
}
}
if ($this->tipsy() && $this->tipsy()->config()['tipsy']['factory'] !== false) {
$this->tipsy()->factory($this);
}
return $this;
} | [
"public",
"function",
"load",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"// fill the object with blank properties based on the fields of that table",
"$",
"fields",
"=",
"$",
"this",
"->",
"fields",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
"?",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
":",
"''",
";",
"}",
"if",
"(",
"!",
"$",
"id",
"&&",
"$",
"this",
"->",
"dbId",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"dbId",
"(",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"id",
")",
")",
"{",
"$",
"node",
"=",
"$",
"id",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"id",
")",
")",
"{",
"$",
"node",
"=",
"(",
"object",
")",
"$",
"id",
";",
"}",
"elseif",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"$",
"node",
")",
"{",
"$",
"node",
"=",
"(",
"object",
")",
"$",
"this",
"->",
"db",
"(",
")",
"->",
"get",
"(",
"'select * from `'",
".",
"$",
"this",
"->",
"table",
"(",
")",
".",
"'` where `'",
".",
"$",
"this",
"->",
"idVar",
"(",
")",
".",
"'` = ? limit 1'",
",",
"[",
"$",
"id",
"]",
")",
"[",
"0",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"node",
")",
"{",
"$",
"node",
"=",
"new",
"Model",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"node",
")",
")",
"{",
"foreach",
"(",
"get_object_vars",
"(",
"$",
"node",
")",
"as",
"$",
"var",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"$",
"var",
"=",
"$",
"value",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"switch",
"(",
"$",
"field",
"->",
"type",
")",
"{",
"case",
"'int'",
":",
"$",
"this",
"->",
"{",
"$",
"field",
"->",
"field",
"}",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"{",
"$",
"field",
"->",
"field",
"}",
";",
"break",
";",
"case",
"'boolean'",
":",
"$",
"this",
"->",
"{",
"$",
"field",
"->",
"field",
"}",
"=",
"$",
"this",
"->",
"{",
"$",
"field",
"->",
"field",
"}",
"?",
"true",
":",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"tipsy",
"(",
")",
"&&",
"$",
"this",
"->",
"tipsy",
"(",
")",
"->",
"config",
"(",
")",
"[",
"'tipsy'",
"]",
"[",
"'factory'",
"]",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"tipsy",
"(",
")",
"->",
"factory",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Load the object with properties
Passing in an object will populate $this with the current vars of that object
as public properties. Passing in an int id will load the object with the
table and key associated with the object.
@param $id object|int | [
"Load",
"the",
"object",
"with",
"properties"
] | 9d46d31dd6d29664a0dd5f85bd6a96d8b21e24af | https://github.com/tipsyphp/tipsy/blob/9d46d31dd6d29664a0dd5f85bd6a96d8b21e24af/src/Resource.php#L251-L300 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.