idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
7,000
|
final public function argument ( $ key ) { $ result = null ; foreach ( $ this -> shellArguments as $ shellArgument ) { if ( $ shellArgument [ 'key' ] === $ key ) { $ result = $ shellArgument ; break ; } } return $ result ; }
|
Get a specific argument .
|
7,001
|
final protected function updateArgument ( $ key , $ value ) { foreach ( $ this -> shellArguments as & $ shellArgument ) { if ( $ shellArgument [ 'key' ] === $ key ) { $ shellArgument [ 'value' ] = $ value ; break ; } } unset ( $ shellArgument ) ; return $ this ; }
|
Update the specific argument .
|
7,002
|
final protected function updateOption ( $ flag , $ enabled , $ value = null , $ remove = false ) { $ shellOption = $ this -> option ( $ flag ) ; $ shellOption -> enable ( $ enabled ) ; if ( $ shellOption -> canHaveValue ( ) ) { $ this -> updateOptionValue ( $ shellOption , $ value , $ remove ) ; } return $ this ; }
|
Update an option .
|
7,003
|
private function setShellCommand ( $ command ) { if ( ! isset ( $ command ) ) { throw new InvalidArgumentException ( 'Must define a command.' ) ; } if ( isset ( $ this -> shellCommand ) && $ this -> shellCommand !== $ command ) { throw new LogicException ( 'Cannot redefine command once set!' ) ; } $ this -> shellCommand = $ command ; return $ this ; }
|
Set the command to execute .
|
7,004
|
private function defineArgument ( $ key ) { $ shellArgumentFound = false ; foreach ( $ this -> shellArguments as $ shellArgument ) { if ( $ shellArgument [ 'key' ] === $ key ) { $ shellArgumentFound = true ; } } if ( ! $ shellArgumentFound ) { array_push ( $ this -> shellArguments , [ 'key' => $ key , 'value' => '' ] ) ; } return $ this ; }
|
Set an argument for the command .
|
7,005
|
private function updateOptionValue ( ShellOption $ shellOption , $ value = null , $ remove = false ) { if ( $ remove ) { $ shellOption -> removeValue ( $ value ) ; } else { $ shellOption -> addValue ( $ value ) ; } }
|
Update the value for an option .
|
7,006
|
private function compile ( ) { $ shellOptions = [ ] ; foreach ( $ this -> shellOptions as $ shellOption ) { $ shellOptions = array_merge ( $ shellOptions , $ shellOption -> getArray ( ) ) ; } $ shellArguments = [ ] ; foreach ( $ this -> shellArguments as $ shellArgument ) { $ shellArguments [ ] = $ shellArgument [ 'value' ] ; } $ command = array_merge ( [ $ this -> shellCommand ] , $ shellOptions , $ shellArguments ) ; $ builder = new Process ( $ command ) ; $ builder -> setTimeout ( $ this -> getCommandTimeout ( ) ) ; $ this -> builder = $ builder ; return $ this -> builder ; }
|
Compile the parts of the command .
|
7,007
|
public function nlToP ( $ string ) { $ string = trim ( $ string ) ; $ string = Modifiers :: linebreaks ( $ string ) ; $ string = str_replace ( "\n" , "</p>\n<p>" , $ string ) ; $ string = str_replace ( '<p></p>' , '' , $ string ) ; return '<p>' . $ string . '</p>' . PHP_EOL ; }
|
Converts text line breaks into HTML paragraphs .
|
7,008
|
public function nlToPbr ( $ string ) { $ string = trim ( $ string ) ; $ string = Modifiers :: linebreaks ( $ string ) ; $ string = str_replace ( "\n" , '<br />' , $ string ) ; $ string = str_replace ( '<br /><br />' , "</p>\n<p>" , $ string ) ; $ string = str_replace ( '<p></p>' , '' , $ string ) ; return '<p>' . $ string . '</p>' . PHP_EOL ; }
|
Converts text line breaks into HTML paragraphs and HTML line breaks .
|
7,009
|
public static function emailEncode ( $ sEmail ) { $ sEmail = bin2hex ( $ sEmail ) ; $ sEmail = chunk_split ( $ sEmail , 2 , '%' ) ; $ sEmail = '%' . substr ( $ sEmail , 0 , strlen ( $ sEmail ) - 1 ) ; return $ sEmail ; }
|
Encode an email address for HTML .
|
7,010
|
protected function findClass ( $ method ) { if ( ! preg_match ( "/^add([a-zA-Z]+)/" , $ method , $ matches ) ) { return false ; } $ className = "\\HtmlForm\\Elements\\{$matches[1]}" ; if ( ! class_exists ( $ className ) ) { return false ; } return $ className ; }
|
Based on a passed method name figure out if there is a cooresponding HtmlForm element .
|
7,011
|
public function setDataSource ( DataSourceInterface $ dataSource ) { $ this -> dataSource = $ dataSource ; $ this -> dataSource -> initialize ( $ this ) ; }
|
Set Table data source
|
7,012
|
public function addColumn ( Column $ column ) { $ this -> columns [ ] = $ column ; if ( $ column instanceof ColumnInterface ) { $ column -> initialize ( $ this ) ; } return $ this ; }
|
Add column to table
|
7,013
|
public function setAjax ( $ ajax ) { if ( is_string ( $ ajax ) ) { $ pattern = '/^(\s+)*(function)(\s+)*\(/i' ; if ( preg_match ( $ pattern , $ ajax , $ matches ) && strtolower ( $ matches [ 2 ] ) == 'function' ) { $ hash = sha1 ( $ ajax ) ; $ this -> properties [ 'ajax' ] = $ hash ; $ this -> callbacks [ $ hash ] = $ ajax ; return $ this ; } $ this -> properties [ 'ajax' ] = $ ajax ; return $ this ; } else { $ this -> properties [ 'ajax' ] = $ ajax ; return $ this ; } }
|
DataTables can obtain the data it is to display in the table table s body from a number of sources including from an Ajax data source using this initialisation parameter . As with other dynamic data sources arrays or objects can be used for the data source for each row with columns . dataDT employed to read from specific object properties .
|
7,014
|
public static function send ( $ rq ) { if ( self :: $ _curlHandler ) { if ( function_exists ( 'curl_reset' ) ) { curl_reset ( self :: $ _curlHandler ) ; } else { my_curl_reset ( self :: $ _curlHandler ) ; } } else { self :: $ _curlHandler = curl_init ( ) ; } curl_setopt ( self :: $ _curlHandler , CURLOPT_URL , $ rq [ 'url' ] ) ; switch ( true ) { case isset ( $ rq [ 'method' ] ) && in_array ( strtolower ( $ rq [ 'method' ] ) , [ 'get' , 'post' , 'put' , 'delete' , 'head' ] ) : $ method = strtoupper ( $ rq [ 'method' ] ) ; break ; case isset ( $ rq [ 'data' ] ) : $ method = 'POST' ; break ; default : $ method = 'GET' ; } $ header = isset ( $ rq [ 'header' ] ) ? $ rq [ 'header' ] : [ ] ; $ header [ ] = 'Method:' . $ method ; $ header [ ] = 'User-Agent:' . Conf :: getUA ( ) ; $ header [ ] = 'Connection: keep-alive' ; if ( 'POST' == $ method ) { $ header [ ] = 'Expect: ' ; } isset ( $ rq [ 'host' ] ) && $ header [ ] = 'Host:' . $ rq [ 'host' ] ; curl_setopt ( self :: $ _curlHandler , CURLOPT_HTTPHEADER , $ header ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_CUSTOMREQUEST , $ method ) ; isset ( $ rq [ 'timeout' ] ) && curl_setopt ( self :: $ _curlHandler , CURLOPT_TIMEOUT , $ rq [ 'timeout' ] ) ; isset ( $ rq [ 'data' ] ) && in_array ( $ method , [ 'POST' , 'PUT' ] ) && curl_setopt ( self :: $ _curlHandler , CURLOPT_POSTFIELDS , $ rq [ 'data' ] ) ; $ ssl = substr ( $ rq [ 'url' ] , 0 , 8 ) == 'https://' ? true : false ; if ( isset ( $ rq [ 'cert' ] ) ) { curl_setopt ( self :: $ _curlHandler , CURLOPT_SSL_VERIFYPEER , true ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_CAINFO , $ rq [ 'cert' ] ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_SSL_VERIFYHOST , 2 ) ; self :: setCurlSSLVersion ( $ rq ) ; } elseif ( $ ssl ) { curl_setopt ( self :: $ _curlHandler , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( self :: $ _curlHandler , CURLOPT_SSL_VERIFYHOST , 0 ) ; self :: setCurlSSLVersion ( $ rq ) ; } $ ret = curl_exec ( self :: $ _curlHandler ) ; self :: $ _httpInfo = curl_getinfo ( self :: $ _curlHandler ) ; return $ ret ; }
|
send http request .
|
7,015
|
public function updateForm ( ) { if ( $ userDefinedForm = $ this -> owner -> getController ( ) -> data ( ) ) { if ( $ userDefinedForm -> EnableSpamGuard ) { $ this -> owner -> enableSpamProtection ( ) ; } } }
|
Updates the extended user form instance .
|
7,016
|
public static function getReasonMessage ( int $ code ) : string { $ code = static :: filterStatusCode ( $ code ) ; if ( ! isset ( self :: $ errorPhrases [ $ code ] ) ) { throw new OutOfBoundsException ( \ sprintf ( 'Unknown http status code: `%s`.' , $ code ) ) ; } return self :: $ errorPhrases [ $ code ] ; }
|
Get the message for a given status code .
|
7,017
|
public static function getReasonPhrase ( int $ code ) : string { $ code = static :: filterStatusCode ( $ code ) ; if ( ! isset ( self :: $ statusNames [ $ code ] ) ) { throw new OutOfBoundsException ( \ sprintf ( 'Unknown http status code: `%s`.' , $ code ) ) ; } return self :: $ statusNames [ $ code ] ; }
|
Get the name for a given status code .
|
7,018
|
public function getLogCollection ( $ now , $ then ) { if ( ! file_exists ( $ this -> fileName ) ) { throw new Exception ( "Access log file is not present - no traffic to report." , 1 ) ; } $ collection = [ ] ; $ lines = file ( $ this -> fileName , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ) ; foreach ( $ lines as $ line ) { $ collection [ ] = $ this -> parser -> parse ( $ line ) ; } $ logs = collect ( $ collection ) ; return $ logs -> where ( 'stamp' , '<=' , $ now ) -> where ( 'stamp' , '>=' , $ then ) ; }
|
Get the log collection based on time
|
7,019
|
public function processLogStats ( $ collection ) { $ validLogs = $ collection -> filter ( function ( $ line ) { return $ this -> validateLine ( $ line ) ; } ) ; $ sentBytes = $ validLogs -> pluck ( 'sentBytes' ) ; $ stats = [ 'hits' => $ validLogs -> count ( ) , 'total_data_sent' => $ sentBytes -> sum ( ) , 'most_common_method' => $ this -> sortByField ( 'requestMethod' , $ validLogs ) , 'most_common_url' => $ this -> sortByField ( 'URL' , $ validLogs ) , 'most_common_user_agent' => $ this -> sortByField ( 'HeaderUserAgent' , $ validLogs ) , ] ; return $ stats ; }
|
Process the log stats
|
7,020
|
public function sortByField ( $ field , $ collection ) { if ( $ collection -> isEmpty ( ) ) { return 'N/A' ; } return $ collection -> groupBy ( $ field ) -> sortByDesc ( function ( $ logs ) { return count ( $ logs ) ; } ) -> first ( ) -> pluck ( $ field ) -> first ( ) ; }
|
Sort data by field
|
7,021
|
public function validateLine ( $ line ) { $ invalidExtensions = [ '.jpg' , '.js' , '.css' , '.sass' , '.scss' , '.png' , '.svg' , '.ico' , '.jpeg' , '.gif' , '.mp4' , ] ; foreach ( $ invalidExtensions as $ needle ) { if ( stristr ( $ line -> URL , $ needle ) ) { return false ; } } if ( $ line -> HeaderUserAgent === 'MissionControlAgent' ) { return false ; } return true ; }
|
Line object from logs
|
7,022
|
public static function send_status ( $ code ) { if ( ! isset ( static :: $ status_messages [ $ code ] ) ) { $ code = self :: STATUS_INTERNAL_SERVER_ERROR ; } http_response_code ( $ code ) ; }
|
send a status code to the browser
|
7,023
|
public static function get_status_message ( $ code ) { if ( ! isset ( static :: $ status_messages [ $ code ] ) ) { $ code = self :: STATUS_INTERNAL_SERVER_ERROR ; } $ message = static :: $ status_messages [ $ code ] ; return $ message ; }
|
get the describing message of the status code
|
7,024
|
public static function download ( $ output , $ content_type = 'text/plain' , $ filename = null ) { $ filename_postfix = ( $ filename ) ? '; filename="' . $ filename . '"' : '' ; header ( 'Content-Type: ' . $ content_type . '; charset=utf-8' ) ; header ( 'Content-Disposition: attachment' . $ filename_postfix ) ; echo $ output ; }
|
force the user to download certain output
|
7,025
|
public function enableSpamProtection ( $ args = [ ] ) { if ( $ guard = $ this -> getSpamGuardInstance ( $ args ) ) { $ name = isset ( $ args [ 'name' ] ) ? $ args [ 'name' ] : $ guard -> getDefaultName ( ) ; $ title = isset ( $ args [ 'title' ] ) ? $ args [ 'title' ] : $ guard -> getDefaultTitle ( ) ; if ( $ field = $ guard -> getFormField ( $ name , $ title ) ) { $ field -> setForm ( $ this -> owner ) ; if ( isset ( $ args [ 'insertBefore' ] ) ) { $ this -> owner -> Fields ( ) -> insertBefore ( $ field , $ args [ 'insertBefore' ] ) ; } elseif ( isset ( $ args [ 'insertAfter' ] ) ) { $ this -> owner -> Fields ( ) -> insertAfter ( $ field , $ args [ 'insertAfter' ] ) ; } else { $ this -> owner -> Fields ( ) -> push ( $ field ) ; } } } return $ this -> owner ; }
|
Enables spam guard protection for the extended form .
|
7,026
|
public function fields ( $ fields ) { if ( ! is_array ( $ fields ) && ! is_null ( $ fields ) ) { $ fields = array ( $ fields ) ; } if ( empty ( $ fields ) || $ fields == array ( '*' ) ) { $ this -> fields = array ( ) ; return $ this ; } $ this -> fields = $ fields ; return $ this ; }
|
Set the select fields
|
7,027
|
public function add_fields ( $ fields ) { if ( ! is_array ( $ fields ) ) { $ fields = array ( $ fields ) ; } $ this -> fields = array_merge ( $ this -> fields , $ fields ) ; return $ this ; }
|
Add select fields
|
7,028
|
public function order_by ( $ cols , $ order = 'asc' ) { if ( ! is_array ( $ cols ) ) { $ this -> orders [ ] = array ( $ cols , $ order ) ; return $ this ; } else { foreach ( $ cols as $ key => $ col ) { if ( is_numeric ( $ key ) ) { $ this -> orders [ ] = array ( $ col , $ order ) ; } else { $ this -> orders [ ] = array ( $ key , $ col ) ; } } } return $ this ; }
|
Set the order parameters
|
7,029
|
public function group_by ( $ key ) { if ( ! is_array ( $ key ) ) { $ key = array ( $ key ) ; } foreach ( $ key as $ group_key ) { $ this -> groups [ ] = $ group_key ; } return $ this ; }
|
Add group by stuff
|
7,030
|
public function column ( $ column , $ name = null ) { return $ this -> fields ( $ column ) -> one ( $ name ) -> $ column ; }
|
Just get a single value from the db
|
7,031
|
public function login ( $ user , $ pass , $ maxtimeout = 10 ) { try { $ this -> expect ( '((U|u)ser|(L|l)ogin)((N|n)ame|)(:|)' , $ user ) ; $ this -> expect ( '(P|p)ass((W|w)ord|)(:|)' , $ pass ) ; } catch ( TelnetException $ e ) { throw new TelnetException ( 'Could not find password request. Login failed.' ) ; } $ timestart = time ( ) ; $ buff = '' ; while ( true ) { $ buff = $ this -> recvLine ( ) ; $ timerun = time ( ) - $ timestart ; if ( preg_match ( "/(fail|wrong|incorrect|failed)/i" , $ buff ) ) { throw new TelnetException ( "Username or password wrong! Login failed" ) ; } if ( preg_match ( "/(#|>|\$)/" , $ buff ) ) { break ; } if ( $ timerun >= $ maxtimeout ) { throw new TelnetException ( "Could not get reply from device. Login failed." ) ; } } $ this -> recvAll ( ) ; $ lines = explode ( "\n" , $ this -> getBuffer ( ) ) ; $ prompt = array_slice ( $ lines , - 1 ) ; $ this -> prompt = $ prompt [ 0 ] ; return $ this ; }
|
Login to device .
|
7,032
|
public function send ( $ data , $ newline = true ) { if ( ! $ this -> _sock ) { throw new SocketClientException ( "Connection unexpectedly closed!" ) ; } if ( $ newline ) { $ data = $ data . $ this -> retcarriage ; } if ( ! $ wr = fwrite ( $ this -> _sock , $ data ) ) { throw new SocketClientException ( 'Error while sending data!' ) ; } return $ wr ; }
|
Send data to socket
|
7,033
|
public function recvChr ( ) { if ( ! $ this -> _sock ) { throw new SocketClientException ( "Connection gone!" ) ; } $ char = fgetc ( $ this -> _sock ) ; if ( $ this -> stream_eof ( ) ) { return false ; } if ( $ char === TEL_IAC && $ this -> negotiation_enabled ) { $ this -> _negotiate ( fgetc ( $ this -> _sock ) ) ; return "" ; } $ this -> _buff .= $ char ; return $ char ; }
|
Get char from socket or call negotiation method if found telnet negotiaton command .
|
7,034
|
public function recvLine ( $ delimiter = "\n" ) { $ str = '' ; while ( ! $ this -> stream_eof ( ) ) { $ char = $ this -> recvChr ( ) ; $ str .= $ char ; if ( $ char === false ) { return $ str ; } if ( strpos ( $ str , $ delimiter ) !== false ) { return $ str ; } } return $ str ; }
|
Receive line from connection
|
7,035
|
public function findAll ( $ str ) { $ this -> recvAll ( ) ; $ output_as_array = explode ( $ this -> retcarriage , $ this -> getBuffer ( ) ) ; foreach ( $ output_as_array as $ line ) { if ( preg_match ( "/{$str}/" , $ line , $ matches ) ) { return $ matches [ 0 ] ; } } return false ; }
|
Receive all data and search through global buffer
|
7,036
|
public function expect ( $ str , $ cmd , $ newline = true , $ maxtimeout = 10 ) { if ( $ this -> waitFor ( $ str , $ maxtimeout ) ) { $ this -> send ( $ cmd , $ newline ) ; return true ; } }
|
Search for given occurance and send given command if found
|
7,037
|
public function getMetaData ( $ param ) { if ( ! $ this -> _sock ) { throw new SocketClientException ( "Connection gone!" ) ; } $ info = stream_get_meta_data ( $ this -> _sock ) ; return $ info [ $ param ] ; }
|
Return stream meta data parameter
|
7,038
|
private function _negotiateDo ( $ cmd ) { switch ( $ cmd ) { case TEL_TTYPE : $ term = ( binary ) $ this -> terminal_type ; return $ this -> send ( TEL_IAC . TEL_SUB . TEL_TTYPE . TEL_BIN . $ term . TEL_IAC . TEL_SUBEND , false ) ; case TEL_XDISPLOC : $ hostname = ( binary ) php_uname ( 'n' ) . ':0.0' ; return $ this -> send ( TEL_IAC . TEL_SUB . TEL_XDISPLOC . TEL_BIN . $ hostname . TEL_IAC . TEL_SUBEND , false ) ; case TEL_NEWENV : $ env = ( binary ) 'DISPLAY ' . php_uname ( 'n' ) . ':0.0' ; return $ this -> send ( TEL_IAC . TEL_SUB . TEL_NEWENV . TEL_BIN . $ env . TEL_IAC . TEL_SUBEND , false ) ; case TEL_TSPEED : $ tspeed = ( binary ) $ this -> terminal_speed_in . ',' . $ this -> terminal_speed_out ; return $ this -> send ( TEL_IAC . TEL_SUB . TEL_TSPEED . TEL_BIN . $ tspeed . TEL_IAC . TEL_SUBEND , false ) ; case TEL_NAWS : $ null = chr ( 0 ) ; $ height = chr ( $ this -> window_size_height ) ; $ width = chr ( $ this -> window_size_width ) ; return $ this -> send ( TEL_IAC . TEL_SUB . TEL_NAWS . $ null . $ width . $ null . $ height . TEL_IAC . TEL_SUBEND , false ) ; case TEL_GA : break ; case TEL_ECHO : return $ this -> send ( TEL_IAC . TEL_WONT . TEL_ECHO , false ) ; default : return $ this -> send ( TEL_IAC . TEL_DONT . $ cmd , false ) ; } }
|
Telnet DO negotiaion
|
7,039
|
private function _negotiateWill ( $ cmd ) { switch ( $ cmd ) { case TEL_GA : break ; case TEL_ECHO : break ; default : return $ this -> send ( TEL_IAC . TEL_WONT . $ cmd , false ) ; } }
|
Telnet WILL negotiaion
|
7,040
|
public function waitReply ( $ timeout = 10 ) { $ timestart = time ( ) ; while ( true ) { $ char = $ this -> recvChr ( ) ; $ timerun = time ( ) - $ timestart ; if ( $ timerun >= $ timeout ) { return false ; } if ( ! empty ( $ char ) ) { return true ; } } return false ; }
|
Wait for reply from socket
|
7,041
|
public function waitFor ( $ str , $ maxtimeout = 10 ) { $ timestart = time ( ) ; $ buff = '' ; while ( true ) { $ buff .= $ this -> recvChr ( ) ; $ timerun = time ( ) - $ timestart ; if ( preg_match ( "/$str/" , $ buff , $ matches ) ) { return true ; } if ( $ timerun >= $ maxtimeout ) { throw new TelnetException ( "Could not find occurance [ $str ] within timeout" ) ; } } return false ; }
|
Wait for specified message from socket till timeout
|
7,042
|
public function getOutputOf ( $ cmd , $ newline = true , $ maxtimeout = 10 ) { $ return = array ( ) ; $ this -> recvAll ( ) ; $ this -> send ( $ cmd , $ newline ) ; $ timestart = time ( ) ; while ( true ) { $ buff = $ this -> recvLine ( ) ; $ timerun = time ( ) - $ timestart ; if ( strpos ( $ buff , $ this -> prompt ) !== false ) { break ; } if ( preg_match ( "/$this->page_delimiter/i" , $ buff ) ) { $ this -> send ( " " , false ) ; $ timestart = time ( ) ; continue ; } if ( $ timerun >= $ maxtimeout ) { throw new TelnetException ( "Timeout reached while waiting to execute command: [ $cmd ]" ) ; } $ return [ ] = $ buff ; } $ newret = array_slice ( $ return , 1 , - 1 ) ; $ newret = implode ( "\r" , $ newret ) ; return $ newret ; }
|
Get only output of running command
|
7,043
|
public function setTermSpeed ( $ in , $ out ) { $ this -> terminal_speed_in = $ in ; $ this -> terminal_speed_out = $ out ; return $ this ; }
|
Setting terminal speed
|
7,044
|
public function setWindowSize ( $ height , $ width ) { if ( ! is_int ( $ height ) || ! is_int ( $ width ) ) { throw new TelnetException ( "Wrong windows height or width used. Should valid integer." ) ; } if ( $ height < 1 || $ width < 1 || $ height === 255 || $ width === 255 ) { throw new TelnetException ( "Window size can't be negative or 255" ) ; } $ this -> winsize_height = $ height ; $ this -> winsize_widht = $ width ; return $ this ; }
|
Window size used while negotiating
|
7,045
|
public function setLiveInfoPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> liveInfoProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the live info position
|
7,046
|
public function setSpectatorInfoPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> spectatorInfoProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the spectator info position
|
7,047
|
public function setCheckpointListPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> checkpointListProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the checkpoint list position
|
7,048
|
public function setRoundScoresPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> roundScoresProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the round scores position
|
7,049
|
public function setChronoPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> chronoProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the chrono position
|
7,050
|
public function setSpeedAndDistancePosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> speedAndDistanceProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the speed and distance position
|
7,051
|
public function setPersonalBestAndRankPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> personalBestAndRankProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the personal best and rank position
|
7,052
|
public function setPositionPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> positionProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the position position
|
7,053
|
public function setCheckpointTimePosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> checkpointTimeProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the checkpoint time position
|
7,054
|
public function setWarmUpPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> warmUpProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the warm - up position
|
7,055
|
public function setMultiLapInfoPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> multiLapInfoProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the multi - lap info position
|
7,056
|
public function setCheckpointRankingPosition ( $ positionX , $ positionY , $ positionZ = null ) { $ this -> setPositionProperty ( $ this -> checkpointRankingProperties , $ positionX , $ positionY , $ positionZ ) ; return $ this ; }
|
Set the checkpoint ranking position
|
7,057
|
public function invoke ( $ queueName , $ payload , $ resultType , $ timeout = 10 ) { $ rs = $ this -> invokeAll ( array ( array ( $ queueName , $ payload , $ resultType ) ) , $ timeout ) ; if ( $ rs [ 0 ] instanceof RpcError ) { throw new RpcErrorException ( $ rs [ 0 ] ) ; } return $ rs [ 0 ] ; }
|
Invokes a single remote command and returns the result of the invocation .
|
7,058
|
public static function reflectorFactory ( Reflector $ reflector ) { $ args = func_get_args ( ) ; $ g = new static ( $ args [ 1 ] ) ; $ g -> elevate ( $ args [ 0 ] ) ; return $ g ; }
|
Erstellt ein neues GProperty
|
7,059
|
public function reset ( array $ names = array ( ) ) { if ( array ( ) == $ names ) { $ this -> new_instance = array ( ) ; return $ this -> update ( ) ; } else { foreach ( $ this -> components as $ c ) { if ( in_array ( $ c -> get_name ( ) , $ names ) ) { $ this -> new_instance [ $ c -> get_name ( ) ] = $ c -> get_default_value ( ) ; } } return $ this -> update ( ) ; } }
|
Reset all fields to their default values .
|
7,060
|
private function update_components ( $ components ) { foreach ( $ components as $ component ) { if ( $ component instanceof UI \ Components \ Composite ) { $ this -> update_components ( $ component -> components ) ; } if ( $ component instanceof UI \ ValueComponentInterface ) { $ this -> update_component ( $ component ) ; } } }
|
Update the given list of components . Recursively calls itself fpr composite components .
|
7,061
|
private function update_value ( $ component , $ value ) { $ component -> set_value ( $ value ) ; $ this -> final_instance [ $ component -> get_name ( ) ] = $ value ; }
|
Update the component s value and the final instance with the given value .
|
7,062
|
private function update_filterable ( UI \ FilterableComponentInterface $ component ) { $ this -> update_value ( $ component , $ component -> apply_filter ( $ this -> new_instance [ $ component -> get_name ( ) ] ) ) ; }
|
Filter the component s value using its filter function .
|
7,063
|
public function get ( $ locale = 'en' ) { if ( isset ( $ this -> stopwords [ $ locale ] ) ) { return $ this -> stopwords [ $ locale ] ; } $ this -> stopwords [ $ locale ] = [ ] ; $ filename = $ this -> path . '/' . $ locale . '.php' ; if ( file_exists ( $ filename ) ) { $ this -> stopwords [ $ locale ] = require $ filename ; } return $ this -> stopwords [ $ locale ] ; }
|
Return stop word list for given locale .
|
7,064
|
public static function doInsert ( $ values , PropelPDO $ con = null ) { if ( $ con === null ) { $ con = Propel :: getConnection ( RolePeer :: DATABASE_NAME , Propel :: CONNECTION_WRITE ) ; } if ( $ values instanceof Criteria ) { $ criteria = clone $ values ; } else { $ criteria = $ values -> buildCriteria ( ) ; } if ( $ criteria -> containsKey ( RolePeer :: ID ) && $ criteria -> keyContainsValue ( RolePeer :: ID ) ) { throw new PropelException ( 'Cannot insert a value for auto-increment primary key (' . RolePeer :: ID . ')' ) ; } $ criteria -> setDbName ( RolePeer :: DATABASE_NAME ) ; try { $ con -> beginTransaction ( ) ; $ pk = BasePeer :: doInsert ( $ criteria , $ con ) ; $ con -> commit ( ) ; } catch ( Exception $ e ) { $ con -> rollBack ( ) ; throw $ e ; } return $ pk ; }
|
Performs an INSERT on the database given a Role or Criteria object .
|
7,065
|
protected function showDetail ( Model $ model ) { $ name = $ this -> manager -> getClassName ( $ model ) ; $ this -> title ( "Summary of Model {$name} :" ) ; $ summary = $ this -> manager -> getModelSummary ( $ name ) ; $ rows = [ ] ; foreach ( $ summary as $ key => $ value ) { if ( is_bool ( $ value ) ) { $ value = $ value ? 'yes' : 'no' ; } $ valueText = $ this -> paintString ( $ value , 'brown' ) ; $ rows [ ] = [ $ key , $ valueText ] ; } $ this -> table ( [ 'Key' , 'Value' ] , $ rows ) ; $ this -> showDatabaseFields ( $ model ) ; $ this -> showRelatoins ( $ model ) ; $ this -> showModifier ( $ model ) ; }
|
show detail of model
|
7,066
|
protected function showDatabaseFields ( Model $ model ) { $ this -> title ( "Table {$model->getTable()} :" ) ; if ( ! $ this -> db -> isConnected ( ) ) { $ this -> warn ( "Not Connected to databse, please check your connection config\r" ) ; } else { $ fields = $ this -> db -> getFields ( $ model -> getTable ( ) ) ; $ headers = [ 'name' , 'type' , 'null' , 'length' , 'unsigned' , 'autoincrement' , 'primary_key' , 'foreign_key' ] ; $ this -> table ( $ headers , $ fields -> toArray ( ) ) ; } }
|
show database fileds
|
7,067
|
protected function showRelatoins ( Model $ model ) { $ name = $ this -> manager -> getClassName ( $ model ) ; $ this -> title ( "Relations of Model {$name}: " ) ; $ relations = $ this -> manager -> getRelations ( $ model ) ; $ tbody = [ ] ; foreach ( $ relations as $ relation ) { $ relationName = $ this -> manager -> getClassName ( $ relation ) ; $ related = $ relation -> getRelated ( ) ? : null ; $ tbody [ ] = [ $ this -> paintString ( $ relationName , 'brown' ) , $ related ? $ this -> manager -> getClassName ( $ related ) : '' , ] ; } $ this -> table ( [ 'relation' , 'model' ] , $ tbody ) ; }
|
show relations of model
|
7,068
|
protected function showModifier ( Model $ model ) { $ name = $ this -> manager -> getClassName ( $ model ) ; $ this -> title ( "Modifier of Model {$name}: " ) ; $ modifiers = [ 'mutators' => $ this -> manager -> getMutators ( $ model ) , 'accessors' => $ this -> manager -> getAccessors ( $ model ) , 'scopes' => $ this -> manager -> getScopes ( $ model ) , ] ; $ rows = [ ] ; foreach ( max ( $ modifiers ) as $ modifier ) { foreach ( [ 'mutator' , 'accessor' , 'scope' ] as $ type ) { $ $ type = '' ; $ types = & $ modifiers [ Str :: plural ( $ type ) ] ; if ( $ types -> count ( ) > 0 ) { $ $ type = $ this -> paintString ( $ types -> first ( ) -> getName ( ) , 'brown' ) ; unset ( $ types [ 0 ] ) ; } } $ rows [ ] = [ $ mutator , $ accessor , $ scope ] ; } $ headers = [ 'mutator' , 'accessor' , 'scope' ] ; $ this -> table ( $ headers , $ rows ) ; }
|
show model modifier
|
7,069
|
public function badRequest ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_BAD_REQUEST , $ headers ) ; }
|
Returns 400 Bad Request Response
|
7,070
|
public function unauthorized ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_UNAUTHORIZED , $ headers ) ; }
|
Returns 401 Unauthorized Response
|
7,071
|
public function forbidden ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_FORBIDDEN , $ headers ) ; }
|
Returns 403 Forbidden Response
|
7,072
|
public function notFound ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_NOT_FOUND , $ headers ) ; }
|
Returns 404 Not Found HTTP Response
|
7,073
|
public function methodNotAllowed ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_METHOD_NOT_ALLOWED , $ headers ) ; }
|
Returns 405 Method Not Allowed Response
|
7,074
|
public function conflict ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_CONFLICT , $ headers ) ; }
|
Returns 409 Conflict Response
|
7,075
|
public function unprocessableEntity ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_UNPROCESSABLE_ENTITY , $ headers ) ; }
|
Returns 422 Unprocessable Entity
|
7,076
|
public function internalError ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_INTERNAL_SERVER_ERROR , $ headers ) ; }
|
Returns 500 Internal Server HTTP Response
|
7,077
|
public function notImplemented ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_NOT_IMPLEMENTED , $ headers ) ; }
|
Returns 501 Not Implemented HTTP Response
|
7,078
|
public function notAvailable ( $ msg = '' , $ errorCode = null , $ headers = [ ] ) { return $ this -> getErrorResponse ( $ msg , $ errorCode , self :: HTTP_SERVICE_UNAVAILABLE , $ headers ) ; }
|
Returns 503 Not Available HTTP Response
|
7,079
|
public function bootstrap ( ) { $ this -> registry -> make ( 'toolbar' ) -> addCollector ( new Response ( $ this -> registry -> make ( 'response' ) ) , true ) ; }
|
Once the has started
|
7,080
|
public function addBehavior ( Behavior $ behavior ) { $ behavior -> setRepository ( $ this ) ; $ this -> _behaviors [ $ behavior -> getAlias ( ) ] = $ behavior ; $ this -> attachObject ( $ behavior -> getAlias ( ) , $ behavior ) ; if ( $ behavior instanceof Listener ) { $ this -> on ( 'db' , $ behavior ) ; } return $ this ; }
|
Add a behavior .
|
7,081
|
public function aggregate ( Query $ query , $ function , $ field ) { $ query -> fields ( Query :: func ( strtoupper ( $ function ) , [ $ field => Func :: FIELD ] ) -> asAlias ( 'aggregate' ) ) ; $ results = $ this -> getDriver ( ) -> setContext ( 'read' ) -> executeQuery ( $ query ) -> find ( ) ; if ( isset ( $ results [ 0 ] ) ) { return ( int ) $ results [ 0 ] [ 'aggregate' ] ; } return 0 ; }
|
Perform an aggregation on the database and return the calculated value . The currently supported aggregates are avg count min max and sum .
|
7,082
|
public function castResults ( Event $ event , array & $ results , $ finder ) { $ columns = $ this -> getSchema ( ) -> getColumns ( ) ; $ driver = $ this -> getDriver ( ) ; $ entityClass = $ this -> getEntity ( ) ; foreach ( $ results as $ i => $ result ) { foreach ( $ result as $ field => $ value ) { if ( isset ( $ columns [ $ field ] ) ) { $ result [ $ field ] = $ driver -> getType ( $ columns [ $ field ] [ 'type' ] ) -> from ( $ value ) ; } if ( ! is_array ( $ value ) ) { continue ; } $ result [ $ field ] = new Entity ( $ value ) ; } $ results [ $ i ] = new $ entityClass ( $ result ) ; } }
|
Type cast the results and wrap each result in an entity after a find operation .
|
7,083
|
public function create ( $ data , array $ options = [ ] ) { return $ this -> query ( Query :: INSERT ) -> save ( $ data , $ options ) ; }
|
Insert data into the database as a new record . If any related data exists insert new records after joining them to the original record . Validate schema data and related data structure before inserting .
|
7,084
|
public function createMany ( array $ data , $ allowPk = false , array $ options = [ ] ) { $ pk = $ this -> getPrimaryKey ( ) ; $ columns = $ this -> getSchema ( ) -> getColumns ( ) ; $ records = [ ] ; $ defaults = [ ] ; if ( $ columns ) { foreach ( $ columns as $ key => $ column ) { $ defaults [ $ key ] = array_key_exists ( 'default' , $ column ) ? $ column [ 'default' ] : '' ; } unset ( $ defaults [ $ pk ] ) ; } foreach ( $ data as $ record ) { if ( $ record instanceof Arrayable ) { $ record = $ record -> toArray ( ) ; } $ record = Hash :: merge ( $ defaults , $ record ) ; if ( ! $ allowPk ) { unset ( $ record [ $ pk ] ) ; } if ( $ columns ) { $ record = array_intersect_key ( $ record , $ columns ) ; } $ records [ ] = $ record ; } return $ this -> query ( Query :: MULTI_INSERT ) -> save ( $ records , $ options ) ; }
|
Insert multiple records into the database using a single query . Missing fields will be added with an empty value or the schema default value . Does not support callbacks or transactions .
|
7,085
|
public function createTable ( array $ options = [ ] , array $ attributes = [ ] ) { $ schema = $ this -> getSchema ( ) ; $ schema -> addOptions ( $ options ) ; $ status = ( bool ) $ this -> query ( Query :: CREATE_TABLE ) -> attribute ( $ attributes ) -> schema ( $ schema ) -> save ( ) ; if ( $ status ) { foreach ( $ schema -> getIndexes ( ) as $ index => $ columns ) { $ this -> query ( Query :: CREATE_INDEX ) -> from ( $ schema -> getTable ( ) , $ index ) -> save ( $ columns ) ; } } return $ status ; }
|
Create a database table and indexes based off the tables schema . The schema must be an array of column data .
|
7,086
|
public function delete ( $ id , array $ options = [ ] ) { return $ this -> query ( Query :: DELETE ) -> where ( $ this -> getPrimaryKey ( ) , $ id ) -> save ( [ ] , $ options ) ; }
|
Delete a record by ID .
|
7,087
|
public function deleteMany ( Closure $ conditions , array $ options = [ ] ) { $ query = $ this -> query ( Query :: DELETE ) -> bindCallback ( $ conditions ) ; $ where = $ query -> getWhere ( ) -> getParams ( ) ; if ( empty ( $ where ) ) { throw new InvalidQueryException ( 'No where clause detected, will not delete all records' ) ; } return $ query -> save ( [ ] , $ options ) ; }
|
Delete multiple records with conditions .
|
7,088
|
public function exists ( $ id ) { return ( bool ) $ this -> select ( ) -> where ( $ this -> getPrimaryKey ( ) , $ id ) -> count ( ) ; }
|
Check if a record with an ID exists .
|
7,089
|
public function filterData ( Event $ event , Query $ query , $ id , array & $ data ) { if ( $ columns = $ this -> getSchema ( ) -> getColumns ( ) ) { $ data = array_intersect_key ( $ data , $ columns ) ; } return true ; }
|
Filter out invalid columns before a save operation .
|
7,090
|
public function find ( Query $ query , $ type , array $ options = [ ] ) { $ options = $ options + [ 'before' => true , 'after' => true , 'collection' => $ this -> getConfig ( 'collection' ) ] ; $ finder = $ this -> getFinder ( $ type ) ; $ state = null ; if ( $ options [ 'before' ] ) { $ event = $ this -> emit ( 'db.preFind' , [ $ query , $ type ] ) ; $ state = $ event -> getState ( ) ; if ( ! $ state ) { return $ finder -> noResults ( $ options ) ; } } if ( is_array ( $ state ) ) { $ results = $ state ; } else { $ finder -> before ( $ query , $ options ) ; $ results = $ this -> getDriver ( ) -> setContext ( 'read' ) -> executeQuery ( $ query ) -> find ( ) ; } if ( ! $ results ) { return $ finder -> noResults ( $ options ) ; } if ( $ options [ 'after' ] ) { $ this -> emit ( 'db.postFind' , [ & $ results , $ type ] ) ; } return $ finder -> after ( $ results , $ options ) ; }
|
All - in - one method for fetching results from a query . Depending on the type of finder the returned results will differ .
|
7,091
|
public function findID ( Query $ query ) { $ pk = $ this -> getPrimaryKey ( ) ; foreach ( $ query -> getWhere ( ) -> getParams ( ) as $ param ) { if ( $ param instanceof Expr && $ param -> getField ( ) === $ pk && in_array ( $ param -> getOperator ( ) , [ '=' , 'in' ] ) ) { return $ param -> getValue ( ) ; } } $ select = clone $ query ; $ results = array_values ( $ select -> setType ( Query :: SELECT ) -> fields ( $ pk ) -> lists ( $ pk , $ pk , [ 'before' => false , 'after' => false ] ) ) ; if ( count ( $ results ) > 1 ) { return $ results ; } else if ( count ( $ results ) === 1 ) { return $ results [ 0 ] ; } return null ; }
|
Find the a primary key value within a query . Begin by looping through the where clause and match any value that equates to the PK field . If none can be found do a select query for a list of IDs .
|
7,092
|
public function getBehavior ( $ alias ) { if ( $ this -> hasBehavior ( $ alias ) ) { return $ this -> _behaviors [ $ alias ] ; } throw new MissingBehaviorException ( sprintf ( 'Behavior %s does not exist' , $ alias ) ) ; }
|
Return a behavior by alias .
|
7,093
|
public function getDisplayField ( ) { return $ this -> cache ( __METHOD__ , function ( ) { $ fields = $ this -> getConfig ( 'displayField' ) ; $ schema = $ this -> getSchema ( ) ; foreach ( ( array ) $ fields as $ field ) { if ( $ schema -> hasColumn ( $ field ) ) { return $ field ; } } return $ this -> getPrimaryKey ( ) ; } ) ; }
|
Return the field used as the display field .
|
7,094
|
public function getDriver ( ) { if ( $ this -> _driver ) { return $ this -> _driver ; } return $ this -> _driver = $ this -> getDatabase ( ) -> getDriver ( $ this -> getConnectionKey ( ) ) ; }
|
Return the driver defined by key .
|
7,095
|
public function getFinder ( $ key ) { if ( isset ( $ this -> _finders [ $ key ] ) ) { return $ this -> _finders [ $ key ] ; } throw new MissingFinderException ( sprintf ( 'Finder %s does not exist' , $ key ) ) ; }
|
Return a finder by name .
|
7,096
|
public function getPrimaryKey ( ) { return $ this -> cache ( __METHOD__ , function ( ) { $ pk = $ this -> getConfig ( 'primaryKey' ) ; $ schema = $ this -> getSchema ( ) ; if ( $ schema -> hasColumn ( $ pk ) ) { return $ pk ; } if ( $ pk = $ schema -> getPrimaryKey ( ) ) { return $ pk [ 'columns' ] [ 0 ] ; } return 'id' ; } ) ; }
|
Return the field used as the primary usually the ID .
|
7,097
|
public function getSchema ( ) { if ( $ this -> _schema instanceof Schema ) { return $ this -> _schema ; } else if ( $ this -> _schema && is_array ( $ this -> _schema ) ) { $ columns = $ this -> _schema ; } else { $ columns = $ this -> getDriver ( ) -> describeTable ( $ this -> getTable ( ) ) ; } $ this -> setSchema ( new Schema ( $ this -> getTable ( ) , $ columns ) ) ; return $ this -> _schema ; }
|
Return a schema object that represents the database table .
|
7,098
|
public function query ( $ type ) { $ query = $ this -> getDriver ( ) -> newQuery ( $ type ) ; $ query -> setRepository ( $ this ) ; $ query -> from ( $ this -> getTable ( ) , $ this -> getAlias ( ) ) ; return $ query ; }
|
Instantiate a new query builder .
|
7,099
|
public function read ( $ id , array $ options = [ ] , Closure $ callback = null ) { return $ this -> select ( ) -> where ( $ this -> getPrimaryKey ( ) , $ id ) -> bindCallback ( $ callback ) -> first ( $ options ) ; }
|
Fetch a single record by ID .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.