idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
50,800
public function sendData ( $ data ) { $ httpResponse = $ this -> sendRequest ( $ data ) ; $ responseClass = $ this -> getResponseClassName ( ) ; return $ this -> response = new $ responseClass ( $ this , $ httpResponse ) ; }
Send the request to the API then build the response object
50,801
protected function getArgumentPath ( $ withName = false ) { $ name = $ this -> argumentName ( ) ; if ( str_contains ( $ name , '.' ) ) { $ name = str_replace ( '.' , '/' , $ name ) ; } if ( str_contains ( $ name , '\\' ) ) { $ name = str_replace ( '\\' , '/' , $ name ) ; } $ name = implode ( '/' , array_map ( 'ucfirst' , explode ( '/' , $ name ) ) ) ; if ( $ this -> settingsDirectoryFormat ( ) === 'strtolower' ) { $ name = implode ( '/' , array_map ( 'strtolower' , explode ( '/' , $ name ) ) ) ; } if ( $ withName ) { return $ name . '/' ; } if ( str_contains ( $ name , '/' ) ) { return substr ( $ name , 0 , strripos ( $ name , '/' ) + 1 ) ; } return '' ; }
Return the path of the file
50,802
protected function getResourceName ( $ name , $ format = true ) { if ( $ name && $ format === false ) { return $ name ; } $ name = isset ( $ name ) ? $ name : $ this -> resource ; $ this -> resource = lcfirst ( str_singular ( class_basename ( $ name ) ) ) ; $ this -> resourceLowerCase = strtolower ( $ name ) ; return $ this -> resource ; }
Get the resource name
50,803
protected function getModelName ( $ name = null ) { $ name = isset ( $ name ) ? $ name : $ this -> resource ; return str_singular ( ucwords ( camel_case ( class_basename ( $ name ) ) ) ) ; }
Get the name for the model
50,804
protected function getSeedName ( $ name = null ) { return ucwords ( camel_case ( str_replace ( $ this -> settings [ 'postfix' ] , '' , $ this -> getResourceName ( $ name ) ) ) ) ; }
Get the name for the seed
50,805
protected function getCollectionUpperName ( $ name = null ) { $ name = str_plural ( $ this -> getResourceName ( $ name ) ) ; $ pieces = explode ( '_' , $ name ) ; $ name = "" ; foreach ( $ pieces as $ k => $ str ) { $ name .= ucfirst ( $ str ) ; } return $ name ; }
Get the plural uppercase name of the resouce
50,806
protected function getContractName ( $ name = null ) { $ name = isset ( $ name ) ? $ name : $ this -> resource ; $ name = str_singular ( ucwords ( camel_case ( class_basename ( $ name ) ) ) ) ; return $ name . config ( 'generators.settings.contract.postfix' ) ; }
Get the name of the contract
50,807
protected function getContractNamespace ( $ withApp = true ) { $ path = config ( 'generators.settings.contract.namespace' ) . '\\' ; $ path .= str_replace ( '/' , '\\' , $ this -> getArgumentPath ( ) ) ; $ pieces = array_map ( 'ucfirst' , explode ( '/' , $ path ) ) ; $ namespace = ( $ withApp === true ? $ this -> getAppNamespace ( ) : '' ) . implode ( '\\' , $ pieces ) ; $ namespace = rtrim ( ltrim ( str_replace ( '\\\\' , '\\' , $ namespace ) , '\\' ) , '\\' ) ; return $ namespace ; }
Get the namespace of where contract was created
50,808
protected function getViewPath ( $ name ) { $ pieces = explode ( '/' , $ name ) ; foreach ( $ pieces as $ k => $ value ) { if ( ! in_array ( $ value , config ( 'generators.reserve_words' ) ) ) { $ pieces [ $ k ] = str_plural ( snake_case ( $ pieces [ $ k ] ) ) ; } } $ name = implode ( '.' , $ pieces ) ; return strtolower ( rtrim ( ltrim ( $ name , '.' ) , '.' ) ) ; }
Get the path to the view file
50,809
protected function getViewPathFormatted ( $ name ) { $ path = $ this -> getViewPath ( $ name ) ; if ( strpos ( $ path , 'admin.' ) === 0 ) { $ path = substr ( $ path , 6 ) ; } if ( strpos ( $ path , 'admins.' ) === 0 ) { $ path = substr ( $ path , 7 ) ; } if ( strpos ( $ path , 'website.' ) === 0 ) { $ path = substr ( $ path , 8 ) ; } if ( strpos ( $ path , 'websites.' ) === 0 ) { $ path = substr ( $ path , 9 ) ; } return $ path ; }
Remove admin and webiste if first in path The Base Controller has it as a prefix path
50,810
protected function getOptionStubKey ( ) { $ plain = $ this -> option ( 'plain' ) ; $ stub = $ this -> option ( 'stub' ) . ( $ plain ? '_plain' : '' ) . '_stub' ; if ( is_null ( $ this -> option ( 'stub' ) ) ) { $ stub = $ this -> option ( 'type' ) . ( $ plain ? '_plain' : '' ) . '_stub' ; } return $ stub ; }
Get the key where the stub is located
50,811
public function getMessage ( ) { $ httpMessage = parent :: getMessage ( ) ; if ( $ httpMessage !== null ) { return $ httpMessage ; } if ( ! $ this -> isSuccessful ( ) && isset ( $ this -> data [ 'paymentStatusReason' ] ) ) { return $ this -> data [ 'paymentStatusReason' ] ; } if ( isset ( $ this -> data [ 'paymentStatus' ] ) ) { return $ this -> data [ 'paymentStatus' ] ; } }
What is the relevant description of the transaction response?
50,812
public function sortedSet ( ) : self { $ obj = clone $ this ; usort ( $ obj -> _elements , function ( Element $ a , Element $ b ) { if ( $ a -> typeClass ( ) != $ b -> typeClass ( ) ) { return $ a -> typeClass ( ) < $ b -> typeClass ( ) ? - 1 : 1 ; } if ( $ a -> tag ( ) == $ b -> tag ( ) ) { return 0 ; } return $ a -> tag ( ) < $ b -> tag ( ) ? - 1 : 1 ; } ) ; return $ obj ; }
Sort by canonical ascending order . Used for DER encoding of SET type .
50,813
public function sortedSetOf ( ) : self { $ obj = clone $ this ; usort ( $ obj -> _elements , function ( Element $ a , Element $ b ) { $ a_der = $ a -> toDER ( ) ; $ b_der = $ b -> toDER ( ) ; return strcmp ( $ a_der , $ b_der ) ; } ) ; return $ obj ; }
Sort by encoding ascending order . Used for DER encoding of SET OF type .
50,814
protected static function _explodeDottedOID ( string $ oid ) : array { $ subids = [ ] ; if ( strlen ( $ oid ) ) { foreach ( explode ( "." , $ oid ) as $ subid ) { $ n = @ gmp_init ( $ subid , 10 ) ; if ( false === $ n ) { throw new \ UnexpectedValueException ( "'$subid' is not a number." ) ; } $ subids [ ] = $ n ; } } return $ subids ; }
Explode dotted OID to an array of sub ID s .
50,815
protected static function _implodeSubIDs ( \ GMP ... $ subids ) : string { return implode ( "." , array_map ( function ( $ num ) { return gmp_strval ( $ num , 10 ) ; } , $ subids ) ) ; }
Implode an array of sub IDs to dotted OID format .
50,816
protected static function _encodeSubIDs ( \ GMP ... $ subids ) : string { $ data = "" ; foreach ( $ subids as $ subid ) { if ( $ subid < 128 ) { $ data .= chr ( intval ( $ subid ) ) ; } else { $ bytes = [ ] ; do { array_unshift ( $ bytes , 0x7f & gmp_intval ( $ subid ) ) ; $ subid >>= 7 ; } while ( $ subid > 0 ) ; foreach ( array_splice ( $ bytes , 0 , - 1 ) as $ byte ) { $ data .= chr ( 0x80 | $ byte ) ; } $ data .= chr ( reset ( $ bytes ) ) ; } } return $ data ; }
Encode sub ID s to DER .
50,817
protected static function _decodeSubIDs ( string $ data ) : array { $ subids = [ ] ; $ idx = 0 ; $ end = strlen ( $ data ) ; while ( $ idx < $ end ) { $ num = gmp_init ( "0" , 10 ) ; while ( true ) { if ( $ idx >= $ end ) { throw new DecodeException ( "Unexpected end of data." ) ; } $ byte = ord ( $ data [ $ idx ++ ] ) ; $ num |= $ byte & 0x7f ; if ( ! ( $ byte & 0x80 ) ) { break ; } $ num <<= 7 ; } $ subids [ ] = $ num ; } return $ subids ; }
Decode sub ID s from DER data .
50,818
public function replaceImageSize ( $ message , $ attribute , $ rule , $ parameters ) { $ width = $ height = $ this -> checkDimension ( $ parameters [ 0 ] ) ; if ( isset ( $ parameters [ 1 ] ) ) { $ height = $ this -> checkDimension ( $ parameters [ 1 ] ) ; } return str_replace ( [ ':width' , ':height' ] , [ $ width [ 'message' ] , $ height [ 'message' ] ] , $ message ) ; }
Build the error message for validation failures .
50,819
protected function checkDimension ( $ rule , $ dimension = 0 ) { $ dimension = ( int ) $ dimension ; if ( $ rule === '*' ) { $ message = $ this -> translator -> trans ( 'image-validator::validation.anysize' ) ; $ pass = true ; } else if ( preg_match ( '/^(\d+)\-(\d+)$/' , $ rule , $ matches ) ) { $ size1 = ( int ) $ matches [ 1 ] ; $ size2 = ( int ) $ matches [ 2 ] ; $ message = $ this -> translator -> trans ( 'image-validator::validation.between' , compact ( 'size1' , 'size2' ) ) ; $ pass = ( $ dimension >= $ size1 ) && ( $ dimension <= $ size2 ) ; } else if ( preg_match ( '/^([<=>]*)(\d+)$/' , $ rule , $ matches ) ) { $ size = ( int ) $ matches [ 2 ] ; switch ( $ matches [ 1 ] ) { case '>' : $ message = $ this -> translator -> trans ( 'image-validator::validation.greaterthan' , compact ( 'size' ) ) ; $ pass = $ dimension > $ size ; break ; case '>=' : $ message = $ this -> translator -> trans ( 'image-validator::validation.greaterthanorequal' , compact ( 'size' ) ) ; $ pass = $ dimension >= $ size ; break ; case '<' : $ message = $ this -> translator -> trans ( 'image-validator::validation.lessthan' , compact ( 'size' ) ) ; $ pass = $ dimension < $ size ; break ; case '<=' : $ message = $ this -> translator -> trans ( 'image-validator::validation.lessthanorequal' , compact ( 'size' ) ) ; $ pass = $ dimension <= $ size ; break ; case '=' : case '' : $ message = $ this -> translator -> trans ( 'image-validator::validation.equal' , compact ( 'size' ) ) ; $ pass = $ dimension == $ size ; break ; default : throw new RuntimeException ( 'Unknown image size validation rule: ' . $ rule ) ; } } else { throw new RuntimeException ( 'Unknown image size validation rule: ' . $ rule ) ; } return compact ( 'message' , 'pass' ) ; }
Parse the dimension rule and check if the dimension passes the rule .
50,820
public static function fromString ( string $ time , string $ tz = null ) : self { try { if ( ! isset ( $ tz ) ) { $ tz = date_default_timezone_get ( ) ; } return new static ( new \ DateTimeImmutable ( $ time , self :: _createTimeZone ( $ tz ) ) ) ; } catch ( \ Exception $ e ) { throw new \ RuntimeException ( "Failed to create DateTime: " . self :: _getLastDateTimeImmutableErrorsStr ( ) , 0 , $ e ) ; } }
Initialize from datetime string .
50,821
private static function _decimalToNR3 ( string $ str ) : string { if ( preg_match ( self :: PHP_EXPONENT_DNUM , $ str , $ match ) ) { $ parts = explode ( "." , $ match [ 1 ] ) ; $ m = ltrim ( $ parts [ 0 ] , "0" ) ; $ e = intval ( $ match [ 2 ] ) ; if ( count ( $ parts ) == 2 ) { $ d = rtrim ( $ parts [ 1 ] , "0" ) ; $ e -= strlen ( $ d ) ; $ m .= $ d ; } } else { $ parts = explode ( "." , $ str ) ; $ m = ltrim ( $ parts [ 0 ] , "0" ) ; if ( count ( $ parts ) == 2 ) { $ e = - strlen ( $ parts [ 1 ] ) ; $ m .= $ parts [ 1 ] ; } else { $ e = 0 ; } while ( substr ( $ m , - 1 ) === "0" ) { $ e ++ ; $ m = substr ( $ m , 0 , - 1 ) ; } } if ( 0 == $ e ) { $ es = "+" ; } else { $ es = $ e < 0 ? "-" : "" ; } return sprintf ( "%s.E%s%d" , $ m , $ es , abs ( $ e ) ) ; }
Convert decimal number string to NR3 form .
50,822
private static function _nr3ToDecimal ( string $ str ) : float { if ( ! preg_match ( self :: NR3_REGEX , $ str , $ match ) ) { throw new \ UnexpectedValueException ( "'$str' is not a valid NR3 form real." ) ; } $ m = $ match [ 2 ] ; $ inv = $ match [ 1 ] == "-" ; $ e = intval ( $ match [ 3 ] ) ; if ( $ e > 0 ) { $ num = $ m . str_repeat ( "0" , $ e ) ; } else if ( $ e < 0 ) { if ( strlen ( $ m ) < abs ( $ e ) ) { $ m = str_repeat ( "0" , abs ( $ e ) - strlen ( $ m ) ) . $ m ; } $ num = substr ( $ m , 0 , $ e ) . "." . substr ( $ m , $ e ) ; } else { $ num = empty ( $ m ) ? "0" : $ m ; } if ( $ inv ) { $ num = "-$num" ; } return floatval ( $ num ) ; }
Convert NR3 form number to decimal .
50,823
public function compress ( $ filename , $ content ) { $ this -> addFile ( $ content , $ filename ) ; $ zip = $ this -> file ( ) ; $ this -> clear ( ) ; return $ zip ; }
Comprime el contenido del archivo con el nombre especifico y retorna el contenido del zip .
50,824
protected function getSortedTableNames ( ) { $ tables = [ strtolower ( $ this -> argument ( 'tableOne' ) ) , strtolower ( $ this -> argument ( 'tableTwo' ) ) ] ; sort ( $ tables ) ; return $ tables ; }
Sort the two tables in alphabetical order .
50,825
public function addRelationshipsInParents ( ) { $ options = config ( 'generators.settings' ) ; if ( ! $ options [ 'model' ] ) { $ this -> info ( 'Model files not found.' ) ; return ; } $ modelSettings = $ options [ 'model' ] ; $ modelOne = $ this -> getModelName ( $ this -> argument ( 'tableOne' ) ) ; $ modelTwo = $ this -> getModelName ( $ this -> argument ( 'tableTwo' ) ) ; $ modelOnePath = $ modelSettings [ 'path' ] . $ modelOne . '.php' ; $ modelTwoPath = $ modelSettings [ 'path' ] . $ modelTwo . '.php' ; $ this -> addRelationshipInModel ( $ modelOnePath , $ modelTwo , $ this -> argument ( 'tableTwo' ) ) ; $ this -> addRelationshipInModel ( $ modelTwoPath , $ modelOne , $ this -> argument ( 'tableOne' ) ) ; }
Append Many to Many Relationships in Parent Models
50,826
private function addRelationshipInModel ( $ modelPath , $ relationshipModel , $ tableName ) { $ model = $ this -> files -> get ( $ modelPath ) ; $ index = strlen ( $ model ) - strpos ( strrev ( $ model ) , '}' ) - 1 ; $ stub = $ this -> files -> get ( config ( 'generators.' . 'many_many_relationship_stub' ) ) ; $ stub = str_replace ( '{{model}}' , $ relationshipModel , $ stub ) ; $ stub = str_replace ( '{{relationship}}' , camel_case ( $ tableName ) , $ stub ) ; $ model = substr_replace ( $ model , $ stub , $ index , 0 ) ; $ this -> files -> put ( $ modelPath , $ model ) ; $ this -> info ( "{$relationshipModel} many to many Relationship added in {$modelPath}" ) ; }
Insert the many to many relationship in model
50,827
public static function cleanFields ( $ fields ) { $ fields = parent :: cleanFields ( $ fields ) ; if ( ( '*' !== array_get ( $ fields , 0 ) ) && ! in_array ( 'private' , $ fields ) ) { $ fields [ ] = 'private' ; } return $ fields ; }
Removes unwanted fields from field list if supplied .
50,828
public function addPlugin ( Plugin $ plugin , $ key = null ) { if ( $ key ) { $ this -> plugins [ $ key ] = $ plugin ; } else { $ this -> plugins [ ] = $ plugin ; } $ plugin -> configure ( $ this ) ; return $ this ; }
Add a plugin
50,829
public function removePlugin ( $ key ) { if ( ! isset ( $ this -> plugins [ $ key ] ) ) { return $ this ; } if ( method_exists ( $ this -> plugins [ $ key ] , 'unconfigure' ) ) { $ this -> plugins [ $ key ] -> unconfigure ( $ this ) ; } unset ( $ this -> plugins [ $ key ] ) ; return $ this ; }
Remove a plugin and its events by the key
50,830
public function getPlugin ( $ key ) { return isset ( $ this -> plugins [ $ key ] ) ? $ this -> plugins [ $ key ] : null ; }
Get a plugin
50,831
public function on ( $ event , callable $ fn ) { if ( ! isset ( $ this -> events [ $ event ] ) ) { $ this -> events [ $ event ] = [ ] ; } $ this -> events [ $ event ] [ ] = $ fn ; return $ this ; }
Set an action to do on the specified event
50,832
public function un ( $ event , callable $ fn = null ) { if ( isset ( $ this -> events [ $ event ] ) ) { if ( $ fn ) { foreach ( $ this -> events [ $ event ] as $ k => $ ev ) { if ( $ ev === $ fn ) { unset ( $ this -> events [ $ event ] [ $ k ] ) ; break ; } } } else { unset ( $ this -> events [ $ event ] ) ; } } return $ this ; }
Remove an action setted for the specified event
50,833
public function trigger ( $ event , array $ args = [ ] , $ acceptReturn = false ) { if ( isset ( $ this -> events [ $ event ] ) ) { array_unshift ( $ args , $ this ) ; foreach ( $ this -> events [ $ event ] as $ fn ) { $ data = call_user_func_array ( $ fn , $ args ) ; if ( $ acceptReturn ) { if ( $ data !== null ) { return $ data ; } } elseif ( $ data === false ) { return false ; } } } }
Browse registered actions for this event
50,834
public function addColumn ( $ column , array $ definition ) { $ this -> columnDefinition [ $ column ] = array_merge ( [ 'isMultiLine' => false , 'isMultiLineHeader' => false , 'isImage' => false , 'renderer' => null , 'headerRenderer' => null , 'header' => '' , 'drawFn' => null , 'drawHeaderFn' => null , 'width' => 10 , 'height' => null , 'border' => 0 , 'ln' => false , 'align' => 'L' , 'fill' => false , 'link' => '' , 'stretch' => 0 , 'ignoreHeight' => false , 'calign' => 'T' , 'valign' => 'M' , 'x' => '' , 'y' => '' , 'reseth' => true , 'isHtml' => false , 'maxh' => null , 'autoPadding' => true , 'fitcell' => false , 'cellPadding' => '' ] , $ this -> defaultColumnDefinition , $ definition ) ; if ( $ this -> columnDefinition [ $ column ] [ 'height' ] === null ) { $ this -> columnDefinition [ $ column ] [ 'height' ] = $ this -> getColumnHeight ( ) ; } $ this -> trigger ( self :: EV_COLUMN_ADDED , [ $ column , $ this -> columnDefinition [ $ column ] ] ) ; return $ this ; }
Define a column . Config array is mostly what we find in \ TCPDF Cell and MultiCell .
50,835
public function setColumns ( array $ columns , $ add = false ) { if ( ! $ add ) { $ this -> columnDefinition = [ ] ; } foreach ( $ columns as $ key => $ def ) { $ this -> addColumn ( $ key , $ def ) ; } return $ this ; }
Add many columns in one shot
50,836
public function setColumnDefinition ( $ column , $ definition , $ value ) { $ this -> columnDefinition [ $ column ] [ $ definition ] = $ value ; return $ this ; }
Set a specific definition for a column like the value of border calign and so on
50,837
public function getColumnWidthBetween ( $ columnA , $ columnB ) { $ width = 0 ; $ check = false ; foreach ( $ this -> columnDefinition as $ key => $ def ) { if ( $ key == $ columnA || ! $ columnA ) { $ check = true ; } if ( ! $ columnA && $ key == $ columnB ) { break ; } if ( $ check ) { $ width += $ def [ 'width' ] ; } if ( $ key == $ columnB ) { break ; } } return $ width ; }
Get width between two columns . Widths of these columns are included in the sum .
50,838
public function setRowDefinition ( $ column , $ definition , $ value ) { if ( $ column === null ) { foreach ( $ this -> columnDefinition as $ key => $ v ) { $ this -> rowDefinition [ $ key ] [ $ definition ] = $ value ; } } else { $ this -> rowDefinition [ $ column ] [ $ definition ] = $ value ; } return $ this ; }
Set a custom configuration for one specific cell in the current row .
50,839
public function getCurrentRowHeight ( $ row ) { $ h = $ this -> getColumnHeight ( ) ; $ this -> setRowHeight ( $ h ) ; if ( ! isset ( $ this -> rowDefinition [ '_content' ] ) ) { $ this -> rowDefinition [ '_content' ] = [ ] ; } foreach ( $ this -> columnDefinition as $ key => $ def ) { $ h = $ def [ 'height' ] ; if ( $ h > $ this -> getRowHeight ( ) ) { $ this -> setRowHeight ( $ h ) ; } $ this -> rowDefinition [ '_content' ] [ $ key ] = $ h ; if ( ( ! isset ( $ row [ $ key ] ) && ! is_callable ( $ def [ 'renderer' ] ) && ! is_callable ( $ def [ 'drawFn' ] ) ) || ! $ def [ 'isMultiLine' ] ) { continue ; } $ data = $ this -> fetchDataByUserFunc ( $ def , isset ( $ row [ $ key ] ) ? $ row [ $ key ] : '' , $ key , $ row , false , true ) ; $ hd = $ this -> trigger ( self :: EV_CELL_HEIGHT_GET , [ $ key , $ data , $ row ] , true ) ; if ( $ hd === null ) { $ data_to_check = $ data ; if ( $ def [ 'isHtml' ] ) { $ data = str_replace ( [ "\n" , "\r" ] , '' , $ data ) ; $ data_to_check = strip_tags ( str_replace ( [ '<br>' , '<br/>' , '<br />' ] , PHP_EOL , $ data ) ) ; } $ nb = $ this -> pdf -> getNumLines ( $ data_to_check , $ def [ 'width' ] , $ def [ 'reseth' ] , $ def [ 'autoPadding' ] , $ def [ 'cellPadding' ] , $ def [ 'border' ] ) ; $ hd = $ nb * $ h ; $ this -> rowDefinition [ '_content' ] [ $ key ] = $ hd ; } if ( $ hd > $ this -> getRowHeight ( ) ) { $ this -> setRowHeight ( $ hd ) ; } } return $ this -> getRowHeight ( ) ; }
Browse all cells for this row to find which content has the max height . Then we can adapt the height of all the other cells of this line .
50,840
public function addHeader ( ) { $ height = $ this -> getRowHeight ( ) ; $ definition = $ this -> rowDefinition ; $ this -> copyDefaultColumnDefinitions ( null ) ; if ( $ this -> trigger ( self :: EV_HEADER_ADD ) !== false ) { foreach ( $ this -> columnDefinition as $ key => $ def ) { $ this -> addCell ( $ key , $ def [ 'header' ] , $ this -> columnDefinition , true ) ; } $ this -> trigger ( self :: EV_HEADER_ADDED ) ; } $ this -> setRowHeight ( $ height ) ; $ this -> rowDefinition = $ definition ; return $ this ; }
Add table headers
50,841
public function addBody ( $ rows , callable $ fn = null ) { end ( $ this -> columnDefinition ) ; $ this -> columnDefinition [ key ( $ this -> columnDefinition ) ] [ 'ln' ] = true ; $ auto_pb = $ this -> pdf -> getAutoPageBreak ( ) ; $ bmargin = $ this -> pdf -> getMargins ( ) [ 'bottom' ] ; $ this -> pdf -> SetAutoPageBreak ( false , $ this -> bottomMargin ) ; if ( $ this -> trigger ( self :: EV_BODY_ADD , [ $ rows , $ fn ] ) === false ) { $ this -> trigger ( self :: EV_BODY_SKIPPED , [ $ rows ] ) ; $ this -> endBody ( $ auto_pb , $ bmargin ) ; return $ this ; } if ( $ this -> showHeader ) { $ this -> addHeader ( ) ; } foreach ( $ rows as $ index => $ row ) { $ data = $ fn ? $ fn ( $ this , $ row , $ index , false ) : $ row ; if ( is_array ( $ data ) || is_object ( $ data ) ) { $ this -> addRow ( $ data , $ index ) ; } else { $ this -> trigger ( self :: EV_ROW_SKIPPED , [ $ row , $ index ] ) ; } } $ this -> trigger ( self :: EV_BODY_ADDED , [ $ rows ] ) ; $ this -> endBody ( $ auto_pb , $ bmargin ) ; return $ this ; }
Add content to the table . It launches events at start and end if we need to add some custom stuff .
50,842
private function addRow ( $ row , $ index = null ) { $ this -> copyDefaultColumnDefinitions ( $ row , $ index ) ; if ( $ this -> trigger ( self :: EV_ROW_ADD , [ $ row , $ index ] ) === false ) { return $ this ; } $ h = $ this -> getRowHeight ( ) ; $ page_break_trigger = $ this -> pdf -> getPageHeight ( ) - $ this -> pdf -> getBreakMargin ( ) ; if ( $ this -> pdf -> GetY ( ) + $ h >= $ page_break_trigger ) { if ( $ this -> trigger ( self :: EV_PAGE_ADD , [ $ row , $ index , false ] ) !== false ) { $ this -> pdf -> AddPage ( ) ; $ this -> trigger ( self :: EV_PAGE_ADDED , [ $ row , $ index , false ] ) ; } } foreach ( $ this -> columnDefinition as $ key => $ value ) { if ( isset ( $ this -> rowDefinition [ $ key ] ) ) { $ this -> addCell ( $ key , isset ( $ row [ $ key ] ) ? $ row [ $ key ] : '' , $ row ) ; } } $ this -> trigger ( self :: EV_ROW_ADDED , [ $ row , $ index ] ) ; return $ this ; }
Add a row
50,843
private function fetchDataByUserFunc ( $ c , $ data , $ column , $ row , $ header , $ heightc ) { if ( ! $ header && is_callable ( $ c [ 'renderer' ] ) ) { $ data = $ c [ 'renderer' ] ( $ this , $ data , $ row , $ column , $ heightc ) ; } elseif ( $ header && is_callable ( $ c [ 'headerRenderer' ] ) ) { $ data = $ c [ 'headerRenderer' ] ( $ this , $ data , $ row , $ column , $ heightc ) ; } return $ data ; }
Get data by user function if it exists
50,844
private function copyDefaultColumnDefinitions ( $ columns = null , $ rowIndex = null ) { $ this -> rowDefinition = $ this -> columnDefinition ; $ h = $ this -> trigger ( self :: EV_ROW_HEIGHT_GET , [ $ columns , $ rowIndex ] , true ) ; if ( $ h === null ) { $ h = $ columns !== null ? $ this -> getCurrentRowHeight ( $ columns ) : $ this -> getColumnHeight ( ) ; } $ this -> setRowHeight ( $ h ) ; }
Copy column definition inside a new property . It allows us to customize it only for this row . For the next row column definition will again be the default one .
50,845
protected function firePreProcessEvent ( $ name = null , $ resource = null ) { if ( empty ( $ name ) ) { $ name = $ this -> getEventName ( ) ; } if ( empty ( $ resource ) ) { $ resource = $ this -> getEventResource ( ) ; } $ event = new PreProcessApiEvent ( $ name , $ this -> request , $ this -> response , $ resource ) ; $ results = \ Event :: fire ( $ event ) ; $ this -> response = $ event -> response ; }
Fires pre process event
50,846
protected function firePostProcessEvent ( $ name = null , $ resource = null ) { if ( empty ( $ name ) ) { $ name = $ this -> getEventName ( ) ; } if ( empty ( $ resource ) ) { $ resource = $ this -> getEventResource ( ) ; } $ results = \ Event :: fire ( new PostProcessApiEvent ( $ name , $ this -> request , $ this -> response , $ resource ) ) ; }
Fires post process event
50,847
protected function fireFinalEvent ( $ name = null , $ resource = null ) { if ( empty ( $ name ) ) { $ name = $ this -> getEventName ( ) ; } if ( empty ( $ resource ) ) { $ resource = $ this -> getEventResource ( ) ; } $ results = \ Event :: fire ( new ApiEvent ( $ name , $ this -> request , $ this -> response , $ resource ) ) ; }
Fires last event before responding
50,848
protected function setAction ( $ action ) { $ this -> action = trim ( strtoupper ( $ action ) ) ; if ( null !== ( $ alias = array_get ( $ this -> verbAliases , $ this -> action ) ) ) { if ( in_array ( $ alias , Verbs :: getDefinedConstants ( ) ) || ! is_callable ( $ alias ) ) { $ this -> originalAction = $ this -> action ; $ this -> action = $ alias ; } } return $ this ; }
Sets the HTTP Action verb
50,849
public function handleApiEvent ( $ event ) { $ eventName = str_replace ( '.queued' , null , $ event -> name ) ; $ ckey = 'event:' . $ eventName ; $ records = Cache :: remember ( $ ckey , Config :: get ( 'df.default_cache_ttl' ) , function ( ) use ( $ eventName ) { return ServiceEventMap :: whereEvent ( $ eventName ) -> get ( ) -> all ( ) ; } ) ; if ( empty ( $ records ) ) { $ serviceName = substr ( $ eventName , 0 , strpos ( $ eventName , '.' ) ) ; $ wildcardEvent = $ serviceName . '.*' ; $ ckey = 'event:' . $ wildcardEvent ; $ records = Cache :: remember ( $ ckey , Config :: get ( 'df.default_cache_ttl' ) , function ( ) use ( $ wildcardEvent ) { return ServiceEventMap :: whereEvent ( $ wildcardEvent ) -> get ( ) -> all ( ) ; } ) ; } foreach ( $ records as $ record ) { Log :: debug ( 'Service event handled: ' . $ eventName ) ; $ service = \ ServiceManager :: getServiceById ( $ record -> service_id ) ; Event :: fire ( new ServiceAssignedEvent ( $ service , $ event , $ record -> toArray ( ) ) ) ; } }
Handle API events .
50,850
public static function toConstant ( $ value ) { if ( false !== ( $ _index = array_search ( $ value , static :: getDefinedConstants ( ) ) ) ) { return $ _index ; } throw new \ InvalidArgumentException ( 'The value "' . $ value . '" has no associated constant.' ) ; }
Given a VALUE return the associated CONSTANT
50,851
public static function toValue ( $ constant ) { if ( false !== ( $ _index = array_search ( $ constant , static :: getDefinedConstants ( true ) ) ) ) { return $ _index ; } throw new \ InvalidArgumentException ( 'The constant "' . $ constant . '" has no associated value.' ) ; }
Given a CONSTANT return the associated VALUE
50,852
public static function resolve ( $ item ) { try { return static :: toConstant ( $ item ) ; } catch ( \ Exception $ _ex ) { } try { return static :: toValue ( $ item ) ; } catch ( \ Exception $ _ex ) { } throw new \ InvalidArgumentException ( 'The item "' . $ item . '" can not be resolved.' ) ; }
Given a CONSTANT or VALUE return the VALUE
50,853
public static function prettyList ( $ quote = null , $ tags = false , $ numbers = false , $ lastOr = true ) { $ quote != '\'' && $ quote != '"' && $ quote = null ; $ _values = array_values ( $ tags ? static :: $ tags : static :: getDefinedConstants ( true ) ) ; for ( $ _i = 0 , $ _max = count ( $ _values ) ; $ _i < $ _max ; $ _i ++ ) { if ( '_' == $ _values [ $ _i ] [ 0 ] ) { array_forget ( $ _values , $ _i ) ; continue ; } } end ( $ _values ) ; $ _last = key ( $ _values ) ; $ _list = null ; for ( $ _i = 0 , $ _max = count ( $ _values ) ; $ _i < $ _max ; $ _i ++ ) { $ _i != 0 && $ _list .= ', ' ; $ lastOr && ( $ _i == $ _last ) && $ _list .= 'or ' ; if ( $ numbers ) { $ _item = $ quote . static :: toValue ( $ _values [ $ _i ] ) . $ quote . ' (' . strtolower ( $ _values [ $ _i ] ) . ')' ; } else { $ _item = $ quote . strtolower ( $ _values [ $ _i ] ) . $ quote ; } $ _list .= $ _item ; } return $ _list ; }
Returns a list of the constants in a comma - separated display manner
50,854
public static function neutralizeObject ( $ object , $ strip = null ) { $ _variables = is_array ( $ object ) ? $ object : get_object_vars ( $ object ) ; if ( ! empty ( $ _variables ) ) { foreach ( $ _variables as $ _key => $ _value ) { $ _originalKey = $ _key ; if ( $ strip ) { $ _key = str_replace ( $ strip , null , $ _key ) ; } $ _variables [ static :: neutralize ( ltrim ( $ _key , '_' ) ) ] = $ _value ; unset ( $ _variables [ $ _originalKey ] ) ; } } return $ _variables ; }
Given an object returns an array containing the variables of the object and their values . The keys for the object have been neutralized for your protection
50,855
public static function camelize ( $ string , $ separator = null , $ preserveWhiteSpace = false , $ isKey = false ) { empty ( $ separator ) && $ separator = [ '_' , '-' ] ; $ _newString = ucwords ( str_replace ( $ separator , ' ' , $ string ) ) ; if ( false !== $ isKey ) { $ _newString = lcfirst ( $ _newString ) ; } return ( false === $ preserveWhiteSpace ? str_replace ( ' ' , null , $ _newString ) : $ _newString ) ; }
Converts a separator delimited string to camel case
50,856
protected function removeDirectory ( $ path ) { $ files = glob ( $ path . '/*' ) ; foreach ( $ files as $ file ) { if ( is_dir ( $ file ) ) { static :: removeDirectory ( $ file ) ; } else if ( basename ( $ file ) !== '.gitignore' ) { unlink ( $ file ) ; } } if ( $ path !== $ this -> cacheRoot ) { rmdir ( $ path ) ; } return ; }
Removes directories recursively .
50,857
public static function alert ( $ type , $ transKey , $ transCount = 1 , $ transParameters = [ ] ) { $ alerts = [ ] ; if ( Session :: has ( 'alerts' ) ) { $ alerts = Session :: get ( 'alerts' ) ; } $ message = trans_choice ( "forum::{$transKey}" , $ transCount , $ transParameters ) ; array_push ( $ alerts , compact ( 'type' , 'message' ) ) ; Session :: flash ( 'alerts' , $ alerts ) ; }
Process an alert message to display to the user .
50,858
public static function route ( $ route , $ model = null ) { if ( ! starts_with ( $ route , config ( 'forum.routing.as' ) ) ) { $ route = config ( 'forum.routing.as' ) . $ route ; } $ params = [ ] ; $ append = '' ; if ( $ model ) { switch ( true ) { case $ model instanceof Category : $ params = [ 'category' => $ model -> id , 'category_slug' => static :: slugify ( $ model -> title ) ] ; break ; case $ model instanceof Thread : $ params = [ 'category' => $ model -> category -> id , 'category_slug' => static :: slugify ( $ model -> category -> title ) , 'thread' => $ model -> id , 'thread_slug' => static :: slugify ( $ model -> title ) ] ; break ; case $ model instanceof Post : $ params = [ 'category' => $ model -> thread -> category -> id , 'category_slug' => static :: slugify ( $ model -> thread -> category -> title ) , 'thread' => $ model -> thread -> id , 'thread_slug' => static :: slugify ( $ model -> thread -> title ) ] ; if ( $ route == config ( 'forum.routing.as' ) . 'thread.show' ) { $ params [ 'page' ] = ceil ( $ model -> sequence / $ model -> getPerPage ( ) ) ; $ append = "#post-{$model->sequence}" ; } else { $ params [ 'post' ] = $ model -> id ; } break ; } } return route ( $ route , $ params ) . $ append ; }
Generate a URL to a named forum route .
50,859
public static function routes ( Router $ router ) { $ controllers = config ( 'forum.frontend.controllers' ) ; $ router -> get ( '/' , [ 'as' => 'index' , 'uses' => "{$controllers['category']}@index" ] ) ; $ router -> get ( 'new' , [ 'as' => 'index-new' , 'uses' => "{$controllers['thread']}@indexNew" ] ) ; $ router -> patch ( 'new' , [ 'as' => 'mark-new' , 'uses' => "{$controllers['thread']}@markNew" ] ) ; $ router -> post ( 'category/create' , [ 'as' => 'category.store' , 'uses' => "{$controllers['category']}@store" ] ) ; $ router -> group ( [ 'prefix' => '{category}-{category_slug}' ] , function ( $ router ) use ( $ controllers ) { $ router -> get ( '/' , [ 'as' => 'category.show' , 'uses' => "{$controllers['category']}@show" ] ) ; $ router -> patch ( '/' , [ 'as' => 'category.update' , 'uses' => "{$controllers['category']}@update" ] ) ; $ router -> delete ( '/' , [ 'as' => 'category.delete' , 'uses' => "{$controllers['category']}@destroy" ] ) ; $ router -> get ( '{thread}-{thread_slug}' , [ 'as' => 'thread.show' , 'uses' => "{$controllers['thread']}@show" ] ) ; $ router -> get ( 'thread/create' , [ 'as' => 'thread.create' , 'uses' => "{$controllers['thread']}@create" ] ) ; $ router -> post ( 'thread/create' , [ 'as' => 'thread.store' , 'uses' => "{$controllers['thread']}@store" ] ) ; $ router -> patch ( '{thread}-{thread_slug}' , [ 'as' => 'thread.update' , 'uses' => "{$controllers['thread']}@update" ] ) ; $ router -> delete ( '{thread}-{thread_slug}' , [ 'as' => 'thread.delete' , 'uses' => "{$controllers['thread']}@destroy" ] ) ; $ router -> get ( '{thread}-{thread_slug}/post/{post}' , [ 'as' => 'post.show' , 'uses' => "{$controllers['post']}@show" ] ) ; $ router -> get ( '{thread}-{thread_slug}/reply' , [ 'as' => 'post.create' , 'uses' => "{$controllers['post']}@create" ] ) ; $ router -> post ( '{thread}-{thread_slug}/reply' , [ 'as' => 'post.store' , 'uses' => "{$controllers['post']}@store" ] ) ; $ router -> get ( '{thread}-{thread_slug}/post/{post}/edit' , [ 'as' => 'post.edit' , 'uses' => "{$controllers['post']}@edit" ] ) ; $ router -> patch ( '{thread}-{thread_slug}/{post}' , [ 'as' => 'post.update' , 'uses' => "{$controllers['post']}@update" ] ) ; $ router -> delete ( '{thread}-{thread_slug}/{post}' , [ 'as' => 'post.delete' , 'uses' => "{$controllers['post']}@destroy" ] ) ; } ) ; $ router -> group ( [ 'prefix' => 'bulk' , 'as' => 'bulk.' ] , function ( $ router ) use ( $ controllers ) { $ router -> patch ( 'thread' , [ 'as' => 'thread.update' , 'uses' => "{$controllers['thread']}@bulkUpdate" ] ) ; $ router -> delete ( 'thread' , [ 'as' => 'thread.delete' , 'uses' => "{$controllers['thread']}@bulkDestroy" ] ) ; $ router -> patch ( 'post' , [ 'as' => 'post.update' , 'uses' => "{$controllers['post']}@bulkUpdate" ] ) ; $ router -> delete ( 'post' , [ 'as' => 'post.delete' , 'uses' => "{$controllers['post']}@bulkDestroy" ] ) ; } ) ; }
Register the standard forum routes .
50,860
protected function csv ( $ key = null , $ default = null ) { if ( empty ( $ this -> contentAsArray ) ) { $ content = $ this -> getContent ( ) ; $ data = DataFormatter :: csvToArray ( $ content ) ; if ( ! empty ( $ data ) ) { $ this -> contentAsArray = ResourcesWrapper :: wrapResources ( $ data ) ; } } if ( null === $ key ) { return $ this -> contentAsArray ; } else { return array_get ( $ this -> contentAsArray , $ key , $ default ) ; } }
Returns CSV payload data
50,861
protected function xml ( $ key = null , $ default = null ) { if ( empty ( $ this -> contentAsArray ) ) { $ content = $ this -> getContent ( ) ; $ data = DataFormatter :: xmlToArray ( $ content ) ; if ( ! empty ( $ data ) ) { if ( ( 1 === count ( $ data ) ) && ! array_key_exists ( ResourcesWrapper :: getWrapper ( ) , $ data ) ) { $ data = reset ( $ data ) ; } $ this -> contentAsArray = $ data ; } } if ( null === $ key ) { return $ this -> contentAsArray ; } else { return array_get ( $ this -> contentAsArray , $ key , $ default ) ; } }
Returns XML payload data .
50,862
protected function formatFileInfo ( $ fileInfo ) { if ( empty ( $ fileInfo ) || ! is_array ( $ fileInfo ) || isset ( $ fileInfo [ 0 ] ) ) { return $ fileInfo ; } $ file = [ ] ; foreach ( $ fileInfo as $ key => $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ k => $ v ) { $ file [ $ k ] [ $ key ] = $ v ; } } else { $ file [ $ key ] = $ value ; } } return $ file ; }
Format file data for ease of use
50,863
private function inBounds ( ) { $ in = true ; if ( $ this -> from !== null ) { $ in = $ this -> current >= $ this -> from ; if ( $ in && $ this -> length !== null ) { $ in = $ this -> current < $ this -> from + $ this -> length ; if ( ! $ in && $ this -> outOfBounds ) { die ( "Process stopped in TcTable Debug Plugin, because " . "\$outOfBounds is set to TRUE in setBounds()." ) ; } } } if ( $ in && is_callable ( $ this -> boundsFn ) ) { return $ this -> boundsFn ( $ this , $ this -> current ) ; } return $ in ; }
Check if the current row is in debug bounds
50,864
private function listenTo ( $ event = null ) { if ( $ event === null && $ this -> getEventInvoker ( ) ) { $ event = $ this -> getEventInvoker ( ) [ 'id' ] ; } return ! $ this -> listen || in_array ( $ event , $ this -> listen ) ; }
Check if the given event is listenable
50,865
public function getModel ( $ table ) { if ( isset ( $ this -> map [ $ table ] ) ) { return $ this -> map [ $ table ] ; } return null ; }
Return the model for the given table .
50,866
public function getTable ( $ model ) { if ( false !== $ pos = array_search ( $ model , $ this -> map ) ) { return $ pos ; } return null ; }
Return the table for the given model .
50,867
protected static function getJWTFromAuthHeader ( ) { if ( 'testing' === env ( 'APP_ENV' ) ) { return [ ] ; } if ( ! function_exists ( 'getallheaders' ) ) { function getallheaders ( ) { if ( ! is_array ( $ _SERVER ) ) { return [ ] ; } $ headers = [ ] ; foreach ( $ _SERVER as $ name => $ value ) { if ( substr ( $ name , 0 , 5 ) == 'HTTP_' ) { $ headers [ str_replace ( ' ' , '-' , ucwords ( strtolower ( str_replace ( '_' , ' ' , substr ( $ name , 5 ) ) ) ) ) ] = $ value ; } } return $ headers ; } } $ token = null ; $ headers = getallheaders ( ) ; $ authHeader = array_get ( $ headers , 'Authorization' ) ; if ( strpos ( $ authHeader , 'Bearer' ) !== false ) { $ token = substr ( $ authHeader , 7 ) ; } return $ token ; }
Gets the token from Authorization header .
50,868
protected function addMiddleware ( ) { if ( method_exists ( \ Illuminate \ Routing \ Router :: class , 'aliasMiddleware' ) ) { Route :: aliasMiddleware ( 'df.auth_check' , AuthCheck :: class ) ; Route :: aliasMiddleware ( 'df.access_check' , AccessCheck :: class ) ; Route :: aliasMiddleware ( 'df.verb_override' , VerbOverrides :: class ) ; } else { Route :: middleware ( 'df.auth_check' , AuthCheck :: class ) ; Route :: middleware ( 'df.access_check' , AccessCheck :: class ) ; Route :: middleware ( 'df.verb_override' , VerbOverrides :: class ) ; } Route :: prependMiddlewareToGroup ( 'web' , FirstUserCheck :: class ) ; Route :: middlewareGroup ( 'df.api' , [ 'df.verb_override' , 'df.auth_check' , 'df.access_check' ] ) ; }
Register any middleware aliases .
50,869
protected function addDecryptedAttributesToArray ( array $ attributes ) { if ( ! $ this -> encryptedView ) { foreach ( $ this -> getEncryptable ( ) as $ key ) { if ( ! array_key_exists ( $ key , $ attributes ) ) { continue ; } if ( ! empty ( $ attributes [ $ key ] ) ) { $ attributes [ $ key ] = Crypt :: decrypt ( $ attributes [ $ key ] ) ; } } } return $ attributes ; }
Decrypt encryptable attributes found in outgoing array
50,870
public function setFill ( TcTable $ table ) { if ( $ this -> disabled ) { $ fill = false ; } else { $ fill = $ this -> rowCurrentStripe = ! $ this -> rowCurrentStripe ; } foreach ( $ table -> getRowDefinition ( ) as $ column => $ row ) { $ table -> setRowDefinition ( $ column , 'fill' , $ row [ 'fill' ] ? : $ fill ) ; } $ this -> moveY ( $ table ) ; }
Set the background of the row
50,871
public function moveY ( TcTable $ table ) { $ y = 0.6 / $ table -> getPdf ( ) -> getScaleFactor ( ) ; $ table -> getPdf ( ) -> SetY ( $ table -> getPdf ( ) -> GetY ( ) + $ y ) ; }
Adjust Y because cell background passes over the previous cell s border hiding it .
50,872
public static function updateEnvSetting ( array $ settings , $ path = null ) { if ( empty ( $ path ) ) { $ path = base_path ( '.env' ) ; } if ( file_exists ( $ path ) ) { $ subject = file_get_contents ( $ path ) ; foreach ( $ settings as $ key => $ value ) { $ subject = str_replace ( [ '#' . $ key , '##$key' ] , $ key , $ subject ) ; } file_put_contents ( $ path , $ subject ) ; foreach ( $ settings as $ key => $ value ) { $ dotenv = new Dotenv ( base_path ( ) ) ; $ dotenv -> load ( ) ; $ search = $ key . '=' . getenv ( $ key ) ; $ replace = $ key . '=' . $ value ; $ subject = str_replace ( $ search , $ replace , $ subject ) ; } file_put_contents ( $ path , $ subject ) ; } }
Updates . env file setting .
50,873
public function addColumn ( ColumnSchema $ schema ) { $ key = strtolower ( $ schema -> name ) ; $ this -> columns [ $ key ] = $ schema ; }
Sets the named column metadata .
50,874
public function getColumn ( $ name , $ use_alias = false ) { if ( $ use_alias ) { foreach ( $ this -> columns as $ column ) { if ( 0 === strcasecmp ( $ name , $ column -> getName ( $ use_alias ) ) ) { return $ column ; } } } else { $ key = strtolower ( $ name ) ; if ( isset ( $ this -> columns [ $ key ] ) ) { return $ this -> columns [ $ key ] ; } } return null ; }
Gets the named column metadata .
50,875
public function getRelation ( $ name , $ use_alias = false ) { if ( $ use_alias ) { foreach ( $ this -> relations as $ relation ) { if ( 0 === strcasecmp ( $ name , $ relation -> getName ( $ use_alias ) ) ) { return $ relation ; } } } else { $ key = strtolower ( $ name ) ; if ( isset ( $ this -> relations [ $ key ] ) ) { return $ this -> relations [ $ key ] ; } } return null ; }
Gets the named relation metadata .
50,876
protected function isProtectedAttribute ( $ key , $ value ) { return ( in_array ( $ key , $ this -> getProtectable ( ) ) && ( $ value === $ this -> protectionMask ) ) ; }
Check if the attribute coming from client is set to mask . If so skip writing to database .
50,877
protected function protectAttribute ( $ key , & $ value ) { if ( ! is_null ( $ value ) && $ this -> protectedView && in_array ( $ key , $ this -> getProtectable ( ) ) ) { $ value = $ this -> protectionMask ; return true ; } return false ; }
Check if the attribute is marked protected if so return the mask not the value .
50,878
protected function addProtectedAttributesToArray ( array $ attributes ) { if ( $ this -> protectedView ) { foreach ( $ this -> getProtectable ( ) as $ key ) { if ( isset ( $ attributes [ $ key ] ) ) { $ attributes [ $ key ] = $ this -> protectionMask ; } } } return $ attributes ; }
Replace all protected attributes in the given array with the mask
50,879
public function create ( array $ data , $ serviceId = null ) { $ userService = ServiceManager :: getService ( 'user' ) ; if ( ! $ userService -> allowOpenRegistration ) { throw new ForbiddenException ( 'Open Registration is not enabled.' ) ; } $ user = User :: create ( $ data ) ; if ( ! empty ( $ userService -> openRegEmailServiceId ) ) { $ this -> sendConfirmation ( $ user , $ userService -> openRegEmailServiceId , $ userService -> openRegEmailTemplateId ) ; } else if ( ! empty ( $ data [ 'password' ] ) ) { $ user -> password = $ data [ 'password' ] ; $ user -> save ( ) ; } if ( ! empty ( $ userService -> openRegRoleId ) ) { User :: applyDefaultUserAppRole ( $ user , $ userService -> openRegRoleId ) ; } if ( ! empty ( $ serviceId ) ) { User :: applyAppRoleMapByService ( $ user , $ serviceId ) ; } return $ user ; }
Creates a non - admin user .
50,880
private static function findByRel ( array $ a , $ rel ) { $ relName = mb_strtolower ( $ rel , 'UTF-8' ) ; foreach ( $ a as $ name => $ value ) { if ( mb_strtolower ( $ name , 'UTF-8' ) === $ relName ) { return $ value ; } } return null ; }
Looks for the given relation name in a case - insensitive fashion and returns the corresponding value .
50,881
public function getTableSchema ( ) { return \ Cache :: rememberForever ( 'model:' . $ this -> table , function ( ) { $ resourceName = $ this -> table ; $ name = $ resourceName ; if ( empty ( $ schemaName = $ this -> getDefaultSchema ( ) ) ) { $ internalName = $ resourceName ; $ quotedName = $ this -> getSchema ( ) -> quoteTableName ( $ resourceName ) ; ; } else { $ internalName = $ schemaName . '.' . $ resourceName ; $ quotedName = $ this -> getSchema ( ) -> quoteTableName ( $ schemaName ) . '.' . $ this -> getSchema ( ) -> quoteTableName ( $ resourceName ) ; ; } $ settings = compact ( 'schemaName' , 'resourceName' , 'name' , 'internalName' , 'quotedName' ) ; $ tableSchema = new TableSchema ( $ settings ) ; $ tableSchema = $ this -> getSchema ( ) -> getResource ( DbResourceTypes :: TYPE_TABLE , $ tableSchema ) ; if ( ! empty ( $ references = $ this -> getTableConstraints ( ) ) ) { $ this -> updateTableWithConstraints ( $ tableSchema , $ references ) ; } $ tableSchema -> discoveryCompleted = true ; return $ tableSchema ; } ) ; }
Gets the TableSchema for this model .
50,882
public static function selectByIds ( $ ids , array $ options = [ ] , array $ criteria = [ ] ) { $ criteria = static :: cleanCriteria ( $ criteria ) ; if ( empty ( $ criteria ) ) { $ criteria [ 'select' ] = [ '*' ] ; } if ( is_array ( $ ids ) ) { $ ids = implode ( ',' , $ ids ) ; } $ pk = static :: getPrimaryKeyStatic ( ) ; if ( ! empty ( $ ids ) ) { $ idsPhrase = " $pk IN ($ids) " ; $ condition = array_get ( $ criteria , 'condition' ) ; if ( ! empty ( $ condition ) ) { $ condition .= ' AND ' . $ idsPhrase ; } else { $ condition = $ idsPhrase ; } $ criteria [ 'condition' ] = $ condition ; } $ data = static :: selectByRequest ( $ criteria , $ options ) ; $ data = static :: cleanResult ( $ data , array_get ( $ criteria , 'select' ) ) ; if ( ! is_array ( $ ids ) ) { $ ids = explode ( ',' , $ ids ) ; } if ( count ( $ data ) != count ( $ ids ) ) { $ out = [ ] ; $ continue = array_get_bool ( $ options , ApiOptions :: CONTINUES ) ; foreach ( $ ids as $ index => $ id ) { $ found = false ; foreach ( $ data as $ record ) { if ( $ id == array_get ( $ record , $ pk ) ) { $ out [ $ index ] = $ record ; $ found = true ; break ; } } if ( ! $ found ) { $ out [ $ index ] = new NotFoundException ( "Record with identifier '$id' not found." ) ; if ( ! $ continue ) { break ; } } } throw new BatchException ( $ out , 'Batch Error: Not all requested records could be retrieved.' ) ; } return $ data ; }
Selects records by multiple ids .
50,883
public static function selectByRequest ( array $ criteria = [ ] , array $ options = [ ] ) { $ criteria = static :: cleanCriteria ( $ criteria ) ; $ pk = static :: getPrimaryKeyStatic ( ) ; $ selection = array_get ( $ criteria , 'select' ) ; if ( empty ( $ selection ) ) { $ selection = [ '*' ] ; } $ related = array_get ( $ options , ApiOptions :: RELATED , [ ] ) ; if ( is_string ( $ related ) ) { $ related = explode ( ',' , $ related ) ; } $ condition = array_get ( $ criteria , 'condition' ) ; if ( ! empty ( $ condition ) ) { $ params = array_get ( $ criteria , 'params' ) ; $ builder = static :: whereRaw ( $ condition , $ params ) -> with ( $ related ) ; } else { $ builder = static :: with ( $ related ) ; } if ( ! empty ( $ limit = array_get ( $ criteria , 'limit' ) ) ) { $ builder -> take ( $ limit ) ; } if ( ! empty ( $ offset = array_get ( $ criteria , 'offset' ) ) ) { $ builder -> skip ( $ offset ) ; } $ orderBy = array_get ( $ criteria , 'order' , "$pk asc" ) ; $ orders = explode ( ',' , $ orderBy ) ; foreach ( $ orders as $ order ) { $ order = trim ( $ order ) ; @ list ( $ column , $ direction ) = explode ( ' ' , $ order ) ; if ( empty ( $ direction ) ) { $ direction = 'ASC' ; } $ builder = $ builder -> orderBy ( $ column , $ direction ) ; } $ groupBy = array_get ( $ criteria , 'group' ) ; if ( ! empty ( $ groupBy ) ) { $ groups = explode ( ',' , $ groupBy ) ; foreach ( $ groups as $ group ) { $ builder = $ builder -> groupBy ( trim ( $ group ) ) ; } } $ response = $ builder -> get ( $ selection ) ; return static :: cleanResult ( $ response , array_get ( $ criteria , 'select' ) ) ; }
Performs a SELECT query based on query criteria supplied from api request .
50,884
public static function countByRequest ( array $ criteria = [ ] ) { if ( ! empty ( $ condition = array_get ( $ criteria , 'condition' ) ) ) { $ params = array_get ( $ criteria , 'params' , [ ] ) ; return static :: whereRaw ( $ condition , $ params ) -> count ( ) ; } return static :: count ( ) ; }
Performs a COUNT query based on query criteria supplied from api request .
50,885
protected function getReferencingField ( $ table , $ name ) { $ references = $ this -> getReferences ( ) ; $ rf = null ; foreach ( $ references as $ item ) { if ( $ item -> refTable === $ table && $ table . '_by_' . implode ( '_' , $ item -> refField ) === $ name ) { $ rf = $ item -> refField [ 0 ] ; break ; } } return $ rf ; }
Gets the foreign key of the referenced table
50,886
protected function getReferencingTable ( $ name ) { $ references = $ this -> getReferences ( ) ; if ( array_key_exists ( $ name , $ references ) ) { return $ references [ $ name ] -> refTable ; } return null ; }
Gets the referenced table name by it s relation name to this model .
50,887
protected function getReferencingModel ( $ name ) { if ( ! $ this -> isRelationMapped ( $ name ) ) { return null ; } $ table = $ this -> getReferencingTable ( $ name ) ; $ model = static :: getModelFromTable ( $ table ) ; return $ model ; }
Gets the referenced model via its table using relation name .
50,888
public function export ( ) { $ this -> checkStoragePermission ( ) ; $ this -> gatherData ( ) ; $ this -> package -> initZipFile ( ) ; $ this -> addManifestFile ( ) ; $ this -> addResourceFiles ( ) ; $ this -> addStorageFiles ( ) ; $ url = $ this -> package -> saveZipFile ( $ this -> storageService , $ this -> storageFolder ) ; return $ url ; }
Extracts resources and exports the package file . Returns URL of the exported file .
50,889
protected function checkStoragePermission ( ) { Session :: checkServicePermission ( Verbs :: POST , $ this -> storageService , trim ( $ this -> storageFolder , '/' ) , Session :: getRequestor ( ) ) ; }
Checks to see if the user exporting the package has permission to storage the package in the target storage service .
50,890
public function isPublic ( ) { $ service = Service :: whereName ( $ this -> storageService ) -> first ( ) -> toArray ( ) ; $ publicPaths = array_get ( $ service , 'config.public_path' ) ; if ( ! empty ( $ publicPaths ) ) { foreach ( $ publicPaths as $ pp ) { if ( trim ( $ this -> storageFolder , '/' ) == trim ( $ pp , '/' ) ) { return true ; } } } return false ; }
Checks to see if the URL of the exported zip file is publicly accessible .
50,891
public function getManifestOnly ( $ systemOnly = false , $ fullTree = false ) { $ this -> data [ 'system' ] [ 'role' ] = $ this -> getAllResources ( 'system' , 'role' , [ 'fields' => 'id,name' ] ) ; $ this -> data [ 'system' ] [ 'service' ] = $ this -> getAllResources ( 'system' , 'service' , [ 'fields' => 'id,name' ] , null , false ) ; $ allServices = $ this -> data [ 'system' ] [ 'service' ] ; $ this -> data [ 'system' ] [ 'app' ] = $ this -> getAllResources ( 'system' , 'app' , [ 'fields' => 'id,name' ] ) ; $ this -> data [ 'system' ] [ 'user' ] = $ this -> getAllResources ( 'system' , 'user' , [ 'fields' => 'id,email,username,first_name,last_name' ] ) ; $ this -> data [ 'system' ] [ 'admin' ] = $ this -> getAllResources ( 'system' , 'admin' , [ 'fields' => 'id,email,username,first_name,last_name' ] ) ; $ this -> data [ 'system' ] [ 'custom' ] = $ this -> getAllResources ( 'system' , 'custom' ) ; $ this -> data [ 'system' ] [ 'cors' ] = $ this -> getAllResources ( 'system' , 'cors' , [ 'fields' => 'id,path' ] ) ; $ this -> data [ 'system' ] [ 'email_template' ] = $ this -> getAllResources ( 'system' , 'email_template' , [ 'fields' => 'id,name' ] ) ; $ this -> data [ 'system' ] [ 'event_script' ] = $ this -> getAllResources ( 'system' , 'event_script' , [ 'fields' => 'name' ] ) ; $ this -> data [ 'system' ] [ 'lookup' ] = $ this -> getAllResources ( 'system' , 'lookup' , [ 'fields' => 'id,name' ] ) ; if ( class_exists ( \ DreamFactory \ Core \ Limit \ ServiceProvider :: class ) ) { $ this -> data [ 'system' ] [ 'limit' ] = $ this -> getAllResources ( 'system' , 'limit' , [ 'fields' => 'id,name' ] ) ; } $ manifest = $ this -> package -> getManifestHeader ( ) ; $ this -> getAllowedSystemResources ( $ manifest ) ; if ( ! Session :: checkServicePermission ( Verbs :: GET , 'system' , 'service' , Session :: getRequestor ( ) , false ) ) { unset ( $ manifest [ 'service' ] [ 'system' ] [ 'service' ] ) ; if ( empty ( $ manifest [ 'service' ] [ 'system' ] ) ) { unset ( $ manifest [ 'service' ] [ 'system' ] ) ; } } if ( false === $ systemOnly ) { $ this -> getAllowedServiceResources ( $ manifest , $ allServices , $ fullTree ) ; } return $ manifest ; }
Returns a manifest file for system - wide resources .
50,892
private function getAllowedSystemResources ( & $ manifest ) { foreach ( $ this -> data as $ serviceName => $ resource ) { foreach ( $ resource as $ resourceName => $ records ) { foreach ( $ records as $ record ) { $ api = $ serviceName . '/' . $ resourceName ; switch ( $ api ) { case 'system/user' : case 'system/admin' : $ manifest [ 'service' ] [ $ serviceName ] [ $ resourceName ] [ ] = [ 'username' => array_get ( $ record , 'username' ) , 'email' => array_get ( $ record , 'email' ) , 'first_name' => array_get ( $ record , 'first_name' ) , 'last_name' => array_get ( $ record , 'last_name' ) ] ; break ; case 'system/cors' : $ manifest [ 'service' ] [ $ serviceName ] [ $ resourceName ] [ ] = array_get ( $ record , 'id' ) ; break ; default : $ manifest [ 'service' ] [ $ serviceName ] [ $ resourceName ] [ ] = array_get ( $ record , 'name' ) ; break ; } } } } }
Gets all system resources based on RBAC
50,893
private function getAllowedDatabaseResources ( & $ manifest , $ serviceName ) { $ manifest [ 'service' ] [ $ serviceName ] [ static :: REACHABLE_FLAG ] = true ; $ result = $ this -> getAllResources ( $ serviceName , '_schema' , [ 'as_list' => true ] , null , false ) ; if ( Session :: isSysAdmin ( ) ) { $ manifest [ 'service' ] [ $ serviceName ] [ '_schema' ] = $ result ; $ manifest [ 'service' ] [ $ serviceName ] [ '_table' ] = $ result ; } else { if ( ! empty ( $ result ) ) { $ manifest [ 'service' ] [ $ serviceName ] [ '_schema' ] = $ result ; } else { $ manifest [ 'service' ] [ $ serviceName ] [ '_schema' ] = [ ] ; } $ result = $ this -> getAllResources ( $ serviceName , '_table' , [ 'as_list' => true ] , null , false ) ; if ( ! empty ( $ result ) ) { $ manifest [ 'service' ] [ $ serviceName ] [ '_table' ] = $ result ; } else { $ manifest [ 'service' ] [ $ serviceName ] [ '_table' ] = [ ] ; } } }
Gets all DB service resources based on RBAC
50,894
private function getAllowedStoragePaths ( & $ manifest , $ serviceName , $ serviceId , $ fullTree ) { if ( Session :: isSysAdmin ( ) ) { $ manifest [ 'service' ] [ $ serviceName ] = $ this -> getAllResources ( $ serviceName , '' , [ 'as_list' => true , 'full_tree' => $ fullTree ] , null , false ) ; } else { $ roleId = Session :: getRoleId ( ) ; $ requestorMask = Session :: getRequestor ( ) ; $ manifest [ 'service' ] [ $ serviceName ] = [ ] ; $ accesses = RoleServiceAccess :: whereRoleId ( $ roleId ) -> whereServiceId ( $ serviceId ) -> whereRequestorMask ( $ requestorMask ) -> get ( [ 'component' , 'verb_mask' ] ) ; foreach ( $ accesses as $ access ) { if ( $ access -> verb_mask & VerbsMask :: toNumeric ( Verbs :: GET ) ) { $ allowedPath = $ access -> component ; if ( $ allowedPath === '*' ) { $ manifest [ 'service' ] [ $ serviceName ] = $ this -> getAllResources ( $ serviceName , '' , [ 'as_list' => true , 'full_tree' => $ fullTree ] ) ; break ; } else { if ( substr ( $ allowedPath , strlen ( $ allowedPath ) - 1 ) === '*' ) { if ( $ fullTree ) { $ allPaths = $ this -> getAllResources ( $ serviceName , substr ( $ allowedPath , 0 , strlen ( $ allowedPath ) - 1 ) , [ 'as_list' => true , 'full_tree' => $ fullTree ] ) ; $ manifest [ 'service' ] [ $ serviceName ] = array_merge ( $ manifest [ 'service' ] [ $ serviceName ] , $ allPaths ) ; } else { $ manifest [ 'service' ] [ $ serviceName ] [ ] = substr ( $ allowedPath , 0 , strlen ( $ allowedPath ) - 1 ) ; } } } } } } }
Gets all allowed storage paths based on RBAC
50,895
protected function addResourceFiles ( ) { foreach ( $ this -> data as $ service => $ resources ) { foreach ( $ resources as $ resourceName => $ records ) { $ this -> package -> zipResourceFile ( $ service . '/' . $ resourceName . '.json' , $ records ) ; } } }
Adds resource files to the package .
50,896
protected function addStorageFiles ( ) { $ items = $ this -> package -> getStorageServices ( ) ; foreach ( $ items as $ service => $ resources ) { if ( is_string ( $ resources ) ) { $ resources = explode ( ',' , $ resources ) ; } foreach ( $ resources as $ resourceName => $ resource ) { if ( $ resourceName === static :: REACHABLE_FLAG && $ resource === false ) { continue ; } if ( Session :: checkServicePermission ( Verbs :: GET , $ service , $ resource , Session :: getRequestor ( ) , false ) ) { $ storage = ServiceManager :: getService ( $ service ) ; if ( ! $ storage ) { throw new InternalServerErrorException ( "Can not find storage service $service." ) ; } if ( $ storage -> folderExists ( $ resource ) ) { $ zippedResource = $ this -> getStorageFolderZip ( $ storage , $ resource ) ; if ( $ zippedResource !== false ) { $ newFileName = $ service . '/' . rtrim ( $ resource , '/' ) . '/' . md5 ( $ resource ) . '.zip' ; $ this -> package -> zipFile ( $ zippedResource , $ newFileName ) ; $ this -> destructible [ ] = $ zippedResource ; } } elseif ( $ storage -> fileExists ( $ resource ) ) { $ content = $ storage -> getFileContent ( $ resource , null , false ) ; $ this -> package -> zipContent ( $ service . '/' . $ resource , $ content ) ; } } } } }
Adds app files or other storage files to the package .
50,897
protected function getStorageFolderZip ( $ storage , $ resource ) { $ resource = rtrim ( $ resource , '/' ) . DIRECTORY_SEPARATOR ; $ zip = new \ ZipArchive ( ) ; $ tmpDir = rtrim ( sys_get_temp_dir ( ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; $ zipFileName = $ tmpDir . str_replace ( '/' , '_' , $ resource ) . time ( ) . '.zip' ; if ( true !== $ zip -> open ( $ zipFileName , \ ZipArchive :: CREATE ) ) { throw new InternalServerErrorException ( 'Could not create zip file for extracting ' . $ resource ) ; } if ( $ storage -> folderExists ( $ resource ) ) { $ storage -> getFolderAsZip ( $ resource , $ zip , $ zipFileName , true ) ; } else { return false ; } $ zip -> close ( ) ; return $ zipFileName ; }
Returns the path of the zip file containing app files or other storage files .
50,898
protected function generateManifest ( ) { $ manifest = $ this -> package -> getManifestHeader ( ) ; $ requestedItems = $ this -> package -> getServices ( ) ; foreach ( $ requestedItems as $ service => $ resources ) { foreach ( $ resources as $ resourceName => $ details ) { if ( isset ( $ this -> data [ $ service ] [ $ resourceName ] ) ) { $ records = $ this -> data [ $ service ] [ $ resourceName ] ; foreach ( $ records as $ i => $ record ) { $ api = $ service . '/' . $ resourceName ; switch ( $ api ) { case 'system/user' : case 'system/admin' : $ manifest [ 'service' ] [ $ service ] [ $ resourceName ] [ ] = array_get ( $ record , 'email' , array_get ( $ record , 'id' , array_get ( $ details , $ i , [ ] ) ) ) ; break ; default : $ manifest [ 'service' ] [ $ service ] [ $ resourceName ] [ ] = array_get ( $ record , 'name' , array_get ( $ record , 'id' , array_get ( $ details , $ i , [ ] ) ) ) ; break ; } } } else { $ manifest [ 'service' ] [ $ service ] [ $ resourceName ] = $ details ; } } } return $ manifest ; }
Generates the package manifest .
50,899
protected function setDefaultRelations ( $ service , $ resource , & $ params ) { $ api = $ service . '/' . $ resource ; $ relations = array_get ( $ this -> defaultRelation , $ api ) ; if ( ! empty ( $ relations ) ) { $ this -> fixDefaultRelations ( $ relations ) ; if ( ! isset ( $ params [ 'related' ] ) ) { $ params [ 'related' ] = implode ( ',' , $ relations ) ; } else { foreach ( $ relations as $ relation ) { if ( strpos ( $ params [ 'related' ] , $ relation ) === false ) { $ params [ 'related' ] .= ',' . $ relation ; } } } } }
Sets the default relations to extract for some resources .