idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
200
protected function applyConditions ( array $ where ) { foreach ( $ where as $ field => $ value ) { if ( is_array ( $ value ) ) { list ( $ field , $ condition , $ val ) = $ value ; $ this -> model = $ this -> model -> where ( $ field , $ condition , $ val ) ; } else { $ this -> model = $ this -> model -> where ( $ field , '=' , $ value ) ; } } }
Applies the given where conditions to the model .
201
public function parserResult ( $ result ) { if ( $ this -> presenter instanceof PresenterInterface ) { if ( $ result instanceof Collection || $ result instanceof LengthAwarePaginator ) { $ result -> each ( function ( $ model ) { if ( $ model instanceof Presentable ) { $ model -> setPresenter ( $ this -> presenter ) ; } return $ model ; } ) ; } elseif ( $ result instanceof Presentable ) { $ result = $ result -> setPresenter ( $ this -> presenter ) ; } if ( ! $ this -> skipPresenter ) { return $ this -> presenter -> present ( $ result ) ; } } return $ result ; }
Wrapper result data
202
public function getName ( ) { $ name = $ this -> name ; if ( str_contains ( $ this -> name , '\\' ) ) { $ name = str_replace ( '\\' , '/' , $ this -> name ) ; } if ( str_contains ( $ this -> name , '/' ) ) { $ name = str_replace ( '/' , '/' , $ this -> name ) ; } return Str :: studly ( str_replace ( ' ' , '/' , ucwords ( str_replace ( '/' , ' ' , $ name ) ) ) ) ; }
Get name input .
203
public function getConfigGeneratorClassPath ( $ class , $ directoryPath = false ) { switch ( $ class ) { case ( 'models' === $ class ) : $ path = config ( 'repository.generator.paths.models' , 'Entities' ) ; break ; case ( 'repositories' === $ class ) : $ path = config ( 'repository.generator.paths.repositories' , 'Repositories' ) ; break ; case ( 'interfaces' === $ class ) : $ path = config ( 'repository.generator.paths.interfaces' , 'Repositories' ) ; break ; case ( 'presenters' === $ class ) : $ path = config ( 'repository.generator.paths.presenters' , 'Presenters' ) ; break ; case ( 'transformers' === $ class ) : $ path = config ( 'repository.generator.paths.transformers' , 'Transformers' ) ; break ; case ( 'validators' === $ class ) : $ path = config ( 'repository.generator.paths.validators' , 'Validators' ) ; break ; case ( 'controllers' === $ class ) : $ path = config ( 'repository.generator.paths.controllers' , 'Http\Controllers' ) ; break ; case ( 'provider' === $ class ) : $ path = config ( 'repository.generator.paths.provider' , 'RepositoryServiceProvider' ) ; break ; case ( 'criteria' === $ class ) : $ path = config ( 'repository.generator.paths.criteria' , 'Criteria' ) ; break ; default : $ path = '' ; } if ( $ directoryPath ) { $ path = str_replace ( '\\' , '/' , $ path ) ; } else { $ path = str_replace ( '/' , '\\' , $ path ) ; } return $ path ; }
Get class - specific output paths .
204
protected function dumpDatabases ( ) : array { return $ this -> dbDumpers -> map ( function ( DbDumper $ dbDumper , $ key ) { consoleOutput ( ) -> info ( "Dumping database {$dbDumper->getDbName()}..." ) ; $ dbType = mb_strtolower ( basename ( str_replace ( '\\' , '/' , get_class ( $ dbDumper ) ) ) ) ; $ dbName = $ dbDumper -> getDbName ( ) ; if ( $ dbDumper instanceof Sqlite ) { $ dbName = $ key . '-database' ; } $ fileName = "{$dbType}-{$dbName}.{$this->getExtension($dbDumper)}" ; if ( config ( 'backup.backup.gzip_database_dump' ) ) { $ dbDumper -> useCompressor ( new GzipCompressor ( ) ) ; $ fileName .= '.' . $ dbDumper -> getCompressorExtension ( ) ; } if ( $ compressor = config ( 'backup.backup.database_dump_compressor' ) ) { $ dbDumper -> useCompressor ( new $ compressor ( ) ) ; $ fileName .= '.' . $ dbDumper -> getCompressorExtension ( ) ; } $ temporaryFilePath = $ this -> temporaryDirectory -> path ( 'db-dumps' . DIRECTORY_SEPARATOR . $ fileName ) ; $ dbDumper -> dumpToFile ( $ temporaryFilePath ) ; return $ temporaryFilePath ; } ) -> toArray ( ) ; }
Dumps the databases to the given directory . Returns an array with paths to the dump files .
205
public function excludeFilesFrom ( $ excludeFilesAndDirectories ) : self { $ this -> excludeFilesAndDirectories = $ this -> excludeFilesAndDirectories -> merge ( $ this -> sanitize ( $ excludeFilesAndDirectories ) ) ; return $ this ; }
Do not included the given files and directories .
206
public function write_bits ( $ bits ) { $ value = 0 ; foreach ( $ bits as $ n => $ bit ) { $ bit = $ bit ? 1 : 0 ; $ value |= ( $ bit << $ n ) ; } $ this -> out .= chr ( $ value ) ; return $ this ; }
Write multiple bits as an octet
207
public function write_octet ( $ n ) { if ( $ n < 0 || $ n > 255 ) { throw new AMQPInvalidArgumentException ( 'Octet out of range: ' . $ n ) ; } $ this -> out .= chr ( $ n ) ; return $ this ; }
Write an integer as an unsigned 8 - bit value
208
public function write_short ( $ n ) { if ( $ n < 0 || $ n > 65535 ) { throw new AMQPInvalidArgumentException ( 'Short out of range: ' . $ n ) ; } $ this -> out .= pack ( 'n' , $ n ) ; return $ this ; }
Write an integer as an unsigned 16 - bit value
209
public function write_long ( $ n ) { if ( ( $ n < 0 ) || ( $ n > 4294967295 ) ) { throw new AMQPInvalidArgumentException ( 'Long out of range: ' . $ n ) ; } if ( empty ( $ this -> is64bits ) && is_string ( $ n ) ) { $ n = ( float ) $ n ; } $ this -> out .= pack ( 'N' , $ n ) ; return $ this ; }
Write an integer as an unsigned 32 - bit value
210
public function write_longlong ( $ n ) { if ( $ n < 0 ) { throw new AMQPInvalidArgumentException ( 'Longlong out of range: ' . $ n ) ; } if ( bcadd ( $ n , - PHP_INT_MAX , 0 ) <= 0 ) { if ( $ this -> is64bits ) { list ( $ hi , $ lo ) = $ this -> splitIntoQuads ( $ n ) ; } else { $ hi = 0 ; $ lo = $ n ; } $ this -> out .= pack ( 'NN' , $ hi , $ lo ) ; } else { try { $ this -> out .= self :: packBigEndian ( $ n , 8 ) ; } catch ( AMQPOutOfBoundsException $ ex ) { throw new AMQPInvalidArgumentException ( 'Longlong out of range: ' . $ n , 0 , $ ex ) ; } } return $ this ; }
Write an integer as an unsigned 64 - bit value
211
public function write_shortstr ( $ s ) { $ len = mb_strlen ( $ s , 'ASCII' ) ; if ( $ len > 255 ) { throw new AMQPInvalidArgumentException ( 'String too long' ) ; } $ this -> write_octet ( $ len ) ; $ this -> out .= $ s ; return $ this ; }
Write a string up to 255 bytes long after encoding . Assume UTF - 8 encoding
212
protected function prepare_method_frame ( $ method_sig , $ args = '' , $ pkt = null ) { return $ this -> connection -> prepare_channel_method_frame ( $ this -> channel_id , $ method_sig , $ args , $ pkt ) ; }
This is here for performance reasons to batch calls to fwrite from basic . publish
213
public function wait ( $ allowed_methods = null , $ non_blocking = false , $ timeout = 0 ) { $ this -> debug -> debug_allowed_methods ( $ allowed_methods ) ; $ deferred = $ this -> process_deferred_methods ( $ allowed_methods ) ; if ( $ deferred [ 'dispatch' ] === true ) { return $ this -> dispatch_deferred_method ( $ deferred [ 'queued_method' ] ) ; } if ( true === $ non_blocking ) { $ timeout = null ; } while ( true ) { try { list ( $ frame_type , $ payload ) = $ this -> next_frame ( $ timeout ) ; } catch ( AMQPNoDataException $ e ) { break ; } catch ( AMQPConnectionClosedException $ exception ) { if ( $ this instanceof AMQPChannel ) { $ this -> do_close ( ) ; } throw $ exception ; } $ this -> validate_method_frame ( $ frame_type ) ; $ this -> validate_frame_payload ( $ payload ) ; $ method_sig = $ this -> build_method_signature ( $ payload ) ; $ args = $ this -> extract_args ( $ payload ) ; $ this -> debug -> debug_method_signature ( '> %s' , $ method_sig ) ; $ amqpMessage = $ this -> maybe_wait_for_content ( $ method_sig ) ; if ( $ this -> should_dispatch_method ( $ allowed_methods , $ method_sig ) ) { return $ this -> dispatch ( $ method_sig , $ args , $ amqpMessage ) ; } $ this -> debug -> debug_method_signature ( 'Queueing for later: %s' , $ method_sig ) ; $ this -> method_queue [ ] = array ( $ method_sig , $ args , $ amqpMessage ) ; if ( $ non_blocking ) { break ; } } }
Wait for some expected AMQP methods and dispatch to them . Unexpected methods are queued up for later calls to this PHP method .
214
public function has ( $ name ) { return isset ( $ this -> properties [ $ name ] ) || isset ( $ this -> delivery_info [ $ name ] ) ; }
Check whether a property exists in the properties dictionary or if present - in the delivery_info dictionary .
215
public function get ( $ name ) { if ( isset ( $ this -> properties [ $ name ] ) ) { return $ this -> properties [ $ name ] ; } if ( isset ( $ this -> delivery_info [ $ name ] ) ) { return $ this -> delivery_info [ $ name ] ; } throw new \ OutOfBoundsException ( sprintf ( 'No "%s" property' , $ name ) ) ; }
Look for additional properties in the properties dictionary and if present - the delivery_info dictionary .
216
protected function write_heartbeat ( ) { $ pkt = new AMQPWriter ( ) ; $ pkt -> write_octet ( 8 ) ; $ pkt -> write_short ( 0 ) ; $ pkt -> write_long ( 0 ) ; $ pkt -> write_octet ( 0xCE ) ; $ this -> write ( $ pkt -> getvalue ( ) ) ; }
Sends a heartbeat message
217
protected function cleanup_error_handler ( ) { restore_error_handler ( ) ; if ( $ this -> last_error !== null ) { throw new \ ErrorException ( $ this -> last_error [ 'errstr' ] , 0 , $ this -> last_error [ 'errno' ] , $ this -> last_error [ 'errfile' ] , $ this -> last_error [ 'errline' ] ) ; } }
throws an ErrorException if an error was handled
218
public function error_handler ( $ errno , $ errstr , $ errfile , $ errline , $ errcontext = null ) { $ this -> last_error = compact ( 'errno' , 'errstr' , 'errfile' , 'errline' , 'errcontext' ) ; }
Internal error handler to deal with stream and socket errors .
219
public function reuse ( $ str ) { $ this -> str = $ str ; $ this -> str_length = mb_strlen ( $ this -> str , 'ASCII' ) ; $ this -> offset = 0 ; $ this -> bitcount = $ this -> bits = 0 ; }
Resets the object from the injected param
220
protected function wait ( ) { $ timeout = $ this -> getTimeout ( ) ; if ( null === $ timeout ) { $ sec = 0 ; $ usec = 0 ; } elseif ( $ timeout > 0 ) { list ( $ sec , $ usec ) = MiscHelper :: splitSecondsMicroseconds ( $ this -> getTimeout ( ) ) ; } else { $ sec = null ; $ usec = 0 ; } $ result = $ this -> io -> select ( $ sec , $ usec ) ; if ( $ result === false ) { throw new AMQPIOWaitException ( 'A network error occurred while awaiting for incoming data' ) ; } if ( $ result === 0 ) { if ( $ timeout > 0 ) { throw new AMQPTimeoutException ( sprintf ( 'The connection timed out after %s sec while awaiting incoming data' , $ timeout ) ) ; } else { throw new AMQPNoDataException ( 'No data is ready to read' ) ; } } }
Waits until some data is retrieved from the socket .
221
public function read_longlong ( ) { $ this -> bitcount = $ this -> bits = 0 ; list ( , $ hi , $ lo ) = unpack ( 'N2' , $ this -> rawread ( 8 ) ) ; $ msb = self :: getLongMSB ( $ hi ) ; if ( empty ( $ this -> is64bits ) ) { if ( $ msb ) { $ hi = sprintf ( '%u' , $ hi ) ; } if ( self :: getLongMSB ( $ lo ) ) { $ lo = sprintf ( '%u' , $ lo ) ; } } return bcadd ( $ this -> is64bits && ! $ msb ? $ hi << 32 : bcmul ( $ hi , '4294967296' , 0 ) , $ lo , 0 ) ; }
Even on 64 bit systems PHP integers are singed . Since we need an unsigned value here we return it as a string .
222
public function read_array ( $ returnObject = false ) { $ this -> bitcount = $ this -> bits = 0 ; $ arrayLength = $ this -> read_php_int ( ) ; $ endOffset = $ this -> offset + $ arrayLength ; $ result = $ returnObject ? new AMQPArray ( ) : array ( ) ; while ( $ this -> offset < $ endOffset ) { $ fieldType = AMQPAbstractCollection :: getDataTypeForSymbol ( $ this -> rawread ( 1 ) ) ; $ fieldValue = $ this -> read_value ( $ fieldType , $ returnObject ) ; $ returnObject ? $ result -> push ( $ fieldValue , $ fieldType ) : $ result [ ] = $ fieldValue ; } return $ result ; }
Reads the array in the next value .
223
public function read_value ( $ fieldType , $ collectionsAsObjects = false ) { $ this -> bitcount = $ this -> bits = 0 ; switch ( $ fieldType ) { case AMQPAbstractCollection :: T_INT_SHORTSHORT : $ val = $ this -> read_signed_octet ( ) ; break ; case AMQPAbstractCollection :: T_INT_SHORTSHORT_U : $ val = $ this -> read_octet ( ) ; break ; case AMQPAbstractCollection :: T_INT_SHORT : $ val = $ this -> read_signed_short ( ) ; break ; case AMQPAbstractCollection :: T_INT_SHORT_U : $ val = $ this -> read_short ( ) ; break ; case AMQPAbstractCollection :: T_INT_LONG : $ val = $ this -> read_signed_long ( ) ; break ; case AMQPAbstractCollection :: T_INT_LONG_U : $ val = $ this -> read_long ( ) ; break ; case AMQPAbstractCollection :: T_INT_LONGLONG : $ val = $ this -> read_signed_longlong ( ) ; break ; case AMQPAbstractCollection :: T_INT_LONGLONG_U : $ val = $ this -> read_longlong ( ) ; break ; case AMQPAbstractCollection :: T_DECIMAL : $ e = $ this -> read_octet ( ) ; $ n = $ this -> read_signed_long ( ) ; $ val = new AMQPDecimal ( $ n , $ e ) ; break ; case AMQPAbstractCollection :: T_TIMESTAMP : $ val = $ this -> read_timestamp ( ) ; break ; case AMQPAbstractCollection :: T_BOOL : $ val = $ this -> read_octet ( ) ; break ; case AMQPAbstractCollection :: T_STRING_SHORT : $ val = $ this -> read_shortstr ( ) ; break ; case AMQPAbstractCollection :: T_STRING_LONG : $ val = $ this -> read_longstr ( ) ; break ; case AMQPAbstractCollection :: T_ARRAY : $ val = $ this -> read_array ( $ collectionsAsObjects ) ; break ; case AMQPAbstractCollection :: T_TABLE : $ val = $ this -> read_table ( $ collectionsAsObjects ) ; break ; case AMQPAbstractCollection :: T_VOID : $ val = null ; break ; case AMQPAbstractCollection :: T_BYTES : $ val = $ this -> read_longstr ( ) ; break ; default : throw new AMQPInvalidArgumentException ( sprintf ( 'Unsupported type "%s"' , $ fieldType ) ) ; } return isset ( $ val ) ? $ val : null ; }
Reads the next value as the provided field type .
224
protected function connect ( ) { try { while ( ! $ this -> isConnected ( ) ) { $ this -> setIsConnected ( true ) ; $ this -> io -> connect ( ) ; $ this -> channels = array ( ) ; parent :: __construct ( $ this , 0 ) ; $ this -> input = new AMQPReader ( null , $ this -> io ) ; $ this -> write ( $ this -> amqp_protocol_header ) ; $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'connection.start' ) ) , false , $ this -> connection_timeout ) ; $ this -> x_start_ok ( $ this -> getLibraryProperties ( ) , $ this -> login_method , $ this -> login_response , $ this -> locale ) ; $ this -> wait_tune_ok = true ; while ( $ this -> wait_tune_ok ) { $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'connection.secure' ) , $ this -> waitHelper -> get_wait ( 'connection.tune' ) ) ) ; } $ host = $ this -> x_open ( $ this -> vhost , '' , $ this -> insist ) ; if ( ! $ host ) { $ this -> io -> reenableHeartbeat ( ) ; return null ; } $ this -> setIsConnected ( false ) ; $ this -> closeChannels ( ) ; $ this -> close_socket ( ) ; } } catch ( \ Exception $ e ) { $ this -> setIsConnected ( false ) ; $ this -> closeChannels ( ) ; $ this -> close_input ( ) ; $ this -> close_socket ( ) ; throw $ e ; } }
Connects to the AMQP server
225
public function reconnect ( ) { $ this -> safeClose ( ) ; $ this -> io -> close ( ) ; $ this -> setIsConnected ( false ) ; $ this -> connect ( ) ; }
Reconnects using the original connection settings . This will not recreate any channels that were established previously
226
protected function safeClose ( ) { try { if ( isset ( $ this -> input ) && $ this -> input ) { $ this -> close ( ) ; } } catch ( \ Exception $ e ) { } }
Attempts to close the connection safely
227
protected function wait_frame ( $ timeout = 0 ) { if ( is_null ( $ this -> input ) ) { $ this -> setIsConnected ( false ) ; throw new AMQPConnectionClosedException ( 'Broken pipe or closed connection' ) ; } $ currentTimeout = $ this -> input -> getTimeout ( ) ; $ this -> input -> setTimeout ( $ timeout ) ; try { $ this -> wait_frame_reader -> reuse ( $ this -> input -> read ( AMQPReader :: OCTET + AMQPReader :: SHORT + AMQPReader :: LONG ) ) ; $ frame_type = $ this -> wait_frame_reader -> read_octet ( ) ; $ class = self :: $ PROTOCOL_CONSTANTS_CLASS ; if ( ! array_key_exists ( $ frame_type , $ class :: $ FRAME_TYPES ) ) { throw new AMQPInvalidFrameException ( 'Invalid frame type ' . $ frame_type ) ; } $ channel = $ this -> wait_frame_reader -> read_short ( ) ; $ size = $ this -> wait_frame_reader -> read_long ( ) ; $ this -> wait_frame_reader -> reuse ( $ this -> input -> read ( AMQPReader :: OCTET + ( int ) $ size ) ) ; $ payload = $ this -> wait_frame_reader -> read ( $ size ) ; $ ch = $ this -> wait_frame_reader -> read_octet ( ) ; } catch ( AMQPTimeoutException $ e ) { $ this -> input -> setTimeout ( $ currentTimeout ) ; throw $ e ; } catch ( AMQPNoDataException $ e ) { if ( $ this -> input ) { $ this -> input -> setTimeout ( $ currentTimeout ) ; } throw $ e ; } catch ( AMQPConnectionClosedException $ exception ) { $ this -> do_close ( ) ; throw $ exception ; } $ this -> input -> setTimeout ( $ currentTimeout ) ; if ( $ ch != 0xCE ) { throw new AMQPInvalidFrameException ( sprintf ( 'Framing error, unexpected byte: %x' , $ ch ) ) ; } return array ( $ frame_type , $ channel , $ payload ) ; }
Waits for a frame from the server
228
protected function wait_channel ( $ channel_id , $ timeout = 0 ) { $ _timeout = $ timeout ; while ( true ) { $ now = time ( ) ; try { list ( $ frame_type , $ frame_channel , $ payload ) = $ this -> wait_frame ( $ _timeout ) ; } catch ( AMQPTimeoutException $ e ) { if ( $ this -> heartbeat && microtime ( true ) - ( $ this -> heartbeat * 2 ) > $ this -> last_frame ) { $ this -> debug -> debug_msg ( "missed server heartbeat (at threshold * 2)" ) ; $ this -> setIsConnected ( false ) ; throw new AMQPHeartbeatMissedException ( "Missed server heartbeat" ) ; } throw $ e ; } $ this -> last_frame = microtime ( true ) ; if ( $ frame_channel === 0 && $ frame_type === 8 ) { $ this -> debug -> debug_msg ( "received server heartbeat" ) ; if ( $ _timeout > 0 ) { $ _timeout -= time ( ) - $ now ; if ( $ _timeout <= 0 ) { throw new AMQPTimeoutException ( "Timeout waiting on channel" ) ; } } continue ; } else { if ( $ frame_channel == $ channel_id ) { return array ( $ frame_type , $ payload ) ; } if ( isset ( $ this -> channels [ $ frame_channel ] ) ) { array_push ( $ this -> channels [ $ frame_channel ] -> frame_queue , array ( $ frame_type , $ payload ) ) ; } if ( ( $ frame_type == 1 ) && ( $ frame_channel == 0 ) ) { $ this -> wait ( ) ; } } } }
Waits for a frame from the server destined for a particular channel .
229
public function close ( $ reply_code = 0 , $ reply_text = '' , $ method_sig = array ( 0 , 0 ) ) { $ result = null ; $ this -> io -> disableHeartbeat ( ) ; if ( empty ( $ this -> protocolWriter ) || ! $ this -> isConnected ( ) ) { return $ result ; } try { $ this -> closeChannels ( ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> connectionClose ( $ reply_code , $ reply_text , $ method_sig [ 0 ] , $ method_sig [ 1 ] ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; $ result = $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'connection.close_ok' ) ) , false , $ this -> connection_timeout ) ; } catch ( \ Exception $ exception ) { $ this -> do_close ( ) ; throw $ exception ; } $ this -> setIsConnected ( false ) ; return $ result ; }
Requests a connection close
230
protected function connection_open_ok ( $ args ) { $ this -> known_hosts = $ args -> read_shortstr ( ) ; $ this -> debug -> debug_msg ( 'Open OK! known_hosts: ' . $ this -> known_hosts ) ; }
Signals that the connection is ready
231
protected function connection_redirect ( $ args ) { $ host = $ args -> read_shortstr ( ) ; $ this -> known_hosts = $ args -> read_shortstr ( ) ; $ this -> debug -> debug_msg ( sprintf ( 'Redirected to [%s], known_hosts [%s]' , $ host , $ this -> known_hosts ) ) ; return $ host ; }
Asks the client to use a different server
232
protected function x_secure_ok ( $ response ) { $ args = new AMQPWriter ( ) ; $ args -> write_longstr ( $ response ) ; $ this -> send_method_frame ( array ( 10 , 21 ) , $ args ) ; }
Security mechanism response
233
protected function connection_start ( $ args ) { $ this -> version_major = $ args -> read_octet ( ) ; $ this -> version_minor = $ args -> read_octet ( ) ; $ this -> server_properties = $ args -> read_table ( ) ; $ this -> mechanisms = explode ( ' ' , $ args -> read_longstr ( ) ) ; $ this -> locales = explode ( ' ' , $ args -> read_longstr ( ) ) ; $ this -> debug -> debug_connection_start ( $ this -> version_major , $ this -> version_minor , $ this -> server_properties , $ this -> mechanisms , $ this -> locales ) ; }
Starts connection negotiation
234
protected function connection_tune ( $ args ) { $ v = $ args -> read_short ( ) ; if ( $ v ) { $ this -> channel_max = $ v ; } $ v = $ args -> read_long ( ) ; if ( $ v ) { $ this -> frame_max = $ v ; } if ( $ this -> heartbeat === null ) { $ this -> heartbeat = $ args -> read_short ( ) ; } $ this -> x_tune_ok ( $ this -> channel_max , $ this -> frame_max , $ this -> heartbeat ) ; }
Proposes connection tuning parameters
235
protected function x_tune_ok ( $ channel_max , $ frame_max , $ heartbeat ) { $ args = new AMQPWriter ( ) ; $ args -> write_short ( $ channel_max ) ; $ args -> write_long ( $ frame_max ) ; $ args -> write_short ( $ heartbeat ) ; $ this -> send_method_frame ( array ( 10 , 31 ) , $ args ) ; $ this -> wait_tune_ok = false ; }
Negotiates connection tuning parameters
236
protected function closeChannels ( ) { foreach ( $ this -> channels as $ key => $ channel ) { if ( $ key === 0 ) { continue ; } try { $ channel -> close ( ) ; } catch ( \ Exception $ e ) { } } }
Closes all available channels
237
protected function channel_alert ( $ reader ) { $ reply_code = $ reader -> read_short ( ) ; $ reply_text = $ reader -> read_shortstr ( ) ; $ details = $ reader -> read_table ( ) ; array_push ( $ this -> alerts , array ( $ reply_code , $ reply_text , $ details ) ) ; }
Only for AMQP0 . 8 . 0 This method allows the server to send a non - fatal warning to the client . This is used for methods that are normally asynchronous and thus do not have confirmations and for which the server may detect errors that need to be reported . Fatal errors are handled as channel or connection exceptions ; non - fatal errors are sent through this method .
238
public function close ( $ reply_code = 0 , $ reply_text = '' , $ method_sig = array ( 0 , 0 ) ) { $ this -> callbacks = array ( ) ; if ( $ this -> is_open === false || $ this -> connection === null ) { $ this -> do_close ( ) ; return null ; } list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> channelClose ( $ reply_code , $ reply_text , $ method_sig [ 0 ] , $ method_sig [ 1 ] ) ; try { $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; } catch ( \ Exception $ e ) { $ this -> do_close ( ) ; throw $ e ; } return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'channel.close_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Request a channel close
239
public function access_request ( $ realm , $ exclusive = false , $ passive = false , $ active = false , $ write = false , $ read = false ) { list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> accessRequest ( $ realm , $ exclusive , $ passive , $ active , $ write , $ read ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'access.request_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Requests an access ticket
240
public function exchange_delete ( $ exchange , $ if_unused = false , $ nowait = false , $ ticket = null ) { $ ticket = $ this -> getTicket ( $ ticket ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> exchangeDelete ( $ ticket , $ exchange , $ if_unused , $ nowait ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; if ( $ nowait ) { return null ; } return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'exchange.delete_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Deletes an exchange
241
public function exchange_bind ( $ destination , $ source , $ routing_key = '' , $ nowait = false , $ arguments = array ( ) , $ ticket = null ) { $ ticket = $ this -> getTicket ( $ ticket ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> exchangeBind ( $ ticket , $ destination , $ source , $ routing_key , $ nowait , $ arguments ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; if ( $ nowait ) { return null ; } return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'exchange.bind_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Binds dest exchange to source exchange
242
public function queue_bind ( $ queue , $ exchange , $ routing_key = '' , $ nowait = false , $ arguments = array ( ) , $ ticket = null ) { $ ticket = $ this -> getTicket ( $ ticket ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> queueBind ( $ ticket , $ queue , $ exchange , $ routing_key , $ nowait , $ arguments ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; if ( $ nowait ) { return null ; } return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'queue.bind_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Binds queue to an exchange
243
public function queue_unbind ( $ queue , $ exchange , $ routing_key = '' , $ arguments = array ( ) , $ ticket = null ) { $ ticket = $ this -> getTicket ( $ ticket ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> queueUnbind ( $ ticket , $ queue , $ exchange , $ routing_key , $ arguments ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'queue.unbind_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Unbind queue from an exchange
244
protected function queue_declare_ok ( $ reader ) { $ queue = $ reader -> read_shortstr ( ) ; $ message_count = $ reader -> read_long ( ) ; $ consumer_count = $ reader -> read_long ( ) ; return array ( $ queue , $ message_count , $ consumer_count ) ; }
Confirms a queue definition
245
public function queue_delete ( $ queue = '' , $ if_unused = false , $ if_empty = false , $ nowait = false , $ ticket = null ) { $ ticket = $ this -> getTicket ( $ ticket ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> queueDelete ( $ ticket , $ queue , $ if_unused , $ if_empty , $ nowait ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; if ( $ nowait ) { return null ; } return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'queue.delete_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Deletes a queue
246
public function queue_purge ( $ queue = '' , $ nowait = false , $ ticket = null ) { $ ticket = $ this -> getTicket ( $ ticket ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> queuePurge ( $ ticket , $ queue , $ nowait ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; if ( $ nowait ) { return null ; } return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'queue.purge_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Purges a queue
247
public function basic_ack ( $ delivery_tag , $ multiple = false ) { list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> basicAck ( $ delivery_tag , $ multiple ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; }
Acknowledges one or more messages
248
protected function basic_ack_from_server ( AMQPReader $ reader ) { $ delivery_tag = $ reader -> read_longlong ( ) ; $ multiple = ( bool ) $ reader -> read_bit ( ) ; if ( ! isset ( $ this -> published_messages [ $ delivery_tag ] ) ) { throw new AMQPRuntimeException ( sprintf ( 'Server ack\'ed unknown delivery_tag "%s"' , $ delivery_tag ) ) ; } $ this -> internal_ack_handler ( $ delivery_tag , $ multiple , $ this -> ack_handler ) ; }
Called when the server sends a basic . ack
249
protected function basic_nack_from_server ( $ reader ) { $ delivery_tag = $ reader -> read_longlong ( ) ; $ multiple = ( bool ) $ reader -> read_bit ( ) ; if ( ! isset ( $ this -> published_messages [ $ delivery_tag ] ) ) { throw new AMQPRuntimeException ( sprintf ( 'Server nack\'ed unknown delivery_tag "%s"' , $ delivery_tag ) ) ; } $ this -> internal_ack_handler ( $ delivery_tag , $ multiple , $ this -> nack_handler ) ; }
Called when the server sends a basic . nack
250
public function basic_nack ( $ delivery_tag , $ multiple = false , $ requeue = false ) { list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> basicNack ( $ delivery_tag , $ multiple , $ requeue ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; }
Rejects one or several received messages
251
public function basic_cancel ( $ consumer_tag , $ nowait = false , $ noreturn = false ) { list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> basicCancel ( $ consumer_tag , $ nowait ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; if ( $ nowait || $ noreturn ) { unset ( $ this -> callbacks [ $ consumer_tag ] ) ; return $ consumer_tag ; } return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'basic.cancel_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Ends a queue consumer
252
public function basic_consume ( $ queue = '' , $ consumer_tag = '' , $ no_local = false , $ no_ack = false , $ exclusive = false , $ nowait = false , $ callback = null , $ ticket = null , $ arguments = array ( ) ) { $ ticket = $ this -> getTicket ( $ ticket ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> basicConsume ( $ ticket , $ queue , $ consumer_tag , $ no_local , $ no_ack , $ exclusive , $ nowait , $ this -> protocolVersion == '0.9.1' ? $ arguments : null ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; if ( false === $ nowait ) { $ consumer_tag = $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'basic.consume_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; } $ this -> callbacks [ $ consumer_tag ] = $ callback ; return $ consumer_tag ; }
Starts a queue consumer
253
protected function basic_deliver ( $ reader , $ message ) { $ consumer_tag = $ reader -> read_shortstr ( ) ; $ delivery_tag = $ reader -> read_longlong ( ) ; $ redelivered = $ reader -> read_bit ( ) ; $ exchange = $ reader -> read_shortstr ( ) ; $ routing_key = $ reader -> read_shortstr ( ) ; $ message -> delivery_info = array ( 'channel' => $ this , 'consumer_tag' => $ consumer_tag , 'delivery_tag' => $ delivery_tag , 'redelivered' => $ redelivered , 'exchange' => $ exchange , 'routing_key' => $ routing_key ) ; if ( isset ( $ this -> callbacks [ $ consumer_tag ] ) ) { call_user_func ( $ this -> callbacks [ $ consumer_tag ] , $ message ) ; } }
Notifies the client of a consumer message
254
public function basic_get ( $ queue = '' , $ no_ack = false , $ ticket = null ) { $ ticket = $ this -> getTicket ( $ ticket ) ; list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> basicGet ( $ ticket , $ queue , $ no_ack ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'basic.get_ok' ) , $ this -> waitHelper -> get_wait ( 'basic.get_empty' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Direct access to a queue if no message was available in the queue return null
255
protected function basic_get_ok ( $ reader , $ message ) { $ delivery_tag = $ reader -> read_longlong ( ) ; $ redelivered = $ reader -> read_bit ( ) ; $ exchange = $ reader -> read_shortstr ( ) ; $ routing_key = $ reader -> read_shortstr ( ) ; $ message_count = $ reader -> read_long ( ) ; $ message -> delivery_info = array ( 'delivery_tag' => $ delivery_tag , 'redelivered' => $ redelivered , 'exchange' => $ exchange , 'routing_key' => $ routing_key , 'message_count' => $ message_count ) ; return $ message ; }
Provides client with a message
256
public function basic_publish ( $ msg , $ exchange = '' , $ routing_key = '' , $ mandatory = false , $ immediate = false , $ ticket = null ) { $ pkt = new AMQPWriter ( ) ; $ pkt -> write ( $ this -> pre_publish ( $ exchange , $ routing_key , $ mandatory , $ immediate , $ ticket ) ) ; try { $ this -> connection -> send_content ( $ this -> channel_id , 60 , 0 , mb_strlen ( $ msg -> body , 'ASCII' ) , $ msg -> serialize_properties ( ) , $ msg -> body , $ pkt ) ; } catch ( AMQPConnectionClosedException $ e ) { $ this -> do_close ( ) ; throw $ e ; } if ( $ this -> next_delivery_tag > 0 ) { $ this -> published_messages [ $ this -> next_delivery_tag ] = $ msg ; $ this -> next_delivery_tag = bcadd ( $ this -> next_delivery_tag , '1' , 0 ) ; } }
Publishes a message
257
public function basic_recover ( $ requeue = false ) { list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> basicRecover ( $ requeue ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'basic.recover_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Redelivers unacknowledged messages
258
public function basic_reject ( $ delivery_tag , $ requeue ) { list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> basicReject ( $ delivery_tag , $ requeue ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; }
Rejects an incoming message
259
protected function basic_return ( $ reader , $ message ) { $ callback = $ this -> basic_return_callback ; if ( ! is_callable ( $ callback ) ) { $ this -> debug -> debug_msg ( 'Skipping unhandled basic_return message' ) ; return null ; } $ reply_code = $ reader -> read_short ( ) ; $ reply_text = $ reader -> read_shortstr ( ) ; $ exchange = $ reader -> read_shortstr ( ) ; $ routing_key = $ reader -> read_shortstr ( ) ; call_user_func_array ( $ callback , array ( $ reply_code , $ reply_text , $ exchange , $ routing_key , $ message , ) ) ; }
Returns a failed message
260
public function tx_rollback ( ) { $ this -> send_method_frame ( array ( 90 , 30 ) ) ; return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'tx.rollback_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Rollbacks the current transaction
261
public function confirm_select ( $ nowait = false ) { list ( $ class_id , $ method_id , $ args ) = $ this -> protocolWriter -> confirmSelect ( $ nowait ) ; $ this -> send_method_frame ( array ( $ class_id , $ method_id ) , $ args ) ; if ( $ nowait ) { return null ; } $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'confirm.select_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; $ this -> next_delivery_tag = 1 ; }
Puts the channel into confirm mode Beware that only non - transactional channels may be put into confirm mode and vice versa
262
public function wait_for_pending_acks ( $ timeout = 0 ) { $ functions = array ( $ this -> waitHelper -> get_wait ( 'basic.ack' ) , $ this -> waitHelper -> get_wait ( 'basic.nack' ) , ) ; while ( count ( $ this -> published_messages ) !== 0 ) { if ( $ timeout > 0 ) { $ this -> wait ( $ functions , true , $ timeout ) ; } else { $ this -> wait ( $ functions ) ; } } }
Waits for pending acks and nacks from the server . If there are no pending acks the method returns immediately
263
public function tx_select ( ) { $ this -> send_method_frame ( array ( 90 , 10 ) ) ; return $ this -> wait ( array ( $ this -> waitHelper -> get_wait ( 'tx.select_ok' ) ) , false , $ this -> channel_rpc_timeout ) ; }
Selects standard transaction mode
264
public function set_return_listener ( $ callback ) { if ( ! is_callable ( $ callback ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Given callback "%s" should be callable. %s type was given.' , $ callback , gettype ( $ callback ) ) ) ; } $ this -> basic_return_callback = $ callback ; }
Sets callback for basic_return
265
public function set_nack_handler ( $ callback ) { if ( ! is_callable ( $ callback ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Given callback "%s" should be callable. %s type was given.' , $ callback , gettype ( $ callback ) ) ) ; } $ this -> nack_handler = $ callback ; }
Sets a handler which called for any message nack ed by the server with the AMQPMessage as first argument .
266
public function set_ack_handler ( $ callback ) { if ( ! is_callable ( $ callback ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Given callback "%s" should be callable. %s type was given.' , $ callback , gettype ( $ callback ) ) ) ; } $ this -> ack_handler = $ callback ; }
Sets a handler which called for any message ack ed by the server with the AMQPMessage as first argument .
267
public function start ( ) { if ( $ this -> restart ) { echo 'Restarting consumer.' . PHP_EOL ; $ this -> restart = false ; } else { echo 'Starting consumer.' . PHP_EOL ; } $ exchange = 'router' ; $ queue = 'msgs' ; $ this -> channel = $ this -> connection -> channel ( ) ; $ this -> channel -> queue_declare ( $ queue , false , true , false , false ) ; $ this -> channel -> exchange_declare ( $ exchange , AMQPExchangeType :: DIRECT , false , true , false ) ; $ this -> channel -> queue_bind ( $ queue , $ exchange ) ; $ this -> channel -> basic_consume ( $ queue , $ this -> consumerTag , false , false , false , false , [ $ this , 'messageHandler' ] , null , [ 'x-cancel-on-ha-failover' => [ 't' , true ] ] ) ; echo 'Enter wait.' . PHP_EOL ; while ( $ this -> channel -> is_consuming ( ) ) { $ this -> channel -> wait ( ) ; } echo 'Exit wait.' . PHP_EOL ; }
Start a consumer on an existing connection
268
public static function hexdump ( $ data , $ htmloutput = true , $ uppercase = false , $ return = false ) { $ hexi = '' ; $ ascii = '' ; $ dump = $ htmloutput ? '<pre>' : '' ; $ offset = 0 ; $ len = mb_strlen ( $ data , 'ASCII' ) ; $ hexFormat = $ uppercase ? 'X' : 'x' ; for ( $ i = $ j = 0 ; $ i < $ len ; $ i ++ ) { $ hexi .= sprintf ( '%02' . $ hexFormat . ' ' , ord ( $ data [ $ i ] ) ) ; if ( ord ( $ data [ $ i ] ) >= 32 ) { $ ascii .= $ htmloutput ? htmlentities ( $ data [ $ i ] ) : $ data [ $ i ] ; } else { $ ascii .= '.' ; } if ( $ j === 7 ) { $ hexi .= ' ' ; $ ascii .= ' ' ; } if ( ++ $ j === 16 || $ i === $ len - 1 ) { $ dump .= sprintf ( '%04' . $ hexFormat . ' %-49s %s' , $ offset , $ hexi , $ ascii ) ; $ hexi = $ ascii = '' ; $ offset += 16 ; $ j = 0 ; if ( $ i !== $ len - 1 ) { $ dump .= PHP_EOL ; } } } $ dump .= $ htmloutput ? '</pre>' : '' ; $ dump .= PHP_EOL ; if ( $ return ) { return $ dump ; } echo $ dump ; }
View any string as a hexdump .
269
protected function getApiDocument ( User $ actor , array $ params ) { $ response = $ this -> api -> send ( 'Flarum\Api\Controller\ShowDiscussionController' , $ actor , $ params ) ; $ statusCode = $ response -> getStatusCode ( ) ; if ( $ statusCode === 404 ) { throw new RouteNotFoundException ; } return json_decode ( $ response -> getBody ( ) ) ; }
Get the result of an API request to show a discussion .
270
public function url ( $ path = null ) { $ config = $ this -> make ( 'flarum.config' ) ; $ url = array_get ( $ config , 'url' , array_get ( $ _SERVER , 'REQUEST_URI' ) ) ; if ( is_array ( $ url ) ) { if ( isset ( $ url [ $ path ] ) ) { return $ url [ $ path ] ; } $ url = $ url [ 'base' ] ; } if ( $ path ) { $ url .= '/' . array_get ( $ config , "paths.$path" , $ path ) ; } return $ url ; }
Get the URL to the Flarum installation .
271
public function registerNotificationTypes ( ) { $ blueprints = [ DiscussionRenamedBlueprint :: class => [ 'alert' ] ] ; $ this -> app -> make ( 'events' ) -> fire ( new ConfigureNotificationTypes ( $ blueprints ) ) ; foreach ( $ blueprints as $ blueprint => $ enabled ) { Notification :: setSubjectModel ( $ type = $ blueprint :: getType ( ) , $ blueprint :: getSubjectModel ( ) ) ; User :: addPreference ( User :: getNotificationPreferenceKey ( $ type , 'alert' ) , 'boolval' , in_array ( 'alert' , $ enabled ) ) ; if ( ( new ReflectionClass ( $ blueprint ) ) -> implementsInterface ( MailableInterface :: class ) ) { User :: addPreference ( User :: getNotificationPreferenceKey ( $ type , 'email' ) , 'boolval' , in_array ( 'email' , $ enabled ) ) ; } } }
Register notification types .
272
protected function getFilenameForRevision ( string $ revision ) : string { $ ext = pathinfo ( $ this -> filename , PATHINFO_EXTENSION ) ; return substr_replace ( $ this -> filename , '-' . $ revision , - strlen ( $ ext ) - 1 , 0 ) ; }
Get the filename for the given revision .
273
public function findByUser ( User $ user , $ limit = null , $ offset = 0 ) { $ primaries = Notification :: select ( app ( 'flarum.db' ) -> raw ( 'MAX(id) AS id' ) , app ( 'flarum.db' ) -> raw ( 'SUM(read_at IS NULL) AS unread_count' ) ) -> where ( 'user_id' , $ user -> id ) -> whereIn ( 'type' , $ user -> getAlertableNotificationTypes ( ) ) -> where ( 'is_deleted' , false ) -> whereSubjectVisibleTo ( $ user ) -> groupBy ( 'type' , 'subject_id' ) -> orderByRaw ( 'MAX(created_at) DESC' ) -> skip ( $ offset ) -> take ( $ limit ) ; return Notification :: select ( 'notifications.*' , app ( 'flarum.db' ) -> raw ( 'p.unread_count' ) ) -> mergeBindings ( $ primaries -> getQuery ( ) ) -> join ( app ( 'flarum.db' ) -> raw ( '(' . $ primaries -> toSql ( ) . ') p' ) , 'notifications.id' , '=' , app ( 'flarum.db' ) -> raw ( 'p.id' ) ) -> latest ( ) -> get ( ) ; }
Find a user s notifications .
274
public function markAllAsRead ( User $ user ) { Notification :: where ( 'user_id' , $ user -> id ) -> update ( [ 'read_at' => Carbon :: now ( ) ] ) ; }
Mark all of a user s notifications as read .
275
public static function generate ( $ userId , $ lifetime = 3600 ) { $ token = new static ; $ token -> token = str_random ( 40 ) ; $ token -> user_id = $ userId ; $ token -> created_at = Carbon :: now ( ) ; $ token -> last_activity_at = Carbon :: now ( ) ; $ token -> lifetime_seconds = $ lifetime ; return $ token ; }
Generate an access token for the specified user .
276
public function route ( $ name , $ parameters = [ ] ) { $ path = $ this -> routes -> getPath ( $ name , $ parameters ) ; $ path = ltrim ( $ path , '/' ) ; return $ this -> baseUrl . '/' . $ path ; }
Generate a URL to a named route .
277
public function assertValid ( array $ attributes ) { $ validator = $ this -> makeValidator ( $ attributes ) ; if ( $ validator -> fails ( ) ) { throw new ValidationException ( $ validator ) ; } }
Throw an exception if a model is not valid .
278
protected function makeValidator ( array $ attributes ) { $ rules = array_only ( $ this -> getRules ( ) , array_keys ( $ attributes ) ) ; $ validator = $ this -> validator -> make ( $ attributes , $ rules , $ this -> getMessages ( ) ) ; $ this -> events -> dispatch ( new Validating ( $ this , $ validator ) ) ; return $ validator ; }
Make a new validator instance for this model .
279
private function getApiDocument ( User $ actor , array $ params ) { return json_decode ( $ this -> api -> send ( ListDiscussionsController :: class , $ actor , $ params ) -> getBody ( ) ) ; }
Get the result of an API request to list discussions .
280
protected function registerNotificationSerializers ( ) { $ blueprints = [ ] ; $ serializers = [ 'discussionRenamed' => BasicDiscussionSerializer :: class ] ; $ this -> app -> make ( 'events' ) -> fire ( new ConfigureNotificationTypes ( $ blueprints , $ serializers ) ) ; foreach ( $ serializers as $ type => $ serializer ) { NotificationSerializer :: setSubjectSerializer ( $ type , $ serializer ) ; } }
Register notification serializers .
281
protected function populateRoutes ( RouteCollection $ routes ) { $ factory = $ this -> app -> make ( RouteHandlerFactory :: class ) ; $ callback = include __DIR__ . '/routes.php' ; $ callback ( $ routes , $ factory ) ; $ this -> app -> make ( 'events' ) -> fire ( new ConfigureApiRoutes ( $ routes , $ factory ) ) ; }
Populate the API routes .
282
public function rename ( $ username ) { if ( $ username !== $ this -> username ) { $ oldUsername = $ this -> username ; $ this -> username = $ username ; $ this -> raise ( new Renamed ( $ this , $ oldUsername ) ) ; } return $ this ; }
Rename the user .
283
public function changeEmail ( $ email ) { if ( $ email !== $ this -> email ) { $ this -> email = $ email ; $ this -> raise ( new EmailChanged ( $ this ) ) ; } return $ this ; }
Change the user s email .
284
public function requestEmailChange ( $ email ) { if ( $ email !== $ this -> email ) { $ this -> raise ( new EmailChangeRequested ( $ this , $ email ) ) ; } return $ this ; }
Request that the user s email be changed .
285
public function changeAvatarPath ( $ path ) { $ this -> avatar_url = $ path ; $ this -> raise ( new AvatarChanged ( $ this ) ) ; return $ this ; }
Change the path of the user avatar .
286
public function getAvatarUrlAttribute ( string $ value = null ) { if ( $ value && strpos ( $ value , '://' ) === false ) { return app ( UrlGenerator :: class ) -> to ( 'forum' ) -> path ( 'assets/avatars/' . $ value ) ; } return $ value ; }
Get the URL of the user s avatar .
287
public function checkPassword ( $ password ) { $ valid = static :: $ dispatcher -> until ( new CheckingPassword ( $ this , $ password ) ) ; if ( $ valid !== null ) { return $ valid ; } return static :: $ hasher -> check ( $ password , $ this -> password ) ; }
Check if a given password matches the user s password .
288
public function activate ( ) { if ( $ this -> is_email_confirmed !== true ) { $ this -> is_email_confirmed = true ; $ this -> raise ( new Activated ( $ this ) ) ; } return $ this ; }
Activate the user s account .
289
public function hasPermission ( $ permission ) { if ( $ this -> isAdmin ( ) ) { return true ; } if ( is_null ( $ this -> permissions ) ) { $ this -> permissions = $ this -> getPermissions ( ) ; } return in_array ( $ permission , $ this -> permissions ) ; }
Check whether the user has a certain permission based on their groups .
290
public function hasPermissionLike ( $ match ) { if ( $ this -> isAdmin ( ) ) { return true ; } if ( is_null ( $ this -> permissions ) ) { $ this -> permissions = $ this -> getPermissions ( ) ; } foreach ( $ this -> permissions as $ permission ) { if ( substr ( $ permission , - strlen ( $ match ) ) === $ match ) { return true ; } } return false ; }
Check whether the user has a permission that is like the given string based on their groups .
291
protected function getUnreadNotifications ( ) { static $ cached = null ; if ( is_null ( $ cached ) ) { $ cached = $ this -> notifications ( ) -> whereIn ( 'type' , $ this -> getAlertableNotificationTypes ( ) ) -> whereNull ( 'read_at' ) -> where ( 'is_deleted' , false ) -> whereSubjectVisibleTo ( $ this ) -> get ( ) ; } return $ cached ; }
Get all notifications that have not been read yet .
292
public function getNewNotificationCount ( ) { return $ this -> getUnreadNotifications ( ) -> filter ( function ( $ notification ) { return $ notification -> created_at > $ this -> read_notifications_at ? : 0 ; } ) -> count ( ) ; }
Get the number of new unseen notifications for the user .
293
public function getPreferencesAttribute ( $ value ) { $ defaults = array_map ( function ( $ value ) { return $ value [ 'default' ] ; } , static :: $ preferences ) ; $ user = array_only ( ( array ) json_decode ( $ value , true ) , array_keys ( static :: $ preferences ) ) ; return array_merge ( $ defaults , $ user ) ; }
Get the values of all registered preferences for this user by transforming their stored preferences and merging them with the defaults .
294
public function setPreference ( $ key , $ value ) { if ( isset ( static :: $ preferences [ $ key ] ) ) { $ preferences = $ this -> preferences ; if ( ! is_null ( $ transformer = static :: $ preferences [ $ key ] [ 'transformer' ] ) ) { $ preferences [ $ key ] = call_user_func ( $ transformer , $ value ) ; } else { $ preferences [ $ key ] = $ value ; } $ this -> preferences = $ preferences ; } return $ this ; }
Set the value of a preference for this user .
295
public function permissions ( ) { $ groupIds = [ Group :: GUEST_ID ] ; if ( $ this -> is_email_confirmed ) { $ groupIds = array_merge ( $ groupIds , [ Group :: MEMBER_ID ] , $ this -> groups -> pluck ( 'id' ) -> all ( ) ) ; } event ( new PrepareUserGroups ( $ this , $ groupIds ) ) ; return Permission :: whereIn ( 'group_id' , $ groupIds ) ; }
Define the relationship with the permissions of all of the groups that the user is in .
296
public function make ( $ name , $ value = null , $ maxAge = null ) { $ cookie = SetCookie :: create ( $ this -> getName ( $ name ) , $ value ) ; if ( $ maxAge ) { $ cookie = $ cookie -> withMaxAge ( $ maxAge ) -> withExpires ( time ( ) + $ maxAge ) ; } if ( $ this -> domain != null ) { $ cookie = $ cookie -> withDomain ( $ this -> domain ) ; } return $ cookie -> withPath ( $ this -> path ) -> withSecure ( $ this -> secure ) -> withHttpOnly ( true ) ; }
Make a new cookie instance .
297
public function getIdForUsername ( $ username , User $ actor = null ) { $ query = User :: where ( 'username' , 'like' , $ username ) ; return $ this -> scopeVisibleTo ( $ query , $ actor ) -> value ( 'id' ) ; }
Get the ID of a user with the given username .
298
public function getIdsForUsername ( $ string , User $ actor = null ) { $ string = $ this -> escapeLikeString ( $ string ) ; $ query = User :: where ( 'username' , 'like' , '%' . $ string . '%' ) -> orderByRaw ( 'username = ? desc' , [ $ string ] ) -> orderByRaw ( 'username like ? desc' , [ $ string . '%' ] ) ; return $ this -> scopeVisibleTo ( $ query , $ actor ) -> pluck ( 'id' ) -> all ( ) ; }
Find users by matching a string of words against their username optionally making sure they are visible to a certain user .
299
public function rename ( $ nameSingular , $ namePlural ) { $ this -> name_singular = $ nameSingular ; $ this -> name_plural = $ namePlural ; $ this -> raise ( new Renamed ( $ this ) ) ; return $ this ; }
Rename the group .