id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
12,200
bishopb/vanilla
library/core/class.autoloader.php
Gdn_Autoloader_Map.Index
public function Index($ExtraPaths = NULL) { $FileMasks = array( sprintf(self::LOOKUP_CLASS_MASK, '*'), sprintf(self::LOOKUP_INTERFACE_MASK, '*') ); $ExtraPathsRemove = NULL; if (!is_null($ExtraPaths)) { $ExtraPathsRemove = array(); foreach ($ExtraPaths as $PathOpts) { $ExtraPath = GetValue('path', $PathOpts); if (array_key_exists($ExtraPath, $this->Paths)) continue; $ExtraPathsRemove[] = $ExtraPath; $ExtraOptions = $this->BuildOptions; $ExtraOptions['SplitTopic'] = GetValue('topic', $PathOpts); $this->AddPath($ExtraPath, $ExtraOptions); } } foreach ($this->Paths as $Path => $PathOptions) { $Recursive = GetValue('recursive', $PathOptions); $Files = $this->FindFiles($Path, $FileMasks, $Recursive); if ($Files === FALSE) continue; foreach ($Files as $File) { $SplitTopic = GetValue('topic', $PathOptions, self::TOPIC_DEFAULT); $ProvidedClass = $this->GetClassNameFromFile($File); if ($ProvidedClass) { $this->Map[$SplitTopic][$ProvidedClass] = $File; $this->MapInfo['dirty'] = TRUE; } // $ProvidesClasses = $this->Investigate($File); // if ($ProvidesClasses === FALSE) continue; // // foreach ($ProvidesClasses as $ProvidedClass) { // $ProvidedClass = strtolower($ProvidedClass); // $this->Map[$SplitTopic][$ProvidedClass] = $File; // $this->MapInfo['dirty'] = TRUE; // } } } // Save $this->Shutdown(); if (!is_null($ExtraPathsRemove)) foreach ($ExtraPathsRemove as $RemPath) unset($this->Paths[$RemPath]); }
php
public function Index($ExtraPaths = NULL) { $FileMasks = array( sprintf(self::LOOKUP_CLASS_MASK, '*'), sprintf(self::LOOKUP_INTERFACE_MASK, '*') ); $ExtraPathsRemove = NULL; if (!is_null($ExtraPaths)) { $ExtraPathsRemove = array(); foreach ($ExtraPaths as $PathOpts) { $ExtraPath = GetValue('path', $PathOpts); if (array_key_exists($ExtraPath, $this->Paths)) continue; $ExtraPathsRemove[] = $ExtraPath; $ExtraOptions = $this->BuildOptions; $ExtraOptions['SplitTopic'] = GetValue('topic', $PathOpts); $this->AddPath($ExtraPath, $ExtraOptions); } } foreach ($this->Paths as $Path => $PathOptions) { $Recursive = GetValue('recursive', $PathOptions); $Files = $this->FindFiles($Path, $FileMasks, $Recursive); if ($Files === FALSE) continue; foreach ($Files as $File) { $SplitTopic = GetValue('topic', $PathOptions, self::TOPIC_DEFAULT); $ProvidedClass = $this->GetClassNameFromFile($File); if ($ProvidedClass) { $this->Map[$SplitTopic][$ProvidedClass] = $File; $this->MapInfo['dirty'] = TRUE; } // $ProvidesClasses = $this->Investigate($File); // if ($ProvidesClasses === FALSE) continue; // // foreach ($ProvidesClasses as $ProvidedClass) { // $ProvidedClass = strtolower($ProvidedClass); // $this->Map[$SplitTopic][$ProvidedClass] = $File; // $this->MapInfo['dirty'] = TRUE; // } } } // Save $this->Shutdown(); if (!is_null($ExtraPathsRemove)) foreach ($ExtraPathsRemove as $RemPath) unset($this->Paths[$RemPath]); }
[ "public", "function", "Index", "(", "$", "ExtraPaths", "=", "NULL", ")", "{", "$", "FileMasks", "=", "array", "(", "sprintf", "(", "self", "::", "LOOKUP_CLASS_MASK", ",", "'*'", ")", ",", "sprintf", "(", "self", "::", "LOOKUP_INTERFACE_MASK", ",", "'*'", ")", ")", ";", "$", "ExtraPathsRemove", "=", "NULL", ";", "if", "(", "!", "is_null", "(", "$", "ExtraPaths", ")", ")", "{", "$", "ExtraPathsRemove", "=", "array", "(", ")", ";", "foreach", "(", "$", "ExtraPaths", "as", "$", "PathOpts", ")", "{", "$", "ExtraPath", "=", "GetValue", "(", "'path'", ",", "$", "PathOpts", ")", ";", "if", "(", "array_key_exists", "(", "$", "ExtraPath", ",", "$", "this", "->", "Paths", ")", ")", "continue", ";", "$", "ExtraPathsRemove", "[", "]", "=", "$", "ExtraPath", ";", "$", "ExtraOptions", "=", "$", "this", "->", "BuildOptions", ";", "$", "ExtraOptions", "[", "'SplitTopic'", "]", "=", "GetValue", "(", "'topic'", ",", "$", "PathOpts", ")", ";", "$", "this", "->", "AddPath", "(", "$", "ExtraPath", ",", "$", "ExtraOptions", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "Paths", "as", "$", "Path", "=>", "$", "PathOptions", ")", "{", "$", "Recursive", "=", "GetValue", "(", "'recursive'", ",", "$", "PathOptions", ")", ";", "$", "Files", "=", "$", "this", "->", "FindFiles", "(", "$", "Path", ",", "$", "FileMasks", ",", "$", "Recursive", ")", ";", "if", "(", "$", "Files", "===", "FALSE", ")", "continue", ";", "foreach", "(", "$", "Files", "as", "$", "File", ")", "{", "$", "SplitTopic", "=", "GetValue", "(", "'topic'", ",", "$", "PathOptions", ",", "self", "::", "TOPIC_DEFAULT", ")", ";", "$", "ProvidedClass", "=", "$", "this", "->", "GetClassNameFromFile", "(", "$", "File", ")", ";", "if", "(", "$", "ProvidedClass", ")", "{", "$", "this", "->", "Map", "[", "$", "SplitTopic", "]", "[", "$", "ProvidedClass", "]", "=", "$", "File", ";", "$", "this", "->", "MapInfo", "[", "'dirty'", "]", "=", "TRUE", ";", "}", "// $ProvidesClasses = $this->Investigate($File);", "// if ($ProvidesClasses === FALSE) continue;", "// ", "// foreach ($ProvidesClasses as $ProvidedClass) {", "// $ProvidedClass = strtolower($ProvidedClass);", "// $this->Map[$SplitTopic][$ProvidedClass] = $File;", "// $this->MapInfo['dirty'] = TRUE;", "// }", "}", "}", "// Save", "$", "this", "->", "Shutdown", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "ExtraPathsRemove", ")", ")", "foreach", "(", "$", "ExtraPathsRemove", "as", "$", "RemPath", ")", "unset", "(", "$", "this", "->", "Paths", "[", "$", "RemPath", "]", ")", ";", "}" ]
Try to index the entire map @return void
[ "Try", "to", "index", "the", "entire", "map" ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.autoloader.php#L798-L851
12,201
phlexible/phlexible
src/Phlexible/Bundle/TeaserBundle/Twig/Extension/TeaserExtension.php
TeaserExtension.renderTeaser
public function renderTeaser(ContentTeaser $teaser, array $parameters = array(), array $options = array()) { $parameters['teaserId'] = $teaser->getId(); if ($this->requestStack->getMasterRequest()->attributes->get('_preview')) { $parameters['preview'] = true; } $uri = $this->router->generate('teaser_render', $parameters); $strategy = isset($options['strategy']) ? $options['strategy'] : 'inline'; unset($options['strategy']); return $this->handler->render($uri, $strategy, $options); }
php
public function renderTeaser(ContentTeaser $teaser, array $parameters = array(), array $options = array()) { $parameters['teaserId'] = $teaser->getId(); if ($this->requestStack->getMasterRequest()->attributes->get('_preview')) { $parameters['preview'] = true; } $uri = $this->router->generate('teaser_render', $parameters); $strategy = isset($options['strategy']) ? $options['strategy'] : 'inline'; unset($options['strategy']); return $this->handler->render($uri, $strategy, $options); }
[ "public", "function", "renderTeaser", "(", "ContentTeaser", "$", "teaser", ",", "array", "$", "parameters", "=", "array", "(", ")", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "parameters", "[", "'teaserId'", "]", "=", "$", "teaser", "->", "getId", "(", ")", ";", "if", "(", "$", "this", "->", "requestStack", "->", "getMasterRequest", "(", ")", "->", "attributes", "->", "get", "(", "'_preview'", ")", ")", "{", "$", "parameters", "[", "'preview'", "]", "=", "true", ";", "}", "$", "uri", "=", "$", "this", "->", "router", "->", "generate", "(", "'teaser_render'", ",", "$", "parameters", ")", ";", "$", "strategy", "=", "isset", "(", "$", "options", "[", "'strategy'", "]", ")", "?", "$", "options", "[", "'strategy'", "]", ":", "'inline'", ";", "unset", "(", "$", "options", "[", "'strategy'", "]", ")", ";", "return", "$", "this", "->", "handler", "->", "render", "(", "$", "uri", ",", "$", "strategy", ",", "$", "options", ")", ";", "}" ]
Renders a teaser. @param ContentTeaser $teaser @param array $parameters @param array $options @return string The fragment content @see FragmentHandler::render()
[ "Renders", "a", "teaser", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/TeaserBundle/Twig/Extension/TeaserExtension.php#L71-L85
12,202
crisu83/yii-caviar
src/helpers/Line.php
Line.text
public function text($string, $color = null, $bold = false) { if ($color !== null) { $this->colorize($color, (int) $bold); } if (!empty($string)) { $this->content .= $string . ' '; } $this->normalize(); return $this; }
php
public function text($string, $color = null, $bold = false) { if ($color !== null) { $this->colorize($color, (int) $bold); } if (!empty($string)) { $this->content .= $string . ' '; } $this->normalize(); return $this; }
[ "public", "function", "text", "(", "$", "string", ",", "$", "color", "=", "null", ",", "$", "bold", "=", "false", ")", "{", "if", "(", "$", "color", "!==", "null", ")", "{", "$", "this", "->", "colorize", "(", "$", "color", ",", "(", "int", ")", "$", "bold", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "string", ")", ")", "{", "$", "this", "->", "content", ".=", "$", "string", ".", "' '", ";", "}", "$", "this", "->", "normalize", "(", ")", ";", "return", "$", "this", ";", "}" ]
Adds texts to this line. @param string $string text to add. @param int|null $color text color. @param bool $bold whether to use bold text. @return Line this line.
[ "Adds", "texts", "to", "this", "line", "." ]
c85286b88e68558224e7f2ea7fff8f6975e46283
https://github.com/crisu83/yii-caviar/blob/c85286b88e68558224e7f2ea7fff8f6975e46283/src/helpers/Line.php#L65-L78
12,203
crisu83/yii-caviar
src/helpers/Line.php
Line.colorize
protected function colorize($color, $bold = 0) { if (!isset(self::$colors[$color])) { throw new Exception("Unknown color '$color'."); } $code = self::$colors[$color]; $this->content .= "\033[{$bold};{$code}m"; }
php
protected function colorize($color, $bold = 0) { if (!isset(self::$colors[$color])) { throw new Exception("Unknown color '$color'."); } $code = self::$colors[$color]; $this->content .= "\033[{$bold};{$code}m"; }
[ "protected", "function", "colorize", "(", "$", "color", ",", "$", "bold", "=", "0", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "colors", "[", "$", "color", "]", ")", ")", "{", "throw", "new", "Exception", "(", "\"Unknown color '$color'.\"", ")", ";", "}", "$", "code", "=", "self", "::", "$", "colors", "[", "$", "color", "]", ";", "$", "this", "->", "content", ".=", "\"\\033[{$bold};{$code}m\"", ";", "}" ]
Adds a color code to this line. @param int $color color code. @param int $bold whether to use bold text. @throws Exception if the color is invalid.
[ "Adds", "a", "color", "code", "to", "this", "line", "." ]
c85286b88e68558224e7f2ea7fff8f6975e46283
https://github.com/crisu83/yii-caviar/blob/c85286b88e68558224e7f2ea7fff8f6975e46283/src/helpers/Line.php#L138-L146
12,204
crisu83/yii-caviar
src/helpers/Line.php
Line.begin
public static function begin($string = '', $color = null, $bold = false) { return new Line($string, $color, $bold); }
php
public static function begin($string = '', $color = null, $bold = false) { return new Line($string, $color, $bold); }
[ "public", "static", "function", "begin", "(", "$", "string", "=", "''", ",", "$", "color", "=", "null", ",", "$", "bold", "=", "false", ")", "{", "return", "new", "Line", "(", "$", "string", ",", "$", "color", ",", "$", "bold", ")", ";", "}" ]
Creates a new line and returns it. @param string $string initial content. @param int|null $color text color. @param bool $bold whether to use bold text. @return Line a new line.
[ "Creates", "a", "new", "line", "and", "returns", "it", "." ]
c85286b88e68558224e7f2ea7fff8f6975e46283
https://github.com/crisu83/yii-caviar/blob/c85286b88e68558224e7f2ea7fff8f6975e46283/src/helpers/Line.php#L174-L177
12,205
neat-php/http
classes/Input.php
Input.load
public function load(...$sources) { if (!$sources) { throw new \RuntimeException('Sources must not be empty'); } $this->clear(); foreach ($sources as $source) { switch ($source) { case 'query': case 'post': case 'files': case 'cookie': $this->data = array_merge($this->data, $this->request->$source()); break; default: throw new \RuntimeException('Unknown source: ' . $source); } } if ($session = $this->session->get('input')) { $this->session->unset('input'); if (!$this->data) { $this->data = $session['data'] ?? []; $this->errors = $session['errors'] ?? []; } } }
php
public function load(...$sources) { if (!$sources) { throw new \RuntimeException('Sources must not be empty'); } $this->clear(); foreach ($sources as $source) { switch ($source) { case 'query': case 'post': case 'files': case 'cookie': $this->data = array_merge($this->data, $this->request->$source()); break; default: throw new \RuntimeException('Unknown source: ' . $source); } } if ($session = $this->session->get('input')) { $this->session->unset('input'); if (!$this->data) { $this->data = $session['data'] ?? []; $this->errors = $session['errors'] ?? []; } } }
[ "public", "function", "load", "(", "...", "$", "sources", ")", "{", "if", "(", "!", "$", "sources", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Sources must not be empty'", ")", ";", "}", "$", "this", "->", "clear", "(", ")", ";", "foreach", "(", "$", "sources", "as", "$", "source", ")", "{", "switch", "(", "$", "source", ")", "{", "case", "'query'", ":", "case", "'post'", ":", "case", "'files'", ":", "case", "'cookie'", ":", "$", "this", "->", "data", "=", "array_merge", "(", "$", "this", "->", "data", ",", "$", "this", "->", "request", "->", "$", "source", "(", ")", ")", ";", "break", ";", "default", ":", "throw", "new", "\\", "RuntimeException", "(", "'Unknown source: '", ".", "$", "source", ")", ";", "}", "}", "if", "(", "$", "session", "=", "$", "this", "->", "session", "->", "get", "(", "'input'", ")", ")", "{", "$", "this", "->", "session", "->", "unset", "(", "'input'", ")", ";", "if", "(", "!", "$", "this", "->", "data", ")", "{", "$", "this", "->", "data", "=", "$", "session", "[", "'data'", "]", "??", "[", "]", ";", "$", "this", "->", "errors", "=", "$", "session", "[", "'errors'", "]", "??", "[", "]", ";", "}", "}", "}" ]
Load input from the requested sources and the session Flushes all previously applied filters and validations @param array $sources
[ "Load", "input", "from", "the", "requested", "sources", "and", "the", "session" ]
5d4781a8481c1f708fd642292e44244435a8369c
https://github.com/neat-php/http/blob/5d4781a8481c1f708fd642292e44244435a8369c/classes/Input.php#L70-L97
12,206
neat-php/http
classes/Input.php
Input.retry
public function retry() { $this->session->set('input', [ 'data' => $this->data, 'errors' => $this->errors, ]); return Response::redirect($this->request->header('referer')); }
php
public function retry() { $this->session->set('input', [ 'data' => $this->data, 'errors' => $this->errors, ]); return Response::redirect($this->request->header('referer')); }
[ "public", "function", "retry", "(", ")", "{", "$", "this", "->", "session", "->", "set", "(", "'input'", ",", "[", "'data'", "=>", "$", "this", "->", "data", ",", "'errors'", "=>", "$", "this", "->", "errors", ",", "]", ")", ";", "return", "Response", "::", "redirect", "(", "$", "this", "->", "request", "->", "header", "(", "'referer'", ")", ")", ";", "}" ]
Retry the input at the referring URL Retains the input data using the session and returns a redirect response so the user can safely resume entering the input at the referring URL. @return Response
[ "Retry", "the", "input", "at", "the", "referring", "URL" ]
5d4781a8481c1f708fd642292e44244435a8369c
https://github.com/neat-php/http/blob/5d4781a8481c1f708fd642292e44244435a8369c/classes/Input.php#L107-L115
12,207
neat-php/http
classes/Input.php
Input.filter
public function filter($var, $filters, $type = null) { if (!is_array($filters)) { $filters = $filters ? explode('|', $filters) : []; } $value = &$this->data[$var] ?? null; if ($value === null) { return null; } foreach ($filters as $key => $filter) { $params = explode(':', $filter); $filter = is_string($key) ? $key : array_shift($params); $filter = $this->filters[$filter] ?? function (&$data) use ($filter, $params) { $data = $filter($data, ...$params); }; $errors = $filter($value, ...$params); if ($errors) { $this->errors[$var] = $errors; break; } if ($value === null) { return null; } } if ($type) { settype($value, $type); } return $value; }
php
public function filter($var, $filters, $type = null) { if (!is_array($filters)) { $filters = $filters ? explode('|', $filters) : []; } $value = &$this->data[$var] ?? null; if ($value === null) { return null; } foreach ($filters as $key => $filter) { $params = explode(':', $filter); $filter = is_string($key) ? $key : array_shift($params); $filter = $this->filters[$filter] ?? function (&$data) use ($filter, $params) { $data = $filter($data, ...$params); }; $errors = $filter($value, ...$params); if ($errors) { $this->errors[$var] = $errors; break; } if ($value === null) { return null; } } if ($type) { settype($value, $type); } return $value; }
[ "public", "function", "filter", "(", "$", "var", ",", "$", "filters", ",", "$", "type", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "filters", ")", ")", "{", "$", "filters", "=", "$", "filters", "?", "explode", "(", "'|'", ",", "$", "filters", ")", ":", "[", "]", ";", "}", "$", "value", "=", "&", "$", "this", "->", "data", "[", "$", "var", "]", "??", "null", ";", "if", "(", "$", "value", "===", "null", ")", "{", "return", "null", ";", "}", "foreach", "(", "$", "filters", "as", "$", "key", "=>", "$", "filter", ")", "{", "$", "params", "=", "explode", "(", "':'", ",", "$", "filter", ")", ";", "$", "filter", "=", "is_string", "(", "$", "key", ")", "?", "$", "key", ":", "array_shift", "(", "$", "params", ")", ";", "$", "filter", "=", "$", "this", "->", "filters", "[", "$", "filter", "]", "??", "function", "(", "&", "$", "data", ")", "use", "(", "$", "filter", ",", "$", "params", ")", "{", "$", "data", "=", "$", "filter", "(", "$", "data", ",", "...", "$", "params", ")", ";", "}", ";", "$", "errors", "=", "$", "filter", "(", "$", "value", ",", "...", "$", "params", ")", ";", "if", "(", "$", "errors", ")", "{", "$", "this", "->", "errors", "[", "$", "var", "]", "=", "$", "errors", ";", "break", ";", "}", "if", "(", "$", "value", "===", "null", ")", "{", "return", "null", ";", "}", "}", "if", "(", "$", "type", ")", "{", "settype", "(", "$", "value", ",", "$", "type", ")", ";", "}", "return", "$", "value", ";", "}" ]
Filter an input variable @param string $var @param string|array $filters @param string $type @return mixed|null
[ "Filter", "an", "input", "variable" ]
5d4781a8481c1f708fd642292e44244435a8369c
https://github.com/neat-php/http/blob/5d4781a8481c1f708fd642292e44244435a8369c/classes/Input.php#L190-L222
12,208
info-com/econtext-lib-file
src/php/econtext-lib-file/File.php
File.isReadable
public function isReadable() { $m = substr($this->mode, 0, 1); $p = strlen($this->mode) > 1 ? substr($this->mode, 1, 2) : ""; return ($m == "r" || $p == "+"); }
php
public function isReadable() { $m = substr($this->mode, 0, 1); $p = strlen($this->mode) > 1 ? substr($this->mode, 1, 2) : ""; return ($m == "r" || $p == "+"); }
[ "public", "function", "isReadable", "(", ")", "{", "$", "m", "=", "substr", "(", "$", "this", "->", "mode", ",", "0", ",", "1", ")", ";", "$", "p", "=", "strlen", "(", "$", "this", "->", "mode", ")", ">", "1", "?", "substr", "(", "$", "this", "->", "mode", ",", "1", ",", "2", ")", ":", "\"\"", ";", "return", "(", "$", "m", "==", "\"r\"", "||", "$", "p", "==", "\"+\"", ")", ";", "}" ]
Is the file readable? @return boolean
[ "Is", "the", "file", "readable?" ]
1ad828ddd90a4d36ec67bd60f938ef1bfc7229e1
https://github.com/info-com/econtext-lib-file/blob/1ad828ddd90a4d36ec67bd60f938ef1bfc7229e1/src/php/econtext-lib-file/File.php#L79-L83
12,209
info-com/econtext-lib-file
src/php/econtext-lib-file/File.php
File.write
public function write($string, $length=null) { $this->assertWritable(); return $this->format->write($this->file, $string, $length); }
php
public function write($string, $length=null) { $this->assertWritable(); return $this->format->write($this->file, $string, $length); }
[ "public", "function", "write", "(", "$", "string", ",", "$", "length", "=", "null", ")", "{", "$", "this", "->", "assertWritable", "(", ")", ";", "return", "$", "this", "->", "format", "->", "write", "(", "$", "this", "->", "file", ",", "$", "string", ",", "$", "length", ")", ";", "}" ]
Write the string to file @param string $string Content to write to file @param mixed $length If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first @see http://us3.php.net/manual/en/function.fwrite.php
[ "Write", "the", "string", "to", "file" ]
1ad828ddd90a4d36ec67bd60f938ef1bfc7229e1
https://github.com/info-com/econtext-lib-file/blob/1ad828ddd90a4d36ec67bd60f938ef1bfc7229e1/src/php/econtext-lib-file/File.php#L132-L135
12,210
info-com/econtext-lib-file
src/php/econtext-lib-file/File.php
File.readline
public function readline($length=null) { $this->assertReadable(); return $this->format->readline($this->file, $length); }
php
public function readline($length=null) { $this->assertReadable(); return $this->format->readline($this->file, $length); }
[ "public", "function", "readline", "(", "$", "length", "=", "null", ")", "{", "$", "this", "->", "assertReadable", "(", ")", ";", "return", "$", "this", "->", "format", "->", "readline", "(", "$", "this", "->", "file", ",", "$", "length", ")", ";", "}" ]
Read a line from the file @param int $length If specified, read this many bytes @see http://www.php.net/manual/en/function.fgets.php
[ "Read", "a", "line", "from", "the", "file" ]
1ad828ddd90a4d36ec67bd60f938ef1bfc7229e1
https://github.com/info-com/econtext-lib-file/blob/1ad828ddd90a4d36ec67bd60f938ef1bfc7229e1/src/php/econtext-lib-file/File.php#L143-L146
12,211
info-com/econtext-lib-file
src/php/econtext-lib-file/File.php
File.unlink
public function unlink() { if($this->isOpen()) { $this->close(); } if($this->exists()) { if(unlink($this->filepath)) { $this->unlinked = true; } } }
php
public function unlink() { if($this->isOpen()) { $this->close(); } if($this->exists()) { if(unlink($this->filepath)) { $this->unlinked = true; } } }
[ "public", "function", "unlink", "(", ")", "{", "if", "(", "$", "this", "->", "isOpen", "(", ")", ")", "{", "$", "this", "->", "close", "(", ")", ";", "}", "if", "(", "$", "this", "->", "exists", "(", ")", ")", "{", "if", "(", "unlink", "(", "$", "this", "->", "filepath", ")", ")", "{", "$", "this", "->", "unlinked", "=", "true", ";", "}", "}", "}" ]
Remove the file from the filesystem @return boolean Successfully deleted the file
[ "Remove", "the", "file", "from", "the", "filesystem" ]
1ad828ddd90a4d36ec67bd60f938ef1bfc7229e1
https://github.com/info-com/econtext-lib-file/blob/1ad828ddd90a4d36ec67bd60f938ef1bfc7229e1/src/php/econtext-lib-file/File.php#L196-L205
12,212
Persata/SymfonyApiExtension
src/ServiceContainer/SymfonyApiExtension.php
SymfonyApiExtension.initialize
public function initialize(ExtensionManager $extensionManager) { $symfonyExtension = $extensionManager->getExtension('fob_symfony'); if (null === $symfonyExtension) { throw new ExtensionInitializationException(sprintf('The %s extension must be enabled for this extension to function.', SymfonyExtension::class), $this->getConfigKey()); } }
php
public function initialize(ExtensionManager $extensionManager) { $symfonyExtension = $extensionManager->getExtension('fob_symfony'); if (null === $symfonyExtension) { throw new ExtensionInitializationException(sprintf('The %s extension must be enabled for this extension to function.', SymfonyExtension::class), $this->getConfigKey()); } }
[ "public", "function", "initialize", "(", "ExtensionManager", "$", "extensionManager", ")", "{", "$", "symfonyExtension", "=", "$", "extensionManager", "->", "getExtension", "(", "'fob_symfony'", ")", ";", "if", "(", "null", "===", "$", "symfonyExtension", ")", "{", "throw", "new", "ExtensionInitializationException", "(", "sprintf", "(", "'The %s extension must be enabled for this extension to function.'", ",", "SymfonyExtension", "::", "class", ")", ",", "$", "this", "->", "getConfigKey", "(", ")", ")", ";", "}", "}" ]
Initializes other extensions. This method is called immediately after all extensions are activated but before any extension `configure()` method is called. This allows extensions to hook into the configuration of other extensions providing such an extension point. @param ExtensionManager $extensionManager
[ "Initializes", "other", "extensions", "." ]
89fcfbd13b462c184ab208215b8b12199e8647dd
https://github.com/Persata/SymfonyApiExtension/blob/89fcfbd13b462c184ab208215b8b12199e8647dd/src/ServiceContainer/SymfonyApiExtension.php#L60-L67
12,213
stevenberg/responsible-images-php
src/Values/Size.php
Size.add
public function add(self $other): self { return self::from($this->value + $other->value); }
php
public function add(self $other): self { return self::from($this->value + $other->value); }
[ "public", "function", "add", "(", "self", "$", "other", ")", ":", "self", "{", "return", "self", "::", "from", "(", "$", "this", "->", "value", "+", "$", "other", "->", "value", ")", ";", "}" ]
Add two Sizes and return the sum.
[ "Add", "two", "Sizes", "and", "return", "the", "sum", "." ]
a890fc2b3d011c660161aae0e18709dadf00e43f
https://github.com/stevenberg/responsible-images-php/blob/a890fc2b3d011c660161aae0e18709dadf00e43f/src/Values/Size.php#L23-L26
12,214
parfumix/laravel-translator
src/Drivers/Yandex.php
Yandex.getStoreTranslation
protected function getStoreTranslation($key, $locale) { if( ! isset($this->translations[$locale][$key]) ) { $response = $this->apiRequest( $this->getAttribute('api_url'), [ 'text' => $key, 'lang' => $locale] ); $response = json_decode($response, true); $this->translations[$locale][$key] = $response['text'][0]; } return $this->translations[$locale][$key]; }
php
protected function getStoreTranslation($key, $locale) { if( ! isset($this->translations[$locale][$key]) ) { $response = $this->apiRequest( $this->getAttribute('api_url'), [ 'text' => $key, 'lang' => $locale] ); $response = json_decode($response, true); $this->translations[$locale][$key] = $response['text'][0]; } return $this->translations[$locale][$key]; }
[ "protected", "function", "getStoreTranslation", "(", "$", "key", ",", "$", "locale", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "translations", "[", "$", "locale", "]", "[", "$", "key", "]", ")", ")", "{", "$", "response", "=", "$", "this", "->", "apiRequest", "(", "$", "this", "->", "getAttribute", "(", "'api_url'", ")", ",", "[", "'text'", "=>", "$", "key", ",", "'lang'", "=>", "$", "locale", "]", ")", ";", "$", "response", "=", "json_decode", "(", "$", "response", ",", "true", ")", ";", "$", "this", "->", "translations", "[", "$", "locale", "]", "[", "$", "key", "]", "=", "$", "response", "[", "'text'", "]", "[", "0", "]", ";", "}", "return", "$", "this", "->", "translations", "[", "$", "locale", "]", "[", "$", "key", "]", ";", "}" ]
Get translation and cache it . @param $key @param null $locale @return mixed
[ "Get", "translation", "and", "cache", "it", "." ]
b85f17cbfebd4f35d1bfb817fbf13bff2c3f487e
https://github.com/parfumix/laravel-translator/blob/b85f17cbfebd4f35d1bfb817fbf13bff2c3f487e/src/Drivers/Yandex.php#L89-L101
12,215
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/db.php
DB.list_columns
public static function list_columns($table = null, $like = null, $db = null) { return \Database_Connection::instance($db)->list_columns($table, $like); }
php
public static function list_columns($table = null, $like = null, $db = null) { return \Database_Connection::instance($db)->list_columns($table, $like); }
[ "public", "static", "function", "list_columns", "(", "$", "table", "=", "null", ",", "$", "like", "=", "null", ",", "$", "db", "=", "null", ")", "{", "return", "\\", "Database_Connection", "::", "instance", "(", "$", "db", ")", "->", "list_columns", "(", "$", "table", ",", "$", "like", ")", ";", "}" ]
Lists all of the columns in a table. Optionally, a LIKE string can be used to search for specific fields. // Get all columns from the "users" table $columns = DB::list_columns('users'); // Get all name-related columns $columns = DB::list_columns('users', '%name%'); @param string table to get columns from @param string column to search for @param string the database connection to use @return array
[ "Lists", "all", "of", "the", "columns", "in", "a", "table", ".", "Optionally", "a", "LIKE", "string", "can", "be", "used", "to", "search", "for", "specific", "fields", "." ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/db.php#L275-L278
12,216
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/db.php
DB.rollback_transaction
public static function rollback_transaction($db = null, $rollback_all = true) { return \Database_Connection::instance($db)->rollback_transaction($rollback_all); }
php
public static function rollback_transaction($db = null, $rollback_all = true) { return \Database_Connection::instance($db)->rollback_transaction($rollback_all); }
[ "public", "static", "function", "rollback_transaction", "(", "$", "db", "=", "null", ",", "$", "rollback_all", "=", "true", ")", "{", "return", "\\", "Database_Connection", "::", "instance", "(", "$", "db", ")", "->", "rollback_transaction", "(", "$", "rollback_all", ")", ";", "}" ]
Rollsback pending transactional queries Rollback to the current level uses SAVEPOINT, it does not work if current RDBMS does not support them. In this case system rollsback all queries and closes the transaction DB::rollback_transaction(); @param string $db connection @param bool $rollback_all: true - rollback everything and close transaction; false - rollback only current level @return bool
[ "Rollsback", "pending", "transactional", "queries", "Rollback", "to", "the", "current", "level", "uses", "SAVEPOINT", "it", "does", "not", "work", "if", "current", "RDBMS", "does", "not", "support", "them", ".", "In", "this", "case", "system", "rollsback", "all", "queries", "and", "closes", "the", "transaction" ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/db.php#L404-L407
12,217
novuso/system
src/Collection/Traits/ItemTypeMethods.php
ItemTypeMethods.setItemType
protected function setItemType(?string $itemType = null): void { if ($itemType !== null) { $itemType = trim($itemType); } $this->itemType = $itemType; }
php
protected function setItemType(?string $itemType = null): void { if ($itemType !== null) { $itemType = trim($itemType); } $this->itemType = $itemType; }
[ "protected", "function", "setItemType", "(", "?", "string", "$", "itemType", "=", "null", ")", ":", "void", "{", "if", "(", "$", "itemType", "!==", "null", ")", "{", "$", "itemType", "=", "trim", "(", "$", "itemType", ")", ";", "}", "$", "this", "->", "itemType", "=", "$", "itemType", ";", "}" ]
Sets the item type If a type is not provided, the item type is dynamic. The type can be any fully-qualified class or interface name, or one of the following type strings: [array, object, bool, int, float, string, callable] @param string|null $itemType The item type @return void
[ "Sets", "the", "item", "type" ]
e34038b391826edc68d0b5fccfba96642de9d6f0
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Collection/Traits/ItemTypeMethods.php#L48-L55
12,218
novuso/system
src/Collection/Traits/ItemTypeMethods.php
ItemTypeMethods.itemTypeError
protected function itemTypeError(string $method, $item): string { $itemType = is_object($item) ? get_class($item) : gettype($item); return sprintf( '%s::%s expects item type (%s); received (%s) %s', static::class, $method, $this->itemType(), $itemType, VarPrinter::toString($item) ); }
php
protected function itemTypeError(string $method, $item): string { $itemType = is_object($item) ? get_class($item) : gettype($item); return sprintf( '%s::%s expects item type (%s); received (%s) %s', static::class, $method, $this->itemType(), $itemType, VarPrinter::toString($item) ); }
[ "protected", "function", "itemTypeError", "(", "string", "$", "method", ",", "$", "item", ")", ":", "string", "{", "$", "itemType", "=", "is_object", "(", "$", "item", ")", "?", "get_class", "(", "$", "item", ")", ":", "gettype", "(", "$", "item", ")", ";", "return", "sprintf", "(", "'%s::%s expects item type (%s); received (%s) %s'", ",", "static", "::", "class", ",", "$", "method", ",", "$", "this", "->", "itemType", "(", ")", ",", "$", "itemType", ",", "VarPrinter", "::", "toString", "(", "$", "item", ")", ")", ";", "}" ]
Retrieves the item type error message @param string $method The calling method @param mixed $item The item @return string
[ "Retrieves", "the", "item", "type", "error", "message" ]
e34038b391826edc68d0b5fccfba96642de9d6f0
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Collection/Traits/ItemTypeMethods.php#L65-L77
12,219
synapsestudios/synapse-base
src/Synapse/Migration/CreateMigrationCommand.php
CreateMigrationCommand.execute
public function execute(InputInterface $input, OutputInterface $output) { $description = $input->getArgument('description'); $time = date('YmdHis'); $classname = $this->generateClassName($time, $description); $filepath = APPDIR.'/src/'.$this->namespaceToPath().$classname.'.php'; if (! is_dir(dirname($filepath))) { mkdir(dirname($filepath), 0775, true); } $view = $this->newMigrationView; $view->description($description); $view->classname($classname); $view->timestamp($time); file_put_contents($filepath, (string) $view); $message = ' Created migration file '.$filepath; // Output message padded by newlines $output->write(['', $message, ''], true); }
php
public function execute(InputInterface $input, OutputInterface $output) { $description = $input->getArgument('description'); $time = date('YmdHis'); $classname = $this->generateClassName($time, $description); $filepath = APPDIR.'/src/'.$this->namespaceToPath().$classname.'.php'; if (! is_dir(dirname($filepath))) { mkdir(dirname($filepath), 0775, true); } $view = $this->newMigrationView; $view->description($description); $view->classname($classname); $view->timestamp($time); file_put_contents($filepath, (string) $view); $message = ' Created migration file '.$filepath; // Output message padded by newlines $output->write(['', $message, ''], true); }
[ "public", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "description", "=", "$", "input", "->", "getArgument", "(", "'description'", ")", ";", "$", "time", "=", "date", "(", "'YmdHis'", ")", ";", "$", "classname", "=", "$", "this", "->", "generateClassName", "(", "$", "time", ",", "$", "description", ")", ";", "$", "filepath", "=", "APPDIR", ".", "'/src/'", ".", "$", "this", "->", "namespaceToPath", "(", ")", ".", "$", "classname", ".", "'.php'", ";", "if", "(", "!", "is_dir", "(", "dirname", "(", "$", "filepath", ")", ")", ")", "{", "mkdir", "(", "dirname", "(", "$", "filepath", ")", ",", "0775", ",", "true", ")", ";", "}", "$", "view", "=", "$", "this", "->", "newMigrationView", ";", "$", "view", "->", "description", "(", "$", "description", ")", ";", "$", "view", "->", "classname", "(", "$", "classname", ")", ";", "$", "view", "->", "timestamp", "(", "$", "time", ")", ";", "file_put_contents", "(", "$", "filepath", ",", "(", "string", ")", "$", "view", ")", ";", "$", "message", "=", "' Created migration file '", ".", "$", "filepath", ";", "// Output message padded by newlines", "$", "output", "->", "write", "(", "[", "''", ",", "$", "message", ",", "''", "]", ",", "true", ")", ";", "}" ]
Execute this console command, in order to create a new migration @param InputInterface $input Command line input interface @param OutputInterface $output Command line output interface
[ "Execute", "this", "console", "command", "in", "order", "to", "create", "a", "new", "migration" ]
60c830550491742a077ab063f924e2f0b63825da
https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Migration/CreateMigrationCommand.php#L56-L79
12,220
synapsestudios/synapse-base
src/Synapse/Migration/CreateMigrationCommand.php
CreateMigrationCommand.generateClassName
protected function generateClassName($time, $description) { $description = substr(strtolower($description), 0, 30); $description = ucwords($description); $description = preg_replace('/[^a-zA-Z]+/', '', $description); return 'Migration'.$time.$description; }
php
protected function generateClassName($time, $description) { $description = substr(strtolower($description), 0, 30); $description = ucwords($description); $description = preg_replace('/[^a-zA-Z]+/', '', $description); return 'Migration'.$time.$description; }
[ "protected", "function", "generateClassName", "(", "$", "time", ",", "$", "description", ")", "{", "$", "description", "=", "substr", "(", "strtolower", "(", "$", "description", ")", ",", "0", ",", "30", ")", ";", "$", "description", "=", "ucwords", "(", "$", "description", ")", ";", "$", "description", "=", "preg_replace", "(", "'/[^a-zA-Z]+/'", ",", "''", ",", "$", "description", ")", ";", "return", "'Migration'", ".", "$", "time", ".", "$", "description", ";", "}" ]
Get the name of the new migration class Converts description to PascalCase and prepends constant string and timestamp. Example: // From: Example description of a migration // To: Migration20140220001906ExampleDescriptionOfAMigration @param string $time Timestamp @param string $description User-provided description of new migration @return string
[ "Get", "the", "name", "of", "the", "new", "migration", "class" ]
60c830550491742a077ab063f924e2f0b63825da
https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Migration/CreateMigrationCommand.php#L96-L102
12,221
Hexmedia/Administrator-Bundle
Controller/CrudController.php
CrudController.createCreateForm
protected function createCreateForm($entity) { $form = $this->createForm( $this->getAddFormType(), $entity, [ 'action' => $this->generateUrl($this->getRouteName() . "Add", $this->getRouteParams()), 'method' => 'POST', ] ); return $form; }
php
protected function createCreateForm($entity) { $form = $this->createForm( $this->getAddFormType(), $entity, [ 'action' => $this->generateUrl($this->getRouteName() . "Add", $this->getRouteParams()), 'method' => 'POST', ] ); return $form; }
[ "protected", "function", "createCreateForm", "(", "$", "entity", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "$", "this", "->", "getAddFormType", "(", ")", ",", "$", "entity", ",", "[", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "$", "this", "->", "getRouteName", "(", ")", ".", "\"Add\"", ",", "$", "this", "->", "getRouteParams", "(", ")", ")", ",", "'method'", "=>", "'POST'", ",", "]", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to create an entity. @param mixed $entity The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "create", "an", "entity", "." ]
ac76cf3d226cd645a0976cfb6f3e6b058fa89890
https://github.com/Hexmedia/Administrator-Bundle/blob/ac76cf3d226cd645a0976cfb6f3e6b058fa89890/Controller/CrudController.php#L149-L159
12,222
Hexmedia/Administrator-Bundle
Controller/CrudController.php
CrudController.createEditForm
protected function createEditForm($entity) { $form = $this->createForm( $this->getEditFormType(), $entity, [ 'action' => $this->generateUrl($this->getRouteName() . "Edit", $this->getRouteParams(['id' => $entity->getId()])), 'method' => 'POST', ] ); return $form; }
php
protected function createEditForm($entity) { $form = $this->createForm( $this->getEditFormType(), $entity, [ 'action' => $this->generateUrl($this->getRouteName() . "Edit", $this->getRouteParams(['id' => $entity->getId()])), 'method' => 'POST', ] ); return $form; }
[ "protected", "function", "createEditForm", "(", "$", "entity", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "$", "this", "->", "getEditFormType", "(", ")", ",", "$", "entity", ",", "[", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "$", "this", "->", "getRouteName", "(", ")", ".", "\"Edit\"", ",", "$", "this", "->", "getRouteParams", "(", "[", "'id'", "=>", "$", "entity", "->", "getId", "(", ")", "]", ")", ")", ",", "'method'", "=>", "'POST'", ",", "]", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to edit an entity. @param mixed $entity The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "edit", "an", "entity", "." ]
ac76cf3d226cd645a0976cfb6f3e6b058fa89890
https://github.com/Hexmedia/Administrator-Bundle/blob/ac76cf3d226cd645a0976cfb6f3e6b058fa89890/Controller/CrudController.php#L210-L220
12,223
zepi/turbo-base
Zepi/Core/AccessControl/src/Manager/AccessControlManager.php
AccessControlManager.getPermissionForId
public function getPermissionForId($id) { $permission = $this->permissionsDataSource->getPermissionForId($id); if ($permission instanceof \Zepi\Core\AccessControl\Entity\Permission) { $accessEntity = $this->getAccessEntityForUuid($permission->getAccessEntityClass(), $permission->getAccessEntityUuid()); if ($accessEntity instanceof \Zepi\Core\AccessControl\Entity\AccessEntity) { $permission->setAccessEntity($accessEntity); } } return $permission; }
php
public function getPermissionForId($id) { $permission = $this->permissionsDataSource->getPermissionForId($id); if ($permission instanceof \Zepi\Core\AccessControl\Entity\Permission) { $accessEntity = $this->getAccessEntityForUuid($permission->getAccessEntityClass(), $permission->getAccessEntityUuid()); if ($accessEntity instanceof \Zepi\Core\AccessControl\Entity\AccessEntity) { $permission->setAccessEntity($accessEntity); } } return $permission; }
[ "public", "function", "getPermissionForId", "(", "$", "id", ")", "{", "$", "permission", "=", "$", "this", "->", "permissionsDataSource", "->", "getPermissionForId", "(", "$", "id", ")", ";", "if", "(", "$", "permission", "instanceof", "\\", "Zepi", "\\", "Core", "\\", "AccessControl", "\\", "Entity", "\\", "Permission", ")", "{", "$", "accessEntity", "=", "$", "this", "->", "getAccessEntityForUuid", "(", "$", "permission", "->", "getAccessEntityClass", "(", ")", ",", "$", "permission", "->", "getAccessEntityUuid", "(", ")", ")", ";", "if", "(", "$", "accessEntity", "instanceof", "\\", "Zepi", "\\", "Core", "\\", "AccessControl", "\\", "Entity", "\\", "AccessEntity", ")", "{", "$", "permission", "->", "setAccessEntity", "(", "$", "accessEntity", ")", ";", "}", "}", "return", "$", "permission", ";", "}" ]
Returns the permission object for the given id @access public @param integer $id @return false|\Zepi\Core\AccessControl\Entity\Permission
[ "Returns", "the", "permission", "object", "for", "the", "given", "id" ]
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Core/AccessControl/src/Manager/AccessControlManager.php#L240-L253
12,224
zepi/turbo-base
Zepi/Core/AccessControl/src/Manager/AccessControlManager.php
AccessControlManager.updatePermissions
public function updatePermissions(AccessEntity $accessEntity, $accessLevels, AccessEntity $donor) { $permissions = $this->getPermissionsRawForUuid($accessEntity->getUuid()); $grantedPermissions = array_diff($accessLevels, $permissions); $revokedPermissions = array_diff($permissions, $accessLevels); // Grant the added access levels foreach ($grantedPermissions as $accessLevel) { if (!$donor->hasAccess($accessLevel)) { continue; } $this->grantPermission($accessEntity->getUuid(), get_class($accessEntity), $accessLevel, $donor->getName()); } // Revoke the removed access levels foreach ($revokedPermissions as $accessLevel) { if (!$donor->hasAccess($accessLevel)) { continue; } $this->revokePermission($accessEntity->getUuid(), get_class($accessEntity), $accessLevel); } }
php
public function updatePermissions(AccessEntity $accessEntity, $accessLevels, AccessEntity $donor) { $permissions = $this->getPermissionsRawForUuid($accessEntity->getUuid()); $grantedPermissions = array_diff($accessLevels, $permissions); $revokedPermissions = array_diff($permissions, $accessLevels); // Grant the added access levels foreach ($grantedPermissions as $accessLevel) { if (!$donor->hasAccess($accessLevel)) { continue; } $this->grantPermission($accessEntity->getUuid(), get_class($accessEntity), $accessLevel, $donor->getName()); } // Revoke the removed access levels foreach ($revokedPermissions as $accessLevel) { if (!$donor->hasAccess($accessLevel)) { continue; } $this->revokePermission($accessEntity->getUuid(), get_class($accessEntity), $accessLevel); } }
[ "public", "function", "updatePermissions", "(", "AccessEntity", "$", "accessEntity", ",", "$", "accessLevels", ",", "AccessEntity", "$", "donor", ")", "{", "$", "permissions", "=", "$", "this", "->", "getPermissionsRawForUuid", "(", "$", "accessEntity", "->", "getUuid", "(", ")", ")", ";", "$", "grantedPermissions", "=", "array_diff", "(", "$", "accessLevels", ",", "$", "permissions", ")", ";", "$", "revokedPermissions", "=", "array_diff", "(", "$", "permissions", ",", "$", "accessLevels", ")", ";", "// Grant the added access levels", "foreach", "(", "$", "grantedPermissions", "as", "$", "accessLevel", ")", "{", "if", "(", "!", "$", "donor", "->", "hasAccess", "(", "$", "accessLevel", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "grantPermission", "(", "$", "accessEntity", "->", "getUuid", "(", ")", ",", "get_class", "(", "$", "accessEntity", ")", ",", "$", "accessLevel", ",", "$", "donor", "->", "getName", "(", ")", ")", ";", "}", "// Revoke the removed access levels", "foreach", "(", "$", "revokedPermissions", "as", "$", "accessLevel", ")", "{", "if", "(", "!", "$", "donor", "->", "hasAccess", "(", "$", "accessLevel", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "revokePermission", "(", "$", "accessEntity", "->", "getUuid", "(", ")", ",", "get_class", "(", "$", "accessEntity", ")", ",", "$", "accessLevel", ")", ";", "}", "}" ]
Adds and removes an array with access level to the given access entity uuid. If the donor hasn't the permission for the access level no action is taken. @access public @param \Zepi\Core\AccessControl\Entity\AccessEntity $accessEntity @param array $accessLevels @param \Zepi\Core\AccessControl\Entity\AccessEntity $donor
[ "Adds", "and", "removes", "an", "array", "with", "access", "level", "to", "the", "given", "access", "entity", "uuid", ".", "If", "the", "donor", "hasn", "t", "the", "permission", "for", "the", "access", "level", "no", "action", "is", "taken", "." ]
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Core/AccessControl/src/Manager/AccessControlManager.php#L345-L369
12,225
Webiny/BackupService
src/Webiny/BackupService/Lib/BackupMongo.php
BackupMongo.exportDatabases
public function exportDatabases() { $exports = []; foreach ($this->databases as $db) { $exports[] = $this->createExport($db); } return $exports; }
php
public function exportDatabases() { $exports = []; foreach ($this->databases as $db) { $exports[] = $this->createExport($db); } return $exports; }
[ "public", "function", "exportDatabases", "(", ")", "{", "$", "exports", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "databases", "as", "$", "db", ")", "{", "$", "exports", "[", "]", "=", "$", "this", "->", "createExport", "(", "$", "db", ")", ";", "}", "return", "$", "exports", ";", "}" ]
Loops over the list of databases and calls createExport method. @return array List of database export directories. @throws \Exception
[ "Loops", "over", "the", "list", "of", "databases", "and", "calls", "createExport", "method", "." ]
9728ddaa67e5703ac7898a6f69a0ad14ac37a256
https://github.com/Webiny/BackupService/blob/9728ddaa67e5703ac7898a6f69a0ad14ac37a256/src/Webiny/BackupService/Lib/BackupMongo.php#L54-L62
12,226
Webiny/BackupService
src/Webiny/BackupService/Lib/BackupMongo.php
BackupMongo.createExport
private function createExport($db) { Service::$log->msg(sprintf('Mongodb: exporting "%s" database.', $db['Database'])); $cmd = 'mongodump'; if (!isset($db['Database'])) { throw new \Exception(sprintf('Missing "Database" parameter for one of the MongoDatabases')); } $cmd .= ' --db ' . $db['Database']; if (!isset($db['Host'])) { throw new \Exception(sprintf('Missing "Host" parameter for "%s" database', $db['Database'])); } $host = explode(':', $db['Host']); $cmd .= ' --host ' . $host[0]; if (isset($host[1])) { $cmd .= ' --port ' . $host[1]; } if (isset($db['Username']) && !empty($db['Username'])) { $cmd .= ' --username ' . $db['Username']; } if (isset($db['Password']) && !empty($db['Password'])) { $cmd .= ' --password ' . $db['Password']; if(!isset($db['AuthenticationDatabase'])){ $cmd .= ' --authenticationDatabase admin'; }else{ $cmd .= ' --authenticationDatabase '.$db['AuthenticationDatabase']; } } // create a folder for this database export $folderName = $this->tempFolder . $db['Database'] . '-' . date('Y-m-d'); $cmd .= ' --out ' . $folderName; // mask password from log command if(isset($db['Password'])){ $logCommand = str_replace(' --password ' . $db['Password'], ' --password xxxxxx', $cmd); }else{ $logCommand = $cmd; } Service::$log->msg(sprintf('Mongodb: export command ' . $logCommand)); $return = system($cmd); Service::$log->msg(sprintf('Mongodb: '.$return)); Service::$log->msg(sprintf('Mongodb: database export done')); Cleanup::addToQueue($folderName, Cleanup::TYPE_DIR); return $folderName; }
php
private function createExport($db) { Service::$log->msg(sprintf('Mongodb: exporting "%s" database.', $db['Database'])); $cmd = 'mongodump'; if (!isset($db['Database'])) { throw new \Exception(sprintf('Missing "Database" parameter for one of the MongoDatabases')); } $cmd .= ' --db ' . $db['Database']; if (!isset($db['Host'])) { throw new \Exception(sprintf('Missing "Host" parameter for "%s" database', $db['Database'])); } $host = explode(':', $db['Host']); $cmd .= ' --host ' . $host[0]; if (isset($host[1])) { $cmd .= ' --port ' . $host[1]; } if (isset($db['Username']) && !empty($db['Username'])) { $cmd .= ' --username ' . $db['Username']; } if (isset($db['Password']) && !empty($db['Password'])) { $cmd .= ' --password ' . $db['Password']; if(!isset($db['AuthenticationDatabase'])){ $cmd .= ' --authenticationDatabase admin'; }else{ $cmd .= ' --authenticationDatabase '.$db['AuthenticationDatabase']; } } // create a folder for this database export $folderName = $this->tempFolder . $db['Database'] . '-' . date('Y-m-d'); $cmd .= ' --out ' . $folderName; // mask password from log command if(isset($db['Password'])){ $logCommand = str_replace(' --password ' . $db['Password'], ' --password xxxxxx', $cmd); }else{ $logCommand = $cmd; } Service::$log->msg(sprintf('Mongodb: export command ' . $logCommand)); $return = system($cmd); Service::$log->msg(sprintf('Mongodb: '.$return)); Service::$log->msg(sprintf('Mongodb: database export done')); Cleanup::addToQueue($folderName, Cleanup::TYPE_DIR); return $folderName; }
[ "private", "function", "createExport", "(", "$", "db", ")", "{", "Service", "::", "$", "log", "->", "msg", "(", "sprintf", "(", "'Mongodb: exporting \"%s\" database.'", ",", "$", "db", "[", "'Database'", "]", ")", ")", ";", "$", "cmd", "=", "'mongodump'", ";", "if", "(", "!", "isset", "(", "$", "db", "[", "'Database'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Missing \"Database\" parameter for one of the MongoDatabases'", ")", ")", ";", "}", "$", "cmd", ".=", "' --db '", ".", "$", "db", "[", "'Database'", "]", ";", "if", "(", "!", "isset", "(", "$", "db", "[", "'Host'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Missing \"Host\" parameter for \"%s\" database'", ",", "$", "db", "[", "'Database'", "]", ")", ")", ";", "}", "$", "host", "=", "explode", "(", "':'", ",", "$", "db", "[", "'Host'", "]", ")", ";", "$", "cmd", ".=", "' --host '", ".", "$", "host", "[", "0", "]", ";", "if", "(", "isset", "(", "$", "host", "[", "1", "]", ")", ")", "{", "$", "cmd", ".=", "' --port '", ".", "$", "host", "[", "1", "]", ";", "}", "if", "(", "isset", "(", "$", "db", "[", "'Username'", "]", ")", "&&", "!", "empty", "(", "$", "db", "[", "'Username'", "]", ")", ")", "{", "$", "cmd", ".=", "' --username '", ".", "$", "db", "[", "'Username'", "]", ";", "}", "if", "(", "isset", "(", "$", "db", "[", "'Password'", "]", ")", "&&", "!", "empty", "(", "$", "db", "[", "'Password'", "]", ")", ")", "{", "$", "cmd", ".=", "' --password '", ".", "$", "db", "[", "'Password'", "]", ";", "if", "(", "!", "isset", "(", "$", "db", "[", "'AuthenticationDatabase'", "]", ")", ")", "{", "$", "cmd", ".=", "' --authenticationDatabase admin'", ";", "}", "else", "{", "$", "cmd", ".=", "' --authenticationDatabase '", ".", "$", "db", "[", "'AuthenticationDatabase'", "]", ";", "}", "}", "// create a folder for this database export", "$", "folderName", "=", "$", "this", "->", "tempFolder", ".", "$", "db", "[", "'Database'", "]", ".", "'-'", ".", "date", "(", "'Y-m-d'", ")", ";", "$", "cmd", ".=", "' --out '", ".", "$", "folderName", ";", "// mask password from log command", "if", "(", "isset", "(", "$", "db", "[", "'Password'", "]", ")", ")", "{", "$", "logCommand", "=", "str_replace", "(", "' --password '", ".", "$", "db", "[", "'Password'", "]", ",", "' --password xxxxxx'", ",", "$", "cmd", ")", ";", "}", "else", "{", "$", "logCommand", "=", "$", "cmd", ";", "}", "Service", "::", "$", "log", "->", "msg", "(", "sprintf", "(", "'Mongodb: export command '", ".", "$", "logCommand", ")", ")", ";", "$", "return", "=", "system", "(", "$", "cmd", ")", ";", "Service", "::", "$", "log", "->", "msg", "(", "sprintf", "(", "'Mongodb: '", ".", "$", "return", ")", ")", ";", "Service", "::", "$", "log", "->", "msg", "(", "sprintf", "(", "'Mongodb: database export done'", ")", ")", ";", "Cleanup", "::", "addToQueue", "(", "$", "folderName", ",", "Cleanup", "::", "TYPE_DIR", ")", ";", "return", "$", "folderName", ";", "}" ]
Private method that does the actual database export. @param array $db Database entry configuration. @return string Path to the created database export. @throws \Exception
[ "Private", "method", "that", "does", "the", "actual", "database", "export", "." ]
9728ddaa67e5703ac7898a6f69a0ad14ac37a256
https://github.com/Webiny/BackupService/blob/9728ddaa67e5703ac7898a6f69a0ad14ac37a256/src/Webiny/BackupService/Lib/BackupMongo.php#L72-L132
12,227
in2pire/in2pire-cli-compiler
src/In2pire/Compiler/Component/Git.php
Git.getLastCommitDate
public function getLastCommitDate() { $process = new Process('git log -n1 --pretty=%ci HEAD', $this->directory); if ($process->run() != 0) { throw new \RuntimeException('Can\'t run git log. You must ensure that git binary is available.'); } $date = new \DateTime(trim($process->getOutput())); $date->setTimezone(new \DateTimeZone('UTC')); return $date->format('Y-m-d H:i:s'); }
php
public function getLastCommitDate() { $process = new Process('git log -n1 --pretty=%ci HEAD', $this->directory); if ($process->run() != 0) { throw new \RuntimeException('Can\'t run git log. You must ensure that git binary is available.'); } $date = new \DateTime(trim($process->getOutput())); $date->setTimezone(new \DateTimeZone('UTC')); return $date->format('Y-m-d H:i:s'); }
[ "public", "function", "getLastCommitDate", "(", ")", "{", "$", "process", "=", "new", "Process", "(", "'git log -n1 --pretty=%ci HEAD'", ",", "$", "this", "->", "directory", ")", ";", "if", "(", "$", "process", "->", "run", "(", ")", "!=", "0", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Can\\'t run git log. You must ensure that git binary is available.'", ")", ";", "}", "$", "date", "=", "new", "\\", "DateTime", "(", "trim", "(", "$", "process", "->", "getOutput", "(", ")", ")", ")", ";", "$", "date", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "return", "$", "date", "->", "format", "(", "'Y-m-d H:i:s'", ")", ";", "}" ]
Get last commit date in repository. @return string Date.
[ "Get", "last", "commit", "date", "in", "repository", "." ]
3210393759c024d70ce15032d7f20a320afc9abe
https://github.com/in2pire/in2pire-cli-compiler/blob/3210393759c024d70ce15032d7f20a320afc9abe/src/In2pire/Compiler/Component/Git.php#L100-L112
12,228
in2pire/in2pire-cli-compiler
src/In2pire/Compiler/Component/Git.php
Git.findGitRepository
public static function findGitRepository($directory) { $process = new Process('git rev-parse --show-toplevel', $directory); $process->run(); if (!$process->isSuccessful()) { return false; } $rootPath = trim($process->getOutput()); return new Git($rootPath); }
php
public static function findGitRepository($directory) { $process = new Process('git rev-parse --show-toplevel', $directory); $process->run(); if (!$process->isSuccessful()) { return false; } $rootPath = trim($process->getOutput()); return new Git($rootPath); }
[ "public", "static", "function", "findGitRepository", "(", "$", "directory", ")", "{", "$", "process", "=", "new", "Process", "(", "'git rev-parse --show-toplevel'", ",", "$", "directory", ")", ";", "$", "process", "->", "run", "(", ")", ";", "if", "(", "!", "$", "process", "->", "isSuccessful", "(", ")", ")", "{", "return", "false", ";", "}", "$", "rootPath", "=", "trim", "(", "$", "process", "->", "getOutput", "(", ")", ")", ";", "return", "new", "Git", "(", "$", "rootPath", ")", ";", "}" ]
Find a git repository. @return mixed Git object or false.
[ "Find", "a", "git", "repository", "." ]
3210393759c024d70ce15032d7f20a320afc9abe
https://github.com/in2pire/in2pire-cli-compiler/blob/3210393759c024d70ce15032d7f20a320afc9abe/src/In2pire/Compiler/Component/Git.php#L120-L131
12,229
lrc-se/bth-anax-repository
src/Repository/SoftReferenceResolverTrait.php
SoftReferenceResolverTrait.getReferenceSoft
public function getReferenceSoft($repository, $attr, $key = 'id') { if (isset($this->$attr)) { return ($repository->findSoft($key, $this->$attr) ?: null); } return null; }
php
public function getReferenceSoft($repository, $attr, $key = 'id') { if (isset($this->$attr)) { return ($repository->findSoft($key, $this->$attr) ?: null); } return null; }
[ "public", "function", "getReferenceSoft", "(", "$", "repository", ",", "$", "attr", ",", "$", "key", "=", "'id'", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "$", "attr", ")", ")", "{", "return", "(", "$", "repository", "->", "findSoft", "(", "$", "key", ",", "$", "this", "->", "$", "attr", ")", "?", ":", "null", ")", ";", "}", "return", "null", ";", "}" ]
Retrieve a reference by foreign key, ignoring soft-deleted entries. @param SoftRepositoryInterface $repository Repository to query. @param string $attr Name of foreign key attribute. @param string $key Name of primary key attribute in referenced table. @return mixed Model instance if found, null otherwise.
[ "Retrieve", "a", "reference", "by", "foreign", "key", "ignoring", "soft", "-", "deleted", "entries", "." ]
344a0795fbfadf34ea768719dc5cf2f1d90154df
https://github.com/lrc-se/bth-anax-repository/blob/344a0795fbfadf34ea768719dc5cf2f1d90154df/src/Repository/SoftReferenceResolverTrait.php#L22-L28
12,230
factorio-item-browser/api-database
src/Entity/RecipeProduct.php
RecipeProduct.setAmountMin
public function setAmountMin(float $amountMin): self { $this->amountMin = (int) ($amountMin * self::FACTOR_AMOUNT_MIN); return $this; }
php
public function setAmountMin(float $amountMin): self { $this->amountMin = (int) ($amountMin * self::FACTOR_AMOUNT_MIN); return $this; }
[ "public", "function", "setAmountMin", "(", "float", "$", "amountMin", ")", ":", "self", "{", "$", "this", "->", "amountMin", "=", "(", "int", ")", "(", "$", "amountMin", "*", "self", "::", "FACTOR_AMOUNT_MIN", ")", ";", "return", "$", "this", ";", "}" ]
Sets the minimal amount of the product in the recipe. @param float $amountMin @return $this Implementing fluent interface.
[ "Sets", "the", "minimal", "amount", "of", "the", "product", "in", "the", "recipe", "." ]
c3a27e5673462a58b5afafc0ea0e0002f6db9803
https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Entity/RecipeProduct.php#L122-L126
12,231
factorio-item-browser/api-database
src/Entity/RecipeProduct.php
RecipeProduct.setAmountMax
public function setAmountMax(float $amountMax): self { $this->amountMax = (int) ($amountMax * self::FACTOR_AMOUNT_MAX); return $this; }
php
public function setAmountMax(float $amountMax): self { $this->amountMax = (int) ($amountMax * self::FACTOR_AMOUNT_MAX); return $this; }
[ "public", "function", "setAmountMax", "(", "float", "$", "amountMax", ")", ":", "self", "{", "$", "this", "->", "amountMax", "=", "(", "int", ")", "(", "$", "amountMax", "*", "self", "::", "FACTOR_AMOUNT_MAX", ")", ";", "return", "$", "this", ";", "}" ]
Sets the maximal amount of the product in the recipe. @param float $amountMax @return $this Implementing fluent interface.
[ "Sets", "the", "maximal", "amount", "of", "the", "product", "in", "the", "recipe", "." ]
c3a27e5673462a58b5afafc0ea0e0002f6db9803
https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Entity/RecipeProduct.php#L142-L146
12,232
factorio-item-browser/api-database
src/Entity/RecipeProduct.php
RecipeProduct.setProbability
public function setProbability(float $probability): self { $this->probability = (int) ($probability * self::FACTOR_AMOUNT_PROBABILITY); return $this; }
php
public function setProbability(float $probability): self { $this->probability = (int) ($probability * self::FACTOR_AMOUNT_PROBABILITY); return $this; }
[ "public", "function", "setProbability", "(", "float", "$", "probability", ")", ":", "self", "{", "$", "this", "->", "probability", "=", "(", "int", ")", "(", "$", "probability", "*", "self", "::", "FACTOR_AMOUNT_PROBABILITY", ")", ";", "return", "$", "this", ";", "}" ]
Sets the probability of the product in the recipe. @param float $probability @return $this Implementing fluent interface.
[ "Sets", "the", "probability", "of", "the", "product", "in", "the", "recipe", "." ]
c3a27e5673462a58b5afafc0ea0e0002f6db9803
https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Entity/RecipeProduct.php#L162-L166
12,233
mszewcz/php-light-framework
src/Session/Revalidation.php
Revalidation.setRevalidationTime
public static function setRevalidationTime(string $variableName = '_MF_SESSION_REVALIDATED_AT_'): bool { $variableName = (string)$variableName; $vHandler = Variables::getInstance(); $vHandler->session->set($variableName, \time()); return true; }
php
public static function setRevalidationTime(string $variableName = '_MF_SESSION_REVALIDATED_AT_'): bool { $variableName = (string)$variableName; $vHandler = Variables::getInstance(); $vHandler->session->set($variableName, \time()); return true; }
[ "public", "static", "function", "setRevalidationTime", "(", "string", "$", "variableName", "=", "'_MF_SESSION_REVALIDATED_AT_'", ")", ":", "bool", "{", "$", "variableName", "=", "(", "string", ")", "$", "variableName", ";", "$", "vHandler", "=", "Variables", "::", "getInstance", "(", ")", ";", "$", "vHandler", "->", "session", "->", "set", "(", "$", "variableName", ",", "\\", "time", "(", ")", ")", ";", "return", "true", ";", "}" ]
Sets revalidation timestamp @param string $variableName @return bool
[ "Sets", "revalidation", "timestamp" ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Session/Revalidation.php#L45-L51
12,234
mszewcz/php-light-framework
src/Session/Revalidation.php
Revalidation.doesNeedRevalidation
public static function doesNeedRevalidation(string $variableName = '_MF_SESSION_REVALIDATED_AT_'): bool { static::init(); $variableName = (string)$variableName; $vHandler = Variables::getInstance(); $validationTS = $vHandler->session->get($variableName, $vHandler::TYPE_INT); return $validationTS < \time() - static::$revalidationTime ? true : false; }
php
public static function doesNeedRevalidation(string $variableName = '_MF_SESSION_REVALIDATED_AT_'): bool { static::init(); $variableName = (string)$variableName; $vHandler = Variables::getInstance(); $validationTS = $vHandler->session->get($variableName, $vHandler::TYPE_INT); return $validationTS < \time() - static::$revalidationTime ? true : false; }
[ "public", "static", "function", "doesNeedRevalidation", "(", "string", "$", "variableName", "=", "'_MF_SESSION_REVALIDATED_AT_'", ")", ":", "bool", "{", "static", "::", "init", "(", ")", ";", "$", "variableName", "=", "(", "string", ")", "$", "variableName", ";", "$", "vHandler", "=", "Variables", "::", "getInstance", "(", ")", ";", "$", "validationTS", "=", "$", "vHandler", "->", "session", "->", "get", "(", "$", "variableName", ",", "$", "vHandler", "::", "TYPE_INT", ")", ";", "return", "$", "validationTS", "<", "\\", "time", "(", ")", "-", "static", "::", "$", "revalidationTime", "?", "true", ":", "false", ";", "}" ]
Checks if session deas need revalidation @param string $variableName @return bool
[ "Checks", "if", "session", "deas", "need", "revalidation" ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Session/Revalidation.php#L59-L66
12,235
mszewcz/php-light-framework
src/Session/Revalidation.php
Revalidation.setRevalidationCounter
public static function setRevalidationCounter(string $variableName = '_MF_SESSION_REVALIDATION_COUNTER_', int $value = 0): void { static::init(); $variableName = (string)$variableName; $vHandler = Variables::getInstance(); $vHandler->session->set($variableName, $value); }
php
public static function setRevalidationCounter(string $variableName = '_MF_SESSION_REVALIDATION_COUNTER_', int $value = 0): void { static::init(); $variableName = (string)$variableName; $vHandler = Variables::getInstance(); $vHandler->session->set($variableName, $value); }
[ "public", "static", "function", "setRevalidationCounter", "(", "string", "$", "variableName", "=", "'_MF_SESSION_REVALIDATION_COUNTER_'", ",", "int", "$", "value", "=", "0", ")", ":", "void", "{", "static", "::", "init", "(", ")", ";", "$", "variableName", "=", "(", "string", ")", "$", "variableName", ";", "$", "vHandler", "=", "Variables", "::", "getInstance", "(", ")", ";", "$", "vHandler", "->", "session", "->", "set", "(", "$", "variableName", ",", "$", "value", ")", ";", "}" ]
Sets revalidation counter value @param string $variableName @param int $value
[ "Sets", "revalidation", "counter", "value" ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Session/Revalidation.php#L74-L81
12,236
mszewcz/php-light-framework
src/Session/Revalidation.php
Revalidation.increaseRevalidationCounter
public static function increaseRevalidationCounter(string $variableName = '_MF_SESSION_REVALIDATION_COUNTER_'): void { static::init(); $variableName = (string)$variableName; $vHandler = Variables::getInstance(); $vHandler->session->set($variableName, $vHandler->session->get($variableName, Variables::TYPE_INT) + 1); }
php
public static function increaseRevalidationCounter(string $variableName = '_MF_SESSION_REVALIDATION_COUNTER_'): void { static::init(); $variableName = (string)$variableName; $vHandler = Variables::getInstance(); $vHandler->session->set($variableName, $vHandler->session->get($variableName, Variables::TYPE_INT) + 1); }
[ "public", "static", "function", "increaseRevalidationCounter", "(", "string", "$", "variableName", "=", "'_MF_SESSION_REVALIDATION_COUNTER_'", ")", ":", "void", "{", "static", "::", "init", "(", ")", ";", "$", "variableName", "=", "(", "string", ")", "$", "variableName", ";", "$", "vHandler", "=", "Variables", "::", "getInstance", "(", ")", ";", "$", "vHandler", "->", "session", "->", "set", "(", "$", "variableName", ",", "$", "vHandler", "->", "session", "->", "get", "(", "$", "variableName", ",", "Variables", "::", "TYPE_INT", ")", "+", "1", ")", ";", "}" ]
Increases revalidation counter @param string $variableName
[ "Increases", "revalidation", "counter" ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Session/Revalidation.php#L88-L94
12,237
mszewcz/php-light-framework
src/Session/Revalidation.php
Revalidation.resetRevalidationCounter
public static function resetRevalidationCounter(string $variableName = '_MF_SESSION_REVALIDATION_COUNTER_'): void { static::init(); $variableName = (string)$variableName; $vHandler = Variables::getInstance(); if ($vHandler->session->get($variableName, Variables::TYPE_INT) > 0) { $vHandler->session->set($variableName, 0); \session_regenerate_id(true); } }
php
public static function resetRevalidationCounter(string $variableName = '_MF_SESSION_REVALIDATION_COUNTER_'): void { static::init(); $variableName = (string)$variableName; $vHandler = Variables::getInstance(); if ($vHandler->session->get($variableName, Variables::TYPE_INT) > 0) { $vHandler->session->set($variableName, 0); \session_regenerate_id(true); } }
[ "public", "static", "function", "resetRevalidationCounter", "(", "string", "$", "variableName", "=", "'_MF_SESSION_REVALIDATION_COUNTER_'", ")", ":", "void", "{", "static", "::", "init", "(", ")", ";", "$", "variableName", "=", "(", "string", ")", "$", "variableName", ";", "$", "vHandler", "=", "Variables", "::", "getInstance", "(", ")", ";", "if", "(", "$", "vHandler", "->", "session", "->", "get", "(", "$", "variableName", ",", "Variables", "::", "TYPE_INT", ")", ">", "0", ")", "{", "$", "vHandler", "->", "session", "->", "set", "(", "$", "variableName", ",", "0", ")", ";", "\\", "session_regenerate_id", "(", "true", ")", ";", "}", "}" ]
Resets revalidation counter & regenerates session id @param string $variableName
[ "Resets", "revalidation", "counter", "&", "regenerates", "session", "id" ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Session/Revalidation.php#L101-L110
12,238
DBRisinajumi/d2person
models/PprsPerson.php
PprsPerson.getPersonsByRole
public static function getPersonsByRole($role = false){ $ccuc_status = CcucUserCompany::CCUC_STATUS_SYS; $sys_ccmp_id = Yii::app()->sysCompany->getActiveCompany(); $sql = " SELECT DISTINCT pprs_id, CONCAT( pprs_second_name, ' ', pprs_first_name ) full_name FROM AuthAssignment aa INNER JOIN `profiles` p ON aa.userid = p.user_id INNER JOIN pprs_person ON p.person_id = pprs_id INNER JOIN ccuc_user_company ON pprs_id = ccuc_person_id AND ccuc_ccmp_id = {$sys_ccmp_id} AND ccuc_status = '{$ccuc_status}' " ; $where = ''; if($role && !is_array($role)){ $where = " WHERE itemname = '{$role}' "; } if($role && is_array($role)){ $where = " WHERE itemname in ('".implode("','",$role)."') "; } $sql .= $where . " ORDER BY pprs_second_name,pprs_first_name "; return Yii::app()->db->createCommand($sql)->queryAll(); }
php
public static function getPersonsByRole($role = false){ $ccuc_status = CcucUserCompany::CCUC_STATUS_SYS; $sys_ccmp_id = Yii::app()->sysCompany->getActiveCompany(); $sql = " SELECT DISTINCT pprs_id, CONCAT( pprs_second_name, ' ', pprs_first_name ) full_name FROM AuthAssignment aa INNER JOIN `profiles` p ON aa.userid = p.user_id INNER JOIN pprs_person ON p.person_id = pprs_id INNER JOIN ccuc_user_company ON pprs_id = ccuc_person_id AND ccuc_ccmp_id = {$sys_ccmp_id} AND ccuc_status = '{$ccuc_status}' " ; $where = ''; if($role && !is_array($role)){ $where = " WHERE itemname = '{$role}' "; } if($role && is_array($role)){ $where = " WHERE itemname in ('".implode("','",$role)."') "; } $sql .= $where . " ORDER BY pprs_second_name,pprs_first_name "; return Yii::app()->db->createCommand($sql)->queryAll(); }
[ "public", "static", "function", "getPersonsByRole", "(", "$", "role", "=", "false", ")", "{", "$", "ccuc_status", "=", "CcucUserCompany", "::", "CCUC_STATUS_SYS", ";", "$", "sys_ccmp_id", "=", "Yii", "::", "app", "(", ")", "->", "sysCompany", "->", "getActiveCompany", "(", ")", ";", "$", "sql", "=", "\" \n SELECT DISTINCT\n \n pprs_id,\n CONCAT(\n pprs_second_name,\n ' ',\n pprs_first_name\n ) full_name \n FROM\n AuthAssignment aa \n INNER JOIN `profiles` p \n ON aa.userid = p.user_id \n INNER JOIN pprs_person \n ON p.person_id = pprs_id \n INNER JOIN ccuc_user_company \n ON pprs_id = ccuc_person_id \n AND ccuc_ccmp_id = {$sys_ccmp_id} \n AND ccuc_status = '{$ccuc_status}' \n\n \"", ";", "$", "where", "=", "''", ";", "if", "(", "$", "role", "&&", "!", "is_array", "(", "$", "role", ")", ")", "{", "$", "where", "=", "\" WHERE itemname = '{$role}' \"", ";", "}", "if", "(", "$", "role", "&&", "is_array", "(", "$", "role", ")", ")", "{", "$", "where", "=", "\" WHERE itemname in ('\"", ".", "implode", "(", "\"','\"", ",", "$", "role", ")", ".", "\"') \"", ";", "}", "$", "sql", ".=", "$", "where", ".", "\" ORDER BY pprs_second_name,pprs_first_name \"", ";", "return", "Yii", "::", "app", "(", ")", "->", "db", "->", "createCommand", "(", "$", "sql", ")", "->", "queryAll", "(", ")", ";", "}" ]
get users list by role, roles or all @param string/array/boolean $role @return array( array(pprs_id=>'1','full_name' => 'Andris Berzins', array(pprs_id=>'2','full_name' => 'Karlis Berzins', )
[ "get", "users", "list", "by", "role", "roles", "or", "all" ]
de3967d0ef0646b7f95774743cf2a2ec8128681a
https://github.com/DBRisinajumi/d2person/blob/de3967d0ef0646b7f95774743cf2a2ec8128681a/models/PprsPerson.php#L195-L234
12,239
DBRisinajumi/d2person
models/PprsPerson.php
PprsPerson.translitStringToAscii
public static function translitStringToAscii($str) { $LATV=array("ā","Ā","č","Č","ē","Ē","ģ","Ģ","ī","Ī","ķ","Ķ","ļ","Ļ","ņ","Ņ","š","Š","ū","Ū","ž","Ž",".",'"'," ","-","_","/"); //Latviešu garie un mīkste burti un neatļautie simboli $LATIN=array("a","A","c","C","e","E","g","G","i","I","k","K","l","L","n","N","s","S","u","U","z","Z","",""," ",""," "," "); //Latviešu mīksto un garo burtu un neatļauto simbolu aizstāēji return str_replace($LATV,$LATIN,$str); //Latviešu garos un mīkstos burtus aizstāj ar latīņu burtiem //$str = str_replace(array('й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф','ы','в','а','п','р','о','л','д','ж','э','я','ч','с','м','и','т','ь','б','ю','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф','Ы','В','А','П','Р','О','Л','Д','Ж','Э','Я','Ч','С','М','И','Т','Ь','Б','Ю','Ā','Č','Ē','Ģ','Ī','Ķ','Ļ','Ņ','Š','Ū','Ž', 'ā','č','ē','ģ','ī','ķ','ļ','ņ','š','ū','ž'),array('A','C','E','G','I','K','L','N','S','U','Z','a','c','e','g','i','k','l','n','s','u','z','i','c','u','k','e','n','g','sh','sh','z','h','i','f','i','v','a','p','r','o','l','d','zh','e','ja','ch','s','m','i','t','','b','ju','I','C','U','K','E','N','G','SH','SH','Z','H','I','F','I','V','A','P','R','O','L','D','ZH','E','JA','CH','S','M','I','T','','B','JU','A','C','E','G','I','K','L','N','S','U','Z','a','c','e','g','i','k','l','n','s','u','z'),$str); return $str; }
php
public static function translitStringToAscii($str) { $LATV=array("ā","Ā","č","Č","ē","Ē","ģ","Ģ","ī","Ī","ķ","Ķ","ļ","Ļ","ņ","Ņ","š","Š","ū","Ū","ž","Ž",".",'"'," ","-","_","/"); //Latviešu garie un mīkste burti un neatļautie simboli $LATIN=array("a","A","c","C","e","E","g","G","i","I","k","K","l","L","n","N","s","S","u","U","z","Z","",""," ",""," "," "); //Latviešu mīksto un garo burtu un neatļauto simbolu aizstāēji return str_replace($LATV,$LATIN,$str); //Latviešu garos un mīkstos burtus aizstāj ar latīņu burtiem //$str = str_replace(array('й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф','ы','в','а','п','р','о','л','д','ж','э','я','ч','с','м','и','т','ь','б','ю','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф','Ы','В','А','П','Р','О','Л','Д','Ж','Э','Я','Ч','С','М','И','Т','Ь','Б','Ю','Ā','Č','Ē','Ģ','Ī','Ķ','Ļ','Ņ','Š','Ū','Ž', 'ā','č','ē','ģ','ī','ķ','ļ','ņ','š','ū','ž'),array('A','C','E','G','I','K','L','N','S','U','Z','a','c','e','g','i','k','l','n','s','u','z','i','c','u','k','e','n','g','sh','sh','z','h','i','f','i','v','a','p','r','o','l','d','zh','e','ja','ch','s','m','i','t','','b','ju','I','C','U','K','E','N','G','SH','SH','Z','H','I','F','I','V','A','P','R','O','L','D','ZH','E','JA','CH','S','M','I','T','','B','JU','A','C','E','G','I','K','L','N','S','U','Z','a','c','e','g','i','k','l','n','s','u','z'),$str); return $str; }
[ "public", "static", "function", "translitStringToAscii", "(", "$", "str", ")", "{", "$", "LATV", "=", "array", "(", "\"ā\",", "\"", "Ā\",\"", "č", "\",\"Č", "\"", ",\"ē\"", ",", "\"Ē\",", "\"", "ģ\",\"", "Ģ", "\",\"ī", "\"", ",\"Ī\"", ",", "\"ķ\",", "\"", "Ķ\",\"", "ļ", "\",\"Ļ", "\"", ",\"ņ\"", ",", "\"Ņ\",", "\"", "š\",\"", "Š", "\",\"ū", "\"", ",\"Ū\"", ",", "\"ž\",", "\"", "Ž\",\"", ".", "\",'\"", "'", ",\" ", " ", "\",\"-", "\"", ",\"_\"", ",", "\"/\"", ")", "; /", "/", "Latvi", "e", "šu ", "g", "ari", "e", " un", " ", "m", "kste burti un neatļautie simboli", "$", "LATIN", "=", "array", "(", "\"a\"", ",", "\"A\"", ",", "\"c\"", ",", "\"C\"", ",", "\"e\"", ",", "\"E\"", ",", "\"g\"", ",", "\"G\"", ",", "\"i\"", ",", "\"I\"", ",", "\"k\"", ",", "\"K\"", ",", "\"l\"", ",", "\"L\"", ",", "\"n\"", ",", "\"N\"", ",", "\"s\"", ",", "\"S\"", ",", "\"u\"", ",", "\"U\"", ",", "\"z\"", ",", "\"Z\"", ",", "\"\"", ",", "\"\"", ",", "\" \"", ",", "\"\"", ",", "\" \"", ",", "\" \"", ")", ";", "//Latviešu mīksto un garo burtu un neatļauto simbolu aizstāēji", "return", "str_replace", "(", "$", "LATV", ",", "$", "LATIN", ",", "$", "str", ")", ";", "//Latviešu garos un mīkstos burtus aizstāj ar latīņu burtiem", "//$str = str_replace(array('й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф','ы','в','а','п','р','о','л','д','ж','э','я','ч','с','м','и','т','ь','б','ю','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф','Ы','В','А','П','Р','О','Л','Д','Ж','Э','Я','Ч','С','М','И','Т','Ь','Б','Ю','Ā','Č','Ē','Ģ','Ī','Ķ','Ļ','Ņ','Š','Ū','Ž', 'ā','č','ē','ģ','ī','ķ','ļ','ņ','š','ū','ž'),array('A','C','E','G','I','K','L','N','S','U','Z','a','c','e','g','i','k','l','n','s','u','z','i','c','u','k','e','n','g','sh','sh','z','h','i','f','i','v','a','p','r','o','l','d','zh','e','ja','ch','s','m','i','t','','b','ju','I','C','U','K','E','N','G','SH','SH','Z','H','I','F','I','V','A','P','R','O','L','D','ZH','E','JA','CH','S','M','I','T','','B','JU','A','C','E','G','I','K','L','N','S','U','Z','a','c','e','g','i','k','l','n','s','u','z'),$str);", "return", "$", "str", ";", "}" ]
replace latvian special characters to latin characters @param string $str @return string
[ "replace", "latvian", "special", "characters", "to", "latin", "characters" ]
de3967d0ef0646b7f95774743cf2a2ec8128681a
https://github.com/DBRisinajumi/d2person/blob/de3967d0ef0646b7f95774743cf2a2ec8128681a/models/PprsPerson.php#L308-L314
12,240
DBRisinajumi/d2person
models/PprsPerson.php
PprsPerson.createUser
public function createUser(){ $password = DbrLib::rand_string(8); /** * create username */ $firstName = strtolower(self::translitStringToAscii($this->pprs_first_name)); $secondName = strtolower(self::translitStringToAscii($this->pprs_second_name)); $username = $firstName . substr($secondName, 0, 1); $i = 1; while(User::model()->findByAttributes(['username'=>$username])){ $i ++; if($i> strlen($secondName)){ $username = $firstName . DbrLib::rand_string(2); } $username = $firstName . substr($secondName, 0, $i); } /** * get email from person contacts */ $contacts = $this->ppcnPersonContacts; $email = ''; foreach($contacts as $contact){ if($contact->ppcn_pcnt_type == PcntContactType::TYPE_EMAIL ){ $email = trim($contact->ppcn_value); } } /** * create user record */ $user = new User(); $user->username = $username; $user->password = $password; $user->email = $email; $user->status = User::STATUS_ACTIVE; if(!$user->validate()){ return CHtml::errorSummary($user); } $user->save(); /** * create profile record */ $profile=new Profile; $profile->user_id=$user->id; $profile->first_name = $this->pprs_first_name; $profile->last_name = $this->pprs_second_name; $profile->sys_ccmp_id = Yii::app()->sysCompany->getActiveCompany(); $profile->person_id=$this->primaryKey; $profile->save(); return true; }
php
public function createUser(){ $password = DbrLib::rand_string(8); /** * create username */ $firstName = strtolower(self::translitStringToAscii($this->pprs_first_name)); $secondName = strtolower(self::translitStringToAscii($this->pprs_second_name)); $username = $firstName . substr($secondName, 0, 1); $i = 1; while(User::model()->findByAttributes(['username'=>$username])){ $i ++; if($i> strlen($secondName)){ $username = $firstName . DbrLib::rand_string(2); } $username = $firstName . substr($secondName, 0, $i); } /** * get email from person contacts */ $contacts = $this->ppcnPersonContacts; $email = ''; foreach($contacts as $contact){ if($contact->ppcn_pcnt_type == PcntContactType::TYPE_EMAIL ){ $email = trim($contact->ppcn_value); } } /** * create user record */ $user = new User(); $user->username = $username; $user->password = $password; $user->email = $email; $user->status = User::STATUS_ACTIVE; if(!$user->validate()){ return CHtml::errorSummary($user); } $user->save(); /** * create profile record */ $profile=new Profile; $profile->user_id=$user->id; $profile->first_name = $this->pprs_first_name; $profile->last_name = $this->pprs_second_name; $profile->sys_ccmp_id = Yii::app()->sysCompany->getActiveCompany(); $profile->person_id=$this->primaryKey; $profile->save(); return true; }
[ "public", "function", "createUser", "(", ")", "{", "$", "password", "=", "DbrLib", "::", "rand_string", "(", "8", ")", ";", "/**\n * create username \n */", "$", "firstName", "=", "strtolower", "(", "self", "::", "translitStringToAscii", "(", "$", "this", "->", "pprs_first_name", ")", ")", ";", "$", "secondName", "=", "strtolower", "(", "self", "::", "translitStringToAscii", "(", "$", "this", "->", "pprs_second_name", ")", ")", ";", "$", "username", "=", "$", "firstName", ".", "substr", "(", "$", "secondName", ",", "0", ",", "1", ")", ";", "$", "i", "=", "1", ";", "while", "(", "User", "::", "model", "(", ")", "->", "findByAttributes", "(", "[", "'username'", "=>", "$", "username", "]", ")", ")", "{", "$", "i", "++", ";", "if", "(", "$", "i", ">", "strlen", "(", "$", "secondName", ")", ")", "{", "$", "username", "=", "$", "firstName", ".", "DbrLib", "::", "rand_string", "(", "2", ")", ";", "}", "$", "username", "=", "$", "firstName", ".", "substr", "(", "$", "secondName", ",", "0", ",", "$", "i", ")", ";", "}", "/**\n * get email from person contacts\n */", "$", "contacts", "=", "$", "this", "->", "ppcnPersonContacts", ";", "$", "email", "=", "''", ";", "foreach", "(", "$", "contacts", "as", "$", "contact", ")", "{", "if", "(", "$", "contact", "->", "ppcn_pcnt_type", "==", "PcntContactType", "::", "TYPE_EMAIL", ")", "{", "$", "email", "=", "trim", "(", "$", "contact", "->", "ppcn_value", ")", ";", "}", "}", "/**\n * create user record\n */", "$", "user", "=", "new", "User", "(", ")", ";", "$", "user", "->", "username", "=", "$", "username", ";", "$", "user", "->", "password", "=", "$", "password", ";", "$", "user", "->", "email", "=", "$", "email", ";", "$", "user", "->", "status", "=", "User", "::", "STATUS_ACTIVE", ";", "if", "(", "!", "$", "user", "->", "validate", "(", ")", ")", "{", "return", "CHtml", "::", "errorSummary", "(", "$", "user", ")", ";", "}", "$", "user", "->", "save", "(", ")", ";", "/**\n * create profile record\n */", "$", "profile", "=", "new", "Profile", ";", "$", "profile", "->", "user_id", "=", "$", "user", "->", "id", ";", "$", "profile", "->", "first_name", "=", "$", "this", "->", "pprs_first_name", ";", "$", "profile", "->", "last_name", "=", "$", "this", "->", "pprs_second_name", ";", "$", "profile", "->", "sys_ccmp_id", "=", "Yii", "::", "app", "(", ")", "->", "sysCompany", "->", "getActiveCompany", "(", ")", ";", "$", "profile", "->", "person_id", "=", "$", "this", "->", "primaryKey", ";", "$", "profile", "->", "save", "(", ")", ";", "return", "true", ";", "}" ]
create user account from person data @return boolean|array - error
[ "create", "user", "account", "from", "person", "data" ]
de3967d0ef0646b7f95774743cf2a2ec8128681a
https://github.com/DBRisinajumi/d2person/blob/de3967d0ef0646b7f95774743cf2a2ec8128681a/models/PprsPerson.php#L320-L379
12,241
eghojansu/nutrition
src/Security/Authorization.php
Authorization.guard
public function guard($loginRoute = null) { $base = Base::instance(); $currentPath = $base['PATH']; $this->parseFirewalls(); if ( $this->firewalls['pattern'] && preg_match($this->firewalls['pattern'], $currentPath, $matches) ) { $key = static::pathName($matches['path']); $config = $this->firewalls['paths'][$key]; if (!$this->isGranted($config['roles'])) { $base->reroute($loginRoute ?: $config['login_route']); } } return $this; }
php
public function guard($loginRoute = null) { $base = Base::instance(); $currentPath = $base['PATH']; $this->parseFirewalls(); if ( $this->firewalls['pattern'] && preg_match($this->firewalls['pattern'], $currentPath, $matches) ) { $key = static::pathName($matches['path']); $config = $this->firewalls['paths'][$key]; if (!$this->isGranted($config['roles'])) { $base->reroute($loginRoute ?: $config['login_route']); } } return $this; }
[ "public", "function", "guard", "(", "$", "loginRoute", "=", "null", ")", "{", "$", "base", "=", "Base", "::", "instance", "(", ")", ";", "$", "currentPath", "=", "$", "base", "[", "'PATH'", "]", ";", "$", "this", "->", "parseFirewalls", "(", ")", ";", "if", "(", "$", "this", "->", "firewalls", "[", "'pattern'", "]", "&&", "preg_match", "(", "$", "this", "->", "firewalls", "[", "'pattern'", "]", ",", "$", "currentPath", ",", "$", "matches", ")", ")", "{", "$", "key", "=", "static", "::", "pathName", "(", "$", "matches", "[", "'path'", "]", ")", ";", "$", "config", "=", "$", "this", "->", "firewalls", "[", "'paths'", "]", "[", "$", "key", "]", ";", "if", "(", "!", "$", "this", "->", "isGranted", "(", "$", "config", "[", "'roles'", "]", ")", ")", "{", "$", "base", "->", "reroute", "(", "$", "loginRoute", "?", ":", "$", "config", "[", "'login_route'", "]", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Do guarding controller @param string|null $loginRoute @return $this
[ "Do", "guarding", "controller" ]
3941c62aeb6dafda55349a38dd4107d521f8964a
https://github.com/eghojansu/nutrition/blob/3941c62aeb6dafda55349a38dd4107d521f8964a/src/Security/Authorization.php#L23-L43
12,242
eghojansu/nutrition
src/Security/Authorization.php
Authorization.isGranted
public function isGranted($roles) { $this->parseRoles(); $roles = (array) $roles; $intersection = array_intersect($roles, $this->roles); return count($intersection) > 0; }
php
public function isGranted($roles) { $this->parseRoles(); $roles = (array) $roles; $intersection = array_intersect($roles, $this->roles); return count($intersection) > 0; }
[ "public", "function", "isGranted", "(", "$", "roles", ")", "{", "$", "this", "->", "parseRoles", "(", ")", ";", "$", "roles", "=", "(", "array", ")", "$", "roles", ";", "$", "intersection", "=", "array_intersect", "(", "$", "roles", ",", "$", "this", "->", "roles", ")", ";", "return", "count", "(", "$", "intersection", ")", ">", "0", ";", "}" ]
Check if user granted for roles @param string|array $roles @return boolean
[ "Check", "if", "user", "granted", "for", "roles" ]
3941c62aeb6dafda55349a38dd4107d521f8964a
https://github.com/eghojansu/nutrition/blob/3941c62aeb6dafda55349a38dd4107d521f8964a/src/Security/Authorization.php#L50-L58
12,243
eghojansu/nutrition
src/Security/Authorization.php
Authorization.parseFirewalls
protected function parseFirewalls($force = false) { if (null == $this->firewalls || $force) { $firewalls = ['pattern'=>null,'paths'=>[]]; $pattern = ''; foreach (Base::instance()->get('SECURITY.firewalls') ?: [] as $name => $config) { $pattern .= ($pattern?'|':'').$config['path']; $key = static::pathName($config['path']); $firewalls['paths'][$key] = [ 'login_route' => $config['login_route'], 'roles' => $config['roles'], ]; } if ($pattern) { $firewalls['pattern'] = '#(?<path>'.$pattern.')#'; } $this->firewalls = $firewalls; } }
php
protected function parseFirewalls($force = false) { if (null == $this->firewalls || $force) { $firewalls = ['pattern'=>null,'paths'=>[]]; $pattern = ''; foreach (Base::instance()->get('SECURITY.firewalls') ?: [] as $name => $config) { $pattern .= ($pattern?'|':'').$config['path']; $key = static::pathName($config['path']); $firewalls['paths'][$key] = [ 'login_route' => $config['login_route'], 'roles' => $config['roles'], ]; } if ($pattern) { $firewalls['pattern'] = '#(?<path>'.$pattern.')#'; } $this->firewalls = $firewalls; } }
[ "protected", "function", "parseFirewalls", "(", "$", "force", "=", "false", ")", "{", "if", "(", "null", "==", "$", "this", "->", "firewalls", "||", "$", "force", ")", "{", "$", "firewalls", "=", "[", "'pattern'", "=>", "null", ",", "'paths'", "=>", "[", "]", "]", ";", "$", "pattern", "=", "''", ";", "foreach", "(", "Base", "::", "instance", "(", ")", "->", "get", "(", "'SECURITY.firewalls'", ")", "?", ":", "[", "]", "as", "$", "name", "=>", "$", "config", ")", "{", "$", "pattern", ".=", "(", "$", "pattern", "?", "'|'", ":", "''", ")", ".", "$", "config", "[", "'path'", "]", ";", "$", "key", "=", "static", "::", "pathName", "(", "$", "config", "[", "'path'", "]", ")", ";", "$", "firewalls", "[", "'paths'", "]", "[", "$", "key", "]", "=", "[", "'login_route'", "=>", "$", "config", "[", "'login_route'", "]", ",", "'roles'", "=>", "$", "config", "[", "'roles'", "]", ",", "]", ";", "}", "if", "(", "$", "pattern", ")", "{", "$", "firewalls", "[", "'pattern'", "]", "=", "'#(?<path>'", ".", "$", "pattern", ".", "')#'", ";", "}", "$", "this", "->", "firewalls", "=", "$", "firewalls", ";", "}", "}" ]
Parse firewalls from configuration @param boolean $force force parsing @return void
[ "Parse", "firewalls", "from", "configuration" ]
3941c62aeb6dafda55349a38dd4107d521f8964a
https://github.com/eghojansu/nutrition/blob/3941c62aeb6dafda55349a38dd4107d521f8964a/src/Security/Authorization.php#L65-L86
12,244
eghojansu/nutrition
src/Security/Authorization.php
Authorization.parseRoles
protected function parseRoles($force = false) { if (null == $this->roles || $force) { $user = UserManager::instance()->getuser(); $userRoles = $user ? $user->getRoles() : ['ROLE_ANONYMOUS']; $roleHierarchy = Base::instance()->get('SECURITY.role_hierarchy') ?: []; $roles = []; foreach ($userRoles as $role) { $roles = array_merge( $roles, [$role], $this->getHierarchy($role, $roleHierarchy) ); } $this->roles = array_unique($roles); } }
php
protected function parseRoles($force = false) { if (null == $this->roles || $force) { $user = UserManager::instance()->getuser(); $userRoles = $user ? $user->getRoles() : ['ROLE_ANONYMOUS']; $roleHierarchy = Base::instance()->get('SECURITY.role_hierarchy') ?: []; $roles = []; foreach ($userRoles as $role) { $roles = array_merge( $roles, [$role], $this->getHierarchy($role, $roleHierarchy) ); } $this->roles = array_unique($roles); } }
[ "protected", "function", "parseRoles", "(", "$", "force", "=", "false", ")", "{", "if", "(", "null", "==", "$", "this", "->", "roles", "||", "$", "force", ")", "{", "$", "user", "=", "UserManager", "::", "instance", "(", ")", "->", "getuser", "(", ")", ";", "$", "userRoles", "=", "$", "user", "?", "$", "user", "->", "getRoles", "(", ")", ":", "[", "'ROLE_ANONYMOUS'", "]", ";", "$", "roleHierarchy", "=", "Base", "::", "instance", "(", ")", "->", "get", "(", "'SECURITY.role_hierarchy'", ")", "?", ":", "[", "]", ";", "$", "roles", "=", "[", "]", ";", "foreach", "(", "$", "userRoles", "as", "$", "role", ")", "{", "$", "roles", "=", "array_merge", "(", "$", "roles", ",", "[", "$", "role", "]", ",", "$", "this", "->", "getHierarchy", "(", "$", "role", ",", "$", "roleHierarchy", ")", ")", ";", "}", "$", "this", "->", "roles", "=", "array_unique", "(", "$", "roles", ")", ";", "}", "}" ]
Parse user roles @param boolean $force force parsing @return void
[ "Parse", "user", "roles" ]
3941c62aeb6dafda55349a38dd4107d521f8964a
https://github.com/eghojansu/nutrition/blob/3941c62aeb6dafda55349a38dd4107d521f8964a/src/Security/Authorization.php#L93-L111
12,245
eghojansu/nutrition
src/Security/Authorization.php
Authorization.getHierarchy
protected function getHierarchy($role, array $roleHierarchy) { $roles = []; if (array_key_exists($role, $roleHierarchy)) { $roleRoles = (array) $roleHierarchy[$role]; foreach ($roleRoles as $role) { $roles = array_merge($roles, $this->getHierarchy($role, $roleHierarchy)); } $roles = array_merge($roles, $roleRoles); } return $roles; }
php
protected function getHierarchy($role, array $roleHierarchy) { $roles = []; if (array_key_exists($role, $roleHierarchy)) { $roleRoles = (array) $roleHierarchy[$role]; foreach ($roleRoles as $role) { $roles = array_merge($roles, $this->getHierarchy($role, $roleHierarchy)); } $roles = array_merge($roles, $roleRoles); } return $roles; }
[ "protected", "function", "getHierarchy", "(", "$", "role", ",", "array", "$", "roleHierarchy", ")", "{", "$", "roles", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "$", "role", ",", "$", "roleHierarchy", ")", ")", "{", "$", "roleRoles", "=", "(", "array", ")", "$", "roleHierarchy", "[", "$", "role", "]", ";", "foreach", "(", "$", "roleRoles", "as", "$", "role", ")", "{", "$", "roles", "=", "array_merge", "(", "$", "roles", ",", "$", "this", "->", "getHierarchy", "(", "$", "role", ",", "$", "roleHierarchy", ")", ")", ";", "}", "$", "roles", "=", "array_merge", "(", "$", "roles", ",", "$", "roleRoles", ")", ";", "}", "return", "$", "roles", ";", "}" ]
Get hierarchy for role @param string $role @param array $roleHierarchy @return array
[ "Get", "hierarchy", "for", "role" ]
3941c62aeb6dafda55349a38dd4107d521f8964a
https://github.com/eghojansu/nutrition/blob/3941c62aeb6dafda55349a38dd4107d521f8964a/src/Security/Authorization.php#L119-L131
12,246
faithmade/churchthemes
includes/classes/breadcrumbs.php
CTFW_WIDGETS_Breadcrumbs.taxonomy_term_breadcrumbs
public function taxonomy_term_breadcrumbs( $term, $taxonomy ) { $term_breadcrumbs = array(); if ( ! empty( $term ) ) { $term_obj = get_term( $term, $taxonomy ); // in case $term is ID, not already object // Current term $this->add_breadcrumb( $term_breadcrumbs, array( $term_obj->name, get_term_link( $term_obj, $taxonomy ) ) ); // Parent terms? if ( ! empty( $term_obj->parent ) ) { $parent_term_breadcrumbs = array(); // Traverse through parent terms $parent_term_id = $term_obj->parent; while ( $parent_term_id ) { // keep moving down levels until there are no more parent terms $parent_term = get_term( $parent_term_id, $taxonomy ); $parent_term_id = $parent_term->parent; // if this parent has a parent, while loop will continue $parent_term_breadcrumbs[] = array( $parent_term->name, get_term_link( $parent_term, $taxonomy ) ); } // Reverse parent term array and marge into main breadcrumbs $this->add_breadcrumbs_array( $term_breadcrumbs, $parent_term_breadcrumbs ); } } $term_breadcrumbs = apply_filters( 'ctc_taxonomy_term_breadcrumbs', $term_breadcrumbs, $term, $taxonomy ); return $term_breadcrumbs; }
php
public function taxonomy_term_breadcrumbs( $term, $taxonomy ) { $term_breadcrumbs = array(); if ( ! empty( $term ) ) { $term_obj = get_term( $term, $taxonomy ); // in case $term is ID, not already object // Current term $this->add_breadcrumb( $term_breadcrumbs, array( $term_obj->name, get_term_link( $term_obj, $taxonomy ) ) ); // Parent terms? if ( ! empty( $term_obj->parent ) ) { $parent_term_breadcrumbs = array(); // Traverse through parent terms $parent_term_id = $term_obj->parent; while ( $parent_term_id ) { // keep moving down levels until there are no more parent terms $parent_term = get_term( $parent_term_id, $taxonomy ); $parent_term_id = $parent_term->parent; // if this parent has a parent, while loop will continue $parent_term_breadcrumbs[] = array( $parent_term->name, get_term_link( $parent_term, $taxonomy ) ); } // Reverse parent term array and marge into main breadcrumbs $this->add_breadcrumbs_array( $term_breadcrumbs, $parent_term_breadcrumbs ); } } $term_breadcrumbs = apply_filters( 'ctc_taxonomy_term_breadcrumbs', $term_breadcrumbs, $term, $taxonomy ); return $term_breadcrumbs; }
[ "public", "function", "taxonomy_term_breadcrumbs", "(", "$", "term", ",", "$", "taxonomy", ")", "{", "$", "term_breadcrumbs", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "term", ")", ")", "{", "$", "term_obj", "=", "get_term", "(", "$", "term", ",", "$", "taxonomy", ")", ";", "// in case $term is ID, not already object", "// Current term", "$", "this", "->", "add_breadcrumb", "(", "$", "term_breadcrumbs", ",", "array", "(", "$", "term_obj", "->", "name", ",", "get_term_link", "(", "$", "term_obj", ",", "$", "taxonomy", ")", ")", ")", ";", "// Parent terms?", "if", "(", "!", "empty", "(", "$", "term_obj", "->", "parent", ")", ")", "{", "$", "parent_term_breadcrumbs", "=", "array", "(", ")", ";", "// Traverse through parent terms", "$", "parent_term_id", "=", "$", "term_obj", "->", "parent", ";", "while", "(", "$", "parent_term_id", ")", "{", "// keep moving down levels until there are no more parent terms", "$", "parent_term", "=", "get_term", "(", "$", "parent_term_id", ",", "$", "taxonomy", ")", ";", "$", "parent_term_id", "=", "$", "parent_term", "->", "parent", ";", "// if this parent has a parent, while loop will continue", "$", "parent_term_breadcrumbs", "[", "]", "=", "array", "(", "$", "parent_term", "->", "name", ",", "get_term_link", "(", "$", "parent_term", ",", "$", "taxonomy", ")", ")", ";", "}", "// Reverse parent term array and marge into main breadcrumbs", "$", "this", "->", "add_breadcrumbs_array", "(", "$", "term_breadcrumbs", ",", "$", "parent_term_breadcrumbs", ")", ";", "}", "}", "$", "term_breadcrumbs", "=", "apply_filters", "(", "'ctc_taxonomy_term_breadcrumbs'", ",", "$", "term_breadcrumbs", ",", "$", "term", ",", "$", "taxonomy", ")", ";", "return", "$", "term_breadcrumbs", ";", "}" ]
Get taxonomy term breadcrumbs @since 0.9 @access public @param mixed $term Taxonomy term as ID or object @param string $taxonomy Taxonomy slug to get breadcrumb ancestors for @return array Breadcrumb ancestors for taxonomy term
[ "Get", "taxonomy", "term", "breadcrumbs" ]
b121e840edaec8fdb3189fc9324cc88d7a0db81c
https://github.com/faithmade/churchthemes/blob/b121e840edaec8fdb3189fc9324cc88d7a0db81c/includes/classes/breadcrumbs.php#L179-L223
12,247
faithmade/churchthemes
includes/classes/breadcrumbs.php
CTFW_WIDGETS_Breadcrumbs.date_breadcrumbs
public function date_breadcrumbs( $base_url = false ) { $date_breadcrumbs = array(); // Year $year = get_query_var( 'year' ); if ( ! empty( $year ) ) { $dateformatstring = _x( 'Y', 'breadcrumb year format', 'church-theme-framework' ); if ( ! empty( $base_url ) ) { // if base URL given, use it (such as custom post type date archive) $date_url = trailingslashit( $base_url ) . trailingslashit( $year ); } else { $date_url = get_year_link( $year ); } $this->add_breadcrumb( $date_breadcrumbs, array( date_i18n( $dateformatstring, mktime( 0, 0, 0, 1, 1, $year ) ), $date_url ) ); // Month $month = get_query_var( 'monthnum' ); if ( ! empty( $month ) ) { $dateformatstring = _x( 'F', 'breadcrumb month format', 'church-theme-framework' ); if ( ! empty( $base_url ) ) { // if base URL given, use it (such as custom post type date archive) $date_url .= trailingslashit( $month ); } else { $date_url = get_month_link( $year, $month ); } $this->add_breadcrumb( $date_breadcrumbs, array( date_i18n( $dateformatstring, mktime( 0, 0, 0, $month, 1, $year ) ), $date_url ) ); // Day $day = get_query_var( 'day' ); if ( ! empty( $day ) ) { $dateformatstring = _x( 'jS', 'breadcrumb day format', 'church-theme-framework' ); if ( ! empty( $base_url ) ) { // if base URL given, use it (such as custom post type date archive) $date_url .= trailingslashit( $day ); } else { $date_url = get_day_link( $year, $month, $day ); } $this->add_breadcrumb( $date_breadcrumbs, array( date_i18n( $dateformatstring, mktime( 0, 0, 0, $month, $day, $year ) ), $date_url ) ); } } } // Reverse order $date_breadcrumbs = array_reverse( $date_breadcrumbs ); return apply_filters( 'ctc_date_breadcrumbs', $date_breadcrumbs, $base_url ); }
php
public function date_breadcrumbs( $base_url = false ) { $date_breadcrumbs = array(); // Year $year = get_query_var( 'year' ); if ( ! empty( $year ) ) { $dateformatstring = _x( 'Y', 'breadcrumb year format', 'church-theme-framework' ); if ( ! empty( $base_url ) ) { // if base URL given, use it (such as custom post type date archive) $date_url = trailingslashit( $base_url ) . trailingslashit( $year ); } else { $date_url = get_year_link( $year ); } $this->add_breadcrumb( $date_breadcrumbs, array( date_i18n( $dateformatstring, mktime( 0, 0, 0, 1, 1, $year ) ), $date_url ) ); // Month $month = get_query_var( 'monthnum' ); if ( ! empty( $month ) ) { $dateformatstring = _x( 'F', 'breadcrumb month format', 'church-theme-framework' ); if ( ! empty( $base_url ) ) { // if base URL given, use it (such as custom post type date archive) $date_url .= trailingslashit( $month ); } else { $date_url = get_month_link( $year, $month ); } $this->add_breadcrumb( $date_breadcrumbs, array( date_i18n( $dateformatstring, mktime( 0, 0, 0, $month, 1, $year ) ), $date_url ) ); // Day $day = get_query_var( 'day' ); if ( ! empty( $day ) ) { $dateformatstring = _x( 'jS', 'breadcrumb day format', 'church-theme-framework' ); if ( ! empty( $base_url ) ) { // if base URL given, use it (such as custom post type date archive) $date_url .= trailingslashit( $day ); } else { $date_url = get_day_link( $year, $month, $day ); } $this->add_breadcrumb( $date_breadcrumbs, array( date_i18n( $dateformatstring, mktime( 0, 0, 0, $month, $day, $year ) ), $date_url ) ); } } } // Reverse order $date_breadcrumbs = array_reverse( $date_breadcrumbs ); return apply_filters( 'ctc_date_breadcrumbs', $date_breadcrumbs, $base_url ); }
[ "public", "function", "date_breadcrumbs", "(", "$", "base_url", "=", "false", ")", "{", "$", "date_breadcrumbs", "=", "array", "(", ")", ";", "// Year", "$", "year", "=", "get_query_var", "(", "'year'", ")", ";", "if", "(", "!", "empty", "(", "$", "year", ")", ")", "{", "$", "dateformatstring", "=", "_x", "(", "'Y'", ",", "'breadcrumb year format'", ",", "'church-theme-framework'", ")", ";", "if", "(", "!", "empty", "(", "$", "base_url", ")", ")", "{", "// if base URL given, use it (such as custom post type date archive)", "$", "date_url", "=", "trailingslashit", "(", "$", "base_url", ")", ".", "trailingslashit", "(", "$", "year", ")", ";", "}", "else", "{", "$", "date_url", "=", "get_year_link", "(", "$", "year", ")", ";", "}", "$", "this", "->", "add_breadcrumb", "(", "$", "date_breadcrumbs", ",", "array", "(", "date_i18n", "(", "$", "dateformatstring", ",", "mktime", "(", "0", ",", "0", ",", "0", ",", "1", ",", "1", ",", "$", "year", ")", ")", ",", "$", "date_url", ")", ")", ";", "// Month", "$", "month", "=", "get_query_var", "(", "'monthnum'", ")", ";", "if", "(", "!", "empty", "(", "$", "month", ")", ")", "{", "$", "dateformatstring", "=", "_x", "(", "'F'", ",", "'breadcrumb month format'", ",", "'church-theme-framework'", ")", ";", "if", "(", "!", "empty", "(", "$", "base_url", ")", ")", "{", "// if base URL given, use it (such as custom post type date archive)", "$", "date_url", ".=", "trailingslashit", "(", "$", "month", ")", ";", "}", "else", "{", "$", "date_url", "=", "get_month_link", "(", "$", "year", ",", "$", "month", ")", ";", "}", "$", "this", "->", "add_breadcrumb", "(", "$", "date_breadcrumbs", ",", "array", "(", "date_i18n", "(", "$", "dateformatstring", ",", "mktime", "(", "0", ",", "0", ",", "0", ",", "$", "month", ",", "1", ",", "$", "year", ")", ")", ",", "$", "date_url", ")", ")", ";", "// Day", "$", "day", "=", "get_query_var", "(", "'day'", ")", ";", "if", "(", "!", "empty", "(", "$", "day", ")", ")", "{", "$", "dateformatstring", "=", "_x", "(", "'jS'", ",", "'breadcrumb day format'", ",", "'church-theme-framework'", ")", ";", "if", "(", "!", "empty", "(", "$", "base_url", ")", ")", "{", "// if base URL given, use it (such as custom post type date archive)", "$", "date_url", ".=", "trailingslashit", "(", "$", "day", ")", ";", "}", "else", "{", "$", "date_url", "=", "get_day_link", "(", "$", "year", ",", "$", "month", ",", "$", "day", ")", ";", "}", "$", "this", "->", "add_breadcrumb", "(", "$", "date_breadcrumbs", ",", "array", "(", "date_i18n", "(", "$", "dateformatstring", ",", "mktime", "(", "0", ",", "0", ",", "0", ",", "$", "month", ",", "$", "day", ",", "$", "year", ")", ")", ",", "$", "date_url", ")", ")", ";", "}", "}", "}", "// Reverse order", "$", "date_breadcrumbs", "=", "array_reverse", "(", "$", "date_breadcrumbs", ")", ";", "return", "apply_filters", "(", "'ctc_date_breadcrumbs'", ",", "$", "date_breadcrumbs", ",", "$", "base_url", ")", ";", "}" ]
Get date breadcrumbs @since 0.9 @access public @param string $base_url Provide a base URL for custom post type archives @return array Date breadcrumbs
[ "Get", "date", "breadcrumbs" ]
b121e840edaec8fdb3189fc9324cc88d7a0db81c
https://github.com/faithmade/churchthemes/blob/b121e840edaec8fdb3189fc9324cc88d7a0db81c/includes/classes/breadcrumbs.php#L233-L299
12,248
jaredtking/jaqb
src/Statement/FromStatement.php
FromStatement.buildJoins
private function buildJoins(array $joins) { foreach ($joins as &$join) { // table(s) foreach ($join[1] as &$table) { $table = $this->escapeIdentifier($table); } $join[1] = implode(', ', array_filter($join[1])); // on clause if ($join[2]) { $join[2] = 'ON '.$join[2]; } else { unset($join[2]); } // using clause foreach ($join[3] as &$column) { $column = $this->escapeIdentifier($column); } $join[3] = implode(', ', array_filter($join[3])); if ($join[3]) { $join[3] = 'USING ('.$join[3].')'; } else { unset($join[3]); } $join = implode(' ', $join); } return implode(' ', array_filter($joins)); }
php
private function buildJoins(array $joins) { foreach ($joins as &$join) { // table(s) foreach ($join[1] as &$table) { $table = $this->escapeIdentifier($table); } $join[1] = implode(', ', array_filter($join[1])); // on clause if ($join[2]) { $join[2] = 'ON '.$join[2]; } else { unset($join[2]); } // using clause foreach ($join[3] as &$column) { $column = $this->escapeIdentifier($column); } $join[3] = implode(', ', array_filter($join[3])); if ($join[3]) { $join[3] = 'USING ('.$join[3].')'; } else { unset($join[3]); } $join = implode(' ', $join); } return implode(' ', array_filter($joins)); }
[ "private", "function", "buildJoins", "(", "array", "$", "joins", ")", "{", "foreach", "(", "$", "joins", "as", "&", "$", "join", ")", "{", "// table(s)", "foreach", "(", "$", "join", "[", "1", "]", "as", "&", "$", "table", ")", "{", "$", "table", "=", "$", "this", "->", "escapeIdentifier", "(", "$", "table", ")", ";", "}", "$", "join", "[", "1", "]", "=", "implode", "(", "', '", ",", "array_filter", "(", "$", "join", "[", "1", "]", ")", ")", ";", "// on clause", "if", "(", "$", "join", "[", "2", "]", ")", "{", "$", "join", "[", "2", "]", "=", "'ON '", ".", "$", "join", "[", "2", "]", ";", "}", "else", "{", "unset", "(", "$", "join", "[", "2", "]", ")", ";", "}", "// using clause", "foreach", "(", "$", "join", "[", "3", "]", "as", "&", "$", "column", ")", "{", "$", "column", "=", "$", "this", "->", "escapeIdentifier", "(", "$", "column", ")", ";", "}", "$", "join", "[", "3", "]", "=", "implode", "(", "', '", ",", "array_filter", "(", "$", "join", "[", "3", "]", ")", ")", ";", "if", "(", "$", "join", "[", "3", "]", ")", "{", "$", "join", "[", "3", "]", "=", "'USING ('", ".", "$", "join", "[", "3", "]", ".", "')'", ";", "}", "else", "{", "unset", "(", "$", "join", "[", "3", "]", ")", ";", "}", "$", "join", "=", "implode", "(", "' '", ",", "$", "join", ")", ";", "}", "return", "implode", "(", "' '", ",", "array_filter", "(", "$", "joins", ")", ")", ";", "}" ]
Builds a list of joins. @param array $joins @return string
[ "Builds", "a", "list", "of", "joins", "." ]
04a853b530fcc12a9863349d3d0da6377d1b9995
https://github.com/jaredtking/jaqb/blob/04a853b530fcc12a9863349d3d0da6377d1b9995/src/Statement/FromStatement.php#L165-L196
12,249
Innmind/RestBundle
Client/Server.php
Server.remove
public function remove($name, $id) { $this->client->remove( $this->capabilities->get($name)->getUrl() . (string) $id ); return $this; }
php
public function remove($name, $id) { $this->client->remove( $this->capabilities->get($name)->getUrl() . (string) $id ); return $this; }
[ "public", "function", "remove", "(", "$", "name", ",", "$", "id", ")", "{", "$", "this", "->", "client", "->", "remove", "(", "$", "this", "->", "capabilities", "->", "get", "(", "$", "name", ")", "->", "getUrl", "(", ")", ".", "(", "string", ")", "$", "id", ")", ";", "return", "$", "this", ";", "}" ]
Delete a resource @param string $name @param mixed $id @return Server self
[ "Delete", "a", "resource" ]
46de57d9b45dfbfcf98867be3c601fba57f2edc2
https://github.com/Innmind/RestBundle/blob/46de57d9b45dfbfcf98867be3c601fba57f2edc2/Client/Server.php#L89-L96
12,250
Innmind/RestBundle
Client/Server.php
Server.getResources
public function getResources() { $keys = $this->capabilities->keys(); $definitions = []; foreach ($keys as $key) { $definitions[$key] = $this->capabilities->get($key); } return $definitions; }
php
public function getResources() { $keys = $this->capabilities->keys(); $definitions = []; foreach ($keys as $key) { $definitions[$key] = $this->capabilities->get($key); } return $definitions; }
[ "public", "function", "getResources", "(", ")", "{", "$", "keys", "=", "$", "this", "->", "capabilities", "->", "keys", "(", ")", ";", "$", "definitions", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "definitions", "[", "$", "key", "]", "=", "$", "this", "->", "capabilities", "->", "get", "(", "$", "key", ")", ";", "}", "return", "$", "definitions", ";", "}" ]
Return the list of resource definitions exposed via the capabilities route @return array
[ "Return", "the", "list", "of", "resource", "definitions", "exposed", "via", "the", "capabilities", "route" ]
46de57d9b45dfbfcf98867be3c601fba57f2edc2
https://github.com/Innmind/RestBundle/blob/46de57d9b45dfbfcf98867be3c601fba57f2edc2/Client/Server.php#L103-L113
12,251
synapsestudios/synapse-base
src/Synapse/Email/MandrillSender.php
MandrillSender.buildMessage
protected function buildMessage(EmailEntity $email) { // Create attachments array $attachments = json_decode($email->getAttachments(), true); $recipientEmail = $email->getRecipientEmail(); $to = [ [ 'email' => $this->filterThroughWhitelist($recipientEmail), 'name' => $email->getRecipientName(), 'type' => 'to' ] ]; $message = [ 'html' => $email->getMessage(), 'subject' => $email->getSubject(), 'from_email' => $email->getSenderEmail(), 'from_name' => $email->getSenderName(), 'to' => $to, 'attachments' => $attachments, 'headers' => json_decode($email->getHeaders(), true), 'important' => false, 'track_opens' => true, 'track_clicks' => true, 'auto_text' => true, 'auto_html' => false, 'inline_css' => true, 'url_strip_qs' => null, 'preserve_recipients' => false, 'bcc_address' => $email->getBcc(), 'merge' => true, ]; return $message; }
php
protected function buildMessage(EmailEntity $email) { // Create attachments array $attachments = json_decode($email->getAttachments(), true); $recipientEmail = $email->getRecipientEmail(); $to = [ [ 'email' => $this->filterThroughWhitelist($recipientEmail), 'name' => $email->getRecipientName(), 'type' => 'to' ] ]; $message = [ 'html' => $email->getMessage(), 'subject' => $email->getSubject(), 'from_email' => $email->getSenderEmail(), 'from_name' => $email->getSenderName(), 'to' => $to, 'attachments' => $attachments, 'headers' => json_decode($email->getHeaders(), true), 'important' => false, 'track_opens' => true, 'track_clicks' => true, 'auto_text' => true, 'auto_html' => false, 'inline_css' => true, 'url_strip_qs' => null, 'preserve_recipients' => false, 'bcc_address' => $email->getBcc(), 'merge' => true, ]; return $message; }
[ "protected", "function", "buildMessage", "(", "EmailEntity", "$", "email", ")", "{", "// Create attachments array", "$", "attachments", "=", "json_decode", "(", "$", "email", "->", "getAttachments", "(", ")", ",", "true", ")", ";", "$", "recipientEmail", "=", "$", "email", "->", "getRecipientEmail", "(", ")", ";", "$", "to", "=", "[", "[", "'email'", "=>", "$", "this", "->", "filterThroughWhitelist", "(", "$", "recipientEmail", ")", ",", "'name'", "=>", "$", "email", "->", "getRecipientName", "(", ")", ",", "'type'", "=>", "'to'", "]", "]", ";", "$", "message", "=", "[", "'html'", "=>", "$", "email", "->", "getMessage", "(", ")", ",", "'subject'", "=>", "$", "email", "->", "getSubject", "(", ")", ",", "'from_email'", "=>", "$", "email", "->", "getSenderEmail", "(", ")", ",", "'from_name'", "=>", "$", "email", "->", "getSenderName", "(", ")", ",", "'to'", "=>", "$", "to", ",", "'attachments'", "=>", "$", "attachments", ",", "'headers'", "=>", "json_decode", "(", "$", "email", "->", "getHeaders", "(", ")", ",", "true", ")", ",", "'important'", "=>", "false", ",", "'track_opens'", "=>", "true", ",", "'track_clicks'", "=>", "true", ",", "'auto_text'", "=>", "true", ",", "'auto_html'", "=>", "false", ",", "'inline_css'", "=>", "true", ",", "'url_strip_qs'", "=>", "null", ",", "'preserve_recipients'", "=>", "false", ",", "'bcc_address'", "=>", "$", "email", "->", "getBcc", "(", ")", ",", "'merge'", "=>", "true", ",", "]", ";", "return", "$", "message", ";", "}" ]
Build Mandrill compatible message array from email entity Documentation at https://mandrillapp.com/api/docs/messages.php.html @param EmailEntity $emails @return array
[ "Build", "Mandrill", "compatible", "message", "array", "from", "email", "entity" ]
60c830550491742a077ab063f924e2f0b63825da
https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Email/MandrillSender.php#L61-L97
12,252
laasti/lazydata
src/Resolvers/FilterResolver.php
FilterResolver.resolve
public function resolve($value, $default = 'value') { $matches = []; if (is_string($value) && preg_match('/^('.self::KEY_REGEX.')'. preg_quote($this->separator).'(.*)/', $value, $matches)) { if (isset($this->filters[$matches[1]])) { return call_user_func_array($this->filters[$matches[1]], [$matches[2]]); } else if (function_exists($matches[1])) { return call_user_func_array($matches[1], [$matches[2]]); } } return $this->fallback->resolve($value, $default); }
php
public function resolve($value, $default = 'value') { $matches = []; if (is_string($value) && preg_match('/^('.self::KEY_REGEX.')'. preg_quote($this->separator).'(.*)/', $value, $matches)) { if (isset($this->filters[$matches[1]])) { return call_user_func_array($this->filters[$matches[1]], [$matches[2]]); } else if (function_exists($matches[1])) { return call_user_func_array($matches[1], [$matches[2]]); } } return $this->fallback->resolve($value, $default); }
[ "public", "function", "resolve", "(", "$", "value", ",", "$", "default", "=", "'value'", ")", "{", "$", "matches", "=", "[", "]", ";", "if", "(", "is_string", "(", "$", "value", ")", "&&", "preg_match", "(", "'/^('", ".", "self", "::", "KEY_REGEX", ".", "')'", ".", "preg_quote", "(", "$", "this", "->", "separator", ")", ".", "'(.*)/'", ",", "$", "value", ",", "$", "matches", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "filters", "[", "$", "matches", "[", "1", "]", "]", ")", ")", "{", "return", "call_user_func_array", "(", "$", "this", "->", "filters", "[", "$", "matches", "[", "1", "]", "]", ",", "[", "$", "matches", "[", "2", "]", "]", ")", ";", "}", "else", "if", "(", "function_exists", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "return", "call_user_func_array", "(", "$", "matches", "[", "1", "]", ",", "[", "$", "matches", "[", "2", "]", "]", ")", ";", "}", "}", "return", "$", "this", "->", "fallback", "->", "resolve", "(", "$", "value", ",", "$", "default", ")", ";", "}" ]
Attempts to resolve through defined filters @param mixed $value
[ "Attempts", "to", "resolve", "through", "defined", "filters" ]
44ceab7475177fc94eeb4fa3b8b630f5fc4fa301
https://github.com/laasti/lazydata/blob/44ceab7475177fc94eeb4fa3b8b630f5fc4fa301/src/Resolvers/FilterResolver.php#L54-L66
12,253
laasti/lazydata
src/Resolvers/FilterResolver.php
FilterResolver.setFilter
public function setFilter($key, $callable) { if (!is_callable($callable)) { throw new InvalidArgumentException('Invalid callable for filter: "'.$key.'"'); } if (!preg_match('/^'.self::KEY_REGEX.'$/', $key)) { throw new InvalidArgumentException('Invalid name for filter: "'.$key.'". The filter name can only contain alphanumeric characters and underscore.'); } $this->filters[$key] = $callable; return $this; }
php
public function setFilter($key, $callable) { if (!is_callable($callable)) { throw new InvalidArgumentException('Invalid callable for filter: "'.$key.'"'); } if (!preg_match('/^'.self::KEY_REGEX.'$/', $key)) { throw new InvalidArgumentException('Invalid name for filter: "'.$key.'". The filter name can only contain alphanumeric characters and underscore.'); } $this->filters[$key] = $callable; return $this; }
[ "public", "function", "setFilter", "(", "$", "key", ",", "$", "callable", ")", "{", "if", "(", "!", "is_callable", "(", "$", "callable", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid callable for filter: \"'", ".", "$", "key", ".", "'\"'", ")", ";", "}", "if", "(", "!", "preg_match", "(", "'/^'", ".", "self", "::", "KEY_REGEX", ".", "'$/'", ",", "$", "key", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid name for filter: \"'", ".", "$", "key", ".", "'\". The filter name can only contain alphanumeric characters and underscore.'", ")", ";", "}", "$", "this", "->", "filters", "[", "$", "key", "]", "=", "$", "callable", ";", "return", "$", "this", ";", "}" ]
Map a filter to a callable @param string $key @param callable $callable @return FilterResolver @throws InvalidArgumentException
[ "Map", "a", "filter", "to", "a", "callable" ]
44ceab7475177fc94eeb4fa3b8b630f5fc4fa301
https://github.com/laasti/lazydata/blob/44ceab7475177fc94eeb4fa3b8b630f5fc4fa301/src/Resolvers/FilterResolver.php#L75-L88
12,254
konservs/brilliant.framework
libraries/CMS/BBreadcrumbs.php
BBreadcrumbs.add_element
public function add_element($url,$name,$active=true,$class='',$children=array()){ $this->elements[]=(object)array( 'url'=>$url, 'name'=>$name, 'active'=>$active, 'class'=>$class, 'children'=>$children, ); }
php
public function add_element($url,$name,$active=true,$class='',$children=array()){ $this->elements[]=(object)array( 'url'=>$url, 'name'=>$name, 'active'=>$active, 'class'=>$class, 'children'=>$children, ); }
[ "public", "function", "add_element", "(", "$", "url", ",", "$", "name", ",", "$", "active", "=", "true", ",", "$", "class", "=", "''", ",", "$", "children", "=", "array", "(", ")", ")", "{", "$", "this", "->", "elements", "[", "]", "=", "(", "object", ")", "array", "(", "'url'", "=>", "$", "url", ",", "'name'", "=>", "$", "name", ",", "'active'", "=>", "$", "active", ",", "'class'", "=>", "$", "class", ",", "'children'", "=>", "$", "children", ",", ")", ";", "}" ]
Add breadcrumb element into array.
[ "Add", "breadcrumb", "element", "into", "array", "." ]
95f03f1917f746fee98bea8a906ba0588c87762d
https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/CMS/BBreadcrumbs.php#L22-L30
12,255
konservs/brilliant.framework
libraries/CMS/BBreadcrumbs.php
BBreadcrumbs.draw
public function draw(){ $bRouter=\Application\BRouter::getInstance(); $template=$bRouter->templatename; $suffix=\Brilliant\HTTP\BBrowserUseragent::getDeviceSuffix(); $fn=BTEMPLATESPATH.$template.DIRECTORY_SEPARATOR.'breadcrumbs'.$suffix.'.php'; if(!file_exists($fn)){ $fn=BTEMPLATESPATH.$template.DIRECTORY_SEPARATOR.'breadcrumbs.d.php'; } if(!file_exists($fn)){ $fn=BTEMPLATESPATH.'default'.DIRECTORY_SEPARATOR.'breadcrumbs'.$suffix.'.php'; } if(!file_exists($fn)){ $fn=BTEMPLATESPATH.'default'.DIRECTORY_SEPARATOR.'breadcrumbs.d.php'; } if(!file_exists($fn)){ return ''; } include($fn); }
php
public function draw(){ $bRouter=\Application\BRouter::getInstance(); $template=$bRouter->templatename; $suffix=\Brilliant\HTTP\BBrowserUseragent::getDeviceSuffix(); $fn=BTEMPLATESPATH.$template.DIRECTORY_SEPARATOR.'breadcrumbs'.$suffix.'.php'; if(!file_exists($fn)){ $fn=BTEMPLATESPATH.$template.DIRECTORY_SEPARATOR.'breadcrumbs.d.php'; } if(!file_exists($fn)){ $fn=BTEMPLATESPATH.'default'.DIRECTORY_SEPARATOR.'breadcrumbs'.$suffix.'.php'; } if(!file_exists($fn)){ $fn=BTEMPLATESPATH.'default'.DIRECTORY_SEPARATOR.'breadcrumbs.d.php'; } if(!file_exists($fn)){ return ''; } include($fn); }
[ "public", "function", "draw", "(", ")", "{", "$", "bRouter", "=", "\\", "Application", "\\", "BRouter", "::", "getInstance", "(", ")", ";", "$", "template", "=", "$", "bRouter", "->", "templatename", ";", "$", "suffix", "=", "\\", "Brilliant", "\\", "HTTP", "\\", "BBrowserUseragent", "::", "getDeviceSuffix", "(", ")", ";", "$", "fn", "=", "BTEMPLATESPATH", ".", "$", "template", ".", "DIRECTORY_SEPARATOR", ".", "'breadcrumbs'", ".", "$", "suffix", ".", "'.php'", ";", "if", "(", "!", "file_exists", "(", "$", "fn", ")", ")", "{", "$", "fn", "=", "BTEMPLATESPATH", ".", "$", "template", ".", "DIRECTORY_SEPARATOR", ".", "'breadcrumbs.d.php'", ";", "}", "if", "(", "!", "file_exists", "(", "$", "fn", ")", ")", "{", "$", "fn", "=", "BTEMPLATESPATH", ".", "'default'", ".", "DIRECTORY_SEPARATOR", ".", "'breadcrumbs'", ".", "$", "suffix", ".", "'.php'", ";", "}", "if", "(", "!", "file_exists", "(", "$", "fn", ")", ")", "{", "$", "fn", "=", "BTEMPLATESPATH", ".", "'default'", ".", "DIRECTORY_SEPARATOR", ".", "'breadcrumbs.d.php'", ";", "}", "if", "(", "!", "file_exists", "(", "$", "fn", ")", ")", "{", "return", "''", ";", "}", "include", "(", "$", "fn", ")", ";", "}" ]
Draw breadcrumbs HTML
[ "Draw", "breadcrumbs", "HTML" ]
95f03f1917f746fee98bea8a906ba0588c87762d
https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/CMS/BBreadcrumbs.php#L34-L54
12,256
zepi/turbo-base
Zepi/Web/UserInterface/src/Table/Column.php
Column.getHtmlWidth
public function getHtmlWidth() { if (is_string($this->width) && $this->width === self::WIDTH_AUTO) { return ''; } else if (intval($this->width) > 0) { return $this->width . '%'; } return $this->width; }
php
public function getHtmlWidth() { if (is_string($this->width) && $this->width === self::WIDTH_AUTO) { return ''; } else if (intval($this->width) > 0) { return $this->width . '%'; } return $this->width; }
[ "public", "function", "getHtmlWidth", "(", ")", "{", "if", "(", "is_string", "(", "$", "this", "->", "width", ")", "&&", "$", "this", "->", "width", "===", "self", "::", "WIDTH_AUTO", ")", "{", "return", "''", ";", "}", "else", "if", "(", "intval", "(", "$", "this", "->", "width", ")", ">", "0", ")", "{", "return", "$", "this", "->", "width", ".", "'%'", ";", "}", "return", "$", "this", "->", "width", ";", "}" ]
Returns the correct with for the html attribute @access public @return string
[ "Returns", "the", "correct", "with", "for", "the", "html", "attribute" ]
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Table/Column.php#L158-L167
12,257
bugadani/Annotiny
src/AnnotationParser.php
AnnotationParser.parse
public function parse($commentString, $target) { // Extract the description part of the comment block $commentString = $this->stripCommentDecoration($commentString); $parts = preg_split('/^\s*(?=@[a-zA-Z]+)/m', $commentString, 2); $comment = new Comment(trim($parts[0])); if (!isset($parts[1])) { return $comment; } $trimmed = trim($parts[1]); if (empty($trimmed)) { return $comment; } $pattern = '/(\'(?:\\\\.|[^\'\\\\])*\'|"(?:\\\\.|[^"\\\\])*"|[@(),={}]|\s+|(?<![:])[:](?![:]))/'; $flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY; $this->parts = preg_split($pattern, $parts[1], -1, $flags); $this->position = -1; while (isset($this->parts[ ++$this->position ])) { if ($this->parts[ $this->position ] === '@') { list($name, $parameters, $isClass) = $this->parseTag(); if ($isClass) { $className = $this->getFullyQualifiedName($name); $this->saveState(); $comment->addAnnotation( $className, $this->container->readClass($className, $parameters, $target) ); $this->restoreState(); } else { $comment->add($name, $parameters); } } } return $comment; }
php
public function parse($commentString, $target) { // Extract the description part of the comment block $commentString = $this->stripCommentDecoration($commentString); $parts = preg_split('/^\s*(?=@[a-zA-Z]+)/m', $commentString, 2); $comment = new Comment(trim($parts[0])); if (!isset($parts[1])) { return $comment; } $trimmed = trim($parts[1]); if (empty($trimmed)) { return $comment; } $pattern = '/(\'(?:\\\\.|[^\'\\\\])*\'|"(?:\\\\.|[^"\\\\])*"|[@(),={}]|\s+|(?<![:])[:](?![:]))/'; $flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY; $this->parts = preg_split($pattern, $parts[1], -1, $flags); $this->position = -1; while (isset($this->parts[ ++$this->position ])) { if ($this->parts[ $this->position ] === '@') { list($name, $parameters, $isClass) = $this->parseTag(); if ($isClass) { $className = $this->getFullyQualifiedName($name); $this->saveState(); $comment->addAnnotation( $className, $this->container->readClass($className, $parameters, $target) ); $this->restoreState(); } else { $comment->add($name, $parameters); } } } return $comment; }
[ "public", "function", "parse", "(", "$", "commentString", ",", "$", "target", ")", "{", "// Extract the description part of the comment block", "$", "commentString", "=", "$", "this", "->", "stripCommentDecoration", "(", "$", "commentString", ")", ";", "$", "parts", "=", "preg_split", "(", "'/^\\s*(?=@[a-zA-Z]+)/m'", ",", "$", "commentString", ",", "2", ")", ";", "$", "comment", "=", "new", "Comment", "(", "trim", "(", "$", "parts", "[", "0", "]", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "parts", "[", "1", "]", ")", ")", "{", "return", "$", "comment", ";", "}", "$", "trimmed", "=", "trim", "(", "$", "parts", "[", "1", "]", ")", ";", "if", "(", "empty", "(", "$", "trimmed", ")", ")", "{", "return", "$", "comment", ";", "}", "$", "pattern", "=", "'/(\\'(?:\\\\\\\\.|[^\\'\\\\\\\\])*\\'|\"(?:\\\\\\\\.|[^\"\\\\\\\\])*\"|[@(),={}]|\\s+|(?<![:])[:](?![:]))/'", ";", "$", "flags", "=", "PREG_SPLIT_DELIM_CAPTURE", "|", "PREG_SPLIT_NO_EMPTY", ";", "$", "this", "->", "parts", "=", "preg_split", "(", "$", "pattern", ",", "$", "parts", "[", "1", "]", ",", "-", "1", ",", "$", "flags", ")", ";", "$", "this", "->", "position", "=", "-", "1", ";", "while", "(", "isset", "(", "$", "this", "->", "parts", "[", "++", "$", "this", "->", "position", "]", ")", ")", "{", "if", "(", "$", "this", "->", "parts", "[", "$", "this", "->", "position", "]", "===", "'@'", ")", "{", "list", "(", "$", "name", ",", "$", "parameters", ",", "$", "isClass", ")", "=", "$", "this", "->", "parseTag", "(", ")", ";", "if", "(", "$", "isClass", ")", "{", "$", "className", "=", "$", "this", "->", "getFullyQualifiedName", "(", "$", "name", ")", ";", "$", "this", "->", "saveState", "(", ")", ";", "$", "comment", "->", "addAnnotation", "(", "$", "className", ",", "$", "this", "->", "container", "->", "readClass", "(", "$", "className", ",", "$", "parameters", ",", "$", "target", ")", ")", ";", "$", "this", "->", "restoreState", "(", ")", ";", "}", "else", "{", "$", "comment", "->", "add", "(", "$", "name", ",", "$", "parameters", ")", ";", "}", "}", "}", "return", "$", "comment", ";", "}" ]
Parses a documentation comment. @param string $commentString @param $target @return Comment
[ "Parses", "a", "documentation", "comment", "." ]
9f28202192350c84b8158efc3984b00c5cdd1946
https://github.com/bugadani/Annotiny/blob/9f28202192350c84b8158efc3984b00c5cdd1946/src/AnnotationParser.php#L59-L99
12,258
bkazuo/common-helper-utilities
src/Helper/UtilityHelper.php
UtilityHelper.getDistance
public function getDistance($lat1, $lgn1, $lat2, $lgn2){ $earth_radius = 6371; $alpha = $lat1 - $lat2; $beta = $lgn1 - $lgn2; $h = pow((sin(deg2rad($alpha/2))), 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * pow(sin(deg2rad($beta/2)),2); $dist = 2*$earth_radius*sqrt($h); return $dist; }
php
public function getDistance($lat1, $lgn1, $lat2, $lgn2){ $earth_radius = 6371; $alpha = $lat1 - $lat2; $beta = $lgn1 - $lgn2; $h = pow((sin(deg2rad($alpha/2))), 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * pow(sin(deg2rad($beta/2)),2); $dist = 2*$earth_radius*sqrt($h); return $dist; }
[ "public", "function", "getDistance", "(", "$", "lat1", ",", "$", "lgn1", ",", "$", "lat2", ",", "$", "lgn2", ")", "{", "$", "earth_radius", "=", "6371", ";", "$", "alpha", "=", "$", "lat1", "-", "$", "lat2", ";", "$", "beta", "=", "$", "lgn1", "-", "$", "lgn2", ";", "$", "h", "=", "pow", "(", "(", "sin", "(", "deg2rad", "(", "$", "alpha", "/", "2", ")", ")", ")", ",", "2", ")", "+", "cos", "(", "deg2rad", "(", "$", "lat1", ")", ")", "*", "cos", "(", "deg2rad", "(", "$", "lat2", ")", ")", "*", "pow", "(", "sin", "(", "deg2rad", "(", "$", "beta", "/", "2", ")", ")", ",", "2", ")", ";", "$", "dist", "=", "2", "*", "$", "earth_radius", "*", "sqrt", "(", "$", "h", ")", ";", "return", "$", "dist", ";", "}" ]
Get distance between two lat and lng @param string $lat1 @param string $lng1 @param string $lat2 @param string $lng2
[ "Get", "distance", "between", "two", "lat", "and", "lng" ]
668fec3333a9db61ffe20e392346e1787dc85d38
https://github.com/bkazuo/common-helper-utilities/blob/668fec3333a9db61ffe20e392346e1787dc85d38/src/Helper/UtilityHelper.php#L57-L65
12,259
bkazuo/common-helper-utilities
src/Helper/UtilityHelper.php
UtilityHelper.hourRange
public function hourRange($openingTime, $closingTime){ $time1 = strtotime($openingTime); $time2 = strtotime($closingTime); return round(abs($time2 - $time1) / 3600,2); }
php
public function hourRange($openingTime, $closingTime){ $time1 = strtotime($openingTime); $time2 = strtotime($closingTime); return round(abs($time2 - $time1) / 3600,2); }
[ "public", "function", "hourRange", "(", "$", "openingTime", ",", "$", "closingTime", ")", "{", "$", "time1", "=", "strtotime", "(", "$", "openingTime", ")", ";", "$", "time2", "=", "strtotime", "(", "$", "closingTime", ")", ";", "return", "round", "(", "abs", "(", "$", "time2", "-", "$", "time1", ")", "/", "3600", ",", "2", ")", ";", "}" ]
Get difference of hours between hours @param string $startHour @param string $endHour
[ "Get", "difference", "of", "hours", "between", "hours" ]
668fec3333a9db61ffe20e392346e1787dc85d38
https://github.com/bkazuo/common-helper-utilities/blob/668fec3333a9db61ffe20e392346e1787dc85d38/src/Helper/UtilityHelper.php#L231-L235
12,260
tkhatibi/php-field
src/Field.php
Field.array2attrs
public static function array2attrs($assoc){ $attrs = []; foreach ((array) $assoc as $key => $value) { $attrs[] = is_string($key) ? "$key='$value'" : trim($value); } return implode(' ', $attrs); }
php
public static function array2attrs($assoc){ $attrs = []; foreach ((array) $assoc as $key => $value) { $attrs[] = is_string($key) ? "$key='$value'" : trim($value); } return implode(' ', $attrs); }
[ "public", "static", "function", "array2attrs", "(", "$", "assoc", ")", "{", "$", "attrs", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "assoc", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "attrs", "[", "]", "=", "is_string", "(", "$", "key", ")", "?", "\"$key='$value'\"", ":", "trim", "(", "$", "value", ")", ";", "}", "return", "implode", "(", "' '", ",", "$", "attrs", ")", ";", "}" ]
Get array and make attributes string @example ['class'=>'testClass', 'name'=>'foo' 'value'=>'bar', "id='exampleId'"] class='testClass' name='foo' value='bar' id='exampleId' @category Rendering @param array|object html attributes @return string html attributes
[ "Get", "array", "and", "make", "attributes", "string" ]
629657a7f96353ab6caf11ca9319a17ede719b76
https://github.com/tkhatibi/php-field/blob/629657a7f96353ab6caf11ca9319a17ede719b76/src/Field.php#L127-L135
12,261
tkhatibi/php-field
src/Field.php
Field.__tostring
public function __tostring() { // Prepare field label if (!$this->label) $this->label = $this->name; // Prepare errors $errors = []; foreach ((array) $this->errors as $error) { // Get Html code by $error $errors[] = $this->renderError($error); } // Implode errors $this->errors = implode('', $errors); // Prepare the object for rendering $this->prepare(); // Make html code related to the attributes $this->attributes = static::array2attrs($this->attributes); // Return rendered field return $this->renderField(); }
php
public function __tostring() { // Prepare field label if (!$this->label) $this->label = $this->name; // Prepare errors $errors = []; foreach ((array) $this->errors as $error) { // Get Html code by $error $errors[] = $this->renderError($error); } // Implode errors $this->errors = implode('', $errors); // Prepare the object for rendering $this->prepare(); // Make html code related to the attributes $this->attributes = static::array2attrs($this->attributes); // Return rendered field return $this->renderField(); }
[ "public", "function", "__tostring", "(", ")", "{", "// Prepare field label\r", "if", "(", "!", "$", "this", "->", "label", ")", "$", "this", "->", "label", "=", "$", "this", "->", "name", ";", "// Prepare errors\r", "$", "errors", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "this", "->", "errors", "as", "$", "error", ")", "{", "// Get Html code by $error\r", "$", "errors", "[", "]", "=", "$", "this", "->", "renderError", "(", "$", "error", ")", ";", "}", "// Implode errors\r", "$", "this", "->", "errors", "=", "implode", "(", "''", ",", "$", "errors", ")", ";", "// Prepare the object for rendering\r", "$", "this", "->", "prepare", "(", ")", ";", "// Make html code related to the attributes\r", "$", "this", "->", "attributes", "=", "static", "::", "array2attrs", "(", "$", "this", "->", "attributes", ")", ";", "// Return rendered field\r", "return", "$", "this", "->", "renderField", "(", ")", ";", "}" ]
Prepare some config and render element @uses self::prepareAttributes() to make html code related to the attributes @uses self::array2attrs() to make html code related to the attributes @category Rendering @return string Rendered element
[ "Prepare", "some", "config", "and", "render", "element" ]
629657a7f96353ab6caf11ca9319a17ede719b76
https://github.com/tkhatibi/php-field/blob/629657a7f96353ab6caf11ca9319a17ede719b76/src/Field.php#L147-L165
12,262
tkhatibi/php-field
src/Field.php
Field.validate
public function validate() { // Deny if rules array is empty if (empty($this->rules)) return true; // If rules are invalid if (!is_array($this->rules)) throw new \Exception("The rules must be an array of the validator|sanitize rules", 1); // Loop the rules foreach ($this->rules as $rule) { // Run rule $rule instanceof \Closure ? $rule($this) : call_user_func($rule, $this); } // Check the field is valid return !$this->hasError(); }
php
public function validate() { // Deny if rules array is empty if (empty($this->rules)) return true; // If rules are invalid if (!is_array($this->rules)) throw new \Exception("The rules must be an array of the validator|sanitize rules", 1); // Loop the rules foreach ($this->rules as $rule) { // Run rule $rule instanceof \Closure ? $rule($this) : call_user_func($rule, $this); } // Check the field is valid return !$this->hasError(); }
[ "public", "function", "validate", "(", ")", "{", "// Deny if rules array is empty\r", "if", "(", "empty", "(", "$", "this", "->", "rules", ")", ")", "return", "true", ";", "// If rules are invalid\r", "if", "(", "!", "is_array", "(", "$", "this", "->", "rules", ")", ")", "throw", "new", "\\", "Exception", "(", "\"The rules must be an array of the validator|sanitize rules\"", ",", "1", ")", ";", "// Loop the rules\r", "foreach", "(", "$", "this", "->", "rules", "as", "$", "rule", ")", "{", "// Run rule\r", "$", "rule", "instanceof", "\\", "Closure", "?", "$", "rule", "(", "$", "this", ")", ":", "call_user_func", "(", "$", "rule", ",", "$", "this", ")", ";", "}", "// Check the field is valid\r", "return", "!", "$", "this", "->", "hasError", "(", ")", ";", "}" ]
Run the rule of the rules Each rule can push error to the field or change the value of the field @category Validation @return boolean The result of validation
[ "Run", "the", "rule", "of", "the", "rules", "Each", "rule", "can", "push", "error", "to", "the", "field", "or", "change", "the", "value", "of", "the", "field" ]
629657a7f96353ab6caf11ca9319a17ede719b76
https://github.com/tkhatibi/php-field/blob/629657a7f96353ab6caf11ca9319a17ede719b76/src/Field.php#L246-L262
12,263
wpfulcrum/foundation
src/Foundation/ServiceProvider/Provider.php
Provider.initDefaults
protected function initDefaults() { if (!$this->hasDefaults) { return ''; } $this->defaultsLocation = get_calling_class_directory($this) . DIRECTORY_SEPARATOR . $this->defaultsLocation; return ConfigFactory::loadConfigFile($this->defaultsLocation); }
php
protected function initDefaults() { if (!$this->hasDefaults) { return ''; } $this->defaultsLocation = get_calling_class_directory($this) . DIRECTORY_SEPARATOR . $this->defaultsLocation; return ConfigFactory::loadConfigFile($this->defaultsLocation); }
[ "protected", "function", "initDefaults", "(", ")", "{", "if", "(", "!", "$", "this", "->", "hasDefaults", ")", "{", "return", "''", ";", "}", "$", "this", "->", "defaultsLocation", "=", "get_calling_class_directory", "(", "$", "this", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "defaultsLocation", ";", "return", "ConfigFactory", "::", "loadConfigFile", "(", "$", "this", "->", "defaultsLocation", ")", ";", "}" ]
Initialize the defaults. @since 3.0.0 @return void
[ "Initialize", "the", "defaults", "." ]
a9655d8fa3bcc4b9d99586bb84a9f36dfa63ed56
https://github.com/wpfulcrum/foundation/blob/a9655d8fa3bcc4b9d99586bb84a9f36dfa63ed56/src/Foundation/ServiceProvider/Provider.php#L96-L105
12,264
wpfulcrum/foundation
src/Foundation/ServiceProvider/Provider.php
Provider.register
public function register(array $concreteConfig, $uniqueId) { $concreteConfig = $this->parseWithDefaultStructure($concreteConfig); if (!Validator::okayToRegister($uniqueId, $concreteConfig, $this->defaultStructure, __CLASS__)) { return false; } $concrete = $this->getConcrete($concreteConfig, $uniqueId); if (true === $this->skipQueue) { return $this->registerConcrete($concrete, $uniqueId); } return $this->queued[$uniqueId] = $concrete; }
php
public function register(array $concreteConfig, $uniqueId) { $concreteConfig = $this->parseWithDefaultStructure($concreteConfig); if (!Validator::okayToRegister($uniqueId, $concreteConfig, $this->defaultStructure, __CLASS__)) { return false; } $concrete = $this->getConcrete($concreteConfig, $uniqueId); if (true === $this->skipQueue) { return $this->registerConcrete($concrete, $uniqueId); } return $this->queued[$uniqueId] = $concrete; }
[ "public", "function", "register", "(", "array", "$", "concreteConfig", ",", "$", "uniqueId", ")", "{", "$", "concreteConfig", "=", "$", "this", "->", "parseWithDefaultStructure", "(", "$", "concreteConfig", ")", ";", "if", "(", "!", "Validator", "::", "okayToRegister", "(", "$", "uniqueId", ",", "$", "concreteConfig", ",", "$", "this", "->", "defaultStructure", ",", "__CLASS__", ")", ")", "{", "return", "false", ";", "}", "$", "concrete", "=", "$", "this", "->", "getConcrete", "(", "$", "concreteConfig", ",", "$", "uniqueId", ")", ";", "if", "(", "true", "===", "$", "this", "->", "skipQueue", ")", "{", "return", "$", "this", "->", "registerConcrete", "(", "$", "concrete", ",", "$", "uniqueId", ")", ";", "}", "return", "$", "this", "->", "queued", "[", "$", "uniqueId", "]", "=", "$", "concrete", ";", "}" ]
Register a concrete into the container. @since 3.0.0 @param array $concreteConfig Concrete's runtime configuration parameters. @param string $uniqueId Container's unique key ID for this instance. @returns mixed
[ "Register", "a", "concrete", "into", "the", "container", "." ]
a9655d8fa3bcc4b9d99586bb84a9f36dfa63ed56
https://github.com/wpfulcrum/foundation/blob/a9655d8fa3bcc4b9d99586bb84a9f36dfa63ed56/src/Foundation/ServiceProvider/Provider.php#L133-L148
12,265
wpfulcrum/foundation
src/Foundation/ServiceProvider/Provider.php
Provider.registerConcrete
protected function registerConcrete(array $concrete, $uniqueId) { $this->uniqueIds[] = $uniqueId; return $this->fulcrum->registerConcrete($concrete, $uniqueId); }
php
protected function registerConcrete(array $concrete, $uniqueId) { $this->uniqueIds[] = $uniqueId; return $this->fulcrum->registerConcrete($concrete, $uniqueId); }
[ "protected", "function", "registerConcrete", "(", "array", "$", "concrete", ",", "$", "uniqueId", ")", "{", "$", "this", "->", "uniqueIds", "[", "]", "=", "$", "uniqueId", ";", "return", "$", "this", "->", "fulcrum", "->", "registerConcrete", "(", "$", "concrete", ",", "$", "uniqueId", ")", ";", "}" ]
Register the concrete into the Container. @since 3.0.0 @param array $concrete Array for the concrete to be registered. @param string $uniqueId Container's unique key ID for this instance. @return mixed
[ "Register", "the", "concrete", "into", "the", "Container", "." ]
a9655d8fa3bcc4b9d99586bb84a9f36dfa63ed56
https://github.com/wpfulcrum/foundation/blob/a9655d8fa3bcc4b9d99586bb84a9f36dfa63ed56/src/Foundation/ServiceProvider/Provider.php#L176-L181
12,266
kore/CTXParser
src/php/CTXParser/Tokenizer/Regexp.php
Regexp.tokenize
public function tokenize($string) { $line = 1; $position = 1; $tokens = array(); while (strlen($string)) { foreach ($this->expressions as $rule) { if (!preg_match($rule['match'], $string, $match)) { continue; } // Remove matched string from input $string = substr($string, strlen($match[0])); // Update position in file $line += substr_count($match[0], "\n"); if (($pos = strrpos($match[0], "\n")) !== false) { $position = strrpos($match[0], "\n") + 1; } else { $position += strlen($match[0]); } // Skip irrelevant rules if (in_array($rule['type'], $this->ignoreTokens)) { continue 2; } // Add all other rules including their match to the token array $match = $this->removeNumericKeys($match); $tokens[] = new Token($rule['type'], $line, $position, $match); continue 2; } throw new \RuntimeException( "Could not parse string: '" . substr($string, 0, 20) . "' in line $line at position $position." ); } $tokens[] = new Token(self::T_EOF, $line, $position, null); return $tokens; }
php
public function tokenize($string) { $line = 1; $position = 1; $tokens = array(); while (strlen($string)) { foreach ($this->expressions as $rule) { if (!preg_match($rule['match'], $string, $match)) { continue; } // Remove matched string from input $string = substr($string, strlen($match[0])); // Update position in file $line += substr_count($match[0], "\n"); if (($pos = strrpos($match[0], "\n")) !== false) { $position = strrpos($match[0], "\n") + 1; } else { $position += strlen($match[0]); } // Skip irrelevant rules if (in_array($rule['type'], $this->ignoreTokens)) { continue 2; } // Add all other rules including their match to the token array $match = $this->removeNumericKeys($match); $tokens[] = new Token($rule['type'], $line, $position, $match); continue 2; } throw new \RuntimeException( "Could not parse string: '" . substr($string, 0, 20) . "' in line $line at position $position." ); } $tokens[] = new Token(self::T_EOF, $line, $position, null); return $tokens; }
[ "public", "function", "tokenize", "(", "$", "string", ")", "{", "$", "line", "=", "1", ";", "$", "position", "=", "1", ";", "$", "tokens", "=", "array", "(", ")", ";", "while", "(", "strlen", "(", "$", "string", ")", ")", "{", "foreach", "(", "$", "this", "->", "expressions", "as", "$", "rule", ")", "{", "if", "(", "!", "preg_match", "(", "$", "rule", "[", "'match'", "]", ",", "$", "string", ",", "$", "match", ")", ")", "{", "continue", ";", "}", "// Remove matched string from input", "$", "string", "=", "substr", "(", "$", "string", ",", "strlen", "(", "$", "match", "[", "0", "]", ")", ")", ";", "// Update position in file", "$", "line", "+=", "substr_count", "(", "$", "match", "[", "0", "]", ",", "\"\\n\"", ")", ";", "if", "(", "(", "$", "pos", "=", "strrpos", "(", "$", "match", "[", "0", "]", ",", "\"\\n\"", ")", ")", "!==", "false", ")", "{", "$", "position", "=", "strrpos", "(", "$", "match", "[", "0", "]", ",", "\"\\n\"", ")", "+", "1", ";", "}", "else", "{", "$", "position", "+=", "strlen", "(", "$", "match", "[", "0", "]", ")", ";", "}", "// Skip irrelevant rules", "if", "(", "in_array", "(", "$", "rule", "[", "'type'", "]", ",", "$", "this", "->", "ignoreTokens", ")", ")", "{", "continue", "2", ";", "}", "// Add all other rules including their match to the token array", "$", "match", "=", "$", "this", "->", "removeNumericKeys", "(", "$", "match", ")", ";", "$", "tokens", "[", "]", "=", "new", "Token", "(", "$", "rule", "[", "'type'", "]", ",", "$", "line", ",", "$", "position", ",", "$", "match", ")", ";", "continue", "2", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"Could not parse string: '\"", ".", "substr", "(", "$", "string", ",", "0", ",", "20", ")", ".", "\"' in line $line at position $position.\"", ")", ";", "}", "$", "tokens", "[", "]", "=", "new", "Token", "(", "self", "::", "T_EOF", ",", "$", "line", ",", "$", "position", ",", "null", ")", ";", "return", "$", "tokens", ";", "}" ]
Tokenize the input string Returns an array of Token structs representing the tokens. @param string $string @return Token[]
[ "Tokenize", "the", "input", "string" ]
9b11c2311a9de61baee7edafe46d1671dd5833c4
https://github.com/kore/CTXParser/blob/9b11c2311a9de61baee7edafe46d1671dd5833c4/src/php/CTXParser/Tokenizer/Regexp.php#L70-L111
12,267
SocietyCMS/User
Repositories/Entrust/EntrustUserRepository.php
EntrustUserRepository.create
public function create(array $data) { if (array_key_exists('password', $data)) { $data['password'] = bcrypt($data['password']); } return parent::create($data); }
php
public function create(array $data) { if (array_key_exists('password', $data)) { $data['password'] = bcrypt($data['password']); } return parent::create($data); }
[ "public", "function", "create", "(", "array", "$", "data", ")", "{", "if", "(", "array_key_exists", "(", "'password'", ",", "$", "data", ")", ")", "{", "$", "data", "[", "'password'", "]", "=", "bcrypt", "(", "$", "data", "[", "'password'", "]", ")", ";", "}", "return", "parent", "::", "create", "(", "$", "data", ")", ";", "}" ]
Encrypt password before creating a new user instance. @param array $data @return EloquentUser
[ "Encrypt", "password", "before", "creating", "a", "new", "user", "instance", "." ]
76f7b52b27e8a9740f8d5a9c3b86181e1c231634
https://github.com/SocietyCMS/User/blob/76f7b52b27e8a9740f8d5a9c3b86181e1c231634/Repositories/Entrust/EntrustUserRepository.php#L27-L34
12,268
SocietyCMS/User
Repositories/Entrust/EntrustUserRepository.php
EntrustUserRepository.update
public function update(array $data, $id) { if (array_key_exists('password', $data)) { $data['password'] = bcrypt($data['password']); } return parent::update($data, $id); }
php
public function update(array $data, $id) { if (array_key_exists('password', $data)) { $data['password'] = bcrypt($data['password']); } return parent::update($data, $id); }
[ "public", "function", "update", "(", "array", "$", "data", ",", "$", "id", ")", "{", "if", "(", "array_key_exists", "(", "'password'", ",", "$", "data", ")", ")", "{", "$", "data", "[", "'password'", "]", "=", "bcrypt", "(", "$", "data", "[", "'password'", "]", ")", ";", "}", "return", "parent", "::", "update", "(", "$", "data", ",", "$", "id", ")", ";", "}" ]
Encrypt password before updating a user instance. @param array $data @return EloquentUser
[ "Encrypt", "password", "before", "updating", "a", "user", "instance", "." ]
76f7b52b27e8a9740f8d5a9c3b86181e1c231634
https://github.com/SocietyCMS/User/blob/76f7b52b27e8a9740f8d5a9c3b86181e1c231634/Repositories/Entrust/EntrustUserRepository.php#L43-L50
12,269
e-commerce-passaro/compra
src/Compra/Manager.php
Manager.generateListByIterator
private function generateListByIterator(Iterator $iterator) { $resultado = array(); foreach ($iterator as $compra) { $resultado[] = $this->preencherCompra($compra); } return $resultado; }
php
private function generateListByIterator(Iterator $iterator) { $resultado = array(); foreach ($iterator as $compra) { $resultado[] = $this->preencherCompra($compra); } return $resultado; }
[ "private", "function", "generateListByIterator", "(", "Iterator", "$", "iterator", ")", "{", "$", "resultado", "=", "array", "(", ")", ";", "foreach", "(", "$", "iterator", "as", "$", "compra", ")", "{", "$", "resultado", "[", "]", "=", "$", "this", "->", "preencherCompra", "(", "$", "compra", ")", ";", "}", "return", "$", "resultado", ";", "}" ]
Gera um lista completa de compras a partir de um iterator @param Iterator $iterator
[ "Gera", "um", "lista", "completa", "de", "compras", "a", "partir", "de", "um", "iterator" ]
8acf4ec2dbcb32305b7855bf6d936c8b95ddd105
https://github.com/e-commerce-passaro/compra/blob/8acf4ec2dbcb32305b7855bf6d936c8b95ddd105/src/Compra/Manager.php#L61-L69
12,270
e-commerce-passaro/compra
src/Compra/Manager.php
Manager.preencherCompra
public function preencherCompra(Compra $compra) { $compra->setProduto($this->getProdutoManager()->getProduto($compra->getProdutoId())); $compra->setAutenticacao($this->getAutenticacaoManager()->obterAutenticacaoBasica($compra->getAutenticacaoId())); $compra->setStatus($this->getStatusManager()->obterStatus($compra->getStatusId())); return $compra; }
php
public function preencherCompra(Compra $compra) { $compra->setProduto($this->getProdutoManager()->getProduto($compra->getProdutoId())); $compra->setAutenticacao($this->getAutenticacaoManager()->obterAutenticacaoBasica($compra->getAutenticacaoId())); $compra->setStatus($this->getStatusManager()->obterStatus($compra->getStatusId())); return $compra; }
[ "public", "function", "preencherCompra", "(", "Compra", "$", "compra", ")", "{", "$", "compra", "->", "setProduto", "(", "$", "this", "->", "getProdutoManager", "(", ")", "->", "getProduto", "(", "$", "compra", "->", "getProdutoId", "(", ")", ")", ")", ";", "$", "compra", "->", "setAutenticacao", "(", "$", "this", "->", "getAutenticacaoManager", "(", ")", "->", "obterAutenticacaoBasica", "(", "$", "compra", "->", "getAutenticacaoId", "(", ")", ")", ")", ";", "$", "compra", "->", "setStatus", "(", "$", "this", "->", "getStatusManager", "(", ")", "->", "obterStatus", "(", "$", "compra", "->", "getStatusId", "(", ")", ")", ")", ";", "return", "$", "compra", ";", "}" ]
Preenche as entidades relacionadas na compra @param Compra $compra @return \Compra\Compra
[ "Preenche", "as", "entidades", "relacionadas", "na", "compra" ]
8acf4ec2dbcb32305b7855bf6d936c8b95ddd105
https://github.com/e-commerce-passaro/compra/blob/8acf4ec2dbcb32305b7855bf6d936c8b95ddd105/src/Compra/Manager.php#L111-L117
12,271
arkanmgerges/multi-tier-architecture
src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php
EntityMapperAbstract.getMappedSecondEntitiesByEntityType
public function getMappedSecondEntitiesByEntityType($secondEntityName) { $secondEntities = []; foreach ($this->data as $data) { $secondEntity = $this->createAndReturnNewSecondEntity($data, $secondEntityName); if ($secondEntity) { $secondEntities[] = $secondEntity; } } return $secondEntities; }
php
public function getMappedSecondEntitiesByEntityType($secondEntityName) { $secondEntities = []; foreach ($this->data as $data) { $secondEntity = $this->createAndReturnNewSecondEntity($data, $secondEntityName); if ($secondEntity) { $secondEntities[] = $secondEntity; } } return $secondEntities; }
[ "public", "function", "getMappedSecondEntitiesByEntityType", "(", "$", "secondEntityName", ")", "{", "$", "secondEntities", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "data", ")", "{", "$", "secondEntity", "=", "$", "this", "->", "createAndReturnNewSecondEntity", "(", "$", "data", ",", "$", "secondEntityName", ")", ";", "if", "(", "$", "secondEntity", ")", "{", "$", "secondEntities", "[", "]", "=", "$", "secondEntity", ";", "}", "}", "return", "$", "secondEntities", ";", "}" ]
Get second entities for the passed argument that represents the name of the second entity @param string $secondEntityName Second entity name @return array Array of entities
[ "Get", "second", "entities", "for", "the", "passed", "argument", "that", "represents", "the", "name", "of", "the", "second", "entity" ]
e8729841db66de7de0bdc9ed79ab73fe2bc262c0
https://github.com/arkanmgerges/multi-tier-architecture/blob/e8729841db66de7de0bdc9ed79ab73fe2bc262c0/src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php#L149-L160
12,272
arkanmgerges/multi-tier-architecture
src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php
EntityMapperAbstract.createAndReturnNewSecondEntity
private function createAndReturnNewSecondEntity($data, $secondEntityName) { /** @var EntityInterface $entity */ $entity = $this->getSecondEntityByName($secondEntityName); if (is_array($data)) { return $this->mapAttributesFromFirstEntityToSecondEntityAndReturnEntity($data, $entity); } return null; }
php
private function createAndReturnNewSecondEntity($data, $secondEntityName) { /** @var EntityInterface $entity */ $entity = $this->getSecondEntityByName($secondEntityName); if (is_array($data)) { return $this->mapAttributesFromFirstEntityToSecondEntityAndReturnEntity($data, $entity); } return null; }
[ "private", "function", "createAndReturnNewSecondEntity", "(", "$", "data", ",", "$", "secondEntityName", ")", "{", "/** @var EntityInterface $entity */", "$", "entity", "=", "$", "this", "->", "getSecondEntityByName", "(", "$", "secondEntityName", ")", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "return", "$", "this", "->", "mapAttributesFromFirstEntityToSecondEntityAndReturnEntity", "(", "$", "data", ",", "$", "entity", ")", ";", "}", "return", "null", ";", "}" ]
Return a new second entity @param array $data Data array that represents entity's attributes @param string $secondEntityName Name of the entity @return EntityInterface|null
[ "Return", "a", "new", "second", "entity" ]
e8729841db66de7de0bdc9ed79ab73fe2bc262c0
https://github.com/arkanmgerges/multi-tier-architecture/blob/e8729841db66de7de0bdc9ed79ab73fe2bc262c0/src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php#L170-L179
12,273
arkanmgerges/multi-tier-architecture
src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php
EntityMapperAbstract.setSecondEntityAttribute
private function setSecondEntityAttribute($secondEntity, $attributeName, $attributeData) { $entityAttribute = $this->mappingFirstEntityToSecondEntityAttributes[$attributeName]; $setterMethod = 'set' . ucfirst($entityAttribute); if (method_exists($secondEntity, $setterMethod)) { $secondEntity->$setterMethod($attributeData); } }
php
private function setSecondEntityAttribute($secondEntity, $attributeName, $attributeData) { $entityAttribute = $this->mappingFirstEntityToSecondEntityAttributes[$attributeName]; $setterMethod = 'set' . ucfirst($entityAttribute); if (method_exists($secondEntity, $setterMethod)) { $secondEntity->$setterMethod($attributeData); } }
[ "private", "function", "setSecondEntityAttribute", "(", "$", "secondEntity", ",", "$", "attributeName", ",", "$", "attributeData", ")", "{", "$", "entityAttribute", "=", "$", "this", "->", "mappingFirstEntityToSecondEntityAttributes", "[", "$", "attributeName", "]", ";", "$", "setterMethod", "=", "'set'", ".", "ucfirst", "(", "$", "entityAttribute", ")", ";", "if", "(", "method_exists", "(", "$", "secondEntity", ",", "$", "setterMethod", ")", ")", "{", "$", "secondEntity", "->", "$", "setterMethod", "(", "$", "attributeData", ")", ";", "}", "}" ]
Set second entity attribute based on the attribute name and attribute data @param EntityInterface $secondEntity Second entity name @param string $attributeName Attribute name of the entity @param mixed $attributeData Attribute data of the entity @return void
[ "Set", "second", "entity", "attribute", "based", "on", "the", "attribute", "name", "and", "attribute", "data" ]
e8729841db66de7de0bdc9ed79ab73fe2bc262c0
https://github.com/arkanmgerges/multi-tier-architecture/blob/e8729841db66de7de0bdc9ed79ab73fe2bc262c0/src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php#L221-L229
12,274
arkanmgerges/multi-tier-architecture
src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php
EntityMapperAbstract.getMappedFirstEntitiesByEntityType
public function getMappedFirstEntitiesByEntityType($entityName) { $entities = []; foreach ($this->data as $data) { $entity = $this->createAndReturnNewFirstEntity($data, $entityName); if ($entity) { $entities[] = $entity; } } return $entities; }
php
public function getMappedFirstEntitiesByEntityType($entityName) { $entities = []; foreach ($this->data as $data) { $entity = $this->createAndReturnNewFirstEntity($data, $entityName); if ($entity) { $entities[] = $entity; } } return $entities; }
[ "public", "function", "getMappedFirstEntitiesByEntityType", "(", "$", "entityName", ")", "{", "$", "entities", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "data", ")", "{", "$", "entity", "=", "$", "this", "->", "createAndReturnNewFirstEntity", "(", "$", "data", ",", "$", "entityName", ")", ";", "if", "(", "$", "entity", ")", "{", "$", "entities", "[", "]", "=", "$", "entity", ";", "}", "}", "return", "$", "entities", ";", "}" ]
Get entities for the passed argument that represents the name of the entity @param string $entityName Entity name @return array Array of entities
[ "Get", "entities", "for", "the", "passed", "argument", "that", "represents", "the", "name", "of", "the", "entity" ]
e8729841db66de7de0bdc9ed79ab73fe2bc262c0
https://github.com/arkanmgerges/multi-tier-architecture/blob/e8729841db66de7de0bdc9ed79ab73fe2bc262c0/src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php#L238-L248
12,275
arkanmgerges/multi-tier-architecture
src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php
EntityMapperAbstract.returnKey
private static function returnKey($key, $mappingArray) { if (!is_array($mappingArray)) { return $key; } foreach ($mappingArray as $mappingKey => $mappingData) { if (is_array($mappingData)) { if (isset($mappingData[$key])) { return $mappingData[$key]; } } else { if ($mappingKey == $key) { return $mappingData; } } } return $key; }
php
private static function returnKey($key, $mappingArray) { if (!is_array($mappingArray)) { return $key; } foreach ($mappingArray as $mappingKey => $mappingData) { if (is_array($mappingData)) { if (isset($mappingData[$key])) { return $mappingData[$key]; } } else { if ($mappingKey == $key) { return $mappingData; } } } return $key; }
[ "private", "static", "function", "returnKey", "(", "$", "key", ",", "$", "mappingArray", ")", "{", "if", "(", "!", "is_array", "(", "$", "mappingArray", ")", ")", "{", "return", "$", "key", ";", "}", "foreach", "(", "$", "mappingArray", "as", "$", "mappingKey", "=>", "$", "mappingData", ")", "{", "if", "(", "is_array", "(", "$", "mappingData", ")", ")", "{", "if", "(", "isset", "(", "$", "mappingData", "[", "$", "key", "]", ")", ")", "{", "return", "$", "mappingData", "[", "$", "key", "]", ";", "}", "}", "else", "{", "if", "(", "$", "mappingKey", "==", "$", "key", ")", "{", "return", "$", "mappingData", ";", "}", "}", "}", "return", "$", "key", ";", "}" ]
Search for mapping key @param int|string $key Key that will be used in the search @param array $mappingArray Array of array that has mapping data @return mixed
[ "Search", "for", "mapping", "key" ]
e8729841db66de7de0bdc9ed79ab73fe2bc262c0
https://github.com/arkanmgerges/multi-tier-architecture/blob/e8729841db66de7de0bdc9ed79ab73fe2bc262c0/src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php#L336-L355
12,276
arkanmgerges/multi-tier-architecture
src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php
EntityMapperAbstract.setFirstEntityAttribute
private function setFirstEntityAttribute($entity, $attributeName, $attributeData) { $entityAttribute = $this->mappingSecondEntityToFirstEntityAttributes[$attributeName]; $setterMethod = 'set' . ucfirst($entityAttribute); if (method_exists($entity, $setterMethod)) { $entity->$setterMethod($attributeData); } }
php
private function setFirstEntityAttribute($entity, $attributeName, $attributeData) { $entityAttribute = $this->mappingSecondEntityToFirstEntityAttributes[$attributeName]; $setterMethod = 'set' . ucfirst($entityAttribute); if (method_exists($entity, $setterMethod)) { $entity->$setterMethod($attributeData); } }
[ "private", "function", "setFirstEntityAttribute", "(", "$", "entity", ",", "$", "attributeName", ",", "$", "attributeData", ")", "{", "$", "entityAttribute", "=", "$", "this", "->", "mappingSecondEntityToFirstEntityAttributes", "[", "$", "attributeName", "]", ";", "$", "setterMethod", "=", "'set'", ".", "ucfirst", "(", "$", "entityAttribute", ")", ";", "if", "(", "method_exists", "(", "$", "entity", ",", "$", "setterMethod", ")", ")", "{", "$", "entity", "->", "$", "setterMethod", "(", "$", "attributeData", ")", ";", "}", "}" ]
Set entity attribute based on the attribute name and attribute data @param \MultiTierArchitecture\Entity\Definition\EntityInterface $entity Entity name @param string $attributeName Attribute name of the entity @param mixed $attributeData Attribute data of the entity @return void
[ "Set", "entity", "attribute", "based", "on", "the", "attribute", "name", "and", "attribute", "data" ]
e8729841db66de7de0bdc9ed79ab73fe2bc262c0
https://github.com/arkanmgerges/multi-tier-architecture/blob/e8729841db66de7de0bdc9ed79ab73fe2bc262c0/src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php#L367-L374
12,277
arkanmgerges/multi-tier-architecture
src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php
EntityMapperAbstract.getMappedSecondAttributes
public function getMappedSecondAttributes() { $attributes = []; /* Only the first array in data will be examined, and map its attributes to db attributes, the attributes that are not present, will not be included */ if (is_array($this->data[0])) { foreach ($this->data[0] as $attribute => $attributeValue) { if (array_key_exists($attribute, $this->mappingFirstEntityToSecondEntityAttributes)) { $attributes[$this->mappingFirstEntityToSecondEntityAttributes[$attribute]] = $attributeValue; } } } return $attributes; }
php
public function getMappedSecondAttributes() { $attributes = []; /* Only the first array in data will be examined, and map its attributes to db attributes, the attributes that are not present, will not be included */ if (is_array($this->data[0])) { foreach ($this->data[0] as $attribute => $attributeValue) { if (array_key_exists($attribute, $this->mappingFirstEntityToSecondEntityAttributes)) { $attributes[$this->mappingFirstEntityToSecondEntityAttributes[$attribute]] = $attributeValue; } } } return $attributes; }
[ "public", "function", "getMappedSecondAttributes", "(", ")", "{", "$", "attributes", "=", "[", "]", ";", "/* Only the first array in data will be examined, and map its attributes to db attributes,\n the attributes that are not present, will not be included\n */", "if", "(", "is_array", "(", "$", "this", "->", "data", "[", "0", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "data", "[", "0", "]", "as", "$", "attribute", "=>", "$", "attributeValue", ")", "{", "if", "(", "array_key_exists", "(", "$", "attribute", ",", "$", "this", "->", "mappingFirstEntityToSecondEntityAttributes", ")", ")", "{", "$", "attributes", "[", "$", "this", "->", "mappingFirstEntityToSecondEntityAttributes", "[", "$", "attribute", "]", "]", "=", "$", "attributeValue", ";", "}", "}", "}", "return", "$", "attributes", ";", "}" ]
Get mapped attributes from the 'data' member mapped to second attributes @return array Attributes after mapping them into second attributes
[ "Get", "mapped", "attributes", "from", "the", "data", "member", "mapped", "to", "second", "attributes" ]
e8729841db66de7de0bdc9ed79ab73fe2bc262c0
https://github.com/arkanmgerges/multi-tier-architecture/blob/e8729841db66de7de0bdc9ed79ab73fe2bc262c0/src/MultiTierArchitecture/Mapper/Definition/EntityMapperAbstract.php#L425-L441
12,278
clacy-builders/xml-express-php
src/Attributes.php
Attributes.setBooleanAttrib
public function setBooleanAttrib($name, $value = true, $comparisonAttribute = null) { if (!is_bool($value) && !is_null($comparisonAttribute)) { $compare = $this->getAttrib($comparisonAttribute); if (is_array($value)) { $value = in_array($compare, $value, true); } else { $value = $value === $compare; } } $this->setAttrib($name, $value); }
php
public function setBooleanAttrib($name, $value = true, $comparisonAttribute = null) { if (!is_bool($value) && !is_null($comparisonAttribute)) { $compare = $this->getAttrib($comparisonAttribute); if (is_array($value)) { $value = in_array($compare, $value, true); } else { $value = $value === $compare; } } $this->setAttrib($name, $value); }
[ "public", "function", "setBooleanAttrib", "(", "$", "name", ",", "$", "value", "=", "true", ",", "$", "comparisonAttribute", "=", "null", ")", "{", "if", "(", "!", "is_bool", "(", "$", "value", ")", "&&", "!", "is_null", "(", "$", "comparisonAttribute", ")", ")", "{", "$", "compare", "=", "$", "this", "->", "getAttrib", "(", "$", "comparisonAttribute", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "in_array", "(", "$", "compare", ",", "$", "value", ",", "true", ")", ";", "}", "else", "{", "$", "value", "=", "$", "value", "===", "$", "compare", ";", "}", "}", "$", "this", "->", "setAttrib", "(", "$", "name", ",", "$", "value", ")", ";", "}" ]
Sets a boolean attribute by comparing a value with the value of another attribute. Helpful for attributes like <code>selected</code> in HTML. @param string $name Name of the attribute. @param mixed $value One or more (array) values. @param string $delimiter The boundary string. @param boolean $check Whether multiple entries shall be removed or not.
[ "Sets", "a", "boolean", "attribute", "by", "comparing", "a", "value", "with", "the", "value", "of", "another", "attribute", "." ]
9c66fd640738b0e87b05047c3f3b8f1cba8aa7e0
https://github.com/clacy-builders/xml-express-php/blob/9c66fd640738b0e87b05047c3f3b8f1cba8aa7e0/src/Attributes.php#L86-L98
12,279
clacy-builders/xml-express-php
src/Attributes.php
Attributes.str
public function str() { $str = ''; foreach ($this->attributes as $name => $value) { $str .= $this->getAttribStr($name); } return $str; }
php
public function str() { $str = ''; foreach ($this->attributes as $name => $value) { $str .= $this->getAttribStr($name); } return $str; }
[ "public", "function", "str", "(", ")", "{", "$", "str", "=", "''", ";", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "str", ".=", "$", "this", "->", "getAttribStr", "(", "$", "name", ")", ";", "}", "return", "$", "str", ";", "}" ]
Returns the string representation of all attributes. @return string
[ "Returns", "the", "string", "representation", "of", "all", "attributes", "." ]
9c66fd640738b0e87b05047c3f3b8f1cba8aa7e0
https://github.com/clacy-builders/xml-express-php/blob/9c66fd640738b0e87b05047c3f3b8f1cba8aa7e0/src/Attributes.php#L128-L135
12,280
clacy-builders/xml-express-php
src/Attributes.php
Attributes.getAttribStr
public function getAttribStr($name) { $value = $this->attributes[$name]; if ($value === null || $value === false || $name === null) { return ''; } if ($value === true) { if ($this->element) { $class = get_class($this->element); if ($class::HTML_MODE) { return ' ' . $name; } } $value = $name; } return ' ' . $name . '="' . $value . '"'; }
php
public function getAttribStr($name) { $value = $this->attributes[$name]; if ($value === null || $value === false || $name === null) { return ''; } if ($value === true) { if ($this->element) { $class = get_class($this->element); if ($class::HTML_MODE) { return ' ' . $name; } } $value = $name; } return ' ' . $name . '="' . $value . '"'; }
[ "public", "function", "getAttribStr", "(", "$", "name", ")", "{", "$", "value", "=", "$", "this", "->", "attributes", "[", "$", "name", "]", ";", "if", "(", "$", "value", "===", "null", "||", "$", "value", "===", "false", "||", "$", "name", "===", "null", ")", "{", "return", "''", ";", "}", "if", "(", "$", "value", "===", "true", ")", "{", "if", "(", "$", "this", "->", "element", ")", "{", "$", "class", "=", "get_class", "(", "$", "this", "->", "element", ")", ";", "if", "(", "$", "class", "::", "HTML_MODE", ")", "{", "return", "' '", ".", "$", "name", ";", "}", "}", "$", "value", "=", "$", "name", ";", "}", "return", "' '", ".", "$", "name", ".", "'=\"'", ".", "$", "value", ".", "'\"'", ";", "}" ]
Returns the string representation of a single attribute. @param string $name Name of the attribute. @return string
[ "Returns", "the", "string", "representation", "of", "a", "single", "attribute", "." ]
9c66fd640738b0e87b05047c3f3b8f1cba8aa7e0
https://github.com/clacy-builders/xml-express-php/blob/9c66fd640738b0e87b05047c3f3b8f1cba8aa7e0/src/Attributes.php#L143-L159
12,281
TagPlanet/universal-analytics
src/TagPlanet/UniversalAnalytics/UniversalAnalytics.php
UniversalAnalytics.get
public function get($name) { if($name == '') { // If no name was passed, we'll assume they wanted the first (and usually only) if(count($this->instances) == 1) { // Grab the instance without knowing tracker name $instances = array_values($this->instances); return array_shift($instances); } // More or less than one instances throw new InvalidArgumentException('Unspecified Universal Analytics tracker name'); } // Positive look up on the tracker name? if(isset($this->instances[$name])) return $this->instances[$name]; // No UA instance with that tracker name! Are you sure? throw new Exception('Universal Analytics instance for "' . $name . '" doesn\'t exist'); }
php
public function get($name) { if($name == '') { // If no name was passed, we'll assume they wanted the first (and usually only) if(count($this->instances) == 1) { // Grab the instance without knowing tracker name $instances = array_values($this->instances); return array_shift($instances); } // More or less than one instances throw new InvalidArgumentException('Unspecified Universal Analytics tracker name'); } // Positive look up on the tracker name? if(isset($this->instances[$name])) return $this->instances[$name]; // No UA instance with that tracker name! Are you sure? throw new Exception('Universal Analytics instance for "' . $name . '" doesn\'t exist'); }
[ "public", "function", "get", "(", "$", "name", ")", "{", "if", "(", "$", "name", "==", "''", ")", "{", "// If no name was passed, we'll assume they wanted the first (and usually only)", "if", "(", "count", "(", "$", "this", "->", "instances", ")", "==", "1", ")", "{", "// Grab the instance without knowing tracker name", "$", "instances", "=", "array_values", "(", "$", "this", "->", "instances", ")", ";", "return", "array_shift", "(", "$", "instances", ")", ";", "}", "// More or less than one instances", "throw", "new", "InvalidArgumentException", "(", "'Unspecified Universal Analytics tracker name'", ")", ";", "}", "// Positive look up on the tracker name?", "if", "(", "isset", "(", "$", "this", "->", "instances", "[", "$", "name", "]", ")", ")", "return", "$", "this", "->", "instances", "[", "$", "name", "]", ";", "// No UA instance with that tracker name! Are you sure?", "throw", "new", "Exception", "(", "'Universal Analytics instance for \"'", ".", "$", "name", ".", "'\" doesn\\'t exist'", ")", ";", "}" ]
Find a single tracker instance @return TagPlanet\UniversalAnalytics\UniversalAnalyticsInstance
[ "Find", "a", "single", "tracker", "instance" ]
0b370fd8d20397e585a550d86f6fb9ccb9e1c783
https://github.com/TagPlanet/universal-analytics/blob/0b370fd8d20397e585a550d86f6fb9ccb9e1c783/src/TagPlanet/UniversalAnalytics/UniversalAnalytics.php#L101-L123
12,282
TagPlanet/universal-analytics
src/TagPlanet/UniversalAnalytics/UniversalAnalytics.php
UniversalAnalytics.create
protected function create($account, $config = array()) { if(!isset($config['name'])) { // This shouldn't happen anymore... but just in case, force it! $config['name'] = 't' . count($this->instances); } // Grab overall config options $debug = $this->debug; $autoPageview = $this->autoPageview; // Finally, make a new instance $this->instances[$config['name']] = new UniversalAnalyticsInstance($account, $config, $debug, $autoPageview); // Return the newly created instance return $this->instances[$config['name']]; }
php
protected function create($account, $config = array()) { if(!isset($config['name'])) { // This shouldn't happen anymore... but just in case, force it! $config['name'] = 't' . count($this->instances); } // Grab overall config options $debug = $this->debug; $autoPageview = $this->autoPageview; // Finally, make a new instance $this->instances[$config['name']] = new UniversalAnalyticsInstance($account, $config, $debug, $autoPageview); // Return the newly created instance return $this->instances[$config['name']]; }
[ "protected", "function", "create", "(", "$", "account", ",", "$", "config", "=", "array", "(", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "config", "[", "'name'", "]", ")", ")", "{", "// This shouldn't happen anymore... but just in case, force it!", "$", "config", "[", "'name'", "]", "=", "'t'", ".", "count", "(", "$", "this", "->", "instances", ")", ";", "}", "// Grab overall config options", "$", "debug", "=", "$", "this", "->", "debug", ";", "$", "autoPageview", "=", "$", "this", "->", "autoPageview", ";", "// Finally, make a new instance", "$", "this", "->", "instances", "[", "$", "config", "[", "'name'", "]", "]", "=", "new", "UniversalAnalyticsInstance", "(", "$", "account", ",", "$", "config", ",", "$", "debug", ",", "$", "autoPageview", ")", ";", "// Return the newly created instance", "return", "$", "this", "->", "instances", "[", "$", "config", "[", "'name'", "]", "]", ";", "}" ]
Create a new tracker instance, or update an existing a new config @return TagPlanet\UniversalAnalytics\UniversalAnalyticsInstance
[ "Create", "a", "new", "tracker", "instance", "or", "update", "an", "existing", "a", "new", "config" ]
0b370fd8d20397e585a550d86f6fb9ccb9e1c783
https://github.com/TagPlanet/universal-analytics/blob/0b370fd8d20397e585a550d86f6fb9ccb9e1c783/src/TagPlanet/UniversalAnalytics/UniversalAnalytics.php#L130-L147
12,283
TagPlanet/universal-analytics
src/TagPlanet/UniversalAnalytics/UniversalAnalytics.php
UniversalAnalytics.render
public function render($renderedCodeBlock = true, $renderScriptTag = true) { // Setup our return array $js = array(); // Do we need to add script tags? if($renderScriptTag) $js[] = '<script>'; foreach($this->instances as $instance) { // Since we could have multiple trackers, we'll want to grab each render $js[] = $instance->render($renderedCodeBlock, false) . PHP_EOL; // Make sure we only render the UA code block once $renderedCodeBlock = false; } // Do we need to add script tags? if($renderScriptTag) $js[] = '</script>'; // Return our combined render return implode(PHP_EOL, $js); }
php
public function render($renderedCodeBlock = true, $renderScriptTag = true) { // Setup our return array $js = array(); // Do we need to add script tags? if($renderScriptTag) $js[] = '<script>'; foreach($this->instances as $instance) { // Since we could have multiple trackers, we'll want to grab each render $js[] = $instance->render($renderedCodeBlock, false) . PHP_EOL; // Make sure we only render the UA code block once $renderedCodeBlock = false; } // Do we need to add script tags? if($renderScriptTag) $js[] = '</script>'; // Return our combined render return implode(PHP_EOL, $js); }
[ "public", "function", "render", "(", "$", "renderedCodeBlock", "=", "true", ",", "$", "renderScriptTag", "=", "true", ")", "{", "// Setup our return array", "$", "js", "=", "array", "(", ")", ";", "// Do we need to add script tags?", "if", "(", "$", "renderScriptTag", ")", "$", "js", "[", "]", "=", "'<script>'", ";", "foreach", "(", "$", "this", "->", "instances", "as", "$", "instance", ")", "{", "// Since we could have multiple trackers, we'll want to grab each render", "$", "js", "[", "]", "=", "$", "instance", "->", "render", "(", "$", "renderedCodeBlock", ",", "false", ")", ".", "PHP_EOL", ";", "// Make sure we only render the UA code block once", "$", "renderedCodeBlock", "=", "false", ";", "}", "// Do we need to add script tags?", "if", "(", "$", "renderScriptTag", ")", "$", "js", "[", "]", "=", "'</script>'", ";", "// Return our combined render", "return", "implode", "(", "PHP_EOL", ",", "$", "js", ")", ";", "}" ]
Render the Universal Analytics code @return string
[ "Render", "the", "Universal", "Analytics", "code" ]
0b370fd8d20397e585a550d86f6fb9ccb9e1c783
https://github.com/TagPlanet/universal-analytics/blob/0b370fd8d20397e585a550d86f6fb9ccb9e1c783/src/TagPlanet/UniversalAnalytics/UniversalAnalytics.php#L154-L178
12,284
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/validation/error.php
Validation_Error._replace_tags
protected function _replace_tags($msg) { // prepare label & value $label = is_array($this->field->label) ? $this->field->label['label'] : $this->field->label; $value = is_array($this->value) ? implode(', ', $this->value) : $this->value; if (\Config::get('validation.quote_labels', false) and strpos($label, ' ') !== false) { // put the label in quotes if it contains spaces $label = '"'.$label.'"'; } // setup find & replace arrays $find = array(':field', ':label', ':value', ':rule'); $replace = array($this->field->name, $label, $value, $this->rule); // add the params to the find & replace arrays foreach($this->params as $key => $val) { // Convert array (as far as possible) if (is_array($val)) { $result = ''; foreach ($val as $v) { if (is_array($v)) { $v = '(array)'; } elseif (is_object($v)) { $v = '(object)'; } elseif (is_bool($v)) { $v = $v ? 'true' : 'false'; } $result .= empty($result) ? $v : (', '.$v); } $val = $result; } elseif (is_bool($val)) { $val = $val ? 'true' : 'false'; } // Convert object with __toString or just the classname elseif (is_object($val)) { $val = method_exists($val, '__toString') ? (string) $val : get_class($val); } $find[] = ':param:'.($key + 1); $replace[] = $val; } // execute find & replace and return return str_replace($find, $replace, $msg); }
php
protected function _replace_tags($msg) { // prepare label & value $label = is_array($this->field->label) ? $this->field->label['label'] : $this->field->label; $value = is_array($this->value) ? implode(', ', $this->value) : $this->value; if (\Config::get('validation.quote_labels', false) and strpos($label, ' ') !== false) { // put the label in quotes if it contains spaces $label = '"'.$label.'"'; } // setup find & replace arrays $find = array(':field', ':label', ':value', ':rule'); $replace = array($this->field->name, $label, $value, $this->rule); // add the params to the find & replace arrays foreach($this->params as $key => $val) { // Convert array (as far as possible) if (is_array($val)) { $result = ''; foreach ($val as $v) { if (is_array($v)) { $v = '(array)'; } elseif (is_object($v)) { $v = '(object)'; } elseif (is_bool($v)) { $v = $v ? 'true' : 'false'; } $result .= empty($result) ? $v : (', '.$v); } $val = $result; } elseif (is_bool($val)) { $val = $val ? 'true' : 'false'; } // Convert object with __toString or just the classname elseif (is_object($val)) { $val = method_exists($val, '__toString') ? (string) $val : get_class($val); } $find[] = ':param:'.($key + 1); $replace[] = $val; } // execute find & replace and return return str_replace($find, $replace, $msg); }
[ "protected", "function", "_replace_tags", "(", "$", "msg", ")", "{", "// prepare label & value", "$", "label", "=", "is_array", "(", "$", "this", "->", "field", "->", "label", ")", "?", "$", "this", "->", "field", "->", "label", "[", "'label'", "]", ":", "$", "this", "->", "field", "->", "label", ";", "$", "value", "=", "is_array", "(", "$", "this", "->", "value", ")", "?", "implode", "(", "', '", ",", "$", "this", "->", "value", ")", ":", "$", "this", "->", "value", ";", "if", "(", "\\", "Config", "::", "get", "(", "'validation.quote_labels'", ",", "false", ")", "and", "strpos", "(", "$", "label", ",", "' '", ")", "!==", "false", ")", "{", "// put the label in quotes if it contains spaces", "$", "label", "=", "'\"'", ".", "$", "label", ".", "'\"'", ";", "}", "// setup find & replace arrays", "$", "find", "=", "array", "(", "':field'", ",", "':label'", ",", "':value'", ",", "':rule'", ")", ";", "$", "replace", "=", "array", "(", "$", "this", "->", "field", "->", "name", ",", "$", "label", ",", "$", "value", ",", "$", "this", "->", "rule", ")", ";", "// add the params to the find & replace arrays", "foreach", "(", "$", "this", "->", "params", "as", "$", "key", "=>", "$", "val", ")", "{", "// Convert array (as far as possible)", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "result", "=", "''", ";", "foreach", "(", "$", "val", "as", "$", "v", ")", "{", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "$", "v", "=", "'(array)'", ";", "}", "elseif", "(", "is_object", "(", "$", "v", ")", ")", "{", "$", "v", "=", "'(object)'", ";", "}", "elseif", "(", "is_bool", "(", "$", "v", ")", ")", "{", "$", "v", "=", "$", "v", "?", "'true'", ":", "'false'", ";", "}", "$", "result", ".=", "empty", "(", "$", "result", ")", "?", "$", "v", ":", "(", "', '", ".", "$", "v", ")", ";", "}", "$", "val", "=", "$", "result", ";", "}", "elseif", "(", "is_bool", "(", "$", "val", ")", ")", "{", "$", "val", "=", "$", "val", "?", "'true'", ":", "'false'", ";", "}", "// Convert object with __toString or just the classname", "elseif", "(", "is_object", "(", "$", "val", ")", ")", "{", "$", "val", "=", "method_exists", "(", "$", "val", ",", "'__toString'", ")", "?", "(", "string", ")", "$", "val", ":", "get_class", "(", "$", "val", ")", ";", "}", "$", "find", "[", "]", "=", "':param:'", ".", "(", "$", "key", "+", "1", ")", ";", "$", "replace", "[", "]", "=", "$", "val", ";", "}", "// execute find & replace and return", "return", "str_replace", "(", "$", "find", ",", "$", "replace", ",", "$", "msg", ")", ";", "}" ]
Replace templating tags with values @param error message to parse @return string
[ "Replace", "templating", "tags", "with", "values" ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/validation/error.php#L113-L169
12,285
odtimetracker/odtimetracker-php-lib
src/Model/AbstractMapper.php
AbstractMapper.selectById
public function selectById($id) { $sql = "SELECT * FROM `$this->tableName` WHERE `$this->pkColName` = %d "; $stmt = $this->pdo->prepare(sprintf($sql, $id)); $res = $stmt->execute(); if ($res === false) { return null; } $rows = $stmt->fetchAll(); if (count($rows) !== 1) { return null; } return $this->prepareEntity($rows[0]); }
php
public function selectById($id) { $sql = "SELECT * FROM `$this->tableName` WHERE `$this->pkColName` = %d "; $stmt = $this->pdo->prepare(sprintf($sql, $id)); $res = $stmt->execute(); if ($res === false) { return null; } $rows = $stmt->fetchAll(); if (count($rows) !== 1) { return null; } return $this->prepareEntity($rows[0]); }
[ "public", "function", "selectById", "(", "$", "id", ")", "{", "$", "sql", "=", "\"SELECT * FROM `$this->tableName` WHERE `$this->pkColName` = %d \"", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "sprintf", "(", "$", "sql", ",", "$", "id", ")", ")", ";", "$", "res", "=", "$", "stmt", "->", "execute", "(", ")", ";", "if", "(", "$", "res", "===", "false", ")", "{", "return", "null", ";", "}", "$", "rows", "=", "$", "stmt", "->", "fetchAll", "(", ")", ";", "if", "(", "count", "(", "$", "rows", ")", "!==", "1", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "prepareEntity", "(", "$", "rows", "[", "0", "]", ")", ";", "}" ]
Select entity by its ID. @param integer $id @return EntityInterface|null
[ "Select", "entity", "by", "its", "ID", "." ]
0bb9081fea8b921241a53c46785441696022590d
https://github.com/odtimetracker/odtimetracker-php-lib/blob/0bb9081fea8b921241a53c46785441696022590d/src/Model/AbstractMapper.php#L59-L76
12,286
odtimetracker/odtimetracker-php-lib
src/Model/AbstractMapper.php
AbstractMapper.deleteById
public function deleteById($id) { $sql = "DELETE FROM `$this->tableName` WHERE `$this->pkColName` = :entityId "; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':entityId', intval($id), \PDO::PARAM_INT); $res = $stmt->execute(); return ($res !== false && $stmt->rowCount() === 1); }
php
public function deleteById($id) { $sql = "DELETE FROM `$this->tableName` WHERE `$this->pkColName` = :entityId "; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':entityId', intval($id), \PDO::PARAM_INT); $res = $stmt->execute(); return ($res !== false && $stmt->rowCount() === 1); }
[ "public", "function", "deleteById", "(", "$", "id", ")", "{", "$", "sql", "=", "\"DELETE FROM `$this->tableName` WHERE `$this->pkColName` = :entityId \"", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "sql", ")", ";", "$", "stmt", "->", "bindParam", "(", "':entityId'", ",", "intval", "(", "$", "id", ")", ",", "\\", "PDO", "::", "PARAM_INT", ")", ";", "$", "res", "=", "$", "stmt", "->", "execute", "(", ")", ";", "return", "(", "$", "res", "!==", "false", "&&", "$", "stmt", "->", "rowCount", "(", ")", "===", "1", ")", ";", "}" ]
Delete record by its identifier. @param integer $id @return boolean
[ "Delete", "record", "by", "its", "identifier", "." ]
0bb9081fea8b921241a53c46785441696022590d
https://github.com/odtimetracker/odtimetracker-php-lib/blob/0bb9081fea8b921241a53c46785441696022590d/src/Model/AbstractMapper.php#L111-L120
12,287
uthando-cms/uthando-twitter
src/UthandoTwitter/View/TweetFeed.php
TweetFeed.setPartial
public function setPartial($partial) { if (null === $partial || is_string($partial) || is_array($partial)) { $this->partial = $partial; } return $this; }
php
public function setPartial($partial) { if (null === $partial || is_string($partial) || is_array($partial)) { $this->partial = $partial; } return $this; }
[ "public", "function", "setPartial", "(", "$", "partial", ")", "{", "if", "(", "null", "===", "$", "partial", "||", "is_string", "(", "$", "partial", ")", "||", "is_array", "(", "$", "partial", ")", ")", "{", "$", "this", "->", "partial", "=", "$", "partial", ";", "}", "return", "$", "this", ";", "}" ]
Sets which partial view script to use for rendering tweets @param string|array $partial @return \UthandoTwitter\View\TweetFeed
[ "Sets", "which", "partial", "view", "script", "to", "use", "for", "rendering", "tweets" ]
003914b2df2255d52314ed8eb5c92f192dab0f12
https://github.com/uthando-cms/uthando-twitter/blob/003914b2df2255d52314ed8eb5c92f192dab0f12/src/UthandoTwitter/View/TweetFeed.php#L89-L96
12,288
uthando-cms/uthando-twitter
src/UthandoTwitter/View/TweetFeed.php
TweetFeed.getTwitter
public function getTwitter() { if (!$this->twitter) { $this->twitter = $this->getServiceLocator() ->getServiceLocator() ->get(Twitter::class); } return $this->twitter; }
php
public function getTwitter() { if (!$this->twitter) { $this->twitter = $this->getServiceLocator() ->getServiceLocator() ->get(Twitter::class); } return $this->twitter; }
[ "public", "function", "getTwitter", "(", ")", "{", "if", "(", "!", "$", "this", "->", "twitter", ")", "{", "$", "this", "->", "twitter", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "getServiceLocator", "(", ")", "->", "get", "(", "Twitter", "::", "class", ")", ";", "}", "return", "$", "this", "->", "twitter", ";", "}" ]
Gets the twitter instance @return \UthandoTwitter\Service\Twitter
[ "Gets", "the", "twitter", "instance" ]
003914b2df2255d52314ed8eb5c92f192dab0f12
https://github.com/uthando-cms/uthando-twitter/blob/003914b2df2255d52314ed8eb5c92f192dab0f12/src/UthandoTwitter/View/TweetFeed.php#L144-L153
12,289
mimmi20/modernizr-server
src/Modernizr.php
Modernizr.getData
public static function getData($key = self::KEY, $cookieExtra = '') { if (!empty(self::$data)) { return self::$data; } $key .= $cookieExtra; if (PHP_SESSION_ACTIVE === session_status() && isset($_SESSION[$key])) { self::$data = $_SESSION[$key]; return self::$data; } if (isset($_COOKIE) && isset($_COOKIE[$key])) { self::$data = self::ang($_COOKIE[$key]); if (isset($_SESSION)) { $_SESSION[$key] = self::$data; } return self::$data; } return null; }
php
public static function getData($key = self::KEY, $cookieExtra = '') { if (!empty(self::$data)) { return self::$data; } $key .= $cookieExtra; if (PHP_SESSION_ACTIVE === session_status() && isset($_SESSION[$key])) { self::$data = $_SESSION[$key]; return self::$data; } if (isset($_COOKIE) && isset($_COOKIE[$key])) { self::$data = self::ang($_COOKIE[$key]); if (isset($_SESSION)) { $_SESSION[$key] = self::$data; } return self::$data; } return null; }
[ "public", "static", "function", "getData", "(", "$", "key", "=", "self", "::", "KEY", ",", "$", "cookieExtra", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "self", "::", "$", "data", ")", ")", "{", "return", "self", "::", "$", "data", ";", "}", "$", "key", ".=", "$", "cookieExtra", ";", "if", "(", "PHP_SESSION_ACTIVE", "===", "session_status", "(", ")", "&&", "isset", "(", "$", "_SESSION", "[", "$", "key", "]", ")", ")", "{", "self", "::", "$", "data", "=", "$", "_SESSION", "[", "$", "key", "]", ";", "return", "self", "::", "$", "data", ";", "}", "if", "(", "isset", "(", "$", "_COOKIE", ")", "&&", "isset", "(", "$", "_COOKIE", "[", "$", "key", "]", ")", ")", "{", "self", "::", "$", "data", "=", "self", "::", "ang", "(", "$", "_COOKIE", "[", "$", "key", "]", ")", ";", "if", "(", "isset", "(", "$", "_SESSION", ")", ")", "{", "$", "_SESSION", "[", "$", "key", "]", "=", "self", "::", "$", "data", ";", "}", "return", "self", "::", "$", "data", ";", "}", "return", "null", ";", "}" ]
returns the data @param string $key @param string $cookieExtra @return array|null
[ "returns", "the", "data" ]
1143f4f62c7d473657d1d461338208a01b16e57e
https://github.com/mimmi20/modernizr-server/blob/1143f4f62c7d473657d1d461338208a01b16e57e/src/Modernizr.php#L367-L392
12,290
mimmi20/modernizr-server
src/Modernizr.php
Modernizr.buildJsCode
public static function buildJsCode($cookieExtra = '') { $js = self::buildJs(); $js .= self::buildConvertJs(self::KEY, $cookieExtra, true); return $js; }
php
public static function buildJsCode($cookieExtra = '') { $js = self::buildJs(); $js .= self::buildConvertJs(self::KEY, $cookieExtra, true); return $js; }
[ "public", "static", "function", "buildJsCode", "(", "$", "cookieExtra", "=", "''", ")", "{", "$", "js", "=", "self", "::", "buildJs", "(", ")", ";", "$", "js", ".=", "self", "::", "buildConvertJs", "(", "self", "::", "KEY", ",", "$", "cookieExtra", ",", "true", ")", ";", "return", "$", "js", ";", "}" ]
builds the complete javascript code to output modernizr.js, new checkes and to write the detection result into the session @param string $cookieExtra @return string
[ "builds", "the", "complete", "javascript", "code", "to", "output", "modernizr", ".", "js", "new", "checkes", "and", "to", "write", "the", "detection", "result", "into", "the", "session" ]
1143f4f62c7d473657d1d461338208a01b16e57e
https://github.com/mimmi20/modernizr-server/blob/1143f4f62c7d473657d1d461338208a01b16e57e/src/Modernizr.php#L402-L408
12,291
mimmi20/modernizr-server
src/Modernizr.php
Modernizr.buildJs
public static function buildJs() { $js = ''; foreach (self::collectJsFiles() as $file) { $js .= file_get_contents(__DIR__ . '/../web' . $file); } return $js; }
php
public static function buildJs() { $js = ''; foreach (self::collectJsFiles() as $file) { $js .= file_get_contents(__DIR__ . '/../web' . $file); } return $js; }
[ "public", "static", "function", "buildJs", "(", ")", "{", "$", "js", "=", "''", ";", "foreach", "(", "self", "::", "collectJsFiles", "(", ")", "as", "$", "file", ")", "{", "$", "js", ".=", "file_get_contents", "(", "__DIR__", ".", "'/../web'", ".", "$", "file", ")", ";", "}", "return", "$", "js", ";", "}" ]
builds the javascript code to output modernizr.js and new checkes @return string
[ "builds", "the", "javascript", "code", "to", "output", "modernizr", ".", "js", "and", "new", "checkes" ]
1143f4f62c7d473657d1d461338208a01b16e57e
https://github.com/mimmi20/modernizr-server/blob/1143f4f62c7d473657d1d461338208a01b16e57e/src/Modernizr.php#L415-L424
12,292
mimmi20/modernizr-server
src/Modernizr.php
Modernizr.buildConvertJs
public static function buildConvertJs($key, $cookieExtra = '', $reload = true) { $content = file_get_contents(__DIR__ . '/../web/convert/start.js.tmp'); ksort(self::$properties); foreach (array_keys(self::$properties) as $i => $property) { if (is_array(self::$properties[$property])) { $content .= str_replace( ['$propertykey', '$property'], [$property, $property], file_get_contents(__DIR__ . '/../web/convert/base-group-start.js.tmp') ); ksort(self::$properties[$property]); foreach (array_keys(self::$properties[$property]) as $j => $subproperty) { $content .= str_replace( ['$property', '$subpropertykey', '$subproperty'], [$property, self::$properties[$property][$subproperty], $subproperty], file_get_contents(__DIR__ . '/../web/convert/base-groupbase.js.tmp') ); if ($j < count(self::$properties[$property]) - 1) { $content .= ','; } $content .= "\n"; } $content .= str_replace( '$property', $property, file_get_contents(__DIR__ . '/../web/convert/base-group-end.js.tmp') ); } else { $content .= str_replace( ['$propertykey', '$property'], [self::$properties[$property], $property], file_get_contents(__DIR__ . '/../web/convert/base-single.js.tmp') ); } if ($i < count(self::$properties) - 1) { $content .= ','; } $content .= "\n"; } $content .= file_get_contents(__DIR__ . '/../web/convert/end.js.tmp'); return str_replace( ['###Modernizr###', '###EXTRA###', 'reload = false'], [$key, $cookieExtra, ($reload ? 'reload = true' : 'reload = false')], $content ); }
php
public static function buildConvertJs($key, $cookieExtra = '', $reload = true) { $content = file_get_contents(__DIR__ . '/../web/convert/start.js.tmp'); ksort(self::$properties); foreach (array_keys(self::$properties) as $i => $property) { if (is_array(self::$properties[$property])) { $content .= str_replace( ['$propertykey', '$property'], [$property, $property], file_get_contents(__DIR__ . '/../web/convert/base-group-start.js.tmp') ); ksort(self::$properties[$property]); foreach (array_keys(self::$properties[$property]) as $j => $subproperty) { $content .= str_replace( ['$property', '$subpropertykey', '$subproperty'], [$property, self::$properties[$property][$subproperty], $subproperty], file_get_contents(__DIR__ . '/../web/convert/base-groupbase.js.tmp') ); if ($j < count(self::$properties[$property]) - 1) { $content .= ','; } $content .= "\n"; } $content .= str_replace( '$property', $property, file_get_contents(__DIR__ . '/../web/convert/base-group-end.js.tmp') ); } else { $content .= str_replace( ['$propertykey', '$property'], [self::$properties[$property], $property], file_get_contents(__DIR__ . '/../web/convert/base-single.js.tmp') ); } if ($i < count(self::$properties) - 1) { $content .= ','; } $content .= "\n"; } $content .= file_get_contents(__DIR__ . '/../web/convert/end.js.tmp'); return str_replace( ['###Modernizr###', '###EXTRA###', 'reload = false'], [$key, $cookieExtra, ($reload ? 'reload = true' : 'reload = false')], $content ); }
[ "public", "static", "function", "buildConvertJs", "(", "$", "key", ",", "$", "cookieExtra", "=", "''", ",", "$", "reload", "=", "true", ")", "{", "$", "content", "=", "file_get_contents", "(", "__DIR__", ".", "'/../web/convert/start.js.tmp'", ")", ";", "ksort", "(", "self", "::", "$", "properties", ")", ";", "foreach", "(", "array_keys", "(", "self", "::", "$", "properties", ")", "as", "$", "i", "=>", "$", "property", ")", "{", "if", "(", "is_array", "(", "self", "::", "$", "properties", "[", "$", "property", "]", ")", ")", "{", "$", "content", ".=", "str_replace", "(", "[", "'$propertykey'", ",", "'$property'", "]", ",", "[", "$", "property", ",", "$", "property", "]", ",", "file_get_contents", "(", "__DIR__", ".", "'/../web/convert/base-group-start.js.tmp'", ")", ")", ";", "ksort", "(", "self", "::", "$", "properties", "[", "$", "property", "]", ")", ";", "foreach", "(", "array_keys", "(", "self", "::", "$", "properties", "[", "$", "property", "]", ")", "as", "$", "j", "=>", "$", "subproperty", ")", "{", "$", "content", ".=", "str_replace", "(", "[", "'$property'", ",", "'$subpropertykey'", ",", "'$subproperty'", "]", ",", "[", "$", "property", ",", "self", "::", "$", "properties", "[", "$", "property", "]", "[", "$", "subproperty", "]", ",", "$", "subproperty", "]", ",", "file_get_contents", "(", "__DIR__", ".", "'/../web/convert/base-groupbase.js.tmp'", ")", ")", ";", "if", "(", "$", "j", "<", "count", "(", "self", "::", "$", "properties", "[", "$", "property", "]", ")", "-", "1", ")", "{", "$", "content", ".=", "','", ";", "}", "$", "content", ".=", "\"\\n\"", ";", "}", "$", "content", ".=", "str_replace", "(", "'$property'", ",", "$", "property", ",", "file_get_contents", "(", "__DIR__", ".", "'/../web/convert/base-group-end.js.tmp'", ")", ")", ";", "}", "else", "{", "$", "content", ".=", "str_replace", "(", "[", "'$propertykey'", ",", "'$property'", "]", ",", "[", "self", "::", "$", "properties", "[", "$", "property", "]", ",", "$", "property", "]", ",", "file_get_contents", "(", "__DIR__", ".", "'/../web/convert/base-single.js.tmp'", ")", ")", ";", "}", "if", "(", "$", "i", "<", "count", "(", "self", "::", "$", "properties", ")", "-", "1", ")", "{", "$", "content", ".=", "','", ";", "}", "$", "content", ".=", "\"\\n\"", ";", "}", "$", "content", ".=", "file_get_contents", "(", "__DIR__", ".", "'/../web/convert/end.js.tmp'", ")", ";", "return", "str_replace", "(", "[", "'###Modernizr###'", ",", "'###EXTRA###'", ",", "'reload = false'", "]", ",", "[", "$", "key", ",", "$", "cookieExtra", ",", "(", "$", "reload", "?", "'reload = true'", ":", "'reload = false'", ")", "]", ",", "$", "content", ")", ";", "}" ]
builds the javascript code to write the detection result into a cookie @param string $key @param string $cookieExtra @param bool $reload @return string
[ "builds", "the", "javascript", "code", "to", "write", "the", "detection", "result", "into", "a", "cookie" ]
1143f4f62c7d473657d1d461338208a01b16e57e
https://github.com/mimmi20/modernizr-server/blob/1143f4f62c7d473657d1d461338208a01b16e57e/src/Modernizr.php#L455-L514
12,293
mimmi20/modernizr-server
src/Modernizr.php
Modernizr.ang
private static function ang($cookie) { $data = new \stdClass(); $features = json_decode($cookie); var_dump($cookie, $features);exit; return $data; }
php
private static function ang($cookie) { $data = new \stdClass(); $features = json_decode($cookie); var_dump($cookie, $features);exit; return $data; }
[ "private", "static", "function", "ang", "(", "$", "cookie", ")", "{", "$", "data", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "features", "=", "json_decode", "(", "$", "cookie", ")", ";", "var_dump", "(", "$", "cookie", ",", "$", "features", ")", ";", "exit", ";", "return", "$", "data", ";", "}" ]
extracts the feature data from the cookie @param string $cookie @return \stdClass
[ "extracts", "the", "feature", "data", "from", "the", "cookie" ]
1143f4f62c7d473657d1d461338208a01b16e57e
https://github.com/mimmi20/modernizr-server/blob/1143f4f62c7d473657d1d461338208a01b16e57e/src/Modernizr.php#L523-L531
12,294
kuria/clock
src/Clock.php
Clock.override
static function override($now): void { if ($now instanceof \DateTimeInterface) { $now = $now->getTimestamp() + ($now->format('u') / 1e6); // extract timestamp with microseconds } elseif (!is_int($now) && !is_float($now)) { throw new \InvalidArgumentException(sprintf( 'Expected int, float or an instance of DateTimeInterface, but got %s', is_object($now) ? get_class($now) : gettype($now) )); } self::$now = $now; }
php
static function override($now): void { if ($now instanceof \DateTimeInterface) { $now = $now->getTimestamp() + ($now->format('u') / 1e6); // extract timestamp with microseconds } elseif (!is_int($now) && !is_float($now)) { throw new \InvalidArgumentException(sprintf( 'Expected int, float or an instance of DateTimeInterface, but got %s', is_object($now) ? get_class($now) : gettype($now) )); } self::$now = $now; }
[ "static", "function", "override", "(", "$", "now", ")", ":", "void", "{", "if", "(", "$", "now", "instanceof", "\\", "DateTimeInterface", ")", "{", "$", "now", "=", "$", "now", "->", "getTimestamp", "(", ")", "+", "(", "$", "now", "->", "format", "(", "'u'", ")", "/", "1e6", ")", ";", "// extract timestamp with microseconds", "}", "elseif", "(", "!", "is_int", "(", "$", "now", ")", "&&", "!", "is_float", "(", "$", "now", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Expected int, float or an instance of DateTimeInterface, but got %s'", ",", "is_object", "(", "$", "now", ")", "?", "get_class", "(", "$", "now", ")", ":", "gettype", "(", "$", "now", ")", ")", ")", ";", "}", "self", "::", "$", "now", "=", "$", "now", ";", "}" ]
Override the current time - this change only affects methods of this class - this method is intended to be used only for testing purposes - the new time can include microseconds @see Clock::resume() @param \DateTimeInterface|int|float $now UNIX timestamp or \DateTimeInterface instance @throws \InvalidArgumentException if $now does not have a valid type
[ "Override", "the", "current", "time" ]
591468bdb175e230f7cc81b8c472fcc2bcfeb938
https://github.com/kuria/clock/blob/591468bdb175e230f7cc81b8c472fcc2bcfeb938/src/Clock.php#L25-L37
12,295
kuria/clock
src/Clock.php
Clock.microtime
static function microtime(): float { if (self::$now !== null) { return (float) self::$now; } return microtime(true); }
php
static function microtime(): float { if (self::$now !== null) { return (float) self::$now; } return microtime(true); }
[ "static", "function", "microtime", "(", ")", ":", "float", "{", "if", "(", "self", "::", "$", "now", "!==", "null", ")", "{", "return", "(", "float", ")", "self", "::", "$", "now", ";", "}", "return", "microtime", "(", "true", ")", ";", "}" ]
Get the current UNIX timestamp with microsecond precision
[ "Get", "the", "current", "UNIX", "timestamp", "with", "microsecond", "precision" ]
591468bdb175e230f7cc81b8c472fcc2bcfeb938
https://github.com/kuria/clock/blob/591468bdb175e230f7cc81b8c472fcc2bcfeb938/src/Clock.php#L76-L83
12,296
kuria/clock
src/Clock.php
Clock.dateTime
static function dateTime(?\DateTimeZone $timezone = null): \DateTime { if (self::$now !== null) { $now = \DateTime::createFromFormat('U.u', sprintf('%.6F', self::$now)); $now->setTimezone($timezone ?? new \DateTimeZone(date_default_timezone_get())); return $now; } return new \DateTime('now', $timezone); }
php
static function dateTime(?\DateTimeZone $timezone = null): \DateTime { if (self::$now !== null) { $now = \DateTime::createFromFormat('U.u', sprintf('%.6F', self::$now)); $now->setTimezone($timezone ?? new \DateTimeZone(date_default_timezone_get())); return $now; } return new \DateTime('now', $timezone); }
[ "static", "function", "dateTime", "(", "?", "\\", "DateTimeZone", "$", "timezone", "=", "null", ")", ":", "\\", "DateTime", "{", "if", "(", "self", "::", "$", "now", "!==", "null", ")", "{", "$", "now", "=", "\\", "DateTime", "::", "createFromFormat", "(", "'U.u'", ",", "sprintf", "(", "'%.6F'", ",", "self", "::", "$", "now", ")", ")", ";", "$", "now", "->", "setTimezone", "(", "$", "timezone", "??", "new", "\\", "DateTimeZone", "(", "date_default_timezone_get", "(", ")", ")", ")", ";", "return", "$", "now", ";", "}", "return", "new", "\\", "DateTime", "(", "'now'", ",", "$", "timezone", ")", ";", "}" ]
Get the current date-time If no time zone is specified, then the default time zone will be used. The default time zone is specified by the date.timezone INI setting or the date_default_timezone_set() function.
[ "Get", "the", "current", "date", "-", "time" ]
591468bdb175e230f7cc81b8c472fcc2bcfeb938
https://github.com/kuria/clock/blob/591468bdb175e230f7cc81b8c472fcc2bcfeb938/src/Clock.php#L92-L102
12,297
kuria/clock
src/Clock.php
Clock.dateTimeImmutable
static function dateTimeImmutable(?\DateTimeZone $timezone = null): \DateTimeImmutable { if (self::$now !== null) { $now = \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', self::$now)); $now = $now->setTimezone($timezone ?? new \DateTimeZone(date_default_timezone_get())); return $now; } return new \DateTimeImmutable('now', $timezone); }
php
static function dateTimeImmutable(?\DateTimeZone $timezone = null): \DateTimeImmutable { if (self::$now !== null) { $now = \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', self::$now)); $now = $now->setTimezone($timezone ?? new \DateTimeZone(date_default_timezone_get())); return $now; } return new \DateTimeImmutable('now', $timezone); }
[ "static", "function", "dateTimeImmutable", "(", "?", "\\", "DateTimeZone", "$", "timezone", "=", "null", ")", ":", "\\", "DateTimeImmutable", "{", "if", "(", "self", "::", "$", "now", "!==", "null", ")", "{", "$", "now", "=", "\\", "DateTimeImmutable", "::", "createFromFormat", "(", "'U.u'", ",", "sprintf", "(", "'%.6F'", ",", "self", "::", "$", "now", ")", ")", ";", "$", "now", "=", "$", "now", "->", "setTimezone", "(", "$", "timezone", "??", "new", "\\", "DateTimeZone", "(", "date_default_timezone_get", "(", ")", ")", ")", ";", "return", "$", "now", ";", "}", "return", "new", "\\", "DateTimeImmutable", "(", "'now'", ",", "$", "timezone", ")", ";", "}" ]
Get the current date-time as an immutable instance If no time zone is specified, then the default time zone will be used. The default time zone is specified by the date.timezone INI setting or the date_default_timezone_set() function.
[ "Get", "the", "current", "date", "-", "time", "as", "an", "immutable", "instance" ]
591468bdb175e230f7cc81b8c472fcc2bcfeb938
https://github.com/kuria/clock/blob/591468bdb175e230f7cc81b8c472fcc2bcfeb938/src/Clock.php#L111-L121
12,298
factorio-item-browser/api-database
src/Repository/TranslationRepository.php
TranslationRepository.findDataByTypesAndNames
public function findDataByTypesAndNames(string $locale, array $namesByTypes, array $modCombinationIds = []): array { $columns = [ 't.locale AS locale', 't.type AS type', 't.name AS name', 't.value AS value', 't.description AS description', 't.isDuplicatedByRecipe AS isDuplicatedByRecipe', 't.isDuplicatedByMachine AS isDuplicatedByMachine', 'mc.order AS order' ]; $queryBuilder = $this->entityManager->createQueryBuilder(); $queryBuilder->select($columns) ->from(Translation::class, 't') ->innerJoin('t.modCombination', 'mc') ->andWhere('t.locale IN (:locales)') ->setParameter('locales', [$locale, 'en']); $conditions = []; foreach ($namesByTypes as $type => $names) { if (count($names) > 0) { $index = count($conditions); switch ($type) { case TranslationType::RECIPE: // Special case: Recipes may re-use the translations provided by the item with the same name. $conditions[] = '((t.type = :type' . $index . ' OR t.isDuplicatedByRecipe = 1) ' . 'AND t.name IN (:names' . $index . '))'; break; case TranslationType::MACHINE: // Special case: Machines may re-use the translations provided by the item with the same name. $conditions[] = '((t.type = :type' . $index . ' OR t.isDuplicatedByMachine = 1) ' . 'AND t.name IN (:names' . $index . '))'; break; default: $conditions[] = '(t.type = :type' . $index . ' AND t.name IN (:names' . $index . '))'; break; } $queryBuilder->setParameter('type' . $index, $type) ->setParameter('names' . $index, array_values($names)); } } $result = []; if (count($conditions) > 0) { $queryBuilder->andWhere('(' . implode(' OR ', $conditions) . ')'); if (count($modCombinationIds) > 0) { $queryBuilder->andWhere('(t.modCombination IN (:modCombinationIds) OR t.type = :typeMod)') ->setParameter('modCombinationIds', array_values($modCombinationIds)) ->setParameter('typeMod', 'mod'); } $result = $this->mapTranslationDataResult($queryBuilder->getQuery()->getResult()); } return $result; }
php
public function findDataByTypesAndNames(string $locale, array $namesByTypes, array $modCombinationIds = []): array { $columns = [ 't.locale AS locale', 't.type AS type', 't.name AS name', 't.value AS value', 't.description AS description', 't.isDuplicatedByRecipe AS isDuplicatedByRecipe', 't.isDuplicatedByMachine AS isDuplicatedByMachine', 'mc.order AS order' ]; $queryBuilder = $this->entityManager->createQueryBuilder(); $queryBuilder->select($columns) ->from(Translation::class, 't') ->innerJoin('t.modCombination', 'mc') ->andWhere('t.locale IN (:locales)') ->setParameter('locales', [$locale, 'en']); $conditions = []; foreach ($namesByTypes as $type => $names) { if (count($names) > 0) { $index = count($conditions); switch ($type) { case TranslationType::RECIPE: // Special case: Recipes may re-use the translations provided by the item with the same name. $conditions[] = '((t.type = :type' . $index . ' OR t.isDuplicatedByRecipe = 1) ' . 'AND t.name IN (:names' . $index . '))'; break; case TranslationType::MACHINE: // Special case: Machines may re-use the translations provided by the item with the same name. $conditions[] = '((t.type = :type' . $index . ' OR t.isDuplicatedByMachine = 1) ' . 'AND t.name IN (:names' . $index . '))'; break; default: $conditions[] = '(t.type = :type' . $index . ' AND t.name IN (:names' . $index . '))'; break; } $queryBuilder->setParameter('type' . $index, $type) ->setParameter('names' . $index, array_values($names)); } } $result = []; if (count($conditions) > 0) { $queryBuilder->andWhere('(' . implode(' OR ', $conditions) . ')'); if (count($modCombinationIds) > 0) { $queryBuilder->andWhere('(t.modCombination IN (:modCombinationIds) OR t.type = :typeMod)') ->setParameter('modCombinationIds', array_values($modCombinationIds)) ->setParameter('typeMod', 'mod'); } $result = $this->mapTranslationDataResult($queryBuilder->getQuery()->getResult()); } return $result; }
[ "public", "function", "findDataByTypesAndNames", "(", "string", "$", "locale", ",", "array", "$", "namesByTypes", ",", "array", "$", "modCombinationIds", "=", "[", "]", ")", ":", "array", "{", "$", "columns", "=", "[", "'t.locale AS locale'", ",", "'t.type AS type'", ",", "'t.name AS name'", ",", "'t.value AS value'", ",", "'t.description AS description'", ",", "'t.isDuplicatedByRecipe AS isDuplicatedByRecipe'", ",", "'t.isDuplicatedByMachine AS isDuplicatedByMachine'", ",", "'mc.order AS order'", "]", ";", "$", "queryBuilder", "=", "$", "this", "->", "entityManager", "->", "createQueryBuilder", "(", ")", ";", "$", "queryBuilder", "->", "select", "(", "$", "columns", ")", "->", "from", "(", "Translation", "::", "class", ",", "'t'", ")", "->", "innerJoin", "(", "'t.modCombination'", ",", "'mc'", ")", "->", "andWhere", "(", "'t.locale IN (:locales)'", ")", "->", "setParameter", "(", "'locales'", ",", "[", "$", "locale", ",", "'en'", "]", ")", ";", "$", "conditions", "=", "[", "]", ";", "foreach", "(", "$", "namesByTypes", "as", "$", "type", "=>", "$", "names", ")", "{", "if", "(", "count", "(", "$", "names", ")", ">", "0", ")", "{", "$", "index", "=", "count", "(", "$", "conditions", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "TranslationType", "::", "RECIPE", ":", "// Special case: Recipes may re-use the translations provided by the item with the same name.", "$", "conditions", "[", "]", "=", "'((t.type = :type'", ".", "$", "index", ".", "' OR t.isDuplicatedByRecipe = 1) '", ".", "'AND t.name IN (:names'", ".", "$", "index", ".", "'))'", ";", "break", ";", "case", "TranslationType", "::", "MACHINE", ":", "// Special case: Machines may re-use the translations provided by the item with the same name.", "$", "conditions", "[", "]", "=", "'((t.type = :type'", ".", "$", "index", ".", "' OR t.isDuplicatedByMachine = 1) '", ".", "'AND t.name IN (:names'", ".", "$", "index", ".", "'))'", ";", "break", ";", "default", ":", "$", "conditions", "[", "]", "=", "'(t.type = :type'", ".", "$", "index", ".", "' AND t.name IN (:names'", ".", "$", "index", ".", "'))'", ";", "break", ";", "}", "$", "queryBuilder", "->", "setParameter", "(", "'type'", ".", "$", "index", ",", "$", "type", ")", "->", "setParameter", "(", "'names'", ".", "$", "index", ",", "array_values", "(", "$", "names", ")", ")", ";", "}", "}", "$", "result", "=", "[", "]", ";", "if", "(", "count", "(", "$", "conditions", ")", ">", "0", ")", "{", "$", "queryBuilder", "->", "andWhere", "(", "'('", ".", "implode", "(", "' OR '", ",", "$", "conditions", ")", ".", "')'", ")", ";", "if", "(", "count", "(", "$", "modCombinationIds", ")", ">", "0", ")", "{", "$", "queryBuilder", "->", "andWhere", "(", "'(t.modCombination IN (:modCombinationIds) OR t.type = :typeMod)'", ")", "->", "setParameter", "(", "'modCombinationIds'", ",", "array_values", "(", "$", "modCombinationIds", ")", ")", "->", "setParameter", "(", "'typeMod'", ",", "'mod'", ")", ";", "}", "$", "result", "=", "$", "this", "->", "mapTranslationDataResult", "(", "$", "queryBuilder", "->", "getQuery", "(", ")", "->", "getResult", "(", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Finds the translation data with the specified types and names. @param string $locale The locale to prefer in the results. @param array|string[][] $namesByTypes The names to search, grouped by their types. @param array|int[] $modCombinationIds The IDs of the mod combinations, or empty to use all translations. @return array|TranslationData[]
[ "Finds", "the", "translation", "data", "with", "the", "specified", "types", "and", "names", "." ]
c3a27e5673462a58b5afafc0ea0e0002f6db9803
https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Repository/TranslationRepository.php#L28-L87
12,299
factorio-item-browser/api-database
src/Repository/TranslationRepository.php
TranslationRepository.mapTranslationDataResult
protected function mapTranslationDataResult(array $translationData): array { $result = []; foreach ($translationData as $data) { $result[] = TranslationData::createFromArray($data); } return $result; }
php
protected function mapTranslationDataResult(array $translationData): array { $result = []; foreach ($translationData as $data) { $result[] = TranslationData::createFromArray($data); } return $result; }
[ "protected", "function", "mapTranslationDataResult", "(", "array", "$", "translationData", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "translationData", "as", "$", "data", ")", "{", "$", "result", "[", "]", "=", "TranslationData", "::", "createFromArray", "(", "$", "data", ")", ";", "}", "return", "$", "result", ";", "}" ]
Maps the query result to instances of TranslationData. @param array $translationData @return array|TranslationData[]
[ "Maps", "the", "query", "result", "to", "instances", "of", "TranslationData", "." ]
c3a27e5673462a58b5afafc0ea0e0002f6db9803
https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Repository/TranslationRepository.php#L94-L101