_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q245500
Manager.getSubscribers
validation
public function getSubscribers($eventName = null) { if ($eventName !== null) { if (!isset($this->subscribers[$eventName])) { return array(); } if (!isset($this->sorted[$eventName])) { $this->sortSubscribers($eventName); } return $this->sorted[$eventName]; } // return all subscribers foreach (\array_keys($this->subscribers) as $eventName) { if (!isset($this->sorted[$eventName])) { $this->sortSubscribers($eventName); } } return \array_filter($this->sorted); }
php
{ "resource": "" }
q245501
Manager.hasSubscribers
validation
public function hasSubscribers($eventName = null) { if ($eventName !== null) { return !empty($this->subscribers[$eventName]); } foreach ($this->subscribers as $subscribers) { if ($subscribers) { return true; } } return false; }
php
{ "resource": "" }
q245502
Manager.removeSubscriberInterface
validation
public function removeSubscriberInterface(SubscriberInterface $interface) { $subscribers = $this->getInterfaceSubscribers($interface); foreach ($subscribers as $row) { $this->unsubscribe($row[0], $row[1], $row[2]); } return $subscribers; }
php
{ "resource": "" }
q245503
Manager.subscribe
validation
public function subscribe($eventName, $callable, $priority = 0) { unset($this->sorted[$eventName]); // clear the sorted cache $this->subscribers[$eventName][$priority][] = $callable; }
php
{ "resource": "" }
q245504
Manager.unsubscribe
validation
public function unsubscribe($eventName, $callable) { if (!isset($this->subscribers[$eventName])) { return; } if ($this->isClosureFactory($callable)) { // factory / lazy subscriber $callable[0] = $callable[0](); } foreach ($this->subscribers[$eventName] as $priority => $subscribers) { foreach ($subscribers as $k => $v) { if ($v !== $callable && $this->isClosureFactory($v)) { $v[0] = $v[0](); } if ($v === $callable) { unset($subscribers[$k], $this->sorted[$eventName]); } else { $subscribers[$k] = $v; } } if ($subscribers) { $this->subscribers[$eventName][$priority] = $subscribers; } else { unset($this->subscribers[$eventName][$priority]); } } }
php
{ "resource": "" }
q245505
Manager.doPublish
validation
protected function doPublish($eventName, $subscribers, Event $event) { foreach ($subscribers as $callable) { if ($event->isPropagationStopped()) { break; } \call_user_func($callable, $event, $eventName, $this); } }
php
{ "resource": "" }
q245506
Manager.sortSubscribers
validation
private function sortSubscribers($eventName) { \krsort($this->subscribers[$eventName]); $this->sorted[$eventName] = array(); foreach ($this->subscribers[$eventName] as $priority => $subscribers) { foreach ($subscribers as $k => $subscriber) { if ($this->isClosureFactory($subscriber)) { $subscriber[0] = $subscriber[0](); $this->subscribers[$eventName][$priority][$k] = $subscriber; } $this->sorted[$eventName][] = $subscriber; } } }
php
{ "resource": "" }
q245507
FileStreamWrapper.register
validation
public static function register($pathsExclude = array()) { $result = \stream_wrapper_unregister(static::PROTOCOL); if ($result === false) { throw new \UnexpectedValueException('Failed to unregister'); } if ($pathsExclude) { self::$pathsExclude = $pathsExclude; } \stream_wrapper_register(static::PROTOCOL, \get_called_class()); /* Disable OPcache a) want to make sure we modify required files b) don't want to cache modified files */ \ini_set('opcache.enable', 0); }
php
{ "resource": "" }
q245508
FileStreamWrapper.dir_closedir
validation
public function dir_closedir() { if (!$this->handle) { return false; } self::restorePrev(); \closedir($this->handle); self::register(); $this->handle = null; return true; }
php
{ "resource": "" }
q245509
FileStreamWrapper.dir_opendir
validation
public function dir_opendir($path, $options = 0) { if ($this->handle) { return false; } // "use" our function params so things don't complain array($options); self::restorePrev(); $this->handle = \opendir($path); self::register(); return $this->handle !== false; }
php
{ "resource": "" }
q245510
FileStreamWrapper.dir_readdir
validation
public function dir_readdir() { if (!$this->handle) { return false; } self::restorePrev(); $success = \readdir($this->handle); self::register(); return $success; }
php
{ "resource": "" }
q245511
FileStreamWrapper.dir_rewinddir
validation
public function dir_rewinddir() { if (!$this->handle) { return false; } self::restorePrev(); \rewinddir($this->handle); self::register(); return true; }
php
{ "resource": "" }
q245512
FileStreamWrapper.rename
validation
public function rename($pathFrom, $pathTo) { self::restorePrev(); $success = \rename($pathFrom, $pathTo); self::register(); return $success; }
php
{ "resource": "" }
q245513
FileStreamWrapper.stream_close
validation
public function stream_close() { if (!$this->handle) { return; } self::restorePrev(); \fclose($this->handle); $this->handle = null; self::register(); }
php
{ "resource": "" }
q245514
FileStreamWrapper.stream_eof
validation
public function stream_eof() { if (!$this->handle) { return false; } self::restorePrev(); $result = \feof($this->handle); self::register(); return $result; }
php
{ "resource": "" }
q245515
FileStreamWrapper.stream_flush
validation
public function stream_flush() { if (!$this->handle) { return false; } self::restorePrev(); $success = \fflush($this->handle); self::register(); return $success; }
php
{ "resource": "" }
q245516
FileStreamWrapper.stream_lock
validation
public function stream_lock($operation) { if (!$this->handle) { return false; } self::restorePrev(); $success = \flock($this->handle, $operation); self::register(); return $success; }
php
{ "resource": "" }
q245517
FileStreamWrapper.stream_metadata
validation
public function stream_metadata($path, $option, $value) { self::restorePrev(); switch ($option) { case STREAM_META_TOUCH: if (!empty($value)) { $success = \touch($path, $value[0], $value[1]); } else { $success = \touch($path); } break; case STREAM_META_OWNER_NAME: // Fall through case STREAM_META_OWNER: $success = \chown($path, $value); break; case STREAM_META_GROUP_NAME: // Fall through case STREAM_META_GROUP: $success = \chgrp($path, $value); break; case STREAM_META_ACCESS: $success = \chmod($path, $value); break; default: $success = false; } self::register(); return $success; }
php
{ "resource": "" }
q245518
FileStreamWrapper.stream_open
validation
public function stream_open($path, $mode, $options, &$openedPath) { if ($this->handle) { return false; } $useIncludePath = (bool) $options & STREAM_USE_PATH; $context = $this->context; if ($context === null) { $context = \stream_context_get_default(); } self::restorePrev(); if (\strpos($mode, 'r') !== false && !\file_exists($path)) { return false; } elseif (\strpos($mode, 'x') !== false && \file_exists($path)) { return false; } $handle = \fopen($path, $mode, $useIncludePath, $context); self::register(); if ($handle === false) { return false; } /* Determine opened path */ $meta = \stream_get_meta_data($handle); if (!isset($meta['uri'])) { throw new \UnexpectedValueException('Uri not in meta data'); } $this->filepath = $openedPath = $meta['uri']; $this->handle = $handle; return true; }
php
{ "resource": "" }
q245519
FileStreamWrapper.stream_read
validation
public function stream_read($count) { if (!$this->handle) { return false; } self::restorePrev(); $buffer = \fread($this->handle, $count); $bufferLen = \strlen($buffer); $backtrace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $isRequire = !\in_array($backtrace[1]['function'], array('file_get_contents')); if (!$this->declaredTicks && $isRequire) { foreach (self::$pathsExclude as $excludePath) { if (\strpos($this->filepath, $excludePath.DIRECTORY_SEPARATOR) === 0) { $this->declaredTicks = true; } } } if (!$this->declaredTicks && $isRequire) { // insert declare(ticks=1); without adding any new lines $buffer = \preg_replace( '/^(<\?php\s*)$/m', '$0 declare(ticks=1);', $buffer, 1 ); $this->declaredTicks = true; self::$filesModified[] = $this->filepath; } $buffer = $this->bufferPrepend.$buffer; $bufferLenAfter = \strlen($buffer); $diff = $bufferLenAfter - $bufferLen; $this->bufferPrepend = ''; if ($diff) { $this->bufferPrepend = \substr($buffer, $count); $buffer = \substr($buffer, 0, $count); } self::register(); return $buffer; }
php
{ "resource": "" }
q245520
FileStreamWrapper.stream_seek
validation
public function stream_seek($offset, $whence = SEEK_SET) { if (!$this->handle) { return false; } self::restorePrev(); $result = \fseek($this->handle, $offset, $whence); $success = $result !== -1; self::register(); return $success; }
php
{ "resource": "" }
q245521
FileStreamWrapper.stream_stat
validation
public function stream_stat() { if (!$this->handle) { return false; } self::restorePrev(); $array = \fstat($this->handle); self::register(); return $array; }
php
{ "resource": "" }
q245522
FileStreamWrapper.stream_tell
validation
public function stream_tell() { if (!$this->handle) { return false; } self::restorePrev(); $position = \ftell($this->handle); self::register(); return $position; }
php
{ "resource": "" }
q245523
FileStreamWrapper.stream_truncate
validation
public function stream_truncate($size) { if (!$this->handle) { return false; } self::restorePrev(); $success = \ftruncate($this->handle, $size); self::register(); return $success; }
php
{ "resource": "" }
q245524
FileStreamWrapper.unlink
validation
public function unlink($path) { self::restorePrev(); $success = \unlink($path); self::register(); return $success; }
php
{ "resource": "" }
q245525
FileStreamWrapper.url_stat
validation
public function url_stat($path, $flags) { self::restorePrev(); if (!\file_exists($path)) { $info = false; } elseif ($flags & STREAM_URL_STAT_LINK) { $info = $flags & STREAM_URL_STAT_QUIET ? @\lstat($path) : \lstat($path); } else { $info = $flags & STREAM_URL_STAT_QUIET ? @\stat($path) : \stat($path); } self::register(); return $info; }
php
{ "resource": "" }
q245526
ChromeLogger.onOutput
validation
public function onOutput(Event $event) { $this->channelName = $this->debug->getCfg('channel'); $this->data = $this->debug->getData(); $this->processAlerts(); $this->processSummary(); $this->processLog(); if ($this->json['rows']) { \array_unshift($this->json['rows'], array( array('PHP', isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'] : '$: '. \implode(' ', $_SERVER['argv']) ), null, 'groupCollapsed', )); \array_push($this->json['rows'], array( array(), null, 'groupEnd', )); $encoded = $this->encode($this->json); if (\strlen($encoded) > 250000) { $this->debug->warn('chromeLogger: output limit exceeded'); } else { $event['headers'][] = array(self::HEADER_NAME, $encoded); } } $this->data = array(); $this->json['rows'] = array(); }
php
{ "resource": "" }
q245527
ChromeLogger.processLogEntry
validation
public function processLogEntry($method, $args = array(), $meta = array()) { if ($method === 'alert') { list($method, $args) = $this->methodAlert($args, $meta); } elseif ($method == 'assert') { \array_unshift($args, false); } elseif (\in_array($method, array('count','time'))) { $method = 'log'; } elseif (\in_array($method, array('profileEnd','table'))) { $method = 'log'; if (\is_array($args[0])) { $method = 'table'; $args = array($this->methodTable($args[0], $meta['columns'])); } elseif ($meta['caption']) { \array_unshift($args, $meta['caption']); } } elseif ($method === 'trace') { $method = 'table'; $args = array($this->methodTable($args[0], array('function','file','line'))); } if (!\in_array($method, $this->consoleMethods)) { $method = 'log'; } foreach ($args as $i => $arg) { $args[$i] = $this->dump($arg); } $this->json['rows'][] = array( $args, isset($meta['file']) ? $meta['file'].': '.$meta['line'] : null, $method === 'log' ? '' : $method, ); }
php
{ "resource": "" }
q245528
Wamp.getSubscriptions
validation
public function getSubscriptions() { if (!$this->isConnected()) { $this->debug->alert('WAMP publisher not connected to WAMP router'); return array(); } $this->publishMeta(); $this->processExistingData(); return array( 'debug.log' => array('onLog', PHP_INT_MAX * -1), 'errorHandler.error' => 'onError', // assumes errorhandler is using same dispatcher.. as should be 'php.shutdown' => array('onShutdown', PHP_INT_MAX * -1), ); }
php
{ "resource": "" }
q245529
Wamp.onError
validation
public function onError(Event $event) { if ($event['inConsole'] || !$event['isFirstOccur']) { return; } $this->processLogEntry( 'errorNotConsoled', array( $event['typeStr'].': '.$event['file'].' (line '.$event['line'].'): '.$event['message'] ), array( 'channel' => 'phpError', 'class' => $event['type'] & $this->debug->getCfg('errorMask') ? 'danger' : 'warning', ) ); }
php
{ "resource": "" }
q245530
Wamp.processLogEntry
validation
public function processLogEntry($method, $args = array(), $meta = array()) { $meta = \array_merge(array( 'format' => 'raw', 'requestId' => $this->requestId, ), $meta); if ($meta['channel'] == $this->debug->getCfg('channel')) { unset($meta['channel']); } if ($meta['format'] == 'raw') { $args = $this->crateValues($args); } if (!empty($meta['backtrace'])) { $meta['backtrace'] = $this->crateValues($meta['backtrace']); } $this->wamp->publish($this->topic, array($method, $args, $meta)); }
php
{ "resource": "" }
q245531
Wamp.processExistingData
validation
private function processExistingData() { $data = $this->debug->getData(); $channelName = $this->debug->getCfg('channel'); foreach ($data['alerts'] as $entry) { $this->processLogEntryWEvent($entry[0], $entry[1], $entry[2]); } foreach ($data['logSummary'] as $priority => $entries) { $this->processLogEntryWEvent( 'groupSummary', array(), array( 'channel' => $channelName, 'priority'=> $priority, ) ); foreach ($entries as $entry) { $this->processLogEntryWEvent($entry[0], $entry[1], $entry[2]); } $this->processLogEntryWEvent( 'groupEnd', array(), array( 'channel' => $channelName, 'closesSummary'=>true, ) ); } foreach ($data['log'] as $entry) { $this->processLogEntryWEvent($entry[0], $entry[1], $entry[2]); } }
php
{ "resource": "" }
q245532
Wamp.publishMeta
validation
private function publishMeta() { $debugClass = \get_class($this->debug); $metaVals = array( 'debug_version' => $debugClass::VERSION, ); $keys = array( 'HTTP_HOST', 'HTTPS', 'REMOTE_ADDR', 'REQUEST_METHOD', 'REQUEST_TIME', 'REQUEST_URI', 'SERVER_ADDR', 'SERVER_NAME', ); foreach ($keys as $k) { $metaVals[$k] = isset($_SERVER[$k]) ? $_SERVER[$k] : null; } if (!isset($metaVals['REQUEST_URI']) && !empty($_SERVER['argv'])) { $metaVals['REQUEST_URI'] = '$: '. \implode(' ', $_SERVER['argv']); } $this->processLogEntry( 'meta', array( $metaVals, ), array( 'channel' => $this->debug->getCfg('channel'), ) ); }
php
{ "resource": "" }
q245533
Abstracter.getCfg
validation
public function getCfg($path = null) { if (!\strlen($path)) { return $this->cfg; } if (isset($this->cfg[$path])) { return $this->cfg[$path]; } return null; }
php
{ "resource": "" }
q245534
Abstracter.getAbstraction
validation
public function getAbstraction(&$mixed, $method = null, $hist = array()) { if (\is_array($mixed)) { return $this->abstractArray->getAbstraction($mixed, $method, $hist); } elseif (\is_object($mixed)) { return $this->abstractObject->getAbstraction($mixed, $method, $hist); } elseif (\is_resource($mixed) || \strpos(\print_r($mixed, true), 'Resource') === 0) { return array( 'debug' => self::ABSTRACTION, 'type' => 'resource', 'value' => \print_r($mixed, true).': '.\get_resource_type($mixed), ); } }
php
{ "resource": "" }
q245535
Abstracter.getType
validation
public static function getType($val, &$typeMore = null) { if (\is_string($val)) { $type = 'string'; if (\is_numeric($val)) { $typeMore = 'numeric'; } elseif ($val === self::UNDEFINED) { $type = 'undefined'; // not a native php type! } elseif ($val === self::RECURSION) { $type = 'recursion'; // not a native php type! } } elseif (\is_array($val)) { if (\in_array(self::ABSTRACTION, $val, true)) { $type = $val['type']; $typeMore = 'abstraction'; } elseif (AbstractArray::isCallable($val)) { $type = 'callable'; $typeMore = 'raw'; // needs abstracted } else { $type = 'array'; $typeMore = 'raw'; // needs abstracted } } elseif (\is_bool($val)) { $type = 'bool'; $typeMore = \json_encode($val); } elseif (\is_float($val)) { $type = 'float'; } elseif (\is_int($val)) { $type = 'int'; } elseif (\is_null($val)) { $type = 'null'; } elseif (\is_object($val)) { $type = 'object'; $typeMore = 'raw'; // needs abstracted } elseif (\is_resource($val) || \strpos(\print_r($val, true), 'Resource') === 0) { // is_resource() returns false for a closed resource // (it's also not a string) $type = 'resource'; $typeMore = 'raw'; // needs abstracted } return $type; }
php
{ "resource": "" }
q245536
Debug.alert
validation
public function alert($message, $class = 'danger', $dismissible = false) { // "use" our function params so things don't complain array($class, $dismissible); $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']), array( 'message' => null, 'class' => 'danger', 'dismissible' => false, ), array('class','dismissible') ); \extract($args); $this->setLogDest('alerts'); $this->appendLog( 'alert', array($message), $meta ); $this->setLogDest('auto'); }
php
{ "resource": "" }
q245537
Debug.assert
validation
public function assert($assertion, $msg = null) { // "use" our function params so things don't complain array($msg); $args = \func_get_args(); $meta = $this->internal->getMetaVals($args); $assertion = \array_shift($args); if (!$assertion) { if (!$args) { $callerInfo = $this->utilities->getCallerInfo(); $args[] = 'Assertion failed in '.$callerInfo['file'].' on line '.$callerInfo['line']; } $this->appendLog('assert', $args, $meta); } }
php
{ "resource": "" }
q245538
Debug.clear
validation
public function clear($flags = self::CLEAR_LOG) { // "use" our function params so things don't complain array($flags); $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']), array('flags' => self::CLEAR_LOG), array('flags' => 'bitmask') ); $event = $this->methodClear->onLog(new Event($this, array( 'method' => __FUNCTION__, 'args' => array(), 'meta' => $meta, ))); // even if cleared from within summary, let's log this in primary log $this->setLogDest('log'); $collect = $this->cfg['collect']; $this->cfg['collect'] = true; if ($event['log']) { $this->appendLog( $event['method'], $event['args'], $event['meta'] ); } elseif ($event['publish']) { /* Publish the debug.log event (regardless of cfg.collect) don't actually log */ $this->internal->publishBubbleEvent('debug.log', $event); } $this->cfg['collect'] = $collect; $this->setLogDest('auto'); }
php
{ "resource": "" }
q245539
Debug.count
validation
public function count($label = null, $flags = 0) { $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']) ); // label may be ommitted and only flags passed as a single argument // (excluding potential meta argument) if (\count($args) == 1 && \is_int($args[0])) { $label = null; $flags = $args[0]; } else { $args = \array_combine( array('label', 'flags'), \array_replace(array(null, 0), $args) ); \extract($args); } if (isset($label)) { $dataLabel = (string) $label; } else { // determine calling file & line $callerInfo = $this->utilities->getCallerInfo(); $meta = \array_merge(array( 'file' => $callerInfo['file'], 'line' => $callerInfo['line'], ), $meta); $label = 'count'; $dataLabel = $meta['file'].': '.$meta['line']; } if (!isset($this->data['counts'][$dataLabel])) { $this->data['counts'][$dataLabel] = 0; } if (!($flags & self::COUNT_NO_INC)) { $this->data['counts'][$dataLabel]++; } $count = $this->data['counts'][$dataLabel]; if (!($flags & self::COUNT_NO_OUT)) { $this->appendLog( 'count', array( (string) $label, $count, ), $meta ); } return $count; }
php
{ "resource": "" }
q245540
Debug.countReset
validation
public function countReset($label = 'default', $flags = null) { $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']) ); // label may be ommitted and only flags passed as a single argument // (excluding potential meta argument) if (\count($args) == 1 && \is_int($args[0])) { $label = 'default'; $flags = $args[0]; } else { $args = \array_combine( array('label', 'flags'), \array_replace(array('default', 0), $args) ); \extract($args); } if (isset($this->data['counts'][$label])) { $this->data['counts'][$label] = 0; $args = array( (string) $label, 0, ); } else { $args = array('Counter \''.$label.'\' doesn\'t exist.'); } if (!($flags & self::COUNT_NO_OUT)) { $this->appendLog( 'countReset', $args, $meta ); } }
php
{ "resource": "" }
q245541
Debug.groupEnd
validation
public function groupEnd($value = \bdk\Debug\Abstracter::UNDEFINED) { $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']), array('value' => \bdk\Debug\Abstracter::UNDEFINED) ); \extract($args); $groupStackWas = $this->rootInstance->groupStackRef; $appendLog = false; if ($groupStackWas && \end($groupStackWas)['collect'] == $this->cfg['collect']) { \array_pop($this->rootInstance->groupStackRef); $appendLog = $this->cfg['collect']; } if ($appendLog && $value !== \bdk\Debug\Abstracter::UNDEFINED) { $this->appendLog( 'groupEndValue', array('return', $value), $meta ); } if ($this->data['groupPriorityStack'] && !$groupStackWas) { // we're closing a summary group $priorityClosing = \array_pop($this->data['groupPriorityStack']); // not really necessary to remove this empty placeholder, but lets keep things tidy unset($this->data['groupStacks'][$priorityClosing]); $this->setLogDest('auto'); /* Publish the debug.log event (regardless of cfg.collect) don't actually log */ $meta['closesSummary'] = true; $this->internal->publishBubbleEvent( 'debug.log', $this, array( 'method' => __FUNCTION__, 'args' => array(), 'meta' => $meta, ) ); } elseif ($appendLog) { $this->appendLog('groupEnd', array(), $meta); } $errorCaller = $this->errorHandler->get('errorCaller'); if ($errorCaller && isset($errorCaller['groupDepth']) && $this->getGroupDepth() < $errorCaller['groupDepth']) { $this->errorHandler->setErrorCaller(false); } }
php
{ "resource": "" }
q245542
Debug.groupSummary
validation
public function groupSummary($priority = 0) { // "use" our function params so things don't complain array($priority); $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']), array('priority' => 0), array('priority') ); $this->data['groupPriorityStack'][] = $meta['priority']; $this->setLogDest('summary'); /* Publish the debug.log event (regardless of cfg.collect) don't actually log */ $this->internal->publishBubbleEvent( 'debug.log', $this, array( 'method' => __FUNCTION__, 'args' => array(), 'meta' => $meta, ) ); }
php
{ "resource": "" }
q245543
Debug.groupUncollapse
validation
public function groupUncollapse() { if (!$this->cfg['collect']) { return; } $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']) ); $curDepth = 0; foreach ($this->rootInstance->groupStackRef as $group) { $curDepth += (int) $group['collect']; } $entryKeys = \array_keys($this->internal->getCurrentGroups($this->rootInstance->logRef, $curDepth)); foreach ($entryKeys as $key) { $this->rootInstance->logRef[$key][0] = 'group'; } /* Publish the debug.log event (regardless of cfg.collect) don't actually log */ $this->internal->publishBubbleEvent( 'debug.log', $this, array( 'method' => __FUNCTION__, 'args' => array(), 'meta' => $meta, ) ); }
php
{ "resource": "" }
q245544
Debug.profile
validation
public function profile($name = null) { if (!$this->cfg['collect']) { return; } if (!$this->cfg['enableProfiling']) { $callerInfo = $this->utilities->getCallerInfo(); $this->appendLog( __FUNCTION__, array('Profile: Unable to start - enableProfiling opt not set. ' . $callerInfo['file'] .' on line ' . $callerInfo['line'] . '.') ); return; } $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']), array('name' => null), array('name') // move name to meta ); if ($meta['name'] === null) { $meta['name'] = 'Profile '.$this->data['profileAutoInc']; $this->data['profileAutoInc']++; } $name = $meta['name']; $message = ''; if (isset($this->data['profileInstances'][$name])) { $instance = $this->data['profileInstances'][$name]; $instance->end(); $instance->start(); // move it to end (last started) unset($this->data['profileInstances'][$name]); $this->data['profileInstances'][$name] = $instance; $message = 'Profile \''.$name.'\' restarted'; } else { $this->data['profileInstances'][$name] = $this->methodProfile; // factory $message = 'Profile \''.$name.'\' started'; } $this->appendLog( __FUNCTION__, array( $message, ), $meta ); }
php
{ "resource": "" }
q245545
Debug.profileEnd
validation
public function profileEnd($name = null) { $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']), array('name' => null), array('name') ); if ($meta['name'] === null) { \end($this->data['profileInstances']); $meta['name'] = \key($this->data['profileInstances']); } $name = $meta['name']; if (isset($this->data['profileInstances'][$name])) { $instance = $this->data['profileInstances'][$name]; $data = $instance->end(); $caption = 'Profile \''.$name.'\' Results'; if ($data) { $args = array( $data ); $meta['sortable'] = true; $meta['caption'] = $caption; $meta['totalCols'] = array('ownTime'); $meta['columns'] = array(); } else { $args = array($caption, 'no data'); } unset($this->data['profileInstances'][$name]); } else { $args = array( $name !== null ? 'profileEnd: No such Profile: '.$name : 'profileEnd: Not currently profiling' ); } $this->appendLog( __FUNCTION__, $args, $meta ); }
php
{ "resource": "" }
q245546
Debug.table
validation
public function table() { if (!$this->cfg['collect']) { return; } $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']) ); $event = $this->methodTable->onLog(new Event($this, array( 'method' => __FUNCTION__, 'args' => $args, 'meta' => $meta, ))); $this->appendLog( $event['method'], $event['args'], $event['meta'] ); }
php
{ "resource": "" }
q245547
Debug.time
validation
public function time($label = null) { $args = \func_get_args(); $this->internal->getMetaVals( $args, array(), array('label' => null) ); \extract($args); if (isset($label)) { $timers = &$this->data['timers']['labels']; if (!isset($timers[$label])) { // new label $timers[$label] = array(0, \microtime(true)); } elseif (!isset($timers[$label][1])) { // no microtime -> the timer is currently paused -> unpause $timers[$label][1] = \microtime(true); } } else { $this->data['timers']['stack'][] = \microtime(true); } }
php
{ "resource": "" }
q245548
Debug.timeEnd
validation
public function timeEnd($label = null, $returnOrTemplate = false, $precision = 4) { $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']), array( 'label' => null, 'returnOrTemplate' => false, 'precision' => 4, ) ); \extract($args); if (\is_bool($label) || \strpos($label, '%time') !== false) { if (\is_numeric($returnOrTemplate)) { $precision = $returnOrTemplate; } $returnOrTemplate = $label; $label = null; } $ret = $this->timeGet($label, true, null); // get non-rounded running time if (isset($label)) { if (isset($this->data['timers']['labels'][$label])) { $this->data['timers']['labels'][$label] = array( $ret, // store the new "running" time null, // "pause" the timer ); } } else { $label = 'time'; \array_pop($this->data['timers']['stack']); } if (\is_int($precision)) { // use number_format rather than round(), which may still run decimals-a-plenty $ret = \number_format($ret, $precision, '.', ''); } $this->doTime($ret, $returnOrTemplate, $label, $meta); return $ret; }
php
{ "resource": "" }
q245549
Debug.trace
validation
public function trace() { if (!$this->cfg['collect']) { return; } $args = \func_get_args(); $meta = $this->internal->getMetaVals( $args, array( 'caption' => 'trace', 'channel' => $this->cfg['channel'], 'columns' => array('file','line','function'), ) ); $backtrace = $this->errorHandler->backtrace(); // toss "internal" frames for ($i = 1, $count = \count($backtrace)-1; $i < $count; $i++) { $frame = $backtrace[$i]; $function = isset($frame['function']) ? $frame['function'] : ''; if (!\preg_match('/^'.\preg_quote(__CLASS__).'(::|->)/', $function)) { break; } } $backtrace = \array_slice($backtrace, $i-1); // keep the calling file & line, but toss ->trace or ::_trace unset($backtrace[0]['function']); $this->appendLog('trace', array($backtrace), $meta); }
php
{ "resource": "" }
q245550
Debug.getChannel
validation
public function getChannel($channelName, $config = array()) { if (\strpos($channelName, '.') !== false) { $this->error('getChannel(): channelName should not contain period (.)'); return $this; } if (!isset($this->channels[$channelName])) { // get inherited config $cfg = $this->getCfg(); // remove config values that channel should not inherit $cfg = \array_diff_key($cfg, \array_flip(array( 'errorEmailer', 'errorHandler', 'output', ))); unset($cfg['debug']['onBootstrap']); // set channel values $cfg['debug']['channel'] = $this->parentInstance ? $this->cfg['channel'].'.'.$channelName : $channelName; $cfg['debug']['parent'] = $this; // instantiate channel $this->channels[$channelName] = new static($cfg); // now update config with passed config // since passed config not yet "normalized", merging above not possible if ($config) { $this->channels[$channelName]->setCfg($config); } } return $this->channels[$channelName]; }
php
{ "resource": "" }
q245551
Debug.getChannels
validation
public function getChannels($allDescendants = false) { if ($allDescendants) { $channels = array(); foreach ($this->channels as $channel) { $channels = \array_merge( $channels, array($channel->getCfg('channel') => $channel), $channel->getChannels(true) ); } return $channels; } return $this->channels; }
php
{ "resource": "" }
q245552
Debug.output
validation
public function output($options = array()) { $cfgRestore = $this->config->setCfg($options); if (!$this->cfg['output']) { $this->config->setCfg($cfgRestore); return null; } /* I'd like to put this outputAs setting bit inside Output::onOutput but, adding a debug.output subscriber from within a debug.output subscriber = fail */ $outputAs = $this->output->getCfg('outputAs'); if (\is_string($outputAs)) { $this->output->setCfg('outputAs', $outputAs); } /* Publish debug.output on all descendant channels and then ourself */ $channels = $this->getChannels(true); $channels[] = $this; $headers = array(); foreach ($channels as $channel) { $event = $channel->eventManager->publish( 'debug.output', $channel, array( 'headers' => array(), 'return' => '', 'isTarget' => $channel === $this, ) ); $headers = \array_merge($headers, $event['headers']); } if (!$this->getCfg('outputHeaders') || !$headers) { $this->data['headers'] = \array_merge($this->data['headers'], $event['headers']); } elseif (\headers_sent($file, $line)) { \trigger_error('PHPDebugConsole: headers already sent: '.$file.', line '.$line, E_USER_NOTICE); } else { foreach ($headers as $nameVal) { \header($nameVal[0].': '.$nameVal[1]); } } if (!$this->parentInstance) { $this->data['outputSent'] = true; } $this->config->setCfg($cfgRestore); return $event['return']; }
php
{ "resource": "" }
q245553
Debug.setErrorCaller
validation
public function setErrorCaller($caller = null) { if ($caller === null) { $caller = $this->utilities->getCallerInfo(1); $caller = array( 'file' => $caller['file'], 'line' => $caller['line'], ); } if ($caller) { // groupEnd will check depth and potentially clear errorCaller $caller['groupDepth'] = $this->getGroupDepth(); } $this->errorHandler->setErrorCaller($caller); }
php
{ "resource": "" }
q245554
Debug.autoloader
validation
protected function autoloader($className) { $className = \ltrim($className, '\\'); // leading backslash _shouldn't_ have been passed if (!\strpos($className, '\\')) { // className is not namespaced return; } $psr4Map = array( 'bdk\\Debug\\' => __DIR__, 'bdk\\PubSub\\' => __DIR__.'/../PubSub', 'bdk\\ErrorHandler\\' => __DIR__.'/../ErrorHandler', ); foreach ($psr4Map as $namespace => $dir) { if (\strpos($className, $namespace) === 0) { $rel = \substr($className, \strlen($namespace)); $rel = \str_replace('\\', '/', $rel); require $dir.'/'.$rel.'.php'; return; } } $classMap = array( 'bdk\\ErrorHandler' => __DIR__.'/../ErrorHandler/ErrorHandler.php', ); if (isset($classMap[$className])) { require $classMap[$className]; } }
php
{ "resource": "" }
q245555
Debug.doGroup
validation
private function doGroup($method, $args) { $meta = $this->internal->getMetaVals( $args, array('channel' => $this->cfg['channel']) ); $this->rootInstance->groupStackRef[] = array( 'channel' => $meta['channel'], 'collect' => $this->cfg['collect'], ); if (!$this->cfg['collect']) { return; } if (empty($args)) { // give a default label $caller = $this->utilities->getCallerInfo(); if (isset($caller['class'])) { $args[] = $caller['class'].$caller['type'].$caller['function']; $meta['isMethodName'] = true; } elseif (isset($caller['function'])) { $args[] = $caller['function']; } else { $args[] = 'group'; } } $this->appendLog($method, $args, $meta); }
php
{ "resource": "" }
q245556
Debug.getGroupDepth
validation
protected function getGroupDepth() { $depth = 0; foreach ($this->data['groupStacks'] as $stack) { $depth += \count($stack); } $depth += \count($this->data['groupPriorityStack']); return $depth; }
php
{ "resource": "" }
q245557
Debug.getDefaultServices
validation
private function getDefaultServices() { return array( 'abstracter' => function (Debug $debug) { return new Debug\Abstracter($debug, $debug->config->getCfgLazy('abstracter')); }, 'config' => function (Debug $debug) { return new Debug\Config($debug, $debug->cfg); // cfg is passed by reference }, 'errorEmailer' => function (Debug $debug) { return new ErrorEmailer($debug->config->getCfgLazy('errorEmailer')); }, 'errorHandler' => function (Debug $debug) { if (ErrorHandler::getInstance()) { return ErrorHandler::getInstance(); } else { $errorHandler = new ErrorHandler($debug->eventManager); /* log E_USER_ERROR to system_log without halting script */ $errorHandler->setCfg('onEUserError', 'log'); return $errorHandler; } }, 'eventManager' => function () { return new EventManager(); }, 'internal' => function (Debug $debug) { return new Debug\Internal($debug); }, 'logger' => function (Debug $debug) { return new Debug\Logger($debug); }, 'methodClear' => function (Debug $debug) { return new Debug\MethodClear($debug, $debug->data); }, 'methodTable' => function () { return new Debug\MethodTable(); }, 'output' => function (Debug $debug) { $output = new Debug\Output($debug, $debug->config->getCfgLazy('output')); $debug->eventManager->addSubscriberInterface($output); return $output; }, 'utf8' => function () { return new Debug\Utf8(); }, 'utilities' => function () { return new Debug\Utilities(); }, ); }
php
{ "resource": "" }
q245558
Debug.getMethodDefaultArgs
validation
private static function getMethodDefaultArgs($methodName) { $defaultArgs = array(); if (isset(self::$methodDefaultArgs[$methodName])) { $defaultArgs = self::$methodDefaultArgs[$methodName]; } elseif (\method_exists(self::$instance, $methodName)) { $reflectionMethod = new ReflectionMethod(self::$instance, $methodName); $params = $reflectionMethod->getParameters(); foreach ($params as $reflectionParameter) { $defaultArgs[] = $reflectionParameter->isOptional() ? $reflectionParameter->getDefaultValue() : null; } self::$methodDefaultArgs[$methodName] = $defaultArgs; } return $defaultArgs; }
php
{ "resource": "" }
q245559
Debug.setLogDest
validation
private function setLogDest($where = 'auto') { if ($where == 'auto') { $where = $this->data['groupPriorityStack'] ? 'summary' : 'log'; } if ($where == 'log') { $this->rootInstance->logRef = &$this->rootInstance->data['log']; $this->rootInstance->groupStackRef = &$this->rootInstance->data['groupStacks']['main']; } elseif ($where == 'alerts') { $this->rootInstance->logRef = &$this->rootInstance->data['alerts']; } else { $priority = \end($this->data['groupPriorityStack']); if (!isset($this->data['logSummary'][$priority])) { $this->data['logSummary'][$priority] = array(); $this->data['groupStacks'][$priority] = array(); } $this->rootInstance->logRef = &$this->rootInstance->data['logSummary'][$priority]; $this->rootInstance->groupStackRef = &$this->rootInstance->data['groupStacks'][$priority]; } }
php
{ "resource": "" }
q245560
Logger.interpolate
validation
protected function interpolate($message, array &$context = array()) { // build a replacement array with braces around the context keys \preg_match_all('/\{([a-z0-9_.]+)\}/', $message, $matches); $placeholders = \array_unique($matches[1]); $replace = array(); foreach ($placeholders as $key) { if (!isset($context[$key])) { continue; } $val = $context[$key]; if (!\is_array($val) && (!\is_object($val) || \method_exists($val, '__toString'))) { $replace['{' . $key . '}'] = $val; } } $context = \array_diff_key($context, \array_flip($placeholders)); if (!$context) { $context = $this->debug->meta(); } return \strtr($message, $replace); }
php
{ "resource": "" }
q245561
Utilities.arrayMergeDeep
validation
public static function arrayMergeDeep($arrayDef, $array2) { if (!\is_array($arrayDef) || self::isCallable($arrayDef)) { // not array or appears to be a callable return $array2; } if (!\is_array($array2) || self::isCallable($array2)) { // not array or appears to be a callable return $array2; } foreach ($array2 as $k2 => $v2) { if (\is_int($k2)) { if (!\in_array($v2, $arrayDef)) { $arrayDef[] = $v2; } } elseif (!isset($arrayDef[$k2])) { $arrayDef[$k2] = $v2; } else { $arrayDef[$k2] = self::arrayMergeDeep($arrayDef[$k2], $v2); } } return $arrayDef; }
php
{ "resource": "" }
q245562
Utilities.arrayPathGet
validation
public static function arrayPathGet($array, $path) { if (!\is_array($path)) { $path = \array_filter(\preg_split('#[\./]#', $path), 'strlen'); } $path = \array_reverse($path); while ($path) { $key = \array_pop($path); $arrayAccess = \is_array($array) || $array instanceof \ArrayAccess; if (!$arrayAccess) { return null; } elseif (isset($array[$key])) { $array = $array[$key]; } elseif ($key == '__count__') { return \count($array); } elseif ($key == '__end__') { \end($array); $path[] = \key($array); } elseif ($key == '__reset__') { \reset($array); $path[] = \key($array); } else { return null; } } return $array; }
php
{ "resource": "" }
q245563
Utilities.buildAttribString
validation
public static function buildAttribString($attribs) { if (\is_string($attribs)) { return \rtrim(' '.\trim($attribs)); } $attribPairs = array(); foreach ($attribs as $k => $v) { if (\is_int($k)) { $k = $v; $v = true; } $k = \strtolower($k); if (\strpos($k, 'data-') === 0) { $v = \json_encode($v); $v = \trim($v, '"'); } elseif (\is_bool($v)) { $v = self::buildAttribBoolVal($k, $v); } elseif (\is_array($v) || $k === 'class') { $v = self::buildAttribArrayVal($k, $v); } if (\array_filter(array( $v === null, $v === '' && \in_array($k, array('class', 'style')) ))) { // don't include continue; } $v = \trim($v); $attribPairs[] = $k.'="'.\htmlspecialchars($v).'"'; } \sort($attribPairs); return \rtrim(' '.\implode(' ', $attribPairs)); }
php
{ "resource": "" }
q245564
Utilities.buildTag
validation
public static function buildTag($tagName, $attribs = array(), $innerhtml = '') { $tagName = \strtolower($tagName); $attribStr = self::buildAttribString($attribs); return \in_array($tagName, self::$htmlEmptyTags) ? '<'.$tagName.$attribStr.' />' : '<'.$tagName.$attribStr.'>'.$innerhtml.'</'.$tagName.'>'; }
php
{ "resource": "" }
q245565
Utilities.getBytes
validation
public static function getBytes($size) { if (\is_string($size) && \preg_match('/^([\d,.]+)\s?([kmgtp])b?$/i', $size, $matches)) { $size = \str_replace(',', '', $matches[1]); switch (\strtolower($matches[2])) { case 'p': $size *= 1024; // no break case 't': $size *= 1024; // no break case 'g': $size *= 1024; // no break case 'm': $size *= 1024; // no break case 'k': $size *= 1024; } } $units = array('B','kB','MB','GB','TB','PB'); $pow = \pow(1024, ($i=\floor(\log($size, 1024)))); $size = $pow == 0 ? '0 B' : \round($size/$pow, 2).' '.$units[$i]; return $size; }
php
{ "resource": "" }
q245566
Utilities.getCallerInfo
validation
public static function getCallerInfo($offset = 0) { $return = array( 'file' => null, 'line' => null, 'function' => null, 'class' => null, 'type' => null, ); $backtrace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT, 8); $numFrames = \count($backtrace); $regexInternal = '/^'.\preg_quote(__NAMESPACE__).'\b/'; if (isset($backtrace[1]['class']) && \preg_match($regexInternal, $backtrace[1]['class'])) { // called from within // find the frame that called/triggered a debug function for ($i = $numFrames - 1; $i >= 0; $i--) { if (isset($backtrace[$i]['class']) && \preg_match($regexInternal, $backtrace[$i]['class'])) { break; } } } else { $i = 1; } $i += $offset; $iLine = $i; $iFunc = $i + 1; if (isset($backtrace[$iFunc]) && \in_array($backtrace[$iFunc]['function'], array('call_user_func', 'call_user_func_array'))) { $iLine++; $iFunc++; } elseif (isset($backtrace[$iFunc]['class']) && $backtrace[$iFunc]['class'] == 'ReflectionMethod' && $backtrace[$iFunc]['function'] == 'invoke' ) { // called via ReflectionMethod->invoke() $iLine++; $iFunc--; } if (isset($backtrace[$iFunc])) { $return = \array_merge($return, \array_intersect_key($backtrace[$iFunc], $return)); if ($return['type'] == '->') { $return['class'] = \get_class($backtrace[$iFunc]['object']); } } if (isset($backtrace[$iLine])) { $return['file'] = $backtrace[$iLine]['file']; $return['line'] = $backtrace[$iLine]['line']; } else { $return['file'] = $backtrace[$numFrames-1]['file']; $return['line'] = 0; } return $return; }
php
{ "resource": "" }
q245567
Utilities.getInterface
validation
public static function getInterface() { $return = 'http'; $isCliOrCron = \count(\array_filter(array( \defined('STDIN'), isset($_SERVER['argv']), !\array_key_exists('REQUEST_METHOD', $_SERVER), ))) > 0; if ($isCliOrCron) { // TERM is a linux/unix thing $return = isset($_SERVER['TERM']) || \array_key_exists('PATH', $_SERVER) ? 'cli' : 'cron'; } elseif (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { $return = 'ajax'; } return $return; }
php
{ "resource": "" }
q245568
Utilities.isList
validation
public static function isList($val) { if (!\is_array($val)) { return false; } $keys = \array_keys($val); foreach ($keys as $i => $key) { if ($i != $key) { return false; } } return true; }
php
{ "resource": "" }
q245569
Utilities.parseAttribString
validation
public static function parseAttribString($str, $dataDecode = true) { $attribs = array(); $regexAttribs = '/\b([\w\-]+)\b(?: \s*=\s*(["\'])(.*?)\\2 | \s*=\s*(\S+) )?/xs'; \preg_match_all($regexAttribs, $str, $matches); $keys = \array_map('strtolower', $matches[1]); $values = \array_replace($matches[3], \array_filter($matches[4], 'strlen')); foreach ($keys as $i => $k) { $attribs[$k] = $values[$i]; if (\in_array($k, self::$htmlBoolAttr)) { $attribs[$k] = true; } } \ksort($attribs); foreach ($attribs as $k => $v) { if (\is_string($v)) { $attribs[$k] = \htmlspecialchars_decode($v); } $isDataAttrib = \strpos($k, 'data-') === 0; if ($isDataAttrib && $dataDecode) { $val = $attribs[$k]; $attribs[$k] = \json_decode($attribs[$k], true); if ($attribs[$k] === null && $val !== 'null') { $attribs[$k] = \json_decode('"'.$val.'"', true); } } } return $attribs; }
php
{ "resource": "" }
q245570
Utilities.requestId
validation
public static function requestId() { return \hash( 'crc32b', (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'terminal') .(isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : $_SERVER['REQUEST_TIME']) .(isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : '') ); }
php
{ "resource": "" }
q245571
Utilities.serializeLog
validation
public static function serializeLog($data) { $str = \serialize($data); if (\function_exists('gzdeflate')) { $str = \gzdeflate($str); } $str = \chunk_split(\base64_encode($str), 124); return "START DEBUG\n" .$str // chunk_split appends a "\r\n" .'END DEBUG'; }
php
{ "resource": "" }
q245572
Utilities.unserializeLog
validation
public static function unserializeLog($str) { $strStart = 'START DEBUG'; $strEnd = 'END DEBUG'; if (\preg_match('/'.$strStart.'[\r\n]+(.+)[\r\n]+'.$strEnd.'/s', $str, $matches)) { $str = $matches[1]; } $str = self::isBase64Encoded($str) ? \base64_decode($str) : false; if ($str && \function_exists('gzinflate')) { $strInflated = \gzinflate($str); if ($strInflated) { $str = $strInflated; } } $data = \unserialize($str); return $data; }
php
{ "resource": "" }
q245573
Utilities.buildAttribArrayVal
validation
private static function buildAttribArrayVal($key, $value = array()) { if ($key == 'class') { if (!\is_array($value)) { $value = \explode(' ', $value); } $value = \array_filter(\array_unique($value)); \sort($value); $value = \implode(' ', $value); } elseif ($key == 'style') { $keyValues = array(); foreach ($value as $k => $v) { $keyValues[] = $k.':'.$v.';'; } \sort($keyValues); $value = \implode('', $keyValues); } else { $value = null; } return $value; }
php
{ "resource": "" }
q245574
Utilities.buildAttribBoolVal
validation
private static function buildAttribBoolVal($key, $value = true) { if ($key == 'autocomplete') { $value = $value ? 'on' : 'off'; } elseif ($key == 'spellcheck') { $value = $value ? 'true' : 'false'; } elseif ($key == 'translate') { $value = $value ? 'yes' : 'no'; } elseif ($value) { // even if not a recognized boolean attribute $value = $key; } else { $value = null; } return $value; }
php
{ "resource": "" }
q245575
Output.getCfg
validation
public function getCfg($path = null) { if ($path == 'outputAs') { $ret = $this->cfg['outputAs']; if (!$ret) { $ret = $this->getDefaultOutputAs(); } } elseif ($path == 'css') { $ret = $this->getCss(); } else { $ret = $this->debug->utilities->arrayPathGet($this->cfg, $path); } return $ret; }
php
{ "resource": "" }
q245576
Output.onOutput
validation
public function onOutput(Event $event) { if (!$event['isTarget']) { /* All channels share the same data. We only need to do this via the channel that called output */ return; } $this->data = $this->debug->getData(); $this->closeOpenGroups(); foreach ($this->data['logSummary'] as &$log) { $this->removeHideIfEmptyGroups($log); $this->uncollapseErrors($log); } $this->removeHideIfEmptyGroups($this->data['log']); $this->uncollapseErrors($this->data['log']); $this->debug->setData($this->data); }
php
{ "resource": "" }
q245577
Output.closeOpenGroups
validation
private function closeOpenGroups() { $this->data['groupPriorityStack'][] = 'main'; while ($this->data['groupPriorityStack']) { $priority = \array_pop($this->data['groupPriorityStack']); foreach ($this->data['groupStacks'][$priority] as $i => $info) { if ($info['collect']) { unset($this->data['groupStacks'][$priority][$i]); $meta = array( 'channel' => $info['channel'], ); if ($priority === 'main') { $this->data['log'][] = array('groupEnd', array(), $meta); } else { $this->data['logSummary'][$priority][] = array('groupEnd', array(), $meta); } } } } }
php
{ "resource": "" }
q245578
Output.getDefaultOutputAs
validation
private function getDefaultOutputAs() { $ret = 'html'; $interface = $this->debug->utilities->getInterface(); if ($interface == 'ajax') { $ret = $this->cfg['outputAsDefaultNonHtml']; } elseif ($interface == 'http') { $contentType = $this->debug->utilities->getResponseHeader(); if ($contentType && $contentType !== 'text/html') { $ret = $this->cfg['outputAsDefaultNonHtml']; } } else { $ret = 'text'; } return $ret; }
php
{ "resource": "" }
q245579
Output.removeHideIfEmptyGroups
validation
private function removeHideIfEmptyGroups(&$log) { $groupStack = array(); $groupStackCount = 0; $removed = false; for ($i = 0, $count = \count($log); $i < $count; $i++) { $method = $log[$i][0]; if (\in_array($method, array('group', 'groupCollapsed'))) { $entry = $log[$i]; $groupStack[] = array( 'i' => $i, 'meta' => !empty($entry[2]) ? $entry[2] : array(), 'hasEntries' => false, ); $groupStackCount ++; } elseif ($method == 'groupEnd') { $group = \end($groupStack); if (!$group['hasEntries'] && !empty($group['meta']['hideIfEmpty'])) { // make it go away unset($log[$group['i']]); unset($log[$i]); $removed = true; } \array_pop($groupStack); $groupStackCount--; } elseif ($groupStack) { $groupStack[$groupStackCount - 1]['hasEntries'] = true; } } if ($removed) { $log = \array_values($log); } }
php
{ "resource": "" }
q245580
Output.setOutputAs
validation
private function setOutputAs($outputAs) { if (\is_object($this->cfg['outputAs'])) { /* unsubscribe current OutputInterface there can only be one 'outputAs' at a time if multiple output routes are desired, use debug->addPlugin() */ $this->debug->removePlugin($this->cfg['outputAs']); $this->cfg['outputAs'] = null; } $prop = null; $obj = null; if (\is_string($outputAs)) { $prop = $outputAs; $classname = __NAMESPACE__.'\\Output\\'.\ucfirst($outputAs); if (\property_exists($this, $prop)) { $obj = $this->{$prop}; } elseif (\class_exists($classname)) { $obj = new $classname($this->debug); } } elseif ($outputAs instanceof OutputInterface) { $classname = \get_class($outputAs); $prefix = __NAMESPACE__.'\\Output\\'; if (\strpos($classname, $prefix) == 0) { $prop = \substr($classname, \strlen($prefix)); $prop = \lcfirst($prop); } $obj = $outputAs; } if ($obj) { $this->debug->addPlugin($obj); $this->cfg['outputAs'] = $obj; if ($prop) { $this->{$prop} = $obj; } } }
php
{ "resource": "" }
q245581
Output.uncollapseErrors
validation
private function uncollapseErrors(&$log) { $groupStack = array(); for ($i = 0, $count = \count($log); $i < $count; $i++) { $method = $log[$i][0]; if (\in_array($method, array('group', 'groupCollapsed'))) { $groupStack[] = $i; } elseif ($method == 'groupEnd') { \array_pop($groupStack); } elseif (\in_array($method, array('error', 'warn'))) { foreach ($groupStack as $i2) { $log[$i2][0] = 'group'; } } } }
php
{ "resource": "" }
q245582
MethodProfile.end
validation
public function end() { \unregister_tick_function(array($this, 'tickFunction')); while ($this->funcStack) { $this->popStack(); } // sort by totalTime descending \uasort($this->data, function ($valA, $valB) { return ($valA['totalTime'] < $valB['totalTime']) ? 1 : -1; }); $data = \array_map(function ($row) { $row['totalTime'] = \round($row['totalTime'], 6); $row['ownTime'] = \round($row['ownTime'], 6); return $row; }, $this->data); $this->data = array(); $this->funcStack = array(); $this->isProfiling = false; $this->rootStack = array(); return $data; }
php
{ "resource": "" }
q245583
MethodProfile.start
validation
public function start() { if ($this->isProfiling) { return false; } $backtrace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $backtrace = $this->backtraceRemoveInternal($backtrace); foreach ($backtrace as $frame) { $class = isset($frame['class']) ? $frame['class'].'::' : ''; $this->rootStack[] = $class.$frame['function']; } \register_tick_function(array($this, 'tickFunction')); $this->isProfiling = true; $this->timeLastTick = \microtime(true); return true; }
php
{ "resource": "" }
q245584
MethodProfile.popStack
validation
protected function popStack() { $stackInfo = \array_pop($this->funcStack); $funcPopped = $stackInfo['function']; $timeElapsed = \microtime(true) - $stackInfo['tsStart']; $this->data[$funcPopped]['ownTime'] += $timeElapsed - $stackInfo['subTime']; $this->data[$funcPopped]['totalTime'] += $timeElapsed; if ($this->data[$funcPopped]['calls'] === 0) { $this->data[$funcPopped]['calls'] ++; } if ($this->funcStack) { $this->funcStack[\count($this->funcStack)-1]['subTime'] += $timeElapsed; } return $stackInfo['function']; }
php
{ "resource": "" }
q245585
MethodProfile.pushStack
validation
protected function pushStack($funcName) { $this->funcStack[] = array( 'function' => $funcName, 'tsStart' => $this->timeLastTick, 'subTime' => 0, // how much time spent in nested functions ); if (!isset($this->data[$funcName])) { $this->data[$funcName] = array( 'calls' => 0, 'totalTime' => 0, // time spent in function and nested func 'ownTime' => 0, // time spent in function excluding nested funcs ); } $this->data[$funcName]['calls'] ++; }
php
{ "resource": "" }
q245586
Config.getCfgLazy
validation
public function getCfgLazy($name) { if (!isset($this->cfgLazy[$name])) { return array(); } $return = $this->cfgLazy[$name]; unset($this->cfgLazy[$name]); return $return; }
php
{ "resource": "" }
q245587
Config.doSetCfg
validation
private function doSetCfg($cfg) { $return = array(); foreach ($cfg as $k => $v) { if ($k == 'debug') { $return[$k] = \array_intersect_key($this->cfg, $v); $this->setDebugCfg($v); } elseif (isset($this->debug->{$k}) && \is_object($this->debug->{$k})) { $return[$k] = \array_intersect_key($this->getCfg($k.'/*'), $v); $this->debug->{$k}->setCfg($v); } elseif (isset($this->cfgLazy[$k])) { $return[$k] = \array_intersect_key($this->cfgLazy[$k], $v); $this->cfgLazy[$k] = \array_merge($this->cfgLazy[$k], $v); } else { $return[$k] = array(); $this->cfgLazy[$k] = $v; } } return $return; }
php
{ "resource": "" }
q245588
Config.getCfgAll
validation
private function getCfgAll() { $cfg = array(); foreach (\array_keys($this->configKeys) as $classname) { if ($classname === 'debug') { $cfg['debug'] = $this->cfg; } elseif (isset($this->debug->{$classname})) { $cfg[$classname] = $this->debug->{$classname}->getCfg(); } elseif (isset($this->cfgLazy[$classname])) { $cfg[$classname] = $this->cfgLazy[$classname]; } } return $cfg; }
php
{ "resource": "" }
q245589
Config.getConfigKeys
validation
private function getConfigKeys() { if (isset($this->configKeys)) { return $this->configKeys; } $this->configKeys = array( 'debug' => array( // any key not found falls under 'debug'... ), 'abstracter' => array( 'cacheMethods', 'collectConstants', 'collectMethods', 'objectsExclude', 'objectSort', 'useDebugInfo', ), 'errorEmailer' => array( 'emailBacktraceDumper', // 'emailFrom', // 'emailFunc', 'emailMask', 'emailMin', 'emailThrottledSummary', 'emailThrottleFile', 'emailThrottleRead', 'emailThrottleWrite', // 'emailTo', 'emailTraceMask', ), 'errorHandler' => \array_keys($this->debug->errorHandler->getCfg()), 'output' => array( 'addBR', 'css', 'displayListKeys', 'filepathCss', 'filepathScript', 'onOutput', 'outputAs', 'outputAsDefaultNonHtml', 'outputConstants', 'outputCss', 'outputHeaders', 'outputMethodDescription', 'outputMethods', 'outputScript', ), ); return $this->configKeys; }
php
{ "resource": "" }
q245590
Config.normalizeArray
validation
private function normalizeArray($cfg) { $return = array( 'debug' => array(), // initialize with debug... we want debug values first ); $configKeys = $this->getConfigKeys(); foreach ($cfg as $k => $v) { $translated = false; foreach ($configKeys as $objName => $objKeys) { if ($k == $objName && \is_array($v)) { $return[$objName] = isset($return[$objName]) ? \array_merge($return[$objName], $v) : $v; $translated = true; break; } elseif (\is_array($v) && isset($configKeys[$k])) { continue; } elseif (\in_array($k, $objKeys)) { $return[$objName][$k] = $v; $translated = true; break; } } if (!$translated) { $return['debug'][$k] = $v; } } if (!$return['debug']) { unset($return['debug']); } return $return; }
php
{ "resource": "" }
q245591
Config.setCopyValues
validation
private function setCopyValues($values) { if (isset($values['debug']['emailLog']) && $values['debug']['emailLog'] === true) { $values['debug']['emailLog'] = 'onError'; } foreach (array('emailFrom','emailFunc','emailTo') as $key) { if (isset($values['debug'][$key]) && !isset($values['errorEmailer'][$key])) { // also set for errorEmailer $values['errorEmailer'][$key] = $values['debug'][$key]; } } return $values; }
php
{ "resource": "" }
q245592
Config.setDebugCfg
validation
private function setDebugCfg($cfg) { if (isset($cfg['key'])) { $cfg = \array_merge($cfg, $this->debugKeyValues($cfg['key'])); } if (isset($cfg['logEnvInfo']) && \is_bool($cfg['logEnvInfo'])) { $keys = \array_keys($this->cfg['logEnvInfo']); $cfg['logEnvInfo'] = \array_fill_keys($keys, $cfg['logEnvInfo']); } if (isset($cfg['logServerKeys'])) { // don't append, replace $this->cfg['logServerKeys'] = array(); } $this->cfg = $this->debug->utilities->arrayMergeDeep($this->cfg, $cfg); }
php
{ "resource": "" }
q245593
File.onConfig
validation
public function onConfig(Event $event) { $file = $this->debug->getCfg('file'); $this->setFile($file); }
php
{ "resource": "" }
q245594
File.onLog
validation
public function onLog(Event $event) { if (!$this->fileHandle) { return; } $method = $event['method']; if ($method == 'groupUncollapse') { return; } $args = $event['args']; $meta = $event['meta']; $isSummaryBookend = $method == 'groupSummary' || !empty($meta['closesSummary']); if ($isSummaryBookend) { \fwrite($this->fileHandle, "=========\n"); return; } if ($args) { $str = $this->processLogEntryWEvent($method, $args, $meta); \fwrite($this->fileHandle, $str); } elseif ($method == 'groupEnd' && $this->depth > 0) { $this->depth --; } }
php
{ "resource": "" }
q245595
File.setFile
validation
protected function setFile($file) { if ($file == $this->file) { // no change return; } if ($this->fileHandle) { // close existing file \fclose($this->fileHandle); $this->fileHandle = null; } $this->file = $file; if (empty($file)) { return; } $fileExists = \file_exists($file); $this->fileHandle = \fopen($file, 'a'); if ($this->fileHandle) { \fwrite($this->fileHandle, '***** '.\date('Y-m-d H:i:s').' *****'."\n"); if (!$fileExists) { // we just created file \chmod($file, 0660); } } }
php
{ "resource": "" }
q245596
Base.checkTimestamp
validation
protected function checkTimestamp($val) { $secs = 86400 * 90; // 90 days worth o seconds $tsNow = \time(); if ($val > $tsNow - $secs && $val < $tsNow + $secs) { return \date('Y-m-d H:i:s', $val); } return false; }
php
{ "resource": "" }
q245597
Base.methodTable
validation
protected function methodTable($array, $columns = array()) { if (!\is_array($array)) { return $this->dump($array); } $keys = $columns ?: $this->debug->methodTable->colKeys($array); $table = array(); $classnames = array(); if ($this->debug->abstracter->isAbstraction($array) && $array['traverseValues']) { $array = $array['traverseValues']; } foreach ($array as $k => $row) { $values = $this->debug->methodTable->keyValues($row, $keys, $objInfo); $values = $this->methodTableCleanValues($values); $table[$k] = $values; $classnames[$k] = $objInfo['row'] ? $objInfo['row']['className'] : ''; } if (\array_filter($classnames)) { foreach ($classnames as $k => $classname) { $table[$k] = \array_merge( array('___class_name' => $classname), $table[$k] ); } } return $table; }
php
{ "resource": "" }
q245598
Base.processLog
validation
protected function processLog() { $str = ''; foreach ($this->data['log'] as $entry) { $channel = isset($entry[2]['channel']) ? $entry[2]['channel'] : null; if ($this->channelTest($channel)) { $str .= $this->processLogEntryWEvent($entry[0], $entry[1], $entry[2]); } } return $str; }
php
{ "resource": "" }
q245599
Base.processSubstitutions
validation
protected function processSubstitutions($args, &$hasSubs) { $subRegex = '/%' .'(?:' .'[coO]|' // c: css, o: obj with max info, O: obj w generic info .'[+-]?' // sign specifier .'(?:[ 0]|\'.{1})?' // padding specifier .'-?' // alignment specifier .'\d*' // width specifier .'(?:\.\d+)?' // precision specifier .'[difs]' .')' .'/'; if (!\is_string($args[0])) { return $args; } $index = 0; $indexes = array( 'c' => array(), ); $hasSubs = false; $args[0] = \preg_replace_callback($subRegex, function ($matches) use ( &$args, &$hasSubs, &$index, &$indexes ) { $hasSubs = true; $index++; $replacement = $matches[0]; $type = \substr($matches[0], -1); if (\strpos('difs', $type) !== false) { $format = $matches[0]; $sub = $args[$index]; if ($type == 'i') { $format = \substr_replace($format, 'd', -1, 1); } elseif ($type === 's') { $sub = $this->substitutionAsString($sub); } $replacement = \sprintf($format, $sub); } elseif ($type === 'c') { $asHtml = \get_called_class() == __NAMESPACE__.'\\Html'; if (!$asHtml) { return ''; } $replacement = ''; if ($indexes['c']) { // close prev $replacement = '</span>'; } $replacement .= '<span'.$this->debug->utilities->buildAttribString(array( 'style' => $args[$index], )).'>'; $indexes['c'][] = $index; } elseif (\strpos('oO', $type) !== false) { $replacement = $this->dump($args[$index]); } return $replacement; }, $args[0]); if ($indexes['c']) { $args[0] .= '</span>'; } if ($hasSubs) { $args = array($args[0]); } return $args; }
php
{ "resource": "" }