idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
22,800
public function Status ( StatusRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.Maintenance/Status' , $ argument , [ '\Etcdserverpb\StatusResponse' , 'decode' ] , $ metadata , $ options ) ; }
Status gets the status of the member .
22,801
public function Defragment ( DefragmentRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.Maintenance/Defragment' , $ argument , [ '\Etcdserverpb\DefragmentResponse' , 'decode' ] , $ metadata , $ options ) ; }
Defragment defragments a member s backend database to recover storage space .
22,802
public function Hash ( HashRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.Maintenance/Hash' , $ argument , [ '\Etcdserverpb\HashResponse' , 'decode' ] , $ metadata , $ options ) ; }
Hash returns the hash of the local KV state for consistency checking purpose . This is designed for testing ; do not use this in production when there are ongoing transactions .
22,803
public function Snapshot ( SnapshotRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _serverStreamRequest ( '/etcdserverpb.Maintenance/Snapshot' , $ argument , [ '\Etcdserverpb\SnapshotResponse' , 'decode' ] , $ metadata , $ options ) ; }
Snapshot sends a snapshot of the entire backend from a member over a stream to a client .
22,804
protected function registerRedirection ( ) : void { if ( ! empty ( $ this -> redirectAfterInstalled ) && \ is_string ( $ this -> redirectAfterInstalled ) ) { Installation :: $ redirectAfterInstalled = $ this -> redirectAfterInstalled ; } }
Register redirection services .
22,805
protected function addDefaultSpecifications ( RequirementContract $ requirement ) { return $ requirement -> add ( new Specifications \ WritableStorage ( $ this -> app ) ) -> add ( new Specifications \ WritableBootstrapCache ( $ this -> app ) ) -> add ( new Specifications \ WritableAsset ( $ this -> app ) ) -> add ( new Specifications \ DatabaseConnection ( $ this -> app ) ) -> add ( new Specifications \ Authentication ( $ this -> app ) ) ; }
Add default specifications .
22,806
public function retrieveResetToken ( $ token ) { return $ this -> queryBuilder -> from ( $ this -> getTokenTable ( ) ) -> where ( 'token' , $ token ) -> first ( ) ; }
Retrieve a reset token
22,807
public function deleteToken ( $ token ) { return $ this -> queryBuilder -> from ( $ this -> getTokenTable ( ) ) -> where ( 'token' , $ token ) -> delete ( ) ; }
Delete a reset token
22,808
public function registerToken ( \ Globalis \ PuppetSkilled \ Database \ Magic \ Model $ user ) { $ this -> queryBuilder -> from ( $ this -> getTokenTable ( ) ) -> insert ( [ 'user_id' => $ user -> getKey ( ) , 'token' => ( $ token = $ this -> generateResetToken ( ) ) , 'created_at' => new Carbon ( ) , ] ) ; return $ token ; }
Create a reset token
22,809
public function getConfig ( $ key = null , $ default = null ) { $ name = $ this -> current ? : 'default' ; $ configs = $ this -> configs [ $ name ] ; if ( $ key === null ) { return $ configs ; } return isset ( $ configs [ $ key ] ) ? $ configs [ $ key ] : $ default ; }
Get current connection config by key
22,810
public function getOption ( $ key = null , $ default = null ) { $ name = $ this -> current ? : 'default' ; $ options = isset ( $ this -> configs [ $ name ] [ 'options' ] ) ? $ this -> configs [ $ name ] [ 'options' ] : [ ] ; if ( $ key === null ) { return $ options ; } return isset ( $ options [ $ key ] ) ? $ options [ $ key ] : $ default ; }
Get current connection option by key
22,811
public function addConnection ( $ name , $ dsn , $ username = null , $ password = null , $ options = [ ] ) { static $ defaultOptions = array ( \ PDO :: ATTR_ERRMODE => \ PDO :: ERRMODE_EXCEPTION , ) ; if ( isset ( $ options [ 'prefix' ] ) ) { $ prefix = $ options [ 'prefix' ] ; unset ( $ options [ 'prefix' ] ) ; } else { $ prefix = '' ; } $ this -> configs [ $ name ] = [ 'dsn' => $ dsn , 'username' => $ username , 'password' => $ password , 'prefix' => $ prefix , 'options' => $ options + $ defaultOptions , ] ; return $ this ; }
Add a new connection configuration
22,812
public function quoteIdentifier ( $ name ) { $ quote = null ; switch ( $ this -> getAttribute ( \ PDO :: ATTR_DRIVER_NAME ) ) { case 'pgsql' : case 'sqlsrv' : case 'dblib' : case 'mssql' : case 'sybase' : $ quote = '"' ; break ; case 'mysql' : case 'sqlite' : case 'sqlite2' : default : $ quote = '`' ; } $ parts = explode ( '.' , $ name ) ; foreach ( $ parts as $ k => $ part ) { if ( $ part !== '*' ) { $ parts [ $ k ] = $ quote . $ part . $ quote ; } } return implode ( '.' , $ parts ) ; }
Quote table or column
22,813
public function writeClientInit ( $ compression = false , $ ssl = false ) { $ date = date ( 'M d Y H:i:s' ) ; $ data = array ( 'MsgType' => 'ClientInit' , 'ClientDate' => $ date , 'ClientVersion' => 'clue/quassel-react alpha' ) ; if ( $ this -> protocol -> isLegacy ( ) ) { $ data += array ( 'ProtocolVersion' => 10 , 'UseCompression' => ( bool ) $ compression , 'UseSsl' => ( bool ) $ ssl ) ; } return $ this -> write ( $ data ) ; }
send client init info
22,814
public function writeCoreSetupData ( $ user , $ password , $ backend = 'SQLite' , $ properties = array ( ) ) { return $ this -> write ( array ( 'MsgType' => 'CoreSetupData' , 'SetupData' => array ( 'AdminUser' => ( string ) $ user , 'AdminPasswd' => ( string ) $ password , 'Backend' => ( string ) $ backend , 'ConnectionProperties' => $ properties ) ) ) ; }
send setup data
22,815
public function writeHeartBeatRequest ( \ DateTime $ dt = null ) { if ( $ dt === null ) { $ dt = \ DateTime :: createFromFormat ( 'U.u' , sprintf ( '%.6F' , microtime ( true ) ) ) ; } return $ this -> write ( array ( Protocol :: REQUEST_HEARTBEAT , $ dt ) ) ; }
Sends a heartbeat request
22,816
public function writeBufferRequestBacklogAll ( $ messageIdFirst , $ messageIdLast , $ maxAmount , $ additional ) { return $ this -> write ( array ( Protocol :: REQUEST_SYNC , "BacklogManager" , "" , "requestBacklogAll" , new QVariant ( ( int ) $ messageIdFirst , 'MsgId' ) , new QVariant ( ( int ) $ messageIdLast , 'MsgId' ) , ( int ) $ maxAmount , ( int ) $ additional ) ) ; }
Sends a backlog request for all messages in all channels
22,817
public function write ( $ data ) { return $ this -> stream -> write ( $ this -> splitter -> writePacket ( $ this -> protocol -> serializeVariantPacket ( $ data ) ) ) ; }
writes the given data array to the underlying connection
22,818
public function execute ( ) { $ groups = array ( ) ; $ results = array ( ) ; $ currentOperation = null ; $ currentGroup = array ( ) ; foreach ( $ this -> commands as $ command ) { if ( $ currentOperation !== $ command [ 0 ] ) { $ groups [ ] = array ( $ currentOperation , $ currentGroup ) ; $ currentOperation = $ command [ 0 ] ; $ currentGroup = array ( ) ; } if ( $ currentOperation === 'get' ) { $ currentGroup [ ] = $ command [ 1 ] ; } else { $ currentGroup [ $ command [ 1 ] ] = $ command [ 2 ] ; } } $ groups [ ] = array ( $ currentOperation , $ currentGroup ) ; array_shift ( $ groups ) ; foreach ( $ groups as $ group ) { list ( $ op , $ args ) = $ group ; if ( $ op === 'set' ) { $ result = $ this -> backend -> setMulti ( $ args , $ this -> ttl ) ; $ results = array_merge ( $ results , array_fill ( 0 , count ( $ args ) , $ result ) ) ; } else { $ results = array_merge ( $ results , $ this -> backend -> getMulti ( $ args ) ) ; } } $ this -> commands = array ( ) ; return $ results ; }
Executes the pipeline and returns results of individual commands as an array .
22,819
protected function rebuild ( InputInterface $ input , OutputInterface $ output ) { $ puli = new Puli ( Path :: join ( [ getcwd ( ) , NANBANDO_DIR ] ) ) ; $ puli -> start ( ) ; $ embeddedComposer = $ this -> getApplication ( ) -> getEmbeddedComposer ( ) ; $ packageManager = $ puli -> getPackageManager ( ) ; $ io = new ConsoleIO ( $ input , $ output , $ this -> getApplication ( ) -> getHelperSet ( ) ) ; $ composer = $ embeddedComposer -> createComposer ( $ io ) ; $ installationManager = $ composer -> getInstallationManager ( ) ; $ rootPackage = $ composer -> getPackage ( ) ; $ repository = $ composer -> getRepositoryManager ( ) -> getLocalRepository ( ) ; $ packages = [ ] ; foreach ( $ repository -> getPackages ( ) as $ package ) { $ packages [ $ package -> getName ( ) ] = $ package ; } foreach ( $ rootPackage -> getRequires ( ) as $ require ) { if ( ! array_key_exists ( $ require -> getTarget ( ) , $ packages ) ) { continue ; } $ packageManager -> installPackage ( Path :: normalize ( $ installationManager -> getInstallPath ( $ packages [ $ require -> getTarget ( ) ] ) ) , $ require -> getTarget ( ) , 'nanbando' ) ; } $ filesystem = new Filesystem ( ) ; $ filesystem -> remove ( Path :: join ( [ getcwd ( ) , NANBANDO_DIR , '.puli' ] ) ) ; $ discoveryManager = $ puli -> getDiscoveryManager ( ) ; if ( ! $ discoveryManager -> hasRootTypeDescriptor ( 'nanbando/bundle' ) ) { $ discoveryManager -> addRootTypeDescriptor ( new BindingTypeDescriptor ( new BindingType ( 'nanbando/bundle' ) ) , 0 ) ; } $ discoveryManager -> clearDiscovery ( ) ; $ discoveryManager -> buildDiscovery ( ) ; $ filesystem = new Filesystem ( ) ; $ filesystem -> remove ( Path :: join ( [ getcwd ( ) , NANBANDO_DIR , 'app' , 'cache' ] ) ) ; }
Rebuild the puli dependencies for symfony container .
22,820
private function _getParagraph ( $ first = false ) { $ words = $ this -> _dictionary ; shuffle ( $ words ) ; if ( $ first ) { $ pre = array ( 'lorem' , 'ipsum' ) ; $ words = array_merge ( $ pre , $ words ) ; } $ nbrWordsPerParagraph = $ this -> _nbrWordsPerParagraph + mt_rand ( - 20 , 20 ) ; $ nbrWordsPerSentence = $ this -> _nbrWordsPerSentence + mt_rand ( - 8 , 8 ) ; $ words = array_slice ( $ words , 0 , $ nbrWordsPerParagraph ) ; $ sentences = array_chunk ( $ words , $ nbrWordsPerSentence ) ; $ result = array ( ) ; foreach ( $ sentences as & $ sentence ) { $ this -> _punctuate ( $ sentence ) ; $ result [ ] = ucfirst ( implode ( ' ' , $ sentence ) ) ; } return ( '<p>' . implode ( ' ' , $ result ) . '</p>' ) ; }
Returns a paragraph .
22,821
private function _numberOfCommas ( $ len ) { $ avg = ( float ) log ( $ len , 6 ) ; $ stdDev = ( float ) ( $ avg / 6.000 ) ; return ( ( int ) round ( $ this -> _gauss ( $ avg , $ stdDev ) ) ) ; }
Determines the number of commas for a sentence of the given length . Average and standard deviation are determined superficially .
22,822
public function get ( $ name ) { if ( isset ( $ this -> global_vars [ $ name ] ) ) { return $ this -> global_vars [ $ name ] ; } return null ; }
get data from roots scope from any where within a Form closure
22,823
public function parseLines ( ) { $ text = [ ] ; while ( ( $ line = $ this -> nextLine ( ) ) !== false ) { $ line = rtrim ( $ line ) ; if ( $ line == "" ) { $ text [ ] = null ; continue ; } $ blockTypes = [ ] ; $ marker = $ line [ 0 ] ; if ( isset ( $ this -> blockTypes [ $ marker ] ) ) { foreach ( $ this -> blockTypes [ $ marker ] as $ blockType ) { $ blockTypes [ ] = $ blockType ; } } foreach ( $ blockTypes as $ blockType ) { if ( $ this -> { "block" . $ blockType } ( $ line ) ) { continue ; } } } $ text = implode ( "\n" , $ this -> lines ) ; return [ "text" => $ text , "frontmatter" => $ this -> frontmatter , ] ; }
Parse each line and look into it to see whats need to be done .
22,824
public function currentLine ( ) { return isset ( $ this -> lines [ $ this -> lineNumber - 1 ] ) ? $ this -> lines [ $ this -> lineNumber - 1 ] : false ; }
Get current line to parse .
22,825
protected function blockInclude ( $ line ) { if ( $ this -> config [ "include" ] && preg_match ( "/^#include[ \t]([\w.]+)$/" , $ line , $ matches ) ) { $ file = $ this -> config [ "include_base" ] . "/" . $ matches [ 1 ] ; if ( ! is_readable ( $ file ) ) { throw new Exception ( "Could not find include file: '$file'" ) ; } $ include = file_get_contents ( $ file ) ; $ include = str_replace ( array ( "\r\n" , "\r" ) , "\n" , $ include ) ; $ include = explode ( "\n" , $ include ) ; array_splice ( $ this -> lines , $ this -> lineNumber - 1 , 1 , $ include ) ; $ this -> lineNumber -- ; return true ; } }
Detect and include external file add it to lines array and parse it .
22,826
protected function blockYamlFrontmatter ( $ line ) { if ( $ this -> config [ "frontmatter_yaml" ] && strlen ( $ line ) === 3 && $ line [ 2 ] === "-" && $ line [ 1 ] === "-" ) { $ startLineNumber = $ this -> lineNumber ; while ( ( $ line = $ this -> nextLine ( ) ) !== false ) { $ line = rtrim ( $ line ) ; if ( strlen ( $ line ) === 3 && ( ( $ line [ 2 ] === "-" && $ line [ 1 ] === "-" && $ line [ 0 ] === "-" ) || ( $ line [ 2 ] === "." && $ line [ 1 ] === "." && $ line [ 0 ] === "." ) ) ) { $ linesRemoved = $ this -> lineNumber + 1 - $ startLineNumber ; $ this -> linesRemoved += $ linesRemoved ; $ frontmatter = array_splice ( $ this -> lines , $ startLineNumber - 1 , $ linesRemoved ) ; unset ( $ frontmatter [ $ linesRemoved - 1 ] ) ; unset ( $ frontmatter [ 0 ] ) ; $ this -> addYamlFrontmatter ( $ frontmatter ) ; $ this -> lineNumber = $ startLineNumber - 1 ; return true ; } } if ( $ this -> currentLine ( ) === false ) { throw new Exception ( "Start of YAML detected at line: $startLineNumber but no end of block detected." ) ; } } }
Detect and extract block with YAML frontmatter from the lines array .
22,827
protected function addYamlFrontmatter ( $ lines ) { $ text = implode ( "\n" , $ lines ) ; $ parsed = $ this -> parseYaml ( $ text ) ; if ( ! is_array ( $ parsed ) ) { $ parsed = [ $ parsed ] ; } $ this -> frontmatter = array_merge ( $ this -> frontmatter , $ parsed ) ; }
Extract YAML frontmatter from text and merge into existing frontmatter .
22,828
protected function parseYaml ( $ text ) { if ( $ this -> config [ "yaml_parser_pecl" ] && function_exists ( "yaml_parse" ) ) { $ parsed = yaml_parse ( $ text ) ; if ( $ parsed === false ) { throw new Exception ( "Failed parsing YAML frontmatter using PECL." ) ; } return $ parsed ; } if ( $ this -> config [ "yaml_parser_symfony" ] && method_exists ( "Symfony\Component\Yaml\Yaml" , "parse" ) ) { $ parsed = Yaml :: parse ( $ text ) ; return $ parsed ; } if ( $ this -> config [ "yaml_parser_spyc" ] && function_exists ( "spyc_load" ) ) { $ parsed = spyc_load ( $ text ) ; return $ parsed ; } throw new Exception ( "Could not find support for YAML." ) ; }
Parse YAML front matter from text use one of several available implementations of a YAML parser .
22,829
protected function addJsonFrontmatter ( $ lines ) { if ( ! function_exists ( "json_decode" ) ) { throw new Exception ( "Missing JSON support, perhaps install JSON module with PHP." ) ; } $ text = implode ( "\n" , $ lines ) ; $ parsed = json_decode ( $ text . "\n" , true ) ; if ( is_null ( $ parsed ) ) { throw new Exception ( "Failed parsing JSON frontmatter." ) ; } if ( ! is_array ( $ parsed ) ) { $ parsed = [ $ parsed ] ; } $ this -> frontmatter = array_merge ( $ this -> frontmatter , $ parsed ) ; }
Extract JSON frontmatter from text and merge into existing frontmatter .
22,830
public function addField ( \ google \ protobuf \ FieldDescriptorProto $ value ) { if ( $ this -> field === null ) { $ this -> field = new \ Protobuf \ MessageCollection ( ) ; } $ this -> field -> add ( $ value ) ; }
Add a new element to field
22,831
public function addNestedType ( \ google \ protobuf \ DescriptorProto $ value ) { if ( $ this -> nested_type === null ) { $ this -> nested_type = new \ Protobuf \ MessageCollection ( ) ; } $ this -> nested_type -> add ( $ value ) ; }
Add a new element to nested_type
22,832
public function addExtensionRange ( \ google \ protobuf \ DescriptorProto \ ExtensionRange $ value ) { if ( $ this -> extension_range === null ) { $ this -> extension_range = new \ Protobuf \ MessageCollection ( ) ; } $ this -> extension_range -> add ( $ value ) ; }
Add a new element to extension_range
22,833
public function addOneofDecl ( \ google \ protobuf \ OneofDescriptorProto $ value ) { if ( $ this -> oneof_decl === null ) { $ this -> oneof_decl = new \ Protobuf \ MessageCollection ( ) ; } $ this -> oneof_decl -> add ( $ value ) ; }
Add a new element to oneof_decl
22,834
public function addReservedRange ( \ google \ protobuf \ DescriptorProto \ ReservedRange $ value ) { if ( $ this -> reserved_range === null ) { $ this -> reserved_range = new \ Protobuf \ MessageCollection ( ) ; } $ this -> reserved_range -> add ( $ value ) ; }
Add a new element to reserved_range
22,835
public function addReservedName ( $ value ) { if ( $ this -> reserved_name === null ) { $ this -> reserved_name = new \ Protobuf \ ScalarCollection ( ) ; } $ this -> reserved_name -> add ( $ value ) ; }
Add a new element to reserved_name
22,836
public function filterAction ( Request $ request , $ endpoint ) { $ form = $ this -> createForm ( CropType :: class ) ; $ form -> handleRequest ( $ request ) ; if ( ! $ form -> isValid ( ) ) { return $ this -> createErrorResponse ( $ this -> get ( 'translator' ) -> trans ( 'Invalid crop parameters' ) ) ; } try { return new JsonResponse ( $ this -> get ( 'jb_fileuploader.croper' ) -> crop ( $ endpoint , $ form -> getData ( ) ) ) ; } catch ( \ Exception $ e ) { return $ this -> createErrorResponse ( $ e -> getMessage ( ) ) ; } }
Filter for croping
22,837
protected function parseDateFromFilename ( $ filename ) { if ( $ date = \ DateTime :: createFromFormat ( self :: FILE_NAME_PATTERN , explode ( '_' , $ filename ) [ 0 ] ) ) { return $ date ; } return \ DateTime :: createFromFormat ( 'H-i-s-Y-m-d' , explode ( '_' , $ filename ) [ 0 ] ) ; }
Parse date from given filename .
22,838
public function prepare ( ) { if ( null === $ this -> statement ) { $ this -> statement = $ this -> db -> prepare ( $ this -> getSql ( ) ) ; } return $ this ; }
Prepare PDO statement
22,839
public function groupBy ( $ fields ) { if ( ! is_array ( $ fields ) ) { $ fields = $ this -> splitParts ( $ fields ) ; } foreach ( $ fields as $ k => $ field ) { $ fields [ $ k ] = $ this -> db -> quoteColumn ( $ field ) ; } $ this -> query [ 'group' ] = implode ( ',' , $ fields ) ; return $ this ; }
GROUP BY statement
22,840
public function buildQuery ( $ query = null ) { if ( null === $ query ) { $ query = $ this -> query ; } $ sql = "SELECT " ; if ( isset ( $ query [ 'distinct' ] ) && $ query [ 'distinct' ] ) { $ sql .= 'DISTINCT ' ; } $ sql .= isset ( $ query [ 'select' ] ) ? $ query [ 'select' ] : '*' ; if ( ! isset ( $ query [ 'from' ] ) ) { return false ; } $ sql .= "\nFROM " . $ query [ 'from' ] ; if ( isset ( $ query [ 'join' ] ) ) { $ sql .= "\n" . ( is_array ( $ query [ 'join' ] ) ? implode ( "\n" , $ query [ 'join' ] ) : $ query [ 'join' ] ) ; } if ( isset ( $ query [ 'where' ] ) && $ query [ 'where' ] !== '' ) { $ sql .= "\nWHERE " . $ query [ 'where' ] ; } if ( isset ( $ query [ 'group' ] ) ) { $ sql .= "\nGROUP BY " . $ query [ 'group' ] ; if ( isset ( $ query [ 'having' ] ) ) { $ sql .= "\nHAVING " . $ query [ 'having' ] ; } } if ( isset ( $ query [ 'order' ] ) ) { $ sql .= "\n ORDER BY " . $ query [ 'order' ] ; } $ limit = isset ( $ query [ 'limit' ] ) ? $ query [ 'limit' ] : 0 ; $ offset = isset ( $ query [ 'offset' ] ) ? $ query [ 'offset' ] : 0 ; $ sql = $ this -> db -> buildLimitOffset ( $ sql , $ limit , $ offset ) ; if ( isset ( $ query [ 'union' ] ) ) { $ sql .= "\n" . ( is_array ( $ query [ 'union' ] ) ? implode ( "\n" , $ query [ 'union' ] ) : $ query [ 'union' ] ) ; } return $ sql ; }
Build query SQL
22,841
public function setSql ( $ sql ) { if ( '' !== $ prefix = $ this -> db -> getPrefix ( ) ) { $ sql = preg_replace ( '#{{(.*?)}}#' , $ prefix . '\1' , $ sql ) ; } $ this -> sql = $ sql ; return $ this ; }
Set SQL for this command
22,842
public function getSql ( ) { if ( null === $ this -> sql ) { if ( ! empty ( $ this -> query ) ) { $ this -> setSql ( $ this -> buildQuery ( ) ) ; } else { return false ; } } return $ this -> sql ; }
Get SQL for this command
22,843
protected function beginQuery ( ) { $ autoSlave = $ this -> db -> isAutoSlave ( ) ; if ( $ autoSlave ) { $ this -> db -> switchConnection ( 'slave' ) ; } $ reconnect = $ this -> db -> getOption ( 'reconnect' ) ; $ reconnectRetries = $ this -> db -> getOption ( 'reconnect_retries' , 3 ) ; $ reconnectDelayMS = $ this -> db -> getOption ( 'reconnect_delay_ms' , 1000 ) ; while ( true ) { $ e = null ; $ errorCode = null ; $ errorInfo = null ; $ result = null ; $ isReconnectError = false ; try { $ this -> prepare ( ) ; $ result = $ this -> statement -> execute ( $ this -> params ? $ this -> params : $ this -> positionParams ) ; } catch ( \ Exception $ e ) { } if ( $ result === false || ! $ e ) { $ errorCode = $ this -> statement -> errorCode ( ) ; $ errorInfo = $ this -> statement -> errorInfo ( ) ; } $ isReconnectError = Util :: checkReconnectError ( $ errorCode , $ errorInfo , $ e ) ; if ( $ reconnect && $ isReconnectError && $ reconnectRetries > 0 ) { $ reconnectRetries -- ; $ this -> statement = null ; $ this -> db -> close ( ) ; $ reconnectDelayMS && usleep ( $ reconnectDelayMS * 1000 ) ; continue ; } break ; } if ( $ autoSlave ) { $ this -> db -> switchConnection ( ) ; } if ( $ e ) { $ this -> db -> logError ( sprintf ( 'Statement exception error #%s: %s' , $ e -> getCode ( ) , $ e -> getMessage ( ) ) ) ; throw $ e ; } if ( $ result === false ) { $ errorMsg = sprintf ( 'Statement execute error #%s: %s' , $ errorInfo [ 0 ] , $ errorInfo [ 2 ] ) ; $ this -> db -> logError ( $ errorMsg ) ; throw new Exception ( $ errorMsg ) ; } }
Prepare statement before query
22,844
public function queryAll ( $ params = array ( ) ) { $ this -> mergeParams ( $ params ) ; $ this -> beginQuery ( ) ; $ rst = $ this -> statement -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; $ this -> statement -> closeCursor ( ) ; return $ rst ; }
Get query result as array
22,845
public function queryRow ( $ params = array ( ) ) { $ this -> mergeParams ( $ params ) ; $ this -> beginQuery ( ) ; $ rst = $ this -> statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; $ this -> statement -> closeCursor ( ) ; return $ rst ; }
Get first row of result
22,846
public function queryColumn ( $ params = array ( ) ) { $ this -> mergeParams ( $ params ) ; $ this -> beginQuery ( ) ; $ rst = $ this -> statement -> fetchAll ( \ PDO :: FETCH_COLUMN ) ; $ this -> statement -> closeCursor ( ) ; return $ rst ; }
Get first column of result set
22,847
public function queryValue ( $ params = array ( ) ) { $ this -> mergeParams ( $ params ) ; $ this -> beginQuery ( ) ; $ rst = $ this -> statement -> fetchColumn ( ) ; $ this -> statement -> closeCursor ( ) ; return $ rst ; }
Get first column of first row of result set
22,848
public function execute ( $ params = array ( ) ) { $ this -> mergeParams ( $ params ) ; $ reconnect = $ this -> db -> getOption ( 'reconnect' ) ; $ reconnectRetries = $ this -> db -> getOption ( 'reconnect_retries' , 3 ) ; $ reconnectDelayMS = $ this -> db -> getOption ( 'reconnect_delay_ms' , 1000 ) ; while ( true ) { $ e = null ; $ errorCode = null ; $ errorInfo = null ; $ result = null ; $ isReconnectError = false ; try { $ this -> prepare ( ) ; foreach ( $ this -> positionParams as $ index => $ value ) { $ this -> statement -> bindValue ( $ index + 1 , $ value ) ; } $ result = $ this -> statement -> execute ( $ this -> params ? : null ) ; } catch ( \ Exception $ e ) { } if ( $ result === false || ! $ e ) { $ errorCode = $ this -> statement -> errorCode ( ) ; $ errorInfo = $ this -> statement -> errorInfo ( ) ; } $ isReconnectError = Util :: checkReconnectError ( $ errorCode , $ errorInfo , $ e ) ; if ( $ reconnect && $ isReconnectError && $ reconnectRetries > 0 ) { $ reconnectRetries -- ; $ this -> statement = null ; $ this -> db -> close ( ) ; $ reconnectDelayMS && usleep ( $ reconnectDelayMS * 1000 ) ; continue ; } break ; } if ( $ e ) { $ this -> db -> logError ( sprintf ( 'Statement exception error #%s: %s' , $ e -> getCode ( ) , $ e -> getMessage ( ) ) ) ; throw $ e ; } if ( $ result === false ) { $ this -> db -> logError ( sprintf ( 'Statement execute error #%s: %s' , $ errorInfo [ 0 ] , $ errorInfo [ 2 ] ) ) ; return false ; } return $ this -> statement -> rowCount ( ) ; }
Execute statement and return rows affected
22,849
public function computeTTL ( $ ttl = null ) { $ ttl = $ ttl ? : $ this -> defaultTTL ; if ( $ ttl === null ) { return null ; } return $ ttl + rand ( 0 , $ this -> ttlVariation ) ; }
Computes the final TTL taking into account the default ttl and the ttl variation
22,850
public function capturePage ( $ id = null , $ ttl = null , $ exit = true ) { if ( $ id === null ) { $ id = md5 ( serialize ( $ _SERVER [ 'REQUEST_URI' ] ) . serialize ( $ _REQUEST ) ) ; } if ( $ this -> start ( $ id ) ) { if ( $ exit ) { exit ; } return true ; } $ self = $ this ; register_shutdown_function ( function ( ) use ( $ self , $ ttl ) { $ self -> end ( $ ttl ) ; } ) ; return false ; }
Captures the whole output of the script until it ends .
22,851
public function pipeline ( $ callback = null ) { $ pipe = $ this -> createPipeline ( ) ; if ( $ callback === null ) { return $ pipe ; } call_user_func ( $ callback , $ pipe ) ; return $ pipe -> execute ( ) ; }
Creates a pipeline executes the callback which should use the provided pipeline object as its only argument without executing it . The pipeline will the be executed and its results will be returned .
22,852
public static function unIndexed ( $ name , $ value , $ encoding = 'UTF-8' ) { return new self ( $ name , $ value , $ encoding , true , false , false ) ; }
Constructs a String - valued Field that is not tokenized nor indexed but is stored in the index for return with hits .
22,853
protected function validateConfig ( $ key , array $ configuration , $ isFloat = false ) { if ( ! $ isFloat && ! ctype_digit ( ( string ) $ configuration [ $ key ] ) ) { throw new ValidationException ( sprintf ( '"%s" is not a valid %s configuration' , $ configuration [ $ key ] , $ key ) ) ; } if ( $ isFloat && ! is_numeric ( ( string ) $ configuration [ $ key ] ) ) { throw new ValidationException ( sprintf ( '"%s" is not a valid %s configuration' , $ configuration [ $ key ] , $ key ) ) ; } return true ; }
Validate configuration value
22,854
public function metadata ( $ path ) { $ writeBinn = new BinnList ; $ writeBinn -> addUint8 ( self :: FSERV_FILEINFO ) ; $ writeBinn -> addStr ( $ path ) ; $ read = $ this -> writeAndReadSocket ( $ writeBinn -> serialize ( ) ) ; $ readBinn = new BinnList ; $ readBinn -> binnOpen ( $ read ) ; $ results = $ readBinn -> unserialize ( ) ; if ( $ results [ 0 ] != self :: FSERV_STATUS_OK ) { throw new RuntimeException ( 'GDaemon metadata error:' . isset ( $ results [ 1 ] ) ? $ results [ 1 ] : 'Unknown' ) ; } $ fileInfo = $ results [ 2 ] ; return [ 'name' => basename ( $ fileInfo [ 0 ] ) , 'size' => $ fileInfo [ 1 ] , 'type' => ( $ fileInfo [ 2 ] == 1 ) ? 'dir' : 'file' , 'mtime' => $ fileInfo [ 3 ] , 'atime' => $ fileInfo [ 4 ] , 'ctime' => $ fileInfo [ 5 ] , 'permissions' => $ fileInfo [ 6 ] , 'mimetype' => $ fileInfo [ 7 ] , ] ; }
Get file metadata
22,855
public function chmod ( $ mode , $ path ) { $ writeBinn = new BinnList ; $ writeBinn -> addUint8 ( self :: FSERV_CHMOD ) ; $ writeBinn -> addStr ( $ path ) ; $ writeBinn -> addUint16 ( $ mode ) ; $ read = $ this -> writeAndReadSocket ( $ writeBinn -> serialize ( ) ) ; $ readBinn = new BinnList ; $ readBinn -> binnOpen ( $ read ) ; $ results = $ readBinn -> unserialize ( ) ; if ( $ results [ 0 ] != self :: FSERV_STATUS_OK ) { throw new RuntimeException ( 'Couldn\'t chmod: ' . isset ( $ results [ 1 ] ) ? $ results [ 1 ] : 'Unknown' ) ; } return true ; }
Change file mode
22,856
public function zip ( $ directory , $ fileName ) { $ path = sprintf ( '%s/%s/%s.zip' , $ this -> localDirectory , $ this -> name , $ fileName ) ; $ this -> filesystem -> mkdir ( dirname ( $ path ) ) ; $ this -> output -> writeln ( PHP_EOL . 'Creating zip file (it may take a few minutes) ...' ) ; $ zip = $ this -> openZip ( $ path ) ; $ files = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ directory ) ) ; foreach ( $ files as $ filePath => $ file ) { $ relative = Path :: makeRelative ( $ filePath , $ directory ) ; if ( is_dir ( $ filePath ) ) { $ zip -> addEmptyDir ( $ relative ) ; continue ; } $ zip -> addFile ( $ filePath , $ relative ) ; } $ zip -> close ( ) ; return $ path ; }
Creates a new zip from the given directory .
22,857
private function openZip ( $ path ) { $ zip = new \ ZipArchive ( ) ; if ( ! $ zip -> open ( $ path , \ ZipArchive :: CREATE ) ) { throw new IOException ( 'Cannot create zip file' ) ; } return $ zip ; }
Open zip from given path .
22,858
protected static function deleteHostedAppStorage ( $ id , $ storageServiceId , $ storageFolder ) { $ app = AppModel :: whereId ( $ id ) -> first ( ) ; if ( empty ( $ app ) && ! empty ( $ storageServiceId ) && ! empty ( $ storageFolder ) ) { $ storageService = ServiceManager :: getServiceById ( $ storageServiceId ) ; if ( $ storageService -> folderExists ( $ storageFolder ) ) { $ storageService -> deleteFolder ( $ storageFolder , true ) ; } } }
Deletes hosted app files from storage .
22,859
private function getHash ( $ stream , $ algorithm = 'sha256' ) { $ hash = hash_init ( $ algorithm ) ; hash_update_stream ( $ hash , $ stream ) ; return hash_final ( $ hash ) ; }
Returns hash for resource .
22,860
public function getRaw ( $ key = null ) { if ( null === $ key ) { return $ this -> _data ; } else { return isset ( $ this -> _data [ $ key ] ) ? $ this -> _data [ $ key ] : null ; } }
Get raw data
22,861
public function getWithRelation ( $ name ) { $ relations = $ this -> getRelations ( ) ; if ( isset ( $ relations [ $ name ] ) ) { $ relation = $ relations [ $ name ] ; if ( $ relation [ 'relation' ] === 'OTO' ) { return $ this -> getOneToOne ( $ relation [ 'target' ] , isset ( $ relation [ 'key' ] ) ? $ relation [ 'key' ] : null , isset ( $ relation [ 'target_key' ] ) ? $ relation [ 'target_key' ] : null ) ; } elseif ( $ relation [ 'relation' ] == 'OTM' ) { return $ this -> getOneToMany ( $ relation [ 'target' ] , isset ( $ relation [ 'key' ] ) ? $ relation [ 'key' ] : null , isset ( $ relation [ 'target_key' ] ) ? $ relation [ 'target_key' ] : null ) ; } elseif ( $ relation [ 'relation' ] == 'MTO' ) { return $ this -> getManyToOne ( $ relation [ 'target' ] , isset ( $ relation [ 'key' ] ) ? $ relation [ 'key' ] : null , isset ( $ relation [ 'target_key' ] ) ? $ relation [ 'target_key' ] : null ) ; } elseif ( $ relation [ 'relation' ] == 'MTM' ) { return $ this -> getManyToMany ( $ relation [ 'target' ] , $ relation [ 'through' ] , isset ( $ relation [ 'key' ] ) ? $ relation [ 'key' ] : null , isset ( $ relation [ 'target_key' ] ) ? $ relation [ 'target_key' ] : null ) ; } else { throw new Exception ( 'Invalid relation "' . $ relation [ 'relation' ] . '"' ) ; } } else { return false ; } }
Get a field with relation
22,862
public function getManyToMany ( $ target , $ through , $ key = null , $ target_key = null ) { $ factory = $ this -> _db -> factory ( $ target ) ; if ( null === $ key ) { $ key = $ this -> getPK ( ) ; } if ( null === $ target_key ) { $ target_key = $ factory -> getPK ( ) ; } $ through = $ this -> parseThrough ( $ through ) ; if ( ! $ through [ 1 ] ) { $ through [ 1 ] = $ key ; } if ( ! $ through [ 2 ] ) { $ through [ 2 ] = $ target_key ; } $ rows = $ this -> _db -> builder ( ) -> select ( 't.*' ) -> from ( $ factory -> getTable ( ) . ' t' ) -> leftJoin ( $ through [ 0 ] . ' m' , 'm.' . $ through [ 2 ] . '=t.' . $ target_key ) -> where ( 'm.' . $ through [ 1 ] . '=:value' , array ( ':value' => $ this -> get ( $ key ) ) ) -> queryAll ( ) ; if ( false === $ rows ) { return false ; } return $ factory -> mapModels ( $ rows ) ; }
Many to many
22,863
public function save ( ) { if ( $ this -> beforeSave ( ) ) { if ( $ this -> isNew ( ) ) { $ data = $ this -> _dirty ; if ( false !== $ rst = $ this -> _db -> builder ( ) -> insert ( $ this -> getTable ( ) , $ data ) ) { if ( is_string ( $ this -> getPK ( ) ) && $ id = $ this -> _db -> lastInsertId ( ) ) { $ data [ $ this -> getPK ( ) ] = $ id ; } $ this -> _data = $ data ; $ this -> _dirty = array ( ) ; $ this -> _isNew = false ; $ this -> afterSave ( ) ; return $ rst ; } } else { if ( $ this -> isDirty ( ) ) { $ pkConditions = $ this -> buildPKConditions ( ) ; if ( false !== $ rst = $ this -> _db -> builder ( ) -> update ( $ this -> getTable ( ) , $ this -> _dirty , $ pkConditions [ 0 ] , $ pkConditions [ 1 ] ) ) { $ this -> _data = array_merge ( $ this -> _data , $ this -> _dirty ) ; $ this -> _dirty = array ( ) ; $ this -> afterSave ( ) ; return $ rst ; } } } } return false ; }
Save modified data to db
22,864
public function createToc ( $ text , $ start = 2 , $ stop = 4 ) { $ level = "$start-$stop" ; $ pattern = "#<(h[$level])([^>]*)>(.*)</h[$level]>#" ; preg_match_all ( $ pattern , $ text , $ matches , PREG_SET_ORDER ) ; $ toc = [ ] ; foreach ( $ matches as $ val ) { preg_match ( "#id=['\"]([^>\"']+)#" , $ val [ 2 ] , $ id ) ; $ id = isset ( $ id [ 1 ] ) ? $ id [ 1 ] : null ; $ toc [ ] = [ "level" => isset ( $ val [ 1 ] ) ? $ val [ 1 ] : null , "title" => isset ( $ val [ 3 ] ) ? ltrim ( strip_tags ( $ val [ 3 ] ) , "#" ) : null , "id" => $ id , ] ; } return $ toc ; }
Create a TOC of HTML headings from and to a certain level .
22,865
public function addBaseurlToRelativeLinks ( $ text , $ baseurl , $ callback ) { $ pattern = "#<a(.+?)href=\"([^\"]*)\"([.^>]*)>#" ; return preg_replace_callback ( $ pattern , function ( $ matches ) use ( $ baseurl , $ callback ) { $ url = $ callback ( $ matches [ 2 ] , $ baseurl ) ; return "<a${matches[1]}href=\"$url\"${matches[3]}>" ; } , $ text ) ; }
Add baseurl to all relative links .
22,866
public function addBaseurlToImageSource ( $ text , $ baseurl , $ callback ) { $ pattern = "#<img(.+?)src=\"([^\"]*)\"(.*?)>#" ; return preg_replace_callback ( $ pattern , function ( $ matches ) use ( $ baseurl , $ callback ) { $ url = $ callback ( $ matches [ 2 ] , $ baseurl ) ; return "<img${matches[1]}src=\"$url\"${matches[3]}>" ; } , $ text ) ; }
Add baseurl to all relative links in image source .
22,867
public function addRevisionHistory ( $ text , $ revision , $ start , $ end , $ class , $ source = null ) { $ text = $ text . $ start ; $ text .= "<ul class=\"$class\">\n" ; foreach ( $ revision as $ date => $ info ) { $ text .= "<li>$date: $info</li>\n" ; } $ text .= "</ul>\n" ; if ( $ source ) { $ text .= "<p><a class=\"$class\" href=\"$source\">" . t ( "Document source" ) . "</a>.</p>\n" ; } $ text .= $ end ; return $ text ; }
Generate revision history and add to the end of content .
22,868
public function addFileToGenerate ( $ value ) { if ( $ this -> file_to_generate === null ) { $ this -> file_to_generate = new \ Protobuf \ ScalarCollection ( ) ; } $ this -> file_to_generate -> add ( $ value ) ; }
Add a new element to file_to_generate
22,869
public function addProtoFile ( \ google \ protobuf \ FileDescriptorProto $ value ) { if ( $ this -> proto_file === null ) { $ this -> proto_file = new \ Protobuf \ MessageCollection ( ) ; } $ this -> proto_file -> add ( $ value ) ; }
Add a new element to proto_file
22,870
protected function handlePOST ( ) { $ oldPassword = $ this -> getPayloadData ( 'old_password' ) ; $ newPassword = $ this -> getPayloadData ( 'new_password' ) ; $ login = $ this -> request -> getParameterAsBool ( 'login' ) ; if ( ! empty ( $ oldPassword ) && Session :: isAuthenticated ( ) ) { $ user = Session :: user ( ) ; return static :: changePassword ( $ user , $ oldPassword , $ newPassword , $ login ) ; } $ email = $ this -> getPayloadData ( 'email' ) ; $ username = $ this -> getPayloadData ( 'username' ) ; $ code = $ this -> getPayloadData ( 'code' ) ; $ answer = $ this -> getPayloadData ( 'security_answer' ) ; $ loginAttribute = strtolower ( config ( 'df.login_attribute' , 'email' ) ) ; if ( $ this -> request -> getParameterAsBool ( 'reset' ) ) { if ( $ loginAttribute === 'username' ) { return $ this -> passwordResetWithUsername ( $ username ) ; } return $ this -> passwordReset ( $ email ) ; } if ( ! empty ( $ code ) ) { if ( $ loginAttribute === 'username' ) { return static :: changePasswordByCodeWithUsername ( $ username , $ code , $ newPassword , $ login ) ; } return static :: changePasswordByCode ( $ email , $ code , $ newPassword , $ login ) ; } if ( ! empty ( $ answer ) ) { if ( $ loginAttribute === 'username' ) { return static :: changePasswordBySecurityAnswerWithUsername ( $ username , $ answer , $ newPassword , $ login ) ; } return static :: changePasswordBySecurityAnswer ( $ email , $ answer , $ newPassword , $ login ) ; } throw new BadRequestException ( 'Not enough information provided to change password.' ) ; }
Resets user password .
22,871
public static function changePasswordByCode ( $ email , $ code , $ newPassword , $ login = true ) { if ( empty ( $ email ) ) { throw new BadRequestException ( "Missing required email for password reset confirmation." ) ; } if ( empty ( $ newPassword ) ) { throw new BadRequestException ( "Missing new password for reset." ) ; } if ( empty ( $ code ) || 'y' == $ code ) { throw new BadRequestException ( "Invalid confirmation code." ) ; } $ user = User :: whereEmail ( $ email ) -> whereConfirmCode ( $ code ) -> first ( ) ; if ( null === $ user ) { throw new NotFoundException ( "The supplied email and/or confirmation code were not found in the system." ) ; } elseif ( $ user -> isConfirmationExpired ( ) ) { throw new BadRequestException ( "Confirmation code expired." ) ; } static :: isAllowed ( $ user ) ; try { $ user -> confirm_code = 'y' ; $ user -> password = $ newPassword ; $ user -> save ( ) ; } catch ( \ Exception $ ex ) { throw new InternalServerErrorException ( "Error processing password reset.\n{$ex->getMessage()}" ) ; } if ( $ login ) { static :: userLogin ( $ email , $ newPassword ) ; return [ 'success' => true , 'session_token' => Session :: getSessionToken ( ) ] ; } return [ 'success' => true ] ; }
Changes password by confirmation code .
22,872
protected static function changePasswordBySecurityAnswer ( $ email , $ answer , $ newPassword , $ login = true ) { if ( empty ( $ email ) ) { throw new BadRequestException ( "Missing required email for password reset confirmation." ) ; } if ( empty ( $ newPassword ) ) { throw new BadRequestException ( "Missing new password for reset." ) ; } if ( empty ( $ answer ) ) { throw new BadRequestException ( "Missing security answer." ) ; } $ user = User :: whereEmail ( $ email ) -> first ( ) ; if ( null === $ user ) { throw new NotFoundException ( "The supplied email and confirmation code were not found in the system." ) ; } static :: isAllowed ( $ user ) ; try { $ isValid = \ Hash :: check ( $ answer , $ user -> security_answer ) ; } catch ( \ Exception $ ex ) { throw new InternalServerErrorException ( "Error validating security answer.\n{$ex->getMessage()}" ) ; } if ( ! $ isValid ) { throw new BadRequestException ( "The answer supplied does not match." ) ; } try { $ user -> password = $ newPassword ; $ user -> save ( ) ; } catch ( \ Exception $ ex ) { throw new InternalServerErrorException ( "Error processing password change.\n{$ex->getMessage()}" ) ; } if ( $ login ) { static :: userLogin ( $ email , $ newPassword ) ; return [ 'success' => true , 'session_token' => Session :: getSessionToken ( ) ] ; } return [ 'success' => true ] ; }
Changes password by security answer .
22,873
protected function sendPasswordResetEmail ( User $ user ) { $ email = $ user -> email ; $ parent = $ this -> getService ( ) ; if ( ! empty ( $ parent -> passwordEmailServiceId ) ) { try { $ emailService = ServiceManager :: getServiceById ( $ parent -> passwordEmailServiceId ) ; if ( empty ( $ emailService ) ) { throw new ServiceUnavailableException ( "Bad email service identifier." ) ; } $ data = [ ] ; if ( ! empty ( $ parent -> passwordEmailTemplateId ) ) { $ template = EmailTemplate :: whereId ( $ parent -> passwordEmailTemplateId ) -> first ( ) ; if ( empty ( $ template ) ) { throw new NotFoundException ( "Email Template id '{$parent->passwordEmailTemplateId}' not found" ) ; } $ data = $ template -> toArray ( ) ; } if ( empty ( $ data ) || ! is_array ( $ data ) ) { throw new ServiceUnavailableException ( "No data found in default email template for password reset." ) ; } $ data [ 'to' ] = $ email ; $ data [ 'content_header' ] = 'Password Reset' ; $ data [ 'first_name' ] = $ user -> first_name ; $ data [ 'last_name' ] = $ user -> last_name ; $ data [ 'name' ] = $ user -> name ; $ data [ 'phone' ] = $ user -> phone ; $ data [ 'email' ] = $ user -> email ; $ data [ 'link' ] = url ( \ Config :: get ( 'df.confirm_reset_url' ) ) . '?code=' . $ user -> confirm_code . '&email=' . $ email . '&username=' . $ user -> username . '&admin=' . $ user -> is_sys_admin ; $ data [ 'confirm_code' ] = $ user -> confirm_code ; $ bodyHtml = array_get ( $ data , 'body_html' ) ; $ bodyText = array_get ( $ data , 'body_text' ) ; if ( empty ( $ bodyText ) && ! empty ( $ bodyHtml ) ) { $ bodyText = strip_tags ( $ bodyHtml ) ; $ bodyText = preg_replace ( '/ +/' , ' ' , $ bodyText ) ; } $ emailService -> sendEmail ( $ data , $ bodyText , $ bodyHtml ) ; return true ; } catch ( \ Exception $ ex ) { throw new InternalServerErrorException ( "Error processing password reset.\n{$ex->getMessage()}" ) ; } } return false ; }
Sends the user an email with password reset link .
22,874
public function filter ( $ string , $ replacement = '' ) { if ( $ replacement !== '' ) { return preg_replace_callback ( static :: REGEX_ANSI , function ( $ matches ) use ( $ replacement ) { return str_repeat ( $ replacement , mb_strlen ( $ matches [ 0 ] ) ) ; } , $ string ) ; } return preg_replace ( static :: REGEX_ANSI , $ replacement , $ string ) ; }
Filter takes a string with Cursor movements and filters them out
22,875
public function getCurrentFormatting ( $ string ) { $ stack = [ ] ; foreach ( $ this -> getStyleStack ( $ string ) as $ style ) { if ( preg_match ( static :: REGEX_FIRST_KEY , $ style , $ matches ) ) { $ key = $ matches [ 0 ] ; if ( array_key_exists ( $ key , $ this -> formats ) ) { $ stack [ ] = [ 'key' => $ key , 'style' => $ style ] ; } else { if ( $ key === static :: STYLE_RESET ) { $ stack = [ ] ; } else { $ stack = array_filter ( $ stack , function ( $ item ) use ( $ key ) { return ! in_array ( $ key , $ this -> formats [ $ item [ 'key' ] ] ) ; } ) ; } } } } if ( count ( $ stack ) === 0 ) { return '' ; } $ items = array_map ( function ( $ item ) { return $ item [ 'style' ] ; } , $ stack ) ; return sprintf ( static :: ESCAPE . '[%sm' , implode ( ';' , $ items ) ) ; }
Gets the styling that would be active at the end of this string
22,876
private function getStyleStack ( $ string ) { if ( preg_match_all ( static :: REGEX_FORMAT , $ string , $ matches ) ) { foreach ( $ matches [ 1 ] as $ grouping ) { if ( preg_match_all ( static :: REGEX_STYLE_ITEM , $ grouping , $ styles ) ) { foreach ( $ styles [ 0 ] as $ style ) { yield $ style ; } } else { yield static :: STYLE_RESET ; } } } return ; }
Get all the styles in order that should be applied at the end
22,877
protected function getAuthUserId ( ) { $ token = $ this -> tokenStorage -> getToken ( ) ; if ( null === $ token ) { return ; } $ user = $ token -> getUser ( ) ; if ( ! is_object ( $ user ) ) { return ; } return $ user -> getId ( ) ; }
Get authenticated user id
22,878
public function addToken ( int $ symbolId , int ... $ tokenIdList ) : void { if ( empty ( $ tokenIdList ) ) { return ; } if ( ! isset ( $ this -> tokenMap [ $ symbolId ] ) ) { $ this -> tokenMap [ $ symbolId ] = $ tokenIdList ; $ this -> increaseChangeCount ( count ( $ tokenIdList ) ) ; return ; } $ newTokenIdList = array_diff ( $ tokenIdList , $ this -> tokenMap [ $ symbolId ] ) ; if ( empty ( $ newTokenIdList ) ) { return ; } $ this -> tokenMap [ $ symbolId ] = array_merge ( $ this -> tokenMap [ $ symbolId ] , $ newTokenIdList ) ; $ this -> increaseChangeCount ( count ( $ newTokenIdList ) ) ; }
Adds list of tokens to the set .
22,879
public function mergeTokens ( int $ targetSymbolId , int $ sourceSymbolId ) : void { $ this -> addToken ( $ targetSymbolId , ... $ this -> getTokens ( $ sourceSymbolId ) ) ; }
Merges token sets .
22,880
protected function processImages ( ) { $ storeViewCode = $ this -> getValue ( ColumnKeys :: STORE_VIEW_CODE ) ; $ attributeSetCode = $ this -> getValue ( ColumnKeys :: ATTRIBUTE_SET_CODE ) ; $ parentSku = $ this -> getValue ( ColumnKeys :: SKU ) ; foreach ( $ this -> getImageTypes ( ) as $ imageColumnName => $ labelColumnName ) { if ( $ image = $ this -> getValue ( $ imageColumnName ) ) { $ labelText = $ this -> getDefaultImageLabel ( ) ; if ( $ this -> hasValue ( $ labelColumnName ) ) { $ labelText = $ this -> getValue ( $ labelColumnName ) ; } $ artefact = $ this -> newArtefact ( array ( ColumnKeys :: STORE_VIEW_CODE => $ storeViewCode , ColumnKeys :: ATTRIBUTE_SET_CODE => $ attributeSetCode , ColumnKeys :: IMAGE_PARENT_SKU => $ parentSku , ColumnKeys :: IMAGE_PATH => $ image , ColumnKeys :: IMAGE_PATH_NEW => $ image , ColumnKeys :: IMAGE_LABEL => $ labelText ) , array ( ColumnKeys :: STORE_VIEW_CODE => ColumnKeys :: STORE_VIEW_CODE , ColumnKeys :: ATTRIBUTE_SET_CODE => ColumnKeys :: ATTRIBUTE_SET_CODE , ColumnKeys :: IMAGE_PARENT_SKU => ColumnKeys :: SKU , ColumnKeys :: IMAGE_PATH => $ imageColumnName , ColumnKeys :: IMAGE_PATH_NEW => $ imageColumnName , ColumnKeys :: IMAGE_LABEL => $ labelColumnName ) ) ; $ this -> artefacts [ ] = $ artefact ; } } }
Parses the column and exports the image data to a separate file .
22,881
protected function processAdditionalImages ( ) { $ storeViewCode = $ this -> getValue ( ColumnKeys :: STORE_VIEW_CODE ) ; $ attributeSetCode = $ this -> getValue ( ColumnKeys :: ATTRIBUTE_SET_CODE ) ; $ parentSku = $ this -> getValue ( ColumnKeys :: SKU ) ; if ( $ additionalImages = $ this -> getValue ( ColumnKeys :: ADDITIONAL_IMAGES , null , array ( $ this , 'explode' ) ) ) { $ additionalImageLabels = $ this -> getValue ( ColumnKeys :: ADDITIONAL_IMAGE_LABELS , array ( ) , array ( $ this , 'explode' ) ) ; foreach ( $ additionalImages as $ key => $ additionalImage ) { $ artefact = $ this -> newArtefact ( array ( ColumnKeys :: STORE_VIEW_CODE => $ storeViewCode , ColumnKeys :: ATTRIBUTE_SET_CODE => $ attributeSetCode , ColumnKeys :: IMAGE_PARENT_SKU => $ parentSku , ColumnKeys :: IMAGE_PATH => $ additionalImage , ColumnKeys :: IMAGE_PATH_NEW => $ additionalImage , ColumnKeys :: IMAGE_LABEL => isset ( $ additionalImageLabels [ $ key ] ) ? $ additionalImageLabels [ $ key ] : $ this -> getDefaultImageLabel ( ) ) , array ( ColumnKeys :: STORE_VIEW_CODE => ColumnKeys :: STORE_VIEW_CODE , ColumnKeys :: ATTRIBUTE_SET_CODE => ColumnKeys :: ATTRIBUTE_SET_CODE , ColumnKeys :: IMAGE_PARENT_SKU => ColumnKeys :: SKU , ColumnKeys :: IMAGE_PATH => ColumnKeys :: ADDITIONAL_IMAGES , ColumnKeys :: IMAGE_PATH_NEW => ColumnKeys :: ADDITIONAL_IMAGES , ColumnKeys :: IMAGE_LABEL => ColumnKeys :: ADDITIONAL_IMAGE_LABELS ) ) ; $ this -> artefacts [ ] = $ artefact ; } } }
Parses the column and exports the additional image data to a separate file .
22,882
public function back ( ) { $ viewModel = new ViewModel ( ) ; $ viewModel -> setTemplate ( 'MelisFront/dragdropzone/meliscontainer' ) ; $ viewModel -> pluginFrontConfig = $ this -> pluginFrontConfig ; $ viewModel -> dragdropzoneId = $ this -> pluginFrontConfig [ 'id' ] ; $ viewModel -> configPluginKey = $ this -> configPluginKey ; $ viewModel -> pluginName = $ this -> pluginName ; $ viewModel -> pluginXmlDbKey = $ this -> pluginXmlDbKey ; $ pageId = ( ! empty ( $ this -> pluginFrontConfig [ 'pageId' ] ) ) ? $ this -> pluginFrontConfig [ 'pageId' ] : 0 ; $ siteModule = getenv ( 'MELIS_MODULE' ) ; $ melisPage = $ this -> getServiceLocator ( ) -> get ( 'MelisEnginePage' ) ; $ datasPage = $ melisPage -> getDatasPage ( $ pageId , 'saved' ) ; if ( $ datasPage ) { $ datasTemplate = $ datasPage -> getMelisTemplate ( ) ; if ( ! empty ( $ datasTemplate ) ) { $ siteModule = $ datasTemplate -> tpl_zf2_website_folder ; } } $ viewModel -> siteModule = $ siteModule ; return $ viewModel ; }
Redefining the back function as the display of tags is specific with TinyMce
22,883
public function parseFeedback ( $ opts ) { $ parsedQuestions = [ ] ; $ scoreMax = 0 ; $ scoreRaw = 0 ; foreach ( $ opts [ 'questions' ] as $ item => $ question ) { $ currentResponse = null ; foreach ( $ opts [ 'attempt' ] -> responses as $ responseId => $ response ) { if ( ! empty ( $ response -> item ) && $ response -> item == $ item ) { $ currentResponse = $ response ; } } if ( is_null ( $ currentResponse ) ) { break ; } $ parsedQuestion = ( object ) [ 'question' => $ question , 'options' => $ this -> parseQuestionPresentation ( $ question -> presentation , $ question -> typ ) , 'score' => ( object ) [ 'max' => 0 , 'raw' => 0 ] , 'response' => null ] ; $ parsedQuestion -> response = $ currentResponse -> id ; foreach ( $ parsedQuestion -> options as $ optionIndex => $ option ) { if ( isset ( $ option -> value ) && $ option -> value > $ parsedQuestion -> score -> max ) { $ parsedQuestion -> score -> max = $ option -> value ; } if ( $ optionIndex == $ currentResponse -> id ) { if ( isset ( $ option -> value ) ) { $ parsedQuestion -> score -> raw = $ option -> value ; } } } $ scoreMax += $ parsedQuestion -> score -> max ; $ scoreRaw += $ parsedQuestion -> score -> raw ; if ( $ parsedQuestion -> score -> max == 0 ) { $ parsedQuestion -> score -> max = null ; $ parsedQuestion -> score -> raw = null ; } else { $ parsedQuestion -> score -> min = 0 ; $ parsedQuestion -> score -> scaled = $ parsedQuestion -> score -> raw / $ parsedQuestion -> score -> max ; } array_push ( $ parsedQuestions , $ parsedQuestion ) ; } $ scoreMin = null ; $ scoreScaled = null ; if ( $ scoreMax == 0 ) { $ scoreMax = null ; $ scoreRaw = null ; } else { $ scoreScaled = $ scoreRaw / $ scoreMax ; $ scoreMin = 0 ; } return ( object ) [ 'questions' => $ parsedQuestions , 'score' => ( object ) [ 'max' => $ scoreMax , 'raw' => $ scoreRaw , 'min' => $ scoreMin , 'scaled' => $ scoreScaled ] ] ; }
Converts a outputs feedback question and result data in a more manageable format
22,884
protected function parseQuestionPresentation ( $ presentation , $ type ) { if ( $ type == 'textarea' ) { return [ ] ; } $ presentation = str_replace ( 'r>>>>>' , '' , $ presentation ) ; $ presentation = trim ( preg_replace ( '/\s+/' , ' ' , $ presentation ) ) ; $ presentation = strip_tags ( $ presentation ) ; $ options = explode ( '|' , $ presentation ) ; $ return = [ ( object ) [ 'description' => 'Not selected' ] ] ; foreach ( $ options as $ index => $ option ) { switch ( $ type ) { case 'multichoice' : array_push ( $ return , ( object ) [ 'description' => $ option ] ) ; break ; case 'multichoicerated' : $ optionArr = explode ( '#### ' , $ option ) ; array_push ( $ return , ( object ) [ 'description' => $ optionArr [ 1 ] , 'value' => $ optionArr [ 0 ] ] ) ; break ; default : return [ ] ; break ; } } return $ return ; }
Converts a feedback item presentation string into an array
22,885
public function setLabel ( \ google \ protobuf \ FieldDescriptorProto \ Label $ value = null ) { $ this -> label = $ value ; }
Set label value
22,886
public function setType ( \ google \ protobuf \ FieldDescriptorProto \ Type $ value = null ) { $ this -> type = $ value ; }
Set type value
22,887
public function get ( $ name ) { if ( isset ( $ this -> container [ 'CI' ] -> { $ name } ) ) { return $ this -> container [ 'CI' ] -> { $ name } ; } return $ this -> container [ $ name ] ; }
Access to CI data or container data
22,888
protected function initializeProductMediaGalleryValue ( array $ attr ) { $ valueId = $ attr [ MemberNames :: VALUE_ID ] ; $ storeId = $ attr [ MemberNames :: STORE_ID ] ; $ entityId = $ attr [ MemberNames :: ENTITY_ID ] ; if ( $ entity = $ this -> loadProductMediaGalleryValue ( $ valueId , $ storeId , $ entityId ) ) { return $ this -> mergeEntity ( $ entity , $ attr ) ; } return $ attr ; }
Initialize the product media gallery value with the passed attributes and returns an instance .
22,889
public function toArray ( ) { return [ 'name' => $ this -> name , 'label' => $ this -> label , 'description' => $ this -> description , 'class_name' => $ this -> className , 'singleton' => $ this -> singleton , 'read_only' => $ this -> readOnly , 'subscription_required' => $ this -> subscriptionRequired , ] ; }
The configuration handler interface for this system resource type
22,890
public function add ( Route $ route , array $ params = [ ] ) { $ callback = $ route -> getCallable ( ) ; if ( empty ( $ callback ) ) { return ; } $ this -> routes [ ] = $ route -> getRoute ( ) ; $ paramNames = $ route -> getParamNames ( ) ; foreach ( $ paramNames as $ name ) { if ( isset ( $ params [ $ name ] ) ) { $ this -> setParam ( $ name , $ params [ $ name ] ) ; } } if ( is_array ( $ callback ) ) { $ this -> callable = array_merge ( $ this -> callable , $ callback ) ; } elseif ( ! in_array ( $ callback , $ this -> callable ) ) { $ this -> callable [ ] = $ callback ; } }
add request handle
22,891
public function transducer ( RequestInterface $ request ) { $ response = null ; if ( count ( $ this -> middleware ) ) { $ md = array_pop ( $ this -> middleware ) ; $ next = function ( RequestInterface $ request ) { return $ this -> transducer ( $ request ) ; } ; if ( is_callable ( $ md ) ) { $ response = $ md ( $ request , $ next ) ; } elseif ( is_array ( $ md ) ) { list ( $ class , $ action ) = $ md ; $ instance = is_object ( $ class ) ? $ class : new $ class ( ) ; $ response = $ instance -> $ action ( $ request , $ next ) ; } if ( $ response instanceof Generator ) { $ response = Poroutine :: resolve ( $ response ) ; } } return $ response ?? new Response ( ) ; }
Iterative process the request
22,892
public static function registerAllExtensions ( \ Protobuf \ Extension \ ExtensionRegistry $ registry ) { $ registry -> add ( self :: package ( ) ) ; $ registry -> add ( self :: genericServices ( ) ) ; }
Register all extensions
22,893
private function addToChangeSet ( EntityManagerInterface $ em , ClassMetadata $ metadata , $ entity , array & $ change_set ) { if ( ! isset ( $ change_set [ $ metadata -> rootEntityName ] ) ) { $ change_set [ $ metadata -> rootEntityName ] = [ ] ; } if ( ! in_array ( $ entity , $ change_set [ $ metadata -> rootEntityName ] , true ) ) { $ change_set [ $ metadata -> rootEntityName ] [ ] = $ entity ; $ this -> appendAssociations ( $ em , $ metadata , $ entity , $ change_set ) ; } }
Add an entity to the change set . This also adds any elements to the change set that are in the associations .
22,894
public function show ( $ slug ) { $ model = $ this -> repository -> bySlug ( $ slug , [ 'translations' , 'files' , 'files.translations' ] ) ; return view ( 'galleries::public.show' ) -> with ( compact ( 'model' ) ) ; }
Show gallery .
22,895
public function getTime ( ) { $ time = 0 ; foreach ( $ this -> data [ 'queries' ] as $ query ) { $ time += ( float ) $ query [ 'time' ] ; } return $ time ; }
Returns the total time spent on running all queries .
22,896
private function buildQueries ( ) { $ queries = array ( ) ; $ outerGlue = $ this -> propelConfiguration -> getParameter ( 'debugpdo.logging.outerglue' , ' | ' ) ; $ innerGlue = $ this -> propelConfiguration -> getParameter ( 'debugpdo.logging.innerglue' , ': ' ) ; foreach ( $ this -> logger -> getQueries ( ) as $ q ) { $ parts = explode ( $ outerGlue , $ q , 4 ) ; $ times = explode ( $ innerGlue , $ parts [ 0 ] ) ; $ con = explode ( $ innerGlue , $ parts [ 2 ] ) ; $ memories = explode ( $ innerGlue , $ parts [ 1 ] ) ; $ sql = trim ( $ parts [ 3 ] ) ; $ con = trim ( $ con [ 1 ] ) ; $ time = trim ( $ times [ 1 ] ) ; $ memory = trim ( $ memories [ 1 ] ) ; $ queries [ ] = array ( 'connection' => $ con , 'sql' => $ sql , 'time' => $ time , 'memory' => $ memory ) ; } return $ queries ; }
Computes the stats of all executed SQL queries .
22,897
public function onRestoreStarted ( RestoreEvent $ event ) { $ database = $ event -> getDatabase ( ) ; if ( $ database -> getWithDefault ( 'state' , BackupStatus :: STATE_SUCCESS ) === BackupStatus :: STATE_FAILED ) { $ this -> output -> writeln ( ' <info>Bypassed</info>' ) ; $ event -> stopPropagation ( ) ; } }
Bypasses failed backup in restore process .
22,898
public function bootGedmoExtensions ( $ namespaces = [ 'App' ] , $ all = true ) { if ( $ all ) { DoctrineExtensions :: registerMappingIntoDriverChainORM ( $ this -> chain , $ this -> reader ) ; } else { DoctrineExtensions :: registerAbstractMappingIntoDriverChainORM ( $ this -> chain , $ this -> reader ) ; } $ driver = $ this -> metadata -> getMetadataDriverImpl ( ) ; foreach ( $ namespaces as $ namespace ) { $ this -> chain -> addDriver ( $ driver , $ namespace ) ; } $ this -> metadata -> setMetadataDriverImpl ( $ this -> chain ) ; $ this -> dispatcher -> fire ( 'doctrine.driver-chain::booted' , [ $ driver , $ this -> chain ] ) ; }
Enable Gedmo Doctrine Extensions
22,899
public function setCtype ( \ google \ protobuf \ FieldOptions \ CType $ value = null ) { $ this -> ctype = $ value ; }
Set ctype value