idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
2,900
|
private function translate ( ) : self { if ( empty ( $ this -> translations ) ) { return $ this ; } $ lang = $ this -> get ( 'lang' ) ; foreach ( $ this -> attributes as $ key => $ attribute ) { if ( in_array ( $ key , $ this -> translations , true ) ) { $ this -> set ( $ key , __ ( $ attribute , [ ] , $ lang ) ) ; } } return $ this ; }
|
Localization of fields .
|
2,901
|
protected function registerOrchid ( ) : self { $ this -> publishes ( [ realpath ( PLATFORM_PATH . '/install-stubs/routes/' ) => base_path ( 'routes' ) , realpath ( PLATFORM_PATH . '/install-stubs/Orchid/' ) => app_path ( 'Orchid' ) , ] , 'orchid-stubs' ) ; return $ this ; }
|
Register orchid .
|
2,902
|
public function registerViews ( ) : self { $ this -> loadViewsFrom ( PLATFORM_PATH . '/resources/views' , 'platform' ) ; $ this -> publishes ( [ PLATFORM_PATH . '/resources/views' => resource_path ( 'views/vendor/platform' ) , ] , 'views' ) ; return $ this ; }
|
Register views & Publish views .
|
2,903
|
public function register ( ) : void { $ this -> commands ( $ this -> commands ) ; $ this -> app -> singleton ( Dashboard :: class , function ( ) { return new Dashboard ( ) ; } ) ; if ( ! Route :: hasMacro ( 'screen' ) ) { Route :: macro ( 'screen' , function ( $ url , $ screen , $ name = null ) { return $ this -> any ( $ url . '/{method?}/{argument?}' , [ $ screen , 'handle' ] ) -> name ( $ name ) ; } ) ; } if ( ! defined ( 'PLATFORM_PATH' ) ) { define ( 'PLATFORM_PATH' , realpath ( __DIR__ . '/../../../' ) ) ; } $ this -> mergeConfigFrom ( realpath ( PLATFORM_PATH . '/config/platform.php' ) , 'platform' ) ; }
|
Register bindings the service provider .
|
2,904
|
public function getAllCategories ( ) { $ categories = $ this -> exists ? self :: whereNotIn ( 'id' , [ $ this -> id ] ) -> get ( ) : self :: get ( ) ; return $ categories -> mapWithKeys ( function ( $ item ) { return [ $ item -> id => $ item -> term -> GetContent ( 'name' ) ] ; } ) -> toArray ( ) ; }
|
Select all categories except current .
|
2,905
|
public function newWithCreateTerm ( $ term ) : self { $ newTerm = Term :: firstOrCreate ( $ term ) ; $ this -> term_id = $ newTerm -> id ; $ this -> term ( ) -> associate ( $ newTerm ) ; $ this -> setTaxonomy ( ) ; return $ this ; }
|
Create category term .
|
2,906
|
public function setParent ( $ parent_id = null ) : self { $ parent_id = ( ( int ) $ parent_id > 0 ) ? ( int ) $ parent_id : null ; $ this -> setAttribute ( 'parent_id' , $ parent_id ) ; return $ this ; }
|
Set parent category .
|
2,907
|
public function utf8ToUtf16BigEndian ( $ str , $ setbom = true ) { if ( $ this -> mpdf -> checkSIP && preg_match ( "/([\x{20000}-\x{2FFFF}])/u" , $ str ) ) { if ( ! in_array ( $ this -> mpdf -> currentfontfamily , [ 'gb' , 'big5' , 'sjis' , 'uhc' , 'gbB' , 'big5B' , 'sjisB' , 'uhcB' , 'gbI' , 'big5I' , 'sjisI' , 'uhcI' , 'gbBI' , 'big5BI' , 'sjisBI' , 'uhcBI' ] ) ) { $ str = preg_replace ( "/[\x{20000}-\x{2FFFF}]/u" , chr ( 0 ) , $ str ) ; } } if ( $ this -> mpdf -> checkSMP && preg_match ( "/([\x{10000}-\x{1FFFF}])/u" , $ str ) ) { $ str = preg_replace ( "/[\x{10000}-\x{1FFFF}]/u" , chr ( 0 ) , $ str ) ; } $ outstr = '' ; if ( $ setbom ) { $ outstr .= "\xFE\xFF" ; } $ outstr .= mb_convert_encoding ( $ str , 'UTF-16BE' , 'UTF-8' ) ; return $ outstr ; }
|
Converts UTF - 8 strings to UTF16 - BE .
|
2,908
|
private function _getXAdvancePos ( $ pos ) { if ( strpos ( $ this -> GlyphClassMarks , $ this -> OTLdata [ $ pos ] [ 'hex' ] ) !== false ) { return $ pos ; } while ( isset ( $ this -> OTLdata [ $ pos + 1 ] [ 'hex' ] ) && strpos ( $ this -> GlyphClassMarks , $ this -> OTLdata [ $ pos + 1 ] [ 'hex' ] ) !== false ) { $ pos ++ ; } return $ pos ; }
|
the last of any Marks which immediately follow the current glyph
|
2,909
|
public static function getSizeFromName ( $ name ) { $ format = strtoupper ( $ name ) ; $ formats = [ '4A0' => [ 4767.87 , 6740.79 ] , '2A0' => [ 3370.39 , 4767.87 ] , 'A0' => [ 2383.94 , 3370.39 ] , 'A1' => [ 1683.78 , 2383.94 ] , 'A2' => [ 1190.55 , 1683.78 ] , 'A3' => [ 841.89 , 1190.55 ] , 'A4' => [ 595.28 , 841.89 ] , 'A5' => [ 419.53 , 595.28 ] , 'A6' => [ 297.64 , 419.53 ] , 'A7' => [ 209.76 , 297.64 ] , 'A8' => [ 147.40 , 209.76 ] , 'A9' => [ 104.88 , 147.40 ] , 'A10' => [ 73.70 , 104.88 ] , 'B0' => [ 2834.65 , 4008.19 ] , 'B1' => [ 2004.09 , 2834.65 ] , 'B2' => [ 1417.32 , 2004.09 ] , 'B3' => [ 1000.63 , 1417.32 ] , 'B4' => [ 708.66 , 1000.63 ] , 'B5' => [ 498.90 , 708.66 ] , 'B6' => [ 354.33 , 498.90 ] , 'B7' => [ 249.45 , 354.33 ] , 'B8' => [ 175.75 , 249.45 ] , 'B9' => [ 124.72 , 175.75 ] , 'B10' => [ 87.87 , 124.72 ] , 'C0' => [ 2599.37 , 3676.54 ] , 'C1' => [ 1836.85 , 2599.37 ] , 'C2' => [ 1298.27 , 1836.85 ] , 'C3' => [ 918.43 , 1298.27 ] , 'C4' => [ 649.13 , 918.43 ] , 'C5' => [ 459.21 , 649.13 ] , 'C6' => [ 323.15 , 459.21 ] , 'C7' => [ 229.61 , 323.15 ] , 'C8' => [ 161.57 , 229.61 ] , 'C9' => [ 113.39 , 161.57 ] , 'C10' => [ 79.37 , 113.39 ] , 'RA0' => [ 2437.80 , 3458.27 ] , 'RA1' => [ 1729.13 , 2437.80 ] , 'RA2' => [ 1218.90 , 1729.13 ] , 'RA3' => [ 864.57 , 1218.90 ] , 'RA4' => [ 609.45 , 864.57 ] , 'SRA0' => [ 2551.18 , 3628.35 ] , 'SRA1' => [ 1814.17 , 2551.18 ] , 'SRA2' => [ 1275.59 , 1814.17 ] , 'SRA3' => [ 907.09 , 1275.59 ] , 'SRA4' => [ 637.80 , 907.09 ] , 'LETTER' => [ 612.00 , 792.00 ] , 'LEGAL' => [ 612.00 , 1008.00 ] , 'LEDGER' => [ 1224.00 , 792.00 ] , 'TABLOID' => [ 792.00 , 1224.00 ] , 'EXECUTIVE' => [ 521.86 , 756.00 ] , 'FOLIO' => [ 612.00 , 936.00 ] , 'B' => [ 362.83 , 561.26 ] , 'A' => [ 314.65 , 504.57 ] , 'DEMY' => [ 382.68 , 612.28 ] , 'ROYAL' => [ 433.70 , 663.30 ] , ] ; if ( ! isset ( $ formats [ $ format ] ) ) { throw new \ Mpdf \ MpdfException ( sprintf ( 'Unknown page format %s' , $ format ) ) ; } return $ formats [ $ format ] ; }
|
This method returns an array of width and height of given named format .
|
2,910
|
function array_merge_recursive_unique ( $ array1 , $ array2 ) { $ arrays = func_get_args ( ) ; $ narrays = count ( $ arrays ) ; $ ret = $ arrays [ 0 ] ; for ( $ i = 1 ; $ i < $ narrays ; $ i ++ ) { foreach ( $ arrays [ $ i ] as $ key => $ value ) { if ( ( ( string ) $ key ) === ( ( string ) ( ( int ) $ key ) ) ) { $ ret [ ] = $ value ; } else { if ( is_array ( $ value ) && isset ( $ ret [ $ key ] ) ) { $ ret [ $ key ] = $ this -> array_merge_recursive_unique ( $ ret [ $ key ] , $ value ) ; } else { $ ret [ $ key ] = $ value ; } } } } return $ ret ; }
|
for CSS handling
|
2,911
|
function _nthchild ( $ f , $ c ) { $ c += 1 ; $ select = false ; $ f_count = count ( $ f ) ; if ( $ f [ 0 ] === 'ODD' ) { $ a = 2 ; $ b = 1 ; } elseif ( $ f [ 0 ] === 'EVEN' ) { $ a = 2 ; $ b = 0 ; } elseif ( $ f_count === 2 ) { $ a = 0 ; $ b = $ f [ 1 ] + 0 ; } elseif ( $ f_count === 3 ) { if ( $ f [ 2 ] == '' ) { $ a = 1 ; } elseif ( $ f [ 2 ] == '-' ) { $ a = - 1 ; } else { $ a = $ f [ 2 ] + 0 ; } $ b = 0 ; } elseif ( $ f_count === 4 ) { if ( $ f [ 2 ] == '' ) { $ a = 1 ; } elseif ( $ f [ 2 ] == '-' ) { $ a = - 1 ; } else { $ a = $ f [ 2 ] + 0 ; } $ b = $ f [ 3 ] + 0 ; } else { return false ; } if ( $ a > 0 ) { if ( ( ( ( $ c % $ a ) - $ b ) % $ a ) === 0 && $ c >= $ b ) { $ select = true ; } } elseif ( $ a == 0 ) { if ( $ c == $ b ) { $ select = true ; } } else { if ( ( ( ( $ c % $ a ) - $ b ) % $ a ) === 0 && $ c <= $ b ) { $ select = true ; } } return $ select ; }
|
mPDF 5 . 7 . 4 nth - child
|
2,912
|
protected function binseqToArray ( $ seq , array $ barcodeData ) { $ len = strlen ( $ seq ) ; $ w = 0 ; $ k = 0 ; for ( $ i = 0 ; $ i < $ len ; ++ $ i ) { $ w += 1 ; if ( ( $ i == ( $ len - 1 ) ) or ( ( $ i < ( $ len - 1 ) ) and ( $ seq [ $ i ] != $ seq [ ( $ i + 1 ) ] ) ) ) { if ( $ seq [ $ i ] == '1' ) { $ t = true ; } else { $ t = false ; } $ barcodeData [ 'bcode' ] [ $ k ] = [ 't' => $ t , 'w' => $ w , 'h' => 1 , 'p' => 0 ] ; $ barcodeData [ 'maxw' ] += $ w ; ++ $ k ; $ w = 0 ; } } return $ barcodeData ; }
|
Convert binary barcode sequence to barcode array
|
2,913
|
private function checksum ( $ code ) { $ len = strlen ( $ code ) ; $ sum = 0 ; for ( $ i = 0 ; $ i < $ len ; $ i += 2 ) { $ sum += $ code [ $ i ] ; } $ sum *= 3 ; for ( $ i = 1 ; $ i < $ len ; $ i += 2 ) { $ sum += ( $ code [ $ i ] ) ; } $ r = $ sum % 10 ; if ( $ r > 0 ) { $ r = ( 10 - $ r ) ; } return $ r ; }
|
Checksum for standard 2 of 5 barcodes .
|
2,914
|
public function getImportedExternalPageLinks ( $ pageNumber ) { $ links = [ ] ; $ reader = $ this -> getPdfReader ( $ this -> currentReaderId ) ; $ parser = $ reader -> getParser ( ) ; $ page = $ reader -> getPage ( $ pageNumber ) ; $ page -> getPageDictionary ( ) ; $ annotations = $ page -> getAttribute ( 'Annots' ) ; if ( $ annotations instanceof PdfIndirectObjectReference ) { $ annotations = PdfType :: resolve ( $ parser -> getIndirectObject ( $ annotations -> value ) , $ parser ) ; } if ( $ annotations instanceof PdfArray ) { $ getAttribute = function ( $ array , $ key ) { if ( isset ( $ array [ $ key ] -> value ) ) { return $ array [ $ key ] -> value ; } return '' ; } ; foreach ( $ annotations -> value as $ annotation ) { $ annotation = PdfType :: resolve ( $ annotation , $ parser ) -> value ; $ type = $ getAttribute ( $ annotation , 'Type' ) ; $ subtype = $ getAttribute ( $ annotation , 'Subtype' ) ; if ( $ type !== 'Annot' || $ subtype !== 'Link' || ! isset ( $ annotation [ 'A' ] ) ) { continue ; } $ position = $ getAttribute ( $ annotation , 'Rect' ) ; if ( count ( $ position ) !== 4 ) { continue ; } $ x1 = $ getAttribute ( $ position , 0 ) / Mpdf :: SCALE ; $ y1 = $ getAttribute ( $ position , 1 ) / Mpdf :: SCALE ; $ x2 = $ getAttribute ( $ position , 2 ) / Mpdf :: SCALE ; $ y2 = $ getAttribute ( $ position , 3 ) / Mpdf :: SCALE ; $ width = $ x2 - $ x1 ; $ height = $ y2 - $ y1 ; $ link = $ annotation [ 'A' ] instanceof PdfIndirectObjectReference ? PdfType :: resolve ( $ annotation [ 'A' ] , $ parser ) -> value : $ getAttribute ( $ annotation , 'A' ) ; if ( isset ( $ link [ 'URI' ] ) ) { $ links [ ] = [ 'x' => $ x1 , 'y' => $ y1 , 'width' => $ width , 'height' => $ height , 'url' => $ getAttribute ( $ link , 'URI' ) ] ; } } } return $ links ; }
|
Imports the external page links
|
2,915
|
function _checkGSUBignore ( $ flag , $ glyph , $ MarkFilteringSet ) { $ ignore = false ; if ( ( ( $ flag & 0x0008 ) == 0x0008 ) && strpos ( $ this -> GlyphClassMarks , $ glyph ) ) { $ ignore = true ; } if ( ( ( $ flag & 0x0004 ) == 0x0004 ) && strpos ( $ this -> GlyphClassLigatures , $ glyph ) ) { $ ignore = true ; } if ( ( ( $ flag & 0x0002 ) == 0x0002 ) && strpos ( $ this -> GlyphClassBases , $ glyph ) ) { $ ignore = true ; } if ( ( $ flag & 0xFF00 ) && strpos ( $ this -> MarkAttachmentType [ ( $ flag >> 8 ) ] , $ glyph ) ) { $ ignore = true ; } if ( ( $ flag & 0x0010 ) && strpos ( $ this -> MarkGlyphSets [ $ MarkFilteringSet ] , $ glyph ) ) { $ ignore = true ; } return $ ignore ; }
|
mPDF 5 . 7 . 1
|
2,916
|
function getGlyphData ( $ originalGlyphIdx , & $ maxdepth , & $ depth , & $ points , & $ contours ) { $ depth ++ ; $ maxdepth = max ( $ maxdepth , $ depth ) ; if ( count ( $ this -> glyphdata [ $ originalGlyphIdx ] [ 'compGlyphs' ] ) ) { foreach ( $ this -> glyphdata [ $ originalGlyphIdx ] [ 'compGlyphs' ] as $ glyphIdx ) { $ this -> getGlyphData ( $ glyphIdx , $ maxdepth , $ depth , $ points , $ contours ) ; } } else { if ( ( $ this -> glyphdata [ $ originalGlyphIdx ] [ 'nContours' ] > 0 ) && $ depth > 0 ) { $ contours += $ this -> glyphdata [ $ originalGlyphIdx ] [ 'nContours' ] ; $ points += $ this -> glyphdata [ $ originalGlyphIdx ] [ 'nPoints' ] ; } } $ depth -- ; }
|
Recursively get composite glyph data
|
2,917
|
function getGlyphs ( $ originalGlyphIdx , & $ start , & $ glyphSet , & $ subsetglyphs ) { $ glyphPos = $ this -> glyphPos [ $ originalGlyphIdx ] ; $ glyphLen = $ this -> glyphPos [ $ originalGlyphIdx + 1 ] - $ glyphPos ; if ( ! $ glyphLen ) { return ; } $ this -> seek ( $ start + $ glyphPos ) ; $ numberOfContours = $ this -> read_short ( ) ; if ( $ numberOfContours < 0 ) { $ this -> skip ( 8 ) ; $ flags = GlyphOperator :: MORE ; while ( $ flags & GlyphOperator :: MORE ) { $ flags = $ this -> read_ushort ( ) ; } $ glyphIdx = $ this -> read_ushort ( ) ; if ( ! isset ( $ glyphSet [ $ glyphIdx ] ) ) { $ glyphSet [ $ glyphIdx ] = count ( $ subsetglyphs ) ; $ subsetglyphs [ $ glyphIdx ] = true ; } $ savepos = ftell ( $ this -> fh ) ; $ this -> getGlyphs ( $ glyphIdx , $ start , $ glyphSet , $ subsetglyphs ) ; $ this -> seek ( $ savepos ) ; if ( $ flags & GlyphOperator :: WORDS ) { $ this -> skip ( 4 ) ; } else { $ this -> skip ( 2 ) ; } if ( $ flags & GlyphOperator :: SCALE ) { $ this -> skip ( 2 ) ; } else { if ( $ flags & GlyphOperator :: XYSCALE ) { $ this -> skip ( 4 ) ; } else { if ( $ flags & GlyphOperator :: TWOBYTWO ) { $ this -> skip ( 8 ) ; } } } } }
|
Recursively get composite glyphs
|
2,918
|
function getCMAP4 ( $ unicode_cmap_offset , & $ glyphToChar , & $ charToGlyph ) { $ this -> maxUniChar = 0 ; $ this -> seek ( $ unicode_cmap_offset + 2 ) ; $ length = $ this -> read_ushort ( ) ; $ limit = $ unicode_cmap_offset + $ length ; $ this -> skip ( 2 ) ; $ segCount = $ this -> read_ushort ( ) / 2 ; $ this -> skip ( 6 ) ; $ endCount = [ ] ; for ( $ i = 0 ; $ i < $ segCount ; $ i ++ ) { $ endCount [ ] = $ this -> read_ushort ( ) ; } $ this -> skip ( 2 ) ; $ startCount = [ ] ; for ( $ i = 0 ; $ i < $ segCount ; $ i ++ ) { $ startCount [ ] = $ this -> read_ushort ( ) ; } $ idDelta = [ ] ; for ( $ i = 0 ; $ i < $ segCount ; $ i ++ ) { $ idDelta [ ] = $ this -> read_short ( ) ; } $ idRangeOffset_start = $ this -> _pos ; $ idRangeOffset = [ ] ; for ( $ i = 0 ; $ i < $ segCount ; $ i ++ ) { $ idRangeOffset [ ] = $ this -> read_ushort ( ) ; } for ( $ n = 0 ; $ n < $ segCount ; $ n ++ ) { $ endpoint = ( $ endCount [ $ n ] + 1 ) ; for ( $ unichar = $ startCount [ $ n ] ; $ unichar < $ endpoint ; $ unichar ++ ) { if ( $ idRangeOffset [ $ n ] == 0 ) { $ glyph = ( $ unichar + $ idDelta [ $ n ] ) & 0xFFFF ; } else { $ offset = ( $ unichar - $ startCount [ $ n ] ) * 2 + $ idRangeOffset [ $ n ] ; $ offset = $ idRangeOffset_start + 2 * $ n + $ offset ; if ( $ offset >= $ limit ) { $ glyph = 0 ; } else { $ glyph = $ this -> get_ushort ( $ offset ) ; if ( $ glyph != 0 ) { $ glyph = ( $ glyph + $ idDelta [ $ n ] ) & 0xFFFF ; } } } $ charToGlyph [ $ unichar ] = $ glyph ; if ( $ unichar < 196608 ) { $ this -> maxUniChar = max ( $ unichar , $ this -> maxUniChar ) ; } $ glyphToChar [ $ glyph ] [ ] = $ unichar ; } } }
|
CMAP Format 4
|
2,919
|
public function objectKey ( $ n ) { if ( $ this -> useRC128Encryption ) { $ len = 16 ; } else { $ len = 10 ; } return substr ( $ this -> md5toBinary ( $ this -> encryptionKey . pack ( 'VXxx' , $ n ) ) , 0 , $ len ) ; }
|
Compute key depending on object number where the encrypted data is stored
|
2,920
|
public function rc4 ( $ key , $ text ) { if ( $ this -> lastRc4Key != $ key ) { $ k = str_repeat ( $ key , 256 / strlen ( $ key ) + 1 ) ; $ rc4 = range ( 0 , 255 ) ; $ j = 0 ; for ( $ i = 0 ; $ i < 256 ; $ i ++ ) { $ t = $ rc4 [ $ i ] ; $ j = ( $ j + $ t + ord ( $ k [ $ i ] ) ) % 256 ; $ rc4 [ $ i ] = $ rc4 [ $ j ] ; $ rc4 [ $ j ] = $ t ; } $ this -> lastRc4Key = $ key ; $ this -> lastRc4KeyC = $ rc4 ; } else { $ rc4 = $ this -> lastRc4KeyC ; } $ len = strlen ( $ text ) ; $ a = 0 ; $ b = 0 ; $ out = '' ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ a = ( $ a + 1 ) % 256 ; $ t = $ rc4 [ $ a ] ; $ b = ( $ b + $ t ) % 256 ; $ rc4 [ $ a ] = $ rc4 [ $ b ] ; $ rc4 [ $ b ] = $ t ; $ k = $ rc4 [ ( $ rc4 [ $ a ] + $ rc4 [ $ b ] ) % 256 ] ; $ out .= chr ( ord ( $ text [ $ i ] ) ^ $ k ) ; } return $ out ; }
|
RC4 is the standard encryption algorithm used in PDF format
|
2,921
|
function svg_overflow ( $ x , $ y ) { $ x2 = $ x ; $ y2 = $ y ; if ( isset ( $ this -> svg_attribs [ 'overflow' ] ) ) { if ( $ this -> svg_attribs [ 'overflow' ] == 'hidden' ) { $ svg_w = preg_replace ( "/([0-9\.]*)(.*)/i" , "$1" , $ this -> svg_attribs [ 'width' ] ) ; $ svg_h = preg_replace ( "/([0-9\.]*)(.*)/i" , "$1" , $ this -> svg_attribs [ 'height' ] ) ; $ xmax = floor ( $ svg_w ) ; $ xmin = 0 ; $ ymax = floor ( ( $ svg_h * - 1 ) ) ; $ ymin = 0 ; if ( $ x > $ xmax ) { $ x2 = $ xmax ; } if ( $ x < $ xmin ) { $ x2 = $ xmin ; } if ( $ y < $ ymax ) { $ y2 = $ ymax ; } if ( $ y > $ ymin ) { $ y2 = $ ymin ; } } } return [ 'x' => $ x2 , 'y' => $ y2 ] ; }
|
check if points are within svg if not set to max
|
2,922
|
private function fourBytesToInt ( $ s ) { return ( ord ( $ s [ 0 ] ) << 24 ) + ( ord ( $ s [ 1 ] ) << 16 ) + ( ord ( $ s [ 2 ] ) << 8 ) + ord ( $ s [ 3 ] ) ; }
|
Read a 4 - byte integer from string
|
2,923
|
private function imageError ( $ file , $ firsttime , $ msg ) { $ this -> failedImages [ $ file ] = true ; if ( $ firsttime && ( $ this -> mpdf -> showImageErrors || $ this -> mpdf -> debug ) ) { throw new \ Mpdf \ MpdfImageException ( sprintf ( '%s (%s)' , $ msg , $ file ) ) ; } $ this -> logger -> warning ( sprintf ( '%s (%s)' , $ msg , $ file ) , [ 'context' => LogContext :: IMAGES ] ) ; }
|
Throw an exception and save re - trying image URL s which have already failed
|
2,924
|
public static function getTagClassName ( $ tag ) { static $ map = [ 'BARCODE' => 'BarCode' , 'BLOCKQUOTE' => 'BlockQuote' , 'COLUMN_BREAK' => 'ColumnBreak' , 'COLUMNBREAK' => 'ColumnBreak' , 'DOTTAB' => 'DotTab' , 'FIELDSET' => 'FieldSet' , 'FIGCAPTION' => 'FigCaption' , 'FORMFEED' => 'FormFeed' , 'HGROUP' => 'HGroup' , 'INDEXENTRY' => 'IndexEntry' , 'INDEXINSERT' => 'IndexInsert' , 'NEWCOLUMN' => 'NewColumn' , 'NEWPAGE' => 'NewPage' , 'PAGEFOOTER' => 'PageFooter' , 'PAGEHEADER' => 'PageHeader' , 'PAGE_BREAK' => 'PageBreak' , 'PAGEBREAK' => 'PageBreak' , 'SETHTMLPAGEFOOTER' => 'SetHtmlPageFooter' , 'SETHTMLPAGEHEADER' => 'SetHtmlPageHeader' , 'SETPAGEFOOTER' => 'SetPageFooter' , 'SETPAGEHEADER' => 'SetPageHeader' , 'TBODY' => 'TBody' , 'TFOOT' => 'TFoot' , 'THEAD' => 'THead' , 'TEXTAREA' => 'TextArea' , 'TEXTCIRCLE' => 'TextCircle' , 'TOCENTRY' => 'TocEntry' , 'TOCPAGEBREAK' => 'TocPageBreak' , 'VAR' => 'VarTag' , 'WATERMARKIMAGE' => 'WatermarkImage' , 'WATERMARKTEXT' => 'WatermarkText' , ] ; $ className = 'Mpdf\Tag\\' ; $ className .= isset ( $ map [ $ tag ] ) ? $ map [ $ tag ] : ucfirst ( strtolower ( $ tag ) ) ; return $ className ; }
|
Returns the fully qualified name of the class handling the rendering of the given tag
|
2,925
|
function GetFirstBlockFill ( ) { $ startfill = 0 ; for ( $ i = 1 ; $ i <= $ this -> blklvl ; $ i ++ ) { if ( $ this -> blk [ $ i ] [ 'bgcolor' ] || $ this -> blk [ $ i ] [ 'border_left' ] [ 'w' ] || $ this -> blk [ $ i ] [ 'border_right' ] [ 'w' ] || $ this -> blk [ $ i ] [ 'border_top' ] [ 'w' ] || $ this -> blk [ $ i ] [ 'border_bottom' ] [ 'w' ] ) { $ startfill = $ i ; break ; } } return $ startfill ; }
|
Used when ColActive for tables - updated to return first block with background fill OR borders
|
2,926
|
function _moveToPrevChar ( & $ contentctr , & $ charctr , $ content ) { $ lastchar = false ; $ charctr -- ; while ( $ charctr < 0 ) { $ contentctr -- ; if ( $ contentctr < 0 ) { return false ; } if ( $ this -> usingCoreFont ) { $ charctr = strlen ( $ content [ $ contentctr ] ) - 1 ; } else { $ charctr = mb_strlen ( $ content [ $ contentctr ] , $ this -> mb_enc ) - 1 ; } } if ( $ this -> usingCoreFont ) { $ lastchar = $ content [ $ contentctr ] [ $ charctr ] ; } else { $ lastchar = mb_substr ( $ content [ $ contentctr ] , $ charctr , 1 , $ this -> mb_enc ) ; } return $ lastchar ; }
|
Get previous character and move pointers
|
2,927
|
function _advanceFloatMargins ( ) { if ( isset ( $ this -> floatmargins [ 'L' ] ) && $ this -> floatmargins [ 'L' ] [ 'skipline' ] && $ this -> floatmargins [ 'L' ] [ 'y0' ] != $ this -> y ) { $ yadj = $ this -> y - $ this -> floatmargins [ 'L' ] [ 'y0' ] ; $ this -> floatmargins [ 'L' ] [ 'y0' ] = $ this -> y ; $ this -> floatmargins [ 'L' ] [ 'y1' ] += $ yadj ; if ( $ this -> floatbuffer [ $ this -> floatmargins [ 'L' ] [ 'id' ] ] [ 'border_left' ] [ 'w' ] ) { $ this -> floatbuffer [ $ this -> floatmargins [ 'L' ] [ 'id' ] ] [ 'BORDER-Y' ] += $ yadj ; } $ this -> floatbuffer [ $ this -> floatmargins [ 'L' ] [ 'id' ] ] [ 'INNER-Y' ] += $ yadj ; $ this -> floatbuffer [ $ this -> floatmargins [ 'L' ] [ 'id' ] ] [ 'OUTER-Y' ] += $ yadj ; $ this -> floatbuffer [ $ this -> floatmargins [ 'L' ] [ 'id' ] ] [ 'skipline' ] = false ; $ this -> floatmargins [ 'L' ] [ 'skipline' ] = false ; $ this -> floatmargins [ 'L' ] [ 'id' ] = '' ; } if ( isset ( $ this -> floatmargins [ 'R' ] ) && $ this -> floatmargins [ 'R' ] [ 'skipline' ] && $ this -> floatmargins [ 'R' ] [ 'y0' ] != $ this -> y ) { $ yadj = $ this -> y - $ this -> floatmargins [ 'R' ] [ 'y0' ] ; $ this -> floatmargins [ 'R' ] [ 'y0' ] = $ this -> y ; $ this -> floatmargins [ 'R' ] [ 'y1' ] += $ yadj ; if ( $ this -> floatbuffer [ $ this -> floatmargins [ 'R' ] [ 'id' ] ] [ 'border_left' ] [ 'w' ] ) { $ this -> floatbuffer [ $ this -> floatmargins [ 'R' ] [ 'id' ] ] [ 'BORDER-Y' ] += $ yadj ; } $ this -> floatbuffer [ $ this -> floatmargins [ 'R' ] [ 'id' ] ] [ 'INNER-Y' ] += $ yadj ; $ this -> floatbuffer [ $ this -> floatmargins [ 'R' ] [ 'id' ] ] [ 'OUTER-Y' ] += $ yadj ; $ this -> floatbuffer [ $ this -> floatmargins [ 'R' ] [ 'id' ] ] [ 'skipline' ] = false ; $ this -> floatmargins [ 'R' ] [ 'skipline' ] = false ; $ this -> floatmargins [ 'R' ] [ 'id' ] = '' ; } }
|
Update values if set to skipline
|
2,928
|
function writeHTMLHeaders ( ) { if ( $ this -> mirrorMargins && ( $ this -> page ) % 2 == 0 ) { $ OE = 'E' ; } else { $ OE = 'O' ; } if ( $ OE === 'E' ) { $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'html' ] = $ this -> HTMLHeaderE [ 'html' ] ; } else { $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'html' ] = $ this -> HTMLHeader [ 'html' ] ; } if ( $ this -> forcePortraitHeaders && $ this -> CurOrientation == 'L' && $ this -> CurOrientation != $ this -> DefOrientation ) { $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'rotate' ] = true ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'ml' ] = $ this -> tMargin ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'mr' ] = $ this -> bMargin ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'mh' ] = $ this -> margin_header ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'mf' ] = $ this -> margin_footer ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'pw' ] = $ this -> h ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'ph' ] = $ this -> w ; } else { $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'ml' ] = $ this -> lMargin ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'mr' ] = $ this -> rMargin ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'mh' ] = $ this -> margin_header ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'mf' ] = $ this -> margin_footer ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'pw' ] = $ this -> w ; $ this -> saveHTMLHeader [ $ this -> page ] [ $ OE ] [ 'ph' ] = $ this -> h ; } }
|
Called internally from Header
|
2,929
|
function ClearFloats ( $ clear , $ blklvl = 0 ) { list ( $ l_exists , $ r_exists , $ l_max , $ r_max , $ l_width , $ r_width ) = $ this -> GetFloatDivInfo ( $ blklvl , true ) ; $ end = $ currpos = ( $ this -> page * 1000 + $ this -> y ) ; if ( $ clear == 'BOTH' && ( $ l_exists || $ r_exists ) ) { $ this -> pageoutput [ $ this -> page ] = [ ] ; $ end = max ( $ l_max , $ r_max , $ currpos ) ; } elseif ( $ clear == 'RIGHT' && $ r_exists ) { $ this -> pageoutput [ $ this -> page ] = [ ] ; $ end = max ( $ r_max , $ currpos ) ; } elseif ( $ clear == 'LEFT' && $ l_exists ) { $ this -> pageoutput [ $ this -> page ] = [ ] ; $ end = max ( $ l_max , $ currpos ) ; } else { return ; } $ old_page = $ this -> page ; $ new_page = intval ( $ end / 1000 ) ; if ( $ old_page != $ new_page ) { $ s = $ this -> PrintPageBackgrounds ( ) ; $ this -> pages [ $ this -> page ] = preg_replace ( '/( BACKGROUND PATTERNS' . $ this -> uniqstr . ')/' , '\\1' . "\n" . $ s . "\n" , $ this -> pages [ $ this -> page ] ) ; $ this -> pageBackgrounds = [ ] ; $ this -> page = $ new_page ; } $ this -> ResetMargins ( ) ; $ this -> pageoutput [ $ this -> page ] = [ ] ; $ this -> y = ( ( $ end * 1000 ) % 1000000 ) / 1000 ; }
|
Added mPDF 3 . 0 Float DIV - CLEAR
|
2,930
|
function GetFloatDivInfo ( $ blklvl = 0 , $ clear = false ) { $ l_exists = false ; $ r_exists = false ; $ l_max = 0 ; $ r_max = 0 ; $ l_width = 0 ; $ r_width = 0 ; if ( count ( $ this -> floatDivs ) ) { $ currpos = ( $ this -> page * 1000 + $ this -> y ) ; foreach ( $ this -> floatDivs as $ f ) { if ( ( $ clear && $ f [ 'blockContext' ] == $ this -> blk [ $ blklvl ] [ 'blockContext' ] ) || ( ! $ clear && $ currpos >= $ f [ 'startpos' ] && $ currpos < ( $ f [ 'endpos' ] - 0.001 ) && $ f [ 'blklvl' ] > $ blklvl && $ f [ 'blockContext' ] == $ this -> blk [ $ blklvl ] [ 'blockContext' ] ) ) { if ( $ f [ 'side' ] == 'L' ) { $ l_exists = true ; $ l_max = max ( $ l_max , $ f [ 'endpos' ] ) ; $ l_width = max ( $ l_width , $ f [ 'w' ] ) ; } if ( $ f [ 'side' ] == 'R' ) { $ r_exists = true ; $ r_max = max ( $ r_max , $ f [ 'endpos' ] ) ; $ r_width = max ( $ r_width , $ f [ 'w' ] ) ; } } } } return [ $ l_exists , $ r_exists , $ l_max , $ r_max , $ l_width , $ r_width ] ; }
|
Added mPDF 3 . 0 Float DIV
|
2,931
|
function SetStylesArray ( $ arr ) { $ style = '' ; foreach ( [ 'B' , 'I' ] as $ s ) { if ( isset ( $ arr [ $ s ] ) ) { if ( $ arr [ $ s ] ) { $ this -> $ s = true ; $ style .= $ s ; } else { $ this -> $ s = false ; } } elseif ( $ this -> $ s ) { $ style .= $ s ; } } $ this -> currentfontstyle = $ style ; $ this -> SetFont ( '' , $ style , 0 , false ) ; }
|
Set multiple styles at one time
|
2,932
|
function Bookmark ( $ txt , $ level = 0 , $ y = 0 ) { $ txt = $ this -> purify_utf8_text ( $ txt ) ; if ( $ this -> text_input_as_HTML ) { $ txt = $ this -> all_entities_to_utf8 ( $ txt ) ; } if ( $ y == - 1 ) { if ( ! $ this -> ColActive ) { $ y = $ this -> y ; } else { $ y = $ this -> y0 ; } } $ bmo = [ 't' => $ txt , 'l' => $ level , 'y' => $ y , 'p' => $ this -> page ] ; if ( $ this -> keep_block_together ) { } elseif ( $ this -> table_rotate ) { $ this -> tbrot_BMoutlines [ ] = $ bmo ; } elseif ( $ this -> kwt ) { $ this -> kwt_BMoutlines [ ] = $ bmo ; } elseif ( $ this -> ColActive ) { $ this -> col_BMoutlines [ ] = $ bmo ; } else { $ this -> BMoutlines [ ] = $ bmo ; } }
|
FROM class PDF_Bookmark
|
2,933
|
function IndexEntry ( $ txt , $ xref = '' ) { if ( $ xref ) { $ this -> IndexEntrySee ( $ txt , $ xref ) ; return ; } $ Present = false ; if ( $ this -> keep_block_together ) { } elseif ( $ this -> kwt ) { $ size = count ( $ this -> kwt_Reference ) ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { if ( isset ( $ this -> kwt_Reference [ $ i ] [ 't' ] ) && $ this -> kwt_Reference [ $ i ] [ 't' ] == $ txt ) { $ Present = true ; if ( $ this -> page != $ this -> kwt_Reference [ $ i ] [ 'op' ] ) { $ this -> kwt_Reference [ $ i ] [ 'op' ] = $ this -> page ; } } } if ( ! $ Present ) { $ this -> kwt_Reference [ ] = [ 't' => $ txt , 'op' => $ this -> page ] ; } } else { $ size = count ( $ this -> Reference ) ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) { if ( isset ( $ this -> Reference [ $ i ] [ 't' ] ) && $ this -> Reference [ $ i ] [ 't' ] == $ txt ) { $ Present = true ; if ( ! in_array ( $ this -> page , $ this -> Reference [ $ i ] [ 'p' ] ) ) { $ this -> Reference [ $ i ] [ 'p' ] [ ] = $ this -> page ; } } } if ( ! $ Present ) { $ this -> Reference [ ] = [ 't' => $ txt , 'p' => [ $ this -> page ] ] ; } } }
|
FROM class PDF_Ref == INDEX
|
2,934
|
function IndexEntrySee ( $ txta , $ txtb ) { if ( $ this -> directionality == 'rtl' ) { if ( $ txta == strip_tags ( $ txta ) ) { $ txta = str_replace ( ':' , ' - ' , $ txta ) ; } if ( $ txtb == strip_tags ( $ txtb ) ) { $ txtb = str_replace ( ':' , ' - ' , $ txtb ) ; } } else { if ( $ txta == strip_tags ( $ txta ) ) { $ txta = str_replace ( ':' , ', ' , $ txta ) ; } if ( $ txtb == strip_tags ( $ txtb ) ) { $ txtb = str_replace ( ':' , ', ' , $ txtb ) ; } } $ this -> Reference [ ] = [ 't' => $ txta . ' - see ' . $ txtb , 'p' => [ ] ] ; }
|
Added function to add a reference Elephants . See Chickens
|
2,935
|
function is_utf8 ( & $ string ) { if ( $ string === mb_convert_encoding ( mb_convert_encoding ( $ string , "UTF-32" , "UTF-8" ) , "UTF-8" , "UTF-32" ) ) { return true ; } if ( $ this -> ignore_invalid_utf8 ) { $ string = mb_convert_encoding ( mb_convert_encoding ( $ string , "UTF-32" , "UTF-8" ) , "UTF-8" , "UTF-32" ) ; return true ; } return false ; }
|
Edited v1 . 2 Pass by reference ; option to continue if invalid UTF - 8 chars
|
2,936
|
function columnAdjustAdd ( $ type , $ k , $ xadj , $ yadj , $ a , $ b , $ c = 0 , $ d = 0 , $ e = 0 , $ f = 0 ) { if ( $ type === 'Td' ) { $ a += ( $ xadj * $ k ) ; $ b -= ( $ yadj * $ k ) ; return 'BT ' . sprintf ( '%.3F %.3F' , $ a , $ b ) . ' Td' ; } elseif ( $ type === 're' ) { $ a += ( $ xadj * $ k ) ; $ b -= ( $ yadj * $ k ) ; return sprintf ( '%.3F %.3F %.3F %.3F' , $ a , $ b , $ c , $ d ) . ' re' ; } elseif ( $ type === 'l' ) { $ a += ( $ xadj * $ k ) ; $ b -= ( $ yadj * $ k ) ; return sprintf ( '%.3F %.3F l' , $ a , $ b ) ; } elseif ( $ type === 'img' ) { $ c += ( $ xadj * $ k ) ; $ d -= ( $ yadj * $ k ) ; return sprintf ( 'q %.3F 0 0 %.3F %.3F %.3F' , $ a , $ b , $ c , $ d ) . ' cm /' . $ e ; } elseif ( $ type === 'draw' ) { $ a += ( $ xadj * $ k ) ; $ b -= ( $ yadj * $ k ) ; return sprintf ( '%.3F %.3F m' , $ a , $ b ) ; } elseif ( $ type === 'bezier' ) { $ a += ( $ xadj * $ k ) ; $ b -= ( $ yadj * $ k ) ; $ c += ( $ xadj * $ k ) ; $ d -= ( $ yadj * $ k ) ; $ e += ( $ xadj * $ k ) ; $ f -= ( $ yadj * $ k ) ; return sprintf ( '%.3F %.3F %.3F %.3F %.3F %.3F' , $ a , $ b , $ c , $ d , $ e , $ f ) . ' c' ; } }
|
Callback function from function printcolumnbuffer in mpdf
|
2,937
|
private function imbCrc11Fcs ( $ codeArray ) { $ genpoly = 0x0F35 ; $ fcs = 0x07FF ; $ data = hexdec ( $ codeArray [ 0 ] ) << 5 ; for ( $ bit = 2 ; $ bit < 8 ; ++ $ bit ) { if ( ( $ fcs ^ $ data ) & 0x400 ) { $ fcs = ( $ fcs << 1 ) ^ $ genpoly ; } else { $ fcs = ( $ fcs << 1 ) ; } $ fcs &= 0x7FF ; $ data <<= 1 ; } for ( $ byte = 1 ; $ byte < 13 ; ++ $ byte ) { $ data = hexdec ( $ codeArray [ $ byte ] ) << 3 ; for ( $ bit = 0 ; $ bit < 8 ; ++ $ bit ) { if ( ( $ fcs ^ $ data ) & 0x400 ) { $ fcs = ( $ fcs << 1 ) ^ $ genpoly ; } else { $ fcs = ( $ fcs << 1 ) ; } $ fcs &= 0x7FF ; $ data <<= 1 ; } } return $ fcs ; }
|
Intelligent Mail Barcode calculation of Frame Check Sequence
|
2,938
|
private function imbReverseUs ( $ num ) { $ rev = 0 ; for ( $ i = 0 ; $ i < 16 ; ++ $ i ) { $ rev <<= 1 ; $ rev |= ( $ num & 1 ) ; $ num >>= 1 ; } return $ rev ; }
|
Reverse unsigned short value
|
2,939
|
private function imbTables ( $ n , $ size ) { $ table = [ ] ; $ lli = 0 ; $ lui = $ size - 1 ; for ( $ count = 0 ; $ count < 8192 ; ++ $ count ) { $ bitCount = 0 ; for ( $ bit_index = 0 ; $ bit_index < 13 ; ++ $ bit_index ) { $ bitCount += ( int ) ( ( $ count & ( 1 << $ bit_index ) ) != 0 ) ; } if ( $ bitCount == $ n ) { $ reverse = ( $ this -> imbReverseUs ( $ count ) >> 3 ) ; if ( $ reverse >= $ count ) { if ( $ reverse == $ count ) { $ table [ $ lui ] = $ count ; -- $ lui ; } else { $ table [ $ lli ] = $ count ; ++ $ lli ; $ table [ $ lli ] = $ reverse ; ++ $ lli ; } } } } return $ table ; }
|
Generate Nof13 tables used for Intelligent Mail Barcode
|
2,940
|
private function decToHex ( $ number ) { $ hex = [ ] ; if ( $ number == 0 ) { return '00' ; } while ( $ number > 0 ) { if ( $ number == 0 ) { array_push ( $ hex , '0' ) ; } else { array_push ( $ hex , strtoupper ( dechex ( bcmod ( $ number , '16' ) ) ) ) ; $ number = bcdiv ( $ number , '16' , 0 ) ; } } $ hex = array_reverse ( $ hex ) ; return implode ( $ hex ) ; }
|
Convert large integer number to hexadecimal representation .
|
2,941
|
public function subscriberByRequest ( array $ input , array $ headers ) : ? Subscriber { $ channel = Arr :: get ( $ input , 'channel_name' ) ; return $ channel ? $ this -> subscriberByChannel ( $ channel ) : null ; }
|
Get subscriber by request .
|
2,942
|
public function subscriberByChannel ( string $ channel ) : ? Subscriber { $ key = self :: SUBSCRIBER_KEY . ".{$channel}" ; return $ this -> cache -> get ( $ key ) ; }
|
Find subscriber by channel .
|
2,943
|
public function subscribersByTopic ( string $ topic ) { $ key = self :: TOPIC_KEY . ".{$topic}" ; if ( ! $ this -> cache -> has ( $ key ) ) { return new Collection ; } $ channels = json_decode ( $ this -> cache -> get ( $ key ) , true ) ; return ( new Collection ( $ channels ) ) -> map ( function ( string $ channel ) : ? Subscriber { return $ this -> subscriberByChannel ( $ channel ) ; } ) -> filter ( ) -> values ( ) ; }
|
Get collection of subscribers by channel .
|
2,944
|
public function storeSubscriber ( Subscriber $ subscriber , string $ topic ) : void { $ topicKey = self :: TOPIC_KEY . ".{$topic}" ; $ subscriberKey = self :: SUBSCRIBER_KEY . ".{$subscriber->channel}" ; $ topic = $ this -> cache -> has ( $ topicKey ) ? json_decode ( $ this -> cache -> get ( $ topicKey ) , true ) : [ ] ; $ topic [ ] = $ subscriber -> channel ; $ this -> cache -> forever ( $ topicKey , json_encode ( $ topic ) ) ; $ this -> cache -> forever ( $ subscriberKey , $ subscriber ) ; }
|
Store subscription .
|
2,945
|
public function deleteSubscriber ( string $ channel ) : ? Subscriber { $ key = self :: SUBSCRIBER_KEY . ".{$channel}" ; $ hasSubscriber = $ this -> cache -> has ( $ key ) ; $ subscriber = $ this -> cache -> get ( $ key ) ; if ( $ hasSubscriber ) { $ this -> cache -> forget ( $ key ) ; } return $ subscriber ; }
|
Delete subscriber .
|
2,946
|
protected static function gatherSchemaImportsRecursively ( string $ path ) : string { if ( ! file_exists ( $ path ) ) { self :: throwFileNotFoundException ( $ path ) ; } return ( new Collection ( file ( $ path ) ) ) -> map ( function ( string $ line ) use ( $ path ) { if ( ! Str :: startsWith ( trim ( $ line ) , '#import ' ) ) { return rtrim ( $ line , PHP_EOL ) . PHP_EOL ; } $ importFileName = trim ( Str :: after ( $ line , '#import ' ) ) ; $ importFilePath = dirname ( $ path ) . '/' . $ importFileName ; if ( ! Str :: contains ( $ importFileName , '*' ) ) { $ realPath = realpath ( $ importFilePath ) ; if ( ! $ realPath ) { self :: throwFileNotFoundException ( $ importFilePath ) ; } return self :: gatherSchemaImportsRecursively ( $ realPath ) ; } $ importFilePaths = glob ( $ importFilePath ) ; return ( new Collection ( $ importFilePaths ) ) -> map ( function ( $ file ) { return self :: gatherSchemaImportsRecursively ( $ file ) ; } ) -> implode ( '' ) ; } ) -> implode ( '' ) ; }
|
Get the schema starting from a root schema following the imports recursively .
|
2,947
|
protected function store ( CacheManager $ cache , string $ key , $ value , ? Carbon $ expiration , array $ tags ) : void { $ supportsTags = $ this -> useTags ( $ cache ) ; if ( $ expiration ) { $ supportsTags ? $ cache -> tags ( $ tags ) -> put ( $ key , $ value , $ expiration ) : $ cache -> put ( $ key , $ value , $ expiration ) ; return ; } $ supportsTags ? $ cache -> tags ( $ tags ) -> forever ( $ key , $ value ) : $ cache -> forever ( $ key , $ value ) ; }
|
Store value in cache .
|
2,948
|
protected function setNodeKey ( NodeValue $ nodeValue ) : void { if ( $ nodeValue -> getCacheKey ( ) ) { return ; } $ fields = data_get ( $ nodeValue -> getTypeDefinition ( ) , 'fields' , [ ] ) ; $ nodeKey = ( new Collection ( $ fields ) ) -> reduce ( function ( ? string $ key , FieldDefinitionNode $ field ) : ? string { if ( $ key ) { return $ key ; } $ hasCacheKey = ( new Collection ( $ field -> directives ) ) -> contains ( function ( DirectiveNode $ directive ) : bool { return $ directive -> name -> value === 'cacheKey' ; } ) ; return $ hasCacheKey ? $ field -> name -> value : $ key ; } ) ; if ( ! $ nodeKey ) { $ nodeKey = ( new Collection ( $ fields ) ) -> reduce ( function ( ? string $ key , FieldDefinitionNode $ field ) : ? string { if ( $ key ) { return $ key ; } $ typeName = ASTHelper :: getUnderlyingTypeName ( $ field ) ; return $ typeName === 'ID' ? $ field -> name -> value : $ key ; } ) ; } if ( ! $ nodeKey && $ nodeValue -> getTypeDefinitionName ( ) !== 'Query' ) { throw new DirectiveException ( "No @cacheKey or ID field defined on {$nodeValue->getTypeDefinitionName()}" ) ; } $ nodeValue -> setCacheKey ( $ nodeKey ) ; }
|
Set node s cache key .
|
2,949
|
public function apply ( $ builder , array $ args ) { $ this -> queryFilter -> filter ( $ builder , $ args ) ; foreach ( $ args as $ key => $ value ) { if ( $ builderDirective = Arr :: get ( $ this -> builderDirectives , $ key ) ) { $ builder = $ builderDirective -> handleBuilder ( $ builder , $ value ) ; } } foreach ( $ this -> scopes as $ scope ) { call_user_func ( [ $ builder , $ scope ] , $ args ) ; } return $ builder ; }
|
Apply the bound QueryBuilderDirectives to the given builder .
|
2,950
|
public function addScopes ( array $ scopes ) : self { $ this -> scopes = array_merge ( $ this -> scopes , $ scopes ) ; return $ this ; }
|
Add scopes that are then called upon the query with the field arguments .
|
2,951
|
public function addBuilderDirective ( string $ argumentName , ArgBuilderDirective $ argBuilderDirective ) : self { $ this -> builderDirectives [ $ argumentName ] = $ argBuilderDirective ; return $ this ; }
|
Add a query builder directive keyed by the argument name .
|
2,952
|
protected function fieldValue ( string $ key ) { return $ this -> isBatched ( ) ? Arr :: get ( $ this -> operations , $ this -> batchIndex . '.' . $ key ) : $ this -> operations [ $ key ] ?? null ; }
|
If we are dealing with a batched request this gets the contents of the currently resolving batch index .
|
2,953
|
public function queueBroadcast ( GraphQLSubscription $ subscription , string $ fieldName , $ root ) : void { $ this -> eventsDispatcher -> dispatch ( new BroadcastSubscriptionEvent ( $ subscription , $ fieldName , $ root ) ) ; }
|
Queue pushing subscription data to subscribers .
|
2,954
|
public function broadcast ( GraphQLSubscription $ subscription , string $ fieldName , $ root ) : void { $ topic = $ subscription -> decodeTopic ( $ fieldName , $ root ) ; $ subscribers = $ this -> storage -> subscribersByTopic ( $ topic ) -> filter ( function ( Subscriber $ subscriber ) use ( $ subscription , $ root ) : bool { return $ subscription -> filter ( $ subscriber , $ root ) ; } ) ; $ this -> iterator -> process ( $ subscribers , function ( Subscriber $ subscriber ) use ( $ root ) : void { $ data = $ this -> graphQL -> executeQuery ( $ subscriber -> query , $ subscriber -> context , $ subscriber -> args , $ subscriber -> setRoot ( $ root ) , $ subscriber -> operationName ) ; $ this -> broadcastManager -> broadcast ( $ subscriber , $ data -> jsonSerialize ( ) ) ; } ) ; }
|
Push subscription data to subscribers .
|
2,955
|
public function authorize ( Request $ request ) : Response { return $ this -> auth -> authorize ( $ request ) ? $ this -> broadcastManager -> authorized ( $ request ) : $ this -> broadcastManager -> unauthorized ( $ request ) ; }
|
Authorize the subscription .
|
2,956
|
public function handleStartRequest ( StartRequest $ startRequest ) : void { $ this -> requestStart = Carbon :: now ( ) ; $ this -> requestStartPrecise = $ this -> getTime ( ) ; }
|
Handle request start .
|
2,957
|
public function handleBuildExtensionsResponse ( BuildExtensionsResponse $ buildExtensionsResponse ) : ExtensionsResponse { $ requestEnd = Carbon :: now ( ) ; $ requestEndPrecise = $ this -> getTime ( ) ; return new ExtensionsResponse ( 'tracing' , [ 'version' => 1 , 'startTime' => $ this -> requestStart -> format ( Carbon :: RFC3339_EXTENDED ) , 'endTime' => $ requestEnd -> format ( Carbon :: RFC3339_EXTENDED ) , 'duration' => $ this -> diffTimeInNanoseconds ( $ this -> requestStartPrecise , $ requestEndPrecise ) , 'execution' => [ 'resolvers' => $ this -> resolverTraces , ] , ] ) ; }
|
Return additional information for the result .
|
2,958
|
public function record ( ResolveInfo $ resolveInfo , $ start , $ end ) : void { $ this -> resolverTraces [ ] = [ 'path' => $ resolveInfo -> path , 'parentType' => $ resolveInfo -> parentType -> name , 'returnType' => $ resolveInfo -> returnType -> __toString ( ) , 'fieldName' => $ resolveInfo -> fieldName , 'startOffset' => $ this -> diffTimeInNanoseconds ( $ this -> requestStartPrecise , $ start ) , 'duration' => $ this -> diffTimeInNanoseconds ( $ start , $ end ) , ] ; }
|
Record resolver execution time .
|
2,959
|
protected function diffTimeInNanoseconds ( $ start , $ end ) : int { if ( $ this -> platformSupportsNanoseconds ( ) ) { return $ end - $ start ; } return ( int ) ( ( $ end - $ start ) * 1000 * 1000 * 1000 ) ; }
|
Diff the time results to each other and convert to nanoseconds if needed .
|
2,960
|
public function serialize ( $ value ) : string { if ( $ value instanceof Carbon ) { return $ value -> toDateString ( ) ; } return $ this -> tryParsingDate ( $ value , InvariantViolation :: class ) -> toDateString ( ) ; }
|
Serialize an internal value ensuring it is a valid date string .
|
2,961
|
public function getKey ( ) : string { $ argKeys = $ this -> argKeys ( ) ; return $ this -> implode ( [ $ this -> privateCache ? 'auth' : null , $ this -> privateCache ? app ( 'auth' ) -> user ( ) -> getKey ( ) : null , strtolower ( $ this -> resolveInfo -> parentType -> name ) , $ this -> fieldKey , strtolower ( $ this -> resolveInfo -> fieldName ) , $ argKeys -> isNotEmpty ( ) ? $ argKeys -> implode ( ':' ) : null , ] ) ; }
|
Resolve key from root value .
|
2,962
|
public function getTags ( ) : array { $ typeTag = $ this -> implode ( [ 'graphql' , strtolower ( $ this -> fieldValue -> getParentName ( ) ) , $ this -> fieldKey , ] ) ; $ fieldTag = $ this -> implode ( [ 'graphql' , strtolower ( $ this -> fieldValue -> getParentName ( ) ) , $ this -> fieldKey , $ this -> resolveInfo -> fieldName , ] ) ; return [ $ typeTag , $ fieldTag ] ; }
|
Get cache tags .
|
2,963
|
protected function argKeys ( ) : Collection { $ args = $ this -> args ; ksort ( $ args ) ; return ( new Collection ( $ args ) ) -> map ( function ( $ value , $ key ) { $ keyValue = is_array ( $ value ) ? json_encode ( $ value , true ) : $ value ; return "{$key}:{$keyValue}" ; } ) ; }
|
Convert input arguments to keys .
|
2,964
|
protected function setFieldKey ( ) { if ( ! $ this -> fieldValue || ! $ this -> rootValue ) { return ; } $ cacheFieldKey = $ this -> fieldValue -> getParent ( ) -> getCacheKey ( ) ; if ( $ cacheFieldKey ) { $ this -> fieldKey = data_get ( $ this -> rootValue , $ cacheFieldKey ) ; } }
|
Set the field key .
|
2,965
|
public function setResolverArguments ( $ root , array $ args , GraphQLContext $ context , ResolveInfo $ resolveInfo ) : self { return $ this -> setRoot ( $ root ) -> setArgs ( $ args ) -> setContext ( $ context ) -> setResolveInfo ( $ resolveInfo ) ; }
|
Set all resolver arguments at once .
|
2,966
|
public static function namespaceClassname ( string $ classCandidate , array $ namespacesToTry , callable $ determineMatch ) : ? string { if ( $ determineMatch ( $ classCandidate ) ) { return $ classCandidate ; } while ( ! empty ( $ namespacesToTry ) ) { $ className = array_shift ( $ namespacesToTry ) . '\\' . $ classCandidate ; if ( $ determineMatch ( $ className ) ) { return $ className ; } } return null ; }
|
Attempt to find a given class in the given namespaces .
|
2,967
|
public static function constructResolver ( string $ className , string $ methodName ) : Closure { if ( ! method_exists ( $ className , $ methodName ) ) { throw new DefinitionException ( "Method '{$methodName}' does not exist on class '{$className}'" ) ; } return Closure :: fromCallable ( [ app ( $ className ) , $ methodName ] ) ; }
|
Construct a closure that passes through the arguments .
|
2,968
|
public function defer ( Closure $ resolver , string $ path ) { if ( $ data = Arr :: get ( $ this -> result , "data.{$path}" ) ) { return $ data ; } if ( $ this -> isDeferred ( $ path ) || ! $ this -> acceptFurtherDeferring ) { return $ this -> resolve ( $ resolver , $ path ) ; } $ this -> deferred [ $ path ] = $ resolver ; }
|
Register deferred field .
|
2,969
|
public function resolve ( Closure $ originalResolver , string $ path ) { $ isDeferred = $ this -> isDeferred ( $ path ) ; $ resolver = $ isDeferred ? $ this -> deferred [ $ path ] : $ originalResolver ; if ( $ isDeferred ) { $ this -> resolved [ ] = $ path ; unset ( $ this -> deferred [ $ path ] ) ; } return $ resolver ( ) ; }
|
Resolve field with data or resolver .
|
2,970
|
public function createResponse ( array $ result ) : Response { if ( empty ( $ this -> deferred ) ) { return response ( $ result ) ; } return response ( ) -> stream ( function ( ) use ( $ result ) : void { $ nested = 1 ; $ this -> result = $ result ; $ this -> isStreaming = true ; $ this -> stream -> stream ( $ result , [ ] , empty ( $ this -> deferred ) ) ; if ( $ executionTime = config ( 'lighthouse.defer.max_execution_ms' , 0 ) ) { $ this -> maxExecutionTime = microtime ( true ) + ( $ executionTime * 1000 ) ; } while ( count ( $ this -> deferred ) && ! $ this -> executionTimeExpired ( ) && ! $ this -> maxNestedFieldsResolved ( $ nested ) ) { $ nested ++ ; $ this -> executeDeferred ( ) ; } if ( count ( $ this -> deferred ) ) { $ this -> acceptFurtherDeferring = false ; $ this -> executeDeferred ( ) ; } } , 200 , [ 'X-Accel-Buffering' => 'no' , 'Content-Type' => 'multipart/mixed; boundary="-"' , ] ) ; }
|
Return either a final response or a stream of responses .
|
2,971
|
protected function maxNestedFieldsResolved ( int $ nested ) : bool { if ( $ this -> maxNestedFields === 0 ) { return false ; } return $ nested >= $ this -> maxNestedFields ; }
|
Check if the maximum number of nested field has been resolved .
|
2,972
|
protected function executeDeferred ( ) : void { $ this -> result = app ( ) -> call ( [ $ this -> graphQL , 'executeRequest' ] ) ; $ this -> stream -> stream ( $ this -> result , $ this -> resolved , empty ( $ this -> deferred ) ) ; $ this -> resolved = [ ] ; }
|
Execute deferred fields .
|
2,973
|
protected function getSingleArgumentDefinition ( ) : InputValueDefinitionNode { if ( count ( $ this -> definitionNode -> arguments ) !== 1 ) { throw new DirectiveException ( "The @delete directive requires the field {$this->definitionNode->name->value} to only contain a single argument." ) ; } return $ this -> definitionNode -> arguments [ 0 ] ; }
|
Ensure there is only a single argument defined on the field .
|
2,974
|
public function build ( string $ schema ) : DocumentAST { $ document = DocumentAST :: fromSource ( $ schema ) ; $ document = $ this -> applyNodeManipulators ( $ document ) ; $ document = $ this -> mergeTypeExtensions ( $ document ) ; $ document = $ this -> applyFieldManipulators ( $ document ) ; $ document = $ this -> applyArgManipulators ( $ document ) ; $ document = $ this -> addPaginationInfoTypes ( $ document ) ; $ document = $ this -> addOrderByTypes ( $ document ) ; return $ this -> addNodeSupport ( $ document ) ; }
|
Convert the base schema string into an AST by applying different manipulations .
|
2,975
|
protected function mergeTypeExtensions ( DocumentAST $ document ) : DocumentAST { $ document -> objectTypeDefinitions ( ) -> each ( function ( ObjectTypeDefinitionNode $ objectType ) use ( $ document ) { $ name = $ objectType -> name -> value ; $ objectType = $ document -> extensionsForType ( $ name ) -> reduce ( function ( ObjectTypeDefinitionNode $ relatedObjectType , ObjectTypeExtensionNode $ typeExtension ) : ObjectTypeDefinitionNode { $ relatedObjectType -> fields = ASTHelper :: mergeUniqueNodeList ( $ relatedObjectType -> fields , $ typeExtension -> fields ) ; return $ relatedObjectType ; } , $ objectType ) ; $ document -> setDefinition ( $ objectType ) ; } ) ; return $ document ; }
|
The final schema must not contain type extensions so we merge them here .
|
2,976
|
protected function addNodeSupport ( DocumentAST $ document ) : DocumentAST { $ hasTypeImplementingNode = $ document -> objectTypeDefinitions ( ) -> contains ( function ( ObjectTypeDefinitionNode $ objectType ) : bool { return ( new Collection ( $ objectType -> interfaces ) ) -> contains ( function ( NamedTypeNode $ interface ) : bool { return $ interface -> name -> value === 'Node' ; } ) ; } ) ; if ( ! $ hasTypeImplementingNode ) { return $ document ; } $ globalId = config ( 'lighthouse.global_id_field' ) ; return $ document -> setDefinition ( PartialParser :: interfaceTypeDefinition ( <<<GRAPHQL"Node global interface" interface Node @interface(resolveType: "Nuwave\\\Lighthouse\\\Schema\\\NodeRegistry@resolveType") { "Global identifier that can be used to resolve any Node implementation." $globalId: ID! } GRAPHQL ) ) -> addFieldToQueryType ( PartialParser :: fieldDefinition ( 'node(id: ID! @globalId): Node @field(resolver: "Nuwave\\\Lighthouse\\\Schema\\\NodeRegistry@resolve")' ) ) ; }
|
Inject the node type and a node field into Query .
|
2,977
|
public function unserialize ( $ subscription ) : self { $ data = json_decode ( $ subscription , true ) ; $ this -> operationName = $ data [ 'operation_name' ] ; $ this -> channel = $ data [ 'channel' ] ; $ this -> args = $ data [ 'args' ] ; $ this -> context = $ this -> contextSerializer ( ) -> unserialize ( $ data [ 'context' ] ) ; $ this -> query = AST :: fromArray ( unserialize ( $ data [ 'query' ] ) ) ; return $ this ; }
|
Unserialize subscription from a JSON string .
|
2,978
|
public function serialize ( ) { return json_encode ( [ 'operation_name' => $ this -> operationName , 'channel' => $ this -> channel , 'args' => $ this -> args , 'context' => $ this -> contextSerializer ( ) -> serialize ( $ this -> context ) , 'query' => serialize ( AST :: toArray ( $ this -> query ) ) , ] ) ; }
|
Convert this into a JSON string .
|
2,979
|
public function query ( GraphQLRequest $ request ) { $ this -> eventsDispatcher -> dispatch ( new StartRequest ( $ request ) ) ; $ result = $ request -> isBatched ( ) ? $ this -> executeBatched ( $ request ) : $ this -> graphQL -> executeRequest ( $ request ) ; $ response = $ this -> createsResponse -> createResponse ( $ result ) ; $ this -> container -> forgetInstance ( GraphQLRequest :: class ) ; return $ response ; }
|
Execute GraphQL query .
|
2,980
|
protected function executeBatched ( GraphQLRequest $ request ) : array { $ results = [ ] ; do { $ results [ ] = $ this -> graphQL -> executeRequest ( $ request ) ; } while ( $ request -> advanceBatchIndex ( ) ) ; return $ results ; }
|
Loop through the individual batched queries and collect the results .
|
2,981
|
public function decodeID ( string $ globalID ) : string { [ $ type , $ id ] = self :: decode ( $ globalID ) ; return $ id ; }
|
Decode the Global ID and get just the ID .
|
2,982
|
public function decodeType ( string $ globalID ) : string { [ $ type , $ id ] = self :: decode ( $ globalID ) ; return $ type ; }
|
Decode the Global ID and get just the type .
|
2,983
|
public function setRelations ( array $ relations ) : self { $ this -> relations = $ this -> newModelQuery ( ) -> with ( $ relations ) -> getEagerLoads ( ) ; return $ this ; }
|
Set the relations to be loaded .
|
2,984
|
protected function setModels ( $ models ) : self { $ this -> models = $ models instanceof EloquentCollection ? $ models : new EloquentCollection ( $ models ) ; return $ this ; }
|
Set one or more Model instances as an EloquentCollection .
|
2,985
|
public function loadRelationsForPage ( int $ perPage , int $ page = 1 ) : self { foreach ( $ this -> relations as $ name => $ constraints ) { $ this -> loadRelationForPage ( $ perPage , $ page , $ name , $ constraints ) ; } return $ this ; }
|
Load all relations for the model but constrain the query to the current page .
|
2,986
|
public function loadRelationForPage ( int $ first , int $ page , string $ relationName , Closure $ relationConstraints ) : self { $ this -> reloadModelsWithRelationCount ( ) ; $ relations = $ this -> buildRelationsFromModels ( $ relationName , $ relationConstraints ) -> map ( function ( Relation $ relation ) use ( $ first , $ page ) { return $ relation -> forPage ( $ page , $ first ) ; } ) ; $ relationModels = $ this -> unionAllRelationQueries ( $ relations ) -> get ( ) ; $ this -> hydratePivotRelation ( $ relationName , $ relationModels ) ; $ this -> loadDefaultWith ( $ relationModels ) ; $ this -> associateRelationModels ( $ relationName , $ relationModels ) ; $ this -> convertRelationToPaginator ( $ first , $ page , $ relationName ) ; return $ this ; }
|
Load only one page of relations of all the models .
|
2,987
|
protected function buildRelationsFromModels ( string $ relationName , Closure $ relationConstraints ) : Collection { return $ this -> models -> toBase ( ) -> map ( function ( Model $ model ) use ( $ relationName , $ relationConstraints ) { $ relation = $ this -> getRelationInstance ( $ relationName ) ; $ relation -> addEagerConstraints ( [ $ model ] ) ; $ relationConstraints ( $ relation , $ model ) ; if ( method_exists ( $ relation , 'shouldSelect' ) ) { $ shouldSelect = new ReflectionMethod ( get_class ( $ relation ) , 'shouldSelect' ) ; $ shouldSelect -> setAccessible ( true ) ; $ select = $ shouldSelect -> invoke ( $ relation , [ '*' ] ) ; $ relation -> addSelect ( $ select ) ; } elseif ( method_exists ( $ relation , 'getSelectColumns' ) ) { $ getSelectColumns = new ReflectionMethod ( get_class ( $ relation ) , 'getSelectColumns' ) ; $ getSelectColumns -> setAccessible ( true ) ; $ select = $ getSelectColumns -> invoke ( $ relation , [ '*' ] ) ; $ relation -> addSelect ( $ select ) ; } $ relation -> initRelation ( [ $ model ] , $ relationName ) ; return $ relation ; } ) ; }
|
Get queries to fetch relationships .
|
2,988
|
protected function loadDefaultWith ( EloquentCollection $ collection ) : self { if ( $ collection -> isEmpty ( ) ) { return $ this ; } $ model = $ collection -> first ( ) ; $ reflection = new ReflectionClass ( $ model ) ; $ withProperty = $ reflection -> getProperty ( 'with' ) ; $ withProperty -> setAccessible ( true ) ; $ with = array_filter ( ( array ) $ withProperty -> getValue ( $ model ) , function ( $ relation ) use ( $ model ) { return ! $ model -> relationLoaded ( $ relation ) ; } ) ; if ( ! empty ( $ with ) ) { $ collection -> load ( $ with ) ; } return $ this ; }
|
Load default eager loads .
|
2,989
|
public function getRelationDictionary ( string $ relationName ) : array { return $ this -> models -> mapWithKeys ( function ( Model $ model ) use ( $ relationName ) { return [ $ this -> buildKey ( $ model -> getKey ( ) ) => $ model -> getRelation ( $ relationName ) ] ; } ) -> all ( ) ; }
|
Get an associative array of relations keyed by the models primary key .
|
2,990
|
protected function unionAllRelationQueries ( Collection $ relations ) : EloquentBuilder { return $ relations -> reduce ( function ( EloquentBuilder $ builder , Relation $ relation ) { return $ builder -> unionAll ( $ relation -> getQuery ( ) ) ; } , $ relations -> shift ( ) -> getQuery ( ) ) ; }
|
Merge all the relation queries into a single query with UNION ALL .
|
2,991
|
protected function associateRelationModels ( string $ relationName , EloquentCollection $ relationModels ) : self { $ relation = $ this -> getRelationInstance ( $ relationName ) ; $ relation -> match ( $ this -> models -> all ( ) , $ relationModels , $ relationName ) ; return $ this ; }
|
Associate the collection of all fetched relationModels back with their parents .
|
2,992
|
protected function hydratePivotRelation ( string $ relationName , EloquentCollection $ relationModels ) : self { $ relation = $ this -> getRelationInstance ( $ relationName ) ; if ( $ relationModels -> isNotEmpty ( ) && method_exists ( $ relation , 'hydratePivotRelation' ) ) { $ hydrationMethod = new ReflectionMethod ( get_class ( $ relation ) , 'hydratePivotRelation' ) ; $ hydrationMethod -> setAccessible ( true ) ; $ hydrationMethod -> invoke ( $ relation , $ relationModels -> all ( ) ) ; } return $ this ; }
|
Ensure the pivot relation is hydrated too if it exists .
|
2,993
|
protected function convertWrappedDefinitionNode ( $ node , array $ wrappers = [ ] ) : Type { if ( $ node -> kind === NodeKind :: NON_NULL_TYPE || $ node -> kind === NodeKind :: LIST_TYPE ) { $ wrappers [ ] = $ node -> kind ; return $ this -> convertWrappedDefinitionNode ( $ node -> type , $ wrappers ) ; } return ( new Collection ( $ wrappers ) ) -> reverse ( ) -> reduce ( function ( Type $ type , string $ kind ) : Type { if ( $ kind === NodeKind :: NON_NULL_TYPE ) { return Type :: nonNull ( $ type ) ; } if ( $ kind === NodeKind :: LIST_TYPE ) { return Type :: listOf ( $ type ) ; } return $ type ; } , $ this -> convertNamedTypeNode ( $ node ) ) ; }
|
Unwrap the node if needed and convert to type .
|
2,994
|
protected function convertNamedTypeNode ( NamedTypeNode $ node ) : Type { $ nodeName = $ node -> name -> value ; switch ( $ nodeName ) { case 'ID' : return Type :: id ( ) ; case 'Int' : return Type :: int ( ) ; case 'Boolean' : return Type :: boolean ( ) ; case 'Float' : return Type :: float ( ) ; case 'String' : return Type :: string ( ) ; default : return $ this -> typeRegistry -> get ( $ nodeName ) ; } }
|
Converted named node to type .
|
2,995
|
public function handle ( FieldValue $ fieldValue ) : array { $ fieldDefinitionNode = $ fieldValue -> getField ( ) ; if ( $ resolverDirective = $ this -> directiveFactory -> createFieldResolver ( $ fieldDefinitionNode ) ) { $ this -> fieldValue = $ resolverDirective -> resolveField ( $ fieldValue ) ; } else { $ this -> fieldValue = $ fieldValue -> setResolver ( $ fieldValue -> getParentName ( ) === 'Subscription' ? $ this -> providesSubscriptionResolver -> provideSubscriptionResolver ( $ fieldValue ) : $ this -> providesResolver -> provideResolver ( $ fieldValue ) ) ; } $ resolverWithMiddleware = $ this -> pipeline -> send ( $ this -> fieldValue ) -> through ( $ this -> directiveFactory -> createFieldMiddleware ( $ fieldDefinitionNode ) ) -> via ( 'handleField' ) -> then ( function ( FieldValue $ fieldValue ) : FieldValue { return $ fieldValue ; } ) -> getResolver ( ) ; $ argumentValues = $ this -> getArgumentValues ( ) ; $ this -> fieldValue -> setResolver ( function ( ) use ( $ argumentValues , $ resolverWithMiddleware ) { $ this -> setResolverArguments ( ... func_get_args ( ) ) ; $ this -> validationErrorBuffer = ( new ErrorBuffer ) -> setErrorType ( 'validation' ) ; $ this -> builder = new Builder ; $ this -> queryFilter = QueryFilter :: getInstance ( $ this -> fieldValue ) ; $ argumentValues -> each ( function ( ArgumentValue $ argumentValue ) : void { $ this -> handleArgDirectivesRecursively ( $ argumentValue -> getType ( ) , $ argumentValue -> getAstNode ( ) , [ $ argumentValue -> getName ( ) ] ) ; } ) ; $ this -> runArgDirectives ( ) ; foreach ( $ this -> spreadPaths as $ argumentPath ) { $ inputValues = $ this -> argValue ( $ argumentPath ) ; $ this -> unsetArgValue ( $ argumentPath ) ; array_pop ( $ argumentPath ) ; foreach ( $ inputValues as $ key => $ value ) { $ this -> setArgValue ( array_merge ( $ argumentPath , [ $ key ] ) , $ value ) ; } } $ this -> builder -> setQueryFilter ( $ this -> queryFilter ) ; $ this -> resolveInfo -> builder = $ this -> builder ; return $ resolverWithMiddleware ( $ this -> root , $ this -> args , $ this -> context , $ this -> resolveInfo ) ; } ) ; return [ 'name' => $ fieldDefinitionNode -> name -> value , 'type' => $ this -> fieldValue -> getReturnType ( ) , 'args' => $ this -> getInputValueDefinitions ( $ argumentValues ) , 'resolve' => $ this -> fieldValue -> getResolver ( ) , 'description' => data_get ( $ fieldDefinitionNode -> description , 'value' ) , 'complexity' => $ this -> fieldValue -> getComplexity ( ) , 'deprecationReason' => $ this -> fieldValue -> getDeprecationReason ( ) , ] ; }
|
Convert a FieldValue to an executable FieldDefinition .
|
2,996
|
protected function getArgumentValues ( ) : Collection { return ( new Collection ( $ this -> fieldValue -> getField ( ) -> arguments ) ) -> map ( function ( InputValueDefinitionNode $ inputValueDefinition ) : ArgumentValue { return new ArgumentValue ( $ inputValueDefinition , $ this -> fieldValue ) ; } ) ; }
|
Get a collection of the fields argument definitions .
|
2,997
|
protected function handleArgDirectivesRecursively ( InputType $ type , InputValueDefinitionNode $ astNode , array $ argumentPath ) : void { if ( $ type instanceof NonNull ) { $ this -> handleArgDirectivesRecursively ( $ type -> getWrappedType ( ) , $ astNode , $ argumentPath ) ; return ; } $ directives = $ this -> directiveFactory -> createArgDirectives ( $ astNode ) ; if ( $ directives -> contains ( function ( Directive $ directive ) : bool { return $ directive instanceof SpreadDirective ; } ) && $ type instanceof InputObjectType ) { $ this -> spreadPaths [ ] = $ argumentPath ; } $ this -> handleArgWithAssociatedDirectives ( $ type , $ astNode , $ directives , $ argumentPath ) ; if ( ! $ this -> argValueExists ( $ argumentPath ) || $ this -> argValue ( $ argumentPath ) === null ) { return ; } if ( $ type instanceof InputObjectType ) { foreach ( $ type -> getFields ( ) as $ field ) { $ this -> handleArgDirectivesRecursively ( $ field -> type , $ field -> astNode , array_merge ( $ argumentPath , [ $ field -> name ] ) ) ; } } if ( $ type instanceof ListOfType ) { foreach ( $ this -> argValue ( $ argumentPath ) as $ index => $ value ) { $ this -> handleArgDirectivesRecursively ( $ type -> ofType , $ astNode , array_merge ( $ argumentPath , [ $ index ] ) ) ; } } }
|
Handle the ArgMiddleware .
|
2,998
|
protected function validateArgs ( ) : void { if ( ! $ this -> rules ) { return ; } $ validator = validator ( $ this -> args , $ this -> rules , $ this -> messages , [ 'root' => $ this -> root , 'context' => $ this -> context , 'resolveInfo' => $ this -> resolveInfo , ] ) ; if ( $ validator -> fails ( ) ) { foreach ( $ validator -> errors ( ) -> getMessages ( ) as $ key => $ errorMessages ) { foreach ( $ errorMessages as $ errorMessage ) { $ this -> validationErrorBuffer -> push ( $ errorMessage , $ key ) ; } } } $ path = implode ( '.' , $ this -> resolveInfo ( ) -> path ) ; $ this -> validationErrorBuffer -> flush ( "Validation failed for the field [$path]." ) ; $ this -> rules = [ ] ; $ this -> messages = [ ] ; }
|
Run the gathered validation rules on the arguments .
|
2,999
|
protected function resumeHandlingArgDirectives ( ) : void { $ snapshots = $ this -> handleArgDirectivesSnapshots ; $ this -> handleArgDirectivesSnapshots = [ ] ; foreach ( $ snapshots as $ handlerArgs ) { $ this -> handleArgDirectives ( ... $ handlerArgs ) ; } if ( count ( $ this -> handleArgDirectivesSnapshots ) > 0 ) { $ this -> runArgDirectives ( ) ; } }
|
Continue evaluating the arg directives after validation has run .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.