idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
21,700
protected function prepare ( $ markup , $ decorators ) { $ param_arr = func_get_args ( ) ; if ( is_array ( $ decorators ) ) { $ param_arr [ 1 ] = new \ ArrayObject ( $ decorators ) ; } $ order = 0 ; $ sortAux = [ ] ; foreach ( $ param_arr [ 1 ] as $ decorator => $ options ) { if ( ! is_string ( $ decorator ) && is_string ( $ options ) ) { $ param_arr [ 1 ] [ $ options ] = [ ] ; continue ; } elseif ( is_callable ( $ options ) ) { $ options = call_user_func_array ( $ options , $ param_arr ) ; $ param_arr [ 1 ] [ $ decorator ] = $ options ; } if ( ! is_array ( $ options ) ) { continue ; } if ( ! isset ( $ options [ 'order' ] ) ) { $ plugin = $ this -> getDecoratorHelper ( empty ( $ options [ 'type' ] ) ? $ decorator : $ options [ 'type' ] ) ; if ( $ plugin instanceof OrderedDecoratorInterface ) { $ order = $ plugin -> getOrder ( ) ; } $ options [ 'order' ] = $ order ; } else { $ order = ( int ) $ options [ 'order' ] ; } $ sortAux [ ] = $ options [ 'order' ] ; $ order += $ this -> orderStep ; } $ param_arr [ 1 ] = ArrayUtils :: iteratorToArray ( $ param_arr [ 1 ] ) ; $ param_arr [ 1 ] = array_filter ( $ param_arr [ 1 ] , 'is_array' ) ; array_multisort ( $ sortAux , SORT_ASC , SORT_NUMERIC , $ param_arr [ 1 ] ) ; return $ param_arr [ 1 ] ; }
Sorts decorators according to order option
21,701
public function getSpreadsheetFeed ( $ location = null ) { if ( $ location == null ) { $ uri = self :: SPREADSHEETS_FEED_URI ; } else if ( $ location instanceof Zend_Gdata_Spreadsheets_DocumentQuery ) { if ( $ location -> getDocumentType ( ) == null ) { $ location -> setDocumentType ( 'spreadsheets' ) ; } $ uri = $ location -> getQueryUrl ( ) ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_Spreadsheets_SpreadsheetFeed' ) ; }
Gets a spreadsheet feed .
21,702
public function getWorksheetFeed ( $ location ) { if ( $ location instanceof Zend_Gdata_Spreadsheets_DocumentQuery ) { if ( $ location -> getDocumentType ( ) == null ) { $ location -> setDocumentType ( 'worksheets' ) ; } $ uri = $ location -> getQueryUrl ( ) ; } else if ( $ location instanceof Zend_Gdata_Spreadsheets_SpreadsheetEntry ) { $ uri = $ location -> getLink ( self :: WORKSHEETS_FEED_LINK_URI ) -> href ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_Spreadsheets_WorksheetFeed' ) ; }
Gets a worksheet feed .
21,703
public function GetWorksheetEntry ( $ location ) { if ( $ location instanceof Zend_Gdata_Spreadsheets_DocumentQuery ) { if ( $ location -> getDocumentType ( ) == null ) { $ location -> setDocumentType ( 'worksheets' ) ; } $ uri = $ location -> getQueryUrl ( ) ; } else { $ uri = $ location ; } return parent :: getEntry ( $ uri , 'Zend_Gdata_Spreadsheets_WorksheetEntry' ) ; }
Gets a worksheet entry .
21,704
public function getCellFeed ( $ location ) { if ( $ location instanceof Zend_Gdata_Spreadsheets_CellQuery ) { $ uri = $ location -> getQueryUrl ( ) ; } else if ( $ location instanceof Zend_Gdata_Spreadsheets_WorksheetEntry ) { $ uri = $ location -> getLink ( self :: CELL_FEED_LINK_URI ) -> href ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_Spreadsheets_CellFeed' ) ; }
Gets a cell feed .
21,705
public function getCellEntry ( $ location ) { if ( $ location instanceof Zend_Gdata_Spreadsheets_CellQuery ) { $ uri = $ location -> getQueryUrl ( ) ; } else { $ uri = $ location ; } return parent :: getEntry ( $ uri , 'Zend_Gdata_Spreadsheets_CellEntry' ) ; }
Gets a cell entry .
21,706
public function getListFeed ( $ location ) { if ( $ location instanceof Zend_Gdata_Spreadsheets_ListQuery ) { $ uri = $ location -> getQueryUrl ( ) ; } else if ( $ location instanceof Zend_Gdata_Spreadsheets_WorksheetEntry ) { $ uri = $ location -> getLink ( self :: LIST_FEED_LINK_URI ) -> href ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_Spreadsheets_ListFeed' ) ; }
Gets a list feed .
21,707
public function getListEntry ( $ location ) { if ( $ location instanceof Zend_Gdata_Spreadsheets_ListQuery ) { $ uri = $ location -> getQueryUrl ( ) ; } else { $ uri = $ location ; } return parent :: getEntry ( $ uri , 'Zend_Gdata_Spreadsheets_ListEntry' ) ; }
Gets a list entry .
21,708
public function updateCell ( $ row , $ col , $ inputValue , $ key , $ wkshtId = 'default' ) { $ cell = 'R' . $ row . 'C' . $ col ; $ query = new Zend_Gdata_Spreadsheets_CellQuery ( ) ; $ query -> setSpreadsheetKey ( $ key ) ; $ query -> setWorksheetId ( $ wkshtId ) ; $ query -> setCellId ( $ cell ) ; $ entry = $ this -> getCellEntry ( $ query ) ; $ entry -> setCell ( new Zend_Gdata_Spreadsheets_Extension_Cell ( null , $ row , $ col , $ inputValue ) ) ; $ response = $ entry -> save ( ) ; return $ response ; }
Updates an existing cell .
21,709
public function insertRow ( $ rowData , $ key , $ wkshtId = 'default' ) { $ newEntry = new Zend_Gdata_Spreadsheets_ListEntry ( ) ; $ newCustomArr = array ( ) ; foreach ( $ rowData as $ k => $ v ) { $ newCustom = new Zend_Gdata_Spreadsheets_Extension_Custom ( ) ; $ newCustom -> setText ( $ v ) -> setColumnName ( $ k ) ; $ newEntry -> addCustom ( $ newCustom ) ; } $ query = new Zend_Gdata_Spreadsheets_ListQuery ( ) ; $ query -> setSpreadsheetKey ( $ key ) ; $ query -> setWorksheetId ( $ wkshtId ) ; $ feed = $ this -> getListFeed ( $ query ) ; $ editLink = $ feed -> getLink ( 'http://schemas.google.com/g/2005#post' ) ; return $ this -> insertEntry ( $ newEntry -> saveXML ( ) , $ editLink -> href , 'Zend_Gdata_Spreadsheets_ListEntry' ) ; }
Inserts a new row with provided data .
21,710
public function updateRow ( $ entry , $ newRowData ) { $ newCustomArr = array ( ) ; foreach ( $ newRowData as $ k => $ v ) { $ newCustom = new Zend_Gdata_Spreadsheets_Extension_Custom ( ) ; $ newCustom -> setText ( $ v ) -> setColumnName ( $ k ) ; $ newCustomArr [ ] = $ newCustom ; } $ entry -> setCustom ( $ newCustomArr ) ; return $ entry -> save ( ) ; }
Updates an existing row with provided data .
21,711
public function getSpreadsheetListFeedContents ( $ location ) { $ listFeed = $ this -> getListFeed ( $ location ) ; $ listFeed = $ this -> retrieveAllEntriesForFeed ( $ listFeed ) ; $ spreadsheetContents = array ( ) ; foreach ( $ listFeed as $ listEntry ) { $ rowContents = array ( ) ; $ customArray = $ listEntry -> getCustom ( ) ; foreach ( $ customArray as $ custom ) { $ rowContents [ $ custom -> getColumnName ( ) ] = $ custom -> getText ( ) ; } $ spreadsheetContents [ ] = $ rowContents ; } return $ spreadsheetContents ; }
Returns the content of all rows as an associative array
21,712
public function getForm ( ) { if ( null === $ this -> form ) { $ this -> setForm ( $ this -> getUserService ( ) -> getLoginForm ( ) ) ; } return $ this -> form ; }
Retrieve Login form
21,713
public static function sanitizeArray ( & $ arr ) { foreach ( $ arr as $ k => $ v ) { if ( is_string ( $ v ) ) { $ arr [ $ k ] = self :: sanitizeInput ( $ v ) ; } } }
Sanitizes all strings of an array
21,714
public static function cnpj ( $ cnpj ) { $ cnpj = preg_replace ( '/[^\d]/' , '' , $ cnpj ) ; if ( strlen ( $ cnpj ) > 14 ) { return false ; } $ cnpj = str_pad ( $ cnpj , 14 , '0' , STR_PAD_LEFT ) ; if ( preg_match ( '/(\d)\1{13}/' , $ cnpj ) ) { return false ; } $ value = substr ( $ cnpj , 0 , - 2 ) ; $ cd = 11 - self :: mod11 ( $ value ) ; if ( $ cd >= 10 ) { $ cd = 0 ; } $ value .= $ cd ; $ cd = 11 - self :: mod11 ( $ value ) ; if ( $ cd >= 10 ) { $ cd = 0 ; } $ value .= $ cd ; if ( $ cnpj === $ value ) { return $ cnpj ; } return false ; }
Validates Brazilian CNPJ
21,715
public static function cpf ( $ cpf ) { $ cpf = preg_replace ( '/[^\d]/' , '' , $ cpf ) ; if ( strlen ( $ cpf ) > 11 ) { return false ; } $ cpf = str_pad ( $ cpf , 11 , '0' , STR_PAD_LEFT ) ; if ( preg_match ( '/(\d)\1{10}/' , $ cpf ) ) { return false ; } for ( $ t = 9 ; $ t < 11 ; $ t ++ ) { for ( $ d = 0 , $ c = 0 ; $ c < $ t ; $ c ++ ) { $ d += $ cpf { $ c } * ( ( $ t + 1 ) - $ c ) ; } $ d = ( ( 10 * $ d ) % 11 ) % 10 ; if ( $ cpf { $ c } != $ d ) { return false ; } } return $ cpf ; }
Validate Brazilian CPF
21,716
public static function mod11Pre ( $ number , $ base = 9 ) { $ checksum = 0 ; $ factor = 2 ; foreach ( str_split ( strrev ( ( string ) $ number ) ) as $ d ) { $ checksum += $ d * $ factor ; if ( ++ $ factor > $ base ) { $ factor = 2 ; } } return $ checksum ; }
Calculates modulus 11 but do not apply the modulus
21,717
protected function _FetchAllRows ( $ DatasetType = FALSE ) { if ( ! is_null ( $ this -> _Result ) ) return ; if ( $ DatasetType ) $ this -> _DatasetType = $ DatasetType ; $ Result = array ( ) ; if ( is_null ( $ this -> _PDOStatement ) ) { $ this -> _Result = $ Result ; return ; } $ Result = $ this -> _PDOStatement -> fetchAll ( $ this -> _DatasetType == DATASET_TYPE_ARRAY ? PDO :: FETCH_ASSOC : PDO :: FETCH_OBJ ) ; $ this -> FreePDOStatement ( TRUE ) ; $ this -> _Result = $ Result ; }
Fetches all rows from the PDOStatement object into the resultset .
21,718
public function & FirstRow ( $ DatasetType = FALSE ) { $ Result = & $ this -> Result ( $ DatasetType ) ; if ( count ( $ Result ) == 0 ) return $ this -> _EOF ; return $ Result [ 0 ] ; }
Returns the first row or FALSE if there are no rows to return .
21,719
public function Format ( $ FormatMethod ) { $ Result = & $ this -> Result ( ) ; foreach ( $ Result as $ Index => $ Value ) { $ Result [ $ Index ] = Gdn_Format :: To ( $ Value , $ FormatMethod ) ; } return $ this ; }
Format the resultset with the given method .
21,720
public static function Index ( $ Data , $ Columns , $ Options = array ( ) ) { $ Columns = ( array ) $ Columns ; $ Result = array ( ) ; $ Options = array_change_key_case ( $ Options ) ; if ( is_string ( $ Options ) ) $ Options = array ( 'sep' => $ Options ) ; $ Sep = GetValue ( 'sep' , $ Options , '|' ) ; $ Unique = GetValue ( 'unique' , $ Options , TRUE ) ; foreach ( $ Data as $ Row ) { $ IndexValues = array ( ) ; foreach ( $ Columns as $ Column ) { $ IndexValues [ ] = GetValue ( $ Column , $ Row ) ; } $ Index = implode ( $ Sep , $ IndexValues ) ; if ( $ Unique ) $ Result [ $ Index ] = $ Row ; else $ Result [ $ Index ] [ ] = $ Row ; } return $ Result ; }
Index a result array .
21,721
public function & LastRow ( $ DatasetType = FALSE ) { $ Result = & $ this -> Result ( $ DatasetType ) ; if ( count ( $ Result ) == 0 ) return $ this -> _EOF ; return $ Result [ count ( $ Result ) - 1 ] ; }
Returns the last row in the or FALSE if there are no rows to return .
21,722
public function & NextRow ( $ DatasetType = FALSE ) { $ Result = & $ this -> Result ( $ DatasetType ) ; ++ $ this -> _Cursor ; if ( isset ( $ Result [ $ this -> _Cursor ] ) ) return $ Result [ $ this -> _Cursor ] ; return $ this -> _EOF ; }
Returns the next row or FALSE if there are no more rows .
21,723
public function & PreviousRow ( $ DatasetType = FALSE ) { $ Result = & $ this -> Result ( $ DatasetType ) ; -- $ this -> _Cursor ; if ( isset ( $ Result [ $ this -> _Cursor ] ) ) { return $ Result [ $ this -> _Cursor ] ; } return $ this -> _EOF ; }
Returns the previous row in the requested format .
21,724
public function & Row ( $ RowIndex ) { $ Result = & $ this -> Result ( ) ; if ( isset ( $ Result [ $ RowIndex ] ) ) return $ Result [ $ RowIndex ] ; return $ this -> _EOF ; }
Returns the requested row index as the requested row type .
21,725
public function PDOStatement ( & $ PDOStatement = FALSE ) { if ( $ PDOStatement === FALSE ) return $ this -> _PDOStatement ; else $ this -> _PDOStatement = $ PDOStatement ; }
Assigns the pdostatement object to this object .
21,726
public function Unserialize ( $ Fields = array ( 'Attributes' , 'Data' ) ) { $ Result = & $ this -> Result ( ) ; $ First = TRUE ; foreach ( $ Result as $ Row ) { if ( $ First ) { foreach ( $ Fields as $ Index => $ Field ) { if ( GetValue ( $ Field , $ Row , FALSE ) === FALSE ) { unset ( $ Fields [ $ Index ] ) ; } } $ First = FALSE ; } foreach ( $ Fields as $ Field ) { if ( is_object ( $ Row ) ) { if ( is_string ( $ Row -> $ Field ) ) $ Row -> $ Field = @ unserialize ( $ Row -> $ Field ) ; } else { if ( is_string ( $ Row [ $ Field ] ) ) $ Row [ $ Field ] = @ unserialize ( $ Row [ $ Field ] ) ; } } } }
Unserialize the fields in the dataset .
21,727
public function Value ( $ ColumnName , $ DefaultValue = NULL ) { if ( $ Row = $ this -> NextRow ( ) ) { if ( is_array ( $ ColumnName ) ) { $ Result = array ( ) ; foreach ( $ ColumnName as $ Name => $ Default ) { if ( is_object ( $ Row ) && property_exists ( $ Row , $ Name ) ) return $ Row -> $ Name ; elseif ( is_array ( $ Row ) && array_key_exists ( $ Name , $ Row ) ) return $ Row [ $ Name ] ; else $ Result [ ] = $ Default ; } return $ Result ; } else { if ( is_object ( $ Row ) && property_exists ( $ Row , $ ColumnName ) ) return $ Row -> $ ColumnName ; elseif ( is_array ( $ Row ) && array_key_exists ( $ ColumnName , $ Row ) ) return $ Row [ $ ColumnName ] ; } } if ( is_array ( $ ColumnName ) ) return array_values ( $ ColumnName ) ; return $ DefaultValue ; }
Advances to the next row and returns the value rom a column .
21,728
public static function apiRoutes ( \ Illuminate \ Routing \ Router $ router ) { $ router -> group ( [ 'prefix' => 'translations' ] , function ( \ Illuminate \ Routing \ Router $ router ) { $ router -> get ( '/index' , [ 'as' => 'translations.api.index' , 'uses' => ApiController :: class . '@index' ] ) ; } ) ; }
Register API routes
21,729
public static function adminRoutes ( \ Illuminate \ Routing \ Router $ router ) { $ router -> group ( [ 'prefix' => 'translations' ] , function ( \ Illuminate \ Routing \ Router $ router ) { $ router -> get ( '/export' , [ 'as' => 'translations.export' , 'uses' => TranslationsController :: class . '@export' ] ) ; $ router -> post ( '/import' , [ 'as' => 'translations.import' , 'uses' => TranslationsController :: class . '@import' ] ) ; $ router -> post ( '/edit/{group}' , [ 'as' => 'translations.edit' , 'uses' => TranslationsController :: class . '@edit' ] ) ; $ router -> get ( '/manual' , [ 'as' => 'translations.manual' , 'uses' => TranslationsController :: class . '@manual' ] ) ; $ router -> post ( '/store' , [ 'as' => 'translations.store' , 'uses' => TranslationsController :: class . '@storeTranslation' ] ) ; $ router -> get ( '/{group?}' , [ 'as' => 'translations.index' , 'uses' => TranslationsController :: class . '@index' ] ) ; } ) ; $ router -> resources ( [ 'languages' => LanguagesController :: class ] ) ; }
Register admin routes
21,730
function rm ( $ dryrun = false , $ harduninstall = false ) { if ( $ this -> locked ) { return [ null , 400 ] ; } else { $ channels = $ this -> channels ( ) ; $ config = [ 'tables' => [ ] ] ; if ( ! $ harduninstall ) { list ( $ history ) = $ this -> history ( ) ; foreach ( $ history as $ i ) { if ( $ i [ 'hotfix' ] === null ) { $ handlers = $ channels [ $ i [ 'channel' ] ] [ 'versions' ] [ $ i [ 'version' ] ] ; } else { $ handlers = $ channels [ $ i [ 'channel' ] ] [ 'versions' ] [ $ i [ 'version' ] ] [ 'hotfixes' ] [ $ i [ 'hotfix' ] ] ; } $ this -> rm__load_tables ( $ config , $ handlers ) ; } } else { foreach ( $ channels as $ channelname => $ chaninfo ) { foreach ( $ chaninfo [ 'versions' ] as $ version => $ handlers ) { $ this -> rm__load_tables ( $ config , $ handlers ) ; if ( isset ( $ handlers [ 'hotfixes' ] ) ) { foreach ( $ handlers [ 'hotfixes' ] as $ hotfix => $ fixhandlers ) { $ this -> rm__load_tables ( $ config , $ fixhandlers ) ; } } } } } if ( $ this -> has_history_table ( ) ) { $ config [ 'tables' ] [ ] = $ this -> table ( ) ; } if ( $ dryrun ) { return [ $ config [ 'tables' ] , 0 ] ; } if ( ! empty ( $ config [ 'tables' ] ) ) { $ dbh = $ this -> dbh ( ) ; $ dbh -> prepare ( 'SET foreign_key_checks = FALSE' ) -> execute ( ) ; foreach ( $ config [ 'tables' ] as $ table ) { $ this -> log ( " Removing $table\n" ) ; $ dbh -> prepare ( "DROP TABLE IF EXISTS `$table`" ) -> execute ( ) ; } $ dbh -> prepare ( 'SET foreign_key_checks = TRUE' ) -> execute ( ) ; } else { $ this -> log ( "Nothing to remove.\n" ) ; } } return [ null , 0 ] ; }
Removes all tables .
21,731
function sync ( $ dryrun = false ) { $ channels = $ this -> channels ( ) ; $ status = [ 'history' => [ ] , 'state' => [ ] , 'active' => [ ] , 'checklist' => $ this -> generate_checklist ( $ channels ) ] ; list ( $ history , $ err ) = $ this -> history ( ) ; if ( $ err !== 0 ) { throw new Panic ( 'Failed to retrieve history.' ) ; } foreach ( $ history as $ entry ) { if ( $ entry [ 'hotfix' ] === null ) { $ status [ 'state' ] [ $ entry [ 'channel' ] ] = $ this -> binversion ( $ entry [ 'channel' ] , $ entry [ 'version' ] ) ; } } foreach ( $ channels as $ channel => & $ timeline ) { if ( count ( $ timeline [ 'versions' ] ) > 0 ) { end ( $ timeline [ 'versions' ] ) ; $ last_version = key ( $ timeline [ 'versions' ] ) ; $ this -> processhistory ( $ channel , $ last_version , $ status , $ channels ) ; } } if ( $ dryrun ) { return [ $ status [ 'history' ] , 0 ] ; } $ migrations = 0 ; if ( ! empty ( $ status [ 'history' ] ) ) { foreach ( $ status [ 'history' ] as $ entry ) { $ this -> processmigration ( $ channels , $ entry [ 'channel' ] , $ entry [ 'version' ] , $ entry [ 'hotfix' ] ) ; $ migrations ++ ; } } else { $ this -> log ( "No changes required.\n" ) ; return [ $ migrations , 0 ] ; } return [ $ migrations , 0 ] ; }
Move the database forward .
21,732
protected function conf ( $ confpath , $ dependencies = [ ] ) { $ conf = $ this -> confs -> read ( $ confpath ) ; if ( isset ( $ conf [ 'require' ] ) ) { throw new Panic ( "The paradox configuration $confpath must not contain a require key. Only the main paradox configuration should specify dependencies." ) ; } return array_merge ( $ conf , [ 'require' => $ dependencies ] ) ; }
Normalize configuration entry
21,733
protected function shout ( $ op , $ channel , $ version , $ note = null ) { ! $ this -> verbose or $ this -> log ( sprintf ( $ this -> step_format ( ) . "\n" , $ op , $ version , $ channel , $ note ) ) ; return true ; }
Step information for verbose output
21,734
protected function dependency_race_error ( array $ status , $ channel , $ version ) { ! $ this -> verbose or $ this -> log ( "\n" ) ; $ this -> log ( " Race backtrace:\n" ) ; foreach ( $ status [ 'active' ] as $ activeinfo ) { $ this -> log ( " - {$activeinfo['channel']} {$activeinfo['version']}\n" ) ; } $ this -> log ( "\n" ) ; throw new Panic ( "Target version breached by race condition on $channel $version" ) ; }
Error report for situation where dependencies race against each other and a channels fall behind another in the requirement war .
21,735
protected function rm__load_tables ( array & $ config , array $ handlers ) { if ( isset ( $ handlers [ 'configure' ] ) ) { $ conf = $ handlers [ 'configure' ] ; if ( is_array ( $ conf ) ) { if ( isset ( $ conf [ 'tables' ] ) ) { foreach ( $ conf [ 'tables' ] as $ table ) { $ config [ 'tables' ] [ ] = $ table ; } } } else { $ config = $ conf ( $ config ) ; } } }
Loads tables from configuration
21,736
public function hasConfig ( $ name ) { if ( property_exists ( $ this , 'client_' . $ name ) ) { $ name = 'client_' . $ name ; return ! empty ( $ this -> $ name ) ; } return false ; }
Check if this client has been provided a property value .
21,737
public function setConfig ( $ name , $ value ) { if ( property_exists ( $ this , 'client_' . $ name ) && ! empty ( $ value ) ) { $ name = 'client_' . $ name ; $ this -> $ name = $ value ; } return $ this ; }
Set a config variable .
21,738
public static function run ( $ size , & $ c1 , & $ c2 ) { if ( $ size > 0 ) { if ( $ size <= $ c2 ) { $ rate = $ c2 / $ size ; $ c2 = $ size ; $ c1 = $ c1 / $ rate ; } else { $ rate = $ size / $ c2 ; $ c2 = $ size ; $ c1 = $ c1 * $ rate ; } } }
Calculates the ratio according to the entered numerical value .
21,739
public function jsonSerialize ( ) { $ json = [ ] ; foreach ( [ 'code' , 'message' , 'description' , 'uri' ] as $ field ) { if ( $ this -> $ field !== null ) { $ json [ $ field ] = $ this -> $ field ; } } return $ json ; }
Only include non - null fields in JSON .
21,740
public function addAnonymousPromise ( callable $ promise , ? int $ priority = null ) { $ priority = $ priority ?? static :: DEFAULT_PRIORITY ; $ this -> pool [ ] = compact ( 'priority' , 'promise' ) ; }
Add no named callback to the pool
21,741
public function callAllPromises ( ) { $ pool = $ this -> pool ; usort ( $ pool , function ( $ a , $ b ) { return $ a [ 'priority' ] - $ b [ 'priority' ] ; } ) ; foreach ( $ pool as $ node ) { $ promise = $ node [ 'promise' ] ; $ promise ( ) ; } }
Call all callbacks ordered by priority
21,742
public static function detect ( $ request_uri ) { if ( $ request_uri == '/' ) { return ; } $ request = explode ( '/' , trim ( $ request_uri , '/' ) ) ; $ filename = $ request [ count ( $ request ) - 1 ] ; $ extension = substr ( $ filename , strrpos ( $ filename , '.' ) ) ; if ( strpos ( $ extension , '.' ) !== 0 ) { return ; } $ extension = substr ( $ extension , 1 ) ; $ request_string = implode ( '/' , $ request ) ; $ class = get_called_class ( ) ; if ( strpos ( $ request_string , '&/' ) !== false ) { $ files = explode ( '&/' , $ request_string ) ; $ mtime = 0 ; foreach ( $ files as $ file ) { $ file_mtime = $ class :: fetch ( 'mtime' , $ file , $ extension ) ; if ( $ file_mtime === false ) { $ class :: fail ( ) ; } if ( $ file_mtime > $ mtime ) { $ mtime = $ file_mtime ; } } if ( isset ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ) ) { if ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] == gmdate ( 'D, d M Y H:i:s' , $ mtime ) . ' GMT' ) { $ class :: output ( $ extension , '' , $ mtime ) ; } } $ content = '' ; foreach ( $ files as $ file ) { $ content .= $ class :: fetch ( 'content' , $ file , $ extension ) . "\n" ; } $ content = $ content ; $ filename = 'compacted.' . $ extension ; } else { $ mtime = $ class :: fetch ( 'mtime' , $ request_string , $ extension ) ; if ( $ mtime === false ) { $ class :: fail ( ) ; } if ( isset ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ) ) { if ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] == gmdate ( 'D, d M Y H:i:s' , $ mtime ) . ' GMT' ) { $ class :: output ( $ extension , '' , $ mtime ) ; } } $ content = $ class :: fetch ( 'content' , $ request_string , $ extension ) ; if ( $ content === null ) { return ; } } if ( $ class :: get_mime_type ( $ extension ) == 'text/css' ) { } $ class :: output ( $ extension , $ content , $ mtime ) ; }
Detect if the request is a request for media
21,743
protected static function fetch ( $ type , $ path , $ extension ) { $ packages = \ Skeleton \ Core \ Package :: get_all ( ) ; foreach ( self :: $ filetypes as $ filetype => $ extensions ) { $ filepaths = [ \ Skeleton \ Core \ Config :: $ asset_dir . '/' . $ path , Application :: get ( ) -> media_path . '/' . $ filetype . '/' . $ path , ] ; foreach ( $ packages as $ package ) { $ path_parts = explode ( '/' , $ path ) ; if ( ! isset ( $ path_parts [ 0 ] ) or $ path_parts [ 0 ] != $ package -> name ) { continue ; } unset ( $ path_parts [ 0 ] ) ; $ package_path = $ package -> asset_path . '/' . $ filetype . '/' . implode ( '/' , $ path_parts ) ; $ filepaths [ ] = $ package_path ; } if ( in_array ( $ extension , $ extensions ) ) { foreach ( $ filepaths as $ filepath ) { if ( file_exists ( $ filepath ) ) { if ( $ type == 'mtime' ) { return filemtime ( $ filepath ) ; } else { return file_get_contents ( $ filepath ) ; } } } return false ; } } return null ; }
Fetch the contents and mtime of a file
21,744
private static function output ( $ extension , $ content , $ mtime ) { header ( 'Etag: ' . crc32 ( $ mtime ) . '-' . sha1 ( $ content ) ) ; self :: cache ( $ mtime ) ; header ( 'Content-Type: ' . self :: get_mime_type ( $ extension ) ) ; echo $ content ; exit ( ) ; }
Ouput the content of the file and cache it
21,745
private static function cache ( $ mtime ) { $ gmt_mtime = gmdate ( 'D, d M Y H:i:s' , $ mtime ) . ' GMT' ; header ( 'Cache-Control: public' ) ; header ( 'Pragma: public' ) ; if ( isset ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ) ) { if ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] == $ gmt_mtime ) { header ( 'Expires: ' ) ; HTTP \ Status :: code_304 ( ) ; } } header ( 'Last-Modified: ' . $ gmt_mtime ) ; header ( 'Expires: ' . gmdate ( 'D, d M Y H:i:s' , strtotime ( '+30 minutes' ) ) . ' GMT' ) ; }
Detect if the file should be resent to the client or if it can use its cache
21,746
public function onBeforeNormalization ( BeforeNormalizationEvent $ event ) : void { $ resource = $ event -> getResource ( ) ; if ( $ resource instanceof RelatedResourceInterface ) { $ this -> fixForRelations ( $ resource ) ; } if ( $ resource instanceof ActionedResourceInterface ) { $ this -> fixForActions ( $ resource ) ; } }
Call to this method before normalization
21,747
private function fixForActions ( ActionedResourceInterface $ resource ) : void { $ actions = $ resource -> getActions ( ) ; foreach ( $ actions as $ action ) { $ routeHref = $ action -> getHref ( ) ; $ href = $ this -> fixHref ( $ routeHref ) ; $ action -> setHref ( $ href ) ; } }
Fix links for actions
21,748
private function fixForRelations ( RelatedResourceInterface $ resource ) : void { $ relations = $ resource -> getRelations ( ) ; foreach ( $ relations as $ relation ) { $ routeHref = $ relation -> getHref ( ) ; $ href = $ this -> fixHref ( $ routeHref ) ; $ relation -> setHref ( $ href ) ; } }
Fix links for relations
21,749
private function fixHref ( HrefInterface $ routeHref ) : HrefInterface { if ( ! $ routeHref instanceof SymfonyRouteHref ) { return $ routeHref ; } $ path = $ this -> urlGenerator -> generate ( $ routeHref -> getRouteName ( ) , $ routeHref -> getRouteParameters ( ) , $ routeHref -> getReferenceType ( ) ) ; return new Href ( $ path , $ routeHref -> isTemplated ( ) ) ; }
Try to fix href
21,750
public function actionView ( $ pprs_id , $ ajax = false , $ errors = false ) { $ model = $ this -> loadModel ( $ pprs_id ) ; if ( $ ajax ) { $ this -> renderPartial ( '_view-relations_grids' , array ( 'modelMain' => $ model , 'ajax' => $ ajax , ) ) ; } else { $ this -> render ( 'view' , array ( 'model' => $ model , 'errors' => $ errors ) ) ; } }
show person data
21,751
public function actionCreateUserAccount ( $ pprs_id ) { $ model = $ this -> loadModel ( $ pprs_id ) ; $ r = $ model -> createUser ( ) ; if ( $ r !== true ) { $ this -> redirect ( array ( 'view' , 'pprs_id' => $ pprs_id , 'ajax' => false , 'errors' => $ r ) ) ; } else { $ this -> redirect ( array ( '/user/admin/view' , 'id' => $ model -> getUserId ( ) ) ) ; } }
create fro person data user account and redirect to it
21,752
public function actionAjaxCreateSpec ( $ ccmp_id ) { $ model = new PprsPerson ; $ model -> $ field = $ value ; try { if ( ! $ model -> save ( ) ) { return var_export ( $ model -> getErrors ( ) ) ; } } catch ( Exception $ e ) { throw new CHttpException ( 500 , $ e -> getMessage ( ) ) ; } $ ccuc = new CcucUserCompany ; $ ccuc -> ccuc_ccmp_id = $ ccmp_id ; $ ccuc -> ccuc_person_id = $ model -> pprs_id ; $ ccuc -> ccuc_status = CcucUserCompany :: CCUC_STATUS_PERSON ; $ ccuc -> save ( ) ; }
crreate person for company
21,753
public function setCraftingTime ( float $ craftingTime ) : self { $ this -> craftingTime = ( int ) ( $ craftingTime * self :: FACTOR_CRAFTING_TIME ) ; return $ this ; }
Sets the required time in seconds to craft the recipe .
21,754
public function getOrderedIngredients ( ) : Collection { return $ this -> ingredients -> matching ( Criteria :: create ( ) -> orderBy ( [ 'order' => Criteria :: ASC ] ) ) ; }
Returns the ordered ingredients of the recipe in case the ingredients are not already ordered .
21,755
public function getOrderedProducts ( ) : Collection { return $ this -> products -> matching ( Criteria :: create ( ) -> orderBy ( [ 'order' => Criteria :: ASC ] ) ) ; }
Returns the ordered products of the recipe in case the products are not already ordered .
21,756
protected function ensureResponse ( $ output ) { if ( $ output instanceof Response ) { return $ output ; } elseif ( is_string ( $ output ) ) { return Response :: create ( $ output , 200 ) ; } else { $ message = "Action response cannot be served." ; throw new ApplicationException ( $ message ) ; } }
Ensure output is a proper response object .
21,757
public function find_all_files ( $ dir ) { $ root = scandir ( $ dir ) ; foreach ( $ root as $ value ) { if ( $ value === '.' || $ value === '..' ) { continue ; } if ( is_file ( "$dir/$value" ) ) { $ result [ ] = "$dir/$value" ; $ this -> setAsset ( "$dir/$value" ) ; continue ; } foreach ( $ this -> find_all_files ( "$dir/$value" ) as $ value ) { $ result [ ] = $ value ; } } return $ result ; }
Find All file on asset dir and create array of Model \ Asset
21,758
public function setAsset ( $ path ) { $ url = $ this -> config [ 'dir' ] [ 'site' ] . str_replace ( $ this -> config [ 'dir' ] [ 'asset' ] , '' , $ path ) ; $ this -> assets [ ] = new Asset ( $ path , $ url ) ; }
Create Asset object instance
21,759
public function createContainer ( ) { $ loader = new ContainerLoader ( function ( $ files ) { return array_filter ( $ files , function ( $ file ) { foreach ( $ this -> ignorePaths as $ path ) { if ( Strings :: startsWith ( $ file , $ path ) ) { return false ; } } return true ; } ) ; } , $ this -> getCacheDirectory ( ) . '/Arachne.Configurator' , $ this -> parameters [ 'debugMode' ] ) ; $ class = $ loader -> load ( array ( $ this -> parameters , $ this -> files ) , array ( $ this , 'generateContainer' ) ) ; $ container = new $ class ; $ container -> initialize ( ) ; return $ container ; }
Returns system DI container .
21,760
public function onRegistrationConfirm ( GetResponseUserEvent $ event ) { if ( null === $ event -> getResponse ( ) ) { $ url = $ this -> router -> generate ( 'fos_user_security_login' ) ; $ event -> setResponse ( new RedirectResponse ( $ url ) ) ; } }
Sets the registration date on the user
21,761
static function isLooselyIdentical ( $ a , $ b , bool $ canonicalizeKeys , array & $ visited = [ ] ) : bool { if ( in_array ( [ $ a , $ b ] , $ visited , true ) || in_array ( [ $ b , $ a ] , $ visited , true ) ) { return true ; } $ aType = gettype ( $ a ) ; $ bType = gettype ( $ b ) ; if ( $ aType === 'object' && $ bType === 'object' && get_class ( $ a ) === get_class ( $ b ) && $ a !== $ b ) { return static :: isLooselyIdentical ( ( array ) $ a , ( array ) $ b , $ canonicalizeKeys , $ visited ) ; } if ( $ aType === 'array' && $ bType === 'array' ) { $ visited [ ] = [ $ a , $ b ] ; $ keys = array_keys ( $ a ) ; $ otherKeys = array_keys ( $ b ) ; if ( $ canonicalizeKeys ) { sort ( $ keys ) ; sort ( $ otherKeys ) ; } if ( $ keys !== $ otherKeys ) { return false ; } foreach ( $ keys as $ key ) { if ( ! static :: isLooselyIdentical ( $ a [ $ key ] , $ b [ $ key ] , $ canonicalizeKeys , $ visited ) ) { return false ; } } return true ; } return $ a === $ b ; }
Check whether two values are loosely identical
21,762
public function indexAction ( $ featureId ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ feature = $ em -> getRepository ( 'EcommerceBundle:Feature' ) -> find ( $ featureId ) ; if ( ! $ feature ) { throw $ this -> createNotFoundException ( 'Unable to find Feature entity.' ) ; } return array ( 'feature' => $ feature , ) ; }
Lists all FeatureValue entities .
21,763
public function createAction ( Request $ request , $ featureId ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ feature = $ em -> getRepository ( 'EcommerceBundle:Feature' ) -> find ( $ featureId ) ; if ( ! $ feature ) { throw $ this -> createNotFoundException ( 'Unable to find Feature entity.' ) ; } $ entity = new FeatureValue ( ) ; $ form = $ this -> createForm ( new FeatureValueType ( ) , $ entity ) ; $ entity -> setFeature ( $ feature ) ; $ form -> bind ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'value.created' ) ; return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_featurevalue_show' , array ( 'featureId' => $ featureId , 'id' => $ entity -> getId ( ) ) ) ) ; } return array ( 'entity' => $ entity , 'feature' => $ feature , 'form' => $ form -> createView ( ) , ) ; }
Creates a new FeatureValue entity .
21,764
public function newAction ( $ featureId ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ feature = $ em -> getRepository ( 'EcommerceBundle:Feature' ) -> find ( $ featureId ) ; if ( ! $ feature ) { throw $ this -> createNotFoundException ( 'Unable to find Feature entity.' ) ; } $ entity = new FeatureValue ( ) ; $ form = $ this -> createForm ( new FeatureValueType ( ) , $ entity ) ; return array ( 'entity' => $ entity , 'feature' => $ feature , 'form' => $ form -> createView ( ) , ) ; }
Displays a form to create a new FeatureValue entity .
21,765
public function showAction ( $ featureId , $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ feature = $ em -> getRepository ( 'EcommerceBundle:Feature' ) -> find ( $ featureId ) ; if ( ! $ feature ) { throw $ this -> createNotFoundException ( 'Unable to find Feature entity.' ) ; } $ entity = $ em -> getRepository ( 'EcommerceBundle:FeatureValue' ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find FeatureValue entity.' ) ; } $ deleteForm = $ this -> createDeleteForm ( $ featureId , $ id ) ; return array ( 'entity' => $ entity , 'feature' => $ feature , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Finds and displays a FeatureValue entity .
21,766
public function editAction ( $ featureId , $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ feature = $ em -> getRepository ( 'EcommerceBundle:Feature' ) -> find ( $ featureId ) ; if ( ! $ feature ) { throw $ this -> createNotFoundException ( 'Unable to find Feature entity.' ) ; } $ entity = $ em -> getRepository ( 'EcommerceBundle:FeatureValue' ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find FeatureValue entity.' ) ; } $ editForm = $ this -> createForm ( new FeatureValueType ( ) , $ entity ) ; $ deleteForm = $ this -> createDeleteForm ( $ featureId , $ id ) ; return array ( 'entity' => $ entity , 'feature' => $ feature , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Displays a form to edit an existing FeatureValue entity .
21,767
public function updateAction ( Request $ request , $ featureId , $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ feature = $ em -> getRepository ( 'EcommerceBundle:Feature' ) -> find ( $ featureId ) ; if ( ! $ feature ) { throw $ this -> createNotFoundException ( 'Unable to find Feature entity.' ) ; } $ entity = $ em -> getRepository ( 'EcommerceBundle:FeatureValue' ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find FeatureValue entity.' ) ; } $ deleteForm = $ this -> createDeleteForm ( $ featureId , $ id ) ; $ editForm = $ this -> createForm ( new FeatureValueType ( ) , $ entity ) ; $ editForm -> bind ( $ request ) ; if ( $ editForm -> isValid ( ) ) { $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'value.edited' ) ; return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_featurevalue_show' , array ( 'featureId' => $ featureId , 'id' => $ id ) ) ) ; } return array ( 'entity' => $ entity , 'feature' => $ feature , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Edits an existing FeatureValue entity .
21,768
private function createDeleteForm ( $ featureId , $ id ) { return $ this -> createFormBuilder ( array ( 'featureId' => $ featureId , 'id' => $ id ) ) -> add ( 'featureId' , 'hidden' ) -> add ( 'id' , 'hidden' ) -> getForm ( ) ; }
Creates a form to delete a FeatureValue entity by id .
21,769
public function getReferenceSoft ( $ name ) { if ( ! isset ( $ this -> _manager ) ) { throw new RepositoryException ( 'Model is not handled by a managed repository' ) ; } if ( array_key_exists ( $ name , $ this -> _references ) ) { $ ref = $ this -> _references [ $ name ] ; $ repo = $ this -> _manager -> getByClass ( $ ref [ 'model' ] ) ; if ( ! $ repo || ! ( $ repo instanceof SoftRepositoryInterface ) ) { throw new RepositoryException ( 'Referenced model is not handled by a managed soft-deletion-aware repository' ) ; } return ( $ repo -> findSoft ( $ ref [ 'key' ] , $ this -> { $ ref [ 'attribute' ] } ) ? : null ) ; } return null ; }
Retrieve a reference by name ignoring soft - deleted entries .
21,770
public function creerRepertoire ( $ repertoire , $ droits = 0777 ) { if ( file_exists ( $ repertoire ) ) { if ( ! chmod ( $ repertoire , $ droits ) ) return false ; } else { if ( ! mkdir ( $ repertoire , $ droits ) ) return false ; if ( ! chmod ( $ repertoire , $ droits ) ) return false ; } exec ( "convmv -f iso-8859-1 -t utf-8 -r " . $ repertoire . "/* --notest" , $ retourExec ) ; return true ; }
creation d un repertoire avec mise en place des droits et conversion des nom de fichiers en utf8
21,771
public function getExtensionFromFile ( $ fichier = '' ) { $ retour = "" ; $ split = explode ( "." , $ fichier ) ; if ( count ( $ split ) > 1 ) { $ retour = $ split [ count ( $ split ) - 1 ] ; } return $ retour ; }
renvoi le nom d extension du fichier
21,772
public function getFileNameWithoutExtension ( $ fichier = '' ) { $ retour = "" ; $ trouve = false ; for ( $ i = pia_strlen ( $ fichier ) - 1 ; $ i > 0 && ! $ trouve ; $ i -- ) { if ( pia_substr ( $ fichier , $ i , 1 ) == '.' ) { $ trouve = true ; } } if ( $ trouve ) { $ retour = pia_substr ( $ fichier , 0 , $ i + 1 ) ; } else { $ retour = $ fichier ; } return $ retour ; }
renvoi la partie gauche du nom de fichier la partie avant l extension
21,773
public function getNewFileNameIfFileNameExistsIn ( $ fileName = '' , $ directory = '' ) { $ extension = $ this -> getExtensionFromFile ( $ fileName ) ; $ partieGauche = $ this -> getFileNameWithoutExtension ( $ fileName ) ; $ i = 0 ; while ( file_exists ( $ directory . $ partieGauche . "." . $ extension ) ) { $ partieGauche .= $ i ; $ i ++ ; } return $ partieGauche . "." . $ extension ; }
ajoute un numero a la fin de la partie gauche du fichier si le fichier existe dans le repertoire en parametre
21,774
public function convertDirectoryFilesNamesToUTF8 ( $ params = array ( ) ) { if ( isset ( $ params [ 'repertoire' ] ) && $ params [ 'repertoire' ] != '' ) { $ slash = "/" ; if ( pia_substr ( $ params [ 'repertoire' ] , - 1 ) == '/' ) { $ slash = "" ; } exec ( "convmv -f iso-8859-1 -t utf-8 -r " . $ params [ 'repertoire' ] . $ slash . "* --notest" ) ; } }
utile pour que php puisse lire certains nom de fichier
21,775
public function merge_feeds ( array $ feeds ) { $ source_feeds = [ [ ] ] ; foreach ( $ feeds as $ feed ) { $ source_feeds [ ] = $ feed -> get_items ( ) ; } $ merged_feed = array_merge ( ... $ source_feeds ) ; $ new_feed = $ this -> service -> get_feed ( '' ) ; $ new_feed -> set_items ( $ merged_feed ) ; return $ new_feed ; }
Merge different Feed_Services together . Feeds passed in should have already had retrieve_items called on them .
21,776
public function validate ( array $ input , $ early_exit = false ) { $ result = new Result ( $ input ) ; foreach ( $ this -> rules as $ name => $ rules ) { $ this -> doValidation ( $ result , $ input , $ name , $ rules , $ early_exit ) ; } return $ result ; }
Validate an array of values .
21,777
protected function submitted ( $ value ) { if ( is_string ( $ value ) ) { $ value = trim ( $ value ) ; } if ( empty ( $ value ) && ! is_numeric ( $ value ) ) { return false ; } return true ; }
Check if a value has been submitted . This means not empty or containing only white space .
21,778
public static function childClass ( $ asModel = false , $ initData = [ ] ) { $ data = debug_backtrace ( ) ; $ callingClassName = get_class ( $ data [ 1 ] [ 'object' ] ) ; $ pattern = '#^(.+\\\\)(\w+\\\\\w+)$#' ; $ formName = preg_replace ( $ pattern , '$2' , get_called_class ( ) ) ; $ result = preg_replace ( $ pattern , '$1' . $ formName , $ callingClassName ) ; return $ asModel ? new $ result ( $ initData ) : $ result ; }
Gets class name for a model that inherits current modules model . CAUTION! This works only when called from inside another module model
21,779
public function findObject ( $ type , $ id ) { $ type = $ this -> getFullType ( $ type ) ; if ( class_exists ( $ type ) ) { $ table = $ type :: getCollection ( ) ; if ( ! ( $ id instanceof MongoId ) && $ id !== null ) { try { $ id = new MongoId ( $ id ) ; } catch ( MongoException $ e ) { $ id = null ; } } $ data = $ this -> cache -> fetch ( "{$table}_{$id}" ) ; if ( ! is_array ( $ data ) ) { $ data = $ this -> mongodb -> $ table -> findOne ( [ '_id' => $ id ] ) ; if ( is_array ( $ data ) ) { $ this -> cache -> store ( "{$table}_{$id}" , $ data ) ; } } if ( $ data === null ) { return null ; } return new $ type ( $ data , $ this -> mongodb -> $ table , $ this -> cache ) ; } return null ; }
Find object by it s Mongo ID and return it
21,780
public function findObjectByProp ( $ type , $ name , $ value ) { $ type = $ this -> getFullType ( $ type ) ; if ( class_exists ( $ type ) ) { $ table = $ type :: getCollection ( ) ; $ data = $ this -> mongodb -> $ table -> findOne ( [ $ name => $ value ] ) ; if ( $ data === null ) { return null ; } return new $ type ( $ data , $ this -> mongodb -> $ table , $ this -> cache ) ; } return null ; }
Find object by it s property value and return it
21,781
public function fetchObjects ( $ type , array $ selector = [ ] , array $ order = null , $ limit = null , $ skip = null ) { $ type = $ this -> getFullType ( $ type ) ; if ( class_exists ( $ type ) ) { $ table = $ type :: getCollection ( ) ; $ cursor = $ this -> mongodb -> $ table -> find ( $ selector ) ; if ( $ order ) { $ cursor -> sort ( $ order ) ; } if ( $ limit ) { $ cursor -> limit ( $ limit ) ; } if ( $ skip ) { $ cursor -> skip ( $ skip ) ; } $ result = [ ] ; foreach ( $ cursor as $ data ) { $ obj = new $ type ( $ data , $ this -> mongodb -> $ table , $ this -> cache ) ; $ result [ ] = $ obj ; } return $ result ; } return null ; }
Find all objects using Mongo selector and return them optionally ordered
21,782
public function countObjects ( $ type , $ query = [ ] ) { $ type = $ this -> getFullType ( $ type ) ; if ( class_exists ( $ type ) ) { $ table = $ type :: getCollection ( ) ; return $ this -> mongodb -> $ table -> find ( $ query , [ '_id' => true ] ) -> count ( ) ; } return false ; }
Count objects in collection matching Mongo query
21,783
public function newObject ( $ type , array $ data = [ ] ) { $ type = $ this -> getFullType ( $ type ) ; if ( class_exists ( $ type ) ) { $ table = $ type :: getCollection ( ) ; return new $ type ( $ data , $ this -> mongodb -> $ table , $ this -> cache ) ; } return null ; }
Construct new object
21,784
public function updateObjects ( $ type , array $ query , array $ data ) { $ type = $ this -> getFullType ( $ type ) ; if ( class_exists ( $ type ) ) { $ collection = $ type :: getCollection ( ) ; $ result = $ this -> mongodb -> $ collection -> update ( $ query , [ '$set' => $ data ] , [ 'multiple' => true ] ) ; return $ result [ 'ok' ] ? $ result [ 'n' ] : false ; } return false ; }
Update multiple objects
21,785
public function deleteObjects ( $ type , array $ query = [ ] ) { $ type = $ this -> getFullType ( $ type ) ; if ( class_exists ( $ type ) ) { $ collection = $ type :: getCollection ( ) ; $ result = $ this -> mongodb -> $ collection -> remove ( $ query ) ; return ( bool ) $ result [ 'ok' ] ; } return false ; }
Delete multiple objects
21,786
public function defer ( $ runLevel , $ priority = 10 ) { $ this -> deferred = true ; $ this -> runLevel = $ runLevel ; $ this -> priority = $ priority ; }
Defer the route into desired to later wp_action .
21,787
public function equal ( ColumnInterface $ column , WhereCompareInterface $ value ) { $ columnName = ( $ column -> getAlias ( ) ) ? : $ column -> getColumnName ( ) ; $ condition = $ columnName . ' = ' . $ value -> getCompareValue ( ) ; $ this -> _addCondition ( $ condition ) ; return $ this ; }
Add an equal condition to the condition array . The order of the method call is important in which way the condition string will concatenate .
21,788
public function greater ( ColumnInterface $ column , WhereNumericCompareInterface $ value ) { $ columnName = ( $ column -> getAlias ( ) ) ? : $ column -> getColumnName ( ) ; $ condition = $ columnName . ' > ' . $ value -> getNumericCompareValue ( ) ; $ this -> _addCondition ( $ condition ) ; return $ this ; }
Add a greater condition to the condition array . The order of the method call is important in which way the condition string will concatenate .
21,789
public function between ( ColumnInterface $ column , WhereNumericCompareInterface $ lowerValue , WhereNumericCompareInterface $ greaterValue ) { $ columnName = ( $ column -> getAlias ( ) ) ? : $ column -> getColumnName ( ) ; $ condition = $ columnName . ' BETWEEN ' . $ lowerValue -> getNumericCompareValue ( ) . ' AND ' . $ greaterValue -> getNumericCompareValue ( ) ; $ this -> _addCondition ( $ condition ) ; return $ this ; }
Add a between condition to the condition array . The order of the method call is important in which way the condition string will concatenate .
21,790
public function like ( ColumnInterface $ column , ReferencesInterface $ value , $ level = 0 ) { $ columnName = ( $ column -> getAlias ( ) ) ? : $ column -> getColumnName ( ) ; if ( $ level === 0 ) { $ condition = $ columnName . ' LIKE ' . $ value -> getValue ( ) ; } elseif ( $ level === 1 ) { $ condition = $ columnName . ' LIKE ' . $ this -> _likeLevelOne ( $ value ) ; } elseif ( $ level === 2 ) { $ condition = $ columnName . ' LIKE ' . $ this -> _likeLevelTwo ( $ value ) ; } elseif ( $ level === 3 ) { $ condition = $ columnName . ' LIKE ' . $ this -> _likeLevelThree ( $ value ) ; } else { throw new \ Exception ( 'invalid level argument' ) ; } $ this -> _addCondition ( $ condition ) ; return $ this ; }
Add a like condition to the condition array . The order of the method call is important in which way the condition string will concatenate .
21,791
public function isNull ( ColumnInterface $ column ) { $ columnName = ( $ column -> getAlias ( ) ) ? : $ column -> getColumnName ( ) ; $ condition = $ columnName . ' IS NULL' ; $ this -> _addCondition ( $ condition ) ; return $ this ; }
Add an is null condition to the condition array . The order of the method call is important in which way the condition string will concatenate .
21,792
private function _addCondition ( $ condition ) { if ( $ this -> logicOperator === null && $ this -> invoked === false ) { $ this -> conditionArray [ ] = array ( $ condition ) ; $ this -> invoked = true ; } elseif ( $ this -> logicOperator === null ) { throw new \ Exception ( 'a logic operator method have to be invoked to continue add conditions' ) ; } else { $ this -> conditionArray [ ] = array ( $ this -> logicOperator => $ condition ) ; $ this -> logicOperator = null ; } }
This method fill the condition array in the expected format .
21,793
private function _likeLevelOne ( ReferencesInterface $ value ) { $ regex = '/"/' ; if ( preg_match ( $ regex , $ value -> getValue ( ) ) ) { return preg_replace ( $ regex , '"%' , $ value -> getValue ( ) , 1 ) ; } return '%' . $ value -> getValue ( ) ; }
Validate the value and the percentage sign to a valid value for an expression . The sign will passed at the begin of the value .
21,794
private function _likeLevelTwo ( ReferencesInterface $ value ) { $ regex = '/("[a-zA-Z0-9_-]*)"/' ; $ matches = array ( ) ; if ( preg_match ( $ regex , $ value -> getValue ( ) , $ matches ) ) { return $ matches [ 1 ] . '%"' ; } return $ value -> getValue ( ) . '%' ; }
Validate the value and the percentage sign to a valid value for an expression . The sign will passed at the end of the value .
21,795
private function _likeLevelThree ( ReferencesInterface $ value ) { $ regex = '/"([a-zA-Z0-9_-]*)"/' ; $ matches = array ( ) ; if ( preg_match ( $ regex , $ value -> getValue ( ) , $ matches ) ) { return '"%' . $ matches [ 1 ] . '%"' ; } return '%' . $ value -> getValue ( ) . '%' ; }
Validate the value and the percentage sign to a valid value for an expression . The sign will passed at the begin and at the end of the value .
21,796
public function prepareContent ( ) { $ content = $ this -> content ; if ( $ content instanceof Renderable ) { $ content = $ content -> render ( ) ; } else if ( $ this -> shouldBeJson ( $ content ) ) { $ content = $ this -> toJson ( $ content ) ; } return $ content ; }
Prepare content to be printed out
21,797
public function sendHeaders ( ) { foreach ( $ this -> headers -> all ( ) as $ header => $ value ) { header ( sprintf ( '%s:%s' , $ header , $ value ) ) ; } }
Send the header to browser
21,798
public function connect ( ) { if ( $ this -> isConnected ( ) ) { return true ; } if ( ! $ this -> isEnabled ( ) ) { throw new MissingDriverException ( 'mongodb driver extension is not enabled' ) ; } $ options = [ ] ; if ( $ db = $ this -> getDatabase ( ) ) { $ options [ 'db' ] = $ db ; } if ( $ user = $ this -> getUser ( ) ) { $ options [ 'username' ] = $ user ; } if ( $ pass = $ this -> getPassword ( ) ) { $ options [ 'password' ] = $ pass ; } if ( $ rSet = $ this -> getConfig ( 'replicaSet' ) ) { if ( ! $ this -> getConfig ( 'servers' ) ) { throw new MissingServersException ( 'A list of servers is required for replica set functionality' ) ; } $ options [ 'replicaSet' ] = $ rSet ; } $ connection = new MongoClient ( $ this -> getServer ( ) , $ options + $ this -> getConfig ( 'flags' ) ) ; $ this -> _connections [ $ this -> getContext ( ) ] = $ connection ; return $ connection -> connected ; }
Connect to the Mongo database .
21,799
public function getServer ( ) { $ server = 'mongodb://' ; if ( $ servers = $ this -> getConfig ( 'servers' ) ) { $ server .= implode ( ',' , $ servers ) ; } else { if ( $ socket = $ this -> getSocket ( ) ) { $ server .= $ socket ; } else { $ server .= $ this -> getHost ( ) . ':' . $ this -> getPort ( ) ; } } return $ server ; }
Build and return the server connection .