repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
orchidsoftware/platform
src/Screen/Field.php
Field.translate
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; }
php
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; }
[ "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. @return $this
[ "Localization", "of", "fields", "." ]
4930f527629e11c404d0a89592e67c857a29b8ff
https://github.com/orchidsoftware/platform/blob/4930f527629e11c404d0a89592e67c857a29b8ff/src/Screen/Field.php#L222-L237
train
orchidsoftware/platform
src/Platform/Providers/FoundationServiceProvider.php
FoundationServiceProvider.registerOrchid
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; }
php
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; }
[ "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. @return $this
[ "Register", "orchid", "." ]
4930f527629e11c404d0a89592e67c857a29b8ff
https://github.com/orchidsoftware/platform/blob/4930f527629e11c404d0a89592e67c857a29b8ff/src/Platform/Providers/FoundationServiceProvider.php#L105-L113
train
orchidsoftware/platform
src/Platform/Providers/FoundationServiceProvider.php
FoundationServiceProvider.registerViews
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; }
php
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; }
[ "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. @return $this
[ "Register", "views", "&", "Publish", "views", "." ]
4930f527629e11c404d0a89592e67c857a29b8ff
https://github.com/orchidsoftware/platform/blob/4930f527629e11c404d0a89592e67c857a29b8ff/src/Platform/Providers/FoundationServiceProvider.php#L120-L129
train
orchidsoftware/platform
src/Platform/Providers/FoundationServiceProvider.php
FoundationServiceProvider.register
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) { /* @var \Illuminate\Routing\Router $this */ return $this->any($url.'/{method?}/{argument?}', [$screen, 'handle']) ->name($name); }); } if (! defined('PLATFORM_PATH')) { /* * Get the path to the ORCHID Platform folder. */ define('PLATFORM_PATH', realpath(__DIR__.'/../../../')); } $this->mergeConfigFrom( realpath(PLATFORM_PATH.'/config/platform.php'), 'platform' ); }
php
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) { /* @var \Illuminate\Routing\Router $this */ return $this->any($url.'/{method?}/{argument?}', [$screen, 'handle']) ->name($name); }); } if (! defined('PLATFORM_PATH')) { /* * Get the path to the ORCHID Platform folder. */ define('PLATFORM_PATH', realpath(__DIR__.'/../../../')); } $this->mergeConfigFrom( realpath(PLATFORM_PATH.'/config/platform.php'), 'platform' ); }
[ "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", ")", "{", "/* @var \\Illuminate\\Routing\\Router $this */", "return", "$", "this", "->", "any", "(", "$", "url", ".", "'/{method?}/{argument?}'", ",", "[", "$", "screen", ",", "'handle'", "]", ")", "->", "name", "(", "$", "name", ")", ";", "}", ")", ";", "}", "if", "(", "!", "defined", "(", "'PLATFORM_PATH'", ")", ")", "{", "/*\n * Get the path to the ORCHID Platform folder.\n */", "define", "(", "'PLATFORM_PATH'", ",", "realpath", "(", "__DIR__", ".", "'/../../../'", ")", ")", ";", "}", "$", "this", "->", "mergeConfigFrom", "(", "realpath", "(", "PLATFORM_PATH", ".", "'/config/platform.php'", ")", ",", "'platform'", ")", ";", "}" ]
Register bindings the service provider.
[ "Register", "bindings", "the", "service", "provider", "." ]
4930f527629e11c404d0a89592e67c857a29b8ff
https://github.com/orchidsoftware/platform/blob/4930f527629e11c404d0a89592e67c857a29b8ff/src/Platform/Providers/FoundationServiceProvider.php#L161-L187
train
orchidsoftware/platform
src/Press/Models/Category.php
Category.getAllCategories
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(); }
php
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(); }
[ "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. @return array
[ "Select", "all", "categories", "except", "current", "." ]
4930f527629e11c404d0a89592e67c857a29b8ff
https://github.com/orchidsoftware/platform/blob/4930f527629e11c404d0a89592e67c857a29b8ff/src/Press/Models/Category.php#L39-L46
train
orchidsoftware/platform
src/Press/Models/Category.php
Category.newWithCreateTerm
public function newWithCreateTerm($term): self { $newTerm = Term::firstOrCreate($term); $this->term_id = $newTerm->id; $this->term()->associate($newTerm); $this->setTaxonomy(); return $this; }
php
public function newWithCreateTerm($term): self { $newTerm = Term::firstOrCreate($term); $this->term_id = $newTerm->id; $this->term()->associate($newTerm); $this->setTaxonomy(); return $this; }
[ "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. @param array $term @return self
[ "Create", "category", "term", "." ]
4930f527629e11c404d0a89592e67c857a29b8ff
https://github.com/orchidsoftware/platform/blob/4930f527629e11c404d0a89592e67c857a29b8ff/src/Press/Models/Category.php#L55-L63
train
orchidsoftware/platform
src/Press/Models/Category.php
Category.setParent
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; }
php
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; }
[ "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. @param int|null $parent_id @return self
[ "Set", "parent", "category", "." ]
4930f527629e11c404d0a89592e67c857a29b8ff
https://github.com/orchidsoftware/platform/blob/4930f527629e11c404d0a89592e67c857a29b8ff/src/Press/Models/Category.php#L72-L79
train
mpdf/mpdf
src/Writer/BaseWriter.php
BaseWriter.utf8ToUtf16BigEndian
public function utf8ToUtf16BigEndian($str, $setbom = true) // UTF8ToUTF16BE { 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 = ''; // string to be returned if ($setbom) { $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM) } $outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8'); return $outstr; }
php
public function utf8ToUtf16BigEndian($str, $setbom = true) // UTF8ToUTF16BE { 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 = ''; // string to be returned if ($setbom) { $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM) } $outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8'); return $outstr; }
[ "public", "function", "utf8ToUtf16BigEndian", "(", "$", "str", ",", "$", "setbom", "=", "true", ")", "// UTF8ToUTF16BE", "{", "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", "=", "''", ";", "// string to be returned", "if", "(", "$", "setbom", ")", "{", "$", "outstr", ".=", "\"\\xFE\\xFF\"", ";", "// Byte Order Mark (BOM)", "}", "$", "outstr", ".=", "mb_convert_encoding", "(", "$", "str", ",", "'UTF-16BE'", ",", "'UTF-8'", ")", ";", "return", "$", "outstr", ";", "}" ]
Converts UTF-8 strings to UTF16-BE.
[ "Converts", "UTF", "-", "8", "strings", "to", "UTF16", "-", "BE", "." ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Writer/BaseWriter.php#L85-L105
train
mpdf/mpdf
src/Otl.php
Otl._getXAdvancePos
private function _getXAdvancePos($pos) { // NB Not all fonts have all marks specified in GlyphClassMarks // If the current glyph is not a base (but a mark) then ignore this, and apply to the current position 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; }
php
private function _getXAdvancePos($pos) { // NB Not all fonts have all marks specified in GlyphClassMarks // If the current glyph is not a base (but a mark) then ignore this, and apply to the current position 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; }
[ "private", "function", "_getXAdvancePos", "(", "$", "pos", ")", "{", "// NB Not all fonts have all marks specified in GlyphClassMarks", "// If the current glyph is not a base (but a mark) then ignore this, and apply to the current position", "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
[ "the", "last", "of", "any", "Marks", "which", "immediately", "follow", "the", "current", "glyph" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Otl.php#L3268-L3280
train
mpdf/mpdf
src/PageFormat.php
PageFormat.getSizeFromName
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], // 'B' format paperback size 128x198mm 'A' => [314.65, 504.57], // 'A' format paperback size 111x178mm 'DEMY' => [382.68, 612.28], // 'Demy' format paperback size 135x216mm 'ROYAL' => [433.70, 663.30], // 'Royal' format paperback size 153x234mm ]; if (!isset($formats[$format])) { throw new \Mpdf\MpdfException(sprintf('Unknown page format %s', $format)); } return $formats[$format]; }
php
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], // 'B' format paperback size 128x198mm 'A' => [314.65, 504.57], // 'A' format paperback size 111x178mm 'DEMY' => [382.68, 612.28], // 'Demy' format paperback size 135x216mm 'ROYAL' => [433.70, 663.30], // 'Royal' format paperback size 153x234mm ]; if (!isset($formats[$format])) { throw new \Mpdf\MpdfException(sprintf('Unknown page format %s', $format)); } return $formats[$format]; }
[ "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", "]", ",", "// 'B' format paperback size 128x198mm", "'A'", "=>", "[", "314.65", ",", "504.57", "]", ",", "// 'A' format paperback size 111x178mm", "'DEMY'", "=>", "[", "382.68", ",", "612.28", "]", ",", "// 'Demy' format paperback size 135x216mm", "'ROYAL'", "=>", "[", "433.70", ",", "663.30", "]", ",", "// 'Royal' format paperback size 153x234mm", "]", ";", "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. Returned values are milimeters multiplied by scale factor of 72 / 25.4 @param string $name @return float[] Width and height of given format
[ "This", "method", "returns", "an", "array", "of", "width", "and", "height", "of", "given", "named", "format", "." ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/PageFormat.php#L16-L82
train
mpdf/mpdf
src/CssManager.php
CssManager.array_merge_recursive_unique
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))) { // integer or string as integer key - append $ret[] = $value; } else { // string key - merge if (is_array($value) && isset($ret[$key])) { $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value); } else { $ret[$key] = $value; } } } } return $ret; }
php
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))) { // integer or string as integer key - append $ret[] = $value; } else { // string key - merge if (is_array($value) && isset($ret[$key])) { $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value); } else { $ret[$key] = $value; } } } } return $ret; }
[ "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", ")", ")", ")", "{", "// integer or string as integer key - append", "$", "ret", "[", "]", "=", "$", "value", ";", "}", "else", "{", "// string key - merge", "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
[ "for", "CSS", "handling" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/CssManager.php#L1326-L1345
train
mpdf/mpdf
src/CssManager.php
CssManager._nthchild
function _nthchild($f, $c) { // $f is formula e.g. 2N+1 split into a preg_match array // $c is the comparator value e.g row or column number $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; } // e.g. (+6) elseif ($f_count === 3) { // e.g. (2N) if ($f[2] == '') { $a = 1; } elseif ($f[2] == '-') { $a = -1; } else { $a = $f[2] + 0; } $b = 0; } elseif ($f_count === 4) { // e.g. (2N+6) 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 ($a<0) if (((($c % $a) - $b) % $a) === 0 && $c <= $b) { $select = true; } } return $select; }
php
function _nthchild($f, $c) { // $f is formula e.g. 2N+1 split into a preg_match array // $c is the comparator value e.g row or column number $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; } // e.g. (+6) elseif ($f_count === 3) { // e.g. (2N) if ($f[2] == '') { $a = 1; } elseif ($f[2] == '-') { $a = -1; } else { $a = $f[2] + 0; } $b = 0; } elseif ($f_count === 4) { // e.g. (2N+6) 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 ($a<0) if (((($c % $a) - $b) % $a) === 0 && $c <= $b) { $select = true; } } return $select; }
[ "function", "_nthchild", "(", "$", "f", ",", "$", "c", ")", "{", "// $f is formula e.g. 2N+1 split into a preg_match array", "// $c is the comparator value e.g row or column number", "$", "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", ";", "}", "// e.g. (+6)", "elseif", "(", "$", "f_count", "===", "3", ")", "{", "// e.g. (2N)", "if", "(", "$", "f", "[", "2", "]", "==", "''", ")", "{", "$", "a", "=", "1", ";", "}", "elseif", "(", "$", "f", "[", "2", "]", "==", "'-'", ")", "{", "$", "a", "=", "-", "1", ";", "}", "else", "{", "$", "a", "=", "$", "f", "[", "2", "]", "+", "0", ";", "}", "$", "b", "=", "0", ";", "}", "elseif", "(", "$", "f_count", "===", "4", ")", "{", "// e.g. (2N+6)", "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 ($a<0)", "if", "(", "(", "(", "(", "$", "c", "%", "$", "a", ")", "-", "$", "b", ")", "%", "$", "a", ")", "===", "0", "&&", "$", "c", "<=", "$", "b", ")", "{", "$", "select", "=", "true", ";", "}", "}", "return", "$", "select", ";", "}" ]
mPDF 5.7.4 nth-child
[ "mPDF", "5", ".", "7", ".", "4", "nth", "-", "child" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/CssManager.php#L2187-L2240
train
mpdf/mpdf
src/Barcode/AbstractBarcode.php
AbstractBarcode.binseqToArray
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; // bar } else { $t = false; // space } $barcodeData['bcode'][$k] = ['t' => $t, 'w' => $w, 'h' => 1, 'p' => 0]; $barcodeData['maxw'] += $w; ++$k; $w = 0; } } return $barcodeData; }
php
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; // bar } else { $t = false; // space } $barcodeData['bcode'][$k] = ['t' => $t, 'w' => $w, 'h' => 1, 'p' => 0]; $barcodeData['maxw'] += $w; ++$k; $w = 0; } } return $barcodeData; }
[ "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", ";", "// bar", "}", "else", "{", "$", "t", "=", "false", ";", "// space", "}", "$", "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 @param string $seq @param mixed[] $barcodeData @return mixed[]
[ "Convert", "binary", "barcode", "sequence", "to", "barcode", "array" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Barcode/AbstractBarcode.php#L47-L67
train
mpdf/mpdf
src/Barcode/S25.php
S25.checksum
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; }
php
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; }
[ "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. @param string $code @return int
[ "Checksum", "for", "standard", "2", "of", "5", "barcodes", "." ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Barcode/S25.php#L85-L101
train
mpdf/mpdf
src/FpdiTrait.php
FpdiTrait.getImportedExternalPageLinks
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; /* Skip over any annotations that aren't links */ $type = $getAttribute($annotation, 'Type'); $subtype = $getAttribute($annotation, 'Subtype'); if ($type !== 'Annot' || $subtype !== 'Link' || !isset($annotation['A'])) { continue; } /* Calculate the link positioning */ $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; }
php
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; /* Skip over any annotations that aren't links */ $type = $getAttribute($annotation, 'Type'); $subtype = $getAttribute($annotation, 'Subtype'); if ($type !== 'Annot' || $subtype !== 'Link' || !isset($annotation['A'])) { continue; } /* Calculate the link positioning */ $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; }
[ "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", ";", "/* Skip over any annotations that aren't links */", "$", "type", "=", "$", "getAttribute", "(", "$", "annotation", ",", "'Type'", ")", ";", "$", "subtype", "=", "$", "getAttribute", "(", "$", "annotation", ",", "'Subtype'", ")", ";", "if", "(", "$", "type", "!==", "'Annot'", "||", "$", "subtype", "!==", "'Link'", "||", "!", "isset", "(", "$", "annotation", "[", "'A'", "]", ")", ")", "{", "continue", ";", "}", "/* Calculate the link positioning */", "$", "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 @param int $pageNumber The page number. @return array @throws CrossReferenceException @throws PdfTypeException @throws \setasign\Fpdi\PdfParser\PdfParserException
[ "Imports", "the", "external", "page", "links" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/FpdiTrait.php#L183-L247
train
mpdf/mpdf
src/OtlDump.php
OtlDump._checkGSUBignore
function _checkGSUBignore($flag, $glyph, $MarkFilteringSet) { $ignore = false; // Flag & 0x0008 = Ignore Marks 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; } // Flag & 0xFF?? = MarkAttachmentType if (($flag & 0xFF00) && strpos($this->MarkAttachmentType[($flag >> 8)], $glyph)) { $ignore = true; } // Flag & 0x0010 = UseMarkFilteringSet if (($flag & 0x0010) && strpos($this->MarkGlyphSets[$MarkFilteringSet], $glyph)) { $ignore = true; } return $ignore; }
php
function _checkGSUBignore($flag, $glyph, $MarkFilteringSet) { $ignore = false; // Flag & 0x0008 = Ignore Marks 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; } // Flag & 0xFF?? = MarkAttachmentType if (($flag & 0xFF00) && strpos($this->MarkAttachmentType[($flag >> 8)], $glyph)) { $ignore = true; } // Flag & 0x0010 = UseMarkFilteringSet if (($flag & 0x0010) && strpos($this->MarkGlyphSets[$MarkFilteringSet], $glyph)) { $ignore = true; } return $ignore; }
[ "function", "_checkGSUBignore", "(", "$", "flag", ",", "$", "glyph", ",", "$", "MarkFilteringSet", ")", "{", "$", "ignore", "=", "false", ";", "// Flag & 0x0008 = Ignore Marks", "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", ";", "}", "// Flag & 0xFF?? = MarkAttachmentType", "if", "(", "(", "$", "flag", "&", "0xFF00", ")", "&&", "strpos", "(", "$", "this", "->", "MarkAttachmentType", "[", "(", "$", "flag", ">>", "8", ")", "]", ",", "$", "glyph", ")", ")", "{", "$", "ignore", "=", "true", ";", "}", "// Flag & 0x0010 = UseMarkFilteringSet", "if", "(", "(", "$", "flag", "&", "0x0010", ")", "&&", "strpos", "(", "$", "this", "->", "MarkGlyphSets", "[", "$", "MarkFilteringSet", "]", ",", "$", "glyph", ")", ")", "{", "$", "ignore", "=", "true", ";", "}", "return", "$", "ignore", ";", "}" ]
mPDF 5.7.1
[ "mPDF", "5", ".", "7", ".", "1" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/OtlDump.php#L2688-L2711
train
mpdf/mpdf
src/OtlDump.php
OtlDump.getGlyphData
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) { // simple $contours += $this->glyphdata[$originalGlyphIdx]['nContours']; $points += $this->glyphdata[$originalGlyphIdx]['nPoints']; } } $depth--; }
php
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) { // simple $contours += $this->glyphdata[$originalGlyphIdx]['nContours']; $points += $this->glyphdata[$originalGlyphIdx]['nPoints']; } } $depth--; }
[ "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", ")", "{", "// simple", "$", "contours", "+=", "$", "this", "->", "glyphdata", "[", "$", "originalGlyphIdx", "]", "[", "'nContours'", "]", ";", "$", "points", "+=", "$", "this", "->", "glyphdata", "[", "$", "originalGlyphIdx", "]", "[", "'nPoints'", "]", ";", "}", "}", "$", "depth", "--", ";", "}" ]
Recursively get composite glyph data
[ "Recursively", "get", "composite", "glyph", "data" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/OtlDump.php#L4007-L4022
train
mpdf/mpdf
src/OtlDump.php
OtlDump.getGlyphs
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); // old glyphID to new glyphID $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); } } } } }
php
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); // old glyphID to new glyphID $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); } } } } }
[ "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", ")", ";", "// old glyphID to new glyphID", "$", "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
[ "Recursively", "get", "composite", "glyphs" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/OtlDump.php#L4026-L4066
train
mpdf/mpdf
src/OtlDump.php
OtlDump.getCMAP4
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(); } // ???? was unsigned 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; } } }
php
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(); } // ???? was unsigned 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; } } }
[ "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", "(", ")", ";", "}", "// ???? was unsigned 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
[ "CMAP", "Format", "4" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/OtlDump.php#L4188-L4241
train
mpdf/mpdf
src/Pdf/Protection.php
Protection.objectKey
public function objectKey($n) { if ($this->useRC128Encryption) { $len = 16; } else { $len = 10; } return substr($this->md5toBinary($this->encryptionKey . pack('VXxx', $n)), 0, $len); }
php
public function objectKey($n) { if ($this->useRC128Encryption) { $len = 16; } else { $len = 10; } return substr($this->md5toBinary($this->encryptionKey . pack('VXxx', $n)), 0, $len); }
[ "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 @param int $n @return string
[ "Compute", "key", "depending", "on", "object", "number", "where", "the", "encrypted", "data", "is", "stored" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Pdf/Protection.php#L135-L144
train
mpdf/mpdf
src/Pdf/Protection.php
Protection.rc4
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; }
php
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; }
[ "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 @param string $key @param string $text @return string
[ "RC4", "is", "the", "standard", "encryption", "algorithm", "used", "in", "PDF", "format" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Pdf/Protection.php#L154-L187
train
mpdf/mpdf
src/Image/Svg.php
Svg.svg_overflow
function svg_overflow($x, $y) { $x2 = $x; $y2 = $y; if (isset($this->svg_attribs['overflow'])) { if ($this->svg_attribs['overflow'] == 'hidden') { // Not sure if this is supposed to strip off units, but since I dont use any I will omlt this step $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($this->svg_attribs['width']); $xmax = floor($svg_w); $xmin = 0; // $ymax = floor(($this->svg_attribs['height'] * -1)); $ymax = floor(($svg_h * -1)); $ymin = 0; if ($x > $xmax) { $x2 = $xmax; // right edge } if ($x < $xmin) { $x2 = $xmin; // left edge } if ($y < $ymax) { $y2 = $ymax; // bottom } if ($y > $ymin) { $y2 = $ymin; // top } } } return ['x' => $x2, 'y' => $y2]; }
php
function svg_overflow($x, $y) { $x2 = $x; $y2 = $y; if (isset($this->svg_attribs['overflow'])) { if ($this->svg_attribs['overflow'] == 'hidden') { // Not sure if this is supposed to strip off units, but since I dont use any I will omlt this step $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($this->svg_attribs['width']); $xmax = floor($svg_w); $xmin = 0; // $ymax = floor(($this->svg_attribs['height'] * -1)); $ymax = floor(($svg_h * -1)); $ymin = 0; if ($x > $xmax) { $x2 = $xmax; // right edge } if ($x < $xmin) { $x2 = $xmin; // left edge } if ($y < $ymax) { $y2 = $ymax; // bottom } if ($y > $ymin) { $y2 = $ymin; // top } } } return ['x' => $x2, 'y' => $y2]; }
[ "function", "svg_overflow", "(", "$", "x", ",", "$", "y", ")", "{", "$", "x2", "=", "$", "x", ";", "$", "y2", "=", "$", "y", ";", "if", "(", "isset", "(", "$", "this", "->", "svg_attribs", "[", "'overflow'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "svg_attribs", "[", "'overflow'", "]", "==", "'hidden'", ")", "{", "// Not sure if this is supposed to strip off units, but since I dont use any I will omlt this step", "$", "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($this->svg_attribs['width']);", "$", "xmax", "=", "floor", "(", "$", "svg_w", ")", ";", "$", "xmin", "=", "0", ";", "// $ymax = floor(($this->svg_attribs['height'] * -1));", "$", "ymax", "=", "floor", "(", "(", "$", "svg_h", "*", "-", "1", ")", ")", ";", "$", "ymin", "=", "0", ";", "if", "(", "$", "x", ">", "$", "xmax", ")", "{", "$", "x2", "=", "$", "xmax", ";", "// right edge", "}", "if", "(", "$", "x", "<", "$", "xmin", ")", "{", "$", "x2", "=", "$", "xmin", ";", "// left edge", "}", "if", "(", "$", "y", "<", "$", "ymax", ")", "{", "$", "y2", "=", "$", "ymax", ";", "// bottom", "}", "if", "(", "$", "y", ">", "$", "ymin", ")", "{", "$", "y2", "=", "$", "ymin", ";", "// top", "}", "}", "}", "return", "[", "'x'", "=>", "$", "x2", ",", "'y'", "=>", "$", "y2", "]", ";", "}" ]
check if points are within svg, if not, set to max
[ "check", "if", "points", "are", "within", "svg", "if", "not", "set", "to", "max" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Image/Svg.php#L1094-L1128
train
mpdf/mpdf
src/Image/ImageProcessor.php
ImageProcessor.fourBytesToInt
private function fourBytesToInt($s) { return (ord($s[0]) << 24) + (ord($s[1]) << 16) + (ord($s[2]) << 8) + ord($s[3]); }
php
private function fourBytesToInt($s) { return (ord($s[0]) << 24) + (ord($s[1]) << 16) + (ord($s[2]) << 8) + ord($s[3]); }
[ "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
[ "Read", "a", "4", "-", "byte", "integer", "from", "string" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Image/ImageProcessor.php#L1375-L1378
train
mpdf/mpdf
src/Image/ImageProcessor.php
ImageProcessor.imageError
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]); }
php
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]); }
[ "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
[ "Throw", "an", "exception", "and", "save", "re", "-", "trying", "image", "URL", "s", "which", "have", "already", "failed" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Image/ImageProcessor.php#L1401-L1410
train
mpdf/mpdf
src/Tag.php
Tag.getTagClassName
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; }
php
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; }
[ "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 @param string $tag The tag name @return string The fully qualified name
[ "Returns", "the", "fully", "qualified", "name", "of", "the", "class", "handling", "the", "rendering", "of", "the", "given", "tag" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Tag.php#L134-L174
train
mpdf/mpdf
src/Mpdf.php
Mpdf.GetFirstBlockFill
function GetFirstBlockFill() { // Returns the first blocklevel that uses a bgcolor fill $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; }
php
function GetFirstBlockFill() { // Returns the first blocklevel that uses a bgcolor fill $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; }
[ "function", "GetFirstBlockFill", "(", ")", "{", "// Returns the first blocklevel that uses a bgcolor fill", "$", "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
[ "Used", "when", "ColActive", "for", "tables", "-", "updated", "to", "return", "first", "block", "with", "background", "fill", "OR", "borders" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L6173-L6184
train
mpdf/mpdf
src/Mpdf.php
Mpdf._moveToPrevChar
function _moveToPrevChar(&$contentctr, &$charctr, $content) { $lastchar = false; $charctr--; while ($charctr < 0) { // go back to previous $content[] $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; }
php
function _moveToPrevChar(&$contentctr, &$charctr, $content) { $lastchar = false; $charctr--; while ($charctr < 0) { // go back to previous $content[] $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; }
[ "function", "_moveToPrevChar", "(", "&", "$", "contentctr", ",", "&", "$", "charctr", ",", "$", "content", ")", "{", "$", "lastchar", "=", "false", ";", "$", "charctr", "--", ";", "while", "(", "$", "charctr", "<", "0", ")", "{", "// go back to previous $content[]", "$", "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
[ "Get", "previous", "character", "and", "move", "pointers" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L7540-L7561
train
mpdf/mpdf
src/Mpdf.php
Mpdf._advanceFloatMargins
function _advanceFloatMargins() { // Update floatmargins - L 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; // Update objattr in floatbuffer 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; // Unset values $this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] = false; $this->floatmargins['L']['skipline'] = false; $this->floatmargins['L']['id'] = ''; } // Update floatmargins - R 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; // Update objattr in floatbuffer 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; // Unset values $this->floatbuffer[$this->floatmargins['R']['id']]['skipline'] = false; $this->floatmargins['R']['skipline'] = false; $this->floatmargins['R']['id'] = ''; } }
php
function _advanceFloatMargins() { // Update floatmargins - L 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; // Update objattr in floatbuffer 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; // Unset values $this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] = false; $this->floatmargins['L']['skipline'] = false; $this->floatmargins['L']['id'] = ''; } // Update floatmargins - R 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; // Update objattr in floatbuffer 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; // Unset values $this->floatbuffer[$this->floatmargins['R']['id']]['skipline'] = false; $this->floatmargins['R']['skipline'] = false; $this->floatmargins['R']['id'] = ''; } }
[ "function", "_advanceFloatMargins", "(", ")", "{", "// Update floatmargins - L", "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", ";", "// Update objattr in floatbuffer", "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", ";", "// Unset values", "$", "this", "->", "floatbuffer", "[", "$", "this", "->", "floatmargins", "[", "'L'", "]", "[", "'id'", "]", "]", "[", "'skipline'", "]", "=", "false", ";", "$", "this", "->", "floatmargins", "[", "'L'", "]", "[", "'skipline'", "]", "=", "false", ";", "$", "this", "->", "floatmargins", "[", "'L'", "]", "[", "'id'", "]", "=", "''", ";", "}", "// Update floatmargins - R", "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", ";", "// Update objattr in floatbuffer", "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", ";", "// Unset values", "$", "this", "->", "floatbuffer", "[", "$", "this", "->", "floatmargins", "[", "'R'", "]", "[", "'id'", "]", "]", "[", "'skipline'", "]", "=", "false", ";", "$", "this", "->", "floatmargins", "[", "'R'", "]", "[", "'skipline'", "]", "=", "false", ";", "$", "this", "->", "floatmargins", "[", "'R'", "]", "[", "'id'", "]", "=", "''", ";", "}", "}" ]
Update values if set to skipline
[ "Update", "values", "if", "set", "to", "skipline" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L8611-L8649
train
mpdf/mpdf
src/Mpdf.php
Mpdf.writeHTMLHeaders
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; } }
php
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; } }
[ "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
[ "Called", "internally", "from", "Header" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L12261-L12292
train
mpdf/mpdf
src/Mpdf.php
Mpdf.ClearFloats
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(); // Writes after the marker so not overwritten later by page background etc. $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; // mod changes operands to integers before processing }
php
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(); // Writes after the marker so not overwritten later by page background etc. $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; // mod changes operands to integers before processing }
[ "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", "(", ")", ";", "// Writes after the marker so not overwritten later by page background etc.", "$", "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", ";", "// mod changes operands to integers before processing", "}" ]
Added mPDF 3.0 Float DIV - CLEAR
[ "Added", "mPDF", "3", ".", "0", "Float", "DIV", "-", "CLEAR" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L15061-L15089
train
mpdf/mpdf
src/Mpdf.php
Mpdf.GetFloatDivInfo
function GetFloatDivInfo($blklvl = 0, $clear = false) { // If blklvl specified, only returns floats at that level - for ClearFloats $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]; }
php
function GetFloatDivInfo($blklvl = 0, $clear = false) { // If blklvl specified, only returns floats at that level - for ClearFloats $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]; }
[ "function", "GetFloatDivInfo", "(", "$", "blklvl", "=", "0", ",", "$", "clear", "=", "false", ")", "{", "// If blklvl specified, only returns floats at that level - for ClearFloats", "$", "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
[ "Added", "mPDF", "3", ".", "0", "Float", "DIV" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L15092-L15119
train
mpdf/mpdf
src/Mpdf.php
Mpdf.SetStylesArray
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); }
php
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); }
[ "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
[ "Set", "multiple", "styles", "at", "one", "time" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L18771-L18788
train
mpdf/mpdf
src/Mpdf.php
Mpdf.Bookmark
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; } // If columns are on - mark top of columns } // else y is used as set, or =0 i.e. top of page // DIRECTIONALITY RTL $bmo = ['t' => $txt, 'l' => $level, 'y' => $y, 'p' => $this->page]; if ($this->keep_block_together) { // do nothing } 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; } }
php
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; } // If columns are on - mark top of columns } // else y is used as set, or =0 i.e. top of page // DIRECTIONALITY RTL $bmo = ['t' => $txt, 'l' => $level, 'y' => $y, 'p' => $this->page]; if ($this->keep_block_together) { // do nothing } 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; } }
[ "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", ";", "}", "// If columns are on - mark top of columns", "}", "// else y is used as set, or =0 i.e. top of page", "// DIRECTIONALITY RTL", "$", "bmo", "=", "[", "'t'", "=>", "$", "txt", ",", "'l'", "=>", "$", "level", ",", "'y'", "=>", "$", "y", ",", "'p'", "=>", "$", "this", "->", "page", "]", ";", "if", "(", "$", "this", "->", "keep_block_together", ")", "{", "// do nothing", "}", "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
[ "FROM", "class", "PDF_Bookmark" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L23019-L23048
train
mpdf/mpdf
src/Mpdf.php
Mpdf.IndexEntry
function IndexEntry($txt, $xref = '') { if ($xref) { $this->IndexEntrySee($txt, $xref); return; } // Search the reference (AND Ref/PageNo) in the array $Present = false; if ($this->keep_block_together) { // do nothing } /* -- TABLES -- */ 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) { // If not found, add it $this->kwt_Reference[] = ['t' => $txt, 'op' => $this->page]; } } /* -- END TABLES -- */ 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) { // If not found, add it $this->Reference[] = ['t' => $txt, 'p' => [$this->page]]; } } }
php
function IndexEntry($txt, $xref = '') { if ($xref) { $this->IndexEntrySee($txt, $xref); return; } // Search the reference (AND Ref/PageNo) in the array $Present = false; if ($this->keep_block_together) { // do nothing } /* -- TABLES -- */ 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) { // If not found, add it $this->kwt_Reference[] = ['t' => $txt, 'op' => $this->page]; } } /* -- END TABLES -- */ 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) { // If not found, add it $this->Reference[] = ['t' => $txt, 'p' => [$this->page]]; } } }
[ "function", "IndexEntry", "(", "$", "txt", ",", "$", "xref", "=", "''", ")", "{", "if", "(", "$", "xref", ")", "{", "$", "this", "->", "IndexEntrySee", "(", "$", "txt", ",", "$", "xref", ")", ";", "return", ";", "}", "// Search the reference (AND Ref/PageNo) in the array", "$", "Present", "=", "false", ";", "if", "(", "$", "this", "->", "keep_block_together", ")", "{", "// do nothing", "}", "/* -- TABLES -- */", "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", ")", "{", "// If not found, add it", "$", "this", "->", "kwt_Reference", "[", "]", "=", "[", "'t'", "=>", "$", "txt", ",", "'op'", "=>", "$", "this", "->", "page", "]", ";", "}", "}", "/* -- END TABLES -- */", "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", ")", "{", "// If not found, add it", "$", "this", "->", "Reference", "[", "]", "=", "[", "'t'", "=>", "$", "txt", ",", "'p'", "=>", "[", "$", "this", "->", "page", "]", "]", ";", "}", "}", "}" ]
FROM class PDF_Ref == INDEX
[ "FROM", "class", "PDF_Ref", "==", "INDEX" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L23631-L23669
train
mpdf/mpdf
src/Mpdf.php
Mpdf.IndexEntrySee
function IndexEntrySee($txta, $txtb) { if ($this->directionality == 'rtl') { // *OTL* // ONLY DO THIS IF NOT IN TAGS if ($txta == strip_tags($txta)) { $txta = str_replace(':', ' - ', $txta); // *OTL* } if ($txtb == strip_tags($txtb)) { $txtb = str_replace(':', ' - ', $txtb); // *OTL* } } // *OTL* else { // *OTL* if ($txta == strip_tags($txta)) { $txta = str_replace(':', ', ', $txta); } if ($txtb == strip_tags($txtb)) { $txtb = str_replace(':', ', ', $txtb); } } // *OTL* $this->Reference[] = ['t' => $txta . ' - see ' . $txtb, 'p' => []]; }
php
function IndexEntrySee($txta, $txtb) { if ($this->directionality == 'rtl') { // *OTL* // ONLY DO THIS IF NOT IN TAGS if ($txta == strip_tags($txta)) { $txta = str_replace(':', ' - ', $txta); // *OTL* } if ($txtb == strip_tags($txtb)) { $txtb = str_replace(':', ' - ', $txtb); // *OTL* } } // *OTL* else { // *OTL* if ($txta == strip_tags($txta)) { $txta = str_replace(':', ', ', $txta); } if ($txtb == strip_tags($txtb)) { $txtb = str_replace(':', ', ', $txtb); } } // *OTL* $this->Reference[] = ['t' => $txta . ' - see ' . $txtb, 'p' => []]; }
[ "function", "IndexEntrySee", "(", "$", "txta", ",", "$", "txtb", ")", "{", "if", "(", "$", "this", "->", "directionality", "==", "'rtl'", ")", "{", "// *OTL*", "// ONLY DO THIS IF NOT IN TAGS", "if", "(", "$", "txta", "==", "strip_tags", "(", "$", "txta", ")", ")", "{", "$", "txta", "=", "str_replace", "(", "':'", ",", "' - '", ",", "$", "txta", ")", ";", "// *OTL*", "}", "if", "(", "$", "txtb", "==", "strip_tags", "(", "$", "txtb", ")", ")", "{", "$", "txtb", "=", "str_replace", "(", "':'", ",", "' - '", ",", "$", "txtb", ")", ";", "// *OTL*", "}", "}", "// *OTL*", "else", "{", "// *OTL*", "if", "(", "$", "txta", "==", "strip_tags", "(", "$", "txta", ")", ")", "{", "$", "txta", "=", "str_replace", "(", "':'", ",", "', '", ",", "$", "txta", ")", ";", "}", "if", "(", "$", "txtb", "==", "strip_tags", "(", "$", "txtb", ")", ")", "{", "$", "txtb", "=", "str_replace", "(", "':'", ",", "', '", ",", "$", "txtb", ")", ";", "}", "}", "// *OTL*", "$", "this", "->", "Reference", "[", "]", "=", "[", "'t'", "=>", "$", "txta", ".", "' - see '", ".", "$", "txtb", ",", "'p'", "=>", "[", "]", "]", ";", "}" ]
Added function to add a reference "Elephants. See Chickens"
[ "Added", "function", "to", "add", "a", "reference", "Elephants", ".", "See", "Chickens" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L23672-L23692
train
mpdf/mpdf
src/Mpdf.php
Mpdf.is_utf8
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; }
php
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; }
[ "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
[ "Edited", "v1", ".", "2", "Pass", "by", "reference", ";", "option", "to", "continue", "if", "invalid", "UTF", "-", "8", "chars" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L25679-L25691
train
mpdf/mpdf
src/Mpdf.php
Mpdf.columnAdjustAdd
function columnAdjustAdd($type, $k, $xadj, $yadj, $a, $b, $c = 0, $d = 0, $e = 0, $f = 0) { if ($type === 'Td') { // xpos,ypos $a += ($xadj * $k); $b -= ($yadj * $k); return 'BT ' . sprintf('%.3F %.3F', $a, $b) . ' Td'; } elseif ($type === 're') { // xpos,ypos,width,height $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F %.3F %.3F', $a, $b, $c, $d) . ' re'; } elseif ($type === 'l') { // xpos,ypos,x2pos,y2pos $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F l', $a, $b); } elseif ($type === 'img') { // width,height,xpos,ypos $c += ($xadj * $k); $d -= ($yadj * $k); return sprintf('q %.3F 0 0 %.3F %.3F %.3F', $a, $b, $c, $d) . ' cm /' . $e; } elseif ($type === 'draw') { // xpos,ypos $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F m', $a, $b); } elseif ($type === 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos $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'; } }
php
function columnAdjustAdd($type, $k, $xadj, $yadj, $a, $b, $c = 0, $d = 0, $e = 0, $f = 0) { if ($type === 'Td') { // xpos,ypos $a += ($xadj * $k); $b -= ($yadj * $k); return 'BT ' . sprintf('%.3F %.3F', $a, $b) . ' Td'; } elseif ($type === 're') { // xpos,ypos,width,height $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F %.3F %.3F', $a, $b, $c, $d) . ' re'; } elseif ($type === 'l') { // xpos,ypos,x2pos,y2pos $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F l', $a, $b); } elseif ($type === 'img') { // width,height,xpos,ypos $c += ($xadj * $k); $d -= ($yadj * $k); return sprintf('q %.3F 0 0 %.3F %.3F %.3F', $a, $b, $c, $d) . ' cm /' . $e; } elseif ($type === 'draw') { // xpos,ypos $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F m', $a, $b); } elseif ($type === 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos $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'; } }
[ "function", "columnAdjustAdd", "(", "$", "type", ",", "$", "k", ",", "$", "xadj", ",", "$", "yadj", ",", "$", "a", ",", "$", "b", ",", "$", "c", "=", "0", ",", "$", "d", "=", "0", ",", "$", "e", "=", "0", ",", "$", "f", "=", "0", ")", "{", "if", "(", "$", "type", "===", "'Td'", ")", "{", "// xpos,ypos", "$", "a", "+=", "(", "$", "xadj", "*", "$", "k", ")", ";", "$", "b", "-=", "(", "$", "yadj", "*", "$", "k", ")", ";", "return", "'BT '", ".", "sprintf", "(", "'%.3F %.3F'", ",", "$", "a", ",", "$", "b", ")", ".", "' Td'", ";", "}", "elseif", "(", "$", "type", "===", "'re'", ")", "{", "// xpos,ypos,width,height", "$", "a", "+=", "(", "$", "xadj", "*", "$", "k", ")", ";", "$", "b", "-=", "(", "$", "yadj", "*", "$", "k", ")", ";", "return", "sprintf", "(", "'%.3F %.3F %.3F %.3F'", ",", "$", "a", ",", "$", "b", ",", "$", "c", ",", "$", "d", ")", ".", "' re'", ";", "}", "elseif", "(", "$", "type", "===", "'l'", ")", "{", "// xpos,ypos,x2pos,y2pos", "$", "a", "+=", "(", "$", "xadj", "*", "$", "k", ")", ";", "$", "b", "-=", "(", "$", "yadj", "*", "$", "k", ")", ";", "return", "sprintf", "(", "'%.3F %.3F l'", ",", "$", "a", ",", "$", "b", ")", ";", "}", "elseif", "(", "$", "type", "===", "'img'", ")", "{", "// width,height,xpos,ypos", "$", "c", "+=", "(", "$", "xadj", "*", "$", "k", ")", ";", "$", "d", "-=", "(", "$", "yadj", "*", "$", "k", ")", ";", "return", "sprintf", "(", "'q %.3F 0 0 %.3F %.3F %.3F'", ",", "$", "a", ",", "$", "b", ",", "$", "c", ",", "$", "d", ")", ".", "' cm /'", ".", "$", "e", ";", "}", "elseif", "(", "$", "type", "===", "'draw'", ")", "{", "// xpos,ypos", "$", "a", "+=", "(", "$", "xadj", "*", "$", "k", ")", ";", "$", "b", "-=", "(", "$", "yadj", "*", "$", "k", ")", ";", "return", "sprintf", "(", "'%.3F %.3F m'", ",", "$", "a", ",", "$", "b", ")", ";", "}", "elseif", "(", "$", "type", "===", "'bezier'", ")", "{", "// xpos,ypos,x2pos,y2pos,x3pos,y3pos", "$", "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
[ "Callback", "function", "from", "function", "printcolumnbuffer", "in", "mpdf" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Mpdf.php#L26525-L26573
train
mpdf/mpdf
src/Barcode/Imb.php
Imb.imbCrc11Fcs
private function imbCrc11Fcs($codeArray) { $genpoly = 0x0F35; // generator polynomial $fcs = 0x07FF; // Frame Check Sequence // do most significant byte skipping the 2 most significant bits $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; } // do rest of bytes 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; }
php
private function imbCrc11Fcs($codeArray) { $genpoly = 0x0F35; // generator polynomial $fcs = 0x07FF; // Frame Check Sequence // do most significant byte skipping the 2 most significant bits $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; } // do rest of bytes 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; }
[ "private", "function", "imbCrc11Fcs", "(", "$", "codeArray", ")", "{", "$", "genpoly", "=", "0x0F35", ";", "// generator polynomial", "$", "fcs", "=", "0x07FF", ";", "// Frame Check Sequence", "// do most significant byte skipping the 2 most significant bits", "$", "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", ";", "}", "// do rest of bytes", "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 @param string[] $codeArray @return int
[ "Intelligent", "Mail", "Barcode", "calculation", "of", "Frame", "Check", "Sequence" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Barcode/Imb.php#L220-L250
train
mpdf/mpdf
src/Barcode/Imb.php
Imb.imbReverseUs
private function imbReverseUs($num) { $rev = 0; for ($i = 0; $i < 16; ++$i) { $rev <<= 1; $rev |= ($num & 1); $num >>= 1; } return $rev; }
php
private function imbReverseUs($num) { $rev = 0; for ($i = 0; $i < 16; ++$i) { $rev <<= 1; $rev |= ($num & 1); $num >>= 1; } return $rev; }
[ "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 @param int $num @return int
[ "Reverse", "unsigned", "short", "value" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Barcode/Imb.php#L258-L267
train
mpdf/mpdf
src/Barcode/Imb.php
Imb.imbTables
private function imbTables($n, $size) { $table = []; $lli = 0; // LUT lower index $lui = $size - 1; // LUT upper index 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 we don't have the right number of bits on, go on to the next value if ($bitCount == $n) { $reverse = ($this->imbReverseUs($count) >> 3); // if the reverse is less than count, we have already visited this pair before if ($reverse >= $count) { // If count is symmetric, place it at the first free slot from the end of the list. // Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list if ($reverse == $count) { $table[$lui] = $count; --$lui; } else { $table[$lli] = $count; ++$lli; $table[$lli] = $reverse; ++$lli; } } } } return $table; }
php
private function imbTables($n, $size) { $table = []; $lli = 0; // LUT lower index $lui = $size - 1; // LUT upper index 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 we don't have the right number of bits on, go on to the next value if ($bitCount == $n) { $reverse = ($this->imbReverseUs($count) >> 3); // if the reverse is less than count, we have already visited this pair before if ($reverse >= $count) { // If count is symmetric, place it at the first free slot from the end of the list. // Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list if ($reverse == $count) { $table[$lui] = $count; --$lui; } else { $table[$lli] = $count; ++$lli; $table[$lli] = $reverse; ++$lli; } } } } return $table; }
[ "private", "function", "imbTables", "(", "$", "n", ",", "$", "size", ")", "{", "$", "table", "=", "[", "]", ";", "$", "lli", "=", "0", ";", "// LUT lower index", "$", "lui", "=", "$", "size", "-", "1", ";", "// LUT upper index", "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 we don't have the right number of bits on, go on to the next value", "if", "(", "$", "bitCount", "==", "$", "n", ")", "{", "$", "reverse", "=", "(", "$", "this", "->", "imbReverseUs", "(", "$", "count", ")", ">>", "3", ")", ";", "// if the reverse is less than count, we have already visited this pair before", "if", "(", "$", "reverse", ">=", "$", "count", ")", "{", "// If count is symmetric, place it at the first free slot from the end of the list.", "// Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list", "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 @param int $n @param int $size @return mixed[]
[ "Generate", "Nof13", "tables", "used", "for", "Intelligent", "Mail", "Barcode" ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Barcode/Imb.php#L277-L310
train
mpdf/mpdf
src/Barcode/Imb.php
Imb.decToHex
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); }
php
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); }
[ "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. @param int $number @return string
[ "Convert", "large", "integer", "number", "to", "hexadecimal", "representation", "." ]
ee370f89a21956ec0ea3e38c0678ced491c6b56a
https://github.com/mpdf/mpdf/blob/ee370f89a21956ec0ea3e38c0678ced491c6b56a/src/Barcode/Imb.php#L318-L337
train
nuwave/lighthouse
src/Subscriptions/StorageManager.php
StorageManager.subscriberByRequest
public function subscriberByRequest(array $input, array $headers): ?Subscriber { $channel = Arr::get($input, 'channel_name'); return $channel ? $this->subscriberByChannel($channel) : null; }
php
public function subscriberByRequest(array $input, array $headers): ?Subscriber { $channel = Arr::get($input, 'channel_name'); return $channel ? $this->subscriberByChannel($channel) : null; }
[ "public", "function", "subscriberByRequest", "(", "array", "$", "input", ",", "array", "$", "headers", ")", ":", "?", "Subscriber", "{", "$", "channel", "=", "Arr", "::", "get", "(", "$", "input", ",", "'channel_name'", ")", ";", "return", "$", "channel", "?", "$", "this", "->", "subscriberByChannel", "(", "$", "channel", ")", ":", "null", ";", "}" ]
Get subscriber by request. @param array $input @param array $headers @return \Nuwave\Lighthouse\Subscriptions\Subscriber|null
[ "Get", "subscriber", "by", "request", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/StorageManager.php#L49-L56
train
nuwave/lighthouse
src/Subscriptions/StorageManager.php
StorageManager.subscriberByChannel
public function subscriberByChannel(string $channel): ?Subscriber { $key = self::SUBSCRIBER_KEY.".{$channel}"; return $this->cache->get($key); }
php
public function subscriberByChannel(string $channel): ?Subscriber { $key = self::SUBSCRIBER_KEY.".{$channel}"; return $this->cache->get($key); }
[ "public", "function", "subscriberByChannel", "(", "string", "$", "channel", ")", ":", "?", "Subscriber", "{", "$", "key", "=", "self", "::", "SUBSCRIBER_KEY", ".", "\".{$channel}\"", ";", "return", "$", "this", "->", "cache", "->", "get", "(", "$", "key", ")", ";", "}" ]
Find subscriber by channel. @param string $channel @return \Nuwave\Lighthouse\Subscriptions\Subscriber|null
[ "Find", "subscriber", "by", "channel", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/StorageManager.php#L64-L69
train
nuwave/lighthouse
src/Subscriptions/StorageManager.php
StorageManager.subscribersByTopic
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(); }
php
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(); }
[ "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. @param string $topic @return \Illuminate\Support\Collection<\Nuwave\Lighthouse\Subscriptions\Subscriber>
[ "Get", "collection", "of", "subscribers", "by", "channel", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/StorageManager.php#L77-L93
train
nuwave/lighthouse
src/Subscriptions/StorageManager.php
StorageManager.storeSubscriber
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); }
php
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); }
[ "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. @param \Nuwave\Lighthouse\Subscriptions\Subscriber $subscriber @param string $topic @return void
[ "Store", "subscription", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/StorageManager.php#L102-L115
train
nuwave/lighthouse
src/Subscriptions/StorageManager.php
StorageManager.deleteSubscriber
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; }
php
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; }
[ "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. @param string $channel @return \Nuwave\Lighthouse\Subscriptions\Subscriber|null
[ "Delete", "subscriber", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/StorageManager.php#L123-L135
train
nuwave/lighthouse
src/Schema/Source/SchemaStitcher.php
SchemaStitcher.gatherSchemaImportsRecursively
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(''); }
php
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(''); }
[ "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. @param string $path @return string
[ "Get", "the", "schema", "starting", "from", "a", "root", "schema", "following", "the", "imports", "recursively", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Source/SchemaStitcher.php#L56-L90
train
nuwave/lighthouse
src/Schema/Directives/CacheDirective.php
CacheDirective.store
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); }
php
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); }
[ "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. @param \Illuminate\Cache\CacheManager $cache @param string $key @param mixed $value @param \Carbon\Carbon|null $expiration @param mixed[] $tags @return void
[ "Store", "value", "in", "cache", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/CacheDirective.php#L104-L119
train
nuwave/lighthouse
src/Schema/Directives/CacheDirective.php
CacheDirective.setNodeKey
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); }
php
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); }
[ "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. @param \Nuwave\Lighthouse\Schema\Values\NodeValue $nodeValue @return void @throws \Nuwave\Lighthouse\Exceptions\DirectiveException
[ "Set", "node", "s", "cache", "key", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/CacheDirective.php#L141-L184
train
nuwave/lighthouse
src/Execution/Builder.php
Builder.apply
public function apply($builder, array $args) { /* * Call the queryFilter for backwards compatibility * @deprecated */ $this->queryFilter->filter($builder, $args); foreach ($args as $key => $value) { /** @var \Nuwave\Lighthouse\Support\Contracts\ArgBuilderDirective $builderDirective */ 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; }
php
public function apply($builder, array $args) { /* * Call the queryFilter for backwards compatibility * @deprecated */ $this->queryFilter->filter($builder, $args); foreach ($args as $key => $value) { /** @var \Nuwave\Lighthouse\Support\Contracts\ArgBuilderDirective $builderDirective */ 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; }
[ "public", "function", "apply", "(", "$", "builder", ",", "array", "$", "args", ")", "{", "/*\n * Call the queryFilter for backwards compatibility\n * @deprecated\n */", "$", "this", "->", "queryFilter", "->", "filter", "(", "$", "builder", ",", "$", "args", ")", ";", "foreach", "(", "$", "args", "as", "$", "key", "=>", "$", "value", ")", "{", "/** @var \\Nuwave\\Lighthouse\\Support\\Contracts\\ArgBuilderDirective $builderDirective */", "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. @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder @param mixed[] $args @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
[ "Apply", "the", "bound", "QueryBuilderDirectives", "to", "the", "given", "builder", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/Builder.php#L37-L57
train
nuwave/lighthouse
src/Execution/Builder.php
Builder.addScopes
public function addScopes(array $scopes): self { $this->scopes = array_merge($this->scopes, $scopes); return $this; }
php
public function addScopes(array $scopes): self { $this->scopes = array_merge($this->scopes, $scopes); return $this; }
[ "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. @param string[] $scopes @return $this
[ "Add", "scopes", "that", "are", "then", "called", "upon", "the", "query", "with", "the", "field", "arguments", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/Builder.php#L65-L70
train
nuwave/lighthouse
src/Execution/Builder.php
Builder.addBuilderDirective
public function addBuilderDirective(string $argumentName, ArgBuilderDirective $argBuilderDirective): self { $this->builderDirectives[$argumentName] = $argBuilderDirective; return $this; }
php
public function addBuilderDirective(string $argumentName, ArgBuilderDirective $argBuilderDirective): self { $this->builderDirectives[$argumentName] = $argBuilderDirective; return $this; }
[ "public", "function", "addBuilderDirective", "(", "string", "$", "argumentName", ",", "ArgBuilderDirective", "$", "argBuilderDirective", ")", ":", "self", "{", "$", "this", "->", "builderDirectives", "[", "$", "argumentName", "]", "=", "$", "argBuilderDirective", ";", "return", "$", "this", ";", "}" ]
Add a query builder directive keyed by the argument name. @param string $argumentName @param \Nuwave\Lighthouse\Support\Contracts\ArgBuilderDirective $argBuilderDirective @return $this
[ "Add", "a", "query", "builder", "directive", "keyed", "by", "the", "argument", "name", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/Builder.php#L79-L84
train
nuwave/lighthouse
src/Execution/MultipartFormRequest.php
MultipartFormRequest.fieldValue
protected function fieldValue(string $key) { return $this->isBatched() ? Arr::get($this->operations, $this->batchIndex.'.'.$key) : $this->operations[$key] ?? null; }
php
protected function fieldValue(string $key) { return $this->isBatched() ? Arr::get($this->operations, $this->batchIndex.'.'.$key) : $this->operations[$key] ?? null; }
[ "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. @param string $key @return array|string|null
[ "If", "we", "are", "dealing", "with", "a", "batched", "request", "this", "gets", "the", "contents", "of", "the", "currently", "resolving", "batch", "index", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/MultipartFormRequest.php#L77-L82
train
nuwave/lighthouse
src/Subscriptions/SubscriptionBroadcaster.php
SubscriptionBroadcaster.queueBroadcast
public function queueBroadcast(GraphQLSubscription $subscription, string $fieldName, $root): void { $this->eventsDispatcher->dispatch( new BroadcastSubscriptionEvent($subscription, $fieldName, $root) ); }
php
public function queueBroadcast(GraphQLSubscription $subscription, string $fieldName, $root): void { $this->eventsDispatcher->dispatch( new BroadcastSubscriptionEvent($subscription, $fieldName, $root) ); }
[ "public", "function", "queueBroadcast", "(", "GraphQLSubscription", "$", "subscription", ",", "string", "$", "fieldName", ",", "$", "root", ")", ":", "void", "{", "$", "this", "->", "eventsDispatcher", "->", "dispatch", "(", "new", "BroadcastSubscriptionEvent", "(", "$", "subscription", ",", "$", "fieldName", ",", "$", "root", ")", ")", ";", "}" ]
Queue pushing subscription data to subscribers. @param \Nuwave\Lighthouse\Schema\Types\GraphQLSubscription $subscription @param string $fieldName @param mixed $root @return void
[ "Queue", "pushing", "subscription", "data", "to", "subscribers", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/SubscriptionBroadcaster.php#L80-L85
train
nuwave/lighthouse
src/Subscriptions/SubscriptionBroadcaster.php
SubscriptionBroadcaster.broadcast
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() ); } ); }
php
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() ); } ); }
[ "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. @param \Nuwave\Lighthouse\Schema\Types\GraphQLSubscription $subscription @param string $fieldName @param mixed $root @return void
[ "Push", "subscription", "data", "to", "subscribers", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/SubscriptionBroadcaster.php#L95-L122
train
nuwave/lighthouse
src/Subscriptions/SubscriptionBroadcaster.php
SubscriptionBroadcaster.authorize
public function authorize(Request $request): Response { return $this->auth->authorize($request) ? $this->broadcastManager->authorized($request) : $this->broadcastManager->unauthorized($request); }
php
public function authorize(Request $request): Response { return $this->auth->authorize($request) ? $this->broadcastManager->authorized($request) : $this->broadcastManager->unauthorized($request); }
[ "public", "function", "authorize", "(", "Request", "$", "request", ")", ":", "Response", "{", "return", "$", "this", "->", "auth", "->", "authorize", "(", "$", "request", ")", "?", "$", "this", "->", "broadcastManager", "->", "authorized", "(", "$", "request", ")", ":", "$", "this", "->", "broadcastManager", "->", "unauthorized", "(", "$", "request", ")", ";", "}" ]
Authorize the subscription. @param \Illuminate\Http\Request $request @return \Symfony\Component\HttpFoundation\Response
[ "Authorize", "the", "subscription", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/SubscriptionBroadcaster.php#L130-L135
train
nuwave/lighthouse
src/Tracing/Tracing.php
Tracing.handleStartRequest
public function handleStartRequest(StartRequest $startRequest): void { $this->requestStart = Carbon::now(); $this->requestStartPrecise = $this->getTime(); }
php
public function handleStartRequest(StartRequest $startRequest): void { $this->requestStart = Carbon::now(); $this->requestStartPrecise = $this->getTime(); }
[ "public", "function", "handleStartRequest", "(", "StartRequest", "$", "startRequest", ")", ":", "void", "{", "$", "this", "->", "requestStart", "=", "Carbon", "::", "now", "(", ")", ";", "$", "this", "->", "requestStartPrecise", "=", "$", "this", "->", "getTime", "(", ")", ";", "}" ]
Handle request start. @param \Nuwave\Lighthouse\Events\StartRequest $startRequest @return void
[ "Handle", "request", "start", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Tracing/Tracing.php#L62-L66
train
nuwave/lighthouse
src/Tracing/Tracing.php
Tracing.handleBuildExtensionsResponse
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, ], ] ); }
php
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, ], ] ); }
[ "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. @param \Nuwave\Lighthouse\Events\BuildExtensionsResponse $buildExtensionsResponse @return \Nuwave\Lighthouse\Execution\ExtensionsResponse
[ "Return", "additional", "information", "for", "the", "result", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Tracing/Tracing.php#L85-L102
train
nuwave/lighthouse
src/Tracing/Tracing.php
Tracing.record
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), ]; }
php
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), ]; }
[ "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. @param \GraphQL\Type\Definition\ResolveInfo $resolveInfo @param float|int $start @param float|int $end @return void
[ "Record", "resolver", "execution", "time", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Tracing/Tracing.php#L112-L122
train
nuwave/lighthouse
src/Tracing/Tracing.php
Tracing.diffTimeInNanoseconds
protected function diffTimeInNanoseconds($start, $end): int { if ($this->platformSupportsNanoseconds()) { return $end - $start; } // Difference is in seconds (with microsecond precision) // * 1000 to get to milliseconds // * 1000 to get to microseconds // * 1000 to get to nanoseconds return (int) (($end - $start) * 1000 * 1000 * 1000); }
php
protected function diffTimeInNanoseconds($start, $end): int { if ($this->platformSupportsNanoseconds()) { return $end - $start; } // Difference is in seconds (with microsecond precision) // * 1000 to get to milliseconds // * 1000 to get to microseconds // * 1000 to get to nanoseconds return (int) (($end - $start) * 1000 * 1000 * 1000); }
[ "protected", "function", "diffTimeInNanoseconds", "(", "$", "start", ",", "$", "end", ")", ":", "int", "{", "if", "(", "$", "this", "->", "platformSupportsNanoseconds", "(", ")", ")", "{", "return", "$", "end", "-", "$", "start", ";", "}", "// Difference is in seconds (with microsecond precision)", "// * 1000 to get to milliseconds", "// * 1000 to get to microseconds", "// * 1000 to get to nanoseconds", "return", "(", "int", ")", "(", "(", "$", "end", "-", "$", "start", ")", "*", "1000", "*", "1000", "*", "1000", ")", ";", "}" ]
Diff the time results to each other and convert to nanoseconds if needed. @param float|int $start @param float|int $end @return int
[ "Diff", "the", "time", "results", "to", "each", "other", "and", "convert", "to", "nanoseconds", "if", "needed", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Tracing/Tracing.php#L145-L156
train
nuwave/lighthouse
src/Schema/Types/Scalars/Date.php
Date.serialize
public function serialize($value): string { if ($value instanceof Carbon) { return $value->toDateString(); } return $this->tryParsingDate($value, InvariantViolation::class) ->toDateString(); }
php
public function serialize($value): string { if ($value instanceof Carbon) { return $value->toDateString(); } return $this->tryParsingDate($value, InvariantViolation::class) ->toDateString(); }
[ "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. @param \Carbon\Carbon|string $value @return string
[ "Serialize", "an", "internal", "value", "ensuring", "it", "is", "a", "valid", "date", "string", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Types/Scalars/Date.php#L21-L29
train
nuwave/lighthouse
src/Schema/Values/CacheValue.php
CacheValue.getKey
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, ]); }
php
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, ]); }
[ "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. @return string
[ "Resolve", "key", "from", "root", "value", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Values/CacheValue.php#L68-L86
train
nuwave/lighthouse
src/Schema/Values/CacheValue.php
CacheValue.getTags
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]; }
php
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]; }
[ "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. @todo Check to see if tags are available on the cache store (or add to config) and use tags to flush cache w/out args. @return array
[ "Get", "cache", "tags", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Values/CacheValue.php#L97-L113
train
nuwave/lighthouse
src/Schema/Values/CacheValue.php
CacheValue.argKeys
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}"; }); }
php
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}"; }); }
[ "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. @return \Illuminate\Support\Collection
[ "Convert", "input", "arguments", "to", "keys", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Values/CacheValue.php#L120-L133
train
nuwave/lighthouse
src/Schema/Values/CacheValue.php
CacheValue.setFieldKey
protected function setFieldKey() { if (! $this->fieldValue || ! $this->rootValue) { return; } $cacheFieldKey = $this->fieldValue ->getParent() ->getCacheKey(); if ($cacheFieldKey) { $this->fieldKey = data_get($this->rootValue, $cacheFieldKey); } }
php
protected function setFieldKey() { if (! $this->fieldValue || ! $this->rootValue) { return; } $cacheFieldKey = $this->fieldValue ->getParent() ->getCacheKey(); if ($cacheFieldKey) { $this->fieldKey = data_get($this->rootValue, $cacheFieldKey); } }
[ "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.
[ "Set", "the", "field", "key", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Values/CacheValue.php#L138-L151
train
nuwave/lighthouse
src/Support/Traits/HasResolverArguments.php
HasResolverArguments.setResolverArguments
public function setResolverArguments($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): self { return $this ->setRoot($root) ->setArgs($args) ->setContext($context) ->setResolveInfo($resolveInfo); }
php
public function setResolverArguments($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): self { return $this ->setRoot($root) ->setArgs($args) ->setContext($context) ->setResolveInfo($resolveInfo); }
[ "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. @param mixed|null $root @param mixed[] $args @param \Nuwave\Lighthouse\Support\Contracts\GraphQLContext $context @param \GraphQL\Type\Definition\ResolveInfo $resolveInfo @return $this
[ "Set", "all", "resolver", "arguments", "at", "once", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Traits/HasResolverArguments.php#L115-L122
train
nuwave/lighthouse
src/Support/Utils.php
Utils.namespaceClassname
public static function namespaceClassname(string $classCandidate, array $namespacesToTry, callable $determineMatch): ?string { if ($determineMatch($classCandidate)) { return $classCandidate; } // Stop if the class is found or we are out of namespaces to try while (! empty($namespacesToTry)) { // Pop off the first namespace and try it $className = array_shift($namespacesToTry).'\\'.$classCandidate; if ($determineMatch($className)) { return $className; } } return null; }
php
public static function namespaceClassname(string $classCandidate, array $namespacesToTry, callable $determineMatch): ?string { if ($determineMatch($classCandidate)) { return $classCandidate; } // Stop if the class is found or we are out of namespaces to try while (! empty($namespacesToTry)) { // Pop off the first namespace and try it $className = array_shift($namespacesToTry).'\\'.$classCandidate; if ($determineMatch($className)) { return $className; } } return null; }
[ "public", "static", "function", "namespaceClassname", "(", "string", "$", "classCandidate", ",", "array", "$", "namespacesToTry", ",", "callable", "$", "determineMatch", ")", ":", "?", "string", "{", "if", "(", "$", "determineMatch", "(", "$", "classCandidate", ")", ")", "{", "return", "$", "classCandidate", ";", "}", "// Stop if the class is found or we are out of namespaces to try", "while", "(", "!", "empty", "(", "$", "namespacesToTry", ")", ")", "{", "// Pop off the first namespace and try it", "$", "className", "=", "array_shift", "(", "$", "namespacesToTry", ")", ".", "'\\\\'", ".", "$", "classCandidate", ";", "if", "(", "$", "determineMatch", "(", "$", "className", ")", ")", "{", "return", "$", "className", ";", "}", "}", "return", "null", ";", "}" ]
Attempt to find a given class in the given namespaces. If the class itself exists, it is simply returned as is. Else, the given namespaces are tried in order. @param string $classCandidate @param array $namespacesToTry @param callable $determineMatch @return string|null
[ "Attempt", "to", "find", "a", "given", "class", "in", "the", "given", "namespaces", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Utils.php#L21-L38
train
nuwave/lighthouse
src/Support/Utils.php
Utils.constructResolver
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]); }
php
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]); }
[ "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. @param string $className This class is resolved through the container. @param string $methodName The method that gets passed the arguments of the closure. @return \Closure @throws \Nuwave\Lighthouse\Exceptions\DefinitionException
[ "Construct", "a", "closure", "that", "passes", "through", "the", "arguments", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Utils.php#L49-L56
train
nuwave/lighthouse
src/Defer/Defer.php
Defer.defer
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; }
php
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; }
[ "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. @param \Closure $resolver @param string $path @return mixed
[ "Register", "deferred", "field", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Defer/Defer.php#L107-L118
train
nuwave/lighthouse
src/Defer/Defer.php
Defer.resolve
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(); }
php
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(); }
[ "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. @param \Closure $originalResolver @param string $path @return mixed
[ "Resolve", "field", "with", "data", "or", "resolver", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Defer/Defer.php#L145-L159
train
nuwave/lighthouse
src/Defer/Defer.php
Defer.createResponse
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); } // TODO: Allow nested_levels to be set in config // to break out of loop early. while ( count($this->deferred) && ! $this->executionTimeExpired() && ! $this->maxNestedFieldsResolved($nested) ) { $nested++; $this->executeDeferred(); } // We've hit the max execution time or max nested levels of deferred fields. // We process remaining deferred fields, but are no longer allowing additional // fields to be deferred. if (count($this->deferred)) { $this->acceptFurtherDeferring = false; $this->executeDeferred(); } }, 200, [ // TODO: Allow headers to be set in config 'X-Accel-Buffering' => 'no', 'Content-Type' => 'multipart/mixed; boundary="-"', ] ); }
php
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); } // TODO: Allow nested_levels to be set in config // to break out of loop early. while ( count($this->deferred) && ! $this->executionTimeExpired() && ! $this->maxNestedFieldsResolved($nested) ) { $nested++; $this->executeDeferred(); } // We've hit the max execution time or max nested levels of deferred fields. // We process remaining deferred fields, but are no longer allowing additional // fields to be deferred. if (count($this->deferred)) { $this->acceptFurtherDeferring = false; $this->executeDeferred(); } }, 200, [ // TODO: Allow headers to be set in config 'X-Accel-Buffering' => 'no', 'Content-Type' => 'multipart/mixed; boundary="-"', ] ); }
[ "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", ")", ";", "}", "// TODO: Allow nested_levels to be set in config", "// to break out of loop early.", "while", "(", "count", "(", "$", "this", "->", "deferred", ")", "&&", "!", "$", "this", "->", "executionTimeExpired", "(", ")", "&&", "!", "$", "this", "->", "maxNestedFieldsResolved", "(", "$", "nested", ")", ")", "{", "$", "nested", "++", ";", "$", "this", "->", "executeDeferred", "(", ")", ";", "}", "// We've hit the max execution time or max nested levels of deferred fields.", "// We process remaining deferred fields, but are no longer allowing additional", "// fields to be deferred.", "if", "(", "count", "(", "$", "this", "->", "deferred", ")", ")", "{", "$", "this", "->", "acceptFurtherDeferring", "=", "false", ";", "$", "this", "->", "executeDeferred", "(", ")", ";", "}", "}", ",", "200", ",", "[", "// TODO: Allow headers to be set in config", "'X-Accel-Buffering'", "=>", "'no'", ",", "'Content-Type'", "=>", "'multipart/mixed; boundary=\"-\"'", ",", "]", ")", ";", "}" ]
Return either a final response or a stream of responses. @param mixed[] $result @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\StreamedResponse
[ "Return", "either", "a", "final", "response", "or", "a", "stream", "of", "responses", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Defer/Defer.php#L185-L228
train
nuwave/lighthouse
src/Defer/Defer.php
Defer.maxNestedFieldsResolved
protected function maxNestedFieldsResolved(int $nested): bool { if ($this->maxNestedFields === 0) { return false; } return $nested >= $this->maxNestedFields; }
php
protected function maxNestedFieldsResolved(int $nested): bool { if ($this->maxNestedFields === 0) { return false; } return $nested >= $this->maxNestedFields; }
[ "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. @param int $nested @return bool
[ "Check", "if", "the", "maximum", "number", "of", "nested", "field", "has", "been", "resolved", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Defer/Defer.php#L270-L277
train
nuwave/lighthouse
src/Defer/Defer.php
Defer.executeDeferred
protected function executeDeferred(): void { $this->result = app()->call( [$this->graphQL, 'executeRequest'] ); $this->stream->stream( $this->result, $this->resolved, empty($this->deferred) ); $this->resolved = []; }
php
protected function executeDeferred(): void { $this->result = app()->call( [$this->graphQL, 'executeRequest'] ); $this->stream->stream( $this->result, $this->resolved, empty($this->deferred) ); $this->resolved = []; }
[ "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. @return void
[ "Execute", "deferred", "fields", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Defer/Defer.php#L284-L297
train
nuwave/lighthouse
src/Schema/Directives/DeleteDirective.php
DeleteDirective.getSingleArgumentDefinition
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]; }
php
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]; }
[ "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. @return \GraphQL\Language\AST\InputValueDefinitionNode @throws \Nuwave\Lighthouse\Exceptions\DirectiveException
[ "Ensure", "there", "is", "only", "a", "single", "argument", "defined", "on", "the", "field", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/DeleteDirective.php#L104-L113
train
nuwave/lighthouse
src/Schema/AST/ASTBuilder.php
ASTBuilder.build
public function build(string $schema): DocumentAST { $document = DocumentAST::fromSource($schema); // Node manipulators may be defined on type extensions $document = $this->applyNodeManipulators($document); // After they have been applied, we can safely merge them $document = $this->mergeTypeExtensions($document); $document = $this->applyFieldManipulators($document); $document = $this->applyArgManipulators($document); $document = $this->addPaginationInfoTypes($document); $document = $this->addOrderByTypes($document); return $this->addNodeSupport($document); }
php
public function build(string $schema): DocumentAST { $document = DocumentAST::fromSource($schema); // Node manipulators may be defined on type extensions $document = $this->applyNodeManipulators($document); // After they have been applied, we can safely merge them $document = $this->mergeTypeExtensions($document); $document = $this->applyFieldManipulators($document); $document = $this->applyArgManipulators($document); $document = $this->addPaginationInfoTypes($document); $document = $this->addOrderByTypes($document); return $this->addNodeSupport($document); }
[ "public", "function", "build", "(", "string", "$", "schema", ")", ":", "DocumentAST", "{", "$", "document", "=", "DocumentAST", "::", "fromSource", "(", "$", "schema", ")", ";", "// Node manipulators may be defined on type extensions", "$", "document", "=", "$", "this", "->", "applyNodeManipulators", "(", "$", "document", ")", ";", "// After they have been applied, we can safely merge them", "$", "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. @param string $schema @return \Nuwave\Lighthouse\Schema\AST\DocumentAST
[ "Convert", "the", "base", "schema", "string", "into", "an", "AST", "by", "applying", "different", "manipulations", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTBuilder.php#L41-L58
train
nuwave/lighthouse
src/Schema/AST/ASTBuilder.php
ASTBuilder.mergeTypeExtensions
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 ); // Modify the original document by overwriting the definition with the merged one $document->setDefinition($objectType); } ); return $document; }
php
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 ); // Modify the original document by overwriting the definition with the merged one $document->setDefinition($objectType); } ); return $document; }
[ "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", ")", ";", "// Modify the original document by overwriting the definition with the merged one", "$", "document", "->", "setDefinition", "(", "$", "objectType", ")", ";", "}", ")", ";", "return", "$", "document", ";", "}" ]
The final schema must not contain type extensions, so we merge them here. @param \Nuwave\Lighthouse\Schema\AST\DocumentAST $document @return \Nuwave\Lighthouse\Schema\AST\DocumentAST
[ "The", "final", "schema", "must", "not", "contain", "type", "extensions", "so", "we", "merge", "them", "here", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTBuilder.php#L93-L119
train
nuwave/lighthouse
src/Schema/AST/ASTBuilder.php
ASTBuilder.addNodeSupport
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'; }); }); // Only add the node type and node field if a type actually implements them // Otherwise, a validation error is thrown if (! $hasTypeImplementingNode) { return $document; } $globalId = config('lighthouse.global_id_field'); // Double slashes to escape the slashes in the namespace. 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")' ) ); }
php
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'; }); }); // Only add the node type and node field if a type actually implements them // Otherwise, a validation error is thrown if (! $hasTypeImplementingNode) { return $document; } $globalId = config('lighthouse.global_id_field'); // Double slashes to escape the slashes in the namespace. 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")' ) ); }
[ "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'", ";", "}", ")", ";", "}", ")", ";", "// Only add the node type and node field if a type actually implements them", "// Otherwise, a validation error is thrown", "if", "(", "!", "$", "hasTypeImplementingNode", ")", "{", "return", "$", "document", ";", "}", "$", "globalId", "=", "config", "(", "'lighthouse.global_id_field'", ")", ";", "// Double slashes to escape the slashes in the namespace.", "return", "$", "document", "->", "setDefinition", "(", "PartialParser", "::", "interfaceTypeDefinition", "(", "<<<GRAPHQL\n\"Node global interface\"\t\ninterface Node @interface(resolveType: \"Nuwave\\\\\\Lighthouse\\\\\\Schema\\\\\\NodeRegistry@resolveType\") {\t\n \"Global identifier that can be used to resolve any Node implementation.\"\n $globalId: ID!\t\n}\t\nGRAPHQL", ")", ")", "->", "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. @param \Nuwave\Lighthouse\Schema\AST\DocumentAST $document @return \Nuwave\Lighthouse\Schema\AST\DocumentAST
[ "Inject", "the", "node", "type", "and", "a", "node", "field", "into", "Query", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTBuilder.php#L260-L295
train
nuwave/lighthouse
src/Subscriptions/Subscriber.php
Subscriber.unserialize
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; }
php
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; }
[ "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. @param string $subscription @return $this
[ "Unserialize", "subscription", "from", "a", "JSON", "string", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/Subscriber.php#L85-L100
train
nuwave/lighthouse
src/Subscriptions/Subscriber.php
Subscriber.serialize
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) ), ]); }
php
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) ), ]); }
[ "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. @return false|string
[ "Convert", "this", "into", "a", "JSON", "string", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/Subscriber.php#L107-L118
train
nuwave/lighthouse
src/Support/Http/Controllers/GraphQLController.php
GraphQLController.query
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); // When handling multiple requests during the application lifetime, // for example in tests, we need a new GraphQLRequest instance // for each HTTP request, so we forget the singleton here. $this->container->forgetInstance(GraphQLRequest::class); return $response; }
php
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); // When handling multiple requests during the application lifetime, // for example in tests, we need a new GraphQLRequest instance // for each HTTP request, so we forget the singleton here. $this->container->forgetInstance(GraphQLRequest::class); return $response; }
[ "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", ")", ";", "// When handling multiple requests during the application lifetime,", "// for example in tests, we need a new GraphQLRequest instance", "// for each HTTP request, so we forget the singleton here.", "$", "this", "->", "container", "->", "forgetInstance", "(", "GraphQLRequest", "::", "class", ")", ";", "return", "$", "response", ";", "}" ]
Execute GraphQL query. @param \Nuwave\Lighthouse\Execution\GraphQLRequest $request @return \Symfony\Component\HttpFoundation\Response
[ "Execute", "GraphQL", "query", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Http/Controllers/GraphQLController.php#L71-L89
train
nuwave/lighthouse
src/Support/Http/Controllers/GraphQLController.php
GraphQLController.executeBatched
protected function executeBatched(GraphQLRequest $request): array { $results = []; do { $results[] = $this->graphQL->executeRequest($request); } while ($request->advanceBatchIndex()); return $results; }
php
protected function executeBatched(GraphQLRequest $request): array { $results = []; do { $results[] = $this->graphQL->executeRequest($request); } while ($request->advanceBatchIndex()); return $results; }
[ "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. @param \Nuwave\Lighthouse\Execution\GraphQLRequest $request @return mixed[]
[ "Loop", "through", "the", "individual", "batched", "queries", "and", "collect", "the", "results", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Http/Controllers/GraphQLController.php#L97-L105
train
nuwave/lighthouse
src/Execution/Utils/GlobalId.php
GlobalId.decodeID
public function decodeID(string $globalID): string { [$type, $id] = self::decode($globalID); return $id; }
php
public function decodeID(string $globalID): string { [$type, $id] = self::decode($globalID); return $id; }
[ "public", "function", "decodeID", "(", "string", "$", "globalID", ")", ":", "string", "{", "[", "$", "type", ",", "$", "id", "]", "=", "self", "::", "decode", "(", "$", "globalID", ")", ";", "return", "$", "id", ";", "}" ]
Decode the Global ID and get just the ID. @param string $globalID @return string
[ "Decode", "the", "Global", "ID", "and", "get", "just", "the", "ID", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/Utils/GlobalId.php#L50-L55
train
nuwave/lighthouse
src/Execution/Utils/GlobalId.php
GlobalId.decodeType
public function decodeType(string $globalID): string { [$type, $id] = self::decode($globalID); return $type; }
php
public function decodeType(string $globalID): string { [$type, $id] = self::decode($globalID); return $type; }
[ "public", "function", "decodeType", "(", "string", "$", "globalID", ")", ":", "string", "{", "[", "$", "type", ",", "$", "id", "]", "=", "self", "::", "decode", "(", "$", "globalID", ")", ";", "return", "$", "type", ";", "}" ]
Decode the Global ID and get just the type. @param string $globalID @return string
[ "Decode", "the", "Global", "ID", "and", "get", "just", "the", "type", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/Utils/GlobalId.php#L63-L68
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.setRelations
public function setRelations(array $relations): self { // Parse and set the relations. $this->relations = $this->newModelQuery() ->with($relations) ->getEagerLoads(); return $this; }
php
public function setRelations(array $relations): self { // Parse and set the relations. $this->relations = $this->newModelQuery() ->with($relations) ->getEagerLoads(); return $this; }
[ "public", "function", "setRelations", "(", "array", "$", "relations", ")", ":", "self", "{", "// Parse and set the relations.", "$", "this", "->", "relations", "=", "$", "this", "->", "newModelQuery", "(", ")", "->", "with", "(", "$", "relations", ")", "->", "getEagerLoads", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set the relations to be loaded. @param array $relations @return $this
[ "Set", "the", "relations", "to", "be", "loaded", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L52-L60
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.setModels
protected function setModels($models): self { // We can not use the collect() helper here, since we require this // to be an Eloquent Collection $this->models = $models instanceof EloquentCollection ? $models : new EloquentCollection($models); return $this; }
php
protected function setModels($models): self { // We can not use the collect() helper here, since we require this // to be an Eloquent Collection $this->models = $models instanceof EloquentCollection ? $models : new EloquentCollection($models); return $this; }
[ "protected", "function", "setModels", "(", "$", "models", ")", ":", "self", "{", "// We can not use the collect() helper here, since we require this", "// to be an Eloquent Collection", "$", "this", "->", "models", "=", "$", "models", "instanceof", "EloquentCollection", "?", "$", "models", ":", "new", "EloquentCollection", "(", "$", "models", ")", ";", "return", "$", "this", ";", "}" ]
Set one or more Model instances as an EloquentCollection. @param mixed $models @return $this
[ "Set", "one", "or", "more", "Model", "instances", "as", "an", "EloquentCollection", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L90-L99
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.loadRelationsForPage
public function loadRelationsForPage(int $perPage, int $page = 1): self { foreach ($this->relations as $name => $constraints) { $this->loadRelationForPage($perPage, $page, $name, $constraints); } return $this; }
php
public function loadRelationsForPage(int $perPage, int $page = 1): self { foreach ($this->relations as $name => $constraints) { $this->loadRelationForPage($perPage, $page, $name, $constraints); } return $this; }
[ "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. @param int $perPage @param int $page @return $this
[ "Load", "all", "relations", "for", "the", "model", "but", "constrain", "the", "query", "to", "the", "current", "page", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L120-L127
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.loadRelationForPage
public function loadRelationForPage(int $first, int $page, string $relationName, Closure $relationConstraints): self { // Load the count of relations of models, this will be the `total` argument of `Paginator`. // Be aware that this will reload all the models entirely with the count of their relations, // which will bring extra DB queries, always prefer querying without pagination if possible. $this->reloadModelsWithRelationCount(); $relations = $this ->buildRelationsFromModels($relationName, $relationConstraints) ->map( function (Relation $relation) use ($first, $page) { return $relation->forPage($page, $first); } ); /** @var \Illuminate\Database\Eloquent\Collection $relationModels */ $relationModels = $this ->unionAllRelationQueries($relations) ->get(); $this->hydratePivotRelation($relationName, $relationModels); $this->loadDefaultWith($relationModels); $this->associateRelationModels($relationName, $relationModels); $this->convertRelationToPaginator($first, $page, $relationName); return $this; }
php
public function loadRelationForPage(int $first, int $page, string $relationName, Closure $relationConstraints): self { // Load the count of relations of models, this will be the `total` argument of `Paginator`. // Be aware that this will reload all the models entirely with the count of their relations, // which will bring extra DB queries, always prefer querying without pagination if possible. $this->reloadModelsWithRelationCount(); $relations = $this ->buildRelationsFromModels($relationName, $relationConstraints) ->map( function (Relation $relation) use ($first, $page) { return $relation->forPage($page, $first); } ); /** @var \Illuminate\Database\Eloquent\Collection $relationModels */ $relationModels = $this ->unionAllRelationQueries($relations) ->get(); $this->hydratePivotRelation($relationName, $relationModels); $this->loadDefaultWith($relationModels); $this->associateRelationModels($relationName, $relationModels); $this->convertRelationToPaginator($first, $page, $relationName); return $this; }
[ "public", "function", "loadRelationForPage", "(", "int", "$", "first", ",", "int", "$", "page", ",", "string", "$", "relationName", ",", "Closure", "$", "relationConstraints", ")", ":", "self", "{", "// Load the count of relations of models, this will be the `total` argument of `Paginator`.", "// Be aware that this will reload all the models entirely with the count of their relations,", "// which will bring extra DB queries, always prefer querying without pagination if possible.", "$", "this", "->", "reloadModelsWithRelationCount", "(", ")", ";", "$", "relations", "=", "$", "this", "->", "buildRelationsFromModels", "(", "$", "relationName", ",", "$", "relationConstraints", ")", "->", "map", "(", "function", "(", "Relation", "$", "relation", ")", "use", "(", "$", "first", ",", "$", "page", ")", "{", "return", "$", "relation", "->", "forPage", "(", "$", "page", ",", "$", "first", ")", ";", "}", ")", ";", "/** @var \\Illuminate\\Database\\Eloquent\\Collection $relationModels */", "$", "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. The relation will be converted to a `Paginator` instance. @param int $first @param int $page @param string $relationName @param \Closure $relationConstraints @return $this
[ "Load", "only", "one", "page", "of", "relations", "of", "all", "the", "models", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L140-L169
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.buildRelationsFromModels
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]); // Call the constraints $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; } ); }
php
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]); // Call the constraints $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; } ); }
[ "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", "]", ")", ";", "// Call the constraints", "$", "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. @param string $relationName @param \Closure $relationConstraints @return \Illuminate\Support\Collection<\Illuminate\Database\Eloquent\Relations\Relation>
[ "Get", "queries", "to", "fetch", "relationships", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L221-L251
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.loadDefaultWith
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; }
php
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; }
[ "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. @param \Illuminate\Database\Eloquent\Collection<\Illuminate\Database\Eloquent\Model> $collection @return $this
[ "Load", "default", "eager", "loads", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L259-L279
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.getRelationDictionary
public function getRelationDictionary(string $relationName): array { return $this->models ->mapWithKeys( function (Model $model) use ($relationName) { return [$this->buildKey($model->getKey()) => $model->getRelation($relationName)]; } )->all(); }
php
public function getRelationDictionary(string $relationName): array { return $this->models ->mapWithKeys( function (Model $model) use ($relationName) { return [$this->buildKey($model->getKey()) => $model->getRelation($relationName)]; } )->all(); }
[ "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. @param string $relationName @return mixed[]
[ "Get", "an", "associative", "array", "of", "relations", "keyed", "by", "the", "models", "primary", "key", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L300-L308
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.unionAllRelationQueries
protected function unionAllRelationQueries(Collection $relations): EloquentBuilder { return $relations ->reduce( function (EloquentBuilder $builder, Relation $relation) { return $builder->unionAll( $relation->getQuery() ); }, // Use the first query as the initial starting point $relations->shift()->getQuery() ); }
php
protected function unionAllRelationQueries(Collection $relations): EloquentBuilder { return $relations ->reduce( function (EloquentBuilder $builder, Relation $relation) { return $builder->unionAll( $relation->getQuery() ); }, // Use the first query as the initial starting point $relations->shift()->getQuery() ); }
[ "protected", "function", "unionAllRelationQueries", "(", "Collection", "$", "relations", ")", ":", "EloquentBuilder", "{", "return", "$", "relations", "->", "reduce", "(", "function", "(", "EloquentBuilder", "$", "builder", ",", "Relation", "$", "relation", ")", "{", "return", "$", "builder", "->", "unionAll", "(", "$", "relation", "->", "getQuery", "(", ")", ")", ";", "}", ",", "// Use the first query as the initial starting point", "$", "relations", "->", "shift", "(", ")", "->", "getQuery", "(", ")", ")", ";", "}" ]
Merge all the relation queries into a single query with UNION ALL. @param \Illuminate\Support\Collection $relations @return \Illuminate\Database\Eloquent\Builder
[ "Merge", "all", "the", "relation", "queries", "into", "a", "single", "query", "with", "UNION", "ALL", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L316-L328
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.associateRelationModels
protected function associateRelationModels(string $relationName, EloquentCollection $relationModels): self { $relation = $this->getRelationInstance($relationName); $relation->match( $this->models->all(), $relationModels, $relationName ); return $this; }
php
protected function associateRelationModels(string $relationName, EloquentCollection $relationModels): self { $relation = $this->getRelationInstance($relationName); $relation->match( $this->models->all(), $relationModels, $relationName ); return $this; }
[ "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. @param string $relationName @param \Illuminate\Database\Eloquent\Collection $relationModels @return $this
[ "Associate", "the", "collection", "of", "all", "fetched", "relationModels", "back", "with", "their", "parents", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L367-L378
train
nuwave/lighthouse
src/Execution/DataLoader/ModelRelationFetcher.php
ModelRelationFetcher.hydratePivotRelation
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; }
php
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; }
[ "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. @param string $relationName @param \Illuminate\Database\Eloquent\Collection<\Illuminate\Database\Eloquent\Model> $relationModels @return $this
[ "Ensure", "the", "pivot", "relation", "is", "hydrated", "too", "if", "it", "exists", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/ModelRelationFetcher.php#L387-L398
train
nuwave/lighthouse
src/Schema/Conversion/DefinitionNodeConverter.php
DefinitionNodeConverter.convertWrappedDefinitionNode
protected function convertWrappedDefinitionNode($node, array $wrappers = []): Type { // Recursively unwrap the type and save the wrappers if ($node->kind === NodeKind::NON_NULL_TYPE || $node->kind === NodeKind::LIST_TYPE) { $wrappers[] = $node->kind; return $this->convertWrappedDefinitionNode( $node->type, $wrappers ); } // Re-wrap the type by applying the wrappers in the reversed order 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) ); }
php
protected function convertWrappedDefinitionNode($node, array $wrappers = []): Type { // Recursively unwrap the type and save the wrappers if ($node->kind === NodeKind::NON_NULL_TYPE || $node->kind === NodeKind::LIST_TYPE) { $wrappers[] = $node->kind; return $this->convertWrappedDefinitionNode( $node->type, $wrappers ); } // Re-wrap the type by applying the wrappers in the reversed order 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) ); }
[ "protected", "function", "convertWrappedDefinitionNode", "(", "$", "node", ",", "array", "$", "wrappers", "=", "[", "]", ")", ":", "Type", "{", "// Recursively unwrap the type and save the wrappers", "if", "(", "$", "node", "->", "kind", "===", "NodeKind", "::", "NON_NULL_TYPE", "||", "$", "node", "->", "kind", "===", "NodeKind", "::", "LIST_TYPE", ")", "{", "$", "wrappers", "[", "]", "=", "$", "node", "->", "kind", ";", "return", "$", "this", "->", "convertWrappedDefinitionNode", "(", "$", "node", "->", "type", ",", "$", "wrappers", ")", ";", "}", "// Re-wrap the type by applying the wrappers in the reversed order", "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. @param mixed $node @param string[] $wrappers @return \GraphQL\Type\Definition\Type
[ "Unwrap", "the", "node", "if", "needed", "and", "convert", "to", "type", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Conversion/DefinitionNodeConverter.php#L45-L74
train
nuwave/lighthouse
src/Schema/Conversion/DefinitionNodeConverter.php
DefinitionNodeConverter.convertNamedTypeNode
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); } }
php
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); } }
[ "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. @param \GraphQL\Language\AST\NamedTypeNode $node @return \GraphQL\Type\Definition\Type
[ "Converted", "named", "node", "to", "type", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Conversion/DefinitionNodeConverter.php#L82-L99
train
nuwave/lighthouse
src/Schema/Factories/FieldFactory.php
FieldFactory.handle
public function handle(FieldValue $fieldValue): array { $fieldDefinitionNode = $fieldValue->getField(); // Directives have the first priority for defining a resolver for a field 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(); // Apply the argument spreadings after we are finished with all // the other argument handling 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 ); // The final resolver can access the builder through the ResolveInfo $this->resolveInfo->builder = $this->builder; return $resolverWithMiddleware($this->root, $this->args, $this->context, $this->resolveInfo); } ); // To see what is allowed here, look at the validation rules in // GraphQL\Type\Definition\FieldDefinition::getDefinition() 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(), ]; }
php
public function handle(FieldValue $fieldValue): array { $fieldDefinitionNode = $fieldValue->getField(); // Directives have the first priority for defining a resolver for a field 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(); // Apply the argument spreadings after we are finished with all // the other argument handling 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 ); // The final resolver can access the builder through the ResolveInfo $this->resolveInfo->builder = $this->builder; return $resolverWithMiddleware($this->root, $this->args, $this->context, $this->resolveInfo); } ); // To see what is allowed here, look at the validation rules in // GraphQL\Type\Definition\FieldDefinition::getDefinition() 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(), ]; }
[ "public", "function", "handle", "(", "FieldValue", "$", "fieldValue", ")", ":", "array", "{", "$", "fieldDefinitionNode", "=", "$", "fieldValue", "->", "getField", "(", ")", ";", "// Directives have the first priority for defining a resolver for a field", "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", "(", ")", ";", "// Apply the argument spreadings after we are finished with all", "// the other argument handling", "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", ")", ";", "// The final resolver can access the builder through the ResolveInfo", "$", "this", "->", "resolveInfo", "->", "builder", "=", "$", "this", "->", "builder", ";", "return", "$", "resolverWithMiddleware", "(", "$", "this", "->", "root", ",", "$", "this", "->", "args", ",", "$", "this", "->", "context", ",", "$", "this", "->", "resolveInfo", ")", ";", "}", ")", ";", "// To see what is allowed here, look at the validation rules in", "// GraphQL\\Type\\Definition\\FieldDefinition::getDefinition()", "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. @param \Nuwave\Lighthouse\Schema\Values\FieldValue $fieldValue @return array Configuration array for a FieldDefinition
[ "Convert", "a", "FieldValue", "to", "an", "executable", "FieldDefinition", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/FieldFactory.php#L138-L227
train
nuwave/lighthouse
src/Schema/Factories/FieldFactory.php
FieldFactory.getArgumentValues
protected function getArgumentValues(): Collection { return (new Collection($this->fieldValue->getField()->arguments)) ->map(function (InputValueDefinitionNode $inputValueDefinition): ArgumentValue { return new ArgumentValue($inputValueDefinition, $this->fieldValue); }); }
php
protected function getArgumentValues(): Collection { return (new Collection($this->fieldValue->getField()->arguments)) ->map(function (InputValueDefinitionNode $inputValueDefinition): ArgumentValue { return new ArgumentValue($inputValueDefinition, $this->fieldValue); }); }
[ "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. @return \Illuminate\Support\Collection<\Nuwave\Lighthouse\Schema\Values\ArgumentValue>
[ "Get", "a", "collection", "of", "the", "fields", "argument", "definitions", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/FieldFactory.php#L234-L240
train
nuwave/lighthouse
src/Schema/Factories/FieldFactory.php
FieldFactory.handleArgDirectivesRecursively
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; } // Handle the argument itself. At this point, it can be wrapped // in a list or an input object $this->handleArgWithAssociatedDirectives($type, $astNode, $directives, $argumentPath); // If we no value or null is given, we bail here to prevent // infinitely going down a chain of nested input objects 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) { // here we are passing by reference so the `$argValue[$key]` is intended. $this->handleArgDirectivesRecursively( $type->ofType, $astNode, array_merge($argumentPath, [$index]) ); } } }
php
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; } // Handle the argument itself. At this point, it can be wrapped // in a list or an input object $this->handleArgWithAssociatedDirectives($type, $astNode, $directives, $argumentPath); // If we no value or null is given, we bail here to prevent // infinitely going down a chain of nested input objects 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) { // here we are passing by reference so the `$argValue[$key]` is intended. $this->handleArgDirectivesRecursively( $type->ofType, $astNode, array_merge($argumentPath, [$index]) ); } } }
[ "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", ";", "}", "// Handle the argument itself. At this point, it can be wrapped", "// in a list or an input object", "$", "this", "->", "handleArgWithAssociatedDirectives", "(", "$", "type", ",", "$", "astNode", ",", "$", "directives", ",", "$", "argumentPath", ")", ";", "// If we no value or null is given, we bail here to prevent", "// infinitely going down a chain of nested input objects", "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", ")", "{", "// here we are passing by reference so the `$argValue[$key]` is intended.", "$", "this", "->", "handleArgDirectivesRecursively", "(", "$", "type", "->", "ofType", ",", "$", "astNode", ",", "array_merge", "(", "$", "argumentPath", ",", "[", "$", "index", "]", ")", ")", ";", "}", "}", "}" ]
Handle the ArgMiddleware. @param \GraphQL\Type\Definition\InputType $type @param \GraphQL\Language\AST\InputValueDefinitionNode $astNode @param mixed[] $argumentPath @return void
[ "Handle", "the", "ArgMiddleware", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/FieldFactory.php#L250-L306
train
nuwave/lighthouse
src/Schema/Factories/FieldFactory.php
FieldFactory.validateArgs
protected function validateArgs(): void { if (! $this->rules) { return; } $validator = validator( $this->args, $this->rules, $this->messages, [ 'root' => $this->root, 'context' => $this->context, // This makes it so that we get an instance of our own Validator class '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]." ); // reset rules and messages $this->rules = []; $this->messages = []; }
php
protected function validateArgs(): void { if (! $this->rules) { return; } $validator = validator( $this->args, $this->rules, $this->messages, [ 'root' => $this->root, 'context' => $this->context, // This makes it so that we get an instance of our own Validator class '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]." ); // reset rules and messages $this->rules = []; $this->messages = []; }
[ "protected", "function", "validateArgs", "(", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "rules", ")", "{", "return", ";", "}", "$", "validator", "=", "validator", "(", "$", "this", "->", "args", ",", "$", "this", "->", "rules", ",", "$", "this", "->", "messages", ",", "[", "'root'", "=>", "$", "this", "->", "root", ",", "'context'", "=>", "$", "this", "->", "context", ",", "// This makes it so that we get an instance of our own Validator class", "'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].\"", ")", ";", "// reset rules and messages", "$", "this", "->", "rules", "=", "[", "]", ";", "$", "this", "->", "messages", "=", "[", "]", ";", "}" ]
Run the gathered validation rules on the arguments. @return void
[ "Run", "the", "gathered", "validation", "rules", "on", "the", "arguments", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/FieldFactory.php#L437-L474
train
nuwave/lighthouse
src/Schema/Factories/FieldFactory.php
FieldFactory.resumeHandlingArgDirectives
protected function resumeHandlingArgDirectives(): void { // copy and reset $snapshots = $this->handleArgDirectivesSnapshots; $this->handleArgDirectivesSnapshots = []; foreach ($snapshots as $handlerArgs) { $this->handleArgDirectives(...$handlerArgs); } // We might have hit more validation-relevant directives so we recurse if (count($this->handleArgDirectivesSnapshots) > 0) { $this->runArgDirectives(); } }
php
protected function resumeHandlingArgDirectives(): void { // copy and reset $snapshots = $this->handleArgDirectivesSnapshots; $this->handleArgDirectivesSnapshots = []; foreach ($snapshots as $handlerArgs) { $this->handleArgDirectives(...$handlerArgs); } // We might have hit more validation-relevant directives so we recurse if (count($this->handleArgDirectivesSnapshots) > 0) { $this->runArgDirectives(); } }
[ "protected", "function", "resumeHandlingArgDirectives", "(", ")", ":", "void", "{", "// copy and reset", "$", "snapshots", "=", "$", "this", "->", "handleArgDirectivesSnapshots", ";", "$", "this", "->", "handleArgDirectivesSnapshots", "=", "[", "]", ";", "foreach", "(", "$", "snapshots", "as", "$", "handlerArgs", ")", "{", "$", "this", "->", "handleArgDirectives", "(", "...", "$", "handlerArgs", ")", ";", "}", "// We might have hit more validation-relevant directives so we recurse", "if", "(", "count", "(", "$", "this", "->", "handleArgDirectivesSnapshots", ")", ">", "0", ")", "{", "$", "this", "->", "runArgDirectives", "(", ")", ";", "}", "}" ]
Continue evaluating the arg directives after validation has run. @return void
[ "Continue", "evaluating", "the", "arg", "directives", "after", "validation", "has", "run", "." ]
f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8
https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/FieldFactory.php#L481-L495
train