repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
frdl/webfan | .ApplicationComposer/lib/frdl/xGlobal/fexe.php | fexe.stream_open | public function stream_open($url, $mode, $options = STREAM_REPORT_ERRORS, &$opened_path = null){
$u = parse_url($url);
$this->file = str_replace('/', DIRECTORY_SEPARATOR, $u['path']);
$this->file_offset = $u['port'];
$this->host = $u['host'];
$this->mode = $mode;
$this->IO = fopen($this->file, $this->mode);
if(!$this->IO)return false;
fseek($this->IO, $this->file_offset);
$this->pos = $this->stream_tell();
$this->eof = $this->stream_eof();
return true;
} | php | public function stream_open($url, $mode, $options = STREAM_REPORT_ERRORS, &$opened_path = null){
$u = parse_url($url);
$this->file = str_replace('/', DIRECTORY_SEPARATOR, $u['path']);
$this->file_offset = $u['port'];
$this->host = $u['host'];
$this->mode = $mode;
$this->IO = fopen($this->file, $this->mode);
if(!$this->IO)return false;
fseek($this->IO, $this->file_offset);
$this->pos = $this->stream_tell();
$this->eof = $this->stream_eof();
return true;
} | [
"public",
"function",
"stream_open",
"(",
"$",
"url",
",",
"$",
"mode",
",",
"$",
"options",
"=",
"STREAM_REPORT_ERRORS",
",",
"&",
"$",
"opened_path",
"=",
"null",
")",
"{",
"$",
"u",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"this",
"->",
"file",
"=",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"u",
"[",
"'path'",
"]",
")",
";",
"$",
"this",
"->",
"file_offset",
"=",
"$",
"u",
"[",
"'port'",
"]",
";",
"$",
"this",
"->",
"host",
"=",
"$",
"u",
"[",
"'host'",
"]",
";",
"$",
"this",
"->",
"mode",
"=",
"$",
"mode",
";",
"$",
"this",
"->",
"IO",
"=",
"fopen",
"(",
"$",
"this",
"->",
"file",
",",
"$",
"this",
"->",
"mode",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"IO",
")",
"return",
"false",
";",
"fseek",
"(",
"$",
"this",
"->",
"IO",
",",
"$",
"this",
"->",
"file_offset",
")",
";",
"$",
"this",
"->",
"pos",
"=",
"$",
"this",
"->",
"stream_tell",
"(",
")",
";",
"$",
"this",
"->",
"eof",
"=",
"$",
"this",
"->",
"stream_eof",
"(",
")",
";",
"return",
"true",
";",
"}"
] | webfan://namespace.vendor.applicationname.fexe:__COMPILER_HALT_OFFSET__/__FILE__
@param undefined $url
@param undefined $mode
@param undefined $options
@param undefined $opened_path
@return | [
"webfan",
":",
"//",
"namespace",
".",
"vendor",
".",
"applicationname",
".",
"fexe",
":",
"__COMPILER_HALT_OFFSET__",
"/",
"__FILE__",
"@param",
"undefined",
"$url",
"@param",
"undefined",
"$mode",
"@param",
"undefined",
"$options",
"@param",
"undefined",
"$opened_path"
] | train | https://github.com/frdl/webfan/blob/84d270377685224e891cd9d571b103b36f05b845/.ApplicationComposer/lib/frdl/xGlobal/fexe.php#L394-L411 |
frdl/webfan | .ApplicationComposer/lib/frdl/xGlobal/fexe.php | fexe.read | public function read(&$data, $delimiters = '#', \closure $func, &$out = null){
$ti = new \frdl\common\TokenIterator($data, $delimiters);
foreach ($ti as $count => $token) {
$func($token);
}
return $this;
} | php | public function read(&$data, $delimiters = '#', \closure $func, &$out = null){
$ti = new \frdl\common\TokenIterator($data, $delimiters);
foreach ($ti as $count => $token) {
$func($token);
}
return $this;
} | [
"public",
"function",
"read",
"(",
"&",
"$",
"data",
",",
"$",
"delimiters",
"=",
"'#'",
",",
"\\",
"closure",
"$",
"func",
",",
"&",
"$",
"out",
"=",
"null",
")",
"{",
"$",
"ti",
"=",
"new",
"\\",
"frdl",
"\\",
"common",
"\\",
"TokenIterator",
"(",
"$",
"data",
",",
"$",
"delimiters",
")",
";",
"foreach",
"(",
"$",
"ti",
"as",
"$",
"count",
"=>",
"$",
"token",
")",
"{",
"$",
"func",
"(",
"$",
"token",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | e.g.:
$data = $this->getFileData();
$this->read($data, '#', (function($token) use (&$out) {
$out.= trim($token).'<br />';
}));
echo $out;
@param undefined $data
@param undefined $delimiters
@param undefined $func
@return | [
"e",
".",
"g",
".",
":",
"$data",
"=",
"$this",
"-",
">",
"getFileData",
"()",
";",
"$this",
"-",
">",
"read",
"(",
"$data",
"#",
"(",
"function",
"(",
"$token",
")",
"use",
"(",
"&$out",
")",
"{",
"$out",
".",
"=",
"trim",
"(",
"$token",
")",
".",
"<br",
"/",
">",
";",
"}",
"))",
";",
"echo",
"$out",
";",
"@param",
"undefined",
"$data",
"@param",
"undefined",
"$delimiters",
"@param",
"undefined",
"$func"
] | train | https://github.com/frdl/webfan/blob/84d270377685224e891cd9d571b103b36f05b845/.ApplicationComposer/lib/frdl/xGlobal/fexe.php#L615-L621 |
frdl/webfan | .ApplicationComposer/lib/frdl/xGlobal/fexe.php | fexe.getFileData | public function getFileData($file = null, $offset = null){
if(null === $file)$file = &$this->file;
if(null === $offset)$offset = $this->file_offset;
$this->IO = fopen($file, 'r');
fseek($this->IO, $offset);
try{
$this->raw = stream_get_contents($this->IO);
}catch(\Exception $e){
$this->raw = '';
trigger_error($e->getMessage(), $this->e_level);
}
return $this->raw;
} | php | public function getFileData($file = null, $offset = null){
if(null === $file)$file = &$this->file;
if(null === $offset)$offset = $this->file_offset;
$this->IO = fopen($file, 'r');
fseek($this->IO, $offset);
try{
$this->raw = stream_get_contents($this->IO);
}catch(\Exception $e){
$this->raw = '';
trigger_error($e->getMessage(), $this->e_level);
}
return $this->raw;
} | [
"public",
"function",
"getFileData",
"(",
"$",
"file",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"file",
")",
"$",
"file",
"=",
"&",
"$",
"this",
"->",
"file",
";",
"if",
"(",
"null",
"===",
"$",
"offset",
")",
"$",
"offset",
"=",
"$",
"this",
"->",
"file_offset",
";",
"$",
"this",
"->",
"IO",
"=",
"fopen",
"(",
"$",
"file",
",",
"'r'",
")",
";",
"fseek",
"(",
"$",
"this",
"->",
"IO",
",",
"$",
"offset",
")",
";",
"try",
"{",
"$",
"this",
"->",
"raw",
"=",
"stream_get_contents",
"(",
"$",
"this",
"->",
"IO",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"raw",
"=",
"''",
";",
"trigger_error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"this",
"->",
"e_level",
")",
";",
"}",
"return",
"$",
"this",
"->",
"raw",
";",
"}"
] | read file from offset
@param undefined $file __FILE__
@param undefined $offset __COMPILER_HALT_OFFSET__
@return string | [
"read",
"file",
"from",
"offset"
] | train | https://github.com/frdl/webfan/blob/84d270377685224e891cd9d571b103b36f05b845/.ApplicationComposer/lib/frdl/xGlobal/fexe.php#L651-L664 |
frdl/webfan | .ApplicationComposer/lib/frdl/xGlobal/fexe.php | fexe.unserialize | final public function unserialize(&$var){
try{
$i=0;return $this->_unserialize($var,false,$i);
}catch(Exception $e) {
trigger_error($e->getMessage(). ' in '.__CLASS__.'::'.__METHOD__.' line '.__LINE__,E_USER_WARNING);
return;
}
} | php | final public function unserialize(&$var){
try{
$i=0;return $this->_unserialize($var,false,$i);
}catch(Exception $e) {
trigger_error($e->getMessage(). ' in '.__CLASS__.'::'.__METHOD__.' line '.__LINE__,E_USER_WARNING);
return;
}
} | [
"final",
"public",
"function",
"unserialize",
"(",
"&",
"$",
"var",
")",
"{",
"try",
"{",
"$",
"i",
"=",
"0",
";",
"return",
"$",
"this",
"->",
"_unserialize",
"(",
"$",
"var",
",",
"false",
",",
"$",
"i",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"trigger_error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"' in '",
".",
"__CLASS__",
".",
"'::'",
".",
"__METHOD__",
".",
"' line '",
".",
"__LINE__",
",",
"E_USER_WARNING",
")",
";",
"return",
";",
"}",
"}"
] | @component
bin
original class bserialize:
Copyright (c) 2009, PHPServer
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Cesar Rodas nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY CESAR RODAS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL CESAR RODAS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | [
"@component",
"bin",
"original",
"class",
"bserialize",
":",
"Copyright",
"(",
"c",
")",
"2009",
"PHPServer",
"All",
"rights",
"reserved",
"."
] | train | https://github.com/frdl/webfan/blob/84d270377685224e891cd9d571b103b36f05b845/.ApplicationComposer/lib/frdl/xGlobal/fexe.php#L713-L721 |
zhouyl/mellivora | Mellivora/Database/Console/Migrations/RefreshCommand.php | RefreshCommand.runRollback | protected function runRollback($database, $path, $step, $force)
{
$this->call('migrate:rollback', [
'--database' => $database,
'--path' => $path,
'--step' => $step,
'--force' => $force,
]);
} | php | protected function runRollback($database, $path, $step, $force)
{
$this->call('migrate:rollback', [
'--database' => $database,
'--path' => $path,
'--step' => $step,
'--force' => $force,
]);
} | [
"protected",
"function",
"runRollback",
"(",
"$",
"database",
",",
"$",
"path",
",",
"$",
"step",
",",
"$",
"force",
")",
"{",
"$",
"this",
"->",
"call",
"(",
"'migrate:rollback'",
",",
"[",
"'--database'",
"=>",
"$",
"database",
",",
"'--path'",
"=>",
"$",
"path",
",",
"'--step'",
"=>",
"$",
"step",
",",
"'--force'",
"=>",
"$",
"force",
",",
"]",
")",
";",
"}"
] | Run the rollback command.
@param string $database
@param string $path
@param bool $step
@param bool $force
@return void | [
"Run",
"the",
"rollback",
"command",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Console/Migrations/RefreshCommand.php#L82-L90 |
oroinc/OroLayoutComponent | Extension/Theme/Model/ThemeFactory.php | ThemeFactory.create | public function create($themeName, array $themeDefinition)
{
$theme = new Theme(
$themeName,
isset($themeDefinition['parent']) ? $themeDefinition['parent'] : null
);
$this->applyThemeProperties($theme, $themeDefinition);
if (isset($themeDefinition['config'])) {
$theme->setConfig($themeDefinition['config']);
}
$this->addPageTemplatesConfig($themeDefinition, $theme);
return $theme;
} | php | public function create($themeName, array $themeDefinition)
{
$theme = new Theme(
$themeName,
isset($themeDefinition['parent']) ? $themeDefinition['parent'] : null
);
$this->applyThemeProperties($theme, $themeDefinition);
if (isset($themeDefinition['config'])) {
$theme->setConfig($themeDefinition['config']);
}
$this->addPageTemplatesConfig($themeDefinition, $theme);
return $theme;
} | [
"public",
"function",
"create",
"(",
"$",
"themeName",
",",
"array",
"$",
"themeDefinition",
")",
"{",
"$",
"theme",
"=",
"new",
"Theme",
"(",
"$",
"themeName",
",",
"isset",
"(",
"$",
"themeDefinition",
"[",
"'parent'",
"]",
")",
"?",
"$",
"themeDefinition",
"[",
"'parent'",
"]",
":",
"null",
")",
";",
"$",
"this",
"->",
"applyThemeProperties",
"(",
"$",
"theme",
",",
"$",
"themeDefinition",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"themeDefinition",
"[",
"'config'",
"]",
")",
")",
"{",
"$",
"theme",
"->",
"setConfig",
"(",
"$",
"themeDefinition",
"[",
"'config'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"addPageTemplatesConfig",
"(",
"$",
"themeDefinition",
",",
"$",
"theme",
")",
";",
"return",
"$",
"theme",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/Model/ThemeFactory.php#L10-L26 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | topic.sync | function sync()
{
global $db;
if(!$this->topic_id)
{
//topic does not exist yet
return;
}
sync('topic', 'topic_id', $this->topic_id, false, true);
if($this->forum_id > 0)
{
sync('forum', 'forum_id', $this->forum_id);
}
$this->refresh_statvars();
} | php | function sync()
{
global $db;
if(!$this->topic_id)
{
//topic does not exist yet
return;
}
sync('topic', 'topic_id', $this->topic_id, false, true);
if($this->forum_id > 0)
{
sync('forum', 'forum_id', $this->forum_id);
}
$this->refresh_statvars();
} | [
"function",
"sync",
"(",
")",
"{",
"global",
"$",
"db",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"topic_id",
")",
"{",
"//topic does not exist yet",
"return",
";",
"}",
"sync",
"(",
"'topic'",
",",
"'topic_id'",
",",
"$",
"this",
"->",
"topic_id",
",",
"false",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"forum_id",
">",
"0",
")",
"{",
"sync",
"(",
"'forum'",
",",
"'forum_id'",
",",
"$",
"this",
"->",
"forum_id",
")",
";",
"}",
"$",
"this",
"->",
"refresh_statvars",
"(",
")",
";",
"}"
] | TODO | [
"TODO"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L544-L561 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | topic.reset_poll | function reset_poll()
{
global $db;
$db->sql_transaction('begin');
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
SET poll_option_total = 0
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
$sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
$this->poll_start = time();
$this->poll_last_vote = 0;
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET poll_start = ' . $this->poll_start . ',
poll_last_vote = 0
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
$db->sql_transaction('commit');
} | php | function reset_poll()
{
global $db;
$db->sql_transaction('begin');
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
SET poll_option_total = 0
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
$sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
$this->poll_start = time();
$this->poll_last_vote = 0;
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET poll_start = ' . $this->poll_start . ',
poll_last_vote = 0
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
$db->sql_transaction('commit');
} | [
"function",
"reset_poll",
"(",
")",
"{",
"global",
"$",
"db",
";",
"$",
"db",
"->",
"sql_transaction",
"(",
"'begin'",
")",
";",
"$",
"sql",
"=",
"'UPDATE '",
".",
"POLL_OPTIONS_TABLE",
".",
"'\n\t\t\tSET poll_option_total = 0\n\t\t\tWHERE topic_id = '",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"sql",
"=",
"'DELETE FROM '",
".",
"POLL_VOTES_TABLE",
".",
"'\n\t\t\tWHERE topic_id = '",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"poll_start",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"poll_last_vote",
"=",
"0",
";",
"$",
"sql",
"=",
"'UPDATE '",
".",
"TOPICS_TABLE",
".",
"'\n\t\t\tSET poll_start = '",
".",
"$",
"this",
"->",
"poll_start",
".",
"',\n\t\t\t\tpoll_last_vote = 0\n\t\t\tWHERE topic_id = '",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"db",
"->",
"sql_transaction",
"(",
"'commit'",
")",
";",
"}"
] | clears all votes (restarts poll) | [
"clears",
"all",
"votes",
"(",
"restarts",
"poll",
")"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L628-L651 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | post.get | static function get($post_id)
{
global $db;
//$sql = "SELECT p.*, t.topic_first_post_id, t.topic_last_post_id
// FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
// WHERE p.post_id=" . intval($this->post_id) . " AND t.topic_id = p.topic_id";
$sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=" . intval($post_id);
$result = $db->sql_query($sql);
$post_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if(!$post_data)
{
//post does not exist, return false
return false;
}
return post::from_array($post_data);
} | php | static function get($post_id)
{
global $db;
//$sql = "SELECT p.*, t.topic_first_post_id, t.topic_last_post_id
// FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
// WHERE p.post_id=" . intval($this->post_id) . " AND t.topic_id = p.topic_id";
$sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=" . intval($post_id);
$result = $db->sql_query($sql);
$post_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if(!$post_data)
{
//post does not exist, return false
return false;
}
return post::from_array($post_data);
} | [
"static",
"function",
"get",
"(",
"$",
"post_id",
")",
"{",
"global",
"$",
"db",
";",
"//$sql = \"SELECT p.*, t.topic_first_post_id, t.topic_last_post_id",
"//\t\tFROM \" . POSTS_TABLE . \" p, \" . TOPICS_TABLE . \" t",
"//\t\tWHERE p.post_id=\" . intval($this->post_id) . \" AND t.topic_id = p.topic_id\";",
"$",
"sql",
"=",
"\"SELECT * FROM \"",
".",
"POSTS_TABLE",
".",
"\" WHERE post_id=\"",
".",
"intval",
"(",
"$",
"post_id",
")",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"post_data",
"=",
"$",
"db",
"->",
"sql_fetchrow",
"(",
"$",
"result",
")",
";",
"$",
"db",
"->",
"sql_freeresult",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"$",
"post_data",
")",
"{",
"//post does not exist, return false",
"return",
"false",
";",
"}",
"return",
"post",
"::",
"from_array",
"(",
"$",
"post_data",
")",
";",
"}"
] | static method, loads the post with a given post_id from database.
returns false if the post does not exist | [
"static",
"method",
"loads",
"the",
"post",
"with",
"a",
"given",
"post_id",
"from",
"database",
".",
"returns",
"false",
"if",
"the",
"post",
"does",
"not",
"exist"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L776-L795 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | post.get_topic | function get_topic($all_posts = false)
{
if(!$this->_topic)
{
if($this->post_id)
{
//existing post, load existing topic
$this->_topic = topic::get($this->topic_id, $all_posts);
//insert $this into topic->posts array
if($all_posts)
{
//this post was also loaded from database, replace it with $this
for($i=0; $i<sizeof($this->_topic->posts); $i++)
{
if($this->_topic->posts[$i]->post_id == $this->post_id)
{
//found it
$this->_topic->posts[$i] = &$this;
break;
}
}
}
else
{
//no posts were loaded in topic::get(), add our post to topic->posts
$this->_topic->posts[] = &$this;
}
}
else
{
//new post, generate topic
$this->_topic = topic::from_post($this);
}
}
return $this->_topic;
} | php | function get_topic($all_posts = false)
{
if(!$this->_topic)
{
if($this->post_id)
{
//existing post, load existing topic
$this->_topic = topic::get($this->topic_id, $all_posts);
//insert $this into topic->posts array
if($all_posts)
{
//this post was also loaded from database, replace it with $this
for($i=0; $i<sizeof($this->_topic->posts); $i++)
{
if($this->_topic->posts[$i]->post_id == $this->post_id)
{
//found it
$this->_topic->posts[$i] = &$this;
break;
}
}
}
else
{
//no posts were loaded in topic::get(), add our post to topic->posts
$this->_topic->posts[] = &$this;
}
}
else
{
//new post, generate topic
$this->_topic = topic::from_post($this);
}
}
return $this->_topic;
} | [
"function",
"get_topic",
"(",
"$",
"all_posts",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_topic",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"post_id",
")",
"{",
"//existing post, load existing topic",
"$",
"this",
"->",
"_topic",
"=",
"topic",
"::",
"get",
"(",
"$",
"this",
"->",
"topic_id",
",",
"$",
"all_posts",
")",
";",
"//insert $this into topic->posts array",
"if",
"(",
"$",
"all_posts",
")",
"{",
"//this post was also loaded from database, replace it with $this",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"this",
"->",
"_topic",
"->",
"posts",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_topic",
"->",
"posts",
"[",
"$",
"i",
"]",
"->",
"post_id",
"==",
"$",
"this",
"->",
"post_id",
")",
"{",
"//found it",
"$",
"this",
"->",
"_topic",
"->",
"posts",
"[",
"$",
"i",
"]",
"=",
"&",
"$",
"this",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"//no posts were loaded in topic::get(), add our post to topic->posts",
"$",
"this",
"->",
"_topic",
"->",
"posts",
"[",
"]",
"=",
"&",
"$",
"this",
";",
"}",
"}",
"else",
"{",
"//new post, generate topic",
"$",
"this",
"->",
"_topic",
"=",
"topic",
"::",
"from_post",
"(",
"$",
"this",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_topic",
";",
"}"
] | loads and returns the topic for this post
@param all_posts whether to load all other posts of the topic into topic->posts | [
"loads",
"and",
"returns",
"the",
"topic",
"for",
"this",
"post"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L865-L901 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | post.merge_into | function merge_into($topic_id)
{
move_posts($this->post_id, $topic_id);
$this->topic_id = $topic_id;
$this->_topic = null;
} | php | function merge_into($topic_id)
{
move_posts($this->post_id, $topic_id);
$this->topic_id = $topic_id;
$this->_topic = null;
} | [
"function",
"merge_into",
"(",
"$",
"topic_id",
")",
"{",
"move_posts",
"(",
"$",
"this",
"->",
"post_id",
",",
"$",
"topic_id",
")",
";",
"$",
"this",
"->",
"topic_id",
"=",
"$",
"topic_id",
";",
"$",
"this",
"->",
"_topic",
"=",
"null",
";",
"}"
] | moves this post to a different topic. If you want to merge multiple post
into one topic, calling move_posts() directly is recommended. | [
"moves",
"this",
"post",
"to",
"a",
"different",
"topic",
".",
"If",
"you",
"want",
"to",
"merge",
"multiple",
"post",
"into",
"one",
"topic",
"calling",
"move_posts",
"()",
"directly",
"is",
"recommended",
"."
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L931-L936 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | post._submit | function _submit(&$sync)
{
global $config, $db, $auth, $user;
if($sync === false)
{
//submit() was called directly so we need to sync after it
$sync = new syncer();
$exec_sync = true;
}
else
{
//submit() was called by topic->submit(), sync there when everything is done
$exec_sync = false;
}
if(!$this->post_id)
{
//new post, set some default values if not set yet
if(!$this->poster_id) $this->poster_id = $user->data['user_id'];
if(!$this->poster_ip) $this->poster_ip = $user->ip;
if(!$this->post_time) $this->post_time = time();
}
$this->post_subject = truncate_string($this->post_subject);
$sql_data = array(
'poster_id' => $this->poster_id,
'poster_ip' => $this->poster_ip,
'topic_id' => $this->topic_id,
'forum_id' => $this->forum_id,
'post_username' => $this->post_username,
'icon_id' => $this->icon_id,
'post_time' => $this->post_time,
'post_postcount' => $this->post_postcount ? 1 : 0,
'post_visibility' => $this->post_visibility,
'post_reported' => $this->post_reported ? 1 : 0,
'enable_bbcode' => $this->enable_bbcode ? 1 : 0,
'enable_smilies' => $this->enable_smilies ? 1 : 0,
'enable_magic_url' => $this->enable_magic_url ? 1 : 0,
'enable_sig' => $this->enable_sig ? 1 : 0,
'post_subject' => $this->post_subject,
'bbcode_bitfield' => 0,
'bbcode_uid' => '',
'post_text' => $this->post_text,
'post_checksum' => md5($this->post_text),
//'post_attachment' => $this->post_attachment ? 1 : 0,
'post_edit_time' => $this->post_edit_time,
'post_edit_reason' => $this->post_edit_reason,
'post_edit_user' => $this->post_edit_user,
'post_edit_count' => $this->post_edit_count,
'post_edit_locked' => $this->post_edit_locked,
'post_delete_time' => $this->post_delete_time,
'post_delete_reason' => $this->post_delete_reason,
'post_delete_user' => $this->post_delete_user,
);
$flags = '';
generate_text_for_storage($sql_data['post_text'], $sql_data['bbcode_uid'], $sql_data['bbcode_bitfield'], $flags, $this->enable_bbcode, $this->enable_magic_url, $this->enable_smilies);
if($this->post_id && $this->topic_id)
{
//edit
$sql = "SELECT p.*, t.topic_first_post_id, t.topic_last_post_id, t.topic_approved, t.topic_replies
FROM " . POSTS_TABLE . " p
LEFT JOIN " . TOPICS_TABLE . " t ON (t.topic_id = p.topic_id)
WHERE p.post_id=" . intval($this->post_id);
//$sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=" . intval($this->post_id);
$result = $db->sql_query($sql);
$post_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if(!$post_data)
{
trigger_error("post_id={$this->post_id}, but that post does not exist", E_USER_ERROR);
}
//check first/last post
$is_first_post = ($post_data['post_id'] == $post_data['topic_first_post_id']);
$is_last_post = ($post_data['post_id'] == $post_data['topic_last_post_id']);
$db->sql_transaction('begin');
$sql = "UPDATE " . POSTS_TABLE . " SET " . $db->sql_build_array('UPDATE', $sql_data) . " WHERE post_id=" . $this->post_id;
$db->sql_query($sql);
if($this->topic_id != $post_data['topic_id'])
{
//merge into new topic
//get new topic's forum id and first/last post time
$sql = "SELECT forum_id, topic_time, topic_last_post_time
FROM " . TOPICS_TABLE . "
WHERE topic_id = {$this->topic_id}";
$result = $db->sql_query($sql);
$new_topic_data = $db->sql_fetchrow($result);
if(!$new_topic_data)
{
trigger_error("attempted to merge post {$this->post_id} into topic {$this->topic_id}, but that topic does not exist", E_USER_ERROR);
}
//sync forum_posts
//TODO
if($new_topic_data['forum_id'] != $post_data['forum_id'])
{
$sync->add('forum', $post_data['forum_id'], 'forum_posts', $this->post_approved ? -1 : 0);
$sync->add('forum', $new_topic_data['forum_id'], 'forum_posts', $this->post_approved ? 1 : 0);
if($this->forum_id != $new_topic_data['forum_id'])
{
//user changed topic_id but not forum_id, so we saved the wrong one above. correct it via sync
$this->forum_id = $new_topic_data['forum_id'];
$sync->set('post', $this->post_id, 'forum_id', $this->forum_id);
}
}
//sync old topic
$sync->add('topic', $post_data['topic_id'], 'topic_replies', $this->post_approved ? -1 : 0);
$sync->add('topic', $post_data['topic_id'], 'topic_replies_real', -1);
$sync->check_topic_empty($post_data['topic_id']);
//sync new topic
$sync->add('topic', $this->topic_id, 'topic_replies', $this->post_approved ? 1 : 0);
$sync->add('topic', $this->topic_id, 'topic_replies_real', 1);
//sync topic_reported and topic_attachment if applicable
if($post_data['post_reported']) {
$sync->topic_reported($post_data['topic_id']);
}
if($post_data['post_attachment']) {
$sync->topic_attachment($post_data['topic_id']);
}
if($this->post_reported) {
$sync->topic_reported($this->topic_id);
}
if($this->post_attachment) {
$sync->topic_attachment($this->topic_id);
}
if($is_first_post)
{
//this was the first post in the old topic, sync it
$sync->topic_first_post($post_data['topic_id']);
$is_first_post = false; //unset since we dont know status for new topic yet
}
if($is_last_post)
{
//this was the last post in the old topic, sync it
$sync->topic_last_post($post_data['topic_id']);
$sync->forum_last_post($post_data['forum_id']);
$is_last_post = false; //unset since we dont know status for new topic yet
}
if($this->post_time <= $new_topic_data['topic_time'])
{
//this will be the first post in the new topic, sync it
$sync->topic_first_post($this->topic_id);
$is_first_post = true;
}
if($this->post_time >= $new_topic_data['topic_last_post_time'])
{
//this will be the last post in the new topic, sync it
$sync->topic_last_post($this->topic_id);
$sync->forum_last_post($this->topic_id);
$is_last_post = true;
}
}
elseif($is_first_post)
{
$sync->set('topic', $this->topic_id, array(
'icon_id' => $this->icon_id,
'topic_approved' => $this->post_approved,
'topic_title' => $this->post_subject,
'topic_poster' => $this->poster_id,
'topic_time' => $this->post_time
));
}
//check if some statistics relevant flags have been changed
if($this->post_approved != $post_data['post_approved'])
{
//if topic_id was changed, we've already updated it above.
if($this->topic_id == $post_data['topic_id'])
{
if($is_first_post)
{
//first post -> approve/disapprove whole topic if not yet done (should only happen when directly storing the post)
if($this->post_approved != $post_data['topic_approved'])
{
$sync->add('forum', $this->forum_id, 'forum_topics', $this->post_approved ? 1 : -1);
$sync->add('forum', $this->forum_id, 'forum_posts', $this->post_approved ? (1+$post_data['topic_replies']) : -(1+$post_data['topic_replies']));
$sync->forum_last_post($this->forum_id);
//and the total topics+posts
set_config('num_topics', $this->post_approved ? $config['num_topics'] + 1 : $config['num_topics'] - 1, true);
set_config('num_posts', $this->post_approved ? $config['num_posts'] + (1+$post_data['topic_replies']) : $config['num_posts'] - (1+$post_data['topic_replies']), true);
}
}
else
{
//reply
$sync->add('topic', $this->topic_id, 'topic_replies', $this->post_approved ? 1 : -1);
$sync->add('forum', $this->forum_id, 'forum_posts', $this->post_approved ? 1 : -1);
}
}
//update total posts
if(!$is_first_post)
{
set_config('num_posts', $this->post_approved ? $config['num_posts'] + 1 : $config['num_posts'] - 1, true);
}
}
/*if($this->post_postcount != $post_data['post_postcount'] && $this->poster_id != ANONYMOUS)
{
//increase or decrease user_posts
$sync->add('user', $this->poster_id, 'user_posts', $this->post_approved ? 1 : -1);
}*/
if($this->poster_id != $post_data['poster_id'] || $this->post_postcount != $post_data['post_postcount'])
{
if($post_data['post_postcount'] && $post_data['poster_id'] != ANONYMOUS)
{
$sync->add('user', $post_data['poster_id'], 'user_posts', -1);
}
if($this->post_postcount && $this->poster_id != ANONYMOUS)
{
$sync->add('user', $this->poster_id, 'user_posts', 1);
}
}
if($is_first_post)
{
$sync->topic_first_post($this->topic_id);
}
if($is_last_post)
{
$sync->topic_last_post($this->topic_id);
$sync->forum_last_post($this->forum_id);
}
reindex('edit', $this->post_id, $sql_data['post_text'], $this->post_subject, $this->poster_id, $this->forum_id);
$db->sql_transaction('commit');
}
elseif($this->topic_id)
{
//reply
$sql = "SELECT t.*, f.forum_name
FROM " . TOPICS_TABLE . " t
LEFT JOIN " . FORUMS_TABLE . " f ON (f.forum_id = t.forum_id)
WHERE t.topic_id=" . intval($this->topic_id);
$result = $db->sql_query($sql);
$topic_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if(!$topic_data)
{
trigger_error("topic_id={$this->topic_id}, but that topic does not exist", E_USER_ERROR);
}
//we need topic_id and forum_id
$this->forum_id = $topic_data['forum_id'];
$sql_data['forum_id'] = $this->forum_id;
$sql_data['topic_id'] = $this->topic_id;
//make sure we have a post_subject (empty subjects are bad for e.g. approving)
if($this->post_subject == '')
{
$this->post_subject = 'Re: ' . $topic_data['topic_title'];
}
$db->sql_transaction('begin');
//insert post
$sql = "INSERT INTO " . POSTS_TABLE . " " . $db->sql_build_array('INSERT', $sql_data);
$db->sql_query($sql);
$this->post_id = $db->sql_nextid();
//update topic
if(!$sync->new_topic_flag)
{
$sync->add('topic', $this->topic_id, 'topic_replies', $this->post_approved ? 1 : 0);
$sync->add('topic', $this->topic_id, 'topic_replies_real', 1);
$sync->set('topic', $this->topic_id, 'topic_bumped', 0);
$sync->set('topic', $this->topic_id, 'topic_bumper', 0);
}
else
{
$sync->topic_first_post($this->topic_id);
$sync->new_topic_flag = false;
}
$sync->topic_last_post($this->topic_id);
//update forum
if($this->forum_id != 0)
{
$sync->add('forum', $this->forum_id, 'forum_posts', $this->post_approved ? 1 : 0);
$sync->forum_last_post($this->forum_id);
}
if($this->post_postcount)
{
//increase user_posts...
$sync->add('user', $this->poster_id, 'user_posts', 1);
}
if($this->post_approved)
{
//...and total posts
set_config('num_posts', $config['num_posts'] + 1, true);
}
reindex('reply', $this->post_id, $sql_data['post_text'], $this->post_subject, $this->poster_id, $this->forum_id);
$db->sql_transaction('commit');
// Mark this topic as posted to
markread('post', $this->forum_id, $this->topic_id, $this->post_time, $this->poster_id);
// Mark this topic as read
// We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)
markread('topic', $this->forum_id, $this->topic_id, time());
//
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$sql = 'SELECT mark_time
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
AND forum_id = ' . $this->forum_id;
$result = $db->sql_query($sql);
$f_mark_time = (int) $db->sql_fetchfield('mark_time');
$db->sql_freeresult($result);
}
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
{
$f_mark_time = false;
}
if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered'])
{
// Update forum info
$sql = 'SELECT forum_last_post_time
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $this->forum_id;
$result = $db->sql_query($sql);
$forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time');
$db->sql_freeresult($result);
update_forum_tracking_info($this->forum_id, $forum_last_post_time, $f_mark_time, false);
}
// Send Notifications
user_notification('reply', $this->post_subject, $topic_data['topic_title'], $topic_data['forum_name'], $this->forum_id, $this->topic_id, $this->post_id);
}
else
{
//new topic
$this->_topic = topic::from_post($this);
$this->_topic->submit(true);
//PHP4 Compatibility:
if(version_compare(PHP_VERSION, '5.0.0', '<'))
{
$this->topic_id = $this->_topic->topic_id;
$this->post_id = $this->_topic->topic_first_post_id;
}
$exec_sync = false;
}
foreach($this->attachments as $attachment)
{
$attachment->post_msg_id = $this->post_id;
$attachment->topic_id = $this->topic_id;
$attachment->poster_id = $this->poster_id;
$attachment->in_message = 0;
$attachment->is_orphan = 0;
$attachment->submit();
}
if($exec_sync)
{
$sync->execute();
}
/*if($sync_topic)
{
if($this->_topic)
{
$this->_topic->sync();
}
else
{
sync('topic', 'topic_id', $this->topic_id);
}
}*/
} | php | function _submit(&$sync)
{
global $config, $db, $auth, $user;
if($sync === false)
{
//submit() was called directly so we need to sync after it
$sync = new syncer();
$exec_sync = true;
}
else
{
//submit() was called by topic->submit(), sync there when everything is done
$exec_sync = false;
}
if(!$this->post_id)
{
//new post, set some default values if not set yet
if(!$this->poster_id) $this->poster_id = $user->data['user_id'];
if(!$this->poster_ip) $this->poster_ip = $user->ip;
if(!$this->post_time) $this->post_time = time();
}
$this->post_subject = truncate_string($this->post_subject);
$sql_data = array(
'poster_id' => $this->poster_id,
'poster_ip' => $this->poster_ip,
'topic_id' => $this->topic_id,
'forum_id' => $this->forum_id,
'post_username' => $this->post_username,
'icon_id' => $this->icon_id,
'post_time' => $this->post_time,
'post_postcount' => $this->post_postcount ? 1 : 0,
'post_visibility' => $this->post_visibility,
'post_reported' => $this->post_reported ? 1 : 0,
'enable_bbcode' => $this->enable_bbcode ? 1 : 0,
'enable_smilies' => $this->enable_smilies ? 1 : 0,
'enable_magic_url' => $this->enable_magic_url ? 1 : 0,
'enable_sig' => $this->enable_sig ? 1 : 0,
'post_subject' => $this->post_subject,
'bbcode_bitfield' => 0,
'bbcode_uid' => '',
'post_text' => $this->post_text,
'post_checksum' => md5($this->post_text),
//'post_attachment' => $this->post_attachment ? 1 : 0,
'post_edit_time' => $this->post_edit_time,
'post_edit_reason' => $this->post_edit_reason,
'post_edit_user' => $this->post_edit_user,
'post_edit_count' => $this->post_edit_count,
'post_edit_locked' => $this->post_edit_locked,
'post_delete_time' => $this->post_delete_time,
'post_delete_reason' => $this->post_delete_reason,
'post_delete_user' => $this->post_delete_user,
);
$flags = '';
generate_text_for_storage($sql_data['post_text'], $sql_data['bbcode_uid'], $sql_data['bbcode_bitfield'], $flags, $this->enable_bbcode, $this->enable_magic_url, $this->enable_smilies);
if($this->post_id && $this->topic_id)
{
//edit
$sql = "SELECT p.*, t.topic_first_post_id, t.topic_last_post_id, t.topic_approved, t.topic_replies
FROM " . POSTS_TABLE . " p
LEFT JOIN " . TOPICS_TABLE . " t ON (t.topic_id = p.topic_id)
WHERE p.post_id=" . intval($this->post_id);
//$sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=" . intval($this->post_id);
$result = $db->sql_query($sql);
$post_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if(!$post_data)
{
trigger_error("post_id={$this->post_id}, but that post does not exist", E_USER_ERROR);
}
//check first/last post
$is_first_post = ($post_data['post_id'] == $post_data['topic_first_post_id']);
$is_last_post = ($post_data['post_id'] == $post_data['topic_last_post_id']);
$db->sql_transaction('begin');
$sql = "UPDATE " . POSTS_TABLE . " SET " . $db->sql_build_array('UPDATE', $sql_data) . " WHERE post_id=" . $this->post_id;
$db->sql_query($sql);
if($this->topic_id != $post_data['topic_id'])
{
//merge into new topic
//get new topic's forum id and first/last post time
$sql = "SELECT forum_id, topic_time, topic_last_post_time
FROM " . TOPICS_TABLE . "
WHERE topic_id = {$this->topic_id}";
$result = $db->sql_query($sql);
$new_topic_data = $db->sql_fetchrow($result);
if(!$new_topic_data)
{
trigger_error("attempted to merge post {$this->post_id} into topic {$this->topic_id}, but that topic does not exist", E_USER_ERROR);
}
//sync forum_posts
//TODO
if($new_topic_data['forum_id'] != $post_data['forum_id'])
{
$sync->add('forum', $post_data['forum_id'], 'forum_posts', $this->post_approved ? -1 : 0);
$sync->add('forum', $new_topic_data['forum_id'], 'forum_posts', $this->post_approved ? 1 : 0);
if($this->forum_id != $new_topic_data['forum_id'])
{
//user changed topic_id but not forum_id, so we saved the wrong one above. correct it via sync
$this->forum_id = $new_topic_data['forum_id'];
$sync->set('post', $this->post_id, 'forum_id', $this->forum_id);
}
}
//sync old topic
$sync->add('topic', $post_data['topic_id'], 'topic_replies', $this->post_approved ? -1 : 0);
$sync->add('topic', $post_data['topic_id'], 'topic_replies_real', -1);
$sync->check_topic_empty($post_data['topic_id']);
//sync new topic
$sync->add('topic', $this->topic_id, 'topic_replies', $this->post_approved ? 1 : 0);
$sync->add('topic', $this->topic_id, 'topic_replies_real', 1);
//sync topic_reported and topic_attachment if applicable
if($post_data['post_reported']) {
$sync->topic_reported($post_data['topic_id']);
}
if($post_data['post_attachment']) {
$sync->topic_attachment($post_data['topic_id']);
}
if($this->post_reported) {
$sync->topic_reported($this->topic_id);
}
if($this->post_attachment) {
$sync->topic_attachment($this->topic_id);
}
if($is_first_post)
{
//this was the first post in the old topic, sync it
$sync->topic_first_post($post_data['topic_id']);
$is_first_post = false; //unset since we dont know status for new topic yet
}
if($is_last_post)
{
//this was the last post in the old topic, sync it
$sync->topic_last_post($post_data['topic_id']);
$sync->forum_last_post($post_data['forum_id']);
$is_last_post = false; //unset since we dont know status for new topic yet
}
if($this->post_time <= $new_topic_data['topic_time'])
{
//this will be the first post in the new topic, sync it
$sync->topic_first_post($this->topic_id);
$is_first_post = true;
}
if($this->post_time >= $new_topic_data['topic_last_post_time'])
{
//this will be the last post in the new topic, sync it
$sync->topic_last_post($this->topic_id);
$sync->forum_last_post($this->topic_id);
$is_last_post = true;
}
}
elseif($is_first_post)
{
$sync->set('topic', $this->topic_id, array(
'icon_id' => $this->icon_id,
'topic_approved' => $this->post_approved,
'topic_title' => $this->post_subject,
'topic_poster' => $this->poster_id,
'topic_time' => $this->post_time
));
}
//check if some statistics relevant flags have been changed
if($this->post_approved != $post_data['post_approved'])
{
//if topic_id was changed, we've already updated it above.
if($this->topic_id == $post_data['topic_id'])
{
if($is_first_post)
{
//first post -> approve/disapprove whole topic if not yet done (should only happen when directly storing the post)
if($this->post_approved != $post_data['topic_approved'])
{
$sync->add('forum', $this->forum_id, 'forum_topics', $this->post_approved ? 1 : -1);
$sync->add('forum', $this->forum_id, 'forum_posts', $this->post_approved ? (1+$post_data['topic_replies']) : -(1+$post_data['topic_replies']));
$sync->forum_last_post($this->forum_id);
//and the total topics+posts
set_config('num_topics', $this->post_approved ? $config['num_topics'] + 1 : $config['num_topics'] - 1, true);
set_config('num_posts', $this->post_approved ? $config['num_posts'] + (1+$post_data['topic_replies']) : $config['num_posts'] - (1+$post_data['topic_replies']), true);
}
}
else
{
//reply
$sync->add('topic', $this->topic_id, 'topic_replies', $this->post_approved ? 1 : -1);
$sync->add('forum', $this->forum_id, 'forum_posts', $this->post_approved ? 1 : -1);
}
}
//update total posts
if(!$is_first_post)
{
set_config('num_posts', $this->post_approved ? $config['num_posts'] + 1 : $config['num_posts'] - 1, true);
}
}
/*if($this->post_postcount != $post_data['post_postcount'] && $this->poster_id != ANONYMOUS)
{
//increase or decrease user_posts
$sync->add('user', $this->poster_id, 'user_posts', $this->post_approved ? 1 : -1);
}*/
if($this->poster_id != $post_data['poster_id'] || $this->post_postcount != $post_data['post_postcount'])
{
if($post_data['post_postcount'] && $post_data['poster_id'] != ANONYMOUS)
{
$sync->add('user', $post_data['poster_id'], 'user_posts', -1);
}
if($this->post_postcount && $this->poster_id != ANONYMOUS)
{
$sync->add('user', $this->poster_id, 'user_posts', 1);
}
}
if($is_first_post)
{
$sync->topic_first_post($this->topic_id);
}
if($is_last_post)
{
$sync->topic_last_post($this->topic_id);
$sync->forum_last_post($this->forum_id);
}
reindex('edit', $this->post_id, $sql_data['post_text'], $this->post_subject, $this->poster_id, $this->forum_id);
$db->sql_transaction('commit');
}
elseif($this->topic_id)
{
//reply
$sql = "SELECT t.*, f.forum_name
FROM " . TOPICS_TABLE . " t
LEFT JOIN " . FORUMS_TABLE . " f ON (f.forum_id = t.forum_id)
WHERE t.topic_id=" . intval($this->topic_id);
$result = $db->sql_query($sql);
$topic_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if(!$topic_data)
{
trigger_error("topic_id={$this->topic_id}, but that topic does not exist", E_USER_ERROR);
}
//we need topic_id and forum_id
$this->forum_id = $topic_data['forum_id'];
$sql_data['forum_id'] = $this->forum_id;
$sql_data['topic_id'] = $this->topic_id;
//make sure we have a post_subject (empty subjects are bad for e.g. approving)
if($this->post_subject == '')
{
$this->post_subject = 'Re: ' . $topic_data['topic_title'];
}
$db->sql_transaction('begin');
//insert post
$sql = "INSERT INTO " . POSTS_TABLE . " " . $db->sql_build_array('INSERT', $sql_data);
$db->sql_query($sql);
$this->post_id = $db->sql_nextid();
//update topic
if(!$sync->new_topic_flag)
{
$sync->add('topic', $this->topic_id, 'topic_replies', $this->post_approved ? 1 : 0);
$sync->add('topic', $this->topic_id, 'topic_replies_real', 1);
$sync->set('topic', $this->topic_id, 'topic_bumped', 0);
$sync->set('topic', $this->topic_id, 'topic_bumper', 0);
}
else
{
$sync->topic_first_post($this->topic_id);
$sync->new_topic_flag = false;
}
$sync->topic_last_post($this->topic_id);
//update forum
if($this->forum_id != 0)
{
$sync->add('forum', $this->forum_id, 'forum_posts', $this->post_approved ? 1 : 0);
$sync->forum_last_post($this->forum_id);
}
if($this->post_postcount)
{
//increase user_posts...
$sync->add('user', $this->poster_id, 'user_posts', 1);
}
if($this->post_approved)
{
//...and total posts
set_config('num_posts', $config['num_posts'] + 1, true);
}
reindex('reply', $this->post_id, $sql_data['post_text'], $this->post_subject, $this->poster_id, $this->forum_id);
$db->sql_transaction('commit');
// Mark this topic as posted to
markread('post', $this->forum_id, $this->topic_id, $this->post_time, $this->poster_id);
// Mark this topic as read
// We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)
markread('topic', $this->forum_id, $this->topic_id, time());
//
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$sql = 'SELECT mark_time
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
AND forum_id = ' . $this->forum_id;
$result = $db->sql_query($sql);
$f_mark_time = (int) $db->sql_fetchfield('mark_time');
$db->sql_freeresult($result);
}
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
{
$f_mark_time = false;
}
if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered'])
{
// Update forum info
$sql = 'SELECT forum_last_post_time
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $this->forum_id;
$result = $db->sql_query($sql);
$forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time');
$db->sql_freeresult($result);
update_forum_tracking_info($this->forum_id, $forum_last_post_time, $f_mark_time, false);
}
// Send Notifications
user_notification('reply', $this->post_subject, $topic_data['topic_title'], $topic_data['forum_name'], $this->forum_id, $this->topic_id, $this->post_id);
}
else
{
//new topic
$this->_topic = topic::from_post($this);
$this->_topic->submit(true);
//PHP4 Compatibility:
if(version_compare(PHP_VERSION, '5.0.0', '<'))
{
$this->topic_id = $this->_topic->topic_id;
$this->post_id = $this->_topic->topic_first_post_id;
}
$exec_sync = false;
}
foreach($this->attachments as $attachment)
{
$attachment->post_msg_id = $this->post_id;
$attachment->topic_id = $this->topic_id;
$attachment->poster_id = $this->poster_id;
$attachment->in_message = 0;
$attachment->is_orphan = 0;
$attachment->submit();
}
if($exec_sync)
{
$sync->execute();
}
/*if($sync_topic)
{
if($this->_topic)
{
$this->_topic->sync();
}
else
{
sync('topic', 'topic_id', $this->topic_id);
}
}*/
} | [
"function",
"_submit",
"(",
"&",
"$",
"sync",
")",
"{",
"global",
"$",
"config",
",",
"$",
"db",
",",
"$",
"auth",
",",
"$",
"user",
";",
"if",
"(",
"$",
"sync",
"===",
"false",
")",
"{",
"//submit() was called directly so we need to sync after it",
"$",
"sync",
"=",
"new",
"syncer",
"(",
")",
";",
"$",
"exec_sync",
"=",
"true",
";",
"}",
"else",
"{",
"//submit() was called by topic->submit(), sync there when everything is done",
"$",
"exec_sync",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"post_id",
")",
"{",
"//new post, set some default values if not set yet",
"if",
"(",
"!",
"$",
"this",
"->",
"poster_id",
")",
"$",
"this",
"->",
"poster_id",
"=",
"$",
"user",
"->",
"data",
"[",
"'user_id'",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"poster_ip",
")",
"$",
"this",
"->",
"poster_ip",
"=",
"$",
"user",
"->",
"ip",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"post_time",
")",
"$",
"this",
"->",
"post_time",
"=",
"time",
"(",
")",
";",
"}",
"$",
"this",
"->",
"post_subject",
"=",
"truncate_string",
"(",
"$",
"this",
"->",
"post_subject",
")",
";",
"$",
"sql_data",
"=",
"array",
"(",
"'poster_id'",
"=>",
"$",
"this",
"->",
"poster_id",
",",
"'poster_ip'",
"=>",
"$",
"this",
"->",
"poster_ip",
",",
"'topic_id'",
"=>",
"$",
"this",
"->",
"topic_id",
",",
"'forum_id'",
"=>",
"$",
"this",
"->",
"forum_id",
",",
"'post_username'",
"=>",
"$",
"this",
"->",
"post_username",
",",
"'icon_id'",
"=>",
"$",
"this",
"->",
"icon_id",
",",
"'post_time'",
"=>",
"$",
"this",
"->",
"post_time",
",",
"'post_postcount'",
"=>",
"$",
"this",
"->",
"post_postcount",
"?",
"1",
":",
"0",
",",
"'post_visibility'",
"=>",
"$",
"this",
"->",
"post_visibility",
",",
"'post_reported'",
"=>",
"$",
"this",
"->",
"post_reported",
"?",
"1",
":",
"0",
",",
"'enable_bbcode'",
"=>",
"$",
"this",
"->",
"enable_bbcode",
"?",
"1",
":",
"0",
",",
"'enable_smilies'",
"=>",
"$",
"this",
"->",
"enable_smilies",
"?",
"1",
":",
"0",
",",
"'enable_magic_url'",
"=>",
"$",
"this",
"->",
"enable_magic_url",
"?",
"1",
":",
"0",
",",
"'enable_sig'",
"=>",
"$",
"this",
"->",
"enable_sig",
"?",
"1",
":",
"0",
",",
"'post_subject'",
"=>",
"$",
"this",
"->",
"post_subject",
",",
"'bbcode_bitfield'",
"=>",
"0",
",",
"'bbcode_uid'",
"=>",
"''",
",",
"'post_text'",
"=>",
"$",
"this",
"->",
"post_text",
",",
"'post_checksum'",
"=>",
"md5",
"(",
"$",
"this",
"->",
"post_text",
")",
",",
"//'post_attachment'\t=> $this->post_attachment ? 1 : 0,",
"'post_edit_time'",
"=>",
"$",
"this",
"->",
"post_edit_time",
",",
"'post_edit_reason'",
"=>",
"$",
"this",
"->",
"post_edit_reason",
",",
"'post_edit_user'",
"=>",
"$",
"this",
"->",
"post_edit_user",
",",
"'post_edit_count'",
"=>",
"$",
"this",
"->",
"post_edit_count",
",",
"'post_edit_locked'",
"=>",
"$",
"this",
"->",
"post_edit_locked",
",",
"'post_delete_time'",
"=>",
"$",
"this",
"->",
"post_delete_time",
",",
"'post_delete_reason'",
"=>",
"$",
"this",
"->",
"post_delete_reason",
",",
"'post_delete_user'",
"=>",
"$",
"this",
"->",
"post_delete_user",
",",
")",
";",
"$",
"flags",
"=",
"''",
";",
"generate_text_for_storage",
"(",
"$",
"sql_data",
"[",
"'post_text'",
"]",
",",
"$",
"sql_data",
"[",
"'bbcode_uid'",
"]",
",",
"$",
"sql_data",
"[",
"'bbcode_bitfield'",
"]",
",",
"$",
"flags",
",",
"$",
"this",
"->",
"enable_bbcode",
",",
"$",
"this",
"->",
"enable_magic_url",
",",
"$",
"this",
"->",
"enable_smilies",
")",
";",
"if",
"(",
"$",
"this",
"->",
"post_id",
"&&",
"$",
"this",
"->",
"topic_id",
")",
"{",
"//edit",
"$",
"sql",
"=",
"\"SELECT p.*, t.topic_first_post_id, t.topic_last_post_id, t.topic_approved, t.topic_replies\n\t\t\t\t\tFROM \"",
".",
"POSTS_TABLE",
".",
"\" p\n\t\t\t\t\tLEFT JOIN \"",
".",
"TOPICS_TABLE",
".",
"\" t ON (t.topic_id = p.topic_id)\n\t\t\t\t\tWHERE p.post_id=\"",
".",
"intval",
"(",
"$",
"this",
"->",
"post_id",
")",
";",
"//$sql = \"SELECT * FROM \" . POSTS_TABLE . \" WHERE post_id=\" . intval($this->post_id);",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"post_data",
"=",
"$",
"db",
"->",
"sql_fetchrow",
"(",
"$",
"result",
")",
";",
"$",
"db",
"->",
"sql_freeresult",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"$",
"post_data",
")",
"{",
"trigger_error",
"(",
"\"post_id={$this->post_id}, but that post does not exist\"",
",",
"E_USER_ERROR",
")",
";",
"}",
"//check first/last post",
"$",
"is_first_post",
"=",
"(",
"$",
"post_data",
"[",
"'post_id'",
"]",
"==",
"$",
"post_data",
"[",
"'topic_first_post_id'",
"]",
")",
";",
"$",
"is_last_post",
"=",
"(",
"$",
"post_data",
"[",
"'post_id'",
"]",
"==",
"$",
"post_data",
"[",
"'topic_last_post_id'",
"]",
")",
";",
"$",
"db",
"->",
"sql_transaction",
"(",
"'begin'",
")",
";",
"$",
"sql",
"=",
"\"UPDATE \"",
".",
"POSTS_TABLE",
".",
"\" SET \"",
".",
"$",
"db",
"->",
"sql_build_array",
"(",
"'UPDATE'",
",",
"$",
"sql_data",
")",
".",
"\" WHERE post_id=\"",
".",
"$",
"this",
"->",
"post_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"if",
"(",
"$",
"this",
"->",
"topic_id",
"!=",
"$",
"post_data",
"[",
"'topic_id'",
"]",
")",
"{",
"//merge into new topic",
"//get new topic's forum id and first/last post time",
"$",
"sql",
"=",
"\"SELECT forum_id, topic_time, topic_last_post_time\n\t\t\t\t\t\tFROM \"",
".",
"TOPICS_TABLE",
".",
"\"\n\t\t\t\t\t\tWHERE topic_id = {$this->topic_id}\"",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"new_topic_data",
"=",
"$",
"db",
"->",
"sql_fetchrow",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"$",
"new_topic_data",
")",
"{",
"trigger_error",
"(",
"\"attempted to merge post {$this->post_id} into topic {$this->topic_id}, but that topic does not exist\"",
",",
"E_USER_ERROR",
")",
";",
"}",
"//sync forum_posts",
"//TODO",
"if",
"(",
"$",
"new_topic_data",
"[",
"'forum_id'",
"]",
"!=",
"$",
"post_data",
"[",
"'forum_id'",
"]",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"post_data",
"[",
"'forum_id'",
"]",
",",
"'forum_posts'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"-",
"1",
":",
"0",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"new_topic_data",
"[",
"'forum_id'",
"]",
",",
"'forum_posts'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"1",
":",
"0",
")",
";",
"if",
"(",
"$",
"this",
"->",
"forum_id",
"!=",
"$",
"new_topic_data",
"[",
"'forum_id'",
"]",
")",
"{",
"//user changed topic_id but not forum_id, so we saved the wrong one above. correct it via sync",
"$",
"this",
"->",
"forum_id",
"=",
"$",
"new_topic_data",
"[",
"'forum_id'",
"]",
";",
"$",
"sync",
"->",
"set",
"(",
"'post'",
",",
"$",
"this",
"->",
"post_id",
",",
"'forum_id'",
",",
"$",
"this",
"->",
"forum_id",
")",
";",
"}",
"}",
"//sync old topic",
"$",
"sync",
"->",
"add",
"(",
"'topic'",
",",
"$",
"post_data",
"[",
"'topic_id'",
"]",
",",
"'topic_replies'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"-",
"1",
":",
"0",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'topic'",
",",
"$",
"post_data",
"[",
"'topic_id'",
"]",
",",
"'topic_replies_real'",
",",
"-",
"1",
")",
";",
"$",
"sync",
"->",
"check_topic_empty",
"(",
"$",
"post_data",
"[",
"'topic_id'",
"]",
")",
";",
"//sync new topic",
"$",
"sync",
"->",
"add",
"(",
"'topic'",
",",
"$",
"this",
"->",
"topic_id",
",",
"'topic_replies'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"1",
":",
"0",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'topic'",
",",
"$",
"this",
"->",
"topic_id",
",",
"'topic_replies_real'",
",",
"1",
")",
";",
"//sync topic_reported and topic_attachment if applicable",
"if",
"(",
"$",
"post_data",
"[",
"'post_reported'",
"]",
")",
"{",
"$",
"sync",
"->",
"topic_reported",
"(",
"$",
"post_data",
"[",
"'topic_id'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"post_data",
"[",
"'post_attachment'",
"]",
")",
"{",
"$",
"sync",
"->",
"topic_attachment",
"(",
"$",
"post_data",
"[",
"'topic_id'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"post_reported",
")",
"{",
"$",
"sync",
"->",
"topic_reported",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"post_attachment",
")",
"{",
"$",
"sync",
"->",
"topic_attachment",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"}",
"if",
"(",
"$",
"is_first_post",
")",
"{",
"//this was the first post in the old topic, sync it",
"$",
"sync",
"->",
"topic_first_post",
"(",
"$",
"post_data",
"[",
"'topic_id'",
"]",
")",
";",
"$",
"is_first_post",
"=",
"false",
";",
"//unset since we dont know status for new topic yet",
"}",
"if",
"(",
"$",
"is_last_post",
")",
"{",
"//this was the last post in the old topic, sync it",
"$",
"sync",
"->",
"topic_last_post",
"(",
"$",
"post_data",
"[",
"'topic_id'",
"]",
")",
";",
"$",
"sync",
"->",
"forum_last_post",
"(",
"$",
"post_data",
"[",
"'forum_id'",
"]",
")",
";",
"$",
"is_last_post",
"=",
"false",
";",
"//unset since we dont know status for new topic yet",
"}",
"if",
"(",
"$",
"this",
"->",
"post_time",
"<=",
"$",
"new_topic_data",
"[",
"'topic_time'",
"]",
")",
"{",
"//this will be the first post in the new topic, sync it",
"$",
"sync",
"->",
"topic_first_post",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"$",
"is_first_post",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"post_time",
">=",
"$",
"new_topic_data",
"[",
"'topic_last_post_time'",
"]",
")",
"{",
"//this will be the last post in the new topic, sync it",
"$",
"sync",
"->",
"topic_last_post",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"$",
"sync",
"->",
"forum_last_post",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"$",
"is_last_post",
"=",
"true",
";",
"}",
"}",
"elseif",
"(",
"$",
"is_first_post",
")",
"{",
"$",
"sync",
"->",
"set",
"(",
"'topic'",
",",
"$",
"this",
"->",
"topic_id",
",",
"array",
"(",
"'icon_id'",
"=>",
"$",
"this",
"->",
"icon_id",
",",
"'topic_approved'",
"=>",
"$",
"this",
"->",
"post_approved",
",",
"'topic_title'",
"=>",
"$",
"this",
"->",
"post_subject",
",",
"'topic_poster'",
"=>",
"$",
"this",
"->",
"poster_id",
",",
"'topic_time'",
"=>",
"$",
"this",
"->",
"post_time",
")",
")",
";",
"}",
"//check if some statistics relevant flags have been changed",
"if",
"(",
"$",
"this",
"->",
"post_approved",
"!=",
"$",
"post_data",
"[",
"'post_approved'",
"]",
")",
"{",
"//if topic_id was changed, we've already updated it above.",
"if",
"(",
"$",
"this",
"->",
"topic_id",
"==",
"$",
"post_data",
"[",
"'topic_id'",
"]",
")",
"{",
"if",
"(",
"$",
"is_first_post",
")",
"{",
"//first post -> approve/disapprove whole topic if not yet done (should only happen when directly storing the post)",
"if",
"(",
"$",
"this",
"->",
"post_approved",
"!=",
"$",
"post_data",
"[",
"'topic_approved'",
"]",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_topics'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"1",
":",
"-",
"1",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"(",
"1",
"+",
"$",
"post_data",
"[",
"'topic_replies'",
"]",
")",
":",
"-",
"(",
"1",
"+",
"$",
"post_data",
"[",
"'topic_replies'",
"]",
")",
")",
";",
"$",
"sync",
"->",
"forum_last_post",
"(",
"$",
"this",
"->",
"forum_id",
")",
";",
"//and the total topics+posts",
"set_config",
"(",
"'num_topics'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"$",
"config",
"[",
"'num_topics'",
"]",
"+",
"1",
":",
"$",
"config",
"[",
"'num_topics'",
"]",
"-",
"1",
",",
"true",
")",
";",
"set_config",
"(",
"'num_posts'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"$",
"config",
"[",
"'num_posts'",
"]",
"+",
"(",
"1",
"+",
"$",
"post_data",
"[",
"'topic_replies'",
"]",
")",
":",
"$",
"config",
"[",
"'num_posts'",
"]",
"-",
"(",
"1",
"+",
"$",
"post_data",
"[",
"'topic_replies'",
"]",
")",
",",
"true",
")",
";",
"}",
"}",
"else",
"{",
"//reply",
"$",
"sync",
"->",
"add",
"(",
"'topic'",
",",
"$",
"this",
"->",
"topic_id",
",",
"'topic_replies'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"1",
":",
"-",
"1",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"1",
":",
"-",
"1",
")",
";",
"}",
"}",
"//update total posts",
"if",
"(",
"!",
"$",
"is_first_post",
")",
"{",
"set_config",
"(",
"'num_posts'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"$",
"config",
"[",
"'num_posts'",
"]",
"+",
"1",
":",
"$",
"config",
"[",
"'num_posts'",
"]",
"-",
"1",
",",
"true",
")",
";",
"}",
"}",
"/*if($this->post_postcount != $post_data['post_postcount'] && $this->poster_id != ANONYMOUS)\n\t\t\t{\n\t\t\t\t//increase or decrease user_posts\n\t\t\t\t$sync->add('user', $this->poster_id, 'user_posts', $this->post_approved ? 1 : -1);\n\t\t\t}*/",
"if",
"(",
"$",
"this",
"->",
"poster_id",
"!=",
"$",
"post_data",
"[",
"'poster_id'",
"]",
"||",
"$",
"this",
"->",
"post_postcount",
"!=",
"$",
"post_data",
"[",
"'post_postcount'",
"]",
")",
"{",
"if",
"(",
"$",
"post_data",
"[",
"'post_postcount'",
"]",
"&&",
"$",
"post_data",
"[",
"'poster_id'",
"]",
"!=",
"ANONYMOUS",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'user'",
",",
"$",
"post_data",
"[",
"'poster_id'",
"]",
",",
"'user_posts'",
",",
"-",
"1",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"post_postcount",
"&&",
"$",
"this",
"->",
"poster_id",
"!=",
"ANONYMOUS",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'user'",
",",
"$",
"this",
"->",
"poster_id",
",",
"'user_posts'",
",",
"1",
")",
";",
"}",
"}",
"if",
"(",
"$",
"is_first_post",
")",
"{",
"$",
"sync",
"->",
"topic_first_post",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"}",
"if",
"(",
"$",
"is_last_post",
")",
"{",
"$",
"sync",
"->",
"topic_last_post",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"$",
"sync",
"->",
"forum_last_post",
"(",
"$",
"this",
"->",
"forum_id",
")",
";",
"}",
"reindex",
"(",
"'edit'",
",",
"$",
"this",
"->",
"post_id",
",",
"$",
"sql_data",
"[",
"'post_text'",
"]",
",",
"$",
"this",
"->",
"post_subject",
",",
"$",
"this",
"->",
"poster_id",
",",
"$",
"this",
"->",
"forum_id",
")",
";",
"$",
"db",
"->",
"sql_transaction",
"(",
"'commit'",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"topic_id",
")",
"{",
"//reply",
"$",
"sql",
"=",
"\"SELECT t.*, f.forum_name\n\t\t\t\t\tFROM \"",
".",
"TOPICS_TABLE",
".",
"\" t\n\t\t\t\t\tLEFT JOIN \"",
".",
"FORUMS_TABLE",
".",
"\" f ON (f.forum_id = t.forum_id)\n\t\t\t\t\tWHERE t.topic_id=\"",
".",
"intval",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"topic_data",
"=",
"$",
"db",
"->",
"sql_fetchrow",
"(",
"$",
"result",
")",
";",
"$",
"db",
"->",
"sql_freeresult",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"$",
"topic_data",
")",
"{",
"trigger_error",
"(",
"\"topic_id={$this->topic_id}, but that topic does not exist\"",
",",
"E_USER_ERROR",
")",
";",
"}",
"//we need topic_id and forum_id",
"$",
"this",
"->",
"forum_id",
"=",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
";",
"$",
"sql_data",
"[",
"'forum_id'",
"]",
"=",
"$",
"this",
"->",
"forum_id",
";",
"$",
"sql_data",
"[",
"'topic_id'",
"]",
"=",
"$",
"this",
"->",
"topic_id",
";",
"//make sure we have a post_subject (empty subjects are bad for e.g. approving)",
"if",
"(",
"$",
"this",
"->",
"post_subject",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"post_subject",
"=",
"'Re: '",
".",
"$",
"topic_data",
"[",
"'topic_title'",
"]",
";",
"}",
"$",
"db",
"->",
"sql_transaction",
"(",
"'begin'",
")",
";",
"//insert post",
"$",
"sql",
"=",
"\"INSERT INTO \"",
".",
"POSTS_TABLE",
".",
"\" \"",
".",
"$",
"db",
"->",
"sql_build_array",
"(",
"'INSERT'",
",",
"$",
"sql_data",
")",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"post_id",
"=",
"$",
"db",
"->",
"sql_nextid",
"(",
")",
";",
"//update topic",
"if",
"(",
"!",
"$",
"sync",
"->",
"new_topic_flag",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'topic'",
",",
"$",
"this",
"->",
"topic_id",
",",
"'topic_replies'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"1",
":",
"0",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'topic'",
",",
"$",
"this",
"->",
"topic_id",
",",
"'topic_replies_real'",
",",
"1",
")",
";",
"$",
"sync",
"->",
"set",
"(",
"'topic'",
",",
"$",
"this",
"->",
"topic_id",
",",
"'topic_bumped'",
",",
"0",
")",
";",
"$",
"sync",
"->",
"set",
"(",
"'topic'",
",",
"$",
"this",
"->",
"topic_id",
",",
"'topic_bumper'",
",",
"0",
")",
";",
"}",
"else",
"{",
"$",
"sync",
"->",
"topic_first_post",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"$",
"sync",
"->",
"new_topic_flag",
"=",
"false",
";",
"}",
"$",
"sync",
"->",
"topic_last_post",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"//update forum",
"if",
"(",
"$",
"this",
"->",
"forum_id",
"!=",
"0",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts'",
",",
"$",
"this",
"->",
"post_approved",
"?",
"1",
":",
"0",
")",
";",
"$",
"sync",
"->",
"forum_last_post",
"(",
"$",
"this",
"->",
"forum_id",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"post_postcount",
")",
"{",
"//increase user_posts...",
"$",
"sync",
"->",
"add",
"(",
"'user'",
",",
"$",
"this",
"->",
"poster_id",
",",
"'user_posts'",
",",
"1",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"post_approved",
")",
"{",
"//...and total posts",
"set_config",
"(",
"'num_posts'",
",",
"$",
"config",
"[",
"'num_posts'",
"]",
"+",
"1",
",",
"true",
")",
";",
"}",
"reindex",
"(",
"'reply'",
",",
"$",
"this",
"->",
"post_id",
",",
"$",
"sql_data",
"[",
"'post_text'",
"]",
",",
"$",
"this",
"->",
"post_subject",
",",
"$",
"this",
"->",
"poster_id",
",",
"$",
"this",
"->",
"forum_id",
")",
";",
"$",
"db",
"->",
"sql_transaction",
"(",
"'commit'",
")",
";",
"// Mark this topic as posted to",
"markread",
"(",
"'post'",
",",
"$",
"this",
"->",
"forum_id",
",",
"$",
"this",
"->",
"topic_id",
",",
"$",
"this",
"->",
"post_time",
",",
"$",
"this",
"->",
"poster_id",
")",
";",
"// Mark this topic as read",
"// We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)",
"markread",
"(",
"'topic'",
",",
"$",
"this",
"->",
"forum_id",
",",
"$",
"this",
"->",
"topic_id",
",",
"time",
"(",
")",
")",
";",
"//",
"if",
"(",
"$",
"config",
"[",
"'load_db_lastread'",
"]",
"&&",
"$",
"user",
"->",
"data",
"[",
"'is_registered'",
"]",
")",
"{",
"$",
"sql",
"=",
"'SELECT mark_time\n\t\t\t\t\tFROM '",
".",
"FORUMS_TRACK_TABLE",
".",
"'\n\t\t\t\t\tWHERE user_id = '",
".",
"$",
"user",
"->",
"data",
"[",
"'user_id'",
"]",
".",
"'\n\t\t\t\t\t\tAND forum_id = '",
".",
"$",
"this",
"->",
"forum_id",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"f_mark_time",
"=",
"(",
"int",
")",
"$",
"db",
"->",
"sql_fetchfield",
"(",
"'mark_time'",
")",
";",
"$",
"db",
"->",
"sql_freeresult",
"(",
"$",
"result",
")",
";",
"}",
"else",
"if",
"(",
"$",
"config",
"[",
"'load_anon_lastread'",
"]",
"||",
"$",
"user",
"->",
"data",
"[",
"'is_registered'",
"]",
")",
"{",
"$",
"f_mark_time",
"=",
"false",
";",
"}",
"if",
"(",
"(",
"$",
"config",
"[",
"'load_db_lastread'",
"]",
"&&",
"$",
"user",
"->",
"data",
"[",
"'is_registered'",
"]",
")",
"||",
"$",
"config",
"[",
"'load_anon_lastread'",
"]",
"||",
"$",
"user",
"->",
"data",
"[",
"'is_registered'",
"]",
")",
"{",
"// Update forum info",
"$",
"sql",
"=",
"'SELECT forum_last_post_time\n\t\t\t\t\tFROM '",
".",
"FORUMS_TABLE",
".",
"'\n\t\t\t\t\tWHERE forum_id = '",
".",
"$",
"this",
"->",
"forum_id",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"forum_last_post_time",
"=",
"(",
"int",
")",
"$",
"db",
"->",
"sql_fetchfield",
"(",
"'forum_last_post_time'",
")",
";",
"$",
"db",
"->",
"sql_freeresult",
"(",
"$",
"result",
")",
";",
"update_forum_tracking_info",
"(",
"$",
"this",
"->",
"forum_id",
",",
"$",
"forum_last_post_time",
",",
"$",
"f_mark_time",
",",
"false",
")",
";",
"}",
"// Send Notifications",
"user_notification",
"(",
"'reply'",
",",
"$",
"this",
"->",
"post_subject",
",",
"$",
"topic_data",
"[",
"'topic_title'",
"]",
",",
"$",
"topic_data",
"[",
"'forum_name'",
"]",
",",
"$",
"this",
"->",
"forum_id",
",",
"$",
"this",
"->",
"topic_id",
",",
"$",
"this",
"->",
"post_id",
")",
";",
"}",
"else",
"{",
"//new topic",
"$",
"this",
"->",
"_topic",
"=",
"topic",
"::",
"from_post",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_topic",
"->",
"submit",
"(",
"true",
")",
";",
"//PHP4 Compatibility:",
"if",
"(",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.0.0'",
",",
"'<'",
")",
")",
"{",
"$",
"this",
"->",
"topic_id",
"=",
"$",
"this",
"->",
"_topic",
"->",
"topic_id",
";",
"$",
"this",
"->",
"post_id",
"=",
"$",
"this",
"->",
"_topic",
"->",
"topic_first_post_id",
";",
"}",
"$",
"exec_sync",
"=",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"attachments",
"as",
"$",
"attachment",
")",
"{",
"$",
"attachment",
"->",
"post_msg_id",
"=",
"$",
"this",
"->",
"post_id",
";",
"$",
"attachment",
"->",
"topic_id",
"=",
"$",
"this",
"->",
"topic_id",
";",
"$",
"attachment",
"->",
"poster_id",
"=",
"$",
"this",
"->",
"poster_id",
";",
"$",
"attachment",
"->",
"in_message",
"=",
"0",
";",
"$",
"attachment",
"->",
"is_orphan",
"=",
"0",
";",
"$",
"attachment",
"->",
"submit",
"(",
")",
";",
"}",
"if",
"(",
"$",
"exec_sync",
")",
"{",
"$",
"sync",
"->",
"execute",
"(",
")",
";",
"}",
"/*if($sync_topic)\n\t\t{\n\t\t\tif($this->_topic)\n\t\t\t{\n\t\t\t\t$this->_topic->sync();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsync('topic', 'topic_id', $this->topic_id);\n\t\t\t}\n\t\t}*/",
"}"
] | TODO | [
"TODO"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L948-L1344 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | post.delete | function delete()
{
if(!$this->post_id)
{
trigger_error('NO_POST', E_USER_ERROR);
}
$ret = delete_posts('post_id', $this->post_id);
//remove references to the deleted post so calls to submit() will create a
//new post instead of trying to update the post which does not exist anymore
$this->post_id = NULL;
return $ret;
} | php | function delete()
{
if(!$this->post_id)
{
trigger_error('NO_POST', E_USER_ERROR);
}
$ret = delete_posts('post_id', $this->post_id);
//remove references to the deleted post so calls to submit() will create a
//new post instead of trying to update the post which does not exist anymore
$this->post_id = NULL;
return $ret;
} | [
"function",
"delete",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"post_id",
")",
"{",
"trigger_error",
"(",
"'NO_POST'",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"ret",
"=",
"delete_posts",
"(",
"'post_id'",
",",
"$",
"this",
"->",
"post_id",
")",
";",
"//remove references to the deleted post so calls to submit() will create a",
"//new post instead of trying to update the post which does not exist anymore",
"$",
"this",
"->",
"post_id",
"=",
"NULL",
";",
"return",
"$",
"ret",
";",
"}"
] | delete this post (and if it was the last one in the topic, also delete the topic) | [
"delete",
"this",
"post",
"(",
"and",
"if",
"it",
"was",
"the",
"last",
"one",
"in",
"the",
"topic",
"also",
"delete",
"the",
"topic",
")"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L1347-L1361 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | post.mark_edited | function mark_edited($user_id = 0, $reason = '')
{
if($user_id = 0)
{
global $user;
$user_id = $user->data['user_id'];
}
$this->post_edit_count++;
$this->post_edit_time = time();
$this->post_edit_user = $user_id;
$this->post_edit_reason = $reason;
} | php | function mark_edited($user_id = 0, $reason = '')
{
if($user_id = 0)
{
global $user;
$user_id = $user->data['user_id'];
}
$this->post_edit_count++;
$this->post_edit_time = time();
$this->post_edit_user = $user_id;
$this->post_edit_reason = $reason;
} | [
"function",
"mark_edited",
"(",
"$",
"user_id",
"=",
"0",
",",
"$",
"reason",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"user_id",
"=",
"0",
")",
"{",
"global",
"$",
"user",
";",
"$",
"user_id",
"=",
"$",
"user",
"->",
"data",
"[",
"'user_id'",
"]",
";",
"}",
"$",
"this",
"->",
"post_edit_count",
"++",
";",
"$",
"this",
"->",
"post_edit_time",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"post_edit_user",
"=",
"$",
"user_id",
";",
"$",
"this",
"->",
"post_edit_reason",
"=",
"$",
"reason",
";",
"}"
] | mark this post as edited (modify post_edit_* fields).
currently logged in user will be used if user_id = 0 | [
"mark",
"this",
"post",
"as",
"edited",
"(",
"modify",
"post_edit_",
"*",
"fields",
")",
".",
"currently",
"logged",
"in",
"user",
"will",
"be",
"used",
"if",
"user_id",
"=",
"0"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L1365-L1376 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | privmsg.reply_to | static function reply_to($msg_id, $quote = true)
{
global $db;
$sql = "SELECT p.msg_id, p.root_level, p.author_id, p.message_subject, p.message_text, p.bbcode_uid, p.to_address, p.bcc_address, u.username
FROM " . PRIVMSGS_TABLE . " p
LEFT JOIN " . USERS_TABLE . " u ON (p.author_id = u.user_id)
WHERE msg_id = " . intval($msg_id);
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
if(!$row)
{
trigger_error('NO_PRIVMSG', E_USER_ERROR);
}
$privmsg = new privmsg();
$privmsg->reply_from_msg_id = $row['msg_id'];
$privmsg->root_level = ($row['root_level'] ? $row['root_level'] : $row['msg_id']);
$privmsg->message_subject = ((!preg_match('/^Re:/', $row['message_subject'])) ? 'Re: ' : '') . censor_text($row['message_subject']);
if($quote)
{
decode_message($row['message_text'], $row['bbcode_uid']);
//for some reason we need " here instead of "
$privmsg->message_text = '[quote="' . $row['username'] . '"]' . censor_text(trim($row['message_text'])) . "[/quote]\n";
}
//add original sender as recipient
$privmsg->to($row['author_id']);
//if message had only a single recipient, use that as sender
if($row['to_address'] == '' || $row['bcc_address'] == '')
{
$to = ($row['to_address'] != '') ? $row['to_address'] : $row['bcc_address'];
if(preg_match('#^u_(\\d+)$#', $to, $m))
{
$privmsg->author_id = $m[1];
}
}
return $privmsg;
} | php | static function reply_to($msg_id, $quote = true)
{
global $db;
$sql = "SELECT p.msg_id, p.root_level, p.author_id, p.message_subject, p.message_text, p.bbcode_uid, p.to_address, p.bcc_address, u.username
FROM " . PRIVMSGS_TABLE . " p
LEFT JOIN " . USERS_TABLE . " u ON (p.author_id = u.user_id)
WHERE msg_id = " . intval($msg_id);
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
if(!$row)
{
trigger_error('NO_PRIVMSG', E_USER_ERROR);
}
$privmsg = new privmsg();
$privmsg->reply_from_msg_id = $row['msg_id'];
$privmsg->root_level = ($row['root_level'] ? $row['root_level'] : $row['msg_id']);
$privmsg->message_subject = ((!preg_match('/^Re:/', $row['message_subject'])) ? 'Re: ' : '') . censor_text($row['message_subject']);
if($quote)
{
decode_message($row['message_text'], $row['bbcode_uid']);
//for some reason we need " here instead of "
$privmsg->message_text = '[quote="' . $row['username'] . '"]' . censor_text(trim($row['message_text'])) . "[/quote]\n";
}
//add original sender as recipient
$privmsg->to($row['author_id']);
//if message had only a single recipient, use that as sender
if($row['to_address'] == '' || $row['bcc_address'] == '')
{
$to = ($row['to_address'] != '') ? $row['to_address'] : $row['bcc_address'];
if(preg_match('#^u_(\\d+)$#', $to, $m))
{
$privmsg->author_id = $m[1];
}
}
return $privmsg;
} | [
"static",
"function",
"reply_to",
"(",
"$",
"msg_id",
",",
"$",
"quote",
"=",
"true",
")",
"{",
"global",
"$",
"db",
";",
"$",
"sql",
"=",
"\"SELECT p.msg_id, p.root_level, p.author_id, p.message_subject, p.message_text, p.bbcode_uid, p.to_address, p.bcc_address, u.username\n\t\t\t\tFROM \"",
".",
"PRIVMSGS_TABLE",
".",
"\" p\n\t\t\t\tLEFT JOIN \"",
".",
"USERS_TABLE",
".",
"\" u ON (p.author_id = u.user_id)\n\t\t\t\tWHERE msg_id = \"",
".",
"intval",
"(",
"$",
"msg_id",
")",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"row",
"=",
"$",
"db",
"->",
"sql_fetchrow",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"$",
"row",
")",
"{",
"trigger_error",
"(",
"'NO_PRIVMSG'",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"privmsg",
"=",
"new",
"privmsg",
"(",
")",
";",
"$",
"privmsg",
"->",
"reply_from_msg_id",
"=",
"$",
"row",
"[",
"'msg_id'",
"]",
";",
"$",
"privmsg",
"->",
"root_level",
"=",
"(",
"$",
"row",
"[",
"'root_level'",
"]",
"?",
"$",
"row",
"[",
"'root_level'",
"]",
":",
"$",
"row",
"[",
"'msg_id'",
"]",
")",
";",
"$",
"privmsg",
"->",
"message_subject",
"=",
"(",
"(",
"!",
"preg_match",
"(",
"'/^Re:/'",
",",
"$",
"row",
"[",
"'message_subject'",
"]",
")",
")",
"?",
"'Re: '",
":",
"''",
")",
".",
"censor_text",
"(",
"$",
"row",
"[",
"'message_subject'",
"]",
")",
";",
"if",
"(",
"$",
"quote",
")",
"{",
"decode_message",
"(",
"$",
"row",
"[",
"'message_text'",
"]",
",",
"$",
"row",
"[",
"'bbcode_uid'",
"]",
")",
";",
"//for some reason we need " here instead of \"",
"$",
"privmsg",
"->",
"message_text",
"=",
"'[quote="'",
".",
"$",
"row",
"[",
"'username'",
"]",
".",
"'"]'",
".",
"censor_text",
"(",
"trim",
"(",
"$",
"row",
"[",
"'message_text'",
"]",
")",
")",
".",
"\"[/quote]\\n\"",
";",
"}",
"//add original sender as recipient",
"$",
"privmsg",
"->",
"to",
"(",
"$",
"row",
"[",
"'author_id'",
"]",
")",
";",
"//if message had only a single recipient, use that as sender",
"if",
"(",
"$",
"row",
"[",
"'to_address'",
"]",
"==",
"''",
"||",
"$",
"row",
"[",
"'bcc_address'",
"]",
"==",
"''",
")",
"{",
"$",
"to",
"=",
"(",
"$",
"row",
"[",
"'to_address'",
"]",
"!=",
"''",
")",
"?",
"$",
"row",
"[",
"'to_address'",
"]",
":",
"$",
"row",
"[",
"'bcc_address'",
"]",
";",
"if",
"(",
"preg_match",
"(",
"'#^u_(\\\\d+)$#'",
",",
"$",
"to",
",",
"$",
"m",
")",
")",
"{",
"$",
"privmsg",
"->",
"author_id",
"=",
"$",
"m",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"$",
"privmsg",
";",
"}"
] | initializes and returns a new privmsg object as reply to the message with msg_id $msg_id | [
"initializes",
"and",
"returns",
"a",
"new",
"privmsg",
"object",
"as",
"reply",
"to",
"the",
"message",
"with",
"msg_id",
"$msg_id"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L1437-L1478 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | privmsg.to | function to()
{
$type = 'to';
$ug_type = 'u';
$id = 0;
$args = func_get_args();
$args = array_map('strtolower', $args);
foreach($args as $arg)
{
switch($arg)
{
case 'to': $type = 'to'; break;
case 'bcc': $type = 'bcc'; break;
case 'user': case 'u': $ug_type = 'u'; break;
case 'group': case 'g': $ug_type = 'g'; break;
}
if(is_numeric($arg)) $id = intval($arg);
}
if($id == 0)
{
trigger_error('privmsg->to(): no id given', E_USER_ERROR);
}
$this->address_list[$ug_type][$id] = $type;
} | php | function to()
{
$type = 'to';
$ug_type = 'u';
$id = 0;
$args = func_get_args();
$args = array_map('strtolower', $args);
foreach($args as $arg)
{
switch($arg)
{
case 'to': $type = 'to'; break;
case 'bcc': $type = 'bcc'; break;
case 'user': case 'u': $ug_type = 'u'; break;
case 'group': case 'g': $ug_type = 'g'; break;
}
if(is_numeric($arg)) $id = intval($arg);
}
if($id == 0)
{
trigger_error('privmsg->to(): no id given', E_USER_ERROR);
}
$this->address_list[$ug_type][$id] = $type;
} | [
"function",
"to",
"(",
")",
"{",
"$",
"type",
"=",
"'to'",
";",
"$",
"ug_type",
"=",
"'u'",
";",
"$",
"id",
"=",
"0",
";",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"args",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"args",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"switch",
"(",
"$",
"arg",
")",
"{",
"case",
"'to'",
":",
"$",
"type",
"=",
"'to'",
";",
"break",
";",
"case",
"'bcc'",
":",
"$",
"type",
"=",
"'bcc'",
";",
"break",
";",
"case",
"'user'",
":",
"case",
"'u'",
":",
"$",
"ug_type",
"=",
"'u'",
";",
"break",
";",
"case",
"'group'",
":",
"case",
"'g'",
":",
"$",
"ug_type",
"=",
"'g'",
";",
"break",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"arg",
")",
")",
"$",
"id",
"=",
"intval",
"(",
"$",
"arg",
")",
";",
"}",
"if",
"(",
"$",
"id",
"==",
"0",
")",
"{",
"trigger_error",
"(",
"'privmsg->to(): no id given'",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"address_list",
"[",
"$",
"ug_type",
"]",
"[",
"$",
"id",
"]",
"=",
"$",
"type",
";",
"}"
] | adds a recipient. arguments can be (in any order):
- 'to': set type to 'to' (default)
- 'bcc': set type to 'bcc'
- integer: a user_id or group_id
- 'u' or 'user': the number is a user_id (default)
- 'g' or 'group': the number is a group_id
e.g. $pm->to('user', 'to', 123); | [
"adds",
"a",
"recipient",
".",
"arguments",
"can",
"be",
"(",
"in",
"any",
"order",
")",
":",
"-",
"to",
":",
"set",
"type",
"to",
"to",
"(",
"default",
")",
"-",
"bcc",
":",
"set",
"type",
"to",
"bcc",
"-",
"integer",
":",
"a",
"user_id",
"or",
"group_id",
"-",
"u",
"or",
"user",
":",
"the",
"number",
"is",
"a",
"user_id",
"(",
"default",
")",
"-",
"g",
"or",
"group",
":",
"the",
"number",
"is",
"a",
"group_id",
"e",
".",
"g",
".",
"$pm",
"-",
">",
"to",
"(",
"user",
"to",
"123",
")",
";"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L1488-L1514 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | attachment.create_checked | function create_checked($file, $forum_id, $mimetype = 'application/octetstream')
{
global $user;
if(!file_exists($file))
{
trigger_error('FILE_NOT_FOUND', E_USER_ERROR);
}
$filedata = array(
'realname' => basename($file),
'size' => filesize($file),
'type' => $mimetype
);
$filedata = upload_attachment(false, $forum_id, true, $file, false, $filedata);
if ($filedata['post_attach'] && !sizeof($filedata['error']))
{
$attachment = new attachment();
$attachment->poster_id = $user->data['user_id'];
$attachment->physical_filename = $filedata['physical_filename'];
$attachment->real_filename = $filedata['real_filename'];
$attachment->extension = $filedata['extension'];
$attachment->mimetype = $filedata['mimetype'];
$attachment->filesize = $filedata['filesize'];
$attachment->filetime = $filedata['filetime'];
$attachment->thumbnail = $filedata['thumbnail'];
$attachment->submit();
return $attachment;
}
else {
trigger_error(implode('<br/>', $filedata['error']), E_USER_ERROR);
}
} | php | function create_checked($file, $forum_id, $mimetype = 'application/octetstream')
{
global $user;
if(!file_exists($file))
{
trigger_error('FILE_NOT_FOUND', E_USER_ERROR);
}
$filedata = array(
'realname' => basename($file),
'size' => filesize($file),
'type' => $mimetype
);
$filedata = upload_attachment(false, $forum_id, true, $file, false, $filedata);
if ($filedata['post_attach'] && !sizeof($filedata['error']))
{
$attachment = new attachment();
$attachment->poster_id = $user->data['user_id'];
$attachment->physical_filename = $filedata['physical_filename'];
$attachment->real_filename = $filedata['real_filename'];
$attachment->extension = $filedata['extension'];
$attachment->mimetype = $filedata['mimetype'];
$attachment->filesize = $filedata['filesize'];
$attachment->filetime = $filedata['filetime'];
$attachment->thumbnail = $filedata['thumbnail'];
$attachment->submit();
return $attachment;
}
else {
trigger_error(implode('<br/>', $filedata['error']), E_USER_ERROR);
}
} | [
"function",
"create_checked",
"(",
"$",
"file",
",",
"$",
"forum_id",
",",
"$",
"mimetype",
"=",
"'application/octetstream'",
")",
"{",
"global",
"$",
"user",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"trigger_error",
"(",
"'FILE_NOT_FOUND'",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"filedata",
"=",
"array",
"(",
"'realname'",
"=>",
"basename",
"(",
"$",
"file",
")",
",",
"'size'",
"=>",
"filesize",
"(",
"$",
"file",
")",
",",
"'type'",
"=>",
"$",
"mimetype",
")",
";",
"$",
"filedata",
"=",
"upload_attachment",
"(",
"false",
",",
"$",
"forum_id",
",",
"true",
",",
"$",
"file",
",",
"false",
",",
"$",
"filedata",
")",
";",
"if",
"(",
"$",
"filedata",
"[",
"'post_attach'",
"]",
"&&",
"!",
"sizeof",
"(",
"$",
"filedata",
"[",
"'error'",
"]",
")",
")",
"{",
"$",
"attachment",
"=",
"new",
"attachment",
"(",
")",
";",
"$",
"attachment",
"->",
"poster_id",
"=",
"$",
"user",
"->",
"data",
"[",
"'user_id'",
"]",
";",
"$",
"attachment",
"->",
"physical_filename",
"=",
"$",
"filedata",
"[",
"'physical_filename'",
"]",
";",
"$",
"attachment",
"->",
"real_filename",
"=",
"$",
"filedata",
"[",
"'real_filename'",
"]",
";",
"$",
"attachment",
"->",
"extension",
"=",
"$",
"filedata",
"[",
"'extension'",
"]",
";",
"$",
"attachment",
"->",
"mimetype",
"=",
"$",
"filedata",
"[",
"'mimetype'",
"]",
";",
"$",
"attachment",
"->",
"filesize",
"=",
"$",
"filedata",
"[",
"'filesize'",
"]",
";",
"$",
"attachment",
"->",
"filetime",
"=",
"$",
"filedata",
"[",
"'filetime'",
"]",
";",
"$",
"attachment",
"->",
"thumbnail",
"=",
"$",
"filedata",
"[",
"'thumbnail'",
"]",
";",
"$",
"attachment",
"->",
"submit",
"(",
")",
";",
"return",
"$",
"attachment",
";",
"}",
"else",
"{",
"trigger_error",
"(",
"implode",
"(",
"'<br/>'",
",",
"$",
"filedata",
"[",
"'error'",
"]",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"}"
] | creates an attachment through the phpBB function upload_attachment. i.e.
quota, allowed extensions etc. will be checked.
returns an attachment object on success or an array of error messages on failure
submit() is automatically called so that this attachment appears in the acp
"orphaned attachments" list if you dont assign it to a post.
WARNING: $file will be moved to the attachment storage | [
"creates",
"an",
"attachment",
"through",
"the",
"phpBB",
"function",
"upload_attachment",
".",
"i",
".",
"e",
".",
"quota",
"allowed",
"extensions",
"etc",
".",
"will",
"be",
"checked",
".",
"returns",
"an",
"attachment",
"object",
"on",
"success",
"or",
"an",
"array",
"of",
"error",
"messages",
"on",
"failure",
"submit",
"()",
"is",
"automatically",
"called",
"so",
"that",
"this",
"attachment",
"appears",
"in",
"the",
"acp",
"orphaned",
"attachments",
"list",
"if",
"you",
"dont",
"assign",
"it",
"to",
"a",
"post",
".",
"WARNING",
":",
"$file",
"will",
"be",
"moved",
"to",
"the",
"attachment",
"storage"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L1636-L1668 |
gn36/phpbb-oo-posting-api | functions_post_oo.php | syncer.add | function add($type, $id, $field, $amount = 1)
{
$this->init($type, $id);
if(!isset($this->data[$type][$id]['add'][$field]))
{
$this->data[$type][$id]['add'][$field] = 0;
}
$this->data[$type][$id]['add'][$field] += $amount;
} | php | function add($type, $id, $field, $amount = 1)
{
$this->init($type, $id);
if(!isset($this->data[$type][$id]['add'][$field]))
{
$this->data[$type][$id]['add'][$field] = 0;
}
$this->data[$type][$id]['add'][$field] += $amount;
} | [
"function",
"add",
"(",
"$",
"type",
",",
"$",
"id",
",",
"$",
"field",
",",
"$",
"amount",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"init",
"(",
"$",
"type",
",",
"$",
"id",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"type",
"]",
"[",
"$",
"id",
"]",
"[",
"'add'",
"]",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"type",
"]",
"[",
"$",
"id",
"]",
"[",
"'add'",
"]",
"[",
"$",
"field",
"]",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"$",
"type",
"]",
"[",
"$",
"id",
"]",
"[",
"'add'",
"]",
"[",
"$",
"field",
"]",
"+=",
"$",
"amount",
";",
"}"
] | increments or decrements a field.
@param $type which table (topic, user, forum or post)
@param $id topic_id, user_id etc.
@param $field field name (e.g. topic_replies)
@param $amount how much to add/subtract (default 1)
example: $sync->add('topic', 123, 'topic_replies', 1)
-> UPDATE phpbb_topics SET topic_replies = topic_replies + 1 WHERE topic_id = 123 | [
"increments",
"or",
"decrements",
"a",
"field",
"."
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/functions_post_oo.php#L1866-L1874 |
php-lug/lug | src/Bundle/GridBundle/Filter/FilterManager.php | FilterManager.get | public function get(GridInterface $grid)
{
return $this->storage !== null && isset($this->storage[$key = $this->getKey($grid)])
? $this->storage[$key]
: $grid->getData();
} | php | public function get(GridInterface $grid)
{
return $this->storage !== null && isset($this->storage[$key = $this->getKey($grid)])
? $this->storage[$key]
: $grid->getData();
} | [
"public",
"function",
"get",
"(",
"GridInterface",
"$",
"grid",
")",
"{",
"return",
"$",
"this",
"->",
"storage",
"!==",
"null",
"&&",
"isset",
"(",
"$",
"this",
"->",
"storage",
"[",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"grid",
")",
"]",
")",
"?",
"$",
"this",
"->",
"storage",
"[",
"$",
"key",
"]",
":",
"$",
"grid",
"->",
"getData",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Filter/FilterManager.php#L38-L43 |
php-lug/lug | src/Bundle/GridBundle/Filter/FilterManager.php | FilterManager.set | public function set(GridInterface $grid, array $filters)
{
if ($this->storage !== null) {
$this->storage[$this->getKey($grid)] = $filters;
}
} | php | public function set(GridInterface $grid, array $filters)
{
if ($this->storage !== null) {
$this->storage[$this->getKey($grid)] = $filters;
}
} | [
"public",
"function",
"set",
"(",
"GridInterface",
"$",
"grid",
",",
"array",
"$",
"filters",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"storage",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"storage",
"[",
"$",
"this",
"->",
"getKey",
"(",
"$",
"grid",
")",
"]",
"=",
"$",
"filters",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Filter/FilterManager.php#L48-L53 |
ronaldborla/chikka | src/Borla/Chikka/Sender.php | Sender.reply | public function reply(Message $message, $adjustCost = true) {
// Return
return $this->request($message->toReply($adjustCost))
// Attach message
->attach('message', $message);
} | php | public function reply(Message $message, $adjustCost = true) {
// Return
return $this->request($message->toReply($adjustCost))
// Attach message
->attach('message', $message);
} | [
"public",
"function",
"reply",
"(",
"Message",
"$",
"message",
",",
"$",
"adjustCost",
"=",
"true",
")",
"{",
"// Return",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"message",
"->",
"toReply",
"(",
"$",
"adjustCost",
")",
")",
"// Attach message",
"->",
"attach",
"(",
"'message'",
",",
"$",
"message",
")",
";",
"}"
] | Reply | [
"Reply"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Sender.php#L51-L56 |
ronaldborla/chikka | src/Borla/Chikka/Sender.php | Sender.request | public function request(array $data) {
// Create request
$request = Loader::request($this->config, $data);
// Return response
return Loader::response(
// Execute
$this->getHttp()->post($this->getRequestUrl(), (string) $request)->json
// Attach request
)->attach('request', $request);
} | php | public function request(array $data) {
// Create request
$request = Loader::request($this->config, $data);
// Return response
return Loader::response(
// Execute
$this->getHttp()->post($this->getRequestUrl(), (string) $request)->json
// Attach request
)->attach('request', $request);
} | [
"public",
"function",
"request",
"(",
"array",
"$",
"data",
")",
"{",
"// Create request",
"$",
"request",
"=",
"Loader",
"::",
"request",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"data",
")",
";",
"// Return response",
"return",
"Loader",
"::",
"response",
"(",
"// Execute",
"$",
"this",
"->",
"getHttp",
"(",
")",
"->",
"post",
"(",
"$",
"this",
"->",
"getRequestUrl",
"(",
")",
",",
"(",
"string",
")",
"$",
"request",
")",
"->",
"json",
"// Attach request",
")",
"->",
"attach",
"(",
"'request'",
",",
"$",
"request",
")",
";",
"}"
] | Create a request | [
"Create",
"a",
"request"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Sender.php#L61-L70 |
bfitech/zapstore | src/SQL.php | SQL.open_pdo_connection | private function open_pdo_connection() {
try {
$this->connection = in_array(
$this->dbtype, ['sqlite3', 'pgsql'])
? new \PDO($this->connection_string)
: new \PDO(
$this->connection_string,
$this->dbuser, $this->dbpass);
self::$logger->debug(sprintf(
"SQL: connection opened: '%s'.",
json_encode($this->verified_params)));
} catch (\PDOException $e) {
self::$logger->error(sprintf(
"SQL: connection failed: '%s'.",
json_encode($this->verified_params)));
throw new SQLError(SQLError::CONNECTION_ERROR,
$this->dbtype . " connection error.");
}
$this->connection->setAttribute(
\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
# set pragma for SQLite3
if ($this->dbtype == 'sqlite3')
$this->connection->exec("PRAGMA foreign_keys=ON");
} | php | private function open_pdo_connection() {
try {
$this->connection = in_array(
$this->dbtype, ['sqlite3', 'pgsql'])
? new \PDO($this->connection_string)
: new \PDO(
$this->connection_string,
$this->dbuser, $this->dbpass);
self::$logger->debug(sprintf(
"SQL: connection opened: '%s'.",
json_encode($this->verified_params)));
} catch (\PDOException $e) {
self::$logger->error(sprintf(
"SQL: connection failed: '%s'.",
json_encode($this->verified_params)));
throw new SQLError(SQLError::CONNECTION_ERROR,
$this->dbtype . " connection error.");
}
$this->connection->setAttribute(
\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
# set pragma for SQLite3
if ($this->dbtype == 'sqlite3')
$this->connection->exec("PRAGMA foreign_keys=ON");
} | [
"private",
"function",
"open_pdo_connection",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"connection",
"=",
"in_array",
"(",
"$",
"this",
"->",
"dbtype",
",",
"[",
"'sqlite3'",
",",
"'pgsql'",
"]",
")",
"?",
"new",
"\\",
"PDO",
"(",
"$",
"this",
"->",
"connection_string",
")",
":",
"new",
"\\",
"PDO",
"(",
"$",
"this",
"->",
"connection_string",
",",
"$",
"this",
"->",
"dbuser",
",",
"$",
"this",
"->",
"dbpass",
")",
";",
"self",
"::",
"$",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"\"SQL: connection opened: '%s'.\"",
",",
"json_encode",
"(",
"$",
"this",
"->",
"verified_params",
")",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"sprintf",
"(",
"\"SQL: connection failed: '%s'.\"",
",",
"json_encode",
"(",
"$",
"this",
"->",
"verified_params",
")",
")",
")",
";",
"throw",
"new",
"SQLError",
"(",
"SQLError",
"::",
"CONNECTION_ERROR",
",",
"$",
"this",
"->",
"dbtype",
".",
"\" connection error.\"",
")",
";",
"}",
"$",
"this",
"->",
"connection",
"->",
"setAttribute",
"(",
"\\",
"PDO",
"::",
"ATTR_ERRMODE",
",",
"\\",
"PDO",
"::",
"ERRMODE_EXCEPTION",
")",
";",
"# set pragma for SQLite3",
"if",
"(",
"$",
"this",
"->",
"dbtype",
"==",
"'sqlite3'",
")",
"$",
"this",
"->",
"connection",
"->",
"exec",
"(",
"\"PRAGMA foreign_keys=ON\"",
")",
";",
"}"
] | Open PDO connection. | [
"Open",
"PDO",
"connection",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L126-L151 |
bfitech/zapstore | src/SQL.php | SQL.format_connection_string | private function format_connection_string() {
if (!in_array($this->dbtype, ['sqlite3', 'mysql', 'pgsql'])) {
$this->verified_params = null;
self::$logger->error(sprintf(
"SQL: database not supported: '%s'.",
$this->dbtype));
throw new SQLError(SQLError::DBTYPE_ERROR,
$this->dbtype . " not supported.");
}
if ($this->dbtype == 'sqlite3')
return $this->connection_string = 'sqlite:' . $this->dbname;
if (!$this->dbuser) {
$this->verified_params = null;
self::$logger->error(
"SQL: param not supplied: 'dbuser'.");
throw new SQLError(
SQLError::CONNECTION_ARGS_ERROR,
"'dbuser' not supplied.");
}
$cstr = sprintf("%s:dbname=%s", $this->dbtype, $this->dbname);
if ($this->dbhost) {
$cstr .= sprintf(';host=%s', $this->dbhost);
if ($this->dbport)
$cstr .= sprintf(';port=%s', $this->dbport);
}
if ($this->dbtype == 'mysql')
# mysql uses dbuser and dbpass on PDO constructor
return $this->connection_string = $cstr;
$cstr .= sprintf(";user=%s", $this->dbuser);
if ($this->dbpass)
$cstr .= sprintf(";password=%s", $this->dbpass);
return $this->connection_string = $cstr;
} | php | private function format_connection_string() {
if (!in_array($this->dbtype, ['sqlite3', 'mysql', 'pgsql'])) {
$this->verified_params = null;
self::$logger->error(sprintf(
"SQL: database not supported: '%s'.",
$this->dbtype));
throw new SQLError(SQLError::DBTYPE_ERROR,
$this->dbtype . " not supported.");
}
if ($this->dbtype == 'sqlite3')
return $this->connection_string = 'sqlite:' . $this->dbname;
if (!$this->dbuser) {
$this->verified_params = null;
self::$logger->error(
"SQL: param not supplied: 'dbuser'.");
throw new SQLError(
SQLError::CONNECTION_ARGS_ERROR,
"'dbuser' not supplied.");
}
$cstr = sprintf("%s:dbname=%s", $this->dbtype, $this->dbname);
if ($this->dbhost) {
$cstr .= sprintf(';host=%s', $this->dbhost);
if ($this->dbport)
$cstr .= sprintf(';port=%s', $this->dbport);
}
if ($this->dbtype == 'mysql')
# mysql uses dbuser and dbpass on PDO constructor
return $this->connection_string = $cstr;
$cstr .= sprintf(";user=%s", $this->dbuser);
if ($this->dbpass)
$cstr .= sprintf(";password=%s", $this->dbpass);
return $this->connection_string = $cstr;
} | [
"private",
"function",
"format_connection_string",
"(",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"dbtype",
",",
"[",
"'sqlite3'",
",",
"'mysql'",
",",
"'pgsql'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"verified_params",
"=",
"null",
";",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"sprintf",
"(",
"\"SQL: database not supported: '%s'.\"",
",",
"$",
"this",
"->",
"dbtype",
")",
")",
";",
"throw",
"new",
"SQLError",
"(",
"SQLError",
"::",
"DBTYPE_ERROR",
",",
"$",
"this",
"->",
"dbtype",
".",
"\" not supported.\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dbtype",
"==",
"'sqlite3'",
")",
"return",
"$",
"this",
"->",
"connection_string",
"=",
"'sqlite:'",
".",
"$",
"this",
"->",
"dbname",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"dbuser",
")",
"{",
"$",
"this",
"->",
"verified_params",
"=",
"null",
";",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"\"SQL: param not supplied: 'dbuser'.\"",
")",
";",
"throw",
"new",
"SQLError",
"(",
"SQLError",
"::",
"CONNECTION_ARGS_ERROR",
",",
"\"'dbuser' not supplied.\"",
")",
";",
"}",
"$",
"cstr",
"=",
"sprintf",
"(",
"\"%s:dbname=%s\"",
",",
"$",
"this",
"->",
"dbtype",
",",
"$",
"this",
"->",
"dbname",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dbhost",
")",
"{",
"$",
"cstr",
".=",
"sprintf",
"(",
"';host=%s'",
",",
"$",
"this",
"->",
"dbhost",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dbport",
")",
"$",
"cstr",
".=",
"sprintf",
"(",
"';port=%s'",
",",
"$",
"this",
"->",
"dbport",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dbtype",
"==",
"'mysql'",
")",
"# mysql uses dbuser and dbpass on PDO constructor",
"return",
"$",
"this",
"->",
"connection_string",
"=",
"$",
"cstr",
";",
"$",
"cstr",
".=",
"sprintf",
"(",
"\";user=%s\"",
",",
"$",
"this",
"->",
"dbuser",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dbpass",
")",
"$",
"cstr",
".=",
"sprintf",
"(",
"\";password=%s\"",
",",
"$",
"this",
"->",
"dbpass",
")",
";",
"return",
"$",
"this",
"->",
"connection_string",
"=",
"$",
"cstr",
";",
"}"
] | Verify and format connection string. | [
"Verify",
"and",
"format",
"connection",
"string",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L156-L193 |
bfitech/zapstore | src/SQL.php | SQL.time | final public function time() {
if ($this->dbtype == 'pgsql')
return $this->query(
"SELECT EXTRACT('epoch' from CURRENT_TIMESTAMP) AS now"
)['now'];
if ($this->dbtype == 'mysql')
return $this->query(
"SELECT UNIX_TIMESTAMP() AS now")['now'];
return $this->query(
"SELECT strftime('%s', CURRENT_TIMESTAMP) AS now"
)['now'];
} | php | final public function time() {
if ($this->dbtype == 'pgsql')
return $this->query(
"SELECT EXTRACT('epoch' from CURRENT_TIMESTAMP) AS now"
)['now'];
if ($this->dbtype == 'mysql')
return $this->query(
"SELECT UNIX_TIMESTAMP() AS now")['now'];
return $this->query(
"SELECT strftime('%s', CURRENT_TIMESTAMP) AS now"
)['now'];
} | [
"final",
"public",
"function",
"time",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dbtype",
"==",
"'pgsql'",
")",
"return",
"$",
"this",
"->",
"query",
"(",
"\"SELECT EXTRACT('epoch' from CURRENT_TIMESTAMP) AS now\"",
")",
"[",
"'now'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"dbtype",
"==",
"'mysql'",
")",
"return",
"$",
"this",
"->",
"query",
"(",
"\"SELECT UNIX_TIMESTAMP() AS now\"",
")",
"[",
"'now'",
"]",
";",
"return",
"$",
"this",
"->",
"query",
"(",
"\"SELECT strftime('%s', CURRENT_TIMESTAMP) AS now\"",
")",
"[",
"'now'",
"]",
";",
"}"
] | Get Unix timestamp from database server.
@return int Unix epoch. | [
"Get",
"Unix",
"timestamp",
"from",
"database",
"server",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L209-L220 |
bfitech/zapstore | src/SQL.php | SQL.stmt_fragment_datetime | private function stmt_fragment_datetime($delta) {
$sign = $delta >= 0 ? '+' : '-';
$delta = abs($delta);
$date = '';
switch ($this->dbtype) {
case 'sqlite3':
$date = "(datetime('now', '%s%s second'))";
break;
case 'pgsql':
$date = (
"(" .
"now() at time zone 'utc' %s " .
"interval '%s second'" .
")::timestamp(0)"
);
break;
case 'mysql':
# mysql cannot accept function default; do
# not use this on DDL
$date = (
"(date_add(utc_timestamp(), interval %s%s second))"
);
break;
}
return sprintf($date, $sign, $delta);
} | php | private function stmt_fragment_datetime($delta) {
$sign = $delta >= 0 ? '+' : '-';
$delta = abs($delta);
$date = '';
switch ($this->dbtype) {
case 'sqlite3':
$date = "(datetime('now', '%s%s second'))";
break;
case 'pgsql':
$date = (
"(" .
"now() at time zone 'utc' %s " .
"interval '%s second'" .
")::timestamp(0)"
);
break;
case 'mysql':
# mysql cannot accept function default; do
# not use this on DDL
$date = (
"(date_add(utc_timestamp(), interval %s%s second))"
);
break;
}
return sprintf($date, $sign, $delta);
} | [
"private",
"function",
"stmt_fragment_datetime",
"(",
"$",
"delta",
")",
"{",
"$",
"sign",
"=",
"$",
"delta",
">=",
"0",
"?",
"'+'",
":",
"'-'",
";",
"$",
"delta",
"=",
"abs",
"(",
"$",
"delta",
")",
";",
"$",
"date",
"=",
"''",
";",
"switch",
"(",
"$",
"this",
"->",
"dbtype",
")",
"{",
"case",
"'sqlite3'",
":",
"$",
"date",
"=",
"\"(datetime('now', '%s%s second'))\"",
";",
"break",
";",
"case",
"'pgsql'",
":",
"$",
"date",
"=",
"(",
"\"(\"",
".",
"\"now() at time zone 'utc' %s \"",
".",
"\"interval '%s second'\"",
".",
"\")::timestamp(0)\"",
")",
";",
"break",
";",
"case",
"'mysql'",
":",
"# mysql cannot accept function default; do",
"# not use this on DDL",
"$",
"date",
"=",
"(",
"\"(date_add(utc_timestamp(), interval %s%s second))\"",
")",
";",
"break",
";",
"}",
"return",
"sprintf",
"(",
"$",
"date",
",",
"$",
"sign",
",",
"$",
"delta",
")",
";",
"}"
] | SQL datetime fragment. | [
"SQL",
"datetime",
"fragment",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L225-L250 |
bfitech/zapstore | src/SQL.php | SQL.stmt_fragment | public function stmt_fragment($part, $args=[]) {
$type = $this->dbtype;
if ($part == 'engine') {
if ($type == 'mysql')
# we only intent to support FOREIGN KEY-capable engines
return "ENGINE=InnoDB";
return '';
}
if ($part == "index") {
if ($type == 'pgsql')
return 'SERIAL PRIMARY KEY';
if ($type == 'mysql')
return 'INTEGER PRIMARY KEY AUTO_INCREMENT';
return 'INTEGER PRIMARY KEY AUTOINCREMENT';
}
if ($part == 'datetime') {
$delta = 0;
if ($args && isset($args['delta']))
$delta = (int)$args['delta'];
return $this->stmt_fragment_datetime($delta);
}
return "";
} | php | public function stmt_fragment($part, $args=[]) {
$type = $this->dbtype;
if ($part == 'engine') {
if ($type == 'mysql')
# we only intent to support FOREIGN KEY-capable engines
return "ENGINE=InnoDB";
return '';
}
if ($part == "index") {
if ($type == 'pgsql')
return 'SERIAL PRIMARY KEY';
if ($type == 'mysql')
return 'INTEGER PRIMARY KEY AUTO_INCREMENT';
return 'INTEGER PRIMARY KEY AUTOINCREMENT';
}
if ($part == 'datetime') {
$delta = 0;
if ($args && isset($args['delta']))
$delta = (int)$args['delta'];
return $this->stmt_fragment_datetime($delta);
}
return "";
} | [
"public",
"function",
"stmt_fragment",
"(",
"$",
"part",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"dbtype",
";",
"if",
"(",
"$",
"part",
"==",
"'engine'",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"'mysql'",
")",
"# we only intent to support FOREIGN KEY-capable engines",
"return",
"\"ENGINE=InnoDB\"",
";",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"part",
"==",
"\"index\"",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"'pgsql'",
")",
"return",
"'SERIAL PRIMARY KEY'",
";",
"if",
"(",
"$",
"type",
"==",
"'mysql'",
")",
"return",
"'INTEGER PRIMARY KEY AUTO_INCREMENT'",
";",
"return",
"'INTEGER PRIMARY KEY AUTOINCREMENT'",
";",
"}",
"if",
"(",
"$",
"part",
"==",
"'datetime'",
")",
"{",
"$",
"delta",
"=",
"0",
";",
"if",
"(",
"$",
"args",
"&&",
"isset",
"(",
"$",
"args",
"[",
"'delta'",
"]",
")",
")",
"$",
"delta",
"=",
"(",
"int",
")",
"$",
"args",
"[",
"'delta'",
"]",
";",
"return",
"$",
"this",
"->",
"stmt_fragment_datetime",
"(",
"$",
"delta",
")",
";",
"}",
"return",
"\"\"",
";",
"}"
] | SQL statement fragment.
@param string $part A part sensitive to the database being used,
one of these: 'engine', 'index', 'datetime'.
@param array $args Dict of parameters for $part, for 'datetime'
only. | [
"SQL",
"statement",
"fragment",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L260-L282 |
bfitech/zapstore | src/SQL.php | SQL.table_exists | public function table_exists($table) {
# we can't use placeholder for table name
if (!preg_match('!^[0-9a-z_]+$!i', $table))
return false;
self::$logger->deactivate();
try {
$this->query(sprintf("SELECT 1 FROM %s LIMIT 1", $table));
self::$logger->activate();
return true;
} catch(SQLError $e) {
self::$logger->activate();
return false;
}
} | php | public function table_exists($table) {
# we can't use placeholder for table name
if (!preg_match('!^[0-9a-z_]+$!i', $table))
return false;
self::$logger->deactivate();
try {
$this->query(sprintf("SELECT 1 FROM %s LIMIT 1", $table));
self::$logger->activate();
return true;
} catch(SQLError $e) {
self::$logger->activate();
return false;
}
} | [
"public",
"function",
"table_exists",
"(",
"$",
"table",
")",
"{",
"# we can't use placeholder for table name",
"if",
"(",
"!",
"preg_match",
"(",
"'!^[0-9a-z_]+$!i'",
",",
"$",
"table",
")",
")",
"return",
"false",
";",
"self",
"::",
"$",
"logger",
"->",
"deactivate",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"query",
"(",
"sprintf",
"(",
"\"SELECT 1 FROM %s LIMIT 1\"",
",",
"$",
"table",
")",
")",
";",
"self",
"::",
"$",
"logger",
"->",
"activate",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"SQLError",
"$",
"e",
")",
"{",
"self",
"::",
"$",
"logger",
"->",
"activate",
"(",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Check if a table or view exists.
@param string $table Table or view name.
@return bool True if table or view does exist.
@fixme This will always re-activate logging at the end,
regardless the logging state. The fix must be in Logger
class itself where logging state must be exposed. | [
"Check",
"if",
"a",
"table",
"or",
"view",
"exists",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L293-L306 |
bfitech/zapstore | src/SQL.php | SQL.prepare_statement | private function prepare_statement($stmt, $args=[]) {
if (!$this->connection) {
self::$logger->error(sprintf(
"SQL: connection failed: '%s'.",
json_encode($this->verified_params)));
throw new SQLError(SQLError::CONNECTION_ERROR,
$this->dbtype . " connection error.");
}
$conn = $this->connection;
try {
$pstmt = $conn->prepare($stmt);
} catch (\PDOException $e) {
self::$logger->error(sprintf(
"SQL: execution failed: %s <- '%s': %s.",
$stmt, json_encode($args),
$e->getMessage()));
throw new SQLError(
SQLError::EXECUTION_ERROR,
sprintf("Execution error: %s.", $e->getMessage()),
$stmt, $args
);
}
try {
$pstmt->execute(array_values($args));
} catch (\PDOException $e) {
self::$logger->error(sprintf(
"SQL: execution failed: %s <- '%s': %s.",
$stmt, json_encode($args),
$e->getMessage()));
throw new SQLError(
SQLError::EXECUTION_ERROR,
sprintf("Execution error: %s.", $e->getMessage()),
$stmt, $args
);
}
return $pstmt;
} | php | private function prepare_statement($stmt, $args=[]) {
if (!$this->connection) {
self::$logger->error(sprintf(
"SQL: connection failed: '%s'.",
json_encode($this->verified_params)));
throw new SQLError(SQLError::CONNECTION_ERROR,
$this->dbtype . " connection error.");
}
$conn = $this->connection;
try {
$pstmt = $conn->prepare($stmt);
} catch (\PDOException $e) {
self::$logger->error(sprintf(
"SQL: execution failed: %s <- '%s': %s.",
$stmt, json_encode($args),
$e->getMessage()));
throw new SQLError(
SQLError::EXECUTION_ERROR,
sprintf("Execution error: %s.", $e->getMessage()),
$stmt, $args
);
}
try {
$pstmt->execute(array_values($args));
} catch (\PDOException $e) {
self::$logger->error(sprintf(
"SQL: execution failed: %s <- '%s': %s.",
$stmt, json_encode($args),
$e->getMessage()));
throw new SQLError(
SQLError::EXECUTION_ERROR,
sprintf("Execution error: %s.", $e->getMessage()),
$stmt, $args
);
}
return $pstmt;
} | [
"private",
"function",
"prepare_statement",
"(",
"$",
"stmt",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"connection",
")",
"{",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"sprintf",
"(",
"\"SQL: connection failed: '%s'.\"",
",",
"json_encode",
"(",
"$",
"this",
"->",
"verified_params",
")",
")",
")",
";",
"throw",
"new",
"SQLError",
"(",
"SQLError",
"::",
"CONNECTION_ERROR",
",",
"$",
"this",
"->",
"dbtype",
".",
"\" connection error.\"",
")",
";",
"}",
"$",
"conn",
"=",
"$",
"this",
"->",
"connection",
";",
"try",
"{",
"$",
"pstmt",
"=",
"$",
"conn",
"->",
"prepare",
"(",
"$",
"stmt",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"sprintf",
"(",
"\"SQL: execution failed: %s <- '%s': %s.\"",
",",
"$",
"stmt",
",",
"json_encode",
"(",
"$",
"args",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"throw",
"new",
"SQLError",
"(",
"SQLError",
"::",
"EXECUTION_ERROR",
",",
"sprintf",
"(",
"\"Execution error: %s.\"",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"stmt",
",",
"$",
"args",
")",
";",
"}",
"try",
"{",
"$",
"pstmt",
"->",
"execute",
"(",
"array_values",
"(",
"$",
"args",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"sprintf",
"(",
"\"SQL: execution failed: %s <- '%s': %s.\"",
",",
"$",
"stmt",
",",
"json_encode",
"(",
"$",
"args",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"throw",
"new",
"SQLError",
"(",
"SQLError",
"::",
"EXECUTION_ERROR",
",",
"sprintf",
"(",
"\"Execution error: %s.\"",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"stmt",
",",
"$",
"args",
")",
";",
"}",
"return",
"$",
"pstmt",
";",
"}"
] | Prepare and execute statement. | [
"Prepare",
"and",
"execute",
"statement",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L311-L350 |
bfitech/zapstore | src/SQL.php | SQL.query | final public function query($stmt, $args=[], $multiple=null) {
$pstmt = $this->prepare_statement($stmt, $args);
$res = $multiple
? $pstmt->fetchAll(\PDO::FETCH_ASSOC)
: $pstmt->fetch(\PDO::FETCH_ASSOC);
self::$logger->info(sprintf(
"SQL: query ok: %s <- '%s'.",
$stmt, json_encode($args)));
return $res;
} | php | final public function query($stmt, $args=[], $multiple=null) {
$pstmt = $this->prepare_statement($stmt, $args);
$res = $multiple
? $pstmt->fetchAll(\PDO::FETCH_ASSOC)
: $pstmt->fetch(\PDO::FETCH_ASSOC);
self::$logger->info(sprintf(
"SQL: query ok: %s <- '%s'.",
$stmt, json_encode($args)));
return $res;
} | [
"final",
"public",
"function",
"query",
"(",
"$",
"stmt",
",",
"$",
"args",
"=",
"[",
"]",
",",
"$",
"multiple",
"=",
"null",
")",
"{",
"$",
"pstmt",
"=",
"$",
"this",
"->",
"prepare_statement",
"(",
"$",
"stmt",
",",
"$",
"args",
")",
";",
"$",
"res",
"=",
"$",
"multiple",
"?",
"$",
"pstmt",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
":",
"$",
"pstmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"self",
"::",
"$",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"\"SQL: query ok: %s <- '%s'.\"",
",",
"$",
"stmt",
",",
"json_encode",
"(",
"$",
"args",
")",
")",
")",
";",
"return",
"$",
"res",
";",
"}"
] | Select query.
@param string $stmt SQL statement.
@param array $args Arguments in numeric array.
@param bool $multiple Whether returned result contains all rows.
@return mixed Rows or connection depending on $raw switch.
@note Since SQLite3 does not enforce type safety, make sure
arguments are cast properly before usage.
@see https://archive.fo/vKBEz#selection-449.0-454.0 | [
"Select",
"query",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L363-L372 |
bfitech/zapstore | src/SQL.php | SQL.query_raw | final public function query_raw($stmt, $args=[]) {
$pstmt = $this->prepare_statement($stmt, $args);
self::$logger->info(sprintf(
"SQL: query raw ok: %s.", $stmt));
return $pstmt;
} | php | final public function query_raw($stmt, $args=[]) {
$pstmt = $this->prepare_statement($stmt, $args);
self::$logger->info(sprintf(
"SQL: query raw ok: %s.", $stmt));
return $pstmt;
} | [
"final",
"public",
"function",
"query_raw",
"(",
"$",
"stmt",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"pstmt",
"=",
"$",
"this",
"->",
"prepare_statement",
"(",
"$",
"stmt",
",",
"$",
"args",
")",
";",
"self",
"::",
"$",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"\"SQL: query raw ok: %s.\"",
",",
"$",
"stmt",
")",
")",
";",
"return",
"$",
"pstmt",
";",
"}"
] | Execute raw query.
This will execute arbitray single SQL queries. Do not execute
multiple queries at once to avoid undocumented side effects.
To execute successive raw queries safely, disable autocommit as
follows:
@code
$connection = new SQL(...);
try {
$connection = $this->get_connection();
$connection->beginTransaction();
$this->query_raw(...);
$this->query_raw(...);
$this->query_raw(...);
$connection->commit();
} catch(SQLError $e) {
$connection->rollBack();
}
@endcode
@param string $stmt SQL statement.
@param array $args Arguments in numeric array.
@return object Executed statement which, depending on `$stmt`,
can be used for later processing. If `$stmt` is a SELECT
statement, rows can be fetched from this. | [
"Execute",
"raw",
"query",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L402-L407 |
bfitech/zapstore | src/SQL.php | SQL.insert | final public function insert($table, $args=[], $pk=null) {
$keys = $vals = [];
$keys = array_keys($args);
$vals = array_fill(0, count($args), '?');
$columns = implode(',', $keys);
$placeholders = implode(',', $vals);
$stmt = "INSERT INTO $table ($columns) VALUES ($placeholders)";
if ($this->dbtype == 'pgsql')
$stmt .= " RETURNING " . ($pk ? $pk : '*');
$pstmt = $this->prepare_statement($stmt, $args);
if ($this->dbtype == 'pgsql') {
$last = $pstmt->fetch(\PDO::FETCH_ASSOC);
$ret = $pk ? $last[$pk] : $last;
} else {
$ret = $this->connection->lastInsertId();
}
self::$logger->info(sprintf(
"SQL: insert ok: %s <- '%s'.",
$stmt, json_encode($args)));
return $ret;
} | php | final public function insert($table, $args=[], $pk=null) {
$keys = $vals = [];
$keys = array_keys($args);
$vals = array_fill(0, count($args), '?');
$columns = implode(',', $keys);
$placeholders = implode(',', $vals);
$stmt = "INSERT INTO $table ($columns) VALUES ($placeholders)";
if ($this->dbtype == 'pgsql')
$stmt .= " RETURNING " . ($pk ? $pk : '*');
$pstmt = $this->prepare_statement($stmt, $args);
if ($this->dbtype == 'pgsql') {
$last = $pstmt->fetch(\PDO::FETCH_ASSOC);
$ret = $pk ? $last[$pk] : $last;
} else {
$ret = $this->connection->lastInsertId();
}
self::$logger->info(sprintf(
"SQL: insert ok: %s <- '%s'.",
$stmt, json_encode($args)));
return $ret;
} | [
"final",
"public",
"function",
"insert",
"(",
"$",
"table",
",",
"$",
"args",
"=",
"[",
"]",
",",
"$",
"pk",
"=",
"null",
")",
"{",
"$",
"keys",
"=",
"$",
"vals",
"=",
"[",
"]",
";",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"args",
")",
";",
"$",
"vals",
"=",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"args",
")",
",",
"'?'",
")",
";",
"$",
"columns",
"=",
"implode",
"(",
"','",
",",
"$",
"keys",
")",
";",
"$",
"placeholders",
"=",
"implode",
"(",
"','",
",",
"$",
"vals",
")",
";",
"$",
"stmt",
"=",
"\"INSERT INTO $table ($columns) VALUES ($placeholders)\"",
";",
"if",
"(",
"$",
"this",
"->",
"dbtype",
"==",
"'pgsql'",
")",
"$",
"stmt",
".=",
"\" RETURNING \"",
".",
"(",
"$",
"pk",
"?",
"$",
"pk",
":",
"'*'",
")",
";",
"$",
"pstmt",
"=",
"$",
"this",
"->",
"prepare_statement",
"(",
"$",
"stmt",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dbtype",
"==",
"'pgsql'",
")",
"{",
"$",
"last",
"=",
"$",
"pstmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"ret",
"=",
"$",
"pk",
"?",
"$",
"last",
"[",
"$",
"pk",
"]",
":",
"$",
"last",
";",
"}",
"else",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"connection",
"->",
"lastInsertId",
"(",
")",
";",
"}",
"self",
"::",
"$",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"\"SQL: insert ok: %s <- '%s'.\"",
",",
"$",
"stmt",
",",
"json_encode",
"(",
"$",
"args",
")",
")",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Insert statement.
@param string $table Table name.
@param array $args Dict of what to INSERT.
@param string $pk Primary key from which last insert ID should
be retrieved. This won't take any effect on databases other
than Postgres. This can take any column name, not necessarily
column with PRIMARY KEY attributes. If left null, the whole
new row is returned as an array. Using invalid column will
throw exception.
@return int|array Last insert ID or IDs on success. Exception
thrown on error. | [
"Insert",
"statement",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L423-L449 |
bfitech/zapstore | src/SQL.php | SQL.update | final public function update($table, $args, $where=[]) {
$pair_args = $params = [];
foreach ($args as $key => $val) {
$pair_args[] = "{$key}=?";
$params[] = $val;
}
$stmt = sprintf("UPDATE $table SET %s",
implode(",", $pair_args));
if ($where) {
$pair_wheres = [];
foreach ($where as $key => $val) {
$pair_wheres[] = "${key}=?";
$params[] = $val;
}
$stmt .= " WHERE ";
$stmt .= implode(' AND ', $pair_wheres);
}
self::$logger->info(sprintf(
"SQL: update ok: %s <- '%s'.",
$stmt, json_encode($args)));
$this->prepare_statement($stmt, $params);
} | php | final public function update($table, $args, $where=[]) {
$pair_args = $params = [];
foreach ($args as $key => $val) {
$pair_args[] = "{$key}=?";
$params[] = $val;
}
$stmt = sprintf("UPDATE $table SET %s",
implode(",", $pair_args));
if ($where) {
$pair_wheres = [];
foreach ($where as $key => $val) {
$pair_wheres[] = "${key}=?";
$params[] = $val;
}
$stmt .= " WHERE ";
$stmt .= implode(' AND ', $pair_wheres);
}
self::$logger->info(sprintf(
"SQL: update ok: %s <- '%s'.",
$stmt, json_encode($args)));
$this->prepare_statement($stmt, $params);
} | [
"final",
"public",
"function",
"update",
"(",
"$",
"table",
",",
"$",
"args",
",",
"$",
"where",
"=",
"[",
"]",
")",
"{",
"$",
"pair_args",
"=",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"pair_args",
"[",
"]",
"=",
"\"{$key}=?\"",
";",
"$",
"params",
"[",
"]",
"=",
"$",
"val",
";",
"}",
"$",
"stmt",
"=",
"sprintf",
"(",
"\"UPDATE $table SET %s\"",
",",
"implode",
"(",
"\",\"",
",",
"$",
"pair_args",
")",
")",
";",
"if",
"(",
"$",
"where",
")",
"{",
"$",
"pair_wheres",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"where",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"pair_wheres",
"[",
"]",
"=",
"\"${key}=?\"",
";",
"$",
"params",
"[",
"]",
"=",
"$",
"val",
";",
"}",
"$",
"stmt",
".=",
"\" WHERE \"",
";",
"$",
"stmt",
".=",
"implode",
"(",
"' AND '",
",",
"$",
"pair_wheres",
")",
";",
"}",
"self",
"::",
"$",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"\"SQL: update ok: %s <- '%s'.\"",
",",
"$",
"stmt",
",",
"json_encode",
"(",
"$",
"args",
")",
")",
")",
";",
"$",
"this",
"->",
"prepare_statement",
"(",
"$",
"stmt",
",",
"$",
"params",
")",
";",
"}"
] | Update statement.
@param string $table Table name.
@param array $args Dict of what to UPDATE.
@param array $where Dict of WHERE to UPDATE. | [
"Update",
"statement",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L458-L483 |
bfitech/zapstore | src/SQL.php | SQL.delete | final public function delete($table, $where=[]) {
$stmt = "DELETE FROM $table";
if ($where) {
$pair_wheres = [];
$params = [];
foreach ($where as $key => $val) {
$pair_wheres[] = "{$key}=?";
$params[] = $val;
}
$stmt .= " WHERE " . implode(" AND ", $pair_wheres);
}
self::$logger->info(sprintf(
"SQL: delete ok: %s <- '%s'.",
$stmt, json_encode($where)));
$this->prepare_statement($stmt, $params);
} | php | final public function delete($table, $where=[]) {
$stmt = "DELETE FROM $table";
if ($where) {
$pair_wheres = [];
$params = [];
foreach ($where as $key => $val) {
$pair_wheres[] = "{$key}=?";
$params[] = $val;
}
$stmt .= " WHERE " . implode(" AND ", $pair_wheres);
}
self::$logger->info(sprintf(
"SQL: delete ok: %s <- '%s'.",
$stmt, json_encode($where)));
$this->prepare_statement($stmt, $params);
} | [
"final",
"public",
"function",
"delete",
"(",
"$",
"table",
",",
"$",
"where",
"=",
"[",
"]",
")",
"{",
"$",
"stmt",
"=",
"\"DELETE FROM $table\"",
";",
"if",
"(",
"$",
"where",
")",
"{",
"$",
"pair_wheres",
"=",
"[",
"]",
";",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"where",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"pair_wheres",
"[",
"]",
"=",
"\"{$key}=?\"",
";",
"$",
"params",
"[",
"]",
"=",
"$",
"val",
";",
"}",
"$",
"stmt",
".=",
"\" WHERE \"",
".",
"implode",
"(",
"\" AND \"",
",",
"$",
"pair_wheres",
")",
";",
"}",
"self",
"::",
"$",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"\"SQL: delete ok: %s <- '%s'.\"",
",",
"$",
"stmt",
",",
"json_encode",
"(",
"$",
"where",
")",
")",
")",
";",
"$",
"this",
"->",
"prepare_statement",
"(",
"$",
"stmt",
",",
"$",
"params",
")",
";",
"}"
] | Delete statement.
@param string $table Table name.
@param array $where Dict of WHERE to delete. | [
"Delete",
"statement",
"."
] | train | https://github.com/bfitech/zapstore/blob/0353a7a3f81cbc4e25fc1646fa2f98cb490b85d0/src/SQL.php#L491-L508 |
Danzabar/config-builder | src/Collections/Collection.php | Collection.registerStandardObjects | public function registerStandardObjects()
{
$this->extensionMap = new ExtensionMap();
$this->extensions = $this->extensionMap->getRegisteredExtensionNames();
$this->finder->files();
} | php | public function registerStandardObjects()
{
$this->extensionMap = new ExtensionMap();
$this->extensions = $this->extensionMap->getRegisteredExtensionNames();
$this->finder->files();
} | [
"public",
"function",
"registerStandardObjects",
"(",
")",
"{",
"$",
"this",
"->",
"extensionMap",
"=",
"new",
"ExtensionMap",
"(",
")",
";",
"$",
"this",
"->",
"extensions",
"=",
"$",
"this",
"->",
"extensionMap",
"->",
"getRegisteredExtensionNames",
"(",
")",
";",
"$",
"this",
"->",
"finder",
"->",
"files",
"(",
")",
";",
"}"
] | Registers the extension map and sets the finder to look for files
@return void
@author Dan Cox | [
"Registers",
"the",
"extension",
"map",
"and",
"sets",
"the",
"finder",
"to",
"look",
"for",
"files"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Collections/Collection.php#L95-L100 |
Danzabar/config-builder | src/Collections/Collection.php | Collection.filterByExtension | public function filterByExtension()
{
// The call back that filters files through the finder
$filter = function (\SplFileInfo $file) {
return in_array($file->getExtension(), $this->extensions);
};
$this->filter($filter);
} | php | public function filterByExtension()
{
// The call back that filters files through the finder
$filter = function (\SplFileInfo $file) {
return in_array($file->getExtension(), $this->extensions);
};
$this->filter($filter);
} | [
"public",
"function",
"filterByExtension",
"(",
")",
"{",
"// The call back that filters files through the finder",
"$",
"filter",
"=",
"function",
"(",
"\\",
"SplFileInfo",
"$",
"file",
")",
"{",
"return",
"in_array",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
",",
"$",
"this",
"->",
"extensions",
")",
";",
"}",
";",
"$",
"this",
"->",
"filter",
"(",
"$",
"filter",
")",
";",
"}"
] | Filters file results by their extension
@return void
@author Dan Cox | [
"Filters",
"file",
"results",
"by",
"their",
"extension"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Collections/Collection.php#L108-L117 |
Danzabar/config-builder | src/Collections/Collection.php | Collection.fetch | public function fetch()
{
$this->filterByExtension();
$results = Array();
foreach ($this->finder as $file)
{
$config = new ConfigFile($this->fs, $this->fileInfo, $this->extracter);
$config->load($file->getRealPath());
$results[] = $config;
}
$this->finder = new Finder();
return new CollectionResults($results);
} | php | public function fetch()
{
$this->filterByExtension();
$results = Array();
foreach ($this->finder as $file)
{
$config = new ConfigFile($this->fs, $this->fileInfo, $this->extracter);
$config->load($file->getRealPath());
$results[] = $config;
}
$this->finder = new Finder();
return new CollectionResults($results);
} | [
"public",
"function",
"fetch",
"(",
")",
"{",
"$",
"this",
"->",
"filterByExtension",
"(",
")",
";",
"$",
"results",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"config",
"=",
"new",
"ConfigFile",
"(",
"$",
"this",
"->",
"fs",
",",
"$",
"this",
"->",
"fileInfo",
",",
"$",
"this",
"->",
"extracter",
")",
";",
"$",
"config",
"->",
"load",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
";",
"$",
"results",
"[",
"]",
"=",
"$",
"config",
";",
"}",
"$",
"this",
"->",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"return",
"new",
"CollectionResults",
"(",
"$",
"results",
")",
";",
"}"
] | Fetches results of current instance of the finder
@return CollectionResults
@author Dan Cox | [
"Fetches",
"results",
"of",
"current",
"instance",
"of",
"the",
"finder"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Collections/Collection.php#L192-L208 |
Danzabar/config-builder | src/Collections/Collection.php | Collection.setDirectory | public function setDirectory($directory)
{
$this->directory = $directory;
// Set the finder to use this directory as well
$this->finder->in($directory);
return $this;
} | php | public function setDirectory($directory)
{
$this->directory = $directory;
// Set the finder to use this directory as well
$this->finder->in($directory);
return $this;
} | [
"public",
"function",
"setDirectory",
"(",
"$",
"directory",
")",
"{",
"$",
"this",
"->",
"directory",
"=",
"$",
"directory",
";",
"// Set the finder to use this directory as well",
"$",
"this",
"->",
"finder",
"->",
"in",
"(",
"$",
"directory",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the directory value
@param String $directory
@return Collection
@author Dan Cox | [
"Sets",
"the",
"directory",
"value"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Collections/Collection.php#L217-L225 |
nonzod/yii2-foundation | DropdownButton.php | DropdownButton.run | public function run() {
$dropdown = Dropdown::begin($this->getDropdownConfig());
echo "\n" . $this->renderButton($dropdown);
Dropdown::end();
$this->registerPlugin('button');
} | php | public function run() {
$dropdown = Dropdown::begin($this->getDropdownConfig());
echo "\n" . $this->renderButton($dropdown);
Dropdown::end();
$this->registerPlugin('button');
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"dropdown",
"=",
"Dropdown",
"::",
"begin",
"(",
"$",
"this",
"->",
"getDropdownConfig",
"(",
")",
")",
";",
"echo",
"\"\\n\"",
".",
"$",
"this",
"->",
"renderButton",
"(",
"$",
"dropdown",
")",
";",
"Dropdown",
"::",
"end",
"(",
")",
";",
"$",
"this",
"->",
"registerPlugin",
"(",
"'button'",
")",
";",
"}"
] | Renders the widget. | [
"Renders",
"the",
"widget",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/DropdownButton.php#L60-L66 |
nonzod/yii2-foundation | DropdownButton.php | DropdownButton.renderButton | protected function renderButton($dropdown) {
$dropdownId = $dropdown->getId();
$label = $this->label;
if ($this->encodeLabel) {
$label = Html::encode($label);
}
if ($this->split) {
$this->tagName = 'a';
Html::addCssClass($this->options, 'button');
Html::addCssClass($this->options, 'split');
$options = $this->options;
$label .= Html::tag('span', '', ['data-dropdown' => $dropdownId]);
} else {
Html::addCssClass($this->options, 'dropdown');
$options = $this->options;
$options['data-dropdown'] = $dropdownId;
}
return Button::widget([
'tagName' => $this->tagName,
'label' => $label,
'options' => $options,
'url' => $this->url,
'encodeLabel' => false,
]) . "<br />\n";
} | php | protected function renderButton($dropdown) {
$dropdownId = $dropdown->getId();
$label = $this->label;
if ($this->encodeLabel) {
$label = Html::encode($label);
}
if ($this->split) {
$this->tagName = 'a';
Html::addCssClass($this->options, 'button');
Html::addCssClass($this->options, 'split');
$options = $this->options;
$label .= Html::tag('span', '', ['data-dropdown' => $dropdownId]);
} else {
Html::addCssClass($this->options, 'dropdown');
$options = $this->options;
$options['data-dropdown'] = $dropdownId;
}
return Button::widget([
'tagName' => $this->tagName,
'label' => $label,
'options' => $options,
'url' => $this->url,
'encodeLabel' => false,
]) . "<br />\n";
} | [
"protected",
"function",
"renderButton",
"(",
"$",
"dropdown",
")",
"{",
"$",
"dropdownId",
"=",
"$",
"dropdown",
"->",
"getId",
"(",
")",
";",
"$",
"label",
"=",
"$",
"this",
"->",
"label",
";",
"if",
"(",
"$",
"this",
"->",
"encodeLabel",
")",
"{",
"$",
"label",
"=",
"Html",
"::",
"encode",
"(",
"$",
"label",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"split",
")",
"{",
"$",
"this",
"->",
"tagName",
"=",
"'a'",
";",
"Html",
"::",
"addCssClass",
"(",
"$",
"this",
"->",
"options",
",",
"'button'",
")",
";",
"Html",
"::",
"addCssClass",
"(",
"$",
"this",
"->",
"options",
",",
"'split'",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"options",
";",
"$",
"label",
".=",
"Html",
"::",
"tag",
"(",
"'span'",
",",
"''",
",",
"[",
"'data-dropdown'",
"=>",
"$",
"dropdownId",
"]",
")",
";",
"}",
"else",
"{",
"Html",
"::",
"addCssClass",
"(",
"$",
"this",
"->",
"options",
",",
"'dropdown'",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"options",
";",
"$",
"options",
"[",
"'data-dropdown'",
"]",
"=",
"$",
"dropdownId",
";",
"}",
"return",
"Button",
"::",
"widget",
"(",
"[",
"'tagName'",
"=>",
"$",
"this",
"->",
"tagName",
",",
"'label'",
"=>",
"$",
"label",
",",
"'options'",
"=>",
"$",
"options",
",",
"'url'",
"=>",
"$",
"this",
"->",
"url",
",",
"'encodeLabel'",
"=>",
"false",
",",
"]",
")",
".",
"\"<br />\\n\"",
";",
"}"
] | Generates the button dropdown.
@return string the rendering result. | [
"Generates",
"the",
"button",
"dropdown",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/DropdownButton.php#L72-L99 |
nonzod/yii2-foundation | DropdownButton.php | DropdownButton.getDropdownConfig | protected function getDropdownConfig() {
$config = $this->dropdown;
$config['id'] = ArrayHelper::getValue($config, 'id', null);
$config['clientOptions'] = false;
$config['view'] = $this->getView();
return $config;
} | php | protected function getDropdownConfig() {
$config = $this->dropdown;
$config['id'] = ArrayHelper::getValue($config, 'id', null);
$config['clientOptions'] = false;
$config['view'] = $this->getView();
return $config;
} | [
"protected",
"function",
"getDropdownConfig",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"dropdown",
";",
"$",
"config",
"[",
"'id'",
"]",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"config",
",",
"'id'",
",",
"null",
")",
";",
"$",
"config",
"[",
"'clientOptions'",
"]",
"=",
"false",
";",
"$",
"config",
"[",
"'view'",
"]",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Get config for [[Dropdown]] widget
@return array config options | [
"Get",
"config",
"for",
"[[",
"Dropdown",
"]]",
"widget"
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/DropdownButton.php#L105-L112 |
alevilar/ristorantino-vendor | Risto/Console/Command/RistoSchemaShell.php | RistoSchemaShell._update | protected function _update(&$Schema, $table = null) {
$db = ConnectionManager::getDataSource($this->Schema->connection);
$this->out(__d('cake_console', 'Comparing Database to Schema...'));
$options = array();
$this->params['force'] = false;
if (isset($this->params['force'])) {
$options['models'] = false;
}
$Old = $this->Schema->read($options);
$compare = $this->Schema->compare($Old, $Schema);
$contents = array();
if (!empty($compare['media'])) {
unset($compare['media']);
}
if (empty($table)) {
foreach ($compare as $table => $changes) {
if (isset($compare[$table]['create'])) {
$contents[$table] = $db->createSchema($Schema, $table);
} else {
$contents[$table] = $db->alterSchema(array($table => $compare[$table]), $table);
}
}
} elseif (isset($compare[$table])) {
if (isset($compare[$table]['create'])) {
$contents[$table] = $db->createSchema($Schema, $table);
} else {
$contents[$table] = $db->alterSchema(array($table => $compare[$table]), $table);
}
}
if (empty($contents)) {
$this->out(__d('cake_console', 'Schema is up to date.'));
return false;
}
$this->out("\n" . __d('cake_console', 'The following statements will run.'));
$this->out(array_map('trim', $contents));
if (!empty($this->params['yes']) ||
$this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n') === 'y'
) {
$this->out();
$this->out(__d('cake_console', 'Updating Database...'));
$this->_run($contents, 'update', $Schema);
}
$this->out(__d('cake_console', 'End update.'));
} | php | protected function _update(&$Schema, $table = null) {
$db = ConnectionManager::getDataSource($this->Schema->connection);
$this->out(__d('cake_console', 'Comparing Database to Schema...'));
$options = array();
$this->params['force'] = false;
if (isset($this->params['force'])) {
$options['models'] = false;
}
$Old = $this->Schema->read($options);
$compare = $this->Schema->compare($Old, $Schema);
$contents = array();
if (!empty($compare['media'])) {
unset($compare['media']);
}
if (empty($table)) {
foreach ($compare as $table => $changes) {
if (isset($compare[$table]['create'])) {
$contents[$table] = $db->createSchema($Schema, $table);
} else {
$contents[$table] = $db->alterSchema(array($table => $compare[$table]), $table);
}
}
} elseif (isset($compare[$table])) {
if (isset($compare[$table]['create'])) {
$contents[$table] = $db->createSchema($Schema, $table);
} else {
$contents[$table] = $db->alterSchema(array($table => $compare[$table]), $table);
}
}
if (empty($contents)) {
$this->out(__d('cake_console', 'Schema is up to date.'));
return false;
}
$this->out("\n" . __d('cake_console', 'The following statements will run.'));
$this->out(array_map('trim', $contents));
if (!empty($this->params['yes']) ||
$this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n') === 'y'
) {
$this->out();
$this->out(__d('cake_console', 'Updating Database...'));
$this->_run($contents, 'update', $Schema);
}
$this->out(__d('cake_console', 'End update.'));
} | [
"protected",
"function",
"_update",
"(",
"&",
"$",
"Schema",
",",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"db",
"=",
"ConnectionManager",
"::",
"getDataSource",
"(",
"$",
"this",
"->",
"Schema",
"->",
"connection",
")",
";",
"$",
"this",
"->",
"out",
"(",
"__d",
"(",
"'cake_console'",
",",
"'Comparing Database to Schema...'",
")",
")",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"params",
"[",
"'force'",
"]",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'force'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'models'",
"]",
"=",
"false",
";",
"}",
"$",
"Old",
"=",
"$",
"this",
"->",
"Schema",
"->",
"read",
"(",
"$",
"options",
")",
";",
"$",
"compare",
"=",
"$",
"this",
"->",
"Schema",
"->",
"compare",
"(",
"$",
"Old",
",",
"$",
"Schema",
")",
";",
"$",
"contents",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"compare",
"[",
"'media'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"compare",
"[",
"'media'",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"table",
")",
")",
"{",
"foreach",
"(",
"$",
"compare",
"as",
"$",
"table",
"=>",
"$",
"changes",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"compare",
"[",
"$",
"table",
"]",
"[",
"'create'",
"]",
")",
")",
"{",
"$",
"contents",
"[",
"$",
"table",
"]",
"=",
"$",
"db",
"->",
"createSchema",
"(",
"$",
"Schema",
",",
"$",
"table",
")",
";",
"}",
"else",
"{",
"$",
"contents",
"[",
"$",
"table",
"]",
"=",
"$",
"db",
"->",
"alterSchema",
"(",
"array",
"(",
"$",
"table",
"=>",
"$",
"compare",
"[",
"$",
"table",
"]",
")",
",",
"$",
"table",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"compare",
"[",
"$",
"table",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"compare",
"[",
"$",
"table",
"]",
"[",
"'create'",
"]",
")",
")",
"{",
"$",
"contents",
"[",
"$",
"table",
"]",
"=",
"$",
"db",
"->",
"createSchema",
"(",
"$",
"Schema",
",",
"$",
"table",
")",
";",
"}",
"else",
"{",
"$",
"contents",
"[",
"$",
"table",
"]",
"=",
"$",
"db",
"->",
"alterSchema",
"(",
"array",
"(",
"$",
"table",
"=>",
"$",
"compare",
"[",
"$",
"table",
"]",
")",
",",
"$",
"table",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"contents",
")",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"__d",
"(",
"'cake_console'",
",",
"'Schema is up to date.'",
")",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"\"\\n\"",
".",
"__d",
"(",
"'cake_console'",
",",
"'The following statements will run.'",
")",
")",
";",
"$",
"this",
"->",
"out",
"(",
"array_map",
"(",
"'trim'",
",",
"$",
"contents",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"params",
"[",
"'yes'",
"]",
")",
"||",
"$",
"this",
"->",
"in",
"(",
"__d",
"(",
"'cake_console'",
",",
"'Are you sure you want to alter the tables?'",
")",
",",
"array",
"(",
"'y'",
",",
"'n'",
")",
",",
"'n'",
")",
"===",
"'y'",
")",
"{",
"$",
"this",
"->",
"out",
"(",
")",
";",
"$",
"this",
"->",
"out",
"(",
"__d",
"(",
"'cake_console'",
",",
"'Updating Database...'",
")",
")",
";",
"$",
"this",
"->",
"_run",
"(",
"$",
"contents",
",",
"'update'",
",",
"$",
"Schema",
")",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"__d",
"(",
"'cake_console'",
",",
"'End update.'",
")",
")",
";",
"}"
] | Update database with Schema object
Should be called via the run method
@param CakeSchema &$Schema The schema instance
@param string $table The table name.
@return void | [
"Update",
"database",
"with",
"Schema",
"object",
"Should",
"be",
"called",
"via",
"the",
"run",
"method"
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Console/Command/RistoSchemaShell.php#L26-L74 |
mithun12000/yii2-process | src/components/ProcessControlTrait.php | ProcessControlTrait.createPidfile | public function createPidfile($appName, $path='/var/run'){
if(!$this->control){
$this->createControl();
}
return new Pidfile($this->control, strtolower($appName), $path);
} | php | public function createPidfile($appName, $path='/var/run'){
if(!$this->control){
$this->createControl();
}
return new Pidfile($this->control, strtolower($appName), $path);
} | [
"public",
"function",
"createPidfile",
"(",
"$",
"appName",
",",
"$",
"path",
"=",
"'/var/run'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"control",
")",
"{",
"$",
"this",
"->",
"createControl",
"(",
")",
";",
"}",
"return",
"new",
"Pidfile",
"(",
"$",
"this",
"->",
"control",
",",
"strtolower",
"(",
"$",
"appName",
")",
",",
"$",
"path",
")",
";",
"}"
] | Create Pid file for process
@param string $appName
@param string $path | [
"Create",
"Pid",
"file",
"for",
"process"
] | train | https://github.com/mithun12000/yii2-process/blob/d4c660010381fee76159eb4c92d4b75e38442d3c/src/components/ProcessControlTrait.php#L47-L52 |
mothership-ec/composer | src/Composer/DependencyResolver/DefaultPolicy.php | DefaultPolicy.replaces | protected function replaces(PackageInterface $source, PackageInterface $target)
{
foreach ($source->getReplaces() as $link) {
if ($link->getTarget() === $target->getName()
// && (null === $link->getConstraint() ||
// $link->getConstraint()->matches(new VersionConstraint('==', $target->getVersion())))) {
) {
return true;
}
}
return false;
} | php | protected function replaces(PackageInterface $source, PackageInterface $target)
{
foreach ($source->getReplaces() as $link) {
if ($link->getTarget() === $target->getName()
// && (null === $link->getConstraint() ||
// $link->getConstraint()->matches(new VersionConstraint('==', $target->getVersion())))) {
) {
return true;
}
}
return false;
} | [
"protected",
"function",
"replaces",
"(",
"PackageInterface",
"$",
"source",
",",
"PackageInterface",
"$",
"target",
")",
"{",
"foreach",
"(",
"$",
"source",
"->",
"getReplaces",
"(",
")",
"as",
"$",
"link",
")",
"{",
"if",
"(",
"$",
"link",
"->",
"getTarget",
"(",
")",
"===",
"$",
"target",
"->",
"getName",
"(",
")",
"// && (null === $link->getConstraint() ||",
"// $link->getConstraint()->matches(new VersionConstraint('==', $target->getVersion())))) {",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if source replaces a package with the same name as target.
Replace constraints are ignored. This method should only be used for
prioritisation, not for actual constraint verification.
@param PackageInterface $source
@param PackageInterface $target
@return bool | [
"Checks",
"if",
"source",
"replaces",
"a",
"package",
"with",
"the",
"same",
"name",
"as",
"target",
"."
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/DependencyResolver/DefaultPolicy.php#L192-L204 |
Humanized/yii2-location | controllers/CountryController.php | CountryController.actionIndex | public function actionIndex()
{
$model = new Country();
if ($model->load(\Yii::$app->request->post()) && $model->save()) {
$model = new Country(); //reset model
}
$searchModel = new CountrySearch();
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model' => $model,
]);
} | php | public function actionIndex()
{
$model = new Country();
if ($model->load(\Yii::$app->request->post()) && $model->save()) {
$model = new Country(); //reset model
}
$searchModel = new CountrySearch();
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model' => $model,
]);
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"Country",
"(",
")",
";",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"$",
"model",
"=",
"new",
"Country",
"(",
")",
";",
"//reset model",
"}",
"$",
"searchModel",
"=",
"new",
"CountrySearch",
"(",
")",
";",
"$",
"dataProvider",
"=",
"$",
"searchModel",
"->",
"search",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"queryParams",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'index'",
",",
"[",
"'searchModel'",
"=>",
"$",
"searchModel",
",",
"'dataProvider'",
"=>",
"$",
"dataProvider",
",",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}"
] | Lists all Country models.
@return mixed | [
"Lists",
"all",
"Country",
"models",
"."
] | train | https://github.com/Humanized/yii2-location/blob/48ac12ceab741fc4c82ac8e979415a11bf9175f2/controllers/CountryController.php#L35-L50 |
ekuiter/feature-php | FeaturePhp/File/RefinedFile.php | RefinedFile.getContent | public function getContent() {
$composer = fphp\Collaboration\Composer::fromKind($this->roles[0]->getKind());
foreach ($this->roles as $role)
$composer = $composer->refine($role);
return $composer->getContent();
} | php | public function getContent() {
$composer = fphp\Collaboration\Composer::fromKind($this->roles[0]->getKind());
foreach ($this->roles as $role)
$composer = $composer->refine($role);
return $composer->getContent();
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"$",
"composer",
"=",
"fphp",
"\\",
"Collaboration",
"\\",
"Composer",
"::",
"fromKind",
"(",
"$",
"this",
"->",
"roles",
"[",
"0",
"]",
"->",
"getKind",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"roles",
"as",
"$",
"role",
")",
"$",
"composer",
"=",
"$",
"composer",
"->",
"refine",
"(",
"$",
"role",
")",
";",
"return",
"$",
"composer",
"->",
"getContent",
"(",
")",
";",
"}"
] | Returns the refined file's content.
It is generated using an appropriate composition mechanism (see {@see \FeaturePhp\Collaboration\Composer}).
@return FileContent | [
"Returns",
"the",
"refined",
"file",
"s",
"content",
".",
"It",
"is",
"generated",
"using",
"an",
"appropriate",
"composition",
"mechanism",
"(",
"see",
"{"
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/RefinedFile.php#L37-L42 |
inhere/php-librarys | src/Traits/StdObjectTrait.php | StdObjectTrait.className | final public static function className(string $fullName = null): string
{
$fullName = $fullName ?: self::fullName();
$fullName = str_replace('\\', '/', $fullName);
return basename($fullName);
} | php | final public static function className(string $fullName = null): string
{
$fullName = $fullName ?: self::fullName();
$fullName = str_replace('\\', '/', $fullName);
return basename($fullName);
} | [
"final",
"public",
"static",
"function",
"className",
"(",
"string",
"$",
"fullName",
"=",
"null",
")",
":",
"string",
"{",
"$",
"fullName",
"=",
"$",
"fullName",
"?",
":",
"self",
"::",
"fullName",
"(",
")",
";",
"$",
"fullName",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"fullName",
")",
";",
"return",
"basename",
"(",
"$",
"fullName",
")",
";",
"}"
] | get called class name
@param null|string $fullName
@return string | [
"get",
"called",
"class",
"name"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/StdObjectTrait.php#L47-L53 |
colorium/web | src/Colorium/Web/Logic.php | Logic.override | public function override(array $specs)
{
unset($specs['param'], $specs['return'], $specs['throws']);
foreach($specs as $key => $value) {
$this->$key = $value;
}
return $this;
} | php | public function override(array $specs)
{
unset($specs['param'], $specs['return'], $specs['throws']);
foreach($specs as $key => $value) {
$this->$key = $value;
}
return $this;
} | [
"public",
"function",
"override",
"(",
"array",
"$",
"specs",
")",
"{",
"unset",
"(",
"$",
"specs",
"[",
"'param'",
"]",
",",
"$",
"specs",
"[",
"'return'",
"]",
",",
"$",
"specs",
"[",
"'throws'",
"]",
")",
";",
"foreach",
"(",
"$",
"specs",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Override data
@param array $specs
@return $this | [
"Override",
"data"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Logic.php#L48-L56 |
colorium/web | src/Colorium/Web/Logic.php | Logic.resolve | public static function resolve($name, $callable)
{
$invokable = Resolver::of($callable);
$annotations = $invokable->annotations();
$annotations['method'] = $invokable;
return new Logic($name, $annotations);
} | php | public static function resolve($name, $callable)
{
$invokable = Resolver::of($callable);
$annotations = $invokable->annotations();
$annotations['method'] = $invokable;
return new Logic($name, $annotations);
} | [
"public",
"static",
"function",
"resolve",
"(",
"$",
"name",
",",
"$",
"callable",
")",
"{",
"$",
"invokable",
"=",
"Resolver",
"::",
"of",
"(",
"$",
"callable",
")",
";",
"$",
"annotations",
"=",
"$",
"invokable",
"->",
"annotations",
"(",
")",
";",
"$",
"annotations",
"[",
"'method'",
"]",
"=",
"$",
"invokable",
";",
"return",
"new",
"Logic",
"(",
"$",
"name",
",",
"$",
"annotations",
")",
";",
"}"
] | Resolve logic from callable
@param string $name
@param $callable
@return Logic | [
"Resolve",
"logic",
"from",
"callable"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Logic.php#L66-L73 |
php-lug/lug | src/Component/Grid/Column/Type/DateTimeType.php | DateTimeType.render | public function render($data, array $options)
{
$dateTime = $this->getValue($data, $options);
if ($dateTime === null) {
return;
}
if (!$dateTime instanceof \DateTimeInterface) {
throw new InvalidTypeException(sprintf(
'The "%s" %s column type expects a "\DateTimeInterface" value, got "%s".',
$options['column']->getName(),
$this->getName(),
is_object($dateTime) ? get_class($dateTime) : gettype($dateTime)
));
}
return $this->formatter->format($dateTime, $options);
} | php | public function render($data, array $options)
{
$dateTime = $this->getValue($data, $options);
if ($dateTime === null) {
return;
}
if (!$dateTime instanceof \DateTimeInterface) {
throw new InvalidTypeException(sprintf(
'The "%s" %s column type expects a "\DateTimeInterface" value, got "%s".',
$options['column']->getName(),
$this->getName(),
is_object($dateTime) ? get_class($dateTime) : gettype($dateTime)
));
}
return $this->formatter->format($dateTime, $options);
} | [
"public",
"function",
"render",
"(",
"$",
"data",
",",
"array",
"$",
"options",
")",
"{",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"getValue",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"dateTime",
"===",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"dateTime",
"instanceof",
"\\",
"DateTimeInterface",
")",
"{",
"throw",
"new",
"InvalidTypeException",
"(",
"sprintf",
"(",
"'The \"%s\" %s column type expects a \"\\DateTimeInterface\" value, got \"%s\".'",
",",
"$",
"options",
"[",
"'column'",
"]",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"is_object",
"(",
"$",
"dateTime",
")",
"?",
"get_class",
"(",
"$",
"dateTime",
")",
":",
"gettype",
"(",
"$",
"dateTime",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatter",
"->",
"format",
"(",
"$",
"dateTime",
",",
"$",
"options",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/DateTimeType.php#L93-L111 |
php-lug/lug | src/Component/Grid/Column/Type/DateTimeType.php | DateTimeType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver
->setDefaults([
'calendar' => $this->calendar,
'date_format' => $this->dateFormat,
'lenient' => $this->lenient,
'pattern' => $this->pattern,
'timezone' => $this->timezone,
'time_format' => $this->timeFormat,
])
->setAllowedTypes('calendar', ['IntlCalendar', 'integer', 'null'])
->setAllowedTypes('lenient', 'boolean')
->setAllowedTypes('pattern', ['string', 'null'])
->setAllowedTypes('timezone', ['IntlTimeZone', 'DateTimeZone', 'string', 'null'])
->setAllowedValues('date_format', $formats = [
\IntlDateFormatter::NONE,
\IntlDateFormatter::SHORT,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::LONG,
\IntlDateFormatter::FULL,
])
->setAllowedValues('time_format', $formats);
} | php | public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver
->setDefaults([
'calendar' => $this->calendar,
'date_format' => $this->dateFormat,
'lenient' => $this->lenient,
'pattern' => $this->pattern,
'timezone' => $this->timezone,
'time_format' => $this->timeFormat,
])
->setAllowedTypes('calendar', ['IntlCalendar', 'integer', 'null'])
->setAllowedTypes('lenient', 'boolean')
->setAllowedTypes('pattern', ['string', 'null'])
->setAllowedTypes('timezone', ['IntlTimeZone', 'DateTimeZone', 'string', 'null'])
->setAllowedValues('date_format', $formats = [
\IntlDateFormatter::NONE,
\IntlDateFormatter::SHORT,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::LONG,
\IntlDateFormatter::FULL,
])
->setAllowedValues('time_format', $formats);
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"parent",
"::",
"configureOptions",
"(",
"$",
"resolver",
")",
";",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"'calendar'",
"=>",
"$",
"this",
"->",
"calendar",
",",
"'date_format'",
"=>",
"$",
"this",
"->",
"dateFormat",
",",
"'lenient'",
"=>",
"$",
"this",
"->",
"lenient",
",",
"'pattern'",
"=>",
"$",
"this",
"->",
"pattern",
",",
"'timezone'",
"=>",
"$",
"this",
"->",
"timezone",
",",
"'time_format'",
"=>",
"$",
"this",
"->",
"timeFormat",
",",
"]",
")",
"->",
"setAllowedTypes",
"(",
"'calendar'",
",",
"[",
"'IntlCalendar'",
",",
"'integer'",
",",
"'null'",
"]",
")",
"->",
"setAllowedTypes",
"(",
"'lenient'",
",",
"'boolean'",
")",
"->",
"setAllowedTypes",
"(",
"'pattern'",
",",
"[",
"'string'",
",",
"'null'",
"]",
")",
"->",
"setAllowedTypes",
"(",
"'timezone'",
",",
"[",
"'IntlTimeZone'",
",",
"'DateTimeZone'",
",",
"'string'",
",",
"'null'",
"]",
")",
"->",
"setAllowedValues",
"(",
"'date_format'",
",",
"$",
"formats",
"=",
"[",
"\\",
"IntlDateFormatter",
"::",
"NONE",
",",
"\\",
"IntlDateFormatter",
"::",
"SHORT",
",",
"\\",
"IntlDateFormatter",
"::",
"MEDIUM",
",",
"\\",
"IntlDateFormatter",
"::",
"LONG",
",",
"\\",
"IntlDateFormatter",
"::",
"FULL",
",",
"]",
")",
"->",
"setAllowedValues",
"(",
"'time_format'",
",",
"$",
"formats",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/DateTimeType.php#L116-L141 |
FriendsOfApi/phraseapp | src/Model/Translation/Locale.php | Locale.createFromArray | public static function createFromArray(array $data)
{
$self = new self();
if (isset($data['id'])) {
$self->setId($data['id']);
}
if (isset($data['name'])) {
$self->setName($data['name']);
}
if (isset($data['code'])) {
$self->setCode($data['code']);
}
return $self;
} | php | public static function createFromArray(array $data)
{
$self = new self();
if (isset($data['id'])) {
$self->setId($data['id']);
}
if (isset($data['name'])) {
$self->setName($data['name']);
}
if (isset($data['code'])) {
$self->setCode($data['code']);
}
return $self;
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setId",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setName",
"(",
"$",
"data",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'code'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setCode",
"(",
"$",
"data",
"[",
"'code'",
"]",
")",
";",
"}",
"return",
"$",
"self",
";",
"}"
] | @param array $data
@return Locale | [
"@param",
"array",
"$data"
] | train | https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Model/Translation/Locale.php#L39-L54 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php | ezcQueryExpressionOracle.bitXor | public function bitXor( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "( {$value1} + {$value2} - bitand( {$value1}, {$value2} ) * 2 )";
} | php | public function bitXor( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "( {$value1} + {$value2} - bitand( {$value1}, {$value2} ) * 2 )";
} | [
"public",
"function",
"bitXor",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"( {$value1} + {$value2} - bitand( {$value1}, {$value2} ) * 2 )\"",
";",
"}"
] | Returns the SQL that performs the bitwise XOR on two values.
@param string $value1
@param string $value2
@return string | [
"Returns",
"the",
"SQL",
"that",
"performs",
"the",
"bitwise",
"XOR",
"on",
"two",
"values",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php#L141-L146 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php | ezcQueryExpressionOracle.unixTimestamp | public function unixTimestamp( $column )
{
$column = $this->getIdentifier( $column );
if ( $column != 'NOW()' )
{
$column = "CAST( {$column} AS TIMESTAMP )";
// // alternative
// if ( preg_match( '/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $column ) ) {
// $column = "TO_TIMESTAMP( {$column}, 'YYYY-MM-DD HH24:MI:SS' )";
// }
}
$date1 = "CAST( SYS_EXTRACT_UTC( {$column} ) AS DATE )";
$date2 = "TO_DATE( '19700101000000', 'YYYYMMDDHH24MISS' )";
return " ROUND( ( {$date1} - {$date2} ) / ( 1 / 86400 ) ) ";
} | php | public function unixTimestamp( $column )
{
$column = $this->getIdentifier( $column );
if ( $column != 'NOW()' )
{
$column = "CAST( {$column} AS TIMESTAMP )";
// // alternative
// if ( preg_match( '/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $column ) ) {
// $column = "TO_TIMESTAMP( {$column}, 'YYYY-MM-DD HH24:MI:SS' )";
// }
}
$date1 = "CAST( SYS_EXTRACT_UTC( {$column} ) AS DATE )";
$date2 = "TO_DATE( '19700101000000', 'YYYYMMDDHH24MISS' )";
return " ROUND( ( {$date1} - {$date2} ) / ( 1 / 86400 ) ) ";
} | [
"public",
"function",
"unixTimestamp",
"(",
"$",
"column",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"column",
")",
";",
"if",
"(",
"$",
"column",
"!=",
"'NOW()'",
")",
"{",
"$",
"column",
"=",
"\"CAST( {$column} AS TIMESTAMP )\"",
";",
"// // alternative",
"// if ( preg_match( '/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $column ) ) {",
"// $column = \"TO_TIMESTAMP( {$column}, 'YYYY-MM-DD HH24:MI:SS' )\";",
"// }",
"}",
"$",
"date1",
"=",
"\"CAST( SYS_EXTRACT_UTC( {$column} ) AS DATE )\"",
";",
"$",
"date2",
"=",
"\"TO_DATE( '19700101000000', 'YYYYMMDDHH24MISS' )\"",
";",
"return",
"\" ROUND( ( {$date1} - {$date2} ) / ( 1 / 86400 ) ) \"",
";",
"}"
] | Returns the SQL that converts a timestamp value to a unix timestamp.
@param string $column
@return string | [
"Returns",
"the",
"SQL",
"that",
"converts",
"a",
"timestamp",
"value",
"to",
"a",
"unix",
"timestamp",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php#L154-L170 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php | ezcQueryExpressionOracle.dateSub | public function dateSub( $column, $expr, $type )
{
$type = $this->intervalMap[$type];
$column = $this->getIdentifier( $column );
if ( $column != 'NOW()' )
{
$column = "CAST( {$column} AS TIMESTAMP )";
}
return " {$column} - INTERVAL '{$expr}' {$type} ";
} | php | public function dateSub( $column, $expr, $type )
{
$type = $this->intervalMap[$type];
$column = $this->getIdentifier( $column );
if ( $column != 'NOW()' )
{
$column = "CAST( {$column} AS TIMESTAMP )";
}
return " {$column} - INTERVAL '{$expr}' {$type} ";
} | [
"public",
"function",
"dateSub",
"(",
"$",
"column",
",",
"$",
"expr",
",",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"intervalMap",
"[",
"$",
"type",
"]",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"column",
")",
";",
"if",
"(",
"$",
"column",
"!=",
"'NOW()'",
")",
"{",
"$",
"column",
"=",
"\"CAST( {$column} AS TIMESTAMP )\"",
";",
"}",
"return",
"\" {$column} - INTERVAL '{$expr}' {$type} \"",
";",
"}"
] | Returns the SQL that subtracts an interval from a timestamp value.
@param string $column
@param numeric $expr
@param string $type one of SECOND, MINUTE, HOUR, DAY, MONTH, or YEAR
@return string | [
"Returns",
"the",
"SQL",
"that",
"subtracts",
"an",
"interval",
"from",
"a",
"timestamp",
"value",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php#L180-L191 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php | ezcQueryExpressionOracle.dateAdd | public function dateAdd( $column, $expr, $type )
{
$type = $this->intervalMap[$type];
$column = $this->getIdentifier( $column );
if ( $column != 'NOW()' )
{
$column = "CAST( {$column} AS TIMESTAMP )";
}
return " {$column} + INTERVAL '{$expr}' {$type} ";
} | php | public function dateAdd( $column, $expr, $type )
{
$type = $this->intervalMap[$type];
$column = $this->getIdentifier( $column );
if ( $column != 'NOW()' )
{
$column = "CAST( {$column} AS TIMESTAMP )";
}
return " {$column} + INTERVAL '{$expr}' {$type} ";
} | [
"public",
"function",
"dateAdd",
"(",
"$",
"column",
",",
"$",
"expr",
",",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"intervalMap",
"[",
"$",
"type",
"]",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"column",
")",
";",
"if",
"(",
"$",
"column",
"!=",
"'NOW()'",
")",
"{",
"$",
"column",
"=",
"\"CAST( {$column} AS TIMESTAMP )\"",
";",
"}",
"return",
"\" {$column} + INTERVAL '{$expr}' {$type} \"",
";",
"}"
] | Returns the SQL that adds an interval to a timestamp value.
@param string $column
@param numeric $expr
@param string $type one of SECOND, MINUTE, HOUR, DAY, MONTH, or YEAR
@return string | [
"Returns",
"the",
"SQL",
"that",
"adds",
"an",
"interval",
"to",
"a",
"timestamp",
"value",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php#L201-L212 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php | ezcQueryExpressionOracle.in | public function in( $column )
{
$args = func_get_args();
if ( count( $args ) < 2 )
{
throw new ezcQueryVariableParameterException( 'in', count( $args ), 2 );
}
if ( is_array( $args[1] ) && count( $args[1] ) == 0 )
{
throw new ezcQueryInvalidParameterException( 'in', 2, 'empty array', 'non-empty array' );
}
$values = ezcQuerySelect::arrayFlatten( array_slice( $args, 1 ) );
$values = $this->getIdentifiers( $values );
$column = $this->getIdentifier( $column );
if ( count( $values ) == 0 )
{
throw new ezcQueryVariableParameterException( 'in', count( $args ), 2 );
}
if ( $this->quoteValues )
{
foreach ( $values as $key => $value )
{
switch ( true )
{
case is_int( $value ):
case is_float( $value ):
case $value instanceof ezcQuerySubSelect:
$values[$key] = (string) $value;
break;
default:
$values[$key] = $this->db->quote( $value );
}
}
}
if ( count( $values ) <= 1000 )
{
return "{$column} IN ( " . join( ', ', $values ) . ' )';
}
else
{
$expression = '( ';
do {
$bunch = array_slice( $values, 0, 1000 );
$values = array_slice( $values, 1000 );
$expression .= "{$column} IN ( " . join( ', ', $bunch ) . ' ) OR ';
} while ( count( $values ) > 1000 );
$expression .= "{$column} IN ( " . join( ', ', $values ) . ' ) )';
return $expression;
}
} | php | public function in( $column )
{
$args = func_get_args();
if ( count( $args ) < 2 )
{
throw new ezcQueryVariableParameterException( 'in', count( $args ), 2 );
}
if ( is_array( $args[1] ) && count( $args[1] ) == 0 )
{
throw new ezcQueryInvalidParameterException( 'in', 2, 'empty array', 'non-empty array' );
}
$values = ezcQuerySelect::arrayFlatten( array_slice( $args, 1 ) );
$values = $this->getIdentifiers( $values );
$column = $this->getIdentifier( $column );
if ( count( $values ) == 0 )
{
throw new ezcQueryVariableParameterException( 'in', count( $args ), 2 );
}
if ( $this->quoteValues )
{
foreach ( $values as $key => $value )
{
switch ( true )
{
case is_int( $value ):
case is_float( $value ):
case $value instanceof ezcQuerySubSelect:
$values[$key] = (string) $value;
break;
default:
$values[$key] = $this->db->quote( $value );
}
}
}
if ( count( $values ) <= 1000 )
{
return "{$column} IN ( " . join( ', ', $values ) . ' )';
}
else
{
$expression = '( ';
do {
$bunch = array_slice( $values, 0, 1000 );
$values = array_slice( $values, 1000 );
$expression .= "{$column} IN ( " . join( ', ', $bunch ) . ' ) OR ';
} while ( count( $values ) > 1000 );
$expression .= "{$column} IN ( " . join( ', ', $values ) . ' ) )';
return $expression;
}
} | [
"public",
"function",
"in",
"(",
"$",
"column",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"<",
"2",
")",
"{",
"throw",
"new",
"ezcQueryVariableParameterException",
"(",
"'in'",
",",
"count",
"(",
"$",
"args",
")",
",",
"2",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"count",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ezcQueryInvalidParameterException",
"(",
"'in'",
",",
"2",
",",
"'empty array'",
",",
"'non-empty array'",
")",
";",
"}",
"$",
"values",
"=",
"ezcQuerySelect",
"::",
"arrayFlatten",
"(",
"array_slice",
"(",
"$",
"args",
",",
"1",
")",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"getIdentifiers",
"(",
"$",
"values",
")",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"column",
")",
";",
"if",
"(",
"count",
"(",
"$",
"values",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ezcQueryVariableParameterException",
"(",
"'in'",
",",
"count",
"(",
"$",
"args",
")",
",",
"2",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"quoteValues",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"is_int",
"(",
"$",
"value",
")",
":",
"case",
"is_float",
"(",
"$",
"value",
")",
":",
"case",
"$",
"value",
"instanceof",
"ezcQuerySubSelect",
":",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"break",
";",
"default",
":",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"values",
")",
"<=",
"1000",
")",
"{",
"return",
"\"{$column} IN ( \"",
".",
"join",
"(",
"', '",
",",
"$",
"values",
")",
".",
"' )'",
";",
"}",
"else",
"{",
"$",
"expression",
"=",
"'( '",
";",
"do",
"{",
"$",
"bunch",
"=",
"array_slice",
"(",
"$",
"values",
",",
"0",
",",
"1000",
")",
";",
"$",
"values",
"=",
"array_slice",
"(",
"$",
"values",
",",
"1000",
")",
";",
"$",
"expression",
".=",
"\"{$column} IN ( \"",
".",
"join",
"(",
"', '",
",",
"$",
"bunch",
")",
".",
"' ) OR '",
";",
"}",
"while",
"(",
"count",
"(",
"$",
"values",
")",
">",
"1000",
")",
";",
"$",
"expression",
".=",
"\"{$column} IN ( \"",
".",
"join",
"(",
"', '",
",",
"$",
"values",
")",
".",
"' ) )'",
";",
"return",
"$",
"expression",
";",
"}",
"}"
] | Returns the SQL to check if a value is one in a set of
given values.
in() accepts an arbitrary number of parameters. The first parameter
must always specify the value that should be matched against. Successive
parameters must contain a logical expression or an array with logical
expressions. These expressions will be matched against the first
parameter.
Example:
<code>
$q->select( '*' )->from( 'table' )
->where( $q->expr->in( 'id', 1, 2, 3 ) );
</code>
Oracle limits the number of values in a single IN() to 1000. This
implementation creates a list of combined IN() expressions to bypass
this limitation.
@throws ezcQueryVariableParameterException if called with less than two
parameters.
@throws ezcQueryInvalidParameterException if the 2nd parameter is an
empty array.
@param string|array(string) values that will be matched against $column
@return string logical expression | [
"Returns",
"the",
"SQL",
"to",
"check",
"if",
"a",
"value",
"is",
"one",
"in",
"a",
"set",
"of",
"given",
"values",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_oracle.php#L268-L326 |
nonzod/yii2-foundation | Dropdown.php | Dropdown.init | public function init() {
parent::init();
Html::addCssClass($this->options, 'f-dropdown');
$this->options['data-dropdown-content'] = 1;
$this->options['tabindex'] = '-1';
$this->_containerOptions = $this->options;
} | php | public function init() {
parent::init();
Html::addCssClass($this->options, 'f-dropdown');
$this->options['data-dropdown-content'] = 1;
$this->options['tabindex'] = '-1';
$this->_containerOptions = $this->options;
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"Html",
"::",
"addCssClass",
"(",
"$",
"this",
"->",
"options",
",",
"'f-dropdown'",
")",
";",
"$",
"this",
"->",
"options",
"[",
"'data-dropdown-content'",
"]",
"=",
"1",
";",
"$",
"this",
"->",
"options",
"[",
"'tabindex'",
"]",
"=",
"'-1'",
";",
"$",
"this",
"->",
"_containerOptions",
"=",
"$",
"this",
"->",
"options",
";",
"}"
] | Initializes the widget.
If you override this method, make sure you call the parent implementation first. | [
"Initializes",
"the",
"widget",
".",
"If",
"you",
"override",
"this",
"method",
"make",
"sure",
"you",
"call",
"the",
"parent",
"implementation",
"first",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/Dropdown.php#L51-L58 |
nonzod/yii2-foundation | Dropdown.php | Dropdown.renderAsItems | protected function renderAsItems($items) {
$lines = [];
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
unset($items[$i]);
continue;
}
if (is_string($item)) {
$lines[] = $item;
continue;
}
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
}
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
$label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$options = ArrayHelper::getValue($item, 'options', []);
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
$content = Html::a($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions);
$lines[] = Html::tag('li', $content, $options);
}
return implode("\n", $lines);
} | php | protected function renderAsItems($items) {
$lines = [];
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
unset($items[$i]);
continue;
}
if (is_string($item)) {
$lines[] = $item;
continue;
}
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
}
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
$label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$options = ArrayHelper::getValue($item, 'options', []);
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
$content = Html::a($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions);
$lines[] = Html::tag('li', $content, $options);
}
return implode("\n", $lines);
} | [
"protected",
"function",
"renderAsItems",
"(",
"$",
"items",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"i",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'visible'",
"]",
")",
"&&",
"!",
"$",
"item",
"[",
"'visible'",
"]",
")",
"{",
"unset",
"(",
"$",
"items",
"[",
"$",
"i",
"]",
")",
";",
"continue",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"item",
")",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"item",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'label'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"The 'label' option is required.\"",
")",
";",
"}",
"$",
"encodeLabel",
"=",
"isset",
"(",
"$",
"item",
"[",
"'encode'",
"]",
")",
"?",
"$",
"item",
"[",
"'encode'",
"]",
":",
"$",
"this",
"->",
"encodeLabels",
";",
"$",
"label",
"=",
"$",
"encodeLabel",
"?",
"Html",
"::",
"encode",
"(",
"$",
"item",
"[",
"'label'",
"]",
")",
":",
"$",
"item",
"[",
"'label'",
"]",
";",
"$",
"options",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'options'",
",",
"[",
"]",
")",
";",
"$",
"linkOptions",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'linkOptions'",
",",
"[",
"]",
")",
";",
"$",
"content",
"=",
"Html",
"::",
"a",
"(",
"$",
"label",
",",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'url'",
",",
"'#'",
")",
",",
"$",
"linkOptions",
")",
";",
"$",
"lines",
"[",
"]",
"=",
"Html",
"::",
"tag",
"(",
"'li'",
",",
"$",
"content",
",",
"$",
"options",
")",
";",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}"
] | Renders menu items.
@param array $items the menu items to be rendered
@return string the rendering result.
@throws InvalidConfigException if the label option is not specified in one of the items. | [
"Renders",
"menu",
"items",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/Dropdown.php#L92-L116 |
HedronDev/hedron | src/Tools/ComposerHelperTrait.php | ComposerHelperTrait.mergeComposerJsonFiles | protected function mergeComposerJsonFiles(string $composer_file, \stdClass $original_composer, \stdClass $new_composer, callable $callback = NULL) {
$new_composer = $this->mergeComposerObjects($original_composer, $new_composer, $callback);
$composer_content = file_get_contents($composer_file);
$replace_composer = json_decode($composer_content);
$changes = $this->calculateRequirementChanges($replace_composer, $new_composer);
if (file_put_contents($composer_file, json_encode($new_composer, JSON_PRETTY_PRINT)) !== FALSE) {
return $changes;
}
} | php | protected function mergeComposerJsonFiles(string $composer_file, \stdClass $original_composer, \stdClass $new_composer, callable $callback = NULL) {
$new_composer = $this->mergeComposerObjects($original_composer, $new_composer, $callback);
$composer_content = file_get_contents($composer_file);
$replace_composer = json_decode($composer_content);
$changes = $this->calculateRequirementChanges($replace_composer, $new_composer);
if (file_put_contents($composer_file, json_encode($new_composer, JSON_PRETTY_PRINT)) !== FALSE) {
return $changes;
}
} | [
"protected",
"function",
"mergeComposerJsonFiles",
"(",
"string",
"$",
"composer_file",
",",
"\\",
"stdClass",
"$",
"original_composer",
",",
"\\",
"stdClass",
"$",
"new_composer",
",",
"callable",
"$",
"callback",
"=",
"NULL",
")",
"{",
"$",
"new_composer",
"=",
"$",
"this",
"->",
"mergeComposerObjects",
"(",
"$",
"original_composer",
",",
"$",
"new_composer",
",",
"$",
"callback",
")",
";",
"$",
"composer_content",
"=",
"file_get_contents",
"(",
"$",
"composer_file",
")",
";",
"$",
"replace_composer",
"=",
"json_decode",
"(",
"$",
"composer_content",
")",
";",
"$",
"changes",
"=",
"$",
"this",
"->",
"calculateRequirementChanges",
"(",
"$",
"replace_composer",
",",
"$",
"new_composer",
")",
";",
"if",
"(",
"file_put_contents",
"(",
"$",
"composer_file",
",",
"json_encode",
"(",
"$",
"new_composer",
",",
"JSON_PRETTY_PRINT",
")",
")",
"!==",
"FALSE",
")",
"{",
"return",
"$",
"changes",
";",
"}",
"}"
] | Merges the original composer file with a new composer file.
This ensures that the composer.json file that is going to be installed
will have all the appropriate requirements documented by the git
repository that is kept up to date by the client.
@param string $composer_file
The absolute path to the composer file to write.
@param \stdClass $original_composer
The original composer.json file before it was removed as a php object.
@param \stdClass $new_composer
The new composer.json file as a php object.
@param callable $callback
A callback if necessary to customize the composer object further.
@return array | [
"Merges",
"the",
"original",
"composer",
"file",
"with",
"a",
"new",
"composer",
"file",
"."
] | train | https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Tools/ComposerHelperTrait.php#L27-L35 |
HedronDev/hedron | src/Tools/ComposerHelperTrait.php | ComposerHelperTrait.mergeComposerObjects | protected function mergeComposerObjects(\stdClass $original_composer, \stdClass $new_composer, callable $callback = NULL) {
foreach ($original_composer as $key => $values) {
$is_array = is_array($values);
$values = (array) $values;
if (isset($new_composer->{$key})) {
$value = (array) $new_composer->{$key};
$values = array_merge($value, $values);
}
$new_composer->{$key} = $is_array ? $values : (object) $values;
}
if ($callback) {
call_user_func($callback, $new_composer);
}
return $new_composer;
} | php | protected function mergeComposerObjects(\stdClass $original_composer, \stdClass $new_composer, callable $callback = NULL) {
foreach ($original_composer as $key => $values) {
$is_array = is_array($values);
$values = (array) $values;
if (isset($new_composer->{$key})) {
$value = (array) $new_composer->{$key};
$values = array_merge($value, $values);
}
$new_composer->{$key} = $is_array ? $values : (object) $values;
}
if ($callback) {
call_user_func($callback, $new_composer);
}
return $new_composer;
} | [
"protected",
"function",
"mergeComposerObjects",
"(",
"\\",
"stdClass",
"$",
"original_composer",
",",
"\\",
"stdClass",
"$",
"new_composer",
",",
"callable",
"$",
"callback",
"=",
"NULL",
")",
"{",
"foreach",
"(",
"$",
"original_composer",
"as",
"$",
"key",
"=>",
"$",
"values",
")",
"{",
"$",
"is_array",
"=",
"is_array",
"(",
"$",
"values",
")",
";",
"$",
"values",
"=",
"(",
"array",
")",
"$",
"values",
";",
"if",
"(",
"isset",
"(",
"$",
"new_composer",
"->",
"{",
"$",
"key",
"}",
")",
")",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"new_composer",
"->",
"{",
"$",
"key",
"}",
";",
"$",
"values",
"=",
"array_merge",
"(",
"$",
"value",
",",
"$",
"values",
")",
";",
"}",
"$",
"new_composer",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"is_array",
"?",
"$",
"values",
":",
"(",
"object",
")",
"$",
"values",
";",
"}",
"if",
"(",
"$",
"callback",
")",
"{",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"new_composer",
")",
";",
"}",
"return",
"$",
"new_composer",
";",
"}"
] | Merges two composer objects into one.
@param \stdClass $original_composer
The original composer.json file before it was removed as a php object.
@param \stdClass $new_composer
The new composer file to generate.
@param callable $callback
A callback if necessary to customize the composer object further.
@return \stdClass
An object representing the merged composer json files. | [
"Merges",
"two",
"composer",
"objects",
"into",
"one",
"."
] | train | https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Tools/ComposerHelperTrait.php#L50-L64 |
HedronDev/hedron | src/Tools/ComposerHelperTrait.php | ComposerHelperTrait.calculateRequirementChanges | protected function calculateRequirementChanges($replace_composer, $new_composer) {
$changes = [
'install' => [],
'update' => [],
'remove' => [],
];
foreach (['require', 'require-dev'] as $key) {
$old_requirements = !empty($replace_composer->{$key}) ? $replace_composer->{$key} : [];
$new_requirements = !empty($new_composer->{$key}) ? $new_composer->{$key} : [];
foreach ($new_requirements as $requirement => $version) {
if (empty($old_requirements->{$requirement})) {
$changes['install'][$requirement] = $version;
}
if ((!empty($old_requirements->{$requirement}) && Comparator::greaterThan($version, $old_requirements->{$requirement}))) {
$changes['update'][$requirement] = $version;
}
}
foreach ($old_requirements as $requirement => $version) {
if (empty($new_requirements->{$requirement})) {
$changes['remove'][] = $requirement;
}
}
}
return $changes;
} | php | protected function calculateRequirementChanges($replace_composer, $new_composer) {
$changes = [
'install' => [],
'update' => [],
'remove' => [],
];
foreach (['require', 'require-dev'] as $key) {
$old_requirements = !empty($replace_composer->{$key}) ? $replace_composer->{$key} : [];
$new_requirements = !empty($new_composer->{$key}) ? $new_composer->{$key} : [];
foreach ($new_requirements as $requirement => $version) {
if (empty($old_requirements->{$requirement})) {
$changes['install'][$requirement] = $version;
}
if ((!empty($old_requirements->{$requirement}) && Comparator::greaterThan($version, $old_requirements->{$requirement}))) {
$changes['update'][$requirement] = $version;
}
}
foreach ($old_requirements as $requirement => $version) {
if (empty($new_requirements->{$requirement})) {
$changes['remove'][] = $requirement;
}
}
}
return $changes;
} | [
"protected",
"function",
"calculateRequirementChanges",
"(",
"$",
"replace_composer",
",",
"$",
"new_composer",
")",
"{",
"$",
"changes",
"=",
"[",
"'install'",
"=>",
"[",
"]",
",",
"'update'",
"=>",
"[",
"]",
",",
"'remove'",
"=>",
"[",
"]",
",",
"]",
";",
"foreach",
"(",
"[",
"'require'",
",",
"'require-dev'",
"]",
"as",
"$",
"key",
")",
"{",
"$",
"old_requirements",
"=",
"!",
"empty",
"(",
"$",
"replace_composer",
"->",
"{",
"$",
"key",
"}",
")",
"?",
"$",
"replace_composer",
"->",
"{",
"$",
"key",
"}",
":",
"[",
"]",
";",
"$",
"new_requirements",
"=",
"!",
"empty",
"(",
"$",
"new_composer",
"->",
"{",
"$",
"key",
"}",
")",
"?",
"$",
"new_composer",
"->",
"{",
"$",
"key",
"}",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"new_requirements",
"as",
"$",
"requirement",
"=>",
"$",
"version",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"old_requirements",
"->",
"{",
"$",
"requirement",
"}",
")",
")",
"{",
"$",
"changes",
"[",
"'install'",
"]",
"[",
"$",
"requirement",
"]",
"=",
"$",
"version",
";",
"}",
"if",
"(",
"(",
"!",
"empty",
"(",
"$",
"old_requirements",
"->",
"{",
"$",
"requirement",
"}",
")",
"&&",
"Comparator",
"::",
"greaterThan",
"(",
"$",
"version",
",",
"$",
"old_requirements",
"->",
"{",
"$",
"requirement",
"}",
")",
")",
")",
"{",
"$",
"changes",
"[",
"'update'",
"]",
"[",
"$",
"requirement",
"]",
"=",
"$",
"version",
";",
"}",
"}",
"foreach",
"(",
"$",
"old_requirements",
"as",
"$",
"requirement",
"=>",
"$",
"version",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"new_requirements",
"->",
"{",
"$",
"requirement",
"}",
")",
")",
"{",
"$",
"changes",
"[",
"'remove'",
"]",
"[",
"]",
"=",
"$",
"requirement",
";",
"}",
"}",
"}",
"return",
"$",
"changes",
";",
"}"
] | Calculated requirements that need to be removed from the system.
@param $replace_composer
Composer object about to be replaced.
@param $new_composer
Composer object doing the replacing.
@return array
An array of requirements to install, update or remove. | [
"Calculated",
"requirements",
"that",
"need",
"to",
"be",
"removed",
"from",
"the",
"system",
"."
] | train | https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Tools/ComposerHelperTrait.php#L77-L101 |
php-lug/lug | src/Component/Translation/Model/TranslatableTrait.php | TranslatableTrait.getTranslation | public function getTranslation($allowCreate = false)
{
$locales = $this->getLocales();
if (empty($locales)) {
throw new LocaleNotFoundException();
}
$translation = null;
foreach ($locales as $locale) {
if (($translation = $this->translations->get($locale)) !== null) {
break;
}
}
if ($translation === null && $allowCreate) {
$translation = $this->getTranslationFactory()->create(['locale' => reset($locales)]);
$this->addTranslation($translation);
}
if ($translation === null && $this->hasFallbackLocale()) {
$translation = $this->translations->get($this->getFallbackLocale());
}
if ($translation === null) {
if ($this->hasFallbackLocale()) {
$locales[] = $this->getFallbackLocale();
}
throw new TranslationNotFoundException();
}
return $translation;
} | php | public function getTranslation($allowCreate = false)
{
$locales = $this->getLocales();
if (empty($locales)) {
throw new LocaleNotFoundException();
}
$translation = null;
foreach ($locales as $locale) {
if (($translation = $this->translations->get($locale)) !== null) {
break;
}
}
if ($translation === null && $allowCreate) {
$translation = $this->getTranslationFactory()->create(['locale' => reset($locales)]);
$this->addTranslation($translation);
}
if ($translation === null && $this->hasFallbackLocale()) {
$translation = $this->translations->get($this->getFallbackLocale());
}
if ($translation === null) {
if ($this->hasFallbackLocale()) {
$locales[] = $this->getFallbackLocale();
}
throw new TranslationNotFoundException();
}
return $translation;
} | [
"public",
"function",
"getTranslation",
"(",
"$",
"allowCreate",
"=",
"false",
")",
"{",
"$",
"locales",
"=",
"$",
"this",
"->",
"getLocales",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"locales",
")",
")",
"{",
"throw",
"new",
"LocaleNotFoundException",
"(",
")",
";",
"}",
"$",
"translation",
"=",
"null",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",
"if",
"(",
"(",
"$",
"translation",
"=",
"$",
"this",
"->",
"translations",
"->",
"get",
"(",
"$",
"locale",
")",
")",
"!==",
"null",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"translation",
"===",
"null",
"&&",
"$",
"allowCreate",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"getTranslationFactory",
"(",
")",
"->",
"create",
"(",
"[",
"'locale'",
"=>",
"reset",
"(",
"$",
"locales",
")",
"]",
")",
";",
"$",
"this",
"->",
"addTranslation",
"(",
"$",
"translation",
")",
";",
"}",
"if",
"(",
"$",
"translation",
"===",
"null",
"&&",
"$",
"this",
"->",
"hasFallbackLocale",
"(",
")",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"translations",
"->",
"get",
"(",
"$",
"this",
"->",
"getFallbackLocale",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"translation",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasFallbackLocale",
"(",
")",
")",
"{",
"$",
"locales",
"[",
"]",
"=",
"$",
"this",
"->",
"getFallbackLocale",
"(",
")",
";",
"}",
"throw",
"new",
"TranslationNotFoundException",
"(",
")",
";",
"}",
"return",
"$",
"translation",
";",
"}"
] | @param bool $allowCreate
@return TranslationInterface | [
"@param",
"bool",
"$allowCreate"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Translation/Model/TranslatableTrait.php#L125-L159 |
gdbots/iam-php | src/ListAllRolesRequestHandler.php | ListAllRolesRequestHandler.handle | protected function handle(ListAllRolesRequest $request, Pbjx $pbjx): ListAllRolesResponse
{
$roles = [];
$this->ncr->pipeNodeRefs(RoleV1Mixin::findOne()->getQName(), function (NodeRef $nodeRef) use (&$roles) {
$roles[] = $nodeRef;
}, $this->createNcrContext($request));
return $this->createListAllRolesResponse($request, $pbjx)->addToSet('roles', $roles);
} | php | protected function handle(ListAllRolesRequest $request, Pbjx $pbjx): ListAllRolesResponse
{
$roles = [];
$this->ncr->pipeNodeRefs(RoleV1Mixin::findOne()->getQName(), function (NodeRef $nodeRef) use (&$roles) {
$roles[] = $nodeRef;
}, $this->createNcrContext($request));
return $this->createListAllRolesResponse($request, $pbjx)->addToSet('roles', $roles);
} | [
"protected",
"function",
"handle",
"(",
"ListAllRolesRequest",
"$",
"request",
",",
"Pbjx",
"$",
"pbjx",
")",
":",
"ListAllRolesResponse",
"{",
"$",
"roles",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"ncr",
"->",
"pipeNodeRefs",
"(",
"RoleV1Mixin",
"::",
"findOne",
"(",
")",
"->",
"getQName",
"(",
")",
",",
"function",
"(",
"NodeRef",
"$",
"nodeRef",
")",
"use",
"(",
"&",
"$",
"roles",
")",
"{",
"$",
"roles",
"[",
"]",
"=",
"$",
"nodeRef",
";",
"}",
",",
"$",
"this",
"->",
"createNcrContext",
"(",
"$",
"request",
")",
")",
";",
"return",
"$",
"this",
"->",
"createListAllRolesResponse",
"(",
"$",
"request",
",",
"$",
"pbjx",
")",
"->",
"addToSet",
"(",
"'roles'",
",",
"$",
"roles",
")",
";",
"}"
] | @param ListAllRolesRequest $request
@param Pbjx $pbjx
@return ListAllRolesResponse | [
"@param",
"ListAllRolesRequest",
"$request",
"@param",
"Pbjx",
"$pbjx"
] | train | https://github.com/gdbots/iam-php/blob/3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3/src/ListAllRolesRequestHandler.php#L34-L42 |
gdbots/iam-php | src/ListAllRolesRequestHandler.php | ListAllRolesRequestHandler.createListAllRolesResponse | protected function createListAllRolesResponse(ListAllRolesRequest $request, Pbjx $pbjx): ListAllRolesResponse
{
/** @var ListAllRolesResponse $response */
$response = $this->createResponseFromRequest($request, $pbjx);
return $response;
} | php | protected function createListAllRolesResponse(ListAllRolesRequest $request, Pbjx $pbjx): ListAllRolesResponse
{
/** @var ListAllRolesResponse $response */
$response = $this->createResponseFromRequest($request, $pbjx);
return $response;
} | [
"protected",
"function",
"createListAllRolesResponse",
"(",
"ListAllRolesRequest",
"$",
"request",
",",
"Pbjx",
"$",
"pbjx",
")",
":",
"ListAllRolesResponse",
"{",
"/** @var ListAllRolesResponse $response */",
"$",
"response",
"=",
"$",
"this",
"->",
"createResponseFromRequest",
"(",
"$",
"request",
",",
"$",
"pbjx",
")",
";",
"return",
"$",
"response",
";",
"}"
] | @param ListAllRolesRequest $request
@param Pbjx $pbjx
@return ListAllRolesResponse | [
"@param",
"ListAllRolesRequest",
"$request",
"@param",
"Pbjx",
"$pbjx"
] | train | https://github.com/gdbots/iam-php/blob/3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3/src/ListAllRolesRequestHandler.php#L50-L55 |
odiaseo/pagebuilder | src/PageBuilder/Model/TemplateModel.php | TemplateModel.updateTemplateSections | public function updateTemplateSections($id, $sections)
{
/** @var $entity \PageBuilder\Entity\Template */
if ($entity = $this->findObject($id)) {
/** @var $ts \PageBuilder\Entity\Join\TemplateSection */
foreach ($entity->getTemplateSections() as $ts) {
$ts->setIsActive(0);
}
if ($ts = $entity->getTemplateSections()) {
$entity->getTemplateSections()->clear();
} else {
$entity->setTemplateSections(new ArrayCollection());
}
}
foreach ($sections as $key => $v) {
$order = $key;
if ($entry = $this->getEntityManager()->getRepository('PageBuilder\Entity\Join\TemplateSection')
->findOneBy(['templateId' => $id, 'sectionId' => $v])
) {
$entry->setSortOrder($order);
$entry->setIsActive(1);
} elseif ($section = $this->getEntityManager()->getRepository('PageBuilder\Entity\Section')->find($v)
) {
$entry = new TemplateSection();
$entry->setSectionId($section);
$entry->setTemplateId($entity);
$entry->setSortOrder($order);
$entry->setIsActive(1);
}
$entity->getTemplateSections()->add($entry);
}
return $this->save($entity);
} | php | public function updateTemplateSections($id, $sections)
{
/** @var $entity \PageBuilder\Entity\Template */
if ($entity = $this->findObject($id)) {
/** @var $ts \PageBuilder\Entity\Join\TemplateSection */
foreach ($entity->getTemplateSections() as $ts) {
$ts->setIsActive(0);
}
if ($ts = $entity->getTemplateSections()) {
$entity->getTemplateSections()->clear();
} else {
$entity->setTemplateSections(new ArrayCollection());
}
}
foreach ($sections as $key => $v) {
$order = $key;
if ($entry = $this->getEntityManager()->getRepository('PageBuilder\Entity\Join\TemplateSection')
->findOneBy(['templateId' => $id, 'sectionId' => $v])
) {
$entry->setSortOrder($order);
$entry->setIsActive(1);
} elseif ($section = $this->getEntityManager()->getRepository('PageBuilder\Entity\Section')->find($v)
) {
$entry = new TemplateSection();
$entry->setSectionId($section);
$entry->setTemplateId($entity);
$entry->setSortOrder($order);
$entry->setIsActive(1);
}
$entity->getTemplateSections()->add($entry);
}
return $this->save($entity);
} | [
"public",
"function",
"updateTemplateSections",
"(",
"$",
"id",
",",
"$",
"sections",
")",
"{",
"/** @var $entity \\PageBuilder\\Entity\\Template */",
"if",
"(",
"$",
"entity",
"=",
"$",
"this",
"->",
"findObject",
"(",
"$",
"id",
")",
")",
"{",
"/** @var $ts \\PageBuilder\\Entity\\Join\\TemplateSection */",
"foreach",
"(",
"$",
"entity",
"->",
"getTemplateSections",
"(",
")",
"as",
"$",
"ts",
")",
"{",
"$",
"ts",
"->",
"setIsActive",
"(",
"0",
")",
";",
"}",
"if",
"(",
"$",
"ts",
"=",
"$",
"entity",
"->",
"getTemplateSections",
"(",
")",
")",
"{",
"$",
"entity",
"->",
"getTemplateSections",
"(",
")",
"->",
"clear",
"(",
")",
";",
"}",
"else",
"{",
"$",
"entity",
"->",
"setTemplateSections",
"(",
"new",
"ArrayCollection",
"(",
")",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"key",
"=>",
"$",
"v",
")",
"{",
"$",
"order",
"=",
"$",
"key",
";",
"if",
"(",
"$",
"entry",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getRepository",
"(",
"'PageBuilder\\Entity\\Join\\TemplateSection'",
")",
"->",
"findOneBy",
"(",
"[",
"'templateId'",
"=>",
"$",
"id",
",",
"'sectionId'",
"=>",
"$",
"v",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setSortOrder",
"(",
"$",
"order",
")",
";",
"$",
"entry",
"->",
"setIsActive",
"(",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"section",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getRepository",
"(",
"'PageBuilder\\Entity\\Section'",
")",
"->",
"find",
"(",
"$",
"v",
")",
")",
"{",
"$",
"entry",
"=",
"new",
"TemplateSection",
"(",
")",
";",
"$",
"entry",
"->",
"setSectionId",
"(",
"$",
"section",
")",
";",
"$",
"entry",
"->",
"setTemplateId",
"(",
"$",
"entity",
")",
";",
"$",
"entry",
"->",
"setSortOrder",
"(",
"$",
"order",
")",
";",
"$",
"entry",
"->",
"setIsActive",
"(",
"1",
")",
";",
"}",
"$",
"entity",
"->",
"getTemplateSections",
"(",
")",
"->",
"add",
"(",
"$",
"entry",
")",
";",
"}",
"return",
"$",
"this",
"->",
"save",
"(",
"$",
"entity",
")",
";",
"}"
] | @param $id
@param $sections
@return mixed | [
"@param",
"$id",
"@param",
"$sections"
] | train | https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/Model/TemplateModel.php#L33-L68 |
inhere/php-librarys | src/Files/SimpleFinder.php | SimpleFinder.inDir | public function inDir($dirs): self
{
$this->dirs = array_merge($this->dirs, (array)$dirs);
return $this;
} | php | public function inDir($dirs): self
{
$this->dirs = array_merge($this->dirs, (array)$dirs);
return $this;
} | [
"public",
"function",
"inDir",
"(",
"$",
"dirs",
")",
":",
"self",
"{",
"$",
"this",
"->",
"dirs",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dirs",
",",
"(",
"array",
")",
"$",
"dirs",
")",
";",
"return",
"$",
"this",
";",
"}"
] | alias of the `in()`
@param string|array $dirs
@return SimpleFinder | [
"alias",
"of",
"the",
"in",
"()"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Files/SimpleFinder.php#L317-L322 |
tequila/mongodb-odm | src/BulkWriteBuilder.php | BulkWriteBuilder.addWriteModel | public function addWriteModel($writeModel)
{
if (is_array($writeModel) || $writeModel instanceof WriteModelInterface) {
$this->writeModels[] = $writeModel;
return $this;
}
throw new InvalidArgumentException(
sprintf(
'$write model must be an array in format %s or an instance of %s.',
'[$operationType => $arrayOfArguments]',
WriteModelInterface::class
)
);
} | php | public function addWriteModel($writeModel)
{
if (is_array($writeModel) || $writeModel instanceof WriteModelInterface) {
$this->writeModels[] = $writeModel;
return $this;
}
throw new InvalidArgumentException(
sprintf(
'$write model must be an array in format %s or an instance of %s.',
'[$operationType => $arrayOfArguments]',
WriteModelInterface::class
)
);
} | [
"public",
"function",
"addWriteModel",
"(",
"$",
"writeModel",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"writeModel",
")",
"||",
"$",
"writeModel",
"instanceof",
"WriteModelInterface",
")",
"{",
"$",
"this",
"->",
"writeModels",
"[",
"]",
"=",
"$",
"writeModel",
";",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'$write model must be an array in format %s or an instance of %s.'",
",",
"'[$operationType => $arrayOfArguments]'",
",",
"WriteModelInterface",
"::",
"class",
")",
")",
";",
"}"
] | @param array|WriteModelInterface $writeModel
@return $this | [
"@param",
"array|WriteModelInterface",
"$writeModel"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/BulkWriteBuilder.php#L41-L56 |
tequila/mongodb-odm | src/BulkWriteBuilder.php | BulkWriteBuilder.deleteMany | public function deleteMany(array $filter, array $options = [])
{
$this->writeModels[] = [BulkWrite::DELETE_MANY => [$filter, $options]];
return $this;
} | php | public function deleteMany(array $filter, array $options = [])
{
$this->writeModels[] = [BulkWrite::DELETE_MANY => [$filter, $options]];
return $this;
} | [
"public",
"function",
"deleteMany",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"writeModels",
"[",
"]",
"=",
"[",
"BulkWrite",
"::",
"DELETE_MANY",
"=>",
"[",
"$",
"filter",
",",
"$",
"options",
"]",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $filter
@param array $options
@return $this | [
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/BulkWriteBuilder.php#L93-L98 |
tequila/mongodb-odm | src/BulkWriteBuilder.php | BulkWriteBuilder.deleteOne | public function deleteOne(array $filter, array $options = [])
{
$this->writeModels[] = [BulkWrite::DELETE_ONE => [$filter, $options]];
return $this;
} | php | public function deleteOne(array $filter, array $options = [])
{
$this->writeModels[] = [BulkWrite::DELETE_ONE => [$filter, $options]];
return $this;
} | [
"public",
"function",
"deleteOne",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"writeModels",
"[",
"]",
"=",
"[",
"BulkWrite",
"::",
"DELETE_ONE",
"=>",
"[",
"$",
"filter",
",",
"$",
"options",
"]",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $filter
@param array $options
@return $this | [
"@param",
"array",
"$filter",
"@param",
"array",
"$options"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/BulkWriteBuilder.php#L106-L111 |
tequila/mongodb-odm | src/BulkWriteBuilder.php | BulkWriteBuilder.insertMany | public function insertMany(array $documents)
{
foreach ($documents as $document) {
$this->writeModels[] = [BulkWrite::INSERT_ONE => [$document]];
}
return $this;
} | php | public function insertMany(array $documents)
{
foreach ($documents as $document) {
$this->writeModels[] = [BulkWrite::INSERT_ONE => [$document]];
}
return $this;
} | [
"public",
"function",
"insertMany",
"(",
"array",
"$",
"documents",
")",
"{",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"$",
"this",
"->",
"writeModels",
"[",
"]",
"=",
"[",
"BulkWrite",
"::",
"INSERT_ONE",
"=>",
"[",
"$",
"document",
"]",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param array $documents
@return $this | [
"@param",
"array",
"$documents"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/BulkWriteBuilder.php#L118-L125 |
tequila/mongodb-odm | src/BulkWriteBuilder.php | BulkWriteBuilder.updateMany | public function updateMany(array $filter, array $update, array $options = [])
{
$this->writeModels[] = [BulkWrite::UPDATE_MANY => [$filter, $update, $options]];
return $this;
} | php | public function updateMany(array $filter, array $update, array $options = [])
{
$this->writeModels[] = [BulkWrite::UPDATE_MANY => [$filter, $update, $options]];
return $this;
} | [
"public",
"function",
"updateMany",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"update",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"writeModels",
"[",
"]",
"=",
"[",
"BulkWrite",
"::",
"UPDATE_MANY",
"=>",
"[",
"$",
"filter",
",",
"$",
"update",
",",
"$",
"options",
"]",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $filter
@param array $update
@param array $options
@return $this | [
"@param",
"array",
"$filter",
"@param",
"array",
"$update",
"@param",
"array",
"$options"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/BulkWriteBuilder.php#L146-L151 |
tequila/mongodb-odm | src/BulkWriteBuilder.php | BulkWriteBuilder.updateOne | public function updateOne(array $filter, array $update, array $options = [])
{
$this->writeModels[] = [BulkWrite::UPDATE_ONE => [$filter, $update, $options]];
return $this;
} | php | public function updateOne(array $filter, array $update, array $options = [])
{
$this->writeModels[] = [BulkWrite::UPDATE_ONE => [$filter, $update, $options]];
return $this;
} | [
"public",
"function",
"updateOne",
"(",
"array",
"$",
"filter",
",",
"array",
"$",
"update",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"writeModels",
"[",
"]",
"=",
"[",
"BulkWrite",
"::",
"UPDATE_ONE",
"=>",
"[",
"$",
"filter",
",",
"$",
"update",
",",
"$",
"options",
"]",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $filter
@param array $update
@param array $options
@return $this | [
"@param",
"array",
"$filter",
"@param",
"array",
"$update",
"@param",
"array",
"$options"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/BulkWriteBuilder.php#L160-L165 |
tequila/mongodb-odm | src/BulkWriteBuilder.php | BulkWriteBuilder.replaceOne | public function replaceOne(array $filter, $replacement, array $options = [])
{
$this->writeModels[] = [BulkWrite::REPLACE_ONE => [$filter, $replacement, $options]];
return $this;
} | php | public function replaceOne(array $filter, $replacement, array $options = [])
{
$this->writeModels[] = [BulkWrite::REPLACE_ONE => [$filter, $replacement, $options]];
return $this;
} | [
"public",
"function",
"replaceOne",
"(",
"array",
"$",
"filter",
",",
"$",
"replacement",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"writeModels",
"[",
"]",
"=",
"[",
"BulkWrite",
"::",
"REPLACE_ONE",
"=>",
"[",
"$",
"filter",
",",
"$",
"replacement",
",",
"$",
"options",
"]",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $filter
@param array|object $replacement
@param array $options
@return $this | [
"@param",
"array",
"$filter",
"@param",
"array|object",
"$replacement",
"@param",
"array",
"$options"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/BulkWriteBuilder.php#L174-L179 |
oroinc/OroLayoutComponent | Loader/Visitor/SimpleContextValueComparisonConditionVisitor.php | SimpleContextValueComparisonConditionVisitor.startVisit | public function startVisit(VisitContext $visitContext)
{
$visitContext->getUpdateMethodWriter()
->writeln('if (')
->indent()
->write(sprintf('$%s->getContext()', LayoutUpdateGeneratorInterface::PARAM_LAYOUT_ITEM))
->write(sprintf('->getOr(\'%s\')', $this->contextValueName))
->write(sprintf(' %s ', $this->condition))
->writeln(var_export($this->value, true))
->outdent()
->writeln(') {')
->indent();
} | php | public function startVisit(VisitContext $visitContext)
{
$visitContext->getUpdateMethodWriter()
->writeln('if (')
->indent()
->write(sprintf('$%s->getContext()', LayoutUpdateGeneratorInterface::PARAM_LAYOUT_ITEM))
->write(sprintf('->getOr(\'%s\')', $this->contextValueName))
->write(sprintf(' %s ', $this->condition))
->writeln(var_export($this->value, true))
->outdent()
->writeln(') {')
->indent();
} | [
"public",
"function",
"startVisit",
"(",
"VisitContext",
"$",
"visitContext",
")",
"{",
"$",
"visitContext",
"->",
"getUpdateMethodWriter",
"(",
")",
"->",
"writeln",
"(",
"'if ('",
")",
"->",
"indent",
"(",
")",
"->",
"write",
"(",
"sprintf",
"(",
"'$%s->getContext()'",
",",
"LayoutUpdateGeneratorInterface",
"::",
"PARAM_LAYOUT_ITEM",
")",
")",
"->",
"write",
"(",
"sprintf",
"(",
"'->getOr(\\'%s\\')'",
",",
"$",
"this",
"->",
"contextValueName",
")",
")",
"->",
"write",
"(",
"sprintf",
"(",
"' %s '",
",",
"$",
"this",
"->",
"condition",
")",
")",
"->",
"writeln",
"(",
"var_export",
"(",
"$",
"this",
"->",
"value",
",",
"true",
")",
")",
"->",
"outdent",
"(",
")",
"->",
"writeln",
"(",
"') {'",
")",
"->",
"indent",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Loader/Visitor/SimpleContextValueComparisonConditionVisitor.php#L34-L46 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/Roles/Doc.php | Doc.toXhtml | public function toXhtml(\DOMDocument $document, \DOMElement $root)
{
$content = '';
$caption = '';
foreach ($this->node->nodes as $node) {
$content .= $node->token->content;
}
$matches = array();
if (preg_match('/([^<]*)<?([^>]*)>?/', $content, $matches)) {
// if the role uses the `caption<content>` notation; extract the two parts
if (isset($matches[2]) && $matches[2]) {
$content = $matches[2];
$caption = trim($matches[1]);
}
}
// check the table of contents for a caption.
if (!$caption && $this->visitor) {
$toc = $this->visitor->getTableOfContents();
$caption = isset($toc[$content]) ? $toc[$content]->getName() : '';
}
// if no caption is captured; create one.
if (!$caption) {
$caption = str_replace(
array('-', '_'),
' ',
ucfirst(ltrim(substr(htmlspecialchars($content), strrpos($content, '/')), '\\/'))
);
}
$link = $document->createElement('a', $caption);
$root->appendChild($link);
$link->setAttribute('href', str_replace('\\', '/', $content) . '.html');
} | php | public function toXhtml(\DOMDocument $document, \DOMElement $root)
{
$content = '';
$caption = '';
foreach ($this->node->nodes as $node) {
$content .= $node->token->content;
}
$matches = array();
if (preg_match('/([^<]*)<?([^>]*)>?/', $content, $matches)) {
// if the role uses the `caption<content>` notation; extract the two parts
if (isset($matches[2]) && $matches[2]) {
$content = $matches[2];
$caption = trim($matches[1]);
}
}
// check the table of contents for a caption.
if (!$caption && $this->visitor) {
$toc = $this->visitor->getTableOfContents();
$caption = isset($toc[$content]) ? $toc[$content]->getName() : '';
}
// if no caption is captured; create one.
if (!$caption) {
$caption = str_replace(
array('-', '_'),
' ',
ucfirst(ltrim(substr(htmlspecialchars($content), strrpos($content, '/')), '\\/'))
);
}
$link = $document->createElement('a', $caption);
$root->appendChild($link);
$link->setAttribute('href', str_replace('\\', '/', $content) . '.html');
} | [
"public",
"function",
"toXhtml",
"(",
"\\",
"DOMDocument",
"$",
"document",
",",
"\\",
"DOMElement",
"$",
"root",
")",
"{",
"$",
"content",
"=",
"''",
";",
"$",
"caption",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"node",
"->",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"content",
".=",
"$",
"node",
"->",
"token",
"->",
"content",
";",
"}",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/([^<]*)<?([^>]*)>?/'",
",",
"$",
"content",
",",
"$",
"matches",
")",
")",
"{",
"// if the role uses the `caption<content>` notation; extract the two parts",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"&&",
"$",
"matches",
"[",
"2",
"]",
")",
"{",
"$",
"content",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"caption",
"=",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"}",
"// check the table of contents for a caption.",
"if",
"(",
"!",
"$",
"caption",
"&&",
"$",
"this",
"->",
"visitor",
")",
"{",
"$",
"toc",
"=",
"$",
"this",
"->",
"visitor",
"->",
"getTableOfContents",
"(",
")",
";",
"$",
"caption",
"=",
"isset",
"(",
"$",
"toc",
"[",
"$",
"content",
"]",
")",
"?",
"$",
"toc",
"[",
"$",
"content",
"]",
"->",
"getName",
"(",
")",
":",
"''",
";",
"}",
"// if no caption is captured; create one.",
"if",
"(",
"!",
"$",
"caption",
")",
"{",
"$",
"caption",
"=",
"str_replace",
"(",
"array",
"(",
"'-'",
",",
"'_'",
")",
",",
"' '",
",",
"ucfirst",
"(",
"ltrim",
"(",
"substr",
"(",
"htmlspecialchars",
"(",
"$",
"content",
")",
",",
"strrpos",
"(",
"$",
"content",
",",
"'/'",
")",
")",
",",
"'\\\\/'",
")",
")",
")",
";",
"}",
"$",
"link",
"=",
"$",
"document",
"->",
"createElement",
"(",
"'a'",
",",
"$",
"caption",
")",
";",
"$",
"root",
"->",
"appendChild",
"(",
"$",
"link",
")",
";",
"$",
"link",
"->",
"setAttribute",
"(",
"'href'",
",",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"content",
")",
".",
"'.html'",
")",
";",
"}"
] | Transform text role to HTML.
Create a XHTML structure at the text roles position in the document.
@param \DOMDocument $document
@param \DOMElement $root
@return void | [
"Transform",
"text",
"role",
"to",
"HTML",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/Roles/Doc.php#L47-L83 |
kecik-framework/kecik | Kecik/Route.php | Route.init | public static function init() {
if ( php_sapi_name() == 'cli' ) {
self::$BasePath = str_replace( '/', DIRECTORY_SEPARATOR, dirname( __FILE__ ) . '/' );
} else {
self::$BasePath = str_replace( '/', DIRECTORY_SEPARATOR, realpath( dirname( __FILE__ ) ) . "/" );
}
if ( isset( $_SERVER['HTTPS'] ) ||
( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] == 443 ) ||
( isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) && $_SERVER['HTTP_X_FORWARDED_PORT'] == 443 )
) {
self::$protocol = "https://";
} else {
self::$protocol = "http://";
}
$PathInfo = pathinfo( $_SERVER['PHP_SELF'] );
$index = basename( $_SERVER["SCRIPT_FILENAME"], '.php' ) . '.php';
Config::set( 'index', $index );
if ( strpos( $PathInfo['dirname'], '/' . $index ) > 0 ) {
$StrLimit = strpos( $PathInfo['dirname'], '/' . $index );
} elseif ( $PathInfo['dirname'] == '/' . $index ) {
$StrLimit = 0;
} else {
$StrLimit = strlen( $PathInfo['dirname'] );
}
if ( php_sapi_name() == 'cli-server' ) {
self::$BaseUrl = self::$protocol . $_SERVER['HTTP_HOST'] . '/';
} else if ( php_sapi_name() == 'cli' ) {
self::$params = $_SERVER['argv'];
chdir( self::$BasePath );
self::$BaseUrl = self::$BasePath;
} else {
/**
* ID: Terkadang terdapat masalah bagian base url, kamu dapat mengedit bagian ini. Biasanya masalah pada
* $PathInfo['dirname']
* EN: Sometimes have a problem in base url section, you can editi this section. normally at
* $PathInfo['dirname']
*/
self::$BaseUrl = self::$protocol . $_SERVER['HTTP_HOST'] . substr( $PathInfo['dirname'], 0, $StrLimit );
if ( substr( self::$BaseUrl, - 1, 1 ) != '/' ) {
self::$BaseUrl .= '/';
}
}
if ( php_sapi_name() == 'cli' ) {
$ResultSegment = $_SERVER['argv'];
array_shift( $ResultSegment );
self::$params = $ResultSegment;
self::$RealParams = self::$params;
self::$ParamsStr = implode( '/', $ResultSegment );
} else {
$path = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
if (substr($path, 0, 1) == '/' && strlen($path) > 1) {
$path = substr($path, 1);
}
$segments = explode( '/', $path );
if ( $segments[ count( $segments ) - 1 ] == '' && count( $segments ) > 1 ) {
unset( $segments[ count( $segments ) - 1 ] );
}
$ResultSegment = array();
while ( list( $key, $seg ) = each( $segments ) ) {
if ( $segments[ $key ] != $index && $seg != '' ) {
array_push( $ResultSegment, urldecode( $seg ) );
}
}
self::$ParamsStr = implode( '/', $ResultSegment );
self::$params = $ResultSegment;
self::$RealParams = self::$params;
}
unset( $StrLimit );
unset( $PathInfo );
} | php | public static function init() {
if ( php_sapi_name() == 'cli' ) {
self::$BasePath = str_replace( '/', DIRECTORY_SEPARATOR, dirname( __FILE__ ) . '/' );
} else {
self::$BasePath = str_replace( '/', DIRECTORY_SEPARATOR, realpath( dirname( __FILE__ ) ) . "/" );
}
if ( isset( $_SERVER['HTTPS'] ) ||
( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] == 443 ) ||
( isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) && $_SERVER['HTTP_X_FORWARDED_PORT'] == 443 )
) {
self::$protocol = "https://";
} else {
self::$protocol = "http://";
}
$PathInfo = pathinfo( $_SERVER['PHP_SELF'] );
$index = basename( $_SERVER["SCRIPT_FILENAME"], '.php' ) . '.php';
Config::set( 'index', $index );
if ( strpos( $PathInfo['dirname'], '/' . $index ) > 0 ) {
$StrLimit = strpos( $PathInfo['dirname'], '/' . $index );
} elseif ( $PathInfo['dirname'] == '/' . $index ) {
$StrLimit = 0;
} else {
$StrLimit = strlen( $PathInfo['dirname'] );
}
if ( php_sapi_name() == 'cli-server' ) {
self::$BaseUrl = self::$protocol . $_SERVER['HTTP_HOST'] . '/';
} else if ( php_sapi_name() == 'cli' ) {
self::$params = $_SERVER['argv'];
chdir( self::$BasePath );
self::$BaseUrl = self::$BasePath;
} else {
/**
* ID: Terkadang terdapat masalah bagian base url, kamu dapat mengedit bagian ini. Biasanya masalah pada
* $PathInfo['dirname']
* EN: Sometimes have a problem in base url section, you can editi this section. normally at
* $PathInfo['dirname']
*/
self::$BaseUrl = self::$protocol . $_SERVER['HTTP_HOST'] . substr( $PathInfo['dirname'], 0, $StrLimit );
if ( substr( self::$BaseUrl, - 1, 1 ) != '/' ) {
self::$BaseUrl .= '/';
}
}
if ( php_sapi_name() == 'cli' ) {
$ResultSegment = $_SERVER['argv'];
array_shift( $ResultSegment );
self::$params = $ResultSegment;
self::$RealParams = self::$params;
self::$ParamsStr = implode( '/', $ResultSegment );
} else {
$path = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
if (substr($path, 0, 1) == '/' && strlen($path) > 1) {
$path = substr($path, 1);
}
$segments = explode( '/', $path );
if ( $segments[ count( $segments ) - 1 ] == '' && count( $segments ) > 1 ) {
unset( $segments[ count( $segments ) - 1 ] );
}
$ResultSegment = array();
while ( list( $key, $seg ) = each( $segments ) ) {
if ( $segments[ $key ] != $index && $seg != '' ) {
array_push( $ResultSegment, urldecode( $seg ) );
}
}
self::$ParamsStr = implode( '/', $ResultSegment );
self::$params = $ResultSegment;
self::$RealParams = self::$params;
}
unset( $StrLimit );
unset( $PathInfo );
} | [
"public",
"static",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"==",
"'cli'",
")",
"{",
"self",
"::",
"$",
"BasePath",
"=",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"dirname",
"(",
"__FILE__",
")",
".",
"'/'",
")",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"BasePath",
"=",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"realpath",
"(",
"dirname",
"(",
"__FILE__",
")",
")",
".",
"\"/\"",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"||",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PORT'",
"]",
")",
"&&",
"$",
"_SERVER",
"[",
"'SERVER_PORT'",
"]",
"==",
"443",
")",
"||",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_PORT'",
"]",
")",
"&&",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_PORT'",
"]",
"==",
"443",
")",
")",
"{",
"self",
"::",
"$",
"protocol",
"=",
"\"https://\"",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"protocol",
"=",
"\"http://\"",
";",
"}",
"$",
"PathInfo",
"=",
"pathinfo",
"(",
"$",
"_SERVER",
"[",
"'PHP_SELF'",
"]",
")",
";",
"$",
"index",
"=",
"basename",
"(",
"$",
"_SERVER",
"[",
"\"SCRIPT_FILENAME\"",
"]",
",",
"'.php'",
")",
".",
"'.php'",
";",
"Config",
"::",
"set",
"(",
"'index'",
",",
"$",
"index",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"PathInfo",
"[",
"'dirname'",
"]",
",",
"'/'",
".",
"$",
"index",
")",
">",
"0",
")",
"{",
"$",
"StrLimit",
"=",
"strpos",
"(",
"$",
"PathInfo",
"[",
"'dirname'",
"]",
",",
"'/'",
".",
"$",
"index",
")",
";",
"}",
"elseif",
"(",
"$",
"PathInfo",
"[",
"'dirname'",
"]",
"==",
"'/'",
".",
"$",
"index",
")",
"{",
"$",
"StrLimit",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"StrLimit",
"=",
"strlen",
"(",
"$",
"PathInfo",
"[",
"'dirname'",
"]",
")",
";",
"}",
"if",
"(",
"php_sapi_name",
"(",
")",
"==",
"'cli-server'",
")",
"{",
"self",
"::",
"$",
"BaseUrl",
"=",
"self",
"::",
"$",
"protocol",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
".",
"'/'",
";",
"}",
"else",
"if",
"(",
"php_sapi_name",
"(",
")",
"==",
"'cli'",
")",
"{",
"self",
"::",
"$",
"params",
"=",
"$",
"_SERVER",
"[",
"'argv'",
"]",
";",
"chdir",
"(",
"self",
"::",
"$",
"BasePath",
")",
";",
"self",
"::",
"$",
"BaseUrl",
"=",
"self",
"::",
"$",
"BasePath",
";",
"}",
"else",
"{",
"/**\n\t\t\t * ID: Terkadang terdapat masalah bagian base url, kamu dapat mengedit bagian ini. Biasanya masalah pada\n\t\t\t * $PathInfo['dirname']\n\t\t\t * EN: Sometimes have a problem in base url section, you can editi this section. normally at\n\t\t\t * $PathInfo['dirname']\n\t\t\t */",
"self",
"::",
"$",
"BaseUrl",
"=",
"self",
"::",
"$",
"protocol",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
".",
"substr",
"(",
"$",
"PathInfo",
"[",
"'dirname'",
"]",
",",
"0",
",",
"$",
"StrLimit",
")",
";",
"if",
"(",
"substr",
"(",
"self",
"::",
"$",
"BaseUrl",
",",
"-",
"1",
",",
"1",
")",
"!=",
"'/'",
")",
"{",
"self",
"::",
"$",
"BaseUrl",
".=",
"'/'",
";",
"}",
"}",
"if",
"(",
"php_sapi_name",
"(",
")",
"==",
"'cli'",
")",
"{",
"$",
"ResultSegment",
"=",
"$",
"_SERVER",
"[",
"'argv'",
"]",
";",
"array_shift",
"(",
"$",
"ResultSegment",
")",
";",
"self",
"::",
"$",
"params",
"=",
"$",
"ResultSegment",
";",
"self",
"::",
"$",
"RealParams",
"=",
"self",
"::",
"$",
"params",
";",
"self",
"::",
"$",
"ParamsStr",
"=",
"implode",
"(",
"'/'",
",",
"$",
"ResultSegment",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"$",
"_SERVER",
"[",
"'SCRIPT_NAME'",
"]",
",",
"''",
",",
"$",
"_SERVER",
"[",
"'PHP_SELF'",
"]",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"1",
")",
"==",
"'/'",
"&&",
"strlen",
"(",
"$",
"path",
")",
">",
"1",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"1",
")",
";",
"}",
"$",
"segments",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"if",
"(",
"$",
"segments",
"[",
"count",
"(",
"$",
"segments",
")",
"-",
"1",
"]",
"==",
"''",
"&&",
"count",
"(",
"$",
"segments",
")",
">",
"1",
")",
"{",
"unset",
"(",
"$",
"segments",
"[",
"count",
"(",
"$",
"segments",
")",
"-",
"1",
"]",
")",
";",
"}",
"$",
"ResultSegment",
"=",
"array",
"(",
")",
";",
"while",
"(",
"list",
"(",
"$",
"key",
",",
"$",
"seg",
")",
"=",
"each",
"(",
"$",
"segments",
")",
")",
"{",
"if",
"(",
"$",
"segments",
"[",
"$",
"key",
"]",
"!=",
"$",
"index",
"&&",
"$",
"seg",
"!=",
"''",
")",
"{",
"array_push",
"(",
"$",
"ResultSegment",
",",
"urldecode",
"(",
"$",
"seg",
")",
")",
";",
"}",
"}",
"self",
"::",
"$",
"ParamsStr",
"=",
"implode",
"(",
"'/'",
",",
"$",
"ResultSegment",
")",
";",
"self",
"::",
"$",
"params",
"=",
"$",
"ResultSegment",
";",
"self",
"::",
"$",
"RealParams",
"=",
"self",
"::",
"$",
"params",
";",
"}",
"unset",
"(",
"$",
"StrLimit",
")",
";",
"unset",
"(",
"$",
"PathInfo",
")",
";",
"}"
] | Initialization Route Class | [
"Initialization",
"Route",
"Class"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L99-L187 |
kecik-framework/kecik | Kecik/Route.php | Route._getParams | public function _getParams( $key = - 1 ) {
if ( $key >= 0 ) {
if ( isset( self::$params[ $key ] ) ) {
return self::$params[ $key ];
} else {
return NULL;
}
} else {
return self::$params;
}
} | php | public function _getParams( $key = - 1 ) {
if ( $key >= 0 ) {
if ( isset( self::$params[ $key ] ) ) {
return self::$params[ $key ];
} else {
return NULL;
}
} else {
return self::$params;
}
} | [
"public",
"function",
"_getParams",
"(",
"$",
"key",
"=",
"-",
"1",
")",
"{",
"if",
"(",
"$",
"key",
">=",
"0",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"params",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"params",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"NULL",
";",
"}",
"}",
"else",
"{",
"return",
"self",
"::",
"$",
"params",
";",
"}",
"}"
] | get Route Paramenters
@param int $key
@return array|null | [
"get",
"Route",
"Paramenters"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L196-L209 |
kecik-framework/kecik | Kecik/Route.php | Route.getParams | public function getParams( $key = - 1 ) {
if ( $key >= 0 ) {
if ( isset( self::$RealParams[ $key ] ) ) {
return self::$RealParams[ $key ];
} else {
return NULL;
}
} else {
return self::$RealParams;
}
} | php | public function getParams( $key = - 1 ) {
if ( $key >= 0 ) {
if ( isset( self::$RealParams[ $key ] ) ) {
return self::$RealParams[ $key ];
} else {
return NULL;
}
} else {
return self::$RealParams;
}
} | [
"public",
"function",
"getParams",
"(",
"$",
"key",
"=",
"-",
"1",
")",
"{",
"if",
"(",
"$",
"key",
">=",
"0",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"RealParams",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"RealParams",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"NULL",
";",
"}",
"}",
"else",
"{",
"return",
"self",
"::",
"$",
"RealParams",
";",
"}",
"}"
] | get Real Route Paramters
@param int $key
@return array|null | [
"get",
"Real",
"Route",
"Paramters",
"@param",
"int",
"$key"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L217-L230 |
kecik-framework/kecik | Kecik/Route.php | Route.setParams | public function setParams( $key, $value = '' ) {
//if (!isset($this->params)) $this->params = array();
if ( is_array( $key ) ) {
self::$RealParams = $key;
} else {
self::$RealParams[ $key ] = $value;
}
} | php | public function setParams( $key, $value = '' ) {
//if (!isset($this->params)) $this->params = array();
if ( is_array( $key ) ) {
self::$RealParams = $key;
} else {
self::$RealParams[ $key ] = $value;
}
} | [
"public",
"function",
"setParams",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"''",
")",
"{",
"//if (!isset($this->params)) $this->params = array();",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"self",
"::",
"$",
"RealParams",
"=",
"$",
"key",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"RealParams",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Set route paramters
@param $key
@param string $value | [
"Set",
"route",
"paramters"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L238-L247 |
kecik-framework/kecik | Kecik/Route.php | Route.is | public function is( $route = '' ) {
if ( $route == '' ) {
return self::$destination;
} else {
if ( self::$destination == $route ) {
return TRUE;
} else {
return FALSE;
}
}
} | php | public function is( $route = '' ) {
if ( $route == '' ) {
return self::$destination;
} else {
if ( self::$destination == $route ) {
return TRUE;
} else {
return FALSE;
}
}
} | [
"public",
"function",
"is",
"(",
"$",
"route",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"route",
"==",
"''",
")",
"{",
"return",
"self",
"::",
"$",
"destination",
";",
"}",
"else",
"{",
"if",
"(",
"self",
"::",
"$",
"destination",
"==",
"$",
"route",
")",
"{",
"return",
"TRUE",
";",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}",
"}"
] | Get or Check current route
@param string $route
@return bool|string | [
"Get",
"or",
"Check",
"current",
"route",
"@param",
"string",
"$route"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L273-L287 |
kecik-framework/kecik | Kecik/Route.php | Route.isPut | public function isPut() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'PUT' || ( isset( $_POST['_METHOD'] ) && $_POST['_METHOD'] == 'PUT' ) ) {
parse_str( file_get_contents( "php://input" ), $vars );
if ( isset( $vars['_METHOD'] ) ) {
unset( $vars['_METHOD'] );
}
$GLOBALS['_PUT'] = $_PUT = $vars;
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} | php | public function isPut() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'PUT' || ( isset( $_POST['_METHOD'] ) && $_POST['_METHOD'] == 'PUT' ) ) {
parse_str( file_get_contents( "php://input" ), $vars );
if ( isset( $vars['_METHOD'] ) ) {
unset( $vars['_METHOD'] );
}
$GLOBALS['_PUT'] = $_PUT = $vars;
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} | [
"public",
"function",
"isPut",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'PUT'",
"||",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'_METHOD'",
"]",
")",
"&&",
"$",
"_POST",
"[",
"'_METHOD'",
"]",
"==",
"'PUT'",
")",
")",
"{",
"parse_str",
"(",
"file_get_contents",
"(",
"\"php://input\"",
")",
",",
"$",
"vars",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"vars",
"[",
"'_METHOD'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"vars",
"[",
"'_METHOD'",
"]",
")",
";",
"}",
"$",
"GLOBALS",
"[",
"'_PUT'",
"]",
"=",
"$",
"_PUT",
"=",
"$",
"vars",
";",
"return",
"TRUE",
";",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}"
] | Check request of Put method
@return bool | [
"Check",
"request",
"of",
"Put",
"method"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L335-L357 |
kecik-framework/kecik | Kecik/Route.php | Route.isDelete | public function isDelete() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'DELETE' || ( isset( $_POST['_METHOD'] ) && $_POST['_METHOD'] == 'DELETE' ) ) {
parse_str( file_get_contents( "php://input" ), $vars );
if ( isset( $vars['_METHOD'] ) ) {
unset( $vars['_METHOD'] );
}
$GLOBALS['_DELETE'] = $_DELETE = $vars;
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} | php | public function isDelete() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'DELETE' || ( isset( $_POST['_METHOD'] ) && $_POST['_METHOD'] == 'DELETE' ) ) {
parse_str( file_get_contents( "php://input" ), $vars );
if ( isset( $vars['_METHOD'] ) ) {
unset( $vars['_METHOD'] );
}
$GLOBALS['_DELETE'] = $_DELETE = $vars;
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} | [
"public",
"function",
"isDelete",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'DELETE'",
"||",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'_METHOD'",
"]",
")",
"&&",
"$",
"_POST",
"[",
"'_METHOD'",
"]",
"==",
"'DELETE'",
")",
")",
"{",
"parse_str",
"(",
"file_get_contents",
"(",
"\"php://input\"",
")",
",",
"$",
"vars",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"vars",
"[",
"'_METHOD'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"vars",
"[",
"'_METHOD'",
"]",
")",
";",
"}",
"$",
"GLOBALS",
"[",
"'_DELETE'",
"]",
"=",
"$",
"_DELETE",
"=",
"$",
"vars",
";",
"return",
"TRUE",
";",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}"
] | Check request of delete method
@return bool | [
"Check",
"request",
"of",
"delete",
"method"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L364-L385 |
kecik-framework/kecik | Kecik/Route.php | Route.isPatch | public function isPatch() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'PATCH' || ( isset( $_POST['_METHOD'] ) && $_POST['_METHOD'] == 'PATCH' ) ) {
parse_str( file_get_contents( "php://input" ), $vars );
if ( isset( $vars['_METHOD'] ) ) {
unset( $vars['_METHOD'] );
}
$GLOBALS['_PATCH'] = $_PATCH = $vars;
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} | php | public function isPatch() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'PATCH' || ( isset( $_POST['_METHOD'] ) && $_POST['_METHOD'] == 'PATCH' ) ) {
parse_str( file_get_contents( "php://input" ), $vars );
if ( isset( $vars['_METHOD'] ) ) {
unset( $vars['_METHOD'] );
}
$GLOBALS['_PATCH'] = $_PATCH = $vars;
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} | [
"public",
"function",
"isPatch",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'PATCH'",
"||",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'_METHOD'",
"]",
")",
"&&",
"$",
"_POST",
"[",
"'_METHOD'",
"]",
"==",
"'PATCH'",
")",
")",
"{",
"parse_str",
"(",
"file_get_contents",
"(",
"\"php://input\"",
")",
",",
"$",
"vars",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"vars",
"[",
"'_METHOD'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"vars",
"[",
"'_METHOD'",
"]",
")",
";",
"}",
"$",
"GLOBALS",
"[",
"'_PATCH'",
"]",
"=",
"$",
"_PATCH",
"=",
"$",
"vars",
";",
"return",
"TRUE",
";",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}"
] | Check request of Patch method
@return bool | [
"Check",
"request",
"of",
"Patch",
"method"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L392-L413 |
kecik-framework/kecik | Kecik/Route.php | Route.isOptions | public function isOptions() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' || ( isset( $_POST['_METHOD'] ) && $_POST['_METHOD'] == 'OPTIONS' ) ) {
parse_str( file_get_contents( "php://input" ), $vars );
if ( isset( $vars['_METHOD'] ) ) {
unset( $vars['_METHOD'] );
}
$GLOBALS['_OPTIONS'] = $_OPTIONS = $vars;
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} | php | public function isOptions() {
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' || ( isset( $_POST['_METHOD'] ) && $_POST['_METHOD'] == 'OPTIONS' ) ) {
parse_str( file_get_contents( "php://input" ), $vars );
if ( isset( $vars['_METHOD'] ) ) {
unset( $vars['_METHOD'] );
}
$GLOBALS['_OPTIONS'] = $_OPTIONS = $vars;
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} | [
"public",
"function",
"isOptions",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'OPTIONS'",
"||",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'_METHOD'",
"]",
")",
"&&",
"$",
"_POST",
"[",
"'_METHOD'",
"]",
"==",
"'OPTIONS'",
")",
")",
"{",
"parse_str",
"(",
"file_get_contents",
"(",
"\"php://input\"",
")",
",",
"$",
"vars",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"vars",
"[",
"'_METHOD'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"vars",
"[",
"'_METHOD'",
"]",
")",
";",
"}",
"$",
"GLOBALS",
"[",
"'_OPTIONS'",
"]",
"=",
"$",
"_OPTIONS",
"=",
"$",
"vars",
";",
"return",
"TRUE",
";",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}"
] | Check request of Options method
@return bool | [
"Check",
"request",
"of",
"Options",
"method"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Route.php#L420-L441 |
GrupaZero/api | src/Gzero/Api/Transformer/BlockTransformer.php | BlockTransformer.transform | public function transform($block)
{
$block = $this->entityToArray(Block::class, $block);
return [
'id' => $this->setNullableValue($block['id']),
'type' => $block['type'],
'region' => $block['region'],
'filter' => $block['filter'],
'options' => $block['options'],
'theme' => $block['theme'],
'weight' => (int) $block['weight'],
'isActive' => (bool) $block['is_active'],
'isCacheable' => (bool) $block['is_cacheable'],
'createdAt' => $block['created_at'],
'updatedAt' => $block['updated_at']
];
} | php | public function transform($block)
{
$block = $this->entityToArray(Block::class, $block);
return [
'id' => $this->setNullableValue($block['id']),
'type' => $block['type'],
'region' => $block['region'],
'filter' => $block['filter'],
'options' => $block['options'],
'theme' => $block['theme'],
'weight' => (int) $block['weight'],
'isActive' => (bool) $block['is_active'],
'isCacheable' => (bool) $block['is_cacheable'],
'createdAt' => $block['created_at'],
'updatedAt' => $block['updated_at']
];
} | [
"public",
"function",
"transform",
"(",
"$",
"block",
")",
"{",
"$",
"block",
"=",
"$",
"this",
"->",
"entityToArray",
"(",
"Block",
"::",
"class",
",",
"$",
"block",
")",
";",
"return",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"setNullableValue",
"(",
"$",
"block",
"[",
"'id'",
"]",
")",
",",
"'type'",
"=>",
"$",
"block",
"[",
"'type'",
"]",
",",
"'region'",
"=>",
"$",
"block",
"[",
"'region'",
"]",
",",
"'filter'",
"=>",
"$",
"block",
"[",
"'filter'",
"]",
",",
"'options'",
"=>",
"$",
"block",
"[",
"'options'",
"]",
",",
"'theme'",
"=>",
"$",
"block",
"[",
"'theme'",
"]",
",",
"'weight'",
"=>",
"(",
"int",
")",
"$",
"block",
"[",
"'weight'",
"]",
",",
"'isActive'",
"=>",
"(",
"bool",
")",
"$",
"block",
"[",
"'is_active'",
"]",
",",
"'isCacheable'",
"=>",
"(",
"bool",
")",
"$",
"block",
"[",
"'is_cacheable'",
"]",
",",
"'createdAt'",
"=>",
"$",
"block",
"[",
"'created_at'",
"]",
",",
"'updatedAt'",
"=>",
"$",
"block",
"[",
"'updated_at'",
"]",
"]",
";",
"}"
] | Transforms block entity
@param Block|array $block Block entity
@return array | [
"Transforms",
"block",
"entity"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/BlockTransformer.php#L45-L61 |
GrupaZero/api | src/Gzero/Api/Transformer/BlockTransformer.php | BlockTransformer.includeTranslations | public function includeTranslations(Block $block)
{
$translations = $block->translations;
return $this->collection($translations, new BlockTranslationTransformer());
} | php | public function includeTranslations(Block $block)
{
$translations = $block->translations;
return $this->collection($translations, new BlockTranslationTransformer());
} | [
"public",
"function",
"includeTranslations",
"(",
"Block",
"$",
"block",
")",
"{",
"$",
"translations",
"=",
"$",
"block",
"->",
"translations",
";",
"return",
"$",
"this",
"->",
"collection",
"(",
"$",
"translations",
",",
"new",
"BlockTranslationTransformer",
"(",
")",
")",
";",
"}"
] | Include Translations
@param Block $block Translation
@return \League\Fractal\ItemResource | [
"Include",
"Translations"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/BlockTransformer.php#L71-L75 |
GrupaZero/api | src/Gzero/Api/Transformer/BlockTransformer.php | BlockTransformer.includeAuthor | public function includeAuthor(Block $block)
{
$author = $block->author;
return (!empty($author)) ? $this->item($author, new UserTransformer()) : null;
} | php | public function includeAuthor(Block $block)
{
$author = $block->author;
return (!empty($author)) ? $this->item($author, new UserTransformer()) : null;
} | [
"public",
"function",
"includeAuthor",
"(",
"Block",
"$",
"block",
")",
"{",
"$",
"author",
"=",
"$",
"block",
"->",
"author",
";",
"return",
"(",
"!",
"empty",
"(",
"$",
"author",
")",
")",
"?",
"$",
"this",
"->",
"item",
"(",
"$",
"author",
",",
"new",
"UserTransformer",
"(",
")",
")",
":",
"null",
";",
"}"
] | Include Author
@param Block $block User
@return \League\Fractal\ItemResource | [
"Include",
"Author"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/BlockTransformer.php#L84-L88 |
GrupaZero/api | src/Gzero/Api/Transformer/BlockTransformer.php | BlockTransformer.includeBlockabale | public function includeBlockabale(Block $block)
{
$blockable = $block->blockable;
if (!empty($blockable)) {
$entityClassName = (new ReflectionClass($blockable))->getShortName();
$transformerClass = 'Gzero\\Api\\Transformer\\' . $entityClassName . 'Transformer';
return $this->item($blockable, new $transformerClass());
}
return null;
} | php | public function includeBlockabale(Block $block)
{
$blockable = $block->blockable;
if (!empty($blockable)) {
$entityClassName = (new ReflectionClass($blockable))->getShortName();
$transformerClass = 'Gzero\\Api\\Transformer\\' . $entityClassName . 'Transformer';
return $this->item($blockable, new $transformerClass());
}
return null;
} | [
"public",
"function",
"includeBlockabale",
"(",
"Block",
"$",
"block",
")",
"{",
"$",
"blockable",
"=",
"$",
"block",
"->",
"blockable",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"blockable",
")",
")",
"{",
"$",
"entityClassName",
"=",
"(",
"new",
"ReflectionClass",
"(",
"$",
"blockable",
")",
")",
"->",
"getShortName",
"(",
")",
";",
"$",
"transformerClass",
"=",
"'Gzero\\\\Api\\\\Transformer\\\\'",
".",
"$",
"entityClassName",
".",
"'Transformer'",
";",
"return",
"$",
"this",
"->",
"item",
"(",
"$",
"blockable",
",",
"new",
"$",
"transformerClass",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Include Author
@param Block $block User
@return \League\Fractal\ItemResource | [
"Include",
"Author"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/BlockTransformer.php#L97-L106 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php | Dwootemplate.add_js | public function add_js($js) {
$current = $this->dwoo_data->js_files;
$current[] = $js;
$this->dwoo_data->js_files = $current;
} | php | public function add_js($js) {
$current = $this->dwoo_data->js_files;
$current[] = $js;
$this->dwoo_data->js_files = $current;
} | [
"public",
"function",
"add_js",
"(",
"$",
"js",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"dwoo_data",
"->",
"js_files",
";",
"$",
"current",
"[",
"]",
"=",
"$",
"js",
";",
"$",
"this",
"->",
"dwoo_data",
"->",
"js_files",
"=",
"$",
"current",
";",
"}"
] | Add Javascript files to template
@param string $js | [
"Add",
"Javascript",
"files",
"to",
"template"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php#L66-L70 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php | Dwootemplate.add_css | public function add_css($css) {
$current = $this->dwoo_data->css_files;
$current[] = $css;
$this->dwoo_data->css_files = $current;
} | php | public function add_css($css) {
$current = $this->dwoo_data->css_files;
$current[] = $css;
$this->dwoo_data->css_files = $current;
} | [
"public",
"function",
"add_css",
"(",
"$",
"css",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"dwoo_data",
"->",
"css_files",
";",
"$",
"current",
"[",
"]",
"=",
"$",
"css",
";",
"$",
"this",
"->",
"dwoo_data",
"->",
"css_files",
"=",
"$",
"current",
";",
"}"
] | Add Css stylesheets to template
@param string $css | [
"Add",
"Css",
"stylesheets",
"to",
"template"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php#L78-L82 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php | Dwootemplate.display | public function display($sTemplate, $return = FALSE) {
// Start benchmark
$CI = get_instance();
$CI->benchmark->mark('dwoo_parse_start');
// Check if file exists
if ( !file_exists($this->template_dir . $sTemplate ) ) {
$message = sprintf('Template file \'%s\' not found.', $sTemplate);
show_error($message);
log_message('error', $message);
}
// Create new template
$tpl = new Dwoo_Template_File($this->template_dir . $sTemplate);
// render the template
$template = $this->get($tpl, $this->dwoo_data);
// Finish benchmark
$CI->benchmark->mark('dwoo_parse_end');
// Return results or not ?
if ($return == FALSE) {
$CI->output->final_output = $template;
} else {
return $template;
}
} | php | public function display($sTemplate, $return = FALSE) {
// Start benchmark
$CI = get_instance();
$CI->benchmark->mark('dwoo_parse_start');
// Check if file exists
if ( !file_exists($this->template_dir . $sTemplate ) ) {
$message = sprintf('Template file \'%s\' not found.', $sTemplate);
show_error($message);
log_message('error', $message);
}
// Create new template
$tpl = new Dwoo_Template_File($this->template_dir . $sTemplate);
// render the template
$template = $this->get($tpl, $this->dwoo_data);
// Finish benchmark
$CI->benchmark->mark('dwoo_parse_end');
// Return results or not ?
if ($return == FALSE) {
$CI->output->final_output = $template;
} else {
return $template;
}
} | [
"public",
"function",
"display",
"(",
"$",
"sTemplate",
",",
"$",
"return",
"=",
"FALSE",
")",
"{",
"// Start benchmark",
"$",
"CI",
"=",
"get_instance",
"(",
")",
";",
"$",
"CI",
"->",
"benchmark",
"->",
"mark",
"(",
"'dwoo_parse_start'",
")",
";",
"// Check if file exists",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"template_dir",
".",
"$",
"sTemplate",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Template file \\'%s\\' not found.'",
",",
"$",
"sTemplate",
")",
";",
"show_error",
"(",
"$",
"message",
")",
";",
"log_message",
"(",
"'error'",
",",
"$",
"message",
")",
";",
"}",
"// Create new template",
"$",
"tpl",
"=",
"new",
"Dwoo_Template_File",
"(",
"$",
"this",
"->",
"template_dir",
".",
"$",
"sTemplate",
")",
";",
"// render the template",
"$",
"template",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"tpl",
",",
"$",
"this",
"->",
"dwoo_data",
")",
";",
"// Finish benchmark",
"$",
"CI",
"->",
"benchmark",
"->",
"mark",
"(",
"'dwoo_parse_end'",
")",
";",
"// Return results or not ?",
"if",
"(",
"$",
"return",
"==",
"FALSE",
")",
"{",
"$",
"CI",
"->",
"output",
"->",
"final_output",
"=",
"$",
"template",
";",
"}",
"else",
"{",
"return",
"$",
"template",
";",
"}",
"}"
] | Display or return the compiled template
Since we assign the results to the standard CI output module
you can also use the helper from CI in your templates!!
@param string $sTemplate
@param boolean $return
@return mixed | [
"Display",
"or",
"return",
"the",
"compiled",
"template",
"Since",
"we",
"assign",
"the",
"results",
"to",
"the",
"standard",
"CI",
"output",
"module",
"you",
"can",
"also",
"use",
"the",
"helper",
"from",
"CI",
"in",
"your",
"templates!!"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php#L94-L121 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php | Dwootemplate.initialize | private function initialize() {
$CI = get_instance();
$CI->config->load('dwootemplate', TRUE);
$config = $CI->config->item('dwootemplate');
foreach ($config as $key => $val) {
$this->$key = $val;
}
} | php | private function initialize() {
$CI = get_instance();
$CI->config->load('dwootemplate', TRUE);
$config = $CI->config->item('dwootemplate');
foreach ($config as $key => $val) {
$this->$key = $val;
}
} | [
"private",
"function",
"initialize",
"(",
")",
"{",
"$",
"CI",
"=",
"get_instance",
"(",
")",
";",
"$",
"CI",
"->",
"config",
"->",
"load",
"(",
"'dwootemplate'",
",",
"TRUE",
")",
";",
"$",
"config",
"=",
"$",
"CI",
"->",
"config",
"->",
"item",
"(",
"'dwootemplate'",
")",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"$",
"key",
"=",
"$",
"val",
";",
"}",
"}"
] | Assign the dwootemplate config items to the instance | [
"Assign",
"the",
"dwootemplate",
"config",
"items",
"to",
"the",
"instance"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php#L164-L171 |
rem42/scraper | Utils/Tools.php | Tools.frenchDateToEnglish | public static function frenchDateToEnglish($date)
{
$date = mb_strtolower($date);
$date = ucwords($date);
$frenchDays = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'];
$englishDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
$date = str_replace($frenchDays, $englishDays, $date);
$frenchMonths = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
$englishMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
$date = str_replace($frenchMonths, $englishMonths, $date);
return $date;
} | php | public static function frenchDateToEnglish($date)
{
$date = mb_strtolower($date);
$date = ucwords($date);
$frenchDays = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'];
$englishDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
$date = str_replace($frenchDays, $englishDays, $date);
$frenchMonths = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
$englishMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
$date = str_replace($frenchMonths, $englishMonths, $date);
return $date;
} | [
"public",
"static",
"function",
"frenchDateToEnglish",
"(",
"$",
"date",
")",
"{",
"$",
"date",
"=",
"mb_strtolower",
"(",
"$",
"date",
")",
";",
"$",
"date",
"=",
"ucwords",
"(",
"$",
"date",
")",
";",
"$",
"frenchDays",
"=",
"[",
"'Lundi'",
",",
"'Mardi'",
",",
"'Mercredi'",
",",
"'Jeudi'",
",",
"'Vendredi'",
",",
"'Samedi'",
",",
"'Dimanche'",
"]",
";",
"$",
"englishDays",
"=",
"[",
"'Monday'",
",",
"'Tuesday'",
",",
"'Wednesday'",
",",
"'Thursday'",
",",
"'Friday'",
",",
"'Saturday'",
",",
"'Sunday'",
"]",
";",
"$",
"date",
"=",
"str_replace",
"(",
"$",
"frenchDays",
",",
"$",
"englishDays",
",",
"$",
"date",
")",
";",
"$",
"frenchMonths",
"=",
"[",
"'Janvier'",
",",
"'Février',",
" ",
"Mars',",
" ",
"Avril',",
" ",
"Mai',",
" ",
"Juin',",
" ",
"Juillet',",
" ",
"Août', ",
"'",
"eptembre', ",
"'",
"ctobre', ",
"'",
"ovembre', ",
"'",
"écembre'];",
"",
"",
"$",
"englishMonths",
"=",
"[",
"'January'",
",",
"'February'",
",",
"'March'",
",",
"'April'",
",",
"'May'",
",",
"'June'",
",",
"'July'",
",",
"'August'",
",",
"'September'",
",",
"'October'",
",",
"'November'",
",",
"'December'",
"]",
";",
"$",
"date",
"=",
"str_replace",
"(",
"$",
"frenchMonths",
",",
"$",
"englishMonths",
",",
"$",
"date",
")",
";",
"return",
"$",
"date",
";",
"}"
] | @param $date
@return mixed|null|string|string[] | [
"@param",
"$date"
] | train | https://github.com/rem42/scraper/blob/7c4ec23ce61b8187f2d8cfebdd233525359adb83/Utils/Tools.php#L12-L26 |
devgiants/mosquitto-clients-php-react-wrapper | src/Client/MosquittoClientsReactWrapper.php | MosquittoClientsReactWrapper.create | public static function create( LoopInterface $loop ) {
// Check clients are installed
if ( ! static::hasDependency() ) {
exit(Codes::MOSQUITTO_CLIENTS_NOT_INSTALLED);
}
// Check config files presents
if ( ! file_exists( $_SERVER['HOME'] . '/.config/mosquitto_pub' ) ) {
exit(Codes::MOSQUITTO_PUB_CONFIG_MISSING);
}
if ( ! file_exists( $_SERVER['HOME'] . '/.config/mosquitto_sub' ) ) {
exit(Codes::MOSQUITTO_SUB_CONFIG_MISSING);
}
return new static( $loop );
} | php | public static function create( LoopInterface $loop ) {
// Check clients are installed
if ( ! static::hasDependency() ) {
exit(Codes::MOSQUITTO_CLIENTS_NOT_INSTALLED);
}
// Check config files presents
if ( ! file_exists( $_SERVER['HOME'] . '/.config/mosquitto_pub' ) ) {
exit(Codes::MOSQUITTO_PUB_CONFIG_MISSING);
}
if ( ! file_exists( $_SERVER['HOME'] . '/.config/mosquitto_sub' ) ) {
exit(Codes::MOSQUITTO_SUB_CONFIG_MISSING);
}
return new static( $loop );
} | [
"public",
"static",
"function",
"create",
"(",
"LoopInterface",
"$",
"loop",
")",
"{",
"// Check clients are installed",
"if",
"(",
"!",
"static",
"::",
"hasDependency",
"(",
")",
")",
"{",
"exit",
"(",
"Codes",
"::",
"MOSQUITTO_CLIENTS_NOT_INSTALLED",
")",
";",
"}",
"// Check config files presents",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"_SERVER",
"[",
"'HOME'",
"]",
".",
"'/.config/mosquitto_pub'",
")",
")",
"{",
"exit",
"(",
"Codes",
"::",
"MOSQUITTO_PUB_CONFIG_MISSING",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"_SERVER",
"[",
"'HOME'",
"]",
".",
"'/.config/mosquitto_sub'",
")",
")",
"{",
"exit",
"(",
"Codes",
"::",
"MOSQUITTO_SUB_CONFIG_MISSING",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"loop",
")",
";",
"}"
] | @param LoopInterface $loop
@return static
@throws MosquittoClientsMissingConfigFileException
@throws MosquittoClientsMissingException | [
"@param",
"LoopInterface",
"$loop"
] | train | https://github.com/devgiants/mosquitto-clients-php-react-wrapper/blob/1ac770e4a55e81eac272f0adb2c80fb450a9345b/src/Client/MosquittoClientsReactWrapper.php#L54-L71 |
Opifer/EavBundle | Form/Type/AttributeType.php | AttributeType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('valueType', ValueProviderType::class, [
'label' => 'attribute.value_type',
'attr' => [
'placeholder' => 'form.value_type.placeholder',
'help_text' => 'form.value_type.help_text'
]
])->add('displayName', TextType::class, [
'label' => 'attribute.display_name',
'attr' => [
'class' => 'slugify',
'data-slugify-target' => '.slugify-target-' . $builder->getName(),
'data-slugify-separator' => '_',
'placeholder' => 'form.display_name.placeholder',
'help_text' => 'form.display_name.help_text',
'widget_col' => 6
]
])->add('name', TextType::class, [
'label' => 'attribute.name',
'attr' => [
'class' => 'slugify-target-' . $builder->getName(),
'placeholder' => 'form.name.placeholder',
'help_text' => 'form.name.help_text',
'widget_col' => 6
]
])->add('description', TextType::class, [
'required' => false,
'label' => 'attribute.description',
'attr' => [ 'help_text' => 'form.description.help_text' ]
])->add('sort', IntegerType::class, [
'label' => 'attribute.sort',
'attr' => [ 'help_text' => 'form.sort.help_text', 'widget_col' => 2 ],
'empty_data' => 0,
'required' => false
])->add('required', ChoiceType::class, [
'choices' => [
false => 'Not required',
true => 'Required'
],
'label' => 'Required',
'required' => true
]);
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$attribute = $event->getData();
$form = $event->getForm();
if ($attribute && in_array($attribute->getValueType(), ['checklist', 'select', 'radio'])) {
// TODO Use Symfony's CollectionType here
$form->add('options', CollapsibleCollectionType::class, [
'allow_add' => true,
'allow_delete' => true,
'type' => OptionType::class
]);
}
});
} | php | public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('valueType', ValueProviderType::class, [
'label' => 'attribute.value_type',
'attr' => [
'placeholder' => 'form.value_type.placeholder',
'help_text' => 'form.value_type.help_text'
]
])->add('displayName', TextType::class, [
'label' => 'attribute.display_name',
'attr' => [
'class' => 'slugify',
'data-slugify-target' => '.slugify-target-' . $builder->getName(),
'data-slugify-separator' => '_',
'placeholder' => 'form.display_name.placeholder',
'help_text' => 'form.display_name.help_text',
'widget_col' => 6
]
])->add('name', TextType::class, [
'label' => 'attribute.name',
'attr' => [
'class' => 'slugify-target-' . $builder->getName(),
'placeholder' => 'form.name.placeholder',
'help_text' => 'form.name.help_text',
'widget_col' => 6
]
])->add('description', TextType::class, [
'required' => false,
'label' => 'attribute.description',
'attr' => [ 'help_text' => 'form.description.help_text' ]
])->add('sort', IntegerType::class, [
'label' => 'attribute.sort',
'attr' => [ 'help_text' => 'form.sort.help_text', 'widget_col' => 2 ],
'empty_data' => 0,
'required' => false
])->add('required', ChoiceType::class, [
'choices' => [
false => 'Not required',
true => 'Required'
],
'label' => 'Required',
'required' => true
]);
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$attribute = $event->getData();
$form = $event->getForm();
if ($attribute && in_array($attribute->getValueType(), ['checklist', 'select', 'radio'])) {
// TODO Use Symfony's CollectionType here
$form->add('options', CollapsibleCollectionType::class, [
'allow_add' => true,
'allow_delete' => true,
'type' => OptionType::class
]);
}
});
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"builder",
"->",
"add",
"(",
"'valueType'",
",",
"ValueProviderType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'attribute.value_type'",
",",
"'attr'",
"=>",
"[",
"'placeholder'",
"=>",
"'form.value_type.placeholder'",
",",
"'help_text'",
"=>",
"'form.value_type.help_text'",
"]",
"]",
")",
"->",
"add",
"(",
"'displayName'",
",",
"TextType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'attribute.display_name'",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'slugify'",
",",
"'data-slugify-target'",
"=>",
"'.slugify-target-'",
".",
"$",
"builder",
"->",
"getName",
"(",
")",
",",
"'data-slugify-separator'",
"=>",
"'_'",
",",
"'placeholder'",
"=>",
"'form.display_name.placeholder'",
",",
"'help_text'",
"=>",
"'form.display_name.help_text'",
",",
"'widget_col'",
"=>",
"6",
"]",
"]",
")",
"->",
"add",
"(",
"'name'",
",",
"TextType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'attribute.name'",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'slugify-target-'",
".",
"$",
"builder",
"->",
"getName",
"(",
")",
",",
"'placeholder'",
"=>",
"'form.name.placeholder'",
",",
"'help_text'",
"=>",
"'form.name.help_text'",
",",
"'widget_col'",
"=>",
"6",
"]",
"]",
")",
"->",
"add",
"(",
"'description'",
",",
"TextType",
"::",
"class",
",",
"[",
"'required'",
"=>",
"false",
",",
"'label'",
"=>",
"'attribute.description'",
",",
"'attr'",
"=>",
"[",
"'help_text'",
"=>",
"'form.description.help_text'",
"]",
"]",
")",
"->",
"add",
"(",
"'sort'",
",",
"IntegerType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'attribute.sort'",
",",
"'attr'",
"=>",
"[",
"'help_text'",
"=>",
"'form.sort.help_text'",
",",
"'widget_col'",
"=>",
"2",
"]",
",",
"'empty_data'",
"=>",
"0",
",",
"'required'",
"=>",
"false",
"]",
")",
"->",
"add",
"(",
"'required'",
",",
"ChoiceType",
"::",
"class",
",",
"[",
"'choices'",
"=>",
"[",
"false",
"=>",
"'Not required'",
",",
"true",
"=>",
"'Required'",
"]",
",",
"'label'",
"=>",
"'Required'",
",",
"'required'",
"=>",
"true",
"]",
")",
";",
"$",
"builder",
"->",
"addEventListener",
"(",
"FormEvents",
"::",
"PRE_SET_DATA",
",",
"function",
"(",
"FormEvent",
"$",
"event",
")",
"{",
"$",
"attribute",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
";",
"$",
"form",
"=",
"$",
"event",
"->",
"getForm",
"(",
")",
";",
"if",
"(",
"$",
"attribute",
"&&",
"in_array",
"(",
"$",
"attribute",
"->",
"getValueType",
"(",
")",
",",
"[",
"'checklist'",
",",
"'select'",
",",
"'radio'",
"]",
")",
")",
"{",
"// TODO Use Symfony's CollectionType here",
"$",
"form",
"->",
"add",
"(",
"'options'",
",",
"CollapsibleCollectionType",
"::",
"class",
",",
"[",
"'allow_add'",
"=>",
"true",
",",
"'allow_delete'",
"=>",
"true",
",",
"'type'",
"=>",
"OptionType",
"::",
"class",
"]",
")",
";",
"}",
"}",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/Opifer/EavBundle/blob/4236fdc28b7574dac43f420704d0fc3c04905a4c/Form/Type/AttributeType.php#L39-L96 |
i-lateral/silverstripe-modeladminplus | src/DataObjectExtension.php | DataObjectExtension.getModelAdminSearchContext | public function getModelAdminSearchContext()
{
return SearchContext::create(
get_class($this->getOwner()),
$this->getOwner()->scaffoldSearchFields(),
$this->getOwner()->defaultSearchFilters()
);
} | php | public function getModelAdminSearchContext()
{
return SearchContext::create(
get_class($this->getOwner()),
$this->getOwner()->scaffoldSearchFields(),
$this->getOwner()->defaultSearchFilters()
);
} | [
"public",
"function",
"getModelAdminSearchContext",
"(",
")",
"{",
"return",
"SearchContext",
"::",
"create",
"(",
"get_class",
"(",
"$",
"this",
"->",
"getOwner",
"(",
")",
")",
",",
"$",
"this",
"->",
"getOwner",
"(",
")",
"->",
"scaffoldSearchFields",
"(",
")",
",",
"$",
"this",
"->",
"getOwner",
"(",
")",
"->",
"defaultSearchFilters",
"(",
")",
")",
";",
"}"
] | Get a custom search context for model admin plus | [
"Get",
"a",
"custom",
"search",
"context",
"for",
"model",
"admin",
"plus"
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/DataObjectExtension.php#L12-L19 |
InactiveProjects/limoncello-illuminate | app/Http/Controllers/Api/BoardsController.php | BoardsController.indexPosts | public function indexPosts($boardId)
{
$parameters = $this->getRequest()->getParameters();
$pagedData = $this->getApi()->indexPosts($boardId, $parameters);
return $this->getResponses()->getPagedDataResponse($pagedData);
} | php | public function indexPosts($boardId)
{
$parameters = $this->getRequest()->getParameters();
$pagedData = $this->getApi()->indexPosts($boardId, $parameters);
return $this->getResponses()->getPagedDataResponse($pagedData);
} | [
"public",
"function",
"indexPosts",
"(",
"$",
"boardId",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getParameters",
"(",
")",
";",
"$",
"pagedData",
"=",
"$",
"this",
"->",
"getApi",
"(",
")",
"->",
"indexPosts",
"(",
"$",
"boardId",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"this",
"->",
"getResponses",
"(",
")",
"->",
"getPagedDataResponse",
"(",
"$",
"pagedData",
")",
";",
"}"
] | @param string $boardId
@return Response | [
"@param",
"string",
"$boardId"
] | train | https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Http/Controllers/Api/BoardsController.php#L33-L40 |
fccn/oai-pmh-core | src/schemas/ands_dces.php | ANDS_DCES.create_dc_node | protected function create_dc_node($name, $value = '')
{
if (empty($value)) {
return;
}
$this->addChild($this->working_node, "dc:".$name, utf8_encode($value));
} | php | protected function create_dc_node($name, $value = '')
{
if (empty($value)) {
return;
}
$this->addChild($this->working_node, "dc:".$name, utf8_encode($value));
} | [
"protected",
"function",
"create_dc_node",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"addChild",
"(",
"$",
"this",
"->",
"working_node",
",",
"\"dc:\"",
".",
"$",
"name",
",",
"utf8_encode",
"(",
"$",
"value",
")",
")",
";",
"}"
] | Creates a generic dc:element node | [
"Creates",
"a",
"generic",
"dc",
":",
"element",
"node"
] | train | https://github.com/fccn/oai-pmh-core/blob/a9c6852482c7bd7c48911a2165120325ecc27ea2/src/schemas/ands_dces.php#L87-L93 |
fccn/oai-pmh-core | src/schemas/ands_dces.php | DC_DataHolder.combine | public function combine($another)
{
if (is_a($another, DC_DataHolder::getKlass())) {
// debug_message("entering combine...");
// debug_var_dump("another", $another);
//identifier
if (empty($this->identifier)) {
debug_message("DC_DataHolder::identifier should not be empty!!");
$this->identifier = $another->identifier;
} elseif (strcmp(substr($this->identifier, - strlen($another->identifier)), $another->identifier) !== 0) {
debug_var_dump('comparison', strcmp(substr($this->identifier, - strlen($another->identifier)), $another->identifier));
error_log("found a different identifier for this element ".$this->identifier." != ".$another->identifier);
return;
}
//continue with other elements
$this->addElement('contributor', $another);
$this->addElement('coverage', $another);
$this->addElement('creator', $another);
$this->addElement('date_', $another);
$this->addElement('description', $another);
$this->addElement('format_', $another);
$this->addElement('language', $another);
$this->addElement('publisher', $another);
$this->addElement('relation', $another);
$this->addElement('rights', $another);
$this->addElement('source', $another);
$this->addElement('subject', $another);
$this->addElement('title', $another);
$this->addElement('type_', $another);
}
} | php | public function combine($another)
{
if (is_a($another, DC_DataHolder::getKlass())) {
// debug_message("entering combine...");
// debug_var_dump("another", $another);
//identifier
if (empty($this->identifier)) {
debug_message("DC_DataHolder::identifier should not be empty!!");
$this->identifier = $another->identifier;
} elseif (strcmp(substr($this->identifier, - strlen($another->identifier)), $another->identifier) !== 0) {
debug_var_dump('comparison', strcmp(substr($this->identifier, - strlen($another->identifier)), $another->identifier));
error_log("found a different identifier for this element ".$this->identifier." != ".$another->identifier);
return;
}
//continue with other elements
$this->addElement('contributor', $another);
$this->addElement('coverage', $another);
$this->addElement('creator', $another);
$this->addElement('date_', $another);
$this->addElement('description', $another);
$this->addElement('format_', $another);
$this->addElement('language', $another);
$this->addElement('publisher', $another);
$this->addElement('relation', $another);
$this->addElement('rights', $another);
$this->addElement('source', $another);
$this->addElement('subject', $another);
$this->addElement('title', $another);
$this->addElement('type_', $another);
}
} | [
"public",
"function",
"combine",
"(",
"$",
"another",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"another",
",",
"DC_DataHolder",
"::",
"getKlass",
"(",
")",
")",
")",
"{",
"// debug_message(\"entering combine...\");",
"// debug_var_dump(\"another\", $another);",
"//identifier",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"identifier",
")",
")",
"{",
"debug_message",
"(",
"\"DC_DataHolder::identifier should not be empty!!\"",
")",
";",
"$",
"this",
"->",
"identifier",
"=",
"$",
"another",
"->",
"identifier",
";",
"}",
"elseif",
"(",
"strcmp",
"(",
"substr",
"(",
"$",
"this",
"->",
"identifier",
",",
"-",
"strlen",
"(",
"$",
"another",
"->",
"identifier",
")",
")",
",",
"$",
"another",
"->",
"identifier",
")",
"!==",
"0",
")",
"{",
"debug_var_dump",
"(",
"'comparison'",
",",
"strcmp",
"(",
"substr",
"(",
"$",
"this",
"->",
"identifier",
",",
"-",
"strlen",
"(",
"$",
"another",
"->",
"identifier",
")",
")",
",",
"$",
"another",
"->",
"identifier",
")",
")",
";",
"error_log",
"(",
"\"found a different identifier for this element \"",
".",
"$",
"this",
"->",
"identifier",
".",
"\" != \"",
".",
"$",
"another",
"->",
"identifier",
")",
";",
"return",
";",
"}",
"//continue with other elements",
"$",
"this",
"->",
"addElement",
"(",
"'contributor'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'coverage'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'creator'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'date_'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'description'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'format_'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'language'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'publisher'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'relation'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'rights'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'source'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'subject'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'title'",
",",
"$",
"another",
")",
";",
"$",
"this",
"->",
"addElement",
"(",
"'type_'",
",",
"$",
"another",
")",
";",
"}",
"}"
] | Combines this object with another DC_DataHolder object | [
"Combines",
"this",
"object",
"with",
"another",
"DC_DataHolder",
"object"
] | train | https://github.com/fccn/oai-pmh-core/blob/a9c6852482c7bd7c48911a2165120325ecc27ea2/src/schemas/ands_dces.php#L184-L214 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.