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
DreadLabs/VantomasWebsite
src/Page/TypeCollection.php
TypeCollection.offsetUnset
public function offsetUnset($offset) { if ($offset instanceof Type) { $this->types = array_filter($this->types, function ($type) use ($offset) { return $type !== $offset; }); return; } unset($this->types[$offset]); }
php
public function offsetUnset($offset) { if ($offset instanceof Type) { $this->types = array_filter($this->types, function ($type) use ($offset) { return $type !== $offset; }); return; } unset($this->types[$offset]); }
[ "public", "function", "offsetUnset", "(", "$", "offset", ")", "{", "if", "(", "$", "offset", "instanceof", "Type", ")", "{", "$", "this", "->", "types", "=", "array_filter", "(", "$", "this", "->", "types", ",", "function", "(", "$", "type", ")", "use", "(", "$", "offset", ")", "{", "return", "$", "type", "!==", "$", "offset", ";", "}", ")", ";", "return", ";", "}", "unset", "(", "$", "this", "->", "types", "[", "$", "offset", "]", ")", ";", "}" ]
Offset to unset @param mixed $offset The offset to unset. @return void
[ "Offset", "to", "unset" ]
train
https://github.com/DreadLabs/VantomasWebsite/blob/7f85f2b45bdf5ed9fa9d320c805c416bf99cd668/src/Page/TypeCollection.php#L89-L100
KDF5000/EasyThink
src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php
SmartTemplateDebugger.SmartTemplateDebugger
function SmartTemplateDebugger ( $template_filename ) { $this->filename = $template_filename; // Load Template if ($hd = @fopen($template_filename, "r")) { $this->template = fread($hd, filesize($template_filename)); fclose($hd); } else { $this->template = "SmartTemplate Debugger Error: File not found: '$template_filename'"; } $this->tab[0] = ''; for ($i=1; $i < 10; $i++) { $this->tab[$i] = str_repeat(' ', $i); } }
php
function SmartTemplateDebugger ( $template_filename ) { $this->filename = $template_filename; // Load Template if ($hd = @fopen($template_filename, "r")) { $this->template = fread($hd, filesize($template_filename)); fclose($hd); } else { $this->template = "SmartTemplate Debugger Error: File not found: '$template_filename'"; } $this->tab[0] = ''; for ($i=1; $i < 10; $i++) { $this->tab[$i] = str_repeat(' ', $i); } }
[ "function", "SmartTemplateDebugger", "(", "$", "template_filename", ")", "{", "$", "this", "->", "filename", "=", "$", "template_filename", ";", "//\tLoad Template", "if", "(", "$", "hd", "=", "@", "fopen", "(", "$", "template_filename", ",", "\"r\"", ")", ")", "{", "$", "this", "->", "template", "=", "fread", "(", "$", "hd", ",", "filesize", "(", "$", "template_filename", ")", ")", ";", "fclose", "(", "$", "hd", ")", ";", "}", "else", "{", "$", "this", "->", "template", "=", "\"SmartTemplate Debugger Error: File not found: '$template_filename'\"", ";", "}", "$", "this", "->", "tab", "[", "0", "]", "=", "''", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "10", ";", "$", "i", "++", ")", "{", "$", "this", "->", "tab", "[", "$", "i", "]", "=", "str_repeat", "(", "' '", ",", "$", "i", ")", ";", "}", "}" ]
SmartTemplateParser Constructor @param string $template_filename HTML Template Filename
[ "SmartTemplateParser", "Constructor" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php#L34-L52
KDF5000/EasyThink
src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php
SmartTemplateDebugger.start
function start ( $vars ) { $page = $this->template; $page = preg_replace("/(<!-- BEGIN [ a-zA-Z0-9_.]* -->)/", "\n$1\n", $page); $page = preg_replace("/(<!-- IF .+? -->)/", "\n$1\n", $page); $page = preg_replace("/(<!-- END.*? -->)/", "\n$1\n", $page); $page = preg_replace("/(<!-- ELSEIF .+? -->)/", "\n$1\n", $page); $page = preg_replace("/(<!-- ELSE [ a-zA-Z0-9_.]*-->)/", "\n$1\n", $page); $page = $this->highlight_html($page); $rows = explode("\n", $page); $page_arr = array(); $level = 0; $blocklvl = 0; $rowcnt = 0; $spancnt = 0; $offset = 22; $lvl_block = array(); $lvl_row = array(); $lvl_typ = array(); foreach ($rows as $row) { if ($row = trim($row)) { $closespan = false; if (substr($row, $offset, 12) == '&lt;!-- END ') { if ($level < 1) { $level++; $error[$rowcnt] = "END Without BEGIN"; } elseif ($lvl_typ[$level] != 'BEGIN') { $error[$lvl_row[$level]] = "IF without ENDIF"; $error[$rowcnt] = "END Without BEGIN"; } $blocklvl--; $level--; $closespan = true; } if (substr($row, $offset, 14) == '&lt;!-- ENDIF ') { if ($level < 1) { $level++; $error[$rowcnt] = "ENDIF Without IF"; } elseif ($lvl_typ[$level] != 'IF') { $error[$lvl_row[$level]] = "BEGIN without END"; $error[$rowcnt] = "ENDIF Without IF"; } $closespan = true; $level--; } if ($closespan) { $page_arr[$rowcnt-1] .= '</span>'; } $this_row = $this->tab[$level] . $row; if (substr($row, $offset, 12) == '&lt;!-- ELSE') { if ($level < 1) { $error[$rowcnt] = "ELSE Without IF"; } elseif ($lvl_typ[$level] != 'IF') { $error[$rowcnt] = "ELSE Without IF"; } else { $this_row = $this->tab[$level-1] . $row; } } if (substr($row, $offset, 14) == '&lt;!-- BEGIN ') { if ($blocklvl == 0) { if ($lp = strpos($row, '--&gt;')) { if ($blockname = trim(substr($row, $offset + 14, $lp -$offset -14))) { if ($nr = count($vars[$blockname])) { $this_row .= $this->toggleview("$nr Entries"); } else { $this_row .= $this->toggleview("Emtpy"); } } } } else { $this_row .= $this->toggleview('['); } $blocklvl++; $level++; $lvl_row[$level] = $rowcnt; $lvl_typ[$level] = 'BEGIN'; } elseif (substr($row, $offset, 11) == '&lt;!-- IF ') { $level++; $lvl_row[$level] = $rowcnt; $lvl_typ[$level] = 'IF'; $this_row .= $this->toggleview(); } $page_arr[] = $this_row; $lvl_block[$rowcnt] = $blocklvl; $rowcnt++; } } if ($level > 0) { $error[$lvl_row[$level]] = "Block not closed"; } $page = join("\n", $page_arr); $rows = explode("\n", $page); $cnt = count($rows); for ($i = 0; $i < $cnt; $i++) { // Add Errortext if (isset($error)) { if ($err = $error[$i]) { $rows[$i] = '<b>' . $rows[$i] . ' ERROR: ' . $err . '!</b>'; } } // Replace Scalars if (preg_match_all('/{([a-zA-Z0-9_. &;]+)}/', $rows[$i], $var)) { foreach ($var[1] as $tag) { $fulltag = $tag; if ($delim = strpos($tag, ' &gt; ')) { $tag = substr($tag, 0, $delim); } if (substr($tag, 0, 4) == 'top.') { $title = $this->tip($vars[substr($tag, 4)]); } elseif ($lvl_block[$i] == 0) { $title = $this->tip($vars[$tag]); } else { $title = '[BLOCK?]'; } $code = '<b title="' . $title . '">{' . $fulltag . '}</b>'; $rows[$i] = str_replace('{'.$fulltag.'}', $code, $rows[$i]); } } // Replace Extensions if (preg_match_all('/{([a-zA-Z0-9_]+):([^}]*)}/', $rows[$i], $var)) { foreach ($var[2] as $tmpcnt => $tag) { $fulltag = $tag; if ($delim = strpos($tag, ' &gt; ')) { $tag = substr($tag, 0, $delim); } if (strpos($tag, ',')) { list($tag, $addparam) = explode(',', $tag, 2); } $extension = $var[1][$tmpcnt]; if (substr($tag, 0, 4) == 'top.') { $title = $this->tip($vars[substr($tag, 4)]); } elseif ($lvl_block[$i] == 0) { $title = $this->tip($vars[$tag]); } else { $title = '[BLOCK?]'; } $code = '<b title="' . $title . '">{' . $extension . ':' . $fulltag . '}</b>'; $rows[$i] = str_replace('{'.$extension . ':' . $fulltag .'}', $code, $rows[$i]); } } // 'IF nnn' Blocks if (preg_match_all('/&lt;!-- IF ([a-zA-Z0-9_.]+) --&gt;/', $rows[$i], $var)) { foreach ($var[1] as $tag) { if (substr($tag, 0, 4) == 'top.') { $title = $this->tip($vars[substr($tag, 4)]); } elseif ($lvl_block[$i] == 0) { $title = $this->tip($vars[$tag]); } else { $title = '[BLOCK?]'; } $code = '<span title="' . $title . '">&lt;!-- IF ' . $tag . ' --&gt;</span>'; $rows[$i] = str_replace("&lt;!-- IF $tag --&gt;", $code, $rows[$i]); if ($title == '[NULL]') { $rows[$i] = str_replace('Hide', 'Show', $rows[$i]); $rows[$i] = str_replace('block', 'none', $rows[$i]); } } } } $page = join("<br>", $rows); // Print Header echo '<html><head><script type="text/javascript"> function toggleVisibility(el, src) { var v = el.style.display == "block"; var str = src.innerHTML; el.style.display = v ? "none" : "block"; src.innerHTML = v ? str.replace(/Hide/, "Show") : str.replace(/Show/, "Hide");} </script></head><body>'; // Print Index echo '<font face="Arial" Size="3"><b>'; echo 'SmartTemplate Debugger<br>'; echo '<font size="2"><li>PHP-Script: ' . $_SERVER['PATH_TRANSLATED'] . '</li><li>Template: ' . $this->filename . '</li></font><hr>'; echo '<li><a href="#template_code">Template</a></li>'; echo '<li><a href="#compiled_code">Compiled Template</a></li>'; echo '<li><a href="#data_code">Data</a></li>'; echo '</b></font><hr>'; // Print Template echo '<a name="template_code"><br><font face="Arial" Size="3"><b>Template:</b>&nbsp;[<a href="javascript:void(\'\');" onclick="toggleVisibility(document.getElementById(\'Template\'), this); return false">Hide Ouptut</a>]</font><br>'; echo '<table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="#C6D3EF"><tr><td bgcolor="#F0F0F0"><pre id="Template" style="display:block">'; echo $page; echo '</pre></td></tr></table>'; // Print Compiled Template if (@include_once ("class.smarttemplateparser.php")) { $parser = new SmartTemplateParser($this->filename); $compiled = $parser->compile(); echo '<a name="compiled_code"><br><br><font face="Arial" Size="3"><b>Compiled Template:</b>&nbsp;[<a href="javascript:void(\'\');" onclick="toggleVisibility(document.getElementById(\'Compiled\'), this); return false">Hide Ouptut</a>]</font><br>'; echo '<table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="#C6D3EF"><tr><td bgcolor="#F0F0F0"><pre id="Compiled" style="display:block">'; highlight_string($compiled); echo '</pre></td></tr></table>'; } else { exit( "SmartTemplate Error: Cannot find class.smarttemplateparser.php; check SmartTemplate installation"); } // Print Data echo '<a name="data_code"><br><br><font face="Arial" Size="3"><b>Data:</b>&nbsp;[<a href="javascript:void(\'\');" onclick="toggleVisibility(document.getElementById(\'Data\'), this); return false">Hide Ouptut</a>]</font><br>'; echo '<table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="#C6D3EF"><tr><td bgcolor="#F0F0F0"><pre id="Data" style="display:block">'; echo $this->vardump($vars); echo '</pre></td></tr></table></body></html>'; }
php
function start ( $vars ) { $page = $this->template; $page = preg_replace("/(<!-- BEGIN [ a-zA-Z0-9_.]* -->)/", "\n$1\n", $page); $page = preg_replace("/(<!-- IF .+? -->)/", "\n$1\n", $page); $page = preg_replace("/(<!-- END.*? -->)/", "\n$1\n", $page); $page = preg_replace("/(<!-- ELSEIF .+? -->)/", "\n$1\n", $page); $page = preg_replace("/(<!-- ELSE [ a-zA-Z0-9_.]*-->)/", "\n$1\n", $page); $page = $this->highlight_html($page); $rows = explode("\n", $page); $page_arr = array(); $level = 0; $blocklvl = 0; $rowcnt = 0; $spancnt = 0; $offset = 22; $lvl_block = array(); $lvl_row = array(); $lvl_typ = array(); foreach ($rows as $row) { if ($row = trim($row)) { $closespan = false; if (substr($row, $offset, 12) == '&lt;!-- END ') { if ($level < 1) { $level++; $error[$rowcnt] = "END Without BEGIN"; } elseif ($lvl_typ[$level] != 'BEGIN') { $error[$lvl_row[$level]] = "IF without ENDIF"; $error[$rowcnt] = "END Without BEGIN"; } $blocklvl--; $level--; $closespan = true; } if (substr($row, $offset, 14) == '&lt;!-- ENDIF ') { if ($level < 1) { $level++; $error[$rowcnt] = "ENDIF Without IF"; } elseif ($lvl_typ[$level] != 'IF') { $error[$lvl_row[$level]] = "BEGIN without END"; $error[$rowcnt] = "ENDIF Without IF"; } $closespan = true; $level--; } if ($closespan) { $page_arr[$rowcnt-1] .= '</span>'; } $this_row = $this->tab[$level] . $row; if (substr($row, $offset, 12) == '&lt;!-- ELSE') { if ($level < 1) { $error[$rowcnt] = "ELSE Without IF"; } elseif ($lvl_typ[$level] != 'IF') { $error[$rowcnt] = "ELSE Without IF"; } else { $this_row = $this->tab[$level-1] . $row; } } if (substr($row, $offset, 14) == '&lt;!-- BEGIN ') { if ($blocklvl == 0) { if ($lp = strpos($row, '--&gt;')) { if ($blockname = trim(substr($row, $offset + 14, $lp -$offset -14))) { if ($nr = count($vars[$blockname])) { $this_row .= $this->toggleview("$nr Entries"); } else { $this_row .= $this->toggleview("Emtpy"); } } } } else { $this_row .= $this->toggleview('['); } $blocklvl++; $level++; $lvl_row[$level] = $rowcnt; $lvl_typ[$level] = 'BEGIN'; } elseif (substr($row, $offset, 11) == '&lt;!-- IF ') { $level++; $lvl_row[$level] = $rowcnt; $lvl_typ[$level] = 'IF'; $this_row .= $this->toggleview(); } $page_arr[] = $this_row; $lvl_block[$rowcnt] = $blocklvl; $rowcnt++; } } if ($level > 0) { $error[$lvl_row[$level]] = "Block not closed"; } $page = join("\n", $page_arr); $rows = explode("\n", $page); $cnt = count($rows); for ($i = 0; $i < $cnt; $i++) { // Add Errortext if (isset($error)) { if ($err = $error[$i]) { $rows[$i] = '<b>' . $rows[$i] . ' ERROR: ' . $err . '!</b>'; } } // Replace Scalars if (preg_match_all('/{([a-zA-Z0-9_. &;]+)}/', $rows[$i], $var)) { foreach ($var[1] as $tag) { $fulltag = $tag; if ($delim = strpos($tag, ' &gt; ')) { $tag = substr($tag, 0, $delim); } if (substr($tag, 0, 4) == 'top.') { $title = $this->tip($vars[substr($tag, 4)]); } elseif ($lvl_block[$i] == 0) { $title = $this->tip($vars[$tag]); } else { $title = '[BLOCK?]'; } $code = '<b title="' . $title . '">{' . $fulltag . '}</b>'; $rows[$i] = str_replace('{'.$fulltag.'}', $code, $rows[$i]); } } // Replace Extensions if (preg_match_all('/{([a-zA-Z0-9_]+):([^}]*)}/', $rows[$i], $var)) { foreach ($var[2] as $tmpcnt => $tag) { $fulltag = $tag; if ($delim = strpos($tag, ' &gt; ')) { $tag = substr($tag, 0, $delim); } if (strpos($tag, ',')) { list($tag, $addparam) = explode(',', $tag, 2); } $extension = $var[1][$tmpcnt]; if (substr($tag, 0, 4) == 'top.') { $title = $this->tip($vars[substr($tag, 4)]); } elseif ($lvl_block[$i] == 0) { $title = $this->tip($vars[$tag]); } else { $title = '[BLOCK?]'; } $code = '<b title="' . $title . '">{' . $extension . ':' . $fulltag . '}</b>'; $rows[$i] = str_replace('{'.$extension . ':' . $fulltag .'}', $code, $rows[$i]); } } // 'IF nnn' Blocks if (preg_match_all('/&lt;!-- IF ([a-zA-Z0-9_.]+) --&gt;/', $rows[$i], $var)) { foreach ($var[1] as $tag) { if (substr($tag, 0, 4) == 'top.') { $title = $this->tip($vars[substr($tag, 4)]); } elseif ($lvl_block[$i] == 0) { $title = $this->tip($vars[$tag]); } else { $title = '[BLOCK?]'; } $code = '<span title="' . $title . '">&lt;!-- IF ' . $tag . ' --&gt;</span>'; $rows[$i] = str_replace("&lt;!-- IF $tag --&gt;", $code, $rows[$i]); if ($title == '[NULL]') { $rows[$i] = str_replace('Hide', 'Show', $rows[$i]); $rows[$i] = str_replace('block', 'none', $rows[$i]); } } } } $page = join("<br>", $rows); // Print Header echo '<html><head><script type="text/javascript"> function toggleVisibility(el, src) { var v = el.style.display == "block"; var str = src.innerHTML; el.style.display = v ? "none" : "block"; src.innerHTML = v ? str.replace(/Hide/, "Show") : str.replace(/Show/, "Hide");} </script></head><body>'; // Print Index echo '<font face="Arial" Size="3"><b>'; echo 'SmartTemplate Debugger<br>'; echo '<font size="2"><li>PHP-Script: ' . $_SERVER['PATH_TRANSLATED'] . '</li><li>Template: ' . $this->filename . '</li></font><hr>'; echo '<li><a href="#template_code">Template</a></li>'; echo '<li><a href="#compiled_code">Compiled Template</a></li>'; echo '<li><a href="#data_code">Data</a></li>'; echo '</b></font><hr>'; // Print Template echo '<a name="template_code"><br><font face="Arial" Size="3"><b>Template:</b>&nbsp;[<a href="javascript:void(\'\');" onclick="toggleVisibility(document.getElementById(\'Template\'), this); return false">Hide Ouptut</a>]</font><br>'; echo '<table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="#C6D3EF"><tr><td bgcolor="#F0F0F0"><pre id="Template" style="display:block">'; echo $page; echo '</pre></td></tr></table>'; // Print Compiled Template if (@include_once ("class.smarttemplateparser.php")) { $parser = new SmartTemplateParser($this->filename); $compiled = $parser->compile(); echo '<a name="compiled_code"><br><br><font face="Arial" Size="3"><b>Compiled Template:</b>&nbsp;[<a href="javascript:void(\'\');" onclick="toggleVisibility(document.getElementById(\'Compiled\'), this); return false">Hide Ouptut</a>]</font><br>'; echo '<table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="#C6D3EF"><tr><td bgcolor="#F0F0F0"><pre id="Compiled" style="display:block">'; highlight_string($compiled); echo '</pre></td></tr></table>'; } else { exit( "SmartTemplate Error: Cannot find class.smarttemplateparser.php; check SmartTemplate installation"); } // Print Data echo '<a name="data_code"><br><br><font face="Arial" Size="3"><b>Data:</b>&nbsp;[<a href="javascript:void(\'\');" onclick="toggleVisibility(document.getElementById(\'Data\'), this); return false">Hide Ouptut</a>]</font><br>'; echo '<table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="#C6D3EF"><tr><td bgcolor="#F0F0F0"><pre id="Data" style="display:block">'; echo $this->vardump($vars); echo '</pre></td></tr></table></body></html>'; }
[ "function", "start", "(", "$", "vars", ")", "{", "$", "page", "=", "$", "this", "->", "template", ";", "$", "page", "=", "preg_replace", "(", "\"/(<!-- BEGIN [ a-zA-Z0-9_.]* -->)/\"", ",", "\"\\n$1\\n\"", ",", "$", "page", ")", ";", "$", "page", "=", "preg_replace", "(", "\"/(<!-- IF .+? -->)/\"", ",", "\"\\n$1\\n\"", ",", "$", "page", ")", ";", "$", "page", "=", "preg_replace", "(", "\"/(<!-- END.*? -->)/\"", ",", "\"\\n$1\\n\"", ",", "$", "page", ")", ";", "$", "page", "=", "preg_replace", "(", "\"/(<!-- ELSEIF .+? -->)/\"", ",", "\"\\n$1\\n\"", ",", "$", "page", ")", ";", "$", "page", "=", "preg_replace", "(", "\"/(<!-- ELSE [ a-zA-Z0-9_.]*-->)/\"", ",", "\"\\n$1\\n\"", ",", "$", "page", ")", ";", "$", "page", "=", "$", "this", "->", "highlight_html", "(", "$", "page", ")", ";", "$", "rows", "=", "explode", "(", "\"\\n\"", ",", "$", "page", ")", ";", "$", "page_arr", "=", "array", "(", ")", ";", "$", "level", "=", "0", ";", "$", "blocklvl", "=", "0", ";", "$", "rowcnt", "=", "0", ";", "$", "spancnt", "=", "0", ";", "$", "offset", "=", "22", ";", "$", "lvl_block", "=", "array", "(", ")", ";", "$", "lvl_row", "=", "array", "(", ")", ";", "$", "lvl_typ", "=", "array", "(", ")", ";", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "if", "(", "$", "row", "=", "trim", "(", "$", "row", ")", ")", "{", "$", "closespan", "=", "false", ";", "if", "(", "substr", "(", "$", "row", ",", "$", "offset", ",", "12", ")", "==", "'&lt;!-- END '", ")", "{", "if", "(", "$", "level", "<", "1", ")", "{", "$", "level", "++", ";", "$", "error", "[", "$", "rowcnt", "]", "=", "\"END Without BEGIN\"", ";", "}", "elseif", "(", "$", "lvl_typ", "[", "$", "level", "]", "!=", "'BEGIN'", ")", "{", "$", "error", "[", "$", "lvl_row", "[", "$", "level", "]", "]", "=", "\"IF without ENDIF\"", ";", "$", "error", "[", "$", "rowcnt", "]", "=", "\"END Without BEGIN\"", ";", "}", "$", "blocklvl", "--", ";", "$", "level", "--", ";", "$", "closespan", "=", "true", ";", "}", "if", "(", "substr", "(", "$", "row", ",", "$", "offset", ",", "14", ")", "==", "'&lt;!-- ENDIF '", ")", "{", "if", "(", "$", "level", "<", "1", ")", "{", "$", "level", "++", ";", "$", "error", "[", "$", "rowcnt", "]", "=", "\"ENDIF Without IF\"", ";", "}", "elseif", "(", "$", "lvl_typ", "[", "$", "level", "]", "!=", "'IF'", ")", "{", "$", "error", "[", "$", "lvl_row", "[", "$", "level", "]", "]", "=", "\"BEGIN without END\"", ";", "$", "error", "[", "$", "rowcnt", "]", "=", "\"ENDIF Without IF\"", ";", "}", "$", "closespan", "=", "true", ";", "$", "level", "--", ";", "}", "if", "(", "$", "closespan", ")", "{", "$", "page_arr", "[", "$", "rowcnt", "-", "1", "]", ".=", "'</span>'", ";", "}", "$", "this_row", "=", "$", "this", "->", "tab", "[", "$", "level", "]", ".", "$", "row", ";", "if", "(", "substr", "(", "$", "row", ",", "$", "offset", ",", "12", ")", "==", "'&lt;!-- ELSE'", ")", "{", "if", "(", "$", "level", "<", "1", ")", "{", "$", "error", "[", "$", "rowcnt", "]", "=", "\"ELSE Without IF\"", ";", "}", "elseif", "(", "$", "lvl_typ", "[", "$", "level", "]", "!=", "'IF'", ")", "{", "$", "error", "[", "$", "rowcnt", "]", "=", "\"ELSE Without IF\"", ";", "}", "else", "{", "$", "this_row", "=", "$", "this", "->", "tab", "[", "$", "level", "-", "1", "]", ".", "$", "row", ";", "}", "}", "if", "(", "substr", "(", "$", "row", ",", "$", "offset", ",", "14", ")", "==", "'&lt;!-- BEGIN '", ")", "{", "if", "(", "$", "blocklvl", "==", "0", ")", "{", "if", "(", "$", "lp", "=", "strpos", "(", "$", "row", ",", "'--&gt;'", ")", ")", "{", "if", "(", "$", "blockname", "=", "trim", "(", "substr", "(", "$", "row", ",", "$", "offset", "+", "14", ",", "$", "lp", "-", "$", "offset", "-", "14", ")", ")", ")", "{", "if", "(", "$", "nr", "=", "count", "(", "$", "vars", "[", "$", "blockname", "]", ")", ")", "{", "$", "this_row", ".=", "$", "this", "->", "toggleview", "(", "\"$nr Entries\"", ")", ";", "}", "else", "{", "$", "this_row", ".=", "$", "this", "->", "toggleview", "(", "\"Emtpy\"", ")", ";", "}", "}", "}", "}", "else", "{", "$", "this_row", ".=", "$", "this", "->", "toggleview", "(", "'['", ")", ";", "}", "$", "blocklvl", "++", ";", "$", "level", "++", ";", "$", "lvl_row", "[", "$", "level", "]", "=", "$", "rowcnt", ";", "$", "lvl_typ", "[", "$", "level", "]", "=", "'BEGIN'", ";", "}", "elseif", "(", "substr", "(", "$", "row", ",", "$", "offset", ",", "11", ")", "==", "'&lt;!-- IF '", ")", "{", "$", "level", "++", ";", "$", "lvl_row", "[", "$", "level", "]", "=", "$", "rowcnt", ";", "$", "lvl_typ", "[", "$", "level", "]", "=", "'IF'", ";", "$", "this_row", ".=", "$", "this", "->", "toggleview", "(", ")", ";", "}", "$", "page_arr", "[", "]", "=", "$", "this_row", ";", "$", "lvl_block", "[", "$", "rowcnt", "]", "=", "$", "blocklvl", ";", "$", "rowcnt", "++", ";", "}", "}", "if", "(", "$", "level", ">", "0", ")", "{", "$", "error", "[", "$", "lvl_row", "[", "$", "level", "]", "]", "=", "\"Block not closed\"", ";", "}", "$", "page", "=", "join", "(", "\"\\n\"", ",", "$", "page_arr", ")", ";", "$", "rows", "=", "explode", "(", "\"\\n\"", ",", "$", "page", ")", ";", "$", "cnt", "=", "count", "(", "$", "rows", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "cnt", ";", "$", "i", "++", ")", "{", "//\tAdd Errortext", "if", "(", "isset", "(", "$", "error", ")", ")", "{", "if", "(", "$", "err", "=", "$", "error", "[", "$", "i", "]", ")", "{", "$", "rows", "[", "$", "i", "]", "=", "'<b>'", ".", "$", "rows", "[", "$", "i", "]", ".", "' ERROR: '", ".", "$", "err", ".", "'!</b>'", ";", "}", "}", "//\tReplace Scalars", "if", "(", "preg_match_all", "(", "'/{([a-zA-Z0-9_. &;]+)}/'", ",", "$", "rows", "[", "$", "i", "]", ",", "$", "var", ")", ")", "{", "foreach", "(", "$", "var", "[", "1", "]", "as", "$", "tag", ")", "{", "$", "fulltag", "=", "$", "tag", ";", "if", "(", "$", "delim", "=", "strpos", "(", "$", "tag", ",", "' &gt; '", ")", ")", "{", "$", "tag", "=", "substr", "(", "$", "tag", ",", "0", ",", "$", "delim", ")", ";", "}", "if", "(", "substr", "(", "$", "tag", ",", "0", ",", "4", ")", "==", "'top.'", ")", "{", "$", "title", "=", "$", "this", "->", "tip", "(", "$", "vars", "[", "substr", "(", "$", "tag", ",", "4", ")", "]", ")", ";", "}", "elseif", "(", "$", "lvl_block", "[", "$", "i", "]", "==", "0", ")", "{", "$", "title", "=", "$", "this", "->", "tip", "(", "$", "vars", "[", "$", "tag", "]", ")", ";", "}", "else", "{", "$", "title", "=", "'[BLOCK?]'", ";", "}", "$", "code", "=", "'<b title=\"'", ".", "$", "title", ".", "'\">{'", ".", "$", "fulltag", ".", "'}</b>'", ";", "$", "rows", "[", "$", "i", "]", "=", "str_replace", "(", "'{'", ".", "$", "fulltag", ".", "'}'", ",", "$", "code", ",", "$", "rows", "[", "$", "i", "]", ")", ";", "}", "}", "//\tReplace Extensions", "if", "(", "preg_match_all", "(", "'/{([a-zA-Z0-9_]+):([^}]*)}/'", ",", "$", "rows", "[", "$", "i", "]", ",", "$", "var", ")", ")", "{", "foreach", "(", "$", "var", "[", "2", "]", "as", "$", "tmpcnt", "=>", "$", "tag", ")", "{", "$", "fulltag", "=", "$", "tag", ";", "if", "(", "$", "delim", "=", "strpos", "(", "$", "tag", ",", "' &gt; '", ")", ")", "{", "$", "tag", "=", "substr", "(", "$", "tag", ",", "0", ",", "$", "delim", ")", ";", "}", "if", "(", "strpos", "(", "$", "tag", ",", "','", ")", ")", "{", "list", "(", "$", "tag", ",", "$", "addparam", ")", "=", "explode", "(", "','", ",", "$", "tag", ",", "2", ")", ";", "}", "$", "extension", "=", "$", "var", "[", "1", "]", "[", "$", "tmpcnt", "]", ";", "if", "(", "substr", "(", "$", "tag", ",", "0", ",", "4", ")", "==", "'top.'", ")", "{", "$", "title", "=", "$", "this", "->", "tip", "(", "$", "vars", "[", "substr", "(", "$", "tag", ",", "4", ")", "]", ")", ";", "}", "elseif", "(", "$", "lvl_block", "[", "$", "i", "]", "==", "0", ")", "{", "$", "title", "=", "$", "this", "->", "tip", "(", "$", "vars", "[", "$", "tag", "]", ")", ";", "}", "else", "{", "$", "title", "=", "'[BLOCK?]'", ";", "}", "$", "code", "=", "'<b title=\"'", ".", "$", "title", ".", "'\">{'", ".", "$", "extension", ".", "':'", ".", "$", "fulltag", ".", "'}</b>'", ";", "$", "rows", "[", "$", "i", "]", "=", "str_replace", "(", "'{'", ".", "$", "extension", ".", "':'", ".", "$", "fulltag", ".", "'}'", ",", "$", "code", ",", "$", "rows", "[", "$", "i", "]", ")", ";", "}", "}", "//\t'IF nnn' Blocks", "if", "(", "preg_match_all", "(", "'/&lt;!-- IF ([a-zA-Z0-9_.]+) --&gt;/'", ",", "$", "rows", "[", "$", "i", "]", ",", "$", "var", ")", ")", "{", "foreach", "(", "$", "var", "[", "1", "]", "as", "$", "tag", ")", "{", "if", "(", "substr", "(", "$", "tag", ",", "0", ",", "4", ")", "==", "'top.'", ")", "{", "$", "title", "=", "$", "this", "->", "tip", "(", "$", "vars", "[", "substr", "(", "$", "tag", ",", "4", ")", "]", ")", ";", "}", "elseif", "(", "$", "lvl_block", "[", "$", "i", "]", "==", "0", ")", "{", "$", "title", "=", "$", "this", "->", "tip", "(", "$", "vars", "[", "$", "tag", "]", ")", ";", "}", "else", "{", "$", "title", "=", "'[BLOCK?]'", ";", "}", "$", "code", "=", "'<span title=\"'", ".", "$", "title", ".", "'\">&lt;!-- IF '", ".", "$", "tag", ".", "' --&gt;</span>'", ";", "$", "rows", "[", "$", "i", "]", "=", "str_replace", "(", "\"&lt;!-- IF $tag --&gt;\"", ",", "$", "code", ",", "$", "rows", "[", "$", "i", "]", ")", ";", "if", "(", "$", "title", "==", "'[NULL]'", ")", "{", "$", "rows", "[", "$", "i", "]", "=", "str_replace", "(", "'Hide'", ",", "'Show'", ",", "$", "rows", "[", "$", "i", "]", ")", ";", "$", "rows", "[", "$", "i", "]", "=", "str_replace", "(", "'block'", ",", "'none'", ",", "$", "rows", "[", "$", "i", "]", ")", ";", "}", "}", "}", "}", "$", "page", "=", "join", "(", "\"<br>\"", ",", "$", "rows", ")", ";", "// Print Header", "echo", "'<html><head><script type=\"text/javascript\">\n\t\t\t\t\tfunction toggleVisibility(el, src) {\n\t\t\t\t\tvar v = el.style.display == \"block\";\n\t\t\t\t\tvar str = src.innerHTML;\n\t\t\t\t\tel.style.display = v ? \"none\" : \"block\";\n\t\t\t\t\tsrc.innerHTML = v ? str.replace(/Hide/, \"Show\") : str.replace(/Show/, \"Hide\");}\n\t\t\t\t\t</script></head><body>'", ";", "// Print Index", "echo", "'<font face=\"Arial\" Size=\"3\"><b>'", ";", "echo", "'SmartTemplate Debugger<br>'", ";", "echo", "'<font size=\"2\"><li>PHP-Script: '", ".", "$", "_SERVER", "[", "'PATH_TRANSLATED'", "]", ".", "'</li><li>Template: '", ".", "$", "this", "->", "filename", ".", "'</li></font><hr>'", ";", "echo", "'<li><a href=\"#template_code\">Template</a></li>'", ";", "echo", "'<li><a href=\"#compiled_code\">Compiled Template</a></li>'", ";", "echo", "'<li><a href=\"#data_code\">Data</a></li>'", ";", "echo", "'</b></font><hr>'", ";", "// Print Template", "echo", "'<a name=\"template_code\"><br><font face=\"Arial\" Size=\"3\"><b>Template:</b>&nbsp;[<a href=\"javascript:void(\\'\\');\" onclick=\"toggleVisibility(document.getElementById(\\'Template\\'), this); return false\">Hide Ouptut</a>]</font><br>'", ";", "echo", "'<table border=\"0\" cellpadding=\"4\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#C6D3EF\"><tr><td bgcolor=\"#F0F0F0\"><pre id=\"Template\" style=\"display:block\">'", ";", "echo", "$", "page", ";", "echo", "'</pre></td></tr></table>'", ";", "// Print Compiled Template", "if", "(", "@", "include_once", "(", "\"class.smarttemplateparser.php\"", ")", ")", "{", "$", "parser", "=", "new", "SmartTemplateParser", "(", "$", "this", "->", "filename", ")", ";", "$", "compiled", "=", "$", "parser", "->", "compile", "(", ")", ";", "echo", "'<a name=\"compiled_code\"><br><br><font face=\"Arial\" Size=\"3\"><b>Compiled Template:</b>&nbsp;[<a href=\"javascript:void(\\'\\');\" onclick=\"toggleVisibility(document.getElementById(\\'Compiled\\'), this); return false\">Hide Ouptut</a>]</font><br>'", ";", "echo", "'<table border=\"0\" cellpadding=\"4\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#C6D3EF\"><tr><td bgcolor=\"#F0F0F0\"><pre id=\"Compiled\" style=\"display:block\">'", ";", "highlight_string", "(", "$", "compiled", ")", ";", "echo", "'</pre></td></tr></table>'", ";", "}", "else", "{", "exit", "(", "\"SmartTemplate Error: Cannot find class.smarttemplateparser.php; check SmartTemplate installation\"", ")", ";", "}", "// Print Data", "echo", "'<a name=\"data_code\"><br><br><font face=\"Arial\" Size=\"3\"><b>Data:</b>&nbsp;[<a href=\"javascript:void(\\'\\');\" onclick=\"toggleVisibility(document.getElementById(\\'Data\\'), this); return false\">Hide Ouptut</a>]</font><br>'", ";", "echo", "'<table border=\"0\" cellpadding=\"4\" cellspacing=\"1\" width=\"100%\" bgcolor=\"#C6D3EF\"><tr><td bgcolor=\"#F0F0F0\"><pre id=\"Data\" style=\"display:block\">'", ";", "echo", "$", "this", "->", "vardump", "(", "$", "vars", ")", ";", "echo", "'</pre></td></tr></table></body></html>'", ";", "}" ]
Main Template Parser @param string $compiled_template_filename Compiled Template Filename @desc Creates Compiled PHP Template
[ "Main", "Template", "Parser" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php#L61-L332
KDF5000/EasyThink
src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php
SmartTemplateDebugger.toggleview
function toggleview ( $suffix = '') { global $spancnt; $spancnt++; if ($suffix) { $suffix .= ':'; } $ret = '[' . $suffix . '<a href="javascript:void(\'\');" onclick="toggleVisibility(document.getElementById(\'Block' . $spancnt . '\'), this); return false">Hide Block</a>]<span id="Block' . $spancnt . '" style="display:block">'; return $ret; }
php
function toggleview ( $suffix = '') { global $spancnt; $spancnt++; if ($suffix) { $suffix .= ':'; } $ret = '[' . $suffix . '<a href="javascript:void(\'\');" onclick="toggleVisibility(document.getElementById(\'Block' . $spancnt . '\'), this); return false">Hide Block</a>]<span id="Block' . $spancnt . '" style="display:block">'; return $ret; }
[ "function", "toggleview", "(", "$", "suffix", "=", "''", ")", "{", "global", "$", "spancnt", ";", "$", "spancnt", "++", ";", "if", "(", "$", "suffix", ")", "{", "$", "suffix", ".=", "':'", ";", "}", "$", "ret", "=", "'['", ".", "$", "suffix", ".", "'<a href=\"javascript:void(\\'\\');\" onclick=\"toggleVisibility(document.getElementById(\\'Block'", ".", "$", "spancnt", ".", "'\\'), this); return false\">Hide Block</a>]<span id=\"Block'", ".", "$", "spancnt", ".", "'\" style=\"display:block\">'", ";", "return", "$", "ret", ";", "}" ]
Insert Hide/Show Layer Switch @param string $suffix Additional Text @desc Insert Hide/Show Layer Switch
[ "Insert", "Hide", "/", "Show", "Layer", "Switch" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php#L341-L352
KDF5000/EasyThink
src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php
SmartTemplateDebugger.vardump
function vardump($var, $depth = 0) { if (is_array($var)) { $result = "Array (" . count($var) . ")<BR>"; foreach(array_keys($var) as $key) { $result .= $this->tab[$depth] . "<B>$key</B>: " . $this->vardump($var[$key], $depth+1); } return $result; } else { $ret = htmlentities($var) . "<BR>"; return $ret; } }
php
function vardump($var, $depth = 0) { if (is_array($var)) { $result = "Array (" . count($var) . ")<BR>"; foreach(array_keys($var) as $key) { $result .= $this->tab[$depth] . "<B>$key</B>: " . $this->vardump($var[$key], $depth+1); } return $result; } else { $ret = htmlentities($var) . "<BR>"; return $ret; } }
[ "function", "vardump", "(", "$", "var", ",", "$", "depth", "=", "0", ")", "{", "if", "(", "is_array", "(", "$", "var", ")", ")", "{", "$", "result", "=", "\"Array (\"", ".", "count", "(", "$", "var", ")", ".", "\")<BR>\"", ";", "foreach", "(", "array_keys", "(", "$", "var", ")", "as", "$", "key", ")", "{", "$", "result", ".=", "$", "this", "->", "tab", "[", "$", "depth", "]", ".", "\"<B>$key</B>: \"", ".", "$", "this", "->", "vardump", "(", "$", "var", "[", "$", "key", "]", ",", "$", "depth", "+", "1", ")", ";", "}", "return", "$", "result", ";", "}", "else", "{", "$", "ret", "=", "htmlentities", "(", "$", "var", ")", ".", "\"<BR>\"", ";", "return", "$", "ret", ";", "}", "}" ]
Recursive Variable Display Output @param mixed $var Content @param int $depth Incremented Indent Counter for Recursive Calls @return string Variable Content @access private @desc Recursive Variable Display Output
[ "Recursive", "Variable", "Display", "Output" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php#L384-L400
KDF5000/EasyThink
src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php
SmartTemplateDebugger.var_name
function var_name($tag) { $parent_level = 0; while (substr($tag, 0, 7) == 'parent.') { $tag = substr($tag, 7); $parent_level++; } if (substr($tag, 0, 4) == 'top.') { $ret = array('_stack[0]', substr($tag,4)); return $ret; } elseif ($parent_level) { $ret = array('_stack[$_stack_cnt-'.$parent_level.']', $tag); return $ret; } else { $ret = array('_obj', $tag); return $ret; } }
php
function var_name($tag) { $parent_level = 0; while (substr($tag, 0, 7) == 'parent.') { $tag = substr($tag, 7); $parent_level++; } if (substr($tag, 0, 4) == 'top.') { $ret = array('_stack[0]', substr($tag,4)); return $ret; } elseif ($parent_level) { $ret = array('_stack[$_stack_cnt-'.$parent_level.']', $tag); return $ret; } else { $ret = array('_obj', $tag); return $ret; } }
[ "function", "var_name", "(", "$", "tag", ")", "{", "$", "parent_level", "=", "0", ";", "while", "(", "substr", "(", "$", "tag", ",", "0", ",", "7", ")", "==", "'parent.'", ")", "{", "$", "tag", "=", "substr", "(", "$", "tag", ",", "7", ")", ";", "$", "parent_level", "++", ";", "}", "if", "(", "substr", "(", "$", "tag", ",", "0", ",", "4", ")", "==", "'top.'", ")", "{", "$", "ret", "=", "array", "(", "'_stack[0]'", ",", "substr", "(", "$", "tag", ",", "4", ")", ")", ";", "return", "$", "ret", ";", "}", "elseif", "(", "$", "parent_level", ")", "{", "$", "ret", "=", "array", "(", "'_stack[$_stack_cnt-'", ".", "$", "parent_level", ".", "']'", ",", "$", "tag", ")", ";", "return", "$", "ret", ";", "}", "else", "{", "$", "ret", "=", "array", "(", "'_obj'", ",", "$", "tag", ")", ";", "return", "$", "ret", ";", "}", "}" ]
Splits Template-Style Variable Names into an Array-Name/Key-Name Components @param string $tag Variale Name used in Template @return array Array Name, Key Name @access private @desc Splits Template-Style Variable Names into an Array-Name/Key-Name Components
[ "Splits", "Template", "-", "Style", "Variable", "Names", "into", "an", "Array", "-", "Name", "/", "Key", "-", "Name", "Components" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php#L411-L434
KDF5000/EasyThink
src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php
SmartTemplateDebugger.highlight_html
function highlight_html ( $code ) { $code = htmlentities($code); $code = preg_replace('/([a-zA-Z_]+)=/', '<font color="#FF0000">$1=</font>', $code); $code = preg_replace('/(&lt;[\/a-zA-Z0-9&;]+)/', '<font color="#0000FF">$1</font>', $code); $code = str_replace('&lt;!--', '<font color="#008080">&lt;!--', $code); $code = str_replace('--&gt;', '--&gt;</font>', $code); $code = preg_replace('/[\r\n]+/', "\n", $code); return $code; }
php
function highlight_html ( $code ) { $code = htmlentities($code); $code = preg_replace('/([a-zA-Z_]+)=/', '<font color="#FF0000">$1=</font>', $code); $code = preg_replace('/(&lt;[\/a-zA-Z0-9&;]+)/', '<font color="#0000FF">$1</font>', $code); $code = str_replace('&lt;!--', '<font color="#008080">&lt;!--', $code); $code = str_replace('--&gt;', '--&gt;</font>', $code); $code = preg_replace('/[\r\n]+/', "\n", $code); return $code; }
[ "function", "highlight_html", "(", "$", "code", ")", "{", "$", "code", "=", "htmlentities", "(", "$", "code", ")", ";", "$", "code", "=", "preg_replace", "(", "'/([a-zA-Z_]+)=/'", ",", "'<font color=\"#FF0000\">$1=</font>'", ",", "$", "code", ")", ";", "$", "code", "=", "preg_replace", "(", "'/(&lt;[\\/a-zA-Z0-9&;]+)/'", ",", "'<font color=\"#0000FF\">$1</font>'", ",", "$", "code", ")", ";", "$", "code", "=", "str_replace", "(", "'&lt;!--'", ",", "'<font color=\"#008080\">&lt;!--'", ",", "$", "code", ")", ";", "$", "code", "=", "str_replace", "(", "'--&gt;'", ",", "'--&gt;</font>'", ",", "$", "code", ")", ";", "$", "code", "=", "preg_replace", "(", "'/[\\r\\n]+/'", ",", "\"\\n\"", ",", "$", "code", ")", ";", "return", "$", "code", ";", "}" ]
Highlight HTML Source @param string $code HTML Source @return string Hightlighte HTML Source @access private @desc Highlight HTML Source
[ "Highlight", "HTML", "Source" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php#L445-L454
qingbing/php-database
src/supports/ColumnSchema.php
ColumnSchema.extractLimit
protected function extractLimit($dbType) { if (0 === strncmp($dbType, 'enum', 4) && preg_match('/\(([\'"])(.*)\\1\)/', $dbType, $matches)) { // explode by (single or double) quote and comma (ENUM values may contain commas) $values = explode($matches[1] . ',' . $matches[1], $matches[2]); $size = 0; foreach ($values as $value) { if (($n = strlen($value)) > $size) { $size = $n; } } $this->size = $this->precision = $size; } else { if (strpos($dbType, '(') && preg_match('/\((.*)\)/', $dbType, $matches)) { $values = explode(',', $matches[1]); $this->size = $this->precision = (int)$values[0]; if (isset($values[1])) { $this->scale = (int)$values[1]; } } } }
php
protected function extractLimit($dbType) { if (0 === strncmp($dbType, 'enum', 4) && preg_match('/\(([\'"])(.*)\\1\)/', $dbType, $matches)) { // explode by (single or double) quote and comma (ENUM values may contain commas) $values = explode($matches[1] . ',' . $matches[1], $matches[2]); $size = 0; foreach ($values as $value) { if (($n = strlen($value)) > $size) { $size = $n; } } $this->size = $this->precision = $size; } else { if (strpos($dbType, '(') && preg_match('/\((.*)\)/', $dbType, $matches)) { $values = explode(',', $matches[1]); $this->size = $this->precision = (int)$values[0]; if (isset($values[1])) { $this->scale = (int)$values[1]; } } } }
[ "protected", "function", "extractLimit", "(", "$", "dbType", ")", "{", "if", "(", "0", "===", "strncmp", "(", "$", "dbType", ",", "'enum'", ",", "4", ")", "&&", "preg_match", "(", "'/\\(([\\'\"])(.*)\\\\1\\)/'", ",", "$", "dbType", ",", "$", "matches", ")", ")", "{", "// explode by (single or double) quote and comma (ENUM values may contain commas)\r", "$", "values", "=", "explode", "(", "$", "matches", "[", "1", "]", ".", "','", ".", "$", "matches", "[", "1", "]", ",", "$", "matches", "[", "2", "]", ")", ";", "$", "size", "=", "0", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "(", "$", "n", "=", "strlen", "(", "$", "value", ")", ")", ">", "$", "size", ")", "{", "$", "size", "=", "$", "n", ";", "}", "}", "$", "this", "->", "size", "=", "$", "this", "->", "precision", "=", "$", "size", ";", "}", "else", "{", "if", "(", "strpos", "(", "$", "dbType", ",", "'('", ")", "&&", "preg_match", "(", "'/\\((.*)\\)/'", ",", "$", "dbType", ",", "$", "matches", ")", ")", "{", "$", "values", "=", "explode", "(", "','", ",", "$", "matches", "[", "1", "]", ")", ";", "$", "this", "->", "size", "=", "$", "this", "->", "precision", "=", "(", "int", ")", "$", "values", "[", "0", "]", ";", "if", "(", "isset", "(", "$", "values", "[", "1", "]", ")", ")", "{", "$", "this", "->", "scale", "=", "(", "int", ")", "$", "values", "[", "1", "]", ";", "}", "}", "}", "}" ]
从列的数据库类型中提取大小、精度、标度信息 @param string $dbType
[ "从列的数据库类型中提取大小、精度、标度信息" ]
train
https://github.com/qingbing/php-database/blob/cfd915c9d25dbe5d5cdd9b4c93eca5fd63cb7015/src/supports/ColumnSchema.php#L82-L103
spryker/shopping-list-data-import
src/Spryker/Zed/ShoppingListDataImport/Business/ShoppingListDataImportStep/ShoppingListItemWriterStep.php
ShoppingListItemWriterStep.execute
public function execute(DataSetInterface $dataSet): void { $shoppingListItemEntity = $this->createShoppingListItemQuery() ->filterByFkShoppingList($dataSet[ShoppingListItemDataSetInterface::ID_SHOPPING_LIST]) ->filterBySku($dataSet[ShoppingListItemDataSetInterface::COLUMN_PRODUCT_SKU]) ->findOneOrCreate(); $shoppingListItemEntity ->setQuantity($dataSet[ShoppingListItemDataSetInterface::COLUMN_QUANTITY]) ->save(); }
php
public function execute(DataSetInterface $dataSet): void { $shoppingListItemEntity = $this->createShoppingListItemQuery() ->filterByFkShoppingList($dataSet[ShoppingListItemDataSetInterface::ID_SHOPPING_LIST]) ->filterBySku($dataSet[ShoppingListItemDataSetInterface::COLUMN_PRODUCT_SKU]) ->findOneOrCreate(); $shoppingListItemEntity ->setQuantity($dataSet[ShoppingListItemDataSetInterface::COLUMN_QUANTITY]) ->save(); }
[ "public", "function", "execute", "(", "DataSetInterface", "$", "dataSet", ")", ":", "void", "{", "$", "shoppingListItemEntity", "=", "$", "this", "->", "createShoppingListItemQuery", "(", ")", "->", "filterByFkShoppingList", "(", "$", "dataSet", "[", "ShoppingListItemDataSetInterface", "::", "ID_SHOPPING_LIST", "]", ")", "->", "filterBySku", "(", "$", "dataSet", "[", "ShoppingListItemDataSetInterface", "::", "COLUMN_PRODUCT_SKU", "]", ")", "->", "findOneOrCreate", "(", ")", ";", "$", "shoppingListItemEntity", "->", "setQuantity", "(", "$", "dataSet", "[", "ShoppingListItemDataSetInterface", "::", "COLUMN_QUANTITY", "]", ")", "->", "save", "(", ")", ";", "}" ]
@param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet @return void
[ "@param", "\\", "Spryker", "\\", "Zed", "\\", "DataImport", "\\", "Business", "\\", "Model", "\\", "DataSet", "\\", "DataSetInterface", "$dataSet" ]
train
https://github.com/spryker/shopping-list-data-import/blob/6313fc39e8ee79a08f7b97d81da7f4056c066674/src/Spryker/Zed/ShoppingListDataImport/Business/ShoppingListDataImportStep/ShoppingListItemWriterStep.php#L22-L32
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Controller/RestController.php
RestController.getAcceptType
protected function getAcceptType(){ $type = array( 'xml' => 'application/xml,text/xml,application/x-xml', 'json' => 'application/json,text/x-json,application/jsonrequest,text/json', 'js' => 'text/javascript,application/javascript,application/x-javascript', 'css' => 'text/css', 'rss' => 'application/rss+xml', 'yaml' => 'application/x-yaml,text/yaml', 'atom' => 'application/atom+xml', 'pdf' => 'application/pdf', 'text' => 'text/plain', 'png' => 'image/png', 'jpg' => 'image/jpg,image/jpeg,image/pjpeg', 'gif' => 'image/gif', 'csv' => 'text/csv', 'html' => 'text/html,application/xhtml+xml,*/*' ); foreach($type as $key=>$val){ $array = explode(',',$val); foreach($array as $k=>$v){ if(stristr($_SERVER['HTTP_ACCEPT'], $v)) { return $key; } } } return false; }
php
protected function getAcceptType(){ $type = array( 'xml' => 'application/xml,text/xml,application/x-xml', 'json' => 'application/json,text/x-json,application/jsonrequest,text/json', 'js' => 'text/javascript,application/javascript,application/x-javascript', 'css' => 'text/css', 'rss' => 'application/rss+xml', 'yaml' => 'application/x-yaml,text/yaml', 'atom' => 'application/atom+xml', 'pdf' => 'application/pdf', 'text' => 'text/plain', 'png' => 'image/png', 'jpg' => 'image/jpg,image/jpeg,image/pjpeg', 'gif' => 'image/gif', 'csv' => 'text/csv', 'html' => 'text/html,application/xhtml+xml,*/*' ); foreach($type as $key=>$val){ $array = explode(',',$val); foreach($array as $k=>$v){ if(stristr($_SERVER['HTTP_ACCEPT'], $v)) { return $key; } } } return false; }
[ "protected", "function", "getAcceptType", "(", ")", "{", "$", "type", "=", "array", "(", "'xml'", "=>", "'application/xml,text/xml,application/x-xml'", ",", "'json'", "=>", "'application/json,text/x-json,application/jsonrequest,text/json'", ",", "'js'", "=>", "'text/javascript,application/javascript,application/x-javascript'", ",", "'css'", "=>", "'text/css'", ",", "'rss'", "=>", "'application/rss+xml'", ",", "'yaml'", "=>", "'application/x-yaml,text/yaml'", ",", "'atom'", "=>", "'application/atom+xml'", ",", "'pdf'", "=>", "'application/pdf'", ",", "'text'", "=>", "'text/plain'", ",", "'png'", "=>", "'image/png'", ",", "'jpg'", "=>", "'image/jpg,image/jpeg,image/pjpeg'", ",", "'gif'", "=>", "'image/gif'", ",", "'csv'", "=>", "'text/csv'", ",", "'html'", "=>", "'text/html,application/xhtml+xml,*/*'", ")", ";", "foreach", "(", "$", "type", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "array", "=", "explode", "(", "','", ",", "$", "val", ")", ";", "foreach", "(", "$", "array", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "stristr", "(", "$", "_SERVER", "[", "'HTTP_ACCEPT'", "]", ",", "$", "v", ")", ")", "{", "return", "$", "key", ";", "}", "}", "}", "return", "false", ";", "}" ]
获取当前请求的Accept头信息 @return string
[ "获取当前请求的Accept头信息" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Controller/RestController.php#L97-L124
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Controller/RestController.php
RestController.setContentType
public function setContentType($type, $charset=''){ if(headers_sent()) return; if(empty($charset)) $charset = C('DEFAULT_CHARSET'); $type = strtolower($type); if(isset($this->allowOutputType[$type])) //过滤content_type header('Content-Type: '.$this->allowOutputType[$type].'; charset='.$charset); }
php
public function setContentType($type, $charset=''){ if(headers_sent()) return; if(empty($charset)) $charset = C('DEFAULT_CHARSET'); $type = strtolower($type); if(isset($this->allowOutputType[$type])) //过滤content_type header('Content-Type: '.$this->allowOutputType[$type].'; charset='.$charset); }
[ "public", "function", "setContentType", "(", "$", "type", ",", "$", "charset", "=", "''", ")", "{", "if", "(", "headers_sent", "(", ")", ")", "return", ";", "if", "(", "empty", "(", "$", "charset", ")", ")", "$", "charset", "=", "C", "(", "'DEFAULT_CHARSET'", ")", ";", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "allowOutputType", "[", "$", "type", "]", ")", ")", "//过滤content_type", "header", "(", "'Content-Type: '", ".", "$", "this", "->", "allowOutputType", "[", "$", "type", "]", ".", "'; charset='", ".", "$", "charset", ")", ";", "}" ]
设置页面输出的CONTENT_TYPE和编码 @access public @param string $type content_type 类型对应的扩展名 @param string $charset 页面输出编码 @return void
[ "设置页面输出的CONTENT_TYPE和编码" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Controller/RestController.php#L214-L220
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Controller/RestController.php
RestController.response
protected function response($data,$type='',$code=200) { $this->sendHttpStatus($code); exit($this->encodeData($data,strtolower($type))); }
php
protected function response($data,$type='',$code=200) { $this->sendHttpStatus($code); exit($this->encodeData($data,strtolower($type))); }
[ "protected", "function", "response", "(", "$", "data", ",", "$", "type", "=", "''", ",", "$", "code", "=", "200", ")", "{", "$", "this", "->", "sendHttpStatus", "(", "$", "code", ")", ";", "exit", "(", "$", "this", "->", "encodeData", "(", "$", "data", ",", "strtolower", "(", "$", "type", ")", ")", ")", ";", "}" ]
输出返回数据 @access protected @param mixed $data 要返回的数据 @param String $type 返回类型 JSON XML @param integer $code HTTP状态 @return void
[ "输出返回数据" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Controller/RestController.php#L230-L233
ndavison/groundwork-framework
src/Groundwork/Classes/Response.php
Response.send
public function send($code, $body = '') { if (!isset($this->codes[$code])) { $statusCode = 500; $body = 'API attempted to return an unknown HTTP status.'; } // if the body wasn't defined, default to the inbuilt response if (!$body) $body = $this->codes[$code]; header('HTTP/1.1 ' . $code . ' ' . $this->codes[$code]); header('Content-type: application/json'); echo json_encode($body); exit; }
php
public function send($code, $body = '') { if (!isset($this->codes[$code])) { $statusCode = 500; $body = 'API attempted to return an unknown HTTP status.'; } // if the body wasn't defined, default to the inbuilt response if (!$body) $body = $this->codes[$code]; header('HTTP/1.1 ' . $code . ' ' . $this->codes[$code]); header('Content-type: application/json'); echo json_encode($body); exit; }
[ "public", "function", "send", "(", "$", "code", ",", "$", "body", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "codes", "[", "$", "code", "]", ")", ")", "{", "$", "statusCode", "=", "500", ";", "$", "body", "=", "'API attempted to return an unknown HTTP status.'", ";", "}", "// if the body wasn't defined, default to the inbuilt response", "if", "(", "!", "$", "body", ")", "$", "body", "=", "$", "this", "->", "codes", "[", "$", "code", "]", ";", "header", "(", "'HTTP/1.1 '", ".", "$", "code", ".", "' '", ".", "$", "this", "->", "codes", "[", "$", "code", "]", ")", ";", "header", "(", "'Content-type: application/json'", ")", ";", "echo", "json_encode", "(", "$", "body", ")", ";", "exit", ";", "}" ]
Output a JSON formatted response of the supplied body param, along with the supplied code param as the HTTP status code. @param int $code @param mixed $body
[ "Output", "a", "JSON", "formatted", "response", "of", "the", "supplied", "body", "param", "along", "with", "the", "supplied", "code", "param", "as", "the", "HTTP", "status", "code", "." ]
train
https://github.com/ndavison/groundwork-framework/blob/c3d22a1410c8d8a07b4ca1f99a35a1181516cd6c/src/Groundwork/Classes/Response.php#L46-L58
praxigento/mobi_mod_pv
Plugin/Magento/Sales/Model/ResourceModel/Order/Collection.php
Collection.aroundAddFieldToSelect
public function aroundAddFieldToSelect( \Magento\Sales\Model\ResourceModel\Order\Collection $subject, \Closure $proceed, $field, $alias = null ) { /** @var \Magento\Sales\Model\ResourceModel\Order\Collection $result */ $result = $proceed($field, $alias); if ($field == '*') { $query = $result->getSelect(); $this->queryAddPv($query); } return $result; }
php
public function aroundAddFieldToSelect( \Magento\Sales\Model\ResourceModel\Order\Collection $subject, \Closure $proceed, $field, $alias = null ) { /** @var \Magento\Sales\Model\ResourceModel\Order\Collection $result */ $result = $proceed($field, $alias); if ($field == '*') { $query = $result->getSelect(); $this->queryAddPv($query); } return $result; }
[ "public", "function", "aroundAddFieldToSelect", "(", "\\", "Magento", "\\", "Sales", "\\", "Model", "\\", "ResourceModel", "\\", "Order", "\\", "Collection", "$", "subject", ",", "\\", "Closure", "$", "proceed", ",", "$", "field", ",", "$", "alias", "=", "null", ")", "{", "/** @var \\Magento\\Sales\\Model\\ResourceModel\\Order\\Collection $result */", "$", "result", "=", "$", "proceed", "(", "$", "field", ",", "$", "alias", ")", ";", "if", "(", "$", "field", "==", "'*'", ")", "{", "$", "query", "=", "$", "result", "->", "getSelect", "(", ")", ";", "$", "this", "->", "queryAddPv", "(", "$", "query", ")", ";", "}", "return", "$", "result", ";", "}" ]
Add PV data to sales orders collection when all fields are added ('*'). Method 'addFieldToSelect' is called from method 'addAttributeToSelect'. @param \Magento\Sales\Model\ResourceModel\Order\Collection $subject @param \Closure $proceed @param $field @param null $alias @return \Magento\Sales\Model\ResourceModel\Order\Collection @throws \Zend_Db_Select_Exception
[ "Add", "PV", "data", "to", "sales", "orders", "collection", "when", "all", "fields", "are", "added", "(", "*", ")", "." ]
train
https://github.com/praxigento/mobi_mod_pv/blob/d1540b7e94264527006e8b9fa68904a72a63928e/Plugin/Magento/Sales/Model/ResourceModel/Order/Collection.php#L38-L51
praxigento/mobi_mod_pv
Plugin/Magento/Sales/Model/ResourceModel/Order/Collection.php
Collection.queryAddPv
private function queryAddPv($query) { $asSales = $this->getAliasForMainTable($query); if ($asSales) { /* there is 'sales_order' table - we can JOIN our tables to get PV */ $tbl = $this->resource->getTableName(EPvSale::ENTITY_NAME); $as = self::AS_PV_SALE; $cols = [ DPvSales::A_PV_SUBTOTAL => EPvSale::A_SUBTOTAL, DPvSales::A_PV_DISCOUNT => EPvSale::A_DISCOUNT, DPvSales::A_PV_GRAND => EPvSale::A_TOTAL, ]; $cond = "$as." . EPvSale::A_SALE_REF . "=$asSales." . Cfg::E_SALE_ORDER_A_ENTITY_ID; $query->joinLeft([$as => $tbl], $cond, $cols); } }
php
private function queryAddPv($query) { $asSales = $this->getAliasForMainTable($query); if ($asSales) { /* there is 'sales_order' table - we can JOIN our tables to get PV */ $tbl = $this->resource->getTableName(EPvSale::ENTITY_NAME); $as = self::AS_PV_SALE; $cols = [ DPvSales::A_PV_SUBTOTAL => EPvSale::A_SUBTOTAL, DPvSales::A_PV_DISCOUNT => EPvSale::A_DISCOUNT, DPvSales::A_PV_GRAND => EPvSale::A_TOTAL, ]; $cond = "$as." . EPvSale::A_SALE_REF . "=$asSales." . Cfg::E_SALE_ORDER_A_ENTITY_ID; $query->joinLeft([$as => $tbl], $cond, $cols); } }
[ "private", "function", "queryAddPv", "(", "$", "query", ")", "{", "$", "asSales", "=", "$", "this", "->", "getAliasForMainTable", "(", "$", "query", ")", ";", "if", "(", "$", "asSales", ")", "{", "/* there is 'sales_order' table - we can JOIN our tables to get PV */", "$", "tbl", "=", "$", "this", "->", "resource", "->", "getTableName", "(", "EPvSale", "::", "ENTITY_NAME", ")", ";", "$", "as", "=", "self", "::", "AS_PV_SALE", ";", "$", "cols", "=", "[", "DPvSales", "::", "A_PV_SUBTOTAL", "=>", "EPvSale", "::", "A_SUBTOTAL", ",", "DPvSales", "::", "A_PV_DISCOUNT", "=>", "EPvSale", "::", "A_DISCOUNT", ",", "DPvSales", "::", "A_PV_GRAND", "=>", "EPvSale", "::", "A_TOTAL", ",", "]", ";", "$", "cond", "=", "\"$as.\"", ".", "EPvSale", "::", "A_SALE_REF", ".", "\"=$asSales.\"", ".", "Cfg", "::", "E_SALE_ORDER_A_ENTITY_ID", ";", "$", "query", "->", "joinLeft", "(", "[", "$", "as", "=>", "$", "tbl", "]", ",", "$", "cond", ",", "$", "cols", ")", ";", "}", "}" ]
Add PV to original query. @param $query @throws \Zend_Db_Select_Exception
[ "Add", "PV", "to", "original", "query", "." ]
train
https://github.com/praxigento/mobi_mod_pv/blob/d1540b7e94264527006e8b9fa68904a72a63928e/Plugin/Magento/Sales/Model/ResourceModel/Order/Collection.php#L81-L96
benjamindulau/BarbeQ
src/BarbeQ/Adapter/PDOAdapter.php
PdoAdapter.publish
public function publish($queue, MessageInterface $message) { $sql = 'INSERT INTO %s (%s, %s, %s, %s, %s)' . ' VALUES (:body, :queue, :state, :priority, :metadata)'; $sql = sprintf($sql, $this->dbOptions['table'], $this->dbOptions['body'], $this->dbOptions['queue'], $this->dbOptions['state'], $this->dbOptions['priority'], $this->dbOptions['metadata'] ); $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':body', serialize($message->getBody()), \PDO::PARAM_STR); $stmt->bindParam(':queue', $message->getQueue(), \PDO::PARAM_STR); $stmt->bindParam(':state', $message->getState(), \PDO::PARAM_INT); $stmt->bindParam(':priority', $message->getPriority(), \PDO::PARAM_INT); $stmt->bindParam(':metadata', serialize($message->getMetadata()), \PDO::PARAM_STR); $stmt->execute(); return true; }
php
public function publish($queue, MessageInterface $message) { $sql = 'INSERT INTO %s (%s, %s, %s, %s, %s)' . ' VALUES (:body, :queue, :state, :priority, :metadata)'; $sql = sprintf($sql, $this->dbOptions['table'], $this->dbOptions['body'], $this->dbOptions['queue'], $this->dbOptions['state'], $this->dbOptions['priority'], $this->dbOptions['metadata'] ); $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':body', serialize($message->getBody()), \PDO::PARAM_STR); $stmt->bindParam(':queue', $message->getQueue(), \PDO::PARAM_STR); $stmt->bindParam(':state', $message->getState(), \PDO::PARAM_INT); $stmt->bindParam(':priority', $message->getPriority(), \PDO::PARAM_INT); $stmt->bindParam(':metadata', serialize($message->getMetadata()), \PDO::PARAM_STR); $stmt->execute(); return true; }
[ "public", "function", "publish", "(", "$", "queue", ",", "MessageInterface", "$", "message", ")", "{", "$", "sql", "=", "'INSERT INTO %s (%s, %s, %s, %s, %s)'", ".", "' VALUES (:body, :queue, :state, :priority, :metadata)'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "this", "->", "dbOptions", "[", "'table'", "]", ",", "$", "this", "->", "dbOptions", "[", "'body'", "]", ",", "$", "this", "->", "dbOptions", "[", "'queue'", "]", ",", "$", "this", "->", "dbOptions", "[", "'state'", "]", ",", "$", "this", "->", "dbOptions", "[", "'priority'", "]", ",", "$", "this", "->", "dbOptions", "[", "'metadata'", "]", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "sql", ")", ";", "$", "stmt", "->", "bindParam", "(", "':body'", ",", "serialize", "(", "$", "message", "->", "getBody", "(", ")", ")", ",", "\\", "PDO", "::", "PARAM_STR", ")", ";", "$", "stmt", "->", "bindParam", "(", "':queue'", ",", "$", "message", "->", "getQueue", "(", ")", ",", "\\", "PDO", "::", "PARAM_STR", ")", ";", "$", "stmt", "->", "bindParam", "(", "':state'", ",", "$", "message", "->", "getState", "(", ")", ",", "\\", "PDO", "::", "PARAM_INT", ")", ";", "$", "stmt", "->", "bindParam", "(", "':priority'", ",", "$", "message", "->", "getPriority", "(", ")", ",", "\\", "PDO", "::", "PARAM_INT", ")", ";", "$", "stmt", "->", "bindParam", "(", "':metadata'", ",", "serialize", "(", "$", "message", "->", "getMetadata", "(", ")", ")", ",", "\\", "PDO", "::", "PARAM_STR", ")", ";", "$", "stmt", "->", "execute", "(", ")", ";", "return", "true", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/benjamindulau/BarbeQ/blob/d1fd7caa1ba700ac317282948c6fc9d62fe6d523/src/BarbeQ/Adapter/PDOAdapter.php#L39-L62
deesoft/yii2-rest
BasicController.php
BasicController.viewDetail
protected function viewDetail($id, $field) { $model = $this->findModel($id); $definition = array_merge($model->fields(), $model->extraFields()); if (isset($definition[$field])) { return is_string($definition[$field]) ? $model->{$definition[$field]} : call_user_func($definition[$field], $model, $field); } elseif (in_array($field, $definition)) { return $model->$field; } throw new NotFoundHttpException("Object not found: $id/$field"); }
php
protected function viewDetail($id, $field) { $model = $this->findModel($id); $definition = array_merge($model->fields(), $model->extraFields()); if (isset($definition[$field])) { return is_string($definition[$field]) ? $model->{$definition[$field]} : call_user_func($definition[$field], $model, $field); } elseif (in_array($field, $definition)) { return $model->$field; } throw new NotFoundHttpException("Object not found: $id/$field"); }
[ "protected", "function", "viewDetail", "(", "$", "id", ",", "$", "field", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "$", "definition", "=", "array_merge", "(", "$", "model", "->", "fields", "(", ")", ",", "$", "model", "->", "extraFields", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "definition", "[", "$", "field", "]", ")", ")", "{", "return", "is_string", "(", "$", "definition", "[", "$", "field", "]", ")", "?", "$", "model", "->", "{", "$", "definition", "[", "$", "field", "]", "}", ":", "call_user_func", "(", "$", "definition", "[", "$", "field", "]", ",", "$", "model", ",", "$", "field", ")", ";", "}", "elseif", "(", "in_array", "(", "$", "field", ",", "$", "definition", ")", ")", "{", "return", "$", "model", "->", "$", "field", ";", "}", "throw", "new", "NotFoundHttpException", "(", "\"Object not found: $id/$field\"", ")", ";", "}" ]
Displays a single filed of model. @param integer $id @return mixed
[ "Displays", "a", "single", "filed", "of", "model", "." ]
train
https://github.com/deesoft/yii2-rest/blob/c33f145fbfa2bc138dffdd2f9408a2a461153128/BasicController.php#L72-L82
deesoft/yii2-rest
BasicController.php
BasicController.actionCreate
public function actionCreate() { /* @var $model ActiveRecord */ $model = $this->createModel(); $model->load(Yii::$app->request->post(), ''); $model->save(); return $model; }
php
public function actionCreate() { /* @var $model ActiveRecord */ $model = $this->createModel(); $model->load(Yii::$app->request->post(), ''); $model->save(); return $model; }
[ "public", "function", "actionCreate", "(", ")", "{", "/* @var $model ActiveRecord */", "$", "model", "=", "$", "this", "->", "createModel", "(", ")", ";", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ",", "''", ")", ";", "$", "model", "->", "save", "(", ")", ";", "return", "$", "model", ";", "}" ]
Creates a new model. If creation is successful, the browser will be redirected to the 'view' page. @return mixed
[ "Creates", "a", "new", "model", ".", "If", "creation", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "view", "page", "." ]
train
https://github.com/deesoft/yii2-rest/blob/c33f145fbfa2bc138dffdd2f9408a2a461153128/BasicController.php#L89-L97
deesoft/yii2-rest
BasicController.php
BasicController.actionPatch
public function actionPatch($id) { $model = $this->findModel($id); $patchs = Yii::$app->request->post(); foreach ($patchs as $patch) { $this->doPatch($model, $patch); } $model->save(); return $model; }
php
public function actionPatch($id) { $model = $this->findModel($id); $patchs = Yii::$app->request->post(); foreach ($patchs as $patch) { $this->doPatch($model, $patch); } $model->save(); return $model; }
[ "public", "function", "actionPatch", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "$", "patchs", "=", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ";", "foreach", "(", "$", "patchs", "as", "$", "patch", ")", "{", "$", "this", "->", "doPatch", "(", "$", "model", ",", "$", "patch", ")", ";", "}", "$", "model", "->", "save", "(", ")", ";", "return", "$", "model", ";", "}" ]
Updates an existing model. If update is successful, the browser will be redirected to the 'view' page. @param integer $id @return mixed
[ "Updates", "an", "existing", "model", ".", "If", "update", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "view", "page", "." ]
train
https://github.com/deesoft/yii2-rest/blob/c33f145fbfa2bc138dffdd2f9408a2a461153128/BasicController.php#L120-L131
Danack/Jig
src/Jig/JigBase.php
JigBase.callFunction
protected function callFunction($functionName) { $functionArgs = func_get_args(); $params = array_splice($functionArgs, 1); foreach ($this->plugins as $plugin) { $functionList = $plugin->getFunctionList(); if (in_array($functionName, $functionList) === true) { return $plugin->callFunction($functionName, $params); } } throw new JigException("Function $functionName not known in plugins."); }
php
protected function callFunction($functionName) { $functionArgs = func_get_args(); $params = array_splice($functionArgs, 1); foreach ($this->plugins as $plugin) { $functionList = $plugin->getFunctionList(); if (in_array($functionName, $functionList) === true) { return $plugin->callFunction($functionName, $params); } } throw new JigException("Function $functionName not known in plugins."); }
[ "protected", "function", "callFunction", "(", "$", "functionName", ")", "{", "$", "functionArgs", "=", "func_get_args", "(", ")", ";", "$", "params", "=", "array_splice", "(", "$", "functionArgs", ",", "1", ")", ";", "foreach", "(", "$", "this", "->", "plugins", "as", "$", "plugin", ")", "{", "$", "functionList", "=", "$", "plugin", "->", "getFunctionList", "(", ")", ";", "if", "(", "in_array", "(", "$", "functionName", ",", "$", "functionList", ")", "===", "true", ")", "{", "return", "$", "plugin", "->", "callFunction", "(", "$", "functionName", ",", "$", "params", ")", ";", "}", "}", "throw", "new", "JigException", "(", "\"Function $functionName not known in plugins.\"", ")", ";", "}" ]
Used to call a function in a template @param $functionName @return mixed @throws JigException
[ "Used", "to", "call", "a", "function", "in", "a", "template" ]
train
https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/JigBase.php#L59-L72
Danack/Jig
src/Jig/JigBase.php
JigBase.startRenderBlock
protected function startRenderBlock($blockName, $segmentText) { foreach ($this->plugins as $plugin) { $blockRenderList = $plugin->getBlockRenderList(); if (in_array($blockName, $blockRenderList) === true) { echo $plugin->callBlockRenderStart($blockName, $segmentText); ob_start(); return; } } throw new JigException("Block $blockName not known for starting block in plugins."); }
php
protected function startRenderBlock($blockName, $segmentText) { foreach ($this->plugins as $plugin) { $blockRenderList = $plugin->getBlockRenderList(); if (in_array($blockName, $blockRenderList) === true) { echo $plugin->callBlockRenderStart($blockName, $segmentText); ob_start(); return; } } throw new JigException("Block $blockName not known for starting block in plugins."); }
[ "protected", "function", "startRenderBlock", "(", "$", "blockName", ",", "$", "segmentText", ")", "{", "foreach", "(", "$", "this", "->", "plugins", "as", "$", "plugin", ")", "{", "$", "blockRenderList", "=", "$", "plugin", "->", "getBlockRenderList", "(", ")", ";", "if", "(", "in_array", "(", "$", "blockName", ",", "$", "blockRenderList", ")", "===", "true", ")", "{", "echo", "$", "plugin", "->", "callBlockRenderStart", "(", "$", "blockName", ",", "$", "segmentText", ")", ";", "ob_start", "(", ")", ";", "return", ";", "}", "}", "throw", "new", "JigException", "(", "\"Block $blockName not known for starting block in plugins.\"", ")", ";", "}" ]
Called when a block is started in a template. @param $blockName @param $segmentText @throws JigException
[ "Called", "when", "a", "block", "is", "started", "in", "a", "template", "." ]
train
https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/JigBase.php#L81-L92
Danack/Jig
src/Jig/JigBase.php
JigBase.endRenderBlock
protected function endRenderBlock($blockName) { $contents = ob_get_contents(); ob_end_clean(); foreach ($this->plugins as $plugin) { $blockRenderList = $plugin->getBlockRenderList(); if (in_array($blockName, $blockRenderList) === true) { echo $plugin->callBlockRenderEnd($blockName, $contents); return; } } echo $contents; throw new JigException("Block $blockName not known for ending block in plugins."); }
php
protected function endRenderBlock($blockName) { $contents = ob_get_contents(); ob_end_clean(); foreach ($this->plugins as $plugin) { $blockRenderList = $plugin->getBlockRenderList(); if (in_array($blockName, $blockRenderList) === true) { echo $plugin->callBlockRenderEnd($blockName, $contents); return; } } echo $contents; throw new JigException("Block $blockName not known for ending block in plugins."); }
[ "protected", "function", "endRenderBlock", "(", "$", "blockName", ")", "{", "$", "contents", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "foreach", "(", "$", "this", "->", "plugins", "as", "$", "plugin", ")", "{", "$", "blockRenderList", "=", "$", "plugin", "->", "getBlockRenderList", "(", ")", ";", "if", "(", "in_array", "(", "$", "blockName", ",", "$", "blockRenderList", ")", "===", "true", ")", "{", "echo", "$", "plugin", "->", "callBlockRenderEnd", "(", "$", "blockName", ",", "$", "contents", ")", ";", "return", ";", "}", "}", "echo", "$", "contents", ";", "throw", "new", "JigException", "(", "\"Block $blockName not known for ending block in plugins.\"", ")", ";", "}" ]
Called when a block is ended in a template. @param $blockName @throws JigException
[ "Called", "when", "a", "block", "is", "ended", "in", "a", "template", "." ]
train
https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/JigBase.php#L99-L112
eureka-framework/component-host
src/Host/Host.php
Host.uri
public function uri($name, $baseUri = null) { if (empty($baseUri)) { $baseUri = $this->baseUri; } return $baseUri . $this->get($name); }
php
public function uri($name, $baseUri = null) { if (empty($baseUri)) { $baseUri = $this->baseUri; } return $baseUri . $this->get($name); }
[ "public", "function", "uri", "(", "$", "name", ",", "$", "baseUri", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "baseUri", ")", ")", "{", "$", "baseUri", "=", "$", "this", "->", "baseUri", ";", "}", "return", "$", "baseUri", ".", "$", "this", "->", "get", "(", "$", "name", ")", ";", "}" ]
Get uri @param string $name @param string $baseUri @return string
[ "Get", "uri" ]
train
https://github.com/eureka-framework/component-host/blob/ba5b3bd2b0c053635d91a783f34ebe0b376fa736/src/Host/Host.php#L80-L88
Hnto/nuki
src/Handlers/Process/Authentication.php
Authentication.searchValue
private function searchValue(array $values = [], array $requestInputs = []) { foreach($values as $value) { if (!array_key_exists($value, $requestInputs)) { continue; } return $requestInputs[$value]; } return null; }
php
private function searchValue(array $values = [], array $requestInputs = []) { foreach($values as $value) { if (!array_key_exists($value, $requestInputs)) { continue; } return $requestInputs[$value]; } return null; }
[ "private", "function", "searchValue", "(", "array", "$", "values", "=", "[", "]", ",", "array", "$", "requestInputs", "=", "[", "]", ")", "{", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "value", ",", "$", "requestInputs", ")", ")", "{", "continue", ";", "}", "return", "$", "requestInputs", "[", "$", "value", "]", ";", "}", "return", "null", ";", "}" ]
Search given value from ids of values @param array $values @param array $requestInputs @return mixed
[ "Search", "given", "value", "from", "ids", "of", "values" ]
train
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Process/Authentication.php#L102-L112
enikeishik/ufoframework
src/Ufo/StorableCache/MysqlStorage.php
MysqlStorage.has
public function has(string $key): bool { $sql = 'SELECT COUNT(*) AS Cnt FROM #__' . $this->table . " WHERE `" . $this->keyField . "`='" . $this->db->addEscape($key) . "'"; $cnt = $this->db->getValue($sql, 'Cnt'); if (null === $cnt) { return false; } return 0 < (int) $cnt; }
php
public function has(string $key): bool { $sql = 'SELECT COUNT(*) AS Cnt FROM #__' . $this->table . " WHERE `" . $this->keyField . "`='" . $this->db->addEscape($key) . "'"; $cnt = $this->db->getValue($sql, 'Cnt'); if (null === $cnt) { return false; } return 0 < (int) $cnt; }
[ "public", "function", "has", "(", "string", "$", "key", ")", ":", "bool", "{", "$", "sql", "=", "'SELECT COUNT(*) AS Cnt FROM #__'", ".", "$", "this", "->", "table", ".", "\" WHERE `\"", ".", "$", "this", "->", "keyField", ".", "\"`='\"", ".", "$", "this", "->", "db", "->", "addEscape", "(", "$", "key", ")", ".", "\"'\"", ";", "$", "cnt", "=", "$", "this", "->", "db", "->", "getValue", "(", "$", "sql", ",", "'Cnt'", ")", ";", "if", "(", "null", "===", "$", "cnt", ")", "{", "return", "false", ";", "}", "return", "0", "<", "(", "int", ")", "$", "cnt", ";", "}" ]
Determines whether an item is present in the cache. @param string $key @return bool
[ "Determines", "whether", "an", "item", "is", "present", "in", "the", "cache", "." ]
train
https://github.com/enikeishik/ufoframework/blob/fb44461bcb0506dbc3257724a2281f756594f62f/src/Ufo/StorableCache/MysqlStorage.php#L104-L113
enikeishik/ufoframework
src/Ufo/StorableCache/MysqlStorage.php
MysqlStorage.getPacket
public function getPacket(string $key): Packet { $sql = 'SELECT ' . '`' . $this->valueField . '`, `' . $this->timestampField . '`,' . '`' . $this->lifetimeField . '`, `' . $this->savetimeField . '`' . ' FROM `' . $this->table . '`' . ' WHERE `' . $this->keyField . '`=' . "'" . $this->db->addEscape($key) . "'"; try { $row = $this->db->getItem($sql); return new Packet( $row[$this->valueField], $row[$this->lifetimeField], $row[$this->savetimeField], $row[$this->timestampField] ); } catch (\Throwable $e) { throw new BadPacketException($e->getMessage(), $e->getCode(), $e); } }
php
public function getPacket(string $key): Packet { $sql = 'SELECT ' . '`' . $this->valueField . '`, `' . $this->timestampField . '`,' . '`' . $this->lifetimeField . '`, `' . $this->savetimeField . '`' . ' FROM `' . $this->table . '`' . ' WHERE `' . $this->keyField . '`=' . "'" . $this->db->addEscape($key) . "'"; try { $row = $this->db->getItem($sql); return new Packet( $row[$this->valueField], $row[$this->lifetimeField], $row[$this->savetimeField], $row[$this->timestampField] ); } catch (\Throwable $e) { throw new BadPacketException($e->getMessage(), $e->getCode(), $e); } }
[ "public", "function", "getPacket", "(", "string", "$", "key", ")", ":", "Packet", "{", "$", "sql", "=", "'SELECT '", ".", "'`'", ".", "$", "this", "->", "valueField", ".", "'`, `'", ".", "$", "this", "->", "timestampField", ".", "'`,'", ".", "'`'", ".", "$", "this", "->", "lifetimeField", ".", "'`, `'", ".", "$", "this", "->", "savetimeField", ".", "'`'", ".", "' FROM `'", ".", "$", "this", "->", "table", ".", "'`'", ".", "' WHERE `'", ".", "$", "this", "->", "keyField", ".", "'`='", ".", "\"'\"", ".", "$", "this", "->", "db", "->", "addEscape", "(", "$", "key", ")", ".", "\"'\"", ";", "try", "{", "$", "row", "=", "$", "this", "->", "db", "->", "getItem", "(", "$", "sql", ")", ";", "return", "new", "Packet", "(", "$", "row", "[", "$", "this", "->", "valueField", "]", ",", "$", "row", "[", "$", "this", "->", "lifetimeField", "]", ",", "$", "row", "[", "$", "this", "->", "savetimeField", "]", ",", "$", "row", "[", "$", "this", "->", "timestampField", "]", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "throw", "new", "BadPacketException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Fetches an item (packet) from the cache. @param string $key @return \Ufo\StorableCache\Packet @throws \Ufo\StorableCache\BadPacketException
[ "Fetches", "an", "item", "(", "packet", ")", "from", "the", "cache", "." ]
train
https://github.com/enikeishik/ufoframework/blob/fb44461bcb0506dbc3257724a2281f756594f62f/src/Ufo/StorableCache/MysqlStorage.php#L124-L142
enikeishik/ufoframework
src/Ufo/StorableCache/MysqlStorage.php
MysqlStorage.set
public function set(string $key, string $value, int $lifetime, int $savetime): bool { if (!$this->has($key)) { $sql = 'INSERT INTO #__' . $this->table . '(' . '`' . $this->keyField . '`, ' . '`' . $this->valueField . '`, ' . '`' . $this->timestampField . '`,' . '`' . $this->lifetimeField . '`,' . '`' . $this->savetimeField . '`' . ')' . ' VALUES(' . "'" . $this->db->addEscape($key) . "'," . "'" . $this->db->addEscape($value) . "'," . "'" . time() . "'," . "'" . $lifetime . "'," . "'" . $savetime . "'" . ')'; } else { $sql = 'UPDATE #__' . $this->table . ' SET ' . '`' . $this->valueField . '`=' . "'" . $this->db->addEscape($value) . "'," . '`' . $this->timestampField . '`=' . "'" . time() . "'," . '`' . $this->lifetimeField . '`=' . "'" . $lifetime . "'," . '`' . $this->savetimeField . '`=' . "'" . $savetime . "'" . ' WHERE `' . $this->keyField . '`=' . "'" . $this->db->addEscape($key) . "'"; } return $this->db->query($sql); }
php
public function set(string $key, string $value, int $lifetime, int $savetime): bool { if (!$this->has($key)) { $sql = 'INSERT INTO #__' . $this->table . '(' . '`' . $this->keyField . '`, ' . '`' . $this->valueField . '`, ' . '`' . $this->timestampField . '`,' . '`' . $this->lifetimeField . '`,' . '`' . $this->savetimeField . '`' . ')' . ' VALUES(' . "'" . $this->db->addEscape($key) . "'," . "'" . $this->db->addEscape($value) . "'," . "'" . time() . "'," . "'" . $lifetime . "'," . "'" . $savetime . "'" . ')'; } else { $sql = 'UPDATE #__' . $this->table . ' SET ' . '`' . $this->valueField . '`=' . "'" . $this->db->addEscape($value) . "'," . '`' . $this->timestampField . '`=' . "'" . time() . "'," . '`' . $this->lifetimeField . '`=' . "'" . $lifetime . "'," . '`' . $this->savetimeField . '`=' . "'" . $savetime . "'" . ' WHERE `' . $this->keyField . '`=' . "'" . $this->db->addEscape($key) . "'"; } return $this->db->query($sql); }
[ "public", "function", "set", "(", "string", "$", "key", ",", "string", "$", "value", ",", "int", "$", "lifetime", ",", "int", "$", "savetime", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "$", "sql", "=", "'INSERT INTO #__'", ".", "$", "this", "->", "table", ".", "'('", ".", "'`'", ".", "$", "this", "->", "keyField", ".", "'`, '", ".", "'`'", ".", "$", "this", "->", "valueField", ".", "'`, '", ".", "'`'", ".", "$", "this", "->", "timestampField", ".", "'`,'", ".", "'`'", ".", "$", "this", "->", "lifetimeField", ".", "'`,'", ".", "'`'", ".", "$", "this", "->", "savetimeField", ".", "'`'", ".", "')'", ".", "' VALUES('", ".", "\"'\"", ".", "$", "this", "->", "db", "->", "addEscape", "(", "$", "key", ")", ".", "\"',\"", ".", "\"'\"", ".", "$", "this", "->", "db", "->", "addEscape", "(", "$", "value", ")", ".", "\"',\"", ".", "\"'\"", ".", "time", "(", ")", ".", "\"',\"", ".", "\"'\"", ".", "$", "lifetime", ".", "\"',\"", ".", "\"'\"", ".", "$", "savetime", ".", "\"'\"", ".", "')'", ";", "}", "else", "{", "$", "sql", "=", "'UPDATE #__'", ".", "$", "this", "->", "table", ".", "' SET '", ".", "'`'", ".", "$", "this", "->", "valueField", ".", "'`='", ".", "\"'\"", ".", "$", "this", "->", "db", "->", "addEscape", "(", "$", "value", ")", ".", "\"',\"", ".", "'`'", ".", "$", "this", "->", "timestampField", ".", "'`='", ".", "\"'\"", ".", "time", "(", ")", ".", "\"',\"", ".", "'`'", ".", "$", "this", "->", "lifetimeField", ".", "'`='", ".", "\"'\"", ".", "$", "lifetime", ".", "\"',\"", ".", "'`'", ".", "$", "this", "->", "savetimeField", ".", "'`='", ".", "\"'\"", ".", "$", "savetime", ".", "\"'\"", ".", "' WHERE `'", ".", "$", "this", "->", "keyField", ".", "'`='", ".", "\"'\"", ".", "$", "this", "->", "db", "->", "addEscape", "(", "$", "key", ")", ".", "\"'\"", ";", "}", "return", "$", "this", "->", "db", "->", "query", "(", "$", "sql", ")", ";", "}" ]
Persists data in the cache, uniquely referenced by a key with an optional lifetime and time to save. @param string $key The key of the item to store. @param string $value The value of the item to store. @param int $lifetime The lifetime value of this item. The library must store items with expired lifetime. @param int $savetime The time to save value of this item. The library can delete outdated items automatically with expired savetime. @return bool True on success and false on failure.
[ "Persists", "data", "in", "the", "cache", "uniquely", "referenced", "by", "a", "key", "with", "an", "optional", "lifetime", "and", "time", "to", "save", "." ]
train
https://github.com/enikeishik/ufoframework/blob/fb44461bcb0506dbc3257724a2281f756594f62f/src/Ufo/StorableCache/MysqlStorage.php#L156-L185
enikeishik/ufoframework
src/Ufo/StorableCache/MysqlStorage.php
MysqlStorage.delete
public function delete(string $key): bool { $sql = 'DELETE FROM #__' . $this->table . " WHERE `" . $this->keyField . "`='" . $this->db->addEscape($key) . "'"; return $this->db->query($sql); }
php
public function delete(string $key): bool { $sql = 'DELETE FROM #__' . $this->table . " WHERE `" . $this->keyField . "`='" . $this->db->addEscape($key) . "'"; return $this->db->query($sql); }
[ "public", "function", "delete", "(", "string", "$", "key", ")", ":", "bool", "{", "$", "sql", "=", "'DELETE FROM #__'", ".", "$", "this", "->", "table", ".", "\" WHERE `\"", ".", "$", "this", "->", "keyField", ".", "\"`='\"", ".", "$", "this", "->", "db", "->", "addEscape", "(", "$", "key", ")", ".", "\"'\"", ";", "return", "$", "this", "->", "db", "->", "query", "(", "$", "sql", ")", ";", "}" ]
Delete an item from the cache by its unique key. @param string $key The unique cache key of the item to delete. @return bool True if the item was successfully removed. False if there was an error.
[ "Delete", "an", "item", "from", "the", "cache", "by", "its", "unique", "key", "." ]
train
https://github.com/enikeishik/ufoframework/blob/fb44461bcb0506dbc3257724a2281f756594f62f/src/Ufo/StorableCache/MysqlStorage.php#L194-L200
enikeishik/ufoframework
src/Ufo/StorableCache/MysqlStorage.php
MysqlStorage.deleteOutdated
public function deleteOutdated(): bool { $sql = 'DELETE FROM `' . $this->table . '`' . ' WHERE `' . $this->savetimeField . '`<' . '(' . time() . '-`' . $this->timestampField . '`)'; return $this->db->query($sql); }
php
public function deleteOutdated(): bool { $sql = 'DELETE FROM `' . $this->table . '`' . ' WHERE `' . $this->savetimeField . '`<' . '(' . time() . '-`' . $this->timestampField . '`)'; return $this->db->query($sql); }
[ "public", "function", "deleteOutdated", "(", ")", ":", "bool", "{", "$", "sql", "=", "'DELETE FROM `'", ".", "$", "this", "->", "table", ".", "'`'", ".", "' WHERE `'", ".", "$", "this", "->", "savetimeField", ".", "'`<'", ".", "'('", ".", "time", "(", ")", ".", "'-`'", ".", "$", "this", "->", "timestampField", ".", "'`)'", ";", "return", "$", "this", "->", "db", "->", "query", "(", "$", "sql", ")", ";", "}" ]
Deletes all outdated (time to save expired) cache items in a single operation. @return bool True on success and false on failure.
[ "Deletes", "all", "outdated", "(", "time", "to", "save", "expired", ")", "cache", "items", "in", "a", "single", "operation", "." ]
train
https://github.com/enikeishik/ufoframework/blob/fb44461bcb0506dbc3257724a2281f756594f62f/src/Ufo/StorableCache/MysqlStorage.php#L207-L213
yii2module/yii2-article
src/widgets/PostList.php
PostList.run
public function run() { $collection = \App::$domain->article->article->allByNames($this->names); return $this->render('list', ['collection' => $collection]); }
php
public function run() { $collection = \App::$domain->article->article->allByNames($this->names); return $this->render('list', ['collection' => $collection]); }
[ "public", "function", "run", "(", ")", "{", "$", "collection", "=", "\\", "App", "::", "$", "domain", "->", "article", "->", "article", "->", "allByNames", "(", "$", "this", "->", "names", ")", ";", "return", "$", "this", "->", "render", "(", "'list'", ",", "[", "'collection'", "=>", "$", "collection", "]", ")", ";", "}" ]
Runs the widget
[ "Runs", "the", "widget" ]
train
https://github.com/yii2module/yii2-article/blob/f9468a892eaa5186393a26356e696e3cc9fa1441/src/widgets/PostList.php#L16-L20
eventerza/module-sql-storage
src/Services/MysqlClient.php
MysqlClient.getAll
public function getAll(string $table, int $page = 0): array { try { $this->db->beginTransaction(); $sql = "SELECT * FROM $table"; if ($page > 0) { $sql = $sql . " LIMIT " . self::LIMIT . " OFFSET " . self::LIMIT * ($page - 1); } /** @var PDOStatement $stmt */ $stmt = $this->db->prepare($sql); $stmt->execute(); $this->db->commit(); $result = $stmt->fetchAll(); return $result; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
php
public function getAll(string $table, int $page = 0): array { try { $this->db->beginTransaction(); $sql = "SELECT * FROM $table"; if ($page > 0) { $sql = $sql . " LIMIT " . self::LIMIT . " OFFSET " . self::LIMIT * ($page - 1); } /** @var PDOStatement $stmt */ $stmt = $this->db->prepare($sql); $stmt->execute(); $this->db->commit(); $result = $stmt->fetchAll(); return $result; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
[ "public", "function", "getAll", "(", "string", "$", "table", ",", "int", "$", "page", "=", "0", ")", ":", "array", "{", "try", "{", "$", "this", "->", "db", "->", "beginTransaction", "(", ")", ";", "$", "sql", "=", "\"SELECT * FROM $table\"", ";", "if", "(", "$", "page", ">", "0", ")", "{", "$", "sql", "=", "$", "sql", ".", "\" LIMIT \"", ".", "self", "::", "LIMIT", ".", "\" OFFSET \"", ".", "self", "::", "LIMIT", "*", "(", "$", "page", "-", "1", ")", ";", "}", "/** @var PDOStatement $stmt */", "$", "stmt", "=", "$", "this", "->", "db", "->", "prepare", "(", "$", "sql", ")", ";", "$", "stmt", "->", "execute", "(", ")", ";", "$", "this", "->", "db", "->", "commit", "(", ")", ";", "$", "result", "=", "$", "stmt", "->", "fetchAll", "(", ")", ";", "return", "$", "result", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "$", "this", "->", "db", "->", "rollBack", "(", ")", ";", "throw", "new", "PDOException", "(", "$", "e", ")", ";", "}", "}" ]
@param string $table @param int $page @return array
[ "@param", "string", "$table" ]
train
https://github.com/eventerza/module-sql-storage/blob/4eaf8f064c86de94dfba100c160146f86524ff8b/src/Services/MysqlClient.php#L41-L64
eventerza/module-sql-storage
src/Services/MysqlClient.php
MysqlClient.getBy
public function getBy(string $table, string $field, $value): array { $result = $this->getByFilter($table, array($field), array($value)); if (empty($result)) { throw new NotFoundException($value . ' not found.'); } return $result[0]; }
php
public function getBy(string $table, string $field, $value): array { $result = $this->getByFilter($table, array($field), array($value)); if (empty($result)) { throw new NotFoundException($value . ' not found.'); } return $result[0]; }
[ "public", "function", "getBy", "(", "string", "$", "table", ",", "string", "$", "field", ",", "$", "value", ")", ":", "array", "{", "$", "result", "=", "$", "this", "->", "getByFilter", "(", "$", "table", ",", "array", "(", "$", "field", ")", ",", "array", "(", "$", "value", ")", ")", ";", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "throw", "new", "NotFoundException", "(", "$", "value", ".", "' not found.'", ")", ";", "}", "return", "$", "result", "[", "0", "]", ";", "}" ]
@param string $table @param string $field @param string $value @return array
[ "@param", "string", "$table", "@param", "string", "$field", "@param", "string", "$value" ]
train
https://github.com/eventerza/module-sql-storage/blob/4eaf8f064c86de94dfba100c160146f86524ff8b/src/Services/MysqlClient.php#L73-L82
eventerza/module-sql-storage
src/Services/MysqlClient.php
MysqlClient.getNumberOf
public function getNumberOf(string $table, array $fields, array $values, string $connectionPhrase = "AND"): int { try { $this->db->beginTransaction(); $query = "SELECT count(*) as numberOfEntities FROM $table "; $query = $query . $this->buildWhereCondition($fields, $connectionPhrase); /** @var PDOStatement $stmt */ $stmt = $this->db->prepare($query); $stmt->execute($values); $this->db->commit(); $result = $stmt->fetch(); return $result['numberOfEntities']; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
php
public function getNumberOf(string $table, array $fields, array $values, string $connectionPhrase = "AND"): int { try { $this->db->beginTransaction(); $query = "SELECT count(*) as numberOfEntities FROM $table "; $query = $query . $this->buildWhereCondition($fields, $connectionPhrase); /** @var PDOStatement $stmt */ $stmt = $this->db->prepare($query); $stmt->execute($values); $this->db->commit(); $result = $stmt->fetch(); return $result['numberOfEntities']; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
[ "public", "function", "getNumberOf", "(", "string", "$", "table", ",", "array", "$", "fields", ",", "array", "$", "values", ",", "string", "$", "connectionPhrase", "=", "\"AND\"", ")", ":", "int", "{", "try", "{", "$", "this", "->", "db", "->", "beginTransaction", "(", ")", ";", "$", "query", "=", "\"SELECT count(*) as numberOfEntities FROM $table \"", ";", "$", "query", "=", "$", "query", ".", "$", "this", "->", "buildWhereCondition", "(", "$", "fields", ",", "$", "connectionPhrase", ")", ";", "/** @var PDOStatement $stmt */", "$", "stmt", "=", "$", "this", "->", "db", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "$", "values", ")", ";", "$", "this", "->", "db", "->", "commit", "(", ")", ";", "$", "result", "=", "$", "stmt", "->", "fetch", "(", ")", ";", "return", "$", "result", "[", "'numberOfEntities'", "]", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "$", "this", "->", "db", "->", "rollBack", "(", ")", ";", "throw", "new", "PDOException", "(", "$", "e", ")", ";", "}", "}" ]
@param string $table @param array $fields @param array $values @param string $connectionPhrase @return int
[ "@param", "string", "$table", "@param", "array", "$fields", "@param", "array", "$values", "@param", "string", "$connectionPhrase" ]
train
https://github.com/eventerza/module-sql-storage/blob/4eaf8f064c86de94dfba100c160146f86524ff8b/src/Services/MysqlClient.php#L127-L148
eventerza/module-sql-storage
src/Services/MysqlClient.php
MysqlClient.getWhereIn
public function getWhereIn(string $table, string $field, array $values): array { try { $this->db->beginTransaction(); $query = "SELECT * FROM $table WHERE $field IN (" . implode(',', $values) . ")"; /** @var PDOStatement $stmt */ $stmt = $this->db->prepare($query); $stmt->execute(); $this->db->commit(); $result = $stmt->fetchAll(); if ($result === false) { throw new NotFoundException($values . ' not found.'); } return $result; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
php
public function getWhereIn(string $table, string $field, array $values): array { try { $this->db->beginTransaction(); $query = "SELECT * FROM $table WHERE $field IN (" . implode(',', $values) . ")"; /** @var PDOStatement $stmt */ $stmt = $this->db->prepare($query); $stmt->execute(); $this->db->commit(); $result = $stmt->fetchAll(); if ($result === false) { throw new NotFoundException($values . ' not found.'); } return $result; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
[ "public", "function", "getWhereIn", "(", "string", "$", "table", ",", "string", "$", "field", ",", "array", "$", "values", ")", ":", "array", "{", "try", "{", "$", "this", "->", "db", "->", "beginTransaction", "(", ")", ";", "$", "query", "=", "\"SELECT * FROM $table WHERE $field IN (\"", ".", "implode", "(", "','", ",", "$", "values", ")", ".", "\")\"", ";", "/** @var PDOStatement $stmt */", "$", "stmt", "=", "$", "this", "->", "db", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", ")", ";", "$", "this", "->", "db", "->", "commit", "(", ")", ";", "$", "result", "=", "$", "stmt", "->", "fetchAll", "(", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "throw", "new", "NotFoundException", "(", "$", "values", ".", "' not found.'", ")", ";", "}", "return", "$", "result", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "$", "this", "->", "db", "->", "rollBack", "(", ")", ";", "throw", "new", "PDOException", "(", "$", "e", ")", ";", "}", "}" ]
@param string $table @param string $field @param array $values @return array @throws NotFoundException
[ "@param", "string", "$table", "@param", "string", "$field", "@param", "array", "$values" ]
train
https://github.com/eventerza/module-sql-storage/blob/4eaf8f064c86de94dfba100c160146f86524ff8b/src/Services/MysqlClient.php#L158-L181
eventerza/module-sql-storage
src/Services/MysqlClient.php
MysqlClient.save
public function save(string $table, array $data): array { try { $this->db->beginTransaction(); $query = "INSERT INTO $table (" . implode(', ', array_keys($data)) . ") VALUES (" . substr(str_repeat(', ?', count($data)), 1) . ")" . " ON DUPLICATE KEY UPDATE " . implode('=?, ', array_keys($data)) . "=?"; $duplicateDate = array_merge(array_values($data), array_values($data)); /** @var PDOStatement $stmt */ $stmt = $this->db->prepare( $query ); $stmt->execute(array_values($duplicateDate)); $this->db->commit(); return $data; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
php
public function save(string $table, array $data): array { try { $this->db->beginTransaction(); $query = "INSERT INTO $table (" . implode(', ', array_keys($data)) . ") VALUES (" . substr(str_repeat(', ?', count($data)), 1) . ")" . " ON DUPLICATE KEY UPDATE " . implode('=?, ', array_keys($data)) . "=?"; $duplicateDate = array_merge(array_values($data), array_values($data)); /** @var PDOStatement $stmt */ $stmt = $this->db->prepare( $query ); $stmt->execute(array_values($duplicateDate)); $this->db->commit(); return $data; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
[ "public", "function", "save", "(", "string", "$", "table", ",", "array", "$", "data", ")", ":", "array", "{", "try", "{", "$", "this", "->", "db", "->", "beginTransaction", "(", ")", ";", "$", "query", "=", "\"INSERT INTO $table (\"", ".", "implode", "(", "', '", ",", "array_keys", "(", "$", "data", ")", ")", ".", "\") VALUES (\"", ".", "substr", "(", "str_repeat", "(", "', ?'", ",", "count", "(", "$", "data", ")", ")", ",", "1", ")", ".", "\")\"", ".", "\" ON DUPLICATE KEY UPDATE \"", ".", "implode", "(", "'=?, '", ",", "array_keys", "(", "$", "data", ")", ")", ".", "\"=?\"", ";", "$", "duplicateDate", "=", "array_merge", "(", "array_values", "(", "$", "data", ")", ",", "array_values", "(", "$", "data", ")", ")", ";", "/** @var PDOStatement $stmt */", "$", "stmt", "=", "$", "this", "->", "db", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "array_values", "(", "$", "duplicateDate", ")", ")", ";", "$", "this", "->", "db", "->", "commit", "(", ")", ";", "return", "$", "data", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "$", "this", "->", "db", "->", "rollBack", "(", ")", ";", "throw", "new", "PDOException", "(", "$", "e", ")", ";", "}", "}" ]
@param string $table @param array $data @return array
[ "@param", "string", "$table", "@param", "array", "$data" ]
train
https://github.com/eventerza/module-sql-storage/blob/4eaf8f064c86de94dfba100c160146f86524ff8b/src/Services/MysqlClient.php#L200-L226
eventerza/module-sql-storage
src/Services/MysqlClient.php
MysqlClient.delete
public function delete(string $table, string $id): bool { return $this->deleteWhere($table, 'id', $id); }
php
public function delete(string $table, string $id): bool { return $this->deleteWhere($table, 'id', $id); }
[ "public", "function", "delete", "(", "string", "$", "table", ",", "string", "$", "id", ")", ":", "bool", "{", "return", "$", "this", "->", "deleteWhere", "(", "$", "table", ",", "'id'", ",", "$", "id", ")", ";", "}" ]
@param string $table @param string $id @return bool
[ "@param", "string", "$table", "@param", "string", "$id" ]
train
https://github.com/eventerza/module-sql-storage/blob/4eaf8f064c86de94dfba100c160146f86524ff8b/src/Services/MysqlClient.php#L234-L237
eventerza/module-sql-storage
src/Services/MysqlClient.php
MysqlClient.deleteWhere
public function deleteWhere(string $table, string $field, string $value): bool { try { $this->db->beginTransaction(); /** @var PDOStatement $stmt */ $stmt = $this->db->prepare("DELETE FROM $table WHERE $field = ?"); $stmt->execute(array($value)); $this->db->commit(); if ($stmt->rowCount() === 0) { return false; } return true; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
php
public function deleteWhere(string $table, string $field, string $value): bool { try { $this->db->beginTransaction(); /** @var PDOStatement $stmt */ $stmt = $this->db->prepare("DELETE FROM $table WHERE $field = ?"); $stmt->execute(array($value)); $this->db->commit(); if ($stmt->rowCount() === 0) { return false; } return true; } catch (PDOException $e) { $this->db->rollBack(); throw new PDOException($e); } }
[ "public", "function", "deleteWhere", "(", "string", "$", "table", ",", "string", "$", "field", ",", "string", "$", "value", ")", ":", "bool", "{", "try", "{", "$", "this", "->", "db", "->", "beginTransaction", "(", ")", ";", "/** @var PDOStatement $stmt */", "$", "stmt", "=", "$", "this", "->", "db", "->", "prepare", "(", "\"DELETE FROM $table WHERE $field = ?\"", ")", ";", "$", "stmt", "->", "execute", "(", "array", "(", "$", "value", ")", ")", ";", "$", "this", "->", "db", "->", "commit", "(", ")", ";", "if", "(", "$", "stmt", "->", "rowCount", "(", ")", "===", "0", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "$", "this", "->", "db", "->", "rollBack", "(", ")", ";", "throw", "new", "PDOException", "(", "$", "e", ")", ";", "}", "}" ]
@param string $table @param string $field @param string $value @return bool
[ "@param", "string", "$table", "@param", "string", "$field", "@param", "string", "$value" ]
train
https://github.com/eventerza/module-sql-storage/blob/4eaf8f064c86de94dfba100c160146f86524ff8b/src/Services/MysqlClient.php#L246-L266
eventerza/module-sql-storage
src/Services/MysqlClient.php
MysqlClient.buildWhereCondition
private function buildWhereCondition(array $fields, string $connectionPhrase): string { $query = ""; foreach ($fields as $key => $field) { if ($key == 0) { $connectionPhrase = "WHERE"; } $query = $query . " " . $connectionPhrase . " $field = ?"; } return $query; }
php
private function buildWhereCondition(array $fields, string $connectionPhrase): string { $query = ""; foreach ($fields as $key => $field) { if ($key == 0) { $connectionPhrase = "WHERE"; } $query = $query . " " . $connectionPhrase . " $field = ?"; } return $query; }
[ "private", "function", "buildWhereCondition", "(", "array", "$", "fields", ",", "string", "$", "connectionPhrase", ")", ":", "string", "{", "$", "query", "=", "\"\"", ";", "foreach", "(", "$", "fields", "as", "$", "key", "=>", "$", "field", ")", "{", "if", "(", "$", "key", "==", "0", ")", "{", "$", "connectionPhrase", "=", "\"WHERE\"", ";", "}", "$", "query", "=", "$", "query", ".", "\" \"", ".", "$", "connectionPhrase", ".", "\" $field = ?\"", ";", "}", "return", "$", "query", ";", "}" ]
@param array $fields @param string $connectionPhrase @param $query @return string
[ "@param", "array", "$fields", "@param", "string", "$connectionPhrase", "@param", "$query" ]
train
https://github.com/eventerza/module-sql-storage/blob/4eaf8f064c86de94dfba100c160146f86524ff8b/src/Services/MysqlClient.php#L275-L286
oliverde8/MPDedicatedServerBundle
Service/DedicatedServer.php
DedicatedServer.getServerInfo
public function getServerInfo($login) { static $lockAcquired = false; if (isset($this->servers[$login])) { $cacheKey = $this->_getServerInfoCacheKey($login); $cacheResult = $this->serverInfoCache->fetch($cacheKey); if ($cacheResult) { return $cacheResult; } else if (!$lockAcquired) { // We don't have the lock, we need to get it before asking the dedicated. // Start Protected code. $this->semaphore->aquire($cacheKey); $lockAcquired = true; // Ask for data again, if cache filled from other instance then data from cache, if not wil do a call. $data = $this->getServerInfo($login); // End protected code. $lockAcquired = false; $this->semaphore->release($cacheKey); return $data; } else { // We have the lock, data not in cache get data from the server. $data = $this->_getServerInfo($login); $this->serverInfoCache->save($cacheKey, $data, $this->cacheTimeOutInfo); return $data; } } return null; }
php
public function getServerInfo($login) { static $lockAcquired = false; if (isset($this->servers[$login])) { $cacheKey = $this->_getServerInfoCacheKey($login); $cacheResult = $this->serverInfoCache->fetch($cacheKey); if ($cacheResult) { return $cacheResult; } else if (!$lockAcquired) { // We don't have the lock, we need to get it before asking the dedicated. // Start Protected code. $this->semaphore->aquire($cacheKey); $lockAcquired = true; // Ask for data again, if cache filled from other instance then data from cache, if not wil do a call. $data = $this->getServerInfo($login); // End protected code. $lockAcquired = false; $this->semaphore->release($cacheKey); return $data; } else { // We have the lock, data not in cache get data from the server. $data = $this->_getServerInfo($login); $this->serverInfoCache->save($cacheKey, $data, $this->cacheTimeOutInfo); return $data; } } return null; }
[ "public", "function", "getServerInfo", "(", "$", "login", ")", "{", "static", "$", "lockAcquired", "=", "false", ";", "if", "(", "isset", "(", "$", "this", "->", "servers", "[", "$", "login", "]", ")", ")", "{", "$", "cacheKey", "=", "$", "this", "->", "_getServerInfoCacheKey", "(", "$", "login", ")", ";", "$", "cacheResult", "=", "$", "this", "->", "serverInfoCache", "->", "fetch", "(", "$", "cacheKey", ")", ";", "if", "(", "$", "cacheResult", ")", "{", "return", "$", "cacheResult", ";", "}", "else", "if", "(", "!", "$", "lockAcquired", ")", "{", "// We don't have the lock, we need to get it before asking the dedicated.", "// Start Protected code.", "$", "this", "->", "semaphore", "->", "aquire", "(", "$", "cacheKey", ")", ";", "$", "lockAcquired", "=", "true", ";", "// Ask for data again, if cache filled from other instance then data from cache, if not wil do a call.", "$", "data", "=", "$", "this", "->", "getServerInfo", "(", "$", "login", ")", ";", "// End protected code.", "$", "lockAcquired", "=", "false", ";", "$", "this", "->", "semaphore", "->", "release", "(", "$", "cacheKey", ")", ";", "return", "$", "data", ";", "}", "else", "{", "// We have the lock, data not in cache get data from the server.", "$", "data", "=", "$", "this", "->", "_getServerInfo", "(", "$", "login", ")", ";", "$", "this", "->", "serverInfoCache", "->", "save", "(", "$", "cacheKey", ",", "$", "data", ",", "$", "this", "->", "cacheTimeOutInfo", ")", ";", "return", "$", "data", ";", "}", "}", "return", "null", ";", "}" ]
Returns server information. If server information not in cache will make call to the dedicated server. Try to use this with ajax calls in order to have a faster website. @param string $login Login of the server @return ServerInfo|null
[ "Returns", "server", "information", ".", "If", "server", "information", "not", "in", "cache", "will", "make", "call", "to", "the", "dedicated", "server", ".", "Try", "to", "use", "this", "with", "ajax", "calls", "in", "order", "to", "have", "a", "faster", "website", "." ]
train
https://github.com/oliverde8/MPDedicatedServerBundle/blob/c0cab0b0089a1273032ddf4bbf0287e7aee8fceb/Service/DedicatedServer.php#L73-L107
oliverde8/MPDedicatedServerBundle
Service/DedicatedServer.php
DedicatedServer.getServerChatLines
public function getServerChatLines($login) { static $lockAcquired = false; if (isset($this->servers[$login])) { $cacheKey = $this->_getServerChatCacheKey($login); $cacheResult = $this->serverInfoCache->fetch($cacheKey); if ($cacheResult) { return $cacheResult; } else if (!$lockAcquired) { // We don't have the lock, we need to get it before asking the dedicated. // Start Protected code. $this->semaphore->aquire($cacheKey); $lockAcquired = true; // Ask for data again, if cache filled from other instance then data from cache, if not wil do a call. $data = $this->getServerChatLines($login); // End protected code. $lockAcquired = false; $this->semaphore->release($cacheKey); return $data; } else { $data = array(); try { $connection = $this->getConnection($login); if ($connection) { $data = $connection->getChatLines(); } } catch (\Exception $e) { } $this->serverInfoCache->save($cacheKey, $data, $this->cacheTimeOutChat); return $data; } } return null; }
php
public function getServerChatLines($login) { static $lockAcquired = false; if (isset($this->servers[$login])) { $cacheKey = $this->_getServerChatCacheKey($login); $cacheResult = $this->serverInfoCache->fetch($cacheKey); if ($cacheResult) { return $cacheResult; } else if (!$lockAcquired) { // We don't have the lock, we need to get it before asking the dedicated. // Start Protected code. $this->semaphore->aquire($cacheKey); $lockAcquired = true; // Ask for data again, if cache filled from other instance then data from cache, if not wil do a call. $data = $this->getServerChatLines($login); // End protected code. $lockAcquired = false; $this->semaphore->release($cacheKey); return $data; } else { $data = array(); try { $connection = $this->getConnection($login); if ($connection) { $data = $connection->getChatLines(); } } catch (\Exception $e) { } $this->serverInfoCache->save($cacheKey, $data, $this->cacheTimeOutChat); return $data; } } return null; }
[ "public", "function", "getServerChatLines", "(", "$", "login", ")", "{", "static", "$", "lockAcquired", "=", "false", ";", "if", "(", "isset", "(", "$", "this", "->", "servers", "[", "$", "login", "]", ")", ")", "{", "$", "cacheKey", "=", "$", "this", "->", "_getServerChatCacheKey", "(", "$", "login", ")", ";", "$", "cacheResult", "=", "$", "this", "->", "serverInfoCache", "->", "fetch", "(", "$", "cacheKey", ")", ";", "if", "(", "$", "cacheResult", ")", "{", "return", "$", "cacheResult", ";", "}", "else", "if", "(", "!", "$", "lockAcquired", ")", "{", "// We don't have the lock, we need to get it before asking the dedicated.", "// Start Protected code.", "$", "this", "->", "semaphore", "->", "aquire", "(", "$", "cacheKey", ")", ";", "$", "lockAcquired", "=", "true", ";", "// Ask for data again, if cache filled from other instance then data from cache, if not wil do a call.", "$", "data", "=", "$", "this", "->", "getServerChatLines", "(", "$", "login", ")", ";", "// End protected code.", "$", "lockAcquired", "=", "false", ";", "$", "this", "->", "semaphore", "->", "release", "(", "$", "cacheKey", ")", ";", "return", "$", "data", ";", "}", "else", "{", "$", "data", "=", "array", "(", ")", ";", "try", "{", "$", "connection", "=", "$", "this", "->", "getConnection", "(", "$", "login", ")", ";", "if", "(", "$", "connection", ")", "{", "$", "data", "=", "$", "connection", "->", "getChatLines", "(", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "$", "this", "->", "serverInfoCache", "->", "save", "(", "$", "cacheKey", ",", "$", "data", ",", "$", "this", "->", "cacheTimeOutChat", ")", ";", "return", "$", "data", ";", "}", "}", "return", "null", ";", "}" ]
Returns chat lines. Try to use this with ajax calls in order to have a faster website. @param string $login Login of the server @return ServerInfo|null
[ "Returns", "chat", "lines", ".", "Try", "to", "use", "this", "with", "ajax", "calls", "in", "order", "to", "have", "a", "faster", "website", "." ]
train
https://github.com/oliverde8/MPDedicatedServerBundle/blob/c0cab0b0089a1273032ddf4bbf0287e7aee8fceb/Service/DedicatedServer.php#L117-L158
oliverde8/MPDedicatedServerBundle
Service/DedicatedServer.php
DedicatedServer.getMapList
public function getMapList($login) { static $lockAcquired = false; if (isset($this->servers[$login])) { $cacheKey = $this->_getServerMapsCacheKey($login); $cacheResult = $this->serverInfoCache->fetch($cacheKey); if ($cacheResult) { return $cacheResult; } else if (!$lockAcquired) { // We don't have the lock, we need to get it before asking the dedicated. // Start Protected code. $this->semaphore->aquire($cacheKey); $lockAcquired = true; // Ask for data again, if cache filled from other instance then data from cache, if not wil do a call. $data = $this->getMapList($login); // End protected code. $lockAcquired = false; $this->semaphore->release($cacheKey); return $data; } else { $data = array(); try { $connection = $this->getConnection($login); if ($connection) { $data = $connection->getMapList(-1, 0); $this->serverInfoCache->save($cacheKey, $data, $this->cacheTimeOutMap); } } catch (\Exception $e) { //If can't connect keep shorter in cache $this->serverInfoCache->save($cacheKey, array(), $this->cacheTimeOutMapRetry); } return $data; } } }
php
public function getMapList($login) { static $lockAcquired = false; if (isset($this->servers[$login])) { $cacheKey = $this->_getServerMapsCacheKey($login); $cacheResult = $this->serverInfoCache->fetch($cacheKey); if ($cacheResult) { return $cacheResult; } else if (!$lockAcquired) { // We don't have the lock, we need to get it before asking the dedicated. // Start Protected code. $this->semaphore->aquire($cacheKey); $lockAcquired = true; // Ask for data again, if cache filled from other instance then data from cache, if not wil do a call. $data = $this->getMapList($login); // End protected code. $lockAcquired = false; $this->semaphore->release($cacheKey); return $data; } else { $data = array(); try { $connection = $this->getConnection($login); if ($connection) { $data = $connection->getMapList(-1, 0); $this->serverInfoCache->save($cacheKey, $data, $this->cacheTimeOutMap); } } catch (\Exception $e) { //If can't connect keep shorter in cache $this->serverInfoCache->save($cacheKey, array(), $this->cacheTimeOutMapRetry); } return $data; } } }
[ "public", "function", "getMapList", "(", "$", "login", ")", "{", "static", "$", "lockAcquired", "=", "false", ";", "if", "(", "isset", "(", "$", "this", "->", "servers", "[", "$", "login", "]", ")", ")", "{", "$", "cacheKey", "=", "$", "this", "->", "_getServerMapsCacheKey", "(", "$", "login", ")", ";", "$", "cacheResult", "=", "$", "this", "->", "serverInfoCache", "->", "fetch", "(", "$", "cacheKey", ")", ";", "if", "(", "$", "cacheResult", ")", "{", "return", "$", "cacheResult", ";", "}", "else", "if", "(", "!", "$", "lockAcquired", ")", "{", "// We don't have the lock, we need to get it before asking the dedicated.", "// Start Protected code.", "$", "this", "->", "semaphore", "->", "aquire", "(", "$", "cacheKey", ")", ";", "$", "lockAcquired", "=", "true", ";", "// Ask for data again, if cache filled from other instance then data from cache, if not wil do a call.", "$", "data", "=", "$", "this", "->", "getMapList", "(", "$", "login", ")", ";", "// End protected code.", "$", "lockAcquired", "=", "false", ";", "$", "this", "->", "semaphore", "->", "release", "(", "$", "cacheKey", ")", ";", "return", "$", "data", ";", "}", "else", "{", "$", "data", "=", "array", "(", ")", ";", "try", "{", "$", "connection", "=", "$", "this", "->", "getConnection", "(", "$", "login", ")", ";", "if", "(", "$", "connection", ")", "{", "$", "data", "=", "$", "connection", "->", "getMapList", "(", "-", "1", ",", "0", ")", ";", "$", "this", "->", "serverInfoCache", "->", "save", "(", "$", "cacheKey", ",", "$", "data", ",", "$", "this", "->", "cacheTimeOutMap", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "//If can't connect keep shorter in cache", "$", "this", "->", "serverInfoCache", "->", "save", "(", "$", "cacheKey", ",", "array", "(", ")", ",", "$", "this", "->", "cacheTimeOutMapRetry", ")", ";", "}", "return", "$", "data", ";", "}", "}", "}" ]
Returns list of maps on the server. If list of map not in cache will make a call to the dedicatd server. Try to use this with ajax calls in order to have a faster website. @param string $login Login of the server @return \Maniaplanet\DedicatedServer\Structures\Map[]
[ "Returns", "list", "of", "maps", "on", "the", "server", ".", "If", "list", "of", "map", "not", "in", "cache", "will", "make", "a", "call", "to", "the", "dedicatd", "server", ".", "Try", "to", "use", "this", "with", "ajax", "calls", "in", "order", "to", "have", "a", "faster", "website", "." ]
train
https://github.com/oliverde8/MPDedicatedServerBundle/blob/c0cab0b0089a1273032ddf4bbf0287e7aee8fceb/Service/DedicatedServer.php#L168-L207
oliverde8/MPDedicatedServerBundle
Service/DedicatedServer.php
DedicatedServer.getServerNames
public function getServerNames() { $serverNames = array(); foreach($this->servers as $login => $data) { $serverNames[$login] = $data['name']; } return $serverNames; }
php
public function getServerNames() { $serverNames = array(); foreach($this->servers as $login => $data) { $serverNames[$login] = $data['name']; } return $serverNames; }
[ "public", "function", "getServerNames", "(", ")", "{", "$", "serverNames", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "servers", "as", "$", "login", "=>", "$", "data", ")", "{", "$", "serverNames", "[", "$", "login", "]", "=", "$", "data", "[", "'name'", "]", ";", "}", "return", "$", "serverNames", ";", "}" ]
Returns login, server name association. This is the name you defined in the config and therfore won't make any dedicated calls. @return String[]
[ "Returns", "login", "server", "name", "association", ".", "This", "is", "the", "name", "you", "defined", "in", "the", "config", "and", "therfore", "won", "t", "make", "any", "dedicated", "calls", "." ]
train
https://github.com/oliverde8/MPDedicatedServerBundle/blob/c0cab0b0089a1273032ddf4bbf0287e7aee8fceb/Service/DedicatedServer.php#L215-L221
oliverde8/MPDedicatedServerBundle
Service/DedicatedServer.php
DedicatedServer.getConnection
public function getConnection($login) { if (isset($this->servers[$login])) { if (!isset($this->connections[$login])) { $conf = $this->servers[$login]; $this->connections[$login] = Connection::factory($conf['host'], $conf['port'], 1, $conf['user'], $conf['password']); } return $this->connections[$login]; } return null; }
php
public function getConnection($login) { if (isset($this->servers[$login])) { if (!isset($this->connections[$login])) { $conf = $this->servers[$login]; $this->connections[$login] = Connection::factory($conf['host'], $conf['port'], 1, $conf['user'], $conf['password']); } return $this->connections[$login]; } return null; }
[ "public", "function", "getConnection", "(", "$", "login", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "servers", "[", "$", "login", "]", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "connections", "[", "$", "login", "]", ")", ")", "{", "$", "conf", "=", "$", "this", "->", "servers", "[", "$", "login", "]", ";", "$", "this", "->", "connections", "[", "$", "login", "]", "=", "Connection", "::", "factory", "(", "$", "conf", "[", "'host'", "]", ",", "$", "conf", "[", "'port'", "]", ",", "1", ",", "$", "conf", "[", "'user'", "]", ",", "$", "conf", "[", "'password'", "]", ")", ";", "}", "return", "$", "this", "->", "connections", "[", "$", "login", "]", ";", "}", "return", "null", ";", "}" ]
Connects to the dedicated server API, if connection already established will send existing connextion @param string $login Server to connect to @return Connection
[ "Connects", "to", "the", "dedicated", "server", "API", "if", "connection", "already", "established", "will", "send", "existing", "connextion" ]
train
https://github.com/oliverde8/MPDedicatedServerBundle/blob/c0cab0b0089a1273032ddf4bbf0287e7aee8fceb/Service/DedicatedServer.php#L301-L312
TransformCore/CSR-Fast-Stream-Domain-Model
src/TransformCore/Bundle/CsrFastStreamBundle/Form/Validation/Applicant.php
Applicant.validate
public static function validate(FormInterface $form) { $groups = array('CsrProfile'); $groups[] = self::password($form); return array_filter( array_unique($groups) ); }
php
public static function validate(FormInterface $form) { $groups = array('CsrProfile'); $groups[] = self::password($form); return array_filter( array_unique($groups) ); }
[ "public", "static", "function", "validate", "(", "FormInterface", "$", "form", ")", "{", "$", "groups", "=", "array", "(", "'CsrProfile'", ")", ";", "$", "groups", "[", "]", "=", "self", "::", "password", "(", "$", "form", ")", ";", "return", "array_filter", "(", "array_unique", "(", "$", "groups", ")", ")", ";", "}" ]
@param FormInterface $form @return array
[ "@param", "FormInterface", "$form" ]
train
https://github.com/TransformCore/CSR-Fast-Stream-Domain-Model/blob/cb8e4c446f814082663a20f3c5d4cea8292bd8d6/src/TransformCore/Bundle/CsrFastStreamBundle/Form/Validation/Applicant.php#L18-L27
TransformCore/CSR-Fast-Stream-Domain-Model
src/TransformCore/Bundle/CsrFastStreamBundle/Form/Validation/Applicant.php
Applicant.password
private static function password(FormInterface $form) { if ($form->has('credentials_group')) { $credentialsGroup = $form->get('credentials_group'); if ($credentialsGroup->has('plainPassword')) { $plainPasswordElement = $credentialsGroup->get('plainPassword'); if (!empty($plainPasswordElement->getData())) { return 'CsrPassword'; } } } }
php
private static function password(FormInterface $form) { if ($form->has('credentials_group')) { $credentialsGroup = $form->get('credentials_group'); if ($credentialsGroup->has('plainPassword')) { $plainPasswordElement = $credentialsGroup->get('plainPassword'); if (!empty($plainPasswordElement->getData())) { return 'CsrPassword'; } } } }
[ "private", "static", "function", "password", "(", "FormInterface", "$", "form", ")", "{", "if", "(", "$", "form", "->", "has", "(", "'credentials_group'", ")", ")", "{", "$", "credentialsGroup", "=", "$", "form", "->", "get", "(", "'credentials_group'", ")", ";", "if", "(", "$", "credentialsGroup", "->", "has", "(", "'plainPassword'", ")", ")", "{", "$", "plainPasswordElement", "=", "$", "credentialsGroup", "->", "get", "(", "'plainPassword'", ")", ";", "if", "(", "!", "empty", "(", "$", "plainPasswordElement", "->", "getData", "(", ")", ")", ")", "{", "return", "'CsrPassword'", ";", "}", "}", "}", "}" ]
@param FormInterface $form @return mixed
[ "@param", "FormInterface", "$form" ]
train
https://github.com/TransformCore/CSR-Fast-Stream-Domain-Model/blob/cb8e4c446f814082663a20f3c5d4cea8292bd8d6/src/TransformCore/Bundle/CsrFastStreamBundle/Form/Validation/Applicant.php#L34-L47
balintsera/evista-perform
src/FormMarkupTranspiler.php
FormMarkupTranspiler.findFormClassName
public function findFormClassName() { $this->runIfNotCached( 'formClassName', function () { return $this->findFormTag()->attr(self:: FORM_CLASS_NAME_ATTR_NAME); } ); return $this->formClassName; }
php
public function findFormClassName() { $this->runIfNotCached( 'formClassName', function () { return $this->findFormTag()->attr(self:: FORM_CLASS_NAME_ATTR_NAME); } ); return $this->formClassName; }
[ "public", "function", "findFormClassName", "(", ")", "{", "$", "this", "->", "runIfNotCached", "(", "'formClassName'", ",", "function", "(", ")", "{", "return", "$", "this", "->", "findFormTag", "(", ")", "->", "attr", "(", "self", "::", "FORM_CLASS_NAME_ATTR_NAME", ")", ";", "}", ")", ";", "return", "$", "this", "->", "formClassName", ";", "}" ]
Get class-name for the form
[ "Get", "class", "-", "name", "for", "the", "form" ]
train
https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/FormMarkupTranspiler.php#L70-L80
balintsera/evista-perform
src/FormMarkupTranspiler.php
FormMarkupTranspiler.transpileFields
private function transpileFields() { $formElements = 'input, select, textarea, button'; $this->findFormTag()->filter($formElements)->each( function (Crawler $node, $i) { // If it has a type attr, use as type if (null !== $node->attr('type')) { $type = $node->attr('type'); } else { $type = $node->nodeName(); } // Node name cames back with apostrophs on some servers $type = str_replace('\"', '', $type); // Create a FormField and get default attributes (name, value, validation, required) $field = $this->fieldFactory($type, $node); // complex form elements 1: select -> options if ($type === 'select') { $options = $node->filter('option'); // FormField $options->each( function ($option) use ($field) { $optionField = $this->fieldFactory('option', $option); $field->addOption($optionField); } ); } // complex form elements: handle file uploads if ($type === 'file') { try { $field->compactFiles($_FILES, $this->uploadDir); } catch (NoFileUploadedException $noFileEx) { // throw validation error? } } // Add to all fields $this->fields[$field->getName()] = $field; } ); return $this->fields; }
php
private function transpileFields() { $formElements = 'input, select, textarea, button'; $this->findFormTag()->filter($formElements)->each( function (Crawler $node, $i) { // If it has a type attr, use as type if (null !== $node->attr('type')) { $type = $node->attr('type'); } else { $type = $node->nodeName(); } // Node name cames back with apostrophs on some servers $type = str_replace('\"', '', $type); // Create a FormField and get default attributes (name, value, validation, required) $field = $this->fieldFactory($type, $node); // complex form elements 1: select -> options if ($type === 'select') { $options = $node->filter('option'); // FormField $options->each( function ($option) use ($field) { $optionField = $this->fieldFactory('option', $option); $field->addOption($optionField); } ); } // complex form elements: handle file uploads if ($type === 'file') { try { $field->compactFiles($_FILES, $this->uploadDir); } catch (NoFileUploadedException $noFileEx) { // throw validation error? } } // Add to all fields $this->fields[$field->getName()] = $field; } ); return $this->fields; }
[ "private", "function", "transpileFields", "(", ")", "{", "$", "formElements", "=", "'input, select, textarea, button'", ";", "$", "this", "->", "findFormTag", "(", ")", "->", "filter", "(", "$", "formElements", ")", "->", "each", "(", "function", "(", "Crawler", "$", "node", ",", "$", "i", ")", "{", "// If it has a type attr, use as type", "if", "(", "null", "!==", "$", "node", "->", "attr", "(", "'type'", ")", ")", "{", "$", "type", "=", "$", "node", "->", "attr", "(", "'type'", ")", ";", "}", "else", "{", "$", "type", "=", "$", "node", "->", "nodeName", "(", ")", ";", "}", "// Node name cames back with apostrophs on some servers", "$", "type", "=", "str_replace", "(", "'\\\"'", ",", "''", ",", "$", "type", ")", ";", "// Create a FormField and get default attributes (name, value, validation, required)", "$", "field", "=", "$", "this", "->", "fieldFactory", "(", "$", "type", ",", "$", "node", ")", ";", "// complex form elements 1: select -> options", "if", "(", "$", "type", "===", "'select'", ")", "{", "$", "options", "=", "$", "node", "->", "filter", "(", "'option'", ")", ";", "// FormField", "$", "options", "->", "each", "(", "function", "(", "$", "option", ")", "use", "(", "$", "field", ")", "{", "$", "optionField", "=", "$", "this", "->", "fieldFactory", "(", "'option'", ",", "$", "option", ")", ";", "$", "field", "->", "addOption", "(", "$", "optionField", ")", ";", "}", ")", ";", "}", "// complex form elements: handle file uploads", "if", "(", "$", "type", "===", "'file'", ")", "{", "try", "{", "$", "field", "->", "compactFiles", "(", "$", "_FILES", ",", "$", "this", "->", "uploadDir", ")", ";", "}", "catch", "(", "NoFileUploadedException", "$", "noFileEx", ")", "{", "// throw validation error?", "}", "}", "// Add to all fields", "$", "this", "->", "fields", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", ";", "}", ")", ";", "return", "$", "this", "->", "fields", ";", "}" ]
Find fields in markup
[ "Find", "fields", "in", "markup" ]
train
https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/FormMarkupTranspiler.php#L112-L161
balintsera/evista-perform
src/FormMarkupTranspiler.php
FormMarkupTranspiler.runIfNotCached
private function runIfNotCached($variableName, callable $function) { if (null === $this->{$variableName}) { // Only assign that don't returns if (null !== $result = $function()) { $this->{$variableName} = $result; } } }
php
private function runIfNotCached($variableName, callable $function) { if (null === $this->{$variableName}) { // Only assign that don't returns if (null !== $result = $function()) { $this->{$variableName} = $result; } } }
[ "private", "function", "runIfNotCached", "(", "$", "variableName", ",", "callable", "$", "function", ")", "{", "if", "(", "null", "===", "$", "this", "->", "{", "$", "variableName", "}", ")", "{", "// Only assign that don't returns", "if", "(", "null", "!==", "$", "result", "=", "$", "function", "(", ")", ")", "{", "$", "this", "->", "{", "$", "variableName", "}", "=", "$", "result", ";", "}", "}", "}" ]
Check if a variable is empty and run function to @param $variableName @param callable $function
[ "Check", "if", "a", "variable", "is", "empty", "and", "run", "function", "to" ]
train
https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/FormMarkupTranspiler.php#L248-L256
DeimosProject/Controller
src/Controller/Controller.php
Controller.execute
public function execute() { $this->configure(); $this->before(); $name = $this->request()->attribute($this->attribute); if (!$this->methodExists($name)) { throw new NotFound('Action \'' . $name . '\' not found!'); } $data = $this->instance($name); $this->after($data); return $this->display($data); }
php
public function execute() { $this->configure(); $this->before(); $name = $this->request()->attribute($this->attribute); if (!$this->methodExists($name)) { throw new NotFound('Action \'' . $name . '\' not found!'); } $data = $this->instance($name); $this->after($data); return $this->display($data); }
[ "public", "function", "execute", "(", ")", "{", "$", "this", "->", "configure", "(", ")", ";", "$", "this", "->", "before", "(", ")", ";", "$", "name", "=", "$", "this", "->", "request", "(", ")", "->", "attribute", "(", "$", "this", "->", "attribute", ")", ";", "if", "(", "!", "$", "this", "->", "methodExists", "(", "$", "name", ")", ")", "{", "throw", "new", "NotFound", "(", "'Action \\''", ".", "$", "name", ".", "'\\' not found!'", ")", ";", "}", "$", "data", "=", "$", "this", "->", "instance", "(", "$", "name", ")", ";", "$", "this", "->", "after", "(", "$", "data", ")", ";", "return", "$", "this", "->", "display", "(", "$", "data", ")", ";", "}" ]
@return mixed @throws \InvalidArgumentException @throws RequestNotFound @throws DisplayNone @throws NotFound
[ "@return", "mixed" ]
train
https://github.com/DeimosProject/Controller/blob/b16e3c14ca26d7da1d9be6a953782e401ffdcc0d/src/Controller/Controller.php#L22-L39
DeimosProject/Controller
src/Controller/Controller.php
Controller.display
protected function display($data) { if (is_string($data)) { return $data; } if (is_array($data) || $data instanceof \stdClass) { return $this->helper()->json()->encode($data); } throw new DisplayNone('Undefined value \'' . $data . '\''); }
php
protected function display($data) { if (is_string($data)) { return $data; } if (is_array($data) || $data instanceof \stdClass) { return $this->helper()->json()->encode($data); } throw new DisplayNone('Undefined value \'' . $data . '\''); }
[ "protected", "function", "display", "(", "$", "data", ")", "{", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "return", "$", "data", ";", "}", "if", "(", "is_array", "(", "$", "data", ")", "||", "$", "data", "instanceof", "\\", "stdClass", ")", "{", "return", "$", "this", "->", "helper", "(", ")", "->", "json", "(", ")", "->", "encode", "(", "$", "data", ")", ";", "}", "throw", "new", "DisplayNone", "(", "'Undefined value \\''", ".", "$", "data", ".", "'\\''", ")", ";", "}" ]
@inheritdoc @throws \InvalidArgumentException @throws DisplayNone
[ "@inheritdoc" ]
train
https://github.com/DeimosProject/Controller/blob/b16e3c14ca26d7da1d9be6a953782e401ffdcc0d/src/Controller/Controller.php#L47-L60
yuncms/yii2-ueditor-widget
UEditor.php
UEditor.init
public function init() { parent::init(); if (!isset ($this->options ['id'])) { $this->options ['id'] = $this->getId(); } $this->clientOptions = array_merge([ 'autoHeightEnabled' => true, 'initialFrameWidth' => '100%', 'initialFrameHeight' => '300', 'serverUrl' => Url::to(['upload']), 'lang' => Yii::$app->language == 'zh-CN' ? 'zh-cn' : 'en', ], $this->clientOptions); }
php
public function init() { parent::init(); if (!isset ($this->options ['id'])) { $this->options ['id'] = $this->getId(); } $this->clientOptions = array_merge([ 'autoHeightEnabled' => true, 'initialFrameWidth' => '100%', 'initialFrameHeight' => '300', 'serverUrl' => Url::to(['upload']), 'lang' => Yii::$app->language == 'zh-CN' ? 'zh-cn' : 'en', ], $this->clientOptions); }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "options", "[", "'id'", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'id'", "]", "=", "$", "this", "->", "getId", "(", ")", ";", "}", "$", "this", "->", "clientOptions", "=", "array_merge", "(", "[", "'autoHeightEnabled'", "=>", "true", ",", "'initialFrameWidth'", "=>", "'100%'", ",", "'initialFrameHeight'", "=>", "'300'", ",", "'serverUrl'", "=>", "Url", "::", "to", "(", "[", "'upload'", "]", ")", ",", "'lang'", "=>", "Yii", "::", "$", "app", "->", "language", "==", "'zh-CN'", "?", "'zh-cn'", ":", "'en'", ",", "]", ",", "$", "this", "->", "clientOptions", ")", ";", "}" ]
{@inheritDoc} @see \yii\base\Object::init()
[ "{" ]
train
https://github.com/yuncms/yii2-ueditor-widget/blob/0adc733d60f2cd4777227a0237605965495a9b47/UEditor.php#L33-L47
black-lamp/blcms-cart
models/SearchOrder.php
SearchOrder.search
public function search($params) { $query = Order::find()->where(['not in','status', [OrderStatus::STATUS_INCOMPLETE]]); $query->orderBy(['status' => SORT_ASC, 'id' => SORT_DESC]); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'user_id' => $this->user_id, ]); $query ->andFilterWhere(['like', 'status', $this->status]) ->andFilterWhere(['like', 'uid', $this->uid]); return $dataProvider; }
php
public function search($params) { $query = Order::find()->where(['not in','status', [OrderStatus::STATUS_INCOMPLETE]]); $query->orderBy(['status' => SORT_ASC, 'id' => SORT_DESC]); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'user_id' => $this->user_id, ]); $query ->andFilterWhere(['like', 'status', $this->status]) ->andFilterWhere(['like', 'uid', $this->uid]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "Order", "::", "find", "(", ")", "->", "where", "(", "[", "'not in'", ",", "'status'", ",", "[", "OrderStatus", "::", "STATUS_INCOMPLETE", "]", "]", ")", ";", "$", "query", "->", "orderBy", "(", "[", "'status'", "=>", "SORT_ASC", ",", "'id'", "=>", "SORT_DESC", "]", ")", ";", "// add conditions that should always apply here", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "]", ")", ";", "$", "this", "->", "load", "(", "$", "params", ")", ";", "if", "(", "!", "$", "this", "->", "validate", "(", ")", ")", "{", "// uncomment the following line if you do not want to return any records when validation fails", "// $query->where('0=1');", "return", "$", "dataProvider", ";", "}", "// grid filtering conditions", "$", "query", "->", "andFilterWhere", "(", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'user_id'", "=>", "$", "this", "->", "user_id", ",", "]", ")", ";", "$", "query", "->", "andFilterWhere", "(", "[", "'like'", ",", "'status'", ",", "$", "this", "->", "status", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'uid'", ",", "$", "this", "->", "uid", "]", ")", ";", "return", "$", "dataProvider", ";", "}" ]
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/models/SearchOrder.php#L44-L74
DeimosProject/Helper
src/Helper/Traits/Helper.php
Helper.instanceHelper
protected function instanceHelper() { if (method_exists($this->builder, 'helper')) { return $this->builder->helper(); } return new DeimosHelper($this->builder); }
php
protected function instanceHelper() { if (method_exists($this->builder, 'helper')) { return $this->builder->helper(); } return new DeimosHelper($this->builder); }
[ "protected", "function", "instanceHelper", "(", ")", "{", "if", "(", "method_exists", "(", "$", "this", "->", "builder", ",", "'helper'", ")", ")", "{", "return", "$", "this", "->", "builder", "->", "helper", "(", ")", ";", "}", "return", "new", "DeimosHelper", "(", "$", "this", "->", "builder", ")", ";", "}" ]
@return DeimosHelper @throws \InvalidArgumentException
[ "@return", "DeimosHelper" ]
train
https://github.com/DeimosProject/Helper/blob/39c67de21a87c7c6391b2f98416063f41c94e26f/src/Helper/Traits/Helper.php#L41-L49