idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
10,600
protected function compileInitialization ( Buffer $ buffer ) { $ configurationLoader = new Configuration \ ConfigurationLoader ( $ this -> staticConfig , new FileLocator ( array ( getcwd ( ) ) ) , new Configuration \ FileLoader ( new Configuration \ PathDefaultFileLocator ( 'ZPLUGINPATH' , $ this -> staticPluginPaths )...
Writes the initialization code for a static build of Z .
10,601
private static function getParamsToSign ( array $ params , array $ ignoreParamKeys = [ ] , int $ currentLevel = 1 , string $ prefix = '' ) : array { $ paramsToSign = [ ] ; foreach ( $ params as $ key => $ value ) { if ( ( in_array ( $ key , $ ignoreParamKeys ) && $ currentLevel == 1 ) ) { continue ; } $ paramKey = ( $ ...
Get parameters to sign
10,602
protected function addConstants ( $ constants , $ fileDescriptor ) { foreach ( $ constants as $ constant ) { $ constantDescriptor = $ this -> getBuilder ( ) -> buildDescriptor ( $ constant ) ; if ( $ constantDescriptor ) { $ constantDescriptor -> setLocation ( $ fileDescriptor , $ constant -> getLineNumber ( ) ) ; if (...
Registers the child constants with the generated File Descriptor .
10,603
protected function addFunctions ( $ functions , $ fileDescriptor ) { foreach ( $ functions as $ function ) { $ functionDescriptor = $ this -> getBuilder ( ) -> buildDescriptor ( $ function ) ; if ( $ functionDescriptor ) { $ functionDescriptor -> setLocation ( $ fileDescriptor , $ function -> getLineNumber ( ) ) ; if (...
Registers the child functions with the generated File Descriptor .
10,604
protected function addInterfaces ( $ interfaces , $ fileDescriptor ) { foreach ( $ interfaces as $ interface ) { $ interfaceDescriptor = $ this -> getBuilder ( ) -> buildDescriptor ( $ interface ) ; if ( $ interfaceDescriptor ) { $ interfaceDescriptor -> setLocation ( $ fileDescriptor , $ interface -> getLineNumber ( )...
Registers the child interfaces with the generated File Descriptor .
10,605
protected function addTraits ( $ traits , $ fileDescriptor ) { foreach ( $ traits as $ trait ) { $ traitDescriptor = $ this -> getBuilder ( ) -> buildDescriptor ( $ trait ) ; if ( $ traitDescriptor ) { $ traitDescriptor -> setLocation ( $ fileDescriptor , $ trait -> getLineNumber ( ) ) ; if ( count ( $ traitDescriptor ...
Registers the child traits with the generated File Descriptor .
10,606
protected function addMarkers ( $ markers , $ fileDescriptor ) { foreach ( $ markers as $ marker ) { list ( $ type , $ message , $ line ) = $ marker ; $ fileDescriptor -> getMarkers ( ) -> add ( array ( 'type' => $ type , 'message' => $ message , 'line' => $ line , ) ) ; } }
Registers the markers that were found in a File with the File Descriptor .
10,607
protected function bindNumericParameters ( ) : void { $ values = $ this -> getValues ( ) ; $ cnt = count ( $ values ) ; for ( $ index0 = 0 , $ index1 = 1 ; $ index0 < $ cnt ; $ index0 ++ , $ index1 ++ ) { $ value = $ this -> toScalar ( $ values [ $ index0 ] ) ; $ this -> getWrappedStatement ( ) -> bindValue ( $ index1 ...
Bind ? parameters
10,608
protected function loop ( ) { while ( $ this -> a !== false && ! is_null ( $ this -> a ) && $ this -> a !== '' ) { switch ( $ this -> a ) { case "\n" : if ( strpos ( '(-+{[@' , $ this -> b ) !== false ) { echo $ this -> a ; $ this -> saveString ( ) ; break ; } if ( $ this -> b === ' ' ) break ; case ' ' : if ( static :...
The primary action occurs here . This function loops through the input string outputting anything that s relevant and discarding anything that is not .
10,609
protected function getChar ( ) { if ( isset ( $ this -> c ) ) { $ char = $ this -> c ; unset ( $ this -> c ) ; } else { $ char = substr ( $ this -> input , $ this -> index , 1 ) ; if ( isset ( $ char ) && $ char === false ) { return false ; } $ this -> index ++ ; } if ( $ char !== "\n" && ord ( $ char ) < 32 ) return '...
Returns the next string for processing based off of the current index .
10,610
public function get ( ) { if ( ! isset ( $ this -> data ) && isset ( $ this -> session [ $ this -> key ] ) ) { $ this -> data = $ this -> session [ $ this -> key ] ; unset ( $ this -> session [ $ this -> key ] ) ; } return $ this -> data ? ( object ) $ this -> data : null ; }
Get the flash .
10,611
public function reissue ( ) { if ( ! isset ( $ this -> data ) && isset ( $ this -> session [ $ this -> key ] ) ) { $ this -> data = $ this -> session [ $ this -> key ] ; } else { $ this -> session [ $ this -> key ] = $ this -> data ; } }
Reissue the flash .
10,612
final protected function build_query ( ) { $ select = empty ( $ this -> _select ) ? $ this -> default_select ( ) : implode ( ', ' , $ this -> _select ) ; $ calc = $ this -> _calc_rows ? ' SQL_CALC_FOUND_ROWS' : '' ; $ distinct = $ this -> _distinct ? sprintf ( 'DISTINCT(%s)' , $ this -> escape_column_name ( $ this -> _...
Build query with current setting
10,613
private function build_where ( array $ where_array ) { $ where_clause = [ ] ; $ counter = 0 ; foreach ( $ where_array as list ( $ glue , $ where ) ) { if ( $ counter ) { $ where_clause [ ] = $ glue ; } if ( is_array ( $ where ) ) { $ where_clause [ ] = $ this -> build_where ( $ where_array ) ; } else { $ where_clause [...
Build where clause
10,614
final protected function select ( $ name , $ escape = true ) { $ this -> _select [ ] = $ escape ? $ this -> escape_column_name ( $ name ) : $ name ; return $ this ; }
Set select param
10,615
final protected function where_not_null ( $ column , $ or = false ) { $ this -> _wheres [ ] = [ $ this -> and_or ( $ or ) , sprintf ( "%s IS NOT NULL" , $ this -> escape_column_name ( $ column ) ) ] ; return $ this ; }
Add where not null clause
10,616
final protected function where_like ( $ column , $ replace , $ position = 'both' , $ or = false ) { switch ( strtolower ( $ position ) ) { case 'left' : $ replace = '%' . $ replace ; break ; case 'right' : $ replace = $ replace . '%' ; break ; default : $ replace = '%' . $ replace . '%' ; break ; } $ column = $ this ->...
Add Where LIKE
10,617
final protected function wheres ( array $ wheres , $ or = false ) { foreach ( $ wheres as $ where => $ replace ) { $ this -> where ( $ where , $ replace , $ or ) ; } return $ this ; }
Add where in one shot
10,618
final protected function group_by ( $ column , $ order = 'ASC' ) { $ order = 'DESC' === strtoupper ( $ order ) ? 'DESC' : 'ASC' ; $ this -> _group_by [ ] = sprintf ( '%s %s' , $ this -> escape_column_name ( $ column ) , $ order ) ; return $ this ; }
Add group by
10,619
final protected function order_by ( $ column , $ order = 'ASC' ) { $ order = 'DESC' === strtoupper ( $ order ) ? 'DESC' : 'ASC' ; $ this -> _order_by [ ] = sprintf ( '%s %s' , $ this -> escape_column_name ( $ column ) , $ order ) ; return $ this ; }
Add order by
10,620
private function escape_column_name ( $ column_names ) { $ columns = [ ] ; foreach ( explode ( ',' , $ column_names ) as $ column_name ) { $ column_name = trim ( $ column_name ) ; $ columns [ ] = preg_replace ( '/[`\'";\n\r\\\\\\0]/u' , '' , $ column_name ) ; } return implode ( ', ' , $ columns ) ; }
Wrap table name with backtick
10,621
final protected function clear ( ) { $ this -> _distinct = false ; $ this -> _select = [ ] ; $ this -> _from = '' ; $ this -> _join = [ ] ; $ this -> _wheres = [ ] ; $ this -> _group_by = [ ] ; $ this -> _order_by = [ ] ; $ this -> _limit = [ ] ; }
Clear all result
10,622
final protected function cache_query ( $ sql , $ result ) { if ( isset ( $ this -> query_cache [ $ sql ] ) ) { $ this -> query_cache [ $ sql ] = $ result ; } elseif ( count ( $ this -> query_cache ) >= $ this -> cache_limit ) { array_shift ( $ this -> query_cache ) ; $ this -> query_cache [ $ sql ] = $ result ; } }
Save query cache
10,623
public function create ( array $ users , int $ public = 0 ) : ? string { if ( $ this -> check ( ) ) { $ join = '' ; $ where = '' ; $ values = [ $ this -> user -> get_id ( ) , $ public ] ; foreach ( $ users as $ i => $ u ) { $ join .= "JOIN bbn_chats_users AS u$i ON u$i.id_chat = bbn_chats.id" . PHP_EOL ; $ where .= "AN...
Creates a new chat with the current userr and another participant .
10,624
public function make_admin ( string $ id_chat , string $ id_user ) : bool { if ( $ this -> is_admin ( $ id_chat ) ) { return ( bool ) $ this -> db -> update_ignore ( 'bbn_chats_users' , [ 'admin' => 1 ] , [ 'id_chat' => $ id_chat , 'id_user' => $ id_user , ] ) ; } return false ; }
Makes the given participant an admin of the given chat provided the current user is admin of this chat .
10,625
public function is_participant ( string $ id_chat , string $ id_user = null ) : ? bool { if ( $ this -> check ( ) ) { return ( bool ) $ this -> db -> count ( 'bbn_chats_users' , [ 'id_chat' => $ id_chat , 'id_user' => $ id_user ? : $ this -> user -> get_id ( ) ] ) ; } return null ; }
Checks whether the given user is participant of the given chat .
10,626
public function info ( $ id_chat ) : ? array { if ( $ this -> check ( ) ) { return $ this -> db -> rselect ( 'bbn_chats' , [ ] , [ 'id' => $ id_chat ] ) ? : null ; } return null ; }
Gets information about the given chat .
10,627
public function get_participants ( string $ id_chat ) : ? array { if ( $ this -> check ( ) ) { return $ this -> db -> get_field_values ( 'bbn_chats_users' , 'id_user' , [ 'id_chat' => $ id_chat ] ) ; } return null ; }
Returns the participants of the given chat as an array of id_user .
10,628
public function talk ( string $ id_chat , string $ message ) : ? int { if ( $ this -> check ( ) && ( $ chat = $ this -> info ( $ id_chat ) ) && ! $ chat [ 'blocked' ] ) { $ users = $ this -> get_participants ( $ id_chat ) ; if ( \ in_array ( $ this -> user -> get_id ( ) , $ users , true ) ) { $ time = microtime ( true ...
Sends a new message from the current user in the given chat .
10,629
public function is_admin ( $ id_chat ) : ? bool { if ( $ this -> check ( ) && ( $ chat = $ this -> info ( $ id_chat ) ) && ! $ chat [ 'blocked' ] ) { return ( bool ) $ this -> db -> count ( 'bbn_chats_users' , [ 'id_chat' => $ id_chat , 'id_user' => $ this -> user -> get_id ( ) , 'admin' => 1 ] ) ; } return null ; }
Checks whether the current user is an admin of the given chat or not .
10,630
public function block ( $ id_chat ) : bool { if ( $ this -> is_admin ( $ id_chat ) ) { return ( bool ) $ this -> db -> update ( 'bbn_chats' , [ 'blocked' => 1 ] , [ 'id' => $ id_chat ] ) ; } return false ; }
Close a chat by setting blocked to 1 .
10,631
public static function setApiVersion ( $ version ) { if ( ! in_array ( $ version , [ 1 , 2 ] ) ) { throw new \ Exception ( sprintf ( "The %d version is not supported" , $ version ) ) ; } self :: $ apiVersion = $ version ; if ( self :: $ url ) { self :: initServices ( ) ; } }
Define which API version to use
10,632
public static function initServices ( $ refresh = false ) { $ path = sprintf ( '%s%sxac-services-v%d.conf' , ! empty ( self :: $ logPath ) ? self :: $ logPath : sys_get_temp_dir ( ) , DIRECTORY_SEPARATOR , self :: $ apiVersion ) ; if ( $ refresh === true || ! file_exists ( $ path ) ) { self :: log ( sprintf ( "Refresh ...
Retrieve definition of available API services
10,633
public function call ( $ endpoint , $ method = 'GET' , array $ data = [ ] ) { if ( substr ( $ endpoint , - 1 ) == '/' ) { $ endpoint = substr ( $ endpoint , 0 , strlen ( $ endpoint ) - 1 ) ; } self :: log ( "Calling $method /api/$endpoint" ) ; $ params = [ 'headers' => [ 'Accept' => sprintf ( 'application/vnd.xac.v%d+j...
Make a HTTP Request and return response
10,634
public static function log ( $ message , $ level = Logger :: INFO ) { if ( ! self :: $ logger ) { $ logfile = sprintf ( '%s%sarrowsphere-client.log' , sys_get_temp_dir ( ) , DIRECTORY_SEPARATOR ) ; self :: $ logger = new Logger ( 'xAC' ) ; self :: $ logger -> pushHandler ( new StreamHandler ( $ logfile , Logger :: INFO...
Log messages to client log file
10,635
public static function getInstance ( HttpClient $ transport = null ) { if ( is_null ( self :: $ client ) ) { self :: $ client = new self ( ) ; if ( ! is_null ( $ transport ) ) { self :: $ client -> setTransport ( $ transport ) ; } } return self :: $ client ; }
Return a singleton instance of the class
10,636
public static function getServicesList ( ) { $ map = [ 'GET' => 'get' , 'POST' => 'create' , 'PUT' => 'update' , 'DELETE' => 'delete' , ] ; $ table = new \ Console_Table ( ) ; $ table -> setHeaders ( [ 'Method' , 'Type' , 'Description' , 'Parameters' ] ) ; foreach ( self :: getServices ( ) as $ key => $ service ) { if ...
Display a list of available service on console
10,637
public static function load ( $ file ) { add_filter ( 'calderawp_file_locator_allow_extensions' , function ( $ allowed , $ context ) { if ( self :: $ context === $ context ) { $ allowed = array ( 'html' , 'htm' ) ; } return $ allowed ; } , 10 , 2 ) ; $ file = file_locator :: locate ( $ file , self :: $ context , true )...
Attempts to load a file and if so puts its contents in an array as expected by Metaplate
10,638
public function merge ( array $ newOptions ) { foreach ( $ newOptions as $ key => $ value ) { $ this -> __set ( $ key , $ value ) ; } }
Merge an array into the actual options object . This method merges an array of new options into the actual options object .
10,639
public function invoke ( callable $ function , array $ parameters = [ ] ) { $ reflection = $ this -> reflectionTools -> getReflectionFunction ( $ function ) ; $ parameters = $ this -> getFunctionParameters ( $ reflection , $ parameters ) ; return call_user_func_array ( $ function , $ parameters ) ; }
Invokes a function after resolving its parameters .
10,640
public function instantiate ( string $ class , array $ parameters = [ ] ) { $ class = new \ ReflectionClass ( $ class ) ; $ instance = $ class -> newInstanceWithoutConstructor ( ) ; $ this -> inject ( $ instance ) ; $ constructor = $ class -> getConstructor ( ) ; if ( $ constructor ) { $ parameters = $ this -> getFunct...
Instantiates a class by resolving its constructor parameters and injects dependencies in the resulting object .
10,641
public function inject ( $ object ) : void { $ reflection = new \ ReflectionObject ( $ object ) ; $ this -> injectProperties ( $ reflection , $ object ) ; $ this -> injectMethods ( $ reflection , $ object ) ; }
Injects dependencies in an object .
10,642
private function getFunctionParameters ( \ ReflectionFunctionAbstract $ function , array $ parameters = [ ] ) : array { $ result = [ ] ; foreach ( $ function -> getParameters ( ) as $ parameter ) { $ name = $ parameter -> getName ( ) ; if ( array_key_exists ( $ name , $ parameters ) ) { $ value = $ parameters [ $ name ...
Returns an associative array of parameters to call a given function .
10,643
public static function allElementsEqual ( array $ haystack , $ needle = null ) { $ return = true ; if ( func_num_args ( ) == 2 ) { $ compareAgainst = $ needle ; } else { $ compareAgainst = reset ( $ haystack ) ; } foreach ( $ haystack as $ element ) { if ( $ compareAgainst != $ element ) { $ return = false ; break ; } ...
Checks if all elements of the array have same value
10,644
public static function isA ( $ name , $ mask ) { if ( ! static :: isElement ( $ name ) ) { return false ; } return ( static :: element ( $ name ) & $ mask ) == $ mask ; }
Check whether the given element meets the given criterion .
10,645
public static function element ( $ name ) { if ( isset ( static :: $ html5 [ $ name ] ) ) { return static :: $ html5 [ $ name ] ; } if ( isset ( static :: $ svg [ $ name ] ) ) { return static :: $ svg [ $ name ] ; } if ( isset ( static :: $ mathml [ $ name ] ) ) { return static :: $ mathml [ $ name ] ; } return false ;...
Get the element mask for the given element name .
10,646
public static function normalizeSvgElement ( $ name ) { $ name = strtolower ( $ name ) ; if ( isset ( static :: $ svgCaseSensitiveElementMap [ $ name ] ) ) { $ name = static :: $ svgCaseSensitiveElementMap [ $ name ] ; } return $ name ; }
Normalize a SVG element name to its proper case and form .
10,647
public static function normalizeSvgAttribute ( $ name ) { $ name = strtolower ( $ name ) ; if ( isset ( static :: $ svgCaseSensitiveAttributeMap [ $ name ] ) ) { $ name = static :: $ svgCaseSensitiveAttributeMap [ $ name ] ; } return $ name ; }
Normalize a SVG attribute name to its proper case and form .
10,648
private function summarize ( array $ whereClause , $ selector ) { switch ( count ( $ whereClause ) ) { case 1 : return $ whereClause [ 0 ] ; default : if ( $ selector instanceof RecordSelector ) { return [ '@OR' => $ whereClause ] ; } if ( $ selector instanceof DocumentSelector ) { return [ '$or' => $ whereClause ] ; }...
Summarize expression array .
10,649
public static function log ( $ st , $ file = 'misc' ) { if ( \ defined ( 'BBN_DATA_PATH' ) ) { if ( ! \ is_string ( $ file ) ) { $ file = 'misc' ; } $ log_file = BBN_DATA_PATH . 'logs/' . $ file . '.log' ; $ backtrace = array_filter ( debug_backtrace ( ) , function ( $ a ) { return $ a [ 'function' ] === 'log' ; } ) ; ...
Saves logs to a file .
10,650
public static function log_error ( $ errno , $ errstr , $ errfile , $ errline ) { if ( \ defined ( 'BBN_DATA_PATH' ) ) { if ( is_dir ( BBN_DATA_PATH . 'logs' ) ) { $ file = BBN_DATA_PATH . 'logs/_php_error.json' ; $ backtrace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 20 ) ; $ r = false ; if ( is_file ( $ file )...
Puts the PHP errors into a JSON file .
10,651
public static function merge_objects ( $ o1 , $ o2 ) { $ args = \ func_get_args ( ) ; if ( \ count ( $ args ) > 2 ) { for ( $ i = \ count ( $ args ) - 1 ; $ i > 1 ; $ i -- ) { $ args [ $ i - 1 ] = self :: merge_arrays ( $ args [ $ i - 1 ] , $ args [ $ i ] ) ; } $ o2 = $ args [ 1 ] ; } $ a1 = self :: to_array ( $ o1 ) ;...
Returns to a merged object from two objects .
10,652
public static function merge_arrays ( array $ a1 , array $ a2 ) { $ args = \ func_get_args ( ) ; if ( \ count ( $ args ) > 2 ) { for ( $ i = \ count ( $ args ) - 1 ; $ i > 1 ; $ i -- ) { $ args [ $ i - 1 ] = self :: merge_arrays ( $ args [ $ i - 1 ] , $ args [ $ i ] ) ; } $ a2 = $ args [ 1 ] ; } if ( ( self :: is_assoc...
Returns to a merged array from two or more arrays .
10,653
public static function is_assoc ( array $ r ) { $ keys = array_keys ( $ r ) ; $ c = \ count ( $ keys ) ; for ( $ i = 0 ; $ i < $ c ; $ i ++ ) { if ( $ keys [ $ i ] !== $ i ) { return 1 ; } } return false ; }
Checks if the given array is associative .
10,654
public static function get_dump ( ) { $ args = \ func_get_args ( ) ; $ st = '' ; foreach ( $ args as $ a ) { $ r = $ a ; if ( \ is_null ( $ a ) ) { $ r = 'null' ; } else if ( $ a === false ) { $ r = 'false' ; } else if ( $ a === true ) { $ r = 'true' ; } else if ( $ a === 0 ) { $ r = '0' ; } else if ( $ a === '' ) { $ ...
Returns a dump of the given variable .
10,655
public static function to_keypair ( $ arr , $ protected = 1 ) { $ num = \ count ( $ arr ) ; $ res = [ ] ; if ( ( $ num % 2 ) === 0 ) { $ i = 0 ; while ( isset ( $ arr [ $ i ] ) ) { if ( ! \ is_string ( $ arr [ $ i ] ) || ( ! $ protected && ! preg_match ( '/[0-9A-z\-_]+/8' , str :: cast ( $ arr [ $ i ] ) ) ) ) { return ...
Converts a numeric array into an associative one alternating key and value .
10,656
public static function min_with_key ( $ array , $ key ) { if ( ! \ is_array ( $ array ) || \ count ( $ array ) == 0 ) return false ; $ min = $ array [ 0 ] [ $ key ] ; foreach ( $ array as $ a ) { if ( $ a [ $ key ] < $ min ) { $ min = $ a [ $ key ] ; } } return $ min ; }
Returns the minimum value of an index from a multidimensional array .
10,657
public static function debug ( $ file = '' ) { $ debug = array_map ( function ( $ a ) { if ( isset ( $ a [ 'object' ] ) ) { unset ( $ a [ 'object' ] ) ; } return $ a ; } , debug_backtrace ( ) ) ; if ( empty ( $ file ) ) { self :: hdump ( $ debug ) ; } else { self :: log ( $ debug , $ file ) ; } }
Gets the backtrace and dumps or logs it into a file .
10,658
public static function find ( array $ ar , array $ where ) { if ( ! empty ( $ where ) ) { foreach ( $ ar as $ i => $ v ) { $ ok = 1 ; foreach ( $ where as $ k => $ w ) { if ( ! isset ( $ v [ $ k ] ) || ( $ v [ $ k ] !== $ w ) ) { $ ok = false ; break ; } } if ( $ ok ) { return $ i ; } } } return false ; }
Returns the array s first index which satisfies the where condition .
10,659
public static function get_field ( array $ r , array $ where , string $ field ) { if ( ( $ res = self :: get_row ( $ r , $ where ) ) && isset ( $ res [ $ field ] ) ) { return $ res [ $ field ] ; } return false ; }
Returns the first value of a specific field of an array .
10,660
public static function sort ( & $ ar ) { usort ( $ ar , function ( $ a , $ b ) { if ( ! str :: is_number ( $ a , $ b ) ) { $ a = str_replace ( '.' , '0' , str_replace ( '_' , '1' , str :: change_case ( $ a , 'lower' ) ) ) ; $ b = str_replace ( '.' , '0' , str_replace ( '_' , '1' , str :: change_case ( $ b , 'lower' ) )...
Sorts the items of an array .
10,661
public static function curl ( string $ url , array $ param = null , array $ options = [ 'post' => 1 ] ) { $ ch = curl_init ( ) ; self :: $ last_curl = $ ch ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; if ( \ is_object ( $ param ) ) { $ param = self :: to_array ( $ param ) ; } if ( \ defined ( 'BBN_IS_SSL' ) &&...
Makes a Curl call towards a URL and returns the result as a string .
10,662
public static function get_tree ( $ ar ) { $ res = [ ] ; foreach ( $ ar as $ k => $ a ) { $ r = [ 'text' => $ k ] ; if ( \ is_object ( $ a ) ) { $ a = self :: to_array ( $ a ) ; } if ( \ is_array ( $ a ) ) { $ r [ 'items' ] = self :: get_tree ( $ a ) ; } else if ( \ is_null ( $ a ) ) { $ r [ 'text' ] .= ': null' ; } el...
Returns the given array or object as a tree structure ready for a JS tree .
10,663
public static function is_same ( string $ file1 , string $ file2 , $ strict = false ) { if ( ! is_file ( $ file1 ) || ! is_file ( $ file2 ) ) { throw Exception ( "Boo! One of the files given to the x::is_same function doesn't exist" ) ; } else { $ same = filesize ( $ file1 ) === filesize ( $ file2 ) ; if ( ! $ strict |...
Checks if two files are the same .
10,664
public static function to_excel ( array $ data , string $ file , bool $ with_titles = true ) : bool { $ checked = false ; $ todo = [ ] ; foreach ( $ data as $ d ) { if ( ! $ checked && self :: is_assoc ( $ d ) ) { if ( $ with_titles ) { $ line1 = [ ] ; $ line2 = [ ] ; foreach ( $ d as $ k => $ v ) { $ line1 [ ] = $ k ;...
Creates an Excel file from a given array .
10,665
public static function make_uid ( $ binary = false , $ hyphens = false ) { $ tmp = sprintf ( $ hyphens ? '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' : '%04x%04x%04x%04x%04x%04x%04x%04x' , mt_rand ( 0 , 0xffff ) , mt_rand ( 0 , 0xffff ) , mt_rand ( 0 , 0xffff ) , mt_rand ( 0 , 0x0fff ) | 0x4000 , mt_rand ( 0 , 0x3fff ) | 0x8...
Makes a UID .
10,666
public static function convert_uids ( $ st ) { if ( \ is_array ( $ st ) || \ is_object ( $ st ) ) { foreach ( $ st as & $ s ) { $ s = self :: convert_uids ( $ s ) ; } } else if ( \ bbn \ str :: is_uid ( $ st ) ) { $ st = bin2hex ( $ st ) ; } return $ st ; }
Converts a hex UID to a binary UID . You can also give an array or an object to convert the array s items or the object s properties .
10,667
public static function compare_floats ( $ v1 , $ v2 , string $ operator = '===' , int $ precision = 4 ) : bool { $ v1 = round ( ( float ) $ v1 * pow ( 10 , $ precision ) ) ; $ v2 = round ( ( float ) $ v2 * pow ( 10 , $ precision ) ) ; switch ( $ operator ) { case '===' : return $ v1 === $ v2 ; case '==' : return $ v1 =...
Compares two float numbers with the given operator .
10,668
public static function json_base64_decode ( $ st ) : ? array { $ res = \ is_string ( $ st ) ? json_decode ( $ st , true ) : $ st ; if ( \ is_array ( $ res ) ) { foreach ( $ res as $ i => $ a ) { if ( \ is_array ( $ a ) ) { $ res [ $ i ] = self :: json_base64_decode ( $ a ) ; } else if ( \ is_string ( $ a ) ) { $ res [ ...
Decodes the base64 array s values . You can also give a JSON string of an array .
10,669
public static function index_by_first_val ( array $ ar ) : array { if ( empty ( $ ar ) || ! isset ( $ ar [ 0 ] ) || ! \ count ( $ ar [ 0 ] ) ) { return $ ar ; } $ cols = array_keys ( $ ar [ 0 ] ) ; $ idx = array_shift ( $ cols ) ; $ num_cols = \ count ( $ cols ) ; $ res = [ ] ; foreach ( $ ar as $ d ) { $ index = $ d [...
Creates an associative array based on the first array s value .
10,670
public function getQueryString ( ) { $ requestUri = $ this -> getRequestUri ( ) ; if ( false !== $ qPos = mb_strpos ( $ requestUri , '?' ) ) { return mb_substr ( $ requestUri , $ qPos + 1 ) ; } return '' ; }
The query string .
10,671
public function getQueryStringAsArray ( ) { $ queryString = $ this -> getQueryString ( ) ; if ( '' === $ queryString ) { return [ ] ; } $ queryStringArray = [ ] ; parse_str ( $ queryString , $ queryStringArray ) ; return $ queryStringArray ; }
The query string as array .
10,672
public function getQueryParameter ( $ key ) { $ queryStringArray = $ this -> getQueryStringAsArray ( ) ; if ( array_key_exists ( $ key , $ queryStringArray ) ) { return $ queryStringArray [ $ key ] ; } return null ; }
Return a specific query string parameter value .
10,673
public function getRoot ( ) { $ requestUri = $ this -> getRequestUri ( ) ; $ pathInfo = $ this -> getPathInfo ( ) ; if ( false !== $ qPos = mb_strpos ( $ requestUri , '?' ) ) { $ requestUri = mb_substr ( $ requestUri , 0 , $ qPos + 1 ) ; } if ( false !== $ pPos = mb_strrpos ( $ requestUri , $ pathInfo ) ) { $ requestUr...
Get the REQUEST_URI without PATH_INFO and QUERY_STRING taking server rewriting in consideration .
10,674
public function getAuthority ( ) { $ scheme = $ this -> getScheme ( ) ; $ serverName = $ this -> getHost ( ) ; $ serverPort = $ this -> getPort ( ) ; $ authority = sprintf ( '%s://%s' , $ scheme , $ serverName ) ; if ( ( 'https' === $ scheme && 443 !== $ serverPort ) || ( 'http' === $ scheme && 80 !== $ serverPort ) ) ...
Get the authority part of the URL . That is the scheme host and optional port if it is not a standard port .
10,675
public function isGranted ( string $ action ) : bool { if ( empty ( $ this -> allowed ) ) { return false ; } if ( isset ( $ this -> denied [ $ action ] ) || isset ( $ this -> denied [ self :: WILDCARD ] ) ) { return false ; } $ rules = $ this -> getRules ( $ action ) ; foreach ( $ rules as $ rule ) { if ( isset ( $ thi...
Returns true if the policy should allow the action to be carried out .
10,676
private function getRules ( string $ action ) : array { $ rules = [ ] ; $ parts = explode ( self :: DELIMITER , $ action ) ; while ( array_pop ( $ parts ) ) { $ rules [ ] = implode ( self :: DELIMITER , $ parts ) . self :: DELIMITER . self :: WILDCARD ; } $ rules = array_reverse ( $ rules ) ; $ rules [ 0 ] = trim ( $ r...
Converts an action with potentially colon delimiters into a set of permissions to check for .
10,677
public function getLoginLogs ( ) { $ class = $ this -> loginLogClass ; try { return $ class :: getLatests ( $ this , Login :: GET_ALL_LATESTS ) ; } catch ( \ Exception $ ex ) { Yii :: error ( $ ex -> getMessage ( ) , __METHOD__ ) ; return [ ] ; } }
Get login logs .
10,678
public function recordLogin ( $ config = [ ] ) { if ( empty ( $ this -> loginLogClass ) ) { return false ; } $ log = $ this -> create ( $ this -> loginLogClass , $ config ) ; try { return $ log -> save ( ) ; } catch ( \ Exception $ ex ) { Yii :: error ( $ ex -> getMessage ( ) , __METHOD__ ) ; } }
Record login .
10,679
public function setData ( $ collection , $ resource_name = '' ) { $ this -> collection = collect ( ) ; if ( ! $ this -> resource_name ) { $ this -> resource_name = empty ( $ resource_name ) ? 'undefined' : $ resource_name ; } $ this -> data = [ ] ; foreach ( $ collection as $ item ) { $ this -> collection -> push ( clo...
Set collection data
10,680
public static function configure ( $ config = [ ] ) { $ defaults = include dirname ( __DIR__ ) . '/conf/defaults.php' ; self :: $ config = array_replace_recursive ( $ defaults , $ config ) ; if ( isset ( self :: $ driver ) ) { if ( self :: $ driver -> connected ) { self :: $ driver -> disconnect ( ) ; } self :: $ drive...
Apply configuration to Nymph .
10,681
public static function checkData ( & $ data , & $ sdata , $ selectors , $ guid = null , $ tags = null , $ typesAlreadyChecked = [ ] , $ dataValsAreadyChecked = [ ] ) { return self :: $ driver -> checkData ( $ data , $ sdata , $ selectors , $ guid , $ tags , $ typesAlreadyChecked , $ dataValsAreadyChecked ) ; }
Check entity data to see if it matches given selectors .
10,682
public static function hsort ( & $ array , $ property = null , $ parentProperty = null , $ caseSensitive = false , $ reverse = false ) { return self :: $ driver -> hsort ( $ array , $ property , $ parentProperty , $ caseSensitive , $ reverse ) ; }
Sort an array of entities hierarchically by a specified property s value .
10,683
public static function sort ( & $ array , $ property = null , $ caseSensitive = false , $ reverse = false ) { return self :: $ driver -> sort ( $ array , $ property , $ caseSensitive , $ reverse ) ; }
Sort an array of entities by a specified property s value .
10,684
public function convertSymfonyRequest ( SymfonyRequest $ request ) { $ session = $ request -> getSession ( ) ; if ( $ session ) { $ session = $ session -> all ( ) ; } else { $ session = [ ] ; } $ parameters = $ request -> request -> all ( ) ; if ( in_array ( $ request -> getMethod ( ) , [ 'POST' , 'PUT' , 'PATCH' ] ) &...
Converts a Symfony request object into an Infuse request object .
10,685
public function convertInfuseResponse ( Response $ res ) { $ response = new SymfonyResponse ( $ res -> getBody ( ) , $ res -> getCode ( ) , $ res -> headers ( ) ) ; foreach ( $ res -> cookies ( ) as $ name => $ params ) { list ( $ value , $ expire , $ path , $ domain , $ secure , $ httponly ) = $ params ; $ cookie = ne...
Converts an Infuse response object into a Symfony response object .
10,686
private function _init_user ( bbn \ user $ user ) : preferences { $ this -> user = $ user ; $ this -> id_user = $ this -> user -> get_id ( ) ; $ this -> id_group = $ this -> user -> get_group ( ) ; return $ this ; }
Sets the user variables using a user object
10,687
private function _insert ( string $ id_option , array $ cfg ) : int { $ json = ( $ tmp = $ this -> get_cfg ( false , $ cfg ) ) ? json_encode ( $ tmp ) : NULL ; return $ this -> db -> insert ( $ this -> class_cfg [ 'table' ] , [ $ this -> fields [ 'id_option' ] => $ id_option , $ this -> fields [ 'num' ] => $ cfg [ $ th...
Actually inserts a row into the preferences table
10,688
public function retrieve_user_ids ( string $ id_option = null , string $ id_user ) : ? array { return $ this -> _retrieve_ids ( $ id_option , $ id_user ) ; }
Returns preferences IDs from the option s ID and the given user ID
10,689
public function retrieve_group_ids ( string $ id_option = null , string $ id_group ) : ? array { return $ this -> _retrieve_ids ( $ id_option , null , $ id_group ) ; }
Returns preferences IDs from the option s ID and the given group ID
10,690
public function has ( string $ id_option = null , bool $ force = false ) : bool { if ( ! $ force && $ this -> user -> is_dev ( ) ) { return true ; } return ( bool ) $ this -> retrieve_ids ( $ id_option ) ; }
Returns true if the current user can access a preference false otherwise
10,691
public function user_has ( string $ id_option , string $ id_user ) : bool { return ( bool ) $ this -> _retrieve_ids ( $ id_option , $ id_user ) ; }
Checks if a user has the given preference
10,692
public function group_has ( string $ id_option , string $ id_group ) : bool { return ( bool ) $ this -> _retrieve_ids ( $ id_option , null , $ id_group ) ; }
Checks if a group has the given preference
10,693
public function get ( string $ id , bool $ with_config = true ) : ? array { if ( bbn \ str :: is_uid ( $ id ) ) { $ cols = implode ( ', ' , array_map ( function ( $ a ) { return $ a ; } , $ this -> fields ) ) ; $ table = $ this -> db -> tsn ( $ this -> class_cfg [ 'table' ] , true ) ; $ uid = $ this -> db -> csn ( $ th...
Returns the current user s preference based on the given id his own profile and his group s
10,694
public function get_all ( string $ id_option = null , bool $ with_config = true ) : ? array { if ( $ id_option = $ this -> _get_id_option ( $ id_option ) ) { $ fields = $ this -> fields ; if ( ! $ with_config ) { unset ( $ fields [ 'cfg' ] ) ; } $ table = $ this -> db -> tsn ( $ this -> class_table , true ) ; $ cols = ...
Returns an array of the current user s preferences based on the given id_option his own profile and his group s
10,695
public function set_by_option ( string $ id_option , array $ cfg ) : int { if ( $ id = $ this -> retrieve_user_ids ( $ id_option , $ this -> id_user ) ) { return $ this -> set ( $ id [ 0 ] , $ cfg ) ; } return $ this -> _insert ( $ id_option , $ cfg ) ; }
Sets the permission row for the current user by the option s ID
10,696
public function set ( string $ id , array $ cfg = null ) : int { return $ this -> db -> update ( $ this -> class_cfg [ 'table' ] , [ $ this -> fields [ 'cfg' ] => $ cfg ? json_encode ( $ this -> get_cfg ( false , $ cfg ) ) : null ] , [ $ this -> fields [ 'id' ] => $ id ] ) ; }
Sets the permission config for the current user by the preference s ID
10,697
public function update ( string $ id , array $ cfg ) : int { return $ this -> db -> update ( $ this -> class_cfg [ 'table' ] , [ $ this -> fields [ 'text' ] => $ cfg [ $ this -> fields [ 'text' ] ] ?? NULL , $ this -> fields [ 'num' ] => $ cfg [ $ this -> fields [ 'num' ] ] ?? NULL , $ this -> fields [ 'id_link' ] => $...
Sets the permission row for the current user by the preference s ID
10,698
public function add ( string $ id_option = null , array $ cfg ) : ? string { return ( ( $ id_option = $ this -> _get_id_option ( $ id_option ) ) && $ this -> _insert ( $ id_option , $ cfg ) ) ? $ this -> db -> last_id ( ) : null ; }
Adds a new preference for the given option for the current user .
10,699
public function delete ( $ id ) : ? int { return $ this -> db -> delete ( $ this -> class_cfg [ 'table' ] , [ $ this -> fields [ 'id' ] => $ id ] ) ; }
Deletes the given permission