idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
53,600
|
public function createProductAPI ( $ url ) { $ api = new Product ( $ url ) ; if ( ! $ this -> getHttpClient ( ) ) { $ this -> setHttpClient ( ) ; } if ( ! $ this -> getEntityFactory ( ) ) { $ this -> setEntityFactory ( ) ; } return $ api -> registerDiffbot ( $ this ) ; }
|
Creates a Product API interface
|
53,601
|
public function createArticleAPI ( $ url ) { $ api = new Article ( $ url ) ; if ( ! $ this -> getHttpClient ( ) ) { $ this -> setHttpClient ( ) ; } if ( ! $ this -> getEntityFactory ( ) ) { $ this -> setEntityFactory ( ) ; } return $ api -> registerDiffbot ( $ this ) ; }
|
Creates an Article API interface
|
53,602
|
public function createImageAPI ( $ url ) { $ api = new Image ( $ url ) ; if ( ! $ this -> getHttpClient ( ) ) { $ this -> setHttpClient ( ) ; } if ( ! $ this -> getEntityFactory ( ) ) { $ this -> setEntityFactory ( ) ; } return $ api -> registerDiffbot ( $ this ) ; }
|
Creates an Image API interface
|
53,603
|
public function createAnalyzeAPI ( $ url ) { $ api = new Analyze ( $ url ) ; if ( ! $ this -> getHttpClient ( ) ) { $ this -> setHttpClient ( ) ; } if ( ! $ this -> getEntityFactory ( ) ) { $ this -> setEntityFactory ( ) ; } return $ api -> registerDiffbot ( $ this ) ; }
|
Creates an Analyze API interface
|
53,604
|
public function createDiscussionAPI ( $ url ) { $ api = new Discussion ( $ url ) ; if ( ! $ this -> getHttpClient ( ) ) { $ this -> setHttpClient ( ) ; } if ( ! $ this -> getEntityFactory ( ) ) { $ this -> setEntityFactory ( ) ; } return $ api -> registerDiffbot ( $ this ) ; }
|
Creates an Discussion API interface
|
53,605
|
public function createCustomAPI ( $ url , $ name ) { $ api = new Custom ( $ url , $ name ) ; if ( ! $ this -> getHttpClient ( ) ) { $ this -> setHttpClient ( ) ; } if ( ! $ this -> getEntityFactory ( ) ) { $ this -> setEntityFactory ( ) ; } return $ api -> registerDiffbot ( $ this ) ; }
|
Creates a generic Custom API
|
53,606
|
public function crawl ( $ name = null , Api $ api = null ) { $ api = new Crawl ( $ name , $ api ) ; if ( ! $ this -> getHttpClient ( ) ) { $ this -> setHttpClient ( ) ; } if ( ! $ this -> getEntityFactory ( ) ) { $ this -> setEntityFactory ( ) ; } return $ api -> registerDiffbot ( $ this ) ; }
|
Creates a new Crawljob with the given name .
|
53,607
|
public function search ( $ q ) { $ api = new Search ( $ q ) ; if ( ! $ this -> getHttpClient ( ) ) { $ this -> setHttpClient ( ) ; } if ( ! $ this -> getEntityFactory ( ) ) { $ this -> setEntityFactory ( ) ; } return $ api -> registerDiffbot ( $ this ) ; }
|
Search query .
|
53,608
|
private function getArchiveFiles ( ) : array { $ list = [ ] ; for ( $ i = 0 ; $ i < $ this -> getArchive ( ) -> numFiles ; $ i ++ ) { $ file = $ this -> getArchive ( ) -> statIndex ( $ i ) ; if ( $ file === false ) { continue ; } $ name = str_replace ( '\\' , '/' , $ file [ 'name' ] ) ; if ( ( $ name [ 0 ] == "." && in_array ( $ this -> getSkipMode ( ) , [ "HIDDEN" , "ALL" ] ) ) || ( $ name [ 0 ] == "." && @ $ name [ 1 ] == "_" && in_array ( $ this -> getSkipMode ( ) , [ "COMODOJO" , "ALL" ] ) ) ) { continue ; } $ list [ ] = $ name ; } return $ list ; }
|
Get a list of file contained in zip archive before extraction
|
53,609
|
private function addItem ( string $ file , bool $ flatroot = false , int $ compression = self :: CM_DEFAULT , int $ encryption = self :: EM_NONE , ? string $ base = null ) : void { $ file = is_null ( $ this -> getPath ( ) ) ? $ file : $ this -> getPath ( ) . "/$file" ; $ real_file = str_replace ( '\\' , '/' , realpath ( $ file ) ) ; $ real_name = basename ( $ real_file ) ; if ( $ base !== null && ( ( $ real_name [ 0 ] == "." && in_array ( $ this -> getSkipMode ( ) , [ "HIDDEN" , "ALL" ] ) ) || ( $ real_name [ 0 ] == "." && @ $ real_name [ 1 ] == "_" && in_array ( $ this -> getSkipMode ( ) , [ "COMODOJO" , "ALL" ] ) ) ) ) { return ; } if ( is_dir ( $ real_file ) ) { $ this -> addDirectoryItem ( $ real_file , $ real_name , $ compression , $ encryption , $ base , $ flatroot ) ; } else { $ this -> addFileItem ( $ real_file , $ real_name , $ compression , $ encryption , $ base ) ; } }
|
Add item to zip archive
|
53,610
|
private function deleteItem ( string $ file ) : void { if ( $ this -> getArchive ( ) -> deleteName ( $ file ) === false ) { throw new ZipException ( StatusCodes :: get ( $ this -> getArchive ( ) -> status ) ) ; } }
|
Delete item from zip archive
|
53,611
|
private static function openZipFile ( string $ zip_file , int $ flags = null ) : ZipArchive { $ zip = new ZipArchive ( ) ; $ open = $ zip -> open ( $ zip_file , $ flags ) ; if ( $ open !== true ) { throw new ZipException ( StatusCodes :: get ( $ open ) ) ; } return $ zip ; }
|
Open a zip file
|
53,612
|
protected function _processAssociation ( Event $ event , EntityInterface $ entity , Association $ assoc , array $ settings ) { $ foreignKeys = ( array ) $ assoc -> foreignKey ( ) ; $ primaryKeys = ( array ) $ assoc -> bindingKey ( ) ; $ countConditions = $ entity -> extract ( $ foreignKeys ) ; $ updateConditions = array_combine ( $ primaryKeys , $ countConditions ) ; $ countOriginalConditions = $ entity -> extractOriginalChanged ( $ foreignKeys ) ; if ( $ countOriginalConditions !== [ ] ) { $ updateOriginalConditions = array_combine ( $ primaryKeys , $ countOriginalConditions ) ; } foreach ( $ settings as $ field => $ config ) { if ( is_int ( $ field ) ) { $ field = $ config ; $ config = [ ] ; } if ( ! is_string ( $ config ) && is_callable ( $ config ) ) { $ count = $ config ( $ event , $ entity , $ this -> _table , false , $ countConditions ) ; } else { $ count = $ this -> _getCount ( $ config , $ countConditions ) ; } $ assoc -> target ( ) -> updateAll ( [ $ field => $ count ] , $ updateConditions ) ; if ( isset ( $ updateOriginalConditions ) ) { if ( ! is_string ( $ config ) && is_callable ( $ config ) ) { $ count = $ config ( $ event , $ entity , $ this -> _table , true , $ countOriginalConditions ) ; } else { $ count = $ this -> _getCount ( $ config , $ countOriginalConditions ) ; } $ assoc -> target ( ) -> updateAll ( [ $ field => $ count ] , $ updateOriginalConditions ) ; } } }
|
Updates sum cache for a single association
|
53,613
|
public function beforeSave ( Event $ event , Entity $ entity ) { $ config = $ this -> _config ; foreach ( $ config [ 'fields' ] as $ field => $ fieldOption ) { $ data = $ entity -> toArray ( ) ; $ virtualField = $ field . $ config [ 'suffix' ] ; if ( ! isset ( $ data [ $ virtualField ] ) || ! is_array ( $ data [ $ virtualField ] ) ) { continue ; } $ file = $ entity -> get ( $ virtualField ) ; $ error = $ this -> _triggerErrors ( $ file ) ; if ( $ error === false ) { continue ; } elseif ( is_string ( $ error ) ) { throw new \ ErrorException ( $ error ) ; } if ( ! isset ( $ fieldOption [ 'path' ] ) ) { throw new \ LogicException ( __ ( 'The path for the {0} field is required.' , $ field ) ) ; } if ( isset ( $ fieldOption [ 'prefix' ] ) && ( is_bool ( $ fieldOption [ 'prefix' ] ) || is_string ( $ fieldOption [ 'prefix' ] ) ) ) { $ this -> _prefix = $ fieldOption [ 'prefix' ] ; } $ extension = ( new File ( $ file [ 'name' ] , false ) ) -> ext ( ) ; $ uploadPath = $ this -> _getUploadPath ( $ entity , $ fieldOption [ 'path' ] , $ extension ) ; if ( ! $ uploadPath ) { throw new \ ErrorException ( __ ( 'Error to get the uploadPath.' ) ) ; } $ folder = new Folder ( $ this -> _config [ 'root' ] ) ; $ folder -> create ( $ this -> _config [ 'root' ] . dirname ( $ uploadPath ) ) ; if ( $ this -> _moveFile ( $ entity , $ file [ 'tmp_name' ] , $ uploadPath , $ field , $ fieldOption ) ) { if ( ! $ this -> _prefix ) { $ this -> _prefix = '' ; } $ entity -> set ( $ field , $ this -> _prefix . $ uploadPath ) ; } $ entity -> unsetProperty ( $ virtualField ) ; } }
|
Check if there is some files to upload and modify the entity before it is saved .
|
53,614
|
protected function _triggerErrors ( $ file ) { if ( ! empty ( $ file [ 'error' ] ) ) { switch ( ( int ) $ file [ 'error' ] ) { case UPLOAD_ERR_INI_SIZE : $ message = __ ( 'The uploaded file exceeds the upload_max_filesize directive in php.ini : {0}' , ini_get ( 'upload_max_filesize' ) ) ; break ; case UPLOAD_ERR_FORM_SIZE : $ message = __ ( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.' ) ; break ; case UPLOAD_ERR_NO_FILE : $ message = false ; break ; case UPLOAD_ERR_PARTIAL : $ message = __ ( 'The uploaded file was only partially uploaded.' ) ; break ; case UPLOAD_ERR_NO_TMP_DIR : $ message = __ ( 'Missing a temporary folder.' ) ; break ; case UPLOAD_ERR_CANT_WRITE : $ message = __ ( 'Failed to write file to disk.' ) ; break ; case UPLOAD_ERR_EXTENSION : $ message = __ ( 'A PHP extension stopped the file upload.' ) ; break ; default : $ message = __ ( 'Unknown upload error.' ) ; } return $ message ; } }
|
Trigger upload errors .
|
53,615
|
protected function _moveFile ( Entity $ entity , $ source = false , $ destination = false , $ field = false , array $ options = [ ] ) { if ( $ source === false || $ destination === false || $ field === false ) { return false ; } if ( isset ( $ options [ 'overwrite' ] ) && is_bool ( $ options [ 'overwrite' ] ) ) { $ this -> _overwrite = $ options [ 'overwrite' ] ; } if ( $ this -> _overwrite ) { $ this -> _deleteOldUpload ( $ entity , $ field , $ destination , $ options ) ; } $ file = new File ( $ source , false , 0755 ) ; if ( $ file -> copy ( $ this -> _config [ 'root' ] . $ destination , $ this -> _overwrite ) ) { return true ; } return false ; }
|
Move the temporary source file to the destination file .
|
53,616
|
protected function _deleteOldUpload ( Entity $ entity , $ field = false , $ newFile = false , array $ options = [ ] ) { if ( $ field === false || $ newFile === false ) { return true ; } $ fileInfo = pathinfo ( $ entity -> $ field ) ; $ newFileInfo = pathinfo ( $ newFile ) ; if ( isset ( $ options [ 'defaultFile' ] ) && ( is_bool ( $ options [ 'defaultFile' ] ) || is_string ( $ options [ 'defaultFile' ] ) ) ) { $ this -> _defaultFile = $ options [ 'defaultFile' ] ; } if ( $ fileInfo [ 'basename' ] == $ newFileInfo [ 'basename' ] || $ fileInfo [ 'basename' ] == pathinfo ( $ this -> _defaultFile ) [ 'basename' ] ) { return true ; } if ( $ this -> _prefix ) { $ entity -> $ field = str_replace ( $ this -> _prefix , "" , $ entity -> $ field ) ; } $ file = new File ( $ this -> _config [ 'root' ] . $ entity -> $ field , false ) ; if ( $ file -> exists ( ) ) { $ file -> delete ( ) ; return true ; } return false ; }
|
Delete the old upload file before to save the new file .
|
53,617
|
public function action ( $ actions , $ function ) { if ( ! is_array ( $ actions ) ) { $ actions = [ $ actions ] ; } $ controller = $ this -> _current [ 'controller' ] ; foreach ( $ actions as $ action ) { $ path = $ controller . '.' . $ action ; self :: $ _data = Hash :: insert ( self :: $ _data , $ path , [ 'function' => $ function , 'roles' => [ ] , ] ) ; $ this -> _runFunction ( $ action ) ; } }
|
Sets authorization per action . The action variable can be a string or array of strings
|
53,618
|
public function setTimeout ( $ timeout = null ) { if ( $ timeout === null ) { $ timeout = 30000 ; } if ( ! is_int ( $ timeout ) ) { throw new \ InvalidArgumentException ( 'Parameter is not an integer' ) ; } if ( $ timeout < 0 ) { throw new \ InvalidArgumentException ( 'Parameter is negative. Only positive timeouts accepted.' ) ; } $ this -> timeout = $ timeout ; return $ this ; }
|
Setting the timeout will define how long Diffbot will keep trying to fetch the API results . A timeout can happen for various reasons from Diffbot s failure to the site being crawled being exceptionally slow and more .
|
53,619
|
protected function option ( $ display , $ value , array $ attributes = [ ] ) { $ options = [ 'value' => $ value ] + $ attributes ; return $ this -> toHtmlString ( '<option' . $ this -> attributes ( $ options ) . '>' . e ( $ display ) . '</option>' ) ; }
|
Generates a single option for the select dropdown .
|
53,620
|
public function autocomplete ( $ name , $ list = [ ] , $ selected = [ ] , array $ inputAttributes = [ ] , array $ spanAttributes = [ ] , $ inputOnly = false ) { $ inputAttributes [ 'id' ] = $ name . '-ms' ; if ( ! isset ( $ inputAttributes [ 'class' ] ) ) { $ inputAttributes [ 'class' ] = 'multiselect' ; } $ spanHtml = $ inputOnly ? '' : $ this -> span ( $ name , $ list , $ selected , $ spanAttributes ) ; $ inputAttributes = $ this -> attributes ( $ inputAttributes ) ; return $ this -> toHtmlString ( $ spanHtml . "<input type=\"text\"{$inputAttributes}>" ) ; }
|
Create the multi - select autocomplete field and optionally the already selected span field . This method interface mimicks LaravelCollective \ html select method .
|
53,621
|
public function select ( $ name , $ list = [ ] , $ selected = [ ] , array $ selectAttributes = [ ] , array $ optionsAttributes = [ ] , array $ spanAttributes = [ ] , $ selectOnly = false ) { $ selectAttributes [ 'id' ] = $ name . '-ms' ; if ( ! isset ( $ selectAttributes [ 'class' ] ) ) { $ selectAttributes [ 'class' ] = 'multiselect' ; } $ spanHtml = $ selectOnly ? '' : $ this -> span ( $ name , $ list , $ selected , $ spanAttributes ) ; $ html = [ ] ; if ( isset ( $ selectAttributes [ 'placeholder' ] ) ) { $ html [ ] = $ this -> option ( $ selectAttributes [ 'placeholder' ] , '' ) ; unset ( $ selectAttributes [ 'placeholder' ] ) ; } else { $ html [ ] = $ this -> option ( ' ' , '' ) ; } foreach ( $ list as $ value => $ display ) { $ optionAttributes = isset ( $ optionsAttributes [ $ value ] ) ? $ optionsAttributes [ $ value ] : [ ] ; $ html [ ] = $ this -> option ( $ display , $ value , $ optionAttributes ) ; } $ list = implode ( '' , $ html ) ; $ selectAttributes = $ this -> attributes ( $ selectAttributes ) ; return $ this -> toHtmlString ( $ spanHtml . "<select{$selectAttributes}>{$list}</select>" ) ; }
|
Create the multi - select select box field and optionally the already selected span field . This method interface mimicks LaravelCollective \ html select method .
|
53,622
|
public function spanElement ( $ name , $ display , $ value ) { $ options = [ 'onClick' => '$(this).remove();' , 'class' => 'multiselector' ] ; return $ this -> toHtmlString ( '<span' . $ this -> attributes ( $ options ) . '>' . '<input type="hidden" name="' . $ name . '[]" value="' . $ value . '">' . e ( $ display ) . '</span>' ) ; }
|
Generates a single span with pre - selected options with relevant options .
|
53,623
|
public function say ( $ text ) { $ message = $ this -> getSpeechBubble ( $ text ) ; return str_replace ( '{{bubble}}' , $ message , $ this -> character ) ; }
|
Make the animal speak .
|
53,624
|
public function extendBubble ( $ message ) { $ characterLength = $ this -> getMaxLineLength ( $ this -> character ) ; $ exploded_message = explode ( "\n" , $ message ) ; $ padded_message = array_map ( function ( $ line ) use ( $ characterLength ) { return str_pad ( $ line , $ characterLength , ' ' ) ; } , $ exploded_message ) ; return implode ( "\n" , $ padded_message ) ; }
|
Used to pad the bubble to fit at least the size of the animal with empty spaces .
|
53,625
|
public function getMessageLines ( $ text ) { $ message = $ text ; $ wrapLength = 40 ; $ message = wordwrap ( $ message , $ wrapLength - 2 ) ; return explode ( "\n" , $ message ) ; }
|
Obtain the message as array wrapping the text
|
53,626
|
public function getMaxLineLength ( $ lines ) { if ( ! is_array ( $ lines ) ) { $ lines = explode ( "\n" , $ lines ) ; } $ lineLength = 0 ; foreach ( $ lines as $ line ) { $ currentLineLength = strlen ( $ line ) ; if ( $ currentLineLength > $ lineLength ) { $ lineLength = $ currentLineLength ; } } return $ lineLength ; }
|
Find the longest line and get the line length
|
53,627
|
public function getSpeechBubble ( $ text ) { $ lines = $ this -> getMessageLines ( $ text ) ; $ lineLength = $ this -> getMaxLineLength ( $ lines ) ; $ text = '' ; $ numberOfLines = count ( $ lines ) ; $ firstLine = str_pad ( array_shift ( $ lines ) , $ lineLength ) ; if ( $ numberOfLines === 1 ) { $ text = "< {$firstLine} >" ; } else { $ lastLine = str_pad ( array_pop ( $ lines ) , $ lineLength ) ; $ text = "/ {$firstLine} \\\n" ; foreach ( $ lines as $ line ) { $ line = str_pad ( $ line , $ lineLength ) ; $ text .= "| {$line} |\n" ; } $ text .= "\\ {$lastLine} /" ; } $ text = $ this -> extendBubble ( $ text ) ; return $ text ; }
|
Obtain the speech bubble .
|
53,628
|
public function defineModelClasses ( $ modelClasses = [ ] ) { $ this -> modelMap = ArrayHelper :: merge ( $ this -> getDefaultModels ( ) , $ this -> modelMap , $ modelClasses ) ; }
|
Merges the default and user defined model classes Also let s the developer to set new ones with the parameter being those the ones with most preference .
|
53,629
|
public function model ( $ name , $ config = [ ] ) { $ modelData = $ this -> modelMap [ ucfirst ( $ name ) ] ; if ( ! empty ( $ config ) ) { if ( is_string ( $ modelData ) ) { $ modelData = [ 'class' => $ modelData ] ; } $ modelData = ArrayHelper :: merge ( $ modelData , $ config ) ; } return $ modelData ; }
|
Get defined className of model
|
53,630
|
public static function createFromConfig ( $ config , $ rpcHelper = null ) { $ clientId = $ config [ 'clientId' ] ; $ projectId = $ config [ 'projectId' ] ; if ( ! isset ( $ clientId ) && ! isset ( $ projectId ) ) { throw new Gitkit_ClientException ( "Missing projectId or clientId in server configuration." ) ; } if ( ! isset ( $ config [ 'widgetUrl' ] ) ) { throw new Gitkit_ClientException ( "\"widgetUrl\" should be configured" ) ; } if ( isset ( $ config [ "cookieName" ] ) ) { $ cookieName = $ config [ 'cookieName' ] ; } else { $ cookieName = self :: $ DEFAULT_COOKIE_NAME ; } if ( ! $ rpcHelper ) { if ( ! isset ( $ config [ 'serviceAccountEmail' ] ) ) { throw new Gitkit_ClientException ( "\"serviceAccountEmail\" should be configured" ) ; } if ( ! isset ( $ config [ 'serviceAccountPrivateKeyFile' ] ) ) { throw new Gitkit_ClientException ( "\"serviceAccountPrivateKeyFile\" should be configured" ) ; } $ p12Key = file_get_contents ( $ config [ "serviceAccountPrivateKeyFile" ] ) ; if ( $ p12Key === false ) { throw new Gitkit_ClientException ( "Can not read file " . $ config [ "serviceAccountPrivateKeyFile" ] ) ; } if ( isset ( $ config [ 'serverApiKey' ] ) ) { $ serverApiKey = $ config [ 'serverApiKey' ] ; } else { $ serverApiKey = null ; } $ rpcHelper = new Gitkit_RpcHelper ( $ config [ "serviceAccountEmail" ] , $ p12Key , self :: $ GITKIT_API_BASE , new Google_Auth_OAuth2 ( new Google_Client ( ) ) , $ serverApiKey ) ; } return new Gitkit_Client ( $ clientId , $ config [ 'widgetUrl' ] , $ cookieName , $ rpcHelper , $ projectId ) ; }
|
Creates a Gitkit client from the config array .
|
53,631
|
public function validateToken ( $ gitToken ) { if ( $ gitToken ) { $ loginTicket = null ; $ auds = array_filter ( array ( $ this -> projectId , $ this -> clientId ) , function ( $ x ) { return isset ( $ x ) ; } ) ; foreach ( $ auds as $ aud ) { try { $ loginTicket = $ this -> oauth2Client -> verifySignedJwtWithCerts ( $ gitToken , $ this -> getCerts ( ) , $ aud , self :: $ GTIKIT_TOKEN_ISSUER , 180 * 86400 ) -> getAttributes ( ) ; break ; } catch ( Google_Auth_Exception $ e ) { if ( strpos ( $ e -> getMessage ( ) , "Wrong recipient" ) === false ) { throw $ e ; } } } if ( ! isset ( $ loginTicket ) ) { throw new Google_Auth_Exception ( "Gitkit token audience doesn't match projectId or clientId in server configuration." ) ; } $ jwt = $ loginTicket [ "payload" ] ; if ( $ jwt ) { $ user = new Gitkit_Account ( ) ; $ user -> setUserId ( $ jwt [ "user_id" ] ) ; $ user -> setEmail ( $ jwt [ "email" ] ) ; if ( isset ( $ jwt [ "provider_id" ] ) ) { $ user -> setProviderId ( $ jwt [ "provider_id" ] ) ; } else { $ user -> setProviderId ( null ) ; } $ user -> setEmailVerified ( $ jwt [ "verified" ] ) ; if ( isset ( $ jwt [ "display_name" ] ) ) { $ user -> setDisplayName ( $ jwt [ "display_name" ] ) ; } if ( isset ( $ jwt [ "photo_url" ] ) ) { $ user -> setPhotoUrl ( $ jwt [ "photo_url" ] ) ; } return $ user ; } } return null ; }
|
Validates a Gitkit token . User info is extracted from the token only .
|
53,632
|
public function getUserInRequest ( ) { if ( isset ( $ _COOKIE [ $ this -> cookieName ] ) ) { $ user = $ this -> validateToken ( $ _COOKIE [ $ this -> cookieName ] , $ this -> clientId ) ; if ( $ user ) { $ accountInfo = $ this -> getUserById ( $ user -> getUserId ( ) ) ; $ accountInfo -> setProviderId ( $ user -> getProviderId ( ) ) ; return $ accountInfo ; } } return null ; }
|
Gets GitkitUser for the http request . Complete user info is retrieved from Gitkit server .
|
53,633
|
public function uploadUsers ( $ hashAlgorithm , $ hashKey , $ accounts , $ rounds = null , $ memoryCost = null ) { $ this -> rpcHelper -> uploadAccount ( $ hashAlgorithm , $ hashKey , $ this -> toJsonRequest ( $ accounts ) , $ rounds , $ memoryCost ) ; }
|
Uploads multiple accounts info to Gitkit server .
|
53,634
|
public function getOobResults ( $ param = null , $ user_ip = null , $ gitkit_token = null ) { if ( ! $ param ) { $ param = $ _POST ; } if ( ! $ user_ip ) { $ user_ip = $ _SERVER [ 'REMOTE_ADDR' ] ; } if ( ! $ gitkit_token ) { $ gitkit_token = $ this -> getTokenString ( ) ; } if ( isset ( $ param [ 'action' ] ) ) { try { if ( $ param [ 'action' ] == 'resetPassword' ) { $ oob_link = $ this -> buildOobLink ( $ this -> passwordResetRequest ( $ param , $ user_ip ) , $ param [ 'action' ] ) ; return $ this -> passwordResetResponse ( $ oob_link , $ param ) ; } else if ( $ param [ 'action' ] == 'changeEmail' ) { if ( ! $ gitkit_token ) { return $ this -> failureOobMsg ( 'login is required' ) ; } $ oob_link = $ this -> buildOobLink ( $ this -> changeEmailRequest ( $ param , $ user_ip , $ gitkit_token ) , $ param [ 'action' ] ) ; return $ this -> emailChangeResponse ( $ oob_link , $ param ) ; } } catch ( Gitkit_ClientException $ error ) { return $ this -> failureOobMsg ( $ error -> getMessage ( ) ) ; } } return $ this -> failureOobMsg ( 'unknown action type' ) ; }
|
Gets out - of - band results for ResetPassword ChangeEmail operations etc .
|
53,635
|
private function toJsonRequest ( $ accounts ) { $ jsonUsers = array ( ) ; foreach ( $ accounts as $ account ) { $ user = array ( 'email' => $ account -> getEmail ( ) , 'localId' => $ account -> getUserId ( ) , 'emailVerified' => $ account -> isEmailVerified ( ) , 'displayName' => $ account -> getDisplayName ( ) , 'passwordHash' => Google_Utils :: urlSafeB64Encode ( $ account -> getPasswordHash ( ) ) , 'salt' => Google_Utils :: urlSafeB64Encode ( $ account -> getSalt ( ) ) ) ; array_push ( $ jsonUsers , $ user ) ; } return $ jsonUsers ; }
|
Converts Gitkit account array to json request .
|
53,636
|
private function buildOobLink ( $ param , $ action ) { $ code = $ this -> rpcHelper -> getOobCode ( $ param ) ; $ separator = parse_url ( $ this -> widgetUrl , PHP_URL_QUERY ) ? '&' : '?' ; return $ this -> widgetUrl . $ separator . http_build_query ( array ( 'mode' => $ action , 'oobCode' => $ code ) ) ; }
|
Builds the url of out - of - band confirmation .
|
53,637
|
protected function setNullableFields ( ) { foreach ( $ this -> nullableFromArray ( $ this -> getAttributes ( ) ) as $ key => $ value ) { $ this -> attributes [ $ key ] = $ this -> nullIfEmpty ( $ value , $ key ) ; } }
|
Set empty nullable fields to null .
|
53,638
|
public function nullIfEmpty ( $ value , $ key = null ) { if ( ! is_null ( $ key ) ) { $ value = $ this -> fetchValueForKey ( $ key , $ value ) ; } if ( is_array ( $ value ) ) { return $ this -> nullIfEmptyArray ( $ key , $ value ) ; } if ( is_bool ( $ value ) ) { return $ value ; } return trim ( $ value ) === '' ? null : $ value ; }
|
If value is empty return null otherwise return the original input .
|
53,639
|
protected function nullableFromArray ( array $ attributes = [ ] ) { if ( is_array ( $ this -> nullable ) && count ( $ this -> nullable ) > 0 ) { return array_intersect_key ( $ attributes , array_flip ( $ this -> nullable ) ) ; } return [ ] ; }
|
Get the nullable attributes of a given array .
|
53,640
|
private function getJsonCastValue ( $ value ) { return method_exists ( $ this , 'fromJson' ) ? $ this -> fromJson ( $ value ) : json_decode ( $ value , true ) ; }
|
Return value of the json - encoded value as a native PHP type
|
53,641
|
private function fetchValueForKey ( $ key , $ value ) { if ( in_array ( $ key , $ this -> getDates ( ) ) ) { return trim ( $ value ) === '' ? null : $ value ; } if ( ! $ this -> hasSetMutator ( $ key ) ) { $ value = $ this -> getAttribute ( $ key ) ; } if ( $ this -> isJsonCastable ( $ key ) && ! is_null ( $ value ) ) { $ value = is_string ( $ value ) ? $ this -> getJsonCastValue ( $ value ) : $ value ; } return $ value ; }
|
For the given key and value pair determine the actual value depending on whether or not a mutator or cast is in use .
|
53,642
|
private function nullIfEmptyArray ( $ key , $ value ) { if ( $ this -> isJsonCastable ( $ key ) && ! empty ( $ value ) ) { return $ this -> setJsonCastValue ( $ value ) ; } return empty ( $ value ) ? null : $ value ; }
|
Determine whether an array value is empty taking into account casting .
|
53,643
|
public function inherit ( ) { if ( ( bool ) Config :: getOption ( "plugins.dataInheritance.enabled" ) ) { $ storeData = Data :: get ( ) ; $ storePatternData = PatternData :: get ( ) ; foreach ( $ storePatternData as $ patternStoreKey => $ patternData ) { if ( isset ( $ patternData [ "lineages" ] ) && ( count ( $ patternData [ "lineages" ] ) > 0 ) ) { $ dataLineage = array ( ) ; foreach ( $ patternData [ "lineages" ] as $ lineage ) { $ lineageKey = $ lineage [ "lineagePattern" ] ; $ lineageData = isset ( $ storeData [ "patternSpecific" ] [ $ lineageKey ] ) && isset ( $ storeData [ "patternSpecific" ] [ $ lineageKey ] [ "data" ] ) ? $ storeData [ "patternSpecific" ] [ $ lineageKey ] [ "data" ] : array ( ) ; if ( ! empty ( $ lineageData ) ) { $ dataLineage = array_replace_recursive ( $ dataLineage , $ lineageData ) ; } } $ dataPattern = isset ( $ storeData [ "patternSpecific" ] [ $ patternStoreKey ] ) && isset ( $ storeData [ "patternSpecific" ] [ $ patternStoreKey ] [ "data" ] ) ? $ storeData [ "patternSpecific" ] [ $ patternStoreKey ] [ "data" ] : array ( ) ; $ dataPattern = array_replace_recursive ( $ dataLineage , $ dataPattern ) ; if ( ! empty ( $ dataPattern ) ) { $ storeData [ "patternSpecific" ] [ $ patternStoreKey ] [ "data" ] = $ dataPattern ; } } } Data :: replaceStore ( $ storeData ) ; } }
|
Look up data in lineages update pattern store data replace store
|
53,644
|
public function getGitkitCerts ( ) { $ certUrl = $ this -> gitkitApisUrl . 'publicKeys' ; if ( $ this -> apiKey ) { return $ this -> oauth2Client -> retrieveCertsFromLocation ( $ certUrl . '?key=' . $ this -> apiKey ) ; } else { $ httpRequest = new Google_Http_Request ( $ certUrl ) ; $ response = $ this -> oauth2Client -> authenticatedRequest ( $ httpRequest ) -> getResponseBody ( ) ; return json_decode ( $ response ) ; } }
|
Downloads Gitkit public certs .
|
53,645
|
public function updateAccount ( $ gitkitAccount ) { $ data = array ( 'email' => $ gitkitAccount -> getEmail ( ) , 'localId' => $ gitkitAccount -> getUserId ( ) , 'displayName' => $ gitkitAccount -> getDisplayName ( ) , 'emailVerified' => $ gitkitAccount -> isEmailVerified ( ) , 'photoUrl' => $ gitkitAccount -> getPhotoUrl ( ) ) ; return $ this -> invokeGitkitApiWithServiceAccount ( 'setAccountInfo' , $ data ) ; }
|
Invokes the SetAccountInfo API .
|
53,646
|
public function uploadAccount ( $ hashAlgorithm , $ hashKey , $ accounts , $ rounds , $ memoryCost ) { $ data = array ( 'hashAlgorithm' => $ hashAlgorithm , 'signerKey' => Google_Utils :: urlSafeB64Encode ( $ hashKey ) , 'users' => $ accounts ) ; if ( $ rounds ) { $ data [ 'rounds' ] = $ rounds ; } if ( $ memoryCost ) { $ data [ 'memoryCost' ] = $ memoryCost ; } $ this -> invokeGitkitApiWithServiceAccount ( 'uploadAccount' , $ data ) ; }
|
Invokes the UploadAccount API .
|
53,647
|
public function downloadAccount ( $ nextPageToken = null , $ maxResults = 10 ) { $ data = array ( ) ; if ( $ nextPageToken ) { $ data [ 'nextPageToken' ] = $ nextPageToken ; } $ data [ 'maxResults' ] = $ maxResults ; return $ this -> invokeGitkitApiWithServiceAccount ( 'downloadAccount' , $ data ) ; }
|
Invokes the DownloadAccount API .
|
53,648
|
public function getOobCode ( $ param ) { $ response = $ this -> invokeGitkitApiWithServiceAccount ( 'getOobConfirmationCode' , $ param ) ; if ( isset ( $ response [ 'oobCode' ] ) ) { return $ response [ 'oobCode' ] ; } else { throw new Gitkit_ClientException ( "can not get oob-code" ) ; } }
|
Invokes the GetOobConfirmationCode API .
|
53,649
|
public function invokeGitkitApiWithServiceAccount ( $ method , $ data ) { $ httpRequest = new Google_Http_Request ( $ this -> gitkitApisUrl . $ method , 'POST' , null , json_encode ( $ data ) ) ; $ contentTypeHeader = array ( ) ; $ contentTypeHeader [ 'content-type' ] = 'application/json; charset=UTF-8' ; $ httpRequest -> setRequestHeaders ( $ contentTypeHeader ) ; $ response = $ this -> oauth2Client -> authenticatedRequest ( $ httpRequest ) -> getResponseBody ( ) ; return $ this -> checkGitkitError ( json_decode ( $ response , true ) ) ; }
|
Sends the authenticated request to Gitkit API . The request contains an OAuth2 access_token generated from service account .
|
53,650
|
public function checkGitkitError ( $ response ) { if ( isset ( $ response [ 'error' ] ) ) { $ error = $ response [ 'error' ] ; if ( ! isset ( $ error [ 'code' ] ) ) { throw new Gitkit_ServerException ( 'null error code from Gitkit server' ) ; } else { $ code = $ error [ 'code' ] ; if ( strpos ( $ code , '4' ) === 0 ) { throw new Gitkit_ClientException ( $ error [ 'message' ] ) ; } else { throw new Gitkit_ServerException ( $ error [ 'message' ] ) ; } } } else { return $ response ; } }
|
Checks the error in the response .
|
53,651
|
public function addProvider ( $ name , ReindexProviderInterface $ provider ) { if ( isset ( $ this -> providers [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Reindex provider with name "%s" has already been registered.' , $ name ) ) ; } $ this -> providers [ $ name ] = $ provider ; }
|
Add a reindex provider to the registry .
|
53,652
|
public function getProvider ( $ name ) { if ( ! isset ( $ this -> providers [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown provider "%s", registered reindex providers: "%s"' , $ name , implode ( '", "' , array_keys ( $ this -> providers ) ) ) ) ; } return $ this -> providers [ $ name ] ; }
|
Return a specific provider .
|
53,653
|
private function truncate ( $ text , $ length , $ suffix = '...' ) { $ computedLength = $ length - strlen ( $ suffix ) ; return strlen ( $ text ) > $ computedLength ? substr ( $ text , 0 , $ computedLength ) . $ suffix : $ text ; }
|
Truncate the given string .
|
53,654
|
private function expandQueryIndexes ( SearchQuery $ query ) { $ expandedIndexes = [ ] ; foreach ( $ query -> getIndexes ( ) as $ index ) { foreach ( $ this -> getDecoratedIndexNames ( $ index , $ query -> getLocale ( ) ) as $ expandedIndex ) { $ expandedIndexes [ $ expandedIndex ] = $ expandedIndex ; } } $ query -> setIndexes ( $ expandedIndexes ) ; }
|
Add additional indexes to the Query object .
|
53,655
|
private function validateQuery ( SearchQuery $ query ) { $ indexNames = $ this -> getIndexNames ( ) ; $ queryIndexNames = $ query -> getIndexes ( ) ; foreach ( $ queryIndexNames as $ queryIndexName ) { if ( ! in_array ( $ queryIndexName , $ indexNames ) ) { $ unknownIndexes [ ] = $ queryIndexName ; } } if ( false === empty ( $ unknownIndexes ) ) { throw new Exception \ SearchException ( sprintf ( 'Search indexes "%s" not known. Known indexes: "%s"' , implode ( '", "' , $ queryIndexNames ) , implode ( '", "' , $ indexNames ) ) ) ; } }
|
If query has indexes ensure that they are known .
|
53,656
|
public function store ( ) { if ( $ this -> id !== null ) { $ method = 'PUT' ; $ path = '/' . $ this -> id ; } else { $ method = 'POST' ; $ path = '' ; } $ response = $ this -> request ( $ method , $ path , [ ] , json_encode ( $ this -> data ) ) ; $ treatedContent = $ response -> getTreatedContent ( ) ; $ this -> id = $ treatedContent [ '_id' ] ; $ this -> version = $ treatedContent [ '_version' ] ; $ this -> dirty = false ; }
|
Stores this document . If ID is given PUT will be used ; else POST
|
53,657
|
public function getField ( $ fieldName , $ silent = false ) { if ( ! array_key_exists ( $ fieldName , $ this -> data ) && $ silent === false ) { throw new ElasticSearchException ( sprintf ( 'The field %s was not present in data of document in %s/%s.' , $ fieldName , $ this -> type -> getIndex ( ) -> getName ( ) , $ this -> type -> getName ( ) ) , 1340274696 ) ; } return $ this -> data [ $ fieldName ] ; }
|
Gets a specific field s value from this data
|
53,658
|
public function onIndex ( IndexEvent $ event ) { try { $ this -> searchManager -> index ( $ event -> getSubject ( ) ) ; } catch ( MetadataNotFoundException $ ex ) { } }
|
Index subject from event .
|
53,659
|
public function request ( $ method , $ path = null , array $ arguments = [ ] , $ content = null ) { return $ this -> requestService -> request ( $ method , $ this , $ path , $ arguments , $ content ) ; }
|
Passes a request through to the request service
|
53,660
|
public function setLanguage ( $ language ) { if ( ! array_key_exists ( $ language , $ this -> allowedlanguages ) ) { throw new InvalidArgumentException ( "Invalid language ISO code" ) ; } $ this -> parameters [ 'language' ] = $ language ; }
|
ISO code eg nl_BE
|
53,661
|
protected function extractShaSign ( array $ parameters ) { if ( ! array_key_exists ( self :: SHASIGN_FIELD , $ parameters ) || $ parameters [ self :: SHASIGN_FIELD ] == '' ) { throw new InvalidArgumentException ( 'SHASIGN parameter not present in parameters.' ) ; } return $ parameters [ self :: SHASIGN_FIELD ] ; }
|
Set Ogone SHA sign
|
53,662
|
public function isValid ( ShaComposer $ shaComposer ) { if ( function_exists ( 'hash_equals' ) ) { return hash_equals ( $ shaComposer -> compose ( $ this -> parameters ) , $ this -> shaSign ) ; } else { return $ shaComposer -> compose ( $ this -> parameters ) == $ this -> shaSign ; } }
|
Checks if the response is valid
|
53,663
|
public function addIndexMetadata ( $ contextName , IndexMetadata $ indexMetadata ) { if ( isset ( $ this -> indexMetadatas [ $ contextName ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Context name "%s" has already been registered' , $ contextName ) ) ; } $ indexMetadata -> setName ( $ this -> name ) ; $ indexMetadata -> setClassMetadata ( $ this ) ; $ this -> indexMetadatas [ $ contextName ] = $ indexMetadata ; }
|
Add an index metadata for the given context name .
|
53,664
|
public function getIndexMetadata ( $ contextName ) { if ( ! isset ( $ this -> indexMetadatas [ $ contextName ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Context name "%s" not known, known contexts: "%s"' , $ contextName , implode ( '", "' , array_keys ( $ this -> indexMetadatas ) ) ) ) ; } return $ this -> indexMetadatas [ $ contextName ] ; }
|
Return the indexmetadata for the given context .
|
53,665
|
public static function getPreferredFormat ( ServerRequestInterface $ request ) { $ acceptTypes = $ request -> getHeader ( 'accept' ) ; if ( count ( $ acceptTypes ) > 0 ) { $ acceptType = $ acceptTypes [ 0 ] ; $ counters = [ ] ; foreach ( self :: $ formats as $ format => $ values ) { foreach ( $ values as $ value ) { $ counters [ $ format ] = isset ( $ counters [ $ format ] ) ? $ counters [ $ format ] : 0 ; $ counters [ $ format ] += intval ( strpos ( $ acceptType , $ value ) !== false ) ; } } asort ( $ counters ) ; end ( $ counters ) ; return key ( $ counters ) ; } return 'html' ; }
|
Returns the preferred format based on the Accept header
|
53,666
|
public static function getAllProcessors ( $ objectManager ) { $ reflectionService = $ objectManager -> get ( ReflectionService :: class ) ; $ processorClassNames = $ reflectionService -> getAllImplementationClassNamesForInterface ( IndexSettingProcessorInterface :: class ) ; $ processors = [ ] ; foreach ( $ processorClassNames as $ processorClassName ) { $ processors [ $ processorClassName ] = [ 'priority' => $ processorClassName :: getPriority ( ) , 'className' => $ processorClassName ] ; } return array_reverse ( ( new PositionalArraySorter ( $ processors , 'priority' ) ) -> toArray ( ) ) ; }
|
Returns all class names implementing the IndexSettingProcessorInterface .
|
53,667
|
public static function buildIndexClassesAndProperties ( $ objectManager ) { $ reflectionService = $ objectManager -> get ( ReflectionService :: class ) ; $ indexAnnotations = [ ] ; $ annotationClassName = Indexable :: class ; foreach ( $ reflectionService -> getClassNamesByAnnotation ( $ annotationClassName ) as $ className ) { if ( $ reflectionService -> isClassAbstract ( $ className ) ) { throw new ElasticSearchException ( sprintf ( 'The class with name "%s" is annotated with %s, but is abstract. Indexable classes must not be abstract.' , $ className , $ annotationClassName ) , 1339595182 ) ; } $ indexAnnotations [ $ className ] [ 'annotation' ] = $ reflectionService -> getClassAnnotation ( $ className , $ annotationClassName ) ; $ annotatedProperties = $ reflectionService -> getPropertyNamesByAnnotation ( $ className , $ annotationClassName ) ; if ( ! empty ( $ annotatedProperties ) ) { $ indexAnnotations [ $ className ] [ 'properties' ] = $ annotatedProperties ; } else { foreach ( $ reflectionService -> getClassPropertyNames ( $ className ) as $ propertyName ) { $ indexAnnotations [ $ className ] [ 'properties' ] [ ] = $ propertyName ; } } } return $ indexAnnotations ; }
|
Creates the source array of what classes and properties have to be annotated . The returned array consists of class names with a sub - key having both annotation and properties set . The annotation contains the class s annotation while properties contains each property that has to be indexed . Each property might either have TRUE as value or also an annotation instance if given .
|
53,668
|
public function getAllIndexNames ( ) { $ indexes = [ ] ; foreach ( $ this -> getClassesAndAnnotations ( ) as $ configuration ) { $ indexes [ $ configuration -> indexName ] = $ configuration -> indexName ; } return array_keys ( $ indexes ) ; }
|
Returns all indexes name deplared in class annotations
|
53,669
|
public function getClassesAndAnnotations ( ) { static $ classesAndAnnotations ; if ( $ classesAndAnnotations === null ) { $ classesAndAnnotations = [ ] ; foreach ( array_keys ( $ this -> indexAnnotations ) as $ className ) { $ classesAndAnnotations [ $ className ] = $ this -> indexAnnotations [ $ className ] [ 'annotation' ] ; } } return $ classesAndAnnotations ; }
|
Returns the to - index classes and their annotation
|
53,670
|
protected function getSearchManager ( ) { return new SearchManager ( $ this -> kernel -> getContainer ( ) -> get ( $ this -> adapterId ) , $ this -> kernel -> getContainer ( ) -> get ( 'massive_search_test.metadata.provider.chain' ) , $ this -> kernel -> getContainer ( ) -> get ( 'massive_search_test.object_to_document_converter' ) , $ this -> kernel -> getContainer ( ) -> get ( 'event_dispatcher' ) , $ this -> kernel -> getContainer ( ) -> get ( 'massive_search_test.index_name_decorator.default' ) , $ this -> kernel -> getContainer ( ) -> get ( 'massive_search_test.metadata.field_evaluator' ) ) ; }
|
Return the search manager using the configured adapter ID .
|
53,671
|
public function onIndexRebuild ( IndexRebuildEvent $ event ) { foreach ( $ this -> adapter -> listIndexes ( ) as $ indexName ) { if ( ! $ this -> indexNameDecorator -> isVariant ( $ this -> indexNameDecorator -> undecorate ( $ indexName ) , $ indexName ) ) { continue ; } $ event -> getOutput ( ) -> writeln ( sprintf ( '<info>Optimizing zend lucene index:</info> %s' , $ indexName ) ) ; $ this -> adapter -> optimize ( $ indexName ) ; } }
|
Optimize the search indexes after the index rebuild event has been fired . Should have a priority low enough in order for it to be executed after all the actual index builders .
|
53,672
|
protected function buildArrayFromMappingCollection ( MappingCollection $ mappingCollection ) { $ return = [ ] ; foreach ( $ mappingCollection as $ mappingInformation ) { $ indexName = $ mappingInformation -> getType ( ) -> getIndex ( ) -> getName ( ) ; $ typeName = $ mappingInformation -> getType ( ) -> getName ( ) ; if ( isset ( $ return [ $ indexName ] [ $ typeName ] ) ) { throw new ElasticSearchException ( 'There was more than one mapping present in index %s with type %s, which must not happen.' , 1339758480 ) ; } $ return [ $ indexName ] [ $ typeName ] [ 'mappingInstance' ] = $ mappingInformation ; $ return [ $ indexName ] [ $ typeName ] [ 'properties' ] = $ mappingInformation -> getProperties ( ) ; } return $ return ; }
|
Traverses through mappingInformation array and aggregates by index and type names
|
53,673
|
public function convergeCommand ( $ clientName = null ) { $ client = $ this -> clientFactory -> create ( $ clientName ) ; $ entityMappingCollection = $ this -> entityMappingBuilder -> buildMappingInformation ( ) ; $ this -> backendMappingBuilder -> setClient ( $ client ) ; $ backendMappingCollection = $ this -> backendMappingBuilder -> buildMappingInformation ( ) ; $ additiveMappings = $ entityMappingCollection -> diffAgainstCollection ( $ backendMappingCollection ) ; foreach ( $ additiveMappings as $ mapping ) { $ index = $ mapping -> getType ( ) -> getIndex ( ) ; $ index -> setClient ( $ client ) ; if ( ! $ index -> exists ( ) ) { $ this -> outputFormatted ( 'Index <b>%s</b> does not exist' , [ $ index -> getName ( ) ] ) ; continue ; } $ this -> outputLine ( 'Attempt to apply properties to %s/%s: %s... ' , [ $ index -> getName ( ) , $ mapping -> getType ( ) -> getName ( ) , print_r ( $ mapping -> getProperties ( ) , true ) , ] ) ; $ response = $ mapping -> apply ( ) ; if ( $ response -> getStatusCode ( ) === 200 ) { $ this -> outputFormatted ( '<b>OK</b>' ) ; } else { $ this -> outputFormatted ( '<b>NOT OK</b>, response code was %d, response body was: %s' , [ $ response -> getStatusCode ( ) , $ response -> getOriginalResponse ( ) -> getContent ( ) , ] , 4 ) ; } } if ( $ additiveMappings -> count ( ) === 0 ) { $ this -> outputLine ( 'No mappings were to be applied.' ) ; } }
|
This command will adjust the backend s mapping to the mapping the entity status prescribes .
|
53,674
|
public function objectToDocument ( IndexMetadata $ metadata , $ object ) { $ indexNameField = $ metadata -> getIndexName ( ) ; $ idField = $ metadata -> getIdField ( ) ; $ urlField = $ metadata -> getUrlField ( ) ; $ titleField = $ metadata -> getTitleField ( ) ; $ descriptionField = $ metadata -> getDescriptionField ( ) ; $ imageUrlField = $ metadata -> getImageUrlField ( ) ; $ localeField = $ metadata -> getLocaleField ( ) ; $ fieldMapping = $ metadata -> getFieldMapping ( ) ; $ document = $ this -> factory -> createDocument ( ) ; $ document -> setIndex ( $ this -> fieldEvaluator -> getValue ( $ object , $ indexNameField ) ) ; $ document -> setId ( $ this -> fieldEvaluator -> getValue ( $ object , $ idField ) ) ; $ document -> setClass ( $ metadata -> getName ( ) ) ; if ( $ urlField ) { $ url = $ this -> fieldEvaluator -> getValue ( $ object , $ urlField ) ; if ( $ url ) { $ document -> setUrl ( $ url ) ; } } if ( $ titleField ) { $ title = $ this -> fieldEvaluator -> getValue ( $ object , $ titleField ) ; if ( $ title ) { $ document -> setTitle ( $ title ) ; } } if ( $ descriptionField ) { $ description = $ this -> fieldEvaluator -> getValue ( $ object , $ descriptionField ) ; if ( $ description ) { $ document -> setDescription ( $ description ) ; } } if ( $ imageUrlField ) { $ imageUrl = $ this -> fieldEvaluator -> getValue ( $ object , $ imageUrlField ) ; $ document -> setImageUrl ( $ imageUrl ) ; } if ( $ localeField ) { $ locale = $ this -> fieldEvaluator -> getValue ( $ object , $ localeField ) ; $ document -> setLocale ( $ locale ) ; } $ this -> populateDocument ( $ document , $ object , $ fieldMapping ) ; return $ document ; }
|
Map the given object to a new document using the given metadata .
|
53,675
|
public function setPropertyByPath ( $ path , $ value ) { $ this -> properties = Arrays :: setValueByPath ( $ this -> properties , $ path , $ value ) ; }
|
Gets a property setting by its path
|
53,676
|
public function asArray ( ) { return [ $ this -> type -> getName ( ) => Arrays :: arrayMergeRecursiveOverrule ( [ 'dynamic_templates' => $ this -> getDynamicTemplates ( ) , 'properties' => $ this -> getProperties ( ) , ] , $ this -> fullMapping ) , ] ; }
|
Return the mapping which would be sent to the server as array
|
53,677
|
public function setSubscriptionPeriod ( SubscriptionPeriod $ period ) { $ this -> parameters [ 'sub_period_unit' ] = $ period -> getUnit ( ) ; $ this -> parameters [ 'sub_period_number' ] = $ period -> getInterval ( ) ; $ this -> parameters [ 'sub_period_moment' ] = $ period -> getMoment ( ) ; }
|
Set subscription payment interval
|
53,678
|
private function removePrefix ( $ decoratedIndexName ) { if ( 0 === strpos ( $ decoratedIndexName , $ this -> prefix . '_' ) ) { $ decoratedIndexName = substr ( $ decoratedIndexName , strlen ( $ this -> prefix ) + 1 ) ; return $ decoratedIndexName ; } return $ decoratedIndexName ; }
|
Removes the prefix added by this decorator from the index name .
|
53,679
|
private function getFieldType ( Field $ field ) { if ( $ field -> isStored ( ) && $ field -> isIndexed ( ) ) { return 'text' ; } if ( false === $ field -> isStored ( ) && $ field -> isIndexed ( ) ) { return 'unStored' ; } if ( $ field -> isStored ( ) && false === $ field -> isIndexed ( ) ) { return 'unIndexed' ; } throw new \ InvalidArgumentException ( sprintf ( 'Field "%s" cannot be both not indexed and not stored' , $ field -> getName ( ) ) ) ; }
|
Return the zend lucene field type to use for the given field .
|
53,680
|
public function preRemove ( LifecycleEventArgs $ event ) { $ event = new DeindexEvent ( $ event -> getEntity ( ) ) ; $ this -> eventDispatcher -> dispatch ( SearchEvents :: DEINDEX , $ event ) ; }
|
Deindex entities after they have been removed .
|
53,681
|
public function getValue ( $ object , FieldInterface $ field ) { try { switch ( get_class ( $ field ) ) { case 'Massive\Bundle\SearchBundle\Search\Metadata\Field\Property' : return $ this -> getPropertyValue ( $ object , $ field ) ; case 'Massive\Bundle\SearchBundle\Search\Metadata\Field\Expression' : return $ this -> getExpressionValue ( $ object , $ field ) ; case 'Massive\Bundle\SearchBundle\Search\Metadata\Field\Field' : return $ this -> getFieldValue ( $ object , $ field ) ; case 'Massive\Bundle\SearchBundle\Search\Metadata\Field\Value' : return $ field -> getValue ( ) ; } } catch ( \ Exception $ e ) { throw new \ Exception ( sprintf ( 'Error encountered when trying to determine value from object "%s"' , get_class ( $ object ) ) , null , $ e ) ; } throw new \ RuntimeException ( sprintf ( 'Unknown field type "%s" when trying to convert "%s" into a search document' , get_class ( $ field ) , get_class ( $ object ) ) ) ; }
|
Evaluate the value from the given object and field .
|
53,682
|
private function getFieldValue ( $ object , Field $ field ) { if ( is_array ( $ object ) ) { $ path = '[' . $ field -> getName ( ) . ']' ; } else { $ path = $ field -> getName ( ) ; } return $ this -> accessor -> getValue ( $ object , $ path ) ; }
|
Return a value determined from the name of the field rather than an explicit property .
|
53,683
|
public function purgeIndexes ( IndexRebuildEvent $ event ) { if ( ! $ event -> getPurge ( ) ) { return ; } foreach ( $ this -> searchManager -> getIndexNames ( ) as $ indexName ) { $ event -> getOutput ( ) -> writeln ( '<info>Purging index</info>: ' . $ indexName ) ; $ this -> searchManager -> purge ( $ indexName ) ; } }
|
Purges all indexes if the purge option is set .
|
53,684
|
public function getConfigTreeBuilder ( ) { $ treeBuilder = new TreeBuilder ( ) ; $ treeBuilder -> root ( 'massive_search' ) -> children ( ) -> arrayNode ( 'services' ) -> addDefaultsifNotSet ( ) -> children ( ) -> scalarNode ( 'factory' ) -> defaultValue ( 'massive_search.factory_default' ) -> end ( ) -> end ( ) -> end ( ) -> enumNode ( 'adapter' ) -> values ( [ 'zend_lucene' , 'elastic' , 'test' ] ) -> defaultValue ( 'zend_lucene' ) -> end ( ) -> arrayNode ( 'adapters' ) -> addDefaultsifNotSet ( ) -> children ( ) -> arrayNode ( 'zend_lucene' ) -> addDefaultsifNotSet ( ) -> children ( ) -> booleanNode ( 'hide_index_exception' ) -> defaultValue ( false ) -> end ( ) -> scalarNode ( 'basepath' ) -> defaultValue ( '%kernel.root_dir%/data' ) -> end ( ) -> scalarNode ( 'encoding' ) -> defaultValue ( 'UTF-8' ) -> end ( ) -> end ( ) -> end ( ) -> arrayNode ( 'elastic' ) -> addDefaultsifNotSet ( ) -> children ( ) -> scalarNode ( 'version' ) -> defaultValue ( '2.2' ) -> end ( ) -> arrayNode ( 'hosts' ) -> defaultValue ( [ 'localhost:9200' ] ) -> prototype ( 'scalar' ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) -> arrayNode ( 'metadata' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> scalarNode ( 'prefix' ) -> defaultValue ( 'massive' ) -> end ( ) -> scalarNode ( 'cache_dir' ) -> defaultValue ( '%kernel.cache_dir%/massive-search' ) -> end ( ) -> booleanNode ( 'debug' ) -> defaultValue ( '%kernel.debug%' ) -> end ( ) -> end ( ) -> end ( ) -> arrayNode ( 'persistence' ) -> addDefaultsifNotSet ( ) -> children ( ) -> arrayNode ( 'doctrine_orm' ) -> canBeEnabled ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) ; return $ treeBuilder ; }
|
Returns the config tree builder .
|
53,685
|
public function onDeindex ( DeindexEvent $ event ) { try { $ this -> searchManager -> deindex ( $ event -> getSubject ( ) ) ; } catch ( MetadataNotFoundException $ ex ) { } }
|
Deindex subject from event .
|
53,686
|
public function findDocumentById ( $ id ) { $ response = $ this -> request ( 'GET' , '/' . $ id ) ; if ( $ response -> getStatusCode ( ) !== 200 ) { return null ; } return $ this -> documentFactory -> createFromResponse ( $ this , $ id , $ response ) ; }
|
Returns a document
|
53,687
|
public function createCommand ( $ indexName , $ clientName = null ) { if ( ! in_array ( $ indexName , $ this -> indexInformer -> getAllIndexNames ( ) ) ) { $ this -> outputFormatted ( "The index <b>%s</b> is not configured in the current application" , [ $ indexName ] ) ; $ this -> quit ( 1 ) ; } $ client = $ this -> clientFactory -> create ( $ clientName ) ; try { $ index = new Index ( $ indexName , $ client ) ; if ( $ index -> exists ( ) ) { $ this -> outputFormatted ( "The index <b>%s</b> exists" , [ $ indexName ] ) ; $ this -> quit ( 1 ) ; } $ index -> create ( ) ; $ this -> outputFormatted ( "Index <b>%s</b> created with success" , [ $ indexName ] ) ; } catch ( Exception $ exception ) { $ this -> outputFormatted ( "Unable to create an index named: <b>%s</b>" , [ $ indexName ] ) ; $ this -> quit ( 1 ) ; } }
|
Create a new index in ElasticSearch
|
53,688
|
public function showConfiguredTypesCommand ( ) { $ classesAndAnnotations = $ this -> indexInformer -> getClassesAndAnnotations ( ) ; $ this -> outputFormatted ( "<b>Available document type</b>" ) ; foreach ( $ classesAndAnnotations as $ className => $ annotation ) { $ this -> outputFormatted ( "%s" , [ $ className ] , 4 ) ; } }
|
List available document type
|
53,689
|
protected function getIndexTypeForObject ( $ object , Client $ client = null ) { if ( $ client === null ) { $ client = $ this -> client ; } $ className = TypeHandling :: getTypeForValue ( $ object ) ; $ indexAnnotation = $ this -> indexInformer -> getClassAnnotation ( $ className ) ; if ( $ indexAnnotation === null ) { return null ; } $ index = $ client -> findIndex ( $ indexAnnotation -> indexName ) ; return new GenericType ( $ index , $ indexAnnotation -> typeName ) ; }
|
Returns the ElasticSearch type for a specific object by its annotation
|
53,690
|
protected function getIndexablePropertiesAndValuesFromObject ( $ object ) { $ className = TypeHandling :: getTypeForValue ( $ object ) ; $ data = [ ] ; foreach ( $ this -> indexInformer -> getClassProperties ( $ className ) as $ propertyName ) { if ( ObjectAccess :: isPropertyGettable ( $ object , $ propertyName ) === false ) { continue ; } $ value = ObjectAccess :: getProperty ( $ object , $ propertyName ) ; if ( ( $ transformAnnotation = $ this -> reflectionService -> getPropertyAnnotation ( $ className , $ propertyName , TransformAnnotation :: class ) ) !== null ) { $ value = $ this -> transformerFactory -> create ( $ transformAnnotation -> type ) -> transformByAnnotation ( $ value , $ transformAnnotation ) ; } $ data [ $ propertyName ] = $ value ; } return $ data ; }
|
Returns a multidimensional array with the indexable probably transformed values of an object
|
53,691
|
public function objectIndexActionRequired ( $ object , Client $ client = null ) { $ type = $ this -> getIndexTypeForObject ( $ object , $ client ) ; if ( $ type === null ) { return null ; } $ id = $ this -> persistenceManager -> getIdentifierByObject ( $ object ) ; $ document = $ type -> findDocumentById ( $ id ) ; if ( $ document !== null ) { $ objectData = $ this -> getIndexablePropertiesAndValuesFromObject ( $ object ) ; if ( strcmp ( json_encode ( $ objectData ) , json_encode ( $ document -> getData ( ) ) ) === 0 ) { $ actionType = null ; } else { $ actionType = self :: ACTION_TYPE_UPDATE ; } } else { $ actionType = self :: ACTION_TYPE_CREATE ; } return $ actionType ; }
|
Returns if and what treatment an object requires regarding the index state i . e . it checks the given object against the index and tells whether deletion update or creation is required .
|
53,692
|
private function createMapFunction ( ) { return new ExpressionFunction ( 'map' , function ( $ elements , $ expression ) { throw new \ Exception ( 'Map function does not support compilation' ) ; } , function ( array $ values , $ elements , $ expression ) { if ( empty ( $ elements ) ) { return [ ] ; } $ result = [ ] ; foreach ( $ elements as $ element ) { $ result [ ] = $ this -> evaluate ( $ expression , [ 'el' => $ element , ] ) ; } return $ result ; } ) ; }
|
Map is an analogue for array_map . The callback in the form of an expression . The nested expression has one variable el .
|
53,693
|
public static function resolve ( array $ controllers ) { $ callbacks = [ ] ; foreach ( $ controllers as $ controller ) { $ qualifiedController = '\\' . trim ( $ controller , '\\' ) ; $ callbacks [ $ controller ] = function ( ContainerInterface $ container ) use ( $ qualifiedController ) { $ controller = new $ qualifiedController ( ) ; if ( $ controller instanceof Controller ) { $ controller -> setContainer ( $ container ) ; } return $ controller ; } ; } return $ callbacks ; }
|
Create service callbacks .
|
53,694
|
private function getIndexStatus ( ) { if ( version_compare ( $ this -> version , '2.2' , '>' ) ) { return $ this -> client -> indices ( ) -> stats ( [ 'index' => '_all' ] ) ; } return $ this -> client -> indices ( ) -> status ( [ 'index' => '_all' ] ) ; }
|
Returns index - status .
|
53,695
|
private function getMapping ( \ SimpleXmlElement $ mapping , $ field ) { $ field = $ mapping -> $ field ; if ( ! $ field -> getName ( ) ) { return ; } return $ this -> getField ( $ field ) ; }
|
Return the value object for the mapping .
|
53,696
|
public function addSorting ( $ sort , $ order = SearchQuery :: SORT_ASC ) { $ this -> searchQuery -> addSorting ( $ sort , $ order ) ; return $ this ; }
|
Set the sort Field .
|
53,697
|
public function getMimeType ( ) { $ finfo = finfo_open ( FILEINFO_MIME ) ; $ mime = finfo_file ( $ finfo , $ this -> getFullPath ( ) ) ; return $ mime ; }
|
Get the mime type for the file .
|
53,698
|
public function forFile ( FileInterface $ file ) { $ filter = function ( $ review ) use ( $ file ) { if ( $ review -> canReview ( $ file ) ) { return true ; } return false ; } ; return $ this -> select ( $ filter ) ; }
|
Returns a filtered ReviewCollection that should be run against the given file .
|
53,699
|
public function forMessage ( CommitMessageInterface $ message ) { $ filter = function ( $ review ) use ( $ message ) { if ( $ review -> canReview ( $ message ) ) { return true ; } return false ; } ; return $ this -> select ( $ filter ) ; }
|
Returns a filtered ReviewCollection that should be run against the given message .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.