idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
28,600 | public function saveGridFilters ( ) { $ this -> defineModelShortClassName ( ) ; if ( ! isset ( Yii :: $ app -> session [ $ this -> sessionVarName ] ) ) { Yii :: $ app -> session [ $ this -> sessionVarName ] = $ this -> owner -> attributes ; } $ params = Yii :: $ app -> request -> queryParams ; if ( isset ( $ params [ $ this -> modelShortClassName ] ) ) { $ this -> filtersChanged = serialize ( Yii :: $ app -> session [ $ this -> sessionVarName ] ) !== serialize ( $ params [ $ this -> modelShortClassName ] ) ? true : false ; Yii :: $ app -> session [ $ this -> sessionVarName ] = $ params [ $ this -> modelShortClassName ] ; } } | Saves the grid s current filters . |
28,601 | public function setOutputStreams ( $ stdout = STDOUT , $ stderr = STDERR ) { $ this -> stdout = $ stdout ; $ this -> stderr = $ stderr ; } | Set output streams |
28,602 | protected function out ( $ message ) { if ( isset ( $ this -> options [ 'v' ] ) || isset ( $ this -> options [ 'verbose' ] ) ) { fwrite ( $ this -> stderr , $ message ) ; } } | Echo a message |
28,603 | protected function parseConnectionInformation ( ) { if ( ( $ info = @ parse_url ( $ this -> dsn ) ) === false ) { fwrite ( $ this -> stderr , "Could not parse provided DSN: {$this->dsn}\n" ) ; return false ; } foreach ( $ info as $ key => $ value ) { if ( array_key_exists ( $ key , $ this -> connectionInfo ) ) { $ this -> connectionInfo [ $ key ] = $ value ; } } if ( isset ( $ this -> options [ 'username' ] ) ) { $ this -> connectionInfo [ 'user' ] = $ this -> options [ 'username' ] ; } if ( isset ( $ this -> options [ 'password' ] ) ) { $ this -> connectionInfo [ 'pass' ] = $ this -> options [ 'password' ] ; } return true ; } | Parse the provided connection information |
28,604 | public function dump ( ) { if ( $ this -> printVersion ( ) ) { return 0 ; } if ( ! $ this -> parseConnectionInformation ( ) ) { return 1 ; } $ db = new phpillowCustomConnection ( $ this -> connectionInfo [ 'host' ] , $ this -> connectionInfo [ 'port' ] , $ this -> connectionInfo [ 'user' ] , $ this -> connectionInfo [ 'pass' ] ) ; $ writer = new phpillowToolMultipartWriter ( $ this -> stdout ) ; $ offset = null ; $ limit = 1000 ; do { $ docs = $ db -> get ( $ this -> connectionInfo [ 'path' ] . '/_all_docs?limit=' . $ limit . ( $ offset !== null ? '&startkey="' . $ offset . '"' : '' ) ) ; foreach ( $ docs -> rows as $ nr => $ doc ) { if ( ( $ nr === 0 ) && ( $ offset !== null ) ) { continue ; } $ offset = $ doc [ 'id' ] ; $ this -> out ( "Dumping document " . $ doc [ 'id' ] . "\n" ) ; $ doc = $ db -> get ( $ this -> connectionInfo [ 'path' ] . '/' . urlencode ( $ doc [ 'id' ] ) ) ; if ( isset ( $ doc -> deleted ) && ( $ doc -> deleted === true ) ) { continue ; } $ doc = $ doc -> getFullDocument ( ) ; if ( isset ( $ doc [ '_attachments' ] ) ) { foreach ( $ doc [ '_attachments' ] as $ name => $ attachment ) { $ data = $ db -> get ( $ this -> connectionInfo [ 'path' ] . '/' . urlencode ( $ doc [ '_id' ] ) . '/' . $ name , null , true ) ; $ doc [ '_attachments' ] [ $ name ] [ 'data' ] = $ data -> data ; } } $ writer -> writeDocument ( $ doc ) ; } } while ( count ( $ docs -> rows ) > 1 ) ; unset ( $ writer ) ; return 0 ; } | Execute dump command |
28,605 | protected function getDocumentBody ( array $ document ) { if ( strpos ( $ document [ 'Content-Type' ] , 'application/json' ) === 0 ) { $ source = json_decode ( $ document [ 'body' ] , true ) ; unset ( $ source [ '_rev' ] ) ; return json_encode ( $ source ) ; } if ( is_array ( $ document [ 'body' ] ) ) { $ main = array_shift ( $ document [ 'body' ] ) ; $ source = json_decode ( $ main [ 'body' ] , true ) ; unset ( $ source [ '_rev' ] ) ; $ source [ '_attachments' ] = array ( ) ; foreach ( $ document [ 'body' ] as $ attachment ) { $ source [ '_attachments' ] [ $ attachment [ 'Content-ID' ] ] = array ( 'content_type' => $ attachment [ 'Content-Type' ] , 'data' => base64_encode ( $ attachment [ 'body' ] ) , ) ; } return json_encode ( $ source ) ; } throw new phpillowMultipartParserException ( "Invalid document: " . var_export ( $ document , true ) ) ; } | Clean up document definition |
28,606 | public function load ( ) { if ( $ this -> printVersion ( ) ) { return 0 ; } if ( ! $ this -> parseConnectionInformation ( ) ) { return 1 ; } $ stream = isset ( $ this -> options [ 'input' ] ) ? fopen ( $ this -> options [ 'input' ] , 'r' ) : STDIN ; $ multipartParser = new phpillowToolMultipartParser ( $ stream ) ; $ db = new phpillowCustomConnection ( $ this -> connectionInfo [ 'host' ] , $ this -> connectionInfo [ 'port' ] , $ this -> connectionInfo [ 'user' ] , $ this -> connectionInfo [ 'pass' ] ) ; try { $ db -> get ( $ this -> connectionInfo [ 'path' ] ) ; } catch ( phpillowResponseNotFoundErrorException $ e ) { $ db -> put ( $ this -> connectionInfo [ 'path' ] ) ; } while ( ( $ document = $ multipartParser -> getDocument ( ) ) !== false ) { try { $ this -> out ( "Loading document " . $ document [ 'Content-ID' ] . "\n" ) ; $ path = $ this -> connectionInfo [ 'path' ] . '/' . $ document [ 'Content-ID' ] ; $ db -> put ( $ path , $ this -> getDocumentBody ( $ document ) ) ; } catch ( phpillowException $ e ) { fwrite ( $ this -> stderr , $ document [ 'Content-ID' ] . ': ' . $ e -> getMessage ( ) . "\n" ) ; if ( ! isset ( $ this -> options [ 'ignore-errors' ] ) ) { return 1 ; } } } return 0 ; } | Execute load command |
28,607 | public function primeCaches ( ) { if ( $ this -> printVersion ( ) ) { return 0 ; } if ( ! $ this -> parseConnectionInformation ( ) ) { return 1 ; } $ db = new phpillowCustomConnection ( $ this -> connectionInfo [ 'host' ] , $ this -> connectionInfo [ 'port' ] , $ this -> connectionInfo [ 'user' ] , $ this -> connectionInfo [ 'pass' ] ) ; $ designDocs = $ db -> get ( $ this -> connectionInfo [ 'path' ] . '/_all_docs?startkey=%22_design%2F%22&endkey=%22_design0%22' ) ; foreach ( $ designDocs -> rows as $ doc ) { $ views = $ db -> get ( $ this -> connectionInfo [ 'path' ] . '/' . $ doc [ 'id' ] ) ; foreach ( $ views -> views as $ view => $ functions ) { $ this -> out ( "Priming view " . $ doc [ 'id' ] . "/" . $ view . "\n" ) ; $ db -> get ( $ this -> connectionInfo [ 'path' ] . '/' . $ doc [ 'id' ] . '/_view/' . $ view ) ; } } } | Prime caches of all views |
28,608 | public function getProductOrderBook ( RequestProduct $ product ) { return $ this -> get ( [ 'products' , $ product -> getProductId ( ) , 'book' ] , ResponseProductOrderBook :: class , $ product -> toArray ( ) ) ; } | Get a list of open orders for a product . The amount of detail shown can be customized with the level parameter . |
28,609 | public function getTrades ( RequestProduct $ product ) { return $ this -> get ( [ 'products' , $ product -> getProductId ( ) , 'trades' ] , ResponseTrade :: class , $ product -> toArray ( ) ) ; } | List the latest trades for a product . |
28,610 | public function getProductHistoricRates ( RequestProduct $ product ) { return $ this -> get ( [ 'products' , $ product -> getProductId ( ) , 'candles' ] , ResponseProductHistoricRate :: class , $ product -> toArray ( ) ) ; } | Historic rates for a product . Rates are returned in grouped buckets based on requested granularity . |
28,611 | private function load_tables ( ) { if ( is_array ( $ this -> cache_translations ) && is_array ( $ this -> table_originals ) && is_array ( $ this -> table_translations ) ) return ; fseek ( $ this -> STREAM , $ this -> originals ) ; $ this -> table_originals = $ this -> readintarray ( $ this -> total * 2 ) ; fseek ( $ this -> STREAM , $ this -> translations ) ; $ this -> table_translations = $ this -> readintarray ( $ this -> total * 2 ) ; if ( $ this -> enable_cache ) { $ this -> cache_translations = array ( '' => NULL ) ; for ( $ i = 0 ; $ i < $ this -> total ; $ i ++ ) { if ( $ this -> table_originals [ $ i * 2 + 1 ] > 0 ) { fseek ( $ this -> STREAM , $ this -> table_originals [ $ i * 2 + 2 ] ) ; $ original = fread ( $ this -> STREAM , $ this -> table_originals [ $ i * 2 + 1 ] ) ; fseek ( $ this -> STREAM , $ this -> table_translations [ $ i * 2 + 2 ] ) ; $ translation = fread ( $ this -> STREAM , $ this -> table_translations [ $ i * 2 + 1 ] ) ; $ this -> cache_translations [ $ original ] = $ translation ; } } } } | Loads the translation tables from the MO file into the cache If caching is enabled also loads all strings into a cache to speed up translation lookups |
28,612 | private function get_original_string ( $ num ) { $ length = $ this -> table_originals [ $ num * 2 + 1 ] ; $ offset = $ this -> table_originals [ $ num * 2 + 2 ] ; if ( ! $ length ) return '' ; fseek ( $ this -> STREAM , $ offset ) ; $ data = fread ( $ this -> STREAM , $ length ) ; return ( string ) $ data ; } | Returns a string from the originals table |
28,613 | private function get_translation_string ( $ num ) { $ length = $ this -> table_translations [ $ num * 2 + 1 ] ; $ offset = $ this -> table_translations [ $ num * 2 + 2 ] ; if ( ! $ length ) return '' ; fseek ( $ this -> STREAM , $ offset ) ; $ data = fread ( $ this -> STREAM , $ length ) ; return ( string ) $ data ; } | Returns a string from the translations table |
28,614 | private function find_string ( $ string , $ start = - 1 , $ end = - 1 ) { if ( ( $ start == - 1 ) or ( $ end == - 1 ) ) { $ start = 0 ; $ end = $ this -> total ; } if ( abs ( $ start - $ end ) <= 1 ) { $ txt = $ this -> get_original_string ( $ start ) ; if ( $ string == $ txt ) return $ start ; else return - 1 ; } else if ( $ start > $ end ) { return $ this -> find_string ( $ string , $ end , $ start ) ; } else { $ half = ( int ) ( ( $ start + $ end ) / 2 ) ; $ cmp = strcmp ( $ string , $ this -> get_original_string ( $ half ) ) ; if ( $ cmp == 0 ) return $ half ; else if ( $ cmp < 0 ) return $ this -> find_string ( $ string , $ start , $ half ) ; else return $ this -> find_string ( $ string , $ half , $ end ) ; } } | Binary search for string |
28,615 | private function get_plural_forms ( ) { $ this -> load_tables ( ) ; if ( ! is_string ( $ this -> pluralheader ) ) { if ( $ this -> enable_cache ) { $ header = $ this -> cache_translations [ "" ] ; } else { $ header = $ this -> get_translation_string ( 0 ) ; } if ( preg_match ( "/plural\-forms: ([^\n]*)\n/i" , $ header , $ regs ) ) $ expr = $ regs [ 1 ] ; else $ expr = "nplurals=2; plural=n == 1 ? 0 : 1;" ; $ this -> pluralheader = $ expr ; } return $ this -> pluralheader ; } | Get possible plural forms from MO header |
28,616 | private function select_string ( $ n ) { $ string = $ this -> get_plural_forms ( ) ; $ string = str_replace ( 'nplurals' , "\$total" , $ string ) ; $ string = str_replace ( "n" , $ n , $ string ) ; $ string = str_replace ( 'plural' , "\$plural" , $ string ) ; $ total = 0 ; $ plural = 0 ; eval ( "$string" ) ; if ( $ plural >= $ total ) $ plural = $ total - 1 ; return $ plural ; } | Detects which plural form to take |
28,617 | public static function identity ( int $ n ) : self { if ( $ n < 1 ) { throw new InvalidArgumentException ( 'Dimensionality must be' . ' greater than 0 on all axes.' ) ; } $ a = [ ] ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ temp = [ ] ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { $ temp [ ] = $ i === $ j ? 1 : 0 ; } $ a [ ] = $ temp ; } return self :: quick ( $ a ) ; } | Return an identity matrix with the given dimensions . |
28,618 | public static function zeros ( int $ m , int $ n ) : self { if ( $ m < 1 or $ n < 1 ) { throw new InvalidArgumentException ( 'Dimensionality must be' . ' greater than 0 on all axes.' ) ; } $ a = array_fill ( 0 , $ m , array_fill ( 0 , $ n , 0 ) ) ; return self :: quick ( $ a ) ; } | Return a zero matrix with the given dimensions . |
28,619 | public static function diagonal ( array $ elements ) : self { $ n = count ( $ elements ) ; if ( $ n < 1 ) { throw new InvalidArgumentException ( 'Dimensionality must be' . ' greater than 0 on all axes.' ) ; } foreach ( $ elements as $ element ) { if ( ! is_int ( $ element ) and ! is_float ( $ element ) ) { throw new InvalidArgumentException ( 'Diagonal element' . ' must be an integer or float, ' . gettype ( $ element ) . ' found.' ) ; } } $ a = [ ] ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ temp = [ ] ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { $ temp [ ] = $ i === $ j ? $ elements [ $ i ] : 0 ; } $ a [ ] = $ temp ; } return self :: quick ( $ a ) ; } | Build a diagonal matrix with the value of each element along the diagonal and 0s everywhere else . |
28,620 | public static function fill ( $ value , int $ m , int $ n ) : self { if ( ! is_int ( $ value ) and ! is_float ( $ value ) ) { throw new InvalidArgumentException ( 'Fill value must be an' . ' integer or float, ' . gettype ( $ value ) . ' found.' ) ; } if ( $ m < 1 or $ n < 1 ) { throw new InvalidArgumentException ( 'Dimensionality must be' . ' greater than 0 on all axes.' ) ; } $ a = array_fill ( 0 , $ m , array_fill ( 0 , $ n , $ value ) ) ; return self :: quick ( $ a ) ; } | Fill a matrix with a given value at each element . |
28,621 | public static function gaussian ( int $ m , int $ n ) : self { if ( $ m < 1 or $ n < 1 ) { throw new InvalidArgumentException ( 'Dimensionality must be' . ' greater than 0 on all axes.' ) ; } $ a = $ extras = [ ] ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) { $ row = [ ] ; if ( ! empty ( $ extras ) ) { $ row [ ] = array_pop ( $ extras ) ; } for ( $ j = count ( $ row ) ; $ j < $ n ; $ j += 2 ) { $ r1 = rand ( 0 , PHP_INT_MAX ) / PHP_INT_MAX ; $ r2 = rand ( 0 , PHP_INT_MAX ) / PHP_INT_MAX ; $ r = sqrt ( - 2. * log ( $ r1 ) ) ; $ row [ ] = $ r * sin ( $ r2 * self :: TWO_PI ) ; $ row [ ] = $ r * cos ( $ r2 * self :: TWO_PI ) ; } if ( count ( $ row ) > $ n ) { $ extras [ ] = array_pop ( $ row ) ; } $ a [ ] = $ row ; } return self :: quick ( $ a ) ; } | Return a standard normally distributed random matrix i . e values between - 1 and 1 . |
28,622 | public static function uniform ( int $ m , int $ n ) : self { if ( $ m < 1 or $ n < 1 ) { throw new InvalidArgumentException ( 'Dimensionality must be' . ' greater than 0 on all axes.' ) ; } $ a = [ ] ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) { $ temp = [ ] ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { $ temp [ ] = rand ( - PHP_INT_MAX , PHP_INT_MAX ) / PHP_INT_MAX ; } $ a [ ] = $ temp ; } return self :: quick ( $ a ) ; } | Return a uniform random matrix with mean 0 and unit variance . |
28,623 | public static function minimum ( Matrix $ a , Matrix $ b ) : self { if ( $ a -> m ( ) !== $ b -> m ( ) ) { throw new DimensionalityMismatchException ( 'Matrix A needs' . " {$a->m()} rows but Matrix B has {$b->m()}." ) ; } if ( $ a -> n ( ) !== $ b -> n ( ) ) { throw new DimensionalityMismatchException ( 'Matrix A needs' . " {$a->n()} columns but Matrix B has {$b->n()}." ) ; } $ c = [ ] ; foreach ( $ a as $ i => $ row ) { $ c [ ] = array_map ( 'min' , $ row , $ b [ $ i ] ) ; } return self :: quick ( $ c ) ; } | Return the elementwise minimum of two matrices . |
28,624 | public static function stack ( array $ vectors ) : self { $ a = [ ] ; foreach ( $ vectors as $ vector ) { if ( ! $ vector instanceof Vector ) { throw new InvalidArgumentException ( 'Cannot stack a non' . ' vector, ' . gettype ( $ vector ) . ' found.' ) ; } $ a [ ] = $ vector -> asArray ( ) ; } return self :: quick ( $ a ) ; } | Build a matrix by stacking an array of vectors . |
28,625 | public function diagonalAsVector ( ) : Vector { if ( ! $ this -> isSquare ( ) ) { throw new RuntimeException ( 'Cannot trace diagonal of a' . ' non square matrix.' ) ; } $ b = [ ] ; for ( $ i = 0 ; $ i < $ this -> m ; $ i ++ ) { $ b [ ] = $ this -> a [ $ i ] [ $ i ] ; } return Vector :: quick ( $ b ) ; } | Return the diagonal elements of a square matrix as a vector . |
28,626 | public function asVectors ( ) : array { $ vectors = [ ] ; foreach ( $ this -> a as $ row ) { $ vectors [ ] = Vector :: quick ( $ row ) ; } return $ vectors ; } | Return each row as a vector in an array . |
28,627 | public function asColumnVectors ( ) : array { $ vectors = [ ] ; foreach ( $ this -> transpose ( ) as $ column ) { $ vectors [ ] = ColumnVector :: quick ( $ column ) ; } return $ vectors ; } | Return each column as a column vector in an array . |
28,628 | public function argmin ( ) : ColumnVector { $ b = [ ] ; foreach ( $ this -> a as $ row ) { $ b [ ] = ( int ) array_search ( min ( $ row ) , $ row ) ; } return ColumnVector :: quick ( $ b ) ; } | Return the index of the minimum element in every row of the matrix . |
28,629 | public function argmax ( ) : ColumnVector { $ b = [ ] ; foreach ( $ this -> a as $ row ) { $ b [ ] = ( int ) array_search ( max ( $ row ) , $ row ) ; } return ColumnVector :: quick ( $ b ) ; } | Return the index of the maximum element in every row of the matrix . |
28,630 | public function map ( callable $ fn ) : self { $ validate = $ fn instanceof Closure ; $ b = [ ] ; foreach ( $ this -> a as $ row ) { $ b [ ] = array_map ( $ fn , $ row ) ; } return new self ( $ b , $ validate ) ; } | Run a function over all of the elements in the matrix . |
28,631 | public function reduce ( callable $ fn , $ initial = 0 ) { if ( ! is_int ( $ initial ) and ! is_float ( $ initial ) ) { throw new InvalidArgumentException ( 'Initial value must' . ' be an integer or float, ' . gettype ( $ initial ) . ' found.' ) ; } $ carry = $ initial ; foreach ( $ this -> a as $ row ) { foreach ( $ row as $ value ) { $ carry = $ fn ( $ value , $ carry ) ; } } return $ carry ; } | Reduce the matrix down to a scalar . |
28,632 | public function transpose ( ) : self { if ( $ this -> m > 1 ) { $ b = array_map ( null , ... $ this -> a ) ; } else { $ b = [ ] ; for ( $ i = 0 ; $ i < $ this -> n ; $ i ++ ) { $ b [ ] = array_column ( $ this -> a , $ i ) ; } } return self :: quick ( $ b ) ; } | Transpose the matrix i . e row become columns and columns become rows . |
28,633 | public function inverse ( ) : self { $ b = self :: identity ( $ this -> m ) -> augmentLeft ( $ this ) -> rref ( ) ; $ c = [ ] ; foreach ( $ b as $ row ) { $ c [ ] = array_slice ( $ row , $ this -> n ) ; } return self :: quick ( $ c ) ; } | Compute the inverse of the matrix . |
28,634 | public function determinant ( ) { if ( ! $ this -> isSquare ( ) ) { throw new RuntimeException ( 'Determinant is undefined' . ' for a non square matrix.' ) ; } [ $ b , $ swaps ] = $ this -> ref ( ) ; $ pi = $ b -> diagonalAsVector ( ) -> product ( ) ; return $ pi * ( - 1. ) ** $ swaps ; } | Calculate the determinant of the matrix . |
28,635 | public function rank ( ) : int { $ pivots = 0 ; foreach ( $ this -> rref ( ) as $ row ) { foreach ( $ row as $ value ) { if ( $ value != 0 ) { $ pivots ++ ; continue 2 ; } } } return $ pivots ; } | Calculate the rank of the matrix i . e the number of pivots in its reduced row echelon form . |
28,636 | public function dot ( Vector $ b ) : ColumnVector { if ( $ this -> n !== $ b -> size ( ) ) { throw new DimensionalityMismatchException ( 'Matrix A requires' . " $this->n elements but Vector B has {$b->size()}." ) ; } return $ this -> matmul ( $ b -> asColumnMatrix ( ) ) -> columnAsVector ( 0 ) ; } | Compute the dot product of this matrix and a vector . |
28,637 | public function convolve ( Matrix $ b , int $ stride = 1 ) : self { [ $ m , $ n ] = $ b -> shape ( ) ; if ( $ m > $ this -> m or $ n > $ this -> n ) { throw new InvalidArgumentException ( 'Matrix B cannot be' . ' larger than Matrix A.' ) ; } if ( $ stride < 1 ) { throw new InvalidArgumentException ( 'Stride cannot be' . " less than 1, $stride given." ) ; } $ p = intdiv ( $ m , 2 ) ; $ q = intdiv ( $ n , 2 ) ; $ c = [ ] ; for ( $ i = 0 ; $ i < $ this -> m ; $ i += $ stride ) { $ temp = [ ] ; for ( $ j = 0 ; $ j < $ this -> n ; $ j += $ stride ) { $ sigma = 0 ; foreach ( $ b as $ k => $ rowB ) { foreach ( $ rowB as $ l => $ valueB ) { $ x = $ i + $ p - ( int ) $ k ; $ y = $ j + $ q - ( int ) $ l ; if ( $ x < 0 or $ x >= $ this -> n or $ y < 0 or $ y >= $ this -> m ) { continue 1 ; } $ sigma += $ this -> a [ $ x ] [ $ y ] * $ valueB ; } } $ temp [ ] = $ sigma ; } $ c [ ] = $ temp ; } return self :: quick ( $ c ) ; } | Convolve this matrix with another matrix . |
28,638 | public function eig ( bool $ normalize = true ) : array { if ( ! $ this -> isSquare ( ) ) { throw new RuntimeException ( 'Cannot decompose a non' . ' square matrix.' ) ; } $ jama = new JAMA ( $ this -> a ) ; $ decomp = $ jama -> eig ( ) ; $ eigenvalues = $ decomp -> getRealEigenvalues ( ) ; $ eigenvectors = $ decomp -> getV ( ) -> getArray ( ) ; $ eigenvectors = self :: quick ( $ eigenvectors ) -> transpose ( ) ; if ( $ normalize === true ) { $ norm = $ eigenvectors -> transpose ( ) -> square ( ) -> sum ( ) -> sqrt ( ) -> transpose ( ) ; $ eigenvectors = $ eigenvectors -> divide ( $ norm ) ; } return [ $ eigenvalues , $ eigenvectors ] ; } | Compute the eigenvalues and eigenvectors of the matrix and return them in a tuple . |
28,639 | public function solve ( Vector $ b ) : ColumnVector { $ k = $ this -> m - 1 ; [ $ l , $ u , $ p ] = $ this -> lu ( ) ; $ pb = $ p -> dot ( $ b ) ; $ y = [ $ pb [ 0 ] / ( $ l [ 0 ] [ 0 ] ? : self :: EPSILON ) ] ; for ( $ i = 1 ; $ i < $ this -> m ; $ i ++ ) { $ sigma = 0 ; for ( $ j = 0 ; $ j <= $ i - 1 ; $ j ++ ) { $ sigma += $ l [ $ i ] [ $ j ] * $ y [ $ j ] ; } $ y [ ] = ( $ pb [ $ i ] - $ sigma ) / $ l [ $ i ] [ $ i ] ; } $ x = [ ] ; $ x = [ $ k => $ y [ $ k ] / ( $ l [ $ k ] [ $ k ] ? : self :: EPSILON ) ] ; for ( $ i = $ this -> m - 2 ; $ i >= 0 ; $ i -- ) { $ sigma = 0 ; for ( $ j = $ i + 1 ; $ j < $ this -> m ; $ j ++ ) { $ sigma += $ u [ $ i ] [ $ j ] * $ x [ $ j ] ; } $ x [ $ i ] = ( $ y [ $ i ] - $ sigma ) / $ u [ $ i ] [ $ i ] ; } return ColumnVector :: quick ( array_reverse ( $ x ) ) ; } | Solve a linear system of equations given the matrix and a solution vector b . Returns the column vector x that satisfies the solution . |
28,640 | public function divide ( $ b ) { switch ( true ) { case $ b instanceof Matrix : $ c = $ this -> divideMatrix ( $ b ) ; break ; case $ b instanceof ColumnVector : $ c = $ this -> divideColumnVector ( $ b ) ; break ; case $ b instanceof Vector : $ c = $ this -> divideVector ( $ b ) ; break ; case is_int ( $ b ) or is_float ( $ b ) : $ c = $ this -> divideScalar ( $ b ) ; break ; default : throw new InvalidArgumentException ( 'Cannot divide matrix' . ' with a ' . gettype ( $ b ) . '.' ) ; } return $ c ; } | A universal function to divide this matrix by another tensor element - wise . |
28,641 | public function add ( $ b ) { switch ( true ) { case $ b instanceof Matrix : $ c = $ this -> addMatrix ( $ b ) ; break ; case $ b instanceof ColumnVector : $ c = $ this -> addColumnVector ( $ b ) ; break ; case $ b instanceof Vector : $ c = $ this -> addVector ( $ b ) ; break ; case is_int ( $ b ) or is_float ( $ b ) : $ c = $ this -> addScalar ( $ b ) ; break ; default : throw new InvalidArgumentException ( 'Cannot add matrix' . ' to a ' . gettype ( $ b ) . '.' ) ; } return $ c ; } | A universal function to add this matrix with another tensor element - wise . |
28,642 | public function subtract ( $ b ) { switch ( true ) { case $ b instanceof Matrix : $ c = $ this -> subtractMatrix ( $ b ) ; break ; case $ b instanceof ColumnVector : $ c = $ this -> subtractColumnVector ( $ b ) ; break ; case $ b instanceof Vector : $ c = $ this -> subtractVector ( $ b ) ; break ; case is_int ( $ b ) or is_float ( $ b ) : $ c = $ this -> subtractScalar ( $ b ) ; break ; default : throw new InvalidArgumentException ( 'Cannot subtract a ' . gettype ( $ b ) . ' from a matrix.' ) ; } return $ c ; } | A universal function to subtract this matrix from another tensor element - wise . |
28,643 | public function greaterEqual ( $ b ) { switch ( true ) { case $ b instanceof Matrix : $ c = $ this -> greaterEqualMatrix ( $ b ) ; break ; case $ b instanceof ColumnVector : $ c = $ this -> greaterEqualColumnVector ( $ b ) ; break ; case $ b instanceof Vector : $ c = $ this -> greaterEqualVector ( $ b ) ; break ; case is_int ( $ b ) or is_float ( $ b ) : $ c = $ this -> greaterEqualScalar ( $ b ) ; break ; default : throw new InvalidArgumentException ( 'Cannot compare matrix' . ' to a ' . gettype ( $ b ) . '.' ) ; } return $ c ; } | A universal function to compute the greater than or equal to comparison of this matrix and another tensor element - wise . |
28,644 | public function less ( $ b ) { switch ( true ) { case $ b instanceof Matrix : $ c = $ this -> lessMatrix ( $ b ) ; break ; case $ b instanceof ColumnVector : $ c = $ this -> lessColumnVector ( $ b ) ; break ; case $ b instanceof Vector : $ c = $ this -> lessVector ( $ b ) ; break ; case is_int ( $ b ) or is_float ( $ b ) : $ c = $ this -> lessScalar ( $ b ) ; break ; default : throw new InvalidArgumentException ( 'Cannot compare matrix' . ' to a ' . gettype ( $ b ) . '.' ) ; } return $ c ; } | A universal function to compute the less than comparison of this matrix and another tensor element - wise . |
28,645 | public function lessEqual ( $ b ) { switch ( true ) { case $ b instanceof Matrix : $ c = $ this -> lessEqualMatrix ( $ b ) ; break ; case $ b instanceof ColumnVector : $ c = $ this -> lessEqualColumnVector ( $ b ) ; break ; case $ b instanceof Vector : $ c = $ this -> lessEqualVector ( $ b ) ; break ; case is_int ( $ b ) or is_float ( $ b ) : $ c = $ this -> lessEqualScalar ( $ b ) ; break ; default : throw new InvalidArgumentException ( 'Cannot compare matrix' . ' to a ' . gettype ( $ b ) . '.' ) ; } return $ c ; } | A universal function to compute the less than or equal to comparison of this matrix and another tensor element - wise . |
28,646 | public function log ( float $ base = M_E ) : self { $ b = [ ] ; foreach ( $ this -> a as $ i => $ row ) { $ temp = [ ] ; foreach ( $ row as $ value ) { $ temp [ ] = log ( $ value , $ base ) ; } $ b [ ] = $ temp ; } return self :: quick ( $ b ) ; } | Return the logarithm of the matrix in specified base . |
28,647 | public function mean ( ) : ColumnVector { if ( $ this -> n < 1 ) { throw new RuntimeException ( 'Median is not defined for matrices' . ' with less than 1 column.' ) ; } return $ this -> sum ( ) -> divide ( $ this -> n ) ; } | Compute the means of each row and return them in a vector . |
28,648 | public function variance ( ) : ColumnVector { return $ this -> subtract ( $ this -> mean ( ) ) -> square ( ) -> sum ( ) -> divide ( $ this -> m ) ; } | Compute the row variance of the matrix and return it in a tuple along with the mean . |
28,649 | public function covariance ( ) : self { $ b = $ this -> subtract ( $ this -> mean ( ) ) ; return $ b -> matmul ( $ b -> transpose ( ) ) -> divide ( $ this -> m ) ; } | Compute the covariance of this matrix and return it in a tuple along with the computed mean . |
28,650 | public function clip ( float $ min , float $ max ) : self { if ( $ min > $ max ) { throw new InvalidArgumentException ( 'Minimum cannot be' . ' greater than maximum.' ) ; } $ b = [ ] ; foreach ( $ this -> a as $ row ) { $ temp = [ ] ; foreach ( $ row as $ value ) { if ( $ value > $ max ) { $ temp [ ] = $ max ; continue 1 ; } if ( $ value < $ min ) { $ temp [ ] = $ min ; continue 1 ; } $ temp [ ] = $ value ; } $ b [ ] = $ temp ; } return self :: quick ( $ b ) ; } | Clip the elements in the matrix to be between given minimum and maximum and return a new matrix . |
28,651 | public function rowExclude ( int $ index ) : self { $ b = $ this -> a ; unset ( $ b [ $ index ] ) ; $ b = array_values ( $ b ) ; return self :: quick ( $ b ) ; } | Exclude a row from the matrix . |
28,652 | public function columnExclude ( int $ index ) : self { $ b = $ this -> a ; foreach ( $ b as & $ row ) { unset ( $ row [ $ index ] ) ; $ row = array_values ( $ row ) ; } return self :: quick ( $ b ) ; } | Exclude a column from the matrix . |
28,653 | public function augmentAbove ( Matrix $ b ) : self { if ( $ this -> m > 0 and $ b -> n ( ) !== $ this -> n ) { throw new DimensionalityMismatchException ( 'Matrix A requires' . " $this->n columns but Matrix B has {$b->n()}." ) ; } $ b = array_merge ( $ b -> asArray ( ) , $ this -> a ) ; return self :: quick ( $ b ) ; } | Attach matrix b above this matrix . |
28,654 | public function augmentLeft ( Matrix $ b ) : self { if ( $ this -> m > 0 and $ b -> m ( ) !== $ this -> m ( ) ) { throw new DimensionalityMismatchException ( 'Matrix A requires' . " $this->m columns but Matrix B has {$b->m()}." ) ; } $ b = array_map ( 'array_merge' , $ b -> asArray ( ) , $ this -> a ) ; return self :: quick ( $ b ) ; } | Attach matrix b to the left of this matrix . |
28,655 | public function repeat ( int $ m = 1 , int $ n = 1 ) : self { if ( $ m < 1 or $ n < 1 ) { throw new InvalidArgumentException ( 'Cannot repeat less than 1' . ' row or column.' ) ; } $ b = $ this -> a ; $ n -= 1 ; if ( $ n > 0 ) { foreach ( $ this -> a as $ i => $ row ) { for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { $ b [ $ i ] = array_merge ( $ b [ $ i ] , $ row ) ; } } } $ c = [ ] ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) { $ c = array_merge ( $ c , $ b ) ; } return self :: quick ( $ c ) ; } | Repeat the matrix m times along the vertival axes and n times along the horizontal axes . |
28,656 | protected function lessMatrix ( Matrix $ b ) : self { if ( $ b -> m ( ) !== $ this -> m ) { throw new DimensionalityMismatchException ( 'Matrix A requires' . " $this->m rows but Matrix B has {$b->m()}." ) ; } if ( $ b -> n ( ) !== $ this -> n ) { throw new DimensionalityMismatchException ( 'Matrix A requires' . " $this->n columns but Matrix B has {$b->n()}." ) ; } $ c = [ ] ; foreach ( $ this -> a as $ i => $ rowA ) { $ rowB = $ b [ $ i ] ; $ temp = [ ] ; foreach ( $ rowA as $ j => $ value ) { $ temp [ ] = $ value < $ rowB [ $ j ] ? 1 : 0 ; } $ c [ ] = $ temp ; } return self :: quick ( $ c ) ; } | Return the element - wise less than comparison of this matrix and another matrix . |
28,657 | protected function multiplyVector ( Vector $ b ) : self { if ( $ b -> n ( ) !== $ this -> n ) { throw new DimensionalityMismatchException ( 'Matrix A requires' . " $this->n columns but Vector B has {$b->n()}." ) ; } $ c = [ ] ; foreach ( $ this -> a as $ row ) { $ temp = [ ] ; foreach ( $ row as $ j => $ value ) { $ temp [ ] = $ value * $ b [ $ j ] ; } $ c [ ] = $ temp ; } return self :: quick ( $ c ) ; } | Multiply this matrix by a vector . |
28,658 | protected function multiplyColumnVector ( ColumnVector $ b ) : self { if ( $ b -> m ( ) !== $ this -> m ) { throw new DimensionalityMismatchException ( 'Matrix A requires' . " $this->m rows but Vector B has {$b->m()}." ) ; } $ c = [ ] ; foreach ( $ this -> a as $ i => $ row ) { $ valueB = $ b [ $ i ] ; $ temp = [ ] ; foreach ( $ row as $ valueA ) { $ temp [ ] = $ valueA * $ valueB ; } $ c [ ] = $ temp ; } return self :: quick ( $ c ) ; } | Multiply this matrix with a column vector . |
28,659 | protected function multiplyScalar ( $ scalar ) : self { if ( ! is_int ( $ scalar ) and ! is_float ( $ scalar ) ) { throw new InvalidArgumentException ( 'Scalar must be an integer' . ' or float, ' . gettype ( $ scalar ) . ' found.' ) ; } if ( $ scalar == 0 ) { return self :: zeros ( ... $ this -> shape ( ) ) ; } $ b = [ ] ; foreach ( $ this -> a as $ row ) { $ temp = [ ] ; foreach ( $ row as $ value ) { $ temp [ ] = $ value * $ scalar ; } $ b [ ] = $ temp ; } return self :: quick ( $ b ) ; } | Multiply this matrix by a scalar . |
28,660 | protected function divideScalar ( $ scalar ) : self { if ( ! is_int ( $ scalar ) and ! is_float ( $ scalar ) ) { throw new InvalidArgumentException ( 'Scalar must be an integer' . ' or float, ' . gettype ( $ scalar ) . ' found.' ) ; } $ b = [ ] ; foreach ( $ this -> a as $ row ) { $ temp = [ ] ; foreach ( $ row as $ value ) { $ temp [ ] = $ value / $ scalar ; } $ b [ ] = $ temp ; } return self :: quick ( $ b ) ; } | Divide this matrix by a scalar . |
28,661 | public static function make ( array $ arguments = [ ] ) { $ class = static :: getFacadeAccessor ( ) ; try { $ reflection = new \ ReflectionClass ( static :: getFacadeAccessor ( ) ) ; $ parameters = $ reflection -> getConstructor ( ) -> getParameters ( ) ; } catch ( \ Throwable $ error ) { throw new \ Exception ( 'Wrong parameter' , 0 , $ error ) ; } return new $ class ( ... static :: composeMakeParameters ( $ parameters , $ arguments ) ) ; } | Make new instance . |
28,662 | public static function input ( $ key , $ default = null , $ clear = false ) { global $ wp_query ; $ value = null ; if ( array_key_exists ( $ key , $ wp_query -> query_vars ) ) { $ value = $ wp_query -> query_vars [ $ key ] ; if ( $ clear ) unset ( $ wp_query -> query_vars [ $ key ] ) ; } else if ( $ _POST && array_key_exists ( $ key , $ _POST ) ) { $ value = $ _POST [ $ key ] ; if ( $ clear ) unset ( $ _POST [ $ key ] ) ; } else if ( array_key_exists ( $ key , $ _GET ) ) { $ value = $ _GET [ $ key ] ; if ( $ clear ) unset ( $ _GET [ $ key ] ) ; } if ( ! is_array ( $ value ) ) $ value = trim ( $ value ) ; return $ value == null ? $ default : ( is_array ( $ value ) ? $ value : ( is_int ( $ value ) ? intval ( $ value ) : ( is_float ( $ value ) ? floatval ( $ value ) : ( strtolower ( $ value ) == 'true' || strtolower ( $ value ) == 'false' ? strtolower ( $ value ) == 'true' : $ value ) ) ) ) ; } | Gets input from either wordpress query vars or request s POST or GET . |
28,663 | protected function multiplyMatrix ( Matrix $ b ) : Matrix { if ( $ this -> n !== $ b -> m ( ) ) { throw new DimensionalityMismatchException ( 'Vector A requires' . " $this->n rows but Matrix B has {$b->m()}." ) ; } $ c = [ ] ; foreach ( $ b as $ i => $ row ) { $ valueA = $ this -> a [ $ i ] ; $ temp = [ ] ; foreach ( $ row as $ valueB ) { $ temp [ ] = $ valueA * $ valueB ; } $ c [ ] = $ temp ; } return Matrix :: quick ( $ c ) ; } | Multiply this column vector with a matrix . |
28,664 | public function update ( UserPolicy $ user , Resume $ resume ) { if ( $ user -> canDo ( 'career.resume.edit' ) && $ user -> isAdmin ( ) ) { return true ; } return $ resume -> user_id == user_id ( ) && $ resume -> user_type == user_type ( ) ; } | Determine if the given user can update the given resume . |
28,665 | public function destroy ( UserPolicy $ user , Resume $ resume ) { return $ resume -> user_id == user_id ( ) && $ resume -> user_type == user_type ( ) ; } | Determine if the given user can delete the given resume . |
28,666 | public function make ( $ objectkey ) { $ vobject = Vobject :: make ( $ objectkey ) ; if ( empty ( $ vobject ) ) { return null ; } return $ vobject -> content ; } | Return an object content from the cache or the database |
28,667 | public static function start ( & $ config ) { $ config = array_merge ( array ( 'scripts_dir' => 'app/scripts' ) , $ config ) ; self :: $ config = & $ config ; self :: $ console = new ConsoleKit \ Console ( ) ; self :: $ console -> addCommand ( 'Atomik\Console::generate' ) ; if ( PHP_SAPI !== 'cli' ) { return false ; } } | Checks we re in console mode |
28,668 | public static function onAtomikStart ( ) { $ paths = ( array ) self :: $ config [ 'scripts_dir' ] ; foreach ( Atomik :: getLoadedPlugins ( true ) as $ plugin => $ path ) { $ paths [ ] = "$path/scripts" ; } foreach ( array_filter ( array_map ( 'realpath' , $ paths ) ) as $ path ) { self :: $ console -> addCommandsFromDir ( $ path , '' , true ) ; } self :: $ console -> run ( ) ; exit ( ) ; } | Display the console and execute callbacks associated to the command |
28,669 | public function issueToken ( IRequest $ request ) { if ( ! $ request -> isMethod ( 'post' ) ) { throw new InvalidHttpMethodException ; } $ grantType = $ this -> grantTypeResolver -> resolve ( $ request ) ; return $ grantType -> grant ( $ request ) ; } | Issues access token using grant type from current request |
28,670 | public function switch ( string $ name , array $ args ) { $ method = function ( string $ key ) { return $ this -> adapters [ $ key ] . "::handle" ; } ; if ( in_array ( $ name , $ this -> cargo_out -> setter_labels ) ) { return call_user_func ( $ method ( "set" ) , $ this -> particle , $ this -> pack ( ) , $ name , $ args ) ; } elseif ( in_array ( $ name , $ this -> cargo_out -> formative_labels ) ) { return call_user_func ( $ method ( "form" ) , $ this -> particle , $ this -> pack ( ) , $ name , $ args ) ; } elseif ( strlen ( $ name ) > 3 ) { $ func_prefix = substr ( $ name , 0 , 3 ) ; if ( array_key_exists ( $ func_prefix , $ this -> adapters ) ) { try { return call_user_func ( $ method ( $ func_prefix ) , $ this -> particle , $ this -> pack ( ) , $ name , $ args ) ; } catch ( \ Exception $ e ) { throw $ e ; } } } throw new InvalidParticleMethodException ( get_class ( $ this -> particle ) , $ name , ( string ) $ this -> particle -> id ( ) ) ; } | Catch - call handler switch |
28,671 | protected function buildViewQuery ( array $ options ) { if ( $ options === array ( ) ) { return '' ; } $ queryString = '?' ; foreach ( $ options as $ key => $ value ) { switch ( $ key ) { case 'key' : case 'startkey' : case 'endkey' : $ queryString .= $ key . '=' . urlencode ( json_encode ( $ value ) ) ; break ; case 'startkey_docid' : $ queryString .= $ key . '=' . urlencode ( ( string ) $ value ) ; break ; case 'reduce' : case 'group' : case 'update' : case 'descending' : case 'include_docs' : $ queryString .= $ key . '=' . ( $ value ? 'true' : 'false' ) ; break ; case 'skip' : case 'group_level' : $ queryString .= $ key . '=' . ( ( int ) $ value ) ; break ; case 'count' : case 'limit' : $ queryString .= 'limit=' . ( ( int ) $ value ) ; break ; default : throw new phpillowNoSuchPropertyException ( $ key ) ; } $ queryString .= '&' ; } return substr ( $ queryString , 0 , - 1 ) ; } | Build view query string from options |
28,672 | public function query ( $ view , array $ options = array ( ) ) { $ url = $ this -> getDatabase ( ) . '_design/' . $ this -> getViewName ( ) . '/_view/' . $ view ; $ url .= $ this -> buildViewQuery ( $ options ) ; $ db = $ this -> getConnection ( ) ; try { $ response = $ db -> get ( $ url ) ; } catch ( phpillowResponseErrorException $ e ) { $ this -> verifyView ( ) ; $ response = $ db -> get ( $ url ) ; } return $ response ; } | Query a view |
28,673 | public function setPrivateKey ( $ path ) { if ( ! file_exists ( $ path ) ) { throw new \ InvalidArgumentException ( 'the private key file does\'t exist' ) ; } $ this -> privateKey = file_get_contents ( $ path ) ; return $ this ; } | set private key |
28,674 | protected function callApiMethod ( $ name , $ arguments ) { $ beforeMethod = 'before' . ucfirst ( $ name ) ; $ afterMethod = 'after' . ucfirst ( $ name ) ; $ options = isset ( $ arguments [ 0 ] ) ? $ arguments [ 0 ] : [ ] ; if ( method_exists ( $ this , $ beforeMethod ) ) { call_user_func_array ( [ $ this , $ beforeMethod ] , $ arguments ) ; } $ result = $ this -> post ( $ this -> apiMethods [ $ name ] , $ this -> createOptionResolver ( $ name ) -> resolve ( $ options ) ) ; if ( method_exists ( $ this , $ afterMethod ) ) { $ result = call_user_func_array ( [ $ this , $ afterMethod ] , array_merge ( [ $ result ] , $ arguments ) ) ; } return $ result ; } | call api method |
28,675 | protected function createOptionResolver ( $ name ) { $ resolverName = ucfirst ( $ name ) . 'OptionResolver' ; if ( ! isset ( $ this -> optionResolvers [ $ resolverName ] ) ) { $ className = "\\Wangjian\\PinganPay\\OptionResolver\\$resolverName" ; $ this -> optionResolvers [ $ resolverName ] = new $ className ( ) ; } return $ this -> optionResolvers [ $ resolverName ] ; } | create option resolver |
28,676 | public function open ( $ filename , $ force = false ) { if ( ! $ this -> filesystem -> exists ( $ filename ) && $ force ) { return $ this -> filesystem -> create ( $ filename ) ; } return $ this -> filesystem -> open ( $ filename ) ; } | By default opens existing files only but can be forced to create new ones . |
28,677 | public function save ( File $ file , $ filename = null ) { if ( $ filename !== null ) { $ file -> setFilename ( $ filename ) ; } $ this -> filesystem -> write ( $ file ) ; } | File changes are made in memory only until this methods actually applies them on the filesystem . |
28,678 | public function jumpAbove ( Text $ text , $ pattern , $ location = null ) { $ searchStrategy = $ this -> searchEngine -> resolve ( $ pattern ) ; $ foundLineNumber = $ searchStrategy -> findAbove ( $ text , $ pattern , $ location ) ; if ( false === $ foundLineNumber ) { throw new PatternNotFoundException ( $ pattern , $ text ) ; } $ text -> setCurrentLineNumber ( $ foundLineNumber ) ; } | Searches the given pattern in the Text above the current line . If the pattern is found the current line is set to it . |
28,679 | public function jumpBelow ( Text $ text , $ pattern , $ location = null ) { $ searchStrategy = $ this -> searchEngine -> resolve ( $ pattern ) ; $ foundLineNumber = $ searchStrategy -> findBelow ( $ text , $ pattern , $ location ) ; if ( false === $ foundLineNumber ) { throw new PatternNotFoundException ( $ pattern , $ text ) ; } $ text -> setCurrentLineNumber ( $ foundLineNumber ) ; } | Searches the given pattern in the Text below the current line . If the pattern is found the current line is set to it . |
28,680 | public function hasAbove ( Text $ text , $ pattern , $ location = null ) { $ searchStrategy = $ this -> searchEngine -> resolve ( $ pattern ) ; $ foundLineNumber = $ searchStrategy -> findAbove ( $ text , $ pattern , $ location ) ; return ( false !== $ foundLineNumber ) ; } | Checks the presence of the given pattern in the Text above the current line . |
28,681 | public function hasBelow ( Text $ text , $ pattern , $ location = null ) { $ searchStrategy = $ this -> searchEngine -> resolve ( $ pattern ) ; $ foundLineNumber = $ searchStrategy -> findBelow ( $ text , $ pattern , $ location ) ; return ( false !== $ foundLineNumber ) ; } | Checks the presence of the given pattern in the Text below the current line . |
28,682 | public function replaceAll ( Text $ text , $ pattern , $ replacement ) { $ input = array ( 'text' => $ text , 'pattern' => $ pattern , 'replacement' => $ replacement , ) ; $ this -> commandInvoker -> run ( 'replace_all' , $ input ) ; } | Replaces all the occurences which match the given pattern with the given replacement . |
28,683 | protected function config ( string $ operator , string $ key = null ) { if ( isset ( $ this -> mutators [ $ operator ] ) ) { return is_null ( $ key ) ? $ this -> mutators [ $ operator ] : $ this -> mutators [ $ operator ] [ $ key ] ; } } | Get mutator config . |
28,684 | protected function registerMutator ( string $ operator , $ callable , bool $ stack = false , string $ property = null ) : self { $ this -> mutators [ $ operator ] = [ 'callable' => $ callable , 'stack' => $ stack , 'property' => $ property ?? $ this -> name , ] ; return $ this ; } | Register mutator . |
28,685 | public function registerSetMutator ( $ callable , bool $ stack = false , string $ property = null ) : self { return $ this -> registerMutator ( self :: OPERATOR_SET , $ callable , $ stack , $ property ) ; } | Register set mutator . |
28,686 | public function registerGetMutator ( $ callable , bool $ stack = false , string $ property = null ) : self { return $ this -> registerMutator ( self :: OPERATOR_GET , $ callable , $ stack , $ property ) ; } | Register get mutator . |
28,687 | protected function mutatorNameOrFail ( string $ name , string $ operator ) : string { if ( ! $ this -> hasMutator ( $ name , $ operator ) ) { throw new DynamicMutatorNotDefinedException ( 'Mutator not defined!' , 0 , null , [ 'name' => $ name , 'operator' => $ operator , 'handler' => $ this -> getName ( ) , ] ) ; } return $ name ; } | Return a valid mutator name or throw an exceptions . |
28,688 | protected function callableOrFail ( string $ operator ) : callable { $ callable = $ this -> config ( $ operator , 'callable' ) ; if ( is_string ( $ callable ) && method_exists ( $ this -> model , $ callable ) ) { return [ $ this -> model , $ callable ] ; } if ( is_callable ( $ callable ) ) { return $ callable ; } throw new DynamicMutatorNotCallableException ( 'The given callable is invalid!' , 0 , null , [ 'callable' => $ callable , 'handler' => $ this -> getName ( ) , ] ) ; } | Get callable or throw an exception . |
28,689 | protected function hasMutator ( string $ name , string $ operator ) : bool { return isset ( $ this -> mutators [ $ operator ] ) && $ this -> getMutatorProperties ( $ operator ) -> has ( $ name ) ; } | Determinate if a mutator exists . |
28,690 | public function make ( Request $ request ) { $ url = $ request -> path ( ) ; if ( $ url == '/' ) { $ url = 'index' ; } return view ( $ url ) ; } | Make and return a view relating to the current URL . |
28,691 | public function resolve ( IRequest $ request ) { foreach ( $ this -> tokenTypes as $ tokenType ) { if ( $ tokenType -> match ( $ request ) ) { return $ tokenType ; } } throw new UnsupportedTokenTypeException ; } | Resolves token type from request |
28,692 | public function addPreviewImageAndDesc ( $ row , $ label ) { if ( $ row [ 'pdir_th_description' ] != '' ) { $ label = '<span><img src="bundles/themehelper/img/buy_theme.png" ' . ' title="' . $ GLOBALS [ 'TL_LANG' ] [ 'tl_theme' ] [ 'buyTheme' ] . '"' . ' onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':768,\'title\':\'' . $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'buyThemeButtonTitle' ] . '\',\'url\':\'https://contao-themes.net/buy-mate.html\',\'id\':\'buyTheme\'});return false"' . ' style="margin: 10px 10px 10px 0;"></span>' . $ label ; } $ label = $ this -> addPreviewImage ( $ row , $ label ) ; if ( $ row [ 'pdir_th_description' ] != '' ) { $ html = '<i class="icon" onmouseover="document.getElementById(\'themeDesc\').style.display = \'block\'"' . ' onmouseout="document.getElementById(\'themeDesc\').style.display = \'none\'"' . ' style="color:#fff;border-radius:50%;font-weight:bold;padding:3px;border:1px solid #649d9a;background:#649d9a;margin-left:10px;">i</i>' ; if ( $ row [ 'pdir_th_license_domain' ] != '' ) $ html .= $ GLOBALS [ 'TL_LANG' ] [ 'tl_theme' ] [ 'pdir_th_payed_license_text' ] . $ row [ 'pdir_th_license_domain' ] . '<br>' ; else $ html .= $ GLOBALS [ 'TL_LANG' ] [ 'tl_theme' ] [ 'pdir_th_license_text' ] . '<br>' ; $ html .= '<div id="themeDesc" style="display:none;line-height:1.2em;margin-top:5px;">' ; $ html .= \ StringUtil :: decodeEntities ( $ row [ 'pdir_th_description' ] ) ; $ html .= '</div>' ; $ label = $ label . $ html ; } return $ label ; } | Add an image and a description to each record |
28,693 | public function validate ( $ input ) { if ( ! preg_match ( $ this -> regexp , $ input ) ) { throw new phpillowValidationException ( 'Input %input did not match regular expression %expression.' , array ( 'input' => $ input , 'expression' => $ this -> regexp , ) ) ; } return ( string ) $ input ; } | Validate input string against a regexp |
28,694 | public function getResolver ( ) { if ( ! $ this -> resolver instanceof Resolver \ AggregateResolver ) { $ this -> resolver = new Resolver \ AggregateResolver ( ) ; $ this -> resolver -> attach ( new Resolver \ DefaultResolver ( ) , 0 ) ; } return $ this -> resolver ; } | Get template resolver |
28,695 | public function render ( $ template , $ view , $ partials = null ) { $ tokenizedPartials = [ ] ; if ( null !== $ partials ) { if ( ! is_array ( $ partials ) && ! is_object ( $ partials ) ) { throw new Exception \ InvalidPartialsException ( ) ; } foreach ( $ partials as $ alias => $ partialTemplate ) { if ( ! is_string ( $ partialTemplate ) ) { continue ; } $ tokenizedPartials [ $ alias ] = $ this -> tokenize ( $ partialTemplate ) ; $ this -> cachedTemplates [ $ alias ] = $ tokenizedPartials [ $ alias ] ; } } $ tokens = $ this -> tokenize ( $ template ) ; $ renderer = $ this -> getRenderer ( ) ; return $ renderer -> render ( $ tokens , $ view , $ tokenizedPartials ) ; } | Render a template using a view and optionally a list of partials |
28,696 | public function tokenize ( $ template , $ cacheTokens = true ) { $ lexer = $ this -> getLexer ( ) ; if ( false !== strstr ( $ template , '{{' ) ) { return $ lexer -> compile ( $ this , $ template ) ; } if ( $ cacheTokens && array_key_exists ( $ template , $ this -> cachedTemplates ) && is_array ( $ this -> cachedTemplates [ $ template ] ) ) { return $ this -> cachedTemplates [ $ template ] ; } $ templateOrTokens = $ this -> fetchTemplate ( $ template ) ; if ( is_string ( $ templateOrTokens ) ) { $ templateOrTokens = $ lexer -> compile ( $ this , $ templateOrTokens , $ template ) ; } if ( $ templateOrTokens instanceof Traversable ) { $ templateOrTokens = iterator_to_array ( $ templateOrTokens ) ; } if ( ! is_array ( $ templateOrTokens ) ) { throw new Exception \ InvalidTokensException ( sprintf ( '%s was unable to either retrieve or compile tokens' , __METHOD__ ) ) ; } if ( $ cacheTokens ) { $ this -> cachedTemplates [ $ template ] = $ templateOrTokens ; } return $ templateOrTokens ; } | Tokenize a template |
28,697 | private function fetchTemplate ( $ template ) { $ resolver = $ this -> getResolver ( ) ; $ content = $ resolver -> resolve ( $ template ) ; if ( ! $ content ) { throw new Exception \ TemplateNotFoundException ( 'Template by name "' . $ template . '" not found' ) ; } return $ content ; } | Locate and retrieve a template in the template path stack |
28,698 | public function merge ( $ output ) { if ( empty ( $ this -> files ) ) { throw new \ LogicException ( "You need to add some files to merge by calling one of addFile, addFiles, setFiles methods" ) ; } $ outputFiles = array ( ) ; foreach ( $ this -> files as $ file ) { if ( ! $ this -> supports ( $ file ) ) { if ( ! $ this -> omitUnsupported ) { throw new UnsupportedException ( sprintf ( "Transformer for file '%s' not found, mime: %s" , $ file -> getPath ( ) , $ file -> getMimeType ( ) ) ) ; } continue ; } if ( ! $ this -> driver -> supports ( $ file ) ) { $ outputFile = $ this -> getTransformer ( $ file ) -> transform ( $ file ) ; if ( ! $ outputFile ) { throw new \ LogicException ( sprintf ( "Transformer should return NeuroSys\\FileMerger\\File in '%s' format" , $ this -> driver -> getFormat ( ) ) ) ; } $ outputFiles [ ] = $ outputFile -> getPath ( ) ; } else { $ outputFiles [ ] = $ file -> getPath ( ) ; } } if ( count ( $ outputFiles ) == 1 ) { copy ( end ( $ outputFiles ) , $ output ) ; } elseif ( $ outputFiles ) { $ this -> driver -> merge ( $ outputFiles , $ output ) ; } $ this -> files = array ( ) ; } | Merge added files |
28,699 | public function stream_seek ( $ offset , $ whence ) { switch ( $ whence ) { case SEEK_SET : if ( ( $ offset < $ this -> length ) && ( $ offset >= 0 ) ) { $ this -> position = $ offset ; return true ; } else { return false ; } break ; case SEEK_CUR : if ( $ offset >= 0 ) { $ this -> position += $ offset ; return true ; } else { return false ; } break ; case SEEK_END : if ( ( $ this -> length + $ offset ) >= 0 ) { $ this -> position = $ this -> length + $ offset ; return true ; } else { return false ; } break ; default : return false ; } } | Seek to a defined position in the string |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.