idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
803
4,000
protected function recurseArrayForTokens ( $ arr , $ tokens ) { $ out = [ ] ; foreach ( $ arr as $ name => $ value ) { if ( is_array ( $ value ) ) { $ out [ $ name ] = $ this -> recurseArrayForTokens ( $ value , $ tokens ) ; continue ; } if ( is_string ( $ value ) ) { foreach ( $ tokens as $ token => $ tval ) { $ value...
Recurse an array for the specified tokens and replace them .
4,001
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ this -> bootstrap ( $ input , $ output ) ; $ version = $ input -> getOption ( 'target' ) ; $ environment = $ input -> getOption ( 'environment' ) ; $ date = $ input -> getOption ( 'date' ) ; $ fake = ( bool ) $ input -> getOption ( 'fa...
Migrate the database .
4,002
protected function verboseLog ( $ message ) { if ( ! $ this -> isDryRunEnabled ( ) && $ this -> getOutput ( ) -> getVerbosity ( ) < OutputInterface :: VERBOSITY_VERY_VERBOSE ) { return ; } $ this -> getOutput ( ) -> writeln ( $ message ) ; }
Writes a message to stdout if verbose output is on
4,003
private function quoteValue ( $ value ) { if ( is_numeric ( $ value ) ) { return $ value ; } if ( $ value === null ) { return 'null' ; } return $ this -> getConnection ( ) -> quote ( $ value ) ; }
Quotes a database value .
4,004
protected function executeAlterSteps ( $ tableName , AlterInstructions $ instructions ) { $ alter = sprintf ( 'ALTER TABLE %s %%s' , $ this -> quoteTableName ( $ tableName ) ) ; $ instructions -> execute ( $ alter , [ $ this , 'execute' ] ) ; }
Executes all the ALTER TABLE instructions passed for the given table
4,005
public function merge ( Intent $ another ) { $ this -> actions = array_merge ( $ this -> actions , $ another -> getActions ( ) ) ; }
Merges another Intent object with this one
4,006
public function changePrimaryKey ( $ columns ) { $ this -> actions -> addAction ( new ChangePrimaryKey ( $ this -> table , $ columns ) ) ; return $ this ; }
Changes the primary key of the database table .
4,007
public function changeComment ( $ comment ) { $ this -> actions -> addAction ( new ChangeComment ( $ this -> table , $ comment ) ) ; return $ this ; }
Changes the comment of the database table .
4,008
public function getColumn ( $ name ) { $ columns = array_filter ( $ this -> getColumns ( ) , function ( $ column ) use ( $ name ) { return $ column -> getName ( ) === $ name ; } ) ; return array_pop ( $ columns ) ; }
Gets a table column if it exists .
4,009
public function removeColumn ( $ columnName ) { $ action = RemoveColumn :: build ( $ this -> table , $ columnName ) ; $ this -> actions -> addAction ( $ action ) ; return $ this ; }
Remove a table column .
4,010
public function removeIndex ( $ columns ) { $ action = DropIndex :: build ( $ this -> table , is_string ( $ columns ) ? [ $ columns ] : $ columns ) ; $ this -> actions -> addAction ( $ action ) ; return $ this ; }
Removes the given index from a table .
4,011
public function removeIndexByName ( $ name ) { $ action = DropIndex :: buildFromName ( $ this -> table , $ name ) ; $ this -> actions -> addAction ( $ action ) ; return $ this ; }
Removes the given index identified by its name from a table .
4,012
public function addForeignKeyWithName ( $ name , $ columns , $ referencedTable , $ referencedColumns = [ 'id' ] , $ options = [ ] ) { $ action = AddForeignKey :: build ( $ this -> table , $ columns , $ referencedTable , $ referencedColumns , $ options , $ name ) ; $ this -> actions -> addAction ( $ action ) ; return $ ...
Add a foreign key to a database table with a given name .
4,013
public function hasForeignKey ( $ columns , $ constraint = null ) { return $ this -> getAdapter ( ) -> hasForeignKey ( $ this -> getName ( ) , $ columns , $ constraint ) ; }
Checks to see if a foreign key exists .
4,014
protected function executeActions ( $ exists ) { $ renamed = collection ( $ this -> actions -> getActions ( ) ) -> filter ( function ( $ action ) { return $ action instanceof RenameTable ; } ) -> first ( ) ; if ( $ renamed ) { $ exists = true ; } if ( ! $ exists ) { $ this -> actions -> addAction ( new CreateTable ( $ ...
Executes all the pending actions for this table
4,015
public static function build ( Table $ table , $ columns , $ constraint = null ) { if ( is_string ( $ columns ) ) { $ columns = [ $ columns ] ; } $ foreignKey = new ForeignKey ( ) ; $ foreignKey -> setColumns ( $ columns ) ; if ( $ constraint ) { $ foreignKey -> setConstraint ( $ constraint ) ; } return new static ( $ ...
Creates a new DropForeignKey object after building the ForeignKey definition out of the passed arguments .
4,016
public function add ( $ key , $ value ) { $ array = array_get ( $ this -> configs , $ key ) ; if ( is_array ( $ array ) ) { $ array [ ] = $ value ; array_set ( $ this -> configs , $ key , $ array ) ; } return $ this ; }
Append the given value to the configuration array at the given key .
4,017
public function useForge ( $ phpVersion = self :: DEFAULT_PHP_VERSION ) { $ this -> reloadFpm ( $ phpVersion ) ; $ this -> setHost ( 'deploy_path' , '/home/forge/' . $ this -> getHostname ( ) ) ; $ this -> setHost ( 'user' , 'forge' ) ; return $ this ; }
Set up defaults values more suitable for forge servers .
4,018
public function store ( $ path = 'config' . DIRECTORY_SEPARATOR . 'deploy.php' ) { $ path = base_path ( $ path ) ; if ( ! is_dir ( dirname ( $ path ) ) ) { mkdir ( dirname ( $ path ) , 0777 , true ) ; } $ this -> filesystem -> put ( $ path , ( string ) $ this ) ; return $ path ; }
Parse the config . stub file and copy its content onto a new deploy . php file in the config folder of the Laravel project .
4,019
protected function _base32Decode ( $ secret ) { if ( empty ( $ secret ) ) { return '' ; } $ base32chars = $ this -> _getBase32LookupTable ( ) ; $ base32charsFlipped = array_flip ( $ base32chars ) ; $ paddingCharCount = substr_count ( $ secret , $ base32chars [ 32 ] ) ; $ allowedValues = array ( 6 , 4 , 3 , 1 , 0 ) ; if...
Helper class to decode base32 .
4,020
public function getAllTables ( ) { return $ this -> connection -> select ( $ this -> grammar -> compileGetAllTables ( $ this -> connection -> getConfig ( 'schema' ) ) ) ; }
Get all of the table names for the database .
4,021
public function eachById ( callable $ callback , $ count = 1000 , $ column = null , $ alias = null ) { return $ this -> chunkById ( $ count , function ( $ results ) use ( $ callback ) { foreach ( $ results as $ key => $ value ) { if ( $ callback ( $ value , $ key ) === false ) { return false ; } } } , $ column , $ alia...
Execute a callback over each item while chunking by id .
4,022
public function createMany ( iterable $ records ) { $ instances = $ this -> related -> newCollection ( ) ; foreach ( $ records as $ record ) { $ instances -> push ( $ this -> create ( $ record ) ) ; } return $ instances ; }
Create a Collection of new instances of the related model .
4,023
public function fromSub ( $ query , $ as ) { [ $ query , $ bindings ] = $ this -> createSub ( $ query ) ; return $ this -> fromRaw ( '(' . $ query . ') as ' . $ this -> grammar -> wrap ( $ as ) , $ bindings ) ; }
Makes from fetch from a subquery .
4,024
public function joinSub ( $ query , $ as , $ first , $ operator = null , $ second = null , $ type = 'inner' , $ where = false ) { [ $ query , $ bindings ] = $ this -> createSub ( $ query ) ; $ expression = '(' . $ query . ') as ' . $ this -> grammar -> wrap ( $ as ) ; $ this -> addBinding ( $ bindings , 'join' ) ; retu...
Add a subquery join clause to the query .
4,025
public function setOptions ( array $ options ) { foreach ( $ options as $ name => $ value ) { $ this -> setOption ( $ name , $ value ) ; } }
Sets an array of options .
4,026
public function getCommand ( $ input , $ output , array $ options = [ ] ) { $ options = $ this -> mergeOptions ( $ options ) ; return $ this -> buildCommand ( $ this -> binary , $ input , $ output , $ options ) ; }
Returns the command for the given input and output files .
4,027
protected function mergeOptions ( array $ options ) { $ mergedOptions = $ this -> options ; foreach ( $ options as $ name => $ value ) { if ( ! array_key_exists ( $ name , $ mergedOptions ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The option \'%s\' does not exist.' , $ name ) ) ; } $ mergedOptions [ $ name...
Merges the given array of options to the instance options and returns the result options array . It does NOT change the instance options .
4,028
protected function checkOutput ( $ output , $ command ) { if ( ! $ this -> fileExists ( $ output ) ) { throw new \ RuntimeException ( sprintf ( 'The file \'%s\' was not created (command: %s).' , $ output , $ command ) ) ; } if ( 0 === $ this -> filesize ( $ output ) ) { throw new \ RuntimeException ( sprintf ( 'The fil...
Checks the specified output .
4,029
protected function buildCommand ( $ binary , $ input , $ output , array $ options = [ ] ) { $ command = $ binary ; $ escapedBinary = escapeshellarg ( $ binary ) ; if ( is_executable ( $ escapedBinary ) ) { $ command = $ escapedBinary ; } foreach ( $ options as $ key => $ option ) { if ( null !== $ option && false !== $...
Builds the command string .
4,030
protected function executeCommand ( $ command ) { if ( method_exists ( Process :: class , 'fromShellCommandline' ) ) { $ process = Process :: fromShellCommandline ( $ command , null , $ this -> env ) ; } else { $ process = new Process ( $ command , null , $ this -> env ) ; } if ( false !== $ this -> timeout ) { $ proce...
Executes the given command via shell and returns the complete output as a string .
4,031
protected function prepareOutput ( $ filename , $ overwrite ) { $ directory = dirname ( $ filename ) ; if ( $ this -> fileExists ( $ filename ) ) { if ( ! $ this -> isFile ( $ filename ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The output file \'%s\' already exists and it is a %s.' , $ filename , $ this ->...
Prepares the specified output .
4,032
protected function handleOptions ( array $ options = [ ] ) { foreach ( $ options as $ option => $ value ) { if ( null === $ value ) { unset ( $ options [ $ option ] ) ; continue ; } if ( ! empty ( $ value ) && array_key_exists ( $ option , $ this -> optionsWithContentCheck ) ) { $ saveToTempFile = ! $ this -> isFile ( ...
Handle options to transform HTML strings into temporary files containing HTML .
4,033
public function listWith ( array $ keys = [ ] , $ directory = '' , $ recursive = false ) { list ( $ prefix , $ directory ) = $ this -> getPrefixAndPath ( $ directory ) ; $ arguments = [ $ keys , $ directory , $ recursive ] ; return $ this -> invokePluginOnFilesystem ( 'listWith' , $ arguments , $ prefix ) ; }
List with plugin adapter .
4,034
public function invokePluginOnFilesystem ( $ method , $ arguments , $ prefix ) { $ filesystem = $ this -> getFilesystem ( $ prefix ) ; try { return $ this -> invokePlugin ( $ method , $ arguments , $ filesystem ) ; } catch ( PluginNotFoundException $ e ) { } $ callback = [ $ filesystem , $ method ] ; return call_user_f...
Invoke a plugin on a filesystem mounted on a given prefix .
4,035
public function get ( $ key , $ default = null ) { if ( ! array_key_exists ( $ key , $ this -> settings ) ) { return $ this -> getDefault ( $ key , $ default ) ; } return $ this -> settings [ $ key ] ; }
Get a setting .
4,036
public function has ( $ key ) { if ( array_key_exists ( $ key , $ this -> settings ) ) { return true ; } return $ this -> fallback instanceof Config ? $ this -> fallback -> has ( $ key ) : false ; }
Check if an item exists by key .
4,037
private function residesInDirectory ( array $ entry ) { if ( $ this -> directory === '' ) { return true ; } return $ this -> caseSensitive ? strpos ( $ entry [ 'path' ] , $ this -> directory . '/' ) === 0 : stripos ( $ entry [ 'path' ] , $ this -> directory . '/' ) === 0 ; }
Check if the entry resides within the parent directory .
4,038
private function isDirectChild ( array $ entry ) { return $ this -> caseSensitive ? $ entry [ 'dirname' ] === $ this -> directory : strcasecmp ( $ this -> directory , $ entry [ 'dirname' ] ) === 0 ; }
Check if the entry is a direct child of the directory .
4,039
public static function pathinfo ( $ path ) { $ pathinfo = compact ( 'path' ) ; if ( '' !== $ dirname = dirname ( $ path ) ) { $ pathinfo [ 'dirname' ] = static :: normalizeDirname ( $ dirname ) ; } $ pathinfo [ 'basename' ] = static :: basename ( $ path ) ; $ pathinfo += pathinfo ( $ pathinfo [ 'basename' ] ) ; return ...
Get normalized pathinfo .
4,040
public static function map ( array $ object , array $ map ) { $ result = [ ] ; foreach ( $ map as $ from => $ to ) { if ( ! isset ( $ object [ $ from ] ) ) { continue ; } $ result [ $ to ] = $ object [ $ from ] ; } return $ result ; }
Map result arrays .
4,041
public static function ensureConfig ( $ config ) { if ( $ config === null ) { return new Config ( ) ; } if ( $ config instanceof Config ) { return $ config ; } if ( is_array ( $ config ) ) { return new Config ( $ config ) ; } throw new LogicException ( 'A config should either be an array or a Flysystem\Config object.' ...
Ensure a Config instance .
4,042
private static function basename ( $ path ) { $ separators = DIRECTORY_SEPARATOR === '/' ? '/' : '\/' ; $ path = rtrim ( $ path , $ separators ) ; $ basename = preg_replace ( '#.*?([^' . preg_quote ( $ separators , '#' ) . ']+$)#' , '$1' , $ path ) ; if ( DIRECTORY_SEPARATOR === '/' ) { return $ basename ; } while ( pr...
Returns the trailing name component of the path .
4,043
protected function setUtf8Mode ( ) { if ( $ this -> utf8 ) { $ response = ftp_raw ( $ this -> connection , "OPTS UTF8 ON" ) ; if ( substr ( $ response [ 0 ] , 0 , 3 ) !== '200' ) { throw new RuntimeException ( 'Could not set UTF-8 mode for connection: ' . $ this -> getHost ( ) . '::' . $ this -> getPort ( ) ) ; } } }
Set the connection to UTF - 8 mode .
4,044
protected function ftpRawlist ( $ options , $ path ) { $ connection = $ this -> getConnection ( ) ; if ( $ this -> isPureFtpd ) { $ path = str_replace ( ' ' , '\ ' , $ path ) ; } return ftp_rawlist ( $ connection , $ options . ' ' . $ path ) ; }
The ftp_rawlist function with optional escaping .
4,045
protected function prepareConfig ( array $ config ) { $ config = new Config ( $ config ) ; $ config -> setFallback ( $ this -> getConfig ( ) ) ; return $ config ; }
Convert a config array to a Config object with the correct fallback .
4,046
protected function findPlugin ( $ method ) { if ( ! isset ( $ this -> plugins [ $ method ] ) ) { throw new PluginNotFoundException ( 'Plugin not found for method: ' . $ method ) ; } return $ this -> plugins [ $ method ] ; }
Find a specific plugin .
4,047
protected function invokePlugin ( $ method , array $ arguments , FilesystemInterface $ filesystem ) { $ plugin = $ this -> findPlugin ( $ method ) ; $ plugin -> setFilesystem ( $ filesystem ) ; $ callback = [ $ plugin , 'handle' ] ; return call_user_func_array ( $ callback , $ arguments ) ; }
Invoke a plugin by method name .
4,048
public function writeStream ( $ path , $ resource , Config $ config ) { return $ this -> stream ( $ path , $ resource , $ config , 'write' ) ; }
Write using a stream .
4,049
protected function addUserIdentityToPayload ( UserInterface $ user , array & $ payload ) { $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; $ payload [ $ this -> userIdClaim ? : $ this -> userIdentityField ] = $ accessor -> getValue ( $ user , $ this -> userIdentityField ) ; }
Add user identity to payload username by default . Override this if you need to identify it by another property .
4,050
private function checkExpiration ( ) { if ( ! $ this -> hasLifetime ) { return ; } if ( ! isset ( $ this -> payload [ 'exp' ] ) || ! is_numeric ( $ this -> payload [ 'exp' ] ) ) { return $ this -> state = self :: INVALID ; } if ( $ this -> clockSkew <= ( new \ DateTime ( ) ) -> format ( 'U' ) - $ this -> payload [ 'exp...
Ensures that the signature is not expired .
4,051
private function checkIssuedAt ( ) { if ( isset ( $ this -> payload [ 'iat' ] ) && ( int ) $ this -> payload [ 'iat' ] - $ this -> clockSkew > time ( ) ) { return $ this -> state = self :: INVALID ; } }
Ensures that the iat claim is not in the future .
4,052
protected function createEntryPoint ( ContainerBuilder $ container , $ id , $ defaultEntryPoint ) { $ entryPointId = 'lexik_jwt_authentication.security.authentication.entry_point.' . $ id ; $ container -> setDefinition ( $ entryPointId , $ this -> createChildDefinition ( 'lexik_jwt_authentication.security.authenticatio...
Create an entry point by default it sends a 401 header and ends the request .
4,053
public function removeExtractor ( \ Closure $ filter ) { $ filtered = array_filter ( $ this -> map , $ filter ) ; if ( ! $ extractorToUnmap = current ( $ filtered ) ) { return false ; } $ key = array_search ( $ extractorToUnmap , $ this -> map ) ; unset ( $ this -> map [ $ key ] ) ; return true ; }
Removes a token extractor from the map .
4,054
public function getCredentials ( Request $ request ) { $ tokenExtractor = $ this -> getTokenExtractor ( ) ; if ( ! $ tokenExtractor instanceof TokenExtractorInterface ) { throw new \ RuntimeException ( sprintf ( 'Method "%s::getTokenExtractor()" must return an instance of "%s".' , __CLASS__ , TokenExtractorInterface ::...
Returns a decoded JWT token extracted from a request .
4,055
public function getUser ( $ preAuthToken , UserProviderInterface $ userProvider ) { if ( ! $ preAuthToken instanceof PreAuthenticationJWTUserToken ) { throw new \ InvalidArgumentException ( sprintf ( 'The first argument of the "%s()" method must be an instance of "%s".' , __METHOD__ , PreAuthenticationJWTUserToken :: c...
Returns an user object loaded from a JWT token .
4,056
protected function loadUser ( UserProviderInterface $ userProvider , array $ payload , $ identity ) { if ( $ userProvider instanceof PayloadAwareUserProviderInterface ) { return $ userProvider -> loadUserByUsernameAndPayload ( $ identity , $ payload ) ; } return $ userProvider -> loadUserByUsername ( $ identity ) ; }
Loads the user to authenticate .
4,057
protected function getUserFromPayload ( array $ payload ) { if ( ! isset ( $ payload [ $ this -> userIdClaim ] ) ) { throw $ this -> createAuthenticationException ( ) ; } return $ this -> userProvider -> loadUserByUsername ( $ payload [ $ this -> userIdClaim ] ) ; }
Load user from payload using username by default . Override this to load by another property .
4,058
private function removeTrailingWhitespaces ( string $ diff ) : string { $ diff = Strings :: replace ( $ diff , '#( ){1,}\n#' , PHP_EOL ) ; return rtrim ( $ diff ) ; }
Removes UnifiedDiffOutputBuilder generated pre - spaces \ n = > \ n
4,059
public function resolveFromInput ( InputInterface $ input ) : void { $ this -> isDryRun = ( bool ) $ input -> getOption ( Option :: OPTION_DRY_RUN ) ; $ this -> source = ( array ) $ input -> getArgument ( Option :: SOURCE ) ; $ this -> hideAutoloadErrors = ( bool ) $ input -> getOption ( Option :: HIDE_AUTOLOAD_ERRORS ...
Needs to run in the start of the life cycle since the rest of workflow uses it .
4,060
private function configureEnabledRectorsOnly ( ) : void { $ this -> visitors = [ ] ; $ enabledRectors = $ this -> enabledRectorsProvider -> getEnabledRectors ( ) ; foreach ( $ enabledRectors as $ enabledRector => $ configuration ) { foreach ( $ this -> allPhpRectors as $ phpRector ) { if ( ! is_a ( $ phpRector , $ enab...
Mostly used for testing
4,061
private function createCreateMockCall ( Param $ param , Name $ name ) : ? Expression { $ classNode = $ param -> getAttribute ( AttributeKey :: CLASS_NODE ) ; $ classMocks = $ this -> phpSpecMockCollector -> resolveClassMocksFromParam ( $ classNode ) ; $ variable = $ this -> getName ( $ param -> var ) ; $ method = $ par...
Variable or property fetch based on number of present params in whole class
4,062
private function setPositionOfLastToken ( AttributeAwarePhpDocNode $ attributeAwarePhpDocNode ) : AttributeAwarePhpDocNode { if ( $ attributeAwarePhpDocNode -> children === [ ] ) { return $ attributeAwarePhpDocNode ; } $ phpDocChildNodes = $ attributeAwarePhpDocNode -> children ; $ lastChildNode = array_pop ( $ phpDocC...
Needed for printing
4,063
private function resolveConfiguration ( RectorInterface $ rector ) : array { $ rectorReflection = new ReflectionClass ( $ rector ) ; $ constructorReflection = $ rectorReflection -> getConstructor ( ) ; if ( $ constructorReflection === null ) { return [ ] ; } $ configuration = [ ] ; foreach ( $ constructorReflection -> ...
Resolve configuration by convention
4,064
public function resolvePropertyTypeInfo ( Property $ property ) : ? VarTypeInfo { $ types = [ ] ; $ propertyDefault = $ property -> props [ 0 ] -> default ; if ( $ propertyDefault !== null ) { $ types [ ] = $ this -> nodeToStringTypeResolver -> resolver ( $ propertyDefault ) ; } $ classNode = $ property -> getAttribute...
Based on static analysis of code looking for property assigns
4,065
public function getParamTypeInfos ( Node $ node ) : array { if ( $ node -> getDocComment ( ) === null ) { return [ ] ; } $ phpDocInfo = $ this -> createPhpDocInfoFromNode ( $ node ) ; $ types = $ phpDocInfo -> getParamTagValues ( ) ; if ( $ types === [ ] ) { return [ ] ; } $ fqnTypes = $ phpDocInfo -> getParamTagValues...
With name as key
4,066
protected function pScalar_String ( String_ $ node ) : string { $ kind = $ node -> getAttribute ( 'kind' , String_ :: KIND_SINGLE_QUOTED ) ; if ( $ kind === String_ :: KIND_DOUBLE_QUOTED && $ node -> getAttribute ( 'is_regular_pattern' ) ) { return '"' . $ node -> value . '"' ; } return parent :: pScalar_String ( $ nod...
Fixes escaping of regular patterns
4,067
protected function pStmt_Class ( Class_ $ class ) : string { $ shouldReindex = false ; foreach ( $ class -> stmts as $ key => $ stmt ) { if ( $ stmt instanceof TraitUse ) { if ( count ( $ stmt -> traits ) === 0 ) { unset ( $ class -> stmts [ $ key ] ) ; $ shouldReindex = true ; } } } if ( $ shouldReindex ) { $ class ->...
Clean class and trait from empty use x ; for traits causing invalid code
4,068
public function refactor ( Node $ node ) : ? Node { if ( ! $ this -> isName ( $ node , 'parse' ) ) { return null ; } if ( ! $ this -> isType ( $ node -> class , 'Symfony\Component\Yaml\Yaml' ) ) { return null ; } if ( ! $ this -> isArgumentYamlFile ( $ node ) ) { return null ; } $ fileGetContentsFunCallNode = $ this ->...
Process Node of matched type
4,069
private function moveFunctionArgumentsUp ( Node $ node ) : void { $ secondArgument = $ node -> args [ 1 ] -> value ; $ node -> args [ 1 ] = $ secondArgument -> args [ 0 ] ; }
Handles custom error messages to not be overwrite by function with multiple args .
4,070
private function resolveArgumentsFromMethodCall ( Return_ $ returnNode ) : array { $ arguments = [ ] ; if ( $ returnNode -> expr instanceof MethodCall ) { foreach ( $ returnNode -> expr -> args as $ arg ) { if ( $ arg -> value instanceof Array_ ) { $ arguments [ ] = $ arg -> value ; } } } return $ arguments ; }
Already existing method call
4,071
public function printFormatPreserving ( PhpDocInfo $ phpDocInfo ) : string { $ this -> attributeAwarePhpDocNode = $ phpDocInfo -> getPhpDocNode ( ) ; $ this -> tokens = $ phpDocInfo -> getTokens ( ) ; $ this -> tokenCount = count ( $ phpDocInfo -> getTokens ( ) ) ; $ this -> phpDocInfo = $ phpDocInfo ; $ this -> curren...
As in php - parser
4,072
public function resolveStaticReturnTypeInfo ( FunctionLike $ functionLike ) : ? ReturnTypeInfo { if ( $ this -> shouldSkip ( $ functionLike ) ) { return null ; } $ returnNodes = $ this -> betterNodeFinder -> findInstanceOf ( ( array ) $ functionLike -> stmts , Return_ :: class ) ; $ isVoid = true ; $ types = [ ] ; fore...
Based on static analysis of code looking for return types
4,073
private function removeSelfTypeMethod ( Class_ $ node ) : Class_ { foreach ( ( array ) $ node -> stmts as $ key => $ stmt ) { if ( ! $ stmt instanceof ClassMethod ) { continue ; } if ( count ( ( array ) $ stmt -> stmts ) !== 1 ) { continue ; } $ innerClassMethodStmt = $ stmt -> stmts [ 0 ] instanceof Expression ? $ stm...
This is already checked on construction of object
4,074
private function shouldSkip ( BinaryOp $ binaryOp ) : bool { if ( $ binaryOp instanceof BooleanOr ) { return true ; } if ( $ binaryOp -> left instanceof BinaryOp ) { return true ; } return $ binaryOp -> right instanceof BinaryOp ; }
Skip too nested binary || binary > binary combinations
4,075
public function isTypehintAble ( ) : bool { if ( $ this -> hasRemovedTypes ( ) ) { return false ; } $ typeCount = count ( $ this -> types ) ; if ( $ typeCount >= 2 && $ this -> isArraySubtype ( $ this -> types ) ) { return true ; } return $ typeCount === 1 ; }
Can be put as PHP typehint to code
4,076
private function isClassFullyQualifiedName ( Node $ node ) : bool { $ parentNode = $ node -> getAttribute ( AttributeKey :: PARENT_NODE ) ; if ( $ parentNode === null ) { return false ; } if ( ! $ parentNode instanceof New_ ) { return false ; } $ fullyQualifiedNode = $ parentNode -> class ; $ newClassName = $ fullyQual...
Checks for new \ ClassNoNamespace ; This should be skipped not a namespace .
4,077
private function removeOriginalVisibilityFromFlags ( Node $ node ) : void { $ this -> ensureIsClassMethodOrProperty ( $ node , __METHOD__ ) ; if ( $ node -> flags === 0 ) { return ; } if ( $ node -> isPublic ( ) ) { $ node -> flags -= Class_ :: MODIFIER_PUBLIC ; } if ( $ node -> isProtected ( ) ) { $ node -> flags -= C...
This way abstract static final are kept
4,078
public static function getLogger ( string $ channel ) : Logger { if ( empty ( static :: $ loggers [ $ channel ] ) ) { static :: $ loggers [ $ channel ] = new Logger ( $ channel ) ; } return static :: $ loggers [ $ channel ] ; }
Returns the Logger identified by the channel .
4,079
public function scopeOrderByTranslation ( Builder $ query , $ key , $ sortmethod = 'asc' ) { $ translationTable = $ this -> getTranslationsTable ( ) ; $ localeKey = $ this -> getLocaleKey ( ) ; $ table = $ this -> getTable ( ) ; $ keyName = $ this -> getKeyName ( ) ; return $ query -> join ( $ translationTable , functi...
This scope sorts results by the given translation field .
4,080
public static function getDetectionRulesExtended ( ) { static $ rules ; if ( ! $ rules ) { $ rules = static :: mergeRules ( static :: $ desktopDevices , static :: $ phoneDevices , static :: $ tabletDevices , static :: $ operatingSystems , static :: $ additionalOperatingSystems , static :: $ browsers , static :: $ addit...
Get all detection rules . These rules include the additional platforms and browsers and utilities .
4,081
public function languages ( $ acceptLanguage = null ) { if ( $ acceptLanguage === null ) { $ acceptLanguage = $ this -> getHttpHeader ( 'HTTP_ACCEPT_LANGUAGE' ) ; } if ( ! $ acceptLanguage ) { return [ ] ; } $ languages = [ ] ; foreach ( explode ( ',' , $ acceptLanguage ) as $ piece ) { $ parts = explode ( ';' , $ piec...
Get accept languages .
4,082
protected function findDetectionRulesAgainstUA ( array $ rules , $ userAgent = null ) { foreach ( $ rules as $ key => $ regex ) { if ( empty ( $ regex ) ) { continue ; } if ( $ this -> match ( $ regex , $ userAgent ) ) { return $ key ? : reset ( $ this -> matchesArray ) ; } } return false ; }
Match a detection rule and return the matched key .
4,083
public function isDesktop ( $ userAgent = null , $ httpHeaders = null ) { return ! $ this -> isMobile ( $ userAgent , $ httpHeaders ) && ! $ this -> isTablet ( $ userAgent , $ httpHeaders ) && ! $ this -> isRobot ( $ userAgent ) ; }
Check if the device is a desktop computer .
4,084
public function isPhone ( $ userAgent = null , $ httpHeaders = null ) { return $ this -> isMobile ( $ userAgent , $ httpHeaders ) && ! $ this -> isTablet ( $ userAgent , $ httpHeaders ) ; }
Check if the device is a mobile phone .
4,085
protected function getFormFields ( RequestHandler $ controller = null , $ name , $ context = [ ] ) { $ fields = $ context [ 'Record' ] -> getCMSFields ( ) ; $ this -> invokeWithExtensions ( 'updateFormFields' , $ fields , $ controller , $ name , $ context ) ; return $ fields ; }
Build field list for this form
4,086
protected function getFormActions ( RequestHandler $ controller = null , $ name , $ context = [ ] ) { $ actions = $ context [ 'Record' ] -> getCMSActions ( ) ; $ this -> invokeWithExtensions ( 'updateFormActions' , $ actions , $ controller , $ name , $ context ) ; return $ actions ; }
Build list of actions for this form
4,087
public function getNewHash ( Member $ member ) { $ generator = new RandomGenerator ( ) ; $ this -> setToken ( $ generator -> randomToken ( 'sha1' ) ) ; return $ member -> encryptWithUserSettings ( $ this -> token ) ; }
Creates a new random token and hashes it using the member information
4,088
public static function generate ( Member $ member ) { if ( ! $ member -> exists ( ) ) { return null ; } if ( static :: config ( ) -> force_single_token ) { RememberLoginHash :: get ( ) -> filter ( 'MemberID' , $ member -> ID ) -> removeAll ( ) ; } $ rememberLoginHash = RememberLoginHash :: create ( ) ; do { $ deviceID ...
Generates a new login hash associated with a device The device is assigned a globally unique device ID The returned login hash stores the hashed token in the database for this device and this member
4,089
public function renew ( ) { $ hash = $ this -> getNewHash ( $ this -> Member ( ) ) ; $ this -> Hash = $ hash ; $ this -> extend ( 'onAfterRenewToken' ) ; $ this -> write ( ) ; return $ this ; }
Generates a new hash for this member but keeps the device ID intact
4,090
public static function clear ( Member $ member , $ alcDevice = null ) { if ( ! $ member -> exists ( ) ) { return ; } $ filter = array ( 'MemberID' => $ member -> ID ) ; if ( ! static :: config ( ) -> logout_across_devices && $ alcDevice ) { $ filter [ 'DeviceID' ] = $ alcDevice ; } RememberLoginHash :: get ( ) -> filte...
Deletes existing tokens for this member if logout_across_devices is true all tokens are deleted otherwise only the token for the provided device ID will be removed
4,091
public static function enabled_for ( $ response ) { $ contentType = $ response -> getHeader ( "Content-Type" ) ; if ( $ contentType && substr ( $ contentType , 0 , 9 ) != 'text/html' && substr ( $ contentType , 0 , 21 ) != 'application/xhtml+xml' ) { return false ; } if ( ContentNegotiator :: getEnabled ( ) ) { return ...
Returns true if negotiation is enabled for the given response . By default negotiation is only enabled for pages that have the xml header .
4,092
protected function splitFile ( $ path , $ lines = null ) { Deprecation :: notice ( '5.0' , 'splitFile is deprecated, please process files using a stream' ) ; $ previous = ini_get ( 'auto_detect_line_endings' ) ; ini_set ( 'auto_detect_line_endings' , true ) ; if ( ! is_int ( $ lines ) ) { $ lines = $ this -> config ( )...
Splits a large file up into many smaller files .
4,093
public function getSchema ( Form $ form ) { $ schema = [ 'name' => $ form -> getName ( ) , 'id' => $ form -> FormName ( ) , 'action' => $ form -> FormAction ( ) , 'method' => $ form -> FormMethod ( ) , 'attributes' => $ form -> getAttributes ( ) , 'data' => [ ] , 'fields' => [ ] , 'actions' => [ ] ] ; foreach ( $ form ...
Gets the schema for this form as a nested array .
4,094
public function getState ( Form $ form ) { $ state = [ 'id' => $ form -> FormName ( ) , 'fields' => [ ] , 'messages' => [ ] , 'notifyUnsavedChanges' => $ form -> getNotifyUnsavedChanges ( ) , ] ; $ state [ 'fields' ] = array_merge ( $ this -> getFieldStates ( $ form -> Fields ( ) ) , $ this -> getFieldStates ( $ form -...
Gets the current state of this form as a nested array .
4,095
protected function getSchemaForMessage ( $ message ) { $ value = $ message [ 'message' ] ; if ( $ message [ 'messageCast' ] === ValidationResult :: CAST_HTML ) { $ value = [ 'html' => $ message ] ; } return [ 'value' => $ value , 'type' => $ message [ 'messageType' ] , 'field' => empty ( $ message [ 'fieldName' ] ) ? n...
Return form schema for encoded validation message
4,096
public function respond ( HTTPRequest $ request , $ extraCallbacks = array ( ) ) { $ callbacks = array_merge ( $ this -> callbacks , $ extraCallbacks ) ; $ response = $ this -> getResponse ( ) ; $ responseParts = array ( ) ; if ( isset ( $ this -> fragmentOverride ) ) { $ fragments = $ this -> fragmentOverride ; } else...
Out of the box the handler CurrentForm value which will return the rendered form . Non - Ajax calls will redirect back .
4,097
protected function getExportColumnsForGridField ( GridField $ gridField ) { if ( $ this -> exportColumns ) { return $ this -> exportColumns ; } $ dataCols = $ gridField -> getConfig ( ) -> getComponentByType ( GridFieldDataColumns :: class ) ; if ( $ dataCols ) { return $ dataCols -> getDisplayFields ( $ gridField ) ; ...
Return the columns to export
4,098
public function Field ( $ properties = array ( ) ) { $ properties = array_merge ( $ properties , array ( 'Options' => $ this -> getOptions ( ) , ) ) ; return FormField :: Field ( $ properties ) ; }
Returns a select tag containing all the appropriate option tags
4,099
protected function clearCookies ( ) { $ secure = $ this -> getTokenCookieSecure ( ) ; Cookie :: set ( $ this -> getTokenCookieName ( ) , null , null , null , null , $ secure ) ; Cookie :: set ( $ this -> getDeviceCookieName ( ) , null , null , null , null , $ secure ) ; Cookie :: force_expiry ( $ this -> getTokenCookie...
Clear the cookies set for the user