idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
5,900
public function getDataCellContent ( $ row ) { $ data = $ this -> grid -> dataProvider -> data [ $ row ] ; if ( $ this -> urlExpression !== null ) $ url = $ this -> evaluateExpression ( $ this -> urlExpression , array ( 'data' => $ data , 'row' => $ row ) ) ; else $ url = $ this -> url ; if ( $ this -> labelExpression !== null ) $ label = $ this -> evaluateExpression ( $ this -> labelExpression , array ( 'data' => $ data , 'row' => $ row ) ) ; else $ label = $ this -> label ; $ options = $ this -> linkHtmlOptions ; if ( is_string ( $ this -> imageUrl ) ) return CHtml :: link ( CHtml :: image ( $ this -> imageUrl , $ label ) , $ url , $ options ) ; else return CHtml :: link ( $ label , $ url , $ options ) ; }
Returns the data cell content . This method renders a hyperlink in the data cell .
5,901
public function renderKeys ( ) { echo CHtml :: openTag ( 'div' , array ( 'class' => 'keys' , 'style' => 'display:none' , 'title' => Yii :: app ( ) -> getRequest ( ) -> getUrl ( ) , ) ) ; foreach ( $ this -> dataProvider -> getKeys ( ) as $ key ) echo "<span>" . CHtml :: encode ( $ key ) . "</span>" ; echo "</div>\n" ; }
Renders the key values of the data in a hidden tag .
5,902
public function renderSummary ( ) { if ( ( $ count = $ this -> dataProvider -> getItemCount ( ) ) <= 0 ) return ; echo CHtml :: openTag ( $ this -> summaryTagName , array ( 'class' => $ this -> summaryCssClass ) ) ; if ( $ this -> enablePagination ) { $ pagination = $ this -> dataProvider -> getPagination ( ) ; $ total = $ this -> dataProvider -> getTotalItemCount ( ) ; $ start = $ pagination -> currentPage * $ pagination -> pageSize + 1 ; $ end = $ start + $ count - 1 ; if ( $ end > $ total ) { $ end = $ total ; $ start = $ end - $ count + 1 ; } if ( ( $ summaryText = $ this -> summaryText ) === null ) $ summaryText = Yii :: t ( 'zii' , 'Displaying {start}-{end} of 1 result.|Displaying {start}-{end} of {count} results.' , $ total ) ; echo strtr ( $ summaryText , array ( '{start}' => $ start , '{end}' => $ end , '{count}' => $ total , '{page}' => $ pagination -> currentPage + 1 , '{pages}' => $ pagination -> pageCount , ) ) ; } else { if ( ( $ summaryText = $ this -> summaryText ) === null ) $ summaryText = Yii :: t ( 'zii' , 'Total 1 result.|Total {count} results.' , $ count ) ; echo strtr ( $ summaryText , array ( '{count}' => $ count , '{start}' => 1 , '{end}' => $ count , '{page}' => 1 , '{pages}' => 1 , ) ) ; } echo CHtml :: closeTag ( $ this -> summaryTagName ) ; }
Renders the summary text .
5,903
public function purify ( $ content ) { if ( is_array ( $ content ) ) $ content = array_map ( array ( $ this , 'purify' ) , $ content ) ; else $ content = $ this -> getPurifier ( ) -> purify ( $ content ) ; return $ content ; }
Purifies the HTML content by removing malicious code .
5,904
protected function createNewHtmlPurifierInstance ( ) { $ this -> _purifier = new HTMLPurifier ( $ this -> getOptions ( ) ) ; $ this -> _purifier -> config -> set ( 'Cache.SerializerPath' , Yii :: app ( ) -> getRuntimePath ( ) ) ; return $ this -> _purifier ; }
Create a new HTML Purifier instance .
5,905
public static function getInstancesByName ( $ name ) { if ( null === self :: $ _files ) self :: prefetchFiles ( ) ; $ len = strlen ( $ name ) ; $ results = array ( ) ; foreach ( array_keys ( self :: $ _files ) as $ key ) if ( 0 === strncmp ( $ key , $ name . '[' , $ len + 1 ) && self :: $ _files [ $ key ] -> getError ( ) != UPLOAD_ERR_NO_FILE ) $ results [ ] = self :: $ _files [ $ key ] ; return $ results ; }
Returns an array of instances starting with specified array name .
5,906
protected function setPermissions ( $ targetDir ) { @ chmod ( $ targetDir . '/assets' , 0777 ) ; @ chmod ( $ targetDir . '/protected/runtime' , 0777 ) ; @ chmod ( $ targetDir . '/protected/data' , 0777 ) ; @ chmod ( $ targetDir . '/protected/data/testdrive.db' , 0777 ) ; @ chmod ( $ targetDir . '/protected/yiic' , 0755 ) ; }
Adjusts created application file and directory permissions
5,907
protected function addFileModificationCallbacks ( & $ fileList ) { $ fileList [ 'index.php' ] [ 'callback' ] = array ( $ this , 'generateIndex' ) ; $ fileList [ 'index-test.php' ] [ 'callback' ] = array ( $ this , 'generateIndex' ) ; $ fileList [ 'protected/tests/bootstrap.php' ] [ 'callback' ] = array ( $ this , 'generateTestBoostrap' ) ; $ fileList [ 'protected/yiic.php' ] [ 'callback' ] = array ( $ this , 'generateYiic' ) ; }
Adds callbacks that will modify source files
5,908
public function generateIndex ( $ source , $ params ) { $ content = file_get_contents ( $ source ) ; $ yii = realpath ( dirname ( __FILE__ ) . '/../../yii.php' ) ; $ yii = $ this -> getRelativePath ( $ yii , $ this -> _rootPath . DIRECTORY_SEPARATOR . 'index.php' ) ; $ yii = str_replace ( '\\' , '\\\\' , $ yii ) ; return preg_replace ( '/\$yii\s*=(.*?);/' , "\$yii=$yii;" , $ content ) ; }
Inserts path to framework s yii . php into application s index . php
5,909
public function generateYiic ( $ source , $ params ) { $ content = file_get_contents ( $ source ) ; $ yiic = realpath ( dirname ( __FILE__ ) . '/../../yiic.php' ) ; $ yiic = $ this -> getRelativePath ( $ yiic , $ this -> _rootPath . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'yiic.php' ) ; $ yiic = str_replace ( '\\' , '\\\\' , $ yiic ) ; return preg_replace ( '/\$yiic\s*=(.*?);/' , "\$yiic=$yiic;" , $ content ) ; }
Inserts path to framework s yiic . php into application s yiic . php
5,910
public function processLogs ( $ logs ) { $ app = Yii :: app ( ) ; if ( ! ( $ app instanceof CWebApplication ) || $ app -> getRequest ( ) -> getIsAjaxRequest ( ) ) return ; if ( $ this -> getReport ( ) === 'summary' ) $ this -> displaySummary ( $ logs ) ; else $ this -> displayCallstack ( $ logs ) ; }
Displays the log messages .
5,911
protected function displayCallstack ( $ logs ) { $ stack = array ( ) ; $ results = array ( ) ; $ n = 0 ; foreach ( $ logs as $ log ) { if ( $ log [ 1 ] !== CLogger :: LEVEL_PROFILE ) continue ; $ message = $ log [ 0 ] ; if ( ! strncasecmp ( $ message , 'begin:' , 6 ) ) { $ log [ 0 ] = substr ( $ message , 6 ) ; $ log [ 4 ] = $ n ; $ stack [ ] = $ log ; $ n ++ ; } elseif ( ! strncasecmp ( $ message , 'end:' , 4 ) ) { $ token = substr ( $ message , 4 ) ; if ( ( $ last = array_pop ( $ stack ) ) !== null && $ last [ 0 ] === $ token ) { $ delta = $ log [ 3 ] - $ last [ 3 ] ; $ results [ $ last [ 4 ] ] = array ( $ token , $ delta , count ( $ stack ) ) ; } else throw new CException ( Yii :: t ( 'yii' , 'CProfileLogRoute found a mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.' , array ( '{token}' => $ token ) ) ) ; } } $ now = microtime ( true ) ; while ( ( $ last = array_pop ( $ stack ) ) !== null ) $ results [ $ last [ 4 ] ] = array ( $ last [ 0 ] , $ now - $ last [ 3 ] , count ( $ stack ) ) ; ksort ( $ results ) ; $ this -> render ( 'profile-callstack' , $ results ) ; }
Displays the callstack of the profiling procedures for display .
5,912
protected function displaySummary ( $ logs ) { $ stack = array ( ) ; $ results = array ( ) ; foreach ( $ logs as $ log ) { if ( $ log [ 1 ] !== CLogger :: LEVEL_PROFILE ) continue ; $ message = $ log [ 0 ] ; if ( ! strncasecmp ( $ message , 'begin:' , 6 ) ) { $ log [ 0 ] = substr ( $ message , 6 ) ; $ stack [ ] = $ log ; } elseif ( ! strncasecmp ( $ message , 'end:' , 4 ) ) { $ token = substr ( $ message , 4 ) ; if ( ( $ last = array_pop ( $ stack ) ) !== null && $ last [ 0 ] === $ token ) { $ delta = $ log [ 3 ] - $ last [ 3 ] ; if ( ! $ this -> groupByToken ) $ token = $ log [ 2 ] ; if ( isset ( $ results [ $ token ] ) ) $ results [ $ token ] = $ this -> aggregateResult ( $ results [ $ token ] , $ delta ) ; else $ results [ $ token ] = array ( $ token , 1 , $ delta , $ delta , $ delta ) ; } else throw new CException ( Yii :: t ( 'yii' , 'CProfileLogRoute found a mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.' , array ( '{token}' => $ token ) ) ) ; } } $ now = microtime ( true ) ; while ( ( $ last = array_pop ( $ stack ) ) !== null ) { $ delta = $ now - $ last [ 3 ] ; $ token = $ this -> groupByToken ? $ last [ 0 ] : $ last [ 2 ] ; if ( isset ( $ results [ $ token ] ) ) $ results [ $ token ] = $ this -> aggregateResult ( $ results [ $ token ] , $ delta ) ; else $ results [ $ token ] = array ( $ token , 1 , $ delta , $ delta , $ delta ) ; } $ entries = array_values ( $ results ) ; usort ( $ entries , array ( $ this , 'resultEntryCompare' ) ) ; $ this -> render ( 'profile-summary' , $ entries ) ; }
Displays the summary report of the profiling result .
5,913
protected function aggregateResult ( $ result , $ delta ) { list ( $ token , $ calls , $ min , $ max , $ total ) = $ result ; if ( $ delta < $ min ) $ min = $ delta ; elseif ( $ delta > $ max ) $ max = $ delta ; $ calls ++ ; $ total += $ delta ; return array ( $ token , $ calls , $ min , $ max , $ total ) ; }
Aggregates the report result .
5,914
public function delete ( ) { if ( ! $ this -> getIsNewRecord ( ) ) { Yii :: trace ( get_class ( $ this ) . '.delete()' , 'system.db.ar.CActiveRecord' ) ; if ( $ this -> beforeDelete ( ) ) { $ result = $ this -> deleteByPk ( $ this -> getPrimaryKey ( ) ) > 0 ; $ this -> afterDelete ( ) ; return $ result ; } else return false ; } else throw new CDbException ( Yii :: t ( 'yii' , 'The active record cannot be deleted because it is new.' ) ) ; }
Deletes the row corresponding to this active record .
5,915
public function find ( $ condition = '' , $ params = array ( ) ) { Yii :: trace ( get_class ( $ this ) . '.find()' , 'system.db.ar.CActiveRecord' ) ; $ criteria = $ this -> getCommandBuilder ( ) -> createCriteria ( $ condition , $ params ) ; return $ this -> query ( $ criteria ) ; }
Finds a single active record with the specified condition .
5,916
public function findBySql ( $ sql , $ params = array ( ) ) { Yii :: trace ( get_class ( $ this ) . '.findBySql()' , 'system.db.ar.CActiveRecord' ) ; $ this -> beforeFind ( ) ; if ( ( $ criteria = $ this -> getDbCriteria ( false ) ) !== null && ! empty ( $ criteria -> with ) ) { $ this -> resetScope ( false ) ; $ finder = $ this -> getActiveFinder ( $ criteria -> with ) ; return $ finder -> findBySql ( $ sql , $ params ) ; } else { $ command = $ this -> getCommandBuilder ( ) -> createSqlCommand ( $ sql , $ params ) ; return $ this -> populateRecord ( $ command -> queryRow ( ) ) ; } }
Finds a single active record with the specified SQL statement .
5,917
public function findAllBySql ( $ sql , $ params = array ( ) ) { Yii :: trace ( get_class ( $ this ) . '.findAllBySql()' , 'system.db.ar.CActiveRecord' ) ; $ this -> beforeFind ( ) ; if ( ( $ criteria = $ this -> getDbCriteria ( false ) ) !== null && ! empty ( $ criteria -> with ) ) { $ this -> resetScope ( false ) ; $ finder = $ this -> getActiveFinder ( $ criteria -> with ) ; return $ finder -> findAllBySql ( $ sql , $ params ) ; } else { $ command = $ this -> getCommandBuilder ( ) -> createSqlCommand ( $ sql , $ params ) ; return $ this -> populateRecords ( $ command -> queryAll ( ) ) ; } }
Finds all active records using the specified SQL statement .
5,918
protected function loadPage ( ) { $ this -> _dataProvider -> getPagination ( ) -> setCurrentPage ( $ this -> _currentPage ) ; return $ this -> _items = $ this -> dataProvider -> getData ( true ) ; }
Loads a page of items
5,919
public function key ( ) { $ pageSize = $ this -> _dataProvider -> getPagination ( ) -> getPageSize ( ) ; return $ this -> _currentPage * $ pageSize + $ this -> _currentIndex ; }
Gets the key of the current item . This method is required by the Iterator interface .
5,920
public function next ( ) { $ pageSize = $ this -> _dataProvider -> getPagination ( ) -> getPageSize ( ) ; $ this -> _currentIndex ++ ; if ( $ this -> _currentIndex >= $ pageSize ) { $ this -> _currentPage ++ ; $ this -> _currentIndex = 0 ; $ this -> loadPage ( ) ; } }
Moves the pointer to the next item in the list . This method is required by the Iterator interface .
5,921
protected function createCacheTable ( $ db , $ tableName ) { $ driver = $ db -> getDriverName ( ) ; if ( $ driver === 'mysql' ) $ blob = 'LONGBLOB' ; elseif ( $ driver === 'pgsql' ) $ blob = 'BYTEA' ; else $ blob = 'BLOB' ; $ sql = <<<EODCREATE TABLE $tableName( id CHAR(128) PRIMARY KEY, expire INTEGER, value $blob)EOD ; $ db -> createCommand ( $ sql ) -> execute ( ) ; }
Creates the cache DB table .
5,922
public static function isLeapYear ( $ year ) { $ year = self :: digitCheck ( $ year ) ; if ( $ year % 4 != 0 ) return false ; if ( $ year % 400 == 0 ) return true ; elseif ( $ year > 1582 && $ year % 100 == 0 ) return false ; return true ; }
Checks for leap year returns true if it is . No 2 - digit year check . Also handles julian calendar correctly .
5,923
protected static function digitCheck ( $ y ) { if ( $ y < 100 ) { $ yr = ( integer ) date ( "Y" ) ; $ century = ( integer ) ( $ yr / 100 ) ; if ( $ yr % 100 > 50 ) { $ c1 = $ century + 1 ; $ c0 = $ century ; } else { $ c1 = $ century ; $ c0 = $ century - 1 ; } $ c1 *= 100 ; if ( ( $ y + $ c1 ) < $ yr + 30 ) $ y = $ y + $ c1 ; else $ y = $ y + $ c0 * 100 ; } return $ y ; }
Fix 2 - digit years . Works for any century . Assumes that if 2 - digit is more than 30 years in future then previous century .
5,924
public static function isValidTime ( $ h , $ m , $ s , $ hs24 = true ) { if ( $ hs24 && ( $ h < 0 || $ h > 23 ) || ! $ hs24 && ( $ h < 1 || $ h > 12 ) ) return false ; if ( $ m > 59 || $ m < 0 ) return false ; if ( $ s > 59 || $ s < 0 ) return false ; return true ; }
Checks to see if the hour minute and second are valid .
5,925
protected function getSortingFieldValue ( $ data , $ fields ) { if ( is_object ( $ data ) ) { foreach ( $ fields as $ field ) $ data = isset ( $ data -> $ field ) ? $ data -> $ field : null ; } else { foreach ( $ fields as $ field ) $ data = isset ( $ data [ $ field ] ) ? $ data [ $ field ] : null ; } return $ this -> caseSensitiveSort ? $ data : mb_strtolower ( $ data , Yii :: app ( ) -> charset ) ; }
Get field for sorting using dot like delimiter in query .
5,926
protected function getSortDirections ( $ order ) { $ segs = explode ( ',' , $ order ) ; $ directions = array ( ) ; foreach ( $ segs as $ seg ) { if ( preg_match ( '/(.*?)(\s+(desc|asc))?$/i' , trim ( $ seg ) , $ matches ) ) $ directions [ $ matches [ 1 ] ] = isset ( $ matches [ 3 ] ) && ! strcasecmp ( $ matches [ 3 ] , 'desc' ) ; else $ directions [ trim ( $ seg ) ] = false ; } return $ directions ; }
Converts the ORDER BY clause into an array representing the sorting directions .
5,927
public function actionError ( ) { if ( $ error = Yii :: app ( ) -> errorHandler -> error ) { if ( Yii :: app ( ) -> request -> isAjaxRequest ) echo $ error [ 'message' ] ; else $ this -> render ( 'error' , $ error ) ; } }
This is the action to handle external exceptions .
5,928
public function actionContact ( ) { $ model = new ContactForm ; if ( isset ( $ _POST [ 'ContactForm' ] ) ) { $ model -> attributes = $ _POST [ 'ContactForm' ] ; if ( $ model -> validate ( ) ) { $ name = '=?UTF-8?B?' . base64_encode ( $ model -> name ) . '?=' ; $ subject = '=?UTF-8?B?' . base64_encode ( $ model -> subject ) . '?=' ; $ headers = "From: $name <{$model->email}>\r\n" . "Reply-To: {$model->email}\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/plain; charset=UTF-8" ; mail ( Yii :: app ( ) -> params [ 'adminEmail' ] , $ subject , $ model -> body , $ headers ) ; Yii :: app ( ) -> user -> setFlash ( 'contact' , 'Thank you for contacting us. We will respond to you as soon as possible.' ) ; $ this -> refresh ( ) ; } } $ this -> render ( 'contact' , array ( 'model' => $ model ) ) ; }
Displays the contact page
5,929
protected function resolveView ( $ viewPath ) { if ( preg_match ( '/^\w[\w\.\-]*$/' , $ viewPath ) ) { $ view = strtr ( $ viewPath , '.' , '/' ) ; if ( ! empty ( $ this -> basePath ) ) $ view = $ this -> basePath . '/' . $ view ; if ( $ this -> getController ( ) -> getViewFile ( $ view ) !== false ) { $ this -> view = $ view ; return ; } } throw new CHttpException ( 404 , Yii :: t ( 'yii' , 'The requested view "{name}" was not found.' , array ( '{name}' => $ viewPath ) ) ) ; }
Resolves the user - specified view into a valid view name .
5,930
public function filter ( & $ logs ) { if ( ! empty ( $ logs ) ) { if ( ( $ message = $ this -> getContext ( ) ) !== '' ) array_unshift ( $ logs , array ( $ message , CLogger :: LEVEL_INFO , 'application' , YII_BEGIN_TIME ) ) ; $ this -> format ( $ logs ) ; } return $ logs ; }
Filters the given log messages . This is the main method of CLogFilter . It processes the log messages by adding context information etc .
5,931
protected function processLogs ( $ logs ) { $ command = $ this -> getDbConnection ( ) -> createCommand ( ) ; foreach ( $ logs as $ log ) { $ command -> insert ( $ this -> logTableName , array ( 'level' => $ log [ 1 ] , 'category' => $ log [ 2 ] , 'logtime' => ( int ) $ log [ 3 ] , 'message' => $ log [ 0 ] , ) ) ; } }
Stores log messages into database .
5,932
public function getPages ( ) { if ( $ this -> _pages === null ) $ this -> _pages = $ this -> createPages ( ) ; return $ this -> _pages ; }
Returns the pagination information used by this pager .
5,933
protected function loadTable ( $ name ) { $ table = new CCubridTableSchema ; $ this -> resolveTableNames ( $ table , $ name ) ; if ( $ this -> findColumns ( $ table ) ) { $ this -> findPrimaryKeys ( $ table ) ; $ this -> findConstraints ( $ table ) ; return $ table ; } else return null ; }
Creates a table instance representing the metadata for the named table .
5,934
protected function findPrimaryKeys ( $ table ) { $ pks = $ this -> getDbConnection ( ) -> getPdoInstance ( ) -> cubrid_schema ( PDO :: CUBRID_SCH_PRIMARY_KEY , $ table -> name ) ; foreach ( $ pks as $ pk ) { $ c = $ table -> columns [ $ pk [ 'ATTR_NAME' ] ] ; $ c -> isPrimaryKey = true ; if ( $ table -> primaryKey === null ) $ table -> primaryKey = $ c -> name ; elseif ( is_string ( $ table -> primaryKey ) ) $ table -> primaryKey = array ( $ table -> primaryKey , $ c -> name ) ; else $ table -> primaryKey [ ] = $ c -> name ; if ( $ c -> autoIncrement ) $ table -> sequenceName = '' ; } }
Collects the primary key column details for the given table .
5,935
public function renderInput ( ) { if ( isset ( self :: $ coreTypes [ $ this -> type ] ) ) { $ method = self :: $ coreTypes [ $ this -> type ] ; if ( strpos ( $ method , 'List' ) !== false ) return CHtml :: $ method ( $ this -> getParent ( ) -> getModel ( ) , $ this -> name , $ this -> items , $ this -> attributes ) ; else return CHtml :: $ method ( $ this -> getParent ( ) -> getModel ( ) , $ this -> name , $ this -> attributes ) ; } else { $ attributes = $ this -> attributes ; $ attributes [ 'model' ] = $ this -> getParent ( ) -> getModel ( ) ; $ attributes [ 'attribute' ] = $ this -> name ; ob_start ( ) ; $ this -> getParent ( ) -> getOwner ( ) -> widget ( $ this -> type , $ attributes ) ; return ob_get_clean ( ) ; } }
Renders the input field . The default implementation returns the result of the appropriate CHtml method or the widget .
5,936
public static function hashPassword ( $ password , $ cost = 13 ) { self :: checkBlowfish ( ) ; $ salt = self :: generateSalt ( $ cost ) ; $ hash = crypt ( $ password , $ salt ) ; if ( ! is_string ( $ hash ) || ( function_exists ( 'mb_strlen' ) ? mb_strlen ( $ hash , '8bit' ) : strlen ( $ hash ) ) < 32 ) throw new CException ( Yii :: t ( 'yii' , 'Internal error while generating hash.' ) ) ; return $ hash ; }
Generate a secure hash from a password and a random salt .
5,937
public static function verifyPassword ( $ password , $ hash ) { self :: checkBlowfish ( ) ; if ( ! is_string ( $ password ) || $ password === '' ) return false ; if ( ! $ password || ! preg_match ( '{^\$2[axy]\$(\d\d)\$[\./0-9A-Za-z]{22}}' , $ hash , $ matches ) || $ matches [ 1 ] < 4 || $ matches [ 1 ] > 31 ) return false ; $ test = crypt ( $ password , $ hash ) ; if ( ! is_string ( $ test ) || strlen ( $ test ) < 32 ) return false ; return self :: same ( $ test , $ hash ) ; }
Verify a password against a hash .
5,938
public static function same ( $ a , $ b ) { if ( ! is_string ( $ a ) || ! is_string ( $ b ) ) return false ; $ mb = function_exists ( 'mb_strlen' ) ; $ length = $ mb ? mb_strlen ( $ a , '8bit' ) : strlen ( $ a ) ; if ( $ length !== ( $ mb ? mb_strlen ( $ b , '8bit' ) : strlen ( $ b ) ) ) return false ; $ check = 0 ; for ( $ i = 0 ; $ i < $ length ; $ i += 1 ) $ check |= ( ord ( $ a [ $ i ] ) ^ ord ( $ b [ $ i ] ) ) ; return $ check === 0 ; }
Check for sameness of two strings using an algorithm with timing independent of the string values if the subject strings are of equal length .
5,939
function _getLines ( & $ text_lines , & $ line_no , $ end = false ) { if ( ! empty ( $ end ) ) { $ lines = array ( ) ; while ( $ line_no <= $ end ) { array_push ( $ lines , array_shift ( $ text_lines ) ) ; $ line_no ++ ; } } else { $ lines = array ( array_shift ( $ text_lines ) ) ; $ line_no ++ ; } return $ lines ; }
Get lines from either the old or new text
5,940
public function init ( ) { $ this -> _cache = Yii :: app ( ) -> getComponent ( $ this -> cacheID ) ; if ( ! ( $ this -> _cache instanceof ICache ) ) throw new CException ( Yii :: t ( 'yii' , 'CCacheHttpSession.cacheID is invalid. Please make sure "{id}" refers to a valid cache application component.' , array ( '{id}' => $ this -> cacheID ) ) ) ; parent :: init ( ) ; }
Initializes the application component . This method overrides the parent implementation by checking if cache is available .
5,941
protected function checkContentCache ( ) { if ( ( empty ( $ this -> requestTypes ) || in_array ( Yii :: app ( ) -> getRequest ( ) -> getRequestType ( ) , $ this -> requestTypes ) ) && ( $ this -> _cache = $ this -> getCache ( ) ) !== null ) { if ( $ this -> duration > 0 && ( $ data = $ this -> _cache -> get ( $ this -> getCacheKey ( ) ) ) !== false ) { $ this -> _content = $ data [ 0 ] ; $ this -> _actions = $ data [ 1 ] ; return true ; } if ( $ this -> duration == 0 ) $ this -> _cache -> delete ( $ this -> getCacheKey ( ) ) ; if ( $ this -> duration <= 0 ) $ this -> _cache = null ; } return false ; }
Looks for content in cache .
5,942
protected function replayActions ( ) { if ( empty ( $ this -> _actions ) ) return ; $ controller = $ this -> getController ( ) ; $ cs = Yii :: app ( ) -> getClientScript ( ) ; foreach ( $ this -> _actions as $ action ) { if ( $ action [ 0 ] === 'clientScript' ) $ object = $ cs ; elseif ( $ action [ 0 ] === '' ) $ object = $ controller ; else $ object = $ controller -> { $ action [ 0 ] } ; if ( method_exists ( $ object , $ action [ 1 ] ) ) call_user_func_array ( array ( $ object , $ action [ 1 ] ) , $ action [ 2 ] ) ; elseif ( $ action [ 0 ] === '' && function_exists ( $ action [ 1 ] ) ) call_user_func_array ( $ action [ 1 ] , $ action [ 2 ] ) ; else throw new CException ( Yii :: t ( 'yii' , 'Unable to replay the action "{object}.{method}". The method does not exist.' , array ( 'object' => $ action [ 0 ] , 'method' => $ action [ 1 ] ) ) ) ; } }
Replays the recorded method calls .
5,943
protected function createSessionTable ( $ db , $ tableName ) { switch ( $ db -> getDriverName ( ) ) { case 'mysql' : $ blob = 'LONGBLOB' ; break ; case 'pgsql' : $ blob = 'BYTEA' ; break ; case 'sqlsrv' : case 'mssql' : case 'dblib' : $ blob = 'VARBINARY(MAX)' ; break ; default : $ blob = 'BLOB' ; break ; } $ db -> createCommand ( ) -> createTable ( $ tableName , array ( 'id' => 'CHAR(32) PRIMARY KEY' , 'expire' => 'integer' , 'data' => $ blob , ) ) ; }
Creates the session DB table .
5,944
public function openSession ( $ savePath , $ sessionName ) { if ( $ this -> autoCreateSessionTable ) { $ db = $ this -> getDbConnection ( ) ; $ db -> setActive ( true ) ; try { $ db -> createCommand ( ) -> delete ( $ this -> sessionTableName , 'expire<:expire' , array ( ':expire' => time ( ) ) ) ; } catch ( Exception $ e ) { $ this -> createSessionTable ( $ db , $ this -> sessionTableName ) ; } } return true ; }
Session open handler . Do not call this method directly .
5,945
protected function getSessionKey ( ) { return self :: SESSION_VAR_PREFIX . Yii :: app ( ) -> getId ( ) . '.' . $ this -> getController ( ) -> getUniqueId ( ) . '.' . $ this -> getId ( ) ; }
Returns the session variable name used to store verification code .
5,946
protected function checkFiles ( $ translatedFilePath = null , $ sourceFilePath = null ) { $ errors = array ( ) ; if ( $ translatedFilePath !== null && ! file_exists ( $ translatedFilePath ) ) { $ errors [ ] = 'Translation does not exist.' ; } if ( $ sourceFilePath !== null && ! file_exists ( $ sourceFilePath ) ) { $ errors [ ] = 'Source does not exist.' ; } return $ errors ; }
Checks for files existence
5,947
protected function highlightDiff ( $ diff ) { $ lines = explode ( "\n" , $ diff ) ; foreach ( $ lines as $ key => $ val ) { if ( mb_substr ( $ val , 0 , 1 , 'utf-8' ) === '@' ) { $ lines [ $ key ] = '<span class="info">' . CHtml :: encode ( $ val ) . '</span>' ; } else if ( mb_substr ( $ val , 0 , 1 , 'utf-8' ) === '+' ) { $ lines [ $ key ] = '<ins>' . CHtml :: encode ( $ val ) . '</ins>' ; } else if ( mb_substr ( $ val , 0 , 1 , 'utf-8' ) === '-' ) { $ lines [ $ key ] = '<del>' . CHtml :: encode ( $ val ) . '</del>' ; } else { $ lines [ $ key ] = CHtml :: encode ( $ val ) ; } } return implode ( "\n" , $ lines ) ; }
Adds all necessary HTML tags and classes to diff output
5,948
public function configure ( $ config ) { if ( is_string ( $ config ) ) $ config = require ( Yii :: getPathOfAlias ( $ config ) . '.php' ) ; if ( is_array ( $ config ) ) { foreach ( $ config as $ name => $ value ) $ this -> $ name = $ value ; } }
Configures this object with property initial values .
5,949
public function init ( ) { parent :: init ( ) ; if ( $ this -> authFile === null ) $ this -> authFile = Yii :: getPathOfAlias ( 'application.data.auth' ) . '.php' ; $ this -> load ( ) ; }
Initializes the application component . This method overrides parent implementation by loading the authorization data from PHP script .
5,950
public function save ( ) { $ items = array ( ) ; foreach ( $ this -> _items as $ name => $ item ) { $ items [ $ name ] = array ( 'type' => $ item -> getType ( ) , 'description' => $ item -> getDescription ( ) , 'bizRule' => $ item -> getBizRule ( ) , 'data' => $ item -> getData ( ) , ) ; if ( isset ( $ this -> _children [ $ name ] ) ) { foreach ( $ this -> _children [ $ name ] as $ child ) $ items [ $ name ] [ 'children' ] [ ] = $ child -> getName ( ) ; } } foreach ( $ this -> _assignments as $ userId => $ assignments ) { foreach ( $ assignments as $ name => $ assignment ) { if ( isset ( $ items [ $ name ] ) ) { $ items [ $ name ] [ 'assignments' ] [ $ userId ] = array ( 'bizRule' => $ assignment -> getBizRule ( ) , 'data' => $ assignment -> getData ( ) , ) ; } } } $ this -> saveToFile ( $ items , $ this -> authFile ) ; }
Saves authorization data into persistent storage . If any change is made to the authorization data please make sure you call this method to save the changed data into persistent storage .
5,951
public function load ( ) { $ this -> clearAll ( ) ; $ items = $ this -> loadFromFile ( $ this -> authFile ) ; foreach ( $ items as $ name => $ item ) $ this -> _items [ $ name ] = new CAuthItem ( $ this , $ name , $ item [ 'type' ] , $ item [ 'description' ] , $ item [ 'bizRule' ] , $ item [ 'data' ] ) ; foreach ( $ items as $ name => $ item ) { if ( isset ( $ item [ 'children' ] ) ) { foreach ( $ item [ 'children' ] as $ childName ) { if ( isset ( $ this -> _items [ $ childName ] ) ) $ this -> _children [ $ name ] [ $ childName ] = $ this -> _items [ $ childName ] ; } } if ( isset ( $ item [ 'assignments' ] ) ) { foreach ( $ item [ 'assignments' ] as $ userId => $ assignment ) { $ this -> _assignments [ $ userId ] [ $ name ] = new CAuthAssignment ( $ this , $ name , $ userId , $ assignment [ 'bizRule' ] , $ assignment [ 'data' ] ) ; } } } }
Loads authorization data .
5,952
public function beforeWebMethod ( $ service ) { $ safeMethods = array ( 'login' , 'getContacts' , ) ; $ pattern = '/^(' . implode ( '|' , $ safeMethods ) . ')$/i' ; if ( ! Yii :: app ( ) -> user -> isGuest || preg_match ( $ pattern , $ service -> methodName ) ) return true ; else throw new CException ( 'Login required.' ) ; }
This method is required by IWebServiceProvider . It makes sure the user is logged in before making changes to data .
5,953
public function saveContact ( $ contact ) { if ( $ contact -> id > 0 ) { $ contact -> isNewRecord = false ; if ( ( $ oldContact = Contact :: model ( ) -> findByPk ( $ contact -> id ) ) !== null ) { $ oldContact -> attributes = $ contact -> attributes ; return $ oldContact -> save ( ) ; } else return false ; } else { $ contact -> isNewRecord = true ; $ contact -> id = null ; return $ contact -> save ( ) ; } }
Updates or inserts a contact . If the ID is null an insertion will be performed ; Otherwise it updates the existing one .
5,954
function getParams ( ) { $ params = array ( ) ; foreach ( get_object_vars ( $ this ) as $ k => $ v ) { if ( $ k [ 0 ] == '_' ) { $ params [ substr ( $ k , 1 ) ] = $ v ; } } return $ params ; }
Get any renderer parameters .
5,955
function render ( $ diff ) { $ xi = $ yi = 1 ; $ block = false ; $ context = array ( ) ; $ nlead = $ this -> _leading_context_lines ; $ ntrail = $ this -> _trailing_context_lines ; $ output = $ this -> _startDiff ( ) ; $ diffs = $ diff -> getDiff ( ) ; foreach ( $ diffs as $ i => $ edit ) { if ( is_a ( $ edit , 'Text_Diff_Op_copy' ) ) { if ( is_array ( $ block ) ) { $ keep = $ i == count ( $ diffs ) - 1 ? $ ntrail : $ nlead + $ ntrail ; if ( count ( $ edit -> orig ) <= $ keep ) { $ block [ ] = $ edit ; } else { if ( $ ntrail ) { $ context = array_slice ( $ edit -> orig , 0 , $ ntrail ) ; $ block [ ] = new Text_Diff_Op_copy ( $ context ) ; } $ output .= $ this -> _block ( $ x0 , $ ntrail + $ xi - $ x0 , $ y0 , $ ntrail + $ yi - $ y0 , $ block ) ; $ block = false ; } } $ context = $ edit -> orig ; } else { if ( ! is_array ( $ block ) ) { $ context = array_slice ( $ context , count ( $ context ) - $ nlead ) ; $ x0 = $ xi - count ( $ context ) ; $ y0 = $ yi - count ( $ context ) ; $ block = array ( ) ; if ( $ context ) { $ block [ ] = new Text_Diff_Op_copy ( $ context ) ; } } $ block [ ] = $ edit ; } if ( $ edit -> orig ) { $ xi += count ( $ edit -> orig ) ; } if ( $ edit -> final ) { $ yi += count ( $ edit -> final ) ; } } if ( is_array ( $ block ) ) { $ output .= $ this -> _block ( $ x0 , $ xi - $ x0 , $ y0 , $ yi - $ y0 , $ block ) ; } return $ output . $ this -> _endDiff ( ) ; }
Renders a diff .
5,956
public function highlight ( $ content ) { $ this -> registerClientScript ( ) ; $ options [ 'use_language' ] = true ; $ options [ 'tabsize' ] = $ this -> tabSize ; if ( $ this -> showLineNumbers ) $ options [ 'numbers' ] = ( $ this -> lineNumberStyle === 'list' ) ? HL_NUMBERS_LI : HL_NUMBERS_TABLE ; $ highlighter = empty ( $ this -> language ) ? false : Text_Highlighter :: factory ( $ this -> language ) ; if ( $ highlighter === false ) $ o = '<pre>' . CHtml :: encode ( $ content ) . '</pre>' ; else { $ highlighter -> setRenderer ( new Text_Highlighter_Renderer_Html ( $ options ) ) ; $ o = preg_replace ( '/<span\s+[^>]*>(\s*)<\/span>/' , '\1' , $ highlighter -> highlight ( $ content ) ) ; } return CHtml :: tag ( 'div' , $ this -> containerOptions , $ o ) ; }
Highlights the content by the syntax of the specified language .
5,957
protected function handleException ( $ exception ) { $ app = Yii :: app ( ) ; if ( $ app instanceof CWebApplication ) { if ( ( $ trace = $ this -> getExactTrace ( $ exception ) ) === null ) { $ fileName = $ exception -> getFile ( ) ; $ errorLine = $ exception -> getLine ( ) ; } else { $ fileName = $ trace [ 'file' ] ; $ errorLine = $ trace [ 'line' ] ; } $ trace = $ exception -> getTrace ( ) ; foreach ( $ trace as $ i => $ t ) { if ( ! isset ( $ t [ 'file' ] ) ) $ trace [ $ i ] [ 'file' ] = 'unknown' ; if ( ! isset ( $ t [ 'line' ] ) ) $ trace [ $ i ] [ 'line' ] = 0 ; if ( ! isset ( $ t [ 'function' ] ) ) $ trace [ $ i ] [ 'function' ] = 'unknown' ; unset ( $ trace [ $ i ] [ 'object' ] ) ; } $ this -> _exception = $ exception ; $ this -> _error = $ data = array ( 'code' => ( $ exception instanceof CHttpException ) ? $ exception -> statusCode : 500 , 'type' => get_class ( $ exception ) , 'errorCode' => $ exception -> getCode ( ) , 'message' => $ exception -> getMessage ( ) , 'file' => $ fileName , 'line' => $ errorLine , 'trace' => $ exception -> getTraceAsString ( ) , 'traces' => $ trace , ) ; if ( ! headers_sent ( ) ) { $ httpVersion = Yii :: app ( ) -> request -> getHttpVersion ( ) ; header ( "HTTP/$httpVersion {$data['code']} " . $ this -> getHttpHeader ( $ data [ 'code' ] , get_class ( $ exception ) ) ) ; } $ this -> renderException ( ) ; } else $ app -> displayException ( $ exception ) ; }
Handles the exception .
5,958
protected function getExactTrace ( $ exception ) { $ traces = $ exception -> getTrace ( ) ; foreach ( $ traces as $ trace ) { if ( isset ( $ trace [ 'function' ] ) && ( $ trace [ 'function' ] === '__get' || $ trace [ 'function' ] === '__set' ) ) return $ trace ; } return null ; }
Returns the exact trace where the problem occurs .
5,959
protected function getViewFile ( $ view , $ code ) { $ viewPaths = array ( Yii :: app ( ) -> getTheme ( ) === null ? null : Yii :: app ( ) -> getTheme ( ) -> getSystemViewPath ( ) , Yii :: app ( ) instanceof CWebApplication ? Yii :: app ( ) -> getSystemViewPath ( ) : null , YII_PATH . DIRECTORY_SEPARATOR . 'views' , ) ; foreach ( $ viewPaths as $ i => $ viewPath ) { if ( $ viewPath !== null ) { $ viewFile = $ this -> getViewFileInternal ( $ viewPath , $ view , $ code , $ i === 2 ? 'en_us' : null ) ; if ( is_file ( $ viewFile ) ) return $ viewFile ; } } }
Determines which view file should be used .
5,960
protected function getViewFileInternal ( $ viewPath , $ view , $ code , $ srcLanguage = null ) { $ app = Yii :: app ( ) ; if ( $ view === 'error' ) { $ viewFile = $ app -> findLocalizedFile ( $ viewPath . DIRECTORY_SEPARATOR . "error{$code}.php" , $ srcLanguage ) ; if ( ! is_file ( $ viewFile ) ) $ viewFile = $ app -> findLocalizedFile ( $ viewPath . DIRECTORY_SEPARATOR . 'error.php' , $ srcLanguage ) ; } else $ viewFile = $ viewPath . DIRECTORY_SEPARATOR . "exception.php" ; return $ viewFile ; }
Looks for the view under the specified directory .
5,961
protected function getVersionInfo ( ) { if ( YII_DEBUG ) { $ version = '<a href="http://www.yiiframework.com/">Yii Framework</a>/' . Yii :: getVersion ( ) ; if ( isset ( $ _SERVER [ 'SERVER_SOFTWARE' ] ) ) $ version = $ _SERVER [ 'SERVER_SOFTWARE' ] . ' ' . $ version ; } else $ version = '' ; return $ version ; }
Returns server version information . If the application is in production mode empty string is returned .
5,962
protected function isCoreCode ( $ trace ) { if ( isset ( $ trace [ 'file' ] ) ) { $ systemPath = realpath ( dirname ( __FILE__ ) . '/..' ) ; return $ trace [ 'file' ] === 'unknown' || strpos ( realpath ( $ trace [ 'file' ] ) , $ systemPath . DIRECTORY_SEPARATOR ) === 0 ; } return false ; }
Returns a value indicating whether the call stack is from application code .
5,963
protected function renderSourceCode ( $ file , $ errorLine , $ maxLines ) { $ errorLine -- ; if ( $ errorLine < 0 || ( $ lines = @ file ( $ file ) ) === false || ( $ lineCount = count ( $ lines ) ) <= $ errorLine ) return '' ; $ halfLines = ( int ) ( $ maxLines / 2 ) ; $ beginLine = $ errorLine - $ halfLines > 0 ? $ errorLine - $ halfLines : 0 ; $ endLine = $ errorLine + $ halfLines < $ lineCount ? $ errorLine + $ halfLines : $ lineCount - 1 ; $ lineNumberWidth = strlen ( $ endLine + 1 ) ; $ output = '' ; for ( $ i = $ beginLine ; $ i <= $ endLine ; ++ $ i ) { $ isErrorLine = $ i === $ errorLine ; $ code = sprintf ( "<span class=\"ln" . ( $ isErrorLine ? ' error-ln' : '' ) . "\">%0{$lineNumberWidth}d</span> %s" , $ i + 1 , CHtml :: encode ( str_replace ( "\t" , ' ' , $ lines [ $ i ] ) ) ) ; if ( ! $ isErrorLine ) $ output .= $ code ; else $ output .= '<span class="error">' . $ code . '</span>' ; } return '<div class="code"><pre>' . $ output . '</pre></div>' ; }
Renders the source code around the error line .
5,964
public function run ( ) { list ( $ name , $ id ) = $ this -> resolveNameID ( ) ; if ( substr ( $ name , - 2 ) !== '[]' ) $ name .= '[]' ; if ( isset ( $ this -> htmlOptions [ 'id' ] ) ) $ id = $ this -> htmlOptions [ 'id' ] ; else $ this -> htmlOptions [ 'id' ] = $ id ; $ this -> registerClientScript ( ) ; echo CHtml :: fileField ( $ name , '' , $ this -> htmlOptions ) ; }
Runs the widget . This method registers all needed client scripts and renders the multiple file uploader .
5,965
public function renderItems ( ) { echo CHtml :: openTag ( $ this -> itemsTagName , array ( 'class' => $ this -> itemsCssClass ) ) . "\n" ; $ data = $ this -> dataProvider -> getData ( ) ; if ( ( $ n = count ( $ data ) ) > 0 ) { $ owner = $ this -> getOwner ( ) ; $ viewFile = $ owner -> getViewFile ( $ this -> itemView ) ; $ j = 0 ; foreach ( $ data as $ i => $ item ) { $ data = $ this -> viewData ; $ data [ 'index' ] = $ i ; $ data [ 'data' ] = $ item ; $ data [ 'widget' ] = $ this ; $ owner -> renderFile ( $ viewFile , $ data ) ; if ( $ j ++ < $ n - 1 ) echo $ this -> separator ; } } else $ this -> renderEmptyText ( ) ; echo CHtml :: closeTag ( $ this -> itemsTagName ) ; }
Renders the data item list .
5,966
public function renderSorter ( ) { if ( $ this -> dataProvider -> getItemCount ( ) <= 0 || ! $ this -> enableSorting || empty ( $ this -> sortableAttributes ) ) return ; echo CHtml :: openTag ( 'div' , array ( 'class' => $ this -> sorterCssClass ) ) . "\n" ; echo $ this -> sorterHeader === null ? Yii :: t ( 'zii' , 'Sort by: ' ) : $ this -> sorterHeader ; echo "<ul>\n" ; $ sort = $ this -> dataProvider -> getSort ( ) ; foreach ( $ this -> sortableAttributes as $ name => $ label ) { echo "<li>" ; if ( is_integer ( $ name ) ) echo $ sort -> link ( $ label ) ; else echo $ sort -> link ( $ name , $ label ) ; echo "</li>\n" ; } echo "</ul>" ; echo $ this -> sorterFooter ; echo CHtml :: closeTag ( 'div' ) ; }
Renders the sorter .
5,967
public function authenticate ( ) { if ( $ this -> username === 'demo' && $ this -> password === 'demo' ) $ this -> errorCode = self :: ERROR_NONE ; else $ this -> errorCode = self :: ERROR_PASSWORD_INVALID ; return ! $ this -> errorCode ; }
Validates the username and password . This method should check the validity of the provided username and password in some way . In case of any authentication failure set errorCode and errorMessage with appropriate values and return false .
5,968
public function init ( ) { list ( $ name , $ id ) = $ this -> resolveNameID ( ) ; if ( isset ( $ this -> htmlOptions [ 'id' ] ) ) $ id = $ this -> htmlOptions [ 'id' ] ; else $ this -> htmlOptions [ 'id' ] = $ id ; if ( isset ( $ this -> htmlOptions [ 'name' ] ) ) $ name = $ this -> htmlOptions [ 'name' ] ; $ this -> registerClientScript ( ) ; if ( $ this -> hasModel ( ) ) { $ field = $ this -> textArea ? 'activeTextArea' : 'activeTextField' ; echo CHtml :: $ field ( $ this -> model , $ this -> attribute , $ this -> htmlOptions ) ; } else { $ field = $ this -> textArea ? 'textArea' : 'textField' ; echo CHtml :: $ field ( $ name , $ this -> value , $ this -> htmlOptions ) ; } }
Initializes the widget . This method registers all needed client scripts and renders the autocomplete input .
5,969
public function save ( $ file , $ messages ) { if ( ! ( $ fw = @ fopen ( $ file , 'wb' ) ) ) throw new CException ( Yii :: t ( 'yii' , 'Unable to write file "{file}".' , array ( '{file}' => $ file ) ) ) ; if ( ! @ flock ( $ fw , LOCK_EX ) ) throw new CException ( Yii :: t ( 'yii' , 'Unable to lock file "{file}" for writing.' , array ( '{file}' => $ file ) ) ) ; if ( $ this -> useBigEndian ) $ this -> writeByte ( $ fw , pack ( 'c*' , 0x95 , 0x04 , 0x12 , 0xde ) ) ; else $ this -> writeByte ( $ fw , pack ( 'c*' , 0xde , 0x12 , 0x04 , 0x95 ) ) ; $ this -> writeInteger ( $ fw , 0 ) ; $ n = count ( $ messages ) ; $ this -> writeInteger ( $ fw , $ n ) ; $ offset = 28 ; $ this -> writeInteger ( $ fw , $ offset ) ; $ offset += ( $ n * 8 ) ; $ this -> writeInteger ( $ fw , $ offset ) ; $ this -> writeInteger ( $ fw , 0 ) ; $ offset += ( $ n * 8 ) ; $ this -> writeInteger ( $ fw , $ offset ) ; foreach ( array_keys ( $ messages ) as $ id ) { $ len = strlen ( $ id ) ; $ this -> writeInteger ( $ fw , $ len ) ; $ this -> writeInteger ( $ fw , $ offset ) ; $ offset += $ len + 1 ; } foreach ( $ messages as $ message ) { $ len = strlen ( $ message ) ; $ this -> writeInteger ( $ fw , $ len ) ; $ this -> writeInteger ( $ fw , $ offset ) ; $ offset += $ len + 1 ; } foreach ( array_keys ( $ messages ) as $ id ) $ this -> writeString ( $ fw , $ id ) ; foreach ( $ messages as $ message ) $ this -> writeString ( $ fw , $ message ) ; @ flock ( $ fw , LOCK_UN ) ; @ fclose ( $ fw ) ; }
Saves messages to an MO file .
5,970
protected function writeInteger ( $ fw , $ data ) { return $ this -> writeByte ( $ fw , pack ( $ this -> useBigEndian ? 'N' : 'V' , ( int ) $ data ) ) ; }
Writes a 4 - byte integer .
5,971
protected function readString ( $ fr , $ length , $ offset = null ) { if ( $ offset !== null ) fseek ( $ fr , $ offset ) ; return $ this -> readByte ( $ fr , $ length ) ; }
Reads a string .
5,972
public static function ensureArray ( $ value ) { if ( is_string ( $ value ) ) { $ value = trim ( $ value ) ; $ len = strlen ( $ value ) ; if ( $ len >= 2 && $ value [ 0 ] == '(' && $ value [ $ len - 1 ] == ')' ) { try { return eval ( 'return array' . $ value . ';' ) ; } catch ( ParseError $ e ) { return array ( ) ; } } else return $ len > 0 ? array ( $ value ) : array ( ) ; } else return ( array ) $ value ; }
Converts a value to array type .
5,973
public static function ensureEnum ( $ value , $ enumType ) { static $ types = array ( ) ; if ( ! isset ( $ types [ $ enumType ] ) ) $ types [ $ enumType ] = new ReflectionClass ( $ enumType ) ; if ( $ types [ $ enumType ] -> hasConstant ( $ value ) ) return $ value ; else throw new CException ( Yii :: t ( 'yii' , 'Invalid enumerable value "{value}". Please make sure it is among ({enum}).' , array ( '{value}' => $ value , '{enum}' => implode ( ', ' , $ types [ $ enumType ] -> getConstants ( ) ) ) ) ) ; }
Converts a value to enum type .
5,974
protected function isRelationTable ( $ table ) { $ pk = $ table -> primaryKey ; $ count = is_array ( $ pk ) ? count ( $ pk ) : 1 ; return ( $ count === 2 && isset ( $ table -> foreignKeys [ $ pk [ 0 ] ] ) && isset ( $ table -> foreignKeys [ $ pk [ 1 ] ] ) && $ table -> foreignKeys [ $ pk [ 0 ] ] [ 0 ] !== $ table -> foreignKeys [ $ pk [ 1 ] ] [ 0 ] ) ; }
Checks if the given table is a many to many pivot table . Their PK has 2 fields and both of those fields are also FK to other separate tables .
5,975
public function executeBizRule ( $ bizRule , $ params , $ data ) { if ( $ bizRule === '' || $ bizRule === null ) return true ; if ( $ this -> showErrors ) return eval ( $ bizRule ) != 0 ; else { try { return @ eval ( $ bizRule ) != 0 ; } catch ( ParseError $ e ) { return false ; } } }
Executes the specified business rule .
5,976
protected function checkItemChildType ( $ parentType , $ childType ) { static $ types = array ( 'operation' , 'task' , 'role' ) ; if ( $ parentType < $ childType ) throw new CException ( Yii :: t ( 'yii' , 'Cannot add an item of type "{child}" to an item of type "{parent}".' , array ( '{child}' => $ types [ $ childType ] , '{parent}' => $ types [ $ parentType ] ) ) ) ; }
Checks the item types to make sure a child can be added to a parent .
5,977
public function formatCurrency ( $ value , $ currency ) { return $ this -> format ( $ this -> _locale -> getCurrencyFormat ( ) , $ value , $ currency ) ; }
Formats a number using the currency format defined in the locale .
5,978
protected function emptyAttribute ( $ object , $ attribute ) { if ( $ this -> safe ) $ object -> $ attribute = null ; if ( ! $ this -> allowEmpty ) { $ message = $ this -> message !== null ? $ this -> message : Yii :: t ( 'yii' , '{attribute} cannot be blank.' ) ; $ this -> addError ( $ object , $ attribute , $ message ) ; } }
Raises an error to inform end user about blank attribute . Sets the owner attribute to null to prevent setting arbitrary values .
5,979
function reverse ( ) { if ( version_compare ( zend_version ( ) , '2' , '>' ) ) { $ rev = clone ( $ this ) ; } else { $ rev = $ this ; } $ rev -> _edits = array ( ) ; foreach ( $ this -> _edits as $ edit ) { $ rev -> _edits [ ] = $ edit -> reverse ( ) ; } return $ rev ; }
Computes a reversed diff .
5,980
function getOriginal ( ) { $ lines = array ( ) ; foreach ( $ this -> _edits as $ edit ) { if ( $ edit -> orig ) { array_splice ( $ lines , count ( $ lines ) , 0 , $ edit -> orig ) ; } } return $ lines ; }
Gets the original set of lines .
5,981
function getFinal ( ) { $ lines = array ( ) ; foreach ( $ this -> _edits as $ edit ) { if ( $ edit -> final ) { array_splice ( $ lines , count ( $ lines ) , 0 , $ edit -> final ) ; } } return $ lines ; }
Gets the final set of lines .
5,982
function _getTempDir ( ) { $ tmp_locations = array ( '/tmp' , '/var/tmp' , 'c:\WUTemp' , 'c:\temp' , 'c:\windows\temp' , 'c:\winnt\temp' ) ; $ tmp = ini_get ( 'upload_tmp_dir' ) ; if ( ! strlen ( $ tmp ) ) { $ tmp = getenv ( 'TMPDIR' ) ; } while ( ! strlen ( $ tmp ) && count ( $ tmp_locations ) ) { $ tmp_check = array_shift ( $ tmp_locations ) ; if ( @ is_dir ( $ tmp_check ) ) { $ tmp = $ tmp_check ; } } return strlen ( $ tmp ) ? $ tmp : false ; }
Determines the location of the system temporary directory .
5,983
function _check ( $ from_lines , $ to_lines ) { if ( serialize ( $ from_lines ) != serialize ( $ this -> getOriginal ( ) ) ) { trigger_error ( "Reconstructed original doesn't match" , E_USER_ERROR ) ; } if ( serialize ( $ to_lines ) != serialize ( $ this -> getFinal ( ) ) ) { trigger_error ( "Reconstructed final doesn't match" , E_USER_ERROR ) ; } $ rev = $ this -> reverse ( ) ; if ( serialize ( $ to_lines ) != serialize ( $ rev -> getOriginal ( ) ) ) { trigger_error ( "Reversed original doesn't match" , E_USER_ERROR ) ; } if ( serialize ( $ from_lines ) != serialize ( $ rev -> getFinal ( ) ) ) { trigger_error ( "Reversed final doesn't match" , E_USER_ERROR ) ; } $ prevtype = null ; foreach ( $ this -> _edits as $ edit ) { if ( $ prevtype == get_class ( $ edit ) ) { trigger_error ( "Edit sequence is non-optimal" , E_USER_ERROR ) ; } $ prevtype = get_class ( $ edit ) ; } return true ; }
Checks a diff for validity .
5,984
public function init ( $ dbType , $ defaultValue ) { if ( $ defaultValue == '(NULL)' ) { $ defaultValue = null ; } parent :: init ( $ dbType , $ defaultValue ) ; }
Initializes the column with its DB type and default value . This sets up the column s PHP type size precision scale as well as default value .
5,985
public function init ( ) { parent :: init ( ) ; Yii :: setPathOfAlias ( 'gii' , dirname ( __FILE__ ) ) ; Yii :: app ( ) -> setComponents ( array ( 'errorHandler' => array ( 'class' => 'CErrorHandler' , 'errorAction' => $ this -> getId ( ) . '/default/error' , ) , 'user' => array ( 'class' => 'CWebUser' , 'stateKeyPrefix' => 'gii' , 'loginUrl' => Yii :: app ( ) -> createUrl ( $ this -> getId ( ) . '/default/login' ) , ) , 'widgetFactory' => array ( 'class' => 'CWidgetFactory' , 'widgets' => array ( ) ) ) , false ) ; $ this -> generatorPaths [ ] = 'gii.generators' ; $ this -> controllerMap = $ this -> findGenerators ( ) ; }
Initializes the gii module .
5,986
protected function findGenerators ( ) { $ generators = array ( ) ; $ n = count ( $ this -> generatorPaths ) ; for ( $ i = $ n - 1 ; $ i >= 0 ; -- $ i ) { $ alias = $ this -> generatorPaths [ $ i ] ; $ path = Yii :: getPathOfAlias ( $ alias ) ; if ( $ path === false || ! is_dir ( $ path ) ) continue ; $ names = scandir ( $ path ) ; foreach ( $ names as $ name ) { if ( $ name [ 0 ] !== '.' && is_dir ( $ path . '/' . $ name ) ) { $ className = ucfirst ( $ name ) . 'Generator' ; if ( is_file ( "$path/$name/$className.php" ) ) { $ generators [ $ name ] = array ( 'class' => "$alias.$name.$className" , ) ; } if ( isset ( $ generators [ $ name ] ) && is_dir ( "$path/$name/templates" ) ) { $ templatePath = "$path/$name/templates" ; $ dirs = scandir ( $ templatePath ) ; foreach ( $ dirs as $ dir ) { if ( $ dir [ 0 ] !== '.' && is_dir ( $ templatePath . '/' . $ dir ) ) $ generators [ $ name ] [ 'templates' ] [ $ dir ] = strtr ( $ templatePath . '/' . $ dir , array ( '/' => DIRECTORY_SEPARATOR , '\\' => DIRECTORY_SEPARATOR ) ) ; } } } } } return $ generators ; }
Finds all available code generators and their code templates .
5,987
public function actionGetTableNames ( $ db ) { if ( Yii :: app ( ) -> getRequest ( ) -> getIsAjaxRequest ( ) ) { $ all = array ( ) ; if ( ! empty ( $ db ) && Yii :: app ( ) -> hasComponent ( $ db ) !== false && ( Yii :: app ( ) -> getComponent ( $ db ) instanceof CDbConnection ) ) $ all = array_keys ( Yii :: app ( ) -> { $ db } -> schema -> getTables ( ) ) ; echo json_encode ( $ all ) ; } else throw new CHttpException ( 404 , 'The requested page does not exist.' ) ; }
Provides autocomplete table names
5,988
public function collectLogs ( $ logger , $ processLogs = false ) { $ logs = $ logger -> getLogs ( $ this -> levels , $ this -> categories , $ this -> except ) ; $ this -> logs = empty ( $ this -> logs ) ? $ logs : array_merge ( $ this -> logs , $ logs ) ; if ( $ processLogs && ! empty ( $ this -> logs ) ) { if ( $ this -> filter !== null ) Yii :: createComponent ( $ this -> filter ) -> filter ( $ this -> logs ) ; if ( $ this -> logs !== array ( ) ) $ this -> processLogs ( $ this -> logs ) ; $ this -> logs = array ( ) ; } }
Retrieves filtered log messages from logger for further processing .
5,989
public function compareTableNames ( $ name1 , $ name2 ) { $ name1 = str_replace ( array ( '[' , ']' ) , '' , $ name1 ) ; $ name2 = str_replace ( array ( '[' , ']' ) , '' , $ name2 ) ; return parent :: compareTableNames ( strtolower ( $ name1 ) , strtolower ( $ name2 ) ) ; }
Compares two table names . The table names can be either quoted or unquoted . This method will consider both cases .
5,990
protected function findForeignKeys ( $ table ) { $ rc = 'INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS' ; $ kcu = 'INFORMATION_SCHEMA.KEY_COLUMN_USAGE' ; if ( isset ( $ table -> catalogName ) ) { $ kcu = $ table -> catalogName . '.' . $ kcu ; $ rc = $ table -> catalogName . '.' . $ rc ; } $ sql = <<<EOD SELECT KCU1.CONSTRAINT_NAME AS 'FK_CONSTRAINT_NAME' , KCU1.TABLE_NAME AS 'FK_TABLE_NAME' , KCU1.COLUMN_NAME AS 'FK_COLUMN_NAME' , KCU1.ORDINAL_POSITION AS 'FK_ORDINAL_POSITION' , KCU2.CONSTRAINT_NAME AS 'UQ_CONSTRAINT_NAME' , KCU2.TABLE_NAME AS 'UQ_TABLE_NAME' , KCU2.COLUMN_NAME AS 'UQ_COLUMN_NAME' , KCU2.ORDINAL_POSITION AS 'UQ_ORDINAL_POSITION' FROM {$this->quoteTableName($rc)} RC JOIN {$this->quoteTableName($kcu)} KCU1 ON KCU1.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG AND KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME JOIN {$this->quoteTableName($kcu)} KCU2 ON KCU2.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG AND KCU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA AND KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME AND KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION WHERE KCU1.TABLE_NAME = :tableEOD ; $ command = $ this -> getDbConnection ( ) -> createCommand ( $ sql ) ; $ command -> bindValue ( ':table' , $ table -> name ) ; $ fkeys = array ( ) ; foreach ( $ command -> queryAll ( ) as $ info ) { $ fkeys [ $ info [ 'FK_COLUMN_NAME' ] ] = array ( $ info [ 'UQ_TABLE_NAME' ] , $ info [ 'UQ_COLUMN_NAME' ] , ) ; } return $ fkeys ; }
Gets foreign relationship constraint keys and table name
5,991
public function generateWsdl ( $ className , $ serviceUrl , $ encoding = 'UTF-8' ) { $ this -> operations = array ( ) ; $ this -> types = array ( ) ; $ this -> elements = array ( ) ; $ this -> messages = array ( ) ; if ( $ this -> serviceName === null ) $ this -> serviceName = $ className ; if ( $ this -> namespace === null ) $ this -> namespace = 'urn:' . str_replace ( '\\' , '/' , $ className ) . 'wsdl' ; $ reflection = new ReflectionClass ( $ className ) ; foreach ( $ reflection -> getMethods ( ) as $ method ) { if ( $ method -> isPublic ( ) ) $ this -> processMethod ( $ method ) ; } $ wsdl = $ this -> buildDOM ( $ serviceUrl , $ encoding ) -> saveXML ( ) ; if ( isset ( $ _GET [ 'makedoc' ] ) ) $ this -> buildHtmlDocs ( ) ; return $ wsdl ; }
Generates the WSDL for the given class .
5,992
protected function addCommands ( CConsoleCommandRunner $ runner ) { $ runner -> addCommands ( Yii :: getPathOfAlias ( 'system.cli.commands.shell' ) ) ; $ runner -> addCommands ( Yii :: getPathOfAlias ( 'application.commands.shell' ) ) ; if ( ( $ _path_ = @ getenv ( 'YIIC_SHELL_COMMAND_PATH' ) ) !== false ) $ runner -> addCommands ( $ _path_ ) ; }
Adds commands to runner
5,993
protected function init ( ) { parent :: init ( ) ; if ( empty ( $ _SERVER [ 'argv' ] ) ) die ( 'This script must be run from the command line.' ) ; $ this -> _runner = $ this -> createCommandRunner ( ) ; $ this -> _runner -> commands = $ this -> commandMap ; $ this -> _runner -> addCommands ( $ this -> getCommandPath ( ) ) ; }
Initializes the application by creating the command runner .
5,994
public function processRequest ( ) { $ exitCode = $ this -> _runner -> run ( $ _SERVER [ 'argv' ] ) ; if ( is_int ( $ exitCode ) ) $ this -> end ( $ exitCode ) ; }
Processes the user request . This method uses a console command runner to handle the particular user command . Since version 1 . 1 . 11 this method will exit application with an exit code if one is returned by the user command .
5,995
public function getViewFile ( $ controller , $ viewName ) { $ moduleViewPath = $ this -> getViewPath ( ) ; if ( ( $ module = $ controller -> getModule ( ) ) !== null ) $ moduleViewPath .= '/' . $ module -> getId ( ) ; return $ controller -> resolveViewFile ( $ viewName , $ this -> getViewPath ( ) . '/' . $ controller -> getUniqueId ( ) , $ this -> getViewPath ( ) , $ moduleViewPath ) ; }
Finds the view file for the specified controller s view .
5,996
public function getLayoutFile ( $ controller , $ layoutName ) { $ moduleViewPath = $ basePath = $ this -> getViewPath ( ) ; $ module = $ controller -> getModule ( ) ; if ( empty ( $ layoutName ) ) { while ( $ module !== null ) { if ( $ module -> layout === false ) return false ; if ( ! empty ( $ module -> layout ) ) break ; $ module = $ module -> getParentModule ( ) ; } if ( $ module === null ) $ layoutName = Yii :: app ( ) -> layout ; else { $ layoutName = $ module -> layout ; $ moduleViewPath .= '/' . $ module -> getId ( ) ; } } elseif ( $ module !== null ) $ moduleViewPath .= '/' . $ module -> getId ( ) ; return $ controller -> resolveViewFile ( $ layoutName , $ moduleViewPath . '/layouts' , $ basePath , $ moduleViewPath ) ; }
Finds the layout file for the specified controller s layout .
5,997
public function login ( ) { if ( $ this -> _identity === null ) { $ this -> _identity = new UserIdentity ( 'yiier' , $ this -> password ) ; $ this -> _identity -> authenticate ( ) ; } if ( $ this -> _identity -> errorCode === UserIdentity :: ERROR_NONE ) { Yii :: app ( ) -> user -> login ( $ this -> _identity ) ; return true ; } else return false ; }
Logs in the user using the given password in the model .
5,998
public function actionIndex ( ) { $ model = $ this -> prepare ( ) ; if ( $ model -> files != array ( ) && isset ( $ _POST [ 'generate' ] , $ _POST [ 'answers' ] ) ) { $ model -> answers = $ _POST [ 'answers' ] ; $ model -> status = $ model -> save ( ) ? CCodeModel :: STATUS_SUCCESS : CCodeModel :: STATUS_ERROR ; } $ this -> render ( 'index' , array ( 'model' => $ model , ) ) ; }
The code generation action . This is the action that displays the code generation interface . Child classes mainly need to provide the index view for collecting user parameters for code generation .
5,999
public function actionCode ( ) { $ model = $ this -> prepare ( ) ; if ( isset ( $ _GET [ 'id' ] ) && isset ( $ model -> files [ $ _GET [ 'id' ] ] ) ) { $ this -> renderPartial ( '/common/code' , array ( 'file' => $ model -> files [ $ _GET [ 'id' ] ] , ) ) ; } else throw new CHttpException ( 404 , 'Unable to find the code you requested.' ) ; }
The code preview action . This action shows up the specified generated code .