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 -> e... | 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 = $ d... | 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'... | 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... | 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' , $ s... | 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 se... | 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 .= ' ' . ... | 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 =... | 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 \ InvalidArgu... | 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 [ $ fol... | 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 -> loadFro... | 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... | 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 , ... | 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 $ u... | 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 nu... | 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_o... | 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 ( da... | 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 ( ) , 'tr... | 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 ... | 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 ) ; }... | 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 = ar... | 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 { r... | 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 \ RuntimeExcept... | 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 ( '", "' , $ thi... | 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 ( )... | 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 ( ! $ t... | 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 } )... | 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 -> autoEx... | 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 ( $... | 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 ] = $ co... | 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 ... | 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... | 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 ) ) { ... | 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 ... | 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 ) ... | 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' ... | 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 -> getActi... | 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 ( $... | 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 -> res... | 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 ) { retu... | 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 -> u... | 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 ( ... | 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 (... | 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 ( $ proj... | 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.