id
int32
0
241k
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
31,100
shimabox/SMBArrayto
src/SMB/Arrayto/Traits/Xml/Creatable.php
Creatable.createOutputContents
protected function createOutputContents() { $dom = $this->formatterInstance() ->forge( $this->rows, $this->rootElementName, $this->replaceSpacesByUnderScoresInKeyNames, $this->versionOfXmlDeclaration, $this->encodingOfXmlDeclaration )->toDom(); $dom->formatOutput = $this->formatOutput; return $dom->saveXML(); }
php
protected function createOutputContents() { $dom = $this->formatterInstance() ->forge( $this->rows, $this->rootElementName, $this->replaceSpacesByUnderScoresInKeyNames, $this->versionOfXmlDeclaration, $this->encodingOfXmlDeclaration )->toDom(); $dom->formatOutput = $this->formatOutput; return $dom->saveXML(); }
[ "protected", "function", "createOutputContents", "(", ")", "{", "$", "dom", "=", "$", "this", "->", "formatterInstance", "(", ")", "->", "forge", "(", "$", "this", "->", "rows", ",", "$", "this", "->", "rootElementName", ",", "$", "this", "->", "replaceSpacesByUnderScoresInKeyNames", ",", "$", "this", "->", "versionOfXmlDeclaration", ",", "$", "this", "->", "encodingOfXmlDeclaration", ")", "->", "toDom", "(", ")", ";", "$", "dom", "->", "formatOutput", "=", "$", "this", "->", "formatOutput", ";", "return", "$", "dom", "->", "saveXML", "(", ")", ";", "}" ]
Create an output content for XML @return string
[ "Create", "an", "output", "content", "for", "XML" ]
7ecacc0c15994c02224bbd3efe055d3bce243971
https://github.com/shimabox/SMBArrayto/blob/7ecacc0c15994c02224bbd3efe055d3bce243971/src/SMB/Arrayto/Traits/Xml/Creatable.php#L89-L103
31,101
pulsarvp/vps-tools
src/html/Form.php
Form.init
public function init () { if (!in_array($this->layout, [ 'default', 'horizontal', 'inline' ])) throw new InvalidConfigException('Invalid layout type: ' . $this->layout); if ($this->layout !== 'default') Html::addCssClass($this->options, 'form-' . $this->layout); if ($this->name) $this->options[ 'name' ] = $this->name; parent::init(); }
php
public function init () { if (!in_array($this->layout, [ 'default', 'horizontal', 'inline' ])) throw new InvalidConfigException('Invalid layout type: ' . $this->layout); if ($this->layout !== 'default') Html::addCssClass($this->options, 'form-' . $this->layout); if ($this->name) $this->options[ 'name' ] = $this->name; parent::init(); }
[ "public", "function", "init", "(", ")", "{", "if", "(", "!", "in_array", "(", "$", "this", "->", "layout", ",", "[", "'default'", ",", "'horizontal'", ",", "'inline'", "]", ")", ")", "throw", "new", "InvalidConfigException", "(", "'Invalid layout type: '", ".", "$", "this", "->", "layout", ")", ";", "if", "(", "$", "this", "->", "layout", "!==", "'default'", ")", "Html", "::", "addCssClass", "(", "$", "this", "->", "options", ",", "'form-'", ".", "$", "this", "->", "layout", ")", ";", "if", "(", "$", "this", "->", "name", ")", "$", "this", "->", "options", "[", "'name'", "]", "=", "$", "this", "->", "name", ";", "parent", "::", "init", "(", ")", ";", "}" ]
Adds some default configuration. I.e. form name and layout class. @inheritdoc
[ "Adds", "some", "default", "configuration", ".", "I", ".", "e", ".", "form", "name", "and", "layout", "class", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/html/Form.php#L71-L83
31,102
pulsarvp/vps-tools
src/modules/page/controllers/PageController.php
PageController.actionFrontend
public function actionFrontend ($id) { $page = Page::find()->where([ 'guid' => $id ])->one(); if ($page === null) { throw new \yii\web\HttpException(404); } $this->setTitle($page->title); $this->data('page', $page); $this->_tpl = '@pageViews/page'; }
php
public function actionFrontend ($id) { $page = Page::find()->where([ 'guid' => $id ])->one(); if ($page === null) { throw new \yii\web\HttpException(404); } $this->setTitle($page->title); $this->data('page', $page); $this->_tpl = '@pageViews/page'; }
[ "public", "function", "actionFrontend", "(", "$", "id", ")", "{", "$", "page", "=", "Page", "::", "find", "(", ")", "->", "where", "(", "[", "'guid'", "=>", "$", "id", "]", ")", "->", "one", "(", ")", ";", "if", "(", "$", "page", "===", "null", ")", "{", "throw", "new", "\\", "yii", "\\", "web", "\\", "HttpException", "(", "404", ")", ";", "}", "$", "this", "->", "setTitle", "(", "$", "page", "->", "title", ")", ";", "$", "this", "->", "data", "(", "'page'", ",", "$", "page", ")", ";", "$", "this", "->", "_tpl", "=", "'@pageViews/page'", ";", "}" ]
View frontend page @param $id page
[ "View", "frontend", "page" ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/page/controllers/PageController.php#L123-L134
31,103
shimabox/SMBArrayto
src/SMB/Arrayto/Traits/Xsv/Creatable.php
Creatable.createOutputContents
protected function createOutputContents( array $header, $delimiter = ',', $enclosure = '"', $toConvert = true ) { $fp = fopen("php://temp", 'r+b'); // header if ($header) { fputcsv($fp, $header, $delimiter, $enclosure); } foreach ($this->rows as $row) { fputcsv($fp, $row, $delimiter, $enclosure); } rewind($fp); $buffer = stream_get_contents($fp); if ($toConvert === false) { fclose($fp); return $buffer; } $ret = $this->convert($buffer); fclose($fp); return $ret; }
php
protected function createOutputContents( array $header, $delimiter = ',', $enclosure = '"', $toConvert = true ) { $fp = fopen("php://temp", 'r+b'); // header if ($header) { fputcsv($fp, $header, $delimiter, $enclosure); } foreach ($this->rows as $row) { fputcsv($fp, $row, $delimiter, $enclosure); } rewind($fp); $buffer = stream_get_contents($fp); if ($toConvert === false) { fclose($fp); return $buffer; } $ret = $this->convert($buffer); fclose($fp); return $ret; }
[ "protected", "function", "createOutputContents", "(", "array", "$", "header", ",", "$", "delimiter", "=", "','", ",", "$", "enclosure", "=", "'\"'", ",", "$", "toConvert", "=", "true", ")", "{", "$", "fp", "=", "fopen", "(", "\"php://temp\"", ",", "'r+b'", ")", ";", "// header", "if", "(", "$", "header", ")", "{", "fputcsv", "(", "$", "fp", ",", "$", "header", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "fputcsv", "(", "$", "fp", ",", "$", "row", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "rewind", "(", "$", "fp", ")", ";", "$", "buffer", "=", "stream_get_contents", "(", "$", "fp", ")", ";", "if", "(", "$", "toConvert", "===", "false", ")", "{", "fclose", "(", "$", "fp", ")", ";", "return", "$", "buffer", ";", "}", "$", "ret", "=", "$", "this", "->", "convert", "(", "$", "buffer", ")", ";", "fclose", "(", "$", "fp", ")", ";", "return", "$", "ret", ";", "}" ]
Create an output content @param array $header @param string $delimiter @param string $enclosure @param boolean $toConvert true : LF => CRLF, UTF-8 => SJIS-win, false : LF, UTF-8 @return string
[ "Create", "an", "output", "content" ]
7ecacc0c15994c02224bbd3efe055d3bce243971
https://github.com/shimabox/SMBArrayto/blob/7ecacc0c15994c02224bbd3efe055d3bce243971/src/SMB/Arrayto/Traits/Xsv/Creatable.php#L36-L68
31,104
wikimedia/slimapp
src/Auth/Password.php
Password.comparePasswordToHash
public static function comparePasswordToHash( $plainText, $hash ) { if ( self::isBlowfishHash( $hash ) ) { $check = crypt( $plainText, $hash ); } else { // horrible unsalted md5 that legacy app used for passwords $check = md5( $plainText ); } return self::hashEquals( $hash, $check ); }
php
public static function comparePasswordToHash( $plainText, $hash ) { if ( self::isBlowfishHash( $hash ) ) { $check = crypt( $plainText, $hash ); } else { // horrible unsalted md5 that legacy app used for passwords $check = md5( $plainText ); } return self::hashEquals( $hash, $check ); }
[ "public", "static", "function", "comparePasswordToHash", "(", "$", "plainText", ",", "$", "hash", ")", "{", "if", "(", "self", "::", "isBlowfishHash", "(", "$", "hash", ")", ")", "{", "$", "check", "=", "crypt", "(", "$", "plainText", ",", "$", "hash", ")", ";", "}", "else", "{", "// horrible unsalted md5 that legacy app used for passwords", "$", "check", "=", "md5", "(", "$", "plainText", ")", ";", "}", "return", "self", "::", "hashEquals", "(", "$", "hash", ",", "$", "check", ")", ";", "}" ]
Compare a plain text string to a stored password hash. @param string $plainText Password to check @param string $hash Stored hash to compare with @return bool True if plain text matches hash, false otherwise
[ "Compare", "a", "plain", "text", "string", "to", "a", "stored", "password", "hash", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Auth/Password.php#L47-L57
31,105
wikimedia/slimapp
src/Auth/Password.php
Password.blowfishSalt
public static function blowfishSalt( $cost = 8 ) { // encoding algorithm from http://www.openwall.com/phpass/ $itoa = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; if ( $cost < 4 || $cost > 31 ) { $cost = 8; } $random = self::getBytes( 16 ); $output = self::BLOWFISH_PREFIX; $output .= chr( ord( '0' ) + $cost / 10 ); $output .= chr( ord( '0' ) + $cost % 10 ); $output .= '$'; $i = 0; do { $c1 = ord( $random[$i++] ); $output .= $itoa[$c1 >> 2]; $c1 = ( $c1 & 0x03 ) << 4; if ( $i >= 16 ) { $output .= $itoa[$c1]; break; } $c2 = ord( $random[$i++] ); $c1 |= $c2 >> 4; $output .= $itoa[$c1]; $c1 = ( $c2 & 0x0f ) << 2; $c2 = ord( $random[$i++] ); $c1 |= $c2 >> 6; $output .= $itoa[$c1]; $output .= $itoa[$c2 & 0x3f]; } while ( 1 ); return $output; }
php
public static function blowfishSalt( $cost = 8 ) { // encoding algorithm from http://www.openwall.com/phpass/ $itoa = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; if ( $cost < 4 || $cost > 31 ) { $cost = 8; } $random = self::getBytes( 16 ); $output = self::BLOWFISH_PREFIX; $output .= chr( ord( '0' ) + $cost / 10 ); $output .= chr( ord( '0' ) + $cost % 10 ); $output .= '$'; $i = 0; do { $c1 = ord( $random[$i++] ); $output .= $itoa[$c1 >> 2]; $c1 = ( $c1 & 0x03 ) << 4; if ( $i >= 16 ) { $output .= $itoa[$c1]; break; } $c2 = ord( $random[$i++] ); $c1 |= $c2 >> 4; $output .= $itoa[$c1]; $c1 = ( $c2 & 0x0f ) << 2; $c2 = ord( $random[$i++] ); $c1 |= $c2 >> 6; $output .= $itoa[$c1]; $output .= $itoa[$c2 & 0x3f]; } while ( 1 ); return $output; }
[ "public", "static", "function", "blowfishSalt", "(", "$", "cost", "=", "8", ")", "{", "// encoding algorithm from http://www.openwall.com/phpass/", "$", "itoa", "=", "'./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'", ";", "if", "(", "$", "cost", "<", "4", "||", "$", "cost", ">", "31", ")", "{", "$", "cost", "=", "8", ";", "}", "$", "random", "=", "self", "::", "getBytes", "(", "16", ")", ";", "$", "output", "=", "self", "::", "BLOWFISH_PREFIX", ";", "$", "output", ".=", "chr", "(", "ord", "(", "'0'", ")", "+", "$", "cost", "/", "10", ")", ";", "$", "output", ".=", "chr", "(", "ord", "(", "'0'", ")", "+", "$", "cost", "%", "10", ")", ";", "$", "output", ".=", "'$'", ";", "$", "i", "=", "0", ";", "do", "{", "$", "c1", "=", "ord", "(", "$", "random", "[", "$", "i", "++", "]", ")", ";", "$", "output", ".=", "$", "itoa", "[", "$", "c1", ">>", "2", "]", ";", "$", "c1", "=", "(", "$", "c1", "&", "0x03", ")", "<<", "4", ";", "if", "(", "$", "i", ">=", "16", ")", "{", "$", "output", ".=", "$", "itoa", "[", "$", "c1", "]", ";", "break", ";", "}", "$", "c2", "=", "ord", "(", "$", "random", "[", "$", "i", "++", "]", ")", ";", "$", "c1", "|=", "$", "c2", ">>", "4", ";", "$", "output", ".=", "$", "itoa", "[", "$", "c1", "]", ";", "$", "c1", "=", "(", "$", "c2", "&", "0x0f", ")", "<<", "2", ";", "$", "c2", "=", "ord", "(", "$", "random", "[", "$", "i", "++", "]", ")", ";", "$", "c1", "|=", "$", "c2", ">>", "6", ";", "$", "output", ".=", "$", "itoa", "[", "$", "c1", "]", ";", "$", "output", ".=", "$", "itoa", "[", "$", "c2", "&", "0x3f", "]", ";", "}", "while", "(", "1", ")", ";", "return", "$", "output", ";", "}" ]
Generate a blowfish salt specification. @param int $cost Cost factor @return string Blowfish salt
[ "Generate", "a", "blowfish", "salt", "specification", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Auth/Password.php#L81-L116
31,106
wikimedia/slimapp
src/Auth/Password.php
Password.getBytes
public static function getBytes( $count, $allowWeak = false ) { if ( function_exists( 'random_bytes' ) ) { $bytes = random_bytes( $count ); if ( strlen( $bytes ) === $count ) { return $bytes; } } if ( function_exists( 'mcrypt_create_iv' ) ) { $bytes = mcrypt_create_iv( $count, MCRYPT_DEV_URANDOM ); if ( strlen( $bytes ) === $count ) { return $bytes; } } if ( function_exists( 'openssl_random_pseudo_bytes' ) ) { $bytes = openssl_random_pseudo_bytes( $count, $strong ); if ( $strong && strlen( $bytes ) === $count ) { return $bytes; } } if ( is_readable( '/dev/urandom' ) ) { // @codingStandardsIgnoreStart : Silencing errors is discouraged $fh = @fopen( '/dev/urandom', 'rb' ); // @codingStandardsIgnoreEnd if ( false !== $fh ) { $bytes = ''; $have = 0; while ( $have < $count ) { $bytes .= fread( $fh, $count - $have ); $have = strlen( $bytes ); } fclose( $fh ); if ( strlen( $bytes ) === $count ) { return $bytes; } } } if ( $allowWeak !== true ) { throw new InvalidArgumentException( 'No high entropy source of random data found and ' . 'weak sources disallowed in function call' ); } // create a high entropy seed value $seed = microtime() . uniqid( '', true ); if ( function_exists( 'getmypid' ) ) { $seed .= getmypid(); } $bytes = ''; for ( $i = 0; $i < $count; $i += 16 ) { $seed = md5( microtime() . $seed ); $bytes .= pack( 'H*', md5( $seed ) ); } return substr( $bytes, 0, $count ); }
php
public static function getBytes( $count, $allowWeak = false ) { if ( function_exists( 'random_bytes' ) ) { $bytes = random_bytes( $count ); if ( strlen( $bytes ) === $count ) { return $bytes; } } if ( function_exists( 'mcrypt_create_iv' ) ) { $bytes = mcrypt_create_iv( $count, MCRYPT_DEV_URANDOM ); if ( strlen( $bytes ) === $count ) { return $bytes; } } if ( function_exists( 'openssl_random_pseudo_bytes' ) ) { $bytes = openssl_random_pseudo_bytes( $count, $strong ); if ( $strong && strlen( $bytes ) === $count ) { return $bytes; } } if ( is_readable( '/dev/urandom' ) ) { // @codingStandardsIgnoreStart : Silencing errors is discouraged $fh = @fopen( '/dev/urandom', 'rb' ); // @codingStandardsIgnoreEnd if ( false !== $fh ) { $bytes = ''; $have = 0; while ( $have < $count ) { $bytes .= fread( $fh, $count - $have ); $have = strlen( $bytes ); } fclose( $fh ); if ( strlen( $bytes ) === $count ) { return $bytes; } } } if ( $allowWeak !== true ) { throw new InvalidArgumentException( 'No high entropy source of random data found and ' . 'weak sources disallowed in function call' ); } // create a high entropy seed value $seed = microtime() . uniqid( '', true ); if ( function_exists( 'getmypid' ) ) { $seed .= getmypid(); } $bytes = ''; for ( $i = 0; $i < $count; $i += 16 ) { $seed = md5( microtime() . $seed ); $bytes .= pack( 'H*', md5( $seed ) ); } return substr( $bytes, 0, $count ); }
[ "public", "static", "function", "getBytes", "(", "$", "count", ",", "$", "allowWeak", "=", "false", ")", "{", "if", "(", "function_exists", "(", "'random_bytes'", ")", ")", "{", "$", "bytes", "=", "random_bytes", "(", "$", "count", ")", ";", "if", "(", "strlen", "(", "$", "bytes", ")", "===", "$", "count", ")", "{", "return", "$", "bytes", ";", "}", "}", "if", "(", "function_exists", "(", "'mcrypt_create_iv'", ")", ")", "{", "$", "bytes", "=", "mcrypt_create_iv", "(", "$", "count", ",", "MCRYPT_DEV_URANDOM", ")", ";", "if", "(", "strlen", "(", "$", "bytes", ")", "===", "$", "count", ")", "{", "return", "$", "bytes", ";", "}", "}", "if", "(", "function_exists", "(", "'openssl_random_pseudo_bytes'", ")", ")", "{", "$", "bytes", "=", "openssl_random_pseudo_bytes", "(", "$", "count", ",", "$", "strong", ")", ";", "if", "(", "$", "strong", "&&", "strlen", "(", "$", "bytes", ")", "===", "$", "count", ")", "{", "return", "$", "bytes", ";", "}", "}", "if", "(", "is_readable", "(", "'/dev/urandom'", ")", ")", "{", "// @codingStandardsIgnoreStart : Silencing errors is discouraged", "$", "fh", "=", "@", "fopen", "(", "'/dev/urandom'", ",", "'rb'", ")", ";", "// @codingStandardsIgnoreEnd", "if", "(", "false", "!==", "$", "fh", ")", "{", "$", "bytes", "=", "''", ";", "$", "have", "=", "0", ";", "while", "(", "$", "have", "<", "$", "count", ")", "{", "$", "bytes", ".=", "fread", "(", "$", "fh", ",", "$", "count", "-", "$", "have", ")", ";", "$", "have", "=", "strlen", "(", "$", "bytes", ")", ";", "}", "fclose", "(", "$", "fh", ")", ";", "if", "(", "strlen", "(", "$", "bytes", ")", "===", "$", "count", ")", "{", "return", "$", "bytes", ";", "}", "}", "}", "if", "(", "$", "allowWeak", "!==", "true", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'No high entropy source of random data found and '", ".", "'weak sources disallowed in function call'", ")", ";", "}", "// create a high entropy seed value", "$", "seed", "=", "microtime", "(", ")", ".", "uniqid", "(", "''", ",", "true", ")", ";", "if", "(", "function_exists", "(", "'getmypid'", ")", ")", "{", "$", "seed", ".=", "getmypid", "(", ")", ";", "}", "$", "bytes", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "+=", "16", ")", "{", "$", "seed", "=", "md5", "(", "microtime", "(", ")", ".", "$", "seed", ")", ";", "$", "bytes", ".=", "pack", "(", "'H*'", ",", "md5", "(", "$", "seed", ")", ")", ";", "}", "return", "substr", "(", "$", "bytes", ",", "0", ",", "$", "count", ")", ";", "}" ]
Get N high entropy random bytes. @param int $count Number of bytes to generate @param bool $allowWeak Allow weak entropy sources @return string String of random bytes @throws InvalidArgumentException if $allowWeak is false and no high entropy sources of random data can be found
[ "Get", "N", "high", "entropy", "random", "bytes", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Auth/Password.php#L127-L190
31,107
wikimedia/slimapp
src/Auth/Password.php
Password.isBlowfishHash
public static function isBlowfishHash( $hash ) { $peek = strlen( self::BLOWFISH_PREFIX ); return strlen( $hash ) == 60 && substr( $hash, 0, $peek ) == self::BLOWFISH_PREFIX; }
php
public static function isBlowfishHash( $hash ) { $peek = strlen( self::BLOWFISH_PREFIX ); return strlen( $hash ) == 60 && substr( $hash, 0, $peek ) == self::BLOWFISH_PREFIX; }
[ "public", "static", "function", "isBlowfishHash", "(", "$", "hash", ")", "{", "$", "peek", "=", "strlen", "(", "self", "::", "BLOWFISH_PREFIX", ")", ";", "return", "strlen", "(", "$", "hash", ")", "==", "60", "&&", "substr", "(", "$", "hash", ",", "0", ",", "$", "peek", ")", "==", "self", "::", "BLOWFISH_PREFIX", ";", "}" ]
Check a salt specification to see if it is a blowfish crypt value. @param string $hash Hash to check @return bool True if blowfish, false otherwise.
[ "Check", "a", "salt", "specification", "to", "see", "if", "it", "is", "a", "blowfish", "crypt", "value", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Auth/Password.php#L198-L202
31,108
wikimedia/slimapp
src/Auth/Password.php
Password.hashEquals
public static function hashEquals( $known, $input ) { if ( !is_string( $known ) ) { return false; } if ( !is_string( $input ) ) { return false; } if ( function_exists( 'hash_equals' ) ) { return hash_equals( $known, $input ); } else { // hash_equals() polyfill taken from MediaWiki $len = strlen( $known ); if ( $len !== strlen( $input ) ) { return false; } $result = 0; for ( $i = 0; $i < $len; $i++ ) { $result |= ord( $known[$i] ) ^ ord( $input[$i] ); } return $result === 0; } }
php
public static function hashEquals( $known, $input ) { if ( !is_string( $known ) ) { return false; } if ( !is_string( $input ) ) { return false; } if ( function_exists( 'hash_equals' ) ) { return hash_equals( $known, $input ); } else { // hash_equals() polyfill taken from MediaWiki $len = strlen( $known ); if ( $len !== strlen( $input ) ) { return false; } $result = 0; for ( $i = 0; $i < $len; $i++ ) { $result |= ord( $known[$i] ) ^ ord( $input[$i] ); } return $result === 0; } }
[ "public", "static", "function", "hashEquals", "(", "$", "known", ",", "$", "input", ")", "{", "if", "(", "!", "is_string", "(", "$", "known", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "is_string", "(", "$", "input", ")", ")", "{", "return", "false", ";", "}", "if", "(", "function_exists", "(", "'hash_equals'", ")", ")", "{", "return", "hash_equals", "(", "$", "known", ",", "$", "input", ")", ";", "}", "else", "{", "// hash_equals() polyfill taken from MediaWiki", "$", "len", "=", "strlen", "(", "$", "known", ")", ";", "if", "(", "$", "len", "!==", "strlen", "(", "$", "input", ")", ")", "{", "return", "false", ";", "}", "$", "result", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "$", "result", "|=", "ord", "(", "$", "known", "[", "$", "i", "]", ")", "^", "ord", "(", "$", "input", "[", "$", "i", "]", ")", ";", "}", "return", "$", "result", "===", "0", ";", "}", "}" ]
Check whether a user-provided string is equal to a fixed-length secret string without revealing bytes of the secret string through timing differences. Implementation for PHP deployments which do not natively have hash_equals taken from MediaWiki's hash_equals() polyfill function. @param string $known Fixed-length secret string to compare against @param string $input User-provided string @return bool True if the strings are the same, false otherwise
[ "Check", "whether", "a", "user", "-", "provided", "string", "is", "equal", "to", "a", "fixed", "-", "length", "secret", "string", "without", "revealing", "bytes", "of", "the", "secret", "string", "through", "timing", "differences", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Auth/Password.php#L255-L280
31,109
bearcms/bearframework-addon
classes/BearCMS/CurrentUser.php
CurrentUser.getSessionKey
public function getSessionKey(): ?string { $cacheKey = 'sessionkey'; if (!isset(self::$cache[$cacheKey])) { $cookies = Internal\Cookies::getList(Internal\Cookies::TYPE_SERVER); $cookieKey = '_s'; $key = isset($cookies[$cookieKey]) ? (string) $cookies[$cookieKey] : ''; self::$cache[$cacheKey] = strlen((string) $key) > 70 ? $key : null; } return self::$cache[$cacheKey]; }
php
public function getSessionKey(): ?string { $cacheKey = 'sessionkey'; if (!isset(self::$cache[$cacheKey])) { $cookies = Internal\Cookies::getList(Internal\Cookies::TYPE_SERVER); $cookieKey = '_s'; $key = isset($cookies[$cookieKey]) ? (string) $cookies[$cookieKey] : ''; self::$cache[$cacheKey] = strlen((string) $key) > 70 ? $key : null; } return self::$cache[$cacheKey]; }
[ "public", "function", "getSessionKey", "(", ")", ":", "?", "string", "{", "$", "cacheKey", "=", "'sessionkey'", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "cache", "[", "$", "cacheKey", "]", ")", ")", "{", "$", "cookies", "=", "Internal", "\\", "Cookies", "::", "getList", "(", "Internal", "\\", "Cookies", "::", "TYPE_SERVER", ")", ";", "$", "cookieKey", "=", "'_s'", ";", "$", "key", "=", "isset", "(", "$", "cookies", "[", "$", "cookieKey", "]", ")", "?", "(", "string", ")", "$", "cookies", "[", "$", "cookieKey", "]", ":", "''", ";", "self", "::", "$", "cache", "[", "$", "cacheKey", "]", "=", "strlen", "(", "(", "string", ")", "$", "key", ")", ">", "70", "?", "$", "key", ":", "null", ";", "}", "return", "self", "::", "$", "cache", "[", "$", "cacheKey", "]", ";", "}" ]
Returns the session key if there is a logged in user @return string|null The session key if there is a logged in user, NULL otherwise
[ "Returns", "the", "session", "key", "if", "there", "is", "a", "logged", "in", "user" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/CurrentUser.php#L42-L52
31,110
bearcms/bearframework-addon
classes/BearCMS/CurrentUser.php
CurrentUser.getID
public function getID(): ?string { $sessionKey = $this->getSessionKey(); if (strlen($sessionKey) === 0) { return null; } $cacheKey = 'id-' . $sessionKey; if (!isset(self::$cache[$cacheKey])) { self::$cache[$cacheKey] = null; $data = Internal\Data::getValue('.temp/bearcms/userkeys/' . md5($sessionKey)); if ($data !== null) { self::$cache[$cacheKey] = $data; } } return self::$cache[$cacheKey]; }
php
public function getID(): ?string { $sessionKey = $this->getSessionKey(); if (strlen($sessionKey) === 0) { return null; } $cacheKey = 'id-' . $sessionKey; if (!isset(self::$cache[$cacheKey])) { self::$cache[$cacheKey] = null; $data = Internal\Data::getValue('.temp/bearcms/userkeys/' . md5($sessionKey)); if ($data !== null) { self::$cache[$cacheKey] = $data; } } return self::$cache[$cacheKey]; }
[ "public", "function", "getID", "(", ")", ":", "?", "string", "{", "$", "sessionKey", "=", "$", "this", "->", "getSessionKey", "(", ")", ";", "if", "(", "strlen", "(", "$", "sessionKey", ")", "===", "0", ")", "{", "return", "null", ";", "}", "$", "cacheKey", "=", "'id-'", ".", "$", "sessionKey", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "cache", "[", "$", "cacheKey", "]", ")", ")", "{", "self", "::", "$", "cache", "[", "$", "cacheKey", "]", "=", "null", ";", "$", "data", "=", "Internal", "\\", "Data", "::", "getValue", "(", "'.temp/bearcms/userkeys/'", ".", "md5", "(", "$", "sessionKey", ")", ")", ";", "if", "(", "$", "data", "!==", "null", ")", "{", "self", "::", "$", "cache", "[", "$", "cacheKey", "]", "=", "$", "data", ";", "}", "}", "return", "self", "::", "$", "cache", "[", "$", "cacheKey", "]", ";", "}" ]
Returns the current logged in user ID @return string|null ID of the current logged in user or null
[ "Returns", "the", "current", "logged", "in", "user", "ID" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/CurrentUser.php#L59-L74
31,111
bearcms/bearframework-addon
classes/BearCMS/CurrentUser.php
CurrentUser.getPermissions
public function getPermissions(): array { $userID = $this->getID(); if ($userID === null) { return []; } $data = Internal\Data::getValue('bearcms/users/user/' . md5($userID) . '.json'); if ($data !== null) { $user = json_decode($data, true); return isset($user['permissions']) ? $user['permissions'] : []; } return []; }
php
public function getPermissions(): array { $userID = $this->getID(); if ($userID === null) { return []; } $data = Internal\Data::getValue('bearcms/users/user/' . md5($userID) . '.json'); if ($data !== null) { $user = json_decode($data, true); return isset($user['permissions']) ? $user['permissions'] : []; } return []; }
[ "public", "function", "getPermissions", "(", ")", ":", "array", "{", "$", "userID", "=", "$", "this", "->", "getID", "(", ")", ";", "if", "(", "$", "userID", "===", "null", ")", "{", "return", "[", "]", ";", "}", "$", "data", "=", "Internal", "\\", "Data", "::", "getValue", "(", "'bearcms/users/user/'", ".", "md5", "(", "$", "userID", ")", ".", "'.json'", ")", ";", "if", "(", "$", "data", "!==", "null", ")", "{", "$", "user", "=", "json_decode", "(", "$", "data", ",", "true", ")", ";", "return", "isset", "(", "$", "user", "[", "'permissions'", "]", ")", "?", "$", "user", "[", "'permissions'", "]", ":", "[", "]", ";", "}", "return", "[", "]", ";", "}" ]
Returns the current logged in user permissions @return array Array containing the permission of the current logged in user
[ "Returns", "the", "current", "logged", "in", "user", "permissions" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/CurrentUser.php#L81-L93
31,112
bearcms/bearframework-addon
classes/BearCMS/CurrentUser.php
CurrentUser.hasPermission
public function hasPermission(string $name): bool { $permissions = $this->getPermissions(); if (array_search('all', $permissions) !== false) { return true; } return array_search($name, $permissions) !== false; }
php
public function hasPermission(string $name): bool { $permissions = $this->getPermissions(); if (array_search('all', $permissions) !== false) { return true; } return array_search($name, $permissions) !== false; }
[ "public", "function", "hasPermission", "(", "string", "$", "name", ")", ":", "bool", "{", "$", "permissions", "=", "$", "this", "->", "getPermissions", "(", ")", ";", "if", "(", "array_search", "(", "'all'", ",", "$", "permissions", ")", "!==", "false", ")", "{", "return", "true", ";", "}", "return", "array_search", "(", "$", "name", ",", "$", "permissions", ")", "!==", "false", ";", "}" ]
Checks whether the current logged in user has the specified permission @param string $name The name of the permission @return boolean TRUE if the current logged in user has the permission specified, FALSE otherwise @throws \InvalidArgumentException
[ "Checks", "whether", "the", "current", "logged", "in", "user", "has", "the", "specified", "permission" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/CurrentUser.php#L102-L109
31,113
bearcms/bearframework-addon
classes/BearCMS/CurrentUser.php
CurrentUser.login
public function login(string $userID): bool { $data = Internal\Server::call('login', ['userID' => $userID], true); if (isset($data['result'])) { return $data['result'] === 'ok'; } return false; }
php
public function login(string $userID): bool { $data = Internal\Server::call('login', ['userID' => $userID], true); if (isset($data['result'])) { return $data['result'] === 'ok'; } return false; }
[ "public", "function", "login", "(", "string", "$", "userID", ")", ":", "bool", "{", "$", "data", "=", "Internal", "\\", "Server", "::", "call", "(", "'login'", ",", "[", "'userID'", "=>", "$", "userID", "]", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'result'", "]", ")", ")", "{", "return", "$", "data", "[", "'result'", "]", "===", "'ok'", ";", "}", "return", "false", ";", "}" ]
Login a user without email and password validation. This methods must be enabled on the CMS server. @param string $userID @return bool Returns TRUE if the user is logged in successfully, FALSE otherwise.
[ "Login", "a", "user", "without", "email", "and", "password", "validation", ".", "This", "methods", "must", "be", "enabled", "on", "the", "CMS", "server", "." ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/CurrentUser.php#L117-L124
31,114
bearcms/bearframework-addon
classes/BearCMS/CurrentUser.php
CurrentUser.logout
public function logout(): void { Internal\Cookies::setList(Internal\Cookies::TYPE_SERVER, [ ['name' => '_s', 'value' => 'deleted', 'expire' => 0], ['name' => '_a', 'value' => 'deleted', 'expire' => 0] ]); self::$cache = []; }
php
public function logout(): void { Internal\Cookies::setList(Internal\Cookies::TYPE_SERVER, [ ['name' => '_s', 'value' => 'deleted', 'expire' => 0], ['name' => '_a', 'value' => 'deleted', 'expire' => 0] ]); self::$cache = []; }
[ "public", "function", "logout", "(", ")", ":", "void", "{", "Internal", "\\", "Cookies", "::", "setList", "(", "Internal", "\\", "Cookies", "::", "TYPE_SERVER", ",", "[", "[", "'name'", "=>", "'_s'", ",", "'value'", "=>", "'deleted'", ",", "'expire'", "=>", "0", "]", ",", "[", "'name'", "=>", "'_a'", ",", "'value'", "=>", "'deleted'", ",", "'expire'", "=>", "0", "]", "]", ")", ";", "self", "::", "$", "cache", "=", "[", "]", ";", "}" ]
Logout the current user. @param string $userID @throws \InvalidArgumentException
[ "Logout", "the", "current", "user", "." ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/CurrentUser.php#L132-L139
31,115
pulsarvp/vps-tools
src/modules/user/widgets/RbacWidget.php
RbacWidget.isFixed
private function isFixed ($name) { $row = ( new Query )->from(Yii::$app->authManager->itemTable) ->select('fixed') ->where([ 'name' => $name ]) ->one(Yii::$app->db); return $row[ 'fixed' ]; }
php
private function isFixed ($name) { $row = ( new Query )->from(Yii::$app->authManager->itemTable) ->select('fixed') ->where([ 'name' => $name ]) ->one(Yii::$app->db); return $row[ 'fixed' ]; }
[ "private", "function", "isFixed", "(", "$", "name", ")", "{", "$", "row", "=", "(", "new", "Query", ")", "->", "from", "(", "Yii", "::", "$", "app", "->", "authManager", "->", "itemTable", ")", "->", "select", "(", "'fixed'", ")", "->", "where", "(", "[", "'name'", "=>", "$", "name", "]", ")", "->", "one", "(", "Yii", "::", "$", "app", "->", "db", ")", ";", "return", "$", "row", "[", "'fixed'", "]", ";", "}" ]
Is fixed role @param $name @return bool
[ "Is", "fixed", "role" ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/user/widgets/RbacWidget.php#L129-L137
31,116
pulsarvp/vps-tools
src/modules/user/widgets/RbacWidget.php
RbacWidget.addRole
private function addRole () { $roleForm = new RoleForm(); if (Yii::$app->request->getIsPost()) { $roleForm->setAttributes(Yii::$app->request->post('RoleForm')); if ($roleForm->method == 'rbac-add') $roleForm->setScenario(RoleForm::SCENARIO_ADD); if ($roleForm->validate()) { $this->saveRole($roleForm); $url = Yii::$app->request->referrer . '#roles'; Yii::$app->response->redirect($url); } } return $roleForm; }
php
private function addRole () { $roleForm = new RoleForm(); if (Yii::$app->request->getIsPost()) { $roleForm->setAttributes(Yii::$app->request->post('RoleForm')); if ($roleForm->method == 'rbac-add') $roleForm->setScenario(RoleForm::SCENARIO_ADD); if ($roleForm->validate()) { $this->saveRole($roleForm); $url = Yii::$app->request->referrer . '#roles'; Yii::$app->response->redirect($url); } } return $roleForm; }
[ "private", "function", "addRole", "(", ")", "{", "$", "roleForm", "=", "new", "RoleForm", "(", ")", ";", "if", "(", "Yii", "::", "$", "app", "->", "request", "->", "getIsPost", "(", ")", ")", "{", "$", "roleForm", "->", "setAttributes", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", "'RoleForm'", ")", ")", ";", "if", "(", "$", "roleForm", "->", "method", "==", "'rbac-add'", ")", "$", "roleForm", "->", "setScenario", "(", "RoleForm", "::", "SCENARIO_ADD", ")", ";", "if", "(", "$", "roleForm", "->", "validate", "(", ")", ")", "{", "$", "this", "->", "saveRole", "(", "$", "roleForm", ")", ";", "$", "url", "=", "Yii", "::", "$", "app", "->", "request", "->", "referrer", ".", "'#roles'", ";", "Yii", "::", "$", "app", "->", "response", "->", "redirect", "(", "$", "url", ")", ";", "}", "}", "return", "$", "roleForm", ";", "}" ]
Add new role
[ "Add", "new", "role" ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/user/widgets/RbacWidget.php#L142-L160
31,117
bearcms/bearframework-addon
classes/BearCMS/Internal/Data2/BlogCategories.php
BlogCategories.get
public function get(string $id): ?\BearCMS\Internal\Data2\BlogCategory { $data = Internal\Data::getValue('bearcms/blog/categories/category/' . md5($id) . '.json'); if ($data !== null) { return $this->makeBlogCategoryFromRawData($data); } return null; }
php
public function get(string $id): ?\BearCMS\Internal\Data2\BlogCategory { $data = Internal\Data::getValue('bearcms/blog/categories/category/' . md5($id) . '.json'); if ($data !== null) { return $this->makeBlogCategoryFromRawData($data); } return null; }
[ "public", "function", "get", "(", "string", "$", "id", ")", ":", "?", "\\", "BearCMS", "\\", "Internal", "\\", "Data2", "\\", "BlogCategory", "{", "$", "data", "=", "Internal", "\\", "Data", "::", "getValue", "(", "'bearcms/blog/categories/category/'", ".", "md5", "(", "$", "id", ")", ".", "'.json'", ")", ";", "if", "(", "$", "data", "!==", "null", ")", "{", "return", "$", "this", "->", "makeBlogCategoryFromRawData", "(", "$", "data", ")", ";", "}", "return", "null", ";", "}" ]
Retrieves information about the page specified @param string $id The page ID @return \IvoPetkov\DataObject|null The page data or null if page not found @throws \InvalidArgumentException
[ "Retrieves", "information", "about", "the", "page", "specified" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/BlogCategories.php#L43-L50
31,118
bearcms/bearframework-addon
classes/BearCMS/Internal/Data2/BlogCategories.php
BlogCategories.getList
public function getList(): \IvoPetkov\DataList { $cacheKey = 'blog_categories_list'; if (!isset(Internal\Data::$cache[$cacheKey])) { $list = Internal\Data::getList('bearcms/blog/categories/category/'); array_walk($list, function(&$value) { $value = $this->makeBlogCategoryFromRawData($value); }); $structureData = Internal\Data::getValue('bearcms/blog/categories/structure.json'); $structureData = $structureData === null ? [] : json_decode($structureData, true); $flattenStructureData = []; foreach ($structureData as $itemData) { $flattenStructureData[] = $itemData['id']; } $flattenStructureData = array_flip($flattenStructureData); usort($list, function($object1, $object2) use ($flattenStructureData) { return $flattenStructureData[$object1->id] - $flattenStructureData[$object2->id]; }); unset($flattenStructureData); Internal\Data::$cache[$cacheKey] = $list; unset($list); } return new \IvoPetkov\DataList(Internal\Data::$cache[$cacheKey]); }
php
public function getList(): \IvoPetkov\DataList { $cacheKey = 'blog_categories_list'; if (!isset(Internal\Data::$cache[$cacheKey])) { $list = Internal\Data::getList('bearcms/blog/categories/category/'); array_walk($list, function(&$value) { $value = $this->makeBlogCategoryFromRawData($value); }); $structureData = Internal\Data::getValue('bearcms/blog/categories/structure.json'); $structureData = $structureData === null ? [] : json_decode($structureData, true); $flattenStructureData = []; foreach ($structureData as $itemData) { $flattenStructureData[] = $itemData['id']; } $flattenStructureData = array_flip($flattenStructureData); usort($list, function($object1, $object2) use ($flattenStructureData) { return $flattenStructureData[$object1->id] - $flattenStructureData[$object2->id]; }); unset($flattenStructureData); Internal\Data::$cache[$cacheKey] = $list; unset($list); } return new \IvoPetkov\DataList(Internal\Data::$cache[$cacheKey]); }
[ "public", "function", "getList", "(", ")", ":", "\\", "IvoPetkov", "\\", "DataList", "{", "$", "cacheKey", "=", "'blog_categories_list'", ";", "if", "(", "!", "isset", "(", "Internal", "\\", "Data", "::", "$", "cache", "[", "$", "cacheKey", "]", ")", ")", "{", "$", "list", "=", "Internal", "\\", "Data", "::", "getList", "(", "'bearcms/blog/categories/category/'", ")", ";", "array_walk", "(", "$", "list", ",", "function", "(", "&", "$", "value", ")", "{", "$", "value", "=", "$", "this", "->", "makeBlogCategoryFromRawData", "(", "$", "value", ")", ";", "}", ")", ";", "$", "structureData", "=", "Internal", "\\", "Data", "::", "getValue", "(", "'bearcms/blog/categories/structure.json'", ")", ";", "$", "structureData", "=", "$", "structureData", "===", "null", "?", "[", "]", ":", "json_decode", "(", "$", "structureData", ",", "true", ")", ";", "$", "flattenStructureData", "=", "[", "]", ";", "foreach", "(", "$", "structureData", "as", "$", "itemData", ")", "{", "$", "flattenStructureData", "[", "]", "=", "$", "itemData", "[", "'id'", "]", ";", "}", "$", "flattenStructureData", "=", "array_flip", "(", "$", "flattenStructureData", ")", ";", "usort", "(", "$", "list", ",", "function", "(", "$", "object1", ",", "$", "object2", ")", "use", "(", "$", "flattenStructureData", ")", "{", "return", "$", "flattenStructureData", "[", "$", "object1", "->", "id", "]", "-", "$", "flattenStructureData", "[", "$", "object2", "->", "id", "]", ";", "}", ")", ";", "unset", "(", "$", "flattenStructureData", ")", ";", "Internal", "\\", "Data", "::", "$", "cache", "[", "$", "cacheKey", "]", "=", "$", "list", ";", "unset", "(", "$", "list", ")", ";", "}", "return", "new", "\\", "IvoPetkov", "\\", "DataList", "(", "Internal", "\\", "Data", "::", "$", "cache", "[", "$", "cacheKey", "]", ")", ";", "}" ]
Retrieves a list of all pages @return \IvoPetkov\DataList|\BearCMS\Internal\Data2\BlogCategory[] List containing all pages data
[ "Retrieves", "a", "list", "of", "all", "pages" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/BlogCategories.php#L57-L81
31,119
pulsarvp/vps-tools
src/modules/setting/components/SettingManager.php
SettingManager.get
public function get ($name, $default = null) { foreach ($this->_data as $d) { if ($d->name === $name) return $d->value; } return $default; }
php
public function get ($name, $default = null) { foreach ($this->_data as $d) { if ($d->name === $name) return $d->value; } return $default; }
[ "public", "function", "get", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "foreach", "(", "$", "this", "->", "_data", "as", "$", "d", ")", "{", "if", "(", "$", "d", "->", "name", "===", "$", "name", ")", "return", "$", "d", "->", "value", ";", "}", "return", "$", "default", ";", "}" ]
Gets specific setting by its name. Return default value if not found. @param string $name @param mixed $default @return null
[ "Gets", "specific", "setting", "by", "its", "name", ".", "Return", "default", "value", "if", "not", "found", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/components/SettingManager.php#L45-L54
31,120
wikimedia/slimapp
src/Form.php
Form.expect
public function expect( $name, $filter, $options = null ) { $options = ( is_array( $options ) ) ? $options : []; $flags = null; $required = false; $validate = null; if ( isset( $options['flags'] ) ) { $flags = $options['flags']; unset( $options['flags'] ); } if ( isset( $options['required'] ) ) { $required = $options['required']; unset( $options['required'] ); } if ( isset( $options['validate'] ) ) { $validate = $options['validate']; unset( $options['validate'] ); } if ( $filter === \FILTER_CALLBACK ) { if ( !isset( $options['callback'] ) || !is_callable( $options['callback'] ) ) { throw new \InvalidArgumentException( 'FILTER_CALLBACK requires a valid callback.' ); } $options = $options['callback']; } $this->params[$name] = [ 'filter' => $filter, 'flags' => $flags, 'options' => $options, 'required' => $required, 'validate' => $validate, ]; return $this; }
php
public function expect( $name, $filter, $options = null ) { $options = ( is_array( $options ) ) ? $options : []; $flags = null; $required = false; $validate = null; if ( isset( $options['flags'] ) ) { $flags = $options['flags']; unset( $options['flags'] ); } if ( isset( $options['required'] ) ) { $required = $options['required']; unset( $options['required'] ); } if ( isset( $options['validate'] ) ) { $validate = $options['validate']; unset( $options['validate'] ); } if ( $filter === \FILTER_CALLBACK ) { if ( !isset( $options['callback'] ) || !is_callable( $options['callback'] ) ) { throw new \InvalidArgumentException( 'FILTER_CALLBACK requires a valid callback.' ); } $options = $options['callback']; } $this->params[$name] = [ 'filter' => $filter, 'flags' => $flags, 'options' => $options, 'required' => $required, 'validate' => $validate, ]; return $this; }
[ "public", "function", "expect", "(", "$", "name", ",", "$", "filter", ",", "$", "options", "=", "null", ")", "{", "$", "options", "=", "(", "is_array", "(", "$", "options", ")", ")", "?", "$", "options", ":", "[", "]", ";", "$", "flags", "=", "null", ";", "$", "required", "=", "false", ";", "$", "validate", "=", "null", ";", "if", "(", "isset", "(", "$", "options", "[", "'flags'", "]", ")", ")", "{", "$", "flags", "=", "$", "options", "[", "'flags'", "]", ";", "unset", "(", "$", "options", "[", "'flags'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'required'", "]", ")", ")", "{", "$", "required", "=", "$", "options", "[", "'required'", "]", ";", "unset", "(", "$", "options", "[", "'required'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'validate'", "]", ")", ")", "{", "$", "validate", "=", "$", "options", "[", "'validate'", "]", ";", "unset", "(", "$", "options", "[", "'validate'", "]", ")", ";", "}", "if", "(", "$", "filter", "===", "\\", "FILTER_CALLBACK", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'callback'", "]", ")", "||", "!", "is_callable", "(", "$", "options", "[", "'callback'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'FILTER_CALLBACK requires a valid callback.'", ")", ";", "}", "$", "options", "=", "$", "options", "[", "'callback'", "]", ";", "}", "$", "this", "->", "params", "[", "$", "name", "]", "=", "[", "'filter'", "=>", "$", "filter", ",", "'flags'", "=>", "$", "flags", ",", "'options'", "=>", "$", "options", ",", "'required'", "=>", "$", "required", ",", "'validate'", "=>", "$", "validate", ",", "]", ";", "return", "$", "this", ";", "}" ]
Add an input expectation. Allowed options: - default: Default value for missing input - flags: Flags to pass to filter_var_array - required: Is this input required? - validate: Callable to perform additional validation - callback: Callable for \FILTER_CALLBACK validation @param string $name Parameter to expect @param int $filter Validation filter(s) to apply @param array $options Validation options @return Form Self, for message chaining
[ "Add", "an", "input", "expectation", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Form.php#L84-L125
31,121
wikimedia/slimapp
src/Form.php
Form.expectDateTime
public function expectDateTime( $name, $format, $options = null ) { $options = ( is_array( $options ) ) ? $options : []; $options['callback'] = function ( $value ) use ( $format ) { try { $date = \DateTime::createFromFormat( $format, $value ); $formatErrors = \DateTime::getLastErrors(); if ( $formatErrors['error_count'] == 0 && $formatErrors['warning_count'] == 0 ) { return $date; } } catch ( \Exception $ignored ) { // no-op } return false; }; return $this->expect( $name, \FILTER_CALLBACK, $options ); }
php
public function expectDateTime( $name, $format, $options = null ) { $options = ( is_array( $options ) ) ? $options : []; $options['callback'] = function ( $value ) use ( $format ) { try { $date = \DateTime::createFromFormat( $format, $value ); $formatErrors = \DateTime::getLastErrors(); if ( $formatErrors['error_count'] == 0 && $formatErrors['warning_count'] == 0 ) { return $date; } } catch ( \Exception $ignored ) { // no-op } return false; }; return $this->expect( $name, \FILTER_CALLBACK, $options ); }
[ "public", "function", "expectDateTime", "(", "$", "name", ",", "$", "format", ",", "$", "options", "=", "null", ")", "{", "$", "options", "=", "(", "is_array", "(", "$", "options", ")", ")", "?", "$", "options", ":", "[", "]", ";", "$", "options", "[", "'callback'", "]", "=", "function", "(", "$", "value", ")", "use", "(", "$", "format", ")", "{", "try", "{", "$", "date", "=", "\\", "DateTime", "::", "createFromFormat", "(", "$", "format", ",", "$", "value", ")", ";", "$", "formatErrors", "=", "\\", "DateTime", "::", "getLastErrors", "(", ")", ";", "if", "(", "$", "formatErrors", "[", "'error_count'", "]", "==", "0", "&&", "$", "formatErrors", "[", "'warning_count'", "]", "==", "0", ")", "{", "return", "$", "date", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "ignored", ")", "{", "// no-op", "}", "return", "false", ";", "}", ";", "return", "$", "this", "->", "expect", "(", "$", "name", ",", "\\", "FILTER_CALLBACK", ",", "$", "options", ")", ";", "}" ]
Add an input expectation for a DateTime object. @param string $name Parameter to expect @param string $format Expected date/time format @param array $options Additional options @return Form Self, for message chaining @see DateTime::createFromFormat
[ "Add", "an", "input", "expectation", "for", "a", "DateTime", "object", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Form.php#L561-L578
31,122
wikimedia/slimapp
src/Form.php
Form.validate
public function validate( $vars = null ) { $vars = $vars ?: $_POST; $this->values = []; $this->errors = []; $arrayInvalids = []; $cleaned = filter_var_array( $vars, $this->params ); foreach ( $this->params as $name => $opt ) { $clean = isset( $vars[$name] ) ? $cleaned[$name] : null; if ( $clean === false && $opt['filter'] !== \FILTER_VALIDATE_BOOLEAN ) { $this->values[$name] = null; } elseif ( is_array( $clean ) && ( $opt['flags'] & \FILTER_REQUIRE_ARRAY ) && $opt['filter'] !== \FILTER_VALIDATE_BOOLEAN ) { // Strip invalid value markers from input array $this->values[$name] = []; foreach ( $clean as $key => $value ) { if ( $opt['filter'] !== \FILTER_VALIDATE_BOOLEAN && $value !== false ) { $this->values[$name][$key] = $value; } elseif ( $opt['filter'] === \FILTER_VALIDATE_BOOLEAN && $value !== null ) { $this->values[$name][$key] = $value; } else { // Keep track of invalid keys in case input was // required if ( !isset( $arrayInvalids[$name] ) ) { $arrayInvalids[$name] = []; } $arrayInvalids[$name][] = "{$name}[{$key}]"; } } } else { $this->values[$name] = $clean; } if ( $opt['required'] && $this->values[$name] === null ) { $this->errors[] = $name; } elseif ( $opt['required'] && isset( $arrayInvalids[$name] ) ) { $this->errors = array_merge( $this->errors, $arrayInvalids[$name] ); } elseif ( is_callable( $opt['validate'] ) && call_user_func( $opt['validate'], $this->values[$name] ) === false ) { $this->errors[] = $name; $this->values[$name] = null; } } $this->customValidationHook(); return count( $this->errors ) === 0; }
php
public function validate( $vars = null ) { $vars = $vars ?: $_POST; $this->values = []; $this->errors = []; $arrayInvalids = []; $cleaned = filter_var_array( $vars, $this->params ); foreach ( $this->params as $name => $opt ) { $clean = isset( $vars[$name] ) ? $cleaned[$name] : null; if ( $clean === false && $opt['filter'] !== \FILTER_VALIDATE_BOOLEAN ) { $this->values[$name] = null; } elseif ( is_array( $clean ) && ( $opt['flags'] & \FILTER_REQUIRE_ARRAY ) && $opt['filter'] !== \FILTER_VALIDATE_BOOLEAN ) { // Strip invalid value markers from input array $this->values[$name] = []; foreach ( $clean as $key => $value ) { if ( $opt['filter'] !== \FILTER_VALIDATE_BOOLEAN && $value !== false ) { $this->values[$name][$key] = $value; } elseif ( $opt['filter'] === \FILTER_VALIDATE_BOOLEAN && $value !== null ) { $this->values[$name][$key] = $value; } else { // Keep track of invalid keys in case input was // required if ( !isset( $arrayInvalids[$name] ) ) { $arrayInvalids[$name] = []; } $arrayInvalids[$name][] = "{$name}[{$key}]"; } } } else { $this->values[$name] = $clean; } if ( $opt['required'] && $this->values[$name] === null ) { $this->errors[] = $name; } elseif ( $opt['required'] && isset( $arrayInvalids[$name] ) ) { $this->errors = array_merge( $this->errors, $arrayInvalids[$name] ); } elseif ( is_callable( $opt['validate'] ) && call_user_func( $opt['validate'], $this->values[$name] ) === false ) { $this->errors[] = $name; $this->values[$name] = null; } } $this->customValidationHook(); return count( $this->errors ) === 0; }
[ "public", "function", "validate", "(", "$", "vars", "=", "null", ")", "{", "$", "vars", "=", "$", "vars", "?", ":", "$", "_POST", ";", "$", "this", "->", "values", "=", "[", "]", ";", "$", "this", "->", "errors", "=", "[", "]", ";", "$", "arrayInvalids", "=", "[", "]", ";", "$", "cleaned", "=", "filter_var_array", "(", "$", "vars", ",", "$", "this", "->", "params", ")", ";", "foreach", "(", "$", "this", "->", "params", "as", "$", "name", "=>", "$", "opt", ")", "{", "$", "clean", "=", "isset", "(", "$", "vars", "[", "$", "name", "]", ")", "?", "$", "cleaned", "[", "$", "name", "]", ":", "null", ";", "if", "(", "$", "clean", "===", "false", "&&", "$", "opt", "[", "'filter'", "]", "!==", "\\", "FILTER_VALIDATE_BOOLEAN", ")", "{", "$", "this", "->", "values", "[", "$", "name", "]", "=", "null", ";", "}", "elseif", "(", "is_array", "(", "$", "clean", ")", "&&", "(", "$", "opt", "[", "'flags'", "]", "&", "\\", "FILTER_REQUIRE_ARRAY", ")", "&&", "$", "opt", "[", "'filter'", "]", "!==", "\\", "FILTER_VALIDATE_BOOLEAN", ")", "{", "// Strip invalid value markers from input array", "$", "this", "->", "values", "[", "$", "name", "]", "=", "[", "]", ";", "foreach", "(", "$", "clean", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "opt", "[", "'filter'", "]", "!==", "\\", "FILTER_VALIDATE_BOOLEAN", "&&", "$", "value", "!==", "false", ")", "{", "$", "this", "->", "values", "[", "$", "name", "]", "[", "$", "key", "]", "=", "$", "value", ";", "}", "elseif", "(", "$", "opt", "[", "'filter'", "]", "===", "\\", "FILTER_VALIDATE_BOOLEAN", "&&", "$", "value", "!==", "null", ")", "{", "$", "this", "->", "values", "[", "$", "name", "]", "[", "$", "key", "]", "=", "$", "value", ";", "}", "else", "{", "// Keep track of invalid keys in case input was", "// required", "if", "(", "!", "isset", "(", "$", "arrayInvalids", "[", "$", "name", "]", ")", ")", "{", "$", "arrayInvalids", "[", "$", "name", "]", "=", "[", "]", ";", "}", "$", "arrayInvalids", "[", "$", "name", "]", "[", "]", "=", "\"{$name}[{$key}]\"", ";", "}", "}", "}", "else", "{", "$", "this", "->", "values", "[", "$", "name", "]", "=", "$", "clean", ";", "}", "if", "(", "$", "opt", "[", "'required'", "]", "&&", "$", "this", "->", "values", "[", "$", "name", "]", "===", "null", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "$", "name", ";", "}", "elseif", "(", "$", "opt", "[", "'required'", "]", "&&", "isset", "(", "$", "arrayInvalids", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "errors", "=", "array_merge", "(", "$", "this", "->", "errors", ",", "$", "arrayInvalids", "[", "$", "name", "]", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "opt", "[", "'validate'", "]", ")", "&&", "call_user_func", "(", "$", "opt", "[", "'validate'", "]", ",", "$", "this", "->", "values", "[", "$", "name", "]", ")", "===", "false", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "$", "name", ";", "$", "this", "->", "values", "[", "$", "name", "]", "=", "null", ";", "}", "}", "$", "this", "->", "customValidationHook", "(", ")", ";", "return", "count", "(", "$", "this", "->", "errors", ")", "===", "0", ";", "}" ]
Validate the provided input data using this form's expectations. @param array $vars Input to validate (default $_POST) @return bool True if input is valid, false otherwise
[ "Validate", "the", "provided", "input", "data", "using", "this", "form", "s", "expectations", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Form.php#L598-L664
31,123
cedx/yii2-mustache
lib/Logger.php
Logger.log
function log($level, $message, array $context = []): void { if (!isset(static::$levels[$level])) { $values = implode(', ', (new \ReflectionClass(LogLevel::class))->getConstants()); throw new InvalidArgumentException("Invalid enumerable value '$level'. Please make sure it is among ($values)."); } \Yii::getLogger()->log($message, static::$levels[$level], __METHOD__); }
php
function log($level, $message, array $context = []): void { if (!isset(static::$levels[$level])) { $values = implode(', ', (new \ReflectionClass(LogLevel::class))->getConstants()); throw new InvalidArgumentException("Invalid enumerable value '$level'. Please make sure it is among ($values)."); } \Yii::getLogger()->log($message, static::$levels[$level], __METHOD__); }
[ "function", "log", "(", "$", "level", ",", "$", "message", ",", "array", "$", "context", "=", "[", "]", ")", ":", "void", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "levels", "[", "$", "level", "]", ")", ")", "{", "$", "values", "=", "implode", "(", "', '", ",", "(", "new", "\\", "ReflectionClass", "(", "LogLevel", "::", "class", ")", ")", "->", "getConstants", "(", ")", ")", ";", "throw", "new", "InvalidArgumentException", "(", "\"Invalid enumerable value '$level'. Please make sure it is among ($values).\"", ")", ";", "}", "\\", "Yii", "::", "getLogger", "(", ")", "->", "log", "(", "$", "message", ",", "static", "::", "$", "levels", "[", "$", "level", "]", ",", "__METHOD__", ")", ";", "}" ]
Logs a message. @param int $level The logging level. @param string $message The message to be logged. @param array $context The log context. @throws InvalidArgumentException The specified logging level is unknown.
[ "Logs", "a", "message", "." ]
20c961e65e74a0bacbe992dd7fdb28319f58a919
https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/Logger.php#L31-L38
31,124
EmchBerger/cube-custom-fields-bundle
src/CustomFieldsEntityTrait.php
CustomFieldsEntityTrait.setCustomFields
public function setCustomFields(ArrayCollection $customFields) { @trigger_error(__METHOD__.' is deprecated', E_USER_DEPRECATED); $this->customFields = $customFields; return $this; }
php
public function setCustomFields(ArrayCollection $customFields) { @trigger_error(__METHOD__.' is deprecated', E_USER_DEPRECATED); $this->customFields = $customFields; return $this; }
[ "public", "function", "setCustomFields", "(", "ArrayCollection", "$", "customFields", ")", "{", "@", "trigger_error", "(", "__METHOD__", ".", "' is deprecated'", ",", "E_USER_DEPRECATED", ")", ";", "$", "this", "->", "customFields", "=", "$", "customFields", ";", "return", "$", "this", ";", "}" ]
Set custom fields entities. @deprecated since version 1.3.5, is probably unused and dangerous @param ArrayCollection $customFields @return $this
[ "Set", "custom", "fields", "entities", "." ]
7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414
https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/CustomFieldsEntityTrait.php#L93-L100
31,125
thejacer87/php-canadapost-api
src/PostOffice.php
PostOffice.getNearestPostOffice
public function getNearestPostOffice( $postal_code, $d2po = false, $max_addresses = 10, array $options = [] ) { $query_params = "d2po={$d2po}&postalCode={$postal_code}&maximum={$max_addresses}"; $response = $this->get( "rs/postoffice?{$query_params}", ['Accept' => 'application/vnd.cpc.postoffice+xml'], $options ); return $response; }
php
public function getNearestPostOffice( $postal_code, $d2po = false, $max_addresses = 10, array $options = [] ) { $query_params = "d2po={$d2po}&postalCode={$postal_code}&maximum={$max_addresses}"; $response = $this->get( "rs/postoffice?{$query_params}", ['Accept' => 'application/vnd.cpc.postoffice+xml'], $options ); return $response; }
[ "public", "function", "getNearestPostOffice", "(", "$", "postal_code", ",", "$", "d2po", "=", "false", ",", "$", "max_addresses", "=", "10", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "query_params", "=", "\"d2po={$d2po}&postalCode={$postal_code}&maximum={$max_addresses}\"", ";", "$", "response", "=", "$", "this", "->", "get", "(", "\"rs/postoffice?{$query_params}\"", ",", "[", "'Accept'", "=>", "'application/vnd.cpc.postoffice+xml'", "]", ",", "$", "options", ")", ";", "return", "$", "response", ";", "}" ]
Get information on Post Offices nearest to a given postal code. @param string $postal_code The postal code. @param bool $d2po True indicates that you want a list of Post Offices that accept the "Deliver to Post Office" delivery of parcels. Use this when you want the parcel to be delivered directly to a Post Office rather than to the recipient’s address. @param int $max_addresses The maximum number of Post Offices to return with the response. The maximum allowed is 50. In remote locations, fewer Post Offices than requested may be returned. @param array $options The options array. @return \DOMDocument|\Psr\Http\Message\StreamInterface @throws \GuzzleHttp\Exception\GuzzleException
[ "Get", "information", "on", "Post", "Offices", "nearest", "to", "a", "given", "postal", "code", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/PostOffice.php#L33-L47
31,126
thejacer87/php-canadapost-api
src/PostOffice.php
PostOffice.getNearestPostOfficeByAddress
public function getNearestPostOfficeByAddress( $province = '', $city = '', $street_name = '', $d2po = false, $max_addresses = 10, array $options = [] ) { $query_params = "d2po={$d2po}&province={$province}&city={$city}&streetName={$street_name}&maximum={$max_addresses}"; $response = $this->get( "rs/postoffice?{$query_params}", ['Accept' => 'application/vnd.cpc.postoffice+xml'], $options ); return $response; }
php
public function getNearestPostOfficeByAddress( $province = '', $city = '', $street_name = '', $d2po = false, $max_addresses = 10, array $options = [] ) { $query_params = "d2po={$d2po}&province={$province}&city={$city}&streetName={$street_name}&maximum={$max_addresses}"; $response = $this->get( "rs/postoffice?{$query_params}", ['Accept' => 'application/vnd.cpc.postoffice+xml'], $options ); return $response; }
[ "public", "function", "getNearestPostOfficeByAddress", "(", "$", "province", "=", "''", ",", "$", "city", "=", "''", ",", "$", "street_name", "=", "''", ",", "$", "d2po", "=", "false", ",", "$", "max_addresses", "=", "10", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "query_params", "=", "\"d2po={$d2po}&province={$province}&city={$city}&streetName={$street_name}&maximum={$max_addresses}\"", ";", "$", "response", "=", "$", "this", "->", "get", "(", "\"rs/postoffice?{$query_params}\"", ",", "[", "'Accept'", "=>", "'application/vnd.cpc.postoffice+xml'", "]", ",", "$", "options", ")", ";", "return", "$", "response", ";", "}" ]
Get information on Post Offices nearest to a given location. @param string $province The province. @param string $city The city. @param string $street_name Street name onl (ie. without the house or apartment number). Street name can be a multi-part name with embedded spaces. If City and Province are specified, provision of this parameter will refine the list to a more specific location in the city indicated. For larger municipalities a list might not be returned if the street name is not provided in addition to the City and Province attributes. @param bool $d2po True indicates that you want a list of Post Offices that accept the "Deliver to Post Office" delivery of parcels. Use this when you want the parcel to be delivered directly to a Post Office rather than to the recipient’s address. @param int $max_addresses The maximum number of Post Offices to return with the response. The maximum allowed is 50. In remote locations, fewer Post Offices than requested may be returned. @param array $options The options array. @return \DOMDocument|\Psr\Http\Message\StreamInterface @throws \GuzzleHttp\Exception\GuzzleException
[ "Get", "information", "on", "Post", "Offices", "nearest", "to", "a", "given", "location", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/PostOffice.php#L78-L94
31,127
thejacer87/php-canadapost-api
src/PostOffice.php
PostOffice.getNearestPostOfficeByGeographicalLocation
public function getNearestPostOfficeByGeographicalLocation( $longitude, $latitude, $d2po = false, $max_addresses = 10, array $options = [] ) { $query_params = "d2po={$d2po}&longitude={$longitude}&latitude={$latitude}&maximum={$max_addresses}"; $response = $this->get( "rs/postoffice?{$query_params}", ['Accept' => 'application/vnd.cpc.postoffice+xml'], $options ); return $response; }
php
public function getNearestPostOfficeByGeographicalLocation( $longitude, $latitude, $d2po = false, $max_addresses = 10, array $options = [] ) { $query_params = "d2po={$d2po}&longitude={$longitude}&latitude={$latitude}&maximum={$max_addresses}"; $response = $this->get( "rs/postoffice?{$query_params}", ['Accept' => 'application/vnd.cpc.postoffice+xml'], $options ); return $response; }
[ "public", "function", "getNearestPostOfficeByGeographicalLocation", "(", "$", "longitude", ",", "$", "latitude", ",", "$", "d2po", "=", "false", ",", "$", "max_addresses", "=", "10", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "query_params", "=", "\"d2po={$d2po}&longitude={$longitude}&latitude={$latitude}&maximum={$max_addresses}\"", ";", "$", "response", "=", "$", "this", "->", "get", "(", "\"rs/postoffice?{$query_params}\"", ",", "[", "'Accept'", "=>", "'application/vnd.cpc.postoffice+xml'", "]", ",", "$", "options", ")", ";", "return", "$", "response", ";", "}" ]
Get information on Post Offices nearest to a given geographical location. @param string $longitude The longitude. Format is 10 characters of the form: [-]3.5 ie. up to 3 digits before the decimal and 5 digits after the decimal eg. -101.32354 @param string $latitude The latitude. Format is 10 characters of the form: [-]3.5 ie. up to 3 digits before the decimal and 5 digits after the decimal eg. 55.32354 @param bool $d2po True indicates that you want a list of Post Offices that accept the "Deliver to Post Office" delivery of parcels. Use this when you want the parcel to be delivered directly to a Post Office rather than to the recipient’s address. @param int $max_addresses The maximum number of Post Offices to return with the response. The maximum allowed is 50. In remote locations, fewer Post Offices than requested may be returned. @param array $options The options array. @return \DOMDocument|\Psr\Http\Message\StreamInterface @throws \GuzzleHttp\Exception\GuzzleException
[ "Get", "information", "on", "Post", "Offices", "nearest", "to", "a", "given", "geographical", "location", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/PostOffice.php#L124-L139
31,128
pulsarvp/vps-tools
src/modules/apiapp/models/Apiapp.php
Apiapp.getTokenForName
public static function getTokenForName ($name) { $object = self::findOne([ 'name' => $name ]); if ($object == null) { $object = new App([ 'name' => $name, 'token' => StringHelper::random(16) ]); $object->save(); } return $object->token; }
php
public static function getTokenForName ($name) { $object = self::findOne([ 'name' => $name ]); if ($object == null) { $object = new App([ 'name' => $name, 'token' => StringHelper::random(16) ]); $object->save(); } return $object->token; }
[ "public", "static", "function", "getTokenForName", "(", "$", "name", ")", "{", "$", "object", "=", "self", "::", "findOne", "(", "[", "'name'", "=>", "$", "name", "]", ")", ";", "if", "(", "$", "object", "==", "null", ")", "{", "$", "object", "=", "new", "App", "(", "[", "'name'", "=>", "$", "name", ",", "'token'", "=>", "StringHelper", "::", "random", "(", "16", ")", "]", ")", ";", "$", "object", "->", "save", "(", ")", ";", "}", "return", "$", "object", "->", "token", ";", "}" ]
Finds App token by its name. @param string $name App name. @return string
[ "Finds", "App", "token", "by", "its", "name", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/apiapp/models/Apiapp.php#L41-L54
31,129
bearcms/bearframework-addon
classes/BearCMS/Addons.php
Addons.register
public function register(string $id, callable $callback): self { Internal\Data\Addons::$registrations[$id] = $callback; return $this; }
php
public function register(string $id, callable $callback): self { Internal\Data\Addons::$registrations[$id] = $callback; return $this; }
[ "public", "function", "register", "(", "string", "$", "id", ",", "callable", "$", "callback", ")", ":", "self", "{", "Internal", "\\", "Data", "\\", "Addons", "::", "$", "registrations", "[", "$", "id", "]", "=", "$", "callback", ";", "return", "$", "this", ";", "}" ]
Register a new addon. @param string $id The addon ID. @param callable $callback A function to define addon parameters. @return self Returns a reference to itself.
[ "Register", "a", "new", "addon", "." ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Addons.php#L28-L32
31,130
bearcms/bearframework-addon
classes/BearCMS/Addons.php
Addons.add
public function add(string $id): self { $app = App::get(); if (\BearFramework\Addons::exists($id)) { $app->addons->add($id); if (isset(Internal\Data\Addons::$registrations[$id])) { $addon = new \BearCMS\Addons\Addon($id); call_user_func(Internal\Data\Addons::$registrations[$id], $addon); if (is_callable($addon->initialize)) { call_user_func($addon->initialize); } } } return $this; }
php
public function add(string $id): self { $app = App::get(); if (\BearFramework\Addons::exists($id)) { $app->addons->add($id); if (isset(Internal\Data\Addons::$registrations[$id])) { $addon = new \BearCMS\Addons\Addon($id); call_user_func(Internal\Data\Addons::$registrations[$id], $addon); if (is_callable($addon->initialize)) { call_user_func($addon->initialize); } } } return $this; }
[ "public", "function", "add", "(", "string", "$", "id", ")", ":", "self", "{", "$", "app", "=", "App", "::", "get", "(", ")", ";", "if", "(", "\\", "BearFramework", "\\", "Addons", "::", "exists", "(", "$", "id", ")", ")", "{", "$", "app", "->", "addons", "->", "add", "(", "$", "id", ")", ";", "if", "(", "isset", "(", "Internal", "\\", "Data", "\\", "Addons", "::", "$", "registrations", "[", "$", "id", "]", ")", ")", "{", "$", "addon", "=", "new", "\\", "BearCMS", "\\", "Addons", "\\", "Addon", "(", "$", "id", ")", ";", "call_user_func", "(", "Internal", "\\", "Data", "\\", "Addons", "::", "$", "registrations", "[", "$", "id", "]", ",", "$", "addon", ")", ";", "if", "(", "is_callable", "(", "$", "addon", "->", "initialize", ")", ")", "{", "call_user_func", "(", "$", "addon", "->", "initialize", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Adds an addon. @param string $id @return self
[ "Adds", "an", "addon", "." ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Addons.php#L40-L54
31,131
wikimedia/slimapp
src/Dao/AbstractDao.php
AbstractDao.bind
protected function bind( $stmt, $values ) { $values = $values ?: []; if ( (bool)count( array_filter( array_keys( $values ), 'is_string' ) ) ) { // associative array provided foreach ( $values as $key => $value ) { // infer bind type from key prefix list( $prefix, $ignored ) = explode( '_', "{$key}_", 2 ); $type = \PDO::PARAM_STR; switch ( $prefix ) { case 'int': $type = \PDO::PARAM_INT; break; case 'bool': $type = \PDO::PARAM_BOOL; break; case 'null': $type = \PDO::PARAM_NULL; break; default: $type = \PDO::PARAM_STR; } $stmt->bindValue( $key, $value, $type ); } } else { // vector provided $idx = 1; foreach ( $values as $value ) { $stmt->bindValue( $idx, $value ); $idx++; } } }
php
protected function bind( $stmt, $values ) { $values = $values ?: []; if ( (bool)count( array_filter( array_keys( $values ), 'is_string' ) ) ) { // associative array provided foreach ( $values as $key => $value ) { // infer bind type from key prefix list( $prefix, $ignored ) = explode( '_', "{$key}_", 2 ); $type = \PDO::PARAM_STR; switch ( $prefix ) { case 'int': $type = \PDO::PARAM_INT; break; case 'bool': $type = \PDO::PARAM_BOOL; break; case 'null': $type = \PDO::PARAM_NULL; break; default: $type = \PDO::PARAM_STR; } $stmt->bindValue( $key, $value, $type ); } } else { // vector provided $idx = 1; foreach ( $values as $value ) { $stmt->bindValue( $idx, $value ); $idx++; } } }
[ "protected", "function", "bind", "(", "$", "stmt", ",", "$", "values", ")", "{", "$", "values", "=", "$", "values", "?", ":", "[", "]", ";", "if", "(", "(", "bool", ")", "count", "(", "array_filter", "(", "array_keys", "(", "$", "values", ")", ",", "'is_string'", ")", ")", ")", "{", "// associative array provided", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "// infer bind type from key prefix", "list", "(", "$", "prefix", ",", "$", "ignored", ")", "=", "explode", "(", "'_'", ",", "\"{$key}_\"", ",", "2", ")", ";", "$", "type", "=", "\\", "PDO", "::", "PARAM_STR", ";", "switch", "(", "$", "prefix", ")", "{", "case", "'int'", ":", "$", "type", "=", "\\", "PDO", "::", "PARAM_INT", ";", "break", ";", "case", "'bool'", ":", "$", "type", "=", "\\", "PDO", "::", "PARAM_BOOL", ";", "break", ";", "case", "'null'", ":", "$", "type", "=", "\\", "PDO", "::", "PARAM_NULL", ";", "break", ";", "default", ":", "$", "type", "=", "\\", "PDO", "::", "PARAM_STR", ";", "}", "$", "stmt", "->", "bindValue", "(", "$", "key", ",", "$", "value", ",", "$", "type", ")", ";", "}", "}", "else", "{", "// vector provided", "$", "idx", "=", "1", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "$", "stmt", "->", "bindValue", "(", "$", "idx", ",", "$", "value", ")", ";", "$", "idx", "++", ";", "}", "}", "}" ]
Bind values to a prepared statement. If an associative array of values is provided, the data type to use when binding will be inferred by looking for a "<type>_" prefix at the beginning of the array key. This can come in very handy if you are using parameters in places like LIMIT clauses where binding as a string (the default type for PDO binds) will cause a syntax error. @param \PDOStatement $stmt Previously prepared statement @param array $values Values to bind
[ "Bind", "values", "to", "a", "prepared", "statement", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Dao/AbstractDao.php#L130-L165
31,132
wikimedia/slimapp
src/Dao/AbstractDao.php
AbstractDao.fetch
protected function fetch( $sql, $params = null ) { $stmt = $this->dbh->prepare( $sql ); $this->bind( $stmt, $params ); $stmt->execute(); return $stmt->fetch(); }
php
protected function fetch( $sql, $params = null ) { $stmt = $this->dbh->prepare( $sql ); $this->bind( $stmt, $params ); $stmt->execute(); return $stmt->fetch(); }
[ "protected", "function", "fetch", "(", "$", "sql", ",", "$", "params", "=", "null", ")", "{", "$", "stmt", "=", "$", "this", "->", "dbh", "->", "prepare", "(", "$", "sql", ")", ";", "$", "this", "->", "bind", "(", "$", "stmt", ",", "$", "params", ")", ";", "$", "stmt", "->", "execute", "(", ")", ";", "return", "$", "stmt", "->", "fetch", "(", ")", ";", "}" ]
Prepare and execute an SQL statement and return the first row of results. @param string $sql SQL @param array $params Prepared statement parameters @return array First response row
[ "Prepare", "and", "execute", "an", "SQL", "statement", "and", "return", "the", "first", "row", "of", "results", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Dao/AbstractDao.php#L174-L179
31,133
wikimedia/slimapp
src/Dao/AbstractDao.php
AbstractDao.fetchAll
protected function fetchAll( $sql, $params = null ) { $this->logger->debug( $sql, $params ?: [] ); $stmt = $this->dbh->prepare( $sql ); $this->bind( $stmt, $params ); $stmt->execute(); return $stmt->fetchAll(); }
php
protected function fetchAll( $sql, $params = null ) { $this->logger->debug( $sql, $params ?: [] ); $stmt = $this->dbh->prepare( $sql ); $this->bind( $stmt, $params ); $stmt->execute(); return $stmt->fetchAll(); }
[ "protected", "function", "fetchAll", "(", "$", "sql", ",", "$", "params", "=", "null", ")", "{", "$", "this", "->", "logger", "->", "debug", "(", "$", "sql", ",", "$", "params", "?", ":", "[", "]", ")", ";", "$", "stmt", "=", "$", "this", "->", "dbh", "->", "prepare", "(", "$", "sql", ")", ";", "$", "this", "->", "bind", "(", "$", "stmt", ",", "$", "params", ")", ";", "$", "stmt", "->", "execute", "(", ")", ";", "return", "$", "stmt", "->", "fetchAll", "(", ")", ";", "}" ]
Prepare and execute an SQL statement and return all results. @param string $sql SQL @param array $params Prepared statement parameters @return array Result rows
[ "Prepare", "and", "execute", "an", "SQL", "statement", "and", "return", "all", "results", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Dao/AbstractDao.php#L188-L194
31,134
wikimedia/slimapp
src/Dao/AbstractDao.php
AbstractDao.fetchAllWithFound
protected function fetchAllWithFound( $sql, $params = null ) { $ret = new \StdClass; $ret->rows = $this->fetchAll( $sql, $params ); $ret->found = $this->fetch( 'SELECT FOUND_ROWS() AS found' ); $ret->found = $ret->found['found']; return $ret; }
php
protected function fetchAllWithFound( $sql, $params = null ) { $ret = new \StdClass; $ret->rows = $this->fetchAll( $sql, $params ); $ret->found = $this->fetch( 'SELECT FOUND_ROWS() AS found' ); $ret->found = $ret->found['found']; return $ret; }
[ "protected", "function", "fetchAllWithFound", "(", "$", "sql", ",", "$", "params", "=", "null", ")", "{", "$", "ret", "=", "new", "\\", "StdClass", ";", "$", "ret", "->", "rows", "=", "$", "this", "->", "fetchAll", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "ret", "->", "found", "=", "$", "this", "->", "fetch", "(", "'SELECT FOUND_ROWS() AS found'", ")", ";", "$", "ret", "->", "found", "=", "$", "ret", "->", "found", "[", "'found'", "]", ";", "return", "$", "ret", ";", "}" ]
Prepare and execute an SQL statement and return all results plus the number of rows found on the server side. The SQL is expected to contain the "SQL_CALC_FOUND_ROWS" option in the select statement. If it does not, the number of found rows returned is dependent on MySQL's interpretation of the query. @param string $sql SQL @param array $params Prepared statement parameters @return object StdClass with rows and found memebers
[ "Prepare", "and", "execute", "an", "SQL", "statement", "and", "return", "all", "results", "plus", "the", "number", "of", "rows", "found", "on", "the", "server", "side", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Dao/AbstractDao.php#L208-L216
31,135
wikimedia/slimapp
src/Dao/AbstractDao.php
AbstractDao.concat
protected static function concat( /*varags*/ ) { $args = []; foreach ( func_get_args() as $arg ) { if ( is_array( $arg ) ) { $args = array_merge( $args, $arg ); } else { $args[] = $arg; } } return implode( ' ', $args ); }
php
protected static function concat( /*varags*/ ) { $args = []; foreach ( func_get_args() as $arg ) { if ( is_array( $arg ) ) { $args = array_merge( $args, $arg ); } else { $args[] = $arg; } } return implode( ' ', $args ); }
[ "protected", "static", "function", "concat", "(", "/*varags*/", ")", "{", "$", "args", "=", "[", "]", ";", "foreach", "(", "func_get_args", "(", ")", "as", "$", "arg", ")", "{", "if", "(", "is_array", "(", "$", "arg", ")", ")", "{", "$", "args", "=", "array_merge", "(", "$", "args", ",", "$", "arg", ")", ";", "}", "else", "{", "$", "args", "[", "]", "=", "$", "arg", ";", "}", "}", "return", "implode", "(", "' '", ",", "$", "args", ")", ";", "}" ]
Create a string by joining all arguments with spaces. If one or more of the arguments are arrays each element of the array will be included independently. @return string New string
[ "Create", "a", "string", "by", "joining", "all", "arguments", "with", "spaces", "." ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Dao/AbstractDao.php#L321-L332
31,136
thejacer87/php-canadapost-api
src/ClientBase.php
ClientBase.delete
public function delete($endpoint, array $headers = [], array $options = []) { $url = $this->baseUrl . '/' . $endpoint; try { $client = $this->buildClient($options); $options += [ 'auth' => [$this->username, $this->password], 'headers' => $headers, ]; $response = $client->request('DELETE', $url, $options); } catch (GuzzleClientException $exception) { $response = $exception->getResponse(); throw new ClientException( $exception->getMessage(), $this->parseResponse($response), $exception->getRequest(), $response, $exception->getPrevious(), $exception->getHandlerContext() ); } return $this->parseResponse($response); }
php
public function delete($endpoint, array $headers = [], array $options = []) { $url = $this->baseUrl . '/' . $endpoint; try { $client = $this->buildClient($options); $options += [ 'auth' => [$this->username, $this->password], 'headers' => $headers, ]; $response = $client->request('DELETE', $url, $options); } catch (GuzzleClientException $exception) { $response = $exception->getResponse(); throw new ClientException( $exception->getMessage(), $this->parseResponse($response), $exception->getRequest(), $response, $exception->getPrevious(), $exception->getHandlerContext() ); } return $this->parseResponse($response); }
[ "public", "function", "delete", "(", "$", "endpoint", ",", "array", "$", "headers", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "url", "=", "$", "this", "->", "baseUrl", ".", "'/'", ".", "$", "endpoint", ";", "try", "{", "$", "client", "=", "$", "this", "->", "buildClient", "(", "$", "options", ")", ";", "$", "options", "+=", "[", "'auth'", "=>", "[", "$", "this", "->", "username", ",", "$", "this", "->", "password", "]", ",", "'headers'", "=>", "$", "headers", ",", "]", ";", "$", "response", "=", "$", "client", "->", "request", "(", "'DELETE'", ",", "$", "url", ",", "$", "options", ")", ";", "}", "catch", "(", "GuzzleClientException", "$", "exception", ")", "{", "$", "response", "=", "$", "exception", "->", "getResponse", "(", ")", ";", "throw", "new", "ClientException", "(", "$", "exception", "->", "getMessage", "(", ")", ",", "$", "this", "->", "parseResponse", "(", "$", "response", ")", ",", "$", "exception", "->", "getRequest", "(", ")", ",", "$", "response", ",", "$", "exception", "->", "getPrevious", "(", ")", ",", "$", "exception", "->", "getHandlerContext", "(", ")", ")", ";", "}", "return", "$", "this", "->", "parseResponse", "(", "$", "response", ")", ";", "}" ]
Send the DELETE request to the Canada Post API. @param string $endpoint The endpoint to send the request. @param array $headers The HTTP headers array. @param array $options An array of options. @return \DOMDocument|\Psr\Http\Message\StreamInterface @throws \GuzzleHttp\Exception\GuzzleException
[ "Send", "the", "DELETE", "request", "to", "the", "Canada", "Post", "API", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L202-L227
31,137
thejacer87/php-canadapost-api
src/ClientBase.php
ClientBase.setCredentials
protected function setCredentials(array $config = []) { if (!isset($config['username']) || !isset($config['password']) || !isset($config['customer_number'])) { $message = 'A username, password and customer number are required for authenticated to the Canada Post API.'; throw new \InvalidArgumentException($message); } $this->username = $config['username']; $this->password = $config['password']; $this->customerNumber = $config['customer_number']; $this->contractId = isset($config['contract_id']) ? $config['contract_id'] : null; }
php
protected function setCredentials(array $config = []) { if (!isset($config['username']) || !isset($config['password']) || !isset($config['customer_number'])) { $message = 'A username, password and customer number are required for authenticated to the Canada Post API.'; throw new \InvalidArgumentException($message); } $this->username = $config['username']; $this->password = $config['password']; $this->customerNumber = $config['customer_number']; $this->contractId = isset($config['contract_id']) ? $config['contract_id'] : null; }
[ "protected", "function", "setCredentials", "(", "array", "$", "config", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "config", "[", "'username'", "]", ")", "||", "!", "isset", "(", "$", "config", "[", "'password'", "]", ")", "||", "!", "isset", "(", "$", "config", "[", "'customer_number'", "]", ")", ")", "{", "$", "message", "=", "'A username, password and customer number are required for authenticated to the Canada Post API.'", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "$", "this", "->", "username", "=", "$", "config", "[", "'username'", "]", ";", "$", "this", "->", "password", "=", "$", "config", "[", "'password'", "]", ";", "$", "this", "->", "customerNumber", "=", "$", "config", "[", "'customer_number'", "]", ";", "$", "this", "->", "contractId", "=", "isset", "(", "$", "config", "[", "'contract_id'", "]", ")", "?", "$", "config", "[", "'contract_id'", "]", ":", "null", ";", "}" ]
Set the API configuration array for the Client. @param array $config The configuration array.
[ "Set", "the", "API", "configuration", "array", "for", "the", "Client", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L300-L311
31,138
thejacer87/php-canadapost-api
src/ClientBase.php
ClientBase.baseUrl
protected function baseUrl(array $config = []) { if (isset($this->baseUrl)) { return $this->baseUrl; } if (isset($config['base_url'])) { $this->baseUrl = $config['base_url']; return $this->baseUrl; } switch ($config['env']) { case self::ENV_DEVELOPMENT: $this->baseUrl = self::BASE_URL_DEVELOPMENT; break; case self::ENV_PRODUCTION: $this->baseUrl = self::BASE_URL_PRODUCTION; break; default: $message = sprintf( 'Unsupported environment "%s". Supported environments are "%s"', $config['env'], implode(', ', [self::ENV_DEVELOPMENT, self::ENV_PRODUCTION]) ); throw new \InvalidArgumentException($message); } return $this->baseUrl; }
php
protected function baseUrl(array $config = []) { if (isset($this->baseUrl)) { return $this->baseUrl; } if (isset($config['base_url'])) { $this->baseUrl = $config['base_url']; return $this->baseUrl; } switch ($config['env']) { case self::ENV_DEVELOPMENT: $this->baseUrl = self::BASE_URL_DEVELOPMENT; break; case self::ENV_PRODUCTION: $this->baseUrl = self::BASE_URL_PRODUCTION; break; default: $message = sprintf( 'Unsupported environment "%s". Supported environments are "%s"', $config['env'], implode(', ', [self::ENV_DEVELOPMENT, self::ENV_PRODUCTION]) ); throw new \InvalidArgumentException($message); } return $this->baseUrl; }
[ "protected", "function", "baseUrl", "(", "array", "$", "config", "=", "[", "]", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "baseUrl", ")", ")", "{", "return", "$", "this", "->", "baseUrl", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'base_url'", "]", ")", ")", "{", "$", "this", "->", "baseUrl", "=", "$", "config", "[", "'base_url'", "]", ";", "return", "$", "this", "->", "baseUrl", ";", "}", "switch", "(", "$", "config", "[", "'env'", "]", ")", "{", "case", "self", "::", "ENV_DEVELOPMENT", ":", "$", "this", "->", "baseUrl", "=", "self", "::", "BASE_URL_DEVELOPMENT", ";", "break", ";", "case", "self", "::", "ENV_PRODUCTION", ":", "$", "this", "->", "baseUrl", "=", "self", "::", "BASE_URL_PRODUCTION", ";", "break", ";", "default", ":", "$", "message", "=", "sprintf", "(", "'Unsupported environment \"%s\". Supported environments are \"%s\"'", ",", "$", "config", "[", "'env'", "]", ",", "implode", "(", "', '", ",", "[", "self", "::", "ENV_DEVELOPMENT", ",", "self", "::", "ENV_PRODUCTION", "]", ")", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "return", "$", "this", "->", "baseUrl", ";", "}" ]
Return the base url for the Canada Post API. @param array $config @return mixed|string The base url. @throws \InvalidArgumentException
[ "Return", "the", "base", "url", "for", "the", "Canada", "Post", "API", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L322-L352
31,139
thejacer87/php-canadapost-api
src/ClientBase.php
ClientBase.parseResponse
protected function parseResponse(Response $response) { $xml = new \DomDocument(); $xml->loadXML($response->getBody()); return XML2Array::createArray($xml->saveXML()); }
php
protected function parseResponse(Response $response) { $xml = new \DomDocument(); $xml->loadXML($response->getBody()); return XML2Array::createArray($xml->saveXML()); }
[ "protected", "function", "parseResponse", "(", "Response", "$", "response", ")", "{", "$", "xml", "=", "new", "\\", "DomDocument", "(", ")", ";", "$", "xml", "->", "loadXML", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "return", "XML2Array", "::", "createArray", "(", "$", "xml", "->", "saveXML", "(", ")", ")", ";", "}" ]
Parse the xml response into an array, @param Response $response The xml response. @return \DOMDocument The response array. @throws \Exception
[ "Parse", "the", "xml", "response", "into", "an", "array" ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L364-L370
31,140
thejacer87/php-canadapost-api
src/ClientBase.php
ClientBase.buildClient
protected function buildClient(array &$options) { if (!isset($options['debug']) && $this->config['env'] === self::ENV_DEVELOPMENT) { $options['debug'] = true; } if (!isset($options['handler'])) { return new GuzzleClient(); } $client = new GuzzleClient(['handler' => $options['handler']]); unset($options['handler']); return $client; }
php
protected function buildClient(array &$options) { if (!isset($options['debug']) && $this->config['env'] === self::ENV_DEVELOPMENT) { $options['debug'] = true; } if (!isset($options['handler'])) { return new GuzzleClient(); } $client = new GuzzleClient(['handler' => $options['handler']]); unset($options['handler']); return $client; }
[ "protected", "function", "buildClient", "(", "array", "&", "$", "options", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'debug'", "]", ")", "&&", "$", "this", "->", "config", "[", "'env'", "]", "===", "self", "::", "ENV_DEVELOPMENT", ")", "{", "$", "options", "[", "'debug'", "]", "=", "true", ";", "}", "if", "(", "!", "isset", "(", "$", "options", "[", "'handler'", "]", ")", ")", "{", "return", "new", "GuzzleClient", "(", ")", ";", "}", "$", "client", "=", "new", "GuzzleClient", "(", "[", "'handler'", "=>", "$", "options", "[", "'handler'", "]", "]", ")", ";", "unset", "(", "$", "options", "[", "'handler'", "]", ")", ";", "return", "$", "client", ";", "}" ]
Build the Guzzle client. @param array $options The options array. @return \GuzzleHttp\Client
[ "Build", "the", "Guzzle", "client", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L380-L393
31,141
thejacer87/php-canadapost-api
src/ClientBase.php
ClientBase.verifyDates
protected function verifyDates($from, $to, $format = 'YmdHs') { if (!DateTime::createFromFormat($format, $from)) { $message = 'The $from date is improperly formatted. Please use "YmdHs".'; throw new \InvalidArgumentException($message); } if (!DateTime::createFromFormat($format, $to)) { $message = 'The $to date is improperly formatted. Please use "YmdHs".'; throw new \InvalidArgumentException($message); } if (new DateTime($from) > new DateTime($to)) { $message = 'The $from date cannot be a later date than the $to date.'; throw new \InvalidArgumentException($message); } }
php
protected function verifyDates($from, $to, $format = 'YmdHs') { if (!DateTime::createFromFormat($format, $from)) { $message = 'The $from date is improperly formatted. Please use "YmdHs".'; throw new \InvalidArgumentException($message); } if (!DateTime::createFromFormat($format, $to)) { $message = 'The $to date is improperly formatted. Please use "YmdHs".'; throw new \InvalidArgumentException($message); } if (new DateTime($from) > new DateTime($to)) { $message = 'The $from date cannot be a later date than the $to date.'; throw new \InvalidArgumentException($message); } }
[ "protected", "function", "verifyDates", "(", "$", "from", ",", "$", "to", ",", "$", "format", "=", "'YmdHs'", ")", "{", "if", "(", "!", "DateTime", "::", "createFromFormat", "(", "$", "format", ",", "$", "from", ")", ")", "{", "$", "message", "=", "'The $from date is improperly formatted. Please use \"YmdHs\".'", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "if", "(", "!", "DateTime", "::", "createFromFormat", "(", "$", "format", ",", "$", "to", ")", ")", "{", "$", "message", "=", "'The $to date is improperly formatted. Please use \"YmdHs\".'", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "if", "(", "new", "DateTime", "(", "$", "from", ")", ">", "new", "DateTime", "(", "$", "to", ")", ")", "{", "$", "message", "=", "'The $from date cannot be a later date than the $to date.'", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "}" ]
Helper function to verify the dates are valid. @param string $from The beginning date. @param $to The end date. @param string $format The date format to verify. @throws \InvalidArgumentException
[ "Helper", "function", "to", "verify", "the", "dates", "are", "valid", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L420-L434
31,142
thejacer87/php-canadapost-api
src/ClientBase.php
ClientBase.parseOptionCodes
protected function parseOptionCodes(array $options) { $valid_options = []; foreach ($options['option_codes'] as $optionCode) { if (!array_key_exists(strtoupper($optionCode), self::getOptionCodes())) { $message = sprintf( 'Unsupported option code: "%s". Supported options are %s', $optionCode, implode(', ', array_keys(self::getOptionCodes())) ); throw new \InvalidArgumentException($message); } // @todo Perhaps we should check for conflicts here, might be overkill. // From Canada Post docs: // There are some options that can be applied to a shipment that // conflict with the presence of another option. You can use the // "Get Option" call in advance to check the contents of the // <conflicting-options> group from a Get Option call for options // selected by end users or options available for a given service. $valid_options[] = [ 'option-code' => $optionCode, ]; } return $valid_options; }
php
protected function parseOptionCodes(array $options) { $valid_options = []; foreach ($options['option_codes'] as $optionCode) { if (!array_key_exists(strtoupper($optionCode), self::getOptionCodes())) { $message = sprintf( 'Unsupported option code: "%s". Supported options are %s', $optionCode, implode(', ', array_keys(self::getOptionCodes())) ); throw new \InvalidArgumentException($message); } // @todo Perhaps we should check for conflicts here, might be overkill. // From Canada Post docs: // There are some options that can be applied to a shipment that // conflict with the presence of another option. You can use the // "Get Option" call in advance to check the contents of the // <conflicting-options> group from a Get Option call for options // selected by end users or options available for a given service. $valid_options[] = [ 'option-code' => $optionCode, ]; } return $valid_options; }
[ "protected", "function", "parseOptionCodes", "(", "array", "$", "options", ")", "{", "$", "valid_options", "=", "[", "]", ";", "foreach", "(", "$", "options", "[", "'option_codes'", "]", "as", "$", "optionCode", ")", "{", "if", "(", "!", "array_key_exists", "(", "strtoupper", "(", "$", "optionCode", ")", ",", "self", "::", "getOptionCodes", "(", ")", ")", ")", "{", "$", "message", "=", "sprintf", "(", "'Unsupported option code: \"%s\". Supported options are %s'", ",", "$", "optionCode", ",", "implode", "(", "', '", ",", "array_keys", "(", "self", "::", "getOptionCodes", "(", ")", ")", ")", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "// @todo Perhaps we should check for conflicts here, might be overkill.", "// From Canada Post docs:", "// There are some options that can be applied to a shipment that", "// conflict with the presence of another option. You can use the", "// \"Get Option\" call in advance to check the contents of the", "// <conflicting-options> group from a Get Option call for options", "// selected by end users or options available for a given service.", "$", "valid_options", "[", "]", "=", "[", "'option-code'", "=>", "$", "optionCode", ",", "]", ";", "}", "return", "$", "valid_options", ";", "}" ]
Helper function to extract the option codes. @param array $options The options array. @return array The list of options with the option-code.
[ "Helper", "function", "to", "extract", "the", "option", "codes", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L445-L470
31,143
pulsarvp/vps-tools
src/controllers/WebController.php
WebController.error
public function error ($message, $isRaw = false) { Yii::$app->notification->error($message, $isRaw); }
php
public function error ($message, $isRaw = false) { Yii::$app->notification->error($message, $isRaw); }
[ "public", "function", "error", "(", "$", "message", ",", "$", "isRaw", "=", "false", ")", "{", "Yii", "::", "$", "app", "->", "notification", "->", "error", "(", "$", "message", ",", "$", "isRaw", ")", ";", "}" ]
Add user error message. @param string $message Message text. @param boolean $isRaw Whether given text is raw. If not it will be processed with [[Yii::tr()]].
[ "Add", "user", "error", "message", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L144-L147
31,144
pulsarvp/vps-tools
src/controllers/WebController.php
WebController.message
public function message ($message, $isRaw = false) { Yii::$app->notification->message($message, $isRaw); }
php
public function message ($message, $isRaw = false) { Yii::$app->notification->message($message, $isRaw); }
[ "public", "function", "message", "(", "$", "message", ",", "$", "isRaw", "=", "false", ")", "{", "Yii", "::", "$", "app", "->", "notification", "->", "message", "(", "$", "message", ",", "$", "isRaw", ")", ";", "}" ]
Add user message. @param string $message Message text. @param boolean $isRaw Whether given text is raw. If not it will be processed with [[Yii::tr()]].
[ "Add", "user", "message", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L155-L158
31,145
pulsarvp/vps-tools
src/controllers/WebController.php
WebController.redirect
public function redirect ($url, $statusCode = 302) { parent::redirect($url, $statusCode); Yii::$app->end(); }
php
public function redirect ($url, $statusCode = 302) { parent::redirect($url, $statusCode); Yii::$app->end(); }
[ "public", "function", "redirect", "(", "$", "url", ",", "$", "statusCode", "=", "302", ")", "{", "parent", "::", "redirect", "(", "$", "url", ",", "$", "statusCode", ")", ";", "Yii", "::", "$", "app", "->", "end", "(", ")", ";", "}" ]
Redirects and ends app. That prevents from sending additional headers. @inheritdoc
[ "Redirects", "and", "ends", "app", ".", "That", "prevents", "from", "sending", "additional", "headers", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L165-L169
31,146
pulsarvp/vps-tools
src/controllers/WebController.php
WebController.warning
public function warning ($message, $isRaw = false) { Yii::$app->notification->warning($message, $isRaw); }
php
public function warning ($message, $isRaw = false) { Yii::$app->notification->warning($message, $isRaw); }
[ "public", "function", "warning", "(", "$", "message", ",", "$", "isRaw", "=", "false", ")", "{", "Yii", "::", "$", "app", "->", "notification", "->", "warning", "(", "$", "message", ",", "$", "isRaw", ")", ";", "}" ]
Add user warning. @param string $message Message text. @param boolean $isRaw Whether given text is raw. If not it will be processed with [[Yii::tr()]].
[ "Add", "user", "warning", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L177-L180
31,147
pulsarvp/vps-tools
src/controllers/WebController.php
WebController.forceSetTitle
private function forceSetTitle () { if (isset($this->_data[ 'title' ])) return; $path = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id; if (Yii::$app->has('menu')) { foreach (Yii::$app->menu as $menu) { if ($menu->path === $path) { $this->setTitle($menu->name); return; } } } $this->setTitle(ucfirst(strtolower(Yii::$app->controller->id . ' ' . Yii::$app->controller->action->id))); }
php
private function forceSetTitle () { if (isset($this->_data[ 'title' ])) return; $path = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id; if (Yii::$app->has('menu')) { foreach (Yii::$app->menu as $menu) { if ($menu->path === $path) { $this->setTitle($menu->name); return; } } } $this->setTitle(ucfirst(strtolower(Yii::$app->controller->id . ' ' . Yii::$app->controller->action->id))); }
[ "private", "function", "forceSetTitle", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_data", "[", "'title'", "]", ")", ")", "return", ";", "$", "path", "=", "Yii", "::", "$", "app", "->", "controller", "->", "id", ".", "'/'", ".", "Yii", "::", "$", "app", "->", "controller", "->", "action", "->", "id", ";", "if", "(", "Yii", "::", "$", "app", "->", "has", "(", "'menu'", ")", ")", "{", "foreach", "(", "Yii", "::", "$", "app", "->", "menu", "as", "$", "menu", ")", "{", "if", "(", "$", "menu", "->", "path", "===", "$", "path", ")", "{", "$", "this", "->", "setTitle", "(", "$", "menu", "->", "name", ")", ";", "return", ";", "}", "}", "}", "$", "this", "->", "setTitle", "(", "ucfirst", "(", "strtolower", "(", "Yii", "::", "$", "app", "->", "controller", "->", "id", ".", "' '", ".", "Yii", "::", "$", "app", "->", "controller", "->", "action", "->", "id", ")", ")", ")", ";", "}" ]
Force generate title if not set previously.
[ "Force", "generate", "title", "if", "not", "set", "previously", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L185-L205
31,148
wikimedia/slimapp
src/Config.php
Config.getBool
public static function getBool( $name, $default = false ) { $var = getenv( $name ); $val = filter_var( $var, \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE ); return ( $val === null ) ? $default : $val; }
php
public static function getBool( $name, $default = false ) { $var = getenv( $name ); $val = filter_var( $var, \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE ); return ( $val === null ) ? $default : $val; }
[ "public", "static", "function", "getBool", "(", "$", "name", ",", "$", "default", "=", "false", ")", "{", "$", "var", "=", "getenv", "(", "$", "name", ")", ";", "$", "val", "=", "filter_var", "(", "$", "var", ",", "\\", "FILTER_VALIDATE_BOOLEAN", ",", "\\", "FILTER_NULL_ON_FAILURE", ")", ";", "return", "(", "$", "val", "===", "null", ")", "?", "$", "default", ":", "$", "val", ";", "}" ]
Get a boolean value @param string $name Setting name @param bool $default Default value if none found @return bool Value
[ "Get", "a", "boolean", "value" ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Config.php#L39-L43
31,149
wikimedia/slimapp
src/Config.php
Config.getStr
public static function getStr( $name, $default = '' ) { $var = getenv( $name ); if ( $var !== false ) { $var = filter_var( $var, \FILTER_SANITIZE_STRING, \FILTER_FLAG_STRIP_LOW | \FILTER_FLAG_STRIP_HIGH ); } return ( $var === false ) ? $default : $var; }
php
public static function getStr( $name, $default = '' ) { $var = getenv( $name ); if ( $var !== false ) { $var = filter_var( $var, \FILTER_SANITIZE_STRING, \FILTER_FLAG_STRIP_LOW | \FILTER_FLAG_STRIP_HIGH ); } return ( $var === false ) ? $default : $var; }
[ "public", "static", "function", "getStr", "(", "$", "name", ",", "$", "default", "=", "''", ")", "{", "$", "var", "=", "getenv", "(", "$", "name", ")", ";", "if", "(", "$", "var", "!==", "false", ")", "{", "$", "var", "=", "filter_var", "(", "$", "var", ",", "\\", "FILTER_SANITIZE_STRING", ",", "\\", "FILTER_FLAG_STRIP_LOW", "|", "\\", "FILTER_FLAG_STRIP_HIGH", ")", ";", "}", "return", "(", "$", "var", "===", "false", ")", "?", "$", "default", ":", "$", "var", ";", "}" ]
Get a string value @param string $name Setting name @param string $default Default value if none found @return string Value
[ "Get", "a", "string", "value" ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Config.php#L51-L60
31,150
wikimedia/slimapp
src/Config.php
Config.load
public static function load( $file ) { if ( !is_readable( $file ) ) { throw new \InvalidArgumentException( "File '{$file}' is not readable." ); } $settings = parse_ini_file( $file ); foreach ( $settings as $key => $value ) { // Store in super globals $_ENV[$key] = $value; $_SERVER[$key] = $value; // Also store in process env vars putenv( "{$key}={$value}" ); } // end foreach settings }
php
public static function load( $file ) { if ( !is_readable( $file ) ) { throw new \InvalidArgumentException( "File '{$file}' is not readable." ); } $settings = parse_ini_file( $file ); foreach ( $settings as $key => $value ) { // Store in super globals $_ENV[$key] = $value; $_SERVER[$key] = $value; // Also store in process env vars putenv( "{$key}={$value}" ); } // end foreach settings }
[ "public", "static", "function", "load", "(", "$", "file", ")", "{", "if", "(", "!", "is_readable", "(", "$", "file", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"File '{$file}' is not readable.\"", ")", ";", "}", "$", "settings", "=", "parse_ini_file", "(", "$", "file", ")", ";", "foreach", "(", "$", "settings", "as", "$", "key", "=>", "$", "value", ")", "{", "// Store in super globals", "$", "_ENV", "[", "$", "key", "]", "=", "$", "value", ";", "$", "_SERVER", "[", "$", "key", "]", "=", "$", "value", ";", "// Also store in process env vars", "putenv", "(", "\"{$key}={$value}\"", ")", ";", "}", "// end foreach settings", "}" ]
Load configuration data from file Reads ini file style configuration settings from the given file and loads the values into the application's environment. This is useful in deployments where the use of the container environment for configuration is discouraged. @param string $file Path to config file
[ "Load", "configuration", "data", "from", "file" ]
9fd0deba96f635c96d28d59d1f761283f62842d4
https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Config.php#L81-L96
31,151
bearcms/bearframework-addon
classes/BearCMS/Internal/Data2/CommentsThreads.php
CommentsThreads.get
public function get(string $id): ?\BearCMS\Internal\Data2\CommentsThread { $data = Internal\Data::getValue('bearcms/comments/thread/' . md5($id) . '.json'); if ($data !== null) { return $this->makeCommentsThreadPostFromRawData($data); } return null; }
php
public function get(string $id): ?\BearCMS\Internal\Data2\CommentsThread { $data = Internal\Data::getValue('bearcms/comments/thread/' . md5($id) . '.json'); if ($data !== null) { return $this->makeCommentsThreadPostFromRawData($data); } return null; }
[ "public", "function", "get", "(", "string", "$", "id", ")", ":", "?", "\\", "BearCMS", "\\", "Internal", "\\", "Data2", "\\", "CommentsThread", "{", "$", "data", "=", "Internal", "\\", "Data", "::", "getValue", "(", "'bearcms/comments/thread/'", ".", "md5", "(", "$", "id", ")", ".", "'.json'", ")", ";", "if", "(", "$", "data", "!==", "null", ")", "{", "return", "$", "this", "->", "makeCommentsThreadPostFromRawData", "(", "$", "data", ")", ";", "}", "return", "null", ";", "}" ]
Retrieves information about the comments thread specified @param string $id The comments thread ID @return \IvoPetkov\DataObject|null The comments thread data or null if the thread not found @throws \InvalidArgumentException
[ "Retrieves", "information", "about", "the", "comments", "thread", "specified" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/CommentsThreads.php#L36-L43
31,152
bearcms/bearframework-addon
classes/BearCMS/Internal/Data2/CommentsThreads.php
CommentsThreads.getList
public function getList() { $list = Internal\Data::getList('bearcms/comments/thread/'); array_walk($list, function(&$value) { $value = $this->makeCommentsThreadPostFromRawData($value); }); return new \IvoPetkov\DataList($list); }
php
public function getList() { $list = Internal\Data::getList('bearcms/comments/thread/'); array_walk($list, function(&$value) { $value = $this->makeCommentsThreadPostFromRawData($value); }); return new \IvoPetkov\DataList($list); }
[ "public", "function", "getList", "(", ")", "{", "$", "list", "=", "Internal", "\\", "Data", "::", "getList", "(", "'bearcms/comments/thread/'", ")", ";", "array_walk", "(", "$", "list", ",", "function", "(", "&", "$", "value", ")", "{", "$", "value", "=", "$", "this", "->", "makeCommentsThreadPostFromRawData", "(", "$", "value", ")", ";", "}", ")", ";", "return", "new", "\\", "IvoPetkov", "\\", "DataList", "(", "$", "list", ")", ";", "}" ]
Retrieves a list of all comments threads @return \IvoPetkov\DataList List containing all comments threads data
[ "Retrieves", "a", "list", "of", "all", "comments", "threads" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/CommentsThreads.php#L50-L57
31,153
bearcms/bearframework-addon
classes/BearCMS/Internal/Data2/UsersInvitations.php
UsersInvitations.get
public function get(string $key): ?\BearCMS\Internal\Data2\UserInvitation { $data = \BearCMS\Internal\Data::getValue('bearcms/users/invitation/' . md5($key) . '.json'); if ($data !== null) { return $this->makeUserFromRawData($data); } return null; }
php
public function get(string $key): ?\BearCMS\Internal\Data2\UserInvitation { $data = \BearCMS\Internal\Data::getValue('bearcms/users/invitation/' . md5($key) . '.json'); if ($data !== null) { return $this->makeUserFromRawData($data); } return null; }
[ "public", "function", "get", "(", "string", "$", "key", ")", ":", "?", "\\", "BearCMS", "\\", "Internal", "\\", "Data2", "\\", "UserInvitation", "{", "$", "data", "=", "\\", "BearCMS", "\\", "Internal", "\\", "Data", "::", "getValue", "(", "'bearcms/users/invitation/'", ".", "md5", "(", "$", "key", ")", ".", "'.json'", ")", ";", "if", "(", "$", "data", "!==", "null", ")", "{", "return", "$", "this", "->", "makeUserFromRawData", "(", "$", "data", ")", ";", "}", "return", "null", ";", "}" ]
Retrieves information about the user invitation specified @param string $id The user invitation key @return \BearCMS\Internal\Data2\UserInvitation|null The user invitation data or null if not found
[ "Retrieves", "information", "about", "the", "user", "invitation", "specified" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/UsersInvitations.php#L38-L45
31,154
bearcms/bearframework-addon
classes/BearCMS/Internal/Data2/UsersInvitations.php
UsersInvitations.getList
public function getList() { $list = \BearCMS\Internal\Data::getList('bearcms/users/invitation/'); array_walk($list, function(&$value) { $value = $this->makeUserFromRawData($value); }); return new \IvoPetkov\DataList($list); }
php
public function getList() { $list = \BearCMS\Internal\Data::getList('bearcms/users/invitation/'); array_walk($list, function(&$value) { $value = $this->makeUserFromRawData($value); }); return new \IvoPetkov\DataList($list); }
[ "public", "function", "getList", "(", ")", "{", "$", "list", "=", "\\", "BearCMS", "\\", "Internal", "\\", "Data", "::", "getList", "(", "'bearcms/users/invitation/'", ")", ";", "array_walk", "(", "$", "list", ",", "function", "(", "&", "$", "value", ")", "{", "$", "value", "=", "$", "this", "->", "makeUserFromRawData", "(", "$", "value", ")", ";", "}", ")", ";", "return", "new", "\\", "IvoPetkov", "\\", "DataList", "(", "$", "list", ")", ";", "}" ]
Retrieves a list of all users invitations @return \IvoPetkov\DataList|\BearCMS\Internal\Data2\UserInvitation[] List containing all users invitations data
[ "Retrieves", "a", "list", "of", "all", "users", "invitations" ]
7ef131b81aac26070a2b937dd67f530a6caa02f0
https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/UsersInvitations.php#L52-L59
31,155
thejacer87/php-canadapost-api
src/Returns.php
Returns.createAuthorizedReturn
public function createAuthorizedReturn( array $returner, array $receiver, array $parcel, array $options = [] ) { $content = $this->buildReturnsArray( $returner, $receiver, $parcel, $options ); $xml = Array2XML::createXML('authorized-return', $content); $envelope = $xml->documentElement; $envelope->setAttribute('xmlns', 'http://www.canadapost.ca/ws/authreturn-v2'); $payload = $xml->saveXML(); $response = $this->post( "rs/{$this->customerNumber}/{$this->customerNumber}/authorizedreturn", [ 'Accept' => 'application/vnd.cpc.authreturn-v2+xml', 'Content-Type' => 'application/vnd.cpc.authreturn-v2+xml', ], $payload, $options ); return $response; }
php
public function createAuthorizedReturn( array $returner, array $receiver, array $parcel, array $options = [] ) { $content = $this->buildReturnsArray( $returner, $receiver, $parcel, $options ); $xml = Array2XML::createXML('authorized-return', $content); $envelope = $xml->documentElement; $envelope->setAttribute('xmlns', 'http://www.canadapost.ca/ws/authreturn-v2'); $payload = $xml->saveXML(); $response = $this->post( "rs/{$this->customerNumber}/{$this->customerNumber}/authorizedreturn", [ 'Accept' => 'application/vnd.cpc.authreturn-v2+xml', 'Content-Type' => 'application/vnd.cpc.authreturn-v2+xml', ], $payload, $options ); return $response; }
[ "public", "function", "createAuthorizedReturn", "(", "array", "$", "returner", ",", "array", "$", "receiver", ",", "array", "$", "parcel", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "content", "=", "$", "this", "->", "buildReturnsArray", "(", "$", "returner", ",", "$", "receiver", ",", "$", "parcel", ",", "$", "options", ")", ";", "$", "xml", "=", "Array2XML", "::", "createXML", "(", "'authorized-return'", ",", "$", "content", ")", ";", "$", "envelope", "=", "$", "xml", "->", "documentElement", ";", "$", "envelope", "->", "setAttribute", "(", "'xmlns'", ",", "'http://www.canadapost.ca/ws/authreturn-v2'", ")", ";", "$", "payload", "=", "$", "xml", "->", "saveXML", "(", ")", ";", "$", "response", "=", "$", "this", "->", "post", "(", "\"rs/{$this->customerNumber}/{$this->customerNumber}/authorizedreturn\"", ",", "[", "'Accept'", "=>", "'application/vnd.cpc.authreturn-v2+xml'", ",", "'Content-Type'", "=>", "'application/vnd.cpc.authreturn-v2+xml'", ",", "]", ",", "$", "payload", ",", "$", "options", ")", ";", "return", "$", "response", ";", "}" ]
Create an authorized return. @param array $returner The returner info. <code> $returner = [ 'name' => 'Jane Doe', 'company' => 'Acro Media', 'domestic-address' => [ 'address-line-1' => '103-2303 Leckie Rd', 'city' => 'Kelowna', 'province' => 'BC', 'postal-code' => 'V1X 6Y5', ], ] </code> @param array $receiver The receiver info. <code> $receiver = [ 'name' => 'John Smith', 'company' => 'Acro Media', 'domestic-address' => [ 'address-line-1' => '123 Main St', 'city' => 'Kelowna', 'province' => 'BC', 'postal-code' => 'V1X 1M2', ], ] </code> @param array $parcel The parcel characteristics. <code> $parcel = [ 'weight' => 0.500, // in kg. 'dimensions' => [ // in cm. 'length' => 30, 'width' => 10, 'height' => 20, ], ], ] </code> @param array $options The options array. @return \DOMDocument @throws \GuzzleHttp\Exception\GuzzleException
[ "Create", "an", "authorized", "return", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Returns.php#L66-L95
31,156
thejacer87/php-canadapost-api
src/Returns.php
Returns.createOpenReturn
public function createOpenReturn( array $receiver, array $parcel, array $options = [] ) { $this->formatPostalCode($receiver['domestic-address']['postal-code']); $content = [ 'max-number-of-artifacts' => 10, 'service-code' => $parcel['service_code'], 'receiver' => $receiver, 'settlement-info' => [ 'contract-id' => $this->contractId, ], ]; if (!empty($options['option_codes'])) { $return_info['options']['option'] = $this->parseOptionCodes($options); } $xml = Array2XML::createXML('open-return', $content); $envelope = $xml->documentElement; $envelope->setAttribute('xmlns', 'http://www.canadapost.ca/ws/openreturn-v2'); $payload = $xml->saveXML(); $response = $this->post( "rs/{$this->customerNumber}/{$this->customerNumber}/openreturn", [ 'Accept' => 'application/vnd.cpc.openreturn-v2+xml', 'Content-Type' => 'application/vnd.cpc.openreturn-v2+xml', ], $payload, $options ); return $response; }
php
public function createOpenReturn( array $receiver, array $parcel, array $options = [] ) { $this->formatPostalCode($receiver['domestic-address']['postal-code']); $content = [ 'max-number-of-artifacts' => 10, 'service-code' => $parcel['service_code'], 'receiver' => $receiver, 'settlement-info' => [ 'contract-id' => $this->contractId, ], ]; if (!empty($options['option_codes'])) { $return_info['options']['option'] = $this->parseOptionCodes($options); } $xml = Array2XML::createXML('open-return', $content); $envelope = $xml->documentElement; $envelope->setAttribute('xmlns', 'http://www.canadapost.ca/ws/openreturn-v2'); $payload = $xml->saveXML(); $response = $this->post( "rs/{$this->customerNumber}/{$this->customerNumber}/openreturn", [ 'Accept' => 'application/vnd.cpc.openreturn-v2+xml', 'Content-Type' => 'application/vnd.cpc.openreturn-v2+xml', ], $payload, $options ); return $response; }
[ "public", "function", "createOpenReturn", "(", "array", "$", "receiver", ",", "array", "$", "parcel", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "formatPostalCode", "(", "$", "receiver", "[", "'domestic-address'", "]", "[", "'postal-code'", "]", ")", ";", "$", "content", "=", "[", "'max-number-of-artifacts'", "=>", "10", ",", "'service-code'", "=>", "$", "parcel", "[", "'service_code'", "]", ",", "'receiver'", "=>", "$", "receiver", ",", "'settlement-info'", "=>", "[", "'contract-id'", "=>", "$", "this", "->", "contractId", ",", "]", ",", "]", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'option_codes'", "]", ")", ")", "{", "$", "return_info", "[", "'options'", "]", "[", "'option'", "]", "=", "$", "this", "->", "parseOptionCodes", "(", "$", "options", ")", ";", "}", "$", "xml", "=", "Array2XML", "::", "createXML", "(", "'open-return'", ",", "$", "content", ")", ";", "$", "envelope", "=", "$", "xml", "->", "documentElement", ";", "$", "envelope", "->", "setAttribute", "(", "'xmlns'", ",", "'http://www.canadapost.ca/ws/openreturn-v2'", ")", ";", "$", "payload", "=", "$", "xml", "->", "saveXML", "(", ")", ";", "$", "response", "=", "$", "this", "->", "post", "(", "\"rs/{$this->customerNumber}/{$this->customerNumber}/openreturn\"", ",", "[", "'Accept'", "=>", "'application/vnd.cpc.openreturn-v2+xml'", ",", "'Content-Type'", "=>", "'application/vnd.cpc.openreturn-v2+xml'", ",", "]", ",", "$", "payload", ",", "$", "options", ")", ";", "return", "$", "response", ";", "}" ]
Create an open return. @param array $receiver The receiver info. <code> $receiver = [ 'name' => 'John Smith', 'company' => 'Acro Media', 'domestic-address' => [ 'address-line-1' => '123 Main St', 'city' => 'Kelowna', 'province' => 'BC', 'postal-code' => 'V1X 1M2', ], ] </code> @param array $parcel The parcel characteristics. <code> $parcel = [ 'weight' => 0.500, // in kg. 'dimensions' => [ // in cm. 'length' => 30, 'width' => 10, 'height' => 20, ], ], ] </code> @param array $options The options array. @return \DOMDocument @throws \GuzzleHttp\Exception\GuzzleException
[ "Create", "an", "open", "return", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Returns.php#L133-L169
31,157
thejacer87/php-canadapost-api
src/Returns.php
Returns.getAllOpenReturns
public function getAllOpenReturns($from, $to = '', array $options = []) { if (empty($to)) { $to = date('YmdHs'); } $query_params = "from={$from}&to{$to}"; $this->verifyDates($from, $to); $response = $this->get( "rs/{$this->config['customer_number']}/{$this->config['customer_number']}/openreturn?{$query_params}", [ 'Accept' => 'application/vnd.cpc.openreturn+xml', 'Content-Type' => 'application/vnd.cpc.openreturn+xml', ], $options ); return $response; }
php
public function getAllOpenReturns($from, $to = '', array $options = []) { if (empty($to)) { $to = date('YmdHs'); } $query_params = "from={$from}&to{$to}"; $this->verifyDates($from, $to); $response = $this->get( "rs/{$this->config['customer_number']}/{$this->config['customer_number']}/openreturn?{$query_params}", [ 'Accept' => 'application/vnd.cpc.openreturn+xml', 'Content-Type' => 'application/vnd.cpc.openreturn+xml', ], $options ); return $response; }
[ "public", "function", "getAllOpenReturns", "(", "$", "from", ",", "$", "to", "=", "''", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "to", ")", ")", "{", "$", "to", "=", "date", "(", "'YmdHs'", ")", ";", "}", "$", "query_params", "=", "\"from={$from}&to{$to}\"", ";", "$", "this", "->", "verifyDates", "(", "$", "from", ",", "$", "to", ")", ";", "$", "response", "=", "$", "this", "->", "get", "(", "\"rs/{$this->config['customer_number']}/{$this->config['customer_number']}/openreturn?{$query_params}\"", ",", "[", "'Accept'", "=>", "'application/vnd.cpc.openreturn+xml'", ",", "'Content-Type'", "=>", "'application/vnd.cpc.openreturn+xml'", ",", "]", ",", "$", "options", ")", ";", "return", "$", "response", ";", "}" ]
Get next open return artifact. @param string $from The beginning range. YmdHs format, eg. 201808282359. @param string $to The end range, defaults to current time. YmdHs format, eg. 201808282359. @param array $options The options array. @return \DOMDocument|\Psr\Http\Message\StreamInterface @throws \GuzzleHttp\Exception\GuzzleException
[ "Get", "next", "open", "return", "artifact", "." ]
1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a
https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Returns.php#L242-L260
31,158
pulsarvp/vps-tools
src/auth/PulsarSsoClient.php
PulsarSsoClient.getLogoutUrl
public function getLogoutUrl ($redirectTo = null) { if (empty($redirectTo)) return $this->_logoutUrl; else return $this->_logoutUrl . '?next=' . urlencode($redirectTo); }
php
public function getLogoutUrl ($redirectTo = null) { if (empty($redirectTo)) return $this->_logoutUrl; else return $this->_logoutUrl . '?next=' . urlencode($redirectTo); }
[ "public", "function", "getLogoutUrl", "(", "$", "redirectTo", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "redirectTo", ")", ")", "return", "$", "this", "->", "_logoutUrl", ";", "else", "return", "$", "this", "->", "_logoutUrl", ".", "'?next='", ".", "urlencode", "(", "$", "redirectTo", ")", ";", "}" ]
Creates logout URL. @param string $redirectTo @return string
[ "Creates", "logout", "URL", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/auth/PulsarSsoClient.php#L36-L42
31,159
Bokbasen/php-api-client
src/ApiClient/Client.php
Client.patch
public function patch(string $path, $body, array $headers = [], bool $authenticate = true): ResponseInterface { return $this->call( HttpRequestOptions::HTTP_METHOD_PATCH, $path, $headers, $body, $authenticate ); }
php
public function patch(string $path, $body, array $headers = [], bool $authenticate = true): ResponseInterface { return $this->call( HttpRequestOptions::HTTP_METHOD_PATCH, $path, $headers, $body, $authenticate ); }
[ "public", "function", "patch", "(", "string", "$", "path", ",", "$", "body", ",", "array", "$", "headers", "=", "[", "]", ",", "bool", "$", "authenticate", "=", "true", ")", ":", "ResponseInterface", "{", "return", "$", "this", "->", "call", "(", "HttpRequestOptions", "::", "HTTP_METHOD_PATCH", ",", "$", "path", ",", "$", "headers", ",", "$", "body", ",", "$", "authenticate", ")", ";", "}" ]
Execute PATCH request @param string $path @param resource|string|StreamInterface|null $body @param array $headers @param bool $authenticate @return ResponseInterface @throws BokbasenApiClientException
[ "Execute", "PATCH", "request" ]
eeb33aa48b90d5043545d1af993167e9a74995df
https://github.com/Bokbasen/php-api-client/blob/eeb33aa48b90d5043545d1af993167e9a74995df/src/ApiClient/Client.php#L172-L181
31,160
Bokbasen/php-api-client
src/ApiClient/Client.php
Client.postJson
public function postJson(string $path, array $body): ResponseInterface { $body = json_encode($body); if ($body === false) { throw new BokbasenApiClientException('Unable to convert data to json'); } return $this->post( $path, $body, [ 'Content-Type' => HttpRequestOptions::CONTENT_TYPE_JSON, ] ); }
php
public function postJson(string $path, array $body): ResponseInterface { $body = json_encode($body); if ($body === false) { throw new BokbasenApiClientException('Unable to convert data to json'); } return $this->post( $path, $body, [ 'Content-Type' => HttpRequestOptions::CONTENT_TYPE_JSON, ] ); }
[ "public", "function", "postJson", "(", "string", "$", "path", ",", "array", "$", "body", ")", ":", "ResponseInterface", "{", "$", "body", "=", "json_encode", "(", "$", "body", ")", ";", "if", "(", "$", "body", "===", "false", ")", "{", "throw", "new", "BokbasenApiClientException", "(", "'Unable to convert data to json'", ")", ";", "}", "return", "$", "this", "->", "post", "(", "$", "path", ",", "$", "body", ",", "[", "'Content-Type'", "=>", "HttpRequestOptions", "::", "CONTENT_TYPE_JSON", ",", "]", ")", ";", "}" ]
Special endpoint for posting json, sets correct content type header and encodes data as json @param string $path @param array $body @return ResponseInterface @throws BokbasenApiClientException
[ "Special", "endpoint", "for", "posting", "json", "sets", "correct", "content", "type", "header", "and", "encodes", "data", "as", "json" ]
eeb33aa48b90d5043545d1af993167e9a74995df
https://github.com/Bokbasen/php-api-client/blob/eeb33aa48b90d5043545d1af993167e9a74995df/src/ApiClient/Client.php#L193-L208
31,161
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.init
public function init () { $class = $this->_modelClass; $this->_root = $class::find()->roots()->one(); if ($this->_root == null) { $root = new $class([ 'guid' => 'root', 'title' => 'ROOT' ]); $root->makeRoot(); $this->_root = $class::find()->roots()->one(); $this->_data = []; } else $this->_data = $this->_root->children()->all(); $this->buildPaths(); }
php
public function init () { $class = $this->_modelClass; $this->_root = $class::find()->roots()->one(); if ($this->_root == null) { $root = new $class([ 'guid' => 'root', 'title' => 'ROOT' ]); $root->makeRoot(); $this->_root = $class::find()->roots()->one(); $this->_data = []; } else $this->_data = $this->_root->children()->all(); $this->buildPaths(); }
[ "public", "function", "init", "(", ")", "{", "$", "class", "=", "$", "this", "->", "_modelClass", ";", "$", "this", "->", "_root", "=", "$", "class", "::", "find", "(", ")", "->", "roots", "(", ")", "->", "one", "(", ")", ";", "if", "(", "$", "this", "->", "_root", "==", "null", ")", "{", "$", "root", "=", "new", "$", "class", "(", "[", "'guid'", "=>", "'root'", ",", "'title'", "=>", "'ROOT'", "]", ")", ";", "$", "root", "->", "makeRoot", "(", ")", ";", "$", "this", "->", "_root", "=", "$", "class", "::", "find", "(", ")", "->", "roots", "(", ")", "->", "one", "(", ")", ";", "$", "this", "->", "_data", "=", "[", "]", ";", "}", "else", "$", "this", "->", "_data", "=", "$", "this", "->", "_root", "->", "children", "(", ")", "->", "all", "(", ")", ";", "$", "this", "->", "buildPaths", "(", ")", ";", "}" ]
Populates category tree with data loaded from database. @inheritdoc
[ "Populates", "category", "tree", "with", "data", "loaded", "from", "database", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L48-L65
31,162
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.getChildren
public function getChildren ($category) { $children = []; foreach ($this->_data as $item) if ($item->lft > $category->lft and $item->rgt < $category->rgt) $children[] = $item; return $children; }
php
public function getChildren ($category) { $children = []; foreach ($this->_data as $item) if ($item->lft > $category->lft and $item->rgt < $category->rgt) $children[] = $item; return $children; }
[ "public", "function", "getChildren", "(", "$", "category", ")", "{", "$", "children", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_data", "as", "$", "item", ")", "if", "(", "$", "item", "->", "lft", ">", "$", "category", "->", "lft", "and", "$", "item", "->", "rgt", "<", "$", "category", "->", "rgt", ")", "$", "children", "[", "]", "=", "$", "item", ";", "return", "$", "children", ";", "}" ]
Gets children of current category. @param Category $category @return array
[ "Gets", "children", "of", "current", "category", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L81-L89
31,163
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.getParent
public function getParent ($category, $depth = 1) { if ($category instanceof $this->_modelClass and $depth > 0) { if ($category->depth == $depth) return $category; foreach ($this->_data as $item) if ($category->lft > $item->lft and $category->rgt < $item->rgt and $item->depth == $depth) return $item; } return null; }
php
public function getParent ($category, $depth = 1) { if ($category instanceof $this->_modelClass and $depth > 0) { if ($category->depth == $depth) return $category; foreach ($this->_data as $item) if ($category->lft > $item->lft and $category->rgt < $item->rgt and $item->depth == $depth) return $item; } return null; }
[ "public", "function", "getParent", "(", "$", "category", ",", "$", "depth", "=", "1", ")", "{", "if", "(", "$", "category", "instanceof", "$", "this", "->", "_modelClass", "and", "$", "depth", ">", "0", ")", "{", "if", "(", "$", "category", "->", "depth", "==", "$", "depth", ")", "return", "$", "category", ";", "foreach", "(", "$", "this", "->", "_data", "as", "$", "item", ")", "if", "(", "$", "category", "->", "lft", ">", "$", "item", "->", "lft", "and", "$", "category", "->", "rgt", "<", "$", "item", "->", "rgt", "and", "$", "item", "->", "depth", "==", "$", "depth", ")", "return", "$", "item", ";", "}", "return", "null", ";", "}" ]
Finds category parent with given depth. @param Category $category @param int $depth @return Category|null
[ "Finds", "category", "parent", "with", "given", "depth", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L97-L109
31,164
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.getParents
public function getParents ($category) { if ($category instanceof $this->_modelClass) { $parents = []; foreach ($this->_data as $item) if ($category->lft > $item->lft and $category->rgt < $item->rgt) $parents[] = $item; return $parents; } return null; }
php
public function getParents ($category) { if ($category instanceof $this->_modelClass) { $parents = []; foreach ($this->_data as $item) if ($category->lft > $item->lft and $category->rgt < $item->rgt) $parents[] = $item; return $parents; } return null; }
[ "public", "function", "getParents", "(", "$", "category", ")", "{", "if", "(", "$", "category", "instanceof", "$", "this", "->", "_modelClass", ")", "{", "$", "parents", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_data", "as", "$", "item", ")", "if", "(", "$", "category", "->", "lft", ">", "$", "item", "->", "lft", "and", "$", "category", "->", "rgt", "<", "$", "item", "->", "rgt", ")", "$", "parents", "[", "]", "=", "$", "item", ";", "return", "$", "parents", ";", "}", "return", "null", ";", "}" ]
Finds all parents from top one to nearest. @param Category $category @return Category[]|null
[ "Finds", "all", "parents", "from", "top", "one", "to", "nearest", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L116-L129
31,165
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.get
public function get ($id) { foreach ($this->_data as $category) if ($category->id == $id) return $category; return null; }
php
public function get ($id) { foreach ($this->_data as $category) if ($category->id == $id) return $category; return null; }
[ "public", "function", "get", "(", "$", "id", ")", "{", "foreach", "(", "$", "this", "->", "_data", "as", "$", "category", ")", "if", "(", "$", "category", "->", "id", "==", "$", "id", ")", "return", "$", "category", ";", "return", "null", ";", "}" ]
Gets single category by its ID. @param integer $id @return Category|null
[ "Gets", "single", "category", "by", "its", "ID", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L145-L152
31,166
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.getByGuidPath
public function getByGuidPath ($guidPath) { foreach ($this->_data as $category) if ($category->guidPath === $guidPath) return $category; return null; }
php
public function getByGuidPath ($guidPath) { foreach ($this->_data as $category) if ($category->guidPath === $guidPath) return $category; return null; }
[ "public", "function", "getByGuidPath", "(", "$", "guidPath", ")", "{", "foreach", "(", "$", "this", "->", "_data", "as", "$", "category", ")", "if", "(", "$", "category", "->", "guidPath", "===", "$", "guidPath", ")", "return", "$", "category", ";", "return", "null", ";", "}" ]
Gets single category by its GUID path. @param string $guidPath @return Category|null
[ "Gets", "single", "category", "by", "its", "GUID", "path", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L159-L166
31,167
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.exists
public function exists ($id) { foreach ($this->_data as $category) if ($category->id == $id) return true; return false; }
php
public function exists ($id) { foreach ($this->_data as $category) if ($category->id == $id) return true; return false; }
[ "public", "function", "exists", "(", "$", "id", ")", "{", "foreach", "(", "$", "this", "->", "_data", "as", "$", "category", ")", "if", "(", "$", "category", "->", "id", "==", "$", "id", ")", "return", "true", ";", "return", "false", ";", "}" ]
Checks if category exists. @param integer $id Category ID. @return bool
[ "Checks", "if", "category", "exists", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L185-L192
31,168
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.reload
public function reload () { $class = $this->_modelClass; $this->_root = $class::find()->roots()->one(); $this->_data = $this->_root->children()->all(); $this->buildPaths(); }
php
public function reload () { $class = $this->_modelClass; $this->_root = $class::find()->roots()->one(); $this->_data = $this->_root->children()->all(); $this->buildPaths(); }
[ "public", "function", "reload", "(", ")", "{", "$", "class", "=", "$", "this", "->", "_modelClass", ";", "$", "this", "->", "_root", "=", "$", "class", "::", "find", "(", ")", "->", "roots", "(", ")", "->", "one", "(", ")", ";", "$", "this", "->", "_data", "=", "$", "this", "->", "_root", "->", "children", "(", ")", "->", "all", "(", ")", ";", "$", "this", "->", "buildPaths", "(", ")", ";", "}" ]
Reloads data from database.
[ "Reloads", "data", "from", "database", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L197-L204
31,169
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.guidPath
public function guidPath ($id) { $category = $this->get($id); if ($category == null) return null; elseif (empty($category->guidPath)) $this->buildPaths(); return $category->guidPath; }
php
public function guidPath ($id) { $category = $this->get($id); if ($category == null) return null; elseif (empty($category->guidPath)) $this->buildPaths(); return $category->guidPath; }
[ "public", "function", "guidPath", "(", "$", "id", ")", "{", "$", "category", "=", "$", "this", "->", "get", "(", "$", "id", ")", ";", "if", "(", "$", "category", "==", "null", ")", "return", "null", ";", "elseif", "(", "empty", "(", "$", "category", "->", "guidPath", ")", ")", "$", "this", "->", "buildPaths", "(", ")", ";", "return", "$", "category", "->", "guidPath", ";", "}" ]
Finds category GUID path by given ID. @param integer $id @return null|string
[ "Finds", "category", "GUID", "path", "by", "given", "ID", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L211-L221
31,170
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.titlePath
public function titlePath ($id) { $category = $this->get($id); if ($category == null) return null; elseif (empty($category->titlePath)) $this->buildPaths(); return $category->titlePath; }
php
public function titlePath ($id) { $category = $this->get($id); if ($category == null) return null; elseif (empty($category->titlePath)) $this->buildPaths(); return $category->titlePath; }
[ "public", "function", "titlePath", "(", "$", "id", ")", "{", "$", "category", "=", "$", "this", "->", "get", "(", "$", "id", ")", ";", "if", "(", "$", "category", "==", "null", ")", "return", "null", ";", "elseif", "(", "empty", "(", "$", "category", "->", "titlePath", ")", ")", "$", "this", "->", "buildPaths", "(", ")", ";", "return", "$", "category", "->", "titlePath", ";", "}" ]
Finds category title path by given ID. @param integer $id @return null|string
[ "Finds", "category", "title", "path", "by", "given", "ID", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L228-L238
31,171
pulsarvp/vps-tools
src/components/CategoryManager.php
CategoryManager.buildPaths
protected function buildPaths () { $titles = []; $guids = []; $n = count($this->_data); for ($i = 0; $i < $n; $i++) { $parent = $this->_data[ $i ]; for ($j = $i + 1; $j < $n; $j++) { $child = $this->_data[ $j ]; if ($child->lft > $parent->lft and $child->rgt < $parent->rgt) { $titles[ $child->id ][] = $parent->title; $guids[ $child->id ][] = $parent->guid; } } $titles[ $parent->id ][] = $parent->title; $guids[ $parent->id ][] = $parent->guid; $parent->titlePath = implode($this->_titlePathDelimiter, $titles[ $parent->id ]); $parent->guidPath = implode($this->_guidPathDelimiter, $guids[ $parent->id ]); } }
php
protected function buildPaths () { $titles = []; $guids = []; $n = count($this->_data); for ($i = 0; $i < $n; $i++) { $parent = $this->_data[ $i ]; for ($j = $i + 1; $j < $n; $j++) { $child = $this->_data[ $j ]; if ($child->lft > $parent->lft and $child->rgt < $parent->rgt) { $titles[ $child->id ][] = $parent->title; $guids[ $child->id ][] = $parent->guid; } } $titles[ $parent->id ][] = $parent->title; $guids[ $parent->id ][] = $parent->guid; $parent->titlePath = implode($this->_titlePathDelimiter, $titles[ $parent->id ]); $parent->guidPath = implode($this->_guidPathDelimiter, $guids[ $parent->id ]); } }
[ "protected", "function", "buildPaths", "(", ")", "{", "$", "titles", "=", "[", "]", ";", "$", "guids", "=", "[", "]", ";", "$", "n", "=", "count", "(", "$", "this", "->", "_data", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "n", ";", "$", "i", "++", ")", "{", "$", "parent", "=", "$", "this", "->", "_data", "[", "$", "i", "]", ";", "for", "(", "$", "j", "=", "$", "i", "+", "1", ";", "$", "j", "<", "$", "n", ";", "$", "j", "++", ")", "{", "$", "child", "=", "$", "this", "->", "_data", "[", "$", "j", "]", ";", "if", "(", "$", "child", "->", "lft", ">", "$", "parent", "->", "lft", "and", "$", "child", "->", "rgt", "<", "$", "parent", "->", "rgt", ")", "{", "$", "titles", "[", "$", "child", "->", "id", "]", "[", "]", "=", "$", "parent", "->", "title", ";", "$", "guids", "[", "$", "child", "->", "id", "]", "[", "]", "=", "$", "parent", "->", "guid", ";", "}", "}", "$", "titles", "[", "$", "parent", "->", "id", "]", "[", "]", "=", "$", "parent", "->", "title", ";", "$", "guids", "[", "$", "parent", "->", "id", "]", "[", "]", "=", "$", "parent", "->", "guid", ";", "$", "parent", "->", "titlePath", "=", "implode", "(", "$", "this", "->", "_titlePathDelimiter", ",", "$", "titles", "[", "$", "parent", "->", "id", "]", ")", ";", "$", "parent", "->", "guidPath", "=", "implode", "(", "$", "this", "->", "_guidPathDelimiter", ",", "$", "guids", "[", "$", "parent", "->", "id", "]", ")", ";", "}", "}" ]
Builds full title and GUID paths for all categories.
[ "Builds", "full", "title", "and", "GUID", "paths", "for", "all", "categories", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L243-L267
31,172
shimabox/SMBArrayto
src/SMB/Arrayto/Plugins/Csv/Downloader.php
Downloader.downloadExistsFile
public function downloadExistsFile($fileName, $aliasOfFileName = '') { $baseFileName = $aliasOfFileName === '' ? basename($fileName) : $aliasOfFileName; header("Content-Type: text/csv; charset={$this->getHeaderCharset()}"); header("Content-Disposition: attachment; filename={$baseFileName}"); readfile($fileName); }
php
public function downloadExistsFile($fileName, $aliasOfFileName = '') { $baseFileName = $aliasOfFileName === '' ? basename($fileName) : $aliasOfFileName; header("Content-Type: text/csv; charset={$this->getHeaderCharset()}"); header("Content-Disposition: attachment; filename={$baseFileName}"); readfile($fileName); }
[ "public", "function", "downloadExistsFile", "(", "$", "fileName", ",", "$", "aliasOfFileName", "=", "''", ")", "{", "$", "baseFileName", "=", "$", "aliasOfFileName", "===", "''", "?", "basename", "(", "$", "fileName", ")", ":", "$", "aliasOfFileName", ";", "header", "(", "\"Content-Type: text/csv; charset={$this->getHeaderCharset()}\"", ")", ";", "header", "(", "\"Content-Disposition: attachment; filename={$baseFileName}\"", ")", ";", "readfile", "(", "$", "fileName", ")", ";", "}" ]
download an existing file @param string $fileName e.g.) sample.xxx | ../sample.xxx | /path/to/sample.xxx @param string $aliasOfFileName
[ "download", "an", "existing", "file" ]
7ecacc0c15994c02224bbd3efe055d3bce243971
https://github.com/shimabox/SMBArrayto/blob/7ecacc0c15994c02224bbd3efe055d3bce243971/src/SMB/Arrayto/Plugins/Csv/Downloader.php#L40-L48
31,173
shimabox/SMBArrayto
src/SMB/Arrayto/Plugins/Csv/Downloader.php
Downloader.downloadExistsFileUsingWriter
public function downloadExistsFileUsingWriter($fileName, Writable $writer) { header("Content-Type: text/csv; charset={$this->getHeaderCharset()}"); header("Content-Disposition: attachment; filename={$fileName}"); $writer->write(); readfile($writer->getFileName()); }
php
public function downloadExistsFileUsingWriter($fileName, Writable $writer) { header("Content-Type: text/csv; charset={$this->getHeaderCharset()}"); header("Content-Disposition: attachment; filename={$fileName}"); $writer->write(); readfile($writer->getFileName()); }
[ "public", "function", "downloadExistsFileUsingWriter", "(", "$", "fileName", ",", "Writable", "$", "writer", ")", "{", "header", "(", "\"Content-Type: text/csv; charset={$this->getHeaderCharset()}\"", ")", ";", "header", "(", "\"Content-Disposition: attachment; filename={$fileName}\"", ")", ";", "$", "writer", "->", "write", "(", ")", ";", "readfile", "(", "$", "writer", "->", "getFileName", "(", ")", ")", ";", "}" ]
download an existing file using Writer @param string $fileName @param \SMB\Arrayto\Interfaces\Writable $writer
[ "download", "an", "existing", "file", "using", "Writer" ]
7ecacc0c15994c02224bbd3efe055d3bce243971
https://github.com/shimabox/SMBArrayto/blob/7ecacc0c15994c02224bbd3efe055d3bce243971/src/SMB/Arrayto/Plugins/Csv/Downloader.php#L55-L62
31,174
pulsarvp/vps-tools
src/modules/setting/models/Setting.php
Setting.validateCommand
public function validateCommand ($attribute) { if (!$this->hasErrors()) { $return_var1 = $return_var2 = $return_var3 = 0; exec('command -v ' . $this->$attribute . '', $output, $return_var); if ($return_var == 127) $this->addError($attribute, Yii::tr('Command not found.', [], 'setting')); } }
php
public function validateCommand ($attribute) { if (!$this->hasErrors()) { $return_var1 = $return_var2 = $return_var3 = 0; exec('command -v ' . $this->$attribute . '', $output, $return_var); if ($return_var == 127) $this->addError($attribute, Yii::tr('Command not found.', [], 'setting')); } }
[ "public", "function", "validateCommand", "(", "$", "attribute", ")", "{", "if", "(", "!", "$", "this", "->", "hasErrors", "(", ")", ")", "{", "$", "return_var1", "=", "$", "return_var2", "=", "$", "return_var3", "=", "0", ";", "exec", "(", "'command -v '", ".", "$", "this", "->", "$", "attribute", ".", "''", ",", "$", "output", ",", "$", "return_var", ")", ";", "if", "(", "$", "return_var", "==", "127", ")", "$", "this", "->", "addError", "(", "$", "attribute", ",", "Yii", "::", "tr", "(", "'Command not found.'", ",", "[", "]", ",", "'setting'", ")", ")", ";", "}", "}" ]
Command validates. @param string $attribute the attribute currently being validated
[ "Command", "validates", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/models/Setting.php#L139-L148
31,175
pulsarvp/vps-tools
src/modules/setting/models/Setting.php
Setting.validateJson
public function validateJson ($attribute) { if (!$this->hasErrors()) { if (!( is_string($this->$attribute) && is_array(json_decode($this->$attribute, true)) && ( json_last_error() == JSON_ERROR_NONE ) )) $this->addError($attribute, Yii::tr('This field must be well-formed JSON.', [], 'setting')); } }
php
public function validateJson ($attribute) { if (!$this->hasErrors()) { if (!( is_string($this->$attribute) && is_array(json_decode($this->$attribute, true)) && ( json_last_error() == JSON_ERROR_NONE ) )) $this->addError($attribute, Yii::tr('This field must be well-formed JSON.', [], 'setting')); } }
[ "public", "function", "validateJson", "(", "$", "attribute", ")", "{", "if", "(", "!", "$", "this", "->", "hasErrors", "(", ")", ")", "{", "if", "(", "!", "(", "is_string", "(", "$", "this", "->", "$", "attribute", ")", "&&", "is_array", "(", "json_decode", "(", "$", "this", "->", "$", "attribute", ",", "true", ")", ")", "&&", "(", "json_last_error", "(", ")", "==", "JSON_ERROR_NONE", ")", ")", ")", "$", "this", "->", "addError", "(", "$", "attribute", ",", "Yii", "::", "tr", "(", "'This field must be well-formed JSON.'", ",", "[", "]", ",", "'setting'", ")", ")", ";", "}", "}" ]
Json validates. @param string $attribute the attribute currently being validated
[ "Json", "validates", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/models/Setting.php#L155-L162
31,176
pulsarvp/vps-tools
src/modules/setting/models/Setting.php
Setting.validateUrl
public function validateUrl ($attribute) { if (!$this->hasErrors()) { if (filter_var($this->$attribute, FILTER_VALIDATE_URL) === false) $this->addError($attribute, Yii::tr('{attribute} is not a valid URL.', [ 'attribute' => $this->name ], 'setting')); } }
php
public function validateUrl ($attribute) { if (!$this->hasErrors()) { if (filter_var($this->$attribute, FILTER_VALIDATE_URL) === false) $this->addError($attribute, Yii::tr('{attribute} is not a valid URL.', [ 'attribute' => $this->name ], 'setting')); } }
[ "public", "function", "validateUrl", "(", "$", "attribute", ")", "{", "if", "(", "!", "$", "this", "->", "hasErrors", "(", ")", ")", "{", "if", "(", "filter_var", "(", "$", "this", "->", "$", "attribute", ",", "FILTER_VALIDATE_URL", ")", "===", "false", ")", "$", "this", "->", "addError", "(", "$", "attribute", ",", "Yii", "::", "tr", "(", "'{attribute} is not a valid URL.'", ",", "[", "'attribute'", "=>", "$", "this", "->", "name", "]", ",", "'setting'", ")", ")", ";", "}", "}" ]
Url validates. @param string $attribute the attribute currently being validated
[ "Url", "validates", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/models/Setting.php#L169-L176
31,177
pulsarvp/vps-tools
src/modules/setting/models/Setting.php
Setting.validatePath
public function validatePath ($attribute) { if (!$this->hasErrors()) { if (!file_exists($this->$attribute)) $this->addError($attribute, Yii::tr('{attribute} does not exist.', [ 'attribute' => $attribute ], 'setting')); if ($this->rule != '') { $rule = json_decode($this->rule, true); if (isset($rule[ 'writable' ]) and $rule[ 'writable' ] == true) { if (!is_writable($this->$attribute)) $this->addError($attribute, Yii::tr('Path is not writable.', [], 'setting')); } } } }
php
public function validatePath ($attribute) { if (!$this->hasErrors()) { if (!file_exists($this->$attribute)) $this->addError($attribute, Yii::tr('{attribute} does not exist.', [ 'attribute' => $attribute ], 'setting')); if ($this->rule != '') { $rule = json_decode($this->rule, true); if (isset($rule[ 'writable' ]) and $rule[ 'writable' ] == true) { if (!is_writable($this->$attribute)) $this->addError($attribute, Yii::tr('Path is not writable.', [], 'setting')); } } } }
[ "public", "function", "validatePath", "(", "$", "attribute", ")", "{", "if", "(", "!", "$", "this", "->", "hasErrors", "(", ")", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "$", "attribute", ")", ")", "$", "this", "->", "addError", "(", "$", "attribute", ",", "Yii", "::", "tr", "(", "'{attribute} does not exist.'", ",", "[", "'attribute'", "=>", "$", "attribute", "]", ",", "'setting'", ")", ")", ";", "if", "(", "$", "this", "->", "rule", "!=", "''", ")", "{", "$", "rule", "=", "json_decode", "(", "$", "this", "->", "rule", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "rule", "[", "'writable'", "]", ")", "and", "$", "rule", "[", "'writable'", "]", "==", "true", ")", "{", "if", "(", "!", "is_writable", "(", "$", "this", "->", "$", "attribute", ")", ")", "$", "this", "->", "addError", "(", "$", "attribute", ",", "Yii", "::", "tr", "(", "'Path is not writable.'", ",", "[", "]", ",", "'setting'", ")", ")", ";", "}", "}", "}", "}" ]
Path validates. @param string $attribute the attribute currently being validated
[ "Path", "validates", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/models/Setting.php#L183-L199
31,178
pulsarvp/vps-tools
src/base/BaseOrderModel.php
BaseOrderModel.beforeSave
public function beforeSave ($insert) { if ($parent = parent::beforeSave($insert)) { if ($this->isNewRecord) { if ($this->hasAttribute('order') and empty($this->order)) { $query = self::find()->select('order')->orderBy([ 'order' => SORT_DESC ]); $condition = $this->orderCondition(); if ($condition !== null) { $query->where($condition); } $order = $query->scalar(); $this->order = !is_null($order) ? $order + 1 : 1; } } } return $parent; }
php
public function beforeSave ($insert) { if ($parent = parent::beforeSave($insert)) { if ($this->isNewRecord) { if ($this->hasAttribute('order') and empty($this->order)) { $query = self::find()->select('order')->orderBy([ 'order' => SORT_DESC ]); $condition = $this->orderCondition(); if ($condition !== null) { $query->where($condition); } $order = $query->scalar(); $this->order = !is_null($order) ? $order + 1 : 1; } } } return $parent; }
[ "public", "function", "beforeSave", "(", "$", "insert", ")", "{", "if", "(", "$", "parent", "=", "parent", "::", "beforeSave", "(", "$", "insert", ")", ")", "{", "if", "(", "$", "this", "->", "isNewRecord", ")", "{", "if", "(", "$", "this", "->", "hasAttribute", "(", "'order'", ")", "and", "empty", "(", "$", "this", "->", "order", ")", ")", "{", "$", "query", "=", "self", "::", "find", "(", ")", "->", "select", "(", "'order'", ")", "->", "orderBy", "(", "[", "'order'", "=>", "SORT_DESC", "]", ")", ";", "$", "condition", "=", "$", "this", "->", "orderCondition", "(", ")", ";", "if", "(", "$", "condition", "!==", "null", ")", "{", "$", "query", "->", "where", "(", "$", "condition", ")", ";", "}", "$", "order", "=", "$", "query", "->", "scalar", "(", ")", ";", "$", "this", "->", "order", "=", "!", "is_null", "(", "$", "order", ")", "?", "$", "order", "+", "1", ":", "1", ";", "}", "}", "}", "return", "$", "parent", ";", "}" ]
Looking for the biggest order in the table, and the current model doing +1. @param bool $insert @return bool
[ "Looking", "for", "the", "biggest", "order", "in", "the", "table", "and", "the", "current", "model", "doing", "+", "1", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/base/BaseOrderModel.php#L24-L48
31,179
pulsarvp/vps-tools
src/base/BaseOrderModel.php
BaseOrderModel.afterDelete
public function afterDelete () { $parent = parent::afterDelete(); if ($this->hasAttribute('order')) { $query = self::find()->where([ '>', 'order', $this->order ]); $condition = $this->orderCondition(); if ($condition !== null) { $query->andWhere($condition); } $objects = $query->all(); foreach ($objects as $object) { $object->order -= 1; $object->save(); } } return $parent; }
php
public function afterDelete () { $parent = parent::afterDelete(); if ($this->hasAttribute('order')) { $query = self::find()->where([ '>', 'order', $this->order ]); $condition = $this->orderCondition(); if ($condition !== null) { $query->andWhere($condition); } $objects = $query->all(); foreach ($objects as $object) { $object->order -= 1; $object->save(); } } return $parent; }
[ "public", "function", "afterDelete", "(", ")", "{", "$", "parent", "=", "parent", "::", "afterDelete", "(", ")", ";", "if", "(", "$", "this", "->", "hasAttribute", "(", "'order'", ")", ")", "{", "$", "query", "=", "self", "::", "find", "(", ")", "->", "where", "(", "[", "'>'", ",", "'order'", ",", "$", "this", "->", "order", "]", ")", ";", "$", "condition", "=", "$", "this", "->", "orderCondition", "(", ")", ";", "if", "(", "$", "condition", "!==", "null", ")", "{", "$", "query", "->", "andWhere", "(", "$", "condition", ")", ";", "}", "$", "objects", "=", "$", "query", "->", "all", "(", ")", ";", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "$", "object", "->", "order", "-=", "1", ";", "$", "object", "->", "save", "(", ")", ";", "}", "}", "return", "$", "parent", ";", "}" ]
Which order more than the remote model, do for order -1.
[ "Which", "order", "more", "than", "the", "remote", "model", "do", "for", "order", "-", "1", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/base/BaseOrderModel.php#L53-L76
31,180
pulsarvp/vps-tools
src/net/Curl.php
Curl.delete
public function delete ($data = null) { $this->_options[ CURLOPT_CUSTOMREQUEST ] = 'DELETE'; if ($data != null) $this->_options[ CURLOPT_POSTFIELDS ] = is_array($data) ? http_build_query($data) : $data; return $this->send(); }
php
public function delete ($data = null) { $this->_options[ CURLOPT_CUSTOMREQUEST ] = 'DELETE'; if ($data != null) $this->_options[ CURLOPT_POSTFIELDS ] = is_array($data) ? http_build_query($data) : $data; return $this->send(); }
[ "public", "function", "delete", "(", "$", "data", "=", "null", ")", "{", "$", "this", "->", "_options", "[", "CURLOPT_CUSTOMREQUEST", "]", "=", "'DELETE'", ";", "if", "(", "$", "data", "!=", "null", ")", "$", "this", "->", "_options", "[", "CURLOPT_POSTFIELDS", "]", "=", "is_array", "(", "$", "data", ")", "?", "http_build_query", "(", "$", "data", ")", ":", "$", "data", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}" ]
Sends DELETE request. @param null|array $data Additional data to append to request. @return string|CurlResponse
[ "Sends", "DELETE", "request", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Curl.php#L103-L110
31,181
pulsarvp/vps-tools
src/net/Curl.php
Curl.post
public function post ($data) { $this->_options[ CURLOPT_POST ] = 1; $this->_options[ CURLOPT_POSTFIELDS ] = is_array($data) ? http_build_query($data) : $data; return $this->send(); }
php
public function post ($data) { $this->_options[ CURLOPT_POST ] = 1; $this->_options[ CURLOPT_POSTFIELDS ] = is_array($data) ? http_build_query($data) : $data; return $this->send(); }
[ "public", "function", "post", "(", "$", "data", ")", "{", "$", "this", "->", "_options", "[", "CURLOPT_POST", "]", "=", "1", ";", "$", "this", "->", "_options", "[", "CURLOPT_POSTFIELDS", "]", "=", "is_array", "(", "$", "data", ")", "?", "http_build_query", "(", "$", "data", ")", ":", "$", "data", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}" ]
Sends POST request. @param array|string $data Additional data to append to request. @return string|CurlResponse
[ "Sends", "POST", "request", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Curl.php#L141-L147
31,182
pulsarvp/vps-tools
src/net/Curl.php
Curl.put
public function put ($data) { $this->_options[ CURLOPT_CUSTOMREQUEST ] = 'PUT'; $this->_options[ CURLOPT_POSTFIELDS ] = http_build_query($data); return $this->send(); }
php
public function put ($data) { $this->_options[ CURLOPT_CUSTOMREQUEST ] = 'PUT'; $this->_options[ CURLOPT_POSTFIELDS ] = http_build_query($data); return $this->send(); }
[ "public", "function", "put", "(", "$", "data", ")", "{", "$", "this", "->", "_options", "[", "CURLOPT_CUSTOMREQUEST", "]", "=", "'PUT'", ";", "$", "this", "->", "_options", "[", "CURLOPT_POSTFIELDS", "]", "=", "http_build_query", "(", "$", "data", ")", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}" ]
Sends PUT request. @param null|array $data Additional data to append to request. @return string|CurlResponse
[ "Sends", "PUT", "request", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Curl.php#L155-L161
31,183
pulsarvp/vps-tools
src/net/Curl.php
Curl.send
private function send () { if (count($this->_params) > 0) $this->_options[ CURLOPT_URL ] .= '?' . http_build_query($this->_params); if (count($this->_headers) > 0) $this->_options[ CURLOPT_HTTPHEADER ] = $this->_headers; $curl = curl_init(); curl_setopt_array($curl, $this->_options); $resp = curl_exec($curl); if ($resp === false) { $this->_response = new CurlResponse([ 'status' => CurlResponse::S_SERVERERROR, 'body' => 'Error #' . curl_errno($curl) . ': ' . curl_error($curl) ]); } else { $this->_response = new CurlResponse; $this->_response->fromCurl($resp, $curl); } curl_close($curl); return $this->_response; }
php
private function send () { if (count($this->_params) > 0) $this->_options[ CURLOPT_URL ] .= '?' . http_build_query($this->_params); if (count($this->_headers) > 0) $this->_options[ CURLOPT_HTTPHEADER ] = $this->_headers; $curl = curl_init(); curl_setopt_array($curl, $this->_options); $resp = curl_exec($curl); if ($resp === false) { $this->_response = new CurlResponse([ 'status' => CurlResponse::S_SERVERERROR, 'body' => 'Error #' . curl_errno($curl) . ': ' . curl_error($curl) ]); } else { $this->_response = new CurlResponse; $this->_response->fromCurl($resp, $curl); } curl_close($curl); return $this->_response; }
[ "private", "function", "send", "(", ")", "{", "if", "(", "count", "(", "$", "this", "->", "_params", ")", ">", "0", ")", "$", "this", "->", "_options", "[", "CURLOPT_URL", "]", ".=", "'?'", ".", "http_build_query", "(", "$", "this", "->", "_params", ")", ";", "if", "(", "count", "(", "$", "this", "->", "_headers", ")", ">", "0", ")", "$", "this", "->", "_options", "[", "CURLOPT_HTTPHEADER", "]", "=", "$", "this", "->", "_headers", ";", "$", "curl", "=", "curl_init", "(", ")", ";", "curl_setopt_array", "(", "$", "curl", ",", "$", "this", "->", "_options", ")", ";", "$", "resp", "=", "curl_exec", "(", "$", "curl", ")", ";", "if", "(", "$", "resp", "===", "false", ")", "{", "$", "this", "->", "_response", "=", "new", "CurlResponse", "(", "[", "'status'", "=>", "CurlResponse", "::", "S_SERVERERROR", ",", "'body'", "=>", "'Error #'", ".", "curl_errno", "(", "$", "curl", ")", ".", "': '", ".", "curl_error", "(", "$", "curl", ")", "]", ")", ";", "}", "else", "{", "$", "this", "->", "_response", "=", "new", "CurlResponse", ";", "$", "this", "->", "_response", "->", "fromCurl", "(", "$", "resp", ",", "$", "curl", ")", ";", "}", "curl_close", "(", "$", "curl", ")", ";", "return", "$", "this", "->", "_response", ";", "}" ]
This is general send method to use in particular request send method. @return string|CurlResponse
[ "This", "is", "general", "send", "method", "to", "use", "in", "particular", "request", "send", "method", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Curl.php#L168-L196
31,184
cedx/yii2-mustache
lib/Helper.php
Helper.parseArguments
protected function parseArguments(string $text, string $defaultArgument, array $defaultValues = []): array { try { if (is_array($json = Json::decode($text))) return ArrayHelper::merge($defaultValues, $json); throw new InvalidArgumentException('The JSON string has an invalid format.'); } catch (InvalidArgumentException $e) { $defaultValues[$defaultArgument] = $text; return $defaultValues; } }
php
protected function parseArguments(string $text, string $defaultArgument, array $defaultValues = []): array { try { if (is_array($json = Json::decode($text))) return ArrayHelper::merge($defaultValues, $json); throw new InvalidArgumentException('The JSON string has an invalid format.'); } catch (InvalidArgumentException $e) { $defaultValues[$defaultArgument] = $text; return $defaultValues; } }
[ "protected", "function", "parseArguments", "(", "string", "$", "text", ",", "string", "$", "defaultArgument", ",", "array", "$", "defaultValues", "=", "[", "]", ")", ":", "array", "{", "try", "{", "if", "(", "is_array", "(", "$", "json", "=", "Json", "::", "decode", "(", "$", "text", ")", ")", ")", "return", "ArrayHelper", "::", "merge", "(", "$", "defaultValues", ",", "$", "json", ")", ";", "throw", "new", "InvalidArgumentException", "(", "'The JSON string has an invalid format.'", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "$", "defaultValues", "[", "$", "defaultArgument", "]", "=", "$", "text", ";", "return", "$", "defaultValues", ";", "}", "}" ]
Parses the arguments of a parameterized helper. Arguments can be specified as a single value, or as a string in JSON format. @param string $text The section content specifying the helper arguments. @param string $defaultArgument The name of the default argument. This is used when the section content provides a plain string instead of a JSON object. @param array $defaultValues The default values of arguments. These are used when the section content does not specify all arguments. @return array The parsed arguments as an associative array.
[ "Parses", "the", "arguments", "of", "a", "parameterized", "helper", ".", "Arguments", "can", "be", "specified", "as", "a", "single", "value", "or", "as", "a", "string", "in", "JSON", "format", "." ]
20c961e65e74a0bacbe992dd7fdb28319f58a919
https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/Helper.php#L41-L51
31,185
EmchBerger/cube-custom-fields-bundle
src/Entity/EntityCustomField.php
EntityCustomField.createStrRepresentation
public function createStrRepresentation() { $entity = $this->getEntityData(); if (is_array($entity) || $entity instanceof \ArrayAccess) { // for some reason, implode does not work directly on the entity traversable $strArr = array(); foreach ($entity as $e) { $strArr[] = $e->__toString(); } return implode("\x1E", $strArr); // ASCII "record separator" character } elseif ($entity) { return $entity->__toString(); } else { return ''; } }
php
public function createStrRepresentation() { $entity = $this->getEntityData(); if (is_array($entity) || $entity instanceof \ArrayAccess) { // for some reason, implode does not work directly on the entity traversable $strArr = array(); foreach ($entity as $e) { $strArr[] = $e->__toString(); } return implode("\x1E", $strArr); // ASCII "record separator" character } elseif ($entity) { return $entity->__toString(); } else { return ''; } }
[ "public", "function", "createStrRepresentation", "(", ")", "{", "$", "entity", "=", "$", "this", "->", "getEntityData", "(", ")", ";", "if", "(", "is_array", "(", "$", "entity", ")", "||", "$", "entity", "instanceof", "\\", "ArrayAccess", ")", "{", "// for some reason, implode does not work directly on the entity traversable", "$", "strArr", "=", "array", "(", ")", ";", "foreach", "(", "$", "entity", "as", "$", "e", ")", "{", "$", "strArr", "[", "]", "=", "$", "e", "->", "__toString", "(", ")", ";", "}", "return", "implode", "(", "\"\\x1E\"", ",", "$", "strArr", ")", ";", "// ASCII \"record separator\" character", "}", "elseif", "(", "$", "entity", ")", "{", "return", "$", "entity", "->", "__toString", "(", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Override the default string representation creator method @return string
[ "Override", "the", "default", "string", "representation", "creator", "method" ]
7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414
https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/EntityCustomField.php#L95-L110
31,186
EmchBerger/cube-custom-fields-bundle
src/Entity/EntityCustomField.php
EntityCustomField.createStrRepresentationOnFlush
public function createStrRepresentationOnFlush($flushEntity) { $entity = $this->getEntityData(); if (is_array($entity) || $entity instanceof \ArrayAccess) { $entityArr = array(); foreach ($entity as $elem) { $entityArr[] = $this->getEntityOnFlush($elem, $flushEntity); } return implode("\x1E", $entityArr); // ASCII "record separator" character } elseif ($entity) { return $this->getEntityOnFlush($entity, $flushEntity)->__toString(); } else { return ''; } }
php
public function createStrRepresentationOnFlush($flushEntity) { $entity = $this->getEntityData(); if (is_array($entity) || $entity instanceof \ArrayAccess) { $entityArr = array(); foreach ($entity as $elem) { $entityArr[] = $this->getEntityOnFlush($elem, $flushEntity); } return implode("\x1E", $entityArr); // ASCII "record separator" character } elseif ($entity) { return $this->getEntityOnFlush($entity, $flushEntity)->__toString(); } else { return ''; } }
[ "public", "function", "createStrRepresentationOnFlush", "(", "$", "flushEntity", ")", "{", "$", "entity", "=", "$", "this", "->", "getEntityData", "(", ")", ";", "if", "(", "is_array", "(", "$", "entity", ")", "||", "$", "entity", "instanceof", "\\", "ArrayAccess", ")", "{", "$", "entityArr", "=", "array", "(", ")", ";", "foreach", "(", "$", "entity", "as", "$", "elem", ")", "{", "$", "entityArr", "[", "]", "=", "$", "this", "->", "getEntityOnFlush", "(", "$", "elem", ",", "$", "flushEntity", ")", ";", "}", "return", "implode", "(", "\"\\x1E\"", ",", "$", "entityArr", ")", ";", "// ASCII \"record separator\" character", "}", "elseif", "(", "$", "entity", ")", "{", "return", "$", "this", "->", "getEntityOnFlush", "(", "$", "entity", ",", "$", "flushEntity", ")", "->", "__toString", "(", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Override the default string representation creator method for the onFlush event @return string
[ "Override", "the", "default", "string", "representation", "creator", "method", "for", "the", "onFlush", "event" ]
7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414
https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/EntityCustomField.php#L117-L131
31,187
EmchBerger/cube-custom-fields-bundle
src/Entity/EntityCustomField.php
EntityCustomField.getEntityOnFlush
private function getEntityOnFlush($entity, $flushEntity) { if (ClassUtils::getClass($entity) == ClassUtils::getClass($flushEntity) && $entity->getId() === $flushEntity->getId()) { return $flushEntity; } else { return $entity; } }
php
private function getEntityOnFlush($entity, $flushEntity) { if (ClassUtils::getClass($entity) == ClassUtils::getClass($flushEntity) && $entity->getId() === $flushEntity->getId()) { return $flushEntity; } else { return $entity; } }
[ "private", "function", "getEntityOnFlush", "(", "$", "entity", ",", "$", "flushEntity", ")", "{", "if", "(", "ClassUtils", "::", "getClass", "(", "$", "entity", ")", "==", "ClassUtils", "::", "getClass", "(", "$", "flushEntity", ")", "&&", "$", "entity", "->", "getId", "(", ")", "===", "$", "flushEntity", "->", "getId", "(", ")", ")", "{", "return", "$", "flushEntity", ";", "}", "else", "{", "return", "$", "entity", ";", "}", "}" ]
Checks if the two passed objects are "the same" but possibly in different states. Returns the second argument if they are the same, else the first @param type $entity @param type $flushEntity @return type
[ "Checks", "if", "the", "two", "passed", "objects", "are", "the", "same", "but", "possibly", "in", "different", "states", ".", "Returns", "the", "second", "argument", "if", "they", "are", "the", "same", "else", "the", "first" ]
7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414
https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/EntityCustomField.php#L139-L146
31,188
EmchBerger/cube-custom-fields-bundle
src/Entity/EntityCustomField.php
EntityCustomField.loadEntitiesAtLoad
public function loadEntitiesAtLoad(LifecycleEventArgs $event) { if ($this->entityValue && $this->entityValue['entityClass']) { $em = $event->getEntityManager(); if (is_array($this->entityValue) && is_array($this->entityValue['entityId'])) { // multiple $entityData = $em->getRepository($this->entityValue['entityClass'])->findById($this->entityValue['entityId']); // in this case, $this->entityValue['entityId'] contains an array of entity IDs } else { // single $entityData = $em->getRepository($this->entityValue['entityClass'])->findOneById($this->entityValue['entityId']); } $this->entityData = $entityData; } else { $this->entityData = null; } }
php
public function loadEntitiesAtLoad(LifecycleEventArgs $event) { if ($this->entityValue && $this->entityValue['entityClass']) { $em = $event->getEntityManager(); if (is_array($this->entityValue) && is_array($this->entityValue['entityId'])) { // multiple $entityData = $em->getRepository($this->entityValue['entityClass'])->findById($this->entityValue['entityId']); // in this case, $this->entityValue['entityId'] contains an array of entity IDs } else { // single $entityData = $em->getRepository($this->entityValue['entityClass'])->findOneById($this->entityValue['entityId']); } $this->entityData = $entityData; } else { $this->entityData = null; } }
[ "public", "function", "loadEntitiesAtLoad", "(", "LifecycleEventArgs", "$", "event", ")", "{", "if", "(", "$", "this", "->", "entityValue", "&&", "$", "this", "->", "entityValue", "[", "'entityClass'", "]", ")", "{", "$", "em", "=", "$", "event", "->", "getEntityManager", "(", ")", ";", "if", "(", "is_array", "(", "$", "this", "->", "entityValue", ")", "&&", "is_array", "(", "$", "this", "->", "entityValue", "[", "'entityId'", "]", ")", ")", "{", "// multiple", "$", "entityData", "=", "$", "em", "->", "getRepository", "(", "$", "this", "->", "entityValue", "[", "'entityClass'", "]", ")", "->", "findById", "(", "$", "this", "->", "entityValue", "[", "'entityId'", "]", ")", ";", "// in this case, $this->entityValue['entityId'] contains an array of entity IDs", "}", "else", "{", "// single", "$", "entityData", "=", "$", "em", "->", "getRepository", "(", "$", "this", "->", "entityValue", "[", "'entityClass'", "]", ")", "->", "findOneById", "(", "$", "this", "->", "entityValue", "[", "'entityId'", "]", ")", ";", "}", "$", "this", "->", "entityData", "=", "$", "entityData", ";", "}", "else", "{", "$", "this", "->", "entityData", "=", "null", ";", "}", "}" ]
LifeCycleCallback PostLoad, loading entities from DataBase. @ORM\PostLoad @param LifecycleEventArgs $event
[ "LifeCycleCallback", "PostLoad", "loading", "entities", "from", "DataBase", "." ]
7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414
https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/EntityCustomField.php#L163-L179
31,189
pulsarvp/vps-tools
src/net/Flow.php
Flow.getChunkPath
public function getChunkPath ($n = null) { if ($n === null) $n = $this->_params[ 'chunkNumber' ]; return $this->_tmpDir . '/' . $this->_params[ 'filename' ] . '.part' . $n; }
php
public function getChunkPath ($n = null) { if ($n === null) $n = $this->_params[ 'chunkNumber' ]; return $this->_tmpDir . '/' . $this->_params[ 'filename' ] . '.part' . $n; }
[ "public", "function", "getChunkPath", "(", "$", "n", "=", "null", ")", "{", "if", "(", "$", "n", "===", "null", ")", "$", "n", "=", "$", "this", "->", "_params", "[", "'chunkNumber'", "]", ";", "return", "$", "this", "->", "_tmpDir", ".", "'/'", ".", "$", "this", "->", "_params", "[", "'filename'", "]", ".", "'.part'", ".", "$", "n", ";", "}" ]
Gets full path to chunk file. @param null|integer $n Chunk number. @return string
[ "Gets", "full", "path", "to", "chunk", "file", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L99-L105
31,190
pulsarvp/vps-tools
src/net/Flow.php
Flow.getIsComplete
public function getIsComplete () { if ($this->_isComplete) return true; for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++) { if (!$this->chunkIsUploaded($i)) { $this->_isComplete = false; return false; } } $this->_isComplete = true; return true; }
php
public function getIsComplete () { if ($this->_isComplete) return true; for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++) { if (!$this->chunkIsUploaded($i)) { $this->_isComplete = false; return false; } } $this->_isComplete = true; return true; }
[ "public", "function", "getIsComplete", "(", ")", "{", "if", "(", "$", "this", "->", "_isComplete", ")", "return", "true", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "this", "->", "_params", "[", "'totalChunks'", "]", ";", "$", "i", "++", ")", "{", "if", "(", "!", "$", "this", "->", "chunkIsUploaded", "(", "$", "i", ")", ")", "{", "$", "this", "->", "_isComplete", "=", "false", ";", "return", "false", ";", "}", "}", "$", "this", "->", "_isComplete", "=", "true", ";", "return", "true", ";", "}" ]
Check whether file uploading is complete. @return bool
[ "Check", "whether", "file", "uploading", "is", "complete", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L111-L129
31,191
pulsarvp/vps-tools
src/net/Flow.php
Flow.getIsNew
public function getIsNew () { if ($this->_isNew == false) return false; for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++) { if ($this->chunkIsUploaded($i)) { $this->_isNew = false; return false; } } $this->_isNew = true; return true; }
php
public function getIsNew () { if ($this->_isNew == false) return false; for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++) { if ($this->chunkIsUploaded($i)) { $this->_isNew = false; return false; } } $this->_isNew = true; return true; }
[ "public", "function", "getIsNew", "(", ")", "{", "if", "(", "$", "this", "->", "_isNew", "==", "false", ")", "return", "false", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "this", "->", "_params", "[", "'totalChunks'", "]", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "chunkIsUploaded", "(", "$", "i", ")", ")", "{", "$", "this", "->", "_isNew", "=", "false", ";", "return", "false", ";", "}", "}", "$", "this", "->", "_isNew", "=", "true", ";", "return", "true", ";", "}" ]
Check whether file uploading is new. @return bool
[ "Check", "whether", "file", "uploading", "is", "new", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L135-L153
31,192
pulsarvp/vps-tools
src/net/Flow.php
Flow.getParam
public function getParam ($name) { if (isset( $this->_params[ $name ] )) return $this->_params[ $name ]; else return null; }
php
public function getParam ($name) { if (isset( $this->_params[ $name ] )) return $this->_params[ $name ]; else return null; }
[ "public", "function", "getParam", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_params", "[", "$", "name", "]", ")", ")", "return", "$", "this", "->", "_params", "[", "$", "name", "]", ";", "else", "return", "null", ";", "}" ]
Gets param by its name. @param string $name Parameter name. @return null|mixed Parameter if exists, null otherwise.
[ "Gets", "param", "by", "its", "name", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L169-L175
31,193
pulsarvp/vps-tools
src/net/Flow.php
Flow.setTmpDir
public function setTmpDir ($dir) { $this->_tmpDir = $dir . '/' . $this->_params[ 'identifier' ]; if (!is_dir($this->_tmpDir)) FileHelper::createDirectory($this->_tmpDir); }
php
public function setTmpDir ($dir) { $this->_tmpDir = $dir . '/' . $this->_params[ 'identifier' ]; if (!is_dir($this->_tmpDir)) FileHelper::createDirectory($this->_tmpDir); }
[ "public", "function", "setTmpDir", "(", "$", "dir", ")", "{", "$", "this", "->", "_tmpDir", "=", "$", "dir", ".", "'/'", ".", "$", "this", "->", "_params", "[", "'identifier'", "]", ";", "if", "(", "!", "is_dir", "(", "$", "this", "->", "_tmpDir", ")", ")", "FileHelper", "::", "createDirectory", "(", "$", "this", "->", "_tmpDir", ")", ";", "}" ]
Sets temporary directory. @param string $dir @throws \yii\base\Exception
[ "Sets", "temporary", "directory", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L191-L196
31,194
pulsarvp/vps-tools
src/net/Flow.php
Flow.setTargetDir
public function setTargetDir ($dir) { $this->_targetDir = $dir; if (!is_dir($this->_targetDir)) FileHelper::createDirectory($this->_targetDir); }
php
public function setTargetDir ($dir) { $this->_targetDir = $dir; if (!is_dir($this->_targetDir)) FileHelper::createDirectory($this->_targetDir); }
[ "public", "function", "setTargetDir", "(", "$", "dir", ")", "{", "$", "this", "->", "_targetDir", "=", "$", "dir", ";", "if", "(", "!", "is_dir", "(", "$", "this", "->", "_targetDir", ")", ")", "FileHelper", "::", "createDirectory", "(", "$", "this", "->", "_targetDir", ")", ";", "}" ]
Sets path to target directory where to save video file. @param string $dir @throws \yii\base\Exception
[ "Sets", "path", "to", "target", "directory", "where", "to", "save", "video", "file", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L203-L208
31,195
pulsarvp/vps-tools
src/net/Flow.php
Flow.process
public function process () { if (!empty( $this->_params )) { if ($this->getIsUploading()) $this->uploadChunk(); else $this->testChunk(); } }
php
public function process () { if (!empty( $this->_params )) { if ($this->getIsUploading()) $this->uploadChunk(); else $this->testChunk(); } }
[ "public", "function", "process", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "_params", ")", ")", "{", "if", "(", "$", "this", "->", "getIsUploading", "(", ")", ")", "$", "this", "->", "uploadChunk", "(", ")", ";", "else", "$", "this", "->", "testChunk", "(", ")", ";", "}", "}" ]
Uploads or tests current chunk.
[ "Uploads", "or", "tests", "current", "chunk", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L213-L222
31,196
pulsarvp/vps-tools
src/net/Flow.php
Flow.save
public function save ($name = null) { if ($name == null) $name = StringHelper::random(); $ext = pathinfo($this->_params[ 'filename' ], PATHINFO_EXTENSION); $this->_savedFilename = $name . '.' . $ext; if (( $file = fopen($this->_targetDir . '/' . $this->_savedFilename, 'w') ) !== false) { if (Yii::$app->settings->get('upload_concat') == 'cat') { fclose($file); setlocale(LC_ALL, 'ru_RU.UTF-8'); for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++) shell_exec('cat ' . escapeshellarg($this->getChunkPath($i)) . ' >> ' . escapeshellarg($this->_targetDir . '/' . $this->_savedFilename)); setlocale(LC_ALL, null); } else { for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++) fwrite($file, file_get_contents($this->getChunkPath($i))); fclose($file); } } FileHelper::removeDirectory($this->_tmpDir); return $this->_savedFilename; }
php
public function save ($name = null) { if ($name == null) $name = StringHelper::random(); $ext = pathinfo($this->_params[ 'filename' ], PATHINFO_EXTENSION); $this->_savedFilename = $name . '.' . $ext; if (( $file = fopen($this->_targetDir . '/' . $this->_savedFilename, 'w') ) !== false) { if (Yii::$app->settings->get('upload_concat') == 'cat') { fclose($file); setlocale(LC_ALL, 'ru_RU.UTF-8'); for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++) shell_exec('cat ' . escapeshellarg($this->getChunkPath($i)) . ' >> ' . escapeshellarg($this->_targetDir . '/' . $this->_savedFilename)); setlocale(LC_ALL, null); } else { for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++) fwrite($file, file_get_contents($this->getChunkPath($i))); fclose($file); } } FileHelper::removeDirectory($this->_tmpDir); return $this->_savedFilename; }
[ "public", "function", "save", "(", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", "==", "null", ")", "$", "name", "=", "StringHelper", "::", "random", "(", ")", ";", "$", "ext", "=", "pathinfo", "(", "$", "this", "->", "_params", "[", "'filename'", "]", ",", "PATHINFO_EXTENSION", ")", ";", "$", "this", "->", "_savedFilename", "=", "$", "name", ".", "'.'", ".", "$", "ext", ";", "if", "(", "(", "$", "file", "=", "fopen", "(", "$", "this", "->", "_targetDir", ".", "'/'", ".", "$", "this", "->", "_savedFilename", ",", "'w'", ")", ")", "!==", "false", ")", "{", "if", "(", "Yii", "::", "$", "app", "->", "settings", "->", "get", "(", "'upload_concat'", ")", "==", "'cat'", ")", "{", "fclose", "(", "$", "file", ")", ";", "setlocale", "(", "LC_ALL", ",", "'ru_RU.UTF-8'", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "this", "->", "_params", "[", "'totalChunks'", "]", ";", "$", "i", "++", ")", "shell_exec", "(", "'cat '", ".", "escapeshellarg", "(", "$", "this", "->", "getChunkPath", "(", "$", "i", ")", ")", ".", "' >> '", ".", "escapeshellarg", "(", "$", "this", "->", "_targetDir", ".", "'/'", ".", "$", "this", "->", "_savedFilename", ")", ")", ";", "setlocale", "(", "LC_ALL", ",", "null", ")", ";", "}", "else", "{", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "this", "->", "_params", "[", "'totalChunks'", "]", ";", "$", "i", "++", ")", "fwrite", "(", "$", "file", ",", "file_get_contents", "(", "$", "this", "->", "getChunkPath", "(", "$", "i", ")", ")", ")", ";", "fclose", "(", "$", "file", ")", ";", "}", "}", "FileHelper", "::", "removeDirectory", "(", "$", "this", "->", "_tmpDir", ")", ";", "return", "$", "this", "->", "_savedFilename", ";", "}" ]
Saves uploaded file. @param null|string $name File name (without extension). @return string Saved file name with extension. @throws \yii\base\ErrorException
[ "Saves", "uploaded", "file", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L230-L257
31,197
pulsarvp/vps-tools
src/net/Flow.php
Flow.uploadChunk
public function uploadChunk () { move_uploaded_file($this->_file[ 'tmp_name' ], $this->chunkPath); Yii::$app->response->setStatusCode(200); }
php
public function uploadChunk () { move_uploaded_file($this->_file[ 'tmp_name' ], $this->chunkPath); Yii::$app->response->setStatusCode(200); }
[ "public", "function", "uploadChunk", "(", ")", "{", "move_uploaded_file", "(", "$", "this", "->", "_file", "[", "'tmp_name'", "]", ",", "$", "this", "->", "chunkPath", ")", ";", "Yii", "::", "$", "app", "->", "response", "->", "setStatusCode", "(", "200", ")", ";", "}" ]
Uploads current chunk. @throws \yii\base\ErrorException
[ "Uploads", "current", "chunk", "." ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L274-L279
31,198
EmchBerger/cube-custom-fields-bundle
src/Utils/ConfigReader.php
ConfigReader.getConfigForEntity
public function getConfigForEntity($entity) { if (is_object($entity)) { $entityClass = self::getEntityClass($entity); } else { $entityClass = $entity; } if (array_key_exists($entityClass, $this->config)) { return $this->config[$entityClass]; } return array(); }
php
public function getConfigForEntity($entity) { if (is_object($entity)) { $entityClass = self::getEntityClass($entity); } else { $entityClass = $entity; } if (array_key_exists($entityClass, $this->config)) { return $this->config[$entityClass]; } return array(); }
[ "public", "function", "getConfigForEntity", "(", "$", "entity", ")", "{", "if", "(", "is_object", "(", "$", "entity", ")", ")", "{", "$", "entityClass", "=", "self", "::", "getEntityClass", "(", "$", "entity", ")", ";", "}", "else", "{", "$", "entityClass", "=", "$", "entity", ";", "}", "if", "(", "array_key_exists", "(", "$", "entityClass", ",", "$", "this", "->", "config", ")", ")", "{", "return", "$", "this", "->", "config", "[", "$", "entityClass", "]", ";", "}", "return", "array", "(", ")", ";", "}" ]
Returns the custom field config for the given entity @param object|string entity or class of entity @return array config of entity
[ "Returns", "the", "custom", "field", "config", "for", "the", "given", "entity" ]
7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414
https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Utils/ConfigReader.php#L41-L53
31,199
pulsarvp/vps-tools
src/modules/setting/migrations/m010101_100001_init_setting.php
m010101_100001_init_setting.up
public function up () { $this->createTable('setting', [ 'name' => $this->string(45)->notNull()->unique(), 'value' => $this->text()->null(), 'description' => $this->text()->null(), ]); $this->addPrimaryKey('name', 'setting', 'name'); }
php
public function up () { $this->createTable('setting', [ 'name' => $this->string(45)->notNull()->unique(), 'value' => $this->text()->null(), 'description' => $this->text()->null(), ]); $this->addPrimaryKey('name', 'setting', 'name'); }
[ "public", "function", "up", "(", ")", "{", "$", "this", "->", "createTable", "(", "'setting'", ",", "[", "'name'", "=>", "$", "this", "->", "string", "(", "45", ")", "->", "notNull", "(", ")", "->", "unique", "(", ")", ",", "'value'", "=>", "$", "this", "->", "text", "(", ")", "->", "null", "(", ")", ",", "'description'", "=>", "$", "this", "->", "text", "(", ")", "->", "null", "(", ")", ",", "]", ")", ";", "$", "this", "->", "addPrimaryKey", "(", "'name'", ",", "'setting'", ",", "'name'", ")", ";", "}" ]
Create table `Setting`
[ "Create", "table", "Setting" ]
bb51fd5f68669edbd2801b52a9edeebaa756eec2
https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/migrations/m010101_100001_init_setting.php#L10-L18