repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
JosephSilber/bouncer | src/Database/Queries/Abilities.php | Abilities.getAuthorityRoleConstraint | protected static function getAuthorityRoleConstraint(Model $authority)
{
return function ($query) use ($authority) {
$pivot = Models::table('assigned_roles');
$roles = Models::table('roles');
$table = $authority->getTable();
$prefix = Models::prefix();
$query->from($table)
->join($pivot, "{$table}.{$authority->getKeyName()}", '=', $pivot.'.entity_id')
->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
->where($pivot.'.entity_type', $authority->getMorphClass())
->where("{$table}.{$authority->getKeyName()}", $authority->getKey());
Models::scope()->applyToModelQuery($query, $roles);
Models::scope()->applyToRelationQuery($query, $pivot);
};
} | php | protected static function getAuthorityRoleConstraint(Model $authority)
{
return function ($query) use ($authority) {
$pivot = Models::table('assigned_roles');
$roles = Models::table('roles');
$table = $authority->getTable();
$prefix = Models::prefix();
$query->from($table)
->join($pivot, "{$table}.{$authority->getKeyName()}", '=', $pivot.'.entity_id')
->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
->where($pivot.'.entity_type', $authority->getMorphClass())
->where("{$table}.{$authority->getKeyName()}", $authority->getKey());
Models::scope()->applyToModelQuery($query, $roles);
Models::scope()->applyToRelationQuery($query, $pivot);
};
} | [
"protected",
"static",
"function",
"getAuthorityRoleConstraint",
"(",
"Model",
"$",
"authority",
")",
"{",
"return",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"authority",
")",
"{",
"$",
"pivot",
"=",
"Models",
"::",
"table",
"(",
"'assigned_roles'",
")",
";",
"$",
"roles",
"=",
"Models",
"::",
"table",
"(",
"'roles'",
")",
";",
"$",
"table",
"=",
"$",
"authority",
"->",
"getTable",
"(",
")",
";",
"$",
"prefix",
"=",
"Models",
"::",
"prefix",
"(",
")",
";",
"$",
"query",
"->",
"from",
"(",
"$",
"table",
")",
"->",
"join",
"(",
"$",
"pivot",
",",
"\"{$table}.{$authority->getKeyName()}\"",
",",
"'='",
",",
"$",
"pivot",
".",
"'.entity_id'",
")",
"->",
"whereRaw",
"(",
"\"{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id\"",
")",
"->",
"where",
"(",
"$",
"pivot",
".",
"'.entity_type'",
",",
"$",
"authority",
"->",
"getMorphClass",
"(",
")",
")",
"->",
"where",
"(",
"\"{$table}.{$authority->getKeyName()}\"",
",",
"$",
"authority",
"->",
"getKey",
"(",
")",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToModelQuery",
"(",
"$",
"query",
",",
"$",
"roles",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelationQuery",
"(",
"$",
"query",
",",
"$",
"pivot",
")",
";",
"}",
";",
"}"
]
| Get a constraint for roles that are assigned to the given authority.
@param \Illuminate\Database\Eloquent\Model $authority
@return \Closure | [
"Get",
"a",
"constraint",
"for",
"roles",
"that",
"are",
"assigned",
"to",
"the",
"given",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/Abilities.php#L98-L115 | train |
JosephSilber/bouncer | src/Database/Queries/Abilities.php | Abilities.getAuthorityConstraint | protected static function getAuthorityConstraint(Model $authority, $allowed)
{
return function ($query) use ($authority, $allowed) {
$permissions = Models::table('permissions');
$abilities = Models::table('abilities');
$table = $authority->getTable();
$prefix = Models::prefix();
$query->from($table)
->join($permissions, "{$table}.{$authority->getKeyName()}", '=', $permissions.'.entity_id')
->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
->where("{$permissions}.forbidden", ! $allowed)
->where("{$permissions}.entity_type", $authority->getMorphClass())
->where("{$table}.{$authority->getKeyName()}", $authority->getKey());
Models::scope()->applyToModelQuery($query, $abilities);
Models::scope()->applyToRelationQuery($query, $permissions);
};
} | php | protected static function getAuthorityConstraint(Model $authority, $allowed)
{
return function ($query) use ($authority, $allowed) {
$permissions = Models::table('permissions');
$abilities = Models::table('abilities');
$table = $authority->getTable();
$prefix = Models::prefix();
$query->from($table)
->join($permissions, "{$table}.{$authority->getKeyName()}", '=', $permissions.'.entity_id')
->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
->where("{$permissions}.forbidden", ! $allowed)
->where("{$permissions}.entity_type", $authority->getMorphClass())
->where("{$table}.{$authority->getKeyName()}", $authority->getKey());
Models::scope()->applyToModelQuery($query, $abilities);
Models::scope()->applyToRelationQuery($query, $permissions);
};
} | [
"protected",
"static",
"function",
"getAuthorityConstraint",
"(",
"Model",
"$",
"authority",
",",
"$",
"allowed",
")",
"{",
"return",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"authority",
",",
"$",
"allowed",
")",
"{",
"$",
"permissions",
"=",
"Models",
"::",
"table",
"(",
"'permissions'",
")",
";",
"$",
"abilities",
"=",
"Models",
"::",
"table",
"(",
"'abilities'",
")",
";",
"$",
"table",
"=",
"$",
"authority",
"->",
"getTable",
"(",
")",
";",
"$",
"prefix",
"=",
"Models",
"::",
"prefix",
"(",
")",
";",
"$",
"query",
"->",
"from",
"(",
"$",
"table",
")",
"->",
"join",
"(",
"$",
"permissions",
",",
"\"{$table}.{$authority->getKeyName()}\"",
",",
"'='",
",",
"$",
"permissions",
".",
"'.entity_id'",
")",
"->",
"whereRaw",
"(",
"\"{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id\"",
")",
"->",
"where",
"(",
"\"{$permissions}.forbidden\"",
",",
"!",
"$",
"allowed",
")",
"->",
"where",
"(",
"\"{$permissions}.entity_type\"",
",",
"$",
"authority",
"->",
"getMorphClass",
"(",
")",
")",
"->",
"where",
"(",
"\"{$table}.{$authority->getKeyName()}\"",
",",
"$",
"authority",
"->",
"getKey",
"(",
")",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToModelQuery",
"(",
"$",
"query",
",",
"$",
"abilities",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelationQuery",
"(",
"$",
"query",
",",
"$",
"permissions",
")",
";",
"}",
";",
"}"
]
| Get a constraint for abilities that have been granted to the given authority.
@param \Illuminate\Database\Eloquent\Model $authority
@param bool $allowed
@return \Closure | [
"Get",
"a",
"constraint",
"for",
"abilities",
"that",
"have",
"been",
"granted",
"to",
"the",
"given",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/Abilities.php#L124-L142 | train |
JosephSilber/bouncer | src/Database/Queries/Abilities.php | Abilities.getEveryoneConstraint | protected static function getEveryoneConstraint($allowed)
{
return function ($query) use ($allowed) {
$permissions = Models::table('permissions');
$abilities = Models::table('abilities');
$prefix = Models::prefix();
$query->from($permissions)
->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
->where("{$permissions}.forbidden", ! $allowed)
->whereNull('entity_id');
Models::scope()->applyToRelationQuery($query, $permissions);
};
} | php | protected static function getEveryoneConstraint($allowed)
{
return function ($query) use ($allowed) {
$permissions = Models::table('permissions');
$abilities = Models::table('abilities');
$prefix = Models::prefix();
$query->from($permissions)
->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
->where("{$permissions}.forbidden", ! $allowed)
->whereNull('entity_id');
Models::scope()->applyToRelationQuery($query, $permissions);
};
} | [
"protected",
"static",
"function",
"getEveryoneConstraint",
"(",
"$",
"allowed",
")",
"{",
"return",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"allowed",
")",
"{",
"$",
"permissions",
"=",
"Models",
"::",
"table",
"(",
"'permissions'",
")",
";",
"$",
"abilities",
"=",
"Models",
"::",
"table",
"(",
"'abilities'",
")",
";",
"$",
"prefix",
"=",
"Models",
"::",
"prefix",
"(",
")",
";",
"$",
"query",
"->",
"from",
"(",
"$",
"permissions",
")",
"->",
"whereRaw",
"(",
"\"{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id\"",
")",
"->",
"where",
"(",
"\"{$permissions}.forbidden\"",
",",
"!",
"$",
"allowed",
")",
"->",
"whereNull",
"(",
"'entity_id'",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelationQuery",
"(",
"$",
"query",
",",
"$",
"permissions",
")",
";",
"}",
";",
"}"
]
| Get a constraint for abilities that have been granted to everyone.
@param bool $allowed
@return \Closure | [
"Get",
"a",
"constraint",
"for",
"abilities",
"that",
"have",
"been",
"granted",
"to",
"everyone",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/Abilities.php#L150-L164 | train |
JosephSilber/bouncer | src/Conductors/Concerns/DisassociatesAbilities.php | DisassociatesAbilities.to | public function to($abilities, $entity = null, array $attributes = [])
{
if (call_user_func_array([$this, 'shouldConductLazy'], func_get_args())) {
return $this->conductLazy($abilities);
}
if ($ids = $this->getAbilityIds($abilities, $entity, $attributes)) {
$this->disassociateAbilities($this->getAuthority(), $ids);
}
return true;
} | php | public function to($abilities, $entity = null, array $attributes = [])
{
if (call_user_func_array([$this, 'shouldConductLazy'], func_get_args())) {
return $this->conductLazy($abilities);
}
if ($ids = $this->getAbilityIds($abilities, $entity, $attributes)) {
$this->disassociateAbilities($this->getAuthority(), $ids);
}
return true;
} | [
"public",
"function",
"to",
"(",
"$",
"abilities",
",",
"$",
"entity",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'shouldConductLazy'",
"]",
",",
"func_get_args",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"conductLazy",
"(",
"$",
"abilities",
")",
";",
"}",
"if",
"(",
"$",
"ids",
"=",
"$",
"this",
"->",
"getAbilityIds",
"(",
"$",
"abilities",
",",
"$",
"entity",
",",
"$",
"attributes",
")",
")",
"{",
"$",
"this",
"->",
"disassociateAbilities",
"(",
"$",
"this",
"->",
"getAuthority",
"(",
")",
",",
"$",
"ids",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Remove the given ability from the model.
@param mixed $abilities
@param \Illuminate\Database\Eloquent\Model|string|null $entity
@param array $attributes
@return bool|\Silber\Bouncer\Conductors\Lazy\ConductsAbilities | [
"Remove",
"the",
"given",
"ability",
"from",
"the",
"model",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/DisassociatesAbilities.php#L25-L36 | train |
JosephSilber/bouncer | src/Conductors/Concerns/DisassociatesAbilities.php | DisassociatesAbilities.disassociateAbilities | protected function disassociateAbilities($authority, array $ids)
{
if (is_null($authority)) {
$this->disassociateEveryone($ids);
} else {
$this->disassociateAuthority($authority, $ids);
}
} | php | protected function disassociateAbilities($authority, array $ids)
{
if (is_null($authority)) {
$this->disassociateEveryone($ids);
} else {
$this->disassociateAuthority($authority, $ids);
}
} | [
"protected",
"function",
"disassociateAbilities",
"(",
"$",
"authority",
",",
"array",
"$",
"ids",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"authority",
")",
")",
"{",
"$",
"this",
"->",
"disassociateEveryone",
"(",
"$",
"ids",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"disassociateAuthority",
"(",
"$",
"authority",
",",
"$",
"ids",
")",
";",
"}",
"}"
]
| Detach the given IDs from the authority.
@param \Illuminate\Database\Eloquent\Model|null $authority
@param array $ids
@return void | [
"Detach",
"the",
"given",
"IDs",
"from",
"the",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/DisassociatesAbilities.php#L45-L52 | train |
JosephSilber/bouncer | src/Conductors/Concerns/DisassociatesAbilities.php | DisassociatesAbilities.disassociateAuthority | protected function disassociateAuthority(Model $authority, array $ids)
{
$this->getAbilitiesPivotQuery($authority, $ids)
->where($this->constraints())
->delete();
} | php | protected function disassociateAuthority(Model $authority, array $ids)
{
$this->getAbilitiesPivotQuery($authority, $ids)
->where($this->constraints())
->delete();
} | [
"protected",
"function",
"disassociateAuthority",
"(",
"Model",
"$",
"authority",
",",
"array",
"$",
"ids",
")",
"{",
"$",
"this",
"->",
"getAbilitiesPivotQuery",
"(",
"$",
"authority",
",",
"$",
"ids",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"constraints",
"(",
")",
")",
"->",
"delete",
"(",
")",
";",
"}"
]
| Disassociate the authority from the abilities with the given IDs.
@param \Illuminate\Database\Eloquent\Model $authority
@param array $ids
@return void | [
"Disassociate",
"the",
"authority",
"from",
"the",
"abilities",
"with",
"the",
"given",
"IDs",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/DisassociatesAbilities.php#L61-L66 | train |
JosephSilber/bouncer | src/Conductors/Concerns/DisassociatesAbilities.php | DisassociatesAbilities.getAbilitiesPivotQuery | protected function getAbilitiesPivotQuery(Model $model, $ids)
{
$relation = $model->abilities();
list($foreignKeyName, $relatedKeyName) = $this->getRelationKeyNames($relation);
$query = $relation
->newPivotStatement()
->where($foreignKeyName, $model->getKey())
->where('entity_type', $model->getMorphClass())
->whereIn($relatedKeyName, $ids);
return Models::scope()->applyToRelationQuery(
$query, $relation->getTable()
);
} | php | protected function getAbilitiesPivotQuery(Model $model, $ids)
{
$relation = $model->abilities();
list($foreignKeyName, $relatedKeyName) = $this->getRelationKeyNames($relation);
$query = $relation
->newPivotStatement()
->where($foreignKeyName, $model->getKey())
->where('entity_type', $model->getMorphClass())
->whereIn($relatedKeyName, $ids);
return Models::scope()->applyToRelationQuery(
$query, $relation->getTable()
);
} | [
"protected",
"function",
"getAbilitiesPivotQuery",
"(",
"Model",
"$",
"model",
",",
"$",
"ids",
")",
"{",
"$",
"relation",
"=",
"$",
"model",
"->",
"abilities",
"(",
")",
";",
"list",
"(",
"$",
"foreignKeyName",
",",
"$",
"relatedKeyName",
")",
"=",
"$",
"this",
"->",
"getRelationKeyNames",
"(",
"$",
"relation",
")",
";",
"$",
"query",
"=",
"$",
"relation",
"->",
"newPivotStatement",
"(",
")",
"->",
"where",
"(",
"$",
"foreignKeyName",
",",
"$",
"model",
"->",
"getKey",
"(",
")",
")",
"->",
"where",
"(",
"'entity_type'",
",",
"$",
"model",
"->",
"getMorphClass",
"(",
")",
")",
"->",
"whereIn",
"(",
"$",
"relatedKeyName",
",",
"$",
"ids",
")",
";",
"return",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelationQuery",
"(",
"$",
"query",
",",
"$",
"relation",
"->",
"getTable",
"(",
")",
")",
";",
"}"
]
| Get the base abilities pivot query.
@param \Illuminate\Database\Eloquent\Model $model
@param array $ids
@return \Illuminate\Database\Query\Builder | [
"Get",
"the",
"base",
"abilities",
"pivot",
"query",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/DisassociatesAbilities.php#L75-L90 | train |
JosephSilber/bouncer | src/Conductors/Concerns/DisassociatesAbilities.php | DisassociatesAbilities.getRelationKeyNames | protected function getRelationKeyNames(MorphToMany $relation)
{
// We need to get the keys of both tables from the relation class.
// The method names have changed in Laravel 5.4 & again in 5.5,
// so we will first check which methods are available to us.
if (method_exists($relation, 'getForeignKey')) {
return [
$relation->getForeignKey(),
$relation->getOtherKey(),
];
}
if (method_exists($relation, 'getQualifiedForeignKeyName')) {
return [
$relation->getQualifiedForeignKeyName(),
$relation->getQualifiedRelatedKeyName(),
];
}
return [
$relation->getQualifiedForeignPivotKeyName(),
$relation->getQualifiedRelatedPivotKeyName(),
];
} | php | protected function getRelationKeyNames(MorphToMany $relation)
{
// We need to get the keys of both tables from the relation class.
// The method names have changed in Laravel 5.4 & again in 5.5,
// so we will first check which methods are available to us.
if (method_exists($relation, 'getForeignKey')) {
return [
$relation->getForeignKey(),
$relation->getOtherKey(),
];
}
if (method_exists($relation, 'getQualifiedForeignKeyName')) {
return [
$relation->getQualifiedForeignKeyName(),
$relation->getQualifiedRelatedKeyName(),
];
}
return [
$relation->getQualifiedForeignPivotKeyName(),
$relation->getQualifiedRelatedPivotKeyName(),
];
} | [
"protected",
"function",
"getRelationKeyNames",
"(",
"MorphToMany",
"$",
"relation",
")",
"{",
"// We need to get the keys of both tables from the relation class.",
"// The method names have changed in Laravel 5.4 & again in 5.5,",
"// so we will first check which methods are available to us.",
"if",
"(",
"method_exists",
"(",
"$",
"relation",
",",
"'getForeignKey'",
")",
")",
"{",
"return",
"[",
"$",
"relation",
"->",
"getForeignKey",
"(",
")",
",",
"$",
"relation",
"->",
"getOtherKey",
"(",
")",
",",
"]",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"relation",
",",
"'getQualifiedForeignKeyName'",
")",
")",
"{",
"return",
"[",
"$",
"relation",
"->",
"getQualifiedForeignKeyName",
"(",
")",
",",
"$",
"relation",
"->",
"getQualifiedRelatedKeyName",
"(",
")",
",",
"]",
";",
"}",
"return",
"[",
"$",
"relation",
"->",
"getQualifiedForeignPivotKeyName",
"(",
")",
",",
"$",
"relation",
"->",
"getQualifiedRelatedPivotKeyName",
"(",
")",
",",
"]",
";",
"}"
]
| Get the two primary key names from the relation.
@param Illuminate\Database\Eloquent\Relations\MorphToMany $relation
@return array | [
"Get",
"the",
"two",
"primary",
"key",
"names",
"from",
"the",
"relation",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/DisassociatesAbilities.php#L98-L121 | train |
JosephSilber/bouncer | src/Conductors/Concerns/DisassociatesAbilities.php | DisassociatesAbilities.disassociateEveryone | protected function disassociateEveryone(array $ids)
{
$query = Models::query('permissions')
->whereNull('entity_id')
->where($this->constraints())
->whereIn('ability_id', $ids);
Models::scope()->applyToRelationQuery($query, $query->from);
$query->delete();
} | php | protected function disassociateEveryone(array $ids)
{
$query = Models::query('permissions')
->whereNull('entity_id')
->where($this->constraints())
->whereIn('ability_id', $ids);
Models::scope()->applyToRelationQuery($query, $query->from);
$query->delete();
} | [
"protected",
"function",
"disassociateEveryone",
"(",
"array",
"$",
"ids",
")",
"{",
"$",
"query",
"=",
"Models",
"::",
"query",
"(",
"'permissions'",
")",
"->",
"whereNull",
"(",
"'entity_id'",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"constraints",
"(",
")",
")",
"->",
"whereIn",
"(",
"'ability_id'",
",",
"$",
"ids",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelationQuery",
"(",
"$",
"query",
",",
"$",
"query",
"->",
"from",
")",
";",
"$",
"query",
"->",
"delete",
"(",
")",
";",
"}"
]
| Disassociate everyone from the abilities with the given IDs.
@param array $ids
@return void | [
"Disassociate",
"everyone",
"from",
"the",
"abilities",
"with",
"the",
"given",
"IDs",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/DisassociatesAbilities.php#L129-L139 | train |
JosephSilber/bouncer | src/Conductors/Concerns/DisassociatesAbilities.php | DisassociatesAbilities.getAuthority | protected function getAuthority()
{
if (is_null($this->authority)) {
return null;
}
if ($this->authority instanceof Model) {
return $this->authority;
}
return Models::role()->where('name', $this->authority)->firstOrFail();
} | php | protected function getAuthority()
{
if (is_null($this->authority)) {
return null;
}
if ($this->authority instanceof Model) {
return $this->authority;
}
return Models::role()->where('name', $this->authority)->firstOrFail();
} | [
"protected",
"function",
"getAuthority",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"authority",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"authority",
"instanceof",
"Model",
")",
"{",
"return",
"$",
"this",
"->",
"authority",
";",
"}",
"return",
"Models",
"::",
"role",
"(",
")",
"->",
"where",
"(",
"'name'",
",",
"$",
"this",
"->",
"authority",
")",
"->",
"firstOrFail",
"(",
")",
";",
"}"
]
| Get the authority from which to disassociate the abilities.
@return \Illuminate\Database\Eloquent\Model|null | [
"Get",
"the",
"authority",
"from",
"which",
"to",
"disassociate",
"the",
"abilities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/DisassociatesAbilities.php#L146-L157 | train |
JosephSilber/bouncer | src/Database/Titles/Title.php | Title.humanize | protected function humanize($value)
{
// Older versions of Laravel's inflector strip out spaces
// in the original string, so we'll first swap out all
// spaces with underscores, then convert them back.
$value = str_replace(' ', '_', $value);
// First we'll convert the string to snake case. Then we'll
// convert all dashes and underscores to spaces. Finally,
// we'll add a space before a pound (Laravel doesn't).
$value = Str::snake($value);
$value = preg_replace('~(?:-|_)+~', ' ', $value);
$value = preg_replace('~([^ ])(?:#)+~', '$1 #', $value);
return ucfirst($value);
} | php | protected function humanize($value)
{
// Older versions of Laravel's inflector strip out spaces
// in the original string, so we'll first swap out all
// spaces with underscores, then convert them back.
$value = str_replace(' ', '_', $value);
// First we'll convert the string to snake case. Then we'll
// convert all dashes and underscores to spaces. Finally,
// we'll add a space before a pound (Laravel doesn't).
$value = Str::snake($value);
$value = preg_replace('~(?:-|_)+~', ' ', $value);
$value = preg_replace('~([^ ])(?:#)+~', '$1 #', $value);
return ucfirst($value);
} | [
"protected",
"function",
"humanize",
"(",
"$",
"value",
")",
"{",
"// Older versions of Laravel's inflector strip out spaces",
"// in the original string, so we'll first swap out all",
"// spaces with underscores, then convert them back.",
"$",
"value",
"=",
"str_replace",
"(",
"' '",
",",
"'_'",
",",
"$",
"value",
")",
";",
"// First we'll convert the string to snake case. Then we'll",
"// convert all dashes and underscores to spaces. Finally,",
"// we'll add a space before a pound (Laravel doesn't).",
"$",
"value",
"=",
"Str",
"::",
"snake",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'~(?:-|_)+~'",
",",
"' '",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'~([^ ])(?:#)+~'",
",",
"'$1 #'",
",",
"$",
"value",
")",
";",
"return",
"ucfirst",
"(",
"$",
"value",
")",
";",
"}"
]
| Convert the given string into a human-readable format.
@param string $value
@return string | [
"Convert",
"the",
"given",
"string",
"into",
"a",
"human",
"-",
"readable",
"format",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Titles/Title.php#L34-L51 | train |
JosephSilber/bouncer | src/Conductors/SyncsRolesAndAbilities.php | SyncsRolesAndAbilities.roles | public function roles($roles)
{
$this->sync(
Models::role()->getRoleKeys($roles),
$this->authority->roles()
);
} | php | public function roles($roles)
{
$this->sync(
Models::role()->getRoleKeys($roles),
$this->authority->roles()
);
} | [
"public",
"function",
"roles",
"(",
"$",
"roles",
")",
"{",
"$",
"this",
"->",
"sync",
"(",
"Models",
"::",
"role",
"(",
")",
"->",
"getRoleKeys",
"(",
"$",
"roles",
")",
",",
"$",
"this",
"->",
"authority",
"->",
"roles",
"(",
")",
")",
";",
"}"
]
| Sync the provided roles to the authority.
@param iterable $roles
@return void | [
"Sync",
"the",
"provided",
"roles",
"to",
"the",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/SyncsRolesAndAbilities.php#L40-L46 | train |
JosephSilber/bouncer | src/Conductors/SyncsRolesAndAbilities.php | SyncsRolesAndAbilities.syncAbilities | protected function syncAbilities($abilities, $options = ['forbidden' => false])
{
$abilityKeys = $this->getAbilityIds($abilities);
$authority = $this->getAuthority();
$relation = $authority->abilities();
$this->newPivotQuery($relation)
->where('entity_type', $authority->getMorphClass())
->whereNotIn($this->getRelatedPivotKeyName($relation), $abilityKeys)
->where('forbidden', $options['forbidden'])
->delete();
if ($options['forbidden']) {
(new ForbidsAbilities($this->authority))->to($abilityKeys);
} else {
(new GivesAbilities($this->authority))->to($abilityKeys);
}
} | php | protected function syncAbilities($abilities, $options = ['forbidden' => false])
{
$abilityKeys = $this->getAbilityIds($abilities);
$authority = $this->getAuthority();
$relation = $authority->abilities();
$this->newPivotQuery($relation)
->where('entity_type', $authority->getMorphClass())
->whereNotIn($this->getRelatedPivotKeyName($relation), $abilityKeys)
->where('forbidden', $options['forbidden'])
->delete();
if ($options['forbidden']) {
(new ForbidsAbilities($this->authority))->to($abilityKeys);
} else {
(new GivesAbilities($this->authority))->to($abilityKeys);
}
} | [
"protected",
"function",
"syncAbilities",
"(",
"$",
"abilities",
",",
"$",
"options",
"=",
"[",
"'forbidden'",
"=>",
"false",
"]",
")",
"{",
"$",
"abilityKeys",
"=",
"$",
"this",
"->",
"getAbilityIds",
"(",
"$",
"abilities",
")",
";",
"$",
"authority",
"=",
"$",
"this",
"->",
"getAuthority",
"(",
")",
";",
"$",
"relation",
"=",
"$",
"authority",
"->",
"abilities",
"(",
")",
";",
"$",
"this",
"->",
"newPivotQuery",
"(",
"$",
"relation",
")",
"->",
"where",
"(",
"'entity_type'",
",",
"$",
"authority",
"->",
"getMorphClass",
"(",
")",
")",
"->",
"whereNotIn",
"(",
"$",
"this",
"->",
"getRelatedPivotKeyName",
"(",
"$",
"relation",
")",
",",
"$",
"abilityKeys",
")",
"->",
"where",
"(",
"'forbidden'",
",",
"$",
"options",
"[",
"'forbidden'",
"]",
")",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'forbidden'",
"]",
")",
"{",
"(",
"new",
"ForbidsAbilities",
"(",
"$",
"this",
"->",
"authority",
")",
")",
"->",
"to",
"(",
"$",
"abilityKeys",
")",
";",
"}",
"else",
"{",
"(",
"new",
"GivesAbilities",
"(",
"$",
"this",
"->",
"authority",
")",
")",
"->",
"to",
"(",
"$",
"abilityKeys",
")",
";",
"}",
"}"
]
| Sync the given abilities for the authority.
@param iterable $abilities
@param array $options
@return void | [
"Sync",
"the",
"given",
"abilities",
"for",
"the",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/SyncsRolesAndAbilities.php#L77-L94 | train |
JosephSilber/bouncer | src/Conductors/SyncsRolesAndAbilities.php | SyncsRolesAndAbilities.sync | protected function sync(array $ids, BelongsToMany $relation)
{
$current = $this->pluck(
$this->newPivotQuery($relation),
$this->getRelatedPivotKeyName($relation)
);
$this->detach(array_diff($current, $ids), $relation);
$relation->attach(
array_diff($ids, $current),
Models::scope()->getAttachAttributes($this->authority)
);
} | php | protected function sync(array $ids, BelongsToMany $relation)
{
$current = $this->pluck(
$this->newPivotQuery($relation),
$this->getRelatedPivotKeyName($relation)
);
$this->detach(array_diff($current, $ids), $relation);
$relation->attach(
array_diff($ids, $current),
Models::scope()->getAttachAttributes($this->authority)
);
} | [
"protected",
"function",
"sync",
"(",
"array",
"$",
"ids",
",",
"BelongsToMany",
"$",
"relation",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"pluck",
"(",
"$",
"this",
"->",
"newPivotQuery",
"(",
"$",
"relation",
")",
",",
"$",
"this",
"->",
"getRelatedPivotKeyName",
"(",
"$",
"relation",
")",
")",
";",
"$",
"this",
"->",
"detach",
"(",
"array_diff",
"(",
"$",
"current",
",",
"$",
"ids",
")",
",",
"$",
"relation",
")",
";",
"$",
"relation",
"->",
"attach",
"(",
"array_diff",
"(",
"$",
"ids",
",",
"$",
"current",
")",
",",
"Models",
"::",
"scope",
"(",
")",
"->",
"getAttachAttributes",
"(",
"$",
"this",
"->",
"authority",
")",
")",
";",
"}"
]
| Sync the given IDs on the pivot relation.
This is a heavily-modified version of Eloquent's built-in
BelongsToMany@sync - which we sadly cannot use because
our scope sets a "closure where" on the pivot table.
@param array $ids
@param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation
@return void | [
"Sync",
"the",
"given",
"IDs",
"on",
"the",
"pivot",
"relation",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/SyncsRolesAndAbilities.php#L133-L146 | train |
JosephSilber/bouncer | src/Conductors/SyncsRolesAndAbilities.php | SyncsRolesAndAbilities.detach | public function detach(array $ids, BelongsToMany $relation)
{
if (empty($ids)) {
return;
}
$this->newPivotQuery($relation)
->whereIn($this->getRelatedPivotKeyName($relation), $ids)
->delete();
} | php | public function detach(array $ids, BelongsToMany $relation)
{
if (empty($ids)) {
return;
}
$this->newPivotQuery($relation)
->whereIn($this->getRelatedPivotKeyName($relation), $ids)
->delete();
} | [
"public",
"function",
"detach",
"(",
"array",
"$",
"ids",
",",
"BelongsToMany",
"$",
"relation",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"newPivotQuery",
"(",
"$",
"relation",
")",
"->",
"whereIn",
"(",
"$",
"this",
"->",
"getRelatedPivotKeyName",
"(",
"$",
"relation",
")",
",",
"$",
"ids",
")",
"->",
"delete",
"(",
")",
";",
"}"
]
| Detach the records with the given IDs from the relationship.
@param array $ids
@param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation
@return void | [
"Detach",
"the",
"records",
"with",
"the",
"given",
"IDs",
"from",
"the",
"relationship",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/SyncsRolesAndAbilities.php#L155-L164 | train |
JosephSilber/bouncer | src/Conductors/SyncsRolesAndAbilities.php | SyncsRolesAndAbilities.newPivotQuery | protected function newPivotQuery(BelongsToMany $relation)
{
$query = $relation->newPivotStatement()->where(
$this->getForeignPivotKeyName($relation),
$relation->getParent()->getKey()
);
return Models::scope()->applyToRelationQuery(
$query, $relation->getTable()
);
} | php | protected function newPivotQuery(BelongsToMany $relation)
{
$query = $relation->newPivotStatement()->where(
$this->getForeignPivotKeyName($relation),
$relation->getParent()->getKey()
);
return Models::scope()->applyToRelationQuery(
$query, $relation->getTable()
);
} | [
"protected",
"function",
"newPivotQuery",
"(",
"BelongsToMany",
"$",
"relation",
")",
"{",
"$",
"query",
"=",
"$",
"relation",
"->",
"newPivotStatement",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getForeignPivotKeyName",
"(",
"$",
"relation",
")",
",",
"$",
"relation",
"->",
"getParent",
"(",
")",
"->",
"getKey",
"(",
")",
")",
";",
"return",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelationQuery",
"(",
"$",
"query",
",",
"$",
"relation",
"->",
"getTable",
"(",
")",
")",
";",
"}"
]
| Get a scoped query for the pivot table.
@param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation
@return \Illuminate\Database\Query\Builder | [
"Get",
"a",
"scoped",
"query",
"for",
"the",
"pivot",
"table",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/SyncsRolesAndAbilities.php#L172-L182 | train |
JosephSilber/bouncer | src/Conductors/SyncsRolesAndAbilities.php | SyncsRolesAndAbilities.getForeignPivotKeyName | protected function getForeignPivotKeyName(BelongsToMany $relation)
{
if (method_exists($relation, 'getForeignPivotKeyName')) {
return $relation->getForeignPivotKeyName();
}
if (method_exists($relation, 'getQualifiedForeignKeyName')) {
return $relation->getQualifiedForeignKeyName();
}
return $relation->getForeignKey();
} | php | protected function getForeignPivotKeyName(BelongsToMany $relation)
{
if (method_exists($relation, 'getForeignPivotKeyName')) {
return $relation->getForeignPivotKeyName();
}
if (method_exists($relation, 'getQualifiedForeignKeyName')) {
return $relation->getQualifiedForeignKeyName();
}
return $relation->getForeignKey();
} | [
"protected",
"function",
"getForeignPivotKeyName",
"(",
"BelongsToMany",
"$",
"relation",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"relation",
",",
"'getForeignPivotKeyName'",
")",
")",
"{",
"return",
"$",
"relation",
"->",
"getForeignPivotKeyName",
"(",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"relation",
",",
"'getQualifiedForeignKeyName'",
")",
")",
"{",
"return",
"$",
"relation",
"->",
"getQualifiedForeignKeyName",
"(",
")",
";",
"}",
"return",
"$",
"relation",
"->",
"getForeignKey",
"(",
")",
";",
"}"
]
| Get the column name for the foreign key on the pivot table.
The name of the underlying method changed in
Laravel 5.4, and then again in 5.5, so we
first check which method is available.
@param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation
@return string | [
"Get",
"the",
"column",
"name",
"for",
"the",
"foreign",
"key",
"on",
"the",
"pivot",
"table",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/SyncsRolesAndAbilities.php#L194-L205 | train |
JosephSilber/bouncer | src/Conductors/SyncsRolesAndAbilities.php | SyncsRolesAndAbilities.getRelatedPivotKeyName | protected function getRelatedPivotKeyName(BelongsToMany $relation)
{
if (method_exists($relation, 'getRelatedPivotKeyName')) {
return $relation->getRelatedPivotKeyName();
}
if (method_exists($relation, 'getQualifiedRelatedKeyName')) {
return $relation->getQualifiedRelatedKeyName();
}
return $relation->getOtherKey();
} | php | protected function getRelatedPivotKeyName(BelongsToMany $relation)
{
if (method_exists($relation, 'getRelatedPivotKeyName')) {
return $relation->getRelatedPivotKeyName();
}
if (method_exists($relation, 'getQualifiedRelatedKeyName')) {
return $relation->getQualifiedRelatedKeyName();
}
return $relation->getOtherKey();
} | [
"protected",
"function",
"getRelatedPivotKeyName",
"(",
"BelongsToMany",
"$",
"relation",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"relation",
",",
"'getRelatedPivotKeyName'",
")",
")",
"{",
"return",
"$",
"relation",
"->",
"getRelatedPivotKeyName",
"(",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"relation",
",",
"'getQualifiedRelatedKeyName'",
")",
")",
"{",
"return",
"$",
"relation",
"->",
"getQualifiedRelatedKeyName",
"(",
")",
";",
"}",
"return",
"$",
"relation",
"->",
"getOtherKey",
"(",
")",
";",
"}"
]
| Get the column name for the related key on the pivot table.
The name of the underlying method changed in
Laravel 5.4, and then again in 5.5, so we
first check which method is available.
@param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation
@return string | [
"Get",
"the",
"column",
"name",
"for",
"the",
"related",
"key",
"on",
"the",
"pivot",
"table",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/SyncsRolesAndAbilities.php#L217-L228 | train |
JosephSilber/bouncer | src/Conductors/SyncsRolesAndAbilities.php | SyncsRolesAndAbilities.pluck | protected function pluck($query, $column)
{
return Arr::pluck($query->get([$column]), last(explode('.', $column)));
} | php | protected function pluck($query, $column)
{
return Arr::pluck($query->get([$column]), last(explode('.', $column)));
} | [
"protected",
"function",
"pluck",
"(",
"$",
"query",
",",
"$",
"column",
")",
"{",
"return",
"Arr",
"::",
"pluck",
"(",
"$",
"query",
"->",
"get",
"(",
"[",
"$",
"column",
"]",
")",
",",
"last",
"(",
"explode",
"(",
"'.'",
",",
"$",
"column",
")",
")",
")",
";",
"}"
]
| Pluck the values of the given column using the provided query.
@param mixed $query
@param string $column
@return string[] | [
"Pluck",
"the",
"values",
"of",
"the",
"given",
"column",
"using",
"the",
"provided",
"query",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/SyncsRolesAndAbilities.php#L237-L240 | train |
JosephSilber/bouncer | src/Conductors/AssignsRoles.php | AssignsRoles.to | public function to($authority)
{
$authorities = is_array($authority) ? $authority : [$authority];
$roles = Models::role()->findOrCreateRoles($this->roles);
foreach (Helpers::mapAuthorityByClass($authorities) as $class => $ids) {
$this->assignRoles($roles, $class, new Collection($ids));
}
return true;
} | php | public function to($authority)
{
$authorities = is_array($authority) ? $authority : [$authority];
$roles = Models::role()->findOrCreateRoles($this->roles);
foreach (Helpers::mapAuthorityByClass($authorities) as $class => $ids) {
$this->assignRoles($roles, $class, new Collection($ids));
}
return true;
} | [
"public",
"function",
"to",
"(",
"$",
"authority",
")",
"{",
"$",
"authorities",
"=",
"is_array",
"(",
"$",
"authority",
")",
"?",
"$",
"authority",
":",
"[",
"$",
"authority",
"]",
";",
"$",
"roles",
"=",
"Models",
"::",
"role",
"(",
")",
"->",
"findOrCreateRoles",
"(",
"$",
"this",
"->",
"roles",
")",
";",
"foreach",
"(",
"Helpers",
"::",
"mapAuthorityByClass",
"(",
"$",
"authorities",
")",
"as",
"$",
"class",
"=>",
"$",
"ids",
")",
"{",
"$",
"this",
"->",
"assignRoles",
"(",
"$",
"roles",
",",
"$",
"class",
",",
"new",
"Collection",
"(",
"$",
"ids",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Assign the roles to the given authority.
@param \Illuminate\Database\Eloquent\Model|array|int $authority
@return bool | [
"Assign",
"the",
"roles",
"to",
"the",
"given",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/AssignsRoles.php#L35-L46 | train |
JosephSilber/bouncer | src/Conductors/AssignsRoles.php | AssignsRoles.assignRoles | protected function assignRoles(Collection $roles, $authorityClass, Collection $authorityIds)
{
$roleIds = $roles->map(function ($model) {
return $model->getKey();
});
$morphType = (new $authorityClass)->getMorphClass();
$records = $this->buildAttachRecords($roleIds, $morphType, $authorityIds);
$existing = $this->getExistingAttachRecords($roleIds, $morphType, $authorityIds);
$this->createMissingAssignRecords($records, $existing);
} | php | protected function assignRoles(Collection $roles, $authorityClass, Collection $authorityIds)
{
$roleIds = $roles->map(function ($model) {
return $model->getKey();
});
$morphType = (new $authorityClass)->getMorphClass();
$records = $this->buildAttachRecords($roleIds, $morphType, $authorityIds);
$existing = $this->getExistingAttachRecords($roleIds, $morphType, $authorityIds);
$this->createMissingAssignRecords($records, $existing);
} | [
"protected",
"function",
"assignRoles",
"(",
"Collection",
"$",
"roles",
",",
"$",
"authorityClass",
",",
"Collection",
"$",
"authorityIds",
")",
"{",
"$",
"roleIds",
"=",
"$",
"roles",
"->",
"map",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"return",
"$",
"model",
"->",
"getKey",
"(",
")",
";",
"}",
")",
";",
"$",
"morphType",
"=",
"(",
"new",
"$",
"authorityClass",
")",
"->",
"getMorphClass",
"(",
")",
";",
"$",
"records",
"=",
"$",
"this",
"->",
"buildAttachRecords",
"(",
"$",
"roleIds",
",",
"$",
"morphType",
",",
"$",
"authorityIds",
")",
";",
"$",
"existing",
"=",
"$",
"this",
"->",
"getExistingAttachRecords",
"(",
"$",
"roleIds",
",",
"$",
"morphType",
",",
"$",
"authorityIds",
")",
";",
"$",
"this",
"->",
"createMissingAssignRecords",
"(",
"$",
"records",
",",
"$",
"existing",
")",
";",
"}"
]
| Assign the given roles to the given authorities.
@param \Illuminate\Suuport\Collection $roles
@param string $authorityClass
@param \Illuminate\Suuport\Collection $authorityIds
@return void | [
"Assign",
"the",
"given",
"roles",
"to",
"the",
"given",
"authorities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/AssignsRoles.php#L56-L69 | train |
JosephSilber/bouncer | src/Conductors/AssignsRoles.php | AssignsRoles.getExistingAttachRecords | protected function getExistingAttachRecords($roleIds, $morphType, $authorityIds)
{
$query = $this->newPivotTableQuery()
->whereIn('role_id', $roleIds->all())
->whereIn('entity_id', $authorityIds->all())
->where('entity_type', $morphType);
Models::scope()->applyToRelationQuery($query, $query->from);
return new Collection($query->get());
} | php | protected function getExistingAttachRecords($roleIds, $morphType, $authorityIds)
{
$query = $this->newPivotTableQuery()
->whereIn('role_id', $roleIds->all())
->whereIn('entity_id', $authorityIds->all())
->where('entity_type', $morphType);
Models::scope()->applyToRelationQuery($query, $query->from);
return new Collection($query->get());
} | [
"protected",
"function",
"getExistingAttachRecords",
"(",
"$",
"roleIds",
",",
"$",
"morphType",
",",
"$",
"authorityIds",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"newPivotTableQuery",
"(",
")",
"->",
"whereIn",
"(",
"'role_id'",
",",
"$",
"roleIds",
"->",
"all",
"(",
")",
")",
"->",
"whereIn",
"(",
"'entity_id'",
",",
"$",
"authorityIds",
"->",
"all",
"(",
")",
")",
"->",
"where",
"(",
"'entity_type'",
",",
"$",
"morphType",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelationQuery",
"(",
"$",
"query",
",",
"$",
"query",
"->",
"from",
")",
";",
"return",
"new",
"Collection",
"(",
"$",
"query",
"->",
"get",
"(",
")",
")",
";",
"}"
]
| Get the pivot table records for the roles already assigned.
@param \Illuminate\Suuport\Collection $roleIds
@param string $morphType
@param \Illuminate\Suuport\Collection $authorityIds
@return \Illuminate\Support\Collection | [
"Get",
"the",
"pivot",
"table",
"records",
"for",
"the",
"roles",
"already",
"assigned",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/AssignsRoles.php#L79-L89 | train |
JosephSilber/bouncer | src/Conductors/AssignsRoles.php | AssignsRoles.buildAttachRecords | protected function buildAttachRecords($roleIds, $morphType, $authorityIds)
{
return $roleIds->map(function ($roleId) use ($morphType, $authorityIds) {
return $authorityIds->map(function ($authorityId) use ($roleId, $morphType) {
return Models::scope()->getAttachAttributes() + [
'role_id' => $roleId,
'entity_id' => $authorityId,
'entity_type' => $morphType,
];
});
})->collapse();
} | php | protected function buildAttachRecords($roleIds, $morphType, $authorityIds)
{
return $roleIds->map(function ($roleId) use ($morphType, $authorityIds) {
return $authorityIds->map(function ($authorityId) use ($roleId, $morphType) {
return Models::scope()->getAttachAttributes() + [
'role_id' => $roleId,
'entity_id' => $authorityId,
'entity_type' => $morphType,
];
});
})->collapse();
} | [
"protected",
"function",
"buildAttachRecords",
"(",
"$",
"roleIds",
",",
"$",
"morphType",
",",
"$",
"authorityIds",
")",
"{",
"return",
"$",
"roleIds",
"->",
"map",
"(",
"function",
"(",
"$",
"roleId",
")",
"use",
"(",
"$",
"morphType",
",",
"$",
"authorityIds",
")",
"{",
"return",
"$",
"authorityIds",
"->",
"map",
"(",
"function",
"(",
"$",
"authorityId",
")",
"use",
"(",
"$",
"roleId",
",",
"$",
"morphType",
")",
"{",
"return",
"Models",
"::",
"scope",
"(",
")",
"->",
"getAttachAttributes",
"(",
")",
"+",
"[",
"'role_id'",
"=>",
"$",
"roleId",
",",
"'entity_id'",
"=>",
"$",
"authorityId",
",",
"'entity_type'",
"=>",
"$",
"morphType",
",",
"]",
";",
"}",
")",
";",
"}",
")",
"->",
"collapse",
"(",
")",
";",
"}"
]
| Build the raw attach records for the assigned roles pivot table.
@param \Illuminate\Suuport\Collection $roleIds
@param string $morphType
@param \Illuminate\Suuport\Collection $authorityIds
@return \Illuminate\Support\Collection | [
"Build",
"the",
"raw",
"attach",
"records",
"for",
"the",
"assigned",
"roles",
"pivot",
"table",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/AssignsRoles.php#L99-L110 | train |
JosephSilber/bouncer | src/Conductors/AssignsRoles.php | AssignsRoles.createMissingAssignRecords | protected function createMissingAssignRecords(Collection $records, Collection $existing)
{
$existing = $existing->keyBy(function ($record) {
return $this->getAttachRecordHash((array) $record);
});
$records = $records->reject(function ($record) use ($existing) {
return $existing->has($this->getAttachRecordHash($record));
});
$this->newPivotTableQuery()->insert($records->all());
} | php | protected function createMissingAssignRecords(Collection $records, Collection $existing)
{
$existing = $existing->keyBy(function ($record) {
return $this->getAttachRecordHash((array) $record);
});
$records = $records->reject(function ($record) use ($existing) {
return $existing->has($this->getAttachRecordHash($record));
});
$this->newPivotTableQuery()->insert($records->all());
} | [
"protected",
"function",
"createMissingAssignRecords",
"(",
"Collection",
"$",
"records",
",",
"Collection",
"$",
"existing",
")",
"{",
"$",
"existing",
"=",
"$",
"existing",
"->",
"keyBy",
"(",
"function",
"(",
"$",
"record",
")",
"{",
"return",
"$",
"this",
"->",
"getAttachRecordHash",
"(",
"(",
"array",
")",
"$",
"record",
")",
";",
"}",
")",
";",
"$",
"records",
"=",
"$",
"records",
"->",
"reject",
"(",
"function",
"(",
"$",
"record",
")",
"use",
"(",
"$",
"existing",
")",
"{",
"return",
"$",
"existing",
"->",
"has",
"(",
"$",
"this",
"->",
"getAttachRecordHash",
"(",
"$",
"record",
")",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"newPivotTableQuery",
"(",
")",
"->",
"insert",
"(",
"$",
"records",
"->",
"all",
"(",
")",
")",
";",
"}"
]
| Save the non-existing attach records in the DB.
@param \Illuminate\Support\Collection $records
@param \Illuminate\Support\Collection $existing
@return void | [
"Save",
"the",
"non",
"-",
"existing",
"attach",
"records",
"in",
"the",
"DB",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/AssignsRoles.php#L119-L130 | train |
JosephSilber/bouncer | src/Bouncer.php | Bouncer.setClipboard | public function setClipboard(Contracts\Clipboard $clipboard)
{
$this->guard->setClipboard($clipboard);
return $this->registerClipboardAtContainer();
} | php | public function setClipboard(Contracts\Clipboard $clipboard)
{
$this->guard->setClipboard($clipboard);
return $this->registerClipboardAtContainer();
} | [
"public",
"function",
"setClipboard",
"(",
"Contracts",
"\\",
"Clipboard",
"$",
"clipboard",
")",
"{",
"$",
"this",
"->",
"guard",
"->",
"setClipboard",
"(",
"$",
"clipboard",
")",
";",
"return",
"$",
"this",
"->",
"registerClipboardAtContainer",
"(",
")",
";",
"}"
]
| Set the clipboard instance used by bouncer.
Will also register the given clipboard with the container.
@param \Silber\Bouncer\Contracts\Clipboard
@return $this | [
"Set",
"the",
"clipboard",
"instance",
"used",
"by",
"bouncer",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Bouncer.php#L210-L215 | train |
JosephSilber/bouncer | src/Bouncer.php | Bouncer.registerClipboardAtContainer | public function registerClipboardAtContainer()
{
$clipboard = $this->guard->getClipboard();
Container::getInstance()->instance(Contracts\Clipboard::class, $clipboard);
return $this;
} | php | public function registerClipboardAtContainer()
{
$clipboard = $this->guard->getClipboard();
Container::getInstance()->instance(Contracts\Clipboard::class, $clipboard);
return $this;
} | [
"public",
"function",
"registerClipboardAtContainer",
"(",
")",
"{",
"$",
"clipboard",
"=",
"$",
"this",
"->",
"guard",
"->",
"getClipboard",
"(",
")",
";",
"Container",
"::",
"getInstance",
"(",
")",
"->",
"instance",
"(",
"Contracts",
"\\",
"Clipboard",
"::",
"class",
",",
"$",
"clipboard",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Register the guard's clipboard at the container.
@return $this | [
"Register",
"the",
"guard",
"s",
"clipboard",
"at",
"the",
"container",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Bouncer.php#L222-L229 | train |
JosephSilber/bouncer | src/Bouncer.php | Bouncer.cache | public function cache(Store $cache = null)
{
$cache = $cache ?: $this->resolve(CacheRepository::class)->getStore();
if ($this->usesCachedClipboard()) {
$this->guard->getClipboard()->setCache($cache);
return $this;
}
return $this->setClipboard(new CachedClipboard($cache));
} | php | public function cache(Store $cache = null)
{
$cache = $cache ?: $this->resolve(CacheRepository::class)->getStore();
if ($this->usesCachedClipboard()) {
$this->guard->getClipboard()->setCache($cache);
return $this;
}
return $this->setClipboard(new CachedClipboard($cache));
} | [
"public",
"function",
"cache",
"(",
"Store",
"$",
"cache",
"=",
"null",
")",
"{",
"$",
"cache",
"=",
"$",
"cache",
"?",
":",
"$",
"this",
"->",
"resolve",
"(",
"CacheRepository",
"::",
"class",
")",
"->",
"getStore",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"usesCachedClipboard",
"(",
")",
")",
"{",
"$",
"this",
"->",
"guard",
"->",
"getClipboard",
"(",
")",
"->",
"setCache",
"(",
"$",
"cache",
")",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"setClipboard",
"(",
"new",
"CachedClipboard",
"(",
"$",
"cache",
")",
")",
";",
"}"
]
| Use a cached clipboard with the given cache instance.
@param \Illuminate\Contracts\Cache\Store $cache
@return $this | [
"Use",
"a",
"cached",
"clipboard",
"with",
"the",
"given",
"cache",
"instance",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Bouncer.php#L237-L248 | train |
JosephSilber/bouncer | src/Database/Queries/Roles.php | Roles.constrainWhereIsAll | public function constrainWhereIsAll($query, $role)
{
$roles = array_slice(func_get_args(), 1);
return $query->whereHas('roles', function ($query) use ($roles) {
$query->whereIn('name', $roles);
}, '=', count($roles));
} | php | public function constrainWhereIsAll($query, $role)
{
$roles = array_slice(func_get_args(), 1);
return $query->whereHas('roles', function ($query) use ($roles) {
$query->whereIn('name', $roles);
}, '=', count($roles));
} | [
"public",
"function",
"constrainWhereIsAll",
"(",
"$",
"query",
",",
"$",
"role",
")",
"{",
"$",
"roles",
"=",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"1",
")",
";",
"return",
"$",
"query",
"->",
"whereHas",
"(",
"'roles'",
",",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"roles",
")",
"{",
"$",
"query",
"->",
"whereIn",
"(",
"'name'",
",",
"$",
"roles",
")",
";",
"}",
",",
"'='",
",",
"count",
"(",
"$",
"roles",
")",
")",
";",
"}"
]
| Constrain the given query by all provided roles.
@param \Illuminate\Database\Eloquent\Builder $query
@param string $role
@return \Illuminate\Database\Eloquent\Builder | [
"Constrain",
"the",
"given",
"query",
"by",
"all",
"provided",
"roles",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/Roles.php#L33-L40 | train |
JosephSilber/bouncer | src/Database/Queries/Roles.php | Roles.constrainWhereAssignedTo | public function constrainWhereAssignedTo($query, $model, array $keys = null)
{
list($model, $keys) = Helpers::extractModelAndKeys($model, $keys);
$query->whereExists(function ($query) use ($model, $keys) {
$table = $model->getTable();
$key = "{$table}.{$model->getKeyName()}";
$pivot = Models::table('assigned_roles');
$roles = Models::table('roles');
$prefix = Models::prefix();
$query->from($table)
->join($pivot, $key, '=', $pivot.'.entity_id')
->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
->where("{$pivot}.entity_type", $model->getMorphClass())
->whereIn($key, $keys);
Models::scope()->applyToModelQuery($query, $roles);
Models::scope()->applyToRelationQuery($query, $pivot);
});
} | php | public function constrainWhereAssignedTo($query, $model, array $keys = null)
{
list($model, $keys) = Helpers::extractModelAndKeys($model, $keys);
$query->whereExists(function ($query) use ($model, $keys) {
$table = $model->getTable();
$key = "{$table}.{$model->getKeyName()}";
$pivot = Models::table('assigned_roles');
$roles = Models::table('roles');
$prefix = Models::prefix();
$query->from($table)
->join($pivot, $key, '=', $pivot.'.entity_id')
->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
->where("{$pivot}.entity_type", $model->getMorphClass())
->whereIn($key, $keys);
Models::scope()->applyToModelQuery($query, $roles);
Models::scope()->applyToRelationQuery($query, $pivot);
});
} | [
"public",
"function",
"constrainWhereAssignedTo",
"(",
"$",
"query",
",",
"$",
"model",
",",
"array",
"$",
"keys",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"model",
",",
"$",
"keys",
")",
"=",
"Helpers",
"::",
"extractModelAndKeys",
"(",
"$",
"model",
",",
"$",
"keys",
")",
";",
"$",
"query",
"->",
"whereExists",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"model",
",",
"$",
"keys",
")",
"{",
"$",
"table",
"=",
"$",
"model",
"->",
"getTable",
"(",
")",
";",
"$",
"key",
"=",
"\"{$table}.{$model->getKeyName()}\"",
";",
"$",
"pivot",
"=",
"Models",
"::",
"table",
"(",
"'assigned_roles'",
")",
";",
"$",
"roles",
"=",
"Models",
"::",
"table",
"(",
"'roles'",
")",
";",
"$",
"prefix",
"=",
"Models",
"::",
"prefix",
"(",
")",
";",
"$",
"query",
"->",
"from",
"(",
"$",
"table",
")",
"->",
"join",
"(",
"$",
"pivot",
",",
"$",
"key",
",",
"'='",
",",
"$",
"pivot",
".",
"'.entity_id'",
")",
"->",
"whereRaw",
"(",
"\"{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id\"",
")",
"->",
"where",
"(",
"\"{$pivot}.entity_type\"",
",",
"$",
"model",
"->",
"getMorphClass",
"(",
")",
")",
"->",
"whereIn",
"(",
"$",
"key",
",",
"$",
"keys",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToModelQuery",
"(",
"$",
"query",
",",
"$",
"roles",
")",
";",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelationQuery",
"(",
"$",
"query",
",",
"$",
"pivot",
")",
";",
"}",
")",
";",
"}"
]
| Constrain the given roles query to those that were assigned to the given authorities.
@param \Illuminate\Database\Eloquent\Builder $query
@param string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection $model
@param array $keys
@return void | [
"Constrain",
"the",
"given",
"roles",
"query",
"to",
"those",
"that",
"were",
"assigned",
"to",
"the",
"given",
"authorities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/Roles.php#L66-L86 | train |
JosephSilber/bouncer | src/Database/Concerns/HasAbilities.php | HasAbilities.abilities | public function abilities()
{
$relation = $this->morphToMany(
Models::classname(Ability::class),
'entity',
Models::table('permissions')
)->withPivot('forbidden', 'scope');
return Models::scope()->applyToRelation($relation);
} | php | public function abilities()
{
$relation = $this->morphToMany(
Models::classname(Ability::class),
'entity',
Models::table('permissions')
)->withPivot('forbidden', 'scope');
return Models::scope()->applyToRelation($relation);
} | [
"public",
"function",
"abilities",
"(",
")",
"{",
"$",
"relation",
"=",
"$",
"this",
"->",
"morphToMany",
"(",
"Models",
"::",
"classname",
"(",
"Ability",
"::",
"class",
")",
",",
"'entity'",
",",
"Models",
"::",
"table",
"(",
"'permissions'",
")",
")",
"->",
"withPivot",
"(",
"'forbidden'",
",",
"'scope'",
")",
";",
"return",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelation",
"(",
"$",
"relation",
")",
";",
"}"
]
| The abilities relationship.
@return \Illuminate\Database\Eloquent\Relations\MorphToMany | [
"The",
"abilities",
"relationship",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasAbilities.php#L34-L43 | train |
JosephSilber/bouncer | src/Database/Concerns/HasAbilities.php | HasAbilities.allow | public function allow($ability = null, $model = null)
{
if (is_null($ability)) {
return new GivesAbilities($this);
}
(new GivesAbilities($this))->to($ability, $model);
return $this;
} | php | public function allow($ability = null, $model = null)
{
if (is_null($ability)) {
return new GivesAbilities($this);
}
(new GivesAbilities($this))->to($ability, $model);
return $this;
} | [
"public",
"function",
"allow",
"(",
"$",
"ability",
"=",
"null",
",",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"ability",
")",
")",
"{",
"return",
"new",
"GivesAbilities",
"(",
"$",
"this",
")",
";",
"}",
"(",
"new",
"GivesAbilities",
"(",
"$",
"this",
")",
")",
"->",
"to",
"(",
"$",
"ability",
",",
"$",
"model",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Give an ability to the model.
@param mixed $ability
@param mixed|null $model
@return \Silber\Bouncer\Conductors\GivesAbilities|$this | [
"Give",
"an",
"ability",
"to",
"the",
"model",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasAbilities.php#L72-L81 | train |
JosephSilber/bouncer | src/Database/Concerns/HasAbilities.php | HasAbilities.disallow | public function disallow($ability = null, $model = null)
{
if (is_null($ability)) {
return new RemovesAbilities($this);
}
(new RemovesAbilities($this))->to($ability, $model);
return $this;
} | php | public function disallow($ability = null, $model = null)
{
if (is_null($ability)) {
return new RemovesAbilities($this);
}
(new RemovesAbilities($this))->to($ability, $model);
return $this;
} | [
"public",
"function",
"disallow",
"(",
"$",
"ability",
"=",
"null",
",",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"ability",
")",
")",
"{",
"return",
"new",
"RemovesAbilities",
"(",
"$",
"this",
")",
";",
"}",
"(",
"new",
"RemovesAbilities",
"(",
"$",
"this",
")",
")",
"->",
"to",
"(",
"$",
"ability",
",",
"$",
"model",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Remove an ability from the model.
@param mixed $ability
@param mixed|null $model
@return \Silber\Bouncer\Conductors\RemovesAbilities|$this | [
"Remove",
"an",
"ability",
"from",
"the",
"model",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasAbilities.php#L90-L99 | train |
JosephSilber/bouncer | src/Database/Concerns/HasAbilities.php | HasAbilities.forbid | public function forbid($ability = null, $model = null)
{
if (is_null($ability)) {
return new ForbidsAbilities($this);
}
(new ForbidsAbilities($this))->to($ability, $model);
return $this;
} | php | public function forbid($ability = null, $model = null)
{
if (is_null($ability)) {
return new ForbidsAbilities($this);
}
(new ForbidsAbilities($this))->to($ability, $model);
return $this;
} | [
"public",
"function",
"forbid",
"(",
"$",
"ability",
"=",
"null",
",",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"ability",
")",
")",
"{",
"return",
"new",
"ForbidsAbilities",
"(",
"$",
"this",
")",
";",
"}",
"(",
"new",
"ForbidsAbilities",
"(",
"$",
"this",
")",
")",
"->",
"to",
"(",
"$",
"ability",
",",
"$",
"model",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Forbid an ability to the model.
@param mixed $ability
@param mixed|null $model
@return \Silber\Bouncer\Conductors\ForbidsAbilities|$this | [
"Forbid",
"an",
"ability",
"to",
"the",
"model",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasAbilities.php#L108-L117 | train |
JosephSilber/bouncer | src/Database/Concerns/HasAbilities.php | HasAbilities.unforbid | public function unforbid($ability = null, $model = null)
{
if (is_null($ability)) {
return new UnforbidsAbilities($this);
}
(new UnforbidsAbilities($this))->to($ability, $model);
return $this;
} | php | public function unforbid($ability = null, $model = null)
{
if (is_null($ability)) {
return new UnforbidsAbilities($this);
}
(new UnforbidsAbilities($this))->to($ability, $model);
return $this;
} | [
"public",
"function",
"unforbid",
"(",
"$",
"ability",
"=",
"null",
",",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"ability",
")",
")",
"{",
"return",
"new",
"UnforbidsAbilities",
"(",
"$",
"this",
")",
";",
"}",
"(",
"new",
"UnforbidsAbilities",
"(",
"$",
"this",
")",
")",
"->",
"to",
"(",
"$",
"ability",
",",
"$",
"model",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Remove ability forbiddal from the model.
@param mixed $ability
@param mixed|null $model
@return \Silber\Bouncer\Conductors\UnforbidsAbilities|$this | [
"Remove",
"ability",
"forbiddal",
"from",
"the",
"model",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasAbilities.php#L126-L135 | train |
JosephSilber/bouncer | src/Database/Titles/AbilityTitle.php | AbilityTitle.isGeneralManagementAbility | protected function isGeneralManagementAbility(Model $ability)
{
return $ability->name === '*'
&& $ability->entity_type !== '*'
&& ! is_null($ability->entity_type)
&& is_null($ability->entity_id);
} | php | protected function isGeneralManagementAbility(Model $ability)
{
return $ability->name === '*'
&& $ability->entity_type !== '*'
&& ! is_null($ability->entity_type)
&& is_null($ability->entity_id);
} | [
"protected",
"function",
"isGeneralManagementAbility",
"(",
"Model",
"$",
"ability",
")",
"{",
"return",
"$",
"ability",
"->",
"name",
"===",
"'*'",
"&&",
"$",
"ability",
"->",
"entity_type",
"!==",
"'*'",
"&&",
"!",
"is_null",
"(",
"$",
"ability",
"->",
"entity_type",
")",
"&&",
"is_null",
"(",
"$",
"ability",
"->",
"entity_id",
")",
";",
"}"
]
| Determines whether the given ability is for managing all models of a given type.
@param \Illuminate\Database\Eloquent\model $ability
@return bool | [
"Determines",
"whether",
"the",
"given",
"ability",
"is",
"for",
"managing",
"all",
"models",
"of",
"a",
"given",
"type",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Titles/AbilityTitle.php#L87-L93 | train |
JosephSilber/bouncer | src/Database/Titles/AbilityTitle.php | AbilityTitle.isBlanketModelAbility | protected function isBlanketModelAbility(Model $ability)
{
return $ability->name !== '*'
&& $ability->entity_type !== '*'
&& ! is_null($ability->entity_type)
&& is_null($ability->entity_id);
} | php | protected function isBlanketModelAbility(Model $ability)
{
return $ability->name !== '*'
&& $ability->entity_type !== '*'
&& ! is_null($ability->entity_type)
&& is_null($ability->entity_id);
} | [
"protected",
"function",
"isBlanketModelAbility",
"(",
"Model",
"$",
"ability",
")",
"{",
"return",
"$",
"ability",
"->",
"name",
"!==",
"'*'",
"&&",
"$",
"ability",
"->",
"entity_type",
"!==",
"'*'",
"&&",
"!",
"is_null",
"(",
"$",
"ability",
"->",
"entity_type",
")",
"&&",
"is_null",
"(",
"$",
"ability",
"->",
"entity_id",
")",
";",
"}"
]
| Determines whether the given ability is for an action on all models of a given type.
@param \Illuminate\Database\Eloquent\model $ability
@return bool | [
"Determines",
"whether",
"the",
"given",
"ability",
"is",
"for",
"an",
"action",
"on",
"all",
"models",
"of",
"a",
"given",
"type",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Titles/AbilityTitle.php#L101-L107 | train |
JosephSilber/bouncer | src/Database/Titles/AbilityTitle.php | AbilityTitle.isSpecificModelAbility | protected function isSpecificModelAbility(Model $ability)
{
return $ability->entity_type !== '*'
&& ! is_null($ability->entity_type)
&& ! is_null($ability->entity_id);
} | php | protected function isSpecificModelAbility(Model $ability)
{
return $ability->entity_type !== '*'
&& ! is_null($ability->entity_type)
&& ! is_null($ability->entity_id);
} | [
"protected",
"function",
"isSpecificModelAbility",
"(",
"Model",
"$",
"ability",
")",
"{",
"return",
"$",
"ability",
"->",
"entity_type",
"!==",
"'*'",
"&&",
"!",
"is_null",
"(",
"$",
"ability",
"->",
"entity_type",
")",
"&&",
"!",
"is_null",
"(",
"$",
"ability",
"->",
"entity_id",
")",
";",
"}"
]
| Determines whether the given ability is for an action on a specific model.
@param \Illuminate\Database\Eloquent\model $ability
@return bool | [
"Determines",
"whether",
"the",
"given",
"ability",
"is",
"for",
"an",
"action",
"on",
"a",
"specific",
"model",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Titles/AbilityTitle.php#L115-L120 | train |
JosephSilber/bouncer | src/Database/Titles/AbilityTitle.php | AbilityTitle.isGlobalActionAbility | protected function isGlobalActionAbility(Model $ability)
{
return $ability->name !== '*'
&& $ability->entity_type === '*'
&& is_null($ability->entity_id);
} | php | protected function isGlobalActionAbility(Model $ability)
{
return $ability->name !== '*'
&& $ability->entity_type === '*'
&& is_null($ability->entity_id);
} | [
"protected",
"function",
"isGlobalActionAbility",
"(",
"Model",
"$",
"ability",
")",
"{",
"return",
"$",
"ability",
"->",
"name",
"!==",
"'*'",
"&&",
"$",
"ability",
"->",
"entity_type",
"===",
"'*'",
"&&",
"is_null",
"(",
"$",
"ability",
"->",
"entity_id",
")",
";",
"}"
]
| Determines whether the given ability allows an action on all models.
@param \Illuminate\Database\Eloquent\model $ability
@return bool | [
"Determines",
"whether",
"the",
"given",
"ability",
"allows",
"an",
"action",
"on",
"all",
"models",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Titles/AbilityTitle.php#L128-L133 | train |
JosephSilber/bouncer | src/Database/Titles/AbilityTitle.php | AbilityTitle.getBlanketModelAbilityTitle | protected function getBlanketModelAbilityTitle(Model $ability, $name = 'manage')
{
return $this->humanize($name.' '.$this->getPluralName($ability->entity_type));
} | php | protected function getBlanketModelAbilityTitle(Model $ability, $name = 'manage')
{
return $this->humanize($name.' '.$this->getPluralName($ability->entity_type));
} | [
"protected",
"function",
"getBlanketModelAbilityTitle",
"(",
"Model",
"$",
"ability",
",",
"$",
"name",
"=",
"'manage'",
")",
"{",
"return",
"$",
"this",
"->",
"humanize",
"(",
"$",
"name",
".",
"' '",
".",
"$",
"this",
"->",
"getPluralName",
"(",
"$",
"ability",
"->",
"entity_type",
")",
")",
";",
"}"
]
| Get the title for the given blanket model ability.
@param \Illuminate\Database\Eloquent\model $ability
@param string $name
@return string | [
"Get",
"the",
"title",
"for",
"the",
"given",
"blanket",
"model",
"ability",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Titles/AbilityTitle.php#L157-L160 | train |
JosephSilber/bouncer | src/Database/Titles/AbilityTitle.php | AbilityTitle.getSpecificModelAbilityTitle | protected function getSpecificModelAbilityTitle(Model $ability)
{
$name = $ability->name === '*' ? 'manage' : $ability->name;
return $this->humanize(
$name.' '.$this->basename($ability->entity_type).' #'.$ability->entity_id
);
} | php | protected function getSpecificModelAbilityTitle(Model $ability)
{
$name = $ability->name === '*' ? 'manage' : $ability->name;
return $this->humanize(
$name.' '.$this->basename($ability->entity_type).' #'.$ability->entity_id
);
} | [
"protected",
"function",
"getSpecificModelAbilityTitle",
"(",
"Model",
"$",
"ability",
")",
"{",
"$",
"name",
"=",
"$",
"ability",
"->",
"name",
"===",
"'*'",
"?",
"'manage'",
":",
"$",
"ability",
"->",
"name",
";",
"return",
"$",
"this",
"->",
"humanize",
"(",
"$",
"name",
".",
"' '",
".",
"$",
"this",
"->",
"basename",
"(",
"$",
"ability",
"->",
"entity_type",
")",
".",
"' #'",
".",
"$",
"ability",
"->",
"entity_id",
")",
";",
"}"
]
| Get the title for the given model ability.
@param \Illuminate\Database\Eloquent\model $ability
@return string | [
"Get",
"the",
"title",
"for",
"the",
"given",
"model",
"ability",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Titles/AbilityTitle.php#L168-L175 | train |
JosephSilber/bouncer | src/Constraints/Group.php | Group.fromData | public static function fromData(array $data)
{
$group = new static(array_map(function ($data) {
return $data['class']::fromData($data['params']);
}, $data['constraints']));
return $group->logicalOperator($data['logicalOperator']);
} | php | public static function fromData(array $data)
{
$group = new static(array_map(function ($data) {
return $data['class']::fromData($data['params']);
}, $data['constraints']));
return $group->logicalOperator($data['logicalOperator']);
} | [
"public",
"static",
"function",
"fromData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"group",
"=",
"new",
"static",
"(",
"array_map",
"(",
"function",
"(",
"$",
"data",
")",
"{",
"return",
"$",
"data",
"[",
"'class'",
"]",
"::",
"fromData",
"(",
"$",
"data",
"[",
"'params'",
"]",
")",
";",
"}",
",",
"$",
"data",
"[",
"'constraints'",
"]",
")",
")",
";",
"return",
"$",
"group",
"->",
"logicalOperator",
"(",
"$",
"data",
"[",
"'logicalOperator'",
"]",
")",
";",
"}"
]
| Create a new instance from the raw data.
@param array $data
@return static | [
"Create",
"a",
"new",
"instance",
"from",
"the",
"raw",
"data",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Group.php#L61-L68 | train |
JosephSilber/bouncer | src/Constraints/Group.php | Group.equals | public function equals(Constrainer $constrainer)
{
if (! $constrainer instanceof static) {
return false;
}
if ($this->constraints->count() != $constrainer->constraints->count()) {
return false;
}
foreach ($this->constraints as $index => $constraint) {
if (! $constrainer->constraints[$index]->equals($constraint)) {
return false;
}
}
return true;
} | php | public function equals(Constrainer $constrainer)
{
if (! $constrainer instanceof static) {
return false;
}
if ($this->constraints->count() != $constrainer->constraints->count()) {
return false;
}
foreach ($this->constraints as $index => $constraint) {
if (! $constrainer->constraints[$index]->equals($constraint)) {
return false;
}
}
return true;
} | [
"public",
"function",
"equals",
"(",
"Constrainer",
"$",
"constrainer",
")",
"{",
"if",
"(",
"!",
"$",
"constrainer",
"instanceof",
"static",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"constraints",
"->",
"count",
"(",
")",
"!=",
"$",
"constrainer",
"->",
"constraints",
"->",
"count",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"constraints",
"as",
"$",
"index",
"=>",
"$",
"constraint",
")",
"{",
"if",
"(",
"!",
"$",
"constrainer",
"->",
"constraints",
"[",
"$",
"index",
"]",
"->",
"equals",
"(",
"$",
"constraint",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Determine whether the given constrainer is equal to this object.
@param \Silber\Bouncer\Constraints\Constrainer $constrainer
@return bool | [
"Determine",
"whether",
"the",
"given",
"constrainer",
"is",
"equal",
"to",
"this",
"object",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Group.php#L151-L168 | train |
JosephSilber/bouncer | src/Constraints/Group.php | Group.data | public function data()
{
return [
'class' => static::class,
'params' => [
'logicalOperator' => $this->logicalOperator,
'constraints' => $this->constraints->map(function ($constraint) {
return $constraint->data();
})->all(),
],
];
} | php | public function data()
{
return [
'class' => static::class,
'params' => [
'logicalOperator' => $this->logicalOperator,
'constraints' => $this->constraints->map(function ($constraint) {
return $constraint->data();
})->all(),
],
];
} | [
"public",
"function",
"data",
"(",
")",
"{",
"return",
"[",
"'class'",
"=>",
"static",
"::",
"class",
",",
"'params'",
"=>",
"[",
"'logicalOperator'",
"=>",
"$",
"this",
"->",
"logicalOperator",
",",
"'constraints'",
"=>",
"$",
"this",
"->",
"constraints",
"->",
"map",
"(",
"function",
"(",
"$",
"constraint",
")",
"{",
"return",
"$",
"constraint",
"->",
"data",
"(",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
",",
"]",
",",
"]",
";",
"}"
]
| Get the JSON-able data of this object.
@return array | [
"Get",
"the",
"JSON",
"-",
"able",
"data",
"of",
"this",
"object",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Group.php#L175-L186 | train |
JosephSilber/bouncer | src/BaseClipboard.php | BaseClipboard.check | public function check(Model $authority, $ability, $model = null)
{
return (bool) $this->checkGetId($authority, $ability, $model);
} | php | public function check(Model $authority, $ability, $model = null)
{
return (bool) $this->checkGetId($authority, $ability, $model);
} | [
"public",
"function",
"check",
"(",
"Model",
"$",
"authority",
",",
"$",
"ability",
",",
"$",
"model",
"=",
"null",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"checkGetId",
"(",
"$",
"authority",
",",
"$",
"ability",
",",
"$",
"model",
")",
";",
"}"
]
| Determine if the given authority has the given ability.
@param \Illuminate\Database\Eloquent\Model $authority
@param string $ability
@param \Illuminate\Database\Eloquent\Model|string|null $model
@return bool | [
"Determine",
"if",
"the",
"given",
"authority",
"has",
"the",
"given",
"ability",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/BaseClipboard.php#L22-L25 | train |
JosephSilber/bouncer | src/BaseClipboard.php | BaseClipboard.checkRole | public function checkRole(Model $authority, $roles, $boolean = 'or')
{
$count = $this->countMatchingRoles($authority, $roles);
if ($boolean == 'or') {
return $count > 0;
} elseif ($boolean === 'not') {
return $count === 0;
}
return $count == count((array) $roles);
} | php | public function checkRole(Model $authority, $roles, $boolean = 'or')
{
$count = $this->countMatchingRoles($authority, $roles);
if ($boolean == 'or') {
return $count > 0;
} elseif ($boolean === 'not') {
return $count === 0;
}
return $count == count((array) $roles);
} | [
"public",
"function",
"checkRole",
"(",
"Model",
"$",
"authority",
",",
"$",
"roles",
",",
"$",
"boolean",
"=",
"'or'",
")",
"{",
"$",
"count",
"=",
"$",
"this",
"->",
"countMatchingRoles",
"(",
"$",
"authority",
",",
"$",
"roles",
")",
";",
"if",
"(",
"$",
"boolean",
"==",
"'or'",
")",
"{",
"return",
"$",
"count",
">",
"0",
";",
"}",
"elseif",
"(",
"$",
"boolean",
"===",
"'not'",
")",
"{",
"return",
"$",
"count",
"===",
"0",
";",
"}",
"return",
"$",
"count",
"==",
"count",
"(",
"(",
"array",
")",
"$",
"roles",
")",
";",
"}"
]
| Check if an authority has the given roles.
@param \Illuminate\Database\Eloquent\Model $authority
@param array|string $roles
@param string $boolean
@return bool | [
"Check",
"if",
"an",
"authority",
"has",
"the",
"given",
"roles",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/BaseClipboard.php#L35-L46 | train |
JosephSilber/bouncer | src/BaseClipboard.php | BaseClipboard.countMatchingRoles | protected function countMatchingRoles($authority, $roles)
{
$lookups = $this->getRolesLookup($authority);
return count(array_filter($roles, function ($role) use ($lookups) {
switch (true) {
case is_string($role):
return $lookups['names']->has($role);
case is_numeric($role):
return $lookups['ids']->has($role);
case $role instanceof Model:
return $lookups['ids']->has($role->getKey());
}
throw new InvalidArgumentException('Invalid model identifier');
}));
} | php | protected function countMatchingRoles($authority, $roles)
{
$lookups = $this->getRolesLookup($authority);
return count(array_filter($roles, function ($role) use ($lookups) {
switch (true) {
case is_string($role):
return $lookups['names']->has($role);
case is_numeric($role):
return $lookups['ids']->has($role);
case $role instanceof Model:
return $lookups['ids']->has($role->getKey());
}
throw new InvalidArgumentException('Invalid model identifier');
}));
} | [
"protected",
"function",
"countMatchingRoles",
"(",
"$",
"authority",
",",
"$",
"roles",
")",
"{",
"$",
"lookups",
"=",
"$",
"this",
"->",
"getRolesLookup",
"(",
"$",
"authority",
")",
";",
"return",
"count",
"(",
"array_filter",
"(",
"$",
"roles",
",",
"function",
"(",
"$",
"role",
")",
"use",
"(",
"$",
"lookups",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"is_string",
"(",
"$",
"role",
")",
":",
"return",
"$",
"lookups",
"[",
"'names'",
"]",
"->",
"has",
"(",
"$",
"role",
")",
";",
"case",
"is_numeric",
"(",
"$",
"role",
")",
":",
"return",
"$",
"lookups",
"[",
"'ids'",
"]",
"->",
"has",
"(",
"$",
"role",
")",
";",
"case",
"$",
"role",
"instanceof",
"Model",
":",
"return",
"$",
"lookups",
"[",
"'ids'",
"]",
"->",
"has",
"(",
"$",
"role",
"->",
"getKey",
"(",
")",
")",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid model identifier'",
")",
";",
"}",
")",
")",
";",
"}"
]
| Count the authority's roles matching the given roles.
@param \Illuminate\Database\Eloquent\Model $authority
@param array|string $roles
@return int | [
"Count",
"the",
"authority",
"s",
"roles",
"matching",
"the",
"given",
"roles",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/BaseClipboard.php#L55-L71 | train |
JosephSilber/bouncer | src/BaseClipboard.php | BaseClipboard.getAbilities | public function getAbilities(Model $authority, $allowed = true)
{
return Abilities::forAuthority($authority, $allowed)->get();
} | php | public function getAbilities(Model $authority, $allowed = true)
{
return Abilities::forAuthority($authority, $allowed)->get();
} | [
"public",
"function",
"getAbilities",
"(",
"Model",
"$",
"authority",
",",
"$",
"allowed",
"=",
"true",
")",
"{",
"return",
"Abilities",
"::",
"forAuthority",
"(",
"$",
"authority",
",",
"$",
"allowed",
")",
"->",
"get",
"(",
")",
";",
"}"
]
| Get a list of the authority's abilities.
@param \Illuminate\Database\Eloquent\Model $authority
@param bool $allowed
@return \Illuminate\Database\Eloquent\Collection | [
"Get",
"a",
"list",
"of",
"the",
"authority",
"s",
"abilities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/BaseClipboard.php#L113-L116 | train |
JosephSilber/bouncer | src/Database/Concerns/Authorizable.php | Authorizable.can | public function can($ability, $model = null)
{
return $this->getClipboardInstance()->check($this, $ability, $model);
} | php | public function can($ability, $model = null)
{
return $this->getClipboardInstance()->check($this, $ability, $model);
} | [
"public",
"function",
"can",
"(",
"$",
"ability",
",",
"$",
"model",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getClipboardInstance",
"(",
")",
"->",
"check",
"(",
"$",
"this",
",",
"$",
"ability",
",",
"$",
"model",
")",
";",
"}"
]
| Determine if the authority has a given ability.
@param string $ability
@param \Illuminate\Database\Eloquent\Model|null $model
@return bool | [
"Determine",
"if",
"the",
"authority",
"has",
"a",
"given",
"ability",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/Authorizable.php#L17-L20 | train |
JosephSilber/bouncer | src/Guard.php | Guard.slot | public function slot($slot = null)
{
if (is_null($slot)) {
return $this->slot;
}
if (! in_array($slot, ['before', 'after'])) {
throw new InvalidArgumentException(
"{$slot} is an invalid gate slot"
);
}
$this->slot = $slot;
return $this;
} | php | public function slot($slot = null)
{
if (is_null($slot)) {
return $this->slot;
}
if (! in_array($slot, ['before', 'after'])) {
throw new InvalidArgumentException(
"{$slot} is an invalid gate slot"
);
}
$this->slot = $slot;
return $this;
} | [
"public",
"function",
"slot",
"(",
"$",
"slot",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"slot",
")",
")",
"{",
"return",
"$",
"this",
"->",
"slot",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"slot",
",",
"[",
"'before'",
",",
"'after'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"{$slot} is an invalid gate slot\"",
")",
";",
"}",
"$",
"this",
"->",
"slot",
"=",
"$",
"slot",
";",
"return",
"$",
"this",
";",
"}"
]
| Set or get which slot to run the clipboard's checks.
@param string|null $slot
@return $this|string | [
"Set",
"or",
"get",
"which",
"slot",
"to",
"run",
"the",
"clipboard",
"s",
"checks",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Guard.php#L79-L94 | train |
JosephSilber/bouncer | src/Guard.php | Guard.registerAt | public function registerAt(Gate $gate)
{
$gate->before(function () {
return call_user_func_array([
$this, 'runBeforeCallback'
], func_get_args());
});
$gate->after(function () {
return call_user_func_array([
$this, 'runAfterCallback'
], func_get_args());
});
return $this;
} | php | public function registerAt(Gate $gate)
{
$gate->before(function () {
return call_user_func_array([
$this, 'runBeforeCallback'
], func_get_args());
});
$gate->after(function () {
return call_user_func_array([
$this, 'runAfterCallback'
], func_get_args());
});
return $this;
} | [
"public",
"function",
"registerAt",
"(",
"Gate",
"$",
"gate",
")",
"{",
"$",
"gate",
"->",
"before",
"(",
"function",
"(",
")",
"{",
"return",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'runBeforeCallback'",
"]",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
")",
";",
"$",
"gate",
"->",
"after",
"(",
"function",
"(",
")",
"{",
"return",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'runAfterCallback'",
"]",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Register the clipboard at the given gate.
@param \Illuminate\Contracts\Auth\Access\Gate $gate
@return $this | [
"Register",
"the",
"clipboard",
"at",
"the",
"given",
"gate",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Guard.php#L102-L117 | train |
JosephSilber/bouncer | src/Guard.php | Guard.parseGateBeforeArguments | protected function parseGateBeforeArguments($arguments, $additional)
{
// The way arguments are passed into the gate's before callback has changed in Laravel
// in the middle of the 5.2 release. Before, arguments were spread out. Now they're
// all supplied in a single array instead. We will normalize it into two values.
if (! is_null($additional)) {
return [$arguments, $additional];
}
if (is_array($arguments)) {
return [
isset($arguments[0]) ? $arguments[0] : null,
isset($arguments[1]) ? $arguments[1] : null,
];
}
return [$arguments, null];
} | php | protected function parseGateBeforeArguments($arguments, $additional)
{
// The way arguments are passed into the gate's before callback has changed in Laravel
// in the middle of the 5.2 release. Before, arguments were spread out. Now they're
// all supplied in a single array instead. We will normalize it into two values.
if (! is_null($additional)) {
return [$arguments, $additional];
}
if (is_array($arguments)) {
return [
isset($arguments[0]) ? $arguments[0] : null,
isset($arguments[1]) ? $arguments[1] : null,
];
}
return [$arguments, null];
} | [
"protected",
"function",
"parseGateBeforeArguments",
"(",
"$",
"arguments",
",",
"$",
"additional",
")",
"{",
"// The way arguments are passed into the gate's before callback has changed in Laravel",
"// in the middle of the 5.2 release. Before, arguments were spread out. Now they're",
"// all supplied in a single array instead. We will normalize it into two values.",
"if",
"(",
"!",
"is_null",
"(",
"$",
"additional",
")",
")",
"{",
"return",
"[",
"$",
"arguments",
",",
"$",
"additional",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"arguments",
")",
")",
"{",
"return",
"[",
"isset",
"(",
"$",
"arguments",
"[",
"0",
"]",
")",
"?",
"$",
"arguments",
"[",
"0",
"]",
":",
"null",
",",
"isset",
"(",
"$",
"arguments",
"[",
"1",
"]",
")",
"?",
"$",
"arguments",
"[",
"1",
"]",
":",
"null",
",",
"]",
";",
"}",
"return",
"[",
"$",
"arguments",
",",
"null",
"]",
";",
"}"
]
| Parse the arguments we got from the gate.
@param mixed $arguments
@param mixed $additional
@return array | [
"Parse",
"the",
"arguments",
"we",
"got",
"from",
"the",
"gate",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Guard.php#L180-L197 | train |
JosephSilber/bouncer | src/Guard.php | Guard.checkAtClipboard | protected function checkAtClipboard(Model $authority, $ability, $model)
{
if ($id = $this->clipboard->checkGetId($authority, $ability, $model)) {
return $this->allow('Bouncer granted permission via ability #'.$id);
}
// If the response from "checkGetId" is "false", then this ability
// has been explicity forbidden. We'll return false so the gate
// doesn't run any further checks. Otherwise we return null.
return $id;
} | php | protected function checkAtClipboard(Model $authority, $ability, $model)
{
if ($id = $this->clipboard->checkGetId($authority, $ability, $model)) {
return $this->allow('Bouncer granted permission via ability #'.$id);
}
// If the response from "checkGetId" is "false", then this ability
// has been explicity forbidden. We'll return false so the gate
// doesn't run any further checks. Otherwise we return null.
return $id;
} | [
"protected",
"function",
"checkAtClipboard",
"(",
"Model",
"$",
"authority",
",",
"$",
"ability",
",",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"clipboard",
"->",
"checkGetId",
"(",
"$",
"authority",
",",
"$",
"ability",
",",
"$",
"model",
")",
")",
"{",
"return",
"$",
"this",
"->",
"allow",
"(",
"'Bouncer granted permission via ability #'",
".",
"$",
"id",
")",
";",
"}",
"// If the response from \"checkGetId\" is \"false\", then this ability",
"// has been explicity forbidden. We'll return false so the gate",
"// doesn't run any further checks. Otherwise we return null.",
"return",
"$",
"id",
";",
"}"
]
| Run an auth check at the clipboard.
@param \Illuminate\Database\Eloquent\Model $authority
@param string $ability
@param \Illuminate\Database\Eloquent\Model|string|null $model
@return mixed | [
"Run",
"an",
"auth",
"check",
"at",
"the",
"clipboard",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Guard.php#L207-L217 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.bootIsRole | public static function bootIsRole()
{
BaseTenantScope::register(static::class);
static::creating(function ($role) {
Models::scope()->applyToModel($role);
if (is_null($role->title)) {
$role->title = RoleTitle::from($role)->toString();
}
});
static::deleted(function ($role) {
$role->abilities()->detach();
});
} | php | public static function bootIsRole()
{
BaseTenantScope::register(static::class);
static::creating(function ($role) {
Models::scope()->applyToModel($role);
if (is_null($role->title)) {
$role->title = RoleTitle::from($role)->toString();
}
});
static::deleted(function ($role) {
$role->abilities()->detach();
});
} | [
"public",
"static",
"function",
"bootIsRole",
"(",
")",
"{",
"BaseTenantScope",
"::",
"register",
"(",
"static",
"::",
"class",
")",
";",
"static",
"::",
"creating",
"(",
"function",
"(",
"$",
"role",
")",
"{",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToModel",
"(",
"$",
"role",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"role",
"->",
"title",
")",
")",
"{",
"$",
"role",
"->",
"title",
"=",
"RoleTitle",
"::",
"from",
"(",
"$",
"role",
")",
"->",
"toString",
"(",
")",
";",
"}",
"}",
")",
";",
"static",
"::",
"deleted",
"(",
"function",
"(",
"$",
"role",
")",
"{",
"$",
"role",
"->",
"abilities",
"(",
")",
"->",
"detach",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Boot the is role trait.
@return void | [
"Boot",
"the",
"is",
"role",
"trait",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L28-L43 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.users | public function users()
{
$relation = $this->morphedByMany(
Models::classname(User::class),
'entity',
Models::table('assigned_roles')
)->withPivot('scope');
return Models::scope()->applyToRelation($relation);
} | php | public function users()
{
$relation = $this->morphedByMany(
Models::classname(User::class),
'entity',
Models::table('assigned_roles')
)->withPivot('scope');
return Models::scope()->applyToRelation($relation);
} | [
"public",
"function",
"users",
"(",
")",
"{",
"$",
"relation",
"=",
"$",
"this",
"->",
"morphedByMany",
"(",
"Models",
"::",
"classname",
"(",
"User",
"::",
"class",
")",
",",
"'entity'",
",",
"Models",
"::",
"table",
"(",
"'assigned_roles'",
")",
")",
"->",
"withPivot",
"(",
"'scope'",
")",
";",
"return",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToRelation",
"(",
"$",
"relation",
")",
";",
"}"
]
| The users relationship.
@return \Illuminate\Database\Eloquent\Relations\MorphedByMany | [
"The",
"users",
"relationship",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L50-L59 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.findOrCreateRoles | public function findOrCreateRoles($roles)
{
$roles = Helpers::groupModelsAndIdentifiersByType($roles);
$roles['integers'] = $this->find($roles['integers']);
$roles['strings'] = $this->findOrCreateRolesByName($roles['strings']);
return $this->newCollection(Arr::collapse($roles));
} | php | public function findOrCreateRoles($roles)
{
$roles = Helpers::groupModelsAndIdentifiersByType($roles);
$roles['integers'] = $this->find($roles['integers']);
$roles['strings'] = $this->findOrCreateRolesByName($roles['strings']);
return $this->newCollection(Arr::collapse($roles));
} | [
"public",
"function",
"findOrCreateRoles",
"(",
"$",
"roles",
")",
"{",
"$",
"roles",
"=",
"Helpers",
"::",
"groupModelsAndIdentifiersByType",
"(",
"$",
"roles",
")",
";",
"$",
"roles",
"[",
"'integers'",
"]",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"roles",
"[",
"'integers'",
"]",
")",
";",
"$",
"roles",
"[",
"'strings'",
"]",
"=",
"$",
"this",
"->",
"findOrCreateRolesByName",
"(",
"$",
"roles",
"[",
"'strings'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"newCollection",
"(",
"Arr",
"::",
"collapse",
"(",
"$",
"roles",
")",
")",
";",
"}"
]
| Find the given roles, creating the names that don't exist yet.
@param iterable $roles
@return \Illuminate\Database\Eloquent\Collection | [
"Find",
"the",
"given",
"roles",
"creating",
"the",
"names",
"that",
"don",
"t",
"exist",
"yet",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L85-L94 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.findOrCreateRolesByName | protected function findOrCreateRolesByName($names)
{
if (empty($names)) {
return [];
}
$existing = static::whereIn('name', $names)->get()->keyBy('name');
return (new Collection($names))
->diff($existing->pluck('name'))
->map(function ($name) {
return static::create(compact('name'));
})
->merge($existing);
} | php | protected function findOrCreateRolesByName($names)
{
if (empty($names)) {
return [];
}
$existing = static::whereIn('name', $names)->get()->keyBy('name');
return (new Collection($names))
->diff($existing->pluck('name'))
->map(function ($name) {
return static::create(compact('name'));
})
->merge($existing);
} | [
"protected",
"function",
"findOrCreateRolesByName",
"(",
"$",
"names",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"names",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"existing",
"=",
"static",
"::",
"whereIn",
"(",
"'name'",
",",
"$",
"names",
")",
"->",
"get",
"(",
")",
"->",
"keyBy",
"(",
"'name'",
")",
";",
"return",
"(",
"new",
"Collection",
"(",
"$",
"names",
")",
")",
"->",
"diff",
"(",
"$",
"existing",
"->",
"pluck",
"(",
"'name'",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"name",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"compact",
"(",
"'name'",
")",
")",
";",
"}",
")",
"->",
"merge",
"(",
"$",
"existing",
")",
";",
"}"
]
| Find roles by name, creating the ones that don't exist.
@param iterable $names
@return \Illuminate\Database\Eloquent\Collection | [
"Find",
"roles",
"by",
"name",
"creating",
"the",
"ones",
"that",
"don",
"t",
"exist",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L102-L116 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.getRoleKeys | public function getRoleKeys($roles)
{
$roles = Helpers::groupModelsAndIdentifiersByType($roles);
$roles['strings'] = $this->getKeysByName($roles['strings']);
$roles['models'] = Arr::pluck($roles['models'], $this->getKeyName());
return Arr::collapse($roles);
} | php | public function getRoleKeys($roles)
{
$roles = Helpers::groupModelsAndIdentifiersByType($roles);
$roles['strings'] = $this->getKeysByName($roles['strings']);
$roles['models'] = Arr::pluck($roles['models'], $this->getKeyName());
return Arr::collapse($roles);
} | [
"public",
"function",
"getRoleKeys",
"(",
"$",
"roles",
")",
"{",
"$",
"roles",
"=",
"Helpers",
"::",
"groupModelsAndIdentifiersByType",
"(",
"$",
"roles",
")",
";",
"$",
"roles",
"[",
"'strings'",
"]",
"=",
"$",
"this",
"->",
"getKeysByName",
"(",
"$",
"roles",
"[",
"'strings'",
"]",
")",
";",
"$",
"roles",
"[",
"'models'",
"]",
"=",
"Arr",
"::",
"pluck",
"(",
"$",
"roles",
"[",
"'models'",
"]",
",",
"$",
"this",
"->",
"getKeyName",
"(",
")",
")",
";",
"return",
"Arr",
"::",
"collapse",
"(",
"$",
"roles",
")",
";",
"}"
]
| Get the IDs of the given roles.
@param iterable $roles
@return array | [
"Get",
"the",
"IDs",
"of",
"the",
"given",
"roles",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L124-L133 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.getRoleNames | public function getRoleNames($roles)
{
$roles = Helpers::groupModelsAndIdentifiersByType($roles);
$roles['integers'] = $this->getNamesByKey($roles['integers']);
$roles['models'] = Arr::pluck($roles['models'], 'name');
return Arr::collapse($roles);
} | php | public function getRoleNames($roles)
{
$roles = Helpers::groupModelsAndIdentifiersByType($roles);
$roles['integers'] = $this->getNamesByKey($roles['integers']);
$roles['models'] = Arr::pluck($roles['models'], 'name');
return Arr::collapse($roles);
} | [
"public",
"function",
"getRoleNames",
"(",
"$",
"roles",
")",
"{",
"$",
"roles",
"=",
"Helpers",
"::",
"groupModelsAndIdentifiersByType",
"(",
"$",
"roles",
")",
";",
"$",
"roles",
"[",
"'integers'",
"]",
"=",
"$",
"this",
"->",
"getNamesByKey",
"(",
"$",
"roles",
"[",
"'integers'",
"]",
")",
";",
"$",
"roles",
"[",
"'models'",
"]",
"=",
"Arr",
"::",
"pluck",
"(",
"$",
"roles",
"[",
"'models'",
"]",
",",
"'name'",
")",
";",
"return",
"Arr",
"::",
"collapse",
"(",
"$",
"roles",
")",
";",
"}"
]
| Get the names of the given roles.
@param iterable $roles
@return array | [
"Get",
"the",
"names",
"of",
"the",
"given",
"roles",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L141-L150 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.getKeysByName | public function getKeysByName($names)
{
if (empty($names)) {
return [];
}
return $this->whereIn('name', $names)
->select($this->getKeyName())->get()
->pluck($this->getKeyName())->all();
} | php | public function getKeysByName($names)
{
if (empty($names)) {
return [];
}
return $this->whereIn('name', $names)
->select($this->getKeyName())->get()
->pluck($this->getKeyName())->all();
} | [
"public",
"function",
"getKeysByName",
"(",
"$",
"names",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"names",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"whereIn",
"(",
"'name'",
",",
"$",
"names",
")",
"->",
"select",
"(",
"$",
"this",
"->",
"getKeyName",
"(",
")",
")",
"->",
"get",
"(",
")",
"->",
"pluck",
"(",
"$",
"this",
"->",
"getKeyName",
"(",
")",
")",
"->",
"all",
"(",
")",
";",
"}"
]
| Get the keys of the roles with the given names.
@param iterable $names
@return array | [
"Get",
"the",
"keys",
"of",
"the",
"roles",
"with",
"the",
"given",
"names",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L158-L167 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.getNamesByKey | public function getNamesByKey($keys)
{
if (empty($keys)) {
return [];
}
return $this->whereIn($this->getKeyName(), $keys)
->select('name')->get()
->pluck('name')->all();
} | php | public function getNamesByKey($keys)
{
if (empty($keys)) {
return [];
}
return $this->whereIn($this->getKeyName(), $keys)
->select('name')->get()
->pluck('name')->all();
} | [
"public",
"function",
"getNamesByKey",
"(",
"$",
"keys",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"keys",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"whereIn",
"(",
"$",
"this",
"->",
"getKeyName",
"(",
")",
",",
"$",
"keys",
")",
"->",
"select",
"(",
"'name'",
")",
"->",
"get",
"(",
")",
"->",
"pluck",
"(",
"'name'",
")",
"->",
"all",
"(",
")",
";",
"}"
]
| Get the names of the roles with the given IDs.
@param iterable $keys
@return array | [
"Get",
"the",
"names",
"of",
"the",
"roles",
"with",
"the",
"given",
"IDs",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L175-L184 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.createAssignRecords | protected function createAssignRecords(Model $model, array $keys)
{
$type = $model->getMorphClass();
return array_map(function ($key) use ($type) {
return Models::scope()->getAttachAttributes() + [
'role_id' => $this->getKey(),
'entity_type' => $type,
'entity_id' => $key,
];
}, $keys);
} | php | protected function createAssignRecords(Model $model, array $keys)
{
$type = $model->getMorphClass();
return array_map(function ($key) use ($type) {
return Models::scope()->getAttachAttributes() + [
'role_id' => $this->getKey(),
'entity_type' => $type,
'entity_id' => $key,
];
}, $keys);
} | [
"protected",
"function",
"createAssignRecords",
"(",
"Model",
"$",
"model",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"type",
"=",
"$",
"model",
"->",
"getMorphClass",
"(",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"key",
")",
"use",
"(",
"$",
"type",
")",
"{",
"return",
"Models",
"::",
"scope",
"(",
")",
"->",
"getAttachAttributes",
"(",
")",
"+",
"[",
"'role_id'",
"=>",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"'entity_type'",
"=>",
"$",
"type",
",",
"'entity_id'",
"=>",
"$",
"key",
",",
"]",
";",
"}",
",",
"$",
"keys",
")",
";",
"}"
]
| Create the pivot table records for assigning the role to given models.
@param \Illuminate\Database\Eloquent\Model $model
@param array $keys
@return array | [
"Create",
"the",
"pivot",
"table",
"records",
"for",
"assigning",
"the",
"role",
"to",
"given",
"models",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L217-L228 | train |
JosephSilber/bouncer | src/Database/Concerns/IsRole.php | IsRole.scopeWhereAssignedTo | public function scopeWhereAssignedTo($query, $model, array $keys = null)
{
(new RolesQuery)->constrainWhereAssignedTo($query, $model, $keys);
} | php | public function scopeWhereAssignedTo($query, $model, array $keys = null)
{
(new RolesQuery)->constrainWhereAssignedTo($query, $model, $keys);
} | [
"public",
"function",
"scopeWhereAssignedTo",
"(",
"$",
"query",
",",
"$",
"model",
",",
"array",
"$",
"keys",
"=",
"null",
")",
"{",
"(",
"new",
"RolesQuery",
")",
"->",
"constrainWhereAssignedTo",
"(",
"$",
"query",
",",
"$",
"model",
",",
"$",
"keys",
")",
";",
"}"
]
| Constrain the given query to roles that were assigned to the given authorities.
@param \Illuminate\Database\Eloquent\Builder $query
@param string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection $model
@param array $keys
@return void | [
"Constrain",
"the",
"given",
"query",
"to",
"roles",
"that",
"were",
"assigned",
"to",
"the",
"given",
"authorities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsRole.php#L238-L241 | train |
JosephSilber/bouncer | src/Conductors/Concerns/ConductsAbilities.php | ConductsAbilities.shouldConductLazy | protected function shouldConductLazy($abilities)
{
// We'll only create a lazy conductor if we got a single
// param, and that single param is either a string or
// a numerically-indexed array (of simple strings).
if (func_num_args() > 1) {
return false;
}
if (is_string($abilities)) {
return true;
}
if (! is_array($abilities) || ! Helpers::isIndexedArray($abilities)) {
return false;
}
// In an ideal world, we'd be using $collection->every('is_string').
// Since we also support older versions of Laravel, we'll need to
// use "array_filter" with a double count. Such is legacy life.
return count(array_filter($abilities, 'is_string')) == count($abilities);
} | php | protected function shouldConductLazy($abilities)
{
// We'll only create a lazy conductor if we got a single
// param, and that single param is either a string or
// a numerically-indexed array (of simple strings).
if (func_num_args() > 1) {
return false;
}
if (is_string($abilities)) {
return true;
}
if (! is_array($abilities) || ! Helpers::isIndexedArray($abilities)) {
return false;
}
// In an ideal world, we'd be using $collection->every('is_string').
// Since we also support older versions of Laravel, we'll need to
// use "array_filter" with a double count. Such is legacy life.
return count(array_filter($abilities, 'is_string')) == count($abilities);
} | [
"protected",
"function",
"shouldConductLazy",
"(",
"$",
"abilities",
")",
"{",
"// We'll only create a lazy conductor if we got a single",
"// param, and that single param is either a string or",
"// a numerically-indexed array (of simple strings).",
"if",
"(",
"func_num_args",
"(",
")",
">",
"1",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"abilities",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"abilities",
")",
"||",
"!",
"Helpers",
"::",
"isIndexedArray",
"(",
"$",
"abilities",
")",
")",
"{",
"return",
"false",
";",
"}",
"// In an ideal world, we'd be using $collection->every('is_string').",
"// Since we also support older versions of Laravel, we'll need to",
"// use \"array_filter\" with a double count. Such is legacy life.",
"return",
"count",
"(",
"array_filter",
"(",
"$",
"abilities",
",",
"'is_string'",
")",
")",
"==",
"count",
"(",
"$",
"abilities",
")",
";",
"}"
]
| Determines whether a call to "to" with the given parameters should be conducted lazily.
@param mixed $abilities
@param mixed $model
@return bool | [
"Determines",
"whether",
"a",
"call",
"to",
"to",
"with",
"the",
"given",
"parameters",
"should",
"be",
"conducted",
"lazily",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/ConductsAbilities.php#L70-L91 | train |
JosephSilber/bouncer | src/Console/CleanCommand.php | CleanCommand.getComputedOptions | protected function getComputedOptions()
{
$unassigned = $this->option('unassigned');
$orphaned = $this->option('orphaned');
if (! $unassigned && ! $orphaned) {
$unassigned = $orphaned = true;
}
return [$unassigned, $orphaned];
} | php | protected function getComputedOptions()
{
$unassigned = $this->option('unassigned');
$orphaned = $this->option('orphaned');
if (! $unassigned && ! $orphaned) {
$unassigned = $orphaned = true;
}
return [$unassigned, $orphaned];
} | [
"protected",
"function",
"getComputedOptions",
"(",
")",
"{",
"$",
"unassigned",
"=",
"$",
"this",
"->",
"option",
"(",
"'unassigned'",
")",
";",
"$",
"orphaned",
"=",
"$",
"this",
"->",
"option",
"(",
"'orphaned'",
")",
";",
"if",
"(",
"!",
"$",
"unassigned",
"&&",
"!",
"$",
"orphaned",
")",
"{",
"$",
"unassigned",
"=",
"$",
"orphaned",
"=",
"true",
";",
"}",
"return",
"[",
"$",
"unassigned",
",",
"$",
"orphaned",
"]",
";",
"}"
]
| Get the options to use, computed by omission.
@return array | [
"Get",
"the",
"options",
"to",
"use",
"computed",
"by",
"omission",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Console/CleanCommand.php#L51-L61 | train |
JosephSilber/bouncer | src/Console/CleanCommand.php | CleanCommand.deleteUnassignedAbilities | protected function deleteUnassignedAbilities()
{
$query = $this->getUnassignedAbilitiesQuery();
if (($count = $query->count()) > 0) {
$query->delete();
$this->info("Deleted {$count} unassigned ".Str::plural('ability', $count).'.');
} else {
$this->info('No unassigned abilities.');
}
} | php | protected function deleteUnassignedAbilities()
{
$query = $this->getUnassignedAbilitiesQuery();
if (($count = $query->count()) > 0) {
$query->delete();
$this->info("Deleted {$count} unassigned ".Str::plural('ability', $count).'.');
} else {
$this->info('No unassigned abilities.');
}
} | [
"protected",
"function",
"deleteUnassignedAbilities",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getUnassignedAbilitiesQuery",
"(",
")",
";",
"if",
"(",
"(",
"$",
"count",
"=",
"$",
"query",
"->",
"count",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"query",
"->",
"delete",
"(",
")",
";",
"$",
"this",
"->",
"info",
"(",
"\"Deleted {$count} unassigned \"",
".",
"Str",
"::",
"plural",
"(",
"'ability'",
",",
"$",
"count",
")",
".",
"'.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"info",
"(",
"'No unassigned abilities.'",
")",
";",
"}",
"}"
]
| Delete abilities not assigned to anyone.
@return void | [
"Delete",
"abilities",
"not",
"assigned",
"to",
"anyone",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Console/CleanCommand.php#L68-L79 | train |
JosephSilber/bouncer | src/Console/CleanCommand.php | CleanCommand.getUnassignedAbilitiesQuery | protected function getUnassignedAbilitiesQuery()
{
$model = Models::ability();
return $model->whereNotIn($model->getKeyName(), function ($query) {
$query->from(Models::table('permissions'))->select('ability_id');
});
} | php | protected function getUnassignedAbilitiesQuery()
{
$model = Models::ability();
return $model->whereNotIn($model->getKeyName(), function ($query) {
$query->from(Models::table('permissions'))->select('ability_id');
});
} | [
"protected",
"function",
"getUnassignedAbilitiesQuery",
"(",
")",
"{",
"$",
"model",
"=",
"Models",
"::",
"ability",
"(",
")",
";",
"return",
"$",
"model",
"->",
"whereNotIn",
"(",
"$",
"model",
"->",
"getKeyName",
"(",
")",
",",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"from",
"(",
"Models",
"::",
"table",
"(",
"'permissions'",
")",
")",
"->",
"select",
"(",
"'ability_id'",
")",
";",
"}",
")",
";",
"}"
]
| Get the base query for all unassigned abilities.
@return \Illuminate\Database\Eloquent\Query | [
"Get",
"the",
"base",
"query",
"for",
"all",
"unassigned",
"abilities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Console/CleanCommand.php#L86-L93 | train |
JosephSilber/bouncer | src/Console/CleanCommand.php | CleanCommand.deleteOrphanedAbilities | protected function deleteOrphanedAbilities()
{
$query = $this->getBaseOrphanedQuery()->where(function ($query) {
foreach ($this->getEntityModels() as $modelName) {
$query->orWhere(function ($query) use ($modelName) {
$this->scopeQueryToWhereModelIsMissing($query, $modelName);
});
}
});
if (($count = $query->count()) > 0) {
$query->delete();
$this->info("Deleted {$count} orphaned ".Str::plural('ability', $count).'.');
} else {
$this->info('No orphaned abilities.');
}
} | php | protected function deleteOrphanedAbilities()
{
$query = $this->getBaseOrphanedQuery()->where(function ($query) {
foreach ($this->getEntityModels() as $modelName) {
$query->orWhere(function ($query) use ($modelName) {
$this->scopeQueryToWhereModelIsMissing($query, $modelName);
});
}
});
if (($count = $query->count()) > 0) {
$query->delete();
$this->info("Deleted {$count} orphaned ".Str::plural('ability', $count).'.');
} else {
$this->info('No orphaned abilities.');
}
} | [
"protected",
"function",
"deleteOrphanedAbilities",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getBaseOrphanedQuery",
"(",
")",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getEntityModels",
"(",
")",
"as",
"$",
"modelName",
")",
"{",
"$",
"query",
"->",
"orWhere",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"modelName",
")",
"{",
"$",
"this",
"->",
"scopeQueryToWhereModelIsMissing",
"(",
"$",
"query",
",",
"$",
"modelName",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"(",
"$",
"count",
"=",
"$",
"query",
"->",
"count",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"query",
"->",
"delete",
"(",
")",
";",
"$",
"this",
"->",
"info",
"(",
"\"Deleted {$count} orphaned \"",
".",
"Str",
"::",
"plural",
"(",
"'ability'",
",",
"$",
"count",
")",
".",
"'.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"info",
"(",
"'No orphaned abilities.'",
")",
";",
"}",
"}"
]
| Delete model abilities whose models have been deleted.
@return void | [
"Delete",
"model",
"abilities",
"whose",
"models",
"have",
"been",
"deleted",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Console/CleanCommand.php#L100-L117 | train |
JosephSilber/bouncer | src/Console/CleanCommand.php | CleanCommand.scopeQueryToWhereModelIsMissing | protected function scopeQueryToWhereModelIsMissing($query, $modelName)
{
$model = new $modelName;
$table = $this->abilitiesTable();
$query->where("{$table}.entity_type", $modelName);
$query->whereNotIn("{$table}.entity_id", function ($query) use ($modelName) {
$model = new $modelName;
$table = $model->getTable();
$query->from($table)->select($table.'.'.$model->getKeyName());
});
} | php | protected function scopeQueryToWhereModelIsMissing($query, $modelName)
{
$model = new $modelName;
$table = $this->abilitiesTable();
$query->where("{$table}.entity_type", $modelName);
$query->whereNotIn("{$table}.entity_id", function ($query) use ($modelName) {
$model = new $modelName;
$table = $model->getTable();
$query->from($table)->select($table.'.'.$model->getKeyName());
});
} | [
"protected",
"function",
"scopeQueryToWhereModelIsMissing",
"(",
"$",
"query",
",",
"$",
"modelName",
")",
"{",
"$",
"model",
"=",
"new",
"$",
"modelName",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"abilitiesTable",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"\"{$table}.entity_type\"",
",",
"$",
"modelName",
")",
";",
"$",
"query",
"->",
"whereNotIn",
"(",
"\"{$table}.entity_id\"",
",",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"modelName",
")",
"{",
"$",
"model",
"=",
"new",
"$",
"modelName",
";",
"$",
"table",
"=",
"$",
"model",
"->",
"getTable",
"(",
")",
";",
"$",
"query",
"->",
"from",
"(",
"$",
"table",
")",
"->",
"select",
"(",
"$",
"table",
".",
"'.'",
".",
"$",
"model",
"->",
"getKeyName",
"(",
")",
")",
";",
"}",
")",
";",
"}"
]
| Scope the given query to where the ability's model is missing.
@param \Illuminate\Database\Query\Builder $query
@param string $modelName
@return void | [
"Scope",
"the",
"given",
"query",
"to",
"where",
"the",
"ability",
"s",
"model",
"is",
"missing",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Console/CleanCommand.php#L126-L139 | train |
JosephSilber/bouncer | src/Conductors/GivesAbilities.php | GivesAbilities.to | public function to($abilities, $model = null, array $attributes = [])
{
if (call_user_func_array([$this, 'shouldConductLazy'], func_get_args())) {
return $this->conductLazy($abilities);
}
$ids = $this->getAbilityIds($abilities, $model, $attributes);
$this->giveAbilities($ids, $this->getAuthority());
} | php | public function to($abilities, $model = null, array $attributes = [])
{
if (call_user_func_array([$this, 'shouldConductLazy'], func_get_args())) {
return $this->conductLazy($abilities);
}
$ids = $this->getAbilityIds($abilities, $model, $attributes);
$this->giveAbilities($ids, $this->getAuthority());
} | [
"public",
"function",
"to",
"(",
"$",
"abilities",
",",
"$",
"model",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'shouldConductLazy'",
"]",
",",
"func_get_args",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"conductLazy",
"(",
"$",
"abilities",
")",
";",
"}",
"$",
"ids",
"=",
"$",
"this",
"->",
"getAbilityIds",
"(",
"$",
"abilities",
",",
"$",
"model",
",",
"$",
"attributes",
")",
";",
"$",
"this",
"->",
"giveAbilities",
"(",
"$",
"ids",
",",
"$",
"this",
"->",
"getAuthority",
"(",
")",
")",
";",
"}"
]
| Give the abilities to the authority.
@param \Illuminate\Database\Eloquent\model|array|int $abilities
@param \Illuminate\Database\Eloquent\Model|string|null $model
@param array $attributes
@return \Silber\Bouncer\Conductors\Lazy\ConductsAbilities|null | [
"Give",
"the",
"abilities",
"to",
"the",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/GivesAbilities.php#L37-L46 | train |
JosephSilber/bouncer | src/Conductors/GivesAbilities.php | GivesAbilities.giveAbilities | protected function giveAbilities(array $ids, Model $authority = null)
{
$ids = array_diff($ids, $this->getAssociatedAbilityIds($authority, $ids, false));
if (is_null($authority)) {
$this->giveAbilitiesToEveryone($ids);
} else {
$this->giveAbilitiesToAuthority($ids, $authority);
}
} | php | protected function giveAbilities(array $ids, Model $authority = null)
{
$ids = array_diff($ids, $this->getAssociatedAbilityIds($authority, $ids, false));
if (is_null($authority)) {
$this->giveAbilitiesToEveryone($ids);
} else {
$this->giveAbilitiesToAuthority($ids, $authority);
}
} | [
"protected",
"function",
"giveAbilities",
"(",
"array",
"$",
"ids",
",",
"Model",
"$",
"authority",
"=",
"null",
")",
"{",
"$",
"ids",
"=",
"array_diff",
"(",
"$",
"ids",
",",
"$",
"this",
"->",
"getAssociatedAbilityIds",
"(",
"$",
"authority",
",",
"$",
"ids",
",",
"false",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"authority",
")",
")",
"{",
"$",
"this",
"->",
"giveAbilitiesToEveryone",
"(",
"$",
"ids",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"giveAbilitiesToAuthority",
"(",
"$",
"ids",
",",
"$",
"authority",
")",
";",
"}",
"}"
]
| Associate the given ability IDs as allowed abilities.
@param array $ids
@param \Illuminate\Database\Eloquent\Model|null $authority
@return void | [
"Associate",
"the",
"given",
"ability",
"IDs",
"as",
"allowed",
"abilities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/GivesAbilities.php#L55-L64 | train |
JosephSilber/bouncer | src/Conductors/GivesAbilities.php | GivesAbilities.giveAbilitiesToAuthority | protected function giveAbilitiesToAuthority(array $ids, Model $authority)
{
$attributes = Models::scope()->getAttachAttributes(get_class($authority));
$authority->abilities()->attach($ids, $attributes);
} | php | protected function giveAbilitiesToAuthority(array $ids, Model $authority)
{
$attributes = Models::scope()->getAttachAttributes(get_class($authority));
$authority->abilities()->attach($ids, $attributes);
} | [
"protected",
"function",
"giveAbilitiesToAuthority",
"(",
"array",
"$",
"ids",
",",
"Model",
"$",
"authority",
")",
"{",
"$",
"attributes",
"=",
"Models",
"::",
"scope",
"(",
")",
"->",
"getAttachAttributes",
"(",
"get_class",
"(",
"$",
"authority",
")",
")",
";",
"$",
"authority",
"->",
"abilities",
"(",
")",
"->",
"attach",
"(",
"$",
"ids",
",",
"$",
"attributes",
")",
";",
"}"
]
| Grant permission to these abilities to the given authority.
@param array $ids
@param \Illuminate\Database\Eloquent\Model $authority
@return void | [
"Grant",
"permission",
"to",
"these",
"abilities",
"to",
"the",
"given",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/GivesAbilities.php#L73-L78 | train |
JosephSilber/bouncer | src/Conductors/GivesAbilities.php | GivesAbilities.giveAbilitiesToEveryone | protected function giveAbilitiesToEveryone(array $ids)
{
$attributes = Models::scope()->getAttachAttributes();
$records = array_map(function ($id) use ($attributes) {
return ['ability_id' => $id] + $attributes;
}, $ids);
Models::query('permissions')->insert($records);
} | php | protected function giveAbilitiesToEveryone(array $ids)
{
$attributes = Models::scope()->getAttachAttributes();
$records = array_map(function ($id) use ($attributes) {
return ['ability_id' => $id] + $attributes;
}, $ids);
Models::query('permissions')->insert($records);
} | [
"protected",
"function",
"giveAbilitiesToEveryone",
"(",
"array",
"$",
"ids",
")",
"{",
"$",
"attributes",
"=",
"Models",
"::",
"scope",
"(",
")",
"->",
"getAttachAttributes",
"(",
")",
";",
"$",
"records",
"=",
"array_map",
"(",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"attributes",
")",
"{",
"return",
"[",
"'ability_id'",
"=>",
"$",
"id",
"]",
"+",
"$",
"attributes",
";",
"}",
",",
"$",
"ids",
")",
";",
"Models",
"::",
"query",
"(",
"'permissions'",
")",
"->",
"insert",
"(",
"$",
"records",
")",
";",
"}"
]
| Grant everyone permission to the given abilities.
@param array $ids
@return void | [
"Grant",
"everyone",
"permission",
"to",
"the",
"given",
"abilities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/GivesAbilities.php#L86-L95 | train |
JosephSilber/bouncer | middleware/ScopeBouncer.php | ScopeBouncer.handle | public function handle($request, Closure $next)
{
// Here you may use whatever mechanism you use in your app
// to determine the current tenant. To demonstrate, the
// $tenantId is set here from the user's account_id.
$tenantId = $request->user()->account_id;
$this->bouncer->scope()->to($tenantId);
return $next($request);
} | php | public function handle($request, Closure $next)
{
// Here you may use whatever mechanism you use in your app
// to determine the current tenant. To demonstrate, the
// $tenantId is set here from the user's account_id.
$tenantId = $request->user()->account_id;
$this->bouncer->scope()->to($tenantId);
return $next($request);
} | [
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"// Here you may use whatever mechanism you use in your app",
"// to determine the current tenant. To demonstrate, the",
"// $tenantId is set here from the user's account_id.",
"$",
"tenantId",
"=",
"$",
"request",
"->",
"user",
"(",
")",
"->",
"account_id",
";",
"$",
"this",
"->",
"bouncer",
"->",
"scope",
"(",
")",
"->",
"to",
"(",
"$",
"tenantId",
")",
";",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}"
]
| Set the proper Bouncer scope for the incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@return mixed | [
"Set",
"the",
"proper",
"Bouncer",
"scope",
"for",
"the",
"incoming",
"request",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/middleware/ScopeBouncer.php#L35-L45 | train |
JosephSilber/bouncer | src/Database/Models.php | Models.scope | public static function scope(ScopeContract $scope = null)
{
if (! is_null($scope)) {
return static::$scope = $scope;
}
if (is_null(static::$scope)) {
static::$scope = new Scope;
}
return static::$scope;
} | php | public static function scope(ScopeContract $scope = null)
{
if (! is_null($scope)) {
return static::$scope = $scope;
}
if (is_null(static::$scope)) {
static::$scope = new Scope;
}
return static::$scope;
} | [
"public",
"static",
"function",
"scope",
"(",
"ScopeContract",
"$",
"scope",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"scope",
")",
")",
"{",
"return",
"static",
"::",
"$",
"scope",
"=",
"$",
"scope",
";",
"}",
"if",
"(",
"is_null",
"(",
"static",
"::",
"$",
"scope",
")",
")",
"{",
"static",
"::",
"$",
"scope",
"=",
"new",
"Scope",
";",
"}",
"return",
"static",
"::",
"$",
"scope",
";",
"}"
]
| Get or set the model scoping instance.
@param \Silber\Bouncer\Contracts\Scope|null $scope
@return mixed | [
"Get",
"or",
"set",
"the",
"model",
"scoping",
"instance",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Models.php#L145-L156 | train |
JosephSilber/bouncer | src/Database/Models.php | Models.updateMorphMap | public static function updateMorphMap($classNames = null)
{
if (is_null($classNames)) {
$classNames = [
static::classname(Role::class),
static::classname(Ability::class),
];
}
Relation::morphMap($classNames);
} | php | public static function updateMorphMap($classNames = null)
{
if (is_null($classNames)) {
$classNames = [
static::classname(Role::class),
static::classname(Ability::class),
];
}
Relation::morphMap($classNames);
} | [
"public",
"static",
"function",
"updateMorphMap",
"(",
"$",
"classNames",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"classNames",
")",
")",
"{",
"$",
"classNames",
"=",
"[",
"static",
"::",
"classname",
"(",
"Role",
"::",
"class",
")",
",",
"static",
"::",
"classname",
"(",
"Ability",
"::",
"class",
")",
",",
"]",
";",
"}",
"Relation",
"::",
"morphMap",
"(",
"$",
"classNames",
")",
";",
"}"
]
| Update Eloquent's morph map with the Bouncer models and tables.
@param array|null $classNames
@return void | [
"Update",
"Eloquent",
"s",
"morph",
"map",
"with",
"the",
"Bouncer",
"models",
"and",
"tables",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Models.php#L179-L189 | train |
JosephSilber/bouncer | src/Database/Models.php | Models.isOwnedBy | public static function isOwnedBy(Model $authority, Model $model)
{
$type = get_class($model);
if (isset(static::$ownership[$type])) {
$attribute = static::$ownership[$type];
} elseif (isset(static::$ownership['*'])) {
$attribute = static::$ownership['*'];
} else {
$attribute = strtolower(static::basename($authority)).'_id';
}
return static::isOwnedVia($attribute, $authority, $model);
} | php | public static function isOwnedBy(Model $authority, Model $model)
{
$type = get_class($model);
if (isset(static::$ownership[$type])) {
$attribute = static::$ownership[$type];
} elseif (isset(static::$ownership['*'])) {
$attribute = static::$ownership['*'];
} else {
$attribute = strtolower(static::basename($authority)).'_id';
}
return static::isOwnedVia($attribute, $authority, $model);
} | [
"public",
"static",
"function",
"isOwnedBy",
"(",
"Model",
"$",
"authority",
",",
"Model",
"$",
"model",
")",
"{",
"$",
"type",
"=",
"get_class",
"(",
"$",
"model",
")",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"ownership",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"attribute",
"=",
"static",
"::",
"$",
"ownership",
"[",
"$",
"type",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"static",
"::",
"$",
"ownership",
"[",
"'*'",
"]",
")",
")",
"{",
"$",
"attribute",
"=",
"static",
"::",
"$",
"ownership",
"[",
"'*'",
"]",
";",
"}",
"else",
"{",
"$",
"attribute",
"=",
"strtolower",
"(",
"static",
"::",
"basename",
"(",
"$",
"authority",
")",
")",
".",
"'_id'",
";",
"}",
"return",
"static",
"::",
"isOwnedVia",
"(",
"$",
"attribute",
",",
"$",
"authority",
",",
"$",
"model",
")",
";",
"}"
]
| Determines whether the given model is owned by the given authority.
@param \Illuminate\Database\Eloquent\Model $authority
@param \Illuminate\Database\Eloquent\Model $model
@return bool | [
"Determines",
"whether",
"the",
"given",
"model",
"is",
"owned",
"by",
"the",
"given",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Models.php#L214-L227 | train |
JosephSilber/bouncer | src/Database/Models.php | Models.isOwnedVia | protected static function isOwnedVia($attribute, Model $authority, Model $model)
{
if ($attribute instanceof Closure) {
return $attribute($model, $authority);
}
return $authority->getKey() == $model->{$attribute};
} | php | protected static function isOwnedVia($attribute, Model $authority, Model $model)
{
if ($attribute instanceof Closure) {
return $attribute($model, $authority);
}
return $authority->getKey() == $model->{$attribute};
} | [
"protected",
"static",
"function",
"isOwnedVia",
"(",
"$",
"attribute",
",",
"Model",
"$",
"authority",
",",
"Model",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"attribute",
"instanceof",
"Closure",
")",
"{",
"return",
"$",
"attribute",
"(",
"$",
"model",
",",
"$",
"authority",
")",
";",
"}",
"return",
"$",
"authority",
"->",
"getKey",
"(",
")",
"==",
"$",
"model",
"->",
"{",
"$",
"attribute",
"}",
";",
"}"
]
| Determines ownership via the given attribute.
@param string|\Closure $attribute
@param \Illuminate\Database\Eloquent\Model $authority
@param \Illuminate\Database\Eloquent\Model $model
@return bool | [
"Determines",
"ownership",
"via",
"the",
"given",
"attribute",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Models.php#L237-L244 | train |
JosephSilber/bouncer | src/Database/Models.php | Models.query | public static function query($table)
{
$query = new Builder(
$connection = static::user()->getConnection(),
$connection->getQueryGrammar(),
$connection->getPostProcessor()
);
return $query->from(static::table($table));
} | php | public static function query($table)
{
$query = new Builder(
$connection = static::user()->getConnection(),
$connection->getQueryGrammar(),
$connection->getPostProcessor()
);
return $query->from(static::table($table));
} | [
"public",
"static",
"function",
"query",
"(",
"$",
"table",
")",
"{",
"$",
"query",
"=",
"new",
"Builder",
"(",
"$",
"connection",
"=",
"static",
"::",
"user",
"(",
")",
"->",
"getConnection",
"(",
")",
",",
"$",
"connection",
"->",
"getQueryGrammar",
"(",
")",
",",
"$",
"connection",
"->",
"getPostProcessor",
"(",
")",
")",
";",
"return",
"$",
"query",
"->",
"from",
"(",
"static",
"::",
"table",
"(",
"$",
"table",
")",
")",
";",
"}"
]
| Get a new query builder instance.
@param string $table
@return \Illuminate\Database\Query\Builder | [
"Get",
"a",
"new",
"query",
"builder",
"instance",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Models.php#L285-L294 | train |
JosephSilber/bouncer | src/Conductors/Lazy/HandlesOwnership.php | HandlesOwnership.to | public function to($ability, array $attributes = [])
{
$this->ability = $ability;
$this->attributes = array_merge($this->attributes, $attributes);
} | php | public function to($ability, array $attributes = [])
{
$this->ability = $ability;
$this->attributes = array_merge($this->attributes, $attributes);
} | [
"public",
"function",
"to",
"(",
"$",
"ability",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"ability",
"=",
"$",
"ability",
";",
"$",
"this",
"->",
"attributes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"attributes",
")",
";",
"}"
]
| Limit ownership to the given ability.
@param string|string[] $ability
@param array $attributes
@return void | [
"Limit",
"ownership",
"to",
"the",
"given",
"ability",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Lazy/HandlesOwnership.php#L56-L61 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.getAbilityIds | protected function getAbilityIds($abilities, $model = null, array $attributes = [])
{
if ($abilities instanceof Model) {
return [$abilities->getKey()];
}
if ( ! is_null($model)) {
return $this->getModelAbilityKeys($abilities, $model, $attributes);
}
if (Helpers::isAssociativeArray($abilities)) {
return $this->getAbilityIdsFromMap($abilities, $attributes);
}
if (! is_array($abilities) && ! $abilities instanceof Collection) {
$abilities = [$abilities];
}
return $this->getAbilityIdsFromArray($abilities, $attributes);
} | php | protected function getAbilityIds($abilities, $model = null, array $attributes = [])
{
if ($abilities instanceof Model) {
return [$abilities->getKey()];
}
if ( ! is_null($model)) {
return $this->getModelAbilityKeys($abilities, $model, $attributes);
}
if (Helpers::isAssociativeArray($abilities)) {
return $this->getAbilityIdsFromMap($abilities, $attributes);
}
if (! is_array($abilities) && ! $abilities instanceof Collection) {
$abilities = [$abilities];
}
return $this->getAbilityIdsFromArray($abilities, $attributes);
} | [
"protected",
"function",
"getAbilityIds",
"(",
"$",
"abilities",
",",
"$",
"model",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"abilities",
"instanceof",
"Model",
")",
"{",
"return",
"[",
"$",
"abilities",
"->",
"getKey",
"(",
")",
"]",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"model",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getModelAbilityKeys",
"(",
"$",
"abilities",
",",
"$",
"model",
",",
"$",
"attributes",
")",
";",
"}",
"if",
"(",
"Helpers",
"::",
"isAssociativeArray",
"(",
"$",
"abilities",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getAbilityIdsFromMap",
"(",
"$",
"abilities",
",",
"$",
"attributes",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"abilities",
")",
"&&",
"!",
"$",
"abilities",
"instanceof",
"Collection",
")",
"{",
"$",
"abilities",
"=",
"[",
"$",
"abilities",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"getAbilityIdsFromArray",
"(",
"$",
"abilities",
",",
"$",
"attributes",
")",
";",
"}"
]
| Get the IDs of the provided abilities.
@param \Illuminate\Database\Eloquent\model|array|int $abilities
@param \Illuminate\Database\Eloquent\Model|string|array|null $model
@param array $attributes
@return array | [
"Get",
"the",
"IDs",
"of",
"the",
"provided",
"abilities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L23-L42 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.getAbilityIdsFromMap | protected function getAbilityIdsFromMap(array $map, array $attributes)
{
list($map, $list) = Helpers::partition($map, function ($value, $key) {
return ! is_int($key);
});
return $map->map(function ($entity, $ability) use ($attributes) {
return $this->getAbilityIds($ability, $entity, $attributes);
})->collapse()->merge($this->getAbilityIdsFromArray($list, $attributes))->all();
} | php | protected function getAbilityIdsFromMap(array $map, array $attributes)
{
list($map, $list) = Helpers::partition($map, function ($value, $key) {
return ! is_int($key);
});
return $map->map(function ($entity, $ability) use ($attributes) {
return $this->getAbilityIds($ability, $entity, $attributes);
})->collapse()->merge($this->getAbilityIdsFromArray($list, $attributes))->all();
} | [
"protected",
"function",
"getAbilityIdsFromMap",
"(",
"array",
"$",
"map",
",",
"array",
"$",
"attributes",
")",
"{",
"list",
"(",
"$",
"map",
",",
"$",
"list",
")",
"=",
"Helpers",
"::",
"partition",
"(",
"$",
"map",
",",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"{",
"return",
"!",
"is_int",
"(",
"$",
"key",
")",
";",
"}",
")",
";",
"return",
"$",
"map",
"->",
"map",
"(",
"function",
"(",
"$",
"entity",
",",
"$",
"ability",
")",
"use",
"(",
"$",
"attributes",
")",
"{",
"return",
"$",
"this",
"->",
"getAbilityIds",
"(",
"$",
"ability",
",",
"$",
"entity",
",",
"$",
"attributes",
")",
";",
"}",
")",
"->",
"collapse",
"(",
")",
"->",
"merge",
"(",
"$",
"this",
"->",
"getAbilityIdsFromArray",
"(",
"$",
"list",
",",
"$",
"attributes",
")",
")",
"->",
"all",
"(",
")",
";",
"}"
]
| Get the ability IDs for the given map.
The map should use the ['ability-name' => Entity::class] format.
@param array $map
@param array $attributes
@return array | [
"Get",
"the",
"ability",
"IDs",
"for",
"the",
"given",
"map",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L53-L62 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.getAbilityIdsFromArray | protected function getAbilityIdsFromArray($abilities, array $attributes)
{
$groups = Helpers::groupModelsAndIdentifiersByType($abilities);
$keyName = Models::ability()->getKeyName();
$groups['strings'] = $this->abilitiesByName($groups['strings'], $attributes)
->pluck($keyName)->all();
$groups['models'] = Arr::pluck($groups['models'], $keyName);
return Arr::collapse($groups);
} | php | protected function getAbilityIdsFromArray($abilities, array $attributes)
{
$groups = Helpers::groupModelsAndIdentifiersByType($abilities);
$keyName = Models::ability()->getKeyName();
$groups['strings'] = $this->abilitiesByName($groups['strings'], $attributes)
->pluck($keyName)->all();
$groups['models'] = Arr::pluck($groups['models'], $keyName);
return Arr::collapse($groups);
} | [
"protected",
"function",
"getAbilityIdsFromArray",
"(",
"$",
"abilities",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"groups",
"=",
"Helpers",
"::",
"groupModelsAndIdentifiersByType",
"(",
"$",
"abilities",
")",
";",
"$",
"keyName",
"=",
"Models",
"::",
"ability",
"(",
")",
"->",
"getKeyName",
"(",
")",
";",
"$",
"groups",
"[",
"'strings'",
"]",
"=",
"$",
"this",
"->",
"abilitiesByName",
"(",
"$",
"groups",
"[",
"'strings'",
"]",
",",
"$",
"attributes",
")",
"->",
"pluck",
"(",
"$",
"keyName",
")",
"->",
"all",
"(",
")",
";",
"$",
"groups",
"[",
"'models'",
"]",
"=",
"Arr",
"::",
"pluck",
"(",
"$",
"groups",
"[",
"'models'",
"]",
",",
"$",
"keyName",
")",
";",
"return",
"Arr",
"::",
"collapse",
"(",
"$",
"groups",
")",
";",
"}"
]
| Get the ability IDs from the provided array, creating the ones that don't exist.
@param iterable $abilities
@param array $attributes
@return array | [
"Get",
"the",
"ability",
"IDs",
"from",
"the",
"provided",
"array",
"creating",
"the",
"ones",
"that",
"don",
"t",
"exist",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L71-L83 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.getModelAbilityKeys | protected function getModelAbilityKeys($abilities, $model, array $attributes)
{
$abilities = Collection::make(is_array($abilities) ? $abilities : [$abilities]);
$models = Collection::make(is_array($model) ? $model : [$model]);
return $abilities->map(function ($ability) use ($models, $attributes) {
return $models->map(function ($model) use ($ability, $attributes) {
return $this->getModelAbility($ability, $model, $attributes)->getKey();
});
})->collapse()->all();
} | php | protected function getModelAbilityKeys($abilities, $model, array $attributes)
{
$abilities = Collection::make(is_array($abilities) ? $abilities : [$abilities]);
$models = Collection::make(is_array($model) ? $model : [$model]);
return $abilities->map(function ($ability) use ($models, $attributes) {
return $models->map(function ($model) use ($ability, $attributes) {
return $this->getModelAbility($ability, $model, $attributes)->getKey();
});
})->collapse()->all();
} | [
"protected",
"function",
"getModelAbilityKeys",
"(",
"$",
"abilities",
",",
"$",
"model",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"abilities",
"=",
"Collection",
"::",
"make",
"(",
"is_array",
"(",
"$",
"abilities",
")",
"?",
"$",
"abilities",
":",
"[",
"$",
"abilities",
"]",
")",
";",
"$",
"models",
"=",
"Collection",
"::",
"make",
"(",
"is_array",
"(",
"$",
"model",
")",
"?",
"$",
"model",
":",
"[",
"$",
"model",
"]",
")",
";",
"return",
"$",
"abilities",
"->",
"map",
"(",
"function",
"(",
"$",
"ability",
")",
"use",
"(",
"$",
"models",
",",
"$",
"attributes",
")",
"{",
"return",
"$",
"models",
"->",
"map",
"(",
"function",
"(",
"$",
"model",
")",
"use",
"(",
"$",
"ability",
",",
"$",
"attributes",
")",
"{",
"return",
"$",
"this",
"->",
"getModelAbility",
"(",
"$",
"ability",
",",
"$",
"model",
",",
"$",
"attributes",
")",
"->",
"getKey",
"(",
")",
";",
"}",
")",
";",
"}",
")",
"->",
"collapse",
"(",
")",
"->",
"all",
"(",
")",
";",
"}"
]
| Get the abilities for the given model ability descriptors.
@param array|string $abilities
@param \Illuminate\Database\Eloquent\Model|string|array $model
@param array $attributes
@return array | [
"Get",
"the",
"abilities",
"for",
"the",
"given",
"model",
"ability",
"descriptors",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L93-L104 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.getModelAbility | protected function getModelAbility($ability, $entity, array $attributes)
{
$entity = $this->getEntityInstance($entity);
$existing = $this->findAbility($ability, $entity, $attributes);
return $existing ?: $this->createAbility($ability, $entity, $attributes);
} | php | protected function getModelAbility($ability, $entity, array $attributes)
{
$entity = $this->getEntityInstance($entity);
$existing = $this->findAbility($ability, $entity, $attributes);
return $existing ?: $this->createAbility($ability, $entity, $attributes);
} | [
"protected",
"function",
"getModelAbility",
"(",
"$",
"ability",
",",
"$",
"entity",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"getEntityInstance",
"(",
"$",
"entity",
")",
";",
"$",
"existing",
"=",
"$",
"this",
"->",
"findAbility",
"(",
"$",
"ability",
",",
"$",
"entity",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"existing",
"?",
":",
"$",
"this",
"->",
"createAbility",
"(",
"$",
"ability",
",",
"$",
"entity",
",",
"$",
"attributes",
")",
";",
"}"
]
| Get an ability for the given entity.
@param string $ability
@param \Illuminate\Database\Eloquent\Model|string $entity
@param array $attributes
@return \Silber\Bouncer\Database\Ability | [
"Get",
"an",
"ability",
"for",
"the",
"given",
"entity",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L114-L121 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.findAbility | protected function findAbility($ability, $entity, $attributes)
{
$onlyOwned = isset($attributes['only_owned']) ? $attributes['only_owned'] : false;
$query = Models::ability()
->where('name', $ability)
->forModel($entity, true)
->where('only_owned', $onlyOwned);
return Models::scope()->applyToModelQuery($query)->first();
} | php | protected function findAbility($ability, $entity, $attributes)
{
$onlyOwned = isset($attributes['only_owned']) ? $attributes['only_owned'] : false;
$query = Models::ability()
->where('name', $ability)
->forModel($entity, true)
->where('only_owned', $onlyOwned);
return Models::scope()->applyToModelQuery($query)->first();
} | [
"protected",
"function",
"findAbility",
"(",
"$",
"ability",
",",
"$",
"entity",
",",
"$",
"attributes",
")",
"{",
"$",
"onlyOwned",
"=",
"isset",
"(",
"$",
"attributes",
"[",
"'only_owned'",
"]",
")",
"?",
"$",
"attributes",
"[",
"'only_owned'",
"]",
":",
"false",
";",
"$",
"query",
"=",
"Models",
"::",
"ability",
"(",
")",
"->",
"where",
"(",
"'name'",
",",
"$",
"ability",
")",
"->",
"forModel",
"(",
"$",
"entity",
",",
"true",
")",
"->",
"where",
"(",
"'only_owned'",
",",
"$",
"onlyOwned",
")",
";",
"return",
"Models",
"::",
"scope",
"(",
")",
"->",
"applyToModelQuery",
"(",
"$",
"query",
")",
"->",
"first",
"(",
")",
";",
"}"
]
| Find the ability for the given entity.
@param string $ability
@param \Illuminate\Database\Eloquent\Model|string $entity
@param array $attributes
@return \Silber\Bouncer\Database\Ability|null | [
"Find",
"the",
"ability",
"for",
"the",
"given",
"entity",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L131-L141 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.createAbility | protected function createAbility($ability, $entity, $attributes)
{
return Models::ability()->createForModel($entity, $attributes + [
'name' => $ability,
]);
} | php | protected function createAbility($ability, $entity, $attributes)
{
return Models::ability()->createForModel($entity, $attributes + [
'name' => $ability,
]);
} | [
"protected",
"function",
"createAbility",
"(",
"$",
"ability",
",",
"$",
"entity",
",",
"$",
"attributes",
")",
"{",
"return",
"Models",
"::",
"ability",
"(",
")",
"->",
"createForModel",
"(",
"$",
"entity",
",",
"$",
"attributes",
"+",
"[",
"'name'",
"=>",
"$",
"ability",
",",
"]",
")",
";",
"}"
]
| Create an ability for the given entity.
@param string $ability
@param \Illuminate\Database\Eloquent\Model|string $entity
@param array $attributes
@return \Silber\Bouncer\Database\Ability | [
"Create",
"an",
"ability",
"for",
"the",
"given",
"entity",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L151-L156 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.getEntityInstance | protected function getEntityInstance($model)
{
if ($model === '*') {
return '*';
}
if ( ! $model instanceof Model) {
return new $model;
}
// Creating an ability for a non-existent model gives the authority that
// ability on all instances of that model. If the developer passed in
// a model instance that does not exist, it is probably a mistake.
if ( ! $model->exists) {
throw new InvalidArgumentException(
'The model does not exist. To edit access to all models, use the class name instead'
);
}
return $model;
} | php | protected function getEntityInstance($model)
{
if ($model === '*') {
return '*';
}
if ( ! $model instanceof Model) {
return new $model;
}
// Creating an ability for a non-existent model gives the authority that
// ability on all instances of that model. If the developer passed in
// a model instance that does not exist, it is probably a mistake.
if ( ! $model->exists) {
throw new InvalidArgumentException(
'The model does not exist. To edit access to all models, use the class name instead'
);
}
return $model;
} | [
"protected",
"function",
"getEntityInstance",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"model",
"===",
"'*'",
")",
"{",
"return",
"'*'",
";",
"}",
"if",
"(",
"!",
"$",
"model",
"instanceof",
"Model",
")",
"{",
"return",
"new",
"$",
"model",
";",
"}",
"// Creating an ability for a non-existent model gives the authority that",
"// ability on all instances of that model. If the developer passed in",
"// a model instance that does not exist, it is probably a mistake.",
"if",
"(",
"!",
"$",
"model",
"->",
"exists",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The model does not exist. To edit access to all models, use the class name instead'",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
]
| Get an instance of the given model.
@param \Illuminate\Database\Eloquent\Model|string $model
@return \Illuminate\Database\Eloquent\Model|string | [
"Get",
"an",
"instance",
"of",
"the",
"given",
"model",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L164-L184 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.abilitiesByName | protected function abilitiesByName($abilities, $attributes = [])
{
$abilities = array_unique(is_array($abilities) ? $abilities : [$abilities]);
if (empty($abilities)) {
return new Collection;
}
$existing = Models::ability()->simpleAbility()->whereIn('name', $abilities)->get();
return $existing->merge($this->createMissingAbilities(
$existing, $abilities, $attributes
));
} | php | protected function abilitiesByName($abilities, $attributes = [])
{
$abilities = array_unique(is_array($abilities) ? $abilities : [$abilities]);
if (empty($abilities)) {
return new Collection;
}
$existing = Models::ability()->simpleAbility()->whereIn('name', $abilities)->get();
return $existing->merge($this->createMissingAbilities(
$existing, $abilities, $attributes
));
} | [
"protected",
"function",
"abilitiesByName",
"(",
"$",
"abilities",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"abilities",
"=",
"array_unique",
"(",
"is_array",
"(",
"$",
"abilities",
")",
"?",
"$",
"abilities",
":",
"[",
"$",
"abilities",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"abilities",
")",
")",
"{",
"return",
"new",
"Collection",
";",
"}",
"$",
"existing",
"=",
"Models",
"::",
"ability",
"(",
")",
"->",
"simpleAbility",
"(",
")",
"->",
"whereIn",
"(",
"'name'",
",",
"$",
"abilities",
")",
"->",
"get",
"(",
")",
";",
"return",
"$",
"existing",
"->",
"merge",
"(",
"$",
"this",
"->",
"createMissingAbilities",
"(",
"$",
"existing",
",",
"$",
"abilities",
",",
"$",
"attributes",
")",
")",
";",
"}"
]
| Get or create abilities by their name.
@param array|string $abilities
@param array $attributes
@return \Illuminate\Support\Collection | [
"Get",
"or",
"create",
"abilities",
"by",
"their",
"name",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L193-L206 | train |
JosephSilber/bouncer | src/Conductors/Concerns/FindsAndCreatesAbilities.php | FindsAndCreatesAbilities.createMissingAbilities | protected function createMissingAbilities($existing, array $abilities, $attributes = [])
{
$missing = array_diff($abilities, $existing->pluck('name')->all());
return array_map(function ($ability) use ($attributes) {
return Models::ability()->create($attributes + ['name' => $ability]);
}, $missing);
} | php | protected function createMissingAbilities($existing, array $abilities, $attributes = [])
{
$missing = array_diff($abilities, $existing->pluck('name')->all());
return array_map(function ($ability) use ($attributes) {
return Models::ability()->create($attributes + ['name' => $ability]);
}, $missing);
} | [
"protected",
"function",
"createMissingAbilities",
"(",
"$",
"existing",
",",
"array",
"$",
"abilities",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"missing",
"=",
"array_diff",
"(",
"$",
"abilities",
",",
"$",
"existing",
"->",
"pluck",
"(",
"'name'",
")",
"->",
"all",
"(",
")",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"ability",
")",
"use",
"(",
"$",
"attributes",
")",
"{",
"return",
"Models",
"::",
"ability",
"(",
")",
"->",
"create",
"(",
"$",
"attributes",
"+",
"[",
"'name'",
"=>",
"$",
"ability",
"]",
")",
";",
"}",
",",
"$",
"missing",
")",
";",
"}"
]
| Create the non-existant abilities by name.
@param \Illuminate\Database\Eloquent\Collection $existing
@param string[] $abilities
@param array $attributes
@return array | [
"Create",
"the",
"non",
"-",
"existant",
"abilities",
"by",
"name",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/FindsAndCreatesAbilities.php#L216-L223 | train |
JosephSilber/bouncer | src/Factory.php | Factory.create | public function create()
{
$gate = $this->getGate();
$guard = $this->getGuard();
$bouncer = (new Bouncer($guard))->setGate($gate);
if ($this->registerAtGate) {
$guard->registerAt($gate);
}
if ($this->registerAtContainer) {
$bouncer->registerClipboardAtContainer();
}
return $bouncer;
} | php | public function create()
{
$gate = $this->getGate();
$guard = $this->getGuard();
$bouncer = (new Bouncer($guard))->setGate($gate);
if ($this->registerAtGate) {
$guard->registerAt($gate);
}
if ($this->registerAtContainer) {
$bouncer->registerClipboardAtContainer();
}
return $bouncer;
} | [
"public",
"function",
"create",
"(",
")",
"{",
"$",
"gate",
"=",
"$",
"this",
"->",
"getGate",
"(",
")",
";",
"$",
"guard",
"=",
"$",
"this",
"->",
"getGuard",
"(",
")",
";",
"$",
"bouncer",
"=",
"(",
"new",
"Bouncer",
"(",
"$",
"guard",
")",
")",
"->",
"setGate",
"(",
"$",
"gate",
")",
";",
"if",
"(",
"$",
"this",
"->",
"registerAtGate",
")",
"{",
"$",
"guard",
"->",
"registerAt",
"(",
"$",
"gate",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"registerAtContainer",
")",
"{",
"$",
"bouncer",
"->",
"registerClipboardAtContainer",
"(",
")",
";",
"}",
"return",
"$",
"bouncer",
";",
"}"
]
| Create an instance of Bouncer.
@return \Silber\Bouncer\Bouncer | [
"Create",
"an",
"instance",
"of",
"Bouncer",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Factory.php#L70-L86 | train |
JosephSilber/bouncer | src/Factory.php | Factory.getGate | protected function getGate()
{
if ($this->gate) {
return $this->gate;
}
return new Gate($this->getContainer(), function () {
return $this->user;
});
} | php | protected function getGate()
{
if ($this->gate) {
return $this->gate;
}
return new Gate($this->getContainer(), function () {
return $this->user;
});
} | [
"protected",
"function",
"getGate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"gate",
")",
"{",
"return",
"$",
"this",
"->",
"gate",
";",
"}",
"return",
"new",
"Gate",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"user",
";",
"}",
")",
";",
"}"
]
| Get an instance of the gate.
@return \Illuminate\Contracts\Auth\Access\Gate | [
"Get",
"an",
"instance",
"of",
"the",
"gate",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Factory.php#L201-L210 | train |
JosephSilber/bouncer | src/Database/Queries/AbilitiesForModel.php | AbilitiesForModel.constrain | public function constrain($query, $model, $strict = false)
{
if ($model === '*') {
return $this->constrainByWildcard($query);
}
$model = is_string($model) ? new $model : $model;
$this->constrainByModel($query, $model, $strict);
} | php | public function constrain($query, $model, $strict = false)
{
if ($model === '*') {
return $this->constrainByWildcard($query);
}
$model = is_string($model) ? new $model : $model;
$this->constrainByModel($query, $model, $strict);
} | [
"public",
"function",
"constrain",
"(",
"$",
"query",
",",
"$",
"model",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"model",
"===",
"'*'",
")",
"{",
"return",
"$",
"this",
"->",
"constrainByWildcard",
"(",
"$",
"query",
")",
";",
"}",
"$",
"model",
"=",
"is_string",
"(",
"$",
"model",
")",
"?",
"new",
"$",
"model",
":",
"$",
"model",
";",
"$",
"this",
"->",
"constrainByModel",
"(",
"$",
"query",
",",
"$",
"model",
",",
"$",
"strict",
")",
";",
"}"
]
| Constrain a query to an ability for a specific model or wildcard.
@param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
@param \Illuminate\Database\Eloquent\Model|string $model
@param bool $strict
@return void | [
"Constrain",
"a",
"query",
"to",
"an",
"ability",
"for",
"a",
"specific",
"model",
"or",
"wildcard",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/AbilitiesForModel.php#L34-L43 | train |
JosephSilber/bouncer | src/Database/Queries/AbilitiesForModel.php | AbilitiesForModel.modelAbilityConstraint | protected function modelAbilityConstraint(Model $model, $strict)
{
return function ($query) use ($model, $strict) {
$query->where("{$this->table}.entity_type", $model->getMorphClass());
$query->where($this->abilitySubqueryConstraint($model, $strict));
};
} | php | protected function modelAbilityConstraint(Model $model, $strict)
{
return function ($query) use ($model, $strict) {
$query->where("{$this->table}.entity_type", $model->getMorphClass());
$query->where($this->abilitySubqueryConstraint($model, $strict));
};
} | [
"protected",
"function",
"modelAbilityConstraint",
"(",
"Model",
"$",
"model",
",",
"$",
"strict",
")",
"{",
"return",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"model",
",",
"$",
"strict",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"\"{$this->table}.entity_type\"",
",",
"$",
"model",
"->",
"getMorphClass",
"(",
")",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"abilitySubqueryConstraint",
"(",
"$",
"model",
",",
"$",
"strict",
")",
")",
";",
"}",
";",
"}"
]
| Get the constraint for regular model abilities.
@param \Illuminate\Database\Eloquent\Model $model
@param bool $strict
@return \Closure | [
"Get",
"the",
"constraint",
"for",
"regular",
"model",
"abilities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/AbilitiesForModel.php#L85-L92 | train |
JosephSilber/bouncer | src/Database/Queries/AbilitiesForModel.php | AbilitiesForModel.abilitySubqueryConstraint | protected function abilitySubqueryConstraint(Model $model, $strict)
{
return function ($query) use ($model, $strict) {
// If the model does not exist, we want to search for blanket abilities
// that cover all instances of this model. If it does exist, we only
// want to find blanket abilities if we're not using strict mode.
if ( ! $model->exists || ! $strict) {
$query->whereNull("{$this->table}.entity_id");
}
if ($model->exists) {
$query->orWhere("{$this->table}.entity_id", $model->getKey());
}
};
} | php | protected function abilitySubqueryConstraint(Model $model, $strict)
{
return function ($query) use ($model, $strict) {
// If the model does not exist, we want to search for blanket abilities
// that cover all instances of this model. If it does exist, we only
// want to find blanket abilities if we're not using strict mode.
if ( ! $model->exists || ! $strict) {
$query->whereNull("{$this->table}.entity_id");
}
if ($model->exists) {
$query->orWhere("{$this->table}.entity_id", $model->getKey());
}
};
} | [
"protected",
"function",
"abilitySubqueryConstraint",
"(",
"Model",
"$",
"model",
",",
"$",
"strict",
")",
"{",
"return",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"model",
",",
"$",
"strict",
")",
"{",
"// If the model does not exist, we want to search for blanket abilities",
"// that cover all instances of this model. If it does exist, we only",
"// want to find blanket abilities if we're not using strict mode.",
"if",
"(",
"!",
"$",
"model",
"->",
"exists",
"||",
"!",
"$",
"strict",
")",
"{",
"$",
"query",
"->",
"whereNull",
"(",
"\"{$this->table}.entity_id\"",
")",
";",
"}",
"if",
"(",
"$",
"model",
"->",
"exists",
")",
"{",
"$",
"query",
"->",
"orWhere",
"(",
"\"{$this->table}.entity_id\"",
",",
"$",
"model",
"->",
"getKey",
"(",
")",
")",
";",
"}",
"}",
";",
"}"
]
| Get the constraint for the ability subquery.
@param \Illuminate\Database\Eloquent\Model $model
@param bool $strict
@return \Closure | [
"Get",
"the",
"constraint",
"for",
"the",
"ability",
"subquery",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/AbilitiesForModel.php#L101-L115 | train |
JosephSilber/bouncer | src/Database/Scope/BaseTenantScope.php | BaseTenantScope.register | public static function register($model)
{
if (interface_exists(EloquentScope::class)) {
$model::addGlobalScope(new TenantScope);
} else {
$model::addGlobalScope(new LegacyTenantScope);
}
} | php | public static function register($model)
{
if (interface_exists(EloquentScope::class)) {
$model::addGlobalScope(new TenantScope);
} else {
$model::addGlobalScope(new LegacyTenantScope);
}
} | [
"public",
"static",
"function",
"register",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"interface_exists",
"(",
"EloquentScope",
"::",
"class",
")",
")",
"{",
"$",
"model",
"::",
"addGlobalScope",
"(",
"new",
"TenantScope",
")",
";",
"}",
"else",
"{",
"$",
"model",
"::",
"addGlobalScope",
"(",
"new",
"LegacyTenantScope",
")",
";",
"}",
"}"
]
| Register the correct global scope class.
@param string $model
@return void | [
"Register",
"the",
"correct",
"global",
"scope",
"class",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Scope/BaseTenantScope.php#L19-L26 | train |
JosephSilber/bouncer | src/Conductors/ForbidsAbilities.php | ForbidsAbilities.forbidAbilities | protected function forbidAbilities(array $ids, Model $authority = null)
{
$ids = array_diff($ids, $this->getAssociatedAbilityIds($authority, $ids, true));
if (is_null($authority)) {
$this->forbidAbilitiesToEveryone($ids);
} else {
$this->forbidAbilitiesToAuthority($ids, $authority);
}
} | php | protected function forbidAbilities(array $ids, Model $authority = null)
{
$ids = array_diff($ids, $this->getAssociatedAbilityIds($authority, $ids, true));
if (is_null($authority)) {
$this->forbidAbilitiesToEveryone($ids);
} else {
$this->forbidAbilitiesToAuthority($ids, $authority);
}
} | [
"protected",
"function",
"forbidAbilities",
"(",
"array",
"$",
"ids",
",",
"Model",
"$",
"authority",
"=",
"null",
")",
"{",
"$",
"ids",
"=",
"array_diff",
"(",
"$",
"ids",
",",
"$",
"this",
"->",
"getAssociatedAbilityIds",
"(",
"$",
"authority",
",",
"$",
"ids",
",",
"true",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"authority",
")",
")",
"{",
"$",
"this",
"->",
"forbidAbilitiesToEveryone",
"(",
"$",
"ids",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"forbidAbilitiesToAuthority",
"(",
"$",
"ids",
",",
"$",
"authority",
")",
";",
"}",
"}"
]
| Associate the given abilitiy IDs as forbidden abilities.
@param array $ids
@param \Illuminate\Database\Eloquent\Model|null $authority
@return void | [
"Associate",
"the",
"given",
"abilitiy",
"IDs",
"as",
"forbidden",
"abilities",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/ForbidsAbilities.php#L57-L66 | train |
JosephSilber/bouncer | src/Conductors/ForbidsAbilities.php | ForbidsAbilities.forbidAbilitiesToAuthority | protected function forbidAbilitiesToAuthority(array $ids, Model $authority)
{
$attributes = Models::scope()->getAttachAttributes(get_class($authority));
$authority->abilities()->attach($ids, $attributes + ['forbidden' => true]);
} | php | protected function forbidAbilitiesToAuthority(array $ids, Model $authority)
{
$attributes = Models::scope()->getAttachAttributes(get_class($authority));
$authority->abilities()->attach($ids, $attributes + ['forbidden' => true]);
} | [
"protected",
"function",
"forbidAbilitiesToAuthority",
"(",
"array",
"$",
"ids",
",",
"Model",
"$",
"authority",
")",
"{",
"$",
"attributes",
"=",
"Models",
"::",
"scope",
"(",
")",
"->",
"getAttachAttributes",
"(",
"get_class",
"(",
"$",
"authority",
")",
")",
";",
"$",
"authority",
"->",
"abilities",
"(",
")",
"->",
"attach",
"(",
"$",
"ids",
",",
"$",
"attributes",
"+",
"[",
"'forbidden'",
"=>",
"true",
"]",
")",
";",
"}"
]
| Forbid these abilities to the given authority.
@param array $ids
@param \Illuminate\Database\Eloquent\Model $authority
@return void | [
"Forbid",
"these",
"abilities",
"to",
"the",
"given",
"authority",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/ForbidsAbilities.php#L75-L80 | train |
JosephSilber/bouncer | src/Conductors/ForbidsAbilities.php | ForbidsAbilities.forbidAbilitiesToEveryone | protected function forbidAbilitiesToEveryone(array $ids)
{
$attributes = Models::scope()->getAttachAttributes() + ['forbidden' => true];
$records = array_map(function ($id) use ($attributes) {
return ['ability_id' => $id] + $attributes;
}, $ids);
Models::query('permissions')->insert($records);
} | php | protected function forbidAbilitiesToEveryone(array $ids)
{
$attributes = Models::scope()->getAttachAttributes() + ['forbidden' => true];
$records = array_map(function ($id) use ($attributes) {
return ['ability_id' => $id] + $attributes;
}, $ids);
Models::query('permissions')->insert($records);
} | [
"protected",
"function",
"forbidAbilitiesToEveryone",
"(",
"array",
"$",
"ids",
")",
"{",
"$",
"attributes",
"=",
"Models",
"::",
"scope",
"(",
")",
"->",
"getAttachAttributes",
"(",
")",
"+",
"[",
"'forbidden'",
"=>",
"true",
"]",
";",
"$",
"records",
"=",
"array_map",
"(",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"attributes",
")",
"{",
"return",
"[",
"'ability_id'",
"=>",
"$",
"id",
"]",
"+",
"$",
"attributes",
";",
"}",
",",
"$",
"ids",
")",
";",
"Models",
"::",
"query",
"(",
"'permissions'",
")",
"->",
"insert",
"(",
"$",
"records",
")",
";",
"}"
]
| Forbid the given abilities for everyone.
@param array $ids
@return void | [
"Forbid",
"the",
"given",
"abilities",
"for",
"everyone",
"."
]
| c2a4eb33266a36e381e09f8a3556f056e8ea996d | https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/ForbidsAbilities.php#L88-L97 | train |
thephpleague/oauth2-client | src/Grant/GrantFactory.php | GrantFactory.getGrant | public function getGrant($name)
{
if (empty($this->registry[$name])) {
$this->registerDefaultGrant($name);
}
return $this->registry[$name];
} | php | public function getGrant($name)
{
if (empty($this->registry[$name])) {
$this->registerDefaultGrant($name);
}
return $this->registry[$name];
} | [
"public",
"function",
"getGrant",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"registerDefaultGrant",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"registry",
"[",
"$",
"name",
"]",
";",
"}"
]
| Returns a grant singleton by name.
If the grant has not be registered, a default grant will be loaded.
@param string $name
@return AbstractGrant | [
"Returns",
"a",
"grant",
"singleton",
"by",
"name",
"."
]
| 552c940c65b2310615b3cc4c0328798011a7e268 | https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Grant/GrantFactory.php#L51-L58 | train |
thephpleague/oauth2-client | src/Grant/GrantFactory.php | GrantFactory.registerDefaultGrant | protected function registerDefaultGrant($name)
{
// PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'
$class = str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $name)));
$class = 'League\\OAuth2\\Client\\Grant\\' . $class;
$this->checkGrant($class);
return $this->setGrant($name, new $class);
} | php | protected function registerDefaultGrant($name)
{
// PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'
$class = str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $name)));
$class = 'League\\OAuth2\\Client\\Grant\\' . $class;
$this->checkGrant($class);
return $this->setGrant($name, new $class);
} | [
"protected",
"function",
"registerDefaultGrant",
"(",
"$",
"name",
")",
"{",
"// PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'",
"$",
"class",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",
"str_replace",
"(",
"[",
"'-'",
",",
"'_'",
"]",
",",
"' '",
",",
"$",
"name",
")",
")",
")",
";",
"$",
"class",
"=",
"'League\\\\OAuth2\\\\Client\\\\Grant\\\\'",
".",
"$",
"class",
";",
"$",
"this",
"->",
"checkGrant",
"(",
"$",
"class",
")",
";",
"return",
"$",
"this",
"->",
"setGrant",
"(",
"$",
"name",
",",
"new",
"$",
"class",
")",
";",
"}"
]
| Registers a default grant singleton by name.
@param string $name
@return self | [
"Registers",
"a",
"default",
"grant",
"singleton",
"by",
"name",
"."
]
| 552c940c65b2310615b3cc4c0328798011a7e268 | https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Grant/GrantFactory.php#L66-L75 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.