repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
linpax/microphp-framework
src/form/Form.php
Form.monthFieldRow
public function monthFieldRow(IFormModel $model, $property, array $options = []) { $element = $this->getField($model, $property); $options['id'] = $element['id']; return Html::openTag('div', $this->getBlock('block', $options)). Html::label($model->getLabel($property), $element['id'], $this->getBlock('label', $options)). $this->monthField($model, $property, $options). Html::closeTag('div'); }
php
public function monthFieldRow(IFormModel $model, $property, array $options = []) { $element = $this->getField($model, $property); $options['id'] = $element['id']; return Html::openTag('div', $this->getBlock('block', $options)). Html::label($model->getLabel($property), $element['id'], $this->getBlock('label', $options)). $this->monthField($model, $property, $options). Html::closeTag('div'); }
[ "public", "function", "monthFieldRow", "(", "IFormModel", "$", "model", ",", "$", "property", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "element", "=", "$", "this", "->", "getField", "(", "$", "model", ",", "$", "property", ")", ";", "$", "options", "[", "'id'", "]", "=", "$", "element", "[", "'id'", "]", ";", "return", "Html", "::", "openTag", "(", "'div'", ",", "$", "this", "->", "getBlock", "(", "'block'", ",", "$", "options", ")", ")", ".", "Html", "::", "label", "(", "$", "model", "->", "getLabel", "(", "$", "property", ")", ",", "$", "element", "[", "'id'", "]", ",", "$", "this", "->", "getBlock", "(", "'label'", ",", "$", "options", ")", ")", ".", "$", "this", "->", "monthField", "(", "$", "model", ",", "$", "property", ",", "$", "options", ")", ".", "Html", "::", "closeTag", "(", "'div'", ")", ";", "}" ]
Render month field row @access public @param IFormModel $model model @param string $property model property @param array $options attribute array @return string
[ "Render", "month", "field", "row" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/form/Form.php#L1030-L1039
train
linpax/microphp-framework
src/form/Form.php
Form.weekFieldRow
public function weekFieldRow(IFormModel $model, $property, array $options = []) { $element = $this->getField($model, $property); $options['id'] = $element['id']; return Html::openTag('div', $this->getBlock('block', $options)). Html::label($model->getLabel($property), $element['id'], $this->getBlock('label', $options)). $this->weekField($model, $property, $options). Html::closeTag('div'); }
php
public function weekFieldRow(IFormModel $model, $property, array $options = []) { $element = $this->getField($model, $property); $options['id'] = $element['id']; return Html::openTag('div', $this->getBlock('block', $options)). Html::label($model->getLabel($property), $element['id'], $this->getBlock('label', $options)). $this->weekField($model, $property, $options). Html::closeTag('div'); }
[ "public", "function", "weekFieldRow", "(", "IFormModel", "$", "model", ",", "$", "property", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "element", "=", "$", "this", "->", "getField", "(", "$", "model", ",", "$", "property", ")", ";", "$", "options", "[", "'id'", "]", "=", "$", "element", "[", "'id'", "]", ";", "return", "Html", "::", "openTag", "(", "'div'", ",", "$", "this", "->", "getBlock", "(", "'block'", ",", "$", "options", ")", ")", ".", "Html", "::", "label", "(", "$", "model", "->", "getLabel", "(", "$", "property", ")", ",", "$", "element", "[", "'id'", "]", ",", "$", "this", "->", "getBlock", "(", "'label'", ",", "$", "options", ")", ")", ".", "$", "this", "->", "weekField", "(", "$", "model", ",", "$", "property", ",", "$", "options", ")", ".", "Html", "::", "closeTag", "(", "'div'", ")", ";", "}" ]
Render week field row @access public @param IFormModel $model model @param string $property model property @param array $options attribute array @return string
[ "Render", "week", "field", "row" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/form/Form.php#L1071-L1080
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.makeFile
public static function makeFile($file, $chmod = 0777, $touchTime = null) { if (!file_exists($file)) { if (!is_dir(dirname($file))) { mkdir(dirname($file), 0777, true); } $h = fopen($file, 'w'); if ($h) { fclose($h); } unset($h); if (null !== $touchTime) { touch($file, $touchTime); } } }
php
public static function makeFile($file, $chmod = 0777, $touchTime = null) { if (!file_exists($file)) { if (!is_dir(dirname($file))) { mkdir(dirname($file), 0777, true); } $h = fopen($file, 'w'); if ($h) { fclose($h); } unset($h); if (null !== $touchTime) { touch($file, $touchTime); } } }
[ "public", "static", "function", "makeFile", "(", "$", "file", ",", "$", "chmod", "=", "0777", ",", "$", "touchTime", "=", "null", ")", "{", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "if", "(", "!", "is_dir", "(", "dirname", "(", "$", "file", ")", ")", ")", "{", "mkdir", "(", "dirname", "(", "$", "file", ")", ",", "0777", ",", "true", ")", ";", "}", "$", "h", "=", "fopen", "(", "$", "file", ",", "'w'", ")", ";", "if", "(", "$", "h", ")", "{", "fclose", "(", "$", "h", ")", ";", "}", "unset", "(", "$", "h", ")", ";", "if", "(", "null", "!==", "$", "touchTime", ")", "{", "touch", "(", "$", "file", ",", "$", "touchTime", ")", ";", "}", "}", "}" ]
Recursively generate directories if not existent and place a empty file inside it. @param string $file full path to the required file @param integer $chmod chmod for the generated folders @param integer $touchTime timestamp for the filemtime @return null
[ "Recursively", "generate", "directories", "if", "not", "existent", "and", "place", "a", "empty", "file", "inside", "it", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L133-L148
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.normalizeUrl
public static function normalizeUrl($url) { if (!class_exists('URLNormalizer')) { require_once(realpath(__DIR__.'/../../classes').'/URLNormalizer.php'); } $un = new \URLNormalizer(); $un->setUrl($url); return $un->normalize(); }
php
public static function normalizeUrl($url) { if (!class_exists('URLNormalizer')) { require_once(realpath(__DIR__.'/../../classes').'/URLNormalizer.php'); } $un = new \URLNormalizer(); $un->setUrl($url); return $un->normalize(); }
[ "public", "static", "function", "normalizeUrl", "(", "$", "url", ")", "{", "if", "(", "!", "class_exists", "(", "'URLNormalizer'", ")", ")", "{", "require_once", "(", "realpath", "(", "__DIR__", ".", "'/../../classes'", ")", ".", "'/URLNormalizer.php'", ")", ";", "}", "$", "un", "=", "new", "\\", "URLNormalizer", "(", ")", ";", "$", "un", "->", "setUrl", "(", "$", "url", ")", ";", "return", "$", "un", "->", "normalize", "(", ")", ";", "}" ]
Use Glen Scotts UrlNormalizer to normalize the passed url. @param string $url @return string
[ "Use", "Glen", "Scotts", "UrlNormalizer", "to", "normalize", "the", "passed", "url", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L204-L212
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.encrypt
public static function encrypt($string, $key) { $result = ''; for ($i=0; $i<strlen ($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)+ord($keychar)); $result .= $char; } return base64_encode($result); }
php
public static function encrypt($string, $key) { $result = ''; for ($i=0; $i<strlen ($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)+ord($keychar)); $result .= $char; } return base64_encode($result); }
[ "public", "static", "function", "encrypt", "(", "$", "string", ",", "$", "key", ")", "{", "$", "result", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "string", ")", ";", "$", "i", "++", ")", "{", "$", "char", "=", "substr", "(", "$", "string", ",", "$", "i", ",", "1", ")", ";", "$", "keychar", "=", "substr", "(", "$", "key", ",", "(", "$", "i", "%", "strlen", "(", "$", "key", ")", ")", "-", "1", ",", "1", ")", ";", "$", "char", "=", "chr", "(", "ord", "(", "$", "char", ")", "+", "ord", "(", "$", "keychar", ")", ")", ";", "$", "result", ".=", "$", "char", ";", "}", "return", "base64_encode", "(", "$", "result", ")", ";", "}" ]
Basic encryption method. http://www.tfonfara.de/php-encryptdecrypt-funktion-mit-base64-und-schlussel.xhtml @param string $string the string that needs encryption. @param string $key a key string for the encryption. @return string the encrypted string.
[ "Basic", "encryption", "method", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L224-L234
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.decrypt
public static function decrypt($string, $key) { $result = ''; $string = base64_decode($string); for ($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)-ord($keychar)); $result .= $char; } return $result; }
php
public static function decrypt($string, $key) { $result = ''; $string = base64_decode($string); for ($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)-ord($keychar)); $result .= $char; } return $result; }
[ "public", "static", "function", "decrypt", "(", "$", "string", ",", "$", "key", ")", "{", "$", "result", "=", "''", ";", "$", "string", "=", "base64_decode", "(", "$", "string", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "string", ")", ";", "$", "i", "++", ")", "{", "$", "char", "=", "substr", "(", "$", "string", ",", "$", "i", ",", "1", ")", ";", "$", "keychar", "=", "substr", "(", "$", "key", ",", "(", "$", "i", "%", "strlen", "(", "$", "key", ")", ")", "-", "1", ",", "1", ")", ";", "$", "char", "=", "chr", "(", "ord", "(", "$", "char", ")", "-", "ord", "(", "$", "keychar", ")", ")", ";", "$", "result", ".=", "$", "char", ";", "}", "return", "$", "result", ";", "}" ]
Basic decryption method. http://www.tfonfara.de/php-encryptdecrypt-funktion-mit-base64-und-schlussel.xhtml @param string $string a string encrypted by THETOOLS::encrypt(). @param string $key a key string for the decryption. @return string the decrypted string.
[ "Basic", "decryption", "method", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L246-L258
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.getPathsBase
public static function getPathsBase(&$a, &$b, $modify = false, $DS = DIRECTORY_SEPARATOR) { if ($modify) { $str1 = &$a; $str2 = &$b; } else { $str1 = $a; $str2 = $b; } $str1 = explode($DS, self::unify_slashes($str1, $DS)); $str2 = explode($DS, self::unify_slashes($str2, $DS)); $match = array(); for ($i=0; $i < count($str1); $i++) { if ($str1[$i] === $str2[$i]) { $match[] = $str1[$i]; } else { break; } } $match = implode($DS, $match); $str1 = substr(implode($DS, $str1), strlen($match)); $str2 = substr(implode($DS, $str2), strlen($match)); return $match; }
php
public static function getPathsBase(&$a, &$b, $modify = false, $DS = DIRECTORY_SEPARATOR) { if ($modify) { $str1 = &$a; $str2 = &$b; } else { $str1 = $a; $str2 = $b; } $str1 = explode($DS, self::unify_slashes($str1, $DS)); $str2 = explode($DS, self::unify_slashes($str2, $DS)); $match = array(); for ($i=0; $i < count($str1); $i++) { if ($str1[$i] === $str2[$i]) { $match[] = $str1[$i]; } else { break; } } $match = implode($DS, $match); $str1 = substr(implode($DS, $str1), strlen($match)); $str2 = substr(implode($DS, $str2), strlen($match)); return $match; }
[ "public", "static", "function", "getPathsBase", "(", "&", "$", "a", ",", "&", "$", "b", ",", "$", "modify", "=", "false", ",", "$", "DS", "=", "DIRECTORY_SEPARATOR", ")", "{", "if", "(", "$", "modify", ")", "{", "$", "str1", "=", "&", "$", "a", ";", "$", "str2", "=", "&", "$", "b", ";", "}", "else", "{", "$", "str1", "=", "$", "a", ";", "$", "str2", "=", "$", "b", ";", "}", "$", "str1", "=", "explode", "(", "$", "DS", ",", "self", "::", "unify_slashes", "(", "$", "str1", ",", "$", "DS", ")", ")", ";", "$", "str2", "=", "explode", "(", "$", "DS", ",", "self", "::", "unify_slashes", "(", "$", "str2", ",", "$", "DS", ")", ")", ";", "$", "match", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "str1", ")", ";", "$", "i", "++", ")", "{", "if", "(", "$", "str1", "[", "$", "i", "]", "===", "$", "str2", "[", "$", "i", "]", ")", "{", "$", "match", "[", "]", "=", "$", "str1", "[", "$", "i", "]", ";", "}", "else", "{", "break", ";", "}", "}", "$", "match", "=", "implode", "(", "$", "DS", ",", "$", "match", ")", ";", "$", "str1", "=", "substr", "(", "implode", "(", "$", "DS", ",", "$", "str1", ")", ",", "strlen", "(", "$", "match", ")", ")", ";", "$", "str2", "=", "substr", "(", "implode", "(", "$", "DS", ",", "$", "str2", ")", ",", "strlen", "(", "$", "match", ")", ")", ";", "return", "$", "match", ";", "}" ]
Return the folder on with the both given paths split. @param string $a first path @param string $b second path @param boolean $modify set true to directly shorten the passed paths to be relative to the return values @param string $DS the directory separator that should be used. @return string
[ "Return", "the", "folder", "on", "with", "the", "both", "given", "paths", "split", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L269-L293
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.buildDir
public static function buildDir($path, $chmod = 0775) { deprecated('mkdir($dir, null, true);'); if (is_dir($path)) { return true; } $dir = DIRECTORY_SEPARATOR; foreach(explode(DIRECTORY_SEPARATOR, self::unify_slashes($path, DIRECTORY_SEPARATOR, true)) as $f) { if (empty($f)) { continue; } $dir .= $f.DIRECTORY_SEPARATOR; if (is_dir($dir)) { continue; } if (is_writable(dirname($dir))) { mkdir($dir, $chmod); } else { return false; } } return true; }
php
public static function buildDir($path, $chmod = 0775) { deprecated('mkdir($dir, null, true);'); if (is_dir($path)) { return true; } $dir = DIRECTORY_SEPARATOR; foreach(explode(DIRECTORY_SEPARATOR, self::unify_slashes($path, DIRECTORY_SEPARATOR, true)) as $f) { if (empty($f)) { continue; } $dir .= $f.DIRECTORY_SEPARATOR; if (is_dir($dir)) { continue; } if (is_writable(dirname($dir))) { mkdir($dir, $chmod); } else { return false; } } return true; }
[ "public", "static", "function", "buildDir", "(", "$", "path", ",", "$", "chmod", "=", "0775", ")", "{", "deprecated", "(", "'mkdir($dir, null, true);'", ")", ";", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "return", "true", ";", "}", "$", "dir", "=", "DIRECTORY_SEPARATOR", ";", "foreach", "(", "explode", "(", "DIRECTORY_SEPARATOR", ",", "self", "::", "unify_slashes", "(", "$", "path", ",", "DIRECTORY_SEPARATOR", ",", "true", ")", ")", "as", "$", "f", ")", "{", "if", "(", "empty", "(", "$", "f", ")", ")", "{", "continue", ";", "}", "$", "dir", ".=", "$", "f", ".", "DIRECTORY_SEPARATOR", ";", "if", "(", "is_dir", "(", "$", "dir", ")", ")", "{", "continue", ";", "}", "if", "(", "is_writable", "(", "dirname", "(", "$", "dir", ")", ")", ")", "{", "mkdir", "(", "$", "dir", ",", "$", "chmod", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks if the given Path is existent and generates missing folders. @param string $path the path @param integer $chmod chmod for new folders @return boolean true if path is available false if not.
[ "Checks", "if", "the", "given", "Path", "is", "existent", "and", "generates", "missing", "folders", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L303-L325
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.arrayWrap
public static function arrayWrap($input, $wrap) { $w1 = ''; $w2 = ''; if (is_array($wrap)) { $w1 = $wrap[0]; if (isset($wrap[1])) { $w2 = $wrap[1]; } } elseif (!is_string($wrap)) { throw new \Exception(sprintf('Invalid Type %s for $wrap', gettype($wrap)), 1); return false; } else { $w1 = $wrap; $w2 = $wrap; } return array_map( function ($el) use ($w1, $w2) { return $w1.$el.$w2; }, $input ); }
php
public static function arrayWrap($input, $wrap) { $w1 = ''; $w2 = ''; if (is_array($wrap)) { $w1 = $wrap[0]; if (isset($wrap[1])) { $w2 = $wrap[1]; } } elseif (!is_string($wrap)) { throw new \Exception(sprintf('Invalid Type %s for $wrap', gettype($wrap)), 1); return false; } else { $w1 = $wrap; $w2 = $wrap; } return array_map( function ($el) use ($w1, $w2) { return $w1.$el.$w2; }, $input ); }
[ "public", "static", "function", "arrayWrap", "(", "$", "input", ",", "$", "wrap", ")", "{", "$", "w1", "=", "''", ";", "$", "w2", "=", "''", ";", "if", "(", "is_array", "(", "$", "wrap", ")", ")", "{", "$", "w1", "=", "$", "wrap", "[", "0", "]", ";", "if", "(", "isset", "(", "$", "wrap", "[", "1", "]", ")", ")", "{", "$", "w2", "=", "$", "wrap", "[", "1", "]", ";", "}", "}", "elseif", "(", "!", "is_string", "(", "$", "wrap", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Invalid Type %s for $wrap'", ",", "gettype", "(", "$", "wrap", ")", ")", ",", "1", ")", ";", "return", "false", ";", "}", "else", "{", "$", "w1", "=", "$", "wrap", ";", "$", "w2", "=", "$", "wrap", ";", "}", "return", "array_map", "(", "function", "(", "$", "el", ")", "use", "(", "$", "w1", ",", "$", "w2", ")", "{", "return", "$", "w1", ".", "$", "el", ".", "$", "w2", ";", "}", ",", "$", "input", ")", ";", "}" ]
Wrap each entry of an array @param array $input the array @param array|string $wrap the wrap @return array
[ "Wrap", "each", "entry", "of", "an", "array" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L396-L419
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.post
public static function post($url, $params) { if (!is_array($params)) { $params = self::ar($params); } $query = http_build_query($params); /* * open connection. */ $ch = curl_init(); /* * set the url, number of POST vars, POST data. */ curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); /* * execute post. */ $r = curl_exec( $ch ); /* * close connection. */ curl_close($ch); return $r; }
php
public static function post($url, $params) { if (!is_array($params)) { $params = self::ar($params); } $query = http_build_query($params); /* * open connection. */ $ch = curl_init(); /* * set the url, number of POST vars, POST data. */ curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); /* * execute post. */ $r = curl_exec( $ch ); /* * close connection. */ curl_close($ch); return $r; }
[ "public", "static", "function", "post", "(", "$", "url", ",", "$", "params", ")", "{", "if", "(", "!", "is_array", "(", "$", "params", ")", ")", "{", "$", "params", "=", "self", "::", "ar", "(", "$", "params", ")", ";", "}", "$", "query", "=", "http_build_query", "(", "$", "params", ")", ";", "/*\n * open connection.\n */", "$", "ch", "=", "curl_init", "(", ")", ";", "/*\n * set the url, number of POST vars, POST data.\n */", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POST", ",", "count", "(", "$", "params", ")", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "query", ")", ";", "/*\n * execute post.\n */", "$", "r", "=", "curl_exec", "(", "$", "ch", ")", ";", "/*\n * close connection.\n */", "curl_close", "(", "$", "ch", ")", ";", "return", "$", "r", ";", "}" ]
Performs a post request to given url passing given parameters. @param string $url the url @param mixed $params array, class or string parameter. See THETOOLS::ar() @return string the output of the requested url.
[ "Performs", "a", "post", "request", "to", "given", "url", "passing", "given", "parameters", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L609-L641
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.ar
public static function ar($a, $b = null, $deep = false) { $r = array(); if (is_array($a) || is_object($a)) { foreach ($a as $k => $v) { if ($deep == true && (is_array($v) || is_object($v))) { $v = self::ar($v, null, true); } $r[$k] = $v; } } elseif (is_string($a) || is_int($a)) { if ($b !== null) { $r[$a] = $b; } else { $r[] = $a; } } return $r; }
php
public static function ar($a, $b = null, $deep = false) { $r = array(); if (is_array($a) || is_object($a)) { foreach ($a as $k => $v) { if ($deep == true && (is_array($v) || is_object($v))) { $v = self::ar($v, null, true); } $r[$k] = $v; } } elseif (is_string($a) || is_int($a)) { if ($b !== null) { $r[$a] = $b; } else { $r[] = $a; } } return $r; }
[ "public", "static", "function", "ar", "(", "$", "a", ",", "$", "b", "=", "null", ",", "$", "deep", "=", "false", ")", "{", "$", "r", "=", "array", "(", ")", ";", "if", "(", "is_array", "(", "$", "a", ")", "||", "is_object", "(", "$", "a", ")", ")", "{", "foreach", "(", "$", "a", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "deep", "==", "true", "&&", "(", "is_array", "(", "$", "v", ")", "||", "is_object", "(", "$", "v", ")", ")", ")", "{", "$", "v", "=", "self", "::", "ar", "(", "$", "v", ",", "null", ",", "true", ")", ";", "}", "$", "r", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", "elseif", "(", "is_string", "(", "$", "a", ")", "||", "is_int", "(", "$", "a", ")", ")", "{", "if", "(", "$", "b", "!==", "null", ")", "{", "$", "r", "[", "$", "a", "]", "=", "$", "b", ";", "}", "else", "{", "$", "r", "[", "]", "=", "$", "a", ";", "}", "}", "return", "$", "r", ";", "}" ]
Converts arrays, objects, integers or strings into arrays. @access public @param mixed $a the variable to be converted or the key if $b is set. @param mixed $b the value for key $a. @param mixed $deep flag if the converting should be limited on first layer or also be appended to deeper objects. @return array a fresh an clean array.
[ "Converts", "arrays", "objects", "integers", "or", "strings", "into", "arrays", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L653-L671
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.pq
public static function pq($html, $contentType = null) { self::initPhpQuery(); return \phpQuery::newDocument($html, $contentType); }
php
public static function pq($html, $contentType = null) { self::initPhpQuery(); return \phpQuery::newDocument($html, $contentType); }
[ "public", "static", "function", "pq", "(", "$", "html", ",", "$", "contentType", "=", "null", ")", "{", "self", "::", "initPhpQuery", "(", ")", ";", "return", "\\", "phpQuery", "::", "newDocument", "(", "$", "html", ",", "$", "contentType", ")", ";", "}" ]
Sets a new "DOM" for PHPQuery. @access public @param string $html @param string $contentType @return void
[ "Sets", "a", "new", "DOM", "for", "PHPQuery", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L724-L728
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.switchVars
public static function switchVars(array $vars) { $i = 0; foreach ($vars as $k => $v) { if ($i == 0) { $pk = $k; $pv = $v; } else { return array($pk => $v, $k => $pv); } $i++; } }
php
public static function switchVars(array $vars) { $i = 0; foreach ($vars as $k => $v) { if ($i == 0) { $pk = $k; $pv = $v; } else { return array($pk => $v, $k => $pv); } $i++; } }
[ "public", "static", "function", "switchVars", "(", "array", "$", "vars", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "vars", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "i", "==", "0", ")", "{", "$", "pk", "=", "$", "k", ";", "$", "pv", "=", "$", "v", ";", "}", "else", "{", "return", "array", "(", "$", "pk", "=>", "$", "v", ",", "$", "k", "=>", "$", "pv", ")", ";", "}", "$", "i", "++", ";", "}", "}" ]
Switches the first two variables of an array while leaving its keys. @param array $vars @return array
[ "Switches", "the", "first", "two", "variables", "of", "an", "array", "while", "leaving", "its", "keys", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L736-L748
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.get_randomString
public static function get_randomString($length = 12, $type = 'pAan', $additional = '') { $sources = array( 'p' => '!#$%&()=?*+-_:.;,<>', // Punctuation 'a' => 'abcdefghijklmnopqrstuvwxyz', // alpha 'A' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', // Alpha 'n' => '1234567890' // Numeric ); $source = ''; foreach ( $sources as $k => $s ) { if (strstr($type, $k)) { $source .= $s; } } $source .= $additional; if ($source == '') { throw new Exception('Type Error in get_randomString', 1); } srand((double)microtime()*1000000); $i = 0; $r = ''; while ($i < $length) { $num = rand() % strlen($source); $tmp = substr($source, $num, 1); $r = $r . $tmp; $i++; } return $r; }
php
public static function get_randomString($length = 12, $type = 'pAan', $additional = '') { $sources = array( 'p' => '!#$%&()=?*+-_:.;,<>', // Punctuation 'a' => 'abcdefghijklmnopqrstuvwxyz', // alpha 'A' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', // Alpha 'n' => '1234567890' // Numeric ); $source = ''; foreach ( $sources as $k => $s ) { if (strstr($type, $k)) { $source .= $s; } } $source .= $additional; if ($source == '') { throw new Exception('Type Error in get_randomString', 1); } srand((double)microtime()*1000000); $i = 0; $r = ''; while ($i < $length) { $num = rand() % strlen($source); $tmp = substr($source, $num, 1); $r = $r . $tmp; $i++; } return $r; }
[ "public", "static", "function", "get_randomString", "(", "$", "length", "=", "12", ",", "$", "type", "=", "'pAan'", ",", "$", "additional", "=", "''", ")", "{", "$", "sources", "=", "array", "(", "'p'", "=>", "'!#$%&()=?*+-_:.;,<>'", ",", "// Punctuation", "'a'", "=>", "'abcdefghijklmnopqrstuvwxyz'", ",", "// alpha", "'A'", "=>", "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'", ",", "// Alpha", "'n'", "=>", "'1234567890'", "// Numeric", ")", ";", "$", "source", "=", "''", ";", "foreach", "(", "$", "sources", "as", "$", "k", "=>", "$", "s", ")", "{", "if", "(", "strstr", "(", "$", "type", ",", "$", "k", ")", ")", "{", "$", "source", ".=", "$", "s", ";", "}", "}", "$", "source", ".=", "$", "additional", ";", "if", "(", "$", "source", "==", "''", ")", "{", "throw", "new", "Exception", "(", "'Type Error in get_randomString'", ",", "1", ")", ";", "}", "srand", "(", "(", "double", ")", "microtime", "(", ")", "*", "1000000", ")", ";", "$", "i", "=", "0", ";", "$", "r", "=", "''", ";", "while", "(", "$", "i", "<", "$", "length", ")", "{", "$", "num", "=", "rand", "(", ")", "%", "strlen", "(", "$", "source", ")", ";", "$", "tmp", "=", "substr", "(", "$", "source", ",", "$", "num", ",", "1", ")", ";", "$", "r", "=", "$", "r", ".", "$", "tmp", ";", "$", "i", "++", ";", "}", "return", "$", "r", ";", "}" ]
Generates a passwordish random string @access public @param integer $length the length of the string @param string $type keys of chartypes to be used. See beginning of declaration. @param string $additional optional string containing additional chars to use beside the ones in $type @return string
[ "Generates", "a", "passwordish", "random", "string" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L775-L807
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.get_browserObj
public static function get_browserObj() { if (!class_exists('\Ikimea\Browser\Browser')) { throw new THETOOLSException("Browser Class could not be loaded"); } if (self::$s_BrowserObj === null) { self::$s_BrowserObj = new \Ikimea\Browser\Browser; self::$s_browserVersion = self::$s_BrowserObj->getVersion(); self::$s_browser = self::$s_BrowserObj->getBrowser(); } return self::$s_BrowserObj; }
php
public static function get_browserObj() { if (!class_exists('\Ikimea\Browser\Browser')) { throw new THETOOLSException("Browser Class could not be loaded"); } if (self::$s_BrowserObj === null) { self::$s_BrowserObj = new \Ikimea\Browser\Browser; self::$s_browserVersion = self::$s_BrowserObj->getVersion(); self::$s_browser = self::$s_BrowserObj->getBrowser(); } return self::$s_BrowserObj; }
[ "public", "static", "function", "get_browserObj", "(", ")", "{", "if", "(", "!", "class_exists", "(", "'\\Ikimea\\Browser\\Browser'", ")", ")", "{", "throw", "new", "THETOOLSException", "(", "\"Browser Class could not be loaded\"", ")", ";", "}", "if", "(", "self", "::", "$", "s_BrowserObj", "===", "null", ")", "{", "self", "::", "$", "s_BrowserObj", "=", "new", "\\", "Ikimea", "\\", "Browser", "\\", "Browser", ";", "self", "::", "$", "s_browserVersion", "=", "self", "::", "$", "s_BrowserObj", "->", "getVersion", "(", ")", ";", "self", "::", "$", "s_browser", "=", "self", "::", "$", "s_BrowserObj", "->", "getBrowser", "(", ")", ";", "}", "return", "self", "::", "$", "s_BrowserObj", ";", "}" ]
Generates and caches the Browser-Object @access private @return object
[ "Generates", "and", "caches", "the", "Browser", "-", "Object" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L967-L980
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.minify
public static function minify($string, $noSpace = false) { $string = preg_replace("/\s+/", ' ', $string); return $noSpace ? str_replace(' ', '', $string) : $string; }
php
public static function minify($string, $noSpace = false) { $string = preg_replace("/\s+/", ' ', $string); return $noSpace ? str_replace(' ', '', $string) : $string; }
[ "public", "static", "function", "minify", "(", "$", "string", ",", "$", "noSpace", "=", "false", ")", "{", "$", "string", "=", "preg_replace", "(", "\"/\\s+/\"", ",", "' '", ",", "$", "string", ")", ";", "return", "$", "noSpace", "?", "str_replace", "(", "' '", ",", "''", ",", "$", "string", ")", ":", "$", "string", ";", "}" ]
deletes linebreaks and tabs from string @access public @param string $string @param bool $noSpace if true spaces will be deleted, too @return string
[ "deletes", "linebreaks", "and", "tabs", "from", "string" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1071-L1075
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.replace_subdomain
public static function replace_subdomain($url, $newSubdomain) { $url = parse_url($url); if(substr_count($url['host'], '.') >= 2) { $url['host'] = (str_replace( substr($url['host'], 0, strpos($url['host'], '.')), $newSubdomain, $url['host'] )); } else { $url['host'] = $newSubdomain.'.'.$url['host']; } return self::unparse_url($url); }
php
public static function replace_subdomain($url, $newSubdomain) { $url = parse_url($url); if(substr_count($url['host'], '.') >= 2) { $url['host'] = (str_replace( substr($url['host'], 0, strpos($url['host'], '.')), $newSubdomain, $url['host'] )); } else { $url['host'] = $newSubdomain.'.'.$url['host']; } return self::unparse_url($url); }
[ "public", "static", "function", "replace_subdomain", "(", "$", "url", ",", "$", "newSubdomain", ")", "{", "$", "url", "=", "parse_url", "(", "$", "url", ")", ";", "if", "(", "substr_count", "(", "$", "url", "[", "'host'", "]", ",", "'.'", ")", ">=", "2", ")", "{", "$", "url", "[", "'host'", "]", "=", "(", "str_replace", "(", "substr", "(", "$", "url", "[", "'host'", "]", ",", "0", ",", "strpos", "(", "$", "url", "[", "'host'", "]", ",", "'.'", ")", ")", ",", "$", "newSubdomain", ",", "$", "url", "[", "'host'", "]", ")", ")", ";", "}", "else", "{", "$", "url", "[", "'host'", "]", "=", "$", "newSubdomain", ".", "'.'", ".", "$", "url", "[", "'host'", "]", ";", "}", "return", "self", "::", "unparse_url", "(", "$", "url", ")", ";", "}" ]
Replaces the subdomain of given url or adds it. @access public @param string $url @param string $newSubdomain @return string
[ "Replaces", "the", "subdomain", "of", "given", "url", "or", "adds", "it", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1085-L1098
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.unparse_url
public static function unparse_url($parsedUrl) { $scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] . '://' : ''; $host = isset($parsedUrl['host']) ? $parsedUrl['host'] : ''; $port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : ''; $user = isset($parsedUrl['user']) ? $parsedUrl['user'] : ''; $pass = isset($parsedUrl['pass']) ? ':' . $parsedUrl['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; $query = isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : ''; $fragment = isset($parsedUrl['fragment']) ? '#' . $parsedUrl['fragment'] : ''; return "$scheme$user$pass$host$port$path$query$fragment"; }
php
public static function unparse_url($parsedUrl) { $scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] . '://' : ''; $host = isset($parsedUrl['host']) ? $parsedUrl['host'] : ''; $port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : ''; $user = isset($parsedUrl['user']) ? $parsedUrl['user'] : ''; $pass = isset($parsedUrl['pass']) ? ':' . $parsedUrl['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; $query = isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : ''; $fragment = isset($parsedUrl['fragment']) ? '#' . $parsedUrl['fragment'] : ''; return "$scheme$user$pass$host$port$path$query$fragment"; }
[ "public", "static", "function", "unparse_url", "(", "$", "parsedUrl", ")", "{", "$", "scheme", "=", "isset", "(", "$", "parsedUrl", "[", "'scheme'", "]", ")", "?", "$", "parsedUrl", "[", "'scheme'", "]", ".", "'://'", ":", "''", ";", "$", "host", "=", "isset", "(", "$", "parsedUrl", "[", "'host'", "]", ")", "?", "$", "parsedUrl", "[", "'host'", "]", ":", "''", ";", "$", "port", "=", "isset", "(", "$", "parsedUrl", "[", "'port'", "]", ")", "?", "':'", ".", "$", "parsedUrl", "[", "'port'", "]", ":", "''", ";", "$", "user", "=", "isset", "(", "$", "parsedUrl", "[", "'user'", "]", ")", "?", "$", "parsedUrl", "[", "'user'", "]", ":", "''", ";", "$", "pass", "=", "isset", "(", "$", "parsedUrl", "[", "'pass'", "]", ")", "?", "':'", ".", "$", "parsedUrl", "[", "'pass'", "]", ":", "''", ";", "$", "pass", "=", "(", "$", "user", "||", "$", "pass", ")", "?", "\"$pass@\"", ":", "''", ";", "$", "path", "=", "isset", "(", "$", "parsedUrl", "[", "'path'", "]", ")", "?", "$", "parsedUrl", "[", "'path'", "]", ":", "''", ";", "$", "query", "=", "isset", "(", "$", "parsedUrl", "[", "'query'", "]", ")", "?", "'?'", ".", "$", "parsedUrl", "[", "'query'", "]", ":", "''", ";", "$", "fragment", "=", "isset", "(", "$", "parsedUrl", "[", "'fragment'", "]", ")", "?", "'#'", ".", "$", "parsedUrl", "[", "'fragment'", "]", ":", "''", ";", "return", "\"$scheme$user$pass$host$port$path$query$fragment\"", ";", "}" ]
reverses the result array of parse_url into an url string. @access public @param array $parsedUrl a parsed url @return string a unparsed url
[ "reverses", "the", "result", "array", "of", "parse_url", "into", "an", "url", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1107-L1119
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.get_currentUrl
public static function get_currentUrl($filter = array(), $queryFilter = array(), $queryFilterMethod = 'remove') { if (!is_array($filter) && !empty($filter)) { $filter = array($filter); } if (!empty(self::$fakeCurrentUrl)) { $pageURL = self::$fakeCurrentUrl; } else { $pageURL = self::get_realCurrentUrl(); } if (empty($filter) && empty($queryFilter)) { return $pageURL; } if (empty($filter)) { $filter = array('http', 'name', 'port', 'path', 'request'); } $urlParts = parse_url($pageURL); if (!in_array('http', $filter)) { $pageURL = preg_replace('#.*://#', '', $pageURL); } if (!in_array('name', $filter) && !in_array('host', $filter) && array_key_exists('host', $urlParts)) { $pageURL = str_replace($urlParts['host'], '', $pageURL); } if (!in_array('port', $filter) && array_key_exists('port', $urlParts)) { $pageURL = str_replace(':'.$urlParts['port'], '', $pageURL); } if (!in_array('path', $filter) && array_key_exists('path', $urlParts)) { $pageURL = str_replace($urlParts['path'], '', $pageURL); } if ((in_array('request', $filter) || in_array('query', $filter)) && array_key_exists('query', $urlParts)) { if (!empty($queryFilter) && is_array($queryFilter)) { parse_str($urlParts['query'], $query); self::filter_data($query, $queryFilter, $queryFilterMethod); $pageURL = explode('?', $pageURL); if (empty($query)) { unset($pageURL[1]); } else { $pageURL[1] = http_build_query($query); } $pageURL = implode('?', $pageURL); } } else { $pageURL = preg_replace('/\?.*/', '', $pageURL); } return $pageURL; }
php
public static function get_currentUrl($filter = array(), $queryFilter = array(), $queryFilterMethod = 'remove') { if (!is_array($filter) && !empty($filter)) { $filter = array($filter); } if (!empty(self::$fakeCurrentUrl)) { $pageURL = self::$fakeCurrentUrl; } else { $pageURL = self::get_realCurrentUrl(); } if (empty($filter) && empty($queryFilter)) { return $pageURL; } if (empty($filter)) { $filter = array('http', 'name', 'port', 'path', 'request'); } $urlParts = parse_url($pageURL); if (!in_array('http', $filter)) { $pageURL = preg_replace('#.*://#', '', $pageURL); } if (!in_array('name', $filter) && !in_array('host', $filter) && array_key_exists('host', $urlParts)) { $pageURL = str_replace($urlParts['host'], '', $pageURL); } if (!in_array('port', $filter) && array_key_exists('port', $urlParts)) { $pageURL = str_replace(':'.$urlParts['port'], '', $pageURL); } if (!in_array('path', $filter) && array_key_exists('path', $urlParts)) { $pageURL = str_replace($urlParts['path'], '', $pageURL); } if ((in_array('request', $filter) || in_array('query', $filter)) && array_key_exists('query', $urlParts)) { if (!empty($queryFilter) && is_array($queryFilter)) { parse_str($urlParts['query'], $query); self::filter_data($query, $queryFilter, $queryFilterMethod); $pageURL = explode('?', $pageURL); if (empty($query)) { unset($pageURL[1]); } else { $pageURL[1] = http_build_query($query); } $pageURL = implode('?', $pageURL); } } else { $pageURL = preg_replace('/\?.*/', '', $pageURL); } return $pageURL; }
[ "public", "static", "function", "get_currentUrl", "(", "$", "filter", "=", "array", "(", ")", ",", "$", "queryFilter", "=", "array", "(", ")", ",", "$", "queryFilterMethod", "=", "'remove'", ")", "{", "if", "(", "!", "is_array", "(", "$", "filter", ")", "&&", "!", "empty", "(", "$", "filter", ")", ")", "{", "$", "filter", "=", "array", "(", "$", "filter", ")", ";", "}", "if", "(", "!", "empty", "(", "self", "::", "$", "fakeCurrentUrl", ")", ")", "{", "$", "pageURL", "=", "self", "::", "$", "fakeCurrentUrl", ";", "}", "else", "{", "$", "pageURL", "=", "self", "::", "get_realCurrentUrl", "(", ")", ";", "}", "if", "(", "empty", "(", "$", "filter", ")", "&&", "empty", "(", "$", "queryFilter", ")", ")", "{", "return", "$", "pageURL", ";", "}", "if", "(", "empty", "(", "$", "filter", ")", ")", "{", "$", "filter", "=", "array", "(", "'http'", ",", "'name'", ",", "'port'", ",", "'path'", ",", "'request'", ")", ";", "}", "$", "urlParts", "=", "parse_url", "(", "$", "pageURL", ")", ";", "if", "(", "!", "in_array", "(", "'http'", ",", "$", "filter", ")", ")", "{", "$", "pageURL", "=", "preg_replace", "(", "'#.*://#'", ",", "''", ",", "$", "pageURL", ")", ";", "}", "if", "(", "!", "in_array", "(", "'name'", ",", "$", "filter", ")", "&&", "!", "in_array", "(", "'host'", ",", "$", "filter", ")", "&&", "array_key_exists", "(", "'host'", ",", "$", "urlParts", ")", ")", "{", "$", "pageURL", "=", "str_replace", "(", "$", "urlParts", "[", "'host'", "]", ",", "''", ",", "$", "pageURL", ")", ";", "}", "if", "(", "!", "in_array", "(", "'port'", ",", "$", "filter", ")", "&&", "array_key_exists", "(", "'port'", ",", "$", "urlParts", ")", ")", "{", "$", "pageURL", "=", "str_replace", "(", "':'", ".", "$", "urlParts", "[", "'port'", "]", ",", "''", ",", "$", "pageURL", ")", ";", "}", "if", "(", "!", "in_array", "(", "'path'", ",", "$", "filter", ")", "&&", "array_key_exists", "(", "'path'", ",", "$", "urlParts", ")", ")", "{", "$", "pageURL", "=", "str_replace", "(", "$", "urlParts", "[", "'path'", "]", ",", "''", ",", "$", "pageURL", ")", ";", "}", "if", "(", "(", "in_array", "(", "'request'", ",", "$", "filter", ")", "||", "in_array", "(", "'query'", ",", "$", "filter", ")", ")", "&&", "array_key_exists", "(", "'query'", ",", "$", "urlParts", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "queryFilter", ")", "&&", "is_array", "(", "$", "queryFilter", ")", ")", "{", "parse_str", "(", "$", "urlParts", "[", "'query'", "]", ",", "$", "query", ")", ";", "self", "::", "filter_data", "(", "$", "query", ",", "$", "queryFilter", ",", "$", "queryFilterMethod", ")", ";", "$", "pageURL", "=", "explode", "(", "'?'", ",", "$", "pageURL", ")", ";", "if", "(", "empty", "(", "$", "query", ")", ")", "{", "unset", "(", "$", "pageURL", "[", "1", "]", ")", ";", "}", "else", "{", "$", "pageURL", "[", "1", "]", "=", "http_build_query", "(", "$", "query", ")", ";", "}", "$", "pageURL", "=", "implode", "(", "'?'", ",", "$", "pageURL", ")", ";", "}", "}", "else", "{", "$", "pageURL", "=", "preg_replace", "(", "'/\\?.*/'", ",", "''", ",", "$", "pageURL", ")", ";", "}", "return", "$", "pageURL", ";", "}" ]
curPageURL returns the current url @param string|array $filter part or parts of the url structure that should be ignored. @return string the current URL
[ "curPageURL", "returns", "the", "current", "url" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1128-L1188
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.recursive_get
public static function recursive_get($obj, $path) { foreach (explode('|', $path) as $key) { if (is_object($obj)) { if (isset($obj->$key)) { $obj = $obj->$key; } else { return null; } } elseif (isset($obj[$key])) { $obj = $obj[$key]; } else { return null; } } return $obj; }
php
public static function recursive_get($obj, $path) { foreach (explode('|', $path) as $key) { if (is_object($obj)) { if (isset($obj->$key)) { $obj = $obj->$key; } else { return null; } } elseif (isset($obj[$key])) { $obj = $obj[$key]; } else { return null; } } return $obj; }
[ "public", "static", "function", "recursive_get", "(", "$", "obj", ",", "$", "path", ")", "{", "foreach", "(", "explode", "(", "'|'", ",", "$", "path", ")", "as", "$", "key", ")", "{", "if", "(", "is_object", "(", "$", "obj", ")", ")", "{", "if", "(", "isset", "(", "$", "obj", "->", "$", "key", ")", ")", "{", "$", "obj", "=", "$", "obj", "->", "$", "key", ";", "}", "else", "{", "return", "null", ";", "}", "}", "elseif", "(", "isset", "(", "$", "obj", "[", "$", "key", "]", ")", ")", "{", "$", "obj", "=", "$", "obj", "[", "$", "key", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}", "return", "$", "obj", ";", "}" ]
Handy function to dive into an array or object without knowing what it is nested keys can be separated by a pipe so it's possible to get a deeper key with only one call @access public @param mixed $obj array or object @param string $path the key or key-path (foo|bar) @return mixed the keys value or null if not found
[ "Handy", "function", "to", "dive", "into", "an", "array", "or", "object", "without", "knowing", "what", "it", "is", "nested", "keys", "can", "be", "separated", "by", "a", "pipe", "so", "it", "s", "possible", "to", "get", "a", "deeper", "key", "with", "only", "one", "call" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1241-L1257
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.recursive_unset
public static function recursive_unset(&$obj, $path) { $i = 1; foreach (($l = explode('|', $path)) as $key) { if (is_object($obj)) { if (isset($obj->$key)) { if (count($l) === $i) { unset($obj->$key); return true; } $obj = &$obj->$key; } else { return false; } } else { if (isset($obj[$key])) { if (count($l) === $i) { unset($obj[$key]); return true; } $obj = &$obj[$key]; } else { return false; } } $i++; } return null; }
php
public static function recursive_unset(&$obj, $path) { $i = 1; foreach (($l = explode('|', $path)) as $key) { if (is_object($obj)) { if (isset($obj->$key)) { if (count($l) === $i) { unset($obj->$key); return true; } $obj = &$obj->$key; } else { return false; } } else { if (isset($obj[$key])) { if (count($l) === $i) { unset($obj[$key]); return true; } $obj = &$obj[$key]; } else { return false; } } $i++; } return null; }
[ "public", "static", "function", "recursive_unset", "(", "&", "$", "obj", ",", "$", "path", ")", "{", "$", "i", "=", "1", ";", "foreach", "(", "(", "$", "l", "=", "explode", "(", "'|'", ",", "$", "path", ")", ")", "as", "$", "key", ")", "{", "if", "(", "is_object", "(", "$", "obj", ")", ")", "{", "if", "(", "isset", "(", "$", "obj", "->", "$", "key", ")", ")", "{", "if", "(", "count", "(", "$", "l", ")", "===", "$", "i", ")", "{", "unset", "(", "$", "obj", "->", "$", "key", ")", ";", "return", "true", ";", "}", "$", "obj", "=", "&", "$", "obj", "->", "$", "key", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "if", "(", "isset", "(", "$", "obj", "[", "$", "key", "]", ")", ")", "{", "if", "(", "count", "(", "$", "l", ")", "===", "$", "i", ")", "{", "unset", "(", "$", "obj", "[", "$", "key", "]", ")", ";", "return", "true", ";", "}", "$", "obj", "=", "&", "$", "obj", "[", "$", "key", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}", "$", "i", "++", ";", "}", "return", "null", ";", "}" ]
Handy function to unset a deep value of a class or an array. @access public @param mixed $obj the class or array containing the value to be unset. @param string $path the key or key-path (foo|bar|some|thing) @return mixed true if unset, false if key does not exist, null if key is invalid.
[ "Handy", "function", "to", "unset", "a", "deep", "value", "of", "a", "class", "or", "an", "array", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1340-L1368
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.unSlash
public static function unSlash($str, $unify = false) { return self::_slash($str, '/', false, false, $unify); }
php
public static function unSlash($str, $unify = false) { return self::_slash($str, '/', false, false, $unify); }
[ "public", "static", "function", "unSlash", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "'/'", ",", "false", ",", "false", ",", "$", "unify", ")", ";", "}" ]
remove potential slash from the end of the string. @access public @param string $str the string to be unslashed @param boolean $unify set true to unify all slashes in $str @return string the unslashed string
[ "remove", "potential", "slash", "from", "the", "end", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1481-L1484
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.unDS
public static function unDS($str, $unify = false) { return self::_slash($str, DIRECTORY_SEPARATOR, false, false, $unify); }
php
public static function unDS($str, $unify = false) { return self::_slash($str, DIRECTORY_SEPARATOR, false, false, $unify); }
[ "public", "static", "function", "unDS", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "DIRECTORY_SEPARATOR", ",", "false", ",", "false", ",", "$", "unify", ")", ";", "}" ]
remove potential DIRECTORY_SEPARATOR from the end of the string. @access public @param string $str the string to be unslashed @param boolean $unify set true to unify all slashes in $str @return string the unslashed string
[ "remove", "potential", "DIRECTORY_SEPARATOR", "from", "the", "end", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1494-L1497
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.unBackSlash
public static function unBackSlash($str, $unify = false) { return self::_slash($str, '\\', false, false, $unify); }
php
public static function unBackSlash($str, $unify = false) { return self::_slash($str, '\\', false, false, $unify); }
[ "public", "static", "function", "unBackSlash", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "'\\\\'", ",", "false", ",", "false", ",", "$", "unify", ")", ";", "}" ]
remove potential backslash from the end of the string. @access public @param string $str the string to be unbackslashed @param boolean $unify set true to unify all slashes in $str @return string the unbackslashed string
[ "remove", "potential", "backslash", "from", "the", "end", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1507-L1510
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.slash
public static function slash($str, $unify = false) { return self::_slash($str, '/', false, true, $unify); }
php
public static function slash($str, $unify = false) { return self::_slash($str, '/', false, true, $unify); }
[ "public", "static", "function", "slash", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "'/'", ",", "false", ",", "true", ",", "$", "unify", ")", ";", "}" ]
add slash to the end of the string. @access public @param string $str the string to be slashed @param boolean $unify set true to unify all slashes in $str @return string the slashed string
[ "add", "slash", "to", "the", "end", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1520-L1523
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.DS
public static function DS($str, $unify = false) { return self::_slash($str, DIRECTORY_SEPARATOR, false, true, $unify); }
php
public static function DS($str, $unify = false) { return self::_slash($str, DIRECTORY_SEPARATOR, false, true, $unify); }
[ "public", "static", "function", "DS", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "DIRECTORY_SEPARATOR", ",", "false", ",", "true", ",", "$", "unify", ")", ";", "}" ]
add DIRECTORY_SEPARATOR to the end of the string. @access public @param string $str the string to be slashed @param boolean $unify set true to unify all slashes in $str @return string the slashed string
[ "add", "DIRECTORY_SEPARATOR", "to", "the", "end", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1533-L1536
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.backSlash
public static function backSlash($str, $unify = false) { return self::_slash($str, '\\', false, true, $unify); }
php
public static function backSlash($str, $unify = false) { return self::_slash($str, '\\', false, true, $unify); }
[ "public", "static", "function", "backSlash", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "'\\\\'", ",", "false", ",", "true", ",", "$", "unify", ")", ";", "}" ]
add backslash to the end of the string. @access public @param string $str the string to be backslash @param boolean $unify set true to unify all slashes in $str @return string the backslashed string
[ "add", "backslash", "to", "the", "end", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1546-L1549
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.unPreSlash
public static function unPreSlash($str, $unify = false) { return self::_slash($str, '/', true, false, $unify); }
php
public static function unPreSlash($str, $unify = false) { return self::_slash($str, '/', true, false, $unify); }
[ "public", "static", "function", "unPreSlash", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "'/'", ",", "true", ",", "false", ",", "$", "unify", ")", ";", "}" ]
remove potential slash from the front of the string. @access public @param string $str the string to be unslashed @param boolean $unify set true to unify all slashes in $str @return string the unslashed string
[ "remove", "potential", "slash", "from", "the", "front", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1559-L1562
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.unPreDS
public static function unPreDS($str, $unify = false) { return self::_slash($str, DIRECTORY_SEPARATOR, true, false, $unify); }
php
public static function unPreDS($str, $unify = false) { return self::_slash($str, DIRECTORY_SEPARATOR, true, false, $unify); }
[ "public", "static", "function", "unPreDS", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "DIRECTORY_SEPARATOR", ",", "true", ",", "false", ",", "$", "unify", ")", ";", "}" ]
remove potential DIRECTORY_SEPARATOR from the front of the string. @access public @param string $str the string to be unslashed @param boolean $unify set true to unify all slashes in $str @return string the unslashed string
[ "remove", "potential", "DIRECTORY_SEPARATOR", "from", "the", "front", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1572-L1575
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.unPreBackSlash
public static function unPreBackSlash($str, $unify = false) { return self::_slash($str, '\\', true, false, $unify); }
php
public static function unPreBackSlash($str, $unify = false) { return self::_slash($str, '\\', true, false, $unify); }
[ "public", "static", "function", "unPreBackSlash", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "'\\\\'", ",", "true", ",", "false", ",", "$", "unify", ")", ";", "}" ]
remove potential backslash from the front of the string. @access public @param string $str the string to be unbackslashed @param boolean $unify set true to unify all slashes in $str @return string the unbackslashed string
[ "remove", "potential", "backslash", "from", "the", "front", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1585-L1588
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.preSlash
public static function preSlash($str, $unify = false) { return self::_slash($str, '/', true, true, $unify); }
php
public static function preSlash($str, $unify = false) { return self::_slash($str, '/', true, true, $unify); }
[ "public", "static", "function", "preSlash", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "'/'", ",", "true", ",", "true", ",", "$", "unify", ")", ";", "}" ]
add slash to the front of the string. @access public @param string $str the string to be slashed @param boolean $unify set true to unify all slashes in $str @return string the slashed string
[ "add", "slash", "to", "the", "front", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1598-L1601
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.preDS
public static function preDS($str, $unify = false) { return self::_slash($str, DIRECTORY_SEPARATOR, true, true, $unify); }
php
public static function preDS($str, $unify = false) { return self::_slash($str, DIRECTORY_SEPARATOR, true, true, $unify); }
[ "public", "static", "function", "preDS", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "DIRECTORY_SEPARATOR", ",", "true", ",", "true", ",", "$", "unify", ")", ";", "}" ]
add DIRECTORY_SEPARATOR to the front of the string. @access public @param string $str the string to be slashed @param boolean $unify set true to unify all slashes in $str @return string the slashed string
[ "add", "DIRECTORY_SEPARATOR", "to", "the", "front", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1611-L1614
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.preBackSlash
public static function preBackSlash($str, $unify = false) { return self::_slash($str, '\\', true, true, $unify); }
php
public static function preBackSlash($str, $unify = false) { return self::_slash($str, '\\', true, true, $unify); }
[ "public", "static", "function", "preBackSlash", "(", "$", "str", ",", "$", "unify", "=", "false", ")", "{", "return", "self", "::", "_slash", "(", "$", "str", ",", "'\\\\'", ",", "true", ",", "true", ",", "$", "unify", ")", ";", "}" ]
add backslash to the front of the string. @access public @param string $str the string to be backslashed @param boolean $unify set true to unify all slashes in $str @return string the backslashed string
[ "add", "backslash", "to", "the", "front", "of", "the", "string", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1624-L1627
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.is_cleanPath
public static function is_cleanPath($path, $clean = false, $regex = '!_-\w\/\\\ ') { if ($clean === true) { $path = self::get_directPath($path); } if (preg_match('/[^' . $regex . ']/', $path)) { return false; } return $path; }
php
public static function is_cleanPath($path, $clean = false, $regex = '!_-\w\/\\\ ') { if ($clean === true) { $path = self::get_directPath($path); } if (preg_match('/[^' . $regex . ']/', $path)) { return false; } return $path; }
[ "public", "static", "function", "is_cleanPath", "(", "$", "path", ",", "$", "clean", "=", "false", ",", "$", "regex", "=", "'!_-\\w\\/\\\\\\ '", ")", "{", "if", "(", "$", "clean", "===", "true", ")", "{", "$", "path", "=", "self", "::", "get_directPath", "(", "$", "path", ")", ";", "}", "if", "(", "preg_match", "(", "'/[^'", ".", "$", "regex", ".", "']/'", ",", "$", "path", ")", ")", "{", "return", "false", ";", "}", "return", "$", "path", ";", "}" ]
Checks if the path has invalid characters. @access public @param string $path @param bool $clean set true to call self::get_directPath() on $path @param string $regex the regex of valid chars @return void
[ "Checks", "if", "the", "path", "has", "invalid", "characters", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1653-L1662
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.get_static_var
public static function get_static_var($classname, $key) { $vars = get_class_vars($classname); if (isset($vars[$key])) { return $vars[$key]; } }
php
public static function get_static_var($classname, $key) { $vars = get_class_vars($classname); if (isset($vars[$key])) { return $vars[$key]; } }
[ "public", "static", "function", "get_static_var", "(", "$", "classname", ",", "$", "key", ")", "{", "$", "vars", "=", "get_class_vars", "(", "$", "classname", ")", ";", "if", "(", "isset", "(", "$", "vars", "[", "$", "key", "]", ")", ")", "{", "return", "$", "vars", "[", "$", "key", "]", ";", "}", "}" ]
Getter for Static Variables of Named Classes @access public @param string $classname @param string $key @return mixed
[ "Getter", "for", "Static", "Variables", "of", "Named", "Classes" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1744-L1750
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.get_dirArray
public static function get_dirArray($dir, $filenameKey = false, $filter = null, $positive = false) { /* * Normalize the Filter. */ if (empty($filter)) { $filter = array('.', '_'); } elseif(is_object($filter)) { $filter = self::ar($filter, null, true); } elseif(!is_array($filter)) { $filter = array($filter); } if ($handle = opendir($dir)) { $r = array(); $i = 0; while (false !== ($file = readdir($handle))) { $ok = !$positive; if (!empty($filter)) { foreach ($filter as $f) { if ($positive && strpos($file, $f) === 0) { $ok = true; break; } elseif(!$positive && strpos($file, $f) === 0) { $ok = false; break; } } } if (!$ok) { continue; } $k = $filenameKey ? $file : $i; $r[$k] = $file; $i++; } return $r; } else { return false; } }
php
public static function get_dirArray($dir, $filenameKey = false, $filter = null, $positive = false) { /* * Normalize the Filter. */ if (empty($filter)) { $filter = array('.', '_'); } elseif(is_object($filter)) { $filter = self::ar($filter, null, true); } elseif(!is_array($filter)) { $filter = array($filter); } if ($handle = opendir($dir)) { $r = array(); $i = 0; while (false !== ($file = readdir($handle))) { $ok = !$positive; if (!empty($filter)) { foreach ($filter as $f) { if ($positive && strpos($file, $f) === 0) { $ok = true; break; } elseif(!$positive && strpos($file, $f) === 0) { $ok = false; break; } } } if (!$ok) { continue; } $k = $filenameKey ? $file : $i; $r[$k] = $file; $i++; } return $r; } else { return false; } }
[ "public", "static", "function", "get_dirArray", "(", "$", "dir", ",", "$", "filenameKey", "=", "false", ",", "$", "filter", "=", "null", ",", "$", "positive", "=", "false", ")", "{", "/*\n * Normalize the Filter.\n */", "if", "(", "empty", "(", "$", "filter", ")", ")", "{", "$", "filter", "=", "array", "(", "'.'", ",", "'_'", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "filter", ")", ")", "{", "$", "filter", "=", "self", "::", "ar", "(", "$", "filter", ",", "null", ",", "true", ")", ";", "}", "elseif", "(", "!", "is_array", "(", "$", "filter", ")", ")", "{", "$", "filter", "=", "array", "(", "$", "filter", ")", ";", "}", "if", "(", "$", "handle", "=", "opendir", "(", "$", "dir", ")", ")", "{", "$", "r", "=", "array", "(", ")", ";", "$", "i", "=", "0", ";", "while", "(", "false", "!==", "(", "$", "file", "=", "readdir", "(", "$", "handle", ")", ")", ")", "{", "$", "ok", "=", "!", "$", "positive", ";", "if", "(", "!", "empty", "(", "$", "filter", ")", ")", "{", "foreach", "(", "$", "filter", "as", "$", "f", ")", "{", "if", "(", "$", "positive", "&&", "strpos", "(", "$", "file", ",", "$", "f", ")", "===", "0", ")", "{", "$", "ok", "=", "true", ";", "break", ";", "}", "elseif", "(", "!", "$", "positive", "&&", "strpos", "(", "$", "file", ",", "$", "f", ")", "===", "0", ")", "{", "$", "ok", "=", "false", ";", "break", ";", "}", "}", "}", "if", "(", "!", "$", "ok", ")", "{", "continue", ";", "}", "$", "k", "=", "$", "filenameKey", "?", "$", "file", ":", "$", "i", ";", "$", "r", "[", "$", "k", "]", "=", "$", "file", ";", "$", "i", "++", ";", "}", "return", "$", "r", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
returns an array of files in a specific folder, excluding files starting with . or _ The default filter can be adjusted as a third parameter. Accepted is an array with the amount of chars that will be filtered at the beginning of the file or folder name on the first index. The second index have to be another array containing strings that are not accepted. @access public @param string $dir the directory. @param mixed $filenameKey set true to use the filename as array key. @param array $filter an array with strings. Files starting with this string will be ignored. @param boolean $positive set true to invert the filter. Only files not starting with the filter string will be ignored @return array
[ "returns", "an", "array", "of", "files", "in", "a", "specific", "folder", "excluding", "files", "starting", "with", ".", "or", "_" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1769-L1810
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.getRequiredArgsError
public static function getRequiredArgsError($args, $requiredArgs) { if (!is_array($args) && !is_object($args)) { return sprintf(__('invalid type "%s" for $args', 'themaster'), gettype($args)); } if (!is_array($requiredArgs) && !is_object($args)) { return sprintf(__('invalid type "%s" for $requiredArgs', 'themaster'), gettype($requiredArgs)); } $missing = array(); foreach ($requiredArgs as $req) { if (!@isset($args[$req]) && !@isset($args->$req)) { $missing[] = $req; } } if (count($missing) == 0) { return false; } else { return sprintf( __('Missing %s as %s.', 'themaster'), self::readableList( $missing, ' '.__('and').' ', ', ', null, '"' ), (count($missing) === 1 ? 'a key' : 'keys') ); } }
php
public static function getRequiredArgsError($args, $requiredArgs) { if (!is_array($args) && !is_object($args)) { return sprintf(__('invalid type "%s" for $args', 'themaster'), gettype($args)); } if (!is_array($requiredArgs) && !is_object($args)) { return sprintf(__('invalid type "%s" for $requiredArgs', 'themaster'), gettype($requiredArgs)); } $missing = array(); foreach ($requiredArgs as $req) { if (!@isset($args[$req]) && !@isset($args->$req)) { $missing[] = $req; } } if (count($missing) == 0) { return false; } else { return sprintf( __('Missing %s as %s.', 'themaster'), self::readableList( $missing, ' '.__('and').' ', ', ', null, '"' ), (count($missing) === 1 ? 'a key' : 'keys') ); } }
[ "public", "static", "function", "getRequiredArgsError", "(", "$", "args", ",", "$", "requiredArgs", ")", "{", "if", "(", "!", "is_array", "(", "$", "args", ")", "&&", "!", "is_object", "(", "$", "args", ")", ")", "{", "return", "sprintf", "(", "__", "(", "'invalid type \"%s\" for $args'", ",", "'themaster'", ")", ",", "gettype", "(", "$", "args", ")", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "requiredArgs", ")", "&&", "!", "is_object", "(", "$", "args", ")", ")", "{", "return", "sprintf", "(", "__", "(", "'invalid type \"%s\" for $requiredArgs'", ",", "'themaster'", ")", ",", "gettype", "(", "$", "requiredArgs", ")", ")", ";", "}", "$", "missing", "=", "array", "(", ")", ";", "foreach", "(", "$", "requiredArgs", "as", "$", "req", ")", "{", "if", "(", "!", "@", "isset", "(", "$", "args", "[", "$", "req", "]", ")", "&&", "!", "@", "isset", "(", "$", "args", "->", "$", "req", ")", ")", "{", "$", "missing", "[", "]", "=", "$", "req", ";", "}", "}", "if", "(", "count", "(", "$", "missing", ")", "==", "0", ")", "{", "return", "false", ";", "}", "else", "{", "return", "sprintf", "(", "__", "(", "'Missing %s as %s.'", ",", "'themaster'", ")", ",", "self", "::", "readableList", "(", "$", "missing", ",", "' '", ".", "__", "(", "'and'", ")", ".", "' '", ",", "', '", ",", "null", ",", "'\"'", ")", ",", "(", "count", "(", "$", "missing", ")", "===", "1", "?", "'a key'", ":", "'keys'", ")", ")", ";", "}", "}" ]
Checks if Array 1 has all required keys, specified by Array 2 @access public @param array $args the array to be checked. @param array $requiredArgs the required keys. @return string|false Error string or false if no Error found.
[ "Checks", "if", "Array", "1", "has", "all", "required", "keys", "specified", "by", "Array", "2" ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1836-L1867
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.filter_urlQuery
public static function filter_urlQuery(&$url, $filterArr, $method = null, array $add = array()) { if ($method === null) { $method = 'remove'; } $pUrl = parse_url($url); $qry; if (isset($pUrl['query'])) { parse_str($pUrl['query'], $qry); } else { $qry = array(); } self::filter_data($qry, $filterArr, $method, $add); $pUrl['query'] = http_build_query($qry); if (empty($pUrl['query'])) { unset($pUrl['query']); } $url = self::unparse_url($pUrl); }
php
public static function filter_urlQuery(&$url, $filterArr, $method = null, array $add = array()) { if ($method === null) { $method = 'remove'; } $pUrl = parse_url($url); $qry; if (isset($pUrl['query'])) { parse_str($pUrl['query'], $qry); } else { $qry = array(); } self::filter_data($qry, $filterArr, $method, $add); $pUrl['query'] = http_build_query($qry); if (empty($pUrl['query'])) { unset($pUrl['query']); } $url = self::unparse_url($pUrl); }
[ "public", "static", "function", "filter_urlQuery", "(", "&", "$", "url", ",", "$", "filterArr", ",", "$", "method", "=", "null", ",", "array", "$", "add", "=", "array", "(", ")", ")", "{", "if", "(", "$", "method", "===", "null", ")", "{", "$", "method", "=", "'remove'", ";", "}", "$", "pUrl", "=", "parse_url", "(", "$", "url", ")", ";", "$", "qry", ";", "if", "(", "isset", "(", "$", "pUrl", "[", "'query'", "]", ")", ")", "{", "parse_str", "(", "$", "pUrl", "[", "'query'", "]", ",", "$", "qry", ")", ";", "}", "else", "{", "$", "qry", "=", "array", "(", ")", ";", "}", "self", "::", "filter_data", "(", "$", "qry", ",", "$", "filterArr", ",", "$", "method", ",", "$", "add", ")", ";", "$", "pUrl", "[", "'query'", "]", "=", "http_build_query", "(", "$", "qry", ")", ";", "if", "(", "empty", "(", "$", "pUrl", "[", "'query'", "]", ")", ")", "{", "unset", "(", "$", "pUrl", "[", "'query'", "]", ")", ";", "}", "$", "url", "=", "self", "::", "unparse_url", "(", "$", "pUrl", ")", ";", "}" ]
Parses an url adds and removes get-query arguments and rebuilds the url. @param string $url the url string @param array $filterArr Array of query keys that should be removed or kept. @param string $method 'remove' deletes all $filterArr keys from query, 'keep' deletes all args that are not in $filterArr @param array $add optional array of values to be added to the query @return void
[ "Parses", "an", "url", "adds", "and", "removes", "get", "-", "query", "arguments", "and", "rebuilds", "the", "url", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1922-L1942
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.filter_data
public static function filter_data(&$data, $filterArr, $method = null, $add = false) { if ($method === null) { $method = 'keep'; } foreach ($data as $k => $v) { if (($method == 'remove' && in_array($k, $filterArr)) || ($method == 'keep' && !in_array($k, $filterArr)) ) { if (is_array($data)) { unset($data[$k]); } elseif (is_object($data)) { unset($data->$k); } } } if (!empty($add)) { $data = self::merge_data($data, $add); } return $data; }
php
public static function filter_data(&$data, $filterArr, $method = null, $add = false) { if ($method === null) { $method = 'keep'; } foreach ($data as $k => $v) { if (($method == 'remove' && in_array($k, $filterArr)) || ($method == 'keep' && !in_array($k, $filterArr)) ) { if (is_array($data)) { unset($data[$k]); } elseif (is_object($data)) { unset($data->$k); } } } if (!empty($add)) { $data = self::merge_data($data, $add); } return $data; }
[ "public", "static", "function", "filter_data", "(", "&", "$", "data", ",", "$", "filterArr", ",", "$", "method", "=", "null", ",", "$", "add", "=", "false", ")", "{", "if", "(", "$", "method", "===", "null", ")", "{", "$", "method", "=", "'keep'", ";", "}", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "(", "$", "method", "==", "'remove'", "&&", "in_array", "(", "$", "k", ",", "$", "filterArr", ")", ")", "||", "(", "$", "method", "==", "'keep'", "&&", "!", "in_array", "(", "$", "k", ",", "$", "filterArr", ")", ")", ")", "{", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "unset", "(", "$", "data", "[", "$", "k", "]", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "data", ")", ")", "{", "unset", "(", "$", "data", "->", "$", "k", ")", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "add", ")", ")", "{", "$", "data", "=", "self", "::", "merge_data", "(", "$", "data", ",", "$", "add", ")", ";", "}", "return", "$", "data", ";", "}" ]
Filters entries of an array. @param string $data the source @param array $filterArr Array of keys keys that should be removed or kept. @param string $method 'remove' deletes all $filterArr keys from $data, 'keep' deletes all keys that are not in $filterArr @param array $add optional array of values to be added to $data @return array|object
[ "Filters", "entries", "of", "an", "array", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1954-L1977
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.merge_data
public static function merge_data($a, $b) { $args = func_get_args(); $t = $args[0]; $array = is_array($t); foreach ($args as $k => $a) { $args[$k] = self::ar($a); } $args = call_user_func_array('array_merge', $args); if (!$array) { $args = self::sc($args); } return $args; }
php
public static function merge_data($a, $b) { $args = func_get_args(); $t = $args[0]; $array = is_array($t); foreach ($args as $k => $a) { $args[$k] = self::ar($a); } $args = call_user_func_array('array_merge', $args); if (!$array) { $args = self::sc($args); } return $args; }
[ "public", "static", "function", "merge_data", "(", "$", "a", ",", "$", "b", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "t", "=", "$", "args", "[", "0", "]", ";", "$", "array", "=", "is_array", "(", "$", "t", ")", ";", "foreach", "(", "$", "args", "as", "$", "k", "=>", "$", "a", ")", "{", "$", "args", "[", "$", "k", "]", "=", "self", "::", "ar", "(", "$", "a", ")", ";", "}", "$", "args", "=", "call_user_func_array", "(", "'array_merge'", ",", "$", "args", ")", ";", "if", "(", "!", "$", "array", ")", "{", "$", "args", "=", "self", "::", "sc", "(", "$", "args", ")", ";", "}", "return", "$", "args", ";", "}" ]
Allows merging of arrays and objects. same usage as array_merge. @param array|object $a target @param array|object $b addition @return array|object same type as $a
[ "Allows", "merging", "of", "arrays", "and", "objects", ".", "same", "usage", "as", "array_merge", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L1988-L2005
train
Xiphe/THETOOLS
src/Xiphe/THETOOLS.php
THETOOLS.merge_data_recursive
public static function merge_data_recursive($a, $b) { $args = func_get_args(); $t = $args[0]; $array = is_array($t); foreach ($args as $k => $a) { $args[$k] = self::ar($a, null, true); } $args = call_user_func_array('array_merge_recursive', $args); if (!$array) { $args = self::sc($args, null, true); } return $args; }
php
public static function merge_data_recursive($a, $b) { $args = func_get_args(); $t = $args[0]; $array = is_array($t); foreach ($args as $k => $a) { $args[$k] = self::ar($a, null, true); } $args = call_user_func_array('array_merge_recursive', $args); if (!$array) { $args = self::sc($args, null, true); } return $args; }
[ "public", "static", "function", "merge_data_recursive", "(", "$", "a", ",", "$", "b", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "t", "=", "$", "args", "[", "0", "]", ";", "$", "array", "=", "is_array", "(", "$", "t", ")", ";", "foreach", "(", "$", "args", "as", "$", "k", "=>", "$", "a", ")", "{", "$", "args", "[", "$", "k", "]", "=", "self", "::", "ar", "(", "$", "a", ",", "null", ",", "true", ")", ";", "}", "$", "args", "=", "call_user_func_array", "(", "'array_merge_recursive'", ",", "$", "args", ")", ";", "if", "(", "!", "$", "array", ")", "{", "$", "args", "=", "self", "::", "sc", "(", "$", "args", ",", "null", ",", "true", ")", ";", "}", "return", "$", "args", ";", "}" ]
Allows deep merging of arrays and objects. same usage as array_merge_recursive. @param array|object $a target @param array|object $b addition @return array|object same type as $a
[ "Allows", "deep", "merging", "of", "arrays", "and", "objects", ".", "same", "usage", "as", "array_merge_recursive", "." ]
16e90e9523272ab48ca44e61d25f56aa1e7fa612
https://github.com/Xiphe/THETOOLS/blob/16e90e9523272ab48ca44e61d25f56aa1e7fa612/src/Xiphe/THETOOLS.php#L2016-L2033
train
Facebook-Anonymous-Publisher/shortener
src/ShortenerManager.php
ShortenerManager.driver
public function driver($driver = null) { $shortener = $this->app['config']['shortener']; $driver = $driver ?: $shortener['default']; $driverMethod = 'create'.ucfirst($driver).'Driver'; if (method_exists($this, $driverMethod)) { return $this->{$driverMethod}($shortener); } throw new InvalidArgumentException("Driver [{$driver}] is not supported."); }
php
public function driver($driver = null) { $shortener = $this->app['config']['shortener']; $driver = $driver ?: $shortener['default']; $driverMethod = 'create'.ucfirst($driver).'Driver'; if (method_exists($this, $driverMethod)) { return $this->{$driverMethod}($shortener); } throw new InvalidArgumentException("Driver [{$driver}] is not supported."); }
[ "public", "function", "driver", "(", "$", "driver", "=", "null", ")", "{", "$", "shortener", "=", "$", "this", "->", "app", "[", "'config'", "]", "[", "'shortener'", "]", ";", "$", "driver", "=", "$", "driver", "?", ":", "$", "shortener", "[", "'default'", "]", ";", "$", "driverMethod", "=", "'create'", ".", "ucfirst", "(", "$", "driver", ")", ".", "'Driver'", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "driverMethod", ")", ")", "{", "return", "$", "this", "->", "{", "$", "driverMethod", "}", "(", "$", "shortener", ")", ";", "}", "throw", "new", "InvalidArgumentException", "(", "\"Driver [{$driver}] is not supported.\"", ")", ";", "}" ]
Get a shortener driver instance. @param string|null $driver @return Base
[ "Get", "a", "shortener", "driver", "instance", "." ]
3b2e49d9cdd96758d35cf57a7a27659d2b6682aa
https://github.com/Facebook-Anonymous-Publisher/shortener/blob/3b2e49d9cdd96758d35cf57a7a27659d2b6682aa/src/ShortenerManager.php#L36-L49
train
shrink0r/php-schema
src/Property/EnumProperty.php
EnumProperty.validate
public function validate($value) { $result = Ok::unit(); foreach ($this->allowedTypes as $type) { $typeChecker = preg_match('/^&/', $type) ? $this->getCustomType($type) : $this->createProperty($type); $result = $typeChecker->validate($value); if ($result instanceof Ok) { return $result; } } return $result; }
php
public function validate($value) { $result = Ok::unit(); foreach ($this->allowedTypes as $type) { $typeChecker = preg_match('/^&/', $type) ? $this->getCustomType($type) : $this->createProperty($type); $result = $typeChecker->validate($value); if ($result instanceof Ok) { return $result; } } return $result; }
[ "public", "function", "validate", "(", "$", "value", ")", "{", "$", "result", "=", "Ok", "::", "unit", "(", ")", ";", "foreach", "(", "$", "this", "->", "allowedTypes", "as", "$", "type", ")", "{", "$", "typeChecker", "=", "preg_match", "(", "'/^&/'", ",", "$", "type", ")", "?", "$", "this", "->", "getCustomType", "(", "$", "type", ")", ":", "$", "this", "->", "createProperty", "(", "$", "type", ")", ";", "$", "result", "=", "$", "typeChecker", "->", "validate", "(", "$", "value", ")", ";", "if", "(", "$", "result", "instanceof", "Ok", ")", "{", "return", "$", "result", ";", "}", "}", "return", "$", "result", ";", "}" ]
Tells if a given value adhere's to one of the property's allowed types. @param mixed $value @return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned.
[ "Tells", "if", "a", "given", "value", "adhere", "s", "to", "one", "of", "the", "property", "s", "allowed", "types", "." ]
94293fe897af376dd9d05962e2c516079409dd29
https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/EnumProperty.php#L39-L52
train
shrink0r/php-schema
src/Property/EnumProperty.php
EnumProperty.getCustomType
protected function getCustomType($type) { $root = $this; while ($cur = $root->getParent()) { $root = $cur; } $customTypes = $root->getSchema()->getCustomTypes(); $type = ltrim($type, '&'); if (isset($customTypes[$type])) { return $customTypes[$type]; } throw new Exception("Unable to resolve '$type' to a custom type-definition."); }
php
protected function getCustomType($type) { $root = $this; while ($cur = $root->getParent()) { $root = $cur; } $customTypes = $root->getSchema()->getCustomTypes(); $type = ltrim($type, '&'); if (isset($customTypes[$type])) { return $customTypes[$type]; } throw new Exception("Unable to resolve '$type' to a custom type-definition."); }
[ "protected", "function", "getCustomType", "(", "$", "type", ")", "{", "$", "root", "=", "$", "this", ";", "while", "(", "$", "cur", "=", "$", "root", "->", "getParent", "(", ")", ")", "{", "$", "root", "=", "$", "cur", ";", "}", "$", "customTypes", "=", "$", "root", "->", "getSchema", "(", ")", "->", "getCustomTypes", "(", ")", ";", "$", "type", "=", "ltrim", "(", "$", "type", ",", "'&'", ")", ";", "if", "(", "isset", "(", "$", "customTypes", "[", "$", "type", "]", ")", ")", "{", "return", "$", "customTypes", "[", "$", "type", "]", ";", "}", "throw", "new", "Exception", "(", "\"Unable to resolve '$type' to a custom type-definition.\"", ")", ";", "}" ]
Retrieves a custom type definition by name, that will be used to proxy the property's validation to. @param string $type The name/key of the type prefixed with a '&'. @return SchemaInterface
[ "Retrieves", "a", "custom", "type", "definition", "by", "name", "that", "will", "be", "used", "to", "proxy", "the", "property", "s", "validation", "to", "." ]
94293fe897af376dd9d05962e2c516079409dd29
https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/EnumProperty.php#L61-L75
train
shrink0r/php-schema
src/Property/EnumProperty.php
EnumProperty.createProperty
protected function createProperty($type) { return $this->getSchema()->getFactory()->createProperty( [ 'type' => $type, 'name' => $this->getName().'_item', 'required' => true ], $this->getSchema(), $this ); }
php
protected function createProperty($type) { return $this->getSchema()->getFactory()->createProperty( [ 'type' => $type, 'name' => $this->getName().'_item', 'required' => true ], $this->getSchema(), $this ); }
[ "protected", "function", "createProperty", "(", "$", "type", ")", "{", "return", "$", "this", "->", "getSchema", "(", ")", "->", "getFactory", "(", ")", "->", "createProperty", "(", "[", "'type'", "=>", "$", "type", ",", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ".", "'_item'", ",", "'required'", "=>", "true", "]", ",", "$", "this", "->", "getSchema", "(", ")", ",", "$", "this", ")", ";", "}" ]
Creates a child-property that will be used as a proxy-target for the parent property's validation. @param string $type The type key of the property to create. @return PropertyInterface
[ "Creates", "a", "child", "-", "property", "that", "will", "be", "used", "as", "a", "proxy", "-", "target", "for", "the", "parent", "property", "s", "validation", "." ]
94293fe897af376dd9d05962e2c516079409dd29
https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/EnumProperty.php#L84-L91
train
dSpaceLabs/http-client
src/Client.php
Client.parse
public function parse($raw) { $lines = explode("\n", $raw); // Status Line preg_match('/HTTP\/(\d\.\d) (\d\d\d) (.*)/', $lines[0], $statusLine); $response = (new Response()) ->withProtocolVersion($statusLine[1]) ->withStatus($statusLine[2], $statusLine[3]); unset($lines[0]); // Headers foreach ($lines as $i => $line) { if ('' == trim($line)) { unset($lines[$i]); break; } $header = explode(': ', $line); $response = $response->withHeader($header[0], $header[1]); unset($lines[$i]); } // Body $stream = new Stream(fopen('php://memory', 'rw+')); $stream->write(implode("\n", $lines)); $stream->rewind(); $response = $response->withBody($stream); return $response; }
php
public function parse($raw) { $lines = explode("\n", $raw); // Status Line preg_match('/HTTP\/(\d\.\d) (\d\d\d) (.*)/', $lines[0], $statusLine); $response = (new Response()) ->withProtocolVersion($statusLine[1]) ->withStatus($statusLine[2], $statusLine[3]); unset($lines[0]); // Headers foreach ($lines as $i => $line) { if ('' == trim($line)) { unset($lines[$i]); break; } $header = explode(': ', $line); $response = $response->withHeader($header[0], $header[1]); unset($lines[$i]); } // Body $stream = new Stream(fopen('php://memory', 'rw+')); $stream->write(implode("\n", $lines)); $stream->rewind(); $response = $response->withBody($stream); return $response; }
[ "public", "function", "parse", "(", "$", "raw", ")", "{", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "raw", ")", ";", "// Status Line", "preg_match", "(", "'/HTTP\\/(\\d\\.\\d) (\\d\\d\\d) (.*)/'", ",", "$", "lines", "[", "0", "]", ",", "$", "statusLine", ")", ";", "$", "response", "=", "(", "new", "Response", "(", ")", ")", "->", "withProtocolVersion", "(", "$", "statusLine", "[", "1", "]", ")", "->", "withStatus", "(", "$", "statusLine", "[", "2", "]", ",", "$", "statusLine", "[", "3", "]", ")", ";", "unset", "(", "$", "lines", "[", "0", "]", ")", ";", "// Headers", "foreach", "(", "$", "lines", "as", "$", "i", "=>", "$", "line", ")", "{", "if", "(", "''", "==", "trim", "(", "$", "line", ")", ")", "{", "unset", "(", "$", "lines", "[", "$", "i", "]", ")", ";", "break", ";", "}", "$", "header", "=", "explode", "(", "': '", ",", "$", "line", ")", ";", "$", "response", "=", "$", "response", "->", "withHeader", "(", "$", "header", "[", "0", "]", ",", "$", "header", "[", "1", "]", ")", ";", "unset", "(", "$", "lines", "[", "$", "i", "]", ")", ";", "}", "// Body", "$", "stream", "=", "new", "Stream", "(", "fopen", "(", "'php://memory'", ",", "'rw+'", ")", ")", ";", "$", "stream", "->", "write", "(", "implode", "(", "\"\\n\"", ",", "$", "lines", ")", ")", ";", "$", "stream", "->", "rewind", "(", ")", ";", "$", "response", "=", "$", "response", "->", "withBody", "(", "$", "stream", ")", ";", "return", "$", "response", ";", "}" ]
Parses a Raw HTTP response and converts it into a response object @param string $raw @return \Psr\Http\Message\Response
[ "Parses", "a", "Raw", "HTTP", "response", "and", "converts", "it", "into", "a", "response", "object" ]
8e2a39f1db2a209012aa14f2828149c11761f2ae
https://github.com/dSpaceLabs/http-client/blob/8e2a39f1db2a209012aa14f2828149c11761f2ae/src/Client.php#L98-L127
train
Erebot/Module_IrcTracker
src/IrcTracker/Token.php
Token.getNick
public function getNick() { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_NICK ); }
php
public function getNick() { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_NICK ); }
[ "public", "function", "getNick", "(", ")", "{", "return", "$", "this", "->", "tracker", "->", "getInfo", "(", "$", "this", "->", "token", ",", "\\", "Erebot", "\\", "Module", "\\", "IrcTracker", "::", "INFO_NICK", ")", ";", "}" ]
Returns the nickname of the user represented by this identity. \retval mixed This user's nickname or NULL if unavailable.
[ "Returns", "the", "nickname", "of", "the", "user", "represented", "by", "this", "identity", "." ]
50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d
https://github.com/Erebot/Module_IrcTracker/blob/50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d/src/IrcTracker/Token.php#L55-L61
train
Erebot/Module_IrcTracker
src/IrcTracker/Token.php
Token.getIdent
public function getIdent() { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_IDENT ); }
php
public function getIdent() { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_IDENT ); }
[ "public", "function", "getIdent", "(", ")", "{", "return", "$", "this", "->", "tracker", "->", "getInfo", "(", "$", "this", "->", "token", ",", "\\", "Erebot", "\\", "Module", "\\", "IrcTracker", "::", "INFO_IDENT", ")", ";", "}" ]
Returns the identity string of the user represented by this identity. \retval mixed This user's identity string or NULL if unavailable. \note The name of this method is somewhat misleading, as it returns the "identity" as defined by the user in his/her client. This is not the same as the "identity" represented here (which contains additional information). To try to disambiguate, the term "identity string" has been used when referring to the user-defined identity.
[ "Returns", "the", "identity", "string", "of", "the", "user", "represented", "by", "this", "identity", "." ]
50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d
https://github.com/Erebot/Module_IrcTracker/blob/50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d/src/IrcTracker/Token.php#L80-L86
train
Erebot/Module_IrcTracker
src/IrcTracker/Token.php
Token.getHost
public function getHost($canonical) { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_HOST, array($canonical) ); }
php
public function getHost($canonical) { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_HOST, array($canonical) ); }
[ "public", "function", "getHost", "(", "$", "canonical", ")", "{", "return", "$", "this", "->", "tracker", "->", "getInfo", "(", "$", "this", "->", "token", ",", "\\", "Erebot", "\\", "Module", "\\", "IrcTracker", "::", "INFO_HOST", ",", "array", "(", "$", "canonical", ")", ")", ";", "}" ]
Returns the host of the user represented by this identity. \param opaque $canonical Either Erebot::Interfaces::Identity::CANON_IPV4 or Erebot::Interfaces::Identity::CANON_IPV6, indicating the type of IP canonicalization to use. \retval string This user's hostname or NULL if unavailable.
[ "Returns", "the", "host", "of", "the", "user", "represented", "by", "this", "identity", "." ]
50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d
https://github.com/Erebot/Module_IrcTracker/blob/50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d/src/IrcTracker/Token.php#L100-L107
train
Erebot/Module_IrcTracker
src/IrcTracker/Token.php
Token.getMask
public function getMask($canonical) { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_MASK, array($canonical) ); }
php
public function getMask($canonical) { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_MASK, array($canonical) ); }
[ "public", "function", "getMask", "(", "$", "canonical", ")", "{", "return", "$", "this", "->", "tracker", "->", "getInfo", "(", "$", "this", "->", "token", ",", "\\", "Erebot", "\\", "Module", "\\", "IrcTracker", "::", "INFO_MASK", ",", "array", "(", "$", "canonical", ")", ")", ";", "}" ]
Returns a mask which can later be used to match against this user. \param opaque $canonical Either Erebot::Interfaces::Identity::CANON_IPV4 or Erebot::Interfaces::Identity::CANON_IPV6, indicating the type of IP canonicalization to use. \retval string A mask matching against this user. \note Fields for which no value is available should be replaced with '*'. This can result in very generic masks (eg. "foo!*@*") if not enough information is known.
[ "Returns", "a", "mask", "which", "can", "later", "be", "used", "to", "match", "against", "this", "user", "." ]
50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d
https://github.com/Erebot/Module_IrcTracker/blob/50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d/src/IrcTracker/Token.php#L127-L134
train
Erebot/Module_IrcTracker
src/IrcTracker/Token.php
Token.isOn
public function isOn() { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_ISON ); }
php
public function isOn() { return $this->tracker->getInfo( $this->token, \Erebot\Module\IrcTracker::INFO_ISON ); }
[ "public", "function", "isOn", "(", ")", "{", "return", "$", "this", "->", "tracker", "->", "getInfo", "(", "$", "this", "->", "token", ",", "\\", "Erebot", "\\", "Module", "\\", "IrcTracker", "::", "INFO_ISON", ")", ";", "}" ]
Indicates whether the person associated with this token is still connected. \retval bool TRUE if the user associated with this token is still online, FALSE otherwise.
[ "Indicates", "whether", "the", "person", "associated", "with", "this", "token", "is", "still", "connected", "." ]
50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d
https://github.com/Erebot/Module_IrcTracker/blob/50eaf5d3e35cf4bb31259819cd3d4fba3279bc5d/src/IrcTracker/Token.php#L144-L150
train
mpf-soft/admin-widgets
form/fields/Autocomplete.php
Autocomplete.getInput
public function getInput() { $options = $this->htmlOptions; $options['class'] = (isset($options['class']) ? $options['class'] . ' ' : '') . 'input autocomplete'; $options['autc_ajax'] = ($this->ajaxUpdate?'1':'0'); $options['autc_url'] = $this->ajaxURL; $options['autc_for'] = str_replace(['[', ']'], '__', $this->getName()); $options['autc_minletters'] = $this->minLettersToSearch; $options['autc_insert'] = ($this->allowNewValues?'1':'0'); $this->ajaxExtraParams[WebApp::get()->request()->getCsrfKey()] = WebApp::get()->request()->getCsrfValue(); $options['autc_extraparams'] = json_encode($this->ajaxExtraParams); $opts = []; foreach ($this->options as $word){ $opts[] = "<li>$word</li>"; } $opts = implode("", $opts); return Form::get()->hiddenInput($this->getName(), $this->getValue(), ['id' => str_replace(['[', ']'], '__', $this->getName())]) . Form::get()->input("", "text", $this->getValue(), $options) . Html::get()->tag("div", "<ul>$opts</ul>", ['id' => 'options-for-' . $options['autc_for'], 'class' => 'form-autocomplete-list']) . Html::get()->scriptFile($this->form->getAssetsURL() . 'autocomplete.js'); }
php
public function getInput() { $options = $this->htmlOptions; $options['class'] = (isset($options['class']) ? $options['class'] . ' ' : '') . 'input autocomplete'; $options['autc_ajax'] = ($this->ajaxUpdate?'1':'0'); $options['autc_url'] = $this->ajaxURL; $options['autc_for'] = str_replace(['[', ']'], '__', $this->getName()); $options['autc_minletters'] = $this->minLettersToSearch; $options['autc_insert'] = ($this->allowNewValues?'1':'0'); $this->ajaxExtraParams[WebApp::get()->request()->getCsrfKey()] = WebApp::get()->request()->getCsrfValue(); $options['autc_extraparams'] = json_encode($this->ajaxExtraParams); $opts = []; foreach ($this->options as $word){ $opts[] = "<li>$word</li>"; } $opts = implode("", $opts); return Form::get()->hiddenInput($this->getName(), $this->getValue(), ['id' => str_replace(['[', ']'], '__', $this->getName())]) . Form::get()->input("", "text", $this->getValue(), $options) . Html::get()->tag("div", "<ul>$opts</ul>", ['id' => 'options-for-' . $options['autc_for'], 'class' => 'form-autocomplete-list']) . Html::get()->scriptFile($this->form->getAssetsURL() . 'autocomplete.js'); }
[ "public", "function", "getInput", "(", ")", "{", "$", "options", "=", "$", "this", "->", "htmlOptions", ";", "$", "options", "[", "'class'", "]", "=", "(", "isset", "(", "$", "options", "[", "'class'", "]", ")", "?", "$", "options", "[", "'class'", "]", ".", "' '", ":", "''", ")", ".", "'input autocomplete'", ";", "$", "options", "[", "'autc_ajax'", "]", "=", "(", "$", "this", "->", "ajaxUpdate", "?", "'1'", ":", "'0'", ")", ";", "$", "options", "[", "'autc_url'", "]", "=", "$", "this", "->", "ajaxURL", ";", "$", "options", "[", "'autc_for'", "]", "=", "str_replace", "(", "[", "'['", ",", "']'", "]", ",", "'__'", ",", "$", "this", "->", "getName", "(", ")", ")", ";", "$", "options", "[", "'autc_minletters'", "]", "=", "$", "this", "->", "minLettersToSearch", ";", "$", "options", "[", "'autc_insert'", "]", "=", "(", "$", "this", "->", "allowNewValues", "?", "'1'", ":", "'0'", ")", ";", "$", "this", "->", "ajaxExtraParams", "[", "WebApp", "::", "get", "(", ")", "->", "request", "(", ")", "->", "getCsrfKey", "(", ")", "]", "=", "WebApp", "::", "get", "(", ")", "->", "request", "(", ")", "->", "getCsrfValue", "(", ")", ";", "$", "options", "[", "'autc_extraparams'", "]", "=", "json_encode", "(", "$", "this", "->", "ajaxExtraParams", ")", ";", "$", "opts", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "options", "as", "$", "word", ")", "{", "$", "opts", "[", "]", "=", "\"<li>$word</li>\"", ";", "}", "$", "opts", "=", "implode", "(", "\"\"", ",", "$", "opts", ")", ";", "return", "Form", "::", "get", "(", ")", "->", "hiddenInput", "(", "$", "this", "->", "getName", "(", ")", ",", "$", "this", "->", "getValue", "(", ")", ",", "[", "'id'", "=>", "str_replace", "(", "[", "'['", ",", "']'", "]", ",", "'__'", ",", "$", "this", "->", "getName", "(", ")", ")", "]", ")", ".", "Form", "::", "get", "(", ")", "->", "input", "(", "\"\"", ",", "\"text\"", ",", "$", "this", "->", "getValue", "(", ")", ",", "$", "options", ")", ".", "Html", "::", "get", "(", ")", "->", "tag", "(", "\"div\"", ",", "\"<ul>$opts</ul>\"", ",", "[", "'id'", "=>", "'options-for-'", ".", "$", "options", "[", "'autc_for'", "]", ",", "'class'", "=>", "'form-autocomplete-list'", "]", ")", ".", "Html", "::", "get", "(", ")", "->", "scriptFile", "(", "$", "this", "->", "form", "->", "getAssetsURL", "(", ")", ".", "'autocomplete.js'", ")", ";", "}" ]
Get the input; @return string
[ "Get", "the", "input", ";" ]
92597f9a09d086664268d6b7e0111d5a5586d8c7
https://github.com/mpf-soft/admin-widgets/blob/92597f9a09d086664268d6b7e0111d5a5586d8c7/form/fields/Autocomplete.php#L60-L79
train
rawphp/RawLog
src/RawPHP/RawLog/Handler/MailHandler.php
MailHandler.init
public function init( $config = [ ] ) { foreach ( $config as $key => $value ) { switch ( $key ) { case 'level': $this->_level = ( int ) $value; break; case 'mailer': $this->_mailer = $value; break; case 'formatter': $this->_formatter = new $value(); break; default: // do nothing break; } } }
php
public function init( $config = [ ] ) { foreach ( $config as $key => $value ) { switch ( $key ) { case 'level': $this->_level = ( int ) $value; break; case 'mailer': $this->_mailer = $value; break; case 'formatter': $this->_formatter = new $value(); break; default: // do nothing break; } } }
[ "public", "function", "init", "(", "$", "config", "=", "[", "]", ")", "{", "foreach", "(", "$", "config", "as", "$", "key", "=>", "$", "value", ")", "{", "switch", "(", "$", "key", ")", "{", "case", "'level'", ":", "$", "this", "->", "_level", "=", "(", "int", ")", "$", "value", ";", "break", ";", "case", "'mailer'", ":", "$", "this", "->", "_mailer", "=", "$", "value", ";", "break", ";", "case", "'formatter'", ":", "$", "this", "->", "_formatter", "=", "new", "$", "value", "(", ")", ";", "break", ";", "default", ":", "// do nothing", "break", ";", "}", "}", "}" ]
Initialises the handler. @param array $config configuration array
[ "Initialises", "the", "handler", "." ]
caee6c1ae92015c9b8481302d0bda5bf4ef9d1b6
https://github.com/rawphp/RawLog/blob/caee6c1ae92015c9b8481302d0bda5bf4ef9d1b6/src/RawPHP/RawLog/Handler/MailHandler.php#L84-L107
train
shadowfax/zf2-asset-manager
src/AssetManager/Asset/Resolver/AssetPathStack.php
AssetPathStack.normalizePath
public static function normalizePath($path) { $path = rtrim($path, '/'); $path = rtrim($path, '\\'); $path .= DIRECTORY_SEPARATOR; return $path; }
php
public static function normalizePath($path) { $path = rtrim($path, '/'); $path = rtrim($path, '\\'); $path .= DIRECTORY_SEPARATOR; return $path; }
[ "public", "static", "function", "normalizePath", "(", "$", "path", ")", "{", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'\\\\'", ")", ";", "$", "path", ".=", "DIRECTORY_SEPARATOR", ";", "return", "$", "path", ";", "}" ]
Normalize a path for insertion in the stack @param string $path @return string
[ "Normalize", "a", "path", "for", "insertion", "in", "the", "stack" ]
adbdc40417c6fddbba1a8c8b675e59ce1a25ad65
https://github.com/shadowfax/zf2-asset-manager/blob/adbdc40417c6fddbba1a8c8b675e59ce1a25ad65/src/AssetManager/Asset/Resolver/AssetPathStack.php#L113-L119
train
shadowfax/zf2-asset-manager
src/AssetManager/Asset/Resolver/AssetPathStack.php
AssetPathStack.resolve
public function resolve($name) { if (preg_match('#\.\.[\\\/]#', $name)) { throw new Exception\DomainException( 'Requested asset may not include parent directory traversal ("../", "..\\" notation)' ); } // Check if we have paths if (!count($this->paths)) { //$this->lastLookupFailure = static::FAILURE_NO_PATHS; return null; } // TODO: Check cache!!! $files = array(); foreach ($this->paths as $path) { $file = new SplFileInfo($path . $name); if ($file->isReadable()) { // Found! Return it. if (($filePath = $file->getRealPath()) === false && substr($path, 0, 7) === 'phar://') { // Do not try to expand phar paths (realpath + phars == fail) $filePath = $path . $name; if (!file_exists($filePath)) { break; } } $files[] = $filePath; } } $count = count($files); if ($count > 1) { $canAppend = $this->canAppend($name); if ($canAppend) { $content = ''; foreach ($files as $file) { $fileContent = file_get_contents($file); if ($fileContents) { $content .= $fileContent; } } return $content; } else { // TODO: Create an exception throw new \Exception("Too many assets found."); } } elseif($count === 1) { $content = file_get_contents($files[0]); if ($content) { return $content; } } return null; }
php
public function resolve($name) { if (preg_match('#\.\.[\\\/]#', $name)) { throw new Exception\DomainException( 'Requested asset may not include parent directory traversal ("../", "..\\" notation)' ); } // Check if we have paths if (!count($this->paths)) { //$this->lastLookupFailure = static::FAILURE_NO_PATHS; return null; } // TODO: Check cache!!! $files = array(); foreach ($this->paths as $path) { $file = new SplFileInfo($path . $name); if ($file->isReadable()) { // Found! Return it. if (($filePath = $file->getRealPath()) === false && substr($path, 0, 7) === 'phar://') { // Do not try to expand phar paths (realpath + phars == fail) $filePath = $path . $name; if (!file_exists($filePath)) { break; } } $files[] = $filePath; } } $count = count($files); if ($count > 1) { $canAppend = $this->canAppend($name); if ($canAppend) { $content = ''; foreach ($files as $file) { $fileContent = file_get_contents($file); if ($fileContents) { $content .= $fileContent; } } return $content; } else { // TODO: Create an exception throw new \Exception("Too many assets found."); } } elseif($count === 1) { $content = file_get_contents($files[0]); if ($content) { return $content; } } return null; }
[ "public", "function", "resolve", "(", "$", "name", ")", "{", "if", "(", "preg_match", "(", "'#\\.\\.[\\\\\\/]#'", ",", "$", "name", ")", ")", "{", "throw", "new", "Exception", "\\", "DomainException", "(", "'Requested asset may not include parent directory traversal (\"../\", \"..\\\\\" notation)'", ")", ";", "}", "// Check if we have paths", "if", "(", "!", "count", "(", "$", "this", "->", "paths", ")", ")", "{", "//$this->lastLookupFailure = static::FAILURE_NO_PATHS;", "return", "null", ";", "}", "// TODO: Check cache!!!", "$", "files", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "paths", "as", "$", "path", ")", "{", "$", "file", "=", "new", "SplFileInfo", "(", "$", "path", ".", "$", "name", ")", ";", "if", "(", "$", "file", "->", "isReadable", "(", ")", ")", "{", "// Found! Return it.", "if", "(", "(", "$", "filePath", "=", "$", "file", "->", "getRealPath", "(", ")", ")", "===", "false", "&&", "substr", "(", "$", "path", ",", "0", ",", "7", ")", "===", "'phar://'", ")", "{", "// Do not try to expand phar paths (realpath + phars == fail)", "$", "filePath", "=", "$", "path", ".", "$", "name", ";", "if", "(", "!", "file_exists", "(", "$", "filePath", ")", ")", "{", "break", ";", "}", "}", "$", "files", "[", "]", "=", "$", "filePath", ";", "}", "}", "$", "count", "=", "count", "(", "$", "files", ")", ";", "if", "(", "$", "count", ">", "1", ")", "{", "$", "canAppend", "=", "$", "this", "->", "canAppend", "(", "$", "name", ")", ";", "if", "(", "$", "canAppend", ")", "{", "$", "content", "=", "''", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "fileContent", "=", "file_get_contents", "(", "$", "file", ")", ";", "if", "(", "$", "fileContents", ")", "{", "$", "content", ".=", "$", "fileContent", ";", "}", "}", "return", "$", "content", ";", "}", "else", "{", "// TODO: Create an exception", "throw", "new", "\\", "Exception", "(", "\"Too many assets found.\"", ")", ";", "}", "}", "elseif", "(", "$", "count", "===", "1", ")", "{", "$", "content", "=", "file_get_contents", "(", "$", "files", "[", "0", "]", ")", ";", "if", "(", "$", "content", ")", "{", "return", "$", "content", ";", "}", "}", "return", "null", ";", "}" ]
Retrieve the filesystem path to a view script @param string $name @param null|Renderer $renderer @return string @throws Exception\DomainException
[ "Retrieve", "the", "filesystem", "path", "to", "a", "view", "script" ]
adbdc40417c6fddbba1a8c8b675e59ce1a25ad65
https://github.com/shadowfax/zf2-asset-manager/blob/adbdc40417c6fddbba1a8c8b675e59ce1a25ad65/src/AssetManager/Asset/Resolver/AssetPathStack.php#L177-L234
train
gplcart/cli
controllers/commands/ProductClassField.php
ProductClassField.cmdGetProductClassField
public function cmdGetProductClassField() { $result = $this->getListProductClassField(); $this->outputFormat($result); $this->outputFormatTableProductClassField($result); $this->output(); }
php
public function cmdGetProductClassField() { $result = $this->getListProductClassField(); $this->outputFormat($result); $this->outputFormatTableProductClassField($result); $this->output(); }
[ "public", "function", "cmdGetProductClassField", "(", ")", "{", "$", "result", "=", "$", "this", "->", "getListProductClassField", "(", ")", ";", "$", "this", "->", "outputFormat", "(", "$", "result", ")", ";", "$", "this", "->", "outputFormatTableProductClassField", "(", "$", "result", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "product-class-field-get" command
[ "Callback", "for", "product", "-", "class", "-", "field", "-", "get", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClassField.php#L40-L46
train
gplcart/cli
controllers/commands/ProductClassField.php
ProductClassField.cmdUpdateProductClassField
public function cmdUpdateProductClassField() { $params = $this->getParam(); if (empty($params[0]) || count($params) < 2) { $this->errorAndExit($this->text('Invalid command')); } if (!is_numeric($params[0])) { $this->errorAndExit($this->text('Invalid argument')); } $this->setSubmitted(null, $params); $this->setSubmitted('update', $params[0]); $this->validateComponent('product_class_field'); $this->updateProductClassField($params[0]); $this->output(); }
php
public function cmdUpdateProductClassField() { $params = $this->getParam(); if (empty($params[0]) || count($params) < 2) { $this->errorAndExit($this->text('Invalid command')); } if (!is_numeric($params[0])) { $this->errorAndExit($this->text('Invalid argument')); } $this->setSubmitted(null, $params); $this->setSubmitted('update', $params[0]); $this->validateComponent('product_class_field'); $this->updateProductClassField($params[0]); $this->output(); }
[ "public", "function", "cmdUpdateProductClassField", "(", ")", "{", "$", "params", "=", "$", "this", "->", "getParam", "(", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "0", "]", ")", "||", "count", "(", "$", "params", ")", "<", "2", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid command'", ")", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "params", "[", "0", "]", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "params", ")", ";", "$", "this", "->", "setSubmitted", "(", "'update'", ",", "$", "params", "[", "0", "]", ")", ";", "$", "this", "->", "validateComponent", "(", "'product_class_field'", ")", ";", "$", "this", "->", "updateProductClassField", "(", "$", "params", "[", "0", "]", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "product-class-field-update" command
[ "Callback", "for", "product", "-", "class", "-", "field", "-", "update", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClassField.php#L116-L134
train
gplcart/cli
controllers/commands/ProductClassField.php
ProductClassField.getListProductClassField
protected function getListProductClassField() { $id = $this->getParam(0); if (!isset($id)) { return $this->product_class_field->getList(array('limit' => $this->getLimit())); } if ($this->getParam('class')) { return $this->product_class_field->getList(array('product_class_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('field')) { return $this->product_class_field->getList(array('field_id' => $id, 'limit' => $this->getLimit())); } if (!is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } $result = $this->product_class_field->get($id); if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } return array($result); }
php
protected function getListProductClassField() { $id = $this->getParam(0); if (!isset($id)) { return $this->product_class_field->getList(array('limit' => $this->getLimit())); } if ($this->getParam('class')) { return $this->product_class_field->getList(array('product_class_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('field')) { return $this->product_class_field->getList(array('field_id' => $id, 'limit' => $this->getLimit())); } if (!is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } $result = $this->product_class_field->get($id); if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } return array($result); }
[ "protected", "function", "getListProductClassField", "(", ")", "{", "$", "id", "=", "$", "this", "->", "getParam", "(", "0", ")", ";", "if", "(", "!", "isset", "(", "$", "id", ")", ")", "{", "return", "$", "this", "->", "product_class_field", "->", "getList", "(", "array", "(", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'class'", ")", ")", "{", "return", "$", "this", "->", "product_class_field", "->", "getList", "(", "array", "(", "'product_class_id'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'field'", ")", ")", "{", "return", "$", "this", "->", "product_class_field", "->", "getList", "(", "array", "(", "'field_id'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "$", "result", "=", "$", "this", "->", "product_class_field", "->", "get", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "return", "array", "(", "$", "result", ")", ";", "}" ]
Returns an array of product class fields @return array
[ "Returns", "an", "array", "of", "product", "class", "fields" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClassField.php#L140-L167
train
gplcart/cli
controllers/commands/ProductClassField.php
ProductClassField.addProductClassField
protected function addProductClassField() { if (!$this->isError()) { $id = $this->product_class_field->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
php
protected function addProductClassField() { if (!$this->isError()) { $id = $this->product_class_field->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
[ "protected", "function", "addProductClassField", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isError", "(", ")", ")", "{", "$", "id", "=", "$", "this", "->", "product_class_field", "->", "add", "(", "$", "this", "->", "getSubmitted", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "$", "this", "->", "line", "(", "$", "id", ")", ";", "}", "}" ]
Add a new product class field
[ "Add", "a", "new", "product", "class", "field" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClassField.php#L203-L212
train
gplcart/cli
controllers/commands/ProductClassField.php
ProductClassField.updateProductClassField
protected function updateProductClassField($product_class_field_id) { if (!$this->isError() && !$this->product_class_field->update($product_class_field_id, $this->getSubmitted())) { $this->errorAndExit($this->text('Unexpected result')); } }
php
protected function updateProductClassField($product_class_field_id) { if (!$this->isError() && !$this->product_class_field->update($product_class_field_id, $this->getSubmitted())) { $this->errorAndExit($this->text('Unexpected result')); } }
[ "protected", "function", "updateProductClassField", "(", "$", "product_class_field_id", ")", "{", "if", "(", "!", "$", "this", "->", "isError", "(", ")", "&&", "!", "$", "this", "->", "product_class_field", "->", "update", "(", "$", "product_class_field_id", ",", "$", "this", "->", "getSubmitted", "(", ")", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "}" ]
Updates a product class field @param string $product_class_field_id
[ "Updates", "a", "product", "class", "field" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClassField.php#L218-L223
train
gplcart/cli
controllers/commands/ProductClassField.php
ProductClassField.submitAddProductClassField
protected function submitAddProductClassField() { $this->setSubmitted(null, $this->getParam()); $this->validateComponent('product_class_field'); $this->addProductClassField(); }
php
protected function submitAddProductClassField() { $this->setSubmitted(null, $this->getParam()); $this->validateComponent('product_class_field'); $this->addProductClassField(); }
[ "protected", "function", "submitAddProductClassField", "(", ")", "{", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "this", "->", "getParam", "(", ")", ")", ";", "$", "this", "->", "validateComponent", "(", "'product_class_field'", ")", ";", "$", "this", "->", "addProductClassField", "(", ")", ";", "}" ]
Add a new product class field at once
[ "Add", "a", "new", "product", "class", "field", "at", "once" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClassField.php#L228-L233
train
gplcart/cli
controllers/commands/ProductClassField.php
ProductClassField.wizardAddProductClassField
protected function wizardAddProductClassField() { // Required $this->validatePrompt('product_class_id', $this->text('Product class'), 'product_class_field'); $this->validatePrompt('field_id', $this->text('Field ID'), 'product_class_field'); // Optional $this->validatePrompt('required', $this->text('Required'), 'product_class_field', 0); $this->validatePrompt('multiple', $this->text('Multiple'), 'product_class_field', 0); $this->validateComponent('product_class_field'); $this->addProductClassField(); }
php
protected function wizardAddProductClassField() { // Required $this->validatePrompt('product_class_id', $this->text('Product class'), 'product_class_field'); $this->validatePrompt('field_id', $this->text('Field ID'), 'product_class_field'); // Optional $this->validatePrompt('required', $this->text('Required'), 'product_class_field', 0); $this->validatePrompt('multiple', $this->text('Multiple'), 'product_class_field', 0); $this->validateComponent('product_class_field'); $this->addProductClassField(); }
[ "protected", "function", "wizardAddProductClassField", "(", ")", "{", "// Required", "$", "this", "->", "validatePrompt", "(", "'product_class_id'", ",", "$", "this", "->", "text", "(", "'Product class'", ")", ",", "'product_class_field'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'field_id'", ",", "$", "this", "->", "text", "(", "'Field ID'", ")", ",", "'product_class_field'", ")", ";", "// Optional", "$", "this", "->", "validatePrompt", "(", "'required'", ",", "$", "this", "->", "text", "(", "'Required'", ")", ",", "'product_class_field'", ",", "0", ")", ";", "$", "this", "->", "validatePrompt", "(", "'multiple'", ",", "$", "this", "->", "text", "(", "'Multiple'", ")", ",", "'product_class_field'", ",", "0", ")", ";", "$", "this", "->", "validateComponent", "(", "'product_class_field'", ")", ";", "$", "this", "->", "addProductClassField", "(", ")", ";", "}" ]
Add a new product class field step by step
[ "Add", "a", "new", "product", "class", "field", "step", "by", "step" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClassField.php#L238-L250
train
phpffcms/ffcms-core
src/Network/Request/MvcFeatures.php
MvcFeatures.searchRedirect
private function searchRedirect(): void { // calculated depend of language $pathway = $this->getPathInfo(); /** @var array $routing */ $routing = App::$Properties->getAll('Routing'); if (!Any::isArray($routing) || !isset($routing['Redirect']) || !Any::isArray($routing['Redirect'])) { return; } // check if source uri is key in redirect target map if (array_key_exists($pathway, $routing['Redirect'])) { $target = $this->getSchemeAndHttpHost(); // . $this->getBasePath() . '/' . rtrim($routing['Redirect'][$pathway], '/'); if ($this->getBasePath() !== null && !Str::likeEmpty($this->getBasePath())) { $target .= '/' . $this->getBasePath(); } $target .= rtrim($routing['Redirect'][$pathway], '/'); $redirect = new RedirectResponse($target); $redirect->send(); exit(); } }
php
private function searchRedirect(): void { // calculated depend of language $pathway = $this->getPathInfo(); /** @var array $routing */ $routing = App::$Properties->getAll('Routing'); if (!Any::isArray($routing) || !isset($routing['Redirect']) || !Any::isArray($routing['Redirect'])) { return; } // check if source uri is key in redirect target map if (array_key_exists($pathway, $routing['Redirect'])) { $target = $this->getSchemeAndHttpHost(); // . $this->getBasePath() . '/' . rtrim($routing['Redirect'][$pathway], '/'); if ($this->getBasePath() !== null && !Str::likeEmpty($this->getBasePath())) { $target .= '/' . $this->getBasePath(); } $target .= rtrim($routing['Redirect'][$pathway], '/'); $redirect = new RedirectResponse($target); $redirect->send(); exit(); } }
[ "private", "function", "searchRedirect", "(", ")", ":", "void", "{", "// calculated depend of language", "$", "pathway", "=", "$", "this", "->", "getPathInfo", "(", ")", ";", "/** @var array $routing */", "$", "routing", "=", "App", "::", "$", "Properties", "->", "getAll", "(", "'Routing'", ")", ";", "if", "(", "!", "Any", "::", "isArray", "(", "$", "routing", ")", "||", "!", "isset", "(", "$", "routing", "[", "'Redirect'", "]", ")", "||", "!", "Any", "::", "isArray", "(", "$", "routing", "[", "'Redirect'", "]", ")", ")", "{", "return", ";", "}", "// check if source uri is key in redirect target map", "if", "(", "array_key_exists", "(", "$", "pathway", ",", "$", "routing", "[", "'Redirect'", "]", ")", ")", "{", "$", "target", "=", "$", "this", "->", "getSchemeAndHttpHost", "(", ")", ";", "// . $this->getBasePath() . '/' . rtrim($routing['Redirect'][$pathway], '/');", "if", "(", "$", "this", "->", "getBasePath", "(", ")", "!==", "null", "&&", "!", "Str", "::", "likeEmpty", "(", "$", "this", "->", "getBasePath", "(", ")", ")", ")", "{", "$", "target", ".=", "'/'", ".", "$", "this", "->", "getBasePath", "(", ")", ";", "}", "$", "target", ".=", "rtrim", "(", "$", "routing", "[", "'Redirect'", "]", "[", "$", "pathway", "]", ",", "'/'", ")", ";", "$", "redirect", "=", "new", "RedirectResponse", "(", "$", "target", ")", ";", "$", "redirect", "->", "send", "(", ")", ";", "exit", "(", ")", ";", "}", "}" ]
Check if current url in redirect map @return void
[ "Check", "if", "current", "url", "in", "redirect", "map" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Network/Request/MvcFeatures.php#L24-L46
train
phpffcms/ffcms-core
src/Network/Request/MvcFeatures.php
MvcFeatures.setPathdata
private function setPathdata(?array $pathArray = null): void { if (!Any::isArray($pathArray) || count($pathArray) < 1) { return; } // extract controller info from full path array $this->controller = ucfirst(Str::lowerCase(array_shift($pathArray))); if (count($pathArray) > 0) { // extract action $this->action = ucfirst(Str::lowerCase(array_shift($pathArray))); // safe other parts to arguments if exist if (count($pathArray) > 0) { $this->args = array_map(function ($in) { return Any::isStr($in) ? urldecode($in) : $in; }, $pathArray); } } }
php
private function setPathdata(?array $pathArray = null): void { if (!Any::isArray($pathArray) || count($pathArray) < 1) { return; } // extract controller info from full path array $this->controller = ucfirst(Str::lowerCase(array_shift($pathArray))); if (count($pathArray) > 0) { // extract action $this->action = ucfirst(Str::lowerCase(array_shift($pathArray))); // safe other parts to arguments if exist if (count($pathArray) > 0) { $this->args = array_map(function ($in) { return Any::isStr($in) ? urldecode($in) : $in; }, $pathArray); } } }
[ "private", "function", "setPathdata", "(", "?", "array", "$", "pathArray", "=", "null", ")", ":", "void", "{", "if", "(", "!", "Any", "::", "isArray", "(", "$", "pathArray", ")", "||", "count", "(", "$", "pathArray", ")", "<", "1", ")", "{", "return", ";", "}", "// extract controller info from full path array", "$", "this", "->", "controller", "=", "ucfirst", "(", "Str", "::", "lowerCase", "(", "array_shift", "(", "$", "pathArray", ")", ")", ")", ";", "if", "(", "count", "(", "$", "pathArray", ")", ">", "0", ")", "{", "// extract action", "$", "this", "->", "action", "=", "ucfirst", "(", "Str", "::", "lowerCase", "(", "array_shift", "(", "$", "pathArray", ")", ")", ")", ";", "// safe other parts to arguments if exist", "if", "(", "count", "(", "$", "pathArray", ")", ">", "0", ")", "{", "$", "this", "->", "args", "=", "array_map", "(", "function", "(", "$", "in", ")", "{", "return", "Any", "::", "isStr", "(", "$", "in", ")", "?", "urldecode", "(", "$", "in", ")", ":", "$", "in", ";", "}", ",", "$", "pathArray", ")", ";", "}", "}", "}" ]
Working with path array data @param array|null $pathArray @return void
[ "Working", "with", "path", "array", "data" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Network/Request/MvcFeatures.php#L53-L72
train
ScaraMVC/Framework
src/Scara/Http/Controller.php
Controller.add
public function add($key, $value = null) { $this->_view->with($key, $value); return $this; }
php
public function add($key, $value = null) { $this->_view->with($key, $value); return $this; }
[ "public", "function", "add", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "$", "this", "->", "_view", "->", "with", "(", "$", "key", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Adds data to the view class that will pass on to the view. @param string $key - Data's key @param mixed $value - $key's value @return \Scara\Http\Controller
[ "Adds", "data", "to", "the", "view", "class", "that", "will", "pass", "on", "to", "the", "view", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Controller.php#L82-L87
train
ScaraMVC/Framework
src/Scara/Http/Controller.php
Controller.withErrors
public function withErrors($validator) { foreach ($validator->errors() as $key => $value) { if (count($value) > 1) { for ($i = 0; $i < count($value); $i++) { $data[$key][$i] = $value[$i]; } } else { $data[$key] = $value[0]; } $this->_errors->add((object) $data); } $this->_session->flash('errors', $this->_errors->all()); return $this; }
php
public function withErrors($validator) { foreach ($validator->errors() as $key => $value) { if (count($value) > 1) { for ($i = 0; $i < count($value); $i++) { $data[$key][$i] = $value[$i]; } } else { $data[$key] = $value[0]; } $this->_errors->add((object) $data); } $this->_session->flash('errors', $this->_errors->all()); return $this; }
[ "public", "function", "withErrors", "(", "$", "validator", ")", "{", "foreach", "(", "$", "validator", "->", "errors", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "count", "(", "$", "value", ")", ">", "1", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "value", ")", ";", "$", "i", "++", ")", "{", "$", "data", "[", "$", "key", "]", "[", "$", "i", "]", "=", "$", "value", "[", "$", "i", "]", ";", "}", "}", "else", "{", "$", "data", "[", "$", "key", "]", "=", "$", "value", "[", "0", "]", ";", "}", "$", "this", "->", "_errors", "->", "add", "(", "(", "object", ")", "$", "data", ")", ";", "}", "$", "this", "->", "_session", "->", "flash", "(", "'errors'", ",", "$", "this", "->", "_errors", "->", "all", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Flash errors grabbed from a request. @param \Scara\Validation\Validator $validator - Validation object @return \Scara\Http\Controller
[ "Flash", "errors", "grabbed", "from", "a", "request", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Controller.php#L126-L142
train
ScaraMVC/Framework
src/Scara/Http/Controller.php
Controller.renderWithData
public function renderWithData($path, $data = []) { foreach ($data as $key => $value) { $this->add($key, $value); } $this->render($path); return $this; }
php
public function renderWithData($path, $data = []) { foreach ($data as $key => $value) { $this->add($key, $value); } $this->render($path); return $this; }
[ "public", "function", "renderWithData", "(", "$", "path", ",", "$", "data", "=", "[", "]", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "add", "(", "$", "key", ",", "$", "value", ")", ";", "}", "$", "this", "->", "render", "(", "$", "path", ")", ";", "return", "$", "this", ";", "}" ]
Renders a view with data to pass on to the view. @param string $path - View's path @param array $data - The data to render with @return \Scara\Http\Controller
[ "Renders", "a", "view", "with", "data", "to", "pass", "on", "to", "the", "view", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Controller.php#L177-L186
train
ScaraMVC/Framework
src/Scara/Http/Controller.php
Controller.redirectWith
public function redirectWith($url, $data) { $this->_session->flash('redirect_data', $data); $this->redirect($url); }
php
public function redirectWith($url, $data) { $this->_session->flash('redirect_data', $data); $this->redirect($url); }
[ "public", "function", "redirectWith", "(", "$", "url", ",", "$", "data", ")", "{", "$", "this", "->", "_session", "->", "flash", "(", "'redirect_data'", ",", "$", "data", ")", ";", "$", "this", "->", "redirect", "(", "$", "url", ")", ";", "}" ]
Redirects to a URL with data passed in as a temp flash session. @param string $url - Redirection's URL @param mixed $data - Data to redirect with @return void
[ "Redirects", "to", "a", "URL", "with", "data", "passed", "in", "as", "a", "temp", "flash", "session", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Controller.php#L208-L212
train
ScaraMVC/Framework
src/Scara/Http/Controller.php
Controller.group
public function group($name, $data = []) { $app = 'App\Groups\\'.ucwords($name); $core = 'Scara\Http\Groups\\'.ucwords($name); if (class_exists($app)) { $class = new $app(); } else { if (class_exists($core)) { $class = new $core(); } else { throw new \Exception("$name group could not be found in the application or in Scara's core"); } } if (method_exists($class, 'init')) { if (!empty($data)) { $class->init($data); } else { $class->init(); } if (in_array('Scara\Http\Groups\Groupable', class_uses($class))) { // class uses Groupable trait. call finalize $class->finalize(); } elseif (method_exists($class, 'finalize')) { $class->finalize(); // not using Groupable trait, but still has a finalize method defined } } else { throw new \Exception("$name group does not define the required init method!"); } return $this; }
php
public function group($name, $data = []) { $app = 'App\Groups\\'.ucwords($name); $core = 'Scara\Http\Groups\\'.ucwords($name); if (class_exists($app)) { $class = new $app(); } else { if (class_exists($core)) { $class = new $core(); } else { throw new \Exception("$name group could not be found in the application or in Scara's core"); } } if (method_exists($class, 'init')) { if (!empty($data)) { $class->init($data); } else { $class->init(); } if (in_array('Scara\Http\Groups\Groupable', class_uses($class))) { // class uses Groupable trait. call finalize $class->finalize(); } elseif (method_exists($class, 'finalize')) { $class->finalize(); // not using Groupable trait, but still has a finalize method defined } } else { throw new \Exception("$name group does not define the required init method!"); } return $this; }
[ "public", "function", "group", "(", "$", "name", ",", "$", "data", "=", "[", "]", ")", "{", "$", "app", "=", "'App\\Groups\\\\'", ".", "ucwords", "(", "$", "name", ")", ";", "$", "core", "=", "'Scara\\Http\\Groups\\\\'", ".", "ucwords", "(", "$", "name", ")", ";", "if", "(", "class_exists", "(", "$", "app", ")", ")", "{", "$", "class", "=", "new", "$", "app", "(", ")", ";", "}", "else", "{", "if", "(", "class_exists", "(", "$", "core", ")", ")", "{", "$", "class", "=", "new", "$", "core", "(", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"$name group could not be found in the application or in Scara's core\"", ")", ";", "}", "}", "if", "(", "method_exists", "(", "$", "class", ",", "'init'", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "class", "->", "init", "(", "$", "data", ")", ";", "}", "else", "{", "$", "class", "->", "init", "(", ")", ";", "}", "if", "(", "in_array", "(", "'Scara\\Http\\Groups\\Groupable'", ",", "class_uses", "(", "$", "class", ")", ")", ")", "{", "// class uses Groupable trait. call finalize", "$", "class", "->", "finalize", "(", ")", ";", "}", "elseif", "(", "method_exists", "(", "$", "class", ",", "'finalize'", ")", ")", "{", "$", "class", "->", "finalize", "(", ")", ";", "// not using Groupable trait, but still has a finalize method defined", "}", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"$name group does not define the required init method!\"", ")", ";", "}", "return", "$", "this", ";", "}" ]
Loads in a group for given controller method. @param string $name - The group name @param array $data - Data to pass to group @throws \Exception @return \Scara\Http\Controller
[ "Loads", "in", "a", "group", "for", "given", "controller", "method", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Controller.php#L236-L269
train
ScaraMVC/Framework
src/Scara/Http/Controller.php
Controller.load
public function load(Router $router, $basepath) { $loader = new RouteLoader(); $loader->registerRouter($router); $this->_route = $loader->getRequestedRoute($basepath); if (isset($this->_route['method']) && $this->_route['method'] == $_SERVER['REQUEST_METHOD']) { $controller = 'App\Controllers\\'.$this->_route['controller']; if (!class_exists($controller)) { throw new \Exception("Class [{$this->_route['controller']}] does not exist!"); } $class = new $controller($this->_route); $method = $this->_route['action']; if (isset($this->_route['query'])) { $request = new Request(); if (method_exists($class, $method)) { $class->$method($request->setRequest($this->_route['query'])->getObject()); } else { throw new \Exception("Method [$method] is not defined in $controller!"); } } else { if (method_exists($class, $method)) { $class->$method(); } else { throw new \Exception("Method [$method] is not defined in $controller!"); } } } else { $this->loadErrorPage('404'); } }
php
public function load(Router $router, $basepath) { $loader = new RouteLoader(); $loader->registerRouter($router); $this->_route = $loader->getRequestedRoute($basepath); if (isset($this->_route['method']) && $this->_route['method'] == $_SERVER['REQUEST_METHOD']) { $controller = 'App\Controllers\\'.$this->_route['controller']; if (!class_exists($controller)) { throw new \Exception("Class [{$this->_route['controller']}] does not exist!"); } $class = new $controller($this->_route); $method = $this->_route['action']; if (isset($this->_route['query'])) { $request = new Request(); if (method_exists($class, $method)) { $class->$method($request->setRequest($this->_route['query'])->getObject()); } else { throw new \Exception("Method [$method] is not defined in $controller!"); } } else { if (method_exists($class, $method)) { $class->$method(); } else { throw new \Exception("Method [$method] is not defined in $controller!"); } } } else { $this->loadErrorPage('404'); } }
[ "public", "function", "load", "(", "Router", "$", "router", ",", "$", "basepath", ")", "{", "$", "loader", "=", "new", "RouteLoader", "(", ")", ";", "$", "loader", "->", "registerRouter", "(", "$", "router", ")", ";", "$", "this", "->", "_route", "=", "$", "loader", "->", "getRequestedRoute", "(", "$", "basepath", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_route", "[", "'method'", "]", ")", "&&", "$", "this", "->", "_route", "[", "'method'", "]", "==", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", ")", "{", "$", "controller", "=", "'App\\Controllers\\\\'", ".", "$", "this", "->", "_route", "[", "'controller'", "]", ";", "if", "(", "!", "class_exists", "(", "$", "controller", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Class [{$this->_route['controller']}] does not exist!\"", ")", ";", "}", "$", "class", "=", "new", "$", "controller", "(", "$", "this", "->", "_route", ")", ";", "$", "method", "=", "$", "this", "->", "_route", "[", "'action'", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "_route", "[", "'query'", "]", ")", ")", "{", "$", "request", "=", "new", "Request", "(", ")", ";", "if", "(", "method_exists", "(", "$", "class", ",", "$", "method", ")", ")", "{", "$", "class", "->", "$", "method", "(", "$", "request", "->", "setRequest", "(", "$", "this", "->", "_route", "[", "'query'", "]", ")", "->", "getObject", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"Method [$method] is not defined in $controller!\"", ")", ";", "}", "}", "else", "{", "if", "(", "method_exists", "(", "$", "class", ",", "$", "method", ")", ")", "{", "$", "class", "->", "$", "method", "(", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"Method [$method] is not defined in $controller!\"", ")", ";", "}", "}", "}", "else", "{", "$", "this", "->", "loadErrorPage", "(", "'404'", ")", ";", "}", "}" ]
Loads the controller with the requested route. @param \Scara\Routing\Router $router - The router @param string $basepath - Application's base path @return void
[ "Loads", "the", "controller", "with", "the", "requested", "route", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Controller.php#L279-L313
train
ScaraMVC/Framework
src/Scara/Http/Controller.php
Controller.loadErrorPage
public function loadErrorPage($errorType) { switch ($errorType) { case 'notfound': $code = '404'; break; case 'badrequest': $code = '400'; break; default: $code = $errorType; break; } require_once \Config::from('app')->get('errors'); if (isset($errors)) { foreach ($errors as $error) { $aexp = explode('@', $error); $c = 'App\\Controllers\\'.$aexp[0]; if (class_exists($c)) { $method = 'error'.$code; if (method_exists($c, $method)) { $class = new $c(); if ($method == 'error'.$code) { $class->$method(); } exit; // quick hack for now } else { $class = new Errors(); $method = 'error'.$code; $class->$method(); } } else { $class = new Errors(); $method = 'error'.$code; $class->$method(); } } } else { $class = new Errors(); $method = 'error'.$code; $class->$method(); } }
php
public function loadErrorPage($errorType) { switch ($errorType) { case 'notfound': $code = '404'; break; case 'badrequest': $code = '400'; break; default: $code = $errorType; break; } require_once \Config::from('app')->get('errors'); if (isset($errors)) { foreach ($errors as $error) { $aexp = explode('@', $error); $c = 'App\\Controllers\\'.$aexp[0]; if (class_exists($c)) { $method = 'error'.$code; if (method_exists($c, $method)) { $class = new $c(); if ($method == 'error'.$code) { $class->$method(); } exit; // quick hack for now } else { $class = new Errors(); $method = 'error'.$code; $class->$method(); } } else { $class = new Errors(); $method = 'error'.$code; $class->$method(); } } } else { $class = new Errors(); $method = 'error'.$code; $class->$method(); } }
[ "public", "function", "loadErrorPage", "(", "$", "errorType", ")", "{", "switch", "(", "$", "errorType", ")", "{", "case", "'notfound'", ":", "$", "code", "=", "'404'", ";", "break", ";", "case", "'badrequest'", ":", "$", "code", "=", "'400'", ";", "break", ";", "default", ":", "$", "code", "=", "$", "errorType", ";", "break", ";", "}", "require_once", "\\", "Config", "::", "from", "(", "'app'", ")", "->", "get", "(", "'errors'", ")", ";", "if", "(", "isset", "(", "$", "errors", ")", ")", "{", "foreach", "(", "$", "errors", "as", "$", "error", ")", "{", "$", "aexp", "=", "explode", "(", "'@'", ",", "$", "error", ")", ";", "$", "c", "=", "'App\\\\Controllers\\\\'", ".", "$", "aexp", "[", "0", "]", ";", "if", "(", "class_exists", "(", "$", "c", ")", ")", "{", "$", "method", "=", "'error'", ".", "$", "code", ";", "if", "(", "method_exists", "(", "$", "c", ",", "$", "method", ")", ")", "{", "$", "class", "=", "new", "$", "c", "(", ")", ";", "if", "(", "$", "method", "==", "'error'", ".", "$", "code", ")", "{", "$", "class", "->", "$", "method", "(", ")", ";", "}", "exit", ";", "// quick hack for now", "}", "else", "{", "$", "class", "=", "new", "Errors", "(", ")", ";", "$", "method", "=", "'error'", ".", "$", "code", ";", "$", "class", "->", "$", "method", "(", ")", ";", "}", "}", "else", "{", "$", "class", "=", "new", "Errors", "(", ")", ";", "$", "method", "=", "'error'", ".", "$", "code", ";", "$", "class", "->", "$", "method", "(", ")", ";", "}", "}", "}", "else", "{", "$", "class", "=", "new", "Errors", "(", ")", ";", "$", "method", "=", "'error'", ".", "$", "code", ";", "$", "class", "->", "$", "method", "(", ")", ";", "}", "}" ]
Loads a requested error page. @param string $errorType - Error type to render for @return void
[ "Loads", "a", "requested", "error", "page", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Controller.php#L322-L364
train
Ang3/PhpunitBundle
src/Traits/ClassUtilsTrait.php
ClassUtilsTrait.getReflectionMethod
protected function getReflectionMethod($class, $name) { // Réflection de la classe $reflectionClass = new ReflectionClass($class); // Récupération de la réflection de la méthode $method = $reflectionClass->getMethod($name); // Ouverture des accès aux appels $method->setAccessible(true); // Retour de la reflection return $method; }
php
protected function getReflectionMethod($class, $name) { // Réflection de la classe $reflectionClass = new ReflectionClass($class); // Récupération de la réflection de la méthode $method = $reflectionClass->getMethod($name); // Ouverture des accès aux appels $method->setAccessible(true); // Retour de la reflection return $method; }
[ "protected", "function", "getReflectionMethod", "(", "$", "class", ",", "$", "name", ")", "{", "// Réflection de la classe", "$", "reflectionClass", "=", "new", "ReflectionClass", "(", "$", "class", ")", ";", "// Récupération de la réflection de la méthode", "$", "method", "=", "$", "reflectionClass", "->", "getMethod", "(", "$", "name", ")", ";", "// Ouverture des accès aux appels", "$", "method", "->", "setAccessible", "(", "true", ")", ";", "// Retour de la reflection", "return", "$", "method", ";", "}" ]
Gets a reflection method object. @param string $class @param string $name @return \ReflectionMethod
[ "Gets", "a", "reflection", "method", "object", "." ]
b76fff16cd8b8a95d71f75a2f5b738716d8b6f36
https://github.com/Ang3/PhpunitBundle/blob/b76fff16cd8b8a95d71f75a2f5b738716d8b6f36/src/Traits/ClassUtilsTrait.php#L36-L49
train
Ang3/PhpunitBundle
src/Traits/ClassUtilsTrait.php
ClassUtilsTrait.getReflectionProperty
protected function getReflectionProperty($objectOrClass, $name) { // Réflection de la classe $reflectionClass = new ReflectionClass($objectOrClass); // Récupération de la réflection de la propriété $property = $reflectionClass->getProperty((string) $name); // Ouverture des accès aux appels $property->setAccessible(true); // Retour de la réflection return $property; }
php
protected function getReflectionProperty($objectOrClass, $name) { // Réflection de la classe $reflectionClass = new ReflectionClass($objectOrClass); // Récupération de la réflection de la propriété $property = $reflectionClass->getProperty((string) $name); // Ouverture des accès aux appels $property->setAccessible(true); // Retour de la réflection return $property; }
[ "protected", "function", "getReflectionProperty", "(", "$", "objectOrClass", ",", "$", "name", ")", "{", "// Réflection de la classe", "$", "reflectionClass", "=", "new", "ReflectionClass", "(", "$", "objectOrClass", ")", ";", "// Récupération de la réflection de la propriété", "$", "property", "=", "$", "reflectionClass", "->", "getProperty", "(", "(", "string", ")", "$", "name", ")", ";", "// Ouverture des accès aux appels", "$", "property", "->", "setAccessible", "(", "true", ")", ";", "// Retour de la réflection", "return", "$", "property", ";", "}" ]
Gets a reflection property object. @param object|string $objectOrClass @param string $name @return \ReflectionProperty
[ "Gets", "a", "reflection", "property", "object", "." ]
b76fff16cd8b8a95d71f75a2f5b738716d8b6f36
https://github.com/Ang3/PhpunitBundle/blob/b76fff16cd8b8a95d71f75a2f5b738716d8b6f36/src/Traits/ClassUtilsTrait.php#L59-L72
train
Ang3/PhpunitBundle
src/Traits/ClassUtilsTrait.php
ClassUtilsTrait.setPropertyValue
protected function setPropertyValue($object, $propertyName, $value) { // Mise-à-jour de la valeur de la propriété $this->getReflectionProperty($object, $propertyName)->setValue($object, $value); // Retour du test return $this; }
php
protected function setPropertyValue($object, $propertyName, $value) { // Mise-à-jour de la valeur de la propriété $this->getReflectionProperty($object, $propertyName)->setValue($object, $value); // Retour du test return $this; }
[ "protected", "function", "setPropertyValue", "(", "$", "object", ",", "$", "propertyName", ",", "$", "value", ")", "{", "// Mise-à-jour de la valeur de la propriété", "$", "this", "->", "getReflectionProperty", "(", "$", "object", ",", "$", "propertyName", ")", "->", "setValue", "(", "$", "object", ",", "$", "value", ")", ";", "// Retour du test", "return", "$", "this", ";", "}" ]
Sets value in object property. @param object $object @param string $propertyName @param mixed $value @return mixed
[ "Sets", "value", "in", "object", "property", "." ]
b76fff16cd8b8a95d71f75a2f5b738716d8b6f36
https://github.com/Ang3/PhpunitBundle/blob/b76fff16cd8b8a95d71f75a2f5b738716d8b6f36/src/Traits/ClassUtilsTrait.php#L83-L90
train
Nekland/BaseApi
lib/Nekland/BaseApi/Http/AbstractHttpClient.php
AbstractHttpClient.getPath
protected function getPath($path) { $hasHttp = strpos($path, 'http'); if (false === $hasHttp || $hasHttp !== 0) { return $this->options['base_url'] . $path; } return $path; }
php
protected function getPath($path) { $hasHttp = strpos($path, 'http'); if (false === $hasHttp || $hasHttp !== 0) { return $this->options['base_url'] . $path; } return $path; }
[ "protected", "function", "getPath", "(", "$", "path", ")", "{", "$", "hasHttp", "=", "strpos", "(", "$", "path", ",", "'http'", ")", ";", "if", "(", "false", "===", "$", "hasHttp", "||", "$", "hasHttp", "!==", "0", ")", "{", "return", "$", "this", "->", "options", "[", "'base_url'", "]", ".", "$", "path", ";", "}", "return", "$", "path", ";", "}" ]
Generate a complete URL using the option "base_url" @param string $path The api uri @return string
[ "Generate", "a", "complete", "URL", "using", "the", "option", "base_url" ]
c96051b36d6982abf2a8b1f1ec16351bcae2455e
https://github.com/Nekland/BaseApi/blob/c96051b36d6982abf2a8b1f1ec16351bcae2455e/lib/Nekland/BaseApi/Http/AbstractHttpClient.php#L110-L118
train
Nekland/BaseApi
lib/Nekland/BaseApi/Http/AbstractHttpClient.php
AbstractHttpClient.createRequest
public static function createRequest($method, $path, $body = [], array $headers = []) { return new Request($method, $path, $body, $headers); }
php
public static function createRequest($method, $path, $body = [], array $headers = []) { return new Request($method, $path, $body, $headers); }
[ "public", "static", "function", "createRequest", "(", "$", "method", ",", "$", "path", ",", "$", "body", "=", "[", "]", ",", "array", "$", "headers", "=", "[", "]", ")", "{", "return", "new", "Request", "(", "$", "method", ",", "$", "path", ",", "$", "body", ",", "$", "headers", ")", ";", "}" ]
Generate a request object @param string $method @param string $path @param array|string $body @param array $headers @return Request
[ "Generate", "a", "request", "object" ]
c96051b36d6982abf2a8b1f1ec16351bcae2455e
https://github.com/Nekland/BaseApi/blob/c96051b36d6982abf2a8b1f1ec16351bcae2455e/lib/Nekland/BaseApi/Http/AbstractHttpClient.php#L129-L132
train
mylxsw/FocusPHP
src/Request/HttpRequest.php
HttpRequest._escape
private function _escape($value, $htmlEntities = false) { if (get_magic_quotes_gpc()) { if ($htmlEntities) { return htmlspecialchars($value); } return $value; } if (is_array($value)) { return array_map(function ($n) use ($htmlEntities) { $val = stripslashes($n); if ($htmlEntities) { return htmlspecialchars($val); } return $val; }, $value); } $val = stripslashes($value); if ($htmlEntities) { return htmlspecialchars($val); } return $val; }
php
private function _escape($value, $htmlEntities = false) { if (get_magic_quotes_gpc()) { if ($htmlEntities) { return htmlspecialchars($value); } return $value; } if (is_array($value)) { return array_map(function ($n) use ($htmlEntities) { $val = stripslashes($n); if ($htmlEntities) { return htmlspecialchars($val); } return $val; }, $value); } $val = stripslashes($value); if ($htmlEntities) { return htmlspecialchars($val); } return $val; }
[ "private", "function", "_escape", "(", "$", "value", ",", "$", "htmlEntities", "=", "false", ")", "{", "if", "(", "get_magic_quotes_gpc", "(", ")", ")", "{", "if", "(", "$", "htmlEntities", ")", "{", "return", "htmlspecialchars", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "return", "array_map", "(", "function", "(", "$", "n", ")", "use", "(", "$", "htmlEntities", ")", "{", "$", "val", "=", "stripslashes", "(", "$", "n", ")", ";", "if", "(", "$", "htmlEntities", ")", "{", "return", "htmlspecialchars", "(", "$", "val", ")", ";", "}", "return", "$", "val", ";", "}", ",", "$", "value", ")", ";", "}", "$", "val", "=", "stripslashes", "(", "$", "value", ")", ";", "if", "(", "$", "htmlEntities", ")", "{", "return", "htmlspecialchars", "(", "$", "val", ")", ";", "}", "return", "$", "val", ";", "}" ]
escape string value. @param $value @param $htmlEntities @return string
[ "escape", "string", "value", "." ]
33922bacbea66f11f874d991d7308a36cdf5831a
https://github.com/mylxsw/FocusPHP/blob/33922bacbea66f11f874d991d7308a36cdf5831a/src/Request/HttpRequest.php#L128-L156
train
apioo/psx-record
src/Mapper.php
Mapper.map
public static function map(RecordInterface $source, $destination, array $rules) { if (!is_object($destination)) { throw new InvalidArgumentException('Destination must be an object'); } $data = $source->getProperties(); foreach ($data as $key => $value) { // convert to camelcase if underscore is in name if (strpos($key, '_') !== false) { $key = implode('', array_map('ucfirst', explode('_', $key))); } $method = null; if (isset($rules[$key])) { if (is_string($rules[$key])) { $method = 'set' . ucfirst($rules[$key]); } elseif ($rules[$key] instanceof Rule) { $method = 'set' . ucfirst($rules[$key]->getName()); $value = $rules[$key]->getValue($value, $data); } } else { $method = 'set' . ucfirst($key); } if (is_callable(array($destination, $method))) { $destination->$method($value); } } }
php
public static function map(RecordInterface $source, $destination, array $rules) { if (!is_object($destination)) { throw new InvalidArgumentException('Destination must be an object'); } $data = $source->getProperties(); foreach ($data as $key => $value) { // convert to camelcase if underscore is in name if (strpos($key, '_') !== false) { $key = implode('', array_map('ucfirst', explode('_', $key))); } $method = null; if (isset($rules[$key])) { if (is_string($rules[$key])) { $method = 'set' . ucfirst($rules[$key]); } elseif ($rules[$key] instanceof Rule) { $method = 'set' . ucfirst($rules[$key]->getName()); $value = $rules[$key]->getValue($value, $data); } } else { $method = 'set' . ucfirst($key); } if (is_callable(array($destination, $method))) { $destination->$method($value); } } }
[ "public", "static", "function", "map", "(", "RecordInterface", "$", "source", ",", "$", "destination", ",", "array", "$", "rules", ")", "{", "if", "(", "!", "is_object", "(", "$", "destination", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Destination must be an object'", ")", ";", "}", "$", "data", "=", "$", "source", "->", "getProperties", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "// convert to camelcase if underscore is in name", "if", "(", "strpos", "(", "$", "key", ",", "'_'", ")", "!==", "false", ")", "{", "$", "key", "=", "implode", "(", "''", ",", "array_map", "(", "'ucfirst'", ",", "explode", "(", "'_'", ",", "$", "key", ")", ")", ")", ";", "}", "$", "method", "=", "null", ";", "if", "(", "isset", "(", "$", "rules", "[", "$", "key", "]", ")", ")", "{", "if", "(", "is_string", "(", "$", "rules", "[", "$", "key", "]", ")", ")", "{", "$", "method", "=", "'set'", ".", "ucfirst", "(", "$", "rules", "[", "$", "key", "]", ")", ";", "}", "elseif", "(", "$", "rules", "[", "$", "key", "]", "instanceof", "Rule", ")", "{", "$", "method", "=", "'set'", ".", "ucfirst", "(", "$", "rules", "[", "$", "key", "]", "->", "getName", "(", ")", ")", ";", "$", "value", "=", "$", "rules", "[", "$", "key", "]", "->", "getValue", "(", "$", "value", ",", "$", "data", ")", ";", "}", "}", "else", "{", "$", "method", "=", "'set'", ".", "ucfirst", "(", "$", "key", ")", ";", "}", "if", "(", "is_callable", "(", "array", "(", "$", "destination", ",", "$", "method", ")", ")", ")", "{", "$", "destination", "->", "$", "method", "(", "$", "value", ")", ";", "}", "}", "}" ]
Method which can map all fields of a record to an arbitrary class by calling the fitting setter methods if available @param \PSX\Record\RecordInterface $source @param object $destination @param array $rules
[ "Method", "which", "can", "map", "all", "fields", "of", "a", "record", "to", "an", "arbitrary", "class", "by", "calling", "the", "fitting", "setter", "methods", "if", "available" ]
045d1ec323635187467569f7d12973c8718a7871
https://github.com/apioo/psx-record/blob/045d1ec323635187467569f7d12973c8718a7871/src/Mapper.php#L43-L73
train
Hnto/nuki
src/Handlers/Security/Hasher.php
Hasher.hash
public function hash(string $data, $file = false) { if ($file === false) { return $this->hashContent($data); } return $this->hashFile($file); }
php
public function hash(string $data, $file = false) { if ($file === false) { return $this->hashContent($data); } return $this->hashFile($file); }
[ "public", "function", "hash", "(", "string", "$", "data", ",", "$", "file", "=", "false", ")", "{", "if", "(", "$", "file", "===", "false", ")", "{", "return", "$", "this", "->", "hashContent", "(", "$", "data", ")", ";", "}", "return", "$", "this", "->", "hashFile", "(", "$", "file", ")", ";", "}" ]
Hash by message @param string $data @return bool|string
[ "Hash", "by", "message" ]
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Security/Hasher.php#L43-L49
train
Hnto/nuki
src/Handlers/Security/Hasher.php
Hasher.hashFile
private function hashFile(string $filename) { $hash = hash_hmac_file( $this->algorithm, $filename, $this->key ); return $this->validate($hash); }
php
private function hashFile(string $filename) { $hash = hash_hmac_file( $this->algorithm, $filename, $this->key ); return $this->validate($hash); }
[ "private", "function", "hashFile", "(", "string", "$", "filename", ")", "{", "$", "hash", "=", "hash_hmac_file", "(", "$", "this", "->", "algorithm", ",", "$", "filename", ",", "$", "this", "->", "key", ")", ";", "return", "$", "this", "->", "validate", "(", "$", "hash", ")", ";", "}" ]
Hash by filename @param string $filename @return bool|string
[ "Hash", "by", "filename" ]
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Security/Hasher.php#L79-L87
train
Hnto/nuki
src/Handlers/Security/Hasher.php
Hasher.hashContent
private function hashContent(string $data) { $hash = hash_hmac( $this->algorithm, $data, $this->key ); return $this->validate($hash); }
php
private function hashContent(string $data) { $hash = hash_hmac( $this->algorithm, $data, $this->key ); return $this->validate($hash); }
[ "private", "function", "hashContent", "(", "string", "$", "data", ")", "{", "$", "hash", "=", "hash_hmac", "(", "$", "this", "->", "algorithm", ",", "$", "data", ",", "$", "this", "->", "key", ")", ";", "return", "$", "this", "->", "validate", "(", "$", "hash", ")", ";", "}" ]
Hash by content @param string $data @return boolean
[ "Hash", "by", "content" ]
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Security/Hasher.php#L95-L103
train
modulusphp/http
Rest.php
Rest.json
public function json(array $array = [], int $code = null) { $this->data = $array; if ($code != null) { $this->code = $code; header('HTTP/1.1 '.$this->code); return $this->send(); } return $this; }
php
public function json(array $array = [], int $code = null) { $this->data = $array; if ($code != null) { $this->code = $code; header('HTTP/1.1 '.$this->code); return $this->send(); } return $this; }
[ "public", "function", "json", "(", "array", "$", "array", "=", "[", "]", ",", "int", "$", "code", "=", "null", ")", "{", "$", "this", "->", "data", "=", "$", "array", ";", "if", "(", "$", "code", "!=", "null", ")", "{", "$", "this", "->", "code", "=", "$", "code", ";", "header", "(", "'HTTP/1.1 '", ".", "$", "this", "->", "code", ")", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Attach json data @param array $array @param integer $code @return Rest
[ "Attach", "json", "data" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Rest.php#L87-L98
train
modulusphp/http
Rest.php
Rest.withHeaders
public function withHeaders(array $array, int $code = null) { foreach($array as $field => $i) { array_push($this->headers, $field .': '. $i); } if ($code != null) { $this->code = $code; header('HTTP/1.1 '.$this->code); return $this->send(); } return $this; }
php
public function withHeaders(array $array, int $code = null) { foreach($array as $field => $i) { array_push($this->headers, $field .': '. $i); } if ($code != null) { $this->code = $code; header('HTTP/1.1 '.$this->code); return $this->send(); } return $this; }
[ "public", "function", "withHeaders", "(", "array", "$", "array", ",", "int", "$", "code", "=", "null", ")", "{", "foreach", "(", "$", "array", "as", "$", "field", "=>", "$", "i", ")", "{", "array_push", "(", "$", "this", "->", "headers", ",", "$", "field", ".", "': '", ".", "$", "i", ")", ";", "}", "if", "(", "$", "code", "!=", "null", ")", "{", "$", "this", "->", "code", "=", "$", "code", ";", "header", "(", "'HTTP/1.1 '", ".", "$", "this", "->", "code", ")", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set response header's @param array $array @return Rest
[ "Set", "response", "header", "s" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Rest.php#L119-L132
train
modulusphp/http
Rest.php
Rest.view
public function view(string $path, array $data = [], bool $return = false) { if ($this->headers !== ['Content-Type: application/json']) { foreach($this->headers as $header) { header($header); } } return View::make($path, $data, $return); }
php
public function view(string $path, array $data = [], bool $return = false) { if ($this->headers !== ['Content-Type: application/json']) { foreach($this->headers as $header) { header($header); } } return View::make($path, $data, $return); }
[ "public", "function", "view", "(", "string", "$", "path", ",", "array", "$", "data", "=", "[", "]", ",", "bool", "$", "return", "=", "false", ")", "{", "if", "(", "$", "this", "->", "headers", "!==", "[", "'Content-Type: application/json'", "]", ")", "{", "foreach", "(", "$", "this", "->", "headers", "as", "$", "header", ")", "{", "header", "(", "$", "header", ")", ";", "}", "}", "return", "View", "::", "make", "(", "$", "path", ",", "$", "data", ",", "$", "return", ")", ";", "}" ]
Return a view response @param string $path @param array $data @param bool $return @return mixed
[ "Return", "a", "view", "response" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Rest.php#L142-L151
train
modulusphp/http
Rest.php
Rest.download
public function download(string $location, ?string $filename = null, ?array $headers = []) { if (!file_exists($location)) { header("HTTP/1.1 404 Not Found"); return; } $size = filesize($location); $time = date('r', filemtime($location)); $fm = @fopen($location, 'rb'); if (!$fm) { header("HTTP/1.1 505 Internal server error"); return; } $filename = ($filename == null) ? basename($location) : $filename; $mimeType = mime_content_type($location); $begin = 0; $end = $size - 1; if (isset($_SERVER['HTTP_RANGE'])) { if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) { $begin = intval($matches[1]); if (!empty($matches[2])) { $end= intval($matches[2]); } } } if ($headers == [] || $headers == null) { if (isset($_SERVER['HTTP_RANGE'])) { header('HTTP/1.1 206 Partial Content'); } else { header('HTTP/1.1 200 OK'); } header("Content-Type: $mimeType"); header('Cache-Control: public, must-revalidate, max-age=0'); header('Pragma: no-cache'); header('Accept-Ranges: bytes'); header('Content-Length:' . (($end - $begin) + 1)); if (isset($_SERVER['HTTP_RANGE'])) { header("Content-Range: bytes $begin-$end/$size"); } header("Content-Disposition: inline; filename=$filename"); header("Content-Transfer-Encoding: binary"); header("Last-Modified: $time"); } else { foreach($headers as $header) { header($header); } } $cur = $begin; fseek($fm, $begin, 0); while(!feof($fm) && $cur <= $end && (connection_status() == 0)) { print fread($fm, min(1024 * 16, ($end - $cur) + 1)); $cur += 1024 * 16; } }
php
public function download(string $location, ?string $filename = null, ?array $headers = []) { if (!file_exists($location)) { header("HTTP/1.1 404 Not Found"); return; } $size = filesize($location); $time = date('r', filemtime($location)); $fm = @fopen($location, 'rb'); if (!$fm) { header("HTTP/1.1 505 Internal server error"); return; } $filename = ($filename == null) ? basename($location) : $filename; $mimeType = mime_content_type($location); $begin = 0; $end = $size - 1; if (isset($_SERVER['HTTP_RANGE'])) { if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) { $begin = intval($matches[1]); if (!empty($matches[2])) { $end= intval($matches[2]); } } } if ($headers == [] || $headers == null) { if (isset($_SERVER['HTTP_RANGE'])) { header('HTTP/1.1 206 Partial Content'); } else { header('HTTP/1.1 200 OK'); } header("Content-Type: $mimeType"); header('Cache-Control: public, must-revalidate, max-age=0'); header('Pragma: no-cache'); header('Accept-Ranges: bytes'); header('Content-Length:' . (($end - $begin) + 1)); if (isset($_SERVER['HTTP_RANGE'])) { header("Content-Range: bytes $begin-$end/$size"); } header("Content-Disposition: inline; filename=$filename"); header("Content-Transfer-Encoding: binary"); header("Last-Modified: $time"); } else { foreach($headers as $header) { header($header); } } $cur = $begin; fseek($fm, $begin, 0); while(!feof($fm) && $cur <= $end && (connection_status() == 0)) { print fread($fm, min(1024 * 16, ($end - $cur) + 1)); $cur += 1024 * 16; } }
[ "public", "function", "download", "(", "string", "$", "location", ",", "?", "string", "$", "filename", "=", "null", ",", "?", "array", "$", "headers", "=", "[", "]", ")", "{", "if", "(", "!", "file_exists", "(", "$", "location", ")", ")", "{", "header", "(", "\"HTTP/1.1 404 Not Found\"", ")", ";", "return", ";", "}", "$", "size", "=", "filesize", "(", "$", "location", ")", ";", "$", "time", "=", "date", "(", "'r'", ",", "filemtime", "(", "$", "location", ")", ")", ";", "$", "fm", "=", "@", "fopen", "(", "$", "location", ",", "'rb'", ")", ";", "if", "(", "!", "$", "fm", ")", "{", "header", "(", "\"HTTP/1.1 505 Internal server error\"", ")", ";", "return", ";", "}", "$", "filename", "=", "(", "$", "filename", "==", "null", ")", "?", "basename", "(", "$", "location", ")", ":", "$", "filename", ";", "$", "mimeType", "=", "mime_content_type", "(", "$", "location", ")", ";", "$", "begin", "=", "0", ";", "$", "end", "=", "$", "size", "-", "1", ";", "if", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_RANGE'", "]", ")", ")", "{", "if", "(", "preg_match", "(", "'/bytes=\\h*(\\d+)-(\\d*)[\\D.*]?/i'", ",", "$", "_SERVER", "[", "'HTTP_RANGE'", "]", ",", "$", "matches", ")", ")", "{", "$", "begin", "=", "intval", "(", "$", "matches", "[", "1", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "matches", "[", "2", "]", ")", ")", "{", "$", "end", "=", "intval", "(", "$", "matches", "[", "2", "]", ")", ";", "}", "}", "}", "if", "(", "$", "headers", "==", "[", "]", "||", "$", "headers", "==", "null", ")", "{", "if", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_RANGE'", "]", ")", ")", "{", "header", "(", "'HTTP/1.1 206 Partial Content'", ")", ";", "}", "else", "{", "header", "(", "'HTTP/1.1 200 OK'", ")", ";", "}", "header", "(", "\"Content-Type: $mimeType\"", ")", ";", "header", "(", "'Cache-Control: public, must-revalidate, max-age=0'", ")", ";", "header", "(", "'Pragma: no-cache'", ")", ";", "header", "(", "'Accept-Ranges: bytes'", ")", ";", "header", "(", "'Content-Length:'", ".", "(", "(", "$", "end", "-", "$", "begin", ")", "+", "1", ")", ")", ";", "if", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_RANGE'", "]", ")", ")", "{", "header", "(", "\"Content-Range: bytes $begin-$end/$size\"", ")", ";", "}", "header", "(", "\"Content-Disposition: inline; filename=$filename\"", ")", ";", "header", "(", "\"Content-Transfer-Encoding: binary\"", ")", ";", "header", "(", "\"Last-Modified: $time\"", ")", ";", "}", "else", "{", "foreach", "(", "$", "headers", "as", "$", "header", ")", "{", "header", "(", "$", "header", ")", ";", "}", "}", "$", "cur", "=", "$", "begin", ";", "fseek", "(", "$", "fm", ",", "$", "begin", ",", "0", ")", ";", "while", "(", "!", "feof", "(", "$", "fm", ")", "&&", "$", "cur", "<=", "$", "end", "&&", "(", "connection_status", "(", ")", "==", "0", ")", ")", "{", "print", "fread", "(", "$", "fm", ",", "min", "(", "1024", "*", "16", ",", "(", "$", "end", "-", "$", "cur", ")", "+", "1", ")", ")", ";", "$", "cur", "+=", "1024", "*", "16", ";", "}", "}" ]
Reads the requested portion of a file and sends its contents to the client with the appropriate headers. This HTTP_RANGE compatible read file function is necessary for allowing streaming media to be skipped around in. @param string $location @param string $filename @param string $mimeType @return @link https://gist.github.com/benvium/3749316
[ "Reads", "the", "requested", "portion", "of", "a", "file", "and", "sends", "its", "contents", "to", "the", "client", "with", "the", "appropriate", "headers", ".", "This", "HTTP_RANGE", "compatible", "read", "file", "function", "is", "necessary", "for", "allowing", "streaming", "media", "to", "be", "skipped", "around", "in", "." ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Rest.php#L164-L229
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php
ParameterBag.resolveString
public function resolveString($value, array $resolving = array()) { // we do this to deal with non string values (Boolean, integer, ...) // as the preg_replace_callback throw an exception when trying // a non-string in a parameter value if (preg_match('/^%([^%\s]+)%$/', $value, $match)) { $key = $match[1]; $lcKey = strtolower($key); // strtolower() to be removed in 4.0 if (isset($resolving[$lcKey])) { throw new ParameterCircularReferenceException(array_keys($resolving)); } $resolving[$lcKey] = true; return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving); } return preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($resolving, $value) { // skip %% if (!isset($match[1])) { return '%%'; } $key = $match[1]; $lcKey = strtolower($key); // strtolower() to be removed in 4.0 if (isset($resolving[$lcKey])) { throw new ParameterCircularReferenceException(array_keys($resolving)); } $resolved = $this->get($key); if (!is_string($resolved) && !is_numeric($resolved)) { throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type %s inside string value "%s".', $key, gettype($resolved), $value)); } $resolved = (string) $resolved; $resolving[$lcKey] = true; return $this->isResolved() ? $resolved : $this->resolveString($resolved, $resolving); }, $value); }
php
public function resolveString($value, array $resolving = array()) { // we do this to deal with non string values (Boolean, integer, ...) // as the preg_replace_callback throw an exception when trying // a non-string in a parameter value if (preg_match('/^%([^%\s]+)%$/', $value, $match)) { $key = $match[1]; $lcKey = strtolower($key); // strtolower() to be removed in 4.0 if (isset($resolving[$lcKey])) { throw new ParameterCircularReferenceException(array_keys($resolving)); } $resolving[$lcKey] = true; return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving); } return preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($resolving, $value) { // skip %% if (!isset($match[1])) { return '%%'; } $key = $match[1]; $lcKey = strtolower($key); // strtolower() to be removed in 4.0 if (isset($resolving[$lcKey])) { throw new ParameterCircularReferenceException(array_keys($resolving)); } $resolved = $this->get($key); if (!is_string($resolved) && !is_numeric($resolved)) { throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type %s inside string value "%s".', $key, gettype($resolved), $value)); } $resolved = (string) $resolved; $resolving[$lcKey] = true; return $this->isResolved() ? $resolved : $this->resolveString($resolved, $resolving); }, $value); }
[ "public", "function", "resolveString", "(", "$", "value", ",", "array", "$", "resolving", "=", "array", "(", ")", ")", "{", "// we do this to deal with non string values (Boolean, integer, ...)", "// as the preg_replace_callback throw an exception when trying", "// a non-string in a parameter value", "if", "(", "preg_match", "(", "'/^%([^%\\s]+)%$/'", ",", "$", "value", ",", "$", "match", ")", ")", "{", "$", "key", "=", "$", "match", "[", "1", "]", ";", "$", "lcKey", "=", "strtolower", "(", "$", "key", ")", ";", "// strtolower() to be removed in 4.0", "if", "(", "isset", "(", "$", "resolving", "[", "$", "lcKey", "]", ")", ")", "{", "throw", "new", "ParameterCircularReferenceException", "(", "array_keys", "(", "$", "resolving", ")", ")", ";", "}", "$", "resolving", "[", "$", "lcKey", "]", "=", "true", ";", "return", "$", "this", "->", "resolved", "?", "$", "this", "->", "get", "(", "$", "key", ")", ":", "$", "this", "->", "resolveValue", "(", "$", "this", "->", "get", "(", "$", "key", ")", ",", "$", "resolving", ")", ";", "}", "return", "preg_replace_callback", "(", "'/%%|%([^%\\s]+)%/'", ",", "function", "(", "$", "match", ")", "use", "(", "$", "resolving", ",", "$", "value", ")", "{", "// skip %%", "if", "(", "!", "isset", "(", "$", "match", "[", "1", "]", ")", ")", "{", "return", "'%%'", ";", "}", "$", "key", "=", "$", "match", "[", "1", "]", ";", "$", "lcKey", "=", "strtolower", "(", "$", "key", ")", ";", "// strtolower() to be removed in 4.0", "if", "(", "isset", "(", "$", "resolving", "[", "$", "lcKey", "]", ")", ")", "{", "throw", "new", "ParameterCircularReferenceException", "(", "array_keys", "(", "$", "resolving", ")", ")", ";", "}", "$", "resolved", "=", "$", "this", "->", "get", "(", "$", "key", ")", ";", "if", "(", "!", "is_string", "(", "$", "resolved", ")", "&&", "!", "is_numeric", "(", "$", "resolved", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'A string value must be composed of strings and/or numbers, but found parameter \"%s\" of type %s inside string value \"%s\".'", ",", "$", "key", ",", "gettype", "(", "$", "resolved", ")", ",", "$", "value", ")", ")", ";", "}", "$", "resolved", "=", "(", "string", ")", "$", "resolved", ";", "$", "resolving", "[", "$", "lcKey", "]", "=", "true", ";", "return", "$", "this", "->", "isResolved", "(", ")", "?", "$", "resolved", ":", "$", "this", "->", "resolveString", "(", "$", "resolved", ",", "$", "resolving", ")", ";", "}", ",", "$", "value", ")", ";", "}" ]
Resolves parameters inside a string. @param string $value The string to resolve @param array $resolving An array of keys that are being resolved (used internally to detect circular references) @return string The resolved string @throws ParameterNotFoundException if a placeholder references a parameter that does not exist @throws ParameterCircularReferenceException if a circular reference if detected @throws RuntimeException when a given parameter has a type problem
[ "Resolves", "parameters", "inside", "a", "string", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php#L205-L246
train
jabernardo/lollipop-php
Library/System/Directory.php
Directory.contents
static function contents($directory) { if (!self::exists($directory)) return null; $dircontents = []; $contents = scandir($directory); foreach ($contents as $content) { if ($content != '.' && $content != '..') { array_push($dircontents, $content); } } return $dircontents; }
php
static function contents($directory) { if (!self::exists($directory)) return null; $dircontents = []; $contents = scandir($directory); foreach ($contents as $content) { if ($content != '.' && $content != '..') { array_push($dircontents, $content); } } return $dircontents; }
[ "static", "function", "contents", "(", "$", "directory", ")", "{", "if", "(", "!", "self", "::", "exists", "(", "$", "directory", ")", ")", "return", "null", ";", "$", "dircontents", "=", "[", "]", ";", "$", "contents", "=", "scandir", "(", "$", "directory", ")", ";", "foreach", "(", "$", "contents", "as", "$", "content", ")", "{", "if", "(", "$", "content", "!=", "'.'", "&&", "$", "content", "!=", "'..'", ")", "{", "array_push", "(", "$", "dircontents", ",", "$", "content", ")", ";", "}", "}", "return", "$", "dircontents", ";", "}" ]
Returns the contents of directory @param string $directory Path to directory @return array
[ "Returns", "the", "contents", "of", "directory" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/System/Directory.php#L38-L52
train
FuzeWorks/Core
src/FuzeWorks/Factory.php
Factory.getInstance
public static function getInstance($cloneInstance = false): Factory { if ($cloneInstance === true || self::$cloneInstances === true) { return clone self::$sharedFactoryInstance; } return self::$sharedFactoryInstance; }
php
public static function getInstance($cloneInstance = false): Factory { if ($cloneInstance === true || self::$cloneInstances === true) { return clone self::$sharedFactoryInstance; } return self::$sharedFactoryInstance; }
[ "public", "static", "function", "getInstance", "(", "$", "cloneInstance", "=", "false", ")", ":", "Factory", "{", "if", "(", "$", "cloneInstance", "===", "true", "||", "self", "::", "$", "cloneInstances", "===", "true", ")", "{", "return", "clone", "self", "::", "$", "sharedFactoryInstance", ";", "}", "return", "self", "::", "$", "sharedFactoryInstance", ";", "}" ]
Get a new instance of the Factory class. @param bool $cloneInstance Whether to get a cloned instance (true) or exactly the same instance (false) @return Factory Instance
[ "Get", "a", "new", "instance", "of", "the", "Factory", "class", "." ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Factory.php#L218-L226
train
FuzeWorks/Core
src/FuzeWorks/Factory.php
Factory.newInstance
public function newInstance($className, $namespace = 'FuzeWorks\\'): self { // Determine the class to load $instanceName = strtolower($className); $className = $namespace.ucfirst($className); if (!isset($this->{$instanceName})) { throw new FactoryException("Could not load new instance of '".$instanceName."'. Instance was not found.", 1); } elseif (!class_exists($className, false)) { throw new FactoryException("Could not load new instance of '".$instanceName."'. Class not found.", 1); } // Remove the current instance unset($this->{$instanceName}); // And set the new one $this->{$instanceName} = new $className(); // Return itself return $this; }
php
public function newInstance($className, $namespace = 'FuzeWorks\\'): self { // Determine the class to load $instanceName = strtolower($className); $className = $namespace.ucfirst($className); if (!isset($this->{$instanceName})) { throw new FactoryException("Could not load new instance of '".$instanceName."'. Instance was not found.", 1); } elseif (!class_exists($className, false)) { throw new FactoryException("Could not load new instance of '".$instanceName."'. Class not found.", 1); } // Remove the current instance unset($this->{$instanceName}); // And set the new one $this->{$instanceName} = new $className(); // Return itself return $this; }
[ "public", "function", "newInstance", "(", "$", "className", ",", "$", "namespace", "=", "'FuzeWorks\\\\'", ")", ":", "self", "{", "// Determine the class to load", "$", "instanceName", "=", "strtolower", "(", "$", "className", ")", ";", "$", "className", "=", "$", "namespace", ".", "ucfirst", "(", "$", "className", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "{", "$", "instanceName", "}", ")", ")", "{", "throw", "new", "FactoryException", "(", "\"Could not load new instance of '\"", ".", "$", "instanceName", ".", "\"'. Instance was not found.\"", ",", "1", ")", ";", "}", "elseif", "(", "!", "class_exists", "(", "$", "className", ",", "false", ")", ")", "{", "throw", "new", "FactoryException", "(", "\"Could not load new instance of '\"", ".", "$", "instanceName", ".", "\"'. Class not found.\"", ",", "1", ")", ";", "}", "// Remove the current instance", "unset", "(", "$", "this", "->", "{", "$", "instanceName", "}", ")", ";", "// And set the new one", "$", "this", "->", "{", "$", "instanceName", "}", "=", "new", "$", "className", "(", ")", ";", "// Return itself", "return", "$", "this", ";", "}" ]
Create a new instance of one of the loaded classes. It reloads the class. It does NOT clone it. @param string $className The name of the loaded class, WITHOUT the namespace @param string $namespace Optional namespace. Defaults to 'FuzeWorks\' @return Factory Instance
[ "Create", "a", "new", "instance", "of", "one", "of", "the", "loaded", "classes", ".", "It", "reloads", "the", "class", ".", "It", "does", "NOT", "clone", "it", "." ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Factory.php#L256-L279
train
FuzeWorks/Core
src/FuzeWorks/Factory.php
Factory.cloneInstance
public function cloneInstance($className): self { // Determine the class to load $instanceName = strtolower($className); if (!isset($this->{$instanceName})) { throw new FactoryException("Could not clone instance of '".$instanceName."'. Instance was not found.", 1); } // Clone the instance $this->{$instanceName} = clone $this->{$instanceName}; // Return itself return $this; }
php
public function cloneInstance($className): self { // Determine the class to load $instanceName = strtolower($className); if (!isset($this->{$instanceName})) { throw new FactoryException("Could not clone instance of '".$instanceName."'. Instance was not found.", 1); } // Clone the instance $this->{$instanceName} = clone $this->{$instanceName}; // Return itself return $this; }
[ "public", "function", "cloneInstance", "(", "$", "className", ")", ":", "self", "{", "// Determine the class to load", "$", "instanceName", "=", "strtolower", "(", "$", "className", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "{", "$", "instanceName", "}", ")", ")", "{", "throw", "new", "FactoryException", "(", "\"Could not clone instance of '\"", ".", "$", "instanceName", ".", "\"'. Instance was not found.\"", ",", "1", ")", ";", "}", "// Clone the instance", "$", "this", "->", "{", "$", "instanceName", "}", "=", "clone", "$", "this", "->", "{", "$", "instanceName", "}", ";", "// Return itself", "return", "$", "this", ";", "}" ]
Clone an instance of one of the loaded classes. It clones the class. It does NOT re-create it. @param string $className The name of the loaded class, WITHOUT the namespace @return Factory Instance
[ "Clone", "an", "instance", "of", "one", "of", "the", "loaded", "classes", ".", "It", "clones", "the", "class", ".", "It", "does", "NOT", "re", "-", "create", "it", "." ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Factory.php#L288-L303
train
FuzeWorks/Core
src/FuzeWorks/Factory.php
Factory.removeInstance
public function removeInstance($className): self { // Determine the instance name $instanceName = strtolower($className); if (!isset($this->{$instanceName})) { throw new FactoryException("Could not remove instance of '".$instanceName."'. Instance was not found.", 1); } // Unset unset($this->{$instanceName}); // Return itself return $this; }
php
public function removeInstance($className): self { // Determine the instance name $instanceName = strtolower($className); if (!isset($this->{$instanceName})) { throw new FactoryException("Could not remove instance of '".$instanceName."'. Instance was not found.", 1); } // Unset unset($this->{$instanceName}); // Return itself return $this; }
[ "public", "function", "removeInstance", "(", "$", "className", ")", ":", "self", "{", "// Determine the instance name", "$", "instanceName", "=", "strtolower", "(", "$", "className", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "{", "$", "instanceName", "}", ")", ")", "{", "throw", "new", "FactoryException", "(", "\"Could not remove instance of '\"", ".", "$", "instanceName", ".", "\"'. Instance was not found.\"", ",", "1", ")", ";", "}", "// Unset", "unset", "(", "$", "this", "->", "{", "$", "instanceName", "}", ")", ";", "// Return itself", "return", "$", "this", ";", "}" ]
Remove an instance of one of the loaded classes. @param string $className The name of the loaded class, WITHOUT the namespace @return Factory Factory Instance
[ "Remove", "an", "instance", "of", "one", "of", "the", "loaded", "classes", "." ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Factory.php#L332-L347
train
raframework/rapkg
src/Rapkg/Validation/Validator.php
Validator.mergeMessages
protected function mergeMessages(array $customMessages = [], array $attributes = []) { $globalMessages = []; if (self::$globalMessageInstance instanceof MessageInterface) { $globalMessages = self::$globalMessageInstance->getMessages(); } // Merge rule messages $ruleMessages = Variable::getDefaultRuleMessages(); if (isset($globalMessages['rule_messages']) && is_array($globalMessages['rule_messages'])) { $ruleMessages = array_merge($ruleMessages, $globalMessages['rule_messages']); } $this->ruleMessages = $ruleMessages; // Merge custom messages if (isset($globalMessages['custom_messages']) && is_array($globalMessages['custom_messages'])) { $this->customMessages = array_merge($this->customMessages, $globalMessages['custom_messages']); } if ($customMessages && is_array($customMessages)) { $this->customMessages = array_merge($this->customMessages, $customMessages); } // Merge attributes if (isset($globalMessages['attributes']) && is_array($globalMessages['attributes'])) { $this->attributes = array_merge($this->attributes, $globalMessages['attributes']); } if ($attributes && is_array($attributes)) { $this->attributes = array_merge($this->attributes, $attributes); } }
php
protected function mergeMessages(array $customMessages = [], array $attributes = []) { $globalMessages = []; if (self::$globalMessageInstance instanceof MessageInterface) { $globalMessages = self::$globalMessageInstance->getMessages(); } // Merge rule messages $ruleMessages = Variable::getDefaultRuleMessages(); if (isset($globalMessages['rule_messages']) && is_array($globalMessages['rule_messages'])) { $ruleMessages = array_merge($ruleMessages, $globalMessages['rule_messages']); } $this->ruleMessages = $ruleMessages; // Merge custom messages if (isset($globalMessages['custom_messages']) && is_array($globalMessages['custom_messages'])) { $this->customMessages = array_merge($this->customMessages, $globalMessages['custom_messages']); } if ($customMessages && is_array($customMessages)) { $this->customMessages = array_merge($this->customMessages, $customMessages); } // Merge attributes if (isset($globalMessages['attributes']) && is_array($globalMessages['attributes'])) { $this->attributes = array_merge($this->attributes, $globalMessages['attributes']); } if ($attributes && is_array($attributes)) { $this->attributes = array_merge($this->attributes, $attributes); } }
[ "protected", "function", "mergeMessages", "(", "array", "$", "customMessages", "=", "[", "]", ",", "array", "$", "attributes", "=", "[", "]", ")", "{", "$", "globalMessages", "=", "[", "]", ";", "if", "(", "self", "::", "$", "globalMessageInstance", "instanceof", "MessageInterface", ")", "{", "$", "globalMessages", "=", "self", "::", "$", "globalMessageInstance", "->", "getMessages", "(", ")", ";", "}", "// Merge rule messages", "$", "ruleMessages", "=", "Variable", "::", "getDefaultRuleMessages", "(", ")", ";", "if", "(", "isset", "(", "$", "globalMessages", "[", "'rule_messages'", "]", ")", "&&", "is_array", "(", "$", "globalMessages", "[", "'rule_messages'", "]", ")", ")", "{", "$", "ruleMessages", "=", "array_merge", "(", "$", "ruleMessages", ",", "$", "globalMessages", "[", "'rule_messages'", "]", ")", ";", "}", "$", "this", "->", "ruleMessages", "=", "$", "ruleMessages", ";", "// Merge custom messages", "if", "(", "isset", "(", "$", "globalMessages", "[", "'custom_messages'", "]", ")", "&&", "is_array", "(", "$", "globalMessages", "[", "'custom_messages'", "]", ")", ")", "{", "$", "this", "->", "customMessages", "=", "array_merge", "(", "$", "this", "->", "customMessages", ",", "$", "globalMessages", "[", "'custom_messages'", "]", ")", ";", "}", "if", "(", "$", "customMessages", "&&", "is_array", "(", "$", "customMessages", ")", ")", "{", "$", "this", "->", "customMessages", "=", "array_merge", "(", "$", "this", "->", "customMessages", ",", "$", "customMessages", ")", ";", "}", "// Merge attributes", "if", "(", "isset", "(", "$", "globalMessages", "[", "'attributes'", "]", ")", "&&", "is_array", "(", "$", "globalMessages", "[", "'attributes'", "]", ")", ")", "{", "$", "this", "->", "attributes", "=", "array_merge", "(", "$", "this", "->", "attributes", ",", "$", "globalMessages", "[", "'attributes'", "]", ")", ";", "}", "if", "(", "$", "attributes", "&&", "is_array", "(", "$", "attributes", ")", ")", "{", "$", "this", "->", "attributes", "=", "array_merge", "(", "$", "this", "->", "attributes", ",", "$", "attributes", ")", ";", "}", "}" ]
Merge rule messages & custom messages & attributes @param array $customMessages @param array $attributes
[ "Merge", "rule", "messages", "&", "custom", "messages", "&", "attributes" ]
7c4371911369d7c9d4463127bcd285144d7347ee
https://github.com/raframework/rapkg/blob/7c4371911369d7c9d4463127bcd285144d7347ee/src/Rapkg/Validation/Validator.php#L84-L113
train
mtils/cmsable
src/Cmsable/Http/CmsRequestConverter.php
CmsRequestConverter.toCmsRequest
public function toCmsRequest(Request $request) { $cmsRequest = (new CmsRequest)->duplicate( $request->query->all(), $request->request->all(), $request->attributes->all(), $request->cookies->all(), $request->files->all(), $request->server->all() ); $cmsRequest->headers = clone $request->headers; return $cmsRequest; }
php
public function toCmsRequest(Request $request) { $cmsRequest = (new CmsRequest)->duplicate( $request->query->all(), $request->request->all(), $request->attributes->all(), $request->cookies->all(), $request->files->all(), $request->server->all() ); $cmsRequest->headers = clone $request->headers; return $cmsRequest; }
[ "public", "function", "toCmsRequest", "(", "Request", "$", "request", ")", "{", "$", "cmsRequest", "=", "(", "new", "CmsRequest", ")", "->", "duplicate", "(", "$", "request", "->", "query", "->", "all", "(", ")", ",", "$", "request", "->", "request", "->", "all", "(", ")", ",", "$", "request", "->", "attributes", "->", "all", "(", ")", ",", "$", "request", "->", "cookies", "->", "all", "(", ")", ",", "$", "request", "->", "files", "->", "all", "(", ")", ",", "$", "request", "->", "server", "->", "all", "(", ")", ")", ";", "$", "cmsRequest", "->", "headers", "=", "clone", "$", "request", "->", "headers", ";", "return", "$", "cmsRequest", ";", "}" ]
Creates a CmsRequest out of an Illuminate Request @param \Illuminate\Http\Request $request @return \Cmsable\Http\CmsRequest
[ "Creates", "a", "CmsRequest", "out", "of", "an", "Illuminate", "Request" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Http/CmsRequestConverter.php#L17-L31
train
Linkvalue-Interne/MobileNotif
src/Model/ApnsMessage.php
ApnsMessage.addAction
public function addAction(array $action) { $actions = $this->getAction(); $actions[] = $action; return $this->setAction($actions); }
php
public function addAction(array $action) { $actions = $this->getAction(); $actions[] = $action; return $this->setAction($actions); }
[ "public", "function", "addAction", "(", "array", "$", "action", ")", "{", "$", "actions", "=", "$", "this", "->", "getAction", "(", ")", ";", "$", "actions", "[", "]", "=", "$", "action", ";", "return", "$", "this", "->", "setAction", "(", "$", "actions", ")", ";", "}" ]
Set an array in the action array. @param array $action @return self
[ "Set", "an", "array", "in", "the", "action", "array", "." ]
e6e4c4219f3bbb0aee32e90e5fdfc8c6a7ed53f6
https://github.com/Linkvalue-Interne/MobileNotif/blob/e6e4c4219f3bbb0aee32e90e5fdfc8c6a7ed53f6/src/Model/ApnsMessage.php#L545-L552
train
Linkvalue-Interne/MobileNotif
src/Model/ApnsMessage.php
ApnsMessage.getPayloadAlertKeyValue
private function getPayloadAlertKeyValue() { // Alert "string" (simple alert) if ($this->getSimpleAlert()) { return $this->getSimpleAlert(); } // Alert "array" (complex alert) $payloadAlert = array(); if ($this->getAlertTitle()) { $payloadAlert['title'] = $this->getAlertTitle(); } if ($this->getAlertBody()) { $payloadAlert['body'] = $this->getAlertBody(); } if ($this->getAlertTitleLocKey()) { $payloadAlert['title-loc-key'] = $this->getAlertTitleLocKey(); } if ($this->getAlertTitleLocArgs()) { $payloadAlert['title-loc-args'] = $this->getAlertTitleLocArgs(); } if ($this->getAlertActionLocKey()) { $payloadAlert['action-loc-key'] = $this->getAlertActionLocKey(); } if ($this->getAlertLocKey()) { $payloadAlert['loc-key'] = $this->getAlertLocKey(); } if ($this->getAlertLocArgs()) { $payloadAlert['loc-args'] = $this->getAlertLocArgs(); } if ($this->getAlertLaunchImage()) { $payloadAlert['launch-image'] = $this->getAlertLaunchImage(); } if ($this->getAction()) { $payloadAlert['action'] = $this->getAction(); } return $payloadAlert; }
php
private function getPayloadAlertKeyValue() { // Alert "string" (simple alert) if ($this->getSimpleAlert()) { return $this->getSimpleAlert(); } // Alert "array" (complex alert) $payloadAlert = array(); if ($this->getAlertTitle()) { $payloadAlert['title'] = $this->getAlertTitle(); } if ($this->getAlertBody()) { $payloadAlert['body'] = $this->getAlertBody(); } if ($this->getAlertTitleLocKey()) { $payloadAlert['title-loc-key'] = $this->getAlertTitleLocKey(); } if ($this->getAlertTitleLocArgs()) { $payloadAlert['title-loc-args'] = $this->getAlertTitleLocArgs(); } if ($this->getAlertActionLocKey()) { $payloadAlert['action-loc-key'] = $this->getAlertActionLocKey(); } if ($this->getAlertLocKey()) { $payloadAlert['loc-key'] = $this->getAlertLocKey(); } if ($this->getAlertLocArgs()) { $payloadAlert['loc-args'] = $this->getAlertLocArgs(); } if ($this->getAlertLaunchImage()) { $payloadAlert['launch-image'] = $this->getAlertLaunchImage(); } if ($this->getAction()) { $payloadAlert['action'] = $this->getAction(); } return $payloadAlert; }
[ "private", "function", "getPayloadAlertKeyValue", "(", ")", "{", "// Alert \"string\" (simple alert)", "if", "(", "$", "this", "->", "getSimpleAlert", "(", ")", ")", "{", "return", "$", "this", "->", "getSimpleAlert", "(", ")", ";", "}", "// Alert \"array\" (complex alert)", "$", "payloadAlert", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "getAlertTitle", "(", ")", ")", "{", "$", "payloadAlert", "[", "'title'", "]", "=", "$", "this", "->", "getAlertTitle", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getAlertBody", "(", ")", ")", "{", "$", "payloadAlert", "[", "'body'", "]", "=", "$", "this", "->", "getAlertBody", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getAlertTitleLocKey", "(", ")", ")", "{", "$", "payloadAlert", "[", "'title-loc-key'", "]", "=", "$", "this", "->", "getAlertTitleLocKey", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getAlertTitleLocArgs", "(", ")", ")", "{", "$", "payloadAlert", "[", "'title-loc-args'", "]", "=", "$", "this", "->", "getAlertTitleLocArgs", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getAlertActionLocKey", "(", ")", ")", "{", "$", "payloadAlert", "[", "'action-loc-key'", "]", "=", "$", "this", "->", "getAlertActionLocKey", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getAlertLocKey", "(", ")", ")", "{", "$", "payloadAlert", "[", "'loc-key'", "]", "=", "$", "this", "->", "getAlertLocKey", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getAlertLocArgs", "(", ")", ")", "{", "$", "payloadAlert", "[", "'loc-args'", "]", "=", "$", "this", "->", "getAlertLocArgs", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getAlertLaunchImage", "(", ")", ")", "{", "$", "payloadAlert", "[", "'launch-image'", "]", "=", "$", "this", "->", "getAlertLaunchImage", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getAction", "(", ")", ")", "{", "$", "payloadAlert", "[", "'action'", "]", "=", "$", "this", "->", "getAction", "(", ")", ";", "}", "return", "$", "payloadAlert", ";", "}" ]
Get the value of the payload "alert" key. @return string|array
[ "Get", "the", "value", "of", "the", "payload", "alert", "key", "." ]
e6e4c4219f3bbb0aee32e90e5fdfc8c6a7ed53f6
https://github.com/Linkvalue-Interne/MobileNotif/blob/e6e4c4219f3bbb0aee32e90e5fdfc8c6a7ed53f6/src/Model/ApnsMessage.php#L559-L598
train
libreworks/caridea-validate
src/Rule/Nested.php
Nested.finish
public function finish(\Caridea\Validate\Registry $registry): \Caridea\Validate\Rule { if ($this->validator instanceof \Caridea\Validate\Validator) { return $this; } else { $rule = clone $this; $builder = $registry->builder(); switch ($this->operator) { case "nested_object": case "list_objects": $rule->validator = $builder->build($this->validator); return $rule; case "list": $rule->validator = $builder->build((object)['entry' => $this->validator]); return $rule; case "list_different_objects": case "variable_object": $validators = []; foreach ($this->validator as $value => $ruleset) { $validators[$value] = $builder->build($ruleset); } $rule->validator = new \Caridea\Validate\SwitchValidator($this->field, $validators); return $rule; } } }
php
public function finish(\Caridea\Validate\Registry $registry): \Caridea\Validate\Rule { if ($this->validator instanceof \Caridea\Validate\Validator) { return $this; } else { $rule = clone $this; $builder = $registry->builder(); switch ($this->operator) { case "nested_object": case "list_objects": $rule->validator = $builder->build($this->validator); return $rule; case "list": $rule->validator = $builder->build((object)['entry' => $this->validator]); return $rule; case "list_different_objects": case "variable_object": $validators = []; foreach ($this->validator as $value => $ruleset) { $validators[$value] = $builder->build($ruleset); } $rule->validator = new \Caridea\Validate\SwitchValidator($this->field, $validators); return $rule; } } }
[ "public", "function", "finish", "(", "\\", "Caridea", "\\", "Validate", "\\", "Registry", "$", "registry", ")", ":", "\\", "Caridea", "\\", "Validate", "\\", "Rule", "{", "if", "(", "$", "this", "->", "validator", "instanceof", "\\", "Caridea", "\\", "Validate", "\\", "Validator", ")", "{", "return", "$", "this", ";", "}", "else", "{", "$", "rule", "=", "clone", "$", "this", ";", "$", "builder", "=", "$", "registry", "->", "builder", "(", ")", ";", "switch", "(", "$", "this", "->", "operator", ")", "{", "case", "\"nested_object\"", ":", "case", "\"list_objects\"", ":", "$", "rule", "->", "validator", "=", "$", "builder", "->", "build", "(", "$", "this", "->", "validator", ")", ";", "return", "$", "rule", ";", "case", "\"list\"", ":", "$", "rule", "->", "validator", "=", "$", "builder", "->", "build", "(", "(", "object", ")", "[", "'entry'", "=>", "$", "this", "->", "validator", "]", ")", ";", "return", "$", "rule", ";", "case", "\"list_different_objects\"", ":", "case", "\"variable_object\"", ":", "$", "validators", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "validator", "as", "$", "value", "=>", "$", "ruleset", ")", "{", "$", "validators", "[", "$", "value", "]", "=", "$", "builder", "->", "build", "(", "$", "ruleset", ")", ";", "}", "$", "rule", "->", "validator", "=", "new", "\\", "Caridea", "\\", "Validate", "\\", "SwitchValidator", "(", "$", "this", "->", "field", ",", "$", "validators", ")", ";", "return", "$", "rule", ";", "}", "}", "}" ]
Finishes creating a rule using the parent builder. @param \Caridea\Validate\Registry $registry @return \Caridea\Validate\Rule The fully created rule
[ "Finishes", "creating", "a", "rule", "using", "the", "parent", "builder", "." ]
625835694d34591bfb1e3b2ce60c2cc28a28d006
https://github.com/libreworks/caridea-validate/blob/625835694d34591bfb1e3b2ce60c2cc28a28d006/src/Rule/Nested.php#L64-L89
train
PenoaksDev/Milky-Framework
src/Milky/Database/Schema/Grammars/MySqlGrammar.php
MySqlGrammar.compileKey
protected function compileKey( Blueprint $blueprint, Fluent $command, $type ) { $columns = $this->columnize( $command->columns ); $table = $this->wrapTable( $blueprint ); $index = $this->wrap( $command->index ); return "alter table {$table} add {$type} {$index}($columns)"; }
php
protected function compileKey( Blueprint $blueprint, Fluent $command, $type ) { $columns = $this->columnize( $command->columns ); $table = $this->wrapTable( $blueprint ); $index = $this->wrap( $command->index ); return "alter table {$table} add {$type} {$index}($columns)"; }
[ "protected", "function", "compileKey", "(", "Blueprint", "$", "blueprint", ",", "Fluent", "$", "command", ",", "$", "type", ")", "{", "$", "columns", "=", "$", "this", "->", "columnize", "(", "$", "command", "->", "columns", ")", ";", "$", "table", "=", "$", "this", "->", "wrapTable", "(", "$", "blueprint", ")", ";", "$", "index", "=", "$", "this", "->", "wrap", "(", "$", "command", "->", "index", ")", ";", "return", "\"alter table {$table} add {$type} {$index}($columns)\"", ";", "}" ]
Compile an index creation command. @param Blueprint $blueprint @param Fluent $command @param string $type @return string
[ "Compile", "an", "index", "creation", "command", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Schema/Grammars/MySqlGrammar.php#L181-L190
train
shrink0r/monatic
src/Many.php
Many.flatMap
protected function flatMap(array $flattened, MonadInterface $result) { $value = $result->get(); if (!is_array($value)) { $value = [ $value ]; } return array_merge($flattened, $value); }
php
protected function flatMap(array $flattened, MonadInterface $result) { $value = $result->get(); if (!is_array($value)) { $value = [ $value ]; } return array_merge($flattened, $value); }
[ "protected", "function", "flatMap", "(", "array", "$", "flattened", ",", "MonadInterface", "$", "result", ")", "{", "$", "value", "=", "$", "result", "->", "get", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "[", "$", "value", "]", ";", "}", "return", "array_merge", "(", "$", "flattened", ",", "$", "value", ")", ";", "}" ]
Internal callback that is used in conjunction with php's array_reduce to flatten recursive chain results. @param array $flattened The current flat array. @param MonadInterface $result The result to be reduced into the flat array. @return array A new flat array created from merging in the flattened result.
[ "Internal", "callback", "that", "is", "used", "in", "conjunction", "with", "php", "s", "array_reduce", "to", "flatten", "recursive", "chain", "results", "." ]
f39b8b2ef68a397d31d844341487412b335fd107
https://github.com/shrink0r/monatic/blob/f39b8b2ef68a397d31d844341487412b335fd107/src/Many.php#L141-L150
train
kaiohken1982/NeobazaarDocumentModule
src/Document/Paginator/ClassifiedFull.php
ClassifiedFull.build
public function build(array $params = null) { if(null !== $params) { $this->setParams($params); } $this->adapter = $this->getDoctrinePaginatorAdapter(); $this->setCurrentPageNumber($this->getParam('page', 1)); $this->setDefaultItemCountPerPage($this->getParam('limit', 30)); }
php
public function build(array $params = null) { if(null !== $params) { $this->setParams($params); } $this->adapter = $this->getDoctrinePaginatorAdapter(); $this->setCurrentPageNumber($this->getParam('page', 1)); $this->setDefaultItemCountPerPage($this->getParam('limit', 30)); }
[ "public", "function", "build", "(", "array", "$", "params", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "params", ")", "{", "$", "this", "->", "setParams", "(", "$", "params", ")", ";", "}", "$", "this", "->", "adapter", "=", "$", "this", "->", "getDoctrinePaginatorAdapter", "(", ")", ";", "$", "this", "->", "setCurrentPageNumber", "(", "$", "this", "->", "getParam", "(", "'page'", ",", "1", ")", ")", ";", "$", "this", "->", "setDefaultItemCountPerPage", "(", "$", "this", "->", "getParam", "(", "'limit'", ",", "30", ")", ")", ";", "}" ]
Build the instance @param array $params
[ "Build", "the", "instance" ]
edb0223878fe02e791d2a0266c5a7c0f2029e3fe
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Paginator/ClassifiedFull.php#L61-L70
train
kaiohken1982/NeobazaarDocumentModule
src/Document/Paginator/ClassifiedFull.php
ClassifiedFull.getParam
public function getParam($param, $default = null) { if(array_key_exists($param, $this->params)) { return $this->params[$param]; } return $default; }
php
public function getParam($param, $default = null) { if(array_key_exists($param, $this->params)) { return $this->params[$param]; } return $default; }
[ "public", "function", "getParam", "(", "$", "param", ",", "$", "default", "=", "null", ")", "{", "if", "(", "array_key_exists", "(", "$", "param", ",", "$", "this", "->", "params", ")", ")", "{", "return", "$", "this", "->", "params", "[", "$", "param", "]", ";", "}", "return", "$", "default", ";", "}" ]
Get a specified param @param string $param @return mixed
[ "Get", "a", "specified", "param" ]
edb0223878fe02e791d2a0266c5a7c0f2029e3fe
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Paginator/ClassifiedFull.php#L101-L108
train