idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
3,700
public function setHour ( $ hour ) { if ( ! in_array ( $ hour , range ( 0 , 23 ) ) ) { throw new InvalidArgumentException ( 'Hour must be between 0 and 23' ) ; } $ this -> hour = $ hour ; return $ this ; }
Sets hour of repetition
3,701
protected function processModuleSorting ( ) { $ this -> model [ 'is_listified' ] = false ; $ this -> model [ 'ordered_by' ] = [ ] ; if ( $ this -> module [ 'max_entries' ] == 1 ) { return ; } if ( $ this -> module [ 'sort_entries_manually' ] ) { $ this -> model [ 'is_listified' ] = true ; return ; } $ this -> model [ 'is_listified' ] = false ; $ sorting = trim ( strtolower ( $ this -> module [ 'sort_entries_by' ] ) ) ; if ( empty ( $ sorting ) ) return ; foreach ( explode ( ',' , $ sorting ) as $ sortClauseString ) { if ( ! preg_match ( "#^\s*[`'](.*)[`']\s+(asc|desc)\s*$#i" , $ sortClauseString , $ matches ) ) { $ this -> context -> log ( "Could not interpret sorting clause '{$sortClauseString}' for module #{$this->moduleId}" , Generator :: LOG_LEVEL_ERROR ) ; continue ; } $ this -> model [ 'ordered_by' ] [ $ matches [ 1 ] ] = $ matches [ 2 ] ; } }
Determines and stores information about the sorting configuration found for entries of the module
3,702
protected function prepareModelOverrides ( ) { $ this -> overrides = $ this -> getOverrideConfigForModel ( $ this -> moduleId ) ; if ( array_key_exists ( 'name' , $ this -> overrides ) ) { $ name = $ this -> overrides [ 'name' ] ; } else { $ name = array_get ( $ this -> module , 'prefixed_name' ) ? : $ this -> model [ 'name' ] ; if ( config ( 'pxlcms.generator.models.model_name.singularize_model_names' ) ) { if ( $ this -> context -> dutchMode ) { $ name = $ this -> dutchSingularize ( $ name ) ; } else { $ name = str_singular ( $ name ) ; } } } $ tableOverride = null ; if ( str_plural ( $ this -> normalizeDb ( $ name ) ) != $ this -> normalizeDb ( $ this -> module [ 'name' ] ) ) { $ tableOverride = $ this -> getModuleTablePrefix ( $ this -> moduleId ) . $ this -> normalizeDb ( $ this -> module [ 'name' ] ) ; } $ listified = array_key_exists ( 'listify' , $ this -> overrides ) ? ( bool ) $ this -> overrides [ 'listify' ] : $ this -> model [ 'is_listified' ] ; $ this -> overrideHidden = [ ] ; if ( ! is_null ( array_get ( $ this -> overrides , 'attributes.hidden' ) ) && ! array_get ( $ this -> overrides , 'attributes.hidden-empty' ) ) { $ this -> overrideHidden = array_get ( $ this -> overrides , 'attributes.hidden' ) ; if ( ! is_array ( $ this -> overrideHidden ) ) $ this -> overrideHidden = [ ( string ) $ this -> overrideHidden ] ; } $ this -> model [ 'name' ] = $ name ; $ this -> model [ 'table' ] = $ tableOverride ; $ this -> model [ 'is_listified' ] = $ listified ; $ this -> model [ 'hidden' ] = $ this -> overrideHidden ; $ this -> model [ 'casts' ] = array_get ( $ this -> overrides , 'attributes.casts' , [ ] ) ; }
Prepares override cache for current model being assembled
3,703
protected function applyOverridesForRelationships ( ) { $ overrides = array_get ( $ this -> overrides , 'relationships' ) ; if ( empty ( $ overrides ) ) return ; $ removeRelations = [ ] ; foreach ( $ overrides as $ overrideName => $ override ) { foreach ( [ 'normal' , 'image' , 'file' , 'checkbox' ] as $ type ) { foreach ( $ this -> model [ 'relationships' ] [ $ type ] as $ name => & $ relationData ) { if ( $ name === $ overrideName ) { $ newName = array_get ( $ override , 'name' ) ; $ preventReverse = array_get ( $ override , 'prevent_reverse' , false ) ; $ reverseName = array_get ( $ override , 'reverse_name' , false ) ; if ( $ preventReverse ) { $ relationData [ 'prevent_reverse' ] = true ; } if ( ! empty ( $ reverseName ) ) { $ relationData [ 'reverse_name' ] = $ reverseName ; } if ( ! empty ( $ newName ) ) { $ this -> model [ 'relationships' ] [ $ type ] [ $ newName ] = $ relationData ; $ removeRelations [ ] = $ type . '.' . $ overrideName ; $ removeRelations = array_diff ( $ removeRelations , [ $ newName ] ) ; } $ this -> context -> log ( "Override applied for relationship {$overrideName} on module {$this->moduleId}." ) ; break 2 ; } } } } unset ( $ relationData ) ; array_forget ( $ this -> model [ 'relationships' ] , $ removeRelations ) ; }
Applies overrides set in the config for analyzed relationships
3,704
protected function multipleBelongsToRelationsBetweenModels ( $ fromModuleId , $ toModuleId ) { $ count = 0 ; foreach ( $ this -> context -> output [ 'models' ] [ $ fromModuleId ] [ 'relationships' ] [ 'normal' ] as $ relationship ) { if ( $ relationship [ 'model' ] == $ toModuleId && $ relationship [ 'type' ] == Generator :: RELATIONSHIP_BELONGS_TO && ! array_get ( $ relationship , 'negative' ) ) { $ count ++ ; } } return ( $ count > 1 ) ; }
Returns whether there are multiple relationships from one model to the other
3,705
protected function getImageResizesForField ( $ fieldId ) { if ( ! array_key_exists ( 'resizes' , $ this -> data -> rawData [ 'fields' ] [ $ fieldId ] ) || ! count ( $ this -> data -> rawData [ 'fields' ] [ $ fieldId ] [ 'resizes' ] ) ) { return [ ] ; } $ resizes = [ ] ; foreach ( $ this -> data -> rawData [ 'fields' ] [ $ fieldId ] [ 'resizes' ] as $ resizeId => $ resize ) { $ resizes [ ] = [ 'resize' => $ resizeId , 'prefix' => $ resize [ 'prefix' ] , 'width' => ( int ) $ resize [ 'width' ] , 'height' => ( int ) $ resize [ 'height' ] , ] ; } uasort ( $ resizes , function ( $ a , $ b ) { return strcmp ( $ a [ 'prefix' ] , $ b [ 'prefix' ] ) ; } ) ; return $ resizes ; }
Returns data about resizes for an image field
3,706
protected function checkForReservedClassName ( $ name ) { $ name = trim ( strtolower ( $ name ) ) ; if ( in_array ( $ name , config ( 'pxlcms.generator.reserved' , [ ] ) ) ) { throw new \ InvalidArgumentException ( "Cannot use {$name} as a module name, it is reserved!" ) ; } }
Checks whether a given name is on the reserved list
3,707
private function extended ( callable $ previous = null , callable $ current ) : callable { return is_null ( $ previous ) ? $ current : new Extension ( $ current , $ previous ) ; }
Return the previous service factory extended with the current service factory .
3,708
final public static function get_header_string ( int $ code ) { if ( ! isset ( self :: $ header_string [ $ code ] ) ) $ code = 404 ; return [ 'code' => $ code , 'msg' => self :: $ header_string [ $ code ] , ] ; }
Get HTTP code .
3,709
public static function start_header ( int $ code = 200 , int $ cache = 0 , array $ headers = [ ] ) { $ msg = 'OK' ; extract ( self :: get_header_string ( $ code ) ) ; $ proto = isset ( $ _SERVER [ 'SERVER_PROTOCOL' ] ) ? $ _SERVER [ 'SERVER_PROTOCOL' ] : 'HTTP/1.1' ; static :: header ( "$proto $code $msg" ) ; if ( $ cache ) { $ cache = intval ( $ cache ) ; $ expire = time ( ) + $ cache ; static :: header ( "Expires: " . gmdate ( "D, d M Y H:i:s" , $ expire ) . " GMT" ) ; static :: header ( "Cache-Control: must-revalidate" ) ; } else { static :: header ( "Expires: Mon, 27 Jul 1996 07:00:00 GMT" ) ; static :: header ( "Cache-Control: no-store, no-cache, must-revalidate" ) ; static :: header ( "Cache-Control: post-check=0, pre-check=0" ) ; static :: header ( "Pragma: no-cache" ) ; } static :: header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" ) ; static :: header ( "X-Powered-By: Zap!" , true ) ; if ( ! $ headers ) return ; foreach ( $ headers as $ header ) static :: header ( $ header ) ; }
Start sending response headers .
3,710
public static function send_file ( string $ fpath , $ disposition = null , int $ code = 200 , int $ cache = 0 , array $ headers = [ ] , bool $ xsendfile = null , callable $ callback_notfound = null ) { if ( ! file_exists ( $ fpath ) || is_dir ( $ fpath ) ) { static :: start_header ( 404 , 0 , $ headers ) ; if ( is_callable ( $ callback_notfound ) ) { $ callback_notfound ( ) ; static :: halt ( ) ; } return ; } static :: start_header ( $ code , $ cache , $ headers ) ; static :: header ( 'Content-Length: ' . filesize ( $ fpath ) ) ; static :: header ( "Content-Type: " . Common :: get_mimetype ( $ fpath ) ) ; if ( $ disposition ) { if ( $ disposition === true ) $ disposition = htmlspecialchars ( basename ( $ fpath ) , ENT_QUOTES ) ; static :: header ( sprintf ( 'Content-Disposition: attachment; filename="%s"' , $ disposition ) ) ; } if ( ! $ xsendfile ) readfile ( $ fpath ) ; static :: halt ( ) ; }
Send file .
3,711
final public static function print_json ( int $ errno = 0 , $ data = null , int $ http_code = 200 , int $ cache = 0 ) { $ json = json_encode ( compact ( 'errno' , 'data' ) ) ; self :: start_header ( $ http_code , $ cache , [ 'Content-Length: ' . strlen ( $ json ) , 'Content-Type: application/json' , ] ) ; static :: halt ( $ json ) ; }
Convenience method for JSON response .
3,712
final public static function pj ( $ retval , int $ forbidden_code = null , int $ cache = 0 ) { $ http_code = 200 ; if ( ! is_array ( $ retval ) ) { $ retval = [ - 1 , null ] ; $ forbidden_code = 500 ; } if ( $ retval [ 0 ] !== 0 ) { $ http_code = 401 ; if ( $ forbidden_code ) $ http_code = $ forbidden_code ; } if ( ! isset ( $ retval [ 1 ] ) ) $ retval [ 1 ] = null ; self :: print_json ( $ retval [ 0 ] , $ retval [ 1 ] , $ http_code , $ cache ) ; }
Even shorter JSON response formatter .
3,713
public function all ( ) { $ pluggables = [ ] ; $ allPlugs = $ this -> getAllBaseNames ( ) ; foreach ( $ allPlugs as $ plug ) { $ pluggables [ ] = $ this -> getJsonContents ( $ plug ) ; } return new Collection ( $ this -> sortByOrder ( $ pluggables ) ) ; }
Get all the pluggables .
3,714
protected function getAllBaseNames ( ) { $ pluggables = [ ] ; $ path = $ this -> getPath ( ) ; if ( ! is_dir ( $ path ) ) { return $ pluggables ; } $ folders = $ this -> files -> directories ( $ path ) ; foreach ( $ folders as $ plug ) { $ pluggables [ ] = basename ( $ plug ) ; } return $ pluggables ; }
Get all pluggable basenames .
3,715
protected function getAllSlugs ( ) { $ pluggables = $ this -> all ( ) ; $ slugs = [ ] ; foreach ( $ pluggables as $ plug ) { $ slugs [ ] = $ plug [ 'slug' ] ; } return $ slugs ; }
Get all pluggable slugs .
3,716
protected function pathExists ( $ folder ) { $ folder = Str :: studly ( $ folder ) ; return in_array ( $ folder , $ this -> getAllBaseNames ( ) ) ; }
Check if given pluggable path exists .
3,717
public function getPluggablePath ( $ slug , $ allowNotExists = false ) { $ pluggable = Str :: studly ( $ slug ) ; if ( ! $ this -> pathExists ( $ pluggable ) && $ allowNotExists === false ) { return ; } return $ this -> getPath ( ) . "/{$pluggable}/" ; }
Get path for the specified pluggable .
3,718
public function getProperty ( $ property , $ default = null ) { list ( $ pluggable , $ key ) = explode ( '::' , $ property ) ; return array_get ( $ this -> getJsonContents ( $ pluggable ) , $ key , $ default ) ; }
Get a pluggable property value .
3,719
public function setProperty ( $ property , $ value ) { list ( $ pluggable , $ key ) = explode ( '::' , $ property ) ; $ content = $ this -> getJsonContents ( $ pluggable ) ; if ( count ( $ content ) ) { if ( isset ( $ content [ $ key ] ) ) { unset ( $ content [ $ key ] ) ; } $ content [ $ key ] = $ value ; $ this -> setJsonContents ( $ pluggable , $ content ) ; return true ; } return false ; }
Set a pluggale property value .
3,720
public function getByEnabled ( $ enabled = true ) { $ disabledPluggables = [ ] ; $ enabledPluggables = [ ] ; $ pluggables = $ this -> all ( ) ; foreach ( $ pluggables as $ pluggable ) { if ( $ this -> isEnabled ( $ pluggable [ 'slug' ] ) ) { $ enabledPluggables [ ] = $ pluggable ; } else { $ disabledPluggables [ ] = $ pluggable ; } } if ( $ enabled === true ) { return $ this -> sortByOrder ( $ enabledPluggables ) ; } return $ this -> sortByOrder ( $ disabledPluggables ) ; }
Find a pluggable with enabled status given .
3,721
protected function getJsonContents ( $ pluggable ) { $ pluggable = Str :: studly ( $ pluggable ) ; $ default = [ ] ; if ( ! $ this -> pathExists ( $ pluggable ) ) { return $ default ; } $ path = $ this -> getJsonPath ( $ pluggable ) ; if ( $ this -> files -> exists ( $ path ) ) { $ contents = $ this -> files -> get ( $ path ) ; return json_decode ( $ contents , true ) ; } else { $ message = "Pluggable [{$pluggable}] must have a valid pluggable.json file." ; throw new FileNotFoundException ( $ message ) ; } }
Get pluggable JSON content as an array .
3,722
public function sortByOrder ( $ pluggables ) { $ orderedPluggables = [ ] ; foreach ( $ pluggables as $ pluggable ) { if ( ! isset ( $ pluggable [ 'order' ] ) ) { $ pluggable [ 'order' ] = 9001 ; } $ orderedPluggables [ ] = $ pluggable ; } if ( count ( $ orderedPluggables ) > 0 ) { $ orderedPluggables = $ this -> arrayOrderBy ( $ orderedPluggables , 'order' , SORT_ASC , 'slug' , SORT_ASC ) ; } return $ orderedPluggables ; }
Sort pluggables by order .
3,723
protected function arrayOrderBy ( ) { $ arguments = func_get_args ( ) ; $ data = array_shift ( $ arguments ) ; foreach ( $ arguments as $ argument => $ field ) { if ( is_string ( $ field ) ) { $ temp = [ ] ; foreach ( $ data as $ key => $ row ) { $ temp [ $ key ] = $ row [ $ field ] ; } $ arguments [ $ argument ] = $ temp ; } } $ arguments [ ] = & $ data ; call_user_func_array ( 'array_multisort' , $ arguments ) ; return array_pop ( $ arguments ) ; }
Helper method to order multiple values easily .
3,724
public function listPayments ( $ userId , $ monetaryAccountId ) { $ payments = $ this -> client -> get ( $ this -> getResourceEndpoint ( $ userId , $ monetaryAccountId ) ) ; foreach ( $ payments [ 'Response' ] as $ key => $ payment ) { $ payments [ 'Response' ] [ $ key ] [ 'Payment' ] [ 'amount' ] [ 'value' ] = $ this -> floatToCents ( $ payment [ 'Payment' ] [ 'amount' ] [ 'value' ] ) ; } return $ payments ; }
Lists all payments .
3,725
public function getPayment ( $ userId , $ monetaryAccountId , $ id ) { $ paymentResponse = $ this -> client -> get ( $ this -> getResourceEndpoint ( $ userId , $ monetaryAccountId ) . '/' . ( int ) $ id ) ; $ payment = $ paymentResponse [ 'Response' ] [ 0 ] [ 'Payment' ] ; $ payment [ 'amount' ] [ 'value' ] = $ this -> floatToCents ( $ payment [ 'amount' ] [ 'value' ] ) ; return $ payment ; }
Gets a user its payment information .
3,726
public function changeNodeNameAction ( ) { $ nodeName = $ this -> bodyParam ( 'node_name' ) ; if ( ! is_string ( $ nodeName ) || strlen ( $ nodeName ) < 3 ) { return new ApiProblemResponse ( new ApiProblem ( 422 , $ this -> translator -> translate ( 'The node name must be at least 3 characters long' ) ) ) ; } $ this -> commandBus -> dispatch ( ChangeNodeName :: to ( NodeName :: fromString ( $ nodeName ) , ConfigLocation :: fromPath ( Definition :: getSystemConfigDir ( ) ) ) ) ; return [ 'success' => true ] ; }
Handles a POST request that want to change the node name
3,727
public function configureJavascriptTickerAction ( ) { $ tickerEnabled = $ this -> bodyParam ( 'enabled' ) ; $ tickerInterval = $ this -> bodyParam ( 'interval' ) ; if ( ! is_bool ( $ tickerEnabled ) ) { return new ApiProblemResponse ( new ApiProblem ( 422 , $ this -> translator -> translate ( 'The enabled flag should be a boolean value' ) ) ) ; } if ( ! is_int ( $ tickerInterval ) || $ tickerInterval <= 0 ) { return new ApiProblemResponse ( new ApiProblem ( 422 , $ this -> translator -> translate ( 'The ticker interval should greater than zero' ) ) ) ; } $ this -> commandBus -> dispatch ( ConfigureJavascriptTicker :: set ( $ tickerEnabled , $ tickerInterval , ConfigLocation :: fromPath ( Definition :: getSystemConfigDir ( ) ) ) ) ; return [ 'success' => true ] ; }
Handles a POST request to configure the javascript ticker
3,728
public function configureWorkflowProcessorMessageQueueAction ( ) { $ queueEnabled = $ this -> bodyParam ( 'enabled' ) ; if ( ! is_bool ( $ queueEnabled ) ) { return new ApiProblemResponse ( new ApiProblem ( 422 , $ this -> translator -> translate ( 'The enabled flag should be a boolean value' ) ) ) ; } if ( $ queueEnabled ) { $ this -> commandBus -> dispatch ( EnableWorkflowProcessorMessageQueue :: in ( ConfigLocation :: fromPath ( Definition :: getSystemConfigDir ( ) ) ) ) ; } else { $ this -> commandBus -> dispatch ( DisableWorkflowProcessorMessageQueue :: in ( ConfigLocation :: fromPath ( Definition :: getSystemConfigDir ( ) ) ) ) ; } return [ 'success' => true ] ; }
Handles a POST request to enable or disable the workflow processor message queue
3,729
public static function log ( $ message , $ args = null ) { if ( getenv ( 'DEBUG' ) || getenv ( 'OPENCART_INSTALLER_DEBUG' ) ) { if ( $ args ) { if ( ! is_array ( $ args ) ) { $ args = array ( $ args ) ; } $ message = vsprintf ( $ message , $ args ) ; } echo 'OpencartInstaller: ' . $ message . PHP_EOL ; } }
Writes debug message to stdout .
3,730
function submitFoundationForm ( $ data , $ form ) { if ( isset ( $ data [ 'SecurityID' ] ) ) { unset ( $ data [ 'SecurityID' ] ) ; } Session :: set ( 'FoundationForm' . $ this -> ID , $ data ) ; return $ this -> redirect ( $ this -> Link ( ) ) ; }
submit the form and redirect back to the form
3,731
protected function parseRuleString ( $ ruleString ) { $ charset = $ this -> getCharset ( ) ; $ ruleString = preg_replace ( '/^[ \r\n\t\f]*@import[ \r\n\t\f]+/i' , '' , $ ruleString ) ; $ ruleString = trim ( $ ruleString , " \r\n\t\f" ) ; $ ruleString = rtrim ( $ ruleString , ";" ) ; $ isEscaped = false ; $ inFunction = false ; $ url = "" ; $ mediaQuery = "" ; $ currentPart = "" ; for ( $ i = 0 , $ j = mb_strlen ( $ ruleString , $ charset ) ; $ i < $ j ; $ i ++ ) { $ char = mb_substr ( $ ruleString , $ i , 1 , $ charset ) ; if ( $ char === "\\" ) { if ( $ isEscaped === false ) { $ isEscaped = true ; } else { $ isEscaped = false ; } } else { if ( $ char === " " ) { if ( $ isEscaped === false ) { if ( $ inFunction == false ) { $ currentPart = trim ( $ currentPart , " \r\n\t\f" ) ; if ( $ currentPart !== "" ) { if ( $ url === "" ) { $ url = trim ( $ currentPart , " \r\n\t\f" ) ; } else { $ mediaQuery .= trim ( $ currentPart , " \r\n\t\f" ) ; $ mediaQuery .= $ char ; } $ currentPart = "" ; } } } else { $ currentPart .= $ char ; } } elseif ( $ isEscaped === false && $ char === "(" ) { $ inFunction = true ; $ currentPart .= $ char ; } elseif ( $ isEscaped === false && $ char === ")" ) { $ inFunction = false ; $ currentPart .= $ char ; } else { $ currentPart .= $ char ; } } if ( $ isEscaped === true && $ char !== "\\" ) { $ isEscaped = false ; } } if ( $ currentPart !== "" ) { $ currentPart = trim ( $ currentPart , " \r\n\t\f" ) ; if ( $ currentPart !== "" ) { if ( $ url === "" ) { $ url = trim ( $ currentPart , " \r\n\t\f" ) ; } else { $ mediaQuery .= trim ( $ currentPart , " \r\n\t\f" ) ; } } } $ url = Url :: extractUrl ( $ url ) ; $ this -> setUrl ( $ url ) ; $ mediaRule = new MediaRule ( $ mediaQuery ) ; $ this -> setQueries ( $ mediaRule -> getQueries ( ) ) ; }
Parses the import rule .
3,732
public function markdown ( $ markdown , $ page = null ) { $ file = $ markdown . '.md' ; if ( isset ( $ page ) ) { $ file = $ page . '/' . $ markdown . '.md' ; } if ( ! Storage :: disk ( 'markdown' ) -> exists ( $ file ) ) { return false ; } $ array = $ this -> markdownToArray ( $ file ) ; return $ array ; }
Parses and output a markdown file
3,733
public function markdownLink ( $ file_path , $ type = '' ) { $ array = explode ( '/' , $ file_path ) ; $ dir = $ array [ 0 ] ; $ replace = array ( '-' , '_' ) ; $ url = trim ( $ dir , '.md' ) ; $ display_name = str_replace ( $ replace , ' ' , trim ( $ dir , '.md' ) ) ; if ( count ( $ array ) > 1 ) { $ name = trim ( $ array [ 1 ] , '.md' ) ; $ url = $ dir . '?page=' . $ name ; $ display_name = str_replace ( $ replace , ' ' , $ name ) ; } $ link = ( $ type == 'url' ) ? '/md/' . $ url : '<a href="/md/' . $ url . '" class="markdown-link">' . $ display_name . '</a>' ; return $ link ; }
Converts a give md file path to a link
3,734
public function markdownMenu ( $ dir = null ) { $ md_files = $ this -> markdownFiles ( $ dir ) ; $ links = [ ] ; foreach ( $ md_files as $ file ) { $ links [ ] = $ this -> markdownLink ( $ file , $ this -> type ) ; } return $ links ; }
Returns an list or directory of array of markdown files
3,735
public function markdownPosts ( $ dir = null ) { $ source = collect ( $ this -> markdownFiles ( $ dir ) ) ; if ( empty ( $ source ) ) { return false ; } $ files = $ source -> map ( function ( $ file ) { $ array = $ this -> markdownToArray ( $ file ) ; $ arr [ 'url' ] = $ array [ 'url' ] ; $ arr [ 'last_modified' ] = $ array [ 'last_modified' ] ; $ arr [ 'time_ago' ] = $ array [ 'time_ago' ] ; $ arr [ 'link' ] = $ array [ 'link' ] ; $ arr [ 'title' ] = $ array [ 'title' ] ; $ arr [ 'excerpt' ] = $ array [ 'excerpt' ] ; $ arr [ 'content' ] = $ array [ 'content' ] ; return $ arr ; } ) ; return $ files ; }
Return and array of markdown
3,736
public function markdownToArray ( $ file ) { $ markdown = $ this -> markdown -> transform ( Storage :: disk ( 'markdown' ) -> get ( $ file ) ) ; $ array = explode ( "\n" , $ markdown ) ; $ data [ 'url' ] = $ this -> markdownLink ( $ file , 'url' ) ; $ data [ 'last_modified' ] = date ( 'Y-m-d' , Storage :: disk ( 'markdown' ) -> lastModified ( $ file ) ) ; $ posted = Carbon :: now ( ) -> parse ( $ data [ 'last_modified' ] ) -> diffForHumans ( ) ; $ data [ 'time_ago' ] = $ posted ; $ data [ 'link' ] = $ this -> markdownLink ( $ file ) ; $ data [ 'title' ] = $ array [ 0 ] ; $ data [ 'excerpt' ] = $ array [ 2 ] ; $ data [ 'content' ] = str_replace ( $ data [ 'title' ] , '' , $ markdown ) ; return $ data ; }
Takes a markdown and converts it to array
3,737
public function setFilters ( $ filters ) { if ( ! is_array ( $ filters ) ) { $ this -> clearFilters ( ) ; foreach ( explode ( '|' , $ filters ) as $ filter ) { $ params = [ ] ; if ( strpos ( $ filter , ':' ) ) { list ( $ filter , $ params ) = explode ( ':' , $ filter ) ; $ params = ( array ) explode ( ',' , $ params ) ; } $ this -> addFilter ( $ filter , null , ... $ params ) ; } } else { $ this -> filters = $ filters ; } return $ this ; }
Set all filter as an array
3,738
public function addFilter ( $ index , $ method = null , ... $ params ) { $ this -> filters [ $ index ] = [ $ method , $ params ] ; return $ this ; }
Add a single filter to the filters container
3,739
public function getFilter ( $ index ) { if ( ! $ this -> hasFilter ( $ index ) ) { throw new \ Exception ( 'Impossible de trouver le filtre : ' . $ index ) ; } return $ this -> filters [ $ index ] ; }
Return the filter from the filters container from the filter container
3,740
public function filter ( $ value ) { foreach ( $ this -> getFilters ( ) as $ index => $ filter ) { list ( $ method , $ params ) = $ filter ; $ method = is_null ( $ method ) ? $ index : $ method ; array_unshift ( $ params , $ value ) ; if ( ! is_string ( $ method ) && is_callable ( $ method ) ) { $ value = call_user_func_array ( $ method , $ params ) ; } else { if ( ! method_exists ( $ this , $ method ) ) { throw new \ Exception ( 'Method "' . $ method . '" not found for filter : ' . $ index ) ; } $ value = call_user_func_array ( [ $ this , $ method ] , $ params ) ; } } return $ value ; }
Filter de value
3,741
public function dateFormat ( $ value , $ format = 'd/m/Y' ) { if ( ! empty ( $ value ) ) { if ( strlen ( $ value ) == 10 ) { $ value .= ' 00:00:00' ; } if ( $ value == '0000-00-00 00:00:00' ) { $ value = '' ; } else { $ date = \ DateTime :: createFromFormat ( 'Y-m-d H:i:s' , $ value ) ; if ( $ date !== false && ! array_sum ( $ date -> getLastErrors ( ) ) ) { $ value = $ date -> format ( $ format ) ; } } } return $ value ; }
Format a date
3,742
public function addServer ( int $ engine , string $ host = "127.0.0.1" , int $ port = 0 ) : Server { $ this -> servers [ ] = new Server ( $ engine , $ host , $ port ) ; return end ( $ this -> servers ) ; }
Add a server to connection queue
3,743
public function isConnected ( ) : bool { if ( $ this -> engine ) { $ connected = $ this -> engine -> isConnected ( ) ; if ( ! $ connected ) { $ this -> engine = null ; } return $ connected ; } return false ; }
Check connection status
3,744
public function ping ( bool $ reconnect = false ) : bool { if ( $ this -> engine ) { $ ping = $ this -> engine -> ping ( ) ; if ( ! $ ping ) { $ this -> engine = null ; if ( $ reconnect ) { $ this -> connect ( ) ; } } return $ ping ; } return false ; }
Ping Cache Server
3,745
public function has ( string $ key ) : bool { $ this -> checkConnection ( __METHOD__ ) ; return $ this -> engine -> has ( $ key ) ; }
Checks if a data exists on cache server corresponding to provided key
3,746
public function delete ( string $ key ) : bool { $ this -> checkConnection ( __METHOD__ ) ; $ delete = $ this -> engine -> delete ( $ key ) ; if ( $ delete && $ this -> index ) { $ this -> index -> events ( ) -> trigger ( Indexing :: EVENT_ON_DELETE ) -> params ( $ key ) -> fire ( ) ; } return $ delete ; }
Delete an stored item with provided key on cache server
3,747
public function flush ( ) : bool { $ this -> checkConnection ( __METHOD__ ) ; $ flush = $ this -> engine -> flush ( ) ; if ( $ flush && $ this -> index ) { $ this -> index -> events ( ) -> trigger ( Indexing :: EVENT_ON_FLUSH ) -> fire ( ) ; } return $ flush ; }
Flushes all stored data from cache server
3,748
public function countUp ( string $ key , int $ inc = 1 ) : int { $ this -> checkConnection ( __METHOD__ ) ; return $ this -> engine -> countUp ( $ key , $ inc ) ; }
Increase stored integer value If key doesn t already exist a new key will be created with value 0 before increment
3,749
public function countDown ( string $ key , int $ dec = 1 ) : int { $ this -> checkConnection ( __METHOD__ ) ; return $ this -> engine -> countDown ( $ key , $ dec ) ; }
Decrease stored integer value If key doesn t already exist a new key will be created with value 0 before decrement
3,750
public function setCacheableIdentifier ( string $ id = null , int $ length = null ) : self { if ( $ id ) { if ( ! preg_match ( '/^[a-zA-Z0-9\_\-\~\.]{8,32}$/' , $ id ) ) { throw new CacheException ( 'Invalid value passed to "setCacheableIdentifier" method' ) ; } $ this -> cacheableId = $ id ; $ this -> cacheableIdLength = strlen ( $ id ) ; } if ( $ length ) { if ( $ length < 100 || $ length <= $ this -> cacheableIdLength ) { throw new CacheException ( 'Length of encoded Cacheable objects must start from at least 100' ) ; } $ this -> cacheableLengthFrom = $ length ; } return $ this ; }
Set custom identifier for objects extending CacheableInterface
3,751
private function setObject ( array $ data ) { $ identifierAttribute = $ this -> configuration -> getIdentifierAttribute ( ) ; if ( $ identifierAttribute === null ) { throw new UndefinedIdentifierAttribute ( ) ; } if ( isset ( $ data [ $ identifierAttribute ] ) === true ) { return $ this -> setObjectForObjectData ( $ identifierAttribute , $ data ) ; } return $ this -> setObjectForCollectionData ( $ data ) ; }
Create class object with data
3,752
public function icon ( $ icon , $ is_icon_only = true ) { $ this -> setIcon ( $ icon ) ; ( $ is_icon_only ) ? $ this -> enableIconOnly ( ) : $ this -> disableIconOnly ( ) ; return $ this ; }
Fast setting for icon
3,753
public static function createDir ( $ strPath , $ rights = 0777 ) { $ folderPath = array ( $ strPath ) ; $ oldumask = umask ( 0 ) ; while ( ! @ is_dir ( dirname ( end ( $ folderPath ) ) ) && dirname ( end ( $ folderPath ) ) != "/" && dirname ( end ( $ folderPath ) ) != "." && dirname ( end ( $ folderPath ) ) != "" ) { array_push ( $ folderPath , dirname ( end ( $ folderPath ) ) ) ; } while ( $ parentFolderPath = array_pop ( $ folderPath ) ) { if ( ! @ is_dir ( $ parentFolderPath ) ) { if ( ! @ mkdir ( $ parentFolderPath , $ rights ) ) { throw new \ RuntimeException ( "Runtime Error: Can't create folder: $parentFolderPath" ) ; } } } umask ( $ oldumask ) ; }
Creates a directory recursively
3,754
public function validate ( $ value ) { $ return = parent :: validate ( $ value ) ; if ( $ return -> status === true && ( preg_match ( '/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/' , $ value , $ matches ) ) ) { if ( checkdate ( $ matches [ 2 ] , $ matches [ 3 ] , $ matches [ 1 ] ) ) { $ timestamp = strtotime ( $ value ) ; if ( $ this -> formatMinimum !== null && $ timestamp < strtotime ( $ this -> formatMinimum ) ) { $ failure = 'formatMinimum' ; goto error ; } if ( $ this -> formatMaximum !== null && $ timestamp > strtotime ( $ this -> formatMaximum ) ) { $ failure = 'formatMaximum' ; goto error ; } $ return -> status = true ; return $ return ; } } $ failure = 'failure' ; error : $ return -> status = false ; $ return -> errorObject = new IncorrectParametersException ( [ [ 'type' => static :: getType ( ) , 'failure' => $ failure ] ] ) ; return $ return ; }
Validate value validates as SQL date or SQL datetime
3,755
public function getType ( $ type_name ) { if ( isset ( $ this -> types [ $ type_name ] ) ) { return $ this -> types [ $ type_name ] ; } else { throw new InvalidArgumentException ( "Type '$type_name' not found" ) ; } }
Return type by type name .
3,756
public function build ( $ build_path = null , ConnectionInterface $ connection = null , array $ event_handlers = [ ] ) { $ builders = $ this -> getBuilders ( $ build_path , $ connection , $ event_handlers ) ; foreach ( $ builders as $ builder ) { $ builder -> preBuild ( ) ; } foreach ( $ this -> types as $ type ) { foreach ( $ builders as $ builder ) { $ builder -> buildType ( $ type ) ; } } foreach ( $ builders as $ builder ) { $ builder -> postBuild ( ) ; } }
Build model at the given path .
3,757
private function getBuilders ( $ build_path , ConnectionInterface $ connection = null , array $ event_handlers ) { if ( empty ( $ this -> builders ) ) { $ this -> builders [ ] = new BaseDirBuilder ( $ this ) ; $ this -> builders [ ] = new TypesBuilder ( $ this ) ; $ this -> builders [ ] = new BaseTypeClassBuilder ( $ this ) ; $ this -> builders [ ] = new TypeClassBuilder ( $ this ) ; $ this -> builders [ ] = new TypeTableBuilder ( $ this ) ; $ this -> builders [ ] = new AssociationsBuilder ( $ this ) ; $ this -> builders [ ] = new TriggersBuilder ( $ this ) ; $ this -> builders [ ] = new ManagerDirBuilder ( $ this ) ; $ this -> builders [ ] = new BaseManagerDirBuilder ( $ this ) ; $ this -> builders [ ] = new BaseTypeManagerBuilder ( $ this ) ; $ this -> builders [ ] = new TypeManagerBuilder ( $ this ) ; $ this -> builders [ ] = new CollectionDirBuilder ( $ this ) ; $ this -> builders [ ] = new BaseCollectionDirBuilder ( $ this ) ; $ this -> builders [ ] = new BaseTypeCollectionBuilder ( $ this ) ; $ this -> builders [ ] = new TypeCollectionBuilder ( $ this ) ; if ( $ build_path ) { foreach ( $ this -> builders as $ k => $ v ) { if ( $ v instanceof FileSystemBuilderInterface ) { $ this -> builders [ $ k ] -> setBuildPath ( $ build_path ) ; } } } if ( $ connection ) { foreach ( $ this -> builders as $ k => $ v ) { if ( $ v instanceof DatabaseBuilderInterface ) { $ this -> builders [ $ k ] -> setConnection ( $ connection ) ; } } } foreach ( $ event_handlers as $ event => $ handler ) { foreach ( $ this -> builders as $ k => $ v ) { $ v -> registerEventHandler ( $ event , $ handler ) ; } } } return $ this -> builders ; }
Return a list of prepared builder instances .
3,758
public function setDay ( $ day ) { if ( ! in_array ( $ day , $ this -> weekDays ) ) { throw new InvalidArgumentException ( 'Argument is not a day of the week' ) ; } $ this -> day = $ day ; return $ this ; }
Sets weekday of the weekly date repetition
3,759
public function batchActionPublish ( ProxyQueryInterface $ query ) { try { $ objects = $ query -> select ( 'DISTINCT ' . $ query -> getRootAlias ( ) ) -> getQuery ( ) -> iterate ( ) ; $ i = 0 ; $ em = $ this -> get ( 'doctrine' ) -> getManager ( ) ; foreach ( $ objects as $ object ) { $ object [ 0 ] -> publish ( ) ; $ em -> persist ( $ object [ 0 ] ) ; if ( ( ++ $ i % 20 ) == 0 ) { $ em -> flush ( ) ; $ em -> clear ( ) ; } } $ em -> flush ( ) ; $ em -> clear ( ) ; $ this -> addFlash ( 'sonata_flash_success' , 'flash.success.batch_publish' ) ; } catch ( ModelManagerException $ e ) { $ this -> addFlash ( 'sonata_flash_error' , 'flash.error.batch_publish' ) ; } return new RedirectResponse ( $ this -> admin -> generateUrl ( 'list' , array ( 'filter' => $ this -> admin -> getFilterParameters ( ) ) ) ) ; }
Execute a batch publish
3,760
public function setupTwig ( ) { $ twigLoader = new TwigLoader ( $ this -> viewManager ) ; $ config = [ ] ; if ( $ this -> viewManager -> cachePath ) { $ config [ 'cache' ] = $ this -> viewManager -> cachePath . 'twig/' ; } $ this -> twig = new Twig_Environment ( $ twigLoader , $ config ) ; }
Sets the Twig Environment up
3,761
public function addItem ( BaseField $ objItem ) { $ this -> items [ ] = $ objItem ; end ( $ this -> items ) ; $ key = key ( $ this -> items ) ; $ this -> index [ $ key ] = $ objItem -> get ( 'colName' ) ; }
Add an item of type BaseField to the field collection
3,762
public function findItemByColName ( $ colName ) { if ( in_array ( $ colName , $ this -> index ) ) { return $ this -> items [ array_search ( $ colName , $ this -> index ) ] ; } return false ; }
Get an item by its colName
3,763
public function getBindedLabel ( $ row = [ ] ) { $ bind = isset ( $ row [ $ this -> getName ( ) ] ) ? $ row [ $ this -> getName ( ) ] : false ; return sprintf ( $ this -> getLabel ( ) , $ bind ) ; }
Return the binded Label
3,764
public function runAction ( ) { try { $ this -> commandBus -> dispatch ( CreateDefaultProcessingConfigFile :: in ( ConfigLocation :: fromPath ( Definition :: getSystemConfigDir ( ) ) ) ) ; $ sqliteDbFile = SqliteDbFile :: initializeFromDist ( Definition :: getEventStoreSqliteDbFile ( ) ) ; $ esConfigLocation = ConfigLocation :: fromPath ( Definition :: getSystemConfigDir ( ) ) ; $ this -> commandBus -> dispatch ( InitializeEventStore :: setUpWithSqliteDbAdapter ( $ sqliteDbFile , $ esConfigLocation ) ) ; } catch ( \ Exception $ ex ) { $ this -> commandBus -> dispatch ( UndoSystemSetUp :: removeConfigs ( Definition :: getSystemConfigDir ( ) , Definition :: getSystemConfigDir ( ) , Definition :: getEventStoreSqliteDbFile ( ) ) ) ; throw $ ex ; } return $ this -> redirect ( ) -> toRoute ( 'prooph.link/system_config' ) ; }
Runs the initial set up of the processing system
3,765
public function load ( array $ configs , ContainerBuilder $ container ) { $ loader = new YamlFileLoader ( $ container , new FileLocator ( __DIR__ . '/../Resources/config' ) ) ; $ loader -> load ( 'services.yml' ) ; $ config = $ this -> processConfiguration ( new Configuration ( ) , $ configs ) ; $ container -> setAlias ( 'best_it_ct_order_export.export.filesystem' , $ config [ 'filesystem' ] ) ; $ container -> setAlias ( 'best_it_ct_order_export.logger' , $ config [ 'logger' ] ) ; $ container -> setParameter ( 'best_it_ct_order_export.commercetools.client.id' , ( string ) @ $ config [ 'commercetools_client' ] [ 'id' ] ) ; $ container -> setParameter ( 'best_it_ct_order_export.commercetools.client.secret' , ( string ) @ $ config [ 'commercetools_client' ] [ 'secret' ] ) ; $ container -> setParameter ( 'best_it_ct_order_export.commercetools.client.project' , ( string ) @ $ config [ 'commercetools_client' ] [ 'project' ] ) ; $ container -> setParameter ( 'best_it_ct_order_export.commercetools.client.scope' , ( string ) @ $ config [ 'commercetools_client' ] [ 'scope' ] ) ; $ container -> setParameter ( 'best_it_ct_order_export.orders.with_pagination' , ( bool ) ( $ config [ 'orders' ] [ 'with_pagination' ] ?? true ) ) ; $ container -> setParameter ( 'best_it_ct_order_export.orders.file_template' , $ config [ 'orders' ] [ 'file_template' ] ) ; $ container -> setParameter ( 'best_it_ct_order_export.orders.name_scheme' , $ config [ 'orders' ] [ 'name_scheme' ] ) ; $ container -> setParameter ( 'best_it_ct_order_export.orders.default_where' , $ config [ 'orders' ] [ 'default_where' ] ?? [ ] ) ; }
Loads the bundle config .
3,766
function resolve ( $ url = '' , $ query_string_vars = [ ] ) { $ url = filter_var ( $ url , FILTER_SANITIZE_URL ) ; if ( ! empty ( $ url ) ) { $ id = md5 ( $ url . serialize ( $ query_string_vars ) ) ; if ( ! isset ( $ this -> items [ $ id ] ) || ! $ this -> items [ $ id ] instanceof UrlToQueryItem ) { $ this -> items [ $ id ] = new UrlToQueryItem ( $ this ) ; } $ result = $ this -> items [ $ id ] -> resolve ( $ url , $ query_string_vars ) ; } else { $ result = new \ WP_Error ( 'url-to-query-bad-url' ) ; } return $ result ; }
Resolve an url to an array of WP_Query arguments for main query
3,767
private function serializeIterable ( $ resource , OutputStream $ out ) { $ memory = fopen ( 'php://memory' , 'wb' ) ; if ( is_array ( $ resource ) && is_scalar ( current ( $ resource ) ) ) { if ( ! is_numeric ( key ( $ resource ) ) ) { $ out -> write ( $ this -> toCsvLine ( array_keys ( $ resource ) , $ memory ) ) ; } $ out -> write ( $ this -> toCsvLine ( $ resource , $ memory ) ) ; } else { $ head = true ; foreach ( Sequence :: of ( $ resource ) -> map ( 'stubbles\sequence\castToArray' ) as $ elements ) { if ( $ head && ! is_numeric ( key ( $ elements ) ) ) { $ out -> write ( $ this -> toCsvLine ( array_keys ( $ elements ) , $ memory ) ) ; } $ head = false ; $ out -> write ( $ this -> toCsvLine ( $ elements , $ memory ) ) ; } } fclose ( $ memory ) ; }
serializes iterable to csv
3,768
private function toCsvLine ( array $ elements , $ memory ) : string { ftruncate ( $ memory , 0 ) ; rewind ( $ memory ) ; fputcsv ( $ memory , $ elements , $ this -> delimiter , $ this -> enclosure ) ; rewind ( $ memory ) ; return stream_get_contents ( $ memory ) ; }
turns given list of elements into a line suitable for csv
3,769
public function actionIndex ( ) { if ( ! $ this -> hasAccess ( ) ) { return $ this -> redirect ( [ 'login' ] ) ; } foreach ( $ this -> module -> assetFiles as $ class ) { $ this -> registerAsset ( $ class ) ; } return $ this -> render ( 'index' , [ 'title' => 'Styleguide' , 'showDomain' => true , 'styleguide' => $ this -> extractElementsFromComponent ( ) ] ) ; }
Render Styleguide .
3,770
public function actionLogin ( ) { $ password = Yii :: $ app -> request -> post ( 'pass' , false ) ; if ( $ password === $ this -> module -> password || $ this -> hasAccess ( ) ) { Yii :: $ app -> session -> set ( self :: STYLEGUIDE_SESSION_PWNAME , $ password ) ; return $ this -> redirect ( [ 'index' ] ) ; } elseif ( $ password !== false ) { Yii :: $ app -> session -> setFlash ( 'wrong.styleguide.password' ) ; } return $ this -> render ( 'login' ) ; }
Login action if password is required .
3,771
protected function extractElementsFromComponent ( ) { $ elements = [ ] ; foreach ( Yii :: $ app -> element -> getElements ( ) as $ name => $ closure ) { $ reflection = new \ ReflectionFunction ( $ closure ) ; $ args = $ reflection -> getParameters ( ) ; $ params = [ ] ; $ writtenParams = [ ] ; foreach ( $ args as $ k => $ v ) { $ mock = Yii :: $ app -> element -> getMockedArgValue ( $ name , $ v -> name ) ; if ( $ mock !== false ) { $ params [ ] = $ mock ; if ( is_array ( $ mock ) ) { $ writtenParams [ ] = 'array $' . $ v -> name ; } else { $ writtenParams [ ] = '$' . $ v -> name ; } } else { if ( $ v -> isArray ( ) ) { $ params [ ] = [ '$' . $ v -> name ] ; $ writtenParams [ ] = 'array $' . $ v -> name ; } else { $ params [ ] = '$' . $ v -> name ; $ writtenParams [ ] = '$' . $ v -> name ; } } } $ elements [ ] = $ this -> defineElement ( $ name , $ name , null , $ params , [ ] , $ writtenParams ) ; } return [ 'groups' => [ [ 'name' => 'Elements' , 'description' => 'Basic element overview' , 'elements' => $ elements , ] ] ] ; }
Extract the data from the element component
3,772
protected function defineElement ( $ element , $ name = null , $ description = null , array $ values = [ ] , array $ options = [ ] , array $ params = [ ] ) { return [ 'name' => $ name ? : $ element , 'description' => $ description , 'element' => $ element , 'values' => $ values , 'params' => $ params , ] ; }
Generate the array for a given element .
3,773
protected function hasAccess ( ) { return $ this -> module -> password == Yii :: $ app -> session -> get ( self :: STYLEGUIDE_SESSION_PWNAME , false ) ; }
Whether current session contains password or not .
3,774
public function add ( $ item , $ prepend = false ) { if ( ! $ item instanceof ChildNodeInterface ) { $ details = is_object ( $ item ) ? get_class ( $ item ) : gettype ( $ item ) ; throw new InvalidArgumentException ( "NodeCollection accepts only objects implementing ChildNodeInterface, $details given." ) ; } $ old = $ item -> parent ( ) ; if ( $ old === $ this -> parentNode ) { return $ this ; } elseif ( $ old !== null ) { $ item -> detach ( ) ; } $ this -> checkUnlocked ( $ item ) ; parent :: add ( $ item , $ prepend ) ; $ item -> internalSetParent ( $ this -> parentNode ) ; return $ this ; }
Adds component to collection .
3,775
public function getImplementedMethods ( ) { $ supported_methods = $ this -> getConfiguration ( ) -> get ( 'supported-http-methods' ) ; if ( is_null ( $ supported_methods ) ) $ supported_methods = self :: $ supported_methods ; if ( method_exists ( $ this , 'any' ) ) { return $ supported_methods ; } $ implemented_methods = [ ] ; foreach ( $ supported_methods as $ method ) { if ( method_exists ( $ this , strtolower ( $ method ) ) ) array_push ( $ implemented_methods , $ method ) ; } return $ implemented_methods ; }
Get service - implemented HTTP methods
3,776
public function getMethod ( $ method ) { $ method = strtolower ( $ method ) ; if ( method_exists ( $ this , $ method ) ) { return $ method ; } else if ( method_exists ( $ this , 'any' ) ) { return 'any' ; } else { return null ; } }
Return the callable class method that reflect the requested one
3,777
protected function stubReplace ( $ placeholder , $ replace , $ pregReplace = false ) { if ( $ pregReplace ) { $ this -> data -> output [ 'content' ] = preg_replace ( $ placeholder , $ replace , $ this -> data -> output [ 'content' ] ) ; } else { $ this -> data -> output [ 'content' ] = str_replace ( $ placeholder , $ replace , $ this -> data -> output [ 'content' ] ) ; } return $ this ; }
Replaces output stub content placeholders with actual content
3,778
protected function getLongestKey ( array $ array ) { $ longest = 0 ; foreach ( $ array as $ key => $ value ) { if ( $ longest > strlen ( $ key ) ) continue ; $ longest = strlen ( $ key ) ; } return $ longest ; }
Returns length of longest key in key - value pair array
3,779
public function attr ( $ attribute ) { if ( strpos ( $ attribute , ':' ) !== false ) { list ( $ ns , $ attribute ) = explode ( ':' , $ attribute , 2 ) ; return trim ( ( string ) $ this -> el -> attributes ( $ ns , true ) -> { $ attribute } ) ; } return trim ( ( string ) $ this -> el -> attributes ( ) -> { $ attribute } ) ; }
Get a node attribute value . Namespace prefixes are supported .
3,780
public function first ( $ path ) { $ x = $ this -> xpath ( $ path ) ; return count ( $ x ) ? $ x [ 0 ] : null ; }
Get the first node matching an XPath query or null if no match .
3,781
public function has ( $ path ) { $ x = $ this -> xpath ( $ path ) ; return count ( $ x ) ? true : false ; }
Check if the document has at least one node matching an XPath query .
3,782
public function xpath ( $ path ) { return array_map ( function ( $ el ) { return new QuiteSimpleXMLElement ( $ el , $ this ) ; } , $ this -> el -> xpath ( $ path ) ) ; }
Get all nodes matching an XPath query .
3,783
public function text ( $ path = '.' , $ trim = true ) { $ text = strval ( $ this -> first ( $ path ) ) ; return $ trim ? trim ( $ text ) : $ text ; }
Get the text of the first node matching an XPath query . By default the text will be trimmed but if you want the untrimmed text set the second parameter to False .
3,784
static public function validateClientConfig ( array $ config ) { $ tags = [ static :: T8700 , static :: T8915 , static :: T8914 ] ; foreach ( $ tags as $ tag ) { if ( ! array_key_exists ( $ tag , $ config ) || empty ( $ config [ $ tag ] ) ) { throw new InvalidArgumentException ( "Please configure value for tag " . $ tag ) ; } } }
Validates the client configuration .
3,785
public function initRolePermissions ( $ overrideExisting = true ) { if ( null !== $ this -> collRolePermissions && ! $ overrideExisting ) { return ; } $ this -> collRolePermissions = new ObjectCollection ( ) ; $ this -> collRolePermissions -> setModel ( '\Alchemy\Component\Cerberus\Model\RolePermission' ) ; }
Initializes the collRolePermissions collection .
3,786
public function addRolePermission ( ChildRolePermission $ l ) { if ( $ this -> collRolePermissions === null ) { $ this -> initRolePermissions ( ) ; $ this -> collRolePermissionsPartial = true ; } if ( ! $ this -> collRolePermissions -> contains ( $ l ) ) { $ this -> doAddRolePermission ( $ l ) ; } return $ this ; }
Method called to associate a ChildRolePermission object to this object through the ChildRolePermission foreign key attribute .
3,787
public function initUsers ( ) { $ this -> collUsers = new ObjectCollection ( ) ; $ this -> collUsersPartial = true ; $ this -> collUsers -> setModel ( '\Alchemy\Component\Cerberus\Model\User' ) ; }
Initializes the collUsers collection .
3,788
public function getUsers ( Criteria $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collUsersPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collUsers || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) ) { if ( null === $ this -> collUsers ) { $ this -> initUsers ( ) ; } } else { $ query = ChildUserQuery :: create ( null , $ criteria ) -> filterByRole ( $ this ) ; $ collUsers = $ query -> find ( $ con ) ; if ( null !== $ criteria ) { return $ collUsers ; } if ( $ partial && $ this -> collUsers ) { foreach ( $ this -> collUsers as $ obj ) { if ( ! $ collUsers -> contains ( $ obj ) ) { $ collUsers [ ] = $ obj ; } } } $ this -> collUsers = $ collUsers ; $ this -> collUsersPartial = false ; } } return $ this -> collUsers ; }
Gets a collection of ChildUser objects related by a many - to - many relationship to the current object by way of the user_role cross - reference table .
3,789
public function countUsers ( Criteria $ criteria = null , $ distinct = false , ConnectionInterface $ con = null ) { $ partial = $ this -> collUsersPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collUsers || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collUsers ) { return 0 ; } else { if ( $ partial && ! $ criteria ) { return count ( $ this -> getUsers ( ) ) ; } $ query = ChildUserQuery :: create ( null , $ criteria ) ; if ( $ distinct ) { $ query -> distinct ( ) ; } return $ query -> filterByRole ( $ this ) -> count ( $ con ) ; } } else { return count ( $ this -> collUsers ) ; } }
Gets the number of User objects related by a many - to - many relationship to the current object by way of the user_role cross - reference table .
3,790
public function addUser ( ChildUser $ user ) { if ( $ this -> collUsers === null ) { $ this -> initUsers ( ) ; } if ( ! $ this -> getUsers ( ) -> contains ( $ user ) ) { $ this -> collUsers -> push ( $ user ) ; $ this -> doAddUser ( $ user ) ; } return $ this ; }
Associate a ChildUser to this object through the user_role cross reference table .
3,791
public function removeUser ( ChildUser $ user ) { if ( $ this -> getUsers ( ) -> contains ( $ user ) ) { $ userRole = new ChildUserRole ( ) ; $ userRole -> setUser ( $ user ) ; if ( $ user -> isRolesLoaded ( ) ) { $ user -> getRoles ( ) -> removeObject ( $ this ) ; } $ userRole -> setRole ( $ this ) ; $ this -> removeUserRole ( clone $ userRole ) ; $ userRole -> clear ( ) ; $ this -> collUsers -> remove ( $ this -> collUsers -> search ( $ user ) ) ; if ( null === $ this -> usersScheduledForDeletion ) { $ this -> usersScheduledForDeletion = clone $ this -> collUsers ; $ this -> usersScheduledForDeletion -> clear ( ) ; } $ this -> usersScheduledForDeletion -> push ( $ user ) ; } return $ this ; }
Remove user of this object through the user_role cross reference table .
3,792
public function initPermissions ( ) { $ this -> collPermissions = new ObjectCollection ( ) ; $ this -> collPermissionsPartial = true ; $ this -> collPermissions -> setModel ( '\Alchemy\Component\Cerberus\Model\Permission' ) ; }
Initializes the collPermissions collection .
3,793
public function getPermissions ( Criteria $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collPermissionsPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collPermissions || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) ) { if ( null === $ this -> collPermissions ) { $ this -> initPermissions ( ) ; } } else { $ query = ChildPermissionQuery :: create ( null , $ criteria ) -> filterByRole ( $ this ) ; $ collPermissions = $ query -> find ( $ con ) ; if ( null !== $ criteria ) { return $ collPermissions ; } if ( $ partial && $ this -> collPermissions ) { foreach ( $ this -> collPermissions as $ obj ) { if ( ! $ collPermissions -> contains ( $ obj ) ) { $ collPermissions [ ] = $ obj ; } } } $ this -> collPermissions = $ collPermissions ; $ this -> collPermissionsPartial = false ; } } return $ this -> collPermissions ; }
Gets a collection of ChildPermission objects related by a many - to - many relationship to the current object by way of the role_permission cross - reference table .
3,794
public function countPermissions ( Criteria $ criteria = null , $ distinct = false , ConnectionInterface $ con = null ) { $ partial = $ this -> collPermissionsPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collPermissions || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collPermissions ) { return 0 ; } else { if ( $ partial && ! $ criteria ) { return count ( $ this -> getPermissions ( ) ) ; } $ query = ChildPermissionQuery :: create ( null , $ criteria ) ; if ( $ distinct ) { $ query -> distinct ( ) ; } return $ query -> filterByRole ( $ this ) -> count ( $ con ) ; } } else { return count ( $ this -> collPermissions ) ; } }
Gets the number of Permission objects related by a many - to - many relationship to the current object by way of the role_permission cross - reference table .
3,795
public function addPermission ( ChildPermission $ permission ) { if ( $ this -> collPermissions === null ) { $ this -> initPermissions ( ) ; } if ( ! $ this -> getPermissions ( ) -> contains ( $ permission ) ) { $ this -> collPermissions -> push ( $ permission ) ; $ this -> doAddPermission ( $ permission ) ; } return $ this ; }
Associate a ChildPermission to this object through the role_permission cross reference table .
3,796
public function removePermission ( ChildPermission $ permission ) { if ( $ this -> getPermissions ( ) -> contains ( $ permission ) ) { $ rolePermission = new ChildRolePermission ( ) ; $ rolePermission -> setPermission ( $ permission ) ; if ( $ permission -> isRolesLoaded ( ) ) { $ permission -> getRoles ( ) -> removeObject ( $ this ) ; } $ rolePermission -> setRole ( $ this ) ; $ this -> removeRolePermission ( clone $ rolePermission ) ; $ rolePermission -> clear ( ) ; $ this -> collPermissions -> remove ( $ this -> collPermissions -> search ( $ permission ) ) ; if ( null === $ this -> permissionsScheduledForDeletion ) { $ this -> permissionsScheduledForDeletion = clone $ this -> collPermissions ; $ this -> permissionsScheduledForDeletion -> clear ( ) ; } $ this -> permissionsScheduledForDeletion -> push ( $ permission ) ; } return $ this ; }
Remove permission of this object through the role_permission cross reference table .
3,797
private function detect ( ) { $ this -> xss = false ; if ( ! $ this -> string ) { return ; } foreach ( $ this -> list as $ item ) { if ( preg_match ( "`$item`i" , $ this -> string ) ) { $ this -> xss = true ; } } }
DETECT XSS URL ATTACK
3,798
public function registerFunction ( ExpressionFunctionInterface $ function ) { $ this -> expressionLanguage -> register ( $ function -> getName ( ) , $ function -> getCompiler ( ) , $ function -> getEvaluator ( ) ) ; foreach ( $ function -> getContextVariables ( ) as $ name => $ value ) { $ this -> setContextVariable ( $ name , $ value ) ; } return $ this ; }
Register a new new ExpressionLanguage function .
3,799
public function onInteraction ( $ consumer , $ interaction , $ hash ) { echo 'Type: ' . $ interaction [ 'interaction' ] [ 'type' ] . "\n" ; echo 'Content: ' . $ interaction [ 'interaction' ] [ 'content' ] . "\n--\n" ; if ( $ this -> _num -- == 1 ) { echo "Stopping consumer...\n" ; $ consumer -> stop ( ) ; } }
Called for each interaction consumed .