idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
34,700 | protected function fixSlug ( $ slug ) { $ parts = explode ( '/' , $ slug ) ; $ slug = '' ; foreach ( $ parts as $ part ) { if ( $ part ) { $ slug .= '/' . str_slug ( $ part ) ; } } return strtolower ( '/' . ltrim ( $ slug , '/' ) ) ; } | Fixes slashes used in slug . |
34,701 | public function generateSlug ( $ title , $ useParent = true ) { $ slug = $ useParent ? $ this -> fixSlug ( $ this -> fixSlug ( $ this -> getAttribute ( 'slug' ) ) . $ this -> fixSlug ( $ title ) ) : $ this -> fixSlug ( $ title ) ; if ( $ this -> getExistingSlug ( $ slug , ! $ useParent ) ) { $ slug = $ this -> incrementLatestSlug ( $ slug ) ; } return $ slug ; } | Takes a parent tree item and generates a slug based off it . |
34,702 | protected function getExistingSlug ( $ slug , $ excludeSelf = false ) { $ existing = static :: where ( 'slug' , "$slug" ) ; if ( isset ( $ this -> isSlugToggled ) && $ this -> isSlugToggled == true ) { $ existing -> where ( 'is_sluggable' , true ) ; } if ( $ excludeSelf ) { $ existing -> where ( 'id' , '!=' , $ this -> id ) ; } return $ existing -> first ( ) ? true : false ; } | Checks where slug is currently being used . |
34,703 | protected function form ( ) { $ form = app ( 'antares.form' ) -> of ( "antares.widgets: report" ) -> extend ( function ( FormGrid $ form ) { $ url = handles ( 'antares::logger/report' , [ 'csrf' => true ] ) ; $ form -> name ( 'Report form' ) ; $ form -> simple ( $ url , [ 'id' => 'report-form' ] ) ; $ form -> layout ( 'antares/logger::admin.report.form' ) ; $ form -> fieldset ( trans ( 'Error Page Report' ) , function ( Fieldset $ fieldset ) { $ location = Input :: get ( 'location' ) ; $ fieldset -> control ( 'input:hidden' , 'url' ) -> value ( $ location ) ; $ fieldset -> control ( 'textarea' , 'description' ) -> label ( trans ( 'Additional message: ' ) ) -> attributes ( [ 'required' => 'required' ] ) ; $ control = $ fieldset -> control ( 'input:checkbox' , 'always_send' ) -> label ( trans ( 'Always send notification as default action in error page' ) ) ; if ( ( int ) memory ( 'notification.send.always' ) ) { $ control -> checked ( ) ; } } ) ; $ form -> ajaxable ( ) ; $ form -> rules ( [ 'description' => [ 'required' , 'max:4000' , 'min:1' ] ] ) ; } ) ; return $ form ; } | create form instance of exception handler |
34,704 | public static function getCurrentPage ( $ url = '' ) { if ( static :: $ currentPage !== false ) { return static :: $ currentPage ; } $ model = static :: find ( ) -> where ( [ 'url' => preg_replace ( '/[\/]{2,}/' , '/' , '/' . $ url . '/' ) , 'visible' => static :: VISIBLE_YES ] ) -> orderBy ( 'id DESC' ) -> one ( ) ; if ( ! $ model ) { return static :: $ currentPage = null ; } if ( $ model -> layout ) { Yii :: $ app -> controller -> layout = $ model -> layout ; } Yii :: $ app -> view -> title = $ model -> page_title ; Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'description' , 'content' => $ model -> page_description ] ) ; Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'keywords' , 'content' => $ model -> page_keywords ] ) ; return static :: $ currentPage = $ model ; } | Gets a page by the url . |
34,705 | public function prepareLabels ( ) { $ this [ Argument :: LABELS ] = $ this -> doReplacements ( $ this [ Argument :: LABELS ] ) ; return $ this ; } | Prepare the labels to be passed into the custom taxonomy registration . |
34,706 | public function offsetSet ( $ key , $ value ) { if ( ! is_scalar ( $ key ) ) { throw new InvalidArgumentException ( "Key must be either a string or an integer, " . gettype ( $ key ) . " given." ) ; } $ this -> $ key = $ value ; } | Replaces or appends a item . |
34,707 | protected function getAcceptHeader ( Request $ request ) : Accept { $ headerName = 'Accept' ; $ headerLine = '*/*' ; if ( $ request -> hasHeader ( $ headerName ) ) { $ headerLine = $ request -> getHeaderLine ( $ headerName ) ; } try { return Accept :: fromString ( $ headerName . ': ' . $ headerLine ) ; } catch ( \ Exception $ e ) { throw new Exception \ BadRequest ( 'Invalid Accept header' , $ e ) ; } } | Makes Accept header object from PSR - 7 request |
34,708 | protected function getContentTypeHeader ( Request $ request ) : ContentType { $ headerName = 'Content-Type' ; if ( ! $ request -> hasHeader ( $ headerName ) ) { throw new Exception \ BadRequest ( 'Content-Type header should be declared' ) ; } if ( count ( $ request -> getHeader ( $ headerName ) ) > 1 ) { throw new Exception \ BadRequest ( 'Multiple Content-Type headers are not allowed' ) ; } try { return ContentType :: fromString ( $ headerName . ': ' . $ request -> getHeaderLine ( $ headerName ) ) ; } catch ( \ Exception $ e ) { throw new Exception \ BadRequest ( 'Invalid Content-Type header' , $ e ) ; } } | Makes ContentType header object from PSR - 7 request |
34,709 | protected function populateResponseWithData ( $ data , Response $ response , ? Producer \ ProducerInterface $ producer ) : Response { if ( $ producer !== null ) { $ stream = $ producer -> assemble ( $ data ) ; if ( $ stream instanceof StreamInterface ) { $ response = $ response -> withBody ( $ stream ) ; } if ( $ producer instanceof Producer \ HeaderInterface ) { foreach ( $ producer -> assembleHeaders ( $ data ) as $ name => $ value ) { $ response = $ response -> withHeader ( $ name , $ value ) ; } } } return $ response ; } | Populates response with data using producer |
34,710 | protected function populateResponseWithException ( Exception \ HttpCode $ exception , Response $ response , ? Producer \ ProducerInterface $ producer ) : Response { $ response = $ this -> populateResponseWithData ( $ exception -> getPayload ( ) , $ response , $ producer ) ; if ( $ exception instanceof Exception \ HeaderInterface ) { foreach ( $ exception -> getHeaders ( ) as $ name => $ value ) { $ response = $ response -> withHeader ( $ name , $ value ) ; } } $ response = $ response -> withStatus ( $ exception -> getCode ( ) , $ exception -> getMessage ( ) ) ; return $ response ; } | Populates response with data from exception using producer |
34,711 | protected function setResponseStaticInstances ( ) { NodesHttpResponse :: setFormatters ( prepare_config_instances ( config ( 'nodes.api.response.formats' ) ) ) ; NodesHttpResponse :: setTransformer ( $ this -> app [ 'api.transformer' ] ) ; NodesHttpResponse :: setEventDispatcher ( $ this -> app [ 'events' ] ) ; } | Set response static instances . |
34,712 | protected function registerAuth ( ) { $ this -> app -> singleton ( 'api.auth' , function ( $ app ) { return new NodesAuth ( $ app [ 'api.router' ] , $ app , prepare_config_instances ( config ( 'nodes.api.auth.providers' ) ) ) ; } ) ; } | Register the authenticator . |
34,713 | public function getFields ( $ offset = 0 , $ limit = 100 ) { $ fields = [ ] ; foreach ( $ this -> client -> get ( "fields?offset={$offset}&limit={$limit}" ) as $ field ) { $ fields [ ] = new Resources \ Field ( $ this , $ field ) ; } return $ fields ; } | Get all fields that can be accessed using the credentials used . |
34,714 | public function getLists ( $ offset = 0 , $ limit = 100 ) { $ lists = [ ] ; foreach ( $ this -> client -> get ( "lists?offset={$offset}&limit={$limit}" ) as $ list ) { $ lists [ ] = new Resources \ MailingList ( $ this , $ list ) ; } return $ lists ; } | Get all Lists that can be accessed using the credentials used . |
34,715 | public function getList ( $ list ) { $ result = $ this -> client -> get ( "lists/{$list}" ) ; return $ result ? new Resources \ MailingList ( $ this , $ result ) : null ; } | Get a specific list . |
34,716 | public function getListFields ( $ list , $ offset = 0 , $ limit = 100 ) { $ fields = [ ] ; foreach ( $ this -> client -> get ( "lists/{$list}/fields?offset={$offset}&limit={$limit}" ) as $ field ) { $ fields [ ] = new Resources \ ListField ( $ this , $ field ) ; } return $ fields ; } | Get all fields that are associated with a list . |
34,717 | public function getListField ( $ list , $ field ) { $ result = $ this -> client -> get ( "lists/{$list}/fields/{$field}" ) ; return $ result ? new Resources \ ListField ( $ this , $ result ) : null ; } | Get a specific field for a list . |
34,718 | public function upload ( Request $ request ) { $ interventionConfig = json_decode ( $ request -> input ( 'intervention' ) , true ) ; $ appendedPath = $ request -> input ( 'uploadSubDir' ) ; $ uploadResponse = ( new Uploader ) -> fancyUpload ( $ request , $ interventionConfig ? : [ ] , $ appendedPath ) ; return response ( ) -> json ( $ uploadResponse ) ; } | pass a file object from request |
34,719 | public function register ( WsdlManager $ wsdlManager ) { $ wsdlManager -> addWebServiceListener ( WebService :: EVENT_SUCCESS , [ $ this , 'logEvent' ] ) ; $ wsdlManager -> addWebServiceListener ( WebService :: EVENT_FAILURE , [ $ this , 'logEvent' ] ) ; Tracy \ Debugger :: getBar ( ) -> addPanel ( $ this ) ; } | Registers event listener on WebService objects via WsdlManager |
34,720 | public function getChecks ( ) { $ client = new \ Guzzle \ Service \ Client ( 'https://api.pingdom.com/api/2.0' ) ; $ request = $ client -> get ( 'checks' , array ( 'App-Key' => $ this -> token ) ) ; $ request -> setAuth ( $ this -> username , $ this -> password ) ; $ response = $ request -> send ( ) ; $ response = json_decode ( $ response -> getBody ( ) , true ) ; return $ response [ 'checks' ] ; } | Returns a list overview of all checks |
34,721 | public function getProbes ( ) { $ client = new \ Guzzle \ Service \ Client ( 'https://api.pingdom.com/api/2.0' ) ; $ request = $ client -> get ( 'probes' , array ( 'App-Key' => $ this -> token ) ) ; $ request -> setAuth ( $ this -> username , $ this -> password ) ; $ response = $ request -> send ( ) ; $ response = json_decode ( $ response -> getBody ( ) , true ) ; $ probes = array ( ) ; foreach ( $ response [ 'probes' ] as $ attributes ) { $ probes [ ] = new Probe \ Server ( $ attributes ) ; } return $ probes ; } | Returns a list of all Pingdom probe servers |
34,722 | public function getResults ( $ checkId , $ limit = 100 , array $ probes = null ) { $ client = new \ Guzzle \ Service \ Client ( 'https://api.pingdom.com/api/2.0' ) ; $ request = $ client -> get ( 'results/' . $ checkId , array ( 'App-Key' => $ this -> token ) ) ; $ request -> setAuth ( $ this -> username , $ this -> password ) ; $ request -> getQuery ( ) -> set ( 'limit' , $ limit ) ; if ( is_array ( $ probes ) ) { $ request -> getQuery ( ) -> set ( 'probes' , implode ( ',' , $ probes ) ) ; } $ response = $ request -> send ( ) ; $ response = json_decode ( $ response -> getBody ( ) , true ) ; return $ response [ 'results' ] ; } | Return a list of raw test results for a specified check |
34,723 | public function getPerformanceSummary ( $ checkId , $ resolution = 'hour' ) { $ client = new \ Guzzle \ Service \ Client ( 'https://api.pingdom.com/api/2.0' ) ; $ request = $ client -> get ( 'summary.performance/' . $ checkId , array ( 'App-Key' => $ this -> token ) ) ; $ request -> setAuth ( $ this -> username , $ this -> password ) ; $ request -> getQuery ( ) -> set ( 'resolution' , $ resolution ) ; $ request -> getQuery ( ) -> set ( 'includeuptime' , 'true' ) ; $ response = $ request -> send ( ) ; $ response = json_decode ( $ response -> getBody ( ) , true ) ; return $ response [ 'summary' ] [ $ resolution . 's' ] ; } | Get Intervals of Average Response Time and Uptime During a Given Interval |
34,724 | protected function doTransform ( Matrix $ mA , $ extra = null ) { $ this -> assertMatrixIsComplete ( $ mA ) ; if ( $ mA -> is ( 'empty' ) || $ mA -> is ( 'singleitem' ) || $ mA -> is ( 'columnvector' ) ) { return clone $ mA ; } $ numShifts = ( is_null ( $ extra ) ? 1 : intval ( $ extra ) ) ; if ( 0 == $ numShifts ) { return clone $ mA ; } $ direction = ( $ numShifts < 0 ? - 1 : 1 ) ; $ nCols = $ mA -> columns ( ) ; $ fSlice = new Colslice ( ) ; $ fConc = new Concatenate ( ) ; $ fReflect = new Reflect ( ) ; $ ret = ( $ direction == 1 ? clone $ mA : $ fReflect ( $ mA , Reflect :: REFL_Y ) ) ; for ( $ x = abs ( $ numShifts ) ; $ x -- ; $ x == 0 ) { $ ret = $ fConc ( $ fSlice ( $ ret , [ $ nCols , 1 ] ) , $ fSlice ( $ ret , [ 1 , $ nCols - 1 ] ) ) ; } return ( $ direction == 1 ? $ ret : $ fReflect ( $ ret , Reflect :: REFL_Y ) ) ; } | Shift matrix rows columns left or right circularly around the matrix |
34,725 | protected function injectAlert ( Response $ response ) { $ content = $ response -> getContent ( ) ; $ pos = strripos ( $ content , '<body>' ) ; if ( false !== $ pos ) { $ renderedContent = soda_cms_view ( 'partials.draft-alert' ) -> render ( ) ; $ content = substr ( $ content , 0 , $ pos ) . $ renderedContent . substr ( $ content , $ pos ) ; $ response -> setContent ( $ content ) ; $ response -> headers -> remove ( 'Content-Length' ) ; } } | Injects the alertbar into the given Response . |
34,726 | protected function parseVisibility ( ) { if ( $ this -> hidden === true ) { Html :: addCssClass ( $ this -> filterOptions , 'kv-grid-hide' ) ; Html :: addCssClass ( $ this -> headerOptions , 'kv-grid-hide' ) ; Html :: addCssClass ( $ this -> contentOptions , 'kv-grid-hide' ) ; Html :: addCssClass ( $ this -> footerOptions , 'kv-grid-hide' ) ; Html :: addCssClass ( $ this -> pageSummaryOptions , 'kv-grid-hide' ) ; } if ( $ this -> hiddenFromExport === true ) { Html :: addCssClass ( $ this -> filterOptions , 'skip-export' ) ; Html :: addCssClass ( $ this -> headerOptions , 'skip-export' ) ; Html :: addCssClass ( $ this -> contentOptions , 'skip-export' ) ; Html :: addCssClass ( $ this -> footerOptions , 'skip-export' ) ; Html :: addCssClass ( $ this -> pageSummaryOptions , 'skip-export' ) ; Html :: addCssClass ( $ this -> options , 'skip-export' ) ; } if ( is_array ( $ this -> hiddenFromExport ) && ! empty ( $ this -> hiddenFromExport ) ) { $ tag = 'skip-export-' ; $ css = $ tag . implode ( " {$tag}" , $ this -> hiddenFromExport ) ; Html :: addCssClass ( $ this -> filterOptions , $ css ) ; Html :: addCssClass ( $ this -> headerOptions , $ css ) ; Html :: addCssClass ( $ this -> contentOptions , $ css ) ; Html :: addCssClass ( $ this -> footerOptions , $ css ) ; Html :: addCssClass ( $ this -> pageSummaryOptions , $ css ) ; Html :: addCssClass ( $ this -> options , $ css ) ; } } | Checks hidden property and hides the column from display |
34,727 | public function saved ( ContentInterface $ content ) { if ( $ content -> content_type_id !== null ) { if ( ! $ content -> relationLoaded ( 'type' ) ) { $ content -> load ( 'type' ) ; } $ contentType = $ content -> getRelation ( 'type' ) ; if ( $ contentType && $ contentType -> shouldDynamicTableExist ( ) && ! $ contentType -> dynamicTableExists ( ) ) { $ contentType -> createTable ( ) ; } } } | Listen to the Page saved event . |
34,728 | public static function bootDraftable ( ) { if ( isset ( static :: $ publishDateField ) ) static :: setPublishDateField ( static :: $ publishDateField ) ; static :: addGlobalScope ( 'published' , function ( Builder $ builder ) { if ( static :: isDraftsEnabled ( ) ) { $ builder -> where ( 'status' , '=' , Constants :: STATUS_LIVE ) ; if ( static :: publishDateFieldEnabled ( ) ) { $ builder -> where ( function ( $ subQuery ) { $ subQuery -> whereNull ( static :: $ _publishDateField ) -> orWhere ( static :: $ _publishDateField , '<' , static :: getConvertedNow ( ) ) ; } ) ; } } return $ builder ; } ) ; } | Automatically filters model to only show live items . |
34,729 | public function bind ( $ properties , $ updateNulls = true ) { if ( ! \ is_array ( $ properties ) && ! \ is_object ( $ properties ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s(%s)' , __METHOD__ , \ gettype ( $ properties ) ) ) ; } if ( $ properties instanceof \ Traversable ) { $ properties = iterator_to_array ( $ properties ) ; } elseif ( \ is_object ( $ properties ) ) { $ properties = ( array ) $ properties ; } foreach ( $ properties as $ property => $ value ) { if ( $ value === null && ! $ updateNulls ) { continue ; } $ this -> setProperty ( $ property , $ value ) ; } return $ this ; } | Binds an array or object to this object . |
34,730 | protected function dumpProperty ( $ property , $ depth , \ SplObjectStorage $ dumped ) { $ value = $ this -> getProperty ( $ property ) ; if ( $ depth > 0 ) { if ( $ value instanceof DumpableInterface ) { if ( ! $ dumped -> contains ( $ value ) ) { $ value = $ value -> dump ( $ depth - 1 , $ dumped ) ; } } if ( $ value instanceof \ DateTime ) { $ value = $ value -> format ( 'Y-m-d H:i:s' ) ; } elseif ( $ value instanceof Registry ) { $ value = $ value -> toObject ( ) ; } } return $ value ; } | Dumps a data property . |
34,731 | protected function setProperty ( $ property , $ value ) { if ( strpos ( $ property , "\0" ) === 0 ) { return ; } $ this -> properties [ $ property ] = $ value ; return $ value ; } | Sets a data property . |
34,732 | protected function generateMasterToken ( ) { return [ hash ( 'sha256' , $ this -> tokenSalt . '+' . config ( 'app.key' ) . '+' . Carbon :: now ( ) -> toDateString ( ) ) , hash ( 'sha256' , $ this -> tokenSalt . '+' . config ( 'app.key' ) . '+' . Carbon :: now ( ) -> addDay ( ) -> toDateString ( ) ) , hash ( 'sha256' , $ this -> tokenSalt . '+' . config ( 'app.key' ) . '+' . Carbon :: now ( ) -> subDay ( ) -> toDateString ( ) ) , ] ; } | Generate master token . |
34,733 | protected function getTokenColumn ( $ column ) { if ( ! array_key_exists ( $ column , $ this -> tokenColumns ) ) { throw new BadRequestHttpException ; } return $ this -> tokenColumns [ $ column ] ; } | Retrieve token columns . |
34,734 | public function display ( array $ options = array ( ) ) { if ( empty ( $ this -> formatter ) ) { throw new FormatterNotSetException ( ) ; } return $ this -> formatter -> format ( $ this , $ options ) ; } | Return the matrix in some displayable format |
34,735 | protected function enforceCompleteness ( ) { if ( $ this -> is ( 'empty' ) ) { return ; } $ numcols = count ( $ this -> data [ 0 ] ) ; array_walk ( $ this -> data , function ( $ value , $ index , $ matchCols ) { if ( count ( $ value ) != $ matchCols ) { throw new NotCompleteMatrixException ( $ index ) ; } } , $ numcols ) ; } | Test for matrix completeness |
34,736 | protected function normalize ( $ default ) { if ( $ this -> is ( 'empty' ) ) { return ; } $ maxCols = array_reduce ( $ this -> data , function ( $ carry , $ item ) { $ l = count ( $ item ) ; return ( $ l > $ carry ? $ l : $ carry ) ; } , 0 ) ; array_walk ( $ this -> data , function ( & $ row ) use ( $ maxCols , $ default ) { if ( ( $ len = count ( $ row ) ) < $ maxCols ) { $ row += array_fill ( $ len , $ maxCols - $ len , $ default ) ; } } ) ; } | Normalize matrix to have same number of columns for each row Missing vertices are set with default value |
34,737 | protected function checkEntryEquality ( Matrix $ mB , $ strict ) { $ dA = $ this -> toArray ( ) ; $ dB = $ mB -> toArray ( ) ; $ m = $ this -> rows ( ) ; $ n = $ this -> columns ( ) ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( $ strict ) { if ( $ dA [ $ i ] [ $ j ] !== $ dB [ $ i ] [ $ j ] ) { return false ; } } else { if ( $ dA [ $ i ] [ $ j ] != $ dB [ $ i ] [ $ j ] ) { return false ; } } } } return true ; } | Check equality of each matrix entry Overide in child class if required |
34,738 | protected function registerBindings ( ) { $ this -> app -> bind ( 'FluxBB\Models\GroupRepositoryInterface' , function ( $ app ) { return new GroupRepository ( $ app [ 'cache' ] ) ; } ) ; $ this -> app -> bind ( 'FluxBB\Models\ConfigRepositoryInterface' , function ( $ app ) { return new ConfigRepository ( $ app [ 'cache.store' ] , $ app [ 'Illuminate\Database\ConnectionInterface' ] ) ; } ) ; $ this -> app -> bind ( 'FluxBB\Models\CategoryRepositoryInterface' , function ( $ app ) { return new CategoryRepository ( $ app [ 'Illuminate\Database\ConnectionInterface' ] ) ; } ) ; $ this -> app -> bind ( 'FluxBB\Models\ConversationRepositoryInterface' , function ( $ app ) { return new ConversationRepository ( $ app [ 'Illuminate\Database\ConnectionInterface' ] ) ; } ) ; } | Register the IoC container bindings . |
34,739 | protected function registerViewComposers ( ) { $ this -> app -> extend ( 'view' , function ( Factory $ view ) { $ view -> composer ( 'fluxbb::layout.main' , 'FluxBB\View\AlertsComposer' ) ; $ view -> composer ( 'fluxbb::layout.main' , 'FluxBB\View\GlobalsComposer' ) ; $ view -> composer ( 'fluxbb::admin.layout.main' , 'FluxBB\View\GlobalsComposer' ) ; return $ view ; } ) ; } | Register any view composers . |
34,740 | protected function registerViewNamespace ( ) { $ viewPath = __DIR__ . '/../../views' ; $ this -> loadViewsFrom ( $ viewPath , 'fluxbb' ) ; $ locale = $ this -> app [ 'config' ] [ 'app.locale' ] ; $ mailPath = __DIR__ . '/../../lang/' . $ locale . '/mail/' ; $ this -> loadViewsFrom ( $ mailPath , 'fluxbb:mail' ) ; } | Register a view namespace for the package . |
34,741 | public function create ( $ DatacenterID , $ Label , $ Size , $ LinodeID = null ) { return $ this -> call ( 'volume.create' , [ 'DatacenterID' => $ DatacenterID , 'Label' => $ Label , 'Size' => $ Size , 'LinodeID' => $ LinodeID , ] ) ; } | Creates a new Block Storage Volume . One of DatacenterID or LinodeID is required . |
34,742 | public function update ( $ VolumeID , $ Label = null , $ Size = null , $ LinodeID = null ) { return $ this -> call ( 'volume.update' , [ 'VolumeID' => $ VolumeID , 'Label' => $ Label , 'Size' => $ Size , 'LinodeID' => $ LinodeID , ] ) ; } | Updates a Volume s properties . |
34,743 | public function setRunnable ( $ _runnable ) { if ( self :: runnableOk ( $ _runnable ) ) { $ this -> runnable = $ _runnable ; } else { throw new Exception ( $ this -> getError ( Thread :: FUNCTION_NOT_CALLABLE ) , Thread :: FUNCTION_NOT_CALLABLE ) ; } } | sets the callback |
34,744 | public function start ( ) { $ pid = @ pcntl_fork ( ) ; if ( $ pid == - 1 ) { throw new Exception ( $ this -> getError ( Thread :: COULD_NOT_FORK ) , Thread :: COULD_NOT_FORK ) ; } if ( $ pid ) { $ this -> pid = $ pid ; } else { pcntl_signal ( SIGTERM , array ( $ this , 'signalHandler' ) ) ; $ arguments = func_get_args ( ) ; if ( ! empty ( $ arguments ) ) { call_user_func_array ( $ this -> runnable , $ arguments ) ; } else { call_user_func ( $ this -> runnable ) ; } exit ( 0 ) ; } } | starts the thread all the parameters are passed to the callback function |
34,745 | public function stop ( $ _signal = SIGKILL , $ _wait = false ) { if ( $ this -> isAlive ( ) ) { posix_kill ( $ this -> pid , $ _signal ) ; if ( $ _wait ) { pcntl_waitpid ( $ this -> pid , $ status = 0 ) ; } } } | attempts to stop the thread returns true on success and false otherwise |
34,746 | public function getError ( $ _code ) { if ( isset ( $ this -> errors [ $ _code ] ) ) { return $ this -> errors [ $ _code ] ; } else { return 'No such error code ' . $ _code . '! Quit inventing errors!!!' ; } } | gets the error s message based on its id |
34,747 | public static function makeFromExisting ( IlluminateResponse $ old ) { $ statusCode = ( $ old instanceof self ) ? $ old -> getStatusCodeAndMessage ( ) : $ old -> getStatusCode ( ) ; $ new = static :: create ( $ old -> getOriginalContent ( ) , $ statusCode ) ; $ new -> headers = $ old -> headers ; return $ new ; } | Make an API response from an existing response object . |
34,748 | public function authorize ( ) { $ response = new Response ( ) ; $ response = $ this -> oauthServer -> handleAuthorizeRequest ( Request :: createFromGlobals ( ) , $ response , true ) ; if ( ! $ response -> getParameters ( ) ) { $ code = substr ( $ response -> getHttpHeader ( 'Location' ) , strpos ( $ response -> getHttpHeader ( 'Location' ) , 'code=' ) + 5 , 40 ) ; return $ this -> response -> sendSuccess ( [ 'code' => $ code ] ) ; } else { return $ this -> response -> sendError ( ResponseCodes :: AUTH_ERROR , $ response -> getStatusCode ( ) , $ response -> getParameter ( 'error_description' ) ) ; } } | Get Authorization code |
34,749 | public function save ( ) { foreach ( $ this -> getChanged ( ) as $ relation ) { $ this -> sync ( $ relation , $ this -> values -> get ( $ relation ) , $ this -> delete ) ; } } | Sync the changed relationships |
34,750 | public static function values ( $ withEmpty = false ) { $ values = parent :: values ( $ withEmpty ) ; $ values [ static :: WORK ] = \ Yii :: t ( 'app' , $ values [ static :: WORK ] ) ; $ values [ static :: PERSONAL ] = \ Yii :: t ( 'app' , $ values [ static :: PERSONAL ] ) ; $ values [ static :: GOOGLEPLUS ] = 'GooglePlus' ; $ values [ static :: LINKEDIN ] = 'LinkedIn' ; return $ values ; } | Values of Urls |
34,751 | public function sendResetPasswordEmail ( array $ conditions ) { if ( empty ( $ conditions ) ) { throw new ResetPasswordNoUserException ( 'Conditions can\'t be empty' ) ; } foreach ( $ conditions as $ column => $ value ) { $ this -> authModel = $ this -> authModel -> where ( $ column , '=' , $ value ) ; } $ user = $ this -> authModel -> first ( ) ; if ( empty ( $ user ) ) { throw new ResetPasswordNoUserException ( 'Could not find any user with those credentials' ) ; } $ token = $ this -> generateResetPasswordToken ( $ user ) ; $ domain = env ( 'NODES_ENV' , false ) ? sprintf ( 'https://%s.%s' , env ( 'APP_NAME' ) , env ( 'APP_DOMAIN' ) ) : config ( 'app.url' ) ; Mail :: send ( [ 'html' => config ( 'nodes.api.reset-password.views.html' , 'nodes.api::reset-password.emails.html' ) , 'text' => config ( 'nodes.api.reset-password.views.text' , 'nodes.api::reset-password.emails.text' ) , ] , [ 'user' => $ user , 'domain' => $ domain , 'token' => $ token , 'expire' => config ( 'nodes.api.reset-password.expire' ) , 'senderName' => ( config ( 'nodes.api.reset-password.from.name' ) != 'Nodes' ) ? config ( 'nodes.api.reset-password.from.name' ) : config ( 'nodes.project.name' ) , ] , function ( $ message ) use ( $ user ) { $ message -> to ( $ user -> email ) -> from ( config ( 'nodes.api.reset-password.from.email' , 'no-reply@nodes.dk' ) , config ( 'nodes.api.reset-password.from.name' , 'Nodes' ) ) -> subject ( config ( 'nodes.api.reset-password.subject' , 'Reset password request' ) ) ; } ) ; } | Generate and send a email with reset password instructions . |
34,752 | public function generateResetPasswordToken ( IlluminateModel $ user ) { $ token = hash_hmac ( 'sha256' , str_random ( 40 ) , config ( 'app.key' ) ) ; $ expire = Carbon :: now ( ) -> addMinutes ( config ( 'nodes.api.reset-password.expire' , 60 ) ) ; $ resetToken = $ this -> where ( 'email' , '=' , $ user -> email ) -> first ( ) ; if ( ! empty ( $ resetToken ) ) { $ resetToken -> update ( [ 'token' => $ token , 'used' => 0 , 'expire_at' => $ expire -> format ( 'Y-m-d H:i:s' ) ] ) ; } else { $ this -> insert ( [ 'email' => $ user -> email , 'token' => $ token , 'expire_at' => $ expire -> format ( 'Y-m-d H:i:s' ) ] ) ; } return $ token ; } | Generate reset token . |
34,753 | public function updatePasswordByEmail ( $ email , $ password ) { $ user = $ this -> authModel -> where ( 'email' , '=' , $ email ) -> first ( ) ; if ( empty ( $ user ) ) { return false ; } $ user -> password = $ password ; return ( bool ) $ user -> update ( ) ; } | Update user s password by e - mail . |
34,754 | public function register ( ) { parent :: register ( ) ; $ this -> mergeConfigFrom ( __DIR__ . '/../resources/config/config.php' , 'antares/api::config' ) ; $ this -> app -> singleton ( PresenterFactory :: class , function ( $ app ) { $ config = config ( 'antares/api::config' , [ ] ) ; return new PresenterFactory ( $ app , $ config ) ; } ) ; $ this -> app -> singleton ( AuthProviderService :: class , function ( $ app ) { $ config = config ( 'antares/api::config.auth.drivers' , [ ] ) ; return new AuthProviderService ( $ app , $ app [ 'cache.store' ] , $ config ) ; } ) ; } | Registers service provider |
34,755 | public function boot ( ) { parent :: boot ( ) ; $ router = $ this -> app -> make ( Router :: class ) ; $ this -> app -> bind ( RouterAdapter :: class , function ( $ app ) { return new RouterAdapter ( $ app -> make ( ApiRouter :: class ) , $ app -> make ( ControllerFinder :: class ) , $ app [ 'config' ] [ 'api' ] ) ; } ) ; $ this -> app -> bind ( 'api-roles' , function ( ) { return new ApiRoles ( ) ; } ) ; if ( ! App :: runningInConsole ( ) ) { $ this -> registerApiAuth ( $ this -> app -> make ( AuthProviderService :: class ) ) ; } $ router -> pushMiddlewareToGroup ( 'api' , ApiMiddleware :: class ) ; $ this -> app -> make ( 'view' ) -> composer ( [ 'antares/api::admin.user.*' ] , AccountPlaceholder :: class ) ; $ this -> app -> make ( 'view' ) -> composer ( [ 'antares/foundation::account.*' , 'antares/logger::admin.devices.*' , 'antares/api::admin.user.*' ] , MenuUser :: class ) ; $ this -> app -> make ( 'view' ) -> composer ( 'antares/api::admin.configuration.*' , ControlPane :: class ) ; } | Boots service provider |
34,756 | public function getResponse ( $ id , $ filename = null , $ forceDownload = false ) { $ object = $ this -> container -> get ( $ id ) ; if ( $ filename === null ) { $ filename = $ object -> getBasename ( ) ; } if ( ! pathinfo ( $ filename , PATHINFO_EXTENSION ) && $ object -> getExtension ( ) ) { $ filename .= '.' . $ object -> getExtension ( ) ; } $ response = $ this -> controller -> getResponse ( ) ; $ response -> setContent ( new LazyResponse ( $ object ) ) ; $ response -> getHeaders ( ) -> addHeaders ( array ( 'Content-Type' => $ object -> getContentType ( ) ? : 'application/octet-stream' , 'Content-Disposition' => ( $ forceDownload ? 'attachment' : 'inline' ) . ';filename="' . str_replace ( '"' , '\\"' , $ filename ) . '"' , 'Content-Transfer-Encoding' => 'binary' , 'Expires' => '-1 year' , 'Cache-Control' => 'must-revalidate' , 'Pragma' => 'public' , 'Content-Length' => $ object -> getContentLength ( ) , ) ) ; return $ response ; } | Return a response object for a given file . |
34,757 | public function generateThumbnail ( $ id , $ width , $ height = null ) { if ( $ height === null ) { $ height = $ width ; } $ temp = $ this -> container -> download ( $ id ) ; $ img = new \ Imagick ( $ temp -> getPath ( ) ) ; $ img -> cropThumbnailImage ( $ width , $ height ) ; $ img -> writeImage ( ) ; return $ this -> container -> upload ( $ temp ) ; } | Generate a thumbnail from an object and return the ID of the new object . |
34,758 | protected function registerContentType ( $ contentType , ConfigInterface $ config ) { $ class = __NAMESPACE__ . '\\' . $ contentType ; if ( ! class_exists ( $ class ) ) { throw new InvalidContentTypeException ( $ contentType ) ; } ( new $ class ( $ config ) ) -> register ( ) ; } | Register a single content type . |
34,759 | private function loadConnections ( ContainerBuilder $ container , array $ config ) { $ factoryName = $ this -> addFactoryToContainer ( $ container ) ; $ genericDefinition = new Definition ( Publisher :: class ) ; $ genericDefinition -> setFactory ( [ new Reference ( $ factoryName ) , 'createPublisher' ] ) ; foreach ( $ config [ 'connections' ] as $ key => $ connection ) { $ protocol = $ connection [ 'protocol' ] ; $ host = $ connection [ 'host' ] ; $ port = $ connection [ 'port' ] ; $ path = $ connection [ 'path' ] ; $ auth_key = $ connection [ 'auth_key' ] ; $ auth_secret = $ connection [ 'auth_secret' ] ; $ hostname = $ connection [ 'hostname' ] ; $ ignoreSsl = $ connection [ 'ssl_ignore' ] ; if ( $ path [ 0 ] !== '/' ) { $ path = '/' . $ path ; } $ definition = clone $ genericDefinition ; $ definition -> setArguments ( [ $ protocol , $ host , $ port , $ path , $ auth_key , $ auth_secret , $ hostname , $ ignoreSsl ] ) ; $ definition -> setPublic ( true ) ; $ container -> setDefinition ( sprintf ( 'facile.crossbar.publisher.%s' , $ key ) , $ definition ) ; } } | Registers publisher services in container |
34,760 | protected function types ( ) { $ types = app ( LogTypes :: class ) -> select ( [ 'name' , 'id' ] ) -> get ( ) ; $ options = [ '' => trans ( 'antares/logger::messages.all' ) ] ; foreach ( $ types as $ type ) { array_set ( $ options , $ type -> name , ucfirst ( Str :: humanize ( $ type -> name ) ) ) ; } $ this -> resolveExtensionsUsingApi ( $ options ) ; return $ options ; } | Creates select for types |
34,761 | protected function resolveExtensionsUsingApi ( & $ options ) { $ extensions = extensions ( ) ; $ extensionFinder = app ( 'antares.extension.finder' ) ; foreach ( $ extensions as $ extension ) { $ path = $ extensionFinder -> resolveExtensionPath ( array_get ( $ extension , 'path' ) ) ; $ finder = new Finder ( ) ; $ count = $ finder -> directories ( ) -> in ( $ path . DIRECTORY_SEPARATOR . 'src' ) -> depth ( '> 2' ) -> name ( '/^Api/' ) -> count ( ) ; $ name = array_get ( $ extension , 'name' ) ; if ( ! $ count && array_key_exists ( $ name , $ options ) ) { unset ( $ options [ $ name ] ) ; } } return $ options ; } | Resolves extensions using api |
34,762 | public function registerAuth ( ) { $ this -> container -> make ( DingoAuth \ Auth :: class ) -> extend ( 'jwt' , function ( $ app ) { return new DingoAuth \ Provider \ JWT ( $ app [ \ Antares \ Modules \ Api \ Providers \ Auth \ JWT :: class ] ) ; } ) ; } | Extends the Auth by the provider . |
34,763 | private function updateIndexFile ( $ indexFile , $ summary ) { touch ( $ indexFile ) ; if ( ( $ fp = @ fopen ( $ indexFile , 'r+' ) ) === false ) { throw new InvalidConfigException ( "Unable to open debug data index file: $indexFile" ) ; } @ flock ( $ fp , LOCK_EX ) ; $ manifest = '' ; while ( ( $ buffer = fgets ( $ fp ) ) !== false ) { $ manifest .= $ buffer ; } if ( ! feof ( $ fp ) || empty ( $ manifest ) ) { $ manifest = [ ] ; } else { $ manifest = unserialize ( $ manifest ) ; } $ manifest [ $ this -> tag ] = $ summary ; $ this -> gc ( $ manifest ) ; ftruncate ( $ fp , 0 ) ; rewind ( $ fp ) ; fwrite ( $ fp , serialize ( $ manifest ) ) ; @ flock ( $ fp , LOCK_UN ) ; @ fclose ( $ fp ) ; if ( $ this -> module -> fileMode !== null ) { @ chmod ( $ indexFile , $ this -> module -> fileMode ) ; } } | Updates index file with summary log data |
34,764 | public static function mount ( $ className = null ) { if ( is_null ( $ className ) ) { $ class = get_called_class ( ) ; $ namespaces = explode ( '\\' , $ class ) ; $ staticName = end ( $ namespaces ) ; $ className = preg_replace ( '/^Static/' , '' , $ staticName ) ; } if ( class_exists ( $ className ) ) { return ; } class_alias ( $ class , $ className ) ; } | Mount this class as an alias . |
34,765 | public function index ( $ token , $ email ) { $ verificationToken = $ this -> emailVerificationRepository -> getByUnexpiredToken ( $ token ) ; if ( empty ( $ verificationToken ) ) { return view ( 'nodes.api::email-verification.invalid' ) ; } if ( $ verificationToken -> email != $ email ) { return view ( 'nodes.api::email-verification.invalid' ) ; } $ status = $ this -> emailVerificationRepository -> updateVerificationByEmail ( $ verificationToken -> email ) ; if ( empty ( $ status ) ) { return view ( 'nodes.api::email-verification.invalid' ) -> with ( [ 'email' => $ verificationToken -> email , 'error' => 'Couldn\'t verify the user. Please contact administrator' ] ) ; } $ verificationToken -> markAsUsed ( ) ; return view ( 'nodes.api::email-verification.done' ) -> with ( 'success' , 'User was successfully verified' ) ; } | Verify account by e - mail and token . |
34,766 | protected static function getProjectDir ( Event $ event ) : string { return $ event -> getComposer ( ) -> getConfig ( ) -> get ( 'vendor-dir' ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR ; } | Get current directory . |
34,767 | public static function preHooks ( Event $ event ) : bool { $ directory = self :: getProjectDir ( $ event ) ; $ io = $ event -> getIO ( ) ; $ removed = false ; foreach ( self :: $ hooks as $ hookName ) { $ hook = sprintf ( '%1$s.git%3$shooks%3$s%2$s' , $ directory , $ hookName , DIRECTORY_SEPARATOR ) ; if ( file_exists ( $ hook ) ) { unlink ( $ hook ) ; $ removed = true ; } } if ( $ removed ) { $ io -> write ( '<info>Hooks removed!</info>' ) ; } return true ; } | Pre hooks . |
34,768 | public static function postHooks ( Event $ event ) : bool { $ directory = self :: getProjectDir ( $ event ) ; if ( ! file_exists ( $ directory . '.git' ) ) { throw new Exception ( sprintf ( 'Oops! Local Git repository not found.' ) ) ; } $ io = $ event -> getIO ( ) ; foreach ( self :: $ hooks as $ hookName ) { $ hook = sprintf ( '%1$s.git%3$shooks%3$s%2$s' , $ directory , $ hookName , DIRECTORY_SEPARATOR ) ; $ original = sprintf ( '%1$s%3$s..%3$shooks%3$s%2$s' , __DIR__ , $ hookName , DIRECTORY_SEPARATOR ) ; copy ( $ original , $ hook ) ; chmod ( $ hook , 0777 ) ; } $ io -> write ( '<info>Hooks added!</info>' ) ; return true ; } | Post hooks . |
34,769 | public static function parse ( $ raw ) { self :: $ parsed = [ ] ; list ( $ headings , $ data ) = self :: parseRawData ( $ raw ) ; if ( ! is_array ( $ headings ) ) { return self :: $ parsed ; } foreach ( $ headings as $ heading ) { for ( $ i = 0 , $ j = count ( $ heading ) ; $ i < $ j ; $ i ++ ) { self :: populateEntries ( $ heading , $ data , $ i ) ; } } ; unset ( $ headings , $ data ) ; return array_reverse ( self :: $ parsed ) ; } | Parse file content . |
34,770 | protected function getFilepath ( $ id , $ pathPrefix = null ) { if ( $ pathPrefix === null ) { $ pathPrefix = $ this -> uploadPath ; } else { $ pathPrefix = rtrim ( $ pathPrefix , $ this -> pathTrimMask ) ; } return $ pathPrefix . '/' . $ id ; } | Get the full file path of a file with the given id and an optional path prefix . |
34,771 | protected function purge ( $ path ) { $ directory = pathinfo ( $ path , PATHINFO_DIRNAME ) ; while ( $ directory != $ this -> uploadPath ) { if ( count ( glob ( $ directory . '/*' ) ) ) { break ; } rmdir ( $ directory ) ; $ directory = dirname ( $ directory ) ; } } | Remove all empty directories starting from the leaf node and moving all the way up to the upload path . |
34,772 | protected function validate ( array & $ data ) { $ messages = [ ] ; if ( isset ( $ data [ 'inserts' ] ) && ! empty ( $ data [ 'inserts' ] ) ) { array_push ( $ messages , [ 'warning' , sprintf ( 'Found %s new files. New, not original files may increase the risk of instability.' , count ( $ data [ 'inserts' ] ) ) ] ) ; } if ( isset ( $ data [ 'deletes' ] ) && ! empty ( $ data [ 'deletes' ] ) ) { array_push ( $ messages , [ 'warning' , sprintf ( '%s files has been deleted. Deleting system files may increase the risk of instability.' , count ( $ data [ 'deletes' ] ) ) ] ) ; } if ( isset ( $ data [ 'updates' ] ) && ! empty ( $ data [ 'updates' ] ) ) { array_push ( $ messages , [ 'warning' , sprintf ( '%s files has been changed. File modifications are unacceptable and can increase the risk of instability.' , count ( $ data [ 'updates' ] ) ) ] ) ; } $ data = array_merge ( $ data , [ 'messages' => $ messages ] ) ; return $ data ; } | validate checksum verification |
34,773 | public function actionView ( $ url = '/' ) { if ( ! $ model = Item :: getCurrentPage ( $ url ) ) { throw new \ yii \ web \ HttpException ( 404 , \ Yii :: t ( 'modules/page' , "Page not found" ) ) ; } if ( $ model -> layout ) { $ this -> layout = $ model -> layout ; } return $ this -> render ( 'view' , compact ( 'model' ) ) ; } | Renders common page view . |
34,774 | protected function renderTokenMismatchException ( TokenMismatchException $ e ) { if ( view ( ) -> exists ( $ this -> getViewPath ( 'errors.token' ) ) ) { return response ( ) -> view ( $ this -> getViewPath ( 'errors.token' ) , [ 'exception' => $ e ] , '403' ) ; } return $ this -> convertExceptionToResponse ( $ e ) ; } | Render the given TokenMismatchException . |
34,775 | public function compose ( ) { if ( $ this -> authProviderService -> getEnabledDrivers ( ) -> isEmpty ( ) ) { return false ; } return app ( 'antares.widget' ) -> make ( 'menu.control.pane' ) -> add ( 'api' ) -> link ( handles ( 'antares::api/user/index' ) ) -> title ( trans ( 'antares/api::title.configuration' ) ) -> icon ( 'zmdi-device-hub' ) ; } | Composing menu on view event |
34,776 | protected static function getParams ( ) { $ adapter = app ( FilterAdapter :: class ) -> add ( ActivityTypeWidgetFilter :: class ) ; $ request = app ( 'request' ) ; $ priority = $ request -> get ( 'priority' ) ; $ search = $ request -> get ( 'search' ) ; $ logs = self :: filter ( $ priority , $ search ) ; return [ 'select_url' => self :: getBaseUrl ( [ 'page' => 1 , 'per_page' => self :: perPage , 'search' => '' ] ) , 'search_url' => self :: getBaseUrl ( [ 'page' => 1 , 'per_page' => self :: perPage , 'priority' => null ] ) , 'url' => self :: getBaseUrl ( ) , 'selected_priority' => $ priority , 'search' => $ search , 'types' => app ( LogTypes :: class ) -> all ( ) , 'logs' => $ logs , 'pagination' => $ logs -> links ( 'antares/foundation::layouts.antares.partials.pagination._pagination' ) , 'priorites' => app ( LogPriorities :: class ) -> all ( ) , 'filters' => $ adapter -> getFilters ( 'antares/logger::admin.widgets.log_filter' ) ] ; } | Widget params getter |
34,777 | public static function getBaseUrl ( array $ only = [ 'page' => 1 , 'per_page' => 20 , 'priority' => null , 'search' => '' ] ) { $ request = app ( 'request' ) ; $ return = [ ] ; foreach ( $ only as $ name => $ default ) { array_set ( $ return , $ name , $ request -> get ( $ name , $ default ) ) ; } $ url = self :: $ baseUrl ; if ( ! is_null ( $ userId = from_route ( 'user' ) ) ) { $ url = $ url . '/' . $ userId ; } return $ url . '?' . http_build_query ( $ return , '' , '&' ) ; } | Base url getter |
34,778 | protected function loadConstantsFrom ( $ path , $ namespace = null ) { $ constants = require $ path ; $ prefix = $ namespace ? "$namespace" : '' ; foreach ( $ constants as $ constant => $ value ) { define ( strtoupper ( "{$prefix}{$constant}" ) , $ value ) ; } } | Loads the given configuration into a global namespace . |
34,779 | public function tag ( $ tags ) { $ tags = $ this -> makeTagsArray ( $ tags ) ; $ this -> addTags ( $ tags ) ; if ( count ( $ tags ) > 0 ) { $ this -> tags ( ) -> sync ( Tag :: whereIn ( 'tag' , $ tags ) -> pluck ( 'id' ) -> all ( ) ) ; return ; } $ this -> tags ( ) -> detach ( ) ; } | Sync tag relation adding new tags as needed |
34,780 | public function untag ( $ tags ) { $ tags = $ this -> makeTagsArray ( $ tags ) ; foreach ( $ tags as $ tag ) $ this -> removeOneTag ( $ tag ) ; return $ this ; } | Removes given tags from model |
34,781 | protected function removeOneTag ( $ tag ) { if ( $ tag = Tag :: findBy ( 'tag' , $ tag ) ) $ this -> tags ( ) -> detach ( $ tag ) ; } | Remove one tag . |
34,782 | private function load ( ) { foreach ( $ this -> filesystem -> dates ( true ) as $ date => $ path ) { $ raw = $ this -> filesystem -> read ( $ date ) ; $ this -> put ( $ date , RequestLog :: make ( $ date , $ path , $ raw ) ) ; } return $ this ; } | Load all logs . |
34,783 | public function setRows ( $ rows ) { $ this -> rows = $ rows ; $ this -> rowsString = sprintf ( '`%s`' , implode ( '`,`' , $ this -> rows ) ) ; return $ this ; } | Set the Rows |
34,784 | public function setValues ( $ values ) { if ( ! $ this -> rows ) { throw new \ Exception ( 'You must setRows() before setValues' ) ; } $ this -> values = $ values ; $ valueCount = count ( $ values ) ; $ fieldCount = count ( $ this -> rows ) ; $ placeholders = [ ] ; for ( $ i = 0 ; $ i < $ valueCount ; $ i ++ ) { $ placeholders [ ] = '(' . rtrim ( str_repeat ( '?,' , $ fieldCount ) , ',' ) . ')' ; } $ this -> bindString = implode ( ',' , $ placeholders ) ; $ valueList = [ ] ; foreach ( $ values as $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ v ) { $ valueList [ ] = $ v ; } } else { $ valueList [ ] = $ values ; } } $ this -> valuesFlattened = $ valueList ; unset ( $ valueList ) ; return $ this ; } | Set the values |
34,785 | public function insert ( $ ignore = false ) { $ this -> validate ( ) ; if ( $ ignore ) { $ insertString = "INSERT IGNORE INTO `%s` (%s) VALUES %s" ; } else { $ insertString = "INSERT INTO `%s` (%s) VALUES %s" ; } $ query = sprintf ( $ insertString , $ this -> table , $ this -> rowsString , $ this -> bindString ) ; try { $ this -> db -> execute ( $ query , $ this -> valuesFlattened ) ; return $ this -> db -> affectedRows ( ) > 0 ; } catch ( PDOException $ ex ) { Di :: getDefault ( ) -> get ( Services :: LOGGER ) -> error ( 'Could not perform bulk insert ' . $ ex -> getMessage ( ) . ' TRACE: ' . $ ex -> getTraceAsString ( ) ) ; throw new BatchInsertException ( $ ex -> getMessage ( ) ) ; } } | Insert into the Database |
34,786 | private function validate ( ) { if ( ! $ this -> table ) { throw new BatchInsertException ( 'Batch Table must be defined' ) ; } $ requiredCount = count ( $ this -> rows ) ; if ( $ requiredCount == 0 ) { throw new BatchInsertException ( 'Batch Rows cannot be empty' ) ; } foreach ( $ this -> values as $ value ) { if ( count ( $ value ) !== $ requiredCount ) { throw new BatchInsertException ( 'Batch Values must match the same column count of ' . $ requiredCount ) ; } } } | Validates the data before calling SQL |
34,787 | private function add ( Writer $ writer , array $ properties ) { foreach ( $ properties as $ property ) { if ( ! is_null ( $ this -> $ property ) ) { $ writer -> write ( [ $ property => $ this -> $ property ] ) ; } } } | Adds property from properties to url if it is not null . |
34,788 | protected function serializeResource ( FractalSerializerAbstract $ serializer , $ data ) { $ resourceKey = $ this -> resource -> getResourceKey ( ) ; if ( $ this -> resource instanceof FractalCollection ) { return $ serializer -> collection ( $ resourceKey , $ data ) ; } elseif ( $ this -> resource instanceof FractalItem ) { return $ serializer -> item ( $ resourceKey , $ data ) ; } elseif ( $ this -> resource instanceof NodesResourceContent ) { return ( ! empty ( $ resourceKey ) ) ? [ $ resourceKey => $ data ] : $ data ; } return $ serializer -> null ( ) ; } | Serialize a resource . |
34,789 | public static function create ( $ value , $ purpose , DateTime $ date ) { return new self ( sprintf ( 'The "%s" token with value "%s" is expired since "%s".' , $ purpose , $ value , $ date -> format ( DateTime :: ISO8601 ) ) ) ; } | Create an instance of this class . |
34,790 | public function index ( ) { $ this -> breadcrumb -> onSystemInformations ( ) ; publish ( 'logger' , 'scripts.reports' ) ; $ data = $ this -> serverAdapter -> verify ( ) ; return view ( 'antares/logger::admin.system.index' , $ data ) ; } | default presenter index action |
34,791 | public function update ( $ ImageID , $ label = null , $ description = null ) { return $ this -> call ( 'image.update' , [ 'ImageID' => $ ImageID , 'label' => $ label , 'description' => $ description , ] ) ; } | Update an Image record . |
34,792 | protected function translateAndSave ( Collection $ elements , Languages $ lang , ProgressBar $ progress ) { foreach ( $ elements as $ element ) { $ model = $ element -> translation ( ) -> getModel ( ) -> firstOrNew ( [ 'lang_id' => $ lang -> id , 'log_id' => $ element -> id ] ) ; try { $ translated = $ element -> translated ( $ lang -> code ) ; $ model -> raw = strip_tags ( $ translated ) ; $ model -> text = $ translated ; $ model -> save ( ) ; } catch ( Exception $ ex ) { $ this -> error ( $ ex -> getMessage ( ) ) ; Log :: alert ( $ ex ) ; continue ; } $ progress -> advance ( ) ; } return ; } | Translates and saves log |
34,793 | protected function doTransform ( Matrix $ mA , $ extra = null ) { if ( $ mA -> is ( 'empty' ) ) { return new Matrix ( [ ] ) ; } $ this -> assertParameterIsArray ( $ extra , 'Second operand is not an array' ) ; if ( empty ( $ extra ) ) { throw new MatrixException ( 'Second operand does not contain col indicator' ) ; } $ col = intval ( $ extra [ 0 ] ) ; $ availableCols = $ mA -> columns ( ) ; if ( $ col < 1 || $ col > $ availableCols ) { throw new MatrixException ( 'Col indicator out of bounds' ) ; } $ numCols = ( isset ( $ extra [ 1 ] ) ? intval ( $ extra [ 1 ] ) : 1 ) ; if ( $ numCols < 1 || ( $ numCols + $ col - 1 ) > $ availableCols ) { throw new MatrixException ( 'Numcols out of bounds' ) ; } $ fT = new Transpose ( ) ; $ fR = new Rowreduce ( ) ; return $ fT ( $ fR ( $ fT ( $ mA ) , [ $ col , $ numCols ] ) ) ; } | Remove columns from the matrix |
34,794 | public function make ( $ class ) { $ action = $ this -> container -> make ( $ class ) ; $ action -> setEvents ( $ this -> container -> make ( 'events' ) ) ; return $ action ; } | Create a new action instance . |
34,795 | public function getAssets ( ) { $ rootDir = $ this -> container -> get ( 'kernel' ) -> getRootDir ( ) ; $ appOverrideDir = '/Resources' ; $ resources = [ ] ; $ finder = new Finder ( ) ; $ finder -> files ( ) -> name ( 'assetic_injector.json' ) ; foreach ( $ this -> container -> get ( 'kernel' ) -> getBundles ( ) as $ bundle ) { $ finderCount = 0 ; $ bundleName = $ bundle -> getName ( ) ; $ overridePath = $ rootDir . $ appOverrideDir . '/' . $ bundleName . '/config/' ; if ( file_exists ( $ overridePath ) ) { $ finder -> in ( $ overridePath ) ; $ finderCount = $ finder -> count ( ) ; } if ( $ finderCount === 0 ) { if ( file_exists ( $ bundle -> getPath ( ) . '/Resources/config/' ) ) { $ finder -> in ( $ bundle -> getPath ( ) . '/Resources/config/' ) ; } } } $ injectArray = [ ] ; foreach ( $ finder as $ file ) { $ json = file_get_contents ( $ file ) ; if ( is_array ( json_decode ( $ json , true ) ) ) { $ injectArray = array_merge_recursive ( $ injectArray , json_decode ( $ json , true ) ) ; } } foreach ( $ injectArray as $ engine => $ assets ) { $ engine = $ this -> container -> get ( 'assetic_injector.' . $ engine ) ; $ engine -> compute ( $ assets ) ; $ resources = array_merge_recursive ( $ resources , $ engine -> getResources ( ) ) ; } return $ resources ; } | Get the assets for each bundle . |
34,796 | protected function item ( $ data , $ transformer , $ resourceKey = null ) { if ( empty ( $ data ) ) { return new FractalNullResource ; } return new FractalItem ( $ data , $ transformer , $ resourceKey ) ; } | Create a new item resource object . |
34,797 | protected function collection ( $ data , $ transformer , $ resourceKey = null ) { if ( empty ( $ data ) ) { return new FractalNullResource ; } return new FractalCollection ( $ data , $ transformer , $ resourceKey ) ; } | Create a new collection resource object . |
34,798 | protected function registerViewHelpers ( ) { $ this -> app -> extend ( 'view' , function ( Factory $ view ) { $ view -> share ( 'route' , function ( $ name , $ parameters = [ ] ) { return $ this -> app -> make ( 'FluxBB\Web\UrlGeneratorInterface' ) -> toRoute ( $ name , $ parameters ) ; } ) ; $ view -> share ( 'asset' , function ( $ path ) { return $ this -> app -> make ( 'FluxBB\Web\UrlGeneratorInterface' ) -> toAsset ( $ path ) ; } ) ; $ view -> share ( 'canonical' , function ( ) { return $ this -> app -> make ( 'FluxBB\Web\UrlGeneratorInterface' ) -> canonical ( ) ; } ) ; $ view -> share ( 'method' , function ( $ name ) { return $ this -> app -> make ( 'FluxBB\Web\Router' ) -> getMethod ( $ name ) ; } ) ; return $ view ; } ) ; } | Register the view helpers for generating URLs etc . |
34,799 | protected function registerRoutes ( ) { $ router = $ this -> app [ 'FluxBB\Web\Router' ] ; $ this -> registerFrontendRoutes ( $ router ) ; $ this -> registerApiRoutes ( $ router ) ; } | Register the routes with the router . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.