idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
60,200
|
public function setAll ( $ name , $ value ) { foreach ( $ this -> data as $ record ) { $ record [ $ name ] = $ value ; } return $ this ; }
|
Set field value for every record in collection
|
60,201
|
public function getAll ( $ name ) { $ data = array ( ) ; foreach ( $ this -> data as $ record ) { $ data [ ] = $ record [ $ name ] ; } return $ data ; }
|
Return the value of field from every record in collection
|
60,202
|
public function remove ( $ name ) { if ( ! $ this -> isColl ) { if ( array_key_exists ( $ name , $ this -> data ) ) { $ this -> data [ $ name ] = null ; } } else { unset ( $ this -> data [ $ name ] ) ; } return $ this ; }
|
Remove field value
|
60,203
|
public function getFields ( ) { if ( empty ( $ this -> fields ) ) { $ this -> fields = $ this -> db -> getTableFields ( $ this -> fullTable , true ) ; } return $ this -> fields ; }
|
Returns the name of fields of current table
|
60,204
|
public function getChangedData ( $ field = null ) { if ( $ field ) { return isset ( $ this -> changedData [ $ field ] ) ? $ this -> changedData [ $ field ] : null ; } return $ this -> changedData ; }
|
Return the field data before changed
|
60,205
|
public function execute ( ) { if ( $ this -> type == self :: SELECT ) { $ this -> loaded = true ; if ( $ this -> cacheTime !== false ) { return $ this -> fetchFromCache ( ) ; } else { return $ this -> db -> fetchAll ( $ this -> getSql ( ) , $ this -> params , $ this -> paramTypes ) ; } } else { return $ this -> db -> executeUpdate ( $ this -> getSql ( ) , $ this -> params , $ this -> paramTypes ) ; } }
|
Execute this query using the bound parameters and their types
|
60,206
|
public function find ( $ conditions = false ) { $ this -> isColl = false ; $ data = $ this -> fetch ( $ conditions ) ; if ( $ data ) { $ this -> data = $ data + $ this -> data ; $ this -> triggerCallback ( 'afterFind' ) ; return $ this ; } else { return false ; } }
|
Executes the generated SQL and returns the found record object or false
|
60,207
|
public function findOrInit ( $ conditions = false , $ data = array ( ) ) { if ( ! $ this -> find ( $ conditions ) ) { $ this -> isNew = true ; ! is_array ( $ conditions ) && $ conditions = array ( $ this -> primaryKey => $ conditions ) ; if ( is_object ( $ data ) && method_exists ( $ data , 'toArray' ) ) { $ data = $ data -> toArray ( ) ; } $ this -> fromArray ( $ data ) ; $ this -> setData ( $ conditions ) ; } return $ this ; }
|
Find a record by specified conditions and init with the specified data if record not found
|
60,208
|
public function findAll ( $ conditions = false ) { $ this -> isColl = true ; $ data = $ this -> fetchAll ( $ conditions ) ; $ records = array ( ) ; foreach ( $ data as $ key => $ row ) { $ records [ $ key ] = $ this -> db -> init ( $ this -> table , $ row , false ) ; $ records [ $ key ] -> triggerCallback ( 'afterFind' ) ; } $ this -> data = $ records ; return $ this ; }
|
Executes the generated SQL and returns the found record collection object or false
|
60,209
|
public function fetch ( $ conditions = false ) { $ this -> andWhere ( $ conditions ) ; $ this -> limit ( 1 ) ; $ data = $ this -> execute ( ) ; return $ data ? $ data [ 0 ] : false ; }
|
Executes the generated query and returns the first array result
|
60,210
|
public function fetchColumn ( $ conditions = false ) { $ data = $ this -> fetch ( $ conditions ) ; return $ data ? current ( $ data ) : false ; }
|
Executes the generated query and returns a column value of the first row
|
60,211
|
public function fetchAll ( $ conditions = false ) { $ this -> andWhere ( $ conditions ) ; $ data = $ this -> execute ( ) ; if ( $ this -> indexBy ) { $ data = $ this -> executeIndexBy ( $ data , $ this -> indexBy ) ; } return $ data ; }
|
Executes the generated query and returns all array results
|
60,212
|
public function count ( $ conditions = false , $ count = '1' ) { $ this -> andWhere ( $ conditions ) ; $ select = $ this -> sqlParts [ 'select' ] ; $ this -> select ( 'COUNT(' . $ count . ')' ) ; $ count = ( int ) $ this -> db -> fetchColumn ( $ this -> getSqlForSelect ( true ) , $ this -> params ) ; $ this -> sqlParts [ 'select' ] = $ select ; return $ count ; }
|
Executes a COUNT query to receive the rows number
|
60,213
|
public function countBySubQuery ( $ conditions = false ) { $ this -> andWhere ( $ conditions ) ; return ( int ) $ this -> db -> fetchColumn ( $ this -> getSqlForCount ( ) , $ this -> params ) ; }
|
Executes a sub query to receive the rows number
|
60,214
|
public function update ( $ set = array ( ) ) { if ( is_array ( $ set ) ) { $ params = array ( ) ; foreach ( $ set as $ field => $ param ) { $ this -> add ( 'set' , $ field . ' = ?' , true ) ; $ params [ ] = $ param ; } $ this -> params = array_merge ( $ params , $ this -> params ) ; } else { $ this -> add ( 'set' , $ set , true ) ; } $ this -> type = self :: UPDATE ; return $ this -> execute ( ) ; }
|
Execute a update query with specified data
|
60,215
|
public function delete ( $ conditions = false ) { $ this -> andWhere ( $ conditions ) ; $ this -> type = self :: DELETE ; return $ this -> execute ( ) ; }
|
Execute a delete query with specified conditions
|
60,216
|
public function from ( $ from ) { $ pos = strpos ( $ from , ' ' ) ; if ( false !== $ pos ) { $ this -> table = substr ( $ from , 0 , $ pos ) ; } else { $ this -> table = $ from ; } $ this -> fullTable = $ this -> db -> getTable ( $ this -> table ) ; return $ this -> add ( 'from' , $ this -> db -> getTable ( $ from ) ) ; }
|
Sets table for FROM query
|
60,217
|
public function andWhere ( $ conditions , $ params = array ( ) , $ types = array ( ) ) { if ( $ conditions === false ) { return $ this ; } else { $ conditions = $ this -> processCondition ( $ conditions , $ params , $ types ) ; return $ this -> add ( 'where' , $ conditions , true , 'AND' ) ; } }
|
Adds one or more restrictions to the query results forming a logical conjunction with any previously specified restrictions
|
60,218
|
public function indexBy ( $ field ) { $ this -> data = $ this -> executeIndexBy ( $ this -> data , $ field ) ; $ this -> indexBy = $ field ; return $ this ; }
|
Specifies a field to be the key of the fetched array
|
60,219
|
public function getSqlPart ( $ name ) { return isset ( $ this -> sqlParts [ $ name ] ) ? $ this -> sqlParts [ $ name ] : false ; }
|
Returns a SQL query part by its name
|
60,220
|
public function resetSqlParts ( $ name = null ) { if ( is_null ( $ name ) ) { $ name = array_keys ( $ this -> sqlParts ) ; } foreach ( $ name as $ queryPartName ) { $ this -> resetSqlPart ( $ queryPartName ) ; } return $ this ; }
|
Reset all SQL parts
|
60,221
|
public function resetSqlPart ( $ name ) { $ this -> sqlParts [ $ name ] = is_array ( $ this -> sqlParts [ $ name ] ) ? array ( ) : null ; $ this -> state = self :: STATE_DIRTY ; return $ this ; }
|
Reset single SQL part
|
60,222
|
public function getSql ( ) { if ( $ this -> sql !== null && $ this -> state === self :: STATE_CLEAN ) { return $ this -> sql ; } switch ( $ this -> type ) { case self :: DELETE : $ this -> sql = $ this -> getSqlForDelete ( ) ; break ; case self :: UPDATE : $ this -> sql = $ this -> getSqlForUpdate ( ) ; break ; case self :: SELECT : default : $ this -> sql = $ this -> getSqlForSelect ( ) ; break ; } $ this -> state = self :: STATE_CLEAN ; return $ this -> sql ; }
|
Get the complete SQL string formed by the current specifications of this QueryBuilder
|
60,223
|
protected function getSqlForSelect ( $ count = false ) { $ parts = $ this -> sqlParts ; if ( ! $ parts [ 'select' ] ) { $ parts [ 'select' ] = array ( '*' ) ; } $ query = 'SELECT ' . implode ( ', ' , $ parts [ 'select' ] ) . ' FROM ' . $ this -> getFrom ( ) ; foreach ( $ parts [ 'join' ] as $ join ) { $ query .= ' ' . strtoupper ( $ join [ 'type' ] ) . ' JOIN ' . $ join [ 'table' ] . ' ON ' . $ join [ 'on' ] ; } $ query .= ( $ parts [ 'where' ] !== null ? ' WHERE ' . ( ( string ) $ parts [ 'where' ] ) : '' ) . ( $ parts [ 'groupBy' ] ? ' GROUP BY ' . implode ( ', ' , $ parts [ 'groupBy' ] ) : '' ) . ( $ parts [ 'having' ] !== null ? ' HAVING ' . ( ( string ) $ parts [ 'having' ] ) : '' ) ; if ( false === $ count ) { $ query .= ( $ parts [ 'orderBy' ] ? ' ORDER BY ' . implode ( ', ' , $ parts [ 'orderBy' ] ) : '' ) . ( $ parts [ 'limit' ] !== null ? ' LIMIT ' . $ parts [ 'limit' ] : '' ) . ( $ parts [ 'offset' ] !== null ? ' OFFSET ' . $ parts [ 'offset' ] : '' ) ; } $ query .= $ this -> generateLockSql ( ) ; return $ query ; }
|
Converts this instance into an SELECT string in SQL
|
60,224
|
protected function processCondition ( $ conditions , $ params , $ types ) { if ( is_numeric ( $ conditions ) || empty ( $ conditions ) ) { $ conditions = array ( $ this -> primaryKey => $ conditions ) ; } if ( is_array ( $ conditions ) ) { $ where = array ( ) ; $ params = array ( ) ; foreach ( $ conditions as $ field => $ condition ) { if ( is_array ( $ condition ) ) { $ where [ ] = $ field . ' IN (' . implode ( ', ' , array_pad ( array ( ) , count ( $ condition ) , '?' ) ) . ')' ; $ params = array_merge ( $ params , $ condition ) ; } else { $ where [ ] = $ field . " = ?" ; $ params [ ] = $ condition ; } } $ conditions = implode ( ' AND ' , $ where ) ; } if ( $ params !== false ) { if ( is_array ( $ params ) ) { $ this -> params = array_merge ( $ this -> params , $ params ) ; $ this -> paramTypes = array_merge ( $ this -> paramTypes , $ types ) ; } else { $ this -> params [ ] = $ params ; if ( $ types ) { $ this -> paramTypes [ ] = $ types ; } } } return $ conditions ; }
|
Generate condition string for WHERE or Having statement
|
60,225
|
protected function loadData ( $ offset ) { if ( ! $ this -> loaded && ! $ this -> isNew ) { if ( is_numeric ( $ offset ) || is_null ( $ offset ) ) { $ this -> findAll ( ) ; } else { $ this -> find ( ) ; } } }
|
Load record by array offset
|
60,226
|
public function filter ( \ Closure $ fn ) { $ data = array_filter ( $ this -> data , $ fn ) ; $ records = $ this -> db -> init ( $ this -> table , array ( ) , $ this -> isNew ) ; $ records -> data = $ data ; $ records -> isColl = true ; $ records -> loaded = $ this -> loaded ; return $ records ; }
|
Filters elements of the collection using a callback function
|
60,227
|
public function cache ( $ seconds = null ) { if ( $ seconds === null ) { $ this -> cacheTime = $ this -> defaultCacheTime ; } elseif ( $ seconds === false ) { $ this -> cacheTime = false ; } else { $ this -> cacheTime = ( int ) $ seconds ; } return $ this ; }
|
Set or remove cache time for the query
|
60,228
|
public function tags ( $ tags = null ) { $ this -> cacheTags = $ tags === false ? false : $ tags ; return $ this ; }
|
Set or remove cache tags
|
60,229
|
public function getCacheKey ( ) { return $ this -> cacheKey ? : md5 ( $ this -> db -> getDbname ( ) . $ this -> getSql ( ) . serialize ( $ this -> params ) . serialize ( $ this -> paramTypes ) ) ; }
|
Generate cache key form query and params
|
60,230
|
public function buildForm ( FormBuilderInterface $ builder , array $ options ) { foreach ( $ options [ 'button_groups' ] as $ name => $ config ) { $ builder -> add ( $ name , ButtonGroupType :: class , $ config ) ; } }
|
Pull all group of button into the form .
|
60,231
|
public function loadFromFile ( $ pattern ) { if ( isset ( $ this -> files [ $ pattern ] ) ) { return $ this ; } $ file = sprintf ( $ pattern , $ this -> locale ) ; if ( ! is_file ( $ file ) ) { $ defaultFile = sprintf ( $ pattern , $ this -> defaultLocale ) ; if ( ! is_file ( $ defaultFile ) ) { throw new \ InvalidArgumentException ( sprintf ( 'File "%s" and "%s" not found or not readable' , $ file , $ defaultFile ) ) ; } else { $ file = $ defaultFile ; } } $ this -> files [ $ pattern ] = true ; return $ this -> loadFromArray ( require $ file ) ; }
|
Loads translator messages from file
|
60,232
|
public function onAfterLoadIntoFile ( $ file ) { if ( ! $ file -> getIsImage ( ) ) { return ; } $ folder = rtrim ( $ file -> Parent ( ) -> getFilename ( ) , '/' ) ; $ custom_folders = $ this -> config ( ) -> get ( 'custom_folders' ) ; if ( ! empty ( $ custom_folders [ $ folder ] ) && is_array ( $ custom_folders [ $ folder ] ) ) { foreach ( $ custom_folders [ $ folder ] as $ key => $ val ) { $ this -> config ( ) -> set ( $ key , $ val ) ; } } if ( $ this -> config ( ) -> get ( 'bypass' ) ) { return ; } $ this -> config_max_width = $ this -> config ( ) -> get ( 'max_width' ) ; $ this -> config_max_height = $ this -> config ( ) -> get ( 'max_height' ) ; $ this -> config_auto_rotate = $ this -> config ( ) -> get ( 'auto_rotate' ) ; $ this -> config_force_resampling = $ this -> config ( ) -> get ( 'force_resampling' ) ; $ extension = $ file -> getExtension ( ) ; if ( $ this -> config_force_resampling || ( $ this -> config_max_height && $ file -> getHeight ( ) > $ this -> config_max_height ) || ( $ this -> config_max_width && $ file -> getWidth ( ) > $ this -> config_max_width ) || ( $ this -> config_auto_rotate && preg_match ( '/jpe?g/i' , $ file -> getExtension ( ) ) ) ) { $ this -> scaleUploadedImage ( $ file ) ; } }
|
Post data manupulation
|
60,233
|
private function scaleUploadedImage ( $ file ) { $ backend = $ file -> getImageBackend ( ) ; $ tmp_image = TEMP_FOLDER . '/resampled-' . mt_rand ( 100000 , 999999 ) . '.' . $ file -> getExtension ( ) ; $ tmp_contents = $ file -> getString ( ) ; @ file_put_contents ( $ tmp_image , $ tmp_contents ) ; $ backend -> loadFrom ( $ tmp_image ) ; if ( $ backend -> getImageResource ( ) ) { $ modified = false ; $ transformed = $ backend ; if ( $ this -> config_auto_rotate && preg_match ( '/jpe?g/i' , $ file -> getExtension ( ) ) ) { $ switch_orientation = $ this -> exifRotation ( $ tmp_image ) ; if ( $ switch_orientation ) { $ modified = true ; $ transformed -> setImageResource ( $ transformed -> getImageResource ( ) -> orientate ( ) ) ; } } if ( $ transformed && ( ( $ this -> config_max_width && $ transformed -> getWidth ( ) > $ this -> config_max_width ) || ( $ this -> config_max_height && $ transformed -> getHeight ( ) > $ this -> config_max_height ) ) ) { if ( $ this -> config_max_width && $ this -> config_max_height ) { $ transformed = $ transformed -> resizeRatio ( $ this -> config_max_width , $ this -> config_max_height ) ; } elseif ( $ this -> config_max_width ) { $ transformed = $ transformed -> resizeByWidth ( $ this -> config_max_width ) ; } else { $ transformed = $ transformed -> resizeByHeight ( $ this -> config_max_height ) ; } $ modified = true ; } elseif ( $ transformed && $ this -> config_force_resampling ) { $ modified = true ; } if ( $ transformed && $ modified ) { $ transformed -> writeTo ( $ tmp_image ) ; if ( ! Config :: inst ( ) -> get ( FlysystemAssetStore :: class , 'legacy_filenames' ) ) { $ file -> File -> deleteFile ( ) ; } $ file -> setFromLocalFile ( $ tmp_image , $ file -> FileName ) ; $ file -> write ( ) ; } } @ unlink ( $ tmp_image ) ; }
|
Scale an image
|
60,234
|
private function exifRotation ( $ file ) { if ( ! function_exists ( 'exif_read_data' ) ) { return false ; } $ exif = @ exif_read_data ( $ file ) ; if ( ! $ exif ) { return false ; } $ ort = @ $ exif [ 'IFD0' ] [ 'Orientation' ] ; if ( ! $ ort ) { $ ort = @ $ exif [ 'Orientation' ] ; } switch ( $ ort ) { case 3 : return '180' ; break ; case 6 : return '-90' ; break ; case 8 : return '90' ; break ; default : return false ; } }
|
exifRotation - return the exif rotation
|
60,235
|
public function full ( $ url , $ argsOrParams = array ( ) , $ params = array ( ) ) { return $ this -> request -> getUrlFor ( $ this -> __invoke ( $ url , $ argsOrParams , $ params ) ) ; }
|
Generate the absolute URL path by specified URL and parameters
|
60,236
|
public function query ( $ url = '' , $ argsOrParams = array ( ) , $ params = array ( ) ) { if ( strpos ( $ url , '%s' ) === false ) { $ argsOrParams = $ argsOrParams + $ this -> request -> getQueries ( ) ; } else { $ params += $ this -> request -> getQueries ( ) ; } return $ this -> __invoke ( $ url , $ argsOrParams , $ params ) ; }
|
Generate the URL path with current query parameters and specified parameters
|
60,237
|
public function append ( $ url = '' , $ argsOrParams = array ( ) , $ params = array ( ) ) { if ( strpos ( $ url , '%s' ) !== false ) { $ url = vsprintf ( $ url , ( array ) $ argsOrParams ) ; } else { $ params = $ argsOrParams ; } if ( $ params ) { $ url .= ( false === strpos ( $ url , '?' ) ? '?' : '&' ) ; } return $ url . ( is_array ( $ params ) ? http_build_query ( $ params ) : $ params ) ; }
|
Append parameters to specified URL
|
60,238
|
public function endTiming ( $ key , $ sampleRate = 1 ) { $ end = gettimeofday ( true ) ; if ( isset ( $ this -> timings [ $ key ] ) ) { $ timing = ( $ end - $ this -> timings [ $ key ] ) * 1000 ; $ this -> timing ( $ key , $ timing , $ sampleRate ) ; unset ( $ this -> timings [ $ key ] ) ; return $ timing ; } return null ; }
|
Ends the timing for a key and sends it to StatsD
|
60,239
|
public function time ( $ key , \ Closure $ fn , $ sampleRate = 1 ) { $ this -> startTiming ( $ key ) ; $ return = $ fn ( ) ; $ this -> endTiming ( $ key , $ sampleRate ) ; return $ return ; }
|
Executes a Closure and records it s execution time and sends it to StatsD returns the value the Closure returned
|
60,240
|
public function endMemoryProfile ( $ key , $ sampleRate = 1 ) { $ end = memory_get_usage ( ) ; if ( array_key_exists ( $ key , $ this -> memoryProfiles ) ) { $ memory = ( $ end - $ this -> memoryProfiles [ $ key ] ) ; $ this -> memory ( $ key , $ memory , $ sampleRate ) ; unset ( $ this -> memoryProfiles [ $ key ] ) ; } }
|
Ends the memory profiling and sends the value to the server
|
60,241
|
public function memory ( $ key , $ memory = null , $ sampleRate = 1 ) { if ( null === $ memory ) { $ memory = memory_get_peak_usage ( ) ; } $ this -> count ( $ key , $ memory , $ sampleRate ) ; }
|
Report memory usage to StatsD . if memory was not given report peak usage
|
60,242
|
public function count ( $ key , $ value , $ sampleRate = 1 ) { $ this -> updateStats ( $ key , ( int ) $ value , $ sampleRate , 'c' ) ; }
|
Sends a count to StatsD
|
60,243
|
public function updateStats ( $ key , $ delta = 1 , $ sampleRate = 1 , $ metric = 'c' ) { if ( ! is_array ( $ key ) ) { $ key = array ( $ key ) ; } $ data = array ( ) ; foreach ( $ key as $ stat ) { $ data [ $ stat ] = "$delta|$metric" ; } $ this -> send ( $ data , $ sampleRate ) ; }
|
Updates one or more stats .
|
60,244
|
public function getLength ( $ input ) { if ( is_scalar ( $ input ) ) { if ( $ this -> countByChars ) { return mb_strlen ( $ input , $ this -> charset ) ; } else { return strlen ( $ input ) ; } } elseif ( is_array ( $ input ) || $ input instanceof \ Countable ) { return count ( $ input ) ; } else { return false ; } }
|
Return the input s length or false when could not detected
|
60,245
|
public function on ( $ name , $ fn = null , $ priority = 0 ) { if ( is_array ( $ name ) ) { foreach ( $ name as $ item => $ fn ) { $ this -> on ( $ item , $ fn ) ; } return $ this ; } if ( ! is_callable ( $ fn ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Expected argument of name callable, "%s" given' , is_object ( $ fn ) ? get_class ( $ fn ) : gettype ( $ fn ) ) ) ; } if ( ! isset ( $ this -> handlers [ $ name ] ) ) { $ this -> handlers [ $ name ] = array ( ) ; } $ this -> handlers [ $ name ] [ $ priority ] [ ] = $ fn ; return $ this ; }
|
Attach a handler to an event
|
60,246
|
public function off ( $ name ) { if ( isset ( $ this -> handlers [ $ name ] ) ) { unset ( $ this -> handlers [ $ name ] ) ; } return $ this ; }
|
Remove event handlers by specified name
|
60,247
|
protected function writeLog ( $ level , $ message , $ context ) { if ( ! $ this -> handle ) { $ this -> handle = fopen ( $ this -> getFile ( ) , 'a' ) ; } $ content = $ this -> formatLog ( $ level , $ message , $ context ) ; return ( bool ) fwrite ( $ this -> handle , $ content ) ; }
|
Write the log message
|
60,248
|
protected function formatLog ( $ level , $ message , $ context = array ( ) ) { $ params = $ this -> formatParams ( $ message , $ context ) ; $ message = $ params [ 'message' ] ; $ context = $ params [ 'context' ] ; $ content = str_replace ( array ( '%datetime%' , '%namespace%' , '%level%' , '%message%' , ) , array ( date ( $ this -> dateFormat , microtime ( true ) ) , $ this -> namespace , strtoupper ( $ level ) , $ message , ) , $ this -> format ) ; if ( $ this -> context || $ context ) { $ content .= print_r ( $ this -> context + $ context , true ) . "\n" ; } return $ content ; }
|
Format the log content
|
60,249
|
protected function formatParams ( $ message , $ context ) { if ( ! is_array ( $ context ) ) { $ context = array ( 'context' => $ context ) ; } if ( $ message instanceof \ Exception ) { $ context += array ( 'code' => $ message -> getCode ( ) , 'file' => $ message -> getFile ( ) , 'line' => $ message -> getLine ( ) , 'trace' => $ message -> getTraceAsString ( ) , ) ; $ message = $ message -> getMessage ( ) ; } elseif ( is_array ( $ message ) ) { $ message = print_r ( $ message , true ) ; } else { $ message = ( string ) $ message ; } return array ( 'message' => $ message , 'context' => $ context ) ; }
|
Convert message to string and content to array for writing
|
60,250
|
public function getFile ( ) { if ( $ this -> fileDetected ) { return $ this -> file ; } $ this -> handle = null ; $ file = & $ this -> file ; if ( ! is_dir ( $ this -> dir ) && ! @ mkdir ( $ this -> dir , 0755 , true ) ) { $ message = sprintf ( 'Fail to create directory "%s"' , $ this -> dir ) ; ( $ e = error_get_last ( ) ) && $ message .= ': ' . $ e [ 'message' ] ; throw new \ RuntimeException ( $ message ) ; } $ file = realpath ( $ this -> dir ) . '/' . date ( $ this -> fileFormat ) ; if ( $ this -> fileSize ) { $ firstFile = $ file ; $ files = glob ( $ file . '*' , GLOB_NOSORT ) ; if ( 1 < count ( $ files ) ) { natsort ( $ files ) ; $ file = array_pop ( $ files ) ; } if ( is_file ( $ file ) && $ this -> fileSize < filesize ( $ file ) ) { $ ext = pathinfo ( $ file , PATHINFO_EXTENSION ) ; if ( is_numeric ( $ ext ) ) { $ file = $ firstFile . '.' . ( $ ext + 1 ) ; } else { $ file = $ firstFile . '.1' ; } } } $ this -> fileDetected = true ; return $ file ; }
|
Get log file
|
60,251
|
public function setContext ( $ name , $ value = null ) { if ( is_array ( $ name ) ) { $ this -> context = $ name + $ this -> context ; } else { $ this -> context [ $ name ] = $ value ; } return $ this ; }
|
Add one or multi item for log message
|
60,252
|
public function clean ( ) { $ this -> close ( ) ; $ dir = dirname ( $ this -> getFile ( ) ) ; if ( is_dir ( $ dir ) ) { $ files = scandir ( $ dir ) ; foreach ( $ files as $ file ) { if ( '.' != $ file && '..' != $ file ) { $ file = $ dir . DIRECTORY_SEPARATOR . $ file ; if ( is_file ( $ file ) ) { unlink ( $ file ) ; } } } } return $ this ; }
|
Clear up all log file
|
60,253
|
public function remove ( $ key ) { unset ( $ this -> data [ $ key ] ) ; $ this -> response -> removeCookie ( $ key ) ; return $ this ; }
|
Remove response cookie
|
60,254
|
protected function getTagValues ( ) { $ keys = array_map ( array ( $ this , 'getTagKey' ) , $ this -> tags ) ; $ values = $ this -> cache -> getMulti ( $ keys ) ; $ emptyKeys = array_diff ( $ values , array_filter ( $ values ) ) ; if ( $ emptyKeys ) { $ newValues = $ this -> setTagValues ( $ emptyKeys ) ; $ values = array_merge ( $ values , $ newValues ) ; } return $ values ; }
|
Returns tag values
|
60,255
|
protected function setTagValues ( $ keys ) { $ values = array ( ) ; foreach ( $ keys as $ key => $ value ) { $ values [ $ key ] = $ this -> generateTagValue ( ) ; } $ this -> cache -> setMulti ( $ values ) ; return $ values ; }
|
Initializes tag values by cache keys
|
60,256
|
public function generate_json ( $ result = NULL , $ match_array_type = FALSE ) { if ( ! is_null ( $ result ) ) { if ( is_object ( $ result ) ) { $ json_result = $ result -> result_array ( ) ; } elseif ( is_array ( $ result ) ) { $ json_result = $ result ; } else { return $ this -> _prep_args ( $ result ) ; } } else { return 'null' ; } return $ this -> _create_json ( $ json_result , $ match_array_type ) ; }
|
Can be passed a database result or associative array and returns a JSON formatted string
|
60,257
|
public function _is_associative_array ( $ arr ) { foreach ( array_keys ( $ arr ) as $ key => $ val ) { if ( $ key !== $ val ) { return TRUE ; } } return FALSE ; }
|
Checks for an associative array
|
60,258
|
private function clearAttachments ( $ dir ) { if ( ! file_exists ( $ dir ) ) { mkdir ( $ dir , 0777 , true ) ; } $ files = glob ( $ dir . '/*' ) ; foreach ( $ files as $ file ) { if ( is_file ( $ file ) ) { unlink ( $ file ) ; } } }
|
Clear all previous email attachments
|
60,259
|
public function css ( $ string ) { if ( ! $ string ) { return $ string ; } $ string = $ this -> toUtf8 ( $ string ) ; if ( $ string === '' || ctype_digit ( $ string ) ) { return $ string ; } $ result = preg_replace_callback ( '/[^a-z0-9]/iSu' , $ this -> cssMatcher , $ string ) ; return $ this -> fromUtf8 ( $ result ) ; }
|
Escape a string for the CSS context . CSS escaping can be applied to any string being inserted into CSS and escapes everything except alphanumerics .
|
60,260
|
protected function convertEncoding ( $ string , $ to , $ from ) { $ result = '' ; if ( function_exists ( 'iconv' ) ) { $ result = iconv ( $ from , $ to , $ string ) ; } elseif ( function_exists ( 'mb_convert_encoding' ) ) { $ result = mb_convert_encoding ( $ string , $ to , $ from ) ; } else { throw new \ RuntimeException ( get_class ( $ this ) . ' requires either the iconv or mbstring extension to be installed' . ' when escaping for non UTF-8 strings.' ) ; } if ( $ result === false ) { return '' ; } return $ result ; }
|
Encoding conversion helper which wraps iconv and mbstring where they exist or throws and exception where neither is available .
|
60,261
|
public function assign ( $ name , $ value = null ) { if ( is_array ( $ name ) ) { $ this -> data = $ name + $ this -> data ; } else { $ this -> data [ $ name ] = $ value ; } return $ this ; }
|
Assign variables to template
|
60,262
|
public function getFile ( $ name ) { if ( $ file = $ this -> resolveFile ( $ name ) ) { return $ file ; } else { $ components = $ this -> parseResource ( $ name ) ; throw new \ RuntimeException ( sprintf ( 'Template "%s" not found in directories "%s"' , $ components [ 'file' ] , implode ( '", "' , $ components [ 'dirs' ] ) ) ) ; } }
|
Get the template file by name
|
60,263
|
public function resolveFile ( $ name ) { $ components = $ this -> parseResource ( $ name ) ; foreach ( $ components [ 'dirs' ] as $ dir ) { if ( is_file ( $ file = $ dir . ( $ dir ? '/' : '' ) . $ components [ 'file' ] ) ) { return $ file ; } } return false ; }
|
Resolve the template file by name
|
60,264
|
public function layout ( $ name = null , $ variable = 'content' ) { $ this -> layout = array ( 'name' => $ name ? : $ this -> defaultLayout , 'variable' => $ variable ) ; return $ this ; }
|
Set layout file for current view
|
60,265
|
public function addOption ( $ option ) { $ this -> renderer -> getElement ( ) -> addOption ( $ option ) ; $ this -> renderer -> getHtmlElement ( ) -> addOption ( $ option ) ; }
|
Adds an option to the current options
|
60,266
|
protected function addButton ( $ builder , $ name , $ config ) { $ options = isset ( $ config [ 'options' ] ) ? $ config [ 'options' ] : [ ] ; if ( ! in_array ( $ config [ 'type' ] , $ this -> allowedTypes ) ) { throw new \ LogicException ( sprintf ( 'Allowed button types : "%s", given "%s".' , implode ( '", "' , $ this -> allowedTypes ) , $ config [ 'type' ] ) ) ; } return $ builder -> add ( $ name , $ config [ 'type' ] , $ options ) ; }
|
Adds a button .
|
60,267
|
protected function registerFatalHandler ( ) { $ error = $ this ; $ cwd = getcwd ( ) ; register_shutdown_function ( function ( ) use ( $ error , $ cwd ) { $ e = error_get_last ( ) ; if ( ! $ e || ! in_array ( $ e [ 'type' ] , array ( E_ERROR , E_CORE_ERROR , E_COMPILE_ERROR , E_PARSE ) ) ) { return ; } ob_get_length ( ) && ob_end_clean ( ) ; chdir ( $ cwd ) ; $ exception = new \ ErrorException ( $ e [ 'message' ] , $ e [ 'type' ] , 0 , $ e [ 'file' ] , $ e [ 'line' ] ) ; if ( $ error -> triggerHandler ( 'fatal' , $ exception ) ) { return ; } if ( $ error -> triggerHandler ( 'error' , $ exception ) ) { return ; } $ error -> internalHandleException ( $ exception ) ; } ) ; }
|
Detect fatal error and register fatal handler
|
60,268
|
public function triggerHandler ( $ type , $ exception ) { foreach ( $ this -> handlers [ $ type ] as $ handler ) { $ result = call_user_func_array ( $ handler , array ( $ exception , $ this -> wei ) ) ; if ( true === $ result ) { return true ; } } return false ; }
|
Trigger a error handler
|
60,269
|
public function handleException ( $ exception ) { if ( ! $ this -> ignorePrevHandler && $ this -> prevExceptionHandler ) { call_user_func ( $ this -> prevExceptionHandler , $ exception ) ; } if ( 404 == $ exception -> getCode ( ) ) { if ( $ this -> triggerHandler ( 'notFound' , $ exception ) ) { return ; } } if ( ! $ this -> triggerHandler ( 'error' , $ exception ) ) { $ this -> internalHandleException ( $ exception ) ; } restore_exception_handler ( ) ; }
|
The exception handler to render pretty message
|
60,270
|
public function displayException ( $ e , $ debug ) { if ( $ this -> enableCli && php_sapi_name ( ) == 'cli' ) { $ this -> displayCliException ( $ e ) ; return ; } $ code = $ e -> getCode ( ) ; $ file = $ e -> getFile ( ) ; $ line = $ e -> getLine ( ) ; if ( ! $ debug ) { $ view = isset ( $ this -> { 'view' . $ code } ) ? $ this -> { 'view' . $ code } : $ this -> view ; $ message = isset ( $ this -> { 'message' . $ code } ) ? $ this -> { 'message' . $ code } : $ this -> message ; $ detail = isset ( $ this -> { 'detail' . $ code } ) ? $ this -> { 'detail' . $ code } : $ this -> detail ; if ( $ view ) { require $ view ; return ; } } else { $ message = $ e -> getMessage ( ) ; $ detail = sprintf ( 'Threw by %s in %s on line %s' , get_class ( $ e ) , $ file , $ line ) ; $ fileInfo = $ this -> getFileCode ( $ file , $ line ) ; $ trace = htmlspecialchars ( $ e -> getTraceAsString ( ) , ENT_QUOTES ) ; $ detail = "<h2>File</h2>" . "<p class=\"text-danger\">$file</p>" . "<p><pre>$fileInfo</pre></p>" . "<h2>Trace</h2>" . "<p class=\"text-danger\">$detail</p>" . "<p><pre>$trace</pre></p>" ; } $ title = htmlspecialchars ( $ message , ENT_QUOTES ) ; $ message = nl2br ( $ title ) ; $ html = '<!DOCTYPE html>' . '<html>' . '<head>' . '<meta name="viewport" content="width=device-width">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' . "<title>$title</title>" . '<style type="text/css">' . 'body { font-size: 14px; color: #333; padding: 15px 20px 20px 20px; }' . 'h1, h2, p, pre { margin: 0; padding: 0; }' . 'body, pre { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif, "\5fae\8f6f\96c5\9ed1", "\5b8b\4f53"; }' . 'h1 { font-size: 36px; }' . 'h2 { font-size: 20px; margin: 20px 0 0; }' . 'pre { font-size:13px; line-height: 1.42857143; }' . '.text-danger { color: #fa5b50 }' . '</style>' . '</head>' . '<body>' . "<h1>$message</h1>" . $ detail . '</body>' . '</html>' ; echo $ html ; }
|
Render exception message
|
60,271
|
protected function displayCliException ( $ e ) { echo 'Exception' , PHP_EOL , $ this -> highlight ( $ e -> getMessage ( ) ) , 'File' , PHP_EOL , $ this -> highlight ( $ e -> getFile ( ) . ' on line ' . $ e -> getLine ( ) ) , 'Trace' , PHP_EOL , $ this -> highlight ( $ e -> getTraceAsString ( ) ) ; if ( $ this -> autoExit ) { exit ( $ this -> getExitCode ( $ e ) ) ; } }
|
Render exception message for CLI
|
60,272
|
public function handleError ( $ code , $ message , $ file , $ line ) { if ( ! ( error_reporting ( ) & $ code ) ) { return ; } restore_error_handler ( ) ; throw new \ ErrorException ( $ message , $ code , 500 , $ file , $ line ) ; }
|
The error handler convert PHP error to exception
|
60,273
|
public function getFileCode ( $ file , $ line , $ range = 20 ) { $ code = file ( $ file ) ; $ half = ( int ) ( $ range / 2 ) ; $ start = $ line - $ half ; 0 > $ start && $ start = 0 ; $ total = count ( $ code ) ; $ end = $ line + $ half ; $ total < $ end && $ end = $ total ; $ len = strlen ( $ end ) ; array_unshift ( $ code , null ) ; $ content = '' ; for ( $ i = $ start ; $ i < $ end ; $ i ++ ) { $ temp = str_pad ( $ i , $ len , 0 , STR_PAD_LEFT ) . ': ' . $ code [ $ i ] ; if ( $ line != $ i ) { $ content .= htmlspecialchars ( $ temp , ENT_QUOTES ) ; } else { $ content .= '<strong class="text-danger">' . htmlspecialchars ( $ temp , ENT_QUOTES ) . '</strong>' ; } } return $ content ; }
|
Get file code in specified range
|
60,274
|
public function end ( ) { $ content = ob_get_clean ( ) ; switch ( $ this -> type ) { case 'append' : $ this -> data [ $ this -> name ] .= $ content ; break ; case 'prepend' : $ this -> data [ $ this -> name ] = $ content . $ this -> data [ $ this -> name ] ; break ; case 'set' : $ this -> data [ $ this -> name ] = $ content ; } return '' ; }
|
Store current block content
|
60,275
|
public function concat ( array $ files ) { $ baseUrl = trim ( $ this -> baseUrl , '/' ) ; $ url = $ this -> concatUrl . '?f=' . implode ( ',' , $ files ) ; return $ baseUrl ? $ url . '&b=' . trim ( $ this -> baseUrl , '/' ) : $ url ; }
|
Returns the Minify concat URL for list of files
|
60,276
|
public function set ( $ route ) { if ( is_string ( $ route ) ) { $ this -> routes [ ] = array ( 'pattern' => $ route ) + $ this -> routeOptions ; } elseif ( is_array ( $ route ) ) { $ this -> routes [ ] = $ route + $ this -> routeOptions ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Expected argument of type string or array, "%s" given' , is_object ( $ route ) ? get_class ( $ route ) : gettype ( $ route ) ) ) ; } return $ this ; }
|
Add one route
|
60,277
|
public function getRoute ( $ id ) { return isset ( $ this -> routes [ $ id ] ) ? $ this -> routes [ $ id ] : false ; }
|
Get the route by id
|
60,278
|
protected function compile ( & $ route ) { if ( $ route [ 'regex' ] ) { return $ route ; } $ regex = preg_replace ( '#[.\+*?[^\]${}=!|:-]#' , '\\\\$0' , $ route [ 'pattern' ] ) ; $ regex = str_replace ( array ( '(' , ')' ) , array ( '(?:' , ')?' ) , $ regex ) ; $ regex = str_replace ( array ( '<' , '>' ) , array ( '(?P<' , '>.+?)' ) , $ regex ) ; if ( $ route [ 'rules' ] ) { $ search = $ replace = array ( ) ; foreach ( $ route [ 'rules' ] as $ key => $ rule ) { $ search [ ] = '<' . $ key . '>.+?' ; $ replace [ ] = '<' . $ key . '>' . $ rule ; } $ regex = str_replace ( $ search , $ replace , $ regex ) ; } $ route [ 'regex' ] = '#^' . $ regex . '$#uUD' ; return $ route ; }
|
Prepare the route pattern to regex
|
60,279
|
public function match ( $ pathInfo , $ method = null ) { $ pathInfo = rtrim ( $ pathInfo , '/' ) ; ! $ pathInfo && $ pathInfo = '/' ; foreach ( $ this -> routes as $ id => $ route ) { if ( false !== ( $ parameters = $ this -> matchRoute ( $ pathInfo , $ method , $ id ) ) ) { return $ parameters ; } } return false ; }
|
Check if there is a route matches the path info and method and return the parameters or return false when not matched
|
60,280
|
public function matchParamSet ( $ pathInfo , $ method = 'GET' ) { $ params = $ this -> match ( $ pathInfo , $ method ) ; $ restParams = $ this -> matchRestParamSet ( $ pathInfo , $ method ) ; return $ params ? array_merge ( array ( $ params ) , $ restParams ) : $ restParams ; }
|
Parse the path info to parameter set
|
60,281
|
protected function matchRoute ( $ pathInfo , $ method , $ id ) { $ route = $ this -> compile ( $ this -> routes [ $ id ] ) ; if ( $ method && $ route [ 'method' ] && ! preg_match ( '#' . $ route [ 'method' ] . '#i' , $ method ) ) { return false ; } if ( ! preg_match ( $ route [ 'regex' ] , $ pathInfo , $ matches ) ) { return false ; } $ parameters = array ( ) ; foreach ( $ matches as $ key => $ parameter ) { if ( is_int ( $ key ) ) { continue ; } $ parameters [ $ key ] = $ parameter ; } $ parameters += $ route [ 'defaults' ] ; preg_match_all ( '#<([a-zA-Z0-9_]++)>#' , $ route [ 'pattern' ] , $ matches ) ; foreach ( $ matches [ 1 ] as $ key ) { if ( ! array_key_exists ( $ key , $ parameters ) ) { $ parameters [ $ key ] = null ; } } return array ( '_id' => $ id ) + $ parameters ; }
|
Check if the route matches the path info and method and return the parameters or return false when not matched
|
60,282
|
protected function parsePath ( $ path ) { $ path = ltrim ( $ path , '/' ) ; foreach ( $ this -> combinedResources as $ resource ) { if ( strpos ( $ path , $ resource ) !== false ) { list ( $ part1 , $ part2 ) = explode ( $ resource , $ path , 2 ) ; $ parts = array_merge ( explode ( '/' , $ part1 ) , array ( $ resource ) , explode ( '/' , $ part2 ) ) ; return array_values ( array_filter ( $ parts ) ) ; } } return explode ( '/' , $ path ) ; }
|
Parse path to resource names actions and ids
|
60,283
|
protected function methodToAction ( $ method , $ collection = false ) { if ( $ method == 'GET' && $ collection ) { $ method = $ method . '-collection' ; } return isset ( $ this -> methodToAction [ $ method ] ) ? $ this -> methodToAction [ $ method ] : $ this -> defaultAction ; }
|
Convert HTTP method to action name
|
60,284
|
public function dispatch ( $ controller , $ action = null , array $ params = array ( ) , $ throwException = true ) { $ notFound = array ( ) ; $ action || $ action = $ this -> defaultAction ; $ classes = $ this -> getControllerClasses ( $ controller ) ; foreach ( $ classes as $ class ) { if ( ! class_exists ( $ class ) ) { $ notFound [ 'controllers' ] [ $ controller ] [ ] = $ class ; continue ; } if ( ! $ this -> isActionAvailable ( $ class , $ action ) ) { $ notFound [ 'actions' ] [ $ action ] [ $ controller ] [ ] = $ class ; continue ; } $ this -> setController ( $ controller ) ; $ this -> setAction ( $ action ) ; $ this -> request -> set ( $ params ) ; try { $ instance = $ this -> getControllerInstance ( $ class ) ; return $ this -> execute ( $ instance , $ action ) ; } catch ( \ RuntimeException $ e ) { if ( $ e -> getCode ( ) === self :: FORWARD ) { return $ this -> response ; } else { throw $ e ; } } } if ( $ throwException ) { throw $ this -> buildException ( $ notFound ) ; } else { return $ notFound ; } }
|
Dispatch by specified controller and action
|
60,285
|
protected function buildException ( array $ notFound ) { $ notFound += array ( 'controllers' => array ( ) , 'actions' => array ( ) ) ; $ message = 'The page you requested was not found' ; if ( $ this -> wei -> isDebug ( ) ) { $ detail = $ this -> request -> get ( 'debug-detail' ) ; foreach ( $ notFound [ 'controllers' ] as $ controller => $ classes ) { $ message .= sprintf ( '%s - controller "%s" not found' , "\n" , $ controller ) ; $ detail && $ message .= sprintf ( ' (class "%s")' , implode ( $ classes , '", "' ) ) ; } foreach ( $ notFound [ 'actions' ] as $ action => $ controllers ) { $ method = $ this -> getActionMethod ( $ action ) ; foreach ( $ controllers as $ controller => $ classes ) { $ message .= sprintf ( '%s - method "%s" not found in controller "%s"' , "\n" , $ method , $ controller ) ; $ detail && $ message .= sprintf ( ' (class "%s")' , implode ( $ classes , '", "' ) ) ; } } } return new \ RuntimeException ( $ message , 404 ) ; }
|
Build 404 exception from notFound array
|
60,286
|
protected function execute ( $ instance , $ action ) { $ app = $ this ; $ wei = $ this -> wei ; $ middleware = $ this -> getMiddleware ( $ instance , $ action ) ; $ callback = function ( ) use ( $ instance , $ action , $ app ) { $ instance -> before ( $ app -> request , $ app -> response ) ; $ method = $ app -> getActionMethod ( $ action ) ; $ response = $ instance -> $ method ( $ app -> request , $ app -> response ) ; $ instance -> after ( $ app -> request , $ response ) ; return $ response ; } ; $ next = function ( ) use ( & $ middleware , & $ next , $ callback , $ wei ) { $ config = array_splice ( $ middleware , 0 , 1 ) ; if ( $ config ) { $ class = key ( $ config ) ; $ service = new $ class ( array ( 'wei' => $ wei ) + $ config [ $ class ] ) ; $ result = $ service ( $ next ) ; } else { $ result = $ callback ( ) ; } return $ result ; } ; return $ this -> handleResponse ( $ next ( ) ) -> send ( ) ; }
|
Execute action with middleware
|
60,287
|
protected function getMiddleware ( $ instance , $ action ) { $ results = array ( ) ; $ middleware = ( array ) $ instance -> getOption ( 'middleware' ) ; foreach ( $ middleware as $ class => $ options ) { if ( ( ! isset ( $ options [ 'only' ] ) || in_array ( $ action , ( array ) $ options [ 'only' ] ) ) && ( ! isset ( $ options [ 'except' ] ) || ! in_array ( $ action , ( array ) $ options [ 'except' ] ) ) ) { $ results [ $ class ] = $ options ; } } return $ results ; }
|
Returns middleware for specified action
|
60,288
|
public function handleResponse ( $ response ) { switch ( true ) { case is_array ( $ response ) : $ content = $ this -> view -> render ( $ this -> getDefaultTemplate ( ) , $ response ) ; return $ this -> response -> setContent ( $ content ) ; case is_scalar ( $ response ) || is_null ( $ response ) : return $ this -> response -> setContent ( $ response ) ; case $ response instanceof Response : return $ response ; default : throw new \ InvalidArgumentException ( sprintf ( 'Expected argument of type array, printable variable or \Wei\Response, "%s" given' , is_object ( $ response ) ? get_class ( $ response ) : gettype ( $ response ) ) ) ; } }
|
Handle the response variable returned by controller action
|
60,289
|
protected function getControllerInstance ( $ class ) { if ( ! isset ( $ this -> controllerInstances [ $ class ] ) ) { $ this -> controllerInstances [ $ class ] = new $ class ( array ( 'wei' => $ this -> wei , 'app' => $ this , ) ) ; } return $ this -> controllerInstances [ $ class ] ; }
|
Get the controller instance if not found return false instead
|
60,290
|
public function isActionAvailable ( $ object , $ action ) { $ method = $ this -> getActionMethod ( $ action ) ; try { $ ref = new \ ReflectionMethod ( $ object , $ method ) ; if ( $ ref -> isPublic ( ) && $ method === $ ref -> name ) { return true ; } else { return false ; } } catch ( \ ReflectionException $ e ) { return false ; } }
|
Check if action name is available
|
60,291
|
public function forward ( $ controller , $ action = null , array $ params = array ( ) ) { $ this -> response = $ this -> dispatch ( $ controller , $ action , $ params ) ; $ this -> preventPreviousDispatch ( ) ; }
|
Forwards to the given controller and action
|
60,292
|
public function validateLuhn ( $ input ) { $ checksum = '' ; foreach ( str_split ( strrev ( $ input ) ) as $ i => $ d ) { $ checksum .= ( $ i % 2 !== 0 ) ? ( $ d * 2 ) : $ d ; } return array_sum ( str_split ( $ checksum ) ) % 10 === 0 ; }
|
Check if the input is valid luhn number
|
60,293
|
public function is ( $ name ) { $ name = strtolower ( $ name ) ; if ( ! array_key_exists ( $ name , $ this -> patterns ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unrecognized browser, OS, mobile or tablet name "%s"' , $ name ) ) ; } if ( preg_match ( '/' . $ this -> patterns [ $ name ] . '/i' , $ this -> userAgent , $ matches ) ) { $ this -> versions [ $ name ] = isset ( $ matches [ 1 ] ) ? $ matches [ 1 ] : false ; return true ; } else { $ this -> versions [ $ name ] = false ; return false ; } }
|
Check if in the specified browser OS or device
|
60,294
|
public function getVersion ( $ name ) { $ name = strtolower ( $ name ) ; if ( ! isset ( $ this -> versions [ $ name ] ) ) { $ this -> is ( $ name ) ; } return $ this -> versions [ $ name ] ; }
|
Returns the version of specified browser OS or device
|
60,295
|
public function isMobile ( ) { $ s = $ this -> server ; if ( isset ( $ s [ 'HTTP_ACCEPT' ] ) && ( strpos ( $ s [ 'HTTP_ACCEPT' ] , 'application/x-obml2d' ) !== false || strpos ( $ s [ 'HTTP_ACCEPT' ] , 'application/vnd.rim.html' ) !== false || strpos ( $ s [ 'HTTP_ACCEPT' ] , 'text/vnd.wap.wml' ) !== false || strpos ( $ s [ 'HTTP_ACCEPT' ] , 'application/vnd.wap.xhtml+xml' ) !== false ) || isset ( $ s [ 'HTTP_X_WAP_PROFILE' ] ) || isset ( $ s [ 'HTTP_X_WAP_CLIENTID' ] ) || isset ( $ s [ 'HTTP_WAP_CONNECTION' ] ) || isset ( $ s [ 'HTTP_PROFILE' ] ) || isset ( $ s [ 'HTTP_X_OPERAMINI_PHONE_UA' ] ) || isset ( $ s [ 'HTTP_X_NOKIA_IPADDRESS' ] ) || isset ( $ s [ 'HTTP_X_NOKIA_GATEWAY_ID' ] ) || isset ( $ s [ 'HTTP_X_ORANGE_ID' ] ) || isset ( $ s [ 'HTTP_X_VODAFONE_3GPDPCONTEXT' ] ) || isset ( $ s [ 'HTTP_X_HUAWEI_USERID' ] ) || isset ( $ s [ 'HTTP_UA_OS' ] ) || isset ( $ s [ 'HTTP_X_MOBILE_GATEWAY' ] ) || isset ( $ s [ 'HTTP_X_ATT_DEVICEID' ] ) || ( isset ( $ s [ 'HTTP_UA_CPU' ] ) && $ s [ 'HTTP_UA_CPU' ] == 'ARM' ) ) { return true ; } return false ; }
|
Check if the device is mobile
|
60,296
|
function getProject ( $ projectShortCode ) { $ findProjectByShortCodeRequest = new findProjectByShortCode ( ) ; $ findProjectByShortCodeRequest -> projectShortCode = $ projectShortCode ; $ project = $ this -> projectService -> findProjectByShortCode ( $ findProjectByShortCodeRequest ) -> return ; return new PDProject ( $ project ) ; }
|
Find project by shortcode
|
60,297
|
function getProjects ( ) { $ getUserProjectsRequest = new getUserProjects ( ) ; $ getUserProjectsRequest -> isSubProjectIncluded = TRUE ; $ projects = $ this -> projectService -> getUserProjects ( $ getUserProjectsRequest ) -> return ; $ i = 0 ; $ proj_arr = array ( ) ; if ( is_array ( $ projects ) ) { foreach ( $ projects as $ project ) { $ pdproject = new PDProject ( $ project ) ; $ proj_arr [ $ i ++ ] = $ pdproject ; } } else { $ fullProject = $ this -> getProject ( $ projects -> projectInfo -> shortCode ) ; $ proj_arr [ 0 ] = $ fullProject ; } return $ proj_arr ; }
|
Get all user projects
|
60,298
|
function getSubmissionTicket ( ) { if ( isset ( $ this -> submission ) && isset ( $ this -> submission -> ticket ) ) { return $ this -> submission -> ticket ; } else { throw new Exception ( "Submission not initialized" ) ; } }
|
Get Submission ticket if a submission has been initialized .
|
60,299
|
function getSubmissionName ( $ submissionTicket ) { $ submission = $ this -> getSubmission ( $ submissionTicket ) ; if ( isset ( $ submission ) ) { return $ submission -> submissionInfo -> name ; } else { throw new Exception ( "Invalid submission ticket" ) ; } }
|
Get Submission name for specified ticket .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.