idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
59,800
public function searchGroups ( $ search , $ by , $ limit = 1 , $ num = 1000 , $ page = 1 ) { $ groups = $ this -> indexGroups ( $ num , $ page ) [ 'data' ] ; $ filtered = array_filter ( $ groups , function ( $ group ) use ( $ search , $ by ) { if ( array_key_exists ( $ by , $ group ) ) { if ( strpos ( $ group [ $ by ] , $ search ) !== false ) { return $ group ; } if ( $ group [ $ by ] === $ search ) { return $ group ; } } return false ; } ) ; if ( $ limit == 1 ) { return array_shift ( $ filtered ) ; } return array_slice ( $ filtered , 0 , $ limit ) ; }
Search if a defined number of Groups exists .
59,801
protected function setupExporter ( ) { if ( $ scope = Input :: get ( Exporter :: $ queryName ) ) { $ this -> model ( ) -> usePaginate ( false ) ; call_user_func ( $ this -> builder , $ this ) ; ( new Exporter ( $ this ) ) -> resolve ( $ this -> exporter ) -> withScope ( $ scope ) -> export ( ) ; } }
Setup grid exporter .
59,802
public function column ( $ name , $ label = '' ) { $ relationName = $ relationColumn = '' ; if ( false !== strpos ( $ name , '.' ) ) { list ( $ relationName , $ relationColumn ) = explode ( '.' , $ name ) ; $ relation = $ this -> model ( ) -> eloquent ( ) -> $ relationName ( ) ; $ label = empty ( $ label ) ? ucfirst ( $ relationColumn ) : $ label ; $ name = snake_case ( $ relationName ) . '.' . $ relationColumn ; } $ column = $ this -> addColumn ( $ name , $ label ) ; if ( isset ( $ relation ) && $ relation instanceof Relation ) { $ this -> model ( ) -> with ( $ relationName ) ; $ column -> setRelation ( $ relationName , $ relationColumn ) ; } return $ column ; }
Add column to Grid .
59,803
protected function setDbColumns ( ) { $ connection = $ this -> model ( ) -> eloquent ( ) -> getConnectionName ( ) ; $ this -> dbColumns = collect ( Schema :: connection ( $ connection ) -> getColumnListing ( $ this -> model ( ) -> getTable ( ) ) ) ; }
Get the table columns for grid .
59,804
protected function handleTableColumn ( $ method , $ label ) { if ( empty ( $ this -> dbColumns ) ) { $ this -> setDbColumns ( ) ; } if ( $ this -> dbColumns -> has ( $ method ) ) { return $ this -> addColumn ( $ method , $ label ) ; } return false ; }
Handle table column for grid .
59,805
protected function prepareValue ( $ key , $ record ) { $ field = $ this -> fields -> first ( function ( Field $ field ) use ( $ key ) { return in_array ( $ key , ( array ) $ field -> column ( ) , true ) ; } ) ; if ( method_exists ( $ field , 'prepare' ) ) { return $ field -> prepare ( $ record ) ; } return $ record ; }
Do prepare work for each field .
59,806
protected function buildNestedArray ( array $ nodes = [ ] , $ parentId = 0 ) { $ branch = [ ] ; if ( empty ( $ nodes ) ) { $ nodes = $ this -> allNodes ( ) ; } foreach ( $ nodes as $ node ) { if ( $ node [ $ this -> parentColumn ] === $ parentId ) { $ children = $ this -> buildNestedArray ( $ nodes , $ node [ $ this -> getKeyName ( ) ] ) ; if ( $ children ) { $ node [ 'children' ] = $ children ; } $ branch [ ] = $ node ; } } return $ branch ; }
Build Nested array .
59,807
public function render ( ) { $ variables = [ 'items' => $ this -> items , 'title' => $ this -> title , 'attributes' => $ this -> formatAttributes ( ) , ] ; return view ( $ this -> view , $ variables ) -> render ( ) ; }
Render Carousel .
59,808
public function render ( ) { $ this -> setupDefaultOptions ( ) ; if ( ! empty ( $ this -> value ) ) { $ this -> attribute ( 'data-initial-preview' , $ this -> preview ( ) ) ; $ this -> attribute ( 'data-initial-caption' , $ this -> initialCaption ( $ this -> value ) ) ; $ this -> setupPreviewOptions ( ) ; } $ this -> options ( [ 'overwriteInitial' => true ] ) ; $ options = json_encode ( $ this -> options ) ; $ this -> script = <<<EOT$("input{$this->getElementClassSelector()}").fileinput({$options});EOT ; return parent :: render ( ) ; }
Render file upload field .
59,809
public static function formatExportQuery ( $ scope = '' , $ args = null ) { $ query = '' ; if ( $ scope === static :: SCOPE_ALL ) { $ query = 'all' ; } if ( $ scope === static :: SCOPE_CURRENT_PAGE ) { $ query = "page:$args" ; } if ( $ scope === static :: SCOPE_SELECTED_ROWS ) { $ query = "selected:$args" ; } return [ static :: $ queryName => $ query ] ; }
Format query for export url .
59,810
public function withError ( $ title = '' , $ message = '' ) { $ error = new MessageBag ( compact ( 'title' , 'message' ) ) ; session ( ) -> flash ( 'error' , $ error ) ; return $ this ; }
Set error message for content .
59,811
protected function getExpression ( $ equation ) { if ( $ this -> fixedVerifyCode !== null ) { return $ this -> fixedVerifyCode ; } return $ equation [ 'first' ] . "~" . $ equation [ 'operator' ] . "~" . $ equation [ 'second' ] . "~=" ; }
Get expresion formula .
59,812
protected function getValue ( $ equation ) { if ( $ this -> fixedVerifyCode !== null ) { return $ this -> fixedVerifyCode ; } return eval ( 'return ' . $ equation [ 'first' ] . $ equation [ 'operator' ] . $ equation [ 'second' ] . ';' ) ; }
Get value of formula
59,813
protected function useDefinedColumn ( ) { $ this -> displayCallbacks = [ ] ; $ class = static :: $ defined [ $ this -> name ] ; if ( $ class instanceof Closure ) { $ this -> display ( $ class ) ; return ; } if ( ! class_exists ( $ class ) || ! is_subclass_of ( $ class , AbstractDisplayer :: class ) ) { throw new \ Exception ( "Invalid column definition [$class]" ) ; } $ grid = $ this -> grid ; $ column = $ this ; $ this -> display ( function ( $ value ) use ( $ grid , $ column , $ class ) { $ definition = new $ class ( $ value , $ grid , $ column , $ this ) ; return $ definition -> display ( ) ; } ) ; }
Use a defined column .
59,814
protected function callBuiltinDisplayer ( $ abstract , $ arguments ) { if ( $ abstract instanceof Closure ) { return $ this -> display ( function ( $ value ) use ( $ abstract , $ arguments ) { return $ abstract -> call ( $ this , ... array_merge ( [ $ value ] , $ arguments ) ) ; } ) ; } if ( class_exists ( $ abstract ) && is_subclass_of ( $ abstract , AbstractDisplayer :: class ) ) { $ grid = $ this -> grid ; $ column = $ this ; return $ this -> display ( function ( $ value ) use ( $ abstract , $ grid , $ column , $ arguments ) { $ displayer = new $ abstract ( $ value , $ grid , $ column , $ this ) ; return call_user_func_array ( [ $ displayer , 'display' ] , $ arguments ) ; } ) ; } return $ this ; }
Call Builtin displayer .
59,815
public function previous ( $ step = 1 ) { return $ this -> siblings ( array_search ( $ this , $ this -> parent -> filters ( ) , true ) - $ step ) ; }
Get previous filter .
59,816
public function next ( $ step = 1 ) { return $ this -> siblings ( array_search ( $ this , $ this -> parent -> filters ( ) , true ) + $ step ) ; }
Get next filter .
59,817
public function condition ( $ inputs ) { $ value = array_get ( $ inputs , $ this -> column ) ; if ( ! isset ( $ value ) ) { return ; } $ this -> value = $ value ; return $ this -> buildCondition ( $ this -> column , $ this -> value ) ; }
Get query condition from filter .
59,818
protected function initAdminDirectory ( ) { $ this -> directory = config ( 'admin.directory' ) ; if ( is_dir ( $ this -> directory ) ) { $ this -> line ( "<error>{$this->directory} directory already exists !</error> " ) ; return ; } $ this -> makeDir ( '/' ) ; $ this -> line ( '<info>Admin directory was created:</info> ' . str_replace ( base_path ( ) , '' , $ this -> directory ) ) ; $ this -> makeDir ( 'Controllers' ) ; $ this -> createHomeController ( ) ; $ this -> createExampleController ( ) ; $ this -> createBootstrapFile ( ) ; $ this -> createRoutesFile ( ) ; }
Initialize the admin directory .
59,819
public function createAdministratorController ( ) { $ controller = $ this -> directory . '/Controllers/AdministratorController.php' ; $ contents = $ this -> getStub ( 'AdministratorController' ) ; $ this -> laravel [ 'files' ] -> put ( $ controller , str_replace ( 'DummyNamespace' , Admin :: controllerNamespace ( ) , $ contents ) ) ; $ this -> line ( '<info>AdministratorController file was created:</info> ' . str_replace ( base_path ( ) , '' , $ controller ) ) ; }
Create AdministratorController .
59,820
protected function createMenuFile ( ) { $ file = $ this -> directory . '/menu.php' ; $ contents = $ this -> getStub ( 'menu' ) ; $ this -> laravel [ 'files' ] -> put ( $ file , $ contents ) ; $ this -> line ( '<info>Menu file was created:</info> ' . str_replace ( base_path ( ) , '' , $ file ) ) ; }
Create menu file .
59,821
protected function normalizeResponse ( $ obj ) { $ result = [ 'path' => ltrim ( $ this -> removePathPrefix ( $ obj -> getPathDisplay ( ) ) , '/' ) ] ; $ objClass = get_class ( $ obj ) ; switch ( $ objClass ) { case 'Kunnu\Dropbox\Models\FolderMetadata' : $ result [ 'type' ] = 'dir' ; break ; case 'Kunnu\Dropbox\Models\FileMetadata' : default : $ result [ 'type' ] = 'file' ; $ result [ 'size' ] = $ obj -> getSize ( ) ; $ result [ 'mimetype' ] = MimeType :: detectByFilename ( $ obj -> getName ( ) ) ; $ result [ 'timestamp' ] = strtotime ( $ obj -> getServerModified ( ) ) ; break ; } return $ result ; }
Normalize a Dropbox File Response .
59,822
protected function upload ( $ path , $ contents , $ opts = [ ] ) { $ location = $ this -> applyPathPrefix ( $ path ) ; try { $ tmpfile = tmpfile ( ) ; fwrite ( $ tmpfile , $ contents ) ; $ localFile = $ this -> getStreamUri ( $ tmpfile ) ; $ obj = $ this -> client -> simpleUpload ( $ localFile , $ location , $ opts ) ; fclose ( $ tmpfile ) ; return $ this -> normalizeResponse ( $ obj ) ; } catch ( DropboxClientException $ e ) { return false ; } }
This function uploads the file to the API using simple upload
59,823
protected function uploadChunked ( $ path , $ resource , $ chunkSize = 8000000 , $ opts = [ ] ) { $ location = $ this -> applyPathPrefix ( $ path ) ; try { $ fileSize = Util :: getStreamSize ( $ resource ) ; $ localFile = $ this -> getStreamUri ( $ resource ) ; $ file = $ this -> client -> uploadChunked ( $ localFile , $ location , $ fileSize , $ chunkSize , $ opts ) ; return $ this -> normalizeResponse ( $ file ) ; } catch ( DropboxClientException $ e ) { return false ; } }
This function uploads the file in chunks instead of whole file
59,824
public function handle ( Request $ request , Closure $ next ) { if ( ! $ this -> auth -> check ( ) ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.access_denied' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; } return $ next ( $ request ) ; }
Check if a user is logged in .
59,825
public function _admin_enqueue_scripts ( ) { $ relative_path = '/vendor/inc2734/wp-customizer-framework/src/assets/js/wp-customizer-framework.js' ; $ src = get_template_directory_uri ( ) . $ relative_path ; $ path = get_template_directory ( ) . $ relative_path ; wp_enqueue_script ( 'inc2734-wp-customizer-framework' , $ src , [ 'jquery' ] , filemtime ( $ path ) , true ) ; }
Enqueue assets for admin page
59,826
public function _print_gutenberg_styles ( ) { $ screen = get_current_screen ( ) ; if ( ! $ screen || 'post' !== $ screen -> base ) { return ; } $ post = get_post ( ) ; $ use_gutenberg_plugin = function_exists ( '\is_gutenberg_page' ) && \ is_gutenberg_page ( ) ; $ use_block_editor = function_exists ( '\use_block_editor_for_post' ) && \ use_block_editor_for_post ( $ post ) ; if ( ! $ post || ! $ use_gutenberg_plugin && ! $ use_block_editor ) { return ; } echo '<style id="wp-customizer-framework-print-styles">' ; do_action ( 'inc2734_wp_customizer_framework_print_gutenberg_styles' ) ; echo '</style>' ; }
Print styles from registerd styles
59,827
protected function deleteFilesAndImages ( $ id ) { $ data = $ this -> model -> with ( $ this -> getRelations ( ) ) -> findOrFail ( $ id ) -> toArray ( ) ; $ this -> builder -> fields ( ) -> filter ( function ( $ field ) { return $ field instanceof Field \ File ; } ) -> each ( function ( File $ file ) use ( $ data ) { $ file -> setOriginal ( $ data ) ; $ file -> destroy ( ) ; } ) ; }
Remove files or images in record .
59,828
public function store ( ) { $ data = Input :: all ( ) ; if ( $ validationMessages = $ this -> validationMessages ( $ data ) ) { return back ( ) -> withInput ( ) -> withErrors ( $ validationMessages ) ; } if ( ( $ response = $ this -> prepare ( $ data ) ) instanceof Response ) { return $ response ; } DB :: transaction ( function ( ) { $ inserts = $ this -> prepareInsert ( $ this -> updates ) ; foreach ( $ inserts as $ column => $ value ) { $ this -> model -> setAttribute ( $ column , $ value ) ; } $ this -> model -> save ( ) ; $ this -> updateRelation ( $ this -> relations ) ; } ) ; if ( ( $ response = $ this -> complete ( $ this -> saved ) ) instanceof Response ) { return $ response ; } if ( $ response = $ this -> ajaxResponse ( trans ( 'admin.save_succeeded' ) ) ) { return $ response ; } return $ this -> redirectAfterStore ( ) ; }
Store a new record .
59,829
protected function getRelationInputs ( $ inputs = [ ] ) { $ relations = [ ] ; foreach ( $ inputs as $ column => $ value ) { if ( method_exists ( $ this -> model , $ column ) ) { $ relation = call_user_func ( [ $ this -> model , $ column ] ) ; if ( $ relation instanceof Relation ) { $ relations [ $ column ] = $ value ; } } } return $ relations ; }
Get inputs for relations .
59,830
protected function handleOrderable ( $ id , array $ input = [ ] ) { if ( array_key_exists ( '_orderable' , $ input ) ) { $ model = $ this -> model -> find ( $ id ) ; if ( $ model instanceof Sortable ) { 1 === $ input [ '_orderable' ] ? $ model -> moveOrderUp ( ) : $ model -> moveOrderDown ( ) ; return true ; } } return false ; }
Handle orderable update .
59,831
protected function getFieldByColumn ( $ column ) { return $ this -> builder -> fields ( ) -> first ( function ( Field $ field ) use ( $ column ) { if ( is_array ( $ field -> column ( ) ) ) { return in_array ( $ column , $ field -> column ( ) , true ) ; } return $ field -> column ( ) === $ column ; } ) ; }
Find field object by column .
59,832
protected function setFieldValue ( $ id ) { $ relations = $ this -> getRelations ( ) ; $ this -> model = $ this -> model -> with ( $ relations ) -> findOrFail ( $ id ) ; $ data = $ this -> model -> toArray ( ) ; $ this -> builder -> fields ( ) -> each ( function ( Field $ field ) use ( $ data ) { $ field -> fill ( $ data ) ; } ) ; }
Set all fields value in form .
59,833
public static function collectFieldAssets ( ) { if ( ! empty ( static :: $ collectedAssets ) ) { return static :: $ collectedAssets ; } $ css = collect ( ) ; $ js = collect ( ) ; foreach ( static :: $ availableFields as $ field ) { if ( ! method_exists ( $ field , 'getAssets' ) ) { continue ; } $ assets = call_user_func ( [ $ field , 'getAssets' ] ) ; $ css -> push ( array_get ( $ assets , 'css' ) ) ; $ js -> push ( array_get ( $ assets , 'js' ) ) ; } return static :: $ collectedAssets = [ 'css' => $ css -> flatten ( ) -> unique ( ) -> filter ( ) -> toArray ( ) , 'js' => $ js -> flatten ( ) -> unique ( ) -> filter ( ) -> toArray ( ) , ] ; }
Collect assets required by registered field .
59,834
public static function extend ( $ placeholder , array $ selectors ) { if ( ! isset ( static :: $ placeholders [ $ placeholder ] ) ) { static :: $ placeholders [ $ placeholder ] = [ ] ; } static :: $ placeholders [ $ placeholder ] = array_merge ( static :: $ placeholders [ $ placeholder ] , $ selectors ) ; }
Set selectors . Styles of these selectors output like extend of Sass .
59,835
public function saveOrder ( $ serialize ) { $ tree = json_decode ( $ serialize , true ) ; if ( JSON_ERROR_NONE !== json_last_error ( ) ) { throw new \ InvalidArgumentException ( json_last_error_msg ( ) ) ; } $ this -> model -> saveOrder ( $ tree ) ; return true ; }
Save tree order from a input .
59,836
public function catchAll ( ) { $ isCatchallDomain = null ; if ( $ this -> options [ 'catchAllEnabled' ] ) { try { $ isCatchallDomain = $ this -> transport -> getSmtp ( ) -> acceptsAnyRecipient ( $ this -> dom ) ; } catch ( \ Exception $ e ) { $ this -> statusManager -> setStatus ( $ this -> users , $ this -> dom , $ this -> options [ 'catchAllIsValid' ] , 'error while on CatchAll test: ' . $ e ) ; } if ( $ isCatchallDomain ) { if ( ! $ this -> options [ 'catchAllIsValid' ] ) { $ this -> statusManager -> setStatus ( $ this -> users , $ this -> dom , $ this -> options [ 'catchAllIsValid' ] , 'catch all detected' ) ; return true ; } } } }
Do a catch - all test for the domain . This increases checking time for a domain slightly but doesn t confuse users .
59,837
protected function setupMiddleware ( ) { $ this -> app [ 'router' ] -> middleware ( 'user' , UserMiddleware :: class ) ; $ this -> app [ 'router' ] -> middleware ( 'roles' , RoleMiddleware :: class ) ; $ this -> app [ 'router' ] -> middleware ( 'permissions' , PermissionMiddleware :: class ) ; }
Register the middleware to the application
59,838
protected function setupProviders ( ) { $ this -> app -> register ( SentinelServiceProvider :: class ) ; $ this -> app -> register ( EkkoServiceProvider :: class ) ; $ this -> app -> register ( FlashServiceProvider :: class ) ; $ this -> app -> register ( FormServiceProvider :: class ) ; $ this -> app -> register ( BootFormsServiceProvider :: class ) ; }
Register the providers to the application .
59,839
protected function setupInterfaces ( ) { $ this -> app -> bind ( 'Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface' , config ( 'laraflock.dashboard.authRepositoryClass' ) ) ; $ this -> app -> bind ( 'Laraflock\Dashboard\Repositories\Permission\PermissionRepositoryInterface' , config ( 'laraflock.dashboard.permissionRepositoryClass' ) ) ; $ this -> app -> bind ( 'Laraflock\Dashboard\Repositories\Role\RoleRepositoryInterface' , config ( 'laraflock.dashboard.roleRepositoryClass' ) ) ; $ this -> app -> bind ( 'Laraflock\Dashboard\Repositories\User\UserRepositoryInterface' , config ( 'laraflock.dashboard.userRepositoryClass' ) ) ; $ this -> app -> singleton ( 'Laraflock\Dashboard\Repositories\Module\ModuleRepositoryInterface' , config ( 'laraflock.dashboard.moduleRepositoryClass' ) ) ; }
Register Interface Bindings
59,840
protected function setupConsoleCommands ( ) { $ this -> app [ 'dashboard::install' ] = $ this -> app -> share ( function ( ) { return new InstallerCommand ( ) ; } ) ; $ this -> app [ 'dashboard::setup' ] = $ this -> app -> share ( function ( ) { return new SetupCommand ( ) ; } ) ; $ this -> app [ 'dashboard::fresh' ] = $ this -> app -> share ( function ( ) { return new FreshCommand ( ) ; } ) ; $ this -> app [ 'dashboard::uninstall' ] = $ this -> app -> share ( function ( ) { return new UninstallCommand ( ) ; } ) ; $ this -> commands ( 'dashboard::install' ) ; $ this -> commands ( 'dashboard::setup' ) ; $ this -> commands ( 'dashboard::fresh' ) ; $ this -> commands ( 'dashboard::uninstall' ) ; }
Register the console commands to the application .
59,841
protected function setupFacades ( ) { $ loader = AliasLoader :: getInstance ( ) ; $ loader -> alias ( 'Activation' , Activation :: class ) ; $ loader -> alias ( 'Reminder' , Reminder :: class ) ; $ loader -> alias ( 'Sentinel' , Sentinel :: class ) ; $ loader -> alias ( 'Flash' , Flash :: class ) ; $ loader -> alias ( 'Ekko' , Ekko :: class ) ; $ loader -> alias ( 'Carbon' , Carbon :: class ) ; $ loader -> alias ( 'Form' , Form :: class ) ; $ loader -> alias ( 'BootForm' , BootForm :: class ) ; }
Register the Facades to the application .
59,842
public function update ( Request $ request , $ id ) { if ( $ request -> input ( 'action' ) == 'update_account' ) { try { $ this -> userRepositoryInterface -> update ( $ request -> all ( ) , $ id ) ; } catch ( FormValidationException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'account.edit' ) -> withErrors ( $ e -> getErrors ( ) ) -> withInput ( ) ; } catch ( UsersException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'dashboard.index' ) ; } Flash :: success ( trans ( 'dashboard::dashboard.flash.account.success' ) ) ; return redirect ( ) -> route ( 'account.edit' ) ; } if ( $ request -> input ( 'action' ) == 'change_password' ) { try { $ this -> userRepositoryInterface -> updatePassword ( $ request -> all ( ) ) ; } catch ( FormValidationException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'account.edit' ) -> withErrors ( $ e -> getErrors ( ) ) ; } catch ( AuthenticationException $ e ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.password.fail' ) ) ; return redirect ( ) -> route ( 'account.edit' ) ; } Flash :: success ( trans ( 'dashboard::dashboard.flash.password.success' ) ) ; return redirect ( ) -> route ( 'account.edit' ) ; } }
Update account information .
59,843
public function sanitize_callback ( ) { return function ( $ value ) { if ( ! is_array ( $ value ) ) { $ value = explode ( ',' , $ value ) ; } $ sanitized_values = [ ] ; foreach ( $ value as $ v ) { if ( ! array_key_exists ( $ v , $ this -> args [ 'choices' ] ) ) { continue ; } $ sanitized_values [ ] = $ v ; } $ sanitized_values = array_map ( 'sanitize_text_field' , $ sanitized_values ) ; return implode ( ',' , $ sanitized_values ) ; } ; }
Sanitize callback function
59,844
protected function formatName ( $ column ) { if ( is_string ( $ column ) ) { $ name = explode ( '.' , $ column ) ; if ( 1 === count ( $ name ) ) { return $ name [ 0 ] ; } $ html = array_shift ( $ name ) ; foreach ( $ name as $ piece ) { $ html .= "[$piece]" ; } return $ html ; } if ( is_array ( $ this -> column ) ) { $ names = [ ] ; foreach ( $ this -> column as $ key => $ name ) { $ names [ $ key ] = $ this -> formatName ( $ name ) ; } return $ names ; } return '' ; }
Format the name of the field .
59,845
public function submitButton ( ) { if ( self :: MODE_VIEW === $ this -> mode ) { return '' ; } if ( ! $ this -> options [ 'enableSubmit' ] ) { return '' ; } if ( self :: MODE_EDIT === $ this -> mode ) { $ text = trans ( 'admin.save' ) ; } else { $ text = trans ( 'admin.submit' ) ; } return <<<EOT<div class="btn-group pull-right"> <button type="submit" class="btn btn-info pull-right" data-loading-text="<i class='fa fa-spinner fa-spin '></i> $text">$text</button></div>EOT ; }
Submit button of form ..
59,846
protected function removeReservedFields ( ) { if ( ! $ this -> isMode ( static :: MODE_CREATE ) ) { return ; } $ reservedColumns = [ $ this -> form -> model ( ) -> getKeyName ( ) , $ this -> form -> model ( ) -> getCreatedAtColumn ( ) , $ this -> form -> model ( ) -> getUpdatedAtColumn ( ) , ] ; $ this -> fields = $ this -> fields ( ) -> reject ( function ( Field $ field ) use ( $ reservedColumns ) { return in_array ( $ field -> column ( ) , $ reservedColumns , true ) ; } ) ; }
Remove reserved fields like id created_at updated_at in form fields .
59,847
public function authentication ( Request $ request ) { try { $ this -> authRepositoryInterface -> authenticate ( $ request -> all ( ) ) ; } catch ( FormValidationException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'auth.login' ) -> withErrors ( $ e -> getErrors ( ) ) ; } catch ( AuthenticationException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; } return redirect ( ) -> route ( 'dashboard.index' ) ; }
Authenticate and Validate login input .
59,848
public function registration ( Request $ request ) { if ( ! config ( 'laraflock.dashboard.registration' ) ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.registration.not_active' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; } try { $ this -> authRepositoryInterface -> register ( $ request -> all ( ) ) ; } catch ( FormValidationException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'auth.register' ) -> withErrors ( $ e -> getErrors ( ) ) -> withInput ( ) ; } catch ( RolesException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'auth.register' ) -> withInput ( ) ; } if ( ! config ( 'laraflock.dashboard.activations' ) ) { Flash :: success ( trans ( 'dashboard::dashboard.flash.registration.activated' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; } Flash :: success ( trans ( 'dashboard::dashboard.flash.registration.created' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; }
Register the user .
59,849
public function activate ( Request $ request ) { if ( ! $ email = $ request -> get ( 'email' ) ) { $ email = null ; } if ( ! $ code = $ request -> get ( 'code' ) ) { $ code = null ; } if ( ! config ( 'laraflock.dashboard.activations' ) ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.activation.not_active' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; } return $ this -> view ( 'auth.activate' ) -> with ( [ 'email' => $ email , 'code' => $ code ] ) ; }
Display activate screen .
59,850
public function activation ( Request $ request ) { if ( ! config ( 'laraflock.dashboard.activations' ) ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.activation.not_active' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; } try { $ this -> authRepositoryInterface -> activate ( $ request -> all ( ) ) ; } catch ( FormValidationException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'auth.activate' ) -> withErrors ( $ e -> getErrors ( ) ) -> withInput ( ) ; } catch ( AuthenticationException $ e ) { Flash :: error ( $ e -> getMessage ( ) ) ; return redirect ( ) -> route ( 'auth.activate' ) -> withInput ( ) ; } Flash :: success ( trans ( 'dashboard::dashboard.flash.activation.success' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; }
Activate a user .
59,851
public function partial ( $ args = null ) { if ( is_null ( $ args ) ) { return $ this -> partial ; } elseif ( is_array ( $ args ) ) { $ this -> partial = new Partial ( $ this -> get_id ( ) , $ args ) ; } }
Control joined to Partial
59,852
public function _set_default_value ( $ value ) { if ( is_null ( $ value ) || false === $ value ) { if ( isset ( $ this -> args [ 'default' ] ) ) { return $ this -> args [ 'default' ] ; } } return $ value ; }
Set default theme_mod
59,853
protected function inExceptArray ( $ request ) { foreach ( config ( 'admin.operation_log.except' ) as $ except ) { if ( '/' !== $ except ) { $ except = trim ( $ except , '/' ) ; } $ methods = [ ] ; if ( Str :: contains ( $ except , ':' ) ) { list ( $ methods , $ except ) = explode ( ':' , $ except ) ; $ methods = explode ( ',' , $ methods ) ; } $ methods = array_map ( 'strtoupper' , $ methods ) ; if ( $ request -> is ( $ except ) && ( empty ( $ methods ) || in_array ( $ request -> method ( ) , $ methods , true ) ) ) { return true ; } } return false ; }
Determine if the request has a URI that should pass through CSRF verification .
59,854
public static function rgba ( $ hex , $ percent ) { $ hex = static :: _hex_normalization ( $ hex ) ; $ rgba = [ ] ; for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { $ dec = hexdec ( substr ( $ hex , $ i * 2 , 2 ) ) ; $ rgba [ ] = $ dec ; } $ rgba = implode ( ',' , $ rgba ) ; $ rgba = "rgba({$rgba}, $percent)" ; return $ rgba ; }
hex to rgba
59,855
private static function _get_hue_based_max_rgb ( $ red , $ green , $ blue ) { $ max_rgb = max ( $ red , $ green , $ blue ) ; $ min_rgb = min ( $ red , $ green , $ blue ) ; $ diff_max_min_rgb = $ max_rgb - $ min_rgb ; if ( $ red === $ max_rgb ) { $ hue = 60 * ( $ diff_max_min_rgb ? ( $ green - $ blue ) / $ diff_max_min_rgb : 0 ) ; } elseif ( $ green === $ max_rgb ) { $ hue = 60 * ( $ diff_max_min_rgb ? ( $ blue - $ red ) / $ diff_max_min_rgb : 0 ) + 120 ; } elseif ( $ blue === $ max_rgb ) { $ hue = 60 * ( $ diff_max_min_rgb ? ( $ red - $ green ) / $ diff_max_min_rgb : 0 ) + 240 ; } return $ hue ; }
Return hue from max rgb
59,856
private static function _get_saturation ( $ hex ) { $ red = hexdec ( substr ( $ hex , 0 , 2 ) ) ; $ green = hexdec ( substr ( $ hex , 2 , 2 ) ) ; $ blue = hexdec ( substr ( $ hex , 4 , 2 ) ) ; $ max_rgb = max ( $ red , $ green , $ blue ) ; $ min_rgb = min ( $ red , $ green , $ blue ) ; $ cnt = round ( ( $ max_rgb + $ min_rgb ) / 2 ) ; if ( 127 >= $ cnt ) { $ tmp = ( $ max_rgb + $ min_rgb ) ; $ saturation = $ tmp ? ( $ max_rgb - $ min_rgb ) / $ tmp : 0 ; } else { $ tmp = ( 510 - $ max_rgb - $ min_rgb ) ; $ saturation = ( $ tmp ) ? ( ( $ max_rgb - $ min_rgb ) / $ tmp ) : 0 ; } return $ saturation * 100 ; }
Return saturation from hex
59,857
private static function _get_luminance ( $ hex ) { $ red = hexdec ( substr ( $ hex , 0 , 2 ) ) ; $ green = hexdec ( substr ( $ hex , 2 , 2 ) ) ; $ blue = hexdec ( substr ( $ hex , 4 , 2 ) ) ; $ max_rgb = max ( $ red , $ green , $ blue ) ; $ min_rgb = min ( $ red , $ green , $ blue ) ; return ( $ max_rgb + $ min_rgb ) / 2 / 255 * 100 ; }
Return luminance from hex
59,858
public static function addBreadcrumbList ( ) { $ view = Yii :: $ app -> getView ( ) ; $ breadcrumbList = [ ] ; if ( isset ( $ view -> params [ 'breadcrumbs' ] ) ) { $ position = 1 ; foreach ( $ view -> params [ 'breadcrumbs' ] as $ breadcrumb ) { if ( is_array ( $ breadcrumb ) ) { $ breadcrumbList [ ] = ( object ) [ "@type" => "http://schema.org/ListItem" , "http://schema.org/position" => $ position , "http://schema.org/item" => ( object ) [ "@id" => Url :: to ( $ breadcrumb [ 'url' ] , true ) , "http://schema.org/name" => $ breadcrumb [ 'label' ] , ] ] ; } else { $ breadcrumbList [ ] = ( object ) [ "@type" => "http://schema.org/ListItem" , "http://schema.org/position" => $ position , "http://schema.org/item" => ( object ) [ "http://schema.org/name" => $ breadcrumb , ] ] ; } $ position ++ ; } } $ doc = ( object ) [ "@type" => "http://schema.org/BreadcrumbList" , "http://schema.org/itemListElement" => $ breadcrumbList ] ; JsonLDHelper :: add ( $ doc ) ; }
Adds BreadcrumbList schema . org markup based on the application view breadcrumbs parameter
59,859
public function getInstalledPackages ( ) { $ packages = [ ] ; $ content = $ this -> getFileContents ( 'composer.lock' ) ; foreach ( [ 'packages' , 'packages-dev' ] as $ key ) { if ( ! isset ( $ content [ $ key ] ) ) { continue ; } foreach ( $ content [ $ key ] as $ package ) { $ name = $ package [ 'name' ] ; $ packages [ $ name ] = [ 'name' => $ name , 'version' => $ package [ 'version' ] , 'devDependency' => $ key === 'packages-dev' , ] ; } } if ( empty ( $ packages ) ) { throw new LogicException ( 'We couldn\'t find any installed packages.' ) ; } return $ packages ; }
Get installed package versions .
59,860
public function getRequiredPackages ( ) { $ packages = [ ] ; $ content = $ this -> getFileContents ( 'composer.json' ) ; foreach ( [ 'require' , 'require-dev' ] as $ key ) { if ( ! isset ( $ content [ $ key ] ) ) { continue ; } foreach ( $ content [ $ key ] as $ name => $ version ) { if ( ! strstr ( $ name , '/' ) ) { continue ; } $ packages [ $ name ] = [ 'name' => $ name , 'version' => $ version , 'devDependency' => $ key === 'require-dev' , ] ; } } if ( empty ( $ packages ) ) { throw new LogicException ( 'We couldn\'t find any required packages.' ) ; } return $ packages ; }
Get required package versions .
59,861
protected function getVariables ( ) { foreach ( $ this -> fields as $ field ) { $ field -> fill ( $ this -> data ) ; } return [ 'fields' => $ this -> fields , 'attributes' => $ this -> formatAttribute ( ) , 'method' => $ this -> attributes [ 'method' ] , ] ; }
Get variables for render form .
59,862
public function versionDiff ( $ current , $ latest ) { $ needle = 0 ; while ( $ needle < strlen ( $ current ) && $ needle < strlen ( $ latest ) ) { if ( $ current [ $ needle ] !== $ latest [ $ needle ] ) { break ; } $ needle ++ ; } return substr ( $ latest , 0 , $ needle ) . '<green>' . substr ( $ latest , $ needle ) . '</green>' ; }
Get the diff between the current and latest version .
59,863
protected function getComposerPathFromInput ( InputInterface $ input ) { if ( $ input -> getOption ( 'directory' ) ) { return $ input -> getOption ( 'directory' ) ; } if ( $ input -> getOption ( 'global' ) ) { return getenv ( 'HOME' ) . '/.composer' ; } }
Get composer path based on user input .
59,864
public function getNewRegistrationIds ( ) { if ( $ this -> getNewRegistrationIdsCount ( ) == 0 ) { return array ( ) ; } $ filteredResults = array_filter ( $ this -> results , function ( $ result ) { return isset ( $ result [ 'registration_id' ] ) ; } ) ; $ data = array_map ( function ( $ result ) { return $ result [ 'registration_id' ] ; } , $ filteredResults ) ; return $ data ; }
Return an array of expired registration ids linked to new id All old registration ids must be updated to new ones in DB
59,865
protected function setRelationSort ( $ column ) { list ( $ relationName , $ relationColumn ) = explode ( '.' , $ column ) ; if ( $ this -> queries -> contains ( function ( $ query ) use ( $ relationName ) { return 'with' === $ query [ 'method' ] && in_array ( $ relationName , $ query [ 'arguments' ] , true ) ; } ) ) { $ relation = $ this -> model -> $ relationName ( ) ; $ this -> queries -> push ( [ 'method' => 'join' , 'arguments' => $ this -> joinParameters ( $ relation ) , ] ) ; $ this -> resetOrderBy ( ) ; $ this -> queries -> push ( [ 'method' => 'orderBy' , 'arguments' => [ $ relation -> getRelated ( ) -> getTable ( ) . '.' . $ relationColumn , $ this -> sort [ 'type' ] , ] , ] ) ; } }
Set relation sort .
59,866
public function _amp_post_template_css ( ) { ob_start ( ) ; $ this -> _print_front_styles ( ) ; $ css = ob_get_clean ( ) ; $ css = str_replace ( '!important' , '' , $ css ) ; echo $ css ; }
Styles for AMP
59,867
public function _tiny_mce_before_init ( $ mce_init ) { $ styles = WP_Customizer_Framework \ Style :: get_registerd_styles ( ) ; if ( ! isset ( $ mce_init [ 'content_style' ] ) ) { $ mce_init [ 'content_style' ] = '' ; } foreach ( $ styles as $ style ) { foreach ( $ style [ 'selectors' ] as $ i => $ selector ) { $ selector = trim ( $ selector ) ; if ( preg_match ( '|^[\.#>]|' , $ selector ) ) { $ style [ 'selectors' ] [ $ i ] = '.mce-content-body.mceContentBody ' . $ selector ; } else { $ style [ 'selectors' ] [ $ i ] = $ selector ; } } $ selectors = addslashes ( implode ( ',' , $ style [ 'selectors' ] ) ) ; $ properties = addslashes ( implode ( ';' , $ style [ 'properties' ] ) ) ; if ( ! $ style [ 'media_query' ] ) { $ mce_init [ 'content_style' ] .= "{$selectors} { {$properties} }" ; } else { $ mce_init [ 'content_style' ] .= "{$style['media_query']} { {$selectors} { {$properties} } }" ; } } return $ mce_init ; }
Styles for TinyMCE
59,868
public function _print_gutenberg_styles ( ) { $ styles = WP_Customizer_Framework \ Style :: get_registerd_styles ( ) ; $ new_styles = [ ] ; foreach ( $ styles as $ styles_index => $ style ) { foreach ( $ style [ 'selectors' ] as $ selectors_index => $ selector ) { $ selector = trim ( $ selector ) ; $ style [ 'selectors' ] [ $ selectors_index ] = '.edit-post-layout__content .editor-styles-wrapper ' . $ selector ; } $ new_styles [ $ styles_index ] = $ style ; } $ this -> _print_styles ( $ new_styles ) ; }
Print styles for Gutenberg
59,869
protected function _print_styles ( $ styles ) { foreach ( $ styles as $ style ) { $ selectors = implode ( ',' , $ style [ 'selectors' ] ) ; $ properties = implode ( ';' , $ style [ 'properties' ] ) ; if ( ! $ style [ 'media_query' ] ) { printf ( '%1$s { %2$s }' , strip_tags ( $ selectors ) , str_replace ( '&quot;' , '"' , esc_textarea ( $ properties ) ) ) ; } else { printf ( '%1$s { %2$s { %3$s } }' , esc_html ( $ style [ 'media_query' ] ) , strip_tags ( $ selectors ) , str_replace ( '&quot;' , '"' , esc_textarea ( $ properties ) ) ) ; } } }
Print styles in head
59,870
public function edit ( $ channelId , $ typeId , $ type , $ allow = null , $ deny = null ) { $ current = $ this -> show ( $ channelId , $ typeId , $ type ) ; if ( is_null ( $ current ) ) { return $ this -> create ( $ channelId , $ typeId , $ type , $ allow , $ deny ) ; } if ( is_null ( $ allow ) ) { $ allow = $ current [ 'allow' ] ; } if ( is_null ( $ deny ) ) { $ deny = $ current [ 'deny' ] ; } return $ this -> request ( 'PUT' , 'channels/' . $ channelId . '/permissions/' . $ typeId , [ 'json' => [ 'type' => $ current [ 'type' ] , 'id' => $ current [ 'id' ] , 'allow' => $ allow , 'deny' => $ deny ] ] ) ; }
Edit channel permissions .
59,871
private function _convert_hsl_to_hex ( $ hue , $ saturation , $ luminance ) { if ( 49 >= $ luminance ) { $ max_hsl = 2.55 * ( $ luminance + $ luminance * ( $ saturation / 100 ) ) ; $ min_hsl = 2.55 * ( $ luminance - $ luminance * ( $ saturation / 100 ) ) ; } else { $ max_hsl = 2.55 * ( $ luminance + ( 100 - $ luminance ) * ( $ saturation / 100 ) ) ; $ min_hsl = 2.55 * ( $ luminance - ( 100 - $ luminance ) * ( $ saturation / 100 ) ) ; } if ( 60 >= $ hue ) { $ red = $ max_hsl ; $ green = ( $ hue / 60 ) * ( $ max_hsl - $ min_hsl ) + $ min_hsl ; $ blue = $ min_hsl ; } elseif ( 120 >= $ hue ) { $ red = ( ( 120 - $ hue ) / 60 ) * ( $ max_hsl - $ min_hsl ) + $ min_hsl ; $ green = $ max_hsl ; $ blue = $ min_hsl ; } elseif ( 180 >= $ hue ) { $ red = $ min_hsl ; $ green = $ max_hsl ; $ blue = ( ( $ hue - 120 ) / 60 ) * ( $ max_hsl - $ min_hsl ) + $ min_hsl ; } elseif ( 240 >= $ hue ) { $ red = $ min_hsl ; $ green = ( ( 240 - $ hue ) / 60 ) * ( $ max_hsl - $ min_hsl ) + $ min_hsl ; $ blue = $ max_hsl ; } elseif ( 300 >= $ hue ) { $ red = ( ( $ hue - 240 ) / 60 ) * ( $ max_hsl - $ min_hsl ) + $ min_hsl ; $ green = $ min_hsl ; $ blue = $ max_hsl ; } else { $ red = $ max_hsl ; $ green = $ min_hsl ; $ blue = ( ( 360 - $ hue ) / 60 ) * ( $ max_hsl - $ min_hsl ) + $ min_hsl ; } $ red = sprintf ( '%02s' , dechex ( round ( $ red ) ) ) ; $ green = sprintf ( '%02s' , dechex ( round ( $ green ) ) ) ; $ blue = sprintf ( '%02s' , dechex ( round ( $ blue ) ) ) ; return '#' . $ red . $ green . $ blue ; }
Convert hsl to hex
59,872
public function bulkSet ( $ registrationIds = array ( ) , $ data = null , $ collapseKey = null ) { $ this -> setRegistrationIds ( $ registrationIds ) ; $ this -> setData ( $ data ) ; $ this -> setCollapseKey ( $ collapseKey ) ; }
Set multiple fields at once .
59,873
public function getOutdatedPackages ( array $ excluded = [ ] ) { $ installed = $ this -> composer -> getInstalledPackages ( ) ; $ required = $ this -> composer -> getRequiredPackages ( ) ; $ outdated = [ ] ; $ packages = array_intersect_key ( $ installed , $ required ) ; foreach ( $ packages as $ package ) { $ name = $ package [ 'name' ] ; $ version = Version :: normalize ( $ package [ 'version' ] ) ; $ prettyVersion = $ required [ $ name ] [ 'version' ] ; $ devDependency = $ package [ 'devDependency' ] ; if ( in_array ( $ name , $ excluded ) ) { continue ; } $ package = new Package ( $ name , $ version , $ prettyVersion , $ devDependency ) ; if ( $ package -> isOutdated ( ) ) { $ outdated [ ] = $ package ; } } return $ outdated ; }
Get outdated packages with their current and latest version .
59,874
protected function buildNestedForm ( $ column , \ Closure $ builder , $ key = null ) { $ form = new Form \ NestedForm ( $ column , $ key ) ; $ form -> setForm ( $ this -> form ) ; call_user_func ( $ builder , $ form ) ; $ form -> hidden ( $ this -> getKeyName ( ) ) ; $ form -> hidden ( NestedForm :: REMOVE_FLAG_NAME ) -> default ( 0 ) -> addElementClass ( NestedForm :: REMOVE_FLAG_CLASS ) ; return $ form ; }
Build a Nested form .
59,875
public function render ( ) { $ this -> view = $ this -> views [ $ this -> viewMode ] ; list ( $ template , $ script ) = $ this -> buildNestedForm ( $ this -> column , $ this -> builder ) -> getTemplateHtmlAndScript ( ) ; $ this -> setupScript ( $ script ) ; return parent :: render ( ) -> with ( [ 'forms' => $ this -> buildRelatedForms ( ) , 'template' => $ template , 'relationName' => $ this -> relationName , ] ) ; }
Render the HasMany field .
59,876
protected function validate ( array $ data ) { $ validator = Validator :: make ( $ data , $ this -> rules ) ; if ( $ validator -> fails ( ) ) { throw new FormValidationException ( trans ( 'dashboard::dashboard.errors.form.validation' ) , $ validator ) ; } }
Validate the form submission .
59,877
public function render ( string $ view , array $ data = [ ] , $ layout = null ) : string { $ output = $ this -> fetch ( $ view , $ data ) ; if ( $ layout === false ) { return $ output ; } return $ this -> renderContent ( $ output , $ data , $ layout ) ; }
Render a view if layout file is setting will use it . throws RuntimeException if view file does not exist
59,878
public function value ( $ value = null ) { if ( is_null ( $ value ) ) { return empty ( $ this -> value ) ? ( $ this -> getDefault ( ) ?? [ ] ) : $ this -> value ; } $ this -> value = $ value ; return $ this ; }
Get or set value for this field .
59,879
public function sendMessage ( ) { $ message = new \ CodeMonkeysRu \ GCM \ Message ( ) ; call_user_func_array ( array ( $ message , 'bulkSet' ) , func_get_args ( ) ) ; return $ this -> send ( $ message ) ; }
Send message to GCM without explicitly created message
59,880
public function send ( Message $ message ) { if ( ! $ this -> serverApiKey ) { throw new Exception ( "Server API Key not set" , Exception :: ILLEGAL_API_KEY ) ; } if ( count ( $ message -> getRegistrationIds ( ) ) > 1000 ) { throw new Exception ( "Malformed request: Registration Ids exceed the GCM imposed limit of 1000" , Exception :: MALFORMED_REQUEST ) ; } $ rawData = $ this -> formMessageData ( $ message ) ; $ this -> validatePayloadSize ( $ rawData , 'data' , 4096 ) ; $ this -> validatePayloadSize ( $ rawData , 'notification' , 2048 ) ; $ data = json_encode ( $ rawData ) ; $ headers = array ( 'Authorization: key=' . $ this -> serverApiKey , 'Content-Type: application/json' ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ this -> gcmUrl ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; if ( $ this -> caInfoPath !== false ) { curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , true ) ; curl_setopt ( $ ch , CURLOPT_CAINFO , $ this -> caInfoPath ) ; } else { curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false ) ; } curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ data ) ; $ resultBody = curl_exec ( $ ch ) ; $ resultHttpCode = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; curl_close ( $ ch ) ; switch ( $ resultHttpCode ) { case "200" : break ; case "400" : throw new Exception ( 'Malformed request. ' . $ resultBody , Exception :: MALFORMED_REQUEST ) ; break ; case "401" : throw new Exception ( 'Authentication Error. ' . $ resultBody , Exception :: AUTHENTICATION_ERROR ) ; break ; default : throw new Exception ( "Unknown error. " . $ resultBody , Exception :: UNKNOWN_ERROR ) ; break ; } return new Response ( $ message , $ resultBody ) ; }
Send message to GCM
59,881
private function formMessageData ( Message $ message ) { $ data = array ( 'registration_ids' => $ message -> getRegistrationIds ( ) , ) ; $ dataFields = array ( 'registration_ids' => 'getRegistrationIds' , 'collapse_key' => 'getCollapseKey' , 'data' => 'getData' , 'notification' => 'getNotification' , 'delay_while_idle' => 'getDelayWhileIdle' , 'time_to_live' => 'getTtl' , 'restricted_package_name' => 'getRestrictedPackageName' , 'dry_run' => 'getDryRun' , 'content_available' => 'getContentAvailable' , 'priority' => 'getPriority' , ) ; foreach ( $ dataFields as $ fieldName => $ getter ) { if ( $ message -> $ getter ( ) != null ) { $ data [ $ fieldName ] = $ message -> $ getter ( ) ; } } return $ data ; }
Form raw message data for sending to GCM
59,882
private function validatePayloadSize ( array $ rawData , $ fieldName , $ maxSize ) { if ( ! isset ( $ rawData [ $ fieldName ] ) ) { return ; } if ( strlen ( json_encode ( $ rawData [ $ fieldName ] ) ) > $ maxSize ) { throw new Exception ( ucfirst ( $ fieldName ) . " payload is to big (max {$maxSize} bytes)" , Exception :: MALFORMED_REQUEST ) ; } }
Validate size of json representation of passed payload
59,883
public function add ( array $ emails ) { if ( ! empty ( $ emails ) ) { foreach ( $ emails as $ key => $ values ) { $ this -> set ( $ key , $ values ) ; } } }
Adds new container the current container set .
59,884
public function get ( $ key , $ default = null , $ first = true ) { if ( ! is_string ( $ key ) && ! is_int ( $ key ) ) { throw new \ InvalidArgumentException ( '$key expected to be string or integer, got: ' . gettype ( $ key ) ) ; } if ( ! array_key_exists ( $ key , $ this -> container ) ) { if ( null === $ default ) { return $ first ? null : array ( ) ; } return $ first ? $ default : array ( $ default ) ; } if ( $ first ) { return count ( $ this -> container [ $ key ] ) ? $ this -> container [ $ key ] [ 0 ] : $ default ; } return $ this -> container [ $ key ] ; }
Returns a email value by name .
59,885
public function set ( $ key , $ values , $ replace = true ) { if ( ! is_string ( $ key ) && ! is_int ( $ key ) ) { throw new \ InvalidArgumentException ( '$key expected to be string, got:' . gettype ( $ key ) ) ; } if ( ! is_string ( $ values ) && ! is_array ( $ values ) ) { throw new \ InvalidArgumentException ( '$key expected to be string or array, got: ' . gettype ( $ key ) ) ; } $ values = array_values ( ( array ) $ values ) ; if ( true === $ replace || ! isset ( $ this -> container [ $ key ] ) ) { $ this -> container [ $ key ] = $ values ; } else { $ this -> container [ $ key ] = array_merge ( $ this -> container [ $ key ] , $ values ) ; } }
Sets a email values .
59,886
public function getEntries ( $ domain ) { $ hosts = array ( ) ; $ weight = array ( ) ; getmxrr ( $ domain , $ hosts , $ weight ) ; foreach ( $ hosts as $ k => $ host ) { $ this -> mxs [ $ host ] = $ weight [ $ k ] ; } asort ( $ this -> mxs ) ; $ this -> mxs [ $ domain ] = 0 ; return $ this -> mxs ; }
Queries the DNS server for domain MX entries
59,887
public function edit ( $ channelId , $ name = null , $ position = null , $ topic = null ) { $ channel = $ this -> show ( $ channelId ) ; $ json [ 'name' ] = is_null ( $ name ) ? $ channel [ 'name' ] : $ name ; $ json [ 'position' ] = is_null ( $ position ) ? $ channel [ 'position' ] : $ position ; $ json [ 'topic' ] = is_null ( $ topic ) ? $ channel [ 'topic' ] : $ topic ; return $ this -> request ( 'PATCH' , 'channels/' . $ channelId , [ 'json' => $ json ] ) ; }
Edit a channel .
59,888
public function handle ( Request $ request , Closure $ next , $ roles ) { $ accessDenied = true ; if ( ! $ user = $ this -> auth -> getActiveUser ( ) ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.access_denied' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; } if ( ! is_array ( $ roles ) ) { $ roles = [ $ roles ] ; } foreach ( $ roles as $ role ) { if ( ! $ role = $ this -> role -> getBySlug ( $ role ) ) { continue ; } if ( $ user -> inRole ( $ role ) ) { $ accessDenied = false ; } } if ( $ accessDenied ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.access_denied' ) ) ; return redirect ( ) -> back ( ) ; } return $ next ( $ request ) ; }
Check if user belongs to the specified role .
59,889
protected function databaseSetup ( ) { $ this -> output -> writeln ( <<<STEP<fg=yellow>*-----------------------------------------------*| || Configure Database || This package uses MySQL Only || |*-----------------------------------------------*</fg=yellow>STEP ) ; $ host = $ this -> anticipate ( 'Please enter the database host' , [ 'localhost' ] ) ; $ name = $ this -> anticipate ( 'Please enter the database name' , [ 'homestead' ] ) ; $ user = $ this -> anticipate ( 'Please enter the database user' , [ 'homestead' ] ) ; $ pass = $ this -> databaseSetupPassword ( ) ; $ headers = [ 'Setting' , 'Value' , ] ; $ data = [ [ 'Host' , $ host ] , [ 'Name' , $ name ] , [ 'User' , $ user ] , [ 'Password' , $ pass ] , ] ; $ this -> table ( $ headers , $ data ) ; if ( ! $ this -> confirm ( 'Is the database info correct?' ) ) { $ this -> databaseSetup ( ) ; } $ this -> database = [ 'host' => $ host , 'name' => $ name , 'user' => $ user , 'pass' => $ pass , ] ; $ this -> info ( 'Database configuration saved.' ) ; }
Setup the database credentials .
59,890
protected function databaseSetupPassword ( ) { $ pass = $ this -> secret ( 'Please enter the database password' ) ; $ passConfirm = $ this -> secret ( 'Please confirm the database password' ) ; if ( $ pass != $ passConfirm ) { $ this -> error ( '[ERROR] Database passwords do not match. Please retry.' ) ; $ this -> databaseSetupPassword ( ) ; } return $ pass ; }
Setup the database credentials password .
59,891
protected function userSetup ( ) { $ this -> output -> writeln ( <<<STEP<fg=yellow>*-----------------------------------------------*| || Configure Default User || |*-----------------------------------------------*</fg=yellow>STEP ) ; $ first = $ this -> ask ( 'Please enter the user first name' ) ; $ last = $ this -> ask ( 'Please enter the user last name' ) ; $ email = $ this -> ask ( 'Please enter the user email' ) ; $ pass = $ this -> userSetupPassword ( ) ; $ headers = [ 'Setting' , 'Value' ] ; $ data = [ [ 'First Name' , $ first ] , [ 'Last Name' , $ last ] , [ 'Email' , $ email ] , [ 'Password' , $ pass ] , ] ; $ this -> table ( $ headers , $ data ) ; if ( ! $ this -> confirm ( 'Is the user information correct?' ) ) { $ this -> userSetup ( ) ; } $ this -> user = [ 'first' => $ first , 'last' => $ last , 'email' => $ email , 'pass' => $ pass , ] ; $ this -> info ( 'User configuration saved.' ) ; }
Setup the user credentials .
59,892
protected function userSetupPassword ( ) { $ pass = $ this -> secret ( 'Please enter the user password' ) ; $ passConfirm = $ this -> secret ( 'Please confirm the user password' ) ; if ( $ pass != $ passConfirm ) { $ this -> error ( '[ERROR] Passwords do not match.' ) ; $ this -> userSetupPassword ( ) ; } return $ pass ; }
Setup the user credentials password .
59,893
protected function setupEnvFile ( ) { $ env = __DIR__ . '/stubs/env.stub' ; $ config = $ this -> database ; $ contents = str_replace ( array_map ( function ( $ key ) { return '{{' . $ key . '}}' ; } , array_keys ( $ config ) ) , array_values ( $ config ) , $ this -> laravel [ 'files' ] -> get ( $ env ) ) ; $ contents = str_replace ( '{{key}}' , Str :: random ( 32 ) , $ contents ) ; if ( $ this -> laravel [ 'files' ] -> put ( ( $ envFile = $ this -> laravel [ 'path.base' ] . '/.env' ) , $ contents ) === false ) { throw new \ RuntimeException ( "Could not write env file to [$envFile]." ) ; } $ this -> laravel [ 'Illuminate\Foundation\Bootstrap\DetectEnvironment' ] -> bootstrap ( $ this -> laravel ) ; $ this -> laravel [ 'Illuminate\Foundation\Bootstrap\LoadConfiguration' ] -> bootstrap ( $ this -> laravel ) ; }
Setup ENV file with database credentials .
59,894
protected function createDefaultUser ( ) { $ config = $ this -> user ; $ this -> permissionRepository -> create ( [ 'name' => 'Administrator (Full Access)' , 'slug' => 'admin' , ] , false ) ; $ this -> roleRepository -> create ( [ 'name' => 'Registered' , 'slug' => 'registered' , ] , false ) ; $ role = $ this -> roleRepository -> create ( [ 'name' => 'Administrator' , 'slug' => 'administrator' , 'permissions' => [ 'admin' => true , ] , ] , false ) ; $ user = $ this -> authRepository -> registerAndActivate ( [ 'email' => array_get ( $ config , 'email' ) , 'first_name' => array_get ( $ config , 'first' ) , 'last_name' => array_get ( $ config , 'last' ) , 'password' => array_get ( $ config , 'pass' ) , 'role' => 'administrator' , ] , false ) ; $ role -> users ( ) -> attach ( $ user ) ; }
Create default Group and User
59,895
protected function setupSeedStubs ( ) { $ config = $ this -> user ; $ user = __DIR__ . '/stubs/UserTableSeeder.stub' ; $ role = __DIR__ . '/stubs/RoleTableSeeder.stub' ; $ permission = __DIR__ . '/stubs/PermissionTableSeeder.stub' ; $ userContents = str_replace ( array_map ( function ( $ key ) { return '{{' . $ key . '}}' ; } , array_keys ( $ config ) ) , array_values ( $ config ) , $ this -> laravel [ 'files' ] -> get ( $ user ) ) ; $ roleContents = $ this -> laravel [ 'files' ] -> get ( $ role ) ; $ permissionContents = $ this -> laravel [ 'files' ] -> get ( $ permission ) ; if ( $ this -> laravel [ 'files' ] -> put ( ( $ userFile = $ this -> laravel [ 'path.database' ] . '/seeds/UserTableSeeder.php' ) , $ userContents ) === false ) { throw new \ RuntimeException ( "Could not write env file to [$userFile]." ) ; } if ( $ this -> laravel [ 'files' ] -> put ( ( $ roleFile = $ this -> laravel [ 'path.database' ] . '/seeds/RoleTableSeeder.php' ) , $ roleContents ) === false ) { throw new \ RuntimeException ( "Could not write env file to [$roleFile]." ) ; } if ( $ this -> laravel [ 'files' ] -> put ( ( $ permissionFile = $ this -> laravel [ 'path.database' ] . '/seeds/PermissionTableSeeder.php' ) , $ permissionContents ) === false ) { throw new \ RuntimeException ( "Could not write env file to [$permissionFile]." ) ; } }
Setup stub files for seeders .
59,896
public static function fromHeader ( string $ string ) { $ parts = \ array_map ( "trim" , \ explode ( ";" , $ string ) ) ; $ nameValue = \ explode ( "=" , \ array_shift ( $ parts ) , 2 ) ; if ( \ count ( $ nameValue ) !== 2 ) { return null ; } list ( $ name , $ value ) = $ nameValue ; $ name = \ trim ( $ name ) ; $ value = \ trim ( $ value , " \t\n\r\0\x0B\"" ) ; if ( $ name === "" ) { return null ; } $ meta = CookieAttributes :: empty ( ) ; foreach ( $ parts as $ part ) { $ pieces = \ array_map ( 'trim' , \ explode ( '=' , $ part , 2 ) ) ; $ key = \ strtolower ( $ pieces [ 0 ] ) ; if ( 1 === \ count ( $ pieces ) ) { switch ( $ key ) { case 'secure' : $ meta = $ meta -> withSecure ( ) ; break ; case 'httponly' : $ meta = $ meta -> withHttpOnly ( ) ; break ; } } else { switch ( $ key ) { case 'expires' : $ time = \ DateTime :: createFromFormat ( 'D, j M Y G:i:s T' , $ pieces [ 1 ] ) ; if ( $ time === false ) { break ; } $ meta = $ meta -> withExpiry ( $ time ) ; break ; case 'max-age' : $ maxAge = \ trim ( $ pieces [ 1 ] ) ; if ( ! \ is_numeric ( $ maxAge ) ) { break ; } $ meta = $ meta -> withMaxAge ( $ maxAge ) ; break ; case 'path' : $ meta = $ meta -> withPath ( $ pieces [ 1 ] ) ; break ; case 'domain' : $ meta = $ meta -> withDomain ( $ pieces [ 1 ] ) ; break ; } } } try { return new self ( $ name , $ value , $ meta ) ; } catch ( InvalidCookieException $ e ) { return null ; } }
Parses a cookie from a set - cookie header .
59,897
public function all ( ) { $ params = [ ] ; foreach ( $ this -> methodRequirements as $ key => $ config ) { $ params [ $ key ] = $ this -> get ( $ key ) ; } return $ params ; }
Fetches all required parameters from the current Request body .
59,898
public function get ( $ name ) { if ( ! $ paramConfig = $ this -> methodRequirements [ $ name ] ) { return ; } $ config = new Credential ( $ name , $ paramConfig ) ; if ( true === $ config -> required && ! ( $ this -> getRequest ( ) -> request -> has ( $ name ) ) ) { throw new BadRequestUserException ( $ this -> formatError ( $ name , false , 'The parameter must be set' ) ) ; } $ param = $ this -> getRequest ( ) -> request -> get ( $ name ) ; if ( false === $ config -> nullable && ! $ param ) { throw new BadRequestUserException ( $ this -> formatError ( $ name , $ param , 'The parameter cannot be null' ) ) ; } if ( ( $ config -> default && $ param === $ config -> default || ( $ param === null && true === $ config -> nullable ) || ( null === $ config -> requirements ) ) ) { return $ param ; } $ this -> validateParam ( $ config , $ param ) ; return $ param ; }
Fetches a given parameter from the current Request body .
59,899
private function validateParam ( Credential $ config , $ param ) { $ name = $ config -> name ; if ( null === $ requirements = $ config -> requirements ) { return ; } foreach ( $ requirements as $ constraint ) { if ( is_scalar ( $ constraint ) ) { $ constraint = new Regex ( [ 'pattern' => '#^' . $ constraint . '$#xsu' , 'message' => sprintf ( 'Does not match "%s"' , $ constraint ) , ] ) ; } elseif ( is_array ( $ constraint ) ) { continue ; } if ( $ constraint instanceof UniqueEntity ) { $ object = $ config -> class ; $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; if ( $ accessor -> isWritable ( $ object , $ name ) ) { $ accessor -> setValue ( $ object , $ name , $ param ) ; } else { throw new BadRequestUserException ( sprintf ( 'The @UniqueEntity constraint must be used on an existing property. The class "%s" does not have a property "%s"' , get_class ( $ object ) , $ name ) ) ; } $ errors = $ this -> validator -> validate ( $ object , $ constraint ) ; } else { $ errors = $ this -> validator -> validate ( $ param , $ constraint ) ; } if ( 0 !== count ( $ errors ) ) { $ error = $ errors [ 0 ] ; throw new BadRequestUserException ( $ this -> formatError ( $ name , $ error -> getInvalidValue ( ) , $ error -> getMessage ( ) ) ) ; } } }
Handle requirements validation .