idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
34,300 | protected function throwValidationException ( string $ message , string $ prefix = null ) { throw new ValidationException ( $ message , $ this -> name , $ prefix ) ; } | Throws a validation exception . |
34,301 | private function getManagerFor ( $ class ) { $ manager = $ this -> doctrine -> getManagerForClass ( $ class ) ; if ( $ manager === null ) { throw new \ RuntimeException ( sprintf ( 'Class "%s" seems not to be a managed Doctrine entity. Did you forget to map it?' , $ class ) ) ; } return $ manager ; } | Get doctrine object manager for a class . |
34,302 | public function clear ( $ date , RequestListener $ listener ) { app ( 'antares.logger' ) -> setOld ( [ 'name' => app ( 'logger.filesystem' ) -> getLogFilename ( $ date ) ] ) -> keep ( 'high' ) ; if ( app ( 'logger.filesystem' ) -> delete ( $ date ) ) { return $ listener -> clearSuccess ( ) ; } return $ listener -> clearFailed ( ) ; } | on clear request log |
34,303 | public function download ( RequestListener $ listener , $ date ) { $ filename = app ( 'logger.filesystem' ) -> getLogFilename ( $ date ) ; $ path = dirname ( config ( 'request-logger.logger.file' ) ) . DIRECTORY_SEPARATOR . $ filename ; if ( ! file_exists ( $ path ) ) { return $ listener -> downloadFailed ( ) ; } return response ( ) -> download ( $ path ) ; } | Download request log |
34,304 | public function actionClear ( ) { $ query = AttachmentFile :: find ( ) -> temporary ( ) ; foreach ( $ query -> batch ( 10 ) as $ models ) { foreach ( $ models as $ model ) { $ url = $ model -> filePath ; if ( $ model -> delete ( ) ) { $ this -> stdout ( 'File ' ) ; $ this -> stdout ( $ url , Console :: FG_YELLOW ) ; $ this -> stdout ( ' deleted' ) ; echo PHP_EOL ; } } } } | Clear temporary files |
34,305 | public function fromMatrix ( Matrix $ mA ) { $ data = $ mA -> toArray ( ) ; $ rows = $ mA -> rows ( ) ; $ cols = $ mA -> columns ( ) ; for ( $ y = 0 ; $ y < $ rows ; $ y ++ ) { for ( $ x = 0 ; $ x < $ cols ; $ x ++ ) { $ this -> append ( new Vector2D ( $ x , $ y , $ data [ $ y ] [ $ x ] ) ) ; } } return $ this ; } | Add vector set entries from a Matrix |
34,306 | public function toMatrix ( $ rebase = true ) { $ mArr = [ ] ; foreach ( $ this as $ vector ) { $ mArr [ $ vector -> getY ( ) ] [ $ vector -> getX ( ) ] = $ vector -> getValue ( ) ; } if ( $ rebase ) { return new Matrix ( $ this -> rebase ( $ mArr ) ) ; } else { return new Matrix ( $ mArr ) ; } } | Convert vector set to a matrix where row == y col == x |
34,307 | protected function rebase ( array $ a ) { $ res = [ ] ; ksort ( $ a ) ; foreach ( array_values ( $ a ) as $ row ) { ksort ( $ row ) ; $ res [ ] = array_values ( $ row ) ; } return $ res ; } | Sort and rebase the result array to zero |
34,308 | protected function initiate ( & $ params ) { $ name = $ this -> model -> name ; $ owner = isset ( $ this -> model -> new_value [ 'name' ] ) ? $ this -> model -> new_value [ 'name' ] : $ this -> model -> owner_id ; $ user = is_null ( $ this -> model -> user ) ? 'Automation' : anchor ( 'users/' . $ this -> model -> user_id , '#' . $ this -> model -> user -> id . ' ' . $ this -> model -> user -> fullname ) ; $ params = [ 'owner_id' => $ owner , 'user_id' => $ this -> model -> user_id , 'user' => $ user ] ; $ params = array_merge ( $ params , ( array ) $ this -> model -> additional_params ) ; return $ name ; } | Inititate params container |
34,309 | public function decorate ( ) { $ classname = $ this -> model -> owner_type ; $ return = '' ; if ( $ this -> hasMethod ( $ classname , 'getLogTitle' ) ) { $ return = $ classname :: getLogTitle ( $ this -> model -> owner_id , $ this -> model ) ; } if ( strlen ( $ return ) ) { return $ return ; } list ( $ operation , $ params ) = $ this -> getOperationWithParams ( ) ; return $ this -> translate ( $ operation , $ params ) ; } | Decorates log entry |
34,310 | protected function getOperationWithParams ( ) { $ params = [ ] ; $ operation = $ this -> initiate ( $ params ) ; if ( $ operation == 'JOBRESULTS_CREATED' ) { $ operation = $ this -> job ( $ params ) ; } else { $ found = false ; $ url = $ this -> getUrlPattern ( ) ; $ map = [ ] ; if ( ! is_null ( $ this -> model -> new_value ) ) { $ map = $ this -> getReplacementKeys ( ) ; $ values = $ this -> getReplacementValues ( ) ; $ title = $ this -> getTitle ( $ this -> model -> new_value ) ; $ found = $ this -> urlFillable ( $ url , $ map ) ; } else { $ title = $ this -> getTitle ( $ this -> model -> old_value ) ; } array_set ( $ params , 'owner_id' , ( $ found && strlen ( $ url ) > 0 ) ? $ this -> link ( $ map , $ values , $ url , $ title ) : $ title ) ; $ operation = $ this -> getRelationData ( $ params , $ map ) ; } $ this -> fill ( $ params ) ; return [ $ operation , $ params ] ; } | Gets operation name with params |
34,311 | protected function translate ( $ operation , array $ params = [ ] ) { $ locale = is_null ( $ this -> locale ) ? app ( ) -> getLocale ( ) : $ this -> locale ; $ translator = app ( 'translator' ) ; if ( ( $ name = $ this -> notificationContents -> find ( $ operation , $ locale ) ) !== false ) { return $ translator -> transWith ( $ name , $ params ) ; } return $ translator -> trans ( "antares/logger::operations.{$operation}" , $ params , 'messages' , $ locale , false ) ; } | Translates log message |
34,312 | protected function getRelationData ( & $ params , array $ map = [ ] ) { $ operation = $ this -> model -> name ; if ( is_null ( $ this -> model -> related_data ) ) { return $ operation ; } foreach ( $ this -> model -> related_data as $ relation => $ data ) { if ( $ relation === 'users' ) { $ classname = get_class ( \ Antares \ Support \ Facades \ Foundation :: make ( 'antares.user' ) ) ; $ urlPattern = $ this -> getUrlPattern ( $ classname ) ; $ links = [ ] ; foreach ( $ data as $ element ) { $ links [ ] = $ this -> link ( '{id}' , $ element [ 'id' ] , $ urlPattern , array_get ( $ element , 'firstname' ) . ' ' . array_get ( $ element , 'lastname' ) ) ; } $ params [ $ relation ] = implode ( ', ' , $ links ) ; } elseif ( $ relation === 'user' ) { continue ; } elseif ( ! empty ( $ data ) ) { foreach ( $ data as $ classname => $ values ) { if ( empty ( $ values ) ) { continue ; } if ( ! class_exists ( $ classname ) ) { continue ; } if ( ( $ url = $ this -> getUrlPattern ( $ classname ) ) !== '' ) { $ submap = $ this -> getReplacementKeys ( $ values ) ; $ subValues = array_values ( $ values ) ; $ title = array_get ( $ values , 'name' , array_get ( $ values , 'id' ) ) ; array_set ( $ params , $ relation , ! $ this -> urlFillable ( $ url , $ map ) ? $ title : $ this -> link ( $ submap , $ subValues , $ url , $ title ) ) ; } else { $ params [ $ relation ] = $ this -> getTitle ( current ( $ data ) ) ; } } } $ operation .= '_' . strtoupper ( $ relation ) ; } return $ operation ; } | Gets relation data for log entry |
34,313 | protected function link ( $ keys , $ replacements , $ url , $ title ) { return HTML :: link ( handles ( str_replace ( $ keys , $ replacements , $ url ) ) , $ title ) ; } | Generates log link |
34,314 | protected function getReplacementKeys ( array $ map = [ ] ) { $ keys = empty ( $ map ) ? array_keys ( $ this -> model -> new_value ) : array_keys ( $ map ) ; return array_map ( function ( $ current ) { return '{' . $ current . '}' ; } , $ keys ) ; } | Gets replacement keys |
34,315 | protected function getUrlPattern ( $ class = null ) { $ url = '' ; $ classname = is_null ( $ class ) ? $ this -> model -> owner_type : $ class ; if ( ! class_exists ( $ classname ) ) { return $ url ; } if ( $ this -> hasMethod ( $ classname , 'getPatternUrl' ) ) { $ url = $ classname :: getPatternUrl ( $ this -> model -> owner_id , $ this -> model ) ; } return $ url ; } | Gets url pattern when available |
34,316 | protected function urlFillable ( $ url , array $ map = [ ] ) { if ( ! str_contains ( $ url , '{' ) and ! str_contains ( $ url , '}' ) ) { return true ; } foreach ( $ map as $ value ) { if ( str_contains ( $ url , $ value ) ) { return true ; } } return false ; } | Gets url fillable params |
34,317 | protected function job ( & $ params ) { $ operationName = $ this -> model -> name ; $ instance = app ( $ this -> model -> owner_type ) -> with ( 'job' ) -> find ( $ this -> model -> owner_id ) ; if ( is_null ( $ instance ) ) { array_set ( $ params , 'time' , '0.0' ) ; array_set ( $ params , 'name' , '[not available]' ) ; $ params [ 'return' ] = '<span class="label-basic label-basic--danger ">Error</span>' ; return 'JOBRESULTS_CREATED_ERROR' ; } array_set ( $ params , 'return' , $ instance -> return ) ; array_set ( $ params , 'time' , $ instance -> runtime ) ; array_set ( $ params , 'name' , anchor ( handles ( 'antares::automation/show/' . $ instance -> job_id ) , $ instance -> job -> name ) ) ; if ( array_get ( $ this -> model -> new_value , 'has_error' ) !== false ) { $ operationName = 'JOBRESULTS_CREATED_ERROR' ; $ params [ 'return' ] = '<span id="error-' . $ this -> model -> owner_id . '" class="label-basic label-basic--danger ">error</span><div class="mdl-tooltip" for="error-' . $ this -> model -> owner_id . '">error</div>' ; } else { $ params [ 'return' ] = '<span id="success-' . $ this -> model -> owner_id . '" class="label-basic label-basic--success ">SUCCESSFULLY</span><div class="mdl-tooltip" for="success-' . $ this -> model -> owner_id . '">successfully</div>' ; } return $ operationName ; } | When logs entity comes from automation job |
34,318 | protected function fill ( & $ params ) { if ( is_null ( $ this -> model -> new_value ) ) { return false ; } foreach ( $ params as $ index => $ value ) { if ( isset ( $ params [ $ index ] ) ) { continue ; } $ params [ $ index ] = array_get ( $ this -> model -> new_value , $ index ) ; } return $ params ; } | Fills params with rest of entity columns |
34,319 | public function setupDatabaseTables ( ) { $ logger = $ this -> getLogger ( ) ; $ database = $ this -> getDatabase ( ) ; $ databaseHandle = $ database -> getDatabaseConnection ( ) ; $ tableDefinition = $ database -> getTableDefinition ( ) ; $ tables = array_keys ( $ tableDefinition ) ; foreach ( $ tables as $ tableName ) { $ logger -> writeln ( '<info>Table "' . $ tableName . '"</info>' ) ; $ statement = $ databaseHandle -> prepare ( 'SHOW TABLES LIKE :table' ) ; $ statement -> bindParam ( ':table' , $ tableName , \ PDO :: PARAM_STR ) ; $ statement -> execute ( ) ; if ( $ statement -> rowCount ( ) == 1 ) { $ logger -> writeln ( '<info>=> Exists. Skip it</info>' ) ; continue ; } $ createTableResult = $ databaseHandle -> query ( $ tableDefinition [ $ tableName ] ) ; if ( $ createTableResult === false ) { $ databaseError = $ databaseHandle -> errorInfo ( ) ; $ message = 'Table "%s" could not be created. %s (%s)' ; $ message = sprintf ( $ message , $ tableName , $ databaseError [ 2 ] , $ databaseError [ 1 ] ) ; throw new \ Exception ( $ message , 1398100879 ) ; } else { $ logger -> writeln ( '<info>Not exists. Created</info>' ) ; } } return true ; } | Creates the necessary database tables if they are not exists . |
34,320 | public function keysExist ( array $ keys ) { foreach ( $ keys as $ key ) { if ( ! $ this -> keyExists ( $ key ) ) { return false ; } } return true ; } | Returns true if a all keys exist false otherwise . |
34,321 | private function encodeMulticall ( array $ requests ) { $ composed_requests = [ ] ; $ this -> logger -> debug ( "Performing an XML multicall" ) ; $ this -> logger -> debug ( "Data dump before encoding" , $ requests ) ; foreach ( $ requests as $ request ) { $ composed_requests [ ] = [ $ request -> getMethod ( ) , $ request -> getParameters ( ) ] ; foreach ( $ request -> getSpecialTypes ( ) as $ key => $ value ) { $ this -> encoder -> setValueType ( $ key , $ value ) ; } } try { $ encoded_requests = $ this -> encoder -> setEncoding ( $ this -> getEncoding ( ) ) -> encodeMulticall ( $ composed_requests ) ; } catch ( XmlrpcException $ xe ) { throw $ xe ; } $ this -> logger -> debug ( "Data dump after encoding: " . $ encoded_requests ) ; return $ encoded_requests ; } | Perform an xml multicall |
34,322 | public function down ( ) { DB :: transaction ( function ( ) { DB :: table ( 'tbl_logs' ) -> delete ( ) ; DB :: table ( 'tbl_log_priorities' ) -> delete ( ) ; DB :: table ( 'tbl_log_types' ) -> delete ( ) ; } ) ; } | delete all database occurences for logger component |
34,323 | protected function prepareCommand ( ) { $ command = $ this -> getExecutable ( ) . ' ' ; $ keyFile = $ this -> getKeyFile ( ) ; if ( $ keyFile ) { $ command .= '-i ' . $ keyFile . ' ' ; } $ port = $ this -> getPort ( ) ; if ( $ port > 0 ) { $ command .= '-p ' . $ port . ' ' ; } $ command .= implode ( ' ' , $ this -> getCommandParts ( ) ) . ' ' ; $ command .= implode ( ' ' , $ this -> getArguments ( ) ) ; $ command = trim ( $ command ) ; if ( $ command ) { $ command .= ' 2>&1' ; } return $ command ; } | Prepares and builds the full command . All properties like ssh key port command and agruments will be considered |
34,324 | public function execute ( $ implodeReturnValue = true ) { $ data = [ ] ; $ command = $ this -> getCommand ( ) ; $ data = $ this -> execCommand ( $ command , $ data ) ; if ( $ implodeReturnValue === false ) { return $ data ; } return implode ( '' , $ data ) ; } | Executes the built command . Returns the output of the command . |
34,325 | public function addArgument ( $ argument , $ value , $ glue ) { $ escapedValue = ( ( $ value ) ? escapeshellarg ( $ value ) : '' ) ; $ this -> arguments [ ] = $ argument . $ glue . $ escapedValue ; } | Adds a new argument to the SSH command . |
34,326 | public function b2_delete_file_version ( $ api_url , $ auth_token , $ file_id , $ file_name ) { $ call_url = $ api_url . "/b2api/v1/b2_delete_file_version" ; $ auth_token = $ auth_token ; $ file_id = $ file_id ; $ file_name = $ file_name ; $ data = array ( "fileId" => $ file_id , "fileName" => $ file_name ) ; $ headers = array ( "Authorization: {$auth_token}" ) ; $ result = b2_call ( $ call_url , $ headers , $ data ) ; return $ result ; } | Delete file version |
34,327 | public function b2_download_file_by_id ( $ download_url , $ file_id , $ auth_token = NULL ) { $ call_url = $ download_url . "/b2api/v1/b2_download_file_by_id?fileId=" . $ file_id ; $ auth_token = $ auth_token ; $ download_url = $ download_url ; $ file_id = $ file_id ; $ headers = array ( "Authorization: {$auth_token}" ) ; $ result = b2_call ( $ call_url , $ headers ) ; return $ result ; } | Download file by ID |
34,328 | public function b2_download_file_by_name ( $ download_url , $ bucket_name , $ file_name , $ auth_token = NULL ) { $ call_url = $ download_url . "/file/" . $ bucket_name . "/" . $ file_name ; $ auth_token = $ auth_token ; $ download_url = $ download_url ; $ bucket_name = $ bucket_name ; $ file_name = $ file_name ; $ headers = array ( "Authorization: {$auth_token}" ) ; $ result = b2_call ( $ call_url , $ headers ) ; return $ result ; } | Download file by name |
34,329 | public function b2_list_file_names ( $ api_url , $ auth_token , $ bucket_id , $ options = NULL ) { $ call_url = $ api_url . "/b2api/v1/b2_list_file_names" ; $ auth_token = $ auth_token ; $ bucket_id = $ bucket_id ; $ max_count = $ options [ "max_count" ] ; $ start_name = $ options [ "start_name" ] ; $ data = array ( "bucketId" => $ bucket_id , "startFileName" => $ start_name , "maxFileCount" => $ max_count ) ; $ headers = array ( "Authorization: {$auth_token}" ) ; $ result = b2_call ( $ call_url , $ headers , $ data ) ; return $ result ; } | List file names |
34,330 | public function b2_update_bucket ( $ api_url , $ account_id , $ auth_token , $ bucket_id , $ bucket_type ) { $ call_url = $ api_url . "/b2api/v1/b2_update_bucket" ; $ account_id = $ account_id ; $ auth_token = $ auth_token ; $ bucket_id = $ bucket_id ; $ bucket_type = $ bucket_type ; $ data = array ( "accountId" => $ account_id , "bucketId" => $ bucket_id , "bucketType" => $ bucket_type ) ; $ headers = array ( "Authorization: {$auth_token}" ) ; $ result = b2_call ( $ call_url , $ headers , $ data ) ; return $ result ; } | List update bucket |
34,331 | public function b2_upload_file ( $ upload_url , $ auth_token , $ file_path ) { $ call_url = $ upload_url ; $ auth_token = $ auth_token ; $ file_path = $ file_path ; $ handle = fopen ( $ file_path , 'r' ) ; $ read_file = fread ( $ handle , filesize ( $ file_path ) ) ; $ file_name = basename ( $ file_path ) ; $ file_type = mime_content_type ( $ file_path ) ; $ file_hash = sha1_file ( $ file_path ) ; $ headers = array ( "Authorization: {$auth_token}" , "X-Bz-File-Name: {$file_name}" , "Content-Type: {$file_type}" , "X-Bz-Content-Sha1: {$file_hash}" ) ; $ result = b2_call ( $ call_url , $ headers , $ read_file ) ; return $ result ; } | List upload file |
34,332 | public function delete ( $ id = null , ActivityListener $ listener ) { if ( is_null ( $ id ) && ! is_null ( $ range = Input :: get ( 'daterange' ) ) ) { return $ this -> deleteByRange ( $ listener , $ range ) ; } if ( is_null ( $ id ) && ! is_null ( $ ids = input ( 'attr' ) ) ) { return $ this -> deleteByIds ( $ listener , $ ids ) ; } $ model = Logs :: withoutGlobalScopes ( ) -> whereHas ( 'user' , function ( $ query ) { $ query -> whereIn ( 'id' , $ this -> users ( ) ) ; } ) -> find ( $ id ) ; if ( is_null ( $ model ) ) { return $ listener -> deleteFailed ( ) ; } $ model -> delete ( ) ; return $ listener -> deleteSuccess ( ) ; } | On delete log item |
34,333 | public function show ( $ id ) { $ model = Logs :: withoutGlobalScopes ( ) -> with ( 'component' , 'priority' , 'brand' ) -> with ( [ 'user' => function ( $ query ) { $ query -> whereRaw ( 'tbl_users.id in (' . implode ( ',' , $ this -> users ( ) ) . ') or tbl_users.id is null' ) ; } ] ) -> whereId ( $ id ) -> firstOrFail ( ) ; return $ this -> presenter -> show ( $ model ) ; } | shows details about single row log |
34,334 | public function download ( ) { set_time_limit ( 0 ) ; ini_set ( 'max_execution_time' , 0 ) ; ignore_user_abort ( ) ; $ datatable = app ( ActivityLogs :: class ) ; list ( $ headers , $ data ) = $ this -> prepareHeadersAndKeys ( $ datatable ) ; $ items = $ this -> prepareContent ( $ datatable , $ data ) ; $ top = implode ( self :: separator , $ headers ) ; $ content = implode ( "\n" , $ items ) ; $ csv = implode ( "\n" , [ $ top , $ content ] ) ; $ date = date ( 'Y_m_d_H_i_s' , time ( ) ) ; $ filename = "activity_log_{$date}.csv" ; return response ( $ csv , 200 , [ 'Content-Type' => 'text/csv' , 'Content-Description' => 'File Transfer' , 'Content-Disposition' => 'attachment; filename=' . $ filename , 'Content-Transfer-Encoding' => 'binary' , 'Connection' => 'Keep-Alive' , 'Expires' => '0' , 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0' , 'Pragma' => 'public' , 'Content-Length' => strlen ( $ csv ) ] ) ; } | Download actvity log |
34,335 | protected function prepareContent ( ActivityLogs $ datatable , array $ data ) { $ collection = $ datatable -> query ( ) -> get ( ) ; $ return = [ ] ; foreach ( $ collection as $ log ) { $ element = [ ] ; foreach ( $ data as $ key => $ method ) { if ( method_exists ( $ datatable , $ method ) ) { $ called = call_user_func ( $ datatable -> { $ method } ( ) , $ log ) ; $ value = is_object ( $ called ) ? $ called -> __toString ( ) : $ called ; } else { $ value = $ log -> { $ key } ; } array_push ( $ element , strip_tags ( $ value ) ) ; } array_push ( $ return , implode ( self :: separator , $ element ) ) ; } return $ return ; } | Prepares content for csv |
34,336 | protected function prepareHeadersAndKeys ( $ datatable ) { $ headers = [ ] ; $ data = [ ] ; $ columns = $ datatable -> html ( ) -> getColumns ( ) ; foreach ( $ columns as $ column ) { if ( $ column -> data == 'action' ) { continue ; } array_push ( $ headers , $ column -> title ) ; array_set ( $ data , $ column -> data , 'get' . ucfirst ( $ column -> data ) . 'Value' ) ; } return [ $ headers , $ data ] ; } | Prepares headers and data keys for csv |
34,337 | protected function users ( ) { $ user = auth ( ) -> user ( ) ; $ roles = $ childs = $ user -> roles -> first ( ) -> getChilds ( ) ; $ users = User :: select ( [ 'id' ] ) -> withoutGlobalScopes ( ) -> whereHas ( 'roles' , function ( $ query ) use ( $ roles ) { $ query -> whereIn ( 'tbl_roles.id' , array_values ( $ roles ) ) ; } ) -> get ( ) -> pluck ( 'id' ) -> toArray ( ) ; array_push ( $ users , $ user -> id ) ; return $ users ; } | Child users getter |
34,338 | public static function detectMimeType ( $ fileName ) { $ fileInfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mime = finfo_file ( $ fileInfo , $ fileName ) ; finfo_close ( $ fileInfo ) ; return $ mime ; } | Detect mime type for file . |
34,339 | public static function formXml ( $ xml , $ file ) { $ xml = simplexml_load_string ( $ xml ) ; $ dataArray = $ xml -> attributes ( ) ; $ dataFileInfo = new DataFileInfo ( ) ; if ( isset ( $ dataArray [ 'Id' ] ) ) { $ dataFileInfo -> setId ( $ dataArray [ 'Id' ] -> __toString ( ) ) ; } if ( isset ( $ dataArray [ 'Filename' ] ) ) { $ dataFileInfo -> setFilename ( $ dataArray [ 'Filename' ] -> __toString ( ) ) ; } if ( isset ( $ dataArray [ 'ContentType' ] ) ) { $ dataFileInfo -> setContentType ( $ dataArray [ 'ContentType' ] -> __toString ( ) ) ; } if ( isset ( $ dataArray [ 'MimeType' ] ) ) { $ dataFileInfo -> setMimeType ( $ dataArray [ 'MimeType' ] -> __toString ( ) ) ; } if ( isset ( $ dataArray [ 'Size' ] ) ) { $ dataFileInfo -> setSize ( $ dataArray [ 'Size' ] -> __toString ( ) ) ; } if ( isset ( $ dataArray [ 'DigestType' ] ) ) { $ dataFileInfo -> setDigestType ( $ dataArray [ 'DigestType' ] -> __toString ( ) ) ; } if ( isset ( $ dataArray [ 'DigestValue' ] ) ) { $ dataFileInfo -> setDigestValue ( $ dataArray [ 'DigestValue' ] -> __toString ( ) ) ; } if ( isset ( $ dataArray [ 'DfData' ] ) ) { $ dataFileInfo -> setDfData ( $ dataArray [ 'DfData' ] -> __toString ( ) ) ; } elseif ( file_exists ( $ file ) ) { $ dataFileInfo -> setDfData ( base64_encode ( file_get_contents ( $ file ) ) ) ; } return $ dataFileInfo ; } | Creates new DataFileInfo from xml element |
34,340 | public function setProtocol ( $ protocol ) { $ proto = strtoupper ( $ protocol ) ; if ( ! in_array ( $ proto , static :: $ supported_protocols ) ) { throw new Exception ( "Invalid RPC protocol" ) ; } $ this -> protocol = $ proto ; return $ this ; } | Set RPC protocol |
34,341 | public function registerMany ( $ formFields ) { foreach ( $ formFields as $ fieldName => $ fieldClass ) { $ this -> register ( $ fieldName , $ fieldClass ) ; } } | Registers an array of new CMS form fields . |
34,342 | protected function translateCursor ( $ properties ) { $ out = [ ] ; foreach ( $ this -> sortMap as $ k => $ v ) { if ( isset ( $ properties [ $ k ] ) ) { $ d = $ v [ 1 ] === OrderParameter :: DESC ? '!' : '' ; $ out [ $ d . $ this -> toPublic ( $ k ) ] = $ properties [ $ k ] ; } } return base64_encode ( json_encode ( $ out ) ) ; } | Translate private cursor in their public counterparts |
34,343 | public function getMetaField ( $ fieldName ) { if ( property_exists ( $ this -> data , 'metadata' ) && property_exists ( $ this -> data -> metadata , $ fieldName ) ) { return $ this -> data -> metadata -> { $ fieldName } ; } else { return null ; } } | attempt to return the fieldName from the metadata on the response object If not present return null . |
34,344 | public function getLinkField ( $ linkType ) { if ( property_exists ( $ this -> data , 'links' ) && property_exists ( $ this -> data -> links , $ linkType ) ) { return $ this -> data -> links -> { $ linkType } ; } else { return null ; } } | attempt to return the link id from the links on the response object If not present return null . |
34,345 | public function set ( $ row , $ col , $ data ) { if ( $ row < 0 || $ row > $ this -> rows ( ) ) { throw new VerticeOutOfBoundsException ( 'row' , $ row ) ; } if ( $ col < 0 || $ col > $ this -> columns ( ) ) { throw new VerticeOutOfBoundsException ( 'col' , $ col ) ; } if ( $ row == 0 && $ col == 0 ) { throw new VerticeOutOfBoundsException ( 'row & col' , 0 ) ; } if ( ( $ row == 0 || $ col == 0 ) && ! $ data instanceof Matrix ) { throw new MatrixException ( '$data for set method must be a matrix' ) ; } if ( $ row == 0 && $ col > 0 ) { if ( ! $ data -> is ( 'columnvector' ) ) { throw new MatrixException ( '$data for set method must be a column vector' ) ; } $ dArr = $ data -> toArray ( ) ; $ col -- ; $ nRows = $ this -> rows ( ) ; for ( $ n = 0 ; $ n < $ nRows ; $ n ++ ) { $ this -> data [ $ n ] [ $ col ] = $ dArr [ $ n ] [ 0 ] ; } return $ this ; } if ( $ col == 0 && $ row > 0 ) { if ( ! $ data -> is ( 'rowvector' ) ) { throw new MatrixException ( '$data for set method must be a row vector' ) ; } $ dArr = $ data -> toArray ( ) ; $ row -- ; $ nCols = $ this -> columns ( ) ; for ( $ m = 0 ; $ m < $ nCols ; $ m ++ ) { $ this -> data [ $ row ] [ $ m ] = $ dArr [ 0 ] [ $ m ] ; } return $ this ; } $ this -> data [ $ row - 1 ] [ $ col - 1 ] = $ data ; return $ this ; } | Set a matrix vertex row or column vector If row == 0 && col > 0 then set the column vector indicated by col If col == 0 && row > 0 then set the row vector indicated by row if row > 0 && col > 0 set the vertex row == col == 0 is an error |
34,346 | public function execute ( array $ input = [ ] ) { $ this -> input = $ input ; $ data = $ this -> run ( ) ; return new Response ( $ data ? : [ ] ) ; } | Turn a request into a response . |
34,347 | protected function raise ( $ event ) { $ qualified = get_class ( $ event ) ; $ name = str_replace ( '\\' , '.' , $ qualified ) ; $ this -> events -> fire ( $ name , [ $ event ] ) ; } | Raise the given event . |
34,348 | public function handle ( ServerRequestInterface $ request ) : ResponseInterface { $ container = new ControllerContainer ( $ this -> container , $ request ) ; $ placeholders = array_map ( [ $ request , 'getAttribute' ] , $ this -> attributes ) ; $ controller = $ container -> get ( $ this -> controller ) ; if ( is_object ( $ controller ) ) { $ action = [ $ controller , $ this -> method ] ; return ( $ this -> factory ) ( $ action ) -> value ( $ container , $ placeholders ) ; } throw new ContainedControllerTypeException ( $ this -> controller , $ controller ) ; } | Return a response from the controller method . Use a controller container using the given request to get the controller and execute the controller method using the resolvable callable factory . |
34,349 | protected function doTransform ( Matrix $ mA , $ extra = null ) { $ this -> assertMatrixIsComplete ( $ mA ) ; if ( $ mA -> is ( 'empty' ) ) { return new Matrix ( array ( ) ) ; } if ( ! is_callable ( $ extra ) ) { throw new MatrixException ( 'Function parameter is not callable' ) ; } $ data = array ( ) ; $ mAData = $ mA -> toArray ( ) ; $ rows = $ mA -> rows ( ) ; $ cols = $ mA -> columns ( ) ; for ( $ row = 0 ; $ row < $ rows ; $ row ++ ) { for ( $ col = 0 ; $ col < $ cols ; $ col ++ ) { $ data [ $ row ] [ $ col ] = $ extra ( $ row + 1 , $ col + 1 , $ mAData [ $ row ] [ $ col ] ) ; } } return new Matrix ( $ data ) ; } | Apply a function to every entry in the matrix |
34,350 | public function updateAuthFailed ( array $ errors ) { $ message = trans ( 'antares/api::response.configuration.update.failed' ) ; $ url = handles ( 'antares::api/configuration' ) ; return $ this -> redirectWithMessage ( $ url , $ message , 'error' ) ; } | Response when updating auth driver failed . |
34,351 | protected function call ( $ action , array $ parameters = [ ] ) { if ( $ this -> batch ) { $ query = [ 'api_action' => $ action ] ; foreach ( $ parameters as $ key => $ value ) { if ( $ value !== null ) { $ query [ urlencode ( $ key ) ] = urlencode ( $ value ) ; } } $ this -> batch -> addRequest ( $ query ) ; return true ; } $ curl = curl_init ( ) ; if ( ! $ curl ) { return false ; } $ query = "api_key={$this->key}&api_action={$action}" ; foreach ( $ parameters as $ key => $ value ) { if ( $ value !== null ) { $ query .= sprintf ( '&%s=%s' , urlencode ( $ key ) , urlencode ( $ value ) ) ; } } if ( $ this -> debug ) { return $ query ; } $ this -> options [ CURLOPT_URL ] = 'https://api.linode.com/' ; $ this -> options [ CURLOPT_POST ] = true ; $ this -> options [ CURLOPT_POSTFIELDS ] = $ query ; $ this -> options [ CURLOPT_RETURNTRANSFER ] = true ; $ this -> options [ CURLOPT_SSLVERSION ] = CURL_SSLVERSION_TLSv1_2 ; curl_setopt_array ( $ curl , $ this -> options ) ; $ result = curl_exec ( $ curl ) ; curl_close ( $ curl ) ; $ json = json_decode ( $ result , true ) ; if ( ! $ json ) { throw new \ RuntimeException ( 'Empty response' ) ; } $ error = reset ( $ json [ 'ERRORARRAY' ] ) ; if ( $ error ) { throw new LinodeException ( $ error [ 'ERRORMESSAGE' ] , $ error [ 'ERRORCODE' ] ) ; } return $ json [ 'DATA' ] ; } | Performs specified call to Linode API . |
34,352 | public function findByAttributes ( $ componentId = null ) { return $ this -> model -> with ( 'component' , 'priority' , 'user' , 'brand' ) -> whereHas ( 'component' , function ( $ q ) use ( $ componentId ) { $ q -> where ( 'active' , 1 ) ; if ( ! is_null ( $ componentId ) ) { $ q -> where ( 'id' , $ componentId ) ; } } ) -> where ( 'brand_id' , brand_id ( ) ) -> orderBy ( 'created_at' , 'desc' ) ; } | find models by type |
34,353 | public function findByComponentName ( $ name = null ) { return $ this -> model -> with ( 'component' , 'priority' , 'brand' , 'jobs' ) -> whereHas ( 'component' , function ( $ q ) use ( $ name ) { $ q -> where ( 'active' , 1 ) ; if ( ! is_null ( $ name ) ) { $ q -> where ( 'name' , $ name ) ; } } ) -> where ( 'brand_id' , brand_id ( ) ) ; } | find rows by component type name |
34,354 | public function findByUser ( $ userId = null ) { $ builder = $ this -> model -> select ( [ 'tbl_logs.id' , 'tbl_logs.priority_id' , 'tbl_logs.type_id' , 'tbl_logs.brand_id' , 'tbl_logs.user_id' , 'tbl_logs.owner_type' , 'tbl_logs.owner_id' , 'tbl_logs.old_value' , 'tbl_logs.new_value' , 'tbl_logs.related_data' , 'tbl_logs.type' , 'tbl_logs.name' , 'tbl_logs.created_at' ] ) -> with ( 'component' , 'priority' , 'brand' ) -> whereHas ( 'user' , function ( $ q ) use ( $ userId ) { if ( ! is_null ( $ userId ) ) { $ q -> where ( 'user_id' , $ userId ) ; } } ) -> whereHas ( 'component' , function ( $ q ) { $ q -> where ( 'active' , 1 ) ; } ) -> where ( 'brand_id' , brand_id ( ) ) -> orderBy ( 'created_at' , 'desc' ) ; $ builder -> withoutGlobalScopes ( ) ; return $ builder ; } | Finds all logs by user id |
34,355 | public function deleteByRange ( $ from , $ to ) { DB :: beginTransaction ( ) ; try { $ from = $ from . ' 00:00:00' ; $ to = $ to . ' 23:59:59' ; $ logs = Logs :: whereBetween ( 'created_at' , [ $ from , $ to ] ) ; $ logs -> delete ( ) ; } catch ( Exception $ ex ) { Log :: alert ( $ ex ) ; DB :: rollback ( ) ; return false ; } DB :: commit ( ) ; return true ; } | Deletes logs using range |
34,356 | protected function checkRelationExistence ( $ name ) { $ getter = 'get' . ucfirst ( $ name ) ; $ class = get_class ( $ this -> owner ) ; if ( method_exists ( $ this -> owner , $ getter ) ) { $ value = $ this -> owner -> $ getter ( ) ; if ( ! ( $ value instanceof ActiveQueryInterface ) ) { throw new InvalidConfigException ( "Value of relation '$getter' not valid" ) ; } $ this -> models [ $ name ] [ 'multiple' ] = $ value -> multiple ; } else { throw new InvalidConfigException ( "Relation '$class::$getter' for attribute '$name' does not exists" ) ; } } | Check if relation with given name exists in model |
34,357 | public function beforeUpdate ( ) { foreach ( $ this -> models as $ relationName => $ config ) { $ this -> markFilesAsPermanent ( $ this -> getRelationValues ( $ relationName ) ) ; } } | Function will be called before updating the record . |
34,358 | protected function authorize ( Request $ request ) { $ authorizer = $ this -> resolveAuthorizer ( $ request ) ; if ( $ authorizer ) { $ authorizer -> authorize ( $ this -> getSubject ( ) ) ; } } | Authorize the given request . |
34,359 | protected function resolveAuthorizer ( Request $ request ) { if ( ! isset ( $ this -> authorizers [ $ request -> getHandler ( ) ] ) ) { return null ; } try { $ authorizerClass = $ this -> authorizers [ $ request -> getHandler ( ) ] ; return $ this -> container -> make ( $ authorizerClass ) ; } catch ( BindingResolutionException $ e ) { return null ; } } | Resolve the matching authorizer instance . |
34,360 | public function addField ( FieldInterface $ field ) : Definition { $ name = $ field -> getName ( ) ; if ( $ this -> hasField ( $ name ) ) { throw new DefinitionException ( "Field '$name' is already defined." ) ; } $ this -> fields [ $ name ] = $ field ; return $ this ; } | Adds the field . |
34,361 | public function getField ( string $ name ) : FieldInterface { if ( ! $ this -> hasField ( $ name ) ) { throw new DefinitionException ( "Field '$name' is not defined." ) ; } return $ this -> fields [ $ name ] ; } | Returns the field for the given name . |
34,362 | protected function resolveAction ( $ name ) { if ( isset ( $ this -> actions [ $ name ] ) ) { return $ this -> factory -> make ( $ this -> actions [ $ name ] ) ; } throw new \ InvalidArgumentException ( "Named action '$name' could not be found." ) ; } | Resolve an action instance by name . |
34,363 | public function registerAutoPresenterMapper ( Container $ app ) { $ app -> singleton ( 'autopresentermapper' , function ( ) { return new AutoPresenterMapper ( ) ; } ) ; $ autoPresenter = $ app -> make ( 'autopresenter' ) ; $ autoPresenter -> register ( new MapperDecorator ( $ autoPresenter , $ this -> app -> make ( 'autopresentermapper' ) , $ this -> app ) ) ; } | Register the Mapper decorator . |
34,364 | protected function getRequestXml ( ) { $ serviceXmlNode = "<" . $ this -> getServiceName ( ) . "/>" ; $ xml = new \ SimpleXMLElement ( '<?xml version="1.0" encoding="UTF-8"?>' . $ serviceXmlNode ) ; $ xml -> addAttribute ( 'version' , $ this -> getServiceVersion ( ) ) ; $ bodyChild = $ xml -> addChild ( 'body' ) ; $ bodyChild -> addAttribute ( 'merchantId' , $ this -> getMerchantId ( ) ) ; $ transactionChild = $ bodyChild -> addChild ( 'transaction' ) ; $ transactionChild -> addAttribute ( 'refno' , $ this -> getTransactionId ( ) ) ; $ requestChild = $ transactionChild -> addChild ( 'request' ) ; $ this -> prepareRequestXml ( $ requestChild ) ; $ requestChild -> addChild ( 'sign' , $ this -> getSign ( ) ) ; return $ xml ; } | Generate XML for request |
34,365 | public function isApiEnabledForUser ( User $ user ) { $ roles = $ user -> roles -> pluck ( 'id' ) -> toArray ( ) ; return ! count ( $ roles ) ? false : $ this -> newQuery ( ) -> whereIn ( 'role_id' , array_values ( $ roles ) ) -> where ( 'enabled' , 1 ) -> get ( ) -> count ( ) > 0 ; } | whether user role has enabled api support |
34,366 | private function createSerializer ( ) { return SerializerBuilder :: create ( ) -> setPropertyNamingStrategy ( new IdenticalPropertyNamingStrategy ( ) ) -> configureListeners ( function ( EventDispatcher $ dispatcher ) { $ dispatcher -> addListener ( 'serializer.post_deserialize' , function ( ObjectEvent $ event ) { $ object = $ event -> getObject ( ) ; if ( $ object instanceof ClientAwareInterface ) { $ object -> setClient ( $ this ) ; } } ) ; $ dispatcher -> addListener ( 'serializer.post_serialize' , function ( ObjectEvent $ event ) { $ options = $ event -> getContext ( ) -> attributes -> get ( 'options' ) -> getOrElse ( array ( ) ) ; $ visitor = $ event -> getVisitor ( ) ; if ( $ visitor instanceof GenericSerializationVisitor ) { foreach ( $ options as $ key => $ value ) { $ visitor -> addData ( $ key , $ value ) ; } } } ) ; } ) -> build ( ) ; } | Creates a serializer . |
34,367 | public function setMethod ( $ method ) { if ( empty ( $ method ) || ! is_string ( $ method ) ) throw new InvalidArgumentException ( "Invalid RPC method" ) ; $ this -> method = $ method ; return $ this ; } | Set rpc method |
34,368 | public function setSpecialType ( & $ value , $ type ) { $ type = strtolower ( $ type ) ; if ( empty ( $ value ) || ! in_array ( $ type , self :: $ supported_special_types ) ) { throw new InvalidArgumentException ( "Invalid value type" ) ; } $ this -> special_types [ $ value ] = $ type ; return $ this ; } | Set values as special type |
34,369 | public function setId ( $ id = null ) { if ( $ id === null || is_bool ( $ id ) || ( is_int ( $ id ) && $ id > 0 ) || ( is_string ( $ id ) && ! empty ( $ id ) ) ) { $ this -> id = $ id ; } else { throw new InvalidArgumentException ( "Invalid RPC id" ) ; } return $ this ; } | Set request s id |
34,370 | public function toArray ( ) { return [ 'uid' => $ this -> uid , 'method' => $ this -> method , 'parameters' => $ this -> parameters , 'special_types' => $ this -> special_types , 'id' => $ this -> id ] ; } | Export request as an array |
34,371 | public function create ( $ LinodeID , $ Label , $ KernelID , $ DiskList , $ RunLevel = null , $ RAMLimit = null , $ virt_mode = null , $ RootDeviceNum = null , $ RootDeviceCustom = null , $ RootDeviceRO = null , $ devtmpfs_automount = null , $ helper_distro = null , $ helper_xen = null , $ helper_disableUpdateDB = null , $ helper_depmod = null , $ helper_network = null , $ Comments = null ) { return $ this -> call ( 'linode.config.create' , [ 'LinodeID' => $ LinodeID , 'Label' => $ Label , 'KernelID' => $ KernelID , 'DiskList' => $ DiskList , 'RunLevel' => $ RunLevel , 'RAMLimit' => $ RAMLimit , 'virt_mode' => $ virt_mode , 'RootDeviceNum' => $ RootDeviceNum , 'RootDeviceCustom' => $ RootDeviceCustom , 'RootDeviceRO' => $ RootDeviceRO , 'devtmpfs_automount' => $ devtmpfs_automount , 'helper_distro' => $ helper_distro , 'helper_xen' => $ helper_xen , 'helper_disableUpdateDB' => $ helper_disableUpdateDB , 'helper_depmod' => $ helper_depmod , 'helper_network' => $ helper_network , 'Comments' => $ Comments , ] ) ; } | Creates a Linode Configuration Profile . |
34,372 | public function setConfigurationValue ( $ key , $ value ) { $ completeConfiguration = $ this -> getConfiguration ( ) ; $ configuration = & $ completeConfiguration ; $ pathParts = explode ( self :: DELIMITER , $ key ) ; foreach ( $ pathParts as $ pathPart ) { if ( is_array ( $ configuration ) === false ) { $ configuration = [ ] ; } $ configuration = & $ configuration [ ucfirst ( $ pathPart ) ] ; } $ configuration = $ value ; $ this -> setConfiguration ( $ completeConfiguration ) ; } | Sets a single configuration value |
34,373 | public function getConfigurationValue ( $ key ) { $ configuration = $ this -> getConfiguration ( ) ; $ pathParts = explode ( self :: DELIMITER , $ key ) ; foreach ( $ pathParts as $ pathPart ) { if ( isset ( $ configuration [ ucfirst ( $ pathPart ) ] ) === true ) { $ configuration = $ configuration [ ucfirst ( $ pathPart ) ] ; } else { $ configuration = null ; } } return $ configuration ; } | Returns a single configuration value |
34,374 | public function hasConfigurationKey ( $ key ) { $ result = true ; $ configuration = $ this -> getConfiguration ( ) ; $ pathParts = explode ( self :: DELIMITER , $ key ) ; foreach ( $ pathParts as $ pathPart ) { if ( array_key_exists ( ucfirst ( $ pathPart ) , $ configuration ) === false ) { $ result = false ; break ; } else { $ configuration = $ configuration [ ucfirst ( $ pathPart ) ] ; } } return $ result ; } | Checks if the configuration got the incoming key |
34,375 | public function init ( ) { $ json = [ ] ; foreach ( $ this -> dataset as $ file ) { if ( ! ( is_file ( $ file ) && is_readable ( $ file ) ) ) { throw new Exception ( "File '$file' for dataset not readable." ) ; } $ content = file_get_contents ( $ file ) ; $ key = pathinfo ( $ file , PATHINFO_FILENAME ) ; $ json [ $ key ] = json_decode ( $ content , true ) ; } $ this -> session -> set ( self :: KEY , $ json ) ; return $ this ; } | Fill the session with default data that are read from files . |
34,376 | public function getItem ( $ key , $ itemId ) { $ dataset = $ this -> getDataset ( $ key ) ; foreach ( $ dataset as $ item ) { if ( $ item [ "id" ] === $ itemId ) { return $ item ; } } return null ; } | Get an item from a dataset . |
34,377 | public function addItem ( $ key , $ item ) { $ dataset = $ this -> getDataset ( $ key ) ; $ max = 0 ; foreach ( $ dataset as $ val ) { if ( $ max < $ val [ "id" ] ) { $ max = $ val [ "id" ] ; } } $ item [ "id" ] = $ max + 1 ; $ dataset [ ] = $ item ; $ this -> saveDataset ( $ key , $ dataset ) ; return $ item ; } | Add an item to a dataset . |
34,378 | public static function create ( $ typeName , $ values ) { $ db = static :: getDb ( ) ; $ quotedValues = array_map ( [ $ db , 'quoteValue' ] , $ values ) ; return static :: getDb ( ) -> createCommand ( 'CREATE TYPE ' . $ db -> quoteColumnName ( $ typeName ) . ' AS ENUM (' . implode ( ',' , $ quotedValues ) . ')' ) -> execute ( ) ; } | Create an enum type |
34,379 | public static function add ( $ typeName , $ values , $ before = null ) { $ values = ( array ) $ values ; $ db = static :: getDb ( ) ; if ( $ db -> getTransaction ( ) ) { $ db = static :: newConnection ( ) ; } $ query = 'ALTER TYPE ' . $ db -> quoteColumnName ( $ typeName ) . ' ADD VALUE IF NOT EXISTS ' ; $ beforeQuery = $ before !== null ? ' BEFORE ' . $ db -> quoteValue ( $ before ) : '' ; foreach ( $ values as $ value ) { $ db -> createCommand ( $ query . $ db -> quoteValue ( $ value ) . $ beforeQuery ) -> execute ( ) ; } } | Add a value to an enum type |
34,380 | public static function values ( $ typeName ) { $ db = static :: getDb ( ) ; return $ db -> createCommand ( 'SELECT unnest(enum_range(NULL::' . $ db -> quoteColumnName ( $ typeName ) . '))' ) -> queryColumn ( ) ; } | Get values of an enum type |
34,381 | public static function exists ( $ typeName ) { $ db = static :: getDb ( ) ; return $ db -> createCommand ( 'SELECT EXISTS (' . 'SELECT 1 ' . 'FROM ' . $ db -> quoteTableName ( 'pg_type' ) . ' WHERE typname = ' . $ db -> quoteValue ( $ typeName ) . ')' ) -> queryScalar ( ) ; } | Check if an enum type exists |
34,382 | public static function remove ( $ typeName , $ values , $ updateTables = false ) { $ values = ( array ) $ values ; $ db = static :: getDb ( ) ; $ transaction = $ db -> beginTransaction ( ) ; try { $ allValues = static :: values ( $ typeName ) ; $ removedValues = [ ] ; $ isAssociative = ArrayHelper :: isAssociative ( $ values , false ) ; if ( $ isAssociative ) { $ caseQuery = '' ; $ placeholders = [ ] ; $ phIndex = 0 ; foreach ( $ values as $ k => $ v ) { $ ph1 = 'case' . $ phIndex ++ ; $ ph2 = 'case' . $ phIndex ++ ; if ( is_int ( $ k ) ) { $ removedValues [ ] = $ v ; } else { $ removedValues [ ] = $ k ; $ placeholders [ $ ph1 ] = $ k ; $ placeholders [ $ ph2 ] = $ v ; if ( ! in_array ( $ v , $ allValues ) ) { static :: add ( $ typeName , $ v ) ; $ allValues [ ] = $ v ; } $ caseQuery .= ' WHEN :' . $ ph1 . ' THEN :' . $ ph2 ; } } $ caseQuery .= ' ELSE NULL END::' . $ db -> quoteColumnName ( $ typeName ) ; } else { $ removedValues = $ values ; } if ( $ updateTables ) { $ columns = static :: columns ( $ typeName ) ; foreach ( $ columns as $ column ) { $ columnName = $ column [ 'column_name' ] ; $ value = $ isAssociative ? new Expression ( 'CASE ' . $ db -> quoteColumnName ( $ columnName ) . $ caseQuery , $ placeholders ) : null ; $ db -> createCommand ( ) -> update ( $ column [ 'table_name' ] , [ $ columnName => $ value ] , [ $ columnName => $ removedValues ] ) -> execute ( ) ; } } static :: recreate ( $ typeName , array_diff ( $ allValues , $ removedValues ) ) ; $ transaction -> commit ( ) ; } catch ( \ Exception $ e ) { $ transaction -> rollBack ( ) ; throw $ e ; } } | Remove values from an enum type |
34,383 | public static function rename ( $ oldTypeName , $ newTypeName ) { $ db = static :: getDb ( ) ; return $ db -> createCommand ( 'ALTER TYPE ' . $ db -> quoteColumnName ( $ oldTypeName ) . ' RENAME TO ' . $ db -> quoteColumnName ( $ newTypeName ) ) -> execute ( ) ; } | Rename an enum type |
34,384 | public static function renameValue ( $ typeName , $ value , $ newValue ) { $ db = static :: getDb ( ) ; return $ db -> createCommand ( 'ALTER TYPE ' . $ db -> quoteColumnName ( $ typeName ) . ' RENAME VALUE ' . $ db -> quoteValue ( $ value ) . ' TO ' . $ db -> quoteValue ( $ newValue ) ) -> execute ( ) ; } | Rename an enum value |
34,385 | public static function recreate ( $ typeName , $ values ) { $ db = static :: getDb ( ) ; $ quotedType = $ db -> quoteColumnName ( $ typeName ) ; $ transaction = $ db -> beginTransaction ( ) ; try { $ columns = static :: columns ( $ typeName ) ; do { $ tmpTypeName = md5 ( rand ( ) ) ; } while ( static :: exists ( $ tmpTypeName ) ) ; static :: rename ( $ typeName , $ tmpTypeName ) ; static :: create ( $ typeName , $ values ) ; $ schema = $ db -> getSchema ( ) ; foreach ( $ columns as $ column ) { $ quotedColumn = $ db -> quoteColumnName ( $ column [ 'column_name' ] ) ; $ db -> createCommand ( 'ALTER TABLE ' . $ db -> quoteTableName ( $ column [ 'table_name' ] ) . ' ALTER ' . $ quotedColumn . ' TYPE ' . $ quotedType . ' USING ' . $ quotedColumn . '::text::' . $ quotedType ) -> execute ( ) ; $ schema -> refreshTableSchema ( $ column [ 'table_name' ] ) ; } static :: drop ( $ tmpTypeName ) ; $ transaction -> commit ( ) ; } catch ( \ Exception $ e ) { $ transaction -> rollBack ( ) ; throw $ e ; } } | Try to recreate an enum type with new values |
34,386 | public static function drop ( $ typeName , $ cascade = false ) { $ db = static :: getDb ( ) ; return $ db -> createCommand ( 'DROP TYPE IF EXISTS ' . $ db -> quoteColumnName ( $ typeName ) . ( $ cascade ? ' CASCADE' : '' ) ) -> execute ( ) ; } | Drop an enum type |
34,387 | protected static function newConnection ( ) { static $ newDb ; if ( $ newDb === null ) { $ db = static :: getDb ( ) ; $ className = get_class ( $ db ) ; $ newDb = new $ className ; $ class = new \ ReflectionClass ( $ db ) ; foreach ( $ class -> getProperties ( \ ReflectionProperty :: IS_PUBLIC ) as $ property ) { if ( ! $ property -> isStatic ( ) ) { $ name = $ property -> getName ( ) ; $ newDb -> $ name = $ db -> $ name ; } } $ newDb -> pdo = null ; } return $ newDb ; } | Create new DB connection like the current connection |
34,388 | public function getRelationData ( Model $ model ) { $ relations = $ this -> getRelations ( $ model ) ; if ( empty ( $ relations ) ) { return [ ] ; } $ return = [ ] ; foreach ( $ this -> properties as $ name => $ details ) { try { $ related = $ model -> { $ name } ; if ( ! is_object ( $ model -> $ name ( ) ) ) { continue ; } } catch ( Exception $ ex ) { continue ; } if ( is_null ( $ related ) ) { $ related = $ model -> $ name ( ) -> getModel ( ) ; array_set ( $ return , $ name , [ get_class ( $ related ) => $ related -> getFillable ( ) ] ) ; } if ( ! is_null ( $ related ) && method_exists ( $ related , 'getAttributes' ) ) { array_set ( $ return , $ name , [ get_class ( $ related ) => $ related -> getAttributes ( ) ] ) ; } } return $ return ; } | Gets prepared data from related model |
34,389 | public function purge ( ) { if ( ! isset ( $ this -> actions [ 'purge' ] ) ) { throw new InvalidActionException ( sprintf ( 'Impossible to purge the container "%s" (current state "%s").' , $ this -> id , $ this -> state ) ) ; } $ this -> client -> post ( $ this -> actions [ 'purge' ] ) ; } | Purges the container . |
34,390 | public function setImageUuid ( $ imageUuid ) { if ( 'docker:' !== substr ( $ imageUuid , 0 , 7 ) ) { $ imageUuid = 'docker:' . $ imageUuid ; } $ this -> imageUuid = $ imageUuid ; return $ this ; } | Sets the UUID image . |
34,391 | public function stop ( $ remove = false , $ timeout = 0 ) { if ( ! isset ( $ this -> actions [ 'stop' ] ) ) { throw new InvalidActionException ( sprintf ( 'Impossible to stop the container "%s" (current state "%s").' , $ this -> id , $ this -> state ) ) ; } $ this -> client -> post ( $ this -> actions [ 'stop' ] , array ( 'remove' => $ remove , 'timeout' => $ timeout ) ) ; } | Stops a container . |
34,392 | public function prepend ( ContainerBuilder $ container ) { $ bundles = $ container -> getParameter ( 'kernel.bundles' ) ; if ( isset ( $ bundles [ 'DoctrineBundle' ] ) ) { $ mappingConfig = [ 'orm' => [ 'entity_managers' => [ 'default' => [ 'mappings' => [ 'HMLBDDDBundle' => [ 'mapping' => true , 'type' => 'xml' , 'dir' => __DIR__ . '/../Resources/config/doctrine' , 'prefix' => 'HMLB\DDD' , 'is_bundle' => false , ] , ] , ] , ] , ] , ] ; $ container -> getExtension ( 'doctrine' ) ; $ container -> prependExtensionConfig ( 'doctrine' , $ mappingConfig ) ; } $ container -> prependExtensionConfig ( 'command_bus' , [ 'command_name_resolver_strategy' => 'named_message' , ] ) ; $ container -> prependExtensionConfig ( 'event_bus' , [ 'event_name_resolver_strategy' => 'named_message' , ] ) ; } | We add mapping information for our Messages Classes . |
34,393 | protected function __afterInsert ( \ Owl \ DataMapper \ Data $ data ) { $ policy = $ this -> getCachePolicy ( ) ; $ id = $ data -> id ( true ) ; if ( $ policy [ 'insert' ] ) { $ record = $ this -> unpack ( $ data ) ; $ record = $ this -> removeNullValues ( $ record ) ; $ this -> saveCache ( $ id , $ record ) ; } elseif ( $ policy [ 'not_found' ] ) { $ this -> deleteCache ( $ id ) ; } parent :: __afterInsert ( $ data ) ; } | create cache after save new data if cache policy set . |
34,394 | protected function __afterDelete ( \ Owl \ DataMapper \ Data $ data ) { $ this -> deleteCache ( $ data -> id ( true ) ) ; parent :: __afterDelete ( $ data ) ; } | delete cache after delete data . |
34,395 | protected function doFind ( array $ id , \ Owl \ Service $ service = null , $ collection = null ) { if ( $ record = $ this -> getCache ( $ id ) ) { return isset ( $ record [ '__IS_NOT_FOUND__' ] ) ? false : $ record ; } if ( $ record = parent :: doFind ( $ id , $ service , $ collection ) ) { $ record = $ this -> removeNullValues ( $ record ) ; $ this -> saveCache ( $ id , $ record ) ; } else { $ policy = $ this -> getCachePolicy ( ) ; if ( $ ttl = $ policy [ 'not_found' ] ) { $ ttl = is_numeric ( $ ttl ) ? ( int ) $ ttl : null ; $ this -> saveCache ( $ id , [ '__IS_NOT_FOUND__' => 1 ] , $ ttl ) ; } } return $ record ; } | return record from cache if cache is created or save data into cache . |
34,396 | private function removeNullValues ( array $ record ) { foreach ( $ record as $ key => $ val ) { if ( $ val === null ) { unset ( $ record [ $ key ] ) ; } } return $ record ; } | remove NULL value from record . |
34,397 | public function registerClientScript ( ) { $ view = $ this -> getView ( ) ; PNotifyAsset :: register ( $ view ) ; $ options = empty ( $ this -> pluginOptions ) ? '' : Json :: encode ( $ this -> pluginOptions ) ; $ js = "new PNotify(" . $ options . ");" ; $ view -> registerJs ( $ js ) ; } | Register js initialization script . |
34,398 | static public function registerStack ( $ stacks , $ view ) { if ( ! is_array ( $ stacks ) ) { throw new InvalidConfigException ( 'The $stacks argument should be provided as an array' ) ; } if ( ! $ view instanceof yii \ web \ View ) { throw new InvalidConfigException ( 'The $view argument should be provided as a yii\web\View' ) ; } foreach ( $ stacks as $ name => $ definition ) { $ view -> registerJs ( 'var ' . $ name . ' = ' . Json :: encode ( $ definition ) . ';' ) ; } } | Register a set of stacks so they are available to PNotify widgets . |
34,399 | public function registerType ( $ typeName , $ className ) { if ( isset ( $ this -> bindings [ $ typeName ] ) ) { throw new \ InvalidArgumentException ( "`$typeName` is already registerd." ) ; } $ type = new \ ReflectionClass ( $ typeName ) ; $ class = new \ ReflectionClass ( $ className ) ; $ this -> bindings [ $ typeName ] = new Service ( $ type , $ class ) ; return $ this ; } | Registers the type and class to resolve the dependent . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.