idx int64 0 241k | question stringlengths 64 6.21k | target stringlengths 5 803 |
|---|---|---|
800 | public function item ( $ item , $ transformer , $ parameters = [ ] , Closure $ after = null ) { $ class = get_class ( $ item ) ; if ( $ parameters instanceof \ Closure ) { $ after = $ parameters ; $ parameters = [ ] ; } $ binding = $ this -> transformer -> register ( $ class , $ transformer , $ parameters , $ after ) ;... | Bind an item to a transformer and start building a response . |
801 | public function resolveTransformer ( ) { if ( is_string ( $ this -> resolver ) ) { return $ this -> container -> make ( $ this -> resolver ) ; } elseif ( is_callable ( $ this -> resolver ) ) { return call_user_func ( $ this -> resolver , $ this -> container ) ; } elseif ( is_object ( $ this -> resolver ) ) { return $ t... | Resolve a transformer binding instance . |
802 | protected function addLookups ( Route $ route ) { $ action = $ route -> getAction ( ) ; if ( isset ( $ action [ 'as' ] ) ) { $ this -> names [ $ action [ 'as' ] ] = $ route ; } if ( isset ( $ action [ 'controller' ] ) ) { $ this -> actions [ $ action [ 'controller' ] ] = $ route ; } } | Add route lookups . |
803 | public function getByName ( $ name ) { return isset ( $ this -> names [ $ name ] ) ? $ this -> names [ $ name ] : null ; } | Get a route by name . |
804 | public function getByAction ( $ action ) { return isset ( $ this -> actions [ $ action ] ) ? $ this -> actions [ $ action ] : null ; } | Get a route by action . |
805 | protected function routeRateLimit ( $ route ) { list ( $ limit , $ expires ) = [ $ route -> getRateLimit ( ) , $ route -> getRateLimitExpiration ( ) ] ; if ( $ limit && $ expires ) { return sprintf ( '%s req/s' , round ( $ limit / ( $ expires * 60 ) , 2 ) ) ; } } | Display the routes rate limiting requests per second . This takes the limit and divides it by the expiration time in seconds to give you a rough idea of how many requests you d be able to fire off per second on the route . |
806 | protected function filterByVersions ( array $ route ) { foreach ( $ this -> option ( 'versions' ) as $ version ) { if ( Str :: contains ( $ route [ 'versions' ] , $ version ) ) { return true ; } } return false ; } | Filter the route by its versions . |
807 | protected function filterByScopes ( array $ route ) { foreach ( $ this -> option ( 'scopes' ) as $ scope ) { if ( Str :: contains ( $ route [ 'scopes' ] , $ scope ) ) { return true ; } } return false ; } | Filter the route by its scopes . |
808 | public function register ( $ class , $ resolver , array $ parameters = [ ] , Closure $ after = null ) { return $ this -> bindings [ $ class ] = $ this -> createBinding ( $ resolver , $ parameters , $ after ) ; } | Register a transformer binding resolver for a class . |
809 | public function transform ( $ response ) { $ binding = $ this -> getBinding ( $ response ) ; return $ this -> adapter -> transform ( $ response , $ binding -> resolveTransformer ( ) , $ binding , $ this -> getRequest ( ) ) ; } | Transform a response . |
810 | protected function getBinding ( $ class ) { if ( $ this -> isCollection ( $ class ) && ! $ class -> isEmpty ( ) ) { return $ this -> getBindingFromCollection ( $ class ) ; } $ class = is_object ( $ class ) ? get_class ( $ class ) : $ class ; if ( ! $ this -> hasBinding ( $ class ) ) { throw new RuntimeException ( 'Unab... | Get a registered transformer binding . |
811 | protected function createBinding ( $ resolver , array $ parameters = [ ] , Closure $ callback = null ) { return new Binding ( $ this -> container , $ resolver , $ parameters , $ callback ) ; } | Create a new binding instance . |
812 | protected function hasBinding ( $ class ) { if ( $ this -> isCollection ( $ class ) && ! $ class -> isEmpty ( ) ) { $ class = $ class -> first ( ) ; } $ class = is_object ( $ class ) ? get_class ( $ class ) : $ class ; return isset ( $ this -> bindings [ $ class ] ) ; } | Determine if a class has a transformer binding . |
813 | public function getRequest ( ) { $ request = $ this -> container [ 'request' ] ; if ( $ request instanceof IlluminateRequest && ! $ request instanceof Request ) { $ request = ( new Request ( ) ) -> createFromIlluminate ( $ request ) ; } return $ request ; } | Get the request from the container . |
814 | protected function normalizeRequestUri ( Request $ request ) { $ query = $ request -> server -> get ( 'QUERY_STRING' ) ; $ uri = '/' . trim ( str_replace ( '?' . $ query , '' , $ request -> server -> get ( 'REQUEST_URI' ) ) , '/' ) . ( $ query ? '?' . $ query : '' ) ; $ request -> server -> set ( 'REQUEST_URI' , $ uri ... | Normalize the request URI so that Lumen can properly dispatch it . |
815 | protected function breakUriSegments ( $ uri ) { if ( ! Str :: contains ( $ uri , '?}' ) ) { return ( array ) $ uri ; } $ segments = preg_split ( '/\/(\{.*?\})/' , preg_replace ( '/\{(.*?)\?\}/' , '{$1}' , $ uri ) , - 1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ) ; $ uris = [ ] ; while ( $ segments ) { $ uris [ ]... | Break a URI that has optional segments into individual URIs . |
816 | protected function removeMiddlewareFromApp ( ) { if ( $ this -> middlewareRemoved ) { return ; } $ this -> middlewareRemoved = true ; $ reflection = new ReflectionClass ( $ this -> app ) ; $ property = $ reflection -> getProperty ( 'middleware' ) ; $ property -> setAccessible ( true ) ; $ oldMiddlewares = $ property ->... | Remove the global application middleware as it s run from this packages Request middleware . Lumen runs middleware later in its life cycle which results in some middleware being executed twice . |
817 | public function getIterableRoutes ( $ version = null ) { $ iterable = [ ] ; foreach ( $ this -> getRoutes ( $ version ) as $ version => $ collector ) { $ routeData = $ collector -> getData ( ) ; foreach ( $ this -> normalizeStaticRoutes ( $ routeData [ 0 ] ) as $ method => $ routes ) { if ( $ method === 'HEAD' ) { cont... | Get routes in an iterable form . |
818 | public function terminate ( $ request , $ response ) { if ( ! ( $ request = $ this -> app [ 'request' ] ) instanceof HttpRequest ) { return ; } $ middlewares = $ this -> gatherRouteMiddlewares ( $ request ) ; if ( class_exists ( Application :: class , false ) ) { $ middlewares = array_merge ( $ middlewares , $ this -> ... | Call the terminate method on middlewares . |
819 | protected function setupRouteProperties ( Request $ request , $ route ) { list ( $ this -> uri , $ this -> methods , $ this -> action ) = $ this -> adapter -> getRouteProperties ( $ route , $ request ) ; $ this -> versions = Arr :: pull ( $ this -> action , 'version' ) ; $ this -> conditionalRequest = Arr :: pull ( $ t... | Setup the route properties . |
820 | protected function mergeControllerProperties ( ) { if ( isset ( $ this -> action [ 'uses' ] ) && is_string ( $ this -> action [ 'uses' ] ) && Str :: contains ( $ this -> action [ 'uses' ] , '@' ) ) { $ this -> action [ 'controller' ] = $ this -> action [ 'uses' ] ; $ this -> makeControllerInstance ( ) ; } if ( ! $ this... | Merge the controller properties onto the route properties . |
821 | protected function findControllerPropertyOptions ( $ name ) { $ properties = [ ] ; foreach ( $ this -> getControllerInstance ( ) -> { 'get' . ucfirst ( $ name ) } ( ) as $ property ) { if ( isset ( $ property [ 'options' ] ) && ! $ this -> optionsApplyToControllerMethod ( $ property [ 'options' ] ) ) { continue ; } uns... | Find the controller options and whether or not it will apply to this routes controller method . |
822 | protected function optionsApplyToControllerMethod ( array $ options ) { if ( empty ( $ options ) ) { return true ; } elseif ( isset ( $ options [ 'only' ] ) && in_array ( $ this -> controllerMethod , $ this -> explodeOnPipes ( $ options [ 'only' ] ) ) ) { return true ; } elseif ( isset ( $ options [ 'except' ] ) ) { re... | Determine if a controller method is in an array of options . |
823 | protected function controllerUsesHelpersTrait ( ) { if ( ! $ controller = $ this -> getControllerInstance ( ) ) { return false ; } $ traits = [ ] ; do { $ traits = array_merge ( class_uses ( $ controller , false ) , $ traits ) ; } while ( $ controller = get_parent_class ( $ controller ) ) ; foreach ( $ traits as $ trai... | Determine if the controller instance uses the helpers trait . |
824 | protected function makeControllerInstance ( ) { list ( $ this -> controllerClass , $ this -> controllerMethod ) = explode ( '@' , $ this -> action [ 'uses' ] ) ; $ this -> container -> instance ( $ this -> controllerClass , $ this -> controller = $ this -> container -> make ( $ this -> controllerClass ) ) ; return $ th... | Make a new controller instance through the container . |
825 | public function isProtected ( ) { if ( isset ( $ this -> middleware [ 'api.auth' ] ) || in_array ( 'api.auth' , $ this -> middleware ) ) { if ( $ this -> controller && isset ( $ this -> middleware [ 'api.auth' ] ) ) { return $ this -> optionsApplyToControllerMethod ( $ this -> middleware [ 'api.auth' ] ) ; } return tru... | Determine if the route is protected . |
826 | protected function getToken ( Request $ request ) { try { $ this -> validateAuthorizationHeader ( $ request ) ; $ token = $ this -> parseAuthorizationHeader ( $ request ) ; } catch ( Exception $ exception ) { if ( ! $ token = $ request -> query ( 'token' , false ) ) { throw $ exception ; } } return $ token ; } | Get the JWT from the request . |
827 | protected function isCustomIndentStyleRequired ( ) { return $ this -> isJsonPrettyPrintEnabled ( ) && isset ( $ this -> options [ 'indent_style' ] ) && in_array ( $ this -> options [ 'indent_style' ] , $ this -> indentStyles ) ; } | Determine if JSON custom indent style is set . |
828 | protected function performJsonEncoding ( $ content , array $ jsonEncodeOptions = [ ] ) { $ jsonEncodeOptions = $ this -> filterJsonEncodeOptions ( $ jsonEncodeOptions ) ; $ optionsBitmask = $ this -> calucateJsonEncodeOptionsBitmask ( $ jsonEncodeOptions ) ; if ( ( $ encodedString = json_encode ( $ content , $ optionsB... | Perform JSON encode . |
829 | protected function indentPrettyPrintedJson ( $ jsonString , $ indentStyle , $ defaultIndentSize = 2 ) { $ indentChar = $ this -> getIndentCharForIndentStyle ( $ indentStyle ) ; $ indentSize = $ this -> getPrettyPrintIndentSize ( ) ? : $ defaultIndentSize ; if ( $ this -> hasVariousIndentSize ( $ indentStyle ) ) { retur... | Indent pretty printed JSON string using given indent style . |
830 | protected function peformIndentation ( $ jsonString , $ indentChar = "\t" , $ indentSize = 1 , $ defaultSpaces = 4 ) { $ pattern = '/(^|\G) {' . $ defaultSpaces . '}/m' ; $ replacement = str_repeat ( $ indentChar , $ indentSize ) . '$1' ; return preg_replace ( $ pattern , $ replacement , $ jsonString ) ; } | Perform indentation for pretty printed JSON string with a given indent char repeated N times as determined by indent size . |
831 | protected function config ( $ item , $ instantiate = true ) { $ value = $ this -> app [ 'config' ] -> get ( 'api.' . $ item ) ; if ( is_array ( $ value ) ) { return $ instantiate ? $ this -> instantiateConfigValues ( $ item , $ value ) : $ value ; } return $ instantiate ? $ this -> instantiateConfigValue ( $ item , $ v... | Retrieve and instantiate a config value if it exists and is a class . |
832 | protected function instantiateConfigValues ( $ item , array $ values ) { foreach ( $ values as $ key => $ value ) { $ values [ $ key ] = $ this -> instantiateConfigValue ( $ item , $ value ) ; } return $ values ; } | Instantiate an array of instantiable configuration values . |
833 | public function validate ( Request $ request ) { try { $ this -> accept -> parse ( $ request , $ this -> strict ) ; } catch ( BadRequestHttpException $ exception ) { if ( $ request -> getMethod ( ) === 'OPTIONS' ) { return true ; } throw $ exception ; } } | Validate the accept header on the request . If this fails it will throw an HTTP exception that will be caught by the middleware . This validator should always be run last and must not return a success boolean . |
834 | protected function updateRouterBindings ( ) { foreach ( $ this -> getRouterBindings ( ) as $ key => $ binding ) { $ this -> app [ 'api.router.adapter' ] -> getRouter ( ) -> bind ( $ key , $ binding ) ; } } | Grab the bindings from the Laravel router and set them on the adapters router . |
835 | public function version ( $ version , $ second , $ third = null ) { if ( func_num_args ( ) == 2 ) { list ( $ version , $ callback , $ attributes ) = array_merge ( func_get_args ( ) , [ [ ] ] ) ; } else { list ( $ version , $ attributes , $ callback ) = func_get_args ( ) ; } $ attributes = array_merge ( $ attributes , [... | An alias for calling the group method allows a more fluent API for registering a new API version group with optional attributes and a required callback . |
836 | public function resource ( $ name , $ controller , array $ options = [ ] ) { if ( $ this -> container -> bound ( ResourceRegistrar :: class ) ) { $ registrar = $ this -> container -> make ( ResourceRegistrar :: class ) ; } else { $ registrar = new ResourceRegistrar ( $ this ) ; } $ registrar -> register ( $ name , $ co... | Register a resource controller . |
837 | protected function mergeLastGroupAttributes ( array $ attributes ) { if ( empty ( $ this -> groupStack ) ) { return $ this -> mergeGroup ( $ attributes , [ ] ) ; } return $ this -> mergeGroup ( $ attributes , end ( $ this -> groupStack ) ) ; } | Merge the last groups attributes . |
838 | public function dispatch ( Request $ request ) { $ this -> currentRoute = null ; $ this -> container -> instance ( Request :: class , $ request ) ; $ this -> routesDispatched ++ ; try { $ response = $ this -> adapter -> dispatch ( $ request , $ request -> version ( ) ) ; } catch ( Exception $ exception ) { if ( $ reque... | Dispatch a request via the adapter . |
839 | public function createRoute ( $ route ) { return new Route ( $ this -> adapter , $ this -> container , $ this -> container [ 'request' ] , $ route ) ; } | Create a new route instance from an adapter route . |
840 | public function getRoutes ( $ version = null ) { $ routes = $ this -> adapter -> getIterableRoutes ( $ version ) ; if ( ! is_null ( $ version ) ) { $ routes = [ $ version => $ routes ] ; } $ collections = [ ] ; foreach ( $ routes as $ key => $ value ) { $ collections [ $ key ] = new RouteCollection ( $ this -> containe... | Get all routes registered on the adapter . |
841 | public function setAdapterRoutes ( array $ routes ) { $ this -> adapter -> setRoutes ( $ routes ) ; $ this -> container -> instance ( 'api.routes' , $ this -> getRoutes ( ) ) ; } | Set the raw adapter routes . |
842 | protected function filterProviders ( array $ providers ) { if ( empty ( $ providers ) ) { return $ this -> providers ; } return array_intersect_key ( $ this -> providers , array_flip ( $ providers ) ) ; } | Filter the requested providers from the available providers . |
843 | public function extend ( $ key , $ provider ) { if ( is_callable ( $ provider ) ) { $ provider = call_user_func ( $ provider , $ this -> container ) ; } $ this -> providers [ $ key ] = $ provider ; } | Extend the authentication layer with a custom provider . |
844 | public function handle ( $ request , Closure $ next ) { if ( $ request instanceof InternalRequest ) { return $ next ( $ request ) ; } $ route = $ this -> router -> getCurrentRoute ( ) ; if ( $ route -> hasThrottle ( ) ) { $ this -> handler -> setThrottle ( $ route -> getThrottle ( ) ) ; } $ this -> handler -> rateLimit... | Perform rate limiting before a request is executed . |
845 | protected function responseWithHeaders ( $ response ) { foreach ( $ this -> getHeaders ( ) as $ key => $ value ) { $ response -> headers -> set ( $ key , $ value ) ; } return $ response ; } | Send the response with the rate limit headers . |
846 | protected function getHeaders ( ) { return [ 'X-RateLimit-Limit' => $ this -> handler -> getThrottleLimit ( ) , 'X-RateLimit-Remaining' => $ this -> handler -> getRemainingLimit ( ) , 'X-RateLimit-Reset' => $ this -> handler -> getRateLimitReset ( ) , ] ; } | Get the headers for the response . |
847 | protected function getDocName ( ) { $ name = $ this -> option ( 'name' ) ? : $ this -> name ; if ( ! $ name ) { $ this -> comment ( 'A name for the documentation was not supplied. Use the --name option or set a default in the configuration.' ) ; exit ; } return $ name ; } | Get the documentation name . |
848 | protected function getVersion ( ) { $ version = $ this -> option ( 'use-version' ) ? : $ this -> version ; if ( ! $ version ) { $ this -> comment ( 'A version for the documentation was not supplied. Use the --use-version option or set a default in the configuration.' ) ; exit ; } return $ version ; } | Get the documentation version . |
849 | protected function getControllers ( ) { $ controllers = new Collection ; if ( $ controller = $ this -> option ( 'use-controller' ) ) { $ this -> addControllerIfNotExists ( $ controllers , app ( $ controller ) ) ; return $ controllers ; } foreach ( $ this -> router -> getRoutes ( ) as $ collections ) { foreach ( $ colle... | Get all the controller instances . |
850 | protected function addControllerIfNotExists ( Collection $ controllers , $ controller ) { $ class = get_class ( $ controller ) ; if ( $ controllers -> has ( $ class ) ) { return ; } $ reflection = new ReflectionClass ( $ controller ) ; $ interface = Arr :: first ( $ reflection -> getInterfaces ( ) , function ( $ key , ... | Add a controller to the collection if it does not exist . If the controller implements an interface suffixed with Docs it will be used instead of the controller . |
851 | public function attach ( array $ files ) { foreach ( $ files as $ key => $ file ) { if ( is_array ( $ file ) ) { $ file = new UploadedFile ( $ file [ 'path' ] , basename ( $ file [ 'path' ] ) , $ file [ 'mime' ] , $ file [ 'size' ] ) ; } elseif ( is_string ( $ file ) ) { $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ ... | Attach files to be uploaded . |
852 | public function json ( $ content ) { if ( is_array ( $ content ) ) { $ content = json_encode ( $ content ) ; } $ this -> content = $ content ; return $ this -> header ( 'Content-Type' , 'application/json' ) ; } | Send a JSON payload in the request body . |
853 | public function with ( $ parameters ) { $ this -> parameters = array_merge ( $ this -> parameters , is_array ( $ parameters ) ? $ parameters : func_get_args ( ) ) ; return $ this ; } | Set the parameters to be sent on the next API request . |
854 | protected function queueRequest ( $ verb , $ uri , $ parameters , $ content = '' ) { if ( ! empty ( $ content ) ) { $ this -> content = $ content ; } if ( end ( $ this -> requestStack ) != $ this -> container [ 'request' ] ) { $ this -> requestStack [ ] = $ this -> container [ 'request' ] ; } $ this -> requestStack [ ]... | Queue up and dispatch a new request . |
855 | protected function dispatch ( InternalRequest $ request ) { $ this -> routeStack [ ] = $ this -> router -> getCurrentRoute ( ) ; $ this -> clearCachedFacadeInstance ( ) ; try { $ this -> container -> instance ( 'request' , $ request ) ; $ response = $ this -> router -> dispatch ( $ request ) ; if ( ! $ response -> isSu... | Attempt to dispatch an internal request . |
856 | public function formatEloquentModel ( $ model ) { $ key = Str :: singular ( $ model -> getTable ( ) ) ; if ( ! $ model :: $ snakeAttributes ) { $ key = Str :: camel ( $ key ) ; } return $ this -> encode ( [ $ key => $ model -> toArray ( ) ] ) ; } | Format an Eloquent model . |
857 | public function formatEloquentCollection ( $ collection ) { if ( $ collection -> isEmpty ( ) ) { return $ this -> encode ( [ ] ) ; } $ model = $ collection -> first ( ) ; $ key = Str :: plural ( $ model -> getTable ( ) ) ; if ( ! $ model :: $ snakeAttributes ) { $ key = Str :: camel ( $ key ) ; } return $ this -> encod... | Format an Eloquent collection . |
858 | protected function encode ( $ content ) { $ jsonEncodeOptions = [ ] ; if ( $ this -> isJsonPrettyPrintEnabled ( ) ) { $ jsonEncodeOptions [ ] = JSON_PRETTY_PRINT ; } $ encodedString = $ this -> performJsonEncoding ( $ content , $ jsonEncodeOptions ) ; if ( $ this -> isCustomIndentStyleRequired ( ) ) { $ encodedString =... | Encode the content to its JSON representation . |
859 | public function rateLimitRequest ( Request $ request , $ limit = 0 , $ expires = 0 ) { $ this -> request = $ request ; if ( $ this -> throttle instanceof Throttle ) { } elseif ( $ limit > 0 || $ expires > 0 ) { $ this -> throttle = new Route ( [ 'limit' => $ limit , 'expires' => $ expires ] ) ; $ this -> keyPrefix = sh... | Execute the rate limiting for the given request . |
860 | protected function prepareCacheStore ( ) { if ( $ this -> retrieve ( 'expires' ) != $ this -> throttle -> getExpires ( ) ) { $ this -> forget ( 'requests' ) ; $ this -> forget ( 'expires' ) ; $ this -> forget ( 'reset' ) ; } } | Prepare the cache store . |
861 | protected function cache ( $ key , $ value , $ minutes ) { $ this -> cache -> add ( $ this -> key ( $ key ) , $ value , Carbon :: now ( ) -> addMinutes ( $ minutes ) ) ; } | Cache a value under a given key for a certain amount of minutes . |
862 | public function extend ( $ throttle ) { if ( is_callable ( $ throttle ) ) { $ throttle = call_user_func ( $ throttle , $ this -> container ) ; } $ this -> throttles -> push ( $ throttle ) ; } | Extend the rate limiter by adding a new throttle . |
863 | public function loadPlugins ( ) { $ this -> checkCache ( ) ; $ this -> validatePlugins ( ) ; $ this -> countPlugins ( ) ; array_map ( static function ( ) { include_once WPMU_PLUGIN_DIR . '/' . func_get_args ( ) [ 0 ] ; } , array_keys ( self :: $ cache [ 'plugins' ] ) ) ; $ this -> pluginHooks ( ) ; } | Run some checks then autoload our plugins . |
864 | private function checkCache ( ) { $ cache = get_site_option ( 'bedrock_autoloader' ) ; if ( $ cache === false || ( isset ( $ cache [ 'plugins' ] , $ cache [ 'count' ] ) && count ( $ cache [ 'plugins' ] ) !== $ cache [ 'count' ] ) ) { $ this -> updateCache ( ) ; return ; } self :: $ cache = $ cache ; } | This sets the cache or calls for an update |
865 | private function validatePlugins ( ) { foreach ( self :: $ cache [ 'plugins' ] as $ plugin_file => $ plugin_info ) { if ( ! file_exists ( WPMU_PLUGIN_DIR . '/' . $ plugin_file ) ) { $ this -> updateCache ( ) ; break ; } } } | Check that the plugin file exists if it doesn t update the cache . |
866 | private function countPlugins ( ) { if ( isset ( self :: $ count ) ) { return self :: $ count ; } $ count = count ( glob ( WPMU_PLUGIN_DIR . '/*/' , GLOB_ONLYDIR | GLOB_NOSORT ) ) ; if ( ! isset ( self :: $ cache [ 'count' ] ) || $ count !== self :: $ cache [ 'count' ] ) { self :: $ count = $ count ; $ this -> updateCa... | Count the number of autoloaded plugins . |
867 | public static function serialize ( $ filename , $ instance , $ force = false ) { if ( $ filename == '' ) { throw new \ danog \ MadelineProto \ Exception ( 'Empty filename' ) ; } if ( $ instance -> API -> asyncInitPromise ) { return $ instance -> call ( static function ( ) use ( $ filename , $ instance , $ force ) { yie... | Serialize API class . |
868 | public function bufferReadAsync ( int $ length ) : \ Generator { return @ $ this -> decrypt -> encrypt ( yield $ this -> read_buffer -> bufferRead ( $ length ) ) ; } | Decrypts read data asynchronously . |
869 | public function setExtra ( $ extra ) { if ( isset ( $ extra [ 'secret' ] ) && strlen ( $ extra [ 'secret' ] ) > 17 ) { $ extra [ 'secret' ] = hex2bin ( $ extra [ 'secret' ] ) ; } if ( isset ( $ extra [ 'secret' ] ) && strlen ( $ extra [ 'secret' ] ) == 17 ) { $ extra [ 'secret' ] = substr ( $ extra [ 'secret' ] , 0 , 1... | Does nothing . |
870 | public function read ( ) : Promise { return $ this -> stream ? $ this -> stream -> read ( ) : new \ Amp \ Success ( null ) ; } | Async chunked read . |
871 | public function setExtra ( $ extra ) { if ( isset ( $ extra [ 'user' ] ) && isset ( $ extra [ 'password' ] ) ) { $ this -> header = \ base64_encode ( $ extra [ 'user' ] . ':' . $ extra [ 'password' ] ) . "\r\n" ; } } | Set proxy data . |
872 | private function get_headers ( $ httpType , $ cookies ) { $ headers = [ ] ; $ headers [ ] = 'Dnt: 1' ; $ headers [ ] = 'Connection: keep-alive' ; $ headers [ ] = 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4' ; $ headers [ ] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Geck... | Function for generating curl request headers . |
873 | public function setUri ( $ uri ) : self { $ this -> uri = $ uri instanceof Uri ? $ uri : new Uri ( $ uri ) ; return $ this ; } | Set the connection URI . |
874 | public function getIntDc ( ) { $ dc = intval ( $ this -> dc ) ; if ( $ this -> test ) { $ dc += 10000 ; } if ( strpos ( $ this -> dc , '_media' ) ) { $ dc = - $ dc ; } return $ dc ; } | Get the int DC ID . |
875 | public function addStream ( string $ streamName , $ extra = null ) : self { $ this -> nextStreams [ ] = [ $ streamName , $ extra ] ; $ this -> key = count ( $ this -> nextStreams ) - 1 ; return $ this ; } | Add a stream to the stream chain . |
876 | public function getStreamAsync ( string $ buffer = '' ) : \ Generator { list ( $ clazz , $ extra ) = $ this -> nextStreams [ $ this -> key -- ] ; $ obj = new $ clazz ( ) ; if ( $ obj instanceof ProxyStreamInterface ) { $ obj -> setExtra ( $ extra ) ; } yield $ obj -> connect ( $ this , $ buffer ) ; return $ obj ; } | Get a stream from the stream chain . |
877 | public function getName ( ) : string { $ string = $ this -> getStringUri ( ) ; if ( $ this -> isSecure ( ) ) { $ string .= ' (TLS)' ; } $ string .= ' DC ' ; $ string .= $ this -> getDc ( ) ; $ string .= ', via ' ; $ string .= $ this -> getIpv6 ( ) ? 'ipv6' : 'ipv4' ; $ string .= ' using ' ; foreach ( array_reverse ( $ ... | Get a description name of the context . |
878 | private function setProperties ( ) { \ danog \ MadelineProto \ Logger :: log ( 'Generating properties...' , \ danog \ MadelineProto \ Logger :: NOTICE ) ; $ fixture = DocBlockFactory :: createInstance ( ) ; $ class = new \ ReflectionClass ( APIFactory :: class ) ; $ content = file_get_contents ( $ filename = $ class ->... | Open file of class APIFactory Insert properties save the file with new content . |
879 | public function getReadHash ( ) : string { $ hash = hash_final ( $ this -> read_hash , true ) ; if ( $ this -> rev ) { $ hash = strrev ( $ hash ) ; } $ this -> read_hash = null ; $ this -> read_check_after = 0 ; $ this -> read_check_pos = 0 ; return $ hash ; } | Stop read hashing and get final hash . |
880 | public function getWriteHash ( ) : string { $ hash = hash_final ( $ this -> write_hash , true ) ; if ( $ this -> rev ) { $ hash = strrev ( $ hash ) ; } $ this -> write_hash = null ; $ this -> write_check_after = 0 ; $ this -> write_check_pos = 0 ; return $ hash ; } | Stop write hashing and get final hash . |
881 | public function bufferReadAsync ( int $ length ) : \ Generator { if ( $ this -> read_check_after && $ length + $ this -> read_check_pos >= $ this -> read_check_after ) { if ( $ length + $ this -> read_check_pos > $ this -> read_check_after ) { throw new \ danog \ MadelineProto \ Exception ( 'Tried to read too much out ... | Hashes read data asynchronously . |
882 | public function setExtra ( $ hash ) { $ rev = strpos ( $ hash , '_rev' ) ; $ this -> rev = false ; if ( $ rev !== false ) { $ hash = substr ( $ hash , 0 , $ rev ) ; $ this -> rev = true ; } $ this -> hash_name = $ hash ; } | Set the hash algorithm . |
883 | public function connect ( ConnectionContext $ ctx , string $ header = '' ) : Promise { $ this -> in_seq_no = - 1 ; $ this -> out_seq_no = - 1 ; $ this -> stream = new HashedBufferedStream ( ) ; $ this -> stream -> setExtra ( 'crc32b_rev' ) ; return $ this -> stream -> connect ( $ ctx , $ header ) ; } | Stream to use as data source . |
884 | public function bufferWrite ( string $ data ) : Promise { if ( $ this -> append_after ) { $ this -> append_after -= strlen ( $ data ) ; if ( $ this -> append_after === 0 ) { $ data .= $ this -> append ; $ this -> append = '' ; } elseif ( $ this -> append_after < 0 ) { $ this -> append_after = 0 ; $ this -> append = '' ... | Async write . |
885 | public function connectAsync ( ConnectionContext $ ctx ) : \ Generator { $ this -> API -> logger -> logger ( "Trying connection via $ctx" , \ danog \ MadelineProto \ Logger :: WARNING ) ; $ this -> ctx = $ ctx -> getCtx ( ) ; $ this -> datacenter = $ ctx -> getDc ( ) ; $ this -> stream = yield $ ctx -> getStream ( ) ; ... | Connect function . |
886 | public function fetchParametersAsync ( ) : \ Generator { $ refetchable = $ this -> isRefetchable ( ) ; if ( $ this -> fetched && ! $ refetchable ) { return $ this -> params ; } $ params = yield call ( [ $ this , 'getParameters' ] ) ; if ( ! $ refetchable ) { $ this -> params = $ params ; } return $ params ; } | Fetch parameters asynchronously . |
887 | public function connect_to_all_dcs_async ( ) : \ Generator { $ this -> datacenter -> __construct ( $ this , $ this -> settings [ 'connection' ] , $ this -> settings [ 'connection_settings' ] ) ; $ dcs = [ ] ; foreach ( $ this -> datacenter -> get_dcs ( ) as $ new_dc ) { $ dcs [ ] = $ this -> datacenter -> dc_connect_as... | Connects to all datacenters and if necessary creates authorization keys binds them and writes client info |
888 | public function repeat ( $ question = '' ) { $ conversation = $ this -> bot -> getStoredConversation ( ) ; if ( ! $ question instanceof Question && ! $ question ) { $ question = unserialize ( $ conversation [ 'question' ] ) ; } $ next = $ conversation [ 'next' ] ; $ additionalParameters = unserialize ( $ conversation [... | Repeat the previously asked question . |
889 | public static function loadFromName ( $ name , array $ config , Request $ request = null ) { if ( class_exists ( $ name ) && is_subclass_of ( $ name , DriverInterface :: class ) ) { $ name = preg_replace ( '#(Driver$)#' , '' , basename ( str_replace ( '\\' , '/' , $ name ) ) ) ; } if ( class_exists ( $ name ) && is_sub... | Load a driver by using its name . |
890 | public static function loadDriver ( $ driver , $ explicit = false ) { array_unshift ( self :: $ drivers , $ driver ) ; if ( method_exists ( $ driver , 'loadExtension' ) ) { call_user_func ( [ $ driver , 'loadExtension' ] ) ; } if ( method_exists ( $ driver , 'additionalDrivers' ) && $ explicit === false ) { $ additiona... | Append a driver to the list of loadable drivers . |
891 | public static function unloadDriver ( $ driver ) { foreach ( array_keys ( self :: $ drivers , $ driver ) as $ key ) { unset ( self :: $ drivers [ $ key ] ) ; } } | Remove a driver from the list of loadable drivers . |
892 | public static function verifyServices ( array $ config , Request $ request = null ) { $ request = ( isset ( $ request ) ) ? $ request : Request :: createFromGlobals ( ) ; foreach ( self :: getAvailableHttpDrivers ( ) as $ driver ) { $ driver = new $ driver ( $ request , $ config , new Curl ( ) ) ; if ( $ driver instanc... | Verify service webhook URLs . |
893 | protected function getResponse ( IncomingMessage $ message ) { $ response = $ this -> http -> post ( $ this -> apiUrl , [ ] , [ 'query' => [ $ message -> getText ( ) ] , 'sessionId' => md5 ( $ message -> getConversationIdentifier ( ) ) , 'lang' => $ this -> lang , ] , [ 'Authorization: Bearer ' . $ this -> token , 'Con... | Perform the API . ai API call and cache it for the message . |
894 | public static function createForSocket ( array $ config , LoopInterface $ loop , CacheInterface $ cache = null , StorageInterface $ storageDriver = null ) { $ port = isset ( $ config [ 'port' ] ) ? $ config [ 'port' ] : 8080 ; $ socket = new Server ( $ loop ) ; if ( empty ( $ cache ) ) { $ cache = new ArrayCache ( ) ; ... | Create a new BotMan instance that listens on a socket . |
895 | public static function passRequestToSocket ( $ port = 8080 , Request $ request = null ) { if ( empty ( $ request ) ) { $ request = Request :: createFromGlobals ( ) ; } $ client = stream_socket_client ( 'tcp://127.0.0.1:' . $ port ) ; fwrite ( $ client , json_encode ( [ 'attributes' => $ request -> attributes -> all ( )... | Pass an incoming HTTP request to the socket . |
896 | public function getBotMessages ( ) { return Collection :: make ( $ this -> getDriver ( ) -> getMessages ( ) ) -> filter ( function ( IncomingMessage $ message ) { return $ message -> isFromBot ( ) ; } ) -> toArray ( ) ; } | Retrieve the chat message that are sent from bots . |
897 | public function on ( $ names , $ callback ) { if ( ! is_array ( $ names ) ) { $ names = [ $ names ] ; } $ callable = $ this -> getCallable ( $ callback ) ; foreach ( $ names as $ name ) { $ this -> events [ ] = [ 'name' => $ name , 'callback' => $ callable , ] ; } } | Listen for messaging service events . |
898 | public function group ( array $ attributes , Closure $ callback ) { $ previousGroupAttributes = $ this -> groupAttributes ; $ this -> groupAttributes = array_merge_recursive ( $ previousGroupAttributes , $ attributes ) ; \ call_user_func ( $ callback , $ this ) ; $ this -> groupAttributes = $ previousGroupAttributes ; ... | Create a command group with shared attributes . |
899 | protected function fireDriverEvents ( ) { $ driverEvent = $ this -> getDriver ( ) -> hasMatchingEvent ( ) ; if ( $ driverEvent instanceof DriverEventInterface ) { $ this -> firedDriverEvents = true ; Collection :: make ( $ this -> events ) -> filter ( function ( $ event ) use ( $ driverEvent ) { return $ driverEvent ->... | Fire potential driver event callbacks . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.