_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q6000
JBDump.timestamp
train
public static function timestamp($timestamp = null) { if (!self::isDebug()) { return false; } $date = date(DATE_RFC822, $timestamp); return self::i()->dump($date, $timestamp . ' sec = '); }
php
{ "resource": "" }
q6001
JBDump.locale
train
public static function locale() { if (!self::isDebug()) { return false; } ob_start(); @system('locale -a'); $locale = explode(PHP_EOL, trim(ob_get_contents())); ob_end_clean(); $result = array( 'list' => $locale, 'conv' => @localeconv() ); return self::i()->dump($result, '! locale info !'); }
php
{ "resource": "" }
q6002
JBDump.timezone
train
public static function timezone() { if (!self::isDebug()) { return false; } $data = date_default_timezone_get(); return self::i()->dump($data, '! timezone !'); }
php
{ "resource": "" }
q6003
JBDump.print_r
train
public static function print_r($var, $varname = '...', $params = array()) { if (!self::isDebug()) { return false; } $output = print_r($var, true); $_this = self::i(); $_this->_dumpRenderHtml($output, $varname, $params); return $_this; }
php
{ "resource": "" }
q6004
JBDump.phpArray
train
public static function phpArray($var, $varname = 'varName', $isReturn = false) { if (!self::isDebug()) { return false; } $output = JBDump_array2php::toString($var, $varname); if ($isReturn) { return $output; } $_this = self::i(); $_this->_dumpRenderHtml($output, $varname, $params); return $_this; }
php
{ "resource": "" }
q6005
JBDump.var_dump
train
public static function var_dump($var, $varname = '...', $params = array()) { if (!self::isDebug()) { return false; } // var_dump the variable into a buffer and keep the output ob_start(); var_dump($var); $output = ob_get_clean(); $_this = self::i(); // neaten the newlines and indents $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output); //if (!extension_loaded('xdebug')) { $output = $_this->_htmlChars($output); //} $_this->_dumpRenderHtml($output, $varname . '::html', $params); return $_this; }
php
{ "resource": "" }
q6006
JBDump.trace
train
public static function trace($trace = null, $addObject = false) { if (!self::isDebug()) { return false; } $_this = self::i(); $trace = $trace ? $trace : debug_backtrace($addObject); unset($trace[0]); $result = $_this->convertTrace($trace, $addObject); return $_this->dump($result, '! backtrace !'); }
php
{ "resource": "" }
q6007
JBDump.extInfo
train
public static function extInfo($extensionName) { $result = self::_getExtension($extensionName); if ($result) { $extensionName = $result['name']; } return self::i()->dump($result, '! extension (' . $extensionName . ') !'); }
php
{ "resource": "" }
q6008
JBDump.pathInfo
train
public static function pathInfo($file) { $result = self::_pathInfo($file); return self::i()->dump($result, '! pathInfo (' . $file . ') !'); }
php
{ "resource": "" }
q6009
JBDump.funcInfo
train
public static function funcInfo($functionName) { $result = self::_getFunction($functionName); if ($result) { $functionName = $result['name']; } return self::i()->dump($result, '! function (' . $functionName . ') !'); }
php
{ "resource": "" }
q6010
JBDump.microtime
train
public static function microtime() { $_this = self::i(); if (!$_this->isDebug()) { return false; } $data = $_this->_microtime(); return $_this->dump($data, '! current microtime !'); }
php
{ "resource": "" }
q6011
JBDump.mark
train
public static function mark($label = '') { $_this = self::i(); if (!$_this->isDebug()) { return false; } $current = $_this->_microtime() - $_this->_start; $memory = self::_getMemory(); $trace = debug_backtrace(); $markInfo = array( 'time' => $current, 'timeDiff' => $current - $_this->_prevTime, 'memory' => $memory, 'memoryDiff' => $memory - $_this->_prevMemory, 'trace' => $_this->_getSourcePath($trace, true), 'label' => $label, ); $_this->_bufferInfo[] = $markInfo; if ((int)self::$_config['profiler']['render'] & self::PROFILER_RENDER_FILE) { $_this->log(self::_profilerFormatMark($markInfo), 'mark #'); } $_this->_prevTime = $current; $_this->_prevMemory = $memory; return $_this; }
php
{ "resource": "" }
q6012
JBDump.profiler
train
public function profiler($mode = 1) { if ($this->isDebug() && count($this->_bufferInfo) > 2 && $mode) { $mode = (int)$mode; if ($mode && self::isAjax()) { if ($mode & self::PROFILER_RENDER_TOTAL) { $this->_profilerRenderTotal(); } } else { if ($mode & self::PROFILER_RENDER_TABLE) { $this->_profilerRenderTable(); } if ($mode & self::PROFILER_RENDER_CHART) { $this->_profilerRenderChart(); } if ($mode & self::PROFILER_RENDER_TOTAL) { $this->_profilerRenderTotal(); } if ($mode & self::PROFILER_RENDER_ECHO) { $this->_profilerRenderEcho(); } } } }
php
{ "resource": "" }
q6013
JBDump._profilerFormatMemory
train
protected static function _profilerFormatMemory($memoryBytes, $addMeasure = false) { $bytes = round($memoryBytes / 1024 / 1024, 3); if ($addMeasure) { $bytes .= ' MB'; } return $bytes; }
php
{ "resource": "" }
q6014
JBDump._profilerFormatTime
train
protected static function _profilerFormatTime($time, $addMeasure = false, $round = 0) { $time = round($time * 1000, $round); if ($addMeasure) { $time .= ' ms'; } return $time; }
php
{ "resource": "" }
q6015
JBDump._profilerFormatMark
train
protected static function _profilerFormatMark(array $mark) { return sprintf("%0.3f sec (+%.3f); %0.3f MB (%s%0.3f) - %s", (float)$mark['time'], (float)$mark['timeDiff'], ($mark['memory'] / 1024 / 1024), ($mark['memoryDiff'] / 1024 / 1024 >= 0) ? '+' : '', ($mark['memoryDiff'] / 1024 / 1024), $mark['label'] ); }
php
{ "resource": "" }
q6016
JBDump._profilerRenderTotal
train
protected function _profilerRenderTotal() { reset($this->_bufferInfo); $first = current($this->_bufferInfo); $last = end($this->_bufferInfo); $memoryPeak = memory_get_peak_usage(true); $memoryDeltas = $timeDeltas = array(); foreach ($this->_bufferInfo as $oneMark) { $memoryDeltas[] = $oneMark['memoryDiff']; $timeDeltas[] = $oneMark['timeDiff']; } $totalInfo = array(); $totalInfo[] = '- Points: ' . count($this->_bufferInfo); $totalInfo[] = '-------- Time (ms)'; $totalInfo[] = '- Max delta, msec: ' . self::_profilerFormatTime(max($timeDeltas)); $totalInfo[] = '- Min delta, msec: ' . self::_profilerFormatTime(min($timeDeltas)); $totalInfo[] = '- Total delta, msec: ' . self::_profilerFormatTime(($last['time'] - $first['time'])); $totalInfo[] = '- Limit, sec: ' . ini_get('max_execution_time'); $totalInfo[] = '-------- Memory (MB)'; $totalInfo[] = '- Max delta: ' . self::_profilerFormatMemory(max($memoryDeltas)); $totalInfo[] = '- Min delta: ' . self::_profilerFormatMemory(min($memoryDeltas)); $totalInfo[] = '- Usage on peak: ' . $this->_formatSize($memoryPeak) . ' (' . $memoryPeak . ')'; $totalInfo[] = '- Total delta: ' . self::_profilerFormatMemory($last['memory'] - $first['memory']); $totalInfo[] = '- Limit: ' . ini_get('memory_limit'); if (self::isAjax()) { $this->_dumpRenderLog($totalInfo, 'Profiler total'); } else { $totalInfo = PHP_EOL . "\t" . implode(PHP_EOL . "\t", $totalInfo) . PHP_EOL; $this->_dumpRenderLite($totalInfo, '! <b>profiler total info</b> !'); } }
php
{ "resource": "" }
q6017
JBDump._profilerRenderFile
train
protected function _profilerRenderFile() { $this->log('-------------------------------------------------------', 'Profiler start'); foreach ($this->_bufferInfo as $key => $mark) { $this->log(self::_profilerFormatMark($mark)); } $this->log('-------------------------------------------------------', 'Profiler end'); }
php
{ "resource": "" }
q6018
JBDump._profilerRenderEcho
train
protected function _profilerRenderEcho() { $output = PHP_EOL; foreach ($this->_bufferInfo as $key => $mark) { $output .= "\t" . self::_profilerFormatMark($mark) . PHP_EOL; } $this->_dumpRenderLite($output, '! profiler !'); }
php
{ "resource": "" }
q6019
JBDump._dumpRenderHtml
train
protected function _dumpRenderHtml($data, $varname = '...', $params = array()) { $this->_currentDepth = 0; $this->_initAssets(); if (isset($params['trace'])) { $this->_trace = $params['trace']; } else { $this->_trace = debug_backtrace(); } $text = $this->_getSourceFunction($this->_trace); $path = $this->_getSourcePath($this->_trace); ?> <div id="jbdump"> <ul class="jbnode"> <?php $this->_dump($data, $varname); ?> <li class="jbfooter"> <div class="jbversion"> <a href="<?php echo $this->_site; ?>" target="_blank">JBDump v<?php echo self::VERSION; ?></a> </div> <?php if (self::$_config['showCall']) : ?> <div class="jbpath"><?php echo $text . ' ' . $path; ?></div> <?php endif; ?> </li> </ul> </div> <?php }
php
{ "resource": "" }
q6020
JBDump._dumpRenderLite
train
protected function _dumpRenderLite($data, $varname = '...', $params = array()) { if (is_bool($data)) { $data = $data ? 'TRUE' : 'FALSE'; } elseif (is_null($data)) { $data = 'NULL'; } if (is_string($data) && strlen($data) == 0) { $printrOut = '""'; } else { $printrOut = print_r($data, true); } if (!self::isCli()) { $printrOut = $this->_htmlChars($printrOut); } if (self::isAjax()) { $printrOut = str_replace('] =&gt;', '] =>', $printrOut); } $output = array(); if (!self::isCli()) { $output[] = '<pre>------------------------------' . PHP_EOL; } $output[] = $varname . ' = '; $output[] = rtrim($printrOut, PHP_EOL); if (!self::isCli()) { $output[] = PHP_EOL . '------------------------------</pre>' . PHP_EOL; } else { $output[] = PHP_EOL; } if (!self::isAjax()) { echo '<pre class="jbdump" style="text-align: left;">' . implode('', $output) . '</pre>' . PHP_EOL; } else { echo implode('', $output); } }
php
{ "resource": "" }
q6021
JBDump.hash
train
public static function hash($data) { $result = array(); foreach (hash_algos() as $algoritm) { $result[$algoritm] = hash($algoritm, $data, false); } return self::i()->dump($result, '! hash !'); }
php
{ "resource": "" }
q6022
JBDump._getMemory
train
protected static function _getMemory() { if (function_exists('memory_get_usage')) { return memory_get_usage(); } else { $output = array(); $pid = getmypid(); if (substr(PHP_OS, 0, 3) == 'WIN') { @exec('tasklist /FI "PID eq ' . $pid . '" /FO LIST', $output); if (!isset($output[5])) { $output[5] = null; } return (int)substr($output[5], strpos($output[5], ':') + 1); } else { @exec("ps -o rss -p $pid", $output); return $output[1] * 1024; } } }
php
{ "resource": "" }
q6023
JBDump._dump
train
protected function _dump($data, $name = '...') { $varType = strtolower(getType($data)); $advType = false; if ($varType == 'string' && preg_match('#(.*)::(.*)#', $name, $matches)) { $matches[2] = trim(strToLower($matches[2])); if ($this->_strlen($matches[2]) > 0) { $advType = $matches[2]; } $name = $matches[1]; } if ($this->_strlen($name) > 80) { $name = substr($name, 0, 80) . '...'; } if ($varType == 'null') { $this->_null($name); } elseif ($varType == 'boolean') { $this->_boolean($data, $name, $advType); } elseif ($varType == 'integer') { $this->_integer($data, $name, $advType); } elseif ($varType == 'double') { $this->_float($data, $name, $advType); } elseif ($varType == 'string') { $this->_string($data, $name, $advType); } elseif ($varType == 'array') { if ($this->_currentDepth <= self::$_config['dump']['maxDepth']) { $this->_currentDepth++; $this->_array($data, $name, $advType); $this->_currentDepth--; } else { $this->_maxDepth($data, $name, $advType); } } elseif ($varType == 'object') { if ($this->_currentDepth <= self::$_config['dump']['maxDepth']) { $this->_currentDepth++; if (get_class($data) == 'Closure') { $this->_closure($data, $name, $advType); } else { $this->_object($data, $name, $advType); } $this->_currentDepth--; } else { $this->_maxDepth($data, $name); } } elseif ($varType == 'resource') { $this->_resource($data, $name, $advType); } else { $this->_undefined($data, $name, $advType); } return $this; }
php
{ "resource": "" }
q6024
JBDump._vars
train
protected function _vars($data, $isExpanded = false) { $_is_object = is_object($data); ?> <div class="jbnest" style="<?php echo $isExpanded ? 'display:block' : 'display:none'; ?>"> <ul class="jbnode"> <?php $keys = ($_is_object) ? array_keys(@get_object_vars($data)) : array_keys($data); // sorting if (self::$_config['sort']['object'] && $_is_object) { sort($keys); } elseif (self::$_config['sort']['array']) { sort($keys); } // get entries foreach ($keys as $key) { $value = null; if ($_is_object && property_exists($data, $key)) { $value = $data->$key; } else { if (is_array($data) && array_key_exists($key, $data)) { $value = $data[$key]; } } $this->_dump($value, $key); } // get methods if ($_is_object && self::$_config['dump']['showMethods']) { if ($methods = $this->_getMethods($data)) { $this->_dump($methods, '&lt;! methods of "' . get_class($data) . '" !&gt;'); } } ?> </ul> </div> <?php }
php
{ "resource": "" }
q6025
JBDump._resource
train
protected function _resource($data, $name) { $data = get_resource_type($data); $this->_renderNode('Resource', $name, $data); }
php
{ "resource": "" }
q6026
JBDump._strlen
train
protected function _strlen($string) { $encoding = function_exists('mb_detect_encoding') ? mb_detect_encoding($string) : false; return $encoding ? mb_strlen($string, $encoding) : strlen($string); }
php
{ "resource": "" }
q6027
JBDump._string
train
protected function _string($data, $name, $advType = '') { $dataLength = $this->_strlen($data); $_extra = false; if ($advType == 'html') { $_extra = true; $_ = 'HTML Code'; $data = '<pre class="jbpreview">' . $data . '</pre>'; } elseif ($advType == 'source') { $data = trim($data); if ($data && strpos($data, '<?') !== 0) { $_ = 'PHP Code'; $_extra = true; $data = "<?php" . PHP_EOL . PHP_EOL . $data; $data = '<pre class="jbpreview">' . highlight_string($data, true) . '</pre>'; } else { $_ = '// code not found'; $data = null; } } else { $_ = $data; if (!( strpos($data, "\r") === false && strpos($data, "\n") === false && strpos($data, " ") === false && strpos($data, "\t") === false ) ) { $_extra = true; } else { $_extra = false; } if ($this->_strlen($data)) { if ($this->_strlen($data) > self::$_config['dump']['stringLength']) { if (function_exists('mb_substr')) { $_ = mb_substr($data, 0, self::$_config['dump']['stringLength'] - 3) . '...'; } else { $_ = substr($data, 0, self::$_config['dump']['stringLength'] - 3) . '...'; } $_extra = true; } $_ = $this->_htmlChars($_); $data = '<textarea readonly="readonly" class="jbpreview">' . $this->_htmlChars($data) . '</textarea>'; } } ?> <li class="jbchild"> <div class="jbelement <?php echo $_extra ? ' jbexpand' : ''; ?>" <?php if ($_extra) { ?> onClick="jbdump.toggle(this);"<?php } ?>> <span class="jbname"><?php echo $name; ?></span> (<span class="jbtype jbtype-string">String</span>, <?php echo $dataLength; ?>) <span class="jbvalue"><?php echo $_; ?></span> </div> <?php if ($_extra) { ?> <div class="jbnest" style="display:none;"> <ul class="jbnode"> <li class="jbchild"><?php echo $data; ?></li> </ul> </div> <?php } ?> </li> <?php }
php
{ "resource": "" }
q6028
JBDump._array
train
protected function _array(array $data, $name) { $isExpanded = $this->_isExpandedLevel(); if (0 === strpos($name, '&lt;! methods of "')) { $isExpanded = false; } ?> <li class="jbchild"> <div class="jbelement<?php echo count((array)$data) > 0 ? ' jbexpand' : ''; ?> <?= $isExpanded ? 'jbopened' : ''; ?>" <?php if (count((array)$data) > 0) { ?> onClick="jbdump.toggle(this);"<?php } ?>> <span class="jbname"><?php echo $name; ?></span> (<span class="jbtype jbtype-array">Array</span>, <?php echo count((array)$data); ?>) </div> <?php if (count((array)$data)) { $this->_vars($data, $isExpanded); } ?> </li> <?php }
php
{ "resource": "" }
q6029
JBDump._object
train
protected function _object($data, $name) { static $objectIdList = array(); $objectId = spl_object_hash($data); if (!isset($objectIdList[$objectId])) { $objectIdList[$objectId] = count($objectIdList); } $count = count(@get_object_vars($data)); $isExpand = $count > 0 || self::$_config['dump']['showMethods']; $isExpanded = $this->_isExpandedLevel(); ?> <li class="jbchild"> <div class="jbelement<?php echo $isExpand ? ' jbexpand' : ''; ?> <?= $isExpanded ? 'jbopened' : ''; ?>" <?php if ($isExpand) { ?> onClick="jbdump.toggle(this);"<?php } ?>> <span class="jbname" title="splHash=<?php echo $objectId;?>"><?php echo $name; ?></span> ( <span class="jbtype jbtype-object"><?php echo get_class($data); ?></span> <span style="text-decoration: underline;" title="splHash=<?php echo $objectId;?>">id:<?php echo $objectIdList[$objectId];?></span>, l:<?php echo $count; ?> ) </div> <?php if ($isExpand) { $this->_vars($data, $isExpanded); } ?> <?php }
php
{ "resource": "" }
q6030
JBDump._closure
train
protected function _closure($data, $name) { $isExpanded = $this->_isExpandedLevel(); ?> <li class="jbchild"> <div class="jbelement<?php echo count((array)$data) > 0 ? ' jbexpand' : ''; ?> <?= $isExpanded ? 'jbopened' : ''; ?>" <?php if (count((array)$data) > 0) { ?> onClick="jbdump.toggle(this);"<?php } ?>> <span class="jbname"><?php echo $name; ?></span> (<span class="jbtype jbtype-closure">Closure</span>) <span class="jbvalue"><?php echo get_class($data); ?></span> </div> <?php $this->_vars($this->_getFunction($data), $isExpanded); ?> </li> <?php }
php
{ "resource": "" }
q6031
JBDump._renderNode
train
protected function _renderNode($type, $name, $data) { $typeAlias = str_replace(' ', '-', strtolower($type)); ?> <li class="jbchild"> <div class="jbelement"> <span class="jbname"><?php echo $name; ?></span> (<span class="jbtype jbtype-<?php echo $typeAlias; ?>"><?php echo $type; ?></span>) <span class="jbvalue"><?php echo $data; ?></span> </div> </li> <?php }
php
{ "resource": "" }
q6032
JBDump.getClientIP
train
public static function getClientIP($getSource = false) { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; $source = 'HTTP_CLIENT_IP'; } elseif (!empty($_SERVER['HTTP_X_REAL_IP'])) { $ip = $_SERVER['HTTP_X_REAL_IP']; $source = 'HTTP_X_REAL_IP'; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; $source = 'HTTP_X_FORWARDED_FOR'; } elseif (!empty($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; $source = 'REMOTE_ADDR'; } else { $ip = '0.0.0.0'; $source = 'undefined'; } if ($getSource) { return $source; } else { return $ip; } }
php
{ "resource": "" }
q6033
JBDump._getRalativePath
train
protected function _getRalativePath($path) { if ($path) { $rootPath = str_replace(array('/', '\\'), '/', self::$_config['root']); $path = str_replace(array('/', '\\'), '/', $path); $path = str_replace($rootPath, '/', $path); $path = str_replace('//', '/', $path); $path = trim($path, '/'); } return $path; }
php
{ "resource": "" }
q6034
JBDump._getOneTrace
train
protected function _getOneTrace($info, $addObject = false) { $_this = self::i(); $_tmp = array(); if (isset($info['file'])) { $_tmp['file'] = $_this->_getRalativePath($info['file']) . ' : ' . $info['line']; } else { $info['file'] = false; } if ($info['function'] != 'include' && $info['function'] != 'include_once' && $info['function'] != 'require' && $info['function'] != 'require_once' ) { if (isset($info['type']) && isset($info['class'])) { $_tmp['func'] = $info['class'] . ' ' . $info['type'] . ' ' . $info['function'] . '()'; } else { $_tmp['func'] = $info['function'] . '()'; } $args = isset($info['args']) ? $info['args'] : array(); if (self::$_config['showArgs'] || $addObject) { $_tmp['args'] = isset($info['args']) ? $info['args'] : array(); } else { $_tmp['count_args'] = count($args); } } else { $_tmp['func'] = $info['function']; } if (isset($info['object']) && (self::$_config['showArgs'] || $addObject)) { $_tmp['obj'] = $info['object']; } return $_tmp; }
php
{ "resource": "" }
q6035
JBDump._formatSize
train
protected static function _formatSize($bytes) { $exp = 0; $value = 0; $symbol = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); if ($bytes > 0) { $exp = floor(log($bytes) / log(1024)); $value = ($bytes / pow(1024, floor($exp))); } return sprintf('%.2f ' . $symbol[$exp], $value); }
php
{ "resource": "" }
q6036
JBDump._getSourceFunction
train
protected function _getSourceFunction($trace) { $lastTrace = $this->_getLastTrace($trace); if (isset($lastTrace['function']) || isset($lastTrace['class'])) { $args = ''; if (isset($lastTrace['args'])) { $args = '( ' . count($lastTrace['args']) . ' args' . ' )'; } if (isset($lastTrace['class'])) { $function = $lastTrace['class'] . ' ' . $lastTrace['type'] . ' ' . $lastTrace['function'] . ' ' . $args; } else { $function = $lastTrace['function'] . ' ' . $args; } return 'Function: ' . $function . '<br />'; } return ''; }
php
{ "resource": "" }
q6037
JBDump._getSourcePath
train
protected function _getSourcePath($trace, $fileOnly = false) { $path = ''; $currentTrace = $this->_getLastTrace($trace); if (isset($currentTrace['file'])) { $path = $this->_getRalativePath($currentTrace['file']); if ($fileOnly && $path) { $path = pathinfo($path, PATHINFO_BASENAME); } if (isset($currentTrace['line']) && $path) { $path = $path . ':' . $currentTrace['line']; } } if (!$path) { $path = 'undefined:0'; } return $path; }
php
{ "resource": "" }
q6038
JBDump._getLastTrace
train
protected function _getLastTrace($trace) { // current filename info $curFile = pathinfo(__FILE__, PATHINFO_BASENAME); $curFileLength = $this->_strlen($curFile); $meta = array(); $j = 0; for ($i = 0; $trace && $i < sizeof($trace); $i++) { $j = $i; if (isset($trace[$i]['class']) && isset($trace[$i]['file']) && ($trace[$i]['class'] == 'JBDump') && (substr($trace[$i]['file'], -$curFileLength, $curFileLength) == $curFile) ) { } elseif (isset($trace[$i]['class']) && isset($trace[$i + 1]['file']) && isset($trace[$i]['file']) && $trace[$i]['class'] == 'JBDump' && (substr($trace[$i]['file'], -$curFileLength, $curFileLength) == $curFile) ) { } elseif (isset($trace[$i]['file']) && (substr($trace[$i]['file'], -$curFileLength, $curFileLength) == $curFile) ) { } else { // found! $meta['file'] = isset($trace[$i]['file']) ? $trace[$i]['file'] : ''; $meta['line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; break; } } // get functions if (isset($trace[$j + 1])) { $result = $trace[$j + 1]; $result['line'] = $meta['line']; $result['file'] = $meta['file']; } else { $result = $meta; } return $result; }
php
{ "resource": "" }
q6039
JBDump._getMethods
train
protected function _getMethods($object) { if (is_string($object)) { $className = $object; } else { $className = get_class($object); } $methods = get_class_methods($className); if (self::$_config['sort']['methods']) { sort($methods); } return $methods; }
php
{ "resource": "" }
q6040
JBDump.convertTrace
train
public function convertTrace($trace, $addObject = false) { $result = array(); if (is_array($trace)) { foreach ($trace as $key => $info) { $oneTrace = self::i()->_getOneTrace($info, $addObject); $file = 'undefined'; if (isset($oneTrace['file'])) { $file = $oneTrace['file']; } $result['#' . ($key - 1) . ' ' . $oneTrace['func']] = $file; } } return $result; }
php
{ "resource": "" }
q6041
JBDump._getErrorTypes
train
protected static function _getErrorTypes() { $errType = array( E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice', E_RECOVERABLE_ERROR => 'Catchable Fatal Error', ); if (defined('E_DEPRECATED')) { $errType[E_DEPRECATED] = 'Deprecated'; $errType[E_USER_DEPRECATED] = 'User Deprecated'; } $errType[E_ALL] = 'All errors'; return $errType; }
php
{ "resource": "" }
q6042
JBDump._errorHandler
train
function _errorHandler($errNo, $errMsg, $errFile, $errLine, $errCont) { $errType = $this->_getErrorTypes(); $errorMessage = $errType[$errNo] . "\t\"" . trim($errMsg) . "\"\t" . $errFile . ' ' . 'Line:' . $errLine; if (self::$_config['errors']['logAll']) { error_log('JBDump:' . $errorMessage); } if (!(error_reporting() & $errNo) || error_reporting() == 0 || (int)ini_get('display_errors') == 0) { if (self::$_config['errors']['logHidden']) { $errorMessage = date(self::DATE_FORMAT, time()) . ' ' . $errorMessage . PHP_EOL; $logPath = self::$_config['log']['path'] . '/' . self::$_config['log']['file'] . '_error_' . date('Y.m.d') . '.log'; error_log($errorMessage, 3, $logPath); } return false; } $errFile = $this->_getRalativePath($errFile); $result = array( 'file' => $errFile . ' : ' . $errLine, 'type' => $errType[$errNo] . ' (' . $errNo . ')', 'message' => $errMsg, ); if (self::$_config['errors']['context']) { $result['context'] = $errCont; } if (self::$_config['errors']['errorBacktrace']) { $trace = debug_backtrace(); unset($trace[0]); $result['backtrace'] = $this->convertTrace($trace); } if ($this->_isLiteMode()) { $errorInfo = array( 'message' => $result['type'] . ' / ' . $result['message'], 'file' => $result['file'] ); $this->_dumpRenderLite($errorInfo, '* ' . $errType[$errNo]); } else { $desc = '<b style="color:red;">*</b> ' . $errType[$errNo] . ' / ' . $this->_htmlChars($result['message']); $this->dump($result, $desc); } return true; }
php
{ "resource": "" }
q6043
JBDump.errors
train
public static function errors() { $result = array(); $result['error_reporting'] = error_reporting(); $errTypes = self::_getErrorTypes(); foreach ($errTypes as $errTypeKey => $errTypeName) { if ($result['error_reporting'] & $errTypeKey) { $result['show_types'][] = $errTypeName . ' (' . $errTypeKey . ')'; } } return self::i()->dump($result, '! errors info !'); }
php
{ "resource": "" }
q6044
JBDump.isAjax
train
public static function isAjax() { if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) { return true; } elseif (self::isCli()) { return true; } elseif (function_exists('apache_request_headers')) { $headers = apache_request_headers(); foreach ($headers as $key => $value) { if (strtolower($key) == 'x-requested-with' && strtolower($value) == 'xmlhttprequest') { return true; } } } elseif (isset($_REQUEST['ajax']) && $_REQUEST['ajax']) { return true; } elseif (isset($_REQUEST['AJAX']) && $_REQUEST['AJAX']) { return true; } return false; }
php
{ "resource": "" }
q6045
JBDump.mail
train
public static function mail($text, $subject = null, $to = null) { if (!self::isDebug()) { return false; } $_this = self::i(); if (empty($subject)) { $subject = self::$_config['mail']['subject']; } if (empty($to)) { $to = isset(self::$_config['mail']['to']) ? self::$_config['mail']['to'] : 'jbdump@' . $_SERVER['HTTP_HOST']; } if (is_array($to)) { $to = implode(', ', $to); } // message $message = array(); $message[] = '<html><body>'; $message[] = '<p><b>JBDump mail from ' . '<a href="http://' . $_SERVER['HTTP_HOST'] . '">' . $_SERVER['HTTP_HOST'] . '</a>' . '</b></p>'; $message[] = '<p><b>Date</b>: ' . date(DATE_RFC822, time()) . '</p>'; $message[] = '<p><b>IP</b>: ' . self::getClientIP() . '</p>'; $message[] = '<b>Debug message</b>: <pre>' . print_r($text, true) . '</pre>'; $message[] = '</body></html>'; $message = wordwrap(implode(PHP_EOL, $message), 70); // To send HTML mail, the Content-type header must be set $headers = array(); $headers[] = 'MIME-Version: 1.0'; $headers[] = 'Content-type: text/html; charset=utf-8'; $headers[] = 'To: ' . $to; $headers[] = 'From: JBDump debug <jbdump@' . $_SERVER['HTTP_HOST'] . '>'; $headers[] = 'X-Mailer: JBDump v' . self::VERSION; $headers = implode("\r\n", $headers); $result = mail($to, $subject, $message, $headers); if (self::$_config['mail']['log']) { $_this->log( array( 'email' => $to, 'subject' => $subject, 'message' => $message, 'headers' => $headers, 'result' => $result ), 'JBDump::mail' ); } return $result; }
php
{ "resource": "" }
q6046
JBDump.sql
train
public static function sql($query, $sqlName = 'SQL Query', $nl2br = false) { // Joomla hack if (defined('_JEXEC')) { $config = new JConfig(); $prefix = $config->dbprefix; $query = str_replace('#__', $prefix, $query); } if (class_exists('JBDump_SqlFormatter')) { $sqlHtml = JBDump_SqlFormatter::format($query); return self::i()->dump($sqlHtml, $sqlName . '::html'); } return self::i()->dump($query, $sqlName . '::html'); }
php
{ "resource": "" }
q6047
JBDump._jsonEncode
train
protected function _jsonEncode($in, $indent = 0) { $out = ''; foreach ($in as $key => $value) { $out .= str_repeat(" ", $indent + 1); $out .= json_encode((string)$key) . ': '; if (is_object($value) || is_array($value)) { $out .= $this->_jsonEncode($value, $indent + 1); } else { $out .= json_encode($value); } $out .= "," . PHP_EOL; } if (!empty($out)) { $out = substr($out, 0, -2); } $out = "{" . PHP_EOL . $out . PHP_EOL . str_repeat(" ", $indent) . "}"; return $out; }
php
{ "resource": "" }
q6048
CustomerAddVatidTypo3.process
train
protected function process( array $stmts ) { $this->msg( 'Adding "vatid" column to fe_users tables', 0 ); $this->status( '' ); foreach( $stmts as $table => $stmt ) { $this->msg( sprintf( 'Checking "%1$s" table', $table ), 1 ); if( $this->schema->tableExists( $table ) === true && $this->schema->columnExists( $table, 'vatid' ) === false ) { $this->execute( $stmt ); $this->status( 'added' ); } else { $this->status( 'OK' ); } } }
php
{ "resource": "" }
q6049
Util.getJson
train
public static function getJson($file, $assoc = true) { // @codeCoverageIgnoreStart if (!extension_loaded('json')) { throw new \Exception('The JSON extension is not loaded.'); } // @codeCoverageIgnoreEnd if (!file_exists($file)) { throw new \InvalidArgumentException(htmlspecialchars("The $file file is missing.")); } if (strrchr($file, '.') != '.json') { throw new \InvalidArgumentException(htmlspecialchars("The $file is not in JSON format.")); } if (($json = file_get_contents($file)) === null) { throw new \Exception(htmlspecialchars("The $file file is not readable.")); } if (($return = json_decode($json, $assoc)) === null) { throw new \Exception(htmlspecialchars("The JSON $file file is invalid.")); } return $return; }
php
{ "resource": "" }
q6050
LinkFactory.link
train
public function link($destination, array $params = array()) { if (($pos = strrpos($destination, '#')) !== FALSE) { $fragment = substr($destination, $pos); $destination = substr($destination, 0, $pos); } else { $fragment = ''; } if (strncmp($destination, '//', 2) === 0) { $absoluteUrl = TRUE; $destination = substr($destination, 2); } else { $absoluteUrl = FALSE; } $pos = strrpos($destination, ':'); $presenter = substr($destination, 0, $pos); if ($pos + 1 < strlen($destination)) { $params['action'] = substr($destination, $pos + 1); } $request = new Nette\Application\Request($presenter, 'GET', $params); $url = $this->router->constructUrl($request, $this->refUrl); if ($url === NULL) { throw new InvalidLinkException("Router failed to create link to '$destination'."); } if (!$absoluteUrl && strncmp($url, $this->refUrlHost, strlen($this->refUrlHost)) === 0) { $url = substr($url, strlen($this->refUrlHost)); } if ($fragment) { $url .= $fragment; } return $url; }
php
{ "resource": "" }
q6051
Client.generateRequestHeaders
train
protected function generateRequestHeaders( $verb, $resourceType, $resourceId, $isQuery = false, $contentLength = 0, array $extraHeaders = [] ){ $xMsDate = gmdate('D, d M Y H:i:s T'); $headers = [ 'Accept: application/json', 'User-Agent: ' . static::USER_AGENT, 'Cache-Control: no-cache', 'x-ms-date: ' . $xMsDate, 'x-ms-version: ' . $this->apiVersion, 'Authorization: ' . $this->generateAuthHeader($verb, $xMsDate, $resourceType, $resourceId) ]; if (in_array($verb, [Verbs::POST, Verbs::PUT])) { $headers[] = 'Content-Length: ' . $contentLength; if ($isQuery === true) { $headers[] = 'Content-Type: application/query+json'; $headers[] = 'x-ms-documentdb-isquery: True'; } else { $headers[] = 'Content-Type: application/json'; } } return array_merge($headers, $extraHeaders); }
php
{ "resource": "" }
q6052
Client.generateAuthHeader
train
private function generateAuthHeader($verb, $xMsDate, $resourceType, $resourceId) { $master = 'master'; $token = '1.0'; $key = base64_decode($this->key); $stringToSign = strtolower($verb) . "\n" . strtolower($resourceType) . "\n" . $resourceId . "\n" . strtolower($xMsDate) . "\n" . "\n"; $sig = base64_encode(hash_hmac('sha256', $stringToSign, $key, true)); return urlencode("type=$master&ver=$token&sig=$sig"); }
php
{ "resource": "" }
q6053
DataStore.getParent
train
public function getParent($id) { /** @var Statement $statement */ $dataItem = $this->get($id); $queryBuilder = $this->driver->getSelectQueryBuilder(); $queryBuilder->andWhere($this->driver->getUniqueId() . " = " . $dataItem->getAttribute($this->getParentField())); $statement = $queryBuilder->execute(); $rows = array($statement->fetch()); $hasResults = count($rows) > 0; $parent = null; if ($hasResults) { $this->driver->prepareResults($rows); $parent = $rows[0]; } return $parent; }
php
{ "resource": "" }
q6054
DataStore.save
train
public function save($item, $autoUpdate = true) { $result = null; $this->allowSave = true; if (isset($this->events[ self::EVENT_ON_BEFORE_SAVE ])) { $this->secureEval($this->events[ self::EVENT_ON_BEFORE_SAVE ], array( 'item' => &$item )); } if ($this->allowSave) { $result = $this->getDriver()->save($item, $autoUpdate); } if (isset($this->events[ self::EVENT_ON_AFTER_SAVE ])) { $this->secureEval($this->events[ self::EVENT_ON_AFTER_SAVE ], array( 'item' => &$item )); } return $result; }
php
{ "resource": "" }
q6055
DataStore.isOracle
train
public function isOracle() { static $r; if (is_null($r)) { $r = $this->driver->getPlatformName() == self::ORACLE_PLATFORM; } return $r; }
php
{ "resource": "" }
q6056
DataStore.isSqlite
train
public function isSqlite() { static $r; if (is_null($r)) { $r = $this->driver->getPlatformName() == self::SQLITE_PLATFORM; } return $r; }
php
{ "resource": "" }
q6057
DataStore.isPostgres
train
public function isPostgres() { static $r; if (is_null($r)) { $r = $this->driver->getPlatformName() == self::POSTGRESQL_PLATFORM; } return $r; }
php
{ "resource": "" }
q6058
DataStore.getTypes
train
public function getTypes() { $list = array(); $reflectionClass = new \ReflectionClass(__CLASS__); foreach ($reflectionClass->getConstants() as $k => $v) { if (strrpos($k, "_PLATFORM") > 0) { $list[] = $v; } } return $list; }
php
{ "resource": "" }
q6059
DataStore.getTroughMapping
train
public function getTroughMapping($mappingId, $id) { $config = $this->mapping[ $mappingId ]; $dataStoreService = $this->container->get("data.source"); $externalDataStore = $dataStoreService->get($config["externalDataStore"]); $externalDriver = $externalDataStore->getDriver(); $internalFieldName = null; $externalFieldName = null; if (isset($config['internalId'])) { $internalFieldName = $config['internalId']; } if (isset($config['externalId'])) { $externalFieldName = $config['externalId']; } if (isset($config['internalFieldName'])) { $internalFieldName = $config['internalFieldName']; } if (isset($config['relatedFieldName'])) { $externalFieldName = $config['relatedFieldName']; } if (!$externalDriver instanceof DoctrineBaseDriver) { throw new Exception('This kind of externalDriver can\'t get relations'); } $criteria = $this->get($id)->getAttribute($internalFieldName); return $externalDriver->getByCriteria($criteria, $externalFieldName); }
php
{ "resource": "" }
q6060
Typo3.deleteMultiple
train
public function deleteMultiple( $keys ) { foreach( $keys as $key ) { $this->object->remove( $this->prefix . $key ); } }
php
{ "resource": "" }
q6061
Typo3.deleteByTags
train
public function deleteByTags( array $tags ) { foreach( $tags as $tag ) { $this->object->flushByTag( $this->prefix . $tag ); } }
php
{ "resource": "" }
q6062
Typo3.clear
train
public function clear() { if( $this->prefix ) { $this->object->flushByTag( $this->prefix . 'siteid' ); } else { $this->object->flush(); } }
php
{ "resource": "" }
q6063
FileManager.getFile
train
public function getFile($file = null, $md5 = null) { //====================================================================// // Stack Trace Splash::log()->trace(); //====================================================================// // PHPUNIT Exception => Look First in Local FileSystem //====================================================================// if (defined('SPLASH_DEBUG') && !empty(SPLASH_DEBUG)) { $filePath = dirname(__DIR__)."/Resources/files/".$file; if (is_file($filePath)) { $file = $this->readFile($filePath, $md5); return is_array($file) ? $file : false; } $imgPath = dirname(__DIR__)."/Resources/img/".$file; if (is_file($imgPath)) { $file = $this->readFile($imgPath, $md5); return is_array($file) ? $file : false; } } //====================================================================// // Initiate Tasks parameters array $params = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); $params->file = $file; $params->md5 = $md5; //====================================================================// // Add Task to Ws Task List Splash::ws()->addTask(SPL_F_GETFILE, $params, Splash::trans("MsgSchRemoteReadFile", (string) $file)); //====================================================================// // Execute Task $response = Splash::ws()->call(SPL_S_FILE); //====================================================================// // Return First Task Result return Splash::ws()->getNextResult($response); }
php
{ "resource": "" }
q6064
FileManager.isFile
train
public function isFile($path = null, $md5 = null) { //====================================================================// // Safety Checks if (empty($path)) { return Splash::log()->err("ErrFileFileMissing", __FUNCTION__); } if (empty(dirname($path))) { return Splash::log()->err("ErrFileDirMissing", __FUNCTION__); } if (empty($md5)) { return Splash::log()->err("ErrFileMd5Missing", __FUNCTION__); } //====================================================================// // Check if folder exists if (!is_dir(dirname($path))) { return Splash::log()->war("ErrFileDirNoExists", __FUNCTION__, dirname($path)); } //====================================================================// // Check if file exists if (!is_file($path)) { return Splash::log()->war("ErrFileNoExists", __FUNCTION__, $path); } //====================================================================// // Check File CheckSum => No Diff with Previous Error for Higher Safety Level if (md5_file($path) != $md5) { return Splash::log()->war("ErrFileNoExists", __FUNCTION__, $path); } //====================================================================// // Read file Informations Splash::log()->deb("Splash - Get File Infos : File ".$path." exists."); $infos = array(); $owner = posix_getpwuid((int) fileowner($path)); $infos["owner"] = $owner["name"]; $infos["readable"] = is_readable($path); $infos["writable"] = is_writable($path); $infos["mtime"] = filemtime($path); $infos["modified"] = date("F d Y H:i:s.", (int) $infos["mtime"]); $infos["md5"] = md5_file($path); $infos["size"] = filesize($path); return $infos; }
php
{ "resource": "" }
q6065
FileManager.readFile
train
public function readFile($path = null, $md5 = null) { //====================================================================// // Safety Checks if (empty($path)) { return Splash::log()->err("ErrFileFileMissing", __FUNCTION__); } if (empty(dirname($path))) { return Splash::log()->err("ErrFileDirMissing", __FUNCTION__); } if (empty($md5)) { return Splash::log()->err("ErrFileMd5Missing", __FUNCTION__); } //====================================================================// // Check if folder exists if (!is_dir(dirname($path))) { return Splash::log()->war("ErrFileDirNoExists", __FUNCTION__, dirname($path)); } //====================================================================// // Check if file exists if (!is_file($path) || !is_readable($path)) { return Splash::log()->war("ErrFileReadable", __FUNCTION__, $path); } //====================================================================// // Check File CheckSum => No Diff with Previous Error for Higher Safety Level if (md5_file($path) != $md5) { return Splash::log()->war("ErrFileNoExists", __FUNCTION__, $path); } //====================================================================// // Open File $filehandle = fopen($path, "rb"); if (false == $filehandle) { return Splash::log()->err("ErrFileRead", __FUNCTION__, $path); } //====================================================================// // Fill file Informations $infos = array(); $infos["filename"] = basename($path); $infos["raw"] = base64_encode((string) fread($filehandle, (int) filesize($path))); fclose($filehandle); $infos["md5"] = md5_file($path); $infos["size"] = filesize($path); Splash::log()->deb("MsgFileRead", __FUNCTION__, basename($path)); return $infos; }
php
{ "resource": "" }
q6066
FileManager.readFileContents
train
public function readFileContents($fileName = null) { //====================================================================// // Safety Checks if (empty($fileName)) { return Splash::log()->err("ErrFileFileMissing"); } //====================================================================// // Check if file exists if (!is_file($fileName)) { return Splash::log()->err("ErrFileNoExists", $fileName); } //====================================================================// // Check if file is readable if (!is_readable($fileName)) { return Splash::log()->err("ErrFileReadable", $fileName); } Splash::log()->deb("MsgFileRead", $fileName); //====================================================================// // Read File Contents return base64_encode((string) file_get_contents($fileName)); }
php
{ "resource": "" }
q6067
FileManager.writeFile
train
public function writeFile($dir = null, $file = null, $md5 = null, $raw = null) { //====================================================================// // Safety Checks if (!$this->isWriteValidInputs($dir, $file, $md5, $raw)) { return false; } //====================================================================// // Assemble full Filename $fullpath = $dir.$file; //====================================================================// // Check if folder exists or create it if (!is_dir((string) $dir)) { mkdir((string) $dir, 0775, true); } //====================================================================// // Check if folder exists if (!is_dir((string) $dir)) { Splash::log()->war("ErrFileDirNoExists", __FUNCTION__, $dir); } //====================================================================// // Check if file exists if (is_file($fullpath)) { Splash::log()->deb("MsgFileExists", __FUNCTION__, $file); //====================================================================// // Check if file is different if ($md5 === md5_file($fullpath)) { return true; } //====================================================================// // Check if file is writable if (!is_writable((string) $fullpath)) { return Splash::log()->err("ErrFileWriteable", __FUNCTION__, $file); } } //====================================================================// // Open File $filehandle = fopen($fullpath, 'w'); if (false == $filehandle) { return Splash::log()->war("ErrFileOpen", __FUNCTION__, $fullpath); } //====================================================================// // Write file fwrite($filehandle, (string) base64_decode((string) $raw, true)); fclose($filehandle); clearstatcache(); //====================================================================// // Verify file checksum if ($md5 !== md5_file($fullpath)) { return Splash::log()->err("ErrFileWrite", __FUNCTION__, $file); } return true; }
php
{ "resource": "" }
q6068
FileManager.deleteFile
train
public function deleteFile($path = null, $md5 = null) { $fPath = (string) $path; //====================================================================// // Safety Checks if (empty(dirname($fPath))) { return Splash::log()->err("ErrFileDirMissing", __FUNCTION__); } if (empty(basename($fPath))) { return Splash::log()->err("ErrFileFileMissing", __FUNCTION__); } if (empty($md5)) { return Splash::log()->err("ErrFileMd5Missing", __FUNCTION__); } //====================================================================// // Check if folder exists if (!is_dir(dirname($fPath))) { Splash::log()->war("ErrFileDirNoExists", __FUNCTION__, dirname($fPath)); } //====================================================================// // Check if file exists if (is_file($fPath) && (md5_file($fPath) === $md5)) { Splash::log()->deb("MsgFileExists", __FUNCTION__, basename($fPath)); //====================================================================// // Delete File if (unlink($fPath)) { return Splash::log()->deb("MsgFileDeleted", __FUNCTION__, basename($fPath)); } return Splash::log()->err("ErrFileDeleted", __FUNCTION__, basename($fPath)); } return true; }
php
{ "resource": "" }
q6069
FileManager.isWriteValidInputs
train
private function isWriteValidInputs($dir = null, $file = null, $md5 = null, $raw = null) { //====================================================================// // Safety Checks if (empty($dir)) { return Splash::log()->err("ErrFileDirMissing", __FUNCTION__); } if (empty($file)) { return Splash::log()->err("ErrFileFileMissing", __FUNCTION__); } if (empty($md5)) { return Splash::log()->err("ErrFileMd5Missing", __FUNCTION__); } if (empty($raw)) { return Splash::log()->err("ErrFileRawMissing", __FUNCTION__); } return true; }
php
{ "resource": "" }
q6070
CreateCardRefQuery.checkPaymentTransactionStatus
train
protected function checkPaymentTransactionStatus(PaymentTransaction $paymentTransaction) { if (!$paymentTransaction->isFinished()) { throw new ValidationException('Only finished payment transaction can be used for create-card-ref-id'); } if (!$paymentTransaction->getPayment()->isPaid()) { throw new ValidationException("Can not use new payment for create-card-ref-id. Execute 'sale' or 'preauth' query first"); } }
php
{ "resource": "" }
q6071
GatewayClient.parseReponse
train
protected function parseReponse($response) { if(empty($response)) { throw new ResponseException('PaynetEasy response is empty'); } $responseFields = array(); parse_str($response, $responseFields); return new Response($responseFields); }
php
{ "resource": "" }
q6072
GatewayClient.getUrl
train
protected function getUrl(Request $request) { if (strpos($request->getApiMethod(), 'sync-') === 0) { $apiMethod = 'sync/' . substr($request->getApiMethod(), strlen('sync-')); } else { $apiMethod = $request->getApiMethod(); } if (strlen($request->getEndPointGroup()) > 0) { $endPoint = "group/{$request->getEndPointGroup()}"; } else { $endPoint = (string) $request->getEndPoint(); } return "{$request->getGatewayUrl()}/{$apiMethod}/{$endPoint}"; }
php
{ "resource": "" }
q6073
TokenGenerator.generateToken
train
public function generateToken($token_length=30, $prefix='') { $token_length = $token_length - strlen($prefix); if ($token_length < 0) { throw new Exception("Prefix is too long", 1); } $token = ""; while (($len = strlen($token)) < $token_length) { $remaining_len = $token_length - $len; $bytes = random_bytes($remaining_len); $token .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $remaining_len); } return $prefix.$token; }
php
{ "resource": "" }
q6074
Validator.validateByRule
train
static public function validateByRule($value, $rule, $failOnError = true) { $valid = false; switch ($rule) { case self::EMAIL: { $valid = filter_var($value, FILTER_VALIDATE_EMAIL); break; } case self::IP: { $valid = filter_var($value, FILTER_VALIDATE_IP); break; } case self::URL: { $valid = filter_var($value, FILTER_VALIDATE_URL); break; } case self::MONTH: { $valid = in_array($value, range(1, 12)); break; } case self::COUNTRY: { $valid = RegionFinder::hasCountryByCode($value); break; } case self::STATE: { $valid = RegionFinder::hasStateByCode($value); break; } default: { if (isset(static::$ruleRegExps[$rule])) { $valid = static::validateByRegExp($value, static::$ruleRegExps[$rule], $failOnError); } else { $valid = static::validateByRegExp($value, $rule, $failOnError); } } } if ($valid !== false) { return true; } elseif ($failOnError === true) { throw new ValidationException("Value '{$value}' does not match rule '{$rule}'"); } else { return false; } }
php
{ "resource": "" }
q6075
FieldsFactory.create
train
public function create($fieldType, $fieldId = null, $fieldName = null) { //====================================================================// // Commit Last Created if not already done if (!empty($this->new)) { $this->commit(); } //====================================================================// // Unset Current $this->new = null; //====================================================================// // Create new empty field $this->new = new ArrayObject($this->empty, ArrayObject::ARRAY_AS_PROPS); //====================================================================// // Set Field Type $this->new->type = $fieldType; //====================================================================// // Set Field Identifier if (!is_null($fieldId)) { $this->identifier($fieldId); } //====================================================================// // Set Field Name if (!is_null($fieldName)) { $this->name($fieldName); } return $this; }
php
{ "resource": "" }
q6076
FieldsFactory.identifier
train
public function identifier($fieldId) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->id = $fieldId; } return $this; }
php
{ "resource": "" }
q6077
FieldsFactory.inList
train
public function inList($listName) { //====================================================================// // Safety Checks ==> Verify List Name Not Empty if (empty($listName)) { return $this; } //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field Identifier $this->new->id = $this->new->id.LISTSPLIT.$listName; //====================================================================// // Update New Field Type $this->new->type = $this->new->type.LISTSPLIT.SPL_T_LIST; } return $this; }
php
{ "resource": "" }
q6078
FieldsFactory.isReadOnly
train
public function isReadOnly($isReadOnly = true) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } elseif ($isReadOnly) { //====================================================================// // Update New Field structure $this->new->read = true; $this->new->write = false; } return $this; }
php
{ "resource": "" }
q6079
FieldsFactory.isWriteOnly
train
public function isWriteOnly($isWriteOnly = true) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } elseif ($isWriteOnly) { //====================================================================// // Update New Field structure $this->new->read = false; $this->new->write = true; } return $this; }
php
{ "resource": "" }
q6080
FieldsFactory.isRequired
train
public function isRequired($isRequired = true) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->required = (bool) $isRequired; } return $this; }
php
{ "resource": "" }
q6081
FieldsFactory.setPreferRead
train
public function setPreferRead() { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->syncmode = self::MODE_READ; } return $this; }
php
{ "resource": "" }
q6082
FieldsFactory.setPreferWrite
train
public function setPreferWrite() { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->syncmode = self::MODE_WRITE; } return $this; }
php
{ "resource": "" }
q6083
FieldsFactory.setPreferNone
train
public function setPreferNone() { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->syncmode = self::MODE_NONE; } return $this; }
php
{ "resource": "" }
q6084
FieldsFactory.association
train
public function association() { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Field Clear Fields Associations if (!empty($this->new->asso)) { $this->new->asso = null; } //====================================================================// // Set New Field Associations if (!empty(func_get_args())) { $this->new->asso = func_get_args(); } } return $this; }
php
{ "resource": "" }
q6085
FieldsFactory.isListed
train
public function isListed($isListed = true) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->inlist = (bool) $isListed; } return $this; }
php
{ "resource": "" }
q6086
FieldsFactory.isLogged
train
public function isLogged($isLogged = true) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->log = (bool) $isLogged; } return $this; }
php
{ "resource": "" }
q6087
FieldsFactory.microData
train
public function microData($itemType, $itemProp) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->itemtype = $itemType; $this->new->itemprop = $itemProp; $this->setTag($itemProp.IDSPLIT.$itemType); } return $this; }
php
{ "resource": "" }
q6088
FieldsFactory.addOptions
train
public function addOptions($fieldOptions) { foreach ($fieldOptions as $type => $value) { $this->addOption($type, $value); } return $this; }
php
{ "resource": "" }
q6089
FieldsFactory.addOption
train
public function addOption($type, $value = true) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } elseif (empty($type)) { Splash::log()->err("Field Option Type Cannot be Empty"); } else { //====================================================================// // Update New Field structure $this->new->options[$type] = $value; } return $this; }
php
{ "resource": "" }
q6090
FieldsFactory.setDefaultLanguage
train
public function setDefaultLanguage($isoCode) { //====================================================================// // Safety Checks ==> Verify Language ISO Code if (!is_string($isoCode) || (strlen($isoCode) < 2)) { Splash::log()->err("Default Language ISO Code is Invalid"); return $this; } //====================================================================// // Store Default Language ISO Code $this->dfLanguage = $isoCode; return $this; }
php
{ "resource": "" }
q6091
FieldsFactory.setMultilang
train
public function setMultilang($isoCode) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); return $this; } //====================================================================// // Safety Checks ==> Verify Language ISO Code if (!is_string($isoCode) || (strlen($isoCode) < 2)) { Splash::log()->err("Language ISO Code is Invalid"); return $this; } //====================================================================// // Safety Checks ==> Verify Field Type is Allowed if (!in_array($this->new->type, array(SPL_T_VARCHAR, SPL_T_TEXT), true)) { Splash::log()->err("ErrFieldsWrongLang"); Splash::log()->err("Received: ".$this->new->type); return $this; } //====================================================================// // Default Language ==> Only Setup Language Option $this->addOption("language", $isoCode); //====================================================================// // Other Language ==> Complete Field Setup if ($isoCode != $this->dfLanguage) { $this->identifier($this->new->id."_".$isoCode); if (!empty($this->new->itemtype)) { $this->microData($this->new->itemtype."/".$isoCode, $this->new->itemprop); } } return $this; }
php
{ "resource": "" }
q6092
FieldsFactory.seachtByTag
train
public function seachtByTag($fieldList, $fieldTag) { //====================================================================// // Safety Checks if (!count($fieldList)) { return false; } if (empty($fieldTag)) { return false; } //====================================================================// // Walk Through List and select by Tag foreach ($fieldList as $field) { if ($field["tag"] == $fieldTag) { return $field; } } return false; }
php
{ "resource": "" }
q6093
FieldsFactory.seachtById
train
public function seachtById($fieldList, $fieldId) { //====================================================================// // Safety Checks if (!count($fieldList)) { return false; } if (empty($fieldId)) { return false; } //====================================================================// // Walk Through List and select by Tag foreach ($fieldList as $field) { if ($field["id"] == $fieldId) { return $field; } } return false; }
php
{ "resource": "" }
q6094
FieldsFactory.setTag
train
private function setTag($fieldTag) { //====================================================================// // Safety Checks ==> Verify a new Field Exists if (empty($this->new)) { Splash::log()->err("ErrFieldsNoNew"); } else { //====================================================================// // Update New Field structure $this->new->tag = md5($fieldTag); } return $this; }
php
{ "resource": "" }
q6095
FieldsFactory.validate
train
private function validate($field) { //====================================================================// // Verify - Field Type is Not Empty if (empty($field->type) || !is_string($field->type)) { return Splash::log()->err("ErrFieldsNoType"); } //====================================================================// // Verify - Field Id is Not Empty if (empty($field->id) || !is_string($field->id)) { return Splash::log()->err("ErrFieldsNoId"); } //====================================================================// // Verify - Field Id No Spacial Chars if ($field->id !== preg_replace('/[^a-zA-Z0-9-_@]/u', '', $field->id)) { Splash::log()->war("ErrFieldsInvalidId", $field->id); return false; } //====================================================================// // Verify - Field Name is Not Empty if (empty($field->name) || !is_string($field->name)) { return Splash::log()->err("ErrFieldsNoName"); } //====================================================================// // Verify - Field Desc is Not Empty if (empty($field->desc) || !is_string($field->desc)) { return Splash::log()->err("ErrFieldsNoDesc"); } return true; }
php
{ "resource": "" }
q6096
ContactController.postSubmit
train
public function postSubmit() { $rules = [ 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'message' => 'required', ]; $input = Binput::only(array_keys($rules)); $val = Validator::make($input, $rules); if ($val->fails()) { return Redirect::to($this->path)->withInput()->withErrors($val); } $this->throttler->hit(); Mailer::send($input['first_name'], $input['last_name'], $input['email'], $input['message']); return Redirect::to('/')->with('success', 'Your message was sent successfully. Thank you for contacting us.'); }
php
{ "resource": "" }
q6097
PHPMailer.EncodeString
train
public function EncodeString($str, $encoding = 'base64') { $encoded = ''; switch (strtolower($encoding)) { case 'base64': $encoded = chunk_split(base64_encode($str), 76, $this->LE); break; case '7bit': case '8bit': $encoded = $this->FixEOL($str); //Make sure it ends with a line break if (substr($encoded, -(strlen($this->LE))) != $this->LE) { $encoded .= $this->LE; } break; case 'binary': $encoded = $str; break; case 'quoted-printable': $encoded = $this->EncodeQP($str); break; default: $this->SetError($this->Lang('encoding') . $encoding); break; } return $encoded; }
php
{ "resource": "" }
q6098
PHPMailer._mime_types
train
public static function _mime_types($ext = '') { $mimes = array( 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'doc' => 'application/msword', 'bin' => 'application/macbinary', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'class' => 'application/octet-stream', 'psd' => 'application/octet-stream', 'so' => 'application/octet-stream', 'sea' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'gtar' => 'application/x-gtar', 'php' => 'application/x-httpd-php', 'php4' => 'application/x-httpd-php', 'php3' => 'application/x-httpd-php', 'phtml' => 'application/x-httpd-php', 'phps' => 'application/x-httpd-php-source', 'js' => 'application/x-javascript', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'tar' => 'application/x-tar', 'tgz' => 'application/x-tar', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'zip' => 'application/zip', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 'rv' => 'video/vnd.rn-realvideo', 'wav' => 'audio/x-wav', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'shtml' => 'text/html', 'txt' => 'text/plain', 'text' => 'text/plain', 'log' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'xml' => 'text/xml', 'xsl' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'doc' => 'application/msword', 'word' => 'application/msword', 'xl' => 'application/excel', 'eml' => 'message/rfc822', ); return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; }
php
{ "resource": "" }
q6099
SMTP.StartTLS
train
public function StartTLS() { $this->error = null; # to avoid confusion if (!$this->connected()) { $this->error = array("error" => "Called StartTLS() without being connected"); return false; } fputs($this->smtp_conn, "STARTTLS" . $this->CRLF); $rply = $this->get_lines(); $code = substr($rply, 0, 3); if ($this->do_debug >= 2) { echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; } if ($code != 220) { $this->error = array("error" => "STARTTLS not accepted from server", "smtp_code" => $code, "smtp_msg" => substr($rply, 4)); if ($this->do_debug >= 1) { echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; } return false; } // Begin encrypted connection if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { return false; } return true; }
php
{ "resource": "" }