id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
33,800
rhoone/yii2-rhoone
controllers/ExtensionController.php
ExtensionController.actionRemove
public function actionRemove($class, $force = false) { try { Yii::$app->rhoone->ext->deregister($class, $force); } catch (\Exception $ex) { throw new Exception($ex->getMessage()); } echo "The extension `" . $class . "` is removed.\n"; return 0; }
php
public function actionRemove($class, $force = false) { try { Yii::$app->rhoone->ext->deregister($class, $force); } catch (\Exception $ex) { throw new Exception($ex->getMessage()); } echo "The extension `" . $class . "` is removed.\n"; return 0; }
[ "public", "function", "actionRemove", "(", "$", "class", ",", "$", "force", "=", "false", ")", "{", "try", "{", "Yii", "::", "$", "app", "->", "rhoone", "->", "ext", "->", "deregister", "(", "$", "class", ",", "$", "force", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "throw", "new", "Exception", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "echo", "\"The extension `\"", ".", "$", "class", ".", "\"` is removed.\\n\"", ";", "return", "0", ";", "}" ]
Remove an extension @param string $class @param boolean $force @return int @throws Exception
[ "Remove", "an", "extension" ]
f6ae90d466ea6f34bba404be0aba03e37ef369ad
https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/controllers/ExtensionController.php#L153-L162
33,801
brainworxx/kreXX
src/Analyse/Comment/Functions.php
Functions.getComment
public function getComment(\Reflector $reflectionFunction, \ReflectionClass $reflectionClass = null) { // Do some static caching. The comment will not change during a run. static $cache = array(); /** @var \ReflectionFunction $reflectionFunction */ $cachingKey = $reflectionFunction->getName(); if (isset($cache[$cachingKey]) === true) { return $cache[$cachingKey]; } // Cache not found. We need to generate this one. $cache[$cachingKey] = $this->pool->encodingService->encodeString( $this->prettifyComment($reflectionFunction->getDocComment()) ); return $cache[$cachingKey]; }
php
public function getComment(\Reflector $reflectionFunction, \ReflectionClass $reflectionClass = null) { // Do some static caching. The comment will not change during a run. static $cache = array(); /** @var \ReflectionFunction $reflectionFunction */ $cachingKey = $reflectionFunction->getName(); if (isset($cache[$cachingKey]) === true) { return $cache[$cachingKey]; } // Cache not found. We need to generate this one. $cache[$cachingKey] = $this->pool->encodingService->encodeString( $this->prettifyComment($reflectionFunction->getDocComment()) ); return $cache[$cachingKey]; }
[ "public", "function", "getComment", "(", "\\", "Reflector", "$", "reflectionFunction", ",", "\\", "ReflectionClass", "$", "reflectionClass", "=", "null", ")", "{", "// Do some static caching. The comment will not change during a run.", "static", "$", "cache", "=", "array", "(", ")", ";", "/** @var \\ReflectionFunction $reflectionFunction */", "$", "cachingKey", "=", "$", "reflectionFunction", "->", "getName", "(", ")", ";", "if", "(", "isset", "(", "$", "cache", "[", "$", "cachingKey", "]", ")", "===", "true", ")", "{", "return", "$", "cache", "[", "$", "cachingKey", "]", ";", "}", "// Cache not found. We need to generate this one.", "$", "cache", "[", "$", "cachingKey", "]", "=", "$", "this", "->", "pool", "->", "encodingService", "->", "encodeString", "(", "$", "this", "->", "prettifyComment", "(", "$", "reflectionFunction", "->", "getDocComment", "(", ")", ")", ")", ";", "return", "$", "cache", "[", "$", "cachingKey", "]", ";", "}" ]
Get the prettified comment from a function. @param \Reflector $reflectionFunction The reflection of the function with the comment. @param \ReflectionClass|null $reflectionClass Nothing, null. We do not have a hosting class. @return string The prettified comment.
[ "Get", "the", "prettified", "comment", "from", "a", "function", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Comment/Functions.php#L55-L71
33,802
honey-comb/core
src/Http/Controllers/HCLanguageController.php
HCLanguageController.index
public function index(): JsonResponse { $config = $this->makeView('language-view', trans('HCCore::languages.title.list')) ->addFormSource('add-new', 'language') ->addDataTable($this->getDataTable()) ->setPermissions(['search']) ->toArray(); return $this->response->success('OK', $config); }
php
public function index(): JsonResponse { $config = $this->makeView('language-view', trans('HCCore::languages.title.list')) ->addFormSource('add-new', 'language') ->addDataTable($this->getDataTable()) ->setPermissions(['search']) ->toArray(); return $this->response->success('OK', $config); }
[ "public", "function", "index", "(", ")", ":", "JsonResponse", "{", "$", "config", "=", "$", "this", "->", "makeView", "(", "'language-view'", ",", "trans", "(", "'HCCore::languages.title.list'", ")", ")", "->", "addFormSource", "(", "'add-new'", ",", "'language'", ")", "->", "addDataTable", "(", "$", "this", "->", "getDataTable", "(", ")", ")", "->", "setPermissions", "(", "[", "'search'", "]", ")", "->", "toArray", "(", ")", ";", "return", "$", "this", "->", "response", "->", "success", "(", "'OK'", ",", "$", "config", ")", ";", "}" ]
Admin panel page config @return JsonResponse
[ "Admin", "panel", "page", "config" ]
5c12aba31cae092e9681f0ae3e3664ed3fcec956
https://github.com/honey-comb/core/blob/5c12aba31cae092e9681f0ae3e3664ed3fcec956/src/Http/Controllers/HCLanguageController.php#L84-L93
33,803
brainworxx/kreXX
src/Analyse/Callback/Analyse/Objects/Getter.php
Getter.callMe
public function callMe() { $output = $this->dispatchStartEvent(); /** @var \Brainworxx\Krexx\Service\Reflection\ReflectionClass $ref */ $ref = $this->parameters[static::PARAM_REF]; // Get all public methods. $methodList = $ref->getMethods(\ReflectionMethod::IS_PUBLIC); $isInScope = $this->pool->scope->isInScope(); if ($isInScope === true) { // Looks like we also need the protected and private methods. $methodList = array_merge( $methodList, $ref->getMethods(\ReflectionMethod::IS_PRIVATE | \ReflectionMethod::IS_PROTECTED) ); } if (empty($methodList) === true) { // There are no methods in here, at all. return $output; } $this->populateGetterLists($methodList, $isInScope, $ref); if (empty($this->normalGetter) === true && empty($this->isGetter) === true && empty($this->hasGetter) === true ) { // There are no getter methods in here. return $output; } return $output . $this->pool->render->renderExpandableChild( $this->dispatchEventWithModel( static::EVENT_MARKER_ANALYSES_END, $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model') ->setName('Getter') ->setType(static::TYPE_INTERNALS) ->setHelpid('getterHelpInfo') ->addParameter(static::PARAM_REF, $ref) ->addParameter(static::PARAM_NORMAL_GETTER, $this->normalGetter) ->addParameter(static::PARAM_IS_GETTER, $this->isGetter) ->addParameter(static::PARAM_HAS_GETTER, $this->hasGetter) ->injectCallback( $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughGetter') ) ) ); }
php
public function callMe() { $output = $this->dispatchStartEvent(); /** @var \Brainworxx\Krexx\Service\Reflection\ReflectionClass $ref */ $ref = $this->parameters[static::PARAM_REF]; // Get all public methods. $methodList = $ref->getMethods(\ReflectionMethod::IS_PUBLIC); $isInScope = $this->pool->scope->isInScope(); if ($isInScope === true) { // Looks like we also need the protected and private methods. $methodList = array_merge( $methodList, $ref->getMethods(\ReflectionMethod::IS_PRIVATE | \ReflectionMethod::IS_PROTECTED) ); } if (empty($methodList) === true) { // There are no methods in here, at all. return $output; } $this->populateGetterLists($methodList, $isInScope, $ref); if (empty($this->normalGetter) === true && empty($this->isGetter) === true && empty($this->hasGetter) === true ) { // There are no getter methods in here. return $output; } return $output . $this->pool->render->renderExpandableChild( $this->dispatchEventWithModel( static::EVENT_MARKER_ANALYSES_END, $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model') ->setName('Getter') ->setType(static::TYPE_INTERNALS) ->setHelpid('getterHelpInfo') ->addParameter(static::PARAM_REF, $ref) ->addParameter(static::PARAM_NORMAL_GETTER, $this->normalGetter) ->addParameter(static::PARAM_IS_GETTER, $this->isGetter) ->addParameter(static::PARAM_HAS_GETTER, $this->hasGetter) ->injectCallback( $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughGetter') ) ) ); }
[ "public", "function", "callMe", "(", ")", "{", "$", "output", "=", "$", "this", "->", "dispatchStartEvent", "(", ")", ";", "/** @var \\Brainworxx\\Krexx\\Service\\Reflection\\ReflectionClass $ref */", "$", "ref", "=", "$", "this", "->", "parameters", "[", "static", "::", "PARAM_REF", "]", ";", "// Get all public methods.", "$", "methodList", "=", "$", "ref", "->", "getMethods", "(", "\\", "ReflectionMethod", "::", "IS_PUBLIC", ")", ";", "$", "isInScope", "=", "$", "this", "->", "pool", "->", "scope", "->", "isInScope", "(", ")", ";", "if", "(", "$", "isInScope", "===", "true", ")", "{", "// Looks like we also need the protected and private methods.", "$", "methodList", "=", "array_merge", "(", "$", "methodList", ",", "$", "ref", "->", "getMethods", "(", "\\", "ReflectionMethod", "::", "IS_PRIVATE", "|", "\\", "ReflectionMethod", "::", "IS_PROTECTED", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "methodList", ")", "===", "true", ")", "{", "// There are no methods in here, at all.", "return", "$", "output", ";", "}", "$", "this", "->", "populateGetterLists", "(", "$", "methodList", ",", "$", "isInScope", ",", "$", "ref", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "normalGetter", ")", "===", "true", "&&", "empty", "(", "$", "this", "->", "isGetter", ")", "===", "true", "&&", "empty", "(", "$", "this", "->", "hasGetter", ")", "===", "true", ")", "{", "// There are no getter methods in here.", "return", "$", "output", ";", "}", "return", "$", "output", ".", "$", "this", "->", "pool", "->", "render", "->", "renderExpandableChild", "(", "$", "this", "->", "dispatchEventWithModel", "(", "static", "::", "EVENT_MARKER_ANALYSES_END", ",", "$", "this", "->", "pool", "->", "createClass", "(", "'Brainworxx\\\\Krexx\\\\Analyse\\\\Model'", ")", "->", "setName", "(", "'Getter'", ")", "->", "setType", "(", "static", "::", "TYPE_INTERNALS", ")", "->", "setHelpid", "(", "'getterHelpInfo'", ")", "->", "addParameter", "(", "static", "::", "PARAM_REF", ",", "$", "ref", ")", "->", "addParameter", "(", "static", "::", "PARAM_NORMAL_GETTER", ",", "$", "this", "->", "normalGetter", ")", "->", "addParameter", "(", "static", "::", "PARAM_IS_GETTER", ",", "$", "this", "->", "isGetter", ")", "->", "addParameter", "(", "static", "::", "PARAM_HAS_GETTER", ",", "$", "this", "->", "hasGetter", ")", "->", "injectCallback", "(", "$", "this", "->", "pool", "->", "createClass", "(", "'Brainworxx\\\\Krexx\\\\Analyse\\\\Callback\\\\Iterate\\\\ThroughGetter'", ")", ")", ")", ")", ";", "}" ]
Dump the possible result of all getter methods @return string The generated markup.
[ "Dump", "the", "possible", "result", "of", "all", "getter", "methods" ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Callback/Analyse/Objects/Getter.php#L85-L136
33,804
brainworxx/kreXX
src/Analyse/Callback/Analyse/Objects/Getter.php
Getter.populateGetterLists
protected function populateGetterLists(array $methodList, $isInScope, ReflectionClass $ref) { /** @var \ReflectionMethod $method */ foreach ($methodList as $method) { // Check, if the method is really available, inside the analysis // context. A inherited private method can not be called inside the // $this context. if ($isInScope === true && $method->isPrivate() === true && $method->getDeclaringClass()->getName() !== $ref->getName() ) { // We skip this one, it's out of scope. // Meh, as of 03-11-2018, I have never seen a private getter in // my whole life. continue; } if (strpos($method->getName(), 'get') === 0) { /** @var \ReflectionMethod $method */ $parameters = $method->getParameters(); if (empty($parameters)) { $this->normalGetter[] = $method; } } elseif (strpos($method->getName(), 'is') === 0) { /** @var \ReflectionMethod $method */ $parameters = $method->getParameters(); if (empty($parameters)) { $this->isGetter[] = $method; } } elseif (strpos($method->getName(), 'has') === 0) { /** @var \ReflectionMethod $method */ $parameters = $method->getParameters(); if (empty($parameters)) { $this->hasGetter[] = $method; } } } }
php
protected function populateGetterLists(array $methodList, $isInScope, ReflectionClass $ref) { /** @var \ReflectionMethod $method */ foreach ($methodList as $method) { // Check, if the method is really available, inside the analysis // context. A inherited private method can not be called inside the // $this context. if ($isInScope === true && $method->isPrivate() === true && $method->getDeclaringClass()->getName() !== $ref->getName() ) { // We skip this one, it's out of scope. // Meh, as of 03-11-2018, I have never seen a private getter in // my whole life. continue; } if (strpos($method->getName(), 'get') === 0) { /** @var \ReflectionMethod $method */ $parameters = $method->getParameters(); if (empty($parameters)) { $this->normalGetter[] = $method; } } elseif (strpos($method->getName(), 'is') === 0) { /** @var \ReflectionMethod $method */ $parameters = $method->getParameters(); if (empty($parameters)) { $this->isGetter[] = $method; } } elseif (strpos($method->getName(), 'has') === 0) { /** @var \ReflectionMethod $method */ $parameters = $method->getParameters(); if (empty($parameters)) { $this->hasGetter[] = $method; } } } }
[ "protected", "function", "populateGetterLists", "(", "array", "$", "methodList", ",", "$", "isInScope", ",", "ReflectionClass", "$", "ref", ")", "{", "/** @var \\ReflectionMethod $method */", "foreach", "(", "$", "methodList", "as", "$", "method", ")", "{", "// Check, if the method is really available, inside the analysis", "// context. A inherited private method can not be called inside the", "// $this context.", "if", "(", "$", "isInScope", "===", "true", "&&", "$", "method", "->", "isPrivate", "(", ")", "===", "true", "&&", "$", "method", "->", "getDeclaringClass", "(", ")", "->", "getName", "(", ")", "!==", "$", "ref", "->", "getName", "(", ")", ")", "{", "// We skip this one, it's out of scope.", "// Meh, as of 03-11-2018, I have never seen a private getter in", "// my whole life.", "continue", ";", "}", "if", "(", "strpos", "(", "$", "method", "->", "getName", "(", ")", ",", "'get'", ")", "===", "0", ")", "{", "/** @var \\ReflectionMethod $method */", "$", "parameters", "=", "$", "method", "->", "getParameters", "(", ")", ";", "if", "(", "empty", "(", "$", "parameters", ")", ")", "{", "$", "this", "->", "normalGetter", "[", "]", "=", "$", "method", ";", "}", "}", "elseif", "(", "strpos", "(", "$", "method", "->", "getName", "(", ")", ",", "'is'", ")", "===", "0", ")", "{", "/** @var \\ReflectionMethod $method */", "$", "parameters", "=", "$", "method", "->", "getParameters", "(", ")", ";", "if", "(", "empty", "(", "$", "parameters", ")", ")", "{", "$", "this", "->", "isGetter", "[", "]", "=", "$", "method", ";", "}", "}", "elseif", "(", "strpos", "(", "$", "method", "->", "getName", "(", ")", ",", "'has'", ")", "===", "0", ")", "{", "/** @var \\ReflectionMethod $method */", "$", "parameters", "=", "$", "method", "->", "getParameters", "(", ")", ";", "if", "(", "empty", "(", "$", "parameters", ")", ")", "{", "$", "this", "->", "hasGetter", "[", "]", "=", "$", "method", ";", "}", "}", "}", "}" ]
Filter and then populate the method list. We only dump those that have no parameters and start with has, is or get. @param array $methodList @param $isInScope @param \Brainworxx\Krexx\Service\Reflection\ReflectionClass $ref
[ "Filter", "and", "then", "populate", "the", "method", "list", ".", "We", "only", "dump", "those", "that", "have", "no", "parameters", "and", "start", "with", "has", "is", "or", "get", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Callback/Analyse/Objects/Getter.php#L146-L183
33,805
silverorange/swat
Swat/SwatTableViewGroup.php
SwatTableViewGroup.displayFooter
public function displayFooter($row, $next_row) { if ($this->group_by === null) { throw new SwatException("Attribute 'group_by' must be set."); } $group_by = $this->group_by; if ( $next_row === null || !$this->isEqual($row->$group_by, $next_row->$group_by) ) { $this->displayGroupFooter($row); } }
php
public function displayFooter($row, $next_row) { if ($this->group_by === null) { throw new SwatException("Attribute 'group_by' must be set."); } $group_by = $this->group_by; if ( $next_row === null || !$this->isEqual($row->$group_by, $next_row->$group_by) ) { $this->displayGroupFooter($row); } }
[ "public", "function", "displayFooter", "(", "$", "row", ",", "$", "next_row", ")", "{", "if", "(", "$", "this", "->", "group_by", "===", "null", ")", "{", "throw", "new", "SwatException", "(", "\"Attribute 'group_by' must be set.\"", ")", ";", "}", "$", "group_by", "=", "$", "this", "->", "group_by", ";", "if", "(", "$", "next_row", "===", "null", "||", "!", "$", "this", "->", "isEqual", "(", "$", "row", "->", "$", "group_by", ",", "$", "next_row", "->", "$", "group_by", ")", ")", "{", "$", "this", "->", "displayGroupFooter", "(", "$", "row", ")", ";", "}", "}" ]
Displays the grouping footer of this table-view group The grouping footer is displayed when the group_by field is different between the given rows. @param mixed $row a data object containing the data for the first row in in the table store for this group. @param mixed $row a data object containing the data for the current row being displayed in the table-view. @param mixed $next_row a data object containing the data for the next row being displayed in the table-view or null if the current row is the last row.
[ "Displays", "the", "grouping", "footer", "of", "this", "table", "-", "view", "group" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewGroup.php#L71-L85
33,806
silverorange/swat
Swat/SwatTableViewGroup.php
SwatTableViewGroup.displayGroupHeader
protected function displayGroupHeader($row) { $tr_tag = new SwatHtmlTag('tr'); $tr_tag->class = 'swat-table-view-group'; $tr_tag->open(); $td_tag = new SwatHtmlTag('td', $this->getTdAttributes()); $td_tag->colspan = $this->view->getXhtmlColspan(); $td_tag->open(); $this->displayRenderersInternal($row); $td_tag->close(); $tr_tag->close(); }
php
protected function displayGroupHeader($row) { $tr_tag = new SwatHtmlTag('tr'); $tr_tag->class = 'swat-table-view-group'; $tr_tag->open(); $td_tag = new SwatHtmlTag('td', $this->getTdAttributes()); $td_tag->colspan = $this->view->getXhtmlColspan(); $td_tag->open(); $this->displayRenderersInternal($row); $td_tag->close(); $tr_tag->close(); }
[ "protected", "function", "displayGroupHeader", "(", "$", "row", ")", "{", "$", "tr_tag", "=", "new", "SwatHtmlTag", "(", "'tr'", ")", ";", "$", "tr_tag", "->", "class", "=", "'swat-table-view-group'", ";", "$", "tr_tag", "->", "open", "(", ")", ";", "$", "td_tag", "=", "new", "SwatHtmlTag", "(", "'td'", ",", "$", "this", "->", "getTdAttributes", "(", ")", ")", ";", "$", "td_tag", "->", "colspan", "=", "$", "this", "->", "view", "->", "getXhtmlColspan", "(", ")", ";", "$", "td_tag", "->", "open", "(", ")", ";", "$", "this", "->", "displayRenderersInternal", "(", "$", "row", ")", ";", "$", "td_tag", "->", "close", "(", ")", ";", "$", "tr_tag", "->", "close", "(", ")", ";", "}" ]
Displays the group header for this grouping column The grouping header is displayed at the beginning of a group. @param mixed $row a data object containing the data for the first row in in the table store for this group.
[ "Displays", "the", "group", "header", "for", "this", "grouping", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewGroup.php#L98-L111
33,807
silverorange/swat
Swat/SwatTableViewGroup.php
SwatTableViewGroup.isEqual
protected function isEqual($group_value, $row_value) { if ( $group_value instanceof SwatDate && $row_value instanceof SwatDate ) { return SwatDate::compare($group_value, $row_value) === 0; } return $group_value === $row_value; }
php
protected function isEqual($group_value, $row_value) { if ( $group_value instanceof SwatDate && $row_value instanceof SwatDate ) { return SwatDate::compare($group_value, $row_value) === 0; } return $group_value === $row_value; }
[ "protected", "function", "isEqual", "(", "$", "group_value", ",", "$", "row_value", ")", "{", "if", "(", "$", "group_value", "instanceof", "SwatDate", "&&", "$", "row_value", "instanceof", "SwatDate", ")", "{", "return", "SwatDate", "::", "compare", "(", "$", "group_value", ",", "$", "row_value", ")", "===", "0", ";", "}", "return", "$", "group_value", "===", "$", "row_value", ";", "}" ]
Compares the value of the current row to the value of the current group to see if the value has changed @param mixed $group_value the current group value. @param mixed $row_value the current row value. @return boolean true if the row value is different from the current group value. Otherwise, false.
[ "Compares", "the", "value", "of", "the", "current", "row", "to", "the", "value", "of", "the", "current", "group", "to", "see", "if", "the", "value", "has", "changed" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewGroup.php#L175-L185
33,808
silverorange/swat
Swat/SwatTableViewGroup.php
SwatTableViewGroup.resetSubGroups
protected function resetSubGroups() { $reset = false; foreach ($this->parent->getGroups() as $group) { if ($reset) { $group->reset(); } if ($group === $this) { $reset = true; } } }
php
protected function resetSubGroups() { $reset = false; foreach ($this->parent->getGroups() as $group) { if ($reset) { $group->reset(); } if ($group === $this) { $reset = true; } } }
[ "protected", "function", "resetSubGroups", "(", ")", "{", "$", "reset", "=", "false", ";", "foreach", "(", "$", "this", "->", "parent", "->", "getGroups", "(", ")", "as", "$", "group", ")", "{", "if", "(", "$", "reset", ")", "{", "$", "group", "->", "reset", "(", ")", ";", "}", "if", "(", "$", "group", "===", "$", "this", ")", "{", "$", "reset", "=", "true", ";", "}", "}", "}" ]
Resets grouping columns below this one This is used when outside headers change before inside headers. In this case, the inside headers are reset so they display again in the new outside header.
[ "Resets", "grouping", "columns", "below", "this", "one" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewGroup.php#L197-L209
33,809
silverorange/swat
Swat/SwatCheckboxTree.php
SwatCheckboxTree.displayNode
private function displayNode( SwatDataTreeNode $node, $nodes = 0, $parent_index = '' ) { // build a unique id of the indexes of the tree if ($parent_index === '' || $parent_index === null) { // index of the first node is just the node index $index = $node->getIndex(); } else { // index of other nodes is a combination of parent indexes $index = $parent_index . '.' . $node->getIndex(); echo '<li>'; if (isset($node->value)) { $this->input_tag->id = $this->id . '_' . $index; $this->input_tag->value = $node->value; if (in_array($node->value, $this->values)) { $this->input_tag->checked = 'checked'; } else { $this->input_tag->checked = null; } if (!$this->isSensitive()) { $this->input_tag->disabled = 'disabled'; } $this->label_tag->for = $this->id . '_' . $index; $this->label_tag->setContent($node->title); echo '<span class="swat-checkbox-wrapper">'; $this->input_tag->display(); echo '<span class="swat-checkbox-shim"></span>'; echo '</span>'; $this->label_tag->display(); } else { echo SwatString::minimizeEntities($node->title); } } // display children $child_nodes = $node->getChildren(); if (count($child_nodes) > 0) { echo '<ul>'; foreach ($child_nodes as $child_node) { $nodes = $this->displayNode($child_node, $nodes, $index); } echo '</ul>'; } if ($parent_index !== '' && $parent_index !== null) { echo '</li>'; } // count checkable nodes if ($node->value !== null) { $nodes++; } return $nodes; }
php
private function displayNode( SwatDataTreeNode $node, $nodes = 0, $parent_index = '' ) { // build a unique id of the indexes of the tree if ($parent_index === '' || $parent_index === null) { // index of the first node is just the node index $index = $node->getIndex(); } else { // index of other nodes is a combination of parent indexes $index = $parent_index . '.' . $node->getIndex(); echo '<li>'; if (isset($node->value)) { $this->input_tag->id = $this->id . '_' . $index; $this->input_tag->value = $node->value; if (in_array($node->value, $this->values)) { $this->input_tag->checked = 'checked'; } else { $this->input_tag->checked = null; } if (!$this->isSensitive()) { $this->input_tag->disabled = 'disabled'; } $this->label_tag->for = $this->id . '_' . $index; $this->label_tag->setContent($node->title); echo '<span class="swat-checkbox-wrapper">'; $this->input_tag->display(); echo '<span class="swat-checkbox-shim"></span>'; echo '</span>'; $this->label_tag->display(); } else { echo SwatString::minimizeEntities($node->title); } } // display children $child_nodes = $node->getChildren(); if (count($child_nodes) > 0) { echo '<ul>'; foreach ($child_nodes as $child_node) { $nodes = $this->displayNode($child_node, $nodes, $index); } echo '</ul>'; } if ($parent_index !== '' && $parent_index !== null) { echo '</li>'; } // count checkable nodes if ($node->value !== null) { $nodes++; } return $nodes; }
[ "private", "function", "displayNode", "(", "SwatDataTreeNode", "$", "node", ",", "$", "nodes", "=", "0", ",", "$", "parent_index", "=", "''", ")", "{", "// build a unique id of the indexes of the tree", "if", "(", "$", "parent_index", "===", "''", "||", "$", "parent_index", "===", "null", ")", "{", "// index of the first node is just the node index", "$", "index", "=", "$", "node", "->", "getIndex", "(", ")", ";", "}", "else", "{", "// index of other nodes is a combination of parent indexes", "$", "index", "=", "$", "parent_index", ".", "'.'", ".", "$", "node", "->", "getIndex", "(", ")", ";", "echo", "'<li>'", ";", "if", "(", "isset", "(", "$", "node", "->", "value", ")", ")", "{", "$", "this", "->", "input_tag", "->", "id", "=", "$", "this", "->", "id", ".", "'_'", ".", "$", "index", ";", "$", "this", "->", "input_tag", "->", "value", "=", "$", "node", "->", "value", ";", "if", "(", "in_array", "(", "$", "node", "->", "value", ",", "$", "this", "->", "values", ")", ")", "{", "$", "this", "->", "input_tag", "->", "checked", "=", "'checked'", ";", "}", "else", "{", "$", "this", "->", "input_tag", "->", "checked", "=", "null", ";", "}", "if", "(", "!", "$", "this", "->", "isSensitive", "(", ")", ")", "{", "$", "this", "->", "input_tag", "->", "disabled", "=", "'disabled'", ";", "}", "$", "this", "->", "label_tag", "->", "for", "=", "$", "this", "->", "id", ".", "'_'", ".", "$", "index", ";", "$", "this", "->", "label_tag", "->", "setContent", "(", "$", "node", "->", "title", ")", ";", "echo", "'<span class=\"swat-checkbox-wrapper\">'", ";", "$", "this", "->", "input_tag", "->", "display", "(", ")", ";", "echo", "'<span class=\"swat-checkbox-shim\"></span>'", ";", "echo", "'</span>'", ";", "$", "this", "->", "label_tag", "->", "display", "(", ")", ";", "}", "else", "{", "echo", "SwatString", "::", "minimizeEntities", "(", "$", "node", "->", "title", ")", ";", "}", "}", "// display children", "$", "child_nodes", "=", "$", "node", "->", "getChildren", "(", ")", ";", "if", "(", "count", "(", "$", "child_nodes", ")", ">", "0", ")", "{", "echo", "'<ul>'", ";", "foreach", "(", "$", "child_nodes", "as", "$", "child_node", ")", "{", "$", "nodes", "=", "$", "this", "->", "displayNode", "(", "$", "child_node", ",", "$", "nodes", ",", "$", "index", ")", ";", "}", "echo", "'</ul>'", ";", "}", "if", "(", "$", "parent_index", "!==", "''", "&&", "$", "parent_index", "!==", "null", ")", "{", "echo", "'</li>'", ";", "}", "// count checkable nodes", "if", "(", "$", "node", "->", "value", "!==", "null", ")", "{", "$", "nodes", "++", ";", "}", "return", "$", "nodes", ";", "}" ]
Displays a node in a tree as a checkbox input @param SwatDataTreeNode $node the node to display. @param integer $nodes the current number of nodes. @param string $parent_index the path of the parent node. @return integer the number of checkable nodes in the tree.
[ "Displays", "a", "node", "in", "a", "tree", "as", "a", "checkbox", "input" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCheckboxTree.php#L155-L217
33,810
silverorange/swat
Swat/SwatString.php
SwatString.minimizeEntities
public static function minimizeEntities($text) { // decode any entities that might already exist $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); // encode all ampersands (&), less than (<), greater than (>), // and double quote (") characters as their XML entities $text = htmlspecialchars($text, ENT_COMPAT, 'UTF-8'); return $text; }
php
public static function minimizeEntities($text) { // decode any entities that might already exist $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); // encode all ampersands (&), less than (<), greater than (>), // and double quote (") characters as their XML entities $text = htmlspecialchars($text, ENT_COMPAT, 'UTF-8'); return $text; }
[ "public", "static", "function", "minimizeEntities", "(", "$", "text", ")", "{", "// decode any entities that might already exist", "$", "text", "=", "html_entity_decode", "(", "$", "text", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ";", "// encode all ampersands (&), less than (<), greater than (>),", "// and double quote (\") characters as their XML entities", "$", "text", "=", "htmlspecialchars", "(", "$", "text", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ";", "return", "$", "text", ";", "}" ]
Converts a UTF-8 text string to have the minimal number of entities necessary to output it as valid UTF-8 XHTML without ever double-escaping. The text is converted as follows: - any exisiting entities are decoded to their UTF-8 characaters - the minimal number of characters necessary are then escaped as entities: - ampersands (&) => &amp; - less than (<) => &lt; - greater than (>) => &gt; - double quote (") => &quot; @param string $text the UTF-8 text string to convert. @return string the UTF-8 text string with minimal entities.
[ "Converts", "a", "UTF", "-", "8", "text", "string", "to", "have", "the", "minimal", "number", "of", "entities", "necessary", "to", "output", "it", "as", "valid", "UTF", "-", "8", "XHTML", "without", "ever", "double", "-", "escaping", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L408-L418
33,811
silverorange/swat
Swat/SwatString.php
SwatString.condenseToName
public static function condenseToName($string, $max_length = 15) { if (!is_string($string)) { $string = strval($string); } if ($string == '') { return $string; } // remove tags and make lowercase $string = strip_tags(mb_strtolower($string)); if (class_exists('Net_IDNA')) { // we have Net_IDNA, convert words to punycode // convert entities to utf-8 $string = self::minimizeEntities($string); // convert non-alpha-numeric ascii characters to spaces and // condense whitespace $search = array( '/[\x00-\x1f\x21-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]/u', '/\s+/u' ); $replace = array(' ', ' '); $string = preg_replace($search, $replace, $string); // remove leading and tailing whitespace that may have been added // during preg_replace() $string = trim($string); $idna = Net_IDNA::getInstance(); // split into words $string_utf8_exp = explode(' ', $string); // convert words into punycode $first = true; $string_out = ''; foreach ($string_utf8_exp as $string_utf8) { $encoded_word = $idna->encode($string_utf8); if ($first) { // first word too long, so forced to chop it if (mb_strlen($encoded_word) >= $max_length) { return mb_substr($encoded_word, 0, $max_length); } $first = false; } // this word would push us over the limit $new_length = mb_strlen($string_out) + mb_strlen($encoded_word); if ($new_length > $max_length) { return $string_out; } $string_out .= $encoded_word; } } else { // remove html entities, convert non-alpha-numeric characters to // spaces and condense whitespace $search = array('/&#?\w+;/u', '/[^a-z0-9 ]/u', '/\s+/u'); $replace = array('', ' ', ' '); $string = preg_replace($search, $replace, $string); // split into words $string_exp = explode(' ', $string); // first word too long, so forced to chop it if (mb_strlen($string_exp[0]) >= $max_length) { return mb_substr($string_exp[0], 0, $max_length); } $string_out = ''; // add words to output until it is too long foreach ($string_exp as $word) { // this word would push us over the limit if (mb_strlen($string_out) + mb_strlen($word) > $max_length) { return $string_out; } $string_out .= $word; } } return $string_out; }
php
public static function condenseToName($string, $max_length = 15) { if (!is_string($string)) { $string = strval($string); } if ($string == '') { return $string; } // remove tags and make lowercase $string = strip_tags(mb_strtolower($string)); if (class_exists('Net_IDNA')) { // we have Net_IDNA, convert words to punycode // convert entities to utf-8 $string = self::minimizeEntities($string); // convert non-alpha-numeric ascii characters to spaces and // condense whitespace $search = array( '/[\x00-\x1f\x21-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]/u', '/\s+/u' ); $replace = array(' ', ' '); $string = preg_replace($search, $replace, $string); // remove leading and tailing whitespace that may have been added // during preg_replace() $string = trim($string); $idna = Net_IDNA::getInstance(); // split into words $string_utf8_exp = explode(' ', $string); // convert words into punycode $first = true; $string_out = ''; foreach ($string_utf8_exp as $string_utf8) { $encoded_word = $idna->encode($string_utf8); if ($first) { // first word too long, so forced to chop it if (mb_strlen($encoded_word) >= $max_length) { return mb_substr($encoded_word, 0, $max_length); } $first = false; } // this word would push us over the limit $new_length = mb_strlen($string_out) + mb_strlen($encoded_word); if ($new_length > $max_length) { return $string_out; } $string_out .= $encoded_word; } } else { // remove html entities, convert non-alpha-numeric characters to // spaces and condense whitespace $search = array('/&#?\w+;/u', '/[^a-z0-9 ]/u', '/\s+/u'); $replace = array('', ' ', ' '); $string = preg_replace($search, $replace, $string); // split into words $string_exp = explode(' ', $string); // first word too long, so forced to chop it if (mb_strlen($string_exp[0]) >= $max_length) { return mb_substr($string_exp[0], 0, $max_length); } $string_out = ''; // add words to output until it is too long foreach ($string_exp as $word) { // this word would push us over the limit if (mb_strlen($string_out) + mb_strlen($word) > $max_length) { return $string_out; } $string_out .= $word; } } return $string_out; }
[ "public", "static", "function", "condenseToName", "(", "$", "string", ",", "$", "max_length", "=", "15", ")", "{", "if", "(", "!", "is_string", "(", "$", "string", ")", ")", "{", "$", "string", "=", "strval", "(", "$", "string", ")", ";", "}", "if", "(", "$", "string", "==", "''", ")", "{", "return", "$", "string", ";", "}", "// remove tags and make lowercase", "$", "string", "=", "strip_tags", "(", "mb_strtolower", "(", "$", "string", ")", ")", ";", "if", "(", "class_exists", "(", "'Net_IDNA'", ")", ")", "{", "// we have Net_IDNA, convert words to punycode", "// convert entities to utf-8", "$", "string", "=", "self", "::", "minimizeEntities", "(", "$", "string", ")", ";", "// convert non-alpha-numeric ascii characters to spaces and", "// condense whitespace", "$", "search", "=", "array", "(", "'/[\\x00-\\x1f\\x21-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7e]/u'", ",", "'/\\s+/u'", ")", ";", "$", "replace", "=", "array", "(", "' '", ",", "' '", ")", ";", "$", "string", "=", "preg_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "string", ")", ";", "// remove leading and tailing whitespace that may have been added", "// during preg_replace()", "$", "string", "=", "trim", "(", "$", "string", ")", ";", "$", "idna", "=", "Net_IDNA", "::", "getInstance", "(", ")", ";", "// split into words", "$", "string_utf8_exp", "=", "explode", "(", "' '", ",", "$", "string", ")", ";", "// convert words into punycode", "$", "first", "=", "true", ";", "$", "string_out", "=", "''", ";", "foreach", "(", "$", "string_utf8_exp", "as", "$", "string_utf8", ")", "{", "$", "encoded_word", "=", "$", "idna", "->", "encode", "(", "$", "string_utf8", ")", ";", "if", "(", "$", "first", ")", "{", "// first word too long, so forced to chop it", "if", "(", "mb_strlen", "(", "$", "encoded_word", ")", ">=", "$", "max_length", ")", "{", "return", "mb_substr", "(", "$", "encoded_word", ",", "0", ",", "$", "max_length", ")", ";", "}", "$", "first", "=", "false", ";", "}", "// this word would push us over the limit", "$", "new_length", "=", "mb_strlen", "(", "$", "string_out", ")", "+", "mb_strlen", "(", "$", "encoded_word", ")", ";", "if", "(", "$", "new_length", ">", "$", "max_length", ")", "{", "return", "$", "string_out", ";", "}", "$", "string_out", ".=", "$", "encoded_word", ";", "}", "}", "else", "{", "// remove html entities, convert non-alpha-numeric characters to", "// spaces and condense whitespace", "$", "search", "=", "array", "(", "'/&#?\\w+;/u'", ",", "'/[^a-z0-9 ]/u'", ",", "'/\\s+/u'", ")", ";", "$", "replace", "=", "array", "(", "''", ",", "' '", ",", "' '", ")", ";", "$", "string", "=", "preg_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "string", ")", ";", "// split into words", "$", "string_exp", "=", "explode", "(", "' '", ",", "$", "string", ")", ";", "// first word too long, so forced to chop it", "if", "(", "mb_strlen", "(", "$", "string_exp", "[", "0", "]", ")", ">=", "$", "max_length", ")", "{", "return", "mb_substr", "(", "$", "string_exp", "[", "0", "]", ",", "0", ",", "$", "max_length", ")", ";", "}", "$", "string_out", "=", "''", ";", "// add words to output until it is too long", "foreach", "(", "$", "string_exp", "as", "$", "word", ")", "{", "// this word would push us over the limit", "if", "(", "mb_strlen", "(", "$", "string_out", ")", "+", "mb_strlen", "(", "$", "word", ")", ">", "$", "max_length", ")", "{", "return", "$", "string_out", ";", "}", "$", "string_out", ".=", "$", "word", ";", "}", "}", "return", "$", "string_out", ";", "}" ]
Condenses a string to a name The generated name can be used for things like database identifiers and site URI fragments. Example: <code> $string = 'The quick brown fox jumped over the lazy dogs.'; // displays 'thequickbrown' echo SwatString::condenseToName($string); </code> @param string $string the string to condense to a name. @param integer $max_length the maximum length of the condensed name in characters. @return string the string condensed into a name.
[ "Condenses", "a", "string", "to", "a", "name" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L595-L685
33,812
silverorange/swat
Swat/SwatString.php
SwatString.removePunctuation
public static function removePunctuation($string) { $string = self::removeTrailingPunctuation($string); $string = self::removeLeadingPunctuation($string); return $string; }
php
public static function removePunctuation($string) { $string = self::removeTrailingPunctuation($string); $string = self::removeLeadingPunctuation($string); return $string; }
[ "public", "static", "function", "removePunctuation", "(", "$", "string", ")", "{", "$", "string", "=", "self", "::", "removeTrailingPunctuation", "(", "$", "string", ")", ";", "$", "string", "=", "self", "::", "removeLeadingPunctuation", "(", "$", "string", ")", ";", "return", "$", "string", ";", "}" ]
Removes both leading and trailing punctuation from a string @param string $string the string to format remove punctuation from. @return string the string with leading and trailing punctuation removed.
[ "Removes", "both", "leading", "and", "trailing", "punctuation", "from", "a", "string" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L936-L941
33,813
silverorange/swat
Swat/SwatString.php
SwatString.moneyFormat
public static function moneyFormat( $value, $locale = null, $display_currency = false, $decimal_places = null ) { if (!function_exists('money_format')) { throw new SwatException( 'moneyFormat() method is not available ' . 'on this operating system. See ' . 'http://php.net/manual/en/function.money-format.php for ' . 'details.' ); } if ($locale !== null) { $old_locale = setlocale(LC_ALL, 0); if (setlocale(LC_ALL, $locale) === false) { throw new SwatException( sprintf( 'Locale %s passed to the ' . 'moneyFormat() method is not valid for this operating ' . 'system.', $locale ) ); } } // get character set of the locale that is used $character_set = nl_langinfo(CODESET); $format_string = $decimal_places === null ? '%n' : '%.' . ((int) $decimal_places) . 'n'; $output = money_format($format_string, $value); if ($display_currency) { $lc = localeconv(); $output .= ' ' . $lc['int_curr_symbol']; } // convert output to UTF-8 if ($character_set !== 'UTF-8') { $output = iconv($character_set, 'UTF-8', $output); if ($output === false) { throw new SwatException( sprintf( 'Could not convert %s output to UTF-8', $character_set ) ); } } if ($locale !== null) { setlocale(LC_ALL, $old_locale); } return $output; }
php
public static function moneyFormat( $value, $locale = null, $display_currency = false, $decimal_places = null ) { if (!function_exists('money_format')) { throw new SwatException( 'moneyFormat() method is not available ' . 'on this operating system. See ' . 'http://php.net/manual/en/function.money-format.php for ' . 'details.' ); } if ($locale !== null) { $old_locale = setlocale(LC_ALL, 0); if (setlocale(LC_ALL, $locale) === false) { throw new SwatException( sprintf( 'Locale %s passed to the ' . 'moneyFormat() method is not valid for this operating ' . 'system.', $locale ) ); } } // get character set of the locale that is used $character_set = nl_langinfo(CODESET); $format_string = $decimal_places === null ? '%n' : '%.' . ((int) $decimal_places) . 'n'; $output = money_format($format_string, $value); if ($display_currency) { $lc = localeconv(); $output .= ' ' . $lc['int_curr_symbol']; } // convert output to UTF-8 if ($character_set !== 'UTF-8') { $output = iconv($character_set, 'UTF-8', $output); if ($output === false) { throw new SwatException( sprintf( 'Could not convert %s output to UTF-8', $character_set ) ); } } if ($locale !== null) { setlocale(LC_ALL, $old_locale); } return $output; }
[ "public", "static", "function", "moneyFormat", "(", "$", "value", ",", "$", "locale", "=", "null", ",", "$", "display_currency", "=", "false", ",", "$", "decimal_places", "=", "null", ")", "{", "if", "(", "!", "function_exists", "(", "'money_format'", ")", ")", "{", "throw", "new", "SwatException", "(", "'moneyFormat() method is not available '", ".", "'on this operating system. See '", ".", "'http://php.net/manual/en/function.money-format.php for '", ".", "'details.'", ")", ";", "}", "if", "(", "$", "locale", "!==", "null", ")", "{", "$", "old_locale", "=", "setlocale", "(", "LC_ALL", ",", "0", ")", ";", "if", "(", "setlocale", "(", "LC_ALL", ",", "$", "locale", ")", "===", "false", ")", "{", "throw", "new", "SwatException", "(", "sprintf", "(", "'Locale %s passed to the '", ".", "'moneyFormat() method is not valid for this operating '", ".", "'system.'", ",", "$", "locale", ")", ")", ";", "}", "}", "// get character set of the locale that is used", "$", "character_set", "=", "nl_langinfo", "(", "CODESET", ")", ";", "$", "format_string", "=", "$", "decimal_places", "===", "null", "?", "'%n'", ":", "'%.'", ".", "(", "(", "int", ")", "$", "decimal_places", ")", ".", "'n'", ";", "$", "output", "=", "money_format", "(", "$", "format_string", ",", "$", "value", ")", ";", "if", "(", "$", "display_currency", ")", "{", "$", "lc", "=", "localeconv", "(", ")", ";", "$", "output", ".=", "' '", ".", "$", "lc", "[", "'int_curr_symbol'", "]", ";", "}", "// convert output to UTF-8", "if", "(", "$", "character_set", "!==", "'UTF-8'", ")", "{", "$", "output", "=", "iconv", "(", "$", "character_set", ",", "'UTF-8'", ",", "$", "output", ")", ";", "if", "(", "$", "output", "===", "false", ")", "{", "throw", "new", "SwatException", "(", "sprintf", "(", "'Could not convert %s output to UTF-8'", ",", "$", "character_set", ")", ")", ";", "}", "}", "if", "(", "$", "locale", "!==", "null", ")", "{", "setlocale", "(", "LC_ALL", ",", "$", "old_locale", ")", ";", "}", "return", "$", "output", ";", "}" ]
Formats a numeric value as currency Note: This method does not work in some operating systems and in such cases, this method will throw an exception. Note: This method is deprecated. Use {@link SwatI18NLocale::formatCurrency()} instead. The newer method is more flexible and works across more platforms. @param float $value the numeric value to format. @param string $locale optional locale to use to format the value. If no locale is specified, the current locale is used. @param boolean $display_currency optional flag specifing whether or not the international currency symbol is appended to the output. If not specified, the international currency symbol is omitted from the output. @param integer $decimal_places optional number of decimal places to display. If not specified, the locale's default number of decimal places is used. @return string a UTF-8 encoded string containing the formatted currency value. @throws SwatException if the PHP money_format() function is undefined. @throws SwatException if the given locale could not be set. @throws SwatException if the locale-based output cannot be converted to UTF-8. @deprecated Use {@link SwatI18NLocale::formatCurrency()} instead. It is more flexible and works across more platforms.
[ "Formats", "a", "numeric", "value", "as", "currency" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L979-L1041
33,814
silverorange/swat
Swat/SwatString.php
SwatString.getInternationalCurrencySymbol
public static function getInternationalCurrencySymbol($locale = null) { if ($locale !== null) { $old_locale = setlocale(LC_MONETARY, 0); if (setlocale(LC_MONETARY, $locale) === false) { throw new SwatException( sprintf( 'Locale %s passed to the ' . 'getInternationalCurrencySymbol() method is not valid ' . 'for this operating system.', $locale ) ); } } // get character set of the locale that is used $character_set = nl_langinfo(CODESET); $lc = localeconv(); $symbol = $lc['int_curr_symbol']; // convert output to UTF-8 if ($character_set !== 'UTF-8') { $symbol = iconv($character_set, 'UTF-8', $symbol); if ($symbol === false) { throw new SwatException( sprintf( 'Could not convert %s output to UTF-8', $character_set ) ); } } // strip C99-defined spacing character $symbol = mb_substr($symbol, 0, 3); if ($locale !== null) { setlocale(LC_ALL, $old_locale); } return $symbol; }
php
public static function getInternationalCurrencySymbol($locale = null) { if ($locale !== null) { $old_locale = setlocale(LC_MONETARY, 0); if (setlocale(LC_MONETARY, $locale) === false) { throw new SwatException( sprintf( 'Locale %s passed to the ' . 'getInternationalCurrencySymbol() method is not valid ' . 'for this operating system.', $locale ) ); } } // get character set of the locale that is used $character_set = nl_langinfo(CODESET); $lc = localeconv(); $symbol = $lc['int_curr_symbol']; // convert output to UTF-8 if ($character_set !== 'UTF-8') { $symbol = iconv($character_set, 'UTF-8', $symbol); if ($symbol === false) { throw new SwatException( sprintf( 'Could not convert %s output to UTF-8', $character_set ) ); } } // strip C99-defined spacing character $symbol = mb_substr($symbol, 0, 3); if ($locale !== null) { setlocale(LC_ALL, $old_locale); } return $symbol; }
[ "public", "static", "function", "getInternationalCurrencySymbol", "(", "$", "locale", "=", "null", ")", "{", "if", "(", "$", "locale", "!==", "null", ")", "{", "$", "old_locale", "=", "setlocale", "(", "LC_MONETARY", ",", "0", ")", ";", "if", "(", "setlocale", "(", "LC_MONETARY", ",", "$", "locale", ")", "===", "false", ")", "{", "throw", "new", "SwatException", "(", "sprintf", "(", "'Locale %s passed to the '", ".", "'getInternationalCurrencySymbol() method is not valid '", ".", "'for this operating system.'", ",", "$", "locale", ")", ")", ";", "}", "}", "// get character set of the locale that is used", "$", "character_set", "=", "nl_langinfo", "(", "CODESET", ")", ";", "$", "lc", "=", "localeconv", "(", ")", ";", "$", "symbol", "=", "$", "lc", "[", "'int_curr_symbol'", "]", ";", "// convert output to UTF-8", "if", "(", "$", "character_set", "!==", "'UTF-8'", ")", "{", "$", "symbol", "=", "iconv", "(", "$", "character_set", ",", "'UTF-8'", ",", "$", "symbol", ")", ";", "if", "(", "$", "symbol", "===", "false", ")", "{", "throw", "new", "SwatException", "(", "sprintf", "(", "'Could not convert %s output to UTF-8'", ",", "$", "character_set", ")", ")", ";", "}", "}", "// strip C99-defined spacing character", "$", "symbol", "=", "mb_substr", "(", "$", "symbol", ",", "0", ",", "3", ")", ";", "if", "(", "$", "locale", "!==", "null", ")", "{", "setlocale", "(", "LC_ALL", ",", "$", "old_locale", ")", ";", "}", "return", "$", "symbol", ";", "}" ]
Gets the international currency symbol of a locale @param string $locale optional. Locale to get the international currency symbol for. If no locale is specified, the current locale is used. @return string the international currency symbol for the specified locale. The symbol is UTF-8 encoded and does not include the spacing character specified in the C99 standard. @throws SwatException if the given locale could not be set.
[ "Gets", "the", "international", "currency", "symbol", "of", "a", "locale" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1059-L1102
33,815
silverorange/swat
Swat/SwatString.php
SwatString.numberFormat
public static function numberFormat( $value, $decimals = null, $locale = null, $show_thousands_separator = true ) { // look up decimal precision if none is provided if ($decimals === null) { $decimals = self::getDecimalPrecision($value); } // number_format can't handle UTF-8 separators, so insert placeholders $output = number_format( $value, $decimals, '.', $show_thousands_separator ? ',' : '' ); if ($locale !== null) { $old_locale = setlocale(LC_ALL, 0); if (setlocale(LC_ALL, $locale) === false) { throw new SwatException( sprintf( 'Locale %s passed to the ' . 'numberFormat() method is not valid for this operating ' . 'system.', $locale ) ); } } // get character set of the locale that is used $character_set = nl_langinfo(CODESET); // replace placeholder separators with locale-specific ones which // might contain non-ASCII $lc = localeconv(); $output = str_replace('.', $lc['decimal_point'], $output); $output = str_replace(',', $lc['thousands_sep'], $output); // convert output to UTF-8 if ($character_set !== 'UTF-8') { $output = iconv($character_set, 'UTF-8', $output); if ($output === false) { throw new SwatException( sprintf( 'Could not convert %s output to UTF-8', $character_set ) ); } } if ($locale !== null) { setlocale(LC_ALL, $old_locale); } return $output; }
php
public static function numberFormat( $value, $decimals = null, $locale = null, $show_thousands_separator = true ) { // look up decimal precision if none is provided if ($decimals === null) { $decimals = self::getDecimalPrecision($value); } // number_format can't handle UTF-8 separators, so insert placeholders $output = number_format( $value, $decimals, '.', $show_thousands_separator ? ',' : '' ); if ($locale !== null) { $old_locale = setlocale(LC_ALL, 0); if (setlocale(LC_ALL, $locale) === false) { throw new SwatException( sprintf( 'Locale %s passed to the ' . 'numberFormat() method is not valid for this operating ' . 'system.', $locale ) ); } } // get character set of the locale that is used $character_set = nl_langinfo(CODESET); // replace placeholder separators with locale-specific ones which // might contain non-ASCII $lc = localeconv(); $output = str_replace('.', $lc['decimal_point'], $output); $output = str_replace(',', $lc['thousands_sep'], $output); // convert output to UTF-8 if ($character_set !== 'UTF-8') { $output = iconv($character_set, 'UTF-8', $output); if ($output === false) { throw new SwatException( sprintf( 'Could not convert %s output to UTF-8', $character_set ) ); } } if ($locale !== null) { setlocale(LC_ALL, $old_locale); } return $output; }
[ "public", "static", "function", "numberFormat", "(", "$", "value", ",", "$", "decimals", "=", "null", ",", "$", "locale", "=", "null", ",", "$", "show_thousands_separator", "=", "true", ")", "{", "// look up decimal precision if none is provided", "if", "(", "$", "decimals", "===", "null", ")", "{", "$", "decimals", "=", "self", "::", "getDecimalPrecision", "(", "$", "value", ")", ";", "}", "// number_format can't handle UTF-8 separators, so insert placeholders", "$", "output", "=", "number_format", "(", "$", "value", ",", "$", "decimals", ",", "'.'", ",", "$", "show_thousands_separator", "?", "','", ":", "''", ")", ";", "if", "(", "$", "locale", "!==", "null", ")", "{", "$", "old_locale", "=", "setlocale", "(", "LC_ALL", ",", "0", ")", ";", "if", "(", "setlocale", "(", "LC_ALL", ",", "$", "locale", ")", "===", "false", ")", "{", "throw", "new", "SwatException", "(", "sprintf", "(", "'Locale %s passed to the '", ".", "'numberFormat() method is not valid for this operating '", ".", "'system.'", ",", "$", "locale", ")", ")", ";", "}", "}", "// get character set of the locale that is used", "$", "character_set", "=", "nl_langinfo", "(", "CODESET", ")", ";", "// replace placeholder separators with locale-specific ones which", "// might contain non-ASCII", "$", "lc", "=", "localeconv", "(", ")", ";", "$", "output", "=", "str_replace", "(", "'.'", ",", "$", "lc", "[", "'decimal_point'", "]", ",", "$", "output", ")", ";", "$", "output", "=", "str_replace", "(", "','", ",", "$", "lc", "[", "'thousands_sep'", "]", ",", "$", "output", ")", ";", "// convert output to UTF-8", "if", "(", "$", "character_set", "!==", "'UTF-8'", ")", "{", "$", "output", "=", "iconv", "(", "$", "character_set", ",", "'UTF-8'", ",", "$", "output", ")", ";", "if", "(", "$", "output", "===", "false", ")", "{", "throw", "new", "SwatException", "(", "sprintf", "(", "'Could not convert %s output to UTF-8'", ",", "$", "character_set", ")", ")", ";", "}", "}", "if", "(", "$", "locale", "!==", "null", ")", "{", "setlocale", "(", "LC_ALL", ",", "$", "old_locale", ")", ";", "}", "return", "$", "output", ";", "}" ]
Formats a number using locale-based separators @param float $value the numeric value to format. @param integer $decimals number of decimal places to display. By default, the full number of decimal places of the value will be displayed. @param string $locale an optional locale to use to format the value. If no locale is specified, the current locale is used. @param boolean $show_thousands_separator whether or not to display the thousands separator (default is true). @return string a UTF-8 encoded string containing the formatted number. @throws SwatException if the given locale could not be set. @throws SwatException if the locale-based output cannot be converted to UTF-8.
[ "Formats", "a", "number", "using", "locale", "-", "based", "separators" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1126-L1186
33,816
silverorange/swat
Swat/SwatString.php
SwatString.byteFormat
public static function byteFormat( $value, $magnitude = -1, $iec_units = false, $significant_digits = 3 ) { if ($iec_units) { $units = array( 60 => 'EiB', 50 => 'PiB', 40 => 'TiB', 30 => 'GiB', 20 => 'MiB', 10 => 'KiB', 0 => 'bytes' ); } else { $units = array( 60 => 'EB', 50 => 'PB', 40 => 'TB', 30 => 'GB', 20 => 'MB', 10 => 'KB', 0 => 'bytes' ); } $unit_magnitude = null; if ($magnitude >= 0) { $magnitude = intval(round($magnitude / 10) * 10); if (array_key_exists($magnitude, $units)) { $unit_magnitude = $magnitude; } else { $unit_magnitude = reset($units); // default magnitude } } else { if ($value == 0) { $unit_magnitude = 0; } else { $log = floor(log10($value) / log10(2)); // get log2() $unit_magnitude = reset($units); // default magnitude foreach ($units as $magnitude => $title) { if ($log >= $magnitude) { $unit_magnitude = $magnitude; break; } } } } $value = $value / pow(2, $unit_magnitude); if ($unit_magnitude == 0) { // 'bytes' are always formatted as integers $formatted_value = self::numberFormat($value, 0); } else { if ($significant_digits !== null) { // round to number of significant digits $integer_digits = floor(log10($value)) + 1; $fractional_digits = max( $significant_digits - $integer_digits, 0 ); $formatted_value = self::numberFormat( $value, $fractional_digits ); } else { // just round to one fractional digit $formatted_value = self::numberFormat($value, 1); } } return $formatted_value . ' ' . $units[$unit_magnitude]; }
php
public static function byteFormat( $value, $magnitude = -1, $iec_units = false, $significant_digits = 3 ) { if ($iec_units) { $units = array( 60 => 'EiB', 50 => 'PiB', 40 => 'TiB', 30 => 'GiB', 20 => 'MiB', 10 => 'KiB', 0 => 'bytes' ); } else { $units = array( 60 => 'EB', 50 => 'PB', 40 => 'TB', 30 => 'GB', 20 => 'MB', 10 => 'KB', 0 => 'bytes' ); } $unit_magnitude = null; if ($magnitude >= 0) { $magnitude = intval(round($magnitude / 10) * 10); if (array_key_exists($magnitude, $units)) { $unit_magnitude = $magnitude; } else { $unit_magnitude = reset($units); // default magnitude } } else { if ($value == 0) { $unit_magnitude = 0; } else { $log = floor(log10($value) / log10(2)); // get log2() $unit_magnitude = reset($units); // default magnitude foreach ($units as $magnitude => $title) { if ($log >= $magnitude) { $unit_magnitude = $magnitude; break; } } } } $value = $value / pow(2, $unit_magnitude); if ($unit_magnitude == 0) { // 'bytes' are always formatted as integers $formatted_value = self::numberFormat($value, 0); } else { if ($significant_digits !== null) { // round to number of significant digits $integer_digits = floor(log10($value)) + 1; $fractional_digits = max( $significant_digits - $integer_digits, 0 ); $formatted_value = self::numberFormat( $value, $fractional_digits ); } else { // just round to one fractional digit $formatted_value = self::numberFormat($value, 1); } } return $formatted_value . ' ' . $units[$unit_magnitude]; }
[ "public", "static", "function", "byteFormat", "(", "$", "value", ",", "$", "magnitude", "=", "-", "1", ",", "$", "iec_units", "=", "false", ",", "$", "significant_digits", "=", "3", ")", "{", "if", "(", "$", "iec_units", ")", "{", "$", "units", "=", "array", "(", "60", "=>", "'EiB'", ",", "50", "=>", "'PiB'", ",", "40", "=>", "'TiB'", ",", "30", "=>", "'GiB'", ",", "20", "=>", "'MiB'", ",", "10", "=>", "'KiB'", ",", "0", "=>", "'bytes'", ")", ";", "}", "else", "{", "$", "units", "=", "array", "(", "60", "=>", "'EB'", ",", "50", "=>", "'PB'", ",", "40", "=>", "'TB'", ",", "30", "=>", "'GB'", ",", "20", "=>", "'MB'", ",", "10", "=>", "'KB'", ",", "0", "=>", "'bytes'", ")", ";", "}", "$", "unit_magnitude", "=", "null", ";", "if", "(", "$", "magnitude", ">=", "0", ")", "{", "$", "magnitude", "=", "intval", "(", "round", "(", "$", "magnitude", "/", "10", ")", "*", "10", ")", ";", "if", "(", "array_key_exists", "(", "$", "magnitude", ",", "$", "units", ")", ")", "{", "$", "unit_magnitude", "=", "$", "magnitude", ";", "}", "else", "{", "$", "unit_magnitude", "=", "reset", "(", "$", "units", ")", ";", "// default magnitude", "}", "}", "else", "{", "if", "(", "$", "value", "==", "0", ")", "{", "$", "unit_magnitude", "=", "0", ";", "}", "else", "{", "$", "log", "=", "floor", "(", "log10", "(", "$", "value", ")", "/", "log10", "(", "2", ")", ")", ";", "// get log2()", "$", "unit_magnitude", "=", "reset", "(", "$", "units", ")", ";", "// default magnitude", "foreach", "(", "$", "units", "as", "$", "magnitude", "=>", "$", "title", ")", "{", "if", "(", "$", "log", ">=", "$", "magnitude", ")", "{", "$", "unit_magnitude", "=", "$", "magnitude", ";", "break", ";", "}", "}", "}", "}", "$", "value", "=", "$", "value", "/", "pow", "(", "2", ",", "$", "unit_magnitude", ")", ";", "if", "(", "$", "unit_magnitude", "==", "0", ")", "{", "// 'bytes' are always formatted as integers", "$", "formatted_value", "=", "self", "::", "numberFormat", "(", "$", "value", ",", "0", ")", ";", "}", "else", "{", "if", "(", "$", "significant_digits", "!==", "null", ")", "{", "// round to number of significant digits", "$", "integer_digits", "=", "floor", "(", "log10", "(", "$", "value", ")", ")", "+", "1", ";", "$", "fractional_digits", "=", "max", "(", "$", "significant_digits", "-", "$", "integer_digits", ",", "0", ")", ";", "$", "formatted_value", "=", "self", "::", "numberFormat", "(", "$", "value", ",", "$", "fractional_digits", ")", ";", "}", "else", "{", "// just round to one fractional digit", "$", "formatted_value", "=", "self", "::", "numberFormat", "(", "$", "value", ",", "1", ")", ";", "}", "}", "return", "$", "formatted_value", ".", "' '", ".", "$", "units", "[", "$", "unit_magnitude", "]", ";", "}" ]
Format bytes in human readible units By default, bytes are formatted using canonical, ambiguous, base-10 prefixed units. Bytes may optionally be formatted using unambiguous IEC standard binary prefixes. See the National Institute of Standards and Technology's page on binary unit prefixes at {@link http://physics.nist.gov/cuu/Units/binary.html} for details. @param integer $value the value in bytes to format. @param integer $magnitude optional. The power of 2 to use as the unit base. This value will be rounded to the nearest ten if specified. If less than zero or not specified, the highest power less than <code>$value</code> will be used. @param boolean $iec_units optional. Whether or not to use IEC binary multiple prefixed units (Mebibyte). Defaults to using canonical units. @param integer $significant_digits optional. The number of significant digits in the formatted result. If null, the value will be rounded and formatted one fractional digit. Otherwise, the value is rounded to the specified the number of digits. By default, this is three. If there are more integer digits than the specified number of significant digits, the value is rounded to the nearest integer. @return string the byte value formated according to IEC units.
[ "Format", "bytes", "in", "human", "readible", "units" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1240-L1319
33,817
silverorange/swat
Swat/SwatString.php
SwatString.pad
public static function pad( $input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT ) { $output = ''; $length = $pad_length - mb_strlen($input); if ($pad_string === null || mb_strlen($pad_string) === 0) { $pad_string = ' '; } if ($length > 0) { switch ($pad_type) { case STR_PAD_LEFT: $padding = str_repeat( $pad_string, ceil($length / mb_strlen($pad_string)) ); $output = mb_substr($padding, 0, $length) . $input; break; case STR_PAD_BOTH: $left_length = floor($length / 2); $right_length = ceil($length / 2); $padding = str_repeat( $pad_string, ceil($right_length / mb_strlen($pad_string)) ); $output = mb_substr($padding, 0, $left_length) . $input . mb_substr($padding, 0, $right_length); break; case STR_PAD_RIGHT: default: $padding = str_repeat( $pad_string, ceil($length / mb_strlen($pad_string)) ); $output = $input . mb_substr($padding, 0, $length); } } else { $output = $input; } return $output; }
php
public static function pad( $input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT ) { $output = ''; $length = $pad_length - mb_strlen($input); if ($pad_string === null || mb_strlen($pad_string) === 0) { $pad_string = ' '; } if ($length > 0) { switch ($pad_type) { case STR_PAD_LEFT: $padding = str_repeat( $pad_string, ceil($length / mb_strlen($pad_string)) ); $output = mb_substr($padding, 0, $length) . $input; break; case STR_PAD_BOTH: $left_length = floor($length / 2); $right_length = ceil($length / 2); $padding = str_repeat( $pad_string, ceil($right_length / mb_strlen($pad_string)) ); $output = mb_substr($padding, 0, $left_length) . $input . mb_substr($padding, 0, $right_length); break; case STR_PAD_RIGHT: default: $padding = str_repeat( $pad_string, ceil($length / mb_strlen($pad_string)) ); $output = $input . mb_substr($padding, 0, $length); } } else { $output = $input; } return $output; }
[ "public", "static", "function", "pad", "(", "$", "input", ",", "$", "pad_length", ",", "$", "pad_string", "=", "' '", ",", "$", "pad_type", "=", "STR_PAD_RIGHT", ")", "{", "$", "output", "=", "''", ";", "$", "length", "=", "$", "pad_length", "-", "mb_strlen", "(", "$", "input", ")", ";", "if", "(", "$", "pad_string", "===", "null", "||", "mb_strlen", "(", "$", "pad_string", ")", "===", "0", ")", "{", "$", "pad_string", "=", "' '", ";", "}", "if", "(", "$", "length", ">", "0", ")", "{", "switch", "(", "$", "pad_type", ")", "{", "case", "STR_PAD_LEFT", ":", "$", "padding", "=", "str_repeat", "(", "$", "pad_string", ",", "ceil", "(", "$", "length", "/", "mb_strlen", "(", "$", "pad_string", ")", ")", ")", ";", "$", "output", "=", "mb_substr", "(", "$", "padding", ",", "0", ",", "$", "length", ")", ".", "$", "input", ";", "break", ";", "case", "STR_PAD_BOTH", ":", "$", "left_length", "=", "floor", "(", "$", "length", "/", "2", ")", ";", "$", "right_length", "=", "ceil", "(", "$", "length", "/", "2", ")", ";", "$", "padding", "=", "str_repeat", "(", "$", "pad_string", ",", "ceil", "(", "$", "right_length", "/", "mb_strlen", "(", "$", "pad_string", ")", ")", ")", ";", "$", "output", "=", "mb_substr", "(", "$", "padding", ",", "0", ",", "$", "left_length", ")", ".", "$", "input", ".", "mb_substr", "(", "$", "padding", ",", "0", ",", "$", "right_length", ")", ";", "break", ";", "case", "STR_PAD_RIGHT", ":", "default", ":", "$", "padding", "=", "str_repeat", "(", "$", "pad_string", ",", "ceil", "(", "$", "length", "/", "mb_strlen", "(", "$", "pad_string", ")", ")", ")", ";", "$", "output", "=", "$", "input", ".", "mb_substr", "(", "$", "padding", ",", "0", ",", "$", "length", ")", ";", "}", "}", "else", "{", "$", "output", "=", "$", "input", ";", "}", "return", "$", "output", ";", "}" ]
Pads a string in a UTF-8 safe way. @param string $input the string to pad. @param int $pad_length length in characters to pad to. @param string $pad_string string to use for padding. @param int $pad_type type of padding to use: <code>STR_PAD_LEFT</code>, <code>STR_PAD_RIGHT</code>, or <code>STR_PAD_BOTH</code>. @return string the padded string.
[ "Pads", "a", "string", "in", "a", "UTF", "-", "8", "safe", "way", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1336-L1385
33,818
silverorange/swat
Swat/SwatString.php
SwatString.toInteger
public static function toInteger($string) { $lc = localeconv(); $string = self::parseNegativeNotation($string); // change all locale formatting to numeric formatting $remove_parts = array( $lc['positive_sign'] => '', $lc['thousands_sep'] => '' ); $value = str_replace( array_keys($remove_parts), array_values($remove_parts), $string ); // note: This might be done better with a regexp, though // checking too closely how well a number matches its locale // formatting could become annoying too. i.e. if 1000 was // rejected because it wasn't formatted 1,000 if (is_numeric($value)) { if ($value > (float) PHP_INT_MAX) { throw new SwatException( 'Floating point value is too big to be an integer' ); } if ($value < (float) (-PHP_INT_MAX - 1)) { throw new SwatException( 'Floating point value is too small to be an integer' ); } $value = intval($value); } else { $value = null; } return $value; }
php
public static function toInteger($string) { $lc = localeconv(); $string = self::parseNegativeNotation($string); // change all locale formatting to numeric formatting $remove_parts = array( $lc['positive_sign'] => '', $lc['thousands_sep'] => '' ); $value = str_replace( array_keys($remove_parts), array_values($remove_parts), $string ); // note: This might be done better with a regexp, though // checking too closely how well a number matches its locale // formatting could become annoying too. i.e. if 1000 was // rejected because it wasn't formatted 1,000 if (is_numeric($value)) { if ($value > (float) PHP_INT_MAX) { throw new SwatException( 'Floating point value is too big to be an integer' ); } if ($value < (float) (-PHP_INT_MAX - 1)) { throw new SwatException( 'Floating point value is too small to be an integer' ); } $value = intval($value); } else { $value = null; } return $value; }
[ "public", "static", "function", "toInteger", "(", "$", "string", ")", "{", "$", "lc", "=", "localeconv", "(", ")", ";", "$", "string", "=", "self", "::", "parseNegativeNotation", "(", "$", "string", ")", ";", "// change all locale formatting to numeric formatting", "$", "remove_parts", "=", "array", "(", "$", "lc", "[", "'positive_sign'", "]", "=>", "''", ",", "$", "lc", "[", "'thousands_sep'", "]", "=>", "''", ")", ";", "$", "value", "=", "str_replace", "(", "array_keys", "(", "$", "remove_parts", ")", ",", "array_values", "(", "$", "remove_parts", ")", ",", "$", "string", ")", ";", "// note: This might be done better with a regexp, though", "// checking too closely how well a number matches its locale", "// formatting could become annoying too. i.e. if 1000 was", "// rejected because it wasn't formatted 1,000", "if", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "if", "(", "$", "value", ">", "(", "float", ")", "PHP_INT_MAX", ")", "{", "throw", "new", "SwatException", "(", "'Floating point value is too big to be an integer'", ")", ";", "}", "if", "(", "$", "value", "<", "(", "float", ")", "(", "-", "PHP_INT_MAX", "-", "1", ")", ")", "{", "throw", "new", "SwatException", "(", "'Floating point value is too small to be an integer'", ")", ";", "}", "$", "value", "=", "intval", "(", "$", "value", ")", ";", "}", "else", "{", "$", "value", "=", "null", ";", "}", "return", "$", "value", ";", "}" ]
Convert a locale-formatted number and return it as an integer. If the string can not be converted to an integer, the method returns null. If the number has values after the decimal point, the value is rounded according to the rounding rules for PHP's {@link http://php.net/manual/en/function.intval.php intval} function. If the number is too large to fit in PHP's integer range (depends on system architecture), an exception is thrown. @param string $string the string to convert. @return integer the converted value or null if it could not be converted. @throws SwatException if the converted number is too large to fit in an integer.
[ "Convert", "a", "locale", "-", "formatted", "number", "and", "return", "it", "as", "an", "integer", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1409-L1451
33,819
silverorange/swat
Swat/SwatString.php
SwatString.toFloat
public static function toFloat($string) { $lc = localeconv(); $string = self::parseNegativeNotation($string); // change all locale formatting to numeric formatting $remove_parts = array( $lc['decimal_point'] => '.', $lc['positive_sign'] => '', $lc['thousands_sep'] => '' ); $value = str_replace( array_keys($remove_parts), array_values($remove_parts), $string ); // note: This might be done better with a regexp, though // checking too closely how well a number matches its locale // formatting could become annoying too. i.e. if 1000 was // rejected because it wasn't formatted 1,000 return is_numeric($value) ? floatval($value) : null; }
php
public static function toFloat($string) { $lc = localeconv(); $string = self::parseNegativeNotation($string); // change all locale formatting to numeric formatting $remove_parts = array( $lc['decimal_point'] => '.', $lc['positive_sign'] => '', $lc['thousands_sep'] => '' ); $value = str_replace( array_keys($remove_parts), array_values($remove_parts), $string ); // note: This might be done better with a regexp, though // checking too closely how well a number matches its locale // formatting could become annoying too. i.e. if 1000 was // rejected because it wasn't formatted 1,000 return is_numeric($value) ? floatval($value) : null; }
[ "public", "static", "function", "toFloat", "(", "$", "string", ")", "{", "$", "lc", "=", "localeconv", "(", ")", ";", "$", "string", "=", "self", "::", "parseNegativeNotation", "(", "$", "string", ")", ";", "// change all locale formatting to numeric formatting", "$", "remove_parts", "=", "array", "(", "$", "lc", "[", "'decimal_point'", "]", "=>", "'.'", ",", "$", "lc", "[", "'positive_sign'", "]", "=>", "''", ",", "$", "lc", "[", "'thousands_sep'", "]", "=>", "''", ")", ";", "$", "value", "=", "str_replace", "(", "array_keys", "(", "$", "remove_parts", ")", ",", "array_values", "(", "$", "remove_parts", ")", ",", "$", "string", ")", ";", "// note: This might be done better with a regexp, though", "// checking too closely how well a number matches its locale", "// formatting could become annoying too. i.e. if 1000 was", "// rejected because it wasn't formatted 1,000", "return", "is_numeric", "(", "$", "value", ")", "?", "floatval", "(", "$", "value", ")", ":", "null", ";", "}" ]
Convert a locale-formatted number and return it as an float. If the string is not an float, the method returns null. @param string $string the string to convert. @return float The converted value.
[ "Convert", "a", "locale", "-", "formatted", "number", "and", "return", "it", "as", "an", "float", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1465-L1490
33,820
silverorange/swat
Swat/SwatString.php
SwatString.toList
public static function toList( $iterator, $conjunction = 'and', $delimiter = ', ', $display_final_delimiter = true ) { if (is_array($iterator)) { $iterator = new ArrayIterator($iterator); } if (!($iterator instanceof Iterator)) { throw new SwatException('Value is not an Iterator or array'); } if (count($iterator) === 1) { $iterator->rewind(); $list = $iterator->current(); } else { $count = 0; $list = ''; foreach ($iterator as $value) { if ($count != 0) { if ($count == count($iterator) - 1) { $list .= $display_final_delimiter && count($iterator) > 2 ? $delimiter : ' '; if ($conjunction != '') { $list .= $conjunction . ' '; } } else { $list .= $delimiter; } } $list .= $value; $count++; } } return $list; }
php
public static function toList( $iterator, $conjunction = 'and', $delimiter = ', ', $display_final_delimiter = true ) { if (is_array($iterator)) { $iterator = new ArrayIterator($iterator); } if (!($iterator instanceof Iterator)) { throw new SwatException('Value is not an Iterator or array'); } if (count($iterator) === 1) { $iterator->rewind(); $list = $iterator->current(); } else { $count = 0; $list = ''; foreach ($iterator as $value) { if ($count != 0) { if ($count == count($iterator) - 1) { $list .= $display_final_delimiter && count($iterator) > 2 ? $delimiter : ' '; if ($conjunction != '') { $list .= $conjunction . ' '; } } else { $list .= $delimiter; } } $list .= $value; $count++; } } return $list; }
[ "public", "static", "function", "toList", "(", "$", "iterator", ",", "$", "conjunction", "=", "'and'", ",", "$", "delimiter", "=", "', '", ",", "$", "display_final_delimiter", "=", "true", ")", "{", "if", "(", "is_array", "(", "$", "iterator", ")", ")", "{", "$", "iterator", "=", "new", "ArrayIterator", "(", "$", "iterator", ")", ";", "}", "if", "(", "!", "(", "$", "iterator", "instanceof", "Iterator", ")", ")", "{", "throw", "new", "SwatException", "(", "'Value is not an Iterator or array'", ")", ";", "}", "if", "(", "count", "(", "$", "iterator", ")", "===", "1", ")", "{", "$", "iterator", "->", "rewind", "(", ")", ";", "$", "list", "=", "$", "iterator", "->", "current", "(", ")", ";", "}", "else", "{", "$", "count", "=", "0", ";", "$", "list", "=", "''", ";", "foreach", "(", "$", "iterator", "as", "$", "value", ")", "{", "if", "(", "$", "count", "!=", "0", ")", "{", "if", "(", "$", "count", "==", "count", "(", "$", "iterator", ")", "-", "1", ")", "{", "$", "list", ".=", "$", "display_final_delimiter", "&&", "count", "(", "$", "iterator", ")", ">", "2", "?", "$", "delimiter", ":", "' '", ";", "if", "(", "$", "conjunction", "!=", "''", ")", "{", "$", "list", ".=", "$", "conjunction", ".", "' '", ";", "}", "}", "else", "{", "$", "list", ".=", "$", "delimiter", ";", "}", "}", "$", "list", ".=", "$", "value", ";", "$", "count", "++", ";", "}", "}", "return", "$", "list", ";", "}" ]
Convert an iterable object or array into a human-readable, delimited list. @param array|Iterator $iterator the object to convert to a list. @param string $conjunction the list's conjunction. Usually 'and' or 'or'. @param string $delimiter the list delimiter. If list items should additionally be padded with a space, the delimiter should also include the space. @param boolean $display_final_delimiter whether or not the final list item should be separated from the list with a delimiter. @return string The formatted list. @throws SwatException if the iterator value is not an array or Iterator @todo Think about using a mask to make this as flexible as possible for different locales.
[ "Convert", "an", "iterable", "object", "or", "array", "into", "a", "human", "-", "readable", "delimited", "list", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1516-L1559
33,821
silverorange/swat
Swat/SwatString.php
SwatString.getTimePeriodParts
public static function getTimePeriodParts($seconds, $interval_parts = null) { $interval = SwatDate::getIntervalFromSeconds($seconds); if ($interval_parts === null) { $interval_parts = SwatDate::DI_YEARS | SwatDate::DI_MONTHS | SwatDate::DI_DAYS | SwatDate::DI_HOURS | SwatDate::DI_MINUTES | SwatDate::DI_SECONDS; } // DateInterval cannot have overflow values for each part, so store // these in local variables. $years = $interval->y; $months = $interval->m; $days = $interval->d; $hours = $interval->h; $minutes = $interval->i; $seconds = $interval->s; $parts = array(); if ($years > 0) { if ($interval_parts & SwatDate::DI_YEARS) { $parts['years'] = $years; } else { // SwatDate::getIntervalFromSeconds() treats years as 365 days, // so convert back to days, not months. $days += $years * 365; } } // Since years are converted into days above, when building months, // and there are enough days to make at least one month, convert those // days into months, and leave the remainder in the days variable. if ($months > 0 || $days >= 30) { if ($interval_parts & SwatDate::DI_MONTHS) { $months += (int) floor($days / 30); $days = $days % 30; $parts['months'] = $months; } else { $days += $months * 30; } } if ($days > 0) { if ($interval_parts & SwatDate::DI_WEEKS && $days >= 7) { $weeks = (int) floor($days / 7); $days = $days % 7; $parts['weeks'] = $weeks; } if ($days > 0) { if ($interval_parts & SwatDate::DI_DAYS) { $parts['days'] = $days; } else { $hours += $days * 24; } } } if ($hours > 0) { if ($interval_parts & SwatDate::DI_HOURS) { $parts['hours'] = $hours; } else { $minutes += $hours * 60; } } if ($minutes > 0) { if ($interval_parts & SwatDate::DI_MINUTES) { $parts['minutes'] = $minutes; } else { $seconds += $minutes * 60; } } if ($seconds > 0) { if ($interval_parts & SwatDate::DI_SECONDS) { $parts['seconds'] = $seconds; } } return $parts; }
php
public static function getTimePeriodParts($seconds, $interval_parts = null) { $interval = SwatDate::getIntervalFromSeconds($seconds); if ($interval_parts === null) { $interval_parts = SwatDate::DI_YEARS | SwatDate::DI_MONTHS | SwatDate::DI_DAYS | SwatDate::DI_HOURS | SwatDate::DI_MINUTES | SwatDate::DI_SECONDS; } // DateInterval cannot have overflow values for each part, so store // these in local variables. $years = $interval->y; $months = $interval->m; $days = $interval->d; $hours = $interval->h; $minutes = $interval->i; $seconds = $interval->s; $parts = array(); if ($years > 0) { if ($interval_parts & SwatDate::DI_YEARS) { $parts['years'] = $years; } else { // SwatDate::getIntervalFromSeconds() treats years as 365 days, // so convert back to days, not months. $days += $years * 365; } } // Since years are converted into days above, when building months, // and there are enough days to make at least one month, convert those // days into months, and leave the remainder in the days variable. if ($months > 0 || $days >= 30) { if ($interval_parts & SwatDate::DI_MONTHS) { $months += (int) floor($days / 30); $days = $days % 30; $parts['months'] = $months; } else { $days += $months * 30; } } if ($days > 0) { if ($interval_parts & SwatDate::DI_WEEKS && $days >= 7) { $weeks = (int) floor($days / 7); $days = $days % 7; $parts['weeks'] = $weeks; } if ($days > 0) { if ($interval_parts & SwatDate::DI_DAYS) { $parts['days'] = $days; } else { $hours += $days * 24; } } } if ($hours > 0) { if ($interval_parts & SwatDate::DI_HOURS) { $parts['hours'] = $hours; } else { $minutes += $hours * 60; } } if ($minutes > 0) { if ($interval_parts & SwatDate::DI_MINUTES) { $parts['minutes'] = $minutes; } else { $seconds += $minutes * 60; } } if ($seconds > 0) { if ($interval_parts & SwatDate::DI_SECONDS) { $parts['seconds'] = $seconds; } } return $parts; }
[ "public", "static", "function", "getTimePeriodParts", "(", "$", "seconds", ",", "$", "interval_parts", "=", "null", ")", "{", "$", "interval", "=", "SwatDate", "::", "getIntervalFromSeconds", "(", "$", "seconds", ")", ";", "if", "(", "$", "interval_parts", "===", "null", ")", "{", "$", "interval_parts", "=", "SwatDate", "::", "DI_YEARS", "|", "SwatDate", "::", "DI_MONTHS", "|", "SwatDate", "::", "DI_DAYS", "|", "SwatDate", "::", "DI_HOURS", "|", "SwatDate", "::", "DI_MINUTES", "|", "SwatDate", "::", "DI_SECONDS", ";", "}", "// DateInterval cannot have overflow values for each part, so store", "// these in local variables.", "$", "years", "=", "$", "interval", "->", "y", ";", "$", "months", "=", "$", "interval", "->", "m", ";", "$", "days", "=", "$", "interval", "->", "d", ";", "$", "hours", "=", "$", "interval", "->", "h", ";", "$", "minutes", "=", "$", "interval", "->", "i", ";", "$", "seconds", "=", "$", "interval", "->", "s", ";", "$", "parts", "=", "array", "(", ")", ";", "if", "(", "$", "years", ">", "0", ")", "{", "if", "(", "$", "interval_parts", "&", "SwatDate", "::", "DI_YEARS", ")", "{", "$", "parts", "[", "'years'", "]", "=", "$", "years", ";", "}", "else", "{", "// SwatDate::getIntervalFromSeconds() treats years as 365 days,", "// so convert back to days, not months.", "$", "days", "+=", "$", "years", "*", "365", ";", "}", "}", "// Since years are converted into days above, when building months,", "// and there are enough days to make at least one month, convert those", "// days into months, and leave the remainder in the days variable.", "if", "(", "$", "months", ">", "0", "||", "$", "days", ">=", "30", ")", "{", "if", "(", "$", "interval_parts", "&", "SwatDate", "::", "DI_MONTHS", ")", "{", "$", "months", "+=", "(", "int", ")", "floor", "(", "$", "days", "/", "30", ")", ";", "$", "days", "=", "$", "days", "%", "30", ";", "$", "parts", "[", "'months'", "]", "=", "$", "months", ";", "}", "else", "{", "$", "days", "+=", "$", "months", "*", "30", ";", "}", "}", "if", "(", "$", "days", ">", "0", ")", "{", "if", "(", "$", "interval_parts", "&", "SwatDate", "::", "DI_WEEKS", "&&", "$", "days", ">=", "7", ")", "{", "$", "weeks", "=", "(", "int", ")", "floor", "(", "$", "days", "/", "7", ")", ";", "$", "days", "=", "$", "days", "%", "7", ";", "$", "parts", "[", "'weeks'", "]", "=", "$", "weeks", ";", "}", "if", "(", "$", "days", ">", "0", ")", "{", "if", "(", "$", "interval_parts", "&", "SwatDate", "::", "DI_DAYS", ")", "{", "$", "parts", "[", "'days'", "]", "=", "$", "days", ";", "}", "else", "{", "$", "hours", "+=", "$", "days", "*", "24", ";", "}", "}", "}", "if", "(", "$", "hours", ">", "0", ")", "{", "if", "(", "$", "interval_parts", "&", "SwatDate", "::", "DI_HOURS", ")", "{", "$", "parts", "[", "'hours'", "]", "=", "$", "hours", ";", "}", "else", "{", "$", "minutes", "+=", "$", "hours", "*", "60", ";", "}", "}", "if", "(", "$", "minutes", ">", "0", ")", "{", "if", "(", "$", "interval_parts", "&", "SwatDate", "::", "DI_MINUTES", ")", "{", "$", "parts", "[", "'minutes'", "]", "=", "$", "minutes", ";", "}", "else", "{", "$", "seconds", "+=", "$", "minutes", "*", "60", ";", "}", "}", "if", "(", "$", "seconds", ">", "0", ")", "{", "if", "(", "$", "interval_parts", "&", "SwatDate", "::", "DI_SECONDS", ")", "{", "$", "parts", "[", "'seconds'", "]", "=", "$", "seconds", ";", "}", "}", "return", "$", "parts", ";", "}" ]
Gets the parts representing a time period matching a desired interval format. This method splits an interval in seconds into component parts. Given an example value of 161740805, the following key=>value array is returned. <code> <?php array( 'years' => 5, 'months' => 3, 'days' => 2, 'seconds' => 5, ); ?> </code> As this method applies on seconds, no time zone considerations are made. Years are assumed to be 365 days. Months are assumed to be 30 days. @param integer $seconds seconds to format. @param integer $interval_parts inclusive or bitwise set of parts to return. @return array An array of time period parts.
[ "Gets", "the", "parts", "representing", "a", "time", "period", "matching", "a", "desired", "interval", "format", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1590-L1679
33,822
silverorange/swat
Swat/SwatString.php
SwatString.getHumanReadableTimePeriodParts
public static function getHumanReadableTimePeriodParts( $seconds, $interval_parts = null ) { // Depend on getTimePeriodParts() to return the correct parts requested $parts = static::getTimePeriodParts($seconds, $interval_parts); // Add human readable formatting to each returned part. if (isset($parts['years'])) { $years = $parts['years']; $parts['years'] = sprintf( Swat::ngettext('%s year', '%s years', $years), $years ); } if (isset($parts['months'])) { $months = $parts['months']; $parts['months'] = sprintf( Swat::ngettext('%s month', '%s months', $months), $months ); } if (isset($parts['weeks'])) { $weeks = $parts['weeks']; $parts['weeks'] = sprintf( Swat::ngettext('%s week', '%s weeks', $weeks), $weeks ); } if (isset($parts['days'])) { $days = $parts['days']; $parts['days'] = sprintf( Swat::ngettext('%s day', '%s days', $days), $days ); } if (isset($parts['hours'])) { $hours = $parts['hours']; $parts['hours'] = sprintf( Swat::ngettext('%s hour', '%s hours', $hours), $hours ); } if (isset($parts['minutes'])) { $minutes = $parts['minutes']; $parts['minutes'] = sprintf( Swat::ngettext('%s minute', '%s minutes', $minutes), $minutes ); } if (isset($parts['seconds'])) { $seconds = $parts['seconds']; $parts['seconds'] = sprintf( Swat::ngettext('%s second', '%s seconds', $seconds), $seconds ); } return $parts; }
php
public static function getHumanReadableTimePeriodParts( $seconds, $interval_parts = null ) { // Depend on getTimePeriodParts() to return the correct parts requested $parts = static::getTimePeriodParts($seconds, $interval_parts); // Add human readable formatting to each returned part. if (isset($parts['years'])) { $years = $parts['years']; $parts['years'] = sprintf( Swat::ngettext('%s year', '%s years', $years), $years ); } if (isset($parts['months'])) { $months = $parts['months']; $parts['months'] = sprintf( Swat::ngettext('%s month', '%s months', $months), $months ); } if (isset($parts['weeks'])) { $weeks = $parts['weeks']; $parts['weeks'] = sprintf( Swat::ngettext('%s week', '%s weeks', $weeks), $weeks ); } if (isset($parts['days'])) { $days = $parts['days']; $parts['days'] = sprintf( Swat::ngettext('%s day', '%s days', $days), $days ); } if (isset($parts['hours'])) { $hours = $parts['hours']; $parts['hours'] = sprintf( Swat::ngettext('%s hour', '%s hours', $hours), $hours ); } if (isset($parts['minutes'])) { $minutes = $parts['minutes']; $parts['minutes'] = sprintf( Swat::ngettext('%s minute', '%s minutes', $minutes), $minutes ); } if (isset($parts['seconds'])) { $seconds = $parts['seconds']; $parts['seconds'] = sprintf( Swat::ngettext('%s second', '%s seconds', $seconds), $seconds ); } return $parts; }
[ "public", "static", "function", "getHumanReadableTimePeriodParts", "(", "$", "seconds", ",", "$", "interval_parts", "=", "null", ")", "{", "// Depend on getTimePeriodParts() to return the correct parts requested", "$", "parts", "=", "static", "::", "getTimePeriodParts", "(", "$", "seconds", ",", "$", "interval_parts", ")", ";", "// Add human readable formatting to each returned part.", "if", "(", "isset", "(", "$", "parts", "[", "'years'", "]", ")", ")", "{", "$", "years", "=", "$", "parts", "[", "'years'", "]", ";", "$", "parts", "[", "'years'", "]", "=", "sprintf", "(", "Swat", "::", "ngettext", "(", "'%s year'", ",", "'%s years'", ",", "$", "years", ")", ",", "$", "years", ")", ";", "}", "if", "(", "isset", "(", "$", "parts", "[", "'months'", "]", ")", ")", "{", "$", "months", "=", "$", "parts", "[", "'months'", "]", ";", "$", "parts", "[", "'months'", "]", "=", "sprintf", "(", "Swat", "::", "ngettext", "(", "'%s month'", ",", "'%s months'", ",", "$", "months", ")", ",", "$", "months", ")", ";", "}", "if", "(", "isset", "(", "$", "parts", "[", "'weeks'", "]", ")", ")", "{", "$", "weeks", "=", "$", "parts", "[", "'weeks'", "]", ";", "$", "parts", "[", "'weeks'", "]", "=", "sprintf", "(", "Swat", "::", "ngettext", "(", "'%s week'", ",", "'%s weeks'", ",", "$", "weeks", ")", ",", "$", "weeks", ")", ";", "}", "if", "(", "isset", "(", "$", "parts", "[", "'days'", "]", ")", ")", "{", "$", "days", "=", "$", "parts", "[", "'days'", "]", ";", "$", "parts", "[", "'days'", "]", "=", "sprintf", "(", "Swat", "::", "ngettext", "(", "'%s day'", ",", "'%s days'", ",", "$", "days", ")", ",", "$", "days", ")", ";", "}", "if", "(", "isset", "(", "$", "parts", "[", "'hours'", "]", ")", ")", "{", "$", "hours", "=", "$", "parts", "[", "'hours'", "]", ";", "$", "parts", "[", "'hours'", "]", "=", "sprintf", "(", "Swat", "::", "ngettext", "(", "'%s hour'", ",", "'%s hours'", ",", "$", "hours", ")", ",", "$", "hours", ")", ";", "}", "if", "(", "isset", "(", "$", "parts", "[", "'minutes'", "]", ")", ")", "{", "$", "minutes", "=", "$", "parts", "[", "'minutes'", "]", ";", "$", "parts", "[", "'minutes'", "]", "=", "sprintf", "(", "Swat", "::", "ngettext", "(", "'%s minute'", ",", "'%s minutes'", ",", "$", "minutes", ")", ",", "$", "minutes", ")", ";", "}", "if", "(", "isset", "(", "$", "parts", "[", "'seconds'", "]", ")", ")", "{", "$", "seconds", "=", "$", "parts", "[", "'seconds'", "]", ";", "$", "parts", "[", "'seconds'", "]", "=", "sprintf", "(", "Swat", "::", "ngettext", "(", "'%s second'", ",", "'%s seconds'", ",", "$", "seconds", ")", ",", "$", "seconds", ")", ";", "}", "return", "$", "parts", ";", "}" ]
Gets the parts to construct a human-readable string representing a time period. This method formats seconds as a time period. Given an example value of 161740805, the following key=>value array is returned. <code> <?php array( 'years' => '5 years', 'months' => '3 months', 'days' => '2 days', 'seconds' => '5 seconds', ); ?> </code> As this method applies on seconds, no time zone considerations are made. Years are assumed to be 365 days. Months are assumed to be 30 days. @param integer $seconds seconds to format. @param integer $interval_parts inclusive or bitwise set of parts to return. @return array An array of human-readable time period string parts.
[ "Gets", "the", "parts", "to", "construct", "a", "human", "-", "readable", "string", "representing", "a", "time", "period", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1710-L1775
33,823
silverorange/swat
Swat/SwatString.php
SwatString.toHumanReadableTimePeriod
public static function toHumanReadableTimePeriod( $seconds, $largest_part = false ) { $parts = self::getHumanReadableTimePeriodParts($seconds); return self::toHumanReadableTimePeriodString($parts, $largest_part); }
php
public static function toHumanReadableTimePeriod( $seconds, $largest_part = false ) { $parts = self::getHumanReadableTimePeriodParts($seconds); return self::toHumanReadableTimePeriodString($parts, $largest_part); }
[ "public", "static", "function", "toHumanReadableTimePeriod", "(", "$", "seconds", ",", "$", "largest_part", "=", "false", ")", "{", "$", "parts", "=", "self", "::", "getHumanReadableTimePeriodParts", "(", "$", "seconds", ")", ";", "return", "self", "::", "toHumanReadableTimePeriodString", "(", "$", "parts", ",", "$", "largest_part", ")", ";", "}" ]
Gets a human-readable string representing a time period This method formats seconds as a time period. Given an example value of 161740805, the formatted value "5 years, 3 months, 2 days and 5 seconds" is returned. As this method applies on seconds, no time zone considerations are made. Years are assumed to be 365 days. Months are assumed to be 30 days. @param integer $seconds seconds to format. @param boolean $largest_part optional. If true, only the largest matching date part is returned. For the above example, "5 years" is returned. @return string A human-readable time period.
[ "Gets", "a", "human", "-", "readable", "string", "representing", "a", "time", "period" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1797-L1803
33,824
silverorange/swat
Swat/SwatString.php
SwatString.toHumanReadableTimePeriodWithWeeks
public static function toHumanReadableTimePeriodWithWeeks( $seconds, $largest_part = false ) { $interval_parts = SwatDate::DI_YEARS | SwatDate::DI_WEEKS | SwatDate::DI_DAYS | SwatDate::DI_HOURS | SwatDate::DI_MINUTES | SwatDate::DI_SECONDS; $parts = self::getHumanReadableTimePeriodParts( $seconds, $interval_parts ); return self::toHumanReadableTimePeriodString($parts, $largest_part); }
php
public static function toHumanReadableTimePeriodWithWeeks( $seconds, $largest_part = false ) { $interval_parts = SwatDate::DI_YEARS | SwatDate::DI_WEEKS | SwatDate::DI_DAYS | SwatDate::DI_HOURS | SwatDate::DI_MINUTES | SwatDate::DI_SECONDS; $parts = self::getHumanReadableTimePeriodParts( $seconds, $interval_parts ); return self::toHumanReadableTimePeriodString($parts, $largest_part); }
[ "public", "static", "function", "toHumanReadableTimePeriodWithWeeks", "(", "$", "seconds", ",", "$", "largest_part", "=", "false", ")", "{", "$", "interval_parts", "=", "SwatDate", "::", "DI_YEARS", "|", "SwatDate", "::", "DI_WEEKS", "|", "SwatDate", "::", "DI_DAYS", "|", "SwatDate", "::", "DI_HOURS", "|", "SwatDate", "::", "DI_MINUTES", "|", "SwatDate", "::", "DI_SECONDS", ";", "$", "parts", "=", "self", "::", "getHumanReadableTimePeriodParts", "(", "$", "seconds", ",", "$", "interval_parts", ")", ";", "return", "self", "::", "toHumanReadableTimePeriodString", "(", "$", "parts", ",", "$", "largest_part", ")", ";", "}" ]
Gets a human-readable string representing a time period that includes weeks. This method formats seconds as a time period. Given an example value of 161740805, the formatted value "5 years, 12 weeks, 2 days and 5 seconds" is returned. Months are not returned as combining months and weeks in the same string can be confusing for people to parse. As this method applies on seconds, no time zone considerations are made. Years are assumed to be 365 days. Months are assumed to be 30 days. @param integer $seconds seconds to format. @param boolean $largest_part optional. If true, only the largest matching date part is returned. For the above example, "5 years" is returned. @return string A human-readable time period.
[ "Gets", "a", "human", "-", "readable", "string", "representing", "a", "time", "period", "that", "includes", "weeks", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1827-L1845
33,825
silverorange/swat
Swat/SwatString.php
SwatString.toHumanReadableTimePeriodWithWeeksAndDays
public static function toHumanReadableTimePeriodWithWeeksAndDays($seconds) { $interval_parts = SwatDate::DI_YEARS | SwatDate::DI_WEEKS | SwatDate::DI_DAYS | SwatDate::DI_HOURS | SwatDate::DI_MINUTES | SwatDate::DI_SECONDS; $parts = self::getHumanReadableTimePeriodParts( $seconds, $interval_parts ); if (isset($parts['weeks']) && isset($parts['days'])) { // reuse the weeks array key, to keep it in the correct position. $parts['weeks'] = self::toList(array( $parts['weeks'], $parts['days'] )); unset($parts['days']); } return self::toHumanReadableTimePeriodString($parts, true); }
php
public static function toHumanReadableTimePeriodWithWeeksAndDays($seconds) { $interval_parts = SwatDate::DI_YEARS | SwatDate::DI_WEEKS | SwatDate::DI_DAYS | SwatDate::DI_HOURS | SwatDate::DI_MINUTES | SwatDate::DI_SECONDS; $parts = self::getHumanReadableTimePeriodParts( $seconds, $interval_parts ); if (isset($parts['weeks']) && isset($parts['days'])) { // reuse the weeks array key, to keep it in the correct position. $parts['weeks'] = self::toList(array( $parts['weeks'], $parts['days'] )); unset($parts['days']); } return self::toHumanReadableTimePeriodString($parts, true); }
[ "public", "static", "function", "toHumanReadableTimePeriodWithWeeksAndDays", "(", "$", "seconds", ")", "{", "$", "interval_parts", "=", "SwatDate", "::", "DI_YEARS", "|", "SwatDate", "::", "DI_WEEKS", "|", "SwatDate", "::", "DI_DAYS", "|", "SwatDate", "::", "DI_HOURS", "|", "SwatDate", "::", "DI_MINUTES", "|", "SwatDate", "::", "DI_SECONDS", ";", "$", "parts", "=", "self", "::", "getHumanReadableTimePeriodParts", "(", "$", "seconds", ",", "$", "interval_parts", ")", ";", "if", "(", "isset", "(", "$", "parts", "[", "'weeks'", "]", ")", "&&", "isset", "(", "$", "parts", "[", "'days'", "]", ")", ")", "{", "// reuse the weeks array key, to keep it in the correct position.", "$", "parts", "[", "'weeks'", "]", "=", "self", "::", "toList", "(", "array", "(", "$", "parts", "[", "'weeks'", "]", ",", "$", "parts", "[", "'days'", "]", ")", ")", ";", "unset", "(", "$", "parts", "[", "'days'", "]", ")", ";", "}", "return", "self", "::", "toHumanReadableTimePeriodString", "(", "$", "parts", ",", "true", ")", ";", "}" ]
Gets a human-readable string representing a time period that includes weeks and days as one time period part, and always returns the largest part only. This method formats seconds as a time period. Given an example value of 7435400, the formatted value "12 weeks, 2 days" is returned. As this method applies on seconds, no time zone considerations are made. Years are assumed to be 365 days. Months are assumed to be 30 days. @param integer $seconds seconds to format. @return string A human-readable time period.
[ "Gets", "a", "human", "-", "readable", "string", "representing", "a", "time", "period", "that", "includes", "weeks", "and", "days", "as", "one", "time", "period", "part", "and", "always", "returns", "the", "largest", "part", "only", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1865-L1891
33,826
silverorange/swat
Swat/SwatString.php
SwatString.hash
public static function hash($string) { $hash = md5($string, true); $hash = base64_encode($hash); // remove padding characters $hash = str_replace('=', '', $hash); // use modified Base64 for URL varient $hash = str_replace('+', '*', $hash); $hash = str_replace('/', '-', $hash); return $hash; }
php
public static function hash($string) { $hash = md5($string, true); $hash = base64_encode($hash); // remove padding characters $hash = str_replace('=', '', $hash); // use modified Base64 for URL varient $hash = str_replace('+', '*', $hash); $hash = str_replace('/', '-', $hash); return $hash; }
[ "public", "static", "function", "hash", "(", "$", "string", ")", "{", "$", "hash", "=", "md5", "(", "$", "string", ",", "true", ")", ";", "$", "hash", "=", "base64_encode", "(", "$", "hash", ")", ";", "// remove padding characters", "$", "hash", "=", "str_replace", "(", "'='", ",", "''", ",", "$", "hash", ")", ";", "// use modified Base64 for URL varient", "$", "hash", "=", "str_replace", "(", "'+'", ",", "'*'", ",", "$", "hash", ")", ";", "$", "hash", "=", "str_replace", "(", "'/'", ",", "'-'", ",", "$", "hash", ")", ";", "return", "$", "hash", ";", "}" ]
Gets a unique hash of a string The hashing is as unique as md5 but the hash string is shorter than md5. This method is useful if hash strings will be visible to end-users and shorter hash strings are desired. @param string $string the string to get the unique hash for. @return string the unique hash of the given string. The returned string is safe to use inside a URI.
[ "Gets", "a", "unique", "hash", "of", "a", "string" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1908-L1921
33,827
silverorange/swat
Swat/SwatString.php
SwatString.getSalt
public static function getSalt($length) { $salt = ''; for ($i = 0; $i < $length; $i++) { $salt .= chr(mt_rand(1, 127)); } return $salt; }
php
public static function getSalt($length) { $salt = ''; for ($i = 0; $i < $length; $i++) { $salt .= chr(mt_rand(1, 127)); } return $salt; }
[ "public", "static", "function", "getSalt", "(", "$", "length", ")", "{", "$", "salt", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "salt", ".=", "chr", "(", "mt_rand", "(", "1", ",", "127", ")", ")", ";", "}", "return", "$", "salt", ";", "}" ]
Gets a salt value of the specified length Useful for securing passwords or other one-way encrypted fields that may be succeptable to a dictionary attack. This method generates a random ASCII string of the specified length. All ASCII characters except the null character (0x00) may be included in the returned string. @param integer $length the desired length of the salt. @return string a salt value of the specified length.
[ "Gets", "a", "salt", "value", "of", "the", "specified", "length" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L1940-L1948
33,828
silverorange/swat
Swat/SwatString.php
SwatString.signedSerialize
public static function signedSerialize($data, $salt) { $serialized_data = serialize($data); $signature_data = self::hash($serialized_data . (string) $salt); return $signature_data . '|' . $serialized_data; }
php
public static function signedSerialize($data, $salt) { $serialized_data = serialize($data); $signature_data = self::hash($serialized_data . (string) $salt); return $signature_data . '|' . $serialized_data; }
[ "public", "static", "function", "signedSerialize", "(", "$", "data", ",", "$", "salt", ")", "{", "$", "serialized_data", "=", "serialize", "(", "$", "data", ")", ";", "$", "signature_data", "=", "self", "::", "hash", "(", "$", "serialized_data", ".", "(", "string", ")", "$", "salt", ")", ";", "return", "$", "signature_data", ".", "'|'", ".", "$", "serialized_data", ";", "}" ]
Serializes and signs a value using a salt By signing serialized data, it is possible to detect tampering of serialized data. This is useful if serialized data is accepted from user editable <code>$_GET</code>, <code>$_POST</code> or <code>$_COOKIE data</code>. @param mixed $data the data to serialize. @param string $salt the signature salt. @return string the signed serialized value. @see SwatString::signedSerialize()
[ "Serializes", "and", "signs", "a", "value", "using", "a", "salt" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L2052-L2058
33,829
silverorange/swat
Swat/SwatString.php
SwatString.signedUnserialize
public static function signedUnserialize($data, $salt) { $data_exp = explode('|', (string) $data, 2); if (count($data_exp) != 2) { throw new SwatInvalidSerializedDataException( "Invalid signed serialized data '{$data}'.", 0, $data ); } $signature_data = $data_exp[0]; $serialized_data = $data_exp[1]; if (self::hash($serialized_data . (string) $salt) != $signature_data) { throw new SwatInvalidSerializedDataException( "Invalid signed serialized data '{$data}'.", 0, $data ); } return unserialize($serialized_data); }
php
public static function signedUnserialize($data, $salt) { $data_exp = explode('|', (string) $data, 2); if (count($data_exp) != 2) { throw new SwatInvalidSerializedDataException( "Invalid signed serialized data '{$data}'.", 0, $data ); } $signature_data = $data_exp[0]; $serialized_data = $data_exp[1]; if (self::hash($serialized_data . (string) $salt) != $signature_data) { throw new SwatInvalidSerializedDataException( "Invalid signed serialized data '{$data}'.", 0, $data ); } return unserialize($serialized_data); }
[ "public", "static", "function", "signedUnserialize", "(", "$", "data", ",", "$", "salt", ")", "{", "$", "data_exp", "=", "explode", "(", "'|'", ",", "(", "string", ")", "$", "data", ",", "2", ")", ";", "if", "(", "count", "(", "$", "data_exp", ")", "!=", "2", ")", "{", "throw", "new", "SwatInvalidSerializedDataException", "(", "\"Invalid signed serialized data '{$data}'.\"", ",", "0", ",", "$", "data", ")", ";", "}", "$", "signature_data", "=", "$", "data_exp", "[", "0", "]", ";", "$", "serialized_data", "=", "$", "data_exp", "[", "1", "]", ";", "if", "(", "self", "::", "hash", "(", "$", "serialized_data", ".", "(", "string", ")", "$", "salt", ")", "!=", "$", "signature_data", ")", "{", "throw", "new", "SwatInvalidSerializedDataException", "(", "\"Invalid signed serialized data '{$data}'.\"", ",", "0", ",", "$", "data", ")", ";", "}", "return", "unserialize", "(", "$", "serialized_data", ")", ";", "}" ]
Unserializes a signed serialized value @param string $data the signed serialized data. @param string $salt the signature salt. This must be the same salt value used to serialize the value. @return mixed the unserialized value. @throws SwatInvalidSerializedDataException if the signed serialized data has been tampered with. @see SwatString::signedSerialize()
[ "Unserializes", "a", "signed", "serialized", "value" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L2077-L2101
33,830
silverorange/swat
Swat/SwatString.php
SwatString.quoteJavaScriptString
public static function quoteJavaScriptString($string) { $search = array( '\\', // backslash quote '&', // ampersand '<', // less than '>', // greater than '=', // equal '"', // double quote "'", // single quote "\t", // tab "\r\n", // line ending (Windows) "\r", // carriage return "\n", // line feed "\xc2\x85", // next line "\xe2\x80\xa8", // line separator "\xe2\x80\xa9" // paragraph separator ); $replace = array( '\\\\', // backslash quote '\x26', // ampersand '\x3c', // less than '\x3e', // greater than '\x3d', // equal '\x22', // double quote '\x27', // single quote '\t', // tab '\n', // line ending (Windows, transformed to line feed) '\n', // carriage return (transformed to line feed) '\n', // line feed '\u0085', // next line '\u2028', // line separator '\u2029' // paragraph separator ); // escape XSS vectors $string = str_replace($search, $replace, $string); // quote string $string = "'" . $string . "'"; return $string; }
php
public static function quoteJavaScriptString($string) { $search = array( '\\', // backslash quote '&', // ampersand '<', // less than '>', // greater than '=', // equal '"', // double quote "'", // single quote "\t", // tab "\r\n", // line ending (Windows) "\r", // carriage return "\n", // line feed "\xc2\x85", // next line "\xe2\x80\xa8", // line separator "\xe2\x80\xa9" // paragraph separator ); $replace = array( '\\\\', // backslash quote '\x26', // ampersand '\x3c', // less than '\x3e', // greater than '\x3d', // equal '\x22', // double quote '\x27', // single quote '\t', // tab '\n', // line ending (Windows, transformed to line feed) '\n', // carriage return (transformed to line feed) '\n', // line feed '\u0085', // next line '\u2028', // line separator '\u2029' // paragraph separator ); // escape XSS vectors $string = str_replace($search, $replace, $string); // quote string $string = "'" . $string . "'"; return $string; }
[ "public", "static", "function", "quoteJavaScriptString", "(", "$", "string", ")", "{", "$", "search", "=", "array", "(", "'\\\\'", ",", "// backslash quote", "'&'", ",", "// ampersand", "'<'", ",", "// less than", "'>'", ",", "// greater than", "'='", ",", "// equal", "'\"'", ",", "// double quote", "\"'\"", ",", "// single quote", "\"\\t\"", ",", "// tab", "\"\\r\\n\"", ",", "// line ending (Windows)", "\"\\r\"", ",", "// carriage return", "\"\\n\"", ",", "// line feed", "\"\\xc2\\x85\"", ",", "// next line", "\"\\xe2\\x80\\xa8\"", ",", "// line separator", "\"\\xe2\\x80\\xa9\"", "// paragraph separator", ")", ";", "$", "replace", "=", "array", "(", "'\\\\\\\\'", ",", "// backslash quote", "'\\x26'", ",", "// ampersand", "'\\x3c'", ",", "// less than", "'\\x3e'", ",", "// greater than", "'\\x3d'", ",", "// equal", "'\\x22'", ",", "// double quote", "'\\x27'", ",", "// single quote", "'\\t'", ",", "// tab", "'\\n'", ",", "// line ending (Windows, transformed to line feed)", "'\\n'", ",", "// carriage return (transformed to line feed)", "'\\n'", ",", "// line feed", "'\\u0085'", ",", "// next line", "'\\u2028'", ",", "// line separator", "'\\u2029'", "// paragraph separator", ")", ";", "// escape XSS vectors", "$", "string", "=", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "string", ")", ";", "// quote string", "$", "string", "=", "\"'\"", ".", "$", "string", ".", "\"'\"", ";", "return", "$", "string", ";", "}" ]
Safely quotes a PHP string into a JavaScript string Strings are always quoted using single quotes. The characters documented at {@link http://code.google.com/p/doctype/wiki/ArticleXSSInJavaScript} are escaped to prevent XSS attacks. @param string $string the PHP string to quote as a JavaScript string. @return string the quoted JavaScript string. The quoted string is wrapped in single quotation marks and is safe to display in inline JavaScript.
[ "Safely", "quotes", "a", "PHP", "string", "into", "a", "JavaScript", "string" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L2119-L2162
33,831
silverorange/swat
Swat/SwatString.php
SwatString.escapeBinary
public static function escapeBinary($string) { $escaped = ''; for ($i = 0; $i < mb_strlen($string, '8bit'); $i++) { $char = mb_substr($string, $i, 1, '8bit'); $ord = ord($char); if ($ord === 9) { $escaped .= '\t'; } elseif ($ord === 10) { $escaped .= '\n'; } elseif ($ord === 13) { $escaped .= '\r'; } elseif ($ord === 92) { $escaped .= '\\\\'; } elseif ($ord < 16) { $escaped .= '\x0' . mb_strtoupper(dechex($ord)); } elseif ($ord < 32 || $ord >= 127) { $escaped .= '\x' . mb_strtoupper(dechex($ord)); } else { $escaped .= $char; } } return $escaped; }
php
public static function escapeBinary($string) { $escaped = ''; for ($i = 0; $i < mb_strlen($string, '8bit'); $i++) { $char = mb_substr($string, $i, 1, '8bit'); $ord = ord($char); if ($ord === 9) { $escaped .= '\t'; } elseif ($ord === 10) { $escaped .= '\n'; } elseif ($ord === 13) { $escaped .= '\r'; } elseif ($ord === 92) { $escaped .= '\\\\'; } elseif ($ord < 16) { $escaped .= '\x0' . mb_strtoupper(dechex($ord)); } elseif ($ord < 32 || $ord >= 127) { $escaped .= '\x' . mb_strtoupper(dechex($ord)); } else { $escaped .= $char; } } return $escaped; }
[ "public", "static", "function", "escapeBinary", "(", "$", "string", ")", "{", "$", "escaped", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "mb_strlen", "(", "$", "string", ",", "'8bit'", ")", ";", "$", "i", "++", ")", "{", "$", "char", "=", "mb_substr", "(", "$", "string", ",", "$", "i", ",", "1", ",", "'8bit'", ")", ";", "$", "ord", "=", "ord", "(", "$", "char", ")", ";", "if", "(", "$", "ord", "===", "9", ")", "{", "$", "escaped", ".=", "'\\t'", ";", "}", "elseif", "(", "$", "ord", "===", "10", ")", "{", "$", "escaped", ".=", "'\\n'", ";", "}", "elseif", "(", "$", "ord", "===", "13", ")", "{", "$", "escaped", ".=", "'\\r'", ";", "}", "elseif", "(", "$", "ord", "===", "92", ")", "{", "$", "escaped", ".=", "'\\\\\\\\'", ";", "}", "elseif", "(", "$", "ord", "<", "16", ")", "{", "$", "escaped", ".=", "'\\x0'", ".", "mb_strtoupper", "(", "dechex", "(", "$", "ord", ")", ")", ";", "}", "elseif", "(", "$", "ord", "<", "32", "||", "$", "ord", ">=", "127", ")", "{", "$", "escaped", ".=", "'\\x'", ".", "mb_strtoupper", "(", "dechex", "(", "$", "ord", ")", ")", ";", "}", "else", "{", "$", "escaped", ".=", "$", "char", ";", "}", "}", "return", "$", "escaped", ";", "}" ]
Escapes a binary string making it safe to display using ASCII encoding Newlines, tabs and returns are encoded as \n, \t and \r. Other bytes are hexadecimal encoded (e.g. \xA6). Escaping the binary string makes it valid UTF-8 as well as valid ASCII. @param string $string the string to escape. @return string the escaped, ASCII encoded string.
[ "Escapes", "a", "binary", "string", "making", "it", "safe", "to", "display", "using", "ASCII", "encoding" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L2226-L2251
33,832
silverorange/swat
Swat/SwatString.php
SwatString.toHumanReadableTimePeriodString
protected static function toHumanReadableTimePeriodString( array $parts, $largest_part = false ) { if ($largest_part && count($parts) > 0) { $parts = array(reset($parts)); } return self::toList($parts); }
php
protected static function toHumanReadableTimePeriodString( array $parts, $largest_part = false ) { if ($largest_part && count($parts) > 0) { $parts = array(reset($parts)); } return self::toList($parts); }
[ "protected", "static", "function", "toHumanReadableTimePeriodString", "(", "array", "$", "parts", ",", "$", "largest_part", "=", "false", ")", "{", "if", "(", "$", "largest_part", "&&", "count", "(", "$", "parts", ")", ">", "0", ")", "{", "$", "parts", "=", "array", "(", "reset", "(", "$", "parts", ")", ")", ";", "}", "return", "self", "::", "toList", "(", "$", "parts", ")", ";", "}" ]
Gets a human-readable string representing a time period from an array of human readable date parts. This method formats seconds as a time period. Given an example value of 161740805, the formatted value "5 years, 3 months, 2 days and 5 seconds" is returned. As this method applies on seconds, no time zone considerations are made. Years are assumed to be 365 days. Months are assumed to be 30 days. @param array $parts array of date period parts. @see SwatString::getHumanReadableTimePeriodParts() @param boolean $largest_part optional. If true, only the largest matching date part is returned. For the above example, "5 years" is returned. @return string A human-readable time period.
[ "Gets", "a", "human", "-", "readable", "string", "representing", "a", "time", "period", "from", "an", "array", "of", "human", "readable", "date", "parts", "." ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L2275-L2284
33,833
silverorange/swat
Swat/SwatString.php
SwatString.stripEntities
private static function stripEntities(&$string, &$matches) { $reg_exp = '/&#?[a-z0-9]*?;/su'; preg_match_all($reg_exp, $string, $matches, PREG_OFFSET_CAPTURE); $string = preg_replace($reg_exp, '*', $string); }
php
private static function stripEntities(&$string, &$matches) { $reg_exp = '/&#?[a-z0-9]*?;/su'; preg_match_all($reg_exp, $string, $matches, PREG_OFFSET_CAPTURE); $string = preg_replace($reg_exp, '*', $string); }
[ "private", "static", "function", "stripEntities", "(", "&", "$", "string", ",", "&", "$", "matches", ")", "{", "$", "reg_exp", "=", "'/&#?[a-z0-9]*?;/su'", ";", "preg_match_all", "(", "$", "reg_exp", ",", "$", "string", ",", "$", "matches", ",", "PREG_OFFSET_CAPTURE", ")", ";", "$", "string", "=", "preg_replace", "(", "$", "reg_exp", ",", "'*'", ",", "$", "string", ")", ";", "}" ]
Strips entities from a string remembering their positions Stripped entities are replaces with a single special character. All parameters are passed by reference and nothing is returned by this function. @param string $string the string to strip entites from. @param array $matches the array to store matches in.
[ "Strips", "entities", "from", "a", "string", "remembering", "their", "positions" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L2299-L2306
33,834
silverorange/swat
Swat/SwatString.php
SwatString.insertEntities
private static function insertEntities( &$string, &$matches, $hole_start = -1, $hole_end = -1, $hole_length = 0 ) { for ($i = 0; $i < count($matches[0]); $i++) { $entity = $matches[0][$i][0]; $position = $matches[0][$i][1]; // offsets are byte offsets, not character offsets $substr = mb_substr($string, 0, $position, '8bit'); $byte_len = mb_strlen($substr, '8bit'); $char_len = mb_strlen($substr); $position -= $byte_len - $char_len; if ($position < $hole_start) { // this entity falls before the hole $string = mb_substr($string, 0, $position) . $entity . mb_substr($string, $position + 1); $hole_start += mb_strlen($entity); $hole_end += mb_strlen($entity); } elseif ($hole_end <= $hole_start) { // break here because all remaining entities fall in the hole // extending infinitely to the right break; } elseif ($position >= $hole_end) { // this entity falls after the hole $offset = -$hole_end + $hole_length + $hole_start + 1; $string = mb_substr($string, 0, $position + $offset) . $entity . mb_substr($string, $position + $offset + 1); } else { // this entity falls in the hole but we must account // for its unused size $hole_end += mb_strlen($entity); } } }
php
private static function insertEntities( &$string, &$matches, $hole_start = -1, $hole_end = -1, $hole_length = 0 ) { for ($i = 0; $i < count($matches[0]); $i++) { $entity = $matches[0][$i][0]; $position = $matches[0][$i][1]; // offsets are byte offsets, not character offsets $substr = mb_substr($string, 0, $position, '8bit'); $byte_len = mb_strlen($substr, '8bit'); $char_len = mb_strlen($substr); $position -= $byte_len - $char_len; if ($position < $hole_start) { // this entity falls before the hole $string = mb_substr($string, 0, $position) . $entity . mb_substr($string, $position + 1); $hole_start += mb_strlen($entity); $hole_end += mb_strlen($entity); } elseif ($hole_end <= $hole_start) { // break here because all remaining entities fall in the hole // extending infinitely to the right break; } elseif ($position >= $hole_end) { // this entity falls after the hole $offset = -$hole_end + $hole_length + $hole_start + 1; $string = mb_substr($string, 0, $position + $offset) . $entity . mb_substr($string, $position + $offset + 1); } else { // this entity falls in the hole but we must account // for its unused size $hole_end += mb_strlen($entity); } } }
[ "private", "static", "function", "insertEntities", "(", "&", "$", "string", ",", "&", "$", "matches", ",", "$", "hole_start", "=", "-", "1", ",", "$", "hole_end", "=", "-", "1", ",", "$", "hole_length", "=", "0", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "matches", "[", "0", "]", ")", ";", "$", "i", "++", ")", "{", "$", "entity", "=", "$", "matches", "[", "0", "]", "[", "$", "i", "]", "[", "0", "]", ";", "$", "position", "=", "$", "matches", "[", "0", "]", "[", "$", "i", "]", "[", "1", "]", ";", "// offsets are byte offsets, not character offsets", "$", "substr", "=", "mb_substr", "(", "$", "string", ",", "0", ",", "$", "position", ",", "'8bit'", ")", ";", "$", "byte_len", "=", "mb_strlen", "(", "$", "substr", ",", "'8bit'", ")", ";", "$", "char_len", "=", "mb_strlen", "(", "$", "substr", ")", ";", "$", "position", "-=", "$", "byte_len", "-", "$", "char_len", ";", "if", "(", "$", "position", "<", "$", "hole_start", ")", "{", "// this entity falls before the hole", "$", "string", "=", "mb_substr", "(", "$", "string", ",", "0", ",", "$", "position", ")", ".", "$", "entity", ".", "mb_substr", "(", "$", "string", ",", "$", "position", "+", "1", ")", ";", "$", "hole_start", "+=", "mb_strlen", "(", "$", "entity", ")", ";", "$", "hole_end", "+=", "mb_strlen", "(", "$", "entity", ")", ";", "}", "elseif", "(", "$", "hole_end", "<=", "$", "hole_start", ")", "{", "// break here because all remaining entities fall in the hole", "// extending infinitely to the right", "break", ";", "}", "elseif", "(", "$", "position", ">=", "$", "hole_end", ")", "{", "// this entity falls after the hole", "$", "offset", "=", "-", "$", "hole_end", "+", "$", "hole_length", "+", "$", "hole_start", "+", "1", ";", "$", "string", "=", "mb_substr", "(", "$", "string", ",", "0", ",", "$", "position", "+", "$", "offset", ")", ".", "$", "entity", ".", "mb_substr", "(", "$", "string", ",", "$", "position", "+", "$", "offset", "+", "1", ")", ";", "}", "else", "{", "// this entity falls in the hole but we must account", "// for its unused size", "$", "hole_end", "+=", "mb_strlen", "(", "$", "entity", ")", ";", "}", "}", "}" ]
Re-inserts stripped entities into a string in the correct positions The first two parameters are passed by reference and nothing is returned by this function. @param string $string the string to re-insert entites into. @param array $matches the array of stored matches. @param integer $hole_start ignore inserting entities between here and hole_end. @param integer $hole_end ignore inserting entities between here and hole_start. @param integer $hole_length the length of the new contents of the hole.
[ "Re", "-", "inserts", "stripped", "entities", "into", "a", "string", "in", "the", "correct", "positions" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatString.php#L2325-L2368
33,835
silverorange/swat
Swat/SwatTile.php
SwatTile.display
public function display($data) { if (!$this->visible) { return; } $this->setupRenderers($data); $this->displayRenderers($data); }
php
public function display($data) { if (!$this->visible) { return; } $this->setupRenderers($data); $this->displayRenderers($data); }
[ "public", "function", "display", "(", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "visible", ")", "{", "return", ";", "}", "$", "this", "->", "setupRenderers", "(", "$", "data", ")", ";", "$", "this", "->", "displayRenderers", "(", "$", "data", ")", ";", "}" ]
Displays this tile using a data object @param mixed $data a data object used to display the cell renderers in this tile.
[ "Displays", "this", "tile", "using", "a", "data", "object" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTile.php#L42-L50
33,836
silverorange/swat
Swat/SwatTile.php
SwatTile.getMessages
public function getMessages() { $messages = $this->messages; foreach ($this->renderers as $renderer) { $messages = array_merge($messages, $renderer->getMessages()); } return $messages; }
php
public function getMessages() { $messages = $this->messages; foreach ($this->renderers as $renderer) { $messages = array_merge($messages, $renderer->getMessages()); } return $messages; }
[ "public", "function", "getMessages", "(", ")", "{", "$", "messages", "=", "$", "this", "->", "messages", ";", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "$", "messages", "=", "array_merge", "(", "$", "messages", ",", "$", "renderer", "->", "getMessages", "(", ")", ")", ";", "}", "return", "$", "messages", ";", "}" ]
Gathers all messages from this tile @return array an array of {@link SwatMessage} objects.
[ "Gathers", "all", "messages", "from", "this", "tile" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTile.php#L90-L99
33,837
silverorange/swat
Swat/SwatTile.php
SwatTile.hasMessage
public function hasMessage() { $has_message = false; foreach ($this->renderers as $renderer) { if ($renderer->hasMessage()) { $has_message = true; break; } } return $has_message; }
php
public function hasMessage() { $has_message = false; foreach ($this->renderers as $renderer) { if ($renderer->hasMessage()) { $has_message = true; break; } } return $has_message; }
[ "public", "function", "hasMessage", "(", ")", "{", "$", "has_message", "=", "false", ";", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "if", "(", "$", "renderer", "->", "hasMessage", "(", ")", ")", "{", "$", "has_message", "=", "true", ";", "break", ";", "}", "}", "return", "$", "has_message", ";", "}" ]
Gets whether or not this tile has any messages @return boolean true if this tile has one or more messages and false if it does not.
[ "Gets", "whether", "or", "not", "this", "tile", "has", "any", "messages" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTile.php#L125-L137
33,838
silverorange/swat
Swat/SwatTile.php
SwatTile.displayRenderers
protected function displayRenderers($data) { $div_tag = new SwatHtmlTag('div'); $div_tag->class = $this->getCSSClassString(); $div_tag->open(); $this->displayRenderersInternal($data); $div_tag->close(); }
php
protected function displayRenderers($data) { $div_tag = new SwatHtmlTag('div'); $div_tag->class = $this->getCSSClassString(); $div_tag->open(); $this->displayRenderersInternal($data); $div_tag->close(); }
[ "protected", "function", "displayRenderers", "(", "$", "data", ")", "{", "$", "div_tag", "=", "new", "SwatHtmlTag", "(", "'div'", ")", ";", "$", "div_tag", "->", "class", "=", "$", "this", "->", "getCSSClassString", "(", ")", ";", "$", "div_tag", "->", "open", "(", ")", ";", "$", "this", "->", "displayRenderersInternal", "(", "$", "data", ")", ";", "$", "div_tag", "->", "close", "(", ")", ";", "}" ]
Renders cell renderers @param mixed $data the data object being used to render the cell renderers of this field.
[ "Renders", "cell", "renderers" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTile.php#L174-L181
33,839
brainworxx/kreXX
src/Service/Flow/Emergency.php
Emergency.checkEmergencyBreak
public function checkEmergencyBreak() { if ($this->disabled === true) { // Tell them, everything is OK! return false; } if (static::$allIsOk === false) { // This has failed before! // No need to check again! return true; } return $this->checkMemory() || $this->checkRuntime(); }
php
public function checkEmergencyBreak() { if ($this->disabled === true) { // Tell them, everything is OK! return false; } if (static::$allIsOk === false) { // This has failed before! // No need to check again! return true; } return $this->checkMemory() || $this->checkRuntime(); }
[ "public", "function", "checkEmergencyBreak", "(", ")", "{", "if", "(", "$", "this", "->", "disabled", "===", "true", ")", "{", "// Tell them, everything is OK!", "return", "false", ";", "}", "if", "(", "static", "::", "$", "allIsOk", "===", "false", ")", "{", "// This has failed before!", "// No need to check again!", "return", "true", ";", "}", "return", "$", "this", "->", "checkMemory", "(", ")", "||", "$", "this", "->", "checkRuntime", "(", ")", ";", "}" ]
Checks if there is enough memory and time left on the Server. @return bool Boolean to show if we have enough left. FALSE = all is OK. TRUE = we have a problem.
[ "Checks", "if", "there", "is", "enough", "memory", "and", "time", "left", "on", "the", "Server", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Flow/Emergency.php#L174-L188
33,840
brainworxx/kreXX
src/Service/Flow/Emergency.php
Emergency.checkRuntime
protected function checkRuntime() { // Check Runtime. if ($this->timer < time()) { // This is taking longer than expected. $this->pool->messages->addMessage('emergencyTimer'); Krexx::editSettings(); Krexx::disable(); static::$allIsOk = false; return true; } return false; }
php
protected function checkRuntime() { // Check Runtime. if ($this->timer < time()) { // This is taking longer than expected. $this->pool->messages->addMessage('emergencyTimer'); Krexx::editSettings(); Krexx::disable(); static::$allIsOk = false; return true; } return false; }
[ "protected", "function", "checkRuntime", "(", ")", "{", "// Check Runtime.", "if", "(", "$", "this", "->", "timer", "<", "time", "(", ")", ")", "{", "// This is taking longer than expected.", "$", "this", "->", "pool", "->", "messages", "->", "addMessage", "(", "'emergencyTimer'", ")", ";", "Krexx", "::", "editSettings", "(", ")", ";", "Krexx", "::", "disable", "(", ")", ";", "static", "::", "$", "allIsOk", "=", "false", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks if there is enough time left for the analysis. @return bool Boolean to show if we have enough left. FALSE = all is OK. TRUE = we have a problem.
[ "Checks", "if", "there", "is", "enough", "time", "left", "for", "the", "analysis", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Flow/Emergency.php#L198-L211
33,841
brainworxx/kreXX
src/Service/Flow/Emergency.php
Emergency.checkMemory
protected function checkMemory() { // We will only check, if we were able to determine a memory limit // in the first place. if ($this->serverMemoryLimit > 2) { $left = $this->serverMemoryLimit - memory_get_usage(); // Is more left than is configured? if ($left < $this->minMemoryLeft) { $this->pool->messages->addMessage('emergencyMemory'); // Show settings to give the dev to repair the situation. Krexx::editSettings(); Krexx::disable(); static::$allIsOk = false; return true; } } return false; }
php
protected function checkMemory() { // We will only check, if we were able to determine a memory limit // in the first place. if ($this->serverMemoryLimit > 2) { $left = $this->serverMemoryLimit - memory_get_usage(); // Is more left than is configured? if ($left < $this->minMemoryLeft) { $this->pool->messages->addMessage('emergencyMemory'); // Show settings to give the dev to repair the situation. Krexx::editSettings(); Krexx::disable(); static::$allIsOk = false; return true; } } return false; }
[ "protected", "function", "checkMemory", "(", ")", "{", "// We will only check, if we were able to determine a memory limit", "// in the first place.", "if", "(", "$", "this", "->", "serverMemoryLimit", ">", "2", ")", "{", "$", "left", "=", "$", "this", "->", "serverMemoryLimit", "-", "memory_get_usage", "(", ")", ";", "// Is more left than is configured?", "if", "(", "$", "left", "<", "$", "this", "->", "minMemoryLeft", ")", "{", "$", "this", "->", "pool", "->", "messages", "->", "addMessage", "(", "'emergencyMemory'", ")", ";", "// Show settings to give the dev to repair the situation.", "Krexx", "::", "editSettings", "(", ")", ";", "Krexx", "::", "disable", "(", ")", ";", "static", "::", "$", "allIsOk", "=", "false", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if we have enough memory left. @return bool Boolean to show if we have enough left. FALSE = all is OK. TRUE = we have a problem.
[ "Check", "if", "we", "have", "enough", "memory", "left", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Flow/Emergency.php#L221-L239
33,842
brainworxx/kreXX
src/Service/Flow/Emergency.php
Emergency.resetTimer
public function resetTimer() { if (empty($this->timer) === true) { $this->timer = time() + $this->maxRuntime; } }
php
public function resetTimer() { if (empty($this->timer) === true) { $this->timer = time() + $this->maxRuntime; } }
[ "public", "function", "resetTimer", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "timer", ")", "===", "true", ")", "{", "$", "this", "->", "timer", "=", "time", "(", ")", "+", "$", "this", "->", "maxRuntime", ";", "}", "}" ]
Resets the timer. When a certain time has passed, kreXX will use an emergency break to prevent too large output (or no output at all (WSOD)).
[ "Resets", "the", "timer", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Flow/Emergency.php#L284-L289
33,843
brainworxx/kreXX
src/Service/Flow/Emergency.php
Emergency.checkMaxCall
public function checkMaxCall() { if ($this->krexxCount >= $this->maxCall) { // Called too often, we might get into trouble here! return true; } // Give feedback if this is our last call. if ($this->krexxCount === ($this->maxCall - 1)) { $this->pool->messages->addMessage('maxCallReached'); } // Count goes up. ++$this->krexxCount; // Tell them that we are still good. return false; }
php
public function checkMaxCall() { if ($this->krexxCount >= $this->maxCall) { // Called too often, we might get into trouble here! return true; } // Give feedback if this is our last call. if ($this->krexxCount === ($this->maxCall - 1)) { $this->pool->messages->addMessage('maxCallReached'); } // Count goes up. ++$this->krexxCount; // Tell them that we are still good. return false; }
[ "public", "function", "checkMaxCall", "(", ")", "{", "if", "(", "$", "this", "->", "krexxCount", ">=", "$", "this", "->", "maxCall", ")", "{", "// Called too often, we might get into trouble here!", "return", "true", ";", "}", "// Give feedback if this is our last call.", "if", "(", "$", "this", "->", "krexxCount", "===", "(", "$", "this", "->", "maxCall", "-", "1", ")", ")", "{", "$", "this", "->", "pool", "->", "messages", "->", "addMessage", "(", "'maxCallReached'", ")", ";", "}", "// Count goes up.", "++", "$", "this", "->", "krexxCount", ";", "// Tell them that we are still good.", "return", "false", ";", "}" ]
Finds out, if krexx was called too often, to prevent large output. @return bool Whether kreXX was called too often or not.
[ "Finds", "out", "if", "krexx", "was", "called", "too", "often", "to", "prevent", "large", "output", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Flow/Emergency.php#L297-L313
33,844
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.each
public function each(callable $callback) { if ($this->isCollection()) { foreach ($this->data as $val) { $callback($this->box($val)); } } else { $callback($this->box($this->data)); } return $this; }
php
public function each(callable $callback) { if ($this->isCollection()) { foreach ($this->data as $val) { $callback($this->box($val)); } } else { $callback($this->box($this->data)); } return $this; }
[ "public", "function", "each", "(", "callable", "$", "callback", ")", "{", "if", "(", "$", "this", "->", "isCollection", "(", ")", ")", "{", "foreach", "(", "$", "this", "->", "data", "as", "$", "val", ")", "{", "$", "callback", "(", "$", "this", "->", "box", "(", "$", "val", ")", ")", ";", "}", "}", "else", "{", "$", "callback", "(", "$", "this", "->", "box", "(", "$", "this", "->", "data", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Fire callback for each member of the array. @param callable $callback @return $this
[ "Fire", "callback", "for", "each", "member", "of", "the", "array", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L63-L74
33,845
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.pluckArray
public function pluckArray($key): array { if ($this->isCollection()) { return array_map(function ($val) { return $this->box($val); }, CollectionUtility::pluck($this->data, $key)); } // Non-collection return CollectionUtility::pluck([$this->data], $key); }
php
public function pluckArray($key): array { if ($this->isCollection()) { return array_map(function ($val) { return $this->box($val); }, CollectionUtility::pluck($this->data, $key)); } // Non-collection return CollectionUtility::pluck([$this->data], $key); }
[ "public", "function", "pluckArray", "(", "$", "key", ")", ":", "array", "{", "if", "(", "$", "this", "->", "isCollection", "(", ")", ")", "{", "return", "array_map", "(", "function", "(", "$", "val", ")", "{", "return", "$", "this", "->", "box", "(", "$", "val", ")", ";", "}", ",", "CollectionUtility", "::", "pluck", "(", "$", "this", "->", "data", ",", "$", "key", ")", ")", ";", "}", "// Non-collection", "return", "CollectionUtility", "::", "pluck", "(", "[", "$", "this", "->", "data", "]", ",", "$", "key", ")", ";", "}" ]
Pluck a value by key from each result and return an array. @param $key @return array
[ "Pluck", "a", "value", "by", "key", "from", "each", "result", "and", "return", "an", "array", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L122-L132
33,846
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.filter
public function filter($filter): ArrayObjectInterface { return \is_callable($filter, true) ? $this->filterCallback($filter) : $this->filterConditions($filter); }
php
public function filter($filter): ArrayObjectInterface { return \is_callable($filter, true) ? $this->filterCallback($filter) : $this->filterConditions($filter); }
[ "public", "function", "filter", "(", "$", "filter", ")", ":", "ArrayObjectInterface", "{", "return", "\\", "is_callable", "(", "$", "filter", ",", "true", ")", "?", "$", "this", "->", "filterCallback", "(", "$", "filter", ")", ":", "$", "this", "->", "filterConditions", "(", "$", "filter", ")", ";", "}" ]
Return a new collection by filtering data within the current collection. @param mixed $filter @return ArrayObjectInterface
[ "Return", "a", "new", "collection", "by", "filtering", "data", "within", "the", "current", "collection", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L141-L144
33,847
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.filterCallback
public function filterCallback(callable $fn): ArrayObjectInterface { return new static( array_values( array_filter( $this->isCollection() ? $this->data : [$this->data], function($item) use ($fn) { return $fn($this->box($item)); } ) ) ); }
php
public function filterCallback(callable $fn): ArrayObjectInterface { return new static( array_values( array_filter( $this->isCollection() ? $this->data : [$this->data], function($item) use ($fn) { return $fn($this->box($item)); } ) ) ); }
[ "public", "function", "filterCallback", "(", "callable", "$", "fn", ")", ":", "ArrayObjectInterface", "{", "return", "new", "static", "(", "array_values", "(", "array_filter", "(", "$", "this", "->", "isCollection", "(", ")", "?", "$", "this", "->", "data", ":", "[", "$", "this", "->", "data", "]", ",", "function", "(", "$", "item", ")", "use", "(", "$", "fn", ")", "{", "return", "$", "fn", "(", "$", "this", "->", "box", "(", "$", "item", ")", ")", ";", "}", ")", ")", ")", ";", "}" ]
Return a new collection by filtering the data via a callback. @param callable|\Closure $fn @return ArrayObjectInterface
[ "Return", "a", "new", "collection", "by", "filtering", "the", "data", "via", "a", "callback", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L153-L165
33,848
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.filterConditions
public function filterConditions( array $conditions, string $matchType = CollectionUtility::MATCH_TYPE_LOOSE, $preserveKeys = false ): ArrayObjectInterface { return new static(CollectionUtility::filterWhere($this->isCollection() ? $this->data : [$this->data], $conditions, $matchType, $preserveKeys)); }
php
public function filterConditions( array $conditions, string $matchType = CollectionUtility::MATCH_TYPE_LOOSE, $preserveKeys = false ): ArrayObjectInterface { return new static(CollectionUtility::filterWhere($this->isCollection() ? $this->data : [$this->data], $conditions, $matchType, $preserveKeys)); }
[ "public", "function", "filterConditions", "(", "array", "$", "conditions", ",", "string", "$", "matchType", "=", "CollectionUtility", "::", "MATCH_TYPE_LOOSE", ",", "$", "preserveKeys", "=", "false", ")", ":", "ArrayObjectInterface", "{", "return", "new", "static", "(", "CollectionUtility", "::", "filterWhere", "(", "$", "this", "->", "isCollection", "(", ")", "?", "$", "this", "->", "data", ":", "[", "$", "this", "->", "data", "]", ",", "$", "conditions", ",", "$", "matchType", ",", "$", "preserveKeys", ")", ")", ";", "}" ]
Return a new collection by filtering the data against a list of conditions. @param array $conditions @param string $matchType @param bool $preserveKeys @return ArrayObjectInterface
[ "Return", "a", "new", "collection", "by", "filtering", "the", "data", "against", "a", "list", "of", "conditions", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L176-L183
33,849
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.first
public function first() { if (!$this->isCollection()) { return $this; } return isset($this->data[0]) ? $this->box($this->data[0]) : null; }
php
public function first() { if (!$this->isCollection()) { return $this; } return isset($this->data[0]) ? $this->box($this->data[0]) : null; }
[ "public", "function", "first", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isCollection", "(", ")", ")", "{", "return", "$", "this", ";", "}", "return", "isset", "(", "$", "this", "->", "data", "[", "0", "]", ")", "?", "$", "this", "->", "box", "(", "$", "this", "->", "data", "[", "0", "]", ")", ":", "null", ";", "}" ]
Returns the first element in the collection. @return mixed
[ "Returns", "the", "first", "element", "in", "the", "collection", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L190-L197
33,850
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.last
public function last() { if (!$this->isCollection()) { return $this; } return isset($this->data[0]) ? $this->box(ArrayUtility::last($this->data)) : null; }
php
public function last() { if (!$this->isCollection()) { return $this; } return isset($this->data[0]) ? $this->box(ArrayUtility::last($this->data)) : null; }
[ "public", "function", "last", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isCollection", "(", ")", ")", "{", "return", "$", "this", ";", "}", "return", "isset", "(", "$", "this", "->", "data", "[", "0", "]", ")", "?", "$", "this", "->", "box", "(", "ArrayUtility", "::", "last", "(", "$", "this", "->", "data", ")", ")", ":", "null", ";", "}" ]
Returns the last element in the collection. @return ArrayObjectInterface|null
[ "Returns", "the", "last", "element", "in", "the", "collection", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L204-L211
33,851
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.getNormalizedKey
protected function getNormalizedKey($key): string { // Keys within collections must be offset based if (!\is_int($key) && $this->isCollection() && !preg_match('/^\d+\./', $key)) { $key = "0.$key"; } return $key; }
php
protected function getNormalizedKey($key): string { // Keys within collections must be offset based if (!\is_int($key) && $this->isCollection() && !preg_match('/^\d+\./', $key)) { $key = "0.$key"; } return $key; }
[ "protected", "function", "getNormalizedKey", "(", "$", "key", ")", ":", "string", "{", "// Keys within collections must be offset based", "if", "(", "!", "\\", "is_int", "(", "$", "key", ")", "&&", "$", "this", "->", "isCollection", "(", ")", "&&", "!", "preg_match", "(", "'/^\\d+\\./'", ",", "$", "key", ")", ")", "{", "$", "key", "=", "\"0.$key\"", ";", "}", "return", "$", "key", ";", "}" ]
Forces key to be prefixed with an offset. @param $key @return string
[ "Forces", "key", "to", "be", "prefixed", "with", "an", "offset", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L236-L244
33,852
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.has
public function has($key): bool { return ArrayUtility::dotRead($this->data, $this->getNormalizedKey($key)) !== null; }
php
public function has($key): bool { return ArrayUtility::dotRead($this->data, $this->getNormalizedKey($key)) !== null; }
[ "public", "function", "has", "(", "$", "key", ")", ":", "bool", "{", "return", "ArrayUtility", "::", "dotRead", "(", "$", "this", "->", "data", ",", "$", "this", "->", "getNormalizedKey", "(", "$", "key", ")", ")", "!==", "null", ";", "}" ]
Determine if the node contains a property. @param string $key @return bool
[ "Determine", "if", "the", "node", "contains", "a", "property", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L321-L324
33,853
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.shift
public function shift() { $this->forceCollection(); if (!$this->hasItems()) { throw new InvalidOffsetException('Cannot shift this array, no more items'); } return $this->box(array_shift($this->data)); }
php
public function shift() { $this->forceCollection(); if (!$this->hasItems()) { throw new InvalidOffsetException('Cannot shift this array, no more items'); } return $this->box(array_shift($this->data)); }
[ "public", "function", "shift", "(", ")", "{", "$", "this", "->", "forceCollection", "(", ")", ";", "if", "(", "!", "$", "this", "->", "hasItems", "(", ")", ")", "{", "throw", "new", "InvalidOffsetException", "(", "'Cannot shift this array, no more items'", ")", ";", "}", "return", "$", "this", "->", "box", "(", "array_shift", "(", "$", "this", "->", "data", ")", ")", ";", "}" ]
Pull the first item off the collection. If the underlying data is not a collection, it will be converted to one. @throws \Rexlabs\ArrayObject\Exceptions\InvalidOffsetException @return mixed
[ "Pull", "the", "first", "item", "off", "the", "collection", ".", "If", "the", "underlying", "data", "is", "not", "a", "collection", "it", "will", "be", "converted", "to", "one", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L346-L354
33,854
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.forceCollection
protected function forceCollection() { if (!$this->isCollection()) { $this->isCollection = true; $this->data = [$this->data]; } }
php
protected function forceCollection() { if (!$this->isCollection()) { $this->isCollection = true; $this->data = [$this->data]; } }
[ "protected", "function", "forceCollection", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isCollection", "(", ")", ")", "{", "$", "this", "->", "isCollection", "=", "true", ";", "$", "this", "->", "data", "=", "[", "$", "this", "->", "data", "]", ";", "}", "}" ]
Forces the underlying data-structure to become a collection.
[ "Forces", "the", "underlying", "data", "-", "structure", "to", "become", "a", "collection", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L359-L365
33,855
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.unshift
public function unshift(...$values) { $this->forceCollection(); $values = array_map([$this, 'unbox'], $values); array_unshift($this->data, ...$values); return $this; }
php
public function unshift(...$values) { $this->forceCollection(); $values = array_map([$this, 'unbox'], $values); array_unshift($this->data, ...$values); return $this; }
[ "public", "function", "unshift", "(", "...", "$", "values", ")", "{", "$", "this", "->", "forceCollection", "(", ")", ";", "$", "values", "=", "array_map", "(", "[", "$", "this", ",", "'unbox'", "]", ",", "$", "values", ")", ";", "array_unshift", "(", "$", "this", "->", "data", ",", "...", "$", "values", ")", ";", "return", "$", "this", ";", "}" ]
Add one or more items at the start of the collection. If the underlying data is not a collection, it will be converted to one. @param array $values @throws \Rexlabs\ArrayObject\Exceptions\InvalidOffsetException @return mixed
[ "Add", "one", "or", "more", "items", "at", "the", "start", "of", "the", "collection", ".", "If", "the", "underlying", "data", "is", "not", "a", "collection", "it", "will", "be", "converted", "to", "one", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L397-L404
33,856
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.push
public function push(...$values) { $this->forceCollection(); $values = array_map([$this, 'unbox'], $values); array_push($this->data, ...$values); return $this; }
php
public function push(...$values) { $this->forceCollection(); $values = array_map([$this, 'unbox'], $values); array_push($this->data, ...$values); return $this; }
[ "public", "function", "push", "(", "...", "$", "values", ")", "{", "$", "this", "->", "forceCollection", "(", ")", ";", "$", "values", "=", "array_map", "(", "[", "$", "this", ",", "'unbox'", "]", ",", "$", "values", ")", ";", "array_push", "(", "$", "this", "->", "data", ",", "...", "$", "values", ")", ";", "return", "$", "this", ";", "}" ]
Add one or more items to the end of the collection. If the underlying data is not a collection, it will be converted to one. @param array $values @return mixed
[ "Add", "one", "or", "more", "items", "to", "the", "end", "of", "the", "collection", ".", "If", "the", "underlying", "data", "is", "not", "a", "collection", "it", "will", "be", "converted", "to", "one", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L414-L421
33,857
rexlabsio/array-object-php
src/ArrayObject.php
ArrayObject.pop
public function pop() { $this->forceCollection(); if (!$this->hasItems()) { throw new InvalidOffsetException('Cannot shift this array, no more items'); } return $this->box(array_pop($this->data)); }
php
public function pop() { $this->forceCollection(); if (!$this->hasItems()) { throw new InvalidOffsetException('Cannot shift this array, no more items'); } return $this->box(array_pop($this->data)); }
[ "public", "function", "pop", "(", ")", "{", "$", "this", "->", "forceCollection", "(", ")", ";", "if", "(", "!", "$", "this", "->", "hasItems", "(", ")", ")", "{", "throw", "new", "InvalidOffsetException", "(", "'Cannot shift this array, no more items'", ")", ";", "}", "return", "$", "this", "->", "box", "(", "array_pop", "(", "$", "this", "->", "data", ")", ")", ";", "}" ]
Pull the last item off the end of the collection. If the underlying data is not a collection, it will be converted to one. @throws \Rexlabs\ArrayObject\Exceptions\InvalidOffsetException @return mixed
[ "Pull", "the", "last", "item", "off", "the", "end", "of", "the", "collection", ".", "If", "the", "underlying", "data", "is", "not", "a", "collection", "it", "will", "be", "converted", "to", "one", "." ]
5633cbd556ed6e495cd77aca6ed644262a7d5165
https://github.com/rexlabsio/array-object-php/blob/5633cbd556ed6e495cd77aca6ed644262a7d5165/src/ArrayObject.php#L431-L439
33,858
brainworxx/kreXX
src/Service/Config/Config.php
Config.getDevHandler
public function getDevHandler() { static $handle = false; if ($handle === false) { $handle = $this->cookieConfig->getConfigFromCookies('deep', static::SETTING_DEV_HANDLE); } return $handle; }
php
public function getDevHandler() { static $handle = false; if ($handle === false) { $handle = $this->cookieConfig->getConfigFromCookies('deep', static::SETTING_DEV_HANDLE); } return $handle; }
[ "public", "function", "getDevHandler", "(", ")", "{", "static", "$", "handle", "=", "false", ";", "if", "(", "$", "handle", "===", "false", ")", "{", "$", "handle", "=", "$", "this", "->", "cookieConfig", "->", "getConfigFromCookies", "(", "'deep'", ",", "static", "::", "SETTING_DEV_HANDLE", ")", ";", "}", "return", "$", "handle", ";", "}" ]
Returns the developer handle from the cookies. @return string The Developer handle.
[ "Returns", "the", "developer", "handle", "from", "the", "cookies", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Config/Config.php#L180-L189
33,859
brainworxx/kreXX
src/Service/Config/Config.php
Config.loadConfigValue
public function loadConfigValue($name) { $feConfig = $this->iniConfig->getFeConfig($name); $section = $this->feConfigFallback[$name][static::SECTION]; /** @var Model $model */ $model = $this->pool->createClass('Brainworxx\\Krexx\\Service\\Config\\Model') ->setSection($section) ->setEditable($feConfig[0]) ->setType($feConfig[1]); // Do we accept cookie settings here? if ($feConfig[0] === true) { $cookieSetting = $this->cookieConfig->getConfigFromCookies($section, $name); // Do we have a value in the cookies? if ($cookieSetting !== null && ($name === static::SETTING_DISABLED && $cookieSetting === static::VALUE_FALSE) === false ) { // We must not overwrite a disabled=true with local cookie settings! // Otherwise it could get enabled locally, which might be a security // issue. $model->setValue($cookieSetting)->setSource('Local cookie settings'); $this->settings[$name] = $model; return $this; } } // Do we have a value in the ini? $iniSettings = $this->iniConfig->getConfigFromFile($section, $name); if (isset($iniSettings) === true) { $model->setValue($iniSettings)->setSource('Krexx.ini settings'); $this->settings[$name] = $model; return $this; } // Nothing yet? Give back factory settings. $model->setValue($this->feConfigFallback[$name][static::VALUE])->setSource('Factory settings'); $this->settings[$name] = $model; return $this; }
php
public function loadConfigValue($name) { $feConfig = $this->iniConfig->getFeConfig($name); $section = $this->feConfigFallback[$name][static::SECTION]; /** @var Model $model */ $model = $this->pool->createClass('Brainworxx\\Krexx\\Service\\Config\\Model') ->setSection($section) ->setEditable($feConfig[0]) ->setType($feConfig[1]); // Do we accept cookie settings here? if ($feConfig[0] === true) { $cookieSetting = $this->cookieConfig->getConfigFromCookies($section, $name); // Do we have a value in the cookies? if ($cookieSetting !== null && ($name === static::SETTING_DISABLED && $cookieSetting === static::VALUE_FALSE) === false ) { // We must not overwrite a disabled=true with local cookie settings! // Otherwise it could get enabled locally, which might be a security // issue. $model->setValue($cookieSetting)->setSource('Local cookie settings'); $this->settings[$name] = $model; return $this; } } // Do we have a value in the ini? $iniSettings = $this->iniConfig->getConfigFromFile($section, $name); if (isset($iniSettings) === true) { $model->setValue($iniSettings)->setSource('Krexx.ini settings'); $this->settings[$name] = $model; return $this; } // Nothing yet? Give back factory settings. $model->setValue($this->feConfigFallback[$name][static::VALUE])->setSource('Factory settings'); $this->settings[$name] = $model; return $this; }
[ "public", "function", "loadConfigValue", "(", "$", "name", ")", "{", "$", "feConfig", "=", "$", "this", "->", "iniConfig", "->", "getFeConfig", "(", "$", "name", ")", ";", "$", "section", "=", "$", "this", "->", "feConfigFallback", "[", "$", "name", "]", "[", "static", "::", "SECTION", "]", ";", "/** @var Model $model */", "$", "model", "=", "$", "this", "->", "pool", "->", "createClass", "(", "'Brainworxx\\\\Krexx\\\\Service\\\\Config\\\\Model'", ")", "->", "setSection", "(", "$", "section", ")", "->", "setEditable", "(", "$", "feConfig", "[", "0", "]", ")", "->", "setType", "(", "$", "feConfig", "[", "1", "]", ")", ";", "// Do we accept cookie settings here?", "if", "(", "$", "feConfig", "[", "0", "]", "===", "true", ")", "{", "$", "cookieSetting", "=", "$", "this", "->", "cookieConfig", "->", "getConfigFromCookies", "(", "$", "section", ",", "$", "name", ")", ";", "// Do we have a value in the cookies?", "if", "(", "$", "cookieSetting", "!==", "null", "&&", "(", "$", "name", "===", "static", "::", "SETTING_DISABLED", "&&", "$", "cookieSetting", "===", "static", "::", "VALUE_FALSE", ")", "===", "false", ")", "{", "// We must not overwrite a disabled=true with local cookie settings!", "// Otherwise it could get enabled locally, which might be a security", "// issue.", "$", "model", "->", "setValue", "(", "$", "cookieSetting", ")", "->", "setSource", "(", "'Local cookie settings'", ")", ";", "$", "this", "->", "settings", "[", "$", "name", "]", "=", "$", "model", ";", "return", "$", "this", ";", "}", "}", "// Do we have a value in the ini?", "$", "iniSettings", "=", "$", "this", "->", "iniConfig", "->", "getConfigFromFile", "(", "$", "section", ",", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "iniSettings", ")", "===", "true", ")", "{", "$", "model", "->", "setValue", "(", "$", "iniSettings", ")", "->", "setSource", "(", "'Krexx.ini settings'", ")", ";", "$", "this", "->", "settings", "[", "$", "name", "]", "=", "$", "model", ";", "return", "$", "this", ";", "}", "// Nothing yet? Give back factory settings.", "$", "model", "->", "setValue", "(", "$", "this", "->", "feConfigFallback", "[", "$", "name", "]", "[", "static", "::", "VALUE", "]", ")", "->", "setSource", "(", "'Factory settings'", ")", ";", "$", "this", "->", "settings", "[", "$", "name", "]", "=", "$", "model", ";", "return", "$", "this", ";", "}" ]
Load values of the kreXX's configuration. @param string $name The name of the config value. @return $this Return this, for chaining.
[ "Load", "values", "of", "the", "kreXX", "s", "configuration", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Config/Config.php#L214-L253
33,860
brainworxx/kreXX
src/Service/Config/Config.php
Config.isRequestAjaxOrCli
protected function isRequestAjaxOrCli() { $server = $this->pool->getServer(); if (isset($server['HTTP_X_REQUESTED_WITH']) === true && strtolower($server['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest' && $this->getSetting(static::SETTING_DETECT_AJAX) === true ) { // Appending stuff after a ajax request will most likely // cause a js error. But there are moments when you actually // want to do this. // // We were supposed to detect ajax, and we did it right now. return true; } // Check for CLI. if (php_sapi_name() === 'cli') { return true; } // Still here? This means it's neither. return false; }
php
protected function isRequestAjaxOrCli() { $server = $this->pool->getServer(); if (isset($server['HTTP_X_REQUESTED_WITH']) === true && strtolower($server['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest' && $this->getSetting(static::SETTING_DETECT_AJAX) === true ) { // Appending stuff after a ajax request will most likely // cause a js error. But there are moments when you actually // want to do this. // // We were supposed to detect ajax, and we did it right now. return true; } // Check for CLI. if (php_sapi_name() === 'cli') { return true; } // Still here? This means it's neither. return false; }
[ "protected", "function", "isRequestAjaxOrCli", "(", ")", "{", "$", "server", "=", "$", "this", "->", "pool", "->", "getServer", "(", ")", ";", "if", "(", "isset", "(", "$", "server", "[", "'HTTP_X_REQUESTED_WITH'", "]", ")", "===", "true", "&&", "strtolower", "(", "$", "server", "[", "'HTTP_X_REQUESTED_WITH'", "]", ")", "===", "'xmlhttprequest'", "&&", "$", "this", "->", "getSetting", "(", "static", "::", "SETTING_DETECT_AJAX", ")", "===", "true", ")", "{", "// Appending stuff after a ajax request will most likely", "// cause a js error. But there are moments when you actually", "// want to do this.", "//", "// We were supposed to detect ajax, and we did it right now.", "return", "true", ";", "}", "// Check for CLI.", "if", "(", "php_sapi_name", "(", ")", "===", "'cli'", ")", "{", "return", "true", ";", "}", "// Still here? This means it's neither.", "return", "false", ";", "}" ]
Check if the current request is an AJAX request. @return bool TRUE when this is AJAX, FALSE if not
[ "Check", "if", "the", "current", "request", "is", "an", "AJAX", "request", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Config/Config.php#L261-L284
33,861
brainworxx/kreXX
src/Service/Config/Config.php
Config.isAllowedIp
protected function isAllowedIp($whitelist) { $server = $this->pool->getServer(); if (empty($server[static::REMOTE_ADDRESS]) === true) { $remote = ''; } else { $remote = $server[static::REMOTE_ADDRESS]; } $whitelist = explode(',', $whitelist); if (php_sapi_name() === 'cli' || in_array($remote, $whitelist) === true) { // Either the IP is matched, or we are in CLI return true; } // Check the wildcards. foreach ($whitelist as $ip) { $ip = trim($ip); $wildcardPos = strpos($ip, '*'); // Check if the ip has a wildcard. if ($wildcardPos !== false && substr($remote, 0, $wildcardPos) . '*' === $ip) { return true; } } return false; }
php
protected function isAllowedIp($whitelist) { $server = $this->pool->getServer(); if (empty($server[static::REMOTE_ADDRESS]) === true) { $remote = ''; } else { $remote = $server[static::REMOTE_ADDRESS]; } $whitelist = explode(',', $whitelist); if (php_sapi_name() === 'cli' || in_array($remote, $whitelist) === true) { // Either the IP is matched, or we are in CLI return true; } // Check the wildcards. foreach ($whitelist as $ip) { $ip = trim($ip); $wildcardPos = strpos($ip, '*'); // Check if the ip has a wildcard. if ($wildcardPos !== false && substr($remote, 0, $wildcardPos) . '*' === $ip) { return true; } } return false; }
[ "protected", "function", "isAllowedIp", "(", "$", "whitelist", ")", "{", "$", "server", "=", "$", "this", "->", "pool", "->", "getServer", "(", ")", ";", "if", "(", "empty", "(", "$", "server", "[", "static", "::", "REMOTE_ADDRESS", "]", ")", "===", "true", ")", "{", "$", "remote", "=", "''", ";", "}", "else", "{", "$", "remote", "=", "$", "server", "[", "static", "::", "REMOTE_ADDRESS", "]", ";", "}", "$", "whitelist", "=", "explode", "(", "','", ",", "$", "whitelist", ")", ";", "if", "(", "php_sapi_name", "(", ")", "===", "'cli'", "||", "in_array", "(", "$", "remote", ",", "$", "whitelist", ")", "===", "true", ")", "{", "// Either the IP is matched, or we are in CLI", "return", "true", ";", "}", "// Check the wildcards.", "foreach", "(", "$", "whitelist", "as", "$", "ip", ")", "{", "$", "ip", "=", "trim", "(", "$", "ip", ")", ";", "$", "wildcardPos", "=", "strpos", "(", "$", "ip", ",", "'*'", ")", ";", "// Check if the ip has a wildcard.", "if", "(", "$", "wildcardPos", "!==", "false", "&&", "substr", "(", "$", "remote", ",", "0", ",", "$", "wildcardPos", ")", ".", "'*'", "===", "$", "ip", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the current client ip is allowed. @author Chin Leung @see https://stackoverflow.com/questions/35559119/php-ip-address-whitelist-with-wildcards @param string $whitelist The ip whitelist. @return bool Whether the current client ip is allowed or not.
[ "Checks", "if", "the", "current", "client", "ip", "is", "allowed", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Config/Config.php#L331-L358
33,862
brainworxx/kreXX
src/Service/Config/Config.php
Config.isAllowedDebugCall
public function isAllowedDebugCall($data) { // Check if the class itself is blacklisted. foreach ($this->classBlacklist as $classname) { if (is_a($data, $classname) === true) { // No debug methods for you. return false; } } // Nothing found? return true; }
php
public function isAllowedDebugCall($data) { // Check if the class itself is blacklisted. foreach ($this->classBlacklist as $classname) { if (is_a($data, $classname) === true) { // No debug methods for you. return false; } } // Nothing found? return true; }
[ "public", "function", "isAllowedDebugCall", "(", "$", "data", ")", "{", "// Check if the class itself is blacklisted.", "foreach", "(", "$", "this", "->", "classBlacklist", "as", "$", "classname", ")", "{", "if", "(", "is_a", "(", "$", "data", ",", "$", "classname", ")", "===", "true", ")", "{", "// No debug methods for you.", "return", "false", ";", "}", "}", "// Nothing found?", "return", "true", ";", "}" ]
Determines if the specific class is blacklisted for debug methods. @param object $data The class we are analysing. @return bool Whether the function is allowed to be called.
[ "Determines", "if", "the", "specific", "class", "is", "blacklisted", "for", "debug", "methods", "." ]
a03beaa4507ffb391412b9ac61593d263d3f8bca
https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Config/Config.php#L369-L381
33,863
silverorange/swat
Swat/SwatDetailsStore.php
SwatDetailsStore.__isset
public function __isset($name) { $is_set = isset($this->data[$name]); if (!$is_set && $this->base_object !== null) { $is_set = isset($this->base_object->$name); } return $is_set; }
php
public function __isset($name) { $is_set = isset($this->data[$name]); if (!$is_set && $this->base_object !== null) { $is_set = isset($this->base_object->$name); } return $is_set; }
[ "public", "function", "__isset", "(", "$", "name", ")", "{", "$", "is_set", "=", "isset", "(", "$", "this", "->", "data", "[", "$", "name", "]", ")", ";", "if", "(", "!", "$", "is_set", "&&", "$", "this", "->", "base_object", "!==", "null", ")", "{", "$", "is_set", "=", "isset", "(", "$", "this", "->", "base_object", "->", "$", "name", ")", ";", "}", "return", "$", "is_set", ";", "}" ]
Gets whether or not a property is set for this details store First, the manually set properties are checked. Then the properties of the base object are checked if there is a base object. @param string $name the name of the property to check. @return boolean true if the property is set for this details store and false if it is not.
[ "Gets", "whether", "or", "not", "a", "property", "is", "set", "for", "this", "details", "store" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatDetailsStore.php#L137-L146
33,864
silverorange/swat
Swat/Swat.php
Swat.ngettext
public static function ngettext($singular_message, $plural_message, $number) { return dngettext( self::GETTEXT_DOMAIN, $singular_message, $plural_message, $number ); }
php
public static function ngettext($singular_message, $plural_message, $number) { return dngettext( self::GETTEXT_DOMAIN, $singular_message, $plural_message, $number ); }
[ "public", "static", "function", "ngettext", "(", "$", "singular_message", ",", "$", "plural_message", ",", "$", "number", ")", "{", "return", "dngettext", "(", "self", "::", "GETTEXT_DOMAIN", ",", "$", "singular_message", ",", "$", "plural_message", ",", "$", "number", ")", ";", "}" ]
Translates a plural phrase This method should be used when a phrase depends on a number. For example, use ngettext when translating a dynamic phrase like: - "There is 1 new item" for 1 item and - "There are 2 new items" for 2 or more items. This method relies on the php gettext extension and uses dngettext() internally. @param string $singular_message the message to use when the number the phrase depends on is one. @param string $plural_message the message to use when the number the phrase depends on is more than one. @param integer $number the number the phrase depends on. @return string the translated phrase.
[ "Translates", "a", "plural", "phrase" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/Swat.php#L89-L97
33,865
silverorange/swat
Swat/Swat.php
Swat.displayMethods
public static function displayMethods($object) { echo sprintf(self::_('Methods for class %s:'), get_class($object)); echo '<ul>'; foreach (get_class_methods(get_class($object)) as $method_name) { echo '<li>', $method_name, '</li>'; } echo '</ul>'; }
php
public static function displayMethods($object) { echo sprintf(self::_('Methods for class %s:'), get_class($object)); echo '<ul>'; foreach (get_class_methods(get_class($object)) as $method_name) { echo '<li>', $method_name, '</li>'; } echo '</ul>'; }
[ "public", "static", "function", "displayMethods", "(", "$", "object", ")", "{", "echo", "sprintf", "(", "self", "::", "_", "(", "'Methods for class %s:'", ")", ",", "get_class", "(", "$", "object", ")", ")", ";", "echo", "'<ul>'", ";", "foreach", "(", "get_class_methods", "(", "get_class", "(", "$", "object", ")", ")", "as", "$", "method_name", ")", "{", "echo", "'<li>'", ",", "$", "method_name", ",", "'</li>'", ";", "}", "echo", "'</ul>'", ";", "}" ]
Displays the methods of an object This is useful for debugging. @param mixed $object the object whose methods are to be displayed.
[ "Displays", "the", "methods", "of", "an", "object" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/Swat.php#L123-L133
33,866
silverorange/swat
Swat/Swat.php
Swat.displayProperties
public static function displayProperties($object) { $class = get_class($object); echo sprintf(self::_('Properties for class %s:'), $class); echo '<ul>'; foreach (get_class_vars($class) as $property_name => $value) { $instance_value = $object->$property_name; echo '<li>', $property_name, ' = ', $instance_value, '</li>'; } echo '</ul>'; }
php
public static function displayProperties($object) { $class = get_class($object); echo sprintf(self::_('Properties for class %s:'), $class); echo '<ul>'; foreach (get_class_vars($class) as $property_name => $value) { $instance_value = $object->$property_name; echo '<li>', $property_name, ' = ', $instance_value, '</li>'; } echo '</ul>'; }
[ "public", "static", "function", "displayProperties", "(", "$", "object", ")", "{", "$", "class", "=", "get_class", "(", "$", "object", ")", ";", "echo", "sprintf", "(", "self", "::", "_", "(", "'Properties for class %s:'", ")", ",", "$", "class", ")", ";", "echo", "'<ul>'", ";", "foreach", "(", "get_class_vars", "(", "$", "class", ")", "as", "$", "property_name", "=>", "$", "value", ")", "{", "$", "instance_value", "=", "$", "object", "->", "$", "property_name", ";", "echo", "'<li>'", ",", "$", "property_name", ",", "' = '", ",", "$", "instance_value", ",", "'</li>'", ";", "}", "echo", "'</ul>'", ";", "}" ]
Displays the properties of an object This is useful for debugging. @param mixed $object the object whose properties are to be displayed.
[ "Displays", "the", "properties", "of", "an", "object" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/Swat.php#L145-L158
33,867
silverorange/swat
SwatDB/SwatDB.php
SwatDB.query
public static function query( $db, $sql, $wrapper = 'SwatDBDefaultRecordsetWrapper', $types = null ) { $mdb2_types = $types === null ? true : $types; $rs = self::executeQuery($db, 'query', array( $sql, $mdb2_types, true, false )); // Wrap results. Do it here instead of in MDB2 so we can wrap using // an existing object instance. if (is_string($wrapper)) { $rs = new $wrapper($rs); } elseif ($wrapper instanceof SwatDBRecordsetWrapper) { $wrapper->initializeFromResultSet($rs); $rs = $wrapper; } return $rs; }
php
public static function query( $db, $sql, $wrapper = 'SwatDBDefaultRecordsetWrapper', $types = null ) { $mdb2_types = $types === null ? true : $types; $rs = self::executeQuery($db, 'query', array( $sql, $mdb2_types, true, false )); // Wrap results. Do it here instead of in MDB2 so we can wrap using // an existing object instance. if (is_string($wrapper)) { $rs = new $wrapper($rs); } elseif ($wrapper instanceof SwatDBRecordsetWrapper) { $wrapper->initializeFromResultSet($rs); $rs = $wrapper; } return $rs; }
[ "public", "static", "function", "query", "(", "$", "db", ",", "$", "sql", ",", "$", "wrapper", "=", "'SwatDBDefaultRecordsetWrapper'", ",", "$", "types", "=", "null", ")", "{", "$", "mdb2_types", "=", "$", "types", "===", "null", "?", "true", ":", "$", "types", ";", "$", "rs", "=", "self", "::", "executeQuery", "(", "$", "db", ",", "'query'", ",", "array", "(", "$", "sql", ",", "$", "mdb2_types", ",", "true", ",", "false", ")", ")", ";", "// Wrap results. Do it here instead of in MDB2 so we can wrap using", "// an existing object instance.", "if", "(", "is_string", "(", "$", "wrapper", ")", ")", "{", "$", "rs", "=", "new", "$", "wrapper", "(", "$", "rs", ")", ";", "}", "elseif", "(", "$", "wrapper", "instanceof", "SwatDBRecordsetWrapper", ")", "{", "$", "wrapper", "->", "initializeFromResultSet", "(", "$", "rs", ")", ";", "$", "rs", "=", "$", "wrapper", ";", "}", "return", "$", "rs", ";", "}" ]
Performs an SQL query @param MDB2_Driver_Common $db the database connection. @param string $sql the SQL to execute. @param string|SwatDBRecordsetWrapper $wrapper optional. The object or name of class with which to wrap the result set. If not specified, {@link SwatDBDefaultRecordsetWrapper} is used. Specify <kbd>null</kbd> to return an unwrapped MDB2 result. @param array $types optional. An array of MDB2 datatypes for the columns of the result set. @return mixed A recordset containing the query result. If <i>$wrapper</i> is specified as null, a MDB2_Result_Common object is returned. @throws SwatDBException
[ "Performs", "an", "SQL", "query" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L87-L112
33,868
silverorange/swat
SwatDB/SwatDB.php
SwatDB.updateColumn
public static function updateColumn( $db, $table, $field, $value, $id_field, $ids, $where = null ) { $ids = self::initArray($ids); if (count($ids) === 0) { return; } $field = new SwatDBField($field, 'integer'); $id_field = new SwatDBField($id_field, 'integer'); $sql = 'update %s set %s = %s where %s in (%s) %s'; foreach ($ids as &$id) { $id = $db->quote($id, $id_field->type); } $id_list = implode(',', $ids); $where = $where === null ? '' : 'and ' . $where; $sql = sprintf( $sql, $table, $field->name, $db->quote($value, $field->type), $id_field->name, $id_list, $where ); return self::exec($db, $sql); }
php
public static function updateColumn( $db, $table, $field, $value, $id_field, $ids, $where = null ) { $ids = self::initArray($ids); if (count($ids) === 0) { return; } $field = new SwatDBField($field, 'integer'); $id_field = new SwatDBField($id_field, 'integer'); $sql = 'update %s set %s = %s where %s in (%s) %s'; foreach ($ids as &$id) { $id = $db->quote($id, $id_field->type); } $id_list = implode(',', $ids); $where = $where === null ? '' : 'and ' . $where; $sql = sprintf( $sql, $table, $field->name, $db->quote($value, $field->type), $id_field->name, $id_list, $where ); return self::exec($db, $sql); }
[ "public", "static", "function", "updateColumn", "(", "$", "db", ",", "$", "table", ",", "$", "field", ",", "$", "value", ",", "$", "id_field", ",", "$", "ids", ",", "$", "where", "=", "null", ")", "{", "$", "ids", "=", "self", "::", "initArray", "(", "$", "ids", ")", ";", "if", "(", "count", "(", "$", "ids", ")", "===", "0", ")", "{", "return", ";", "}", "$", "field", "=", "new", "SwatDBField", "(", "$", "field", ",", "'integer'", ")", ";", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "sql", "=", "'update %s set %s = %s where %s in (%s) %s'", ";", "foreach", "(", "$", "ids", "as", "&", "$", "id", ")", "{", "$", "id", "=", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ";", "}", "$", "id_list", "=", "implode", "(", "','", ",", "$", "ids", ")", ";", "$", "where", "=", "$", "where", "===", "null", "?", "''", ":", "'and '", ".", "$", "where", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "table", ",", "$", "field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "value", ",", "$", "field", "->", "type", ")", ",", "$", "id_field", "->", "name", ",", "$", "id_list", ",", "$", "where", ")", ";", "return", "self", "::", "exec", "(", "$", "db", ",", "$", "sql", ")", ";", "}" ]
Update a column Convenience method to update a single database field for one or more rows. One convenient use of this method is for processing {@link SwatAction}s that change a single database field. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to query. @param string $field The name of the database field to update. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param mixed $value The value to store in database field $field. The type should correspond to the type of $field. @param string $id_field The name of the database field that contains the the id. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param array $ids An array of identifiers corresponding to the database rows to be updated. The type of the individual identifiers should correspond to the type of $id_field. @param string $where An optional additional where clause. @return integer the number of rows updated. @throws SwatDBException
[ "Update", "a", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L172-L211
33,869
silverorange/swat
SwatDB/SwatDB.php
SwatDB.queryColumn
public static function queryColumn( $db, $table, $field, $id_field = null, $id = 0 ) { $field = new SwatDBField($field, 'integer'); if ($id_field == null) { $sql = 'select %s from %s'; $sql = sprintf($sql, $field->name, $table); } else { $id_field = new SwatDBField($id_field, 'integer'); $sql = 'select %s from %s where %s = %s'; $sql = sprintf( $sql, $field->name, $table, $id_field->name, $db->quote($id, $id_field->type) ); } $values = self::executeQuery($db, 'queryCol', array( $sql, $field->type )); return $values; }
php
public static function queryColumn( $db, $table, $field, $id_field = null, $id = 0 ) { $field = new SwatDBField($field, 'integer'); if ($id_field == null) { $sql = 'select %s from %s'; $sql = sprintf($sql, $field->name, $table); } else { $id_field = new SwatDBField($id_field, 'integer'); $sql = 'select %s from %s where %s = %s'; $sql = sprintf( $sql, $field->name, $table, $id_field->name, $db->quote($id, $id_field->type) ); } $values = self::executeQuery($db, 'queryCol', array( $sql, $field->type )); return $values; }
[ "public", "static", "function", "queryColumn", "(", "$", "db", ",", "$", "table", ",", "$", "field", ",", "$", "id_field", "=", "null", ",", "$", "id", "=", "0", ")", "{", "$", "field", "=", "new", "SwatDBField", "(", "$", "field", ",", "'integer'", ")", ";", "if", "(", "$", "id_field", "==", "null", ")", "{", "$", "sql", "=", "'select %s from %s'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "field", "->", "name", ",", "$", "table", ")", ";", "}", "else", "{", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "sql", "=", "'select %s from %s where %s = %s'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "field", "->", "name", ",", "$", "table", ",", "$", "id_field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ")", ";", "}", "$", "values", "=", "self", "::", "executeQuery", "(", "$", "db", ",", "'queryCol'", ",", "array", "(", "$", "sql", ",", "$", "field", "->", "type", ")", ")", ";", "return", "$", "values", ";", "}" ]
Query a column Convenience method to query for values in a single database column. One convenient use of this method is for loading values from a binding table. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to query. @param string $field The name of the database field to query. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param string $id_field The name of the database field that contains the the id. If not null this will be used to construct a where clause to limit results. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param mixed $id The value to look for in the $id_field. The type should correspond to the type of $id_field. @return array An associative array of $id_field => $field @throws SwatDBException
[ "Query", "a", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L245-L275
33,870
silverorange/swat
SwatDB/SwatDB.php
SwatDB.queryOne
public static function queryOne($db, $sql, $type = null) { $mdb2_type = $type === null ? true : $type; return self::executeQuery($db, 'queryOne', array($sql, $mdb2_type)); }
php
public static function queryOne($db, $sql, $type = null) { $mdb2_type = $type === null ? true : $type; return self::executeQuery($db, 'queryOne', array($sql, $mdb2_type)); }
[ "public", "static", "function", "queryOne", "(", "$", "db", ",", "$", "sql", ",", "$", "type", "=", "null", ")", "{", "$", "mdb2_type", "=", "$", "type", "===", "null", "?", "true", ":", "$", "type", ";", "return", "self", "::", "executeQuery", "(", "$", "db", ",", "'queryOne'", ",", "array", "(", "$", "sql", ",", "$", "mdb2_type", ")", ")", ";", "}" ]
Query a single value Convenience method to query a single value in a single database column. @param MDB2_Driver_Common $db The database connection. @param string $sql The SQL to execute. @param string $type Optional MDB2 datatype for the result. @return mixed The value queried for a single result. Null when there are no results. @throws SwatDBException
[ "Query", "a", "single", "value" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L294-L298
33,871
silverorange/swat
SwatDB/SwatDB.php
SwatDB.queryRow
public static function queryRow($db, $sql, $types = null) { $mdb2_types = $types === null ? true : $types; $row = self::executeQuery($db, 'queryRow', array( $sql, $mdb2_types, MDB2_FETCHMODE_OBJECT )); return $row; }
php
public static function queryRow($db, $sql, $types = null) { $mdb2_types = $types === null ? true : $types; $row = self::executeQuery($db, 'queryRow', array( $sql, $mdb2_types, MDB2_FETCHMODE_OBJECT )); return $row; }
[ "public", "static", "function", "queryRow", "(", "$", "db", ",", "$", "sql", ",", "$", "types", "=", "null", ")", "{", "$", "mdb2_types", "=", "$", "types", "===", "null", "?", "true", ":", "$", "types", ";", "$", "row", "=", "self", "::", "executeQuery", "(", "$", "db", ",", "'queryRow'", ",", "array", "(", "$", "sql", ",", "$", "mdb2_types", ",", "MDB2_FETCHMODE_OBJECT", ")", ")", ";", "return", "$", "row", ";", "}" ]
Query a single row Convenience method to query for a single row from a database table. @param MDB2_Driver_Common $db The database connection. @param string $sql The SQL to execute. @param array $types Optional array of MDB2 datatypes for the result. @return Object A row object, or null. @throws SwatDBException
[ "Query", "a", "single", "row" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L316-L327
33,872
silverorange/swat
SwatDB/SwatDB.php
SwatDB.queryOneFromTable
public static function queryOneFromTable( $db, $table, $field, $id_field = null, $id = 0 ) { $field = new SwatDBField($field, 'integer'); if ($id_field == null) { $sql = 'select %s from %s'; $sql = sprintf($sql, $field->name, $table); } else { $id_field = new SwatDBField($id_field, 'integer'); $sql = 'select %s from %s where %s = %s'; $sql = sprintf( $sql, $field->name, $table, $id_field->name, $db->quote($id, $id_field->type) ); } $value = self::queryOne($db, $sql, $field->type); return $value; }
php
public static function queryOneFromTable( $db, $table, $field, $id_field = null, $id = 0 ) { $field = new SwatDBField($field, 'integer'); if ($id_field == null) { $sql = 'select %s from %s'; $sql = sprintf($sql, $field->name, $table); } else { $id_field = new SwatDBField($id_field, 'integer'); $sql = 'select %s from %s where %s = %s'; $sql = sprintf( $sql, $field->name, $table, $id_field->name, $db->quote($id, $id_field->type) ); } $value = self::queryOne($db, $sql, $field->type); return $value; }
[ "public", "static", "function", "queryOneFromTable", "(", "$", "db", ",", "$", "table", ",", "$", "field", ",", "$", "id_field", "=", "null", ",", "$", "id", "=", "0", ")", "{", "$", "field", "=", "new", "SwatDBField", "(", "$", "field", ",", "'integer'", ")", ";", "if", "(", "$", "id_field", "==", "null", ")", "{", "$", "sql", "=", "'select %s from %s'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "field", "->", "name", ",", "$", "table", ")", ";", "}", "else", "{", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "sql", "=", "'select %s from %s where %s = %s'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "field", "->", "name", ",", "$", "table", ",", "$", "id_field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ")", ";", "}", "$", "value", "=", "self", "::", "queryOne", "(", "$", "db", ",", "$", "sql", ",", "$", "field", "->", "type", ")", ";", "return", "$", "value", ";", "}" ]
Query a single value from a specified table and column Convenience method to query a single value in a single database column. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to query. @param string $field The name of the database field to query. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param string $id_field The name of the database field that contains the the id. If not null this will be used to construct a where clause to limit results. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param mixed $id The value to look for in the $id_field. The type should correspond to the type of $id_field. @return mixed The value queried for a single result. @throws SwatDBException
[ "Query", "a", "single", "value", "from", "a", "specified", "table", "and", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L359-L386
33,873
silverorange/swat
SwatDB/SwatDB.php
SwatDB.queryRowFromTable
public static function queryRowFromTable( $db, $table, $fields, $id_field, $id ) { self::initFields($fields); $id_field = new SwatDBField($id_field, 'integer'); $sql = 'select %s from %s where %s = %s'; $field_list = implode(',', self::getFieldNameArray($fields)); $sql = sprintf( $sql, $field_list, $table, $id_field->name, $db->quote($id, $id_field->type) ); $rs = self::query($db, $sql, null); $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); if (MDB2::isError($row)) { throw new SwatDBException($row); } return $row; }
php
public static function queryRowFromTable( $db, $table, $fields, $id_field, $id ) { self::initFields($fields); $id_field = new SwatDBField($id_field, 'integer'); $sql = 'select %s from %s where %s = %s'; $field_list = implode(',', self::getFieldNameArray($fields)); $sql = sprintf( $sql, $field_list, $table, $id_field->name, $db->quote($id, $id_field->type) ); $rs = self::query($db, $sql, null); $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); if (MDB2::isError($row)) { throw new SwatDBException($row); } return $row; }
[ "public", "static", "function", "queryRowFromTable", "(", "$", "db", ",", "$", "table", ",", "$", "fields", ",", "$", "id_field", ",", "$", "id", ")", "{", "self", "::", "initFields", "(", "$", "fields", ")", ";", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "sql", "=", "'select %s from %s where %s = %s'", ";", "$", "field_list", "=", "implode", "(", "','", ",", "self", "::", "getFieldNameArray", "(", "$", "fields", ")", ")", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "field_list", ",", "$", "table", ",", "$", "id_field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ")", ";", "$", "rs", "=", "self", "::", "query", "(", "$", "db", ",", "$", "sql", ",", "null", ")", ";", "$", "row", "=", "$", "rs", "->", "fetchRow", "(", "MDB2_FETCHMODE_OBJECT", ")", ";", "if", "(", "MDB2", "::", "isError", "(", "$", "row", ")", ")", "{", "throw", "new", "SwatDBException", "(", "$", "row", ")", ";", "}", "return", "$", "row", ";", "}" ]
Query a single row from a specified table and column Convenience method to query for a single row from a database table. One convenient use of this method is for loading data on an edit page. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to query. @param array $fields An array of fields to be queried. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then text is assummed. @param string $id_field The name of the database field that contains the the id. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param mixed $id The value to look for in the id field column. The type should correspond to the type of $field. @return Object A row object. @throws SwatDBException
[ "Query", "a", "single", "row", "from", "a", "specified", "table", "and", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L417-L445
33,874
silverorange/swat
SwatDB/SwatDB.php
SwatDB.executeStoredProc
public static function executeStoredProc( $db, $proc, $params, $wrapper = 'SwatDBDefaultRecordsetWrapper', $types = null ) { if (!is_array($params)) { $params = array($params); } $mdb2_types = $types === null ? true : $types; $db->loadModule('Function'); $rs = $db->function->executeStoredProc( $proc, $params, $mdb2_types, true, false ); if (MDB2::isError($rs)) { throw new SwatDBException($rs); } // Wrap results. Do it here instead of in MDB2 so we can wrap using // an existing object instance. if (is_string($wrapper)) { $rs = new $wrapper($rs); } elseif ($wrapper instanceof SwatDBRecordsetWrapper) { $wrapper->initializeFromResultSet($rs); $rs = $wrapper; } return $rs; }
php
public static function executeStoredProc( $db, $proc, $params, $wrapper = 'SwatDBDefaultRecordsetWrapper', $types = null ) { if (!is_array($params)) { $params = array($params); } $mdb2_types = $types === null ? true : $types; $db->loadModule('Function'); $rs = $db->function->executeStoredProc( $proc, $params, $mdb2_types, true, false ); if (MDB2::isError($rs)) { throw new SwatDBException($rs); } // Wrap results. Do it here instead of in MDB2 so we can wrap using // an existing object instance. if (is_string($wrapper)) { $rs = new $wrapper($rs); } elseif ($wrapper instanceof SwatDBRecordsetWrapper) { $wrapper->initializeFromResultSet($rs); $rs = $wrapper; } return $rs; }
[ "public", "static", "function", "executeStoredProc", "(", "$", "db", ",", "$", "proc", ",", "$", "params", ",", "$", "wrapper", "=", "'SwatDBDefaultRecordsetWrapper'", ",", "$", "types", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "params", ")", ")", "{", "$", "params", "=", "array", "(", "$", "params", ")", ";", "}", "$", "mdb2_types", "=", "$", "types", "===", "null", "?", "true", ":", "$", "types", ";", "$", "db", "->", "loadModule", "(", "'Function'", ")", ";", "$", "rs", "=", "$", "db", "->", "function", "->", "executeStoredProc", "(", "$", "proc", ",", "$", "params", ",", "$", "mdb2_types", ",", "true", ",", "false", ")", ";", "if", "(", "MDB2", "::", "isError", "(", "$", "rs", ")", ")", "{", "throw", "new", "SwatDBException", "(", "$", "rs", ")", ";", "}", "// Wrap results. Do it here instead of in MDB2 so we can wrap using", "// an existing object instance.", "if", "(", "is_string", "(", "$", "wrapper", ")", ")", "{", "$", "rs", "=", "new", "$", "wrapper", "(", "$", "rs", ")", ";", "}", "elseif", "(", "$", "wrapper", "instanceof", "SwatDBRecordsetWrapper", ")", "{", "$", "wrapper", "->", "initializeFromResultSet", "(", "$", "rs", ")", ";", "$", "rs", "=", "$", "wrapper", ";", "}", "return", "$", "rs", ";", "}" ]
Performs a stored procedure @param MDB2_Driver_Common $db the database connection. @param string $proc the name of the stored procedure to execute. @param mixed $params the parameters to pass to the stored procedure. Use an array for more than one parameter. @param string|SwatDBRecordsetWrapper $wrapper optional. The object or name of class with which to wrap the result set. If not specified, {@link SwatDBDefaultRecordsetWrapper} is used. Specify <kbd>null</kbd> to return an unwrapped MDB2 result. @param array $types optional. An array of MDB2 datatypes for the columns of the result set. @return mixed A recordset containing the query result. If <i>$wrapper</i> is specified as null, a MDB2_Result_Common object is returned. @throws SwatDBException
[ "Performs", "a", "stored", "procedure" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L478-L514
33,875
silverorange/swat
SwatDB/SwatDB.php
SwatDB.executeStoredProcOne
public static function executeStoredProcOne($db, $proc, $params) { if (!is_array($params)) { $params = array($params); } $rs = self::executeStoredProc($db, $proc, $params); $row = $rs->getFirst(); return current($row); }
php
public static function executeStoredProcOne($db, $proc, $params) { if (!is_array($params)) { $params = array($params); } $rs = self::executeStoredProc($db, $proc, $params); $row = $rs->getFirst(); return current($row); }
[ "public", "static", "function", "executeStoredProcOne", "(", "$", "db", ",", "$", "proc", ",", "$", "params", ")", "{", "if", "(", "!", "is_array", "(", "$", "params", ")", ")", "{", "$", "params", "=", "array", "(", "$", "params", ")", ";", "}", "$", "rs", "=", "self", "::", "executeStoredProc", "(", "$", "db", ",", "$", "proc", ",", "$", "params", ")", ";", "$", "row", "=", "$", "rs", "->", "getFirst", "(", ")", ";", "return", "current", "(", "$", "row", ")", ";", "}" ]
Execute a stored procedure that returns a single value Convenience method to execute a stored procedure that returns a single value. @param MDB2_Driver_Common $db The database connection. @param string $proc The name of the stored procedure to execute. @param mixed $params The parameters to pass to the stored procedure. Use an array for more than one parameter. @return mixed The value returned by the stored procedure. @throws SwatDBException
[ "Execute", "a", "stored", "procedure", "that", "returns", "a", "single", "value" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L536-L545
33,876
silverorange/swat
SwatDB/SwatDB.php
SwatDB.updateBinding
public static function updateBinding( $db, $table, $id_field, $id, $value_field, $values, $bound_table, $bound_field ) { $id_field = new SwatDBField($id_field, 'integer'); $value_field = new SwatDBField($value_field, 'integer'); $bound_field = new SwatDBField($bound_field, 'integer'); $values = self::initArray($values); $delete_sql = 'delete from %s where %s = %s'; $delete_sql = sprintf( $delete_sql, $table, $id_field->name, $db->quote($id, $id_field->type) ); if (count($values)) { foreach ($values as &$value) { $value = $db->quote($value, $value_field->type); } $value_list = implode(',', $values); $insert_sql = 'insert into %s (%s, %s) select %s, %s from %s ' . 'where %s not in (select %s from %s where %s = %s) and %s in (%s)'; $insert_sql = sprintf( $insert_sql, $table, $id_field->name, $value_field->name, $db->quote($id, $id_field->type), $bound_field->name, $bound_table, $bound_field->name, $value_field->name, $table, $id_field->name, $db->quote($id, $id_field->type), $bound_field->name, $value_list ); $delete_sql .= sprintf( ' and %s not in (%s)', $value_field->name, $value_list ); } $transaction = new SwatDBTransaction($db); try { if (count($values)) { self::exec($db, $insert_sql); } self::exec($db, $delete_sql); } catch (Exception $e) { $transaction->rollback(); throw $e; } $transaction->commit(); }
php
public static function updateBinding( $db, $table, $id_field, $id, $value_field, $values, $bound_table, $bound_field ) { $id_field = new SwatDBField($id_field, 'integer'); $value_field = new SwatDBField($value_field, 'integer'); $bound_field = new SwatDBField($bound_field, 'integer'); $values = self::initArray($values); $delete_sql = 'delete from %s where %s = %s'; $delete_sql = sprintf( $delete_sql, $table, $id_field->name, $db->quote($id, $id_field->type) ); if (count($values)) { foreach ($values as &$value) { $value = $db->quote($value, $value_field->type); } $value_list = implode(',', $values); $insert_sql = 'insert into %s (%s, %s) select %s, %s from %s ' . 'where %s not in (select %s from %s where %s = %s) and %s in (%s)'; $insert_sql = sprintf( $insert_sql, $table, $id_field->name, $value_field->name, $db->quote($id, $id_field->type), $bound_field->name, $bound_table, $bound_field->name, $value_field->name, $table, $id_field->name, $db->quote($id, $id_field->type), $bound_field->name, $value_list ); $delete_sql .= sprintf( ' and %s not in (%s)', $value_field->name, $value_list ); } $transaction = new SwatDBTransaction($db); try { if (count($values)) { self::exec($db, $insert_sql); } self::exec($db, $delete_sql); } catch (Exception $e) { $transaction->rollback(); throw $e; } $transaction->commit(); }
[ "public", "static", "function", "updateBinding", "(", "$", "db", ",", "$", "table", ",", "$", "id_field", ",", "$", "id", ",", "$", "value_field", ",", "$", "values", ",", "$", "bound_table", ",", "$", "bound_field", ")", "{", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "value_field", "=", "new", "SwatDBField", "(", "$", "value_field", ",", "'integer'", ")", ";", "$", "bound_field", "=", "new", "SwatDBField", "(", "$", "bound_field", ",", "'integer'", ")", ";", "$", "values", "=", "self", "::", "initArray", "(", "$", "values", ")", ";", "$", "delete_sql", "=", "'delete from %s where %s = %s'", ";", "$", "delete_sql", "=", "sprintf", "(", "$", "delete_sql", ",", "$", "table", ",", "$", "id_field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ")", ";", "if", "(", "count", "(", "$", "values", ")", ")", "{", "foreach", "(", "$", "values", "as", "&", "$", "value", ")", "{", "$", "value", "=", "$", "db", "->", "quote", "(", "$", "value", ",", "$", "value_field", "->", "type", ")", ";", "}", "$", "value_list", "=", "implode", "(", "','", ",", "$", "values", ")", ";", "$", "insert_sql", "=", "'insert into %s (%s, %s) select %s, %s from %s '", ".", "'where %s not in (select %s from %s where %s = %s) and %s in (%s)'", ";", "$", "insert_sql", "=", "sprintf", "(", "$", "insert_sql", ",", "$", "table", ",", "$", "id_field", "->", "name", ",", "$", "value_field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ",", "$", "bound_field", "->", "name", ",", "$", "bound_table", ",", "$", "bound_field", "->", "name", ",", "$", "value_field", "->", "name", ",", "$", "table", ",", "$", "id_field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ",", "$", "bound_field", "->", "name", ",", "$", "value_list", ")", ";", "$", "delete_sql", ".=", "sprintf", "(", "' and %s not in (%s)'", ",", "$", "value_field", "->", "name", ",", "$", "value_list", ")", ";", "}", "$", "transaction", "=", "new", "SwatDBTransaction", "(", "$", "db", ")", ";", "try", "{", "if", "(", "count", "(", "$", "values", ")", ")", "{", "self", "::", "exec", "(", "$", "db", ",", "$", "insert_sql", ")", ";", "}", "self", "::", "exec", "(", "$", "db", ",", "$", "delete_sql", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "transaction", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "}", "$", "transaction", "->", "commit", "(", ")", ";", "}" ]
Update a binding table Convenience method to update rows in a binding table. It will delete and insert rows as necessary. @param MDB2_Driver_Common $db The database connection. @param string $table The binding table to update. @param string $id_field The name of the binding table field that contains the fixed value. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param mixed $id The value to store in the $id_field. The type should correspond to the type of $id_field. @param string $value_field The name of the binding table field that contains the values from the bound table. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param array $values An array of values that should be stored in the $value_field. The type of the individual values should correspond to the type of $value_field. @param string $bound_table The table bound through the binding table. @param string $bound_field The database field in the bound table that the binding table references. @throws SwatDBException
[ "Update", "a", "binding", "table" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L584-L656
33,877
silverorange/swat
SwatDB/SwatDB.php
SwatDB.updateRow
public static function updateRow( $db, $table, $fields, $values, $id_field, $id ) { self::initFields($fields); $id_field = new SwatDBField($id_field, 'integer'); $sql = 'update %s set %s where %s = %s'; $updates = array(); foreach ($fields as &$field) { $value = isset($values[$field->name]) ? $values[$field->name] : null; $updates[] = sprintf( '%s = %s', $field->name, $db->quote($value, $field->type) ); } $update_list = implode(',', $updates); $sql = sprintf( $sql, $table, $update_list, $id_field->name, $db->quote($id, $id_field->type) ); self::exec($db, $sql); }
php
public static function updateRow( $db, $table, $fields, $values, $id_field, $id ) { self::initFields($fields); $id_field = new SwatDBField($id_field, 'integer'); $sql = 'update %s set %s where %s = %s'; $updates = array(); foreach ($fields as &$field) { $value = isset($values[$field->name]) ? $values[$field->name] : null; $updates[] = sprintf( '%s = %s', $field->name, $db->quote($value, $field->type) ); } $update_list = implode(',', $updates); $sql = sprintf( $sql, $table, $update_list, $id_field->name, $db->quote($id, $id_field->type) ); self::exec($db, $sql); }
[ "public", "static", "function", "updateRow", "(", "$", "db", ",", "$", "table", ",", "$", "fields", ",", "$", "values", ",", "$", "id_field", ",", "$", "id", ")", "{", "self", "::", "initFields", "(", "$", "fields", ")", ";", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "sql", "=", "'update %s set %s where %s = %s'", ";", "$", "updates", "=", "array", "(", ")", ";", "foreach", "(", "$", "fields", "as", "&", "$", "field", ")", "{", "$", "value", "=", "isset", "(", "$", "values", "[", "$", "field", "->", "name", "]", ")", "?", "$", "values", "[", "$", "field", "->", "name", "]", ":", "null", ";", "$", "updates", "[", "]", "=", "sprintf", "(", "'%s = %s'", ",", "$", "field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "value", ",", "$", "field", "->", "type", ")", ")", ";", "}", "$", "update_list", "=", "implode", "(", "','", ",", "$", "updates", ")", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "table", ",", "$", "update_list", ",", "$", "id_field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ")", ";", "self", "::", "exec", "(", "$", "db", ",", "$", "sql", ")", ";", "}" ]
Update a row Convenience method to update multiple fields of a single database row. One convenient use of this method is for save data on an edit page. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to update. @param array $fields An array of fields to be updated. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then text is assummed. @param array $values An associative array of values to store in the database. The array keys should correspond to field names. The type of the individual values should correspond to the field type. @param string $id_field The name of the database field that contains an identifier of row to be updated. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param mixed $id The value to look for in the $id_field column. The type should correspond to the type of $field. @throws SwatDBException
[ "Update", "a", "row" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L776-L812
33,878
silverorange/swat
SwatDB/SwatDB.php
SwatDB.deleteRow
public static function deleteRow($db, $table, $id_field, $id) { $id_field = new SwatDBField($id_field, 'integer'); $sql = 'delete from %s where %s = %s'; $sql = sprintf( $sql, $table, $id_field->name, $db->quote($id, $id_field->type) ); self::exec($db, $sql); }
php
public static function deleteRow($db, $table, $id_field, $id) { $id_field = new SwatDBField($id_field, 'integer'); $sql = 'delete from %s where %s = %s'; $sql = sprintf( $sql, $table, $id_field->name, $db->quote($id, $id_field->type) ); self::exec($db, $sql); }
[ "public", "static", "function", "deleteRow", "(", "$", "db", ",", "$", "table", ",", "$", "id_field", ",", "$", "id", ")", "{", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "sql", "=", "'delete from %s where %s = %s'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "table", ",", "$", "id_field", "->", "name", ",", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "id_field", "->", "type", ")", ")", ";", "self", "::", "exec", "(", "$", "db", ",", "$", "sql", ")", ";", "}" ]
Delete a row Convenience method to delete a single database row. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to delete from. @param string $id_field The name of the database field that contains an identifier of row to be deleted. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param mixed $id The value to look for in the $id_field column. The type should correspond to the type of $field. @throws SwatDBException
[ "Delete", "a", "row" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L836-L849
33,879
silverorange/swat
SwatDB/SwatDB.php
SwatDB.getCascadeOptionArray
public static function getCascadeOptionArray( $db, $table, $title_field, $id_field, $cascade_field, $order_by_clause = null, $where_clause = null ) { $title_field = new SwatDBField($title_field, 'text'); $id_field = new SwatDBField($id_field, 'integer'); $cascade_field = new SwatDBField($cascade_field, 'integer'); $sql = 'select %s, %s, %s from %s'; $sql = sprintf( $sql, $id_field->name, $title_field->name, $cascade_field->name, $table ); if ($where_clause !== null) { $sql .= ' where ' . $where_clause; } $sql .= ' order by ' . $cascade_field->name; if ($order_by_clause !== null) { $sql .= ', ' . $order_by_clause; } $rs = self::query($db, $sql, null); $options = array(); $current = null; $title_field_name = $title_field->name; $id_field_name = $id_field->name; $cascade_field_name = $cascade_field->name; $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); while ($row) { if (MDB2::isError($row)) { throw new SwatDBException($row); } if ($row->$cascade_field_name != $current) { $current = $row->$cascade_field_name; $options[$current] = array(); } $options[$current][$row->$id_field_name] = $row->$title_field_name; $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); } return $options; }
php
public static function getCascadeOptionArray( $db, $table, $title_field, $id_field, $cascade_field, $order_by_clause = null, $where_clause = null ) { $title_field = new SwatDBField($title_field, 'text'); $id_field = new SwatDBField($id_field, 'integer'); $cascade_field = new SwatDBField($cascade_field, 'integer'); $sql = 'select %s, %s, %s from %s'; $sql = sprintf( $sql, $id_field->name, $title_field->name, $cascade_field->name, $table ); if ($where_clause !== null) { $sql .= ' where ' . $where_clause; } $sql .= ' order by ' . $cascade_field->name; if ($order_by_clause !== null) { $sql .= ', ' . $order_by_clause; } $rs = self::query($db, $sql, null); $options = array(); $current = null; $title_field_name = $title_field->name; $id_field_name = $id_field->name; $cascade_field_name = $cascade_field->name; $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); while ($row) { if (MDB2::isError($row)) { throw new SwatDBException($row); } if ($row->$cascade_field_name != $current) { $current = $row->$cascade_field_name; $options[$current] = array(); } $options[$current][$row->$id_field_name] = $row->$title_field_name; $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); } return $options; }
[ "public", "static", "function", "getCascadeOptionArray", "(", "$", "db", ",", "$", "table", ",", "$", "title_field", ",", "$", "id_field", ",", "$", "cascade_field", ",", "$", "order_by_clause", "=", "null", ",", "$", "where_clause", "=", "null", ")", "{", "$", "title_field", "=", "new", "SwatDBField", "(", "$", "title_field", ",", "'text'", ")", ";", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "cascade_field", "=", "new", "SwatDBField", "(", "$", "cascade_field", ",", "'integer'", ")", ";", "$", "sql", "=", "'select %s, %s, %s from %s'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "id_field", "->", "name", ",", "$", "title_field", "->", "name", ",", "$", "cascade_field", "->", "name", ",", "$", "table", ")", ";", "if", "(", "$", "where_clause", "!==", "null", ")", "{", "$", "sql", ".=", "' where '", ".", "$", "where_clause", ";", "}", "$", "sql", ".=", "' order by '", ".", "$", "cascade_field", "->", "name", ";", "if", "(", "$", "order_by_clause", "!==", "null", ")", "{", "$", "sql", ".=", "', '", ".", "$", "order_by_clause", ";", "}", "$", "rs", "=", "self", "::", "query", "(", "$", "db", ",", "$", "sql", ",", "null", ")", ";", "$", "options", "=", "array", "(", ")", ";", "$", "current", "=", "null", ";", "$", "title_field_name", "=", "$", "title_field", "->", "name", ";", "$", "id_field_name", "=", "$", "id_field", "->", "name", ";", "$", "cascade_field_name", "=", "$", "cascade_field", "->", "name", ";", "$", "row", "=", "$", "rs", "->", "fetchRow", "(", "MDB2_FETCHMODE_OBJECT", ")", ";", "while", "(", "$", "row", ")", "{", "if", "(", "MDB2", "::", "isError", "(", "$", "row", ")", ")", "{", "throw", "new", "SwatDBException", "(", "$", "row", ")", ";", "}", "if", "(", "$", "row", "->", "$", "cascade_field_name", "!=", "$", "current", ")", "{", "$", "current", "=", "$", "row", "->", "$", "cascade_field_name", ";", "$", "options", "[", "$", "current", "]", "=", "array", "(", ")", ";", "}", "$", "options", "[", "$", "current", "]", "[", "$", "row", "->", "$", "id_field_name", "]", "=", "$", "row", "->", "$", "title_field_name", ";", "$", "row", "=", "$", "rs", "->", "fetchRow", "(", "MDB2_FETCHMODE_OBJECT", ")", ";", "}", "return", "$", "options", ";", "}" ]
Query for an option array cascaded by a field Convenience method to query for a set of options, each consisting of an id, title, and a group-by field. The returned option array in the form of $cascade => array($id => $title, $id => $title) can be passed directly to other classes, such as {@link SwatCascade} for example. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to query. @param string $title_field The name of the database field to query for the title. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then text is assummed for this field. @param string $id_field The name of the database field to query for the id. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param string $cascade_field The name of the database field to cascade the options by. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param string $order_by_clause Optional comma deliminated list of database field names to use in the <i>order by</i> clause. Do not include "order by" in the string; only include the list of field names. Pass null to skip over this paramater. @param string $where_clause Optional <i>where</i> clause to limit the returned results. Do not include "where" in the string; only include the conditionals. @return array An array in the form of $id => $title. @throws SwatDBException
[ "Query", "for", "an", "option", "array", "cascaded", "by", "a", "field" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L973-L1028
33,880
silverorange/swat
SwatDB/SwatDB.php
SwatDB.getGroupedOptionArray
public static function getGroupedOptionArray( $db, $table, $title_field, $id_field, $group_table, $group_title_field, $group_id_field, $group_field, $order_by_clause = null, $where_clause = null, $tree = null ) { $title_field = new SwatDBField($title_field, 'text'); $id_field = new SwatDBField($id_field, 'integer'); $group_title_field = new SwatDBField($group_title_field, 'text'); $group_id_field = new SwatDBField($group_id_field, 'integer'); $group_field = new SwatDBField($group_field, 'text'); $sql = 'select %s as id, %s as title, %s as group_title, %s as group_id from %s'; $sql = sprintf( $sql, "{$table}.{$id_field->name}", "{$table}.{$title_field->name}", "{$group_table}.{$group_title_field->name}", "{$group_table}.{$group_id_field->name}", $table ); $sql .= ' inner join %s on %s = %s'; $sql = sprintf( $sql, $group_table, "{$group_table}.{$group_id_field->name}", "{$table}.{$group_field->name}" ); if ($where_clause != null) { $sql .= ' where ' . $where_clause; } if ($order_by_clause != null) { $sql .= ' order by ' . $order_by_clause; } $rs = self::query($db, $sql, null); $options = array(); if ($tree !== null && $tree instanceof SwatDataTreeNode) { $base_parent = $tree; } else { $base_parent = new SwatDataTreeNode(null, Swat::_('Root')); } $current_group = null; $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); while ($row) { if ($current_group !== $row->group_id) { $current_parent = new SwatDataTreeNode(null, $row->group_title); $base_parent->addChild($current_parent); $current_group = $row->group_id; } $current_parent->addChild( new SwatDataTreeNode($row->id, $row->title) ); $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); } return $base_parent; }
php
public static function getGroupedOptionArray( $db, $table, $title_field, $id_field, $group_table, $group_title_field, $group_id_field, $group_field, $order_by_clause = null, $where_clause = null, $tree = null ) { $title_field = new SwatDBField($title_field, 'text'); $id_field = new SwatDBField($id_field, 'integer'); $group_title_field = new SwatDBField($group_title_field, 'text'); $group_id_field = new SwatDBField($group_id_field, 'integer'); $group_field = new SwatDBField($group_field, 'text'); $sql = 'select %s as id, %s as title, %s as group_title, %s as group_id from %s'; $sql = sprintf( $sql, "{$table}.{$id_field->name}", "{$table}.{$title_field->name}", "{$group_table}.{$group_title_field->name}", "{$group_table}.{$group_id_field->name}", $table ); $sql .= ' inner join %s on %s = %s'; $sql = sprintf( $sql, $group_table, "{$group_table}.{$group_id_field->name}", "{$table}.{$group_field->name}" ); if ($where_clause != null) { $sql .= ' where ' . $where_clause; } if ($order_by_clause != null) { $sql .= ' order by ' . $order_by_clause; } $rs = self::query($db, $sql, null); $options = array(); if ($tree !== null && $tree instanceof SwatDataTreeNode) { $base_parent = $tree; } else { $base_parent = new SwatDataTreeNode(null, Swat::_('Root')); } $current_group = null; $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); while ($row) { if ($current_group !== $row->group_id) { $current_parent = new SwatDataTreeNode(null, $row->group_title); $base_parent->addChild($current_parent); $current_group = $row->group_id; } $current_parent->addChild( new SwatDataTreeNode($row->id, $row->title) ); $row = $rs->fetchRow(MDB2_FETCHMODE_OBJECT); } return $base_parent; }
[ "public", "static", "function", "getGroupedOptionArray", "(", "$", "db", ",", "$", "table", ",", "$", "title_field", ",", "$", "id_field", ",", "$", "group_table", ",", "$", "group_title_field", ",", "$", "group_id_field", ",", "$", "group_field", ",", "$", "order_by_clause", "=", "null", ",", "$", "where_clause", "=", "null", ",", "$", "tree", "=", "null", ")", "{", "$", "title_field", "=", "new", "SwatDBField", "(", "$", "title_field", ",", "'text'", ")", ";", "$", "id_field", "=", "new", "SwatDBField", "(", "$", "id_field", ",", "'integer'", ")", ";", "$", "group_title_field", "=", "new", "SwatDBField", "(", "$", "group_title_field", ",", "'text'", ")", ";", "$", "group_id_field", "=", "new", "SwatDBField", "(", "$", "group_id_field", ",", "'integer'", ")", ";", "$", "group_field", "=", "new", "SwatDBField", "(", "$", "group_field", ",", "'text'", ")", ";", "$", "sql", "=", "'select %s as id, %s as title, %s as group_title, %s as group_id\n\t\t\tfrom %s'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "\"{$table}.{$id_field->name}\"", ",", "\"{$table}.{$title_field->name}\"", ",", "\"{$group_table}.{$group_title_field->name}\"", ",", "\"{$group_table}.{$group_id_field->name}\"", ",", "$", "table", ")", ";", "$", "sql", ".=", "' inner join %s on %s = %s'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "group_table", ",", "\"{$group_table}.{$group_id_field->name}\"", ",", "\"{$table}.{$group_field->name}\"", ")", ";", "if", "(", "$", "where_clause", "!=", "null", ")", "{", "$", "sql", ".=", "' where '", ".", "$", "where_clause", ";", "}", "if", "(", "$", "order_by_clause", "!=", "null", ")", "{", "$", "sql", ".=", "' order by '", ".", "$", "order_by_clause", ";", "}", "$", "rs", "=", "self", "::", "query", "(", "$", "db", ",", "$", "sql", ",", "null", ")", ";", "$", "options", "=", "array", "(", ")", ";", "if", "(", "$", "tree", "!==", "null", "&&", "$", "tree", "instanceof", "SwatDataTreeNode", ")", "{", "$", "base_parent", "=", "$", "tree", ";", "}", "else", "{", "$", "base_parent", "=", "new", "SwatDataTreeNode", "(", "null", ",", "Swat", "::", "_", "(", "'Root'", ")", ")", ";", "}", "$", "current_group", "=", "null", ";", "$", "row", "=", "$", "rs", "->", "fetchRow", "(", "MDB2_FETCHMODE_OBJECT", ")", ";", "while", "(", "$", "row", ")", "{", "if", "(", "$", "current_group", "!==", "$", "row", "->", "group_id", ")", "{", "$", "current_parent", "=", "new", "SwatDataTreeNode", "(", "null", ",", "$", "row", "->", "group_title", ")", ";", "$", "base_parent", "->", "addChild", "(", "$", "current_parent", ")", ";", "$", "current_group", "=", "$", "row", "->", "group_id", ";", "}", "$", "current_parent", "->", "addChild", "(", "new", "SwatDataTreeNode", "(", "$", "row", "->", "id", ",", "$", "row", "->", "title", ")", ")", ";", "$", "row", "=", "$", "rs", "->", "fetchRow", "(", "MDB2_FETCHMODE_OBJECT", ")", ";", "}", "return", "$", "base_parent", ";", "}" ]
Queries for a grouped option array Convenience method to query a grouped list of {@link SwatDataTreeNode} objects used for things like {@link SwatCheckboxList} where checkboxes are grouped together under a title. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to query. @param string $title_field The name of the database field to query for the title. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then text is assummed for this field. @param string $id_field The name of the database field to query for the id. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param string $group_table The database table that the group titles come from. @param string $group_idfield The name of the database field to query for the id of the $group_table. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param string $group_title_field The name of the database field to query for the group title. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then text is assummed for this field. @param string $group_field The name of the database field in $table that links with the $group_idfield. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then integer is assummed for this field. @param string $order_by_clause Optional comma deliminated list of database field names to use in the <i>order by</i> clause. Do not include "order by" in the string; only include the list of field names. Pass null to skip over this paramater. @param string $where_clause Optional <i>where</i> clause to limit the returned results. Do not include "where" in the string; only include the conditionals. @param SwatDataTreeNode $tree a tree to add nodes to. If no tree is specified, nodes are added to a new empty tree. @return SwatDataTreeNode a tree composed of {@link SwatDataTreeNode} objects. @throws SwatDBException
[ "Queries", "for", "a", "grouped", "option", "array" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L1089-L1164
33,881
silverorange/swat
SwatDB/SwatDB.php
SwatDB.getFieldMax
public static function getFieldMax($db, $table, $field) { $field = new SwatDBField($field, 'integer'); $sql = sprintf( 'select max(%s) as %s from %s', $field->name, $field->name, $table ); return self::queryOne($db, $sql); }
php
public static function getFieldMax($db, $table, $field) { $field = new SwatDBField($field, 'integer'); $sql = sprintf( 'select max(%s) as %s from %s', $field->name, $field->name, $table ); return self::queryOne($db, $sql); }
[ "public", "static", "function", "getFieldMax", "(", "$", "db", ",", "$", "table", ",", "$", "field", ")", "{", "$", "field", "=", "new", "SwatDBField", "(", "$", "field", ",", "'integer'", ")", ";", "$", "sql", "=", "sprintf", "(", "'select max(%s) as %s from %s'", ",", "$", "field", "->", "name", ",", "$", "field", "->", "name", ",", "$", "table", ")", ";", "return", "self", "::", "queryOne", "(", "$", "db", ",", "$", "sql", ")", ";", "}" ]
Get max field value Convenience method to grab the max value from a single field. @param MDB2_Driver_Common $db The database connection. @param string $table The database table to update. @param string $field The field to be return the max value of. Can be given in the form type:name where type is a standard MDB2 datatype. If type is ommitted, then text is assummed. @return mixed The max value of field specified. @throws SwatDBException
[ "Get", "max", "field", "value" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L1186-L1198
33,882
silverorange/swat
SwatDB/SwatDB.php
SwatDB.equalityOperator
public static function equalityOperator($value, $neg = false) { if ($value === null && $neg) { return 'is not'; } elseif ($value === null) { return 'is'; } elseif ($neg) { return '!='; } else { return '='; } }
php
public static function equalityOperator($value, $neg = false) { if ($value === null && $neg) { return 'is not'; } elseif ($value === null) { return 'is'; } elseif ($neg) { return '!='; } else { return '='; } }
[ "public", "static", "function", "equalityOperator", "(", "$", "value", ",", "$", "neg", "=", "false", ")", "{", "if", "(", "$", "value", "===", "null", "&&", "$", "neg", ")", "{", "return", "'is not'", ";", "}", "elseif", "(", "$", "value", "===", "null", ")", "{", "return", "'is'", ";", "}", "elseif", "(", "$", "neg", ")", "{", "return", "'!='", ";", "}", "else", "{", "return", "'='", ";", "}", "}" ]
Get proper conditional operator Convenience method to return proper operators for database values that may be null. @param mixed $value The value to check for null on @param boolean $neg Whether to return the operator for a negative comparison @return string SQL operator
[ "Get", "proper", "conditional", "operator" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L1216-L1227
33,883
silverorange/swat
SwatDB/SwatDB.php
SwatDB.getDataTree
public static function getDataTree( $rs, $title_field_name, $id_field_name, $level_field_name, $tree = null ) { $stack = array(); if ($tree !== null && $tree instanceof SwatDataTreeNode) { $current_parent = $tree; } else { $current_parent = new SwatDataTreeNode('', Swat::_('Root')); } $base_parent = $current_parent; array_push($stack, $current_parent); $last_node = $current_parent; foreach ($rs as $row) { $title = $row->$title_field_name; $id = $row->$id_field_name; $level = $row->$level_field_name; if ($level > count($stack)) { array_push($stack, $current_parent); $current_parent = $last_node; } elseif ($level < count($stack)) { $current_parent = array_pop($stack); } $last_node = new SwatDataTreeNode($id, $title); $current_parent->addChild($last_node); } return $base_parent; }
php
public static function getDataTree( $rs, $title_field_name, $id_field_name, $level_field_name, $tree = null ) { $stack = array(); if ($tree !== null && $tree instanceof SwatDataTreeNode) { $current_parent = $tree; } else { $current_parent = new SwatDataTreeNode('', Swat::_('Root')); } $base_parent = $current_parent; array_push($stack, $current_parent); $last_node = $current_parent; foreach ($rs as $row) { $title = $row->$title_field_name; $id = $row->$id_field_name; $level = $row->$level_field_name; if ($level > count($stack)) { array_push($stack, $current_parent); $current_parent = $last_node; } elseif ($level < count($stack)) { $current_parent = array_pop($stack); } $last_node = new SwatDataTreeNode($id, $title); $current_parent->addChild($last_node); } return $base_parent; }
[ "public", "static", "function", "getDataTree", "(", "$", "rs", ",", "$", "title_field_name", ",", "$", "id_field_name", ",", "$", "level_field_name", ",", "$", "tree", "=", "null", ")", "{", "$", "stack", "=", "array", "(", ")", ";", "if", "(", "$", "tree", "!==", "null", "&&", "$", "tree", "instanceof", "SwatDataTreeNode", ")", "{", "$", "current_parent", "=", "$", "tree", ";", "}", "else", "{", "$", "current_parent", "=", "new", "SwatDataTreeNode", "(", "''", ",", "Swat", "::", "_", "(", "'Root'", ")", ")", ";", "}", "$", "base_parent", "=", "$", "current_parent", ";", "array_push", "(", "$", "stack", ",", "$", "current_parent", ")", ";", "$", "last_node", "=", "$", "current_parent", ";", "foreach", "(", "$", "rs", "as", "$", "row", ")", "{", "$", "title", "=", "$", "row", "->", "$", "title_field_name", ";", "$", "id", "=", "$", "row", "->", "$", "id_field_name", ";", "$", "level", "=", "$", "row", "->", "$", "level_field_name", ";", "if", "(", "$", "level", ">", "count", "(", "$", "stack", ")", ")", "{", "array_push", "(", "$", "stack", ",", "$", "current_parent", ")", ";", "$", "current_parent", "=", "$", "last_node", ";", "}", "elseif", "(", "$", "level", "<", "count", "(", "$", "stack", ")", ")", "{", "$", "current_parent", "=", "array_pop", "(", "$", "stack", ")", ";", "}", "$", "last_node", "=", "new", "SwatDataTreeNode", "(", "$", "id", ",", "$", "title", ")", ";", "$", "current_parent", "->", "addChild", "(", "$", "last_node", ")", ";", "}", "return", "$", "base_parent", ";", "}" ]
Get a tree of data nodes Convenience method to take a structured query with each row consisting of an id, levelnum, and a title, and turning it into a tree of {@link SwatDataTreeNode} objects. The returned option array in the form of a collection of {@link SwatDataTreeNode} objects can be used by other classes, such as {@link SwatTreeFlydown} and {@link @SwatChecklistTree}. @param MDB2_Driver_Common $rs The MDB2 result set, usually the result of a stored procedure. Must be wrapped in . {@link SwatDBRecordsetWrapper}. @param string $title_field_name The name of the database field representing the title @param string $idfield_field_name The name of the database field representing the id @param string $level_field_name the name of the database field representing the tree level. @param SwatDataTreeNode $tree an optional tree to add nodes to. If no tree is specified, nodes are added to a new empty tree. @return SwatDataTreeNode a tree composed of {@link SwatDataTreeNode} objects. @throws SwatDBException
[ "Get", "a", "tree", "of", "data", "nodes" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L1259-L1294
33,884
silverorange/swat
SwatDB/SwatDB.php
SwatDB.implodeSelection
public static function implodeSelection( MDB2_Driver_Common $db, SwatViewSelection $selection, $type = 'integer' ) { $quoted_ids = array(); foreach ($selection as $id) { $quoted_ids[] = $db->quote($id, $type); } return implode(',', $quoted_ids); }
php
public static function implodeSelection( MDB2_Driver_Common $db, SwatViewSelection $selection, $type = 'integer' ) { $quoted_ids = array(); foreach ($selection as $id) { $quoted_ids[] = $db->quote($id, $type); } return implode(',', $quoted_ids); }
[ "public", "static", "function", "implodeSelection", "(", "MDB2_Driver_Common", "$", "db", ",", "SwatViewSelection", "$", "selection", ",", "$", "type", "=", "'integer'", ")", "{", "$", "quoted_ids", "=", "array", "(", ")", ";", "foreach", "(", "$", "selection", "as", "$", "id", ")", "{", "$", "quoted_ids", "[", "]", "=", "$", "db", "->", "quote", "(", "$", "id", ",", "$", "type", ")", ";", "}", "return", "implode", "(", "','", ",", "$", "quoted_ids", ")", ";", "}" ]
Implodes a view selection object Each item in the view is quoted using the specified type. @param MDB2_Driver_Common $db the database connection to use to implode the view. @param SwatViewSelection $selection the selection to implode. @param string $type optional. The datatype to use. Must be a valid MDB2 datatype. If unspecified, 'integer' is used. @return string the imploded view ready for inclusion in an SQL statement.
[ "Implodes", "a", "view", "selection", "object" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatDB/SwatDB.php#L1312-L1323
33,885
rhoone/yii2-rhoone
models/ExtensionQuery.php
ExtensionQuery.enabled
public function enabled($enabled = true) { if (is_bool($enabled)) { return $this->andWhere(['enabled' => $enabled == true ? 1 : 0]); } return $this; }
php
public function enabled($enabled = true) { if (is_bool($enabled)) { return $this->andWhere(['enabled' => $enabled == true ? 1 : 0]); } return $this; }
[ "public", "function", "enabled", "(", "$", "enabled", "=", "true", ")", "{", "if", "(", "is_bool", "(", "$", "enabled", ")", ")", "{", "return", "$", "this", "->", "andWhere", "(", "[", "'enabled'", "=>", "$", "enabled", "==", "true", "?", "1", ":", "0", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Attach enabled condition. @param mixed $enabled @return \static
[ "Attach", "enabled", "condition", "." ]
f6ae90d466ea6f34bba404be0aba03e37ef369ad
https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/models/ExtensionQuery.php#L30-L36
33,886
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.init
public function init() { foreach ($this->renderers as $renderer) { $renderer->init(); } if ($this->id === null) { $this->id = $this->getUniqueId(); $this->has_auto_id = true; } // add the input cell to this column's view's input row if ($this->input_cell !== null) { $input_row = $this->parent->getFirstRowByClass( 'SwatTableViewInputRow' ); if ($input_row === null) { throw new SwatException( 'Table-view does not have an input row.' ); } $input_row->addInputCell($this->input_cell, $this->id); } }
php
public function init() { foreach ($this->renderers as $renderer) { $renderer->init(); } if ($this->id === null) { $this->id = $this->getUniqueId(); $this->has_auto_id = true; } // add the input cell to this column's view's input row if ($this->input_cell !== null) { $input_row = $this->parent->getFirstRowByClass( 'SwatTableViewInputRow' ); if ($input_row === null) { throw new SwatException( 'Table-view does not have an input row.' ); } $input_row->addInputCell($this->input_cell, $this->id); } }
[ "public", "function", "init", "(", ")", "{", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "$", "renderer", "->", "init", "(", ")", ";", "}", "if", "(", "$", "this", "->", "id", "===", "null", ")", "{", "$", "this", "->", "id", "=", "$", "this", "->", "getUniqueId", "(", ")", ";", "$", "this", "->", "has_auto_id", "=", "true", ";", "}", "// add the input cell to this column's view's input row", "if", "(", "$", "this", "->", "input_cell", "!==", "null", ")", "{", "$", "input_row", "=", "$", "this", "->", "parent", "->", "getFirstRowByClass", "(", "'SwatTableViewInputRow'", ")", ";", "if", "(", "$", "input_row", "===", "null", ")", "{", "throw", "new", "SwatException", "(", "'Table-view does not have an input row.'", ")", ";", "}", "$", "input_row", "->", "addInputCell", "(", "$", "this", "->", "input_cell", ",", "$", "this", "->", "id", ")", ";", "}", "}" ]
Initializes this column Gets a unique identifier for this column if one is not provided This calls init on all cell renderers and input cells in this column
[ "Initializes", "this", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L138-L162
33,887
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.displayHeaderCell
public function displayHeaderCell() { if (!$this->visible) { return; } $th_tag = new SwatHtmlTag('th', $this->getThAttributes()); $th_tag->scope = 'col'; $colspan = $this->getXhtmlColspan(); if ($colspan > 1) { $th_tag->colspan = $colspan; } $th_tag->open(); $this->displayHeader(); $th_tag->close(); }
php
public function displayHeaderCell() { if (!$this->visible) { return; } $th_tag = new SwatHtmlTag('th', $this->getThAttributes()); $th_tag->scope = 'col'; $colspan = $this->getXhtmlColspan(); if ($colspan > 1) { $th_tag->colspan = $colspan; } $th_tag->open(); $this->displayHeader(); $th_tag->close(); }
[ "public", "function", "displayHeaderCell", "(", ")", "{", "if", "(", "!", "$", "this", "->", "visible", ")", "{", "return", ";", "}", "$", "th_tag", "=", "new", "SwatHtmlTag", "(", "'th'", ",", "$", "this", "->", "getThAttributes", "(", ")", ")", ";", "$", "th_tag", "->", "scope", "=", "'col'", ";", "$", "colspan", "=", "$", "this", "->", "getXhtmlColspan", "(", ")", ";", "if", "(", "$", "colspan", ">", "1", ")", "{", "$", "th_tag", "->", "colspan", "=", "$", "colspan", ";", "}", "$", "th_tag", "->", "open", "(", ")", ";", "$", "this", "->", "displayHeader", "(", ")", ";", "$", "th_tag", "->", "close", "(", ")", ";", "}" ]
Displays the table-view header cell for this column
[ "Displays", "the", "table", "-", "view", "header", "cell", "for", "this", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L191-L208
33,888
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.display
public function display($row) { if (!$this->visible) { return; } $this->setupRenderers($row); $this->displayRenderers($row); }
php
public function display($row) { if (!$this->visible) { return; } $this->setupRenderers($row); $this->displayRenderers($row); }
[ "public", "function", "display", "(", "$", "row", ")", "{", "if", "(", "!", "$", "this", "->", "visible", ")", "{", "return", ";", "}", "$", "this", "->", "setupRenderers", "(", "$", "row", ")", ";", "$", "this", "->", "displayRenderers", "(", "$", "row", ")", ";", "}" ]
Displays this column using a data object The properties of the cell renderers are set from the data object through the datafield property mappings. @param mixed $row a data object used to display the cell renderers in this column.
[ "Displays", "this", "column", "using", "a", "data", "object" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L257-L265
33,889
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.getMessages
public function getMessages($data) { foreach ($this->renderers as $renderer) { $this->renderers->applyMappingsToRenderer($renderer, $data); } $messages = array(); foreach ($this->renderers as $renderer) { $messages = array_merge($messages, $renderer->getMessages()); } return $messages; }
php
public function getMessages($data) { foreach ($this->renderers as $renderer) { $this->renderers->applyMappingsToRenderer($renderer, $data); } $messages = array(); foreach ($this->renderers as $renderer) { $messages = array_merge($messages, $renderer->getMessages()); } return $messages; }
[ "public", "function", "getMessages", "(", "$", "data", ")", "{", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "$", "this", "->", "renderers", "->", "applyMappingsToRenderer", "(", "$", "renderer", ",", "$", "data", ")", ";", "}", "$", "messages", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "$", "messages", "=", "array_merge", "(", "$", "messages", ",", "$", "renderer", "->", "getMessages", "(", ")", ")", ";", "}", "return", "$", "messages", ";", "}" ]
Gathers all messages from this column for the given data object @param mixed $data the data object to use to check this column for messages. @return array an array of {@link SwatMessage} objects.
[ "Gathers", "all", "messages", "from", "this", "column", "for", "the", "given", "data", "object" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L278-L290
33,890
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.hasMessage
public function hasMessage($data) { foreach ($this->renderers as $renderer) { $this->renderers->applyMappingsToRenderer($renderer, $data); } $has_message = false; foreach ($this->renderers as $renderer) { if ($renderer->hasMessage()) { $has_message = true; break; } } return $has_message; }
php
public function hasMessage($data) { foreach ($this->renderers as $renderer) { $this->renderers->applyMappingsToRenderer($renderer, $data); } $has_message = false; foreach ($this->renderers as $renderer) { if ($renderer->hasMessage()) { $has_message = true; break; } } return $has_message; }
[ "public", "function", "hasMessage", "(", "$", "data", ")", "{", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "$", "this", "->", "renderers", "->", "applyMappingsToRenderer", "(", "$", "renderer", ",", "$", "data", ")", ";", "}", "$", "has_message", "=", "false", ";", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "if", "(", "$", "renderer", "->", "hasMessage", "(", ")", ")", "{", "$", "has_message", "=", "true", ";", "break", ";", "}", "}", "return", "$", "has_message", ";", "}" ]
Gets whether or not this column has any messages for the given data object @param mixed $data the data object to use to check this column for messages. @return boolean true if this table-view column has one or more messages for the given data object and false if it does not.
[ "Gets", "whether", "or", "not", "this", "column", "has", "any", "messages", "for", "the", "given", "data", "object" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L305-L320
33,891
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.getHtmlHeadEntrySet
public function getHtmlHeadEntrySet() { $set = parent::getHtmlHeadEntrySet(); if ($this->input_cell !== null) { $set->addEntrySet($this->input_cell->getHtmlHeadEntrySet()); } return $set; }
php
public function getHtmlHeadEntrySet() { $set = parent::getHtmlHeadEntrySet(); if ($this->input_cell !== null) { $set->addEntrySet($this->input_cell->getHtmlHeadEntrySet()); } return $set; }
[ "public", "function", "getHtmlHeadEntrySet", "(", ")", "{", "$", "set", "=", "parent", "::", "getHtmlHeadEntrySet", "(", ")", ";", "if", "(", "$", "this", "->", "input_cell", "!==", "null", ")", "{", "$", "set", "->", "addEntrySet", "(", "$", "this", "->", "input_cell", "->", "getHtmlHeadEntrySet", "(", ")", ")", ";", "}", "return", "$", "set", ";", "}" ]
Gets the SwatHtmlHeadEntry objects needed by this column @return SwatHtmlHeadEntrySet the SwatHtmlHeadEntry objects needed by this column. @see SwatUIObject::getHtmlHeadEntrySet()
[ "Gets", "the", "SwatHtmlHeadEntry", "objects", "needed", "by", "this", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L546-L555
33,892
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.getAvailableHtmlHeadEntrySet
public function getAvailableHtmlHeadEntrySet() { $set = parent::getAvailableHtmlHeadEntrySet(); if ($this->input_cell !== null) { $set->addEntrySet( $this->input_cell->getAvailableHtmlHeadEntrySet() ); } return $set; }
php
public function getAvailableHtmlHeadEntrySet() { $set = parent::getAvailableHtmlHeadEntrySet(); if ($this->input_cell !== null) { $set->addEntrySet( $this->input_cell->getAvailableHtmlHeadEntrySet() ); } return $set; }
[ "public", "function", "getAvailableHtmlHeadEntrySet", "(", ")", "{", "$", "set", "=", "parent", "::", "getAvailableHtmlHeadEntrySet", "(", ")", ";", "if", "(", "$", "this", "->", "input_cell", "!==", "null", ")", "{", "$", "set", "->", "addEntrySet", "(", "$", "this", "->", "input_cell", "->", "getAvailableHtmlHeadEntrySet", "(", ")", ")", ";", "}", "return", "$", "set", ";", "}" ]
Gets the SwatHtmlHeadEntry objects that may be needed by this column @return SwatHtmlHeadEntrySet the SwatHtmlHeadEntry objects that may be needed by this column. @see SwatUIObject::getAvailableHtmlHeadEntrySet()
[ "Gets", "the", "SwatHtmlHeadEntry", "objects", "that", "may", "be", "needed", "by", "this", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L568-L579
33,893
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.hasVisibleRenderer
public function hasVisibleRenderer($row) { $this->setupRenderers($row); $visible_renderers = false; foreach ($this->renderers as $renderer) { if ($renderer->visible) { $visible_renderers = true; break; } } return $visible_renderers; }
php
public function hasVisibleRenderer($row) { $this->setupRenderers($row); $visible_renderers = false; foreach ($this->renderers as $renderer) { if ($renderer->visible) { $visible_renderers = true; break; } } return $visible_renderers; }
[ "public", "function", "hasVisibleRenderer", "(", "$", "row", ")", "{", "$", "this", "->", "setupRenderers", "(", "$", "row", ")", ";", "$", "visible_renderers", "=", "false", ";", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "if", "(", "$", "renderer", "->", "visible", ")", "{", "$", "visible_renderers", "=", "true", ";", "break", ";", "}", "}", "return", "$", "visible_renderers", ";", "}" ]
Whether or not this column has one or more visible cell renderers @param mixed $row a data object containing the data for a single row in the table store for this group. This object may affect the visibility of renderers in this column. @return boolean true if this column has one or more visible cell renderers and false if it does not.
[ "Whether", "or", "not", "this", "column", "has", "one", "or", "more", "visible", "cell", "renderers" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L642-L656
33,894
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.displayRenderersInternal
protected function displayRenderersInternal($data) { if (count($this->renderers) === 1) { $this->renderers->getFirst()->render(); } else { $div_tag = new SwatHtmlTag('div'); $first = true; foreach ($this->renderers as $renderer) { if (!$renderer->visible) { continue; } if ($first) { $first = false; } else { echo ' '; } // get renderer class names $classes = array('swat-table-view-column-renderer'); $classes = array_merge( $classes, $renderer->getInheritanceCSSClassNames() ); $classes = array_merge( $classes, $renderer->getBaseCSSClassNames() ); $classes = array_merge( $classes, $renderer->getDataSpecificCSSClassNames() ); $classes = array_merge($classes, $renderer->classes); $div_tag->class = implode(' ', $classes); $div_tag->open(); $renderer->render(); $div_tag->close(); } } }
php
protected function displayRenderersInternal($data) { if (count($this->renderers) === 1) { $this->renderers->getFirst()->render(); } else { $div_tag = new SwatHtmlTag('div'); $first = true; foreach ($this->renderers as $renderer) { if (!$renderer->visible) { continue; } if ($first) { $first = false; } else { echo ' '; } // get renderer class names $classes = array('swat-table-view-column-renderer'); $classes = array_merge( $classes, $renderer->getInheritanceCSSClassNames() ); $classes = array_merge( $classes, $renderer->getBaseCSSClassNames() ); $classes = array_merge( $classes, $renderer->getDataSpecificCSSClassNames() ); $classes = array_merge($classes, $renderer->classes); $div_tag->class = implode(' ', $classes); $div_tag->open(); $renderer->render(); $div_tag->close(); } } }
[ "protected", "function", "displayRenderersInternal", "(", "$", "data", ")", "{", "if", "(", "count", "(", "$", "this", "->", "renderers", ")", "===", "1", ")", "{", "$", "this", "->", "renderers", "->", "getFirst", "(", ")", "->", "render", "(", ")", ";", "}", "else", "{", "$", "div_tag", "=", "new", "SwatHtmlTag", "(", "'div'", ")", ";", "$", "first", "=", "true", ";", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "if", "(", "!", "$", "renderer", "->", "visible", ")", "{", "continue", ";", "}", "if", "(", "$", "first", ")", "{", "$", "first", "=", "false", ";", "}", "else", "{", "echo", "' '", ";", "}", "// get renderer class names", "$", "classes", "=", "array", "(", "'swat-table-view-column-renderer'", ")", ";", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "renderer", "->", "getInheritanceCSSClassNames", "(", ")", ")", ";", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "renderer", "->", "getBaseCSSClassNames", "(", ")", ")", ";", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "renderer", "->", "getDataSpecificCSSClassNames", "(", ")", ")", ";", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "renderer", "->", "classes", ")", ";", "$", "div_tag", "->", "class", "=", "implode", "(", "' '", ",", "$", "classes", ")", ";", "$", "div_tag", "->", "open", "(", ")", ";", "$", "renderer", "->", "render", "(", ")", ";", "$", "div_tag", "->", "close", "(", ")", ";", "}", "}", "}" ]
Renders each cell renderer in this column If there is once cell renderer in this column, it is rendered by itself. If there is more than one cell renderer in this column, cell renderers are rendered in order inside separate <i>div</i> elements. Each <i>div</i> element is separated with a breaking space character and the div elements are displayed inline by default. @param mixed $data the data object being used to render the cell renderers of this field.
[ "Renders", "each", "cell", "renderer", "in", "this", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L728-L772
33,895
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.setupRenderers
protected function setupRenderers($data) { if (count($this->renderers) === 0) { throw new SwatException( 'No renderer has been provided for this column.' ); } $sensitive = $this->view->isSensitive(); // Set the properties of the renderers to the value of the data field. foreach ($this->renderers as $renderer) { $this->renderers->applyMappingsToRenderer($renderer, $data); $renderer->sensitive = $renderer->sensitive && $sensitive; } }
php
protected function setupRenderers($data) { if (count($this->renderers) === 0) { throw new SwatException( 'No renderer has been provided for this column.' ); } $sensitive = $this->view->isSensitive(); // Set the properties of the renderers to the value of the data field. foreach ($this->renderers as $renderer) { $this->renderers->applyMappingsToRenderer($renderer, $data); $renderer->sensitive = $renderer->sensitive && $sensitive; } }
[ "protected", "function", "setupRenderers", "(", "$", "data", ")", "{", "if", "(", "count", "(", "$", "this", "->", "renderers", ")", "===", "0", ")", "{", "throw", "new", "SwatException", "(", "'No renderer has been provided for this column.'", ")", ";", "}", "$", "sensitive", "=", "$", "this", "->", "view", "->", "isSensitive", "(", ")", ";", "// Set the properties of the renderers to the value of the data field.", "foreach", "(", "$", "this", "->", "renderers", "as", "$", "renderer", ")", "{", "$", "this", "->", "renderers", "->", "applyMappingsToRenderer", "(", "$", "renderer", ",", "$", "data", ")", ";", "$", "renderer", "->", "sensitive", "=", "$", "renderer", "->", "sensitive", "&&", "$", "sensitive", ";", "}", "}" ]
Sets properties of renderers using data from current row @param mixed $data the data object being used to render the cell renderers of this field.
[ "Sets", "properties", "of", "renderers", "using", "data", "from", "current", "row" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L783-L798
33,896
silverorange/swat
Swat/SwatTableViewColumn.php
SwatTableViewColumn.getCSSClassNames
protected function getCSSClassNames() { $classes = array(); // instance specific class if ($this->id !== null && !$this->has_auto_id) { $column_class = str_replace('_', '-', $this->id); $classes[] = $column_class; } // base classes $classes = array_merge($classes, $this->getBaseCSSClassNames()); // user-specified classes $classes = array_merge($classes, $this->classes); $first_renderer = $this->renderers->getFirst(); if ( $this->show_renderer_classes && $first_renderer instanceof SwatCellRenderer ) { // renderer inheritance classes $classes = array_merge( $classes, $first_renderer->getInheritanceCSSClassNames() ); // renderer base classes $classes = array_merge( $classes, $first_renderer->getBaseCSSClassNames() ); // renderer data specific classes if ($this->renderers->mappingsApplied()) { $classes = array_merge( $classes, $first_renderer->getDataSpecificCSSClassNames() ); } // renderer user-specified classes $classes = array_merge($classes, $first_renderer->classes); } return $classes; }
php
protected function getCSSClassNames() { $classes = array(); // instance specific class if ($this->id !== null && !$this->has_auto_id) { $column_class = str_replace('_', '-', $this->id); $classes[] = $column_class; } // base classes $classes = array_merge($classes, $this->getBaseCSSClassNames()); // user-specified classes $classes = array_merge($classes, $this->classes); $first_renderer = $this->renderers->getFirst(); if ( $this->show_renderer_classes && $first_renderer instanceof SwatCellRenderer ) { // renderer inheritance classes $classes = array_merge( $classes, $first_renderer->getInheritanceCSSClassNames() ); // renderer base classes $classes = array_merge( $classes, $first_renderer->getBaseCSSClassNames() ); // renderer data specific classes if ($this->renderers->mappingsApplied()) { $classes = array_merge( $classes, $first_renderer->getDataSpecificCSSClassNames() ); } // renderer user-specified classes $classes = array_merge($classes, $first_renderer->classes); } return $classes; }
[ "protected", "function", "getCSSClassNames", "(", ")", "{", "$", "classes", "=", "array", "(", ")", ";", "// instance specific class", "if", "(", "$", "this", "->", "id", "!==", "null", "&&", "!", "$", "this", "->", "has_auto_id", ")", "{", "$", "column_class", "=", "str_replace", "(", "'_'", ",", "'-'", ",", "$", "this", "->", "id", ")", ";", "$", "classes", "[", "]", "=", "$", "column_class", ";", "}", "// base classes", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "this", "->", "getBaseCSSClassNames", "(", ")", ")", ";", "// user-specified classes", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "this", "->", "classes", ")", ";", "$", "first_renderer", "=", "$", "this", "->", "renderers", "->", "getFirst", "(", ")", ";", "if", "(", "$", "this", "->", "show_renderer_classes", "&&", "$", "first_renderer", "instanceof", "SwatCellRenderer", ")", "{", "// renderer inheritance classes", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "first_renderer", "->", "getInheritanceCSSClassNames", "(", ")", ")", ";", "// renderer base classes", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "first_renderer", "->", "getBaseCSSClassNames", "(", ")", ")", ";", "// renderer data specific classes", "if", "(", "$", "this", "->", "renderers", "->", "mappingsApplied", "(", ")", ")", "{", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "first_renderer", "->", "getDataSpecificCSSClassNames", "(", ")", ")", ";", "}", "// renderer user-specified classes", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "first_renderer", "->", "classes", ")", ";", "}", "return", "$", "classes", ";", "}" ]
Gets the array of CSS classes that are applied to this table-view column CSS classes are added to this column in the following order: 1. a CSS class representing cells in this column's instance if this column has an id set, 2. hard-coded CSS classes from column subclasses, 3. user-specified CSS classes on this column, If {@link SwatTableViewColumn::$show_renderer_classes} is true, the following extra CSS classes are added: 4. the inheritance classes of the first cell renderer in this column, 5. hard-coded CSS classes from the first cell renderer in this column, 6. hard-coded data-specific CSS classes from the first cell renderer in this column if this column has data mappings applied, 7. user-specified CSS classes on the first cell renderer in this column. @return array the array of CSS classes that are applied to this table-view column. @see SwatCellRenderer::getInheritanceCSSClassNames() @see SwatCellRenderer::getBaseCSSClassNames() @see SwatUIObject::getCSSClassNames()
[ "Gets", "the", "array", "of", "CSS", "classes", "that", "are", "applied", "to", "this", "table", "-", "view", "column" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewColumn.php#L829-L875
33,897
silverorange/swat
Swat/SwatButton.php
SwatButton.display
public function display() { if (!$this->visible) { return; } parent::display(); $input_tag = $this->getInputTag(); $input_tag->display(); if ( $this->show_processing_throbber || $this->confirmation_message !== null ) { Swat::displayInlineJavaScript($this->getInlineJavaScript()); } }
php
public function display() { if (!$this->visible) { return; } parent::display(); $input_tag = $this->getInputTag(); $input_tag->display(); if ( $this->show_processing_throbber || $this->confirmation_message !== null ) { Swat::displayInlineJavaScript($this->getInlineJavaScript()); } }
[ "public", "function", "display", "(", ")", "{", "if", "(", "!", "$", "this", "->", "visible", ")", "{", "return", ";", "}", "parent", "::", "display", "(", ")", ";", "$", "input_tag", "=", "$", "this", "->", "getInputTag", "(", ")", ";", "$", "input_tag", "->", "display", "(", ")", ";", "if", "(", "$", "this", "->", "show_processing_throbber", "||", "$", "this", "->", "confirmation_message", "!==", "null", ")", "{", "Swat", "::", "displayInlineJavaScript", "(", "$", "this", "->", "getInlineJavaScript", "(", ")", ")", ";", "}", "}" ]
Displays this button Outputs an XHTML input tag.
[ "Displays", "this", "button" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatButton.php#L157-L174
33,898
silverorange/swat
Swat/SwatButton.php
SwatButton.process
public function process() { parent::process(); $data = &$this->getForm()->getFormData(); if (isset($data[$this->id])) { $this->clicked = true; $this->getForm()->button = $this; } }
php
public function process() { parent::process(); $data = &$this->getForm()->getFormData(); if (isset($data[$this->id])) { $this->clicked = true; $this->getForm()->button = $this; } }
[ "public", "function", "process", "(", ")", "{", "parent", "::", "process", "(", ")", ";", "$", "data", "=", "&", "$", "this", "->", "getForm", "(", ")", "->", "getFormData", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "$", "this", "->", "id", "]", ")", ")", "{", "$", "this", "->", "clicked", "=", "true", ";", "$", "this", "->", "getForm", "(", ")", "->", "button", "=", "$", "this", ";", "}", "}" ]
Does button processing Sets whether this button has been clicked and also updates the form this button belongs to with a reference to this button if this button submitted the form.
[ "Does", "button", "processing" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatButton.php#L186-L196
33,899
silverorange/swat
Swat/SwatButton.php
SwatButton.setFromStock
public function setFromStock($stock_id, $overwrite_properties = true) { switch ($stock_id) { case 'submit': $title = Swat::_('Submit'); $class = 'swat-button-submit'; break; case 'create': $title = Swat::_('Create'); $class = 'swat-button-create'; break; case 'add': $title = Swat::_('Add'); $class = 'swat-button-add'; break; case 'apply': $title = Swat::_('Apply'); $class = 'swat-button-apply'; break; case 'delete': $title = Swat::_('Delete'); $class = 'swat-button-delete'; break; case 'cancel': $title = Swat::_('Cancel'); $class = 'swat-button-cancel'; break; default: throw new SwatUndefinedStockTypeException( "Stock type with id of '{$stock_id}' not found.", 0, $stock_id ); } if ($overwrite_properties || $this->title === null) { $this->title = $title; } $this->stock_class = $class; }
php
public function setFromStock($stock_id, $overwrite_properties = true) { switch ($stock_id) { case 'submit': $title = Swat::_('Submit'); $class = 'swat-button-submit'; break; case 'create': $title = Swat::_('Create'); $class = 'swat-button-create'; break; case 'add': $title = Swat::_('Add'); $class = 'swat-button-add'; break; case 'apply': $title = Swat::_('Apply'); $class = 'swat-button-apply'; break; case 'delete': $title = Swat::_('Delete'); $class = 'swat-button-delete'; break; case 'cancel': $title = Swat::_('Cancel'); $class = 'swat-button-cancel'; break; default: throw new SwatUndefinedStockTypeException( "Stock type with id of '{$stock_id}' not found.", 0, $stock_id ); } if ($overwrite_properties || $this->title === null) { $this->title = $title; } $this->stock_class = $class; }
[ "public", "function", "setFromStock", "(", "$", "stock_id", ",", "$", "overwrite_properties", "=", "true", ")", "{", "switch", "(", "$", "stock_id", ")", "{", "case", "'submit'", ":", "$", "title", "=", "Swat", "::", "_", "(", "'Submit'", ")", ";", "$", "class", "=", "'swat-button-submit'", ";", "break", ";", "case", "'create'", ":", "$", "title", "=", "Swat", "::", "_", "(", "'Create'", ")", ";", "$", "class", "=", "'swat-button-create'", ";", "break", ";", "case", "'add'", ":", "$", "title", "=", "Swat", "::", "_", "(", "'Add'", ")", ";", "$", "class", "=", "'swat-button-add'", ";", "break", ";", "case", "'apply'", ":", "$", "title", "=", "Swat", "::", "_", "(", "'Apply'", ")", ";", "$", "class", "=", "'swat-button-apply'", ";", "break", ";", "case", "'delete'", ":", "$", "title", "=", "Swat", "::", "_", "(", "'Delete'", ")", ";", "$", "class", "=", "'swat-button-delete'", ";", "break", ";", "case", "'cancel'", ":", "$", "title", "=", "Swat", "::", "_", "(", "'Cancel'", ")", ";", "$", "class", "=", "'swat-button-cancel'", ";", "break", ";", "default", ":", "throw", "new", "SwatUndefinedStockTypeException", "(", "\"Stock type with id of '{$stock_id}' not found.\"", ",", "0", ",", "$", "stock_id", ")", ";", "}", "if", "(", "$", "overwrite_properties", "||", "$", "this", "->", "title", "===", "null", ")", "{", "$", "this", "->", "title", "=", "$", "title", ";", "}", "$", "this", "->", "stock_class", "=", "$", "class", ";", "}" ]
Sets the values of this button to a stock type Valid stock type ids are: - submit - create - add - apply - delete - cancel @param string $stock_id the identifier of the stock type to use. @param boolean $overwrite_properties whether to overwrite properties if they are already set. @throws SwatUndefinedStockTypeException
[ "Sets", "the", "values", "of", "this", "button", "to", "a", "stock", "type" ]
e65dc5bc351927c61f594068430cdeeb874c8bc5
https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatButton.php#L232-L278