repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.getWidget | public function getWidget($replicator_id, $widget_id = null)
{
$widget = null;
if ($widget_id === null) {
if (isset($this->widgets[$replicator_id])) {
$widget = current($this->widgets[$replicator_id]);
}
} else {
if (isset($this->widgets[$replicator_id][$widget_id])) {
$widget = $this->widgets[$replicator_id][$widget_id];
}
}
return $widget;
} | php | public function getWidget($replicator_id, $widget_id = null)
{
$widget = null;
if ($widget_id === null) {
if (isset($this->widgets[$replicator_id])) {
$widget = current($this->widgets[$replicator_id]);
}
} else {
if (isset($this->widgets[$replicator_id][$widget_id])) {
$widget = $this->widgets[$replicator_id][$widget_id];
}
}
return $widget;
} | [
"public",
"function",
"getWidget",
"(",
"$",
"replicator_id",
",",
"$",
"widget_id",
"=",
"null",
")",
"{",
"$",
"widget",
"=",
"null",
";",
"if",
"(",
"$",
"widget_id",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"widgets",
... | Retrieves a reference to a replicated widget
@param string $replicator_id the replicator id of the replicated widget
@param string $widget_id the unique id of the original widget, or null
to get the root
@return SwatWidget a reference to the replicated widget, or null if the
widget is not found. | [
"Retrieves",
"a",
"reference",
"to",
"a",
"replicated",
"widget"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L308-L323 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.getWidgets | public function getWidgets($widget_id = null)
{
$form = $this->getForm();
if ($form !== null && $form->isSubmitted()) {
$replicators = $form->getHiddenField(
$this->getReplicatorFieldName()
);
$widgets = array();
if (is_array($replicators)) {
foreach ($this->clones as $replicator_id => $clone) {
if (in_array($replicator_id, $replicators)) {
if (
$widget_id !== null &&
!isset($this->widgets[$replicator_id][$widget_id])
) {
throw new SwatWidgetNotFoundException(
sprintf(
'No widget with the id "%s" exists in the ' .
'cloned widget sub-tree of this ' .
'SwatWidgetCellRenderer.',
$widget_id
),
0,
$widget_id
);
}
$widgets[$replicator_id] = $this->getWidget(
$replicator_id,
$widget_id
);
}
}
}
} else {
$widgets = $this->clones;
}
return $widgets;
} | php | public function getWidgets($widget_id = null)
{
$form = $this->getForm();
if ($form !== null && $form->isSubmitted()) {
$replicators = $form->getHiddenField(
$this->getReplicatorFieldName()
);
$widgets = array();
if (is_array($replicators)) {
foreach ($this->clones as $replicator_id => $clone) {
if (in_array($replicator_id, $replicators)) {
if (
$widget_id !== null &&
!isset($this->widgets[$replicator_id][$widget_id])
) {
throw new SwatWidgetNotFoundException(
sprintf(
'No widget with the id "%s" exists in the ' .
'cloned widget sub-tree of this ' .
'SwatWidgetCellRenderer.',
$widget_id
),
0,
$widget_id
);
}
$widgets[$replicator_id] = $this->getWidget(
$replicator_id,
$widget_id
);
}
}
}
} else {
$widgets = $this->clones;
}
return $widgets;
} | [
"public",
"function",
"getWidgets",
"(",
"$",
"widget_id",
"=",
"null",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"getForm",
"(",
")",
";",
"if",
"(",
"$",
"form",
"!==",
"null",
"&&",
"$",
"form",
"->",
"isSubmitted",
"(",
")",
")",
"{",
"$... | Gets an array of replicated widgets indexed by the replicator_id
If this cell renderer's form is submitted, only cloned widgets that were
displayed and processed are returned.
@param string $widget_id the unique id of the original widget, or null
to get the root
@return array an array of widgets indexed by replicator_id
@throws SwatWidgetNotFoundException if a widget id is specified and no
such widget exists in the subtree. | [
"Gets",
"an",
"array",
"of",
"replicated",
"widgets",
"indexed",
"by",
"the",
"replicator_id"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L342-L382 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.& | public function &getClonedWidgets()
{
$form = $this->getForm();
if ($form !== null && $form->isSubmitted()) {
$replicators = $form->getHiddenField(
$this->getReplicatorFieldName()
);
$clones = array();
foreach ($this->clones as $replicator_id => $clone) {
if (
is_array($replicators) &&
in_array($replicator_id, $replicators)
) {
$clones[$replicator_id] = $clone;
}
}
} else {
$clones = $this->clones;
}
return $clones;
} | php | public function &getClonedWidgets()
{
$form = $this->getForm();
if ($form !== null && $form->isSubmitted()) {
$replicators = $form->getHiddenField(
$this->getReplicatorFieldName()
);
$clones = array();
foreach ($this->clones as $replicator_id => $clone) {
if (
is_array($replicators) &&
in_array($replicator_id, $replicators)
) {
$clones[$replicator_id] = $clone;
}
}
} else {
$clones = $this->clones;
}
return $clones;
} | [
"public",
"function",
"&",
"getClonedWidgets",
"(",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"getForm",
"(",
")",
";",
"if",
"(",
"$",
"form",
"!==",
"null",
"&&",
"$",
"form",
"->",
"isSubmitted",
"(",
")",
")",
"{",
"$",
"replicators",
"=",... | Gets an array of cloned widgets indexed by the replicator_id
If this cell renderer's form is submitted, only cloned widgets that were
displayed and processed are returned.
@deprecated Use {@link SwatWidgetCellRenderer::getWidgets()} instead.
Pass null to getWidgets() for the same output as this
method.
@return array an array of widgets indexed by replicator_id | [
"Gets",
"an",
"array",
"of",
"cloned",
"widgets",
"indexed",
"by",
"the",
"replicator_id"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L399-L421 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.getDataSpecificCSSClassNames | public function getDataSpecificCSSClassNames()
{
$classes = array();
if (
$this->replicator_id !== null &&
$this->hasMessage($this->replicator_id)
) {
$classes[] = 'swat-error';
}
return $classes;
} | php | public function getDataSpecificCSSClassNames()
{
$classes = array();
if (
$this->replicator_id !== null &&
$this->hasMessage($this->replicator_id)
) {
$classes[] = 'swat-error';
}
return $classes;
} | [
"public",
"function",
"getDataSpecificCSSClassNames",
"(",
")",
"{",
"$",
"classes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"replicator_id",
"!==",
"null",
"&&",
"$",
"this",
"->",
"hasMessage",
"(",
"$",
"this",
"->",
"replicator_id",
... | Gets the data specific CSS class names for this widget cell renderer
If the widget within this cell renderer has messages, a CSS class of
'swat-error' is added to the base CSS classes of this cell renderer.
@return array the array of data specific CSS class names for this widget
cell-renderer. | [
"Gets",
"the",
"data",
"specific",
"CSS",
"class",
"names",
"for",
"this",
"widget",
"cell",
"renderer"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L435-L447 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.getMessages | public function getMessages($replicator_id = null)
{
$messages = array();
if ($replicator_id !== null) {
$messages = $this->getClonedWidget($replicator_id)->getMessages();
} elseif ($this->replicator_id !== null) {
$messages = $this->getClonedWidget(
$this->replicator_id
)->getMessages();
}
return $messages;
} | php | public function getMessages($replicator_id = null)
{
$messages = array();
if ($replicator_id !== null) {
$messages = $this->getClonedWidget($replicator_id)->getMessages();
} elseif ($this->replicator_id !== null) {
$messages = $this->getClonedWidget(
$this->replicator_id
)->getMessages();
}
return $messages;
} | [
"public",
"function",
"getMessages",
"(",
"$",
"replicator_id",
"=",
"null",
")",
"{",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"replicator_id",
"!==",
"null",
")",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"getClonedWidget",
"... | Gathers all messages from the widget of this cell renderer for the given
replicator id
@param mixed $replicator_id an optional replicator id of the row to
gather messages from. If no replicator id
is specified, the current replicator_id is
used.
@return array an array of {@link SwatMessage} objects. | [
"Gathers",
"all",
"messages",
"from",
"the",
"widget",
"of",
"this",
"cell",
"renderer",
"for",
"the",
"given",
"replicator",
"id"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L463-L476 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.hasMessage | public function hasMessage($replicator_id = null)
{
$has_message = false;
if ($replicator_id !== null) {
$has_message = $this->getClonedWidget($replicator_id)->hasMessage();
} elseif ($this->replicator_id !== null) {
$has_message = $this->getClonedWidget(
$this->replicator_id
)->hasMessage();
}
return $has_message;
} | php | public function hasMessage($replicator_id = null)
{
$has_message = false;
if ($replicator_id !== null) {
$has_message = $this->getClonedWidget($replicator_id)->hasMessage();
} elseif ($this->replicator_id !== null) {
$has_message = $this->getClonedWidget(
$this->replicator_id
)->hasMessage();
}
return $has_message;
} | [
"public",
"function",
"hasMessage",
"(",
"$",
"replicator_id",
"=",
"null",
")",
"{",
"$",
"has_message",
"=",
"false",
";",
"if",
"(",
"$",
"replicator_id",
"!==",
"null",
")",
"{",
"$",
"has_message",
"=",
"$",
"this",
"->",
"getClonedWidget",
"(",
"$"... | Gets whether or not this widget cell renderer has messages
@param mixed $replicator_id an optional replicator id of the row to
check for messages. If no replicator id is
specified, the current replicator_id is
used.
@return boolean true if this widget cell renderer has one or more
messages for the given replicator id and false if it
does not. | [
"Gets",
"whether",
"or",
"not",
"this",
"widget",
"cell",
"renderer",
"has",
"messages"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L493-L506 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.getTitle | public function getTitle()
{
$title = null;
if (isset($this->parent->title)) {
$title = $this->parent->title;
}
return $title;
} | php | public function getTitle()
{
$title = null;
if (isset($this->parent->title)) {
$title = $this->parent->title;
}
return $title;
} | [
"public",
"function",
"getTitle",
"(",
")",
"{",
"$",
"title",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"parent",
"->",
"title",
")",
")",
"{",
"$",
"title",
"=",
"$",
"this",
"->",
"parent",
"->",
"title",
";",
"}",
"return"... | Gets the title of this widget cell renderer
The title is taken from this cell renderer's parent.
Satisfies the {SwatTitleable::getTitle()} interface.
@return string the title of this widget cell renderer. | [
"Gets",
"the",
"title",
"of",
"this",
"widget",
"cell",
"renderer"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L519-L528 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.getTitleContentType | public function getTitleContentType()
{
$title_content_type = 'text/plain';
if (isset($this->parent->title_content_type)) {
$title_content_type = $this->parent->title_content_type;
}
return $title_content_type;
} | php | public function getTitleContentType()
{
$title_content_type = 'text/plain';
if (isset($this->parent->title_content_type)) {
$title_content_type = $this->parent->title_content_type;
}
return $title_content_type;
} | [
"public",
"function",
"getTitleContentType",
"(",
")",
"{",
"$",
"title_content_type",
"=",
"'text/plain'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"parent",
"->",
"title_content_type",
")",
")",
"{",
"$",
"title_content_type",
"=",
"$",
"this",
"->... | Gets the title content-type of this widget cell renderer
Implements the {@link SwatTitleable::getTitleContentType()} interface.
@return string the title content-type of this widget cell renderer. | [
"Gets",
"the",
"title",
"content",
"-",
"type",
"of",
"this",
"widget",
"cell",
"renderer"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L540-L549 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.getHtmlHeadEntrySet | public function getHtmlHeadEntrySet()
{
$set = parent::getHtmlHeadEntrySet();
if ($this->using_null_replication) {
$set->addEntrySet(
$this->getPrototypeWidget()->getHtmlHeadEntrySet()
);
} else {
$widgets = $this->getWidgets();
foreach ($widgets as $widget) {
$set->addEntrySet($widget->getHtmlHeadEntrySet());
}
}
return $set;
} | php | public function getHtmlHeadEntrySet()
{
$set = parent::getHtmlHeadEntrySet();
if ($this->using_null_replication) {
$set->addEntrySet(
$this->getPrototypeWidget()->getHtmlHeadEntrySet()
);
} else {
$widgets = $this->getWidgets();
foreach ($widgets as $widget) {
$set->addEntrySet($widget->getHtmlHeadEntrySet());
}
}
return $set;
} | [
"public",
"function",
"getHtmlHeadEntrySet",
"(",
")",
"{",
"$",
"set",
"=",
"parent",
"::",
"getHtmlHeadEntrySet",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"using_null_replication",
")",
"{",
"$",
"set",
"->",
"addEntrySet",
"(",
"$",
"this",
"->",
... | Gets the SwatHtmlHeadEntry objects needed by this widget cell renderer
@return SwatHtmlHeadEntrySet the SwatHtmlHeadEntry objects needed by
this widget cell renderer.
@see SwatUIObject::getHtmlHeadEntrySet() | [
"Gets",
"the",
"SwatHtmlHeadEntry",
"objects",
"needed",
"by",
"this",
"widget",
"cell",
"renderer"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L562-L578 | train |
silverorange/swat | Swat/SwatWidgetCellRenderer.php | SwatWidgetCellRenderer.getAvailableHtmlHeadEntrySet | public function getAvailableHtmlHeadEntrySet()
{
$set = parent::getAvailableHtmlHeadEntrySet();
if ($this->using_null_replication) {
$set->addEntrySet(
$this->getPrototypeWidget()->getAvailableHtmlHeadEntrySet()
);
} else {
$widgets = $this->getWidgets();
foreach ($widgets as $widget) {
$set->addEntrySet($widget->getAvailableHtmlHeadEntrySet());
}
}
return $set;
} | php | public function getAvailableHtmlHeadEntrySet()
{
$set = parent::getAvailableHtmlHeadEntrySet();
if ($this->using_null_replication) {
$set->addEntrySet(
$this->getPrototypeWidget()->getAvailableHtmlHeadEntrySet()
);
} else {
$widgets = $this->getWidgets();
foreach ($widgets as $widget) {
$set->addEntrySet($widget->getAvailableHtmlHeadEntrySet());
}
}
return $set;
} | [
"public",
"function",
"getAvailableHtmlHeadEntrySet",
"(",
")",
"{",
"$",
"set",
"=",
"parent",
"::",
"getAvailableHtmlHeadEntrySet",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"using_null_replication",
")",
"{",
"$",
"set",
"->",
"addEntrySet",
"(",
"$",
... | Gets the SwatHtmlHeadEntry objects that may be needed by this widget
cell renderer
@return SwatHtmlHeadEntrySet the SwatHtmlHeadEntry objects that may be
needed by this widget cell renderer.
@see SwatUIObject::getAvailableHtmlHeadEntrySet() | [
"Gets",
"the",
"SwatHtmlHeadEntry",
"objects",
"that",
"may",
"be",
"needed",
"by",
"this",
"widget",
"cell",
"renderer"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatWidgetCellRenderer.php#L592-L608 | train |
silverorange/swat | Swat/SwatContentBlock.php | SwatContentBlock.display | public function display()
{
if (!$this->visible) {
return;
}
parent::display();
if ($this->content_type === 'text/plain') {
echo SwatString::minimizeEntities($this->content);
} else {
echo $this->content;
}
} | php | public function display()
{
if (!$this->visible) {
return;
}
parent::display();
if ($this->content_type === 'text/plain') {
echo SwatString::minimizeEntities($this->content);
} else {
echo $this->content;
}
} | [
"public",
"function",
"display",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"visible",
")",
"{",
"return",
";",
"}",
"parent",
"::",
"display",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"content_type",
"===",
"'text/plain'",
")",
"{",
"ec... | Displays this content
Merely performs an echo of the content. | [
"Displays",
"this",
"content"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatContentBlock.php#L38-L51 | train |
brainworxx/kreXX | src/Controller/EditSettingsController.php | EditSettingsController.editSettingsAction | public function editSettingsAction()
{
if ($this->pool->emergencyHandler->checkMaxCall() === true) {
// Called too often, we might get into trouble here!
return $this;
}
$this->pool->reset();
// We will not check this for the cookie config, to avoid people locking
// themselves out.
$this->pool->emergencyHandler->setDisable(true);
// Find caller.
$caller = $this->callerFinder->findCaller('Cookie Configuration', array());
$this->pool->chunks->addMetadata($caller);
// Render it.
$footer = $this->outputFooter($caller, true);
$this->pool->chunks->detectEncoding($footer);
$this->outputService
->addChunkString($this->pool->render->renderHeader('Edit local settings', $this->outputCssAndJs()))
->addChunkString($footer);
$this->pool->emergencyHandler->setDisable(false);
$this->outputService->finalize();
return $this;
} | php | public function editSettingsAction()
{
if ($this->pool->emergencyHandler->checkMaxCall() === true) {
// Called too often, we might get into trouble here!
return $this;
}
$this->pool->reset();
// We will not check this for the cookie config, to avoid people locking
// themselves out.
$this->pool->emergencyHandler->setDisable(true);
// Find caller.
$caller = $this->callerFinder->findCaller('Cookie Configuration', array());
$this->pool->chunks->addMetadata($caller);
// Render it.
$footer = $this->outputFooter($caller, true);
$this->pool->chunks->detectEncoding($footer);
$this->outputService
->addChunkString($this->pool->render->renderHeader('Edit local settings', $this->outputCssAndJs()))
->addChunkString($footer);
$this->pool->emergencyHandler->setDisable(false);
$this->outputService->finalize();
return $this;
} | [
"public",
"function",
"editSettingsAction",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pool",
"->",
"emergencyHandler",
"->",
"checkMaxCall",
"(",
")",
"===",
"true",
")",
"{",
"// Called too often, we might get into trouble here!",
"return",
"$",
"this",
";",
... | Outputs the edit settings dialog, without any analysis.
@return $this
Return $this for chaining | [
"Outputs",
"the",
"edit",
"settings",
"dialog",
"without",
"any",
"analysis",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Controller/EditSettingsController.php#L50-L78 | train |
brainworxx/kreXX | src/Controller/AbstractController.php | AbstractController.outputFooter | protected function outputFooter(array $caller, $isExpanded = false)
{
// Now we need to stitch together the content of the ini file
// as well as it's path.
$pathToIni = $this->pool->config->getPathToIniFile();
if ($this->pool->fileService->fileIsReadable($pathToIni) === true) {
$path = $this->pool->messages->getHelp('currentConfig');
} else {
// Project settings are not accessible
// tell the user, that we are using fallback settings.
$path = $this->pool->messages->getHelp('iniNotFound');
}
$model = $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model')
->setName($path)
->setType($this->pool->fileService->filterFilePath($pathToIni))
->setHelpid('currentSettings')
->injectCallback(
$this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughConfig')
);
return $this->pool->render->renderFooter(
$caller,
$model,
$isExpanded
);
} | php | protected function outputFooter(array $caller, $isExpanded = false)
{
// Now we need to stitch together the content of the ini file
// as well as it's path.
$pathToIni = $this->pool->config->getPathToIniFile();
if ($this->pool->fileService->fileIsReadable($pathToIni) === true) {
$path = $this->pool->messages->getHelp('currentConfig');
} else {
// Project settings are not accessible
// tell the user, that we are using fallback settings.
$path = $this->pool->messages->getHelp('iniNotFound');
}
$model = $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model')
->setName($path)
->setType($this->pool->fileService->filterFilePath($pathToIni))
->setHelpid('currentSettings')
->injectCallback(
$this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughConfig')
);
return $this->pool->render->renderFooter(
$caller,
$model,
$isExpanded
);
} | [
"protected",
"function",
"outputFooter",
"(",
"array",
"$",
"caller",
",",
"$",
"isExpanded",
"=",
"false",
")",
"{",
"// Now we need to stitch together the content of the ini file",
"// as well as it's path.",
"$",
"pathToIni",
"=",
"$",
"this",
"->",
"pool",
"->",
"... | Simply renders the footer and output current settings.
@param array $caller
Where was kreXX initially invoked from.
@param boolean $isExpanded
Are we rendering an expanded footer?
TRUE when we render the settings menu only.
@return string
The generated markup. | [
"Simply",
"renders",
"the",
"footer",
"and",
"output",
"current",
"settings",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Controller/AbstractController.php#L162-L188 | train |
brainworxx/kreXX | src/Controller/AbstractController.php | AbstractController.outputCssAndJs | protected function outputCssAndJs()
{
// We only do this once per output type.
$result = isset(static::$jsCssSend[$this->destination]);
static::$jsCssSend[$this->destination] = true;
if ($result === true) {
// Been here, done that.
return '';
}
// Adding our DOM tools to the js.
if ($this->pool->fileService->fileIsReadable(KREXX_DIR . 'resources/jsLibs/kdt.min.js') === true) {
$kdtPath = KREXX_DIR . 'resources/jsLibs/kdt.min.js';
} else {
$kdtPath = KREXX_DIR . 'resources/jsLibs/kdt.js';
}
$jsCode = $this->pool->fileService->getFileContents($kdtPath);
// Adding the skin css and js.
$skinDirectory = $this->pool->config->getSkinDirectory();
// Get the css file.
$css = $this->pool->fileService->getFileContents($skinDirectory . 'skin.css');
// Remove whitespace.
$css = preg_replace('/\s+/', ' ', $css);
// Krexx.js is comes directly form the template.
if ($this->pool->fileService->fileIsReadable($skinDirectory . 'krexx.min.js') === true) {
$skinJsPath = $skinDirectory . 'krexx.min.js';
} else {
$skinJsPath = $skinDirectory . 'krexx.js';
}
$jsCode .= $this->pool->fileService->getFileContents($skinJsPath);
return $this->pool->render->renderCssJs($css, $jsCode);
} | php | protected function outputCssAndJs()
{
// We only do this once per output type.
$result = isset(static::$jsCssSend[$this->destination]);
static::$jsCssSend[$this->destination] = true;
if ($result === true) {
// Been here, done that.
return '';
}
// Adding our DOM tools to the js.
if ($this->pool->fileService->fileIsReadable(KREXX_DIR . 'resources/jsLibs/kdt.min.js') === true) {
$kdtPath = KREXX_DIR . 'resources/jsLibs/kdt.min.js';
} else {
$kdtPath = KREXX_DIR . 'resources/jsLibs/kdt.js';
}
$jsCode = $this->pool->fileService->getFileContents($kdtPath);
// Adding the skin css and js.
$skinDirectory = $this->pool->config->getSkinDirectory();
// Get the css file.
$css = $this->pool->fileService->getFileContents($skinDirectory . 'skin.css');
// Remove whitespace.
$css = preg_replace('/\s+/', ' ', $css);
// Krexx.js is comes directly form the template.
if ($this->pool->fileService->fileIsReadable($skinDirectory . 'krexx.min.js') === true) {
$skinJsPath = $skinDirectory . 'krexx.min.js';
} else {
$skinJsPath = $skinDirectory . 'krexx.js';
}
$jsCode .= $this->pool->fileService->getFileContents($skinJsPath);
return $this->pool->render->renderCssJs($css, $jsCode);
} | [
"protected",
"function",
"outputCssAndJs",
"(",
")",
"{",
"// We only do this once per output type.",
"$",
"result",
"=",
"isset",
"(",
"static",
"::",
"$",
"jsCssSend",
"[",
"$",
"this",
"->",
"destination",
"]",
")",
";",
"static",
"::",
"$",
"jsCssSend",
"[... | Outputs the CSS and JS.
@return string
The generated markup. | [
"Outputs",
"the",
"CSS",
"and",
"JS",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Controller/AbstractController.php#L196-L229 | train |
brainworxx/kreXX | src/Controller/AbstractController.php | AbstractController.noFatalForKrexx | public function noFatalForKrexx()
{
if ($this->fatalShouldActive === true) {
$this::$krexxFatal->setIsActive(false);
unregister_tick_function(array($this::$krexxFatal, 'tickCallback'));
}
return $this;
} | php | public function noFatalForKrexx()
{
if ($this->fatalShouldActive === true) {
$this::$krexxFatal->setIsActive(false);
unregister_tick_function(array($this::$krexxFatal, 'tickCallback'));
}
return $this;
} | [
"public",
"function",
"noFatalForKrexx",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fatalShouldActive",
"===",
"true",
")",
"{",
"$",
"this",
"::",
"$",
"krexxFatal",
"->",
"setIsActive",
"(",
"false",
")",
";",
"unregister_tick_function",
"(",
"array",
... | Disables the fatal handler and the tick callback.
We disable the tick callback and the error handler during
a analysis, to generate faster output. We also disable
other kreXX calls, which may be caused by the debug callbacks
to prevent kreXX from starting other kreXX calls.
@return $this
Return $this for chaining. | [
"Disables",
"the",
"fatal",
"handler",
"and",
"the",
"tick",
"callback",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Controller/AbstractController.php#L242-L250 | train |
brainworxx/kreXX | src/Controller/AbstractController.php | AbstractController.reFatalAfterKrexx | public function reFatalAfterKrexx()
{
if ($this->fatalShouldActive === true) {
$this::$krexxFatal->setIsActive(true);
register_tick_function(array($this::$krexxFatal, 'tickCallback'));
}
return $this;
} | php | public function reFatalAfterKrexx()
{
if ($this->fatalShouldActive === true) {
$this::$krexxFatal->setIsActive(true);
register_tick_function(array($this::$krexxFatal, 'tickCallback'));
}
return $this;
} | [
"public",
"function",
"reFatalAfterKrexx",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fatalShouldActive",
"===",
"true",
")",
"{",
"$",
"this",
"::",
"$",
"krexxFatal",
"->",
"setIsActive",
"(",
"true",
")",
";",
"register_tick_function",
"(",
"array",
... | Re-enable the fatal handler and the tick callback.
We disable the tick callback and the error handler during
a analysis, to generate faster output. We re-enable kreXX
afterwards, so the dev can use it again.
@return $this
Return $this for chaining. | [
"Re",
"-",
"enable",
"the",
"fatal",
"handler",
"and",
"the",
"tick",
"callback",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Controller/AbstractController.php#L262-L270 | train |
brainworxx/kreXX | src/Analyse/Routing/Process/ProcessArray.php | ProcessArray.process | public function process(Model $model)
{
$multiline = false;
$count = count($model->getData());
if ($count > (int) $this->pool->config->getSetting(Fallback::SETTING_ARRAY_COUNT_LIMIT)) {
// Budget array analysis.
$model->injectCallback(
$this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughLargeArray')
)->setHelpid('simpleArray');
} else {
// Complete array analysis.
$model->injectCallback(
$this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughArray')
);
}
// Dumping all Properties.
return $this->pool->render->renderExpandableChild(
$model->setType(static::TYPE_ARRAY)
->setNormal($count . ' elements')
->addParameter(static::PARAM_DATA, $model->getData())
->addParameter(static::PARAM_MULTILINE, $multiline)
);
} | php | public function process(Model $model)
{
$multiline = false;
$count = count($model->getData());
if ($count > (int) $this->pool->config->getSetting(Fallback::SETTING_ARRAY_COUNT_LIMIT)) {
// Budget array analysis.
$model->injectCallback(
$this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughLargeArray')
)->setHelpid('simpleArray');
} else {
// Complete array analysis.
$model->injectCallback(
$this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughArray')
);
}
// Dumping all Properties.
return $this->pool->render->renderExpandableChild(
$model->setType(static::TYPE_ARRAY)
->setNormal($count . ' elements')
->addParameter(static::PARAM_DATA, $model->getData())
->addParameter(static::PARAM_MULTILINE, $multiline)
);
} | [
"public",
"function",
"process",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"multiline",
"=",
"false",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"model",
"->",
"getData",
"(",
")",
")",
";",
"if",
"(",
"$",
"count",
">",
"(",
"int",
")",
"$",
... | Render a dump for an array.
@param Model $model
The data we are analysing.
@return string
The rendered markup. | [
"Render",
"a",
"dump",
"for",
"an",
"array",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Routing/Process/ProcessArray.php#L58-L82 | train |
silverorange/swat | Swat/SwatXHTMLTextarea.php | SwatXHTMLTextarea.getValidationErrorMessage | protected function getValidationErrorMessage(array $xml_errors)
{
$ignored_errors = array(
'extra content at the end of the document',
'premature end of data in tag html',
'opening and ending tag mismatch between html and body',
'opening and ending tag mismatch between body and html'
);
$errors = array();
foreach ($xml_errors as $error_object) {
$error = $error_object->message;
// further humanize
$error = str_replace(
'tag mismatch:',
Swat::_('tag mismatch between'),
$error
);
// remove some stuff that only makes sense in document context
$error = preg_replace('/\s?line:? [0-9]+\s?/ui', ' ', $error);
$error = preg_replace('/in entity[:,.]?/ui', '', $error);
$error = mb_strtolower($error);
$error = str_replace(
'xmlparseentityref: no name',
Swat::_('unescaped ampersand. Use & instead of &'),
$error
);
$error = str_replace(
'starttag: invalid element name',
Swat::_('unescaped less-than. Use &lt; instead of <'),
$error
);
$error = str_replace(
'specification mandate value for attribute',
Swat::_('a value is required for the attribute'),
$error
);
$error = preg_replace(
'/^no declaration for attribute (.*?) of element (.*?)$/',
Swat::_('the attribute \1 is not valid for the element \2'),
$error
);
$error = str_replace(
'attvalue: " or \' expected',
Swat::_(
'attribute values must be contained within quotation ' .
'marks'
),
$error
);
$error = trim($error);
if (!in_array($error, $ignored_errors)) {
$errors[] = $error;
}
}
$content = Swat::_('%s must be valid XHTML markup: ');
$content .= '<ul><li>' . implode(',</li><li>', $errors) . '.</li></ul>';
$message = new SwatMessage($content, 'error');
$message->content_type = 'text/xml';
return $message;
} | php | protected function getValidationErrorMessage(array $xml_errors)
{
$ignored_errors = array(
'extra content at the end of the document',
'premature end of data in tag html',
'opening and ending tag mismatch between html and body',
'opening and ending tag mismatch between body and html'
);
$errors = array();
foreach ($xml_errors as $error_object) {
$error = $error_object->message;
// further humanize
$error = str_replace(
'tag mismatch:',
Swat::_('tag mismatch between'),
$error
);
// remove some stuff that only makes sense in document context
$error = preg_replace('/\s?line:? [0-9]+\s?/ui', ' ', $error);
$error = preg_replace('/in entity[:,.]?/ui', '', $error);
$error = mb_strtolower($error);
$error = str_replace(
'xmlparseentityref: no name',
Swat::_('unescaped ampersand. Use &amp; instead of &'),
$error
);
$error = str_replace(
'starttag: invalid element name',
Swat::_('unescaped less-than. Use &lt; instead of <'),
$error
);
$error = str_replace(
'specification mandate value for attribute',
Swat::_('a value is required for the attribute'),
$error
);
$error = preg_replace(
'/^no declaration for attribute (.*?) of element (.*?)$/',
Swat::_('the attribute \1 is not valid for the element \2'),
$error
);
$error = str_replace(
'attvalue: " or \' expected',
Swat::_(
'attribute values must be contained within quotation ' .
'marks'
),
$error
);
$error = trim($error);
if (!in_array($error, $ignored_errors)) {
$errors[] = $error;
}
}
$content = Swat::_('%s must be valid XHTML markup: ');
$content .= '<ul><li>' . implode(',</li><li>', $errors) . '.</li></ul>';
$message = new SwatMessage($content, 'error');
$message->content_type = 'text/xml';
return $message;
} | [
"protected",
"function",
"getValidationErrorMessage",
"(",
"array",
"$",
"xml_errors",
")",
"{",
"$",
"ignored_errors",
"=",
"array",
"(",
"'extra content at the end of the document'",
",",
"'premature end of data in tag html'",
",",
"'opening and ending tag mismatch between html... | Gets a human readable error message for XHTML validation errors on
this textarea's value
@param array $xml_errors an array of LibXMLError objects.
@return SwatMessage a human readable error message for XHTML validation
errors on this textarea's value. | [
"Gets",
"a",
"human",
"readable",
"error",
"message",
"for",
"XHTML",
"validation",
"errors",
"on",
"this",
"textarea",
"s",
"value"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatXHTMLTextarea.php#L138-L209 | train |
silverorange/swat | Swat/SwatXHTMLTextarea.php | SwatXHTMLTextarea.createCompositeWidgets | protected function createCompositeWidgets()
{
$this->ignore_errors_checkbox = new SwatCheckbox(
$this->id . '_ignore_checkbox'
);
$ignore_field = new SwatFormField($this->id . '_ignore_field');
$ignore_field->title = Swat::_('Ignore XHTML validation errors');
$ignore_field->add($this->ignore_errors_checkbox);
$this->addCompositeWidget($ignore_field, 'ignore_field');
} | php | protected function createCompositeWidgets()
{
$this->ignore_errors_checkbox = new SwatCheckbox(
$this->id . '_ignore_checkbox'
);
$ignore_field = new SwatFormField($this->id . '_ignore_field');
$ignore_field->title = Swat::_('Ignore XHTML validation errors');
$ignore_field->add($this->ignore_errors_checkbox);
$this->addCompositeWidget($ignore_field, 'ignore_field');
} | [
"protected",
"function",
"createCompositeWidgets",
"(",
")",
"{",
"$",
"this",
"->",
"ignore_errors_checkbox",
"=",
"new",
"SwatCheckbox",
"(",
"$",
"this",
"->",
"id",
".",
"'_ignore_checkbox'",
")",
";",
"$",
"ignore_field",
"=",
"new",
"SwatFormField",
"(",
... | Creates the composite checkbox used by this XHTML textarea
@see SwatWidget::createCompositeWidgets() | [
"Creates",
"the",
"composite",
"checkbox",
"used",
"by",
"this",
"XHTML",
"textarea"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatXHTMLTextarea.php#L219-L230 | train |
silverorange/swat | Swat/SwatHtmlHeadEntrySetDisplayer.php | SwatHtmlHeadEntrySetDisplayer.display | public function display(
SwatHtmlHeadEntrySet $set,
$uri_prefix = '',
$tag = null,
$combine = false,
$minify = false
) {
// clone set so displaying doesn't modify it
$set = clone $set;
$entries = $set->toArray();
// combine files
if ($combine) {
$info = $this->getCombinedEntries($entries);
$entries = $info['entries'];
$uris = $info['superset'];
} else {
$uris = array_keys($entries);
}
// check for conflicts in the displayed set
$this->checkForConflicts($uris);
// sort
$entries = $this->getSortedEntries($entries);
// display entries
$current_type = null;
foreach ($entries as $entry) {
if ($this->compareTypes($current_type, $entry->getType()) !== 0) {
$current_type = $entry->getType();
echo "\n";
}
echo "\t";
$prefix = $uri_prefix;
if ($minify && $this->concentrator->isMinified($entry->getUri())) {
$prefix = $prefix . 'min/';
}
if ($entry->getType() === 'SwatLessStyleSheetHtmlHeadEntry') {
$prefix = $prefix . 'compiled/';
$entry = $entry->getStyleSheetHeadEntry();
}
$entry->display($prefix, $tag);
echo "\n";
}
echo "\n";
} | php | public function display(
SwatHtmlHeadEntrySet $set,
$uri_prefix = '',
$tag = null,
$combine = false,
$minify = false
) {
// clone set so displaying doesn't modify it
$set = clone $set;
$entries = $set->toArray();
// combine files
if ($combine) {
$info = $this->getCombinedEntries($entries);
$entries = $info['entries'];
$uris = $info['superset'];
} else {
$uris = array_keys($entries);
}
// check for conflicts in the displayed set
$this->checkForConflicts($uris);
// sort
$entries = $this->getSortedEntries($entries);
// display entries
$current_type = null;
foreach ($entries as $entry) {
if ($this->compareTypes($current_type, $entry->getType()) !== 0) {
$current_type = $entry->getType();
echo "\n";
}
echo "\t";
$prefix = $uri_prefix;
if ($minify && $this->concentrator->isMinified($entry->getUri())) {
$prefix = $prefix . 'min/';
}
if ($entry->getType() === 'SwatLessStyleSheetHtmlHeadEntry') {
$prefix = $prefix . 'compiled/';
$entry = $entry->getStyleSheetHeadEntry();
}
$entry->display($prefix, $tag);
echo "\n";
}
echo "\n";
} | [
"public",
"function",
"display",
"(",
"SwatHtmlHeadEntrySet",
"$",
"set",
",",
"$",
"uri_prefix",
"=",
"''",
",",
"$",
"tag",
"=",
"null",
",",
"$",
"combine",
"=",
"false",
",",
"$",
"minify",
"=",
"false",
")",
"{",
"// clone set so displaying doesn't modi... | Displays a set of HTML head entries
@param SwatHtmlHeadEntrySet $set the HTML head entry set to display.
@param string $uri_prefix an optional URI prefix to prepend to all the
displayed HTML head entries.
@param string $tag an optional tag to suffix the URI with. This is
suffixed as a HTTP get var and can be used to
explicitly refresh the browser cache.
@param boolean $combine whether or not to combine files. Defaults to
false.
@param boolean $minify whether or not to minify files. Defaults to
false. | [
"Displays",
"a",
"set",
"of",
"HTML",
"head",
"entries"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatHtmlHeadEntrySetDisplayer.php#L52-L105 | train |
silverorange/swat | Swat/SwatHtmlHeadEntrySetDisplayer.php | SwatHtmlHeadEntrySetDisplayer.displayInline | public function displayInline(
SwatHtmlHeadEntrySet $set,
$path,
$type = null
) {
$entries = $set->toArray();
$uris = array_keys($entries);
// check for conflicts in the displayed set
$this->checkForConflicts($uris);
// sort
$entries = $this->getSortedEntries($entries);
// display entries inline
// TODO: Use Concentrate_Inliner to display CSS inline
foreach ($entries as $entry) {
if ($type === null || $entry->getType() === $type) {
echo "\t", '<!-- ', $entry->getUri(), ' -->', "\n";
$entry->displayInline($path);
echo "\n\t";
}
}
echo "\n";
} | php | public function displayInline(
SwatHtmlHeadEntrySet $set,
$path,
$type = null
) {
$entries = $set->toArray();
$uris = array_keys($entries);
// check for conflicts in the displayed set
$this->checkForConflicts($uris);
// sort
$entries = $this->getSortedEntries($entries);
// display entries inline
// TODO: Use Concentrate_Inliner to display CSS inline
foreach ($entries as $entry) {
if ($type === null || $entry->getType() === $type) {
echo "\t", '<!-- ', $entry->getUri(), ' -->', "\n";
$entry->displayInline($path);
echo "\n\t";
}
}
echo "\n";
} | [
"public",
"function",
"displayInline",
"(",
"SwatHtmlHeadEntrySet",
"$",
"set",
",",
"$",
"path",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"entries",
"=",
"$",
"set",
"->",
"toArray",
"(",
")",
";",
"$",
"uris",
"=",
"array_keys",
"(",
"$",
"ent... | Displays the contents of the set of HTML head entries inline | [
"Displays",
"the",
"contents",
"of",
"the",
"set",
"of",
"HTML",
"head",
"entries",
"inline"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatHtmlHeadEntrySetDisplayer.php#L113-L139 | train |
silverorange/swat | Swat/SwatHtmlHeadEntrySetDisplayer.php | SwatHtmlHeadEntrySetDisplayer.getCombinedEntries | protected function getCombinedEntries(array $entries)
{
$info = $this->concentrator->getCombines(array_keys($entries));
// add combines to set of entries
foreach ($info['combines'] as $combine) {
if (mb_substr($combine, -4) === '.css') {
$class_name = 'SwatStyleSheetHtmlHeadEntry';
} elseif (mb_substr($combine, -5) === '.less') {
$class_name = 'SwatLessStyleSheetHtmlHeadEntry';
} else {
$class_name = 'SwatJavaScriptHtmlHeadEntry';
}
$entries[$combine] = new $class_name($combine, '__combine__');
}
// remove files included in combines
$entries = array_intersect_key($entries, array_flip($info['files']));
return array(
'entries' => $entries,
'superset' => $info['superset']
);
} | php | protected function getCombinedEntries(array $entries)
{
$info = $this->concentrator->getCombines(array_keys($entries));
// add combines to set of entries
foreach ($info['combines'] as $combine) {
if (mb_substr($combine, -4) === '.css') {
$class_name = 'SwatStyleSheetHtmlHeadEntry';
} elseif (mb_substr($combine, -5) === '.less') {
$class_name = 'SwatLessStyleSheetHtmlHeadEntry';
} else {
$class_name = 'SwatJavaScriptHtmlHeadEntry';
}
$entries[$combine] = new $class_name($combine, '__combine__');
}
// remove files included in combines
$entries = array_intersect_key($entries, array_flip($info['files']));
return array(
'entries' => $entries,
'superset' => $info['superset']
);
} | [
"protected",
"function",
"getCombinedEntries",
"(",
"array",
"$",
"entries",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"concentrator",
"->",
"getCombines",
"(",
"array_keys",
"(",
"$",
"entries",
")",
")",
";",
"// add combines to set of entries",
"foreach"... | Gets the entries of this set accounting for combining
@param array $entries
@return array the entries of this set accounting for combinations. | [
"Gets",
"the",
"entries",
"of",
"this",
"set",
"accounting",
"for",
"combining"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatHtmlHeadEntrySetDisplayer.php#L151-L174 | train |
silverorange/swat | Swat/SwatHtmlHeadEntrySetDisplayer.php | SwatHtmlHeadEntrySetDisplayer.getSortedEntries | protected function getSortedEntries(array $original_entries)
{
$entries = array();
// get array of entries with native ordering so we can do a
// stable, user-defined sort
$count = 0;
foreach ($original_entries as $uri => $entry) {
$entries[] = array(
'order' => $count,
'uri' => $uri,
'object' => $entry
);
$count++;
}
// stable-sort entries
usort($entries, array($this, 'compareEntries'));
// put back in a flat array
$sorted_entries = array();
foreach ($entries as $uri => $entry) {
$sorted_entries[$uri] = $entry['object'];
}
return $sorted_entries;
} | php | protected function getSortedEntries(array $original_entries)
{
$entries = array();
// get array of entries with native ordering so we can do a
// stable, user-defined sort
$count = 0;
foreach ($original_entries as $uri => $entry) {
$entries[] = array(
'order' => $count,
'uri' => $uri,
'object' => $entry
);
$count++;
}
// stable-sort entries
usort($entries, array($this, 'compareEntries'));
// put back in a flat array
$sorted_entries = array();
foreach ($entries as $uri => $entry) {
$sorted_entries[$uri] = $entry['object'];
}
return $sorted_entries;
} | [
"protected",
"function",
"getSortedEntries",
"(",
"array",
"$",
"original_entries",
")",
"{",
"$",
"entries",
"=",
"array",
"(",
")",
";",
"// get array of entries with native ordering so we can do a",
"// stable, user-defined sort",
"$",
"count",
"=",
"0",
";",
"foreac... | Gets the entries of this set sorted by their correct display order
@param array $original_entries
@return array the entries of this set sorted by their correct display
order. | [
"Gets",
"the",
"entries",
"of",
"this",
"set",
"sorted",
"by",
"their",
"correct",
"display",
"order"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatHtmlHeadEntrySetDisplayer.php#L187-L213 | train |
silverorange/swat | Swat/SwatHtmlHeadEntrySetDisplayer.php | SwatHtmlHeadEntrySetDisplayer.compareTypes | protected function compareTypes($a, $b)
{
// compare entry type order
$type_order = $this->getTypeOrder();
if (!array_key_exists($a, $type_order)) {
$a = '__unknown__';
}
if (!array_key_exists($b, $type_order)) {
$b = '__unknown__';
}
if ($type_order[$a] > $type_order[$b]) {
return 1;
}
if ($type_order[$a] < $type_order[$b]) {
return -1;
}
return 0;
} | php | protected function compareTypes($a, $b)
{
// compare entry type order
$type_order = $this->getTypeOrder();
if (!array_key_exists($a, $type_order)) {
$a = '__unknown__';
}
if (!array_key_exists($b, $type_order)) {
$b = '__unknown__';
}
if ($type_order[$a] > $type_order[$b]) {
return 1;
}
if ($type_order[$a] < $type_order[$b]) {
return -1;
}
return 0;
} | [
"protected",
"function",
"compareTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"// compare entry type order",
"$",
"type_order",
"=",
"$",
"this",
"->",
"getTypeOrder",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"a",
",",
"$",
"type_o... | Compares two HTML head entry types
@param string $a left side of comparison.
@param string $b right side of comparison.
@return integer a tri-value where -1 means the left side is less than
the right side, 1 means the left side is greater than
the right side and 0 means the left side and right
side are equivalent. | [
"Compares",
"two",
"HTML",
"head",
"entry",
"types"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatHtmlHeadEntrySetDisplayer.php#L285-L307 | train |
silverorange/swat | Swat/SwatHtmlHeadEntrySetDisplayer.php | SwatHtmlHeadEntrySetDisplayer.checkForConflicts | protected function checkForConflicts(array $uris)
{
$conflicts = $this->concentrator->getConflicts($uris);
if (count($conflicts) > 0) {
$conflict_list = '';
$count = 0;
foreach ($conflicts as $file => $conflict) {
$conflict_list .= sprintf(
"\n- %s conflicts with %s",
$file,
implode(', ', $conflict)
);
$count++;
}
throw new SwatException(
'Could not display head entries because the following ' .
'conflicts were detected: ' .
$conflict_list
);
}
} | php | protected function checkForConflicts(array $uris)
{
$conflicts = $this->concentrator->getConflicts($uris);
if (count($conflicts) > 0) {
$conflict_list = '';
$count = 0;
foreach ($conflicts as $file => $conflict) {
$conflict_list .= sprintf(
"\n- %s conflicts with %s",
$file,
implode(', ', $conflict)
);
$count++;
}
throw new SwatException(
'Could not display head entries because the following ' .
'conflicts were detected: ' .
$conflict_list
);
}
} | [
"protected",
"function",
"checkForConflicts",
"(",
"array",
"$",
"uris",
")",
"{",
"$",
"conflicts",
"=",
"$",
"this",
"->",
"concentrator",
"->",
"getConflicts",
"(",
"$",
"uris",
")",
";",
"if",
"(",
"count",
"(",
"$",
"conflicts",
")",
">",
"0",
")"... | Check for conflicts in a set of HTML head entry URIs
If a conflict is detected, an exception is thrown explaining the
conflict.
@param array $uris the HTML head entry URIs to check.
@throws SwatException if one or more conflicts are present. | [
"Check",
"for",
"conflicts",
"in",
"a",
"set",
"of",
"HTML",
"head",
"entry",
"URIs"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatHtmlHeadEntrySetDisplayer.php#L349-L370 | train |
silverorange/swat | Swat/SwatCheckboxEntryList.php | SwatCheckboxEntryList.process | public function process()
{
if (
$this->getForm()->getHiddenField($this->id . '_submitted') === null
) {
return;
}
parent::process();
foreach ($this->values as $option_value) {
$this->getEntryWidget($option_value)->process();
}
} | php | public function process()
{
if (
$this->getForm()->getHiddenField($this->id . '_submitted') === null
) {
return;
}
parent::process();
foreach ($this->values as $option_value) {
$this->getEntryWidget($option_value)->process();
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getForm",
"(",
")",
"->",
"getHiddenField",
"(",
"$",
"this",
"->",
"id",
".",
"'_submitted'",
")",
"===",
"null",
")",
"{",
"return",
";",
"}",
"parent",
"::",
"process",... | Processes this checkbox entry list
Processes the checkboxes as well as each entry widget for each checked
checkbox. The entry widgets for unchecked checkboxes are not processed.
@see SwatCheckboxList::process() | [
"Processes",
"this",
"checkbox",
"entry",
"list"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCheckboxEntryList.php#L180-L193 | train |
silverorange/swat | Swat/SwatCheckboxEntryList.php | SwatCheckboxEntryList.getEntryValue | public function getEntryValue($option_value)
{
$entry_value = null;
if ($this->hasEntryWidget($option_value)) {
$entry = $this->getEntryWidget($option_value)->getFirst();
$entry_value = $entry->value;
}
return $entry_value;
} | php | public function getEntryValue($option_value)
{
$entry_value = null;
if ($this->hasEntryWidget($option_value)) {
$entry = $this->getEntryWidget($option_value)->getFirst();
$entry_value = $entry->value;
}
return $entry_value;
} | [
"public",
"function",
"getEntryValue",
"(",
"$",
"option_value",
")",
"{",
"$",
"entry_value",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"hasEntryWidget",
"(",
"$",
"option_value",
")",
")",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"getEntryWidge... | Gets the value of an entry widget in this checkbox entry list
@param string $option_value used to indentify the entry widget
@return string the value of the specified entry widget or null if no
such widget exists. | [
"Gets",
"the",
"value",
"of",
"an",
"entry",
"widget",
"in",
"this",
"checkbox",
"entry",
"list"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCheckboxEntryList.php#L257-L267 | train |
silverorange/swat | Swat/SwatCheckboxEntryList.php | SwatCheckboxEntryList.setEntryValue | public function setEntryValue($option_value, $entry_value)
{
$options = $this->getOptions();
$option_values = array();
foreach ($options as $option) {
$option_values[] = $option->value;
}
if (!in_array($option_value, $option_values)) {
throw new SwatInvalidPropertyException(
sprintf(
'No option with a value of "%s" exists in this checkbox ' .
'entry list',
$option_value
)
);
}
$this->getEntryWidget($option_value)->getFirst()->value = $entry_value;
} | php | public function setEntryValue($option_value, $entry_value)
{
$options = $this->getOptions();
$option_values = array();
foreach ($options as $option) {
$option_values[] = $option->value;
}
if (!in_array($option_value, $option_values)) {
throw new SwatInvalidPropertyException(
sprintf(
'No option with a value of "%s" exists in this checkbox ' .
'entry list',
$option_value
)
);
}
$this->getEntryWidget($option_value)->getFirst()->value = $entry_value;
} | [
"public",
"function",
"setEntryValue",
"(",
"$",
"option_value",
",",
"$",
"entry_value",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"option_values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"options",
... | Sets the value of an entry widget in this checkbox entry list
@param string $option_value the value of the option for which to set
the entry widget value.
@param string $entry_value the value to set on the entry widget.
@throws SwatInvalidPropertyException if the option value does not match
an existing option value in this
checkbox entry list. | [
"Sets",
"the",
"value",
"of",
"an",
"entry",
"widget",
"in",
"this",
"checkbox",
"entry",
"list"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCheckboxEntryList.php#L283-L302 | train |
silverorange/swat | Swat/SwatCheckboxEntryList.php | SwatCheckboxEntryList.setEntryValuesByArray | public function setEntryValuesByArray(array $entry_values)
{
foreach ($entry_values as $option_value => $entry_value) {
$this->setEntryValue($option_value, $entry_value);
}
} | php | public function setEntryValuesByArray(array $entry_values)
{
foreach ($entry_values as $option_value => $entry_value) {
$this->setEntryValue($option_value, $entry_value);
}
} | [
"public",
"function",
"setEntryValuesByArray",
"(",
"array",
"$",
"entry_values",
")",
"{",
"foreach",
"(",
"$",
"entry_values",
"as",
"$",
"option_value",
"=>",
"$",
"entry_value",
")",
"{",
"$",
"this",
"->",
"setEntryValue",
"(",
"$",
"option_value",
",",
... | Sets the values of multiple entry widgets
This is a convenience method to quickly set the entry values for one
or more options in this checkbox entry list. This calls
{@link SwatCheckboxEntryList::setEntryValue()} internally for each
entry in the <i>$entry_values</i> array.
@param array $entry_values an array indexed by option values of this
checkbox entry list with values of the entry
widget values.
@throws SwatInvalidPropertyException if any option value (array key)
does not match an existing option
value in this checkbox entry list. | [
"Sets",
"the",
"values",
"of",
"multiple",
"entry",
"widgets"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCheckboxEntryList.php#L323-L328 | train |
silverorange/swat | Swat/SwatCheckboxEntryList.php | SwatCheckboxEntryList.getInlineJavaScript | protected function getInlineJavaScript()
{
$javascript = sprintf(
"var %s_obj = new SwatCheckboxEntryList('%s');",
$this->id,
$this->id
);
// set check-all controller if it is visible
if ($this->show_check_all && count($this->getOptions()) > 1) {
$javascript .= sprintf(
"\n%s_obj.setController(%s_obj);",
$this->getCompositeWidget('check_all')->id,
$this->id
);
}
return $javascript;
} | php | protected function getInlineJavaScript()
{
$javascript = sprintf(
"var %s_obj = new SwatCheckboxEntryList('%s');",
$this->id,
$this->id
);
// set check-all controller if it is visible
if ($this->show_check_all && count($this->getOptions()) > 1) {
$javascript .= sprintf(
"\n%s_obj.setController(%s_obj);",
$this->getCompositeWidget('check_all')->id,
$this->id
);
}
return $javascript;
} | [
"protected",
"function",
"getInlineJavaScript",
"(",
")",
"{",
"$",
"javascript",
"=",
"sprintf",
"(",
"\"var %s_obj = new SwatCheckboxEntryList('%s');\"",
",",
"$",
"this",
"->",
"id",
",",
"$",
"this",
"->",
"id",
")",
";",
"// set check-all controller if it is visi... | Gets the inline JavaScript for this checkbox entry list
@return string the inline JavaScript for this checkbox entry list. | [
"Gets",
"the",
"inline",
"JavaScript",
"for",
"this",
"checkbox",
"entry",
"list"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCheckboxEntryList.php#L338-L356 | train |
silverorange/swat | Swat/SwatCheckboxEntryList.php | SwatCheckboxEntryList.getEntryWidget | protected function getEntryWidget($option_value)
{
if (!$this->hasEntryWidget($option_value)) {
$container = new SwatFormField(
$this->id . '_field_' . $option_value
);
$container->add($this->createEntryWidget($option_value));
$container->parent = $this;
$container->init();
$this->entry_widgets[$option_value] = $container;
}
return $this->entry_widgets[$option_value];
} | php | protected function getEntryWidget($option_value)
{
if (!$this->hasEntryWidget($option_value)) {
$container = new SwatFormField(
$this->id . '_field_' . $option_value
);
$container->add($this->createEntryWidget($option_value));
$container->parent = $this;
$container->init();
$this->entry_widgets[$option_value] = $container;
}
return $this->entry_widgets[$option_value];
} | [
"protected",
"function",
"getEntryWidget",
"(",
"$",
"option_value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasEntryWidget",
"(",
"$",
"option_value",
")",
")",
"{",
"$",
"container",
"=",
"new",
"SwatFormField",
"(",
"$",
"this",
"->",
"id",
".",... | Gets a widget tree for the entry widget of this checkbox entry list
This is used internally to create the widget tree containing a
{@link SwatEntry} widget for display and processing.
@param string $option_value the value of the option for which to get
the entry widget. If no entry widget exists
for the given option value, one is created.
@return SwatContainer the widget tree containing the entry widget for
the given option value. | [
"Gets",
"a",
"widget",
"tree",
"for",
"the",
"entry",
"widget",
"of",
"this",
"checkbox",
"entry",
"list"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCheckboxEntryList.php#L408-L421 | train |
silverorange/swat | Swat/SwatCheckboxEntryList.php | SwatCheckboxEntryList.createEntryWidget | protected function createEntryWidget($option_value)
{
$widget = new SwatEntry($this->id . '_entry_' . $option_value);
$widget->size = $this->entry_size;
$widget->maxlength = $this->entry_maxlength;
return $widget;
} | php | protected function createEntryWidget($option_value)
{
$widget = new SwatEntry($this->id . '_entry_' . $option_value);
$widget->size = $this->entry_size;
$widget->maxlength = $this->entry_maxlength;
return $widget;
} | [
"protected",
"function",
"createEntryWidget",
"(",
"$",
"option_value",
")",
"{",
"$",
"widget",
"=",
"new",
"SwatEntry",
"(",
"$",
"this",
"->",
"id",
".",
"'_entry_'",
".",
"$",
"option_value",
")",
";",
"$",
"widget",
"->",
"size",
"=",
"$",
"this",
... | Creates an entry widget of this checkbox entry list
Subclasses may override this method to create a different widget type.
@param string $option_value the value of the option for which to get
the entry widget.
@return SwatEntry the new entry widget for the given option value. | [
"Creates",
"an",
"entry",
"widget",
"of",
"this",
"checkbox",
"entry",
"list"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCheckboxEntryList.php#L436-L442 | train |
silverorange/swat | Swat/SwatReplicableFormField.php | SwatReplicableFormField.init | public function init()
{
$children = array();
foreach ($this->children as $child_widget) {
$children[] = $this->remove($child_widget);
}
$field = new SwatFormField();
$field->id = $field->getUniqueId();
$prototype_id = $field->id;
foreach ($children as $child_widget) {
$field->add($child_widget);
}
$this->add($field);
parent::init();
foreach ($this->replicators as $id => $title) {
$field = $this->getWidget($prototype_id, $id);
$field->title = $title;
}
} | php | public function init()
{
$children = array();
foreach ($this->children as $child_widget) {
$children[] = $this->remove($child_widget);
}
$field = new SwatFormField();
$field->id = $field->getUniqueId();
$prototype_id = $field->id;
foreach ($children as $child_widget) {
$field->add($child_widget);
}
$this->add($field);
parent::init();
foreach ($this->replicators as $id => $title) {
$field = $this->getWidget($prototype_id, $id);
$field->title = $title;
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"children",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"children",
"as",
"$",
"child_widget",
")",
"{",
"$",
"children",
"[",
"]",
"=",
"$",
"this",
"->",
"remove",
"(",
"$",
... | Initilizes this replicable form field | [
"Initilizes",
"this",
"replicable",
"form",
"field"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatReplicableFormField.php#L23-L46 | train |
honey-comb/core | src/Http/Controllers/HCAuthController.php | HCAuthController.deAuthorize | private function deAuthorize(User $user): void
{
$client = new Client;
$client->delete("https://graph.facebook.com/{$user->id}/permissions",
[
'headers' => ['Accept' => 'application/json'],
'form_params' => [
'access_token' => $user->token,
],
]
);
} | php | private function deAuthorize(User $user): void
{
$client = new Client;
$client->delete("https://graph.facebook.com/{$user->id}/permissions",
[
'headers' => ['Accept' => 'application/json'],
'form_params' => [
'access_token' => $user->token,
],
]
);
} | [
"private",
"function",
"deAuthorize",
"(",
"User",
"$",
"user",
")",
":",
"void",
"{",
"$",
"client",
"=",
"new",
"Client",
";",
"$",
"client",
"->",
"delete",
"(",
"\"https://graph.facebook.com/{$user->id}/permissions\"",
",",
"[",
"'headers'",
"=>",
"[",
"'A... | DeAuthorize user from app
@param User $user
@return void | [
"DeAuthorize",
"user",
"from",
"app"
] | 5c12aba31cae092e9681f0ae3e3664ed3fcec956 | https://github.com/honey-comb/core/blob/5c12aba31cae092e9681f0ae3e3664ed3fcec956/src/Http/Controllers/HCAuthController.php#L317-L329 | train |
mindkomm/types | lib/Post_Type_Page.php | Post_Type_Page.update_archive_slug | public function update_archive_slug( $args, $post_type ) {
if ( $post_type !== $this->post_type ) {
return $args;
}
$args['has_archive'] = trim(
wp_make_link_relative( get_permalink( $this->post_id ) ),
'/'
);
return $args;
} | php | public function update_archive_slug( $args, $post_type ) {
if ( $post_type !== $this->post_type ) {
return $args;
}
$args['has_archive'] = trim(
wp_make_link_relative( get_permalink( $this->post_id ) ),
'/'
);
return $args;
} | [
"public",
"function",
"update_archive_slug",
"(",
"$",
"args",
",",
"$",
"post_type",
")",
"{",
"if",
"(",
"$",
"post_type",
"!==",
"$",
"this",
"->",
"post_type",
")",
"{",
"return",
"$",
"args",
";",
"}",
"$",
"args",
"[",
"'has_archive'",
"]",
"=",
... | Update the archive slug to be the same as the page that should be used for the archive.
@param array $args Post type registration arguments.
@param string $post_type Post type name.
@return mixed | [
"Update",
"the",
"archive",
"slug",
"to",
"be",
"the",
"same",
"as",
"the",
"page",
"that",
"should",
"be",
"used",
"for",
"the",
"archive",
"."
] | a075d59acf995605427ce8a647a10ed12463b856 | https://github.com/mindkomm/types/blob/a075d59acf995605427ce8a647a10ed12463b856/lib/Post_Type_Page.php#L72-L83 | train |
mindkomm/types | lib/Post_Type_Page.php | Post_Type_Page.filter_wp_nav_menu_objects | public function filter_wp_nav_menu_objects( $menu_items ) {
foreach ( $menu_items as &$item ) {
if ( 'page' !== $item->object || (int) $item->object_id !== $this->post_id ) {
continue;
}
if ( is_singular( $this->post_type ) ) {
$item->current_item_parent = true;
$item->classes[] = 'current-menu-parent';
$menu_items = \Types\menu_items_ancestors( $item, $menu_items );
}
if ( is_post_type_archive( $this->post_type ) ) {
$item->classes[] = 'current-menu-item';
$item->current = true;
$menu_items = \Types\menu_items_ancestors( $item, $menu_items );
}
}
return $menu_items;
} | php | public function filter_wp_nav_menu_objects( $menu_items ) {
foreach ( $menu_items as &$item ) {
if ( 'page' !== $item->object || (int) $item->object_id !== $this->post_id ) {
continue;
}
if ( is_singular( $this->post_type ) ) {
$item->current_item_parent = true;
$item->classes[] = 'current-menu-parent';
$menu_items = \Types\menu_items_ancestors( $item, $menu_items );
}
if ( is_post_type_archive( $this->post_type ) ) {
$item->classes[] = 'current-menu-item';
$item->current = true;
$menu_items = \Types\menu_items_ancestors( $item, $menu_items );
}
}
return $menu_items;
} | [
"public",
"function",
"filter_wp_nav_menu_objects",
"(",
"$",
"menu_items",
")",
"{",
"foreach",
"(",
"$",
"menu_items",
"as",
"&",
"$",
"item",
")",
"{",
"if",
"(",
"'page'",
"!==",
"$",
"item",
"->",
"object",
"||",
"(",
"int",
")",
"$",
"item",
"->"... | Make sure menu items for our pages get the correct classes assigned
@param array $menu_items Array of menu items.
@return array | [
"Make",
"sure",
"menu",
"items",
"for",
"our",
"pages",
"get",
"the",
"correct",
"classes",
"assigned"
] | a075d59acf995605427ce8a647a10ed12463b856 | https://github.com/mindkomm/types/blob/a075d59acf995605427ce8a647a10ed12463b856/lib/Post_Type_Page.php#L102-L124 | train |
silverorange/swat | Swat/SwatPercentageEntry.php | SwatPercentageEntry.getDisplayValue | protected function getDisplayValue($value)
{
if (is_numeric($value)) {
$value = $value * 100;
$value = parent::getDisplayValue($value);
$value = $value . '%';
} else {
$value = parent::getDisplayValue($value);
}
return $value;
} | php | protected function getDisplayValue($value)
{
if (is_numeric($value)) {
$value = $value * 100;
$value = parent::getDisplayValue($value);
$value = $value . '%';
} else {
$value = parent::getDisplayValue($value);
}
return $value;
} | [
"protected",
"function",
"getDisplayValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"*",
"100",
";",
"$",
"value",
"=",
"parent",
"::",
"getDisplayValue",
"(",
"$",
"val... | Returns a value for this widget
The method returns a value to be displayed in the widget
@return string the final percentage value | [
"Returns",
"a",
"value",
"for",
"this",
"widget"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatPercentageEntry.php#L21-L32 | train |
silverorange/swat | Swat/SwatPercentageEntry.php | SwatPercentageEntry.getNumericValue | protected function getNumericValue($value)
{
$value = trim($value);
$value = str_replace('%', '', $value);
$value = parent::getNumericValue($value);
if ($value !== null) {
$value = $value / 100;
}
return $value;
} | php | protected function getNumericValue($value)
{
$value = trim($value);
$value = str_replace('%', '', $value);
$value = parent::getNumericValue($value);
if ($value !== null) {
$value = $value / 100;
}
return $value;
} | [
"protected",
"function",
"getNumericValue",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"str_replace",
"(",
"'%'",
",",
"''",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"parent",
"::"... | Gets the float value of this widget
This allows each widget to parse raw values and turn them into floats
@param string $value the raw value to use to get the numeric value.
@return mixed the numeric value of this entry widget or null if no
no numeric value is available. | [
"Gets",
"the",
"float",
"value",
"of",
"this",
"widget"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatPercentageEntry.php#L47-L57 | train |
silverorange/swat | Swat/SwatIntegerEntry.php | SwatIntegerEntry.process | public function process()
{
parent::process();
if ($this->value === null) {
return;
}
try {
$integer_value = $this->getNumericValue($this->value);
if ($integer_value === null) {
$this->addMessage($this->getValidationMessage('integer'));
} else {
$this->value = $integer_value;
}
} catch (SwatIntegerOverflowException $e) {
if ($e->getSign() > 0) {
$this->addMessage(
$this->getValidationMessage('integer-maximum')
);
} else {
$this->addMessage(
$this->getValidationMessage('integer-minimum')
);
}
$integer_value = null;
}
} | php | public function process()
{
parent::process();
if ($this->value === null) {
return;
}
try {
$integer_value = $this->getNumericValue($this->value);
if ($integer_value === null) {
$this->addMessage($this->getValidationMessage('integer'));
} else {
$this->value = $integer_value;
}
} catch (SwatIntegerOverflowException $e) {
if ($e->getSign() > 0) {
$this->addMessage(
$this->getValidationMessage('integer-maximum')
);
} else {
$this->addMessage(
$this->getValidationMessage('integer-minimum')
);
}
$integer_value = null;
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"parent",
"::",
"process",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"value",
"===",
"null",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"integer_value",
"=",
"$",
"this",
"->",
"getNumericValue",... | Checks to make sure value is an integer
If the value of this widget is not an integer then an error message is
attached to this widget. | [
"Checks",
"to",
"make",
"sure",
"value",
"is",
"an",
"integer"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatIntegerEntry.php#L20-L49 | train |
silverorange/swat | Swat/SwatIntegerEntry.php | SwatIntegerEntry.getValidationMessage | protected function getValidationMessage($id)
{
switch ($id) {
case 'integer':
if ($this->minimum_value < 0) {
$text = $this->show_field_title_in_messages
? Swat::_('The %s field must be an integer.')
: Swat::_('This field must be an integer.');
} else {
$text = $this->show_field_title_in_messages
? Swat::_('The %s field must be a whole number.')
: Swat::_('This field must be a whole number.');
}
$message = new SwatMessage($text, 'error');
break;
case 'integer-maximum':
$text = $this->show_field_title_in_messages
? Swat::_('The %s field is too big.')
: Swat::_('This field is too big.');
$message = new SwatMessage($text, 'error');
break;
case 'integer-minimum':
$text = $this->show_field_title_in_messages
? Swat::_('The %s field is too small.')
: Swat::_('The this field is too small.');
$message = new SwatMessage($text, 'error');
break;
default:
$message = parent::getValidationMessage($id);
break;
}
return $message;
} | php | protected function getValidationMessage($id)
{
switch ($id) {
case 'integer':
if ($this->minimum_value < 0) {
$text = $this->show_field_title_in_messages
? Swat::_('The %s field must be an integer.')
: Swat::_('This field must be an integer.');
} else {
$text = $this->show_field_title_in_messages
? Swat::_('The %s field must be a whole number.')
: Swat::_('This field must be a whole number.');
}
$message = new SwatMessage($text, 'error');
break;
case 'integer-maximum':
$text = $this->show_field_title_in_messages
? Swat::_('The %s field is too big.')
: Swat::_('This field is too big.');
$message = new SwatMessage($text, 'error');
break;
case 'integer-minimum':
$text = $this->show_field_title_in_messages
? Swat::_('The %s field is too small.')
: Swat::_('The this field is too small.');
$message = new SwatMessage($text, 'error');
break;
default:
$message = parent::getValidationMessage($id);
break;
}
return $message;
} | [
"protected",
"function",
"getValidationMessage",
"(",
"$",
"id",
")",
"{",
"switch",
"(",
"$",
"id",
")",
"{",
"case",
"'integer'",
":",
"if",
"(",
"$",
"this",
"->",
"minimum_value",
"<",
"0",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"show_fie... | Gets a validation message for this integer entry
@see SwatEntry::getValidationMessage()
@param string $id the string identifier of the validation message.
@return SwatMessage the validation message. | [
"Gets",
"a",
"validation",
"message",
"for",
"this",
"integer",
"entry"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatIntegerEntry.php#L108-L146 | train |
silverorange/swat | Swat/SwatFlydown.php | SwatFlydown.process | public function process()
{
parent::process();
if (!$this->processValue()) {
return;
}
if ($this->required && $this->isSensitive()) {
// When values are not serialized, an empty string is treated as
// null. As a result, you should not use a null value and an empty
// string value in the same flydown except when using serialized
// values.
if (
($this->serialize_values && $this->value === null) ||
(!$this->serialize_values && $this->value == '')
) {
$this->addMessage($this->getValidationMessage('required'));
}
}
} | php | public function process()
{
parent::process();
if (!$this->processValue()) {
return;
}
if ($this->required && $this->isSensitive()) {
// When values are not serialized, an empty string is treated as
// null. As a result, you should not use a null value and an empty
// string value in the same flydown except when using serialized
// values.
if (
($this->serialize_values && $this->value === null) ||
(!$this->serialize_values && $this->value == '')
) {
$this->addMessage($this->getValidationMessage('required'));
}
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"parent",
"::",
"process",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"processValue",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"required",
"&&",
"$",
"this",
"->"... | Figures out what option was selected
Processes this widget and figures out what select element from this
flydown was selected. Any validation errors cause an error message to
be attached to this widget in this method. | [
"Figures",
"out",
"what",
"option",
"was",
"selected"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFlydown.php#L171-L191 | train |
silverorange/swat | Swat/SwatFlydown.php | SwatFlydown.processValue | protected function processValue()
{
$form = $this->getForm();
$data = &$form->getFormData();
if (!isset($data[$this->id])) {
return false;
}
if ($this->serialize_values) {
$salt = $form->getSalt();
$this->value = SwatString::signedUnserialize(
$data[$this->id],
$salt
);
} else {
$this->value = (string) $data[$this->id];
}
return true;
} | php | protected function processValue()
{
$form = $this->getForm();
$data = &$form->getFormData();
if (!isset($data[$this->id])) {
return false;
}
if ($this->serialize_values) {
$salt = $form->getSalt();
$this->value = SwatString::signedUnserialize(
$data[$this->id],
$salt
);
} else {
$this->value = (string) $data[$this->id];
}
return true;
} | [
"protected",
"function",
"processValue",
"(",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"getForm",
"(",
")",
";",
"$",
"data",
"=",
"&",
"$",
"form",
"->",
"getFormData",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
... | Processes the value of this flydown from user-submitted form data
@return boolean true if the value was processed from form data | [
"Processes",
"the",
"value",
"of",
"this",
"flydown",
"from",
"user",
"-",
"submitted",
"form",
"data"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFlydown.php#L295-L315 | train |
silverorange/swat | Swat/SwatFlydown.php | SwatFlydown.displaySingle | protected function displaySingle(SwatOption $flydown_option)
{
$title = $flydown_option->title;
$value = $flydown_option->value;
$hidden_tag = new SwatHtmlTag('input');
$hidden_tag->type = 'hidden';
$hidden_tag->name = $this->id;
if ($this->serialize_values) {
$salt = $this->getForm()->getSalt();
$hidden_tag->value = SwatString::signedSerialize($value, $salt);
} else {
$hidden_tag->value = (string) $value;
}
$hidden_tag->display();
$span_tag = new SwatHtmlTag('span');
$span_tag->class = 'swat-flydown-single';
$span_tag->setContent($title, $flydown_option->content_type);
$span_tag->display();
} | php | protected function displaySingle(SwatOption $flydown_option)
{
$title = $flydown_option->title;
$value = $flydown_option->value;
$hidden_tag = new SwatHtmlTag('input');
$hidden_tag->type = 'hidden';
$hidden_tag->name = $this->id;
if ($this->serialize_values) {
$salt = $this->getForm()->getSalt();
$hidden_tag->value = SwatString::signedSerialize($value, $salt);
} else {
$hidden_tag->value = (string) $value;
}
$hidden_tag->display();
$span_tag = new SwatHtmlTag('span');
$span_tag->class = 'swat-flydown-single';
$span_tag->setContent($title, $flydown_option->content_type);
$span_tag->display();
} | [
"protected",
"function",
"displaySingle",
"(",
"SwatOption",
"$",
"flydown_option",
")",
"{",
"$",
"title",
"=",
"$",
"flydown_option",
"->",
"title",
";",
"$",
"value",
"=",
"$",
"flydown_option",
"->",
"value",
";",
"$",
"hidden_tag",
"=",
"new",
"SwatHtml... | Displays this flydown if there is only a single option | [
"Displays",
"this",
"flydown",
"if",
"there",
"is",
"only",
"a",
"single",
"option"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFlydown.php#L323-L345 | train |
FreeDSx/Socket | src/FreeDSx/Socket/SocketServer.php | SocketServer.listen | public function listen(string $ip, int $port)
{
$flags = STREAM_SERVER_BIND;
if ($this->options['transport'] !== 'udp') {
$flags |= STREAM_SERVER_LISTEN;
}
$this->socket = @\stream_socket_server(
$this->options['transport'].'://'.$ip.':'.$port,
$this->errorNumber,
$this->errorMessage,
$flags,
$this->createSocketContext()
);
if (!$this->socket) {
throw new ConnectionException(sprintf(
'Unable to open %s socket (%s): %s',
\strtoupper($this->options['transport']),
$this->errorNumber,
$this->errorMessage
));
}
return $this;
} | php | public function listen(string $ip, int $port)
{
$flags = STREAM_SERVER_BIND;
if ($this->options['transport'] !== 'udp') {
$flags |= STREAM_SERVER_LISTEN;
}
$this->socket = @\stream_socket_server(
$this->options['transport'].'://'.$ip.':'.$port,
$this->errorNumber,
$this->errorMessage,
$flags,
$this->createSocketContext()
);
if (!$this->socket) {
throw new ConnectionException(sprintf(
'Unable to open %s socket (%s): %s',
\strtoupper($this->options['transport']),
$this->errorNumber,
$this->errorMessage
));
}
return $this;
} | [
"public",
"function",
"listen",
"(",
"string",
"$",
"ip",
",",
"int",
"$",
"port",
")",
"{",
"$",
"flags",
"=",
"STREAM_SERVER_BIND",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'transport'",
"]",
"!==",
"'udp'",
")",
"{",
"$",
"flags",
"|=",... | Create the socket server and bind to a specific port to listen for clients.
@param string $ip
@param int $port
@return $this
@throws ConnectionException
@internal param string $ip | [
"Create",
"the",
"socket",
"server",
"and",
"bind",
"to",
"a",
"specific",
"port",
"to",
"listen",
"for",
"clients",
"."
] | d74683bf8b827e91a8ca051805c55dacaf64f93d | https://github.com/FreeDSx/Socket/blob/d74683bf8b827e91a8ca051805c55dacaf64f93d/src/FreeDSx/Socket/SocketServer.php#L56-L79 | train |
FreeDSx/Socket | src/FreeDSx/Socket/SocketServer.php | SocketServer.receive | public function receive(&$ipAddress = null)
{
$this->block(true);
return \stream_socket_recvfrom($this->socket, 65507, 0, $ipAddress);
} | php | public function receive(&$ipAddress = null)
{
$this->block(true);
return \stream_socket_recvfrom($this->socket, 65507, 0, $ipAddress);
} | [
"public",
"function",
"receive",
"(",
"&",
"$",
"ipAddress",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"block",
"(",
"true",
")",
";",
"return",
"\\",
"stream_socket_recvfrom",
"(",
"$",
"this",
"->",
"socket",
",",
"65507",
",",
"0",
",",
"$",
"ipAd... | Receive data from a UDP based socket. Optionally get the IP address the data was received from.
@todo Buffer size should be adjustable. Max UDP packet size is 65507. Currently this avoids possible truncation.
@param null $ipAddress
@return null|string | [
"Receive",
"data",
"from",
"a",
"UDP",
"based",
"socket",
".",
"Optionally",
"get",
"the",
"IP",
"address",
"the",
"data",
"was",
"received",
"from",
"."
] | d74683bf8b827e91a8ca051805c55dacaf64f93d | https://github.com/FreeDSx/Socket/blob/d74683bf8b827e91a8ca051805c55dacaf64f93d/src/FreeDSx/Socket/SocketServer.php#L105-L110 | train |
FreeDSx/Socket | src/FreeDSx/Socket/SocketServer.php | SocketServer.bind | public static function bind(string $ip, int $port, array $options = []) : SocketServer
{
return (new self($options))->listen($ip, $port);
} | php | public static function bind(string $ip, int $port, array $options = []) : SocketServer
{
return (new self($options))->listen($ip, $port);
} | [
"public",
"static",
"function",
"bind",
"(",
"string",
"$",
"ip",
",",
"int",
"$",
"port",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"SocketServer",
"{",
"return",
"(",
"new",
"self",
"(",
"$",
"options",
")",
")",
"->",
"listen",
"(",... | Create the socket server. Binds and listens on a specific port
@param string $ip
@param int $port
@param array $options
@return $this
@throws ConnectionException | [
"Create",
"the",
"socket",
"server",
".",
"Binds",
"and",
"listens",
"on",
"a",
"specific",
"port"
] | d74683bf8b827e91a8ca051805c55dacaf64f93d | https://github.com/FreeDSx/Socket/blob/d74683bf8b827e91a8ca051805c55dacaf64f93d/src/FreeDSx/Socket/SocketServer.php#L139-L142 | train |
FreeDSx/Socket | src/FreeDSx/Socket/SocketServer.php | SocketServer.bindTcp | public static function bindTcp(string $ip, int $port, array $options = []) : SocketServer
{
return static::bind($ip, $port, \array_merge($options, ['transport' => 'tcp']));
} | php | public static function bindTcp(string $ip, int $port, array $options = []) : SocketServer
{
return static::bind($ip, $port, \array_merge($options, ['transport' => 'tcp']));
} | [
"public",
"static",
"function",
"bindTcp",
"(",
"string",
"$",
"ip",
",",
"int",
"$",
"port",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"SocketServer",
"{",
"return",
"static",
"::",
"bind",
"(",
"$",
"ip",
",",
"$",
"port",
",",
"\\",... | Create a TCP based socket server.
@param string $ip
@param int $port
@param array $options
@return SocketServer
@throws ConnectionException | [
"Create",
"a",
"TCP",
"based",
"socket",
"server",
"."
] | d74683bf8b827e91a8ca051805c55dacaf64f93d | https://github.com/FreeDSx/Socket/blob/d74683bf8b827e91a8ca051805c55dacaf64f93d/src/FreeDSx/Socket/SocketServer.php#L153-L156 | train |
brainworxx/kreXX | src/Analyse/Routing/Process/ProcessResource.php | ProcessResource.process | public function process(Model $model)
{
$resource = $model->getData();
$type = get_resource_type($resource);
$typeString = 'resource (' . $type . ')';
switch ($type) {
case 'stream':
$meta = stream_get_meta_data($resource);
break;
case 'curl':
// No need to check for a curl installation, because we are
// facing a curl instance right here.
$meta = curl_getinfo($resource);
break;
default:
$meta = array();
}
// Check, if we have something useful.
if (empty($meta)) {
// If we are facing a closed resource, 'Unknown' is a little bit sparse.
// PHP 7.2 can provide more info by calling gettype().
if (version_compare(phpversion(), '7.2.0', '>=')) {
$typeString = gettype($resource);
}
return $this->pool->render->renderSingleChild(
$model->setData($typeString)
->setNormal($typeString)
->setType(static::TYPE_RESOURCE)
);
}
// Output meta data from the class.
return $this->pool->render->renderExpandableChild(
$model->setType(static::TYPE_RESOURCE)
->addParameter(static::PARAM_DATA, $meta)
->setNormal($typeString)
->injectCallback(
$this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughResource')
)
);
} | php | public function process(Model $model)
{
$resource = $model->getData();
$type = get_resource_type($resource);
$typeString = 'resource (' . $type . ')';
switch ($type) {
case 'stream':
$meta = stream_get_meta_data($resource);
break;
case 'curl':
// No need to check for a curl installation, because we are
// facing a curl instance right here.
$meta = curl_getinfo($resource);
break;
default:
$meta = array();
}
// Check, if we have something useful.
if (empty($meta)) {
// If we are facing a closed resource, 'Unknown' is a little bit sparse.
// PHP 7.2 can provide more info by calling gettype().
if (version_compare(phpversion(), '7.2.0', '>=')) {
$typeString = gettype($resource);
}
return $this->pool->render->renderSingleChild(
$model->setData($typeString)
->setNormal($typeString)
->setType(static::TYPE_RESOURCE)
);
}
// Output meta data from the class.
return $this->pool->render->renderExpandableChild(
$model->setType(static::TYPE_RESOURCE)
->addParameter(static::PARAM_DATA, $meta)
->setNormal($typeString)
->injectCallback(
$this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughResource')
)
);
} | [
"public",
"function",
"process",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"resource",
"=",
"$",
"model",
"->",
"getData",
"(",
")",
";",
"$",
"type",
"=",
"get_resource_type",
"(",
"$",
"resource",
")",
";",
"$",
"typeString",
"=",
"'resource ('",
".... | Analyses a resource.
@param Model $model
The data we are analysing.
@return string
The rendered markup. | [
"Analyses",
"a",
"resource",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Routing/Process/ProcessResource.php#L57-L101 | train |
honey-comb/core | src/Console/HCCreateSuperAdminCommand.php | HCCreateSuperAdminCommand.getEmail | private function getEmail(): ? string
{
$email = $this->ask("Enter email address");
$validator = Validator::make(['email' => $email], [
'email' => 'required|min:3|email',
]);
if ($validator->fails()) {
$this->error('Email is required, minimum 3 symbols length and must be email format');
return $this->getEmail();
}
$this->email = $email;
return null;
} | php | private function getEmail(): ? string
{
$email = $this->ask("Enter email address");
$validator = Validator::make(['email' => $email], [
'email' => 'required|min:3|email',
]);
if ($validator->fails()) {
$this->error('Email is required, minimum 3 symbols length and must be email format');
return $this->getEmail();
}
$this->email = $email;
return null;
} | [
"private",
"function",
"getEmail",
"(",
")",
":",
"?",
"string",
"{",
"$",
"email",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Enter email address\"",
")",
";",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"[",
"'email'",
"=>",
"$",
"email",
"]",... | Get email address
@return null|string | [
"Get",
"email",
"address"
] | 5c12aba31cae092e9681f0ae3e3664ed3fcec956 | https://github.com/honey-comb/core/blob/5c12aba31cae092e9681f0ae3e3664ed3fcec956/src/Console/HCCreateSuperAdminCommand.php#L122-L139 | train |
honey-comb/core | src/Console/HCCreateSuperAdminCommand.php | HCCreateSuperAdminCommand.createSuperAdmin | private function createSuperAdmin(): void
{
$this->getEmail();
$this->info('');
$this->comment('Creating default super-admin user...');
$this->info('');
$this->checkIfAdminExists();
$this->getPassword();
$this->createAdmin();
$this->comment('Super admin account successfully created!');
$this->comment('Your email: ');
$this->error($this->email);
$this->info('');
} | php | private function createSuperAdmin(): void
{
$this->getEmail();
$this->info('');
$this->comment('Creating default super-admin user...');
$this->info('');
$this->checkIfAdminExists();
$this->getPassword();
$this->createAdmin();
$this->comment('Super admin account successfully created!');
$this->comment('Your email: ');
$this->error($this->email);
$this->info('');
} | [
"private",
"function",
"createSuperAdmin",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"getEmail",
"(",
")",
";",
"$",
"this",
"->",
"info",
"(",
"''",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"'Creating default super-admin user...'",
")",
";",
"$... | Create super admin account | [
"Create",
"super",
"admin",
"account"
] | 5c12aba31cae092e9681f0ae3e3664ed3fcec956 | https://github.com/honey-comb/core/blob/5c12aba31cae092e9681f0ae3e3664ed3fcec956/src/Console/HCCreateSuperAdminCommand.php#L144-L163 | train |
honey-comb/core | src/Console/HCScanRolePermissionsCommand.php | HCScanRolePermissionsCommand.extractAllActions | private function extractAllActions(array $aclData): array
{
$allRolesActions = [];
// get all role actions available
foreach ($aclData as $acl) {
if (isset($acl['acl']['rolesActions']) && !empty ($acl['acl']['rolesActions'])) {
foreach ($acl['acl']['rolesActions'] as $role => $actions) {
if (array_key_exists($role, $allRolesActions)) {
$allRolesActions[$role] = array_merge($allRolesActions[$role], $actions);
} else {
$allRolesActions[$role] = array_merge([], $actions);
}
}
}
}
return $allRolesActions;
} | php | private function extractAllActions(array $aclData): array
{
$allRolesActions = [];
// get all role actions available
foreach ($aclData as $acl) {
if (isset($acl['acl']['rolesActions']) && !empty ($acl['acl']['rolesActions'])) {
foreach ($acl['acl']['rolesActions'] as $role => $actions) {
if (array_key_exists($role, $allRolesActions)) {
$allRolesActions[$role] = array_merge($allRolesActions[$role], $actions);
} else {
$allRolesActions[$role] = array_merge([], $actions);
}
}
}
}
return $allRolesActions;
} | [
"private",
"function",
"extractAllActions",
"(",
"array",
"$",
"aclData",
")",
":",
"array",
"{",
"$",
"allRolesActions",
"=",
"[",
"]",
";",
"// get all role actions available",
"foreach",
"(",
"$",
"aclData",
"as",
"$",
"acl",
")",
"{",
"if",
"(",
"isset",... | Extract all actions from roles config
@param array $aclData
@return array | [
"Extract",
"all",
"actions",
"from",
"roles",
"config"
] | 5c12aba31cae092e9681f0ae3e3664ed3fcec956 | https://github.com/honey-comb/core/blob/5c12aba31cae092e9681f0ae3e3664ed3fcec956/src/Console/HCScanRolePermissionsCommand.php#L309-L327 | train |
rhoone/yii2-rhoone | models/SynonymQuery.php | SynonymQuery.headword | public function headword($headword)
{
if ($headword instanceof Headword) {
return $this->andWhere(['headword_guid' => $headword->guid]);
}
if (is_string($headword)) {
$headword = Headword::find()->where(['word' => $headword])->one();
if (!$headword) {
return $this;
}
return $this->andWhere(['headword_guid' => $headword->guid]);
}
} | php | public function headword($headword)
{
if ($headword instanceof Headword) {
return $this->andWhere(['headword_guid' => $headword->guid]);
}
if (is_string($headword)) {
$headword = Headword::find()->where(['word' => $headword])->one();
if (!$headword) {
return $this;
}
return $this->andWhere(['headword_guid' => $headword->guid]);
}
} | [
"public",
"function",
"headword",
"(",
"$",
"headword",
")",
"{",
"if",
"(",
"$",
"headword",
"instanceof",
"Headword",
")",
"{",
"return",
"$",
"this",
"->",
"andWhere",
"(",
"[",
"'headword_guid'",
"=>",
"$",
"headword",
"->",
"guid",
"]",
")",
";",
... | Attach headword.
@param string|Headword $headword
@return \static | [
"Attach",
"headword",
"."
] | f6ae90d466ea6f34bba404be0aba03e37ef369ad | https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/models/SynonymQuery.php#L55-L67 | train |
rollun-com/rollun-datastore | src/DataStore/src/DataStore/Traits/AutoIdGeneratorTrait.php | AutoIdGeneratorTrait.generateId | protected function generateId()
{
trigger_error(AutoIdGeneratorTrait::class . ' trait is deprecated', E_USER_DEPRECATED);
$tryCount = 0;
do {
$id = $this->idGenerator->generate();
$tryCount++;
if ($tryCount >= $this->getIdGenerateMaxTry()) {
throw new DataStoreException("Can't generate id.");
}
} while ($this->has($id));
return $id;
} | php | protected function generateId()
{
trigger_error(AutoIdGeneratorTrait::class . ' trait is deprecated', E_USER_DEPRECATED);
$tryCount = 0;
do {
$id = $this->idGenerator->generate();
$tryCount++;
if ($tryCount >= $this->getIdGenerateMaxTry()) {
throw new DataStoreException("Can't generate id.");
}
} while ($this->has($id));
return $id;
} | [
"protected",
"function",
"generateId",
"(",
")",
"{",
"trigger_error",
"(",
"AutoIdGeneratorTrait",
"::",
"class",
".",
"' trait is deprecated'",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"tryCount",
"=",
"0",
";",
"do",
"{",
"$",
"id",
"=",
"$",
"this",
"->"... | Generates an arbitrary length string of cryptographic random bytes
@return string
@throws DataStoreException | [
"Generates",
"an",
"arbitrary",
"length",
"string",
"of",
"cryptographic",
"random",
"bytes"
] | ef433b58b94e1c311123ad1b2a0360e95a636bd1 | https://github.com/rollun-com/rollun-datastore/blob/ef433b58b94e1c311123ad1b2a0360e95a636bd1/src/DataStore/src/DataStore/Traits/AutoIdGeneratorTrait.php#L29-L45 | train |
rollun-com/rollun-datastore | src/DataStore/src/DataStore/Traits/AutoIdGeneratorTrait.php | AutoIdGeneratorTrait.prepareItem | protected function prepareItem(array $itemData)
{
if (!isset($itemData[$this->getIdentifier()])) {
$itemData[$this->getIdentifier()] = $this->generateId();
}
return $itemData;
} | php | protected function prepareItem(array $itemData)
{
if (!isset($itemData[$this->getIdentifier()])) {
$itemData[$this->getIdentifier()] = $this->generateId();
}
return $itemData;
} | [
"protected",
"function",
"prepareItem",
"(",
"array",
"$",
"itemData",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"itemData",
"[",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
"]",
")",
")",
"{",
"$",
"itemData",
"[",
"$",
"this",
"->",
"getIdenti... | Generate id to item
@param array $itemData
@return array
@throws DataStoreException | [
"Generate",
"id",
"to",
"item"
] | ef433b58b94e1c311123ad1b2a0360e95a636bd1 | https://github.com/rollun-com/rollun-datastore/blob/ef433b58b94e1c311123ad1b2a0360e95a636bd1/src/DataStore/src/DataStore/Traits/AutoIdGeneratorTrait.php#L81-L88 | train |
brainworxx/kreXX | src/Service/Misc/Registry.php | Registry.get | public function get($key)
{
if (empty($this->data[$key]) === true) {
return null;
}
return $this->data[$key];
} | php | public function get($key)
{
if (empty($this->data[$key]) === true) {
return null;
}
return $this->data[$key];
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
... | Getter for the registry.
@param $key
The key under what we once stored the $value,
@return null|mixed
The value, if available. | [
"Getter",
"for",
"the",
"registry",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Misc/Registry.php#L81-L88 | train |
silverorange/swat | Swat/SwatConfirmPasswordEntry.php | SwatConfirmPasswordEntry.process | public function process()
{
parent::process();
if ($this->password_widget === null) {
throw new SwatException(
"Property 'password_widget' is null. " .
'Expected a reference to a SwatPasswordEntry.'
);
}
if ($this->password_widget->value !== null) {
if ($this->password_widget->value !== $this->value) {
$message = Swat::_(
'Password and confirmation password do not match.'
);
$this->addMessage(new SwatMessage($message, 'error'));
}
}
} | php | public function process()
{
parent::process();
if ($this->password_widget === null) {
throw new SwatException(
"Property 'password_widget' is null. " .
'Expected a reference to a SwatPasswordEntry.'
);
}
if ($this->password_widget->value !== null) {
if ($this->password_widget->value !== $this->value) {
$message = Swat::_(
'Password and confirmation password do not match.'
);
$this->addMessage(new SwatMessage($message, 'error'));
}
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"parent",
"::",
"process",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"password_widget",
"===",
"null",
")",
"{",
"throw",
"new",
"SwatException",
"(",
"\"Property 'password_widget' is null. \"",
".",
"'Expecte... | Checks to make sure passwords match
Checks to make sure the values of the two password fields are the same.
If an associated password widget is not set, an exception is thrown. If
the passwords do not match, an error is added to this widget.
@throws SwatException | [
"Checks",
"to",
"make",
"sure",
"passwords",
"match"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatConfirmPasswordEntry.php#L36-L56 | train |
brainworxx/kreXX | src/Analyse/Callback/Analyse/ConfigSection.php | ConfigSection.callMe | public function callMe()
{
$sectionOutput = $this->dispatchStartEvent();
foreach ($this->parameters[static::PARAM_DATA] as $id => $setting) {
// Render the single value.
// We need to find out where the value comes from.
/** @var \Brainworxx\Krexx\Service\Config\Model $setting */
if ($setting->getType() !== Fallback::RENDER_TYPE_NONE) {
$value = $setting->getValue();
// We need to re-translate booleans to something the
// frontend can understand.
if ($value === true) {
$value = 'true';
}
if ($value === false) {
$value = 'false';
}
/** @var Model $model */
$model = $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model')->setHelpid($id . static::META_HELP);
$name = $this->pool->messages->getHelp($id . 'Readable');
if ($setting->getEditable() === true) {
$model->setData($name)
->setDomid($id)
->setName($value)
->setNormal($setting->getSource())
->setType($setting->getType());
$sectionOutput .= $this->pool->render->renderSingleEditableChild($model);
} else {
$model->setData($value)
->setName($name)
->setNormal($value)
->setType($setting->getSource());
$sectionOutput .= $this->pool->render->renderSingleChild($model);
}
}
}
return $sectionOutput;
} | php | public function callMe()
{
$sectionOutput = $this->dispatchStartEvent();
foreach ($this->parameters[static::PARAM_DATA] as $id => $setting) {
// Render the single value.
// We need to find out where the value comes from.
/** @var \Brainworxx\Krexx\Service\Config\Model $setting */
if ($setting->getType() !== Fallback::RENDER_TYPE_NONE) {
$value = $setting->getValue();
// We need to re-translate booleans to something the
// frontend can understand.
if ($value === true) {
$value = 'true';
}
if ($value === false) {
$value = 'false';
}
/** @var Model $model */
$model = $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model')->setHelpid($id . static::META_HELP);
$name = $this->pool->messages->getHelp($id . 'Readable');
if ($setting->getEditable() === true) {
$model->setData($name)
->setDomid($id)
->setName($value)
->setNormal($setting->getSource())
->setType($setting->getType());
$sectionOutput .= $this->pool->render->renderSingleEditableChild($model);
} else {
$model->setData($value)
->setName($name)
->setNormal($value)
->setType($setting->getSource());
$sectionOutput .= $this->pool->render->renderSingleChild($model);
}
}
}
return $sectionOutput;
} | [
"public",
"function",
"callMe",
"(",
")",
"{",
"$",
"sectionOutput",
"=",
"$",
"this",
"->",
"dispatchStartEvent",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"PARAM_DATA",
"]",
"as",
"$",
"id",
"=>",
"$",
"sett... | Renders each section of the footer.
@return string
The generated markup. | [
"Renders",
"each",
"section",
"of",
"the",
"footer",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Callback/Analyse/ConfigSection.php#L63-L104 | train |
rhoone/yii2-rhoone | controllers/ExtensionController.php | ExtensionController.actionIndex | public function actionIndex()
{
$extensions = Extension::find()->all();
if (empty($extensions)) {
echo "<empty list>";
}
echo"|";
echo sprintf("%28s", "Class Name");
echo"|";
echo sprintf("%4s", "Enb");
echo"|";
echo sprintf("%4s", "Mnp");
echo"|";
echo sprintf("%4s", "Dft");
echo"|";
echo sprintf("%20s", "Create Time");
echo"|";
echo sprintf("%20s", "Update Time");
echo"|";
echo "\r\n";
foreach ($extensions as $extension) {
echo"|";
echo sprintf("%28s", $extension->classname);
echo"|";
echo sprintf("%4d", $extension->isEnabled);
echo"|";
echo sprintf("%4d", $extension->monopolized);
echo"|";
echo sprintf("%4d", $extension->default);
echo"|";
echo sprintf("%20s", $extension->createdAt);
echo"|";
echo sprintf("%20s", $extension->updatedAt);
echo"|";
echo "\r\n";
}
return 0;
} | php | public function actionIndex()
{
$extensions = Extension::find()->all();
if (empty($extensions)) {
echo "<empty list>";
}
echo"|";
echo sprintf("%28s", "Class Name");
echo"|";
echo sprintf("%4s", "Enb");
echo"|";
echo sprintf("%4s", "Mnp");
echo"|";
echo sprintf("%4s", "Dft");
echo"|";
echo sprintf("%20s", "Create Time");
echo"|";
echo sprintf("%20s", "Update Time");
echo"|";
echo "\r\n";
foreach ($extensions as $extension) {
echo"|";
echo sprintf("%28s", $extension->classname);
echo"|";
echo sprintf("%4d", $extension->isEnabled);
echo"|";
echo sprintf("%4d", $extension->monopolized);
echo"|";
echo sprintf("%4d", $extension->default);
echo"|";
echo sprintf("%20s", $extension->createdAt);
echo"|";
echo sprintf("%20s", $extension->updatedAt);
echo"|";
echo "\r\n";
}
return 0;
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"extensions",
"=",
"Extension",
"::",
"find",
"(",
")",
"->",
"all",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"extensions",
")",
")",
"{",
"echo",
"\"<empty list>\"",
";",
"}",
"echo",
"\"|... | List all registered extensions.
@return int | [
"List",
"all",
"registered",
"extensions",
"."
] | f6ae90d466ea6f34bba404be0aba03e37ef369ad | https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/controllers/ExtensionController.php#L32-L69 | train |
rhoone/yii2-rhoone | controllers/ExtensionController.php | ExtensionController.actionEnable | public function actionEnable($class)
{
try {
if (Yii::$app->rhoone->ext->enable($class)) {
echo "Enabled.";
} else {
echo "Failed to enable.";
}
} catch (\Exception $ex) {
throw new Exception($ex->getMessage());
}
return 0;
} | php | public function actionEnable($class)
{
try {
if (Yii::$app->rhoone->ext->enable($class)) {
echo "Enabled.";
} else {
echo "Failed to enable.";
}
} catch (\Exception $ex) {
throw new Exception($ex->getMessage());
}
return 0;
} | [
"public",
"function",
"actionEnable",
"(",
"$",
"class",
")",
"{",
"try",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"rhoone",
"->",
"ext",
"->",
"enable",
"(",
"$",
"class",
")",
")",
"{",
"echo",
"\"Enabled.\"",
";",
"}",
"else",
"{",
"echo",... | Enable an extension.
@param string $class
@return int | [
"Enable",
"an",
"extension",
"."
] | f6ae90d466ea6f34bba404be0aba03e37ef369ad | https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/controllers/ExtensionController.php#L96-L108 | train |
rhoone/yii2-rhoone | controllers/ExtensionController.php | ExtensionController.actionDisable | public function actionDisable($class)
{
try {
if (Yii::$app->rhoone->ext->disable($class)) {
echo "Disabled.";
} else {
echo "Failed to disable.";
}
} catch (\Exception $ex) {
throw new Exception($ex->getMessage());
}
return 0;
} | php | public function actionDisable($class)
{
try {
if (Yii::$app->rhoone->ext->disable($class)) {
echo "Disabled.";
} else {
echo "Failed to disable.";
}
} catch (\Exception $ex) {
throw new Exception($ex->getMessage());
}
return 0;
} | [
"public",
"function",
"actionDisable",
"(",
"$",
"class",
")",
"{",
"try",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"rhoone",
"->",
"ext",
"->",
"disable",
"(",
"$",
"class",
")",
")",
"{",
"echo",
"\"Disabled.\"",
";",
"}",
"else",
"{",
"ech... | Disable an extension.
@param string $class
@return int | [
"Disable",
"an",
"extension",
"."
] | f6ae90d466ea6f34bba404be0aba03e37ef369ad | https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/controllers/ExtensionController.php#L115-L127 | train |
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",
... | 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 | train |
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"... | 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 | train |
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'",
",",
"'languag... | 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 | train |
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",
... | 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 | train |
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",
")",
"{",
"// Ch... | 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 | train |
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.\"",
")",
";",
"}",
"$",
"g... | 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 | train |
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",
"(",
")",
";",
"$",... | 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 | train |
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",
"(",
"$"... | 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 | train |
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",
"->"... | 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 | train |
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",
"===",
"''",
"||",
"$",
"... | 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 | train |
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 ... | 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 (&) => &
- less than (<) => <
- greater than (>) => >
- double quote (") => "
@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 | train |
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"... | 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 | train |
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",
... | 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 | train |
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'",
")",... | 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 | train |
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",
"(",
"setlo... | 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 | train |
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",
"(",
"$"... | 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 | train |
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",
"=",
... | 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 | train |
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... | 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 | train |
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 formattin... | 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 | train |
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"... | 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 | train |
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",
")",
")",
... | 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 | train |
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",
"... | 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 | train |
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",
"("... | 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 | train |
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",
"::",
"toHu... | 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 | train |
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_D... | 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 | train |
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_HO... | 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 | train |
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",
"=",
... | 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 | train |
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",
... | 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 | train |
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",
".",
"("... | 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 | train |
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",
")",... | 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 | train |
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",
"'='",
",",
"//... | 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 | train |
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",
"++",
")",
"{"... | 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 | train |
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",
"... | 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 | train |
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_OFFS... | 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 | train |
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",
"... | 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 | train |
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",
"(",
"$... | 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 | train |
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",
",... | 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 | train |
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_m... | 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 | train |
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",
"->",
... | 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 | train |
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",
")",
"... | 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 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.