idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
48,800
public function update ( $ criteria , $ newobj , array $ options = [ ] ) { $ this -> mustBeArrayOrObject ( $ criteria ) ; $ this -> mustBeArrayOrObject ( $ newobj ) ; $ this -> checkKeys ( ( array ) $ newobj ) ; $ multiple = isset ( $ options [ 'multiple' ] ) ? $ options [ 'multiple' ] : false ; $ isReplace = ! \ Mongo...
Update records based on a given criteria
48,801
public function remove ( array $ criteria = [ ] , array $ options = [ ] ) { $ multiple = isset ( $ options [ 'justOne' ] ) ? ! $ options [ 'justOne' ] : true ; $ method = $ multiple ? 'deleteMany' : 'deleteOne' ; try { $ result = $ this -> collection -> $ method ( TypeConverter :: fromLegacy ( $ criteria ) , $ this -> ...
Remove records from this collection
48,802
public function distinct ( $ key , array $ query = [ ] ) { try { return array_map ( [ TypeConverter :: class , 'toLegacy' ] , $ this -> collection -> distinct ( $ key , TypeConverter :: fromLegacy ( $ query ) ) ) ; } catch ( \ MongoDB \ Driver \ Exception \ Exception $ e ) { return false ; } }
Retrieve a list of distinct values for the given key across a collection
48,803
public function findAndModify ( array $ query , array $ update = null , array $ fields = null , array $ options = [ ] ) { $ query = TypeConverter :: fromLegacy ( $ query ) ; try { if ( isset ( $ options [ 'remove' ] ) ) { unset ( $ options [ 'remove' ] ) ; $ document = $ this -> collection -> findOneAndDelete ( $ query...
Update a document and return it
48,804
public function findOne ( $ query = [ ] , array $ fields = [ ] , array $ options = [ ] ) { if ( ! is_array ( $ query ) ) { trigger_error ( sprintf ( 'MongoCollection::findOne(): expects parameter 1 to be an array or object, %s given' , gettype ( $ query ) ) , E_USER_WARNING ) ; return ; } $ options = [ 'projection' => ...
Querys this collection returning a single element
48,805
public function deleteIndex ( $ keys ) { if ( is_string ( $ keys ) ) { $ indexName = $ keys ; if ( ! preg_match ( '#_-?1$#' , $ indexName ) ) { $ indexName .= '_1' ; } } elseif ( is_array ( $ keys ) ) { $ indexName = \ MongoDB \ generate_index_name ( $ keys ) ; } else { throw new \ InvalidArgumentException ( ) ; } try ...
Deletes an index from this collection
48,806
public function deleteIndexes ( ) { try { return TypeConverter :: toLegacy ( $ this -> collection -> dropIndexes ( ) ) ; } catch ( \ MongoDB \ Driver \ Exception \ Exception $ e ) { return ExceptionConverter :: toResultArray ( $ e ) ; } }
Delete all indexes for this collection
48,807
public function getIndexInfo ( ) { $ convertIndex = function ( \ MongoDB \ Model \ IndexInfo $ indexInfo ) { $ infos = [ 'v' => $ indexInfo -> getVersion ( ) , 'key' => $ indexInfo -> getKey ( ) , 'name' => $ indexInfo -> getName ( ) , 'ns' => $ indexInfo -> getNamespace ( ) , ] ; $ additionalKeys = [ 'unique' , 'spars...
Returns an array of index names for this collection
48,808
public function count ( $ query = [ ] , $ options = [ ] ) { try { if ( ! is_array ( $ options ) ) { $ limit = $ options ; $ options = [ ] ; if ( $ limit !== null ) { $ options [ 'limit' ] = ( int ) $ limit ; } if ( func_num_args ( ) > 2 ) { $ options [ 'skip' ] = ( int ) func_get_args ( ) [ 2 ] ; } } return $ this -> c...
Counts the number of documents in this collection
48,809
public function save ( & $ a , array $ options = [ ] ) { $ id = $ this -> ensureDocumentHasMongoId ( $ a ) ; $ document = ( array ) $ a ; $ options [ 'upsert' ] = true ; try { $ result = $ this -> collection -> replaceOne ( TypeConverter :: fromLegacy ( [ '_id' => $ id ] ) , TypeConverter :: fromLegacy ( $ document ) ,...
Saves an object to this collection
48,810
public function group ( $ keys , array $ initial , $ reduce , array $ condition = [ ] ) { if ( is_string ( $ reduce ) ) { $ reduce = new MongoCode ( $ reduce ) ; } $ command = [ 'group' => [ 'ns' => $ this -> name , '$reduce' => ( string ) $ reduce , 'initial' => $ initial , 'cond' => $ condition , ] , ] ; if ( $ keys ...
Performs an operation similar to SQL s GROUP BY command
48,811
private function convertWriteConcernOptions ( array $ options ) { if ( isset ( $ options [ 'safe' ] ) ) { $ options [ 'w' ] = ( $ options [ 'safe' ] ) ? 1 : 0 ; } if ( isset ( $ options [ 'wtimeout' ] ) && ! isset ( $ options [ 'wTimeoutMS' ] ) ) { $ options [ 'wTimeoutMS' ] = $ options [ 'wtimeout' ] ; } if ( isset ( ...
Converts legacy write concern options to a WriteConcern object
48,812
public function delete ( $ id ) { $ this -> createChunksIndex ( ) ; $ this -> chunks -> remove ( [ 'files_id' => $ id ] , [ 'justOne' => false ] ) ; return parent :: remove ( [ '_id' => $ id ] ) ; }
Delete a file from the database
48,813
public function findOne ( $ query = [ ] , array $ fields = [ ] , array $ options = [ ] ) { if ( ! is_array ( $ query ) ) { $ query = [ 'filename' => ( string ) $ query ] ; } $ items = iterator_to_array ( $ this -> find ( $ query , $ fields ) -> limit ( 1 ) ) ; return count ( $ items ) ? current ( $ items ) : null ; }
Returns a single file matching the criteria
48,814
public function remove ( array $ criteria = [ ] , array $ options = [ ] ) { $ this -> createChunksIndex ( ) ; $ matchingFiles = parent :: find ( $ criteria , [ '_id' => 1 ] ) ; $ ids = [ ] ; foreach ( $ matchingFiles as $ file ) { $ ids [ ] = $ file [ '_id' ] ; } $ this -> chunks -> remove ( [ 'files_id' => [ '$in' => ...
Removes files from the collections
48,815
public function storeBytes ( $ bytes , array $ extra = [ ] , array $ options = [ ] ) { $ this -> createChunksIndex ( ) ; $ record = $ extra + [ 'length' => mb_strlen ( $ bytes , '8bit' ) , 'md5' => md5 ( $ bytes ) , ] ; try { $ file = $ this -> insertFile ( $ record , $ options ) ; } catch ( MongoException $ e ) { thro...
Chunkifies and stores bytes in the database
48,816
public function storeFile ( $ filename , array $ extra = [ ] , array $ options = [ ] ) { $ this -> createChunksIndex ( ) ; $ record = $ extra ; if ( is_string ( $ filename ) ) { $ record += [ 'md5' => md5_file ( $ filename ) , 'length' => filesize ( $ filename ) , 'filename' => $ filename , ] ; $ handle = fopen ( $ fil...
Stores a file in the database
48,817
public function storeUpload ( $ name , array $ metadata = [ ] ) { if ( ! isset ( $ _FILES [ $ name ] ) || $ _FILES [ $ name ] [ 'error' ] !== UPLOAD_ERR_OK ) { throw new MongoGridFSException ( "Could not find uploaded file $name" ) ; } if ( ! isset ( $ _FILES [ $ name ] [ 'tmp_name' ] ) ) { throw new MongoGridFSExcepti...
Saves an uploaded file directly from a POST to the database
48,818
private function insertChunk ( $ fileId , $ data , $ chunkNumber ) { $ chunk = [ 'files_id' => $ fileId , 'n' => $ chunkNumber , 'data' => new MongoBinData ( $ data ) , ] ; $ result = $ this -> chunks -> insert ( $ chunk ) ; if ( ! $ this -> isOKResult ( $ result ) ) { throw new \ MongoException ( 'error inserting chun...
Inserts a single chunk into the database
48,819
private function insertChunksFromBytes ( $ bytes , $ record ) { $ chunkSize = $ record [ 'chunkSize' ] ; $ fileId = $ record [ '_id' ] ; $ i = 0 ; $ chunks = str_split ( $ bytes , $ chunkSize ) ; foreach ( $ chunks as $ chunk ) { $ this -> insertChunk ( $ fileId , $ chunk , $ i ++ ) ; } }
Splits a string into chunks and writes them to the database
48,820
private function insertChunksFromFile ( $ handle , $ record , & $ md5 ) { $ written = 0 ; $ offset = 0 ; $ i = 0 ; $ fileId = $ record [ '_id' ] ; $ chunkSize = $ record [ 'chunkSize' ] ; $ hash = hash_init ( 'md5' ) ; rewind ( $ handle ) ; while ( ! feof ( $ handle ) ) { $ data = stream_get_contents ( $ handle , $ chu...
Reads chunks from a file and writes them to the database
48,821
private function insertFile ( $ record , array $ options = [ ] ) { $ record += [ '_id' => new MongoId ( ) , 'uploadDate' => new MongoDate ( ) , 'chunkSize' => $ this -> defaultChunkSize , ] ; $ result = $ this -> insert ( $ record , $ options ) ; if ( ! $ this -> isOKResult ( $ result ) ) { throw new \ MongoException (...
Writes a file record to the database
48,822
public static function create ( $ collection , $ id , $ database = null ) { $ ref = [ static :: $ refKey => $ collection , static :: $ idKey => $ id ] ; if ( $ database !== null ) { $ ref [ '$db' ] = $ database ; } return $ ref ; }
If no database is given the current database is used .
48,823
public static function get ( $ db , $ ref ) { if ( ! static :: isRef ( $ ref ) ) { return null ; } return $ db -> selectCollection ( $ ref [ static :: $ refKey ] ) -> findOne ( [ '_id' => $ ref [ static :: $ idKey ] ] ) ; }
Fetches the object pointed to by a reference
48,824
public function next ( ) { if ( ! $ this -> startedIterating ) { $ this -> ensureIterator ( ) ; $ this -> startedIterating = true ; } else { if ( $ this -> cursorNeedsAdvancing ) { $ this -> ensureIterator ( ) -> next ( ) ; } $ this -> cursorNeedsAdvancing = true ; $ this -> position ++ ; } return $ this -> storeIterat...
Advances the cursor to the next result and returns that result
48,825
public function rewind ( ) { $ this -> reset ( ) ; $ this -> startedIterating = true ; $ this -> position = 0 ; $ this -> ensureIterator ( ) -> rewind ( ) ; $ this -> storeIteratorState ( ) ; }
Returns the cursor to the beginning of the result set
48,826
protected function getOptions ( $ optionNames = null ) { $ options = [ ] ; if ( $ optionNames === null ) { $ optionNames = $ this -> optionNames ; } foreach ( $ optionNames as $ option ) { $ converter = 'convert' . ucfirst ( $ option ) ; $ value = method_exists ( $ this , $ converter ) ? $ this -> $ converter ( ) : $ t...
Applies all options set on the cursor overwriting any options that have already been set
48,827
protected function reset ( ) { $ this -> startedIterating = false ; $ this -> cursorNeedsAdvancing = true ; $ this -> cursor = null ; $ this -> iterator = null ; $ this -> storeIteratorState ( ) ; }
Clears the cursor
48,828
protected function storeIteratorState ( ) { if ( ! $ this -> startedIterating ) { $ this -> current = null ; $ this -> key = null ; $ this -> valid = false ; return null ; } $ this -> current = $ this -> ensureIterator ( ) -> current ( ) ; $ this -> key = $ this -> ensureIterator ( ) -> key ( ) ; $ this -> valid = $ th...
Stores the current cursor element .
48,829
public static function isValid ( $ value ) { if ( $ value instanceof ObjectID || $ value instanceof MongoId ) { return true ; } elseif ( ! is_string ( $ value ) ) { return false ; } return ( bool ) preg_match ( '#^[a-f0-9]{24}$#i' , $ value ) ; }
Check if a value is a valid ObjectId
48,830
protected function getProcess ( $ host , Task $ task ) { $ target = $ this -> getConfiguredServer ( $ host ) ? : $ host ; $ env = $ this -> getEnvironment ( $ host ) ; if ( in_array ( $ target , [ 'local' , 'localhost' , '127.0.0.1' ] ) ) { $ process = new Process ( $ task -> script , null , $ env ) ; } else { $ delimi...
Run the given script on the given host .
48,831
protected function getServer ( TaskContainer $ container ) { if ( $ this -> argument ( 'name' ) ) { return $ container -> getServer ( $ this -> argument ( 'name' ) ) ; } elseif ( $ container -> hasOneServer ( ) ) { return $ container -> getFirstServer ( ) ; } else { throw new \ InvalidArgumentException ( 'Please provid...
Get the server from the task container .
48,832
public static function parseString ( $ string ) { $ groups = [ ] ; $ index = 0 ; $ matchSection = false ; foreach ( explode ( PHP_EOL , $ string ) as $ line ) { $ line = trim ( $ line ) ; if ( '' == $ line || starts_with ( $ line , '#' ) ) { continue ; } if ( preg_match ( '/^\s*(\S+)\s*=(.*)$/' , $ line , $ match ) ) {...
Parse the given configuration string .
48,833
public function findConfiguredHost ( $ host ) { list ( $ user , $ host ) = $ this -> parseHost ( $ host ) ; foreach ( $ this -> groups as $ group ) { if ( ( isset ( $ group [ 'host' ] ) && $ group [ 'host' ] == $ host ) || ( isset ( $ group [ 'hostname' ] ) && $ group [ 'hostname' ] == $ host ) ) { if ( ! empty ( $ use...
Get the configured SSH host by name or IP .
48,834
protected function listTasks ( $ container ) { $ this -> output -> writeln ( '<comment>Available tasks:</comment>' ) ; foreach ( array_keys ( $ container -> getTasks ( ) ) as $ task ) { $ this -> output -> writeln ( " <info>{$task}</info>" ) ; } }
List the tasks from the container .
48,835
protected function listMacros ( $ container ) { $ this -> output -> writeln ( '<comment>Available stories:</comment>' ) ; foreach ( array_keys ( $ container -> getMacros ( ) ) as $ macro ) { $ this -> output -> writeln ( " <info>{$macro}</info>" ) ; } }
List the macros from the container .
48,836
public function compile ( $ value , $ serversOnly = false ) { $ compilers = $ serversOnly ? $ this -> serverCompilers : $ this -> compilers ; $ value = $ this -> initializeVariables ( $ value ) ; foreach ( $ compilers as $ compiler ) { $ value = $ this -> { "compile{$compiler}" } ( $ value ) ; } return $ value ; }
Compile the given Envoy template contents .
48,837
protected function compileMacroStart ( $ value ) { $ pattern = $ this -> createMatcher ( 'macro' ) ; $ value = preg_replace ( $ pattern , '$1<?php $__container->startMacro$2; ?>' , $ value ) ; $ pattern = $ this -> createMatcher ( 'story' ) ; return preg_replace ( $ pattern , '$1<?php $__container->startMacro$2; ?>' , ...
Compile Envoy macro start statements into valid PHP .
48,838
protected function compileMacroStop ( $ value ) { $ pattern = $ this -> createPlainMatcher ( 'endmacro' ) ; $ value = preg_replace ( $ pattern , '$1<?php $__container->endMacro(); ?>$2' , $ value ) ; $ pattern = $ this -> createPlainMatcher ( 'endstory' ) ; return preg_replace ( $ pattern , '$1<?php $__container->endMa...
Compile Envoy macro stop statements into valid PHP .
48,839
private function initializeVariables ( $ value ) { preg_match_all ( '/\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/' , $ value , $ matches ) ; foreach ( array_unique ( $ matches [ 0 ] ) as $ variable ) { $ value = "<?php $variable = isset($variable) ? $variable : null; ?>\n" . $ value ; } return $ value ; }
Initialize the variables included in the Envoy template .
48,840
public function load ( $ __path , Compiler $ __compiler , array $ __data = [ ] , $ __serversOnly = false ) { $ __dir = realpath ( dirname ( $ __path ) ) ; $ __envoyPath = $ this -> writeCompiledEnvoyFile ( $ __compiler , $ __path , $ __serversOnly ) ; $ __container = $ this ; ob_start ( ) && extract ( $ __data ) ; incl...
Load the Envoy file into the container .
48,841
protected function writeCompiledEnvoyFile ( $ compiler , $ path , $ serversOnly ) { file_put_contents ( $ envoyPath = getcwd ( ) . '/Envoy' . md5_file ( $ path ) . '.php' , $ compiler -> compile ( file_get_contents ( $ path ) , $ serversOnly ) ) ; return $ envoyPath ; }
Write the compiled Envoy file to disk .
48,842
protected function replaceSubTasks ( ) { foreach ( $ this -> tasks as $ name => & $ script ) { $ callback = function ( $ m ) { return $ m [ 1 ] . $ this -> tasks [ $ m [ 2 ] ] ; } ; $ script = $ this -> trimSpaces ( preg_replace_callback ( "/(\s*)@run\('(.*)'\)/" , $ callback , $ script ) ) ; } }
Replace all of the sub tasks and trim leading spaces .
48,843
public function getServer ( $ server ) { if ( ! array_key_exists ( $ server , $ this -> servers ) ) { throw new \ Exception ( 'Server [' . $ server . '] is not defined.' ) ; } return Arr :: get ( $ this -> servers , $ server ) ; }
Get the IP address for a server .
48,844
public function import ( $ file , array $ data = [ ] ) { $ data = Arr :: except ( $ data , [ '__path' , '__dir' , '__compiler' , '__data' , '__serversOnly' , '__envoyPath' , '__container' , 'this' , ] ) ; if ( ( $ path = $ this -> resolveImportPath ( $ file ) ) === false ) { throw new InvalidArgumentException ( "Unable...
Import the given file into the container .
48,845
protected function resolveImportPath ( $ file ) { if ( ( $ path = realpath ( $ file ) ) !== false ) { return $ path ; } elseif ( ( $ path = realpath ( $ file . '.blade.php' ) ) !== false ) { return $ path ; } elseif ( ( $ path = realpath ( getcwd ( ) . '/vendor/' . $ file . '/Envoy.blade.php' ) ) !== false ) { return $...
Resolve the import path for the given file .
48,846
public function getTask ( $ task , array $ macroOptions = [ ] ) { $ script = Arr :: get ( $ this -> tasks , $ task , '' ) ; if ( $ script == '' ) { throw new \ Exception ( sprintf ( 'Task "%s" is not defined.' , $ task ) ) ; } $ options = array_merge ( $ this -> getTaskOptions ( $ task ) , $ macroOptions ) ; $ parallel...
Get a Task instance by the given name .
48,847
protected function getServers ( array $ options ) { if ( ! array_key_exists ( 'on' , $ options ) ) { $ options [ 'on' ] = [ ] ; } return Arr :: flatten ( array_map ( function ( $ name ) { return $ this -> getServer ( $ name ) ; } , ( array ) $ options [ 'on' ] ) ) ; }
Get the IP addresses of the servers specified on the options .
48,848
public function startMacro ( $ macro , array $ options = [ ] ) { ob_start ( ) && $ this -> macroStack [ ] = $ macro ; $ this -> macroOptions [ $ macro ] = $ options ; }
Begin defining a macro .
48,849
public function endMacro ( ) { $ macro = explode ( PHP_EOL , $ this -> trimSpaces ( trim ( ob_get_clean ( ) ) ) ) ; $ this -> macros [ array_pop ( $ this -> macroStack ) ] = $ macro ; }
Stop defining a macro .
48,850
public function startTask ( $ task , array $ options = [ ] ) { ob_start ( ) && $ this -> taskStack [ ] = $ task ; $ this -> taskOptions [ $ task ] = $ this -> mergeDefaultOptions ( $ options ) ; }
Begin defining a task .
48,851
public function endTask ( ) { $ name = array_pop ( $ this -> taskStack ) ; $ contents = trim ( ob_get_clean ( ) ) ; if ( isset ( $ this -> tasks [ $ name ] ) ) { $ this -> tasks [ $ name ] = str_replace ( '@parent' , $ this -> tasks [ $ name ] , $ contents ) ; } else { $ this -> tasks [ $ name ] = $ contents ; } }
Stop defining a task .
48,852
public function confirmTaskWithUser ( $ task , $ question ) { $ question = $ question === true ? 'Are you sure you want to run the [' . $ task . '] task?' : ( string ) $ question ; $ question = '<comment>' . $ question . ' [y/N]:</comment> ' ; $ question = new ConfirmationQuestion ( $ question , false ) ; return $ this...
Confirm the operation with the user .
48,853
public function secret ( $ question ) { $ question = '<comment>' . $ question . '</comment> ' ; $ question = new Question ( $ question ) ; $ question -> setHidden ( true ) ; $ question -> setHiddenFallback ( false ) ; return $ this -> getHelperSet ( ) -> get ( 'question' ) -> ask ( $ this -> input , $ this -> output , ...
Ask the user the given secret question .
48,854
protected function getTasks ( $ container ) { $ tasks = [ $ task = $ this -> argument ( 'task' ) ] ; if ( $ macro = $ container -> getMacro ( $ task ) ) { $ tasks = $ macro ; } return $ tasks ; }
Get the tasks from the container based on user input .
48,855
protected function runTask ( $ container , $ task ) { $ macroOptions = $ container -> getMacroOptions ( $ this -> argument ( 'task' ) ) ; $ confirm = $ container -> getTask ( $ task , $ macroOptions ) -> confirm ; if ( $ confirm && ! $ this -> confirmTaskWithUser ( $ task , $ confirm ) ) { return ; } if ( ( $ exitCode ...
Run the given task out of the container .
48,856
protected function displayOutput ( $ type , $ host , $ line ) { $ lines = explode ( "\n" , $ line ) ; foreach ( $ lines as $ line ) { if ( strlen ( trim ( $ line ) ) === 0 ) { continue ; } if ( $ type == Process :: OUT ) { $ this -> output -> write ( '<comment>[' . $ host . ']</comment>: ' . trim ( $ line ) . PHP_EOL )...
Display the given output line .
48,857
protected function getOptions ( ) { $ options = [ ] ; foreach ( $ _SERVER [ 'argv' ] as $ argument ) { if ( ! starts_with ( $ argument , '--' ) || in_array ( $ argument , $ this -> ignoreOptions ) ) { continue ; } $ option = explode ( '=' , substr ( $ argument , 2 ) ) ; if ( count ( $ option ) == 1 ) { $ option [ 1 ] =...
Gather the dynamic options for the command .
48,858
protected function getConfiguredServer ( $ host ) { if ( $ config = $ this -> getSshConfig ( $ this -> getSystemUser ( ) ) ) { return $ config -> findConfiguredHost ( $ host ) ; } }
Get the configured server from the SSH config .
48,859
protected function getSshConfig ( $ user ) { if ( file_exists ( $ path = $ this -> getHomeDirectory ( $ user ) . '/.ssh/config' ) ) { return SSHConfigFile :: parse ( $ path ) ; } }
Get the SSH configuration file instance .
48,860
protected function getHomeDirectory ( $ user ) { $ system = strtolower ( php_uname ( ) ) ; if ( Str :: contains ( $ system , 'darwin' ) ) { return "/Users/{$user}" ; } elseif ( Str :: contains ( $ system , 'windows' ) ) { return "C:\\Users\\{$user}" ; } elseif ( Str :: contains ( $ system , 'linux' ) ) { return "/home/...
Get the home directory for the user based on OS .
48,861
public static function make ( $ hook , $ channel = '' , $ message = null , $ options = [ ] ) { return new static ( $ hook , $ channel , $ message , $ options ) ; }
Create a new Slack message instance .
48,862
public function send ( ) { $ message = $ this -> message ? : ( $ this -> task ? ucwords ( $ this -> getSystemUser ( ) ) . ' ran the [' . $ this -> task . '] task.' : ucwords ( $ this -> getSystemUser ( ) ) . ' ran a task.' ) ; $ payload = array_merge ( [ 'text' => $ message , 'channel' => $ this -> channel ] , $ this -...
Send the Slack message .
48,863
private function getConfigsForUriTemplates ( $ config ) { $ configs = [ $ config ] ; if ( $ config [ 'additionalBindings' ] ) { foreach ( $ config [ 'additionalBindings' ] as $ additionalBinding ) { $ configs [ ] = $ additionalBinding + $ config ; } } return $ configs ; }
Create a list of all possible configs using the additionalBindings
48,864
public static function build ( array $ args = [ ] ) { $ args += [ 'keyFile' => null , 'scopes' => null , 'authHttpHandler' => null , 'enableCaching' => true , 'authCache' => null , 'authCacheOptions' => [ ] , ] ; $ keyFile = $ args [ 'keyFile' ] ; $ authHttpHandler = $ args [ 'authHttpHandler' ] ? : self :: buildHttpHa...
Factory method to create a CredentialsWrapper from an array of options .
48,865
public function readResponse ( ) { list ( $ response , $ status ) = $ this -> call -> wait ( ) ; if ( $ status -> code == Code :: OK ) { return $ response ; } else { throw ApiException :: createFromStdClass ( $ status ) ; } }
Read the response from the server completing the streaming call .
48,866
public function readAll ( ) { $ resourcesGetMethod = $ this -> resourcesGetMethod ; if ( ! is_null ( $ resourcesGetMethod ) ) { foreach ( $ this -> call -> responses ( ) as $ response ) { foreach ( $ response -> $ resourcesGetMethod ( ) as $ resource ) { yield $ resource ; } } } else { foreach ( $ this -> call -> respo...
A generator which yields results from the server until the streaming call completes . Throws an ApiException if the streaming call failed .
48,867
public static function load ( $ serviceName , $ clientConfig , $ disableRetries = false ) { $ serviceRetrySettings = [ ] ; $ serviceConfig = $ clientConfig [ 'interfaces' ] [ $ serviceName ] ; $ retryCodes = $ serviceConfig [ 'retry_codes' ] ; $ retryParams = $ serviceConfig [ 'retry_params' ] ; foreach ( $ serviceConf...
Constructs an array mapping method names to CallSettings .
48,868
public static function parseSegments ( $ path ) { if ( empty ( $ path ) ) { throw new ValidationException ( "Cannot parse empty path" ) ; } $ segments = [ ] ; $ index = 0 ; $ segments [ ] = self :: parseSegmentFromPath ( $ path , $ index ) ; while ( $ index < strlen ( $ path ) ) { self :: parseLiteralFromPath ( '/' , $...
Parses a path into an array of segments .
48,869
private static function parseSegmentFromPath ( $ path , & $ index ) { if ( $ index >= strlen ( $ path ) ) { throw self :: parseError ( $ path , strlen ( $ path ) - 1 , "invalid trailing '/'" ) ; } if ( $ path [ $ index ] === '{' ) { $ closingBraceIndex = strpos ( $ path , '}' , $ index ) ; if ( $ closingBraceIndex === ...
Given a path and an index reads a Segment from the path and updates the index .
48,870
public static function build ( $ serviceAddress , array $ config = [ ] ) { $ config += [ 'httpHandler' => null , ] ; list ( $ baseUri , $ port ) = self :: normalizeServiceAddress ( $ serviceAddress ) ; $ httpHandler = $ config [ 'httpHandler' ] ? : self :: buildHttpHandlerAsync ( ) ; return new GrpcFallbackTransport ( ...
Builds a GrpcFallbackTransport .
48,871
public function encodeMessage ( $ message ) { $ pool = DescriptorPool :: getGeneratedPool ( ) ; $ messageType = $ pool -> getDescriptorByClassName ( get_class ( $ message ) ) ; try { return $ this -> encodeMessageImpl ( $ message , $ messageType ) ; } catch ( \ Exception $ e ) { throw new ValidationException ( "Error e...
Encode protobuf message as a PHP array
48,872
public function decodeMessage ( $ message , $ data ) { $ pool = DescriptorPool :: getGeneratedPool ( ) ; $ messageType = $ pool -> getDescriptorByClassName ( get_class ( $ message ) ) ; try { return $ this -> decodeMessageImpl ( $ message , $ messageType , $ data ) ; } catch ( \ Exception $ e ) { throw new ValidationEx...
Decode PHP array into the specified protobuf message
48,873
public static function decodeMetadata ( $ metadata ) { if ( is_null ( $ metadata ) || count ( $ metadata ) == 0 ) { return [ ] ; } $ result = [ ] ; foreach ( $ metadata as $ key => $ values ) { foreach ( $ values as $ value ) { $ decodedValue = [ '@type' => $ key , ] ; if ( self :: hasBinaryHeaderSuffix ( $ key ) ) { i...
Decode metadata received from gRPC status object
48,874
public static function decodeAnyMessages ( $ anyArray ) { $ results = [ ] ; foreach ( $ anyArray as $ any ) { try { $ unpacked = $ any -> unpack ( ) ; $ results [ ] = self :: serializeToPhpArray ( $ unpacked ) ; } catch ( \ Exception $ ex ) { echo "$ex\n" ; $ results [ ] = [ 'typeUrl' => $ any -> getTypeUrl ( ) , 'valu...
Decode an array of Any messages into a printable PHP array .
48,875
public function getNextPage ( $ pageSize = null ) { if ( ! $ this -> hasNextPage ( ) ) { throw new ValidationException ( 'Could not complete getNextPage operation: ' . 'there are no more pages to retrieve.' ) ; } $ newRequest = clone $ this -> getRequestObject ( ) ; $ requestPageTokenSetMethod = $ this -> pageStreaming...
Retrieves the next Page object using the next page token .
48,876
public function getIterator ( ) { $ resourcesGetMethod = $ this -> pageStreamingDescriptor -> getResourcesGetMethod ( ) ; foreach ( $ this -> getResponseObject ( ) -> $ resourcesGetMethod ( ) as $ element ) { yield $ element ; } }
Return an iterator over the elements in the response .
48,877
public function iteratePages ( ) { $ currentPage = $ this ; yield $ this ; while ( $ currentPage -> hasNextPage ( ) ) { $ currentPage = $ currentPage -> getNextPage ( ) ; yield $ currentPage ; } }
Return an iterator over Page objects beginning with this object . Additional Page objects are retrieved lazily via API calls until all elements have been retrieved .
48,878
public function expandToFixedSizeCollection ( $ collectionSize ) { if ( ! $ this -> pageStreamingDescriptor -> requestHasPageSizeField ( ) ) { throw new ValidationException ( "FixedSizeCollection is not supported for this method, because " . "the method does not support an optional argument to set the " . "page size." ...
Returns a collection of elements with a fixed size set by the collectionSize parameter . The collection will only contain fewer than collectionSize elements if there are no more pages to be retrieved from the server .
48,879
public function write ( $ request ) { if ( $ this -> isComplete ) { throw new ValidationException ( "Cannot call write() after streaming call is complete." ) ; } if ( $ this -> writesClosed ) { throw new ValidationException ( "Cannot call write() after calling closeWrite()." ) ; } $ this -> call -> write ( $ request ) ...
Write request to the server .
48,880
public function read ( ) { if ( $ this -> isComplete ) { throw new ValidationException ( "Cannot call read() after streaming call is complete." ) ; } $ resourcesGetMethod = $ this -> resourcesGetMethod ; if ( ! is_null ( $ resourcesGetMethod ) ) { if ( count ( $ this -> pendingResources ) === 0 ) { $ response = $ this ...
Read the next response from the server . Returns null if the streaming call completed successfully . Throws an ApiException if the streaming call failed .
48,881
private function setClientOptions ( array $ options ) { $ this -> validateNotNull ( $ options , [ 'serviceAddress' , 'serviceName' , 'descriptorsConfigPath' , 'clientConfig' , 'disableRetries' , 'credentialsConfig' , 'transportConfig' , ] ) ; $ this -> validate ( $ options , [ 'credentials' , 'transport' , 'gapicVersio...
Configures the GAPIC client based on an array of options .
48,882
public function isDone ( ) { return ( is_null ( $ this -> lastProtoResponse ) || is_null ( $ this -> lastProtoResponse -> getDone ( ) ) ) ? false : $ this -> lastProtoResponse -> getDone ( ) ; }
Check whether the operation has completed .
48,883
public function pollUntilComplete ( $ options = [ ] ) { if ( $ this -> isDone ( ) ) { return true ; } $ pollSettings = array_merge ( $ this -> defaultPollSettings , $ options ) ; return $ this -> poll ( function ( ) { $ this -> reload ( ) ; return $ this -> isDone ( ) ; } , $ pollSettings ) ; }
Poll the server in a loop until the operation is complete .
48,884
public function reload ( ) { if ( $ this -> deleted ) { throw new ValidationException ( "Cannot call reload() on a deleted operation" ) ; } $ name = $ this -> getName ( ) ; $ this -> lastProtoResponse = $ this -> operationsClient -> getOperation ( $ name ) ; }
Reload the status of the operation with a request to the service .
48,885
public function getMetadata ( ) { if ( is_null ( $ this -> lastProtoResponse ) ) { return null ; } $ any = $ this -> lastProtoResponse -> getMetadata ( ) ; if ( is_null ( $ this -> metadataReturnType ) ) { return $ any ; } if ( is_null ( $ any ) || is_null ( $ any -> getValue ( ) ) ) { return null ; } $ metadataReturnT...
Get the metadata returned with the last proto response . If a metadata type was provided then the return value will be of that type - otherwise the return value will be of type Any . If no metadata object is available returns null .
48,886
protected function convertEncoding ( $ str , $ from = 'ISO-8859-1' , $ force = false ) { if ( $ from !== 'UTF-8' ) { if ( $ force || ! ( $ this -> charsetConverter -> checkEncoding ( $ str , 'UTF-8' ) ) ) { return $ this -> charsetConverter -> convert ( $ str , $ from , 'UTF-8' ) ; } } return $ str ; }
Ensures the encoding of the passed string is set to UTF - 8 .
48,887
protected function getBoundaryAndChildStreams ( ParentHeaderPart $ part ) { $ boundary = $ part -> getHeaderParameter ( 'Content-Type' , 'boundary' ) ; if ( $ boundary === null ) { return array_map ( function ( $ child ) { return $ child -> getStream ( ) ; } , $ part -> getChildParts ( ) ) ; } $ streams = [ ] ; foreach...
Creates an array of streams based on the attached part s mime boundary and child streams .
48,888
protected function getStreamsArray ( ) { $ content = Psr7 \ stream_for ( ) ; $ this -> writePartContentTo ( $ content ) ; $ content -> rewind ( ) ; $ streams = [ $ this -> streamFactory -> newHeaderStream ( $ this -> part ) , $ content ] ; $ part = $ this -> part ; if ( $ part instanceof ParentHeaderPart && $ part -> g...
Returns an array of Psr7 Streams representing the attached part and it s direct children .
48,889
public function getStream ( ) { if ( $ this -> stream === null ) { return $ this -> streamFactory -> newMessagePartStream ( $ this ) ; } $ this -> stream -> rewind ( ) ; return $ this -> stream ; }
Returns a Psr7 StreamInterface containing this part including any headers for a MimePart its content and all its children .
48,890
public function setCharsetOverride ( $ charsetOverride , $ onlyIfNoCharset = false ) { if ( ! $ onlyIfNoCharset || $ this -> getCharset ( ) === null ) { $ this -> charsetOverride = $ charsetOverride ; } }
Overrides the default character set used for reading content from content streams in cases where a user knows the source charset is not what is specified .
48,891
public function getContentResourceHandle ( $ charset = MailMimeParser :: DEFAULT_CHARSET ) { $ stream = $ this -> getContentStream ( $ charset ) ; if ( $ stream !== null ) { return StreamWrapper :: getResource ( $ stream ) ; } return null ; }
Returns a resource handle for the content s stream or null if the part doesn t have a content stream .
48,892
public function getContentStream ( $ charset = MailMimeParser :: DEFAULT_CHARSET ) { if ( $ this -> hasContent ( ) ) { $ tr = ( $ this -> ignoreTransferEncoding ) ? '' : $ this -> getContentTransferEncoding ( ) ; $ ch = ( $ this -> charsetOverride !== null ) ? $ this -> charsetOverride : $ this -> getCharset ( ) ; retu...
Returns the StreamInterface for the part s content or null if the part doesn t have a content section .
48,893
public function getBinaryContentStream ( ) { if ( $ this -> hasContent ( ) ) { $ tr = ( $ this -> ignoreTransferEncoding ) ? '' : $ this -> getContentTransferEncoding ( ) ; return $ this -> partStreamFilterManager -> getBinaryStream ( $ tr ) ; } return null ; }
Returns the raw data stream for the current part if it exists or null if there s no content associated with the stream .
48,894
public function getBinaryContentResourceHandle ( ) { $ stream = $ this -> getBinaryContentStream ( ) ; if ( $ stream !== null ) { return StreamWrapper :: getResource ( $ stream ) ; } return null ; }
Returns a resource handle for the content s raw data stream or null if the part doesn t have a content stream .
48,895
public function saveContent ( $ filenameResourceOrStream ) { $ resourceOrStream = $ filenameResourceOrStream ; if ( is_string ( $ filenameResourceOrStream ) ) { $ resourceOrStream = fopen ( $ filenameResourceOrStream , 'w+' ) ; } $ stream = Psr7 \ stream_for ( $ resourceOrStream ) ; Psr7 \ copy_to_stream ( $ this -> ge...
Saves the binary content of the stream to the passed file resource or stream .
48,896
public function getContent ( $ charset = MailMimeParser :: DEFAULT_CHARSET ) { $ stream = $ this -> getContentStream ( $ charset ) ; if ( $ stream !== null ) { return $ stream -> getContents ( ) ; } return null ; }
Shortcut to reading stream content and assigning it to a string . Returns null if the part doesn t have a content stream .
48,897
public function attachContentStream ( StreamInterface $ stream , $ streamCharset = MailMimeParser :: DEFAULT_CHARSET ) { if ( $ this -> contentStream !== null && $ this -> contentStream !== $ stream ) { $ this -> contentStream -> close ( ) ; } $ this -> contentStream = $ stream ; $ ch = ( $ this -> charsetOverride !== ...
Attaches the stream or resource handle for the part s content . The stream is closed when another stream is attached or the MimePart is destroyed .
48,898
public function detachContentStream ( ) { $ this -> contentStream = null ; $ this -> partStreamFilterManager -> setStream ( null ) ; $ this -> onChange ( ) ; }
Detaches and closes the content stream .
48,899
public function setContent ( $ resource , $ charset = MailMimeParser :: DEFAULT_CHARSET ) { $ stream = Psr7 \ stream_for ( $ resource ) ; $ this -> attachContentStream ( $ stream , $ charset ) ; }
Sets the content of the part to the passed resource .