idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
48,500
public function getAlias ( $ alias ) { return isset ( $ this -> _aliases [ $ alias ] ) ? $ this -> _aliases [ $ alias ] : $ alias ; }
Returns the real type of a alias .
48,501
public function set ( $ class , $ definition = [ ] , array $ params = [ ] ) { $ normalizedDefinition = $ this -> normalizeDefinition ( $ class , $ definition ) ; if ( is_array ( $ normalizedDefinition ) ) { $ concrete = $ normalizedDefinition [ 'class' ] ; } else { $ concrete = $ class ; } if ( $ class !== $ concrete ) { $ this -> alias ( $ concrete , $ class ) ; } $ this -> _definitions [ $ concrete ] = $ normalizedDefinition ; $ this -> _params [ $ concrete ] = $ params ; unset ( $ this -> _singletons [ $ concrete ] ) ; return $ this ; }
Registers a class definition with this container .
48,502
public function setSingleton ( $ class , $ definition = [ ] , array $ params = [ ] ) { $ normalizedDefinition = $ this -> normalizeDefinition ( $ class , $ definition ) ; if ( is_array ( $ normalizedDefinition ) ) { $ concrete = $ normalizedDefinition [ 'class' ] ; } else { $ concrete = $ class ; } if ( $ class !== $ concrete ) { $ this -> alias ( $ concrete , $ class ) ; } $ this -> _definitions [ $ concrete ] = $ normalizedDefinition ; $ this -> _params [ $ concrete ] = $ params ; $ this -> _singletons [ $ concrete ] = null ; return $ this ; }
Registers a class definition with this container and marks the class as a singleton class .
48,503
public function hasSingleton ( $ class , $ checkInstance = false ) { $ class = $ this -> getAlias ( $ class ) ; return $ checkInstance ? isset ( $ this -> _singletons [ $ class ] ) : array_key_exists ( $ class , $ this -> _singletons ) ; }
Returns a value indicating whether the given name corresponds to a registered singleton .
48,504
public function clear ( $ class ) { $ concrete = $ this -> getAlias ( $ class ) ; unset ( $ this -> _aliases [ $ class ] ) ; unset ( $ this -> _definitions [ $ concrete ] , $ this -> _singletons [ $ concrete ] ) ; }
Removes the definition for the specified name .
48,505
protected function normalizeDefinition ( $ class , $ definition ) { if ( empty ( $ definition ) ) { return [ 'class' => $ class ] ; } elseif ( is_string ( $ definition ) ) { return [ 'class' => $ definition ] ; } elseif ( is_callable ( $ definition , true ) || is_object ( $ definition ) ) { return $ definition ; } elseif ( is_array ( $ definition ) ) { if ( ! isset ( $ definition [ 'class' ] ) ) { if ( strpos ( $ class , '\\' ) !== false ) { $ definition [ 'class' ] = $ class ; } else { throw new InvalidConfigException ( "A class definition requires a \"class\" member." ) ; } } return $ definition ; } else { throw new InvalidConfigException ( "Unsupported definition type for \"$class\": " . gettype ( $ definition ) ) ; } }
Normalizes the class definition .
48,506
public function redirect ( $ url , $ statusCode = 302 ) { if ( strpos ( $ url , '/' ) === 0 && strpos ( $ url , '//' ) !== 0 ) { $ url = request ( ) -> root ( ) . $ url ; } $ this -> status ( $ statusCode ) ; $ this -> headers -> set ( 'Location' , $ url ) ; }
Redirects to the specified url .
48,507
private function setStream ( $ stream , $ mode = 'r' ) { $ error = null ; $ resource = $ stream ; if ( is_string ( $ stream ) ) { set_error_handler ( function ( $ e ) use ( & $ error ) { $ error = $ e ; } , E_WARNING ) ; $ resource = fopen ( $ stream , $ mode ) ; restore_error_handler ( ) ; } if ( $ error ) { throw new InvalidArgumentException ( 'Invalid stream reference provided' ) ; } if ( ! is_resource ( $ resource ) || 'stream' !== get_resource_type ( $ resource ) ) { throw new InvalidArgumentException ( 'Invalid stream provided; must be a string stream identifier or stream resource' ) ; } if ( $ stream !== $ resource ) { $ this -> stream = $ stream ; } $ this -> resource = $ resource ; }
Set the internal stream resource .
48,508
public function pushHandler ( HandlerInterface $ handler ) { if ( $ handler instanceof BaseObject ) { array_unshift ( $ this -> handlers , $ handler ) ; } return $ this ; }
Hack to remove the default logger support of Monolog .
48,509
public function get ( $ name ) { if ( isset ( $ this -> files [ $ name ] ) ) { return [ $ this -> files [ $ name ] ] ; } $ results = [ ] ; foreach ( $ this -> files as $ key => $ file ) { if ( strpos ( $ key , "{$name}[" ) === 0 ) { $ results [ ] = $ file ; } } return $ results ; }
Returns files by its name .
48,510
public function first ( $ name ) { if ( isset ( $ this -> files [ $ name ] ) ) { return $ this -> files [ $ name ] ; } foreach ( $ this -> files as $ key => $ file ) { if ( strpos ( $ key , "{$name}[" ) === 0 ) { return $ file ; } } }
Returns the first file by its name .
48,511
public function setFiles ( $ files = [ ] ) { if ( ! $ files instanceof FileBag ) { $ files = new FileBag ( $ files ) ; } $ this -> _files = $ files ; }
Defines the setter for files property .
48,512
public function setCookies ( $ cookies ) { if ( ! $ cookies instanceof CookieBag ) { $ cookies = new CookieBag ( CookieBag :: normalize ( $ cookies ) ) ; } $ this -> _cookies = $ cookies ; }
Defines the setter for cookie property .
48,513
public function url ( $ withParams = true ) { if ( $ withParams ) { return ( string ) $ this -> uri ; } else { return $ this -> root ( ) . $ this -> uri -> path ; } }
Returns the url of the request .
48,514
public function getContentType ( ) { $ contentType = $ this -> headers -> first ( 'Content-Type' ) ; if ( ( $ pos = strpos ( $ contentType , ';' ) ) !== false ) { $ contentType = substr ( $ contentType , 0 , $ pos ) ; } return $ contentType ; }
Returns the Content - Type of the request without it s parameters .
48,515
public function getContentTypeParams ( ) { $ contentType = $ this -> headers -> first ( 'Content-Type' ) ; $ contentTypeParams = [ ] ; if ( $ contentType ) { $ contentTypeParts = preg_split ( '/\s*[;,]\s*/' , $ contentType ) ; $ contentTypePartsLength = count ( $ contentTypeParts ) ; for ( $ i = 1 ; $ i < $ contentTypePartsLength ; $ i ++ ) { $ paramParts = explode ( '=' , $ contentTypeParts [ $ i ] ) ; $ contentTypeParams [ strtolower ( $ paramParts [ 0 ] ) ] = $ paramParts [ 1 ] ; } } return $ contentTypeParams ; }
Returns parameters of the Content - Type header .
48,516
public function has ( $ key ) { return $ this -> params -> has ( $ key ) || $ this -> payload -> has ( $ key ) ; }
Returns whether has an input value by key .
48,517
public function input ( $ key , $ default = null ) { if ( ( $ value = $ this -> params -> get ( $ key ) ) !== null ) { return $ value ; } if ( ( $ value = $ this -> payload -> get ( $ key ) ) !== null ) { return $ value ; } return $ default ; }
Gets a input value by key .
48,518
public function getSession ( ) { if ( $ this -> _session === false ) { $ sessionId = is_callable ( $ this -> sessionKey ) ? call_user_func ( $ this -> sessionKey , $ this ) : $ this -> headers -> first ( $ this -> sessionKey ) ; if ( $ session = session ( ) -> get ( $ sessionId ) ) { $ this -> _session = $ session ; } else { $ this -> _session = null ; } } return $ this -> _session ; }
Returns the current session associated to the request .
48,519
public function user ( $ user = null ) { if ( $ user !== null ) { $ this -> _user = $ user ; return ; } if ( $ this -> _user === false ) { if ( ( $ session = $ this -> getSession ( ) ) && $ session -> id ) { $ this -> _user = auth ( ) -> who ( $ session ) ; } else { $ this -> _user = null ; } } return $ this -> _user ; }
Gets or sets the authenticated user for this request .
48,520
public function get ( $ name ) { return isset ( $ this -> cookies [ $ name ] ) ? $ this -> cookies [ $ name ] : null ; }
Returns a cookie by name .
48,521
public function bind ( $ id , $ definition = [ ] , $ replace = true ) { $ container = Container :: $ instance ; if ( ! $ replace && $ container -> has ( $ id ) ) { throw new InvalidParamException ( "Can not bind service, service '$id' is already exists." ) ; } if ( is_array ( $ definition ) && ! isset ( $ definition [ 'class' ] ) ) { throw new InvalidConfigException ( "The configuration for the \"$id\" service must contain a \"class\" element." ) ; } $ container -> setSingleton ( $ id , $ definition ) ; }
Bind a service definition to this service locator .
48,522
public function call ( $ callback , $ arguments = [ ] ) { $ dependencies = $ this -> getMethodDependencies ( $ callback , $ arguments ) ; return call_user_func_array ( $ callback , $ dependencies ) ; }
Call the given callback or class method with dependency injection .
48,523
public function middleware ( $ definition , $ prepend = false ) { if ( $ this -> freezed ) { throw new InvalidCallException ( 'The middleware stack is already called, no middleware can be added' ) ; } if ( $ prepend ) { array_unshift ( $ this -> middleware , $ definition ) ; } else { $ this -> middleware [ ] = $ definition ; } }
Add a new middleware to the middleware stack of the object .
48,524
public function defaultCommands ( ) { return [ 'server' => [ 'class' => ServerCommand :: class , ] , 'server:start' => [ 'class' => ServerStartCommand :: class , ] , 'server:stop' => [ 'class' => ServerStopCommand :: class , ] , 'server:restart' => [ 'class' => ServerRestartCommand :: class , ] , 'server:reload' => [ 'class' => ServerReloadCommand :: class , ] , 'server:serve' => [ 'class' => ServerServeCommand :: class , ] , 'shell' => [ 'class' => ShellCommand :: class , ] , 'service:install' => [ 'class' => ServiceInstallCommand :: class , ] , 'service:uninstall' => [ 'class' => ServiceUninstallCommand :: class , ] , ] ; }
Returns the default console commands definitions .
48,525
public function callMiddleware ( $ id , $ owner ) { if ( $ owner -> freezed ) { return $ owner ; } $ class = get_class ( $ owner ) ; foreach ( $ owner -> middleware as $ definition ) { $ middleware = make ( $ definition ) ; if ( ! $ middleware instanceof MiddlewareContract ) { throw new InvalidConfigException ( sprintf ( "'%s' is not a valid middleware" , get_class ( $ middleware ) ) ) ; } $ result = $ middleware -> handle ( $ owner ) ; if ( $ result === false ) { break ; } elseif ( $ result instanceof $ class ) { $ owner = $ result ; } elseif ( $ result !== null ) { throw new InvalidValueException ( sprintf ( 'The return value of %s::handle() should be one of false, null and %s' , get_class ( $ middleware ) , $ class ) ) ; } } $ this -> bind ( $ id , $ owner , true ) ; $ owner -> freeze ( ) ; return $ owner ; }
Call the middleware stack .
48,526
public function setBody ( $ body ) { if ( $ body instanceof StreamInterface ) { $ this -> _body = $ body ; } else { $ this -> _body = new Stream ( 'php://memory' , 'rw+' ) ; } }
Sets the body of the message .
48,527
public function enable ( ) { $ this -> manager -> enable ( $ this ) ; if ( $ this -> referenced ) { $ this -> manager -> reference ( $ this ) ; } }
Enables listening for signals to arrive .
48,528
public function emit ( $ value = null ) : \ Generator { if ( null === $ this -> emit ) { $ this -> emit = ( yield $ this -> started ) ; } $ emit = $ this -> emit ; return yield from $ emit ( $ value ) ; }
Emits a value from the contained Emitter object .
48,529
public function complete ( $ value = null ) { if ( null !== $ this -> started ) { $ this -> started -> reject ( new CompletedError ( ) ) ; } $ this -> delayed -> resolve ( $ value ) ; }
Completes the observable with the given value .
48,530
public function fail ( \ Throwable $ reason ) { if ( null !== $ this -> started ) { $ this -> started -> reject ( new CompletedError ( ) ) ; } $ this -> delayed -> reject ( $ reason ) ; }
Throws an error in the observable .
48,531
public function execute ( ) { $ this -> manager -> execute ( $ this ) ; if ( ! $ this -> referenced ) { $ this -> manager -> unreference ( $ this ) ; } }
Execute the immediate if not pending .
48,532
protected function resolve ( $ value = null ) { if ( null !== $ this -> result ) { return ; } if ( $ value instanceof self ) { $ value = $ value -> unwrap ( ) ; if ( $ this === $ value ) { $ value = new Internal \ RejectedAwaitable ( new CircularResolutionError ( 'Circular reference in awaitable resolution chain.' ) ) ; } } elseif ( ! $ value instanceof Awaitable ) { $ value = new Internal \ FulfilledAwaitable ( $ value ) ; } $ this -> result = $ value ; $ this -> result -> done ( $ this -> onFulfilled , $ this -> onRejected ? : new DoneQueue ( ) ) ; $ this -> onFulfilled = null ; $ this -> onRejected = null ; $ this -> onCancelled = null ; }
Resolves the awaitable with the given awaitable or value . If another awaitable this awaitable takes on the state of that awaitable . If a value the awaitable will be fulfilled with that value .
48,533
private function start ( ) { Loop \ queue ( function ( ) { if ( null === $ this -> emitter ) { return ; } $ emit = function ( $ value = null ) : \ Generator { return $ this -> queue -> push ( $ value ) ; } ; try { $ generator = ( $ this -> emitter ) ( $ emit ) ; if ( ! $ generator instanceof Generator ) { throw new UnexpectedTypeError ( 'Generator' , $ generator ) ; } $ this -> coroutine = new Coroutine ( $ generator ) ; $ this -> coroutine -> done ( [ $ this -> queue , 'complete' ] , [ $ this -> queue , 'fail' ] ) ; } catch ( Throwable $ exception ) { $ this -> queue -> fail ( new InvalidEmitterError ( $ this -> emitter , $ exception ) ) ; } $ this -> emitter = null ; } ) ; }
Executes the emitter coroutine .
48,534
protected function getSignalList ( ) : array { if ( null !== self :: $ list ) { return self :: $ list ; } $ signals = [ SIGHUP , SIGINT , SIGQUIT , SIGILL , SIGABRT , SIGTRAP , SIGBUS , SIGTERM , SIGSEGV , SIGFPE , SIGALRM , SIGVTALRM , SIGPROF , SIGIO , SIGCONT , SIGURG , SIGPIPE , SIGXCPU , SIGXFSZ , SIGTTIN , SIGTTOU , SIGUSR1 , SIGUSR2 , ] ; if ( defined ( 'SIGIOT' ) ) { $ signals [ ] = SIGIOT ; } if ( defined ( 'SIGSTKFLT' ) ) { $ signals [ ] = SIGSTKFLT ; } if ( defined ( 'SIGCLD' ) ) { $ signals [ ] = SIGCLD ; } if ( defined ( 'SIGCHLD' ) ) { $ signals [ ] = SIGCHLD ; } return self :: $ list = $ signals ; }
Returns an array of signals to be handled . Exploits the fact that PHP will not notice the signal constants are undefined if the pcntl extension is not installed .
48,535
protected function createSignalCallback ( ) : callable { return function ( $ signo ) { $ handled = false ; if ( isset ( $ this -> signals [ $ signo ] ) ) { foreach ( $ this -> signals [ $ signo ] as $ signal ) { $ handled = true ; $ signal -> call ( ) ; } } switch ( $ signo ) { case SIGHUP : case SIGINT : case SIGQUIT : case SIGABRT : case SIGTRAP : case SIGXCPU : if ( ! $ handled ) { $ this -> loop -> stop ( ) ; } break ; case SIGTERM : case SIGBUS : case SIGSEGV : case SIGFPE : $ this -> loop -> stop ( ) ; break ; } } ; }
Creates callback function for handling signals .
48,536
public function getInterval ( ) { while ( ! $ this -> queue -> isEmpty ( ) ) { list ( $ timer , $ timeout ) = $ this -> queue -> top ( ) ; if ( ! $ this -> timers -> contains ( $ timer ) || $ timeout !== $ this -> timers [ $ timer ] ) { $ this -> queue -> extract ( ) ; continue ; } $ timeout -= microtime ( true ) ; if ( 0 > $ timeout ) { return 0 ; } return $ timeout ; } return null ; }
Calculates the time remaining until the top timer is ready . Returns null if no timers are in the queue otherwise a non - negative value is returned .
48,537
public function tick ( ) : int { $ count = 0 ; $ time = microtime ( true ) ; while ( ! $ this -> queue -> isEmpty ( ) ) { list ( $ timer , $ timeout ) = $ this -> queue -> top ( ) ; if ( ! $ this -> timers -> contains ( $ timer ) || $ timeout !== $ this -> timers [ $ timer ] ) { $ this -> queue -> extract ( ) ; continue ; } if ( $ this -> timers [ $ timer ] > $ time ) { return $ count ; } $ this -> queue -> extract ( ) ; if ( $ timer -> isPeriodic ( ) ) { $ timeout = $ time + $ timer -> getInterval ( ) ; $ this -> queue -> insert ( [ $ timer , $ timeout ] , - $ timeout ) ; $ this -> timers [ $ timer ] = $ timeout ; } else { $ this -> timers -> detach ( $ timer ) ; } $ timer -> call ( ) ; ++ $ count ; } return $ count ; }
Executes any pending timers . Returns the number of timers executed .
48,538
public function maxDepth ( int $ depth = null ) : int { if ( null === $ depth ) { return $ this -> maxDepth ; } $ previous = $ this -> maxDepth ; $ this -> maxDepth = 0 > $ depth ? 0 : $ depth ; return $ previous ; }
Sets the maximum number of functions that can be called when the queue is called .
48,539
public function call ( ) : int { $ count = 0 ; while ( ! $ this -> queue -> isEmpty ( ) && ( 0 === $ this -> maxDepth || $ count < $ this -> maxDepth ) ) { list ( $ callback , $ args ) = $ this -> queue -> shift ( ) ; ++ $ count ; if ( empty ( $ args ) ) { $ callback ( ) ; } else { call_user_func_array ( $ callback , $ args ) ; } } return $ count ; }
Executes each callback that was in the queue when this method is called up to the maximum depth .
48,540
private function next ( $ yielded ) { if ( ! $ this -> generator -> valid ( ) ) { $ result = $ this -> generator -> getReturn ( ) ; if ( $ result instanceof Awaitable ) { $ this -> reject ( new AwaitableReturnedError ( $ result ) ) ; return ; } if ( $ result instanceof Generator ) { $ this -> reject ( new GeneratorReturnedError ( $ result ) ) ; return ; } $ this -> resolve ( $ result ) ; return ; } $ this -> busy = true ; if ( $ yielded instanceof Generator ) { $ yielded = new self ( $ yielded ) ; } $ this -> current = $ yielded ; if ( $ yielded instanceof Awaitable ) { $ yielded -> done ( $ this -> send , $ this -> capture ) ; } else { Loop \ queue ( $ this -> send , $ yielded ) ; } $ this -> busy = false ; }
Examines the value yielded from the generator and prepares the next step in interation .
48,541
public function start ( ) { $ this -> manager -> start ( $ this ) ; if ( ! $ this -> referenced ) { $ this -> manager -> unreference ( $ this ) ; } }
Starts the timer if it not pending .
48,542
public function push ( callable $ callback ) { if ( $ callback instanceof self ) { $ this -> queue = array_merge ( $ this -> queue , $ callback -> queue ) ; return ; } $ this -> queue [ ] = $ callback ; }
Unrolls instances of self to avoid blowing up the call stack on resolution .
48,543
public function isEmpty ( ) : bool { return $ this -> pollManager -> isEmpty ( ) && $ this -> awaitManager -> isEmpty ( ) && $ this -> timerManager -> isEmpty ( ) && $ this -> callableQueue -> isEmpty ( ) && $ this -> immediateManager -> isEmpty ( ) && ( null === $ this -> signalManager || $ this -> signalManager -> isEmpty ( ) ) ; }
Determines if there are any pending tasks in the loop .
48,544
public function decrement ( ) { if ( 0 >= -- $ this -> listeners && null !== $ this -> observable ) { $ this -> observable -> dispose ( new AutoDisposedException ( ) ) ; } }
Decrements the number of listening iterators . Marks the queue as disposed if the count reaches 0 .
48,545
public function complete ( $ value ) { if ( null === $ this -> observable ) { return ; } $ this -> observable = null ; $ this -> delayed -> resolve ( $ value ) ; }
Marks the observable as complete .
48,546
public function fail ( \ Throwable $ exception ) { if ( null === $ this -> observable ) { return ; } $ this -> observable = null ; $ this -> failed = true ; $ this -> delayed -> reject ( $ exception ) ; }
Marks the observable as complete with the given error .
48,547
protected function printBlock ( array $ lines , $ style , $ firstBlock = false ) { $ formatter = $ this -> getHelper ( 'formatter' ) ; if ( $ firstBlock ) { $ this -> line ( '' ) ; } $ spacedLines = array_merge ( [ '' ] , array_merge ( $ lines , [ '' ] ) ) ; $ block = $ formatter -> formatBlock ( $ spacedLines , $ style ) ; $ this -> line ( $ block ) ; $ this -> line ( '' ) ; }
Prints a text block into console output .
48,548
protected function getTokenFromHeader ( ) { if ( ! $ this -> getRequest ( ) -> headers -> has ( 'Authorization' ) ) { return null ; } $ header = $ this -> getRequest ( ) -> headers -> get ( 'Authorization' ) ; return Str :: replaceFirst ( 'Bearer ' , '' , $ header ) ; }
Parse the request looking for the authorization header .
48,549
protected function findUserByToken ( Token $ token ) { $ id = $ token -> getClaim ( 'sub' ) ; return $ this -> provider -> retrieveById ( $ id ) ; }
Retrieves the user by it s token .
48,550
public function issue ( array $ customClaims = [ ] ) { if ( ! $ this -> user ) { return false ; } try { return $ this -> manager ( ) -> issue ( $ this -> user , $ customClaims ) ; } catch ( \ Exception $ e ) { return false ; } }
Issue a token for the current authenticated user .
48,551
public function refresh ( string $ token = null , array $ customClaims = [ ] ) { $ token = $ token ?? $ this -> detectedToken ( ) ; if ( ! $ token ) { return false ; } if ( ! $ this -> manager ( ) -> canBeRenewed ( $ token ) ) { return false ; } $ user = $ this -> findUserByToken ( $ token ) ; if ( ! $ user ) { return false ; } $ this -> user = $ user ; try { return $ this -> manager ( ) -> issue ( $ user , $ customClaims ) ; } catch ( \ Exception $ e ) { return false ; } }
Refresh a given token .
48,552
public function register ( ) { $ this -> authManager = $ this -> app -> make ( AuthManager :: class ) ; $ this -> registerPolicies ( ) ; $ this -> authManager -> extend ( 'jwt' , function ( $ app , $ name , array $ config ) { $ tokenManager = $ this -> getTokenManager ( ) ; $ userProvider = $ this -> getUserProvider ( $ config [ 'provider' ] ) ; $ guard = new Guard ( $ app , $ name , $ userProvider , $ tokenManager ) ; $ guard -> setDispatcher ( resolve ( Dispatcher :: class ) ) ; return new Guard ( $ app , $ name , $ userProvider , $ tokenManager ) ; } ) ; }
Register Guard .
48,553
protected function setupGuardMiddlewareMatch ( ) { $ middlewareMatch = $ this -> app [ 'config' ] -> get ( 'jwt.middleware_match' , true ) ; if ( $ middlewareMatch ) { $ this -> app [ 'router' ] -> matched ( function ( RouteMatched $ event ) { $ middlewareGroup = Arr :: first ( ( array ) $ event -> route -> middleware ( ) ) ; if ( $ middlewareGroup && ! ! $ this -> app [ 'auth' ] -> guard ( $ middlewareGroup ) ) { $ this -> app [ 'auth' ] -> setDefaultDriver ( $ middlewareGroup ) ; } } ) ; } }
Setup the current guard to be matched by route middleware name .
48,554
public function setupSecret ( ) { $ secret = $ this -> config -> get ( 'jwt.secret' ) ; if ( Str :: startsWith ( $ secret , 'base64:' ) ) { $ secret = base64_decode ( substr ( $ secret , 7 ) ) ; } $ this -> secret = $ secret ; if ( ! $ this -> validSecret ( ) ) { throw new \ Exception ( 'Invalid Secret (not present or too short). Use php artisan jwt:generate to create a valid key.' ) ; } }
Setup the secret that will be used to sign keys .
48,555
protected function setupConfig ( ) { $ this -> ttl = $ this -> config -> get ( 'jwt.ttl' , 60 ) ; $ this -> refreshLimit = $ this -> config -> get ( 'jwt.refresh_limit' , 7200 ) ; $ this -> issuer = url ( '' ) ; }
Setup JWT configuration .
48,556
public function parseToken ( string $ tokenString ) { try { return $ this -> parser ( ) -> parse ( $ tokenString ) ; } catch ( \ Exception $ e ) { return null ; } }
Method for parsing a token from a string .
48,557
public function canBeRenewed ( Token $ token ) { if ( ! $ token -> isExpired ( ) ) { return true ; } $ renewalLimitTimestamp = $ token -> getClaim ( 'rli' , null ) ; if ( ! $ renewalLimitTimestamp ) { return false ; } $ limit = Carbon :: createFromTimestampUTC ( $ renewalLimitTimestamp ) ; $ now = $ this -> now ( ) ; return $ now -> lessThanOrEqualTo ( $ limit ) ; }
Is the token Expired?
48,558
public function boot ( ) { $ configPath = __DIR__ . '/../config/api-debugger.php' ; $ this -> publishes ( [ $ configPath => config_path ( 'api-debugger.php' ) ] ) ; $ this -> mergeConfigFrom ( $ configPath , 'api-debugger' ) ; $ config = $ this -> app [ 'config' ] ; if ( $ config [ 'api-debugger.enabled' ] ) { $ this -> registerCollections ( $ config [ 'api-debugger.collections' ] ) ; } }
Bootstrap application service .
48,559
protected function registerCollections ( array $ collections ) { $ debugger = $ this -> app -> make ( Debugger :: class ) ; foreach ( $ collections as $ collection ) { $ debugger -> populateWith ( $ this -> app -> make ( $ collection ) ) ; } }
Register requested collections within debugger .
48,560
public function getData ( ) { $ return = [ ] ; foreach ( $ this -> collections as $ collection ) { $ return [ $ collection -> name ( ) ] = $ collection -> items ( ) ; } if ( count ( $ this -> dump ) != 0 ) { $ return [ 'dump' ] = $ this -> dump ; } return $ return ; }
Return result debug data .
48,561
public function profileMe ( $ name , \ Closure $ action ) { $ this -> startProfiling ( $ name ) ; $ return = $ action ( ) ; $ this -> stopProfiling ( $ name ) ; return $ return ; }
Profile action .
48,562
protected function updateResponse ( Request $ request , Response $ response ) { $ this -> stopProfiling ( ProfilingCollection :: REQUEST_TIMER ) ; if ( $ this -> needToUpdateResponse ( $ response ) ) { $ data = $ this -> getResponseData ( $ response ) ; if ( $ data === false ) { return ; } $ data [ $ this -> responseKey ] = $ this -> storage -> getData ( ) ; $ this -> setResponseData ( $ response , $ data ) ; } }
Update final response .
48,563
protected function needToUpdateResponse ( Response $ response ) { $ isJsonResponse = $ response instanceof JsonResponse || $ response -> headers -> contains ( 'content-type' , 'application/json' ) ; return $ isJsonResponse && ! $ this -> storage -> isEmpty ( ) ; }
Check if debugger has to update the response .
48,564
protected function getResponseData ( Response $ response ) { if ( $ response instanceof JsonResponse ) { return $ response -> getData ( true ) ? : [ ] ; } $ content = $ response -> getContent ( ) ; return json_decode ( $ content , true ) ? : false ; }
Fetches the contents of the response and parses them to an assoc array
48,565
protected function setResponseData ( Response $ response , array $ data ) { if ( $ response instanceof JsonResponse ) { return $ response -> setData ( $ data ) ; } $ content = json_encode ( $ data , JsonResponse :: DEFAULT_ENCODING_OPTIONS ) ; return $ response -> setContent ( $ content ) ; }
Updates the response content
48,566
protected function store ( $ label , CacheEvent $ event ) { $ tags = $ event -> tags ; $ this -> events [ $ label ] [ 'keys' ] [ ] = ! empty ( $ tags ) ? [ 'tags' => $ tags , 'key' => $ event -> key ] : $ event -> key ; $ this -> events [ $ label ] [ 'total' ] ++ ; }
Store event .
48,567
public function logQuery ( $ connection , $ query , array $ bindings , $ time ) { if ( ! empty ( $ bindings ) ) { $ query = vsprintf ( str_replace ( [ '%' , '?' ] , [ '%%' , "'%s'" ] , $ query ) , $ this -> normalizeQueryAttributes ( $ bindings ) ) ; } $ query = rtrim ( $ query , ';' ) . ';' ; $ this -> queries [ ] = compact ( 'connection' , 'query' , 'time' ) ; }
Log DB query .
48,568
protected function normalizeQueryAttributes ( array $ attributes ) { $ result = [ ] ; foreach ( $ attributes as $ attribute ) { $ result [ ] = $ this -> convertAttribute ( $ attribute ) ; } return $ result ; }
Be sure that all attributes sent to DB layer are strings .
48,569
protected function convertAttribute ( $ attribute ) { try { return ( string ) $ attribute ; } catch ( \ Exception $ e ) { switch ( true ) { case $ attribute instanceof \ DateTime : return $ attribute -> format ( 'Y-m-d H:i:s' ) ; case $ attribute instanceof \ Closure : return $ this -> convertAttribute ( $ attribute ( ) ) ; case is_array ( $ attribute ) : $ json = json_encode ( $ attribute ) ; return json_last_error ( ) === JSON_ERROR_NONE ? $ json : print_r ( $ attribute ) ; case is_object ( $ attribute ) : return get_class ( $ attribute ) ; default : return '?' ; } } }
Convert attribute to string .
48,570
public function addMessage ( $ type , $ message , $ file = null , $ file_details = null ) { switch ( $ type ) { case Output :: FATAL : $ this -> fatals [ ] = new Message ( $ type , $ message , $ file , $ file_details ) ; break ; case Output :: ERROR : $ this -> errors [ ] = new Message ( $ type , $ message , $ file , $ file_details ) ; break ; case Output :: WARNING : $ this -> warnings [ ] = new Message ( $ type , $ message , $ file , $ file_details ) ; break ; case Output :: NOTICE : $ this -> notices [ ] = new Message ( $ type , $ message , $ file , $ file_details ) ; break ; default : } }
Add a new message to the output of the validator .
48,571
public function getMessages ( ) { return array_merge ( $ this -> fatals , $ this -> errors , $ this -> warnings , $ this -> notices ) ; }
Get all messages saved into the message queue .
48,572
public function getMessageCount ( $ type ) { switch ( $ type ) { case Output :: FATAL : return sizeof ( $ this -> fatals ) ; case Output :: ERROR : return sizeof ( $ this -> errors ) ; case Output :: WARNING : return sizeof ( $ this -> warnings ) ; case Output :: NOTICE : return sizeof ( $ this -> notices ) ; } return 0 ; }
Get the amount of messages that were fatal .
48,573
protected function getFileList ( $ dir ) { $ finder = new Finder ( ) ; $ iterator = $ finder -> ignoreDotFiles ( false ) -> files ( ) -> sortByName ( ) -> in ( $ dir ) ; $ files = array ( ) ; foreach ( $ iterator as $ file ) { $ files [ ] = str_replace ( DIRECTORY_SEPARATOR , '/' , substr ( $ file -> getPathname ( ) , strlen ( $ dir ) + 1 ) ) ; } return $ files ; }
Returns a list of files in the directory
48,574
public function setPluralRule ( $ pluralRule ) { $ this -> pluralRule = $ pluralRule ; $ this -> langkeyValidator -> setPluralRule ( $ pluralRule ) ; return $ this ; }
Set plural rule
48,575
public function setDebug ( $ debug ) { $ this -> debug = $ debug ; $ this -> langkeyValidator -> setDebug ( $ debug ) ; return $ this ; }
Set debug mode
48,576
public function validate ( $ sourceFile , $ originFile ) { $ this -> validateLineEndings ( $ originFile ) ; if ( substr ( $ originFile , - 4 ) === '.php' ) { $ this -> validateDefinedInPhpbb ( $ originFile ) ; $ this -> validateUtf8withoutbom ( $ originFile ) ; $ this -> validateNoPhpClosingTag ( $ originFile ) ; } if ( strpos ( $ originFile , $ this -> originLanguagePath . 'email/' ) === 0 && substr ( $ originFile , - 4 ) === '.txt' ) { $ this -> validateEmail ( $ sourceFile , $ originFile ) ; } else if ( strpos ( $ originFile , $ this -> originLanguagePath . 'help_' ) === 0 && substr ( $ originFile , - 4 ) === '.php' ) { $ this -> validateHelpFile ( $ sourceFile , $ originFile ) ; } else if ( $ originFile == $ this -> originLanguagePath . 'search_synonyms.php' ) { $ this -> validateSearchSynonymsFile ( $ originFile ) ; } else if ( $ originFile == $ this -> originLanguagePath . 'search_ignore_words.php' ) { $ this -> validateSearchIgnoreWordsFile ( $ originFile ) ; } else if ( substr ( $ originFile , - 4 ) === '.php' ) { $ this -> validateLangFile ( $ sourceFile , $ originFile ) ; } else if ( substr ( $ originFile , - 9 ) === 'index.htm' ) { $ this -> validateIndexFile ( $ originFile ) ; } else if ( $ originFile === $ this -> originLanguagePath . 'LICENSE' ) { $ this -> validateLicenseFile ( $ originFile ) ; } else if ( $ originFile === $ this -> originLanguagePath . 'iso.txt' ) { $ this -> validateIsoFile ( $ originFile ) ; } else if ( substr ( $ originFile , - 4 ) === '.css' ) { $ this -> validateUtf8withoutbom ( $ originFile ) ; $ this -> validateCSSFile ( $ sourceFile , $ originFile ) ; } else { $ this -> output -> addMessage ( Output :: NOTICE , 'File is not validated' , $ originFile ) ; } }
Decides which validation function to use
48,577
public function validateLangFile ( $ sourceFile , $ originFile ) { $ originFilePath = $ this -> originPath . '/' . $ originFile ; $ sourceFilePath = $ this -> sourcePath . '/' . $ sourceFile ; if ( ! $ this -> safeMode ) { ob_start ( ) ; include ( $ originFilePath ) ; $ defined_variables = get_defined_vars ( ) ; if ( sizeof ( $ defined_variables ) != 5 || ! isset ( $ defined_variables [ 'lang' ] ) || gettype ( $ defined_variables [ 'lang' ] ) != 'array' ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must only contain the lang-array' , $ originFile ) ; if ( ! isset ( $ defined_variables [ 'lang' ] ) || gettype ( $ defined_variables [ 'lang' ] ) != 'array' ) { return ; } } $ output = ob_get_contents ( ) ; ob_end_clean ( ) ; if ( $ output !== '' ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must not produces output: ' . htmlspecialchars ( $ output ) , $ originFile ) ; } } else { $ lang = ValidatorRunner :: langParser ( $ originFilePath ) ; $ this -> output -> addMessage ( Output :: NOTICE , '<bg=yellow;options=bold>[Safe Mode]</> Manually run the translation validator to check for disallowed output.' , $ originFile ) ; } $ validate = $ lang ; unset ( $ lang ) ; if ( ! $ this -> safeMode ) { include ( $ sourceFilePath ) ; } else { $ lang = ValidatorRunner :: langParser ( $ sourceFilePath ) ; } $ against = $ lang ; unset ( $ lang ) ; foreach ( $ against as $ againstLangKey => $ againstLanguage ) { if ( ! isset ( $ validate [ $ againstLangKey ] ) ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must contain key: ' . $ againstLangKey , $ originFile ) ; continue ; } $ this -> langkeyValidator -> validate ( $ originFile , $ againstLangKey , $ againstLanguage , $ validate [ $ againstLangKey ] ) ; } foreach ( $ validate as $ validateLangKey => $ validateLanguage ) { if ( ! isset ( $ against [ $ validateLangKey ] ) ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must not contain key: ' . $ validateLangKey , $ originFile ) ; } } if ( $ originFile === $ this -> originLanguagePath . 'captcha_recaptcha.php' ) { $ this -> validateReCaptchaValue ( $ originFile , $ validate ) ; } }
Validates a normal language file
48,578
public function validateReCaptchaValue ( $ originFile , $ validate ) { if ( array_key_exists ( 'RECAPTCHA_LANG' , $ validate ) && ! in_array ( $ validate [ 'RECAPTCHA_LANG' ] , $ this -> reCaptchaLanguages ) ) { $ this -> output -> addMessage ( Output :: ERROR , 'reCaptcha must match a language/country code on https://developers.google.com/recaptcha/docs/language - if no code exists for your language you can use "en" or leave the string empty' , $ originFile , 'RECAPTCHA_LANG' ) ; } }
Check that the reCaptcha key provided is allowed
48,579
public function validateSearchSynonymsFile ( $ originFile ) { $ originFilePath = $ this -> originPath . '/' . $ originFile ; if ( ! $ this -> safeMode ) { include ( $ originFilePath ) ; $ defined_variables = get_defined_vars ( ) ; if ( sizeof ( $ defined_variables ) != 3 || ! isset ( $ defined_variables [ 'synonyms' ] ) || gettype ( $ defined_variables [ 'synonyms' ] ) != 'array' ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must only contain the synonyms-array' , $ originFile ) ; return ; } } else { $ synonyms = ValidatorRunner :: langParser ( $ originFilePath ) ; $ this -> output -> addMessage ( Output :: NOTICE , '<bg=yellow;options=bold>[Safe Mode]</> Manually run the translation validator to check synonym variables.' , $ originFile ) ; } foreach ( $ synonyms as $ synonym1 => $ synonym2 ) { if ( gettype ( $ synonym1 ) != 'string' || gettype ( $ synonym2 ) != 'string' ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must only contain entries of type string => string: ' . serialize ( $ synonym1 ) . ' => ' . serialize ( $ synonym2 ) , $ originFile ) ; } } }
Validates the search_synonyms . php file
48,580
public function validateSearchIgnoreWordsFile ( $ originFile ) { $ originFilePath = $ this -> originPath . '/' . $ originFile ; if ( ! $ this -> safeMode ) { include ( $ originFilePath ) ; $ defined_variables = get_defined_vars ( ) ; if ( sizeof ( $ defined_variables ) != 3 || ! isset ( $ defined_variables [ 'words' ] ) || gettype ( $ defined_variables [ 'words' ] ) != 'array' ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must only contain the words-array' , $ originFile ) ; return ; } } else { $ words = ValidatorRunner :: langParser ( $ originFilePath ) ; $ this -> output -> addMessage ( Output :: NOTICE , '<bg=yellow;options=bold>[Safe Mode]</> Manually run the translation validator to check word variables.' , $ originFile ) ; } foreach ( $ words as $ word ) { if ( gettype ( $ word ) != 'string' ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must only contain entries of type string: ' . serialize ( $ word ) , $ originFile ) ; } } }
Validates the search_ignore_words . php file
48,581
public function validateLicenseFile ( $ originFile ) { $ fileContents = ( string ) file_get_contents ( $ this -> originPath . '/' . $ originFile ) ; if ( md5 ( $ fileContents ) != 'e060338598cd2cd6b8503733fdd40a11' ) { $ this -> output -> addMessage ( Output :: FATAL , 'License must be: GNU GENERAL PUBLIC LICENSE Version 2, June 1991' , $ originFile ) ; } }
Validates the LICENSE file
48,582
public function validateIsoFile ( $ originFile ) { $ fileContents = ( string ) file_get_contents ( $ this -> originPath . '/' . $ originFile ) ; $ isoFile = explode ( "\n" , $ fileContents ) ; if ( sizeof ( $ isoFile ) != 3 ) { $ this -> output -> addMessage ( Output :: FATAL , 'Must contain exactly 3 lines: 1. English name, 2. Native name, 3. Author information' , $ originFile ) ; } }
Validates the iso . txt file
48,583
public function validateNoPhpClosingTag ( $ originFile ) { $ fileContents = ( string ) file_get_contents ( $ this -> originPath . '/' . $ originFile ) ; $ fileContents = str_replace ( "\r\n" , "\n" , $ fileContents ) ; $ fileContents = str_replace ( "\r" , "\n" , $ fileContents ) ; if ( substr ( $ fileContents , - 3 ) !== ");\n" ) { if ( substr ( $ fileContents , - 3 ) !== "];\n" ) { $ this -> output -> addMessage ( Output :: FATAL , 'File must not contain a PHP closing tag, but end with one new line' , $ originFile ) ; } } }
Validates whether a file does not contain a closing php tag
48,584
public function validate ( $ file , $ key , $ against_language , $ validate_language ) { if ( gettype ( $ against_language ) !== gettype ( $ validate_language ) ) { $ this -> output -> addMessage ( Output :: FATAL , sprintf ( 'Key should be type %s but is type %s' , gettype ( $ against_language ) , gettype ( $ validate_language ) ) , $ file , $ key ) ; return ; } if ( $ key === 'PLURAL_RULE' ) { if ( $ validate_language < 0 || $ validate_language > 15 ) { $ this -> output -> addMessage ( Output :: FATAL , sprintf ( 'The plural rule %d, which you are trying to use, does not exist. For more information see https://wiki.phpbb.com/Plural_Rules.' , $ validate_language ) , $ file , $ key ) ; return ; } } else if ( $ key === 'DIRECTION' ) { if ( ! in_array ( $ validate_language , array ( 'ltr' , 'rtl' ) ) ) { $ this -> output -> addMessage ( Output :: FATAL , sprintf ( 'The text direction %s, which you are trying to use, does not exist. Currently only ltr (left-to-right) and rtl (right-to-left) are allowed.' , $ validate_language ) , $ file , $ key ) ; return ; } } else if ( $ key === 'USER_LANG' ) { if ( str_replace ( '_' , '-' , $ this -> originIso ) !== $ validate_language && strpos ( $ validate_language , $ this -> originIso . '-' ) !== 0 ) { $ this -> output -> addMessage ( Output :: FATAL , sprintf ( 'The user language %s, which you are trying to use, does not match the language.' , $ validate_language ) , $ file , $ key ) ; return ; } } else if ( gettype ( $ against_language ) === 'string' ) { $ this -> validateString ( $ file , $ key , $ against_language , $ validate_language ) ; } else { $ this -> validateArray ( $ file , $ key , $ against_language , $ validate_language ) ; } }
Validates type of the language and decides on further validation
48,585
public function validateArray ( $ file , $ key , $ against_language , $ validate_language ) { if ( $ key === 'dateformats' ) { $ this -> validateDateformats ( $ file , $ key , $ validate_language ) ; } else if ( $ key === 'datetime' || $ key === 'timezones' || $ key === 'tokens' || $ key === 'report_reasons' || $ key === 'PM_ACTION' || $ key === 'PM_CHECK' || $ key === 'PM_RULE' ) { $ this -> validateArrayKey ( $ file , $ key , $ against_language , $ validate_language ) ; } else { $ against_keys = array_keys ( $ against_language ) ; $ key_types = array ( ) ; foreach ( $ against_keys as $ against_key ) { $ type = gettype ( $ against_key ) ; if ( ! isset ( $ key_types [ $ type ] ) ) { $ key_types [ $ type ] = 0 ; } $ key_types [ $ type ] ++ ; } if ( sizeof ( $ key_types ) == 1 ) { if ( isset ( $ key_types [ 'string' ] ) ) { $ this -> validateArrayKey ( $ file , $ key , $ against_language , $ validate_language ) ; } else if ( isset ( $ key_types [ 'integer' ] ) ) { $ this -> validatePluralKeys ( $ file , $ key , $ against_language , $ validate_language ) ; } else { $ this -> output -> addMessage ( Output :: NOTICE , 'Array has mixed types: ' . implode ( ', ' , array_keys ( $ key_types ) ) , $ file , $ key ) ; } } else { $ this -> output -> addMessage ( Output :: NOTICE , 'Array has mixed types: ' . implode ( ', ' , array_keys ( $ key_types ) ) , $ file , $ key ) ; } } }
Decides which array validation function should be used based on the key
48,586
public function validatePluralKeys ( $ file , $ key , $ against_language , $ validate_language ) { $ origin_cases = array_keys ( $ validate_language ) ; if ( empty ( $ origin_cases ) ) { $ this -> output -> addMessage ( Output :: FATAL , 'Plural array must not be empty' , $ file , $ key ) ; return ; } $ valid_cases = $ this -> getPluralKeys ( $ this -> pluralRule ) ; $ intersect_cases = array_intersect ( $ origin_cases , $ valid_cases ) ; $ missing_cases = array_diff ( $ valid_cases , $ origin_cases ) ; $ additional_cases = array_diff ( $ origin_cases , $ valid_cases , array ( 0 ) ) ; if ( ! empty ( $ additional_cases ) ) { $ this -> output -> addMessage ( Output :: FATAL , 'Plural array has additional case: ' . implode ( ', ' , $ additional_cases ) , $ file , $ key ) ; } if ( empty ( $ intersect_cases ) ) { $ this -> output -> addMessage ( Output :: FATAL , 'Plural array must not be empty' , $ file , $ key ) ; return ; } if ( ! empty ( $ missing_cases ) ) { $ this -> output -> addMessage ( Output :: WARNING , 'Plural array is missing case: ' . implode ( ', ' , $ missing_cases ) , $ file , $ key ) ; } if ( ! empty ( $ intersect_cases ) ) { $ compare_against = '' ; if ( $ against_language ) { $ compare_against = end ( $ against_language ) ; } foreach ( $ intersect_cases as $ case ) { $ this -> validateString ( $ file , $ key . '.' . $ case , $ compare_against , $ validate_language [ $ case ] , true ) ; } } }
Validates the plural keys
48,587
public function validateDateformats ( $ file , $ key , $ validate_language ) { if ( empty ( $ validate_language ) ) { $ this -> output -> addMessage ( Output :: FATAL , 'Array must not be empty' , $ file , $ key ) ; return ; } foreach ( $ validate_language as $ dateformat => $ example_time ) { $ this -> validateString ( $ file , $ key . '.' . $ dateformat , '' , $ dateformat ) ; $ this -> validateString ( $ file , $ key . '.' . $ dateformat , '' , $ example_time ) ; } }
Validates the dateformats
48,588
public function validateAcl ( $ file , $ key , $ against_language , $ validate_language ) { if ( ! isset ( $ validate_language [ 'cat' ] ) ) { $ this -> output -> addMessage ( Output :: FATAL , 'Permission is missing the cat-key' , $ file , $ key ) ; } else if ( $ validate_language [ 'cat' ] !== $ against_language [ 'cat' ] ) { $ this -> output -> addMessage ( Output :: FATAL , sprintf ( 'Permission should have cat %1$s but has %2$s' , $ against_language [ 'cat' ] , $ validate_language [ 'cat' ] ) , $ file , $ key ) ; } if ( ! isset ( $ validate_language [ 'lang' ] ) ) { $ this -> output -> addMessage ( Output :: FATAL , 'Permission is missing the lang-key' , $ file , $ key ) ; } else { $ this -> validateString ( $ file , $ key , $ against_language [ 'lang' ] , $ validate_language [ 'lang' ] ) ; } }
Validates a permission entry
48,589
public function validateArrayKey ( $ file , $ key , $ against_language , $ validate_language ) { if ( gettype ( $ against_language ) !== gettype ( $ validate_language ) ) { $ this -> output -> addMessage ( Output :: FATAL , sprintf ( 'Should be type %1$s but is type %2$s' , gettype ( $ against_language ) , gettype ( $ validate_language ) ) , $ file , $ key ) ; return ; } $ cat_validate_keys = array_keys ( $ validate_language ) ; $ cat_against_keys = array_keys ( $ against_language ) ; $ invalid_keys = array_diff ( $ cat_validate_keys , $ cat_against_keys ) ; foreach ( $ against_language as $ array_key => $ lang ) { if ( ! isset ( $ validate_language [ $ array_key ] ) ) { if ( gettype ( $ array_key ) == 'string' ) { $ this -> output -> addMessage ( Output :: FATAL , 'Array is missing key: ' . $ array_key , $ file , $ key ) ; } continue ; } if ( is_string ( $ lang ) ) { $ this -> validateString ( $ file , $ key . '.' . $ array_key , $ lang , $ validate_language [ $ array_key ] ) ; } else { $ this -> validateArray ( $ file , $ key . '.' . $ array_key , $ lang , $ validate_language [ $ array_key ] ) ; } } if ( ! empty ( $ invalid_keys ) ) { foreach ( $ invalid_keys as $ array_key ) { if ( gettype ( $ array_key ) == 'string' ) { $ this -> output -> addMessage ( Output :: FATAL , 'Array has invalid key: ' . $ array_key , $ file , $ key ) ; } else { $ this -> output -> addMessage ( Output :: FATAL , 'Array has invalid key: ' . $ array_key , $ file , $ key ) ; } $ this -> output -> addMessage ( Output :: ERROR , 'Key was not validated: ' . $ array_key , $ file , $ key . '.' . $ array_key ) ; } } }
Validates an array entry
48,590
protected function getErrorLevelForAdditionalHtml ( $ html ) { if ( preg_match ( '#^<(i|b|ul|ol|li|h3)( style="[a-zA-Z0-9_\:\ \;\-]+")?>$#' , $ html ) ) { return Output :: ERROR ; } if ( in_array ( $ html , array ( '<em>' , '<strong>' , '<samp>' , '<u>' , '<br />' , '<br>' , '<hr>' ) ) ) { return Output :: NOTICE ; } if ( preg_match ( '#^<a href="([a-zA-Z0-9_\:\&\/\?\.\-\#\@]+)">$#' , $ html ) || preg_match ( '#^<a href="([a-zA-Z0-9_\:\&\/\?\.\-\#]+)" rel="external">$#' , $ html ) ) { return Output :: ERROR ; } return Output :: FATAL ; }
Returns the error level for a given HTML
48,591
public function runValidators ( ) { $ filelistValidator = new FileListValidator ( $ this -> input , $ this -> output ) ; $ validateFiles = $ filelistValidator -> setSource ( $ this -> sourceIso , $ this -> sourcePath , $ this -> sourceLanguagePath ) -> setOrigin ( $ this -> originIso , $ this -> originPath , $ this -> originLanguagePath ) -> setPhpbbVersion ( $ this -> phpbbVersion ) -> setDebug ( $ this -> debug ) -> setSafeMode ( $ this -> safeMode ) -> validate ( ) ; if ( empty ( $ validateFiles ) ) { $ this -> output -> writelnIfDebug ( '' ) ; $ this -> output -> writelnIfDebug ( "<fatal>No files found for validation.</fatal>" ) ; return ; } $ pluralRule = $ this -> guessPluralRule ( ) ; $ this -> output -> writelnIfDebug ( "<notice>Using plural rule #$pluralRule for validation.</notice>" ) ; $ this -> output -> writelnIfDebug ( '' ) ; $ this -> output -> writelnIfDebug ( "Validating file list:" ) ; $ this -> printErrorLevel ( $ this -> output ) ; $ this -> maxProgress = sizeof ( $ validateFiles ) + 1 ; $ this -> progressLength = 11 + strlen ( $ this -> maxProgress ) * 2 ; $ filelistValidator = new FileValidator ( $ this -> input , $ this -> output ) ; $ filelistValidator -> setSource ( $ this -> sourceIso , $ this -> sourcePath , $ this -> sourceLanguagePath ) -> setOrigin ( $ this -> originIso , $ this -> originPath , $ this -> originLanguagePath ) -> setPhpbbVersion ( $ this -> phpbbVersion ) -> setPluralRule ( $ pluralRule ) -> setDebug ( $ this -> debug ) -> setSafeMode ( $ this -> safeMode ) ; foreach ( $ validateFiles as $ sourceFile => $ originFile ) { $ this -> output -> writelnIfDebug ( '' ) ; $ this -> output -> writelnIfDebug ( "Validating file: $originFile" ) ; $ filelistValidator -> validate ( $ sourceFile , $ originFile ) ; $ this -> printErrorLevel ( $ this -> output ) ; usleep ( 31250 ) ; } $ this -> output -> writeln ( '.' ) ; }
Run the actual test suite .
48,592
protected function guessPluralRule ( ) { $ filePath = $ this -> originPath . '/' . $ this -> originLanguagePath . 'common.php' ; if ( file_exists ( $ filePath ) ) { if ( $ this -> safeMode ) { $ lang = self :: langParser ( $ filePath ) ; } else { include ( $ filePath ) ; } if ( ! isset ( $ lang [ 'PLURAL_RULE' ] ) ) { $ this -> output -> writelnIfDebug ( "<info>No plural rule set, falling back to plural rule #1</info>" ) ; } } else { $ this -> output -> writelnIfDebug ( "<info>Could not find common.php, falling back to plural rule #1</info>" ) ; } return isset ( $ lang [ 'PLURAL_RULE' ] ) ? $ lang [ 'PLURAL_RULE' ] : 1 ; }
Try to find the plural rule for the language
48,593
public static function langParser ( $ filePath , $ relativePath = '' ) { $ lang = [ ] ; $ parsed = self :: arrayParser ( $ relativePath . $ filePath ) ; foreach ( $ parsed as $ parse ) { $ lang = array_merge ( $ lang , $ parse ) ; } return $ lang ; }
Merge parsed language entries into a single array
48,594
protected function changeTimezone ( ) { $ this -> previousTimezone = false ; if ( $ this -> timezone ) { $ this -> previousTimezone = date_default_timezone_get ( ) ; date_default_timezone_set ( $ this -> timezone ) ; } }
Changes the timezone
48,595
private function isLessThan1Hour29Mins59Seconds ( $ timeDifference ) { return $ timeDifference >= ( ( $ this -> secondsPerMinute * 44 ) + 30 ) && $ timeDifference <= ( $ this -> secondsPerHour + ( $ this -> secondsPerMinute * 29 ) + 59 ) ; }
Checks if the time difference is less than 1hour 29mins 59seconds
48,596
private function isLessThan23Hours59Mins29Seconds ( $ timeDifference ) { return $ timeDifference >= ( $ this -> secondsPerHour + ( $ this -> secondsPerMinute * 30 ) ) && $ timeDifference <= ( ( $ this -> secondsPerHour * 23 ) + ( $ this -> secondsPerMinute * 59 ) + 29 ) ; }
Checks if the time difference is less than 23hours 59mins 29seconds
48,597
private function isLessThan47Hours59Mins29Seconds ( $ timeDifference ) { return $ timeDifference >= ( ( $ this -> secondsPerHour * 23 ) + ( $ this -> secondsPerMinute * 59 ) + 30 ) && $ timeDifference <= ( ( $ this -> secondsPerHour * 47 ) + ( $ this -> secondsPerMinute * 59 ) + 29 ) ; }
Checks if the time difference is less than 27hours 59mins 29seconds
48,598
private function isLessThan29Days23Hours59Mins29Seconds ( $ timeDifference ) { return $ timeDifference >= ( ( $ this -> secondsPerHour * 47 ) + ( $ this -> secondsPerMinute * 59 ) + 30 ) && $ timeDifference <= ( ( $ this -> secondsPerDay * 29 ) + ( $ this -> secondsPerHour * 23 ) + ( $ this -> secondsPerMinute * 59 ) + 29 ) ; }
Checks if the time difference is less than 29days 23hours 59mins 29seconds
48,599
private function isLessThan59Days23Hours59Mins29Secs ( $ timeDifference ) { return $ timeDifference >= ( ( $ this -> secondsPerDay * 29 ) + ( $ this -> secondsPerHour * 23 ) + ( $ this -> secondsPerMinute * 59 ) + 30 ) && $ timeDifference <= ( ( $ this -> secondsPerDay * 59 ) + ( $ this -> secondsPerHour * 23 ) + ( $ this -> secondsPerMinute * 59 ) + 29 ) ; }
Checks if the time difference is less than 59days 23hours 59mins 29seconds