idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
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 = str_replace ( $ token , $ tval , $ value ) ; } $ out [ $ name ] = $ value ; continue ; } $ out [ $ name ] = $ value ; } return $ out ; }
|
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 ( 'fake' ) ; if ( $ environment === null ) { $ environment = $ this -> getConfig ( ) -> getDefaultEnvironment ( ) ; $ output -> writeln ( '<comment>warning</comment> no environment specified, defaulting to: ' . $ environment ) ; } else { $ output -> writeln ( '<info>using environment</info> ' . $ environment ) ; } $ envOptions = $ this -> getConfig ( ) -> getEnvironment ( $ environment ) ; if ( isset ( $ envOptions [ 'adapter' ] ) ) { $ output -> writeln ( '<info>using adapter</info> ' . $ envOptions [ 'adapter' ] ) ; } if ( isset ( $ envOptions [ 'wrapper' ] ) ) { $ output -> writeln ( '<info>using wrapper</info> ' . $ envOptions [ 'wrapper' ] ) ; } if ( isset ( $ envOptions [ 'name' ] ) ) { $ output -> writeln ( '<info>using database</info> ' . $ envOptions [ 'name' ] ) ; } else { $ output -> writeln ( '<error>Could not determine database name! Please specify a database name in your config file.</error>' ) ; return 1 ; } if ( isset ( $ envOptions [ 'table_prefix' ] ) ) { $ output -> writeln ( '<info>using table prefix</info> ' . $ envOptions [ 'table_prefix' ] ) ; } if ( isset ( $ envOptions [ 'table_suffix' ] ) ) { $ output -> writeln ( '<info>using table suffix</info> ' . $ envOptions [ 'table_suffix' ] ) ; } if ( $ fake ) { $ output -> writeln ( '<comment>warning</comment> performing fake migrations' ) ; } try { $ start = microtime ( true ) ; if ( $ date !== null ) { $ this -> getManager ( ) -> migrateToDateTime ( $ environment , new \ DateTime ( $ date ) , $ fake ) ; } else { $ this -> getManager ( ) -> migrate ( $ environment , $ version , $ fake ) ; } $ end = microtime ( true ) ; } catch ( \ Exception $ e ) { $ output -> writeln ( '<error>' . $ e -> __toString ( ) . '</error>' ) ; return 1 ; } catch ( \ Throwable $ e ) { $ output -> writeln ( '<error>' . $ e -> __toString ( ) . '</error>' ) ; return 1 ; } $ output -> writeln ( '' ) ; $ output -> writeln ( '<comment>All Done. Took ' . sprintf ( '%.4fs' , $ end - $ start ) . '</comment>' ) ; return 0 ; }
|
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 $ this ; }
|
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 ( $ this -> table ) ) ; } $ plan = new Plan ( $ this -> actions ) ; $ plan -> execute ( $ this -> getAdapter ( ) ) ; }
|
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 ( $ table , $ foreignKey ) ; }
|
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 ( ! in_array ( $ paddingCharCount , $ allowedValues ) ) { return false ; } for ( $ i = 0 ; $ i < 4 ; ++ $ i ) { if ( $ paddingCharCount == $ allowedValues [ $ i ] && substr ( $ secret , - ( $ allowedValues [ $ i ] ) ) != str_repeat ( $ base32chars [ 32 ] , $ allowedValues [ $ i ] ) ) { return false ; } } $ secret = str_replace ( '=' , '' , $ secret ) ; $ secret = str_split ( $ secret ) ; $ binaryString = '' ; for ( $ i = 0 ; $ i < count ( $ secret ) ; $ i = $ i + 8 ) { $ x = '' ; if ( ! in_array ( $ secret [ $ i ] , $ base32chars ) ) { return false ; } for ( $ j = 0 ; $ j < 8 ; ++ $ j ) { $ x .= str_pad ( base_convert ( @ $ base32charsFlipped [ @ $ secret [ $ i + $ j ] ] , 10 , 2 ) , 5 , '0' , STR_PAD_LEFT ) ; } $ eightBits = str_split ( $ x , 8 ) ; for ( $ z = 0 ; $ z < count ( $ eightBits ) ; ++ $ z ) { $ binaryString .= ( ( $ y = chr ( base_convert ( $ eightBits [ $ z ] , 2 , 10 ) ) ) || ord ( $ y ) == 48 ) ? $ y : '' ; } } return $ binaryString ; }
|
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 , $ alias ) ; }
|
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' ) ; return $ this -> join ( new Expression ( $ expression ) , $ first , $ operator , $ second , $ type , $ where ) ; }
|
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 ] = $ value ; } return $ mergedOptions ; }
|
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 file \'%s\' was created but is empty (command: %s).' , $ output , $ command ) ) ; } }
|
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 !== $ option ) { if ( true === $ option ) { if ( $ key == 'toc' ) { $ command .= ' ' . $ key ; } else { $ command .= ' --' . $ key ; } } elseif ( is_array ( $ option ) ) { if ( $ this -> isAssociativeArray ( $ option ) ) { foreach ( $ option as $ k => $ v ) { $ command .= ' --' . $ key . ' ' . escapeshellarg ( $ k ) . ' ' . escapeshellarg ( $ v ) ; } } else { foreach ( $ option as $ v ) { $ command .= ' --' . $ key . ' ' . escapeshellarg ( $ v ) ; } } } else { if ( in_array ( $ key , [ 'toc' , 'cover' ] ) ) { $ command .= ' ' . $ key . ' ' . escapeshellarg ( $ option ) ; } elseif ( in_array ( $ key , [ 'image-dpi' , 'image-quality' ] ) ) { $ command .= ' --' . $ key . ' ' . ( int ) $ option ; } else { $ command .= ' --' . $ key . ' ' . escapeshellarg ( $ option ) ; } } } } if ( is_array ( $ input ) ) { foreach ( $ input as $ i ) { $ command .= ' ' . escapeshellarg ( $ i ) . ' ' ; } $ command .= escapeshellarg ( $ output ) ; } else { $ command .= ' ' . escapeshellarg ( $ input ) . ' ' . escapeshellarg ( $ output ) ; } return $ command ; }
|
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 ) { $ process -> setTimeout ( $ this -> timeout ) ; } $ process -> run ( ) ; return [ $ process -> getExitCode ( ) , $ process -> getOutput ( ) , $ process -> getErrorOutput ( ) , ] ; }
|
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 -> isDir ( $ filename ) ? 'directory' : 'link' ) ) ; } elseif ( false === $ overwrite ) { throw new Exceptions \ FileAlreadyExistsException ( sprintf ( 'The output file \'%s\' already exists.' , $ filename ) ) ; } elseif ( ! $ this -> unlink ( $ filename ) ) { throw new \ RuntimeException ( sprintf ( 'Could not delete already existing output file \'%s\'.' , $ filename ) ) ; } } elseif ( ! $ this -> isDir ( $ directory ) && ! $ this -> mkdir ( $ directory ) ) { throw new \ RuntimeException ( sprintf ( 'The output file\'s directory \'%s\' could not be created.' , $ directory ) ) ; } }
|
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 ( $ value ) && ! $ this -> isOptionUrl ( $ value ) ; $ fetchUrlContent = $ option === 'xsl-style-sheet' && $ this -> isOptionUrl ( $ value ) ; if ( $ saveToTempFile || $ fetchUrlContent ) { $ fileContent = $ fetchUrlContent ? file_get_contents ( $ value ) : $ value ; $ options [ $ option ] = $ this -> createTemporaryFile ( $ fileContent , $ this -> optionsWithContentCheck [ $ option ] ) ; } } } return $ options ; }
|
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_func_array ( $ callback , $ arguments ) ; }
|
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 $ pathinfo + [ 'dirname' => '' ] ; }
|
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 ( preg_match ( '#^[a-zA-Z]{1}:[^\\\/]#' , $ basename ) ) { $ basename = substr ( $ basename , 2 ) ; } if ( preg_match ( '#^[a-zA-Z]{1}:$#' , $ basename ) ) { $ basename = rtrim ( $ basename , ':' ) ; } return $ basename ; }
|
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' ] ) { $ this -> state = self :: EXPIRED ; } }
|
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.authentication.entry_point' ) ) ; return $ entryPointId ; }
|
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 :: class ) ) ; } if ( false === ( $ jsonWebToken = $ tokenExtractor -> extract ( $ request ) ) ) { return ; } $ preAuthToken = new PreAuthenticationJWTUserToken ( $ jsonWebToken ) ; try { if ( ! $ payload = $ this -> jwtManager -> decode ( $ preAuthToken ) ) { throw new InvalidTokenException ( 'Invalid JWT Token' ) ; } $ preAuthToken -> setPayload ( $ payload ) ; } catch ( JWTDecodeFailureException $ e ) { if ( JWTDecodeFailureException :: EXPIRED_TOKEN === $ e -> getReason ( ) ) { throw new ExpiredTokenException ( ) ; } throw new InvalidTokenException ( 'Invalid JWT Token' , 0 , $ e ) ; } return $ preAuthToken ; }
|
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 :: class ) ) ; } $ payload = $ preAuthToken -> getPayload ( ) ; $ idClaim = $ this -> jwtManager -> getUserIdClaim ( ) ; if ( ! isset ( $ payload [ $ idClaim ] ) ) { throw new InvalidPayloadException ( $ idClaim ) ; } $ identity = $ payload [ $ idClaim ] ; try { $ user = $ this -> loadUser ( $ userProvider , $ payload , $ identity ) ; } catch ( UsernameNotFoundException $ e ) { throw new UserNotFoundException ( $ idClaim , $ identity ) ; } $ this -> preAuthenticationTokenStorage -> setToken ( $ preAuthToken ) ; return $ user ; }
|
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 ) ; $ this -> withStyle = ( bool ) $ input -> getOption ( Option :: OPTION_WITH_STYLE ) ; }
|
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 , $ enabledRector , true ) ) { continue ; } $ this -> addRectorConfiguration ( $ configuration , $ phpRector ) ; $ this -> addVisitor ( $ phpRector ) ; continue 2 ; } } }
|
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 = $ param -> getAttribute ( AttributeKey :: METHOD_NAME ) ; $ methodsWithWThisMock = $ classMocks [ $ variable ] ; if ( ! $ this -> phpSpecMockCollector -> isVariableMockInProperty ( $ param -> var ) ) { return $ this -> createNewMockVariableAssign ( $ param , $ name ) ; } $ reversedMethodsWithThisMock = array_flip ( $ methodsWithWThisMock ) ; if ( $ reversedMethodsWithThisMock [ $ method ] === 0 ) { return $ this -> createPropertyFetchMockVariableAssign ( $ param , $ name ) ; } return null ; }
|
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 ( $ phpDocChildNodes ) ; $ phpDocNodeInfo = $ lastChildNode -> getAttribute ( Attribute :: PHP_DOC_NODE_INFO ) ; if ( $ phpDocNodeInfo !== null ) { $ attributeAwarePhpDocNode -> setAttribute ( Attribute :: LAST_TOKEN_POSITION , $ phpDocNodeInfo -> getEnd ( ) ) ; } return $ attributeAwarePhpDocNode ; }
|
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 -> getParameters ( ) as $ reflectionParameter ) { $ parameterType = ( string ) $ reflectionParameter -> getType ( ) ; if ( ! $ this -> typeAnalyzer -> isPhpReservedType ( $ parameterType ) ) { continue ; } if ( ! $ rectorReflection -> hasProperty ( $ reflectionParameter -> getName ( ) ) ) { continue ; } $ propertyReflection = $ rectorReflection -> getProperty ( $ reflectionParameter -> getName ( ) ) ; $ propertyReflection -> setAccessible ( true ) ; $ configurationValue = $ propertyReflection -> getValue ( $ rector ) ; $ configuration [ $ reflectionParameter -> getName ( ) ] = $ configurationValue ; } return $ configuration ; }
|
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 ( AttributeKey :: CLASS_NODE ) ; if ( ! $ classNode instanceof Class_ ) { throw new ShouldNotHappenException ( ) ; } $ propertyName = $ this -> nameResolver -> resolve ( $ property ) ; if ( $ propertyName === null ) { return null ; } $ propertyAssignNodes = $ this -> betterNodeFinder -> find ( [ $ classNode ] , function ( Node $ node ) use ( $ propertyName ) : bool { if ( $ node instanceof Assign && $ node -> var instanceof PropertyFetch ) { return $ this -> nameResolver -> isName ( $ node -> var , $ propertyName ) ; } return false ; } ) ; foreach ( $ propertyAssignNodes as $ propertyAssignNode ) { $ types = array_merge ( $ types , $ this -> nodeTypeResolver -> resolveSingleTypeToStrings ( $ propertyAssignNode -> expr ) ) ; } $ types = array_filter ( $ types ) ; return new VarTypeInfo ( $ types , $ this -> typeAnalyzer , $ types , true ) ; }
|
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 ( ) ; $ paramTypeInfos = [ ] ; foreach ( $ types as $ i => $ paramTagValueNode ) { $ fqnParamTagValueNode = $ fqnTypes [ $ i ] ; $ paramTypeInfo = new ParamTypeInfo ( $ paramTagValueNode -> parameterName , $ this -> typeAnalyzer , $ paramTagValueNode -> getAttribute ( Attribute :: TYPE_AS_ARRAY ) , $ fqnParamTagValueNode -> getAttribute ( Attribute :: RESOLVED_NAMES ) ) ; $ paramTypeInfos [ $ paramTypeInfo -> getName ( ) ] = $ paramTypeInfo ; } return $ paramTypeInfos ; }
|
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 ( $ node ) ; }
|
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 -> stmts = array_values ( $ class -> stmts ) ; } return parent :: pStmt_Class ( $ 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 -> createFunction ( 'file_get_contents' , [ $ node -> args [ 0 ] ] ) ; $ node -> args [ 0 ] = new Arg ( $ fileGetContentsFunCallNode ) ; return $ node ; }
|
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 -> currentTokenPosition = 0 ; $ this -> removedNodePositions = [ ] ; return $ this -> printPhpDocNode ( $ this -> attributeAwarePhpDocNode ) ; }
|
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 = [ ] ; foreach ( $ returnNodes as $ returnNode ) { if ( $ returnNode -> expr === null ) { continue ; } $ types = array_merge ( $ types , $ this -> nodeTypeResolver -> resolveSingleTypeToStrings ( $ returnNode -> expr ) ) ; $ isVoid = false ; } if ( $ isVoid ) { return new ReturnTypeInfo ( [ 'void' ] , $ this -> typeAnalyzer ) ; } $ types = array_filter ( $ types ) ; return new ReturnTypeInfo ( $ types , $ this -> typeAnalyzer ) ; }
|
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 ? $ stmt -> stmts [ 0 ] -> expr : $ stmt -> stmts [ 0 ] ; if ( ! $ innerClassMethodStmt instanceof MethodCall ) { continue ; } if ( ! $ this -> isName ( $ innerClassMethodStmt , 'shouldHaveType' ) ) { continue ; } if ( ! $ this -> isValue ( $ innerClassMethodStmt -> args [ 0 ] -> value , $ this -> testedClass ) ) { continue ; } unset ( $ node -> stmts [ $ key ] ) ; } return $ node ; }
|
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 = $ fullyQualifiedNode -> toString ( ) ; return array_key_exists ( $ newClassName , $ this -> oldToNewNamespaces ) ; }
|
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 -= Class_ :: MODIFIER_PROTECTED ; } if ( $ node -> isPrivate ( ) ) { $ node -> flags -= Class_ :: MODIFIER_PRIVATE ; } }
|
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 , function ( JoinClause $ join ) use ( $ translationTable , $ localeKey , $ table , $ keyName ) { $ join -> on ( $ translationTable . '.' . $ this -> getRelationKey ( ) , '=' , $ table . '.' . $ keyName ) -> where ( $ translationTable . '.' . $ localeKey , $ this -> locale ( ) ) ; } ) -> orderBy ( $ translationTable . '.' . $ key , $ sortmethod ) -> select ( $ table . '.*' ) -> with ( 'translations' ) ; }
|
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 :: $ additionalBrowsers , static :: $ utilities ) ; } return $ rules ; }
|
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 ( ';' , $ piece ) ; $ language = strtolower ( $ parts [ 0 ] ) ; $ priority = empty ( $ parts [ 1 ] ) ? 1. : floatval ( str_replace ( 'q=' , '' , $ parts [ 1 ] ) ) ; $ languages [ $ language ] = $ priority ; } arsort ( $ languages ) ; return array_keys ( $ languages ) ; }
|
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 = $ rememberLoginHash -> getNewDeviceID ( ) ; } while ( RememberLoginHash :: get ( ) -> filter ( 'DeviceID' , $ deviceID ) -> count ( ) ) ; $ rememberLoginHash -> DeviceID = $ deviceID ; $ rememberLoginHash -> Hash = $ rememberLoginHash -> getNewHash ( $ member ) ; $ rememberLoginHash -> MemberID = $ member -> ID ; $ now = DBDatetime :: now ( ) ; $ expiryDate = new DateTime ( $ now -> Rfc2822 ( ) ) ; $ tokenExpiryDays = static :: config ( ) -> token_expiry_days ; $ expiryDate -> add ( new DateInterval ( 'P' . $ tokenExpiryDays . 'D' ) ) ; $ rememberLoginHash -> ExpiryDate = $ expiryDate -> format ( 'Y-m-d H:i:s' ) ; $ rememberLoginHash -> extend ( 'onAfterGenerateToken' ) ; $ rememberLoginHash -> write ( ) ; return $ rememberLoginHash ; }
|
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 ( ) -> filter ( $ filter ) -> removeAll ( ) ; }
|
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 true ; } else { return ( substr ( $ response -> getBody ( ) , 0 , 5 ) == '<' . '?xml' ) ; } }
|
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 ( ) -> get ( "lines" ) ; } $ new = $ this -> getNewSplitFileName ( ) ; $ to = fopen ( $ new , 'w+' ) ; $ from = fopen ( $ path , 'r' ) ; $ header = null ; if ( $ this -> hasHeaderRow ) { $ header = fgets ( $ from ) ; fwrite ( $ to , $ header ) ; } $ files = array ( ) ; $ files [ ] = $ new ; $ count = 0 ; while ( ! feof ( $ from ) ) { fwrite ( $ to , fgets ( $ from ) ) ; $ count ++ ; if ( $ count >= $ lines ) { fclose ( $ to ) ; $ new = $ this -> getNewSplitFileName ( ) ; $ to = fopen ( $ new , 'w+' ) ; if ( $ this -> hasHeaderRow ) { fwrite ( $ to , $ header ) ; } $ files [ ] = $ new ; $ count = 0 ; } } fclose ( $ to ) ; ini_set ( 'auto_detect_line_endings' , $ previous ) ; return $ files ; }
|
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 -> Actions ( ) as $ action ) { $ schema [ 'actions' ] [ ] = $ action -> getSchemaData ( ) ; } foreach ( $ form -> Fields ( ) as $ field ) { $ schema [ 'fields' ] [ ] = $ field -> getSchemaData ( ) ; } return $ schema ; }
|
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 -> Actions ( ) ) ) ; if ( $ message = $ form -> getSchemaMessage ( ) ) { $ state [ 'messages' ] [ ] = $ message ; } return $ state ; }
|
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' ] ) ? null : $ message [ 'fieldName' ] , ] ; }
|
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 ; } elseif ( $ fragmentStr = $ request -> getHeader ( 'X-Pjax' ) ) { $ fragments = explode ( ',' , $ fragmentStr ) ; } else { if ( $ request -> isAjax ( ) ) { throw new HTTPResponse_Exception ( "Ajax requests to this URL require an X-Pjax header." , 400 ) ; } elseif ( empty ( $ callbacks [ 'default' ] ) ) { throw new HTTPResponse_Exception ( "Missing default response handler for this URL" , 400 ) ; } $ response -> setBody ( call_user_func ( $ callbacks [ 'default' ] ) ) ; return $ response ; } foreach ( $ fragments as $ fragment ) { if ( isset ( $ callbacks [ $ fragment ] ) ) { $ res = call_user_func ( $ callbacks [ $ fragment ] ) ; $ responseParts [ $ fragment ] = $ res ? ( string ) $ res : $ res ; } else { throw new HTTPResponse_Exception ( "X-Pjax = '$fragment' not supported for this URL." , 400 ) ; } } $ response -> setBody ( json_encode ( $ responseParts ) ) ; $ response -> addHeader ( 'Content-Type' , 'application/json' ) ; return $ response ; }
|
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 DataObject :: singleton ( $ gridField -> getModelClass ( ) ) -> summaryFields ( ) ; }
|
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 -> getTokenCookieName ( ) , null , null , null , null , $ secure ) ; Cookie :: force_expiry ( $ this -> getDeviceCookieName ( ) , null , null , null , null , $ secure ) ; }
|
Clear the cookies set for the user
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.