_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q100
RedirectLoginHelper.validateCsrf
train
protected function validateCsrf() { if (empty($this->getInput('state')) || ($this->getInput('state') !== $this->store->get('oauth2state')) ) { $this->store->set('oauth2state', null); throw new CsrfException('Invalid state'); } return; }
php
{ "resource": "" }
q101
Client.getAccessToken
train
public function getAccessToken($code, $grant = 'authorization_code') { $token = $this->container->get(RedirectLoginHelper::class) ->getAccessToken($code, $grant); $this->setAccessToken($token); return $token; }
php
{ "resource": "" }
q102
Client.setAccessToken
train
public function setAccessToken(AccessToken $token) { $this->container->get('config') ->set('access_token', json_encode($token->jsonSerialize())); }
php
{ "resource": "" }
q103
Profile.getData
train
public function getData($sEmail) { $this->sFormat = 'php'; $sProfile = file_get_contents($this->getUrl($sEmail)); $aProfile = unserialize($sProfile); if (is_array($aProfile) && isset($aProfile['entry'])) { return $aProfile; } }
php
{ "resource": "" }
q104
Profile.format
train
public function format($sFormat= null) { if (null === $sFormat) { return $this->getFormat(); } return $this->setFormat($sFormat); }
php
{ "resource": "" }
q105
Profile.setFormat
train
public function setFormat($sFormat = null) { if (null === $sFormat) { return $this; } if (!in_array($sFormat, $this->aValidFormats)) { $message = sprintf( 'The format "%s" is not a valid one, profile format for Gravatar can be: %s', $s...
php
{ "resource": "" }
q106
RegisterController.createSignup
train
protected function createSignup(array $data, $userId) { return Signup::create([ 'user_id' => $userId, 'firstname' => $data['firstname'], 'surname' => $data['surname'], 'gender' => $data['gender'], 'email' => $data['email'], 'mobile_numb...
php
{ "resource": "" }
q107
Guzzle.handleErrors
train
private static function handleErrors($response) { switch ($response->getStatusCode()) { case 200: return json_decode($response->getBody()); break; case 401: throw new UnauthorizedException('Unauthorized (Invalid API key or insufficient ...
php
{ "resource": "" }
q108
LatLong.primeCoordinateParsers
train
protected function primeCoordinateParsers() { $this->latitude->getParser()->setDirection(N::LAT); $this->longitude->getParser()->setDirection(N::LONG); }
php
{ "resource": "" }
q109
DefaultController.servicosDisponiveisUnidade
train
private function servicosDisponiveisUnidade($unidade) { $rs = $this ->getDoctrine() ->getManager() ->createQueryBuilder() ->select([ 'e', 's', 'sub' ]) ->from(ServicoUnidade::class, 'e') ...
php
{ "resource": "" }
q110
PasswordlessProvider.registerEvents
train
public function registerEvents() { // Delete user tokens after login if (config('passwordless.empty_tokens_after_login') === true) { Event::listen( Authenticated::class, function (Authenticated $event) { $event->user->tokens() ...
php
{ "resource": "" }
q111
Worker.processOne
train
public function processOne(ObjectId $id): void { $this->catchSignal(); $this->logger->debug('process job ['.$id.'] and exit', [ 'category' => get_class($this), ]); try { $job = $this->scheduler->getJob($id)->toArray(); $this->queueJob($job); ...
php
{ "resource": "" }
q112
Worker.cleanup
train
public function cleanup() { $this->saveState(); if (null === $this->current_job) { $this->logger->debug('received cleanup call on worker ['.$this->id.'], no job is currently processing, exit now', [ 'category' => get_class($this), 'pm' => $this->process, ...
php
{ "resource": "" }
q113
Worker.saveState
train
protected function saveState(): self { foreach ($this->queue as $key => $job) { $this->db->selectCollection($this->scheduler->getJobQueue())->updateOne( ['_id' => $job['_id'], '$isolated' => true], ['$setOnInsert' => $job], ['upsert' => true] ...
php
{ "resource": "" }
q114
Worker.catchSignal
train
protected function catchSignal(): self { pcntl_async_signals(true); pcntl_signal(SIGTERM, [$this, 'cleanup']); pcntl_signal(SIGINT, [$this, 'cleanup']); pcntl_signal(SIGALRM, [$this, 'timeout']); return $this; }
php
{ "resource": "" }
q115
Worker.queueJob
train
protected function queueJob(array $job): bool { if (!isset($job['status'])) { return false; } if (true === $this->collectJob($job, JobInterface::STATUS_PROCESSING)) { $this->processJob($job); } elseif (JobInterface::STATUS_POSTPONED === $job['status']) { ...
php
{ "resource": "" }
q116
Worker.processLocalQueue
train
protected function processLocalQueue(): bool { $now = time(); foreach ($this->queue as $key => $job) { $this->db->{$this->scheduler->getJobQueue()}->updateOne( ['_id' => $job['_id'], '$isolated' => true], ['$setOnInsert' => $job], ['upsert'...
php
{ "resource": "" }
q117
Worker.executeJob
train
protected function executeJob(array $job): bool { if (!class_exists($job['class'])) { throw new InvalidJobException('job class does not exists'); } if (null === $this->container) { $instance = new $job['class'](); } else { $instance = $this->conta...
php
{ "resource": "" }
q118
Loader.addToHTML
train
public static function addToHTML() { if (!self::isViewingHTMLPage()) { return; } // js $paths = self::getAssetFilePaths('js'); echo sprintf( '<script>%s</script>', self::getCombinedContents($paths) ); // css $paths...
php
{ "resource": "" }
q119
Loader.isViewingHTMLPage
train
public static function isViewingHTMLPage() { if (!is_admin()) { return false; } if (!array_key_exists('SCRIPT_NAME', $_SERVER)) { return false; } $whitelisted_script_names = array( 'wp-admin/post-new.php', 'wp-admin/pos...
php
{ "resource": "" }
q120
Loader.getAssetFilePaths
train
public static function getAssetFilePaths($type) { $path = sprintf('%s/assets/%s/', __DIR__, $type); $filenames = preg_grep('/^[^\.]/', scandir($path)); if (!Arr::iterable($filenames)) { return array(); } return array_map(function ($filename) use ($path) { ...
php
{ "resource": "" }
q121
Loader.getCombinedContents
train
public static function getCombinedContents($paths) { if (!Arr::iterable($paths)) { return ''; } $out = array(); foreach ($paths as $path) { $out[] = file_get_contents($path); } return join("\n", $out); }
php
{ "resource": "" }
q122
Prpcrypt.decode
train
public function decode($decrypted) { $pad = ord(substr($decrypted, -1)); if ($pad < 1 || $pad > $this->blockSize) { $pad = 0; } return substr($decrypted, 0, (strlen($decrypted) - $pad)); }
php
{ "resource": "" }
q123
SchedulerValidator.validateOptions
train
public static function validateOptions(array $options): array { foreach ($options as $option => $value) { switch ($option) { case Scheduler::OPTION_AT: case Scheduler::OPTION_INTERVAL: case Scheduler::OPTION_RETRY: case Scheduler::O...
php
{ "resource": "" }
q124
Helper.addRedirectUriToServiceConfig
train
protected static function addRedirectUriToServiceConfig(array $config) { if (!empty($config['constructor']) && is_array($config['constructor'])) { $key = key($config['constructor']); // Key may be non-numeric if (!isset($config['constructor'][$key]['redirectUri'])) { ...
php
{ "resource": "" }
q125
Image.getUrl
train
public function getUrl($sEmail = null) { if (null !== $sEmail) { $this->setEmail($sEmail); } return static::URL .'avatar/' .$this->getHash($this->getEmail()) .$this->getParams(); }
php
{ "resource": "" }
q126
Image.size
train
public function size($iSize = null) { if (null === $iSize) { return $this->getSize(); } return $this->setSize($iSize); }
php
{ "resource": "" }
q127
Image.defaultImage
train
public function defaultImage($sDefaultImage = null, $bForce = false) { if (null === $sDefaultImage) { return $this->getDefaultImage(); } return $this->setDefaultImage($sDefaultImage, $bForce); }
php
{ "resource": "" }
q128
Image.forceDefault
train
public function forceDefault($bForceDefault = null) { if (null === $bForceDefault) { return $this->getForceDefault(); } return $this->setForceDefault($bForceDefault); }
php
{ "resource": "" }
q129
Image.rating
train
public function rating($sRating = null) { if (null === $sRating) { return $this->getMaxRating(); } return $this->setMaxRating($sRating); }
php
{ "resource": "" }
q130
Image.extension
train
public function extension($sExtension = null) { if (null === $sExtension) { return $this->getExtension(); } return $this->setExtension($sExtension); }
php
{ "resource": "" }
q131
Image.setExtension
train
public function setExtension($sExtension = null) { if (null === $sExtension) { return $this; } if (!in_array($sExtension, $this->aValidExtensions)) { $message = sprintf( 'The extension "%s" is not a valid one, extension image for Gravatar can be: %s',...
php
{ "resource": "" }
q132
Image.getParams
train
protected function getParams() { $aParams = []; if (null !== $this->getSize()) { $aParams['s'] = $this->getSize(); } if (null !== $this->getDefaultImage()) { $aParams['d'] = $this->getDefaultImage(); } if (null !== $this->getMaxRating()) { ...
php
{ "resource": "" }
q133
ResponsiveImageRenderer.render
train
public function render(FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false): string { if (!array_key_exists(self::OPTIONS_IMAGE_RELATVE_WIDTH_KEY, $options) && isset($GLOBALS['TSFE']->register[self::REGISTER_IMAGE_RELATVE_WIDTH_KEY]) ) { ...
php
{ "resource": "" }
q134
Configuration.getPattern
train
public function getPattern(PackageInterface $package) { if (isset($this->packages[$package->getName()])) { return $this->packages[$package->getName()]; } elseif (isset($this->packages[$package->getPrettyName()])) { return $this->packages[$package->getPrettyName()]; } ...
php
{ "resource": "" }
q135
Configuration.convert
train
protected function convert($extra) { if (isset($extra['custom-installer'])) { foreach ($extra['custom-installer'] as $pattern => $specs) { foreach ($specs as $spec) { $match = array(); // Type matching if (preg_match('/^...
php
{ "resource": "" }
q136
Controller.getReturnUrl
train
protected function getReturnUrl() { $backUrl = $this->getRequest()->getSession()->get('oauth2.backurl'); if (!$backUrl || !Director::is_site_url($backUrl)) { $backUrl = Director::absoluteBaseURL(); } return $backUrl; }
php
{ "resource": "" }
q137
Controller.authenticate
train
public function authenticate(HTTPRequest $request) { $providerName = $request->getVar('provider'); $context = $request->getVar('context'); $scope = $request->getVar('scope'); // Missing or invalid data means we can't proceed if (!$providerName || !is_array($scope)) { ...
php
{ "resource": "" }
q138
Controller.callback
train
public function callback(HTTPRequest $request) { $session = $request->getSession(); if (!$this->validateState($request)) { $session->clear('oauth2'); $this->httpError(400, 'Invalid session state.'); return null; } $providerName = $session->get('o...
php
{ "resource": "" }
q139
Controller.getHandlersForContext
train
protected function getHandlersForContext($context = null) { $handlers = $this->config()->get('token_handlers'); if (empty($handlers)) { throw new Exception('No token handlers were registered'); } // If we've been given a context, limit to that context + global handlers. ...
php
{ "resource": "" }
q140
Controller.validateState
train
public function validateState(HTTPRequest $request) { $state = $request->getVar('state'); $session = $request->getSession(); $data = $session->get('oauth2'); // If we're lacking any required data, or the session state doesn't match // the one the provider returned, the reque...
php
{ "resource": "" }
q141
Challonge.getTournaments
train
public function getTournaments() { $response = Guzzle::get('tournaments'); $tournaments = []; foreach ($response as $tourney) { $tournaments[] = new Tournament($tourney->tournament); } return $tournaments; }
php
{ "resource": "" }
q142
Challonge.getParticipants
train
public function getParticipants($tournament) { $response = Guzzle::get("tournaments/{$tournament}/participants"); $participants = []; foreach ($response as $team) { $participant = new Participant($team->participant); $participant->tournament_slug = $tournament; ...
php
{ "resource": "" }
q143
Challonge.randomizeParticipants
train
public function randomizeParticipants($tournament) { $response = Guzzle::post("tournaments/{$tournament}/participants/randomize"); $participants = []; foreach ($response as $team) { $participant = new Participant($team->participant); $participant->tournament_slug = $...
php
{ "resource": "" }
q144
Challonge.getParticipant
train
public function getParticipant($tournament, $participant) { $response = Guzzle::get("tournaments/{$tournament}/participants/{$participant}"); $participant = new Participant($response->participant); $participant->tournament_slug = $tournament; return $participant; }
php
{ "resource": "" }
q145
Challonge.getMatches
train
public function getMatches($tournament) { $response = Guzzle::get("tournaments/{$tournament}/matches"); $matches = []; foreach ($response as $match) { $matchModel = new Match($match->match); $matchModel->tournament_slug = $tournament; $matches[] = $matchM...
php
{ "resource": "" }
q146
Challonge.getMatch
train
public function getMatch($tournament, $match) { $response = Guzzle::get("tournaments/{$tournament}/matches/{$match}"); $match = new Match($response->match); $match->tournament_slug = $tournament; return $match; }
php
{ "resource": "" }
q147
StubLocale.getCurrenciesData
train
public static function getCurrenciesData($locale) { if (null === self::$currencies) { self::prepareCurrencies($locale); } return self::$currencies; }
php
{ "resource": "" }
q148
StubLocale.getDisplayCurrencies
train
public static function getDisplayCurrencies($locale) { if (null === self::$currenciesNames) { self::prepareCurrencies($locale); } return self::$currenciesNames; }
php
{ "resource": "" }
q149
TranslatedFile.updateCMSFields
train
public function updateCMSFields(FieldList $fields) { // only apply the update to files (not folders) if ($this->owner->class != 'Folder') { // add the tabs from the translatable tab set to the fields /** @var TabSet $set */ $set = $this->owner->getTranslatableTabS...
php
{ "resource": "" }
q150
TranslatableDataObject.get_extra_config
train
public static function get_extra_config($class, $extension, $args) { if (!self::is_translatable_installed()) { // remain silent during a test if (SapphireTest::is_running_test()) { return null; } // raise an error otherwise user_err...
php
{ "resource": "" }
q151
TranslatableDataObject.updateCMSFields
train
public function updateCMSFields(FieldList $fields) { parent::updateCMSFields($fields); if (!isset(self::$collectorCache[$this->owner->class])) { return; } // remove all localized fields from the list (generated through scaffolding) foreach (self::$collectorCache...
php
{ "resource": "" }
q152
TranslatableDataObject.getLocalizedFormField
train
public function getLocalizedFormField($fieldName, $locale) { $baseName = $this->getBasename($fieldName); $fieldLabels = $this->owner->fieldLabels(); $localizedFieldName = self::localized_field($fieldName, $locale); $fieldLabel = isset($fieldLabels[$baseName]) ? $fieldLabels[$baseName...
php
{ "resource": "" }
q153
TranslatableDataObject.getLocalizedRelationField
train
public function getLocalizedRelationField($fieldName, $locale) { $baseName = $this->getBasename($fieldName); $localizedFieldName = self::localized_field($fieldName, $locale); $field = null; if ($field = $this->getFieldForRelation($fieldName)) { $relationField = clone $f...
php
{ "resource": "" }
q154
TranslatableDataObject.updateFieldLabels
train
public function updateFieldLabels(&$labels) { parent::updateFieldLabels($labels); $statics = self::$collectorCache[$this->ownerBaseClass]; foreach ($statics as $field => $type) { $parts = explode(TRANSLATABLE_COLUMN_SEPARATOR, $field); $labels[$field] = FormField::na...
php
{ "resource": "" }
q155
TranslatableDataObject.isLocalizedField
train
public function isLocalizedField($fieldName) { $fields = self::get_localized_class_fields($this->ownerBaseClass); return in_array($fieldName, $fields); }
php
{ "resource": "" }
q156
TranslatableDataObject.getLocalizedFieldName
train
public function getLocalizedFieldName($fieldName) { if ($this->isLocalizedField($fieldName) || $this->isLocalizedRelation($fieldName)) { return self::localized_field($fieldName); } trigger_error("Field '$fieldName' is not a localized field", E_USER_ERROR); }
php
{ "resource": "" }
q157
TranslatableDataObject.getLocalizedRelation
train
public function getLocalizedRelation($fieldName, $strict = true) { $localizedField = $this->getLocalizedFieldName($fieldName); if ($strict) { return $this->owner->getRelation($localizedField); } // if not strict, check localized first and fallback to fieldname i...
php
{ "resource": "" }
q158
TranslatableDataObject.getLocalizedValue
train
public function getLocalizedValue($fieldName, $strict = true, $parseShortCodes = false) { $localizedField = $this->getLocalizedFieldName($fieldName); // ensure that $strict is a boolean value $strict = filter_var($strict, FILTER_VALIDATE_BOOLEAN); /** @var DBField $value */ ...
php
{ "resource": "" }
q159
TranslatableDataObject.onBeforeWrite
train
public function onBeforeWrite() { if (!isset(self::$localizedFields[$this->ownerBaseClass])) { return; } $fields = self::$localizedFields[$this->ownerBaseClass]; foreach ($fields as $field => $localized) { foreach (self::get_target_locales() as $locale) { ...
php
{ "resource": "" }
q160
TranslatableDataObject.get_localized_class_fields
train
public static function get_localized_class_fields($class) { $fieldNames = null; $ancestry = array_reverse(ClassInfo::ancestry($class)); foreach ($ancestry as $className) { if (isset(self::$localizedFields[$className])) { if ($fieldNames === null) { ...
php
{ "resource": "" }
q161
TranslatableDataObject.localized_field
train
public static function localized_field($field, $locale = null) { if ($locale === null) { $locale = Translatable::get_current_locale(); } if ($locale == Translatable::default_locale()) { return $field; } return $field . TRANSLATABLE_COLUMN_SEPARATOR . $...
php
{ "resource": "" }
q162
TranslatableDataObject.set_locales
train
public static function set_locales($locales) { if (is_array($locales)) { $list = array(); foreach ($locales as $locale) { if (i18n::validate_locale($locale)) { $list[] = $locale; } } $list = array_unique($lis...
php
{ "resource": "" }
q163
TranslatableDataObject.collectDBFields
train
protected static function collectDBFields($class) { if (isset(self::$collectorCache[$class])) { return self::$collectorCache[$class]; } if (isset(self::$collectorLock[$class]) && self::$collectorLock[$class]) { return null; } self::$collectorLock[$cla...
php
{ "resource": "" }
q164
TranslatableDataObject.get_target_locales
train
protected static function get_target_locales() { // if locales are explicitly set, use these if (is_array(self::config()->locales)) { return (array)self::config()->locales; // otherwise check the allowed locales. If these have been set, use these } else if (is_array(T...
php
{ "resource": "" }
q165
TranslatableDataObject.get_arguments
train
protected static function get_arguments($class) { if (isset(self::$arguments[$class])) { return self::$arguments[$class]; } else { if ($staticFields = Config::inst()->get($class, 'translatable_fields', Config::FIRST_SET)) { if (is_array($staticFields) && !empt...
php
{ "resource": "" }
q166
TranslatableDataObject.setFieldForRelation
train
public function setFieldForRelation($fieldName, FormField $field) { if (self::isLocalizedRelation($fieldName)) { self::$localizedFields[$this->ownerBaseClass . '_has_one'][$fieldName]['FormField'] = $field; } }
php
{ "resource": "" }
q167
Locale.getDisplayCountries
train
public static function getDisplayCountries($locale) { if (!isset(self::$countries[$locale])) { self::$countries[$locale] = Intl::getRegionBundle()->getCountryNames($locale); } return self::$countries[$locale]; }
php
{ "resource": "" }
q168
Locale.getDisplayLanguages
train
public static function getDisplayLanguages($locale) { if (!isset(self::$languages[$locale])) { self::$languages[$locale] = Intl::getLanguageBundle()->getLanguageNames($locale); } return self::$languages[$locale]; }
php
{ "resource": "" }
q169
Locale.getDisplayLocales
train
public static function getDisplayLocales($locale) { if (!isset(self::$locales[$locale])) { self::$locales[$locale] = Intl::getLocaleBundle()->getLocaleNames($locale); } return self::$locales[$locale]; }
php
{ "resource": "" }
q170
Queue.exitWorkerManager
train
public function exitWorkerManager(int $sig, array $pid): void { $this->logger->debug('fork manager ['.$pid['pid'].'] exit with ['.$sig.']', [ 'category' => get_class($this), ]); pcntl_waitpid($pid['pid'], $status, WNOHANG | WUNTRACED); $this->cleanup(SIGTERM); }
php
{ "resource": "" }
q171
Queue.initWorkerManager
train
protected function initWorkerManager() { $pid = pcntl_fork(); $this->manager_pid = $pid; if (-1 === $pid) { throw new SpawnForkException('failed to spawn fork manager'); } if (!$pid) { $manager = $this->factory->buildManager(); $manager->...
php
{ "resource": "" }
q172
Queue.main
train
protected function main(): void { $this->logger->info('start job listener', [ 'category' => get_class($this), ]); $cursor_jobs = $this->jobs->getCursor([ '$or' => [ ['status' => JobInterface::STATUS_WAITING], ['status' => JobInterface:...
php
{ "resource": "" }
q173
WPUpdatePhp.does_it_meet_required_php_version
train
public function does_it_meet_required_php_version( $version = PHP_VERSION ) { if ( $this->version_passes_requirement( $this->minimum_version, $version ) ) { return true; } $this->load_version_notice( array( $this, 'minimum_admin_notice' ) ); return false; }
php
{ "resource": "" }
q174
WPUpdatePhp.does_it_meet_recommended_php_version
train
public function does_it_meet_recommended_php_version( $version = PHP_VERSION ) { if ( $this->version_passes_requirement( $this->recommended_version, $version ) ) { return true; } $this->load_version_notice( array( $this, 'recommended_admin_notice' ) ); return false; }
php
{ "resource": "" }
q175
WPUpdatePhp.get_admin_notice
train
public function get_admin_notice( $level = 'minimum' ) { if ( 'recommended' === $level ) { if ( ! empty( $this->plugin_name ) ) { return '<p>' . $this->plugin_name . ' recommends a PHP version higher than ' . $this->recommended_version . '. Read more information about <a href="http://www.wpupdatephp.com/update...
php
{ "resource": "" }
q176
Navigator.splAutoloader
train
private static function splAutoloader($class_name) { if('Treffynnon\\Navigator' === substr(ltrim($class_name, '\\'), 0, 20)) { $class_path = realpath(__DIR__ . '/..') . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $class_name); require_once $class_path . '.php'; } }
php
{ "resource": "" }
q177
Navigator.distanceFactory
train
public static function distanceFactory($lat1, $long1, $lat2, $long2) { $point1 = new L(new C($lat1), new C($long1)); $point2 = new L(new C($lat2), new C($long2)); return new D($point1, $point2); }
php
{ "resource": "" }
q178
Navigator.getDistance
train
public static function getDistance($lat1, $long1, $lat2, $long2) { return self::distanceFactory($lat1, $long1, $lat2, $long2)->get(); }
php
{ "resource": "" }
q179
WorkerManager.exitWorker
train
public function exitWorker(int $sig, array $pid): self { $this->logger->debug('worker ['.$pid['pid'].'] exit with ['.$sig.']', [ 'category' => get_class($this), ]); pcntl_waitpid($pid['pid'], $status, WNOHANG | WUNTRACED); foreach ($this->forks as $id => $process) { ...
php
{ "resource": "" }
q180
WorkerManager.spawnInitialWorkers
train
protected function spawnInitialWorkers() { $this->logger->debug('spawn initial ['.$this->min_children.'] workers', [ 'category' => get_class($this), ]); if (self::PM_DYNAMIC === $this->pm || self::PM_STATIC === $this->pm) { for ($i = $this->count(); $i < $this->min_c...
php
{ "resource": "" }
q181
WorkerManager.spawnMinimumWorkers
train
protected function spawnMinimumWorkers() { $this->logger->debug('verify that the minimum number ['.$this->min_children.'] of workers are running', [ 'category' => get_class($this), ]); for ($i = $this->count(); $i < $this->min_children; ++$i) { $this->spawnWorker(); ...
php
{ "resource": "" }
q182
Scheduler.getJob
train
public function getJob(ObjectId $id): Process { $result = $this->db->{$this->job_queue}->findOne([ '_id' => $id, ], [ 'typeMap' => self::TYPE_MAP, ]); if (null === $result) { throw new JobNotFoundException('job '.$id.' was not found'); } ...
php
{ "resource": "" }
q183
Scheduler.cancelJob
train
public function cancelJob(ObjectId $id): bool { $result = $this->updateJob($id, JobInterface::STATUS_CANCELED); if (1 !== $result->getMatchedCount()) { throw new JobNotFoundException('job '.$id.' was not found'); } $this->db->{$this->event_queue}->insertOne([ ...
php
{ "resource": "" }
q184
Scheduler.addJob
train
public function addJob(string $class, $data, array $options = []): Process { $document = $this->prepareInsert($class, $data, $options); $result = $this->db->{$this->job_queue}->insertOne($document); $this->logger->debug('queue job ['.$result->getInsertedId().'] added to ['.$class.']', [ ...
php
{ "resource": "" }
q185
Scheduler.addJobOnce
train
public function addJobOnce(string $class, $data, array $options = []): Process { $filter = [ 'class' => $class, '$or' => [ ['status' => JobInterface::STATUS_WAITING], ['status' => JobInterface::STATUS_POSTPONED], ['status' => JobInterfa...
php
{ "resource": "" }
q186
Scheduler.listen
train
public function listen(Closure $callback, array $query = []): self { if (0 === count($query)) { $query = [ 'timestamp' => ['$gte' => new UTCDateTime()], ]; } $cursor = $this->events->getCursor($query); while (true) { if (null === ...
php
{ "resource": "" }
q187
Scheduler.prepareInsert
train
protected function prepareInsert(string $class, $data, array &$options = []): array { $defaults = [ self::OPTION_AT => $this->default_at, self::OPTION_INTERVAL => $this->default_interval, self::OPTION_RETRY => $this->default_retry, self::OPTION_RETRY_INTERVAL ...
php
{ "resource": "" }
q188
TranslatableFormFieldTransformation.transformFormField
train
public function transformFormField(FormField $field) { $newfield = $field->performReadOnlyTransformation(); $fieldname = $field->getName(); if ($this->original->isLocalizedField($fieldname)) { $field->setName($this->original->getLocalizedFieldName($fieldname)); $valu...
php
{ "resource": "" }
q189
Tournament.start
train
public function start() { if ($this->state != 'pending') { throw new AlreadyStartedException('Tournament is already underway.'); } $response = Guzzle::post("tournaments/{$this->id}/start"); return $this->updateModel($response->tournament); }
php
{ "resource": "" }
q190
Tournament.finalize
train
public function finalize() { if ($this->state != 'awaiting_review') { throw new StillRunningException('Tournament is still running.'); } $response = Guzzle::post("tournaments/{$this->id}/finalize"); return $this->updateModel($response->tournament); }
php
{ "resource": "" }
q191
Tournament.update
train
public function update($params = []) { $response = Guzzle::put("tournaments/{$this->id}", $params); return $this->updateModel($response->tournament); }
php
{ "resource": "" }
q192
Distance.get
train
public function get(D\Calculator\CalculatorInterface $calculator = null, D\Converter\ConverterInterface $unit_converter = null) { if (is_null($calculator)) { $calculator = new D\Calculator\Vincenty; } $distance = $calculator->calculate($this->point1, $this->point2); if (!is...
php
{ "resource": "" }
q193
CustomInstaller.getPackageReplacementTokens
train
protected function getPackageReplacementTokens(PackageInterface $package) { $vars = array( '{$type}' => $package->getType(), ); $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { $pieces = explode('/', $prettyName); $...
php
{ "resource": "" }
q194
CustomInstaller.getPluginConfiguration
train
protected function getPluginConfiguration() { if (!isset($this->configuration)) { $extra = $this->composer->getPackage()->getExtra(); // We check if we need to support the legacy configuration. $legacy = false; if (isset($extra['custom-installer'])) { ...
php
{ "resource": "" }
q195
Term.getTaxonomyKey
train
public function getTaxonomyKey() { $called_class_segments = explode('\\', get_called_class()); $class_name = end($called_class_segments); return (is_null($this->taxonomy_key)) ? Str::machine(Str::camelToHuman($class_name), Base::SEPARATOR) : $this->taxonomy_key; }
php
{ "resource": "" }
q196
Term.getOptionID
train
public function getOptionID($term_id = null) { return join('_', array( $this->getTaxonomyKey(), ($term_id) ? $term_id : $this->get(self::ID) )); }
php
{ "resource": "" }
q197
Term.renderAdminColumn
train
public function renderAdminColumn($column_name, $term_id) { $this->load($term_id); parent::renderAdminColumn($column_name, $term_id); }
php
{ "resource": "" }
q198
Term.getEditPermalink
train
public function getEditPermalink($object_type = null) { // WordPress get_edit_term_link requires an object_type // but if this object was created by \Taco\Post::getTerms // then it will have an object_id, which also works if (is_null($object_type)) { $object_type = $this-...
php
{ "resource": "" }
q199
Term.getWhere
train
public static function getWhere($args = array()) { $instance = Term\Factory::create(get_called_class()); // Allow sorting both by core fields and custom fields // See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters $default_args = array( ...
php
{ "resource": "" }