idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
26,500
public static function compileAttributeStringFromArray ( array $ array ) : string { $ attributeString = '' ; foreach ( $ array as $ key => $ value ) { if ( null === $ value || ( \ is_bool ( $ value ) && $ value ) ) { $ attributeString .= "$key " ; } else if ( ! \ is_bool ( $ value ) ) { $ attributeString .= "$key=\"$value\" " ; } } return $ attributeString ? ' ' . $ attributeString : '' ; }
Walk through the array and create an HTML tag attribute string
26,501
public static function getFormatPatternByGostType ( $ gost_type ) { foreach ( static :: $ patterns_and_types_map as $ format_pattern => $ gost_types ) { foreach ( ( array ) $ gost_types as $ iterated_gost_type ) { if ( $ iterated_gost_type === $ gost_type ) { return $ format_pattern ; } } } }
Get pattern format by passed GOST type .
26,502
public function getFormatPattern ( ) { static $ kyr = self :: KYR_CHARS ; switch ( true ) { case \ preg_match ( "~^[{$kyr}]{1}\d{3}[{$kyr}]{2}\d{2,3}$~iu" , $ this -> value ) === 1 : return self :: FORMAT_PATTERN_1 ; case \ preg_match ( "~^[{$kyr}]{1}\d{3}[{$kyr}]{2}$~iu" , $ this -> value ) === 1 : return self :: FORMAT_PATTERN_2 ; case \ preg_match ( "~^[{$kyr}]{2}\d{3}\d{2}$~iu" , $ this -> value ) === 1 : return self :: FORMAT_PATTERN_3 ; case \ preg_match ( "~^\d{4}[{$kyr}]{2}\d{2}$~iu" , $ this -> value ) === 1 : return self :: FORMAT_PATTERN_4 ; case \ preg_match ( "~^[{$kyr}]{2}\d{4}\d{2}$~iu" , $ this -> value ) === 1 : return self :: FORMAT_PATTERN_5 ; case \ preg_match ( "~^[{$kyr}]{1}\d{4}\d{2}$~iu" , $ this -> value ) === 1 : return self :: FORMAT_PATTERN_6 ; case \ preg_match ( "~^\d{3}[{$kyr}]{1}\d{2}$~iu" , $ this -> value ) === 1 : return self :: FORMAT_PATTERN_7 ; case \ preg_match ( "~^\d{4}[{$kyr}]{1}\d{2}$~iu" , $ this -> value ) === 1 : return self :: FORMAT_PATTERN_8 ; } }
Returns value format pattern .
26,503
public function getPath ( $ size ) { if ( $ this -> isProvided ( ) ) { return $ this -> locationBuilder -> buildPath ( $ this -> id , $ this -> cover , $ size ) ; } else { throw new RuntimeException ( 'You gotta provide both id and cover to use this method' ) ; } }
Returns image path on the file - system filtered by provided size
26,504
public function getUrl ( $ size ) { if ( $ this -> isProvided ( ) ) { return $ this -> locationBuilder -> buildUrl ( $ this -> id , $ this -> cover , $ size ) ; } else { throw new RuntimeException ( 'You gotta provide both id and cover to use this method' ) ; } }
Returns image URL filtered by provided size
26,505
public function isValid ( $ target ) { if ( $ target >= $ this -> start && $ target <= $ this -> end ) { return true ; } else { $ this -> violate ( sprintf ( $ this -> message , $ this -> start , $ this -> end ) ) ; return false ; } }
Checks whether values
26,506
public function deployBuild ( $ opts = [ 'build-path' => null , 'deploy-type' => 'git' , 'include-asset' => [ ] , ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ build_path = $ this -> buildPath ( $ opts ) ; $ deploy_type = $ opts [ 'deploy-type' ] ; if ( ! file_exists ( $ build_path ) ) { $ this -> _mkdir ( $ build_path ) ; } $ this -> executeBuild ( __FUNCTION__ , $ build_path ) ; $ this -> executeIncludeAssets ( $ opts [ 'include-asset' ] , $ build_path ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; $ continue = ! is_null ( $ deploy_type ) ? $ this -> doAsk ( new ConfirmationQuestion ( 'Run deployment? (y/n) [yes] ' , true ) ) : false ; if ( ! $ continue ) { return ; } $ this -> deployPush ( [ 'build-path' => $ build_path , 'deploy-type' => $ deploy_type ] ) ; }
Run the deployment build process .
26,507
public function deployPush ( $ opts = [ 'build-path' => null , 'deploy-type' => 'git' , ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ build_path = $ this -> buildPath ( $ opts ) ; if ( ! file_exists ( $ build_path ) ) { throw new DeploymentRuntimeException ( 'Build directory does not exist.' ) ; } $ deploy = $ this -> loadDeployTask ( $ opts [ 'deploy-type' ] , $ build_path ) ; $ this -> executeDeploy ( __FUNCTION__ , $ deploy ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; }
Run the deployment push process .
26,508
protected function executeIncludeAssets ( array $ assets , $ build_path ) { $ root_path = ProjectX :: projectRoot ( ) ; foreach ( $ assets as $ asset ) { $ file_info = new \ splFileInfo ( "{$root_path}/{$asset}" ) ; if ( ! file_exists ( $ file_info ) ) { continue ; } $ file_path = $ file_info -> getRealPath ( ) ; $ file_method = $ file_info -> isFile ( ) ? '_copy' : '_mirrorDir' ; call_user_func_array ( [ $ this , $ file_method ] , [ $ file_path , "{$build_path}/{$file_info->getFilename()}" ] ) ; } }
Execute including assets to the build directory .
26,509
protected function executeBuild ( $ method , $ build_path ) { $ this -> say ( 'Build has initialized!' ) ; $ this -> executeCommandHook ( $ method , 'before_build' ) ; $ this -> projectInstance ( ) -> onDeployBuild ( $ build_path ) ; $ this -> executeCommandHook ( $ method , 'after_build' ) ; $ this -> say ( 'Build has completed!' ) ; return $ this ; }
Execute build process .
26,510
protected function executeDeploy ( $ method , DeployBase $ deploy ) { $ this -> say ( 'Deploy has initialized!' ) ; $ deploy -> beforeDeploy ( ) ; $ this -> executeCommandHook ( $ method , 'before_deploy' ) ; $ deploy -> onDeploy ( ) ; $ this -> executeCommandHook ( $ method , 'after_deploy' ) ; $ deploy -> afterDeploy ( ) ; $ this -> say ( 'Deploy has completed!' ) ; return $ this ; }
Execute deployment process .
26,511
protected function loadDeployTask ( $ type , $ build_path , array $ configurations = [ ] ) { $ definitions = $ this -> deployDefinitions ( ) ; $ classname = isset ( $ definitions [ $ type ] ) && class_exists ( $ definitions [ $ type ] ) ? $ definitions [ $ type ] : 'Droath\ProjectX\Deploy\NullDeploy' ; return ( new $ classname ( $ build_path , $ configurations ) ) -> setInput ( $ this -> input ( ) ) -> setOutput ( $ this -> output ( ) ) -> setBuilder ( $ this -> getBuilder ( ) ) -> setContainer ( $ this -> getContainer ( ) ) ; }
Load deployment task .
26,512
private function hasUncommittedChanges ( $ git ) { $ status = $ git -> status ( ) -> short ( ) -> getIndexStatus ( ) ; if ( empty ( $ status ) ) { return false ; } return true ; }
Check if git repository has uncommitted modifications .
26,513
public function sslRedirect ( ) { if ( ! $ this -> isSecure ( ) ) { $ redirect = 'https://' . $ this -> server [ 'HTTP_HOST' ] . $ this -> server [ 'REQUEST_URI' ] ; header ( 'HTTP/1.1 301 Moved Permanently' ) ; header ( 'Location: ' . $ redirect ) ; exit ( ) ; } }
Run HTTP to HTTPs redirect
26,514
public function getAll ( $ separate = true ) { if ( $ this -> isPost ( ) ) { $ data = $ this -> getPost ( ) ; } if ( $ this -> isGet ( ) ) { $ data = $ this -> getQuery ( ) ; } if ( $ this -> hasFiles ( ) ) { $ files = $ this -> getFiles ( ) ; } else { $ files = array ( ) ; } if ( $ separate === false ) { return array_merge ( $ data , $ files ) ; } else { $ result = array ( ) ; $ result [ 'data' ] = $ data ; $ result [ 'files' ] = ! empty ( $ files ) ? $ files : array ( ) ; return $ result ; } }
Returns all request data
26,515
public function buildQuery ( array $ params , $ includeCurrent = true ) { if ( $ includeCurrent == true ) { $ params = array_replace_recursive ( $ this -> getQuery ( ) , $ params ) ; } return $ this -> serialize ( $ params ) ; }
Builds query string
26,516
public function getFile ( $ name = null , $ index = 0 , $ default = false ) { $ files = $ this -> getFiles ( $ name ) ; if ( isset ( $ files [ $ index ] ) ) { return $ files [ $ index ] ; } else { return $ default ; } }
Returns a single file bag from uploaded collection
26,517
public function hasFiles ( $ name = null ) { if ( ! empty ( $ this -> files ) ) { return $ this -> getFilesbag ( ) -> hasFiles ( $ name ) ; } return false ; }
Checks whether we at least one file
26,518
private function getFilesbag ( ) { static $ filesBag = null ; if ( is_null ( $ filesBag ) ) { $ filesBag = new FileInput ( $ this -> files ) ; } return $ filesBag ; }
Returns files bag For internal usage only
26,519
public function getSubdomains ( ) { $ current = $ this -> server [ 'HTTP_HOST' ] ; $ parts = explode ( '.' , $ current ) ; array_pop ( $ parts ) ; array_pop ( $ parts ) ; return $ parts ; }
Returns all sub - domains
26,520
public function getDomain ( ) { $ current = $ this -> server [ 'HTTP_HOST' ] ; $ parts = explode ( '.' , $ current ) ; $ zone = array_pop ( $ parts ) ; $ provider = array_pop ( $ parts ) ; return $ provider . '.' . $ zone ; }
Returns base domain
26,521
public function getLanguages ( ) { $ source = $ this -> server [ 'HTTP_ACCEPT_LANGUAGE' ] ; if ( strpos ( $ source , ',' ) !== false ) { $ langs = explode ( ',' , $ source ) ; return $ langs ; } else { return array ( $ source ) ; } }
Returns all available languages supported by browser
26,522
public function isSecure ( ) { return ( ( ! empty ( $ this -> server [ 'HTTPS' ] ) && $ this -> server [ 'HTTPS' ] != 'off' ) || ( ! empty ( $ this -> server [ 'HTTP_HTTPS' ] ) && $ this -> server [ 'HTTP_HTTPS' ] != 'off' ) || $ this -> server [ 'REQUEST_SCHEME' ] == 'https' || $ this -> server [ 'SERVER_PORT' ] == 443 ) ; }
Checks whether requested from secured connection
26,523
public function hasQueryNs ( $ ns , $ key ) { $ data = $ this -> getQuery ( $ ns ) ; if ( is_array ( $ data ) ) { return array_key_exists ( $ key , $ data ) ; } else { return false ; } }
Checks whether there s a key in namespaced query
26,524
public function getQueryNs ( $ ns , $ key , $ default ) { if ( $ this -> hasQueryNs ( $ ns , $ key ) ) { $ data = $ this -> getQuery ( $ ns ) ; if ( isset ( $ data [ $ key ] ) ) { return $ data [ $ key ] ; } } return $ default ; }
Returns key s value from a namespace
26,525
public function getWithNsQuery ( $ ns , array $ data , $ mark = true ) { if ( $ this -> hasQuery ( $ ns ) ) { $ query = $ this -> getQuery ( $ ns ) ; $ url = null ; if ( $ mark === true ) { $ url = '?' ; } $ url .= http_build_query ( array ( $ ns => array_merge ( $ query , $ data ) ) ) ; $ url = str_replace ( '%25s' , '%s' , $ url ) ; return $ url ; } else { return null ; } }
Merges and returns current query data with defined data and returns as query string
26,526
public function getWithQuery ( array $ data , $ mark = true ) { if ( $ this -> hasQuery ( ) ) { $ url = null ; if ( $ mark === true ) { $ url = '?' ; } $ url .= http_build_query ( array_merge ( $ this -> getQuery ( ) , $ data ) ) ; $ url = str_replace ( '%25s' , '%s' , $ url ) ; return $ url ; } else { return null ; } }
Returns current query with merged data
26,527
public function hasQuery ( ) { if ( func_num_args ( ) == 0 ) { return ! empty ( $ this -> query ) ; } foreach ( func_get_args ( ) as $ key ) { if ( ! $ this -> hasParam ( $ this -> query , $ key ) ) { return false ; } } return true ; }
Checks whether query has a parameter or its empty
26,528
public function hasPost ( ) { if ( func_num_args ( ) == 0 ) { return ! empty ( $ this -> post ) ; } foreach ( func_get_args ( ) as $ key ) { if ( ! $ this -> hasParam ( $ this -> post , $ key ) ) { return false ; } } return true ; }
Checks whether post parameter exists or the whole array isn t empty
26,529
public function getPost ( $ key = null , $ default = false ) { if ( $ key !== null ) { if ( array_key_exists ( $ key , $ this -> post ) ) { return $ this -> post [ $ key ] ; } else { return $ default ; } } else { return $ this -> post ; } }
Returns post parameter
26,530
public function getQuery ( $ key = null , $ default = false ) { if ( $ key !== null ) { if ( array_key_exists ( $ key , $ this -> query ) ) { return $ this -> query [ $ key ] ; } else { return $ default ; } } else { return $ this -> query ; } }
Returns query parameter
26,531
private function isOutdated ( $ key , $ time ) { return ( $ this -> getTouchByKey ( $ key ) + $ this -> getKeyTtl ( $ key ) ) < $ time ; }
Check whether key is outdated
26,532
public function set ( $ key , $ value , $ ttl ) { $ this -> initializeOnDemand ( ) ; if ( ! is_string ( $ key ) ) { throw new InvalidArgumentException ( sprintf ( 'Argument #1 must be a string and only, received "%s"' , gettype ( $ key ) ) ) ; } $ time = time ( ) ; if ( $ this -> has ( $ key ) ) { $ this -> cacheMapper -> update ( $ key , $ value , $ ttl ) ; } else { $ this -> cacheMapper -> insert ( $ key , $ value , $ ttl , $ time ) ; } $ this -> cache [ $ key ] = array ( ConstProviderInterface :: CACHE_PARAM_VALUE => $ value , ConstProviderInterface :: CACHE_PARAM_CREATED_ON => $ time , ConstProviderInterface :: CACHE_PARAM_TTL => $ ttl ) ; return true ; }
Write data to the cache
26,533
public function getAll ( ) { $ this -> initializeOnDemand ( ) ; $ result = array ( ) ; foreach ( $ this -> cache as $ key => $ options ) { $ result [ $ key ] = $ options [ ConstProviderInterface :: CACHE_PARAM_VALUE ] ; } return $ result ; }
Returns cache data
26,534
public function get ( $ key , $ default = false ) { $ this -> initializeOnDemand ( ) ; if ( $ this -> has ( $ key ) ) { return $ this -> cache [ $ key ] [ ConstProviderInterface :: CACHE_PARAM_VALUE ] ; } else { return $ default ; } }
Reads cache item by its key
26,535
protected function normaliseViewport ( $ prefix , array $ valid , $ value ) { $ value = $ this -> convertToArray ( $ value ) ; foreach ( $ value as $ i => $ viewport ) { if ( ! \ in_array ( $ viewport , $ valid ) ) { throw new InvalidConfigurationException ( sprintf ( 'The "%s" %s viewport option does not exist. Known options are: "%s"' , $ viewport , $ prefix , implode ( '", "' , $ valid ) ) ) ; } $ value [ $ i ] = sprintf ( '%s-%s' , $ prefix , $ viewport ) ; } return $ value ; }
Normalises the viewport .
26,536
public function createIndex ( $ index = null ) { if ( ! $ this -> elasticsearch -> indices ( ) -> exists ( [ 'index' => $ index [ 'index' ] ] ) ) { return $ this -> elasticsearch -> indices ( ) -> create ( $ index ) ; } }
Gerar em uma migration com os templates criados .
26,537
public function phpTravisCi ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> getProjectInstance ( ) -> setupTravisCi ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Setup TravisCi configurations .
26,538
public function phpBehat ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> getProjectInstance ( ) -> setupBehat ( ) -> saveComposer ( ) -> updateComposer ( ) -> initBehat ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Setup Behat configurations and initialize .
26,539
public function phpPhpCs ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> getProjectInstance ( ) -> setupPhpCodeSniffer ( ) -> saveComposer ( ) -> updateComposer ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Setup PHPcs configurations .
26,540
public function phpComposer ( array $ composer_command , $ opts = [ 'remote-binary-path' => 'composer' , 'remote-working-dir' => '/var/www/html' , ] ) { $ instance = $ this -> getProjectInstance ( ) ; $ engine = ProjectX :: getEngineType ( ) ; $ binary = $ opts [ 'remote-binary-path' ] ; $ command_str = escapeshellcmd ( implode ( ' ' , $ composer_command ) ) ; $ working_dir = escapeshellarg ( $ opts [ 'remote-working-dir' ] ) ; $ command = $ this -> taskExec ( "{$binary} --working-dir={$working_dir} {$command_str}" ) ; if ( $ engine instanceof DockerEngineType ) { $ container = $ instance -> getPhpServiceName ( 'php' ) ; $ result = $ this -> taskDockerComposeExecute ( ) -> setContainer ( $ container ) -> exec ( $ command ) -> run ( ) ; } else { $ result = $ command -> run ( ) ; } $ this -> validateTaskResult ( $ result ) ; return $ this ; }
Php composer command .
26,541
public function phpImportDatabase ( $ opts = [ 'service' => null , 'import_path' => null , 'localhost' => false , ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ instance = $ this -> getProjectInstance ( ) ; $ service = isset ( $ opts [ 'service' ] ) ? $ opts [ 'service' ] : $ instance -> getPhpServiceName ( ) ; $ instance -> importDatabaseToService ( $ service , $ opts [ 'import_path' ] , true , $ opts [ 'localhost' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; }
Import PHP project database .
26,542
protected function getProjectInstance ( ) { $ project = ProjectX :: getProjectType ( ) ; if ( ! $ project instanceof PhpProjectType ) { throw new \ Exception ( 'These tasks can only be ran for PHP based projects.' ) ; } $ project -> setBuilder ( $ this -> getBuilder ( ) ) ; return $ project ; }
Get the project instance .
26,543
private function getPdo ( ) { static $ pdo = null ; if ( is_null ( $ pdo ) ) { $ builder = new InstanceBuilder ( ) ; $ pdo = $ builder -> build ( 'PDO' , $ this -> args ) ; } return $ pdo ; }
Lazily returns PDO instance
26,544
protected function startConversation ( \ KeythKatz \ TelegramBotCore \ Conversation $ conversation ) : void { $ conversation -> setBot ( $ this -> bot ) ; $ conversation -> setMessage ( $ this -> message ) ; $ conversation -> start ( ) ; }
Start a new Conversation .
26,545
public function sendMessageReply ( bool $ quoteOriginal = false ) : SendMessage { $ m = $ this -> bot -> sendMessage ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Create a new blank message sending back to the chat
26,546
public function sendPhotoReply ( bool $ quoteOriginal = false ) : SendPhoto { $ m = $ this -> bot -> sendPhoto ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a photo back to the chat .
26,547
public function sendAudioReply ( bool $ quoteOriginal = false ) : SendAudio { $ m = $ this -> bot -> sendAudio ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a audio file back to the chat .
26,548
public function sendDocumentReply ( bool $ quoteOriginal = false ) : SendDocument { $ m = $ this -> bot -> sendDocument ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a document back to the chat .
26,549
public function sendVideoReply ( bool $ quoteOriginal = false ) : SendVideo { $ m = $ this -> bot -> sendVideo ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a video back to the chat .
26,550
public function sendVoiceReply ( bool $ quoteOriginal = false ) : SendVoice { $ m = $ this -> bot -> sendVoice ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a voice message back to the chat .
26,551
public function sendVideoNoteReply ( bool $ quoteOriginal = false ) : SendVideoNote { $ m = $ this -> bot -> sendVideoNote ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a video note back to the chat .
26,552
public function sendMediaGroupReply ( bool $ quoteOriginal = false ) : SendMediaGroup { $ m = $ this -> bot -> sendMediaGroup ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a media group back to the chat .
26,553
public function sendLocationReply ( bool $ quoteOriginal = false ) : SendLocation { $ m = $ this -> bot -> sendLocation ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a location back to the chat .
26,554
public function editMessageLiveLocationReply ( ) : EditMessageLiveLocation { $ m = $ this -> bot -> editMessageLiveLocation ( ) ; $ this -> setReplyMarkup ( $ m , false ) ; return $ m ; }
Edit a location in the chat .
26,555
public function stopMessageLiveLocationReply ( ) : StopMessageLiveLocation { $ m = $ this -> bot -> stopMessageLiveLocation ( ) ; $ this -> setReplyMarkup ( $ m , false ) ; return $ m ; }
Stop a live location in the chat .
26,556
public function sendVenueReply ( bool $ quoteOriginal = false ) : SendVenue { $ m = $ this -> bot -> sendVenue ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a venue back to the chat .
26,557
public function sendContactReply ( bool $ quoteOriginal = false ) : SendContact { $ m = $ this -> bot -> sendContact ( ) ; $ this -> setReplyMarkup ( $ m , $ quoteOriginal ) ; return $ m ; }
Send a contact back to the chat .
26,558
public function sendChatActionReply ( ) : SendChatAction { $ m = $ this -> bot -> sendChatAction ( ) ; $ this -> setReplyMarkup ( $ m , false ) ; return $ m ; }
Send a chat action back to the chat .
26,559
protected function copyTemplateFilesToProject ( array $ filenames , $ overwrite = false ) { try { $ filesystem = $ this -> taskFilesystemStack ( ) ; foreach ( $ filenames as $ template_path => $ target_path ) { $ target_file = ProjectX :: projectRoot ( ) . "/{$target_path}" ; $ template_file = $ this -> templateManager ( ) -> getTemplateFilePath ( $ template_path ) ; $ filesystem -> copy ( $ template_file , $ target_file , $ overwrite ) ; } $ filesystem -> run ( ) ; } catch ( \ Exception $ e ) { throw new \ Exception ( sprintf ( 'Failed to copy template file(s) into project!' ) ) ; } return $ this ; }
Copy template files to project root .
26,560
public static function arrayDropdown ( array $ raw , $ partition , $ key , $ value ) { $ output = array ( ) ; foreach ( self :: arrayPartition ( $ raw , $ partition ) as $ target => $ data ) { foreach ( $ data as $ innerKey => $ innerValue ) { if ( isset ( $ innerValue [ $ key ] , $ innerValue [ $ value ] ) ) { $ output [ $ target ] [ $ innerValue [ $ key ] ] = $ innerValue [ $ value ] ; } } } return $ output ; }
Drops a raw result - set into partitions and creates inner array with key = > value pairs
26,561
public static function arrayPartition ( array $ raw , $ key , $ keepKey = true ) { $ result = array ( ) ; foreach ( $ raw as $ index => $ collection ) { if ( ! isset ( $ collection [ $ key ] ) ) { throw new LogicException ( sprintf ( 'The key "%s" does not exist in provided collection' , $ key ) ) ; } $ target = array ( $ collection [ $ key ] => $ collection ) ; foreach ( $ target as $ module => $ array ) { if ( ! isset ( $ result [ $ module ] ) ) { $ result [ $ module ] = array ( ) ; } if ( $ keepKey == false ) { unset ( $ array [ $ key ] ) ; } $ result [ $ module ] [ ] = $ array ; } } return $ result ; }
Drops an array into partitions
26,562
public static function arrayRecovery ( array $ array , array $ keys , $ value ) { foreach ( $ keys as $ key ) { if ( ! isset ( $ array [ $ key ] ) ) { $ array [ $ key ] = $ value ; } } return $ array ; }
Recoveries missing array keys
26,563
public static function valuefy ( array $ data , $ valueModue = true ) { if ( $ valueModue === true ) { $ values = array_values ( $ data ) ; } else { $ values = array_keys ( $ data ) ; } return array_combine ( $ values , $ values ) ; }
Duplicate array values into keys
26,564
public static function sumColumnsWithAverages ( array $ entities , array $ averages = array ( ) , $ precision = 2 ) { $ sum = self :: sumColumns ( $ entities ) ; if ( ! empty ( $ averages ) ) { $ count = count ( $ entities ) ; if ( $ count === 0 ) { $ count = 1 ; } foreach ( $ averages as $ average ) { if ( isset ( $ sum [ $ average ] ) ) { if ( $ precision !== false ) { } else { $ sum [ $ average ] = $ sum [ $ average ] / $ count ; } } } } return $ sum ; }
Sum columns with averages
26,565
public static function roundValues ( array $ data , $ precision = 2 ) { return self :: filterValuesRecursively ( $ data , function ( $ value ) use ( $ precision ) { $ value = is_numeric ( $ value ) ? round ( $ value , $ precision ) : $ value ; $ value = empty ( $ value ) ? 0 : $ value ; return $ value ; } ) ; }
Round array values recursively
26,566
public static function arrayColumns ( array $ data ) { $ count = count ( $ data ) ; if ( $ count === 0 ) { return false ; } if ( $ count === 1 ) { return array_keys ( $ data [ 0 ] ) ; } if ( isset ( $ data [ 0 ] ) ) { return array_keys ( $ data [ 0 ] ) ; } else { return false ; } }
Returns all column names from two dimensional array validating by count
26,567
public static function sumColumns ( array $ data ) { $ columns = self :: arrayColumns ( $ data ) ; if ( $ columns !== false ) { return self :: columnSum ( $ data , $ columns ) ; } else { return false ; } }
Counts a total sum of each collection
26,568
public static function columnSum ( array $ data , array $ columns ) { $ result = array ( ) ; foreach ( $ columns as $ column ) { foreach ( $ data as $ collection ) { if ( isset ( $ collection [ $ column ] ) ) { if ( isset ( $ result [ $ column ] ) ) { $ result [ $ column ] += $ collection [ $ column ] ; } else { $ result [ $ column ] = $ collection [ $ column ] ; } } } } return $ result ; }
Counts column sum
26,569
public static function filterValuesRecursively ( array $ array , Closure $ callback = null ) { foreach ( $ array as $ index => $ value ) { if ( is_array ( $ value ) ) { $ array [ $ index ] = call_user_func ( __METHOD__ , $ value , $ callback ) ; } else { $ array [ $ index ] = call_user_func ( $ callback , $ value ) ; } } return $ array ; }
Filter array values applying a callback function that returns a value
26,570
public static function filterArray ( array $ array , Closure $ callback ) { foreach ( $ array as $ index => $ collection ) { $ array [ $ index ] = call_user_func ( $ callback , $ collection ) ; } return $ array ; }
Filters an array applying a callback function
26,571
public static function mergeWithout ( array $ first , array $ second , array $ keys ) { $ result = array_merge ( $ first , $ second ) ; return self :: arrayWithout ( $ result , $ keys ) ; }
Merges two arrays removing keys
26,572
public static function keysExist ( array $ collection , array $ keys ) { $ collection = array_flip ( $ collection ) ; foreach ( $ keys as $ key ) { if ( ! in_array ( $ key , $ collection ) ) { return false ; } } return true ; }
Determines whether all keys exist in a collection
26,573
public static function arrayOnlyWith ( array $ array , array $ keys ) { $ result = array ( ) ; if ( ! self :: isSequential ( $ array ) ) { foreach ( $ array as $ key => $ value ) { if ( in_array ( $ key , $ keys ) ) { $ result [ $ key ] = $ value ; } } } else { foreach ( $ array as $ value ) { if ( in_array ( $ value , $ keys ) ) { $ result [ ] = $ value ; } } } return $ result ; }
Filters an array by matching keys only
26,574
public static function arrayCombine ( array $ first , array $ second , $ replacement = null , $ order = true ) { if ( count ( $ first ) !== count ( $ second ) ) { $ input = array ( $ first , $ second ) ; $ count = array_map ( 'count' , $ input ) ; $ min = array_keys ( $ count , max ( $ count ) ) ; $ max = array_keys ( $ count , min ( $ count ) ) ; $ min = $ min [ 0 ] ; $ max = $ max [ 0 ] ; $ largest = $ input [ $ min ] ; $ smallest = $ input [ $ max ] ; foreach ( $ largest as $ key => $ value ) { if ( ! isset ( $ smallest [ $ key ] ) ) { $ smallest [ $ key ] = $ replacement ; } } $ first = $ smallest ; $ second = $ largest ; } if ( $ order === true ) { return array_combine ( $ second , $ first ) ; } else { return array_combine ( $ first , $ second ) ; } }
Combines two arrays even with different length
26,575
public static function arrayList ( array $ array , $ key , $ value ) { $ result = array ( ) ; foreach ( $ array as $ row ) { if ( array_key_exists ( $ key , $ row ) && array_key_exists ( $ value , $ row ) ) { $ name = & $ row [ $ key ] ; $ text = & $ row [ $ value ] ; $ result [ $ name ] = $ text ; } else { trigger_error ( sprintf ( 'Nested arrays must contain both %s and %s' , $ key , $ value ) ) ; } } return $ result ; }
Turns array s row into a list
26,576
public static function arrayWithout ( array $ array , array $ keys ) { $ filter = function ( array $ array , array $ keys ) { foreach ( $ keys as $ key ) { if ( array_key_exists ( $ key , $ array ) ) { unset ( $ array [ $ key ] ) ; } } return $ array ; } ; if ( self :: hasAllArrayValues ( $ array ) ) { return self :: filterArray ( $ array , function ( $ collection ) use ( $ keys , $ filter ) { return $ filter ( $ collection , $ keys ) ; } ) ; } else { return $ filter ( $ array , $ keys ) ; } }
Returns a copy of an array without keys . Handles two dimensional arrays as well
26,577
public static function search ( array $ haystack , $ needle ) { foreach ( $ haystack as $ key => $ value ) { if ( is_array ( $ value ) ) { $ target = self :: search ( $ value , $ needle ) ; } else { $ target = '' ; } if ( $ needle === $ value || ( $ target != false && $ target != null ) ) { if ( $ target == null ) { return array ( $ key ) ; } return array_merge ( array ( $ key ) , $ target ) ; } } return false ; }
Search data by given value inside array recursively
26,578
public static function arrayUnique ( array $ array ) { foreach ( $ array as & $ value ) { $ value = serialize ( $ value ) ; } $ array = array_unique ( $ array ) ; foreach ( $ array as & $ value ) { $ value = unserialize ( $ value ) ; } return $ array ; }
Array unique for multi - dimensional arrays
26,579
public function orderBy ( string $ field , int $ direction = self :: ASCENDING ) : DocumentSelector { return $ this -> sortBy ( $ this -> sortBy + [ $ field => $ direction ] ) ; }
Alias for sortBy .
26,580
public function findOne ( array $ query = [ ] , bool $ normalizeDates = true ) { if ( $ normalizeDates ) { $ query = $ this -> normalizeDates ( $ query ) ; } $ result = $ this -> collection -> findOne ( array_merge ( $ this -> query , $ query ) , $ this -> createOptions ( ) ) ; if ( empty ( $ result ) ) { return null ; } return $ this -> odm -> make ( $ this -> class , $ result , false ) ; }
Select one document or it s fields from collection .
26,581
public function count ( array $ query = [ ] ) : int { return $ this -> collection -> count ( array_merge ( $ this -> query , $ query ) , [ 'skip' => $ this -> offset , 'limit' => $ this -> limit ] ) ; }
Count collection . Attention this method depends on current values set for limit and offset!
26,582
protected function normalizeDates ( array $ query ) : array { array_walk_recursive ( $ query , function ( & $ value ) { if ( $ value instanceof \ DateTime ) { $ value = new UTCDateTime ( $ value ) ; } } ) ; return $ query ; }
Converts DateTime objects into MongoDatetime .
26,583
public function cache_set ( $ cid , $ data , $ bin = 'cache' , $ expire = CACHE_PERMANENT ) { return cache_set ( $ cid , $ data , $ bin , $ expire ) ; }
Stores data in the persistent cache .
26,584
public function getService ( ) { if ( ! isset ( $ this -> service ) ) { $ info = $ this -> getInfo ( ) ; $ this -> service = $ this -> service ( ) ; foreach ( static :: PROPERTIES_OVERRIDE as $ property ) { if ( ! isset ( $ info [ $ property ] ) || empty ( $ info [ $ property ] ) ) { continue ; } $ method = 'set' . ucwords ( $ property ) ; if ( is_callable ( [ $ this -> service , $ method ] ) ) { call_user_func_array ( [ $ this -> service , $ method ] , [ $ info [ $ property ] ] ) ; } } } return $ this -> service ; }
Get complete service object .
26,585
public function getEnvironmentValue ( $ name ) { $ name = strtolower ( $ name ) ; $ service = $ this -> getService ( ) ; foreach ( $ service -> getEnvironment ( ) as $ environment ) { list ( $ key , $ value ) = explode ( '=' , $ environment ) ; if ( strtolower ( $ key ) !== $ name ) { continue ; } return $ value ; } return null ; }
Get environment value .
26,586
public function getHostPorts ( ) { $ ports = [ ] ; $ service = $ this -> getService ( ) ; foreach ( $ service -> getPorts ( ) as $ port ) { list ( $ host , ) = explode ( ':' , $ port ) ; $ ports [ ] = $ host ; } return $ ports ; }
Get Docker host ports .
26,587
protected function getPorts ( $ host = null ) { $ ports = $ this -> ports ( ) ; array_walk ( $ ports , function ( & $ port ) use ( $ host ) { $ host = isset ( $ host ) ? $ host : $ port ; $ port = "{$host}:{$port}" ; } ) ; return $ ports ; }
Get Docker formatted service ports .
26,588
protected function getServiceNames ( ) { $ names = [ ] ; foreach ( $ this -> getServices ( ) as $ name => $ info ) { if ( ! isset ( $ info [ 'type' ] ) ) { continue ; } $ names [ $ name ] = $ info [ 'type' ] ; } return $ names ; }
Get all defined docker service names .
26,589
protected function alterService ( DockerService $ service ) { if ( $ this -> internal ) { $ service -> setNetworks ( [ 'internal' ] ) -> setlabels ( [ 'traefik.enable=false' ] ) ; if ( $ this -> bindPorts ) { $ service -> setPorts ( $ this -> getPorts ( '0000' ) ) ; } } else { $ service -> setPorts ( $ this -> getPorts ( ) ) ; } return $ service ; }
Default alternations to the service object .
26,590
protected function formatRunCommand ( array $ commands ) { $ last = end ( $ commands ) ; return 'RUN ' . implode ( "\r\n && " , array_map ( function ( $ value ) use ( $ last ) { return $ last !== $ value ? "{$value} \\" : $ value ; } , $ commands ) ) ; }
Format command into a docker run statement .
26,591
protected function mergeConfigVariable ( $ name , array $ values ) { if ( in_array ( $ name , static :: DOCKER_VARIABLES ) ) { $ this -> configs [ $ name ] = array_unique ( array_merge ( $ this -> configs [ $ name ] , $ values ) ) ; } return $ this ; }
Merge configuration variables .
26,592
protected function launchNextTask ( ) { if ( ! $ this -> numberOfThreadsToLaunch ) { return false ; } $ taskInfos = $ this -> pool [ $ this -> numberOfTasks - $ this -> numberOfThreadsToLaunch ] ; $ taskInfos [ 'task' ] -> fork ( ) ; $ this -> numberOfRunningThreads ++ ; $ this -> numberOfThreadsToLaunch -- ; return true ; }
Fork next task
26,593
public function match ( $ segment , array $ map ) { foreach ( $ map as $ index => $ uriTemplate ) { $ matches = array ( ) ; if ( preg_match ( $ this -> createRegEx ( $ uriTemplate ) , $ segment , $ matches ) === 1 ) { $ matchedURI = array_shift ( $ matches ) ; $ routeMatch = new RouteMatch ( ) ; $ routeMatch -> setMatchedUri ( $ matchedURI ) -> setMatchedUriTemplate ( $ uriTemplate ) -> setVariables ( $ matches ) ; return $ routeMatch ; } } return false ; }
Matches a URI string against a route map
26,594
private function createRegEx ( $ uriTemplate ) { $ pattern = str_replace ( $ this -> getPlaceholders ( ) , $ this -> getPatterns ( ) , $ uriTemplate ) ; $ pattern .= '(\?(.*))?' ; return '~^' . $ pattern . '$~i' ; }
Creates a regular expression according to URI template
26,595
public function fetchAll ( ) { $ query = sprintf ( 'SELECT * FROM `%s`' , $ this -> table ) ; $ result = array ( ) ; foreach ( $ this -> pdo -> query ( $ query ) as $ key => $ value ) { $ result [ $ key ] = $ value ; } return $ this -> parse ( $ result ) ; }
Fetches cache data
26,596
private function alter ( $ key , $ operator , $ step ) { $ query = sprintf ( 'UPDATE `%s` SET `value` = value %s %s WHERE `key` = :key' , $ this -> table , $ operator , $ step ) ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; return $ stmt -> execute ( array ( ':key' => $ key ) ) ; }
Alters a column
26,597
public function insert ( $ key , $ value , $ ttl , $ time ) { if ( $ this -> serializer -> isSerializeable ( $ value ) ) { $ value = $ this -> serializer -> serialize ( $ value ) ; } $ query = sprintf ( 'INSERT INTO `%s` (`key`, `value`, `ttl`, `created_on`) VALUES (:key, :value, :ttl, :created_on)' , $ this -> table ) ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; return $ stmt -> execute ( array ( ':' . ConstProviderInterface :: CACHE_PARAM_KEY => $ key , ':' . ConstProviderInterface :: CACHE_PARAM_VALUE => $ value , ':' . ConstProviderInterface :: CACHE_PARAM_TTL => $ ttl , ':' . ConstProviderInterface :: CACHE_PARAM_CREATED_ON => time ( ) , ) ) ; }
Inserts new cache s record
26,598
private function parse ( array $ data ) { $ result = array ( ) ; foreach ( $ data as $ index => $ array ) { if ( $ this -> serializer -> isSerialized ( $ array [ ConstProviderInterface :: CACHE_PARAM_VALUE ] ) ) { $ array [ ConstProviderInterface :: CACHE_PARAM_VALUE ] = $ this -> serializer -> unserialize ( $ array [ ConstProviderInterface :: CACHE_PARAM_VALUE ] ) ; } $ result [ $ array [ ConstProviderInterface :: CACHE_PARAM_KEY ] ] = array ( ConstProviderInterface :: CACHE_PARAM_VALUE => $ array [ ConstProviderInterface :: CACHE_PARAM_VALUE ] , ConstProviderInterface :: CACHE_PARAM_TTL => $ array [ ConstProviderInterface :: CACHE_PARAM_TTL ] , ConstProviderInterface :: CACHE_PARAM_CREATED_ON => $ array [ ConstProviderInterface :: CACHE_PARAM_CREATED_ON ] ) ; } return $ result ; }
Parses result from a table
26,599
private function insertNewFileFunctions ( iterable $ new ) : void { if ( 0 === \ count ( $ new ) ) { return ; } $ table = $ this -> getTable ( ) ; $ db = $ this -> getDb ( ) ; foreach ( $ new as $ file_function => $ data ) { $ query = $ db -> prepare ( "INSERT INTO $table (function, added_at, changed_at) VALUES (:file_function, NOW(), :changed_at)" ) ; $ changed_at = $ data -> getChangedAt ( ) ; $ query -> bindParam ( ":file_function" , $ file_function ) ; $ query -> bindParam ( ":changed_at" , $ changed_at ) ; $ query -> execute ( ) ; } }
Constructs the SQL query and executes it .