_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q17100
FlexSampleRestaurant.get
train
public static function get() { return FlexMessageBuilder::builder() ->setAltText('Restaurant') ->setContents( BubbleContainerBuilder::builder() ->setHero(self::createHeroBlock())
php
{ "resource": "" }
q17101
ImagemapMessageBuilder.buildMessage
train
public function buildMessage() { if (!empty($this->message)) { return $this->message; } $actions = []; foreach ($this->imagemapActionBuilders as $builder) { $actions[] = $builder->buildImagemapAction(); } $imagemapMessage = [ 'typ...
php
{ "resource": "" }
q17102
TemplateMessageBuilder.buildMessage
train
public function buildMessage() { if (!empty($this->message)) { return $this->message; } $templateMessage = [ 'type' => MessageType::TEMPLATE, 'altText' => $this->altText, 'template' => $this->templateBuilder->buildTemplate(), ]; ...
php
{ "resource": "" }
q17103
FlexMessageBuilder.buildMessage
train
public function buildMessage() { if (isset($this->message)) { return $this->message; } $this->message = [ BuildUtil::removeNullElements([ 'type' => MessageType::FLEX, 'altText' => $this->altText,
php
{ "resource": "" }
q17104
ButtonComponentBuilder.build
train
public function build() { if (isset($this->component)) { return $this->component; } $this->component = BuildUtil::removeNullElements([ 'type' => ComponentType::BUTTON, 'action' => $this->actionBuilder->buildTemplateAction(), 'flex' => $this->f...
php
{ "resource": "" }
q17105
VideoMessageBuilder.buildMessage
train
public function buildMessage() { if (!empty($this->message)) { return $this->message; } $video = [ 'type' => MessageType::VIDEO, 'originalContentUrl' => $this->originalContentUrl, 'previewImageUrl' => $this->previewImageUrl, ]; ...
php
{ "resource": "" }
q17106
PostbackTemplateActionBuilder.buildTemplateAction
train
public function buildTemplateAction() { $action = [ 'type' => ActionType::POSTBACK, 'label' => $this->label, 'data' => $this->data, ]; if (isset($this->displayText)) {
php
{ "resource": "" }
q17107
CarouselContainerBuilder.build
train
public function build() { if (!empty($this->container)) { return $this->container; } $contents = array_map(function ($containerBuilder) { return $containerBuilder->build(); }, $this->containerBuilders); $this->container =
php
{ "resource": "" }
q17108
Subscription.create
train
public static function create(array $associativeArray): Subscription { if (array_key_exists('keys', $associativeArray) && is_array($associativeArray['keys'])) { return new self( $associativeArray['endpoint'], $associativeArray['keys']['p256dh'] ?? null, ...
php
{ "resource": "" }
q17109
VAPID.getVapidHeaders
train
public static function getVapidHeaders(string $audience, string $subject, string $publicKey, string $privateKey, string $contentEncoding, ?int $expiration = null) { $expirationLimit = time() + 43200; // equal margin of error between 0 and 24h if (null === $expiration || $expiration > $expirationLimi...
php
{ "resource": "" }
q17110
VAPID.createVapidKeys
train
public static function createVapidKeys(): array { $curve = NistCurve::curve256(); $privateKey = $curve->createPrivateKey(); $publicKey = $curve->createPublicKey($privateKey); $binaryPublicKey = hex2bin(Utils::serializePublicKey($publicKey)); if (!$binaryPublicKey) { ...
php
{ "resource": "" }
q17111
WebPush.flush
train
public function flush(?int $batchSize = null): \Generator { if (null === $this->notifications || empty($this->notifications)) { yield from []; return; } if (null === $batchSize) { $batchSize = $this->defaultOptions['batchSize']; } $batche...
php
{ "resource": "" }
q17112
CrudModelCommand.createRelationshipFunction
train
protected function createRelationshipFunction(&$stub, $relationshipName, $relationshipType, $argsString) { $tabIndent = ' '; $code = "public function " . $relationshipName . "()\n" . $tabIndent . "{\n" . $tabIndent . $tabIndent . "return \$this->" . $relationshipType . "(" . $argsStri...
php
{ "resource": "" }
q17113
CrudApiCommand.processJSONForeignKeys
train
protected function processJSONForeignKeys($file) { $json = File::get($file); $fields = json_decode($json); if (! property_exists($fields, 'foreign_keys')) { return ''; } $foreignKeysString = ''; foreach ($fields->foreign_keys as $foreign_key) { ...
php
{ "resource": "" }
q17114
CrudApiCommand.processJSONRelationships
train
protected function processJSONRelationships($file) { $json = File::get($file); $fields = json_decode($json); if (!property_exists($fields, 'relationships')) { return ''; } $relationsString = ''; foreach ($fields->relationships as $relation) {
php
{ "resource": "" }
q17115
CrudApiCommand.processJSONValidations
train
protected function processJSONValidations($file) { $json = File::get($file); $fields = json_decode($json); if (!property_exists($fields, 'validations')) { return ''; } $validationsString = ''; foreach ($fields->validations as $validation) {
php
{ "resource": "" }
q17116
CrudViewCommand.templateStubs
train
protected function templateStubs($path) { $dynamicViewTemplate = config('crudgenerator.dynamic_view_template') ? config('crudgenerator.dynamic_view_template') : $this->defaultTemplating(); foreach ($dynamicViewTemplate as $name => $vars) {
php
{ "resource": "" }
q17117
CrudViewCommand.templateVars
train
protected function templateVars($file, $vars) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; foreach ($vars as $var) { $replace = $start . $var . $end; if (in_array($var,
php
{ "resource": "" }
q17118
CrudViewCommand.userDefinedVars
train
protected function userDefinedVars($file) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; if ($this->customData !== null) { $customVars = explode(';', $this->customData); foreach ($customVars as $rawVar) {
php
{ "resource": "" }
q17119
CrudViewCommand.createPasswordField
train
protected function createPasswordField($item) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; $required = $item['required'] ? 'required' : ''; $markup = File::get($this->viewDirectoryPath . 'form-fields/password-field.blade.stub');
php
{ "resource": "" }
q17120
CrudControllerCommand.replaceModelNamespaceSegments
train
protected function replaceModelNamespaceSegments(&$stub, $modelNamespace) { $modelSegments = explode('\\', $modelNamespace); foreach ($modelSegments as $key => $segment) { $stub
php
{ "resource": "" }
q17121
CrudLangCommand.templateVars
train
private function templateVars($newLangFile) { $messages = []; foreach ($this->formFields as $field) { $index = $field['name']; $text = ucwords(strtolower(str_replace('_', ' ', $index))); $messages[] = "'$index' => '$text'";
php
{ "resource": "" }
q17122
Table.getItems
train
protected function getItems(array $items) { $result = array(); foreach($items as $item) {
php
{ "resource": "" }
q17123
ForeignKeyGenerator.generate
train
public function generate($table, $schema, $ignoreForeignKeyNames) { $this->table = $table; $fields = []; $foreignKeys = $schema->listTableForeignKeys($table); if ( empty( $foreignKeys ) ) return array(); foreach ( $foreignKeys as $foreignKey ) { $fields[] = [ 'name' => $this->getName($foreignKey, $...
php
{ "resource": "" }
q17124
MigrateGenerateCommand.askNumeric
train
protected function askNumeric( $question, $default = null ) { $ask = 'Your answer needs to be a numeric value'; if ( ! is_null( $default ) ) { $question .= ' [Default: '. $default .'] '; $ask .= ' or blank for default'; } $answer = $this->ask( $question ); while ( ! is_numeric( $answer ) and ! ( $ans...
php
{ "resource": "" }
q17125
MigrateGenerateCommand.generateTablesAndIndices
train
protected function generateTablesAndIndices( array $tables ) { $this->method = 'create'; foreach ( $tables as $table ) {
php
{ "resource": "" }
q17126
MigrateGenerateCommand.generateForeignKeys
train
protected function generateForeignKeys( array $tables ) { $this->method = 'table'; foreach ( $tables as $table ) { $this->table = $table; $this->migrationName = 'add_foreign_keys_to_'. $this->table
php
{ "resource": "" }
q17127
MigrateGenerateCommand.generate
train
protected function generate() { if ( $this->fields ) { parent::fire(); if ( $this->log ) { $file = $this->datePrefix
php
{ "resource": "" }
q17128
MigrateGenerateCommand.getFileGenerationPath
train
protected function getFileGenerationPath() { $path = $this->getPathByOptionOrConfig( 'path', 'migration_target_path' ); $migrationName = str_replace('/', '_', $this->migrationName);
php
{ "resource": "" }
q17129
MigrateGenerateCommand.removeExcludedTables
train
protected function removeExcludedTables( array $tables ) { $excludes = $this->getExcludedTables();
php
{ "resource": "" }
q17130
MigrateGenerateCommand.getExcludedTables
train
protected function getExcludedTables() { $excludes = ['migrations']; $ignore = $this->option('ignore'); if ( ! empty($ignore)) {
php
{ "resource": "" }
q17131
FieldGenerator.getEnum
train
protected function getEnum($table) { try { $result = DB::table('information_schema.columns') ->where('table_schema', $this->database)
php
{ "resource": "" }
q17132
Driver.run
train
public function run() { $this->running = true; try { while ($this->running) { if ($this->isEmpty()) { return;
php
{ "resource": "" }
q17133
Driver.error
train
protected function error(\Throwable $exception) { if ($this->errorHandler === null) { throw $exception;
php
{ "resource": "" }
q17134
Driver.getInfo
train
public function getInfo(): array { $watchers = [ "referenced" => 0, "unreferenced" => 0, ]; $defer = $delay = $repeat = $onReadable = $onWritable = $onSignal = [ "enabled" => 0, "disabled" => 0, ]; foreach ($this->watchers as ...
php
{ "resource": "" }
q17135
Producer.emit
train
private function emit($value): Promise { if ($this->complete) { throw new \Error("Iterators cannot emit values after calling complete"); } if ($value instanceof ReactPromise) { $value = Promise\adapt($value); } if ($value instanceof Promise) { ...
php
{ "resource": "" }
q17136
Producer.complete
train
private function complete() { if ($this->complete) { $message = "Iterator has already been completed"; if (isset($this->resolutionTrace)) { $trace = formatStacktrace($this->resolutionTrace); $message .= ". Previous completion trace:\n\n{$trace}\n\n"; ...
php
{ "resource": "" }
q17137
Loop.run
train
public static function run(callable $callback = null) { if ($callback) {
php
{ "resource": "" }
q17138
DriverFactory.create
train
public function create(): Driver { if ($driver = $this->createDriverFromEnv()) { return $driver; } if (UvDriver::isSupported()) { return new UvDriver; } if (EvDriver::isSupported()) {
php
{ "resource": "" }
q17139
InstallCommand.registerAuditingServiceProvider
train
protected function registerAuditingServiceProvider() { $namespace = str_replace_last('\\', '', $this->getAppNamespace()); $appConfig = file_get_contents(config_path('app.php')); if (Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) { return; ...
php
{ "resource": "" }
q17140
Audit.getFormattedValue
train
protected function getFormattedValue(Model $model, string $key, $value) { // Apply defined get mutator if ($model->hasGetMutator($key)) { return $model->mutateAttribute($key, $value); } // Cast to native PHP type if ($model->hasCast($key)) {
php
{ "resource": "" }
q17141
Audit.decodeAttributeValue
train
protected function decodeAttributeValue(Contracts\Auditable $auditable, string $attribute, $value) { $attributeModifiers = $auditable->getAttributeModifiers(); if (!array_key_exists($attribute, $attributeModifiers)) { return $value; } $attributeDecoder =
php
{ "resource": "" }
q17142
Auditable.resolveAuditExclusions
train
protected function resolveAuditExclusions() { $this->excludedAttributes = $this->getAuditExclude(); // When in strict mode, hidden and non visible attributes are excluded if ($this->getAuditStrict()) { // Hidden attributes $this->excludedAttributes = array_merge($thi...
php
{ "resource": "" }
q17143
Auditable.modifyAttributeValue
train
protected function modifyAttributeValue(string $attribute, $value) { $attributeModifiers = $this->getAttributeModifiers(); if (!array_key_exists($attribute, $attributeModifiers)) { return $value; } $attributeModifier = $attributeModifiers[$attribute]; if (is_su...
php
{ "resource": "" }
q17144
Auditable.resolveUser
train
protected function resolveUser() { $userResolver = Config::get('audit.resolver.user'); if (is_subclass_of($userResolver, UserResolver::class))
php
{ "resource": "" }
q17145
Auditable.resolveUrl
train
protected function resolveUrl(): string { $urlResolver = Config::get('audit.resolver.url'); if (is_subclass_of($urlResolver, UrlResolver::class))
php
{ "resource": "" }
q17146
Auditable.resolveIpAddress
train
protected function resolveIpAddress(): string { $ipAddressResolver = Config::get('audit.resolver.ip_address'); if (is_subclass_of($ipAddressResolver, IpAddressResolver::class))
php
{ "resource": "" }
q17147
Auditable.resolveUserAgent
train
protected function resolveUserAgent() { $userAgentResolver = Config::get('audit.resolver.user_agent'); if (is_subclass_of($userAgentResolver, UserAgentResolver::class))
php
{ "resource": "" }
q17148
Auditable.resolveAttributeGetter
train
protected function resolveAttributeGetter($event) { foreach ($this->getAuditEvents() as $key => $value) { $auditableEvent = is_int($key) ? $value : $key; $auditableEventRegex = sprintf('/%s/', preg_replace('/\*+/', '.*', $auditableEvent));
php
{ "resource": "" }
q17149
Auditable.isAuditingEnabled
train
public static function isAuditingEnabled(): bool { if (App::runningInConsole()) { return Config::get('audit.console', false);
php
{ "resource": "" }
q17150
Auditor.fireAuditingEvent
train
protected function fireAuditingEvent(Auditable $model, AuditDriver $driver): bool { return $this->app->make('events')->until(
php
{ "resource": "" }
q17151
IsAbility.bootIsAbility
train
public static function bootIsAbility() { BaseTenantScope::register(static::class); static::creating(function ($ability) {
php
{ "resource": "" }
q17152
IsAbility.getConstraints
train
public function getConstraints() { if (empty($this->options['constraints'])) { return new Group(); }
php
{ "resource": "" }
q17153
IsAbility.setConstraints
train
public function setConstraints(Constrainer $constrainer) { $this->options =
php
{ "resource": "" }
q17154
IsAbility.createForModel
train
public static function createForModel($model, $attributes) { $model = static::makeForModel($model,
php
{ "resource": "" }
q17155
IsAbility.makeForModel
train
public static function makeForModel($model, $attributes) { if (is_string($attributes)) { $attributes = ['name' => $attributes]; } if ($model === '*') { return (new static)->forceFill($attributes + [ 'entity_type' => '*', ]); } ...
php
{ "resource": "" }
q17156
IsAbility.getIdentifierAttribute
train
final public function getIdentifierAttribute() { $slug = $this->attributes['name']; if ($this->attributes['entity_type']) { $slug .= '-'.$this->attributes['entity_type']; } if ($this->attributes['entity_id']) { $slug .= '-'.$this->attributes['entity_id'];
php
{ "resource": "" }
q17157
IsAbility.scopeByName
train
public function scopeByName($query, $name, $strict = false) { $names = (array) $name;
php
{ "resource": "" }
q17158
RemovesRoles.from
train
public function from($authority) { if (! ($roleIds = $this->getRoleIds())) { return; } $authorities =
php
{ "resource": "" }
q17159
RemovesRoles.getRoleIds
train
protected function getRoleIds() { list($models, $names) = Helpers::partition($this->roles, function ($role) { return $role instanceof Model; }); $ids = $models->map(function ($model) { return $model->getKey();
php
{ "resource": "" }
q17160
RemovesRoles.getRoleIdsFromNames
train
protected function getRoleIdsFromNames(array $names) { $key = Models::role()->getKeyName();
php
{ "resource": "" }
q17161
RemovesRoles.retractRoles
train
protected function retractRoles($roleIds, $authorityClass, $authorityIds) { $query = $this->newPivotTableQuery(); $morphType = (new $authorityClass)->getMorphClass(); foreach ($roleIds as $roleId) { foreach ($authorityIds as $authorityId) {
php
{ "resource": "" }
q17162
RemovesRoles.getDetachQueryConstraint
train
protected function getDetachQueryConstraint($roleId, $authorityId, $morphType) { return function ($query) use ($roleId, $authorityId, $morphType) { $query->where(Models::scope()->getAttachAttributes() + [ 'role_id' => $roleId,
php
{ "resource": "" }
q17163
ChecksRoles.a
train
public function a($role) { $roles = func_get_args();
php
{ "resource": "" }
q17164
ChecksRoles.notA
train
public function notA($role) { $roles = func_get_args();
php
{ "resource": "" }
q17165
ChecksRoles.an
train
public function an($role) { $roles = func_get_args();
php
{ "resource": "" }
q17166
ChecksRoles.notAn
train
public function notAn($role) { $roles = func_get_args();
php
{ "resource": "" }
q17167
ChecksRoles.all
train
public function all($role) { $roles = func_get_args();
php
{ "resource": "" }
q17168
AssociatesAbilities.getAuthority
train
protected function getAuthority() { if (is_null($this->authority)) { return null; } if ($this->authority instanceof Model) {
php
{ "resource": "" }
q17169
AssociatesAbilities.getAssociatedAbilityIds
train
protected function getAssociatedAbilityIds($authority, array $abilityIds, $forbidden) { if (is_null($authority)) { return $this->getAbilityIdsAssociatedWithEveryone($abilityIds, $forbidden); } $relation = $authority->abilities(); $table = Models::table('abilities'); ...
php
{ "resource": "" }
q17170
AssociatesAbilities.getAbilityIdsAssociatedWithEveryone
train
protected function getAbilityIdsAssociatedWithEveryone(array $abilityIds, $forbidden) { $query = Models::query('permissions') ->whereNull('entity_id') ->whereIn('ability_id', $abilityIds) ->where('forbidden', '=', $forbidden);
php
{ "resource": "" }
q17171
HasRoles.roles
train
public function roles() { $relation = $this->morphToMany( Models::classname(Role::class),
php
{ "resource": "" }
q17172
HasRoles.isAn
train
public function isAn($role) { $roles = func_get_args(); $clipboard = $this->getClipboardInstance();
php
{ "resource": "" }
q17173
HasRoles.isNotAn
train
public function isNotAn($role) { $roles = func_get_args();
php
{ "resource": "" }
q17174
HasRoles.isAll
train
public function isAll($role) { $roles = func_get_args(); $clipboard = $this->getClipboardInstance();
php
{ "resource": "" }
q17175
Constraint.where
train
public static function where($column, $operator, $value = null) { list($operator, $value) = static::prepareOperatorAndValue(
php
{ "resource": "" }
q17176
Constraint.whereColumn
train
public static function whereColumn($a, $operator, $b = null) { list($operator, $b) = static::prepareOperatorAndValue(
php
{ "resource": "" }
q17177
Constraint.logicalOperator
train
public function logicalOperator($operator = null) { if (is_null($operator)) { return $this->logicalOperator; }
php
{ "resource": "" }
q17178
Constraint.prepareOperatorAndValue
train
protected static function prepareOperatorAndValue($operator, $value, $usesDefault) { if ($usesDefault) { return ['=', $operator]; } if (! in_array($operator, ['=', '==', '!=', '<', '>', '<=', '>='])) {
php
{ "resource": "" }
q17179
Constraint.compare
train
protected function compare($a, $b) { switch ($this->operator) { case '=': case '==': return $a == $b; case '!=': return $a != $b; case '<': return $a < $b;
php
{ "resource": "" }
q17180
CachedClipboard.setCache
train
public function setCache(Store $cache) { if (method_exists($cache, 'tags')) { $cache = $cache->tags($this->tag());
php
{ "resource": "" }
q17181
CachedClipboard.findMatchingAbility
train
protected function findMatchingAbility($abilities, $applicable, $model, $authority) { $abilities = $abilities->toBase()->pluck('identifier', 'id'); if ($id = $this->getMatchedAbilityId($abilities, $applicable)) {
php
{ "resource": "" }
q17182
CachedClipboard.getMatchedAbilityId
train
protected function getMatchedAbilityId($abilityMap, $applicable) { foreach ($abilityMap as $id => $identifier) { if
php
{ "resource": "" }
q17183
CachedClipboard.compileAbilityIdentifiers
train
protected function compileAbilityIdentifiers($ability, $model) { $identifiers = new BaseCollection( is_null($model) ? [$ability, '*-*', '*'] : $this->compileModelAbilityIdentifiers($ability, $model) );
php
{ "resource": "" }
q17184
CachedClipboard.compileModelAbilityIdentifiers
train
protected function compileModelAbilityIdentifiers($ability, $model) { if ($model === '*') { return ["{$ability}-*", "*-*"]; } $model = $model instanceof Model ? $model : new $model; $type = $model->getMorphClass(); $abilities = [ "{$ability}-{$type}...
php
{ "resource": "" }
q17185
CachedClipboard.getAbilities
train
public function getAbilities(Model $authority, $allowed = true) { $key = $this->getCacheKey($authority, 'abilities', $allowed); if (is_array($abilities = $this->cache->get($key))) {
php
{ "resource": "" }
q17186
CachedClipboard.refreshAllIteratively
train
protected function refreshAllIteratively() { foreach (Models::user()->all() as $user) { $this->refreshFor($user);
php
{ "resource": "" }
q17187
CachedClipboard.getCacheKey
train
protected function getCacheKey(Model $model, $type, $allowed = true) { return implode('-', [ $this->tag(), $type, $model->getMorphClass(),
php
{ "resource": "" }
q17188
Clipboard.isForbidden
train
protected function isForbidden(Model $authority, $ability, $model = null) { return $this->getHasAbilityQuery(
php
{ "resource": "" }
q17189
Clipboard.getAllowingAbility
train
protected function getAllowingAbility(Model $authority, $ability, $model = null) { return $this->getHasAbilityQuery(
php
{ "resource": "" }
q17190
Clipboard.getHasAbilityQuery
train
protected function getHasAbilityQuery($authority, $ability, $model, $allowed) { $query = Abilities::forAuthority($authority, $allowed); if (! $this->isOwnedBy($authority, $model)) { $query->where('only_owned', false); } if (is_null($model))
php
{ "resource": "" }
q17191
Clipboard.constrainToSimpleAbility
train
protected function constrainToSimpleAbility($query, $ability) { return $query->where(function ($query) use ($ability) { $query->where('name', $ability)->whereNull('entity_type'); $query->orWhere(function ($query) use ($ability) { $query->where('name', '*')->where(fun...
php
{ "resource": "" }
q17192
Builder.where
train
public function where($column, $operator = null, $value = null) { if ($column instanceof Closure) { return $this->whereNested('and', $column);
php
{ "resource": "" }
q17193
Builder.whereColumn
train
public function whereColumn($a, $operator, $b = null) { $constraint = call_user_func_array( [Constraint::class, 'whereColumn'],
php
{ "resource": "" }
q17194
Builder.build
train
public function build() { if ($this->constraints->count() == 1) { return $this->constraints->first();
php
{ "resource": "" }
q17195
Builder.whereNested
train
protected function whereNested($logicalOperator, Closure $callback) { $callback($builder = new static);
php
{ "resource": "" }
q17196
Helpers.extractModelAndKeys
train
public static function extractModelAndKeys($model, array $keys = null) { if (! is_null($keys)) { if (is_string($model)) { $model = new $model; } return [$model, $keys];
php
{ "resource": "" }
q17197
Helpers.fillMissingKeys
train
public static function fillMissingKeys($array, $value, $keys) { foreach ($keys as $key) {
php
{ "resource": "" }
q17198
Helpers.isIndexedArray
train
public static function isIndexedArray($array) { if (! is_array($array)) { return false; } foreach ($array as $key => $value) { if (!
php
{ "resource": "" }
q17199
Helpers.toArray
train
public static function toArray($value) { if (is_array($value)) { return $value; }
php
{ "resource": "" }