idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
47,600 | public static function merge ( & $ context , $ tmp ) { $ context [ 'error' ] = $ tmp [ 'error' ] ; $ context [ 'helpers' ] = $ tmp [ 'helpers' ] ; $ context [ 'partials' ] = $ tmp [ 'partials' ] ; $ context [ 'partialCode' ] = $ tmp [ 'partialCode' ] ; $ context [ 'partialStack' ] = $ tmp [ 'partialStack' ] ; $ context... | Merge a context into another |
47,601 | public static function debug ( $ v , $ f , $ cx ) { $ P = func_get_args ( ) ; $ params = array ( ) ; for ( $ i = 2 ; $ i < count ( $ P ) ; $ i ++ ) { $ params [ ] = & $ P [ $ i ] ; } $ r = call_user_func_array ( ( isset ( $ cx [ 'funcs' ] [ $ f ] ) ? $ cx [ 'funcs' ] [ $ f ] : "{$cx['runtime']}::$f" ) , $ params ) ; if... | Output debug info . |
47,602 | public static function err ( $ cx , $ err ) { if ( $ cx [ 'flags' ] [ 'debug' ] & static :: DEBUG_ERROR_LOG ) { error_log ( $ err ) ; return ; } if ( $ cx [ 'flags' ] [ 'debug' ] & static :: DEBUG_ERROR_EXCEPTION ) { throw new \ Exception ( $ err ) ; } } | Handle error by error_log or throw exception . |
47,603 | public static function v ( $ cx , $ in , $ base , $ path , $ args = null ) { $ count = count ( $ cx [ 'scopes' ] ) ; $ plen = count ( $ path ) ; while ( $ base ) { $ v = $ base ; foreach ( $ path as $ i => $ name ) { if ( is_array ( $ v ) ) { if ( isset ( $ v [ $ name ] ) ) { $ v = $ v [ $ name ] ; continue ; } if ( ( ... | Resursive lookup variable and helpers . This is slow and will only be used for instance property or method detection or lambdas . |
47,604 | public static function m ( $ cx , $ a , $ b ) { if ( is_array ( $ b ) ) { if ( $ a === null ) { return $ b ; } else if ( is_array ( $ a ) ) { return array_merge ( $ a , $ b ) ; } else if ( $ cx [ 'flags' ] [ 'method' ] || $ cx [ 'flags' ] [ 'prop' ] ) { if ( ! is_object ( $ a ) ) { $ a = new StringObject ( $ a ) ; } fo... | Get merged context . |
47,605 | public static function exch ( $ cx , $ ch , $ vars , & $ options ) { $ args = $ vars [ 0 ] ; $ args [ ] = $ options ; $ e = null ; $ r = true ; try { $ r = call_user_func_array ( $ cx [ 'helpers' ] [ $ ch ] , $ args ) ; } catch ( \ Exception $ E ) { $ e = "Runtime: call custom helper '$ch' error: " . $ E -> getMessage ... | Execute custom helper with prepared options |
47,606 | public static function compilePartial ( $ template , $ options = array ( 'flags' => self :: FLAG_BESTPERFORMANCE ) ) { $ context = Context :: create ( $ options ) ; if ( static :: handleError ( $ context ) ) { return false ; } $ code = Partial :: compile ( $ context , SafeString :: escapeTemplate ( $ template ) ) ; sta... | Compile handlebars partial into PHP function code . |
47,607 | protected static function handleError ( & $ context ) { static :: $ lastContext = $ context ; if ( count ( $ context [ 'error' ] ) ) { if ( $ context [ 'flags' ] [ 'errorlog' ] ) { error_log ( implode ( "\n" , $ context [ 'error' ] ) ) ; } if ( $ context [ 'flags' ] [ 'exception' ] ) { throw new \ Exception ( implode (... | Handle exists error and return error status . |
47,608 | public static function prepare ( $ php , $ tmpDir = null , $ delete = true ) { $ php = "<?php $php ?>" ; if ( ! ini_get ( 'allow_url_include' ) || ! ini_get ( 'allow_url_fopen' ) ) { if ( ! is_string ( $ tmpDir ) || ! is_dir ( $ tmpDir ) ) { $ tmpDir = sys_get_temp_dir ( ) ; } } if ( is_dir ( $ tmpDir ) ) { $ fn = temp... | Get a working render function by a string of PHP code . This method may requires php setting allow_url_include = 1 and allow_url_fopen = 1 or access right to tmp file system . |
47,609 | protected static function pushLeft ( & $ context ) { $ L = $ context [ 'currentToken' ] [ Token :: POS_LOTHER ] . $ context [ 'currentToken' ] [ Token :: POS_LSPACE ] ; if ( $ context [ 'currentToken' ] [ Token :: POS_OP ] === '!' ) { $ appender = function ( & $ pb ) use ( $ L ) { $ pb .= $ L ; } ; if ( count ( $ conte... | push left string of current token and clear it |
47,610 | protected static function pushToken ( & $ context , $ token ) { if ( $ token === '' ) { return ; } if ( is_string ( $ token ) ) { if ( is_string ( end ( $ context [ 'parsed' ] [ 0 ] ) ) ) { $ context [ 'parsed' ] [ 0 ] [ key ( $ context [ 'parsed' ] [ 0 ] ) ] .= $ token ; return ; } } $ context [ 'parsed' ] [ 0 ] [ ] =... | push a token into the stack when it is not empty string |
47,611 | protected static function pushStack ( & $ context , $ operation , $ vars ) { list ( $ levels , $ spvar , $ var ) = Expression :: analyze ( $ context , $ vars [ 0 ] ) ; $ context [ 'stack' ] [ ] = $ context [ 'currentToken' ] [ Token :: POS_INNERTAG ] ; $ context [ 'stack' ] [ ] = Expression :: toString ( $ levels , $ s... | push current token into the section stack |
47,612 | protected static function delimiter ( $ token , & $ context ) { if ( strlen ( $ token [ Token :: POS_BEGINRAW ] ) !== strlen ( $ token [ Token :: POS_ENDRAW ] ) ) { $ context [ 'error' ] [ ] = 'Bad token ' . Token :: toString ( $ token ) . ' ! Do you mean ' . Token :: toString ( $ token , array ( Token :: POS_BEGINRAW ... | Verify delimiters and operators |
47,613 | protected static function inlinePartial ( & $ context , $ vars ) { if ( count ( $ context [ 'inlinepartial' ] ) > 0 ) { $ ended = false ; $ append = $ context [ 'currentToken' ] [ Token :: POS_LOTHER ] . $ context [ 'currentToken' ] [ Token :: POS_LSPACE ] ; array_walk ( $ context [ 'inlinepartial' ] , function ( & $ p... | validate inline partial begin token |
47,614 | protected static function partialBlock ( & $ context , $ vars ) { if ( count ( $ context [ 'partialblock' ] ) > 0 ) { $ ended = false ; $ append = $ context [ 'currentToken' ] [ Token :: POS_LOTHER ] . $ context [ 'currentToken' ] [ Token :: POS_LSPACE ] ; array_walk ( $ context [ 'partialblock' ] , function ( & $ pb )... | validate partial block token |
47,615 | protected static function blockBegin ( & $ context , $ vars ) { switch ( ( isset ( $ vars [ 0 ] [ 0 ] ) && is_string ( $ vars [ 0 ] [ 0 ] ) ) ? $ vars [ 0 ] [ 0 ] : null ) { case 'with' : return static :: with ( $ context , $ vars ) ; case 'each' : return static :: section ( $ context , $ vars , true ) ; case 'unless' ... | validate block begin token |
47,616 | protected static function builtin ( & $ context , $ vars ) { if ( $ context [ 'flags' ] [ 'nohbh' ] ) { if ( isset ( $ vars [ 1 ] [ 0 ] ) ) { $ context [ 'error' ] [ ] = "Do not support {{#{$vars[0][0]} var}} because you compile with LightnCandy::FLAG_NOHBHELPERS flag" ; } } else { if ( count ( $ vars ) < 2 ) { $ conte... | validate builtin helpers |
47,617 | protected static function section ( & $ context , $ vars , $ isEach = false ) { if ( $ isEach ) { static :: builtin ( $ context , $ vars ) ; } else { if ( ( count ( $ vars ) > 1 ) && ! $ context [ 'flags' ] [ 'lambda' ] ) { $ context [ 'error' ] [ ] = "Custom helper not found: {$vars[0][0]} in " . Token :: toString ( $... | validate section token |
47,618 | protected static function blockCustomHelper ( & $ context , $ vars , $ inverted = false ) { if ( is_string ( $ vars [ 0 ] [ 0 ] ) ) { if ( static :: resolveHelper ( $ context , $ vars ) ) { return ++ $ context [ 'usedFeature' ] [ 'helper' ] ; } } } | validate block custom helper token |
47,619 | protected static function isDelimiter ( & $ context ) { if ( preg_match ( '/^=\s*([^ ]+)\s+([^ ]+)\s*=$/' , $ context [ 'currentToken' ] [ Token :: POS_INNERTAG ] , $ matched ) ) { $ context [ 'usedFeature' ] [ 'delimiter' ] ++ ; Parser :: setDelimiter ( $ context , $ matched [ 1 ] , $ matched [ 2 ] ) ; return true ; }... | handle delimiter change |
47,620 | protected static function rawblock ( & $ token , & $ context ) { $ inner = $ token [ Token :: POS_INNERTAG ] ; trim ( $ inner ) ; if ( $ context [ 'rawblock' ] && ! ( ( $ token [ Token :: POS_BEGINRAW ] === '{{' ) && ( $ token [ Token :: POS_OP ] === '/' ) && ( $ context [ 'rawblock' ] === $ inner ) ) ) { return true ;... | handle raw block |
47,621 | protected static function doElse ( & $ context , $ vars ) { if ( $ context [ 'level' ] == 0 ) { $ context [ 'error' ] [ ] = '{{else}} only valid in if, unless, each, and #section context' ; } if ( isset ( $ vars [ 1 ] [ 0 ] ) ) { $ token = $ context [ 'currentToken' ] ; $ context [ 'currentToken' ] [ Token :: POS_RSPAC... | Return 1 or larger number when else token detected |
47,622 | public static function helper ( & $ context , $ vars , $ checkSubexp = false ) { if ( static :: resolveHelper ( $ context , $ vars ) ) { $ context [ 'usedFeature' ] [ 'helper' ] ++ ; return true ; } if ( $ checkSubexp ) { switch ( $ vars [ 0 ] [ 0 ] ) { case 'if' : case 'unless' : case 'with' : case 'each' : case 'look... | Return true when the name is listed in helper table |
47,623 | public static function resolveHelper ( & $ context , & $ vars ) { if ( count ( $ vars [ 0 ] ) !== 1 ) { return false ; } if ( isset ( $ context [ 'helpers' ] [ $ vars [ 0 ] [ 0 ] ] ) ) { return true ; } if ( $ context [ 'helperresolver' ] ) { $ helper = $ context [ 'helperresolver' ] ( $ context , $ vars [ 0 ] [ 0 ] ) ... | use helperresolver to resolve helper return true when helper founded |
47,624 | protected static function inline ( & $ context , $ vars ) { if ( ! $ context [ 'flags' ] [ 'runpart' ] ) { $ context [ 'error' ] [ ] = "Do not support {{#*{$context['currentToken'][Token::POS_INNERTAG]}}}, you should do compile with LightnCandy::FLAG_RUNTIMEPARTIAL flag" ; } if ( ! isset ( $ vars [ 0 ] [ 0 ] ) || ( $ v... | validate inline partial |
47,625 | public static function analyze ( $ context , $ var ) { $ levels = 0 ; $ spvar = false ; if ( isset ( $ var [ 0 ] ) ) { if ( ! is_string ( $ var [ 0 ] ) && is_int ( $ var [ 0 ] ) ) { $ levels = array_shift ( $ var ) ; } } if ( isset ( $ var [ 0 ] ) ) { if ( $ context [ 'flags' ] [ 'spvar' ] ) { if ( substr ( $ var [ 0 ]... | Analyze an expression |
47,626 | public static function toString ( $ levels , $ spvar , $ var ) { return ( $ spvar ? '@' : '' ) . str_repeat ( '../' , $ levels ) . ( ( is_array ( $ var ) && count ( $ var ) ) ? implode ( '.' , array_map ( function ( $ v ) { return ( $ v === null ) ? 'this' : "[$v]" ; } , $ var ) ) : 'this' ) ; } | get normalized handlebars expression for a variable |
47,627 | public static function setDelimiter ( & $ context , $ left = null , $ right = null ) { if ( $ left === null ) { $ left = $ context [ 'delimiters' ] [ 0 ] ; } if ( $ right === null ) { $ right = $ context [ 'delimiters' ] [ 1 ] ; } if ( preg_match ( '/=/' , "$left$right" ) ) { $ context [ 'error' ] [ ] = "Can not set de... | Setup delimiter by default or provided string |
47,628 | public static function toString ( $ token , $ merge = null ) { if ( is_array ( $ merge ) ) { $ token = array_replace ( $ token , $ merge ) ; } return implode ( '' , array_slice ( $ token , 3 , - 2 ) ) ; } | return token string |
47,629 | public static function getPartialBlock ( & $ vars ) { if ( isset ( $ vars [ static :: PARTIALBLOCK ] ) ) { $ id = $ vars [ static :: PARTIALBLOCK ] ; unset ( $ vars [ static :: PARTIALBLOCK ] ) ; return $ id ; } return 0 ; } | Get partial block id and fix the variable list |
47,630 | public static function getBlockParams ( & $ vars ) { if ( isset ( $ vars [ static :: BLOCKPARAM ] ) ) { $ list = $ vars [ static :: BLOCKPARAM ] ; unset ( $ vars [ static :: BLOCKPARAM ] ) ; return $ list ; } } | Get block params and fix the variable list |
47,631 | protected static function getLiteral ( $ name , $ asis , $ quote = false ) { return $ asis ? array ( $ name ) : array ( static :: LITERAL , $ quote ? "'$name'" : $ name ) ; } | Return array presentation for a literal |
47,632 | public static function parse ( & $ token , & $ context ) { $ vars = static :: analyze ( $ token [ static :: POS_INNERTAG ] , $ context ) ; if ( $ token [ static :: POS_OP ] === '>' ) { $ fn = static :: getPartialName ( $ vars ) ; } else if ( $ token [ static :: POS_OP ] === '#*' ) { $ fn = static :: getPartialName ( $ ... | Parse the token and return parsed result . |
47,633 | public static function subexpression ( $ expression , & $ context ) { $ context [ 'usedFeature' ] [ 'subexp' ] ++ ; $ vars = static :: analyze ( substr ( $ expression , 1 , - 1 ) , $ context ) ; $ avars = static :: advancedVariable ( $ vars , $ context , $ expression ) ; if ( isset ( $ avars [ 0 ] [ 0 ] ) && ! $ contex... | Parse a subexpression then return parsed result . |
47,634 | protected static function detectQuote ( $ string ) { if ( preg_match ( '/^\([^\)]*$/' , $ string ) ) { return array ( ')' , 1 ) ; } if ( preg_match ( '/^"[^"]*$/' , $ string ) ) { return array ( '"' , 0 ) ; } if ( preg_match ( '/^\\\\\'[^\']*$/' , $ string ) ) { return array ( '\'' , 0 ) ; } if ( preg_match ( '/^[^"]*=... | Detect quote charactors |
47,635 | public function decode ( $ data ) { if ( $ this -> extensionLoaded ( ) ) { $ oData = $ data ; $ data = @ ( ( \ strlen ( $ data ) > 0 ) ? \ gzuncompress ( $ data ) : '' ) ; if ( $ data === false ) { $ tries = 1 ; while ( $ tries < 10 && ( $ data === false || \ strlen ( $ data ) < ( \ strlen ( $ oData ) - $ tries - 1 ) )... | Decodes a flate compressed string . |
47,636 | public function cleanUp ( $ allReaders = false ) { $ readers = $ allReaders ? array_keys ( $ this -> readers ) : $ this -> createdReaders ; foreach ( $ readers as $ id ) { $ this -> readers [ $ id ] -> getParser ( ) -> getStreamReader ( ) -> cleanUp ( ) ; unset ( $ this -> readers [ $ id ] ) ; } $ this -> createdReader... | Release resources and file handles . |
47,637 | protected function getPdfReader ( $ id ) { if ( isset ( $ this -> readers [ $ id ] ) ) { return $ this -> readers [ $ id ] ; } throw new \ InvalidArgumentException ( \ sprintf ( 'No pdf reader with the given id (%s) exists.' , $ id ) ) ; } | Get a pdf reader instance by its id . |
47,638 | public function setSourceFile ( $ file ) { $ this -> currentReaderId = $ this -> getPdfReaderId ( $ file ) ; $ this -> objectsToCopy [ $ this -> currentReaderId ] = [ ] ; $ reader = $ this -> getPdfReader ( $ this -> currentReaderId ) ; $ this -> setMinPdfVersion ( $ reader -> getPdfVersion ( ) ) ; return $ reader -> g... | Set the source PDF file . |
47,639 | public function getImportedPageSize ( $ tpl , $ width = null , $ height = null ) { if ( isset ( $ this -> importedPages [ $ tpl ] ) ) { $ importedPage = $ this -> importedPages [ $ tpl ] ; if ( $ width === null && $ height === null ) { $ width = $ importedPage [ 'width' ] ; $ height = $ importedPage [ 'height' ] ; } el... | Get the size of an imported page . |
47,640 | public function getOffsetFor ( $ objectNumber ) { foreach ( $ this -> getReaders ( ) as $ reader ) { $ offset = $ reader -> getOffsetFor ( $ objectNumber ) ; if ( $ offset !== false ) { return $ offset ; } } return false ; } | Get the offset by an object number . |
47,641 | protected function readXref ( $ offset ) { $ this -> parser -> getStreamReader ( ) -> reset ( $ offset ) ; $ this -> parser -> getTokenizer ( ) -> clearStack ( ) ; $ initValue = $ this -> parser -> readValue ( ) ; return $ this -> initReaderInstance ( $ initValue ) ; } | Read the cross - reference table at a given offset . |
47,642 | protected function initReaderInstance ( $ initValue ) { $ position = $ this -> parser -> getStreamReader ( ) -> getPosition ( ) + $ this -> parser -> getStreamReader ( ) -> getOffset ( ) + $ this -> fileHeaderOffset ; if ( $ initValue instanceof PdfToken && $ initValue -> value === 'xref' ) { try { return new FixedRead... | Get a cross - reference reader instance . |
47,643 | protected function findStartXref ( ) { $ reader = $ this -> parser -> getStreamReader ( ) ; $ reader -> reset ( - self :: $ trailerSearchLength , self :: $ trailerSearchLength ) ; $ buffer = $ reader -> getBuffer ( false ) ; $ pos = \ strrpos ( $ buffer , 'startxref' ) ; $ addOffset = 9 ; if ( $ pos === false ) { $ pos... | Find the start position for the first cross - reference . |
47,644 | public static function parse ( StreamReader $ streamReader ) { $ bufferOffset = $ streamReader -> getOffset ( ) ; while ( true ) { $ buffer = $ streamReader -> getBuffer ( false ) ; $ pos = \ strpos ( $ buffer , '>' , $ bufferOffset ) ; if ( $ pos === false ) { if ( ! $ streamReader -> increaseLength ( ) ) { return fal... | Parses a hexadecimal string object from the stream reader . |
47,645 | public function decode ( $ data ) { $ data = \ preg_replace ( '/[^0-9A-Fa-f]/' , '' , \ rtrim ( $ data , '>' ) ) ; if ( ( \ strlen ( $ data ) % 2 ) === 1 ) { $ data .= '0' ; } return \ pack ( 'H*' , $ data ) ; } | Converts an ASCII hexadecimal encoded string into its binary representation . |
47,646 | public function encode ( $ data , $ leaveEOD = false ) { $ t = \ unpack ( 'H*' , $ data ) ; return \ current ( $ t ) . ( $ leaveEOD ? '' : '>' ) ; } | Converts a string into ASCII hexadecimal representation . |
47,647 | public static function parse ( StreamReader $ streamReader ) { $ pos = $ startPos = $ streamReader -> getOffset ( ) ; $ openBrackets = 1 ; do { $ buffer = $ streamReader -> getBuffer ( false ) ; for ( $ length = \ strlen ( $ buffer ) ; $ openBrackets !== 0 && $ pos < $ length ; $ pos ++ ) { switch ( $ buffer [ $ pos ] ... | Parses a string object from the stream reader . |
47,648 | public static function unescape ( $ s ) { $ out = '' ; for ( $ count = 0 , $ n = \ strlen ( $ s ) ; $ count < $ n ; $ count ++ ) { if ( $ s [ $ count ] !== '\\' ) { $ out .= $ s [ $ count ] ; } else { if ( $ count === ( $ n - 1 ) ) { break ; } switch ( $ s [ ++ $ count ] ) { case ')' : case '(' : case '\\' : $ out .= $... | Unescapes escaped sequences in a PDF string according to the PDF specification . |
47,649 | protected function resolveFileHeader ( ) { if ( $ this -> fileHeader ) { return $ this -> fileHeaderOffset ; } $ this -> streamReader -> reset ( 0 ) ; $ offset = false ; $ maxIterations = 1000 ; while ( true ) { $ buffer = $ this -> streamReader -> getBuffer ( false ) ; $ offset = \ strpos ( $ buffer , '%PDF-' ) ; if (... | Resolves the file header . |
47,650 | public function getCrossReference ( ) { if ( $ this -> xref === null ) { $ this -> xref = new CrossReference ( $ this , $ this -> resolveFileHeader ( ) ) ; } return $ this -> xref ; } | Get the cross reference instance . |
47,651 | public function getPdfVersion ( ) { $ this -> resolveFileHeader ( ) ; if ( \ preg_match ( '/%PDF-(\d)\.(\d)/' , $ this -> fileHeader , $ result ) === 0 ) { throw new PdfParserException ( 'Unable to extract PDF version from file header.' , PdfParserException :: PDF_VERSION_NOT_FOUND ) ; } list ( , $ major , $ minor ) = ... | Get the PDF version . |
47,652 | public function getCatalog ( ) { $ xref = $ this -> getCrossReference ( ) ; $ trailer = $ xref -> getTrailer ( ) ; $ catalog = PdfType :: resolve ( PdfDictionary :: get ( $ trailer , 'Root' ) , $ this ) ; return PdfDictionary :: ensure ( $ catalog ) ; } | Get the catalog dictionary . |
47,653 | public static function createByString ( $ content , $ maxMemory = 2097152 ) { $ h = \ fopen ( 'php://temp/maxmemory:' . ( ( int ) $ maxMemory ) , 'r+b' ) ; \ fwrite ( $ h , $ content ) ; \ rewind ( $ h ) ; return new self ( $ h , true ) ; } | Creates a stream reader instance by a string value . |
47,654 | public function getBufferLength ( $ atOffset = false ) { if ( $ atOffset === false ) { return $ this -> bufferLength ; } return $ this -> bufferLength - $ this -> offset ; } | Returns the byte length of the buffer . |
47,655 | public function getByte ( $ position = null ) { $ position = ( int ) ( $ position !== null ? $ position : $ this -> offset ) ; if ( $ position >= $ this -> bufferLength && ( ! $ this -> increaseLength ( ) || $ position >= $ this -> bufferLength ) ) { return false ; } return $ this -> buffer [ $ position ] ; } | Gets a byte at a specific position in the buffer . |
47,656 | public function readByte ( $ position = null ) { if ( $ position !== null ) { $ position = ( int ) $ position ; if ( ! ( $ position >= $ this -> position && $ position < $ this -> position + $ this -> bufferLength ) ) { $ this -> reset ( $ position ) ; $ offset = $ this -> offset ; } else { $ offset = $ position - $ th... | Returns a byte at a specific position and set the offset to the next byte position . |
47,657 | public function readBytes ( $ length , $ position = null ) { $ length = ( int ) $ length ; if ( $ position !== null ) { if ( ! ( $ position >= $ this -> position && $ position < $ this -> position + $ this -> bufferLength ) ) { $ this -> reset ( $ position , $ length ) ; $ offset = $ this -> offset ; } else { $ offset ... | Read bytes from the current or a specific offset position and set the internal pointer to the next byte . |
47,658 | public function readLine ( $ length = 1024 ) { if ( $ this -> ensureContent ( ) === false ) { return false ; } $ line = '' ; while ( $ this -> ensureContent ( ) ) { $ char = $ this -> readByte ( ) ; if ( $ char === "\n" ) { break ; } if ( $ char === "\r" ) { if ( $ this -> getByte ( ) === "\n" ) { $ this -> addOffset (... | Read a line from the current position . |
47,659 | public function setOffset ( $ offset ) { if ( $ offset > $ this -> bufferLength || $ offset < 0 ) { throw new \ OutOfRangeException ( \ sprintf ( 'Offset (%s) out of range (length: %s)' , $ offset , $ this -> bufferLength ) ) ; } $ this -> offset = ( int ) $ offset ; } | Set the offset position in the current buffer . |
47,660 | public function getTotalLength ( ) { if ( $ this -> totalLength === null ) { $ stat = \ fstat ( $ this -> stream ) ; $ this -> totalLength = $ stat [ 'size' ] ; } return $ this -> totalLength ; } | Gets the total available length . |
47,661 | public function reset ( $ pos = 0 , $ length = 200 ) { if ( $ pos === null ) { $ pos = $ this -> position + $ this -> offset ; } elseif ( $ pos < 0 ) { $ pos = \ max ( 0 , $ this -> getTotalLength ( ) + $ pos ) ; } \ fseek ( $ this -> stream , $ pos ) ; $ this -> position = $ pos ; $ this -> buffer = $ length > 0 ? \ f... | Resets the buffer to a position and re - read the buffer with the given length . |
47,662 | public function ensure ( $ pos , $ length ) { if ( $ pos >= $ this -> position && $ pos < ( $ this -> position + $ this -> bufferLength ) && ( $ this -> position + $ this -> bufferLength ) >= ( $ pos + $ length ) ) { $ this -> offset = $ pos - $ this -> position ; } else { $ this -> reset ( $ pos , $ length ) ; } } | Ensures bytes in the buffer with a specific length and location in the file . |
47,663 | public function increaseLength ( $ minLength = 100 ) { $ length = \ max ( $ minLength , 100 ) ; if ( \ feof ( $ this -> stream ) || $ this -> getTotalLength ( ) === $ this -> position + $ this -> bufferLength ) { return false ; } $ newLength = $ this -> bufferLength + $ length ; do { $ this -> buffer .= \ fread ( $ thi... | Forcefully read more data into the buffer . |
47,664 | public static function parse ( $ objectNumberToken , $ objectGenerationNumberToken , PdfParser $ parser , Tokenizer $ tokenizer , StreamReader $ reader ) { $ value = $ parser -> readValue ( ) ; if ( $ value === false ) { return false ; } $ nextToken = $ tokenizer -> getNextToken ( ) ; if ( $ nextToken === 'stream' ) { ... | Parses an indirect object from a tokenizer parser and stream - reader . |
47,665 | public function getNextToken ( ) { $ token = \ array_pop ( $ this -> stack ) ; if ( $ token !== null ) { return $ token ; } if ( ( $ byte = $ this -> streamReader -> readByte ( ) ) === false ) { return false ; } if ( $ byte === "\x20" || $ byte === "\x0A" || $ byte === "\x0D" || $ byte === "\x0C" || $ byte === "\x09" |... | Get next token . |
47,666 | public function leapWhiteSpaces ( ) { do { if ( ! $ this -> streamReader -> ensureContent ( ) ) { return false ; } $ buffer = $ this -> streamReader -> getBuffer ( false ) ; $ matches = \ strspn ( $ buffer , "\x20\x0A\x0C\x0D\x09\x00" , $ this -> streamReader -> getOffset ( ) ) ; if ( $ matches > 0 ) { $ this -> stream... | Leap white spaces . |
47,667 | public function decode ( $ data ) { if ( $ data [ 0 ] === "\x00" && $ data [ 1 ] === "\x01" ) { throw new LzwException ( 'LZW flavour not supported.' , LzwException :: LZW_FLAVOUR_NOT_SUPPORTED ) ; } $ this -> initsTable ( ) ; $ this -> data = $ data ; $ this -> dataLength = \ strlen ( $ data ) ; $ this -> bytePointer ... | Method to decode LZW compressed data . |
47,668 | protected function getNextCode ( ) { if ( $ this -> bytePointer === $ this -> dataLength ) { return 257 ; } $ this -> nextData = ( $ this -> nextData << 8 ) | ( \ ord ( $ this -> data [ $ this -> bytePointer ++ ] ) & 0xff ) ; $ this -> nextBits += 8 ; if ( $ this -> nextBits < $ this -> bitsToGet ) { $ this -> nextData... | Returns the next 9 10 11 or 12 bits . |
47,669 | public function getPageDictionary ( ) { if ( null === $ this -> pageDictionary ) { $ this -> pageDictionary = PdfDictionary :: ensure ( PdfType :: resolve ( $ this -> getPageObject ( ) , $ this -> parser ) ) ; } return $ this -> pageDictionary ; } | Get the dictionary of this page . |
47,670 | public function getAttribute ( $ name , $ inherited = true ) { $ dict = $ this -> getPageDictionary ( ) ; if ( isset ( $ dict -> value [ $ name ] ) ) { return $ dict -> value [ $ name ] ; } $ inheritedKeys = [ 'Resources' , 'MediaBox' , 'CropBox' , 'Rotate' ] ; if ( $ inherited && \ in_array ( $ name , $ inheritedKeys ... | Get a page attribute . |
47,671 | public function getRotation ( ) { $ rotation = $ this -> getAttribute ( 'Rotate' ) ; if ( null === $ rotation ) { return 0 ; } $ rotation = PdfNumeric :: ensure ( PdfType :: resolve ( $ rotation , $ this -> parser ) ) -> value % 360 ; if ( $ rotation < 0 ) { $ rotation += 360 ; } return $ rotation ; } | Get the rotation value . |
47,672 | public function getBoundary ( $ box = PageBoundaries :: CROP_BOX , $ fallback = true ) { $ value = $ this -> getAttribute ( $ box ) ; if ( $ value !== null ) { return Rectangle :: byPdfArray ( $ value , $ this -> parser ) ; } if ( $ fallback === false ) { return false ; } switch ( $ box ) { case PageBoundaries :: BLEED... | Get a boundary of this page . |
47,673 | public function getWidthAndHeight ( $ box = PageBoundaries :: CROP_BOX , $ fallback = true ) { $ boundary = $ this -> getBoundary ( $ box , $ fallback ) ; if ( $ boundary === false ) { return false ; } $ rotation = $ this -> getRotation ( ) ; $ interchange = ( $ rotation / 90 ) % 2 ; return [ $ interchange ? $ boundary... | Get the width and height of this page . |
47,674 | public function getContentStream ( ) { $ dict = $ this -> getPageDictionary ( ) ; $ contents = PdfType :: resolve ( PdfDictionary :: get ( $ dict , 'Contents' ) , $ this -> parser ) ; if ( $ contents instanceof PdfNull ) { return '' ; } if ( $ contents instanceof PdfArray ) { $ result = [ ] ; foreach ( $ contents -> va... | Get the raw content stream . |
47,675 | public static function resolve ( PdfType $ value , PdfParser $ parser , $ stopAtIndirectObject = false ) { if ( $ value instanceof PdfIndirectObject ) { if ( $ stopAtIndirectObject === true ) { return $ value ; } return self :: resolve ( $ value -> value , $ parser , $ stopAtIndirectObject ) ; } if ( $ value instanceof... | Resolves a PdfType value to its value . |
47,676 | protected static function ensureType ( $ type , $ value , $ errorMessage ) { if ( ! ( $ value instanceof $ type ) ) { throw new PdfTypeException ( $ errorMessage , PdfTypeException :: INVALID_DATA_TYPE ) ; } return $ value ; } | Ensure that a value is an instance of a specific PDF type . |
47,677 | public function setPageFormat ( $ size , $ orientation ) { if ( $ this -> currentTemplateId !== null ) { throw new \ BadMethodCallException ( 'The page format cannot be changed when writing to a template.' ) ; } if ( ! \ in_array ( $ orientation , [ 'P' , 'L' ] , true ) ) { throw new \ InvalidArgumentException ( \ spri... | Set the page format of the current page . |
47,678 | public function useTemplate ( $ tpl , $ x = 0 , $ y = 0 , $ width = null , $ height = null , $ adjustPageSize = false ) { if ( ! isset ( $ this -> templates [ $ tpl ] ) ) { throw new \ InvalidArgumentException ( 'Template does not exist!' ) ; } if ( \ is_array ( $ x ) ) { unset ( $ x [ 'tpl' ] ) ; \ extract ( $ x , EXT... | Draws a template onto the page or another template . |
47,679 | public function getTemplateSize ( $ tpl , $ width = null , $ height = null ) { if ( ! isset ( $ this -> templates [ $ tpl ] ) ) { return false ; } if ( $ width === null && $ height === null ) { $ width = $ this -> templates [ $ tpl ] [ 'width' ] ; $ height = $ this -> templates [ $ tpl ] [ 'height' ] ; } elseif ( $ wid... | Get the size of a template . |
47,680 | public function beginTemplate ( $ width = null , $ height = null , $ groupXObject = false ) { if ( $ width === null ) { $ width = $ this -> w ; } if ( $ height === null ) { $ height = $ this -> h ; } $ templateId = $ this -> getNextTemplateId ( ) ; $ buffer = "2 J\n" . \ sprintf ( '%.2F w' , $ this -> LineWidth * $ thi... | Begins a new template . |
47,681 | public function endTemplate ( ) { if ( null === $ this -> currentTemplateId ) { return false ; } $ templateId = $ this -> currentTemplateId ; $ template = $ this -> templates [ $ templateId ] ; $ state = $ template [ 'state' ] ; $ this -> SetXY ( $ state [ 'x' ] , $ state [ 'y' ] ) ; $ this -> tMargin = $ state [ 'tMar... | Ends a template . |
47,682 | public function getPageCount ( ) { if ( $ this -> pageCount === null ) { $ catalog = $ this -> parser -> getCatalog ( ) ; $ pages = PdfType :: resolve ( PdfDictionary :: get ( $ catalog , 'Pages' ) , $ this -> parser ) ; $ count = PdfType :: resolve ( PdfDictionary :: get ( $ pages , 'Count' ) , $ this -> parser ) ; $ ... | Get the page count . |
47,683 | public function getPage ( $ pageNumber ) { if ( ! \ is_numeric ( $ pageNumber ) ) { throw new \ InvalidArgumentException ( 'Page number needs to be a number.' ) ; } if ( $ pageNumber < 1 || $ pageNumber > $ this -> getPageCount ( ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'Page number "%s" out of availabl... | Get a page instance . |
47,684 | protected function readPages ( ) { if ( \ count ( $ this -> pages ) > 0 ) { return ; } $ readPages = function ( $ kids , $ count ) use ( & $ readPages ) { $ kids = PdfArray :: ensure ( $ kids ) ; $ isLeaf = $ count -> value === \ count ( $ kids -> value ) ; foreach ( $ kids -> value as $ reference ) { $ reference = Pdf... | Walk the page tree and resolve all indirect objects of all pages . |
47,685 | protected function _put ( $ s , $ newLine = true ) { if ( $ newLine ) { $ this -> setBuffer ( $ s . "\n" ) ; } else { $ this -> setBuffer ( $ s ) ; } } | Append content to the buffer of TCPDF . |
47,686 | public static function parse ( PdfDictionary $ dictionary , StreamReader $ reader , PdfParser $ parser = null ) { $ v = new self ; $ v -> value = $ dictionary ; $ v -> reader = $ reader ; $ v -> parser = $ parser ; $ offset = $ reader -> getOffset ( ) ; while ( ( $ firstByte = $ reader -> getByte ( $ offset ) ) !== fal... | Parses a stream from a stream reader . |
47,687 | public function getStream ( $ cache = false ) { if ( \ is_int ( $ this -> stream ) ) { $ length = PdfDictionary :: get ( $ this -> value , 'Length' ) ; if ( $ this -> parser !== null ) { $ length = PdfType :: resolve ( $ length , $ this -> parser ) ; } if ( ! ( $ length instanceof PdfNumeric ) || $ length -> value === ... | Get the stream data . |
47,688 | protected function extractStream ( ) { while ( true ) { $ buffer = $ this -> reader -> getBuffer ( false ) ; $ length = \ strpos ( $ buffer , 'endstream' ) ; if ( $ length === false ) { if ( ! $ this -> reader -> increaseLength ( 100000 ) ) { throw new PdfTypeException ( 'Cannot extract stream.' ) ; } continue ; } brea... | Extract the stream manually . |
47,689 | protected function extract ( StreamReader $ reader ) { $ cycles = - 1 ; $ bytesPerCycle = 100 ; $ reader -> reset ( null , $ bytesPerCycle ) ; while ( ( $ trailerPos = \ strpos ( $ reader -> getBuffer ( false ) , 'trailer' , \ max ( $ bytesPerCycle * $ cycles ++ , 0 ) ) ) === false ) { if ( $ reader -> increaseLength (... | Extracts the cross reference data from the stream reader . |
47,690 | protected function read ( $ xrefContent ) { \ preg_match_all ( "/(\r\n|\n|\r)/" , \ substr ( $ xrefContent , 0 , 100 ) , $ m ) ; if ( \ count ( $ m [ 0 ] ) === 0 ) { throw new CrossReferenceException ( 'No data found in cross-reference.' , CrossReferenceException :: INVALID_DATA ) ; } $ differentLineEndings = \ count (... | Read the cross - reference entries . |
47,691 | public static function parse ( Tokenizer $ tokenizer , PdfParser $ parser ) { $ result = [ ] ; while ( ( $ token = $ tokenizer -> getNextToken ( ) ) !== ']' ) { if ( $ token === false || ( $ value = $ parser -> readValue ( $ token ) ) === false ) { return false ; } $ result [ ] = $ value ; } $ v = new self ; $ v -> val... | Parses an array of the passed tokenizer and parser . |
47,692 | public static function parse ( Tokenizer $ tokenizer , StreamReader $ streamReader , PdfParser $ parser ) { $ entries = [ ] ; while ( true ) { $ token = $ tokenizer -> getNextToken ( ) ; if ( $ token === '>' && $ streamReader -> getByte ( ) === '>' ) { $ streamReader -> addOffset ( 1 ) ; break ; } $ key = $ parser -> r... | Parses a dictionary of the passed tokenizer stream - reader and parser . |
47,693 | public static function get ( $ dictionary , $ key , PdfType $ default = null ) { $ dictionary = self :: ensure ( $ dictionary ) ; if ( isset ( $ dictionary -> value [ $ key ] ) ) { return $ dictionary -> value [ $ key ] ; } return $ default === null ? new PdfNull ( ) : $ default ; } | Get a value by its key from a dictionary or a default value . |
47,694 | public static function parse ( Tokenizer $ tokenizer , StreamReader $ streamReader ) { $ v = new self ; if ( \ strspn ( $ streamReader -> getByte ( ) , "\x00\x09\x0A\x0C\x0D\x20()<>[]{}/%" ) === 0 ) { $ v -> value = ( string ) $ tokenizer -> getNextToken ( ) ; return $ v ; } $ v -> value = '' ; return $ v ; } | Parses a name object from the passed tokenizer and stream - reader . |
47,695 | static public function unescape ( $ value ) { if ( strpos ( $ value , '#' ) === false ) return $ value ; return preg_replace_callback ( '/#[a-fA-F\d]{2}/' , function ( $ matches ) { return chr ( hexdec ( $ matches [ 0 ] ) ) ; } , $ value ) ; } | Unescapes a name string . |
47,696 | protected function read ( ) { $ subSections = [ ] ; $ startObject = $ entryCount = $ lastLineStart = null ; $ validityChecked = false ; while ( ( $ line = $ this -> reader -> readLine ( 20 ) ) !== false ) { if ( \ strpos ( $ line , 'trailer' ) !== false ) { $ this -> reader -> reset ( $ lastLineStart ) ; break ; } if (... | Read the cross - reference . |
47,697 | public function fixFaultySubSectionShift ( ) { $ subSections = $ this -> getSubSections ( ) ; if ( \ count ( $ subSections ) > 1 ) { return false ; } $ subSection = \ current ( $ subSections ) ; if ( $ subSection [ 0 ] != 1 ) { return false ; } if ( $ this -> getOffsetFor ( 1 ) === false ) { foreach ( $ subSections as ... | Fixes an invalid object number shift . |
47,698 | public static function byPdfArray ( $ array , PdfParser $ parser ) { $ array = PdfArray :: ensure ( PdfType :: resolve ( $ array , $ parser ) , 4 ) -> value ; $ ax = PdfNumeric :: ensure ( PdfType :: resolve ( $ array [ 0 ] , $ parser ) ) -> value ; $ ay = PdfNumeric :: ensure ( PdfType :: resolve ( $ array [ 1 ] , $ p... | Create a rectangle instance by a PdfArray . |
47,699 | public function toPdfArray ( ) { $ array = new PdfArray ( ) ; $ array -> value [ ] = PdfNumeric :: create ( $ this -> llx ) ; $ array -> value [ ] = PdfNumeric :: create ( $ this -> lly ) ; $ array -> value [ ] = PdfNumeric :: create ( $ this -> urx ) ; $ array -> value [ ] = PdfNumeric :: create ( $ this -> ury ) ; re... | Get the rectangle as a PdfArray . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.