idx int64 0 241k | question stringlengths 64 6.21k | target stringlengths 5 803 |
|---|---|---|
3,700 | 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 . |
3,701 | 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 . |
3,702 | 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 |
3,703 | 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 |
3,704 | 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 |
3,705 | 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 . |
3,706 | 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 |
3,707 | 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 . |
3,708 | protected function getItems ( array $ items ) { $ result = array ( ) ; foreach ( $ items as $ item ) { $ result [ ] = $ this -> getItem ( $ item ) ; } return $ result ; } | Return string for adding all foreign keys |
3,709 | 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 |
3,710 | 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 |
3,711 | 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 . |
3,712 | 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 . |
3,713 | 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 . |
3,714 | 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 |
3,715 | 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 |
3,716 | 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 |
3,717 | 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 |
3,718 | public function run ( ) { $ this -> running = true ; try { while ( $ this -> running ) { if ( $ this -> isEmpty ( ) ) { return ; } $ this -> tick ( ) ; } } finally { $ this -> stop ( ) ; } } | Run the event loop . |
3,719 | protected function error ( \ Throwable $ exception ) { if ( $ this -> errorHandler === null ) { throw $ exception ; } ( $ this -> errorHandler ) ( $ exception ) ; } | Invokes the error handler with the given exception . |
3,720 | 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 : throw new \ Error ( "Unknown watcher type" ) ; } 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 . |
3,721 | 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 . |
3,722 | 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 { $ message .= ", define environment variable AMP_DEBUG or const AMP_DEBUG = true and enable assertions " . "for a stacktrace of the previous resolution." ; } 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 ) ; $ 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 . |
3,723 | 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 . |
3,724 | 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 . |
3,725 | 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 . |
3,726 | protected function getFormattedValue ( Model $ model , string $ key , $ value ) { if ( $ model -> hasGetMutator ( $ key ) ) { return $ model -> mutateAttribute ( $ key , $ value ) ; } if ( $ model -> hasCast ( $ key ) ) { return $ model -> castAttribute ( $ key , $ value ) ; } if ( $ value !== null && in_array ( $ key , $ model -> getDates ( ) , true ) ) { return $ model -> asDateTime ( $ value ) ; } return $ value ; } | Get the formatted value of an Eloquent model . |
3,727 | 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 . |
3,728 | protected function resolveAuditExclusions ( ) { $ this -> excludedAttributes = $ this -> getAuditExclude ( ) ; if ( $ this -> getAuditStrict ( ) ) { $ this -> excludedAttributes = array_merge ( $ this -> excludedAttributes , $ this -> hidden ) ; if ( $ this -> visible ) { $ invisible = array_diff ( array_keys ( $ this -> attributes ) , $ this -> visible ) ; $ this -> excludedAttributes = array_merge ( $ this -> excludedAttributes , $ invisible ) ; } } 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 ( ) ; } } $ attributes = Arr :: except ( $ this -> attributes , $ this -> excludedAttributes ) ; foreach ( $ attributes as $ attribute => $ value ) { if ( is_array ( $ value ) || ( is_object ( $ value ) && ! method_exists ( $ value , '__toString' ) ) ) { $ this -> excludedAttributes [ ] = $ attribute ; } } } | Resolve the Auditable attributes to exclude from the Audit . |
3,729 | 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 . |
3,730 | 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 . |
3,731 | 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 . |
3,732 | 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 . |
3,733 | 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 . |
3,734 | 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 . |
3,735 | 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 . |
3,736 | protected function fireAuditingEvent ( Auditable $ model , AuditDriver $ driver ) : bool { return $ this -> app -> make ( 'events' ) -> until ( new Auditing ( $ model , $ driver ) ) !== false ; } | Fire the Auditing event . |
3,737 | 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 . |
3,738 | 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 . |
3,739 | public function setConstraints ( Constrainer $ constrainer ) { $ this -> options = array_merge ( $ this -> options , [ 'constraints' => $ constrainer -> data ( ) , ] ) ; return $ this ; } | Set the ability s constraints . |
3,740 | public static function createForModel ( $ model , $ attributes ) { $ model = static :: makeForModel ( $ model , $ attributes ) ; $ model -> save ( ) ; return $ model ; } | Create a new ability for a specific model . |
3,741 | 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 . |
3,742 | 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 . |
3,743 | 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 . |
3,744 | 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 . |
3,745 | 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 . |
3,746 | 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 . |
3,747 | 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 . |
3,748 | 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 . |
3,749 | 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 . |
3,750 | 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 . |
3,751 | public function an ( $ role ) { $ roles = func_get_args ( ) ; return $ this -> clipboard -> checkRole ( $ this -> authority , $ roles , 'or' ) ; } | Alias to the a method . |
3,752 | public function notAn ( $ role ) { $ roles = func_get_args ( ) ; return $ this -> clipboard -> checkRole ( $ this -> authority , $ roles , 'not' ) ; } | Alias to the notA method . |
3,753 | 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 . |
3,754 | 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 . |
3,755 | 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 . |
3,756 | 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 . |
3,757 | 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 . |
3,758 | 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 . |
3,759 | 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 . |
3,760 | 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 . |
3,761 | 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 . |
3,762 | 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 . |
3,763 | 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 . |
3,764 | 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 . |
3,765 | 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 . |
3,766 | public function setCache ( Store $ cache ) { if ( method_exists ( $ cache , 'tags' ) ) { $ cache = $ cache -> tags ( $ this -> tag ( ) ) ; } $ this -> cache = $ cache ; return $ this ; } | Set the cache instance . |
3,767 | 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 . |
3,768 | 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 . |
3,769 | 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 . |
3,770 | 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 . |
3,771 | 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 . |
3,772 | 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 . |
3,773 | 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 . |
3,774 | 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 . |
3,775 | 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 . |
3,776 | 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 . |
3,777 | 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 . |
3,778 | 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 . |
3,779 | 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 . |
3,780 | public function build ( ) { if ( $ this -> constraints -> count ( ) == 1 ) { return $ this -> constraints -> first ( ) ; } return new Group ( $ this -> constraints ) ; } | Build the compiled list of constraints . |
3,781 | protected function whereNested ( $ logicalOperator , Closure $ callback ) { $ callback ( $ builder = new static ) ; $ constraint = $ builder -> build ( ) -> logicalOperator ( $ logicalOperator ) ; return $ this -> addConstraint ( $ constraint ) ; } | Add a nested where clause . |
3,782 | 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 . |
3,783 | 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 . |
3,784 | 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 . |
3,785 | 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 . |
3,786 | 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 . |
3,787 | 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 . |
3,788 | 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 . |
3,789 | 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 . |
3,790 | 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 . |
3,791 | public function applyToRelation ( BelongsToMany $ relation ) { $ this -> applyToRelationQuery ( $ relation -> getQuery ( ) , $ relation -> getTable ( ) ) ; return $ relation ; } | Scope the given relation to the current tenant . |
3,792 | 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 . |
3,793 | 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 . |
3,794 | 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 . |
3,795 | 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 . |
3,796 | 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 . |
3,797 | 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 . |
3,798 | 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 . |
3,799 | 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 . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.