_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q8600
Net_SmartIRC.reconnect
train
public function reconnect() { // remember in which channels we are joined $channels = array(); foreach ($this->_channels as $value) { if (empty($value->key)) { $channels[] = array('name' => $value->name); } else { $channels[] = array('name' => $value->name, 'key' => $value->key); } } $this->disconnect(true); while ($this->_autoretry === true && ($this->_autoretrymax == 0 || $this->_autoretrycount < $this->_autoretrymax) && $this->_updatestate() != SMARTIRC_STATE_CONNECTED ) { $this->_autoretrycount++; if ($this->_reconnectdelay > 0) { $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: delaying ' .'reconnect for '.$this->_reconnectdelay.' ms', __FILE__, __LINE__ ); for ($i = 0; $i < $this->_reconnectdelay; $i++) { $this->_callTimeHandlers(); usleep(1000); } } $this->_callTimeHandlers(); $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: reconnecting...', __FILE__, __LINE__ ); if ($this->connect($this->_address, $this->_port, true) !== false) { break; } } if ($this->_updatestate() != SMARTIRC_STATE_CONNECTED) { return false; } $this->login($this->_nick, $this->_realname, $this->_usermode, $this->_username, $this->_password ); // rejoin the channels foreach ($channels as $value) { if (isset($value['key'])) { $this->join($value['name'], $value['key']); } else { $this->join($value['name']); } } return $this; }
php
{ "resource": "" }
q8601
Net_SmartIRC.login
train
public function login($nick, $realname, $usermode = 0, $username = null, $password = null ) { $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: logging in', __FILE__, __LINE__ ); $this->_nick = str_replace(' ', '', $nick); $this->_realname = $realname; if ($username !== null) { $this->_username = str_replace(' ', '', $username); } else { $this->_username = str_replace(' ', '', exec('whoami')); } if ($password !== null) { $this->_password = $password; $this->send('PASS '.$this->_password, SMARTIRC_CRITICAL); } if (!is_numeric($usermode)) { $ipos = strpos($usermode, 'i'); $wpos = strpos($usermode, 'w'); $val = 0; if ($ipos) $val += 8; if ($wpos) $val += 4; if ($val == 0) { $this->log(SMARTIRC_DEBUG_NOTICE, 'DEBUG_NOTICE: login() usermode (' .$usermode.') is not valid, using 0 instead', __FILE__, __LINE__ ); } $usermode = $val; } $this->send('NICK '.$this->_nick, SMARTIRC_CRITICAL); $this->send('USER '.$this->_username.' '.$usermode.' '.SMARTIRC_UNUSED .' :'.$this->_realname, SMARTIRC_CRITICAL ); if (count($this->_performs)) { // if we have extra commands to send, do it now foreach ($this->_performs as $command) { $this->send($command, SMARTIRC_HIGH); } // if we sent "ns auth" commands, we may need to resend our nick $this->send('NICK '.$this->_nick, SMARTIRC_HIGH); } return $this; }
php
{ "resource": "" }
q8602
Net_SmartIRC.send
train
public function send($data, $priority = SMARTIRC_MEDIUM) { switch ($priority) { case SMARTIRC_CRITICAL: $this->_rawsend($data); break; case SMARTIRC_HIGH: case SMARTIRC_MEDIUM: case SMARTIRC_LOW: $this->_messagebuffer[$priority][] = $data; break; default: $this->log(SMARTIRC_DEBUG_NOTICE, "WARNING: message ($data) " ."with an invalid priority passed ($priority), message is " .'ignored!', __FILE__, __LINE__ ); return false; } return $this; }
php
{ "resource": "" }
q8603
Net_SmartIRC.isJoined
train
public function isJoined($channel, $nickname = null) { if (!$this->_channelsyncing) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isJoined() is called ' .'and the required Channel Syncing is not activated!', __FILE__, __LINE__ ); return false; } if (!isset($this->_channels[strtolower($channel)])) { if ($nickname !== null) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isJoined() is called' .' on a user in a channel we are not joined to!', __FILE__, __LINE__ ); } return false; } if ($nickname === null) { return true; } return isset($this->getChannel($channel)->users[strtolower($nickname)]); }
php
{ "resource": "" }
q8604
Net_SmartIRC.isFounder
train
public function isFounder($channel, $nickname = null) { if (!$this->_channelsyncing) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isFounder() is called ' .'and the required Channel Syncing is not activated!', __FILE__, __LINE__ ); return false; } if ($nickname === null) { $nickname = $this->_nick; } return ($this->isJoined($channel, $nickname) && $this->getUser($channel, $nickname)->founder ); }
php
{ "resource": "" }
q8605
Net_SmartIRC.isAdmin
train
public function isAdmin($channel, $nickname = null) { if (!$this->_channelsyncing) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isAdmin() is called ' .'and the required Channel Syncing is not activated!', __FILE__, __LINE__ ); return false; } if ($nickname === null) { $nickname = $this->_nick; } return ($this->isJoined($channel, $nickname) && $this->getUser($channel, $nickname)->admin ); }
php
{ "resource": "" }
q8606
Net_SmartIRC.isOpped
train
public function isOpped($channel, $nickname = null) { if (!$this->_channelsyncing) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isOpped() is called ' .'and the required Channel Syncing is not activated!', __FILE__, __LINE__ ); return false; } if ($nickname === null) { $nickname = $this->_nick; } return ($this->isJoined($channel, $nickname) && $this->getUser($channel, $nickname)->op ); }
php
{ "resource": "" }
q8607
Net_SmartIRC.isHopped
train
public function isHopped($channel, $nickname = null) { if (!$this->_channelsyncing) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isHopped() is called ' .'and the required Channel Syncing is not activated!', __FILE__, __LINE__ ); return false; } if ($nickname === null) { $nickname = $this->_nick; } return ($this->isJoined($channel, $nickname) && $this->getUser($channel, $nickname)->hop ); }
php
{ "resource": "" }
q8608
Net_SmartIRC.isVoiced
train
public function isVoiced($channel, $nickname = null) { if (!$this->_channelsyncing) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isVoiced() is called ' .'and the required Channel Syncing is not activated!', __FILE__, __LINE__ ); return false; } if ($nickname === null) { $nickname = $this->_nick; } return ($this->isJoined($channel, $nickname) && $this->getUser($channel, $nickname)->voice ); }
php
{ "resource": "" }
q8609
Net_SmartIRC.isBanned
train
public function isBanned($channel, $hostmask) { if (!$this->_channelsyncing) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isBanned() is called ' .'and the required Channel Syncing is not activated!', __FILE__, __LINE__ ); return false; } return ($this->isJoined($channel) && array_search($hostmask, $this->getChannel($channel)->bans ) !== false ); }
php
{ "resource": "" }
q8610
Net_SmartIRC.listenFor
train
public function listenFor($messagetype, $regex = '.*') { $listenfor = new Net_SmartIRC_listenfor(); $this->registerActionHandler($messagetype, $regex, array($listenfor, 'handler')); $this->listen(); return $listenfor->result; }
php
{ "resource": "" }
q8611
Net_SmartIRC.registerActionHandler
train
public function registerActionHandler($handlertype, $regexhandler, $object, $methodname = '' ) { // precheck if (!($handlertype & SMARTIRC_TYPE_ALL)) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: passed invalid handler' .'type to registerActionHandler()', __FILE__, __LINE__ ); return false; } if (!empty($methodname)) { $object = array($object, $methodname); } $id = $this->_actionhandlerid++; $this->_actionhandler[] = array( 'id' => $id, 'type' => $handlertype, 'message' => $regexhandler, 'callback' => $object, ); $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: ' .'actionhandler('.$id.') registered', __FILE__, __LINE__ ); return $id; }
php
{ "resource": "" }
q8612
Net_SmartIRC.unregisterActionHandler
train
public function unregisterActionHandler($handlertype, $regexhandler, $object, $methodname = '' ) { // precheck if (!($handlertype & SMARTIRC_TYPE_ALL)) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: passed invalid handler' .'type to unregisterActionHandler()', __FILE__, __LINE__ ); return false; } if (!empty($methodname)) { $object = array($object, $methodname); } foreach ($this->_actionhandler as $i => &$handlerinfo) { if ($handlerinfo['type'] == $handlertype && $handlerinfo['message'] == $regexhandler && $handlerinfo['callback'] == $object ) { $id = $handlerinfo['id']; unset($this->_actionhandler[$i]); $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: ' .'actionhandler('.$id.') unregistered', __FILE__, __LINE__ ); $this->_actionhandler = array_values($this->_actionhandler); return $this; } } $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: could ' .'not find actionhandler type: "'.$handlertype.'" message: "' .$regexhandler.'" matching callback. Nothing unregistered', __FILE__, __LINE__ ); return false; }
php
{ "resource": "" }
q8613
Net_SmartIRC.unregisterActionId
train
public function unregisterActionId($id) { if (is_array($id)) { foreach ($id as $each) { $this->unregisterActionId($each); } return $this; } foreach ($this->_actionhandler as $i => &$handlerinfo) { if ($handlerinfo['id'] == $id) { unset($this->_actionhandler[$i]); $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: ' .'actionhandler('.$id.') unregistered', __FILE__, __LINE__ ); $this->_actionhandler = array_values($this->_actionhandler); return $this; } } $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: could ' .'not find actionhandler id: '.$id.' _not_ unregistered', __FILE__, __LINE__ ); return false; }
php
{ "resource": "" }
q8614
Net_SmartIRC.registerTimeHandler
train
public function registerTimeHandler($interval, $object, $methodname = '') { $id = $this->_timehandlerid++; if (!empty($methodname)) { $object = array($object, $methodname); } $this->_timehandler[] = array( 'id' => $id, 'interval' => $interval, 'callback' => $object, 'lastmicrotimestamp' => microtime(true), ); $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: timehandler(' .$id.') registered', __FILE__, __LINE__ ); if (($this->_mintimer == false) || ($interval < $this->_mintimer)) { $this->_mintimer = $interval; } return $id; }
php
{ "resource": "" }
q8615
Net_SmartIRC.unregisterTimeId
train
public function unregisterTimeId($id) { if (is_array($id)) { foreach ($id as $each) { $this->unregisterTimeId($each); } return $this; } foreach ($this->_timehandler as $i => &$handlerinfo) { if ($handlerinfo['id'] == $id) { unset($this->_timehandler[$i]); $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: ' .'timehandler('.$id.') unregistered', __FILE__, __LINE__ ); $this->_timehandler = array_values($this->_timehandler); $timerarray = array(); foreach ($this->_timehandler as $values) { $timerarray[] = $values->interval; } $this->_mintimer = ( array_multisort($timerarray, SORT_NUMERIC, SORT_ASC) && isset($timerarray[0]) ) ? $timerarray[0] : false; return $this; } } $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: could not ' ."find timehandler id: $id _not_ unregistered", __FILE__, __LINE__ ); return false; }
php
{ "resource": "" }
q8616
Net_SmartIRC.unloadModule
train
public function unloadModule($name) { $this->log(SMARTIRC_DEBUG_MODULES, 'DEBUG_MODULES: unloading module: ' ."$name...", __FILE__, __LINE__ ); if (isset($this->_modules[$name])) { if (in_array('module_exit', get_class_methods(get_class($this->_modules[$name])) )) { $this->_modules[$name]->module_exit($this); } unset($this->_modules[$name]); $this->log(SMARTIRC_DEBUG_MODULES, 'DEBUG_MODULES: successfully' ." unloaded module: $name", __FILE__, __LINE__); return $this; } $this->log(SMARTIRC_DEBUG_MODULES, "DEBUG_MODULES: couldn't unload" ." module: $name (it's not loaded!)", __FILE__, __LINE__ ); return false; }
php
{ "resource": "" }
q8617
Net_SmartIRC._adduser
train
protected function _adduser(&$channel, &$newuser) { $lowerednick = strtolower($newuser->nick); if ($this->isJoined($channel->name, $newuser->nick)) { $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: ' .'updating user: '.$newuser->nick.' on channel: ' .$channel->name, __FILE__, __LINE__ ); // lets update the existing user $currentuser = &$channel->users[$lowerednick]; $props = array('ident', 'host', 'realname', 'ircop', 'founder', 'admin', 'op', 'hop', 'voice', 'away', 'server', 'hopcount' ); foreach ($props as $prop) { if ($newuser->$prop !== null) { $currentuser->$prop = $newuser->$prop; } } } else { $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: ' .'adding user: '.$newuser->nick.' to channel: '.$channel->name, __FILE__, __LINE__ ); $channel->users[$lowerednick] = $newuser; } $user = &$channel->users[$lowerednick]; $modes = array('founder', 'admin', 'op', 'hop', 'voice'); foreach ($modes as $mode) { if ($user->$mode) { $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, "DEBUG_CHANNELSYNCING: adding $mode: ".$user->nick .' to channel: '.$channel->name, __FILE__, __LINE__ ); $ms = $mode.'s'; $channel->{$ms}[$user->nick] = true; } } return $this; }
php
{ "resource": "" }
q8618
Net_SmartIRC._callTimeHandlers
train
protected function _callTimeHandlers() { foreach ($this->_timehandler as &$handlerinfo) { $microtimestamp = microtime(true); if ($microtimestamp >= $handlerinfo['lastmicrotimestamp'] + ($handlerinfo['interval'] / 1000.0) ) { $callback = $handlerinfo['callback']; $handlerinfo['lastmicrotimestamp'] = $microtimestamp; $cbstring = (is_array($callback)) ? (is_object($callback[0]) ? get_class($callback[0]) : $callback[0] ) . '->' . $callback[1] : '(anonymous function)'; if (is_callable($callback)) { $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: calling "'.$cbstring.'"', __FILE__, __LINE__ ); call_user_func($callback, $this); } else { $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: callback is invalid! "'.$cbstring.'"', __FILE__, __LINE__ ); } } } }
php
{ "resource": "" }
q8619
Net_SmartIRC._pingcheck
train
protected function _pingcheck() { $time = time(); if ($time - $this->_lastrx > $this->_rxtimeout) { $this->reconnect(); $this->_lastrx = $time; } elseif ($time - $this->_lastrx > $this->_rxtimeout/2) { $this->send('PING '.$this->_address, SMARTIRC_CRITICAL); } }
php
{ "resource": "" }
q8620
Net_SmartIRC._rawsend
train
protected function _rawsend($data) { if ($this->_updatestate() != SMARTIRC_STATE_CONNECTED) { return false; } $this->log(SMARTIRC_DEBUG_IRCMESSAGES, 'DEBUG_IRCMESSAGES: sent: "' .$data.'"', __FILE__, __LINE__ ); $result = fwrite($this->_socket, $data.SMARTIRC_CRLF); if (!$result) { // writing to the socket failed, means the connection is broken $this->_connectionerror = true; } else { $this->_lasttx = time(); } return $result; }
php
{ "resource": "" }
q8621
Net_SmartIRC._removeuser
train
protected function _removeuser($ircdata) { if ($ircdata->type & (SMARTIRC_TYPE_PART | SMARTIRC_TYPE_QUIT)) { $nick = $ircdata->nick; } else if ($ircdata->type & SMARTIRC_TYPE_KICK) { $nick = $ircdata->params[1]; } else { $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: ' .'unknown TYPE ('.$ircdata->type .') in _removeuser(), trying default', __FILE__, __LINE__ ); $nick = $ircdata->nick; } $lowerednick = strtolower($nick); if ($this->_nick == $nick) { $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: we left channel: '.$ircdata->channel .' destroying...', __FILE__, __LINE__ ); unset($this->_channels[strtolower($ircdata->channel)]); } else { $lists = array('founders', 'admins', 'ops', 'hops', 'voices'); if ($ircdata->type & SMARTIRC_TYPE_QUIT) { $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: user '.$nick .' quit, removing him from all channels', __FILE__, __LINE__ ); // remove the user from all channels $channelkeys = array_keys($this->_channels); foreach ($channelkeys as $channelkey) { // loop through all channels $channel = &$this->getChannel($channelkey); foreach ($channel->users as $uservalue) { // loop through all user in this channel if ($nick == $uservalue->nick) { // found him, kill him $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: found him on channel: ' .$channel->name.' destroying...', __FILE__, __LINE__ ); unset($channel->users[$lowerednick]); foreach ($lists as $list) { if (isset($channel->{$list}[$nick])) { // die! $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing him ' ."from $list list", __FILE__, __LINE__ ); unset($channel->{$list}[$nick]); } } } } } } else { $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing user: '.$nick .' from channel: '.$ircdata->channel, __FILE__, __LINE__ ); $channel = &$this->getChannel($ircdata->channel); unset($channel->users[$lowerednick]); foreach ($lists as $list) { if (isset($channel->{$list}[$nick])) { $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing him ' ."from $list list", __FILE__, __LINE__ ); unset($channel->{$list}[$nick]); } } } } return $this; }
php
{ "resource": "" }
q8622
Net_SmartIRC_listenfor.handler
train
public function handler(&$irc, &$ircdata) { $irc->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: listenfor handler called', __FILE__, __LINE__ ); $this->result[] = $ircdata; $irc->disconnect(); }
php
{ "resource": "" }
q8623
MelisFrontShowListFromFolderPlugin.createOptionsForms
train
public function createOptionsForms() { // construct form $factory = new \Zend\Form\Factory(); $formElements = $this->getServiceLocator()->get('FormElementManager'); $factory->setFormElementManager($formElements); $formConfig = $this->pluginBackConfig['modal_form']; $response = []; $render = []; if (!empty($formConfig)) { foreach ($formConfig as $formKey => $config) { $form = $factory->createForm($config); $request = $this->getServiceLocator()->get('request'); $parameters = $request->getQuery()->toArray(); if (!isset($parameters['validate'])) { $form->setData($this->getFormData()); $viewModelTab = new ViewModel(); $viewModelTab->setTemplate($config['tab_form_layout']); $viewModelTab->modalForm = $form; $viewModelTab->formData = $this->getFormData(); $viewRender = $this->getServiceLocator()->get('ViewRenderer'); $html = $viewRender->render($viewModelTab); array_push($render, [ 'name' => $config['tab_title'], 'icon' => $config['tab_icon'], 'html' => $html ] ); } else { // validate the forms and send back an array with errors by tabs $post = get_object_vars($request->getPost()); $success = false; $form->setData($post); $errors = array(); if ($form->isValid()) { $data = $form->getData(); $success = true; array_push($response, [ 'name' => $this->pluginBackConfig['modal_form'][$formKey]['tab_title'], 'success' => $success, ]); } else { $errors = $form->getMessages(); foreach ($errors as $keyError => $valueError) { foreach ($config['elements'] as $keyForm => $valueForm) { if ($valueForm['spec']['name'] == $keyError && !empty($valueForm['spec']['options']['label']) ) $errors[$keyError]['label'] = $valueForm['spec']['options']['label']; } } array_push($response, [ 'name' => $this->pluginBackConfig['modal_form'][$formKey]['tab_title'], 'success' => $success, 'errors' => $errors, 'message' => '', ]); } } } } if (!isset($parameters['validate'])) { return $render; } else { return $response; } }
php
{ "resource": "" }
q8624
Safeurl.make
train
public function make($text, $options = null) { $this->setUserOptions($options); // set user defined options $text = $this->decode($text); // decode UTF-8 chars $text = trim($text); // trim $text = $this->lower($text); // convert to lowercase $text = $this->strip($text); // strip HTML $text = $this->filter($text); // filter the input //chop? if (strlen($text) > $this->maxlength) { $text = substr($text, 0, $this->maxlength); if ($this->whole_word) { /* * If maxlength is small and leaves us with only part of one * word ignore the "whole_word" filtering. */ $words = explode($this->separator, $text); $temp = implode($this->separator, array_diff($words, [array_pop($words)])); if ($temp != '') { $text = $temp; } } $text = rtrim($text, $this->separator); // remove any trailing separators } //return =] if ($text == '') { return $this->blank; } return $text; }
php
{ "resource": "" }
q8625
Safeurl.setUserOptions
train
private function setUserOptions($options) { if (is_array($options)) { foreach ($options as $property => $value) { $this->$property = $value; } } }
php
{ "resource": "" }
q8626
Safeurl.convertCharacters
train
public function convertCharacters($text) { $text = html_entity_decode($text, ENT_QUOTES, $this->decode_charset); $text = strtr($text, $this->translation_table); return $text; }
php
{ "resource": "" }
q8627
Safeurl.filter
train
private function filter($text) { $text = preg_replace("/[^&a-z0-9-_\s']/i", '', $text); $text = str_replace(' ', $this->separator, $text); $text = trim(preg_replace("/{$this->separator}{2,}/", $this->separator, $text), $this->separator); return $text; }
php
{ "resource": "" }
q8628
BackupListener.onBackupStarted
train
public function onBackupStarted(BackupEvent $event) { $database = $event->getDatabase(); $database->set('started', (new \DateTime())->format(\DateTime::RFC3339)); }
php
{ "resource": "" }
q8629
BackupListener.onBackup
train
public function onBackup(BackupEvent $event) { $plugin = $this->pluginRegistry->getPlugin($event->getOption('plugin')); $optionsResolver = new OptionsResolver(); $plugin->configureOptionsResolver($optionsResolver); $parameter = $optionsResolver->resolve($event->getOption('parameter')); try { $plugin->backup($event->getSource(), $event->getDestination(), $event->getDatabase(), $parameter); $event->setStatus(BackupStatus::STATE_SUCCESS); } catch (\Exception $exception) { $event->setStatus(BackupStatus::STATE_FAILED); $event->setException($exception); } }
php
{ "resource": "" }
q8630
BackupListener.onBackupFinished
train
public function onBackupFinished(BackupEvent $event) { $database = $event->getDatabase(); $database->set('finished', (new \DateTime())->format(\DateTime::RFC3339)); $database->set('state', $event->getStatus()); if (BackupStatus::STATE_FAILED === $event->getStatus()) { $database->set('exception', $this->serializeException($event->getException())); } }
php
{ "resource": "" }
q8631
BackupListener.serializeException
train
private function serializeException(\Exception $exception) { return [ 'message' => $exception->getMessage(), 'code' => $exception->getCode(), 'trace' => $exception->getTrace(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'previous' => null !== $exception->getPrevious() ? $this->serializeException($exception->getPrevious()) : null, ]; }
php
{ "resource": "" }
q8632
DoctrineMigrationRepository.repositoryExists
train
public function repositoryExists() { $schema = $this->em->getConnection()->getSchemaManager(); $tables = array_filter($schema->listTables(), function ($value) { return $value->getName() === 'migrations'; }); return !empty($tables); }
php
{ "resource": "" }
q8633
Gdaemon.writeAndReadSocket
train
protected function writeAndReadSocket($buffer) { $this->writeSocket($buffer . self::SOCKET_MSG_ENDL); $read = $this->readSocket(); return $read; }
php
{ "resource": "" }
q8634
AuthClient.AuthEnable
train
public function AuthEnable(AuthEnableRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/AuthEnable', $argument, ['\Etcdserverpb\AuthEnableResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8635
AuthClient.AuthDisable
train
public function AuthDisable(AuthDisableRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/AuthDisable', $argument, ['\Etcdserverpb\AuthDisableResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8636
AuthClient.Authenticate
train
public function Authenticate(AuthenticateRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/Authenticate', $argument, ['\Etcdserverpb\AuthenticateResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8637
AuthClient.UserAdd
train
public function UserAdd(AuthUserAddRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/UserAdd', $argument, ['\Etcdserverpb\AuthUserAddResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8638
AuthClient.UserGet
train
public function UserGet(AuthUserGetRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/UserGet', $argument, ['\Etcdserverpb\AuthUserGetResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8639
AuthClient.UserList
train
public function UserList(AuthUserListRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/UserList', $argument, ['\Etcdserverpb\AuthUserListResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8640
AuthClient.UserDelete
train
public function UserDelete(AuthUserDeleteRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/UserDelete', $argument, ['\Etcdserverpb\AuthUserDeleteResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8641
AuthClient.UserChangePassword
train
public function UserChangePassword(AuthUserChangePasswordRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/UserChangePassword', $argument, ['\Etcdserverpb\AuthUserChangePasswordResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8642
AuthClient.UserGrantRole
train
public function UserGrantRole(AuthUserGrantRoleRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/UserGrantRole', $argument, ['\Etcdserverpb\AuthUserGrantRoleResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8643
AuthClient.UserRevokeRole
train
public function UserRevokeRole(AuthUserRevokeRoleRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/UserRevokeRole', $argument, ['\Etcdserverpb\AuthUserRevokeRoleResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8644
AuthClient.RoleAdd
train
public function RoleAdd(AuthRoleAddRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/RoleAdd', $argument, ['\Etcdserverpb\AuthRoleAddResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8645
AuthClient.RoleGet
train
public function RoleGet(AuthRoleGetRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/RoleGet', $argument, ['\Etcdserverpb\AuthRoleGetResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8646
AuthClient.RoleList
train
public function RoleList(AuthRoleListRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/RoleList', $argument, ['\Etcdserverpb\AuthRoleListResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8647
AuthClient.RoleDelete
train
public function RoleDelete(AuthRoleDeleteRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/RoleDelete', $argument, ['\Etcdserverpb\AuthRoleDeleteResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8648
AuthClient.RoleGrantPermission
train
public function RoleGrantPermission(AuthRoleGrantPermissionRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/RoleGrantPermission', $argument, ['\Etcdserverpb\AuthRoleGrantPermissionResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8649
AuthClient.RoleRevokePermission
train
public function RoleRevokePermission(AuthRoleRevokePermissionRequest $argument, $metadata = [], $options = []) { return $this->_simpleRequest('/etcdserverpb.Auth/RoleRevokePermission', $argument, ['\Etcdserverpb\AuthRoleRevokePermissionResponse', 'decode'], $metadata, $options); }
php
{ "resource": "" }
q8650
Model.load
train
public function load($relations) { $query = $this->newQuery()->with( is_string($relations) ? func_get_args() : $relations ); $query->eagerLoadRelations([$this]); return $this; }
php
{ "resource": "" }
q8651
Model.freshTimestamp
train
public function freshTimestamp() { $t = microtime(true); $micro = sprintf("%06d",($t - floor($t)) * 1000000); return new Carbon(date('Y-m-d H:i:s.'.$micro, $t)); }
php
{ "resource": "" }
q8652
FileDescriptorProto.addDependency
train
public function addDependency($value) { if ($this->dependency === null) { $this->dependency = new \Protobuf\ScalarCollection(); } $this->dependency->add($value); }
php
{ "resource": "" }
q8653
FileDescriptorProto.addPublicDependency
train
public function addPublicDependency($value) { if ($this->public_dependency === null) { $this->public_dependency = new \Protobuf\ScalarCollection(); } $this->public_dependency->add($value); }
php
{ "resource": "" }
q8654
FileDescriptorProto.addWeakDependency
train
public function addWeakDependency($value) { if ($this->weak_dependency === null) { $this->weak_dependency = new \Protobuf\ScalarCollection(); } $this->weak_dependency->add($value); }
php
{ "resource": "" }
q8655
FileDescriptorProto.addMessageType
train
public function addMessageType(\google\protobuf\DescriptorProto $value) { if ($this->message_type === null) { $this->message_type = new \Protobuf\MessageCollection(); } $this->message_type->add($value); }
php
{ "resource": "" }
q8656
FileDescriptorProto.addEnumType
train
public function addEnumType(\google\protobuf\EnumDescriptorProto $value) { if ($this->enum_type === null) { $this->enum_type = new \Protobuf\MessageCollection(); } $this->enum_type->add($value); }
php
{ "resource": "" }
q8657
FileDescriptorProto.addService
train
public function addService(\google\protobuf\ServiceDescriptorProto $value) { if ($this->service === null) { $this->service = new \Protobuf\MessageCollection(); } $this->service->add($value); }
php
{ "resource": "" }
q8658
FileDescriptorProto.addExtension
train
public function addExtension(\google\protobuf\FieldDescriptorProto $value) { if ($this->extension === null) { $this->extension = new \Protobuf\MessageCollection(); } $this->extension->add($value); }
php
{ "resource": "" }
q8659
SshConnection.execute
train
public function execute($command, callable $callback = null) { $this->login(); return $this->ssh->exec(sprintf('cd %s; %s', $this->directory, $command), $callback); }
php
{ "resource": "" }
q8660
SshConnection.executeNanbando
train
public function executeNanbando($command, array $parameter, callable $callback = null) { $this->login(); $parameterString = []; foreach ($parameter as $key => $value) { if (!is_array($value)) { $value = [$value]; } foreach ($value as $item) { $parameterString[] = trim((is_string($key) ? $key . ' ' : '') . $item); } } return $this->execute( sprintf('%s %s %s', $this->executable, $command, implode(' ', $parameterString)), $callback ); }
php
{ "resource": "" }
q8661
SshConnection.get
train
public function get($remoteFile, $localFile) { $this->login(); if (!isset($this->ssh)) { return false; } if (!$this->ssh->exec('scp -f ' . escapeshellarg($remoteFile), false)) { // -f = from return false; } $this->sendPacket("\0"); if (!preg_match('#(?<perms>[^ ]+) (?<size>\d+) (?<name>.+)#', rtrim($this->receivePacket()), $info)) { return false; } $this->sendPacket("\0"); $size = 0; $fp = null; if ($localFile !== false) { $fp = @fopen($localFile, 'wb'); if (!$fp) { return false; } } $progressBar = new ProgressBar($this->output, $info['size']); $progressBar->setFormat(' %message% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'); $progressBar->start(); $byteFormatter = new ByteFormatter(); $content = ''; while ($size < $info['size']) { $data = $this->receivePacket(); // SCP usually seems to split stuff out into 16k chunks $length = strlen($data); $size += $length; $progressBar->advance($length); $progressBar->setMessage( sprintf('%s/%s', $byteFormatter->format($size), $byteFormatter->format($info['size'])) ); if (!$fp) { $content .= $data; } else { fwrite($fp, $data); } } $progressBar->finish(); $this->output->writeln(''); $this->closeChannel(); return true; }
php
{ "resource": "" }
q8662
SshConnection.login
train
private function login() { if ($this->loggedIn) { return; } if (array_key_exists('rsakey', $this->sshConfig)) { $this->loginWithRsaKey(); } elseif (array_key_exists('password', $this->sshConfig)) { $this->loginWithPassword(); } $this->loggedIn = $this->validate(); }
php
{ "resource": "" }
q8663
SshConnection.loginWithPassword
train
private function loginWithPassword() { $password = $this->sshConfig['password']; if (!is_string($password)) { $password = $this->askForPassword( sprintf( 'Password for %s@%s:%s: ', $this->sshConfig['username'], $this->sshConfig['host'], $this->sshConfig['port'] ) ); } if (!$this->ssh->login($this->sshConfig['username'], $password)) { throw new SshLoginException($this->name); } return true; }
php
{ "resource": "" }
q8664
SshConnection.loginWithRsaKey
train
private function loginWithRsaKey() { $key = new RSA(); $password = $this->sshConfig['rsakey']['password']; if ($password) { if (!is_string($password)) { $password = $this->askForPassword( sprintf('Password for file "%s": ', $this->sshConfig['rsakey']['file']) ); } $key->setPassword($password); } $key->loadKey(file_get_contents($this->sshConfig['rsakey']['file'])); if (!$this->ssh->login($this->sshConfig['username'], $key)) { throw new SshLoginException($this->name); } return true; }
php
{ "resource": "" }
q8665
SshConnection.askForPassword
train
private function askForPassword($question) { $questionHelper = new QuestionHelper(); $question = new Question($question); $question->setHidden(true); $question->setHiddenFallback(false); $password = $questionHelper->ask($this->input, $this->output, $question); $this->output->writeln(''); return $password; }
php
{ "resource": "" }
q8666
SshConnection.validate
train
private function validate() { if (!$this->testServer($this->ssh, sprintf('-d "%s"', $this->directory))) { throw new SshValidateException('Directory does not exists'); } if (!$this->testServer($this->ssh, sprintf('-x "%s"', $this->executable), $this->directory)) { throw new SshValidateException('Executable does not exists'); } return true; }
php
{ "resource": "" }
q8667
AmaranHandler.create
train
public function create() { $script = "<script>\n\t$(function(){ \n\t\t"; if ($this->click) { $script .= "\t$('".$this->click[0]."').on('".$this->click[1]."',function(){ \n\t\t\t\t $.amaran(". json_encode($this->amaran).") \n\t\t\t}); \n\t\t});\n\t</script>\n"; } else { $script .= "$.amaran(".json_encode($this->amaran)."); \n\t });\n</script>\n"; } if ($this->flash) { $this->session->flash('amaranjs.content', $script); } else { $this->viewBinder->bind($script); } }
php
{ "resource": "" }
q8668
Builder.whereSub
train
protected function whereSub($column, $operator, Closure $callback, $boolean) { $type = 'Sub'; $query = $this->newQuery(); // Once we have the query instance we can simply execute it so it can add all // of the sub-select's conditions to itself, and then we can cache it off // in the array of where clauses for the "main" parent query instance. call_user_func($callback, $query); $this->wheres[] = compact('type', 'column', 'operator', 'query', 'boolean'); $this->addBinding($query->getBindings(), 'where'); return $this; }
php
{ "resource": "" }
q8669
Builder.whereInSub
train
protected function whereInSub($column, Closure $callback, $boolean, $not) { $type = $not ? 'NotInSub' : 'InSub'; // To create the exists sub-select, we will actually create a query and call the // provided callback with the query so the developer may set any of the query // conditions they want for the in clause, then we'll put it in this array. call_user_func($callback, $query = $this->newQuery()); $this->wheres[] = compact('type', 'column', 'query', 'boolean'); $this->addBinding($query->getBindings(), 'where'); return $this; }
php
{ "resource": "" }
q8670
Builder.whereTime
train
public function whereTime($column, $operator, $value, $boolean = 'and') { return $this->addDateBasedWhere('Time', $column, $operator, $value, $boolean); }
php
{ "resource": "" }
q8671
Builder.backupFieldsForCount
train
protected function backupFieldsForCount() { foreach (['orders', 'limit', 'offset', 'columns'] as $field) { $this->backups[$field] = $this->{$field}; $this->{$field} = null; } foreach (['order', 'select'] as $key) { $this->bindingBackups[$key] = $this->bindings[$key]; $this->bindings[$key] = []; } }
php
{ "resource": "" }
q8672
UploadListener.createFileHistory
train
protected function createFileHistory(PostPersistEvent $event) { // Find original filename in request uploaded file $files = $event->getRequest()->files->all(); $uploadedFile = array_pop($files); $originalFileName = $uploadedFile->getClientOriginalName(); // Get generated filename $fileName = $event->getFile()->getBasename(); // Fill FileHistory object return $this->fileHistoryManager->createAndSave($fileName, $originalFileName, $event->getType()); }
php
{ "resource": "" }
q8673
Builder.mergeConstraintsFrom
train
public function mergeConstraintsFrom(Builder $from) { $whereBindings = array_get( $from->getQuery()->getRawBindings(), 'where', [] ); // Here we have some other query that we want to merge the where constraints from. We will // copy over any where constraints on the query as well as remove any global scopes the // query might have removed. Then we will return ourselves with the finished merging. return $this->withoutGlobalScopes( $from->removedScopes() )->mergeWheres( $from->getQuery()->wheres, $whereBindings ); }
php
{ "resource": "" }
q8674
Builder.firstOr
train
public function firstOr($columns = ['*'], callable $callback = null) { if (is_callable($columns)) { $callback = $columns; $columns = ['*']; } if (! is_null($model = $this->first($columns))) { return $model; } return call_user_func($callback); }
php
{ "resource": "" }
q8675
ModelFactory.map
train
public function map($row){ $class = $this->modelClass; $model = new $class($this->db, $row, false); $model->setAttribute('table', $this->table)->setAttribute('pk', $this->pk); return $model; }
php
{ "resource": "" }
q8676
ModelFactory.mapModels
train
public function mapModels($rows){ $rst = array(); foreach($rows as $row){ $rst[] = $this->map($row); } return $rst; }
php
{ "resource": "" }
q8677
ModelFactory.create
train
public function create($row = array()){ $class = $this->modelClass; $model = new $class($this->db, $row); $model->setAttribute('table', $this->table)->setAttribute('pk', $this->pk); return $model; }
php
{ "resource": "" }
q8678
ModelFactory.count
train
public function count($conditions = '', $params = array()){ return $this->db->builder()->select('COUNT(*)')->from($this->table)->where($conditions, $params)->queryValue(); }
php
{ "resource": "" }
q8679
ModelFactory.findOne
train
public function findOne($conditions, $params = array()){ $row = $this->db->builder()->select()->from($this->table)->where($conditions, $params)->limit(1)->queryRow(); if(false === $row){ return false; } return $this->map($row); }
php
{ "resource": "" }
q8680
ModelFactory.findByPK
train
public function findByPK($pk){ $pkConditions = $this->buildPKConditions($this->pk, $pk); return $this->findOne($pkConditions[0], $pkConditions[1]); }
php
{ "resource": "" }
q8681
ModelFactory.findMany
train
public function findMany($conditions = '', $params = array(), $orderBy = null, $limit = null, $offset = null){ $cmd = $this->db->builder()->select()->from($this->table)->where($conditions, $params); if($orderBy){ $cmd->orderBy($orderBy); } $rows = $cmd->limit($limit, $offset)->queryAll(); if(false === $rows){ return false; } else{ return $this->mapModels($rows); } }
php
{ "resource": "" }
q8682
ModelFactory.findManyBy
train
public function findManyBy($key, $value, $orderBy = null, $limit = null, $offset = null){ return $this->findMany($key.'=:key', array(':key' => $value), $orderBy, $limit, $offset); }
php
{ "resource": "" }
q8683
ModelFactory.update
train
public function update($values, $conditions, $params = array()){ return $this->db->builder()->update($this->table, $values, $conditions, $params); }
php
{ "resource": "" }
q8684
ModelFactory.updateByPK
train
public function updateByPK($pk, $values){ $pkConditions = $this->buildPKConditions($this->pk, $pk); return $this->update($values, $pkConditions[0], $pkConditions[1]); }
php
{ "resource": "" }
q8685
ModelFactory.delete
train
public function delete($conditions, $params = array()){ return $this->db->builder()->delete($this->table, $conditions, $params); }
php
{ "resource": "" }
q8686
ModelFactory.deleteByPK
train
public function deleteByPK($pk){ $pkConditions = $this->buildPKConditions($this->pk, $pk); return $this->delete($pkConditions[0], $pkConditions[1]); }
php
{ "resource": "" }
q8687
BelongsToMany.findMany
train
public function findMany($ids, $columns = ['*']) { return empty($ids) ? [] : $this->whereIn( $this->getRelated()->getQualifiedKeyName(), $ids )->get($columns); }
php
{ "resource": "" }
q8688
curlMaster.Array2string
train
private function Array2string($arr, $glue = '&') { if (!is_array($arr)) { throw new Exception('Argument arr must be array');; } $new = array(); foreach ($arr as $k => $v) { $new[] = urlencode($k) .'='. urlencode($v); } return implode($glue, $new); }
php
{ "resource": "" }
q8689
curlMaster.getHeaders
train
private function getHeaders($str) { $str = explode(self::LE . self::LE, $str); $str = reset($str); $str = explode(self::LE, $str); $new = array(); $s = 1; foreach ($str as $line) { $pos = strpos($line, ': '); if ($pos !== false) { $key = strtolower(substr($line, 0, $pos)); if (!isset($new[$key])) { $new[$key] = preg_replace('/\s+/', ' ', trim(substr($line, $pos+1))); } else { $new[$key.'-'.$s] = preg_replace('/\s+/', ' ', trim(substr($line, $pos+1))); $s++; } } else { $new['status'] = $line; # HTTP/1.1 200 OK } } return $new; }
php
{ "resource": "" }
q8690
curlMaster.getBody
train
private function getBody($str) { $str = substr($str, strpos($str, self::LE . self::LE)); return trim($str); }
php
{ "resource": "" }
q8691
curlMaster.ParseCachingHeader
train
private function ParseCachingHeader($arr) { if (!empty($arr['cache-control'])) { if (strpos('no-cache', $arr['cache-control']) !== false) { return 0; } if (strpos('no-store', $arr['cache-control']) !== false) { return 0; } if (strpos('max-age=0', $arr['cache-control']) !== false) { return 0; } if (preg_match('/\bmax-age=(\d+),?\b/', $arr['cache-control'], $match)) { return (integer) $match[1]; } } if (!empty($arr['expires'])) { if (preg_match('/^-\d+|0$/', $arr['expires'])) { return 0; } $epoch = strtotime($arr['expires']); $sec = $epoch - time(); if ($sec > 0) { return $sec; } return 0; } return 0; }
php
{ "resource": "" }
q8692
curlMaster.GetCookieFileName
train
private function GetCookieFileName($url) { $temp = parse_url($url); $ext = (string) $this->CookieMaxAge; return $this->CacheDir .'/CURL_COOKIE-'. sha1($temp['host']) .'.'. $ext; }
php
{ "resource": "" }
q8693
curlMaster.DeleteChacheFile
train
public function DeleteChacheFile($filename) { if (preg_match('/^\/CURL_RESPON-[0-9a-f]{40}\.\d+$/', $filename)) { $filename = $this->CacheDir . $filename; if (file_exists($filename)) { unlink($filename); } } }
php
{ "resource": "" }
q8694
curlMaster.FilePutContents
train
private function FilePutContents($file, $str) { $fileObj = new SplFileObject($file, 'w'); while (!$fileObj->flock(LOCK_EX)) { usleep(1); } $bytes = $fileObj->fwrite($str); $fileObj->flock(LOCK_UN); return $bytes; }
php
{ "resource": "" }
q8695
curlMaster.FileGetContents
train
private function FileGetContents($file) { $fileObj = new SplFileObject($file, 'r'); while (!$fileObj->flock(LOCK_EX)) { usleep(1); } $str = $fileObj->fread($fileObj->getSize()); $fileObj->flock(LOCK_UN); return $str; }
php
{ "resource": "" }
q8696
PWEModule.getBaseLink
train
protected function getBaseLink() { $res = '.'; $res .= str_repeat("/..", sizeof($this->PWE->getURL()->getParamsAsArray())); return $res; }
php
{ "resource": "" }
q8697
App.addRoute
train
public function addRoute(string $method, string $route, ...$callback) { $method = strtolower($method); $route = ltrim($route, '/'); $group = rtrim($this->group, '/') . '/'; $route = $group . $route; $scope = $this->middleware->count(); $this->layer[$method][] = new Route( $method, $route, $callback, $scope, $this->group ); return true; }
php
{ "resource": "" }
q8698
App.import
train
public function import(array $loader) { $this->loader = $loader; foreach ($loader as $alias => $namespace) { $alias = $this->alias($alias); $this->container->set($alias, function ($c) use ($alias, $namespace) { if (is_callable([$namespace, 'make'])) { call_user_func_array($namespace . '::make', [$alias, $c]); } return new $namespace(); }); } }
php
{ "resource": "" }
q8699
ApplicationData.getData
train
public function getData() { $data = []; foreach ($this->providerList as $provider) { $data += $provider->getData(); } return $data; }
php
{ "resource": "" }