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
appzcoder/crud-generator
src/Commands/CrudApiCommand.php
CrudApiCommand.processJSONRelationships
protected function processJSONRelationships($file) { $json = File::get($file); $fields = json_decode($json); if (!property_exists($fields, 'relationships')) { return ''; } $relationsString = ''; foreach ($fields->relationships as $relation) { $relationsString .= $relation->name . '#' . $relation->type . '#' . $relation->class . ';'; } $relationsString = rtrim($relationsString, ';'); return $relationsString; }
php
protected function processJSONRelationships($file) { $json = File::get($file); $fields = json_decode($json); if (!property_exists($fields, 'relationships')) { return ''; } $relationsString = ''; foreach ($fields->relationships as $relation) { $relationsString .= $relation->name . '#' . $relation->type . '#' . $relation->class . ';'; } $relationsString = rtrim($relationsString, ';'); return $relationsString; }
[ "protected", "function", "processJSONRelationships", "(", "$", "file", ")", "{", "$", "json", "=", "File", "::", "get", "(", "$", "file", ")", ";", "$", "fields", "=", "json_decode", "(", "$", "json", ")", ";", "if", "(", "!", "property_exists", "(", "$", "fields", ",", "'relationships'", ")", ")", "{", "return", "''", ";", "}", "$", "relationsString", "=", "''", ";", "foreach", "(", "$", "fields", "->", "relationships", "as", "$", "relation", ")", "{", "$", "relationsString", ".=", "$", "relation", "->", "name", ".", "'#'", ".", "$", "relation", "->", "type", ".", "'#'", ".", "$", "relation", "->", "class", ".", "';'", ";", "}", "$", "relationsString", "=", "rtrim", "(", "$", "relationsString", ",", "';'", ")", ";", "return", "$", "relationsString", ";", "}" ]
Process the JSON Relationships. @param string $file @return string
[ "Process", "the", "JSON", "Relationships", "." ]
e086cdb6a9497ddb80c849626aa22ab1e379b4a4
https://github.com/appzcoder/crud-generator/blob/e086cdb6a9497ddb80c849626aa22ab1e379b4a4/src/Commands/CrudApiCommand.php#L226-L243
train
appzcoder/crud-generator
src/Commands/CrudApiCommand.php
CrudApiCommand.processJSONValidations
protected function processJSONValidations($file) { $json = File::get($file); $fields = json_decode($json); if (!property_exists($fields, 'validations')) { return ''; } $validationsString = ''; foreach ($fields->validations as $validation) { $validationsString .= $validation->field . '#' . $validation->rules . ';'; } $validationsString = rtrim($validationsString, ';'); return $validationsString; }
php
protected function processJSONValidations($file) { $json = File::get($file); $fields = json_decode($json); if (!property_exists($fields, 'validations')) { return ''; } $validationsString = ''; foreach ($fields->validations as $validation) { $validationsString .= $validation->field . '#' . $validation->rules . ';'; } $validationsString = rtrim($validationsString, ';'); return $validationsString; }
[ "protected", "function", "processJSONValidations", "(", "$", "file", ")", "{", "$", "json", "=", "File", "::", "get", "(", "$", "file", ")", ";", "$", "fields", "=", "json_decode", "(", "$", "json", ")", ";", "if", "(", "!", "property_exists", "(", "$", "fields", ",", "'validations'", ")", ")", "{", "return", "''", ";", "}", "$", "validationsString", "=", "''", ";", "foreach", "(", "$", "fields", "->", "validations", "as", "$", "validation", ")", "{", "$", "validationsString", ".=", "$", "validation", "->", "field", ".", "'#'", ".", "$", "validation", "->", "rules", ".", "';'", ";", "}", "$", "validationsString", "=", "rtrim", "(", "$", "validationsString", ",", "';'", ")", ";", "return", "$", "validationsString", ";", "}" ]
Process the JSON Validations. @param string $file @return string
[ "Process", "the", "JSON", "Validations", "." ]
e086cdb6a9497ddb80c849626aa22ab1e379b4a4
https://github.com/appzcoder/crud-generator/blob/e086cdb6a9497ddb80c849626aa22ab1e379b4a4/src/Commands/CrudApiCommand.php#L252-L269
train
appzcoder/crud-generator
src/Commands/CrudViewCommand.php
CrudViewCommand.templateStubs
protected function templateStubs($path) { $dynamicViewTemplate = config('crudgenerator.dynamic_view_template') ? config('crudgenerator.dynamic_view_template') : $this->defaultTemplating(); foreach ($dynamicViewTemplate as $name => $vars) { $file = $this->viewDirectoryPath . $name . '.blade.stub'; $newFile = $path . $name . '.blade.php'; if (!File::copy($file, $newFile)) { echo "failed to copy $file...\n"; } else { $this->templateVars($newFile, $vars); $this->userDefinedVars($newFile); } } }
php
protected function templateStubs($path) { $dynamicViewTemplate = config('crudgenerator.dynamic_view_template') ? config('crudgenerator.dynamic_view_template') : $this->defaultTemplating(); foreach ($dynamicViewTemplate as $name => $vars) { $file = $this->viewDirectoryPath . $name . '.blade.stub'; $newFile = $path . $name . '.blade.php'; if (!File::copy($file, $newFile)) { echo "failed to copy $file...\n"; } else { $this->templateVars($newFile, $vars); $this->userDefinedVars($newFile); } } }
[ "protected", "function", "templateStubs", "(", "$", "path", ")", "{", "$", "dynamicViewTemplate", "=", "config", "(", "'crudgenerator.dynamic_view_template'", ")", "?", "config", "(", "'crudgenerator.dynamic_view_template'", ")", ":", "$", "this", "->", "defaultTemplating", "(", ")", ";", "foreach", "(", "$", "dynamicViewTemplate", "as", "$", "name", "=>", "$", "vars", ")", "{", "$", "file", "=", "$", "this", "->", "viewDirectoryPath", ".", "$", "name", ".", "'.blade.stub'", ";", "$", "newFile", "=", "$", "path", ".", "$", "name", ".", "'.blade.php'", ";", "if", "(", "!", "File", "::", "copy", "(", "$", "file", ",", "$", "newFile", ")", ")", "{", "echo", "\"failed to copy $file...\\n\"", ";", "}", "else", "{", "$", "this", "->", "templateVars", "(", "$", "newFile", ",", "$", "vars", ")", ";", "$", "this", "->", "userDefinedVars", "(", "$", "newFile", ")", ";", "}", "}", "}" ]
Generate files from stub @param $path
[ "Generate", "files", "from", "stub" ]
e086cdb6a9497ddb80c849626aa22ab1e379b4a4
https://github.com/appzcoder/crud-generator/blob/e086cdb6a9497ddb80c849626aa22ab1e379b4a4/src/Commands/CrudViewCommand.php#L381-L397
train
appzcoder/crud-generator
src/Commands/CrudViewCommand.php
CrudViewCommand.templateVars
protected function templateVars($file, $vars) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; foreach ($vars as $var) { $replace = $start . $var . $end; if (in_array($var, $this->vars)) { File::put($file, str_replace($replace, $this->$var, File::get($file))); } } }
php
protected function templateVars($file, $vars) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; foreach ($vars as $var) { $replace = $start . $var . $end; if (in_array($var, $this->vars)) { File::put($file, str_replace($replace, $this->$var, File::get($file))); } } }
[ "protected", "function", "templateVars", "(", "$", "file", ",", "$", "vars", ")", "{", "$", "start", "=", "$", "this", "->", "delimiter", "[", "0", "]", ";", "$", "end", "=", "$", "this", "->", "delimiter", "[", "1", "]", ";", "foreach", "(", "$", "vars", "as", "$", "var", ")", "{", "$", "replace", "=", "$", "start", ".", "$", "var", ".", "$", "end", ";", "if", "(", "in_array", "(", "$", "var", ",", "$", "this", "->", "vars", ")", ")", "{", "File", "::", "put", "(", "$", "file", ",", "str_replace", "(", "$", "replace", ",", "$", "this", "->", "$", "var", ",", "File", "::", "get", "(", "$", "file", ")", ")", ")", ";", "}", "}", "}" ]
Update specified values between delimiter with real values @param $file @param $vars
[ "Update", "specified", "values", "between", "delimiter", "with", "real", "values" ]
e086cdb6a9497ddb80c849626aa22ab1e379b4a4
https://github.com/appzcoder/crud-generator/blob/e086cdb6a9497ddb80c849626aa22ab1e379b4a4/src/Commands/CrudViewCommand.php#L405-L416
train
appzcoder/crud-generator
src/Commands/CrudViewCommand.php
CrudViewCommand.userDefinedVars
protected function userDefinedVars($file) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; if ($this->customData !== null) { $customVars = explode(';', $this->customData); foreach ($customVars as $rawVar) { $arrayVar = explode('=', $rawVar); File::put($file, str_replace($start . $arrayVar[0] . $end, $arrayVar[1], File::get($file))); } } }
php
protected function userDefinedVars($file) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; if ($this->customData !== null) { $customVars = explode(';', $this->customData); foreach ($customVars as $rawVar) { $arrayVar = explode('=', $rawVar); File::put($file, str_replace($start . $arrayVar[0] . $end, $arrayVar[1], File::get($file))); } } }
[ "protected", "function", "userDefinedVars", "(", "$", "file", ")", "{", "$", "start", "=", "$", "this", "->", "delimiter", "[", "0", "]", ";", "$", "end", "=", "$", "this", "->", "delimiter", "[", "1", "]", ";", "if", "(", "$", "this", "->", "customData", "!==", "null", ")", "{", "$", "customVars", "=", "explode", "(", "';'", ",", "$", "this", "->", "customData", ")", ";", "foreach", "(", "$", "customVars", "as", "$", "rawVar", ")", "{", "$", "arrayVar", "=", "explode", "(", "'='", ",", "$", "rawVar", ")", ";", "File", "::", "put", "(", "$", "file", ",", "str_replace", "(", "$", "start", ".", "$", "arrayVar", "[", "0", "]", ".", "$", "end", ",", "$", "arrayVar", "[", "1", "]", ",", "File", "::", "get", "(", "$", "file", ")", ")", ")", ";", "}", "}", "}" ]
Update custom values between delimiter with real values @param $file
[ "Update", "custom", "values", "between", "delimiter", "with", "real", "values" ]
e086cdb6a9497ddb80c849626aa22ab1e379b4a4
https://github.com/appzcoder/crud-generator/blob/e086cdb6a9497ddb80c849626aa22ab1e379b4a4/src/Commands/CrudViewCommand.php#L423-L435
train
appzcoder/crud-generator
src/Commands/CrudViewCommand.php
CrudViewCommand.createPasswordField
protected function createPasswordField($item) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; $required = $item['required'] ? 'required' : ''; $markup = File::get($this->viewDirectoryPath . 'form-fields/password-field.blade.stub'); $markup = str_replace($start . 'required' . $end, $required, $markup); $markup = str_replace($start . 'itemName' . $end, $item['name'], $markup); $markup = str_replace($start . 'crudNameSingular' . $end, $this->crudNameSingular, $markup); return $this->wrapField( $item, $markup ); }
php
protected function createPasswordField($item) { $start = $this->delimiter[0]; $end = $this->delimiter[1]; $required = $item['required'] ? 'required' : ''; $markup = File::get($this->viewDirectoryPath . 'form-fields/password-field.blade.stub'); $markup = str_replace($start . 'required' . $end, $required, $markup); $markup = str_replace($start . 'itemName' . $end, $item['name'], $markup); $markup = str_replace($start . 'crudNameSingular' . $end, $this->crudNameSingular, $markup); return $this->wrapField( $item, $markup ); }
[ "protected", "function", "createPasswordField", "(", "$", "item", ")", "{", "$", "start", "=", "$", "this", "->", "delimiter", "[", "0", "]", ";", "$", "end", "=", "$", "this", "->", "delimiter", "[", "1", "]", ";", "$", "required", "=", "$", "item", "[", "'required'", "]", "?", "'required'", ":", "''", ";", "$", "markup", "=", "File", "::", "get", "(", "$", "this", "->", "viewDirectoryPath", ".", "'form-fields/password-field.blade.stub'", ")", ";", "$", "markup", "=", "str_replace", "(", "$", "start", ".", "'required'", ".", "$", "end", ",", "$", "required", ",", "$", "markup", ")", ";", "$", "markup", "=", "str_replace", "(", "$", "start", ".", "'itemName'", ".", "$", "end", ",", "$", "item", "[", "'name'", "]", ",", "$", "markup", ")", ";", "$", "markup", "=", "str_replace", "(", "$", "start", ".", "'crudNameSingular'", ".", "$", "end", ",", "$", "this", "->", "crudNameSingular", ",", "$", "markup", ")", ";", "return", "$", "this", "->", "wrapField", "(", "$", "item", ",", "$", "markup", ")", ";", "}" ]
Create a password field using the form helper. @param array $item @return string
[ "Create", "a", "password", "field", "using", "the", "form", "helper", "." ]
e086cdb6a9497ddb80c849626aa22ab1e379b4a4
https://github.com/appzcoder/crud-generator/blob/e086cdb6a9497ddb80c849626aa22ab1e379b4a4/src/Commands/CrudViewCommand.php#L518-L534
train
appzcoder/crud-generator
src/Commands/CrudControllerCommand.php
CrudControllerCommand.replaceModelNamespaceSegments
protected function replaceModelNamespaceSegments(&$stub, $modelNamespace) { $modelSegments = explode('\\', $modelNamespace); foreach ($modelSegments as $key => $segment) { $stub = str_replace('{{modelNamespace[' . $key . ']}}', $segment, $stub); } $stub = preg_replace('{{modelNamespace\[\d*\]}}', '', $stub); return $this; }
php
protected function replaceModelNamespaceSegments(&$stub, $modelNamespace) { $modelSegments = explode('\\', $modelNamespace); foreach ($modelSegments as $key => $segment) { $stub = str_replace('{{modelNamespace[' . $key . ']}}', $segment, $stub); } $stub = preg_replace('{{modelNamespace\[\d*\]}}', '', $stub); return $this; }
[ "protected", "function", "replaceModelNamespaceSegments", "(", "&", "$", "stub", ",", "$", "modelNamespace", ")", "{", "$", "modelSegments", "=", "explode", "(", "'\\\\'", ",", "$", "modelNamespace", ")", ";", "foreach", "(", "$", "modelSegments", "as", "$", "key", "=>", "$", "segment", ")", "{", "$", "stub", "=", "str_replace", "(", "'{{modelNamespace['", ".", "$", "key", ".", "']}}'", ",", "$", "segment", ",", "$", "stub", ")", ";", "}", "$", "stub", "=", "preg_replace", "(", "'{{modelNamespace\\[\\d*\\]}}'", ",", "''", ",", "$", "stub", ")", ";", "return", "$", "this", ";", "}" ]
Replace the modelNamespace segments for the given stub @param $stub @param $modelNamespace @return $this
[ "Replace", "the", "modelNamespace", "segments", "for", "the", "given", "stub" ]
e086cdb6a9497ddb80c849626aa22ab1e379b4a4
https://github.com/appzcoder/crud-generator/blob/e086cdb6a9497ddb80c849626aa22ab1e379b4a4/src/Commands/CrudControllerCommand.php#L281-L291
train
appzcoder/crud-generator
src/Commands/CrudLangCommand.php
CrudLangCommand.templateVars
private function templateVars($newLangFile) { $messages = []; foreach ($this->formFields as $field) { $index = $field['name']; $text = ucwords(strtolower(str_replace('_', ' ', $index))); $messages[] = "'$index' => '$text'"; } File::put($newLangFile, str_replace('%%messages%%', implode(",\n", $messages), File::get($newLangFile))); }
php
private function templateVars($newLangFile) { $messages = []; foreach ($this->formFields as $field) { $index = $field['name']; $text = ucwords(strtolower(str_replace('_', ' ', $index))); $messages[] = "'$index' => '$text'"; } File::put($newLangFile, str_replace('%%messages%%', implode(",\n", $messages), File::get($newLangFile))); }
[ "private", "function", "templateVars", "(", "$", "newLangFile", ")", "{", "$", "messages", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "formFields", "as", "$", "field", ")", "{", "$", "index", "=", "$", "field", "[", "'name'", "]", ";", "$", "text", "=", "ucwords", "(", "strtolower", "(", "str_replace", "(", "'_'", ",", "' '", ",", "$", "index", ")", ")", ")", ";", "$", "messages", "[", "]", "=", "\"'$index' => '$text'\"", ";", "}", "File", "::", "put", "(", "$", "newLangFile", ",", "str_replace", "(", "'%%messages%%'", ",", "implode", "(", "\",\\n\"", ",", "$", "messages", ")", ",", "File", "::", "get", "(", "$", "newLangFile", ")", ")", ")", ";", "}" ]
Translate form's fields. @param string $newLangFile @return void
[ "Translate", "form", "s", "fields", "." ]
e086cdb6a9497ddb80c849626aa22ab1e379b4a4
https://github.com/appzcoder/crud-generator/blob/e086cdb6a9497ddb80c849626aa22ab1e379b4a4/src/Commands/CrudLangCommand.php#L115-L125
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/Syntax/Table.php
Table.getItems
protected function getItems(array $items) { $result = array(); foreach($items as $item) { $result[] = $this->getItem($item); } return $result; }
php
protected function getItems(array $items) { $result = array(); foreach($items as $item) { $result[] = $this->getItem($item); } return $result; }
[ "protected", "function", "getItems", "(", "array", "$", "items", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "result", "[", "]", "=", "$", "this", "->", "getItem", "(", "$", "item", ")", ";", "}", "return", "$", "result", ";", "}" ]
Return string for adding all foreign keys @param array $items @return array
[ "Return", "string", "for", "adding", "all", "foreign", "keys" ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/Syntax/Table.php#L37-L44
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/Generators/ForeignKeyGenerator.php
ForeignKeyGenerator.generate
public function generate($table, $schema, $ignoreForeignKeyNames) { $this->table = $table; $fields = []; $foreignKeys = $schema->listTableForeignKeys($table); if ( empty( $foreignKeys ) ) return array(); foreach ( $foreignKeys as $foreignKey ) { $fields[] = [ 'name' => $this->getName($foreignKey, $ignoreForeignKeyNames), 'field' => $foreignKey->getLocalColumns()[0], 'references' => $foreignKey->getForeignColumns()[0], 'on' => $foreignKey->getForeignTableName(), 'onUpdate' => $foreignKey->hasOption('onUpdate') ? $foreignKey->getOption('onUpdate') : 'RESTRICT', 'onDelete' => $foreignKey->hasOption('onDelete') ? $foreignKey->getOption('onDelete') : 'RESTRICT', ]; } return $fields; }
php
public function generate($table, $schema, $ignoreForeignKeyNames) { $this->table = $table; $fields = []; $foreignKeys = $schema->listTableForeignKeys($table); if ( empty( $foreignKeys ) ) return array(); foreach ( $foreignKeys as $foreignKey ) { $fields[] = [ 'name' => $this->getName($foreignKey, $ignoreForeignKeyNames), 'field' => $foreignKey->getLocalColumns()[0], 'references' => $foreignKey->getForeignColumns()[0], 'on' => $foreignKey->getForeignTableName(), 'onUpdate' => $foreignKey->hasOption('onUpdate') ? $foreignKey->getOption('onUpdate') : 'RESTRICT', 'onDelete' => $foreignKey->hasOption('onDelete') ? $foreignKey->getOption('onDelete') : 'RESTRICT', ]; } return $fields; }
[ "public", "function", "generate", "(", "$", "table", ",", "$", "schema", ",", "$", "ignoreForeignKeyNames", ")", "{", "$", "this", "->", "table", "=", "$", "table", ";", "$", "fields", "=", "[", "]", ";", "$", "foreignKeys", "=", "$", "schema", "->", "listTableForeignKeys", "(", "$", "table", ")", ";", "if", "(", "empty", "(", "$", "foreignKeys", ")", ")", "return", "array", "(", ")", ";", "foreach", "(", "$", "foreignKeys", "as", "$", "foreignKey", ")", "{", "$", "fields", "[", "]", "=", "[", "'name'", "=>", "$", "this", "->", "getName", "(", "$", "foreignKey", ",", "$", "ignoreForeignKeyNames", ")", ",", "'field'", "=>", "$", "foreignKey", "->", "getLocalColumns", "(", ")", "[", "0", "]", ",", "'references'", "=>", "$", "foreignKey", "->", "getForeignColumns", "(", ")", "[", "0", "]", ",", "'on'", "=>", "$", "foreignKey", "->", "getForeignTableName", "(", ")", ",", "'onUpdate'", "=>", "$", "foreignKey", "->", "hasOption", "(", "'onUpdate'", ")", "?", "$", "foreignKey", "->", "getOption", "(", "'onUpdate'", ")", ":", "'RESTRICT'", ",", "'onDelete'", "=>", "$", "foreignKey", "->", "hasOption", "(", "'onDelete'", ")", "?", "$", "foreignKey", "->", "getOption", "(", "'onDelete'", ")", ":", "'RESTRICT'", ",", "]", ";", "}", "return", "$", "fields", ";", "}" ]
Get array of foreign keys @param string $table Table Name @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema @param $ignoreForeignKeyNames @return array
[ "Get", "array", "of", "foreign", "keys" ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/Generators/ForeignKeyGenerator.php#L19-L39
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php
MigrateGenerateCommand.askNumeric
protected function askNumeric( $question, $default = null ) { $ask = 'Your answer needs to be a numeric value'; if ( ! is_null( $default ) ) { $question .= ' [Default: '. $default .'] '; $ask .= ' or blank for default'; } $answer = $this->ask( $question ); while ( ! is_numeric( $answer ) and ! ( $answer == '' and ! is_null( $default ) ) ) { $answer = $this->ask( $ask .'. '); } if ( $answer == '' ) { $answer = $default; } return $answer; }
php
protected function askNumeric( $question, $default = null ) { $ask = 'Your answer needs to be a numeric value'; if ( ! is_null( $default ) ) { $question .= ' [Default: '. $default .'] '; $ask .= ' or blank for default'; } $answer = $this->ask( $question ); while ( ! is_numeric( $answer ) and ! ( $answer == '' and ! is_null( $default ) ) ) { $answer = $this->ask( $ask .'. '); } if ( $answer == '' ) { $answer = $default; } return $answer; }
[ "protected", "function", "askNumeric", "(", "$", "question", ",", "$", "default", "=", "null", ")", "{", "$", "ask", "=", "'Your answer needs to be a numeric value'", ";", "if", "(", "!", "is_null", "(", "$", "default", ")", ")", "{", "$", "question", ".=", "' [Default: '", ".", "$", "default", ".", "'] '", ";", "$", "ask", ".=", "' or blank for default'", ";", "}", "$", "answer", "=", "$", "this", "->", "ask", "(", "$", "question", ")", ";", "while", "(", "!", "is_numeric", "(", "$", "answer", ")", "and", "!", "(", "$", "answer", "==", "''", "and", "!", "is_null", "(", "$", "default", ")", ")", ")", "{", "$", "answer", "=", "$", "this", "->", "ask", "(", "$", "ask", ".", "'. '", ")", ";", "}", "if", "(", "$", "answer", "==", "''", ")", "{", "$", "answer", "=", "$", "default", ";", "}", "return", "$", "answer", ";", "}" ]
Ask user for a Numeric Value, or blank for default @param string $question Question to ask @param int|float $default Default Value (optional) @return int|float Answer
[ "Ask", "user", "for", "a", "Numeric", "Value", "or", "blank", "for", "default" ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php#L211-L228
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php
MigrateGenerateCommand.generateTablesAndIndices
protected function generateTablesAndIndices( array $tables ) { $this->method = 'create'; foreach ( $tables as $table ) { $this->table = $table; $this->migrationName = 'create_'. $this->table .'_table'; $this->fields = $this->schemaGenerator->getFields( $this->table ); $this->generate(); } }
php
protected function generateTablesAndIndices( array $tables ) { $this->method = 'create'; foreach ( $tables as $table ) { $this->table = $table; $this->migrationName = 'create_'. $this->table .'_table'; $this->fields = $this->schemaGenerator->getFields( $this->table ); $this->generate(); } }
[ "protected", "function", "generateTablesAndIndices", "(", "array", "$", "tables", ")", "{", "$", "this", "->", "method", "=", "'create'", ";", "foreach", "(", "$", "tables", "as", "$", "table", ")", "{", "$", "this", "->", "table", "=", "$", "table", ";", "$", "this", "->", "migrationName", "=", "'create_'", ".", "$", "this", "->", "table", ".", "'_table'", ";", "$", "this", "->", "fields", "=", "$", "this", "->", "schemaGenerator", "->", "getFields", "(", "$", "this", "->", "table", ")", ";", "$", "this", "->", "generate", "(", ")", ";", "}", "}" ]
Generate tables and index migrations. @param array $tables List of tables to create migrations for @return void
[ "Generate", "tables", "and", "index", "migrations", "." ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php#L236-L247
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php
MigrateGenerateCommand.generateForeignKeys
protected function generateForeignKeys( array $tables ) { $this->method = 'table'; foreach ( $tables as $table ) { $this->table = $table; $this->migrationName = 'add_foreign_keys_to_'. $this->table .'_table'; $this->fields = $this->schemaGenerator->getForeignKeyConstraints( $this->table ); $this->generate(); } }
php
protected function generateForeignKeys( array $tables ) { $this->method = 'table'; foreach ( $tables as $table ) { $this->table = $table; $this->migrationName = 'add_foreign_keys_to_'. $this->table .'_table'; $this->fields = $this->schemaGenerator->getForeignKeyConstraints( $this->table ); $this->generate(); } }
[ "protected", "function", "generateForeignKeys", "(", "array", "$", "tables", ")", "{", "$", "this", "->", "method", "=", "'table'", ";", "foreach", "(", "$", "tables", "as", "$", "table", ")", "{", "$", "this", "->", "table", "=", "$", "table", ";", "$", "this", "->", "migrationName", "=", "'add_foreign_keys_to_'", ".", "$", "this", "->", "table", ".", "'_table'", ";", "$", "this", "->", "fields", "=", "$", "this", "->", "schemaGenerator", "->", "getForeignKeyConstraints", "(", "$", "this", "->", "table", ")", ";", "$", "this", "->", "generate", "(", ")", ";", "}", "}" ]
Generate foreign key migrations. @param array $tables List of tables to create migrations for @return void
[ "Generate", "foreign", "key", "migrations", "." ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php#L255-L266
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php
MigrateGenerateCommand.generate
protected function generate() { if ( $this->fields ) { parent::fire(); if ( $this->log ) { $file = $this->datePrefix . '_' . $this->migrationName; $this->repository->log($file, $this->batch); } } }
php
protected function generate() { if ( $this->fields ) { parent::fire(); if ( $this->log ) { $file = $this->datePrefix . '_' . $this->migrationName; $this->repository->log($file, $this->batch); } } }
[ "protected", "function", "generate", "(", ")", "{", "if", "(", "$", "this", "->", "fields", ")", "{", "parent", "::", "fire", "(", ")", ";", "if", "(", "$", "this", "->", "log", ")", "{", "$", "file", "=", "$", "this", "->", "datePrefix", ".", "'_'", ".", "$", "this", "->", "migrationName", ";", "$", "this", "->", "repository", "->", "log", "(", "$", "file", ",", "$", "this", "->", "batch", ")", ";", "}", "}", "}" ]
Generate Migration for the current table. @return void
[ "Generate", "Migration", "for", "the", "current", "table", "." ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php#L273-L283
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php
MigrateGenerateCommand.getFileGenerationPath
protected function getFileGenerationPath() { $path = $this->getPathByOptionOrConfig( 'path', 'migration_target_path' ); $migrationName = str_replace('/', '_', $this->migrationName); $fileName = $this->getDatePrefix() . '_' . $migrationName . '.php'; return "{$path}/{$fileName}"; }
php
protected function getFileGenerationPath() { $path = $this->getPathByOptionOrConfig( 'path', 'migration_target_path' ); $migrationName = str_replace('/', '_', $this->migrationName); $fileName = $this->getDatePrefix() . '_' . $migrationName . '.php'; return "{$path}/{$fileName}"; }
[ "protected", "function", "getFileGenerationPath", "(", ")", "{", "$", "path", "=", "$", "this", "->", "getPathByOptionOrConfig", "(", "'path'", ",", "'migration_target_path'", ")", ";", "$", "migrationName", "=", "str_replace", "(", "'/'", ",", "'_'", ",", "$", "this", "->", "migrationName", ")", ";", "$", "fileName", "=", "$", "this", "->", "getDatePrefix", "(", ")", ".", "'_'", ".", "$", "migrationName", ".", "'.php'", ";", "return", "\"{$path}/{$fileName}\"", ";", "}" ]
The path where the file will be created @return string
[ "The", "path", "where", "the", "file", "will", "be", "created" ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php#L290-L297
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php
MigrateGenerateCommand.removeExcludedTables
protected function removeExcludedTables( array $tables ) { $excludes = $this->getExcludedTables(); $tables = array_diff($tables, $excludes); return $tables; }
php
protected function removeExcludedTables( array $tables ) { $excludes = $this->getExcludedTables(); $tables = array_diff($tables, $excludes); return $tables; }
[ "protected", "function", "removeExcludedTables", "(", "array", "$", "tables", ")", "{", "$", "excludes", "=", "$", "this", "->", "getExcludedTables", "(", ")", ";", "$", "tables", "=", "array_diff", "(", "$", "tables", ",", "$", "excludes", ")", ";", "return", "$", "tables", ";", "}" ]
Remove all the tables to exclude from the array of tables @param array $tables @return array
[ "Remove", "all", "the", "tables", "to", "exclude", "from", "the", "array", "of", "tables" ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php#L380-L386
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php
MigrateGenerateCommand.getExcludedTables
protected function getExcludedTables() { $excludes = ['migrations']; $ignore = $this->option('ignore'); if ( ! empty($ignore)) { return array_merge($excludes, explode(',', $ignore)); } return $excludes; }
php
protected function getExcludedTables() { $excludes = ['migrations']; $ignore = $this->option('ignore'); if ( ! empty($ignore)) { return array_merge($excludes, explode(',', $ignore)); } return $excludes; }
[ "protected", "function", "getExcludedTables", "(", ")", "{", "$", "excludes", "=", "[", "'migrations'", "]", ";", "$", "ignore", "=", "$", "this", "->", "option", "(", "'ignore'", ")", ";", "if", "(", "!", "empty", "(", "$", "ignore", ")", ")", "{", "return", "array_merge", "(", "$", "excludes", ",", "explode", "(", "','", ",", "$", "ignore", ")", ")", ";", "}", "return", "$", "excludes", ";", "}" ]
Get a list of tables to exclude @return array
[ "Get", "a", "list", "of", "tables", "to", "exclude" ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php#L393-L402
train
Xethron/migrations-generator
src/Xethron/MigrationsGenerator/Generators/FieldGenerator.php
FieldGenerator.getEnum
protected function getEnum($table) { try { $result = DB::table('information_schema.columns') ->where('table_schema', $this->database) ->where('table_name', $table) ->where('data_type', 'enum') ->get(['column_name','column_type']); if ($result) return $result; else return []; } catch (\Exception $e){ return []; } }
php
protected function getEnum($table) { try { $result = DB::table('information_schema.columns') ->where('table_schema', $this->database) ->where('table_name', $table) ->where('data_type', 'enum') ->get(['column_name','column_type']); if ($result) return $result; else return []; } catch (\Exception $e){ return []; } }
[ "protected", "function", "getEnum", "(", "$", "table", ")", "{", "try", "{", "$", "result", "=", "DB", "::", "table", "(", "'information_schema.columns'", ")", "->", "where", "(", "'table_schema'", ",", "$", "this", "->", "database", ")", "->", "where", "(", "'table_name'", ",", "$", "table", ")", "->", "where", "(", "'data_type'", ",", "'enum'", ")", "->", "get", "(", "[", "'column_name'", ",", "'column_type'", "]", ")", ";", "if", "(", "$", "result", ")", "return", "$", "result", ";", "else", "return", "[", "]", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "[", "]", ";", "}", "}" ]
Return all enum columns for a given table @param string $table @return array
[ "Return", "all", "enum", "columns", "for", "a", "given", "table" ]
a05bd7319ed808fcc3125212e37d30ccbe0d2b8b
https://github.com/Xethron/migrations-generator/blob/a05bd7319ed808fcc3125212e37d30ccbe0d2b8b/src/Xethron/MigrationsGenerator/Generators/FieldGenerator.php#L51-L66
train
amphp/amp
lib/Loop/Driver.php
Driver.run
public function run() { $this->running = true; try { while ($this->running) { if ($this->isEmpty()) { return; } $this->tick(); } } finally { $this->stop(); } }
php
public function run() { $this->running = true; try { while ($this->running) { if ($this->isEmpty()) { return; } $this->tick(); } } finally { $this->stop(); } }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "running", "=", "true", ";", "try", "{", "while", "(", "$", "this", "->", "running", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "$", "this", "->", "tick", "(", ")", ";", "}", "}", "finally", "{", "$", "this", "->", "stop", "(", ")", ";", "}", "}" ]
Run the event loop. One iteration of the loop is called one "tick". A tick covers the following steps: 1. Activate watchers created / enabled in the last tick / before `run()`. 2. Execute all enabled defer watchers. 3. Execute all due timer, pending signal and actionable stream callbacks, each only once per tick. The loop MUST continue to run until it is either stopped explicitly, no referenced watchers exist anymore, or an exception is thrown that cannot be handled. Exceptions that cannot be handled are exceptions thrown from an error handler or exceptions that would be passed to an error handler but none exists to handle them. @return void
[ "Run", "the", "event", "loop", "." ]
4e822395c9d6c768aedddfde22903ededcfe0e0e
https://github.com/amphp/amp/blob/4e822395c9d6c768aedddfde22903ededcfe0e0e/lib/Loop/Driver.php#L63-L77
train
amphp/amp
lib/Loop/Driver.php
Driver.error
protected function error(\Throwable $exception) { if ($this->errorHandler === null) { throw $exception; } ($this->errorHandler)($exception); }
php
protected function error(\Throwable $exception) { if ($this->errorHandler === null) { throw $exception; } ($this->errorHandler)($exception); }
[ "protected", "function", "error", "(", "\\", "Throwable", "$", "exception", ")", "{", "if", "(", "$", "this", "->", "errorHandler", "===", "null", ")", "{", "throw", "$", "exception", ";", "}", "(", "$", "this", "->", "errorHandler", ")", "(", "$", "exception", ")", ";", "}" ]
Invokes the error handler with the given exception. @param \Throwable $exception The exception thrown from a watcher callback. @throws \Throwable If no error handler has been set.
[ "Invokes", "the", "error", "handler", "with", "the", "given", "exception", "." ]
4e822395c9d6c768aedddfde22903ededcfe0e0e
https://github.com/amphp/amp/blob/4e822395c9d6c768aedddfde22903ededcfe0e0e/lib/Loop/Driver.php#L584-L591
train
amphp/amp
lib/Loop/Driver.php
Driver.getInfo
public function getInfo(): array { $watchers = [ "referenced" => 0, "unreferenced" => 0, ]; $defer = $delay = $repeat = $onReadable = $onWritable = $onSignal = [ "enabled" => 0, "disabled" => 0, ]; foreach ($this->watchers as $watcher) { switch ($watcher->type) { case Watcher::READABLE: $array = &$onReadable; break; case Watcher::WRITABLE: $array = &$onWritable; break; case Watcher::SIGNAL: $array = &$onSignal; break; case Watcher::DEFER: $array = &$defer; break; case Watcher::DELAY: $array = &$delay; break; case Watcher::REPEAT: $array = &$repeat; break; default: // @codeCoverageIgnoreStart throw new \Error("Unknown watcher type"); // @codeCoverageIgnoreEnd } if ($watcher->enabled) { ++$array["enabled"]; if ($watcher->referenced) { ++$watchers["referenced"]; } else { ++$watchers["unreferenced"]; } } else { ++$array["disabled"]; } } return [ "enabled_watchers" => $watchers, "defer" => $defer, "delay" => $delay, "repeat" => $repeat, "on_readable" => $onReadable, "on_writable" => $onWritable, "on_signal" => $onSignal, "running" => (bool) $this->running, ]; }
php
public function getInfo(): array { $watchers = [ "referenced" => 0, "unreferenced" => 0, ]; $defer = $delay = $repeat = $onReadable = $onWritable = $onSignal = [ "enabled" => 0, "disabled" => 0, ]; foreach ($this->watchers as $watcher) { switch ($watcher->type) { case Watcher::READABLE: $array = &$onReadable; break; case Watcher::WRITABLE: $array = &$onWritable; break; case Watcher::SIGNAL: $array = &$onSignal; break; case Watcher::DEFER: $array = &$defer; break; case Watcher::DELAY: $array = &$delay; break; case Watcher::REPEAT: $array = &$repeat; break; default: // @codeCoverageIgnoreStart throw new \Error("Unknown watcher type"); // @codeCoverageIgnoreEnd } if ($watcher->enabled) { ++$array["enabled"]; if ($watcher->referenced) { ++$watchers["referenced"]; } else { ++$watchers["unreferenced"]; } } else { ++$array["disabled"]; } } return [ "enabled_watchers" => $watchers, "defer" => $defer, "delay" => $delay, "repeat" => $repeat, "on_readable" => $onReadable, "on_writable" => $onWritable, "on_signal" => $onSignal, "running" => (bool) $this->running, ]; }
[ "public", "function", "getInfo", "(", ")", ":", "array", "{", "$", "watchers", "=", "[", "\"referenced\"", "=>", "0", ",", "\"unreferenced\"", "=>", "0", ",", "]", ";", "$", "defer", "=", "$", "delay", "=", "$", "repeat", "=", "$", "onReadable", "=", "$", "onWritable", "=", "$", "onSignal", "=", "[", "\"enabled\"", "=>", "0", ",", "\"disabled\"", "=>", "0", ",", "]", ";", "foreach", "(", "$", "this", "->", "watchers", "as", "$", "watcher", ")", "{", "switch", "(", "$", "watcher", "->", "type", ")", "{", "case", "Watcher", "::", "READABLE", ":", "$", "array", "=", "&", "$", "onReadable", ";", "break", ";", "case", "Watcher", "::", "WRITABLE", ":", "$", "array", "=", "&", "$", "onWritable", ";", "break", ";", "case", "Watcher", "::", "SIGNAL", ":", "$", "array", "=", "&", "$", "onSignal", ";", "break", ";", "case", "Watcher", "::", "DEFER", ":", "$", "array", "=", "&", "$", "defer", ";", "break", ";", "case", "Watcher", "::", "DELAY", ":", "$", "array", "=", "&", "$", "delay", ";", "break", ";", "case", "Watcher", "::", "REPEAT", ":", "$", "array", "=", "&", "$", "repeat", ";", "break", ";", "default", ":", "// @codeCoverageIgnoreStart", "throw", "new", "\\", "Error", "(", "\"Unknown watcher type\"", ")", ";", "// @codeCoverageIgnoreEnd", "}", "if", "(", "$", "watcher", "->", "enabled", ")", "{", "++", "$", "array", "[", "\"enabled\"", "]", ";", "if", "(", "$", "watcher", "->", "referenced", ")", "{", "++", "$", "watchers", "[", "\"referenced\"", "]", ";", "}", "else", "{", "++", "$", "watchers", "[", "\"unreferenced\"", "]", ";", "}", "}", "else", "{", "++", "$", "array", "[", "\"disabled\"", "]", ";", "}", "}", "return", "[", "\"enabled_watchers\"", "=>", "$", "watchers", ",", "\"defer\"", "=>", "$", "defer", ",", "\"delay\"", "=>", "$", "delay", ",", "\"repeat\"", "=>", "$", "repeat", ",", "\"on_readable\"", "=>", "$", "onReadable", ",", "\"on_writable\"", "=>", "$", "onWritable", ",", "\"on_signal\"", "=>", "$", "onSignal", ",", "\"running\"", "=>", "(", "bool", ")", "$", "this", "->", "running", ",", "]", ";", "}" ]
Retrieve an associative array of information about the event loop driver. The returned array MUST contain the following data describing the driver's currently registered watchers: [ "defer" => ["enabled" => int, "disabled" => int], "delay" => ["enabled" => int, "disabled" => int], "repeat" => ["enabled" => int, "disabled" => int], "on_readable" => ["enabled" => int, "disabled" => int], "on_writable" => ["enabled" => int, "disabled" => int], "on_signal" => ["enabled" => int, "disabled" => int], "enabled_watchers" => ["referenced" => int, "unreferenced" => int], "running" => bool ]; Implementations MAY optionally add more information in the array but at minimum the above `key => value` format MUST always be provided. @return array Statistics about the loop in the described format.
[ "Retrieve", "an", "associative", "array", "of", "information", "about", "the", "event", "loop", "driver", "." ]
4e822395c9d6c768aedddfde22903ededcfe0e0e
https://github.com/amphp/amp/blob/4e822395c9d6c768aedddfde22903ededcfe0e0e/lib/Loop/Driver.php#L652-L714
train
amphp/amp
lib/Internal/Producer.php
Producer.emit
private function emit($value): Promise { if ($this->complete) { throw new \Error("Iterators cannot emit values after calling complete"); } if ($value instanceof ReactPromise) { $value = Promise\adapt($value); } if ($value instanceof Promise) { $deferred = new Deferred; $value->onResolve(function ($e, $v) use ($deferred) { if ($this->complete) { $deferred->fail( new \Error("The iterator was completed before the promise result could be emitted") ); return; } if ($e) { $this->fail($e); $deferred->fail($e); return; } $deferred->resolve($this->emit($v)); }); return $deferred->promise(); } $this->values[] = $value; $this->backPressure[] = $pressure = new Deferred; if ($this->waiting !== null) { $waiting = $this->waiting; $this->waiting = null; $waiting->resolve(true); } return $pressure->promise(); }
php
private function emit($value): Promise { if ($this->complete) { throw new \Error("Iterators cannot emit values after calling complete"); } if ($value instanceof ReactPromise) { $value = Promise\adapt($value); } if ($value instanceof Promise) { $deferred = new Deferred; $value->onResolve(function ($e, $v) use ($deferred) { if ($this->complete) { $deferred->fail( new \Error("The iterator was completed before the promise result could be emitted") ); return; } if ($e) { $this->fail($e); $deferred->fail($e); return; } $deferred->resolve($this->emit($v)); }); return $deferred->promise(); } $this->values[] = $value; $this->backPressure[] = $pressure = new Deferred; if ($this->waiting !== null) { $waiting = $this->waiting; $this->waiting = null; $waiting->resolve(true); } return $pressure->promise(); }
[ "private", "function", "emit", "(", "$", "value", ")", ":", "Promise", "{", "if", "(", "$", "this", "->", "complete", ")", "{", "throw", "new", "\\", "Error", "(", "\"Iterators cannot emit values after calling complete\"", ")", ";", "}", "if", "(", "$", "value", "instanceof", "ReactPromise", ")", "{", "$", "value", "=", "Promise", "\\", "adapt", "(", "$", "value", ")", ";", "}", "if", "(", "$", "value", "instanceof", "Promise", ")", "{", "$", "deferred", "=", "new", "Deferred", ";", "$", "value", "->", "onResolve", "(", "function", "(", "$", "e", ",", "$", "v", ")", "use", "(", "$", "deferred", ")", "{", "if", "(", "$", "this", "->", "complete", ")", "{", "$", "deferred", "->", "fail", "(", "new", "\\", "Error", "(", "\"The iterator was completed before the promise result could be emitted\"", ")", ")", ";", "return", ";", "}", "if", "(", "$", "e", ")", "{", "$", "this", "->", "fail", "(", "$", "e", ")", ";", "$", "deferred", "->", "fail", "(", "$", "e", ")", ";", "return", ";", "}", "$", "deferred", "->", "resolve", "(", "$", "this", "->", "emit", "(", "$", "v", ")", ")", ";", "}", ")", ";", "return", "$", "deferred", "->", "promise", "(", ")", ";", "}", "$", "this", "->", "values", "[", "]", "=", "$", "value", ";", "$", "this", "->", "backPressure", "[", "]", "=", "$", "pressure", "=", "new", "Deferred", ";", "if", "(", "$", "this", "->", "waiting", "!==", "null", ")", "{", "$", "waiting", "=", "$", "this", "->", "waiting", ";", "$", "this", "->", "waiting", "=", "null", ";", "$", "waiting", "->", "resolve", "(", "true", ")", ";", "}", "return", "$", "pressure", "->", "promise", "(", ")", ";", "}" ]
Emits a value from the iterator. The returned promise is resolved with the emitted value once all listeners have been invoked. @param mixed $value @return \Amp\Promise @throws \Error If the iterator has completed.
[ "Emits", "a", "value", "from", "the", "iterator", ".", "The", "returned", "promise", "is", "resolved", "with", "the", "emitted", "value", "once", "all", "listeners", "have", "been", "invoked", "." ]
4e822395c9d6c768aedddfde22903ededcfe0e0e
https://github.com/amphp/amp/blob/4e822395c9d6c768aedddfde22903ededcfe0e0e/lib/Internal/Producer.php#L94-L136
train
amphp/amp
lib/Internal/Producer.php
Producer.complete
private function complete() { if ($this->complete) { $message = "Iterator has already been completed"; if (isset($this->resolutionTrace)) { $trace = formatStacktrace($this->resolutionTrace); $message .= ". Previous completion trace:\n\n{$trace}\n\n"; } else { // @codeCoverageIgnoreStart $message .= ", define environment variable AMP_DEBUG or const AMP_DEBUG = true and enable assertions " . "for a stacktrace of the previous resolution."; // @codeCoverageIgnoreEnd } throw new \Error($message); } \assert((function () { $env = \getenv("AMP_DEBUG") ?: "0"; if (($env !== "0" && $env !== "false") || (\defined("AMP_DEBUG") && \AMP_DEBUG)) { $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); \array_shift($trace); // remove current closure $this->resolutionTrace = $trace; } return true; })()); $this->complete = new Success(false); if ($this->waiting !== null) { $waiting = $this->waiting; $this->waiting = null; $waiting->resolve($this->complete); } }
php
private function complete() { if ($this->complete) { $message = "Iterator has already been completed"; if (isset($this->resolutionTrace)) { $trace = formatStacktrace($this->resolutionTrace); $message .= ". Previous completion trace:\n\n{$trace}\n\n"; } else { // @codeCoverageIgnoreStart $message .= ", define environment variable AMP_DEBUG or const AMP_DEBUG = true and enable assertions " . "for a stacktrace of the previous resolution."; // @codeCoverageIgnoreEnd } throw new \Error($message); } \assert((function () { $env = \getenv("AMP_DEBUG") ?: "0"; if (($env !== "0" && $env !== "false") || (\defined("AMP_DEBUG") && \AMP_DEBUG)) { $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); \array_shift($trace); // remove current closure $this->resolutionTrace = $trace; } return true; })()); $this->complete = new Success(false); if ($this->waiting !== null) { $waiting = $this->waiting; $this->waiting = null; $waiting->resolve($this->complete); } }
[ "private", "function", "complete", "(", ")", "{", "if", "(", "$", "this", "->", "complete", ")", "{", "$", "message", "=", "\"Iterator has already been completed\"", ";", "if", "(", "isset", "(", "$", "this", "->", "resolutionTrace", ")", ")", "{", "$", "trace", "=", "formatStacktrace", "(", "$", "this", "->", "resolutionTrace", ")", ";", "$", "message", ".=", "\". Previous completion trace:\\n\\n{$trace}\\n\\n\"", ";", "}", "else", "{", "// @codeCoverageIgnoreStart", "$", "message", ".=", "\", define environment variable AMP_DEBUG or const AMP_DEBUG = true and enable assertions \"", ".", "\"for a stacktrace of the previous resolution.\"", ";", "// @codeCoverageIgnoreEnd", "}", "throw", "new", "\\", "Error", "(", "$", "message", ")", ";", "}", "\\", "assert", "(", "(", "function", "(", ")", "{", "$", "env", "=", "\\", "getenv", "(", "\"AMP_DEBUG\"", ")", "?", ":", "\"0\"", ";", "if", "(", "(", "$", "env", "!==", "\"0\"", "&&", "$", "env", "!==", "\"false\"", ")", "||", "(", "\\", "defined", "(", "\"AMP_DEBUG\"", ")", "&&", "\\", "AMP_DEBUG", ")", ")", "{", "$", "trace", "=", "\\", "debug_backtrace", "(", "\\", "DEBUG_BACKTRACE_IGNORE_ARGS", ")", ";", "\\", "array_shift", "(", "$", "trace", ")", ";", "// remove current closure", "$", "this", "->", "resolutionTrace", "=", "$", "trace", ";", "}", "return", "true", ";", "}", ")", "(", ")", ")", ";", "$", "this", "->", "complete", "=", "new", "Success", "(", "false", ")", ";", "if", "(", "$", "this", "->", "waiting", "!==", "null", ")", "{", "$", "waiting", "=", "$", "this", "->", "waiting", ";", "$", "this", "->", "waiting", "=", "null", ";", "$", "waiting", "->", "resolve", "(", "$", "this", "->", "complete", ")", ";", "}", "}" ]
Completes the iterator. @throws \Error If the iterator has already been completed.
[ "Completes", "the", "iterator", "." ]
4e822395c9d6c768aedddfde22903ededcfe0e0e
https://github.com/amphp/amp/blob/4e822395c9d6c768aedddfde22903ededcfe0e0e/lib/Internal/Producer.php#L143-L179
train
amphp/amp
lib/Loop.php
Loop.run
public static function run(callable $callback = null) { if ($callback) { self::$driver->defer($callback); } self::$driver->run(); }
php
public static function run(callable $callback = null) { if ($callback) { self::$driver->defer($callback); } self::$driver->run(); }
[ "public", "static", "function", "run", "(", "callable", "$", "callback", "=", "null", ")", "{", "if", "(", "$", "callback", ")", "{", "self", "::", "$", "driver", "->", "defer", "(", "$", "callback", ")", ";", "}", "self", "::", "$", "driver", "->", "run", "(", ")", ";", "}" ]
Run the event loop and optionally execute a callback within the scope of it. The loop MUST continue to run until it is either stopped explicitly, no referenced watchers exist anymore, or an exception is thrown that cannot be handled. Exceptions that cannot be handled are exceptions thrown from an error handler or exceptions that would be passed to an error handler but none exists to handle them. @param callable|null $callback The callback to execute. @return void
[ "Run", "the", "event", "loop", "and", "optionally", "execute", "a", "callback", "within", "the", "scope", "of", "it", "." ]
4e822395c9d6c768aedddfde22903ededcfe0e0e
https://github.com/amphp/amp/blob/4e822395c9d6c768aedddfde22903ededcfe0e0e/lib/Loop.php#L78-L85
train
amphp/amp
lib/Loop/DriverFactory.php
DriverFactory.create
public function create(): Driver { if ($driver = $this->createDriverFromEnv()) { return $driver; } if (UvDriver::isSupported()) { return new UvDriver; } if (EvDriver::isSupported()) { return new EvDriver; } if (EventDriver::isSupported()) { return new EventDriver; } return new NativeDriver; }
php
public function create(): Driver { if ($driver = $this->createDriverFromEnv()) { return $driver; } if (UvDriver::isSupported()) { return new UvDriver; } if (EvDriver::isSupported()) { return new EvDriver; } if (EventDriver::isSupported()) { return new EventDriver; } return new NativeDriver; }
[ "public", "function", "create", "(", ")", ":", "Driver", "{", "if", "(", "$", "driver", "=", "$", "this", "->", "createDriverFromEnv", "(", ")", ")", "{", "return", "$", "driver", ";", "}", "if", "(", "UvDriver", "::", "isSupported", "(", ")", ")", "{", "return", "new", "UvDriver", ";", "}", "if", "(", "EvDriver", "::", "isSupported", "(", ")", ")", "{", "return", "new", "EvDriver", ";", "}", "if", "(", "EventDriver", "::", "isSupported", "(", ")", ")", "{", "return", "new", "EventDriver", ";", "}", "return", "new", "NativeDriver", ";", "}" ]
Creates a new loop instance and chooses the best available driver. @return Driver @throws \Error If an invalid class has been specified via AMP_LOOP_DRIVER
[ "Creates", "a", "new", "loop", "instance", "and", "chooses", "the", "best", "available", "driver", "." ]
4e822395c9d6c768aedddfde22903ededcfe0e0e
https://github.com/amphp/amp/blob/4e822395c9d6c768aedddfde22903ededcfe0e0e/lib/Loop/DriverFactory.php#L15-L34
train
owen-it/laravel-auditing
src/Console/InstallCommand.php
InstallCommand.registerAuditingServiceProvider
protected function registerAuditingServiceProvider() { $namespace = str_replace_last('\\', '', $this->getAppNamespace()); $appConfig = file_get_contents(config_path('app.php')); if (Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) { return; } file_put_contents(config_path('app.php'), str_replace( "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL, "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL." OwenIt\Auditing\AuditingServiceProvider::class,".PHP_EOL, $appConfig )); }
php
protected function registerAuditingServiceProvider() { $namespace = str_replace_last('\\', '', $this->getAppNamespace()); $appConfig = file_get_contents(config_path('app.php')); if (Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) { return; } file_put_contents(config_path('app.php'), str_replace( "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL, "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL." OwenIt\Auditing\AuditingServiceProvider::class,".PHP_EOL, $appConfig )); }
[ "protected", "function", "registerAuditingServiceProvider", "(", ")", "{", "$", "namespace", "=", "str_replace_last", "(", "'\\\\'", ",", "''", ",", "$", "this", "->", "getAppNamespace", "(", ")", ")", ";", "$", "appConfig", "=", "file_get_contents", "(", "config_path", "(", "'app.php'", ")", ")", ";", "if", "(", "Str", "::", "contains", "(", "$", "appConfig", ",", "'OwenIt\\\\Auditing\\\\AuditingServiceProvider::class'", ")", ")", "{", "return", ";", "}", "file_put_contents", "(", "config_path", "(", "'app.php'", ")", ",", "str_replace", "(", "\"{$namespace}\\\\Providers\\EventServiceProvider::class,\"", ".", "PHP_EOL", ",", "\"{$namespace}\\\\Providers\\EventServiceProvider::class,\"", ".", "PHP_EOL", ".", "\" OwenIt\\Auditing\\AuditingServiceProvider::class,\"", ".", "PHP_EOL", ",", "$", "appConfig", ")", ")", ";", "}" ]
Register the Auditing service provider in the application configuration file. @return void
[ "Register", "the", "Auditing", "service", "provider", "in", "the", "application", "configuration", "file", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Console/InstallCommand.php#L44-L59
train
owen-it/laravel-auditing
src/Audit.php
Audit.getFormattedValue
protected function getFormattedValue(Model $model, string $key, $value) { // Apply defined get mutator if ($model->hasGetMutator($key)) { return $model->mutateAttribute($key, $value); } // Cast to native PHP type if ($model->hasCast($key)) { return $model->castAttribute($key, $value); } // Honour DateTime attribute if ($value !== null && in_array($key, $model->getDates(), true)) { return $model->asDateTime($value); } return $value; }
php
protected function getFormattedValue(Model $model, string $key, $value) { // Apply defined get mutator if ($model->hasGetMutator($key)) { return $model->mutateAttribute($key, $value); } // Cast to native PHP type if ($model->hasCast($key)) { return $model->castAttribute($key, $value); } // Honour DateTime attribute if ($value !== null && in_array($key, $model->getDates(), true)) { return $model->asDateTime($value); } return $value; }
[ "protected", "function", "getFormattedValue", "(", "Model", "$", "model", ",", "string", "$", "key", ",", "$", "value", ")", "{", "// Apply defined get mutator", "if", "(", "$", "model", "->", "hasGetMutator", "(", "$", "key", ")", ")", "{", "return", "$", "model", "->", "mutateAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", "// Cast to native PHP type", "if", "(", "$", "model", "->", "hasCast", "(", "$", "key", ")", ")", "{", "return", "$", "model", "->", "castAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", "// Honour DateTime attribute", "if", "(", "$", "value", "!==", "null", "&&", "in_array", "(", "$", "key", ",", "$", "model", "->", "getDates", "(", ")", ",", "true", ")", ")", "{", "return", "$", "model", "->", "asDateTime", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Get the formatted value of an Eloquent model. @param Model $model @param string $key @param mixed $value @return mixed
[ "Get", "the", "formatted", "value", "of", "an", "Eloquent", "model", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Audit.php#L117-L135
train
owen-it/laravel-auditing
src/Audit.php
Audit.decodeAttributeValue
protected function decodeAttributeValue(Contracts\Auditable $auditable, string $attribute, $value) { $attributeModifiers = $auditable->getAttributeModifiers(); if (!array_key_exists($attribute, $attributeModifiers)) { return $value; } $attributeDecoder = $attributeModifiers[$attribute]; if (is_subclass_of($attributeDecoder, AttributeEncoder::class)) { return call_user_func([$attributeDecoder, 'decode'], $value); } return $value; }
php
protected function decodeAttributeValue(Contracts\Auditable $auditable, string $attribute, $value) { $attributeModifiers = $auditable->getAttributeModifiers(); if (!array_key_exists($attribute, $attributeModifiers)) { return $value; } $attributeDecoder = $attributeModifiers[$attribute]; if (is_subclass_of($attributeDecoder, AttributeEncoder::class)) { return call_user_func([$attributeDecoder, 'decode'], $value); } return $value; }
[ "protected", "function", "decodeAttributeValue", "(", "Contracts", "\\", "Auditable", "$", "auditable", ",", "string", "$", "attribute", ",", "$", "value", ")", "{", "$", "attributeModifiers", "=", "$", "auditable", "->", "getAttributeModifiers", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "attribute", ",", "$", "attributeModifiers", ")", ")", "{", "return", "$", "value", ";", "}", "$", "attributeDecoder", "=", "$", "attributeModifiers", "[", "$", "attribute", "]", ";", "if", "(", "is_subclass_of", "(", "$", "attributeDecoder", ",", "AttributeEncoder", "::", "class", ")", ")", "{", "return", "call_user_func", "(", "[", "$", "attributeDecoder", ",", "'decode'", "]", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Decode attribute value. @param Contracts\Auditable $auditable @param string $attribute @param mixed $value @return mixed
[ "Decode", "attribute", "value", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Audit.php#L176-L191
train
owen-it/laravel-auditing
src/Auditable.php
Auditable.resolveAuditExclusions
protected function resolveAuditExclusions() { $this->excludedAttributes = $this->getAuditExclude(); // When in strict mode, hidden and non visible attributes are excluded if ($this->getAuditStrict()) { // Hidden attributes $this->excludedAttributes = array_merge($this->excludedAttributes, $this->hidden); // Non visible attributes if ($this->visible) { $invisible = array_diff(array_keys($this->attributes), $this->visible); $this->excludedAttributes = array_merge($this->excludedAttributes, $invisible); } } // Exclude Timestamps if (!$this->getAuditTimestamps()) { array_push($this->excludedAttributes, $this->getCreatedAtColumn(), $this->getUpdatedAtColumn()); if (in_array(SoftDeletes::class, class_uses_recursive(get_class($this)))) { $this->excludedAttributes[] = $this->getDeletedAtColumn(); } } // Valid attributes are all those that made it out of the exclusion array $attributes = Arr::except($this->attributes, $this->excludedAttributes); foreach ($attributes as $attribute => $value) { // Apart from null, non scalar values will be excluded if (is_array($value) || (is_object($value) && !method_exists($value, '__toString'))) { $this->excludedAttributes[] = $attribute; } } }
php
protected function resolveAuditExclusions() { $this->excludedAttributes = $this->getAuditExclude(); // When in strict mode, hidden and non visible attributes are excluded if ($this->getAuditStrict()) { // Hidden attributes $this->excludedAttributes = array_merge($this->excludedAttributes, $this->hidden); // Non visible attributes if ($this->visible) { $invisible = array_diff(array_keys($this->attributes), $this->visible); $this->excludedAttributes = array_merge($this->excludedAttributes, $invisible); } } // Exclude Timestamps if (!$this->getAuditTimestamps()) { array_push($this->excludedAttributes, $this->getCreatedAtColumn(), $this->getUpdatedAtColumn()); if (in_array(SoftDeletes::class, class_uses_recursive(get_class($this)))) { $this->excludedAttributes[] = $this->getDeletedAtColumn(); } } // Valid attributes are all those that made it out of the exclusion array $attributes = Arr::except($this->attributes, $this->excludedAttributes); foreach ($attributes as $attribute => $value) { // Apart from null, non scalar values will be excluded if (is_array($value) || (is_object($value) && !method_exists($value, '__toString'))) { $this->excludedAttributes[] = $attribute; } } }
[ "protected", "function", "resolveAuditExclusions", "(", ")", "{", "$", "this", "->", "excludedAttributes", "=", "$", "this", "->", "getAuditExclude", "(", ")", ";", "// When in strict mode, hidden and non visible attributes are excluded", "if", "(", "$", "this", "->", "getAuditStrict", "(", ")", ")", "{", "// Hidden attributes", "$", "this", "->", "excludedAttributes", "=", "array_merge", "(", "$", "this", "->", "excludedAttributes", ",", "$", "this", "->", "hidden", ")", ";", "// Non visible attributes", "if", "(", "$", "this", "->", "visible", ")", "{", "$", "invisible", "=", "array_diff", "(", "array_keys", "(", "$", "this", "->", "attributes", ")", ",", "$", "this", "->", "visible", ")", ";", "$", "this", "->", "excludedAttributes", "=", "array_merge", "(", "$", "this", "->", "excludedAttributes", ",", "$", "invisible", ")", ";", "}", "}", "// Exclude Timestamps", "if", "(", "!", "$", "this", "->", "getAuditTimestamps", "(", ")", ")", "{", "array_push", "(", "$", "this", "->", "excludedAttributes", ",", "$", "this", "->", "getCreatedAtColumn", "(", ")", ",", "$", "this", "->", "getUpdatedAtColumn", "(", ")", ")", ";", "if", "(", "in_array", "(", "SoftDeletes", "::", "class", ",", "class_uses_recursive", "(", "get_class", "(", "$", "this", ")", ")", ")", ")", "{", "$", "this", "->", "excludedAttributes", "[", "]", "=", "$", "this", "->", "getDeletedAtColumn", "(", ")", ";", "}", "}", "// Valid attributes are all those that made it out of the exclusion array", "$", "attributes", "=", "Arr", "::", "except", "(", "$", "this", "->", "attributes", ",", "$", "this", "->", "excludedAttributes", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "attribute", "=>", "$", "value", ")", "{", "// Apart from null, non scalar values will be excluded", "if", "(", "is_array", "(", "$", "value", ")", "||", "(", "is_object", "(", "$", "value", ")", "&&", "!", "method_exists", "(", "$", "value", ",", "'__toString'", ")", ")", ")", "{", "$", "this", "->", "excludedAttributes", "[", "]", "=", "$", "attribute", ";", "}", "}", "}" ]
Resolve the Auditable attributes to exclude from the Audit. @return void
[ "Resolve", "the", "Auditable", "attributes", "to", "exclude", "from", "the", "Audit", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditable.php#L70-L105
train
owen-it/laravel-auditing
src/Auditable.php
Auditable.modifyAttributeValue
protected function modifyAttributeValue(string $attribute, $value) { $attributeModifiers = $this->getAttributeModifiers(); if (!array_key_exists($attribute, $attributeModifiers)) { return $value; } $attributeModifier = $attributeModifiers[$attribute]; if (is_subclass_of($attributeModifier, AttributeRedactor::class)) { return call_user_func([$attributeModifier, 'redact'], $value); } if (is_subclass_of($attributeModifier, AttributeEncoder::class)) { return call_user_func([$attributeModifier, 'encode'], $value); } throw new AuditingException(sprintf('Invalid AttributeModifier implementation: %s', $attributeModifier)); }
php
protected function modifyAttributeValue(string $attribute, $value) { $attributeModifiers = $this->getAttributeModifiers(); if (!array_key_exists($attribute, $attributeModifiers)) { return $value; } $attributeModifier = $attributeModifiers[$attribute]; if (is_subclass_of($attributeModifier, AttributeRedactor::class)) { return call_user_func([$attributeModifier, 'redact'], $value); } if (is_subclass_of($attributeModifier, AttributeEncoder::class)) { return call_user_func([$attributeModifier, 'encode'], $value); } throw new AuditingException(sprintf('Invalid AttributeModifier implementation: %s', $attributeModifier)); }
[ "protected", "function", "modifyAttributeValue", "(", "string", "$", "attribute", ",", "$", "value", ")", "{", "$", "attributeModifiers", "=", "$", "this", "->", "getAttributeModifiers", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "attribute", ",", "$", "attributeModifiers", ")", ")", "{", "return", "$", "value", ";", "}", "$", "attributeModifier", "=", "$", "attributeModifiers", "[", "$", "attribute", "]", ";", "if", "(", "is_subclass_of", "(", "$", "attributeModifier", ",", "AttributeRedactor", "::", "class", ")", ")", "{", "return", "call_user_func", "(", "[", "$", "attributeModifier", ",", "'redact'", "]", ",", "$", "value", ")", ";", "}", "if", "(", "is_subclass_of", "(", "$", "attributeModifier", ",", "AttributeEncoder", "::", "class", ")", ")", "{", "return", "call_user_func", "(", "[", "$", "attributeModifier", ",", "'encode'", "]", ",", "$", "value", ")", ";", "}", "throw", "new", "AuditingException", "(", "sprintf", "(", "'Invalid AttributeModifier implementation: %s'", ",", "$", "attributeModifier", ")", ")", ";", "}" ]
Modify attribute value. @param string $attribute @param mixed $value @throws AuditingException @return mixed
[ "Modify", "attribute", "value", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditable.php#L221-L240
train
owen-it/laravel-auditing
src/Auditable.php
Auditable.resolveUser
protected function resolveUser() { $userResolver = Config::get('audit.resolver.user'); if (is_subclass_of($userResolver, UserResolver::class)) { return call_user_func([$userResolver, 'resolve']); } throw new AuditingException('Invalid UserResolver implementation'); }
php
protected function resolveUser() { $userResolver = Config::get('audit.resolver.user'); if (is_subclass_of($userResolver, UserResolver::class)) { return call_user_func([$userResolver, 'resolve']); } throw new AuditingException('Invalid UserResolver implementation'); }
[ "protected", "function", "resolveUser", "(", ")", "{", "$", "userResolver", "=", "Config", "::", "get", "(", "'audit.resolver.user'", ")", ";", "if", "(", "is_subclass_of", "(", "$", "userResolver", ",", "UserResolver", "::", "class", ")", ")", "{", "return", "call_user_func", "(", "[", "$", "userResolver", ",", "'resolve'", "]", ")", ";", "}", "throw", "new", "AuditingException", "(", "'Invalid UserResolver implementation'", ")", ";", "}" ]
Resolve the User. @throws AuditingException @return mixed|null
[ "Resolve", "the", "User", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditable.php#L311-L320
train
owen-it/laravel-auditing
src/Auditable.php
Auditable.resolveUrl
protected function resolveUrl(): string { $urlResolver = Config::get('audit.resolver.url'); if (is_subclass_of($urlResolver, UrlResolver::class)) { return call_user_func([$urlResolver, 'resolve']); } throw new AuditingException('Invalid UrlResolver implementation'); }
php
protected function resolveUrl(): string { $urlResolver = Config::get('audit.resolver.url'); if (is_subclass_of($urlResolver, UrlResolver::class)) { return call_user_func([$urlResolver, 'resolve']); } throw new AuditingException('Invalid UrlResolver implementation'); }
[ "protected", "function", "resolveUrl", "(", ")", ":", "string", "{", "$", "urlResolver", "=", "Config", "::", "get", "(", "'audit.resolver.url'", ")", ";", "if", "(", "is_subclass_of", "(", "$", "urlResolver", ",", "UrlResolver", "::", "class", ")", ")", "{", "return", "call_user_func", "(", "[", "$", "urlResolver", ",", "'resolve'", "]", ")", ";", "}", "throw", "new", "AuditingException", "(", "'Invalid UrlResolver implementation'", ")", ";", "}" ]
Resolve the URL. @throws AuditingException @return string
[ "Resolve", "the", "URL", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditable.php#L329-L338
train
owen-it/laravel-auditing
src/Auditable.php
Auditable.resolveIpAddress
protected function resolveIpAddress(): string { $ipAddressResolver = Config::get('audit.resolver.ip_address'); if (is_subclass_of($ipAddressResolver, IpAddressResolver::class)) { return call_user_func([$ipAddressResolver, 'resolve']); } throw new AuditingException('Invalid IpAddressResolver implementation'); }
php
protected function resolveIpAddress(): string { $ipAddressResolver = Config::get('audit.resolver.ip_address'); if (is_subclass_of($ipAddressResolver, IpAddressResolver::class)) { return call_user_func([$ipAddressResolver, 'resolve']); } throw new AuditingException('Invalid IpAddressResolver implementation'); }
[ "protected", "function", "resolveIpAddress", "(", ")", ":", "string", "{", "$", "ipAddressResolver", "=", "Config", "::", "get", "(", "'audit.resolver.ip_address'", ")", ";", "if", "(", "is_subclass_of", "(", "$", "ipAddressResolver", ",", "IpAddressResolver", "::", "class", ")", ")", "{", "return", "call_user_func", "(", "[", "$", "ipAddressResolver", ",", "'resolve'", "]", ")", ";", "}", "throw", "new", "AuditingException", "(", "'Invalid IpAddressResolver implementation'", ")", ";", "}" ]
Resolve the IP Address. @throws AuditingException @return string
[ "Resolve", "the", "IP", "Address", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditable.php#L347-L356
train
owen-it/laravel-auditing
src/Auditable.php
Auditable.resolveUserAgent
protected function resolveUserAgent() { $userAgentResolver = Config::get('audit.resolver.user_agent'); if (is_subclass_of($userAgentResolver, UserAgentResolver::class)) { return call_user_func([$userAgentResolver, 'resolve']); } throw new AuditingException('Invalid UserAgentResolver implementation'); }
php
protected function resolveUserAgent() { $userAgentResolver = Config::get('audit.resolver.user_agent'); if (is_subclass_of($userAgentResolver, UserAgentResolver::class)) { return call_user_func([$userAgentResolver, 'resolve']); } throw new AuditingException('Invalid UserAgentResolver implementation'); }
[ "protected", "function", "resolveUserAgent", "(", ")", "{", "$", "userAgentResolver", "=", "Config", "::", "get", "(", "'audit.resolver.user_agent'", ")", ";", "if", "(", "is_subclass_of", "(", "$", "userAgentResolver", ",", "UserAgentResolver", "::", "class", ")", ")", "{", "return", "call_user_func", "(", "[", "$", "userAgentResolver", ",", "'resolve'", "]", ")", ";", "}", "throw", "new", "AuditingException", "(", "'Invalid UserAgentResolver implementation'", ")", ";", "}" ]
Resolve the User Agent. @throws AuditingException @return string|null
[ "Resolve", "the", "User", "Agent", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditable.php#L365-L374
train
owen-it/laravel-auditing
src/Auditable.php
Auditable.resolveAttributeGetter
protected function resolveAttributeGetter($event) { foreach ($this->getAuditEvents() as $key => $value) { $auditableEvent = is_int($key) ? $value : $key; $auditableEventRegex = sprintf('/%s/', preg_replace('/\*+/', '.*', $auditableEvent)); if (preg_match($auditableEventRegex, $event)) { return is_int($key) ? sprintf('get%sEventAttributes', ucfirst($event)) : $value; } } }
php
protected function resolveAttributeGetter($event) { foreach ($this->getAuditEvents() as $key => $value) { $auditableEvent = is_int($key) ? $value : $key; $auditableEventRegex = sprintf('/%s/', preg_replace('/\*+/', '.*', $auditableEvent)); if (preg_match($auditableEventRegex, $event)) { return is_int($key) ? sprintf('get%sEventAttributes', ucfirst($event)) : $value; } } }
[ "protected", "function", "resolveAttributeGetter", "(", "$", "event", ")", "{", "foreach", "(", "$", "this", "->", "getAuditEvents", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "auditableEvent", "=", "is_int", "(", "$", "key", ")", "?", "$", "value", ":", "$", "key", ";", "$", "auditableEventRegex", "=", "sprintf", "(", "'/%s/'", ",", "preg_replace", "(", "'/\\*+/'", ",", "'.*'", ",", "$", "auditableEvent", ")", ")", ";", "if", "(", "preg_match", "(", "$", "auditableEventRegex", ",", "$", "event", ")", ")", "{", "return", "is_int", "(", "$", "key", ")", "?", "sprintf", "(", "'get%sEventAttributes'", ",", "ucfirst", "(", "$", "event", ")", ")", ":", "$", "value", ";", "}", "}", "}" ]
Attribute getter method resolver. @param string $event @return string|null
[ "Attribute", "getter", "method", "resolver", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditable.php#L416-L427
train
owen-it/laravel-auditing
src/Auditable.php
Auditable.isAuditingEnabled
public static function isAuditingEnabled(): bool { if (App::runningInConsole()) { return Config::get('audit.console', false); } return Config::get('audit.enabled', true); }
php
public static function isAuditingEnabled(): bool { if (App::runningInConsole()) { return Config::get('audit.console', false); } return Config::get('audit.enabled', true); }
[ "public", "static", "function", "isAuditingEnabled", "(", ")", ":", "bool", "{", "if", "(", "App", "::", "runningInConsole", "(", ")", ")", "{", "return", "Config", "::", "get", "(", "'audit.console'", ",", "false", ")", ";", "}", "return", "Config", "::", "get", "(", "'audit.enabled'", ",", "true", ")", ";", "}" ]
Determine whether auditing is enabled. @return bool
[ "Determine", "whether", "auditing", "is", "enabled", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditable.php#L485-L492
train
owen-it/laravel-auditing
src/Auditor.php
Auditor.fireAuditingEvent
protected function fireAuditingEvent(Auditable $model, AuditDriver $driver): bool { return $this->app->make('events')->until( new Auditing($model, $driver) ) !== false; }
php
protected function fireAuditingEvent(Auditable $model, AuditDriver $driver): bool { return $this->app->make('events')->until( new Auditing($model, $driver) ) !== false; }
[ "protected", "function", "fireAuditingEvent", "(", "Auditable", "$", "model", ",", "AuditDriver", "$", "driver", ")", ":", "bool", "{", "return", "$", "this", "->", "app", "->", "make", "(", "'events'", ")", "->", "until", "(", "new", "Auditing", "(", "$", "model", ",", "$", "driver", ")", ")", "!==", "false", ";", "}" ]
Fire the Auditing event. @param \OwenIt\Auditing\Contracts\Auditable $model @param \OwenIt\Auditing\Contracts\AuditDriver $driver @return bool
[ "Fire", "the", "Auditing", "event", "." ]
0379d973c34e00138eb8ac7196c6661980564f72
https://github.com/owen-it/laravel-auditing/blob/0379d973c34e00138eb8ac7196c6661980564f72/src/Auditor.php#L96-L101
train
JosephSilber/bouncer
src/Database/Concerns/IsAbility.php
IsAbility.bootIsAbility
public static function bootIsAbility() { BaseTenantScope::register(static::class); static::creating(function ($ability) { Models::scope()->applyToModel($ability); if (is_null($ability->title)) { $ability->title = AbilityTitle::from($ability)->toString(); } }); }
php
public static function bootIsAbility() { BaseTenantScope::register(static::class); static::creating(function ($ability) { Models::scope()->applyToModel($ability); if (is_null($ability->title)) { $ability->title = AbilityTitle::from($ability)->toString(); } }); }
[ "public", "static", "function", "bootIsAbility", "(", ")", "{", "BaseTenantScope", "::", "register", "(", "static", "::", "class", ")", ";", "static", "::", "creating", "(", "function", "(", "$", "ability", ")", "{", "Models", "::", "scope", "(", ")", "->", "applyToModel", "(", "$", "ability", ")", ";", "if", "(", "is_null", "(", "$", "ability", "->", "title", ")", ")", "{", "$", "ability", "->", "title", "=", "AbilityTitle", "::", "from", "(", "$", "ability", ")", "->", "toString", "(", ")", ";", "}", "}", ")", ";", "}" ]
Boot the is ability trait. @return void
[ "Boot", "the", "is", "ability", "trait", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsAbility.php#L21-L32
train
JosephSilber/bouncer
src/Database/Concerns/IsAbility.php
IsAbility.getConstraints
public function getConstraints() { if (empty($this->options['constraints'])) { return new Group(); } $data = $this->options['constraints']; return $data['class']::fromData($data['params']); }
php
public function getConstraints() { if (empty($this->options['constraints'])) { return new Group(); } $data = $this->options['constraints']; return $data['class']::fromData($data['params']); }
[ "public", "function", "getConstraints", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "options", "[", "'constraints'", "]", ")", ")", "{", "return", "new", "Group", "(", ")", ";", "}", "$", "data", "=", "$", "this", "->", "options", "[", "'constraints'", "]", ";", "return", "$", "data", "[", "'class'", "]", "::", "fromData", "(", "$", "data", "[", "'params'", "]", ")", ";", "}" ]
Get the ability's constraints. @return \Silber\Bouncer\Constraints\Constrainer
[ "Get", "the", "ability", "s", "constraints", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsAbility.php#L74-L83
train
JosephSilber/bouncer
src/Database/Concerns/IsAbility.php
IsAbility.setConstraints
public function setConstraints(Constrainer $constrainer) { $this->options = array_merge($this->options, [ 'constraints' => $constrainer->data(), ]); return $this; }
php
public function setConstraints(Constrainer $constrainer) { $this->options = array_merge($this->options, [ 'constraints' => $constrainer->data(), ]); return $this; }
[ "public", "function", "setConstraints", "(", "Constrainer", "$", "constrainer", ")", "{", "$", "this", "->", "options", "=", "array_merge", "(", "$", "this", "->", "options", ",", "[", "'constraints'", "=>", "$", "constrainer", "->", "data", "(", ")", ",", "]", ")", ";", "return", "$", "this", ";", "}" ]
Set the ability's constraints. @param \Silber\Bouncer\Constraints\Constrainer $constrainer @return $this
[ "Set", "the", "ability", "s", "constraints", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsAbility.php#L91-L98
train
JosephSilber/bouncer
src/Database/Concerns/IsAbility.php
IsAbility.createForModel
public static function createForModel($model, $attributes) { $model = static::makeForModel($model, $attributes); $model->save(); return $model; }
php
public static function createForModel($model, $attributes) { $model = static::makeForModel($model, $attributes); $model->save(); return $model; }
[ "public", "static", "function", "createForModel", "(", "$", "model", ",", "$", "attributes", ")", "{", "$", "model", "=", "static", "::", "makeForModel", "(", "$", "model", ",", "$", "attributes", ")", ";", "$", "model", "->", "save", "(", ")", ";", "return", "$", "model", ";", "}" ]
Create a new ability for a specific model. @param \Illuminate\Database\Eloquent\Model|string $model @param string|array $attributes @return static
[ "Create", "a", "new", "ability", "for", "a", "specific", "model", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsAbility.php#L107-L114
train
JosephSilber/bouncer
src/Database/Concerns/IsAbility.php
IsAbility.makeForModel
public static function makeForModel($model, $attributes) { if (is_string($attributes)) { $attributes = ['name' => $attributes]; } if ($model === '*') { return (new static)->forceFill($attributes + [ 'entity_type' => '*', ]); } if (is_string($model)) { $model = new $model; } return (new static)->forceFill($attributes + [ 'entity_type' => $model->getMorphClass(), 'entity_id' => $model->exists ? $model->getKey() : null, ]); }
php
public static function makeForModel($model, $attributes) { if (is_string($attributes)) { $attributes = ['name' => $attributes]; } if ($model === '*') { return (new static)->forceFill($attributes + [ 'entity_type' => '*', ]); } if (is_string($model)) { $model = new $model; } return (new static)->forceFill($attributes + [ 'entity_type' => $model->getMorphClass(), 'entity_id' => $model->exists ? $model->getKey() : null, ]); }
[ "public", "static", "function", "makeForModel", "(", "$", "model", ",", "$", "attributes", ")", "{", "if", "(", "is_string", "(", "$", "attributes", ")", ")", "{", "$", "attributes", "=", "[", "'name'", "=>", "$", "attributes", "]", ";", "}", "if", "(", "$", "model", "===", "'*'", ")", "{", "return", "(", "new", "static", ")", "->", "forceFill", "(", "$", "attributes", "+", "[", "'entity_type'", "=>", "'*'", ",", "]", ")", ";", "}", "if", "(", "is_string", "(", "$", "model", ")", ")", "{", "$", "model", "=", "new", "$", "model", ";", "}", "return", "(", "new", "static", ")", "->", "forceFill", "(", "$", "attributes", "+", "[", "'entity_type'", "=>", "$", "model", "->", "getMorphClass", "(", ")", ",", "'entity_id'", "=>", "$", "model", "->", "exists", "?", "$", "model", "->", "getKey", "(", ")", ":", "null", ",", "]", ")", ";", "}" ]
Make a new ability for a specific model. @param \Illuminate\Database\Eloquent\Model|string $model @param string|array $attributes @return static
[ "Make", "a", "new", "ability", "for", "a", "specific", "model", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsAbility.php#L123-L143
train
JosephSilber/bouncer
src/Database/Concerns/IsAbility.php
IsAbility.getIdentifierAttribute
final public function getIdentifierAttribute() { $slug = $this->attributes['name']; if ($this->attributes['entity_type']) { $slug .= '-'.$this->attributes['entity_type']; } if ($this->attributes['entity_id']) { $slug .= '-'.$this->attributes['entity_id']; } if ($this->attributes['only_owned']) { $slug .= '-owned'; } return strtolower($slug); }
php
final public function getIdentifierAttribute() { $slug = $this->attributes['name']; if ($this->attributes['entity_type']) { $slug .= '-'.$this->attributes['entity_type']; } if ($this->attributes['entity_id']) { $slug .= '-'.$this->attributes['entity_id']; } if ($this->attributes['only_owned']) { $slug .= '-owned'; } return strtolower($slug); }
[ "final", "public", "function", "getIdentifierAttribute", "(", ")", "{", "$", "slug", "=", "$", "this", "->", "attributes", "[", "'name'", "]", ";", "if", "(", "$", "this", "->", "attributes", "[", "'entity_type'", "]", ")", "{", "$", "slug", ".=", "'-'", ".", "$", "this", "->", "attributes", "[", "'entity_type'", "]", ";", "}", "if", "(", "$", "this", "->", "attributes", "[", "'entity_id'", "]", ")", "{", "$", "slug", ".=", "'-'", ".", "$", "this", "->", "attributes", "[", "'entity_id'", "]", ";", "}", "if", "(", "$", "this", "->", "attributes", "[", "'only_owned'", "]", ")", "{", "$", "slug", ".=", "'-owned'", ";", "}", "return", "strtolower", "(", "$", "slug", ")", ";", "}" ]
Get the identifier for this ability. @return string
[ "Get", "the", "identifier", "for", "this", "ability", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsAbility.php#L182-L199
train
JosephSilber/bouncer
src/Database/Concerns/IsAbility.php
IsAbility.scopeByName
public function scopeByName($query, $name, $strict = false) { $names = (array) $name; if (! $strict && $name !== '*') { $names[] = '*'; } $query->whereIn("{$this->table}.name", $names); }
php
public function scopeByName($query, $name, $strict = false) { $names = (array) $name; if (! $strict && $name !== '*') { $names[] = '*'; } $query->whereIn("{$this->table}.name", $names); }
[ "public", "function", "scopeByName", "(", "$", "query", ",", "$", "name", ",", "$", "strict", "=", "false", ")", "{", "$", "names", "=", "(", "array", ")", "$", "name", ";", "if", "(", "!", "$", "strict", "&&", "$", "name", "!==", "'*'", ")", "{", "$", "names", "[", "]", "=", "'*'", ";", "}", "$", "query", "->", "whereIn", "(", "\"{$this->table}.name\"", ",", "$", "names", ")", ";", "}" ]
Constrain a query to having the given name. @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query @return string|array $name @return bool $strict @return void
[ "Constrain", "a", "query", "to", "having", "the", "given", "name", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/IsAbility.php#L219-L228
train
JosephSilber/bouncer
src/Conductors/RemovesRoles.php
RemovesRoles.from
public function from($authority) { if (! ($roleIds = $this->getRoleIds())) { return; } $authorities = is_array($authority) ? $authority : [$authority]; foreach (Helpers::mapAuthorityByClass($authorities) as $class => $keys) { $this->retractRoles($roleIds, $class, $keys); } }
php
public function from($authority) { if (! ($roleIds = $this->getRoleIds())) { return; } $authorities = is_array($authority) ? $authority : [$authority]; foreach (Helpers::mapAuthorityByClass($authorities) as $class => $keys) { $this->retractRoles($roleIds, $class, $keys); } }
[ "public", "function", "from", "(", "$", "authority", ")", "{", "if", "(", "!", "(", "$", "roleIds", "=", "$", "this", "->", "getRoleIds", "(", ")", ")", ")", "{", "return", ";", "}", "$", "authorities", "=", "is_array", "(", "$", "authority", ")", "?", "$", "authority", ":", "[", "$", "authority", "]", ";", "foreach", "(", "Helpers", "::", "mapAuthorityByClass", "(", "$", "authorities", ")", "as", "$", "class", "=>", "$", "keys", ")", "{", "$", "this", "->", "retractRoles", "(", "$", "roleIds", ",", "$", "class", ",", "$", "keys", ")", ";", "}", "}" ]
Remove the role from the given authority. @param \Illuminate\Database\Eloquent\Model|array|int $authority @return void
[ "Remove", "the", "role", "from", "the", "given", "authority", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/RemovesRoles.php#L35-L46
train
JosephSilber/bouncer
src/Conductors/RemovesRoles.php
RemovesRoles.getRoleIds
protected function getRoleIds() { list($models, $names) = Helpers::partition($this->roles, function ($role) { return $role instanceof Model; }); $ids = $models->map(function ($model) { return $model->getKey(); }); if ($names->count()) { $ids = $ids->merge($this->getRoleIdsFromNames($names->all())); } return $ids->all(); }
php
protected function getRoleIds() { list($models, $names) = Helpers::partition($this->roles, function ($role) { return $role instanceof Model; }); $ids = $models->map(function ($model) { return $model->getKey(); }); if ($names->count()) { $ids = $ids->merge($this->getRoleIdsFromNames($names->all())); } return $ids->all(); }
[ "protected", "function", "getRoleIds", "(", ")", "{", "list", "(", "$", "models", ",", "$", "names", ")", "=", "Helpers", "::", "partition", "(", "$", "this", "->", "roles", ",", "function", "(", "$", "role", ")", "{", "return", "$", "role", "instanceof", "Model", ";", "}", ")", ";", "$", "ids", "=", "$", "models", "->", "map", "(", "function", "(", "$", "model", ")", "{", "return", "$", "model", "->", "getKey", "(", ")", ";", "}", ")", ";", "if", "(", "$", "names", "->", "count", "(", ")", ")", "{", "$", "ids", "=", "$", "ids", "->", "merge", "(", "$", "this", "->", "getRoleIdsFromNames", "(", "$", "names", "->", "all", "(", ")", ")", ")", ";", "}", "return", "$", "ids", "->", "all", "(", ")", ";", "}" ]
Get the IDs of anyexisting roles provided. @return array
[ "Get", "the", "IDs", "of", "anyexisting", "roles", "provided", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/RemovesRoles.php#L53-L68
train
JosephSilber/bouncer
src/Conductors/RemovesRoles.php
RemovesRoles.getRoleIdsFromNames
protected function getRoleIdsFromNames(array $names) { $key = Models::role()->getKeyName(); return Models::role() ->whereIn('name', $names) ->get([$key]) ->pluck($key); }
php
protected function getRoleIdsFromNames(array $names) { $key = Models::role()->getKeyName(); return Models::role() ->whereIn('name', $names) ->get([$key]) ->pluck($key); }
[ "protected", "function", "getRoleIdsFromNames", "(", "array", "$", "names", ")", "{", "$", "key", "=", "Models", "::", "role", "(", ")", "->", "getKeyName", "(", ")", ";", "return", "Models", "::", "role", "(", ")", "->", "whereIn", "(", "'name'", ",", "$", "names", ")", "->", "get", "(", "[", "$", "key", "]", ")", "->", "pluck", "(", "$", "key", ")", ";", "}" ]
Get the IDs of the roles with the given names. @param string[] $names @return \Illuminate\Database\Eloquent\Collection
[ "Get", "the", "IDs", "of", "the", "roles", "with", "the", "given", "names", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/RemovesRoles.php#L76-L84
train
JosephSilber/bouncer
src/Conductors/RemovesRoles.php
RemovesRoles.retractRoles
protected function retractRoles($roleIds, $authorityClass, $authorityIds) { $query = $this->newPivotTableQuery(); $morphType = (new $authorityClass)->getMorphClass(); foreach ($roleIds as $roleId) { foreach ($authorityIds as $authorityId) { $query->orWhere($this->getDetachQueryConstraint( $roleId, $authorityId, $morphType )); } } $query->delete(); }
php
protected function retractRoles($roleIds, $authorityClass, $authorityIds) { $query = $this->newPivotTableQuery(); $morphType = (new $authorityClass)->getMorphClass(); foreach ($roleIds as $roleId) { foreach ($authorityIds as $authorityId) { $query->orWhere($this->getDetachQueryConstraint( $roleId, $authorityId, $morphType )); } } $query->delete(); }
[ "protected", "function", "retractRoles", "(", "$", "roleIds", ",", "$", "authorityClass", ",", "$", "authorityIds", ")", "{", "$", "query", "=", "$", "this", "->", "newPivotTableQuery", "(", ")", ";", "$", "morphType", "=", "(", "new", "$", "authorityClass", ")", "->", "getMorphClass", "(", ")", ";", "foreach", "(", "$", "roleIds", "as", "$", "roleId", ")", "{", "foreach", "(", "$", "authorityIds", "as", "$", "authorityId", ")", "{", "$", "query", "->", "orWhere", "(", "$", "this", "->", "getDetachQueryConstraint", "(", "$", "roleId", ",", "$", "authorityId", ",", "$", "morphType", ")", ")", ";", "}", "}", "$", "query", "->", "delete", "(", ")", ";", "}" ]
Retract the given roles from the given authorities. @param array $roleIds @param string $authorityClass @param array $authorityIds @return void
[ "Retract", "the", "given", "roles", "from", "the", "given", "authorities", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/RemovesRoles.php#L94-L109
train
JosephSilber/bouncer
src/Conductors/RemovesRoles.php
RemovesRoles.getDetachQueryConstraint
protected function getDetachQueryConstraint($roleId, $authorityId, $morphType) { return function ($query) use ($roleId, $authorityId, $morphType) { $query->where(Models::scope()->getAttachAttributes() + [ 'role_id' => $roleId, 'entity_id' => $authorityId, 'entity_type' => $morphType, ]); }; }
php
protected function getDetachQueryConstraint($roleId, $authorityId, $morphType) { return function ($query) use ($roleId, $authorityId, $morphType) { $query->where(Models::scope()->getAttachAttributes() + [ 'role_id' => $roleId, 'entity_id' => $authorityId, 'entity_type' => $morphType, ]); }; }
[ "protected", "function", "getDetachQueryConstraint", "(", "$", "roleId", ",", "$", "authorityId", ",", "$", "morphType", ")", "{", "return", "function", "(", "$", "query", ")", "use", "(", "$", "roleId", ",", "$", "authorityId", ",", "$", "morphType", ")", "{", "$", "query", "->", "where", "(", "Models", "::", "scope", "(", ")", "->", "getAttachAttributes", "(", ")", "+", "[", "'role_id'", "=>", "$", "roleId", ",", "'entity_id'", "=>", "$", "authorityId", ",", "'entity_type'", "=>", "$", "morphType", ",", "]", ")", ";", "}", ";", "}" ]
Get a constraint for the detach query for the given parameters. @param mixed $roleId @param mixed $authorityId @param string $morphType @return \Closure
[ "Get", "a", "constraint", "for", "the", "detach", "query", "for", "the", "given", "parameters", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/RemovesRoles.php#L119-L128
train
JosephSilber/bouncer
src/Conductors/ChecksRoles.php
ChecksRoles.a
public function a($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'or'); }
php
public function a($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'or'); }
[ "public", "function", "a", "(", "$", "role", ")", "{", "$", "roles", "=", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "clipboard", "->", "checkRole", "(", "$", "this", "->", "authority", ",", "$", "roles", ",", "'or'", ")", ";", "}" ]
Check if the authority has any of the given roles. @param string $role @return bool
[ "Check", "if", "the", "authority", "has", "any", "of", "the", "given", "roles", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/ChecksRoles.php#L42-L47
train
JosephSilber/bouncer
src/Conductors/ChecksRoles.php
ChecksRoles.notA
public function notA($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'not'); }
php
public function notA($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'not'); }
[ "public", "function", "notA", "(", "$", "role", ")", "{", "$", "roles", "=", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "clipboard", "->", "checkRole", "(", "$", "this", "->", "authority", ",", "$", "roles", ",", "'not'", ")", ";", "}" ]
Check if the authority doesn't have any of the given roles. @param string $role @return bool
[ "Check", "if", "the", "authority", "doesn", "t", "have", "any", "of", "the", "given", "roles", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/ChecksRoles.php#L55-L60
train
JosephSilber/bouncer
src/Conductors/ChecksRoles.php
ChecksRoles.an
public function an($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'or'); }
php
public function an($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'or'); }
[ "public", "function", "an", "(", "$", "role", ")", "{", "$", "roles", "=", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "clipboard", "->", "checkRole", "(", "$", "this", "->", "authority", ",", "$", "roles", ",", "'or'", ")", ";", "}" ]
Alias to the "a" method. @param string $role @return bool
[ "Alias", "to", "the", "a", "method", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/ChecksRoles.php#L68-L73
train
JosephSilber/bouncer
src/Conductors/ChecksRoles.php
ChecksRoles.notAn
public function notAn($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'not'); }
php
public function notAn($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'not'); }
[ "public", "function", "notAn", "(", "$", "role", ")", "{", "$", "roles", "=", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "clipboard", "->", "checkRole", "(", "$", "this", "->", "authority", ",", "$", "roles", ",", "'not'", ")", ";", "}" ]
Alias to the "notA" method. @param string $role @return bool
[ "Alias", "to", "the", "notA", "method", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/ChecksRoles.php#L81-L86
train
JosephSilber/bouncer
src/Conductors/ChecksRoles.php
ChecksRoles.all
public function all($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'and'); }
php
public function all($role) { $roles = func_get_args(); return $this->clipboard->checkRole($this->authority, $roles, 'and'); }
[ "public", "function", "all", "(", "$", "role", ")", "{", "$", "roles", "=", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "clipboard", "->", "checkRole", "(", "$", "this", "->", "authority", ",", "$", "roles", ",", "'and'", ")", ";", "}" ]
Check if the authority has all of the given roles. @param string $role @return bool
[ "Check", "if", "the", "authority", "has", "all", "of", "the", "given", "roles", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/ChecksRoles.php#L94-L99
train
JosephSilber/bouncer
src/Conductors/Concerns/AssociatesAbilities.php
AssociatesAbilities.getAuthority
protected function getAuthority() { if (is_null($this->authority)) { return null; } if ($this->authority instanceof Model) { return $this->authority; } return Models::role()->firstOrCreate(['name' => $this->authority]); }
php
protected function getAuthority() { if (is_null($this->authority)) { return null; } if ($this->authority instanceof Model) { return $this->authority; } return Models::role()->firstOrCreate(['name' => $this->authority]); }
[ "protected", "function", "getAuthority", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "authority", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "this", "->", "authority", "instanceof", "Model", ")", "{", "return", "$", "this", "->", "authority", ";", "}", "return", "Models", "::", "role", "(", ")", "->", "firstOrCreate", "(", "[", "'name'", "=>", "$", "this", "->", "authority", "]", ")", ";", "}" ]
Get the authority, creating a role authority if necessary. @return \Illuminate\Database\Eloquent\Model|null
[ "Get", "the", "authority", "creating", "a", "role", "authority", "if", "necessary", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/AssociatesAbilities.php#L18-L29
train
JosephSilber/bouncer
src/Conductors/Concerns/AssociatesAbilities.php
AssociatesAbilities.getAssociatedAbilityIds
protected function getAssociatedAbilityIds($authority, array $abilityIds, $forbidden) { if (is_null($authority)) { return $this->getAbilityIdsAssociatedWithEveryone($abilityIds, $forbidden); } $relation = $authority->abilities(); $table = Models::table('abilities'); $relation->whereIn("{$table}.id", $abilityIds) ->wherePivot('forbidden', '=', $forbidden); Models::scope()->applyToRelation($relation); return $relation->get(["{$table}.id"])->pluck('id')->all(); }
php
protected function getAssociatedAbilityIds($authority, array $abilityIds, $forbidden) { if (is_null($authority)) { return $this->getAbilityIdsAssociatedWithEveryone($abilityIds, $forbidden); } $relation = $authority->abilities(); $table = Models::table('abilities'); $relation->whereIn("{$table}.id", $abilityIds) ->wherePivot('forbidden', '=', $forbidden); Models::scope()->applyToRelation($relation); return $relation->get(["{$table}.id"])->pluck('id')->all(); }
[ "protected", "function", "getAssociatedAbilityIds", "(", "$", "authority", ",", "array", "$", "abilityIds", ",", "$", "forbidden", ")", "{", "if", "(", "is_null", "(", "$", "authority", ")", ")", "{", "return", "$", "this", "->", "getAbilityIdsAssociatedWithEveryone", "(", "$", "abilityIds", ",", "$", "forbidden", ")", ";", "}", "$", "relation", "=", "$", "authority", "->", "abilities", "(", ")", ";", "$", "table", "=", "Models", "::", "table", "(", "'abilities'", ")", ";", "$", "relation", "->", "whereIn", "(", "\"{$table}.id\"", ",", "$", "abilityIds", ")", "->", "wherePivot", "(", "'forbidden'", ",", "'='", ",", "$", "forbidden", ")", ";", "Models", "::", "scope", "(", ")", "->", "applyToRelation", "(", "$", "relation", ")", ";", "return", "$", "relation", "->", "get", "(", "[", "\"{$table}.id\"", "]", ")", "->", "pluck", "(", "'id'", ")", "->", "all", "(", ")", ";", "}" ]
Get the IDs of the associated abilities. @param \Illuminate\Database\Eloquent\Model|null $authority @param array $abilityIds @param bool $forbidden @return array
[ "Get", "the", "IDs", "of", "the", "associated", "abilities", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/AssociatesAbilities.php#L39-L55
train
JosephSilber/bouncer
src/Conductors/Concerns/AssociatesAbilities.php
AssociatesAbilities.getAbilityIdsAssociatedWithEveryone
protected function getAbilityIdsAssociatedWithEveryone(array $abilityIds, $forbidden) { $query = Models::query('permissions') ->whereNull('entity_id') ->whereIn('ability_id', $abilityIds) ->where('forbidden', '=', $forbidden); Models::scope()->applyToRelationQuery($query, $query->from); return Arr::pluck($query->get(['ability_id']), 'ability_id'); }
php
protected function getAbilityIdsAssociatedWithEveryone(array $abilityIds, $forbidden) { $query = Models::query('permissions') ->whereNull('entity_id') ->whereIn('ability_id', $abilityIds) ->where('forbidden', '=', $forbidden); Models::scope()->applyToRelationQuery($query, $query->from); return Arr::pluck($query->get(['ability_id']), 'ability_id'); }
[ "protected", "function", "getAbilityIdsAssociatedWithEveryone", "(", "array", "$", "abilityIds", ",", "$", "forbidden", ")", "{", "$", "query", "=", "Models", "::", "query", "(", "'permissions'", ")", "->", "whereNull", "(", "'entity_id'", ")", "->", "whereIn", "(", "'ability_id'", ",", "$", "abilityIds", ")", "->", "where", "(", "'forbidden'", ",", "'='", ",", "$", "forbidden", ")", ";", "Models", "::", "scope", "(", ")", "->", "applyToRelationQuery", "(", "$", "query", ",", "$", "query", "->", "from", ")", ";", "return", "Arr", "::", "pluck", "(", "$", "query", "->", "get", "(", "[", "'ability_id'", "]", ")", ",", "'ability_id'", ")", ";", "}" ]
Get the IDs of the abilities associated with everyone. @param array $abilityIds @param bool $forbidden @return array
[ "Get", "the", "IDs", "of", "the", "abilities", "associated", "with", "everyone", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Conductors/Concerns/AssociatesAbilities.php#L64-L74
train
JosephSilber/bouncer
src/Database/Concerns/HasRoles.php
HasRoles.roles
public function roles() { $relation = $this->morphToMany( Models::classname(Role::class), 'entity', Models::table('assigned_roles') )->withPivot('scope'); return Models::scope()->applyToRelation($relation); }
php
public function roles() { $relation = $this->morphToMany( Models::classname(Role::class), 'entity', Models::table('assigned_roles') )->withPivot('scope'); return Models::scope()->applyToRelation($relation); }
[ "public", "function", "roles", "(", ")", "{", "$", "relation", "=", "$", "this", "->", "morphToMany", "(", "Models", "::", "classname", "(", "Role", "::", "class", ")", ",", "'entity'", ",", "Models", "::", "table", "(", "'assigned_roles'", ")", ")", "->", "withPivot", "(", "'scope'", ")", ";", "return", "Models", "::", "scope", "(", ")", "->", "applyToRelation", "(", "$", "relation", ")", ";", "}" ]
The roles relationship. @return \Illuminate\Database\Eloquent\Relations\MorphToMany
[ "The", "roles", "relationship", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasRoles.php#L33-L42
train
JosephSilber/bouncer
src/Database/Concerns/HasRoles.php
HasRoles.isAn
public function isAn($role) { $roles = func_get_args(); $clipboard = $this->getClipboardInstance(); return $clipboard->checkRole($this, $roles, 'or'); }
php
public function isAn($role) { $roles = func_get_args(); $clipboard = $this->getClipboardInstance(); return $clipboard->checkRole($this, $roles, 'or'); }
[ "public", "function", "isAn", "(", "$", "role", ")", "{", "$", "roles", "=", "func_get_args", "(", ")", ";", "$", "clipboard", "=", "$", "this", "->", "getClipboardInstance", "(", ")", ";", "return", "$", "clipboard", "->", "checkRole", "(", "$", "this", ",", "$", "roles", ",", "'or'", ")", ";", "}" ]
Check if the model has any of the given roles. @param string $role @return bool
[ "Check", "if", "the", "model", "has", "any", "of", "the", "given", "roles", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasRoles.php#L86-L93
train
JosephSilber/bouncer
src/Database/Concerns/HasRoles.php
HasRoles.isNotAn
public function isNotAn($role) { $roles = func_get_args(); $clipboard = $this->getClipboardInstance(); return $clipboard->checkRole($this, $roles, 'not'); }
php
public function isNotAn($role) { $roles = func_get_args(); $clipboard = $this->getClipboardInstance(); return $clipboard->checkRole($this, $roles, 'not'); }
[ "public", "function", "isNotAn", "(", "$", "role", ")", "{", "$", "roles", "=", "func_get_args", "(", ")", ";", "$", "clipboard", "=", "$", "this", "->", "getClipboardInstance", "(", ")", ";", "return", "$", "clipboard", "->", "checkRole", "(", "$", "this", ",", "$", "roles", ",", "'not'", ")", ";", "}" ]
Check if the model has none of the given roles. @param string $role @return bool
[ "Check", "if", "the", "model", "has", "none", "of", "the", "given", "roles", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasRoles.php#L114-L121
train
JosephSilber/bouncer
src/Database/Concerns/HasRoles.php
HasRoles.isAll
public function isAll($role) { $roles = func_get_args(); $clipboard = $this->getClipboardInstance(); return $clipboard->checkRole($this, $roles, 'and'); }
php
public function isAll($role) { $roles = func_get_args(); $clipboard = $this->getClipboardInstance(); return $clipboard->checkRole($this, $roles, 'and'); }
[ "public", "function", "isAll", "(", "$", "role", ")", "{", "$", "roles", "=", "func_get_args", "(", ")", ";", "$", "clipboard", "=", "$", "this", "->", "getClipboardInstance", "(", ")", ";", "return", "$", "clipboard", "->", "checkRole", "(", "$", "this", ",", "$", "roles", ",", "'and'", ")", ";", "}" ]
Check if the model has all of the given roles. @param string $role @return bool
[ "Check", "if", "the", "model", "has", "all", "of", "the", "given", "roles", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Concerns/HasRoles.php#L142-L149
train
JosephSilber/bouncer
src/Constraints/Constraint.php
Constraint.where
public static function where($column, $operator, $value = null) { list($operator, $value) = static::prepareOperatorAndValue( $operator, $value, func_num_args() === 2 ); return new ValueConstraint($column, $operator, $value); }
php
public static function where($column, $operator, $value = null) { list($operator, $value) = static::prepareOperatorAndValue( $operator, $value, func_num_args() === 2 ); return new ValueConstraint($column, $operator, $value); }
[ "public", "static", "function", "where", "(", "$", "column", ",", "$", "operator", ",", "$", "value", "=", "null", ")", "{", "list", "(", "$", "operator", ",", "$", "value", ")", "=", "static", "::", "prepareOperatorAndValue", "(", "$", "operator", ",", "$", "value", ",", "func_num_args", "(", ")", "===", "2", ")", ";", "return", "new", "ValueConstraint", "(", "$", "column", ",", "$", "operator", ",", "$", "value", ")", ";", "}" ]
Create a new constraint for where a column matches the given value. @param string $column @param mixed $operator @param mixed $value @return \Silber\Bouncer\Constraints\ValueConstraint
[ "Create", "a", "new", "constraint", "for", "where", "a", "column", "matches", "the", "given", "value", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Constraint.php#L42-L49
train
JosephSilber/bouncer
src/Constraints/Constraint.php
Constraint.whereColumn
public static function whereColumn($a, $operator, $b = null) { list($operator, $b) = static::prepareOperatorAndValue( $operator, $b, func_num_args() === 2 ); return new ColumnConstraint($a, $operator, $b); }
php
public static function whereColumn($a, $operator, $b = null) { list($operator, $b) = static::prepareOperatorAndValue( $operator, $b, func_num_args() === 2 ); return new ColumnConstraint($a, $operator, $b); }
[ "public", "static", "function", "whereColumn", "(", "$", "a", ",", "$", "operator", ",", "$", "b", "=", "null", ")", "{", "list", "(", "$", "operator", ",", "$", "b", ")", "=", "static", "::", "prepareOperatorAndValue", "(", "$", "operator", ",", "$", "b", ",", "func_num_args", "(", ")", "===", "2", ")", ";", "return", "new", "ColumnConstraint", "(", "$", "a", ",", "$", "operator", ",", "$", "b", ")", ";", "}" ]
Create a new constraint for where a column matches the given column on the authority. @param string $a @param mixed $operator @param mixed $b @return \Silber\Bouncer\Constraints\ColumnConstraint
[ "Create", "a", "new", "constraint", "for", "where", "a", "column", "matches", "the", "given", "column", "on", "the", "authority", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Constraint.php#L76-L83
train
JosephSilber/bouncer
src/Constraints/Constraint.php
Constraint.logicalOperator
public function logicalOperator($operator = null) { if (is_null($operator)) { return $this->logicalOperator; } Helpers::ensureValidLogicalOperator($operator); $this->logicalOperator = $operator; return $this; }
php
public function logicalOperator($operator = null) { if (is_null($operator)) { return $this->logicalOperator; } Helpers::ensureValidLogicalOperator($operator); $this->logicalOperator = $operator; return $this; }
[ "public", "function", "logicalOperator", "(", "$", "operator", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "operator", ")", ")", "{", "return", "$", "this", "->", "logicalOperator", ";", "}", "Helpers", "::", "ensureValidLogicalOperator", "(", "$", "operator", ")", ";", "$", "this", "->", "logicalOperator", "=", "$", "operator", ";", "return", "$", "this", ";", "}" ]
Set the logical operator to use when checked after a previous constraint. @param string|null $operator @return $this|string
[ "Set", "the", "logical", "operator", "to", "use", "when", "checked", "after", "a", "previous", "constraint", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Constraint.php#L107-L118
train
JosephSilber/bouncer
src/Constraints/Constraint.php
Constraint.prepareOperatorAndValue
protected static function prepareOperatorAndValue($operator, $value, $usesDefault) { if ($usesDefault) { return ['=', $operator]; } if (! in_array($operator, ['=', '==', '!=', '<', '>', '<=', '>='])) { throw new InvalidArgumentException("{$operator} is not a valid operator"); } return [$operator, $value]; }
php
protected static function prepareOperatorAndValue($operator, $value, $usesDefault) { if ($usesDefault) { return ['=', $operator]; } if (! in_array($operator, ['=', '==', '!=', '<', '>', '<=', '>='])) { throw new InvalidArgumentException("{$operator} is not a valid operator"); } return [$operator, $value]; }
[ "protected", "static", "function", "prepareOperatorAndValue", "(", "$", "operator", ",", "$", "value", ",", "$", "usesDefault", ")", "{", "if", "(", "$", "usesDefault", ")", "{", "return", "[", "'='", ",", "$", "operator", "]", ";", "}", "if", "(", "!", "in_array", "(", "$", "operator", ",", "[", "'='", ",", "'=='", ",", "'!='", ",", "'<'", ",", "'>'", ",", "'<='", ",", "'>='", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"{$operator} is not a valid operator\"", ")", ";", "}", "return", "[", "$", "operator", ",", "$", "value", "]", ";", "}" ]
Prepare the value and operator. @param string $operator @param string $value @param bool $usesDefault @return array @throws \InvalidArgumentException
[ "Prepare", "the", "value", "and", "operator", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Constraint.php#L165-L176
train
JosephSilber/bouncer
src/Constraints/Constraint.php
Constraint.compare
protected function compare($a, $b) { switch ($this->operator) { case '=': case '==': return $a == $b; case '!=': return $a != $b; case '<': return $a < $b; case '>': return $a > $b; case '<=': return $a <= $b; case '>=': return $a >= $b; } }
php
protected function compare($a, $b) { switch ($this->operator) { case '=': case '==': return $a == $b; case '!=': return $a != $b; case '<': return $a < $b; case '>': return $a > $b; case '<=': return $a <= $b; case '>=': return $a >= $b; } }
[ "protected", "function", "compare", "(", "$", "a", ",", "$", "b", ")", "{", "switch", "(", "$", "this", "->", "operator", ")", "{", "case", "'='", ":", "case", "'=='", ":", "return", "$", "a", "==", "$", "b", ";", "case", "'!='", ":", "return", "$", "a", "!=", "$", "b", ";", "case", "'<'", ":", "return", "$", "a", "<", "$", "b", ";", "case", "'>'", ":", "return", "$", "a", ">", "$", "b", ";", "case", "'<='", ":", "return", "$", "a", "<=", "$", "b", ";", "case", "'>='", ":", "return", "$", "a", ">=", "$", "b", ";", "}", "}" ]
Compare the two values by the constraint's operator. @param mixed $a @param mixed $b @return bool
[ "Compare", "the", "two", "values", "by", "the", "constraint", "s", "operator", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Constraint.php#L185-L196
train
JosephSilber/bouncer
src/CachedClipboard.php
CachedClipboard.setCache
public function setCache(Store $cache) { if (method_exists($cache, 'tags')) { $cache = $cache->tags($this->tag()); } $this->cache = $cache; return $this; }
php
public function setCache(Store $cache) { if (method_exists($cache, 'tags')) { $cache = $cache->tags($this->tag()); } $this->cache = $cache; return $this; }
[ "public", "function", "setCache", "(", "Store", "$", "cache", ")", "{", "if", "(", "method_exists", "(", "$", "cache", ",", "'tags'", ")", ")", "{", "$", "cache", "=", "$", "cache", "->", "tags", "(", "$", "this", "->", "tag", "(", ")", ")", ";", "}", "$", "this", "->", "cache", "=", "$", "cache", ";", "return", "$", "this", ";", "}" ]
Set the cache instance. @param \Illuminate\Contracts\Cache\Store $cache @return $this
[ "Set", "the", "cache", "instance", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/CachedClipboard.php#L45-L54
train
JosephSilber/bouncer
src/CachedClipboard.php
CachedClipboard.findMatchingAbility
protected function findMatchingAbility($abilities, $applicable, $model, $authority) { $abilities = $abilities->toBase()->pluck('identifier', 'id'); if ($id = $this->getMatchedAbilityId($abilities, $applicable)) { return $id; } if ($this->isOwnedBy($authority, $model)) { return $this->getMatchedAbilityId( $abilities, $applicable->map(function ($identifier) { return $identifier.'-owned'; }) ); } }
php
protected function findMatchingAbility($abilities, $applicable, $model, $authority) { $abilities = $abilities->toBase()->pluck('identifier', 'id'); if ($id = $this->getMatchedAbilityId($abilities, $applicable)) { return $id; } if ($this->isOwnedBy($authority, $model)) { return $this->getMatchedAbilityId( $abilities, $applicable->map(function ($identifier) { return $identifier.'-owned'; }) ); } }
[ "protected", "function", "findMatchingAbility", "(", "$", "abilities", ",", "$", "applicable", ",", "$", "model", ",", "$", "authority", ")", "{", "$", "abilities", "=", "$", "abilities", "->", "toBase", "(", ")", "->", "pluck", "(", "'identifier'", ",", "'id'", ")", ";", "if", "(", "$", "id", "=", "$", "this", "->", "getMatchedAbilityId", "(", "$", "abilities", ",", "$", "applicable", ")", ")", "{", "return", "$", "id", ";", "}", "if", "(", "$", "this", "->", "isOwnedBy", "(", "$", "authority", ",", "$", "model", ")", ")", "{", "return", "$", "this", "->", "getMatchedAbilityId", "(", "$", "abilities", ",", "$", "applicable", "->", "map", "(", "function", "(", "$", "identifier", ")", "{", "return", "$", "identifier", ".", "'-owned'", ";", "}", ")", ")", ";", "}", "}" ]
Determine if any of the abilities can be matched against the provided applicable ones. @param \Illuminate\Support\Collection $abilities @param \Illuminate\Support\Collection $applicable @param \Illuminate\Database\Eloquent\Model $model @param \Illuminate\Database\Eloquent\Model $authority @return int|null
[ "Determine", "if", "any", "of", "the", "abilities", "can", "be", "matched", "against", "the", "provided", "applicable", "ones", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/CachedClipboard.php#L103-L119
train
JosephSilber/bouncer
src/CachedClipboard.php
CachedClipboard.getMatchedAbilityId
protected function getMatchedAbilityId($abilityMap, $applicable) { foreach ($abilityMap as $id => $identifier) { if ($applicable->contains($identifier)) { return $id; } } }
php
protected function getMatchedAbilityId($abilityMap, $applicable) { foreach ($abilityMap as $id => $identifier) { if ($applicable->contains($identifier)) { return $id; } } }
[ "protected", "function", "getMatchedAbilityId", "(", "$", "abilityMap", ",", "$", "applicable", ")", "{", "foreach", "(", "$", "abilityMap", "as", "$", "id", "=>", "$", "identifier", ")", "{", "if", "(", "$", "applicable", "->", "contains", "(", "$", "identifier", ")", ")", "{", "return", "$", "id", ";", "}", "}", "}" ]
Get the ID of the ability that matches one of the applicable abilities. @param \Illuminate\Support\Collection $abilityMap @param \Illuminate\Support\Collection $applicable @return int|null
[ "Get", "the", "ID", "of", "the", "ability", "that", "matches", "one", "of", "the", "applicable", "abilities", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/CachedClipboard.php#L128-L135
train
JosephSilber/bouncer
src/CachedClipboard.php
CachedClipboard.compileAbilityIdentifiers
protected function compileAbilityIdentifiers($ability, $model) { $identifiers = new BaseCollection( is_null($model) ? [$ability, '*-*', '*'] : $this->compileModelAbilityIdentifiers($ability, $model) ); return $identifiers->map(function ($identifier) { return strtolower($identifier); }); }
php
protected function compileAbilityIdentifiers($ability, $model) { $identifiers = new BaseCollection( is_null($model) ? [$ability, '*-*', '*'] : $this->compileModelAbilityIdentifiers($ability, $model) ); return $identifiers->map(function ($identifier) { return strtolower($identifier); }); }
[ "protected", "function", "compileAbilityIdentifiers", "(", "$", "ability", ",", "$", "model", ")", "{", "$", "identifiers", "=", "new", "BaseCollection", "(", "is_null", "(", "$", "model", ")", "?", "[", "$", "ability", ",", "'*-*'", ",", "'*'", "]", ":", "$", "this", "->", "compileModelAbilityIdentifiers", "(", "$", "ability", ",", "$", "model", ")", ")", ";", "return", "$", "identifiers", "->", "map", "(", "function", "(", "$", "identifier", ")", "{", "return", "strtolower", "(", "$", "identifier", ")", ";", "}", ")", ";", "}" ]
Compile a list of ability identifiers that match the provided parameters. @param string $ability @param \Illuminate\Database\Eloquent\Model|string|null $model @return \Illuminate\Support\Collection
[ "Compile", "a", "list", "of", "ability", "identifiers", "that", "match", "the", "provided", "parameters", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/CachedClipboard.php#L144-L155
train
JosephSilber/bouncer
src/CachedClipboard.php
CachedClipboard.compileModelAbilityIdentifiers
protected function compileModelAbilityIdentifiers($ability, $model) { if ($model === '*') { return ["{$ability}-*", "*-*"]; } $model = $model instanceof Model ? $model : new $model; $type = $model->getMorphClass(); $abilities = [ "{$ability}-{$type}", "{$ability}-*", "*-{$type}", "*-*", ]; if ($model->exists) { $abilities[] = "{$ability}-{$type}-{$model->getKey()}"; $abilities[] = "*-{$type}-{$model->getKey()}"; } return $abilities; }
php
protected function compileModelAbilityIdentifiers($ability, $model) { if ($model === '*') { return ["{$ability}-*", "*-*"]; } $model = $model instanceof Model ? $model : new $model; $type = $model->getMorphClass(); $abilities = [ "{$ability}-{$type}", "{$ability}-*", "*-{$type}", "*-*", ]; if ($model->exists) { $abilities[] = "{$ability}-{$type}-{$model->getKey()}"; $abilities[] = "*-{$type}-{$model->getKey()}"; } return $abilities; }
[ "protected", "function", "compileModelAbilityIdentifiers", "(", "$", "ability", ",", "$", "model", ")", "{", "if", "(", "$", "model", "===", "'*'", ")", "{", "return", "[", "\"{$ability}-*\"", ",", "\"*-*\"", "]", ";", "}", "$", "model", "=", "$", "model", "instanceof", "Model", "?", "$", "model", ":", "new", "$", "model", ";", "$", "type", "=", "$", "model", "->", "getMorphClass", "(", ")", ";", "$", "abilities", "=", "[", "\"{$ability}-{$type}\"", ",", "\"{$ability}-*\"", ",", "\"*-{$type}\"", ",", "\"*-*\"", ",", "]", ";", "if", "(", "$", "model", "->", "exists", ")", "{", "$", "abilities", "[", "]", "=", "\"{$ability}-{$type}-{$model->getKey()}\"", ";", "$", "abilities", "[", "]", "=", "\"*-{$type}-{$model->getKey()}\"", ";", "}", "return", "$", "abilities", ";", "}" ]
Compile a list of ability identifiers that match the given model. @param string $ability @param \Illuminate\Database\Eloquent\Model|string $model @return array
[ "Compile", "a", "list", "of", "ability", "identifiers", "that", "match", "the", "given", "model", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/CachedClipboard.php#L164-L187
train
JosephSilber/bouncer
src/CachedClipboard.php
CachedClipboard.getAbilities
public function getAbilities(Model $authority, $allowed = true) { $key = $this->getCacheKey($authority, 'abilities', $allowed); if (is_array($abilities = $this->cache->get($key))) { return $this->deserializeAbilities($abilities); } $abilities = $this->getFreshAbilities($authority, $allowed); $this->cache->forever($key, $this->serializeAbilities($abilities)); return $abilities; }
php
public function getAbilities(Model $authority, $allowed = true) { $key = $this->getCacheKey($authority, 'abilities', $allowed); if (is_array($abilities = $this->cache->get($key))) { return $this->deserializeAbilities($abilities); } $abilities = $this->getFreshAbilities($authority, $allowed); $this->cache->forever($key, $this->serializeAbilities($abilities)); return $abilities; }
[ "public", "function", "getAbilities", "(", "Model", "$", "authority", ",", "$", "allowed", "=", "true", ")", "{", "$", "key", "=", "$", "this", "->", "getCacheKey", "(", "$", "authority", ",", "'abilities'", ",", "$", "allowed", ")", ";", "if", "(", "is_array", "(", "$", "abilities", "=", "$", "this", "->", "cache", "->", "get", "(", "$", "key", ")", ")", ")", "{", "return", "$", "this", "->", "deserializeAbilities", "(", "$", "abilities", ")", ";", "}", "$", "abilities", "=", "$", "this", "->", "getFreshAbilities", "(", "$", "authority", ",", "$", "allowed", ")", ";", "$", "this", "->", "cache", "->", "forever", "(", "$", "key", ",", "$", "this", "->", "serializeAbilities", "(", "$", "abilities", ")", ")", ";", "return", "$", "abilities", ";", "}" ]
Get the given authority's abilities. @param \Illuminate\Database\Eloquent\Model $authority @param bool $allowed @return \Illuminate\Database\Eloquent\Collection
[ "Get", "the", "given", "authority", "s", "abilities", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/CachedClipboard.php#L196-L209
train
JosephSilber/bouncer
src/CachedClipboard.php
CachedClipboard.refreshAllIteratively
protected function refreshAllIteratively() { foreach (Models::user()->all() as $user) { $this->refreshFor($user); } foreach (Models::role()->all() as $role) { $this->refreshFor($role); } }
php
protected function refreshAllIteratively() { foreach (Models::user()->all() as $user) { $this->refreshFor($user); } foreach (Models::role()->all() as $role) { $this->refreshFor($role); } }
[ "protected", "function", "refreshAllIteratively", "(", ")", "{", "foreach", "(", "Models", "::", "user", "(", ")", "->", "all", "(", ")", "as", "$", "user", ")", "{", "$", "this", "->", "refreshFor", "(", "$", "user", ")", ";", "}", "foreach", "(", "Models", "::", "role", "(", ")", "->", "all", "(", ")", "as", "$", "role", ")", "{", "$", "this", "->", "refreshFor", "(", "$", "role", ")", ";", "}", "}" ]
Refresh the cache for all roles and users, iteratively. @return void
[ "Refresh", "the", "cache", "for", "all", "roles", "and", "users", "iteratively", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/CachedClipboard.php#L295-L304
train
JosephSilber/bouncer
src/CachedClipboard.php
CachedClipboard.getCacheKey
protected function getCacheKey(Model $model, $type, $allowed = true) { return implode('-', [ $this->tag(), $type, $model->getMorphClass(), $model->getKey(), $allowed ? 'a' : 'f', ]); }
php
protected function getCacheKey(Model $model, $type, $allowed = true) { return implode('-', [ $this->tag(), $type, $model->getMorphClass(), $model->getKey(), $allowed ? 'a' : 'f', ]); }
[ "protected", "function", "getCacheKey", "(", "Model", "$", "model", ",", "$", "type", ",", "$", "allowed", "=", "true", ")", "{", "return", "implode", "(", "'-'", ",", "[", "$", "this", "->", "tag", "(", ")", ",", "$", "type", ",", "$", "model", "->", "getMorphClass", "(", ")", ",", "$", "model", "->", "getKey", "(", ")", ",", "$", "allowed", "?", "'a'", ":", "'f'", ",", "]", ")", ";", "}" ]
Get the cache key for the given model's cache type. @param \Illuminate\Database\Eloquent\Model $model @param string $type @param bool $allowed @return string
[ "Get", "the", "cache", "key", "for", "the", "given", "model", "s", "cache", "type", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/CachedClipboard.php#L314-L323
train
JosephSilber/bouncer
src/Clipboard.php
Clipboard.isForbidden
protected function isForbidden(Model $authority, $ability, $model = null) { return $this->getHasAbilityQuery( $authority, $ability, $model, $allowed = false )->exists(); }
php
protected function isForbidden(Model $authority, $ability, $model = null) { return $this->getHasAbilityQuery( $authority, $ability, $model, $allowed = false )->exists(); }
[ "protected", "function", "isForbidden", "(", "Model", "$", "authority", ",", "$", "ability", ",", "$", "model", "=", "null", ")", "{", "return", "$", "this", "->", "getHasAbilityQuery", "(", "$", "authority", ",", "$", "ability", ",", "$", "model", ",", "$", "allowed", "=", "false", ")", "->", "exists", "(", ")", ";", "}" ]
Determine whether the given ability request is explicitely forbidden. @param \Illuminate\Database\Eloquent\Model $authority @param string $ability @param \Illuminate\Database\Eloquent\Model|string|null $model @return bool
[ "Determine", "whether", "the", "given", "ability", "request", "is", "explicitely", "forbidden", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Clipboard.php#L37-L42
train
JosephSilber/bouncer
src/Clipboard.php
Clipboard.getAllowingAbility
protected function getAllowingAbility(Model $authority, $ability, $model = null) { return $this->getHasAbilityQuery( $authority, $ability, $model, $allowed = true )->first(); }
php
protected function getAllowingAbility(Model $authority, $ability, $model = null) { return $this->getHasAbilityQuery( $authority, $ability, $model, $allowed = true )->first(); }
[ "protected", "function", "getAllowingAbility", "(", "Model", "$", "authority", ",", "$", "ability", ",", "$", "model", "=", "null", ")", "{", "return", "$", "this", "->", "getHasAbilityQuery", "(", "$", "authority", ",", "$", "ability", ",", "$", "model", ",", "$", "allowed", "=", "true", ")", "->", "first", "(", ")", ";", "}" ]
Get the ability model that allows the given ability request. Returns null if the ability is not allowed. @param \Illuminate\Database\Eloquent\Model $authority @param string $ability @param \Illuminate\Database\Eloquent\Model|string|null $model @return \Illuminate\Database\Eloquent\Model|null
[ "Get", "the", "ability", "model", "that", "allows", "the", "given", "ability", "request", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Clipboard.php#L54-L59
train
JosephSilber/bouncer
src/Clipboard.php
Clipboard.getHasAbilityQuery
protected function getHasAbilityQuery($authority, $ability, $model, $allowed) { $query = Abilities::forAuthority($authority, $allowed); if (! $this->isOwnedBy($authority, $model)) { $query->where('only_owned', false); } if (is_null($model)) { return $this->constrainToSimpleAbility($query, $ability); } return $query->byName($ability)->forModel($model); }
php
protected function getHasAbilityQuery($authority, $ability, $model, $allowed) { $query = Abilities::forAuthority($authority, $allowed); if (! $this->isOwnedBy($authority, $model)) { $query->where('only_owned', false); } if (is_null($model)) { return $this->constrainToSimpleAbility($query, $ability); } return $query->byName($ability)->forModel($model); }
[ "protected", "function", "getHasAbilityQuery", "(", "$", "authority", ",", "$", "ability", ",", "$", "model", ",", "$", "allowed", ")", "{", "$", "query", "=", "Abilities", "::", "forAuthority", "(", "$", "authority", ",", "$", "allowed", ")", ";", "if", "(", "!", "$", "this", "->", "isOwnedBy", "(", "$", "authority", ",", "$", "model", ")", ")", "{", "$", "query", "->", "where", "(", "'only_owned'", ",", "false", ")", ";", "}", "if", "(", "is_null", "(", "$", "model", ")", ")", "{", "return", "$", "this", "->", "constrainToSimpleAbility", "(", "$", "query", ",", "$", "ability", ")", ";", "}", "return", "$", "query", "->", "byName", "(", "$", "ability", ")", "->", "forModel", "(", "$", "model", ")", ";", "}" ]
Get the query for where the given authority has the given ability. @param \Illuminate\Database\Eloquent\Model $authority @param string $ability @param \Illuminate\Database\Eloquent\Model|string|null $model @param bool $allowed @return \Illuminate\Database\Eloquent\Builder
[ "Get", "the", "query", "for", "where", "the", "given", "authority", "has", "the", "given", "ability", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Clipboard.php#L70-L83
train
JosephSilber/bouncer
src/Clipboard.php
Clipboard.constrainToSimpleAbility
protected function constrainToSimpleAbility($query, $ability) { return $query->where(function ($query) use ($ability) { $query->where('name', $ability)->whereNull('entity_type'); $query->orWhere(function ($query) use ($ability) { $query->where('name', '*')->where(function ($query) { $query->whereNull('entity_type')->orWhere('entity_type', '*'); }); }); }); }
php
protected function constrainToSimpleAbility($query, $ability) { return $query->where(function ($query) use ($ability) { $query->where('name', $ability)->whereNull('entity_type'); $query->orWhere(function ($query) use ($ability) { $query->where('name', '*')->where(function ($query) { $query->whereNull('entity_type')->orWhere('entity_type', '*'); }); }); }); }
[ "protected", "function", "constrainToSimpleAbility", "(", "$", "query", ",", "$", "ability", ")", "{", "return", "$", "query", "->", "where", "(", "function", "(", "$", "query", ")", "use", "(", "$", "ability", ")", "{", "$", "query", "->", "where", "(", "'name'", ",", "$", "ability", ")", "->", "whereNull", "(", "'entity_type'", ")", ";", "$", "query", "->", "orWhere", "(", "function", "(", "$", "query", ")", "use", "(", "$", "ability", ")", "{", "$", "query", "->", "where", "(", "'name'", ",", "'*'", ")", "->", "where", "(", "function", "(", "$", "query", ")", "{", "$", "query", "->", "whereNull", "(", "'entity_type'", ")", "->", "orWhere", "(", "'entity_type'", ",", "'*'", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Constrain the query to the given non-model ability. @param \Illuminate\Database\Eloquent\Builder $query @param string $ability @return \Illuminate\Database\Eloquent\Builder
[ "Constrain", "the", "query", "to", "the", "given", "non", "-", "model", "ability", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Clipboard.php#L92-L103
train
JosephSilber/bouncer
src/Constraints/Builder.php
Builder.where
public function where($column, $operator = null, $value = null) { if ($column instanceof Closure) { return $this->whereNested('and', $column); } $constraint = call_user_func_array( [Constraint::class, 'where'], func_get_args() ); return $this->addConstraint($constraint); }
php
public function where($column, $operator = null, $value = null) { if ($column instanceof Closure) { return $this->whereNested('and', $column); } $constraint = call_user_func_array( [Constraint::class, 'where'], func_get_args() ); return $this->addConstraint($constraint); }
[ "public", "function", "where", "(", "$", "column", ",", "$", "operator", "=", "null", ",", "$", "value", "=", "null", ")", "{", "if", "(", "$", "column", "instanceof", "Closure", ")", "{", "return", "$", "this", "->", "whereNested", "(", "'and'", ",", "$", "column", ")", ";", "}", "$", "constraint", "=", "call_user_func_array", "(", "[", "Constraint", "::", "class", ",", "'where'", "]", ",", "func_get_args", "(", ")", ")", ";", "return", "$", "this", "->", "addConstraint", "(", "$", "constraint", ")", ";", "}" ]
Add a "where" constraint. @param string|\Closure $column @param mixed $operator @param mixed $value @return $this
[ "Add", "a", "where", "constraint", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Builder.php#L44-L56
train
JosephSilber/bouncer
src/Constraints/Builder.php
Builder.whereColumn
public function whereColumn($a, $operator, $b = null) { $constraint = call_user_func_array( [Constraint::class, 'whereColumn'], func_get_args() ); return $this->addConstraint($constraint); }
php
public function whereColumn($a, $operator, $b = null) { $constraint = call_user_func_array( [Constraint::class, 'whereColumn'], func_get_args() ); return $this->addConstraint($constraint); }
[ "public", "function", "whereColumn", "(", "$", "a", ",", "$", "operator", ",", "$", "b", "=", "null", ")", "{", "$", "constraint", "=", "call_user_func_array", "(", "[", "Constraint", "::", "class", ",", "'whereColumn'", "]", ",", "func_get_args", "(", ")", ")", ";", "return", "$", "this", "->", "addConstraint", "(", "$", "constraint", ")", ";", "}" ]
Add a "where column" constraint. @param string $a @param mixed $operator @param mixed $b @return $this
[ "Add", "a", "where", "column", "constraint", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Builder.php#L88-L96
train
JosephSilber/bouncer
src/Constraints/Builder.php
Builder.build
public function build() { if ($this->constraints->count() == 1) { return $this->constraints->first(); } return new Group($this->constraints); }
php
public function build() { if ($this->constraints->count() == 1) { return $this->constraints->first(); } return new Group($this->constraints); }
[ "public", "function", "build", "(", ")", "{", "if", "(", "$", "this", "->", "constraints", "->", "count", "(", ")", "==", "1", ")", "{", "return", "$", "this", "->", "constraints", "->", "first", "(", ")", ";", "}", "return", "new", "Group", "(", "$", "this", "->", "constraints", ")", ";", "}" ]
Build the compiled list of constraints. @return \Silber\Bouncer\Constraints\Constrainer
[ "Build", "the", "compiled", "list", "of", "constraints", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Builder.php#L121-L128
train
JosephSilber/bouncer
src/Constraints/Builder.php
Builder.whereNested
protected function whereNested($logicalOperator, Closure $callback) { $callback($builder = new static); $constraint = $builder->build()->logicalOperator($logicalOperator); return $this->addConstraint($constraint); }
php
protected function whereNested($logicalOperator, Closure $callback) { $callback($builder = new static); $constraint = $builder->build()->logicalOperator($logicalOperator); return $this->addConstraint($constraint); }
[ "protected", "function", "whereNested", "(", "$", "logicalOperator", ",", "Closure", "$", "callback", ")", "{", "$", "callback", "(", "$", "builder", "=", "new", "static", ")", ";", "$", "constraint", "=", "$", "builder", "->", "build", "(", ")", "->", "logicalOperator", "(", "$", "logicalOperator", ")", ";", "return", "$", "this", "->", "addConstraint", "(", "$", "constraint", ")", ";", "}" ]
Add a nested "where" clause. @param string $logicalOperator 'and'|'or' @param \Closure $callback @return $this
[ "Add", "a", "nested", "where", "clause", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Constraints/Builder.php#L137-L144
train
JosephSilber/bouncer
src/Helpers.php
Helpers.extractModelAndKeys
public static function extractModelAndKeys($model, array $keys = null) { if (! is_null($keys)) { if (is_string($model)) { $model = new $model; } return [$model, $keys]; } if ($model instanceof Model) { return [$model, [$model->getKey()]]; } if ($model instanceof Collection) { $keys = $model->map(function ($model) { return $model->getKey(); }); return [$model->first(), $keys]; } }
php
public static function extractModelAndKeys($model, array $keys = null) { if (! is_null($keys)) { if (is_string($model)) { $model = new $model; } return [$model, $keys]; } if ($model instanceof Model) { return [$model, [$model->getKey()]]; } if ($model instanceof Collection) { $keys = $model->map(function ($model) { return $model->getKey(); }); return [$model->first(), $keys]; } }
[ "public", "static", "function", "extractModelAndKeys", "(", "$", "model", ",", "array", "$", "keys", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "keys", ")", ")", "{", "if", "(", "is_string", "(", "$", "model", ")", ")", "{", "$", "model", "=", "new", "$", "model", ";", "}", "return", "[", "$", "model", ",", "$", "keys", "]", ";", "}", "if", "(", "$", "model", "instanceof", "Model", ")", "{", "return", "[", "$", "model", ",", "[", "$", "model", "->", "getKey", "(", ")", "]", "]", ";", "}", "if", "(", "$", "model", "instanceof", "Collection", ")", "{", "$", "keys", "=", "$", "model", "->", "map", "(", "function", "(", "$", "model", ")", "{", "return", "$", "model", "->", "getKey", "(", ")", ";", "}", ")", ";", "return", "[", "$", "model", "->", "first", "(", ")", ",", "$", "keys", "]", ";", "}", "}" ]
Extract the model instance and model keys from the given parameters. @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|string $model @param array|null $keys @return array
[ "Extract", "the", "model", "instance", "and", "model", "keys", "from", "the", "given", "parameters", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Helpers.php#L38-L59
train
JosephSilber/bouncer
src/Helpers.php
Helpers.fillMissingKeys
public static function fillMissingKeys($array, $value, $keys) { foreach ($keys as $key) { if (! array_key_exists($key, $array)) { $array[$key] = $value; } } return $array; }
php
public static function fillMissingKeys($array, $value, $keys) { foreach ($keys as $key) { if (! array_key_exists($key, $array)) { $array[$key] = $value; } } return $array; }
[ "public", "static", "function", "fillMissingKeys", "(", "$", "array", ",", "$", "value", ",", "$", "keys", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "array", ")", ")", "{", "$", "array", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "array", ";", "}" ]
Fill the given array with the given value for any missing keys. @param iterable $array @param mixed $value @param iterable $keys @return iterable
[ "Fill", "the", "given", "array", "with", "the", "given", "value", "for", "any", "missing", "keys", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Helpers.php#L69-L78
train
JosephSilber/bouncer
src/Helpers.php
Helpers.isIndexedArray
public static function isIndexedArray($array) { if (! is_array($array)) { return false; } foreach ($array as $key => $value) { if (! is_numeric($key)) { return false; } } return true; }
php
public static function isIndexedArray($array) { if (! is_array($array)) { return false; } foreach ($array as $key => $value) { if (! is_numeric($key)) { return false; } } return true; }
[ "public", "static", "function", "isIndexedArray", "(", "$", "array", ")", "{", "if", "(", "!", "is_array", "(", "$", "array", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "key", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Determines if an array is numerically indexed. @param mixed $array @return bool
[ "Determines", "if", "an", "array", "is", "numerically", "indexed", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Helpers.php#L130-L143
train
JosephSilber/bouncer
src/Helpers.php
Helpers.toArray
public static function toArray($value) { if (is_array($value)) { return $value; } if ($value instanceof Collection) { return $value->all(); } return [$value]; }
php
public static function toArray($value) { if (is_array($value)) { return $value; } if ($value instanceof Collection) { return $value->all(); } return [$value]; }
[ "public", "static", "function", "toArray", "(", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "if", "(", "$", "value", "instanceof", "Collection", ")", "{", "return", "$", "value", "->", "all", "(", ")", ";", "}", "return", "[", "$", "value", "]", ";", "}" ]
Convert the given value to an array. @param mixed $value @return array
[ "Convert", "the", "given", "value", "to", "an", "array", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Helpers.php#L151-L162
train
JosephSilber/bouncer
src/Helpers.php
Helpers.mapAuthorityByClass
public static function mapAuthorityByClass(array $authorities) { $map = []; foreach ($authorities as $authority) { if ($authority instanceof Model) { $map[get_class($authority)][] = $authority->getKey(); } else { $map[Models::classname(User::class)][] = $authority; } } return $map; }
php
public static function mapAuthorityByClass(array $authorities) { $map = []; foreach ($authorities as $authority) { if ($authority instanceof Model) { $map[get_class($authority)][] = $authority->getKey(); } else { $map[Models::classname(User::class)][] = $authority; } } return $map; }
[ "public", "static", "function", "mapAuthorityByClass", "(", "array", "$", "authorities", ")", "{", "$", "map", "=", "[", "]", ";", "foreach", "(", "$", "authorities", "as", "$", "authority", ")", "{", "if", "(", "$", "authority", "instanceof", "Model", ")", "{", "$", "map", "[", "get_class", "(", "$", "authority", ")", "]", "[", "]", "=", "$", "authority", "->", "getKey", "(", ")", ";", "}", "else", "{", "$", "map", "[", "Models", "::", "classname", "(", "User", "::", "class", ")", "]", "[", "]", "=", "$", "authority", ";", "}", "}", "return", "$", "map", ";", "}" ]
Map a list of authorities by their class name. @param array $authorities @return array
[ "Map", "a", "list", "of", "authorities", "by", "their", "class", "name", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Helpers.php#L170-L183
train
JosephSilber/bouncer
src/Helpers.php
Helpers.partition
public static function partition($items, callable $callback) { $partitions = [new Collection, new Collection]; foreach ($items as $key => $item) { $partitions[(int) ! $callback($item, $key)][$key] = $item; } return new Collection($partitions); }
php
public static function partition($items, callable $callback) { $partitions = [new Collection, new Collection]; foreach ($items as $key => $item) { $partitions[(int) ! $callback($item, $key)][$key] = $item; } return new Collection($partitions); }
[ "public", "static", "function", "partition", "(", "$", "items", ",", "callable", "$", "callback", ")", "{", "$", "partitions", "=", "[", "new", "Collection", ",", "new", "Collection", "]", ";", "foreach", "(", "$", "items", "as", "$", "key", "=>", "$", "item", ")", "{", "$", "partitions", "[", "(", "int", ")", "!", "$", "callback", "(", "$", "item", ",", "$", "key", ")", "]", "[", "$", "key", "]", "=", "$", "item", ";", "}", "return", "new", "Collection", "(", "$", "partitions", ")", ";", "}" ]
Partition the given collection into two collection using the given callback. @param iterable $items @param callable $callback @return \Illuminate\Support\Collection
[ "Partition", "the", "given", "collection", "into", "two", "collection", "using", "the", "given", "callback", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Helpers.php#L192-L201
train
JosephSilber/bouncer
src/Database/Scope/Scope.php
Scope.applyToModel
public function applyToModel(Model $model) { if (! $this->onlyScopeRelations && ! is_null($this->scope)) { $model->scope = $this->scope; } return $model; }
php
public function applyToModel(Model $model) { if (! $this->onlyScopeRelations && ! is_null($this->scope)) { $model->scope = $this->scope; } return $model; }
[ "public", "function", "applyToModel", "(", "Model", "$", "model", ")", "{", "if", "(", "!", "$", "this", "->", "onlyScopeRelations", "&&", "!", "is_null", "(", "$", "this", "->", "scope", ")", ")", "{", "$", "model", "->", "scope", "=", "$", "this", "->", "scope", ";", "}", "return", "$", "model", ";", "}" ]
Scope the given model to the current tenant. @param \Illuminate\Database\Eloquent\Model $model @return \Illuminate\Database\Eloquent\Model
[ "Scope", "the", "given", "model", "to", "the", "current", "tenant", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Scope/Scope.php#L94-L101
train
JosephSilber/bouncer
src/Database/Scope/Scope.php
Scope.applyToModelQuery
public function applyToModelQuery($query, $table = null) { if (is_null($this->scope) || $this->onlyScopeRelations) { return $query; } if (is_null($table)) { $table = $query->getModel()->getTable(); } return $this->applyToQuery($query, $table); }
php
public function applyToModelQuery($query, $table = null) { if (is_null($this->scope) || $this->onlyScopeRelations) { return $query; } if (is_null($table)) { $table = $query->getModel()->getTable(); } return $this->applyToQuery($query, $table); }
[ "public", "function", "applyToModelQuery", "(", "$", "query", ",", "$", "table", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "scope", ")", "||", "$", "this", "->", "onlyScopeRelations", ")", "{", "return", "$", "query", ";", "}", "if", "(", "is_null", "(", "$", "table", ")", ")", "{", "$", "table", "=", "$", "query", "->", "getModel", "(", ")", "->", "getTable", "(", ")", ";", "}", "return", "$", "this", "->", "applyToQuery", "(", "$", "query", ",", "$", "table", ")", ";", "}" ]
Scope the given model query to the current tenant. @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query @param string|null $table @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
[ "Scope", "the", "given", "model", "query", "to", "the", "current", "tenant", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Scope/Scope.php#L110-L121
train
JosephSilber/bouncer
src/Database/Scope/Scope.php
Scope.applyToRelationQuery
public function applyToRelationQuery($query, $table) { if (is_null($this->scope)) { return $query; } return $this->applyToQuery($query, $table); }
php
public function applyToRelationQuery($query, $table) { if (is_null($this->scope)) { return $query; } return $this->applyToQuery($query, $table); }
[ "public", "function", "applyToRelationQuery", "(", "$", "query", ",", "$", "table", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "scope", ")", ")", "{", "return", "$", "query", ";", "}", "return", "$", "this", "->", "applyToQuery", "(", "$", "query", ",", "$", "table", ")", ";", "}" ]
Scope the given relationship query to the current tenant. @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query @param string $table @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
[ "Scope", "the", "given", "relationship", "query", "to", "the", "current", "tenant", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Scope/Scope.php#L130-L137
train
JosephSilber/bouncer
src/Database/Scope/Scope.php
Scope.applyToRelation
public function applyToRelation(BelongsToMany $relation) { $this->applyToRelationQuery( $relation->getQuery(), $relation->getTable() ); return $relation; }
php
public function applyToRelation(BelongsToMany $relation) { $this->applyToRelationQuery( $relation->getQuery(), $relation->getTable() ); return $relation; }
[ "public", "function", "applyToRelation", "(", "BelongsToMany", "$", "relation", ")", "{", "$", "this", "->", "applyToRelationQuery", "(", "$", "relation", "->", "getQuery", "(", ")", ",", "$", "relation", "->", "getTable", "(", ")", ")", ";", "return", "$", "relation", ";", "}" ]
Scope the given relation to the current tenant. @param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
[ "Scope", "the", "given", "relation", "to", "the", "current", "tenant", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Scope/Scope.php#L145-L153
train
JosephSilber/bouncer
src/Database/Scope/Scope.php
Scope.applyToQuery
protected function applyToQuery($query, $table) { return $query->where(function ($query) use ($table) { $query->where("{$table}.scope", $this->scope) ->orWhereNull("{$table}.scope"); }); }
php
protected function applyToQuery($query, $table) { return $query->where(function ($query) use ($table) { $query->where("{$table}.scope", $this->scope) ->orWhereNull("{$table}.scope"); }); }
[ "protected", "function", "applyToQuery", "(", "$", "query", ",", "$", "table", ")", "{", "return", "$", "query", "->", "where", "(", "function", "(", "$", "query", ")", "use", "(", "$", "table", ")", "{", "$", "query", "->", "where", "(", "\"{$table}.scope\"", ",", "$", "this", "->", "scope", ")", "->", "orWhereNull", "(", "\"{$table}.scope\"", ")", ";", "}", ")", ";", "}" ]
Apply the current scope to the given query. This internal method does not check whether the given query needs to be scoped. That is fully the caller's responsibility. @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query @param string $table @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
[ "Apply", "the", "current", "scope", "to", "the", "given", "query", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Scope/Scope.php#L166-L172
train
JosephSilber/bouncer
src/Database/Scope/Scope.php
Scope.getAttachAttributes
public function getAttachAttributes($authority = null) { if (is_null($this->scope)) { return []; } if (! $this->scopeRoleAbilities && $this->isRoleClass($authority)) { return []; } return ['scope' => $this->scope]; }
php
public function getAttachAttributes($authority = null) { if (is_null($this->scope)) { return []; } if (! $this->scopeRoleAbilities && $this->isRoleClass($authority)) { return []; } return ['scope' => $this->scope]; }
[ "public", "function", "getAttachAttributes", "(", "$", "authority", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "scope", ")", ")", "{", "return", "[", "]", ";", "}", "if", "(", "!", "$", "this", "->", "scopeRoleAbilities", "&&", "$", "this", "->", "isRoleClass", "(", "$", "authority", ")", ")", "{", "return", "[", "]", ";", "}", "return", "[", "'scope'", "=>", "$", "this", "->", "scope", "]", ";", "}" ]
Get the additional attributes for pivot table records. @param string|null $authority @return array
[ "Get", "the", "additional", "attributes", "for", "pivot", "table", "records", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Scope/Scope.php#L190-L201
train
JosephSilber/bouncer
src/Database/Scope/Scope.php
Scope.onceTo
public function onceTo($scope, callable $callback) { $mainScope = $this->scope; $this->scope = $scope; $result = $callback(); $this->scope = $mainScope; return $result; }
php
public function onceTo($scope, callable $callback) { $mainScope = $this->scope; $this->scope = $scope; $result = $callback(); $this->scope = $mainScope; return $result; }
[ "public", "function", "onceTo", "(", "$", "scope", ",", "callable", "$", "callback", ")", "{", "$", "mainScope", "=", "$", "this", "->", "scope", ";", "$", "this", "->", "scope", "=", "$", "scope", ";", "$", "result", "=", "$", "callback", "(", ")", ";", "$", "this", "->", "scope", "=", "$", "mainScope", ";", "return", "$", "result", ";", "}" ]
Run the given callback with the given temporary scope. @param mixed $scope @param callable $callback @return mixed
[ "Run", "the", "given", "callback", "with", "the", "given", "temporary", "scope", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Scope/Scope.php#L210-L221
train
JosephSilber/bouncer
src/BouncerServiceProvider.php
BouncerServiceProvider.registerBouncer
protected function registerBouncer() { $this->app->singleton(Bouncer::class, function () { return Bouncer::make() ->withClipboard(new CachedClipboard(new ArrayStore)) ->withGate($this->app->make(Gate::class)) ->create(); }); }
php
protected function registerBouncer() { $this->app->singleton(Bouncer::class, function () { return Bouncer::make() ->withClipboard(new CachedClipboard(new ArrayStore)) ->withGate($this->app->make(Gate::class)) ->create(); }); }
[ "protected", "function", "registerBouncer", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "Bouncer", "::", "class", ",", "function", "(", ")", "{", "return", "Bouncer", "::", "make", "(", ")", "->", "withClipboard", "(", "new", "CachedClipboard", "(", "new", "ArrayStore", ")", ")", "->", "withGate", "(", "$", "this", "->", "app", "->", "make", "(", "Gate", "::", "class", ")", ")", "->", "create", "(", ")", ";", "}", ")", ";", "}" ]
Register Bouncer as a singleton. @return void
[ "Register", "Bouncer", "as", "a", "singleton", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/BouncerServiceProvider.php#L50-L58
train
JosephSilber/bouncer
src/BouncerServiceProvider.php
BouncerServiceProvider.getTablePrefix
protected function getTablePrefix() { $config = $this->app->config['database']; $connection = array_get($config, 'default'); return array_get($config, "connections.{$connection}.prefix"); }
php
protected function getTablePrefix() { $config = $this->app->config['database']; $connection = array_get($config, 'default'); return array_get($config, "connections.{$connection}.prefix"); }
[ "protected", "function", "getTablePrefix", "(", ")", "{", "$", "config", "=", "$", "this", "->", "app", "->", "config", "[", "'database'", "]", ";", "$", "connection", "=", "array_get", "(", "$", "config", ",", "'default'", ")", ";", "return", "array_get", "(", "$", "config", ",", "\"connections.{$connection}.prefix\"", ")", ";", "}" ]
Get the configured table prefix. @return string|null
[ "Get", "the", "configured", "table", "prefix", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/BouncerServiceProvider.php#L97-L104
train
JosephSilber/bouncer
src/Database/Queries/Abilities.php
Abilities.forAuthority
public static function forAuthority(Model $authority, $allowed = true) { return Models::ability()->where(function ($query) use ($authority, $allowed) { $query->whereExists(static::getRoleConstraint($authority, $allowed)); $query->orWhereExists(static::getAuthorityConstraint($authority, $allowed)); $query->orWhereExists(static::getEveryoneConstraint($allowed)); }); }
php
public static function forAuthority(Model $authority, $allowed = true) { return Models::ability()->where(function ($query) use ($authority, $allowed) { $query->whereExists(static::getRoleConstraint($authority, $allowed)); $query->orWhereExists(static::getAuthorityConstraint($authority, $allowed)); $query->orWhereExists(static::getEveryoneConstraint($allowed)); }); }
[ "public", "static", "function", "forAuthority", "(", "Model", "$", "authority", ",", "$", "allowed", "=", "true", ")", "{", "return", "Models", "::", "ability", "(", ")", "->", "where", "(", "function", "(", "$", "query", ")", "use", "(", "$", "authority", ",", "$", "allowed", ")", "{", "$", "query", "->", "whereExists", "(", "static", "::", "getRoleConstraint", "(", "$", "authority", ",", "$", "allowed", ")", ")", ";", "$", "query", "->", "orWhereExists", "(", "static", "::", "getAuthorityConstraint", "(", "$", "authority", ",", "$", "allowed", ")", ")", ";", "$", "query", "->", "orWhereExists", "(", "static", "::", "getEveryoneConstraint", "(", "$", "allowed", ")", ")", ";", "}", ")", ";", "}" ]
Get a query for the authority's abilities. @param \Illuminate\Database\Eloquent\Model $authority @param bool $allowed @return \Illuminate\Database\Eloquent\Builder
[ "Get", "a", "query", "for", "the", "authority", "s", "abilities", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/Abilities.php#L19-L26
train
JosephSilber/bouncer
src/Database/Queries/Abilities.php
Abilities.getRoleConstraint
protected static function getRoleConstraint(Model $authority, $allowed) { return function ($query) use ($authority, $allowed) { $permissions = Models::table('permissions'); $abilities = Models::table('abilities'); $roles = Models::table('roles'); $prefix = Models::prefix(); $query->from($roles) ->join($permissions, $roles.'.id', '=', $permissions.'.entity_id') ->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id") ->where($permissions.".forbidden", ! $allowed) ->where($permissions.".entity_type", Models::role()->getMorphClass()); Models::scope()->applyToModelQuery($query, $roles); Models::scope()->applyToRelationQuery($query, $permissions); $query->where(function ($query) use ($roles, $authority, $allowed) { $query->whereExists(static::getAuthorityRoleConstraint($authority)); if ($allowed) { static::addRoleInheritCondition($query, $authority, $roles); } }); }; }
php
protected static function getRoleConstraint(Model $authority, $allowed) { return function ($query) use ($authority, $allowed) { $permissions = Models::table('permissions'); $abilities = Models::table('abilities'); $roles = Models::table('roles'); $prefix = Models::prefix(); $query->from($roles) ->join($permissions, $roles.'.id', '=', $permissions.'.entity_id') ->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id") ->where($permissions.".forbidden", ! $allowed) ->where($permissions.".entity_type", Models::role()->getMorphClass()); Models::scope()->applyToModelQuery($query, $roles); Models::scope()->applyToRelationQuery($query, $permissions); $query->where(function ($query) use ($roles, $authority, $allowed) { $query->whereExists(static::getAuthorityRoleConstraint($authority)); if ($allowed) { static::addRoleInheritCondition($query, $authority, $roles); } }); }; }
[ "protected", "static", "function", "getRoleConstraint", "(", "Model", "$", "authority", ",", "$", "allowed", ")", "{", "return", "function", "(", "$", "query", ")", "use", "(", "$", "authority", ",", "$", "allowed", ")", "{", "$", "permissions", "=", "Models", "::", "table", "(", "'permissions'", ")", ";", "$", "abilities", "=", "Models", "::", "table", "(", "'abilities'", ")", ";", "$", "roles", "=", "Models", "::", "table", "(", "'roles'", ")", ";", "$", "prefix", "=", "Models", "::", "prefix", "(", ")", ";", "$", "query", "->", "from", "(", "$", "roles", ")", "->", "join", "(", "$", "permissions", ",", "$", "roles", ".", "'.id'", ",", "'='", ",", "$", "permissions", ".", "'.entity_id'", ")", "->", "whereRaw", "(", "\"{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id\"", ")", "->", "where", "(", "$", "permissions", ".", "\".forbidden\"", ",", "!", "$", "allowed", ")", "->", "where", "(", "$", "permissions", ".", "\".entity_type\"", ",", "Models", "::", "role", "(", ")", "->", "getMorphClass", "(", ")", ")", ";", "Models", "::", "scope", "(", ")", "->", "applyToModelQuery", "(", "$", "query", ",", "$", "roles", ")", ";", "Models", "::", "scope", "(", ")", "->", "applyToRelationQuery", "(", "$", "query", ",", "$", "permissions", ")", ";", "$", "query", "->", "where", "(", "function", "(", "$", "query", ")", "use", "(", "$", "roles", ",", "$", "authority", ",", "$", "allowed", ")", "{", "$", "query", "->", "whereExists", "(", "static", "::", "getAuthorityRoleConstraint", "(", "$", "authority", ")", ")", ";", "if", "(", "$", "allowed", ")", "{", "static", "::", "addRoleInheritCondition", "(", "$", "query", ",", "$", "authority", ",", "$", "roles", ")", ";", "}", "}", ")", ";", "}", ";", "}" ]
Get a constraint for abilities that have been granted to the given authority through a role. @param \Illuminate\Database\Eloquent\Model $authority @param bool $allowed @return \Closure
[ "Get", "a", "constraint", "for", "abilities", "that", "have", "been", "granted", "to", "the", "given", "authority", "through", "a", "role", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/Abilities.php#L46-L71
train
JosephSilber/bouncer
src/Database/Queries/Abilities.php
Abilities.addRoleInheritCondition
protected static function addRoleInheritCondition(Builder $query, Model $authority, $roles) { $query->orWhere('level', '<', function ($query) use ($authority, $roles) { $query->selectRaw('max(level)') ->from($roles) ->whereExists(static::getAuthorityRoleConstraint($authority)); Models::scope()->applyToModelQuery($query, $roles); }); }
php
protected static function addRoleInheritCondition(Builder $query, Model $authority, $roles) { $query->orWhere('level', '<', function ($query) use ($authority, $roles) { $query->selectRaw('max(level)') ->from($roles) ->whereExists(static::getAuthorityRoleConstraint($authority)); Models::scope()->applyToModelQuery($query, $roles); }); }
[ "protected", "static", "function", "addRoleInheritCondition", "(", "Builder", "$", "query", ",", "Model", "$", "authority", ",", "$", "roles", ")", "{", "$", "query", "->", "orWhere", "(", "'level'", ",", "'<'", ",", "function", "(", "$", "query", ")", "use", "(", "$", "authority", ",", "$", "roles", ")", "{", "$", "query", "->", "selectRaw", "(", "'max(level)'", ")", "->", "from", "(", "$", "roles", ")", "->", "whereExists", "(", "static", "::", "getAuthorityRoleConstraint", "(", "$", "authority", ")", ")", ";", "Models", "::", "scope", "(", ")", "->", "applyToModelQuery", "(", "$", "query", ",", "$", "roles", ")", ";", "}", ")", ";", "}" ]
Add the role inheritence "where" clause to the given query. @param \Illuminate\Database\Query\Builder $query @param \Illuminate\Database\Eloquent\Model $authority @param string $roles @return \Closure
[ "Add", "the", "role", "inheritence", "where", "clause", "to", "the", "given", "query", "." ]
c2a4eb33266a36e381e09f8a3556f056e8ea996d
https://github.com/JosephSilber/bouncer/blob/c2a4eb33266a36e381e09f8a3556f056e8ea996d/src/Database/Queries/Abilities.php#L81-L90
train