idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
57,200
|
public function getList ( ) { $ list = new \ BearFramework \ DataList ( ) ; foreach ( $ this -> data as $ header ) { $ list [ ] = clone ( $ header ) ; } return $ list ; }
|
Returns a list of all headers .
|
57,201
|
public function make ( string $ name = null , string $ value = null ) : \ BearFramework \ App \ Request \ FormDataItem { if ( $ this -> newFormDataItemCache === null ) { $ this -> newFormDataItemCache = new \ BearFramework \ App \ Request \ FormDataItem ( ) ; } $ object = clone ( $ this -> newFormDataItemCache ) ; if ( $ name !== null ) { $ object -> name = $ name ; } if ( $ value !== null ) { $ object -> value = $ value ; } return $ object ; }
|
Constructs a new form data item and returns it .
|
57,202
|
public function set ( \ BearFramework \ App \ Request \ FormDataItem $ dataItem ) : self { $ this -> data [ $ dataItem -> name ] = $ dataItem ; return $ this ; }
|
Sets a form data item .
|
57,203
|
public function getFile ( string $ name ) : ? \ BearFramework \ App \ Request \ FormDataFileItem { if ( isset ( $ this -> data [ $ name ] ) && $ this -> data [ $ name ] instanceof \ BearFramework \ App \ Request \ FormDataFileItem ) { return $ this -> data [ $ name ] ; } return null ; }
|
Returns a file data item or null if not found .
|
57,204
|
public function getList ( ) { $ list = new \ BearFramework \ DataList ( ) ; foreach ( $ this -> data as $ formDataItem ) { $ list [ ] = clone ( $ formDataItem ) ; } return $ list ; }
|
Returns a list of all form data items .
|
57,205
|
public function get ( string $ filename = null ) : \ BearFramework \ App \ Context { if ( $ filename === null ) { $ trace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 1 ) ; if ( ! isset ( $ trace [ 0 ] ) ) { throw new \ Exception ( 'Cannot detect context!' ) ; } $ filename = $ trace [ 0 ] [ 'file' ] ; } $ filename = \ BearFramework \ Internal \ Utilities :: normalizePath ( $ filename ) ; if ( isset ( $ this -> objectsCache [ $ filename ] ) ) { return clone ( $ this -> objectsCache [ $ filename ] ) ; } $ matchedDir = null ; foreach ( $ this -> dirs as $ dir => $ length ) { if ( $ dir === $ filename . '/' || substr ( $ filename , 0 , $ length ) === $ dir ) { $ matchedDir = $ dir ; break ; } } if ( $ matchedDir !== null ) { if ( isset ( $ this -> objectsCache [ $ matchedDir ] ) ) { return clone ( $ this -> objectsCache [ $ matchedDir ] ) ; } $ this -> objectsCache [ $ matchedDir ] = new App \ Context ( $ this -> app , substr ( $ matchedDir , 0 , - 1 ) ) ; $ this -> objectsCache [ $ filename ] = clone ( $ this -> objectsCache [ $ matchedDir ] ) ; return clone ( $ this -> objectsCache [ $ matchedDir ] ) ; } throw new \ Exception ( 'Connot find context for ' . $ filename ) ; }
|
Returns a context object for the filename specified .
|
57,206
|
public function add ( string $ dir ) : self { $ dir = rtrim ( \ BearFramework \ Internal \ Utilities :: normalizePath ( $ dir ) , '/' ) . '/' ; if ( ! isset ( $ this -> dirs [ $ dir ] ) ) { $ this -> dirs [ $ dir ] = strlen ( $ dir ) ; arsort ( $ this -> dirs ) ; $ indexFilename = $ dir . 'index.php' ; if ( is_file ( $ indexFilename ) ) { ob_start ( ) ; try { ( static function ( $ __filename ) { include $ __filename ; } ) ( $ indexFilename ) ; ob_end_clean ( ) ; } catch ( \ Exception $ e ) { ob_end_clean ( ) ; throw $ e ; } } else { throw new \ Exception ( 'Cannot find index.php file in the dir specified (' . $ dir . ')!' ) ; } } return $ this ; }
|
Registers a new context .
|
57,207
|
public function fetchMessages ( ) { $ messages = $ this -> client -> get ( "inboxes/{$this->config['inbox_id']}/messages" ) -> getBody ( ) ; if ( $ messages instanceof Stream ) { $ messages = $ messages -> getContents ( ) ; } $ messages = json_decode ( $ messages , true ) ; foreach ( $ messages as $ key => $ message ) { $ messages [ $ key ] = new MailtrapMessage ( $ message , $ this -> client ) ; } return $ messages ; }
|
Get the most recent message of the default inbox .
|
57,208
|
public function fetchLastMessages ( $ number = 1 ) { $ messages = $ this -> fetchMessages ( ) ; $ firstIndex = count ( $ messages ) - $ number ; $ messages = array_slice ( $ messages , $ firstIndex , $ number ) ; $ this -> assertCount ( $ number , $ messages ) ; return $ messages ; }
|
Get the most recent messages of the default inbox .
|
57,209
|
public function fetchAttachmentsOfLastMessage ( ) { $ email = $ this -> fetchLastMessage ( ) ; $ response = $ this -> client -> get ( "inboxes/{$this->config['inbox_id']}/messages/{$email->id}/attachments" ) -> getBody ( ) ; return json_decode ( $ response , true ) ; }
|
Gets the attachments on the last message .
|
57,210
|
public function seeInEmailSubject ( $ expected ) { $ email = $ this -> fetchLastMessage ( ) ; $ this -> assertContains ( $ expected , $ email -> subject , 'Email subject contains text' ) ; }
|
Look for a string in the most recent email subject .
|
57,211
|
public function getBccEmailOfMessage ( $ messageId ) { $ message = $ this -> client -> get ( "inboxes/{$this->config['inbox_id']}/messages/$messageId/body.eml" ) -> getBody ( ) ; if ( $ message instanceof Stream ) { $ message = $ message -> getContents ( ) ; } $ matches = [ ] ; preg_match ( '/Bcc:\s[\w.-]+@[\w.-]+\.[a-z]{2,6}/' , $ message , $ matches ) ; $ bcc = substr ( array_shift ( $ matches ) , 5 ) ; return $ bcc ; }
|
Get the bcc property of a message
|
57,212
|
public function waitForEmail ( $ timeout = 5 ) { $ condition = function ( ) { return ! empty ( $ this -> fetchLastMessage ( ) ) ; } ; $ message = sprintf ( 'Waited for %d secs but no email has arrived' , $ timeout ) ; $ this -> wait ( $ timeout ) -> until ( $ condition , $ message ) ; }
|
Wait until an email to be received .
|
57,213
|
public function setConfig ( array $ configs = array ( ) ) { foreach ( $ configs as $ config_key => $ config ) { switch ( $ config_key ) { case 'table-striped' : $ this -> table_striped = $ config ; break ; case 'table-bordered' : $ this -> table_bordered = $ config ; break ; case 'table-hover' : $ this -> table_hover = $ config ; break ; case 'table-condensed' : $ this -> table_condensed = $ config ; break ; case 'table-responsive' : $ this -> table_responsive = $ config ; break ; case 'id' : $ this -> id = $ config ; break ; default : throw new \ InvalidArgumentException ( ) ; break ; } } }
|
Set the configuration of the table
|
57,214
|
public function setHeader ( array $ header_cols ) { $ this -> header = new TableHeader ( $ header_cols ) ; $ this -> updateMaxRowLength ( $ this -> header ) ; }
|
Set the header of the table
|
57,215
|
public function addRows ( array $ rows , array $ classes = array ( ) ) { $ table_row = new TableRow ( $ rows , $ classes ) ; $ this -> rows [ ] = $ table_row ; $ this -> updateMaxRowLength ( $ table_row ) ; }
|
Add a row to the table
|
57,216
|
protected function updateMaxRowLength ( $ table_line ) { $ length = $ table_line -> getLength ( ) ; if ( $ length > $ this -> max_length_rows ) { $ this -> max_length_rows = $ length ; } return $ this -> max_length_rows ; }
|
Update the max lenght of rows in the table
|
57,217
|
protected function fillWithEmptyCells ( $ table_row , $ tag_row ) { $ html = '' ; if ( ! ( $ table_row instanceof TableLine ) ) { throw new \ InvalidArgumentException ; } $ length_row = $ table_row -> getLength ( ) ; $ diff = $ this -> max_length_rows - $ length_row ; if ( $ diff > 0 ) { foreach ( range ( 1 , $ diff ) as $ key ) { $ html .= "\t\t\t<{$tag_row}></{$tag_row}>\n" ; } } $ html .= "\t\t</tr>\n" ; return $ html ; }
|
Fill the rest of the row with empty cells
|
57,218
|
protected function getTableClasses ( ) { $ classes = "" ; if ( $ this -> table_striped ) { $ classes .= "table-striped " ; } if ( $ this -> table_bordered ) { $ classes .= "table-bordered " ; } if ( $ this -> table_hover ) { $ classes .= "table-hover " ; } if ( $ this -> table_condensed ) { $ classes .= "table-condensed " ; } $ classes .= $ this -> getTableExtraClassesString ( ) ; return $ classes ; }
|
Get the classes in string format separated by a space
|
57,219
|
protected function getTableExtraClassesString ( ) { $ classes_html = '' ; if ( ! empty ( $ this -> table_extra_classes ) ) { foreach ( $ this -> table_extra_classes as $ class ) { $ classes_html .= "{$class} " ; } } return $ classes_html ; }
|
Return the extra classes as concatenated strings
|
57,220
|
public function setTableExtraClasses ( $ classes = array ( ) ) { if ( ! empty ( $ classes ) ) { foreach ( $ classes as $ class ) { if ( str_word_count ( $ class ) > 1 ) { throw new \ InvalidArgumentException ; } } $ this -> table_extra_classes = $ classes ; } }
|
Add extra classes to the table
|
57,221
|
public function getHtml ( ) { $ html = "" ; $ table_classes = $ this -> getTableClasses ( ) ; if ( $ this -> table_responsive ) { $ html .= "<div class=\"table-responsive\">\n" ; } $ id_tag = $ this -> getTagId ( ) ; $ html .= "<table {$id_tag} class=\"table {$table_classes}\">\n" ; if ( isset ( $ this -> header ) ) { $ html .= "\t<thead>\n" ; $ html .= $ this -> header -> getHtml ( ) ; $ html .= $ this -> fillWithEmptyCells ( $ this -> header , $ this -> header -> getTagRow ( ) ) ; $ html .= "\t</thead>\n" ; } if ( isset ( $ this -> rows ) ) { $ html .= "\t<tbody>\n" ; foreach ( $ this -> rows as $ row ) { $ html .= $ row -> getHtml ( ) ; $ html .= $ this -> fillWithEmptyCells ( $ row , $ row -> getTagRow ( ) ) ; } $ html .= "\t</tbody>\n" ; } $ html .= "</table>\n" ; if ( $ this -> table_responsive ) { $ html .= "</div>\n" ; } return $ html ; }
|
Return the table as Html
|
57,222
|
public function scopeLive ( $ query ) { return $ query -> where ( $ this -> getTable ( ) . '.status' , '=' , Post :: APPROVED ) -> where ( $ this -> getTable ( ) . '.published_date' , '<=' , \ Carbon \ Carbon :: now ( ) ) ; }
|
Query scope for live posts adds conditions for status = APPROVED and published date is in the past
|
57,223
|
public function scopeByYearMonth ( $ query , $ year , $ month ) { return $ query -> where ( \ DB :: raw ( 'DATE_FORMAT(published_date, "%Y%m")' ) , '=' , $ year . $ month ) ; }
|
Query scope for posts published within the given year and month number .
|
57,224
|
public function getImage ( $ type , $ size , array $ attributes = array ( ) ) { if ( empty ( $ this -> $ type ) ) { return null ; } $ html = '<img src="' . $ this -> getImageSrc ( $ type , $ size ) . '"' ; $ html .= ' alt="' . $ this -> { $ type . '_alt' } . '"' ; $ html .= ' width="' . $ this -> getImageWidth ( $ type , $ size ) . '"' ; $ html .= ' height="' . $ this -> getImageHeight ( $ type , $ size ) . '"' ; $ html_attributes = '' ; if ( ! empty ( $ attributes ) ) { $ html_attributes = join ( ' ' , array_map ( function ( $ key ) use ( $ attributes ) { if ( is_bool ( $ attributes [ $ key ] ) ) { return $ attributes [ $ key ] ? $ key : '' ; } return "{$key}=\"{$attributes[$key]}\"" ; } , array_keys ( $ attributes ) ) ) ; } return $ html ; }
|
Returns the HTML img tag for the requested image type and size for this item
|
57,225
|
public function getImageSrc ( $ type , $ size ) { if ( empty ( $ this -> $ type ) ) { return null ; } return $ this -> getImageConfig ( $ type , $ size , 'dir' ) . $ this -> $ type ; }
|
Returns the value for use in the src attribute of an img tag for the given image type and size
|
57,226
|
public function getImageWidth ( $ type , $ size ) { if ( empty ( $ this -> $ type ) ) { return null ; } $ method = $ this -> getImageConfig ( $ type , $ size , 'method' ) ; if ( in_array ( $ method , array ( 'portrait' , 'auto' , 'fit' , 'crop' ) ) ) { list ( $ width ) = $ this -> getImageDimensions ( $ type , $ size ) ; return $ width ; } return $ this -> getImageConfig ( $ type , $ size , 'width' ) ; }
|
Returns the value for use in the width attribute of an img tag for the given image type and size
|
57,227
|
public function getImageHeight ( $ type , $ size ) { if ( empty ( $ this -> $ type ) ) { return null ; } $ method = $ this -> getImageConfig ( $ type , $ size , 'method' ) ; if ( in_array ( $ method , array ( 'landscape' , 'auto' , 'fit' , 'crop' ) ) ) { list ( $ width , $ height ) = $ this -> getImageDimensions ( $ type , $ size ) ; return $ height ; } return $ this -> getImageConfig ( $ type , $ size , 'height' ) ; }
|
Returns the value for use in the height attribute of an img tag for the given image type and size
|
57,228
|
public function getImageConfig ( $ imageType , $ size , $ property ) { $ config = $ this -> getConfigPrefix ( ) . 'images.' . $ imageType . '.' ; if ( $ size == 'original' ) { $ config .= 'original.' ; } elseif ( ! is_null ( $ size ) ) { $ config .= 'sizes.' . $ size . '.' ; } $ config .= $ property ; return \ Config :: get ( $ config ) ; }
|
Returns the config setting for an image
|
57,229
|
public function newer ( ) { return $ this -> live ( ) -> where ( 'published_date' , '>=' , $ this -> published_date ) -> where ( 'id' , '<>' , $ this -> id ) -> orderBy ( 'published_date' , 'asc' ) -> orderBy ( 'id' , 'asc' ) -> first ( ) ; }
|
Returns the next newer post relative to the current one if it exists
|
57,230
|
public function older ( ) { return $ this -> live ( ) -> where ( 'published_date' , '<=' , $ this -> published_date ) -> where ( 'id' , '<>' , $ this -> id ) -> orderBy ( 'published_date' , 'desc' ) -> orderBy ( 'id' , 'desc' ) -> first ( ) ; }
|
Returns the next older post relative to the current one if it exists
|
57,231
|
public function add ( string $ class , string $ filename ) : self { if ( substr ( $ class , - 2 ) === '\*' ) { $ this -> patterns [ ] = [ substr ( $ class , 0 , - 1 ) , $ filename ] ; } else { $ this -> classes [ $ class ] = $ filename ; } return $ this ; }
|
Registers a class for autoloading .
|
57,232
|
public function load ( string $ class ) : self { $ filename = $ this -> getFilename ( $ class ) ; if ( $ filename !== null ) { ( static function ( $ __filename ) { include_once $ __filename ; } ) ( $ filename ) ; } return $ this ; }
|
Loads a class if registered .
|
57,233
|
public function addEventListener ( string $ name , callable $ listener ) : self { if ( ! isset ( $ this -> internalEventListenersData [ $ name ] ) ) { $ this -> internalEventListenersData [ $ name ] = [ ] ; } $ this -> internalEventListenersData [ $ name ] [ ] = $ listener ; return $ this ; }
|
Registers a new event listener .
|
57,234
|
public function removeEventListener ( string $ name , callable $ listener ) : self { if ( isset ( $ this -> internalEventListenersData [ $ name ] ) ) { foreach ( $ this -> internalEventListenersData [ $ name ] as $ i => $ value ) { if ( $ value === $ listener ) { unset ( $ this -> internalEventListenersData [ $ name ] [ $ i ] ) ; if ( empty ( $ this -> internalEventListenersData [ $ name ] ) ) { unset ( $ this -> internalEventListenersData [ $ name ] ) ; } break ; } } } return $ this ; }
|
Removes a registered event listener .
|
57,235
|
public function make ( string $ name = null , string $ value = null ) : \ BearFramework \ App \ Request \ QueryItem { if ( $ this -> newQueryItemCache === null ) { $ this -> newQueryItemCache = new \ BearFramework \ App \ Request \ QueryItem ( ) ; } $ object = clone ( $ this -> newQueryItemCache ) ; if ( $ name !== null ) { $ object -> name = $ name ; } if ( $ value !== null ) { $ object -> value = $ value ; } return $ object ; }
|
Constructs a new query item and returns it .
|
57,236
|
public function set ( \ BearFramework \ App \ Request \ QueryItem $ queryItem ) : self { $ this -> data [ $ queryItem -> name ] = $ queryItem ; return $ this ; }
|
Sets a query item .
|
57,237
|
public function getList ( ) { $ list = new \ BearFramework \ DataList ( ) ; foreach ( $ this -> data as $ queryItem ) { $ list [ ] = clone ( $ queryItem ) ; } return $ list ; }
|
Returns a list of all query items .
|
57,238
|
public function toString ( ) { $ temp = [ ] ; foreach ( $ this -> data as $ queryItem ) { $ temp [ $ queryItem -> name ] = $ queryItem -> value ; } return http_build_query ( $ temp ) ; }
|
Returns the query items as string .
|
57,239
|
public function add ( string $ class , string $ filename ) : self { $ this -> appClasses -> add ( $ class , $ this -> dir . '/' . $ filename ) ; return $ this ; }
|
Registers a class for autoloading in the current context .
|
57,240
|
public function getMessageData ( $ key ) { if ( $ this -> { $ key } ) { return $ this -> { $ key } ; } $ data_key = str_replace ( [ 'text_body' , 'html_body' ] , [ 'txt_path' , 'html_path' ] , $ key ) ; $ data = $ this -> retrieveMessageData ( $ data_key ) ; if ( ! $ data ) { return '' ; } $ this -> { $ key } = $ data ; return $ data ; }
|
Get the body data for a message
|
57,241
|
protected function retrieveMessageData ( $ key ) { $ data = $ this -> client -> get ( $ this -> data [ $ key ] ) -> getBody ( ) ; if ( $ data instanceof Stream ) { return $ data -> getContents ( ) ; } return false ; }
|
Retrieve the body data from the MailTrap API
|
57,242
|
protected function getHostChunks ( Request $ request ) { $ host = parse_url ( $ request -> getHostInfo ( ) , PHP_URL_HOST ) ; return explode ( self :: SEPARATOR_HOST , $ host ) ; }
|
Returns the Host header value splitted by the separator .
|
57,243
|
protected function setQueryParam ( Request $ request , $ value ) { $ queryParams = $ request -> getQueryParams ( ) ; $ queryParams [ $ this -> queryParam ] = $ value ; $ request -> setQueryParams ( $ queryParams ) ; }
|
Sets the query parameter that contains a language .
|
57,244
|
protected function isBlacklisted ( $ pathInfo ) { $ pathInfo = ltrim ( $ pathInfo , self :: SEPARATOR_PATH ) ; foreach ( $ this -> blacklist as $ pattern ) { if ( preg_match ( $ pattern , $ pathInfo ) ) { return true ; } } return false ; }
|
Returns whether the path info is blacklisted .
|
57,245
|
protected function getHtmlClasses ( ) { $ classes = '' ; if ( ! empty ( $ this -> css_classes ) ) { $ classes .= " class=\"" ; foreach ( $ this -> css_classes as $ class ) { $ classes .= "{$class} " ; } $ classes .= "\"" ; } return $ classes ; }
|
Return the custom classes as html attribute
|
57,246
|
public function getImpersonatingUser ( ) { if ( $ this -> isGranted ( 'ROLE_PREVIOUS_ADMIN' ) ) { foreach ( $ this -> tokenStorage -> getToken ( ) -> getRoles ( ) as $ role ) { if ( $ role instanceof SwitchUserRole ) { return $ role -> getSource ( ) -> getUser ( ) ; } } } }
|
When impersonating a user it returns the original user who started the impersonation .
|
57,247
|
public function isPasswordValid ( $ plainPassword , $ user = null ) { $ user = $ user ? : $ this -> getUser ( ) ; return $ this -> passwordEncoder -> isPasswordValid ( $ user , $ plainPassword ) ; }
|
Returns true if the given plain password is valid for the current application user or the optionally given user .
|
57,248
|
public function getSegment ( $ index ) : ? string { $ path = trim ( $ this -> path , '/' ) ; if ( isset ( $ path { 0 } ) ) { $ parts = explode ( '/' , $ path ) ; if ( array_key_exists ( $ index , $ parts ) ) { return $ parts [ $ index ] ; } } return null ; }
|
Returns the value of the path segment for the index specified or null if not found .
|
57,249
|
public function getDataItemStreamWrapper ( string $ key ) : \ BearFramework \ App \ IDataItemStreamWrapper { return new \ BearFramework \ App \ FileDataItemStreamWrapper ( $ key , $ this -> dir ) ; }
|
Returns a DataItemStreamWrapper for the key specified .
|
57,250
|
public function multiply ( Fraction $ fraction ) { $ numerator = $ this -> getNumerator ( ) * $ fraction -> getNumerator ( ) ; $ denominator = $ this -> getDenominator ( ) * $ fraction -> getDenominator ( ) ; return new static ( $ numerator , $ denominator ) ; }
|
Multiply this fraction by a given fraction
|
57,251
|
public function divide ( Fraction $ fraction ) { $ numerator = $ this -> getNumerator ( ) * $ fraction -> getDenominator ( ) ; $ denominator = $ this -> getDenominator ( ) * $ fraction -> getNumerator ( ) ; if ( $ denominator < 0 ) { $ numerator *= - 1 ; } return new static ( $ numerator , abs ( $ denominator ) ) ; }
|
Divide this fraction by a given fraction
|
57,252
|
public function add ( Fraction $ fraction ) { $ numerator = ( $ this -> getNumerator ( ) * $ fraction -> getDenominator ( ) ) + ( $ fraction -> getNumerator ( ) * $ this -> getDenominator ( ) ) ; $ denominator = $ this -> getDenominator ( ) * $ fraction -> getDenominator ( ) ; return new static ( $ numerator , $ denominator ) ; }
|
Add this fraction to a given fraction
|
57,253
|
public function subtract ( Fraction $ fraction ) { $ numerator = ( $ this -> getNumerator ( ) * $ fraction -> getDenominator ( ) ) - ( $ fraction -> getNumerator ( ) * $ this -> getDenominator ( ) ) ; $ denominator = $ this -> getDenominator ( ) * $ fraction -> getDenominator ( ) ; return new static ( $ numerator , $ denominator ) ; }
|
Subtract a given fraction from this fraction
|
57,254
|
public static function fromFloat ( $ float ) { if ( is_int ( $ float ) ) { return new self ( $ float ) ; } if ( ! is_numeric ( $ float ) ) { throw new InvalidArgumentException ( 'Argument passed is not a numeric value.' ) ; } $ float = rtrim ( sprintf ( '%.8F' , $ float ) , '0' ) ; $ denominator = strstr ( $ float , '.' ) ; $ denominator = ( int ) str_pad ( '1' , strlen ( $ denominator ) , '0' ) ; $ numerator = ( int ) ( $ float * $ denominator ) ; return new self ( $ numerator , $ denominator ) ; }
|
Create from float
|
57,255
|
public function addDir ( string $ pathname ) : self { $ this -> dirs [ ] = $ pathname ; $ this -> optimizedDirs = null ; return $ this ; }
|
Registers a directory that will be publicly accessible .
|
57,256
|
public function getContent ( string $ filename , array $ options = [ ] ) : ? string { if ( ! empty ( $ options ) ) { $ this -> validateOptions ( $ options ) ; } $ urlOptions = [ ] ; if ( isset ( $ options [ 'width' ] ) ) { $ urlOptions [ 'width' ] = $ options [ 'width' ] ; } if ( isset ( $ options [ 'height' ] ) ) { $ urlOptions [ 'height' ] = $ options [ 'height' ] ; } if ( isset ( $ options [ 'outputType' ] ) ) { $ urlOptions [ 'outputType' ] = $ options [ 'outputType' ] ; } $ url = $ this -> getURL ( $ filename , $ urlOptions ) ; $ path = substr ( $ url , strlen ( $ this -> app -> request -> base ) ) ; $ request = new \ BearFramework \ App \ Request ( ) ; $ request -> path -> set ( $ path ) ; $ response = $ this -> getResponse ( $ request ) ; if ( $ response === null ) { return null ; } $ content = file_get_contents ( $ response -> filename ) ; if ( isset ( $ options [ 'encoding' ] ) ) { if ( $ options [ 'encoding' ] === 'base64' ) { return base64_encode ( $ content ) ; } elseif ( $ options [ 'encoding' ] === 'data-uri' ) { $ mimeType = $ this -> getMimeType ( $ filename ) ; return 'data:' . $ mimeType . ',' . $ content ; } elseif ( $ options [ 'encoding' ] === 'data-uri-base64' ) { $ mimeType = $ this -> getMimeType ( $ filename ) ; return 'data:' . $ mimeType . ';base64,' . base64_encode ( $ content ) ; } else { throw new \ InvalidArgumentException ( 'Unsupported encoding type (' . $ options [ 'encoding' ] . ')' ) ; } } return $ content ; }
|
Returns the content of the file specified .
|
57,257
|
private function prepare ( string $ filename , array $ options = [ ] ) : ? string { if ( ! empty ( $ options ) ) { $ this -> validateOptions ( $ options ) ; } $ result = null ; if ( $ this -> hasEventListeners ( 'beforePrepare' ) ) { $ eventDetails = new \ BearFramework \ App \ Assets \ BeforePrepareEventDetails ( $ filename , $ options ) ; $ this -> dispatchEvent ( 'beforePrepare' , $ eventDetails ) ; $ filename = $ eventDetails -> filename ; $ options = $ eventDetails -> options ; } if ( strlen ( $ filename ) > 0 && is_file ( $ filename ) ) { if ( ! isset ( $ options [ 'width' ] ) && ! isset ( $ options [ 'height' ] ) ) { $ result = $ filename ; } else { $ extension = pathinfo ( $ filename , PATHINFO_EXTENSION ) ; if ( $ extension === '' ) { $ extension = 'tmp' ; } if ( isset ( $ options [ 'outputType' ] ) ) { $ extension = $ options [ 'outputType' ] ; } $ tempFilename = $ this -> app -> data -> getFilename ( '.temp/assets/' . md5 ( md5 ( $ filename ) . md5 ( json_encode ( $ options ) ) ) . '.' . $ extension ) ; if ( ! is_file ( $ tempFilename ) ) { $ this -> resize ( $ filename , $ tempFilename , [ 'width' => ( isset ( $ options [ 'width' ] ) ? $ options [ 'width' ] : null ) , 'height' => ( isset ( $ options [ 'height' ] ) ? $ options [ 'height' ] : null ) ] ) ; } $ result = $ tempFilename ; } } if ( $ this -> hasEventListeners ( 'prepare' ) ) { $ eventDetails = new \ BearFramework \ App \ Assets \ PrepareEventDetails ( $ filename , $ options , $ result ) ; $ this -> dispatchEvent ( 'prepare' , $ eventDetails ) ; $ result = $ eventDetails -> returnValue ; } return $ result ; }
|
Prepares a local filename that will be returned for the file requested .
|
57,258
|
public function getDetails ( string $ filename , array $ list ) : array { $ result = null ; if ( $ this -> hasEventListeners ( 'beforeGetDetails' ) ) { $ eventDetails = new \ BearFramework \ App \ Assets \ BeforeGetDetailsEventDetails ( $ filename , $ list ) ; $ this -> dispatchEvent ( 'beforeGetDetails' , $ eventDetails ) ; $ filename = $ eventDetails -> filename ; $ list = $ eventDetails -> list ; if ( $ eventDetails -> returnValue !== null ) { $ result = $ eventDetails -> returnValue ; } } if ( $ result === null ) { $ result = [ ] ; $ temp = array_flip ( $ list ) ; if ( isset ( $ temp [ 'mimeType' ] ) ) { $ result [ 'mimeType' ] = $ this -> getMimeType ( $ filename ) ; } if ( isset ( $ temp [ 'width' ] ) || isset ( $ temp [ 'height' ] ) || isset ( $ temp [ 'size' ] ) ) { $ fileExists = is_file ( $ filename ) ; } if ( isset ( $ temp [ 'width' ] ) || isset ( $ temp [ 'height' ] ) ) { if ( $ fileExists ) { $ imageSize = $ this -> getImageSize ( $ filename ) ; } if ( isset ( $ temp [ 'width' ] ) ) { $ result [ 'width' ] = $ fileExists ? $ imageSize [ 0 ] : null ; } if ( isset ( $ temp [ 'height' ] ) ) { $ result [ 'height' ] = $ fileExists ? $ imageSize [ 1 ] : null ; } } if ( isset ( $ temp [ 'size' ] ) ) { $ result [ 'size' ] = $ fileExists ? filesize ( $ filename ) : null ; } } if ( $ this -> hasEventListeners ( 'getDetails' ) ) { $ eventDetails = new \ BearFramework \ App \ Assets \ GetDetailsEventDetails ( $ filename , $ list , $ result ) ; $ this -> dispatchEvent ( 'getDetails' , $ eventDetails ) ; $ result = $ eventDetails -> returnValue ; } return $ result ; }
|
Returns a list of details for the filename specified .
|
57,259
|
public static function get ( $ key = null ) { if ( null === self :: $ instance ) { self :: $ instance = new self ( ) ; } return $ key ? self :: $ instance [ $ key ] : self :: $ instance ; }
|
Returns the application singleton .
|
57,260
|
public function registerUpdater ( ) { $ this -> register ( new UpdateServiceProvider ( ) , array ( 'update_url' => '@manifest_url@' ) ) ; $ app = $ this ; $ command = $ this -> add ( 'update' , function ( InputInterface $ input , OutputInterface $ output ) use ( $ app ) { $ output -> writeln ( 'Looking for updates...' ) ; $ console = $ app [ 'console' ] ; $ updated = $ app [ 'update' ] ( $ console -> getVersion ( ) , ! $ input -> getOption ( 'upgrade' ) , $ input -> getOption ( 'pre-release' ) ) ; if ( $ updated ) { $ output -> writeln ( '<info>Updated successfully.</info>' ) ; } else { $ output -> writeln ( '<comment>Already up-to-date.</comment>' ) ; } } ) ; $ command -> addOption ( 'pre-release' , 'p' , InputOption :: VALUE_NONE , 'Allow pre-release updates.' ) ; $ command -> addOption ( 'upgrade' , 'u' , InputOption :: VALUE_NONE , 'Allow upgrade to next major release.' ) ; return $ this ; }
|
Allows the application to be updated .
|
57,261
|
public function enableErrorHandler ( array $ options = [ ] ) : void { if ( $ this -> errorHandlerEnabled ) { throw new \ Exception ( 'The error handler is already enabled!' ) ; } set_exception_handler ( function ( $ exception ) use ( $ options ) { \ BearFramework \ Internal \ ErrorHandler :: handleException ( $ this , $ exception , $ options ) ; } ) ; register_shutdown_function ( function ( ) use ( $ options ) { $ errorData = error_get_last ( ) ; if ( is_array ( $ errorData ) ) { \ BearFramework \ Internal \ ErrorHandler :: handleFatalError ( $ this , $ errorData , $ options ) ; } } ) ; set_error_handler ( function ( $ errorNumber , $ errorMessage , $ errorFile , $ errorLine ) { throw new \ ErrorException ( $ errorMessage , 0 , $ errorNumber , $ errorFile , $ errorLine ) ; } ) ; $ this -> errorHandlerEnabled = true ; }
|
Enables an error handler .
|
57,262
|
public function run ( ) : void { $ response = $ this -> routes -> getResponse ( $ this -> request ) ; if ( ! ( $ response instanceof App \ Response ) ) { $ response = new App \ Response \ NotFound ( ) ; } $ this -> send ( $ response ) ; }
|
Call this method to find the response in the registered routes and send it .
|
57,263
|
public function send ( \ BearFramework \ App \ Response $ response ) : void { if ( $ this -> hasEventListeners ( 'beforeSendResponse' ) ) { $ this -> dispatchEvent ( 'beforeSendResponse' , new \ BearFramework \ App \ BeforeSendResponseEventDetails ( $ response ) ) ; } if ( ! $ response -> headers -> exists ( 'Content-Length' ) ) { $ response -> headers -> set ( $ response -> headers -> make ( 'Content-Length' , ( $ response instanceof App \ Response \ FileReader ? ( string ) filesize ( $ response -> filename ) : ( string ) strlen ( $ response -> content ) ) ) ) ; } if ( ! $ response -> headers -> exists ( 'Cache-Control' ) ) { $ response -> headers -> set ( $ response -> headers -> make ( 'Cache-Control' , 'no-cache, no-store, must-revalidate, private, max-age=0' ) ) ; } http_response_code ( $ response -> statusCode ) ; if ( ! headers_sent ( ) ) { $ headers = $ response -> headers -> getList ( ) ; foreach ( $ headers as $ header ) { if ( $ header -> name === 'Content-Type' && $ response -> charset !== null ) { $ header -> value .= '; charset=' . $ response -> charset ; } header ( $ header -> name . ': ' . $ header -> value ) ; } $ cookies = $ response -> cookies -> getList ( ) ; if ( $ cookies -> count ( ) > 0 ) { $ baseURLParts = parse_url ( $ this -> request -> base ) ; foreach ( $ cookies as $ cookie ) { setcookie ( $ cookie -> name , $ cookie -> value , $ cookie -> expire , $ cookie -> path === null ? ( isset ( $ baseURLParts [ 'path' ] ) ? $ baseURLParts [ 'path' ] . '/' : '/' ) : $ cookie -> path , $ cookie -> domain === null ? ( isset ( $ baseURLParts [ 'host' ] ) ? $ baseURLParts [ 'host' ] : '' ) : $ cookie -> domain , $ cookie -> secure === null ? $ this -> request -> scheme === 'https' : $ cookie -> secure , $ cookie -> httpOnly ) ; } } } if ( $ response instanceof App \ Response \ FileReader ) { readfile ( $ response -> filename ) ; } else { echo $ response -> content ; } if ( $ this -> hasEventListeners ( 'sendResponse' ) ) { $ this -> dispatchEvent ( 'sendResponse' , new \ BearFramework \ App \ SendResponseEventDetails ( $ response ) ) ; } }
|
Outputs a response .
|
57,264
|
public function getAttachmentUrls ( ) { return Collection :: make ( $ this -> event -> get ( 'attachments' ) ) -> map ( function ( $ item ) { return new File ( $ item [ 'contentUrl' ] , $ item ) ; } ) -> toArray ( ) ; }
|
Retrieve attachment urls from an incoming message .
|
57,265
|
public function set ( string $ key , $ value , int $ ttl = null ) : void { $ keyMD5 = md5 ( $ key ) ; $ key = $ this -> keyPrefix . substr ( $ keyMD5 , 0 , 3 ) . '/' . substr ( $ keyMD5 , 3 ) . '.2' ; $ this -> dataRepository -> setValue ( $ key , gzcompress ( serialize ( [ $ ttl > 0 ? time ( ) + $ ttl : 0 , $ value ] ) ) ) ; }
|
Stores a value in the cache .
|
57,266
|
public function get ( string $ key ) { $ keyMD5 = md5 ( $ key ) ; $ value = $ this -> dataRepository -> getValue ( $ this -> keyPrefix . substr ( $ keyMD5 , 0 , 3 ) . '/' . substr ( $ keyMD5 , 3 ) . '.2' ) ; if ( $ value !== null ) { try { $ value = unserialize ( gzuncompress ( $ value ) ) ; if ( $ value [ 0 ] > 0 ) { if ( $ value [ 0 ] > time ( ) ) { return $ value [ 1 ] ; } return null ; } return $ value [ 1 ] ; } catch ( \ Exception $ e ) { } } return null ; }
|
Retrieves a value from the cache .
|
57,267
|
public function delete ( string $ key ) : void { $ keyMD5 = md5 ( $ key ) ; $ this -> dataRepository -> delete ( $ this -> keyPrefix . substr ( $ keyMD5 , 0 , 3 ) . '/' . substr ( $ keyMD5 , 3 ) . '.2' ) ; }
|
Deletes a value from the cache .
|
57,268
|
public function setMultiple ( array $ items , int $ ttl = null ) : void { foreach ( $ items as $ key => $ value ) { $ this -> set ( $ key , $ value , $ ttl ) ; } }
|
Stores multiple values in the cache .
|
57,269
|
public function get ( string $ path = '/' ) { return $ this -> app -> request -> base . implode ( '/' , array_map ( 'urlencode' , explode ( '/' , $ path ) ) ) ; }
|
Constructs a url for the path specified .
|
57,270
|
public function add ( string $ name , callable $ callback ) : self { call_user_func ( $ this -> addCallback , $ name , $ callback ) ; return $ this ; }
|
Creates a new shortcut .
|
57,271
|
public function addDir ( string $ pathname ) : self { $ this -> appAssets -> addDir ( $ this -> dir . '/' . $ pathname ) ; return $ this ; }
|
Registers a directory that will be publicly accessible relative to the current addon or application location .
|
57,272
|
public function getURL ( string $ filename , array $ options = [ ] ) : string { return $ this -> appAssets -> getURL ( $ this -> dir . '/' . $ filename , $ options ) ; }
|
Returns a public URL for the specified filename in the current context .
|
57,273
|
public function getContent ( string $ filename , array $ options = [ ] ) : ? string { return $ this -> appAssets -> getContent ( $ this -> dir . '/' . $ filename , $ options ) ; }
|
Returns the content of the file specified in the current context .
|
57,274
|
public function getDetails ( string $ filename , array $ list ) : array { return $ this -> appAssets -> getDetails ( $ this -> dir . '/' . $ filename , $ list ) ; }
|
Returns a list of details for the filename specifie in the current context .
|
57,275
|
public function getURL ( ) : ? string { if ( $ this -> base !== null ) { $ list = [ ] ; $ queryList = $ this -> query -> getList ( ) ; foreach ( $ queryList as $ queryItem ) { $ list [ $ queryItem -> name ] = $ queryItem -> value ; } return $ this -> base . implode ( '/' , array_map ( 'urlencode' , explode ( '/' , ( string ) $ this -> path ) ) ) . ( empty ( $ list ) ? '' : '?' . http_build_query ( $ list ) ) ; } return null ; }
|
Returns the request URL or null if the base is empty .
|
57,276
|
public function add ( $ pattern , $ callback ) : self { if ( is_string ( $ pattern ) ) { if ( ! isset ( $ pattern { 0 } ) ) { throw new \ InvalidArgumentException ( 'The pattern argument must be a not empty string or array of not empty strings' ) ; } $ pattern = [ $ pattern ] ; } elseif ( is_array ( $ pattern ) ) { if ( empty ( $ pattern ) ) { throw new \ InvalidArgumentException ( 'The pattern argument must be a not empty string or array of not empty strings' ) ; } foreach ( $ pattern as $ _pattern ) { if ( ! is_string ( $ _pattern ) ) { throw new \ InvalidArgumentException ( 'The pattern argument must be a not empty string or array of not empty strings' ) ; } if ( ! isset ( $ _pattern { 0 } ) ) { throw new \ InvalidArgumentException ( 'The pattern argument must be a not empty string or array of not empty strings' ) ; } } } else { throw new \ InvalidArgumentException ( 'The pattern argument must be a not empty string or array of not empty strings' ) ; } if ( is_callable ( $ callback ) ) { $ callback = [ $ callback ] ; } elseif ( is_array ( $ callback ) ) { if ( empty ( $ callback ) ) { throw new \ InvalidArgumentException ( 'The callback argument must be a valid callable or array of valid callables' ) ; } foreach ( $ callback as $ _callback ) { if ( ! is_callable ( $ _callback ) ) { throw new \ InvalidArgumentException ( 'The callback argument must be a valid callable or array of valid callables' ) ; } } } else { throw new \ InvalidArgumentException ( 'The callback argument must be a valid callable or array of valid callables' ) ; } $ this -> data [ ] = [ $ pattern , $ callback ] ; return $ this ; }
|
Registers a request handler .
|
57,277
|
public function getResponse ( \ BearFramework \ App \ Request $ request ) { $ requestPath = ( string ) $ request -> path ; $ requestMethod = $ request -> method ; foreach ( $ this -> data as $ route ) { foreach ( $ route [ 0 ] as $ pattern ) { $ matches = null ; preg_match ( '/^(?:(?:((?:[A-Z]+\|){0,}[A-Z]+) )?)(.*+)/' , $ pattern , $ matches ) ; $ patternMethods = '|' . ( $ matches [ 1 ] === '' ? 'GET' : $ matches [ 1 ] ) . '|' ; if ( strpos ( $ patternMethods , '|' . $ requestMethod . '|' ) === false ) { continue ; } $ patternPath = $ matches [ 2 ] ; if ( preg_match ( '/^' . str_replace ( [ '/' , '?' , '*' ] , [ '\/' , '[^\/]+?' , '.+?' ] , $ patternPath ) . '$/u' , $ requestPath ) === 1 ) { foreach ( $ route [ 1 ] as $ callable ) { ob_start ( ) ; try { $ response = call_user_func ( $ callable , $ request ) ; ob_end_clean ( ) ; } catch ( \ Exception $ e ) { ob_end_clean ( ) ; throw $ e ; } if ( $ response instanceof App \ Response ) { return $ response ; } } } } } if ( $ request -> method === 'HEAD' ) { $ getRequest = clone ( $ request ) ; $ getRequest -> method = 'GET' ; $ response = $ this -> getResponse ( $ getRequest ) ; if ( $ response instanceof App \ Response ) { $ response -> content = '' ; return $ response ; } } return null ; }
|
Finds the matching callback and returns its result .
|
57,278
|
public function additionalCleanup ( $ additionalFiles ) { foreach ( $ additionalFiles as $ path ) { $ dir_to_remove = $ path ; $ print_message = $ this -> io -> isVeryVerbose ( ) ; if ( is_dir ( $ dir_to_remove ) ) { if ( static :: deleteRecursive ( $ dir_to_remove ) ) { $ message = sprintf ( " <info>Removing directory '%s'</info>" , $ path ) ; } else { $ print_message = true ; $ message = sprintf ( " <error>Failure removing directory '%s'</error>." , $ path ) ; } } else { $ message = sprintf ( " Directory '%s' does not exist" , $ path ) ; } if ( $ print_message ) { $ this -> io -> write ( $ message ) ; } } if ( $ this -> io -> isVeryVerbose ( ) ) { $ this -> io -> write ( "" ) ; } }
|
Remove other files that could be possibly problematic .
|
57,279
|
protected function findPackageKey ( $ package_name ) { $ package_key = null ; if ( isset ( static :: $ packageToCleanup [ $ package_name ] ) ) { $ package_key = $ package_name ; } else { foreach ( static :: $ packageToCleanup as $ key => $ dirs ) { if ( strtolower ( $ key ) === $ package_name ) { $ package_key = $ key ; break ; } } } return $ package_key ; }
|
Find the array key for a given package name with a case - insensitive search .
|
57,280
|
protected function deleteRecursive ( $ path ) { if ( is_file ( $ path ) || is_link ( $ path ) ) { return unlink ( $ path ) ; } $ success = true ; $ dir = dir ( $ path ) ; while ( ( $ entry = $ dir -> read ( ) ) !== false ) { if ( $ entry == '.' || $ entry == '..' ) { continue ; } $ entry_path = $ path . '/' . $ entry ; $ success = static :: deleteRecursive ( $ entry_path ) && $ success ; } $ dir -> close ( ) ; return rmdir ( $ path ) && $ success ; }
|
Helper method to remove directories and the files they contain .
|
57,281
|
public function add ( string $ id ) : self { if ( ! isset ( $ this -> data [ $ id ] ) ) { $ registeredAddon = \ BearFramework \ Addons :: get ( $ id ) ; if ( $ registeredAddon === null ) { throw new \ Exception ( 'The addon ' . $ id . ' is not registered!' ) ; } $ registeredAddonOptions = $ registeredAddon -> options ; if ( isset ( $ registeredAddonOptions [ 'require' ] ) && is_array ( $ registeredAddonOptions [ 'require' ] ) ) { foreach ( $ registeredAddonOptions [ 'require' ] as $ requiredAddonID ) { if ( is_string ( $ requiredAddonID ) && ! isset ( $ this -> data [ $ requiredAddonID ] ) ) { $ this -> add ( $ requiredAddonID ) ; } } } $ dir = $ registeredAddon -> dir ; $ this -> data [ $ id ] = new \ BearFramework \ App \ Addon ( $ id , $ dir ) ; $ this -> app -> contexts -> add ( $ dir ) ; } return $ this ; }
|
Enables an addon .
|
57,282
|
public function get ( string $ id ) : ? \ BearFramework \ App \ Addon { if ( isset ( $ this -> data [ $ id ] ) ) { return clone ( $ this -> data [ $ id ] ) ; } return null ; }
|
Returns the enabled addon or null if not found .
|
57,283
|
public function getList ( ) { $ list = new \ BearFramework \ DataList ( ) ; foreach ( $ this -> data as $ addon ) { $ list [ ] = clone ( $ addon ) ; } return $ list ; }
|
Returns a list of all enabled addons .
|
57,284
|
public function populateWithClones ( $ source , array $ propertyNameMap = array ( ) , $ onlyMappedProperties = false ) { $ this -> populateInternal ( $ source , $ propertyNameMap , $ onlyMappedProperties , true ) ; }
|
Populates this instance cloning any object values that may be encountered .
|
57,285
|
public function exportGettableProperties ( array $ propertyNameMap = array ( ) , $ onlyMappedProperties = false ) { $ export = array ( ) ; $ propertyNameMap = $ this -> convertPropertyMap ( $ propertyNameMap ) ; if ( ! $ onlyMappedProperties ) { $ sourcePropertyNames = array_keys ( get_class_vars ( get_called_class ( ) ) ) ; foreach ( $ sourcePropertyNames as $ propertyName ) { if ( isset ( $ propertyNameMap [ $ propertyName ] ) || $ propertyName === 'populatableAccessorMethodNames' ) { continue ; } try { $ export [ $ propertyName ] = $ this -> getPopulatedProperty ( $ propertyName ) ; } catch ( Exception $ error ) { continue ; } } } foreach ( $ propertyNameMap as $ sourcePropertyName => $ targetPropertyName ) { $ export [ $ targetPropertyName ] = $ this -> getPopulatedProperty ( $ sourcePropertyName ) ; } return $ export ; }
|
Exports properties from this object to a plain array optionally mapping property names to array indices using a property name map - and optionally only exporting those properties whose names are included in the property name map .
|
57,286
|
private function GetLDAPConnectionOptions ( ) { if ( ! isset ( $ this -> ldapConOp ) || is_null ( $ this -> ldapConOp ) ) { $ this -> ldapConOp = [ "account_suffix" => Settings :: get ( 'eloquent-ldap.account_suffix' ) , "base_dn" => Settings :: get ( 'eloquent-ldap.base_dn' ) , "domain_controllers" => [ Settings :: get ( 'eloquent-ldap.server' ) ] , "admin_username" => Settings :: get ( 'eloquent-ldap.user_name' ) , "admin_password" => Settings :: get ( 'eloquent-ldap.password' ) , "follow_referrals" => false , ] ; if ( 'tls' === Settings :: get ( 'eloquent-ldap.secured' ) ) { $ comOpt = [ "use_ssl" => false , "use_tls" => true , "port" => Settings :: get ( 'eloquent-ldap.secured_port' ) , ] ; } else if ( 'ssl' === Settings :: get ( 'eloquent-ldap.secured' ) ) { $ comOpt = [ "use_ssl" => true , "use_tls" => false , "port" => Settings :: get ( 'eloquent-ldap.secured_port' ) , ] ; } else { $ comOpt = [ "use_ssl" => false , "use_tls" => false , "port" => Settings :: get ( 'eloquent-ldap.port' ) , ] ; } $ this -> ldapConOp = array_merge ( $ this -> ldapConOp , $ comOpt ) ; } return $ this -> ldapConOp ; }
|
Builds the LDAP connection options from the configuration files .
|
57,287
|
private function GetArrayValueOrDefault ( $ array , $ key , $ default = null ) { $ value = $ default ; try { $ value = $ array [ $ key ] ; if ( null === $ value ) { $ value = $ default ; } } catch ( Exception $ ex ) { $ value = $ default ; } return $ value ; }
|
Returns the value of a key in an array or if not found returns the default provided .
|
57,288
|
private function GetArrayIndexedValueOrDefault ( $ array , $ key , $ index , $ default = null ) { $ value = $ default ; try { $ value = $ this -> GetArrayValueOrDefault ( $ array , $ key , $ default ) ; if ( ( isset ( $ value ) ) && ( $ value !== $ default ) ) { $ value = $ value [ $ index ] ; } } catch ( Exception $ ex ) { $ value = $ default ; } return $ value ; }
|
Returns the value of a key at an index in a multi - dimensional array or if not found returns the default provided .
|
57,289
|
private function revokeMembership ( $ user ) { try { foreach ( $ user -> membershipList as $ group ) { if ( $ group -> resync_on_login ) { $ user -> membershipList ( ) -> detach ( $ group ) ; } } } catch ( \ Exception $ ex ) { Log :: error ( 'Exception revoking local group membership for user: ' . $ user -> username . ', Exception message: ' . $ ex -> getMessage ( ) ) ; Log :: error ( $ ex -> getTraceAsString ( ) ) ; } }
|
Revoke membership to all local group that are marked with resync_on_login as 1 or true .
|
57,290
|
private function handleLDAPError ( \ Adldap \ Adldap $ adldap ) { if ( false != $ adldap ) { $ adLDAPError = $ adldap -> getConnection ( ) -> getLastError ( ) ; if ( "Success" != $ adLDAPError ) { Log :: error ( 'Problem with LDAP:' . $ adLDAPError ) ; } } }
|
Logs the last LDAP error if it is not Success .
|
57,291
|
private function getSerializationFormat ( ReflectionClass $ reflectionClass ) { if ( $ this -> isPhpVersionWithBrokenSerializationFormat ( ) && $ reflectionClass -> implementsInterface ( 'Serializable' ) ) { return self :: SERIALIZATION_FORMAT_USE_UNSERIALIZER ; } return self :: SERIALIZATION_FORMAT_AVOID_UNSERIALIZER ; }
|
Verifies if the given PHP version implements the Serializable interface serialization with an incompatible serialization format . If that s the case use serialization marker C instead of O .
|
57,292
|
private function getInstantiatorsMap ( ) { $ that = $ this ; return self :: $ cachedInstantiators = self :: $ cachedInstantiators ? : new CallbackLazyMap ( function ( $ className ) use ( $ that ) { return $ that -> buildFactory ( $ className ) ; } ) ; }
|
Builds or fetches the instantiators map
|
57,293
|
private function getCloneablesMap ( ) { $ cachedInstantiators = $ this -> getInstantiatorsMap ( ) ; $ that = $ this ; return self :: $ cachedCloneables = self :: $ cachedCloneables ? : new CallbackLazyMap ( function ( $ className ) use ( $ cachedInstantiators , $ that ) { $ factory = $ cachedInstantiators -> $ className ; $ instance = $ factory ( ) ; if ( ! $ that -> isSafeToClone ( new ReflectionClass ( $ className ) ) ) { return null ; } return $ instance ; } ) ; }
|
Builds or fetches the cloneables map
|
57,294
|
public function registerApi ( ) { $ this -> app [ 'api.request' ] = $ this -> app -> share ( function ( $ app ) { $ remoteClient = new Client ( ) ; return new Api ( $ app [ 'config' ] , $ app [ 'router' ] , $ app [ 'request' ] , $ remoteClient ) ; } ) ; }
|
Register Api .
|
57,295
|
public function registerApiCallCommand ( ) { $ this -> app [ 'api.call' ] = $ this -> app -> share ( function ( $ app ) { return new Commands \ ApiCallCommand ( $ app [ 'api.request' ] ) ; } ) ; }
|
Register Api Call command .
|
57,296
|
public function make ( $ data , $ code , $ overwrite = false ) { $ status = ( preg_match ( '/^(1|2|3)/' , $ code ) ) ? 'success' : 'error' ; if ( is_object ( $ data ) ) { $ data = $ data -> toArray ( ) ; } if ( is_string ( $ data ) ) { $ data = array ( 'message' => $ data ) ; } if ( $ overwrite === true ) { $ response = $ data ; } else { $ message = $ this -> statuses [ $ code ] ; if ( isset ( $ data [ 'message' ] ) ) { $ message = $ data [ 'message' ] ; unset ( $ data [ 'message' ] ) ; } $ response = array ( 'status' => $ status , 'code' => $ code , 'message' => $ message , 'data' => $ data , 'pagination' => null ) ; if ( isset ( $ data [ 'data' ] ) ) { $ response = array_merge ( $ response , $ data ) ; } $ response = array_filter ( $ response , function ( $ value ) { return ! is_null ( $ value ) ; } ) ; if ( $ this -> config [ 'removeEmptyData' ] && empty ( $ response [ 'data' ] ) ) { unset ( $ response [ 'data' ] ) ; } } $ header = ( $ this -> config [ 'httpResponse' ] ) ? $ code : 200 ; return Response :: make ( $ response , $ header ) ; }
|
Make json data format .
|
57,297
|
public function configureRemoteClient ( $ configurations ) { foreach ( $ configurations as $ option => $ value ) { call_user_func_array ( array ( $ this -> remoteClient , 'setDefaultOption' ) , array ( $ option , $ value ) ) ; } }
|
Configure remote client for http request .
|
57,298
|
public function invokeRemote ( $ uri , $ method , $ parameters = array ( ) ) { $ remoteClient = $ this -> getRemoteClient ( ) ; $ request = call_user_func_array ( array ( $ remoteClient , $ method ) , array ( $ uri , null , $ parameters ) ) ; $ response = $ request -> send ( ) ; $ body = ( string ) $ response -> getBody ( ) ; if ( $ response -> getContentType ( ) == 'application/json' ) { if ( function_exists ( 'json_decode' ) and is_string ( $ body ) ) { $ body = json_decode ( $ body , true ) ; } } return $ body ; }
|
Invoke with remote uri .
|
57,299
|
public function setParser ( $ p ) { if ( $ p === null || $ p instanceof ParseInterface || is_callable ( $ p ) ) { $ this -> _parser = $ p ; } }
|
Set response parse handler
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.