idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
1,100
|
private function check ( string $ uuid ) : void { $ uuid32 = \ str_replace ( '-' , '' , $ uuid ) ; if ( \ preg_match ( '/^[0-9a-f]{8}[0-9a-f]{4}[4][0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12}$/i' , $ uuid32 ) !== 1 ) { throw new InvalidArgumentException ( 'Invalid UUID version 4 provided.' ) ; } $ this -> hexUUID = $ uuid ; }
|
Check UUID .
|
1,101
|
private function generate ( ) : void { $ this -> hexUUID = \ sprintf ( '%s-%s-%s-%s-%s' , \ bin2hex ( \ random_bytes ( 4 ) ) , \ bin2hex ( \ random_bytes ( 2 ) ) , \ dechex ( \ random_int ( 16384 , 20479 ) ) , \ dechex ( \ random_int ( 32768 , 49151 ) ) , \ bin2hex ( \ random_bytes ( 6 ) ) ) ; }
|
Generate a random UUID v4 in hex format .
|
1,102
|
public function canById ( int $ permissionId ) : bool { if ( isset ( $ this -> permission [ $ permissionId ] ) ) { return true ; } return false ; }
|
Check if a Permission is owned use permission Id .
|
1,103
|
public function canByName ( string $ permissionName ) : bool { if ( \ in_array ( $ permissionName , \ array_column ( $ this -> permission , 'name' ) , true ) ) { return true ; } return false ; }
|
Check if a Permission is owned use permission name .
|
1,104
|
protected static function createNew ( int $ ttl , TokenOwnerInterface $ owner = null , Client $ client = null , array $ scopes = null ) : self { if ( is_array ( $ scopes ) ) { $ scopes = array_map ( function ( $ scope ) { return ( string ) $ scope ; } , $ scopes ) ; } $ token = new static ( ) ; $ token -> token = bin2hex ( random_bytes ( 20 ) ) ; $ token -> owner = $ owner ; $ token -> client = $ client ; $ token -> scopes = $ scopes ?? [ ] ; $ token -> expiresAt = $ ttl ? ( new DateTime ( '@' . time ( ) , new DateTimeZone ( 'UTC' ) ) ) -> modify ( "+$ttl seconds" ) : null ; return $ token ; }
|
Create a new AbstractToken
|
1,105
|
public function matchScopes ( $ scopes ) : bool { $ scopes = is_string ( $ scopes ) ? explode ( ' ' , $ scopes ) : $ scopes ; $ diff = array_diff ( $ scopes , $ this -> scopes ) ; return empty ( $ diff ) ; }
|
Match the scopes of the token with the one provided in the parameter
|
1,106
|
private function doesFileChecksFailed ( string $ file ) : bool { if ( ! \ file_exists ( $ file ) ) { return true ; } $ cacheValue = include $ file ; if ( $ cacheValue [ 'expires' ] <= \ time ( ) && $ cacheValue [ 'expires' ] !== 0 ) { \ unlink ( $ file ) ; return true ; } return false ; }
|
Checks for cache file .
|
1,107
|
public function isUserInRoleById ( int $ userId ) : bool { if ( isset ( $ this -> users [ $ userId ] ) ) { return true ; } return false ; }
|
Check if an user is in role use the user Id .
|
1,108
|
public function isUserInRoleByName ( string $ userName ) : bool { if ( \ in_array ( $ userName , \ array_column ( $ this -> users , 'name' ) , true ) ) { return true ; } return false ; }
|
Check if an user is in role use the user name .
|
1,109
|
private function executeColumnWidths ( ) : void { $ this -> loadOldColumns ( ) ; $ this -> loadColumns ( ) ; $ this -> enhanceColumns ( ) ; $ this -> mergeColumns ( ) ; $ this -> writeColumns ( ) ; }
|
Gathers constants based on column widths .
|
1,110
|
private function executeEnabled ( ) : void { if ( $ this -> constantsFilename !== null ) { $ this -> executeColumnWidths ( ) ; } if ( $ this -> className !== null ) { $ this -> executeCreateConstants ( ) ; } $ this -> logNumberOfConstants ( ) ; }
|
Executes the enabled functionalities .
|
1,111
|
private function loadLabels ( ) : void { $ tables = DataLayer :: getLabelTables ( ) ; foreach ( $ tables as $ table ) { $ rows = DataLayer :: getLabelsFromTable ( $ table [ 'table_name' ] , $ table [ 'id' ] , $ table [ 'label' ] ) ; foreach ( $ rows as $ row ) { $ this -> labels [ $ row [ 'label' ] ] = $ row [ 'id' ] ; } } }
|
Loads all primary key labels from the MySQL database .
|
1,112
|
private function logNumberOfConstants ( ) : void { $ n_id = sizeof ( $ this -> labels ) ; $ n_len = sizeof ( $ this -> constants ) - $ n_id ; $ this -> io -> writeln ( '' ) ; $ this -> io -> text ( sprintf ( 'Number of constants based on column widths: %d' , $ n_len ) ) ; $ this -> io -> text ( sprintf ( 'Number of constants based on database IDs : %d' , $ n_id ) ) ; }
|
Logs the number of constants generated .
|
1,113
|
private function makeConstantStatements ( ) : array { $ width1 = 0 ; $ width2 = 0 ; $ constants = [ ] ; foreach ( $ this -> constants as $ constant => $ value ) { $ width1 = max ( mb_strlen ( $ constant ) , $ width1 ) ; $ width2 = max ( mb_strlen ( ( string ) $ value ) , $ width2 ) ; } $ line_format = sprintf ( ' const %%-%ds = %%%dd;' , $ width1 , $ width2 ) ; foreach ( $ this -> constants as $ constant => $ value ) { $ constants [ ] = sprintf ( $ line_format , $ constant , $ value ) ; } return $ constants ; }
|
Generates PHP code with constant declarations .
|
1,114
|
private function readConfigFile ( string $ configFilename ) : array { $ settings = parse_ini_file ( $ configFilename , true ) ; $ this -> constantsFilename = self :: getSetting ( $ settings , false , 'constants' , 'columns' ) ; $ this -> className = self :: getSetting ( $ settings , false , 'constants' , 'class' ) ; return $ settings ; }
|
Reads configuration parameters from the configuration file .
|
1,115
|
private static function extractColumnsFromTableDescription ( array $ description ) : array { $ ret = [ ] ; foreach ( $ description as $ column ) { preg_match ( '/^(\w+)(.*)?$/' , $ column [ 'Type' ] , $ parts1 ) ; $ tmp = [ 'column_name' => $ column [ 'Field' ] , 'data_type' => $ parts1 [ 1 ] , 'numeric_precision' => null , 'numeric_scale' => null , 'dtd_identifier' => $ column [ 'Type' ] ] ; switch ( $ parts1 [ 1 ] ) { case 'tinyint' : case 'smallint' : case 'mediumint' : case 'int' : case 'bigint' : preg_match ( '/^\((\d+)\)/' , $ parts1 [ 2 ] , $ parts2 ) ; $ tmp [ 'numeric_precision' ] = ( int ) $ parts2 [ 1 ] ; $ tmp [ 'numeric_scale' ] = 0 ; break ; case 'year' : break ; case 'float' : $ tmp [ 'numeric_precision' ] = 12 ; break ; case 'double' : $ tmp [ 'numeric_precision' ] = 22 ; break ; case 'binary' : case 'char' : case 'varbinary' : case 'varchar' : break ; case 'decimal' : preg_match ( '/^\((\d+),(\d+)\)$/' , $ parts1 [ 2 ] , $ parts2 ) ; $ tmp [ 'numeric_precision' ] = ( int ) $ parts2 [ 1 ] ; $ tmp [ 'numeric_scale' ] = ( int ) $ parts2 [ 2 ] ; ; break ; case 'time' : case 'timestamp' : case 'date' : case 'datetime' : break ; case 'enum' : case 'set' : break ; case 'bit' : preg_match ( '/^\((\d+)\)$/' , $ parts1 [ 2 ] , $ parts2 ) ; $ tmp [ 'numeric_precision' ] = ( int ) $ parts2 [ 1 ] ; break ; case 'tinytext' : case 'text' : case 'mediumtext' : case 'longtext' : case 'tinyblob' : case 'blob' : case 'mediumblob' : case 'longblob' : break ; default : throw new FallenException ( 'data type' , $ parts1 [ 1 ] ) ; } $ ret [ ] = $ tmp ; } return $ ret ; }
|
Extract column metadata from the rows returend by the SQL statement describe table .
|
1,116
|
public function loadStoredRoutine ( ) : array { $ this -> routineName = pathinfo ( $ this -> sourceFilename , PATHINFO_FILENAME ) ; $ this -> phpStratumOldMetadata = $ this -> phpStratumMetadata ; $ this -> filemtime = filemtime ( $ this -> sourceFilename ) ; $ load = $ this -> mustLoadStoredRoutine ( ) ; if ( $ load ) { $ this -> io -> text ( sprintf ( 'Loading routine <dbo>%s</dbo>' , OutputFormatter :: escape ( $ this -> routineName ) ) ) ; $ this -> readSourceCode ( ) ; $ this -> extractPlaceholders ( ) ; $ this -> extractDesignationType ( ) ; $ this -> extractReturnType ( ) ; $ this -> extractRoutineTypeAndName ( ) ; $ this -> validateReturnType ( ) ; $ this -> loadRoutineFile ( ) ; $ this -> extractBulkInsertTableColumnsInfo ( ) ; $ this -> extractExtendedParametersInfo ( ) ; $ this -> extractRoutineParametersInfo ( ) ; $ this -> extractDocBlockPartsWrapper ( ) ; $ this -> validateParameterLists ( ) ; $ this -> updateMetadata ( ) ; } return $ this -> phpStratumMetadata ; }
|
Loads the stored routine into the instance of MySQL and returns the metadata of the stored routine .
|
1,117
|
private function dropRoutine ( ) : void { if ( isset ( $ this -> rdbmsOldRoutineMetadata ) ) { MetaDataLayer :: dropRoutine ( $ this -> rdbmsOldRoutineMetadata [ 'routine_type' ] , $ this -> routineName ) ; } }
|
Drops the stored routine if it exists .
|
1,118
|
private function extractBulkInsertTableColumnsInfo ( ) : void { if ( $ this -> designationType != 'bulk_insert' ) return ; $ table_is_non_temporary = MetaDataLayer :: checkTableExists ( $ this -> bulkInsertTableName ) ; if ( ! $ table_is_non_temporary ) { MetaDataLayer :: callProcedure ( $ this -> routineName ) ; } $ description = MetaDataLayer :: describeTable ( $ this -> bulkInsertTableName ) ; if ( ! $ table_is_non_temporary ) { MetaDataLayer :: dropTemporaryTable ( $ this -> bulkInsertTableName ) ; } $ n1 = count ( $ this -> bulkInsertKeys ) ; $ n2 = count ( $ description ) ; if ( $ n1 != $ n2 ) { throw new RoutineLoaderException ( "Number of fields %d and number of columns %d don't match." , $ n1 , $ n2 ) ; } $ this -> bulkInsertColumns = self :: extractColumnsFromTableDescription ( $ description ) ; }
|
Extracts the column names and column types of the current table for bulk insert .
|
1,119
|
private function extractDesignationType ( ) : void { $ found = true ; $ key = array_search ( 'begin' , $ this -> routineSourceCodeLines ) ; if ( $ key !== false ) { for ( $ i = 1 ; $ i < $ key ; $ i ++ ) { $ n = preg_match ( '/^\s*--\s+type:\s*(\w+)\s*(.+)?\s*$/' , $ this -> routineSourceCodeLines [ $ key - $ i ] , $ matches ) ; if ( $ n == 1 ) { $ this -> designationType = $ matches [ 1 ] ; switch ( $ this -> designationType ) { case 'bulk_insert' : $ m = preg_match ( '/^([a-zA-Z0-9_]+)\s+([a-zA-Z0-9_,]+)$/' , $ matches [ 2 ] , $ info ) ; if ( $ m == 0 ) { throw new RoutineLoaderException ( 'Error: Expected: -- type: bulk_insert <table_name> <columns>' ) ; } $ this -> bulkInsertTableName = $ info [ 1 ] ; $ this -> bulkInsertKeys = explode ( ',' , $ info [ 2 ] ) ; break ; case 'rows_with_key' : case 'rows_with_index' : $ this -> indexColumns = explode ( ',' , $ matches [ 2 ] ) ; break ; default : if ( isset ( $ matches [ 2 ] ) ) $ found = false ; } break ; } if ( $ i == ( $ key - 1 ) ) $ found = false ; } } else { $ found = false ; } if ( $ found === false ) { throw new RoutineLoaderException ( 'Unable to find the designation type of the stored routine' ) ; } }
|
Extracts the designation type of the stored routine .
|
1,120
|
private function extractDocBlockPartsWrapper ( ) : void { $ this -> extractDocBlockPartsSource ( ) ; $ parameters = [ ] ; foreach ( $ this -> parameters as $ parameter_info ) { $ parameters [ ] = [ 'parameter_name' => $ parameter_info [ 'parameter_name' ] , 'php_type' => DataTypeHelper :: columnTypeToPhpTypeHinting ( $ parameter_info ) . '|null' , 'data_type_descriptor' => $ parameter_info [ 'data_type_descriptor' ] , 'description' => $ this -> getParameterDocDescription ( $ parameter_info [ 'parameter_name' ] ) ] ; } $ this -> docBlockPartsWrapper = [ 'sort_description' => $ this -> docBlockPartsSource [ 'sort_description' ] , 'long_description' => $ this -> docBlockPartsSource [ 'long_description' ] , 'parameters' => $ parameters ] ; }
|
Extracts DocBlock parts to be used by the wrapper generator .
|
1,121
|
private function extractExtendedParametersInfo ( ) : void { $ key = array_search ( 'begin' , $ this -> routineSourceCodeLines ) ; if ( $ key !== false ) { for ( $ i = 1 ; $ i < $ key ; $ i ++ ) { $ k = preg_match ( '/^\s*--\s+param:(?:\s*(\w+)\s+(\w+)(?:(?:\s+([^\s-])\s+([^\s-])\s+([^\s-])\s*$)|(?:\s*$)))?/' , $ this -> routineSourceCodeLines [ $ key - $ i + 1 ] , $ matches ) ; if ( $ k == 1 ) { $ count = count ( $ matches ) ; if ( $ count == 3 || $ count == 6 ) { $ parameter_name = $ matches [ 1 ] ; $ data_type = $ matches [ 2 ] ; if ( $ count == 6 ) { $ list_delimiter = $ matches [ 3 ] ; $ list_enclosure = $ matches [ 4 ] ; $ list_escape = $ matches [ 5 ] ; } else { $ list_delimiter = ',' ; $ list_enclosure = '"' ; $ list_escape = '\\' ; } if ( ! isset ( $ this -> extendedParameters [ $ parameter_name ] ) ) { $ this -> extendedParameters [ $ parameter_name ] = [ 'name' => $ parameter_name , 'data_type' => $ data_type , 'delimiter' => $ list_delimiter , 'enclosure' => $ list_enclosure , 'escape' => $ list_escape ] ; } else { throw new RoutineLoaderException ( "Duplicate parameter '%s'" , $ parameter_name ) ; } } else { throw new RoutineLoaderException ( 'Error: Expected: -- param: <field_name> <type_of_list> [delimiter enclosure escape]' ) ; } } } } }
|
Extracts extended info of the routine parameters .
|
1,122
|
private function extractPlaceholders ( ) : void { $ unknown = [ ] ; preg_match_all ( '(@[A-Za-z0-9\_\.]+(\%type)?@)' , $ this -> routineSourceCode , $ matches ) ; if ( ! empty ( $ matches [ 0 ] ) ) { foreach ( $ matches [ 0 ] as $ placeholder ) { if ( isset ( $ this -> replacePairs [ strtoupper ( $ placeholder ) ] ) ) { $ this -> replace [ $ placeholder ] = $ this -> replacePairs [ strtoupper ( $ placeholder ) ] ; } else { $ unknown [ ] = $ placeholder ; } } } $ this -> logUnknownPlaceholders ( $ unknown ) ; }
|
Extracts the placeholders from the stored routine source .
|
1,123
|
private function extractReturnType ( ) : void { if ( ! in_array ( $ this -> designationType , [ 'function' , 'singleton0' , 'singleton1' ] ) ) return ; $ key = array_search ( 'begin' , $ this -> routineSourceCodeLines ) ; if ( $ key !== false ) { for ( $ i = 1 ; $ i < $ key ; $ i ++ ) { $ n = preg_match ( '/^\s*--\s+return:\s*((\w|\|)+)\s*$/' , $ this -> routineSourceCodeLines [ $ key - $ i ] , $ matches ) ; if ( $ n == 1 ) { $ this -> returnType = $ matches [ 1 ] ; break ; } } } if ( $ this -> returnType === null ) { $ this -> returnType = 'mixed' ; $ this -> io -> logNote ( 'Unable to find the return type of stored routine' ) ; } }
|
Extracts the return type of the stored routine .
|
1,124
|
private function extractRoutineParametersInfo ( ) : void { $ routine_parameters = MetaDataLayer :: getRoutineParameters ( $ this -> routineName ) ; foreach ( $ routine_parameters as $ key => $ routine_parameter ) { if ( $ routine_parameter [ 'parameter_name' ] ) { $ data_type_descriptor = $ routine_parameter [ 'dtd_identifier' ] ; if ( isset ( $ routine_parameter [ 'character_set_name' ] ) ) { $ data_type_descriptor .= ' character set ' . $ routine_parameter [ 'character_set_name' ] ; } if ( isset ( $ routine_parameter [ 'collation_name' ] ) ) { $ data_type_descriptor .= ' collation ' . $ routine_parameter [ 'collation_name' ] ; } $ routine_parameter [ 'data_type_descriptor' ] = $ data_type_descriptor ; $ this -> parameters [ $ key ] = $ routine_parameter ; } } $ this -> updateParametersInfo ( ) ; }
|
Extracts info about the parameters of the stored routine .
|
1,125
|
private function getParameterDocDescription ( string $ name ) : ? string { if ( isset ( $ this -> docBlockPartsSource [ 'parameters' ] ) ) { foreach ( $ this -> docBlockPartsSource [ 'parameters' ] as $ parameter_doc_info ) { if ( $ parameter_doc_info [ 'name' ] === $ name ) return $ parameter_doc_info [ 'description' ] ; } } return null ; }
|
Gets description by name of the parameter as found in the DocBlock of the stored routine .
|
1,126
|
private function loadRoutineFile ( ) : void { $ this -> setMagicConstants ( ) ; $ lines = explode ( "\n" , $ this -> routineSourceCode ) ; $ routine_source = [ ] ; foreach ( $ lines as $ i => & $ line ) { $ this -> replace [ '__LINE__' ] = $ i + 1 ; $ routine_source [ $ i ] = strtr ( $ line , $ this -> replace ) ; } $ routine_source = implode ( "\n" , $ routine_source ) ; $ this -> unsetMagicConstants ( ) ; $ this -> dropRoutine ( ) ; MetaDataLayer :: setSqlMode ( $ this -> sqlMode ) ; MetaDataLayer :: setCharacterSet ( $ this -> characterSet , $ this -> collate ) ; MetaDataLayer :: loadRoutine ( $ routine_source ) ; }
|
Loads the stored routine into the database .
|
1,127
|
private function mustLoadStoredRoutine ( ) : bool { if ( ! isset ( $ this -> phpStratumOldMetadata ) ) return true ; if ( $ this -> phpStratumOldMetadata [ 'timestamp' ] != $ this -> filemtime ) return true ; foreach ( $ this -> phpStratumOldMetadata [ 'replace' ] as $ place_holder => $ old_value ) { if ( ! isset ( $ this -> replacePairs [ strtoupper ( $ place_holder ) ] ) || $ this -> replacePairs [ strtoupper ( $ place_holder ) ] !== $ old_value ) { return true ; } } if ( ! isset ( $ this -> rdbmsOldRoutineMetadata ) ) return true ; if ( $ this -> rdbmsOldRoutineMetadata [ 'sql_mode' ] != $ this -> sqlMode ) return true ; if ( $ this -> rdbmsOldRoutineMetadata [ 'character_set_client' ] != $ this -> characterSet ) return true ; if ( $ this -> rdbmsOldRoutineMetadata [ 'collation_connection' ] != $ this -> collate ) return true ; return false ; }
|
Returns true if the source file must be load or reloaded . Otherwise returns false .
|
1,128
|
private function readSourceCode ( ) : void { $ this -> routineSourceCode = file_get_contents ( $ this -> sourceFilename ) ; $ this -> routineSourceCodeLines = explode ( "\n" , $ this -> routineSourceCode ) ; if ( $ this -> routineSourceCodeLines === false ) { throw new RoutineLoaderException ( 'Source file is empty' ) ; } }
|
Reads the source code of the stored routine .
|
1,129
|
private function setMagicConstants ( ) : void { $ real_path = realpath ( $ this -> sourceFilename ) ; $ this -> replace [ '__FILE__' ] = "'" . MetaDataLayer :: realEscapeString ( $ real_path ) . "'" ; $ this -> replace [ '__ROUTINE__' ] = "'" . $ this -> routineName . "'" ; $ this -> replace [ '__DIR__' ] = "'" . MetaDataLayer :: realEscapeString ( dirname ( $ real_path ) ) . "'" ; }
|
Adds magic constants to replace list .
|
1,130
|
private function unsetMagicConstants ( ) : void { unset ( $ this -> replace [ '__FILE__' ] ) ; unset ( $ this -> replace [ '__ROUTINE__' ] ) ; unset ( $ this -> replace [ '__DIR__' ] ) ; unset ( $ this -> replace [ '__LINE__' ] ) ; }
|
Removes magic constants from current replace list .
|
1,131
|
private function updateMetadata ( ) : void { $ this -> phpStratumMetadata [ 'routine_name' ] = $ this -> routineName ; $ this -> phpStratumMetadata [ 'designation' ] = $ this -> designationType ; $ this -> phpStratumMetadata [ 'return' ] = $ this -> returnType ; $ this -> phpStratumMetadata [ 'parameters' ] = $ this -> parameters ; $ this -> phpStratumMetadata [ 'timestamp' ] = $ this -> filemtime ; $ this -> phpStratumMetadata [ 'replace' ] = $ this -> replace ; $ this -> phpStratumMetadata [ 'phpdoc' ] = $ this -> docBlockPartsWrapper ; $ this -> phpStratumMetadata [ 'spec_params' ] = $ this -> extendedParameters ; $ this -> phpStratumMetadata [ 'index_columns' ] = $ this -> indexColumns ; $ this -> phpStratumMetadata [ 'bulk_insert_table_name' ] = $ this -> bulkInsertTableName ; $ this -> phpStratumMetadata [ 'bulk_insert_columns' ] = $ this -> bulkInsertColumns ; $ this -> phpStratumMetadata [ 'bulk_insert_keys' ] = $ this -> bulkInsertKeys ; }
|
Updates the metadata for the stored routine .
|
1,132
|
private function updateParametersInfo ( ) : void { if ( ! empty ( $ this -> extendedParameters ) ) { foreach ( $ this -> extendedParameters as $ spec_param_name => $ spec_param_info ) { $ param_not_exist = true ; foreach ( $ this -> parameters as $ key => $ param_info ) { if ( $ param_info [ 'parameter_name' ] == $ spec_param_name ) { $ this -> parameters [ $ key ] = array_merge ( $ this -> parameters [ $ key ] , $ spec_param_info ) ; $ param_not_exist = false ; break ; } } if ( $ param_not_exist ) { throw new RoutineLoaderException ( "Specific parameter '%s' does not exist" , $ spec_param_name ) ; } } } }
|
Update information about specific parameters of stored routine .
|
1,133
|
private function validateParameterLists ( ) : void { $ database_parameters_names = [ ] ; foreach ( $ this -> parameters as $ parameter_info ) { $ database_parameters_names [ ] = $ parameter_info [ 'parameter_name' ] ; } $ doc_block_parameters_names = [ ] ; if ( isset ( $ this -> docBlockPartsSource [ 'parameters' ] ) ) { foreach ( $ this -> docBlockPartsSource [ 'parameters' ] as $ parameter ) { $ doc_block_parameters_names [ ] = $ parameter [ 'name' ] ; } } $ tmp = array_diff ( $ database_parameters_names , $ doc_block_parameters_names ) ; foreach ( $ tmp as $ name ) { $ this -> io -> logNote ( 'Parameter <dbo>%s</dbo> is missing from doc block' , $ name ) ; } $ tmp = array_diff ( $ doc_block_parameters_names , $ database_parameters_names ) ; foreach ( $ tmp as $ name ) { $ this -> io -> logNote ( 'Unknown parameter <dbo>%s</dbo> found in doc block' , $ name ) ; } }
|
Validates the parameters found the DocBlock in the source of the stored routine against the parameters from the metadata of MySQL and reports missing and unknown parameters names .
|
1,134
|
private function validateReturnType ( ) : void { if ( ! in_array ( $ this -> designationType , [ 'function' , 'singleton0' , 'singleton1' ] ) ) return ; $ types = explode ( '|' , $ this -> returnType ) ; $ diff = array_diff ( $ types , [ 'string' , 'int' , 'float' , 'double' , 'bool' , 'null' ] ) ; if ( ! ( $ this -> returnType == 'mixed' || $ this -> returnType == 'bool' || empty ( $ diff ) ) ) { throw new RoutineLoaderException ( "Return type must be 'mixed', 'bool', or a combination of 'int', 'float', 'string', and 'null'" ) ; } if ( ! in_array ( $ this -> designationType , [ 'singleton0' ] ) ) return ; if ( in_array ( $ this -> returnType , [ 'bool' , 'mixed' ] ) ) return ; $ parts = explode ( '|' , $ this -> returnType ) ; $ key = array_search ( 'null' , $ parts ) ; if ( $ key === false ) { throw new RoutineLoaderException ( "Return type must be 'mixed', 'bool', or contain 'null' (with a combination of 'int', 'float', and 'string')" ) ; } }
|
Validates the specified return type of the stored routine .
|
1,135
|
public static function format ( $ hook , $ type , $ notification , $ params ) { $ event = elgg_extract ( 'event' , $ params ) ; $ comment = $ event -> getObject ( ) ; $ recipient = elgg_extract ( 'recipient' , $ params ) ; $ language = elgg_extract ( 'language' , $ params ) ; if ( ! $ comment instanceof Comment ) { return ; } $ entity = $ comment -> getContainerEntity ( ) ; if ( ! $ entity ) { return ; } $ messages = ( new NotificationFormatter ( $ comment , $ recipient , $ language ) ) -> prepare ( ) ; $ notification -> summary = $ messages -> summary ; $ notification -> subject = $ messages -> subject ; $ notification -> body = $ messages -> body ; return $ notification ; }
|
Prepare a notification for when comment is created
|
1,136
|
public static function getSubscriptions ( $ hook , $ type , $ return , $ params ) { $ event = elgg_extract ( 'event' , $ params ) ; if ( ! $ event instanceof SubscriptionNotificationEvent ) { return ; } $ object = $ event -> getObject ( ) ; if ( ! $ object instanceof Comment ) { return ; } $ subscriptions = [ ] ; $ actor_subscriptions = [ ] ; $ group_subscriptions = [ ] ; $ original_container = $ object -> getOriginalContainer ( ) ; if ( $ original_container instanceof \ ElggObject ) { $ subscriptions = elgg_get_subscriptions_for_container ( $ original_container -> guid ) ; $ group = $ original_container -> getContainerEntity ( ) ; if ( $ group instanceof \ ElggGroup ) { $ group_subscriptions = elgg_get_subscriptions_for_container ( $ group -> guid ) ; } } else if ( $ original_container instanceof \ ElggGroup ) { $ group_subscriptions = elgg_get_subscriptions_for_container ( $ original_container -> guid ) ; } $ actor = $ event -> getActor ( ) ; if ( $ actor instanceof \ ElggUser ) { $ actor_subscriptions = elgg_get_subscriptions_for_container ( $ actor -> guid ) ; } $ all_subscriptions = $ return + $ subscriptions + $ group_subscriptions + $ actor_subscriptions ; $ user_guids = elgg_get_entities_from_relationship ( array ( 'type' => 'user' , 'relationship_guid' => $ original_container -> guid , 'relationship' => 'comment_subscribe' , 'inverse_relationship' => true , 'limit' => false , 'callback' => function ( $ row ) { return ( int ) $ row -> guid ; } , ) ) ; if ( $ user_guids ) { $ user_guids_set = implode ( ',' , $ user_guids ) ; $ dbprefix = elgg_get_config ( 'dbprefix' ) ; $ site_guid = elgg_get_site_entity ( ) -> guid ; $ blocked_relationships = get_data ( " SELECT * FROM {$dbprefix}entity_relationships WHERE relationship LIKE 'block_comment_notify%' AND guid_one IN ($user_guids_set) AND guid_two = $site_guid " ) ; $ blocked_methods = array ( ) ; foreach ( $ blocked_relationships as $ row ) { $ method = str_replace ( 'block_comment_notify' , '' , $ row -> relationship ) ; $ blocked_methods [ $ row -> guid_one ] [ ] = $ method ; } $ registered_methods = _elgg_services ( ) -> notifications -> getMethods ( ) ; foreach ( $ user_guids as $ user_guid ) { $ methods = $ registered_methods ; if ( isset ( $ blocked_methods [ $ user_guid ] ) ) { $ methods = array_diff ( $ methods , $ blocked_methods [ $ user_guid ] ) ; } if ( $ methods ) { $ all_subscriptions [ $ user_guid ] = $ methods ; } } } foreach ( $ all_subscriptions as $ guid => $ methods ) { if ( check_entity_relationship ( $ guid , 'comment_tracker_unsubscribed' , $ original_container -> guid ) ) { unset ( $ all_subscriptions [ $ guid ] ) ; } } unset ( $ all_subscriptions [ $ actor -> guid ] ) ; return $ all_subscriptions ; }
|
Subscribe users to comments based on original entity
|
1,137
|
public static function subscribe ( $ event , $ type , $ entity ) { if ( ! $ entity instanceof Comment ) { return ; } $ original_container = $ entity -> getOriginalContainer ( ) ; if ( ! $ original_container instanceof \ ElggObject ) { return ; } if ( check_entity_relationship ( $ entity -> owner_guid , 'comment_tracker_unsubscribed' , $ original_container -> guid ) ) { return ; } add_entity_relationship ( $ entity -> owner_guid , 'comment_subscribe' , $ original_container -> guid ) ; }
|
Subscribe users to notifications about the thread
|
1,138
|
public function transfert ( $ imageId , array $ parameters ) { if ( ! array_key_exists ( 'region_id' , $ parameters ) || ! is_int ( $ parameters [ 'region_id' ] ) ) { throw new \ InvalidArgumentException ( 'You need to provide an integer "region_id".' ) ; } return $ this -> processQuery ( $ this -> buildQuery ( $ imageId , ImagesActions :: ACTION_TRANSFERT , $ parameters ) ) ; }
|
Transferts a specific image to a specified region . The region_id key is required .
|
1,139
|
protected function whenPivotLoaded ( $ table , $ value , $ default = null ) { if ( func_num_args ( ) === 2 ) $ default = new MissingValue ; return $ this -> when ( $ this -> pivot && ( $ this -> pivot instanceof $ table || $ this -> pivot -> getTable ( ) === $ table ) , ... [ $ value , $ default ] ) ; }
|
Execute a callback if the given pivot table has been loaded .
|
1,140
|
protected function resolveNestedRelations ( $ data , $ request ) { foreach ( $ data as $ key => $ value ) { if ( is_array ( $ value ) ) { $ data [ $ key ] = $ this -> resolveNestedRelations ( $ value , $ request ) ; } elseif ( $ value instanceof static ) { $ data [ $ key ] = $ value -> resolve ( $ request ) ; } } return $ this -> filter ( $ data ) ; }
|
Resolve the nested resources to an array .
|
1,141
|
protected function when ( $ condition , $ value , $ default = null ) { return $ condition ? value ( $ value ) : ( func_num_args ( ) === 3 ? value ( $ default ) : new MissingValue ) ; }
|
Retrieve a value based on a given condition .
|
1,142
|
public function items ( ) { return [ 'home' => [ 'title' => trans ( 'dashboard::menus.principal.home' ) , 'url' => '#home' , 'data-scroll' => true ] , 'about' => [ 'title' => trans ( 'dashboard::menus.principal.about' ) , 'url' => '#about' , 'data-scroll' => true ] , 'team' => [ 'title' => trans ( 'dashboard::menus.principal.team' ) , 'url' => '#team' , 'data-scroll' => true ] , 'services' => [ 'title' => trans ( 'dashboard::menus.principal.services' ) , 'url' => '#services' , 'data-scroll' => true ] , 'platform' => [ 'title' => trans ( 'dashboard::menus.principal.platform' ) , 'url' => route ( 'auth.loginGet' ) , 'data-scroll' => true ] , 'contact' => [ 'title' => trans ( 'dashboard::menus.principal.contact' ) , 'url' => '#contact' , 'data-scroll' => true ] , 'facebook' => [ 'url' => '#' , 'icon' => 'fa fa-facebook' , ] , 'twitter' => [ 'url' => '#' , 'icon' => 'fa fa-twitter' , ] , 'google' => [ 'url' => '#' , 'icon' => 'fa fa-google' , ] , ] ; }
|
Specify Items Menu
|
1,143
|
public function getOriginalContainer ( ) { $ container = $ this ; while ( $ container instanceof Comment ) { $ container = $ container -> getContainerEntity ( ) ; } return ( $ container instanceof Comment ) ? $ this -> getOwnerEntity ( ) : $ container ; }
|
Get entity that the original comment was made on in a comment thread
|
1,144
|
public function getDepthToOriginalContainer ( ) { $ depth = 0 ; $ ancestry = $ this -> getAncestry ( ) ; foreach ( $ ancestry as $ a ) { $ ancestor = get_entity ( $ a ) ; if ( $ ancestor instanceof self ) { $ depth ++ ; } } return $ depth ; }
|
Get nesting level of this comment
|
1,145
|
public function getSubscriberFilterOptions ( array $ options = array ( ) ) { $ defaults = array ( 'type' => 'user' , 'relationship' => 'subscribed' , 'relationship_guid' => $ this -> getOriginalContainer ( ) -> guid , 'inverse_relationship' => true , ) ; return array_merge ( $ defaults , $ options ) ; }
|
Returns getter options for comment subscribers
|
1,146
|
public function getProgressBar ( ) : ProgressBar { if ( ! $ this -> progressBar ) { $ this -> progressBar = new ProgressBar ( $ this -> getOutput ( ) , $ this -> numRecords ) ; $ this -> progressBar -> setFormat ( 'debug' ) ; $ this -> progressBar -> setBarWidth ( ( int ) exec ( 'tput cols' ) ) ; } return $ this -> progressBar ; }
|
Allows to modify the progress bar instance
|
1,147
|
public static function columnTypeToPhpTypeHinting ( array $ dataTypeInfo ) : string { switch ( $ dataTypeInfo [ 'data_type' ] ) { case 'tinyint' : case 'smallint' : case 'mediumint' : case 'int' : case 'bigint' : case 'year' : $ phpType = 'int' ; break ; case 'decimal' : $ phpType = 'int|float|string' ; break ; case 'float' : case 'double' : $ phpType = 'float' ; break ; case 'bit' : case 'varbinary' : case 'binary' : case 'char' : case 'varchar' : case 'time' : case 'timestamp' : case 'date' : case 'datetime' : case 'enum' : case 'set' : case 'tinytext' : case 'text' : case 'mediumtext' : case 'longtext' : case 'tinyblob' : case 'blob' : case 'mediumblob' : case 'longblob' : $ phpType = 'string' ; break ; case 'list_of_int' : $ phpType = 'string|int[]' ; break ; default : throw new FallenException ( 'data type' , $ dataTypeInfo [ 'data_type' ] ) ; } return $ phpType ; }
|
Returns the corresponding PHP type hinting of a MySQL column type .
|
1,148
|
public static function deriveFieldLength ( array $ dataTypeInfo ) : ? int { switch ( $ dataTypeInfo [ 'data_type' ] ) { case 'tinyint' : case 'smallint' : case 'mediumint' : case 'int' : case 'bigint' : case 'float' : case 'double' : $ ret = $ dataTypeInfo [ 'numeric_precision' ] ; break ; case 'decimal' : $ ret = $ dataTypeInfo [ 'numeric_precision' ] ; if ( $ dataTypeInfo [ 'numeric_scale' ] > 0 ) $ ret += 1 ; break ; case 'char' : case 'varchar' : case 'binary' : case 'varbinary' : case 'tinytext' : case 'text' : case 'mediumtext' : case 'longtext' : case 'tinyblob' : case 'blob' : case 'mediumblob' : case 'longblob' : case 'bit' : $ ret = $ dataTypeInfo [ 'character_maximum_length' ] ; break ; case 'timestamp' : $ ret = 16 ; break ; case 'year' : $ ret = 4 ; break ; case 'time' : $ ret = 8 ; break ; case 'date' : $ ret = 10 ; break ; case 'datetime' : $ ret = 16 ; break ; case 'enum' : case 'set' : $ ret = null ; break ; default : throw new FallenException ( 'data type' , $ dataTypeInfo [ 'data_type' ] ) ; } return $ ret ; }
|
Returns the widths of a field based on a MySQL data type .
|
1,149
|
public static function escapePhpExpression ( array $ dataTypeInfo , string $ expression , bool $ lobAsString ) : string { switch ( $ dataTypeInfo [ 'data_type' ] ) { case 'tinyint' : case 'smallint' : case 'mediumint' : case 'int' : case 'bigint' : case 'year' : $ ret = "'.self::quoteInt(" . $ expression . ").'" ; break ; case 'float' : case 'double' : $ ret = "'.self::quoteFloat(" . $ expression . ").'" ; break ; case 'char' : case 'varchar' : $ ret = "'.self::quoteString(" . $ expression . ").'" ; break ; case 'binary' : case 'varbinary' : $ ret = "'.self::quoteBinary(" . $ expression . ").'" ; break ; case 'decimal' : $ ret = "'.self::quoteDecimal(" . $ expression . ").'" ; break ; case 'time' : case 'timestamp' : case 'date' : case 'datetime' : $ ret = "'.self::quoteString(" . $ expression . ").'" ; break ; case 'enum' : case 'set' : $ ret = "'.self::quoteString(" . $ expression . ").'" ; break ; case 'bit' : $ ret = "'.self::quoteBit(" . $ expression . ").'" ; break ; case 'tinytext' : case 'text' : case 'mediumtext' : case 'longtext' : $ ret = ( $ lobAsString ) ? $ ret = "'.self::quoteString(" . $ expression . ").'" : '?' ; break ; case 'tinyblob' : case 'blob' : case 'mediumblob' : case 'longblob' : $ ret = ( $ lobAsString ) ? $ ret = "'.self::quoteBinary(" . $ expression . ").'" : '?' ; break ; case 'list_of_int' : $ ret = "'.self::quoteListOfInt(" . $ expression . ", '" . addslashes ( $ dataTypeInfo [ 'delimiter' ] ) . "', '" . addslashes ( $ dataTypeInfo [ 'enclosure' ] ) . "', '" . addslashes ( $ dataTypeInfo [ 'escape' ] ) . "').'" ; break ; default : throw new FallenException ( 'data type' , $ dataTypeInfo [ 'data_type' ] ) ; } return $ ret ; }
|
Returns PHP code escaping the value of a PHP expression that can be safely used when concatenating a SQL statement .
|
1,150
|
public static function getBindVariableType ( array $ dataTypeInfo , bool $ lobAsString ) : string { $ ret = '' ; switch ( $ dataTypeInfo [ 'data_type' ] ) { case 'tinyint' : case 'smallint' : case 'mediumint' : case 'int' : case 'bigint' : case 'year' : $ ret = 'i' ; break ; case 'float' : case 'double' : $ ret = 'd' ; break ; case 'time' : case 'timestamp' : case 'binary' : case 'enum' : case 'bit' : case 'set' : case 'char' : case 'varchar' : case 'date' : case 'datetime' : case 'varbinary' : $ ret = 's' ; break ; case 'decimal' : $ ret = 's' ; break ; case 'tinytext' : case 'text' : case 'mediumtext' : case 'longtext' : case 'tinyblob' : case 'blob' : case 'mediumblob' : case 'longblob' : $ ret .= ( $ lobAsString ) ? 's' : 'b' ; break ; case 'list_of_int' : $ ret = 's' ; break ; default : throw new FallenException ( 'parameter type' , $ dataTypeInfo [ 'data_type' ] ) ; } return $ ret ; }
|
Returns the type of a bind variable .
|
1,151
|
public static function isBlobParameter ( string $ dataType ) : bool { switch ( $ dataType ) { case 'tinytext' : case 'text' : case 'mediumtext' : case 'longtext' : case 'tinyblob' : case 'blob' : case 'mediumblob' : case 'longblob' : $ isBlob = true ; break ; case 'tinyint' : case 'smallint' : case 'mediumint' : case 'int' : case 'bigint' : case 'year' : case 'decimal' : case 'float' : case 'double' : case 'time' : case 'timestamp' : case 'binary' : case 'enum' : case 'bit' : case 'set' : case 'char' : case 'varchar' : case 'date' : case 'datetime' : case 'varbinary' : case 'list_of_int' : $ isBlob = false ; break ; default : throw new FallenException ( 'data type' , $ dataType ) ; } return $ isBlob ; }
|
Returns true if one if a MySQL column type is a BLOB or a CLOB .
|
1,152
|
public static function phpTypeHintingToPhpTypeDeclaration ( string $ phpTypeHint ) : string { $ phpType = '' ; switch ( $ phpTypeHint ) { case 'array' : case 'array[]' : case 'bool' : case 'float' : case 'int' : case 'string' : case 'void' : $ phpType = $ phpTypeHint ; break ; default : $ parts = explode ( '|' , $ phpTypeHint ) ; $ key = array_search ( 'null' , $ parts ) ; if ( count ( $ parts ) == 2 && $ key !== false ) { unset ( $ parts [ $ key ] ) ; $ tmp = static :: phpTypeHintingToPhpTypeDeclaration ( implode ( '|' , $ parts ) ) ; if ( $ tmp !== '' ) { $ phpType = '?' . $ tmp ; } } } return $ phpType ; }
|
Returns the corresponding PHP type declaration of a MySQL column type .
|
1,153
|
private function base64Encode ( $ uri ) { if ( null === $ uri ) { return null ; } $ splFileObject = new SplFileObject ( $ uri ) ; if ( 30100 < Kernel :: VERSION_ID ) { return ( new DataUriNormalizer ( ) ) -> normalize ( $ splFileObject ) ; } $ data = "" ; while ( false === $ splFileObject -> eof ( ) ) { $ data .= $ splFileObject -> fgets ( ) ; } return sprintf ( "data:%s;base64,%s" , mime_content_type ( $ uri ) , base64_encode ( $ data ) ) ; }
|
Encode an URI into base 64 .
|
1,154
|
public function bootstrapImageBase64Function ( array $ args = [ ] ) { $ src = $ this -> base64Encode ( ArrayHelper :: get ( $ args , "src" ) ) ; return $ this -> bootstrapImage ( $ src , ArrayHelper :: get ( $ args , "alt" ) , ArrayHelper :: get ( $ args , "width" ) , ArrayHelper :: get ( $ args , "height" ) , ArrayHelper :: get ( $ args , "class" ) , ArrayHelper :: get ( $ args , "usemap" ) ) ; }
|
Displays a Bootstrap image Base 64 .
|
1,155
|
public static function executeBulk ( BulkHandler $ bulkHandler , string $ query ) : void { self :: realQuery ( $ query ) ; $ bulkHandler -> start ( ) ; $ result = self :: $ mysqli -> use_result ( ) ; while ( ( $ row = $ result -> fetch_assoc ( ) ) ) { $ bulkHandler -> row ( $ row ) ; } $ result -> free ( ) ; $ bulkHandler -> stop ( ) ; if ( self :: $ mysqli -> more_results ( ) ) self :: $ mysqli -> next_result ( ) ; }
|
Executes a query using a bulk handler .
|
1,156
|
public static function executeSingleton0 ( string $ query ) { $ result = self :: query ( $ query ) ; $ row = $ result -> fetch_array ( MYSQLI_NUM ) ; $ n = $ result -> num_rows ; $ result -> free ( ) ; if ( self :: $ mysqli -> more_results ( ) ) self :: $ mysqli -> next_result ( ) ; if ( ! ( $ n == 0 || $ n == 1 ) ) { throw new ResultException ( '0 or 1' , $ n , $ query ) ; } return $ row [ 0 ] ; }
|
Executes a query that returns 0 or 1 row with one column . Throws an exception if the query selects 2 or more rows .
|
1,157
|
public static function quoteDecimal ( $ value ) : string { if ( $ value === null || $ value === '' ) return 'null' ; if ( is_int ( $ value ) || is_float ( $ value ) ) return ( string ) $ value ; return "'" . self :: $ mysqli -> real_escape_string ( $ value ) . "'" ; }
|
Returns a literal for a decimal value that can be safely used in SQL statements .
|
1,158
|
private static function executeTableShowTableColumn ( array $ column , $ value ) : void { $ spaces = str_repeat ( ' ' , $ column [ 'length' ] - mb_strlen ( ( string ) $ value ) ) ; switch ( $ column [ 'type' ] ) { case 1 : case 2 : case 3 : case 4 : case 5 : case 8 : case 9 : case 246 : echo ' ' , $ spaces . $ value , ' ' ; break ; case 7 : case 10 : case 11 : case 12 : case 13 : case 16 : case 252 : case 253 : case 254 : echo ' ' , $ value . $ spaces , ' ' ; break ; default : throw new FallenException ( 'data type id' , $ column [ 'type' ] ) ; } }
|
Helper method for method executeTable . Shows table cell with data .
|
1,159
|
public static function callProcedure ( string $ procedureName ) : void { $ query = 'call ' . $ procedureName . '()' ; self :: $ dl -> executeNone ( $ query ) ; }
|
Class a stored procedure without arguments .
|
1,160
|
public static function checkTableExists ( string $ tableName ) : bool { $ query = sprintf ( 'select 1from information_schema.TABLESwhere table_schema = database()and table_name = %s' , self :: $ dl -> quoteString ( $ tableName ) ) ; return ! empty ( self :: executeSingleton0 ( $ query ) ) ; }
|
Checks if a table exists in the current schema .
|
1,161
|
public static function dropRoutine ( string $ routineType , string $ routineName ) : void { $ query = sprintf ( 'drop %s if exists `%s`' , $ routineType , $ routineName ) ; self :: executeNone ( $ query ) ; }
|
Drops a routine if it exists .
|
1,162
|
public static function dropTemporaryTable ( string $ tableName ) : void { $ query = sprintf ( 'drop temporary table `%s`' , $ tableName ) ; self :: executeNone ( $ query ) ; }
|
Drops a temporary table .
|
1,163
|
public static function executeRow1 ( string $ query ) : array { self :: logQuery ( $ query ) ; return self :: $ dl -> executeRow1 ( $ query ) ; }
|
Executes a query that returns 1 and only 1 row . Throws an exception if the query selects none 2 or more rows .
|
1,164
|
public static function executeSingleton1 ( string $ query ) { self :: logQuery ( $ query ) ; return self :: $ dl -> executeSingleton1 ( $ query ) ; }
|
Executes a query that returns 1 and only 1 row with 1 column . Throws an exception if the query selects none 2 or more rows .
|
1,165
|
public static function getCorrectSqlMode ( string $ sqlMode ) : string { $ query = sprintf ( 'set sql_mode = %s' , self :: $ dl -> quoteString ( $ sqlMode ) ) ; self :: executeNone ( $ query ) ; $ query = 'select @@sql_mode' ; return ( string ) self :: executeSingleton1 ( $ query ) ; }
|
Selects the SQL mode in the order as preferred by MySQL .
|
1,166
|
public static function getLabelsFromTable ( string $ tableName , string $ idColumnName , string $ labelColumnName ) : array { $ query = "select `%s` id, `%s` labelfrom `%s`where nullif(`%s`,'') is not null" ; $ query = sprintf ( $ query , $ idColumnName , $ labelColumnName , $ tableName , $ labelColumnName ) ; return self :: executeRows ( $ query ) ; }
|
Selects all labels from a table with labels .
|
1,167
|
public static function getTableColumns ( string $ schemaName , string $ tableName ) : array { $ sql = sprintf ( 'select COLUMN_NAME as column_name, COLUMN_TYPE as column_type, IS_NULLABLE as is_nullable, CHARACTER_SET_NAME as character_set_name, COLLATION_NAME as collation_name, EXTRA as extrafrom information_schema.COLUMNSwhere TABLE_SCHEMA = %sand TABLE_NAME = %sorder by ORDINAL_POSITION' , self :: $ dl -> quoteString ( $ schemaName ) , self :: $ dl -> quoteString ( $ tableName ) ) ; return self :: $ dl -> executeRows ( $ sql ) ; }
|
Selects metadata of all columns of table .
|
1,168
|
public static function getTablePrimaryKeys ( string $ schemaName , string $ tableName ) : array { $ sql = sprintf ( 'show index from %s.%swhere Key_name = \'PRIMARY\'' , $ schemaName , $ tableName ) ; return self :: $ dl -> executeRows ( $ sql ) ; }
|
Selects all primary keys from table .
|
1,169
|
public static function getTablesNames ( string $ schemaName ) : array { $ sql = sprintf ( "select TABLE_NAME as table_namefrom information_schema.TABLESwhere TABLE_SCHEMA = %sand TABLE_TYPE = 'BASE TABLE'order by TABLE_NAME" , self :: $ dl -> quoteString ( $ schemaName ) ) ; return self :: $ dl -> executeRows ( $ sql ) ; }
|
Selects all table names in a schema .
|
1,170
|
public static function setCharacterSet ( string $ characterSet , string $ collate ) : void { $ sql = sprintf ( 'set names %s collate %s' , self :: $ dl -> quoteString ( $ characterSet ) , self :: $ dl -> quoteString ( $ collate ) ) ; self :: executeNone ( $ sql ) ; }
|
Sets the default character set and collate .
|
1,171
|
private static function logQuery ( string $ query ) : void { $ query = trim ( $ query ) ; if ( strpos ( $ query , "\n" ) !== false ) { self :: $ io -> logVeryVerbose ( 'Executing query:' ) ; self :: $ io -> logVeryVerbose ( '<sql>%s</sql>' , $ query ) ; } else { self :: $ io -> logVeryVerbose ( 'Executing query: <sql>%s</sql>' , $ query ) ; } }
|
Logs the query on the console .
|
1,172
|
public function setPassword ( string $ newPassword ) : void { $ this -> password = $ this -> passwordUtility -> hash ( $ newPassword ) ; }
|
Set new user password without do any check .
|
1,173
|
public function changePassword ( string $ newPassword , string $ oldPassword ) : bool { if ( $ this -> passwordUtility -> verify ( $ oldPassword , $ this -> password ) ) { $ this -> password = $ this -> passwordUtility -> hash ( $ newPassword ) ; return true ; } return false ; }
|
Change user password only after check old password .
|
1,174
|
protected function initRequests ( ) { $ this -> useragent = 'Wikimate ' . self :: VERSION . ' (https://github.com/hamstar/Wikimate)' ; $ this -> session = new Requests_Session ( $ this -> api , $ this -> headers , $ this -> data , $ this -> options ) ; $ this -> session -> useragent = $ this -> useragent ; }
|
Set up a Requests_Session with appropriate user agent .
|
1,175
|
public function login ( $ username , $ password , $ domain = null ) { $ details = array ( 'action' => 'login' , 'lgname' => $ username , 'lgpassword' => $ password , 'format' => 'json' ) ; if ( is_string ( $ domain ) ) { $ details [ 'lgdomain' ] = $ domain ; } $ response = $ this -> session -> post ( $ this -> api , array ( ) , $ details ) ; if ( strpos ( $ response -> body , "This is an auto-generated MediaWiki API documentation page" ) !== false ) { $ this -> error = array ( ) ; $ this -> error [ 'login' ] = 'The API could not understand the first login request' ; return false ; } $ loginResult = json_decode ( $ response -> body ) ; if ( $ this -> debugMode ) { echo "Login request:\n" ; print_r ( $ details ) ; echo "Login request response:\n" ; print_r ( $ loginResult ) ; } if ( isset ( $ loginResult -> login -> result ) && $ loginResult -> login -> result == 'NeedToken' ) { $ details [ 'lgtoken' ] = strtolower ( trim ( $ loginResult -> login -> token ) ) ; $ loginResult = $ this -> session -> post ( $ this -> api , array ( ) , $ details ) -> body ; if ( strpos ( $ loginResult , "This is an auto-generated MediaWiki API documentation page" ) !== false ) { $ this -> error = array ( ) ; $ this -> error [ 'login' ] = 'The API could not understand the confirm token request' ; return false ; } $ loginResult = json_decode ( $ loginResult ) ; if ( $ this -> debugMode ) { echo "Confirm token request:\n" ; print_r ( $ details ) ; echo "Confirm token response:\n" ; print_r ( $ loginResult ) ; } if ( $ loginResult -> login -> result != 'Success' ) { $ this -> error = array ( ) ; switch ( $ loginResult -> login -> result ) { case 'NotExists' : $ this -> error [ 'login' ] = 'The username does not exist' ; break ; default : $ this -> error [ 'login' ] = 'The API result was: ' . $ loginResult -> login -> result ; break ; } return false ; } } return true ; }
|
Logs in to the wiki .
|
1,176
|
public function debugRequestsConfig ( $ echo = false ) { if ( $ echo ) { echo "<pre>Requests options:\n" ; print_r ( $ this -> session -> options ) ; echo "Requests headers:\n" ; print_r ( $ this -> session -> headers ) ; echo "</pre>" ; return true ; } return $ this -> session -> options ; }
|
Get or print the Requests configuration .
|
1,177
|
public function query ( $ array ) { $ array [ 'action' ] = 'query' ; $ array [ 'format' ] = 'php' ; $ apiResult = $ this -> session -> get ( $ this -> api . '?' . http_build_query ( $ array ) ) ; return unserialize ( $ apiResult -> body ) ; }
|
Performs a query to the wiki API with the given details .
|
1,178
|
public function edit ( $ array ) { $ headers = array ( 'Content-Type' => "application/x-www-form-urlencoded" ) ; $ array [ 'action' ] = 'edit' ; $ array [ 'format' ] = 'php' ; $ apiResult = $ this -> session -> post ( $ this -> api , $ headers , $ array ) ; return unserialize ( $ apiResult -> body ) ; }
|
Perfoms an edit query to the wiki API .
|
1,179
|
public function download ( $ url ) { $ getResult = $ this -> session -> get ( $ url ) ; if ( ! $ getResult -> success ) { $ this -> error = array ( ) ; $ this -> error [ 'file' ] = 'Download error (HTTP status: ' . $ getResult -> status_code . ')' ; $ this -> error [ 'http' ] = $ getResult -> status_code ; return null ; } return $ getResult -> body ; }
|
Downloads data from the given URL .
|
1,180
|
public function upload ( $ array ) { $ array [ 'action' ] = 'upload' ; $ array [ 'format' ] = 'php' ; $ boundary = '---Wikimate-' . md5 ( microtime ( ) ) ; $ body = '' ; foreach ( $ array as $ fieldName => $ fieldData ) { $ body .= "--{$boundary}\r\n" ; $ body .= 'Content-Disposition: form-data; name="' . $ fieldName . '"' ; if ( $ fieldName == 'file' ) { $ body .= '; filename="' . $ array [ 'filename' ] . '"' . "\r\n" ; $ body .= "Content-Type: application/octet-stream; charset=UTF-8\r\n" ; $ body .= "Content-Transfer-Encoding: binary\r\n" ; } else { $ body .= "\r\n" ; $ body .= "Content-Type: text/plain; charset=UTF-8\r\n" ; $ body .= "Content-Transfer-Encoding: 8bit\r\n" ; } $ body .= "\r\n{$fieldData}\r\n" ; } $ body .= "--{$boundary}--\r\n" ; $ headers = array ( 'Content-Type' => "multipart/form-data; boundary={$boundary}" , 'Content-Length' => strlen ( $ body ) , ) ; $ apiResult = $ this -> session -> post ( $ this -> api , $ headers , $ body ) ; return unserialize ( $ apiResult -> body ) ; }
|
Uploads a file to the wiki API .
|
1,181
|
public function getSection ( $ section , $ includeHeading = false , $ includeSubsections = true ) { if ( is_int ( $ section ) ) { if ( ! isset ( $ this -> sections -> byIndex [ $ section ] ) ) { return false ; } $ coords = $ this -> sections -> byIndex [ $ section ] ; } else if ( is_string ( $ section ) ) { if ( ! isset ( $ this -> sections -> byName [ $ section ] ) ) { return false ; } $ coords = $ this -> sections -> byName [ $ section ] ; } @ extract ( $ coords ) ; if ( $ includeSubsections && $ offset > 0 ) { $ found = false ; foreach ( $ this -> sections -> byName as $ section ) { if ( $ found ) { if ( $ depth < $ section [ 'depth' ] ) { $ length += $ section [ 'length' ] ; } else { break ; } } else { if ( $ offset == $ section [ 'offset' ] ) { $ found = true ; } } } } $ text = substr ( $ this -> text , $ offset , $ length ) ; if ( ! $ includeHeading && $ offset > 0 ) { $ text = substr ( $ text , strpos ( $ text , "\n" ) ) ; } return $ text ; }
|
Returns the requested section with its subsections if any .
|
1,182
|
public function delete ( $ reason = null ) { $ data = array ( 'title' => $ this -> title , 'token' => $ this -> edittoken , ) ; if ( ! is_null ( $ reason ) ) { $ data [ 'reason' ] = $ reason ; } $ r = $ this -> wikimate -> delete ( $ data ) ; if ( isset ( $ r [ 'delete' ] ) ) { $ this -> exists = false ; $ this -> error = null ; return true ; } $ this -> error = $ r [ 'error' ] ; return false ; }
|
Delete the page .
|
1,183
|
private function findSection ( $ section ) { if ( is_int ( $ section ) || $ section === 'new' ) { return $ section ; } else if ( is_string ( $ section ) ) { $ sections = array_keys ( $ this -> sections -> byName ) ; $ index = array_search ( $ section , $ sections ) ; if ( $ index !== false ) { return $ index ; } } $ this -> error = array ( ) ; $ this -> error [ 'page' ] = "Section '$section' was not found on this page" ; return - 1 ; }
|
Find a section s index by name . If a section index or new is passed it is returned directly .
|
1,184
|
public function getInfo ( $ refresh = false , $ history = null ) { if ( $ refresh ) { $ data = array ( 'titles' => 'File:' . $ this -> filename , 'prop' => 'info|imageinfo' , 'iiprop' => 'bitdepth|canonicaltitle|comment|parsedcomment|' . 'commonmetadata|metadata|extmetadata|mediatype|' . 'mime|thumbmime|sha1|size|timestamp|url|user|userid' , 'intoken' => 'edit' , ) ; if ( is_array ( $ history ) ) { foreach ( $ history as $ key => $ val ) { $ data [ $ key ] = $ val ; } $ data [ 'iiprop' ] .= '|archivename' ; } $ r = $ this -> wikimate -> query ( $ data ) ; if ( isset ( $ r [ 'error' ] ) ) { $ this -> error = $ r [ 'error' ] ; return null ; } else { $ this -> error = null ; } $ page = array_pop ( $ r [ 'query' ] [ 'pages' ] ) ; unset ( $ r , $ data ) ; if ( isset ( $ page [ 'invalid' ] ) ) { $ this -> invalid = true ; return null ; } $ this -> edittoken = $ page [ 'edittoken' ] ; if ( ! isset ( $ page [ 'missing' ] ) && isset ( $ page [ 'imageinfo' ] ) ) { $ this -> exists = true ; $ this -> info = $ page [ 'imageinfo' ] [ 0 ] ; $ this -> history = $ page [ 'imageinfo' ] ; } unset ( $ page ) ; } return $ this -> info ; }
|
Gets the information of the file . If refresh is true then this method will query the wiki API again for the file details .
|
1,185
|
public function getBitDepth ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return ( int ) $ this -> info [ 'bitdepth' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return - 1 ; } return ( int ) $ info [ 'bitdepth' ] ; }
|
Returns the bit depth of this file or of its specified revision .
|
1,186
|
public function getCanonicalTitle ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'canonicaltitle' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'canonicaltitle' ] ; }
|
Returns the canonical title of this file or of its specified revision .
|
1,187
|
public function getComment ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'comment' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'comment' ] ; }
|
Returns the edit comment of this file or of its specified revision .
|
1,188
|
public function getCommonMetadata ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'commonmetadata' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'commonmetadata' ] ; }
|
Returns the common metadata of this file or of its specified revision .
|
1,189
|
public function getDescriptionUrl ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'descriptionurl' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'descriptionurl' ] ; }
|
Returns the description URL of this file or of its specified revision .
|
1,190
|
public function getExtendedMetadata ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'extmetadata' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'extmetadata' ] ; }
|
Returns the extended metadata of this file or of its specified revision .
|
1,191
|
public function getHeight ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return ( int ) $ this -> info [ 'height' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return - 1 ; } return ( int ) $ info [ 'height' ] ; }
|
Returns the height of this file or of its specified revision .
|
1,192
|
public function getMediaType ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'mediatype' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'mediatype' ] ; }
|
Returns the media type of this file or of its specified revision .
|
1,193
|
public function getMetadata ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'metadata' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'metadata' ] ; }
|
Returns the Exif metadata of this file or of its specified revision .
|
1,194
|
public function getMime ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'mime' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'mime' ] ; }
|
Returns the MIME type of this file or of its specified revision .
|
1,195
|
public function getParsedComment ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'parsedcomment' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'parsedcomment' ] ; }
|
Returns the parsed edit comment of this file or of its specified revision .
|
1,196
|
public function getSha1 ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'sha1' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'sha1' ] ; }
|
Returns the SHA - 1 hash of this file or of its specified revision .
|
1,197
|
public function getSize ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return ( int ) $ this -> info [ 'size' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return - 1 ; } return ( int ) $ info [ 'size' ] ; }
|
Returns the size of this file or of its specified revision .
|
1,198
|
public function getThumbMime ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return ( isset ( $ this -> info [ 'thumbmime' ] ) ? $ this -> info [ 'thumbmime' ] : '' ) ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return ( isset ( $ info [ 'thumbmime' ] ) ? $ info [ 'thumbmime' ] : '' ) ; }
|
Returns the MIME type of this file s thumbnail or of its specified revision . Returns empty string if property not available for this file type .
|
1,199
|
public function getTimestamp ( $ revision = null ) { if ( ! isset ( $ revision ) ) { return $ this -> info [ 'timestamp' ] ; } if ( ( $ info = $ this -> getRevision ( $ revision ) ) === null ) { return null ; } return $ info [ 'timestamp' ] ; }
|
Returns the timestamp of this file or of its specified revision .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.