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
kaoken/markdown-it-php
src/MarkdownIt/MarkdownIt.php
MarkdownIt.enable
public function enable($list, $ignoreInvalid=false) { $result = []; if (!is_array($list)) { $list = [ $list ]; } foreach ([ 'core', 'block', 'inline' ] as &$chain) { if( !property_exists($this,$chain) ) continue; $result = array_merge($result, $this->{$chain}->ruler->enable($list, true)); } $result = array_merge($result, $this->inline->ruler2->enable($list, true) ); $missed = array_filter ($list, function ($name) use(&$result) { return array_search ($name, $result) === false; }); if (count($missed) !== 0 && !$ignoreInvalid) { throw new \Exception('MarkdownIt. Failed to enable unknown rule(s): ' . implode(', ', $missed)); } return $this; }
php
public function enable($list, $ignoreInvalid=false) { $result = []; if (!is_array($list)) { $list = [ $list ]; } foreach ([ 'core', 'block', 'inline' ] as &$chain) { if( !property_exists($this,$chain) ) continue; $result = array_merge($result, $this->{$chain}->ruler->enable($list, true)); } $result = array_merge($result, $this->inline->ruler2->enable($list, true) ); $missed = array_filter ($list, function ($name) use(&$result) { return array_search ($name, $result) === false; }); if (count($missed) !== 0 && !$ignoreInvalid) { throw new \Exception('MarkdownIt. Failed to enable unknown rule(s): ' . implode(', ', $missed)); } return $this; }
[ "public", "function", "enable", "(", "$", "list", ",", "$", "ignoreInvalid", "=", "false", ")", "{", "$", "result", "=", "[", "]", ";", "if", "(", "!", "is_array", "(", "$", "list", ")", ")", "{", "$", "list", "=", "[", "$", "list", "]", ";", ...
chainable Enable list or rules. It will automatically find appropriate components, containing rules with given names. If rule not found, and `ignoreInvalid` not set - throws exception. ##### Example ```PHP $md = new MarkdownIt(); $md->enable(['sub', 'sup']) ->disable('smartquotes'); ``` @param string|array $list rule name or list of rule names to enable @param boolean $ignoreInvalid set `true` to ignore errors when rule not found. @return $this
[ "chainable", "Enable", "list", "or", "rules", ".", "It", "will", "automatically", "find", "appropriate", "components", "containing", "rules", "with", "given", "names", ".", "If", "rule", "not", "found", "and", "ignoreInvalid", "not", "set", "-", "throws", "exc...
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/MarkdownIt.php#L458-L479
train
kaoken/markdown-it-php
src/MarkdownIt/Ruler.php
Ruler.at
public function at($name, $entity, $options=null) { $index = $this->__find__($name); if( is_object($options) ) $opt = $options; else $opt = is_array($options) ? (object)$options : new \stdClass(); if ($index === -1) { throw new \Exception('Parser rule not found: ' . $name); } $this->__rules__[$index]->setEntity($entity); $this->__rules__[$index]->alt = isset($opt->alt) ? $opt->alt : []; $this->__cache__ = null; }
php
public function at($name, $entity, $options=null) { $index = $this->__find__($name); if( is_object($options) ) $opt = $options; else $opt = is_array($options) ? (object)$options : new \stdClass(); if ($index === -1) { throw new \Exception('Parser rule not found: ' . $name); } $this->__rules__[$index]->setEntity($entity); $this->__rules__[$index]->alt = isset($opt->alt) ? $opt->alt : []; $this->__cache__ = null; }
[ "public", "function", "at", "(", "$", "name", ",", "$", "entity", ",", "$", "options", "=", "null", ")", "{", "$", "index", "=", "$", "this", "->", "__find__", "(", "$", "name", ")", ";", "if", "(", "is_object", "(", "$", "options", ")", ")", "...
Replace rule by name with new function & options. Throws error if name not found. ##### Options: - __alt__ - array with names of "alternate" chains. ##### Example Replace existing typographer replacement rule with new one: ```PHP class Instance{ public property($state){...} } $md = new Mmarkdown-It(); $md->core->ruler->at('replacements', [new Instance(), 'property']); // or $md->core->ruler->at('replacements', function replace($state) { //... }); ``` @param string $name rule name to replace. @param callable|array $entity new rule function or instance. @param object $options new rule options (not mandatory).
[ "Replace", "rule", "by", "name", "with", "new", "function", "&", "options", ".", "Throws", "error", "if", "name", "not", "found", "." ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/Ruler.php#L125-L136
train
kaoken/markdown-it-php
src/MarkdownIt/Ruler.php
Ruler.enable
public function enable($list, $ignoreInvalid=false) { if (!is_array($list)) { $list = [ $list ]; } $result = []; // Search by $name and enable foreach ($list as &$name){ $idx = $this->__find__($name); if ($idx < 0) { if ($ignoreInvalid) continue; throw new \Exception("Rules manager: invalid rule name '{$name}''"); } $this->__rules__[$idx]->enabled = true; $result[] = $name; } $this->__cache__ = null; return $result; }
php
public function enable($list, $ignoreInvalid=false) { if (!is_array($list)) { $list = [ $list ]; } $result = []; // Search by $name and enable foreach ($list as &$name){ $idx = $this->__find__($name); if ($idx < 0) { if ($ignoreInvalid) continue; throw new \Exception("Rules manager: invalid rule name '{$name}''"); } $this->__rules__[$idx]->enabled = true; $result[] = $name; } $this->__cache__ = null; return $result; }
[ "public", "function", "enable", "(", "$", "list", ",", "$", "ignoreInvalid", "=", "false", ")", "{", "if", "(", "!", "is_array", "(", "$", "list", ")", ")", "{", "$", "list", "=", "[", "$", "list", "]", ";", "}", "$", "result", "=", "[", "]", ...
Enable rules with given names. If any rule name not found - throw Error. Errors can be disabled by second param. Returns list of found rule names (if no exception happened). See also [[Ruler.disable]], [[Ruler.enableOnly]]. @param string|array $list list of rule names to enable. @param boolean $ignoreInvalid set `true` to ignore errors when $rule not found. @return array
[ "Enable", "rules", "with", "given", "names", ".", "If", "any", "rule", "name", "not", "found", "-", "throw", "Error", ".", "Errors", "can", "be", "disabled", "by", "second", "param", "." ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/Ruler.php#L291-L311
train
kaoken/markdown-it-php
src/MarkdownIt/Ruler.php
Ruler.enableOnly
public function enableOnly($list, $ignoreInvalid=false) { if (!is_array($list)) { $list = [ $list ]; } foreach ($this->__rules__ as &$rule) { $rule->enabled = false; } $this->enable($list, $ignoreInvalid); }
php
public function enableOnly($list, $ignoreInvalid=false) { if (!is_array($list)) { $list = [ $list ]; } foreach ($this->__rules__ as &$rule) { $rule->enabled = false; } $this->enable($list, $ignoreInvalid); }
[ "public", "function", "enableOnly", "(", "$", "list", ",", "$", "ignoreInvalid", "=", "false", ")", "{", "if", "(", "!", "is_array", "(", "$", "list", ")", ")", "{", "$", "list", "=", "[", "$", "list", "]", ";", "}", "foreach", "(", "$", "this", ...
Enable rules with given names, and disable everything else. If any rule name not found - throw Error. Errors can be disabled by second param. See also [[Ruler.disable]], [[Ruler.enable]]. @param array|string $list list of rule names to enable (whitelist). @param bool $ignoreInvalid set `true` to ignore errors when $rule not found.
[ "Enable", "rules", "with", "given", "names", "and", "disable", "everything", "else", ".", "If", "any", "rule", "name", "not", "found", "-", "throw", "Error", ".", "Errors", "can", "be", "disabled", "by", "second", "param", "." ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/Ruler.php#L322-L331
train
kaoken/markdown-it-php
src/MarkdownIt/Common/Utils.php
Utils.arrayReplaceAt
public function arrayReplaceAt($src, $pos, $newElements) { if(empty($newElements))$newElements=[]; return array_merge(array_slice($src, 0, $pos), $newElements, array_slice($src, $pos + 1)); }
php
public function arrayReplaceAt($src, $pos, $newElements) { if(empty($newElements))$newElements=[]; return array_merge(array_slice($src, 0, $pos), $newElements, array_slice($src, $pos + 1)); }
[ "public", "function", "arrayReplaceAt", "(", "$", "src", ",", "$", "pos", ",", "$", "newElements", ")", "{", "if", "(", "empty", "(", "$", "newElements", ")", ")", "$", "newElements", "=", "[", "]", ";", "return", "array_merge", "(", "array_slice", "("...
Remove element from array and put another array at those position. Useful for some operations with tokens @param array $src @param integer $pos @param array $newElements @return array
[ "Remove", "element", "from", "array", "and", "put", "another", "array", "at", "those", "position", ".", "Useful", "for", "some", "operations", "with", "tokens" ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/Common/Utils.php#L131-L135
train
kaoken/markdown-it-php
src/MarkdownIt/Common/Utils.php
Utils.fromCodePoint
public function fromCodePoint($c) { if ($c < 0x7F) // U+0000-U+007F - 1 byte return chr($c); if ($c < 0x7FF) // U+0080-U+07FF - 2 bytes return chr(0xC0 | ($c >> 6)) . chr(0x80 | ($c & 0x3F)); if ($c < 0xFFFF) // U+0800-U+FFFF - 3 bytes return chr(0xE0 | ($c >> 12)) . chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F)); // U+010000-U+10FFFF - 4 bytes return chr(0xF0 | ($c >> 18)) . chr(0x80 | ($c >> 12) & 0x3F) .chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F)); }
php
public function fromCodePoint($c) { if ($c < 0x7F) // U+0000-U+007F - 1 byte return chr($c); if ($c < 0x7FF) // U+0080-U+07FF - 2 bytes return chr(0xC0 | ($c >> 6)) . chr(0x80 | ($c & 0x3F)); if ($c < 0xFFFF) // U+0800-U+FFFF - 3 bytes return chr(0xE0 | ($c >> 12)) . chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F)); // U+010000-U+10FFFF - 4 bytes return chr(0xF0 | ($c >> 18)) . chr(0x80 | ($c >> 12) & 0x3F) .chr(0x80 | (($c >> 6) & 0x3F)) . chr(0x80 | ($c & 0x3F)); }
[ "public", "function", "fromCodePoint", "(", "$", "c", ")", "{", "if", "(", "$", "c", "<", "0x7F", ")", "// U+0000-U+007F - 1 byte", "return", "chr", "(", "$", "c", ")", ";", "if", "(", "$", "c", "<", "0x7FF", ")", "// U+0080-U+07FF - 2 bytes", "return", ...
UTF16 -> UTF8 @param integer $c @return string
[ "UTF16", "-", ">", "UTF8" ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/Common/Utils.php#L178-L188
train
kaoken/markdown-it-php
src/MarkdownIt/Common/Utils.php
Utils.isMdAsciiPunct
public function isMdAsciiPunct($c) { $code = ord($c); if( ( $code >= 0x21 /* ! */ && $code <= 0x2F /* / */) || ( $code >= 0x3A /* : */ && $code <= 0x40 /* @ */) || ( $code >= 0x5B /* [ */ && $code <= 0x60 /* ` */) || ( $code >= 0x7B /* { */ && $code <= 0x7E /* ~ */) ) return true; return false; }
php
public function isMdAsciiPunct($c) { $code = ord($c); if( ( $code >= 0x21 /* ! */ && $code <= 0x2F /* / */) || ( $code >= 0x3A /* : */ && $code <= 0x40 /* @ */) || ( $code >= 0x5B /* [ */ && $code <= 0x60 /* ` */) || ( $code >= 0x7B /* { */ && $code <= 0x7E /* ~ */) ) return true; return false; }
[ "public", "function", "isMdAsciiPunct", "(", "$", "c", ")", "{", "$", "code", "=", "ord", "(", "$", "c", ")", ";", "if", "(", "(", "$", "code", ">=", "0x21", "/* ! */", "&&", "$", "code", "<=", "0x2F", "/* / */", ")", "||", "(", "$", "code", ">...
Markdown ASCII punctuation characters. !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~ @see http://spec.commonmark.org/0.15/#ascii-punctuation-character Don't confuse with unicode punctuation !!! It lacks some chars in ascii range. @param string $c @return bool
[ "Markdown", "ASCII", "punctuation", "characters", "." ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/Common/Utils.php#L318-L327
train
kaoken/markdown-it-php
src/MarkdownIt/Plugins/MarkdownItForInline.php
MarkdownItForInline.plugin
public function plugin($md, $ruleName, $tokenType, $iteartor) { $scan = function($state) use($md, $ruleName, $tokenType, $iteartor) { for ($blkIdx = count($state->tokens) - 1; $blkIdx >= 0; $blkIdx--) { if ($state->tokens[$blkIdx]->type !== 'inline') { continue; } $inlineTokens = $state->tokens[$blkIdx]->children; for ($i = count($inlineTokens) - 1; $i >= 0; $i--) { if ($inlineTokens[$i]->type !== $tokenType) { continue; } $iteartor($inlineTokens, $i); } } }; $md->core->ruler->push($ruleName, $scan); }
php
public function plugin($md, $ruleName, $tokenType, $iteartor) { $scan = function($state) use($md, $ruleName, $tokenType, $iteartor) { for ($blkIdx = count($state->tokens) - 1; $blkIdx >= 0; $blkIdx--) { if ($state->tokens[$blkIdx]->type !== 'inline') { continue; } $inlineTokens = $state->tokens[$blkIdx]->children; for ($i = count($inlineTokens) - 1; $i >= 0; $i--) { if ($inlineTokens[$i]->type !== $tokenType) { continue; } $iteartor($inlineTokens, $i); } } }; $md->core->ruler->push($ruleName, $scan); }
[ "public", "function", "plugin", "(", "$", "md", ",", "$", "ruleName", ",", "$", "tokenType", ",", "$", "iteartor", ")", "{", "$", "scan", "=", "function", "(", "$", "state", ")", "use", "(", "$", "md", ",", "$", "ruleName", ",", "$", "tokenType", ...
MarkdownItForInline constructor. @param \Kaoken\MarkdownIt\MarkdownIt $md @param string $ruleName @param string $tokenType @param callable $iteartor
[ "MarkdownItForInline", "constructor", "." ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/Plugins/MarkdownItForInline.php#L30-L51
train
kaoken/markdown-it-php
src/MarkdownIt/RulesBlock/StateBlock.php
StateBlock.skipSpaces
public function skipSpaces($pos) { for ( $max = strlen ($this->src); $pos < $max; $pos++) { if (!$this->md->utils->isSpace($this->src[$pos])) { break; } } return $pos; }
php
public function skipSpaces($pos) { for ( $max = strlen ($this->src); $pos < $max; $pos++) { if (!$this->md->utils->isSpace($this->src[$pos])) { break; } } return $pos; }
[ "public", "function", "skipSpaces", "(", "$", "pos", ")", "{", "for", "(", "$", "max", "=", "strlen", "(", "$", "this", "->", "src", ")", ";", "$", "pos", "<", "$", "max", ";", "$", "pos", "++", ")", "{", "if", "(", "!", "$", "this", "->", ...
Skip spaces from given position. @param integer $pos @return integer
[ "Skip", "spaces", "from", "given", "position", "." ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/RulesBlock/StateBlock.php#L216-L223
train
kaoken/markdown-it-php
src/MarkdownIt/RulesBlock/StateBlock.php
StateBlock.skipSpacesBack
public function skipSpacesBack($pos, $min) { if ($pos <= $min) { return $pos; } while ($pos > $min) { if (!$this->md->utils->isSpace($this->src[--$pos])) { return $pos + 1; } } return $pos; }
php
public function skipSpacesBack($pos, $min) { if ($pos <= $min) { return $pos; } while ($pos > $min) { if (!$this->md->utils->isSpace($this->src[--$pos])) { return $pos + 1; } } return $pos; }
[ "public", "function", "skipSpacesBack", "(", "$", "pos", ",", "$", "min", ")", "{", "if", "(", "$", "pos", "<=", "$", "min", ")", "{", "return", "$", "pos", ";", "}", "while", "(", "$", "pos", ">", "$", "min", ")", "{", "if", "(", "!", "$", ...
Skip spaces from given position in reverse. @param integer $pos @param integer $min @return integer
[ "Skip", "spaces", "from", "given", "position", "in", "reverse", "." ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/RulesBlock/StateBlock.php#L231-L240
train
kaoken/markdown-it-php
src/MarkdownIt/RulesBlock/StateBlock.php
StateBlock.skipChars
public function skipChars($pos, $code) { for ($max = strlen ($this->src); $pos < $max; $pos++) { if ($this->src[$pos] !== $code) { break; } } return $pos; }
php
public function skipChars($pos, $code) { for ($max = strlen ($this->src); $pos < $max; $pos++) { if ($this->src[$pos] !== $code) { break; } } return $pos; }
[ "public", "function", "skipChars", "(", "$", "pos", ",", "$", "code", ")", "{", "for", "(", "$", "max", "=", "strlen", "(", "$", "this", "->", "src", ")", ";", "$", "pos", "<", "$", "max", ";", "$", "pos", "++", ")", "{", "if", "(", "$", "t...
Skip char codes from given position @param integer $pos @param string $code @return integer
[ "Skip", "char", "codes", "from", "given", "position" ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/RulesBlock/StateBlock.php#L248-L254
train
kaoken/markdown-it-php
src/MarkdownIt/RulesBlock/StateBlock.php
StateBlock.skipCharsBack
public function skipCharsBack($pos, $code, $min) { if ($pos <= $min) { return $pos; } while ($pos > $min) { if ($code !== $this->src[--$pos]) { return $pos + 1; } } return $pos; }
php
public function skipCharsBack($pos, $code, $min) { if ($pos <= $min) { return $pos; } while ($pos > $min) { if ($code !== $this->src[--$pos]) { return $pos + 1; } } return $pos; }
[ "public", "function", "skipCharsBack", "(", "$", "pos", ",", "$", "code", ",", "$", "min", ")", "{", "if", "(", "$", "pos", "<=", "$", "min", ")", "{", "return", "$", "pos", ";", "}", "while", "(", "$", "pos", ">", "$", "min", ")", "{", "if",...
Skip char codes reverse from given position - 1 @param integer $pos @param string $code @param integer $min @return integer
[ "Skip", "char", "codes", "reverse", "from", "given", "position", "-", "1" ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/RulesBlock/StateBlock.php#L263-L271
train
kaoken/markdown-it-php
src/MarkdownIt/RulesBlock/StateBlock.php
StateBlock.getLines
public function getLines($begin, $end, $indent, $keepLastLF) { $line = $begin; if ($begin >= $end) { return ''; } $queue =array_fill(0, $end - $begin, ''); for ($i = 0; $line < $end; $line++, $i++) { $lineIndent = 0; $lineStart = $first = $this->bMarks[$line]; if ($line + 1 < $end || $keepLastLF) { // No need for bounds check because we have fake entry on tail. $last = $this->eMarks[$line] + 1; } else { $last = $this->eMarks[$line]; } while ($first < $last && $lineIndent < $indent) { $ch = $this->src[$first]; if ($this->md->utils->isSpace($ch)) { if ($ch === "\t") { $lineIndent += 4 - ($lineIndent + $this->bsCount[$line]) % 4; } else { $lineIndent++; } } else if ($first - $lineStart < $this->tShift[$line]) { // patched tShift masked characters to look like spaces (blockquotes, list markers) $lineIndent++; } else { break; } $first++; } if ($lineIndent > $indent) { // partially expanding tabs in code blocks, e.g '\t\tfoobar' // with indent=2 becomes ' \tfoobar' $queue[$i] = str_repeat(' ', $lineIndent - $indent) . substr($this->src, $first, $last-$first); } else { $queue[$i] = substr($this->src, $first, $last-$first); } } return join('',$queue); }
php
public function getLines($begin, $end, $indent, $keepLastLF) { $line = $begin; if ($begin >= $end) { return ''; } $queue =array_fill(0, $end - $begin, ''); for ($i = 0; $line < $end; $line++, $i++) { $lineIndent = 0; $lineStart = $first = $this->bMarks[$line]; if ($line + 1 < $end || $keepLastLF) { // No need for bounds check because we have fake entry on tail. $last = $this->eMarks[$line] + 1; } else { $last = $this->eMarks[$line]; } while ($first < $last && $lineIndent < $indent) { $ch = $this->src[$first]; if ($this->md->utils->isSpace($ch)) { if ($ch === "\t") { $lineIndent += 4 - ($lineIndent + $this->bsCount[$line]) % 4; } else { $lineIndent++; } } else if ($first - $lineStart < $this->tShift[$line]) { // patched tShift masked characters to look like spaces (blockquotes, list markers) $lineIndent++; } else { break; } $first++; } if ($lineIndent > $indent) { // partially expanding tabs in code blocks, e.g '\t\tfoobar' // with indent=2 becomes ' \tfoobar' $queue[$i] = str_repeat(' ', $lineIndent - $indent) . substr($this->src, $first, $last-$first); } else { $queue[$i] = substr($this->src, $first, $last-$first); } } return join('',$queue); }
[ "public", "function", "getLines", "(", "$", "begin", ",", "$", "end", ",", "$", "indent", ",", "$", "keepLastLF", ")", "{", "$", "line", "=", "$", "begin", ";", "if", "(", "$", "begin", ">=", "$", "end", ")", "{", "return", "''", ";", "}", "$",...
cut lines range from source. @param integer $begin @param integer $end @param integer $indent @param boolean $keepLastLF @return string
[ "cut", "lines", "range", "from", "source", "." ]
ec41aa6d5d700ddeea6819ead10cfbde19d51f8f
https://github.com/kaoken/markdown-it-php/blob/ec41aa6d5d700ddeea6819ead10cfbde19d51f8f/src/MarkdownIt/RulesBlock/StateBlock.php#L281-L332
train
boldenamsterdam/htmlcache
src/services/HtmlcacheService.php
HtmlcacheService.checkForCacheFile
public function checkForCacheFile() { // first check if we can create a file if (!$this->canCreateCacheFile()) { return; } $cacheEntry = HtmlCacheCache::findOne(['uri' => $this->uri, 'siteId' => $this->siteId]); // check if cache exists if ($cacheEntry) { $file = $this->getCacheFileName($cacheEntry->uid); if (file_exists($file)) { // load cache - may return false if cache has expired if ($this->loadCache($file)) { return \Craft::$app->end(); } } } // Turn output buffering on ob_start(); }
php
public function checkForCacheFile() { // first check if we can create a file if (!$this->canCreateCacheFile()) { return; } $cacheEntry = HtmlCacheCache::findOne(['uri' => $this->uri, 'siteId' => $this->siteId]); // check if cache exists if ($cacheEntry) { $file = $this->getCacheFileName($cacheEntry->uid); if (file_exists($file)) { // load cache - may return false if cache has expired if ($this->loadCache($file)) { return \Craft::$app->end(); } } } // Turn output buffering on ob_start(); }
[ "public", "function", "checkForCacheFile", "(", ")", "{", "// first check if we can create a file\r", "if", "(", "!", "$", "this", "->", "canCreateCacheFile", "(", ")", ")", "{", "return", ";", "}", "$", "cacheEntry", "=", "HtmlCacheCache", "::", "findOne", "(",...
Check if cache file exists @return void
[ "Check", "if", "cache", "file", "exists" ]
6c9ff585e5fea99929b029c0fdd27ab52619d035
https://github.com/boldenamsterdam/htmlcache/blob/6c9ff585e5fea99929b029c0fdd27ab52619d035/src/services/HtmlcacheService.php#L51-L71
train
boldenamsterdam/htmlcache
src/services/HtmlcacheService.php
HtmlcacheService.canCreateCacheFile
public function canCreateCacheFile() { // Skip if we're running in devMode and not in force mode if (\Craft::$app->config->general->devMode === true && $this->settings->forceOn == false) { return false; } // skip if not enabled if ($this->settings->enableGeneral == false) { return false; } // Skip if system is not on and not in force mode if (!\Craft::$app->getIsSystemOn() && $this->settings->forceOn == false) { return false; } // Skip if it's a CP Request if (\Craft::$app->request->getIsCpRequest()) { return false; } // Skip if it's an action Request if (\Craft::$app->request->getIsActionRequest()) { return false; } // Skip if it's a preview request if (\Craft::$app->request->getIsLivePreview()) { return false; } // Skip if it's a post request if (!\Craft::$app->request->getIsGet()) { return false; } // Skip if it's an ajax request if (\Craft::$app->request->getIsAjax()) { return false; } // Skip if route from element api if ($this->isElementApiRoute()) { return false; } // Skip if currently requested URL path is excluded if ($this->isPathExcluded()) { return false; } return true; }
php
public function canCreateCacheFile() { // Skip if we're running in devMode and not in force mode if (\Craft::$app->config->general->devMode === true && $this->settings->forceOn == false) { return false; } // skip if not enabled if ($this->settings->enableGeneral == false) { return false; } // Skip if system is not on and not in force mode if (!\Craft::$app->getIsSystemOn() && $this->settings->forceOn == false) { return false; } // Skip if it's a CP Request if (\Craft::$app->request->getIsCpRequest()) { return false; } // Skip if it's an action Request if (\Craft::$app->request->getIsActionRequest()) { return false; } // Skip if it's a preview request if (\Craft::$app->request->getIsLivePreview()) { return false; } // Skip if it's a post request if (!\Craft::$app->request->getIsGet()) { return false; } // Skip if it's an ajax request if (\Craft::$app->request->getIsAjax()) { return false; } // Skip if route from element api if ($this->isElementApiRoute()) { return false; } // Skip if currently requested URL path is excluded if ($this->isPathExcluded()) { return false; } return true; }
[ "public", "function", "canCreateCacheFile", "(", ")", "{", "// Skip if we're running in devMode and not in force mode\r", "if", "(", "\\", "Craft", "::", "$", "app", "->", "config", "->", "general", "->", "devMode", "===", "true", "&&", "$", "this", "->", "setting...
Check if creation of file is allowed @return boolean
[ "Check", "if", "creation", "of", "file", "is", "allowed" ]
6c9ff585e5fea99929b029c0fdd27ab52619d035
https://github.com/boldenamsterdam/htmlcache/blob/6c9ff585e5fea99929b029c0fdd27ab52619d035/src/services/HtmlcacheService.php#L78-L127
train
boldenamsterdam/htmlcache
src/services/HtmlcacheService.php
HtmlcacheService.isElementApiRoute
private function isElementApiRoute() { $plugin = \Craft::$app->getPlugins()->getPlugin('element-api'); if ($plugin) { $elementApiRoutes = $plugin->getSettings()->endpoints; $routes = array_keys($elementApiRoutes); foreach ($routes as $route) { // form the correct expression $route = preg_replace('~\<.*?:(.*?)\>~', '$1', $route); $found = preg_match('~' . $route . '~', $this->uri); if ($found) { return true; } } } return false; }
php
private function isElementApiRoute() { $plugin = \Craft::$app->getPlugins()->getPlugin('element-api'); if ($plugin) { $elementApiRoutes = $plugin->getSettings()->endpoints; $routes = array_keys($elementApiRoutes); foreach ($routes as $route) { // form the correct expression $route = preg_replace('~\<.*?:(.*?)\>~', '$1', $route); $found = preg_match('~' . $route . '~', $this->uri); if ($found) { return true; } } } return false; }
[ "private", "function", "isElementApiRoute", "(", ")", "{", "$", "plugin", "=", "\\", "Craft", "::", "$", "app", "->", "getPlugins", "(", ")", "->", "getPlugin", "(", "'element-api'", ")", ";", "if", "(", "$", "plugin", ")", "{", "$", "elementApiRoutes", ...
Check if route is from element api @return boolean
[ "Check", "if", "route", "is", "from", "element", "api" ]
6c9ff585e5fea99929b029c0fdd27ab52619d035
https://github.com/boldenamsterdam/htmlcache/blob/6c9ff585e5fea99929b029c0fdd27ab52619d035/src/services/HtmlcacheService.php#L134-L150
train
boldenamsterdam/htmlcache
src/services/HtmlcacheService.php
HtmlcacheService.isPathExcluded
private function isPathExcluded() { // determine currently requested URL path and the multi-site ID $requestedPath = \Craft::$app->request->getFullPath(); $requestedSiteId = \Craft::$app->getSites()->getCurrentSite()->id; // compare with excluded paths and sites from the settings if (!empty($this->settings->excludedUrlPaths)) { foreach ($this->settings->excludedUrlPaths as $exclude) { $path = reset($exclude); $siteId = intval(next($exclude)); // check if requested path is one of those of the settings if ($requestedPath == $path || preg_match('@' . $path . '@', $requestedPath)) { // and if requested site either corresponds to the exclude setting or if it's unimportant at all if ($requestedSiteId == $siteId || $siteId < 0) { return true; } } } } return false; }
php
private function isPathExcluded() { // determine currently requested URL path and the multi-site ID $requestedPath = \Craft::$app->request->getFullPath(); $requestedSiteId = \Craft::$app->getSites()->getCurrentSite()->id; // compare with excluded paths and sites from the settings if (!empty($this->settings->excludedUrlPaths)) { foreach ($this->settings->excludedUrlPaths as $exclude) { $path = reset($exclude); $siteId = intval(next($exclude)); // check if requested path is one of those of the settings if ($requestedPath == $path || preg_match('@' . $path . '@', $requestedPath)) { // and if requested site either corresponds to the exclude setting or if it's unimportant at all if ($requestedSiteId == $siteId || $siteId < 0) { return true; } } } } return false; }
[ "private", "function", "isPathExcluded", "(", ")", "{", "// determine currently requested URL path and the multi-site ID\r", "$", "requestedPath", "=", "\\", "Craft", "::", "$", "app", "->", "request", "->", "getFullPath", "(", ")", ";", "$", "requestedSiteId", "=", ...
Check if currently requested URL path has been added to list of excluded paths @return bool
[ "Check", "if", "currently", "requested", "URL", "path", "has", "been", "added", "to", "list", "of", "excluded", "paths" ]
6c9ff585e5fea99929b029c0fdd27ab52619d035
https://github.com/boldenamsterdam/htmlcache/blob/6c9ff585e5fea99929b029c0fdd27ab52619d035/src/services/HtmlcacheService.php#L157-L180
train
boldenamsterdam/htmlcache
src/services/HtmlcacheService.php
HtmlcacheService.createCacheFile
public function createCacheFile() { // check if valid to create the file if ($this->canCreateCacheFile() && http_response_code() == 200) { $cacheEntry = HtmlCacheCache::findOne(['uri' => $this->uri, 'siteId' => $this->siteId]); // check if entry exists and start capturing content if ($cacheEntry) { $content = ob_get_contents(); if($this->settings->optimizeContent){ $content = implode("\n", array_map('trim', explode("\n", $content))); } $file = $this->getCacheFileName($cacheEntry->uid); $fp = fopen($file, 'w+'); if ($fp) { fwrite($fp, $content); fclose($fp); } else { \Craft::info('HTML Cache could not write cache file "' . $file . '"'); } } else { \Craft::info('HTML Cache could not find cache entry for siteId: "' . $this->siteId . '" and uri: "' . $this->uri . '"'); } } }
php
public function createCacheFile() { // check if valid to create the file if ($this->canCreateCacheFile() && http_response_code() == 200) { $cacheEntry = HtmlCacheCache::findOne(['uri' => $this->uri, 'siteId' => $this->siteId]); // check if entry exists and start capturing content if ($cacheEntry) { $content = ob_get_contents(); if($this->settings->optimizeContent){ $content = implode("\n", array_map('trim', explode("\n", $content))); } $file = $this->getCacheFileName($cacheEntry->uid); $fp = fopen($file, 'w+'); if ($fp) { fwrite($fp, $content); fclose($fp); } else { \Craft::info('HTML Cache could not write cache file "' . $file . '"'); } } else { \Craft::info('HTML Cache could not find cache entry for siteId: "' . $this->siteId . '" and uri: "' . $this->uri . '"'); } } }
[ "public", "function", "createCacheFile", "(", ")", "{", "// check if valid to create the file\r", "if", "(", "$", "this", "->", "canCreateCacheFile", "(", ")", "&&", "http_response_code", "(", ")", "==", "200", ")", "{", "$", "cacheEntry", "=", "HtmlCacheCache", ...
Create the cache file @return void
[ "Create", "the", "cache", "file" ]
6c9ff585e5fea99929b029c0fdd27ab52619d035
https://github.com/boldenamsterdam/htmlcache/blob/6c9ff585e5fea99929b029c0fdd27ab52619d035/src/services/HtmlcacheService.php#L187-L210
train
boldenamsterdam/htmlcache
src/services/HtmlcacheService.php
HtmlcacheService.clearCacheFile
public function clearCacheFile($elementId) { // get all possible caches $elements = HtmlCacheElement::findAll(['elementId' => $elementId]); // \craft::Dd($elements); $cacheIds = array_map(function ($el) { return $el->cacheId; }, $elements); // get all possible caches $caches = HtmlCacheCache::findAll(['id' => $cacheIds]); foreach ($caches as $cache) { $file = $this->getCacheFileName($cache->uid); if (file_exists($file)) { @unlink($file); } } // delete caches for related entry HtmlCacheCache::deleteAll(['id' => $cacheIds]); return true; }
php
public function clearCacheFile($elementId) { // get all possible caches $elements = HtmlCacheElement::findAll(['elementId' => $elementId]); // \craft::Dd($elements); $cacheIds = array_map(function ($el) { return $el->cacheId; }, $elements); // get all possible caches $caches = HtmlCacheCache::findAll(['id' => $cacheIds]); foreach ($caches as $cache) { $file = $this->getCacheFileName($cache->uid); if (file_exists($file)) { @unlink($file); } } // delete caches for related entry HtmlCacheCache::deleteAll(['id' => $cacheIds]); return true; }
[ "public", "function", "clearCacheFile", "(", "$", "elementId", ")", "{", "// get all possible caches\r", "$", "elements", "=", "HtmlCacheElement", "::", "findAll", "(", "[", "'elementId'", "=>", "$", "elementId", "]", ")", ";", "// \\craft::Dd($elements);\r", "$", ...
clear cache for given elementId @param integer $elementId @return boolean
[ "clear", "cache", "for", "given", "elementId" ]
6c9ff585e5fea99929b029c0fdd27ab52619d035
https://github.com/boldenamsterdam/htmlcache/blob/6c9ff585e5fea99929b029c0fdd27ab52619d035/src/services/HtmlcacheService.php#L218-L240
train
boldenamsterdam/htmlcache
src/services/HtmlcacheService.php
HtmlcacheService.getDirectory
private function getDirectory() { // Fallback to default directory if no storage path defined if (defined('CRAFT_STORAGE_PATH')) { $basePath = CRAFT_STORAGE_PATH; } else { $basePath = CRAFT_BASE_PATH . DIRECTORY_SEPARATOR . 'storage'; } return $basePath . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . 'htmlcache' . DIRECTORY_SEPARATOR; }
php
private function getDirectory() { // Fallback to default directory if no storage path defined if (defined('CRAFT_STORAGE_PATH')) { $basePath = CRAFT_STORAGE_PATH; } else { $basePath = CRAFT_BASE_PATH . DIRECTORY_SEPARATOR . 'storage'; } return $basePath . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . 'htmlcache' . DIRECTORY_SEPARATOR; }
[ "private", "function", "getDirectory", "(", ")", "{", "// Fallback to default directory if no storage path defined\r", "if", "(", "defined", "(", "'CRAFT_STORAGE_PATH'", ")", ")", "{", "$", "basePath", "=", "CRAFT_STORAGE_PATH", ";", "}", "else", "{", "$", "basePath",...
Get the directory path @return string
[ "Get", "the", "directory", "path" ]
6c9ff585e5fea99929b029c0fdd27ab52619d035
https://github.com/boldenamsterdam/htmlcache/blob/6c9ff585e5fea99929b029c0fdd27ab52619d035/src/services/HtmlcacheService.php#L269-L279
train
boldenamsterdam/htmlcache
src/services/HtmlcacheService.php
HtmlcacheService.loadCache
private function loadCache($file) { if (file_exists($settingsFile = $this->getDirectory() . 'settings.json')) { $settings = json_decode(file_get_contents($settingsFile), true); } elseif (!empty($this->settings->cacheDuration)) { $settings = ['cacheDuration' => $this->settings->cacheDuration]; } else { $settings = ['cacheDuration' => 3600]; } if (time() - ($fmt = filemtime($file)) >= $settings['cacheDuration']) { unlink($file); return false; } \Craft::$app->response->data = file_get_contents($file); return true; }
php
private function loadCache($file) { if (file_exists($settingsFile = $this->getDirectory() . 'settings.json')) { $settings = json_decode(file_get_contents($settingsFile), true); } elseif (!empty($this->settings->cacheDuration)) { $settings = ['cacheDuration' => $this->settings->cacheDuration]; } else { $settings = ['cacheDuration' => 3600]; } if (time() - ($fmt = filemtime($file)) >= $settings['cacheDuration']) { unlink($file); return false; } \Craft::$app->response->data = file_get_contents($file); return true; }
[ "private", "function", "loadCache", "(", "$", "file", ")", "{", "if", "(", "file_exists", "(", "$", "settingsFile", "=", "$", "this", "->", "getDirectory", "(", ")", ".", "'settings.json'", ")", ")", "{", "$", "settings", "=", "json_decode", "(", "file_g...
Check cache and return it if exists @param string $file @return mixed
[ "Check", "cache", "and", "return", "it", "if", "exists" ]
6c9ff585e5fea99929b029c0fdd27ab52619d035
https://github.com/boldenamsterdam/htmlcache/blob/6c9ff585e5fea99929b029c0fdd27ab52619d035/src/services/HtmlcacheService.php#L287-L302
train
mister-bk/craft-plugin-mix
src/twigextensions/MixTwigExtension.php
MixTwigExtension.mix
public function mix($file, $tag = false, $inline = false) { if ($tag) { return Mix::$plugin->mix->withTag($file, $inline); } return Mix::$plugin->mix->version($file); }
php
public function mix($file, $tag = false, $inline = false) { if ($tag) { return Mix::$plugin->mix->withTag($file, $inline); } return Mix::$plugin->mix->version($file); }
[ "public", "function", "mix", "(", "$", "file", ",", "$", "tag", "=", "false", ",", "$", "inline", "=", "false", ")", "{", "if", "(", "$", "tag", ")", "{", "return", "Mix", "::", "$", "plugin", "->", "mix", "->", "withTag", "(", "$", "file", ","...
Returns versioned file or the entire tag. @param string $file @param bool $tag (optional) @param bool $inline (optional) @return string
[ "Returns", "versioned", "file", "or", "the", "entire", "tag", "." ]
bf2a66a6a993be46ba43a719971ec99b2d2db827
https://github.com/mister-bk/craft-plugin-mix/blob/bf2a66a6a993be46ba43a719971ec99b2d2db827/src/twigextensions/MixTwigExtension.php#L56-L63
train
BeatSwitch/lock
stubs/FalseConditionStub.php
FalseConditionStub.assert
public function assert(Lock $lock, Permission $permission, $action, Resource $resource = null) { return false; }
php
public function assert(Lock $lock, Permission $permission, $action, Resource $resource = null) { return false; }
[ "public", "function", "assert", "(", "Lock", "$", "lock", ",", "Permission", "$", "permission", ",", "$", "action", ",", "Resource", "$", "resource", "=", "null", ")", "{", "return", "false", ";", "}" ]
Assert if the condition is correct @param \BeatSwitch\Lock\Lock $lock @param \BeatSwitch\Lock\Permissions\Permission $permission @param string $action @param \BeatSwitch\Lock\Resources\Resource|null $resource @return bool
[ "Assert", "if", "the", "condition", "is", "correct" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/stubs/FalseConditionStub.php#L20-L23
train
BeatSwitch/lock
src/Roles/RoleLock.php
RoleLock.getInheritedRolePermissions
public function getInheritedRolePermissions(Role $role) { $permissions = $this->getPermissionsForRole($role); if ($inheritedRole = $role->getInheritedRole()) { if ($inheritedRole = $this->manager->convertRoleToObject($inheritedRole)) { $permissions = array_merge($permissions, $this->getInheritedRolePermissions($inheritedRole)); } } return $permissions; }
php
public function getInheritedRolePermissions(Role $role) { $permissions = $this->getPermissionsForRole($role); if ($inheritedRole = $role->getInheritedRole()) { if ($inheritedRole = $this->manager->convertRoleToObject($inheritedRole)) { $permissions = array_merge($permissions, $this->getInheritedRolePermissions($inheritedRole)); } } return $permissions; }
[ "public", "function", "getInheritedRolePermissions", "(", "Role", "$", "role", ")", "{", "$", "permissions", "=", "$", "this", "->", "getPermissionsForRole", "(", "$", "role", ")", ";", "if", "(", "$", "inheritedRole", "=", "$", "role", "->", "getInheritedRo...
Returns all the permissions for a role and their inherited roles @param \BeatSwitch\Lock\Roles\Role $role @return \BeatSwitch\Lock\Permissions\Permission[]
[ "Returns", "all", "the", "permissions", "for", "a", "role", "and", "their", "inherited", "roles" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Roles/RoleLock.php#L108-L119
train
BeatSwitch/lock
src/Permissions/AbstractPermission.php
AbstractPermission.matchesPermission
public function matchesPermission(Permission $permission) { return ( $this instanceof $permission && $this->action === $permission->getAction() && // Not using matchesAction to avoid the wildcard $this->matchesResource($permission->getResource()) ); }
php
public function matchesPermission(Permission $permission) { return ( $this instanceof $permission && $this->action === $permission->getAction() && // Not using matchesAction to avoid the wildcard $this->matchesResource($permission->getResource()) ); }
[ "public", "function", "matchesPermission", "(", "Permission", "$", "permission", ")", "{", "return", "(", "$", "this", "instanceof", "$", "permission", "&&", "$", "this", "->", "action", "===", "$", "permission", "->", "getAction", "(", ")", "&&", "// Not us...
Determine if a permission exactly matches the current instance @param \BeatSwitch\Lock\Permissions\Permission $permission @return bool
[ "Determine", "if", "a", "permission", "exactly", "matches", "the", "current", "instance" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/AbstractPermission.php#L43-L50
train
BeatSwitch/lock
src/Permissions/AbstractPermission.php
AbstractPermission.resolve
protected function resolve(Lock $lock, $action, Resource $resource = null) { // If no resource was set for this permission we'll only need to check the action. if ($this->resource === null || $this->resource->getResourceType() === null) { return $this->matchesAction($action) && $this->resolveConditions($lock, $action, $resource); } return ( $this->matchesAction($action) && $this->matchesResource($resource) && $this->resolveConditions($lock, $action, $resource) ); }
php
protected function resolve(Lock $lock, $action, Resource $resource = null) { // If no resource was set for this permission we'll only need to check the action. if ($this->resource === null || $this->resource->getResourceType() === null) { return $this->matchesAction($action) && $this->resolveConditions($lock, $action, $resource); } return ( $this->matchesAction($action) && $this->matchesResource($resource) && $this->resolveConditions($lock, $action, $resource) ); }
[ "protected", "function", "resolve", "(", "Lock", "$", "lock", ",", "$", "action", ",", "Resource", "$", "resource", "=", "null", ")", "{", "// If no resource was set for this permission we'll only need to check the action.", "if", "(", "$", "this", "->", "resource", ...
Validate a permission against the given params. @param \BeatSwitch\Lock\Lock $lock @param string $action @param \BeatSwitch\Lock\Resources\Resource|null $resource @return bool
[ "Validate", "a", "permission", "against", "the", "given", "params", "." ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/AbstractPermission.php#L60-L72
train
BeatSwitch/lock
src/Permissions/AbstractPermission.php
AbstractPermission.matchesResource
protected function matchesResource(Resource $resource = null) { // If the resource is null we should only return true if the current resource is also null. if ($resource === null) { return $this->getResource() === null || ( $this->getResourceType() === null && $this->getResourceId() === null ); } // If the permission's resource id is null then all resources with a specific ID are accepted. if ($this->getResourceId() === null) { return $this->getResourceType() === $resource->getResourceType(); } // Otherwise make sure that we're matching a specific resource. return ( $this->getResourceType() === $resource->getResourceType() && $this->getResourceId() === $resource->getResourceId() ); }
php
protected function matchesResource(Resource $resource = null) { // If the resource is null we should only return true if the current resource is also null. if ($resource === null) { return $this->getResource() === null || ( $this->getResourceType() === null && $this->getResourceId() === null ); } // If the permission's resource id is null then all resources with a specific ID are accepted. if ($this->getResourceId() === null) { return $this->getResourceType() === $resource->getResourceType(); } // Otherwise make sure that we're matching a specific resource. return ( $this->getResourceType() === $resource->getResourceType() && $this->getResourceId() === $resource->getResourceId() ); }
[ "protected", "function", "matchesResource", "(", "Resource", "$", "resource", "=", "null", ")", "{", "// If the resource is null we should only return true if the current resource is also null.", "if", "(", "$", "resource", "===", "null", ")", "{", "return", "$", "this", ...
Validate the resource @param \BeatSwitch\Lock\Resources\Resource|null $resource @return bool
[ "Validate", "the", "resource" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/AbstractPermission.php#L91-L110
train
BeatSwitch/lock
src/Permissions/AbstractPermission.php
AbstractPermission.setConditions
protected function setConditions($conditions = []) { if ($conditions instanceof Closure || is_array($conditions)) { $this->conditions = $conditions; } else { $this->conditions = [$conditions]; } }
php
protected function setConditions($conditions = []) { if ($conditions instanceof Closure || is_array($conditions)) { $this->conditions = $conditions; } else { $this->conditions = [$conditions]; } }
[ "protected", "function", "setConditions", "(", "$", "conditions", "=", "[", "]", ")", "{", "if", "(", "$", "conditions", "instanceof", "Closure", "||", "is_array", "(", "$", "conditions", ")", ")", "{", "$", "this", "->", "conditions", "=", "$", "conditi...
Sets the conditions for this permission @param \BeatSwitch\Lock\Permissions\Condition|\BeatSwitch\Lock\Permissions\Condition[]|\Closure $conditions
[ "Sets", "the", "conditions", "for", "this", "permission" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/AbstractPermission.php#L117-L124
train
BeatSwitch/lock
src/Permissions/AbstractPermission.php
AbstractPermission.resolveConditions
protected function resolveConditions(Lock $lock, $action, $resource) { // If the given condition is a closure, execute it. if ($this->conditions instanceof Closure) { return call_user_func($this->conditions, $lock, $this, $action, $resource); } // If the conditions are an array of Condition objects, check them all. foreach ($this->conditions as $condition) { if (! $condition->assert($lock, $this, $action, $resource)) { return false; } } return true; }
php
protected function resolveConditions(Lock $lock, $action, $resource) { // If the given condition is a closure, execute it. if ($this->conditions instanceof Closure) { return call_user_func($this->conditions, $lock, $this, $action, $resource); } // If the conditions are an array of Condition objects, check them all. foreach ($this->conditions as $condition) { if (! $condition->assert($lock, $this, $action, $resource)) { return false; } } return true; }
[ "protected", "function", "resolveConditions", "(", "Lock", "$", "lock", ",", "$", "action", ",", "$", "resource", ")", "{", "// If the given condition is a closure, execute it.", "if", "(", "$", "this", "->", "conditions", "instanceof", "Closure", ")", "{", "retur...
Check all the conditions and make sure they all return true @param \BeatSwitch\Lock\Lock $lock @param string $action @param \BeatSwitch\Lock\Resources\Resource|null $resource @return bool
[ "Check", "all", "the", "conditions", "and", "make", "sure", "they", "all", "return", "true" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/AbstractPermission.php#L134-L149
train
BeatSwitch/lock
src/Manager.php
Manager.makeCallerLockAware
public function makeCallerLockAware(Caller $caller) { $lock = $this->caller($caller); $caller->setLock($lock); return $caller; }
php
public function makeCallerLockAware(Caller $caller) { $lock = $this->caller($caller); $caller->setLock($lock); return $caller; }
[ "public", "function", "makeCallerLockAware", "(", "Caller", "$", "caller", ")", "{", "$", "lock", "=", "$", "this", "->", "caller", "(", "$", "caller", ")", ";", "$", "caller", "->", "setLock", "(", "$", "lock", ")", ";", "return", "$", "caller", ";"...
Sets the lock instance on caller that implements the LockAware trait @param \BeatSwitch\Lock\Callers\Caller $caller @return \BeatSwitch\Lock\Callers\Caller
[ "Sets", "the", "lock", "instance", "on", "caller", "that", "implements", "the", "LockAware", "trait" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Manager.php#L62-L69
train
BeatSwitch/lock
src/Manager.php
Manager.makeRoleLockAware
public function makeRoleLockAware($role) { $role = $this->convertRoleToObject($role); $lock = $this->role($role); $role->setLock($lock); return $role; }
php
public function makeRoleLockAware($role) { $role = $this->convertRoleToObject($role); $lock = $this->role($role); $role->setLock($lock); return $role; }
[ "public", "function", "makeRoleLockAware", "(", "$", "role", ")", "{", "$", "role", "=", "$", "this", "->", "convertRoleToObject", "(", "$", "role", ")", ";", "$", "lock", "=", "$", "this", "->", "role", "(", "$", "role", ")", ";", "$", "role", "->...
Sets the lock instance on role that implements the LockAware trait @param \BeatSwitch\Lock\Roles\Role|string $role @return \BeatSwitch\Lock\Roles\Role
[ "Sets", "the", "lock", "instance", "on", "role", "that", "implements", "the", "LockAware", "trait" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Manager.php#L77-L85
train
BeatSwitch/lock
src/Manager.php
Manager.setRole
public function setRole($names, $inherit = null) { foreach ((array) $names as $name) { $this->roles[$name] = new SimpleRole($name, $inherit); } }
php
public function setRole($names, $inherit = null) { foreach ((array) $names as $name) { $this->roles[$name] = new SimpleRole($name, $inherit); } }
[ "public", "function", "setRole", "(", "$", "names", ",", "$", "inherit", "=", "null", ")", "{", "foreach", "(", "(", "array", ")", "$", "names", "as", "$", "name", ")", "{", "$", "this", "->", "roles", "[", "$", "name", "]", "=", "new", "SimpleRo...
Add one role to the lock instance @param string|array $names @param string $inherit
[ "Add", "one", "role", "to", "the", "lock", "instance" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Manager.php#L104-L109
train
BeatSwitch/lock
src/Manager.php
Manager.findRole
protected function findRole($role) { // Try to see if we have a role registered for the given // key so we can determine the role's inheritances. if (array_key_exists($role, $this->roles)) { return $this->roles[$role]; } // If we couldn't find a registered role for the // given key, just return a new role object. return new SimpleRole($role); }
php
protected function findRole($role) { // Try to see if we have a role registered for the given // key so we can determine the role's inheritances. if (array_key_exists($role, $this->roles)) { return $this->roles[$role]; } // If we couldn't find a registered role for the // given key, just return a new role object. return new SimpleRole($role); }
[ "protected", "function", "findRole", "(", "$", "role", ")", "{", "// Try to see if we have a role registered for the given", "// key so we can determine the role's inheritances.", "if", "(", "array_key_exists", "(", "$", "role", ",", "$", "this", "->", "roles", ")", ")", ...
Find a role in the roles array @param string $role @return \BeatSwitch\Lock\Roles\Role
[ "Find", "a", "role", "in", "the", "roles", "array" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Manager.php#L128-L139
train
BeatSwitch/lock
src/Callers/CallerLock.php
CallerLock.getLockInstancesForCallerRoles
protected function getLockInstancesForCallerRoles() { return array_map(function ($role) { return $this->manager->role($role); }, $this->caller->getCallerRoles()); }
php
protected function getLockInstancesForCallerRoles() { return array_map(function ($role) { return $this->manager->role($role); }, $this->caller->getCallerRoles()); }
[ "protected", "function", "getLockInstancesForCallerRoles", "(", ")", "{", "return", "array_map", "(", "function", "(", "$", "role", ")", "{", "return", "$", "this", "->", "manager", "->", "role", "(", "$", "role", ")", ";", "}", ",", "$", "this", "->", ...
Get all the lock instances for all the roles of the current caller @return \BeatSwitch\Lock\Roles\RoleLock[]
[ "Get", "all", "the", "lock", "instances", "for", "all", "the", "roles", "of", "the", "current", "caller" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Callers/CallerLock.php#L103-L108
train
BeatSwitch/lock
src/Permissions/PermissionFactory.php
PermissionFactory.createFromData
public static function createFromData($permissions) { return array_map(function ($permission) { if (is_array($permission)) { return PermissionFactory::createFromArray($permission); } else { return PermissionFactory::createFromObject($permission); } }, $permissions); }
php
public static function createFromData($permissions) { return array_map(function ($permission) { if (is_array($permission)) { return PermissionFactory::createFromArray($permission); } else { return PermissionFactory::createFromObject($permission); } }, $permissions); }
[ "public", "static", "function", "createFromData", "(", "$", "permissions", ")", "{", "return", "array_map", "(", "function", "(", "$", "permission", ")", "{", "if", "(", "is_array", "(", "$", "permission", ")", ")", "{", "return", "PermissionFactory", "::", ...
Maps an array of permission data to Permission objects @param array $permissions @return \BeatSwitch\Lock\Permissions\Permission[]
[ "Maps", "an", "array", "of", "permission", "data", "to", "Permission", "objects" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/PermissionFactory.php#L14-L23
train
BeatSwitch/lock
src/Permissions/PermissionFactory.php
PermissionFactory.createFromArray
public static function createFromArray(array $permission) { $type = $permission['type']; // Make sure the id is typecast to an integer. $id = ! is_null($permission['resource_id']) ? (int) $permission['resource_id'] : null; if ($type === Privilege::TYPE) { return new Privilege( $permission['action'], new SimpleResource($permission['resource_type'], $id) ); } elseif ($type === Restriction::TYPE) { return new Restriction( $permission['action'], new SimpleResource($permission['resource_type'], $id) ); } else { throw new InvalidPermissionType("The permission type you provided \"$type\" is incorrect."); } }
php
public static function createFromArray(array $permission) { $type = $permission['type']; // Make sure the id is typecast to an integer. $id = ! is_null($permission['resource_id']) ? (int) $permission['resource_id'] : null; if ($type === Privilege::TYPE) { return new Privilege( $permission['action'], new SimpleResource($permission['resource_type'], $id) ); } elseif ($type === Restriction::TYPE) { return new Restriction( $permission['action'], new SimpleResource($permission['resource_type'], $id) ); } else { throw new InvalidPermissionType("The permission type you provided \"$type\" is incorrect."); } }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "permission", ")", "{", "$", "type", "=", "$", "permission", "[", "'type'", "]", ";", "// Make sure the id is typecast to an integer.", "$", "id", "=", "!", "is_null", "(", "$", "permission", ...
Maps an data array to a permission object @param array $permission @return \BeatSwitch\Lock\Permissions\Permission @throws \BeatSwitch\Lock\Permissions\InvalidPermissionType
[ "Maps", "an", "data", "array", "to", "a", "permission", "object" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/PermissionFactory.php#L32-L52
train
BeatSwitch/lock
src/Permissions/PermissionFactory.php
PermissionFactory.createFromObject
public static function createFromObject($permission) { // Make sure the id is typecast to an integer. $id = ! is_null($permission->resource_id) ? (int) $permission->resource_id : null; if ($permission->type === Privilege::TYPE) { return new Privilege( $permission->action, new SimpleResource($permission->resource_type, $id) ); } elseif ($permission->type === Restriction::TYPE) { return new Restriction( $permission->action, new SimpleResource($permission->resource_type, $id) ); } else { throw new InvalidPermissionType("The permission type you provided \"{$permission->type}\" is incorrect."); } }
php
public static function createFromObject($permission) { // Make sure the id is typecast to an integer. $id = ! is_null($permission->resource_id) ? (int) $permission->resource_id : null; if ($permission->type === Privilege::TYPE) { return new Privilege( $permission->action, new SimpleResource($permission->resource_type, $id) ); } elseif ($permission->type === Restriction::TYPE) { return new Restriction( $permission->action, new SimpleResource($permission->resource_type, $id) ); } else { throw new InvalidPermissionType("The permission type you provided \"{$permission->type}\" is incorrect."); } }
[ "public", "static", "function", "createFromObject", "(", "$", "permission", ")", "{", "// Make sure the id is typecast to an integer.", "$", "id", "=", "!", "is_null", "(", "$", "permission", "->", "resource_id", ")", "?", "(", "int", ")", "$", "permission", "->...
Maps an data object to a permission object @param object $permission @return \BeatSwitch\Lock\Permissions\Permission[] @throws \BeatSwitch\Lock\Permissions\InvalidPermissionType
[ "Maps", "an", "data", "object", "to", "a", "permission", "object" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/PermissionFactory.php#L61-L79
train
BeatSwitch/lock
src/Permissions/Privilege.php
Privilege.isAllowed
public function isAllowed(Lock $lock, $action, Resource $resource = null) { return $this->resolve($lock, $action, $resource); }
php
public function isAllowed(Lock $lock, $action, Resource $resource = null) { return $this->resolve($lock, $action, $resource); }
[ "public", "function", "isAllowed", "(", "Lock", "$", "lock", ",", "$", "action", ",", "Resource", "$", "resource", "=", "null", ")", "{", "return", "$", "this", "->", "resolve", "(", "$", "lock", ",", "$", "action", ",", "$", "resource", ")", ";", ...
Validate a permission against the given params @param \BeatSwitch\Lock\Lock $lock @param string $action @param \BeatSwitch\Lock\Resources\Resource|null $resource @return bool
[ "Validate", "a", "permission", "against", "the", "given", "params" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Permissions/Privilege.php#L23-L26
train
BeatSwitch/lock
src/Drivers/ArrayDriver.php
ArrayDriver.storeCallerPermission
public function storeCallerPermission(Caller $caller, Permission $permission) { $this->permissions[$this->getCallerKey($caller)][] = $permission; }
php
public function storeCallerPermission(Caller $caller, Permission $permission) { $this->permissions[$this->getCallerKey($caller)][] = $permission; }
[ "public", "function", "storeCallerPermission", "(", "Caller", "$", "caller", ",", "Permission", "$", "permission", ")", "{", "$", "this", "->", "permissions", "[", "$", "this", "->", "getCallerKey", "(", "$", "caller", ")", "]", "[", "]", "=", "$", "perm...
Stores a new permission into the driver for a caller @param \BeatSwitch\Lock\Callers\Caller $caller @param \BeatSwitch\Lock\Permissions\Permission @return void
[ "Stores", "a", "new", "permission", "into", "the", "driver", "for", "a", "caller" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Drivers/ArrayDriver.php#L40-L43
train
BeatSwitch/lock
src/Drivers/ArrayDriver.php
ArrayDriver.removeCallerPermission
public function removeCallerPermission(Caller $caller, Permission $permission) { // Remove permissions which match the action and resource $this->permissions[$this->getCallerKey($caller)] = array_filter( $this->getCallerPermissions($caller), function (Permission $callerPermission) use ($permission) { // Only keep permissions which don't exactly match the one which we're trying to remove. return ! $callerPermission->matchesPermission($permission); } ); }
php
public function removeCallerPermission(Caller $caller, Permission $permission) { // Remove permissions which match the action and resource $this->permissions[$this->getCallerKey($caller)] = array_filter( $this->getCallerPermissions($caller), function (Permission $callerPermission) use ($permission) { // Only keep permissions which don't exactly match the one which we're trying to remove. return ! $callerPermission->matchesPermission($permission); } ); }
[ "public", "function", "removeCallerPermission", "(", "Caller", "$", "caller", ",", "Permission", "$", "permission", ")", "{", "// Remove permissions which match the action and resource", "$", "this", "->", "permissions", "[", "$", "this", "->", "getCallerKey", "(", "$...
Removes a permission from the driver for a caller @param \BeatSwitch\Lock\Callers\Caller $caller @param \BeatSwitch\Lock\Permissions\Permission @return void
[ "Removes", "a", "permission", "from", "the", "driver", "for", "a", "caller" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Drivers/ArrayDriver.php#L52-L62
train
BeatSwitch/lock
src/Drivers/ArrayDriver.php
ArrayDriver.hasCallerPermission
public function hasCallerPermission(Caller $caller, Permission $permission) { // Iterate over each permission from the user and check if the permission is in the array. foreach ($this->getCallerPermissions($caller) as $callerPermission) { // If a matching permission was found, immediately break the sequence and return true. if ($callerPermission->matchesPermission($permission)) { return true; } } return false; }
php
public function hasCallerPermission(Caller $caller, Permission $permission) { // Iterate over each permission from the user and check if the permission is in the array. foreach ($this->getCallerPermissions($caller) as $callerPermission) { // If a matching permission was found, immediately break the sequence and return true. if ($callerPermission->matchesPermission($permission)) { return true; } } return false; }
[ "public", "function", "hasCallerPermission", "(", "Caller", "$", "caller", ",", "Permission", "$", "permission", ")", "{", "// Iterate over each permission from the user and check if the permission is in the array.", "foreach", "(", "$", "this", "->", "getCallerPermissions", ...
Checks if a permission is stored for a user @param \BeatSwitch\Lock\Callers\Caller $caller @param \BeatSwitch\Lock\Permissions\Permission @return bool
[ "Checks", "if", "a", "permission", "is", "stored", "for", "a", "user" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Drivers/ArrayDriver.php#L71-L82
train
BeatSwitch/lock
src/Lock.php
Lock.allow
public function allow($action, $resource = null, $resourceId = null, $conditions = []) { $actions = (array) $action; $resource = $this->convertResourceToObject($resource, $resourceId); $permissions = $this->getPermissions(); foreach ($actions as $action) { foreach ($permissions as $key => $permission) { if ($permission instanceof Restriction && ! $permission->isAllowed($this, $action, $resource)) { $this->removePermission($permission); unset($permissions[$key]); } } // We'll need to clear any restrictions above $restriction = new Restriction($action, $resource); if ($this->hasPermission($restriction)) { $this->removePermission($restriction); } $this->storePermission(new Privilege($action, $resource, $conditions)); } }
php
public function allow($action, $resource = null, $resourceId = null, $conditions = []) { $actions = (array) $action; $resource = $this->convertResourceToObject($resource, $resourceId); $permissions = $this->getPermissions(); foreach ($actions as $action) { foreach ($permissions as $key => $permission) { if ($permission instanceof Restriction && ! $permission->isAllowed($this, $action, $resource)) { $this->removePermission($permission); unset($permissions[$key]); } } // We'll need to clear any restrictions above $restriction = new Restriction($action, $resource); if ($this->hasPermission($restriction)) { $this->removePermission($restriction); } $this->storePermission(new Privilege($action, $resource, $conditions)); } }
[ "public", "function", "allow", "(", "$", "action", ",", "$", "resource", "=", "null", ",", "$", "resourceId", "=", "null", ",", "$", "conditions", "=", "[", "]", ")", "{", "$", "actions", "=", "(", "array", ")", "$", "action", ";", "$", "resource",...
Give the subject permission to do something @param string|array $action @param string|\BeatSwitch\Lock\Resources\Resource $resource @param int $resourceId @param \BeatSwitch\Lock\Permissions\Condition|\BeatSwitch\Lock\Permissions\Condition[]|\Closure $conditions
[ "Give", "the", "subject", "permission", "to", "do", "something" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Lock.php#L67-L90
train
BeatSwitch/lock
src/Lock.php
Lock.deny
public function deny($action, $resource = null, $resourceId = null, $conditions = []) { $actions = (array) $action; $resource = $this->convertResourceToObject($resource, $resourceId); $permissions = $this->getPermissions(); foreach ($actions as $action) { $this->clearPermission($action, $resource, $permissions); $this->storePermission(new Restriction($action, $resource, $conditions)); } }
php
public function deny($action, $resource = null, $resourceId = null, $conditions = []) { $actions = (array) $action; $resource = $this->convertResourceToObject($resource, $resourceId); $permissions = $this->getPermissions(); foreach ($actions as $action) { $this->clearPermission($action, $resource, $permissions); $this->storePermission(new Restriction($action, $resource, $conditions)); } }
[ "public", "function", "deny", "(", "$", "action", ",", "$", "resource", "=", "null", ",", "$", "resourceId", "=", "null", ",", "$", "conditions", "=", "[", "]", ")", "{", "$", "actions", "=", "(", "array", ")", "$", "action", ";", "$", "resource", ...
Deny the subject from doing something @param string|array $action @param string|\BeatSwitch\Lock\Resources\Resource $resource @param int $resourceId @param \BeatSwitch\Lock\Permissions\Condition|\BeatSwitch\Lock\Permissions\Condition[]|\Closure $conditions
[ "Deny", "the", "subject", "from", "doing", "something" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Lock.php#L100-L111
train
BeatSwitch/lock
src/Lock.php
Lock.resolveRestrictions
protected function resolveRestrictions($permissions, $action, Resource $resource) { foreach ($permissions as $permission) { // If we've found a matching restriction, return false. if ($permission instanceof Restriction && ! $permission->isAllowed($this, $action, $resource)) { return false; } } return true; }
php
protected function resolveRestrictions($permissions, $action, Resource $resource) { foreach ($permissions as $permission) { // If we've found a matching restriction, return false. if ($permission instanceof Restriction && ! $permission->isAllowed($this, $action, $resource)) { return false; } } return true; }
[ "protected", "function", "resolveRestrictions", "(", "$", "permissions", ",", "$", "action", ",", "Resource", "$", "resource", ")", "{", "foreach", "(", "$", "permissions", "as", "$", "permission", ")", "{", "// If we've found a matching restriction, return false.", ...
Check if the given restrictions prevent the given action and resource to pass @param \BeatSwitch\Lock\Permissions\Permission[] $permissions @param string $action @param \BeatSwitch\Lock\Resources\Resource $resource @return bool
[ "Check", "if", "the", "given", "restrictions", "prevent", "the", "given", "action", "and", "resource", "to", "pass" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Lock.php#L242-L252
train
BeatSwitch/lock
src/Lock.php
Lock.resolvePrivileges
protected function resolvePrivileges($permissions, $action, Resource $resource) { // Search for privileges in the permissions. foreach ($permissions as $permission) { // If we've found a valid privilege, return true. if ($permission instanceof Privilege && $permission->isAllowed($this, $action, $resource)) { return true; } } return false; }
php
protected function resolvePrivileges($permissions, $action, Resource $resource) { // Search for privileges in the permissions. foreach ($permissions as $permission) { // If we've found a valid privilege, return true. if ($permission instanceof Privilege && $permission->isAllowed($this, $action, $resource)) { return true; } } return false; }
[ "protected", "function", "resolvePrivileges", "(", "$", "permissions", ",", "$", "action", ",", "Resource", "$", "resource", ")", "{", "// Search for privileges in the permissions.", "foreach", "(", "$", "permissions", "as", "$", "permission", ")", "{", "// If we've...
Check if the given privileges allow the given action and resource to pass @param \BeatSwitch\Lock\Permissions\Permission[] $permissions @param string $action @param \BeatSwitch\Lock\Resources\Resource $resource @return bool
[ "Check", "if", "the", "given", "privileges", "allow", "the", "given", "action", "and", "resource", "to", "pass" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Lock.php#L262-L273
train
BeatSwitch/lock
src/Lock.php
Lock.getAliasesForAction
protected function getAliasesForAction($action) { $actions = []; foreach ($this->manager->getAliases() as $aliasName => $alias) { if ($alias->hasAction($action)) { $actions[] = $aliasName; } } return $actions; }
php
protected function getAliasesForAction($action) { $actions = []; foreach ($this->manager->getAliases() as $aliasName => $alias) { if ($alias->hasAction($action)) { $actions[] = $aliasName; } } return $actions; }
[ "protected", "function", "getAliasesForAction", "(", "$", "action", ")", "{", "$", "actions", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "manager", "->", "getAliases", "(", ")", "as", "$", "aliasName", "=>", "$", "alias", ")", "{", "if", ...
Returns all aliases which contain the given action @param string $action @return array
[ "Returns", "all", "aliases", "which", "contain", "the", "given", "action" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Lock.php#L310-L321
train
BeatSwitch/lock
src/Lock.php
Lock.convertResourceToObject
protected function convertResourceToObject($resource, $resourceId = null) { return ! $resource instanceof Resource ? new SimpleResource($resource, $resourceId) : $resource; }
php
protected function convertResourceToObject($resource, $resourceId = null) { return ! $resource instanceof Resource ? new SimpleResource($resource, $resourceId) : $resource; }
[ "protected", "function", "convertResourceToObject", "(", "$", "resource", ",", "$", "resourceId", "=", "null", ")", "{", "return", "!", "$", "resource", "instanceof", "Resource", "?", "new", "SimpleResource", "(", "$", "resource", ",", "$", "resourceId", ")", ...
Create a resource value object if a non resource object is passed @param string|\BeatSwitch\Lock\Resources\Resource|null $resource @param int|null $resourceId @return \BeatSwitch\Lock\Resources\Resource
[ "Create", "a", "resource", "value", "object", "if", "a", "non", "resource", "object", "is", "passed" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/Lock.php#L330-L333
train
BeatSwitch/lock
src/LockAware.php
LockAware.deny
public function deny($action, $resource = null, $resourceId = null, $conditions = []) { $this->assertLockInstanceIsSet(); $this->lock->deny($action, $resource, $resourceId, $conditions); }
php
public function deny($action, $resource = null, $resourceId = null, $conditions = []) { $this->assertLockInstanceIsSet(); $this->lock->deny($action, $resource, $resourceId, $conditions); }
[ "public", "function", "deny", "(", "$", "action", ",", "$", "resource", "=", "null", ",", "$", "resourceId", "=", "null", ",", "$", "conditions", "=", "[", "]", ")", "{", "$", "this", "->", "assertLockInstanceIsSet", "(", ")", ";", "$", "this", "->",...
Deny a caller from doing something @param string|array $action @param string|\BeatSwitch\Lock\Resources\Resource $resource @param int $resourceId @param \BeatSwitch\Lock\Permissions\Condition|\BeatSwitch\Lock\Permissions\Condition[]|\Closure $conditions
[ "Deny", "a", "caller", "from", "doing", "something" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/LockAware.php#L71-L76
train
BeatSwitch/lock
src/LockAware.php
LockAware.setLock
public function setLock(Lock $lock) { // Make sure that the subject from the given lock instance is this object. if ($lock->getSubject() !== $this) { throw new InvalidLockInstance('Invalid Lock instance given for current object.'); } $this->lock = $lock; }
php
public function setLock(Lock $lock) { // Make sure that the subject from the given lock instance is this object. if ($lock->getSubject() !== $this) { throw new InvalidLockInstance('Invalid Lock instance given for current object.'); } $this->lock = $lock; }
[ "public", "function", "setLock", "(", "Lock", "$", "lock", ")", "{", "// Make sure that the subject from the given lock instance is this object.", "if", "(", "$", "lock", "->", "getSubject", "(", ")", "!==", "$", "this", ")", "{", "throw", "new", "InvalidLockInstanc...
Sets the lock instance for this caller @param \BeatSwitch\Lock\Lock $lock @throws \BeatSwitch\Lock\InvalidLockInstance
[ "Sets", "the", "lock", "instance", "for", "this", "caller" ]
b3a47635b06b61915735c8633ad6cee26bf9e7ab
https://github.com/BeatSwitch/lock/blob/b3a47635b06b61915735c8633ad6cee26bf9e7ab/src/LockAware.php#L140-L148
train
antkaz/yii2-vue
src/Vue.php
Vue.initClientOptions
protected function initClientOptions() { if (!isset($this->clientOptions['el'])) { $this->clientOptions['el'] = "#{$this->getId()}"; } $this->initData(); $this->initComputed(); $this->initMethods(); }
php
protected function initClientOptions() { if (!isset($this->clientOptions['el'])) { $this->clientOptions['el'] = "#{$this->getId()}"; } $this->initData(); $this->initComputed(); $this->initMethods(); }
[ "protected", "function", "initClientOptions", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "clientOptions", "[", "'el'", "]", ")", ")", "{", "$", "this", "->", "clientOptions", "[", "'el'", "]", "=", "\"#{$this->getId()}\"", ";", "}", ...
Initializes the options for the Vue object
[ "Initializes", "the", "options", "for", "the", "Vue", "object" ]
150deabf6a08961d8876f0eaf55ca53d97badef7
https://github.com/antkaz/yii2-vue/blob/150deabf6a08961d8876f0eaf55ca53d97badef7/src/Vue.php#L92-L101
train
antkaz/yii2-vue
src/Vue.php
Vue.initData
protected function initData() { if (empty($this->data)) { return; } if (is_array($this->data) || $this->data instanceof JsExpression) { $this->clientOptions['data'] = $this->data; } elseif (is_string($this->data)) { $this->clientOptions['data'] = new JsExpression($this->data); } else { throw new InvalidConfigException('The "data" option can only be a string or an array'); } }
php
protected function initData() { if (empty($this->data)) { return; } if (is_array($this->data) || $this->data instanceof JsExpression) { $this->clientOptions['data'] = $this->data; } elseif (is_string($this->data)) { $this->clientOptions['data'] = new JsExpression($this->data); } else { throw new InvalidConfigException('The "data" option can only be a string or an array'); } }
[ "protected", "function", "initData", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "data", ")", ")", "{", "return", ";", "}", "if", "(", "is_array", "(", "$", "this", "->", "data", ")", "||", "$", "this", "->", "data", "instanceof", ...
Initializes the data object for the Vue instance @throws InvalidConfigException
[ "Initializes", "the", "data", "object", "for", "the", "Vue", "instance" ]
150deabf6a08961d8876f0eaf55ca53d97badef7
https://github.com/antkaz/yii2-vue/blob/150deabf6a08961d8876f0eaf55ca53d97badef7/src/Vue.php#L108-L121
train
antkaz/yii2-vue
src/Vue.php
Vue.initComputed
protected function initComputed() { if (empty($this->computed)) { return; } if (!is_array($this->computed)) { throw new InvalidConfigException('The "computed" option are not an array'); } foreach ($this->computed as $key => $callback) { if (is_array($callback)) { if (isset($callback['get'])) { $function = $callback['get'] instanceof JsExpression ? $callback['get'] : new JsExpression($callback['get']); $this->clientOptions['computed'][$key]['get'] = $function; } if (isset($callback['set'])) { $function = $callback['set'] instanceof JsExpression ? $callback['set'] : new JsExpression($callback['set']); $this->clientOptions['computed'][$key]['set'] = $function; } } else { $function = $callback instanceof JsExpression ? $callback : new JsExpression($callback); $this->clientOptions['computed'][$key] = $function; } } }
php
protected function initComputed() { if (empty($this->computed)) { return; } if (!is_array($this->computed)) { throw new InvalidConfigException('The "computed" option are not an array'); } foreach ($this->computed as $key => $callback) { if (is_array($callback)) { if (isset($callback['get'])) { $function = $callback['get'] instanceof JsExpression ? $callback['get'] : new JsExpression($callback['get']); $this->clientOptions['computed'][$key]['get'] = $function; } if (isset($callback['set'])) { $function = $callback['set'] instanceof JsExpression ? $callback['set'] : new JsExpression($callback['set']); $this->clientOptions['computed'][$key]['set'] = $function; } } else { $function = $callback instanceof JsExpression ? $callback : new JsExpression($callback); $this->clientOptions['computed'][$key] = $function; } } }
[ "protected", "function", "initComputed", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "computed", ")", ")", "{", "return", ";", "}", "if", "(", "!", "is_array", "(", "$", "this", "->", "computed", ")", ")", "{", "throw", "new", "Inval...
Initializes computed to be mixed into the Vue instance. @throws InvalidConfigException
[ "Initializes", "computed", "to", "be", "mixed", "into", "the", "Vue", "instance", "." ]
150deabf6a08961d8876f0eaf55ca53d97badef7
https://github.com/antkaz/yii2-vue/blob/150deabf6a08961d8876f0eaf55ca53d97badef7/src/Vue.php#L128-L153
train
antkaz/yii2-vue
src/Vue.php
Vue.initMethods
protected function initMethods() { if (empty($this->methods)) { return; } if (!is_array($this->methods)) { throw new InvalidConfigException('The "methods" option are not an array'); } foreach ($this->methods as $methodName => $handler) { $function = $handler instanceof JsExpression ? $handler : new JsExpression($handler); $this->clientOptions['methods'][$methodName] = $function; } }
php
protected function initMethods() { if (empty($this->methods)) { return; } if (!is_array($this->methods)) { throw new InvalidConfigException('The "methods" option are not an array'); } foreach ($this->methods as $methodName => $handler) { $function = $handler instanceof JsExpression ? $handler : new JsExpression($handler); $this->clientOptions['methods'][$methodName] = $function; } }
[ "protected", "function", "initMethods", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "methods", ")", ")", "{", "return", ";", "}", "if", "(", "!", "is_array", "(", "$", "this", "->", "methods", ")", ")", "{", "throw", "new", "InvalidC...
Initializes methods to be mixed into the Vue instance. @throws InvalidConfigException
[ "Initializes", "methods", "to", "be", "mixed", "into", "the", "Vue", "instance", "." ]
150deabf6a08961d8876f0eaf55ca53d97badef7
https://github.com/antkaz/yii2-vue/blob/150deabf6a08961d8876f0eaf55ca53d97badef7/src/Vue.php#L160-L174
train
antkaz/yii2-vue
src/Vue.php
Vue.registerJs
protected function registerJs() { VueAsset::register($this->getView()); $options = Json::htmlEncode($this->clientOptions); $js = "var app = new Vue({$options})"; $this->getView()->registerJs($js, View::POS_END); }
php
protected function registerJs() { VueAsset::register($this->getView()); $options = Json::htmlEncode($this->clientOptions); $js = "var app = new Vue({$options})"; $this->getView()->registerJs($js, View::POS_END); }
[ "protected", "function", "registerJs", "(", ")", "{", "VueAsset", "::", "register", "(", "$", "this", "->", "getView", "(", ")", ")", ";", "$", "options", "=", "Json", "::", "htmlEncode", "(", "$", "this", "->", "clientOptions", ")", ";", "$", "js", ...
Registers a specific asset bundles. @throws \yii\base\InvalidArgumentException
[ "Registers", "a", "specific", "asset", "bundles", "." ]
150deabf6a08961d8876f0eaf55ca53d97badef7
https://github.com/antkaz/yii2-vue/blob/150deabf6a08961d8876f0eaf55ca53d97badef7/src/Vue.php#L180-L187
train
romanpitak/PHP-REST-Client
src/Request.php
Request.buildResponse
private function buildResponse() { $curlOptions = $this->getBasicCurlOptions(); $this->addRequestAuth($curlOptions); $this->addRequestHeaders($curlOptions); $this->addRequestMethod($curlOptions); // push options into the resource $curlResource = $this->getCurlResource(); if (!curl_setopt_array($curlResource, $curlOptions)) { throw new RequestException('Invalid cURL options'); } // create response $response = new Response($curlResource); return $response; }
php
private function buildResponse() { $curlOptions = $this->getBasicCurlOptions(); $this->addRequestAuth($curlOptions); $this->addRequestHeaders($curlOptions); $this->addRequestMethod($curlOptions); // push options into the resource $curlResource = $this->getCurlResource(); if (!curl_setopt_array($curlResource, $curlOptions)) { throw new RequestException('Invalid cURL options'); } // create response $response = new Response($curlResource); return $response; }
[ "private", "function", "buildResponse", "(", ")", "{", "$", "curlOptions", "=", "$", "this", "->", "getBasicCurlOptions", "(", ")", ";", "$", "this", "->", "addRequestAuth", "(", "$", "curlOptions", ")", ";", "$", "this", "->", "addRequestHeaders", "(", "$...
Build the response object. Builds the response object based on current request configuration. @return Response @throws RequestException
[ "Build", "the", "response", "object", "." ]
728b6c44040a13daeb8033953f5f3cdd3dde1980
https://github.com/romanpitak/PHP-REST-Client/blob/728b6c44040a13daeb8033953f5f3cdd3dde1980/src/Request.php#L105-L121
train
romanpitak/PHP-REST-Client
src/Request.php
Request.getBasicCurlOptions
private function getBasicCurlOptions() { $curlOptions = $this->getOption(self::CURL_OPTIONS_KEY, array()); $curlOptions[CURLOPT_HEADER] = true; $curlOptions[CURLOPT_RETURNTRANSFER] = true; $curlOptions[CURLOPT_USERAGENT] = $this->getOption(self::USER_AGENT_KEY); $curlOptions[CURLOPT_URL] = $this->getOption(self::BASE_URL_KEY); return $curlOptions; }
php
private function getBasicCurlOptions() { $curlOptions = $this->getOption(self::CURL_OPTIONS_KEY, array()); $curlOptions[CURLOPT_HEADER] = true; $curlOptions[CURLOPT_RETURNTRANSFER] = true; $curlOptions[CURLOPT_USERAGENT] = $this->getOption(self::USER_AGENT_KEY); $curlOptions[CURLOPT_URL] = $this->getOption(self::BASE_URL_KEY); return $curlOptions; }
[ "private", "function", "getBasicCurlOptions", "(", ")", "{", "$", "curlOptions", "=", "$", "this", "->", "getOption", "(", "self", "::", "CURL_OPTIONS_KEY", ",", "array", "(", ")", ")", ";", "$", "curlOptions", "[", "CURLOPT_HEADER", "]", "=", "true", ";",...
Create basic curl options @return array Curl options
[ "Create", "basic", "curl", "options" ]
728b6c44040a13daeb8033953f5f3cdd3dde1980
https://github.com/romanpitak/PHP-REST-Client/blob/728b6c44040a13daeb8033953f5f3cdd3dde1980/src/Request.php#L128-L135
train
romanpitak/PHP-REST-Client
src/Request.php
Request.addRequestAuth
private function addRequestAuth(&$curlOptions) { $username = $this->getOption(self::USERNAME_KEY); $password = $this->getOption(self::PASSWORD_KEY); if ((!is_null($username)) && (!is_null($password))) { $curlOptions[CURLOPT_USERPWD] = sprintf("%s:%s", $username, $password); } }
php
private function addRequestAuth(&$curlOptions) { $username = $this->getOption(self::USERNAME_KEY); $password = $this->getOption(self::PASSWORD_KEY); if ((!is_null($username)) && (!is_null($password))) { $curlOptions[CURLOPT_USERPWD] = sprintf("%s:%s", $username, $password); } }
[ "private", "function", "addRequestAuth", "(", "&", "$", "curlOptions", ")", "{", "$", "username", "=", "$", "this", "->", "getOption", "(", "self", "::", "USERNAME_KEY", ")", ";", "$", "password", "=", "$", "this", "->", "getOption", "(", "self", "::", ...
Add authentication to curl options @param array &$curlOptions
[ "Add", "authentication", "to", "curl", "options" ]
728b6c44040a13daeb8033953f5f3cdd3dde1980
https://github.com/romanpitak/PHP-REST-Client/blob/728b6c44040a13daeb8033953f5f3cdd3dde1980/src/Request.php#L142-L148
train
romanpitak/PHP-REST-Client
src/Request.php
Request.addRequestHeaders
private function addRequestHeaders(&$curlOptions) { // cURL HTTP headers $headers = $this->getOption(self::HEADERS_KEY, array()); // Turn off the Expect header to stop HTTP 100 Continue responses. // Response parsing was not handling these headers. $curlOptions[CURLOPT_HTTPHEADER][] = "Expect:"; if (0 < count($headers)) { $curlOptions[CURLOPT_HTTPHEADER] = array(); foreach ($headers as $key => $value) { $curlOptions[CURLOPT_HTTPHEADER][] = sprintf("%s:%s", $key, $value); } } }
php
private function addRequestHeaders(&$curlOptions) { // cURL HTTP headers $headers = $this->getOption(self::HEADERS_KEY, array()); // Turn off the Expect header to stop HTTP 100 Continue responses. // Response parsing was not handling these headers. $curlOptions[CURLOPT_HTTPHEADER][] = "Expect:"; if (0 < count($headers)) { $curlOptions[CURLOPT_HTTPHEADER] = array(); foreach ($headers as $key => $value) { $curlOptions[CURLOPT_HTTPHEADER][] = sprintf("%s:%s", $key, $value); } } }
[ "private", "function", "addRequestHeaders", "(", "&", "$", "curlOptions", ")", "{", "// cURL HTTP headers", "$", "headers", "=", "$", "this", "->", "getOption", "(", "self", "::", "HEADERS_KEY", ",", "array", "(", ")", ")", ";", "// Turn off the Expect header to...
Add headers to curl options @param array &$curlOptions
[ "Add", "headers", "to", "curl", "options" ]
728b6c44040a13daeb8033953f5f3cdd3dde1980
https://github.com/romanpitak/PHP-REST-Client/blob/728b6c44040a13daeb8033953f5f3cdd3dde1980/src/Request.php#L155-L167
train
romanpitak/PHP-REST-Client
src/Request.php
Request.addRequestMethod
private function addRequestMethod(&$curlOptions) { $method = strtoupper($this->getOption(self::METHOD_KEY, 'GET')); switch ($method) { case 'GET': break; case 'POST': $curlOptions[CURLOPT_POST] = true; $curlOptions[CURLOPT_POSTFIELDS] = $this->getOption(self::DATA_KEY, array()); break; default: $curlOptions[CURLOPT_CUSTOMREQUEST] = $method; $curlOptions[CURLOPT_POSTFIELDS] = $this->getOption(self::DATA_KEY, array()); } }
php
private function addRequestMethod(&$curlOptions) { $method = strtoupper($this->getOption(self::METHOD_KEY, 'GET')); switch ($method) { case 'GET': break; case 'POST': $curlOptions[CURLOPT_POST] = true; $curlOptions[CURLOPT_POSTFIELDS] = $this->getOption(self::DATA_KEY, array()); break; default: $curlOptions[CURLOPT_CUSTOMREQUEST] = $method; $curlOptions[CURLOPT_POSTFIELDS] = $this->getOption(self::DATA_KEY, array()); } }
[ "private", "function", "addRequestMethod", "(", "&", "$", "curlOptions", ")", "{", "$", "method", "=", "strtoupper", "(", "$", "this", "->", "getOption", "(", "self", "::", "METHOD_KEY", ",", "'GET'", ")", ")", ";", "switch", "(", "$", "method", ")", "...
Add Method to curl options @param array &$curlOptions
[ "Add", "Method", "to", "curl", "options" ]
728b6c44040a13daeb8033953f5f3cdd3dde1980
https://github.com/romanpitak/PHP-REST-Client/blob/728b6c44040a13daeb8033953f5f3cdd3dde1980/src/Request.php#L174-L187
train
grohiro/laravel-camelcase-json
src/CamelCaseJsonResponseFactory.php
CamelCaseJsonResponseFactory.encodeJson
public function encodeJson($value) { if ($value instanceof Arrayable) { return $this->encodeArrayable($value); } else if (is_array($value)) { return $this->encodeArray($value); } else if (is_object($value)) { return $this->encodeArray((array) $value); } else { return $value; } }
php
public function encodeJson($value) { if ($value instanceof Arrayable) { return $this->encodeArrayable($value); } else if (is_array($value)) { return $this->encodeArray($value); } else if (is_object($value)) { return $this->encodeArray((array) $value); } else { return $value; } }
[ "public", "function", "encodeJson", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Arrayable", ")", "{", "return", "$", "this", "->", "encodeArrayable", "(", "$", "value", ")", ";", "}", "else", "if", "(", "is_array", "(", "$", ...
Encode a value to camelCase JSON
[ "Encode", "a", "value", "to", "camelCase", "JSON" ]
9659d3c418c835864648f3ba1c2c42d2769a543c
https://github.com/grohiro/laravel-camelcase-json/blob/9659d3c418c835864648f3ba1c2c42d2769a543c/src/CamelCaseJsonResponseFactory.php#L26-L37
train
grohiro/laravel-camelcase-json
src/CamelCaseJsonResponseFactory.php
CamelCaseJsonResponseFactory.encodeArray
public function encodeArray($array) { $newArray = []; foreach ($array as $key => $val) { $newArray[\camel_case($key)] = $this->encodeJson($val); } return $newArray; }
php
public function encodeArray($array) { $newArray = []; foreach ($array as $key => $val) { $newArray[\camel_case($key)] = $this->encodeJson($val); } return $newArray; }
[ "public", "function", "encodeArray", "(", "$", "array", ")", "{", "$", "newArray", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "newArray", "[", "\\", "camel_case", "(", "$", "key", ")", "]"...
Encode an array
[ "Encode", "an", "array" ]
9659d3c418c835864648f3ba1c2c42d2769a543c
https://github.com/grohiro/laravel-camelcase-json/blob/9659d3c418c835864648f3ba1c2c42d2769a543c/src/CamelCaseJsonResponseFactory.php#L51-L58
train
php-middleware/request-id
src/RequestDecorator.php
RequestDecorator.decorate
public function decorate(RequestInterface $request) { return $request->withHeader($this->headerName, $this->requestIdProvider->getRequestId()); }
php
public function decorate(RequestInterface $request) { return $request->withHeader($this->headerName, $this->requestIdProvider->getRequestId()); }
[ "public", "function", "decorate", "(", "RequestInterface", "$", "request", ")", "{", "return", "$", "request", "->", "withHeader", "(", "$", "this", "->", "headerName", ",", "$", "this", "->", "requestIdProvider", "->", "getRequestId", "(", ")", ")", ";", ...
Adds request id to request and return new instance @param RequestInterface $request @return RequestInterface
[ "Adds", "request", "id", "to", "request", "and", "return", "new", "instance" ]
3936e46a3b533e78125651734fe189be1d94d4d2
https://github.com/php-middleware/request-id/blob/3936e46a3b533e78125651734fe189be1d94d4d2/src/RequestDecorator.php#L25-L28
train
adam-paterson/oauth2-slack
src/Provider/Slack.php
Slack.getResourceOwnerDetailsUrl
public function getResourceOwnerDetailsUrl(AccessToken $token) { $authorizedUser = $this->getAuthorizedUser($token); $params = [ 'token' => $token->getToken(), 'user' => $authorizedUser->getId() ]; return 'https://slack.com/api/users.info?'.http_build_query($params); }
php
public function getResourceOwnerDetailsUrl(AccessToken $token) { $authorizedUser = $this->getAuthorizedUser($token); $params = [ 'token' => $token->getToken(), 'user' => $authorizedUser->getId() ]; return 'https://slack.com/api/users.info?'.http_build_query($params); }
[ "public", "function", "getResourceOwnerDetailsUrl", "(", "AccessToken", "$", "token", ")", "{", "$", "authorizedUser", "=", "$", "this", "->", "getAuthorizedUser", "(", "$", "token", ")", ";", "$", "params", "=", "[", "'token'", "=>", "$", "token", "->", "...
Returns the URL for requesting the resource owner's details. @param AccessToken $token @return string
[ "Returns", "the", "URL", "for", "requesting", "the", "resource", "owner", "s", "details", "." ]
f0b4a409c018c9b9623a9377baea14ac36fbb9e9
https://github.com/adam-paterson/oauth2-slack/blob/f0b4a409c018c9b9623a9377baea14ac36fbb9e9/src/Provider/Slack.php#L49-L59
train
Elao/PhpEnums
src/FlaggedEnum.php
FlaggedEnum.getBitmask
private static function getBitmask(): int { $enumType = static::class; if (!isset(self::$masks[$enumType])) { $mask = 0; foreach (static::values() as $flag) { if ($flag < 1 || ($flag > 1 && ($flag % 2) !== 0)) { throw new LogicException(sprintf( 'Possible value %s of the enumeration "%s" is not a bit flag.', json_encode($flag), static::class )); } $mask |= $flag; } self::$masks[$enumType] = $mask; } return self::$masks[$enumType]; }
php
private static function getBitmask(): int { $enumType = static::class; if (!isset(self::$masks[$enumType])) { $mask = 0; foreach (static::values() as $flag) { if ($flag < 1 || ($flag > 1 && ($flag % 2) !== 0)) { throw new LogicException(sprintf( 'Possible value %s of the enumeration "%s" is not a bit flag.', json_encode($flag), static::class )); } $mask |= $flag; } self::$masks[$enumType] = $mask; } return self::$masks[$enumType]; }
[ "private", "static", "function", "getBitmask", "(", ")", ":", "int", "{", "$", "enumType", "=", "static", "::", "class", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "masks", "[", "$", "enumType", "]", ")", ")", "{", "$", "mask", "=", "0...
Gets an integer value of the possible flags for enumeration. @throws LogicException If the possibles values are not valid bit flags @return int
[ "Gets", "an", "integer", "value", "of", "the", "possible", "flags", "for", "enumeration", "." ]
7fae338102f868a070326a9cda3cbd0a9615ebaf
https://github.com/Elao/PhpEnums/blob/7fae338102f868a070326a9cda3cbd0a9615ebaf/src/FlaggedEnum.php#L111-L131
train
Elao/PhpEnums
src/FlaggedEnum.php
FlaggedEnum.getFlags
public function getFlags(): array { if ($this->flags === null) { $this->flags = []; foreach (static::values() as $flag) { if ($this->hasFlag($flag)) { $this->flags[] = $flag; } } } return $this->flags; }
php
public function getFlags(): array { if ($this->flags === null) { $this->flags = []; foreach (static::values() as $flag) { if ($this->hasFlag($flag)) { $this->flags[] = $flag; } } } return $this->flags; }
[ "public", "function", "getFlags", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "flags", "===", "null", ")", "{", "$", "this", "->", "flags", "=", "[", "]", ";", "foreach", "(", "static", "::", "values", "(", ")", "as", "$", "flag", ...
Gets an array of bit flags of the value. @return array
[ "Gets", "an", "array", "of", "bit", "flags", "of", "the", "value", "." ]
7fae338102f868a070326a9cda3cbd0a9615ebaf
https://github.com/Elao/PhpEnums/blob/7fae338102f868a070326a9cda3cbd0a9615ebaf/src/FlaggedEnum.php#L148-L160
train
Elao/PhpEnums
src/FlaggedEnum.php
FlaggedEnum.hasFlag
public function hasFlag(int $bitFlag): bool { if ($bitFlag >= 1) { return $bitFlag === ($bitFlag & $this->value); } return false; }
php
public function hasFlag(int $bitFlag): bool { if ($bitFlag >= 1) { return $bitFlag === ($bitFlag & $this->value); } return false; }
[ "public", "function", "hasFlag", "(", "int", "$", "bitFlag", ")", ":", "bool", "{", "if", "(", "$", "bitFlag", ">=", "1", ")", "{", "return", "$", "bitFlag", "===", "(", "$", "bitFlag", "&", "$", "this", "->", "value", ")", ";", "}", "return", "f...
Determines whether the specified flag is set in a numeric value. @param int $bitFlag The bit flag or bit flags @return bool True if the bit flag or bit flags are also set in the current instance; otherwise, false
[ "Determines", "whether", "the", "specified", "flag", "is", "set", "in", "a", "numeric", "value", "." ]
7fae338102f868a070326a9cda3cbd0a9615ebaf
https://github.com/Elao/PhpEnums/blob/7fae338102f868a070326a9cda3cbd0a9615ebaf/src/FlaggedEnum.php#L169-L176
train
Elao/PhpEnums
src/FlaggedEnum.php
FlaggedEnum.withFlags
public function withFlags(int $flags): self { if (!static::accepts($flags)) { throw new InvalidValueException($flags, static::class); } return static::get($this->value | $flags); }
php
public function withFlags(int $flags): self { if (!static::accepts($flags)) { throw new InvalidValueException($flags, static::class); } return static::get($this->value | $flags); }
[ "public", "function", "withFlags", "(", "int", "$", "flags", ")", ":", "self", "{", "if", "(", "!", "static", "::", "accepts", "(", "$", "flags", ")", ")", "{", "throw", "new", "InvalidValueException", "(", "$", "flags", ",", "static", "::", "class", ...
Computes a new value with given flags, and returns the corresponding instance. @param int $flags The bit flag or bit flags @throws InvalidValueException When $flags is not acceptable for this enumeration type @return static The enum instance for computed value
[ "Computes", "a", "new", "value", "with", "given", "flags", "and", "returns", "the", "corresponding", "instance", "." ]
7fae338102f868a070326a9cda3cbd0a9615ebaf
https://github.com/Elao/PhpEnums/blob/7fae338102f868a070326a9cda3cbd0a9615ebaf/src/FlaggedEnum.php#L187-L194
train
Elao/PhpEnums
src/Bridge/Symfony/Form/DataTransformer/ValueToEnumTransformer.php
ValueToEnumTransformer.transform
public function transform($value) { if ($value === null) { return null; } if (!$value instanceof $this->enumClass) { throw new TransformationFailedException(sprintf( 'Expected instance of "%s". Got "%s".', $this->enumClass, \is_object($value) ? \get_class($value) : \gettype($value) )); } return $value->getValue(); }
php
public function transform($value) { if ($value === null) { return null; } if (!$value instanceof $this->enumClass) { throw new TransformationFailedException(sprintf( 'Expected instance of "%s". Got "%s".', $this->enumClass, \is_object($value) ? \get_class($value) : \gettype($value) )); } return $value->getValue(); }
[ "public", "function", "transform", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "!", "$", "value", "instanceof", "$", "this", "->", "enumClass", ")", "{", "throw", "new", "Tra...
Transforms EnumInterface object to a raw enumerated value. @param EnumInterface|null $value EnumInterface instance @throws TransformationFailedException When the transformation fails @return int|string|null Value of EnumInterface
[ "Transforms", "EnumInterface", "object", "to", "a", "raw", "enumerated", "value", "." ]
7fae338102f868a070326a9cda3cbd0a9615ebaf
https://github.com/Elao/PhpEnums/blob/7fae338102f868a070326a9cda3cbd0a9615ebaf/src/Bridge/Symfony/Form/DataTransformer/ValueToEnumTransformer.php#L49-L64
train
Elao/PhpEnums
src/Bridge/Symfony/Form/DataTransformer/ValueToEnumTransformer.php
ValueToEnumTransformer.reverseTransform
public function reverseTransform($value) { if ($value === null) { return null; } try { return $this->enumClass::get($value); } catch (InvalidValueException $exception) { throw new TransformationFailedException($exception->getMessage(), $exception->getCode(), $exception); } }
php
public function reverseTransform($value) { if ($value === null) { return null; } try { return $this->enumClass::get($value); } catch (InvalidValueException $exception) { throw new TransformationFailedException($exception->getMessage(), $exception->getCode(), $exception); } }
[ "public", "function", "reverseTransform", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "null", ";", "}", "try", "{", "return", "$", "this", "->", "enumClass", "::", "get", "(", "$", "value", ")", ";", "}"...
Transforms a raw enumerated value to an enumeration instance. @param int|string|null $value Value accepted by EnumInterface @throws TransformationFailedException When the transformation fails @return EnumInterface|null A single EnumInterface instance or null
[ "Transforms", "a", "raw", "enumerated", "value", "to", "an", "enumeration", "instance", "." ]
7fae338102f868a070326a9cda3cbd0a9615ebaf
https://github.com/Elao/PhpEnums/blob/7fae338102f868a070326a9cda3cbd0a9615ebaf/src/Bridge/Symfony/Form/DataTransformer/ValueToEnumTransformer.php#L75-L86
train
loveorigami/yii2-plugins-system
src/components/View.php
View.doBody
public function doBody() { if ($this->hasEventHandlers(self::EVENT_DO_BODY)) { $event = new ViewEvent([ 'content' => $this->_body, ]); $this->trigger(self::EVENT_DO_BODY, $event); $this->_body = $event->content; } }
php
public function doBody() { if ($this->hasEventHandlers(self::EVENT_DO_BODY)) { $event = new ViewEvent([ 'content' => $this->_body, ]); $this->trigger(self::EVENT_DO_BODY, $event); $this->_body = $event->content; } }
[ "public", "function", "doBody", "(", ")", "{", "if", "(", "$", "this", "->", "hasEventHandlers", "(", "self", "::", "EVENT_DO_BODY", ")", ")", "{", "$", "event", "=", "new", "ViewEvent", "(", "[", "'content'", "=>", "$", "this", "->", "_body", ",", "...
Content manipulation. Need for correct replacement shortcodes
[ "Content", "manipulation", ".", "Need", "for", "correct", "replacement", "shortcodes" ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/components/View.php#L28-L37
train
loveorigami/yii2-plugins-system
src/controllers/EventController.php
EventController.actionCreate
public function actionCreate() { $model = new Event(); $model->plugin_id = Plugin::EVENTS_CORE; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); } else { return $this->render('create', [ 'model' => $model, ]); } }
php
public function actionCreate() { $model = new Event(); $model->plugin_id = Plugin::EVENTS_CORE; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); } else { return $this->render('create', [ 'model' => $model, ]); } }
[ "public", "function", "actionCreate", "(", ")", "{", "$", "model", "=", "new", "Event", "(", ")", ";", "$", "model", "->", "plugin_id", "=", "Plugin", "::", "EVENTS_CORE", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "-...
Creates a new Event model. If creation is successful, the browser will be redirected to the 'view' page. @return mixed
[ "Creates", "a", "new", "Event", "model", ".", "If", "creation", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "view", "page", "." ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/controllers/EventController.php#L62-L74
train
loveorigami/yii2-plugins-system
src/shortcodes/ShortcodeParser.php
ShortcodeParser.addIgnoreBlocks
public function addIgnoreBlocks($blocks) { if (is_array($blocks)) { foreach ($blocks as $openTag => $closeTag) { $this->addIgnoreBlock($openTag, $closeTag); } } }
php
public function addIgnoreBlocks($blocks) { if (is_array($blocks)) { foreach ($blocks as $openTag => $closeTag) { $this->addIgnoreBlock($openTag, $closeTag); } } }
[ "public", "function", "addIgnoreBlocks", "(", "$", "blocks", ")", "{", "if", "(", "is_array", "(", "$", "blocks", ")", ")", "{", "foreach", "(", "$", "blocks", "as", "$", "openTag", "=>", "$", "closeTag", ")", "{", "$", "this", "->", "addIgnoreBlock", ...
Add ignore blocks from array @param array $blocks
[ "Add", "ignore", "blocks", "from", "array" ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/shortcodes/ShortcodeParser.php#L32-L39
train
loveorigami/yii2-plugins-system
src/shortcodes/ShortcodeParser.php
ShortcodeParser.hasShortcode
public function hasShortcode($content, $tag) { if (false === strpos($content, '[')) { return false; } if ($this->existsShortcode($tag)) { return true; } preg_match_all($this->shortcodeRegex(), $content, $matches, PREG_SET_ORDER); if (empty($matches)) { return false; } foreach ($matches as $shortcode) { if ($tag === $shortcode[2]) { return true; } } return false; }
php
public function hasShortcode($content, $tag) { if (false === strpos($content, '[')) { return false; } if ($this->existsShortcode($tag)) { return true; } preg_match_all($this->shortcodeRegex(), $content, $matches, PREG_SET_ORDER); if (empty($matches)) { return false; } foreach ($matches as $shortcode) { if ($tag === $shortcode[2]) { return true; } } return false; }
[ "public", "function", "hasShortcode", "(", "$", "content", ",", "$", "tag", ")", "{", "if", "(", "false", "===", "strpos", "(", "$", "content", ",", "'['", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "existsShortcode", ...
Tests whether content has a particular shortcode @param $content @param $tag @return bool
[ "Tests", "whether", "content", "has", "a", "particular", "shortcode" ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/shortcodes/ShortcodeParser.php#L151-L174
train
loveorigami/yii2-plugins-system
src/shortcodes/ShortcodeParser.php
ShortcodeParser.doShortcode
public function doShortcode($content) { if (false === strpos($content, '[')) { return $content; } if (empty($this->_shortcodes) || !is_array($this->_shortcodes)) return $content; /** * Clear content from ignore blocks */ $pattern = $this->getIgnorePattern(); $content = preg_replace_callback("~$pattern~isu", ['self', '_stack'], $content); /** * parse nested */ $content = $this->parseContent($content); /** * Replase shorcodes in content */ $content = strtr($content, self::_stack()); return $content; }
php
public function doShortcode($content) { if (false === strpos($content, '[')) { return $content; } if (empty($this->_shortcodes) || !is_array($this->_shortcodes)) return $content; /** * Clear content from ignore blocks */ $pattern = $this->getIgnorePattern(); $content = preg_replace_callback("~$pattern~isu", ['self', '_stack'], $content); /** * parse nested */ $content = $this->parseContent($content); /** * Replase shorcodes in content */ $content = strtr($content, self::_stack()); return $content; }
[ "public", "function", "doShortcode", "(", "$", "content", ")", "{", "if", "(", "false", "===", "strpos", "(", "$", "content", ",", "'['", ")", ")", "{", "return", "$", "content", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "_shortcodes", ...
Parse shortcodes in given content @param string $content Content to parse for shortcodes @return string
[ "Parse", "shortcodes", "in", "given", "content" ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/shortcodes/ShortcodeParser.php#L181-L207
train
loveorigami/yii2-plugins-system
src/shortcodes/ShortcodeParser.php
ShortcodeParser.parseContent
protected function parseContent($content) { $content = preg_replace_callback($this->shortcodeRegex(), [$this, 'doShortcodeTag'], $content); if (!$this->isFinishedParse()) { $content = $this->parseContent($content); } return $content; }
php
protected function parseContent($content) { $content = preg_replace_callback($this->shortcodeRegex(), [$this, 'doShortcodeTag'], $content); if (!$this->isFinishedParse()) { $content = $this->parseContent($content); } return $content; }
[ "protected", "function", "parseContent", "(", "$", "content", ")", "{", "$", "content", "=", "preg_replace_callback", "(", "$", "this", "->", "shortcodeRegex", "(", ")", ",", "[", "$", "this", ",", "'doShortcodeTag'", "]", ",", "$", "content", ")", ";", ...
parse nested shortcodes @param $content @return string
[ "parse", "nested", "shortcodes" ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/shortcodes/ShortcodeParser.php#L214-L221
train
loveorigami/yii2-plugins-system
src/shortcodes/ShortcodeParser.php
ShortcodeParser.getShortcodesFromContent
public function getShortcodesFromContent($content) { $content = $this->getContentWithoutIgnoreBlocks($content); if (false === strpos($content, '[')) { return []; } $result = []; $regex = "\[([A-Za-z_]+[^\ \]]+)"; preg_match_all('/' . $regex . '/', $content, $matches); if (!empty($matches[1])) { foreach ($matches[1] as $match) { $result[$match] = $match; } } if ($result) { return array_keys($result); } return $result; }
php
public function getShortcodesFromContent($content) { $content = $this->getContentWithoutIgnoreBlocks($content); if (false === strpos($content, '[')) { return []; } $result = []; $regex = "\[([A-Za-z_]+[^\ \]]+)"; preg_match_all('/' . $regex . '/', $content, $matches); if (!empty($matches[1])) { foreach ($matches[1] as $match) { $result[$match] = $match; } } if ($result) { return array_keys($result); } return $result; }
[ "public", "function", "getShortcodesFromContent", "(", "$", "content", ")", "{", "$", "content", "=", "$", "this", "->", "getContentWithoutIgnoreBlocks", "(", "$", "content", ")", ";", "if", "(", "false", "===", "strpos", "(", "$", "content", ",", "'['", "...
Get the list of all shortcodes found in given content @param string $content Content to process @return array
[ "Get", "the", "list", "of", "all", "shortcodes", "found", "in", "given", "content" ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/shortcodes/ShortcodeParser.php#L305-L329
train
loveorigami/yii2-plugins-system
src/repositories/PluginDirRepository.php
PluginDirRepository.populate
protected function populate() { ClassHelper::getAllClasses($this->_dirs, function ($class) { foreach ($this->_methods as $type) { /** @var BasePlugin|BaseShortcode $class */ if (is_callable([$class, $type])) { $this->_data[] = $this->getInfo($class, $type); return $class; } } return null; }); }
php
protected function populate() { ClassHelper::getAllClasses($this->_dirs, function ($class) { foreach ($this->_methods as $type) { /** @var BasePlugin|BaseShortcode $class */ if (is_callable([$class, $type])) { $this->_data[] = $this->getInfo($class, $type); return $class; } } return null; }); }
[ "protected", "function", "populate", "(", ")", "{", "ClassHelper", "::", "getAllClasses", "(", "$", "this", "->", "_dirs", ",", "function", "(", "$", "class", ")", "{", "foreach", "(", "$", "this", "->", "_methods", "as", "$", "type", ")", "{", "/** @v...
populate pool storage
[ "populate", "pool", "storage" ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/repositories/PluginDirRepository.php#L30-L42
train
loveorigami/yii2-plugins-system
src/helpers/ShortcodesHelper.php
ShortcodesHelper.shortcodeRegex
public static function shortcodeRegex($shortcodes, $as_key = true) { if (!is_array($shortcodes)) { $shortcodes = (array)$shortcodes; $as_key = false; } $keys = ($as_key) ? array_keys($shortcodes) : $shortcodes; $tagRegex = join('|', array_map('preg_quote', $keys)); return '/' . '\\[' // Opening bracket . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] . "($tagRegex)" // 2: Shortcode name . '(?![\\w-])' // Not followed by word character or hyphen . '(' // 3: Unroll the loop: Inside the opening shortcode tag . '[^\\]\\/]*' // Not a closing bracket or forward slash . '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket . '[^\\]\\/]*' // Not a closing bracket or forward slash . ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag ... . '\\]' // ... and closing bracket . '|' . '\\]' // Closing bracket . '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags . '[^\\[]*+' // Not an opening bracket . '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag . '[^\\[]*+' // Not an opening bracket . ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag . ')?' . ')' . '(\\]?)' // 6: Optional second closing brocket for escaping shortcodes: [[tag]] . '/s'; }
php
public static function shortcodeRegex($shortcodes, $as_key = true) { if (!is_array($shortcodes)) { $shortcodes = (array)$shortcodes; $as_key = false; } $keys = ($as_key) ? array_keys($shortcodes) : $shortcodes; $tagRegex = join('|', array_map('preg_quote', $keys)); return '/' . '\\[' // Opening bracket . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] . "($tagRegex)" // 2: Shortcode name . '(?![\\w-])' // Not followed by word character or hyphen . '(' // 3: Unroll the loop: Inside the opening shortcode tag . '[^\\]\\/]*' // Not a closing bracket or forward slash . '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket . '[^\\]\\/]*' // Not a closing bracket or forward slash . ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag ... . '\\]' // ... and closing bracket . '|' . '\\]' // Closing bracket . '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags . '[^\\[]*+' // Not an opening bracket . '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag . '[^\\[]*+' // Not an opening bracket . ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag . ')?' . ')' . '(\\]?)' // 6: Optional second closing brocket for escaping shortcodes: [[tag]] . '/s'; }
[ "public", "static", "function", "shortcodeRegex", "(", "$", "shortcodes", ",", "$", "as_key", "=", "true", ")", "{", "if", "(", "!", "is_array", "(", "$", "shortcodes", ")", ")", "{", "$", "shortcodes", "=", "(", "array", ")", "$", "shortcodes", ";", ...
Retrieve the shortcode regular expression for searching. The regular expression combines the shortcode tags in the regular expression in a regex class. The regular expression contains 6 different sub matches to help with parsing. 1 - An extra [ to allow for escaping shortcodes with double [[]] 2 - The shortcode name 3 - The shortcode argument list 4 - The self closing / 5 - The content of a shortcode when it wraps some content. 6 - An extra ] to allow for escaping shortcodes with double [[]] @param $shortcodes @param bool $as_key @return string The shortcode search regular expression
[ "Retrieve", "the", "shortcode", "regular", "expression", "for", "searching", ".", "The", "regular", "expression", "combines", "the", "shortcode", "tags", "in", "the", "regular", "expression", "in", "a", "regex", "class", "." ]
9f2d926237910b5ff24d2c6e0993a7f3ba4607f1
https://github.com/loveorigami/yii2-plugins-system/blob/9f2d926237910b5ff24d2c6e0993a7f3ba4607f1/src/helpers/ShortcodesHelper.php#L70-L109
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord.loadFromFile
public function loadFromFile(&$ShapeFile, &$SHPFile, &$DBFFile) { $this->ShapeFile = $ShapeFile; $this->SHPFile = $SHPFile; $this->DBFFile = $DBFFile; $this->_loadHeaders(); /* No header read */ if ($this->read == 0) { return; } switch ($this->shapeType) { case 0: $this->_loadNullRecord(); break; case 1: $this->_loadPointRecord(); break; case 21: $this->_loadPointMRecord(); break; case 11: $this->_loadPointZRecord(); break; case 3: $this->_loadPolyLineRecord(); break; case 23: $this->_loadPolyLineMRecord(); break; case 13: $this->_loadPolyLineZRecord(); break; case 5: $this->_loadPolygonRecord(); break; case 25: $this->_loadPolygonMRecord(); break; case 15: $this->_loadPolygonZRecord(); break; case 8: $this->_loadMultiPointRecord(); break; case 28: $this->_loadMultiPointMRecord(); break; case 18: $this->_loadMultiPointZRecord(); break; default: $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); break; } /* We need to skip rest of the record */ while ($this->read < $this->size) { $this->_loadData('V', 4); } /* Check if we didn't read too much */ if ($this->read != $this->size) { $this->setError(sprintf('Failed to parse record, read=%d, size=%d', $this->read, $this->size)); } if (ShapeFile::supportsDbase() && isset($this->DBFFile)) { $this->_loadDBFData(); } }
php
public function loadFromFile(&$ShapeFile, &$SHPFile, &$DBFFile) { $this->ShapeFile = $ShapeFile; $this->SHPFile = $SHPFile; $this->DBFFile = $DBFFile; $this->_loadHeaders(); /* No header read */ if ($this->read == 0) { return; } switch ($this->shapeType) { case 0: $this->_loadNullRecord(); break; case 1: $this->_loadPointRecord(); break; case 21: $this->_loadPointMRecord(); break; case 11: $this->_loadPointZRecord(); break; case 3: $this->_loadPolyLineRecord(); break; case 23: $this->_loadPolyLineMRecord(); break; case 13: $this->_loadPolyLineZRecord(); break; case 5: $this->_loadPolygonRecord(); break; case 25: $this->_loadPolygonMRecord(); break; case 15: $this->_loadPolygonZRecord(); break; case 8: $this->_loadMultiPointRecord(); break; case 28: $this->_loadMultiPointMRecord(); break; case 18: $this->_loadMultiPointZRecord(); break; default: $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); break; } /* We need to skip rest of the record */ while ($this->read < $this->size) { $this->_loadData('V', 4); } /* Check if we didn't read too much */ if ($this->read != $this->size) { $this->setError(sprintf('Failed to parse record, read=%d, size=%d', $this->read, $this->size)); } if (ShapeFile::supportsDbase() && isset($this->DBFFile)) { $this->_loadDBFData(); } }
[ "public", "function", "loadFromFile", "(", "&", "$", "ShapeFile", ",", "&", "$", "SHPFile", ",", "&", "$", "DBFFile", ")", "{", "$", "this", "->", "ShapeFile", "=", "$", "ShapeFile", ";", "$", "this", "->", "SHPFile", "=", "$", "SHPFile", ";", "$", ...
Loads record from files. @param ShapeFile $ShapeFile @param file &$SHPFile Opened SHP file @param file &$DBFFile Opened DBF file
[ "Loads", "record", "from", "files", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L61-L131
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord.saveToFile
public function saveToFile(&$SHPFile, &$DBFFile, $recordNumber) { $this->SHPFile = $SHPFile; $this->DBFFile = $DBFFile; $this->recordNumber = $recordNumber; $this->_saveHeaders(); switch ($this->shapeType) { case 0: // Nothing to save break; case 1: $this->_savePointRecord(); break; case 21: $this->_savePointMRecord(); break; case 11: $this->_savePointZRecord(); break; case 3: $this->_savePolyLineRecord(); break; case 23: $this->_savePolyLineMRecord(); break; case 13: $this->_savePolyLineZRecord(); break; case 5: $this->_savePolygonRecord(); break; case 25: $this->_savePolygonMRecord(); break; case 15: $this->_savePolygonZRecord(); break; case 8: $this->_saveMultiPointRecord(); break; case 28: $this->_saveMultiPointMRecord(); break; case 18: $this->_saveMultiPointZRecord(); break; default: $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); break; } if (ShapeFile::supportsDbase() && ! is_null($this->DBFFile)) { $this->_saveDBFData(); } }
php
public function saveToFile(&$SHPFile, &$DBFFile, $recordNumber) { $this->SHPFile = $SHPFile; $this->DBFFile = $DBFFile; $this->recordNumber = $recordNumber; $this->_saveHeaders(); switch ($this->shapeType) { case 0: // Nothing to save break; case 1: $this->_savePointRecord(); break; case 21: $this->_savePointMRecord(); break; case 11: $this->_savePointZRecord(); break; case 3: $this->_savePolyLineRecord(); break; case 23: $this->_savePolyLineMRecord(); break; case 13: $this->_savePolyLineZRecord(); break; case 5: $this->_savePolygonRecord(); break; case 25: $this->_savePolygonMRecord(); break; case 15: $this->_savePolygonZRecord(); break; case 8: $this->_saveMultiPointRecord(); break; case 28: $this->_saveMultiPointMRecord(); break; case 18: $this->_saveMultiPointZRecord(); break; default: $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); break; } if (ShapeFile::supportsDbase() && ! is_null($this->DBFFile)) { $this->_saveDBFData(); } }
[ "public", "function", "saveToFile", "(", "&", "$", "SHPFile", ",", "&", "$", "DBFFile", ",", "$", "recordNumber", ")", "{", "$", "this", "->", "SHPFile", "=", "$", "SHPFile", ";", "$", "this", "->", "DBFFile", "=", "$", "DBFFile", ";", "$", "this", ...
Saves record to files. @param file &$SHPFile Opened SHP file @param file &$DBFFile Opened DBF file @param int $recordNumber Record number
[ "Saves", "record", "to", "files", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L140-L194
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord.updateDBFInfo
public function updateDBFInfo($header) { $tmp = $this->DBFData; unset($this->DBFData); $this->DBFData = []; foreach ($header as $value) { $this->DBFData[$value[0]] = (isset($tmp[$value[0]])) ? $tmp[$value[0]] : ''; } }
php
public function updateDBFInfo($header) { $tmp = $this->DBFData; unset($this->DBFData); $this->DBFData = []; foreach ($header as $value) { $this->DBFData[$value[0]] = (isset($tmp[$value[0]])) ? $tmp[$value[0]] : ''; } }
[ "public", "function", "updateDBFInfo", "(", "$", "header", ")", "{", "$", "tmp", "=", "$", "this", "->", "DBFData", ";", "unset", "(", "$", "this", "->", "DBFData", ")", ";", "$", "this", "->", "DBFData", "=", "[", "]", ";", "foreach", "(", "$", ...
Updates DBF data to match header. @param array $header DBF structure header
[ "Updates", "DBF", "data", "to", "match", "header", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L201-L209
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord._loadHeaders
private function _loadHeaders() { $this->shapeType = false; $this->recordNumber = $this->_loadData('N', 4); if ($this->recordNumber === false) { return; } // We read the length of the record $this->size = $this->_loadData('N', 4); if ($this->size === false) { return; } $this->size = $this->size * 2 + 8; $this->shapeType = $this->_loadData('V', 4); }
php
private function _loadHeaders() { $this->shapeType = false; $this->recordNumber = $this->_loadData('N', 4); if ($this->recordNumber === false) { return; } // We read the length of the record $this->size = $this->_loadData('N', 4); if ($this->size === false) { return; } $this->size = $this->size * 2 + 8; $this->shapeType = $this->_loadData('V', 4); }
[ "private", "function", "_loadHeaders", "(", ")", "{", "$", "this", "->", "shapeType", "=", "false", ";", "$", "this", "->", "recordNumber", "=", "$", "this", "->", "_loadData", "(", "'N'", ",", "4", ")", ";", "if", "(", "$", "this", "->", "recordNumb...
Loads metadata header from a file.
[ "Loads", "metadata", "header", "from", "a", "file", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L233-L247
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord._saveHeaders
private function _saveHeaders() { fwrite($this->SHPFile, pack('N', $this->recordNumber)); fwrite($this->SHPFile, pack('N', $this->getContentLength())); fwrite($this->SHPFile, pack('V', $this->shapeType)); }
php
private function _saveHeaders() { fwrite($this->SHPFile, pack('N', $this->recordNumber)); fwrite($this->SHPFile, pack('N', $this->getContentLength())); fwrite($this->SHPFile, pack('V', $this->shapeType)); }
[ "private", "function", "_saveHeaders", "(", ")", "{", "fwrite", "(", "$", "this", "->", "SHPFile", ",", "pack", "(", "'N'", ",", "$", "this", "->", "recordNumber", ")", ")", ";", "fwrite", "(", "$", "this", "->", "SHPFile", ",", "pack", "(", "'N'", ...
Saves metadata header to a file.
[ "Saves", "metadata", "header", "to", "a", "file", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L252-L257
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord._adjustPoint
private function _adjustPoint($point) { $type = $this->shapeType / 10; if ($type >= 2) { $point = $this->_fixPoint($point, 'm'); } elseif ($type >= 1) { $point = $this->_fixPoint($point, 'z'); $point = $this->_fixPoint($point, 'm'); } return $point; }
php
private function _adjustPoint($point) { $type = $this->shapeType / 10; if ($type >= 2) { $point = $this->_fixPoint($point, 'm'); } elseif ($type >= 1) { $point = $this->_fixPoint($point, 'z'); $point = $this->_fixPoint($point, 'm'); } return $point; }
[ "private", "function", "_adjustPoint", "(", "$", "point", ")", "{", "$", "type", "=", "$", "this", "->", "shapeType", "/", "10", ";", "if", "(", "$", "type", ">=", "2", ")", "{", "$", "point", "=", "$", "this", "->", "_fixPoint", "(", "$", "point...
Adjust point and bounding box when adding point. @param array $point Point data @return array Fixed point data
[ "Adjust", "point", "and", "bounding", "box", "when", "adding", "point", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L628-L639
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord.addPoint
public function addPoint($point, $partIndex = 0) { $point = $this->_adjustPoint($point); switch ($this->shapeType) { case 0: //Don't add anything return; case 1: case 11: case 21: //Substitutes the value of the current point $this->SHPData = $point; break; case 3: case 5: case 13: case 15: case 23: case 25: //Adds a new point to the selected part $this->SHPData['parts'][$partIndex]['points'][] = $point; $this->SHPData['numparts'] = count($this->SHPData['parts']); $this->SHPData['numpoints'] = 1 + (isset($this->SHPData['numpoints']) ? $this->SHPData['numpoints'] : 0); break; case 8: case 18: case 28: //Adds a new point $this->SHPData['points'][] = $point; $this->SHPData['numpoints'] = 1 + (isset($this->SHPData['numpoints']) ? $this->SHPData['numpoints'] : 0); break; default: $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); return; } $this->_adjustBBox($point); }
php
public function addPoint($point, $partIndex = 0) { $point = $this->_adjustPoint($point); switch ($this->shapeType) { case 0: //Don't add anything return; case 1: case 11: case 21: //Substitutes the value of the current point $this->SHPData = $point; break; case 3: case 5: case 13: case 15: case 23: case 25: //Adds a new point to the selected part $this->SHPData['parts'][$partIndex]['points'][] = $point; $this->SHPData['numparts'] = count($this->SHPData['parts']); $this->SHPData['numpoints'] = 1 + (isset($this->SHPData['numpoints']) ? $this->SHPData['numpoints'] : 0); break; case 8: case 18: case 28: //Adds a new point $this->SHPData['points'][] = $point; $this->SHPData['numpoints'] = 1 + (isset($this->SHPData['numpoints']) ? $this->SHPData['numpoints'] : 0); break; default: $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); return; } $this->_adjustBBox($point); }
[ "public", "function", "addPoint", "(", "$", "point", ",", "$", "partIndex", "=", "0", ")", "{", "$", "point", "=", "$", "this", "->", "_adjustPoint", "(", "$", "point", ")", ";", "switch", "(", "$", "this", "->", "shapeType", ")", "{", "case", "0",...
Adds point to a record. @param array $point Point data @param int $partIndex Part index
[ "Adds", "point", "to", "a", "record", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L647-L684
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord.deletePoint
public function deletePoint($pointIndex = 0, $partIndex = 0) { switch ($this->shapeType) { case 0: //Don't delete anything break; case 1: case 11: case 21: //Sets the value of the point to zero $this->SHPData['x'] = 0.0; $this->SHPData['y'] = 0.0; if (in_array($this->shapeType, [11, 21])) { $this->SHPData['m'] = 0.0; } if (in_array($this->shapeType, [11])) { $this->SHPData['z'] = 0.0; } break; case 3: case 5: case 13: case 15: case 23: case 25: //Deletes the point from the selected part, if exists if (isset($this->SHPData['parts'][$partIndex]) && isset($this->SHPData['parts'][$partIndex]['points'][$pointIndex])) { $count = count($this->SHPData['parts'][$partIndex]['points']) - 1; for ($i = $pointIndex; $i < $count; ++$i) { $this->SHPData['parts'][$partIndex]['points'][$i] = $this->SHPData['parts'][$partIndex]['points'][$i + 1]; } unset($this->SHPData['parts'][$partIndex]['points'][count($this->SHPData['parts'][$partIndex]['points']) - 1]); $this->SHPData['numparts'] = count($this->SHPData['parts']); --$this->SHPData['numpoints']; } break; case 8: case 18: case 28: //Deletes the point, if exists if (isset($this->SHPData['points'][$pointIndex])) { $count = count($this->SHPData['points']) - 1; for ($i = $pointIndex; $i < $count; ++$i) { $this->SHPData['points'][$i] = $this->SHPData['points'][$i + 1]; } unset($this->SHPData['points'][count($this->SHPData['points']) - 1]); --$this->SHPData['numpoints']; } break; default: $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); break; } }
php
public function deletePoint($pointIndex = 0, $partIndex = 0) { switch ($this->shapeType) { case 0: //Don't delete anything break; case 1: case 11: case 21: //Sets the value of the point to zero $this->SHPData['x'] = 0.0; $this->SHPData['y'] = 0.0; if (in_array($this->shapeType, [11, 21])) { $this->SHPData['m'] = 0.0; } if (in_array($this->shapeType, [11])) { $this->SHPData['z'] = 0.0; } break; case 3: case 5: case 13: case 15: case 23: case 25: //Deletes the point from the selected part, if exists if (isset($this->SHPData['parts'][$partIndex]) && isset($this->SHPData['parts'][$partIndex]['points'][$pointIndex])) { $count = count($this->SHPData['parts'][$partIndex]['points']) - 1; for ($i = $pointIndex; $i < $count; ++$i) { $this->SHPData['parts'][$partIndex]['points'][$i] = $this->SHPData['parts'][$partIndex]['points'][$i + 1]; } unset($this->SHPData['parts'][$partIndex]['points'][count($this->SHPData['parts'][$partIndex]['points']) - 1]); $this->SHPData['numparts'] = count($this->SHPData['parts']); --$this->SHPData['numpoints']; } break; case 8: case 18: case 28: //Deletes the point, if exists if (isset($this->SHPData['points'][$pointIndex])) { $count = count($this->SHPData['points']) - 1; for ($i = $pointIndex; $i < $count; ++$i) { $this->SHPData['points'][$i] = $this->SHPData['points'][$i + 1]; } unset($this->SHPData['points'][count($this->SHPData['points']) - 1]); --$this->SHPData['numpoints']; } break; default: $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); break; } }
[ "public", "function", "deletePoint", "(", "$", "pointIndex", "=", "0", ",", "$", "partIndex", "=", "0", ")", "{", "switch", "(", "$", "this", "->", "shapeType", ")", "{", "case", "0", ":", "//Don't delete anything", "break", ";", "case", "1", ":", "cas...
Deletes point from a record. @param int $pointIndex Point index @param int $partIndex Part index
[ "Deletes", "point", "from", "a", "record", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L692-L747
train
phpmyadmin/shapefile
src/ShapeRecord.php
ShapeRecord.getContentLength
public function getContentLength() { // The content length for a record is the length of the record contents section measured in 16-bit words. // one coordinate makes 4 16-bit words (64 bit double) switch ($this->shapeType) { case 0: $result = 0; break; case 1: $result = 10; break; case 21: $result = 10 + 4; break; case 11: $result = 10 + 8; break; case 3: case 5: $count = count($this->SHPData['parts']); $result = 22 + 2 * $count; for ($i = 0; $i < $count; ++$i) { $result += 8 * count($this->SHPData['parts'][$i]['points']); } break; case 23: case 25: $count = count($this->SHPData['parts']); $result = 22 + (2 * 4) + 2 * $count; for ($i = 0; $i < $count; ++$i) { $result += (8 + 4) * count($this->SHPData['parts'][$i]['points']); } break; case 13: case 15: $count = count($this->SHPData['parts']); $result = 22 + (4 * 4) + 2 * $count; for ($i = 0; $i < $count; ++$i) { $result += (8 + 8) * count($this->SHPData['parts'][$i]['points']); } break; case 8: $result = 20 + 8 * count($this->SHPData['points']); break; case 28: $result = 20 + (2 * 4) + (8 + 4) * count($this->SHPData['points']); break; case 18: $result = 20 + (4 * 4) + (8 + 8) * count($this->SHPData['points']); break; default: $result = false; $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); break; } return $result; }
php
public function getContentLength() { // The content length for a record is the length of the record contents section measured in 16-bit words. // one coordinate makes 4 16-bit words (64 bit double) switch ($this->shapeType) { case 0: $result = 0; break; case 1: $result = 10; break; case 21: $result = 10 + 4; break; case 11: $result = 10 + 8; break; case 3: case 5: $count = count($this->SHPData['parts']); $result = 22 + 2 * $count; for ($i = 0; $i < $count; ++$i) { $result += 8 * count($this->SHPData['parts'][$i]['points']); } break; case 23: case 25: $count = count($this->SHPData['parts']); $result = 22 + (2 * 4) + 2 * $count; for ($i = 0; $i < $count; ++$i) { $result += (8 + 4) * count($this->SHPData['parts'][$i]['points']); } break; case 13: case 15: $count = count($this->SHPData['parts']); $result = 22 + (4 * 4) + 2 * $count; for ($i = 0; $i < $count; ++$i) { $result += (8 + 8) * count($this->SHPData['parts'][$i]['points']); } break; case 8: $result = 20 + 8 * count($this->SHPData['points']); break; case 28: $result = 20 + (2 * 4) + (8 + 4) * count($this->SHPData['points']); break; case 18: $result = 20 + (4 * 4) + (8 + 8) * count($this->SHPData['points']); break; default: $result = false; $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)); break; } return $result; }
[ "public", "function", "getContentLength", "(", ")", "{", "// The content length for a record is the length of the record contents section measured in 16-bit words.", "// one coordinate makes 4 16-bit words (64 bit double)", "switch", "(", "$", "this", "->", "shapeType", ")", "{", "ca...
Returns length of content. @return int
[ "Returns", "length", "of", "content", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeRecord.php#L754-L811
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile.saveToFile
public function saveToFile($FileName = null) { if (! is_null($FileName)) { $this->FileName = $FileName; } if (($this->_openSHPFile(true)) && ($this->_openSHXFile(true)) && ($this->_createDBFFile())) { $this->_saveHeaders(); $this->_saveRecords(); $this->_closeSHPFile(); $this->_closeSHXFile(); $this->_closeDBFFile(); } else { return false; } }
php
public function saveToFile($FileName = null) { if (! is_null($FileName)) { $this->FileName = $FileName; } if (($this->_openSHPFile(true)) && ($this->_openSHXFile(true)) && ($this->_createDBFFile())) { $this->_saveHeaders(); $this->_saveRecords(); $this->_closeSHPFile(); $this->_closeSHXFile(); $this->_closeDBFFile(); } else { return false; } }
[ "public", "function", "saveToFile", "(", "$", "FileName", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "FileName", ")", ")", "{", "$", "this", "->", "FileName", "=", "$", "FileName", ";", "}", "if", "(", "(", "$", "this", "->", "_o...
Saves shapefile. @param string|null $FileName Name of file, otherwise existing is used
[ "Saves", "shapefile", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L127-L142
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile.updateBBox
private function updateBBox($type, $data) { $min = $type . 'min'; $max = $type . 'max'; if (! isset($this->boundingBox[$min]) || $this->boundingBox[$min] == 0.0 || ($this->boundingBox[$min] > $data[$min])) { $this->boundingBox[$min] = $data[$min]; } if (! isset($this->boundingBox[$max]) || $this->boundingBox[$max] == 0.0 || ($this->boundingBox[$max] < $data[$max])) { $this->boundingBox[$max] = $data[$max]; } }
php
private function updateBBox($type, $data) { $min = $type . 'min'; $max = $type . 'max'; if (! isset($this->boundingBox[$min]) || $this->boundingBox[$min] == 0.0 || ($this->boundingBox[$min] > $data[$min])) { $this->boundingBox[$min] = $data[$min]; } if (! isset($this->boundingBox[$max]) || $this->boundingBox[$max] == 0.0 || ($this->boundingBox[$max] < $data[$max])) { $this->boundingBox[$max] = $data[$max]; } }
[ "private", "function", "updateBBox", "(", "$", "type", ",", "$", "data", ")", "{", "$", "min", "=", "$", "type", ".", "'min'", ";", "$", "max", "=", "$", "type", ".", "'max'", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "boundingBox", ...
Updates bounding box based on SHPData. @param string $type Type of box @param array $data ShapeRecord SHPData
[ "Updates", "bounding", "box", "based", "on", "SHPData", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L162-L173
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile.addRecord
public function addRecord($record) { if ((isset($this->DBFHeader)) && (is_array($this->DBFHeader))) { $record->updateDBFInfo($this->DBFHeader); } $this->fileLength += ($record->getContentLength() + 4); $this->records[] = $record; $this->records[count($this->records) - 1]->recordNumber = count($this->records); $this->updateBBox('x', $record->SHPData); $this->updateBBox('y', $record->SHPData); if (in_array($this->shapeType, [11, 13, 15, 18, 21, 23, 25, 28])) { $this->updateBBox('m', $record->SHPData); } if (in_array($this->shapeType, [11, 13, 15, 18])) { $this->updateBBox('z', $record->SHPData); } return count($this->records) - 1; }
php
public function addRecord($record) { if ((isset($this->DBFHeader)) && (is_array($this->DBFHeader))) { $record->updateDBFInfo($this->DBFHeader); } $this->fileLength += ($record->getContentLength() + 4); $this->records[] = $record; $this->records[count($this->records) - 1]->recordNumber = count($this->records); $this->updateBBox('x', $record->SHPData); $this->updateBBox('y', $record->SHPData); if (in_array($this->shapeType, [11, 13, 15, 18, 21, 23, 25, 28])) { $this->updateBBox('m', $record->SHPData); } if (in_array($this->shapeType, [11, 13, 15, 18])) { $this->updateBBox('z', $record->SHPData); } return count($this->records) - 1; }
[ "public", "function", "addRecord", "(", "$", "record", ")", "{", "if", "(", "(", "isset", "(", "$", "this", "->", "DBFHeader", ")", ")", "&&", "(", "is_array", "(", "$", "this", "->", "DBFHeader", ")", ")", ")", "{", "$", "record", "->", "updateDBF...
Adds record to shape file. @param ShapeRecord $record @return int Number of added record
[ "Adds", "record", "to", "shape", "file", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L182-L204
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile.deleteRecord
public function deleteRecord($index) { if (isset($this->records[$index])) { $this->fileLength -= ($this->records[$index]->getContentLength() + 4); $count = count($this->records) - 1; for ($i = $index; $i < $count; ++$i) { $this->records[$i] = $this->records[$i + 1]; } unset($this->records[count($this->records) - 1]); $this->_deleteRecordFromDBF($index); } }
php
public function deleteRecord($index) { if (isset($this->records[$index])) { $this->fileLength -= ($this->records[$index]->getContentLength() + 4); $count = count($this->records) - 1; for ($i = $index; $i < $count; ++$i) { $this->records[$i] = $this->records[$i + 1]; } unset($this->records[count($this->records) - 1]); $this->_deleteRecordFromDBF($index); } }
[ "public", "function", "deleteRecord", "(", "$", "index", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "records", "[", "$", "index", "]", ")", ")", "{", "$", "this", "->", "fileLength", "-=", "(", "$", "this", "->", "records", "[", "$", "...
Deletes record from shapefile. @param int $index
[ "Deletes", "record", "from", "shapefile", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L211-L222
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile.setDBFHeader
public function setDBFHeader($header) { $this->DBFHeader = $header; $count = count($this->records); for ($i = 0; $i < $count; ++$i) { $this->records[$i]->updateDBFInfo($header); } }
php
public function setDBFHeader($header) { $this->DBFHeader = $header; $count = count($this->records); for ($i = 0; $i < $count; ++$i) { $this->records[$i]->updateDBFInfo($header); } }
[ "public", "function", "setDBFHeader", "(", "$", "header", ")", "{", "$", "this", "->", "DBFHeader", "=", "$", "header", ";", "$", "count", "=", "count", "(", "$", "this", "->", "records", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", ...
Changes array defining fields in DBF file, used in dbase_create call. @param array $header An array of arrays, each array describing the format of one field of the database. Each field consists of a name, a character indicating the field type, and optionally, a length, a precision and a nullable flag.
[ "Changes", "array", "defining", "fields", "in", "DBF", "file", "used", "in", "dbase_create", "call", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L243-L251
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile.getIndexFromDBFData
public function getIndexFromDBFData($field, $value) { foreach ($this->records as $index => $record) { if (isset($record->DBFData[$field]) && (trim(strtoupper($record->DBFData[$field])) == strtoupper($value)) ) { return $index; } } return -1; }
php
public function getIndexFromDBFData($field, $value) { foreach ($this->records as $index => $record) { if (isset($record->DBFData[$field]) && (trim(strtoupper($record->DBFData[$field])) == strtoupper($value)) ) { return $index; } } return -1; }
[ "public", "function", "getIndexFromDBFData", "(", "$", "field", ",", "$", "value", ")", "{", "foreach", "(", "$", "this", "->", "records", "as", "$", "index", "=>", "$", "record", ")", "{", "if", "(", "isset", "(", "$", "record", "->", "DBFData", "["...
Lookups value in the DBF file and returs index. @param string $field Field to match @param mixed $value Value to match @return int
[ "Lookups", "value", "in", "the", "DBF", "file", "and", "returs", "index", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L261-L272
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile._loadDBFHeader
private function _loadDBFHeader() { $DBFFile = fopen($this->_getFilename('.dbf'), 'r'); $result = []; $i = 1; $inHeader = true; while ($inHeader) { if (! feof($DBFFile)) { $buff32 = fread($DBFFile, 32); if ($i > 1) { if (substr($buff32, 0, 1) == chr(13)) { $inHeader = false; } else { $pos = strpos(substr($buff32, 0, 10), chr(0)); $pos = ($pos == 0 ? 10 : $pos); $fieldName = substr($buff32, 0, $pos); $fieldType = substr($buff32, 11, 1); $fieldLen = ord(substr($buff32, 16, 1)); $fieldDec = ord(substr($buff32, 17, 1)); array_push($result, [$fieldName, $fieldType, $fieldLen, $fieldDec]); } } ++$i; } else { $inHeader = false; } } fclose($DBFFile); return $result; }
php
private function _loadDBFHeader() { $DBFFile = fopen($this->_getFilename('.dbf'), 'r'); $result = []; $i = 1; $inHeader = true; while ($inHeader) { if (! feof($DBFFile)) { $buff32 = fread($DBFFile, 32); if ($i > 1) { if (substr($buff32, 0, 1) == chr(13)) { $inHeader = false; } else { $pos = strpos(substr($buff32, 0, 10), chr(0)); $pos = ($pos == 0 ? 10 : $pos); $fieldName = substr($buff32, 0, $pos); $fieldType = substr($buff32, 11, 1); $fieldLen = ord(substr($buff32, 16, 1)); $fieldDec = ord(substr($buff32, 17, 1)); array_push($result, [$fieldName, $fieldType, $fieldLen, $fieldDec]); } } ++$i; } else { $inHeader = false; } } fclose($DBFFile); return $result; }
[ "private", "function", "_loadDBFHeader", "(", ")", "{", "$", "DBFFile", "=", "fopen", "(", "$", "this", "->", "_getFilename", "(", "'.dbf'", ")", ",", "'r'", ")", ";", "$", "result", "=", "[", "]", ";", "$", "i", "=", "1", ";", "$", "inHeader", "...
Loads DBF metadata.
[ "Loads", "DBF", "metadata", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L277-L312
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile._deleteRecordFromDBF
private function _deleteRecordFromDBF($index) { if ($this->DBFFile !== null && @dbase_delete_record($this->DBFFile, $index)) { dbase_pack($this->DBFFile); } }
php
private function _deleteRecordFromDBF($index) { if ($this->DBFFile !== null && @dbase_delete_record($this->DBFFile, $index)) { dbase_pack($this->DBFFile); } }
[ "private", "function", "_deleteRecordFromDBF", "(", "$", "index", ")", "{", "if", "(", "$", "this", "->", "DBFFile", "!==", "null", "&&", "@", "dbase_delete_record", "(", "$", "this", "->", "DBFFile", ",", "$", "index", ")", ")", "{", "dbase_pack", "(", ...
Deletes record from the DBF file. @param int $index
[ "Deletes", "record", "from", "the", "DBF", "file", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L319-L324
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile._loadHeaders
private function _loadHeaders() { if (Util::loadData('N', $this->readSHP(4)) != self::MAGIC) { $this->setError('Not a SHP file (file code mismatch)'); return false; } /* Skip 20 unused bytes */ $this->readSHP(20); $this->fileLength = Util::loadData('N', $this->readSHP(4)); /* We currently ignore version */ $this->readSHP(4); $this->shapeType = Util::loadData('V', $this->readSHP(4)); $this->boundingBox = []; $this->boundingBox['xmin'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['ymin'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['xmax'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['ymax'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['zmin'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['zmax'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['mmin'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['mmax'] = Util::loadData('d', $this->readSHP(8)); if (self::supportsDbase()) { $this->DBFHeader = $this->_loadDBFHeader(); } return true; }
php
private function _loadHeaders() { if (Util::loadData('N', $this->readSHP(4)) != self::MAGIC) { $this->setError('Not a SHP file (file code mismatch)'); return false; } /* Skip 20 unused bytes */ $this->readSHP(20); $this->fileLength = Util::loadData('N', $this->readSHP(4)); /* We currently ignore version */ $this->readSHP(4); $this->shapeType = Util::loadData('V', $this->readSHP(4)); $this->boundingBox = []; $this->boundingBox['xmin'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['ymin'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['xmax'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['ymax'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['zmin'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['zmax'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['mmin'] = Util::loadData('d', $this->readSHP(8)); $this->boundingBox['mmax'] = Util::loadData('d', $this->readSHP(8)); if (self::supportsDbase()) { $this->DBFHeader = $this->_loadDBFHeader(); } return true; }
[ "private", "function", "_loadHeaders", "(", ")", "{", "if", "(", "Util", "::", "loadData", "(", "'N'", ",", "$", "this", "->", "readSHP", "(", "4", ")", ")", "!=", "self", "::", "MAGIC", ")", "{", "$", "this", "->", "setError", "(", "'Not a SHP file ...
Loads SHP file metadata. @return bool
[ "Loads", "SHP", "file", "metadata", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L331-L364
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile._saveBBoxRecord
private function _saveBBoxRecord($file, $type) { fwrite($file, Util::packDouble( isset($this->boundingBox[$type]) ? $this->boundingBox[$type] : 0 )); }
php
private function _saveBBoxRecord($file, $type) { fwrite($file, Util::packDouble( isset($this->boundingBox[$type]) ? $this->boundingBox[$type] : 0 )); }
[ "private", "function", "_saveBBoxRecord", "(", "$", "file", ",", "$", "type", ")", "{", "fwrite", "(", "$", "file", ",", "Util", "::", "packDouble", "(", "isset", "(", "$", "this", "->", "boundingBox", "[", "$", "type", "]", ")", "?", "$", "this", ...
Saves bounding box record, possibly using 0 instead of not set values. @param file $file File object @param string $type Bounding box dimension (eg. xmax, mmin...)
[ "Saves", "bounding", "box", "record", "possibly", "using", "0", "instead", "of", "not", "set", "values", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L372-L377
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile._saveBBox
private function _saveBBox($file) { $this->_saveBBoxRecord($file, 'xmin'); $this->_saveBBoxRecord($file, 'ymin'); $this->_saveBBoxRecord($file, 'xmax'); $this->_saveBBoxRecord($file, 'ymax'); $this->_saveBBoxRecord($file, 'zmin'); $this->_saveBBoxRecord($file, 'zmax'); $this->_saveBBoxRecord($file, 'mmin'); $this->_saveBBoxRecord($file, 'mmax'); }
php
private function _saveBBox($file) { $this->_saveBBoxRecord($file, 'xmin'); $this->_saveBBoxRecord($file, 'ymin'); $this->_saveBBoxRecord($file, 'xmax'); $this->_saveBBoxRecord($file, 'ymax'); $this->_saveBBoxRecord($file, 'zmin'); $this->_saveBBoxRecord($file, 'zmax'); $this->_saveBBoxRecord($file, 'mmin'); $this->_saveBBoxRecord($file, 'mmax'); }
[ "private", "function", "_saveBBox", "(", "$", "file", ")", "{", "$", "this", "->", "_saveBBoxRecord", "(", "$", "file", ",", "'xmin'", ")", ";", "$", "this", "->", "_saveBBoxRecord", "(", "$", "file", ",", "'ymin'", ")", ";", "$", "this", "->", "_sav...
Saves bounding box to a file. @param file $file File object
[ "Saves", "bounding", "box", "to", "a", "file", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L384-L394
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile._saveHeaders
private function _saveHeaders() { fwrite($this->SHPFile, pack('NNNNNN', self::MAGIC, 0, 0, 0, 0, 0)); fwrite($this->SHPFile, pack('N', $this->fileLength)); fwrite($this->SHPFile, pack('V', 1000)); fwrite($this->SHPFile, pack('V', $this->shapeType)); $this->_saveBBox($this->SHPFile); fwrite($this->SHXFile, pack('NNNNNN', self::MAGIC, 0, 0, 0, 0, 0)); fwrite($this->SHXFile, pack('N', 50 + 4 * count($this->records))); fwrite($this->SHXFile, pack('V', 1000)); fwrite($this->SHXFile, pack('V', $this->shapeType)); $this->_saveBBox($this->SHXFile); }
php
private function _saveHeaders() { fwrite($this->SHPFile, pack('NNNNNN', self::MAGIC, 0, 0, 0, 0, 0)); fwrite($this->SHPFile, pack('N', $this->fileLength)); fwrite($this->SHPFile, pack('V', 1000)); fwrite($this->SHPFile, pack('V', $this->shapeType)); $this->_saveBBox($this->SHPFile); fwrite($this->SHXFile, pack('NNNNNN', self::MAGIC, 0, 0, 0, 0, 0)); fwrite($this->SHXFile, pack('N', 50 + 4 * count($this->records))); fwrite($this->SHXFile, pack('V', 1000)); fwrite($this->SHXFile, pack('V', $this->shapeType)); $this->_saveBBox($this->SHXFile); }
[ "private", "function", "_saveHeaders", "(", ")", "{", "fwrite", "(", "$", "this", "->", "SHPFile", ",", "pack", "(", "'NNNNNN'", ",", "self", "::", "MAGIC", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ")", ")", ";", "fwrite", "(", "$", "t...
Saves SHP and SHX file metadata.
[ "Saves", "SHP", "and", "SHX", "file", "metadata", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L399-L412
train
phpmyadmin/shapefile
src/ShapeFile.php
ShapeFile._saveRecords
private function _saveRecords() { $offset = 50; if (is_array($this->records) && (count($this->records) > 0)) { foreach ($this->records as $index => $record) { //Save the record to the .shp file $record->saveToFile($this->SHPFile, $this->DBFFile, $index + 1); //Save the record to the .shx file fwrite($this->SHXFile, pack('N', $offset)); fwrite($this->SHXFile, pack('N', $record->getContentLength())); $offset += (4 + $record->getContentLength()); } } }
php
private function _saveRecords() { $offset = 50; if (is_array($this->records) && (count($this->records) > 0)) { foreach ($this->records as $index => $record) { //Save the record to the .shp file $record->saveToFile($this->SHPFile, $this->DBFFile, $index + 1); //Save the record to the .shx file fwrite($this->SHXFile, pack('N', $offset)); fwrite($this->SHXFile, pack('N', $record->getContentLength())); $offset += (4 + $record->getContentLength()); } } }
[ "private", "function", "_saveRecords", "(", ")", "{", "$", "offset", "=", "50", ";", "if", "(", "is_array", "(", "$", "this", "->", "records", ")", "&&", "(", "count", "(", "$", "this", "->", "records", ")", ">", "0", ")", ")", "{", "foreach", "(...
Saves records to SHP and SHX files.
[ "Saves", "records", "to", "SHP", "and", "SHX", "files", "." ]
f4f359b58ea3065ea85e3aa3bb8b677a24861363
https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L443-L457
train