repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
blainesch/prettyArray
src/prettyArray/PrettyArray.php
PrettyArray.key
public function key() { $keys = array_keys($this->data); return isset($keys[$this->position]) ? $keys[$this->position] : null; }
php
public function key() { $keys = array_keys($this->data); return isset($keys[$this->position]) ? $keys[$this->position] : null; }
[ "public", "function", "key", "(", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "this", "->", "data", ")", ";", "return", "isset", "(", "$", "keys", "[", "$", "this", "->", "position", "]", ")", "?", "$", "keys", "[", "$", "this", "->", "position", "]", ":", "null", ";", "}" ]
Retrieve the current key. Part of the Iterator interface. @return null
[ "Retrieve", "the", "current", "key", ".", "Part", "of", "the", "Iterator", "interface", "." ]
2c18672e45a0ed9b67a0e321213c4055d224a334
https://github.com/blainesch/prettyArray/blob/2c18672e45a0ed9b67a0e321213c4055d224a334/src/prettyArray/PrettyArray.php#L543-L546
train
romm/configuration_object
Classes/Validation/Validator/FileExistsValidator.php
FileExistsValidator.isValid
public function isValid($value) { $filePath = GeneralUtility::getFileAbsFileName($value); if (false === GeneralUtility::getUrl($filePath)) { $errorMessage = $this->translateErrorMessage('validator.file_exists.not_valid', 'configuration_object', [$value]); $this->addError($errorMessage, 1510085560); } }
php
public function isValid($value) { $filePath = GeneralUtility::getFileAbsFileName($value); if (false === GeneralUtility::getUrl($filePath)) { $errorMessage = $this->translateErrorMessage('validator.file_exists.not_valid', 'configuration_object', [$value]); $this->addError($errorMessage, 1510085560); } }
[ "public", "function", "isValid", "(", "$", "value", ")", "{", "$", "filePath", "=", "GeneralUtility", "::", "getFileAbsFileName", "(", "$", "value", ")", ";", "if", "(", "false", "===", "GeneralUtility", "::", "getUrl", "(", "$", "filePath", ")", ")", "{", "$", "errorMessage", "=", "$", "this", "->", "translateErrorMessage", "(", "'validator.file_exists.not_valid'", ",", "'configuration_object'", ",", "[", "$", "value", "]", ")", ";", "$", "this", "->", "addError", "(", "$", "errorMessage", ",", "1510085560", ")", ";", "}", "}" ]
Checks if the value is a path to an existing file. The following syntax is supported: `EXT:my_extension/Path/To/My/File.txt` @param mixed $value
[ "Checks", "if", "the", "value", "is", "a", "path", "to", "an", "existing", "file", "." ]
d3a40903386c2e0766bd8279337fe6da45cf5ce3
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Validation/Validator/FileExistsValidator.php#L28-L36
train
danielgp/common-lib
source/DomCssAndJavascriptByDanielGP.php
DomCssAndJavascriptByDanielGP.setCssContent
protected function setCssContent($cssContent, $optionalFlags = null) { $attr = []; if (is_null($optionalFlags)) { $attr['media'] = 'all'; } else { $knownAttributes = ['media']; foreach ($knownAttributes as $value) { if (array_key_exists($value, $optionalFlags)) { $attr[$value] = $optionalFlags[$value]; } } } return '<style type="text/css" media="' . $attr['media'] . '">' . $cssContent . '</style>'; }
php
protected function setCssContent($cssContent, $optionalFlags = null) { $attr = []; if (is_null($optionalFlags)) { $attr['media'] = 'all'; } else { $knownAttributes = ['media']; foreach ($knownAttributes as $value) { if (array_key_exists($value, $optionalFlags)) { $attr[$value] = $optionalFlags[$value]; } } } return '<style type="text/css" media="' . $attr['media'] . '">' . $cssContent . '</style>'; }
[ "protected", "function", "setCssContent", "(", "$", "cssContent", ",", "$", "optionalFlags", "=", "null", ")", "{", "$", "attr", "=", "[", "]", ";", "if", "(", "is_null", "(", "$", "optionalFlags", ")", ")", "{", "$", "attr", "[", "'media'", "]", "=", "'all'", ";", "}", "else", "{", "$", "knownAttributes", "=", "[", "'media'", "]", ";", "foreach", "(", "$", "knownAttributes", "as", "$", "value", ")", "{", "if", "(", "array_key_exists", "(", "$", "value", ",", "$", "optionalFlags", ")", ")", "{", "$", "attr", "[", "$", "value", "]", "=", "$", "optionalFlags", "[", "$", "value", "]", ";", "}", "}", "}", "return", "'<style type=\"text/css\" media=\"'", ".", "$", "attr", "[", "'media'", "]", ".", "'\">'", ".", "$", "cssContent", ".", "'</style>'", ";", "}" ]
Returns css codes @param string $cssContent @param array $optionalFlags @return string
[ "Returns", "css", "codes" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGP.php#L65-L80
train
danielgp/common-lib
source/DomCssAndJavascriptByDanielGP.php
DomCssAndJavascriptByDanielGP.setCssFile
protected function setCssFile($cssFileName, $hostsWithoutCDNrq = null) { if (is_null($hostsWithoutCDNrq)) { $hostsWithoutCDNrq = []; } if (in_array($this->getClientRealIpAddress(), $hostsWithoutCDNrq)) { return '<link rel="stylesheet" type="text/css" href="' . filter_var($cssFileName, FILTER_SANITIZE_STRING) . '" />'; } $patternFound = $this->setCssFileCDN($cssFileName); return '<link rel="stylesheet" type="text/css" href="' . filter_var($patternFound[1], FILTER_SANITIZE_STRING) . '" />'; }
php
protected function setCssFile($cssFileName, $hostsWithoutCDNrq = null) { if (is_null($hostsWithoutCDNrq)) { $hostsWithoutCDNrq = []; } if (in_array($this->getClientRealIpAddress(), $hostsWithoutCDNrq)) { return '<link rel="stylesheet" type="text/css" href="' . filter_var($cssFileName, FILTER_SANITIZE_STRING) . '" />'; } $patternFound = $this->setCssFileCDN($cssFileName); return '<link rel="stylesheet" type="text/css" href="' . filter_var($patternFound[1], FILTER_SANITIZE_STRING) . '" />'; }
[ "protected", "function", "setCssFile", "(", "$", "cssFileName", ",", "$", "hostsWithoutCDNrq", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "hostsWithoutCDNrq", ")", ")", "{", "$", "hostsWithoutCDNrq", "=", "[", "]", ";", "}", "if", "(", "in_array", "(", "$", "this", "->", "getClientRealIpAddress", "(", ")", ",", "$", "hostsWithoutCDNrq", ")", ")", "{", "return", "'<link rel=\"stylesheet\" type=\"text/css\" href=\"'", ".", "filter_var", "(", "$", "cssFileName", ",", "FILTER_SANITIZE_STRING", ")", ".", "'\" />'", ";", "}", "$", "patternFound", "=", "$", "this", "->", "setCssFileCDN", "(", "$", "cssFileName", ")", ";", "return", "'<link rel=\"stylesheet\" type=\"text/css\" href=\"'", ".", "filter_var", "(", "$", "patternFound", "[", "1", "]", ",", "FILTER_SANITIZE_STRING", ")", ".", "'\" />'", ";", "}" ]
Returns css link to a given file @param string $cssFileName @return string
[ "Returns", "css", "link", "to", "a", "given", "file" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGP.php#L88-L100
train
danielgp/common-lib
source/DomCssAndJavascriptByDanielGP.php
DomCssAndJavascriptByDanielGP.setFormJavascriptFinal
protected function setFormJavascriptFinal($frmId) { $cnt = implode(PHP_EOL, [ '$(document).ready(function(){', '$("form#' . $frmId . '").submit(function(){', '$("form#' . $frmId . ' input[type=checkbox]").attr("readonly", true);', '$("form#' . $frmId . ' input[type=password]").attr("readonly", true);', '$("form#' . $frmId . ' input[type=radio]").attr("readonly", true);', '$("form#' . $frmId . ' input[type=text]").attr("readonly", true);', '$("form#' . $frmId . ' textarea").attr("readonly", true);', '$("form#' . $frmId . ' select").attr("readonly", true);', '$("input[type=submit]").attr("disabled", "disabled");', '$("input[type=submit]").attr("value", "' . $this->lclMsgCmn('i18n_Form_ButtonSaving') . '");', '});', '});', ]); return $this->setJavascriptContent(PHP_EOL . $cnt . PHP_EOL); }
php
protected function setFormJavascriptFinal($frmId) { $cnt = implode(PHP_EOL, [ '$(document).ready(function(){', '$("form#' . $frmId . '").submit(function(){', '$("form#' . $frmId . ' input[type=checkbox]").attr("readonly", true);', '$("form#' . $frmId . ' input[type=password]").attr("readonly", true);', '$("form#' . $frmId . ' input[type=radio]").attr("readonly", true);', '$("form#' . $frmId . ' input[type=text]").attr("readonly", true);', '$("form#' . $frmId . ' textarea").attr("readonly", true);', '$("form#' . $frmId . ' select").attr("readonly", true);', '$("input[type=submit]").attr("disabled", "disabled");', '$("input[type=submit]").attr("value", "' . $this->lclMsgCmn('i18n_Form_ButtonSaving') . '");', '});', '});', ]); return $this->setJavascriptContent(PHP_EOL . $cnt . PHP_EOL); }
[ "protected", "function", "setFormJavascriptFinal", "(", "$", "frmId", ")", "{", "$", "cnt", "=", "implode", "(", "PHP_EOL", ",", "[", "'$(document).ready(function(){'", ",", "'$(\"form#'", ".", "$", "frmId", ".", "'\").submit(function(){'", ",", "'$(\"form#'", ".", "$", "frmId", ".", "' input[type=checkbox]\").attr(\"readonly\", true);'", ",", "'$(\"form#'", ".", "$", "frmId", ".", "' input[type=password]\").attr(\"readonly\", true);'", ",", "'$(\"form#'", ".", "$", "frmId", ".", "' input[type=radio]\").attr(\"readonly\", true);'", ",", "'$(\"form#'", ".", "$", "frmId", ".", "' input[type=text]\").attr(\"readonly\", true);'", ",", "'$(\"form#'", ".", "$", "frmId", ".", "' textarea\").attr(\"readonly\", true);'", ",", "'$(\"form#'", ".", "$", "frmId", ".", "' select\").attr(\"readonly\", true);'", ",", "'$(\"input[type=submit]\").attr(\"disabled\", \"disabled\");'", ",", "'$(\"input[type=submit]\").attr(\"value\", \"'", ".", "$", "this", "->", "lclMsgCmn", "(", "'i18n_Form_ButtonSaving'", ")", ".", "'\");'", ",", "'});'", ",", "'});'", ",", "]", ")", ";", "return", "$", "this", "->", "setJavascriptContent", "(", "PHP_EOL", ".", "$", "cnt", ".", "PHP_EOL", ")", ";", "}" ]
Builds javascript to avoid multiple form submission @param string $frmId @return string
[ "Builds", "javascript", "to", "avoid", "multiple", "form", "submission" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGP.php#L108-L125
train
danielgp/common-lib
source/DomCssAndJavascriptByDanielGP.php
DomCssAndJavascriptByDanielGP.setJavascriptFile
protected function setJavascriptFile($jsFileName, $hostsWithoutCDNrq = null) { if (is_null($hostsWithoutCDNrq)) { $hostsWithoutCDNrq = []; } if (in_array($this->getClientRealIpAddress(), $hostsWithoutCDNrq)) { return '<script type="text/javascript" src="' . filter_var($jsFileName, FILTER_SANITIZE_STRING) . '"></script>'; } $patternFound = $this->setJavascriptFileCDN($jsFileName); return '<script type="text/javascript" src="' . $patternFound[1] . '"></script>' . $patternFound[2]; }
php
protected function setJavascriptFile($jsFileName, $hostsWithoutCDNrq = null) { if (is_null($hostsWithoutCDNrq)) { $hostsWithoutCDNrq = []; } if (in_array($this->getClientRealIpAddress(), $hostsWithoutCDNrq)) { return '<script type="text/javascript" src="' . filter_var($jsFileName, FILTER_SANITIZE_STRING) . '"></script>'; } $patternFound = $this->setJavascriptFileCDN($jsFileName); return '<script type="text/javascript" src="' . $patternFound[1] . '"></script>' . $patternFound[2]; }
[ "protected", "function", "setJavascriptFile", "(", "$", "jsFileName", ",", "$", "hostsWithoutCDNrq", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "hostsWithoutCDNrq", ")", ")", "{", "$", "hostsWithoutCDNrq", "=", "[", "]", ";", "}", "if", "(", "in_array", "(", "$", "this", "->", "getClientRealIpAddress", "(", ")", ",", "$", "hostsWithoutCDNrq", ")", ")", "{", "return", "'<script type=\"text/javascript\" src=\"'", ".", "filter_var", "(", "$", "jsFileName", ",", "FILTER_SANITIZE_STRING", ")", ".", "'\"></script>'", ";", "}", "$", "patternFound", "=", "$", "this", "->", "setJavascriptFileCDN", "(", "$", "jsFileName", ")", ";", "return", "'<script type=\"text/javascript\" src=\"'", ".", "$", "patternFound", "[", "1", "]", ".", "'\"></script>'", ".", "$", "patternFound", "[", "2", "]", ";", "}" ]
Returns javascript link to a given file @param string $jsFileName @return string
[ "Returns", "javascript", "link", "to", "a", "given", "file" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomCssAndJavascriptByDanielGP.php#L180-L191
train
AeonDigital/PHP-Collection
src/TypeList.php
TypeList.getStructureType
protected function getStructureType(string $structure, int $lvl) : array { $structureType = ""; $dataType = ""; if ($structure === "mixed" || $structure === "?mixed") { $structureType .= "nullable-"; $structure = "mixed"; } elseif (strpos($structure, "?") === 0) { $structureType .= "nullable-"; $structure = substr($structure, 1, (strlen($structure) - 1)); } if ($this->isStructureASingleType($structure) === true) { $structureType .= "type"; $dataType = "type"; } elseif ($this->isStructureAnCommomArray($structure) === true) { $structureType .= "array"; // Remove os "[]" $structure = substr($structure, 1, (strlen($structure) - 2)); if ($this->isStructureASingleType($structure) === true || $this->isStructureAnArrayOfTypes($structure, $lvl) === true) { $dataType = "array-of-types"; } elseif ($this->isStructureAnAssocArray($structure, $lvl) === true) { $dataType = "array-assoc"; } } // Tratando-se de uma definição de um tipo if (($structureType === "type" || $structureType === "nullable-type") && $this->validateType($structure) === false) { $structureType = ""; $dataType = ""; } return [ "structureType" => $structureType, "dataType" => $dataType, "internalStructure" => $structure ]; }
php
protected function getStructureType(string $structure, int $lvl) : array { $structureType = ""; $dataType = ""; if ($structure === "mixed" || $structure === "?mixed") { $structureType .= "nullable-"; $structure = "mixed"; } elseif (strpos($structure, "?") === 0) { $structureType .= "nullable-"; $structure = substr($structure, 1, (strlen($structure) - 1)); } if ($this->isStructureASingleType($structure) === true) { $structureType .= "type"; $dataType = "type"; } elseif ($this->isStructureAnCommomArray($structure) === true) { $structureType .= "array"; // Remove os "[]" $structure = substr($structure, 1, (strlen($structure) - 2)); if ($this->isStructureASingleType($structure) === true || $this->isStructureAnArrayOfTypes($structure, $lvl) === true) { $dataType = "array-of-types"; } elseif ($this->isStructureAnAssocArray($structure, $lvl) === true) { $dataType = "array-assoc"; } } // Tratando-se de uma definição de um tipo if (($structureType === "type" || $structureType === "nullable-type") && $this->validateType($structure) === false) { $structureType = ""; $dataType = ""; } return [ "structureType" => $structureType, "dataType" => $dataType, "internalStructure" => $structure ]; }
[ "protected", "function", "getStructureType", "(", "string", "$", "structure", ",", "int", "$", "lvl", ")", ":", "array", "{", "$", "structureType", "=", "\"\"", ";", "$", "dataType", "=", "\"\"", ";", "if", "(", "$", "structure", "===", "\"mixed\"", "||", "$", "structure", "===", "\"?mixed\"", ")", "{", "$", "structureType", ".=", "\"nullable-\"", ";", "$", "structure", "=", "\"mixed\"", ";", "}", "elseif", "(", "strpos", "(", "$", "structure", ",", "\"?\"", ")", "===", "0", ")", "{", "$", "structureType", ".=", "\"nullable-\"", ";", "$", "structure", "=", "substr", "(", "$", "structure", ",", "1", ",", "(", "strlen", "(", "$", "structure", ")", "-", "1", ")", ")", ";", "}", "if", "(", "$", "this", "->", "isStructureASingleType", "(", "$", "structure", ")", "===", "true", ")", "{", "$", "structureType", ".=", "\"type\"", ";", "$", "dataType", "=", "\"type\"", ";", "}", "elseif", "(", "$", "this", "->", "isStructureAnCommomArray", "(", "$", "structure", ")", "===", "true", ")", "{", "$", "structureType", ".=", "\"array\"", ";", "// Remove os \"[]\"", "$", "structure", "=", "substr", "(", "$", "structure", ",", "1", ",", "(", "strlen", "(", "$", "structure", ")", "-", "2", ")", ")", ";", "if", "(", "$", "this", "->", "isStructureASingleType", "(", "$", "structure", ")", "===", "true", "||", "$", "this", "->", "isStructureAnArrayOfTypes", "(", "$", "structure", ",", "$", "lvl", ")", "===", "true", ")", "{", "$", "dataType", "=", "\"array-of-types\"", ";", "}", "elseif", "(", "$", "this", "->", "isStructureAnAssocArray", "(", "$", "structure", ",", "$", "lvl", ")", "===", "true", ")", "{", "$", "dataType", "=", "\"array-assoc\"", ";", "}", "}", "// Tratando-se de uma definição de um tipo", "if", "(", "(", "$", "structureType", "===", "\"type\"", "||", "$", "structureType", "===", "\"nullable-type\"", ")", "&&", "$", "this", "->", "validateType", "(", "$", "structure", ")", "===", "false", ")", "{", "$", "structureType", "=", "\"\"", ";", "$", "dataType", "=", "\"\"", ";", "}", "return", "[", "\"structureType\"", "=>", "$", "structureType", ",", "\"dataType\"", "=>", "$", "dataType", ",", "\"internalStructure\"", "=>", "$", "structure", "]", ";", "}" ]
Retorna o tipo de estrutura de dados que a string passada representa. O retorno será um array associativo contendo: <pre> "structureType" => [nullable-] type | array "dataType => type | array-of-types | array-assoc "internalStructure => Estrutura interna, removendo marcações mais externas como ?[ ... ], ficando apenas o conteúdo em si. "childModel" => Array contendo as definições para os valores filhos da estrutura atual. </pre> O valor "structureType" representado por uma string vazia indica que o tipo não é válido. @param string $structure Estrutura de dados que será identificada. @param int $lvl Nível de complexidade do objeto. @return array
[ "Retorna", "o", "tipo", "de", "estrutura", "de", "dados", "que", "a", "string", "passada", "representa", "." ]
8b010e1fada781e7ca86e9f406c18ad7adc6499d
https://github.com/AeonDigital/PHP-Collection/blob/8b010e1fada781e7ca86e9f406c18ad7adc6499d/src/TypeList.php#L413-L457
train
SahilDude89ss/PyntaxFramework
src/Pyntax/DAO/Adapter/MySqlAdapter.php
MySqlAdapter.exec
public function exec($sql = "", $bindingValues = array(), $insert = true) { //Check if the query is a SELECT|INSERT|UPDATE and :variation is available if (preg_match("/.*(SELECT|INSERT|UPDATE|SHOW|DELETE).*/", $sql)) { $this->sql = $sql; //Always prepare the SQL statement first $query = $this->connection->prepare($sql); if (preg_match('/\s*:(.+?)\s/', $sql)) { if (is_array($bindingValues) && !empty($bindingValues)) { foreach ($bindingValues as $key => $val) { //Clean the bindingValues. Check if they start with : if (!preg_match('/:.*/', $key)) { $bindingValues[":" . $key] = $val; unset($bindingValues[$key]); } } } //Add the binding variables to the query if ($query->execute($bindingValues)) { return $this->getLastInsertID(); } else { //@ToDo:When the save or update fails make sure we handle the error gracefully! throw new \Exception(implode("\n", $query->errorInfo())); } } else { $result = $query->execute(); } if (preg_match('/.*(SELECT|SHOW).*/', $sql)) { $query->setFetchMode(\PDO::FETCH_ASSOC); return $query->fetchAll(); } return $result; } return false; }
php
public function exec($sql = "", $bindingValues = array(), $insert = true) { //Check if the query is a SELECT|INSERT|UPDATE and :variation is available if (preg_match("/.*(SELECT|INSERT|UPDATE|SHOW|DELETE).*/", $sql)) { $this->sql = $sql; //Always prepare the SQL statement first $query = $this->connection->prepare($sql); if (preg_match('/\s*:(.+?)\s/', $sql)) { if (is_array($bindingValues) && !empty($bindingValues)) { foreach ($bindingValues as $key => $val) { //Clean the bindingValues. Check if they start with : if (!preg_match('/:.*/', $key)) { $bindingValues[":" . $key] = $val; unset($bindingValues[$key]); } } } //Add the binding variables to the query if ($query->execute($bindingValues)) { return $this->getLastInsertID(); } else { //@ToDo:When the save or update fails make sure we handle the error gracefully! throw new \Exception(implode("\n", $query->errorInfo())); } } else { $result = $query->execute(); } if (preg_match('/.*(SELECT|SHOW).*/', $sql)) { $query->setFetchMode(\PDO::FETCH_ASSOC); return $query->fetchAll(); } return $result; } return false; }
[ "public", "function", "exec", "(", "$", "sql", "=", "\"\"", ",", "$", "bindingValues", "=", "array", "(", ")", ",", "$", "insert", "=", "true", ")", "{", "//Check if the query is a SELECT|INSERT|UPDATE and :variation is available", "if", "(", "preg_match", "(", "\"/.*(SELECT|INSERT|UPDATE|SHOW|DELETE).*/\"", ",", "$", "sql", ")", ")", "{", "$", "this", "->", "sql", "=", "$", "sql", ";", "//Always prepare the SQL statement first", "$", "query", "=", "$", "this", "->", "connection", "->", "prepare", "(", "$", "sql", ")", ";", "if", "(", "preg_match", "(", "'/\\s*:(.+?)\\s/'", ",", "$", "sql", ")", ")", "{", "if", "(", "is_array", "(", "$", "bindingValues", ")", "&&", "!", "empty", "(", "$", "bindingValues", ")", ")", "{", "foreach", "(", "$", "bindingValues", "as", "$", "key", "=>", "$", "val", ")", "{", "//Clean the bindingValues. Check if they start with :", "if", "(", "!", "preg_match", "(", "'/:.*/'", ",", "$", "key", ")", ")", "{", "$", "bindingValues", "[", "\":\"", ".", "$", "key", "]", "=", "$", "val", ";", "unset", "(", "$", "bindingValues", "[", "$", "key", "]", ")", ";", "}", "}", "}", "//Add the binding variables to the query", "if", "(", "$", "query", "->", "execute", "(", "$", "bindingValues", ")", ")", "{", "return", "$", "this", "->", "getLastInsertID", "(", ")", ";", "}", "else", "{", "//@ToDo:When the save or update fails make sure we handle the error gracefully!", "throw", "new", "\\", "Exception", "(", "implode", "(", "\"\\n\"", ",", "$", "query", "->", "errorInfo", "(", ")", ")", ")", ";", "}", "}", "else", "{", "$", "result", "=", "$", "query", "->", "execute", "(", ")", ";", "}", "if", "(", "preg_match", "(", "'/.*(SELECT|SHOW).*/'", ",", "$", "sql", ")", ")", "{", "$", "query", "->", "setFetchMode", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "$", "query", "->", "fetchAll", "(", ")", ";", "}", "return", "$", "result", ";", "}", "return", "false", ";", "}" ]
Executes the current SQL query. Returns a ASSOC result set. @param string $sql @param array $bindingValues @param bool $insert @return mixed
[ "Executes", "the", "current", "SQL", "query", ".", "Returns", "a", "ASSOC", "result", "set", "." ]
045cca87d24eb2b6405734966c64344e00224c7b
https://github.com/SahilDude89ss/PyntaxFramework/blob/045cca87d24eb2b6405734966c64344e00224c7b/src/Pyntax/DAO/Adapter/MySqlAdapter.php#L96-L140
train
SahilDude89ss/PyntaxFramework
src/Pyntax/DAO/Adapter/MySqlAdapter.php
MySqlAdapter.convertWhereToString
protected function convertWhereToString(array $whereArray = array(), $concatenationOperator = " AND ", $assignmentOperator = "=") { if (empty($whereArray)) { return false; } $returnWhereStringToken = array(); //Check if the the keys is AND or OR, if yes then use that as the concat operator foreach ($whereArray as $key => $val) { $_key = strtoupper($key); if ((in_array($_key, array("OR","AND","LIKE"))) && is_array($val) && !empty($val)) { $_assignmentOperator = ($_key == "LIKE") ? $_key : $assignmentOperator; $returnWhereStringToken = array_merge($returnWhereStringToken, array($this->convertWhereToString($val, " " . trim($key) . " ", $_assignmentOperator))); } else { $returnWhereStringToken[] = "$key {$assignmentOperator} '$val'"; } } return implode($concatenationOperator, $returnWhereStringToken); }
php
protected function convertWhereToString(array $whereArray = array(), $concatenationOperator = " AND ", $assignmentOperator = "=") { if (empty($whereArray)) { return false; } $returnWhereStringToken = array(); //Check if the the keys is AND or OR, if yes then use that as the concat operator foreach ($whereArray as $key => $val) { $_key = strtoupper($key); if ((in_array($_key, array("OR","AND","LIKE"))) && is_array($val) && !empty($val)) { $_assignmentOperator = ($_key == "LIKE") ? $_key : $assignmentOperator; $returnWhereStringToken = array_merge($returnWhereStringToken, array($this->convertWhereToString($val, " " . trim($key) . " ", $_assignmentOperator))); } else { $returnWhereStringToken[] = "$key {$assignmentOperator} '$val'"; } } return implode($concatenationOperator, $returnWhereStringToken); }
[ "protected", "function", "convertWhereToString", "(", "array", "$", "whereArray", "=", "array", "(", ")", ",", "$", "concatenationOperator", "=", "\" AND \"", ",", "$", "assignmentOperator", "=", "\"=\"", ")", "{", "if", "(", "empty", "(", "$", "whereArray", ")", ")", "{", "return", "false", ";", "}", "$", "returnWhereStringToken", "=", "array", "(", ")", ";", "//Check if the the keys is AND or OR, if yes then use that as the concat operator", "foreach", "(", "$", "whereArray", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "_key", "=", "strtoupper", "(", "$", "key", ")", ";", "if", "(", "(", "in_array", "(", "$", "_key", ",", "array", "(", "\"OR\"", ",", "\"AND\"", ",", "\"LIKE\"", ")", ")", ")", "&&", "is_array", "(", "$", "val", ")", "&&", "!", "empty", "(", "$", "val", ")", ")", "{", "$", "_assignmentOperator", "=", "(", "$", "_key", "==", "\"LIKE\"", ")", "?", "$", "_key", ":", "$", "assignmentOperator", ";", "$", "returnWhereStringToken", "=", "array_merge", "(", "$", "returnWhereStringToken", ",", "array", "(", "$", "this", "->", "convertWhereToString", "(", "$", "val", ",", "\" \"", ".", "trim", "(", "$", "key", ")", ".", "\" \"", ",", "$", "_assignmentOperator", ")", ")", ")", ";", "}", "else", "{", "$", "returnWhereStringToken", "[", "]", "=", "\"$key {$assignmentOperator} '$val'\"", ";", "}", "}", "return", "implode", "(", "$", "concatenationOperator", ",", "$", "returnWhereStringToken", ")", ";", "}" ]
This function converts an array into a Where String. @param array $whereArray @param string $concatenationOperator @return bool|string
[ "This", "function", "converts", "an", "array", "into", "a", "Where", "String", "." ]
045cca87d24eb2b6405734966c64344e00224c7b
https://github.com/SahilDude89ss/PyntaxFramework/blob/045cca87d24eb2b6405734966c64344e00224c7b/src/Pyntax/DAO/Adapter/MySqlAdapter.php#L232-L253
train
SahilDude89ss/PyntaxFramework
src/Pyntax/DAO/Adapter/MySqlAdapter.php
MySqlAdapter.getOneResult
public function getOneResult($table, $where = null, $groupBy = null, $orderBy = null) { return $this->Select($table, $where, $groupBy, $orderBy, 1); }
php
public function getOneResult($table, $where = null, $groupBy = null, $orderBy = null) { return $this->Select($table, $where, $groupBy, $orderBy, 1); }
[ "public", "function", "getOneResult", "(", "$", "table", ",", "$", "where", "=", "null", ",", "$", "groupBy", "=", "null", ",", "$", "orderBy", "=", "null", ")", "{", "return", "$", "this", "->", "Select", "(", "$", "table", ",", "$", "where", ",", "$", "groupBy", ",", "$", "orderBy", ",", "1", ")", ";", "}" ]
Executes the current SQL query and returns the first result as ASSOC result set @param $table @param null $where @param null $groupBy @param null $orderBy @return mixed
[ "Executes", "the", "current", "SQL", "query", "and", "returns", "the", "first", "result", "as", "ASSOC", "result", "set" ]
045cca87d24eb2b6405734966c64344e00224c7b
https://github.com/SahilDude89ss/PyntaxFramework/blob/045cca87d24eb2b6405734966c64344e00224c7b/src/Pyntax/DAO/Adapter/MySqlAdapter.php#L265-L268
train
SahilDude89ss/PyntaxFramework
src/Pyntax/DAO/Adapter/MySqlAdapter.php
MySqlAdapter.Insert
public function Insert($table, $data = array()) { if (empty($table) || empty($data)) { return false; } //Before we set the columns, make sure we only use the column that re meant to be filled. foreach ($data as $key => $val) { if (empty($val)) { unset($data[$key]); } } //Get all the columns that are being set $columns = array_keys($data); //If the columns are not empty, proceed with the save if (!empty($columns)) { //Create a newInsert object $insert = $this->queryFactory->newInsert(); //Set the table $insert->into($table); //Set the columns $insert->cols($columns); //Bind the values to be saved $insert->bindValues($data); //return the insert id return $this->exec($insert->getStatement(), $insert->getBindValues()); } return false; }
php
public function Insert($table, $data = array()) { if (empty($table) || empty($data)) { return false; } //Before we set the columns, make sure we only use the column that re meant to be filled. foreach ($data as $key => $val) { if (empty($val)) { unset($data[$key]); } } //Get all the columns that are being set $columns = array_keys($data); //If the columns are not empty, proceed with the save if (!empty($columns)) { //Create a newInsert object $insert = $this->queryFactory->newInsert(); //Set the table $insert->into($table); //Set the columns $insert->cols($columns); //Bind the values to be saved $insert->bindValues($data); //return the insert id return $this->exec($insert->getStatement(), $insert->getBindValues()); } return false; }
[ "public", "function", "Insert", "(", "$", "table", ",", "$", "data", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "table", ")", "||", "empty", "(", "$", "data", ")", ")", "{", "return", "false", ";", "}", "//Before we set the columns, make sure we only use the column that re meant to be filled.", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "empty", "(", "$", "val", ")", ")", "{", "unset", "(", "$", "data", "[", "$", "key", "]", ")", ";", "}", "}", "//Get all the columns that are being set", "$", "columns", "=", "array_keys", "(", "$", "data", ")", ";", "//If the columns are not empty, proceed with the save", "if", "(", "!", "empty", "(", "$", "columns", ")", ")", "{", "//Create a newInsert object", "$", "insert", "=", "$", "this", "->", "queryFactory", "->", "newInsert", "(", ")", ";", "//Set the table", "$", "insert", "->", "into", "(", "$", "table", ")", ";", "//Set the columns", "$", "insert", "->", "cols", "(", "$", "columns", ")", ";", "//Bind the values to be saved", "$", "insert", "->", "bindValues", "(", "$", "data", ")", ";", "//return the insert id", "return", "$", "this", "->", "exec", "(", "$", "insert", "->", "getStatement", "(", ")", ",", "$", "insert", "->", "getBindValues", "(", ")", ")", ";", "}", "return", "false", ";", "}" ]
Saves the data in the table with a new id; INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100; @param $table @param array $data @return mixed
[ "Saves", "the", "data", "in", "the", "table", "with", "a", "new", "id", ";" ]
045cca87d24eb2b6405734966c64344e00224c7b
https://github.com/SahilDude89ss/PyntaxFramework/blob/045cca87d24eb2b6405734966c64344e00224c7b/src/Pyntax/DAO/Adapter/MySqlAdapter.php#L364-L400
train
squareproton/Bond
src/Bond/Normality/Builder/Repository.php
Repository.getClassExtends
private function getClassExtends() { if( $this->isMultiton() ) { $this->class->addUses('\Bond\Repository\Multiton as RM'); $this->class->addExtends('RM'); } else { $this->class->addUses('\Bond\Repository as R'); $this->class->addExtends('R'); } }
php
private function getClassExtends() { if( $this->isMultiton() ) { $this->class->addUses('\Bond\Repository\Multiton as RM'); $this->class->addExtends('RM'); } else { $this->class->addUses('\Bond\Repository as R'); $this->class->addExtends('R'); } }
[ "private", "function", "getClassExtends", "(", ")", "{", "if", "(", "$", "this", "->", "isMultiton", "(", ")", ")", "{", "$", "this", "->", "class", "->", "addUses", "(", "'\\Bond\\Repository\\Multiton as RM'", ")", ";", "$", "this", "->", "class", "->", "addExtends", "(", "'RM'", ")", ";", "}", "else", "{", "$", "this", "->", "class", "->", "addUses", "(", "'\\Bond\\Repository as R'", ")", ";", "$", "this", "->", "class", "->", "addExtends", "(", "'R'", ")", ";", "}", "}" ]
Class to extend @return string
[ "Class", "to", "extend" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/Builder/Repository.php#L96-L106
train
squareproton/Bond
src/Bond/Normality/Builder/Repository.php
Repository.getClassConstants
private function getClassConstants() { $pgClass = $this->entity->pgClass; $this->class->classComponents[] = new ClassConstant( 'TABLE', new Sformatf( "const TABLE = '%s';", $pgClass->getFullyQualifiedName() ) ); $this->class->classComponents[] = new ClassConstant( 'PARENT', new Sformatf( "const PARENT = %s;", $pgClass->isInherited($parent) ? "'{$parent->getFullyQualifiedName()}'" : 'null' ) ); }
php
private function getClassConstants() { $pgClass = $this->entity->pgClass; $this->class->classComponents[] = new ClassConstant( 'TABLE', new Sformatf( "const TABLE = '%s';", $pgClass->getFullyQualifiedName() ) ); $this->class->classComponents[] = new ClassConstant( 'PARENT', new Sformatf( "const PARENT = %s;", $pgClass->isInherited($parent) ? "'{$parent->getFullyQualifiedName()}'" : 'null' ) ); }
[ "private", "function", "getClassConstants", "(", ")", "{", "$", "pgClass", "=", "$", "this", "->", "entity", "->", "pgClass", ";", "$", "this", "->", "class", "->", "classComponents", "[", "]", "=", "new", "ClassConstant", "(", "'TABLE'", ",", "new", "Sformatf", "(", "\"const TABLE = '%s';\"", ",", "$", "pgClass", "->", "getFullyQualifiedName", "(", ")", ")", ")", ";", "$", "this", "->", "class", "->", "classComponents", "[", "]", "=", "new", "ClassConstant", "(", "'PARENT'", ",", "new", "Sformatf", "(", "\"const PARENT = %s;\"", ",", "$", "pgClass", "->", "isInherited", "(", "$", "parent", ")", "?", "\"'{$parent->getFullyQualifiedName()}'\"", ":", "'null'", ")", ")", ";", "}" ]
Get class constants
[ "Get", "class", "constants" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/Builder/Repository.php#L111-L126
train
squareproton/Bond
src/Bond/Normality/Builder/Repository.php
Repository.setClassComment
private function setClassComment() { $connectionSettings = $this->entity->pgClass->getCatalog()->db->resource->connectionSettings; $header = new Sformatf( <<<TEXT ConnectionInfo %s@%s:%s, Relation %s TEXT , $connectionSettings->dbname, $connectionSettings->user, $connectionSettings->host, $this->entity->pgClass->getFullyQualifiedName() ); $this->class->setClassComment( $header->docblockify() ); }
php
private function setClassComment() { $connectionSettings = $this->entity->pgClass->getCatalog()->db->resource->connectionSettings; $header = new Sformatf( <<<TEXT ConnectionInfo %s@%s:%s, Relation %s TEXT , $connectionSettings->dbname, $connectionSettings->user, $connectionSettings->host, $this->entity->pgClass->getFullyQualifiedName() ); $this->class->setClassComment( $header->docblockify() ); }
[ "private", "function", "setClassComment", "(", ")", "{", "$", "connectionSettings", "=", "$", "this", "->", "entity", "->", "pgClass", "->", "getCatalog", "(", ")", "->", "db", "->", "resource", "->", "connectionSettings", ";", "$", "header", "=", "new", "Sformatf", "(", " <<<TEXT\n ConnectionInfo %s@%s:%s,\n Relation %s\nTEXT", ",", "$", "connectionSettings", "->", "dbname", ",", "$", "connectionSettings", "->", "user", ",", "$", "connectionSettings", "->", "host", ",", "$", "this", "->", "entity", "->", "pgClass", "->", "getFullyQualifiedName", "(", ")", ")", ";", "$", "this", "->", "class", "->", "setClassComment", "(", "$", "header", "->", "docblockify", "(", ")", ")", ";", "}" ]
Entity generated Headers @return array Headers
[ "Entity", "generated", "Headers" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/Builder/Repository.php#L132-L149
train
squareproton/Bond
src/Bond/Normality/Builder/Repository.php
Repository.getOptionsResolverFunctionDeclaration
private function getOptionsResolverFunctionDeclaration() { // get required properties $required = []; $optional = []; $allowedValues = []; // optional foreach( $this->entity->dataTypes as $name => $dataType ) { // is required if( !$dataType->getDefault() and !$dataType->isNullable() ) { $required[] = $name; } else { $optional[] = $name; } // set allowed values (currently only works for enums) if( $dataType->isEnum($enumName) ) { // At the moment this is bugged in Symfony.Don't think it is of vital importance. Ignoring for now. # $allowedValues[$name] = $enumName; } } // allowed values declaration $allowedValuesPhp = ''; if( $allowedValues ) { $allowedValuesPhp = "\n\$resolver->setAllowedValues(\n array(\n"; // at the moment this enum supported only foreach( $allowedValues as $column => $enumName ) { $allowedValuesPhp .= sprintf( ' %s => Enum::getValues(%s),%s', Php::varExport( $column ), Php::varExport( $enumName ), "\n" ); } $allowedValuesPhp .= " )\n);"; $allowedValuesPhp = new Format( $allowedValuesPhp ); } // require block $requiredPhp = new Format(); if( $required ) { $requiredPhp = "\n\$resolver->setRequired(\n" . (new Format(Php::varExport( $required )))->indent(4) . "\n);"; $requiredPhp = new Format($requiredPhp); $requiredPhp->indent(24); } // optional $optionalPhp = new Format(); if( $optional ) { $optionalPhp = "\n\$resolver->setOptional(\n" . (new Format(Php::varExport( $optional )))->indent(4) . "\n);"; $optionalPhp = new Format($optionalPhp); $optionalPhp->indent(24); } $this->class->addUses('Symfony\Component\OptionsResolver\OptionsResolver'); $this->class->classComponents[] = new FunctionDeclaration( 'resolverGet', new Sformatf( <<<'PHP' /** * Resolver getter. Singleton * @return Symfony\Component\Options\Resolver */ public function resolverGet() { // do we already have a resolver instance if( !$this->resolver ) { $resolver = new OptionsResolver();%s%s%s $this->resolver = $resolver; } return $this->resolver; } PHP , $requiredPhp, $optionalPhp, $allowedValuesPhp ) ); $this->class->classComponents[] = new VariableDeclaration( 'resolver', new SFormatf( <<<'PHP' /** * Options Resolver * @var array */ private $resolver; PHP ) ); }
php
private function getOptionsResolverFunctionDeclaration() { // get required properties $required = []; $optional = []; $allowedValues = []; // optional foreach( $this->entity->dataTypes as $name => $dataType ) { // is required if( !$dataType->getDefault() and !$dataType->isNullable() ) { $required[] = $name; } else { $optional[] = $name; } // set allowed values (currently only works for enums) if( $dataType->isEnum($enumName) ) { // At the moment this is bugged in Symfony.Don't think it is of vital importance. Ignoring for now. # $allowedValues[$name] = $enumName; } } // allowed values declaration $allowedValuesPhp = ''; if( $allowedValues ) { $allowedValuesPhp = "\n\$resolver->setAllowedValues(\n array(\n"; // at the moment this enum supported only foreach( $allowedValues as $column => $enumName ) { $allowedValuesPhp .= sprintf( ' %s => Enum::getValues(%s),%s', Php::varExport( $column ), Php::varExport( $enumName ), "\n" ); } $allowedValuesPhp .= " )\n);"; $allowedValuesPhp = new Format( $allowedValuesPhp ); } // require block $requiredPhp = new Format(); if( $required ) { $requiredPhp = "\n\$resolver->setRequired(\n" . (new Format(Php::varExport( $required )))->indent(4) . "\n);"; $requiredPhp = new Format($requiredPhp); $requiredPhp->indent(24); } // optional $optionalPhp = new Format(); if( $optional ) { $optionalPhp = "\n\$resolver->setOptional(\n" . (new Format(Php::varExport( $optional )))->indent(4) . "\n);"; $optionalPhp = new Format($optionalPhp); $optionalPhp->indent(24); } $this->class->addUses('Symfony\Component\OptionsResolver\OptionsResolver'); $this->class->classComponents[] = new FunctionDeclaration( 'resolverGet', new Sformatf( <<<'PHP' /** * Resolver getter. Singleton * @return Symfony\Component\Options\Resolver */ public function resolverGet() { // do we already have a resolver instance if( !$this->resolver ) { $resolver = new OptionsResolver();%s%s%s $this->resolver = $resolver; } return $this->resolver; } PHP , $requiredPhp, $optionalPhp, $allowedValuesPhp ) ); $this->class->classComponents[] = new VariableDeclaration( 'resolver', new SFormatf( <<<'PHP' /** * Options Resolver * @var array */ private $resolver; PHP ) ); }
[ "private", "function", "getOptionsResolverFunctionDeclaration", "(", ")", "{", "// get required properties", "$", "required", "=", "[", "]", ";", "$", "optional", "=", "[", "]", ";", "$", "allowedValues", "=", "[", "]", ";", "// optional", "foreach", "(", "$", "this", "->", "entity", "->", "dataTypes", "as", "$", "name", "=>", "$", "dataType", ")", "{", "// is required", "if", "(", "!", "$", "dataType", "->", "getDefault", "(", ")", "and", "!", "$", "dataType", "->", "isNullable", "(", ")", ")", "{", "$", "required", "[", "]", "=", "$", "name", ";", "}", "else", "{", "$", "optional", "[", "]", "=", "$", "name", ";", "}", "// set allowed values (currently only works for enums)", "if", "(", "$", "dataType", "->", "isEnum", "(", "$", "enumName", ")", ")", "{", "// At the moment this is bugged in Symfony.Don't think it is of vital importance. Ignoring for now.", "# $allowedValues[$name] = $enumName;", "}", "}", "// allowed values declaration", "$", "allowedValuesPhp", "=", "''", ";", "if", "(", "$", "allowedValues", ")", "{", "$", "allowedValuesPhp", "=", "\"\\n\\$resolver->setAllowedValues(\\n array(\\n\"", ";", "// at the moment this enum supported only", "foreach", "(", "$", "allowedValues", "as", "$", "column", "=>", "$", "enumName", ")", "{", "$", "allowedValuesPhp", ".=", "sprintf", "(", "' %s => Enum::getValues(%s),%s'", ",", "Php", "::", "varExport", "(", "$", "column", ")", ",", "Php", "::", "varExport", "(", "$", "enumName", ")", ",", "\"\\n\"", ")", ";", "}", "$", "allowedValuesPhp", ".=", "\" )\\n);\"", ";", "$", "allowedValuesPhp", "=", "new", "Format", "(", "$", "allowedValuesPhp", ")", ";", "}", "// require block", "$", "requiredPhp", "=", "new", "Format", "(", ")", ";", "if", "(", "$", "required", ")", "{", "$", "requiredPhp", "=", "\"\\n\\$resolver->setRequired(\\n\"", ".", "(", "new", "Format", "(", "Php", "::", "varExport", "(", "$", "required", ")", ")", ")", "->", "indent", "(", "4", ")", ".", "\"\\n);\"", ";", "$", "requiredPhp", "=", "new", "Format", "(", "$", "requiredPhp", ")", ";", "$", "requiredPhp", "->", "indent", "(", "24", ")", ";", "}", "// optional", "$", "optionalPhp", "=", "new", "Format", "(", ")", ";", "if", "(", "$", "optional", ")", "{", "$", "optionalPhp", "=", "\"\\n\\$resolver->setOptional(\\n\"", ".", "(", "new", "Format", "(", "Php", "::", "varExport", "(", "$", "optional", ")", ")", ")", "->", "indent", "(", "4", ")", ".", "\"\\n);\"", ";", "$", "optionalPhp", "=", "new", "Format", "(", "$", "optionalPhp", ")", ";", "$", "optionalPhp", "->", "indent", "(", "24", ")", ";", "}", "$", "this", "->", "class", "->", "addUses", "(", "'Symfony\\Component\\OptionsResolver\\OptionsResolver'", ")", ";", "$", "this", "->", "class", "->", "classComponents", "[", "]", "=", "new", "FunctionDeclaration", "(", "'resolverGet'", ",", "new", "Sformatf", "(", " <<<'PHP'\n /**\n * Resolver getter. Singleton\n * @return Symfony\\Component\\Options\\Resolver\n */\n public function resolverGet()\n {\n // do we already have a resolver instance\n if( !$this->resolver ) {\n\n $resolver = new OptionsResolver();%s%s%s\n $this->resolver = $resolver;\n\n }\n return $this->resolver;\n }\nPHP", ",", "$", "requiredPhp", ",", "$", "optionalPhp", ",", "$", "allowedValuesPhp", ")", ")", ";", "$", "this", "->", "class", "->", "classComponents", "[", "]", "=", "new", "VariableDeclaration", "(", "'resolver'", ",", "new", "SFormatf", "(", " <<<'PHP'\n /**\n * Options Resolver\n * @var array\n */\n private $resolver;\nPHP", ")", ")", ";", "}" ]
Generate a get Options Resolver component for the enity
[ "Generate", "a", "get", "Options", "Resolver", "component", "for", "the", "enity" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/Builder/Repository.php#L504-L601
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssParser.getAndClearBuffer
public function getAndClearBuffer($trim = "", $tolower = false) { $r = $this->getBuffer($trim, $tolower); $this->buffer = ""; return $r; }
php
public function getAndClearBuffer($trim = "", $tolower = false) { $r = $this->getBuffer($trim, $tolower); $this->buffer = ""; return $r; }
[ "public", "function", "getAndClearBuffer", "(", "$", "trim", "=", "\"\"", ",", "$", "tolower", "=", "false", ")", "{", "$", "r", "=", "$", "this", "->", "getBuffer", "(", "$", "trim", ",", "$", "tolower", ")", ";", "$", "this", "->", "buffer", "=", "\"\"", ";", "return", "$", "r", ";", "}" ]
Returns and clear the current buffer. @param string $trim Chars to use to trim the returned buffer @param boolean $tolower if TRUE the returned buffer will get converted to lower case @return string
[ "Returns", "and", "clear", "the", "current", "buffer", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L1502-L1507
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssParser.getPlugin
public function getPlugin($class) { static $index = null; if (is_null($index)) { $index = array(); for ($i = 0, $l = count($this->plugins); $i < $l; $i++) { $index[get_class($this->plugins[$i])] = $i; } } return isset($index[$class]) ? $this->plugins[$index[$class]] : false; }
php
public function getPlugin($class) { static $index = null; if (is_null($index)) { $index = array(); for ($i = 0, $l = count($this->plugins); $i < $l; $i++) { $index[get_class($this->plugins[$i])] = $i; } } return isset($index[$class]) ? $this->plugins[$index[$class]] : false; }
[ "public", "function", "getPlugin", "(", "$", "class", ")", "{", "static", "$", "index", "=", "null", ";", "if", "(", "is_null", "(", "$", "index", ")", ")", "{", "$", "index", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ",", "$", "l", "=", "count", "(", "$", "this", "->", "plugins", ")", ";", "$", "i", "<", "$", "l", ";", "$", "i", "++", ")", "{", "$", "index", "[", "get_class", "(", "$", "this", "->", "plugins", "[", "$", "i", "]", ")", "]", "=", "$", "i", ";", "}", "}", "return", "isset", "(", "$", "index", "[", "$", "class", "]", ")", "?", "$", "this", "->", "plugins", "[", "$", "index", "[", "$", "class", "]", "]", ":", "false", ";", "}" ]
Returns a plugin by class name. @param string $name Class name of the plugin @return aCssParserPlugin
[ "Returns", "a", "plugin", "by", "class", "name", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L1561-L1573
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssParser.popState
public function popState() { $r = array_pop($this->states); $this->state = $this->states[count($this->states) - 1]; return $r; }
php
public function popState() { $r = array_pop($this->states); $this->state = $this->states[count($this->states) - 1]; return $r; }
[ "public", "function", "popState", "(", ")", "{", "$", "r", "=", "array_pop", "(", "$", "this", "->", "states", ")", ";", "$", "this", "->", "state", "=", "$", "this", "->", "states", "[", "count", "(", "$", "this", "->", "states", ")", "-", "1", "]", ";", "return", "$", "r", ";", "}" ]
Remove the last state of the state stack and return the removed stack value. @return integer Removed state value
[ "Remove", "the", "last", "state", "of", "the", "state", "stack", "and", "return", "the", "removed", "stack", "value", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L1713-L1718
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssParser.pushState
public function pushState($state) { $r = array_push($this->states, $state); $this->state = $this->states[count($this->states) - 1]; return $r; }
php
public function pushState($state) { $r = array_push($this->states, $state); $this->state = $this->states[count($this->states) - 1]; return $r; }
[ "public", "function", "pushState", "(", "$", "state", ")", "{", "$", "r", "=", "array_push", "(", "$", "this", "->", "states", ",", "$", "state", ")", ";", "$", "this", "->", "state", "=", "$", "this", "->", "states", "[", "count", "(", "$", "this", "->", "states", ")", "-", "1", "]", ";", "return", "$", "r", ";", "}" ]
Adds a new state onto the state stack. @param integer $state State to add onto the state stack. @return integer The index of the added state in the state stacks
[ "Adds", "a", "new", "state", "onto", "the", "state", "stack", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L1725-L1730
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssMinifier.minify
public function minify($source) { // Variables $r = ""; $parser = new CssParser($source); $tokens = $parser->getTokens(); $filters = $this->filters; $filterCount = count($this->filters); $plugins = $this->plugins; $pluginCount = count($plugins); $pluginIndex = array(); $pluginTriggerTokens = array(); $globalTriggerTokens = array(); for ($i = 0, $l = count($plugins); $i < $l; $i++) { $tPluginClassName = get_class($plugins[$i]); $pluginTriggerTokens[$i] = $plugins[$i]->getTriggerTokens(); foreach ($pluginTriggerTokens[$i] as $v) { if (!in_array($v, $globalTriggerTokens)) { $globalTriggerTokens[] = $v; } } $pluginTriggerTokens[$i] = "|" . implode("|", $pluginTriggerTokens[$i]) . "|"; $pluginIndex[$tPluginClassName] = $i; } $globalTriggerTokens = "|" . implode("|", $globalTriggerTokens) . "|"; /* * Apply filters */ for($i = 0; $i < $filterCount; $i++) { // Apply the filter; if the return value is larger than 0... if ($filters[$i]->apply($tokens) > 0) { // ...then filter null values and rebuild the token array $tokens = array_values(array_filter($tokens)); } } $tokenCount = count($tokens); /* * Apply plugins */ for($i = 0; $i < $tokenCount; $i++) { $triggerToken = "|" . get_class($tokens[$i]) . "|"; if (strpos($globalTriggerTokens, $triggerToken) !== false) { for($ii = 0; $ii < $pluginCount; $ii++) { if (strpos($pluginTriggerTokens[$ii], $triggerToken) !== false || $pluginTriggerTokens[$ii] === false) { // Apply the plugin; if the return value is TRUE continue to the next token if ($plugins[$ii]->apply($tokens[$i]) === true) { continue 2; } } } } } // Stringify the tokens for($i = 0; $i < $tokenCount; $i++) { $r .= (string) $tokens[$i]; } $this->minified = $r; return $r; }
php
public function minify($source) { // Variables $r = ""; $parser = new CssParser($source); $tokens = $parser->getTokens(); $filters = $this->filters; $filterCount = count($this->filters); $plugins = $this->plugins; $pluginCount = count($plugins); $pluginIndex = array(); $pluginTriggerTokens = array(); $globalTriggerTokens = array(); for ($i = 0, $l = count($plugins); $i < $l; $i++) { $tPluginClassName = get_class($plugins[$i]); $pluginTriggerTokens[$i] = $plugins[$i]->getTriggerTokens(); foreach ($pluginTriggerTokens[$i] as $v) { if (!in_array($v, $globalTriggerTokens)) { $globalTriggerTokens[] = $v; } } $pluginTriggerTokens[$i] = "|" . implode("|", $pluginTriggerTokens[$i]) . "|"; $pluginIndex[$tPluginClassName] = $i; } $globalTriggerTokens = "|" . implode("|", $globalTriggerTokens) . "|"; /* * Apply filters */ for($i = 0; $i < $filterCount; $i++) { // Apply the filter; if the return value is larger than 0... if ($filters[$i]->apply($tokens) > 0) { // ...then filter null values and rebuild the token array $tokens = array_values(array_filter($tokens)); } } $tokenCount = count($tokens); /* * Apply plugins */ for($i = 0; $i < $tokenCount; $i++) { $triggerToken = "|" . get_class($tokens[$i]) . "|"; if (strpos($globalTriggerTokens, $triggerToken) !== false) { for($ii = 0; $ii < $pluginCount; $ii++) { if (strpos($pluginTriggerTokens[$ii], $triggerToken) !== false || $pluginTriggerTokens[$ii] === false) { // Apply the plugin; if the return value is TRUE continue to the next token if ($plugins[$ii]->apply($tokens[$i]) === true) { continue 2; } } } } } // Stringify the tokens for($i = 0; $i < $tokenCount; $i++) { $r .= (string) $tokens[$i]; } $this->minified = $r; return $r; }
[ "public", "function", "minify", "(", "$", "source", ")", "{", "// Variables\r", "$", "r", "=", "\"\"", ";", "$", "parser", "=", "new", "CssParser", "(", "$", "source", ")", ";", "$", "tokens", "=", "$", "parser", "->", "getTokens", "(", ")", ";", "$", "filters", "=", "$", "this", "->", "filters", ";", "$", "filterCount", "=", "count", "(", "$", "this", "->", "filters", ")", ";", "$", "plugins", "=", "$", "this", "->", "plugins", ";", "$", "pluginCount", "=", "count", "(", "$", "plugins", ")", ";", "$", "pluginIndex", "=", "array", "(", ")", ";", "$", "pluginTriggerTokens", "=", "array", "(", ")", ";", "$", "globalTriggerTokens", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ",", "$", "l", "=", "count", "(", "$", "plugins", ")", ";", "$", "i", "<", "$", "l", ";", "$", "i", "++", ")", "{", "$", "tPluginClassName", "=", "get_class", "(", "$", "plugins", "[", "$", "i", "]", ")", ";", "$", "pluginTriggerTokens", "[", "$", "i", "]", "=", "$", "plugins", "[", "$", "i", "]", "->", "getTriggerTokens", "(", ")", ";", "foreach", "(", "$", "pluginTriggerTokens", "[", "$", "i", "]", "as", "$", "v", ")", "{", "if", "(", "!", "in_array", "(", "$", "v", ",", "$", "globalTriggerTokens", ")", ")", "{", "$", "globalTriggerTokens", "[", "]", "=", "$", "v", ";", "}", "}", "$", "pluginTriggerTokens", "[", "$", "i", "]", "=", "\"|\"", ".", "implode", "(", "\"|\"", ",", "$", "pluginTriggerTokens", "[", "$", "i", "]", ")", ".", "\"|\"", ";", "$", "pluginIndex", "[", "$", "tPluginClassName", "]", "=", "$", "i", ";", "}", "$", "globalTriggerTokens", "=", "\"|\"", ".", "implode", "(", "\"|\"", ",", "$", "globalTriggerTokens", ")", ".", "\"|\"", ";", "/*\r\n\t\t * Apply filters\r\n\t\t */", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "filterCount", ";", "$", "i", "++", ")", "{", "// Apply the filter; if the return value is larger than 0...\r", "if", "(", "$", "filters", "[", "$", "i", "]", "->", "apply", "(", "$", "tokens", ")", ">", "0", ")", "{", "// ...then filter null values and rebuild the token array\r", "$", "tokens", "=", "array_values", "(", "array_filter", "(", "$", "tokens", ")", ")", ";", "}", "}", "$", "tokenCount", "=", "count", "(", "$", "tokens", ")", ";", "/*\r\n\t\t * Apply plugins\r\n\t\t */", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "tokenCount", ";", "$", "i", "++", ")", "{", "$", "triggerToken", "=", "\"|\"", ".", "get_class", "(", "$", "tokens", "[", "$", "i", "]", ")", ".", "\"|\"", ";", "if", "(", "strpos", "(", "$", "globalTriggerTokens", ",", "$", "triggerToken", ")", "!==", "false", ")", "{", "for", "(", "$", "ii", "=", "0", ";", "$", "ii", "<", "$", "pluginCount", ";", "$", "ii", "++", ")", "{", "if", "(", "strpos", "(", "$", "pluginTriggerTokens", "[", "$", "ii", "]", ",", "$", "triggerToken", ")", "!==", "false", "||", "$", "pluginTriggerTokens", "[", "$", "ii", "]", "===", "false", ")", "{", "// Apply the plugin; if the return value is TRUE continue to the next token\r", "if", "(", "$", "plugins", "[", "$", "ii", "]", "->", "apply", "(", "$", "tokens", "[", "$", "i", "]", ")", "===", "true", ")", "{", "continue", "2", ";", "}", "}", "}", "}", "}", "// Stringify the tokens\r", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "tokenCount", ";", "$", "i", "++", ")", "{", "$", "r", ".=", "(", "string", ")", "$", "tokens", "[", "$", "i", "]", ";", "}", "$", "this", "->", "minified", "=", "$", "r", ";", "return", "$", "r", ";", "}" ]
Minifies the CSS source. @param string $source CSS source @return string
[ "Minifies", "the", "CSS", "source", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L2058-L2127
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssMin.initialise
public static function initialise() { // Create the class index for autoloading or including $paths = array(dirname(__FILE__)); while (list($i, $path) = each($paths)) { $subDirectorys = glob($path . "*", GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT); if (is_array($subDirectorys)) { foreach ($subDirectorys as $subDirectory) { $paths[] = $subDirectory; } } $files = glob($path . "*.php", 0); if (is_array($files)) { foreach ($files as $file) { $class = substr(basename($file), 0, -4); self::$classIndex[$class] = $file; } } } krsort(self::$classIndex); // Only use autoloading if spl_autoload_register() is available and no __autoload() is defined (because // __autoload() breaks if spl_autoload_register() is used. if (function_exists("spl_autoload_register") && !is_callable("__autoload")) { spl_autoload_register(array(__CLASS__, "autoload")); } // Otherwise include all class files else { foreach (self::$classIndex as $class => $file) { if (!class_exists($class)) { require_once($file); } } } }
php
public static function initialise() { // Create the class index for autoloading or including $paths = array(dirname(__FILE__)); while (list($i, $path) = each($paths)) { $subDirectorys = glob($path . "*", GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT); if (is_array($subDirectorys)) { foreach ($subDirectorys as $subDirectory) { $paths[] = $subDirectory; } } $files = glob($path . "*.php", 0); if (is_array($files)) { foreach ($files as $file) { $class = substr(basename($file), 0, -4); self::$classIndex[$class] = $file; } } } krsort(self::$classIndex); // Only use autoloading if spl_autoload_register() is available and no __autoload() is defined (because // __autoload() breaks if spl_autoload_register() is used. if (function_exists("spl_autoload_register") && !is_callable("__autoload")) { spl_autoload_register(array(__CLASS__, "autoload")); } // Otherwise include all class files else { foreach (self::$classIndex as $class => $file) { if (!class_exists($class)) { require_once($file); } } } }
[ "public", "static", "function", "initialise", "(", ")", "{", "// Create the class index for autoloading or including\r", "$", "paths", "=", "array", "(", "dirname", "(", "__FILE__", ")", ")", ";", "while", "(", "list", "(", "$", "i", ",", "$", "path", ")", "=", "each", "(", "$", "paths", ")", ")", "{", "$", "subDirectorys", "=", "glob", "(", "$", "path", ".", "\"*\"", ",", "GLOB_MARK", "|", "GLOB_ONLYDIR", "|", "GLOB_NOSORT", ")", ";", "if", "(", "is_array", "(", "$", "subDirectorys", ")", ")", "{", "foreach", "(", "$", "subDirectorys", "as", "$", "subDirectory", ")", "{", "$", "paths", "[", "]", "=", "$", "subDirectory", ";", "}", "}", "$", "files", "=", "glob", "(", "$", "path", ".", "\"*.php\"", ",", "0", ")", ";", "if", "(", "is_array", "(", "$", "files", ")", ")", "{", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "class", "=", "substr", "(", "basename", "(", "$", "file", ")", ",", "0", ",", "-", "4", ")", ";", "self", "::", "$", "classIndex", "[", "$", "class", "]", "=", "$", "file", ";", "}", "}", "}", "krsort", "(", "self", "::", "$", "classIndex", ")", ";", "// Only use autoloading if spl_autoload_register() is available and no __autoload() is defined (because \r", "// __autoload() breaks if spl_autoload_register() is used. \r", "if", "(", "function_exists", "(", "\"spl_autoload_register\"", ")", "&&", "!", "is_callable", "(", "\"__autoload\"", ")", ")", "{", "spl_autoload_register", "(", "array", "(", "__CLASS__", ",", "\"autoload\"", ")", ")", ";", "}", "// Otherwise include all class files\r", "else", "{", "foreach", "(", "self", "::", "$", "classIndex", "as", "$", "class", "=>", "$", "file", ")", "{", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "require_once", "(", "$", "file", ")", ";", "}", "}", "}", "}" ]
Initialises CssMin. @return void
[ "Initialises", "CssMin", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L2218-L2260
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssMin.minify
public static function minify($source, array $filters = null, array $plugins = null) { self::$errors = array(); $minifier = new CssMinifier($source, $filters, $plugins); return $minifier->getMinified(); }
php
public static function minify($source, array $filters = null, array $plugins = null) { self::$errors = array(); $minifier = new CssMinifier($source, $filters, $plugins); return $minifier->getMinified(); }
[ "public", "static", "function", "minify", "(", "$", "source", ",", "array", "$", "filters", "=", "null", ",", "array", "$", "plugins", "=", "null", ")", "{", "self", "::", "$", "errors", "=", "array", "(", ")", ";", "$", "minifier", "=", "new", "CssMinifier", "(", "$", "source", ",", "$", "filters", ",", "$", "plugins", ")", ";", "return", "$", "minifier", "->", "getMinified", "(", ")", ";", "}" ]
Minifies CSS source. @param string $source CSS source @param array $filters Filter configuration [optional] @param array $plugins Plugin configuration [optional] @return string Minified CSS
[ "Minifies", "CSS", "source", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L2269-L2274
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssMin.parse
public static function parse($source, array $plugins = null) { self::$errors = array(); $parser = new CssParser($source, $plugins); return $parser->getTokens(); }
php
public static function parse($source, array $plugins = null) { self::$errors = array(); $parser = new CssParser($source, $plugins); return $parser->getTokens(); }
[ "public", "static", "function", "parse", "(", "$", "source", ",", "array", "$", "plugins", "=", "null", ")", "{", "self", "::", "$", "errors", "=", "array", "(", ")", ";", "$", "parser", "=", "new", "CssParser", "(", "$", "source", ",", "$", "plugins", ")", ";", "return", "$", "parser", "->", "getTokens", "(", ")", ";", "}" ]
Parse the CSS source. @param string $source CSS source @param array $plugins Plugin configuration [optional] @return array Array of aCssToken
[ "Parse", "the", "CSS", "source", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L2282-L2287
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssConvertHslColorsMinifierPlugin.hsl2hex
private function hsl2hex($hue, $saturation, $lightness) { $hue = $hue / 360; $saturation = $saturation / 100; $lightness = $lightness / 100; if ($saturation == 0) { $red = $lightness * 255; $green = $lightness * 255; $blue = $lightness * 255; } else { if ($lightness < 0.5 ) { $v2 = $lightness * (1 + $saturation); } else { $v2 = ($lightness + $saturation) - ($saturation * $lightness); } $v1 = 2 * $lightness - $v2; $red = 255 * self::hue2rgb($v1, $v2, $hue + (1 / 3)); $green = 255 * self::hue2rgb($v1, $v2, $hue); $blue = 255 * self::hue2rgb($v1, $v2, $hue - (1 / 3)); } return "#" . str_pad(dechex(round($red)), 2, "0", STR_PAD_LEFT) . str_pad(dechex(round($green)), 2, "0", STR_PAD_LEFT) . str_pad(dechex(round($blue)), 2, "0", STR_PAD_LEFT); }
php
private function hsl2hex($hue, $saturation, $lightness) { $hue = $hue / 360; $saturation = $saturation / 100; $lightness = $lightness / 100; if ($saturation == 0) { $red = $lightness * 255; $green = $lightness * 255; $blue = $lightness * 255; } else { if ($lightness < 0.5 ) { $v2 = $lightness * (1 + $saturation); } else { $v2 = ($lightness + $saturation) - ($saturation * $lightness); } $v1 = 2 * $lightness - $v2; $red = 255 * self::hue2rgb($v1, $v2, $hue + (1 / 3)); $green = 255 * self::hue2rgb($v1, $v2, $hue); $blue = 255 * self::hue2rgb($v1, $v2, $hue - (1 / 3)); } return "#" . str_pad(dechex(round($red)), 2, "0", STR_PAD_LEFT) . str_pad(dechex(round($green)), 2, "0", STR_PAD_LEFT) . str_pad(dechex(round($blue)), 2, "0", STR_PAD_LEFT); }
[ "private", "function", "hsl2hex", "(", "$", "hue", ",", "$", "saturation", ",", "$", "lightness", ")", "{", "$", "hue", "=", "$", "hue", "/", "360", ";", "$", "saturation", "=", "$", "saturation", "/", "100", ";", "$", "lightness", "=", "$", "lightness", "/", "100", ";", "if", "(", "$", "saturation", "==", "0", ")", "{", "$", "red", "=", "$", "lightness", "*", "255", ";", "$", "green", "=", "$", "lightness", "*", "255", ";", "$", "blue", "=", "$", "lightness", "*", "255", ";", "}", "else", "{", "if", "(", "$", "lightness", "<", "0.5", ")", "{", "$", "v2", "=", "$", "lightness", "*", "(", "1", "+", "$", "saturation", ")", ";", "}", "else", "{", "$", "v2", "=", "(", "$", "lightness", "+", "$", "saturation", ")", "-", "(", "$", "saturation", "*", "$", "lightness", ")", ";", "}", "$", "v1", "=", "2", "*", "$", "lightness", "-", "$", "v2", ";", "$", "red", "=", "255", "*", "self", "::", "hue2rgb", "(", "$", "v1", ",", "$", "v2", ",", "$", "hue", "+", "(", "1", "/", "3", ")", ")", ";", "$", "green", "=", "255", "*", "self", "::", "hue2rgb", "(", "$", "v1", ",", "$", "v2", ",", "$", "hue", ")", ";", "$", "blue", "=", "255", "*", "self", "::", "hue2rgb", "(", "$", "v1", ",", "$", "v2", ",", "$", "hue", "-", "(", "1", "/", "3", ")", ")", ";", "}", "return", "\"#\"", ".", "str_pad", "(", "dechex", "(", "round", "(", "$", "red", ")", ")", ",", "2", ",", "\"0\"", ",", "STR_PAD_LEFT", ")", ".", "str_pad", "(", "dechex", "(", "round", "(", "$", "green", ")", ")", ",", "2", ",", "\"0\"", ",", "STR_PAD_LEFT", ")", ".", "str_pad", "(", "dechex", "(", "round", "(", "$", "blue", ")", ")", ",", "2", ",", "\"0\"", ",", "STR_PAD_LEFT", ")", ";", "}" ]
Convert a HSL value to hexadecimal notation. Based on: {@link http://www.easyrgb.com/index.php?X=MATH&H=19#text19}. @param integer $hue Hue @param integer $saturation Saturation @param integer $lightness Lightnesss @return string
[ "Convert", "a", "HSL", "value", "to", "hexadecimal", "notation", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L3442-L3469
train
crodas/SimpleAssetManager
lib/crodas/Contrib/cssmin-v3.0.1.php
CssConvertHslColorsMinifierPlugin.hue2rgb
private function hue2rgb($v1, $v2, $hue) { if ($hue < 0) { $hue += 1; } if ($hue > 1) { $hue -= 1; } if ((6 * $hue) < 1) { return ($v1 + ($v2 - $v1) * 6 * $hue); } if ((2 * $hue) < 1) { return ($v2); } if ((3 * $hue) < 2) { return ($v1 + ($v2 - $v1) * (( 2 / 3) - $hue) * 6); } return $v1; }
php
private function hue2rgb($v1, $v2, $hue) { if ($hue < 0) { $hue += 1; } if ($hue > 1) { $hue -= 1; } if ((6 * $hue) < 1) { return ($v1 + ($v2 - $v1) * 6 * $hue); } if ((2 * $hue) < 1) { return ($v2); } if ((3 * $hue) < 2) { return ($v1 + ($v2 - $v1) * (( 2 / 3) - $hue) * 6); } return $v1; }
[ "private", "function", "hue2rgb", "(", "$", "v1", ",", "$", "v2", ",", "$", "hue", ")", "{", "if", "(", "$", "hue", "<", "0", ")", "{", "$", "hue", "+=", "1", ";", "}", "if", "(", "$", "hue", ">", "1", ")", "{", "$", "hue", "-=", "1", ";", "}", "if", "(", "(", "6", "*", "$", "hue", ")", "<", "1", ")", "{", "return", "(", "$", "v1", "+", "(", "$", "v2", "-", "$", "v1", ")", "*", "6", "*", "$", "hue", ")", ";", "}", "if", "(", "(", "2", "*", "$", "hue", ")", "<", "1", ")", "{", "return", "(", "$", "v2", ")", ";", "}", "if", "(", "(", "3", "*", "$", "hue", ")", "<", "2", ")", "{", "return", "(", "$", "v1", "+", "(", "$", "v2", "-", "$", "v1", ")", "*", "(", "(", "2", "/", "3", ")", "-", "$", "hue", ")", "*", "6", ")", ";", "}", "return", "$", "v1", ";", "}" ]
Apply hue to a rgb color value. @param integer $v1 Value 1 @param integer $v2 Value 2 @param integer $hue Hue @return integer
[ "Apply", "hue", "to", "a", "rgb", "color", "value", "." ]
a81661cc5739fa15c0ed7b6809b392b955c26401
https://github.com/crodas/SimpleAssetManager/blob/a81661cc5739fa15c0ed7b6809b392b955c26401/lib/crodas/Contrib/cssmin-v3.0.1.php#L3478-L3501
train
praxigento/mobi_mod_downline
Repo/Dao/Change.php
Change.getChangelogMinDate
public function getChangelogMinDate() { $result = null; $asChange = 'c'; $tblChange = $this->resource->getTableName(EChange::ENTITY_NAME); /* select from account */ $query = $this->conn->select(); $query->from([$asChange => $tblChange], [EChange::A_DATE_CHANGED]); /* order by */ $query->order([$asChange . '.' . EChange::A_DATE_CHANGED . ' ASC']); /* perform query */ $result = $this->conn->fetchOne($query); if ($result < self::DATE_MIN) { $result = self::DATE_MIN; } return $result; }
php
public function getChangelogMinDate() { $result = null; $asChange = 'c'; $tblChange = $this->resource->getTableName(EChange::ENTITY_NAME); /* select from account */ $query = $this->conn->select(); $query->from([$asChange => $tblChange], [EChange::A_DATE_CHANGED]); /* order by */ $query->order([$asChange . '.' . EChange::A_DATE_CHANGED . ' ASC']); /* perform query */ $result = $this->conn->fetchOne($query); if ($result < self::DATE_MIN) { $result = self::DATE_MIN; } return $result; }
[ "public", "function", "getChangelogMinDate", "(", ")", "{", "$", "result", "=", "null", ";", "$", "asChange", "=", "'c'", ";", "$", "tblChange", "=", "$", "this", "->", "resource", "->", "getTableName", "(", "EChange", "::", "ENTITY_NAME", ")", ";", "/* select from account */", "$", "query", "=", "$", "this", "->", "conn", "->", "select", "(", ")", ";", "$", "query", "->", "from", "(", "[", "$", "asChange", "=>", "$", "tblChange", "]", ",", "[", "EChange", "::", "A_DATE_CHANGED", "]", ")", ";", "/* order by */", "$", "query", "->", "order", "(", "[", "$", "asChange", ".", "'.'", ".", "EChange", "::", "A_DATE_CHANGED", ".", "' ASC'", "]", ")", ";", "/* perform query */", "$", "result", "=", "$", "this", "->", "conn", "->", "fetchOne", "(", "$", "query", ")", ";", "if", "(", "$", "result", "<", "self", "::", "DATE_MIN", ")", "{", "$", "result", "=", "self", "::", "DATE_MIN", ";", "}", "return", "$", "result", ";", "}" ]
Select MIN date for the existing change log. SELECT `c`.`date_changed` FROM `prxgt_dwnl_change` AS `c` ORDER BY `c`.`date_changed` ASC @return string|null
[ "Select", "MIN", "date", "for", "the", "existing", "change", "log", "." ]
0f3c276dfff1aa029f9fd205ccfc56f207a2e75b
https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Repo/Dao/Change.php#L54-L70
train
modulusphp/utility
Accessor.php
Accessor.requireView
public static function requireView() : void { $medusa = new Medusa(self::$viewsEngine); $medusa->setCacheDirectory(self::$viewsCache); $medusa->setViewsDirectory(self::$viewsDirectory); $medusa->setViewsExtension(self::$viewsExtension); $medusa->register(Partial::class); $medusa->register(Using::class); $medusa->register(Csrf::class); $medusa->register(ConfigToJsonString::class); if (class_exists(DirectivesResolver::class)) { (new DirectivesResolver)->start([ 'view' => $medusa ]); } self::$viewComponent = $medusa; }
php
public static function requireView() : void { $medusa = new Medusa(self::$viewsEngine); $medusa->setCacheDirectory(self::$viewsCache); $medusa->setViewsDirectory(self::$viewsDirectory); $medusa->setViewsExtension(self::$viewsExtension); $medusa->register(Partial::class); $medusa->register(Using::class); $medusa->register(Csrf::class); $medusa->register(ConfigToJsonString::class); if (class_exists(DirectivesResolver::class)) { (new DirectivesResolver)->start([ 'view' => $medusa ]); } self::$viewComponent = $medusa; }
[ "public", "static", "function", "requireView", "(", ")", ":", "void", "{", "$", "medusa", "=", "new", "Medusa", "(", "self", "::", "$", "viewsEngine", ")", ";", "$", "medusa", "->", "setCacheDirectory", "(", "self", "::", "$", "viewsCache", ")", ";", "$", "medusa", "->", "setViewsDirectory", "(", "self", "::", "$", "viewsDirectory", ")", ";", "$", "medusa", "->", "setViewsExtension", "(", "self", "::", "$", "viewsExtension", ")", ";", "$", "medusa", "->", "register", "(", "Partial", "::", "class", ")", ";", "$", "medusa", "->", "register", "(", "Using", "::", "class", ")", ";", "$", "medusa", "->", "register", "(", "Csrf", "::", "class", ")", ";", "$", "medusa", "->", "register", "(", "ConfigToJsonString", "::", "class", ")", ";", "if", "(", "class_exists", "(", "DirectivesResolver", "::", "class", ")", ")", "{", "(", "new", "DirectivesResolver", ")", "->", "start", "(", "[", "'view'", "=>", "$", "medusa", "]", ")", ";", "}", "self", "::", "$", "viewComponent", "=", "$", "medusa", ";", "}" ]
Create a new Medusa Object @return void
[ "Create", "a", "new", "Medusa", "Object" ]
c1e127539b13d3ec8381e41c64b881e0701807f5
https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/Accessor.php#L62-L82
train
erenmustafaozdal/laravel-modules-base
src/Exceptions/Handler.php
Handler.getEmailDatas
private function getEmailDatas($request, $e) { $session = $request->session()->all(); return [ 'date' => Carbon::now()->format('d.m.Y H:i:s'), 'rUser' => $request->user(), 'rSessionOld' => isset($session['flash']) ? $session['flash']['old'] : [], 'rSessionNew' => isset($session['flash']) ? $session['flash']['new'] : [], 'rAll' => $request->all(), 'rIp' => $request->ip(), 'rDecodedPath' => $request->decodedPath(), 'rPath' => $request->path(), 'rFullUrl' => $request->fullUrl(), 'rUrl' => $request->url(), 'rRoot' => $request->root(), 'rMethod' => $request->method(), 'eMessage' => method_exists($e, 'getMessage') ? $e->getMessage() : '', 'eCode' => method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 200, 'eFile' => method_exists($e, 'getFile') ? $e->getFile() : '', 'eLine' => method_exists($e, 'getLine') ? $e->getLine() : '', 'ePrevious' => is_string($e->getPrevious()) ? $e->getPrevious() : '', 'eTrace' => nl2br($e->getTraceAsString()), ]; }
php
private function getEmailDatas($request, $e) { $session = $request->session()->all(); return [ 'date' => Carbon::now()->format('d.m.Y H:i:s'), 'rUser' => $request->user(), 'rSessionOld' => isset($session['flash']) ? $session['flash']['old'] : [], 'rSessionNew' => isset($session['flash']) ? $session['flash']['new'] : [], 'rAll' => $request->all(), 'rIp' => $request->ip(), 'rDecodedPath' => $request->decodedPath(), 'rPath' => $request->path(), 'rFullUrl' => $request->fullUrl(), 'rUrl' => $request->url(), 'rRoot' => $request->root(), 'rMethod' => $request->method(), 'eMessage' => method_exists($e, 'getMessage') ? $e->getMessage() : '', 'eCode' => method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 200, 'eFile' => method_exists($e, 'getFile') ? $e->getFile() : '', 'eLine' => method_exists($e, 'getLine') ? $e->getLine() : '', 'ePrevious' => is_string($e->getPrevious()) ? $e->getPrevious() : '', 'eTrace' => nl2br($e->getTraceAsString()), ]; }
[ "private", "function", "getEmailDatas", "(", "$", "request", ",", "$", "e", ")", "{", "$", "session", "=", "$", "request", "->", "session", "(", ")", "->", "all", "(", ")", ";", "return", "[", "'date'", "=>", "Carbon", "::", "now", "(", ")", "->", "format", "(", "'d.m.Y H:i:s'", ")", ",", "'rUser'", "=>", "$", "request", "->", "user", "(", ")", ",", "'rSessionOld'", "=>", "isset", "(", "$", "session", "[", "'flash'", "]", ")", "?", "$", "session", "[", "'flash'", "]", "[", "'old'", "]", ":", "[", "]", ",", "'rSessionNew'", "=>", "isset", "(", "$", "session", "[", "'flash'", "]", ")", "?", "$", "session", "[", "'flash'", "]", "[", "'new'", "]", ":", "[", "]", ",", "'rAll'", "=>", "$", "request", "->", "all", "(", ")", ",", "'rIp'", "=>", "$", "request", "->", "ip", "(", ")", ",", "'rDecodedPath'", "=>", "$", "request", "->", "decodedPath", "(", ")", ",", "'rPath'", "=>", "$", "request", "->", "path", "(", ")", ",", "'rFullUrl'", "=>", "$", "request", "->", "fullUrl", "(", ")", ",", "'rUrl'", "=>", "$", "request", "->", "url", "(", ")", ",", "'rRoot'", "=>", "$", "request", "->", "root", "(", ")", ",", "'rMethod'", "=>", "$", "request", "->", "method", "(", ")", ",", "'eMessage'", "=>", "method_exists", "(", "$", "e", ",", "'getMessage'", ")", "?", "$", "e", "->", "getMessage", "(", ")", ":", "''", ",", "'eCode'", "=>", "method_exists", "(", "$", "e", ",", "'getStatusCode'", ")", "?", "$", "e", "->", "getStatusCode", "(", ")", ":", "200", ",", "'eFile'", "=>", "method_exists", "(", "$", "e", ",", "'getFile'", ")", "?", "$", "e", "->", "getFile", "(", ")", ":", "''", ",", "'eLine'", "=>", "method_exists", "(", "$", "e", ",", "'getLine'", ")", "?", "$", "e", "->", "getLine", "(", ")", ":", "''", ",", "'ePrevious'", "=>", "is_string", "(", "$", "e", "->", "getPrevious", "(", ")", ")", "?", "$", "e", "->", "getPrevious", "(", ")", ":", "''", ",", "'eTrace'", "=>", "nl2br", "(", "$", "e", "->", "getTraceAsString", "(", ")", ")", ",", "]", ";", "}" ]
get error email datas @param \Illuminate\Http\Request $request @param Exception $e @return array
[ "get", "error", "email", "datas" ]
c26600543817642926bcf16ada84009e00d784e0
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Exceptions/Handler.php#L89-L112
train
horntell/php-sdk
src/Horntell/Campaign.php
Campaign.toProfiles
public function toProfiles($profiles, $campaignId, $meta = []) { $data = ['profile_uids' => $profiles, 'meta' => $meta]; return $this->request->send('POST', "profiles/campaigns/$campaignId", $data); }
php
public function toProfiles($profiles, $campaignId, $meta = []) { $data = ['profile_uids' => $profiles, 'meta' => $meta]; return $this->request->send('POST', "profiles/campaigns/$campaignId", $data); }
[ "public", "function", "toProfiles", "(", "$", "profiles", ",", "$", "campaignId", ",", "$", "meta", "=", "[", "]", ")", "{", "$", "data", "=", "[", "'profile_uids'", "=>", "$", "profiles", ",", "'meta'", "=>", "$", "meta", "]", ";", "return", "$", "this", "->", "request", "->", "send", "(", "'POST'", ",", "\"profiles/campaigns/$campaignId\"", ",", "$", "data", ")", ";", "}" ]
Triggers campaign for multiple profiles @param array $profiles @param string $campaignId @param array $meta @return Horntell\Http\Response
[ "Triggers", "campaign", "for", "multiple", "profiles" ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/src/Horntell/Campaign.php#L41-L46
train
horntell/php-sdk
src/Horntell/Campaign.php
Campaign.toChannels
public function toChannels($channels, $campaignId, $meta = []) { $data = ['channel_uids' => $channels, 'meta' => $meta]; return $this->request->send('POST', "channels/campaigns/$campaignId", $data); }
php
public function toChannels($channels, $campaignId, $meta = []) { $data = ['channel_uids' => $channels, 'meta' => $meta]; return $this->request->send('POST', "channels/campaigns/$campaignId", $data); }
[ "public", "function", "toChannels", "(", "$", "channels", ",", "$", "campaignId", ",", "$", "meta", "=", "[", "]", ")", "{", "$", "data", "=", "[", "'channel_uids'", "=>", "$", "channels", ",", "'meta'", "=>", "$", "meta", "]", ";", "return", "$", "this", "->", "request", "->", "send", "(", "'POST'", ",", "\"channels/campaigns/$campaignId\"", ",", "$", "data", ")", ";", "}" ]
Triggers campaign for multiple channels @param array $channels @param string $campaignId @param array $meta @return Horntell\Http\Response
[ "Triggers", "campaign", "for", "multiple", "channels" ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/src/Horntell/Campaign.php#L69-L74
train
PenoaksDev/Milky-Framework
src/Milky/Pagination/LengthAwarePaginator.php
LengthAwarePaginator.nextPageUrl
public function nextPageUrl() { if ( $this->lastPage() > $this->currentPage() ) return $this->url( $this->currentPage() + 1 ); return null; }
php
public function nextPageUrl() { if ( $this->lastPage() > $this->currentPage() ) return $this->url( $this->currentPage() + 1 ); return null; }
[ "public", "function", "nextPageUrl", "(", ")", "{", "if", "(", "$", "this", "->", "lastPage", "(", ")", ">", "$", "this", "->", "currentPage", "(", ")", ")", "return", "$", "this", "->", "url", "(", "$", "this", "->", "currentPage", "(", ")", "+", "1", ")", ";", "return", "null", ";", "}" ]
Get the URL for the next page. @return string|null
[ "Get", "the", "URL", "for", "the", "next", "page", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Pagination/LengthAwarePaginator.php#L69-L75
train
PenoaksDev/Milky-Framework
src/Milky/Pagination/LengthAwarePaginator.php
LengthAwarePaginator.render
public function render( Presenter $presenter = null ) { if ( is_null( $presenter ) && static::$presenterResolver ) $presenter = call_user_func( static::$presenterResolver, $this ); $presenter = $presenter ?: new BootstrapThreePresenter( $this ); return $presenter->render(); }
php
public function render( Presenter $presenter = null ) { if ( is_null( $presenter ) && static::$presenterResolver ) $presenter = call_user_func( static::$presenterResolver, $this ); $presenter = $presenter ?: new BootstrapThreePresenter( $this ); return $presenter->render(); }
[ "public", "function", "render", "(", "Presenter", "$", "presenter", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "presenter", ")", "&&", "static", "::", "$", "presenterResolver", ")", "$", "presenter", "=", "call_user_func", "(", "static", "::", "$", "presenterResolver", ",", "$", "this", ")", ";", "$", "presenter", "=", "$", "presenter", "?", ":", "new", "BootstrapThreePresenter", "(", "$", "this", ")", ";", "return", "$", "presenter", "->", "render", "(", ")", ";", "}" ]
Render the paginator using the given presenter. @param Presenter|null $presenter @return string
[ "Render", "the", "paginator", "using", "the", "given", "presenter", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Pagination/LengthAwarePaginator.php#L124-L132
train
mullanaphy/variable
src/PHY/Variable/Str.php
Str.pad
public function pad($pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) { $string = $this->get(); $value = str_pad($string, $pad_length, $pad_string, $pad_type); $this->update($value); return $this; }
php
public function pad($pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) { $string = $this->get(); $value = str_pad($string, $pad_length, $pad_string, $pad_type); $this->update($value); return $this; }
[ "public", "function", "pad", "(", "$", "pad_length", ",", "$", "pad_string", "=", "' '", ",", "$", "pad_type", "=", "STR_PAD_RIGHT", ")", "{", "$", "string", "=", "$", "this", "->", "get", "(", ")", ";", "$", "value", "=", "str_pad", "(", "$", "string", ",", "$", "pad_length", ",", "$", "pad_string", ",", "$", "pad_type", ")", ";", "$", "this", "->", "update", "(", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Pad a string. @param int $pad_length @param string $pad_string @param int $pad_type @return \PHY\Variable\Str
[ "Pad", "a", "string", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Str.php#L83-L89
train
mullanaphy/variable
src/PHY/Variable/Str.php
Str.rot13
public function rot13() { $string = $this->get(); $value = str_rot13($string); $this->update($value); return $this; }
php
public function rot13() { $string = $this->get(); $value = str_rot13($string); $this->update($value); return $this; }
[ "public", "function", "rot13", "(", ")", "{", "$", "string", "=", "$", "this", "->", "get", "(", ")", ";", "$", "value", "=", "str_rot13", "(", "$", "string", ")", ";", "$", "this", "->", "update", "(", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Performs the ROT13 encoding on the str argument and returns the resulting string. The ROT13 encoding simply shifts every letter by 13 places in the alphabet while leaving non-alpha characters untouched. Encoding and decoding are done by the same function, passing an encoded string as argument will return the original version. Obviously this is not for any actual encryption... @return \PHY\Variable\Str
[ "Performs", "the", "ROT13", "encoding", "on", "the", "str", "argument", "and", "returns", "the", "resulting", "string", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Str.php#L104-L110
train
mullanaphy/variable
src/PHY/Variable/Str.php
Str.shuffle
public function shuffle() { $string = $this->get(); $value = str_shuffle($string); $this->update($value); return $this; }
php
public function shuffle() { $string = $this->get(); $value = str_shuffle($string); $this->update($value); return $this; }
[ "public", "function", "shuffle", "(", ")", "{", "$", "string", "=", "$", "this", "->", "get", "(", ")", ";", "$", "value", "=", "str_shuffle", "(", "$", "string", ")", ";", "$", "this", "->", "update", "(", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Randomly shuffles the string. @return \PHY\Variable\Str
[ "Randomly", "shuffles", "the", "string", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Str.php#L117-L123
train
mullanaphy/variable
src/PHY/Variable/Str.php
Str.possessive
public function possessive() { $string = $this->get(); $value = $string."'".( 's' !== substr($string, -1) ? 's' : null ); $this->update($value); return $this; }
php
public function possessive() { $string = $this->get(); $value = $string."'".( 's' !== substr($string, -1) ? 's' : null ); $this->update($value); return $this; }
[ "public", "function", "possessive", "(", ")", "{", "$", "string", "=", "$", "this", "->", "get", "(", ")", ";", "$", "value", "=", "$", "string", ".", "\"'\"", ".", "(", "'s'", "!==", "substr", "(", "$", "string", ",", "-", "1", ")", "?", "'s'", ":", "null", ")", ";", "$", "this", "->", "update", "(", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Get the possessive version of a string. @return \PHY\Variable\Str
[ "Get", "the", "possessive", "version", "of", "a", "string", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Str.php#L163-L173
train
mullanaphy/variable
src/PHY/Variable/Str.php
Str.toShorten
public function toShorten($length = 32, $truncate = false) { $string = $this->get(); if (is_bool($length)) { $truncate = $length; $length = 32; } else { $length = (int)$length; } if (strlen($string) > $length) { $length - 4; $string = substr($string, 0, $length); if (!$truncate) { $string = explode(' ', $string); $size = count($string) - 1; if ($size > -1) { $final = ''; for ($i = 0; $i < $size; ++$i) { $final .= $string[$i].' '; } $string = $final; } } $string = trim($string).'...'; } return $string; }
php
public function toShorten($length = 32, $truncate = false) { $string = $this->get(); if (is_bool($length)) { $truncate = $length; $length = 32; } else { $length = (int)$length; } if (strlen($string) > $length) { $length - 4; $string = substr($string, 0, $length); if (!$truncate) { $string = explode(' ', $string); $size = count($string) - 1; if ($size > -1) { $final = ''; for ($i = 0; $i < $size; ++$i) { $final .= $string[$i].' '; } $string = $final; } } $string = trim($string).'...'; } return $string; }
[ "public", "function", "toShorten", "(", "$", "length", "=", "32", ",", "$", "truncate", "=", "false", ")", "{", "$", "string", "=", "$", "this", "->", "get", "(", ")", ";", "if", "(", "is_bool", "(", "$", "length", ")", ")", "{", "$", "truncate", "=", "$", "length", ";", "$", "length", "=", "32", ";", "}", "else", "{", "$", "length", "=", "(", "int", ")", "$", "length", ";", "}", "if", "(", "strlen", "(", "$", "string", ")", ">", "$", "length", ")", "{", "$", "length", "-", "4", ";", "$", "string", "=", "substr", "(", "$", "string", ",", "0", ",", "$", "length", ")", ";", "if", "(", "!", "$", "truncate", ")", "{", "$", "string", "=", "explode", "(", "' '", ",", "$", "string", ")", ";", "$", "size", "=", "count", "(", "$", "string", ")", "-", "1", ";", "if", "(", "$", "size", ">", "-", "1", ")", "{", "$", "final", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "size", ";", "++", "$", "i", ")", "{", "$", "final", ".=", "$", "string", "[", "$", "i", "]", ".", "' '", ";", "}", "$", "string", "=", "$", "final", ";", "}", "}", "$", "string", "=", "trim", "(", "$", "string", ")", ".", "'...'", ";", "}", "return", "$", "string", ";", "}" ]
Shorten a string. @param int $length @param bool $truncate @return string
[ "Shorten", "a", "string", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Str.php#L200-L229
train
Vectrex/vxPHP
src/Database/AbstractPdoAdapter.php
AbstractPdoAdapter.primeQuery
protected function primeQuery($statementString, array $parameters) { $statement = $this->connection->prepare($statementString); foreach($parameters as $name => $value) { // question mark placeholders start with 1 if(is_int($name)) { ++$name; } // otherwise ensure colons else { $name = ':' . ltrim($name, ':'); } // set parameter types, depending on parameter values $type = \PDO::PARAM_STR; if(is_bool($value)) { $type = \PDO::PARAM_BOOL; } else if(is_int($value)) { $type = \PDO::PARAM_INT; } else if(is_null($value)) { $type = \PDO::PARAM_NULL; } else if($value instanceof \DateTime) { $value = $value->format('Y-m-d H:i:s'); } else if(is_object($value)) { if(method_exists($value, '__toString')) { $value = (string) $value; } else { throw new \InvalidArgumentException('Value cannot be converted into string.'); } } $statement->bindValue($name, $value, $type); } $this->statement = $statement; return $statement; }
php
protected function primeQuery($statementString, array $parameters) { $statement = $this->connection->prepare($statementString); foreach($parameters as $name => $value) { // question mark placeholders start with 1 if(is_int($name)) { ++$name; } // otherwise ensure colons else { $name = ':' . ltrim($name, ':'); } // set parameter types, depending on parameter values $type = \PDO::PARAM_STR; if(is_bool($value)) { $type = \PDO::PARAM_BOOL; } else if(is_int($value)) { $type = \PDO::PARAM_INT; } else if(is_null($value)) { $type = \PDO::PARAM_NULL; } else if($value instanceof \DateTime) { $value = $value->format('Y-m-d H:i:s'); } else if(is_object($value)) { if(method_exists($value, '__toString')) { $value = (string) $value; } else { throw new \InvalidArgumentException('Value cannot be converted into string.'); } } $statement->bindValue($name, $value, $type); } $this->statement = $statement; return $statement; }
[ "protected", "function", "primeQuery", "(", "$", "statementString", ",", "array", "$", "parameters", ")", "{", "$", "statement", "=", "$", "this", "->", "connection", "->", "prepare", "(", "$", "statementString", ")", ";", "foreach", "(", "$", "parameters", "as", "$", "name", "=>", "$", "value", ")", "{", "// question mark placeholders start with 1", "if", "(", "is_int", "(", "$", "name", ")", ")", "{", "++", "$", "name", ";", "}", "// otherwise ensure colons", "else", "{", "$", "name", "=", "':'", ".", "ltrim", "(", "$", "name", ",", "':'", ")", ";", "}", "// set parameter types, depending on parameter values", "$", "type", "=", "\\", "PDO", "::", "PARAM_STR", ";", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "$", "type", "=", "\\", "PDO", "::", "PARAM_BOOL", ";", "}", "else", "if", "(", "is_int", "(", "$", "value", ")", ")", "{", "$", "type", "=", "\\", "PDO", "::", "PARAM_INT", ";", "}", "else", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "type", "=", "\\", "PDO", "::", "PARAM_NULL", ";", "}", "else", "if", "(", "$", "value", "instanceof", "\\", "DateTime", ")", "{", "$", "value", "=", "$", "value", "->", "format", "(", "'Y-m-d H:i:s'", ")", ";", "}", "else", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "if", "(", "method_exists", "(", "$", "value", ",", "'__toString'", ")", ")", "{", "$", "value", "=", "(", "string", ")", "$", "value", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Value cannot be converted into string.'", ")", ";", "}", "}", "$", "statement", "->", "bindValue", "(", "$", "name", ",", "$", "value", ",", "$", "type", ")", ";", "}", "$", "this", "->", "statement", "=", "$", "statement", ";", "return", "$", "statement", ";", "}" ]
prepare a statement and bind parameters @param string $statementString @param array $parameters @return \PDOStatement
[ "prepare", "a", "statement", "and", "bind", "parameters" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Database/AbstractPdoAdapter.php#L830-L884
train
theomessin/ts-framework
src/Node/Channelgroup.php
Channelgroup.message
public function message($msg) { foreach ($this as $client) { try { $this->execute( "sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => Teamspeak::TEXTMSG_CLIENT) ); } catch (TeamSpeak3_Adapter_ServerQuery_Exception $e) { /* ERROR_client_invalid_id */ if ($e->getCode() != 0x0200) { throw $e; } } } }
php
public function message($msg) { foreach ($this as $client) { try { $this->execute( "sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => Teamspeak::TEXTMSG_CLIENT) ); } catch (TeamSpeak3_Adapter_ServerQuery_Exception $e) { /* ERROR_client_invalid_id */ if ($e->getCode() != 0x0200) { throw $e; } } } }
[ "public", "function", "message", "(", "$", "msg", ")", "{", "foreach", "(", "$", "this", "as", "$", "client", ")", "{", "try", "{", "$", "this", "->", "execute", "(", "\"sendtextmessage\"", ",", "array", "(", "\"msg\"", "=>", "$", "msg", ",", "\"target\"", "=>", "$", "client", ",", "\"targetmode\"", "=>", "Teamspeak", "::", "TEXTMSG_CLIENT", ")", ")", ";", "}", "catch", "(", "TeamSpeak3_Adapter_ServerQuery_Exception", "$", "e", ")", "{", "/* ERROR_client_invalid_id */", "if", "(", "$", "e", "->", "getCode", "(", ")", "!=", "0x0200", ")", "{", "throw", "$", "e", ";", "}", "}", "}", "}" ]
Sends a text message to all clients residing in the channel group on the virtual server. @param string $msg @return void
[ "Sends", "a", "text", "message", "to", "all", "clients", "residing", "in", "the", "channel", "group", "on", "the", "virtual", "server", "." ]
d60e36553241db05cb05ef19e749866cc977437c
https://github.com/theomessin/ts-framework/blob/d60e36553241db05cb05ef19e749866cc977437c/src/Node/Channelgroup.php#L198-L213
train
gingerwfms/ginger-core
src/GingerCore/Repository/Adapter/ZendDbCrudRepositoryAdapter.php
ZendDbCrudRepositoryAdapter.getTablegateway
protected function getTablegateway(Resource\ResourceType $resourceType) { $type = $resourceType->getValue(); if (!isset($this->tableGateways[$type])) { $this->tableGateways[$type] = new TableGateway($type, $this->zendDbAdapter); } return $this->tableGateways[$type]; }
php
protected function getTablegateway(Resource\ResourceType $resourceType) { $type = $resourceType->getValue(); if (!isset($this->tableGateways[$type])) { $this->tableGateways[$type] = new TableGateway($type, $this->zendDbAdapter); } return $this->tableGateways[$type]; }
[ "protected", "function", "getTablegateway", "(", "Resource", "\\", "ResourceType", "$", "resourceType", ")", "{", "$", "type", "=", "$", "resourceType", "->", "getValue", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "tableGateways", "[", "$", "type", "]", ")", ")", "{", "$", "this", "->", "tableGateways", "[", "$", "type", "]", "=", "new", "TableGateway", "(", "$", "type", ",", "$", "this", "->", "zendDbAdapter", ")", ";", "}", "return", "$", "this", "->", "tableGateways", "[", "$", "type", "]", ";", "}" ]
Get the corresponding Tablegateway of the given ResourceType @param Resource\ResourceType $resourceType @return TableGateway
[ "Get", "the", "corresponding", "Tablegateway", "of", "the", "given", "ResourceType" ]
178e699dd1a912ec7b8b4e21f7de51edd2a1c1e8
https://github.com/gingerwfms/ginger-core/blob/178e699dd1a912ec7b8b4e21f7de51edd2a1c1e8/src/GingerCore/Repository/Adapter/ZendDbCrudRepositoryAdapter.php#L195-L204
train
RocketPropelledTortoise/Core
src/Utilities/ParentChildTree.php
ParentChildTree.buildTree
protected function buildTree($tree_data) { $parent_key = $this->config['parent']; $default_root_id = $this->config['default_root_id']; while (count($tree_data)) { $beginning_with = count($tree_data); foreach ($tree_data as $node_id => $node) { $node[$this->config['childs']] = []; $parent = (array_key_exists($parent_key, $node)) ? $node[$parent_key] : $default_root_id; if ($this->add($parent, $node[$this->config['id']], $node)) { unset($tree_data[$node_id]); } } $this->ungracefulExit($beginning_with, $tree_data); } }
php
protected function buildTree($tree_data) { $parent_key = $this->config['parent']; $default_root_id = $this->config['default_root_id']; while (count($tree_data)) { $beginning_with = count($tree_data); foreach ($tree_data as $node_id => $node) { $node[$this->config['childs']] = []; $parent = (array_key_exists($parent_key, $node)) ? $node[$parent_key] : $default_root_id; if ($this->add($parent, $node[$this->config['id']], $node)) { unset($tree_data[$node_id]); } } $this->ungracefulExit($beginning_with, $tree_data); } }
[ "protected", "function", "buildTree", "(", "$", "tree_data", ")", "{", "$", "parent_key", "=", "$", "this", "->", "config", "[", "'parent'", "]", ";", "$", "default_root_id", "=", "$", "this", "->", "config", "[", "'default_root_id'", "]", ";", "while", "(", "count", "(", "$", "tree_data", ")", ")", "{", "$", "beginning_with", "=", "count", "(", "$", "tree_data", ")", ";", "foreach", "(", "$", "tree_data", "as", "$", "node_id", "=>", "$", "node", ")", "{", "$", "node", "[", "$", "this", "->", "config", "[", "'childs'", "]", "]", "=", "[", "]", ";", "$", "parent", "=", "(", "array_key_exists", "(", "$", "parent_key", ",", "$", "node", ")", ")", "?", "$", "node", "[", "$", "parent_key", "]", ":", "$", "default_root_id", ";", "if", "(", "$", "this", "->", "add", "(", "$", "parent", ",", "$", "node", "[", "$", "this", "->", "config", "[", "'id'", "]", "]", ",", "$", "node", ")", ")", "{", "unset", "(", "$", "tree_data", "[", "$", "node_id", "]", ")", ";", "}", "}", "$", "this", "->", "ungracefulExit", "(", "$", "beginning_with", ",", "$", "tree_data", ")", ";", "}", "}" ]
Build the tree from the received data @param array $tree_data The raw data to create a tree from @throws \Exception
[ "Build", "the", "tree", "from", "the", "received", "data" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Utilities/ParentChildTree.php#L66-L84
train
RocketPropelledTortoise/Core
src/Utilities/ParentChildTree.php
ParentChildTree.ungracefulExit
protected function ungracefulExit($beginning_with, $tree_data) { if ($beginning_with == count($tree_data)) { throw new \Exception('This tree has some missing parent items: ' . print_r($tree_data, true)); } }
php
protected function ungracefulExit($beginning_with, $tree_data) { if ($beginning_with == count($tree_data)) { throw new \Exception('This tree has some missing parent items: ' . print_r($tree_data, true)); } }
[ "protected", "function", "ungracefulExit", "(", "$", "beginning_with", ",", "$", "tree_data", ")", "{", "if", "(", "$", "beginning_with", "==", "count", "(", "$", "tree_data", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'This tree has some missing parent items: '", ".", "print_r", "(", "$", "tree_data", ",", "true", ")", ")", ";", "}", "}" ]
Exit the tree creation if the tree can't be built completely @param int $beginning_with The number of nodes left to place on the tree @param array $tree_data The rest of the tree data to place @throws \Exception
[ "Exit", "the", "tree", "creation", "if", "the", "tree", "can", "t", "be", "built", "completely" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Utilities/ParentChildTree.php#L93-L98
train
RocketPropelledTortoise/Core
src/Utilities/ParentChildTree.php
ParentChildTree.add
public function add($parent_id, $node_id, $node) { //is it a root ? if (in_array($parent_id, $this->config['default_parent'])) { if (!$this->config['create_root']) { $this->tree[$node_id] = $node; $this->finder[$node_id] = &$this->tree[$node_id]; return true; } $node[$this->config['parent']] = $this->config['default_root_id']; $parent_id = $this->config['default_root_id']; } //is it in the finder ? if (array_key_exists($parent_id, $this->finder)) { $this->finder[$parent_id][$this->config['childs']][$node_id] = $node; $this->finder[$node_id] = &$this->finder[$parent_id][$this->config['childs']][$node_id]; return true; } //could'nt find anything return false; }
php
public function add($parent_id, $node_id, $node) { //is it a root ? if (in_array($parent_id, $this->config['default_parent'])) { if (!$this->config['create_root']) { $this->tree[$node_id] = $node; $this->finder[$node_id] = &$this->tree[$node_id]; return true; } $node[$this->config['parent']] = $this->config['default_root_id']; $parent_id = $this->config['default_root_id']; } //is it in the finder ? if (array_key_exists($parent_id, $this->finder)) { $this->finder[$parent_id][$this->config['childs']][$node_id] = $node; $this->finder[$node_id] = &$this->finder[$parent_id][$this->config['childs']][$node_id]; return true; } //could'nt find anything return false; }
[ "public", "function", "add", "(", "$", "parent_id", ",", "$", "node_id", ",", "$", "node", ")", "{", "//is it a root ?", "if", "(", "in_array", "(", "$", "parent_id", ",", "$", "this", "->", "config", "[", "'default_parent'", "]", ")", ")", "{", "if", "(", "!", "$", "this", "->", "config", "[", "'create_root'", "]", ")", "{", "$", "this", "->", "tree", "[", "$", "node_id", "]", "=", "$", "node", ";", "$", "this", "->", "finder", "[", "$", "node_id", "]", "=", "&", "$", "this", "->", "tree", "[", "$", "node_id", "]", ";", "return", "true", ";", "}", "$", "node", "[", "$", "this", "->", "config", "[", "'parent'", "]", "]", "=", "$", "this", "->", "config", "[", "'default_root_id'", "]", ";", "$", "parent_id", "=", "$", "this", "->", "config", "[", "'default_root_id'", "]", ";", "}", "//is it in the finder ?", "if", "(", "array_key_exists", "(", "$", "parent_id", ",", "$", "this", "->", "finder", ")", ")", "{", "$", "this", "->", "finder", "[", "$", "parent_id", "]", "[", "$", "this", "->", "config", "[", "'childs'", "]", "]", "[", "$", "node_id", "]", "=", "$", "node", ";", "$", "this", "->", "finder", "[", "$", "node_id", "]", "=", "&", "$", "this", "->", "finder", "[", "$", "parent_id", "]", "[", "$", "this", "->", "config", "[", "'childs'", "]", "]", "[", "$", "node_id", "]", ";", "return", "true", ";", "}", "//could'nt find anything", "return", "false", ";", "}" ]
Add a leaf on the tree. @param string $parent_id @param string $node_id @param array $node @return bool
[ "Add", "a", "leaf", "on", "the", "tree", "." ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Utilities/ParentChildTree.php#L108-L133
train
RocketPropelledTortoise/Core
src/Utilities/ParentChildTree.php
ParentChildTree.getChilds
public function getChilds($id) { $result = []; if (array_key_exists($id, $this->finder)) { return $this->recursiveGetChilds($this->finder[$id][$this->config['childs']], $result); } else { return $result; } }
php
public function getChilds($id) { $result = []; if (array_key_exists($id, $this->finder)) { return $this->recursiveGetChilds($this->finder[$id][$this->config['childs']], $result); } else { return $result; } }
[ "public", "function", "getChilds", "(", "$", "id", ")", "{", "$", "result", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "$", "id", ",", "$", "this", "->", "finder", ")", ")", "{", "return", "$", "this", "->", "recursiveGetChilds", "(", "$", "this", "->", "finder", "[", "$", "id", "]", "[", "$", "this", "->", "config", "[", "'childs'", "]", "]", ",", "$", "result", ")", ";", "}", "else", "{", "return", "$", "result", ";", "}", "}" ]
Get all node's children. @param string $id The entry's ID @return array
[ "Get", "all", "node", "s", "children", "." ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Utilities/ParentChildTree.php#L151-L159
train
RocketPropelledTortoise/Core
src/Utilities/ParentChildTree.php
ParentChildTree.recursiveGetChilds
private function recursiveGetChilds($childs, $result) { foreach ($childs as $node) { $result[] = $node[$this->config['id']]; $result = $this->recursiveGetChilds($node[$this->config['childs']], $result); } return $result; }
php
private function recursiveGetChilds($childs, $result) { foreach ($childs as $node) { $result[] = $node[$this->config['id']]; $result = $this->recursiveGetChilds($node[$this->config['childs']], $result); } return $result; }
[ "private", "function", "recursiveGetChilds", "(", "$", "childs", ",", "$", "result", ")", "{", "foreach", "(", "$", "childs", "as", "$", "node", ")", "{", "$", "result", "[", "]", "=", "$", "node", "[", "$", "this", "->", "config", "[", "'id'", "]", "]", ";", "$", "result", "=", "$", "this", "->", "recursiveGetChilds", "(", "$", "node", "[", "$", "this", "->", "config", "[", "'childs'", "]", "]", ",", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}" ]
Internal recursive function to get children. @param array $childs @param array $result @return array
[ "Internal", "recursive", "function", "to", "get", "children", "." ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Utilities/ParentChildTree.php#L168-L176
train
RocketPropelledTortoise/Core
src/Utilities/ParentChildTree.php
ParentChildTree.recursiveSort
private function recursiveSort(&$tree) { //execute sort usort( $tree, function ($a, $b) { if ($a[$this->config['sort_key']] == $b[$this->config['sort_key']]) { return 0; } return ($a[$this->config['sort_key']] < $b[$this->config['sort_key']]) ? -1 : 1; } ); foreach ($tree as &$t) { if (array_key_exists($this->config['childs'], $t) && $t[$this->config['childs']] != '') { $t[$this->config['childs']] = $this->recursiveSort($t[$this->config['childs']]); } } return $tree; }
php
private function recursiveSort(&$tree) { //execute sort usort( $tree, function ($a, $b) { if ($a[$this->config['sort_key']] == $b[$this->config['sort_key']]) { return 0; } return ($a[$this->config['sort_key']] < $b[$this->config['sort_key']]) ? -1 : 1; } ); foreach ($tree as &$t) { if (array_key_exists($this->config['childs'], $t) && $t[$this->config['childs']] != '') { $t[$this->config['childs']] = $this->recursiveSort($t[$this->config['childs']]); } } return $tree; }
[ "private", "function", "recursiveSort", "(", "&", "$", "tree", ")", "{", "//execute sort", "usort", "(", "$", "tree", ",", "function", "(", "$", "a", ",", "$", "b", ")", "{", "if", "(", "$", "a", "[", "$", "this", "->", "config", "[", "'sort_key'", "]", "]", "==", "$", "b", "[", "$", "this", "->", "config", "[", "'sort_key'", "]", "]", ")", "{", "return", "0", ";", "}", "return", "(", "$", "a", "[", "$", "this", "->", "config", "[", "'sort_key'", "]", "]", "<", "$", "b", "[", "$", "this", "->", "config", "[", "'sort_key'", "]", "]", ")", "?", "-", "1", ":", "1", ";", "}", ")", ";", "foreach", "(", "$", "tree", "as", "&", "$", "t", ")", "{", "if", "(", "array_key_exists", "(", "$", "this", "->", "config", "[", "'childs'", "]", ",", "$", "t", ")", "&&", "$", "t", "[", "$", "this", "->", "config", "[", "'childs'", "]", "]", "!=", "''", ")", "{", "$", "t", "[", "$", "this", "->", "config", "[", "'childs'", "]", "]", "=", "$", "this", "->", "recursiveSort", "(", "$", "t", "[", "$", "this", "->", "config", "[", "'childs'", "]", "]", ")", ";", "}", "}", "return", "$", "tree", ";", "}" ]
Internal recursive function @param array $tree @return bool
[ "Internal", "recursive", "function" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Utilities/ParentChildTree.php#L193-L214
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Client/Pool/Pool.php
Pool.execute
public function execute($hydrationMode = self::RESULT_TYPE_HYDRATED) { if ($hydrationMode !== self::RESULT_TYPE_NONE) { $items = $this->getResultIterator(); } // Send requests until the queue is empty while (!empty($this->queue)) { $pool = new \Aws\CommandPool($this->dm->getClient(), $this->getQueue(), [ 'concurrency' => $this->poolSize, 'fulfilled' => $this->getFulfilledCallback($items, $hydrationMode), 'rejected' => $this->getRejectedCallback(), 'preserve_iterator_keys' => true ]); $pool->promise()->wait(); if ($this->isPaging()) { break; } } if ($hydrationMode === self::RESULT_TYPE_NONE) { return true; } elseif ($hydrationMode === self::RESULT_TYPE_SDK) { return new SdkResultIterator($items); } return new IteratorIterator($items); }
php
public function execute($hydrationMode = self::RESULT_TYPE_HYDRATED) { if ($hydrationMode !== self::RESULT_TYPE_NONE) { $items = $this->getResultIterator(); } // Send requests until the queue is empty while (!empty($this->queue)) { $pool = new \Aws\CommandPool($this->dm->getClient(), $this->getQueue(), [ 'concurrency' => $this->poolSize, 'fulfilled' => $this->getFulfilledCallback($items, $hydrationMode), 'rejected' => $this->getRejectedCallback(), 'preserve_iterator_keys' => true ]); $pool->promise()->wait(); if ($this->isPaging()) { break; } } if ($hydrationMode === self::RESULT_TYPE_NONE) { return true; } elseif ($hydrationMode === self::RESULT_TYPE_SDK) { return new SdkResultIterator($items); } return new IteratorIterator($items); }
[ "public", "function", "execute", "(", "$", "hydrationMode", "=", "self", "::", "RESULT_TYPE_HYDRATED", ")", "{", "if", "(", "$", "hydrationMode", "!==", "self", "::", "RESULT_TYPE_NONE", ")", "{", "$", "items", "=", "$", "this", "->", "getResultIterator", "(", ")", ";", "}", "// Send requests until the queue is empty", "while", "(", "!", "empty", "(", "$", "this", "->", "queue", ")", ")", "{", "$", "pool", "=", "new", "\\", "Aws", "\\", "CommandPool", "(", "$", "this", "->", "dm", "->", "getClient", "(", ")", ",", "$", "this", "->", "getQueue", "(", ")", ",", "[", "'concurrency'", "=>", "$", "this", "->", "poolSize", ",", "'fulfilled'", "=>", "$", "this", "->", "getFulfilledCallback", "(", "$", "items", ",", "$", "hydrationMode", ")", ",", "'rejected'", "=>", "$", "this", "->", "getRejectedCallback", "(", ")", ",", "'preserve_iterator_keys'", "=>", "true", "]", ")", ";", "$", "pool", "->", "promise", "(", ")", "->", "wait", "(", ")", ";", "if", "(", "$", "this", "->", "isPaging", "(", ")", ")", "{", "break", ";", "}", "}", "if", "(", "$", "hydrationMode", "===", "self", "::", "RESULT_TYPE_NONE", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "hydrationMode", "===", "self", "::", "RESULT_TYPE_SDK", ")", "{", "return", "new", "SdkResultIterator", "(", "$", "items", ")", ";", "}", "return", "new", "IteratorIterator", "(", "$", "items", ")", ";", "}" ]
Execute queued requests. Unprocessed items are automatically retried. @param int $hydrationMode @return IteratorIterator|bool
[ "Execute", "queued", "requests", ".", "Unprocessed", "items", "are", "automatically", "retried", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Client/Pool/Pool.php#L58-L87
train
agentmedia/phine-builtin
src/BuiltIn/Modules/Frontend/Logout.php
Logout.RedirectUrl
private function RedirectUrl() { if ($this->logout->GetNextUrl()) { return FrontendRouter::Url($this->logout->GetNextUrl()); } return CurrentUrl(); }
php
private function RedirectUrl() { if ($this->logout->GetNextUrl()) { return FrontendRouter::Url($this->logout->GetNextUrl()); } return CurrentUrl(); }
[ "private", "function", "RedirectUrl", "(", ")", "{", "if", "(", "$", "this", "->", "logout", "->", "GetNextUrl", "(", ")", ")", "{", "return", "FrontendRouter", "::", "Url", "(", "$", "this", "->", "logout", "->", "GetNextUrl", "(", ")", ")", ";", "}", "return", "CurrentUrl", "(", ")", ";", "}" ]
Gets the actual redirect url @return string Gets the url after post
[ "Gets", "the", "actual", "redirect", "url" ]
4dd05bc406a71e997bd4eaa16b12e23dbe62a456
https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Frontend/Logout.php#L46-L53
train
crazy-cats/framework
src/Utility/File.php
File.getCsv
static public function getCsv( $handle, $length = null, $delimiter = ',', $enclosure = '"' ) { $separator = preg_quote( $delimiter ); $quoteSymbol = preg_quote( $enclosure ); $line = ''; $eof = false; do { $line .= ( $length === null ? fgets( $handle ) : fgets( $handle, (int) $length ) ); $eof = ( preg_match_all( '/' . $quoteSymbol . '/', $line ) % 2 == 0 ); } while ( !$eof ); if ( empty( $line ) ) { return false; } $csvPattern = '/(' . $quoteSymbol . '[^' . $quoteSymbol . ']*(?:' . $quoteSymbol . $quoteSymbol . '[^' . $quoteSymbol . ']*)*' . $quoteSymbol . '|[^' . $separator . ']*)' . $separator . '/'; $csvLine = preg_replace( '/(?: |[ ])?$/', $separator, trim( $line ) ); $matches = null; preg_match_all( $csvPattern, $csvLine, $matches ); $row = $matches[1]; for ( $col = 0; $col < count( $row ); $col++ ) { $row[$col] = preg_replace( '/^' . $quoteSymbol . '(.*)' . $quoteSymbol . '$/s', '$1', $row[$col] ); $row[$col] = str_replace( $quoteSymbol . $quoteSymbol, $quoteSymbol, $row[$col] ); } return $row; }
php
static public function getCsv( $handle, $length = null, $delimiter = ',', $enclosure = '"' ) { $separator = preg_quote( $delimiter ); $quoteSymbol = preg_quote( $enclosure ); $line = ''; $eof = false; do { $line .= ( $length === null ? fgets( $handle ) : fgets( $handle, (int) $length ) ); $eof = ( preg_match_all( '/' . $quoteSymbol . '/', $line ) % 2 == 0 ); } while ( !$eof ); if ( empty( $line ) ) { return false; } $csvPattern = '/(' . $quoteSymbol . '[^' . $quoteSymbol . ']*(?:' . $quoteSymbol . $quoteSymbol . '[^' . $quoteSymbol . ']*)*' . $quoteSymbol . '|[^' . $separator . ']*)' . $separator . '/'; $csvLine = preg_replace( '/(?: |[ ])?$/', $separator, trim( $line ) ); $matches = null; preg_match_all( $csvPattern, $csvLine, $matches ); $row = $matches[1]; for ( $col = 0; $col < count( $row ); $col++ ) { $row[$col] = preg_replace( '/^' . $quoteSymbol . '(.*)' . $quoteSymbol . '$/s', '$1', $row[$col] ); $row[$col] = str_replace( $quoteSymbol . $quoteSymbol, $quoteSymbol, $row[$col] ); } return $row; }
[ "static", "public", "function", "getCsv", "(", "$", "handle", ",", "$", "length", "=", "null", ",", "$", "delimiter", "=", "','", ",", "$", "enclosure", "=", "'\"'", ")", "{", "$", "separator", "=", "preg_quote", "(", "$", "delimiter", ")", ";", "$", "quoteSymbol", "=", "preg_quote", "(", "$", "enclosure", ")", ";", "$", "line", "=", "''", ";", "$", "eof", "=", "false", ";", "do", "{", "$", "line", ".=", "(", "$", "length", "===", "null", "?", "fgets", "(", "$", "handle", ")", ":", "fgets", "(", "$", "handle", ",", "(", "int", ")", "$", "length", ")", ")", ";", "$", "eof", "=", "(", "preg_match_all", "(", "'/'", ".", "$", "quoteSymbol", ".", "'/'", ",", "$", "line", ")", "%", "2", "==", "0", ")", ";", "}", "while", "(", "!", "$", "eof", ")", ";", "if", "(", "empty", "(", "$", "line", ")", ")", "{", "return", "false", ";", "}", "$", "csvPattern", "=", "'/('", ".", "$", "quoteSymbol", ".", "'[^'", ".", "$", "quoteSymbol", ".", "']*(?:'", ".", "$", "quoteSymbol", ".", "$", "quoteSymbol", ".", "'[^'", ".", "$", "quoteSymbol", ".", "']*)*'", ".", "$", "quoteSymbol", ".", "'|[^'", ".", "$", "separator", ".", "']*)'", ".", "$", "separator", ".", "'/'", ";", "$", "csvLine", "=", "preg_replace", "(", "'/(?: |[ ])?$/'", ",", "$", "separator", ",", "trim", "(", "$", "line", ")", ")", ";", "$", "matches", "=", "null", ";", "preg_match_all", "(", "$", "csvPattern", ",", "$", "csvLine", ",", "$", "matches", ")", ";", "$", "row", "=", "$", "matches", "[", "1", "]", ";", "for", "(", "$", "col", "=", "0", ";", "$", "col", "<", "count", "(", "$", "row", ")", ";", "$", "col", "++", ")", "{", "$", "row", "[", "$", "col", "]", "=", "preg_replace", "(", "'/^'", ".", "$", "quoteSymbol", ".", "'(.*)'", ".", "$", "quoteSymbol", ".", "'$/s'", ",", "'$1'", ",", "$", "row", "[", "$", "col", "]", ")", ";", "$", "row", "[", "$", "col", "]", "=", "str_replace", "(", "$", "quoteSymbol", ".", "$", "quoteSymbol", ",", "$", "quoteSymbol", ",", "$", "row", "[", "$", "col", "]", ")", ";", "}", "return", "$", "row", ";", "}" ]
Customized a method to read CSV file with Chinese content, instead of using PHP fgetcsv function. @param resource $handle @param int $length @param string $delimiter @param string $enclosure @return string[]
[ "Customized", "a", "method", "to", "read", "CSV", "file", "with", "Chinese", "content", "instead", "of", "using", "PHP", "fgetcsv", "function", "." ]
5ea53d3f97689a301782c0d3d7b924d763420c66
https://github.com/crazy-cats/framework/blob/5ea53d3f97689a301782c0d3d7b924d763420c66/src/Utility/File.php#L76-L102
train
Mandarin-Medien/MMCmfRoutingBundle
Entity/NodeRouteManager.php
NodeRouteManager.generateAutoNodeRoute
public function generateAutoNodeRoute(RoutableNodeInterface $node) { $repository = $this->manager->getRepository(AutoNodeRoute::class); $route = (new AutoNodeRoute()) ->setRoute('/' . $this->slugify($node)); //$node->addRoute($route); /** * @var Node $parent */ while (!is_null($parent = $node->getParent())) { $route->setRoute($this->getAutoNodeRoute($parent) . $route->getRoute()); $node = $parent; } // add increment if route exists $route->setRoute( $route->getRoute().$this->getIncrement($route->getRoute()) ); //var_dump($route->getRoute()); return $route; }
php
public function generateAutoNodeRoute(RoutableNodeInterface $node) { $repository = $this->manager->getRepository(AutoNodeRoute::class); $route = (new AutoNodeRoute()) ->setRoute('/' . $this->slugify($node)); //$node->addRoute($route); /** * @var Node $parent */ while (!is_null($parent = $node->getParent())) { $route->setRoute($this->getAutoNodeRoute($parent) . $route->getRoute()); $node = $parent; } // add increment if route exists $route->setRoute( $route->getRoute().$this->getIncrement($route->getRoute()) ); //var_dump($route->getRoute()); return $route; }
[ "public", "function", "generateAutoNodeRoute", "(", "RoutableNodeInterface", "$", "node", ")", "{", "$", "repository", "=", "$", "this", "->", "manager", "->", "getRepository", "(", "AutoNodeRoute", "::", "class", ")", ";", "$", "route", "=", "(", "new", "AutoNodeRoute", "(", ")", ")", "->", "setRoute", "(", "'/'", ".", "$", "this", "->", "slugify", "(", "$", "node", ")", ")", ";", "//$node->addRoute($route);", "/**\n * @var Node $parent\n */", "while", "(", "!", "is_null", "(", "$", "parent", "=", "$", "node", "->", "getParent", "(", ")", ")", ")", "{", "$", "route", "->", "setRoute", "(", "$", "this", "->", "getAutoNodeRoute", "(", "$", "parent", ")", ".", "$", "route", "->", "getRoute", "(", ")", ")", ";", "$", "node", "=", "$", "parent", ";", "}", "// add increment if route exists", "$", "route", "->", "setRoute", "(", "$", "route", "->", "getRoute", "(", ")", ".", "$", "this", "->", "getIncrement", "(", "$", "route", "->", "getRoute", "(", ")", ")", ")", ";", "//var_dump($route->getRoute());", "return", "$", "route", ";", "}" ]
generates a AutoNodeRoute for a given Node @param RoutableNodeInterface $node @return AutoNodeRoute
[ "generates", "a", "AutoNodeRoute", "for", "a", "given", "Node" ]
7db1b03f5e120bd473486c0be6ab76c6146cd2d0
https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/Entity/NodeRouteManager.php#L43-L71
train
Mandarin-Medien/MMCmfRoutingBundle
Entity/NodeRouteManager.php
NodeRouteManager.getAutoNodeRoutesRecursive
public function getAutoNodeRoutesRecursive(NodeInterface &$node, $base = null, &$routeObjects = array()) { $route = $this->getAutoNodeRoute($node); if($route) { $route->setRoute( $base ? $base . '/' . util::slugify($node->getName()) : $this->generateAutoNodeRoute($node)->getRoute() ); // add soft Increment $route->setRoute($route->getRoute().$this->softIncrement($route, $routeObjects)); $routeObjects[] = $route; // recursive loop foreach ($node->getNodes() as $subnode) { if($subnode instanceof RoutableNodeInterface) $this->getAutoNodeRoutesRecursive($subnode, $this->getAutoNodeRoute($node)->getRoute(), $routeObjects); } } return $routeObjects; }
php
public function getAutoNodeRoutesRecursive(NodeInterface &$node, $base = null, &$routeObjects = array()) { $route = $this->getAutoNodeRoute($node); if($route) { $route->setRoute( $base ? $base . '/' . util::slugify($node->getName()) : $this->generateAutoNodeRoute($node)->getRoute() ); // add soft Increment $route->setRoute($route->getRoute().$this->softIncrement($route, $routeObjects)); $routeObjects[] = $route; // recursive loop foreach ($node->getNodes() as $subnode) { if($subnode instanceof RoutableNodeInterface) $this->getAutoNodeRoutesRecursive($subnode, $this->getAutoNodeRoute($node)->getRoute(), $routeObjects); } } return $routeObjects; }
[ "public", "function", "getAutoNodeRoutesRecursive", "(", "NodeInterface", "&", "$", "node", ",", "$", "base", "=", "null", ",", "&", "$", "routeObjects", "=", "array", "(", ")", ")", "{", "$", "route", "=", "$", "this", "->", "getAutoNodeRoute", "(", "$", "node", ")", ";", "if", "(", "$", "route", ")", "{", "$", "route", "->", "setRoute", "(", "$", "base", "?", "$", "base", ".", "'/'", ".", "util", "::", "slugify", "(", "$", "node", "->", "getName", "(", ")", ")", ":", "$", "this", "->", "generateAutoNodeRoute", "(", "$", "node", ")", "->", "getRoute", "(", ")", ")", ";", "// add soft Increment", "$", "route", "->", "setRoute", "(", "$", "route", "->", "getRoute", "(", ")", ".", "$", "this", "->", "softIncrement", "(", "$", "route", ",", "$", "routeObjects", ")", ")", ";", "$", "routeObjects", "[", "]", "=", "$", "route", ";", "// recursive loop", "foreach", "(", "$", "node", "->", "getNodes", "(", ")", "as", "$", "subnode", ")", "{", "if", "(", "$", "subnode", "instanceof", "RoutableNodeInterface", ")", "$", "this", "->", "getAutoNodeRoutesRecursive", "(", "$", "subnode", ",", "$", "this", "->", "getAutoNodeRoute", "(", "$", "node", ")", "->", "getRoute", "(", ")", ",", "$", "routeObjects", ")", ";", "}", "}", "return", "$", "routeObjects", ";", "}" ]
get updated AutoNodeRoutes recursive @param NodeInterface $node @param null|string $base @return NodeRoute[]
[ "get", "updated", "AutoNodeRoutes", "recursive" ]
7db1b03f5e120bd473486c0be6ab76c6146cd2d0
https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/Entity/NodeRouteManager.php#L81-L110
train
Mandarin-Medien/MMCmfRoutingBundle
Entity/NodeRouteManager.php
NodeRouteManager.getIncrement
protected function getIncrement($route) { // var_dump($route); $mapper = new ResultSetMapping(); $mapper->addScalarResult('route', 'route'); $builder = $this->manager->createNativeQuery( 'SELECT route FROM node_route WHERE route REGEXP ?', $mapper ) ->setParameter('1', $this->prepareMysqlRegexp($route)); //var_dump($builder->getArrayResult()); $i = 0; foreach($builder->getArrayResult() as $_route) { if(preg_match('#\(([0-9])*\)$#', $_route['route'], $matches)) { $i = (int) $matches[1] == $i ? (int) $matches[1]+1 : $i; } else { $i++; } } return ($i ? "($i)" : ''); }
php
protected function getIncrement($route) { // var_dump($route); $mapper = new ResultSetMapping(); $mapper->addScalarResult('route', 'route'); $builder = $this->manager->createNativeQuery( 'SELECT route FROM node_route WHERE route REGEXP ?', $mapper ) ->setParameter('1', $this->prepareMysqlRegexp($route)); //var_dump($builder->getArrayResult()); $i = 0; foreach($builder->getArrayResult() as $_route) { if(preg_match('#\(([0-9])*\)$#', $_route['route'], $matches)) { $i = (int) $matches[1] == $i ? (int) $matches[1]+1 : $i; } else { $i++; } } return ($i ? "($i)" : ''); }
[ "protected", "function", "getIncrement", "(", "$", "route", ")", "{", "// var_dump($route);", "$", "mapper", "=", "new", "ResultSetMapping", "(", ")", ";", "$", "mapper", "->", "addScalarResult", "(", "'route'", ",", "'route'", ")", ";", "$", "builder", "=", "$", "this", "->", "manager", "->", "createNativeQuery", "(", "'SELECT route FROM node_route WHERE route REGEXP ?'", ",", "$", "mapper", ")", "->", "setParameter", "(", "'1'", ",", "$", "this", "->", "prepareMysqlRegexp", "(", "$", "route", ")", ")", ";", "//var_dump($builder->getArrayResult());", "$", "i", "=", "0", ";", "foreach", "(", "$", "builder", "->", "getArrayResult", "(", ")", "as", "$", "_route", ")", "{", "if", "(", "preg_match", "(", "'#\\(([0-9])*\\)$#'", ",", "$", "_route", "[", "'route'", "]", ",", "$", "matches", ")", ")", "{", "$", "i", "=", "(", "int", ")", "$", "matches", "[", "1", "]", "==", "$", "i", "?", "(", "int", ")", "$", "matches", "[", "1", "]", "+", "1", ":", "$", "i", ";", "}", "else", "{", "$", "i", "++", ";", "}", "}", "return", "(", "$", "i", "?", "\"($i)\"", ":", "''", ")", ";", "}" ]
check if the generated route already exists and return the count @param string $route route string to check @return string increment value in parenthesis
[ "check", "if", "the", "generated", "route", "already", "exists", "and", "return", "the", "count" ]
7db1b03f5e120bd473486c0be6ab76c6146cd2d0
https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/Entity/NodeRouteManager.php#L144-L174
train
Mandarin-Medien/MMCmfRoutingBundle
Entity/NodeRouteManager.php
NodeRouteManager.prepareMysqlRegexp
protected function prepareMysqlRegexp($string) { $regexp = $string; // first remove trailing increment $regexp = preg_replace('/\([0-9]\)$/', "", $regexp); // escape existing parenthesis $regexp = preg_replace('(\(|\))', '\\\\${0}', $regexp); // append matching mysql matching pattern $regexp .= "([[.left-parenthesis.]][0-9]*[[.right-parenthesis.]])*$"; return $regexp; }
php
protected function prepareMysqlRegexp($string) { $regexp = $string; // first remove trailing increment $regexp = preg_replace('/\([0-9]\)$/', "", $regexp); // escape existing parenthesis $regexp = preg_replace('(\(|\))', '\\\\${0}', $regexp); // append matching mysql matching pattern $regexp .= "([[.left-parenthesis.]][0-9]*[[.right-parenthesis.]])*$"; return $regexp; }
[ "protected", "function", "prepareMysqlRegexp", "(", "$", "string", ")", "{", "$", "regexp", "=", "$", "string", ";", "// first remove trailing increment", "$", "regexp", "=", "preg_replace", "(", "'/\\([0-9]\\)$/'", ",", "\"\"", ",", "$", "regexp", ")", ";", "// escape existing parenthesis", "$", "regexp", "=", "preg_replace", "(", "'(\\(|\\))'", ",", "'\\\\\\\\${0}'", ",", "$", "regexp", ")", ";", "// append matching mysql matching pattern", "$", "regexp", ".=", "\"([[.left-parenthesis.]][0-9]*[[.right-parenthesis.]])*$\"", ";", "return", "$", "regexp", ";", "}" ]
create regexp for mysql query @param $string NodeRoute::route @return string
[ "create", "regexp", "for", "mysql", "query" ]
7db1b03f5e120bd473486c0be6ab76c6146cd2d0
https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/Entity/NodeRouteManager.php#L215-L230
train
CalderaWP/caldera-interop
src/Traits/Rest/ProvidesRoute.php
ProvidesRoute.addEndpoint
public function addEndpoint(Endpoint $endpoint): Route { $this->endpoints[get_class($endpoint)] = $endpoint; return $this; }
php
public function addEndpoint(Endpoint $endpoint): Route { $this->endpoints[get_class($endpoint)] = $endpoint; return $this; }
[ "public", "function", "addEndpoint", "(", "Endpoint", "$", "endpoint", ")", ":", "Route", "{", "$", "this", "->", "endpoints", "[", "get_class", "(", "$", "endpoint", ")", "]", "=", "$", "endpoint", ";", "return", "$", "this", ";", "}" ]
Add an endpoint to route @param Endpoint $endpoint @return Route
[ "Add", "an", "endpoint", "to", "route" ]
d25c4bc930200b314fbd42d084080b5d85261c94
https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/Traits/Rest/ProvidesRoute.php#L20-L24
train
joegreen88/zf1-component-validate
src/Zend/Validate/Barcode/AdapterAbstract.php
Zend_Validate_Barcode_AdapterAbstract.checkLength
public function checkLength($value) { if (!is_string($value)) { return false; } $fixum = strlen($value); $found = false; $length = $this->getLength(); if (is_array($length)) { foreach ($length as $value) { if ($fixum == $value) { $found = true; } if ($value == -1) { $found = true; } } } elseif ($fixum == $length) { $found = true; } elseif ($length == -1) { $found = true; } elseif ($length == 'even') { $count = $fixum % 2; $found = ($count == 0) ? true : false; } elseif ($length == 'odd') { $count = $fixum % 2; $found = ($count == 1) ? true : false; } return $found; }
php
public function checkLength($value) { if (!is_string($value)) { return false; } $fixum = strlen($value); $found = false; $length = $this->getLength(); if (is_array($length)) { foreach ($length as $value) { if ($fixum == $value) { $found = true; } if ($value == -1) { $found = true; } } } elseif ($fixum == $length) { $found = true; } elseif ($length == -1) { $found = true; } elseif ($length == 'even') { $count = $fixum % 2; $found = ($count == 0) ? true : false; } elseif ($length == 'odd') { $count = $fixum % 2; $found = ($count == 1) ? true : false; } return $found; }
[ "public", "function", "checkLength", "(", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "$", "fixum", "=", "strlen", "(", "$", "value", ")", ";", "$", "found", "=", "false", ";", "$", "length", "=", "$", "this", "->", "getLength", "(", ")", ";", "if", "(", "is_array", "(", "$", "length", ")", ")", "{", "foreach", "(", "$", "length", "as", "$", "value", ")", "{", "if", "(", "$", "fixum", "==", "$", "value", ")", "{", "$", "found", "=", "true", ";", "}", "if", "(", "$", "value", "==", "-", "1", ")", "{", "$", "found", "=", "true", ";", "}", "}", "}", "elseif", "(", "$", "fixum", "==", "$", "length", ")", "{", "$", "found", "=", "true", ";", "}", "elseif", "(", "$", "length", "==", "-", "1", ")", "{", "$", "found", "=", "true", ";", "}", "elseif", "(", "$", "length", "==", "'even'", ")", "{", "$", "count", "=", "$", "fixum", "%", "2", ";", "$", "found", "=", "(", "$", "count", "==", "0", ")", "?", "true", ":", "false", ";", "}", "elseif", "(", "$", "length", "==", "'odd'", ")", "{", "$", "count", "=", "$", "fixum", "%", "2", ";", "$", "found", "=", "(", "$", "count", "==", "1", ")", "?", "true", ":", "false", ";", "}", "return", "$", "found", ";", "}" ]
Checks the length of a barcode @param string $value The barcode to check for proper length @return boolean
[ "Checks", "the", "length", "of", "a", "barcode" ]
88d9ea016f73d48ff0ba7d06ecbbf28951fd279e
https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Barcode/AdapterAbstract.php#L66-L98
train
joegreen88/zf1-component-validate
src/Zend/Validate/Barcode/AdapterAbstract.php
Zend_Validate_Barcode_AdapterAbstract.checkChars
public function checkChars($value) { if (!is_string($value)) { return false; } $characters = $this->getCharacters(); if ($characters == 128) { for ($x = 0; $x < 128; ++$x) { $value = str_replace(chr($x), '', $value); } } else { $chars = str_split($characters); foreach ($chars as $char) { $value = str_replace($char, '', $value); } } if (strlen($value) > 0) { return false; } return true; }
php
public function checkChars($value) { if (!is_string($value)) { return false; } $characters = $this->getCharacters(); if ($characters == 128) { for ($x = 0; $x < 128; ++$x) { $value = str_replace(chr($x), '', $value); } } else { $chars = str_split($characters); foreach ($chars as $char) { $value = str_replace($char, '', $value); } } if (strlen($value) > 0) { return false; } return true; }
[ "public", "function", "checkChars", "(", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "$", "characters", "=", "$", "this", "->", "getCharacters", "(", ")", ";", "if", "(", "$", "characters", "==", "128", ")", "{", "for", "(", "$", "x", "=", "0", ";", "$", "x", "<", "128", ";", "++", "$", "x", ")", "{", "$", "value", "=", "str_replace", "(", "chr", "(", "$", "x", ")", ",", "''", ",", "$", "value", ")", ";", "}", "}", "else", "{", "$", "chars", "=", "str_split", "(", "$", "characters", ")", ";", "foreach", "(", "$", "chars", "as", "$", "char", ")", "{", "$", "value", "=", "str_replace", "(", "$", "char", ",", "''", ",", "$", "value", ")", ";", "}", "}", "if", "(", "strlen", "(", "$", "value", ")", ">", "0", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks for allowed characters within the barcode @param string $value The barcode to check for allowed characters @return boolean
[ "Checks", "for", "allowed", "characters", "within", "the", "barcode" ]
88d9ea016f73d48ff0ba7d06ecbbf28951fd279e
https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Barcode/AdapterAbstract.php#L106-L129
train
devlabmtl/haven-core
Controller/CategoryController.php
CategoryController.listAction
public function listAction() { $entities = $this->container->get("haven_core.category.read_handler")->getAll(); foreach ($entities as $entity) { $delete_forms[$entity->getId()] = $this->container->get("haven_core.category.form_handler")->createDeleteForm($entity->getId())->createView(); } return array("entities" => $entities , 'delete_forms' => isset($delete_forms) && is_array($delete_forms) ? $delete_forms : array() , "entities" => $entities); }
php
public function listAction() { $entities = $this->container->get("haven_core.category.read_handler")->getAll(); foreach ($entities as $entity) { $delete_forms[$entity->getId()] = $this->container->get("haven_core.category.form_handler")->createDeleteForm($entity->getId())->createView(); } return array("entities" => $entities , 'delete_forms' => isset($delete_forms) && is_array($delete_forms) ? $delete_forms : array() , "entities" => $entities); }
[ "public", "function", "listAction", "(", ")", "{", "$", "entities", "=", "$", "this", "->", "container", "->", "get", "(", "\"haven_core.category.read_handler\"", ")", "->", "getAll", "(", ")", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "$", "delete_forms", "[", "$", "entity", "->", "getId", "(", ")", "]", "=", "$", "this", "->", "container", "->", "get", "(", "\"haven_core.category.form_handler\"", ")", "->", "createDeleteForm", "(", "$", "entity", "->", "getId", "(", ")", ")", "->", "createView", "(", ")", ";", "}", "return", "array", "(", "\"entities\"", "=>", "$", "entities", ",", "'delete_forms'", "=>", "isset", "(", "$", "delete_forms", ")", "&&", "is_array", "(", "$", "delete_forms", ")", "?", "$", "delete_forms", ":", "array", "(", ")", ",", "\"entities\"", "=>", "$", "entities", ")", ";", "}" ]
Finds and all persona for admin. @Route("admin/list/category") @Method("GET") @Template()
[ "Finds", "and", "all", "persona", "for", "admin", "." ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Controller/CategoryController.php#L48-L58
train
devlabmtl/haven-core
Controller/CategoryController.php
CategoryController.addAction
public function addAction() { $edit_form = $this->container->get("haven_core.category.form_handler")->createNewForm(); $request = $this->container->get('request_modifier')->setRequest($this->container->get("request")) ->slug(array("name")) ->getRequest(); $edit_form->bind($request); if ($edit_form->isValid()) { $this->container->get("haven_core.category.persistence_handler")->save($edit_form->getData()); $this->container->get("session")->getFlashBag()->add("success", "create.success"); return new RedirectResponse($this->container->get('router')->generate(str_replace('update', "list", $this->container->get("request")->get("_route")))); } $this->container->get("session")->getFlashBag()->add("error", "create.error"); $template = str_replace(":create.html.twig", ":new.html.twig", $this->container->get("request")->get('_template')); $params = array( 'edit_form' => $edit_form->createView() ); return new Response($this->container->get('templating')->render($template, $params)); }
php
public function addAction() { $edit_form = $this->container->get("haven_core.category.form_handler")->createNewForm(); $request = $this->container->get('request_modifier')->setRequest($this->container->get("request")) ->slug(array("name")) ->getRequest(); $edit_form->bind($request); if ($edit_form->isValid()) { $this->container->get("haven_core.category.persistence_handler")->save($edit_form->getData()); $this->container->get("session")->getFlashBag()->add("success", "create.success"); return new RedirectResponse($this->container->get('router')->generate(str_replace('update', "list", $this->container->get("request")->get("_route")))); } $this->container->get("session")->getFlashBag()->add("error", "create.error"); $template = str_replace(":create.html.twig", ":new.html.twig", $this->container->get("request")->get('_template')); $params = array( 'edit_form' => $edit_form->createView() ); return new Response($this->container->get('templating')->render($template, $params)); }
[ "public", "function", "addAction", "(", ")", "{", "$", "edit_form", "=", "$", "this", "->", "container", "->", "get", "(", "\"haven_core.category.form_handler\"", ")", "->", "createNewForm", "(", ")", ";", "$", "request", "=", "$", "this", "->", "container", "->", "get", "(", "'request_modifier'", ")", "->", "setRequest", "(", "$", "this", "->", "container", "->", "get", "(", "\"request\"", ")", ")", "->", "slug", "(", "array", "(", "\"name\"", ")", ")", "->", "getRequest", "(", ")", ";", "$", "edit_form", "->", "bind", "(", "$", "request", ")", ";", "if", "(", "$", "edit_form", "->", "isValid", "(", ")", ")", "{", "$", "this", "->", "container", "->", "get", "(", "\"haven_core.category.persistence_handler\"", ")", "->", "save", "(", "$", "edit_form", "->", "getData", "(", ")", ")", ";", "$", "this", "->", "container", "->", "get", "(", "\"session\"", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "\"success\"", ",", "\"create.success\"", ")", ";", "return", "new", "RedirectResponse", "(", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "generate", "(", "str_replace", "(", "'update'", ",", "\"list\"", ",", "$", "this", "->", "container", "->", "get", "(", "\"request\"", ")", "->", "get", "(", "\"_route\"", ")", ")", ")", ")", ";", "}", "$", "this", "->", "container", "->", "get", "(", "\"session\"", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "\"error\"", ",", "\"create.error\"", ")", ";", "$", "template", "=", "str_replace", "(", "\":create.html.twig\"", ",", "\":new.html.twig\"", ",", "$", "this", "->", "container", "->", "get", "(", "\"request\"", ")", "->", "get", "(", "'_template'", ")", ")", ";", "$", "params", "=", "array", "(", "'edit_form'", "=>", "$", "edit_form", "->", "createView", "(", ")", ")", ";", "return", "new", "Response", "(", "$", "this", "->", "container", "->", "get", "(", "'templating'", ")", "->", "render", "(", "$", "template", ",", "$", "params", ")", ")", ";", "}" ]
Creates a new persona entity. @Route("/admin/create/category") @Method("POST") @Template
[ "Creates", "a", "new", "persona", "entity", "." ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Controller/CategoryController.php#L98-L123
train
Nekland/BaseApi
lib/Nekland/BaseApi/ApiFactory.php
ApiFactory.useAuthentication
public function useAuthentication($auth, array $options = []) { if (!($auth instanceof AuthStrategyInterface)) { $auth = $this->getAuthFactory()->get($auth); $auth->setOptions($options); } $this->dispatcher->addListener(Events::ON_REQUEST_EVENT, [ $auth, 'auth' ]); }
php
public function useAuthentication($auth, array $options = []) { if (!($auth instanceof AuthStrategyInterface)) { $auth = $this->getAuthFactory()->get($auth); $auth->setOptions($options); } $this->dispatcher->addListener(Events::ON_REQUEST_EVENT, [ $auth, 'auth' ]); }
[ "public", "function", "useAuthentication", "(", "$", "auth", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "(", "$", "auth", "instanceof", "AuthStrategyInterface", ")", ")", "{", "$", "auth", "=", "$", "this", "->", "getAuthFactory", "(", ")", "->", "get", "(", "$", "auth", ")", ";", "$", "auth", "->", "setOptions", "(", "$", "options", ")", ";", "}", "$", "this", "->", "dispatcher", "->", "addListener", "(", "Events", "::", "ON_REQUEST_EVENT", ",", "[", "$", "auth", ",", "'auth'", "]", ")", ";", "}" ]
Allow the user to add an authentication to the request @param string|AuthStrategyInterface $auth @param array $options
[ "Allow", "the", "user", "to", "add", "an", "authentication", "to", "the", "request" ]
c96051b36d6982abf2a8b1f1ec16351bcae2455e
https://github.com/Nekland/BaseApi/blob/c96051b36d6982abf2a8b1f1ec16351bcae2455e/lib/Nekland/BaseApi/ApiFactory.php#L80-L91
train
irfantoor/console
src/Console.php
Console.applyStyle
function applyStyle($text, $styles = []) { if (!self::$supported) return $text; if (is_string($styles)) { $styles = [$styles]; } $output = $text; foreach ($styles as $style) { if (isset(self::$theme[$style])) { $output = $this->applyStyle($output, self::$theme[$style]); } else { if (isset(self::$styles[$style])) { $pre = $this->escSequence(self::$styles[$style]); $post = $this->escSequence(0); } else { $pre = $post = ''; } $output = $pre . $output . $post; } } return $output; }
php
function applyStyle($text, $styles = []) { if (!self::$supported) return $text; if (is_string($styles)) { $styles = [$styles]; } $output = $text; foreach ($styles as $style) { if (isset(self::$theme[$style])) { $output = $this->applyStyle($output, self::$theme[$style]); } else { if (isset(self::$styles[$style])) { $pre = $this->escSequence(self::$styles[$style]); $post = $this->escSequence(0); } else { $pre = $post = ''; } $output = $pre . $output . $post; } } return $output; }
[ "function", "applyStyle", "(", "$", "text", ",", "$", "styles", "=", "[", "]", ")", "{", "if", "(", "!", "self", "::", "$", "supported", ")", "return", "$", "text", ";", "if", "(", "is_string", "(", "$", "styles", ")", ")", "{", "$", "styles", "=", "[", "$", "styles", "]", ";", "}", "$", "output", "=", "$", "text", ";", "foreach", "(", "$", "styles", "as", "$", "style", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "theme", "[", "$", "style", "]", ")", ")", "{", "$", "output", "=", "$", "this", "->", "applyStyle", "(", "$", "output", ",", "self", "::", "$", "theme", "[", "$", "style", "]", ")", ";", "}", "else", "{", "if", "(", "isset", "(", "self", "::", "$", "styles", "[", "$", "style", "]", ")", ")", "{", "$", "pre", "=", "$", "this", "->", "escSequence", "(", "self", "::", "$", "styles", "[", "$", "style", "]", ")", ";", "$", "post", "=", "$", "this", "->", "escSequence", "(", "0", ")", ";", "}", "else", "{", "$", "pre", "=", "$", "post", "=", "''", ";", "}", "$", "output", "=", "$", "pre", ".", "$", "output", ".", "$", "post", ";", "}", "}", "return", "$", "output", ";", "}" ]
Returns the text with the styles applied to it @param string @param string|array @return string
[ "Returns", "the", "text", "with", "the", "styles", "applied", "to", "it" ]
683927e2205a4d54061add377cb2b33adc1d83dc
https://github.com/irfantoor/console/blob/683927e2205a4d54061add377cb2b33adc1d83dc/src/Console.php#L102-L129
train
irfantoor/console
src/Console.php
Console.read
public function read($prompt, $style = '') { $this->write($prompt . ' ', $style); $stdin = fopen('php://stdin', 'r'); $str = fgets($stdin, 4096); fclose($stdin); return preg_replace('{\r?\n$}D', '', $str); }
php
public function read($prompt, $style = '') { $this->write($prompt . ' ', $style); $stdin = fopen('php://stdin', 'r'); $str = fgets($stdin, 4096); fclose($stdin); return preg_replace('{\r?\n$}D', '', $str); }
[ "public", "function", "read", "(", "$", "prompt", ",", "$", "style", "=", "''", ")", "{", "$", "this", "->", "write", "(", "$", "prompt", ".", "' '", ",", "$", "style", ")", ";", "$", "stdin", "=", "fopen", "(", "'php://stdin'", ",", "'r'", ")", ";", "$", "str", "=", "fgets", "(", "$", "stdin", ",", "4096", ")", ";", "fclose", "(", "$", "stdin", ")", ";", "return", "preg_replace", "(", "'{\\r?\\n$}D'", ",", "''", ",", "$", "str", ")", ";", "}" ]
Read a line from input with an optional prompt and optional style @param string $prompt can be string to be prompted before reading from console @param mixed $style can be null, a style code as string or an array of strings. @return the line read from console
[ "Read", "a", "line", "from", "input", "with", "an", "optional", "prompt", "and", "optional", "style" ]
683927e2205a4d54061add377cb2b33adc1d83dc
https://github.com/irfantoor/console/blob/683927e2205a4d54061add377cb2b33adc1d83dc/src/Console.php#L150-L156
train
irfantoor/console
src/Console.php
Console.write
public function write($text = '', $style = 'none') { if (is_array($text)) { $max = 0; foreach($text as $txt) { $max = max($max, strlen($txt)); } $outline = str_repeat(' ', $max + 4); $this->writeln($outline, $style); foreach($text as $txt) { $len = strlen($txt); $pre_space = str_repeat(' ', 2); $post_space = str_repeat(' ', $max + 2 - $len); $this->writeln($pre_space . $txt . $post_space, $style); } $this->writeln($outline, $style); } else { echo $this->applyStyle($text, $style); } }
php
public function write($text = '', $style = 'none') { if (is_array($text)) { $max = 0; foreach($text as $txt) { $max = max($max, strlen($txt)); } $outline = str_repeat(' ', $max + 4); $this->writeln($outline, $style); foreach($text as $txt) { $len = strlen($txt); $pre_space = str_repeat(' ', 2); $post_space = str_repeat(' ', $max + 2 - $len); $this->writeln($pre_space . $txt . $post_space, $style); } $this->writeln($outline, $style); } else { echo $this->applyStyle($text, $style); } }
[ "public", "function", "write", "(", "$", "text", "=", "''", ",", "$", "style", "=", "'none'", ")", "{", "if", "(", "is_array", "(", "$", "text", ")", ")", "{", "$", "max", "=", "0", ";", "foreach", "(", "$", "text", "as", "$", "txt", ")", "{", "$", "max", "=", "max", "(", "$", "max", ",", "strlen", "(", "$", "txt", ")", ")", ";", "}", "$", "outline", "=", "str_repeat", "(", "' '", ",", "$", "max", "+", "4", ")", ";", "$", "this", "->", "writeln", "(", "$", "outline", ",", "$", "style", ")", ";", "foreach", "(", "$", "text", "as", "$", "txt", ")", "{", "$", "len", "=", "strlen", "(", "$", "txt", ")", ";", "$", "pre_space", "=", "str_repeat", "(", "' '", ",", "2", ")", ";", "$", "post_space", "=", "str_repeat", "(", "' '", ",", "$", "max", "+", "2", "-", "$", "len", ")", ";", "$", "this", "->", "writeln", "(", "$", "pre_space", ".", "$", "txt", ".", "$", "post_space", ",", "$", "style", ")", ";", "}", "$", "this", "->", "writeln", "(", "$", "outline", ",", "$", "style", ")", ";", "}", "else", "{", "echo", "$", "this", "->", "applyStyle", "(", "$", "text", ",", "$", "style", ")", ";", "}", "}" ]
Write a line or a group of lines to output @param mixed $text can be string or an array of strings @param mixed $style can be null, a style code as string or an array of strings.
[ "Write", "a", "line", "or", "a", "group", "of", "lines", "to", "output" ]
683927e2205a4d54061add377cb2b33adc1d83dc
https://github.com/irfantoor/console/blob/683927e2205a4d54061add377cb2b33adc1d83dc/src/Console.php#L164-L187
train
stevenliebregt/crispysystem
src/Helpers/Config.php
Config.init
public static function init() { $file = ROOT . 'storage/crispysystem.config.php'; if (!is_readable($file)) { showPlainError('The file `crispysystem.config.php` in the `storage` directory is not readable'); } $config = unserialize(file_get_contents($file)); static::$config = $config; }
php
public static function init() { $file = ROOT . 'storage/crispysystem.config.php'; if (!is_readable($file)) { showPlainError('The file `crispysystem.config.php` in the `storage` directory is not readable'); } $config = unserialize(file_get_contents($file)); static::$config = $config; }
[ "public", "static", "function", "init", "(", ")", "{", "$", "file", "=", "ROOT", ".", "'storage/crispysystem.config.php'", ";", "if", "(", "!", "is_readable", "(", "$", "file", ")", ")", "{", "showPlainError", "(", "'The file `crispysystem.config.php` in the `storage` directory is not readable'", ")", ";", "}", "$", "config", "=", "unserialize", "(", "file_get_contents", "(", "$", "file", ")", ")", ";", "static", "::", "$", "config", "=", "$", "config", ";", "}" ]
Read the config from the cached file @since 1.0.0
[ "Read", "the", "config", "from", "the", "cached", "file" ]
06547dae100dae1023a93ec903f2d2abacce9aec
https://github.com/stevenliebregt/crispysystem/blob/06547dae100dae1023a93ec903f2d2abacce9aec/src/Helpers/Config.php#L25-L35
train
stevenliebregt/crispysystem
src/Helpers/Config.php
Config.cache
public static function cache() { $cache = []; $finder = (new Finder()) ->files() ->name('/.+\.php/') ->in(ROOT . 'config'); /** @var SplFileInfo $file */ foreach ($finder as $file) { $category = str_ireplace('.php', '', $file->getFilename()); $config = require $file->getRealPath(); $cache[$category] = $config; } file_put_contents(ROOT . 'storage/crispysystem.config.php', serialize($cache)); }
php
public static function cache() { $cache = []; $finder = (new Finder()) ->files() ->name('/.+\.php/') ->in(ROOT . 'config'); /** @var SplFileInfo $file */ foreach ($finder as $file) { $category = str_ireplace('.php', '', $file->getFilename()); $config = require $file->getRealPath(); $cache[$category] = $config; } file_put_contents(ROOT . 'storage/crispysystem.config.php', serialize($cache)); }
[ "public", "static", "function", "cache", "(", ")", "{", "$", "cache", "=", "[", "]", ";", "$", "finder", "=", "(", "new", "Finder", "(", ")", ")", "->", "files", "(", ")", "->", "name", "(", "'/.+\\.php/'", ")", "->", "in", "(", "ROOT", ".", "'config'", ")", ";", "/** @var SplFileInfo $file */", "foreach", "(", "$", "finder", "as", "$", "file", ")", "{", "$", "category", "=", "str_ireplace", "(", "'.php'", ",", "''", ",", "$", "file", "->", "getFilename", "(", ")", ")", ";", "$", "config", "=", "require", "$", "file", "->", "getRealPath", "(", ")", ";", "$", "cache", "[", "$", "category", "]", "=", "$", "config", ";", "}", "file_put_contents", "(", "ROOT", ".", "'storage/crispysystem.config.php'", ",", "serialize", "(", "$", "cache", ")", ")", ";", "}" ]
Cache the configuration files into one file @since 1.0.0
[ "Cache", "the", "configuration", "files", "into", "one", "file" ]
06547dae100dae1023a93ec903f2d2abacce9aec
https://github.com/stevenliebregt/crispysystem/blob/06547dae100dae1023a93ec903f2d2abacce9aec/src/Helpers/Config.php#L41-L59
train
stevenliebregt/crispysystem
src/Helpers/Config.php
Config.get
public static function get(string $key = null) { if (is_null($key)) { return static::$config; } // Key is formatted like database.default.driver $config = static::$config; $key = explode('.', $key); foreach ($key as $k) { if (!isset($config[$k])) { return null; } $config = $config[$k]; } return $config; }
php
public static function get(string $key = null) { if (is_null($key)) { return static::$config; } // Key is formatted like database.default.driver $config = static::$config; $key = explode('.', $key); foreach ($key as $k) { if (!isset($config[$k])) { return null; } $config = $config[$k]; } return $config; }
[ "public", "static", "function", "get", "(", "string", "$", "key", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "return", "static", "::", "$", "config", ";", "}", "// Key is formatted like database.default.driver", "$", "config", "=", "static", "::", "$", "config", ";", "$", "key", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "foreach", "(", "$", "key", "as", "$", "k", ")", "{", "if", "(", "!", "isset", "(", "$", "config", "[", "$", "k", "]", ")", ")", "{", "return", "null", ";", "}", "$", "config", "=", "$", "config", "[", "$", "k", "]", ";", "}", "return", "$", "config", ";", "}" ]
Get the value of a configuration key @param string|null $key Name of the key you want value of, leave empty to retrieve all, multidimensional keys are formatted like: key.subkey.subsubkey.something @return array|mixed|null Retrieve values or null if key doesn't exist @since 1.0.0
[ "Get", "the", "value", "of", "a", "configuration", "key" ]
06547dae100dae1023a93ec903f2d2abacce9aec
https://github.com/stevenliebregt/crispysystem/blob/06547dae100dae1023a93ec903f2d2abacce9aec/src/Helpers/Config.php#L68-L83
train
lightwerk/SurfCaptain
Classes/Lightwerk/SurfCaptain/Domain/Repository/Preset/GitRepository.php
GitRepository.savePresets
protected function savePresets(array $presets, $logMessage) { $this->driverComposite->setFileContent( $this->settings['repositoryUrl'], $this->settings['filePath'], json_encode($presets, JSON_PRETTY_PRINT), '[SURFCAPTAIN] ' . $logMessage ); $this->presets = null; }
php
protected function savePresets(array $presets, $logMessage) { $this->driverComposite->setFileContent( $this->settings['repositoryUrl'], $this->settings['filePath'], json_encode($presets, JSON_PRETTY_PRINT), '[SURFCAPTAIN] ' . $logMessage ); $this->presets = null; }
[ "protected", "function", "savePresets", "(", "array", "$", "presets", ",", "$", "logMessage", ")", "{", "$", "this", "->", "driverComposite", "->", "setFileContent", "(", "$", "this", "->", "settings", "[", "'repositoryUrl'", "]", ",", "$", "this", "->", "settings", "[", "'filePath'", "]", ",", "json_encode", "(", "$", "presets", ",", "JSON_PRETTY_PRINT", ")", ",", "'[SURFCAPTAIN] '", ".", "$", "logMessage", ")", ";", "$", "this", "->", "presets", "=", "null", ";", "}" ]
Saves the presets. @param array $presets @param string $logMessage @return void
[ "Saves", "the", "presets", "." ]
2865e963fd634504d8923902cf422873749a0940
https://github.com/lightwerk/SurfCaptain/blob/2865e963fd634504d8923902cf422873749a0940/Classes/Lightwerk/SurfCaptain/Domain/Repository/Preset/GitRepository.php#L50-L59
train
lightwerk/SurfCaptain
Classes/Lightwerk/SurfCaptain/Domain/Repository/Preset/GitRepository.php
GitRepository.loadPresets
protected function loadPresets() { if (!isset($this->presets)) { $this->presets = json_decode( $this->driverComposite->getFileContent($this->settings['repositoryUrl'], $this->settings['filePath']), true ); if (empty($this->presets)) { throw new Exception('Could not load presets', 1407782202); } } return $this->presets; }
php
protected function loadPresets() { if (!isset($this->presets)) { $this->presets = json_decode( $this->driverComposite->getFileContent($this->settings['repositoryUrl'], $this->settings['filePath']), true ); if (empty($this->presets)) { throw new Exception('Could not load presets', 1407782202); } } return $this->presets; }
[ "protected", "function", "loadPresets", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "presets", ")", ")", "{", "$", "this", "->", "presets", "=", "json_decode", "(", "$", "this", "->", "driverComposite", "->", "getFileContent", "(", "$", "this", "->", "settings", "[", "'repositoryUrl'", "]", ",", "$", "this", "->", "settings", "[", "'filePath'", "]", ")", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "presets", ")", ")", "{", "throw", "new", "Exception", "(", "'Could not load presets'", ",", "1407782202", ")", ";", "}", "}", "return", "$", "this", "->", "presets", ";", "}" ]
Load the presets. @return array $presets @throws Exception
[ "Load", "the", "presets", "." ]
2865e963fd634504d8923902cf422873749a0940
https://github.com/lightwerk/SurfCaptain/blob/2865e963fd634504d8923902cf422873749a0940/Classes/Lightwerk/SurfCaptain/Domain/Repository/Preset/GitRepository.php#L67-L79
train
prolic/HumusMvc
src/HumusMvc/Cache/Service/CacheManagerFactory.php
CacheManagerFactory.createService
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); if (!isset($config['cache_manager'])) { throw new Exception\RuntimeException( 'No cache manager config found.' ); } $options = $config['cache_manager']; $manager = new CacheManager; foreach ($options as $key => $value) { if ($manager->hasCacheTemplate($key)) { $manager->setTemplateOptions($key, $value); } else { $manager->setCacheTemplate($key, $value); } } return $manager; }
php
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); if (!isset($config['cache_manager'])) { throw new Exception\RuntimeException( 'No cache manager config found.' ); } $options = $config['cache_manager']; $manager = new CacheManager; foreach ($options as $key => $value) { if ($manager->hasCacheTemplate($key)) { $manager->setTemplateOptions($key, $value); } else { $manager->setCacheTemplate($key, $value); } } return $manager; }
[ "public", "function", "createService", "(", "ServiceLocatorInterface", "$", "serviceLocator", ")", "{", "$", "config", "=", "$", "serviceLocator", "->", "get", "(", "'Config'", ")", ";", "if", "(", "!", "isset", "(", "$", "config", "[", "'cache_manager'", "]", ")", ")", "{", "throw", "new", "Exception", "\\", "RuntimeException", "(", "'No cache manager config found.'", ")", ";", "}", "$", "options", "=", "$", "config", "[", "'cache_manager'", "]", ";", "$", "manager", "=", "new", "CacheManager", ";", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "manager", "->", "hasCacheTemplate", "(", "$", "key", ")", ")", "{", "$", "manager", "->", "setTemplateOptions", "(", "$", "key", ",", "$", "value", ")", ";", "}", "else", "{", "$", "manager", "->", "setCacheTemplate", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}", "return", "$", "manager", ";", "}" ]
Create cache manager service @param ServiceLocatorInterface $serviceLocator @return CacheManager @throws Exception\RuntimeException
[ "Create", "cache", "manager", "service" ]
09e8c6422d84b57745cc643047e10761be2a21a7
https://github.com/prolic/HumusMvc/blob/09e8c6422d84b57745cc643047e10761be2a21a7/src/HumusMvc/Cache/Service/CacheManagerFactory.php#L35-L53
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.setAuthentication
public function setAuthentication($username, $password) { $this->_mailer->Username = $username; $this->_mailer->Password = $password; return $this; }
php
public function setAuthentication($username, $password) { $this->_mailer->Username = $username; $this->_mailer->Password = $password; return $this; }
[ "public", "function", "setAuthentication", "(", "$", "username", ",", "$", "password", ")", "{", "$", "this", "->", "_mailer", "->", "Username", "=", "$", "username", ";", "$", "this", "->", "_mailer", "->", "Password", "=", "$", "password", ";", "return", "$", "this", ";", "}" ]
Sets the authentication used to send the mail. @param string $username @param string $password @return \Scara\Mail\Mailer
[ "Sets", "the", "authentication", "used", "to", "send", "the", "mail", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L87-L93
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.create
public function create($options = []) { if (isset($options['to'])) { $name = ''; if (is_array($options['to'])) { if (isset($options['to'][1])) { $name = $options['to'][1]; } $this->setTo($options['to'][0], $name); } else { $this->setTo($options['to']); } } if (isset($options['from'])) { $name = ''; if (is_array($options['from'])) { if (isset($options['from'][1])) { $name = $options['from'][1]; } $this->setFrom($options['from'][0], $name); } else { $this->setFrom($options['from']); } } if (isset($options['subject'])) { $this->addSubject($options['subject']); } return $this; }
php
public function create($options = []) { if (isset($options['to'])) { $name = ''; if (is_array($options['to'])) { if (isset($options['to'][1])) { $name = $options['to'][1]; } $this->setTo($options['to'][0], $name); } else { $this->setTo($options['to']); } } if (isset($options['from'])) { $name = ''; if (is_array($options['from'])) { if (isset($options['from'][1])) { $name = $options['from'][1]; } $this->setFrom($options['from'][0], $name); } else { $this->setFrom($options['from']); } } if (isset($options['subject'])) { $this->addSubject($options['subject']); } return $this; }
[ "public", "function", "create", "(", "$", "options", "=", "[", "]", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'to'", "]", ")", ")", "{", "$", "name", "=", "''", ";", "if", "(", "is_array", "(", "$", "options", "[", "'to'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'to'", "]", "[", "1", "]", ")", ")", "{", "$", "name", "=", "$", "options", "[", "'to'", "]", "[", "1", "]", ";", "}", "$", "this", "->", "setTo", "(", "$", "options", "[", "'to'", "]", "[", "0", "]", ",", "$", "name", ")", ";", "}", "else", "{", "$", "this", "->", "setTo", "(", "$", "options", "[", "'to'", "]", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "options", "[", "'from'", "]", ")", ")", "{", "$", "name", "=", "''", ";", "if", "(", "is_array", "(", "$", "options", "[", "'from'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'from'", "]", "[", "1", "]", ")", ")", "{", "$", "name", "=", "$", "options", "[", "'from'", "]", "[", "1", "]", ";", "}", "$", "this", "->", "setFrom", "(", "$", "options", "[", "'from'", "]", "[", "0", "]", ",", "$", "name", ")", ";", "}", "else", "{", "$", "this", "->", "setFrom", "(", "$", "options", "[", "'from'", "]", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "options", "[", "'subject'", "]", ")", ")", "{", "$", "this", "->", "addSubject", "(", "$", "options", "[", "'subject'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Creates the initial message. Takes in to, from and subject. @param array $options @return \Scara\Mail\Mailer
[ "Creates", "the", "initial", "message", ".", "Takes", "in", "to", "from", "and", "subject", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L102-L137
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.setTo
public function setTo($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for setTo!'); } if (empty($name)) { $name = substr($email, 0, strrpos($email, '@')); } if (is_null($this->to)) { $this->to = [$email, $name]; } else { throw new MailerException('A master recipient has already been set!'); } return $this; }
php
public function setTo($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for setTo!'); } if (empty($name)) { $name = substr($email, 0, strrpos($email, '@')); } if (is_null($this->to)) { $this->to = [$email, $name]; } else { throw new MailerException('A master recipient has already been set!'); } return $this; }
[ "public", "function", "setTo", "(", "$", "email", ",", "$", "name", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "email", ")", ")", "{", "throw", "new", "MailerException", "(", "'email is required for setTo!'", ")", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "$", "name", "=", "substr", "(", "$", "email", ",", "0", ",", "strrpos", "(", "$", "email", ",", "'@'", ")", ")", ";", "}", "if", "(", "is_null", "(", "$", "this", "->", "to", ")", ")", "{", "$", "this", "->", "to", "=", "[", "$", "email", ",", "$", "name", "]", ";", "}", "else", "{", "throw", "new", "MailerException", "(", "'A master recipient has already been set!'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the Recipient of the email. @param string $email @param string $name @return \Scara\Mail\Mailer
[ "Sets", "the", "Recipient", "of", "the", "email", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L147-L164
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.setFrom
public function setFrom($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for setFrom!'); } if (empty($name)) { $name = substr($email, 0, strrpos($email, '@')); } if (is_null($this->from)) { $this->from = [$email, $name]; } else { throw new MailerException('Sender has already been set!'); } return $this; }
php
public function setFrom($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for setFrom!'); } if (empty($name)) { $name = substr($email, 0, strrpos($email, '@')); } if (is_null($this->from)) { $this->from = [$email, $name]; } else { throw new MailerException('Sender has already been set!'); } return $this; }
[ "public", "function", "setFrom", "(", "$", "email", ",", "$", "name", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "email", ")", ")", "{", "throw", "new", "MailerException", "(", "'email is required for setFrom!'", ")", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "$", "name", "=", "substr", "(", "$", "email", ",", "0", ",", "strrpos", "(", "$", "email", ",", "'@'", ")", ")", ";", "}", "if", "(", "is_null", "(", "$", "this", "->", "from", ")", ")", "{", "$", "this", "->", "from", "=", "[", "$", "email", ",", "$", "name", "]", ";", "}", "else", "{", "throw", "new", "MailerException", "(", "'Sender has already been set!'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the Sender of the email. @param string $email @param string $name @return \Scara\Mail\Mailer
[ "Sets", "the", "Sender", "of", "the", "email", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L174-L191
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.cc
public function cc($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for cc!'); } $this->_mailer->addCC($email, $name); return $this; }
php
public function cc($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for cc!'); } $this->_mailer->addCC($email, $name); return $this; }
[ "public", "function", "cc", "(", "$", "email", ",", "$", "name", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "email", ")", ")", "{", "throw", "new", "MailerException", "(", "'email is required for cc!'", ")", ";", "}", "$", "this", "->", "_mailer", "->", "addCC", "(", "$", "email", ",", "$", "name", ")", ";", "return", "$", "this", ";", "}" ]
Adds a CC to the email. @param string $email @param string $name @return \Scara\Mail\Mailer
[ "Adds", "a", "CC", "to", "the", "email", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L201-L210
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.bcc
public function bcc($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for bcc!'); } $this->_mailer->addBCC($email, $name); return $this; }
php
public function bcc($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for bcc!'); } $this->_mailer->addBCC($email, $name); return $this; }
[ "public", "function", "bcc", "(", "$", "email", ",", "$", "name", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "email", ")", ")", "{", "throw", "new", "MailerException", "(", "'email is required for bcc!'", ")", ";", "}", "$", "this", "->", "_mailer", "->", "addBCC", "(", "$", "email", ",", "$", "name", ")", ";", "return", "$", "this", ";", "}" ]
Adds a VCC to the email. @param string $email @param string $name @return \Scara\Mail\Mailer
[ "Adds", "a", "VCC", "to", "the", "email", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L220-L229
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.addAddress
public function addAddress($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for addAddress!'); } $this->_mailer->addAddress($email, $name); return $this; }
php
public function addAddress($email, $name = '') { if (empty($email)) { throw new MailerException('email is required for addAddress!'); } $this->_mailer->addAddress($email, $name); return $this; }
[ "public", "function", "addAddress", "(", "$", "email", ",", "$", "name", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "email", ")", ")", "{", "throw", "new", "MailerException", "(", "'email is required for addAddress!'", ")", ";", "}", "$", "this", "->", "_mailer", "->", "addAddress", "(", "$", "email", ",", "$", "name", ")", ";", "return", "$", "this", ";", "}" ]
Adds a recipient to the email. @param string $email @param string $name @return \Scara\Mail\Mailer
[ "Adds", "a", "recipient", "to", "the", "email", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L239-L248
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.attach
public function attach($file) { if (empty($file)) { throw new MailerException('a file is required to use attach!'); } elseif (!file_exists($file)) { throw new MailerException("$file does not exist!"); } $this->_mailer->addAttachment($file); return $this; }
php
public function attach($file) { if (empty($file)) { throw new MailerException('a file is required to use attach!'); } elseif (!file_exists($file)) { throw new MailerException("$file does not exist!"); } $this->_mailer->addAttachment($file); return $this; }
[ "public", "function", "attach", "(", "$", "file", ")", "{", "if", "(", "empty", "(", "$", "file", ")", ")", "{", "throw", "new", "MailerException", "(", "'a file is required to use attach!'", ")", ";", "}", "elseif", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "throw", "new", "MailerException", "(", "\"$file does not exist!\"", ")", ";", "}", "$", "this", "->", "_mailer", "->", "addAttachment", "(", "$", "file", ")", ";", "return", "$", "this", ";", "}" ]
Attaches a file to the email. @param string $file @return \Scara\Mail\Mailer
[ "Attaches", "a", "file", "to", "the", "email", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L257-L268
train
ScaraMVC/Framework
src/Scara/Mail/Mailer.php
Mailer.send
public function send() { $this->_mailer->addAddress($this->to[0], $this->to[1]); $this->_mailer->setFrom($this->from[0], $this->from[1]); $this->_mailer->isHtml($this->html); $this->_mailer->Subject = $this->subject; $this->_mailer->Body = $this->body; $this->_mailer->AltBody = strip_tags($this->body); return $this->_mailer->send(); }
php
public function send() { $this->_mailer->addAddress($this->to[0], $this->to[1]); $this->_mailer->setFrom($this->from[0], $this->from[1]); $this->_mailer->isHtml($this->html); $this->_mailer->Subject = $this->subject; $this->_mailer->Body = $this->body; $this->_mailer->AltBody = strip_tags($this->body); return $this->_mailer->send(); }
[ "public", "function", "send", "(", ")", "{", "$", "this", "->", "_mailer", "->", "addAddress", "(", "$", "this", "->", "to", "[", "0", "]", ",", "$", "this", "->", "to", "[", "1", "]", ")", ";", "$", "this", "->", "_mailer", "->", "setFrom", "(", "$", "this", "->", "from", "[", "0", "]", ",", "$", "this", "->", "from", "[", "1", "]", ")", ";", "$", "this", "->", "_mailer", "->", "isHtml", "(", "$", "this", "->", "html", ")", ";", "$", "this", "->", "_mailer", "->", "Subject", "=", "$", "this", "->", "subject", ";", "$", "this", "->", "_mailer", "->", "Body", "=", "$", "this", "->", "body", ";", "$", "this", "->", "_mailer", "->", "AltBody", "=", "strip_tags", "(", "$", "this", "->", "body", ")", ";", "return", "$", "this", "->", "_mailer", "->", "send", "(", ")", ";", "}" ]
Sends the constructed email. @return bool
[ "Sends", "the", "constructed", "email", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/Mailer.php#L311-L321
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.getCookieItem
public function getCookieItem($key) { return isset($this->cookie[$key]) ? $this->cookie[$key] : null; }
php
public function getCookieItem($key) { return isset($this->cookie[$key]) ? $this->cookie[$key] : null; }
[ "public", "function", "getCookieItem", "(", "$", "key", ")", "{", "return", "isset", "(", "$", "this", "->", "cookie", "[", "$", "key", "]", ")", "?", "$", "this", "->", "cookie", "[", "$", "key", "]", ":", "null", ";", "}" ]
Get a single cookie by index from the cookie array. @param mixed $key.
[ "Get", "a", "single", "cookie", "by", "index", "from", "the", "cookie", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L126-L129
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.removeCookieItem
public function removeCookieItem($key) { if (isset($this->cookie[$key])) { unset($this->cookie[$key]); return true; } else { return false; } }
php
public function removeCookieItem($key) { if (isset($this->cookie[$key])) { unset($this->cookie[$key]); return true; } else { return false; } }
[ "public", "function", "removeCookieItem", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "cookie", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "cookie", "[", "$", "key", "]", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Remove a single cookie by index from the cookie array. @param mixed $key. @return boolean $succes.
[ "Remove", "a", "single", "cookie", "by", "index", "from", "the", "cookie", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L163-L171
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.removeFile
public function removeFile($key) { if (isset($this->files[$key])) { unset($this->files[$key]); return true; } else { return false; } }
php
public function removeFile($key) { if (isset($this->files[$key])) { unset($this->files[$key]); return true; } else { return false; } }
[ "public", "function", "removeFile", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "files", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "files", "[", "$", "key", "]", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Remove a single file by index from the files array. @param mixed $key. @return boolean $succes.
[ "Remove", "a", "single", "file", "by", "index", "from", "the", "files", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L236-L244
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.getGetItem
public function getGetItem($key) { return isset($this->get[$key]) ? $this->get[$key] : null; }
php
public function getGetItem($key) { return isset($this->get[$key]) ? $this->get[$key] : null; }
[ "public", "function", "getGetItem", "(", "$", "key", ")", "{", "return", "isset", "(", "$", "this", "->", "get", "[", "$", "key", "]", ")", "?", "$", "this", "->", "get", "[", "$", "key", "]", ":", "null", ";", "}" ]
Get a single get by index from the get array. @param mixed $key.
[ "Get", "a", "single", "get", "by", "index", "from", "the", "get", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L268-L271
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.removeGetItem
public function removeGetItem($key) { if (isset($this->get[$key])) { unset($this->get[$key]); return true; } else { return false; } }
php
public function removeGetItem($key) { if (isset($this->get[$key])) { unset($this->get[$key]); return true; } else { return false; } }
[ "public", "function", "removeGetItem", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "get", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "get", "[", "$", "key", "]", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Remove a single get by index from the get array. @param mixed $key. @return boolean $succes.
[ "Remove", "a", "single", "get", "by", "index", "from", "the", "get", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L305-L313
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.removeParameter
public function removeParameter($key) { if (isset($this->parameters[$key])) { unset($this->parameters[$key]); return true; } else { return false; } }
php
public function removeParameter($key) { if (isset($this->parameters[$key])) { unset($this->parameters[$key]); return true; } else { return false; } }
[ "public", "function", "removeParameter", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "parameters", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "parameters", "[", "$", "key", "]", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Remove a single parameter by index from the parameters array. @param mixed $key. @return boolean $succes.
[ "Remove", "a", "single", "parameter", "by", "index", "from", "the", "parameters", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L387-L395
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.getPostItem
public function getPostItem($key) { return isset($this->post[$key]) ? $this->post[$key] : null; }
php
public function getPostItem($key) { return isset($this->post[$key]) ? $this->post[$key] : null; }
[ "public", "function", "getPostItem", "(", "$", "key", ")", "{", "return", "isset", "(", "$", "this", "->", "post", "[", "$", "key", "]", ")", "?", "$", "this", "->", "post", "[", "$", "key", "]", ":", "null", ";", "}" ]
Get a single post by index from the post array. @param mixed $key.
[ "Get", "a", "single", "post", "by", "index", "from", "the", "post", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L432-L435
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.getSessionItem
public function getSessionItem($key) { return isset($this->session[$key]) ? $this->session[$key] : null; }
php
public function getSessionItem($key) { return isset($this->session[$key]) ? $this->session[$key] : null; }
[ "public", "function", "getSessionItem", "(", "$", "key", ")", "{", "return", "isset", "(", "$", "this", "->", "session", "[", "$", "key", "]", ")", "?", "$", "this", "->", "session", "[", "$", "key", "]", ":", "null", ";", "}" ]
Get a single session by index from the session array. @param mixed $key.
[ "Get", "a", "single", "session", "by", "index", "from", "the", "session", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L500-L503
train
MarijnKoesen/php-code-generator
src/codegenerator/Request.php
Request.removeSessionItem
public function removeSessionItem($key) { if (isset($this->session[$key])) { unset($this->session[$key]); return true; } else { return false; } }
php
public function removeSessionItem($key) { if (isset($this->session[$key])) { unset($this->session[$key]); return true; } else { return false; } }
[ "public", "function", "removeSessionItem", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "session", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "session", "[", "$", "key", "]", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Remove a single session by index from the session array. @param mixed $key. @return boolean $succes.
[ "Remove", "a", "single", "session", "by", "index", "from", "the", "session", "array", "." ]
36e66505b8d5994d3ac159b776df5455ad01e1b1
https://github.com/MarijnKoesen/php-code-generator/blob/36e66505b8d5994d3ac159b776df5455ad01e1b1/src/codegenerator/Request.php#L537-L545
train
Fulfillment-dot-com/api-wrapper-php
src/Utilities/Helper.php
Helper.getStoragePath
public static function getStoragePath($path = '') { if (function_exists('storage_path')) { return storage_path($path); } else { return (__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '../storage') . ($path ? DIRECTORY_SEPARATOR . $path : $path); } }
php
public static function getStoragePath($path = '') { if (function_exists('storage_path')) { return storage_path($path); } else { return (__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '../storage') . ($path ? DIRECTORY_SEPARATOR . $path : $path); } }
[ "public", "static", "function", "getStoragePath", "(", "$", "path", "=", "''", ")", "{", "if", "(", "function_exists", "(", "'storage_path'", ")", ")", "{", "return", "storage_path", "(", "$", "path", ")", ";", "}", "else", "{", "return", "(", "__DIR__", ".", "DIRECTORY_SEPARATOR", ".", "'..'", ".", "DIRECTORY_SEPARATOR", ".", "'../storage'", ")", ".", "(", "$", "path", "?", "DIRECTORY_SEPARATOR", ".", "$", "path", ":", "$", "path", ")", ";", "}", "}" ]
Get the path to the storage folder. @param string $path @return string
[ "Get", "the", "path", "to", "the", "storage", "folder", "." ]
f4352843d060bc1b460c1283f25c210c9b94d324
https://github.com/Fulfillment-dot-com/api-wrapper-php/blob/f4352843d060bc1b460c1283f25c210c9b94d324/src/Utilities/Helper.php#L11-L21
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/JsonFilterer.php
JsonFilterer.encode
public function encode() { if (is_null($this->getParameter('value'))) return '""'; $value = $this->getParameter('value'); $index = $this->getParameter('index'); if($index != null && is_array($value)) return JSONUtils::encode($value[$index]); return JSONUtils::encode($value); }
php
public function encode() { if (is_null($this->getParameter('value'))) return '""'; $value = $this->getParameter('value'); $index = $this->getParameter('index'); if($index != null && is_array($value)) return JSONUtils::encode($value[$index]); return JSONUtils::encode($value); }
[ "public", "function", "encode", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", ")", ")", "return", "'\"\"'", ";", "$", "value", "=", "$", "this", "->", "getParameter", "(", "'value'", ")", ";", "$", "index", "=", "$", "this", "->", "getParameter", "(", "'index'", ")", ";", "if", "(", "$", "index", "!=", "null", "&&", "is_array", "(", "$", "value", ")", ")", "return", "JSONUtils", "::", "encode", "(", "$", "value", "[", "$", "index", "]", ")", ";", "return", "JSONUtils", "::", "encode", "(", "$", "value", ")", ";", "}" ]
Escapes the specified parameter in 'value' for use in json Expected Param: value mixed if is a string, this is what will be converted index string if specified and value is an array, then value[index] will be converted @return string
[ "Escapes", "the", "specified", "parameter", "in", "value", "for", "use", "in", "json" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/JsonFilterer.php#L39-L51
train
faizalpribadi/Cache
Driver/OpCache/Memcache.php
Memcache.set
public function set($id, $data, $lifeTime = 0) { if ($lifeTime > (int) 2592000) { $lifeTime = time() + $lifeTime; } return $this->memcache->add($id, $data, CacheFlags::CACHE_COMPRESSED, (int) $lifeTime); }
php
public function set($id, $data, $lifeTime = 0) { if ($lifeTime > (int) 2592000) { $lifeTime = time() + $lifeTime; } return $this->memcache->add($id, $data, CacheFlags::CACHE_COMPRESSED, (int) $lifeTime); }
[ "public", "function", "set", "(", "$", "id", ",", "$", "data", ",", "$", "lifeTime", "=", "0", ")", "{", "if", "(", "$", "lifeTime", ">", "(", "int", ")", "2592000", ")", "{", "$", "lifeTime", "=", "time", "(", ")", "+", "$", "lifeTime", ";", "}", "return", "$", "this", "->", "memcache", "->", "add", "(", "$", "id", ",", "$", "data", ",", "CacheFlags", "::", "CACHE_COMPRESSED", ",", "(", "int", ")", "$", "lifeTime", ")", ";", "}" ]
Set the data content for memcache cache provider @param string $id @param string $data @param int $lifeTime @return mixed
[ "Set", "the", "data", "content", "for", "memcache", "cache", "provider" ]
e62a4d71739e542ca6e7bac77f5cc522accef8cb
https://github.com/faizalpribadi/Cache/blob/e62a4d71739e542ca6e7bac77f5cc522accef8cb/Driver/OpCache/Memcache.php#L70-L77
train
faizalpribadi/Cache
Driver/OpCache/Memcache.php
Memcache.get
public function get($id) { if (function_exists('memcache_get')) { return $this->memcache->get($id); } throw new MemcacheException( sprintf('key id memcache "%s" not found, are you sure memcache_get function already loaded ?', $id) ); }
php
public function get($id) { if (function_exists('memcache_get')) { return $this->memcache->get($id); } throw new MemcacheException( sprintf('key id memcache "%s" not found, are you sure memcache_get function already loaded ?', $id) ); }
[ "public", "function", "get", "(", "$", "id", ")", "{", "if", "(", "function_exists", "(", "'memcache_get'", ")", ")", "{", "return", "$", "this", "->", "memcache", "->", "get", "(", "$", "id", ")", ";", "}", "throw", "new", "MemcacheException", "(", "sprintf", "(", "'key id memcache \"%s\" not found, are you sure memcache_get function already loaded ?'", ",", "$", "id", ")", ")", ";", "}" ]
Get data content from cache key memcache @param string $id @return string @throws \Mozart\Library\Cache\Exception\MemcacheException
[ "Get", "data", "content", "from", "cache", "key", "memcache" ]
e62a4d71739e542ca6e7bac77f5cc522accef8cb
https://github.com/faizalpribadi/Cache/blob/e62a4d71739e542ca6e7bac77f5cc522accef8cb/Driver/OpCache/Memcache.php#L87-L96
train
modusphp/framework
src/Response/ResponseManager.php
ResponseManager.process
public function process(PayloadInterface $payload, ResponseGenerator $generator) { $typeMap = $generator->checkContentResponseType(); $availableTypes = array_keys($typeMap); $type = $this->determineResponseType($availableTypes); // If we don't get a valid type back, let's force one, per the HTTP 1.1 spec. if (!$type) { $type = array_shift($availableTypes); } $methodToCall = $typeMap[$type]; $response = $generator->$methodToCall($payload); $this->sendResponse($response); }
php
public function process(PayloadInterface $payload, ResponseGenerator $generator) { $typeMap = $generator->checkContentResponseType(); $availableTypes = array_keys($typeMap); $type = $this->determineResponseType($availableTypes); // If we don't get a valid type back, let's force one, per the HTTP 1.1 spec. if (!$type) { $type = array_shift($availableTypes); } $methodToCall = $typeMap[$type]; $response = $generator->$methodToCall($payload); $this->sendResponse($response); }
[ "public", "function", "process", "(", "PayloadInterface", "$", "payload", ",", "ResponseGenerator", "$", "generator", ")", "{", "$", "typeMap", "=", "$", "generator", "->", "checkContentResponseType", "(", ")", ";", "$", "availableTypes", "=", "array_keys", "(", "$", "typeMap", ")", ";", "$", "type", "=", "$", "this", "->", "determineResponseType", "(", "$", "availableTypes", ")", ";", "// If we don't get a valid type back, let's force one, per the HTTP 1.1 spec.", "if", "(", "!", "$", "type", ")", "{", "$", "type", "=", "array_shift", "(", "$", "availableTypes", ")", ";", "}", "$", "methodToCall", "=", "$", "typeMap", "[", "$", "type", "]", ";", "$", "response", "=", "$", "generator", "->", "$", "methodToCall", "(", "$", "payload", ")", ";", "$", "this", "->", "sendResponse", "(", "$", "response", ")", ";", "}" ]
Processes the results of the Action. @var $payload PayloadInterface @var $generator ResponseGenerator @throws Exception\ContentTypeNotValidException
[ "Processes", "the", "results", "of", "the", "Action", "." ]
9d041a2de97b1736702bf75c0f5e9d1c69366746
https://github.com/modusphp/framework/blob/9d041a2de97b1736702bf75c0f5e9d1c69366746/src/Response/ResponseManager.php#L45-L61
train
modusphp/framework
src/Response/ResponseManager.php
ResponseManager.determineResponseType
protected function determineResponseType($availableTypes) { $bestType = $this->contentNegotiation->negotiateMedia($availableTypes); if ($bestType instanceof Accept\Media\MediaValue) { $contentType = $bestType->getValue(); $subType = $bestType->getSubtype(); $this->contentType = $contentType; return $contentType; } }
php
protected function determineResponseType($availableTypes) { $bestType = $this->contentNegotiation->negotiateMedia($availableTypes); if ($bestType instanceof Accept\Media\MediaValue) { $contentType = $bestType->getValue(); $subType = $bestType->getSubtype(); $this->contentType = $contentType; return $contentType; } }
[ "protected", "function", "determineResponseType", "(", "$", "availableTypes", ")", "{", "$", "bestType", "=", "$", "this", "->", "contentNegotiation", "->", "negotiateMedia", "(", "$", "availableTypes", ")", ";", "if", "(", "$", "bestType", "instanceof", "Accept", "\\", "Media", "\\", "MediaValue", ")", "{", "$", "contentType", "=", "$", "bestType", "->", "getValue", "(", ")", ";", "$", "subType", "=", "$", "bestType", "->", "getSubtype", "(", ")", ";", "$", "this", "->", "contentType", "=", "$", "contentType", ";", "return", "$", "contentType", ";", "}", "}" ]
Determines if the Accepts header types match what this responder is configured to return. If not, we throw an exception. @throws Exception\ContentTypeNotValidException
[ "Determines", "if", "the", "Accepts", "header", "types", "match", "what", "this", "responder", "is", "configured", "to", "return", ".", "If", "not", "we", "throw", "an", "exception", "." ]
9d041a2de97b1736702bf75c0f5e9d1c69366746
https://github.com/modusphp/framework/blob/9d041a2de97b1736702bf75c0f5e9d1c69366746/src/Response/ResponseManager.php#L79-L88
train
tjwlucas/phpjstore
src/jstoreObject.php
jstoreObject.toJSON
public function toJSON() { $allvals = Array(); $reflection = new \ReflectionObject($this); $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); foreach($properties as $prop){ $propkey = $prop->getName(); $allvals[$propkey] = $this->$propkey; } $json = json_encode($allvals, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); return $json; }
php
public function toJSON() { $allvals = Array(); $reflection = new \ReflectionObject($this); $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); foreach($properties as $prop){ $propkey = $prop->getName(); $allvals[$propkey] = $this->$propkey; } $json = json_encode($allvals, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); return $json; }
[ "public", "function", "toJSON", "(", ")", "{", "$", "allvals", "=", "Array", "(", ")", ";", "$", "reflection", "=", "new", "\\", "ReflectionObject", "(", "$", "this", ")", ";", "$", "properties", "=", "$", "reflection", "->", "getProperties", "(", "\\", "ReflectionProperty", "::", "IS_PUBLIC", ")", ";", "foreach", "(", "$", "properties", "as", "$", "prop", ")", "{", "$", "propkey", "=", "$", "prop", "->", "getName", "(", ")", ";", "$", "allvals", "[", "$", "propkey", "]", "=", "$", "this", "->", "$", "propkey", ";", "}", "$", "json", "=", "json_encode", "(", "$", "allvals", ",", "JSON_PRETTY_PRINT", "|", "JSON_UNESCAPED_SLASHES", ")", ";", "return", "$", "json", ";", "}" ]
Outputs the object as a JSON
[ "Outputs", "the", "object", "as", "a", "JSON" ]
ebc8f821de38757724efb89992a9d3aa9f9834d2
https://github.com/tjwlucas/phpjstore/blob/ebc8f821de38757724efb89992a9d3aa9f9834d2/src/jstoreObject.php#L18-L29
train
koolkode/view-express
src/ExpressCompiler.php
ExpressCompiler.write
public function write($contents) { if($this->output != '') { $this->buffer .= "\t\t\$out->write(" . var_export($this->output, true) . ");\n"; $this->output = ''; } $this->buffer .= $contents; }
php
public function write($contents) { if($this->output != '') { $this->buffer .= "\t\t\$out->write(" . var_export($this->output, true) . ");\n"; $this->output = ''; } $this->buffer .= $contents; }
[ "public", "function", "write", "(", "$", "contents", ")", "{", "if", "(", "$", "this", "->", "output", "!=", "''", ")", "{", "$", "this", "->", "buffer", ".=", "\"\\t\\t\\$out->write(\"", ".", "var_export", "(", "$", "this", "->", "output", ",", "true", ")", ".", "\");\\n\"", ";", "$", "this", "->", "output", "=", "''", ";", "}", "$", "this", "->", "buffer", ".=", "$", "contents", ";", "}" ]
Write instructions into the generated code. @param string $contents
[ "Write", "instructions", "into", "the", "generated", "code", "." ]
a8ebe6f373b6bfe8b8818d6264535e8fe063a596
https://github.com/koolkode/view-express/blob/a8ebe6f373b6bfe8b8818d6264535e8fe063a596/src/ExpressCompiler.php#L168-L177
train
koolkode/view-express
src/ExpressCompiler.php
ExpressCompiler.generateCode
public function generateCode($key) { if($this->extends === NULL && $this->output != '') { $this->buffer .= "\t\t\$out->write(" . var_export($this->output, true) . ");\n"; $this->output = ''; } $buffer = sprintf("<?php\n\nnamespace %s {\n\n", __NAMESPACE__); $buffer .= 'use KoolKode\View\TagBuilder;' . "\n"; $buffer .= "\n"; $buffer .= sprintf('final class CompiledTemplate_%s extends CompiledTemplate {' . "\n\n", $key); for($count = count($this->fields), $step = 8, $i = 0; $i < $count; $i += $step) { $buffer .= "\tprivate \$" . $this->fields[$i]; for($max = min($count, $i + $step), $j = $i + 1; $j < $max; $j++) { $buffer .= ', $' . $this->fields[$j]; } $buffer .= ";\n"; } $buffer .= "\n\tpublic function getResource() {\n"; $buffer .= "\t\treturn " . var_export($this->resource, true) . ";\n"; $buffer .= "\t}\n"; if($this->extends === NULL) { $buffer .= "\n\tprotected function renderMain(OutputBuffer \$out) {\n\n"; $buffer .= "\t\t\$pout = \$this->context->set('@out', \$out);\n"; $buffer .= "\t\t\$pthis = \$this->context->set('@this', \$this);\n"; $buffer .= "\t\ttry {\n"; $buffer .= "\n" . $this->buffer . "\n"; $buffer .= "\t\t} finally {\n"; $buffer .= "\t\t\t\$this->context->set('@out', \$pout);\n"; $buffer .= "\t\t\t\$this->context->set('@this', \$pthis);\n"; $buffer .= "\t\t}\n"; $buffer .= "\t}\n"; } else { $compiler = new self($this->renderer); foreach($this->extends as $i => $node) { if($i != 0) { $compiler->write(' . '); } $node->compile($compiler, NodeInterface::FLAG_RAW); } $buffer .= "\n\tprotected function getExtended() {\n"; $buffer .= "\t\treturn " . $compiler->getBuffer() . ";\n"; $buffer .= "\t}\n"; } foreach($this->blocks as $block) { $buffer .= "\n" . $block; } $buffer .= "}}\n ?>"; return $buffer; }
php
public function generateCode($key) { if($this->extends === NULL && $this->output != '') { $this->buffer .= "\t\t\$out->write(" . var_export($this->output, true) . ");\n"; $this->output = ''; } $buffer = sprintf("<?php\n\nnamespace %s {\n\n", __NAMESPACE__); $buffer .= 'use KoolKode\View\TagBuilder;' . "\n"; $buffer .= "\n"; $buffer .= sprintf('final class CompiledTemplate_%s extends CompiledTemplate {' . "\n\n", $key); for($count = count($this->fields), $step = 8, $i = 0; $i < $count; $i += $step) { $buffer .= "\tprivate \$" . $this->fields[$i]; for($max = min($count, $i + $step), $j = $i + 1; $j < $max; $j++) { $buffer .= ', $' . $this->fields[$j]; } $buffer .= ";\n"; } $buffer .= "\n\tpublic function getResource() {\n"; $buffer .= "\t\treturn " . var_export($this->resource, true) . ";\n"; $buffer .= "\t}\n"; if($this->extends === NULL) { $buffer .= "\n\tprotected function renderMain(OutputBuffer \$out) {\n\n"; $buffer .= "\t\t\$pout = \$this->context->set('@out', \$out);\n"; $buffer .= "\t\t\$pthis = \$this->context->set('@this', \$this);\n"; $buffer .= "\t\ttry {\n"; $buffer .= "\n" . $this->buffer . "\n"; $buffer .= "\t\t} finally {\n"; $buffer .= "\t\t\t\$this->context->set('@out', \$pout);\n"; $buffer .= "\t\t\t\$this->context->set('@this', \$pthis);\n"; $buffer .= "\t\t}\n"; $buffer .= "\t}\n"; } else { $compiler = new self($this->renderer); foreach($this->extends as $i => $node) { if($i != 0) { $compiler->write(' . '); } $node->compile($compiler, NodeInterface::FLAG_RAW); } $buffer .= "\n\tprotected function getExtended() {\n"; $buffer .= "\t\treturn " . $compiler->getBuffer() . ";\n"; $buffer .= "\t}\n"; } foreach($this->blocks as $block) { $buffer .= "\n" . $block; } $buffer .= "}}\n ?>"; return $buffer; }
[ "public", "function", "generateCode", "(", "$", "key", ")", "{", "if", "(", "$", "this", "->", "extends", "===", "NULL", "&&", "$", "this", "->", "output", "!=", "''", ")", "{", "$", "this", "->", "buffer", ".=", "\"\\t\\t\\$out->write(\"", ".", "var_export", "(", "$", "this", "->", "output", ",", "true", ")", ".", "\");\\n\"", ";", "$", "this", "->", "output", "=", "''", ";", "}", "$", "buffer", "=", "sprintf", "(", "\"<?php\\n\\nnamespace %s {\\n\\n\"", ",", "__NAMESPACE__", ")", ";", "$", "buffer", ".=", "'use KoolKode\\View\\TagBuilder;'", ".", "\"\\n\"", ";", "$", "buffer", ".=", "\"\\n\"", ";", "$", "buffer", ".=", "sprintf", "(", "'final class CompiledTemplate_%s extends CompiledTemplate {'", ".", "\"\\n\\n\"", ",", "$", "key", ")", ";", "for", "(", "$", "count", "=", "count", "(", "$", "this", "->", "fields", ")", ",", "$", "step", "=", "8", ",", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "+=", "$", "step", ")", "{", "$", "buffer", ".=", "\"\\tprivate \\$\"", ".", "$", "this", "->", "fields", "[", "$", "i", "]", ";", "for", "(", "$", "max", "=", "min", "(", "$", "count", ",", "$", "i", "+", "$", "step", ")", ",", "$", "j", "=", "$", "i", "+", "1", ";", "$", "j", "<", "$", "max", ";", "$", "j", "++", ")", "{", "$", "buffer", ".=", "', $'", ".", "$", "this", "->", "fields", "[", "$", "j", "]", ";", "}", "$", "buffer", ".=", "\";\\n\"", ";", "}", "$", "buffer", ".=", "\"\\n\\tpublic function getResource() {\\n\"", ";", "$", "buffer", ".=", "\"\\t\\treturn \"", ".", "var_export", "(", "$", "this", "->", "resource", ",", "true", ")", ".", "\";\\n\"", ";", "$", "buffer", ".=", "\"\\t}\\n\"", ";", "if", "(", "$", "this", "->", "extends", "===", "NULL", ")", "{", "$", "buffer", ".=", "\"\\n\\tprotected function renderMain(OutputBuffer \\$out) {\\n\\n\"", ";", "$", "buffer", ".=", "\"\\t\\t\\$pout = \\$this->context->set('@out', \\$out);\\n\"", ";", "$", "buffer", ".=", "\"\\t\\t\\$pthis = \\$this->context->set('@this', \\$this);\\n\"", ";", "$", "buffer", ".=", "\"\\t\\ttry {\\n\"", ";", "$", "buffer", ".=", "\"\\n\"", ".", "$", "this", "->", "buffer", ".", "\"\\n\"", ";", "$", "buffer", ".=", "\"\\t\\t} finally {\\n\"", ";", "$", "buffer", ".=", "\"\\t\\t\\t\\$this->context->set('@out', \\$pout);\\n\"", ";", "$", "buffer", ".=", "\"\\t\\t\\t\\$this->context->set('@this', \\$pthis);\\n\"", ";", "$", "buffer", ".=", "\"\\t\\t}\\n\"", ";", "$", "buffer", ".=", "\"\\t}\\n\"", ";", "}", "else", "{", "$", "compiler", "=", "new", "self", "(", "$", "this", "->", "renderer", ")", ";", "foreach", "(", "$", "this", "->", "extends", "as", "$", "i", "=>", "$", "node", ")", "{", "if", "(", "$", "i", "!=", "0", ")", "{", "$", "compiler", "->", "write", "(", "' . '", ")", ";", "}", "$", "node", "->", "compile", "(", "$", "compiler", ",", "NodeInterface", "::", "FLAG_RAW", ")", ";", "}", "$", "buffer", ".=", "\"\\n\\tprotected function getExtended() {\\n\"", ";", "$", "buffer", ".=", "\"\\t\\treturn \"", ".", "$", "compiler", "->", "getBuffer", "(", ")", ".", "\";\\n\"", ";", "$", "buffer", ".=", "\"\\t}\\n\"", ";", "}", "foreach", "(", "$", "this", "->", "blocks", "as", "$", "block", ")", "{", "$", "buffer", ".=", "\"\\n\"", ".", "$", "block", ";", "}", "$", "buffer", ".=", "\"}}\\n ?>\"", ";", "return", "$", "buffer", ";", "}" ]
Generate code within a class and return it. @param string $key Will be prepended to the class name to make it unique. @return string
[ "Generate", "code", "within", "a", "class", "and", "return", "it", "." ]
a8ebe6f373b6bfe8b8818d6264535e8fe063a596
https://github.com/koolkode/view-express/blob/a8ebe6f373b6bfe8b8818d6264535e8fe063a596/src/ExpressCompiler.php#L232-L302
train
metaclassing/PHP-Curler
src/Certbot.php
Certbot.findCertificate
public function findCertificate($name) { foreach ($this->accounttypes as $type) { foreach ($this->accounts[$type] as $account) { // Skip empty accounts with no visible certificates if (!isset($account['certificates'])) { continue; } foreach ($account['certificates'] as $certificate) { if ($certificate['name'] == $name) { $certificate['accounttype'] = $type; $certificate['pemurl'] = $this->baseurl.'/'.$type.'/accounts/'.$certificate['account_id'].'/certificates/'.$certificate['id'].'/pem'; return $certificate; } } } } }
php
public function findCertificate($name) { foreach ($this->accounttypes as $type) { foreach ($this->accounts[$type] as $account) { // Skip empty accounts with no visible certificates if (!isset($account['certificates'])) { continue; } foreach ($account['certificates'] as $certificate) { if ($certificate['name'] == $name) { $certificate['accounttype'] = $type; $certificate['pemurl'] = $this->baseurl.'/'.$type.'/accounts/'.$certificate['account_id'].'/certificates/'.$certificate['id'].'/pem'; return $certificate; } } } } }
[ "public", "function", "findCertificate", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "accounttypes", "as", "$", "type", ")", "{", "foreach", "(", "$", "this", "->", "accounts", "[", "$", "type", "]", "as", "$", "account", ")", "{", "// Skip empty accounts with no visible certificates", "if", "(", "!", "isset", "(", "$", "account", "[", "'certificates'", "]", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "account", "[", "'certificates'", "]", "as", "$", "certificate", ")", "{", "if", "(", "$", "certificate", "[", "'name'", "]", "==", "$", "name", ")", "{", "$", "certificate", "[", "'accounttype'", "]", "=", "$", "type", ";", "$", "certificate", "[", "'pemurl'", "]", "=", "$", "this", "->", "baseurl", ".", "'/'", ".", "$", "type", ".", "'/accounts/'", ".", "$", "certificate", "[", "'account_id'", "]", ".", "'/certificates/'", ".", "$", "certificate", "[", "'id'", "]", ".", "'/pem'", ";", "return", "$", "certificate", ";", "}", "}", "}", "}", "}" ]
Really only necessary until I implement a direct API route to search for certificates...
[ "Really", "only", "necessary", "until", "I", "implement", "a", "direct", "API", "route", "to", "search", "for", "certificates", "..." ]
6e658c141171d852c68754d452dbfb97b24638cc
https://github.com/metaclassing/PHP-Curler/blob/6e658c141171d852c68754d452dbfb97b24638cc/src/Certbot.php#L92-L110
train
juliangut/mapping
src/Driver/AbstractMappingDriver.php
AbstractMappingDriver.getMappingData
protected function getMappingData(): array { $mappings = []; foreach ($this->locator->getMappingFiles() as $mappingFile) { $mappings[] = $this->loadMappingFile($mappingFile); } $mappingData = []; foreach ($mappings as $mapping) { $mappingData = $this->mergeMappings($mappingData, $mapping); } return $mappingData; }
php
protected function getMappingData(): array { $mappings = []; foreach ($this->locator->getMappingFiles() as $mappingFile) { $mappings[] = $this->loadMappingFile($mappingFile); } $mappingData = []; foreach ($mappings as $mapping) { $mappingData = $this->mergeMappings($mappingData, $mapping); } return $mappingData; }
[ "protected", "function", "getMappingData", "(", ")", ":", "array", "{", "$", "mappings", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "locator", "->", "getMappingFiles", "(", ")", "as", "$", "mappingFile", ")", "{", "$", "mappings", "[", "]", "=", "$", "this", "->", "loadMappingFile", "(", "$", "mappingFile", ")", ";", "}", "$", "mappingData", "=", "[", "]", ";", "foreach", "(", "$", "mappings", "as", "$", "mapping", ")", "{", "$", "mappingData", "=", "$", "this", "->", "mergeMappings", "(", "$", "mappingData", ",", "$", "mapping", ")", ";", "}", "return", "$", "mappingData", ";", "}" ]
Get mapping data. @throws \Jgut\Mapping\Exception\DriverException @return mixed[]
[ "Get", "mapping", "data", "." ]
1830ff84c054d8e3759df170a5664a97f7070be9
https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/AbstractMappingDriver.php#L28-L42
train
juliangut/mapping
src/Driver/AbstractMappingDriver.php
AbstractMappingDriver.mergeMappings
final protected function mergeMappings(array $mappingsA, array $mappingsB): array { foreach ($mappingsB as $key => $value) { if (isset($mappingsA[$key]) || \array_key_exists($key, $mappingsA)) { if (\is_int($key)) { $mappingsA[] = $value; } elseif (\is_array($value) && \is_array($mappingsA[$key])) { $mappingsA[$key] = $this->mergeMappings($mappingsA[$key], $value); } else { $mappingsA[$key] = $value; } } else { $mappingsA[$key] = $value; } } return $mappingsA; }
php
final protected function mergeMappings(array $mappingsA, array $mappingsB): array { foreach ($mappingsB as $key => $value) { if (isset($mappingsA[$key]) || \array_key_exists($key, $mappingsA)) { if (\is_int($key)) { $mappingsA[] = $value; } elseif (\is_array($value) && \is_array($mappingsA[$key])) { $mappingsA[$key] = $this->mergeMappings($mappingsA[$key], $value); } else { $mappingsA[$key] = $value; } } else { $mappingsA[$key] = $value; } } return $mappingsA; }
[ "final", "protected", "function", "mergeMappings", "(", "array", "$", "mappingsA", ",", "array", "$", "mappingsB", ")", ":", "array", "{", "foreach", "(", "$", "mappingsB", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "mappingsA", "[", "$", "key", "]", ")", "||", "\\", "array_key_exists", "(", "$", "key", ",", "$", "mappingsA", ")", ")", "{", "if", "(", "\\", "is_int", "(", "$", "key", ")", ")", "{", "$", "mappingsA", "[", "]", "=", "$", "value", ";", "}", "elseif", "(", "\\", "is_array", "(", "$", "value", ")", "&&", "\\", "is_array", "(", "$", "mappingsA", "[", "$", "key", "]", ")", ")", "{", "$", "mappingsA", "[", "$", "key", "]", "=", "$", "this", "->", "mergeMappings", "(", "$", "mappingsA", "[", "$", "key", "]", ",", "$", "value", ")", ";", "}", "else", "{", "$", "mappingsA", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "else", "{", "$", "mappingsA", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "mappingsA", ";", "}" ]
Merge mapping data. @param array $mappingsA @param array $mappingsB @return array
[ "Merge", "mapping", "data", "." ]
1830ff84c054d8e3759df170a5664a97f7070be9
https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/AbstractMappingDriver.php#L61-L78
train
ezra-obiwale/dSCore
src/Core/Authenticate.php
Authenticate.checkPermission
private function checkPermission(array $properties) { if (empty($properties)) return true; if (isset($properties['actions']) && !is_array($properties['actions'])) $properties['actions'] = array($properties['actions']); if (isset($properties['actions']) && !empty($properties['actions']) && !in_array($this->action, $properties['actions']) && !in_array(\Util::camelToHyphen($this->action), $properties['actions'])) return null; foreach ($properties as $ppt => $values) { if (!is_array($values)) $values = array($values); if (strtolower($ppt) === 'role' && in_array('@', $values) && !$this->userId->isGuest()) { return true; } if (strtolower($ppt) !== 'actions') { if ($this->userId->getUser()->$ppt === null) return false; if (empty($values)) return true; if (!in_array($this->userId->getUser()->$ppt, $values)) return false; } } return true; }
php
private function checkPermission(array $properties) { if (empty($properties)) return true; if (isset($properties['actions']) && !is_array($properties['actions'])) $properties['actions'] = array($properties['actions']); if (isset($properties['actions']) && !empty($properties['actions']) && !in_array($this->action, $properties['actions']) && !in_array(\Util::camelToHyphen($this->action), $properties['actions'])) return null; foreach ($properties as $ppt => $values) { if (!is_array($values)) $values = array($values); if (strtolower($ppt) === 'role' && in_array('@', $values) && !$this->userId->isGuest()) { return true; } if (strtolower($ppt) !== 'actions') { if ($this->userId->getUser()->$ppt === null) return false; if (empty($values)) return true; if (!in_array($this->userId->getUser()->$ppt, $values)) return false; } } return true; }
[ "private", "function", "checkPermission", "(", "array", "$", "properties", ")", "{", "if", "(", "empty", "(", "$", "properties", ")", ")", "return", "true", ";", "if", "(", "isset", "(", "$", "properties", "[", "'actions'", "]", ")", "&&", "!", "is_array", "(", "$", "properties", "[", "'actions'", "]", ")", ")", "$", "properties", "[", "'actions'", "]", "=", "array", "(", "$", "properties", "[", "'actions'", "]", ")", ";", "if", "(", "isset", "(", "$", "properties", "[", "'actions'", "]", ")", "&&", "!", "empty", "(", "$", "properties", "[", "'actions'", "]", ")", "&&", "!", "in_array", "(", "$", "this", "->", "action", ",", "$", "properties", "[", "'actions'", "]", ")", "&&", "!", "in_array", "(", "\\", "Util", "::", "camelToHyphen", "(", "$", "this", "->", "action", ")", ",", "$", "properties", "[", "'actions'", "]", ")", ")", "return", "null", ";", "foreach", "(", "$", "properties", "as", "$", "ppt", "=>", "$", "values", ")", "{", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "$", "values", "=", "array", "(", "$", "values", ")", ";", "if", "(", "strtolower", "(", "$", "ppt", ")", "===", "'role'", "&&", "in_array", "(", "'@'", ",", "$", "values", ")", "&&", "!", "$", "this", "->", "userId", "->", "isGuest", "(", ")", ")", "{", "return", "true", ";", "}", "if", "(", "strtolower", "(", "$", "ppt", ")", "!==", "'actions'", ")", "{", "if", "(", "$", "this", "->", "userId", "->", "getUser", "(", ")", "->", "$", "ppt", "===", "null", ")", "return", "false", ";", "if", "(", "empty", "(", "$", "values", ")", ")", "return", "true", ";", "if", "(", "!", "in_array", "(", "$", "this", "->", "userId", "->", "getUser", "(", ")", "->", "$", "ppt", ",", "$", "values", ")", ")", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks each permission @param array $properties @return null|boolean @throws \Exception
[ "Checks", "each", "permission" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Authenticate.php#L43-L76
train
ezra-obiwale/dSCore
src/Core/Authenticate.php
Authenticate.execute
final public function execute() { if (!is_array($this->controller->accessRules())) throw new \Exception('Authentication failed: Method "accessRules" in "' . $this->controller->getClass() . '" must return an array'); foreach ($this->controller->accessRules() as $rule) { if (!is_array($rule)) throw new \Exception('Authentication error: Each element of the array returned by accessRules() must be an array'); if (!isset($rule[0])) throw new \Exception('Authentication error: Each element of the array returned by accessRules() must indicate permission as its first element'); $permission = $rule[0]; $rules = (isset($rule[1])) ? $rule[1] : array(); if (!is_string($permission) || (is_string($permission) && !in_array($permission, array('allow', 'deny')))) throw new \Exception('Authentication error: First element of each rules array can only be either "allow" or "deny"'); if (isset($rules) && !is_array($rules)) throw new \Exception('Authentication error: The second element of each rules array must return an array'); if (strtolower($permission) === 'allow') { if ($this->checkPermission($rules) === TRUE) return true; } elseif (strtolower($permission) === 'deny') { if ($this->checkPermission($rules) === TRUE) return false; } } return true; }
php
final public function execute() { if (!is_array($this->controller->accessRules())) throw new \Exception('Authentication failed: Method "accessRules" in "' . $this->controller->getClass() . '" must return an array'); foreach ($this->controller->accessRules() as $rule) { if (!is_array($rule)) throw new \Exception('Authentication error: Each element of the array returned by accessRules() must be an array'); if (!isset($rule[0])) throw new \Exception('Authentication error: Each element of the array returned by accessRules() must indicate permission as its first element'); $permission = $rule[0]; $rules = (isset($rule[1])) ? $rule[1] : array(); if (!is_string($permission) || (is_string($permission) && !in_array($permission, array('allow', 'deny')))) throw new \Exception('Authentication error: First element of each rules array can only be either "allow" or "deny"'); if (isset($rules) && !is_array($rules)) throw new \Exception('Authentication error: The second element of each rules array must return an array'); if (strtolower($permission) === 'allow') { if ($this->checkPermission($rules) === TRUE) return true; } elseif (strtolower($permission) === 'deny') { if ($this->checkPermission($rules) === TRUE) return false; } } return true; }
[ "final", "public", "function", "execute", "(", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "controller", "->", "accessRules", "(", ")", ")", ")", "throw", "new", "\\", "Exception", "(", "'Authentication failed: Method \"accessRules\" in \"'", ".", "$", "this", "->", "controller", "->", "getClass", "(", ")", ".", "'\" must return an array'", ")", ";", "foreach", "(", "$", "this", "->", "controller", "->", "accessRules", "(", ")", "as", "$", "rule", ")", "{", "if", "(", "!", "is_array", "(", "$", "rule", ")", ")", "throw", "new", "\\", "Exception", "(", "'Authentication error: Each element of the array returned by accessRules() must be an array'", ")", ";", "if", "(", "!", "isset", "(", "$", "rule", "[", "0", "]", ")", ")", "throw", "new", "\\", "Exception", "(", "'Authentication error: Each element of the array returned by accessRules() must indicate permission as its first element'", ")", ";", "$", "permission", "=", "$", "rule", "[", "0", "]", ";", "$", "rules", "=", "(", "isset", "(", "$", "rule", "[", "1", "]", ")", ")", "?", "$", "rule", "[", "1", "]", ":", "array", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "permission", ")", "||", "(", "is_string", "(", "$", "permission", ")", "&&", "!", "in_array", "(", "$", "permission", ",", "array", "(", "'allow'", ",", "'deny'", ")", ")", ")", ")", "throw", "new", "\\", "Exception", "(", "'Authentication error: First element of each rules array can only be either \"allow\" or \"deny\"'", ")", ";", "if", "(", "isset", "(", "$", "rules", ")", "&&", "!", "is_array", "(", "$", "rules", ")", ")", "throw", "new", "\\", "Exception", "(", "'Authentication error: The second element of each rules array must return an array'", ")", ";", "if", "(", "strtolower", "(", "$", "permission", ")", "===", "'allow'", ")", "{", "if", "(", "$", "this", "->", "checkPermission", "(", "$", "rules", ")", "===", "TRUE", ")", "return", "true", ";", "}", "elseif", "(", "strtolower", "(", "$", "permission", ")", "===", "'deny'", ")", "{", "if", "(", "$", "this", "->", "checkPermission", "(", "$", "rules", ")", "===", "TRUE", ")", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Executes the authentication @return boolean @throws \Exception
[ "Executes", "the", "authentication" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Authenticate.php#L83-L113
train