idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
2,800
|
public function sortByDimensionName ( $ direction ) { if ( $ this -> id != '$name' && $ this -> id != '$value' ) { throw new AnalyticsDbException ( 'In order to sort by dimension name, you need to first group by dimension name or dimension value.' ) ; } $ direction = ( int ) $ direction ; if ( $ this -> id == '$name' ) { $ this -> pipeline [ '$sort' ] = [ '_id' => $ direction ] ; } else { $ this -> pipeline [ '$sort' ] = [ '_id.name' => $ direction ] ; } return $ this ; }
|
Sort records by dimension name .
|
2,801
|
public function sortByDimensionValue ( $ direction ) { if ( $ this -> id != '$value' ) { throw new AnalyticsDbException ( 'In order to sort by dimension value, you need to first group by dimension value.' ) ; } $ direction = ( int ) $ direction ; $ this -> pipeline [ '$sort' ] = [ '_id.value' => $ direction ] ; return $ this ; }
|
Sort records by dimension value .
|
2,802
|
public function loadLanguage ( $ code ) { static $ languages_seen = array ( ) ; if ( isset ( $ this -> cache [ $ code ] ) ) return ; $ filename = $ this -> dir . '/Language/messages/' . $ code . '.php' ; $ fallback = ( $ code != 'en' ) ? 'en' : false ; if ( ! file_exists ( $ filename ) ) { $ filename = $ this -> dir . '/Language/messages/en.php' ; $ cache = array ( ) ; } else { include $ filename ; $ cache = compact ( $ this -> keys ) ; } if ( ! empty ( $ fallback ) ) { if ( isset ( $ languages_seen [ $ code ] ) ) { trigger_error ( 'Circular fallback reference in language ' . $ code , E_USER_ERROR ) ; $ fallback = 'en' ; } $ language_seen [ $ code ] = true ; $ this -> loadLanguage ( $ fallback ) ; $ fallback_cache = $ this -> cache [ $ fallback ] ; foreach ( $ this -> keys as $ key ) { if ( isset ( $ cache [ $ key ] ) && isset ( $ fallback_cache [ $ key ] ) ) { if ( isset ( $ this -> mergeable_keys_map [ $ key ] ) ) { $ cache [ $ key ] = $ cache [ $ key ] + $ fallback_cache [ $ key ] ; } elseif ( isset ( $ this -> mergeable_keys_list [ $ key ] ) ) { $ cache [ $ key ] = array_merge ( $ fallback_cache [ $ key ] , $ cache [ $ key ] ) ; } } else { $ cache [ $ key ] = $ fallback_cache [ $ key ] ; } } } $ this -> cache [ $ code ] = $ cache ; return ; }
|
Loads language into the cache handles message file and fallbacks
|
2,803
|
public function setCasServer ( $ server ) { $ this -> casServer = $ server ; $ this -> guzzleClient = new Client ( [ 'base_uri' => $ server , 'cookies' => true ] ) ; }
|
Set the CAS server URL
|
2,804
|
public function setTGT ( $ tgt ) { $ this -> tgt = $ tgt ; $ this -> tgtLocation = $ this -> casServer . $ this -> casRESTcontext . '/' . $ tgt ; }
|
Accepts the Ticket - Granting Ticket from the app running the client .
|
2,805
|
public function logout ( ) { $ this -> checkTgtExists ( ) ; $ this -> guzzleClient -> delete ( $ this -> tgtLocation ) ; $ this -> tgtLocation = null ; $ this -> tgt = null ; if ( $ this -> tgtStorageLocation ) { unlink ( $ this -> tgtStorageLocation ) ; } return true ; }
|
Logout of the CAS session and destroy the TGT .
|
2,806
|
public function post ( $ service , $ headers = [ ] , $ body = '' , $ form_params = [ ] ) { return $ this -> callRestService ( 'POST' , $ service , $ headers , $ body , $ form_params ) ; }
|
Request a Service Ticket for the CAS server and perform a HTTP POST operation .
|
2,807
|
public function patch ( $ service , $ headers = [ ] , $ body = '' , $ form_params = [ ] ) { return $ this -> callRestService ( 'PATCH' , $ service , $ headers , $ body , $ form_params ) ; }
|
Request a Service Ticket for the CAS server and perform a HTTP PATCH operation .
|
2,808
|
public function head ( $ service , $ headers = [ ] , $ body = '' , $ form_params = [ ] ) { return $ this -> callRestService ( 'HEAD' , $ service , $ headers , $ body , $ form_params ) ; }
|
Request a Service Ticket for the CAS server and perform a HTTP HEAD operation .
|
2,809
|
public function put ( $ service , $ headers = [ ] , $ body = '' , $ form_params = [ ] ) { return $ this -> callRestService ( 'PUT' , $ service , $ headers , $ body , $ form_params ) ; }
|
Request a Service Ticket for the CAS server and perform a HTTP PUT operation .
|
2,810
|
public function options ( $ service , $ headers = [ ] , $ body = '' , $ form_params = [ ] ) { return $ this -> callRestService ( 'OPTIONS' , $ service , $ headers , $ body , $ form_params ) ; }
|
Request a Service Ticket for the CAS server and perform a HTTP OPTIONS operation .
|
2,811
|
public function delete ( $ service , $ headers = [ ] , $ body = '' , $ form_params = [ ] ) { return $ this -> callRestService ( 'DELETE' , $ service , $ headers , $ body , $ form_params ) ; }
|
Request a Service Ticket for the CAS server and perform a HTTP DELETE operation .
|
2,812
|
private function callRestService ( $ method , $ service , $ headers = [ ] , $ body = '' , $ form_params = [ ] ) { $ this -> checkTgtExists ( ) ; $ serviceTicket = $ this -> getServiceTicket ( $ service ) ; if ( strpos ( $ service , '?' ) === false ) { $ finalService = $ service . '?ticket=' . $ serviceTicket ; } else { $ finalService = $ service . '&ticket=' . $ serviceTicket ; } $ jar = new \ GuzzleHttp \ Cookie \ CookieJar ; $ options = [ 'cookies' => $ jar , 'body' => $ body , 'form_params' => $ form_params , 'headers' => $ this -> setGuzzleHeaders ( $ headers ) , 'verify' => $ this -> verifySSL ] ; switch ( $ method ) { case 'GET' : $ result = $ this -> guzzleClient -> get ( $ finalService , $ options ) ; break ; case 'HEAD' : $ result = $ this -> guzzleClient -> head ( $ finalService , $ options ) ; break ; case 'POST' : $ result = $ this -> guzzleClient -> post ( $ finalService , $ options ) ; break ; case 'PUT' : $ result = $ this -> guzzleClient -> put ( $ finalService , $ options ) ; break ; case 'PATCH' : $ result = $ this -> guzzleClient -> patch ( $ finalService , $ options ) ; break ; case 'DELETE' : $ result = $ this -> guzzleClient -> delete ( $ finalService , $ options ) ; break ; default : throw new \ Exception ( 'Unsupported HTTP method: ' . $ method , 500 ) ; } return $ result ; }
|
Set up and execute a REST request .
|
2,813
|
private function getServiceTicket ( $ service ) { try { $ response = $ this -> guzzleClient -> request ( 'POST' , $ this -> tgtLocation , [ 'verify' => $ this -> verifySSL , 'form_params' => [ 'service' => $ service ] ] ) ; return ( string ) $ response -> getBody ( ) ; } catch ( ClientException $ e ) { if ( $ e -> getCode ( ) == 404 ) { $ this -> login ( $ this -> tgtStorageLocation , true ) ; return $ this -> getServiceTicket ( $ service ) ; } elseif ( $ e -> getCode ( ) == 415 ) { return false ; } else { throw new \ Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } } catch ( \ Exception $ e ) { throw new \ Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
|
Request Service ticket from CAS server
|
2,814
|
public function login ( $ tgtStorageLocation = '' , $ forceAuth = false ) { if ( ( ! $ this -> casServer ) || ( ! $ this -> casPassword ) || ( ! $ this -> casUsername ) ) { throw new \ Exception ( 'CAS server and credentials must be set before calling login()' , 1 ) ; } $ this -> tgtStorageLocation = $ tgtStorageLocation ; if ( ! $ forceAuth && $ tgtStorageLocation ) { if ( file_exists ( $ tgtStorageLocation ) ) { if ( ! is_readable ( $ tgtStorageLocation ) ) { throw new \ Exception ( 'TGT storage file [' . $ tgtStorageLocation . '] is not readable!' , 500 ) ; } $ this -> loadTGTfromFile ( $ tgtStorageLocation ) ; return true ; } } try { $ response = $ this -> guzzleClient -> request ( 'POST' , $ this -> casRESTcontext , [ 'verify' => $ this -> verifySSL , 'form_params' => [ 'username' => $ this -> casUsername , 'password' => $ this -> casPassword ] ] ) ; $ responseHeaders = $ response -> getHeaders ( ) ; } catch ( ClientException $ e ) { if ( $ e -> getCode ( ) == 400 ) { return false ; } elseif ( $ e -> getCode ( ) == 415 ) { return false ; } else { throw new \ Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } } catch ( \ Exception $ e ) { throw new \ Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } if ( isset ( $ responseHeaders [ 'Location' ] [ 0 ] ) ) { $ this -> tgtLocation = $ responseHeaders [ 'Location' ] [ 0 ] ; $ this -> tgt = substr ( strrchr ( $ this -> tgtLocation , '/' ) , 1 ) ; } if ( $ tgtStorageLocation ) { $ this -> writeTGTtoFile ( $ tgtStorageLocation , $ this -> tgt ) ; } return true ; }
|
Validate credentials against the CAS server and retrieve a Ticket - Granting Ticket . If a tgtStorageLocation is specified the fle is read and the saved TGT is used instead of validating credentials . If force_auth is TRUE always validate credentials .
|
2,815
|
private function loadTGTfromFile ( $ tgtStorageLocation ) { $ tgtStorageData = json_decode ( file_get_contents ( $ tgtStorageLocation ) , true ) ; if ( $ tgtStorageData [ 'username' ] ) { $ this -> casUsername = $ tgtStorageData [ 'username' ] ; } else { throw new \ Exception ( 'TGT storage missing "username" value!' , 551 ) ; } if ( $ tgtStorageData [ 'server' ] ) { $ this -> casServer = $ tgtStorageData [ 'server' ] ; } else { throw new \ Exception ( 'TGT storage missing "server" value!' , 552 ) ; } if ( $ tgtStorageData [ 'context' ] ) { $ this -> casRESTcontext = $ tgtStorageData [ 'context' ] ; } else { throw new \ Exception ( 'TGT storage missing "context" value!' , 552 ) ; } if ( $ tgtStorageData [ 'TGT' ] ) { $ this -> tgt = $ tgtStorageData [ 'TGT' ] ; $ this -> tgtLocation = $ this -> casServer . $ this -> casRESTcontext . '/' . $ this -> tgt ; } else { throw new \ Exception ( 'TGT storage missing "TGT" value!' , 552 ) ; } }
|
Read the TGT data from a file
|
2,816
|
private function writeTGTtoFile ( $ tgtStorageLocation , $ tgt ) { $ tgtStorageData = [ 'TGT' => $ tgt , 'username' => $ this -> casUsername , 'server' => $ this -> casServer , 'context' => $ this -> casRESTcontext , 'saved' => time ( ) ] ; file_put_contents ( $ tgtStorageLocation , json_encode ( $ tgtStorageData ) ) ; }
|
Save the TGT data to a local file
|
2,817
|
public function create ( $ level , $ message ) { $ this -> next [ ] = [ 'level' => $ level , 'message' => $ message ] ; $ this -> session -> flash ( $ this -> key , $ this -> next ) ; return $ this ; }
|
Create a new flash message .
|
2,818
|
public function again ( ) { $ this -> next = $ this -> current -> map ( function ( $ item ) { return $ item -> toArray ( ) ; } ) -> merge ( $ this -> next ) -> toArray ( ) ; $ this -> session -> keep ( [ $ this -> key ] ) ; }
|
Reflash message to next session .
|
2,819
|
public function get ( $ level = null ) { if ( isset ( $ level ) ) { return $ this -> getMessage ( ) ; } return $ this -> current -> where ( 'level' , $ level ) ; }
|
Get the current flash message .
|
2,820
|
private function getFromSession ( ) { if ( $ this -> exists ( ) ) { $ flashes = $ this -> session -> get ( $ this -> key ) ; foreach ( $ flashes as $ flash ) { $ this -> current -> push ( new Flash ( $ flash [ 'level' ] , $ flash [ 'message' ] ) ) ; } } }
|
Get current flash message from session .
|
2,821
|
protected function gatherRoutes ( ) { $ basePath = $ this -> container -> get ( 'app.base_path' ) ; $ routesPath = $ this -> container -> get ( 'app.routes_path' ) ; include $ basePath . DIRECTORY_SEPARATOR . $ routesPath ; }
|
Get all the routes that match to the given request .
|
2,822
|
private static function template ( $ t , $ vars = array ( ) ) { $ t = preg_replace_callback ( '/\s+|<[^>]++>/' , array ( 'self' , 'templateCb' ) , $ t ) ; array_unshift ( $ vars , $ t ) ; $ code = call_user_func_array ( 'sprintf' , $ vars ) ; return $ code ; }
|
strips out unnecessary whitespace from a template
|
2,823
|
protected function linkifyCb ( $ matches ) { $ uri = ( isset ( $ matches [ 1 ] ) && strlen ( trim ( $ matches [ 1 ] ) ) ) ? $ matches [ 0 ] : "http://" . $ matches [ 0 ] ; $ openTags = array ( ) ; $ closeTags = array ( ) ; preg_match_all ( "/<(?!\/)([^\s>]*).*?>/" , $ matches [ 0 ] , $ openTags , PREG_SET_ORDER ) ; preg_match_all ( "/<\/([^\s>]*).*?>/" , $ matches [ 0 ] , $ closeTags , PREG_SET_ORDER ) ; if ( count ( $ openTags ) != count ( $ closeTags ) ) { return $ matches [ 0 ] ; } if ( isset ( $ openTags [ 0 ] ) && trim ( $ openTags [ 0 ] [ 1 ] ) !== trim ( $ closeTags [ 0 ] [ 1 ] ) ) { return $ matches [ 0 ] ; } $ uri = strip_tags ( $ uri ) ; $ target = ( $ this -> strictStandards ) ? '' : ' target="_blank"' ; return "<a href='{$uri}' class='link'{$target}>{$matches[0]}</a>" ; }
|
Detects and links URLs - callback
|
2,824
|
protected function linkify ( $ src ) { if ( stripos ( $ src , "http" ) === false && stripos ( $ src , "www" ) === false ) { return $ src ; } $ chars = "0-9a-zA-Z\$\-_\.+!\*,%" ; $ src_ = $ src ; $ src = preg_replace_callback ( "@(?<![\w]) (?:(https?://(?:www[0-9]*\.)?) | (?:www\d*\.) ) # domain and tld (?:[$chars]+)+\.[$chars]{2,} # we don't include tags at the EOL because these are likely to be # line-enclosing tags. (?:[/$chars/?=\#;]+|&|<[^>]+>(?!$))* @xm" , array ( $ this , 'linkifyCb' ) , $ src ) ; if ( preg_last_error ( ) !== PREG_NO_ERROR ) { $ src = $ src_ ; } return $ src ; }
|
Detects and links URLs
|
2,825
|
public static function get ( string $ section , $ row = null ) { if ( $ row === null ) { return isset ( self :: $ config [ $ section ] ) ? self :: $ config [ $ section ] : null ; } else { return isset ( self :: $ config [ $ section ] [ $ row ] ) ? self :: $ config [ $ section ] [ $ row ] : null ; } }
|
Return current config
|
2,826
|
private function add ( $ s1 , $ s2 , $ scale ) { if ( $ this -> bcmath ) return bcadd ( $ s1 , $ s2 , $ scale ) ; else return $ this -> scale ( $ s1 + $ s2 , $ scale ) ; }
|
Adds two numbers using arbitrary precision when available .
|
2,827
|
private function mul ( $ s1 , $ s2 , $ scale ) { if ( $ this -> bcmath ) return bcmul ( $ s1 , $ s2 , $ scale ) ; else return $ this -> scale ( $ s1 * $ s2 , $ scale ) ; }
|
Multiples two numbers using arbitrary precision when available .
|
2,828
|
public function autocomplete ( $ postalcode , $ number = '' , $ extension = '' ) { $ postalcode = $ this -> determinePostalType ( $ postalcode ) ; $ this -> data = array_merge ( $ postalcode , [ 'streetnumber' => $ number , 'extension' => $ extension ] ) ; return $ this -> call ( 'autocomplete' , $ this -> prepareData ( $ this -> data ) ) ; }
|
Get a full address after providing a postalcode and number the results also include the coordinates from the address .
|
2,829
|
public function reverse ( $ lat , $ lng ) { $ this -> data = [ 'lat' => $ lat , 'lng' => $ lng ] ; return $ this -> call ( 'reverse' , $ this -> prepareData ( $ this -> data ) ) ; }
|
Find an address by their coordinates returns a full address if found .
|
2,830
|
public function range ( $ nl_fourpp , $ range = 5000 , $ per_page = 10 , $ page = 1 ) { $ this -> data = [ 'nl_fourpp' => $ nl_fourpp , 'range' => $ range , 'per_page' => $ per_page , 'page' => $ page ] ; return $ this -> call ( 'range' , $ this -> prepareData ( $ this -> data ) ) ; }
|
Returns a list of postalcodes within a given range .
|
2,831
|
public function suggest ( $ nl_city , $ per_page = 10 ) { $ this -> data = [ 'nl_city' => $ nl_city , 'per_page' => $ per_page ] ; return $ this -> call ( 'suggest' , $ this -> prepareData ( $ this -> data ) ) ; }
|
Autocompletes a city name .
|
2,832
|
public function distance ( $ from_nl_fourpp , $ to_nl_fourpp , $ algorithm = 'road' ) { $ this -> data = [ 'from_nl_fourpp' => $ from_nl_fourpp , 'to_nl_fourpp' => $ to_nl_fourpp , 'algorithm' => $ algorithm ] ; return $ this -> call ( 'distance' , $ this -> prepareData ( $ this -> data ) ) ; }
|
Calculates the distance between two nl_fourpp postalcodes . Optional you can choose between road or straight distance .
|
2,833
|
public function coordinatesDistance ( $ lat1 , $ lng1 , $ lat2 , $ lng2 , $ miles = false ) { $ pi80 = M_PI / 180 ; $ lat1 *= $ pi80 ; $ lng1 *= $ pi80 ; $ lat2 *= $ pi80 ; $ lng2 *= $ pi80 ; $ r = 6372.797 ; $ dlat = $ lat2 - $ lat1 ; $ dlng = $ lng2 - $ lng1 ; $ a = sin ( $ dlat / 2 ) * sin ( $ dlat / 2 ) + cos ( $ lat1 ) * cos ( $ lat2 ) * sin ( $ dlng / 2 ) * sin ( $ dlng / 2 ) ; $ c = 2 * atan2 ( sqrt ( $ a ) , sqrt ( 1 - $ a ) ) ; $ km = $ r * $ c ; return $ miles ? ( $ km * 0.621371192 ) : $ km ; }
|
Helper method to calculate the distance between two coordinates .
|
2,834
|
public function determinePostalType ( $ postalcode ) { $ postalcode = str_replace ( ' ' , '' , $ postalcode ) ; if ( strlen ( $ postalcode ) == 6 ) { return [ 'nl_sixpp' => $ postalcode ] ; } if ( strlen ( $ postalcode ) == 4 ) { return [ 'nl_fourpp' => $ postalcode ] ; } throw new \ Exception ( 'No valid postalcode was found (nl_sixpp or nl_fourpp)' ) ; }
|
Checks if one of two valid postal types was sent along .
|
2,835
|
protected function prepareData ( $ data ) { $ data [ 'auth_key' ] = $ this -> api_key ; $ data [ 'format' ] = $ this -> api_format ; $ data [ 'pretty' ] = $ this -> api_pretty ; return $ data ; }
|
Make sure the data contains the api_key and desired format .
|
2,836
|
protected function call ( $ path , $ data ) { $ url = $ this -> api_host . $ path . '?' . http_build_query ( $ data ) ; $ ch = curl_init ( $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , 5 ) ; $ return = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; return $ return ; }
|
Method to do the actual call to Pro6PP s API and return the data in the given format .
|
2,837
|
public function getFormValue ( $ currentPage = false , $ encode = false ) { if ( $ currentPage ) $ url = $ encode ? $ this -> urlEncode ( Yii :: app ( ) -> getRequest ( ) -> getUrl ( ) ) : Yii :: app ( ) -> getRequest ( ) -> getUrl ( ) ; else $ url = $ this -> getUrlFromSubmitFields ( ) ; return $ url ; }
|
Get url from submitted data or the current page url for usage in a hidden form element
|
2,838
|
public function getLinkValue ( $ currentPage = false ) { return $ this -> encodeLinkValue ( $ currentPage ? Yii :: app ( ) -> request -> getUrl ( ) : $ this -> getUrlFromSubmitFields ( ) ) ; }
|
Get url from submitted data or the current page url for usage in a link
|
2,839
|
public function getUrl ( $ altUrl = false ) { $ url = $ this -> getUrlFromSubmitFields ( ) ; if ( ! $ url && $ altUrl ) $ url = $ altUrl ; return $ url ? $ url : Yii :: app ( ) -> homeUrl ; }
|
Get url from submitted data or session
|
2,840
|
private function getUrlFromSubmitFields ( ) { $ requestKey = $ this -> requestKey ; $ url = isset ( $ _GET [ $ requestKey ] ) && is_scalar ( $ _GET [ $ requestKey ] ) ? $ _GET [ $ requestKey ] : ( isset ( $ _POST [ $ requestKey ] ) && is_scalar ( $ _POST [ $ requestKey ] ) ? $ _POST [ $ requestKey ] : false ) ; $ url = str_replace ( chr ( 0 ) , '' , $ url ) ; $ url = preg_replace ( '/\s+/' , '' , $ url ) ; return isset ( $ _GET [ $ requestKey ] ) && is_scalar ( $ _GET [ $ requestKey ] ) ? $ this -> urlDecode ( $ url ) : $ url ; }
|
Get the url from the request decodes if needed
|
2,841
|
public function addUserAgentHandler ( WURFL_Handlers_Handler $ handler ) { $ size = count ( $ this -> _userAgentHandlers ) ; if ( $ size > 0 ) { $ this -> _userAgentHandlers [ $ size - 1 ] -> setNextHandler ( $ handler ) ; } $ this -> _userAgentHandlers [ ] = $ handler ; return $ this ; }
|
Adds a WURFL_Handlers_Handler to the chain
|
2,842
|
public function set ( $ key , $ value = null ) { DotArr :: set ( $ this -> data , $ key , $ value ) ; }
|
Sets a value to the dot - notated internal array .
|
2,843
|
public function modal ( Modal \ Modal $ modal ) { $ html = '' ; if ( $ modal -> hasCloseButton ( ) ) { $ html .= html ( 'button' , [ 'type' => 'button' , 'class' => 'close' , 'data-dismiss' => 'modal' , 'aria-label' => $ modal -> getCloseButtonLabel ( ) ] , '<span aria-hidden="true">×</span>' ) ; } if ( $ modal -> hasTitle ( ) ) { $ html .= html ( 'h4' , [ 'class' => Style :: MODAL_HEADER_TITLE_CLASS ] , $ modal -> getTitle ( ) ) ; $ html = html ( 'div' , [ 'class' => Style :: MODAL_HEADER_CLASS ] , $ html ) ; } $ html .= html ( 'div' , [ 'class' => Style :: MODAL_BODY_CLASS ] , $ modal -> getBody ( ) ) ; if ( $ modal -> hasActions ( ) ) { $ actions = '' ; if ( $ modal -> hasCloseButton ( ) ) { $ actions .= html ( 'button' , [ 'type' => 'button' , 'class' => 'btn btn-default' , 'data-dismiss' => 'modal' ] , $ modal -> getCloseButtonLabel ( ) ) ; } foreach ( $ modal -> getActions ( ) as $ action ) { $ actions .= $ this -> render ( 'action' , $ action ) ; } $ html .= html ( 'div' , [ 'class' => Style :: MODAL_FOOTER_CLASS ] , $ actions ) ; } if ( ! $ modal -> isRemote ( ) ) { $ html = html ( 'div' , [ 'class' => Style :: MODAL_CONTENT_CLASS , ] , $ html ) ; $ html = html ( 'div' , [ 'class' => Style :: MODAL_DIALOG_CLASS , 'role' => 'document' ] , $ html ) ; $ html = html ( 'div' , [ 'class' => Style :: MODAL_CLASS , 'role' => 'dialog' ] , $ html ) ; } $ html .= html ( 'script' , [ 'type' => 'text/javascript' ] , js ( 'onload' ) ) ; return $ html ; }
|
Render a modal
|
2,844
|
protected function normalizeRelationsData ( ) { if ( is_null ( $ this -> data [ 'relationships' ] ) ) { $ this -> data [ 'relationships' ] = [ ] ; } foreach ( [ 'normal' , 'reverse' , 'image' , 'file' , 'checkbox' , 'category' ] as $ key ) { if ( ! array_key_exists ( $ key , $ this -> data [ 'relationships' ] ) || ! is_array ( $ this -> data [ 'relationships' ] [ $ key ] ) ) { $ this -> data -> relationships [ $ key ] = [ ] ; } } return $ this ; }
|
Makes sure that expected relations data is traversable
|
2,845
|
protected function getRelationsConfigReplace ( ) { $ relationships = $ this -> collectRelationshipDataForConfig ( ) ; if ( ! count ( $ relationships ) ) return '' ; $ replace = $ this -> tab ( ) . "protected \$relationsConfig = [\n" ; foreach ( $ relationships as $ name => $ relationship ) { $ replace .= $ this -> tab ( 2 ) . "'" . $ name . "' => [\n" ; $ rows = [ ] ; if ( array_get ( $ relationship , 'field' ) ) { $ rows [ 'field' ] = $ relationship [ 'field' ] ; } if ( array_get ( $ relationship , 'special' ) ) { $ rows [ 'type' ] = $ relationship [ 'specialString' ] ; } else { $ rows [ 'parent' ] = ( $ relationship [ 'reverse' ] ? 'false' : 'true' ) ; } if ( array_get ( $ relationship , 'translated' ) === true ) { $ rows [ 'translated' ] = 'true' ; } $ longestPropertyLength = $ this -> getLongestKey ( $ rows ) ; foreach ( $ rows as $ property => $ value ) { $ replace .= $ this -> tab ( 3 ) . "'" . str_pad ( $ property . "'" , $ longestPropertyLength + 1 ) . " => {$value},\n" ; } $ replace .= $ this -> tab ( 2 ) . "],\n" ; } $ replace .= $ this -> tab ( ) . "];\n\n" ; return $ replace ; }
|
Returns the replacement for the relations config placeholder
|
2,846
|
protected function getRelationshipsReplace ( ) { $ totalCount = $ this -> getTotalRelevantRelationshipCount ( ) ; if ( ! $ totalCount ) return '' ; $ replace = "\n" . $ this -> getRelationshipsIntro ( ) ; $ replace .= $ this -> getReplaceForNormalRelationships ( ) . $ this -> getReplaceForSpecialRelationships ( ) ; return $ replace ; }
|
Returns the replacement for the relationships placeholder
|
2,847
|
protected function getTotalRelevantRelationshipCount ( ) { return count ( $ this -> getCombinedRelationships ( ) ) + count ( $ this -> data [ 'relationships' ] [ 'image' ] ) + count ( $ this -> data [ 'relationships' ] [ 'file' ] ) + count ( $ this -> data [ 'relationships' ] [ 'checkbox' ] ) + count ( $ this -> data [ 'relationships' ] [ 'category' ] ) ; }
|
Returns the number of relationships to be considered for building up the stub replacement .
|
2,848
|
protected function determineCategoryRelationName ( ) { $ tryNames = config ( 'pxlcms.generator.standard_models.category_relation_names' , [ ] ) ; $ this -> categoryRelationName = null ; foreach ( $ tryNames as $ tryName ) { $ tryName = trim ( $ tryName ) ; if ( ! $ this -> doesRelationNameConflict ( $ tryName ) ) { $ this -> categoryRelationName = $ tryName ; break ; } } if ( empty ( $ this -> categoryRelationName ) ) { $ this -> context -> log ( "Unable to find a non-conflicting category relation name for model #{$this->data->module}. " . "Relation omitted." , Generator :: LOG_LEVEL_ERROR ) ; } return $ this -> categoryRelationName ; }
|
Attempts to determine a non - conflicting name for the relationship to the Category model
|
2,849
|
protected function doesRelationNameConflict ( $ name ) { $ relationships = array_merge ( $ this -> data [ 'relationships' ] [ 'normal' ] , $ this -> data [ 'relationships' ] [ 'reverse' ] , $ this -> data [ 'relationships' ] [ 'image' ] , $ this -> data [ 'relationships' ] [ 'file' ] , $ this -> data [ 'relationships' ] [ 'checkbox' ] ) ; if ( array_key_exists ( $ name , $ relationships ) ) return true ; $ attributes = array_merge ( $ this -> data -> normal_attributes , $ this -> data -> translated_attributes ) ; if ( in_array ( snake_case ( $ name ) , $ attributes ) ) return true ; return false ; }
|
Returns whether a given name is already in use by anything that it would conflict with for this model
|
2,850
|
protected function getRelationMethodSection ( array $ relationships , $ type = CmsModel :: RELATION_TYPE_MODEL ) { $ replace = '' ; $ relatedClassName = $ this -> context -> getModelNamespaceForSpecialModel ( $ type ) ; foreach ( $ relationships as $ name => $ relationship ) { $ relationParameters = '' ; $ relationMethodParameters = '' ; if ( $ relationKey = array_get ( $ relationship , 'key' ) ) { $ relationParameters = ", '{$relationKey}'" ; } if ( array_get ( $ relationship , 'translated' ) && $ type !== CmsModel :: RELATION_TYPE_MODEL && config ( 'pxlcms.generator.models.allow_locale_override_on_translated_model_relation' ) ) { $ relationMethodParameters = '$locale = null' ; $ relationParameters = ( substr_count ( $ relationParameters , ',' ) ? null : ', null' ) . ', null' . ', $locale' ; } $ replace .= $ this -> tab ( ) . "public function {$name}({$relationMethodParameters})\n" . $ this -> tab ( ) . "{\n" . $ this -> tab ( 2 ) . "return \$this->{$relationship['type']}({$relatedClassName}::class" . $ relationParameters . ");\n" . $ this -> tab ( ) . "}\n" . "\n" ; if ( $ type == CmsModel :: RELATION_TYPE_IMAGE ) { $ replace .= $ this -> tab ( ) . "public function get" . studly_case ( $ name ) . "Attribute()\n" . $ this -> tab ( ) . "{\n" . $ this -> tab ( 2 ) . "return \$this->getImagesWithResizes();\n" . $ this -> tab ( ) . "}\n" . "\n" ; } } return $ replace ; }
|
Returns stub section for relation method
|
2,851
|
public function setDefaultValue ( $ value ) { $ value = $ this -> mmAttribute -> valueToWidget ( $ value ) ; $ this -> set ( 'value' , $ value ) ; }
|
Set the default value of the Attribute
|
2,852
|
public function addProperties ( $ properties ) { if ( empty ( $ properties ) || ! count ( ( array ) $ properties ) ) { throw new \ Exception ( 'Empty properties given' ) ; } if ( ! is_array ( $ properties ) && ! is_object ( $ properties ) ) { throw new \ Exception ( 'Expected array or object' ) ; } foreach ( $ properties as $ key => $ property ) { $ this -> addProperty ( $ key , $ property ) ; } return $ this ; }
|
Add properties to this object validator
|
2,853
|
public function addProperty ( $ key , BaseValidator $ property ) { if ( property_exists ( $ this -> properties , $ key ) ) { throw new \ Exception ( 'Property key exists' ) ; } $ this -> properties -> { $ key } = $ property ; return $ this ; }
|
Add a property to this object validator
|
2,854
|
public static function castFrom ( $ requestUri , string $ requestMethod = null ) { if ( $ requestUri instanceof self ) { return $ requestUri ; } return new self ( $ requestUri , ( string ) $ requestMethod ) ; }
|
casts given values to an instance of UriRequest
|
2,855
|
public function methodEquals ( string $ method = null ) : bool { if ( empty ( $ method ) ) { return true ; } return $ this -> method === $ method ; }
|
checks if request method equals given method
|
2,856
|
public function satisfiesPath ( string $ expectedPath = null ) : bool { if ( empty ( $ expectedPath ) ) { return true ; } if ( preg_match ( '/^' . UriPath :: pattern ( $ expectedPath ) . '/' , $ this -> uri -> path ( ) ) >= 1 ) { return true ; } return false ; }
|
checks if given path is satisfied by request path
|
2,857
|
public function satisfies ( string $ method = null , string $ expectedPath = null ) : bool { return $ this -> methodEquals ( $ method ) && $ this -> satisfiesPath ( $ expectedPath ) ; }
|
checks if given method and path is satisfied by request
|
2,858
|
public function eachChild ( $ callback ) { foreach ( $ this -> children as $ child ) { call_user_func ( $ callback , $ child ) ; } return $ this ; }
|
Run a callback for each child .
|
2,859
|
protected function generateChildren ( ) { $ buffer = '' ; foreach ( $ this -> children as $ child ) { $ buffer .= $ child -> generate ( ) ; } return $ buffer ; }
|
Generate children .
|
2,860
|
protected function bind ( $ vars , ServerRequestInterface $ request , array $ parts ) { $ type = is_array ( $ vars ) && array_keys ( $ vars ) === array_keys ( array_keys ( $ vars ) ) ? 'numeric' : 'assoc' ; $ values = $ this -> bindParts ( $ vars , $ type , $ request , $ parts ) ; if ( $ vars instanceof Route ) { $ class = get_class ( $ vars ) ; $ values = new $ class ( $ values ) ; } elseif ( is_object ( $ vars ) && $ type === 'assoc' ) { $ values = ( object ) $ values ; } return $ values ; }
|
Fill out the routes variables based on the url parts .
|
2,861
|
protected function bindParts ( $ vars , $ type , ServerRequestInterface $ request , array $ parts ) { $ values = [ ] ; foreach ( $ vars as $ key => $ var ) { $ part = null ; $ bound = $ this -> bindPartObject ( $ var , $ part ) || $ this -> bindPartArray ( $ var , $ request , $ parts , $ part ) || $ this -> bindPartVar ( $ var , $ type , $ request , $ parts , $ part ) || $ this -> bindPartConcat ( $ var , $ request , $ parts , $ part ) || $ this -> bindPartValue ( $ var , $ part ) ; if ( ! $ bound ) continue ; if ( $ type === 'assoc' ) { $ values [ $ key ] = $ part [ 0 ] ; } else { $ values = array_merge ( $ values , $ part ) ; } } return $ values ; }
|
Fill out the values based on the url parts .
|
2,862
|
protected function bindPartArray ( $ var , ServerRequestInterface $ request , array $ parts , & $ part ) { if ( ! is_array ( $ var ) && ! $ var instanceof \ stdClass ) { return false ; } $ part = [ $ this -> bind ( $ var , $ request , $ parts ) ] ; return true ; }
|
Bind part if it s an array
|
2,863
|
protected function bindPartVar ( $ var , $ type , ServerRequestInterface $ request , array $ parts , & $ part ) { if ( ! is_string ( $ var ) || $ var [ 0 ] !== '$' ) { return false ; } $ options = array_map ( 'trim' , explode ( '|' , $ var ) ) ; $ part = $ this -> bindVar ( $ type , $ request , $ parts , $ options ) ; return true ; }
|
Bind part if it s an variable
|
2,864
|
protected function bindPartConcat ( $ var , ServerRequestInterface $ request , array $ parts , & $ part ) { if ( ! is_string ( $ var ) || $ var [ 0 ] !== '~' || substr ( $ var , - 1 ) !== '~' ) { return false ; } $ pieces = array_map ( 'trim' , explode ( '~' , substr ( $ var , 1 , - 1 ) ) ) ; $ bound = array_filter ( $ this -> bind ( $ pieces , $ request , $ parts ) ) ; $ part = [ join ( '' , $ bound ) ] ; return true ; }
|
Bind part if it s an concatenation
|
2,865
|
protected function bindVarSuperGlobal ( $ option , ServerRequestInterface $ request , & $ value ) { if ( preg_match ( '/^\$_(GET|POST|COOKIE)\[([^\[]*)\]$/i' , $ option , $ matches ) ) { list ( , $ var , $ key ) = $ matches ; $ var = strtolower ( $ var ) ; $ data = null ; if ( $ var === 'get' ) { $ data = $ request -> getQueryParams ( ) ; } elseif ( $ var === 'post' ) { $ data = $ request -> getParsedBody ( ) ; } elseif ( $ var === 'cookie' ) { $ data = $ request -> getCookieParams ( ) ; } $ value = isset ( $ data [ $ key ] ) ? [ $ data [ $ key ] ] : null ; return true ; } return false ; }
|
Bind variable when option is a super global
|
2,866
|
protected function bindVarRequestHeader ( $ option , ServerRequestInterface $ request , & $ value ) { if ( preg_match ( '/^\$(?:HTTP_)?([A-Z_]+)$/' , $ option , $ matches ) ) { $ sentence = preg_replace ( '/[\W_]+/' , ' ' , $ matches [ 1 ] ) ; $ name = str_replace ( ' ' , '-' , ucwords ( $ sentence ) ) ; $ value = [ $ request -> getHeaderLine ( $ name ) ] ; return true ; } return false ; }
|
Bind variable when option is a request header
|
2,867
|
protected function bindVarMultipleUrlParts ( $ option , $ type , array $ parts , & $ value ) { if ( substr ( $ option , - 3 ) === '...' && ctype_digit ( substr ( $ option , 1 , - 3 ) ) ) { $ i = ( int ) substr ( $ option , 1 , - 3 ) ; if ( $ type === 'assoc' ) { throw new \ InvalidArgumentException ( "Binding multiple parts using '$option' is only allowed in numeric arrays" ) ; } else { $ value = array_slice ( $ parts , $ i - 1 ) ; } return true ; } return false ; }
|
Bind variable when option contains multiple URL parts
|
2,868
|
protected function bindVarSingleUrlPart ( $ option , array $ parts , & $ value ) { if ( ctype_digit ( substr ( $ option , 1 ) ) ) { $ i = ( int ) substr ( $ option , 1 ) ; $ part = array_slice ( $ parts , $ i - 1 , 1 ) ; if ( ! empty ( $ part ) ) { $ value = $ part ; return true ; } } return false ; }
|
Bind variable when option contains a single URL part
|
2,869
|
public function addCondition ( ConditionAbstract $ condition ) { if ( $ condition instanceof SupportsCondition ) { $ this -> conditions [ ] = $ condition ; } else { throw new \ InvalidArgumentException ( "Invalid condition instance. Instance of 'SupportsCondition' expected." ) ; } return $ this ; }
|
Adds a supports condition .
|
2,870
|
protected function parseRuleString ( $ ruleString ) { $ ruleString = preg_replace ( '/^[ \r\n\t\f]*@supports[ \r\n\t\f]*/i' , '' , $ ruleString ) ; $ ruleString = trim ( $ ruleString , " \r\n\t\f" ) ; $ charset = $ this -> getCharset ( ) ; $ conditions = [ ] ; foreach ( Condition :: splitNestedConditions ( $ ruleString , $ this -> getCharset ( ) ) as $ normalizedConditionList ) { $ normalizedConditions = [ ] ; $ currentCondition = "" ; if ( preg_match ( '/[^\x00-\x7f]/' , $ normalizedConditionList ) ) { $ isAscii = false ; $ strLen = mb_strlen ( $ normalizedConditionList , $ charset ) ; $ getAnd = function ( $ i ) use ( $ normalizedConditionList ) { return strtolower ( substr ( $ normalizedConditionList , $ i , 5 ) ) ; } ; } else { $ isAscii = true ; $ strLen = strlen ( $ normalizedConditionList ) ; $ getAnd = function ( $ i ) use ( $ charset , $ normalizedConditionList ) { return mb_strtolower ( mb_substr ( $ normalizedConditionList , $ i , 5 , $ charset ) , $ charset ) ; } ; } for ( $ i = 0 , $ j = $ strLen ; $ i < $ j ; $ i ++ ) { if ( $ isAscii === true ) { $ char = $ normalizedConditionList [ $ i ] ; } else { $ char = mb_substr ( $ normalizedConditionList , $ i , 1 , $ charset ) ; } if ( $ char === " " && $ getAnd ( $ i ) === " and " ) { $ normalizedConditions [ ] = new SupportsCondition ( trim ( $ currentCondition , " \r\n\t\f" ) ) ; $ currentCondition = "" ; $ i += ( 5 - 1 ) ; } else { $ currentCondition .= $ char ; } } $ currentCondition = trim ( $ currentCondition , " \r\n\t\f" ) ; if ( $ currentCondition !== "" ) { $ normalizedConditions [ ] = new SupportsCondition ( trim ( $ currentCondition , " \r\n\t\f" ) ) ; } foreach ( $ normalizedConditions as $ normalizedCondition ) { $ conditions [ ] = $ normalizedCondition ; } } $ this -> setConditions ( $ conditions ) ; }
|
Parses the supports rule .
|
2,871
|
public function getUserRoles ( Criteria $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collUserRolesPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collUserRoles || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collUserRoles ) { $ this -> initUserRoles ( ) ; } else { $ collUserRoles = ChildUserRoleQuery :: create ( null , $ criteria ) -> filterByUser ( $ this ) -> find ( $ con ) ; if ( null !== $ criteria ) { if ( false !== $ this -> collUserRolesPartial && count ( $ collUserRoles ) ) { $ this -> initUserRoles ( false ) ; foreach ( $ collUserRoles as $ obj ) { if ( false == $ this -> collUserRoles -> contains ( $ obj ) ) { $ this -> collUserRoles -> append ( $ obj ) ; } } $ this -> collUserRolesPartial = true ; } return $ collUserRoles ; } if ( $ partial && $ this -> collUserRoles ) { foreach ( $ this -> collUserRoles as $ obj ) { if ( $ obj -> isNew ( ) ) { $ collUserRoles [ ] = $ obj ; } } } $ this -> collUserRoles = $ collUserRoles ; $ this -> collUserRolesPartial = false ; } } return $ this -> collUserRoles ; }
|
Gets an array of ChildUserRole objects which contain a foreign key that references this object .
|
2,872
|
public function addUserRole ( ChildUserRole $ l ) { if ( $ this -> collUserRoles === null ) { $ this -> initUserRoles ( ) ; $ this -> collUserRolesPartial = true ; } if ( ! $ this -> collUserRoles -> contains ( $ l ) ) { $ this -> doAddUserRole ( $ l ) ; } return $ this ; }
|
Method called to associate a ChildUserRole object to this object through the ChildUserRole foreign key attribute .
|
2,873
|
public function getUserRolesJoinRole ( Criteria $ criteria = null , ConnectionInterface $ con = null , $ joinBehavior = Criteria :: LEFT_JOIN ) { $ query = ChildUserRoleQuery :: create ( null , $ criteria ) ; $ query -> joinWith ( 'Role' , $ joinBehavior ) ; return $ this -> getUserRoles ( $ query , $ con ) ; }
|
If this collection has already been initialized with an identical criteria it returns the collection . Otherwise if this User is new it will return an empty collection ; or if this User has previously been saved it will retrieve related UserRoles from storage .
|
2,874
|
public function initRoles ( ) { $ this -> collRoles = new ObjectCollection ( ) ; $ this -> collRolesPartial = true ; $ this -> collRoles -> setModel ( '\Alchemy\Component\Cerberus\Model\Role' ) ; }
|
Initializes the collRoles collection .
|
2,875
|
public function addRole ( ChildRole $ role ) { if ( $ this -> collRoles === null ) { $ this -> initRoles ( ) ; } if ( ! $ this -> getRoles ( ) -> contains ( $ role ) ) { $ this -> collRoles -> push ( $ role ) ; $ this -> doAddRole ( $ role ) ; } return $ this ; }
|
Associate a ChildRole to this object through the user_role cross reference table .
|
2,876
|
public function removeRole ( ChildRole $ role ) { if ( $ this -> getRoles ( ) -> contains ( $ role ) ) { $ userRole = new ChildUserRole ( ) ; $ userRole -> setRole ( $ role ) ; if ( $ role -> isUsersLoaded ( ) ) { $ role -> getUsers ( ) -> removeObject ( $ this ) ; } $ userRole -> setUser ( $ this ) ; $ this -> removeUserRole ( clone $ userRole ) ; $ userRole -> clear ( ) ; $ this -> collRoles -> remove ( $ this -> collRoles -> search ( $ role ) ) ; if ( null === $ this -> rolesScheduledForDeletion ) { $ this -> rolesScheduledForDeletion = clone $ this -> collRoles ; $ this -> rolesScheduledForDeletion -> clear ( ) ; } $ this -> rolesScheduledForDeletion -> push ( $ role ) ; } return $ this ; }
|
Remove role of this object through the user_role cross reference table .
|
2,877
|
private function throwException ( $ method ) { if ( isset ( $ this -> exceptions [ $ method ] ) && ! empty ( $ this -> exceptions [ $ method ] ) ) { $ exception = array_shift ( $ this -> exceptions [ $ method ] ) ; if ( $ exception != null ) { throw $ exception ; } } }
|
Dequeue an exception for a specific method invocation
|
2,878
|
public function setLock ( CacheKey $ key , Lock $ lock ) { $ this -> locks [ $ key -> hash ] = $ lock ; }
|
Locks a specific cache entry
|
2,879
|
public function emailOutput ( $ address ) { if ( is_null ( $ this -> _output ) || $ this -> _output == $ this -> getDefaultOutput ( ) ) { throw new InvalidCallException ( 'Must direct output to file in order to email results.' ) ; } $ address = is_array ( $ address ) ? $ address : func_get_args ( ) ; return $ this -> then ( function ( Application $ app ) use ( $ address ) { $ this -> sendEmail ( $ app -> mailer , $ address ) ; } ) ; }
|
Register the send email logic .
|
2,880
|
public function buildCommand ( ) { $ command = $ this -> command . ' >> ' . $ this -> _output . ' 2>&1 &' ; return $ this -> _user ? 'sudo -u ' . $ this -> _user . ' ' . $ command : $ command ; }
|
Build the execute command .
|
2,881
|
protected function sendEmail ( MailerInterface $ mailer , $ address ) { $ message = $ mailer -> compose ( ) ; $ message -> setTextBody ( file_get_contents ( $ this -> _output ) ) -> setSubject ( $ this -> getEmailSubject ( ) ) -> setTo ( $ address ) ; $ message -> send ( ) ; }
|
Send email logic .
|
2,882
|
private function getMigrationInstances ( array $ migration_class_file_path_map ) { $ result = [ ] ; foreach ( $ migration_class_file_path_map as $ migration_class => $ migration_file_path ) { if ( is_file ( $ migration_file_path ) ) { require_once $ migration_file_path ; if ( class_exists ( $ migration_class , false ) ) { $ reflection = new ReflectionClass ( $ migration_class ) ; if ( $ reflection -> implementsInterface ( MigrationInterface :: class ) && ! $ reflection -> isAbstract ( ) ) { $ result [ $ migration_class ] = new $ migration_class ( $ this -> connection , $ this -> log ) ; } } else { throw new RuntimeException ( "Migration class '$migration_class' not found" ) ; } } else { throw new RuntimeException ( "File '$migration_file_path' not found" ) ; } } return $ result ; }
|
Return an array of MigrationInterface instances indexed by class name .
|
2,883
|
public function getTableName ( ) { if ( $ this -> table_exists === null && ! in_array ( $ this -> table_name , $ this -> connection -> getTableNames ( ) ) ) { $ this -> connection -> execute ( 'CREATE TABLE ' . $ this -> connection -> escapeTableName ( $ this -> table_name ) . ' ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `migration` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `executed_at` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `migration` (`migration`), KEY `executed_on` (`executed_at`) ) ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;' ) ; $ this -> table_exists = true ; } return $ this -> table_name ; }
|
Return name of the table where we store info about executed migrations .
|
2,884
|
protected function format ( string $ timestamp , string $ levelstr , string $ msg ) { $ fmt = "[%s] %s: %s\n" ; return sprintf ( $ fmt , $ timestamp , $ levelstr , $ msg ) ; }
|
Log line formatter .
|
2,885
|
private function one_line ( string $ msg ) { $ msg = trim ( $ msg ) ; $ msg = str_replace ( [ "\t" , "\n" , "\r" , ] , [ '\t' , '\n' , '\r' , ] , $ msg ) ; return preg_replace ( '! +!' , ' ' , $ msg ) ; }
|
Write lines as single line with tab CR and LF written symbolically .
|
2,886
|
private function write ( string $ levelstr , string $ msg ) { $ timestamp = gmdate ( \ DateTime :: ATOM ) ; try { $ msg = $ this -> one_line ( $ msg ) ; $ line = $ this -> format ( $ timestamp , $ levelstr , $ msg ) ; fwrite ( $ this -> handle , $ line ) ; } catch ( \ Exception $ e ) { } }
|
Write to handle .
|
2,887
|
public function bootstrap ( ) { $ this -> registerBootstrapArguments ( ) ; $ this -> registerEventDispatcher ( ) ; $ this -> registerConfigLoader ( ) ; $ this -> registerConfig ( ) ; $ this -> registerPlugins ( ) ; $ this -> registerTaskDispatcherCollection ( ) ; $ this -> registerLogger ( ) ; $ this -> getContainer ( ) -> plugins ( ) ; $ this -> getContainer ( ) -> events ( ) -> dispatch ( BootstrapFinishedEvent :: EVENT_NAME , new BootstrapFinishedEvent ( $ this -> getContainer ( ) ) ) ; return $ this -> getContainer ( ) ; }
|
Run bootstrap an register services to the DI container
|
2,888
|
public static function val ( $ value1 , $ value2 , $ _ = null ) { if ( ! static :: is ( $ value1 ) || ! static :: is ( $ value2 ) ) { throw new \ InvalidArgumentException ( "All parameters must be of type bool." ) ; } $ ret = ( $ value1 || $ value2 ) ; $ args = array_slice ( func_get_args ( ) , 2 ) ; while ( ! $ ret && ( $ bool = array_shift ( $ args ) ) !== null ) { if ( ! static :: is ( $ bool ) ) { throw new \ InvalidArgumentException ( "All parameters must be of type bool." ) ; } $ ret = ( $ ret || $ bool ) ; } return $ ret ; }
|
Applies the OR operation to the given values .
|
2,889
|
public static function enable2FA ( $ userUid , $ authenticationKey , $ verificationCode ) { $ request = array ( 'authenticationKey' => $ authenticationKey , 'verificationCode' => $ verificationCode ) ; return Pencepay_Util_HttpClient :: postArray ( "/user/$userUid/tfa_enable" , $ request ) ; }
|
Enables the two - factor authentication for this user .
|
2,890
|
public function register ( ) { $ file = $ this -> app -> make ( Filesystem :: class ) ; $ path = realpath ( __DIR__ . '/../Libraries' ) ; $ libraries = $ file -> glob ( $ path . '/*.php' ) ; foreach ( $ libraries as $ librarie ) { require_once ( $ librarie ) ; } $ libraries2 = $ file -> glob ( $ path . '/HuasituoApi/*.php' ) ; foreach ( $ libraries2 as $ librarie ) { require_once ( $ librarie ) ; } $ libraries3 = $ file -> glob ( $ path . '/HuasituoApi/Request/*.php' ) ; foreach ( $ libraries3 as $ librarie ) { require_once ( $ librarie ) ; } $ fields = $ file -> glob ( $ path . '/Fields/*.php' ) ; foreach ( $ fields as $ field ) { require_once ( $ field ) ; } $ alipays = $ file -> glob ( $ path . '/Alipay/*.php' ) ; foreach ( $ alipays as $ librarie ) { require_once ( $ librarie ) ; } }
|
Register the libraries services .
|
2,891
|
protected function isWantedContrib ( \ SplFileInfo $ dir ) { $ info_file = $ this -> cleanDirPath ( $ dir -> getPathName ( ) ) . DIRECTORY_SEPARATOR . $ this -> moduleName . '.info' ; return file_exists ( $ info_file ) ; }
|
Checks if the passed directory is the contrib module we are looking for .
|
2,892
|
public function isGlobbed ( $ string ) { $ segments = $ this -> parser -> parse ( $ string ) ; foreach ( $ segments as $ segment ) { if ( $ segment [ 1 ] & SelectorParser :: T_PATTERN ) { return true ; } } return false ; }
|
Return true if the given string is contains a glob pattern
|
2,893
|
public function load ( $ fileName ) { if ( ! file_exists ( $ fileName ) ) { throw new \ InvalidArgumentException ( 'File ' . $ fileName . ' does not exist' ) ; } $ lines = $ this -> readLinesFromFile ( $ fileName ) ; return $ this -> getArrayFromLines ( $ lines ) ; }
|
Returns array which consists of value array and map
|
2,894
|
public function getArrayFromLines ( array $ lines ) { $ array = [ ] ; $ map = [ ] ; $ i = 1 ; foreach ( $ lines as $ line ) { if ( $ this -> processor -> isEmptyLine ( $ line ) ) { $ map [ $ i ] = [ 'type' => 'empty' ] ; } elseif ( $ this -> processor -> isCommentLine ( $ line ) ) { $ map [ $ i ] = [ 'type' => 'comment' , 'value' => $ line ] ; } else { $ keyValue = explode ( '=' , $ line , 2 ) ; if ( count ( $ keyValue ) < 2 ) { throw new InvalidLineException ( 'Invalid line in configuration file' ) ; } list ( $ key , $ value ) = $ keyValue ; $ key = trim ( $ key ) ; $ array [ $ key ] = $ this -> processValue ( $ value ) ; $ map [ $ i ] = [ 'type' => 'value' , 'key' => $ key ] ; $ map [ $ i ] [ 'info' ] = $ this -> mapInfoForValue ( $ value ) ; } $ i ++ ; } return [ $ array , $ map ] ; }
|
Creates value and map array from string lines
|
2,895
|
public function processValue ( $ value ) { $ value = ltrim ( rtrim ( $ value ) ) ; if ( $ this -> processor -> isBool ( $ value ) ) { return $ this -> processor -> getBool ( $ value ) ; } if ( $ this -> processor -> isNumber ( $ value ) ) { return $ this -> processor -> getNumber ( $ value ) ; } if ( $ this -> processor -> isNull ( $ value ) ) { return null ; } return $ this -> processor -> getString ( $ value ) ; }
|
Creates value from string
|
2,896
|
protected function getDefaultOptions ( array $ fields ) { $ fieldsUpdated = array ( ) ; foreach ( $ fields as $ fieldName => $ field ) { $ fieldsUpdated [ $ fieldName ] = $ this -> typeHandler -> getDefaultOptions ( $ field ) ; } return $ fieldsUpdated ; }
|
Get the default options for the fields for their type
|
2,897
|
public function setDefaultValues ( array $ defaultValues ) { foreach ( $ defaultValues as $ name => $ value ) { if ( isset ( $ this -> fields [ $ name ] ) ) { $ this -> data [ $ name ] = $ value ; } } }
|
Set the default values of matching fields
|
2,898
|
public function bindEntity ( $ entity , $ fields = null , $ validatable = true ) { if ( $ this -> submitted ) { throw new BadMethodCallException ( "Entities cannot be assigned after FormHandler::handleRequest has been called" ) ; } $ this -> entities [ ] = array ( 'entity' => $ entity , 'fields' => $ fields , 'validatable' => $ validatable ) ; if ( $ entity instanceof EntityInterface ) { $ entityData = $ entity -> getFormData ( array_keys ( $ this -> fields ) , $ fields ) ; } else { $ entityData = $ this -> entityProcessor -> getFromEntity ( $ entity , array_keys ( $ this -> fields ) , $ fields ) ; } $ entityData = $ this -> transformToFormData ( $ entityData ) ; $ this -> data = array_replace_recursive ( $ this -> data , $ entityData ) ; }
|
Add an entity to the form . The entities values will be used to fill the form and the forms data will be assigned to the entity when saveToEntities is called
|
2,899
|
public function handleRequest ( $ request = null ) { $ this -> submitted = true ; $ requestData = $ this -> requestHandler -> handleRequest ( $ this , $ request ) ; $ validRequestData = $ this -> checkFieldsSubmitted ( $ this -> fields , $ requestData ) ; if ( $ this -> submitted === true && ! empty ( $ validRequestData ) ) { $ this -> data = $ validRequestData ; $ this -> setRequiredFieldErrors ( ) ; } else { $ this -> submitted = false ; } if ( isset ( $ this -> restoreDataHandler ) ) { if ( $ this -> isSubmitted ( ) ) { $ this -> restoreDataHandler -> setRestorableData ( $ this , $ this -> data , $ request ) ; } else { $ restoredData = $ this -> restoreDataHandler -> restoreData ( $ this , $ request ) ; if ( is_array ( $ restoredData ) && ! empty ( $ restoredData ) ) { $ this -> data = $ restoredData ; } } } if ( isset ( $ this -> eventDispatcher ) ) { $ event = new FormHandlerRequestEvent ( $ this , $ request , $ this -> data ) ; $ this -> eventDispatcher -> dispatch ( 'form_handler.request' , $ event ) ; $ this -> data = $ event -> getFormData ( ) ; } }
|
Use a request handler to get data from a request and store the values that match fields in the form blueprint
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.