idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
42,100
public function subscribeAuthEvents ( ) { foreach ( static :: $ authEventHandlerMap as $ eventName => $ handler ) { $ this -> events -> listen ( $ eventName , [ $ this , $ handler ] ) ; } }
Attach all authentication event handlers .
42,101
public function subscribeQueueEvents ( QueueManager $ queue ) { $ queue -> looping ( function ( ) { Integration :: flushEvents ( ) ; Hub :: getCurrent ( ) -> popScope ( ) ; } ) ; foreach ( static :: $ queueEventHandlerMap as $ eventName => $ handler ) { $ this -> events -> listen ( $ eventName , [ $ this , $ handler ] ...
Attach all queue event handlers .
42,102
protected function logHandler ( $ level , $ message , $ context ) { Integration :: addBreadcrumb ( new Breadcrumb ( $ level , Breadcrumb :: TYPE_USER , 'log.' . $ level , $ message , empty ( $ context ) ? [ ] : [ 'params' => $ context ] ) ) ; }
Until Laravel 5 . 3
42,103
protected function messageLoggedHandler ( MessageLogged $ logEntry ) { Integration :: addBreadcrumb ( new Breadcrumb ( $ logEntry -> level , Breadcrumb :: TYPE_USER , 'log.' . $ logEntry -> level , $ logEntry -> message , empty ( $ logEntry -> context ) ? [ ] : [ 'params' => $ logEntry -> context ] ) ) ; }
Since Laravel 5 . 4
42,104
protected function authenticatedHandler ( Authenticated $ event ) { Integration :: configureScope ( function ( Scope $ scope ) use ( $ event ) : void { $ scope -> setUser ( [ 'id' => $ event -> user -> getAuthIdentifier ( ) , ] ) ; } ) ; }
Since Laravel 5 . 3
42,105
public static function addBreadcrumb ( Breadcrumb $ breadcrumb ) : void { $ self = Hub :: getCurrent ( ) -> getIntegration ( self :: class ) ; if ( ! $ self instanceof self ) { return ; } addBreadcrumb ( $ breadcrumb ) ; }
Adds a breadcrumb if the integration is enabled for Laravel .
42,106
public static function configureScope ( callable $ callback ) : void { $ self = Hub :: getCurrent ( ) -> getIntegration ( self :: class ) ; if ( ! $ self instanceof self ) { return ; } configureScope ( $ callback ) ; }
Configures the scope if the integration is enabled for Laravel .
42,107
public static function flushEvents ( ) : void { $ client = Hub :: getCurrent ( ) -> getClient ( ) ; if ( $ client instanceof Client ) { $ transportProperty = new \ ReflectionProperty ( Client :: class , 'transport' ) ; $ transportProperty -> setAccessible ( true ) ; $ transport = $ transportProperty -> getValue ( $ cli...
Block until all async events are processed for the HTTP transport .
42,108
protected function bindEvents ( ) : void { $ userConfig = $ this -> app [ 'config' ] [ static :: $ abstract ] ; $ handler = new EventHandler ( $ this -> app -> events , $ userConfig ) ; $ handler -> subscribe ( ) ; $ handler -> subscribeQueueEvents ( $ this -> app -> queue ) ; if ( isset ( $ userConfig [ 'send_default_...
Bind to the Laravel event dispatcher to log events .
42,109
protected function configureAndRegisterClient ( ) : void { $ this -> app -> singleton ( static :: $ abstract , function ( ) { $ basePath = base_path ( ) ; $ userConfig = $ this -> app [ 'config' ] [ static :: $ abstract ] ; unset ( $ userConfig [ 'breadcrumbs' ] , $ userConfig [ 'breadcrumbs.sql_bindings' ] ) ; $ optio...
Configure and register the Sentry client with the container .
42,110
public function setMeta ( array $ meta ) { $ this -> took = isset ( $ meta [ 'took' ] ) ? $ meta [ 'took' ] : null ; $ this -> timed_out = isset ( $ meta [ 'timed_out' ] ) ? $ meta [ 'timed_out' ] : null ; $ this -> shards = isset ( $ meta [ '_shards' ] ) ? $ meta [ '_shards' ] : null ; $ this -> hits = isset ( $ meta ...
Set the result meta .
42,111
public function getElasticSearchClient ( ) { $ config = $ this -> getElasticConfig ( ) ; if ( class_exists ( '\Elasticsearch\ClientBuilder' ) ) { return \ Elasticsearch \ ClientBuilder :: fromConfig ( $ config ) ; } return new \ Elasticsearch \ Client ( $ config ) ; }
Get ElasticSearch Client
42,112
public function addToIndex ( ) { if ( $ this -> isEmpty ( ) ) { return null ; } $ params = array ( ) ; foreach ( $ this -> all ( ) as $ item ) { $ params [ 'body' ] [ ] = array ( 'index' => array ( '_id' => $ item -> getKey ( ) , '_type' => $ item -> getTypeName ( ) , '_index' => $ item -> getIndexName ( ) , ) , ) ; $ ...
Add To Index
42,113
public function deleteFromIndex ( ) { $ all = $ this -> all ( ) ; $ params = array ( ) ; foreach ( $ all as $ item ) { $ params [ 'body' ] [ ] = array ( 'delete' => array ( '_id' => $ item -> getKey ( ) , '_type' => $ item -> getTypeName ( ) , '_index' => $ item -> getIndexName ( ) , ) , ) ; } return $ this -> getElast...
Delete From Index
42,114
public function getElasticConfig ( $ key = 'config' , $ prefix = 'elasticquent' ) { $ key = $ prefix . ( $ key ? '.' : '' ) . $ key ; if ( function_exists ( 'config' ) ) { $ config_helper = config ( ) ; } elseif ( function_exists ( 'app' ) ) { $ config_helper = app ( 'config' ) ; } else { $ config_helper = $ this -> ge...
Get the Elasticquent config
42,115
protected function getConfigHelper ( ) { $ config_file = $ this -> getConfigFile ( ) ; if ( ! file_exists ( $ config_file ) ) { throw new \ Exception ( 'Config file not found.' ) ; } return new \ Illuminate \ Config \ Repository ( array ( 'elasticquent' => require ( $ config_file ) ) ) ; }
Inject given config file into an instance of Laravel s config
42,116
public static function complexSearch ( $ params ) { $ instance = new static ; $ result = $ instance -> getElasticSearchClient ( ) -> search ( $ params ) ; return static :: hydrateElasticsearchResult ( $ result ) ; }
Perform a complex or custom search .
42,117
public function addToIndex ( ) { if ( ! $ this -> exists ) { throw new Exception ( 'Document does not exist.' ) ; } $ params = $ this -> getBasicEsParams ( ) ; $ params [ 'body' ] = $ this -> getIndexDocumentData ( ) ; $ params [ 'id' ] = $ this -> getKey ( ) ; return $ this -> getElasticSearchClient ( ) -> index ( $ p...
Add to Search Index
42,118
public function updateIndex ( ) { $ params = $ this -> getBasicEsParams ( ) ; $ params [ 'body' ] [ 'doc' ] = $ this -> getIndexDocumentData ( ) ; return $ this -> getElasticSearchClient ( ) -> update ( $ params ) ; }
Partial Update to Indexed Document
42,119
public function getBasicEsParams ( $ getIdIfPossible = true , $ limit = null , $ offset = null ) { $ params = array ( 'index' => $ this -> getIndexName ( ) , 'type' => $ this -> getTypeName ( ) , ) ; if ( $ getIdIfPossible && $ this -> getKey ( ) ) { $ params [ 'id' ] = $ this -> getKey ( ) ; } if ( is_numeric ( $ limi...
Get Basic Elasticsearch Params
42,120
public static function typeExists ( ) { $ instance = new static ; $ params = $ instance -> getBasicEsParams ( ) ; return $ instance -> getElasticSearchClient ( ) -> indices ( ) -> existsType ( $ params ) ; }
Type Exists .
42,121
public function newFromHitBuilder ( $ hit = array ( ) ) { $ key_name = $ this -> getKeyName ( ) ; $ attributes = $ hit [ '_source' ] ; if ( isset ( $ hit [ '_id' ] ) ) { $ attributes [ $ key_name ] = is_numeric ( $ hit [ '_id' ] ) ? intval ( $ hit [ '_id' ] ) : $ hit [ '_id' ] ; } if ( isset ( $ hit [ 'fields' ] ) ) { ...
New From Hit Builder
42,122
public static function hydrateElasticquentResult ( array $ items , $ meta = null ) { $ instance = new static ; $ items = array_map ( function ( $ item ) use ( $ instance ) { return $ instance -> newFromHitBuilder ( $ item ) ; } , $ items ) ; return $ instance -> newElasticquentResultCollection ( $ items , $ meta ) ; }
Create a elacticquent result collection of models from plain arrays .
42,123
public static function newFromBuilderRecursive ( Model $ model , array $ attributes = [ ] , Relation $ parentRelation = null ) { $ instance = $ model -> newInstance ( [ ] , $ exists = true ) ; $ instance -> setRawAttributes ( ( array ) $ attributes , $ sync = true ) ; static :: loadRelationsAttributesRecursive ( $ inst...
Create a new model instance that is existing recursive .
42,124
public static function hydrateRecursive ( Model $ model , array $ items , Relation $ parentRelation = null ) { $ instance = $ model ; $ items = array_map ( function ( $ item ) use ( $ instance , $ parentRelation ) { $ item = $ item ? : [ ] ; return static :: newFromBuilderRecursive ( $ instance , $ item , $ parentRelat...
Create a collection of models from plain arrays recursive .
42,125
public static function loadPivotAttribute ( Model $ model , Relation $ parentRelation = null ) { $ attributes = $ model -> getAttributes ( ) ; foreach ( $ attributes as $ key => $ value ) { if ( $ key === 'pivot' ) { unset ( $ model [ $ key ] ) ; $ pivot = $ parentRelation -> newExistingPivot ( $ value ) ; $ model -> s...
Get the pivot attribute from a model .
42,126
public function getHeader ( ) : array { if ( null === $ this -> header_offset ) { return $ this -> header ; } if ( [ ] !== $ this -> header ) { return $ this -> header ; } $ this -> header = $ this -> setHeader ( $ this -> header_offset ) ; return $ this -> header ; }
Returns the CSV record used as header .
42,127
protected function setHeader ( int $ offset ) : array { $ header = $ this -> seekRow ( $ offset ) ; if ( false === $ header || [ ] === $ header ) { throw new Exception ( sprintf ( 'The header record does not exist or is empty at offset: `%s`' , $ offset ) ) ; } if ( 0 === $ offset ) { return $ this -> removeBOM ( $ hea...
Determine the CSV record header .
42,128
protected function seekRow ( int $ offset ) { foreach ( $ this -> getDocument ( ) as $ index => $ record ) { if ( $ offset === $ index ) { return $ record ; } } return false ; }
Returns the row at a given offset .
42,129
protected function getDocument ( ) : Iterator { if ( 70400 > PHP_VERSION_ID && '' === $ this -> escape ) { $ this -> document -> setCsvControl ( $ this -> delimiter , $ this -> enclosure ) ; return EmptyEscapeParser :: parse ( $ this -> document ) ; } $ this -> document -> setFlags ( SplFileObject :: READ_CSV | SplFile...
Returns the document as an Iterator .
42,130
protected function removeBOM ( array $ record , int $ bom_length , string $ enclosure ) : array { if ( 0 === $ bom_length ) { return $ record ; } $ record [ 0 ] = mb_substr ( $ record [ 0 ] , $ bom_length ) ; if ( $ enclosure . $ enclosure != substr ( $ record [ 0 ] . $ record [ 0 ] , strlen ( $ record [ 0 ] ) - 1 , 2 ...
Strip the BOM sequence from a record .
42,131
public function getRecords ( array $ header = [ ] ) : Iterator { $ header = $ this -> computeHeader ( $ header ) ; $ normalized = static function ( $ record ) : bool { return is_array ( $ record ) && $ record != [ null ] ; } ; $ bom = $ this -> getInputBOM ( ) ; $ document = $ this -> getDocument ( ) ; $ records = $ th...
Returns the CSV records as an iterator object .
42,132
protected function computeHeader ( array $ header ) { if ( [ ] === $ header ) { $ header = $ this -> getHeader ( ) ; } if ( $ header === array_unique ( array_filter ( $ header , 'is_string' ) ) ) { return $ header ; } throw new Exception ( 'The header record must be empty or a flat array with unique string values' ) ; ...
Returns the header to be used for iteration .
42,133
protected function combineHeader ( Iterator $ iterator , array $ header ) : Iterator { if ( [ ] === $ header ) { return $ iterator ; } $ field_count = count ( $ header ) ; $ mapper = static function ( array $ record ) use ( $ header , $ field_count ) : array { if ( count ( $ record ) != $ field_count ) { $ record = arr...
Combine the CSV header to each record if present .
42,134
protected function stripBOM ( Iterator $ iterator , string $ bom ) : Iterator { if ( '' === $ bom ) { return $ iterator ; } $ bom_length = mb_strlen ( $ bom ) ; $ mapper = function ( array $ record , int $ index ) use ( $ bom_length ) : array { if ( 0 !== $ index ) { return $ record ; } return $ this -> removeBOM ( $ r...
Strip the BOM sequence from the returned records if necessary .
42,135
public function setHeaderOffset ( $ offset ) : self { if ( $ offset === $ this -> header_offset ) { return $ this ; } if ( ! is_nullable_int ( $ offset ) ) { throw new TypeError ( sprintf ( __METHOD__ . '() expects 1 Argument to be null or an integer %s given' , gettype ( $ offset ) ) ) ; } if ( null !== $ offset && 0 ...
Selects the record to be used as the CSV header .
42,136
public static function triggerOnValidation ( string $ name , array $ record ) : self { $ exception = new static ( 'Record validation failed' ) ; $ exception -> name = $ name ; $ exception -> record = $ record ; return $ exception ; }
Create an Exception from a Record Validation .
42,137
public function getInputBOM ( ) : string { if ( null !== $ this -> input_bom ) { return $ this -> input_bom ; } $ this -> document -> setFlags ( SplFileObject :: READ_CSV ) ; $ this -> document -> rewind ( ) ; $ this -> input_bom = bom_match ( ( string ) $ this -> document -> fread ( 4 ) ) ; return $ this -> input_bom ...
Returns the BOM sequence of the given CSV .
42,138
public function chunk ( int $ length ) : Generator { if ( $ length < 1 ) { throw new Exception ( sprintf ( '%s() expects the length to be a positive integer %d given' , __METHOD__ , $ length ) ) ; } $ input_bom = $ this -> getInputBOM ( ) ; $ this -> document -> rewind ( ) ; $ this -> document -> fseek ( strlen ( $ inp...
Retuns the CSV document as a Generator of string chunk .
42,139
public function getContent ( ) : string { $ raw = '' ; foreach ( $ this -> chunk ( 8192 ) as $ chunk ) { $ raw .= $ chunk ; } return $ raw ; }
Retrieves the CSV content .
42,140
public function output ( string $ filename = null ) : int { if ( null !== $ filename ) { $ this -> sendHeaders ( $ filename ) ; } $ input_bom = $ this -> getInputBOM ( ) ; $ this -> document -> rewind ( ) ; $ this -> document -> fseek ( strlen ( $ input_bom ) ) ; echo $ this -> output_bom ; return strlen ( $ this -> ou...
Outputs all data on the CSV file .
42,141
protected function sendHeaders ( string $ filename ) { if ( strlen ( $ filename ) != strcspn ( $ filename , '\\/' ) ) { throw new Exception ( 'The filename cannot contain the "/" and "\\" characters.' ) ; } $ flag = FILTER_FLAG_STRIP_LOW ; if ( strlen ( $ filename ) !== mb_strlen ( $ filename ) ) { $ flag |= FILTER_FLA...
Send the CSV headers .
42,142
public function setDelimiter ( string $ delimiter ) : self { if ( $ delimiter === $ this -> delimiter ) { return $ this ; } if ( 1 === strlen ( $ delimiter ) ) { $ this -> delimiter = $ delimiter ; $ this -> resetProperties ( ) ; return $ this ; } throw new Exception ( sprintf ( '%s() expects delimiter to be a single c...
Sets the field delimiter .
42,143
public function setEnclosure ( string $ enclosure ) : self { if ( $ enclosure === $ this -> enclosure ) { return $ this ; } if ( 1 === strlen ( $ enclosure ) ) { $ this -> enclosure = $ enclosure ; $ this -> resetProperties ( ) ; return $ this ; } throw new Exception ( sprintf ( '%s() expects enclosure to be a single c...
Sets the field enclosure .
42,144
public function setEscape ( string $ escape ) : self { if ( $ escape === $ this -> escape ) { return $ this ; } if ( '' === $ escape || 1 === strlen ( $ escape ) ) { $ this -> escape = $ escape ; $ this -> resetProperties ( ) ; return $ this ; } throw new Exception ( sprintf ( '%s() expects escape to be a single charac...
Sets the field escape character .
42,145
public function addStreamFilter ( string $ filtername , $ params = null ) : self { if ( ! $ this -> document instanceof Stream ) { throw new Exception ( 'The stream filter API can not be used' ) ; } $ this -> document -> appendFilter ( $ filtername , $ this -> stream_filter_mode , $ params ) ; $ this -> stream_filters ...
append a stream filter .
42,146
protected static function isValidSequence ( string $ sequence ) : bool { return strlen ( $ sequence ) != strcspn ( $ sequence , self :: $ force_enclosure ) ; }
Filter type and sequence parameters .
42,147
public function insertAll ( $ records ) : int { if ( ! is_iterable ( $ records ) ) { throw new TypeError ( sprintf ( '%s() expects argument passed to be iterable, %s given' , __METHOD__ , gettype ( $ records ) ) ) ; } $ bytes = 0 ; foreach ( $ records as $ record ) { $ bytes += $ this -> insertOne ( $ record ) ; } $ th...
Adds multiple records to the CSV document .
42,148
public function insertOne ( array $ record ) : int { $ method = 'addRecord' ; if ( 70400 > PHP_VERSION_ID && '' === $ this -> escape ) { $ method = 'addRFC4180CompliantRecord' ; } $ record = array_reduce ( $ this -> formatters , [ $ this , 'formatRecord' ] , $ record ) ; $ this -> validateRecord ( $ record ) ; $ bytes ...
Adds a single record to a CSV document .
42,149
protected function addRecord ( array $ record ) { return $ this -> document -> fputcsv ( $ record , $ this -> delimiter , $ this -> enclosure , $ this -> escape ) ; }
Adds a single record to a CSV Document using PHP algorithm .
42,150
protected function addRFC4180CompliantRecord ( array $ record ) { foreach ( $ record as & $ field ) { $ field = ( string ) $ field ; if ( preg_match ( $ this -> rfc4180_regexp , $ field ) ) { $ field = $ this -> enclosure . str_replace ( $ this -> enclosure , $ this -> rfc4180_enclosure , $ field ) . $ this -> enclosur...
Adds a single record to a CSV Document using RFC4180 algorithm .
42,151
protected function validateRecord ( array $ record ) { foreach ( $ this -> validators as $ name => $ validator ) { if ( true !== $ validator ( $ record ) ) { throw CannotInsertRecord :: triggerOnValidation ( $ name , $ record ) ; } } }
Validate a record .
42,152
protected function consolidate ( ) : int { $ bytes = 0 ; if ( "\n" !== $ this -> newline ) { $ this -> document -> fseek ( - 1 , SEEK_CUR ) ; $ bytes = $ this -> document -> fwrite ( $ this -> newline , strlen ( $ this -> newline ) ) - 1 ; } if ( null === $ this -> flush_threshold ) { return $ bytes ; } ++ $ this -> fl...
Apply post insertion actions .
42,153
public function addValidator ( callable $ validator , string $ validator_name ) : self { $ this -> validators [ $ validator_name ] = $ validator ; return $ this ; }
Adds a record validator .
42,154
public function setFlushThreshold ( $ threshold ) : self { if ( $ threshold === $ this -> flush_threshold ) { return $ this ; } if ( ! is_nullable_int ( $ threshold ) ) { throw new TypeError ( sprintf ( __METHOD__ . '() expects 1 Argument to be null or an integer %s given' , gettype ( $ threshold ) ) ) ; } if ( null !=...
Set the flush threshold .
42,155
public function table ( string $ class_name , string $ id_value = '' ) : self { if ( preg_match ( ",\s," , $ id_value ) ) { throw new DOMException ( "the id attribute's value must not contain whitespace (spaces, tabs etc.)" ) ; } $ clone = clone $ this ; $ clone -> class_name = $ class_name ; $ clone -> id_value = $ id...
HTML table class name setter .
42,156
public function tr ( string $ record_offset_attribute_name ) : self { $ clone = clone $ this ; $ clone -> xml_converter = $ this -> xml_converter -> recordElement ( 'tr' , $ record_offset_attribute_name ) ; return $ clone ; }
HTML tr record offset attribute setter .
42,157
public function td ( string $ fieldname_attribute_name ) : self { $ clone = clone $ this ; $ clone -> xml_converter = $ this -> xml_converter -> fieldElement ( 'td' , $ fieldname_attribute_name ) ; return $ clone ; }
HTML td field name attribute setter .
42,158
public static function getFiltername ( string $ input_encoding , string $ output_encoding ) : string { return sprintf ( '%s.%s/%s' , self :: FILTERNAME , self :: filterEncoding ( $ input_encoding ) , self :: filterEncoding ( $ output_encoding ) ) ; }
Static method to return the stream filter filtername .
42,159
protected static function filterEncoding ( string $ encoding ) : string { static $ encoding_list ; if ( null === $ encoding_list ) { $ list = mb_list_encodings ( ) ; $ encoding_list = array_combine ( array_map ( 'strtolower' , $ list ) , $ list ) ; } $ key = strtolower ( $ encoding ) ; if ( isset ( $ encoding_list [ $ ...
Filter encoding charset .
42,160
public function convert ( $ records ) { if ( ! is_iterable ( $ records ) ) { throw new TypeError ( sprintf ( '%s() expects argument passed to be iterable, %s given' , __METHOD__ , gettype ( $ records ) ) ) ; } if ( $ this -> output_encoding === $ this -> input_encoding ) { return $ records ; } if ( is_array ( $ records...
Convert Csv records collection into UTF - 8 .
42,161
protected function encodeField ( & $ value , & $ offset ) { if ( null !== $ value && ! is_numeric ( $ value ) ) { $ value = mb_convert_encoding ( ( string ) $ value , $ this -> output_encoding , $ this -> input_encoding ) ; } if ( ! is_numeric ( $ offset ) ) { $ offset = mb_convert_encoding ( ( string ) $ offset , $ th...
Walker method to convert the offset and the value of a CSV record field .
42,162
public function inputEncoding ( string $ encoding ) : self { $ encoding = $ this -> filterEncoding ( $ encoding ) ; if ( $ encoding === $ this -> input_encoding ) { return $ this ; } $ clone = clone $ this ; $ clone -> input_encoding = $ encoding ; return $ clone ; }
Sets the records input encoding charset .
42,163
public function outputEncoding ( string $ encoding ) : self { $ encoding = $ this -> filterEncoding ( $ encoding ) ; if ( $ encoding === $ this -> output_encoding ) { return $ this ; } $ clone = clone $ this ; $ clone -> output_encoding = $ encoding ; return $ clone ; }
Sets the records output encoding charset .
42,164
protected function recordToElementWithAttribute ( DOMDocument $ doc , array $ record , string $ field_encoder , int $ offset ) : DOMElement { $ node = $ this -> recordToElement ( $ doc , $ record , $ field_encoder ) ; $ node -> setAttribute ( $ this -> offset_attr , ( string ) $ offset ) ; return $ node ; }
Convert a CSV record into a DOMElement and adds its offset as DOMElement attribute .
42,165
protected function recordToElement ( DOMDocument $ doc , array $ record , string $ field_encoder ) : DOMElement { $ node = $ doc -> createElement ( $ this -> record_name ) ; foreach ( $ record as $ node_name => $ value ) { $ item = $ this -> $ field_encoder ( $ doc , ( string ) $ value , $ node_name ) ; $ node -> appen...
Convert a CSV record into a DOMElement .
42,166
public function recordElement ( string $ node_name , string $ record_offset_attribute_name = '' ) : self { $ clone = clone $ this ; $ clone -> record_name = $ this -> filterElementName ( $ node_name ) ; $ clone -> offset_attr = $ this -> filterAttributeName ( $ record_offset_attribute_name ) ; return $ clone ; }
XML Record element setter .
42,167
public function fieldElement ( string $ node_name , string $ fieldname_attribute_name = '' ) : self { $ clone = clone $ this ; $ clone -> field_name = $ this -> filterElementName ( $ node_name ) ; $ clone -> column_attr = $ this -> filterAttributeName ( $ fieldname_attribute_name ) ; return $ clone ; }
XML Field element setter .
42,168
public function fetchOne ( int $ nth_record = 0 ) : array { if ( $ nth_record < 0 ) { throw new Exception ( sprintf ( '%s() expects the submitted offset to be a positive integer or 0, %s given' , __METHOD__ , $ nth_record ) ) ; } $ iterator = new LimitIterator ( $ this -> records , $ nth_record , 1 ) ; $ iterator -> re...
Returns the nth record from the result set .
42,169
public function fetchColumn ( $ index = 0 ) : Generator { $ offset = $ this -> getColumnIndex ( $ index , __METHOD__ . '() expects the column index to be a valid string or integer, `%s` given' ) ; $ filter = static function ( array $ record ) use ( $ offset ) : bool { return isset ( $ record [ $ offset ] ) ; } ; $ sele...
Returns a single column from the next record of the result set .
42,170
protected function getColumnIndex ( $ field , string $ error_message ) { $ method = is_string ( $ field ) ? 'getColumnIndexByValue' : 'getColumnIndexByKey' ; return $ this -> $ method ( $ field , $ error_message ) ; }
Filter a column name against the header if any .
42,171
protected function getColumnIndexByValue ( string $ value , string $ error_message ) : string { if ( false !== array_search ( $ value , $ this -> header , true ) ) { return $ value ; } throw new Exception ( sprintf ( $ error_message , $ value ) ) ; }
Returns the selected column name .
42,172
protected function getColumnIndexByKey ( int $ index , string $ error_message ) { if ( $ index < 0 ) { throw new Exception ( $ error_message ) ; } if ( [ ] === $ this -> header ) { return $ index ; } $ value = array_search ( $ index , array_flip ( $ this -> header ) , true ) ; if ( false !== $ value ) { return $ value ...
Returns the selected column name according to its offset .
42,173
public static function parse ( $ document ) : Generator { self :: $ document = self :: filterDocument ( $ document ) ; list ( self :: $ delimiter , self :: $ enclosure , ) = self :: $ document -> getCsvControl ( ) ; self :: $ trim_mask = str_replace ( [ self :: $ delimiter , self :: $ enclosure ] , '' , " \t\0\x0B" ) ;...
Converts the document into a CSV record iterator .
42,174
private static function filterDocument ( $ document ) { if ( $ document instanceof Stream || $ document instanceof SplFileObject ) { return $ document ; } throw new TypeError ( sprintf ( '%s::parse expects parameter 1 to be a %s or a SplFileObject object, %s given' , self :: class , Stream :: class , is_object ( $ docu...
Filters the submitted document .
42,175
private static function extractRecord ( ) : array { $ record = [ ] ; self :: $ line = self :: $ document -> fgets ( ) ; do { $ method = 'extractFieldContent' ; $ buffer = ltrim ( self :: $ line , self :: $ trim_mask ) ; if ( ( $ buffer [ 0 ] ?? '' ) === self :: $ enclosure ) { $ method = 'extractEnclosedFieldContent' ;...
Extracts a record form the CSV document .
42,176
private static function extractFieldContent ( ) { if ( in_array ( self :: $ line , self :: FIELD_BREAKS , true ) ) { self :: $ line = false ; return null ; } list ( $ content , self :: $ line ) = explode ( self :: $ delimiter , self :: $ line , 2 ) + [ 1 => false ] ; if ( false === self :: $ line ) { return rtrim ( $ c...
Extracts the content from a field without enclosure .
42,177
private static function extractEnclosedFieldContent ( ) { if ( ( self :: $ line [ 0 ] ?? '' ) === self :: $ enclosure ) { self :: $ line = substr ( self :: $ line , 1 ) ; } $ content = '' ; while ( false !== self :: $ line ) { list ( $ buffer , $ remainder ) = explode ( self :: $ enclosure , self :: $ line , 2 ) + [ 1 ...
Extracts the content from a field with enclosure .
42,178
public static function createFromString ( string $ content = '' ) { $ resource = fopen ( 'php://temp' , 'r+' ) ; fwrite ( $ resource , $ content ) ; $ instance = new static ( $ resource ) ; $ instance -> should_close_stream = true ; return $ instance ; }
Return a new instance from a string .
42,179
public function appendFilter ( string $ filtername , int $ read_write , $ params = null ) { $ res = @ stream_filter_append ( $ this -> stream , $ filtername , $ read_write , $ params ) ; if ( is_resource ( $ res ) ) { $ this -> filters [ $ filtername ] [ ] = $ res ; return ; } throw new Exception ( sprintf ( 'unable to...
append a filter .
42,180
public function setCsvControl ( string $ delimiter = ',' , string $ enclosure = '"' , string $ escape = '\\' ) { list ( $ this -> delimiter , $ this -> enclosure , $ this -> escape ) = $ this -> filterControl ( $ delimiter , $ enclosure , $ escape , __METHOD__ ) ; }
Set CSV control .
42,181
protected function filterControl ( string $ delimiter , string $ enclosure , string $ escape , string $ caller ) : array { $ controls = [ 'delimiter' => $ delimiter , 'enclosure' => $ enclosure , 'escape' => $ escape ] ; foreach ( $ controls as $ type => $ control ) { if ( 'escape' === $ type && '' === $ control && 704...
Filter Csv control characters .
42,182
public function fputcsv ( array $ fields , string $ delimiter = ',' , string $ enclosure = '"' , string $ escape = '\\' ) { $ controls = $ this -> filterControl ( $ delimiter , $ enclosure , $ escape , __METHOD__ ) ; return fputcsv ( $ this -> stream , $ fields , ... $ controls ) ; }
Write a field array as a CSV line .
42,183
public function rewind ( ) { if ( ! $ this -> is_seekable ) { throw new Exception ( 'stream does not support seeking' ) ; } rewind ( $ this -> stream ) ; $ this -> offset = 0 ; $ this -> value = false ; if ( $ this -> flags & SplFileObject :: READ_AHEAD ) { $ this -> current ( ) ; } }
Rewind the file to the first line .
42,184
public function valid ( ) { if ( $ this -> flags & SplFileObject :: READ_AHEAD ) { return $ this -> current ( ) !== false ; } return ! feof ( $ this -> stream ) ; }
Not at EOF .
42,185
public function current ( ) { if ( false !== $ this -> value ) { return $ this -> value ; } $ this -> value = $ this -> getCurrentRecord ( ) ; return $ this -> value ; }
Retrieves the current line of the file .
42,186
protected function getCurrentRecord ( ) { do { $ ret = fgetcsv ( $ this -> stream , 0 , $ this -> delimiter , $ this -> enclosure , $ this -> escape ) ; } while ( $ this -> flags & SplFileObject :: SKIP_EMPTY && $ ret !== false && $ ret [ 0 ] === null ) ; return $ ret ; }
Retrieves the current line as a CSV Record .
42,187
public function seek ( $ position ) { if ( $ position < 0 ) { throw new Exception ( sprintf ( '%s() can\'t seek stream to negative line %d' , __METHOD__ , $ position ) ) ; } $ this -> rewind ( ) ; while ( $ this -> key ( ) !== $ position && $ this -> valid ( ) ) { $ this -> current ( ) ; $ this -> next ( ) ; } if ( 0 !...
Seek to specified line .
42,188
public function fseek ( int $ offset , int $ whence = SEEK_SET ) { if ( ! $ this -> is_seekable ) { throw new Exception ( 'stream does not support seeking' ) ; } return fseek ( $ this -> stream , $ offset , $ whence ) ; }
Seek to a position .
42,189
public function offset ( int $ offset ) : self { if ( 0 > $ offset ) { throw new Exception ( sprintf ( '%s() expects the offset to be a positive integer or 0, %s given' , __METHOD__ , $ offset ) ) ; } if ( $ offset === $ this -> offset ) { return $ this ; } $ clone = clone $ this ; $ clone -> offset = $ offset ; return...
Set LimitIterator Offset .
42,190
public function limit ( int $ limit ) : self { if ( - 1 > $ limit ) { throw new Exception ( sprintf ( '%s() expects the limit to be greater or equal to -1, %s given' , __METHOD__ , $ limit ) ) ; } if ( $ limit === $ this -> limit ) { return $ this ; } $ clone = clone $ this ; $ clone -> limit = $ limit ; return $ clone...
Set LimitIterator Count .
42,191
protected function buildOrderBy ( Iterator $ iterator ) : Iterator { if ( [ ] === $ this -> order_by ) { return $ iterator ; } $ compare = function ( array $ record_a , array $ record_b ) : int { foreach ( $ this -> order_by as $ callable ) { if ( 0 !== ( $ cmp = $ callable ( $ record_a , $ record_b ) ) ) { return $ cm...
Sort the Iterator .
42,192
protected function isValidParams ( array $ params ) : bool { static $ mode_list = [ STREAM_FILTER_READ => 1 , STREAM_FILTER_WRITE => 1 ] ; return isset ( $ params [ 'enclosure' ] , $ params [ 'escape' ] , $ params [ 'mode' ] , $ mode_list [ $ params [ 'mode' ] ] ) && 1 == strlen ( $ params [ 'enclosure' ] ) && 1 == str...
Validate params property .
42,193
protected function isValidSequence ( array $ params ) { return isset ( $ params [ 'whitespace_replace' ] ) && strlen ( $ params [ 'whitespace_replace' ] ) == strcspn ( $ params [ 'whitespace_replace' ] , self :: $ force_enclosure ) ; }
Is Valid White space replaced sequence .
42,194
public function serves ( $ sitePath , $ siteName , $ uri ) { $ typo3Dir = $ sitePath . $ this -> documentRoot . '/typo3' ; return file_exists ( $ typo3Dir ) && is_dir ( $ typo3Dir ) ; }
Determine if the driver serves the request . For TYPO3 this is the case if a folder called typo3 is present in the document root .
42,195
private function isAccessAuthorized ( $ uri ) { foreach ( $ this -> forbiddenUriPatterns as $ forbiddenUriPattern ) { if ( preg_match ( "@$forbiddenUriPattern@" , $ uri ) ) { return false ; } } return true ; }
Determines if the given URI is blacklisted so that access is prevented .
42,196
public function frontControllerPath ( $ sitePath , $ siteName , $ uri ) { $ this -> handleRedirectBackendShorthandUris ( $ uri ) ; $ uri = rtrim ( $ uri , '/' ) ; if ( file_exists ( $ absoluteFilePath = $ sitePath . $ this -> documentRoot . $ uri ) ) { if ( is_dir ( $ absoluteFilePath ) ) { if ( file_exists ( $ absolut...
Get the fully resolved path to the application s front controller . This can be the currently requested PHP script a folder that contains an index . php or the global index . php otherwise .
42,197
public static function assign ( $ sitePath , $ siteName , $ uri ) { $ drivers = [ ] ; if ( $ customSiteDriver = static :: customSiteDriver ( $ sitePath ) ) { $ drivers [ ] = $ customSiteDriver ; } $ drivers = array_merge ( $ drivers , static :: driversIn ( VALET_HOME_PATH . '/Drivers' ) ) ; $ drivers [ ] = 'LaravelVale...
Find a driver that can serve the incoming request .
42,198
public static function driversIn ( $ path ) { if ( ! is_dir ( $ path ) ) { return [ ] ; } $ drivers = [ ] ; $ dir = new RecursiveDirectoryIterator ( $ path ) ; $ iterator = new RecursiveIteratorIterator ( $ dir ) ; $ regex = new RegexIterator ( $ iterator , '/^.+ValetDriver\.php$/i' , RecursiveRegexIterator :: GET_MATC...
Get all of the driver classes in a given path .
42,199
public function serveStaticFile ( $ staticFilePath , $ sitePath , $ siteName , $ uri ) { header ( 'Content-Type: text/html' ) ; header_remove ( 'Content-Type' ) ; header ( 'X-Accel-Redirect: /' . VALET_STATIC_PREFIX . $ staticFilePath ) ; }
Serve the static file at the given path .