idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
48,200
|
public function setMethods ( array $ methods ) { foreach ( $ this -> methods as $ method ) { $ method -> setParent ( null ) ; } $ this -> methods -> clear ( ) ; foreach ( $ methods as $ method ) { $ this -> setMethod ( $ method ) ; } return $ this ; }
|
Sets a collection of methods
|
48,201
|
public function setMethod ( PhpMethod $ method ) { $ method -> setParent ( $ this ) ; $ this -> methods -> set ( $ method -> getName ( ) , $ method ) ; return $ this ; }
|
Adds a method
|
48,202
|
public function removeMethod ( $ nameOrMethod ) { if ( $ nameOrMethod instanceof PhpMethod ) { $ nameOrMethod = $ nameOrMethod -> getName ( ) ; } if ( ! $ this -> methods -> has ( $ nameOrMethod ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The method "%s" does not exist.' , $ nameOrMethod ) ) ; } $ m = $ this -> methods -> get ( $ nameOrMethod ) ; $ m -> setParent ( null ) ; $ this -> methods -> remove ( $ nameOrMethod ) ; return $ this ; }
|
Removes a method
|
48,203
|
public function hasMethod ( $ nameOrMethod ) : bool { if ( $ nameOrMethod instanceof PhpMethod ) { $ nameOrMethod = $ nameOrMethod -> getName ( ) ; } return $ this -> methods -> has ( $ nameOrMethod ) ; }
|
Checks whether a method exists or not
|
48,204
|
public function getMethod ( $ nameOrMethod ) : PhpMethod { if ( $ nameOrMethod instanceof PhpMethod ) { $ nameOrMethod = $ nameOrMethod -> getName ( ) ; } if ( ! $ this -> methods -> has ( $ nameOrMethod ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The method "%s" does not exist.' , $ nameOrMethod ) ) ; } return $ this -> methods -> get ( $ nameOrMethod ) ; }
|
Returns a method
|
48,205
|
public function clearMethods ( ) { foreach ( $ this -> methods as $ method ) { $ method -> setParent ( null ) ; } $ this -> methods -> clear ( ) ; return $ this ; }
|
Clears all methods
|
48,206
|
public function generateDocblock ( ) { $ docblock = $ this -> getDocblock ( ) ; $ docblock -> setShortDescription ( $ this -> getDescription ( ) ) ; $ docblock -> setLongDescription ( $ this -> getLongDescription ( ) ) ; foreach ( $ this -> methods as $ method ) { $ method -> generateDocblock ( ) ; } return $ this ; }
|
Generates a docblock from provided information
|
48,207
|
public function addInterface ( $ interface ) { if ( $ interface instanceof PhpInterface ) { $ name = $ interface -> getName ( ) ; $ qname = $ interface -> getQualifiedName ( ) ; $ namespace = $ interface -> getNamespace ( ) ; if ( $ namespace != $ this -> getNamespace ( ) ) { $ this -> addUseStatement ( $ qname ) ; } } else { $ name = $ interface ; } $ this -> interfaces -> add ( $ name ) ; return $ this ; }
|
Adds an interface .
|
48,208
|
public function hasInterface ( $ interface ) : bool { if ( $ interface instanceof PhpInterface ) { return $ this -> interfaces -> contains ( $ interface -> getName ( ) ) || $ this -> interfaces -> contains ( $ interface -> getQualifiedName ( ) ) ; } return $ this -> interfaces -> contains ( $ interface ) || $ this -> hasInterface ( new PhpInterface ( $ interface ) ) ; }
|
Checks whether an interface exists
|
48,209
|
public function removeInterface ( $ interface ) { if ( $ interface instanceof PhpInterface ) { $ name = $ interface -> getName ( ) ; $ qname = $ interface -> getQualifiedName ( ) ; $ this -> removeUseStatement ( $ qname ) ; } else { $ name = $ interface ; } $ this -> interfaces -> remove ( $ name ) ; return $ this ; }
|
Removes an interface .
|
48,210
|
public static function fromFile ( string $ filename ) : PhpClass { $ class = new PhpClass ( ) ; $ parser = new FileParser ( $ filename ) ; $ parser -> addVisitor ( new ClassParserVisitor ( $ class ) ) ; $ parser -> addVisitor ( new MethodParserVisitor ( $ class ) ) ; $ parser -> addVisitor ( new ConstantParserVisitor ( $ class ) ) ; $ parser -> addVisitor ( new PropertyParserVisitor ( $ class ) ) ; $ parser -> parse ( ) ; return $ class ; }
|
Creates a PHP class from file
|
48,211
|
public static function fromFile ( string $ filename ) : PhpInterface { $ interface = new PhpInterface ( ) ; $ parser = new FileParser ( $ filename ) ; $ parser -> addVisitor ( new InterfaceParserVisitor ( $ interface ) ) ; $ parser -> addVisitor ( new MethodParserVisitor ( $ interface ) ) ; $ parser -> addVisitor ( new ConstantParserVisitor ( $ interface ) ) ; $ parser -> parse ( ) ; return $ interface ; }
|
Creates a PHP interface from file
|
48,212
|
public function removeConstant ( $ nameOrConstant ) { if ( $ nameOrConstant instanceof PhpConstant ) { $ nameOrConstant = $ nameOrConstant -> getName ( ) ; } if ( ! $ this -> constants -> has ( $ nameOrConstant ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The constant "%s" does not exist.' , $ nameOrConstant ) ) ; } $ this -> constants -> remove ( $ nameOrConstant ) ; return $ this ; }
|
Removes a constant
|
48,213
|
public function hasConstant ( $ nameOrConstant ) : bool { if ( $ nameOrConstant instanceof PhpConstant ) { $ nameOrConstant = $ nameOrConstant -> getName ( ) ; } return $ this -> constants -> has ( $ nameOrConstant ) ; }
|
Checks whether a constant exists
|
48,214
|
public static function create ( Randomizer $ randomizer = null ) { return new self ( [ new Alliteration ( $ randomizer ) , new Vgng ( $ randomizer ) ] , $ randomizer ) ; }
|
Constructs an All Generator using the default list of generators .
|
48,215
|
protected function _getRandomGenerator ( ) { return $ this -> _randomizer ? $ this -> _randomizer -> getArrayValue ( $ this -> _generators ) : $ this -> _generators [ array_rand ( $ this -> _generators ) ] ; }
|
Get a random generator from the list of generators .
|
48,216
|
public function getName ( ) { $ adjective = $ this -> _getRandomWord ( $ this -> _adjectives ) ; $ noun = $ this -> _getRandomWord ( $ this -> _nouns , $ adjective [ 0 ] ) ; return ucwords ( "{$adjective} {$noun}" ) ; }
|
Gets a randomly generated alliterative name .
|
48,217
|
protected function _getRandomWord ( array $ words , $ startingLetter = null ) { $ wordsToSearch = $ startingLetter === null ? $ words : preg_grep ( "/^{$startingLetter}/" , $ words ) ; return $ this -> _randomizer ? $ this -> _randomizer -> getArrayValue ( $ wordsToSearch ) : $ wordsToSearch [ array_rand ( $ wordsToSearch ) ] ; }
|
Get a random word from the list of words optionally filtering by starting letter .
|
48,218
|
public function getName ( ) { $ similarWords = [ ] ; $ words = [ ] ; foreach ( $ this -> _definitionSets as $ definitionSet ) { $ word = $ this -> _getUniqueWord ( $ definitionSet , $ similarWords ) ; $ words [ ] = $ word [ 'word' ] ; $ similarWords [ ] = $ word [ 'word' ] ; $ similarWords = array_merge ( $ similarWords , $ word [ 'similarWords' ] ) ; } return implode ( ' ' , $ words ) ; }
|
Gets a randomly generated video game name .
|
48,219
|
protected function _getUniqueWord ( array $ definitions , array $ existingWords ) { $ definition = $ this -> _randomizer ? $ this -> _randomizer -> getArrayValue ( $ definitions ) : $ definitions [ array_rand ( $ definitions ) ] ; if ( array_search ( $ definition [ 'word' ] , $ existingWords ) === false ) { return $ definition ; } return $ this -> _getUniqueWord ( $ definitions , $ existingWords ) ; }
|
Get a definition from the definitions that does not exist already .
|
48,220
|
protected function _parseDefinition ( $ definition ) { $ word = strtok ( $ definition , '^' ) ; $ similarWords = array_filter ( explode ( '|' , strtok ( '^' ) ) ) ; return [ 'word' => $ word , 'similarWords' => $ similarWords ] ; }
|
Parses a single definition into its component pieces .
|
48,221
|
public function all ( ) { $ default = $ this -> data ( $ this -> getLocale ( ) ) ; $ fallback = $ this -> data ( $ this -> getFallbackLocale ( ) ) ; return $ default + $ fallback ; }
|
Get all localized records .
|
48,222
|
protected function data ( $ locale ) { if ( ! isset ( $ this -> data [ $ locale ] ) ) { $ path = base_path ( 'vendor/umpirsky/country-list/data/' . $ locale . '/country.php' ) ; $ this -> data [ $ locale ] = is_file ( $ path ) ? require $ path : [ ] ; } return $ this -> data [ $ locale ] ; }
|
Get the data for the given locale .
|
48,223
|
protected function registerCountry ( ) { $ this -> app -> singleton ( Country :: class , function ( $ app ) { $ repository = new Country ; return $ repository -> setLocale ( $ app [ 'config' ] [ 'app.locale' ] ) -> setFallbackLocale ( $ app [ 'config' ] [ 'app.fallback_locale' ] ) ; } ) ; $ this -> app -> alias ( Country :: class , 'intl.country' ) ; }
|
Register the country repository .
|
48,224
|
protected function registerCurrency ( ) { $ this -> app -> singleton ( Currency :: class , function ( $ app ) { $ repository = new Currency ; return $ repository -> setLocale ( $ app [ 'config' ] [ 'app.locale' ] ) -> setFallbackLocale ( $ app [ 'config' ] [ 'app.fallback_locale' ] ) ; } ) ; $ this -> app -> alias ( Currency :: class , 'intl.currency' ) ; }
|
Register the currency repository .
|
48,225
|
protected function registerLanguage ( ) { $ this -> app -> singleton ( Language :: class , function ( $ app ) { $ repository = new Language ; return $ repository -> setLocale ( $ app [ 'config' ] [ 'app.locale' ] ) -> setFallbackLocale ( $ app [ 'config' ] [ 'app.fallback_locale' ] ) ; } ) ; $ this -> app -> alias ( Language :: class , 'intl.language' ) ; }
|
Register the language repository .
|
48,226
|
protected function registerNumber ( ) { $ this -> app -> singleton ( Number :: class , function ( $ app ) { $ repository = new Number ; return $ repository -> setLocale ( $ app [ 'config' ] [ 'app.locale' ] ) -> setFallbackLocale ( $ app [ 'config' ] [ 'app.fallback_locale' ] ) ; } ) ; $ this -> app -> alias ( Number :: class , 'intl.number' ) ; }
|
Register the number repository .
|
48,227
|
protected function setLocale ( ) { $ locale = $ this -> app [ 'config' ] [ 'app.locale' ] ; $ fallbackLocale = $ this -> app [ 'config' ] [ 'app.fallback_locale' ] ; Punic :: setDefaultLocale ( $ locale ) ; Punic :: setFallbackLocale ( $ fallbackLocale ) ; }
|
Set locales on sub - libraries .
|
48,228
|
public function usingLocale ( $ locale , callable $ callback , $ fallbackLocale = null ) { $ originalLocale = $ this -> getLocale ( ) ; $ originalFallbackLocale = $ this -> getFallbackLocale ( ) ; $ this -> setLocale ( $ locale ) ; $ this -> setFallbackLocale ( $ fallbackLocale ? : $ originalFallbackLocale ) ; $ result = $ callback ( $ this ) ; $ this -> setFallbackLocale ( $ originalFallbackLocale ) ; $ this -> setLocale ( $ originalLocale ) ; return $ result ; }
|
Run the given callable while using another locale .
|
48,229
|
public function parse ( $ number , $ options = [ ] ) { return $ this -> formatter ( ) -> parse ( $ number , $ this -> mergeOptions ( $ options ) ) ; }
|
Parse a localized number into native PHP format .
|
48,230
|
protected function data ( ) { $ key = $ this -> getLocalesKey ( $ locale = $ this -> getLocale ( ) , $ fallbackLocale = $ this -> getFallbackLocale ( ) ) ; if ( ! isset ( $ this -> data [ $ key ] ) ) { $ this -> data [ $ key ] = new CurrencyRepository ( $ locale , $ fallbackLocale ) ; } return $ this -> data [ $ key ] ; }
|
The currency repository .
|
48,231
|
protected function filter ( $ result , $ choices ) { foreach ( $ choices as $ key => $ regex ) { if ( $ result -> is ( $ key ) and stripos ( $ key , 'generic' ) === false ) { return $ key ; } } return null ; }
|
Filter through the choices to find the matching one .
|
48,232
|
protected function parseVersion ( $ version , $ prefix ) { $ response = [ ] ; if ( preg_match ( '%(?<major>\d+)((\.(?<minor>\d+)((\.(?<patch>\d+))|$))|$)%' , $ version , $ match ) ) { $ pieces = [ ] ; foreach ( $ match as $ key => $ value ) { if ( $ key === 'major' || $ key === 'minor' || $ key === 'patch' ) { $ pieces [ ] = $ response [ $ prefix . 'Version' . ucfirst ( $ key ) ] = ( int ) $ value ; } } if ( ! empty ( $ pieces ) ) { $ response [ $ prefix . 'Version' ] = implode ( '.' , $ pieces ) ; } } return $ response ; }
|
Parse semantic version strings into major . minor . patch pieces .
|
48,233
|
protected function process ( $ agent ) { $ pipeline = new Pipeline ( [ new Stages \ UAParser , new Stages \ MobileDetect , new Stages \ CrawlerDetect , new Stages \ DeviceDetector , new Stages \ BrowserDetect , ] ) ; return $ pipeline -> process ( new Payload ( $ agent ) ) ; }
|
Pipe the payload through the stages .
|
48,234
|
protected function registerDirectives ( ) { if ( version_compare ( $ this -> app -> version ( ) , '5.5' , '>=' ) ) { $ blade = Blade :: getFacadeRoot ( ) ; $ if = 'if' ; foreach ( [ 'desktop' , 'tablet' , 'mobile' ] as $ key ) { $ blade -> $ if ( $ key , function ( ) use ( $ key ) { $ fn = 'is' . $ key ; return app ( ) -> make ( 'browser-detect' ) -> detect ( ) -> $ fn ( ) ; } ) ; } $ blade -> $ if ( 'browser' , function ( $ fn ) { return app ( ) -> make ( 'browser-detect' ) -> detect ( ) -> $ fn ( ) ; } ) ; } }
|
Register the blade directives .
|
48,235
|
protected function appendAllResponse ( ResponseInterface $ response ) : ResponseInterface { if ( $ this -> append ) { $ this -> cors -> setResponse ( 'psr-7' , $ response ) ; $ this -> cors -> handle ( ) ; return $ this -> cors -> getResponse ( ) ; } return $ response ; }
|
Append all response .
|
48,236
|
public function boot ( ) { $ this -> publishes ( [ __DIR__ . '/../../../config/laravel.php' => config_path ( 'cors.php' ) ] ) ; $ kernel = $ this -> app -> make ( Kernel :: class ) ; if ( ! $ kernel -> hasMiddleware ( CorsMiddleware :: class ) ) { $ kernel -> prependMiddleware ( CorsMiddleware :: class ) ; } }
|
Bootstrap the CORS service provider .
|
48,237
|
public function process ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { if ( $ this -> cors -> onlyPreflight ( ) ) { if ( $ this -> cors -> isPreflightRequest ( 'psr-7' , $ request ) ) { if ( ! ( ( $ response = $ this -> getResponse ( ) ) instanceof ResponseInterface ) ) { $ response = $ handler -> handle ( $ request ) ; } return $ this -> handle ( $ request , $ response ) -> withStatus ( 204 ) ; } return $ handler -> handle ( $ request ) ; } return $ this -> handle ( $ request , $ handler -> handle ( $ request ) ) ; }
|
The middleware handler .
|
48,238
|
protected function handle ( ServerRequestInterface $ request , ResponseInterface $ response ) : ResponseInterface { $ cors = $ this -> cors -> getCors ( ) ; $ cors -> setRequest ( 'psr-7' , $ request ) ; $ cors -> setResponse ( 'psr-7' , $ response ) ; $ cors -> handle ( ) ; return $ cors -> getResponse ( ) ; }
|
The cors handle .
|
48,239
|
public function handle ( ) { if ( in_array ( false , array_values ( $ this -> initialized ) ) ) { throw new CorsInitException ( 'Not set "request" or "response"' ) ; } $ this -> response -> setAccessControlAllowCredentials ( $ this -> getCredentials ( ) ) ; $ this -> response -> setAccessControlAllowOrigin ( $ this -> getOrigin ( ) ) ; $ this -> response -> setAccessControlAllowMethods ( $ this -> getMethods ( ) ) ; $ this -> response -> setAccessControlAllowHeaders ( $ this -> getAllowheaders ( ) ) ; $ this -> response -> setAccessControlExposeHeaders ( $ this -> getExposeHeaders ( ) ) ; $ this -> response -> setAccessControlMaxAge ( $ this -> getMaxAge ( ) ) ; $ this -> response -> setAddedStatus ( true ) ; }
|
Run the CORS handle .
|
48,240
|
public function getOrigin ( ) : string { $ requestOrigin = $ this -> request -> getOrigin ( ) ; $ hasWildcard = in_array ( '*' , $ this -> origins ) ; if ( $ hasWildcard && ! $ requestOrigin ) { return '*' ; } if ( in_array ( $ requestOrigin , $ this -> origins ) || $ hasWildcard ) { return $ requestOrigin ; } return '' ; }
|
Get allowed origin .
|
48,241
|
public function getMethods ( ) { $ requestMethod = $ this -> request -> getAccessControlRequestMethod ( ) ; if ( in_array ( '*' , $ this -> methods ) && $ requestMethod ) { return $ requestMethod ; } return $ this -> methods ; }
|
Get allowed methods .
|
48,242
|
public function getAllowheaders ( ) { $ requestHeaders = $ this -> request -> getAccessControlRequestHeaders ( ) ; if ( in_array ( '*' , $ this -> allowedHeaders ) && $ requestHeaders ) { return $ requestHeaders ; } return $ this -> allowedHeaders ; }
|
Get allow - headers .
|
48,243
|
public function setRequest ( string $ type , $ request ) { $ this -> request = new Request ( $ type , $ request ) ; $ this -> initialized [ 'request' ] = true ; return $ this ; }
|
Set a request .
|
48,244
|
public function setResponse ( string $ type , $ response ) { $ this -> response = new Response ( $ type , $ response ) ; $ this -> initialized [ 'response' ] = true ; return $ this ; }
|
Set a response .
|
48,245
|
public function isCorsRequest ( string $ type , $ request ) : bool { $ origin = ( new Request ( $ type , $ request ) ) -> getOrigin ( ) ; switch ( strtolower ( $ type ) ) { case 'psr-7' : $ scheme = $ request -> getUri ( ) -> getScheme ( ) ; $ httpHost = $ scheme . '://' . $ request -> getUri ( ) -> getHost ( ) ; $ port = $ request -> getUri ( ) -> getPort ( ) ; if ( ( 'http' == $ scheme && 80 == $ port ) || ( 'https' == $ scheme && 443 == $ port ) ) { $ isSameHost = $ origin === $ httpHost ; break ; } $ isSameHost = $ origin === ( $ httpHost . ':' . $ port ) ; break ; case 'laravel' : case 'symfony' : $ isSameHost = $ origin === $ request -> getSchemeAndHttpHost ( ) ; break ; default : $ isSameHost = false ; break ; } return $ origin && ! $ isSameHost ; }
|
The request is CORE request .
|
48,246
|
public function isPreflightRequest ( string $ type , $ request ) : bool { $ requestManager = new Request ( $ type , $ request ) ; switch ( strtolower ( $ type ) ) { case 'psr-7' : case 'laravel' : case 'symfony' : $ method = $ request -> getMethod ( ) ; break ; default : $ method = strtolower ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; if ( $ method === 'post' ) { if ( $ _method = $ requestManager -> getHeader ( 'X-HTTP-METHOD-OVERRIDE' ) ) { $ method = $ _method ; } } break ; } return $ this -> isCorsRequest ( $ type , $ request ) && 'options' === strtolower ( $ method ) && $ requestManager -> getHeader ( 'Access-Control-Request-Method' ) ; }
|
The request is perflight request .
|
48,247
|
public function getCors ( ) : CorsInterface { if ( static :: $ cors instanceof CorsInterface ) { return static :: $ cors ; } return $ this -> setCors ( $ this -> createCors ( ) ) -> getCors ( ) ; }
|
Get the cors instance .
|
48,248
|
public function getConfigure ( string $ key = '' , $ value = null ) { return App :: getAppProperties ( ) -> get ( $ key ? sprintf ( 'cors.%s' , $ key ) : 'cors' , $ value ) ; }
|
Get the cors configures .
|
48,249
|
public function getHeader ( string $ name , string $ default = '' ) : string { switch ( $ this -> type ) { case 'psr-7' : return $ this -> request -> getHeaderLine ( $ name ) ? : $ default ; case 'laravel' : case 'symfony' : return $ this -> request -> headers -> get ( $ name , $ default ) ; case 'thinkphp' : return $ this -> request -> header ( $ name , $ default ) ; } foreach ( $ this -> request as $ key => $ value ) { if ( strtolower ( $ key ) === strtolower ( $ name ) ) { return ( string ) $ value ; } } return $ default ; }
|
Get header line .
|
48,250
|
public function handle ( $ request , Closure $ next ) { $ type = 'laravel' ; if ( $ this -> cors -> isPreflightRequest ( $ type , $ request ) ) { $ this -> cors -> setRequest ( $ type , $ request ) ; $ this -> cors -> setResponse ( $ type , $ response = new Response ( ) ) ; $ this -> cors -> handle ( ) ; $ response -> setStatusCode ( 204 ) ; return $ response ; } return $ next ( $ request ) ; }
|
The CORS middleware handle .
|
48,251
|
public function process ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { $ response = $ handler -> handle ( $ request ) ; if ( $ this -> onlyPreflight ) { if ( $ this -> cors -> isPreflightRequest ( 'psr-7' , $ request ) ) { return $ this -> handle ( $ request , $ response ) -> withStatus ( 204 ) ; } return $ response ; } return $ this -> handle ( $ request , $ response ) ; }
|
The middleware process .
|
48,252
|
public function handle ( ServerRequestInterface $ request , ResponseInterface $ response ) : ResponseInterface { $ type = 'psr-7' ; $ this -> cors -> setRequest ( $ type , $ request ) ; $ this -> cors -> setResponse ( $ type , $ response ) ; $ this -> cors -> handle ( ) ; return $ this -> cors -> getResponse ( ) ; }
|
Process cors headers .
|
48,253
|
protected function resoveCors ( $ payload ) : CorsInterface { if ( $ payload instanceof CorsInterface ) { return $ payload ; } elseif ( ! is_array ( $ payload ) ) { $ payload = [ ] ; } return new Cors ( static :: parseSettings ( $ payload ) ) ; }
|
Resolve cors instance .
|
48,254
|
public function register ( ) { $ this -> mergeConfigFrom ( __DIR__ . '/../../config/lumen.php' , 'cors' ) ; $ this -> app -> alias ( CorsInterface :: class , Cors :: class ) ; $ this -> app -> singleton ( CorsInterface :: class , function ( $ app ) { $ config = $ app [ 'config' ] -> get ( 'cors' ) ; return new Cors ( $ config ) ; } ) ; }
|
Run the service provider register handle .
|
48,255
|
protected function resolveSettings ( array $ settings = [ ] ) { $ defaultSettings = [ 'allow-credentiails' => false , 'allow-headers' => [ ] , 'expose-headers' => [ ] , 'origins' => [ ] , 'methods' => [ ] , 'max-age' => 0 , ] ; $ this -> config -> set ( [ 'cors' => array_merge ( $ defaultSettings , $ this -> config -> pull ( 'cors' ) ) , ] ) ; }
|
Parse settings .
|
48,256
|
public function setHeader ( string $ name , string $ value ) { switch ( $ this -> type ) { case 'psr-7' : $ this -> response = $ this -> response -> withHeader ( $ name , $ value ) ; break ; case 'laravel' : case 'symfony' : $ this -> response -> headers -> set ( $ name , $ value ) ; break ; case 'thinkphp' : $ this -> response -> header ( $ name , $ value ) ; break ; default : $ this -> response [ $ name ] = $ value ; break ; } return $ this ; }
|
Setting response headers .
|
48,257
|
public function setAccessControlAllowMethods ( $ methods ) { if ( is_array ( $ methods ) ) { $ methods = implode ( ', ' , $ methods ) ; } $ this -> setHeader ( 'Access-Control-Allow-Methods' , ( string ) $ methods ) ; return $ this ; }
|
Set Access - Control - Allow - Methods header line .
|
48,258
|
public function setAccessControlAllowHeaders ( $ headers ) { if ( is_array ( $ headers ) ) { $ headers = implode ( ', ' , $ headers ) ; } $ this -> setHeader ( 'Access-Control-Allow-Headers' , ( string ) $ headers ) ; return $ this ; }
|
Set Access - Control - Allow - Headers header line .
|
48,259
|
public function setAccessControlExposeHeaders ( $ headers ) { if ( is_array ( $ headers ) ) { $ headers = implode ( ', ' , $ headers ) ; } if ( ! empty ( $ headers ) ) { $ this -> setHeader ( 'Access-Control-Expose-Headers' , ( string ) $ headers ) ; } return $ this ; }
|
Set Access - Control - Expose - Headers header line .
|
48,260
|
protected function hasShouldRouteGroup ( $ request ) : bool { if ( ! config ( 'cors.laravel.route-group-mode' ) ) { return true ; } $ shouldClsssName = ShouldGroup :: class ; $ shouldAlias = collect ( Route :: getMiddleware ( ) ) -> flip ( ) -> get ( $ shouldClsssName , $ shouldClsssName ) ; $ route = collect ( Route :: getRoutes ( ) -> get ( ) ) -> first ( function ( $ route ) use ( $ request ) { return $ route -> matches ( $ request , false ) ; } ) ; if ( ! $ route ) { return false ; } $ gatherMiddleware = $ route -> gatherMiddleware ( ) ; if ( in_array ( $ shouldClsssName , $ gatherMiddleware ) || in_array ( $ shouldAlias , $ gatherMiddleware ) ) { return true ; } $ middlewareGroups = collect ( Route :: getMiddlewareGroups ( ) ) -> filter ( function ( $ group ) use ( $ shouldClsssName , $ shouldAlias ) { return in_array ( $ shouldAlias , $ group ) || in_array ( $ shouldClsssName , $ group ) ; } ) -> keys ( ) ; return $ middlewareGroups -> filter ( function ( $ value ) use ( $ gatherMiddleware ) { return in_array ( $ value , $ gatherMiddleware ) ; } ) -> isNotEmpty ( ) ; }
|
Has should route group .
|
48,261
|
protected function corsHandle ( $ request , $ response ) { if ( ! $ this -> cors -> hasAdded ( ) ) { $ this -> cors -> setRequest ( 'laravel' , $ request ) ; $ this -> cors -> setResponse ( 'laravel' , $ response ) ; $ this -> cors -> handle ( ) ; } return $ this -> cors -> getResponse ( ) ; }
|
CORS serve singleton handle .
|
48,262
|
private function processBatchRequests ( $ input ) { $ replies = array ( ) ; foreach ( $ input as $ request ) { $ reply = $ this -> processRequest ( $ request ) ; if ( $ reply !== null ) { $ replies [ ] = $ reply ; } } if ( count ( $ replies ) === 0 ) { return null ; } return $ replies ; }
|
Processes a batch of user requests and prepares the response .
|
48,263
|
private function processRequest ( $ request ) { if ( ! is_array ( $ request ) ) { return self :: requestError ( ) ; } $ isQuery = array_key_exists ( 'id' , $ request ) ; $ id = & $ request [ 'id' ] ; if ( ( $ id !== null ) && ! is_int ( $ id ) && ! is_float ( $ id ) && ! is_string ( $ id ) ) { return self :: requestError ( ) ; } $ version = & $ request [ 'jsonrpc' ] ; if ( $ version !== self :: VERSION ) { return self :: requestError ( $ id ) ; } $ method = & $ request [ 'method' ] ; if ( ! is_string ( $ method ) ) { return self :: requestError ( $ id ) ; } if ( array_key_exists ( 'params' , $ request ) ) { $ arguments = $ request [ 'params' ] ; if ( ! is_array ( $ arguments ) ) { return self :: requestError ( $ id ) ; } } else { $ arguments = array ( ) ; } if ( $ isQuery ) { return $ this -> processQuery ( $ id , $ method , $ arguments ) ; } $ this -> processNotification ( $ method , $ arguments ) ; return null ; }
|
Processes an individual request and prepares the response .
|
48,264
|
private function processQuery ( $ id , $ method , $ arguments ) { try { $ result = $ this -> evaluator -> evaluate ( $ method , $ arguments ) ; return self :: response ( $ id , $ result ) ; } catch ( Exception $ exception ) { $ code = $ exception -> getCode ( ) ; $ message = $ exception -> getMessage ( ) ; $ data = $ exception -> getData ( ) ; return self :: error ( $ id , $ code , $ message , $ data ) ; } }
|
Processes a query request and prepares the response .
|
48,265
|
private function processNotification ( $ method , $ arguments ) { try { $ this -> evaluator -> evaluate ( $ method , $ arguments ) ; } catch ( Exception $ exception ) { } }
|
Processes a notification . No response is necessary .
|
48,266
|
private static function error ( $ id , $ code , $ message , $ data = null ) { $ error = array ( 'code' => $ code , 'message' => $ message ) ; if ( $ data !== null ) { $ error [ 'data' ] = $ data ; } return array ( 'jsonrpc' => self :: VERSION , 'id' => $ id , 'error' => $ error ) ; }
|
Returns a properly - formatted error object .
|
48,267
|
public function encode ( ) { $ count = count ( $ this -> messages ) ; if ( $ count === 0 ) { return null ; } if ( $ count === 1 ) { $ output = array_shift ( $ this -> messages ) ; } else { $ output = $ this -> messages ; } $ this -> messages = array ( ) ; return json_encode ( $ output ) ; }
|
Encodes the requests as a valid JSON - RPC 2 . 0 string
|
48,268
|
public function decode ( $ input ) { set_error_handler ( __CLASS__ . '::onError' ) ; $ value = json_decode ( $ input , true ) ; restore_error_handler ( ) ; if ( ( $ value === null ) && ( strtolower ( trim ( $ input ) ) !== 'null' ) ) { $ valuePhp = self :: getValuePhp ( $ input ) ; throw new ErrorException ( "Invalid JSON: {$valuePhp}" ) ; } if ( ! $ this -> getReply ( $ value , $ output ) ) { $ valuePhp = self :: getValuePhp ( $ input ) ; throw new ErrorException ( "Invalid JSON-RPC 2.0 response: {$valuePhp}" ) ; } return $ output ; }
|
Translates a JSON - RPC 2 . 0 server reply into an array of Response objects
|
48,269
|
private static function isValidData ( $ input ) { $ type = gettype ( $ input ) ; return ( $ type === 'array' ) || ( $ type === 'string' ) || ( $ type === 'double' ) || ( $ type === 'integer' ) || ( $ type === 'boolean' ) || ( $ type === 'NULL' ) ; }
|
Determines whether a value can be used as the data value in an error object .
|
48,270
|
public function jsonSerialize ( ) { $ geometries = [ ] ; foreach ( $ this -> geometries as $ geometry ) { $ geometries [ ] = $ geometry -> jsonSerialize ( ) ; } return new \ GeoJson \ Geometry \ GeometryCollection ( $ geometries ) ; }
|
Convert to GeoJson GeometryCollection that is jsonable to GeoJSON
|
48,271
|
public function geometrycollection ( $ column , $ srid = null , $ dimensions = 2 , $ typmod = true ) { return $ this -> addCommand ( 'geometrycollection' , compact ( 'column' , 'srid' , 'dimensions' , 'typmod' ) ) ; }
|
Add a geometrycollection column on the table
|
48,272
|
public function jsonSerialize ( ) { $ polygons = [ ] ; foreach ( $ this -> polygons as $ polygon ) { $ polygons [ ] = $ polygon -> jsonSerialize ( ) ; } return new \ GeoJson \ Geometry \ MultiPolygon ( $ polygons ) ; }
|
Convert to GeoJson MultiPolygon that is jsonable to GeoJSON
|
48,273
|
public function typePoint ( Fluent $ column ) { $ type = strtoupper ( $ column -> geomtype ) ; if ( $ this -> isValid ( $ column ) ) { if ( $ type == 'GEOGRAPHY' && $ column -> srid != 4326 ) { throw new UnsupportedGeomtypeException ( 'Error with validation of srid! SRID of GEOGRAPHY must be 4326)' ) ; } return $ type . '(POINT, ' . $ column -> srid . ')' ; } else { throw new UnsupportedGeomtypeException ( 'Error with validation of geom type or srid!' ) ; } }
|
Adds a statement to add a point geometry column
|
48,274
|
public function compileGeometrycollection ( Blueprint $ blueprint , Fluent $ command ) { $ command -> type = 'GEOMETRYCOLLECTION' ; return $ this -> compileGeometry ( $ blueprint , $ command ) ; }
|
Adds a statement to add a geometrycollection geometry column
|
48,275
|
protected function compileGeometry ( Blueprint $ blueprint , Fluent $ command ) { $ dimensions = $ command -> dimensions ? : 2 ; $ typmod = $ command -> typmod ? 'true' : 'false' ; $ srid = $ command -> srid ? : 4326 ; return sprintf ( "SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d, %s)" , $ blueprint -> getTable ( ) , $ command -> column , $ srid , strtoupper ( $ command -> type ) , $ dimensions , $ typmod ) ; }
|
Adds a statement to add a geometry column
|
48,276
|
public function jsonSerialize ( ) { $ points = [ ] ; foreach ( $ this -> points as $ point ) { $ points [ ] = $ point -> jsonSerialize ( ) ; } return new \ GeoJson \ Geometry \ MultiPoint ( $ points ) ; }
|
Convert to GeoJson MultiPoint that is jsonable to GeoJSON
|
48,277
|
public function jsonSerialize ( ) { $ points = [ ] ; foreach ( $ this -> points as $ point ) { $ points [ ] = $ point -> jsonSerialize ( ) ; } return new \ GeoJson \ Geometry \ LineString ( $ points ) ; }
|
Convert to GeoJson LineString that is jsonable to GeoJSON
|
48,278
|
public function jsonSerialize ( ) { $ linearrings = [ ] ; foreach ( $ this -> linestrings as $ linestring ) { $ linearrings [ ] = new \ GeoJson \ Geometry \ LinearRing ( $ linestring -> jsonSerialize ( ) -> getCoordinates ( ) ) ; } return new \ GeoJson \ Geometry \ Polygon ( $ linearrings ) ; }
|
Convert to GeoJson Polygon that is jsonable to GeoJSON
|
48,279
|
private function prepareAutoloadPaths ( string $ mergeSection , array $ packageComposerJson , SmartFileInfo $ packageFile ) : array { if ( ! in_array ( $ mergeSection , [ 'autoload' , 'autoload-dev' ] , true ) ) { return $ packageComposerJson ; } foreach ( $ this -> sectionsWithPath as $ sectionWithPath ) { if ( ! isset ( $ packageComposerJson [ $ mergeSection ] [ $ sectionWithPath ] ) ) { continue ; } $ packageComposerJson [ $ mergeSection ] [ $ sectionWithPath ] = $ this -> relativizePath ( $ packageComposerJson [ $ mergeSection ] [ $ sectionWithPath ] , $ packageFile ) ; } return $ packageComposerJson ; }
|
Class map path needs to be prefixed before merge otherwise will override one another
|
48,280
|
public function getMostRecentTag ( string $ gitDirectory ) : ? string { $ command = [ 'git' , 'tag' , '-l' , '--sort=committerdate' ] ; if ( getcwd ( ) !== $ gitDirectory ) { $ command [ ] = '--git-dir' ; $ command [ ] = $ gitDirectory ; } $ tags = $ this -> processRunner -> run ( $ command ) ; $ tagList = explode ( PHP_EOL , trim ( $ tags ) ) ; $ theMostRecentTag = array_pop ( $ tagList ) ; if ( empty ( $ theMostRecentTag ) ) { return null ; } return $ theMostRecentTag ; }
|
Returns null when there are no local tags yet
|
48,281
|
protected function fixHeaders ( array $ headers ) { $ fixedHeaders = array ( ) ; foreach ( $ headers as $ key => $ value ) { if ( is_int ( $ key ) ) { $ fixedHeaders [ ] = $ value ; } else { $ fixedHeaders [ ] = sprintf ( '%s:%s' , $ key , $ value ) ; } } return $ fixedHeaders ; }
|
Fixes the headers to match the http format .
|
48,282
|
protected function createResponse ( $ statusCode , $ url , $ headers , $ body , $ effectiveUrl = null ) { return new HttpResponse ( $ statusCode , $ url , $ this -> createHeaders ( $ headers ) , $ body , $ effectiveUrl ) ; }
|
Creates an Http response .
|
48,283
|
private function createHeaders ( $ headers ) { if ( is_string ( $ headers ) ) { return $ this -> createHeaders ( explode ( "\r\n" , $ headers ) ) ; } $ fixedHeaders = array ( ) ; foreach ( $ headers as $ key => $ header ) { if ( is_int ( $ key ) ) { if ( ( $ pos = strpos ( $ header , ':' ) ) === false ) { continue ; } $ fixedHeaders [ substr ( $ header , 0 , $ pos ) ] = substr ( $ header , $ pos + 1 ) ; } else { $ fixedHeaders [ $ key ] = $ this -> createHeader ( $ header ) ; } } return $ fixedHeaders ; }
|
Creates the headers .
|
48,284
|
private function execute ( $ url , $ context ) { if ( ( $ stream = @ fopen ( $ this -> fixUrl ( $ url ) , 'rb' , false , $ context ) ) === false ) { throw HttpAdapterException :: cannotFetchUrl ( $ url , $ this -> getName ( ) , print_r ( error_get_last ( ) , true ) ) ; } $ metadata = stream_get_meta_data ( $ stream ) ; if ( preg_match_all ( '#Location:([^,]+)#' , implode ( ',' , $ metadata [ 'wrapper_data' ] ) , $ matches ) ) { $ effectiveUrl = trim ( $ matches [ 1 ] [ count ( $ matches [ 1 ] ) - 1 ] ) ; } else { $ effectiveUrl = $ url ; } $ content = stream_get_contents ( $ stream ) ; fclose ( $ stream ) ; return $ this -> createResponse ( isset ( $ metadata [ 'wrapper_data' ] [ 0 ] ) ? $ this -> parseStatusCode ( $ metadata [ 'wrapper_data' ] [ 0 ] ) : null , $ url , $ metadata [ 'wrapper_data' ] , $ content , $ effectiveUrl ) ; }
|
Calls an URL given a context .
|
48,285
|
private function createStreamContext ( $ method , array $ headers , array $ content = array ( ) , array $ files = array ( ) ) { if ( ! empty ( $ files ) ) { throw new HttpAdapterException ( sprintf ( 'The "%s" does not support files.' , __CLASS__ ) ) ; } $ contextOptions = array ( 'http' => array ( 'method' => $ method ) ) ; if ( ! empty ( $ headers ) ) { $ contextOptions [ 'http' ] [ 'header' ] = '' ; foreach ( $ this -> fixHeaders ( $ headers ) as $ header ) { $ contextOptions [ 'http' ] [ 'header' ] .= sprintf ( "%s\r\n" , $ header ) ; } } if ( $ this -> getMaxRedirects ( ) > 0 ) { $ contextOptions [ 'http' ] [ 'follow_location' ] = 1 ; $ contextOptions [ 'http' ] [ 'max_redirects' ] = $ this -> getMaxRedirects ( ) ; } if ( $ method === 'POST' || $ method === 'PUT' ) { $ contextOptions [ 'http' ] [ 'content' ] = $ this -> fixContent ( $ content ) ; } return stream_context_create ( $ contextOptions ) ; }
|
Creates the stream context .
|
48,286
|
private function execute ( $ url , array $ headers = array ( ) , $ callable = null ) { $ curl = curl_init ( ) ; curl_setopt ( $ curl , CURLOPT_URL , $ this -> fixUrl ( $ url ) ) ; curl_setopt ( $ curl , CURLOPT_HEADER , true ) ; curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , true ) ; if ( $ this -> getMaxRedirects ( ) > 0 ) { curl_setopt ( $ curl , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ curl , CURLOPT_MAXREDIRS , $ this -> getMaxRedirects ( ) ) ; } if ( ! empty ( $ headers ) ) { curl_setopt ( $ curl , CURLOPT_HTTPHEADER , $ this -> fixHeaders ( $ headers ) ) ; } if ( $ callable !== null ) { call_user_func ( $ callable , $ curl ) ; } if ( ( $ response = curl_exec ( $ curl ) ) === false ) { $ error = curl_error ( $ curl ) ; curl_close ( $ curl ) ; throw HttpAdapterException :: cannotFetchUrl ( $ url , $ this -> getName ( ) , $ error ) ; } $ statusCode = curl_getinfo ( $ curl , CURLINFO_HTTP_CODE ) ; $ headersSize = curl_getinfo ( $ curl , CURLINFO_HEADER_SIZE ) ; $ effectiveUrl = curl_getinfo ( $ curl , CURLINFO_EFFECTIVE_URL ) ; curl_close ( $ curl ) ; $ headers = substr ( $ response , 0 , $ headersSize ) ; $ body = substr ( $ response , $ headersSize ) ; return $ this -> createResponse ( $ statusCode , $ url , $ headers , $ body , $ effectiveUrl ) ; }
|
Fetches a response from an URL .
|
48,287
|
public function offsetSet ( $ offset , $ value ) { $ this -> checkTypeWrapper ( $ value ) ; parent :: offsetSet ( $ offset , $ value ) ; }
|
Assigns a value to the specified offset + check the type .
|
48,288
|
public function where ( string $ keyOrPropertyOrMethod , $ value ) : CollectionInterface { return $ this -> filter ( function ( $ item ) use ( $ keyOrPropertyOrMethod , $ value ) { $ accessorValue = $ this -> extractValue ( $ item , $ keyOrPropertyOrMethod ) ; return $ accessorValue === $ value ; } ) ; }
|
Returns a collection of matching items .
|
48,289
|
public static function range ( int $ base , int $ stop = null , int $ step = 1 ) : Arrayy { if ( $ stop !== null ) { $ start = $ base ; } else { $ start = 1 ; $ stop = $ base ; } return Arrayy :: create ( \ range ( $ start , $ stop , $ step ) ) ; }
|
Generate an array from a range .
|
48,290
|
public function asort ( int $ sort_flags = 0 ) : self { $ this -> generatorToArray ( ) ; \ asort ( $ this -> array , $ sort_flags ) ; return $ this ; }
|
Sort the entries by value .
|
48,291
|
public function getIterator ( ) : \ Iterator { if ( $ this -> generator instanceof ArrayyRewindableGenerator ) { return $ this -> generator ; } $ iterator = $ this -> getIteratorClass ( ) ; if ( $ iterator === ArrayyIterator :: class ) { return new $ iterator ( $ this -> getArray ( ) , 0 , static :: class , false ) ; } return new $ iterator ( $ this -> getArray ( ) ) ; }
|
Returns a new iterator thus implementing the \ Iterator interface .
|
48,292
|
public function ksort ( int $ sort_flags = 0 ) : self { $ this -> generatorToArray ( ) ; \ ksort ( $ this -> array , $ sort_flags ) ; return $ this ; }
|
Sort the entries by key
|
48,293
|
public function offsetUnset ( $ offset ) { $ this -> generatorToArray ( ) ; if ( $ this -> array === [ ] ) { return ; } if ( \ array_key_exists ( $ offset , $ this -> array ) ) { unset ( $ this -> array [ $ offset ] ) ; return ; } if ( $ this -> pathSeparator && \ is_string ( $ offset ) && \ strpos ( $ offset , $ this -> pathSeparator ) !== false ) { $ path = \ explode ( $ this -> pathSeparator , ( string ) $ offset ) ; if ( $ path !== false ) { $ pathToUnset = \ array_pop ( $ path ) ; $ this -> callAtPath ( \ implode ( $ this -> pathSeparator , $ path ) , static function ( & $ offset ) use ( $ pathToUnset ) { unset ( $ offset [ $ pathToUnset ] ) ; } ) ; } } unset ( $ this -> array [ $ offset ] ) ; }
|
Unset an offset .
|
48,294
|
public function at ( \ Closure $ closure ) : self { $ arrayy = clone $ this ; foreach ( $ arrayy -> getGenerator ( ) as $ key => $ value ) { $ closure ( $ value , $ key ) ; } return static :: create ( $ arrayy -> toArray ( ) , $ this -> iteratorClass , false ) ; }
|
Iterate over the current array and execute a callback for each loop .
|
48,295
|
public function changeKeyCase ( int $ case = \ CASE_LOWER ) : self { if ( $ case !== \ CASE_LOWER && $ case !== \ CASE_UPPER ) { $ case = \ CASE_LOWER ; } $ return = [ ] ; foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { if ( $ case === \ CASE_LOWER ) { $ key = \ mb_strtolower ( ( string ) $ key ) ; } else { $ key = \ mb_strtoupper ( ( string ) $ key ) ; } $ return [ $ key ] = $ value ; } return static :: create ( $ return , $ this -> iteratorClass , false ) ; }
|
Changes all keys in an array .
|
48,296
|
public function chunk ( $ size , $ preserveKeys = false ) : self { return static :: create ( \ array_chunk ( $ this -> getArray ( ) , $ size , $ preserveKeys ) , $ this -> iteratorClass , false ) ; }
|
Create a chunked version of the current array .
|
48,297
|
public function contains ( $ value , bool $ recursive = false , bool $ strict = true ) : bool { if ( $ recursive === true ) { return $ this -> in_array_recursive ( $ value , $ this -> getArray ( ) , $ strict ) ; } foreach ( $ this -> getGenerator ( ) as $ valueFromArray ) { if ( $ strict ) { if ( $ value === $ valueFromArray ) { return true ; } } else { if ( $ value == $ valueFromArray ) { return true ; } } } return false ; }
|
Check if an item is in the current array .
|
48,298
|
public function containsValues ( array $ needles ) : bool { return \ count ( \ array_intersect ( $ needles , $ this -> getArray ( ) ) , \ COUNT_NORMAL ) === \ count ( $ needles , \ COUNT_NORMAL ) ; }
|
Check if all given needles are present in the array .
|
48,299
|
public static function create ( $ array = [ ] , string $ iteratorClass = ArrayyIterator :: class , bool $ checkForMissingPropertiesInConstructor = true ) : self { return new static ( $ array , $ iteratorClass , $ checkForMissingPropertiesInConstructor ) ; }
|
Creates an Arrayy object .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.