_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q4500
Serializer.getRanges
train
protected function getRanges(array $values) { $i = 0; $cnt = count($values); $start = $values[0]; $end = $start; $ranges = []; while (++$i < $cnt) { if ($values[$i] === $end + 1) { ++$end; } else { $ranges[] = [$start, $end]; $start = $end = $values[$i]; } } ...
php
{ "resource": "" }
q4501
Serializer.serializeCharacterClass
train
protected function serializeCharacterClass(array $values) { $expr = '['; foreach ($this->getRanges($values) as list($start, $end)) { $expr .= $this->serializeCharacterClassUnit($start); if ($end > $start) { if ($end > $start + 1) { $expr .= '-'; } $expr .= $this->serializeCharacterC...
php
{ "resource": "" }
q4502
Serializer.serializeElement
train
protected function serializeElement($element) { return (is_array($element)) ? $this->serializeStrings($element) : $this->serializeLiteral($element); }
php
{ "resource": "" }
q4503
Serializer.serializeValue
train
protected function serializeValue($value, $escapeMethod) { return ($value < 0) ? $this->meta->getExpression($value) : $this->escaper->$escapeMethod($this->output->output($value)); }
php
{ "resource": "" }
q4504
StringTools.mb_ucfirst
train
public static function mb_ucfirst($str, $encoding = 'UTF-8') { $length = mb_strlen($str, $encoding); $firstChar = mb_substr($str, 0, 1, $encoding); $then = mb_substr($str, 1, $length - 1, $encoding); return mb_strtoupper($firstChar, $encoding) . $then; }
php
{ "resource": "" }
q4505
OmmuPlugins.getPlugin
train
public static function getPlugin($actived=null, $keypath=null, $array=true) { $criteria=new CDbCriteria; if($actived != null) $criteria->compare('actived', $actived); $criteria->addNotInCondition('orders', array(0)); if($actived == null || $actived == 0) $criteria->order = 'folder ASC'; else ...
php
{ "resource": "" }
q4506
MultiCurrencySum.times
train
public function times($multiplier) { return new self($this->getAugend()->times($multiplier), $this->getAddend()->times($multiplier)); }
php
{ "resource": "" }
q4507
Parser.get_dataset
train
private function get_dataset($index, $apiindex) { if (isset($this->data[$index])) { return $this->data[$index]; } $data = array(); foreach ($this->raw as $k => $v) { $pos = strpos($k, $apiindex); if ($pos !== 0) { continue; ...
php
{ "resource": "" }
q4508
Parser.get_lists
train
public function get_lists($timeperiod) { $lists = array(); foreach ($this->get_all_lists() as $list) { $object = $this->get_list($list); if ($object->get_time_period() == $timeperiod) { $lists[] = $list; } } return $lists; }
php
{ "resource": "" }
q4509
Parser.get_list
train
public function get_list($id) { foreach (array(self::INDEX_LISTS, self::INDEX_LIST) as $k) { $key = $this->baseurl . '/' . $k . $id; if (isset($this->raw[$key])) { return new ReadingList($this->api, $this->baseurl, $id, $this->raw[$key]); } } ...
php
{ "resource": "" }
q4510
Parser.get_category
train
public function get_category($url) { if (isset($this->raw[$url])) { return new Category($this->api, $this->baseurl, $url, $this->raw[$url]); } return null; }
php
{ "resource": "" }
q4511
PhpDoc.firstLine
train
public static function firstLine(string $comment): string { $docLines = \preg_split('~\R~u', $comment); if (isset($docLines[1])) { return \trim($docLines[1], "/\t *"); } return ''; }
php
{ "resource": "" }
q4512
PhpDoc.description
train
public static function description(string $comment): string { $comment = \str_replace("\r", '', \trim(\preg_replace('/^\s*\**( |\t)?/m', '', trim($comment, '/')))); if (\preg_match('/^\s*@\w+/m', $comment, $matches, \PREG_OFFSET_CAPTURE)) { $comment = \trim(\substr($comment, 0, $matches...
php
{ "resource": "" }
q4513
Response.sendHeader
train
public function sendHeader(string $name, ?string $value): void { if (headers_sent($file, $line)) { throw new HttpException(sprintf("Cannot use '%s()', headers already sent in %s:%s", __method__, $file, $line)); } // null means remove if ($value === null) ...
php
{ "resource": "" }
q4514
Response.sendCookie
train
public function sendCookie(string $name, ?string $value, int $expire = 0, string $path = '/', string $domain = '', bool $secure = false, bool $httpOnly = false): void { // check name if (!preg_match('~^[a-z0-9_\-\.]+$~i', $name)) { throw new HttpException("Invalid cookie name '{$...
php
{ "resource": "" }
q4515
Response.sendCookies
train
public function sendCookies(): void { foreach ((array) $this->cookies as $cookie) { $this->sendCookie($cookie['name'], $cookie['value'], $cookie['expire'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httpOnly']); } }
php
{ "resource": "" }
q4516
SqliteDb.alterTableMigrate
train
private function alterTableMigrate(array $alterDef, array $options = []) { $table = $alterDef['name']; $currentDef = $this->fetchTableDef($table); // Merge the table definitions if we aren't dropping stuff. if (!self::val(Db::OPTION_DROP, $options)) { $tableDef = $this->merg...
php
{ "resource": "" }
q4517
SqliteDb.fetchColumnDefsDb
train
protected function fetchColumnDefsDb(string $table) { $cdefs = $this->query('pragma table_info('.$this->prefixTable($table, false).')')->fetchAll(PDO::FETCH_ASSOC); if (empty($cdefs)) { return null; } $columns = []; $pk = []; foreach ($cdefs as $cdef) { ...
php
{ "resource": "" }
q4518
SqliteDb.fetchIndexesDb
train
protected function fetchIndexesDb($table = '') { $indexes = []; $indexInfos = $this->query('pragma index_list('.$this->prefixTable($table).')')->fetchAll(PDO::FETCH_ASSOC); foreach ($indexInfos as $row) { $indexName = $row['name']; if ($row['unique']) { $...
php
{ "resource": "" }
q4519
SqliteDb.getPKValue
train
private function getPKValue($table, array $row, $quick = false) { if ($quick && isset($row[$table.'ID'])) { return [$table.'ID' => $row[$table.'ID']]; } $tdef = $this->fetchTableDef($table); $cols = []; foreach ($tdef['columns'] as $name => $cdef) { if (e...
php
{ "resource": "" }
q4520
SqliteDb.fetchTableNamesDb
train
protected function fetchTableNamesDb() { // Get the table names. $tables = $this->get( new Identifier('sqlite_master'), [ 'type' => 'table', 'name' => [Db::OP_LIKE => $this->escapeLike($this->getPx()).'%'] ], [ ...
php
{ "resource": "" }
q4521
CsrfGuard.forbidden
train
public function forbidden(ServerRequestInterface $request, ResponseInterface $response) { $contentType = $this->determineContentType($request); switch ($contentType) { case 'application/json': $output = $this->renderJsonErrorMessage(); break; ...
php
{ "resource": "" }
q4522
MdsClient.request
train
public function request($url, $content = false, $customRequest = false) { $request_parts = explode('/', $url); $request = $request_parts[3]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if(strpos($url,'test'...
php
{ "resource": "" }
q4523
CoalesceSingleCharacterPrefix.filterEligibleKeys
train
protected function filterEligibleKeys(array $eligibleKeys) { $filteredKeys = []; foreach ($eligibleKeys as $k => $keys) { if (count($keys) > 1) { $filteredKeys[] = $keys; } } return $filteredKeys; }
php
{ "resource": "" }
q4524
CoalesceSingleCharacterPrefix.getEligibleKeys
train
protected function getEligibleKeys(array $strings) { $eligibleKeys = []; foreach ($strings as $k => $string) { if (!is_array($string[0]) && isset($string[1])) { $suffix = serialize(array_slice($string, 1)); $eligibleKeys[$suffix][] = $k; } } return $this->filterEligibleKeys($eligibleKeys); ...
php
{ "resource": "" }
q4525
ReadingList.get_time_period
train
public function get_time_period() { $period = $this->data[Parser::INDEX_LISTS_TIME_PERIOD][0]['value']; return substr($period, strpos($period, Parser::INDEX_TIME_PERIOD) + strlen(Parser::INDEX_TIME_PERIOD)); }
php
{ "resource": "" }
q4526
ReadingList.get_items
train
public function get_items() { if (!isset($this->data[Parser::INDEX_CHILDREN_SPEC])) { return array(); } $items = array(); foreach ($this->data[Parser::INDEX_CHILDREN_SPEC] as $k => $data) { $items[] = $this->api->get_item($data['value']); } ...
php
{ "resource": "" }
q4527
ReadingList.get_item_count
train
public function get_item_count() { $data = $this->data; $count = 0; if (isset($data[Parser::INDEX_LISTS_LIST_ITEMS])) { foreach ($data[Parser::INDEX_LISTS_LIST_ITEMS] as $things) { if (preg_match('#/items/#', $things['value'])) { $count++; ...
php
{ "resource": "" }
q4528
ReadingList.get_categories
train
public function get_categories() { $data = $this->data; if (empty($data[Parser::INDEX_PARENT_SPEC])) { return array(); } // Okay. We first grab all of our categories. $categories = array(); foreach ($data[Parser::INDEX_PARENT_SPEC] as $category) { ...
php
{ "resource": "" }
q4529
ReadingList.get_last_updated
train
public function get_last_updated($asstring = false) { $data = $this->data; $time = null; if (isset($data[Parser::INDEX_LISTS_LIST_UPDATED])) { $time = $data[Parser::INDEX_LISTS_LIST_UPDATED][0]['value']; $time = strtotime($time); } if ($asstring && $time...
php
{ "resource": "" }
q4530
EmailAwareTrait.emailFromArray
train
protected function emailFromArray(array $arr) { if (isset($arr['address'])) { $arr['email'] = $arr['address']; unset($arr['address']); } if (!isset($arr['email'])) { throw new InvalidArgumentException( 'The array must contain at least the ...
php
{ "resource": "" }
q4531
BannersPositionsController.add
train
public function add() { $position = $this->BannersPositions->newEntity(); if ($this->request->is('post')) { $position = $this->BannersPositions->patchEntity($position, $this->request->getData()); if ($this->BannersPositions->save($position)) { $this->Flash->...
php
{ "resource": "" }
q4532
BannersPositionsController.edit
train
public function edit($id = null) { $position = $this->BannersPositions->get($id); if ($this->request->is(['patch', 'post', 'put'])) { $position = $this->BannersPositions->patchEntity($position, $this->request->getData()); if ($this->BannersPositions->save($position)) { ...
php
{ "resource": "" }
q4533
BannersPositionsController.delete
train
public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $position = $this->BannersPositions->get($id); //Before deleting, it checks if the position has some banners if (!$position->banner_count) { $this->BannersPositions->deleteOrFail($posi...
php
{ "resource": "" }
q4534
Gettext.getTranslations
train
protected function getTranslations( $domain ) { if( !isset( $this->files[$domain] ) ) { if ( !isset( $this->sources[$domain] ) ) { $msg = sprintf( 'No translation directory for domain "%1$s" available', $domain ); throw new \Aimeos\MW\Translation\Exception( $msg ); } // Reverse locations so th...
php
{ "resource": "" }
q4535
MigrateScript.syncRelatedFields
train
protected function syncRelatedFields( IdProperty $newProp, PropertyField $newField, IdProperty $oldProp, PropertyField $oldField ) { unset($newProp, $oldProp, $oldField); $cli = $this->climate(); if (!$this->quiet()) { $cli->br(); $cli...
php
{ "resource": "" }
q4536
MigrateScript.targetModel
train
public function targetModel() { if (!isset($this->targetModel)) { $this->targetModel = $this->modelFactory()->get(Attachment::class); } return $this->targetModel; }
php
{ "resource": "" }
q4537
MigrateScript.pivotModel
train
public function pivotModel() { if (!isset($this->pivotModel)) { $this->pivotModel = $this->modelFactory()->get(Join::class); } return $this->pivotModel; }
php
{ "resource": "" }
q4538
Message.getCookie
train
public final function getCookie(string $name, ?string $valueDefault = null): ?string { return $this->cookies[$name] ?? $valueDefault; }
php
{ "resource": "" }
q4539
Message.removeCookie
train
public function removeCookie(string $name, bool $defer = false): self { if ($this->type == self::TYPE_REQUEST) { throw new HttpException('You cannot modify request cookies'); } unset($this->cookies[$name]); if (!$defer) { // remove instantly $this->sendCookie...
php
{ "resource": "" }
q4540
UsersController.loginWithCookie
train
protected function loginWithCookie() { $username = $this->request->getCookie('login.username'); $password = $this->request->getCookie('login.password'); //Checks if the cookies exist if (!$username || !$password) { return; } //Tries to login $thi...
php
{ "resource": "" }
q4541
UsersController.buildLogout
train
protected function buildLogout() { //Deletes some cookies and KCFinder session $cookies = $this->request->getCookieCollection()->remove('login')->remove('sidebar-lastmenu'); $this->request = $this->request->withCookieCollection($cookies); $this->request->getSession()->delete('KCFINDE...
php
{ "resource": "" }
q4542
UsersController.sendActivationMail
train
protected function sendActivationMail($user) { //Creates the token $token = $this->Token->create($user->email, ['type' => 'signup', 'user_id' => $user->id]); return $this->getMailer('MeCms.User') ->set('url', Router::url(['_name' => 'activation', $user->id, $token], true)) ...
php
{ "resource": "" }
q4543
OmmuWallComment.getGridColumn
train
public function getGridColumn($columns=null) { if($columns !== null) { foreach($columns as $val) { /* if(trim($val) == 'enabled') { $this->defaultColumns[] = array( 'name' => 'enabled', 'value' => '$data->enabled == 1? "Ya": "Tidak"', ); } */ $this->defaultColu...
php
{ "resource": "" }
q4544
App.go
train
public function go( $sEntryPoint, InputInterface $oInputInterface = null, OutputInterface $oOutputInterface = null, $bAutoExit = true ) { /* *--------------------------------------------------------------- * App Bootstrapper: preSystem *------------...
php
{ "resource": "" }
q4545
MailhideHelper.obfuscate
train
protected function obfuscate($mail) { return preg_replace_callback('/^([^@]+)(.*)$/', function ($matches) { $lenght = floor(strlen($matches[1]) / 2); $name = substr($matches[1], 0, $lenght) . str_repeat('*', $lenght); return $name . $matches[2]; }, $mail); }
php
{ "resource": "" }
q4546
MailhideHelper.link
train
public function link($title, $mail, array $options = []) { //Obfuscates the title, if the title is the email address $title = filter_var($title, FILTER_VALIDATE_EMAIL) ? $this->obfuscate($title) : $title; $mail = Security::encryptMail($mail); $url = Router::url(['_name' => 'mailhide...
php
{ "resource": "" }
q4547
Query.beginBracket
train
private function beginBracket($op) { $this->currentWhere[] = [$op => []]; $this->whereStack[] = &$this->currentWhere; end($this->currentWhere); $this->currentWhere = &$this->currentWhere[key($this->currentWhere)][$op]; return $this; }
php
{ "resource": "" }
q4548
Query.end
train
public function end() { // First unset the reference so it doesn't overwrite the original where clause. unset($this->currentWhere); // Move the pointer in the where stack back one level. if (empty($this->whereStack)) { trigger_error("Call to Query->end() without a correspond...
php
{ "resource": "" }
q4549
Query.addLike
train
public function addLike($column, $value) { $r = $this->addWhere($column, [Db::OP_LIKE => $value]); return $r; }
php
{ "resource": "" }
q4550
Query.addIn
train
public function addIn($column, array $values) { $r = $this->addWhere($column, [Db::OP_IN, $values]); return $r; }
php
{ "resource": "" }
q4551
Query.addWheres
train
public function addWheres(array $where) { foreach ($where as $column => $value) { $this->addWhere($column, $value); } return $this; }
php
{ "resource": "" }
q4552
Query.toArray
train
public function toArray() { $r = [ 'from' => $this->from, 'where' => $this->where, 'order' => $this->order, 'limit' => $this->limit, 'offset' => $this->offset ]; return $r; }
php
{ "resource": "" }
q4553
Query.exec
train
public function exec(Db $db) { $options = [ 'limit' => $this->limit, 'offset' => $this->offset ]; $r = $db->get($this->from, $this->where, $options); return $r; }
php
{ "resource": "" }
q4554
IsOwnedByTrait.isOwnedBy
train
public function isOwnedBy($recordId, $userId = null) { return (bool)$this->find() ->where(['id' => $recordId, 'user_id' => $userId]) ->first(); }
php
{ "resource": "" }
q4555
MenuHelper.posts
train
public function posts() { $links[] = [__d('me_cms', 'List posts'), [ 'controller' => 'Posts', 'action' => 'index', 'plugin' => 'MeCms', 'prefix' => ADMIN_PREFIX, ]]; $links[] = [__d('me_cms', 'Add post'), [ 'controller' => 'Posts', ...
php
{ "resource": "" }
q4556
MenuHelper.pages
train
public function pages() { $links[] = [__d('me_cms', 'List pages'), [ 'controller' => 'Pages', 'action' => 'index', 'plugin' => 'MeCms', 'prefix' => ADMIN_PREFIX, ]]; //Only admins and managers can access these actions if ($this->Auth->...
php
{ "resource": "" }
q4557
MenuHelper.photos
train
public function photos() { $links[] = [__d('me_cms', 'List photos'), [ 'controller' => 'Photos', 'action' => 'index', 'plugin' => 'MeCms', 'prefix' => ADMIN_PREFIX, ]]; $links[] = [__d('me_cms', 'Upload photos'), [ 'controller' => '...
php
{ "resource": "" }
q4558
MenuHelper.banners
train
public function banners() { //Only admins and managers can access these controllers if (!$this->Auth->isGroup(['admin', 'manager'])) { return; } $links[] = [__d('me_cms', 'List banners'), [ 'controller' => 'Banners', 'action' => 'index', ...
php
{ "resource": "" }
q4559
MenuHelper.users
train
public function users() { //Only admins and managers can access this controller if (!$this->Auth->isGroup(['admin', 'manager'])) { return; } $links[] = [__d('me_cms', 'List users'), [ 'controller' => 'Users', 'action' => 'index', 'plug...
php
{ "resource": "" }
q4560
MenuHelper.backups
train
public function backups() { //Only admins can access this controller if (!$this->Auth->isGroup('admin')) { return; } $links[] = [__d('me_cms', 'List backups'), [ 'controller' => 'Backups', 'action' => 'index', 'plugin' => 'MeCms', ...
php
{ "resource": "" }
q4561
MenuHelper.systems
train
public function systems() { //Only admins and managers can access this controller if (!$this->Auth->isGroup(['admin', 'manager'])) { return; } $links[] = [__d('me_cms', 'Temporary files'), [ 'controller' => 'Systems', 'action' => 'tmpViewer', ...
php
{ "resource": "" }
q4562
ControllerTrait.dispatch
train
protected function dispatch($request, $response) { $this->setRequest($request); $this->setResponse($response); if (!$this->responder) { $this->responder = Respond::getResponder(); } return $this->_execInternalMethods(); }
php
{ "resource": "" }
q4563
DoctrineSpool.sendEmails
train
protected function sendEmails(Swift_Transport $transport, &$failedRecipients, array $emails) { $count = 0; $time = time(); $emails = $this->prepareEmails($emails); $skip = false; foreach ($emails as $email) { if ($skip) { $email->setStatus(SpoolEm...
php
{ "resource": "" }
q4564
DoctrineSpool.prepareEmails
train
protected function prepareEmails(array $emails) { foreach ($emails as $email) { $email->setStatus(SpoolEmailStatus::STATUS_SENDING); $email->setSentAt(null); $this->om->persist($email); } $this->om->flush(); reset($emails); return $emails...
php
{ "resource": "" }
q4565
DoctrineSpool.sendEmail
train
protected function sendEmail(Swift_Transport $transport, SpoolEmailInterface $email, &$failedRecipients) { $count = 0; try { if ($transport->send($email->getMessage(), $failedRecipients)) { $email->setStatus(SpoolEmailStatus::STATUS_SUCCESS); ++$count; ...
php
{ "resource": "" }
q4566
DoctrineSpool.flushEmail
train
protected function flushEmail(SpoolEmailInterface $email): void { $email->setSentAt(new \DateTime()); $this->om->persist($email); $this->om->flush(); if (SpoolEmailStatus::STATUS_SUCCESS === $email->getStatus()) { $this->om->remove($email); $this->om->flush()...
php
{ "resource": "" }
q4567
AppTable.beforeSave
train
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) { if (empty($entity->created)) { $entity->created = new Time; } elseif (!empty($entity->created) && !$entity->created instanceof Time) { $entity->created = new Time($entity->created); ...
php
{ "resource": "" }
q4568
AppTable.findRandom
train
public function findRandom(Query $query, array $options) { $query->order('rand()'); if (!$query->clause('limit')) { $query->limit(1); } return $query; }
php
{ "resource": "" }
q4569
AppTable.getCacheName
train
public function getCacheName($associations = false) { $values = $this->cache ?: null; if ($associations) { $values = [$values]; foreach ($this->associations()->getIterator() as $association) { if (method_exists($association->getTarget(), 'getCacheName') && $a...
php
{ "resource": "" }
q4570
AppTable.getList
train
public function getList() { return $this->find('list') ->order([$this->getDisplayField() => 'ASC']) ->cache(sprintf('%s_list', $this->getTable()), $this->getCacheName()); }
php
{ "resource": "" }
q4571
DatasetTrait.setPage
train
public function setPage(int $page) { if ($page < 0) { throw new \InvalidArgumentException("Invalid page '$page.'", 500); } $this->setOffset(($page - 1) * $this->getLimit()); return $this; }
php
{ "resource": "" }
q4572
DatasetTrait.setOffset
train
public function setOffset($offset) { if (!is_numeric($offset) || $offset < 0) { throw new \InvalidArgumentException("Invalid offset '$offset.'", 500); } $this->offset = (int)$offset; return $this; }
php
{ "resource": "" }
q4573
BaseMaker.getResource
train
protected function getResource(string $sFile, array $aFields): string { if (empty(static::RESOURCE_PATH)) { throw new NailsException('RESOURCE_PATH is not defined'); } $sResource = require static::RESOURCE_PATH . $sFile; foreach ($aFields as $sField => $sValue) { ...
php
{ "resource": "" }
q4574
BaseMaker.createPath
train
protected function createPath(string $sPath): BaseMaker { if (!is_dir($sPath)) { if (!@mkdir($sPath, self::FILE_PERMISSION, true)) { throw new DoesNotExistException('Path "' . $sPath . '" does not exist and could not be created'); } } if (!is_writable...
php
{ "resource": "" }
q4575
BaseMaker.getArguments
train
protected function getArguments(): array { Factory::helper('string'); $aArguments = []; if (!empty($this->aArguments)) { foreach ($this->aArguments as $aArgument) { $aArguments[] = (object) [ 'name' => getFromArray('name', $aArgument), ...
php
{ "resource": "" }
q4576
BaseMaker.validateServiceFile
train
protected function validateServiceFile(string $sToken = null): BaseMaker { if (empty($sToken) && empty(static::SERVICE_TOKEN)) { throw new ConsoleException( 'SERVICE_TOKEN is not set' ); } elseif (empty($sToken)) { $sToken = static::SERVICE_TOKEN; ...
php
{ "resource": "" }
q4577
BaseMaker.writeServiceFile
train
protected function writeServiceFile(array $aServiceDefinitions = []): BaseMaker { // Create a temporary file $fTempHandle = fopen(static::SERVICE_TEMP_PATH, 'w+'); rewind($this->fServicesHandle); $iLocation = 0; while (($sLine = fgets($this->fServicesHandle)) !== false) { ...
php
{ "resource": "" }
q4578
CoalesceOptionalStrings.buildCoalescedStrings
train
protected function buildCoalescedStrings(array $prefixStrings, array $suffix) { $strings = $this->runPass($this->buildPrefix($prefixStrings)); if (count($strings) === 1 && $strings[0][0][0] === []) { // If the prefix has been remerged into a list of strings which contains only one string // of which the fi...
php
{ "resource": "" }
q4579
CoalesceOptionalStrings.buildPrefix
train
protected function buildPrefix(array $strings) { $prefix = []; foreach ($strings as $string) { // Remove the last element (suffix) of each string before adding it array_pop($string); $prefix[] = $string; } return $prefix; }
php
{ "resource": "" }
q4580
CoalesceOptionalStrings.buildSuffix
train
protected function buildSuffix(array $strings) { $suffix = [[]]; foreach ($strings as $string) { if ($this->isCharacterClassString($string)) { foreach ($string[0] as $element) { $suffix[] = $element; } } else { $suffix[] = $string; } } return $suffix; }
php
{ "resource": "" }
q4581
CoalesceOptionalStrings.getPrefixGroups
train
protected function getPrefixGroups(array $strings) { $groups = []; foreach ($strings as $k => $string) { if ($this->hasOptionalSuffix($string)) { $groups[serialize(end($string))][$k] = $string; } } return $groups; }
php
{ "resource": "" }
q4582
URLScheme.match
train
public function match($url) { if (!$this->pattern) { $this->pattern = self::buildPatternFromScheme($this); } return (bool) preg_match($this->pattern, $url); }
php
{ "resource": "" }
q4583
URLScheme.buildPatternFromScheme
train
static protected function buildPatternFromScheme(URLScheme $scheme) { // generate a unique random string $uniq = md5(mt_rand()); // replace the wildcard sub-domain if exists $scheme = str_replace( '://'.self::WILDCARD_CHARACTER.'.', '://'.$uniq, $scheme->__tostring() ); // replace the wildcar...
php
{ "resource": "" }
q4584
ExperiencesTable.toLevel
train
public function toLevel(Experiences $experiences): Level { $woundsBonus = $this->toWoundsBonus($experiences); return new Level($this->bonusToLevelValue($woundsBonus), $this); }
php
{ "resource": "" }
q4585
ExperiencesTable.toTotalLevel
train
public function toTotalLevel(Experiences $experiences): Level { $currentExperiences = 0; $usedExperiences = 0; $maxLevelValue = 0; while ($usedExperiences + $currentExperiences <= $experiences->getValue()) { $level = $this->toLevel(new Experiences($currentExperiences, $th...
php
{ "resource": "" }
q4586
ExperiencesTable.toTotalExperiences
train
public function toTotalExperiences(Level $level): Experiences { $experiencesSum = 0; for ($levelValueToCast = $level->getValue(); $levelValueToCast > 0; $levelValueToCast--) { if ($levelValueToCast > 1) { // main profession has first level for free $currentLevel = new Lev...
php
{ "resource": "" }
q4587
Db.driverClass
train
public static function driverClass($driver) { if ($driver instanceof PDO) { $name = $driver->getAttribute(PDO::ATTR_DRIVER_NAME); } else { $name = (string)$driver; } $name = strtolower($name); return isset(self::$drivers[$name]) ? self::$drivers[$name] : ...
php
{ "resource": "" }
q4588
Db.dropTable
train
final public function dropTable(string $table, array $options = []) { $options += [Db::OPTION_IGNORE => false]; $this->dropTableDb($table, $options); $tableKey = strtolower($table); unset($this->tables[$tableKey], $this->tableNames[$tableKey]); }
php
{ "resource": "" }
q4589
Db.fetchTableNames
train
final public function fetchTableNames() { if ($this->tableNames !== null) { return array_values($this->tableNames); } $names = $this->fetchTableNamesDb(); $this->tableNames = []; foreach ($names as $name) { $name = $this->stripPrefix($name); ...
php
{ "resource": "" }
q4590
Db.fetchTableDef
train
final public function fetchTableDef(string $table) { $tableKey = strtolower($table); // First check the table cache. if (isset($this->tables[$tableKey])) { $tableDef = $this->tables[$tableKey]; if (isset($tableDef['columns'], $tableDef['indexes'])) { ret...
php
{ "resource": "" }
q4591
Db.fetchColumnDefs
train
final public function fetchColumnDefs(string $table) { $tableKey = strtolower($table); if (!empty($this->tables[$tableKey]['columns'])) { $this->tables[$tableKey]['columns']; } elseif ($this->tableNames !== null && !isset($this->tableNames[$tableKey])) { return null; ...
php
{ "resource": "" }
q4592
Db.typeDef
train
public static function typeDef(string $type) { // Check for the unsigned signifier. $unsigned = null; if ($type[0] === 'u') { $unsigned = true; $type = substr($type, 1); } elseif (preg_match('`(.+)\s+unsigned`i', $type, $m)) { $unsigned = true; ...
php
{ "resource": "" }
q4593
Db.dbType
train
protected static function dbType(array $typeDef) { $dbtype = $typeDef['dbtype']; if (!empty($typeDef['maxLength'])) { $dbtype .= "({$typeDef['maxLength']})"; } elseif (!empty($typeDef['unsigned'])) { $dbtype = 'u'.$dbtype; } elseif (!empty($typeDef['precision']))...
php
{ "resource": "" }
q4594
Db.findPrimaryKeyIndex
train
protected function findPrimaryKeyIndex(array $indexes) { foreach ($indexes as $index) { if ($index['type'] === Db::INDEX_PK) { return $index; } } return null; }
php
{ "resource": "" }
q4595
Db.fixIndexes
train
private function fixIndexes(string $tableName, array &$tableDef, $curTableDef = null) { $tableDef += ['indexes' => []]; // Loop through the columns and add the primary key index. $primaryColumns = []; foreach ($tableDef['columns'] as $cname => $cdef) { if (!empty($cdef['prim...
php
{ "resource": "" }
q4596
Db.indexCompare
train
private function indexCompare(array $a, array $b): int { if ($a['columns'] > $b['columns']) { return 1; } elseif ($a['columns'] < $b['columns']) { return -1; } return strcmp( isset($a['type']) ? $a['type'] : '', isset($b['type']) ? $b['typ...
php
{ "resource": "" }
q4597
Db.getOne
train
final public function getOne($table, array $where, array $options = []) { $rows = $this->get($table, $where, $options); $row = $rows->fetch(); return $row === false ? null : $row; }
php
{ "resource": "" }
q4598
Db.load
train
public function load(string $table, $rows, array $options = []) { foreach ($rows as $row) { $this->insert($table, $row, $options); } }
php
{ "resource": "" }
q4599
Db.buildIndexName
train
protected function buildIndexName(string $tableName, array $indexDef): string { $indexDef += ['type' => Db::INDEX_IX, 'suffix' => '']; $type = $indexDef['type']; if ($type === Db::INDEX_PK) { return 'primary'; } $px = self::val($type, [Db::INDEX_IX => 'ix_', Db::IND...
php
{ "resource": "" }