idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
39,700
protected function setDefaultCurlSettings ( ) { $ verifySsl = $ this -> options -> verifySsl ( ) ; $ timeout = $ this -> options -> getTimeout ( ) ; $ followRedirects = $ this -> options -> getFollowRedirects ( ) ; \ curl_setopt ( $ this -> ch , CURLOPT_SSL_VERIFYPEER , $ verifySsl ) ; if ( ! $ verifySsl ) { \ curl_set...
Set default cURL settings .
39,701
protected function lookForErrors ( $ parsedResponse ) { if ( ! \ in_array ( $ this -> response -> getCode ( ) , [ '200' , '201' , '202' ] ) ) { $ errors = isset ( $ parsedResponse -> errors ) ? $ parsedResponse -> errors : $ parsedResponse ; $ errorMessage = '' ; $ errorCode = '' ; if ( is_array ( $ errors ) ) { $ erro...
Look for errors in the request .
39,702
protected function processResponse ( ) { $ body = $ this -> response -> getBody ( ) ; if ( 0 === strpos ( bin2hex ( substr ( $ body , 0 , 4 ) ) , 'efbbbf' ) ) { $ body = substr ( $ body , 3 ) ; } $ parsedResponse = \ json_decode ( $ body ) ; if ( JSON_ERROR_NONE !== json_last_error ( ) ) { $ message = function_exists (...
Process response .
39,703
public function request ( $ endpoint , $ method , $ data = [ ] , $ parameters = [ ] ) { $ this -> ch = \ curl_init ( ) ; $ request = $ this -> createRequest ( $ endpoint , $ method , $ data , $ parameters ) ; $ this -> setDefaultCurlSettings ( ) ; $ response = $ this -> createResponse ( ) ; if ( \ curl_errno ( $ this -...
Make requests .
39,704
private function _compact_exploded_javascript ( string $ str ) : string { static $ WORDS_CACHE ; $ WORDS_CACHE [ 'chunk' ] = [ ] ; $ WORDS_CACHE [ 'split' ] = [ ] ; $ words = [ 'javascript' , '<script' , '</script>' , 'base64' , 'document' , 'eval' , ] ; if ( \ strlen ( $ str ) <= 30 ) { $ useStrPos = true ; } else { $...
Compact any exploded words .
39,705
private function _decode_entity ( array $ match ) : string { $ str = $ match [ 0 ] ; if ( \ preg_match_all ( "/[\?|&]?[\\p{L}0-9_\-\[\]]+\s*=\s*(?<wrapped>\"|\042|'|\047)(?<attr>[^\\1]*?)\\g{wrapped}/ui" , $ str , $ matches ) ) { if ( isset ( $ matches [ 'attr' ] ) ) { foreach ( $ matches [ 'attr' ] as $ matchInner ) {...
HTML - Entity decode callback .
39,706
private function _do_never_allowed ( string $ str ) : string { static $ NEVER_ALLOWED_CACHE = [ ] ; $ NEVER_ALLOWED_CACHE [ 'keys' ] = null ; $ NEVER_ALLOWED_CACHE [ 'regex' ] = null ; if ( $ NEVER_ALLOWED_CACHE [ 'keys' ] === null ) { $ NEVER_ALLOWED_CACHE [ 'keys' ] = \ array_keys ( $ this -> _never_allowed_str ) ; }...
Remove never allowed strings .
39,707
private function _do_never_allowed_afterwards ( string $ str ) : string { if ( \ stripos ( $ str , 'on' ) !== false ) { foreach ( self :: $ _never_allowed_on_events_afterwards as $ event ) { if ( \ stripos ( $ str , $ event ) !== false ) { $ regex = '(?<before>[^\p{L}]|^)(?:' . $ event . ')(?<after>\s|[^\p{L}]|$)' ; do...
Remove never allowed string afterwards .
39,708
private function _entity_decode ( string $ str ) : string { static $ HTML_ENTITIES_CACHE ; $ flags = ENT_QUOTES | ENT_HTML5 | ENT_DISALLOWED | ENT_SUBSTITUTE ; $ str = UTF8 :: html_entity_decode ( $ str , $ flags ) ; if ( \ preg_match_all ( '/(?<html_entity>&[A-Za-z]{2,}[;]{0})/' , $ str , $ matches ) ) { if ( $ HTML_E...
Entity - decoding .
39,709
private function _filter_attributes ( string $ str ) : string { if ( $ str === '' ) { return '' ; } $ out = '' ; if ( \ preg_match_all ( '#\s*[\\p{L}0-9_\-\[\]]+\s*=\s*("|\042|\'|\047)(?:[^\\1]*?)\\1#ui' , $ str , $ matches ) ) { foreach ( $ matches [ 0 ] as $ match ) { $ out .= $ match ; } } return $ out ; }
Filters tag attributes for consistency and safety .
39,710
private function _repack_utf7 ( string $ str ) : string { return ( string ) \ preg_replace_callback ( '#\+([\\p{L}0-9]+)\-#ui' , function ( $ matches ) { return $ this -> _repack_utf7_callback ( $ matches ) ; } , $ str ) ; }
UTF - 7 decoding function .
39,711
private function _repack_utf7_callback ( array $ strings ) : string { $ strTmp = \ base64_decode ( $ strings [ 1 ] , true ) ; if ( $ strTmp === false ) { return $ strings [ 0 ] ; } if ( \ rtrim ( \ base64_encode ( $ strTmp ) , '=' ) !== \ rtrim ( $ strings [ 1 ] , '=' ) ) { return $ strings [ 0 ] ; } $ string = ( strin...
Additional UTF - 7 decoding function .
39,712
private function _sanitize_naughty_html ( $ str ) : string { $ evil_html_tags = \ implode ( '|' , $ this -> _evil_html_tags ) ; $ str = ( string ) \ preg_replace_callback ( '#<(?<start>/*\s*)(?<content>' . $ evil_html_tags . ')(?<end>[^><]*)(?<rest>[><]*)#ius' , function ( $ matches ) { return $ this -> _sanitize_naugh...
Sanitize naughty HTML elements .
39,713
public function addEvilAttributes ( array $ strings ) : self { $ this -> _evil_attributes_regex = \ array_merge ( $ strings , $ this -> _evil_attributes_regex ) ; return $ this ; }
Add some strings to the _evil_attributes - array .
39,714
public function addEvilHtmlTags ( array $ strings ) : self { $ this -> _evil_html_tags = \ array_merge ( $ strings , $ this -> _evil_html_tags ) ; return $ this ; }
Add some strings to the _evil_html_tags - array .
39,715
public function removeEvilAttributes ( array $ strings ) : self { $ this -> _evil_attributes_regex = \ array_diff ( $ this -> _evil_attributes_regex , \ array_intersect ( $ strings , $ this -> _evil_attributes_regex ) ) ; return $ this ; }
Remove some strings from the _evil_attributes - array .
39,716
public function removeEvilHtmlTags ( array $ strings ) : self { $ this -> _evil_html_tags = \ array_diff ( $ this -> _evil_html_tags , \ array_intersect ( $ strings , $ this -> _evil_html_tags ) ) ; return $ this ; }
Remove some strings from the _evil_html_tags - array .
39,717
public function setReplacement ( $ string ) : self { $ this -> _replacement = ( string ) $ string ; $ this -> _initNeverAllowedStr ( ) ; return $ this ; }
Set the replacement - string for not allowed strings .
39,718
public function createSecret ( $ bits = 80 , $ requirecryptosecure = true ) { $ secret = '' ; $ bytes = ceil ( $ bits / 5 ) ; $ rngprovider = $ this -> getRngprovider ( ) ; if ( $ requirecryptosecure && ! $ rngprovider -> isCryptographicallySecure ( ) ) throw new TwoFactorAuthException ( 'RNG provider is not cryptograp...
Create a new secret
39,719
public function getQRCodeImageAsDataUri ( $ label , $ secret , $ size = 200 ) { if ( ! is_int ( $ size ) || $ size <= 0 ) throw new TwoFactorAuthException ( 'Size must be int > 0' ) ; $ qrcodeprovider = $ this -> getQrCodeProvider ( ) ; return 'data:' . $ qrcodeprovider -> getMimeType ( ) . ';base64,' . base64_encode (...
Get data - uri of QRCode
39,720
public function getQRText ( $ label , $ secret ) { return 'otpauth://totp/' . rawurlencode ( $ label ) . '?secret=' . rawurlencode ( $ secret ) . '&issuer=' . rawurlencode ( $ this -> issuer ) . '&period=' . intval ( $ this -> period ) . '&algorithm=' . rawurlencode ( strtoupper ( $ this -> algorithm ) ) . '&digits=' ....
Builds a string to be encoded in a QR code
39,721
public static function getOptionsValidator ( array $ options ) { return function ( $ value ) use ( $ options ) { if ( ! in_array ( $ value , $ options ) ) { $ options_formatted = implode ( ', ' , $ options ) ; $ error_message = sprintf ( 'The value should be one of the following: %s.' , $ options_formatted ) ; throw ne...
Returns a validator for allowed options .
39,722
public static function moduleQuestions ( ) { $ questions [ 'name' ] = new Question ( 'Module name' ) ; $ questions [ 'name' ] -> setValidator ( [ Utils :: class , 'validateRequired' ] ) ; $ questions [ 'machine_name' ] = new Question ( 'Module machine name' ) ; $ questions [ 'machine_name' ] -> setValidator ( [ Utils :...
Returns default questions for module generators .
39,723
public static function pluginQuestions ( $ class_suffix = '' ) { $ questions [ 'plugin_label' ] = new Question ( 'Plugin label' , 'Example' ) ; $ questions [ 'plugin_label' ] -> setValidator ( [ Utils :: class , 'validateRequired' ] ) ; $ questions [ 'plugin_id' ] = new Question ( 'Plugin ID' , [ Utils :: class , 'defa...
Returns default questions for plugin generators .
39,724
public static function pluginClassQuestion ( $ suffix = '' ) { $ default_class = function ( $ vars ) use ( $ suffix ) { $ unprefixed_plugin_id = preg_replace ( '/^' . $ vars [ 'machine_name' ] . '_/' , '' , $ vars [ 'plugin_id' ] ) ; return Utils :: camelize ( $ unprefixed_plugin_id ) . $ suffix ; } ; return new Questi...
Creates plugin class question .
39,725
public static function getExtensionRoot ( $ directory ) { $ extension_root = FALSE ; for ( $ i = 1 ; $ i <= 5 ; $ i ++ ) { $ info_file = $ directory . '/' . basename ( $ directory ) . '.info' ; if ( ( file_exists ( $ info_file ) && basename ( $ directory ) !== 'drush' ) || file_exists ( $ info_file . '.yml' ) ) { $ ext...
Returns extension root .
39,726
public static function replaceTokens ( $ text , array $ data ) { $ tokens = [ ] ; foreach ( $ data as $ var_name => $ var ) { if ( is_string ( $ var ) ) { $ tokens [ '{' . $ var_name . '}' ] = $ var ; } } return str_replace ( array_keys ( $ tokens ) , array_values ( $ tokens ) , $ text ) ; }
Replaces all tokens in a given string with appropriate values .
39,727
public static function prepareChoices ( array $ raw_choices ) { $ choices = array_values ( $ raw_choices ) ; array_unshift ( $ choices , NULL ) ; unset ( $ choices [ 0 ] ) ; return $ choices ; }
Prepares choices .
39,728
protected function routeInteraction ( InputInterface $ input , OutputInterface $ output ) { $ vars = & $ this -> vars ; $ route_question = new ConfirmationQuestion ( 'Would you like to create a route for this form?' ) ; $ vars [ 'route' ] = $ this -> ask ( $ input , $ output , $ route_question ) ; $ raw_form_id = preg_...
Interacts with the user and builds route variables .
39,729
public function render ( Renderer $ renderer ) { if ( ! $ this -> isDirectory ( ) && is_null ( $ this -> getContent ( ) ) ) { $ content = '' ; if ( $ header_template = $ this -> getHeaderTemplate ( ) ) { $ content .= $ renderer -> render ( $ header_template , $ this -> getVars ( ) ) . "\n" ; } $ content .= $ renderer -...
Renders the asset template .
39,730
protected function setQuestionText ( Question $ question , $ question_text ) { if ( $ question instanceof ChoiceQuestion ) { $ question -> __construct ( $ question_text , $ question -> getChoices ( ) , $ question -> getDefault ( ) ) ; } else { $ question -> __construct ( $ question_text , $ question -> getDefault ( ) )...
Sets question text .
39,731
protected function setQuestionDefault ( Question $ question , $ default_value ) { if ( $ question instanceof ChoiceQuestion ) { $ question -> __construct ( $ question -> getQuestion ( ) , $ question -> getChoices ( ) , $ default_value ) ; } else { $ question -> __construct ( $ question -> getQuestion ( ) , $ default_va...
Sets question default value .
39,732
public function collectVars ( InputInterface $ input , OutputInterface $ output , array $ questions , array $ vars = [ ] ) { $ answers = NULL ; if ( $ answers_raw = $ input -> getOption ( 'answers' ) ) { $ answers = json_decode ( $ answers_raw , TRUE ) ; if ( ! is_array ( $ answers ) ) { throw new InvalidOptionExceptio...
Interacts with the user and returns variables for templates .
39,733
protected function normalizeQuestions ( array $ questions ) { return array_map ( function ( $ question ) { if ( is_array ( $ question ) ) { if ( count ( $ question ) > 2 ) { throw new \ OutOfBoundsException ( 'The question array is too long.' ) ; } list ( $ question_text , $ default_value ) = array_pad ( $ question , 2...
Normalizes questions .
39,734
public static function normalizePath ( $ path ) { $ parts = [ ] ; $ path = str_replace ( '\\' , '/' , $ path ) ; $ path = preg_replace ( '/\/+/' , '/' , $ path ) ; $ segments = explode ( '/' , $ path ) ; foreach ( $ segments as $ segment ) { if ( $ segment != '.' ) { $ test = array_pop ( $ parts ) ; if ( is_null ( $ te...
Returns normalized file path .
39,735
public function dump ( InputInterface $ input , OutputInterface $ output ) { $ this -> input = $ input ; $ this -> output = $ output ; $ formatter_style = new OutputFormatterStyle ( 'black' , 'cyan' , [ ] ) ; $ this -> output -> getFormatter ( ) -> setStyle ( 'title' , $ formatter_style ) ; $ interactive = $ input -> i...
Dumps the generated code to file system .
39,736
protected function doDump ( array $ assets , $ directory ) { $ dumped_files = [ ] ; foreach ( $ assets as $ asset ) { $ content = $ asset -> getContent ( ) ; $ path = $ asset -> getPath ( ) ; $ file_path = "$directory/$path" ; if ( $ this -> filesystem -> exists ( $ file_path ) && ! $ asset -> isDirectory ( ) ) { $ act...
Dumps assets .
39,737
protected function & collectVars ( InputInterface $ input , OutputInterface $ output , array $ questions , array $ vars = [ ] ) { $ this -> vars += $ this -> getHelper ( 'dcg_input_handler' ) -> collectVars ( $ input , $ output , $ questions , $ vars ) ; return $ this -> vars ; }
Asks the user for template variables .
39,738
protected function ask ( InputInterface $ input , OutputInterface $ output , Question $ question , array $ vars = [ ] ) { $ key = mt_rand ( ) ; $ answers = $ this -> getHelper ( 'dcg_input_handler' ) -> collectVars ( $ input , $ output , [ $ key => $ question ] , $ vars ) ; return $ answers [ $ key ] ; }
Asks the user a single question and returns the answer .
39,739
protected function addAsset ( $ type ) { $ asset = ( new Asset ( ) ) -> type ( $ type ) ; $ this -> assets [ ] = $ asset ; return $ asset ; }
Creates an asset .
39,740
protected function setFile ( $ path = NULL , $ template = NULL , array $ vars = [ ] ) { $ this -> addFile ( ) -> path ( $ path ) -> template ( $ template ) -> vars ( $ vars ) ; }
Creates file asset .
39,741
protected function setServicesFile ( $ path , $ template , array $ vars ) { $ this -> addServicesFile ( ) -> path ( $ path ) -> template ( $ template ) -> vars ( $ vars ) ; }
Creates service file asset .
39,742
protected function collectServices ( InputInterface $ input , OutputInterface $ output ) { $ service_definitions = self :: getServiceDefinitions ( ) ; $ service_ids = array_keys ( $ service_definitions ) ; $ services = [ ] ; while ( TRUE ) { $ question = new Question ( 'Type the service name or use arrows up/down. Pres...
Collects services .
39,743
public function getGenerators ( array $ command_directories , $ namespace = '\DrupalCodeGenerator\Command' ) { $ commands = [ ] ; foreach ( $ command_directories as $ directory ) { $ iterator = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ directory , RecursiveDirectoryIterator :: SKIP_DOTS ) ) ; f...
Finds and instantiates generator commands .
39,744
protected function createMenuItemLabel ( $ menu_item , $ comment ) { $ label = isset ( $ this -> labels [ $ menu_item ] ) ? $ this -> labels [ $ menu_item ] : str_replace ( [ '-' , '_' ] , ' ' , ucfirst ( $ menu_item ) ) ; return $ comment ? "<comment>$label</comment>" : $ label ; }
Creates a human readable label for a given menu item .
39,745
protected function supportedHooks ( ) { return array_map ( function ( $ file ) { return pathinfo ( $ file , PATHINFO_FILENAME ) ; } , array_diff ( scandir ( $ this -> templatePath . '/d8/hook' ) , [ '.' , '..' ] ) ) ; }
Returns list of supported hooks .
39,746
protected static function addPackage ( array & $ section , $ package ) { $ versions = [ 'composer/installers' => '^1.4' , 'cweagans/composer-patches' => '^1.6' , 'drupal-composer/drupal-scaffold' => '^2.5' , 'drupal/console' => '^1.0' , 'drupal/core' => self :: DRUPAL_DEFAULT_VERSION , 'drupal/drupal-extension' => '^3....
Requires a given package .
39,747
public function name ( $ nameOrInitials ) { $ nameOrInitials = $ this -> translate ( $ nameOrInitials ) ; $ this -> name = $ nameOrInitials ; $ this -> initials_generator -> name ( $ nameOrInitials ) ; return $ this ; }
Set the name used for generating initials .
39,748
public function glyph ( $ char ) { $ uChar = json_decode ( sprintf ( '"\u%s"' , $ char ) , false ) ; $ this -> name ( $ uChar ) ; return $ this ; }
Transforms a unicode string to the proper format
39,749
public function getInitials ( ) { return $ this -> initials_generator -> keepCase ( $ this -> getKeepCase ( ) ) -> name ( $ this -> name ) -> getInitials ( ) ; }
Will return the generated initials .
39,750
protected function getTranslator ( ) { if ( $ this -> translator instanceof Base && $ this -> translator -> getSourceLanguage ( ) === $ this -> language ) { return $ this -> translator ; } $ translatorClass = array_key_exists ( $ this -> language , $ this -> translatorMap ) ? $ this -> translatorMap [ $ this -> languag...
Instance the translator by language
39,751
public function findClasses ( $ directory ) { $ classes = [ ] ; foreach ( Finder :: create ( ) -> in ( $ directory ) -> name ( '*.php' ) as $ file ) { $ classes [ ] = $ this -> findClass ( $ file -> getRealPath ( ) ) ; } return array_filter ( $ classes ) ; }
Find all the class and interface names in a given directory .
39,752
public function findClass ( $ path ) { $ namespace = null ; $ tokens = token_get_all ( file_get_contents ( $ path ) ) ; foreach ( $ tokens as $ key => $ token ) { if ( $ this -> tokenIsNamespace ( $ token ) ) { $ namespace = $ this -> getNamespace ( $ key + 2 , $ tokens ) ; } elseif ( $ this -> tokenIsClassOrInterface ...
Extract the class name from the file at the given path .
39,753
protected function getClass ( $ key , array $ tokens ) { $ class = null ; $ tokenCount = count ( $ tokens ) ; for ( $ i = $ key ; $ i < $ tokenCount ; $ i ++ ) { if ( $ this -> isPartOfClass ( $ tokens [ $ i ] ) ) { $ class .= $ tokens [ $ i ] [ 1 ] ; } elseif ( $ this -> isWhitespace ( $ tokens [ $ i ] ) ) { return $ ...
Find the class in the tokens starting at a given key .
39,754
protected function middlewareAppliesToMethod ( $ method , array $ middleware ) { if ( ! empty ( $ middleware [ 'only' ] ) && ! in_array ( $ method , $ middleware [ 'only' ] ) ) { return false ; } elseif ( ! empty ( $ middleware [ 'except' ] ) && in_array ( $ method , $ middleware [ 'except' ] ) ) { return false ; } ret...
Determine if the middleware applies to a given method .
39,755
protected function implodeArray ( array $ array ) { $ results = [ ] ; foreach ( $ array as $ key => $ value ) { if ( is_string ( $ key ) ) { $ results [ ] = "'" . $ key . "' => '" . $ value . "'" ; } else { $ results [ ] = "'" . $ value . "'" ; } } return count ( $ results ) > 0 ? implode ( ', ' , $ results ) : '' ; }
Implode the given list into a comma separated string .
39,756
protected function extractFromEndpoints ( EndpointCollection $ endpoints , $ key ) { $ items = [ 'index' => [ ] , 'create' => [ ] , 'store' => [ ] , 'show' => [ ] , 'edit' => [ ] , 'update' => [ ] , 'destroy' => [ ] , ] ; foreach ( $ this -> getEndpointsWithResourceMethods ( $ endpoints , $ key ) as $ endpoint ) { $ it...
Extract method items from endpoints for the given key .
39,757
protected function getEndpointsWithResourceMethods ( EndpointCollection $ endpoints ) { return Collection :: make ( $ endpoints ) -> filter ( function ( $ endpoint ) { return $ endpoint instanceof MethodEndpoint && in_array ( $ endpoint -> method , $ this -> methods ) ; } ) -> all ( ) ; }
Get all of the resource method endpoints with pathless filters .
39,758
protected function getIncludedMethods ( ) { if ( $ this -> only ) { return $ this -> only ; } elseif ( $ this -> except ) { return array_diff ( $ this -> methods , $ this -> except ) ; } return $ this -> methods ; }
Get the methods to be included in the resource .
39,759
protected function getMiddleware ( ResourcePath $ path ) { $ classMiddleware = $ this -> getClassMiddlewareForPath ( $ path ) -> all ( ) ; return array_merge ( $ classMiddleware , array_get ( $ this -> middleware , $ path -> method , [ ] ) ) ; }
Get all of the middleware for the given path .
39,760
protected function getNames ( ResourcePath $ path ) { return isset ( $ this -> names [ $ path -> method ] ) ? [ $ path -> method => $ this -> names [ $ path -> method ] ] : [ ] ; }
Get the names for the given path .
39,761
public function getAllPaths ( ) { $ paths = [ ] ; foreach ( $ this as $ endpoint ) { foreach ( $ endpoint -> getPaths ( ) as $ path ) { $ paths [ ] = $ path ; } } return $ paths ; }
Get all of the paths for the given endpoint collection .
39,762
protected function getClassesToScan ( ) { $ classes = [ ] ; foreach ( $ this -> scan as $ class ) { try { $ classes [ ] = new ReflectionClass ( $ class ) ; } catch ( ReflectionException $ e ) { } } return $ classes ; }
Get all of the ReflectionClass instances in the scan array .
39,763
public function addAnnotationNamespace ( $ namespace , $ path = null ) { $ this -> namespaces [ ] = $ namespace ; return $ this -> registerAnnotationsPathWithRegistry ( $ path ? : $ this -> getPathFromNamespace ( $ namespace ) ) ; }
Add an annotation namespace for the SimpleAnnotationReader instance .
39,764
public function registerAnnotationsPathWithRegistry ( $ path ) { foreach ( Finder :: create ( ) -> files ( ) -> in ( $ path ) as $ file ) { AnnotationRegistry :: registerFile ( $ file -> getRealPath ( ) ) ; } return $ this ; }
Register the annotator files with the annotation registry .
39,765
public function getRouteDefinitionsDetail ( ) { $ paths = array ( ) ; foreach ( $ this -> getEndpointsInClasses ( $ this -> getReader ( ) ) as $ endpoint ) { foreach ( $ endpoint -> toRouteDefinitionDetail ( ) as $ path ) { $ paths [ ] = $ path ; } } return $ paths ; }
Give information about the scanned annotations related to route definition .
39,766
protected function getEndpointsInClasses ( SimpleAnnotationReader $ reader ) { $ endpoints = new EndpointCollection ( ) ; foreach ( $ this -> getClassesToScan ( ) as $ class ) { $ endpoints = $ endpoints -> merge ( $ this -> getEndpointsInClass ( $ class , new AnnotationSet ( $ class , $ reader ) ) ) ; } return $ endpo...
Scan the directory and generate the route manifest .
39,767
protected function getEndpointsInClass ( ReflectionClass $ class , AnnotationSet $ annotations ) { $ endpoints = new EndpointCollection ( ) ; foreach ( $ annotations -> method as $ method => $ methodAnnotations ) { $ this -> addEndpoint ( $ endpoints , $ class , $ method , $ methodAnnotations ) ; } foreach ( $ annotati...
Build the Endpoints for the given class .
39,768
protected function getMiddleware ( AbstractPath $ path ) { $ classMiddleware = $ this -> getClassMiddlewareForPath ( $ path ) -> all ( ) ; return $ this -> implodeArray ( array_merge ( $ classMiddleware , $ path -> middleware , $ this -> middleware ) ) ; }
Get the middleware for the path .
39,769
protected function getClassMiddlewareForPath ( AbstractPath $ path ) { return Collection :: make ( $ this -> classMiddleware ) -> filter ( function ( $ m ) { return $ this -> middlewareAppliesToMethod ( $ this -> method , $ m ) ; } ) -> map ( function ( $ m ) { return $ m [ 'name' ] ; } ) ; }
Get the class middleware for the given path .
39,770
public function boot ( ) { $ this -> addEventAnnotations ( $ this -> app -> make ( 'annotations.event.scanner' ) ) ; $ this -> loadAnnotatedEvents ( ) ; $ this -> addRoutingAnnotations ( $ this -> app -> make ( 'annotations.route.scanner' ) ) ; if ( ! $ this -> app -> routesAreCached ( ) ) { $ this -> loadAnnotatedRout...
Register the application s annotated event listeners .
39,771
protected function loadScannedRoutes ( ) { $ this -> app -> booted ( function ( ) { $ router = $ this -> app [ 'Illuminate\Contracts\Routing\Registrar' ] ; require $ this -> finder -> getScannedRoutesPath ( ) ; } ) ; }
Load the scanned application routes .
39,772
protected function loadAnnotatedModels ( ) { if ( $ this -> app -> environment ( 'local' ) && $ this -> scanWhenLocal ) { $ this -> scanModels ( ) ; } $ scans = $ this -> modelScans ( ) ; if ( ! empty ( $ scans ) && $ this -> finder -> modelsAreScanned ( ) ) { $ this -> loadScannedModels ( ) ; } }
Load the annotated models .
39,773
protected function scanModels ( ) { $ scans = $ this -> modelScans ( ) ; if ( empty ( $ scans ) ) { return ; } $ scanner = $ this -> app -> make ( 'annotations.model.scanner' ) ; $ scanner -> setClassesToScan ( $ scans ) ; file_put_contents ( $ this -> finder -> getScannedModelsPath ( ) , '<?php ' . $ scanner -> getMod...
Scan the models and write the scanned models file .
39,774
protected function loadScannedModels ( ) { $ this -> app -> booted ( function ( ) { $ router = $ this -> app [ 'Illuminate\Contracts\Routing\Registrar' ] ; require $ this -> finder -> getScannedModelsPath ( ) ; } ) ; }
Load the scanned application models .
39,775
public function routeScans ( ) { if ( $ this -> scanEverything ) { return $ this -> getAllClasses ( ) ; } $ classes = $ this -> scanRoutes ; if ( $ this -> scanControllers ) { $ classes = array_merge ( $ classes , $ this -> getClassesFromNamespace ( $ this -> getAppNamespace ( ) . 'Http\\Controllers' ) ) ; } return $ c...
Get the classes to be scanned by the provider .
39,776
public function getClassesFromNamespace ( $ namespace , $ base = null ) { $ directory = ( $ base ? : $ this -> app -> make ( 'path' ) ) . '/' . $ this -> convertNamespaceToPath ( $ namespace ) ; return $ this -> app -> make ( 'Collective\Annotations\Filesystem\ClassFinder' ) -> findClasses ( $ directory ) ; }
Get a list of the classes in a namespace . Leaving the second argument will scan for classes within the project s app directory .
39,777
protected function prefixEndpoints ( EndpointCollection $ endpoints ) { foreach ( $ endpoints -> getAllPaths ( ) as $ path ) { $ path -> path = $ this -> trimPath ( $ this -> prefix , $ path -> path ) ; } }
Set the prefixes on the endpoints .
39,778
protected function setEndpointDomains ( EndpointCollection $ endpoints ) { foreach ( $ endpoints -> getAllPaths ( ) as $ path ) { if ( is_null ( $ path -> domain ) ) { $ path -> domain = $ this -> domain ; } } }
Set the domain on the endpoints .
39,779
public function locate ( $ key ) { if ( array_key_exists ( $ key , $ this -> cache ) ) { return $ this -> cache [ $ key ] [ 'found' ] ; } if ( $ this -> locateLocal ( $ key ) ) { return true ; } if ( $ this -> locateGlobal ( $ key ) ) { return true ; } $ this -> cache [ $ key ] = [ 'found' => false , 'config' => [ ] , ...
Try to locate where is the config for the given key .
39,780
private function locateLocal ( $ key ) { $ composerConfig = $ this -> composer -> getConfig ( ) ; $ reflection = new \ ReflectionClass ( $ composerConfig ) ; $ property = $ reflection -> getProperty ( 'baseDir' ) ; $ property -> setAccessible ( true ) ; $ path = $ property -> getValue ( $ composerConfig ) ; $ localComp...
Search config in the local root package .
39,781
private function locateGlobal ( $ key ) { $ path = $ this -> composer -> getConfig ( ) -> get ( 'home' ) ; $ globalComposerJsonFile = $ path . '/composer.json' ; if ( file_exists ( $ globalComposerJsonFile ) ) { $ globalComposerJson = json_decode ( file_get_contents ( $ globalComposerJsonFile ) , true ) ; if ( array_ke...
Search config in the global root package .
39,782
protected function generateBaseUrl ( $ sourceUrl ) { if ( $ this -> isSshUrl ( $ sourceUrl ) ) { return $ this -> transformSshUrlIntoHttp ( $ sourceUrl ) ; } $ sourceUrl = parse_url ( $ sourceUrl ) ; $ pos = strrpos ( $ sourceUrl [ 'path' ] , '.git' ) ; return sprintf ( '%s://%s%s' , $ sourceUrl [ 'scheme' ] , $ source...
Generates the canonical http url for a repository .
39,783
protected function getCompareVersion ( Version $ version ) { if ( $ version -> isDev ( ) ) { return substr ( $ version -> getFullPretty ( ) , strlen ( $ version -> getPretty ( ) ) + 1 ) ; } return $ version -> getPretty ( ) ; }
Get the version to use for the compare url .
39,784
protected function extractRepositoryInformation ( $ sourceUrl ) { $ pattern = '#' . $ this -> getDomain ( ) . '/' . self :: REGEX_USER . '/' . self :: REGEX_REPOSITORY . '#' ; preg_match ( $ pattern , $ sourceUrl , $ matches ) ; if ( ! isset ( $ matches [ 'user' ] ) || ! isset ( $ matches [ 'repository' ] ) ) { throw n...
Extracts information like user and repository from the http url .
39,785
private function transformSshUrlIntoHttp ( $ url ) { $ pattern = '#git@' . $ this -> getDomain ( ) . ':' . self :: REGEX_USER . '/' . self :: REGEX_REPOSITORY . '.git$#' ; if ( preg_match ( $ pattern , $ url , $ matches ) ) { return sprintf ( 'https://%s/%s/%s' , $ this -> getDomain ( ) , $ matches [ 'user' ] , $ match...
Transform an ssh git url into an http one .
39,786
public function list_ ( $ args , $ assoc_args ) { $ formatter = $ this -> get_formatter ( $ assoc_args ) ; $ events = self :: get_cron_events ( ) ; if ( is_wp_error ( $ events ) ) { $ events = array ( ) ; } foreach ( $ events as $ key => $ event ) { foreach ( $ this -> fields as $ field ) { if ( ! empty ( $ assoc_args ...
Lists scheduled cron events .
39,787
public function schedule ( $ args , $ assoc_args ) { $ hook = $ args [ 0 ] ; $ next_run = Utils \ get_flag_value ( $ args , 1 , 'now' ) ; $ recurrence = Utils \ get_flag_value ( $ args , 2 , false ) ; if ( empty ( $ next_run ) ) { $ timestamp = time ( ) ; } elseif ( is_numeric ( $ next_run ) ) { $ timestamp = absint ( ...
Schedules a new cron event .
39,788
public function run ( $ args , $ assoc_args ) { if ( empty ( $ args ) && ! Utils \ get_flag_value ( $ assoc_args , 'due-now' ) && ! Utils \ get_flag_value ( $ assoc_args , 'all' ) ) { WP_CLI :: error ( 'Please specify one or more cron events, or use --due-now/--all.' ) ; } $ events = self :: get_cron_events ( ) ; if ( ...
Runs the next scheduled cron event for the given hook .
39,789
protected static function run_event ( stdClass $ event ) { if ( ! defined ( 'DOING_CRON' ) ) { define ( 'DOING_CRON' , true ) ; } if ( false !== $ event -> schedule ) { $ new_args = array ( $ event -> time , $ event -> schedule , $ event -> hook , $ event -> args ) ; call_user_func_array ( 'wp_reschedule_event' , $ new...
Executes an event immediately .
39,790
public function delete ( $ args , $ assoc_args ) { $ hook = $ args [ 0 ] ; $ events = self :: get_cron_events ( ) ; if ( is_wp_error ( $ events ) ) { WP_CLI :: error ( $ events ) ; } $ deleted = 0 ; foreach ( $ events as $ event ) { if ( $ event -> hook === $ hook ) { $ result = self :: delete_event ( $ event ) ; if ( ...
Deletes the next scheduled cron event for the given hook .
39,791
protected static function delete_event ( stdClass $ event ) { $ crons = _get_cron_array ( ) ; if ( ! isset ( $ crons [ $ event -> time ] [ $ event -> hook ] [ $ event -> sig ] ) ) { return false ; } wp_unschedule_event ( $ event -> time , $ event -> hook , $ event -> args ) ; return true ; }
Deletes a cron event .
39,792
protected static function format_event ( stdClass $ event ) { $ event -> next_run = get_date_from_gmt ( date ( 'Y-m-d H:i:s' , $ event -> time ) , self :: $ time_format ) ; $ event -> next_run_gmt = date ( self :: $ time_format , $ event -> time ) ; $ event -> next_run_relative = self :: interval ( $ event -> time - ti...
Callback function to format a cron event .
39,793
protected static function get_cron_events ( ) { $ crons = _get_cron_array ( ) ; $ events = array ( ) ; if ( empty ( $ crons ) ) { return new WP_Error ( 'no_events' , 'You currently have no scheduled cron events.' ) ; } foreach ( $ crons as $ time => $ hooks ) { foreach ( $ hooks as $ hook => $ hook_events ) { foreach (...
Fetches an array of scheduled cron events .
39,794
private static function interval ( $ since ) { if ( $ since <= 0 ) { return 'now' ; } $ since = absint ( $ since ) ; $ chunks = array ( array ( 60 * 60 * 24 * 365 , 'year' ) , array ( 60 * 60 * 24 * 30 , 'month' ) , array ( 60 * 60 * 24 * 7 , 'week' ) , array ( 60 * 60 * 24 , 'day' ) , array ( 60 * 60 , 'hour' ) , arra...
Converts a time interval into human - readable format .
39,795
public function list_ ( $ args , $ assoc_args ) { $ formatter = $ this -> get_formatter ( $ assoc_args ) ; $ schedules = self :: get_schedules ( ) ; if ( 'ids' === $ formatter -> format ) { echo implode ( ' ' , wp_list_pluck ( $ schedules , 'name' ) ) ; } else { $ formatter -> display_items ( $ schedules ) ; } }
List available cron schedules .
39,796
protected static function get_schedules ( ) { $ schedules = wp_get_schedules ( ) ; if ( ! empty ( $ schedules ) ) { uasort ( $ schedules , 'Cron_Schedule_Command::sort' ) ; $ schedules = array_map ( 'Cron_Schedule_Command::format_schedule' , $ schedules , array_keys ( $ schedules ) ) ; } return $ schedules ; }
Return a list of the cron schedules sorted according to interval .
39,797
protected static function get_cron_spawn ( ) { $ sslverify = \ WP_CLI \ Utils \ wp_version_compare ( 4.0 , '<' ) ; $ doing_wp_cron = sprintf ( '%.22F' , microtime ( true ) ) ; $ cron_request_array = array ( 'url' => site_url ( 'wp-cron.php?doing_wp_cron=' . $ doing_wp_cron ) , 'key' => $ doing_wp_cron , 'args' => array...
Spawns a request to wp - cron . php and return the response .
39,798
public function getTabsForElement ( $ elementClass ) { if ( null !== ( $ tabs = $ this -> getCache ( ) -> get ( $ this -> getCacheKey ( $ elementClass ) ) ) ) { return $ tabs ; } return $ this -> generateTabsForElement ( $ elementClass ) ; }
Get the top level tab names for the given element class
39,799
public static function flush ( ) { $ self = singleton ( static :: class ) ; $ self -> getCache ( ) -> clear ( ) ; if ( $ self -> config ( ) -> get ( 'regenerate_on_flush' ) ) { $ self -> generateAllTabs ( ) ; } }
This function is triggered early in the request if the flush query parameter has been set . Each class that implements Flushable implements this function which looks after it s own specific flushing functionality .