idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
53,700
private function getHeaders ( array $ headers ) { $ str = '' ; foreach ( $ headers as $ key => $ value ) { $ str .= sprintf ( "%s: %s\r\n" , $ key , $ value ) ; } return $ str ; }
Get the headers formatted for the HTTP message .
53,701
public function getBoundary ( ) { if ( null === $ this -> boundary ) { $ this -> boundary = uniqid ( '' , true ) ; } return $ this -> boundary ; }
Get the boundary that separates the streams .
53,702
private function basename ( $ path ) { $ separators = '/' ; if ( DIRECTORY_SEPARATOR != '/' ) { $ separators .= DIRECTORY_SEPARATOR ; } $ path = rtrim ( $ path , $ separators ) ; $ filename = preg_match ( '@[^' . preg_quote ( $ separators , '@' ) . ']+$@' , $ path , $ matches ) ? $ matches [ 0 ] : '' ; return $ filenam...
Gets the filename from a given path .
53,703
protected function compile ( ) { $ this -> headers = array_merge ( $ this -> csp ( ) , $ this -> featurePolicy ( ) , $ this -> hpkp ( ) , $ this -> hsts ( ) , $ this -> expectCT ( ) , $ this -> clearSiteData ( ) , $ this -> miscellaneous ( ) ) ; $ this -> compiled = true ; }
Compile HTTP headers .
53,704
protected function csp ( ) : array { if ( ! is_null ( $ this -> config [ 'custom-csp' ] ) ) { if ( empty ( $ this -> config [ 'custom-csp' ] ) ) { return [ ] ; } return [ 'Content-Security-Policy' => $ this -> config [ 'custom-csp' ] , ] ; } return Builder :: getCSPHeader ( $ this -> config [ 'csp' ] ) ; }
Get CSP header .
53,705
protected function expectCT ( ) : array { if ( ! ( $ this -> config [ 'expect-ct' ] [ 'enable' ] ?? false ) ) { return [ ] ; } $ ct = "max-age={$this->config['expect-ct']['max-age']}" ; if ( $ this -> config [ 'expect-ct' ] [ 'enforce' ] ) { $ ct .= ', enforce' ; } if ( ! empty ( $ this -> config [ 'expect-ct' ] [ 'rep...
Generate Expect - CT header .
53,706
protected function clearSiteData ( ) : array { if ( ! ( $ this -> config [ 'clear-site-data' ] [ 'enable' ] ?? false ) ) { return [ ] ; } if ( $ this -> config [ 'clear-site-data' ] [ 'all' ] ) { $ csd = '"*"' ; } else { $ flags = array_keys ( array_filter ( array_intersect_key ( $ this -> config [ 'clear-site-data' ] ...
Generate Clear - Site - Data header .
53,707
protected function miscellaneous ( ) : array { return array_filter ( [ 'X-Content-Type-Options' => $ this -> config [ 'x-content-type-options' ] , 'X-Download-Options' => $ this -> config [ 'x-download-options' ] , 'X-Frame-Options' => $ this -> config [ 'x-frame-options' ] , 'X-Permitted-Cross-Domain-Policies' => $ th...
Get miscellaneous headers .
53,708
protected function addGeneratedNonce ( array $ config ) : array { if ( ( $ config [ 'csp' ] [ 'script-src' ] [ 'add-generated-nonce' ] ?? false ) === true ) { $ config [ 'csp' ] [ 'script-src' ] [ 'nonces' ] [ ] = self :: nonce ( ) ; } if ( ( $ config [ 'csp' ] [ 'style-src' ] [ 'add-generated-nonce' ] ?? false ) === t...
Add generated nonce value to script - src and style - src .
53,709
public static function getHPKPHeader ( array $ config ) : array { $ headers = [ ] ; foreach ( $ config [ 'hashes' ] as $ hash ) { $ headers [ ] = sprintf ( 'pin-sha256="%s"' , $ hash ) ; } $ headers [ ] = sprintf ( 'max-age=%d' , $ config [ 'max-age' ] ) ; if ( $ config [ 'include-sub-domains' ] ) { $ headers [ ] = 'in...
Generate HPKP header .
53,710
public static function getFeaturePolicyHeader ( array $ config ) : array { $ directives = [ 'accelerometer' , 'ambient-light-sensor' , 'autoplay' , 'camera' , 'encrypted-media' , 'fullscreen' , 'geolocation' , 'gyroscope' , 'magnetometer' , 'microphone' , 'midi' , 'payment' , 'picture-in-picture' , 'speaker' , 'sync-xh...
Generate Feature Policy header .
53,711
public static function getCSPHeader ( array $ config ) : array { $ directives = [ 'default-src' , 'base-uri' , 'connect-src' , 'font-src' , 'form-action' , 'frame-ancestors' , 'frame-src' , 'img-src' , 'manifest-src' , 'media-src' , 'object-src' , 'plugin-types' , 'require-sri-for' , 'sandbox' , 'script-src' , 'style-s...
Generate CSP header .
53,712
protected static function compileDirective ( string $ directive , $ policies ) : string { switch ( $ directive ) { case 'plugin-types' : return empty ( $ policies ) ? '' : sprintf ( '%s %s' , $ directive , implode ( ' ' , $ policies ) ) ; case 'require-sri-for' : case 'sandbox' : return empty ( $ policies ) ? '' : spri...
Compile a subgroup into a policy string .
53,713
protected static function isBase64Valid ( string $ encode ) : bool { $ decode = base64_decode ( $ encode , true ) ; if ( false === $ decode ) { return false ; } return base64_encode ( $ decode ) === $ encode ; }
Check base64 encoded string is valid or not .
53,714
public function initialize ( array & $ docs ) { $ doc_keys = range ( 0 , count ( $ docs ) - 1 ) ; $ topic_keys = range ( 0 , $ this -> ntopics - 1 ) ; $ this -> words_in_doc = array_fill_keys ( $ doc_keys , 0 ) ; $ this -> words_in_topic = array_fill_keys ( $ topic_keys , 0 ) ; $ this -> count_docs_topics = array_fill_...
Count initially the co - occurences of documents topics and topics words and cache them to run Gibbs sampling faster
53,715
public function gibbsSample ( array & $ docs ) { foreach ( $ docs as $ i => $ doc ) { foreach ( $ doc as $ idx => $ w ) { $ topic = $ this -> word_doc_assigned_topic [ $ i ] [ $ idx ] ; $ this -> count_docs_topics [ $ i ] [ $ topic ] -- ; $ this -> count_topics_words [ $ topic ] [ $ w ] -- ; $ this -> words_in_topic [ ...
Generate one gibbs sample . The docs must have been passed to initialize previous to calling this function .
53,716
public function getLogLikelihood ( ) { $ voccnt = $ this -> voccnt ; $ lik = 0 ; $ b = $ this -> b ; $ a = $ this -> a ; foreach ( $ this -> count_topics_words as $ topic => $ words ) { $ lik += $ this -> log_multi_beta ( $ words , $ b ) ; $ lik -= $ this -> log_multi_beta ( $ b , 0 , $ voccnt ) ; } foreach ( $ this ->...
Log likelihood of the model having generated the data as implemented by M . Blondel
53,717
protected function conditionalDistribution ( $ i , $ w ) { $ p = array_fill_keys ( range ( 0 , $ this -> ntopics - 1 ) , 0 ) ; for ( $ topic = 0 ; $ topic < $ this -> ntopics ; $ topic ++ ) { if ( isset ( $ this -> count_topics_words [ $ topic ] [ $ w ] ) ) $ numerator = $ this -> count_topics_words [ $ topic ] [ $ w ]...
This is the implementation of the equation number 5 in the paper by Griffiths and Steyvers .
53,718
protected function drawIndex ( array $ d ) { $ x = $ this -> mt -> generate ( ) ; $ p = 0.0 ; foreach ( $ d as $ i => $ v ) { $ p += $ v ; if ( $ p > $ x ) return $ i ; } }
Draw once from a multinomial distribution and return the index of that is drawn .
53,719
public function generate ( ) { if ( feof ( $ this -> h ) ) rewind ( $ this -> h ) ; return ( float ) fgets ( $ this -> h ) ; }
Read a float from a file and return it . It doesn t do anything to make sure that the float returned will be in the appropriate range .
53,720
public function transform ( $ w ) { $ class = $ this -> cls -> classify ( $ this -> classes , new RawDocument ( $ w ) ) ; foreach ( $ this -> transforms [ $ class ] as $ t ) { $ w = $ t -> transform ( $ w ) ; } return $ w ; }
Classify the passed in variable w and then apply each transformation to the output of the previous one .
53,721
public function register ( $ class , $ transforms ) { if ( ! is_array ( $ transforms ) ) { $ transforms = array ( $ transforms ) ; } foreach ( $ transforms as $ t ) { if ( ! ( $ t instanceof TransformationInterface ) ) { throw new \ InvalidArgumentException ( "Only instances of TransformationInterface can be registered...
Register a set of transformations for a given class .
53,722
public function tokenize ( $ str ) { $ tokens = $ this -> tok -> tokenize ( $ str ) ; $ docs = array ( ) ; foreach ( $ tokens as $ offset => $ tok ) { $ docs [ ] = new WordDocument ( $ tokens , $ offset , 5 ) ; } $ tags = array ( ) ; foreach ( $ docs as $ doc ) { $ tags [ ] = $ this -> classifier -> classify ( self :: ...
Tokenize the string .
53,723
public function getCentroid ( array & $ docs , array $ choose = array ( ) ) { $ bitl = strlen ( $ docs [ 0 ] ) ; $ buckets = array_fill_keys ( range ( 0 , $ bitl - 1 ) , 0 ) ; if ( empty ( $ choose ) ) $ choose = range ( 0 , count ( $ docs ) - 1 ) ; foreach ( $ choose as $ idx ) { $ s = $ docs [ $ idx ] ; foreach ( $ b...
Return a number in binary encoding in a string such that the sum of its hamming distances of each document is minimized .
53,724
public function dist ( & $ A , & $ B ) { $ l1 = strlen ( $ A ) ; $ l2 = strlen ( $ B ) ; $ l = min ( $ l1 , $ l2 ) ; $ d = 0 ; for ( $ i = 0 ; $ i < $ l ; $ i ++ ) { $ d += ( int ) ( $ A [ $ i ] != $ B [ $ i ] ) ; } return $ d + ( int ) abs ( $ l1 - $ l2 ) ; }
Count the number of positions that A and B differ .
53,725
public function applyTransformation ( TransformationInterface $ transform ) { $ this -> tokens = array_values ( array_filter ( array_map ( array ( $ transform , 'transform' ) , $ this -> tokens ) , function ( $ token ) { return $ token !== null ; } ) ) ; }
Apply the transform to each token . Filter out the null tokens .
53,726
public function similarity ( & $ A , & $ B ) { $ alpha = $ this -> alpha ; $ beta = $ this -> beta ; $ a = array_fill_keys ( $ A , 1 ) ; $ b = array_fill_keys ( $ B , 1 ) ; $ min = min ( count ( array_diff_key ( $ a , $ b ) ) , count ( array_diff_key ( $ b , $ a ) ) ) ; $ max = max ( count ( array_diff_key ( $ a , $ b ...
Compute the similarity using the alpha and beta values given in the constructor .
53,727
public function cluster ( TrainingSet $ documents , FeatureFactoryInterface $ ff ) { $ docs = $ this -> getDocumentArray ( $ documents , $ ff ) ; $ this -> strategy -> initializeStrategy ( $ this -> dist , $ docs ) ; unset ( $ docs ) ; $ clusters = range ( 0 , count ( $ documents ) - 1 ) ; $ c = count ( $ clusters ) ; ...
Iteratively merge documents together to create an hierarchy of clusters . While hierarchical clustering only returns one element it still wraps it in an array to be consistent with the rest of the clustering methods .
53,728
public function classify ( array $ classes , DocumentInterface $ d ) { $ maxclass = current ( $ classes ) ; $ maxvote = $ this -> getVote ( $ maxclass , $ d ) ; while ( $ class = next ( $ classes ) ) { $ v = $ this -> getVote ( $ class , $ d ) ; if ( $ v > $ maxvote ) { $ maxclass = $ class ; $ maxvote = $ v ; } } retu...
Compute the vote for every class . Return the class that receive the maximum vote .
53,729
public function offsetGet ( $ token ) { if ( isset ( $ this -> idf [ $ token ] ) ) { return $ this -> idf [ $ token ] ; } else { return $ this -> logD ; } }
Implements the array access interface . Return the computed idf or the logarithm of the count of the documents for a token we have not seen before .
53,730
public function cluster ( TrainingSet $ documents , FeatureFactoryInterface $ ff ) { $ docs = $ this -> getDocumentArray ( $ documents , $ ff ) ; $ centroids = array ( ) ; foreach ( array_rand ( $ docs , $ this -> n ) as $ key ) { $ centroids [ ] = $ docs [ $ key ] ; } $ dist = array ( $ this -> dist , 'dist' ) ; $ cf ...
Apply the feature factory to the documents and then cluster the resulting array using the provided distance metric and centroid factory .
53,731
public function getCentroid ( array & $ docs , array $ choose = array ( ) ) { $ v = array ( ) ; if ( empty ( $ choose ) ) $ choose = range ( 0 , count ( $ docs ) - 1 ) ; $ cnt = count ( $ choose ) ; foreach ( $ choose as $ idx ) { $ doc = $ this -> getVector ( $ docs [ $ idx ] ) ; foreach ( $ doc as $ k => $ w ) { if (...
Compute the mean value for each dimension .
53,732
public function optimize ( array & $ feature_array ) { $ desrciptorspec = array ( 0 => array ( 'pipe' , 'r' ) , 1 => array ( 'pipe' , 'w' ) , 2 => STDERR ) ; $ process = proc_open ( $ this -> optimizer , $ desrciptorspec , $ pipes ) ; if ( ! is_resource ( $ process ) ) { return array ( ) ; } fwrite ( $ pipes [ 0 ] , js...
Open a pipe to the optimizer send him the data encoded in json and then read the stdout to get the results encoded in json
53,733
public function initializeStrategy ( DistanceInterface $ d , array & $ docs ) { $ this -> L = count ( $ docs ) ; $ this -> removed = array_fill_keys ( range ( 0 , $ this -> L - 1 ) , false ) ; $ elements = ( int ) ( $ this -> L * ( $ this -> L - 1 ) ) / 2 ; $ this -> dm = new \ SplFixedArray ( $ elements ) ; $ this -> ...
Initialize the distance matrix and any other data structure needed to calculate the merges later .
53,734
protected function unravelIndex ( $ index ) { $ a = 0 ; $ b = $ this -> L - 1 ; $ y = 0 ; while ( $ b - $ a > 1 ) { $ y = ( int ) ( ( $ a + $ b ) / 2 ) ; $ i = $ y * ( $ y - 1 ) / 2 ; if ( $ i > $ index ) { $ b = $ y ; } else { $ a = $ y ; } } $ x = $ index - $ i ; if ( $ y <= $ x ) { $ y ++ ; $ x = $ index - $ y * ( $...
Use binary search to unravel the index to its coordinates x y return them in the order y x . This operation is to be done only once per merge so it doesn t add much overhead .
53,735
public function getFeatureArray ( $ class , DocumentInterface $ d ) { $ features = array_filter ( array_map ( function ( $ feature ) use ( $ class , $ d ) { return call_user_func ( $ feature , $ class , $ d ) ; } , $ this -> functions ) ) ; $ set = array ( ) ; foreach ( $ features as $ f ) { if ( is_array ( $ f ) ) { f...
Compute the features that fire for a given class document pair .
53,736
public function setAsKey ( $ what ) { switch ( $ what ) { case self :: CLASS_AS_KEY : case self :: OFFSET_AS_KEY : $ this -> keytype = $ what ; break ; default : $ this -> keytype = self :: CLASS_AS_KEY ; break ; } }
Decide what should be returned as key when iterated upon
53,737
public function applyTransformations ( array $ transforms ) { foreach ( $ this -> documents as $ doc ) { foreach ( $ transforms as $ transform ) { $ doc -> applyTransformation ( $ transform ) ; } } }
Apply an array of transformations to all documents in this container .
53,738
public function train ( FeatureFactoryInterface $ ff , TrainingSet $ tset , MaxentOptimizerInterface $ opt ) { $ classSet = $ tset -> getClassSet ( ) ; $ features = $ this -> calculateFeatureArray ( $ classSet , $ tset , $ ff ) ; $ this -> l = $ opt -> optimize ( $ features ) ; }
Calculate all the features for every possible class . Pass the information to the optimizer to find the weights that satisfy the constraints and maximize the entropy
53,739
protected function calculateFeatureArray ( array $ classes , TrainingSet $ tset , FeatureFactoryInterface $ ff ) { $ features = array ( ) ; $ tset -> setAsKey ( TrainingSet :: OFFSET_AS_KEY ) ; foreach ( $ tset as $ offset => $ doc ) { $ features [ $ offset ] = array ( ) ; foreach ( $ classes as $ class ) { $ features ...
Calculate all the features for each possible class of each document . This is done so that we can optimize without the need of the FeatureFactory .
53,740
protected function prepareFprime ( array & $ feature_array , array & $ l ) { $ this -> denominators = array ( ) ; foreach ( $ feature_array as $ offset => $ doc ) { $ numerator = array_fill_keys ( array_keys ( $ doc ) , 0.0 ) ; $ denominator = 0.0 ; foreach ( $ doc as $ cl => $ f ) { if ( ! is_array ( $ f ) ) continue ...
Compute the denominators which is the predicted expectation of each feature given a set of weights L and a set of features for each document for each class .
53,741
public function dist ( & $ A , & $ B ) { if ( is_int ( key ( $ A ) ) ) $ v1 = array_count_values ( $ A ) ; else $ v1 = & $ A ; if ( is_int ( key ( $ B ) ) ) $ v2 = array_count_values ( $ B ) ; else $ v2 = & $ B ; $ r = array ( ) ; foreach ( $ v1 as $ k => $ v ) { $ r [ $ k ] = $ v ; } foreach ( $ v2 as $ k => $ v ) { i...
see class description
53,742
public function getCondProb ( $ term , $ class ) { if ( ! isset ( $ this -> condprob [ $ term ] [ $ class ] ) ) { return isset ( $ this -> unknown [ $ class ] ) ? $ this -> unknown [ $ class ] : 0 ; } else { return $ this -> condprob [ $ term ] [ $ class ] ; } }
Return the conditional probability of a term for a given class .
53,743
public function train_with_context ( array & $ train_ctx , FeatureFactoryInterface $ ff , TrainingSet $ tset , $ a_smoothing = 1 ) { $ this -> countTrainingSet ( $ ff , $ tset , $ train_ctx [ 'termcount_per_class' ] , $ train_ctx [ 'termcount' ] , $ train_ctx [ 'ndocs_per_class' ] , $ train_ctx [ 'voc' ] , $ train_ctx ...
Train on the given set and fill the model s variables . Use the training context provided to update the counts as if the training set was appended to the previous one that provided the context .
53,744
public function train ( FeatureFactoryInterface $ ff , TrainingSet $ tset , $ a_smoothing = 1 ) { $ class_set = $ tset -> getClassSet ( ) ; $ ctx = array ( 'termcount_per_class' => array_fill_keys ( $ class_set , 0 ) , 'termcount' => array_fill_keys ( $ class_set , array ( ) ) , 'ndocs_per_class' => array_fill_keys ( $...
Train on the given set and fill the models variables
53,745
protected function countTrainingSet ( FeatureFactoryInterface $ ff , TrainingSet $ tset , array & $ termcount_per_class , array & $ termcount , array & $ ndocs_per_class , array & $ voc , & $ ndocs ) { foreach ( $ tset as $ tdoc ) { $ ndocs ++ ; $ c = $ tdoc -> getClass ( ) ; $ ndocs_per_class [ $ c ] ++ ; $ features =...
Count all the features for each document . All parameters are passed by reference and they are filled in this function . Useful for not making copies of big arrays .
53,746
protected function computeProbabilitiesFromCounts ( array $ class_set , array & $ termcount_per_class , array & $ termcount , array & $ ndocs_per_class , $ ndocs , $ voccount , $ a_smoothing = 1 ) { $ denom_smoothing = $ a_smoothing * $ voccount ; foreach ( $ class_set as $ class ) { $ this -> priors [ $ class ] = $ nd...
Compute the probabilities given the counts of the features in the training set .
53,747
public function dist ( & $ A , & $ B ) { $ h1 = $ this -> simhash ( $ A ) ; $ h2 = $ this -> simhash ( $ B ) ; $ d = 0 ; for ( $ i = 0 ; $ i < $ this -> length ; $ i ++ ) { if ( $ h1 [ $ i ] != $ h2 [ $ i ] ) $ d ++ ; } return $ d ; }
Computes the hamming distance of the simhashes of two sets .
53,748
public function tokenize ( $ str ) { $ str = array ( $ str ) ; foreach ( $ this -> patterns as $ p ) { if ( ! is_array ( $ p ) ) $ p = array ( $ p ) ; if ( count ( $ p ) == 1 ) { $ this -> split ( $ str , $ p [ 0 ] ) ; } elseif ( is_int ( $ p [ 1 ] ) ) { $ this -> match ( $ str , $ p [ 0 ] , $ p [ 1 ] ) ; } else { $ th...
Iteratively run for each pattern . The tokens resulting from one pattern are fed to the next as strings .
53,749
protected function split ( array & $ str , $ pattern ) { $ tokens = array ( ) ; foreach ( $ str as $ s ) { $ tokens = array_merge ( $ tokens , preg_split ( $ pattern , $ s , null , PREG_SPLIT_NO_EMPTY ) ) ; } $ str = $ tokens ; }
Execute the SPLIT mode
53,750
protected function match ( array & $ str , $ pattern , $ keep ) { $ tokens = array ( ) ; foreach ( $ str as $ s ) { preg_match_all ( $ pattern , $ s , $ m ) ; $ tokens = array_merge ( $ tokens , $ m [ $ keep ] ) ; } $ str = $ tokens ; }
Execute the KEEP_MATCHES mode
53,751
protected function replace ( array & $ str , $ pattern , $ replacement ) { foreach ( $ str as & $ s ) { $ s = preg_replace ( $ pattern , $ replacement , $ s ) ; } }
Execute the TRANSFORM mode .
53,752
public function applyTransformation ( TransformationInterface $ transform ) { $ null_filter = function ( $ token ) { return $ token !== null ; } ; $ this -> word = $ transform -> transform ( $ this -> word ) ; $ this -> before = array_values ( array_filter ( array_map ( array ( $ transform , "transform" ) , $ this -> b...
Apply the transformation to the token and the surrounding context . Filter out the null tokens from the context . If the word is transformed to null it is for the feature factory to decide what to do .
53,753
protected function getDocumentArray ( TrainingSet $ documents , FeatureFactoryInterface $ ff ) { $ docs = array ( ) ; foreach ( $ documents as $ d ) { $ docs [ ] = $ ff -> getFeatureArray ( '' , $ d ) ; } return $ docs ; }
Helper function to transform a TrainingSet to an array of feature vectors
53,754
protected function resolvePathAndQuery ( string $ path , string $ query ) : array { $ components = [ 'path' => $ path , 'query' => $ query ] ; if ( '' === $ components [ 'path' ] ) { $ components [ 'path' ] = $ this -> base_uri -> getPath ( ) ; if ( '' === $ components [ 'query' ] ) { $ components [ 'query' ] = $ this ...
Resolve the URI for a Authority - less target URI
53,755
protected function mergePath ( string $ path ) : string { $ base_path = $ this -> base_uri -> getPath ( ) ; if ( '' !== $ this -> base_uri -> getAuthority ( ) && '' === $ base_path ) { return ( string ) $ this -> filterPath ( $ path ) -> withLeadingSlash ( ) ; } if ( '' !== $ base_path ) { $ segments = explode ( '/' , ...
Merging Relative URI path with Base URI path
53,756
protected function formatPath ( string $ path ) : string { $ path = $ this -> filterPath ( $ path ) -> withoutDotSegments ( ) ; if ( '' !== $ this -> base_uri -> getAuthority ( ) && '' !== $ path -> __toString ( ) ) { $ path = $ path -> withLeadingSlash ( ) ; } return ( string ) $ path ; }
Format the resolved path
53,757
protected function hostToAscii ( $ uri ) { static $ modifier ; if ( null === $ modifier ) { $ modifier = new HostToAscii ( ) ; } return $ modifier -> process ( $ uri ) ; }
Convert the Uri host component to its ascii version
53,758
protected function isRelativizable ( $ payload ) : bool { $ payload = $ this -> hostToAscii ( $ payload ) ; return $ this -> base_uri -> getScheme ( ) === $ payload -> getScheme ( ) && $ this -> base_uri -> getAuthority ( ) === $ payload -> getAuthority ( ) && ! is_relative_path ( $ payload ) ; }
Tell whether the submitted URI object can be relativize
53,759
protected function relativizePath ( string $ path ) : string { $ base_segments = $ this -> getSegments ( $ this -> base_uri -> getPath ( ) ) ; $ target_segments = $ this -> getSegments ( $ path ) ; $ target_basename = array_pop ( $ target_segments ) ; array_pop ( $ base_segments ) ; foreach ( $ base_segments as $ offse...
Relative the URI for a authority - less target URI
53,760
protected function getSegments ( string $ path ) : array { if ( '' !== $ path && '/' === $ path [ 0 ] ) { $ path = substr ( $ path , 1 ) ; } return explode ( '/' , $ path ) ; }
returns the path segments
53,761
protected function formatPath ( string $ path ) : string { if ( '' === $ path ) { $ base_path = $ this -> base_uri -> getPath ( ) ; return in_array ( $ base_path , [ '' , '/' ] , true ) ? $ base_path : './' ; } if ( false === ( $ colon_pos = strpos ( $ path , ':' ) ) ) { return $ path ; } $ slash_pos = strpos ( $ path ...
Formatting the path to keep a valid URI
53,762
protected function formatPathWithEmptyBaseQuery ( string $ path ) : string { $ target_segments = $ this -> getSegments ( $ path ) ; $ basename = end ( $ target_segments ) ; return '' === $ basename ? './' : $ basename ; }
Formatting the path to keep a resolvable URI
53,763
public function process ( $ uri ) { $ interface = $ this -> getUriInterface ( $ uri ) ; $ new_uri = $ this -> execute ( $ uri ) ; if ( $ new_uri instanceof $ interface ) { return $ new_uri ; } throw Exception :: fromInvalidInterface ( $ interface , $ new_uri ) ; }
Process and return an Uri
53,764
protected function getUriInterface ( $ uri ) { if ( $ uri instanceof UriInterface ) { return UriInterface :: class ; } if ( $ uri instanceof Uri ) { return Uri :: class ; } throw Exception :: fromInvalidUri ( $ uri ) ; }
Returns the URI object interface
53,765
protected function filterString ( string $ str ) : string { $ invalid_chars = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F" ; if ( strlen ( $ str ) !== strcspn ( $ str , $ invalid_chars ) ) { throw new Exception ( sprintf ( 'the su...
validate a string
53,766
protected function filterHost ( string $ label , Rules $ resolver = null ) : Host { return new Host ( $ this -> filterString ( $ label ) , $ resolver ) ; }
Filter and validate the host string
53,767
protected function filterExtension ( string $ extension ) : string { $ extension = $ this -> filterString ( $ extension ) ; if ( 0 === strpos ( $ extension , '.' ) || false !== strpos ( $ extension , '/' ) ) { throw new Exception ( 'extension must be string sequence without a leading `.` and the path separator `/` char...
filter and validate the extension to use
53,768
public function setEncoding ( int $ enc_type ) { static $ enc_type_list ; if ( null === $ enc_type_list ) { $ enc_type_list = [ self :: RFC1738_ENCODING => 1 , self :: RFC3986_ENCODING => 1 , self :: RFC3987_ENCODING => 1 , self :: NO_ENCODING => 1 , ] ; } if ( ! isset ( $ enc_type_list [ $ enc_type ] ) ) { throw new I...
Formatting encoding type
53,769
public function setQuerySeparator ( string $ separator ) { $ separator = filter_var ( $ separator , FILTER_SANITIZE_STRING , FILTER_FLAG_STRIP_LOW ) ; $ this -> query_separator = trim ( $ separator ) ; }
Query separator setter
53,770
protected function formatUri ( $ uri ) : string { $ scheme = $ uri -> getScheme ( ) ; if ( '' != $ scheme ) { $ scheme = $ scheme . ':' ; } $ authority = null ; $ host = $ uri -> getHost ( ) ; if ( '' != $ host ) { $ user_info = $ uri -> getUserInfo ( ) ; if ( '' != $ user_info ) { $ authority .= ( new UserInfo ( ) ) -...
Format an Uri according to the Formatter properties
53,771
public function add ( $ enumerator ) : void { $ this -> { $ this -> fnDoSetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; }
Adds an enumerator object or value
53,772
public function addIterable ( iterable $ enumerators ) : void { $ bitset = $ this -> bitset ; try { foreach ( $ enumerators as $ enumerator ) { $ this -> { $ this -> fnDoSetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; } } catch ( \ Throwable $ e ) { $ this -> bitset = $ bitset ; throw...
Adds all enumerator objects or values of the given iterable
53,773
public function remove ( $ enumerator ) : void { $ this -> { $ this -> fnDoUnsetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; }
Removes the given enumerator object or value
53,774
public function removeIterable ( iterable $ enumerators ) : void { $ bitset = $ this -> bitset ; try { foreach ( $ enumerators as $ enumerator ) { $ this -> { $ this -> fnDoUnsetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; } } catch ( \ Throwable $ e ) { $ this -> bitset = $ bitset ; ...
Removes all enumerator objects or values of the given iterable
53,775
public function setBit ( int $ ordinal , bool $ bit ) : void { if ( $ ordinal < 0 || $ ordinal > $ this -> enumerationCount ) { throw new InvalidArgumentException ( "Ordinal number must be between 0 and {$this->enumerationCount}" ) ; } if ( $ bit ) { $ this -> { $ this -> fnDoSetBit } ( $ ordinal ) ; } else { $ this ->...
Set a bit at the given ordinal number
53,776
private function doSetBitBin ( $ ordinal ) : void { $ byte = ( int ) ( $ ordinal / 8 ) ; $ this -> bitset [ $ byte ] = $ this -> bitset [ $ byte ] | \ chr ( 1 << ( $ ordinal % 8 ) ) ; }
Set a bit at the given ordinal number .
53,777
private function doUnsetBitBin ( $ ordinal ) : void { $ byte = ( int ) ( $ ordinal / 8 ) ; $ this -> bitset [ $ byte ] = $ this -> bitset [ $ byte ] & \ chr ( ~ ( 1 << ( $ ordinal % 8 ) ) ) ; }
Unset a bit at the given ordinal number .
53,778
public function with ( $ enumerator ) : self { $ clone = clone $ this ; $ clone -> { $ this -> fnDoSetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; return $ clone ; }
Creates a new set with the given enumerator object or value added
53,779
public function withIterable ( iterable $ enumerators ) : self { $ clone = clone $ this ; foreach ( $ enumerators as $ enumerator ) { $ clone -> { $ this -> fnDoSetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; } return $ clone ; }
Creates a new set with the given enumeration objects or values added
53,780
public function without ( $ enumerator ) : self { $ clone = clone $ this ; $ clone -> { $ this -> fnDoUnsetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; return $ clone ; }
Create a new set with the given enumerator object or value removed
53,781
public function withoutIterable ( iterable $ enumerators ) : self { $ clone = clone $ this ; foreach ( $ enumerators as $ enumerator ) { $ clone -> { $ this -> fnDoUnsetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; } return $ clone ; }
Creates a new set with the given enumeration objects or values removed
53,782
public function withBit ( int $ ordinal , bool $ bit ) : self { $ clone = clone $ this ; $ clone -> setBit ( $ ordinal , $ bit ) ; return $ clone ; }
Create a new set with the bit at the given ordinal number set
53,783
public function has ( $ enumerator ) : bool { return $ this -> { $ this -> fnDoGetBit } ( ( $ this -> enumeration ) :: get ( $ enumerator ) -> getOrdinal ( ) ) ; }
Test if the given enumerator exists
53,784
public function isEqual ( EnumSet $ other ) : bool { return $ this -> enumeration === $ other -> enumeration && $ this -> bitset === $ other -> bitset ; }
Check if this EnumSet is the same as other
53,785
public function isSubset ( EnumSet $ other ) : bool { return $ this -> enumeration === $ other -> enumeration && ( $ this -> bitset & $ other -> bitset ) === $ this -> bitset ; }
Check if this EnumSet is a subset of other
53,786
public function isSuperset ( EnumSet $ other ) : bool { return $ this -> enumeration === $ other -> enumeration && ( $ this -> bitset | $ other -> bitset ) === $ this -> bitset ; }
Check if this EnumSet is a superset of other
53,787
public function getValues ( ) : array { $ enumeration = $ this -> enumeration ; $ values = [ ] ; foreach ( $ this -> getOrdinals ( ) as $ ord ) { $ values [ ] = $ enumeration :: byOrdinal ( $ ord ) -> getValue ( ) ; } return $ values ; }
Get values of the defined enumerators as array
53,788
public function getNames ( ) : array { $ enumeration = $ this -> enumeration ; $ names = [ ] ; foreach ( $ this -> getOrdinals ( ) as $ ord ) { $ names [ ] = $ enumeration :: byOrdinal ( $ ord ) -> getName ( ) ; } return $ names ; }
Get names of the defined enumerators as array
53,789
public function getEnumerators ( ) : array { $ enumeration = $ this -> enumeration ; $ enumerators = [ ] ; foreach ( $ this -> getOrdinals ( ) as $ ord ) { $ enumerators [ ] = $ enumeration :: byOrdinal ( $ ord ) ; } return $ enumerators ; }
Get the defined enumerators as array
53,790
private function doGetBinaryBitsetLeInt ( ) { $ bin = \ pack ( \ PHP_INT_SIZE === 8 ? 'P' : 'V' , $ this -> bitset ) ; return \ substr ( $ bin , 0 , ( int ) \ ceil ( $ this -> enumerationCount / 8 ) ) ; }
Get binary bitset in little - endian order .
53,791
public function getBit ( int $ ordinal ) : bool { if ( $ ordinal < 0 || $ ordinal > $ this -> enumerationCount ) { throw new InvalidArgumentException ( "Ordinal number must be between 0 and {$this->enumerationCount}" ) ; } return $ this -> { $ this -> fnDoGetBit } ( $ ordinal ) ; }
Get a bit at the given ordinal number
53,792
final public function getOrdinal ( ) { if ( $ this -> ordinal === null ) { $ ordinal = 0 ; $ value = $ this -> value ; foreach ( self :: detectConstants ( static :: class ) as $ constValue ) { if ( $ value === $ constValue ) { break ; } ++ $ ordinal ; } $ this -> ordinal = $ ordinal ; } return $ this -> ordinal ; }
Get the ordinal number of the enumerator
53,793
final public function is ( $ enumerator ) { return $ this === $ enumerator || $ this -> value === $ enumerator || ( $ enumerator instanceof static && \ get_class ( $ enumerator ) === static :: class && $ enumerator -> value === $ this -> value ) ; }
Compare this enumerator against another and check if it s the same .
53,794
final public static function byValue ( $ value ) { if ( ! isset ( self :: $ constants [ static :: class ] ) ) { self :: detectConstants ( static :: class ) ; } $ name = \ array_search ( $ value , self :: $ constants [ static :: class ] , true ) ; if ( $ name === false ) { throw new InvalidArgumentException ( sprintf ( ...
Get an enumerator instance by the given value
53,795
final public static function byName ( string $ name ) { if ( isset ( self :: $ instances [ static :: class ] [ $ name ] ) ) { return self :: $ instances [ static :: class ] [ $ name ] ; } $ const = static :: class . "::{$name}" ; if ( ! \ defined ( $ const ) ) { throw new InvalidArgumentException ( "{$const} not define...
Get an enumerator instance by the given name
53,796
final public static function byOrdinal ( int $ ordinal ) { if ( ! isset ( self :: $ names [ static :: class ] ) ) { self :: detectConstants ( static :: class ) ; } if ( ! isset ( self :: $ names [ static :: class ] [ $ ordinal ] ) ) { throw new InvalidArgumentException ( \ sprintf ( 'Invalid ordinal number %s, must bet...
Get an enumeration instance by the given ordinal number
53,797
private static function detectConstants ( $ class ) { if ( ! isset ( self :: $ constants [ $ class ] ) ) { $ reflection = new ReflectionClass ( $ class ) ; $ constants = [ ] ; do { $ scopeConstants = [ ] ; foreach ( $ reflection -> getReflectionConstants ( ) as $ reflConstant ) { if ( $ reflConstant -> isPublic ( ) ) {...
Detect all public available constants of given enumeration class
53,798
private static function noAmbiguousValues ( $ constants ) { foreach ( $ constants as $ value ) { $ names = \ array_keys ( $ constants , $ value , true ) ; if ( \ count ( $ names ) > 1 ) { return false ; } } return true ; }
Test that the given constants does not contain ambiguous values
53,799
public function search ( $ value , bool $ strict = false ) { $ ord = \ array_search ( $ value , $ this -> map , $ strict ) ; if ( $ ord !== false ) { return ( $ this -> enumeration ) :: byOrdinal ( $ ord ) ; } return null ; }
Search for the given data value .